diff --git a/src/allmain.c b/src/allmain.c index a88611e27..434b1c6da 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 allmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 allmain.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.60 $ */ /* NetHack 3.6 allmain.c $Date: 2012/05/16 01:47:18 $ $Revision: 1.43 $ */ /* SCCS Id: @(#)allmain.c 3.5 2007/03/12 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -28,423 +28,472 @@ boolean resuming; boolean monscanmove = FALSE; /* Note: these initializers don't do anything except guarantee that - we're linked properly. + we're linked properly. */ decl_init(); monst_init(); - monstr_init(); /* monster strengths */ + monstr_init(); /* monster strengths */ objects_init(); - if (wizard) add_debug_extended_commands(); + if (wizard) + add_debug_extended_commands(); /* if a save file created in normal mode is now being restored in explore mode, treat it as normal restore followed by 'X' command to use up the save file and require confirmation for explore mode */ - if (resuming && iflags.deferred_X) (void)enter_explore_mode(); + if (resuming && iflags.deferred_X) + (void) enter_explore_mode(); /* side-effects from the real world */ flags.moonphase = phase_of_the_moon(); - if(flags.moonphase == FULL_MOON) { - You("are lucky! Full moon tonight."); - change_luck(1); - } else if(flags.moonphase == NEW_MOON) { - pline("Be careful! New moon tonight."); + if (flags.moonphase == FULL_MOON) { + You("are lucky! Full moon tonight."); + change_luck(1); + } else if (flags.moonphase == NEW_MOON) { + pline("Be careful! New moon tonight."); } flags.friday13 = friday_13th(); if (flags.friday13) { - pline("Watch out! Bad things can happen on Friday the 13th."); - change_luck(-1); + pline("Watch out! Bad things can happen on Friday the 13th."); + change_luck(-1); } - if (!resuming) { /* new game */ - context.rndencode = rnd(9000); - set_wear((struct obj *)0); /* for side-effects of worn starting gear */ - (void) pickup(1); /* autopickup at initial location */ - } else { /* restore old game */ + if (!resuming) { /* new game */ + context.rndencode = rnd(9000); + set_wear( + (struct obj *) 0); /* for side-effects of worn starting gear */ + (void) pickup(1); /* autopickup at initial location */ + } else { /* restore old game */ #ifndef WIN32 - update_inventory(); /* for perm_invent */ + update_inventory(); /* for perm_invent */ #endif - read_engr_at(u.ux, u.uy); /* subset of pickup() */ + read_engr_at(u.ux, u.uy); /* subset of pickup() */ } #ifdef WIN32 - update_inventory(); /* for perm_invent */ + update_inventory(); /* for perm_invent */ #endif - + (void) encumber_msg(); /* in case they auto-picked up something */ if (defer_see_monsters) { - defer_see_monsters = FALSE; - see_monsters(); + defer_see_monsters = FALSE; + see_monsters(); } initrack(); u.uz0.dlevel = u.uz.dlevel; - youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ + youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ context.move = 0; program_state.in_moveloop = 1; - for(;;) { + for (;;) { #ifdef SAFERHANGUP - if (program_state.done_hup) end_of_input(); + if (program_state.done_hup) + end_of_input(); #endif - get_nh_event(); + get_nh_event(); #ifdef POSITIONBAR - do_positionbar(); + do_positionbar(); #endif - if (context.move) { - /* actual time passed */ - youmonst.movement -= NORMAL_SPEED; + if (context.move) { + /* actual time passed */ + youmonst.movement -= NORMAL_SPEED; - do { /* hero can't move this turn loop */ - wtcap = encumber_msg(); + do { /* hero can't move this turn loop */ + wtcap = encumber_msg(); - context.mon_moving = TRUE; - do { - monscanmove = movemon(); - if (youmonst.movement >= NORMAL_SPEED) - break; /* it's now your turn */ - } while (monscanmove); - context.mon_moving = FALSE; + context.mon_moving = TRUE; + do { + monscanmove = movemon(); + if (youmonst.movement >= NORMAL_SPEED) + break; /* it's now your turn */ + } while (monscanmove); + context.mon_moving = FALSE; - if (!monscanmove && youmonst.movement < NORMAL_SPEED) { - /* both you and the monsters are out of steam this round */ - /* set up for a new turn */ - struct monst *mtmp; - mcalcdistress(); /* adjust monsters' trap, blind, etc */ + if (!monscanmove && youmonst.movement < NORMAL_SPEED) { + /* both you and the monsters are out of steam this round + */ + /* set up for a new turn */ + struct monst *mtmp; + mcalcdistress(); /* adjust monsters' trap, blind, etc */ - /* reallocate movement rations to monsters */ - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - mtmp->movement += mcalcmove(mtmp); + /* reallocate movement rations to monsters */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + mtmp->movement += mcalcmove(mtmp); - if(!rn2(u.uevent.udemigod ? 25 : - (depth(&u.uz) > depth(&stronghold_level)) ? 50 : 70)) - (void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS); + if (!rn2(u.uevent.udemigod + ? 25 + : (depth(&u.uz) > depth(&stronghold_level)) + ? 50 + : 70)) + (void) makemon((struct permonst *) 0, 0, 0, + NO_MM_FLAGS); - /* calculate how much time passed. */ - if (u.usteed && u.umoved) { - /* your speed doesn't augment steed's speed */ - moveamt = mcalcmove(u.usteed); - } else - { - moveamt = youmonst.data->mmove; + /* calculate how much time passed. */ + if (u.usteed && u.umoved) { + /* your speed doesn't augment steed's speed */ + moveamt = mcalcmove(u.usteed); + } else { + moveamt = youmonst.data->mmove; - if (Very_fast) { /* speed boots or potion */ - /* average movement is 1.67 times normal */ - moveamt += NORMAL_SPEED / 2; - if (rn2(3) == 0) moveamt += NORMAL_SPEED / 2; - } else if (Fast) { - /* average movement is 1.33 times normal */ - if (rn2(3) != 0) moveamt += NORMAL_SPEED / 2; - } - } + if (Very_fast) { /* speed boots or potion */ + /* average movement is 1.67 times normal */ + moveamt += NORMAL_SPEED / 2; + if (rn2(3) == 0) + moveamt += NORMAL_SPEED / 2; + } else if (Fast) { + /* average movement is 1.33 times normal */ + if (rn2(3) != 0) + moveamt += NORMAL_SPEED / 2; + } + } - switch (wtcap) { - case UNENCUMBERED: break; - case SLT_ENCUMBER: moveamt -= (moveamt / 4); break; - case MOD_ENCUMBER: moveamt -= (moveamt / 2); break; - case HVY_ENCUMBER: moveamt -= ((moveamt * 3) / 4); break; - case EXT_ENCUMBER: moveamt -= ((moveamt * 7) / 8); break; - default: break; - } + switch (wtcap) { + case UNENCUMBERED: + break; + case SLT_ENCUMBER: + moveamt -= (moveamt / 4); + break; + case MOD_ENCUMBER: + moveamt -= (moveamt / 2); + break; + case HVY_ENCUMBER: + moveamt -= ((moveamt * 3) / 4); + break; + case EXT_ENCUMBER: + moveamt -= ((moveamt * 7) / 8); + break; + default: + break; + } - youmonst.movement += moveamt; - if (youmonst.movement < 0) youmonst.movement = 0; - settrack(); + youmonst.movement += moveamt; + if (youmonst.movement < 0) + youmonst.movement = 0; + settrack(); - monstermoves++; - moves++; + monstermoves++; + moves++; - /********************************/ - /* once-per-turn things go here */ - /********************************/ + /********************************/ + /* once-per-turn things go here */ + /********************************/ - if (context.bypasses) clear_bypasses(); - if(Glib) glibr(); - nh_timeout(); - run_regions(); + if (context.bypasses) + clear_bypasses(); + if (Glib) + glibr(); + nh_timeout(); + run_regions(); - if (u.ublesscnt) u.ublesscnt--; - if(flags.time && !context.run) - context.botl = 1; + if (u.ublesscnt) + u.ublesscnt--; + if (flags.time && !context.run) + context.botl = 1; - /* One possible result of prayer is healing. Whether or - * not you get healed depends on your current hit points. - * If you are allowed to regenerate during the prayer, the - * end-of-prayer calculation messes up on this. - * Another possible result is rehumanization, which requires - * that encumbrance and movement rate be recalculated. - */ - if (u.uinvulnerable) { - /* for the moment at least, you're in tiptop shape */ - wtcap = UNENCUMBERED; - } else if (Upolyd && youmonst.data->mlet == S_EEL && - !is_pool(u.ux, u.uy) && !Is_waterlevel(&u.uz)) { - /* eel out of water loses hp, same as for monsters; - as hp gets lower, rate of further loss slows down */ - if (u.mh > 1 && rn2(u.mh) > rn2(8) && - (!Half_physical_damage || !(moves % 2L))) { - u.mh--; - context.botl = 1; - } else if (u.mh < 1) - rehumanize(); - } else if (Upolyd && u.mh < u.mhmax) { - if (u.mh < 1) - rehumanize(); - else if (Regeneration || - (wtcap < MOD_ENCUMBER && !(moves%20))) { - context.botl = 1; - u.mh++; - } - } else if (u.uhp < u.uhpmax && - (wtcap < MOD_ENCUMBER || !u.umoved || Regeneration)) { - if (u.ulevel > 9 && !(moves % 3)) { - int heal, Con = (int) ACURR(A_CON); + /* One possible result of prayer is healing. Whether or + * not you get healed depends on your current hit points. + * If you are allowed to regenerate during the prayer, the + * end-of-prayer calculation messes up on this. + * Another possible result is rehumanization, which + * requires + * that encumbrance and movement rate be recalculated. + */ + if (u.uinvulnerable) { + /* for the moment at least, you're in tiptop shape */ + wtcap = UNENCUMBERED; + } else if (Upolyd && youmonst.data->mlet == S_EEL + && !is_pool(u.ux, u.uy) + && !Is_waterlevel(&u.uz)) { + /* eel out of water loses hp, same as for monsters; + as hp gets lower, rate of further loss slows down + */ + if (u.mh > 1 && rn2(u.mh) > rn2(8) + && (!Half_physical_damage || !(moves % 2L))) { + u.mh--; + context.botl = 1; + } else if (u.mh < 1) + rehumanize(); + } else if (Upolyd && u.mh < u.mhmax) { + if (u.mh < 1) + rehumanize(); + else if (Regeneration + || (wtcap < MOD_ENCUMBER && !(moves % 20))) { + context.botl = 1; + u.mh++; + } + } else if (u.uhp < u.uhpmax + && (wtcap < MOD_ENCUMBER || !u.umoved + || Regeneration)) { + if (u.ulevel > 9 && !(moves % 3)) { + int heal, Con = (int) ACURR(A_CON); - if (Con <= 12) { - heal = 1; - } else { - heal = rnd(Con); - if (heal > u.ulevel-9) heal = u.ulevel-9; - } - context.botl = 1; - u.uhp += heal; - if(u.uhp > u.uhpmax) - u.uhp = u.uhpmax; - } else if (Regeneration || - (u.ulevel <= 9 && - !(moves % ((MAXULEV+12) / (u.ulevel+2) + 1)))) { - context.botl = 1; - u.uhp++; - } - } + if (Con <= 12) { + heal = 1; + } else { + heal = rnd(Con); + if (heal > u.ulevel - 9) + heal = u.ulevel - 9; + } + context.botl = 1; + u.uhp += heal; + if (u.uhp > u.uhpmax) + u.uhp = u.uhpmax; + } else if (Regeneration + || (u.ulevel <= 9 + && !(moves + % ((MAXULEV + 12) / (u.ulevel + 2) + + 1)))) { + context.botl = 1; + u.uhp++; + } + } - /* moving around while encumbered is hard work */ - if (wtcap > MOD_ENCUMBER && u.umoved) { - if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) { - if (Upolyd && u.mh > 1) { - u.mh--; - } else if (!Upolyd && u.uhp > 1) { - u.uhp--; - } else { - You("pass out from exertion!"); - exercise(A_CON, FALSE); - fall_asleep(-10, FALSE); - } - } - } + /* moving around while encumbered is hard work */ + if (wtcap > MOD_ENCUMBER && u.umoved) { + if (!(wtcap < EXT_ENCUMBER ? moves % 30 + : moves % 10)) { + if (Upolyd && u.mh > 1) { + u.mh--; + } else if (!Upolyd && u.uhp > 1) { + u.uhp--; + } else { + You("pass out from exertion!"); + exercise(A_CON, FALSE); + fall_asleep(-10, FALSE); + } + } + } - if ((u.uen < u.uenmax) && - ((wtcap < MOD_ENCUMBER && - (!(moves%((MAXULEV + 8 - u.ulevel) * - (Role_if(PM_WIZARD) ? 3 : 4) / 6)))) - || Energy_regeneration)) { - u.uen += rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1,1); - if (u.uen > u.uenmax) u.uen = u.uenmax; - context.botl = 1; - } + if ((u.uen < u.uenmax) + && ((wtcap < MOD_ENCUMBER + && (!(moves % ((MAXULEV + 8 - u.ulevel) + * (Role_if(PM_WIZARD) ? 3 : 4) + / 6)))) || Energy_regeneration)) { + u.uen += rn1( + (int) (ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1, 1); + if (u.uen > u.uenmax) + u.uen = u.uenmax; + context.botl = 1; + } - if(!u.uinvulnerable) { - if(Teleportation && !rn2(85)) { - xchar old_ux = u.ux, old_uy = u.uy; - tele(); - if (u.ux != old_ux || u.uy != old_uy) { - if (!next_to_u()) { - check_leash(old_ux, old_uy); - } - /* clear doagain keystrokes */ - pushch(0); - savech(0); - } - } - /* delayed change may not be valid anymore */ - if ((change == 1 && !Polymorph) || - (change == 2 && u.ulycn == NON_PM)) - change = 0; - if(Polymorph && !rn2(100)) - change = 1; - else if (u.ulycn >= LOW_PM && !Upolyd && - !rn2(80 - (20 * night()))) - change = 2; - if (change && !Unchanging) { - if (multi >= 0) { - if (occupation) - stop_occupation(); - else - nomul(0); - if (change == 1) polyself(0); - else you_were(); - change = 0; - } - } - } + if (!u.uinvulnerable) { + if (Teleportation && !rn2(85)) { + xchar old_ux = u.ux, old_uy = u.uy; + tele(); + if (u.ux != old_ux || u.uy != old_uy) { + if (!next_to_u()) { + check_leash(old_ux, old_uy); + } + /* clear doagain keystrokes */ + pushch(0); + savech(0); + } + } + /* delayed change may not be valid anymore */ + if ((change == 1 && !Polymorph) + || (change == 2 && u.ulycn == NON_PM)) + change = 0; + if (Polymorph && !rn2(100)) + change = 1; + else if (u.ulycn >= LOW_PM && !Upolyd + && !rn2(80 - (20 * night()))) + change = 2; + if (change && !Unchanging) { + if (multi >= 0) { + if (occupation) + stop_occupation(); + else + nomul(0); + if (change == 1) + polyself(0); + else + you_were(); + change = 0; + } + } + } - if(Searching && multi >= 0) (void) dosearch0(1); - dosounds(); - do_storms(); - gethungry(); - age_spells(); - exerchk(); - invault(); - if (u.uhave.amulet) amulet(); - if (!rn2(40+(int)(ACURR(A_DEX)*3))) - u_wipe_engr(rnd(3)); - if (u.uevent.udemigod && !u.uinvulnerable) { - if (u.udg_cnt) u.udg_cnt--; - if (!u.udg_cnt) { - intervene(); - u.udg_cnt = rn1(200, 50); - } - } - restore_attrib(); - /* underwater and waterlevel vision are done here */ - if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) - movebubbles(); - else if (Is_firelevel(&u.uz)) - fumaroles(); - else if (Underwater) - under_water(0); - /* vision while buried done here */ - else if (u.uburied) under_ground(0); + if (Searching && multi >= 0) + (void) dosearch0(1); + dosounds(); + do_storms(); + gethungry(); + age_spells(); + exerchk(); + invault(); + if (u.uhave.amulet) + amulet(); + if (!rn2(40 + (int) (ACURR(A_DEX) * 3))) + u_wipe_engr(rnd(3)); + if (u.uevent.udemigod && !u.uinvulnerable) { + if (u.udg_cnt) + u.udg_cnt--; + if (!u.udg_cnt) { + intervene(); + u.udg_cnt = rn1(200, 50); + } + } + restore_attrib(); + /* underwater and waterlevel vision are done here */ + if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) + movebubbles(); + else if (Is_firelevel(&u.uz)) + fumaroles(); + else if (Underwater) + under_water(0); + /* vision while buried done here */ + else if (u.uburied) + under_ground(0); - /* when immobile, count is in turns */ - if(multi < 0) { - if (++multi == 0) { /* finished yet? */ - unmul((char *)0); - /* if unmul caused a level change, take it now */ - if (u.utotype) deferred_goto(); - } - } - } - } while (youmonst.movement= 0 && occupation) { + if (multi >= 0 && occupation) { #if defined(MICRO) || defined(WIN32) - abort_lev = 0; - if (kbhit()) { - if ((ch = pgetchar()) == ABORT) - abort_lev++; - else - pushch(ch); - } - if (!abort_lev && (*occupation)() == 0) + abort_lev = 0; + if (kbhit()) { + if ((ch = pgetchar()) == ABORT) + abort_lev++; + else + pushch(ch); + } + if (!abort_lev && (*occupation)() == 0) #else - if ((*occupation)() == 0) + if ((*occupation)() == 0) #endif - occupation = 0; - if( + occupation = 0; + if ( #if defined(MICRO) || defined(WIN32) - abort_lev || + abort_lev || #endif - monster_nearby()) { - stop_occupation(); - reset_eat(); - } + monster_nearby()) { + stop_occupation(); + reset_eat(); + } #if defined(MICRO) || defined(WIN32) - if (!(++occtime % 7)) - display_nhwindow(WIN_MAP, FALSE); + if (!(++occtime % 7)) + display_nhwindow(WIN_MAP, FALSE); #endif - continue; - } + continue; + } - if (iflags.sanity_check) - sanity_check(); + if (iflags.sanity_check) + sanity_check(); #ifdef CLIPPING - /* just before rhack */ - cliparound(u.ux, u.uy); + /* just before rhack */ + cliparound(u.ux, u.uy); #endif - u.umoved = FALSE; + u.umoved = FALSE; - if (multi > 0) { - lookaround(); - if (!multi) { - /* lookaround may clear multi */ - context.move = 0; - if (flags.time) context.botl = 1; - continue; - } - if (context.mv) { - if(multi < COLNO && !--multi) - context.travel = context.travel1 = - context.mv = context.run = 0; - domove(); - } else { - --multi; - rhack(save_cm); - } - } else if (multi == 0) { + if (multi > 0) { + lookaround(); + if (!multi) { + /* lookaround may clear multi */ + context.move = 0; + if (flags.time) + context.botl = 1; + continue; + } + if (context.mv) { + if (multi < COLNO && !--multi) + context.travel = context.travel1 = context.mv = + context.run = 0; + domove(); + } else { + --multi; + rhack(save_cm); + } + } else if (multi == 0) { #ifdef MAIL - ckmailstatus(); + ckmailstatus(); #endif - rhack((char *)0); - } - if (u.utotype) /* change dungeon level */ - deferred_goto(); /* after rhack() */ - /* !context.move here: multiple movement command stopped */ - else if (flags.time && (!context.move || !context.mv)) - context.botl = 1; + rhack((char *) 0); + } + if (u.utotype) /* change dungeon level */ + deferred_goto(); /* after rhack() */ + /* !context.move here: multiple movement command stopped */ + else if (flags.time && (!context.move || !context.mv)) + context.botl = 1; - if (vision_full_recalc) vision_recalc(0); /* vision! */ - /* when running in non-tport mode, this gets done through domove() */ - if ((!context.run || flags.runmode == RUN_TPORT) && - (multi && (!context.travel ? !(multi % 7) : !(moves % 7L)))) { - if (flags.time && context.run) context.botl = 1; - display_nhwindow(WIN_MAP, FALSE); - } + if (vision_full_recalc) + vision_recalc(0); /* vision! */ + /* when running in non-tport mode, this gets done through domove() */ + if ((!context.run || flags.runmode == RUN_TPORT) + && (multi && (!context.travel ? !(multi % 7) : !(moves % 7L)))) { + if (flags.time && context.run) + context.botl = 1; + display_nhwindow(WIN_MAP, FALSE); + } } } void stop_occupation() { - if(occupation) { - if (!maybe_finished_meal(TRUE)) - You("stop %s.", occtxt); - occupation = 0; - context.botl = 1; /* in case u.uhs changed */ - nomul(0); - pushch(0); - } + if (occupation) { + if (!maybe_finished_meal(TRUE)) + You("stop %s.", occtxt); + occupation = 0; + context.botl = 1; /* in case u.uhs changed */ + nomul(0); + pushch(0); + } } void @@ -464,14 +513,14 @@ display_gamewindows() * have to split display_gamewindows into create_gamewindows * and show_gamewindows to get rid of this ifdef... */ - if (!strcmp(windowprocs. name, "mac")) - SanePositions(); + if (!strcmp(windowprocs.name, "mac")) + SanePositions(); #endif - /* - * The mac port is not DEPENDENT on the order of these - * displays, but it looks a lot better this way... - */ +/* + * The mac port is not DEPENDENT on the order of these + * displays, but it looks a lot better this way... + */ #ifndef STATUS_VIA_WINDOWPORT display_nhwindow(WIN_STATUS, FALSE); #endif @@ -483,81 +532,84 @@ display_gamewindows() void newgame() { - int i; + int i; #ifdef MFLOPPY - gameDiskPrompt(); + gameDiskPrompt(); #endif - context.botlx = 1; - context.ident = 1; - context.stethoscope_move = -1L; - context.warnlevel = 1; - context.next_attrib_check = 600L; /* arbitrary first setting */ - context.tribute.enabled = TRUE; /* turn on 3.6 tributes */ - context.tribute.tributesz = sizeof(struct tribute_info); + context.botlx = 1; + context.ident = 1; + context.stethoscope_move = -1L; + context.warnlevel = 1; + context.next_attrib_check = 600L; /* arbitrary first setting */ + context.tribute.enabled = TRUE; /* turn on 3.6 tributes */ + context.tribute.tributesz = sizeof(struct tribute_info); - for (i = 0; i < NUMMONS; i++) - mvitals[i].mvflags = mons[i].geno & G_NOCORPSE; + for (i = 0; i < NUMMONS; i++) + mvitals[i].mvflags = mons[i].geno & G_NOCORPSE; - init_objects(); /* must be before u_init() */ + 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() */ + 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(); /* before u_init() in case $WIZKIT specifies - * any artifacts */ - u_init(); + 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(); /* before u_init() in case $WIZKIT specifies + * any artifacts */ + u_init(); #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); + (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif #ifdef NEWS - if(iflags.news) display_file(NEWS, FALSE); + if (iflags.news) + display_file(NEWS, FALSE); #endif - load_qtlist(); /* load up the quest text info */ -/* quest_init();*/ /* Now part of role_init() */ + load_qtlist(); /* load up the quest text info */ + /* quest_init();*/ /* Now part of role_init() */ - mklev(); - u_on_upstairs(); - if (wizard) obj_delivery(FALSE); /* finish wizkit */ - vision_reset(); /* set up internals for level (after mklev) */ - check_special_room(FALSE); + mklev(); + u_on_upstairs(); + if (wizard) + obj_delivery(FALSE); /* finish wizkit */ + vision_reset(); /* set up internals for level (after mklev) */ + check_special_room(FALSE); - if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy)); - (void) makedog(); - docrt(); + if (MON_AT(u.ux, u.uy)) + mnexto(m_at(u.ux, u.uy)); + (void) makedog(); + docrt(); - if (flags.legacy) { - flush_screen(1); - com_pager(1); - } + if (flags.legacy) { + flush_screen(1); + com_pager(1); + } #ifdef INSURANCE - save_currentstate(); + save_currentstate(); #endif - program_state.something_worth_saving++; /* useful data now exists */ + program_state.something_worth_saving++; /* useful data now exists */ - urealtime.realtime = 0L; + urealtime.realtime = 0L; #if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *)&urealtime.restored); + (void) time((long *) &urealtime.restored); #else - (void) time(&urealtime.restored); + (void) time(&urealtime.restored); #endif - /* Success! */ - welcome(TRUE); - return; + /* Success! */ + welcome(TRUE); + return; } /* show "welcome [back] to nethack" message at program startup */ void welcome(new_game) -boolean new_game; /* false => restoring an old game */ +boolean new_game; /* false => restoring an old game */ { char buf[BUFSZ]; boolean currentgend = Upolyd ? u.mfemale : flags.female; @@ -572,71 +624,72 @@ boolean new_game; /* false => restoring an old game */ */ *buf = '\0'; if (new_game || u.ualignbase[A_ORIGINAL] != u.ualignbase[A_CURRENT]) - Sprintf(eos(buf), " %s", align_str(u.ualignbase[A_ORIGINAL])); - if (!urole.name.f && - (new_game ? (urole.allow & ROLE_GENDMASK) == (ROLE_MALE|ROLE_FEMALE) : - currentgend != flags.initgend)) - Sprintf(eos(buf), " %s", genders[currentgend].adj); + Sprintf(eos(buf), " %s", align_str(u.ualignbase[A_ORIGINAL])); + if (!urole.name.f + && (new_game + ? (urole.allow & ROLE_GENDMASK) == (ROLE_MALE | ROLE_FEMALE) + : currentgend != flags.initgend)) + Sprintf(eos(buf), " %s", genders[currentgend].adj); pline(new_game ? "%s %s, welcome to NetHack! You are a%s %s %s." - : "%s %s, the%s %s %s, welcome back to NetHack!", - Hello((struct monst *) 0), plname, buf, urace.adj, - (currentgend && urole.name.f) ? urole.name.f : urole.name.m); + : "%s %s, the%s %s %s, welcome back to NetHack!", + Hello((struct monst *) 0), plname, buf, urace.adj, + (currentgend && urole.name.f) ? urole.name.f : urole.name.m); } #ifdef POSITIONBAR STATIC_DCL void do_positionbar() { - static char pbar[COLNO]; - char *p; - - p = pbar; - /* up stairway */ - if (upstair.sx && - (glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) == - S_upstair || - glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) == - S_upladder)) { - *p++ = '<'; - *p++ = upstair.sx; - } - if (sstairs.sx && - (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) == - S_upstair || - glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) == - S_upladder)) { - *p++ = '<'; - *p++ = sstairs.sx; - } + static char pbar[COLNO]; + char *p; - /* down stairway */ - if (dnstair.sx && - (glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) == - S_dnstair || - glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) == - S_dnladder)) { - *p++ = '>'; - *p++ = dnstair.sx; - } - if (sstairs.sx && - (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) == - S_dnstair || - glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) == - S_dnladder)) { - *p++ = '>'; - *p++ = sstairs.sx; - } + p = pbar; + /* up stairway */ + if (upstair.sx + && (glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) + == S_upstair + || glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) + == S_upladder)) { + *p++ = '<'; + *p++ = upstair.sx; + } + if (sstairs.sx + && (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) + == S_upstair + || glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) + == S_upladder)) { + *p++ = '<'; + *p++ = sstairs.sx; + } - /* hero location */ - if (u.ux) { - *p++ = '@'; - *p++ = u.ux; - } - /* fence post */ - *p = 0; + /* down stairway */ + if (dnstair.sx + && (glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) + == S_dnstair + || glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) + == S_dnladder)) { + *p++ = '>'; + *p++ = dnstair.sx; + } + if (sstairs.sx + && (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) + == S_dnstair + || glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) + == S_dnladder)) { + *p++ = '>'; + *p++ = sstairs.sx; + } - update_positionbar(pbar); + /* hero location */ + if (u.ux) { + *p++ = '@'; + *p++ = u.ux; + } + /* fence post */ + *p = 0; + + update_positionbar(pbar); } #endif diff --git a/src/alloc.c b/src/alloc.c index a09cb05ab..e5d92c565 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,14 +1,14 @@ -/* NetHack 3.6 alloc.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 alloc.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 alloc.c $Date: 2012/01/29 03:00:17 $ $Revision: 1.8 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ /* to get the malloc() prototype from system.h */ -#define ALLOC_C /* comment line for pre-compiled headers */ +#define ALLOC_C /* comment line for pre-compiled headers */ /* since this file is also used in auxiliary programs, don't include all the * function declarations for all of nethack */ -#define EXTERN_H /* comment line for pre-compiled headers */ +#define EXTERN_H /* comment line for pre-compiled headers */ #include "config.h" char *FDECL(fmt_ptr, (const genericptr)); @@ -16,49 +16,50 @@ char *FDECL(fmt_ptr, (const genericptr)); #ifdef MONITOR_HEAP #undef alloc #undef free -extern void FDECL(free,(genericptr_t)); +extern void FDECL(free, (genericptr_t)); static void NDECL(heapmon_init); static FILE *heaplog = 0; static boolean tried_heaplog = FALSE; #endif -long *FDECL(alloc,(unsigned int)); -extern void VDECL(panic, (const char *,...)) PRINTF_F(1,2); +long *FDECL(alloc, (unsigned int)); +extern void +VDECL(panic, (const char *, ...)) +PRINTF_F(1, 2); - -long * -alloc(lth) -register unsigned int lth; +long *alloc(lth) register unsigned int lth; { #ifdef LINT -/* - * a ridiculous definition, suppressing - * "possible pointer alignment problem" for (long *) malloc() - * from lint - */ - long dummy = ftell(stderr); + /* + * a ridiculous definition, suppressing + * "possible pointer alignment problem" for (long *) malloc() + * from lint + */ + long dummy = ftell(stderr); - if(lth) dummy = 0; /* make sure arg is used */ - return(&dummy); + if (lth) + dummy = 0; /* make sure arg is used */ + return (&dummy); #else - register genericptr_t ptr; + register genericptr_t ptr; - ptr = malloc(lth); + ptr = malloc(lth); #ifndef MONITOR_HEAP - if (!ptr) panic("Memory allocation failure; cannot get %u bytes", lth); + if (!ptr) + panic("Memory allocation failure; cannot get %u bytes", lth); #endif - return((long *) ptr); + return ((long *) ptr); #endif } -# ifdef HAS_PTR_FMT -# define PTR_FMT "%p" -# define PTR_TYP genericptr_t -# else -# define PTR_FMT "%06lx" -# define PTR_TYP unsigned long -# endif +#ifdef HAS_PTR_FMT +#define PTR_FMT "%p" +#define PTR_TYP genericptr_t +#else +#define PTR_FMT "%06lx" +#define PTR_TYP unsigned long +#endif /* A small pool of static formatting buffers. * PTRBUFSIZ: We assume that pointers will be formatted as integers in @@ -79,13 +80,14 @@ char * fmt_ptr(ptr) const genericptr ptr; { - char *buf; + char *buf; - buf = ptrbuf[ptrbufidx]; - if (++ptrbufidx >= PTRBUFCNT) ptrbufidx = 0; + buf = ptrbuf[ptrbufidx]; + if (++ptrbufidx >= PTRBUFCNT) + ptrbufidx = 0; - Sprintf(buf, PTR_FMT, (PTR_TYP)ptr); - return buf; + Sprintf(buf, PTR_FMT, (PTR_TYP) ptr); + return buf; } #ifdef MONITOR_HEAP @@ -95,11 +97,11 @@ const genericptr ptr; static void heapmon_init() { - char *logname = getenv("NH_HEAPLOG"); + char *logname = getenv("NH_HEAPLOG"); - if (logname && *logname) - heaplog = fopen(logname, "w"); - tried_heaplog = TRUE; + if (logname && *logname) + heaplog = fopen(logname, "w"); + tried_heaplog = TRUE; } long * @@ -108,17 +110,18 @@ unsigned int lth; const char *file; int line; { - long *ptr = alloc(lth); + long *ptr = alloc(lth); - if (!tried_heaplog) heapmon_init(); - if (heaplog) - (void) fprintf(heaplog, "+%5u %s %4d %s\n", lth, - fmt_ptr((genericptr_t)ptr), line, file); - /* potential panic in alloc() was deferred til here */ - if (!ptr) panic("Cannot get %u bytes, line %d of %s", - lth, line, file); + if (!tried_heaplog) + heapmon_init(); + if (heaplog) + (void) fprintf(heaplog, "+%5u %s %4d %s\n", lth, + fmt_ptr((genericptr_t) ptr), line, file); + /* potential panic in alloc() was deferred til here */ + if (!ptr) + panic("Cannot get %u bytes, line %d of %s", lth, line, file); - return ptr; + return ptr; } void @@ -127,12 +130,13 @@ genericptr_t ptr; const char *file; int line; { - if (!tried_heaplog) heapmon_init(); - if (heaplog) - (void) fprintf(heaplog, "- %s %4d %s\n", - fmt_ptr((genericptr_t)ptr), line, file); + if (!tried_heaplog) + heapmon_init(); + if (heaplog) + (void) fprintf(heaplog, "- %s %4d %s\n", + fmt_ptr((genericptr_t) ptr), line, file); - free(ptr); + free(ptr); } /* strdup() which uses our alloc() rather than libc's malloc(), @@ -143,7 +147,7 @@ const char *string; const char *file; int line; { - return strcpy((char *)nhalloc(strlen(string) + 1, file, line), string); + return strcpy((char *) nhalloc(strlen(string) + 1, file, line), string); } #undef dupstr @@ -156,7 +160,7 @@ char * dupstr(string) const char *string; { - return strcpy((char *)alloc(strlen(string) + 1), string); + return strcpy((char *) alloc(strlen(string) + 1), string); } /*alloc.c*/ diff --git a/src/apply.c b/src/apply.c index ea0454385..eb4b57c1d 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1,15 +1,15 @@ -/* NetHack 3.6 apply.c $NHDT-Date: 1426465431 2015/03/16 00:23:51 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.173 $ */ +/* NetHack 3.6 apply.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.196 $ */ /* NetHack 3.6 apply.c $Date: 2012/05/01 02:22:32 $ $Revision: 1.168 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ STATIC_DCL int FDECL(use_camera, (struct obj *)); STATIC_DCL int FDECL(use_towel, (struct obj *)); -STATIC_DCL boolean FDECL(its_dead, (int,int,int *)); +STATIC_DCL boolean FDECL(its_dead, (int, int, int *)); STATIC_DCL int FDECL(use_stethoscope, (struct obj *)); STATIC_DCL void FDECL(use_whistle, (struct obj *)); STATIC_DCL void FDECL(use_magic_whistle, (struct obj *)); @@ -26,136 +26,138 @@ STATIC_DCL void FDECL(use_figurine, (struct obj **)); STATIC_DCL void FDECL(use_grease, (struct obj *)); STATIC_DCL void FDECL(use_trap, (struct obj *)); STATIC_DCL void FDECL(use_stone, (struct obj *)); -STATIC_PTR int NDECL(set_trap); /* occupation callback */ +STATIC_PTR int NDECL(set_trap); /* occupation callback */ STATIC_DCL int FDECL(use_whip, (struct obj *)); STATIC_PTR void FDECL(display_polearm_positions, (int)); STATIC_DCL int FDECL(use_pole, (struct obj *)); STATIC_DCL int FDECL(use_cream_pie, (struct obj *)); STATIC_DCL int FDECL(use_grapple, (struct obj *)); STATIC_DCL int FDECL(do_break_wand, (struct obj *)); -STATIC_DCL boolean FDECL(figurine_location_checks, - (struct obj *, coord *, BOOLEAN_P)); +STATIC_DCL boolean +FDECL(figurine_location_checks, (struct obj *, coord *, BOOLEAN_P)); STATIC_DCL void FDECL(add_class, (char *, CHAR_P)); STATIC_DCL void FDECL(setapplyclasses, (char *)); STATIC_DCL boolean FDECL(is_valid_jump_pos, (int, int, int, BOOLEAN_P)); STATIC_DCL boolean FDECL(find_poleable_mon, (coord *, int, int)); -#ifdef AMIGA -void FDECL( amii_speaker, ( struct obj *, char *, int ) ); +#ifdef AMIGA +void FDECL(amii_speaker, (struct obj *, char *, int)); #endif -static const char no_elbow_room[] = "don't have enough elbow-room to maneuver."; +static const char no_elbow_room[] = + "don't have enough elbow-room to maneuver."; STATIC_OVL int use_camera(obj) - struct obj *obj; +struct obj *obj; { - register struct monst *mtmp; + register struct monst *mtmp; - if(Underwater) { - pline("Using your camera underwater would void the warranty."); - return(0); - } - if(!getdir((char *)0)) return(0); + if (Underwater) { + pline("Using your camera underwater would void the warranty."); + return (0); + } + if (!getdir((char *) 0)) + return (0); - if (obj->spe <= 0) { - pline1(nothing_happens); - return (1); - } - consume_obj_charge(obj, TRUE); + if (obj->spe <= 0) { + pline1(nothing_happens); + return (1); + } + consume_obj_charge(obj, TRUE); - if (obj->cursed && !rn2(2)) { - (void) zapyourself(obj, TRUE); - } else if (u.uswallow) { - You("take a picture of %s %s.", s_suffix(mon_nam(u.ustuck)), - mbodypart(u.ustuck, STOMACH)); - } else if (u.dz) { - You("take a picture of the %s.", - (u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy)); - } else if (!u.dx && !u.dy) { - (void) zapyourself(obj, TRUE); - } else if ((mtmp = bhit(u.dx, u.dy, COLNO, FLASHED_LIGHT, - (int FDECL((*),(MONST_P,OBJ_P)))0, - (int FDECL((*),(OBJ_P,OBJ_P)))0, - &obj)) != 0) { - obj->ox = u.ux, obj->oy = u.uy; - (void) flash_hits_mon(mtmp, obj); - } - return 1; + if (obj->cursed && !rn2(2)) { + (void) zapyourself(obj, TRUE); + } else if (u.uswallow) { + You("take a picture of %s %s.", s_suffix(mon_nam(u.ustuck)), + mbodypart(u.ustuck, STOMACH)); + } else if (u.dz) { + You("take a picture of the %s.", + (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy)); + } else if (!u.dx && !u.dy) { + (void) zapyourself(obj, TRUE); + } else if ((mtmp = bhit(u.dx, u.dy, COLNO, FLASHED_LIGHT, + (int FDECL((*), (MONST_P, OBJ_P))) 0, + (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj)) != 0) { + obj->ox = u.ux, obj->oy = u.uy; + (void) flash_hits_mon(mtmp, obj); + } + return 1; } STATIC_OVL int use_towel(obj) - struct obj *obj; +struct obj *obj; { - if(!freehand()) { - You("have no free %s!", body_part(HAND)); - return 0; - } else if (obj == ublindf) { - You("cannot use it while you're wearing it!"); - return 0; - } else if (obj->cursed) { - long old; - switch (rn2(3)) { - case 2: - old = Glib; - incr_itimeout(&Glib, rn1(10, 3)); - Your("%s %s!", makeplural(body_part(HAND)), - (old ? "are filthier than ever" : "get slimy")); - return 1; - case 1: - if (!ublindf) { - old = u.ucreamed; - u.ucreamed += rn1(10, 3); - pline("Yecch! Your %s %s gunk on it!", body_part(FACE), - (old ? "has more" : "now has")); - make_blinded(Blinded + (long)u.ucreamed - old, TRUE); - } else { - const char *what; + if (!freehand()) { + You("have no free %s!", body_part(HAND)); + return 0; + } else if (obj == ublindf) { + You("cannot use it while you're wearing it!"); + return 0; + } else if (obj->cursed) { + long old; + switch (rn2(3)) { + case 2: + old = Glib; + incr_itimeout(&Glib, rn1(10, 3)); + Your("%s %s!", makeplural(body_part(HAND)), + (old ? "are filthier than ever" : "get slimy")); + return 1; + case 1: + if (!ublindf) { + old = u.ucreamed; + u.ucreamed += rn1(10, 3); + pline("Yecch! Your %s %s gunk on it!", body_part(FACE), + (old ? "has more" : "now has")); + make_blinded(Blinded + (long) u.ucreamed - old, TRUE); + } else { + const char *what; - what = (ublindf->otyp == LENSES) ? "lenses" : - (obj->otyp == ublindf->otyp) ? "other towel" : - "blindfold"; - if (ublindf->cursed) { - You("push your %s %s.", what, - rn2(2) ? "cock-eyed" : "crooked"); - } else { - struct obj *saved_ublindf = ublindf; - You("push your %s off.", what); - Blindf_off(ublindf); - dropx(saved_ublindf); - } - } - return 1; - case 0: - break; - } - } + what = (ublindf->otyp == LENSES) + ? "lenses" + : (obj->otyp == ublindf->otyp) ? "other towel" + : "blindfold"; + if (ublindf->cursed) { + You("push your %s %s.", what, + rn2(2) ? "cock-eyed" : "crooked"); + } else { + struct obj *saved_ublindf = ublindf; + You("push your %s off.", what); + Blindf_off(ublindf); + dropx(saved_ublindf); + } + } + return 1; + case 0: + break; + } + } - if (Glib) { - Glib = 0; - You("wipe off your %s.", makeplural(body_part(HAND))); - return 1; - } else if(u.ucreamed) { - Blinded -= u.ucreamed; - u.ucreamed = 0; + if (Glib) { + Glib = 0; + You("wipe off your %s.", makeplural(body_part(HAND))); + return 1; + } else if (u.ucreamed) { + Blinded -= u.ucreamed; + u.ucreamed = 0; - if (!Blinded) { - pline("You've got the glop off."); - if (!gulp_blnd_check()) { - Blinded = 1; - make_blinded(0L,TRUE); - } - } else { - Your("%s feels clean now.", body_part(FACE)); - } - return 1; - } + if (!Blinded) { + pline("You've got the glop off."); + if (!gulp_blnd_check()) { + Blinded = 1; + make_blinded(0L, TRUE); + } + } else { + Your("%s feels clean now.", body_part(FACE)); + } + return 1; + } - Your("%s and %s are already clean.", - body_part(FACE), makeplural(body_part(HAND))); + Your("%s and %s are already clean.", body_part(FACE), + makeplural(body_part(HAND))); - return 0; + return 0; } /* maybe give a stethoscope message based on floor objects */ @@ -167,106 +169,108 @@ int rx, ry, *resp; boolean more_corpses; struct permonst *mptr; struct obj *corpse = sobj_at(CORPSE, rx, ry), - *statue = sobj_at(STATUE, rx, ry); + *statue = sobj_at(STATUE, rx, ry); - if (!can_reach_floor(TRUE)) { /* levitation or unskilled riding */ - corpse = 0; /* can't reach corpse on floor */ - /* you can't reach tiny statues (even though you can fight - tiny monsters while levitating--consistency, what's that?) */ - while (statue && mons[statue->corpsenm].msize == MZ_TINY) - statue = nxtobj(statue, STATUE, TRUE); + if (!can_reach_floor(TRUE)) { /* levitation or unskilled riding */ + corpse = 0; /* can't reach corpse on floor */ + /* you can't reach tiny statues (even though you can fight + tiny monsters while levitating--consistency, what's that?) */ + while (statue && mons[statue->corpsenm].msize == MZ_TINY) + statue = nxtobj(statue, STATUE, TRUE); } /* when both corpse and statue are present, pick the uppermost one */ if (corpse && statue) { - if (nxtobj(statue, CORPSE, TRUE) == corpse) - corpse = 0; /* corpse follows statue; ignore it */ - else - statue = 0; /* corpse precedes statue; ignore statue */ + if (nxtobj(statue, CORPSE, TRUE) == corpse) + corpse = 0; /* corpse follows statue; ignore it */ + else + statue = 0; /* corpse precedes statue; ignore statue */ } more_corpses = (corpse && nxtobj(corpse, CORPSE, TRUE)); /* additional stethoscope messages from jyoung@apanix.apana.org.au */ if (!corpse && !statue) { - ; /* nothing to do */ + ; /* nothing to do */ } else if (Hallucination) { - if (!corpse) { - /* it's a statue */ - Strcpy(buf, "You're both stoned"); - } else if (corpse->quan == 1L && !more_corpses) { - int gndr = 2; /* neuter: "it" */ - struct monst *mtmp = get_mtraits(corpse, FALSE); + if (!corpse) { + /* it's a statue */ + Strcpy(buf, "You're both stoned"); + } else if (corpse->quan == 1L && !more_corpses) { + int gndr = 2; /* neuter: "it" */ + struct monst *mtmp = get_mtraits(corpse, FALSE); - /* (most corpses don't retain the monster's sex, so - we're usually forced to use generic pronoun here) */ - if (mtmp) { - mptr = &mons[mtmp->mnum]; - /* can't use mhe() here; it calls pronoun_gender() which - expects monster to be on the map (visibility check) */ - if ((humanoid(mptr) || (mptr->geno & G_UNIQ) || - type_is_pname(mptr)) && !is_neuter(mptr)) - gndr = (int)mtmp->female; - } else { - mptr = &mons[corpse->corpsenm]; - if (is_female(mptr)) gndr = 1; - else if (is_male(mptr)) gndr = 0; - } - Sprintf(buf, "%s's dead", genders[gndr].he); /* "he"/"she"/"it" */ - buf[0] = highc(buf[0]); - } else { /* plural */ - Strcpy(buf, "They're dead"); - } - /* variations on "He's dead, Jim." (Star Trek's Dr McCoy) */ - You_hear("a voice say, \"%s, Jim.\"", buf); - *resp = 1; - return TRUE; + /* (most corpses don't retain the monster's sex, so + we're usually forced to use generic pronoun here) */ + if (mtmp) { + mptr = &mons[mtmp->mnum]; + /* can't use mhe() here; it calls pronoun_gender() which + expects monster to be on the map (visibility check) */ + if ((humanoid(mptr) || (mptr->geno & G_UNIQ) + || type_is_pname(mptr)) && !is_neuter(mptr)) + gndr = (int) mtmp->female; + } else { + mptr = &mons[corpse->corpsenm]; + if (is_female(mptr)) + gndr = 1; + else if (is_male(mptr)) + gndr = 0; + } + Sprintf(buf, "%s's dead", genders[gndr].he); /* "he"/"she"/"it" */ + buf[0] = highc(buf[0]); + } else { /* plural */ + Strcpy(buf, "They're dead"); + } + /* variations on "He's dead, Jim." (Star Trek's Dr McCoy) */ + You_hear("a voice say, \"%s, Jim.\"", buf); + *resp = 1; + return TRUE; } else if (corpse) { - boolean here = (rx == u.ux && ry == u.uy), - one = (corpse->quan == 1L && !more_corpses), - reviver = FALSE; + boolean here = (rx == u.ux && ry == u.uy), + one = (corpse->quan == 1L && !more_corpses), reviver = FALSE; - if (Role_if(PM_HEALER)) { - /* ok to reset `corpse' here; we're done with it */ - do { - if (obj_has_timer(corpse, REVIVE_MON)) - reviver = TRUE; - else - corpse = nxtobj(corpse, CORPSE, TRUE); - } while (corpse && !reviver); - } - You("determine that %s unfortunate being%s %s%s dead.", - one ? (here ? "this" : "that") : (here ? "these" : "those"), - one ? "" : "s", one ? "is" : "are", - reviver ? " mostly" : ""); - return TRUE; + if (Role_if(PM_HEALER)) { + /* ok to reset `corpse' here; we're done with it */ + do { + if (obj_has_timer(corpse, REVIVE_MON)) + reviver = TRUE; + else + corpse = nxtobj(corpse, CORPSE, TRUE); + } while (corpse && !reviver); + } + You("determine that %s unfortunate being%s %s%s dead.", + one ? (here ? "this" : "that") : (here ? "these" : "those"), + one ? "" : "s", one ? "is" : "are", reviver ? " mostly" : ""); + return TRUE; - } else { /* statue */ - const char *what, *how; + } else { /* statue */ + const char *what, *how; - mptr = &mons[statue->corpsenm]; - if (Blind) { /* ignore statue->dknown; it'll always be set */ - Sprintf(buf, "%s %s", - (rx == u.ux && ry == u.uy) ? "This" : "That", - humanoid(mptr) ? "person" : "creature"); - what = buf; - } else { - what = mptr->mname; - if (!type_is_pname(mptr)) what = The(what); - } - how = "fine"; - if (Role_if(PM_HEALER)) { - struct trap *ttmp = t_at(rx, ry); + mptr = &mons[statue->corpsenm]; + if (Blind) { /* ignore statue->dknown; it'll always be set */ + Sprintf(buf, "%s %s", + (rx == u.ux && ry == u.uy) ? "This" : "That", + humanoid(mptr) ? "person" : "creature"); + what = buf; + } else { + what = mptr->mname; + if (!type_is_pname(mptr)) + what = The(what); + } + how = "fine"; + if (Role_if(PM_HEALER)) { + struct trap *ttmp = t_at(rx, ry); - if (ttmp && ttmp->ttyp == STATUE_TRAP) how = "extraordinary"; - else if (Has_contents(statue)) how = "remarkable"; - } - - pline("%s is in %s health for a statue.", what, how); - return TRUE; + if (ttmp && ttmp->ttyp == STATUE_TRAP) + how = "extraordinary"; + else if (Has_contents(statue)) + how = "remarkable"; + } + pline("%s is in %s health for a statue.", what, how); + return TRUE; } - return FALSE; /* no corpse or statue */ + return FALSE; /* no corpse or statue */ } static const char hollow_str[] = "a hollow sound. This must be a secret %s!"; @@ -277,130 +281,136 @@ static const char hollow_str[] = "a hollow sound. This must be a secret %s!"; uses up the turn; this makes curse status have a tangible effect. */ STATIC_OVL int use_stethoscope(obj) - register struct obj *obj; +register struct obj *obj; { - struct monst *mtmp; - struct rm *lev; - int rx, ry, res; - boolean interference = (u.uswallow && is_whirly(u.ustuck->data) && - !rn2(Role_if(PM_HEALER) ? 10 : 3)); + struct monst *mtmp; + struct rm *lev; + int rx, ry, res; + boolean interference = (u.uswallow && is_whirly(u.ustuck->data) + && !rn2(Role_if(PM_HEALER) ? 10 : 3)); - if (nohands(youmonst.data)) { - You("have no hands!"); /* not `body_part(HAND)' */ - return 0; - } else if (Deaf) { - You_cant("hear anything!"); - return 0; - } else if (!freehand()) { - You("have no free %s.", body_part(HAND)); - return 0; - } - if (!getdir((char *)0)) return 0; + if (nohands(youmonst.data)) { + You("have no hands!"); /* not `body_part(HAND)' */ + return 0; + } else if (Deaf) { + You_cant("hear anything!"); + return 0; + } else if (!freehand()) { + You("have no free %s.", body_part(HAND)); + return 0; + } + if (!getdir((char *) 0)) + return 0; - res = (moves == context.stethoscope_move) && - (youmonst.movement == context.stethoscope_movement); - context.stethoscope_move = moves; - context.stethoscope_movement = youmonst.movement; + res = (moves == context.stethoscope_move) + && (youmonst.movement == context.stethoscope_movement); + context.stethoscope_move = moves; + context.stethoscope_movement = youmonst.movement; - if (u.usteed && u.dz > 0) { - if (interference) { - pline("%s interferes.", Monnam(u.ustuck)); - mstatusline(u.ustuck); - } else - mstatusline(u.usteed); - return res; - } else - if (u.uswallow && (u.dx || u.dy || u.dz)) { - mstatusline(u.ustuck); - return res; - } else if (u.uswallow && interference) { - pline("%s interferes.", Monnam(u.ustuck)); - mstatusline(u.ustuck); - return res; - } else if (u.dz) { - if (Underwater) - You_hear("faint splashing."); - else if (u.dz < 0 || !can_reach_floor(TRUE)) - cant_reach_floor(u.ux, u.uy, (u.dz < 0), TRUE); - else if (its_dead(u.ux, u.uy, &res)) - ; /* message already given */ - else if (Is_stronghold(&u.uz)) - You_hear("the crackling of hellfire."); - else - pline_The("%s seems healthy enough.", surface(u.ux,u.uy)); - return res; - } else if (obj->cursed && !rn2(2)) { - You_hear("your heart beat."); - return res; - } - if (Stunned || (Confusion && !rn2(5))) confdir(); - if (!u.dx && !u.dy) { - ustatusline(); - return res; - } - rx = u.ux + u.dx; ry = u.uy + u.dy; - if (!isok(rx,ry)) { - You_hear("a faint typing noise."); - return 0; - } - if ((mtmp = m_at(rx,ry)) != 0) { - const char *mnm = x_monnam(mtmp, ARTICLE_A, (const char *)0, - SUPPRESS_IT|SUPPRESS_INVISIBLE, FALSE); + if (u.usteed && u.dz > 0) { + if (interference) { + pline("%s interferes.", Monnam(u.ustuck)); + mstatusline(u.ustuck); + } else + mstatusline(u.usteed); + return res; + } else if (u.uswallow && (u.dx || u.dy || u.dz)) { + mstatusline(u.ustuck); + return res; + } else if (u.uswallow && interference) { + pline("%s interferes.", Monnam(u.ustuck)); + mstatusline(u.ustuck); + return res; + } else if (u.dz) { + if (Underwater) + You_hear("faint splashing."); + else if (u.dz < 0 || !can_reach_floor(TRUE)) + cant_reach_floor(u.ux, u.uy, (u.dz < 0), TRUE); + else if (its_dead(u.ux, u.uy, &res)) + ; /* message already given */ + else if (Is_stronghold(&u.uz)) + You_hear("the crackling of hellfire."); + else + pline_The("%s seems healthy enough.", surface(u.ux, u.uy)); + return res; + } else if (obj->cursed && !rn2(2)) { + You_hear("your heart beat."); + return res; + } + if (Stunned || (Confusion && !rn2(5))) + confdir(); + if (!u.dx && !u.dy) { + ustatusline(); + return res; + } + rx = u.ux + u.dx; + ry = u.uy + u.dy; + if (!isok(rx, ry)) { + You_hear("a faint typing noise."); + return 0; + } + if ((mtmp = m_at(rx, ry)) != 0) { + const char *mnm = x_monnam(mtmp, ARTICLE_A, (const char *) 0, + SUPPRESS_IT | SUPPRESS_INVISIBLE, FALSE); - if (mtmp->mundetected) { - if (!canspotmon(mtmp)) - There("is %s hidden there.", mnm); - mtmp->mundetected = 0; - newsym(mtmp->mx, mtmp->my); - } else if (mtmp->mappearance) { - const char *what = "thing"; + if (mtmp->mundetected) { + if (!canspotmon(mtmp)) + There("is %s hidden there.", mnm); + mtmp->mundetected = 0; + newsym(mtmp->mx, mtmp->my); + } else if (mtmp->mappearance) { + const char *what = "thing"; - switch (mtmp->m_ap_type) { - case M_AP_OBJECT: - what = simple_typename(mtmp->mappearance); - break; - case M_AP_MONSTER: /* ignore Hallucination here */ - what = mons[mtmp->mappearance].mname; - break; - case M_AP_FURNITURE: - what = defsyms[mtmp->mappearance].explanation; - break; - } - seemimic(mtmp); - pline("That %s is really %s", what, mnm); - } else if (flags.verbose && !canspotmon(mtmp)) { - There("is %s there.", mnm); - } - mstatusline(mtmp); - if (!canspotmon(mtmp)) - map_invisible(rx,ry); - return res; - } - if (glyph_is_invisible(levl[rx][ry].glyph)) { - unmap_object(rx, ry); - newsym(rx, ry); - pline_The("invisible monster must have moved."); - } - lev = &levl[rx][ry]; - switch(lev->typ) { - case SDOOR: - You_hear(hollow_str, "door"); - cvt_sdoor_to_door(lev); /* ->typ = DOOR */ - if (Blind) feel_location(rx,ry); - else newsym(rx,ry); - return res; - case SCORR: - You_hear(hollow_str, "passage"); - lev->typ = CORR; - unblock_point(rx,ry); - if (Blind) feel_location(rx,ry); - else newsym(rx,ry); - return res; - } + switch (mtmp->m_ap_type) { + case M_AP_OBJECT: + what = simple_typename(mtmp->mappearance); + break; + case M_AP_MONSTER: /* ignore Hallucination here */ + what = mons[mtmp->mappearance].mname; + break; + case M_AP_FURNITURE: + what = defsyms[mtmp->mappearance].explanation; + break; + } + seemimic(mtmp); + pline("That %s is really %s", what, mnm); + } else if (flags.verbose && !canspotmon(mtmp)) { + There("is %s there.", mnm); + } + mstatusline(mtmp); + if (!canspotmon(mtmp)) + map_invisible(rx, ry); + return res; + } + if (glyph_is_invisible(levl[rx][ry].glyph)) { + unmap_object(rx, ry); + newsym(rx, ry); + pline_The("invisible monster must have moved."); + } + lev = &levl[rx][ry]; + switch (lev->typ) { + case SDOOR: + You_hear(hollow_str, "door"); + cvt_sdoor_to_door(lev); /* ->typ = DOOR */ + if (Blind) + feel_location(rx, ry); + else + newsym(rx, ry); + return res; + case SCORR: + You_hear(hollow_str, "passage"); + lev->typ = CORR; + unblock_point(rx, ry); + if (Blind) + feel_location(rx, ry); + else + newsym(rx, ry); + return res; + } - if (!its_dead(rx, ry, &res)) - You("hear nothing special."); /* not You_hear() */ - return res; + if (!its_dead(rx, ry, &res)) + You("hear nothing special."); /* not You_hear() */ + return res; } static const char whistle_str[] = "produce a %s whistling sound."; @@ -409,309 +419,328 @@ STATIC_OVL void use_whistle(obj) struct obj *obj; { - if (!can_blow(&youmonst)) { - You("are incapable of using the whistle."); - } else if(Underwater) { - You("blow bubbles through %s.", yname(obj)); - } else { - You(whistle_str, obj->cursed ? "shrill" : "high"); - wake_nearby(); - } + if (!can_blow(&youmonst)) { + You("are incapable of using the whistle."); + } else if (Underwater) { + You("blow bubbles through %s.", yname(obj)); + } else { + You(whistle_str, obj->cursed ? "shrill" : "high"); + wake_nearby(); + } } STATIC_OVL void use_magic_whistle(obj) struct obj *obj; { - register struct monst *mtmp, *nextmon; + register struct monst *mtmp, *nextmon; - if (!can_blow(&youmonst)) { - You("are incapable of using the whistle."); - } else if (obj->cursed && !rn2(2)) { - You("produce a %shigh-pitched humming noise.", - Underwater ? "very " : ""); - wake_nearby(); - } else { - int pet_cnt = 0, omx, omy; + if (!can_blow(&youmonst)) { + You("are incapable of using the whistle."); + } else if (obj->cursed && !rn2(2)) { + You("produce a %shigh-pitched humming noise.", + Underwater ? "very " : ""); + wake_nearby(); + } else { + int pet_cnt = 0, omx, omy; - /* it's magic! it works underwater too (at a higher pitch) */ - You(whistle_str, Hallucination ? "normal" : - Underwater ? "strange, high-pitched" : "strange"); - for(mtmp = fmon; mtmp; mtmp = nextmon) { - nextmon = mtmp->nmon; /* trap might kill mon */ - if (DEADMONSTER(mtmp)) continue; - /* steed is already at your location, so not affected; - this avoids trap issues if you're on a trap location */ - if (mtmp == u.usteed) continue; - if (mtmp->mtame) { - if (mtmp->mtrapped) { - /* no longer in previous trap (affects mintrap) */ - mtmp->mtrapped = 0; - fill_pit(mtmp->mx, mtmp->my); - } - /* mimic must be revealed before we know whether it - actually moves because line-of-sight may change */ - if (mtmp->m_ap_type) seemimic(mtmp); - omx = mtmp->mx, omy = mtmp->my; - mnexto(mtmp); - if (mtmp->mx != omx || mtmp->my != omy) { - mtmp->mundetected = 0; /* reveal non-mimic hider */ - if (canspotmon(mtmp)) ++pet_cnt; - if (mintrap(mtmp) == 2) change_luck(-1); - } - } - } - if (pet_cnt > 0) makeknown(obj->otyp); - } + /* it's magic! it works underwater too (at a higher pitch) */ + You(whistle_str, + Hallucination ? "normal" : Underwater ? "strange, high-pitched" + : "strange"); + for (mtmp = fmon; mtmp; mtmp = nextmon) { + nextmon = mtmp->nmon; /* trap might kill mon */ + if (DEADMONSTER(mtmp)) + continue; + /* steed is already at your location, so not affected; + this avoids trap issues if you're on a trap location */ + if (mtmp == u.usteed) + continue; + if (mtmp->mtame) { + if (mtmp->mtrapped) { + /* no longer in previous trap (affects mintrap) */ + mtmp->mtrapped = 0; + fill_pit(mtmp->mx, mtmp->my); + } + /* mimic must be revealed before we know whether it + actually moves because line-of-sight may change */ + if (mtmp->m_ap_type) + seemimic(mtmp); + omx = mtmp->mx, omy = mtmp->my; + mnexto(mtmp); + if (mtmp->mx != omx || mtmp->my != omy) { + mtmp->mundetected = 0; /* reveal non-mimic hider */ + if (canspotmon(mtmp)) + ++pet_cnt; + if (mintrap(mtmp) == 2) + change_luck(-1); + } + } + } + if (pet_cnt > 0) + makeknown(obj->otyp); + } } boolean -um_dist(x,y,n) +um_dist(x, y, n) register xchar x, y, n; { - return((boolean)(abs(u.ux - x) > n || abs(u.uy - y) > n)); + return ((boolean)(abs(u.ux - x) > n || abs(u.uy - y) > n)); } int number_leashed() { - register int i = 0; - register struct obj *obj; + register int i = 0; + register struct obj *obj; - for(obj = invent; obj; obj = obj->nobj) - if(obj->otyp == LEASH && obj->leashmon != 0) i++; - return(i); + for (obj = invent; obj; obj = obj->nobj) + if (obj->otyp == LEASH && obj->leashmon != 0) + i++; + return (i); } -void -o_unleash(otmp) /* otmp is about to be destroyed or stolen */ +void o_unleash(otmp) /* otmp is about to be destroyed or stolen */ register struct obj *otmp; { - register struct monst *mtmp; + register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if(mtmp->m_id == (unsigned)otmp->leashmon) - mtmp->mleashed = 0; - otmp->leashmon = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (mtmp->m_id == (unsigned) otmp->leashmon) + mtmp->mleashed = 0; + otmp->leashmon = 0; } -void -m_unleash(mtmp, feedback) /* mtmp is about to die, or become untame */ +void m_unleash(mtmp, feedback) /* mtmp is about to die, or become untame */ register struct monst *mtmp; boolean feedback; { - register struct obj *otmp; + register struct obj *otmp; - if (feedback) { - if (canseemon(mtmp)) - pline("%s pulls free of %s leash!", Monnam(mtmp), mhis(mtmp)); - else - Your("leash falls slack."); - } - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == LEASH && - otmp->leashmon == (int)mtmp->m_id) - otmp->leashmon = 0; - mtmp->mleashed = 0; + if (feedback) { + if (canseemon(mtmp)) + pline("%s pulls free of %s leash!", Monnam(mtmp), mhis(mtmp)); + else + Your("leash falls slack."); + } + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == LEASH && otmp->leashmon == (int) mtmp->m_id) + otmp->leashmon = 0; + mtmp->mleashed = 0; } -void -unleash_all() /* player is about to die (for bones) */ +void unleash_all() /* player is about to die (for bones) */ { - register struct obj *otmp; - register struct monst *mtmp; + register struct obj *otmp; + register struct monst *mtmp; - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == LEASH) otmp->leashmon = 0; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - mtmp->mleashed = 0; + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == LEASH) + otmp->leashmon = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + mtmp->mleashed = 0; } -#define MAXLEASHED 2 +#define MAXLEASHED 2 /* ARGSUSED */ STATIC_OVL void use_leash(obj) struct obj *obj; { - coord cc; - register struct monst *mtmp; - int spotmon; + coord cc; + register struct monst *mtmp; + int spotmon; - if(!obj->leashmon && number_leashed() >= MAXLEASHED) { - You("cannot leash any more pets."); - return; - } + if (!obj->leashmon && number_leashed() >= MAXLEASHED) { + You("cannot leash any more pets."); + return; + } - if(!get_adjacent_loc((char *)0, (char *)0, u.ux, u.uy, &cc)) return; + if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc)) + return; - if((cc.x == u.ux) && (cc.y == u.uy)) { - if (u.usteed && u.dz > 0) { - mtmp = u.usteed; - spotmon = 1; - goto got_target; - } - pline("Leash yourself? Very funny..."); - return; - } + if ((cc.x == u.ux) && (cc.y == u.uy)) { + if (u.usteed && u.dz > 0) { + mtmp = u.usteed; + spotmon = 1; + goto got_target; + } + pline("Leash yourself? Very funny..."); + return; + } - if(!(mtmp = m_at(cc.x, cc.y))) { - There("is no creature there."); - return; - } + if (!(mtmp = m_at(cc.x, cc.y))) { + There("is no creature there."); + return; + } - spotmon = canspotmon(mtmp); - got_target: + spotmon = canspotmon(mtmp); +got_target: - if(!mtmp->mtame) { - if(!spotmon) - There("is no creature there."); - else - pline("%s %s leashed!", Monnam(mtmp), (!obj->leashmon) ? - "cannot be" : "is not"); - return; - } - if(!obj->leashmon) { - if(mtmp->mleashed) { - pline("This %s is already leashed.", - spotmon ? l_monnam(mtmp) : "monster"); - return; - } - You("slip the leash around %s%s.", - spotmon ? "your " : "", l_monnam(mtmp)); - mtmp->mleashed = 1; - obj->leashmon = (int)mtmp->m_id; - mtmp->msleeping = 0; - return; - } - if(obj->leashmon != (int)mtmp->m_id) { - pline("This leash is not attached to that creature."); - return; - } else { - if(obj->cursed) { - pline_The("leash would not come off!"); - obj->bknown = TRUE; - return; - } - mtmp->mleashed = 0; - obj->leashmon = 0; - You("remove the leash from %s%s.", - spotmon ? "your " : "", l_monnam(mtmp)); - } - return; + if (!mtmp->mtame) { + if (!spotmon) + There("is no creature there."); + else + pline("%s %s leashed!", Monnam(mtmp), + (!obj->leashmon) ? "cannot be" : "is not"); + return; + } + if (!obj->leashmon) { + if (mtmp->mleashed) { + pline("This %s is already leashed.", + spotmon ? l_monnam(mtmp) : "monster"); + return; + } + You("slip the leash around %s%s.", spotmon ? "your " : "", + l_monnam(mtmp)); + mtmp->mleashed = 1; + obj->leashmon = (int) mtmp->m_id; + mtmp->msleeping = 0; + return; + } + if (obj->leashmon != (int) mtmp->m_id) { + pline("This leash is not attached to that creature."); + return; + } else { + if (obj->cursed) { + pline_The("leash would not come off!"); + obj->bknown = TRUE; + return; + } + mtmp->mleashed = 0; + obj->leashmon = 0; + You("remove the leash from %s%s.", spotmon ? "your " : "", + l_monnam(mtmp)); + } + return; } -struct obj * -get_mleash(mtmp) /* assuming mtmp->mleashed has been checked */ +struct obj *get_mleash(mtmp) /* assuming mtmp->mleashed has been checked */ register struct monst *mtmp; { - register struct obj *otmp; + register struct obj *otmp; - otmp = invent; - while(otmp) { - if(otmp->otyp == LEASH && otmp->leashmon == (int)mtmp->m_id) - return(otmp); - otmp = otmp->nobj; - } - return((struct obj *)0); + otmp = invent; + while (otmp) { + if (otmp->otyp == LEASH && otmp->leashmon == (int) mtmp->m_id) + return (otmp); + otmp = otmp->nobj; + } + return ((struct obj *) 0); } - boolean next_to_u() { - register struct monst *mtmp; - register struct obj *otmp; + register struct monst *mtmp; + register struct obj *otmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if(mtmp->mleashed) { - if (distu(mtmp->mx,mtmp->my) > 2) mnexto(mtmp); - if (distu(mtmp->mx,mtmp->my) > 2) { - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == LEASH && - otmp->leashmon == (int)mtmp->m_id) { - if(otmp->cursed) return(FALSE); - You_feel("%s leash go slack.", - (number_leashed() > 1) ? "a" : "the"); - mtmp->mleashed = 0; - otmp->leashmon = 0; - } - } - } - } - /* no pack mules for the Amulet */ - if (u.usteed && mon_has_amulet(u.usteed)) return FALSE; - return(TRUE); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->mleashed) { + if (distu(mtmp->mx, mtmp->my) > 2) + mnexto(mtmp); + if (distu(mtmp->mx, mtmp->my) > 2) { + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == LEASH + && otmp->leashmon == (int) mtmp->m_id) { + if (otmp->cursed) + return (FALSE); + You_feel("%s leash go slack.", + (number_leashed() > 1) ? "a" : "the"); + mtmp->mleashed = 0; + otmp->leashmon = 0; + } + } + } + } + /* no pack mules for the Amulet */ + if (u.usteed && mon_has_amulet(u.usteed)) + return FALSE; + return (TRUE); } void check_leash(x, y) register xchar x, y; { - register struct obj *otmp; - register struct monst *mtmp; + register struct obj *otmp; + register struct monst *mtmp; - for (otmp = invent; otmp; otmp = otmp->nobj) { - if (otmp->otyp != LEASH || otmp->leashmon == 0) continue; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((int)mtmp->m_id == otmp->leashmon) break; - } - if (!mtmp) { - impossible("leash in use isn't attached to anything?"); - otmp->leashmon = 0; - continue; - } - if (dist2(u.ux,u.uy,mtmp->mx,mtmp->my) > - dist2(x,y,mtmp->mx,mtmp->my)) { - if (!um_dist(mtmp->mx, mtmp->my, 3)) { - ; /* still close enough */ - } else if (otmp->cursed && !breathless(mtmp->data)) { - if (um_dist(mtmp->mx, mtmp->my, 5) || - (mtmp->mhp -= rnd(2)) <= 0) { - long save_pacifism = u.uconduct.killer; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->otyp != LEASH || otmp->leashmon == 0) + continue; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((int) mtmp->m_id == otmp->leashmon) + break; + } + if (!mtmp) { + impossible("leash in use isn't attached to anything?"); + otmp->leashmon = 0; + continue; + } + if (dist2(u.ux, u.uy, mtmp->mx, mtmp->my) + > dist2(x, y, mtmp->mx, mtmp->my)) { + if (!um_dist(mtmp->mx, mtmp->my, 3)) { + ; /* still close enough */ + } else if (otmp->cursed && !breathless(mtmp->data)) { + if (um_dist(mtmp->mx, mtmp->my, 5) + || (mtmp->mhp -= rnd(2)) <= 0) { + long save_pacifism = u.uconduct.killer; - Your("leash chokes %s to death!", mon_nam(mtmp)); - /* hero might not have intended to kill pet, but - that's the result of his actions; gain experience, - lose pacifism, take alignment and luck hit, make - corpse less likely to remain tame after revival */ - xkilled(mtmp, 0); /* no "you kill it" message */ - /* life-saving doesn't ordinarily reset this */ - if (mtmp->mhp > 0) u.uconduct.killer = save_pacifism; - } else { - pline("%s is choked by the leash!", Monnam(mtmp)); - /* tameness eventually drops to 1 here (never 0) */ - if (mtmp->mtame && rn2(mtmp->mtame)) mtmp->mtame--; - } - } else { - if (um_dist(mtmp->mx, mtmp->my, 5)) { - pline("%s leash snaps loose!", s_suffix(Monnam(mtmp))); - m_unleash(mtmp, FALSE); - } else { - You("pull on the leash."); - if (mtmp->data->msound != MS_SILENT) - switch (rn2(3)) { - case 0: growl(mtmp); break; - case 1: yelp(mtmp); break; - default: whimper(mtmp); break; - } - } - } - } - } + Your("leash chokes %s to death!", mon_nam(mtmp)); + /* hero might not have intended to kill pet, but + that's the result of his actions; gain experience, + lose pacifism, take alignment and luck hit, make + corpse less likely to remain tame after revival */ + xkilled(mtmp, 0); /* no "you kill it" message */ + /* life-saving doesn't ordinarily reset this */ + if (mtmp->mhp > 0) + u.uconduct.killer = save_pacifism; + } else { + pline("%s is choked by the leash!", Monnam(mtmp)); + /* tameness eventually drops to 1 here (never 0) */ + if (mtmp->mtame && rn2(mtmp->mtame)) + mtmp->mtame--; + } + } else { + if (um_dist(mtmp->mx, mtmp->my, 5)) { + pline("%s leash snaps loose!", s_suffix(Monnam(mtmp))); + m_unleash(mtmp, FALSE); + } else { + You("pull on the leash."); + if (mtmp->data->msound != MS_SILENT) + switch (rn2(3)) { + case 0: + growl(mtmp); + break; + case 1: + yelp(mtmp); + break; + default: + whimper(mtmp); + break; + } + } + } + } + } } const char * beautiful() { - return (ACURR(A_CHA) > 14) ? - (poly_gender() == 1 ? "beautiful" : "handsome") : "ugly"; + return (ACURR(A_CHA) > 14) + ? (poly_gender() == 1 ? "beautiful" : "handsome") + : "ugly"; } - -#define WEAK 3 /* from eat.c */ +#define WEAK 3 /* from eat.c */ static const char look_str[] = "look %s."; @@ -719,432 +748,437 @@ STATIC_OVL int use_mirror(obj) struct obj *obj; { - const char *mirror, *uvisage; - struct monst *mtmp; - unsigned how_seen; - char mlet; - boolean vis, invis_mirror, useeit, monable; + const char *mirror, *uvisage; + struct monst *mtmp; + unsigned how_seen; + char mlet; + boolean vis, invis_mirror, useeit, monable; - if(!getdir((char *)0)) return 0; - invis_mirror = Invis; - useeit = !Blind && (!invis_mirror || See_invisible); - uvisage = beautiful(); - mirror = simpleonames(obj); /* "mirror" or "looking glass" */ - if(obj->cursed && !rn2(2)) { - if (!Blind) - pline_The("%s fogs up and doesn't reflect!", mirror); - return 1; - } - if(!u.dx && !u.dy && !u.dz) { - if (!useeit) { - You_cant("see your %s %s.", uvisage, body_part(FACE)); - } else { - if (u.umonnum == PM_FLOATING_EYE) { - if (Free_action) { - You("stiffen momentarily under your gaze."); - } else { - if (Hallucination) - pline("Yow! The %s stares back!", mirror); - else - pline("Yikes! You've frozen yourself!"); - if (!Hallucination || !rn2(4)) { - nomul(-rnd(MAXULEV + 6 - u.ulevel)); - multi_reason = "gazing into a mirror"; - } - nomovemsg = 0; /* default, "you can move again" */ - } - } else if (youmonst.data->mlet == S_VAMPIRE) - You("don't have a reflection."); - else if (u.umonnum == PM_UMBER_HULK) { - pline("Huh? That doesn't look like you!"); - make_confused(HConfusion + d(3,4),FALSE); - } else if (Hallucination) - You(look_str, hcolor((char *)0)); - else if (Sick) - You(look_str, "peaked"); - else if (u.uhs >= WEAK) - You(look_str, "undernourished"); - else - You("look as %s as ever.", uvisage); - } - return 1; - } - if(u.uswallow) { - if (useeit) - You("reflect %s %s.", s_suffix(mon_nam(u.ustuck)), - mbodypart(u.ustuck, STOMACH)); - return 1; - } - if(Underwater) { - if (useeit) - You(Hallucination ? - "give the fish a chance to fix their makeup." : - "reflect the murky water."); - return 1; - } - if(u.dz) { - if (useeit) - You("reflect the %s.", - (u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy)); - return 1; - } - mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM, - (int FDECL((*),(MONST_P,OBJ_P)))0, - (int FDECL((*),(OBJ_P,OBJ_P)))0, - &obj); - if (!mtmp || !haseyes(mtmp->data) || notonhead) - return 1; + if (!getdir((char *) 0)) + return 0; + invis_mirror = Invis; + useeit = !Blind && (!invis_mirror || See_invisible); + uvisage = beautiful(); + mirror = simpleonames(obj); /* "mirror" or "looking glass" */ + if (obj->cursed && !rn2(2)) { + if (!Blind) + pline_The("%s fogs up and doesn't reflect!", mirror); + return 1; + } + if (!u.dx && !u.dy && !u.dz) { + if (!useeit) { + You_cant("see your %s %s.", uvisage, body_part(FACE)); + } else { + if (u.umonnum == PM_FLOATING_EYE) { + if (Free_action) { + You("stiffen momentarily under your gaze."); + } else { + if (Hallucination) + pline("Yow! The %s stares back!", mirror); + else + pline("Yikes! You've frozen yourself!"); + if (!Hallucination || !rn2(4)) { + nomul(-rnd(MAXULEV + 6 - u.ulevel)); + multi_reason = "gazing into a mirror"; + } + nomovemsg = 0; /* default, "you can move again" */ + } + } else if (youmonst.data->mlet == S_VAMPIRE) + You("don't have a reflection."); + else if (u.umonnum == PM_UMBER_HULK) { + pline("Huh? That doesn't look like you!"); + make_confused(HConfusion + d(3, 4), FALSE); + } else if (Hallucination) + You(look_str, hcolor((char *) 0)); + else if (Sick) + You(look_str, "peaked"); + else if (u.uhs >= WEAK) + You(look_str, "undernourished"); + else + You("look as %s as ever.", uvisage); + } + return 1; + } + if (u.uswallow) { + if (useeit) + You("reflect %s %s.", s_suffix(mon_nam(u.ustuck)), + mbodypart(u.ustuck, STOMACH)); + return 1; + } + if (Underwater) { + if (useeit) + You(Hallucination ? "give the fish a chance to fix their makeup." + : "reflect the murky water."); + return 1; + } + if (u.dz) { + if (useeit) + You("reflect the %s.", + (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy)); + return 1; + } + mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM, + (int FDECL((*), (MONST_P, OBJ_P))) 0, + (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj); + if (!mtmp || !haseyes(mtmp->data) || notonhead) + return 1; - /* couldsee(mtmp->mx, mtmp->my) is implied by the fact that bhit() - targetted it, so we can ignore possibility of X-ray vision */ - vis = canseemon(mtmp); - /* ways to directly see monster (excludes X-ray vision, telepathy, - extended detection, type-specific warning) */ + /* couldsee(mtmp->mx, mtmp->my) is implied by the fact that bhit() + targetted it, so we can ignore possibility of X-ray vision */ + vis = canseemon(mtmp); +/* ways to directly see monster (excludes X-ray vision, telepathy, + extended detection, type-specific warning) */ #define SEENMON (MONSEEN_NORMAL | MONSEEN_SEEINVIS | MONSEEN_INFRAVIS) - how_seen = vis ? howmonseen(mtmp) : 0; - /* whether monster is able to use its vision-based capabilities */ - monable = !mtmp->mcan && (!mtmp->minvis || perceives(mtmp->data)); - mlet = mtmp->data->mlet; - if (mtmp->msleeping) { - if (vis) - pline("%s is too tired to look at your %s.", - Monnam(mtmp), mirror); - } else if (!mtmp->mcansee) { - if (vis) - pline("%s can't see anything right now.", Monnam(mtmp)); - } else if (invis_mirror && !perceives(mtmp->data)) { - if (vis) - pline("%s fails to notice your %s.", Monnam(mtmp), mirror); - /* infravision doesn't produce an image in the mirror */ - } else if ((how_seen & SEENMON) == MONSEEN_INFRAVIS) { - if (vis) /* (redundant) */ - pline("%s is too far away to see %sself in the dark.", - Monnam(mtmp), mhim(mtmp)); - /* some monsters do special things */ - } else if (mlet == S_VAMPIRE || mlet == S_GHOST || - is_vampshifter(mtmp)) { - if (vis) - pline("%s doesn't have a reflection.", Monnam(mtmp)); - } else if (monable && mtmp->data == &mons[PM_MEDUSA]) { - if (mon_reflects(mtmp, "The gaze is reflected away by %s %s!")) - return 1; - if (vis) - pline("%s is turned to stone!", Monnam(mtmp)); - stoned = TRUE; - killed(mtmp); - } else if (monable && mtmp->data == &mons[PM_FLOATING_EYE]) { - int tmp = d((int)mtmp->m_lev, (int)mtmp->data->mattk[0].damd); - if (!rn2(4)) tmp = 120; - if (vis) - pline("%s is frozen by its reflection.", Monnam(mtmp)); - else - You_hear("%s stop moving.", something); - paralyze_monst(mtmp, (int)mtmp->mfrozen + tmp); - } else if (monable && mtmp->data == &mons[PM_UMBER_HULK]) { - if (vis) - pline("%s confuses itself!", Monnam(mtmp)); - mtmp->mconf = 1; - } else if (monable && - (mlet == S_NYMPH || - mtmp->data == &mons[PM_SUCCUBUS] || - mtmp->data == &mons[PM_INCUBUS])) { - if (vis) { - char buf[BUFSZ]; /* "She" or "He" */ + how_seen = vis ? howmonseen(mtmp) : 0; + /* whether monster is able to use its vision-based capabilities */ + monable = !mtmp->mcan && (!mtmp->minvis || perceives(mtmp->data)); + mlet = mtmp->data->mlet; + if (mtmp->msleeping) { + if (vis) + pline("%s is too tired to look at your %s.", Monnam(mtmp), + mirror); + } else if (!mtmp->mcansee) { + if (vis) + pline("%s can't see anything right now.", Monnam(mtmp)); + } else if (invis_mirror && !perceives(mtmp->data)) { + if (vis) + pline("%s fails to notice your %s.", Monnam(mtmp), mirror); + /* infravision doesn't produce an image in the mirror */ + } else if ((how_seen & SEENMON) == MONSEEN_INFRAVIS) { + if (vis) /* (redundant) */ + pline("%s is too far away to see %sself in the dark.", + Monnam(mtmp), mhim(mtmp)); + /* some monsters do special things */ + } else if (mlet == S_VAMPIRE || mlet == S_GHOST || is_vampshifter(mtmp)) { + if (vis) + pline("%s doesn't have a reflection.", Monnam(mtmp)); + } else if (monable && mtmp->data == &mons[PM_MEDUSA]) { + if (mon_reflects(mtmp, "The gaze is reflected away by %s %s!")) + return 1; + if (vis) + pline("%s is turned to stone!", Monnam(mtmp)); + stoned = TRUE; + killed(mtmp); + } else if (monable && mtmp->data == &mons[PM_FLOATING_EYE]) { + int tmp = d((int) mtmp->m_lev, (int) mtmp->data->mattk[0].damd); + if (!rn2(4)) + tmp = 120; + if (vis) + pline("%s is frozen by its reflection.", Monnam(mtmp)); + else + You_hear("%s stop moving.", something); + paralyze_monst(mtmp, (int) mtmp->mfrozen + tmp); + } else if (monable && mtmp->data == &mons[PM_UMBER_HULK]) { + if (vis) + pline("%s confuses itself!", Monnam(mtmp)); + mtmp->mconf = 1; + } else if (monable && (mlet == S_NYMPH || mtmp->data == &mons[PM_SUCCUBUS] + || mtmp->data == &mons[PM_INCUBUS])) { + if (vis) { + char buf[BUFSZ]; /* "She" or "He" */ - pline("%s admires %sself in your %s.", Monnam(mtmp), - mhim(mtmp), mirror); - pline("%s takes it!", upstart(strcpy(buf, mhe(mtmp)))); - } else - pline("It steals your %s!", mirror); - setnotworn(obj); /* in case mirror was wielded */ - freeinv(obj); - (void) mpickobj(mtmp,obj); - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - } else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data) && - (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) { - if (vis) - pline("%s is frightened by its reflection.", Monnam(mtmp)); - monflee(mtmp, d(2,4), FALSE, FALSE); - } else if (!Blind) { - if (mtmp->minvis && !See_invisible) - ; - else if ((mtmp->minvis && !perceives(mtmp->data)) || - /* redundant: can't get here if these are true */ - !haseyes(mtmp->data) || notonhead || !mtmp->mcansee) - pline("%s doesn't seem to notice %s reflection.", - Monnam(mtmp), mhis(mtmp)); - else - pline("%s ignores %s reflection.", - Monnam(mtmp), mhis(mtmp)); - } - return 1; + pline("%s admires %sself in your %s.", Monnam(mtmp), mhim(mtmp), + mirror); + pline("%s takes it!", upstart(strcpy(buf, mhe(mtmp)))); + } else + pline("It steals your %s!", mirror); + setnotworn(obj); /* in case mirror was wielded */ + freeinv(obj); + (void) mpickobj(mtmp, obj); + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + } else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data) + && (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) { + if (vis) + pline("%s is frightened by its reflection.", Monnam(mtmp)); + monflee(mtmp, d(2, 4), FALSE, FALSE); + } else if (!Blind) { + if (mtmp->minvis && !See_invisible) + ; + else if ((mtmp->minvis && !perceives(mtmp->data)) || + /* redundant: can't get here if these are true */ + !haseyes(mtmp->data) || notonhead || !mtmp->mcansee) + pline("%s doesn't seem to notice %s reflection.", Monnam(mtmp), + mhis(mtmp)); + else + pline("%s ignores %s reflection.", Monnam(mtmp), mhis(mtmp)); + } + return 1; } STATIC_OVL void use_bell(optr) struct obj **optr; { - register struct obj *obj = *optr; - struct monst *mtmp; - boolean wakem = FALSE, learno = FALSE, - ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe), - invoking = (obj->otyp == BELL_OF_OPENING && - invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)); + register struct obj *obj = *optr; + struct monst *mtmp; + boolean wakem = FALSE, learno = FALSE, + ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe), + invoking = + (obj->otyp == BELL_OF_OPENING && invocation_pos(u.ux, u.uy) + && !On_stairs(u.ux, u.uy)); - You("ring %s.", the(xname(obj))); + You("ring %s.", the(xname(obj))); - if (Underwater || (u.uswallow && ordinary)) { -#ifdef AMIGA - amii_speaker( obj, "AhDhGqEqDhEhAqDqFhGw", AMII_MUFFLED_VOLUME ); + if (Underwater || (u.uswallow && ordinary)) { +#ifdef AMIGA + amii_speaker(obj, "AhDhGqEqDhEhAqDqFhGw", AMII_MUFFLED_VOLUME); #endif - pline("But the sound is muffled."); + pline("But the sound is muffled."); - } else if (invoking && ordinary) { - /* needs to be recharged... */ - pline("But it makes no sound."); - learno = TRUE; /* help player figure out why */ + } else if (invoking && ordinary) { + /* needs to be recharged... */ + pline("But it makes no sound."); + learno = TRUE; /* help player figure out why */ - } else if (ordinary) { -#ifdef AMIGA - amii_speaker( obj, "ahdhgqeqdhehaqdqfhgw", AMII_MUFFLED_VOLUME ); + } else if (ordinary) { +#ifdef AMIGA + amii_speaker(obj, "ahdhgqeqdhehaqdqfhgw", AMII_MUFFLED_VOLUME); #endif - if (obj->cursed && !rn2(4) && - /* note: once any of them are gone, we stop all of them */ - !(mvitals[PM_WOOD_NYMPH].mvflags & G_GONE) && - !(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) && - !(mvitals[PM_MOUNTAIN_NYMPH].mvflags & G_GONE) && - (mtmp = makemon(mkclass(S_NYMPH, 0), - u.ux, u.uy, NO_MINVENT)) != 0) { - You("summon %s!", a_monnam(mtmp)); - if (!obj_resists(obj, 93, 100)) { - pline("%s shattered!", Tobjnam(obj, "have")); - useup(obj); - *optr = 0; - } else switch (rn2(3)) { - default: - break; - case 1: - mon_adjust_speed(mtmp, 2, (struct obj *)0); - break; - case 2: /* no explanation; it just happens... */ - nomovemsg = ""; - multi_reason = NULL; - nomul(-rnd(2)); - break; - } - } - wakem = TRUE; + if (obj->cursed && !rn2(4) && + /* note: once any of them are gone, we stop all of them */ + !(mvitals[PM_WOOD_NYMPH].mvflags & G_GONE) + && !(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) + && !(mvitals[PM_MOUNTAIN_NYMPH].mvflags & G_GONE) + && (mtmp = makemon(mkclass(S_NYMPH, 0), u.ux, u.uy, NO_MINVENT)) + != 0) { + You("summon %s!", a_monnam(mtmp)); + if (!obj_resists(obj, 93, 100)) { + pline("%s shattered!", Tobjnam(obj, "have")); + useup(obj); + *optr = 0; + } else + switch (rn2(3)) { + default: + break; + case 1: + mon_adjust_speed(mtmp, 2, (struct obj *) 0); + break; + case 2: /* no explanation; it just happens... */ + nomovemsg = ""; + multi_reason = NULL; + nomul(-rnd(2)); + break; + } + } + wakem = TRUE; - } else { - /* charged Bell of Opening */ - consume_obj_charge(obj, TRUE); + } else { + /* charged Bell of Opening */ + consume_obj_charge(obj, TRUE); - if (u.uswallow) { - if (!obj->cursed) - (void) openit(); - else - pline1(nothing_happens); + if (u.uswallow) { + if (!obj->cursed) + (void) openit(); + else + pline1(nothing_happens); - } else if (obj->cursed) { - coord mm; + } else if (obj->cursed) { + coord mm; - mm.x = u.ux; - mm.y = u.uy; - mkundead(&mm, FALSE, NO_MINVENT); - wakem = TRUE; + mm.x = u.ux; + mm.y = u.uy; + mkundead(&mm, FALSE, NO_MINVENT); + wakem = TRUE; - } else if (invoking) { - pline("%s an unsettling shrill sound...", - Tobjnam(obj, "issue")); -#ifdef AMIGA - amii_speaker( obj, "aefeaefeaefeaefeaefe", AMII_LOUDER_VOLUME ); + } else if (invoking) { + pline("%s an unsettling shrill sound...", Tobjnam(obj, "issue")); +#ifdef AMIGA + amii_speaker(obj, "aefeaefeaefeaefeaefe", AMII_LOUDER_VOLUME); #endif - obj->age = moves; - learno = TRUE; - wakem = TRUE; + obj->age = moves; + learno = TRUE; + wakem = TRUE; - } else if (obj->blessed) { - int res = 0; + } else if (obj->blessed) { + int res = 0; -#ifdef AMIGA - amii_speaker( obj, "ahahahDhEhCw", AMII_SOFT_VOLUME ); +#ifdef AMIGA + amii_speaker(obj, "ahahahDhEhCw", AMII_SOFT_VOLUME); #endif - if (uchain) { - unpunish(); - res = 1; - } - else if (u.utrap && u.utraptype == TT_BURIEDBALL) { - buried_ball_to_freedom(); - res = 1; - } - res += openit(); - switch (res) { - case 0: pline1(nothing_happens); break; - case 1: pline("%s opens...", Something); - learno = TRUE; break; - default: pline("Things open around you..."); - learno = TRUE; break; - } + if (uchain) { + unpunish(); + res = 1; + } else if (u.utrap && u.utraptype == TT_BURIEDBALL) { + buried_ball_to_freedom(); + res = 1; + } + res += openit(); + switch (res) { + case 0: + pline1(nothing_happens); + break; + case 1: + pline("%s opens...", Something); + learno = TRUE; + break; + default: + pline("Things open around you..."); + learno = TRUE; + break; + } - } else { /* uncursed */ -#ifdef AMIGA - amii_speaker( obj, "AeFeaeFeAefegw", AMII_OKAY_VOLUME ); + } else { /* uncursed */ +#ifdef AMIGA + amii_speaker(obj, "AeFeaeFeAefegw", AMII_OKAY_VOLUME); #endif - if (findit() != 0) learno = TRUE; - else pline1(nothing_happens); - } + if (findit() != 0) + learno = TRUE; + else + pline1(nothing_happens); + } - } /* charged BofO */ + } /* charged BofO */ - if (learno) { - makeknown(BELL_OF_OPENING); - obj->known = 1; - } - if (wakem) wake_nearby(); + if (learno) { + makeknown(BELL_OF_OPENING); + obj->known = 1; + } + if (wakem) + wake_nearby(); } STATIC_OVL void use_candelabrum(obj) register struct obj *obj; { - const char *s = (obj->spe != 1) ? "candles" : "candle"; + const char *s = (obj->spe != 1) ? "candles" : "candle"; - if(obj->lamplit) { - You("snuff the %s.", s); - end_burn(obj, TRUE); - return; - } - if(obj->spe <= 0) { - pline("This %s has no %s.", xname(obj), s); - return; - } - if (Underwater) { - You("cannot make fire under water."); - return; - } - if(u.uswallow || obj->cursed) { - if (!Blind) - pline_The("%s %s for a moment, then %s.", - s, vtense(s, "flicker"), vtense(s, "die")); - return; - } - if(obj->spe < 7) { - There("%s only %d %s in %s.", - vtense(s, "are"), obj->spe, s, the(xname(obj))); - if (!Blind) - pline("%s lit. %s dimly.", - obj->spe == 1 ? "It is" : "They are", - Tobjnam(obj, "shine")); - } else { - pline("%s's %s burn%s", The(xname(obj)), s, - (Blind ? "." : " brightly!")); - } - if (!invocation_pos(u.ux, u.uy) || On_stairs(u.ux, u.uy)) { - pline_The("%s %s being rapidly consumed!", s, vtense(s, "are")); - /* this used to be obj->age /= 2, rounding down; an age of - 1 would yield 0, confusing begin_burn() and producing an - unlightable, unrefillable candelabrum; round up instead */ - obj->age = (obj->age + 1L) / 2L; - } else { - if(obj->spe == 7) { - if (Blind) - pline("%s a strange warmth!", Tobjnam(obj, "radiate")); - else - pline("%s with a strange light!", Tobjnam(obj, "glow")); - } - obj->known = 1; - } - begin_burn(obj, FALSE); + if (obj->lamplit) { + You("snuff the %s.", s); + end_burn(obj, TRUE); + return; + } + if (obj->spe <= 0) { + pline("This %s has no %s.", xname(obj), s); + return; + } + if (Underwater) { + You("cannot make fire under water."); + return; + } + if (u.uswallow || obj->cursed) { + if (!Blind) + pline_The("%s %s for a moment, then %s.", s, vtense(s, "flicker"), + vtense(s, "die")); + return; + } + if (obj->spe < 7) { + There("%s only %d %s in %s.", vtense(s, "are"), obj->spe, s, + the(xname(obj))); + if (!Blind) + pline("%s lit. %s dimly.", obj->spe == 1 ? "It is" : "They are", + Tobjnam(obj, "shine")); + } else { + pline("%s's %s burn%s", The(xname(obj)), s, + (Blind ? "." : " brightly!")); + } + if (!invocation_pos(u.ux, u.uy) || On_stairs(u.ux, u.uy)) { + pline_The("%s %s being rapidly consumed!", s, vtense(s, "are")); + /* this used to be obj->age /= 2, rounding down; an age of + 1 would yield 0, confusing begin_burn() and producing an + unlightable, unrefillable candelabrum; round up instead */ + obj->age = (obj->age + 1L) / 2L; + } else { + if (obj->spe == 7) { + if (Blind) + pline("%s a strange warmth!", Tobjnam(obj, "radiate")); + else + pline("%s with a strange light!", Tobjnam(obj, "glow")); + } + obj->known = 1; + } + begin_burn(obj, FALSE); } STATIC_OVL void use_candle(optr) struct obj **optr; { - register struct obj *obj = *optr; - register struct obj *otmp; - const char *s = (obj->quan != 1) ? "candles" : "candle"; - char qbuf[QBUFSZ], qsfx[QBUFSZ], *q; + register struct obj *obj = *optr; + register struct obj *otmp; + const char *s = (obj->quan != 1) ? "candles" : "candle"; + char qbuf[QBUFSZ], qsfx[QBUFSZ], *q; - if(u.uswallow) { - You(no_elbow_room); - return; - } + if (u.uswallow) { + You(no_elbow_room); + return; + } - otmp = carrying(CANDELABRUM_OF_INVOCATION); - if(!otmp || otmp->spe == 7) { - use_lamp(obj); - return; - } + otmp = carrying(CANDELABRUM_OF_INVOCATION); + if (!otmp || otmp->spe == 7) { + use_lamp(obj); + return; + } - /* first, minimal candelabrum suffix for formatting candles */ - Sprintf(qsfx, " to\033%s?", thesimpleoname(otmp)); - /* next, format the candles as a prefix for the candelabrum */ - (void)safe_qbuf(qbuf, "Attach ", qsfx, - obj, yname, thesimpleoname, s); - /* strip temporary candelabrum suffix */ - if ((q = strstri(qbuf, " to\033")) != 0) Strcpy(q, " to "); - /* last, format final "attach candles to candelabrum?" query */ - if (yn(safe_qbuf(qbuf, qbuf, "?", - otmp, yname, thesimpleoname, "it")) == 'n') { - use_lamp(obj); - return; - } else { - if ((long)otmp->spe + obj->quan > 7L) { - obj = splitobj(obj, 7L - (long)otmp->spe); - /* avoid a grammatical error if obj->quan gets - reduced to 1 candle from more than one */ - s = (obj->quan != 1) ? "candles" : "candle"; - } else *optr = 0; - You("attach %ld%s %s to %s.", - obj->quan, !otmp->spe ? "" : " more", - s, the(xname(otmp))); - if (!otmp->spe || otmp->age > obj->age) - otmp->age = obj->age; - otmp->spe += (int)obj->quan; - if (otmp->lamplit && !obj->lamplit) - pline_The("new %s magically %s!", s, vtense(s, "ignite")); - else if (!otmp->lamplit && obj->lamplit) - pline("%s out.", (obj->quan > 1L) ? "They go" : "It goes"); - if (obj->unpaid) - verbalize("You %s %s, you bought %s!", - otmp->lamplit ? "burn" : "use", - (obj->quan > 1L) ? "them" : "it", - (obj->quan > 1L) ? "them" : "it"); - if (obj->quan < 7L && otmp->spe == 7) - pline("%s now has seven%s candles attached.", - The(xname(otmp)), otmp->lamplit ? " lit" : ""); - /* candelabrum's light range might increase */ - if (otmp->lamplit) obj_merge_light_sources(otmp, otmp); - /* candles are no longer a separate light source */ - if (obj->lamplit) end_burn(obj, TRUE); - /* candles are now gone */ - useupall(obj); - } + /* first, minimal candelabrum suffix for formatting candles */ + Sprintf(qsfx, " to\033%s?", thesimpleoname(otmp)); + /* next, format the candles as a prefix for the candelabrum */ + (void) safe_qbuf(qbuf, "Attach ", qsfx, obj, yname, thesimpleoname, s); + /* strip temporary candelabrum suffix */ + if ((q = strstri(qbuf, " to\033")) != 0) + Strcpy(q, " to "); + /* last, format final "attach candles to candelabrum?" query */ + if (yn(safe_qbuf(qbuf, qbuf, "?", otmp, yname, thesimpleoname, "it")) + == 'n') { + use_lamp(obj); + return; + } else { + if ((long) otmp->spe + obj->quan > 7L) { + obj = splitobj(obj, 7L - (long) otmp->spe); + /* avoid a grammatical error if obj->quan gets + reduced to 1 candle from more than one */ + s = (obj->quan != 1) ? "candles" : "candle"; + } else + *optr = 0; + You("attach %ld%s %s to %s.", obj->quan, !otmp->spe ? "" : " more", s, + the(xname(otmp))); + if (!otmp->spe || otmp->age > obj->age) + otmp->age = obj->age; + otmp->spe += (int) obj->quan; + if (otmp->lamplit && !obj->lamplit) + pline_The("new %s magically %s!", s, vtense(s, "ignite")); + else if (!otmp->lamplit && obj->lamplit) + pline("%s out.", (obj->quan > 1L) ? "They go" : "It goes"); + if (obj->unpaid) + verbalize("You %s %s, you bought %s!", + otmp->lamplit ? "burn" : "use", + (obj->quan > 1L) ? "them" : "it", + (obj->quan > 1L) ? "them" : "it"); + if (obj->quan < 7L && otmp->spe == 7) + pline("%s now has seven%s candles attached.", The(xname(otmp)), + otmp->lamplit ? " lit" : ""); + /* candelabrum's light range might increase */ + if (otmp->lamplit) + obj_merge_light_sources(otmp, otmp); + /* candles are no longer a separate light source */ + if (obj->lamplit) + end_burn(obj, TRUE); + /* candles are now gone */ + useupall(obj); + } } -boolean -snuff_candle(otmp) /* call in drop, throw, and put in box, etc. */ +boolean snuff_candle(otmp) /* call in drop, throw, and put in box, etc. */ register struct obj *otmp; { - register boolean candle = Is_candle(otmp); + register boolean candle = Is_candle(otmp); - if ((candle || otmp->otyp == CANDELABRUM_OF_INVOCATION) && - otmp->lamplit) { - char buf[BUFSZ]; - xchar x, y; - register boolean many = candle ? otmp->quan > 1L : otmp->spe > 1; + if ((candle || otmp->otyp == CANDELABRUM_OF_INVOCATION) + && otmp->lamplit) { + char buf[BUFSZ]; + xchar x, y; + register boolean many = candle ? otmp->quan > 1L : otmp->spe > 1; - (void) get_obj_location(otmp, &x, &y, 0); - if (otmp->where == OBJ_MINVENT ? cansee(x,y) : !Blind) - pline("%s%scandle%s flame%s extinguished.", - Shk_Your(buf, otmp), - (candle ? "" : "candelabrum's "), - (many ? "s'" : "'s"), (many ? "s are" : " is")); - end_burn(otmp, TRUE); - return(TRUE); - } - return(FALSE); + (void) get_obj_location(otmp, &x, &y, 0); + if (otmp->where == OBJ_MINVENT ? cansee(x, y) : !Blind) + pline("%s%scandle%s flame%s extinguished.", Shk_Your(buf, otmp), + (candle ? "" : "candelabrum's "), (many ? "s'" : "'s"), + (many ? "s are" : " is")); + end_burn(otmp, TRUE); + return (TRUE); + } + return (FALSE); } /* called when lit lamp is hit by water or put into a container or @@ -1154,20 +1188,21 @@ boolean snuff_lit(obj) struct obj *obj; { - xchar x, y; + xchar x, y; - if (obj->lamplit) { - if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP || - obj->otyp == BRASS_LANTERN || obj->otyp == POT_OIL) { - (void) get_obj_location(obj, &x, &y, 0); - if (obj->where == OBJ_MINVENT ? cansee(x,y) : !Blind) - pline("%s %s out!", Yname2(obj), otense(obj, "go")); - end_burn(obj, TRUE); - return TRUE; - } - if (snuff_candle(obj)) return TRUE; - } - return FALSE; + if (obj->lamplit) { + if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP + || obj->otyp == BRASS_LANTERN || obj->otyp == POT_OIL) { + (void) get_obj_location(obj, &x, &y, 0); + if (obj->where == OBJ_MINVENT ? cansee(x, y) : !Blind) + pline("%s %s out!", Yname2(obj), otense(obj, "go")); + end_burn(obj, TRUE); + return TRUE; + } + if (snuff_candle(obj)) + return TRUE; + } + return FALSE; } /* Called when potentially lightable object is affected by fire_damage(). @@ -1176,144 +1211,145 @@ boolean catch_lit(obj) struct obj *obj; { - xchar x, y; + xchar x, y; - if (!obj->lamplit && (obj->otyp == MAGIC_LAMP || ignitable(obj))) { - if ((obj->otyp == MAGIC_LAMP || - obj->otyp == CANDELABRUM_OF_INVOCATION) && - obj->spe == 0) - return FALSE; - else if (obj->otyp != MAGIC_LAMP && obj->age == 0) - return FALSE; - if (!get_obj_location(obj, &x, &y, 0)) - return FALSE; - if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->cursed) - return FALSE; - if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP || - obj->otyp == BRASS_LANTERN) && obj->cursed && !rn2(2)) - return FALSE; - if (obj->where == OBJ_MINVENT ? cansee(x,y) : !Blind) - pline("%s %s light!", Yname2(obj), otense(obj, "catch")); - if (obj->otyp == POT_OIL) makeknown(obj->otyp); - if (carried(obj) && obj->unpaid && costly_spot(u.ux, u.uy)) { - /* if it catches while you have it, then it's your tough luck */ - check_unpaid(obj); - verbalize("That's in addition to the cost of %s %s, of course.", - yname(obj), obj->quan == 1L ? "itself" : "themselves"); - bill_dummy_object(obj); - } - begin_burn(obj, FALSE); - return TRUE; - } - return FALSE; + if (!obj->lamplit && (obj->otyp == MAGIC_LAMP || ignitable(obj))) { + if ((obj->otyp == MAGIC_LAMP + || obj->otyp == CANDELABRUM_OF_INVOCATION) && obj->spe == 0) + return FALSE; + else if (obj->otyp != MAGIC_LAMP && obj->age == 0) + return FALSE; + if (!get_obj_location(obj, &x, &y, 0)) + return FALSE; + if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->cursed) + return FALSE; + if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP + || obj->otyp == BRASS_LANTERN) && obj->cursed && !rn2(2)) + return FALSE; + if (obj->where == OBJ_MINVENT ? cansee(x, y) : !Blind) + pline("%s %s light!", Yname2(obj), otense(obj, "catch")); + if (obj->otyp == POT_OIL) + makeknown(obj->otyp); + if (carried(obj) && obj->unpaid && costly_spot(u.ux, u.uy)) { + /* if it catches while you have it, then it's your tough luck */ + check_unpaid(obj); + verbalize("That's in addition to the cost of %s %s, of course.", + yname(obj), obj->quan == 1L ? "itself" : "themselves"); + bill_dummy_object(obj); + } + begin_burn(obj, FALSE); + return TRUE; + } + return FALSE; } STATIC_OVL void use_lamp(obj) struct obj *obj; { - char buf[BUFSZ]; + char buf[BUFSZ]; - if(obj->lamplit) { - if(obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP || - obj->otyp == BRASS_LANTERN) - pline("%slamp is now off.", Shk_Your(buf, obj)); - else - You("snuff out %s.", yname(obj)); - end_burn(obj, TRUE); - return; - } - if (Underwater) { - pline(!Is_candle(obj) ? "This is not a diving lamp" : - "Sorry, fire and water don't mix."); - return; - } - /* magic lamps with an spe == 0 (wished for) cannot be lit */ - if ((!Is_candle(obj) && obj->age == 0) - || (obj->otyp == MAGIC_LAMP && obj->spe == 0)) { - if (obj->otyp == BRASS_LANTERN) - Your("lamp has run out of power."); - else pline("This %s has no oil.", xname(obj)); - return; - } - if (obj->cursed && !rn2(2)) { - if (!Blind) - pline("%s for a moment, then %s.", - Tobjnam(obj, "flicker"), otense(obj, "die")); - } else { - if(obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP || - obj->otyp == BRASS_LANTERN) { - check_unpaid(obj); - pline("%slamp is now on.", Shk_Your(buf, obj)); - } else { /* candle(s) */ - pline("%s flame%s %s%s", - s_suffix(Yname2(obj)), - plur(obj->quan), otense(obj, "burn"), - Blind ? "." : " brightly!"); - if (obj->unpaid && costly_spot(u.ux, u.uy) && - obj->age == 20L * (long)objects[obj->otyp].oc_cost) { - const char *ithem = (obj->quan > 1L) ? "them" : "it"; + if (obj->lamplit) { + if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP + || obj->otyp == BRASS_LANTERN) + pline("%slamp is now off.", Shk_Your(buf, obj)); + else + You("snuff out %s.", yname(obj)); + end_burn(obj, TRUE); + return; + } + if (Underwater) { + pline(!Is_candle(obj) ? "This is not a diving lamp" + : "Sorry, fire and water don't mix."); + return; + } + /* magic lamps with an spe == 0 (wished for) cannot be lit */ + if ((!Is_candle(obj) && obj->age == 0) + || (obj->otyp == MAGIC_LAMP && obj->spe == 0)) { + if (obj->otyp == BRASS_LANTERN) + Your("lamp has run out of power."); + else + pline("This %s has no oil.", xname(obj)); + return; + } + if (obj->cursed && !rn2(2)) { + if (!Blind) + pline("%s for a moment, then %s.", Tobjnam(obj, "flicker"), + otense(obj, "die")); + } else { + if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP + || obj->otyp == BRASS_LANTERN) { + check_unpaid(obj); + pline("%slamp is now on.", Shk_Your(buf, obj)); + } else { /* candle(s) */ + pline("%s flame%s %s%s", s_suffix(Yname2(obj)), plur(obj->quan), + otense(obj, "burn"), Blind ? "." : " brightly!"); + if (obj->unpaid && costly_spot(u.ux, u.uy) + && obj->age == 20L * (long) objects[obj->otyp].oc_cost) { + const char *ithem = (obj->quan > 1L) ? "them" : "it"; - verbalize("You burn %s, you bought %s!", ithem, ithem); - bill_dummy_object(obj); - } - } - begin_burn(obj, FALSE); - } + verbalize("You burn %s, you bought %s!", ithem, ithem); + bill_dummy_object(obj); + } + } + begin_burn(obj, FALSE); + } } STATIC_OVL void light_cocktail(obj) - struct obj *obj; /* obj is a potion of oil */ +struct obj *obj; /* obj is a potion of oil */ { - char buf[BUFSZ]; - boolean split1off; + char buf[BUFSZ]; + boolean split1off; - if (u.uswallow) { - You(no_elbow_room); - return; - } + if (u.uswallow) { + You(no_elbow_room); + return; + } - if (obj->lamplit) { - You("snuff the lit potion."); - end_burn(obj, TRUE); - /* - * Free & add to re-merge potion. This will average the - * age of the potions. Not exactly the best solution, - * but its easy. - */ - freeinv(obj); - (void) addinv(obj); - return; - } else if (Underwater) { - There("is not enough oxygen to sustain a fire."); - return; - } + if (obj->lamplit) { + You("snuff the lit potion."); + end_burn(obj, TRUE); + /* + * Free & add to re-merge potion. This will average the + * age of the potions. Not exactly the best solution, + * but its easy. + */ + freeinv(obj); + (void) addinv(obj); + return; + } else if (Underwater) { + There("is not enough oxygen to sustain a fire."); + return; + } - split1off = (obj->quan > 1L); - if (split1off) obj = splitobj(obj, 1L); + split1off = (obj->quan > 1L); + if (split1off) + obj = splitobj(obj, 1L); - You("light %spotion.%s", shk_your(buf, obj), - Blind ? "" : " It gives off a dim light."); + You("light %spotion.%s", shk_your(buf, obj), + Blind ? "" : " It gives off a dim light."); - if (obj->unpaid && costly_spot(u.ux, u.uy)) { - /* Normally, we shouldn't both partially and fully charge - * for an item, but (Yendorian Fuel) Taxes are inevitable... - */ - check_unpaid(obj); - verbalize("That's in addition to the cost of the potion, of course."); - bill_dummy_object(obj); - } - makeknown(obj->otyp); + if (obj->unpaid && costly_spot(u.ux, u.uy)) { + /* Normally, we shouldn't both partially and fully charge + * for an item, but (Yendorian Fuel) Taxes are inevitable... + */ + check_unpaid(obj); + verbalize("That's in addition to the cost of the potion, of course."); + bill_dummy_object(obj); + } + makeknown(obj->otyp); - begin_burn(obj, FALSE); /* after shop billing */ - if (split1off) { - obj_extract_self(obj); /* free from inv */ - obj->nomerge = 1; - obj = hold_another_object(obj, "You drop %s!", - doname(obj), (const char *)0); - if (obj) obj->nomerge = 0; - } + begin_burn(obj, FALSE); /* after shop billing */ + if (split1off) { + obj_extract_self(obj); /* free from inv */ + obj->nomerge = 1; + obj = hold_another_object(obj, "You drop %s!", doname(obj), + (const char *) 0); + if (obj) + obj->nomerge = 0; + } } static NEARDATA const char cuddly[] = { TOOL_CLASS, GEM_CLASS, 0 }; @@ -1321,77 +1357,82 @@ static NEARDATA const char cuddly[] = { TOOL_CLASS, GEM_CLASS, 0 }; int dorub() { - struct obj *obj = getobj(cuddly, "rub"); + struct obj *obj = getobj(cuddly, "rub"); - if (obj && obj->oclass == GEM_CLASS) { - if (is_graystone(obj)) { - use_stone(obj); - return 1; - } else { - pline("Sorry, I don't know how to use that."); - return 0; - } - } + if (obj && obj->oclass == GEM_CLASS) { + if (is_graystone(obj)) { + use_stone(obj); + return 1; + } else { + pline("Sorry, I don't know how to use that."); + return 0; + } + } - if (!obj || !wield_tool(obj, "rub")) return 0; + if (!obj || !wield_tool(obj, "rub")) + return 0; - /* now uwep is obj */ - if (uwep->otyp == MAGIC_LAMP) { - if (uwep->spe > 0 && !rn2(3)) { - check_unpaid_usage(uwep, TRUE); /* unusual item use */ - /* bones preparation: perform the lamp transformation - before releasing the djinni in case the latter turns out - to be fatal (a hostile djinni has no chance to attack yet, - but an indebtted one who grants a wish might bestow an - artifact which blasts the hero with lethal results) */ - uwep->otyp = OIL_LAMP; - uwep->spe = 0; /* for safety */ - uwep->age = rn1(500,1000); - if (uwep->lamplit) begin_burn(uwep, TRUE); - djinni_from_bottle(uwep); - makeknown(MAGIC_LAMP); - update_inventory(); - } else if (rn2(2)) { - You("%s smoke.", !Blind ? "see a puff of" : "smell"); - } else - pline1(nothing_happens); - } else if (obj->otyp == BRASS_LANTERN) { - /* message from Adventure */ - pline("Rubbing the electric lamp is not particularly rewarding."); - pline("Anyway, nothing exciting happens."); - } else - pline1(nothing_happens); - return 1; + /* now uwep is obj */ + if (uwep->otyp == MAGIC_LAMP) { + if (uwep->spe > 0 && !rn2(3)) { + check_unpaid_usage(uwep, TRUE); /* unusual item use */ + /* bones preparation: perform the lamp transformation + before releasing the djinni in case the latter turns out + to be fatal (a hostile djinni has no chance to attack yet, + but an indebtted one who grants a wish might bestow an + artifact which blasts the hero with lethal results) */ + uwep->otyp = OIL_LAMP; + uwep->spe = 0; /* for safety */ + uwep->age = rn1(500, 1000); + if (uwep->lamplit) + begin_burn(uwep, TRUE); + djinni_from_bottle(uwep); + makeknown(MAGIC_LAMP); + update_inventory(); + } else if (rn2(2)) { + You("%s smoke.", !Blind ? "see a puff of" : "smell"); + } else + pline1(nothing_happens); + } else if (obj->otyp == BRASS_LANTERN) { + /* message from Adventure */ + pline("Rubbing the electric lamp is not particularly rewarding."); + pline("Anyway, nothing exciting happens."); + } else + pline1(nothing_happens); + return 1; } int dojump() { - /* Physical jump */ - return jump(0); + /* Physical jump */ + return jump(0); } boolean -is_valid_jump_pos(x,y, magic, showmsg) -int x,y, magic; +is_valid_jump_pos(x, y, magic, showmsg) +int x, y, magic; boolean showmsg; { - if (!magic && !(HJumping & ~INTRINSIC) && !EJumping && - distu(x, y) != 5) { - /* The Knight jumping restriction still applies when riding a - * horse. After all, what shape is the knight piece in chess? - */ - if (showmsg) pline("Illegal move!"); - return FALSE; - } else if (distu(x, y) > (magic ? 6+magic*3 : 9)) { - if (showmsg) pline("Too far!"); - return FALSE; + if (!magic && !(HJumping & ~INTRINSIC) && !EJumping && distu(x, y) != 5) { + /* The Knight jumping restriction still applies when riding a + * horse. After all, what shape is the knight piece in chess? + */ + if (showmsg) + pline("Illegal move!"); + return FALSE; + } else if (distu(x, y) > (magic ? 6 + magic * 3 : 9)) { + if (showmsg) + pline("Too far!"); + return FALSE; } else if (!cansee(x, y)) { - if (showmsg) You("cannot see where to land!"); - return FALSE; + if (showmsg) + You("cannot see where to land!"); + return FALSE; } else if (!isok(x, y)) { - if (showmsg) You("cannot jump there!"); - return FALSE; + if (showmsg) + You("cannot jump there!"); + return FALSE; } return TRUE; } @@ -1403,19 +1444,19 @@ display_jump_positions(state) int state; { if (state == 0) { - tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); + tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); } else if (state == 1) { - int x,y, dx, dy; - for (dx = -4; dx <= 4; dx++) - for (dy = -4; dy <= 4; dy++) { - x = dx + (int)u.ux; - y = dy + (int)u.uy; - if (isok(x,y) && ACCESSIBLE(levl[x][y].typ) && - is_valid_jump_pos(x,y, jumping_is_magic, FALSE)) - tmp_at(x,y); - } + int x, y, dx, dy; + for (dx = -4; dx <= 4; dx++) + for (dy = -4; dy <= 4; dy++) { + x = dx + (int) u.ux; + y = dy + (int) u.uy; + if (isok(x, y) && ACCESSIBLE(levl[x][y].typ) + && is_valid_jump_pos(x, y, jumping_is_magic, FALSE)) + tmp_at(x, y); + } } else { - tmp_at(DISP_END, 0); + tmp_at(DISP_END, 0); } } @@ -1423,378 +1464,402 @@ int jump(magic) int magic; /* 0=Physical, otherwise skill level */ { - coord cc; + coord cc; - if (!magic && (nolimbs(youmonst.data) || slithy(youmonst.data))) { - /* normally (nolimbs || slithy) implies !Jumping, - but that isn't necessarily the case for knights */ - You_cant("jump; you have no legs!"); - return 0; - } else if (!magic && !Jumping) { - You_cant("jump very far."); - return 0; - /* if steed is immobile, can't do physical jump but can do spell one */ - } else if (!magic && u.usteed && stucksteed(FALSE)) { - /* stucksteed gave " won't move" message */ - return 0; - } else if (u.uswallow) { - if (magic) { - You("bounce around a little."); - return 1; - } - pline("You've got to be kidding!"); - return 0; - } else if (u.uinwater) { - if (magic) { - You("swish around a little."); - return 1; - } - pline("This calls for swimming, not jumping!"); - return 0; - } else if (u.ustuck) { - if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) { - You("pull free from %s.", mon_nam(u.ustuck)); - u.ustuck = 0; - return 1; - } - if (magic) { - You("writhe a little in the grasp of %s!", mon_nam(u.ustuck)); - return 1; - } - You("cannot escape from %s!", mon_nam(u.ustuck)); - return 0; - } else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { - if (magic) { - You("flail around a little."); - return 1; - } - You("don't have enough traction to jump."); - return 0; - } else if (!magic && near_capacity() > UNENCUMBERED) { - You("are carrying too much to jump!"); - return 0; - } else if (!magic && (u.uhunger <= 100 || ACURR(A_STR) < 6)) { - You("lack the strength to jump!"); - return 0; - } else if (!magic && Wounded_legs) { - long wl = (Wounded_legs & BOTH_SIDES); - const char *bp = body_part(LEG); + if (!magic && (nolimbs(youmonst.data) || slithy(youmonst.data))) { + /* normally (nolimbs || slithy) implies !Jumping, + but that isn't necessarily the case for knights */ + You_cant("jump; you have no legs!"); + return 0; + } else if (!magic && !Jumping) { + You_cant("jump very far."); + return 0; + /* if steed is immobile, can't do physical jump but can do spell one + */ + } else if (!magic && u.usteed && stucksteed(FALSE)) { + /* stucksteed gave " won't move" message */ + return 0; + } else if (u.uswallow) { + if (magic) { + You("bounce around a little."); + return 1; + } + pline("You've got to be kidding!"); + return 0; + } else if (u.uinwater) { + if (magic) { + You("swish around a little."); + return 1; + } + pline("This calls for swimming, not jumping!"); + return 0; + } else if (u.ustuck) { + if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) { + You("pull free from %s.", mon_nam(u.ustuck)); + u.ustuck = 0; + return 1; + } + if (magic) { + You("writhe a little in the grasp of %s!", mon_nam(u.ustuck)); + return 1; + } + You("cannot escape from %s!", mon_nam(u.ustuck)); + return 0; + } else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { + if (magic) { + You("flail around a little."); + return 1; + } + You("don't have enough traction to jump."); + return 0; + } else if (!magic && near_capacity() > UNENCUMBERED) { + You("are carrying too much to jump!"); + return 0; + } else if (!magic && (u.uhunger <= 100 || ACURR(A_STR) < 6)) { + You("lack the strength to jump!"); + return 0; + } else if (!magic && Wounded_legs) { + long wl = (Wounded_legs & BOTH_SIDES); + const char *bp = body_part(LEG); - if (wl == BOTH_SIDES) bp = makeplural(bp); - if (u.usteed) - pline("%s is in no shape for jumping.", Monnam(u.usteed)); - else - Your("%s%s %s in no shape for jumping.", - (wl == LEFT_SIDE) ? "left " : - (wl == RIGHT_SIDE) ? "right " : "", - bp, (wl == BOTH_SIDES) ? "are" : "is"); - return 0; - } - else if (u.usteed && u.utrap) { - pline("%s is stuck in a trap.", Monnam(u.usteed)); - return (0); - } + if (wl == BOTH_SIDES) + bp = makeplural(bp); + if (u.usteed) + pline("%s is in no shape for jumping.", Monnam(u.usteed)); + else + Your("%s%s %s in no shape for jumping.", + (wl == LEFT_SIDE) ? "left " : (wl == RIGHT_SIDE) ? "right " + : "", + bp, (wl == BOTH_SIDES) ? "are" : "is"); + return 0; + } else if (u.usteed && u.utrap) { + pline("%s is stuck in a trap.", Monnam(u.usteed)); + return (0); + } - pline("Where do you want to jump?"); - cc.x = u.ux; - cc.y = u.uy; - jumping_is_magic = magic; - getpos_sethilite(display_jump_positions); - if (getpos(&cc, TRUE, "the desired position") < 0) - return 0; /* user pressed ESC */ - if (!is_valid_jump_pos(cc.x, cc.y, magic, TRUE)) { - return 0; - } else { - coord uc; - int range, temp; + pline("Where do you want to jump?"); + cc.x = u.ux; + cc.y = u.uy; + jumping_is_magic = magic; + getpos_sethilite(display_jump_positions); + if (getpos(&cc, TRUE, "the desired position") < 0) + return 0; /* user pressed ESC */ + if (!is_valid_jump_pos(cc.x, cc.y, magic, TRUE)) { + return 0; + } else { + coord uc; + int range, temp; - if(u.utrap) - switch(u.utraptype) { - case TT_BEARTRAP: { - register long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; - You("rip yourself free of the bear trap! Ouch!"); - losehp(Maybe_Half_Phys(rnd(10)), - "jumping out of a bear trap", KILLED_BY); - set_wounded_legs(side, rn1(1000,500)); - break; - } - case TT_PIT: - You("leap from the pit!"); - break; - case TT_WEB: - You("tear the web apart as you pull yourself free!"); - deltrap(t_at(u.ux,u.uy)); - break; - case TT_LAVA: - You("pull yourself above the lava!"); - u.utrap = 0; - return 1; - case TT_BURIEDBALL: - case TT_INFLOOR: - You("strain your %s, but you're still %s.", - makeplural(body_part(LEG)), - (u.utraptype == TT_INFLOOR) ? "stuck in the floor" : - "attached to the buried ball"); - set_wounded_legs(LEFT_SIDE, rn1(10, 11)); - set_wounded_legs(RIGHT_SIDE, rn1(10, 11)); - return 1; - } + if (u.utrap) + switch (u.utraptype) { + case TT_BEARTRAP: { + register long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; + You("rip yourself free of the bear trap! Ouch!"); + losehp(Maybe_Half_Phys(rnd(10)), "jumping out of a bear trap", + KILLED_BY); + set_wounded_legs(side, rn1(1000, 500)); + break; + } + case TT_PIT: + You("leap from the pit!"); + break; + case TT_WEB: + You("tear the web apart as you pull yourself free!"); + deltrap(t_at(u.ux, u.uy)); + break; + case TT_LAVA: + You("pull yourself above the lava!"); + u.utrap = 0; + return 1; + case TT_BURIEDBALL: + case TT_INFLOOR: + You("strain your %s, but you're still %s.", + makeplural(body_part(LEG)), + (u.utraptype == TT_INFLOOR) + ? "stuck in the floor" + : "attached to the buried ball"); + set_wounded_legs(LEFT_SIDE, rn1(10, 11)); + set_wounded_legs(RIGHT_SIDE, rn1(10, 11)); + return 1; + } - /* - * Check the path from uc to cc, calling hurtle_step at each - * location. The final position actually reached will be - * in cc. - */ - uc.x = u.ux; - uc.y = u.uy; - /* calculate max(abs(dx), abs(dy)) as the range */ - range = cc.x - uc.x; - if (range < 0) range = -range; - temp = cc.y - uc.y; - if (temp < 0) temp = -temp; - if (range < temp) - range = temp; - (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t)&range); - teleds(cc.x, cc.y, TRUE); - sokoban_guilt(); - nomul(-1); - multi_reason = "jumping around"; - nomovemsg = ""; - morehungry(rnd(25)); - return 1; - } + /* + * Check the path from uc to cc, calling hurtle_step at each + * location. The final position actually reached will be + * in cc. + */ + uc.x = u.ux; + uc.y = u.uy; + /* calculate max(abs(dx), abs(dy)) as the range */ + range = cc.x - uc.x; + if (range < 0) + range = -range; + temp = cc.y - uc.y; + if (temp < 0) + temp = -temp; + if (range < temp) + range = temp; + (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t) &range); + teleds(cc.x, cc.y, TRUE); + sokoban_guilt(); + nomul(-1); + multi_reason = "jumping around"; + nomovemsg = ""; + morehungry(rnd(25)); + return 1; + } } boolean tinnable(corpse) struct obj *corpse; { - if (corpse->oeaten) return 0; - if (!mons[corpse->corpsenm].cnutrit) return 0; - return 1; + if (corpse->oeaten) + return 0; + if (!mons[corpse->corpsenm].cnutrit) + return 0; + return 1; } STATIC_OVL void use_tinning_kit(obj) register struct obj *obj; { - register struct obj *corpse, *can; + register struct obj *corpse, *can; - /* This takes only 1 move. If this is to be changed to take many - * moves, we've got to deal with decaying corpses... - */ - if (obj->spe <= 0) { - You("seem to be out of tins."); - return; - } - if (!(corpse = floorfood("tin", 2))) return; - if (corpse->oeaten) { - You("cannot tin %s which is partly eaten.",something); - return; - } - if (touch_petrifies(&mons[corpse->corpsenm]) - && !Stone_resistance && !uarmg) { - char kbuf[BUFSZ]; + /* This takes only 1 move. If this is to be changed to take many + * moves, we've got to deal with decaying corpses... + */ + if (obj->spe <= 0) { + You("seem to be out of tins."); + return; + } + if (!(corpse = floorfood("tin", 2))) + return; + if (corpse->oeaten) { + You("cannot tin %s which is partly eaten.", something); + return; + } + if (touch_petrifies(&mons[corpse->corpsenm]) && !Stone_resistance + && !uarmg) { + char kbuf[BUFSZ]; - if (poly_when_stoned(youmonst.data)) - You("tin %s without wearing gloves.", - an(mons[corpse->corpsenm].mname)); - else { - pline("Tinning %s without wearing gloves is a fatal mistake...", - an(mons[corpse->corpsenm].mname)); - Sprintf(kbuf, "trying to tin %s without gloves", - an(mons[corpse->corpsenm].mname)); - } - instapetrify(kbuf); - } - if (is_rider(&mons[corpse->corpsenm])) { - if (revive_corpse(corpse)) - verbalize("Yes... But War does not preserve its enemies..."); - else - pline_The("corpse evades your grasp."); - return; - } - if (mons[corpse->corpsenm].cnutrit == 0) { - pline("That's too insubstantial to tin."); - return; - } - consume_obj_charge(obj, TRUE); + if (poly_when_stoned(youmonst.data)) + You("tin %s without wearing gloves.", + an(mons[corpse->corpsenm].mname)); + else { + pline("Tinning %s without wearing gloves is a fatal mistake...", + an(mons[corpse->corpsenm].mname)); + Sprintf(kbuf, "trying to tin %s without gloves", + an(mons[corpse->corpsenm].mname)); + } + instapetrify(kbuf); + } + if (is_rider(&mons[corpse->corpsenm])) { + if (revive_corpse(corpse)) + verbalize("Yes... But War does not preserve its enemies..."); + else + pline_The("corpse evades your grasp."); + return; + } + if (mons[corpse->corpsenm].cnutrit == 0) { + pline("That's too insubstantial to tin."); + return; + } + consume_obj_charge(obj, TRUE); - if ((can = mksobj(TIN, FALSE, FALSE)) != 0) { - static const char you_buy_it[] = "You tin it, you bought it!"; + if ((can = mksobj(TIN, FALSE, FALSE)) != 0) { + static const char you_buy_it[] = "You tin it, you bought it!"; - can->corpsenm = corpse->corpsenm; - can->cursed = obj->cursed; - can->blessed = obj->blessed; - can->owt = weight(can); - can->known = 1; - /* Mark tinned tins. No spinach allowed... */ - set_tin_variety(can, HOMEMADE_TIN); - if (carried(corpse)) { - if (corpse->unpaid) - verbalize(you_buy_it); - useup(corpse); - } else { - if (costly_spot(corpse->ox, corpse->oy) && !corpse->no_charge) - verbalize(you_buy_it); - useupf(corpse, 1L); - } - can = hold_another_object(can, "You make, but cannot pick up, %s.", - doname(can), (const char *)0); - } else impossible("Tinning failed."); + can->corpsenm = corpse->corpsenm; + can->cursed = obj->cursed; + can->blessed = obj->blessed; + can->owt = weight(can); + can->known = 1; + /* Mark tinned tins. No spinach allowed... */ + set_tin_variety(can, HOMEMADE_TIN); + if (carried(corpse)) { + if (corpse->unpaid) + verbalize(you_buy_it); + useup(corpse); + } else { + if (costly_spot(corpse->ox, corpse->oy) && !corpse->no_charge) + verbalize(you_buy_it); + useupf(corpse, 1L); + } + can = hold_another_object(can, "You make, but cannot pick up, %s.", + doname(can), (const char *) 0); + } else + impossible("Tinning failed."); } void use_unicorn_horn(obj) struct obj *obj; { -#define PROP_COUNT 6 /* number of properties we're dealing with */ -#define ATTR_COUNT (A_MAX*3) /* number of attribute points we might fix */ - int idx, val, val_limit, - trouble_count, unfixable_trbl, did_prop, did_attr; - int trouble_list[PROP_COUNT + ATTR_COUNT]; +#define PROP_COUNT 6 /* number of properties we're dealing with */ +#define ATTR_COUNT (A_MAX * 3) /* number of attribute points we might fix */ + int idx, val, val_limit, trouble_count, unfixable_trbl, did_prop, + did_attr; + int trouble_list[PROP_COUNT + ATTR_COUNT]; - if (obj && obj->cursed) { - long lcount = (long) rnd(100); + if (obj && obj->cursed) { + long lcount = (long) rnd(100); - switch (rn2(6)) { - case 0: make_sick((Sick & TIMEOUT) ? (Sick & TIMEOUT) / 3L + 1L : - (long)rn1(ACURR(A_CON),20), - xname(obj), TRUE, SICK_NONVOMITABLE); - break; - case 1: make_blinded((Blinded & TIMEOUT) + lcount, TRUE); - break; - case 2: if (!Confusion) - You("suddenly feel %s.", - Hallucination ? "trippy" : "confused"); - make_confused((HConfusion & TIMEOUT) + lcount, TRUE); - break; - case 3: make_stunned((HStun & TIMEOUT) + lcount, TRUE); - break; - case 4: (void) adjattrib(rn2(A_MAX), -1, FALSE); - break; - case 5: (void) make_hallucinated((HHallucination & TIMEOUT) - + lcount, TRUE, 0L); - break; - } - return; - } + switch (rn2(6)) { + case 0: + make_sick((Sick & TIMEOUT) ? (Sick & TIMEOUT) / 3L + 1L + : (long) rn1(ACURR(A_CON), 20), + xname(obj), TRUE, SICK_NONVOMITABLE); + break; + case 1: + make_blinded((Blinded & TIMEOUT) + lcount, TRUE); + break; + case 2: + if (!Confusion) + You("suddenly feel %s.", + Hallucination ? "trippy" : "confused"); + make_confused((HConfusion & TIMEOUT) + lcount, TRUE); + break; + case 3: + make_stunned((HStun & TIMEOUT) + lcount, TRUE); + break; + case 4: + (void) adjattrib(rn2(A_MAX), -1, FALSE); + break; + case 5: + (void) make_hallucinated((HHallucination & TIMEOUT) + lcount, + TRUE, 0L); + break; + } + return; + } /* * Entries in the trouble list use a very simple encoding scheme. */ -#define prop2trbl(X) ((X) + A_MAX) -#define attr2trbl(Y) (Y) +#define prop2trbl(X) ((X) + A_MAX) +#define attr2trbl(Y) (Y) #define prop_trouble(X) trouble_list[trouble_count++] = prop2trbl(X) #define attr_trouble(Y) trouble_list[trouble_count++] = attr2trbl(Y) -#define TimedTrouble(P) (((P) && !((P) & ~TIMEOUT)) ? ((P) & TIMEOUT) : 0L) +#define TimedTrouble(P) (((P) && !((P) & ~TIMEOUT)) ? ((P) &TIMEOUT) : 0L) - trouble_count = unfixable_trbl = did_prop = did_attr = 0; + trouble_count = unfixable_trbl = did_prop = did_attr = 0; - /* collect property troubles */ - if (TimedTrouble(Sick)) prop_trouble(SICK); - if (TimedTrouble(Blinded) > (long)u.ucreamed && - !(u.uswallow && - attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))) - prop_trouble(BLINDED); - if (TimedTrouble(HHallucination)) prop_trouble(HALLUC); - if (TimedTrouble(Vomiting)) prop_trouble(VOMITING); - if (TimedTrouble(HConfusion)) prop_trouble(CONFUSION); - if (TimedTrouble(HStun)) prop_trouble(STUNNED); + /* collect property troubles */ + if (TimedTrouble(Sick)) + prop_trouble(SICK); + if (TimedTrouble(Blinded) > (long) u.ucreamed + && !(u.uswallow + && attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))) + prop_trouble(BLINDED); + if (TimedTrouble(HHallucination)) + prop_trouble(HALLUC); + if (TimedTrouble(Vomiting)) + prop_trouble(VOMITING); + if (TimedTrouble(HConfusion)) + prop_trouble(CONFUSION); + if (TimedTrouble(HStun)) + prop_trouble(STUNNED); - unfixable_trbl = unfixable_trouble_count(TRUE); + unfixable_trbl = unfixable_trouble_count(TRUE); - /* collect attribute troubles */ - for (idx = 0; idx < A_MAX; idx++) { - if (ABASE(idx) >= AMAX(idx)) continue; - val_limit = AMAX(idx); - /* don't recover strength lost from hunger */ - if (idx == A_STR && u.uhs >= WEAK) val_limit--; - if (Fixed_abil) { - /* potion/spell of restore ability override sustain ability - intrinsic but unicorn horn usage doesn't */ - unfixable_trbl += val_limit - ABASE(idx); - continue; - } - /* don't recover more than 3 points worth of any attribute */ - if (val_limit > ABASE(idx) + 3) val_limit = ABASE(idx) + 3; + /* collect attribute troubles */ + for (idx = 0; idx < A_MAX; idx++) { + if (ABASE(idx) >= AMAX(idx)) + continue; + val_limit = AMAX(idx); + /* don't recover strength lost from hunger */ + if (idx == A_STR && u.uhs >= WEAK) + val_limit--; + if (Fixed_abil) { + /* potion/spell of restore ability override sustain ability + intrinsic but unicorn horn usage doesn't */ + unfixable_trbl += val_limit - ABASE(idx); + continue; + } + /* don't recover more than 3 points worth of any attribute */ + if (val_limit > ABASE(idx) + 3) + val_limit = ABASE(idx) + 3; - for (val = ABASE(idx); val < val_limit; val++) - attr_trouble(idx); - /* keep track of unfixed trouble, for message adjustment below */ - unfixable_trbl += (AMAX(idx) - val_limit); - } + for (val = ABASE(idx); val < val_limit; val++) + attr_trouble(idx); + /* keep track of unfixed trouble, for message adjustment below */ + unfixable_trbl += (AMAX(idx) - val_limit); + } - if (trouble_count == 0) { - pline1(nothing_happens); - return; - } else if (trouble_count > 1) { /* shuffle */ - int i, j, k; + if (trouble_count == 0) { + pline1(nothing_happens); + return; + } else if (trouble_count > 1) { /* shuffle */ + int i, j, k; - for (i = trouble_count - 1; i > 0; i--) - if ((j = rn2(i + 1)) != i) { - k = trouble_list[j]; - trouble_list[j] = trouble_list[i]; - trouble_list[i] = k; - } - } + for (i = trouble_count - 1; i > 0; i--) + if ((j = rn2(i + 1)) != i) { + k = trouble_list[j]; + trouble_list[j] = trouble_list[i]; + trouble_list[i] = k; + } + } - /* - * Chances for number of troubles to be fixed - * 0 1 2 3 4 5 6 7 - * blessed: 22.7% 22.7% 19.5% 15.4% 10.7% 5.7% 2.6% 0.8% - * uncursed: 35.4% 35.4% 22.9% 6.3% 0 0 0 0 - */ - val_limit = rn2( d(2, (obj && obj->blessed) ? 4 : 2) ); - if (val_limit > trouble_count) val_limit = trouble_count; + /* + * Chances for number of troubles to be fixed + * 0 1 2 3 4 5 6 7 + * blessed: 22.7% 22.7% 19.5% 15.4% 10.7% 5.7% 2.6% 0.8% + * uncursed: 35.4% 35.4% 22.9% 6.3% 0 0 0 0 + */ + val_limit = rn2(d(2, (obj && obj->blessed) ? 4 : 2)); + if (val_limit > trouble_count) + val_limit = trouble_count; - /* fix [some of] the troubles */ - for (val = 0; val < val_limit; val++) { - idx = trouble_list[val]; + /* fix [some of] the troubles */ + for (val = 0; val < val_limit; val++) { + idx = trouble_list[val]; - switch (idx) { - case prop2trbl(SICK): - make_sick(0L, (char *) 0, TRUE, SICK_ALL); - did_prop++; - break; - case prop2trbl(BLINDED): - make_blinded((long)u.ucreamed, TRUE); - did_prop++; - break; - case prop2trbl(HALLUC): - (void) make_hallucinated(0L, TRUE, 0L); - did_prop++; - break; - case prop2trbl(VOMITING): - make_vomiting(0L, TRUE); - did_prop++; - break; - case prop2trbl(CONFUSION): - make_confused(0L, TRUE); - did_prop++; - break; - case prop2trbl(STUNNED): - make_stunned(0L, TRUE); - did_prop++; - break; - default: - if (idx >= 0 && idx < A_MAX) { - ABASE(idx) += 1; - did_attr++; - } else - panic("use_unicorn_horn: bad trouble? (%d)", idx); - break; - } - } + switch (idx) { + case prop2trbl(SICK): + make_sick(0L, (char *) 0, TRUE, SICK_ALL); + did_prop++; + break; + case prop2trbl(BLINDED): + make_blinded((long) u.ucreamed, TRUE); + did_prop++; + break; + case prop2trbl(HALLUC): + (void) make_hallucinated(0L, TRUE, 0L); + did_prop++; + break; + case prop2trbl(VOMITING): + make_vomiting(0L, TRUE); + did_prop++; + break; + case prop2trbl(CONFUSION): + make_confused(0L, TRUE); + did_prop++; + break; + case prop2trbl(STUNNED): + make_stunned(0L, TRUE); + did_prop++; + break; + default: + if (idx >= 0 && idx < A_MAX) { + ABASE(idx) += 1; + did_attr++; + } else + panic("use_unicorn_horn: bad trouble? (%d)", idx); + break; + } + } - if (did_attr) - pline("This makes you feel %s!", - (did_prop + did_attr) == (trouble_count + unfixable_trbl) ? - "great" : "better"); - else if (!did_prop) - pline("Nothing seems to happen."); + if (did_attr) + pline("This makes you feel %s!", + (did_prop + did_attr) == (trouble_count + unfixable_trbl) + ? "great" + : "better"); + else if (!did_prop) + pline("Nothing seems to happen."); - context.botl = (did_attr || did_prop); + context.botl = (did_attr || did_prop); #undef PROP_COUNT #undef ATTR_COUNT #undef prop2trbl @@ -1812,116 +1877,110 @@ fig_transform(arg, timeout) anything *arg; long timeout; { - struct obj *figurine = arg->a_obj; - struct monst *mtmp; - coord cc; - boolean cansee_spot, silent, okay_spot; - boolean redraw = FALSE; - boolean suppress_see = FALSE; - char monnambuf[BUFSZ], carriedby[BUFSZ]; + struct obj *figurine = arg->a_obj; + struct monst *mtmp; + coord cc; + boolean cansee_spot, silent, okay_spot; + boolean redraw = FALSE; + boolean suppress_see = FALSE; + char monnambuf[BUFSZ], carriedby[BUFSZ]; - if (!figurine) { - debugpline0("null figurine in fig_transform()"); - return; - } - silent = (timeout != monstermoves); /* happened while away */ - okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0); - if (figurine->where == OBJ_INVENT || - figurine->where == OBJ_MINVENT) - okay_spot = enexto(&cc, cc.x, cc.y, - &mons[figurine->corpsenm]); - if (!okay_spot || - !figurine_location_checks(figurine,&cc, TRUE)) { - /* reset the timer to try again later */ - (void) start_timer((long)rnd(5000), TIMER_OBJECT, - FIG_TRANSFORM, obj_to_any(figurine)); - return; - } + if (!figurine) { + debugpline0("null figurine in fig_transform()"); + return; + } + silent = (timeout != monstermoves); /* happened while away */ + okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0); + if (figurine->where == OBJ_INVENT || figurine->where == OBJ_MINVENT) + okay_spot = enexto(&cc, cc.x, cc.y, &mons[figurine->corpsenm]); + if (!okay_spot || !figurine_location_checks(figurine, &cc, TRUE)) { + /* reset the timer to try again later */ + (void) start_timer((long) rnd(5000), TIMER_OBJECT, FIG_TRANSFORM, + obj_to_any(figurine)); + return; + } - cansee_spot = cansee(cc.x, cc.y); - mtmp = make_familiar(figurine, cc.x, cc.y, TRUE); - if (mtmp) { - char and_vanish[BUFSZ]; - struct obj *mshelter = level.objects[mtmp->mx][mtmp->my]; - Sprintf(monnambuf, "%s",an(m_monnam(mtmp))); + cansee_spot = cansee(cc.x, cc.y); + mtmp = make_familiar(figurine, cc.x, cc.y, TRUE); + if (mtmp) { + char and_vanish[BUFSZ]; + struct obj *mshelter = level.objects[mtmp->mx][mtmp->my]; + Sprintf(monnambuf, "%s", an(m_monnam(mtmp))); - and_vanish[0] = '\0'; - if ((mtmp->minvis && !See_invisible) || - (mtmp->data->mlet == S_MIMIC && - mtmp->m_ap_type != M_AP_NOTHING)) - suppress_see = TRUE; + and_vanish[0] = '\0'; + if ((mtmp->minvis && !See_invisible) + || (mtmp->data->mlet == S_MIMIC + && mtmp->m_ap_type != M_AP_NOTHING)) + suppress_see = TRUE; - if (mtmp->mundetected) { - if (hides_under(mtmp->data) && mshelter) { - Sprintf(and_vanish, " and %s under %s", - locomotion(mtmp->data, "crawl"), - doname(mshelter)); - } else if (mtmp->data->mlet == S_MIMIC || - mtmp->data->mlet == S_EEL) { - suppress_see = TRUE; - } else - Strcpy(and_vanish, " and vanish"); - } + if (mtmp->mundetected) { + if (hides_under(mtmp->data) && mshelter) { + Sprintf(and_vanish, " and %s under %s", + locomotion(mtmp->data, "crawl"), doname(mshelter)); + } else if (mtmp->data->mlet == S_MIMIC + || mtmp->data->mlet == S_EEL) { + suppress_see = TRUE; + } else + Strcpy(and_vanish, " and vanish"); + } - switch (figurine->where) { - case OBJ_INVENT: - if (Blind || suppress_see) - You_feel("%s %s from your pack!", something, - locomotion(mtmp->data,"drop")); - else - You_see("%s %s out of your pack%s!", - monnambuf, - locomotion(mtmp->data,"drop"), - and_vanish); - break; + switch (figurine->where) { + case OBJ_INVENT: + if (Blind || suppress_see) + You_feel("%s %s from your pack!", something, + locomotion(mtmp->data, "drop")); + else + You_see("%s %s out of your pack%s!", monnambuf, + locomotion(mtmp->data, "drop"), and_vanish); + break; - case OBJ_FLOOR: - if (cansee_spot && !silent) { - if (suppress_see) - pline("%s suddenly vanishes!", an(xname(figurine))); - else - You_see("a figurine transform into %s%s!", - monnambuf, and_vanish); - redraw = TRUE; /* update figurine's map location */ - } - break; + case OBJ_FLOOR: + if (cansee_spot && !silent) { + if (suppress_see) + pline("%s suddenly vanishes!", an(xname(figurine))); + else + You_see("a figurine transform into %s%s!", monnambuf, + and_vanish); + redraw = TRUE; /* update figurine's map location */ + } + break; - case OBJ_MINVENT: - if (cansee_spot && !silent && !suppress_see) { - struct monst *mon; - mon = figurine->ocarry; - /* figurine carring monster might be invisible */ - if (canseemon(figurine->ocarry)) { - Sprintf(carriedby, "%s pack", - s_suffix(a_monnam(mon))); - } else if (is_pool(mon->mx, mon->my)) - Strcpy(carriedby, "empty water"); - else - Strcpy(carriedby, "thin air"); - You_see("%s %s out of %s%s!", monnambuf, - locomotion(mtmp->data, "drop"), carriedby, - and_vanish); - } - break; + case OBJ_MINVENT: + if (cansee_spot && !silent && !suppress_see) { + struct monst *mon; + mon = figurine->ocarry; + /* figurine carring monster might be invisible */ + if (canseemon(figurine->ocarry)) { + Sprintf(carriedby, "%s pack", s_suffix(a_monnam(mon))); + } else if (is_pool(mon->mx, mon->my)) + Strcpy(carriedby, "empty water"); + else + Strcpy(carriedby, "thin air"); + You_see("%s %s out of %s%s!", monnambuf, + locomotion(mtmp->data, "drop"), carriedby, + and_vanish); + } + break; #if 0 case OBJ_MIGRATING: break; #endif - default: - impossible("figurine came to life where? (%d)", - (int)figurine->where); - break; - } - } - /* free figurine now */ - if (carried(figurine)) { - useup(figurine); - } else { - obj_extract_self(figurine); - obfree(figurine, (struct obj *)0); - } - if (redraw) newsym(cc.x, cc.y); + default: + impossible("figurine came to life where? (%d)", + (int) figurine->where); + break; + } + } + /* free figurine now */ + if (carried(figurine)) { + useup(figurine); + } else { + obj_extract_self(figurine); + obfree(figurine, (struct obj *) 0); + } + if (redraw) + newsym(cc.x, cc.y); } STATIC_OVL boolean @@ -1930,68 +1989,71 @@ struct obj *obj; coord *cc; boolean quietly; { - xchar x,y; + xchar x, y; - if (carried(obj) && u.uswallow) { - if (!quietly) - You("don't have enough room in here."); - return FALSE; - } - x = cc->x; y = cc->y; - if (!isok(x,y)) { - if (!quietly) - You("cannot put the figurine there."); - return FALSE; - } - if (IS_ROCK(levl[x][y].typ) && - !(passes_walls(&mons[obj->corpsenm]) && may_passwall(x,y))) { - if (!quietly) - You("cannot place a figurine in %s!", - IS_TREE(levl[x][y].typ) ? "a tree" : "solid rock"); - return FALSE; - } - if (sobj_at(BOULDER,x,y) && !passes_walls(&mons[obj->corpsenm]) - && !throws_rocks(&mons[obj->corpsenm])) { - if (!quietly) - You("cannot fit the figurine on the boulder."); - return FALSE; - } - return TRUE; + if (carried(obj) && u.uswallow) { + if (!quietly) + You("don't have enough room in here."); + return FALSE; + } + x = cc->x; + y = cc->y; + if (!isok(x, y)) { + if (!quietly) + You("cannot put the figurine there."); + return FALSE; + } + if (IS_ROCK(levl[x][y].typ) + && !(passes_walls(&mons[obj->corpsenm]) && may_passwall(x, y))) { + if (!quietly) + You("cannot place a figurine in %s!", + IS_TREE(levl[x][y].typ) ? "a tree" : "solid rock"); + return FALSE; + } + if (sobj_at(BOULDER, x, y) && !passes_walls(&mons[obj->corpsenm]) + && !throws_rocks(&mons[obj->corpsenm])) { + if (!quietly) + You("cannot fit the figurine on the boulder."); + return FALSE; + } + return TRUE; } STATIC_OVL void use_figurine(optr) struct obj **optr; { - register struct obj *obj = *optr; - xchar x, y; - coord cc; + register struct obj *obj = *optr; + xchar x, y; + coord cc; - if (u.uswallow) { - /* can't activate a figurine while swallowed */ - if (!figurine_location_checks(obj, (coord *)0, FALSE)) - return; - } - if(!getdir((char *)0)) { - context.move = multi = 0; - return; - } - x = u.ux + u.dx; y = u.uy + u.dy; - cc.x = x; cc.y = y; - /* Passing FALSE arg here will result in messages displayed */ - if (!figurine_location_checks(obj, &cc, FALSE)) return; - You("%s and it transforms.", - (u.dx||u.dy) ? "set the figurine beside you" : - (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) || - is_pool(cc.x, cc.y)) ? - "release the figurine" : - (u.dz < 0 ? - "toss the figurine into the air" : - "set the figurine on the ground")); - (void) make_familiar(obj, cc.x, cc.y, FALSE); - (void) stop_timer(FIG_TRANSFORM, obj_to_any(obj)); - useup(obj); - *optr = 0; + if (u.uswallow) { + /* can't activate a figurine while swallowed */ + if (!figurine_location_checks(obj, (coord *) 0, FALSE)) + return; + } + if (!getdir((char *) 0)) { + context.move = multi = 0; + return; + } + x = u.ux + u.dx; + y = u.uy + u.dy; + cc.x = x; + cc.y = y; + /* Passing FALSE arg here will result in messages displayed */ + if (!figurine_location_checks(obj, &cc, FALSE)) + return; + You("%s and it transforms.", + (u.dx || u.dy) ? "set the figurine beside you" + : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) + || is_pool(cc.x, cc.y)) + ? "release the figurine" + : (u.dz < 0 ? "toss the figurine into the air" + : "set the figurine on the ground")); + (void) make_familiar(obj, cc.x, cc.y, FALSE); + (void) stop_timer(FIG_TRANSFORM, obj_to_any(obj)); + useup(obj); + *optr = 0; } static NEARDATA const char lubricables[] = { ALL_CLASSES, ALLOW_NONE, 0 }; @@ -2000,64 +2062,64 @@ STATIC_OVL void use_grease(obj) struct obj *obj; { - struct obj *otmp; + struct obj *otmp; - if (Glib) { - pline("%s from your %s.", Tobjnam(obj, "slip"), - makeplural(body_part(FINGER))); - dropx(obj); - return; - } + if (Glib) { + pline("%s from your %s.", Tobjnam(obj, "slip"), + makeplural(body_part(FINGER))); + dropx(obj); + return; + } - if (obj->spe > 0) { - if ((obj->cursed || Fumbling) && !rn2(2)) { - consume_obj_charge(obj, TRUE); + if (obj->spe > 0) { + if ((obj->cursed || Fumbling) && !rn2(2)) { + consume_obj_charge(obj, TRUE); - pline("%s from your %s.", Tobjnam(obj, "slip"), - makeplural(body_part(FINGER))); - dropx(obj); - return; - } - otmp = getobj(lubricables, "grease"); - if (!otmp) return; - if (inaccessible_equipment(otmp, "grease", FALSE)) return; - consume_obj_charge(obj, TRUE); + pline("%s from your %s.", Tobjnam(obj, "slip"), + makeplural(body_part(FINGER))); + dropx(obj); + return; + } + otmp = getobj(lubricables, "grease"); + if (!otmp) + return; + if (inaccessible_equipment(otmp, "grease", FALSE)) + return; + consume_obj_charge(obj, TRUE); - if (otmp != &zeroobj) { - You("cover %s with a thick layer of grease.", - yname(otmp)); - otmp->greased = 1; - if (obj->cursed && !nohands(youmonst.data)) { - incr_itimeout(&Glib, rnd(15)); - pline("Some of the grease gets all over your %s.", - makeplural(body_part(HAND))); - } - } else { - incr_itimeout(&Glib, rnd(15)); - You("coat your %s with grease.", - makeplural(body_part(FINGER))); - } - } else { - if (obj->known) - pline("%s empty.", Tobjnam(obj, "are")); - else - pline("%s to be empty.", Tobjnam(obj, "seem")); - } - update_inventory(); + if (otmp != &zeroobj) { + You("cover %s with a thick layer of grease.", yname(otmp)); + otmp->greased = 1; + if (obj->cursed && !nohands(youmonst.data)) { + incr_itimeout(&Glib, rnd(15)); + pline("Some of the grease gets all over your %s.", + makeplural(body_part(HAND))); + } + } else { + incr_itimeout(&Glib, rnd(15)); + You("coat your %s with grease.", makeplural(body_part(FINGER))); + } + } else { + if (obj->known) + pline("%s empty.", Tobjnam(obj, "are")); + else + pline("%s to be empty.", Tobjnam(obj, "seem")); + } + update_inventory(); } static struct trapinfo { - struct obj *tobj; - xchar tx, ty; - int time_needed; - boolean force_bungle; + struct obj *tobj; + xchar tx, ty; + int time_needed; + boolean force_bungle; } trapinfo; void reset_trapset() { - trapinfo.tobj = 0; - trapinfo.force_bungle = 0; + trapinfo.tobj = 0; + trapinfo.force_bungle = 0; } /* touchstones - by Ken Arnold */ @@ -2074,114 +2136,118 @@ struct obj *tstone; static const char coins_gems[3] = { COIN_CLASS, GEM_CLASS, 0 }; /* in case it was acquired while blinded */ - if (!Blind) tstone->dknown = 1; + if (!Blind) + tstone->dknown = 1; /* when the touchstone is fully known, don't bother listing extra junk as likely candidates for rubbing */ - choices = (tstone->otyp == TOUCHSTONE && tstone->dknown && - objects[TOUCHSTONE].oc_name_known) ? coins_gems : allowall; + choices = (tstone->otyp == TOUCHSTONE && tstone->dknown + && objects[TOUCHSTONE].oc_name_known) + ? coins_gems + : allowall; Sprintf(stonebuf, "rub on the stone%s", plur(tstone->quan)); if ((obj = getobj(choices, stonebuf)) == 0) - return; + return; if (obj == tstone && obj->quan == 1L) { - You_cant("rub %s on itself.", the(xname(obj))); - return; + You_cant("rub %s on itself.", the(xname(obj))); + return; } - if (tstone->otyp == TOUCHSTONE && tstone->cursed && - obj->oclass == GEM_CLASS && !is_graystone(obj) && - !obj_resists(obj, 80, 100)) { - if (Blind) - pline("You feel something shatter."); - else if (Hallucination) - pline("Oh, wow, look at the pretty shards."); - else - pline("A sharp crack shatters %s%s.", - (obj->quan > 1L) ? "one of " : "", the(xname(obj))); - useup(obj); - return; + if (tstone->otyp == TOUCHSTONE && tstone->cursed + && obj->oclass == GEM_CLASS && !is_graystone(obj) + && !obj_resists(obj, 80, 100)) { + if (Blind) + pline("You feel something shatter."); + else if (Hallucination) + pline("Oh, wow, look at the pretty shards."); + else + pline("A sharp crack shatters %s%s.", + (obj->quan > 1L) ? "one of " : "", the(xname(obj))); + useup(obj); + return; } if (Blind) { - pline(scritch); - return; + pline(scritch); + return; } else if (Hallucination) { - pline("Oh wow, man: Fractals!"); - return; + pline("Oh wow, man: Fractals!"); + return; } do_scratch = FALSE; streak_color = 0; switch (obj->oclass) { - case GEM_CLASS: /* these have class-specific handling below */ + case GEM_CLASS: /* these have class-specific handling below */ case RING_CLASS: - if (tstone->otyp != TOUCHSTONE) { - do_scratch = TRUE; - } else if (obj->oclass == GEM_CLASS && (tstone->blessed || - (!tstone->cursed && - (Role_if(PM_ARCHEOLOGIST) || Race_if(PM_GNOME))))) { - makeknown(TOUCHSTONE); - makeknown(obj->otyp); - prinv((char *)0, obj, 0L); - return; - } else { - /* either a ring or the touchstone was not effective */ - if (objects[obj->otyp].oc_material == GLASS) { - do_scratch = TRUE; - break; - } - } - streak_color = c_obj_colors[objects[obj->otyp].oc_color]; - break; /* gem or ring */ + if (tstone->otyp != TOUCHSTONE) { + do_scratch = TRUE; + } else if (obj->oclass == GEM_CLASS + && (tstone->blessed + || (!tstone->cursed && (Role_if(PM_ARCHEOLOGIST) + || Race_if(PM_GNOME))))) { + makeknown(TOUCHSTONE); + makeknown(obj->otyp); + prinv((char *) 0, obj, 0L); + return; + } else { + /* either a ring or the touchstone was not effective */ + if (objects[obj->otyp].oc_material == GLASS) { + do_scratch = TRUE; + break; + } + } + streak_color = c_obj_colors[objects[obj->otyp].oc_color]; + break; /* gem or ring */ default: - switch (objects[obj->otyp].oc_material) { - case CLOTH: - pline("%s a little more polished now.", Tobjnam(tstone, "look")); - return; - case LIQUID: - if (!obj->known) /* note: not "whetstone" */ - You("must think this is a wetstone, do you?"); - else - pline("%s a little wetter now.", Tobjnam(tstone, "are")); - return; - case WAX: - streak_color = "waxy"; - break; /* okay even if not touchstone */ - case WOOD: - streak_color = "wooden"; - break; /* okay even if not touchstone */ - case GOLD: - do_scratch = TRUE; /* scratching and streaks */ - streak_color = "golden"; - break; - case SILVER: - do_scratch = TRUE; /* scratching and streaks */ - streak_color = "silvery"; - break; - default: - /* Objects passing the is_flimsy() test will not - scratch a stone. They will leave streaks on - non-touchstones and touchstones alike. */ - if (is_flimsy(obj)) - streak_color = c_obj_colors[objects[obj->otyp].oc_color]; - else - do_scratch = (tstone->otyp != TOUCHSTONE); - break; - } - break; /* default oclass */ + switch (objects[obj->otyp].oc_material) { + case CLOTH: + pline("%s a little more polished now.", Tobjnam(tstone, "look")); + return; + case LIQUID: + if (!obj->known) /* note: not "whetstone" */ + You("must think this is a wetstone, do you?"); + else + pline("%s a little wetter now.", Tobjnam(tstone, "are")); + return; + case WAX: + streak_color = "waxy"; + break; /* okay even if not touchstone */ + case WOOD: + streak_color = "wooden"; + break; /* okay even if not touchstone */ + case GOLD: + do_scratch = TRUE; /* scratching and streaks */ + streak_color = "golden"; + break; + case SILVER: + do_scratch = TRUE; /* scratching and streaks */ + streak_color = "silvery"; + break; + default: + /* Objects passing the is_flimsy() test will not + scratch a stone. They will leave streaks on + non-touchstones and touchstones alike. */ + if (is_flimsy(obj)) + streak_color = c_obj_colors[objects[obj->otyp].oc_color]; + else + do_scratch = (tstone->otyp != TOUCHSTONE); + break; + } + break; /* default oclass */ } Sprintf(stonebuf, "stone%s", plur(tstone->quan)); if (do_scratch) - You("make %s%sscratch marks on the %s.", - streak_color ? streak_color : (const char *)"", - streak_color ? " " : "", stonebuf); + You("make %s%sscratch marks on the %s.", + streak_color ? streak_color : (const char *) "", + streak_color ? " " : "", stonebuf); else if (streak_color) - You_see("%s streaks on the %s.", streak_color, stonebuf); + You_see("%s streaks on the %s.", streak_color, stonebuf); else - pline(scritch); + pline(scritch); return; } @@ -2190,137 +2256,140 @@ STATIC_OVL void use_trap(otmp) struct obj *otmp; { - int ttyp, tmp; - const char *what = (char *)0; - char buf[BUFSZ]; - int levtyp = levl[u.ux][u.uy].typ; - const char *occutext = "setting the trap"; + int ttyp, tmp; + const char *what = (char *) 0; + char buf[BUFSZ]; + int levtyp = levl[u.ux][u.uy].typ; + const char *occutext = "setting the trap"; - if (nohands(youmonst.data)) - what = "without hands"; - else if (Stunned) - what = "while stunned"; - else if (u.uswallow) - what = is_animal(u.ustuck->data) ? "while swallowed" : - "while engulfed"; - else if (Underwater) - what = "underwater"; - else if (Levitation) - what = "while levitating"; - else if (is_pool(u.ux, u.uy)) - what = "in water"; - else if (is_lava(u.ux, u.uy)) - what = "in lava"; - else if (On_stairs(u.ux, u.uy)) - what = (u.ux == xdnladder || u.ux == xupladder) ? - "on the ladder" : "on the stairs"; - else if (IS_FURNITURE(levtyp) || IS_ROCK(levtyp) || - closed_door(u.ux, u.uy) || t_at(u.ux, u.uy)) - what = "here"; - else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) - what = (levtyp == AIR) ? "in midair" : - (levtyp == CLOUD) ? "in a cloud" : - "in this place"; /* Air/Water Plane catch-all */ - if (what) { - You_cant("set a trap %s!",what); - reset_trapset(); - return; - } - ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; - if (otmp == trapinfo.tobj && - u.ux == trapinfo.tx && u.uy == trapinfo.ty) { - You("resume setting %s%s.", - shk_your(buf, otmp), - defsyms[trap_to_defsym(what_trap(ttyp))].explanation); - set_occupation(set_trap, occutext, 0); - return; - } - trapinfo.tobj = otmp; - trapinfo.tx = u.ux, trapinfo.ty = u.uy; - tmp = ACURR(A_DEX); - trapinfo.time_needed = (tmp > 17) ? 2 : (tmp > 12) ? 3 : - (tmp > 7) ? 4 : 5; - if (Blind) trapinfo.time_needed *= 2; - tmp = ACURR(A_STR); - if (ttyp == BEAR_TRAP && tmp < 18) - trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4; - /*[fumbling and/or confusion and/or cursed object check(s) - should be incorporated here instead of in set_trap]*/ - if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { - boolean chance; + if (nohands(youmonst.data)) + what = "without hands"; + else if (Stunned) + what = "while stunned"; + else if (u.uswallow) + what = + is_animal(u.ustuck->data) ? "while swallowed" : "while engulfed"; + else if (Underwater) + what = "underwater"; + else if (Levitation) + what = "while levitating"; + else if (is_pool(u.ux, u.uy)) + what = "in water"; + else if (is_lava(u.ux, u.uy)) + what = "in lava"; + else if (On_stairs(u.ux, u.uy)) + what = (u.ux == xdnladder || u.ux == xupladder) ? "on the ladder" + : "on the stairs"; + else if (IS_FURNITURE(levtyp) || IS_ROCK(levtyp) + || closed_door(u.ux, u.uy) || t_at(u.ux, u.uy)) + what = "here"; + else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) + what = (levtyp == AIR) + ? "in midair" + : (levtyp == CLOUD) + ? "in a cloud" + : "in this place"; /* Air/Water Plane catch-all */ + if (what) { + You_cant("set a trap %s!", what); + reset_trapset(); + return; + } + ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; + if (otmp == trapinfo.tobj && u.ux == trapinfo.tx && u.uy == trapinfo.ty) { + You("resume setting %s%s.", shk_your(buf, otmp), + defsyms[trap_to_defsym(what_trap(ttyp))].explanation); + set_occupation(set_trap, occutext, 0); + return; + } + trapinfo.tobj = otmp; + trapinfo.tx = u.ux, trapinfo.ty = u.uy; + tmp = ACURR(A_DEX); + trapinfo.time_needed = + (tmp > 17) ? 2 : (tmp > 12) ? 3 : (tmp > 7) ? 4 : 5; + if (Blind) + trapinfo.time_needed *= 2; + tmp = ACURR(A_STR); + if (ttyp == BEAR_TRAP && tmp < 18) + trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4; + /*[fumbling and/or confusion and/or cursed object check(s) + should be incorporated here instead of in set_trap]*/ + if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { + boolean chance; - if (Fumbling || otmp->cursed) chance = (rnl(10) > 3); - else chance = (rnl(10) > 5); - You("aren't very skilled at reaching from %s.", - mon_nam(u.usteed)); - Sprintf(buf, "Continue your attempt to set %s?", - the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); - if(yn(buf) == 'y') { - if (chance) { - switch(ttyp) { - case LANDMINE: /* set it off */ - trapinfo.time_needed = 0; - trapinfo.force_bungle = TRUE; - break; - case BEAR_TRAP: /* drop it without arming it */ - reset_trapset(); - You("drop %s!", - the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); - dropx(otmp); - return; - } - } - } else { - reset_trapset(); - return; - } - } - You("begin setting %s%s.", - shk_your(buf, otmp), - defsyms[trap_to_defsym(what_trap(ttyp))].explanation); - set_occupation(set_trap, occutext, 0); - return; + if (Fumbling || otmp->cursed) + chance = (rnl(10) > 3); + else + chance = (rnl(10) > 5); + You("aren't very skilled at reaching from %s.", mon_nam(u.usteed)); + Sprintf(buf, "Continue your attempt to set %s?", + the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); + if (yn(buf) == 'y') { + if (chance) { + switch (ttyp) { + case LANDMINE: /* set it off */ + trapinfo.time_needed = 0; + trapinfo.force_bungle = TRUE; + break; + case BEAR_TRAP: /* drop it without arming it */ + reset_trapset(); + You("drop %s!", + the(defsyms[trap_to_defsym(what_trap(ttyp))] + .explanation)); + dropx(otmp); + return; + } + } + } else { + reset_trapset(); + return; + } + } + You("begin setting %s%s.", shk_your(buf, otmp), + defsyms[trap_to_defsym(what_trap(ttyp))].explanation); + set_occupation(set_trap, occutext, 0); + return; } STATIC_PTR int set_trap() { - struct obj *otmp = trapinfo.tobj; - struct trap *ttmp; - int ttyp; + struct obj *otmp = trapinfo.tobj; + struct trap *ttmp; + int ttyp; - if (!otmp || !carried(otmp) || - u.ux != trapinfo.tx || u.uy != trapinfo.ty) { - /* ?? */ - reset_trapset(); - return 0; - } + if (!otmp || !carried(otmp) || u.ux != trapinfo.tx + || u.uy != trapinfo.ty) { + /* ?? */ + reset_trapset(); + return 0; + } - if (--trapinfo.time_needed > 0) return 1; /* still busy */ + if (--trapinfo.time_needed > 0) + return 1; /* still busy */ - ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; - ttmp = maketrap(u.ux, u.uy, ttyp); - if (ttmp) { - ttmp->madeby_u = 1; - feeltrap(ttmp); - if (*in_rooms(u.ux,u.uy,SHOPBASE)) { - add_damage(u.ux, u.uy, 0L); /* schedule removal */ - } - if (!trapinfo.force_bungle) - You("finish arming %s.", - the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); - if (((otmp->cursed || Fumbling) && (rnl(10) > 5)) || - trapinfo.force_bungle) - dotrap(ttmp, - (unsigned)(trapinfo.force_bungle ? FORCEBUNGLE : 0)); - } else { - /* this shouldn't happen */ - Your("trap setting attempt fails."); - } - useup(otmp); - reset_trapset(); - return 0; + ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; + ttmp = maketrap(u.ux, u.uy, ttyp); + if (ttmp) { + ttmp->madeby_u = 1; + feeltrap(ttmp); + if (*in_rooms(u.ux, u.uy, SHOPBASE)) { + add_damage(u.ux, u.uy, 0L); /* schedule removal */ + } + if (!trapinfo.force_bungle) + You("finish arming %s.", + the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation)); + if (((otmp->cursed || Fumbling) && (rnl(10) > 5)) + || trapinfo.force_bungle) + dotrap(ttmp, + (unsigned) (trapinfo.force_bungle ? FORCEBUNGLE : 0)); + } else { + /* this shouldn't happen */ + Your("trap setting attempt fails."); + } + useup(otmp); + reset_trapset(); + return 0; } STATIC_OVL int @@ -2335,175 +2404,190 @@ struct obj *obj; const char *msg_snap = "Snap!"; if (obj != uwep) { - if (!wield_tool(obj, "lash")) return 0; - else res = 1; + if (!wield_tool(obj, "lash")) + return 0; + else + res = 1; } - if (!getdir((char *)0)) return res; + if (!getdir((char *) 0)) + return res; if (u.uswallow) { - mtmp = u.ustuck; - rx = mtmp->mx; - ry = mtmp->my; + mtmp = u.ustuck; + rx = mtmp->mx; + ry = mtmp->my; } else { - if (Stunned || (Confusion && !rn2(5))) confdir(); - rx = u.ux + u.dx; - ry = u.uy + u.dy; - if (!isok(rx, ry)) { - You("miss."); - return res; - } - mtmp = m_at(rx, ry); + if (Stunned || (Confusion && !rn2(5))) + confdir(); + rx = u.ux + u.dx; + ry = u.uy + u.dy; + if (!isok(rx, ry)) { + You("miss."); + return res; + } + mtmp = m_at(rx, ry); } /* fake some proficiency checks */ proficient = 0; - if (Role_if(PM_ARCHEOLOGIST)) ++proficient; - if (ACURR(A_DEX) < 6) proficient--; - else if (ACURR(A_DEX) >= 14) proficient += (ACURR(A_DEX) - 14); - if (Fumbling) --proficient; - if (proficient > 3) proficient = 3; - if (proficient < 0) proficient = 0; + if (Role_if(PM_ARCHEOLOGIST)) + ++proficient; + if (ACURR(A_DEX) < 6) + proficient--; + else if (ACURR(A_DEX) >= 14) + proficient += (ACURR(A_DEX) - 14); + if (Fumbling) + --proficient; + if (proficient > 3) + proficient = 3; + if (proficient < 0) + proficient = 0; if (u.uswallow && attack(u.ustuck)) { - There("is not enough room to flick your bullwhip."); + There("is not enough room to flick your bullwhip."); } else if (Underwater) { - There("is too much resistance to flick your bullwhip."); + There("is too much resistance to flick your bullwhip."); } else if (u.dz < 0) { - You("flick a bug off of the %s.",ceiling(u.ux,u.uy)); + You("flick a bug off of the %s.", ceiling(u.ux, u.uy)); } else if ((!u.dx && !u.dy) || (u.dz > 0)) { - int dam; + int dam; - /* Sometimes you hit your steed by mistake */ - if (u.usteed && !rn2(proficient + 2)) { - You("whip %s!", mon_nam(u.usteed)); - kick_steed(); - return 1; - } - if (Levitation || u.usteed) { - /* Have a shot at snaring something on the floor */ - otmp = level.objects[u.ux][u.uy]; - if (otmp && otmp->otyp == CORPSE && otmp->corpsenm == PM_HORSE) { - pline("Why beat a dead horse?"); - return 1; - } - if (otmp && proficient) { - You("wrap your bullwhip around %s on the %s.", - an(singular(otmp, xname)), surface(u.ux, u.uy)); - if (rnl(6) || pickup_object(otmp, 1L, TRUE) < 1) - pline1(msg_slipsfree); - return 1; - } - } - dam = rnd(2) + dbon() + obj->spe; - if (dam <= 0) dam = 1; - You("hit your %s with your bullwhip.", body_part(FOOT)); - Sprintf(buf, "killed %sself with %s bullwhip", uhim(), uhis()); - losehp(Maybe_Half_Phys(dam), buf, NO_KILLER_PREFIX); - context.botl = 1; - return 1; + /* Sometimes you hit your steed by mistake */ + if (u.usteed && !rn2(proficient + 2)) { + You("whip %s!", mon_nam(u.usteed)); + kick_steed(); + return 1; + } + if (Levitation || u.usteed) { + /* Have a shot at snaring something on the floor */ + otmp = level.objects[u.ux][u.uy]; + if (otmp && otmp->otyp == CORPSE && otmp->corpsenm == PM_HORSE) { + pline("Why beat a dead horse?"); + return 1; + } + if (otmp && proficient) { + You("wrap your bullwhip around %s on the %s.", + an(singular(otmp, xname)), surface(u.ux, u.uy)); + if (rnl(6) || pickup_object(otmp, 1L, TRUE) < 1) + pline1(msg_slipsfree); + return 1; + } + } + dam = rnd(2) + dbon() + obj->spe; + if (dam <= 0) + dam = 1; + You("hit your %s with your bullwhip.", body_part(FOOT)); + Sprintf(buf, "killed %sself with %s bullwhip", uhim(), uhis()); + losehp(Maybe_Half_Phys(dam), buf, NO_KILLER_PREFIX); + context.botl = 1; + return 1; } else if ((Fumbling || Glib) && !rn2(5)) { - pline_The("bullwhip slips out of your %s.", body_part(HAND)); - dropx(obj); + pline_The("bullwhip slips out of your %s.", body_part(HAND)); + dropx(obj); } else if (u.utrap && u.utraptype == TT_PIT) { - /* - * Assumptions: - * - * if you're in a pit - * - you are attempting to get out of the pit - * - or, if you are applying it towards a small - * monster then it is assumed that you are - * trying to hit it. - * else if the monster is wielding a weapon - * - you are attempting to disarm a monster - * else - * - you are attempting to hit the monster - * - * if you're confused (and thus off the mark) - * - you only end up hitting. - * - */ - const char *wrapped_what = (char *)0; + /* + * Assumptions: + * + * if you're in a pit + * - you are attempting to get out of the pit + * - or, if you are applying it towards a small + * monster then it is assumed that you are + * trying to hit it. + * else if the monster is wielding a weapon + * - you are attempting to disarm a monster + * else + * - you are attempting to hit the monster + * + * if you're confused (and thus off the mark) + * - you only end up hitting. + * + */ + const char *wrapped_what = (char *) 0; - if (mtmp) { - if (bigmonst(mtmp->data)) { - wrapped_what = strcpy(buf, mon_nam(mtmp)); - } else if (proficient) { - if (attack(mtmp)) return 1; - else pline1(msg_snap); - } - } - if (!wrapped_what) { - if (IS_FURNITURE(levl[rx][ry].typ)) - wrapped_what = something; - else if (sobj_at(BOULDER, rx, ry)) - wrapped_what = "a boulder"; - } - if (wrapped_what) { - coord cc; + if (mtmp) { + if (bigmonst(mtmp->data)) { + wrapped_what = strcpy(buf, mon_nam(mtmp)); + } else if (proficient) { + if (attack(mtmp)) + return 1; + else + pline1(msg_snap); + } + } + if (!wrapped_what) { + if (IS_FURNITURE(levl[rx][ry].typ)) + wrapped_what = something; + else if (sobj_at(BOULDER, rx, ry)) + wrapped_what = "a boulder"; + } + if (wrapped_what) { + coord cc; - cc.x = rx; cc.y = ry; - You("wrap your bullwhip around %s.", wrapped_what); - if (proficient && rn2(proficient + 2)) { - if (!mtmp || enexto(&cc, rx, ry, youmonst.data)) { - You("yank yourself out of the pit!"); - teleds(cc.x, cc.y, TRUE); - u.utrap = 0; - vision_full_recalc = 1; - } - } else { - pline1(msg_slipsfree); - } - if (mtmp) wakeup(mtmp); - } else pline1(msg_snap); + cc.x = rx; + cc.y = ry; + You("wrap your bullwhip around %s.", wrapped_what); + if (proficient && rn2(proficient + 2)) { + if (!mtmp || enexto(&cc, rx, ry, youmonst.data)) { + You("yank yourself out of the pit!"); + teleds(cc.x, cc.y, TRUE); + u.utrap = 0; + vision_full_recalc = 1; + } + } else { + pline1(msg_slipsfree); + } + if (mtmp) + wakeup(mtmp); + } else + pline1(msg_snap); } else if (mtmp) { - if (!canspotmon(mtmp) && - !glyph_is_invisible(levl[rx][ry].glyph)) { - pline("A monster is there that you couldn't see."); - map_invisible(rx, ry); - } - otmp = MON_WEP(mtmp); /* can be null */ - if (otmp) { - char onambuf[BUFSZ]; - const char *mon_hand; - boolean gotit = proficient && (!Fumbling || !rn2(10)); + if (!canspotmon(mtmp) && !glyph_is_invisible(levl[rx][ry].glyph)) { + pline("A monster is there that you couldn't see."); + map_invisible(rx, ry); + } + otmp = MON_WEP(mtmp); /* can be null */ + if (otmp) { + char onambuf[BUFSZ]; + const char *mon_hand; + boolean gotit = proficient && (!Fumbling || !rn2(10)); - Strcpy(onambuf, cxname(otmp)); - if (gotit) { - mon_hand = mbodypart(mtmp, HAND); - if (bimanual(otmp)) mon_hand = makeplural(mon_hand); - } else - mon_hand = 0; /* lint suppression */ + Strcpy(onambuf, cxname(otmp)); + if (gotit) { + mon_hand = mbodypart(mtmp, HAND); + if (bimanual(otmp)) + mon_hand = makeplural(mon_hand); + } else + mon_hand = 0; /* lint suppression */ - You("wrap your bullwhip around %s.", yname(otmp)); - if (gotit && mwelded(otmp)) { - pline("%s welded to %s %s%c", - (otmp->quan == 1L) ? "It is" : "They are", - mhis(mtmp), mon_hand, - !otmp->bknown ? '!' : '.'); - otmp->bknown = 1; - gotit = FALSE; /* can't pull it free */ - } - if (gotit) { - obj_extract_self(otmp); - possibly_unwield(mtmp, FALSE); - setmnotwielded(mtmp,otmp); + You("wrap your bullwhip around %s.", yname(otmp)); + if (gotit && mwelded(otmp)) { + pline("%s welded to %s %s%c", + (otmp->quan == 1L) ? "It is" : "They are", mhis(mtmp), + mon_hand, !otmp->bknown ? '!' : '.'); + otmp->bknown = 1; + gotit = FALSE; /* can't pull it free */ + } + if (gotit) { + obj_extract_self(otmp); + possibly_unwield(mtmp, FALSE); + setmnotwielded(mtmp, otmp); - switch (rn2(proficient + 1)) { - case 2: - /* to floor near you */ - You("yank %s to the %s!", - yname(otmp), surface(u.ux, u.uy)); - place_object(otmp, u.ux, u.uy); - stackobj(otmp); - break; - case 3: - /* right to you */ + switch (rn2(proficient + 1)) { + case 2: + /* to floor near you */ + You("yank %s to the %s!", yname(otmp), + surface(u.ux, u.uy)); + place_object(otmp, u.ux, u.uy); + stackobj(otmp); + break; + case 3: +/* right to you */ #if 0 if (!rn2(25)) { /* proficient with whip, but maybe not @@ -2523,64 +2607,66 @@ struct obj *obj; break; } #endif /* 0 */ - /* right into your inventory */ - You("snatch %s!", yname(otmp)); - if (otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm]) && - !uarmg && !Stone_resistance && - !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - char kbuf[BUFSZ]; + /* right into your inventory */ + You("snatch %s!", yname(otmp)); + if (otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm]) && !uarmg + && !Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + char kbuf[BUFSZ]; - Sprintf(kbuf, "%s corpse", - an(mons[otmp->corpsenm].mname)); - pline("Snatching %s is a fatal mistake.", kbuf); - instapetrify(kbuf); - } - otmp = hold_another_object(otmp, "You drop %s!", - doname(otmp), (const char *)0); - break; - default: - /* to floor beneath mon */ - You("yank %s from %s %s!", the(onambuf), - s_suffix(mon_nam(mtmp)), mon_hand); - obj_no_longer_held(otmp); - place_object(otmp, mtmp->mx, mtmp->my); - stackobj(otmp); - break; - } - } else { - pline1(msg_slipsfree); - } - wakeup(mtmp); - } else { - if (mtmp->m_ap_type && - !Protection_from_shape_changers && !sensemon(mtmp)) - stumble_onto_mimic(mtmp); - else You("flick your bullwhip towards %s.", mon_nam(mtmp)); - if (proficient) { - if (attack(mtmp)) return 1; - else pline1(msg_snap); - } - } + Sprintf(kbuf, "%s corpse", + an(mons[otmp->corpsenm].mname)); + pline("Snatching %s is a fatal mistake.", kbuf); + instapetrify(kbuf); + } + otmp = hold_another_object( + otmp, "You drop %s!", doname(otmp), (const char *) 0); + break; + default: + /* to floor beneath mon */ + You("yank %s from %s %s!", the(onambuf), + s_suffix(mon_nam(mtmp)), mon_hand); + obj_no_longer_held(otmp); + place_object(otmp, mtmp->mx, mtmp->my); + stackobj(otmp); + break; + } + } else { + pline1(msg_slipsfree); + } + wakeup(mtmp); + } else { + if (mtmp->m_ap_type && !Protection_from_shape_changers + && !sensemon(mtmp)) + stumble_onto_mimic(mtmp); + else + You("flick your bullwhip towards %s.", mon_nam(mtmp)); + if (proficient) { + if (attack(mtmp)) + return 1; + else + pline1(msg_snap); + } + } } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { - /* it must be air -- water checked above */ - You("snap your whip through thin air."); + /* it must be air -- water checked above */ + You("snap your whip through thin air."); } else { - pline1(msg_snap); - + pline1(msg_snap); } return 1; } - -static const char - not_enough_room[] = "There's not enough room here to use that.", - where_to_hit[] = "Where do you want to hit?", - cant_see_spot[] = "won't hit anything if you can't see that spot.", - cant_reach[] = "can't reach that spot from here."; +static const char not_enough_room[] = + "There's not enough room here to use that.", + where_to_hit[] = "Where do you want to hit?", + cant_see_spot[] = + "won't hit anything if you can't see that spot.", + cant_reach[] = "can't reach that spot from here."; /* find pos of monster in range, if only one monster */ boolean @@ -2591,14 +2677,16 @@ int min_range, max_range; struct monst *mtmp; struct monst *selmon = NULL; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (mtmp && !DEADMONSTER(mtmp) && !mtmp->mtame && - cansee(mtmp->mx, mtmp->my) && - distu(mtmp->mx, mtmp->my) <= max_range && - distu(mtmp->mx, mtmp->my) >= min_range) { - if (selmon) return FALSE; - selmon = mtmp; - } - if (!selmon) return FALSE; + if (mtmp && !DEADMONSTER(mtmp) && !mtmp->mtame + && cansee(mtmp->mx, mtmp->my) + && distu(mtmp->mx, mtmp->my) <= max_range + && distu(mtmp->mx, mtmp->my) >= min_range) { + if (selmon) + return FALSE; + selmon = mtmp; + } + if (!selmon) + return FALSE; pos->x = selmon->mx; pos->y = selmon->my; return TRUE; @@ -2612,326 +2700,337 @@ display_polearm_positions(state) int state; { if (state == 0) { - tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); + tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); } else if (state == 1) { - int x,y, dx,dy; - for (dx = -4; dx <= 4; dx++) - for (dy = -4; dy <= 4; dy++) { - x = dx + (int)u.ux; - y = dy + (int)u.uy; - if (isok(x, y) && ACCESSIBLE(levl[x][y].typ) && - distu(x, y) >= polearm_range_min && - distu(x, y) <= polearm_range_max) { - tmp_at(x, y); - } - } + int x, y, dx, dy; + for (dx = -4; dx <= 4; dx++) + for (dy = -4; dy <= 4; dy++) { + x = dx + (int) u.ux; + y = dy + (int) u.uy; + if (isok(x, y) && ACCESSIBLE(levl[x][y].typ) + && distu(x, y) >= polearm_range_min + && distu(x, y) <= polearm_range_max) { + tmp_at(x, y); + } + } } else { - tmp_at(DISP_END, 0); + tmp_at(DISP_END, 0); } } /* Distance attacks by pole-weapons */ STATIC_OVL int use_pole(obj) - struct obj *obj; +struct obj *obj; { - int res = 0, typ, max_range, min_range, glyph; - coord cc; - struct monst *mtmp; - struct monst *hitm = context.polearm.hitmon; + int res = 0, typ, max_range, min_range, glyph; + coord cc; + struct monst *mtmp; + struct monst *hitm = context.polearm.hitmon; - /* Are you allowed to use the pole? */ - if (u.uswallow) { - pline(not_enough_room); - return (0); - } - if (obj != uwep) { - if (!wield_tool(obj, "swing")) return(0); - else res = 1; - } - /* assert(obj == uwep); */ + /* Are you allowed to use the pole? */ + if (u.uswallow) { + pline(not_enough_room); + return (0); + } + if (obj != uwep) { + if (!wield_tool(obj, "swing")) + return (0); + else + res = 1; + } + /* assert(obj == uwep); */ - /* - * Calculate allowable range (pole's reach is always 2 steps): - * unskilled and basic: orthogonal direction, 4..4; - * skilled: as basic, plus knight's jump position, 4..5; - * expert: as skilled, plus diagonal, 4..8. - * ...9... - * .85458. - * .52125. - * 9410149 - * .52125. - * .85458. - * ...9... - * (Note: no roles in nethack can become expert or better - * for polearm skill; Yeoman in slash'em can become expert.) - */ - min_range = 4; - typ = uwep_skill_type(); - if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) max_range = 4; - else if (P_SKILL(typ) == P_SKILLED) max_range = 5; - else max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */ + /* +* Calculate allowable range (pole's reach is always 2 steps): +* unskilled and basic: orthogonal direction, 4..4; +* skilled: as basic, plus knight's jump position, 4..5; +* expert: as skilled, plus diagonal, 4..8. +* ...9... +* .85458. +* .52125. +* 9410149 +* .52125. +* .85458. +* ...9... +* (Note: no roles in nethack can become expert or better +* for polearm skill; Yeoman in slash'em can become expert.) +*/ + min_range = 4; + typ = uwep_skill_type(); + if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) + max_range = 4; + else if (P_SKILL(typ) == P_SKILLED) + max_range = 5; + else + max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */ - polearm_range_min = min_range; - polearm_range_max = max_range; + polearm_range_min = min_range; + polearm_range_max = max_range; - /* Prompt for a location */ - pline(where_to_hit); - cc.x = u.ux; - cc.y = u.uy; - if (!find_poleable_mon(&cc, min_range, max_range) && - hitm && !DEADMONSTER(hitm) && cansee(hitm->mx, hitm->my) && - distu(hitm->mx,hitm->my) <= max_range && - distu(hitm->mx,hitm->my) >= min_range) { - cc.x = hitm->mx; - cc.y = hitm->my; - } - getpos_sethilite(display_polearm_positions); - if (getpos(&cc, TRUE, "the spot to hit") < 0) - return res; /* ESC; uses turn iff polearm became wielded */ + /* Prompt for a location */ + pline(where_to_hit); + cc.x = u.ux; + cc.y = u.uy; + if (!find_poleable_mon(&cc, min_range, max_range) && hitm + && !DEADMONSTER(hitm) && cansee(hitm->mx, hitm->my) + && distu(hitm->mx, hitm->my) <= max_range + && distu(hitm->mx, hitm->my) >= min_range) { + cc.x = hitm->mx; + cc.y = hitm->my; + } + getpos_sethilite(display_polearm_positions); + if (getpos(&cc, TRUE, "the spot to hit") < 0) + return res; /* ESC; uses turn iff polearm became wielded */ - glyph = glyph_at(cc.x, cc.y); - if (distu(cc.x, cc.y) > max_range) { - pline("Too far!"); - return (res); - } else if (distu(cc.x, cc.y) < min_range) { - pline("Too close!"); - return (res); - } else if (!cansee(cc.x, cc.y) && - !glyph_is_monster(glyph) && - !glyph_is_invisible(glyph) && - !glyph_is_statue(glyph)) { - You(cant_see_spot); - return (res); - } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ - You(cant_reach); - return res; - } + glyph = glyph_at(cc.x, cc.y); + if (distu(cc.x, cc.y) > max_range) { + pline("Too far!"); + return (res); + } else if (distu(cc.x, cc.y) < min_range) { + pline("Too close!"); + return (res); + } else if (!cansee(cc.x, cc.y) && !glyph_is_monster(glyph) + && !glyph_is_invisible(glyph) && !glyph_is_statue(glyph)) { + You(cant_see_spot); + return (res); + } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ + You(cant_reach); + return res; + } - context.polearm.hitmon = NULL; - /* Attack the monster there */ - bhitpos = cc; - if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != (struct monst *)0) { - if (attack_checks(mtmp, uwep)) return res; - if (overexertion()) return 1; /* burn nutrition; maybe pass out */ - context.polearm.hitmon = mtmp; - check_caitiff(mtmp); - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); - (void) thitmonst(mtmp, uwep); - } else if (glyph_is_statue(glyph) && /* might be hallucinatory */ - sobj_at(STATUE, bhitpos.x, bhitpos.y)) { - struct trap *t = t_at(bhitpos.x, bhitpos.y); + context.polearm.hitmon = NULL; + /* Attack the monster there */ + bhitpos = cc; + if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != (struct monst *) 0) { + if (attack_checks(mtmp, uwep)) + return res; + if (overexertion()) + return 1; /* burn nutrition; maybe pass out */ + context.polearm.hitmon = mtmp; + check_caitiff(mtmp); + notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + (void) thitmonst(mtmp, uwep); + } else if (glyph_is_statue(glyph) && /* might be hallucinatory */ + sobj_at(STATUE, bhitpos.x, bhitpos.y)) { + struct trap *t = t_at(bhitpos.x, bhitpos.y); - if (t && t->ttyp == STATUE_TRAP && - activate_statue_trap(t, t->tx, t->ty, FALSE)) { - ; /* feedback has been give by animate_statue() */ - } else { - /* Since statues look like monsters now, we say something - different from "you miss" or "there's nobody there". - Note: we only do this when a statue is displayed here, - because the player is probably attempting to attack it; - other statues obscured by anything are just ignored. */ - pline("Thump! Your blow bounces harmlessly off the statue."); - wake_nearto(bhitpos.x, bhitpos.y, 25); - } - } else { - /* no monster here and no statue seen or remembered here */ - if (glyph_is_invisible(glyph)) { - /* now you know that nothing is there... */ - unmap_object(bhitpos.x, bhitpos.y); - newsym(bhitpos.x, bhitpos.y); - } - You("miss; there is no one there to hit."); - } - u_wipe_engr(2); /* same as for melee or throwing */ - return (1); + if (t && t->ttyp == STATUE_TRAP + && activate_statue_trap(t, t->tx, t->ty, FALSE)) { + ; /* feedback has been give by animate_statue() */ + } else { + /* Since statues look like monsters now, we say something + different from "you miss" or "there's nobody there". + Note: we only do this when a statue is displayed here, + because the player is probably attempting to attack it; + other statues obscured by anything are just ignored. */ + pline("Thump! Your blow bounces harmlessly off the statue."); + wake_nearto(bhitpos.x, bhitpos.y, 25); + } + } else { + /* no monster here and no statue seen or remembered here */ + if (glyph_is_invisible(glyph)) { + /* now you know that nothing is there... */ + unmap_object(bhitpos.x, bhitpos.y); + newsym(bhitpos.x, bhitpos.y); + } + You("miss; there is no one there to hit."); + } + u_wipe_engr(2); /* same as for melee or throwing */ + return (1); } STATIC_OVL int use_cream_pie(obj) struct obj *obj; { - boolean wasblind = Blind; - boolean wascreamed = u.ucreamed; - boolean several = FALSE; + boolean wasblind = Blind; + boolean wascreamed = u.ucreamed; + boolean several = FALSE; - if (obj->quan > 1L) { - several = TRUE; - obj = splitobj(obj, 1L); - } - if (Hallucination) - You("give yourself a facial."); - else - pline("You immerse your %s in %s%s.", body_part(FACE), - several ? "one of " : "", - several ? makeplural(the(xname(obj))) : the(xname(obj))); - if(can_blnd((struct monst*)0, &youmonst, AT_WEAP, obj)) { - int blindinc = rnd(25); - u.ucreamed += blindinc; - make_blinded(Blinded + (long)blindinc, FALSE); - if (!Blind || (Blind && wasblind)) - pline("There's %ssticky goop all over your %s.", - wascreamed ? "more " : "", - body_part(FACE)); - else /* Blind && !wasblind */ - You_cant("see through all the sticky goop on your %s.", - body_part(FACE)); - } + if (obj->quan > 1L) { + several = TRUE; + obj = splitobj(obj, 1L); + } + if (Hallucination) + You("give yourself a facial."); + else + pline("You immerse your %s in %s%s.", body_part(FACE), + several ? "one of " : "", + several ? makeplural(the(xname(obj))) : the(xname(obj))); + if (can_blnd((struct monst *) 0, &youmonst, AT_WEAP, obj)) { + int blindinc = rnd(25); + u.ucreamed += blindinc; + make_blinded(Blinded + (long) blindinc, FALSE); + if (!Blind || (Blind && wasblind)) + pline("There's %ssticky goop all over your %s.", + wascreamed ? "more " : "", body_part(FACE)); + else /* Blind && !wasblind */ + You_cant("see through all the sticky goop on your %s.", + body_part(FACE)); + } - setnotworn(obj); - /* useup() is appropriate, but we want costly_alteration()'s message */ - costly_alteration(obj, COST_SPLAT); - obj_extract_self(obj); - delobj(obj); - return(0); + setnotworn(obj); + /* useup() is appropriate, but we want costly_alteration()'s message */ + costly_alteration(obj, COST_SPLAT); + obj_extract_self(obj); + delobj(obj); + return (0); } STATIC_OVL int use_grapple(obj) - struct obj *obj; +struct obj *obj; { - int res = 0, typ, max_range = 4, tohit; - boolean save_confirm; - coord cc; - struct monst *mtmp; - struct obj *otmp; + int res = 0, typ, max_range = 4, tohit; + boolean save_confirm; + coord cc; + struct monst *mtmp; + struct obj *otmp; - /* Are you allowed to use the hook? */ - if (u.uswallow) { - pline(not_enough_room); - return (0); - } - if (obj != uwep) { - if (!wield_tool(obj, "cast")) return(0); - else res = 1; - } - /* assert(obj == uwep); */ + /* Are you allowed to use the hook? */ + if (u.uswallow) { + pline(not_enough_room); + return (0); + } + if (obj != uwep) { + if (!wield_tool(obj, "cast")) + return (0); + else + res = 1; + } + /* assert(obj == uwep); */ - /* Prompt for a location */ - pline(where_to_hit); - cc.x = u.ux; - cc.y = u.uy; - if (getpos(&cc, TRUE, "the spot to hit") < 0) - return res; /* ESC; uses turn iff grapnel became wielded */ + /* Prompt for a location */ + pline(where_to_hit); + cc.x = u.ux; + cc.y = u.uy; + if (getpos(&cc, TRUE, "the spot to hit") < 0) + return res; /* ESC; uses turn iff grapnel became wielded */ - /* Calculate range; unlike use_pole(), there's no minimum for range */ - typ = uwep_skill_type(); - if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) max_range = 4; - else if (P_SKILL(typ) == P_SKILLED) max_range = 5; - else max_range = 8; - if (distu(cc.x, cc.y) > max_range) { - pline("Too far!"); - return (res); - } else if (!cansee(cc.x, cc.y)) { - You(cant_see_spot); - return (res); - } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ - You(cant_reach); - return res; - } + /* Calculate range; unlike use_pole(), there's no minimum for range */ + typ = uwep_skill_type(); + if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) + max_range = 4; + else if (P_SKILL(typ) == P_SKILLED) + max_range = 5; + else + max_range = 8; + if (distu(cc.x, cc.y) > max_range) { + pline("Too far!"); + return (res); + } else if (!cansee(cc.x, cc.y)) { + You(cant_see_spot); + return (res); + } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ + You(cant_reach); + return res; + } - /* What do you want to hit? */ - tohit = rn2(5); - if (typ != P_NONE && P_SKILL(typ) >= P_SKILLED) { - winid tmpwin = create_nhwindow(NHW_MENU); - anything any; - char buf[BUFSZ]; - menu_item *selected; + /* What do you want to hit? */ + tohit = rn2(5); + if (typ != P_NONE && P_SKILL(typ) >= P_SKILLED) { + winid tmpwin = create_nhwindow(NHW_MENU); + anything any; + char buf[BUFSZ]; + menu_item *selected; - any = zeroany; /* set all bits to zero */ - any.a_int = 1; /* use index+1 (cant use 0) as identifier */ - start_menu(tmpwin); - any.a_int++; - Sprintf(buf, "an object on the %s", surface(cc.x, cc.y)); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - buf, MENU_UNSELECTED); - any.a_int++; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - "a monster", MENU_UNSELECTED); - any.a_int++; - Sprintf(buf, "the %s", surface(cc.x, cc.y)); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - buf, MENU_UNSELECTED); - end_menu(tmpwin, "Aim for what?"); - tohit = rn2(4); - if (select_menu(tmpwin, PICK_ONE, &selected) > 0 && - rn2(P_SKILL(typ) > P_SKILLED ? 20 : 2)) - tohit = selected[0].item.a_int - 1; - free((genericptr_t)selected); - destroy_nhwindow(tmpwin); - } + any = zeroany; /* set all bits to zero */ + any.a_int = 1; /* use index+1 (cant use 0) as identifier */ + start_menu(tmpwin); + any.a_int++; + Sprintf(buf, "an object on the %s", surface(cc.x, cc.y)); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + any.a_int++; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "a monster", + MENU_UNSELECTED); + any.a_int++; + Sprintf(buf, "the %s", surface(cc.x, cc.y)); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + end_menu(tmpwin, "Aim for what?"); + tohit = rn2(4); + if (select_menu(tmpwin, PICK_ONE, &selected) > 0 + && rn2(P_SKILL(typ) > P_SKILLED ? 20 : 2)) + tohit = selected[0].item.a_int - 1; + free((genericptr_t) selected); + destroy_nhwindow(tmpwin); + } - /* possibly scuff engraving at your feet; - any engraving at the target location is unaffected */ - if (tohit == 2 || !rn2(2)) u_wipe_engr(rnd(2)); + /* possibly scuff engraving at your feet; + any engraving at the target location is unaffected */ + if (tohit == 2 || !rn2(2)) + u_wipe_engr(rnd(2)); - /* What did you hit? */ - switch (tohit) { - case 0: /* Trap */ - /* FIXME -- untrap needs to deal with non-adjacent traps */ - break; - case 1: /* Object */ - if ((otmp = level.objects[cc.x][cc.y]) != 0) { - You("snag an object from the %s!", surface(cc.x, cc.y)); - (void) pickup_object(otmp, 1L, FALSE); - /* If pickup fails, leave it alone */ - newsym(cc.x, cc.y); - return (1); - } - break; - case 2: /* Monster */ - bhitpos = cc; - if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *)0) break; - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); - save_confirm = flags.confirm; - if (verysmall(mtmp->data) && !rn2(4) && - enexto(&cc, u.ux, u.uy, (struct permonst *)0)) { - flags.confirm = FALSE; - (void) attack_checks(mtmp, uwep); - flags.confirm = save_confirm; - check_caitiff(mtmp); /* despite fact there's no damage */ - You("pull in %s!", mon_nam(mtmp)); - mtmp->mundetected = 0; - rloc_to(mtmp, cc.x, cc.y); - return (1); - } else if ((!bigmonst(mtmp->data) && !strongmonst(mtmp->data)) || - rn2(4)) { - flags.confirm = FALSE; - (void) attack_checks(mtmp, uwep); - flags.confirm = save_confirm; - check_caitiff(mtmp); - (void) thitmonst(mtmp, uwep); - return (1); - } - /* FALL THROUGH */ - case 3: /* Surface */ - if (IS_AIR(levl[cc.x][cc.y].typ) || is_pool(cc.x, cc.y)) - pline_The("hook slices through the %s.", surface(cc.x, cc.y)); - else { - You("are yanked toward the %s!", surface(cc.x, cc.y)); - hurtle(sgn(cc.x-u.ux), sgn(cc.y-u.uy), 1, FALSE); - spoteffects(TRUE); - } - return (1); - default: /* Yourself (oops!) */ - if (P_SKILL(typ) <= P_BASIC) { - You("hook yourself!"); - losehp(Maybe_Half_Phys(rn1(10,10)), "a grappling hook", KILLED_BY); - return (1); - } - break; - } - pline1(nothing_happens); - return (1); + /* What did you hit? */ + switch (tohit) { + case 0: /* Trap */ + /* FIXME -- untrap needs to deal with non-adjacent traps */ + break; + case 1: /* Object */ + if ((otmp = level.objects[cc.x][cc.y]) != 0) { + You("snag an object from the %s!", surface(cc.x, cc.y)); + (void) pickup_object(otmp, 1L, FALSE); + /* If pickup fails, leave it alone */ + newsym(cc.x, cc.y); + return (1); + } + break; + case 2: /* Monster */ + bhitpos = cc; + if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *) 0) + break; + notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + save_confirm = flags.confirm; + if (verysmall(mtmp->data) && !rn2(4) + && enexto(&cc, u.ux, u.uy, (struct permonst *) 0)) { + flags.confirm = FALSE; + (void) attack_checks(mtmp, uwep); + flags.confirm = save_confirm; + check_caitiff(mtmp); /* despite fact there's no damage */ + You("pull in %s!", mon_nam(mtmp)); + mtmp->mundetected = 0; + rloc_to(mtmp, cc.x, cc.y); + return (1); + } else if ((!bigmonst(mtmp->data) && !strongmonst(mtmp->data)) + || rn2(4)) { + flags.confirm = FALSE; + (void) attack_checks(mtmp, uwep); + flags.confirm = save_confirm; + check_caitiff(mtmp); + (void) thitmonst(mtmp, uwep); + return (1); + } + /* FALL THROUGH */ + case 3: /* Surface */ + if (IS_AIR(levl[cc.x][cc.y].typ) || is_pool(cc.x, cc.y)) + pline_The("hook slices through the %s.", surface(cc.x, cc.y)); + else { + You("are yanked toward the %s!", surface(cc.x, cc.y)); + hurtle(sgn(cc.x - u.ux), sgn(cc.y - u.uy), 1, FALSE); + spoteffects(TRUE); + } + return (1); + default: /* Yourself (oops!) */ + if (P_SKILL(typ) <= P_BASIC) { + You("hook yourself!"); + losehp(Maybe_Half_Phys(rn1(10, 10)), "a grappling hook", + KILLED_BY); + return (1); + } + break; + } + pline1(nothing_happens); + return (1); } - -#define BY_OBJECT ((struct monst *)0) +#define BY_OBJECT ((struct monst *) 0) /* return 1 if the wand is broken, hence some time elapsed */ STATIC_OVL int do_break_wand(obj) - struct obj *obj; +struct obj *obj; { static const char nothing_else_happens[] = "But nothing else happens..."; register int i, x, y; @@ -2945,34 +3044,34 @@ do_break_wand(obj) boolean is_fragile = (!strcmp(OBJ_DESCR(objects[obj->otyp]), "balsa")); if (yn(safe_qbuf(confirm, "Are you really sure you want to break ", "?", - obj, yname, ysimple_name, "the wand")) == 'n') - return 0; + obj, yname, ysimple_name, "the wand")) == 'n') + return 0; if (nohands(youmonst.data)) { - You_cant("break %s without hands!", yname(obj)); - return 0; + You_cant("break %s without hands!", yname(obj)); + return 0; } else if (ACURR(A_STR) < (is_fragile ? 5 : 10)) { - You("don't have the strength to break %s!", yname(obj)); - return 0; + You("don't have the strength to break %s!", yname(obj)); + return 0; } - pline("Raising %s high above your %s, you break it in two!", - yname(obj), body_part(HEAD)); + pline("Raising %s high above your %s, you break it in two!", yname(obj), + body_part(HEAD)); /* [ALI] Do this first so that wand is removed from bill. Otherwise, * the freeinv() below also hides it from setpaid() which causes problems. */ if (obj->unpaid) { - check_unpaid(obj); /* Extra charge for use */ - costly_alteration(obj, COST_DSTROY); + check_unpaid(obj); /* Extra charge for use */ + costly_alteration(obj, COST_DSTROY); } - current_wand = obj; /* destroy_item might reset this */ - freeinv(obj); /* hide it from destroy_item instead... */ - setnotworn(obj); /* so we need to do this ourselves */ + current_wand = obj; /* destroy_item might reset this */ + freeinv(obj); /* hide it from destroy_item instead... */ + setnotworn(obj); /* so we need to do this ourselves */ if (!zappable(obj)) { - pline(nothing_else_happens); - goto discard_broken_wand; + pline(nothing_else_happens); + goto discard_broken_wand; } /* successful call to zappable() consumes a charge; put it back */ obj->spe++; @@ -2981,7 +3080,8 @@ do_break_wand(obj) below so give it 1..3 charges now, usually making it stronger than an ordinary last charge (the wand is already gone from inventory, so perm_invent can't accidentally reveal this) */ - if (!obj->spe) obj->spe = rnd(3); + if (!obj->spe) + obj->spe = rnd(3); obj->ox = u.ux; obj->oy = u.uy; @@ -2996,126 +3096,137 @@ do_break_wand(obj) case WAN_ENLIGHTENMENT: case WAN_OPENING: case WAN_SECRET_DOOR_DETECTION: - pline(nothing_else_happens); - goto discard_broken_wand; + pline(nothing_else_happens); + goto discard_broken_wand; case WAN_DEATH: case WAN_LIGHTNING: - dmg *= 4; - goto wanexpl; + dmg *= 4; + goto wanexpl; case WAN_FIRE: - expltype = EXPL_FIERY; + expltype = EXPL_FIERY; case WAN_COLD: - if (expltype == EXPL_MAGICAL) expltype = EXPL_FROSTY; - dmg *= 2; + if (expltype == EXPL_MAGICAL) + expltype = EXPL_FROSTY; + dmg *= 2; case WAN_MAGIC_MISSILE: wanexpl: - explode(u.ux, u.uy, -(obj->otyp), dmg, WAND_CLASS, expltype); - makeknown(obj->otyp); /* explode describes the effect */ - goto discard_broken_wand; + explode(u.ux, u.uy, -(obj->otyp), dmg, WAND_CLASS, expltype); + makeknown(obj->otyp); /* explode describes the effect */ + goto discard_broken_wand; case WAN_STRIKING: - /* we want this before the explosion instead of at the very end */ - pline("A wall of force smashes down around you!"); - dmg = d(1 + obj->spe,6); /* normally 2d12 */ - /*FALLTHRU*/ + /* we want this before the explosion instead of at the very end */ + pline("A wall of force smashes down around you!"); + dmg = d(1 + obj->spe, 6); /* normally 2d12 */ + /*FALLTHRU*/ case WAN_CANCELLATION: case WAN_POLYMORPH: case WAN_TELEPORTATION: case WAN_UNDEAD_TURNING: - affects_objects = TRUE; - break; + affects_objects = TRUE; + break; default: - break; + break; } - /* magical explosion and its visual effect occur before specific effects */ + /* magical explosion and its visual effect occur before specific effects + */ /* [TODO? This really ought to prevent the explosion from being fatal so that we never leave a bones file where none of the surrounding targets (or underlying objects) got affected yet.] */ - explode(obj->ox, obj->oy, -(obj->otyp), rnd(dmg), WAND_CLASS, EXPL_MAGICAL); + explode(obj->ox, obj->oy, -(obj->otyp), rnd(dmg), WAND_CLASS, + EXPL_MAGICAL); /* prepare for potential feedback from polymorph... */ zapsetup(); /* this makes it hit us last, so that we can see the action first */ for (i = 0; i <= 8; i++) { - bhitpos.x = x = obj->ox + xdir[i]; - bhitpos.y = y = obj->oy + ydir[i]; - if (!isok(x,y)) continue; + bhitpos.x = x = obj->ox + xdir[i]; + bhitpos.y = y = obj->oy + ydir[i]; + if (!isok(x, y)) + continue; - if (obj->otyp == WAN_DIGGING) { - schar typ; - if(dig_check(BY_OBJECT, FALSE, x, y)) { - if (IS_WALL(levl[x][y].typ) || IS_DOOR(levl[x][y].typ)) { - /* normally, pits and holes don't anger guards, but they - * do if it's a wall or door that's being dug */ - watch_dig((struct monst *)0, x, y, TRUE); - if (*in_rooms(x,y,SHOPBASE)) shop_damage = TRUE; - } - /* - * Let liquid flow into the newly created pits. - * Adjust corresponding code in music.c for - * drum of earthquake if you alter this sequence. - */ - typ = fillholetyp(x,y,FALSE); - if (typ != ROOM) { - levl[x][y].typ = typ; - liquid_flow(x, y, typ, t_at(x,y), - fillmsg ? (char *)0 : - "Some holes are quickly filled with %s!"); - fillmsg = TRUE; - } else - digactualhole(x, y, BY_OBJECT, - (rn2(obj->spe) < 3 || - (!Can_dig_down(&u.uz) && !levl[x][y].candig)) ? - PIT : HOLE); - } - continue; - } else if(obj->otyp == WAN_CREATE_MONSTER) { - /* u.ux,u.uy creates it near you--x,y might create it in rock */ - (void) makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS); - continue; - } else if (x != u.ux || y != u.uy) { - /* - * Wand breakage is targetting a square adjacent to the hero, - * which might contain a monster or a pile of objects or both. - * Handle objects last; avoids having undead turning raise an - * undead's corpse and then attack resulting undead monster. - * obj->bypass in bhitm() prevents the polymorphing of items - * dropped due to monster's polymorph and prevents undead - * turning that kills an undead from raising resulting corpse. - */ - if ((mon = m_at(x, y)) != 0) { - (void) bhitm(mon, obj); - /* if (context.botl) bot(); */ - } - if (affects_objects && level.objects[x][y]) { - (void) bhitpile(obj, bhito, x, y, 0); - if (context.botl) bot(); /* potion effects */ - } - } else { - /* - * Wand breakage is targetting the hero. Using xdir[]+ydir[] - * deltas for location selection causes this case to happen - * after all the surrounding squares have been handled. - * Process objects first, in case damage is fatal and leaves - * bones, or teleportation sends one or more of the objects to - * same destination as hero (lookhere/autopickup); also avoids - * the polymorphing of gear dropped due to hero's transformation. - * (Unlike with monsters being hit by zaps, we can't rely on use - * of obj->bypass in the zap code to accomplish that last case - * since it's also used by retouch_equipment() for polyself.) - */ - if (affects_objects && level.objects[x][y]) { - (void) bhitpile(obj, bhito, x, y, 0); - if (context.botl) bot(); /* potion effects */ - } - damage = zapyourself(obj, FALSE); - if (damage) { - Sprintf(buf, "killed %sself by breaking a wand", uhim()); - losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); - } - if (context.botl) bot(); /* blindness */ - } + if (obj->otyp == WAN_DIGGING) { + schar typ; + if (dig_check(BY_OBJECT, FALSE, x, y)) { + if (IS_WALL(levl[x][y].typ) || IS_DOOR(levl[x][y].typ)) { + /* normally, pits and holes don't anger guards, but they + * do if it's a wall or door that's being dug */ + watch_dig((struct monst *) 0, x, y, TRUE); + if (*in_rooms(x, y, SHOPBASE)) + shop_damage = TRUE; + } + /* + * Let liquid flow into the newly created pits. + * Adjust corresponding code in music.c for + * drum of earthquake if you alter this sequence. + */ + typ = fillholetyp(x, y, FALSE); + if (typ != ROOM) { + levl[x][y].typ = typ; + liquid_flow( + x, y, typ, t_at(x, y), + fillmsg ? (char *) 0 + : "Some holes are quickly filled with %s!"); + fillmsg = TRUE; + } else + digactualhole( + x, y, BY_OBJECT, + (rn2(obj->spe) < 3 + || (!Can_dig_down(&u.uz) && !levl[x][y].candig)) + ? PIT + : HOLE); + } + continue; + } else if (obj->otyp == WAN_CREATE_MONSTER) { + /* u.ux,u.uy creates it near you--x,y might create it in rock */ + (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); + continue; + } else if (x != u.ux || y != u.uy) { + /* + * Wand breakage is targetting a square adjacent to the hero, + * which might contain a monster or a pile of objects or both. + * Handle objects last; avoids having undead turning raise an + * undead's corpse and then attack resulting undead monster. + * obj->bypass in bhitm() prevents the polymorphing of items + * dropped due to monster's polymorph and prevents undead + * turning that kills an undead from raising resulting corpse. + */ + if ((mon = m_at(x, y)) != 0) { + (void) bhitm(mon, obj); + /* if (context.botl) bot(); */ + } + if (affects_objects && level.objects[x][y]) { + (void) bhitpile(obj, bhito, x, y, 0); + if (context.botl) + bot(); /* potion effects */ + } + } else { + /* + * Wand breakage is targetting the hero. Using xdir[]+ydir[] + * deltas for location selection causes this case to happen + * after all the surrounding squares have been handled. + * Process objects first, in case damage is fatal and leaves + * bones, or teleportation sends one or more of the objects to + * same destination as hero (lookhere/autopickup); also avoids + * the polymorphing of gear dropped due to hero's transformation. + * (Unlike with monsters being hit by zaps, we can't rely on use + * of obj->bypass in the zap code to accomplish that last case + * since it's also used by retouch_equipment() for polyself.) + */ + if (affects_objects && level.objects[x][y]) { + (void) bhitpile(obj, bhito, x, y, 0); + if (context.botl) + bot(); /* potion effects */ + } + damage = zapyourself(obj, FALSE); + if (damage) { + Sprintf(buf, "killed %sself by breaking a wand", uhim()); + losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); + } + if (context.botl) + bot(); /* blindness */ + } } /* potentially give post zap/break feedback */ @@ -3123,16 +3234,17 @@ do_break_wand(obj) /* Note: if player fell thru, this call is a no-op. Damage is handled in digactualhole in that case */ - if (shop_damage) pay_for_damage("dig into", FALSE); + if (shop_damage) + pay_for_damage("dig into", FALSE); if (obj->otyp == WAN_LIGHT) - litroom(TRUE, obj); /* only needs to be done once */ + litroom(TRUE, obj); /* only needs to be done once */ - discard_broken_wand: - obj = current_wand; /* [see dozap() and destroy_item()] */ +discard_broken_wand: + obj = current_wand; /* [see dozap() and destroy_item()] */ current_wand = 0; if (obj) - delobj(obj); + delobj(obj); nomul(0); return 1; } @@ -3142,11 +3254,11 @@ add_class(cl, class) char *cl; char class; { - char tmp[2]; + char tmp[2]; - tmp[0] = class; - tmp[1] = '\0'; - Strcat(cl, tmp); + tmp[0] = class; + tmp[1] = '\0'; + Strcat(cl, tmp); } static const char tools[] = { TOOL_CLASS, WEAPON_CLASS, WAND_CLASS, 0 }; @@ -3156,232 +3268,242 @@ STATIC_OVL void setapplyclasses(class_list) char class_list[]; { - register struct obj *otmp; - int otyp; - boolean knowoil, knowtouchstone, addpotions, addstones, addfood; + register struct obj *otmp; + int otyp; + boolean knowoil, knowtouchstone, addpotions, addstones, addfood; - knowoil = objects[POT_OIL].oc_name_known; - knowtouchstone = objects[TOUCHSTONE].oc_name_known; - addpotions = addstones = addfood = FALSE; - for (otmp = invent; otmp; otmp = otmp->nobj) { - otyp = otmp->otyp; - if (otyp == POT_OIL || - (otmp->oclass == POTION_CLASS && - (!otmp->dknown || - (!knowoil && !objects[otyp].oc_name_known)))) - addpotions = TRUE; - if (otyp == TOUCHSTONE || - (is_graystone(otmp) && - (!otmp->dknown || - (!knowtouchstone && !objects[otyp].oc_name_known)))) - addstones = TRUE; - if (otyp == CREAM_PIE || otyp == EUCALYPTUS_LEAF) - addfood = TRUE; - } + knowoil = objects[POT_OIL].oc_name_known; + knowtouchstone = objects[TOUCHSTONE].oc_name_known; + addpotions = addstones = addfood = FALSE; + for (otmp = invent; otmp; otmp = otmp->nobj) { + otyp = otmp->otyp; + if (otyp == POT_OIL + || (otmp->oclass == POTION_CLASS + && (!otmp->dknown + || (!knowoil && !objects[otyp].oc_name_known)))) + addpotions = TRUE; + if (otyp == TOUCHSTONE + || (is_graystone(otmp) + && (!otmp->dknown + || (!knowtouchstone && !objects[otyp].oc_name_known)))) + addstones = TRUE; + if (otyp == CREAM_PIE || otyp == EUCALYPTUS_LEAF) + addfood = TRUE; + } - class_list[0] = '\0'; - if (addpotions || addstones) add_class(class_list, ALL_CLASSES); - Strcat(class_list, tools); - if (addpotions) add_class(class_list, POTION_CLASS); - if (addstones) add_class(class_list, GEM_CLASS); - if (addfood) add_class(class_list, FOOD_CLASS); + class_list[0] = '\0'; + if (addpotions || addstones) + add_class(class_list, ALL_CLASSES); + Strcat(class_list, tools); + if (addpotions) + add_class(class_list, POTION_CLASS); + if (addstones) + add_class(class_list, GEM_CLASS); + if (addfood) + add_class(class_list, FOOD_CLASS); } int doapply() { - struct obj *obj; - register int res = 1; - char class_list[MAXOCLASSES+2]; + struct obj *obj; + register int res = 1; + char class_list[MAXOCLASSES + 2]; - if(check_capacity((char *)0)) return (0); + if (check_capacity((char *) 0)) + return (0); - setapplyclasses(class_list); /* tools[] */ - obj = getobj(class_list, "use or apply"); - if(!obj) return 0; + setapplyclasses(class_list); /* tools[] */ + obj = getobj(class_list, "use or apply"); + if (!obj) + return 0; - if (!retouch_object(&obj, FALSE)) - return 1; /* evading your grasp costs a turn; just be - grateful that you don't drop it as well */ + if (!retouch_object(&obj, FALSE)) + return 1; /* evading your grasp costs a turn; just be + grateful that you don't drop it as well */ - if (obj->oclass == WAND_CLASS) - return do_break_wand(obj); + if (obj->oclass == WAND_CLASS) + return do_break_wand(obj); - switch(obj->otyp){ - case BLINDFOLD: - case LENSES: - if (obj == ublindf) { - if (!cursed(obj)) Blindf_off(obj); - } else if (!ublindf) - Blindf_on(obj); - else You("are already %s.", - ublindf->otyp == TOWEL ? "covered by a towel" : - ublindf->otyp == BLINDFOLD ? "wearing a blindfold" : - "wearing lenses"); - break; - case CREAM_PIE: - res = use_cream_pie(obj); - break; - case BULLWHIP: - res = use_whip(obj); - break; - case GRAPPLING_HOOK: - res = use_grapple(obj); - break; - case LARGE_BOX: - case CHEST: - case ICE_BOX: - case SACK: - case BAG_OF_HOLDING: - case OILSKIN_SACK: - res = use_container(&obj, 1); - break; - case BAG_OF_TRICKS: - (void) bagotricks(obj, FALSE, (int *)0); - break; - case CAN_OF_GREASE: - use_grease(obj); - break; - case LOCK_PICK: - case CREDIT_CARD: - case SKELETON_KEY: - res = (pick_lock(obj) != 0); - break; - case PICK_AXE: - case DWARVISH_MATTOCK: - res = use_pick_axe(obj); - break; - case TINNING_KIT: - use_tinning_kit(obj); - break; - case LEASH: - use_leash(obj); - break; - case SADDLE: - res = use_saddle(obj); - break; - case MAGIC_WHISTLE: - use_magic_whistle(obj); - break; - case TIN_WHISTLE: - use_whistle(obj); - break; - case EUCALYPTUS_LEAF: - /* MRKR: Every Australian knows that a gum leaf makes an */ - /* excellent whistle, especially if your pet is a */ - /* tame kangaroo named Skippy. */ - if (obj->blessed) { - use_magic_whistle(obj); - /* sometimes the blessing will be worn off */ - if (!rn2(49)) { - if (!Blind) { - pline("%s %s.", - Yobjnam2(obj, "glow"), hcolor("brown")); - obj->bknown = 1; - } - unbless(obj); - } - } else { - use_whistle(obj); - } - break; - case STETHOSCOPE: - res = use_stethoscope(obj); - break; - case MIRROR: - res = use_mirror(obj); - break; - case BELL: - case BELL_OF_OPENING: - use_bell(&obj); - break; - case CANDELABRUM_OF_INVOCATION: - use_candelabrum(obj); - break; - case WAX_CANDLE: - case TALLOW_CANDLE: - use_candle(&obj); - break; - case OIL_LAMP: - case MAGIC_LAMP: - case BRASS_LANTERN: - use_lamp(obj); - break; - case POT_OIL: - light_cocktail(obj); - break; - case EXPENSIVE_CAMERA: - res = use_camera(obj); - break; - case TOWEL: - res = use_towel(obj); - break; - case CRYSTAL_BALL: - use_crystal_ball(obj); - break; - case MAGIC_MARKER: - res = dowrite(obj); - break; - case TIN_OPENER: - if(!carrying(TIN)) { - You("have no tin to open."); - goto xit; - } - You("cannot open a tin without eating or discarding its contents."); - if(flags.verbose) - pline("In order to eat, use the 'e' command."); - if(obj != uwep) - pline("Opening the tin will be much easier if you wield the tin opener."); - goto xit; + switch (obj->otyp) { + case BLINDFOLD: + case LENSES: + if (obj == ublindf) { + if (!cursed(obj)) + Blindf_off(obj); + } else if (!ublindf) + Blindf_on(obj); + else + You("are already %s.", ublindf->otyp == TOWEL + ? "covered by a towel" + : ublindf->otyp == BLINDFOLD + ? "wearing a blindfold" + : "wearing lenses"); + break; + case CREAM_PIE: + res = use_cream_pie(obj); + break; + case BULLWHIP: + res = use_whip(obj); + break; + case GRAPPLING_HOOK: + res = use_grapple(obj); + break; + case LARGE_BOX: + case CHEST: + case ICE_BOX: + case SACK: + case BAG_OF_HOLDING: + case OILSKIN_SACK: + res = use_container(&obj, 1); + break; + case BAG_OF_TRICKS: + (void) bagotricks(obj, FALSE, (int *) 0); + break; + case CAN_OF_GREASE: + use_grease(obj); + break; + case LOCK_PICK: + case CREDIT_CARD: + case SKELETON_KEY: + res = (pick_lock(obj) != 0); + break; + case PICK_AXE: + case DWARVISH_MATTOCK: + res = use_pick_axe(obj); + break; + case TINNING_KIT: + use_tinning_kit(obj); + break; + case LEASH: + use_leash(obj); + break; + case SADDLE: + res = use_saddle(obj); + break; + case MAGIC_WHISTLE: + use_magic_whistle(obj); + break; + case TIN_WHISTLE: + use_whistle(obj); + break; + case EUCALYPTUS_LEAF: + /* MRKR: Every Australian knows that a gum leaf makes an */ + /* excellent whistle, especially if your pet is a */ + /* tame kangaroo named Skippy. */ + if (obj->blessed) { + use_magic_whistle(obj); + /* sometimes the blessing will be worn off */ + if (!rn2(49)) { + if (!Blind) { + pline("%s %s.", Yobjnam2(obj, "glow"), hcolor("brown")); + obj->bknown = 1; + } + unbless(obj); + } + } else { + use_whistle(obj); + } + break; + case STETHOSCOPE: + res = use_stethoscope(obj); + break; + case MIRROR: + res = use_mirror(obj); + break; + case BELL: + case BELL_OF_OPENING: + use_bell(&obj); + break; + case CANDELABRUM_OF_INVOCATION: + use_candelabrum(obj); + break; + case WAX_CANDLE: + case TALLOW_CANDLE: + use_candle(&obj); + break; + case OIL_LAMP: + case MAGIC_LAMP: + case BRASS_LANTERN: + use_lamp(obj); + break; + case POT_OIL: + light_cocktail(obj); + break; + case EXPENSIVE_CAMERA: + res = use_camera(obj); + break; + case TOWEL: + res = use_towel(obj); + break; + case CRYSTAL_BALL: + use_crystal_ball(obj); + break; + case MAGIC_MARKER: + res = dowrite(obj); + break; + case TIN_OPENER: + if (!carrying(TIN)) { + You("have no tin to open."); + goto xit; + } + You("cannot open a tin without eating or discarding its contents."); + if (flags.verbose) + pline("In order to eat, use the 'e' command."); + if (obj != uwep) + pline("Opening the tin will be much easier if you wield the tin " + "opener."); + goto xit; - case FIGURINE: - use_figurine(&obj); - break; - case UNICORN_HORN: - use_unicorn_horn(obj); - break; - case WOODEN_FLUTE: - case MAGIC_FLUTE: - case TOOLED_HORN: - case FROST_HORN: - case FIRE_HORN: - case WOODEN_HARP: - case MAGIC_HARP: - case BUGLE: - case LEATHER_DRUM: - case DRUM_OF_EARTHQUAKE: - res = do_play_instrument(obj); - break; - case HORN_OF_PLENTY: /* not a musical instrument */ - (void) hornoplenty(obj, FALSE); - break; - case LAND_MINE: - case BEARTRAP: - use_trap(obj); - break; - case FLINT: - case LUCKSTONE: - case LOADSTONE: - case TOUCHSTONE: - use_stone(obj); - break; - default: - /* Pole-weapons can strike at a distance */ - if (is_pole(obj)) { - res = use_pole(obj); - break; - } else if (is_pick(obj) || is_axe(obj)) { - res = use_pick_axe(obj); - break; - } - pline("Sorry, I don't know how to use that."); - xit: - nomul(0); - return 0; - } - if (res && obj && obj->oartifact) arti_speak(obj); - nomul(0); - return res; + case FIGURINE: + use_figurine(&obj); + break; + case UNICORN_HORN: + use_unicorn_horn(obj); + break; + case WOODEN_FLUTE: + case MAGIC_FLUTE: + case TOOLED_HORN: + case FROST_HORN: + case FIRE_HORN: + case WOODEN_HARP: + case MAGIC_HARP: + case BUGLE: + case LEATHER_DRUM: + case DRUM_OF_EARTHQUAKE: + res = do_play_instrument(obj); + break; + case HORN_OF_PLENTY: /* not a musical instrument */ + (void) hornoplenty(obj, FALSE); + break; + case LAND_MINE: + case BEARTRAP: + use_trap(obj); + break; + case FLINT: + case LUCKSTONE: + case LOADSTONE: + case TOUCHSTONE: + use_stone(obj); + break; + default: + /* Pole-weapons can strike at a distance */ + if (is_pole(obj)) { + res = use_pole(obj); + break; + } else if (is_pick(obj) || is_axe(obj)) { + res = use_pick_axe(obj); + break; + } + pline("Sorry, I don't know how to use that."); + xit: + nomul(0); + return 0; + } + if (res && obj && obj->oartifact) + arti_speak(obj); + nomul(0); + return res; } /* Keep track of unfixable troubles for purposes of messages saying you feel @@ -3389,24 +3511,33 @@ doapply() */ int unfixable_trouble_count(is_horn) - boolean is_horn; +boolean is_horn; { - int unfixable_trbl = 0; + int unfixable_trbl = 0; - if (Stoned) unfixable_trbl++; - if (Strangled) unfixable_trbl++; - if (Wounded_legs && !u.usteed) unfixable_trbl++; - if (Slimed) unfixable_trbl++; - /* lycanthropy is not desirable, but it doesn't actually make you feel - bad */ + if (Stoned) + unfixable_trbl++; + if (Strangled) + unfixable_trbl++; + if (Wounded_legs && !u.usteed) + unfixable_trbl++; + if (Slimed) + unfixable_trbl++; + /* lycanthropy is not desirable, but it doesn't actually make you feel + bad */ - if (!is_horn || (Confusion & ~TIMEOUT)) unfixable_trbl++; - if (!is_horn || (Sick & ~TIMEOUT)) unfixable_trbl++; - if (!is_horn || (HHallucination & ~TIMEOUT)) unfixable_trbl++; - if (!is_horn || (Vomiting & ~TIMEOUT)) unfixable_trbl++; - if (!is_horn || (HStun & ~TIMEOUT)) unfixable_trbl++; + if (!is_horn || (Confusion & ~TIMEOUT)) + unfixable_trbl++; + if (!is_horn || (Sick & ~TIMEOUT)) + unfixable_trbl++; + if (!is_horn || (HHallucination & ~TIMEOUT)) + unfixable_trbl++; + if (!is_horn || (Vomiting & ~TIMEOUT)) + unfixable_trbl++; + if (!is_horn || (HStun & ~TIMEOUT)) + unfixable_trbl++; - return unfixable_trbl; + return unfixable_trbl; } /*apply.c*/ diff --git a/src/artifact.c b/src/artifact.c index 9a3ee0d77..8b0d82bbe 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 artifact.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 artifact.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.85 $ */ /* NetHack 3.6 artifact.c $Date: 2013/11/07 01:03:16 $ $Revision: 1.77 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,20 +14,21 @@ * the contents, just the total size. */ -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ #define get_artifact(o) \ - (((o)&&(o)->oartifact) ? &artilist[(int) (o)->oartifact] : 0) + (((o) && (o)->oartifact) ? &artilist[(int) (o)->oartifact] : 0) -STATIC_DCL boolean FDECL(bane_applies, (const struct artifact *,struct monst *)); -STATIC_DCL int FDECL(spec_applies, (const struct artifact *,struct monst *)); -STATIC_DCL int FDECL(arti_invoke, (struct obj*)); -STATIC_DCL boolean FDECL(Mb_hit, (struct monst *magr,struct monst *mdef, - struct obj *,int *,int,BOOLEAN_P,char *)); +STATIC_DCL boolean +FDECL(bane_applies, (const struct artifact *, struct monst *)); +STATIC_DCL int FDECL(spec_applies, (const struct artifact *, struct monst *)); +STATIC_DCL int FDECL(arti_invoke, (struct obj *)); +STATIC_DCL boolean +FDECL(Mb_hit, (struct monst * magr, struct monst *mdef, struct obj *, int *, + int, BOOLEAN_P, char *)); STATIC_DCL unsigned long FDECL(abil_to_spfx, (long *)); -STATIC_DCL uchar FDECL(abil_to_adtyp,(long *)); -STATIC_DCL boolean FDECL(untouchable, (struct obj *,BOOLEAN_P)); - +STATIC_DCL uchar FDECL(abil_to_adtyp, (long *)); +STATIC_DCL boolean FDECL(untouchable, (struct obj *, BOOLEAN_P)); /* The amount added to the victim's total hit points to insure that the victim will be killed even after damage bonus/penalty adjustments. @@ -43,69 +44,70 @@ STATIC_DCL boolean FDECL(untouchable, (struct obj *,BOOLEAN_P)); STATIC_OVL int spec_dbon_applies = 0; /* flags including which artifacts have already been created */ -static boolean artiexist[1+NROFARTIFACTS+1]; +static boolean artiexist[1 + NROFARTIFACTS + 1]; /* and a discovery list for them (no dummy first entry here) */ STATIC_OVL xchar artidisco[NROFARTIFACTS]; STATIC_DCL void NDECL(hack_artifacts); -STATIC_DCL boolean FDECL(attacks, (int,struct obj *)); +STATIC_DCL boolean FDECL(attacks, (int, struct obj *)); /* handle some special cases; must be called after u_init() */ STATIC_OVL void hack_artifacts() { - struct artifact *art; - int alignmnt = aligns[flags.initalign].value; + struct artifact *art; + int alignmnt = aligns[flags.initalign].value; - /* Fix up the alignments of "gift" artifacts */ - for (art = artilist+1; art->otyp; art++) - if (art->role == Role_switch && art->alignment != A_NONE) - art->alignment = alignmnt; + /* Fix up the alignments of "gift" artifacts */ + for (art = artilist + 1; art->otyp; art++) + if (art->role == Role_switch && art->alignment != A_NONE) + art->alignment = alignmnt; - /* Excalibur can be used by any lawful character, not just knights */ - if (!Role_if(PM_KNIGHT)) - artilist[ART_EXCALIBUR].role = NON_PM; + /* Excalibur can be used by any lawful character, not just knights */ + if (!Role_if(PM_KNIGHT)) + artilist[ART_EXCALIBUR].role = NON_PM; - /* Fix up the quest artifact */ - if (urole.questarti) { - artilist[urole.questarti].alignment = alignmnt; - artilist[urole.questarti].role = Role_switch; - } - return; + /* Fix up the quest artifact */ + if (urole.questarti) { + artilist[urole.questarti].alignment = alignmnt; + artilist[urole.questarti].role = Role_switch; + } + return; } /* zero out the artifact existence list */ void init_artifacts() { - (void) memset((genericptr_t) artiexist, 0, sizeof artiexist); - (void) memset((genericptr_t) artidisco, 0, sizeof artidisco); - hack_artifacts(); + (void) memset((genericptr_t) artiexist, 0, sizeof artiexist); + (void) memset((genericptr_t) artidisco, 0, sizeof artidisco); + hack_artifacts(); } void save_artifacts(fd) int fd; { - bwrite(fd, (genericptr_t) artiexist, sizeof artiexist); - bwrite(fd, (genericptr_t) artidisco, sizeof artidisco); + bwrite(fd, (genericptr_t) artiexist, sizeof artiexist); + bwrite(fd, (genericptr_t) artidisco, sizeof artidisco); } void restore_artifacts(fd) int fd; { - mread(fd, (genericptr_t) artiexist, sizeof artiexist); - mread(fd, (genericptr_t) artidisco, sizeof artidisco); - hack_artifacts(); /* redo non-saved special cases */ + mread(fd, (genericptr_t) artiexist, sizeof artiexist); + mread(fd, (genericptr_t) artidisco, sizeof artidisco); + hack_artifacts(); /* redo non-saved special cases */ } const char * artiname(artinum) int artinum; { - if (artinum <= 0 || artinum > NROFARTIFACTS) return(""); - return(artilist[artinum].name); + if (artinum <= 0 || artinum > NROFARTIFACTS) + return (""); + return (artilist[artinum].name); } /* @@ -114,87 +116,95 @@ int artinum; none is available. (If at least one aligned artifact has already been given, then unaligned ones also become eligible for this.) If no alignment is given, then 'otmp' is converted - into an artifact of matching type, or returned as-is if that's not possible. + into an artifact of matching type, or returned as-is if that's not + possible. For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE);'' for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);''. */ struct obj * mk_artifact(otmp, alignment) -struct obj *otmp; /* existing object; ignored if alignment specified */ -aligntyp alignment; /* target alignment, or A_NONE */ +struct obj *otmp; /* existing object; ignored if alignment specified */ +aligntyp alignment; /* target alignment, or A_NONE */ { - const struct artifact *a; - int m, n, altn; - boolean by_align = (alignment != A_NONE); - short o_typ = (by_align || !otmp) ? 0 : otmp->otyp; - boolean unique = !by_align && otmp && objects[o_typ].oc_unique; - short eligible[NROFARTIFACTS]; + const struct artifact *a; + int m, n, altn; + boolean by_align = (alignment != A_NONE); + short o_typ = (by_align || !otmp) ? 0 : otmp->otyp; + boolean unique = !by_align && otmp && objects[o_typ].oc_unique; + short eligible[NROFARTIFACTS]; - n = altn = 0; /* no candidates found yet */ - eligible[0] = 0; /* lint suppression */ - /* gather eligible artifacts */ - for (m = 1, a = &artilist[m]; a->otyp; a++, m++) { - if (artiexist[m]) continue; - if ((a->spfx & SPFX_NOGEN) || unique) continue; + n = altn = 0; /* no candidates found yet */ + eligible[0] = 0; /* lint suppression */ + /* gather eligible artifacts */ + for (m = 1, a = &artilist[m]; a->otyp; a++, m++) { + if (artiexist[m]) + continue; + if ((a->spfx & SPFX_NOGEN) || unique) + continue; - if (!by_align) { - /* looking for a particular type of item; not producing a - divine gift so we don't care about role's first choice */ - if (a->otyp == o_typ) eligible[n++] = m; - continue; /* move on to next possibility */ - } + if (!by_align) { + /* looking for a particular type of item; not producing a + divine gift so we don't care about role's first choice */ + if (a->otyp == o_typ) + eligible[n++] = m; + continue; /* move on to next possibility */ + } - /* we're looking for an alignment-specific item - suitable for hero's role+race */ - if ((a->alignment == alignment || a->alignment == A_NONE) && - /* avoid enemies' equipment */ - (a->race == NON_PM || !race_hostile(&mons[a->race]))) { - /* when a role-specific first choice is available, use it */ - if (Role_if(a->role)) { - /* make this be the only possibility in the list */ - eligible[0] = m; - n = 1; - break; /* skip all other candidates */ - } - /* found something to consider for random selection */ - if (a->alignment != A_NONE || u.ugifts > 0) { - /* right alignment, or non-aligned with at least 1 - previous gift bestowed, makes this one viable */ - eligible[n++] = m; - } else { - /* non-aligned with no previous gifts; - if no candidates have been found yet, record - this one as a[nother] fallback possibility in - case all aligned candidates have been used up - (via wishing, naming, bones, random generation) */ - if (!n) eligible[altn++] = m; - /* [once a regular candidate is found, the list - is overwritten and `altn' becomes irrelevant] */ - } - } - } + /* we're looking for an alignment-specific item + suitable for hero's role+race */ + if ((a->alignment == alignment || a->alignment == A_NONE) && + /* avoid enemies' equipment */ + (a->race == NON_PM || !race_hostile(&mons[a->race]))) { + /* when a role-specific first choice is available, use it */ + if (Role_if(a->role)) { + /* make this be the only possibility in the list */ + eligible[0] = m; + n = 1; + break; /* skip all other candidates */ + } + /* found something to consider for random selection */ + if (a->alignment != A_NONE || u.ugifts > 0) { + /* right alignment, or non-aligned with at least 1 + previous gift bestowed, makes this one viable */ + eligible[n++] = m; + } else { + /* non-aligned with no previous gifts; + if no candidates have been found yet, record + this one as a[nother] fallback possibility in + case all aligned candidates have been used up + (via wishing, naming, bones, random generation) */ + if (!n) + eligible[altn++] = m; + /* [once a regular candidate is found, the list + is overwritten and `altn' becomes irrelevant] */ + } + } + } - /* resort to fallback list if main list was empty */ - if (!n) n = altn; + /* resort to fallback list if main list was empty */ + if (!n) + n = altn; - if (n) { - /* found at least one candidate; pick one at random */ - m = eligible[rn2(n)]; /* [0..n-1] */ - a = &artilist[m]; + if (n) { + /* found at least one candidate; pick one at random */ + m = eligible[rn2(n)]; /* [0..n-1] */ + a = &artilist[m]; - /* make an appropriate object if necessary, then christen it */ - if (by_align) otmp = mksobj((int)a->otyp, TRUE, FALSE); + /* make an appropriate object if necessary, then christen it */ + if (by_align) + otmp = mksobj((int) a->otyp, TRUE, FALSE); - if (otmp) { - otmp = oname(otmp, a->name); - otmp->oartifact = m; - artiexist[m] = TRUE; - } - } else { - /* nothing appropriate could be found; return original object */ - if (by_align) otmp = 0; /* (there was no original object) */ - } - return otmp; + if (otmp) { + otmp = oname(otmp, a->name); + otmp->oartifact = m; + artiexist[m] = TRUE; + } + } else { + /* nothing appropriate could be found; return original object */ + if (by_align) + otmp = 0; /* (there was no original object) */ + } + return otmp; } /* @@ -204,7 +214,7 @@ aligntyp alignment; /* target alignment, or A_NONE */ * The object type of the artifact is returned in otyp if the return value * is non-NULL. */ -const char* +const char * artifact_name(name, otyp) const char *name; short *otyp; @@ -212,18 +222,20 @@ short *otyp; register const struct artifact *a; register const char *aname; - if(!strncmpi(name, "the ", 4)) name += 4; + if (!strncmpi(name, "the ", 4)) + name += 4; - for (a = artilist+1; a->otyp; a++) { - aname = a->name; - if(!strncmpi(aname, "the ", 4)) aname += 4; - if(!strcmpi(name, aname)) { - *otyp = a->otyp; - return a->name; - } + for (a = artilist + 1; a->otyp; a++) { + aname = a->name; + if (!strncmpi(aname, "the ", 4)) + aname += 4; + if (!strcmpi(name, aname)) { + *otyp = a->otyp; + return a->name; + } } - return (char *)0; + return (char *) 0; } boolean @@ -231,14 +243,14 @@ exist_artifact(otyp, name) register int otyp; register const char *name; { - register const struct artifact *a; - register boolean *arex; + register const struct artifact *a; + register boolean *arex; - if (otyp && *name) - for (a = artilist+1,arex = artiexist+1; a->otyp; a++,arex++) - if ((int) a->otyp == otyp && !strcmp(a->name, name)) - return *arex; - return FALSE; + if (otyp && *name) + for (a = artilist + 1, arex = artiexist + 1; a->otyp; a++, arex++) + if ((int) a->otyp == otyp && !strcmp(a->name, name)) + return *arex; + return FALSE; } void @@ -247,20 +259,20 @@ register struct obj *otmp; register const char *name; register boolean mod; { - register const struct artifact *a; + register const struct artifact *a; - if (otmp && *name) - for (a = artilist+1; a->otyp; a++) - if (a->otyp == otmp->otyp && !strcmp(a->name, name)) { - register int m = (int)(a - artilist); - otmp->oartifact = (char)(mod ? m : 0); - otmp->age = 0; - if(otmp->otyp == RIN_INCREASE_DAMAGE) - otmp->spe = 0; - artiexist[m] = mod; - break; - } - return; + if (otmp && *name) + for (a = artilist + 1; a->otyp; a++) + if (a->otyp == otmp->otyp && !strcmp(a->name, name)) { + register int m = (int) (a - artilist); + otmp->oartifact = (char) (mod ? m : 0); + otmp->age = 0; + if (otmp->otyp == RIN_INCREASE_DAMAGE) + otmp->spe = 0; + artiexist[m] = mod; + break; + } + return; } int @@ -269,8 +281,9 @@ nartifact_exist() int a = 0; int n = SIZE(artiexist); - while(n > 1) - if(artiexist[--n]) a++; + while (n > 1) + if (artiexist[--n]) + a++; return a; } @@ -280,9 +293,9 @@ spec_ability(otmp, abil) struct obj *otmp; unsigned long abil; { - const struct artifact *arti = get_artifact(otmp); + const struct artifact *arti = get_artifact(otmp); - return((boolean)(arti && (arti->spfx & abil))); + return ((boolean)(arti && (arti->spfx & abil))); } /* used so that callers don't need to known about SPFX_ codes */ @@ -291,7 +304,8 @@ confers_luck(obj) struct obj *obj; { /* might as well check for this too */ - if (obj->otyp == LUCKSTONE) return TRUE; + if (obj->otyp == LUCKSTONE) + return TRUE; return (obj->oartifact && spec_ability(obj, SPFX_LUCK)); } @@ -303,12 +317,13 @@ struct obj *obj; { const struct artifact *arti = get_artifact(obj); - if (arti) { - /* while being worn */ - if ((obj->owornmask & ~W_ART) && (arti->spfx & SPFX_REFLECT)) - return TRUE; - /* just being carried */ - if (arti->cspfx & SPFX_REFLECT) return TRUE; + if (arti) { + /* while being worn */ + if ((obj->owornmask & ~W_ART) && (arti->spfx & SPFX_REFLECT)) + return TRUE; + /* just being carried */ + if (arti->cspfx & SPFX_REFLECT) + return TRUE; } return FALSE; } @@ -322,11 +337,12 @@ struct obj *obj; const struct artifact *arti; /* any silver object is effective */ - if (objects[obj->otyp].oc_material == SILVER) return TRUE; + if (objects[obj->otyp].oc_material == SILVER) + return TRUE; /* non-silver artifacts with bonus against undead also are effective */ arti = get_artifact(obj); if (arti && (arti->spfx & SPFX_DFLAG2) && arti->mtype == M2_UNDEAD) - return TRUE; + return TRUE; /* [if there was anything with special bonus against noncorporeals, it would be effective too] */ /* otherwise, harmless to shades */ @@ -334,51 +350,56 @@ struct obj *obj; } boolean -restrict_name(otmp, name) /* returns 1 if name is restricted for otmp->otyp */ +restrict_name(otmp, name) /* returns 1 if name is restricted for otmp->otyp */ register struct obj *otmp; register const char *name; { - register const struct artifact *a; - const char *aname, *odesc, *other; - boolean sametype[NUM_OBJECTS]; - int i, lo, hi, otyp = otmp->otyp, ocls = objects[otyp].oc_class; + register const struct artifact *a; + const char *aname, *odesc, *other; + boolean sametype[NUM_OBJECTS]; + int i, lo, hi, otyp = otmp->otyp, ocls = objects[otyp].oc_class; - if (!*name) return FALSE; - if (!strncmpi(name, "the ", 4)) name += 4; + if (!*name) + return FALSE; + if (!strncmpi(name, "the ", 4)) + name += 4; - /* decide what types of objects are the same as otyp; - if it's been discovered, then only itself matches; - otherwise, include all other undiscovered objects - of the same class which have the same description - or share the same pool of shuffled descriptions */ - (void) memset((genericptr_t)sametype, 0, sizeof sametype); /* FALSE */ - sametype[otyp] = TRUE; - if (!objects[otyp].oc_name_known && - (odesc = OBJ_DESCR(objects[otyp])) != 0) { - obj_shuffle_range(otyp, &lo, &hi); - for (i = bases[ocls]; i < NUM_OBJECTS; i++) { - if (objects[i].oc_class != ocls) break; - if (!objects[i].oc_name_known && - (other = OBJ_DESCR(objects[i])) != 0 && - (!strcmp(odesc, other) || (i >= lo && i <= hi))) - sametype[i] = TRUE; - } - } + /* decide what types of objects are the same as otyp; + if it's been discovered, then only itself matches; + otherwise, include all other undiscovered objects + of the same class which have the same description + or share the same pool of shuffled descriptions */ + (void) memset((genericptr_t) sametype, 0, sizeof sametype); /* FALSE */ + sametype[otyp] = TRUE; + if (!objects[otyp].oc_name_known + && (odesc = OBJ_DESCR(objects[otyp])) != 0) { + obj_shuffle_range(otyp, &lo, &hi); + for (i = bases[ocls]; i < NUM_OBJECTS; i++) { + if (objects[i].oc_class != ocls) + break; + if (!objects[i].oc_name_known + && (other = OBJ_DESCR(objects[i])) != 0 + && (!strcmp(odesc, other) || (i >= lo && i <= hi))) + sametype[i] = TRUE; + } + } - /* Since almost every artifact is SPFX_RESTR, it doesn't cost - us much to do the string comparison before the spfx check. - Bug fix: don't name multiple elven daggers "Sting". - */ - for (a = artilist+1; a->otyp; a++) { - if (!sametype[a->otyp]) continue; - aname = a->name; - if (!strncmpi(aname, "the ", 4)) aname += 4; - if (!strcmp(aname, name)) - return ((boolean)((a->spfx & (SPFX_NOGEN|SPFX_RESTR)) != 0 || - otmp->quan > 1L)); - } + /* Since almost every artifact is SPFX_RESTR, it doesn't cost + us much to do the string comparison before the spfx check. + Bug fix: don't name multiple elven daggers "Sting". + */ + for (a = artilist + 1; a->otyp; a++) { + if (!sametype[a->otyp]) + continue; + aname = a->name; + if (!strncmpi(aname, "the ", 4)) + aname += 4; + if (!strcmp(aname, name)) + return ((boolean)((a->spfx & (SPFX_NOGEN | SPFX_RESTR)) != 0 + || otmp->quan > 1L)); + } - return FALSE; + return FALSE; } STATIC_OVL boolean @@ -386,11 +407,11 @@ attacks(adtyp, otmp) register int adtyp; register struct obj *otmp; { - register const struct artifact *weap; + register const struct artifact *weap; - if ((weap = get_artifact(otmp)) != 0) - return((boolean)(weap->attk.adtyp == adtyp)); - return FALSE; + if ((weap = get_artifact(otmp)) != 0) + return ((boolean)(weap->attk.adtyp == adtyp)); + return FALSE; } boolean @@ -398,11 +419,11 @@ defends(adtyp, otmp) register int adtyp; register struct obj *otmp; { - register const struct artifact *weap; + register const struct artifact *weap; - if ((weap = get_artifact(otmp)) != 0) - return((boolean)(weap->defn.adtyp == adtyp)); - return FALSE; + if ((weap = get_artifact(otmp)) != 0) + return ((boolean)(weap->defn.adtyp == adtyp)); + return FALSE; } /* used for monsters */ @@ -411,11 +432,11 @@ defends_when_carried(adtyp, otmp) int adtyp; struct obj *otmp; { - register const struct artifact *weap; + register const struct artifact *weap; - if ((weap = get_artifact(otmp)) != 0) - return (boolean)(weap->cary.adtyp == adtyp); - return FALSE; + if ((weap = get_artifact(otmp)) != 0) + return (boolean)(weap->cary.adtyp == adtyp); + return FALSE; } /* determine whether an item confers Protection */ @@ -424,14 +445,15 @@ protects(otmp, being_worn) struct obj *otmp; boolean being_worn; { - const struct artifact *arti; + const struct artifact *arti; - if (being_worn && objects[otmp->otyp].oc_oprop == PROTECTION) - return TRUE; - arti = get_artifact(otmp); - if (!arti) return FALSE; - return (arti->cspfx & SPFX_PROTECT) != 0 || - (being_worn && (arti->spfx & SPFX_PROTECT) != 0); + if (being_worn && objects[otmp->otyp].oc_oprop == PROTECTION) + return TRUE; + arti = get_artifact(otmp); + if (!arti) + return FALSE; + return (arti->cspfx & SPFX_PROTECT) != 0 + || (being_worn && (arti->spfx & SPFX_PROTECT) != 0); } /* @@ -439,217 +461,251 @@ boolean being_worn; * unworn/unwielded/dropped. Pickup/drop only set/reset the W_ART mask. */ void -set_artifact_intrinsic(otmp,on,wp_mask) +set_artifact_intrinsic(otmp, on, wp_mask) register struct obj *otmp; boolean on; long wp_mask; { - long *mask = 0; - register const struct artifact *oart = get_artifact(otmp); - uchar dtyp; - long spfx; + long *mask = 0; + register const struct artifact *oart = get_artifact(otmp); + uchar dtyp; + long spfx; - if (!oart) return; + if (!oart) + return; - /* effects from the defn field */ - dtyp = (wp_mask != W_ART) ? oart->defn.adtyp : oart->cary.adtyp; + /* effects from the defn field */ + dtyp = (wp_mask != W_ART) ? oart->defn.adtyp : oart->cary.adtyp; - if (dtyp == AD_FIRE) - mask = &EFire_resistance; - else if (dtyp == AD_COLD) - mask = &ECold_resistance; - else if (dtyp == AD_ELEC) - mask = &EShock_resistance; - else if (dtyp == AD_MAGM) - mask = &EAntimagic; - else if (dtyp == AD_DISN) - mask = &EDisint_resistance; - else if (dtyp == AD_DRST) - mask = &EPoison_resistance; + if (dtyp == AD_FIRE) + mask = &EFire_resistance; + else if (dtyp == AD_COLD) + mask = &ECold_resistance; + else if (dtyp == AD_ELEC) + mask = &EShock_resistance; + else if (dtyp == AD_MAGM) + mask = &EAntimagic; + else if (dtyp == AD_DISN) + mask = &EDisint_resistance; + else if (dtyp == AD_DRST) + mask = &EPoison_resistance; - if (mask && wp_mask == W_ART && !on) { - /* find out if some other artifact also confers this intrinsic */ - /* if so, leave the mask alone */ - register struct obj* obj; - for(obj = invent; obj; obj = obj->nobj) - if(obj != otmp && obj->oartifact) { - register const struct artifact *art = get_artifact(obj); - if(art->cary.adtyp == dtyp) { - mask = (long *) 0; - break; - } - } - } - if (mask) { - if (on) *mask |= wp_mask; - else *mask &= ~wp_mask; - } + if (mask && wp_mask == W_ART && !on) { + /* find out if some other artifact also confers this intrinsic */ + /* if so, leave the mask alone */ + register struct obj *obj; + for (obj = invent; obj; obj = obj->nobj) + if (obj != otmp && obj->oartifact) { + register const struct artifact *art = get_artifact(obj); + if (art->cary.adtyp == dtyp) { + mask = (long *) 0; + break; + } + } + } + if (mask) { + if (on) + *mask |= wp_mask; + else + *mask &= ~wp_mask; + } - /* intrinsics from the spfx field; there could be more than one */ - spfx = (wp_mask != W_ART) ? oart->spfx : oart->cspfx; - if(spfx && wp_mask == W_ART && !on) { - /* don't change any spfx also conferred by other artifacts */ - register struct obj* obj; - for(obj = invent; obj; obj = obj->nobj) - if(obj != otmp && obj->oartifact) { - register const struct artifact *art = get_artifact(obj); - spfx &= ~art->cspfx; - } - } + /* intrinsics from the spfx field; there could be more than one */ + spfx = (wp_mask != W_ART) ? oart->spfx : oart->cspfx; + if (spfx && wp_mask == W_ART && !on) { + /* don't change any spfx also conferred by other artifacts */ + register struct obj *obj; + for (obj = invent; obj; obj = obj->nobj) + if (obj != otmp && obj->oartifact) { + register const struct artifact *art = get_artifact(obj); + spfx &= ~art->cspfx; + } + } - if (spfx & SPFX_SEARCH) { - if(on) ESearching |= wp_mask; - else ESearching &= ~wp_mask; - } - if (spfx & SPFX_HALRES) { - /* make_hallucinated must (re)set the mask itself to get - * the display right */ - /* restoring needed because this is the only artifact intrinsic - * that can print a message--need to guard against being printed - * when restoring a game - */ - (void) make_hallucinated((long)!on, restoring ? FALSE : TRUE, wp_mask); - } - if (spfx & SPFX_ESP) { - if(on) ETelepat |= wp_mask; - else ETelepat &= ~wp_mask; - see_monsters(); - } - if (spfx & SPFX_STLTH) { - if (on) EStealth |= wp_mask; - else EStealth &= ~wp_mask; - } - if (spfx & SPFX_REGEN) { - if (on) ERegeneration |= wp_mask; - else ERegeneration &= ~wp_mask; - } - if (spfx & SPFX_TCTRL) { - if (on) ETeleport_control |= wp_mask; - else ETeleport_control &= ~wp_mask; - } - if (spfx & SPFX_WARN) { - if (spec_m2(otmp)) { - if (on) { - EWarn_of_mon |= wp_mask; - context.warntype.obj |= spec_m2(otmp); - } else { - EWarn_of_mon &= ~wp_mask; - context.warntype.obj &= ~spec_m2(otmp); - } - see_monsters(); - } else { - if (on) EWarning |= wp_mask; - else EWarning &= ~wp_mask; - } - } - if (spfx & SPFX_EREGEN) { - if (on) EEnergy_regeneration |= wp_mask; - else EEnergy_regeneration &= ~wp_mask; - } - if (spfx & SPFX_HSPDAM) { - if (on) EHalf_spell_damage |= wp_mask; - else EHalf_spell_damage &= ~wp_mask; - } - if (spfx & SPFX_HPHDAM) { - if (on) EHalf_physical_damage |= wp_mask; - else EHalf_physical_damage &= ~wp_mask; - } - if (spfx & SPFX_XRAY) { - /* this assumes that no one else is using xray_range */ - if (on) u.xray_range = 3; - else u.xray_range = -1; - vision_full_recalc = 1; - } - if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) { - if (on) EReflecting |= wp_mask; - else EReflecting &= ~wp_mask; - } - if (spfx & SPFX_PROTECT) { - if (on) EProtection |= wp_mask; - else EProtection &= ~wp_mask; - } + if (spfx & SPFX_SEARCH) { + if (on) + ESearching |= wp_mask; + else + ESearching &= ~wp_mask; + } + if (spfx & SPFX_HALRES) { + /* make_hallucinated must (re)set the mask itself to get + * the display right */ + /* restoring needed because this is the only artifact intrinsic + * that can print a message--need to guard against being printed + * when restoring a game + */ + (void) make_hallucinated((long) !on, restoring ? FALSE : TRUE, + wp_mask); + } + if (spfx & SPFX_ESP) { + if (on) + ETelepat |= wp_mask; + else + ETelepat &= ~wp_mask; + see_monsters(); + } + if (spfx & SPFX_STLTH) { + if (on) + EStealth |= wp_mask; + else + EStealth &= ~wp_mask; + } + if (spfx & SPFX_REGEN) { + if (on) + ERegeneration |= wp_mask; + else + ERegeneration &= ~wp_mask; + } + if (spfx & SPFX_TCTRL) { + if (on) + ETeleport_control |= wp_mask; + else + ETeleport_control &= ~wp_mask; + } + if (spfx & SPFX_WARN) { + if (spec_m2(otmp)) { + if (on) { + EWarn_of_mon |= wp_mask; + context.warntype.obj |= spec_m2(otmp); + } else { + EWarn_of_mon &= ~wp_mask; + context.warntype.obj &= ~spec_m2(otmp); + } + see_monsters(); + } else { + if (on) + EWarning |= wp_mask; + else + EWarning &= ~wp_mask; + } + } + if (spfx & SPFX_EREGEN) { + if (on) + EEnergy_regeneration |= wp_mask; + else + EEnergy_regeneration &= ~wp_mask; + } + if (spfx & SPFX_HSPDAM) { + if (on) + EHalf_spell_damage |= wp_mask; + else + EHalf_spell_damage &= ~wp_mask; + } + if (spfx & SPFX_HPHDAM) { + if (on) + EHalf_physical_damage |= wp_mask; + else + EHalf_physical_damage &= ~wp_mask; + } + if (spfx & SPFX_XRAY) { + /* this assumes that no one else is using xray_range */ + if (on) + u.xray_range = 3; + else + u.xray_range = -1; + vision_full_recalc = 1; + } + if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) { + if (on) + EReflecting |= wp_mask; + else + EReflecting &= ~wp_mask; + } + if (spfx & SPFX_PROTECT) { + if (on) + EProtection |= wp_mask; + else + EProtection &= ~wp_mask; + } - if(wp_mask == W_ART && !on && oart->inv_prop) { - /* might have to turn off invoked power too */ - if (oart->inv_prop <= LAST_PROP && - (u.uprops[oart->inv_prop].extrinsic & W_ARTI)) - (void) arti_invoke(otmp); - } + if (wp_mask == W_ART && !on && oart->inv_prop) { + /* might have to turn off invoked power too */ + if (oart->inv_prop <= LAST_PROP + && (u.uprops[oart->inv_prop].extrinsic & W_ARTI)) + (void) arti_invoke(otmp); + } } /* touch_artifact()'s return value isn't sufficient to tell whether it dished out damage, and tracking changes to u.uhp, u.mh, Lifesaved when trying to avoid second wounding is too cumbersome */ -STATIC_VAR boolean touch_blasted; /* for retouch_object() */ +STATIC_VAR boolean touch_blasted; /* for retouch_object() */ /* - * creature (usually player) tries to touch (pick up or wield) an artifact obj. + * creature (usually player) tries to touch (pick up or wield) an artifact + * obj. * Returns 0 if the object refuses to be touched. * This routine does not change any object chains. * Ignores such things as gauntlets, assuming the artifact is not * fooled by such trappings. */ int -touch_artifact(obj,mon) - struct obj *obj; - struct monst *mon; +touch_artifact(obj, mon) +struct obj *obj; +struct monst *mon; { register const struct artifact *oart = get_artifact(obj); boolean badclass, badalign, self_willed, yours; touch_blasted = FALSE; - if(!oart) return 1; + if (!oart) + return 1; yours = (mon == &youmonst); /* all quest artifacts are self-willed; it this ever changes, `badclass' will have to be extended to explicitly include quest artifacts */ self_willed = ((oart->spfx & SPFX_INTEL) != 0); if (yours) { - badclass = self_willed && - ((oart->role != NON_PM && !Role_if(oart->role)) || - (oart->race != NON_PM && !Race_if(oart->race))); - badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE && - (oart->alignment != u.ualign.type || u.ualign.record < 0); + badclass = self_willed + && ((oart->role != NON_PM && !Role_if(oart->role)) + || (oart->race != NON_PM && !Race_if(oart->race))); + badalign = + (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE + && (oart->alignment != u.ualign.type || u.ualign.record < 0); } else if (!is_covetous(mon->data) && !is_mplayer(mon->data)) { - badclass = self_willed && - oart->role != NON_PM && oart != &artilist[ART_EXCALIBUR]; - badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE && - (oart->alignment != mon_aligntyp(mon)); - } else { /* an M3_WANTSxxx monster or a fake player */ - /* special monsters trying to take the Amulet, invocation tools or - quest item can touch anything except for `spec_applies' artifacts */ - badclass = badalign = FALSE; + badclass = self_willed && oart->role != NON_PM + && oart != &artilist[ART_EXCALIBUR]; + badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE + && (oart->alignment != mon_aligntyp(mon)); + } else { /* an M3_WANTSxxx monster or a fake player */ + /* special monsters trying to take the Amulet, invocation tools or + quest item can touch anything except for `spec_applies' artifacts + */ + badclass = badalign = FALSE; } /* weapons which attack specific categories of monsters are bad for them even if their alignments happen to match */ - if (!badalign) badalign = bane_applies(oart, mon); + if (!badalign) + badalign = bane_applies(oart, mon); - if (((badclass || badalign) && self_willed) || - (badalign && (!yours || !rn2(4)))) { - int dmg, tmp; - char buf[BUFSZ]; + if (((badclass || badalign) && self_willed) + || (badalign && (!yours || !rn2(4)))) { + int dmg, tmp; + char buf[BUFSZ]; - if (!yours) return 0; - You("are blasted by %s power!", s_suffix(the(xname(obj)))); - touch_blasted = TRUE; - dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4)); - /* add half (maybe quarter) of the usual silver damage bonus */ - if (objects[obj->otyp].oc_material == SILVER && Hate_silver) - tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); - Sprintf(buf, "touching %s", oart->name); - losehp(dmg, buf, KILLED_BY); /* magic damage, not physical */ - exercise(A_WIS, FALSE); + if (!yours) + return 0; + You("are blasted by %s power!", s_suffix(the(xname(obj)))); + touch_blasted = TRUE; + dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4)); + /* add half (maybe quarter) of the usual silver damage bonus */ + if (objects[obj->otyp].oc_material == SILVER && Hate_silver) + tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); + Sprintf(buf, "touching %s", oart->name); + losehp(dmg, buf, KILLED_BY); /* magic damage, not physical */ + exercise(A_WIS, FALSE); } /* can pick it up unless you're totally non-synch'd with the artifact */ if (badclass && badalign && self_willed) { - if (yours) { - if (!carried(obj)) - pline("%s your grasp!", Tobjnam(obj, "evade")); - else - pline("%s beyond your control!", Tobjnam(obj, "are")); - } - return 0; + if (yours) { + if (!carried(obj)) + pline("%s your grasp!", Tobjnam(obj, "evade")); + else + pline("%s beyond your control!", Tobjnam(obj, "are")); + } + return 0; } return 1; @@ -664,11 +720,12 @@ int dtyp; { register const struct artifact *weap = get_artifact(obj); - if (!weap) return FALSE; - if (dtyp == AD_PHYS) return FALSE; /* nothing is immune to phys dmg */ - return (weap->attk.adtyp == dtyp || - weap->defn.adtyp == dtyp || - weap->cary.adtyp == dtyp); + if (!weap) + return FALSE; + if (dtyp == AD_PHYS) + return FALSE; /* nothing is immune to phys dmg */ + return (weap->attk.adtyp == dtyp || weap->defn.adtyp == dtyp + || weap->cary.adtyp == dtyp); } STATIC_OVL boolean @@ -679,9 +736,10 @@ struct monst *mon; struct artifact atmp; if (oart && (oart->spfx & SPFX_DBONUS) != 0) { - atmp = *oart; - atmp.spfx &= SPFX_DBONUS; /* clear other spfx fields */ - if (spec_applies(&atmp, mon)) return TRUE; + atmp = *oart; + atmp.spfx &= SPFX_DBONUS; /* clear other spfx fields */ + if (spec_applies(&atmp, mon)) + return TRUE; } return FALSE; } @@ -692,66 +750,69 @@ spec_applies(weap, mtmp) register const struct artifact *weap; struct monst *mtmp; { - struct permonst *ptr; - boolean yours; + struct permonst *ptr; + boolean yours; - if(!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK))) - return(weap->attk.adtyp == AD_PHYS); + if (!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK))) + return (weap->attk.adtyp == AD_PHYS); - yours = (mtmp == &youmonst); - ptr = mtmp->data; + yours = (mtmp == &youmonst); + ptr = mtmp->data; - if (weap->spfx & SPFX_DMONS) { - return (ptr == &mons[(int)weap->mtype]); - } else if (weap->spfx & SPFX_DCLAS) { - return (weap->mtype == (unsigned long)ptr->mlet); - } else if (weap->spfx & SPFX_DFLAG1) { - return ((ptr->mflags1 & weap->mtype) != 0L); - } else if (weap->spfx & SPFX_DFLAG2) { - return ((ptr->mflags2 & weap->mtype) || (yours && - ((!Upolyd && (urace.selfmask & weap->mtype)) || - ((weap->mtype & M2_WERE) && u.ulycn >= LOW_PM)))); - } else if (weap->spfx & SPFX_DALIGN) { - return yours ? (u.ualign.type != weap->alignment) : - (ptr->maligntyp == A_NONE || - sgn(ptr->maligntyp) != weap->alignment); - } else if (weap->spfx & SPFX_ATTK) { - struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp)); + if (weap->spfx & SPFX_DMONS) { + return (ptr == &mons[(int) weap->mtype]); + } else if (weap->spfx & SPFX_DCLAS) { + return (weap->mtype == (unsigned long) ptr->mlet); + } else if (weap->spfx & SPFX_DFLAG1) { + return ((ptr->mflags1 & weap->mtype) != 0L); + } else if (weap->spfx & SPFX_DFLAG2) { + return ((ptr->mflags2 & weap->mtype) + || (yours + && ((!Upolyd && (urace.selfmask & weap->mtype)) + || ((weap->mtype & M2_WERE) && u.ulycn >= LOW_PM)))); + } else if (weap->spfx & SPFX_DALIGN) { + return yours ? (u.ualign.type != weap->alignment) + : (ptr->maligntyp == A_NONE + || sgn(ptr->maligntyp) != weap->alignment); + } else if (weap->spfx & SPFX_ATTK) { + struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp)); - if (defending_weapon && defending_weapon->oartifact && - defends((int)weap->attk.adtyp, defending_weapon)) - return FALSE; - switch(weap->attk.adtyp) { - case AD_FIRE: - return !(yours ? Fire_resistance : resists_fire(mtmp)); - case AD_COLD: - return !(yours ? Cold_resistance : resists_cold(mtmp)); - case AD_ELEC: - return !(yours ? Shock_resistance : resists_elec(mtmp)); - case AD_MAGM: - case AD_STUN: - return !(yours ? Antimagic : (rn2(100) < ptr->mr)); - case AD_DRST: - return !(yours ? Poison_resistance : resists_poison(mtmp)); - case AD_DRLI: - return !(yours ? Drain_resistance : resists_drli(mtmp)); - case AD_STON: - return !(yours ? Stone_resistance : resists_ston(mtmp)); - default: impossible("Weird weapon special attack."); - } - } - return(0); + if (defending_weapon && defending_weapon->oartifact + && defends((int) weap->attk.adtyp, defending_weapon)) + return FALSE; + switch (weap->attk.adtyp) { + case AD_FIRE: + return !(yours ? Fire_resistance : resists_fire(mtmp)); + case AD_COLD: + return !(yours ? Cold_resistance : resists_cold(mtmp)); + case AD_ELEC: + return !(yours ? Shock_resistance : resists_elec(mtmp)); + case AD_MAGM: + case AD_STUN: + return !(yours ? Antimagic : (rn2(100) < ptr->mr)); + case AD_DRST: + return !(yours ? Poison_resistance : resists_poison(mtmp)); + case AD_DRLI: + return !(yours ? Drain_resistance : resists_drli(mtmp)); + case AD_STON: + return !(yours ? Stone_resistance : resists_ston(mtmp)); + default: + impossible("Weird weapon special attack."); + } + } + return (0); } -/* return the M2 flags of monster that an artifact's special attacks apply against */ +/* return the M2 flags of monster that an artifact's special attacks apply + * against */ long spec_m2(otmp) struct obj *otmp; { - register const struct artifact *artifact = get_artifact(otmp); - if (artifact) - return artifact->mtype; - return 0L; + register const struct artifact *artifact = get_artifact(otmp); + if (artifact) + return artifact->mtype; + return 0L; } /* special attack bonus */ @@ -760,14 +821,14 @@ spec_abon(otmp, mon) struct obj *otmp; struct monst *mon; { - register const struct artifact *weap = get_artifact(otmp); + register const struct artifact *weap = get_artifact(otmp); - /* no need for an extra check for `NO_ATTK' because this will - always return 0 for any artifact which has that attribute */ + /* no need for an extra check for `NO_ATTK' because this will + always return 0 for any artifact which has that attribute */ - if (weap && weap->attk.damn && spec_applies(weap, mon)) - return rnd((int)weap->attk.damn); - return 0; + if (weap && weap->attk.damn && spec_applies(weap, mon)) + return rnd((int) weap->attk.damn); + return 0; } /* special damage bonus */ @@ -777,17 +838,17 @@ struct obj *otmp; struct monst *mon; int tmp; { - register const struct artifact *weap = get_artifact(otmp); + register const struct artifact *weap = get_artifact(otmp); - if (!weap || (weap->attk.adtyp == AD_PHYS && /* check for `NO_ATTK' */ - weap->attk.damn == 0 && weap->attk.damd == 0)) - spec_dbon_applies = FALSE; - else - spec_dbon_applies = spec_applies(weap, mon); + if (!weap || (weap->attk.adtyp == AD_PHYS && /* check for `NO_ATTK' */ + weap->attk.damn == 0 && weap->attk.damd == 0)) + spec_dbon_applies = FALSE; + else + spec_dbon_applies = spec_applies(weap, mon); - if (spec_dbon_applies) - return weap->attk.damd ? rnd((int)weap->attk.damd) : max(tmp,1); - return 0; + if (spec_dbon_applies) + return weap->attk.damd ? rnd((int) weap->attk.damd) : max(tmp, 1); + return 0; } /* add identified artifact to discoveries list */ @@ -800,13 +861,13 @@ xchar m; /* look for this artifact in the discoveries list; if we hit an empty slot then it's not present, so add it */ for (i = 0; i < NROFARTIFACTS; i++) - if (artidisco[i] == 0 || artidisco[i] == m) { - artidisco[i] = m; - return; - } + if (artidisco[i] == 0 || artidisco[i] == m) { + artidisco[i] = m; + return; + } /* there is one slot per artifact, so we should never reach the end without either finding the artifact or an empty slot... */ - impossible("couldn't discover artifact (%d)", (int)m); + impossible("couldn't discover artifact (%d)", (int) m); } /* used to decide whether an artifact has been fully identified */ @@ -819,95 +880,98 @@ xchar m; /* look for this artifact in the discoveries list; if we hit an empty slot then it's undiscovered */ for (i = 0; i < NROFARTIFACTS; i++) - if (artidisco[i] == m) - return FALSE; - else if (artidisco[i] == 0) - break; + if (artidisco[i] == m) + return FALSE; + else if (artidisco[i] == 0) + break; return TRUE; } /* display a list of discovered artifacts; return their count */ int disp_artifact_discoveries(tmpwin) -winid tmpwin; /* supplied by dodiscover() */ +winid tmpwin; /* supplied by dodiscover() */ { int i, m, otyp; char buf[BUFSZ]; for (i = 0; i < NROFARTIFACTS; i++) { - if (artidisco[i] == 0) break; /* empty slot implies end of list */ - if (tmpwin == WIN_ERR) continue; /* for WIN_ERR, we just count */ + if (artidisco[i] == 0) + break; /* empty slot implies end of list */ + if (tmpwin == WIN_ERR) + continue; /* for WIN_ERR, we just count */ - if (i == 0) putstr(tmpwin, iflags.menu_headings, "Artifacts"); - m = artidisco[i]; - otyp = artilist[m].otyp; - Sprintf(buf, " %s [%s %s]", artiname(m), - align_str(artilist[m].alignment), simple_typename(otyp)); - putstr(tmpwin, 0, buf); + if (i == 0) + putstr(tmpwin, iflags.menu_headings, "Artifacts"); + m = artidisco[i]; + otyp = artilist[m].otyp; + Sprintf(buf, " %s [%s %s]", artiname(m), + align_str(artilist[m].alignment), simple_typename(otyp)); + putstr(tmpwin, 0, buf); } return i; } - /* - * Magicbane's intrinsic magic is incompatible with normal - * enchantment magic. Thus, its effects have a negative - * dependence on spe. Against low mr victims, it typically - * does "double athame" damage, 2d4. Occasionally, it will - * cast unbalancing magic which effectively averages out to - * 4d4 damage (3d4 against high mr victims), for spe = 0. - * - * Prior to 3.4.1, the cancel (aka purge) effect always - * included the scare effect too; now it's one or the other. - * Likewise, the stun effect won't be combined with either - * of those two; it will be chosen separately or possibly - * used as a fallback when scare or cancel fails. - * - * [Historical note: a change to artifact_hit() for 3.4.0 - * unintentionally made all of Magicbane's special effects - * be blocked if the defender successfully saved against a - * stun attack. As of 3.4.1, those effects can occur but - * will be slightly less likely than they were in 3.3.x.] - */ -#define MB_MAX_DIEROLL 8 /* rolls above this aren't magical */ -static const char * const mb_verb[2][4] = { - { "probe", "stun", "scare", "cancel" }, - { "prod", "amaze", "tickle", "purge" }, +/* + * Magicbane's intrinsic magic is incompatible with normal + * enchantment magic. Thus, its effects have a negative + * dependence on spe. Against low mr victims, it typically + * does "double athame" damage, 2d4. Occasionally, it will + * cast unbalancing magic which effectively averages out to + * 4d4 damage (3d4 against high mr victims), for spe = 0. + * + * Prior to 3.4.1, the cancel (aka purge) effect always + * included the scare effect too; now it's one or the other. + * Likewise, the stun effect won't be combined with either + * of those two; it will be chosen separately or possibly + * used as a fallback when scare or cancel fails. + * + * [Historical note: a change to artifact_hit() for 3.4.0 + * unintentionally made all of Magicbane's special effects + * be blocked if the defender successfully saved against a + * stun attack. As of 3.4.1, those effects can occur but + * will be slightly less likely than they were in 3.3.x.] + */ +#define MB_MAX_DIEROLL 8 /* rolls above this aren't magical */ +static const char *const mb_verb[2][4] = { + { "probe", "stun", "scare", "cancel" }, + { "prod", "amaze", "tickle", "purge" }, }; -#define MB_INDEX_PROBE 0 -#define MB_INDEX_STUN 1 -#define MB_INDEX_SCARE 2 -#define MB_INDEX_CANCEL 3 +#define MB_INDEX_PROBE 0 +#define MB_INDEX_STUN 1 +#define MB_INDEX_SCARE 2 +#define MB_INDEX_CANCEL 3 /* called when someone is being hit by Magicbane */ STATIC_OVL boolean Mb_hit(magr, mdef, mb, dmgptr, dieroll, vis, hittee) -struct monst *magr, *mdef; /* attacker and defender */ -struct obj *mb; /* Magicbane */ -int *dmgptr; /* extra damage target will suffer */ -int dieroll; /* d20 that has already scored a hit */ -boolean vis; /* whether the action can be seen */ -char *hittee; /* target's name: "you" or mon_nam(mdef) */ +struct monst *magr, *mdef; /* attacker and defender */ +struct obj *mb; /* Magicbane */ +int *dmgptr; /* extra damage target will suffer */ +int dieroll; /* d20 that has already scored a hit */ +boolean vis; /* whether the action can be seen */ +char *hittee; /* target's name: "you" or mon_nam(mdef) */ { struct permonst *old_uasmon; const char *verb, *fakename; - boolean youattack = (magr == &youmonst), - youdefend = (mdef == &youmonst), - resisted = FALSE, do_stun, do_confuse, result; + boolean youattack = (magr == &youmonst), youdefend = (mdef == &youmonst), + resisted = FALSE, do_stun, do_confuse, result; int attack_indx, scare_dieroll = MB_MAX_DIEROLL / 2; - result = FALSE; /* no message given yet */ + result = FALSE; /* no message given yet */ /* the most severe effects are less likely at higher enchantment */ if (mb->spe >= 3) - scare_dieroll /= (1 << (mb->spe / 3)); + scare_dieroll /= (1 << (mb->spe / 3)); /* if target successfully resisted the artifact damage bonus, reduce overall likelihood of the assorted special effects */ - if (!spec_dbon_applies) dieroll += 1; + if (!spec_dbon_applies) + dieroll += 1; /* might stun even when attempting a more severe effect, but in that case it will only happen if the other effect fails; extra damage will apply regardless; 3.4.1: sometimes might just probe even when it hasn't been enchanted */ - do_stun = (max(mb->spe,0) < rn2(spec_dbon_applies ? 11 : 7)); + do_stun = (max(mb->spe, 0) < rn2(spec_dbon_applies ? 11 : 7)); /* the special effects also boost physical damage; increments are generally cumulative, but since the stun effect is based on a @@ -917,143 +981,149 @@ char *hittee; /* target's name: "you" or mon_nam(mdef) */ [note that a successful save against AD_STUN doesn't actually prevent the target from ending up stunned] */ attack_indx = MB_INDEX_PROBE; - *dmgptr += rnd(4); /* (2..3)d4 */ + *dmgptr += rnd(4); /* (2..3)d4 */ if (do_stun) { - attack_indx = MB_INDEX_STUN; - *dmgptr += rnd(4); /* (3..4)d4 */ + attack_indx = MB_INDEX_STUN; + *dmgptr += rnd(4); /* (3..4)d4 */ } if (dieroll <= scare_dieroll) { - attack_indx = MB_INDEX_SCARE; - *dmgptr += rnd(4); /* (3..5)d4 */ + attack_indx = MB_INDEX_SCARE; + *dmgptr += rnd(4); /* (3..5)d4 */ } if (dieroll <= (scare_dieroll / 2)) { - attack_indx = MB_INDEX_CANCEL; - *dmgptr += rnd(4); /* (4..6)d4 */ + attack_indx = MB_INDEX_CANCEL; + *dmgptr += rnd(4); /* (4..6)d4 */ } /* give the hit message prior to inflicting the effects */ verb = mb_verb[!!Hallucination][attack_indx]; if (youattack || youdefend || vis) { - result = TRUE; - pline_The("magic-absorbing blade %s %s!", - vtense((const char *)0, verb), hittee); - /* assume probing has some sort of noticeable feedback - even if it is being done by one monster to another */ - if (attack_indx == MB_INDEX_PROBE && !canspotmon(mdef)) - map_invisible(mdef->mx, mdef->my); + result = TRUE; + pline_The("magic-absorbing blade %s %s!", + vtense((const char *) 0, verb), hittee); + /* assume probing has some sort of noticeable feedback + even if it is being done by one monster to another */ + if (attack_indx == MB_INDEX_PROBE && !canspotmon(mdef)) + map_invisible(mdef->mx, mdef->my); } /* now perform special effects */ switch (attack_indx) { case MB_INDEX_CANCEL: - old_uasmon = youmonst.data; - /* No mdef->mcan check: even a cancelled monster can be polymorphed - * into a golem, and the "cancel" effect acts as if some magical - * energy remains in spellcasting defenders to be absorbed later. - */ - if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) { - resisted = TRUE; - } else { - do_stun = FALSE; - if (youdefend) { - if (youmonst.data != old_uasmon) - *dmgptr = 0; /* rehumanized, so no more damage */ - if (u.uenmax > 0) { - You("lose magical energy!"); - u.uenmax--; - if (u.uen > 0) u.uen--; - context.botl = 1; - } - } else { - if (mdef->data == &mons[PM_CLAY_GOLEM]) - mdef->mhp = 1; /* cancelled clay golems will die */ - if (youattack && attacktype(mdef->data, AT_MAGC)) { - You("absorb magical energy!"); - u.uenmax++; - u.uen++; - context.botl = 1; - } - } - } - break; + old_uasmon = youmonst.data; + /* No mdef->mcan check: even a cancelled monster can be polymorphed + * into a golem, and the "cancel" effect acts as if some magical + * energy remains in spellcasting defenders to be absorbed later. + */ + if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) { + resisted = TRUE; + } else { + do_stun = FALSE; + if (youdefend) { + if (youmonst.data != old_uasmon) + *dmgptr = 0; /* rehumanized, so no more damage */ + if (u.uenmax > 0) { + You("lose magical energy!"); + u.uenmax--; + if (u.uen > 0) + u.uen--; + context.botl = 1; + } + } else { + if (mdef->data == &mons[PM_CLAY_GOLEM]) + mdef->mhp = 1; /* cancelled clay golems will die */ + if (youattack && attacktype(mdef->data, AT_MAGC)) { + You("absorb magical energy!"); + u.uenmax++; + u.uen++; + context.botl = 1; + } + } + } + break; case MB_INDEX_SCARE: - if (youdefend) { - if (Antimagic) { - resisted = TRUE; - } else { - nomul(-3); - multi_reason = "being scared stiff"; - nomovemsg = ""; - if (magr && magr == u.ustuck && sticks(youmonst.data)) { - u.ustuck = (struct monst *)0; - You("release %s!", mon_nam(magr)); - } - } - } else { - if (rn2(2) && resist(mdef, WEAPON_CLASS, 0, NOTELL)) - resisted = TRUE; - else - monflee(mdef, 3, FALSE, (mdef->mhp > *dmgptr)); - } - if (!resisted) do_stun = FALSE; - break; + if (youdefend) { + if (Antimagic) { + resisted = TRUE; + } else { + nomul(-3); + multi_reason = "being scared stiff"; + nomovemsg = ""; + if (magr && magr == u.ustuck && sticks(youmonst.data)) { + u.ustuck = (struct monst *) 0; + You("release %s!", mon_nam(magr)); + } + } + } else { + if (rn2(2) && resist(mdef, WEAPON_CLASS, 0, NOTELL)) + resisted = TRUE; + else + monflee(mdef, 3, FALSE, (mdef->mhp > *dmgptr)); + } + if (!resisted) + do_stun = FALSE; + break; case MB_INDEX_STUN: - do_stun = TRUE; /* (this is redundant...) */ - break; + do_stun = TRUE; /* (this is redundant...) */ + break; case MB_INDEX_PROBE: - if (youattack && (mb->spe == 0 || !rn2(3 * abs(mb->spe)))) { - pline_The("%s is insightful.", verb); - /* pre-damage status */ - probe_monster(mdef); - } - break; + if (youattack && (mb->spe == 0 || !rn2(3 * abs(mb->spe)))) { + pline_The("%s is insightful.", verb); + /* pre-damage status */ + probe_monster(mdef); + } + break; } /* stun if that was selected and a worse effect didn't occur */ if (do_stun) { - if (youdefend) - make_stunned(((HStun & TIMEOUT) + 3L), FALSE); - else - mdef->mstun = 1; - /* avoid extra stun message below if we used mb_verb["stun"] above */ - if (attack_indx == MB_INDEX_STUN) do_stun = FALSE; + if (youdefend) + make_stunned(((HStun & TIMEOUT) + 3L), FALSE); + else + mdef->mstun = 1; + /* avoid extra stun message below if we used mb_verb["stun"] above */ + if (attack_indx == MB_INDEX_STUN) + do_stun = FALSE; } /* lastly, all this magic can be confusing... */ do_confuse = !rn2(12); if (do_confuse) { - if (youdefend) - make_confused((HConfusion & TIMEOUT) + 4L, FALSE); - else - mdef->mconf = 1; + if (youdefend) + make_confused((HConfusion & TIMEOUT) + 4L, FALSE); + else + mdef->mconf = 1; } /* now give message(s) describing side-effects; don't let vtense() be fooled by assigned name ending in 's' */ fakename = youdefend ? "you" : "mon"; if (youattack || youdefend || vis) { - (void) upstart(hittee); /* capitalize */ - if (resisted) { - pline("%s %s!", hittee, vtense(fakename, "resist")); - shieldeff(youdefend ? u.ux : mdef->mx, - youdefend ? u.uy : mdef->my); - } - if ((do_stun || do_confuse) && flags.verbose) { - char buf[BUFSZ]; + (void) upstart(hittee); /* capitalize */ + if (resisted) { + pline("%s %s!", hittee, vtense(fakename, "resist")); + shieldeff(youdefend ? u.ux : mdef->mx, + youdefend ? u.uy : mdef->my); + } + if ((do_stun || do_confuse) && flags.verbose) { + char buf[BUFSZ]; - buf[0] = '\0'; - if (do_stun) Strcat(buf, "stunned"); - if (do_stun && do_confuse) Strcat(buf, " and "); - if (do_confuse) Strcat(buf, "confused"); - pline("%s %s %s%c", hittee, vtense(fakename, "are"), - buf, (do_stun && do_confuse) ? '!' : '.'); - } + buf[0] = '\0'; + if (do_stun) + Strcat(buf, "stunned"); + if (do_stun && do_confuse) + Strcat(buf, " and "); + if (do_confuse) + Strcat(buf, "confused"); + pline("%s %s %s%c", hittee, vtense(fakename, "are"), buf, + (do_stun && do_confuse) ? '!' : '.'); + } } return result; } - + /* Function used when someone attacks someone else with an artifact * weapon. Only adds the special (artifact) damage, and returns a 1 if it * did something special (in which case the caller won't print the normal @@ -1069,243 +1139,245 @@ struct obj *otmp; int *dmgptr; int dieroll; /* needed for Magicbane and vorpal blades */ { - boolean youattack = (magr == &youmonst); - boolean youdefend = (mdef == &youmonst); - boolean vis = (!youattack && magr && cansee(magr->mx, magr->my)) - || (!youdefend && cansee(mdef->mx, mdef->my)) - || (youattack && u.uswallow && mdef == u.ustuck && !Blind); - boolean realizes_damage; - const char *wepdesc; - static const char you[] = "you"; - char hittee[BUFSZ]; + boolean youattack = (magr == &youmonst); + boolean youdefend = (mdef == &youmonst); + boolean vis = (!youattack && magr && cansee(magr->mx, magr->my)) + || (!youdefend && cansee(mdef->mx, mdef->my)) + || (youattack && u.uswallow && mdef == u.ustuck && !Blind); + boolean realizes_damage; + const char *wepdesc; + static const char you[] = "you"; + char hittee[BUFSZ]; - Strcpy(hittee, youdefend ? you : mon_nam(mdef)); + Strcpy(hittee, youdefend ? you : mon_nam(mdef)); - /* The following takes care of most of the damage, but not all-- - * the exception being for level draining, which is specially - * handled. Messages are done in this function, however. - */ - *dmgptr += spec_dbon(otmp, mdef, *dmgptr); + /* The following takes care of most of the damage, but not all-- + * the exception being for level draining, which is specially + * handled. Messages are done in this function, however. + */ + *dmgptr += spec_dbon(otmp, mdef, *dmgptr); - if (youattack && youdefend) { - impossible("attacking yourself with weapon?"); - return FALSE; - } + if (youattack && youdefend) { + impossible("attacking yourself with weapon?"); + return FALSE; + } - realizes_damage = (youdefend || vis || - /* feel the effect even if not seen */ - (youattack && mdef == u.ustuck)); + realizes_damage = (youdefend || vis || + /* feel the effect even if not seen */ + (youattack && mdef == u.ustuck)); - /* the four basic attacks: fire, cold, shock and missiles */ - if (attacks(AD_FIRE, otmp)) { - if (realizes_damage) - pline_The("fiery blade %s %s%c", - !spec_dbon_applies ? "hits" : - (mdef->data == &mons[PM_WATER_ELEMENTAL]) ? - "vaporizes part of" : "burns", - hittee, !spec_dbon_applies ? '.' : '!'); - if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); - if (!rn2(4)) (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); - if (!rn2(7)) (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); - if (youdefend && Slimed) burn_away_slime(); - return realizes_damage; - } - if (attacks(AD_COLD, otmp)) { - if (realizes_damage) - pline_The("ice-cold blade %s %s%c", - !spec_dbon_applies ? "hits" : "freezes", - hittee, !spec_dbon_applies ? '.' : '!'); - if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); - return realizes_damage; - } - if (attacks(AD_ELEC, otmp)) { - if (realizes_damage) - pline_The("massive hammer hits%s %s%c", - !spec_dbon_applies ? "" : "! Lightning strikes", - hittee, !spec_dbon_applies ? '.' : '!'); - if (!rn2(5)) (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); - if (!rn2(5)) (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC); - return realizes_damage; - } - if (attacks(AD_MAGM, otmp)) { - if (realizes_damage) - pline_The("imaginary widget hits%s %s%c", - !spec_dbon_applies ? "" : - "! A hail of magic missiles strikes", - hittee, !spec_dbon_applies ? '.' : '!'); - return realizes_damage; - } + /* the four basic attacks: fire, cold, shock and missiles */ + if (attacks(AD_FIRE, otmp)) { + if (realizes_damage) + pline_The("fiery blade %s %s%c", + !spec_dbon_applies + ? "hits" + : (mdef->data == &mons[PM_WATER_ELEMENTAL]) + ? "vaporizes part of" + : "burns", + hittee, !spec_dbon_applies ? '.' : '!'); + if (!rn2(4)) + (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); + if (!rn2(4)) + (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); + if (!rn2(7)) + (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); + if (youdefend && Slimed) + burn_away_slime(); + return realizes_damage; + } + if (attacks(AD_COLD, otmp)) { + if (realizes_damage) + pline_The("ice-cold blade %s %s%c", + !spec_dbon_applies ? "hits" : "freezes", hittee, + !spec_dbon_applies ? '.' : '!'); + if (!rn2(4)) + (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); + return realizes_damage; + } + if (attacks(AD_ELEC, otmp)) { + if (realizes_damage) + pline_The("massive hammer hits%s %s%c", + !spec_dbon_applies ? "" : "! Lightning strikes", + hittee, !spec_dbon_applies ? '.' : '!'); + if (!rn2(5)) + (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); + if (!rn2(5)) + (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC); + return realizes_damage; + } + if (attacks(AD_MAGM, otmp)) { + if (realizes_damage) + pline_The("imaginary widget hits%s %s%c", + !spec_dbon_applies + ? "" + : "! A hail of magic missiles strikes", + hittee, !spec_dbon_applies ? '.' : '!'); + return realizes_damage; + } - if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) { - /* Magicbane's special attacks (possibly modifies hittee[]) */ - return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); - } + if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) { + /* Magicbane's special attacks (possibly modifies hittee[]) */ + return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); + } - if (!spec_dbon_applies) { - /* since damage bonus didn't apply, nothing more to do; - no further attacks have side-effects on inventory */ - return FALSE; - } + if (!spec_dbon_applies) { + /* since damage bonus didn't apply, nothing more to do; + no further attacks have side-effects on inventory */ + return FALSE; + } - /* We really want "on a natural 20" but Nethack does it in */ - /* reverse from AD&D. */ - if (spec_ability(otmp, SPFX_BEHEAD)) { - if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { - wepdesc = "The razor-sharp blade"; - /* not really beheading, but so close, why add another SPFX */ - if (youattack && u.uswallow && mdef == u.ustuck) { - You("slice %s wide open!", mon_nam(mdef)); - *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; - return TRUE; - } - if (!youdefend) { - /* allow normal cutworm() call to add extra damage */ - if(notonhead) - return FALSE; + /* We really want "on a natural 20" but Nethack does it in */ + /* reverse from AD&D. */ + if (spec_ability(otmp, SPFX_BEHEAD)) { + if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { + wepdesc = "The razor-sharp blade"; + /* not really beheading, but so close, why add another SPFX */ + if (youattack && u.uswallow && mdef == u.ustuck) { + You("slice %s wide open!", mon_nam(mdef)); + *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; + return TRUE; + } + if (!youdefend) { + /* allow normal cutworm() call to add extra damage */ + if (notonhead) + return FALSE; - if (bigmonst(mdef->data)) { - if (youattack) - You("slice deeply into %s!", - mon_nam(mdef)); - else if (vis) - pline("%s cuts deeply into %s!", - Monnam(magr), hittee); - *dmgptr *= 2; - return TRUE; - } - *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; - pline("%s cuts %s in half!", wepdesc, mon_nam(mdef)); - otmp->dknown = TRUE; - return TRUE; - } else { - if (bigmonst(youmonst.data)) { - pline("%s cuts deeply into you!", - magr ? Monnam(magr) : wepdesc); - *dmgptr *= 2; - return TRUE; - } + if (bigmonst(mdef->data)) { + if (youattack) + You("slice deeply into %s!", mon_nam(mdef)); + else if (vis) + pline("%s cuts deeply into %s!", Monnam(magr), + hittee); + *dmgptr *= 2; + return TRUE; + } + *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; + pline("%s cuts %s in half!", wepdesc, mon_nam(mdef)); + otmp->dknown = TRUE; + return TRUE; + } else { + if (bigmonst(youmonst.data)) { + pline("%s cuts deeply into you!", + magr ? Monnam(magr) : wepdesc); + *dmgptr *= 2; + return TRUE; + } - /* Players with negative AC's take less damage instead - * of just not getting hit. We must add a large enough - * value to the damage so that this reduction in - * damage does not prevent death. - */ - *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; - pline("%s cuts you in half!", wepdesc); - otmp->dknown = TRUE; - return TRUE; - } - } else if (otmp->oartifact == ART_VORPAL_BLADE && - (dieroll == 1 || mdef->data == &mons[PM_JABBERWOCK])) { - static const char * const behead_msg[2] = { - "%s beheads %s!", - "%s decapitates %s!" - }; + /* Players with negative AC's take less damage instead + * of just not getting hit. We must add a large enough + * value to the damage so that this reduction in + * damage does not prevent death. + */ + *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; + pline("%s cuts you in half!", wepdesc); + otmp->dknown = TRUE; + return TRUE; + } + } else if (otmp->oartifact == ART_VORPAL_BLADE + && (dieroll == 1 || mdef->data == &mons[PM_JABBERWOCK])) { + static const char *const behead_msg[2] = { "%s beheads %s!", + "%s decapitates %s!" }; - if (youattack && u.uswallow && mdef == u.ustuck) - return FALSE; - wepdesc = artilist[ART_VORPAL_BLADE].name; - if (!youdefend) { - if (!has_head(mdef->data) || notonhead || u.uswallow) { - if (youattack) - pline("Somehow, you miss %s wildly.", - mon_nam(mdef)); - else if (vis) - pline("Somehow, %s misses wildly.", - mon_nam(magr)); - *dmgptr = 0; - return ((boolean)(youattack || vis)); - } - if (noncorporeal(mdef->data) || amorphous(mdef->data)) { - pline("%s slices through %s %s.", wepdesc, - s_suffix(mon_nam(mdef)), - mbodypart(mdef,NECK)); - return TRUE; - } - *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; - pline(behead_msg[rn2(SIZE(behead_msg))], - wepdesc, mon_nam(mdef)); - if(Hallucination && !flags.female) - pline("Good job Henry, but that wasn't Anne."); - otmp->dknown = TRUE; - return TRUE; - } else { - if (!has_head(youmonst.data)) { - pline("Somehow, %s misses you wildly.", - magr ? mon_nam(magr) : wepdesc); - *dmgptr = 0; - return TRUE; - } - if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) { - pline("%s slices through your %s.", - wepdesc, body_part(NECK)); - return TRUE; - } - *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) - + FATAL_DAMAGE_MODIFIER; - pline(behead_msg[rn2(SIZE(behead_msg))], - wepdesc, "you"); - otmp->dknown = TRUE; - /* Should amulets fall off? */ - return TRUE; - } - } - } - if (spec_ability(otmp, SPFX_DRLI)) { - /* some non-living creatures (golems, vortices) are - vulnerable to life drain effects */ - const char *life = nonliving(mdef->data) ? - "animating force" : "life"; + if (youattack && u.uswallow && mdef == u.ustuck) + return FALSE; + wepdesc = artilist[ART_VORPAL_BLADE].name; + if (!youdefend) { + if (!has_head(mdef->data) || notonhead || u.uswallow) { + if (youattack) + pline("Somehow, you miss %s wildly.", mon_nam(mdef)); + else if (vis) + pline("Somehow, %s misses wildly.", mon_nam(magr)); + *dmgptr = 0; + return ((boolean)(youattack || vis)); + } + if (noncorporeal(mdef->data) || amorphous(mdef->data)) { + pline("%s slices through %s %s.", wepdesc, + s_suffix(mon_nam(mdef)), mbodypart(mdef, NECK)); + return TRUE; + } + *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; + pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, + mon_nam(mdef)); + if (Hallucination && !flags.female) + pline("Good job Henry, but that wasn't Anne."); + otmp->dknown = TRUE; + return TRUE; + } else { + if (!has_head(youmonst.data)) { + pline("Somehow, %s misses you wildly.", + magr ? mon_nam(magr) : wepdesc); + *dmgptr = 0; + return TRUE; + } + if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) { + pline("%s slices through your %s.", wepdesc, + body_part(NECK)); + return TRUE; + } + *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; + pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, "you"); + otmp->dknown = TRUE; + /* Should amulets fall off? */ + return TRUE; + } + } + } + if (spec_ability(otmp, SPFX_DRLI)) { + /* some non-living creatures (golems, vortices) are + vulnerable to life drain effects */ + const char *life = nonliving(mdef->data) ? "animating force" : "life"; - if (!youdefend) { - if (vis) { - if(otmp->oartifact == ART_STORMBRINGER) - pline_The("%s blade draws the %s from %s!", - hcolor(NH_BLACK), - life, mon_nam(mdef)); - else - pline("%s draws the %s from %s!", - The(distant_name(otmp, xname)), - life, mon_nam(mdef)); - } - if (mdef->m_lev == 0) { - *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; - } else { - int drain = monhp_per_lvl(mdef); - *dmgptr += drain; - mdef->mhpmax -= drain; - mdef->m_lev--; - drain /= 2; - if (drain) healup(drain, 0, FALSE, FALSE); - } - return vis; - } else { /* youdefend */ - int oldhpmax = u.uhpmax; + if (!youdefend) { + if (vis) { + if (otmp->oartifact == ART_STORMBRINGER) + pline_The("%s blade draws the %s from %s!", + hcolor(NH_BLACK), life, mon_nam(mdef)); + else + pline("%s draws the %s from %s!", + The(distant_name(otmp, xname)), life, + mon_nam(mdef)); + } + if (mdef->m_lev == 0) { + *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; + } else { + int drain = monhp_per_lvl(mdef); + *dmgptr += drain; + mdef->mhpmax -= drain; + mdef->m_lev--; + drain /= 2; + if (drain) + healup(drain, 0, FALSE, FALSE); + } + return vis; + } else { /* youdefend */ + int oldhpmax = u.uhpmax; - if (Blind) - You_feel("an %s drain your %s!", - otmp->oartifact == ART_STORMBRINGER ? - "unholy blade" : "object", life); - else if (otmp->oartifact == ART_STORMBRINGER) - pline_The("%s blade drains your %s!", - hcolor(NH_BLACK), life); - else - pline("%s drains your %s!", - The(distant_name(otmp, xname)), life); - losexp("life drainage"); - if (magr && magr->mhp < magr->mhpmax) { - magr->mhp += (oldhpmax - u.uhpmax)/2; - if (magr->mhp > magr->mhpmax) magr->mhp = magr->mhpmax; - } - return TRUE; - } - } - return FALSE; + if (Blind) + You_feel("an %s drain your %s!", + otmp->oartifact == ART_STORMBRINGER ? "unholy blade" + : "object", + life); + else if (otmp->oartifact == ART_STORMBRINGER) + pline_The("%s blade drains your %s!", hcolor(NH_BLACK), life); + else + pline("%s drains your %s!", The(distant_name(otmp, xname)), + life); + losexp("life drainage"); + if (magr && magr->mhp < magr->mhpmax) { + magr->mhp += (oldhpmax - u.uhpmax) / 2; + if (magr->mhp > magr->mhpmax) + magr->mhp = magr->mhpmax; + } + return TRUE; + } + } + return FALSE; } static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 }; - /* #invoke: an "ugly check" filters out most objects */ +/* #invoke: an "ugly check" filters out most objects */ int doinvoke() @@ -1313,227 +1385,250 @@ doinvoke() struct obj *obj; obj = getobj(invoke_types, "invoke"); - if (!obj) return 0; - if (!retouch_object(&obj, FALSE)) return 1; + if (!obj) + return 0; + if (!retouch_object(&obj, FALSE)) + return 1; return arti_invoke(obj); } STATIC_OVL int arti_invoke(obj) - register struct obj *obj; +register struct obj *obj; { register const struct artifact *oart = get_artifact(obj); - if(!oart || !oart->inv_prop) { - if(obj->otyp == CRYSTAL_BALL) - use_crystal_ball(obj); - else - pline1(nothing_happens); - return 1; + if (!oart || !oart->inv_prop) { + if (obj->otyp == CRYSTAL_BALL) + use_crystal_ball(obj); + else + pline1(nothing_happens); + return 1; } - if(oart->inv_prop > LAST_PROP) { - /* It's a special power, not "just" a property */ - if(obj->age > monstermoves) { - /* the artifact is tired :-) */ - You_feel("that %s %s ignoring you.", - the(xname(obj)), otense(obj, "are")); - /* and just got more so; patience is essential... */ - obj->age += (long) d(3,10); - return 1; - } - obj->age = monstermoves + rnz(100); + if (oart->inv_prop > LAST_PROP) { + /* It's a special power, not "just" a property */ + if (obj->age > monstermoves) { + /* the artifact is tired :-) */ + You_feel("that %s %s ignoring you.", the(xname(obj)), + otense(obj, "are")); + /* and just got more so; patience is essential... */ + obj->age += (long) d(3, 10); + return 1; + } + obj->age = monstermoves + rnz(100); - switch(oart->inv_prop) { - case TAMING: { - struct obj pseudo; + switch (oart->inv_prop) { + case TAMING: { + struct obj pseudo; - pseudo = zeroobj; /* neither cursed nor blessed, zero oextra too */ - pseudo.otyp = SCR_TAMING; - (void) seffects(&pseudo); - break; - } - case HEALING: { - int healamt = (u.uhpmax + 1 - u.uhp) / 2; - long creamed = (long)u.ucreamed; + pseudo = + zeroobj; /* neither cursed nor blessed, zero oextra too */ + pseudo.otyp = SCR_TAMING; + (void) seffects(&pseudo); + break; + } + case HEALING: { + int healamt = (u.uhpmax + 1 - u.uhp) / 2; + long creamed = (long) u.ucreamed; - if (Upolyd) healamt = (u.mhmax + 1 - u.mh) / 2; - if (healamt || Sick || Slimed || Blinded > creamed) - You_feel("better."); - else - goto nothing_special; - if (healamt > 0) { - if (Upolyd) u.mh += healamt; - else u.uhp += healamt; - } - if(Sick) make_sick(0L,(char *)0,FALSE,SICK_ALL); - if(Slimed) make_slimed(0L, (char *)0); - if (Blinded > creamed) make_blinded(creamed, FALSE); - context.botl = 1; - break; - } - case ENERGY_BOOST: { - int epboost = (u.uenmax + 1 - u.uen) / 2; - if (epboost > 120) epboost = 120; /* arbitrary */ - else if (epboost < 12) epboost = u.uenmax - u.uen; - if(epboost) { - You_feel("re-energized."); - u.uen += epboost; - context.botl = 1; - } else - goto nothing_special; - break; - } - case UNTRAP: { - if(!untrap(TRUE)) { - obj->age = 0; /* don't charge for changing their mind */ - return 0; - } - break; - } - case CHARGE_OBJ: { - struct obj *otmp = getobj(recharge_type, "charge"); - boolean b_effect; + if (Upolyd) + healamt = (u.mhmax + 1 - u.mh) / 2; + if (healamt || Sick || Slimed || Blinded > creamed) + You_feel("better."); + else + goto nothing_special; + if (healamt > 0) { + if (Upolyd) + u.mh += healamt; + else + u.uhp += healamt; + } + if (Sick) + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + if (Slimed) + make_slimed(0L, (char *) 0); + if (Blinded > creamed) + make_blinded(creamed, FALSE); + context.botl = 1; + break; + } + case ENERGY_BOOST: { + int epboost = (u.uenmax + 1 - u.uen) / 2; + if (epboost > 120) + epboost = 120; /* arbitrary */ + else if (epboost < 12) + epboost = u.uenmax - u.uen; + if (epboost) { + You_feel("re-energized."); + u.uen += epboost; + context.botl = 1; + } else + goto nothing_special; + break; + } + case UNTRAP: { + if (!untrap(TRUE)) { + obj->age = 0; /* don't charge for changing their mind */ + return 0; + } + break; + } + case CHARGE_OBJ: { + struct obj *otmp = getobj(recharge_type, "charge"); + boolean b_effect; - if (!otmp) { - obj->age = 0; - return 0; - } - b_effect = obj->blessed && - (Role_switch == oart->role || !oart->role); - recharge(otmp, b_effect ? 1 : obj->cursed ? -1 : 0); - update_inventory(); - break; - } - case LEV_TELE: - level_tele(); - break; - case CREATE_PORTAL: { - int i, num_ok_dungeons, last_ok_dungeon = 0; - d_level newlev; - extern int n_dgns; /* from dungeon.c */ - winid tmpwin = create_nhwindow(NHW_MENU); - anything any; + if (!otmp) { + obj->age = 0; + return 0; + } + b_effect = + obj->blessed && (Role_switch == oart->role || !oart->role); + recharge(otmp, b_effect ? 1 : obj->cursed ? -1 : 0); + update_inventory(); + break; + } + case LEV_TELE: + level_tele(); + break; + case CREATE_PORTAL: { + int i, num_ok_dungeons, last_ok_dungeon = 0; + d_level newlev; + extern int n_dgns; /* from dungeon.c */ + winid tmpwin = create_nhwindow(NHW_MENU); + anything any; - any = zeroany; /* set all bits to zero */ - start_menu(tmpwin); - /* use index+1 (cant use 0) as identifier */ - for (i = num_ok_dungeons = 0; i < n_dgns; i++) { - if (!dungeons[i].dunlev_ureached) continue; - any.a_int = i+1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - dungeons[i].dname, MENU_UNSELECTED); - num_ok_dungeons++; - last_ok_dungeon = i; - } - end_menu(tmpwin, "Open a portal to which dungeon?"); - if (num_ok_dungeons > 1) { - /* more than one entry; display menu for choices */ - menu_item *selected; - int n; + any = zeroany; /* set all bits to zero */ + start_menu(tmpwin); + /* use index+1 (cant use 0) as identifier */ + for (i = num_ok_dungeons = 0; i < n_dgns; i++) { + if (!dungeons[i].dunlev_ureached) + continue; + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + dungeons[i].dname, MENU_UNSELECTED); + num_ok_dungeons++; + last_ok_dungeon = i; + } + end_menu(tmpwin, "Open a portal to which dungeon?"); + if (num_ok_dungeons > 1) { + /* more than one entry; display menu for choices */ + menu_item *selected; + int n; - n = select_menu(tmpwin, PICK_ONE, &selected); - if (n <= 0) { - destroy_nhwindow(tmpwin); - goto nothing_special; - } - i = selected[0].item.a_int - 1; - free((genericptr_t)selected); - } else - i = last_ok_dungeon; /* also first & only OK dungeon */ - destroy_nhwindow(tmpwin); + n = select_menu(tmpwin, PICK_ONE, &selected); + if (n <= 0) { + destroy_nhwindow(tmpwin); + goto nothing_special; + } + i = selected[0].item.a_int - 1; + free((genericptr_t) selected); + } else + i = last_ok_dungeon; /* also first & only OK dungeon */ + destroy_nhwindow(tmpwin); - /* - * i is now index into dungeon structure for the new dungeon. - * Find the closest level in the given dungeon, open - * a use-once portal to that dungeon and go there. - * The closest level is either the entry or dunlev_ureached. - */ - newlev.dnum = i; - if(dungeons[i].depth_start >= depth(&u.uz)) - newlev.dlevel = dungeons[i].entry_lev; - else - newlev.dlevel = dungeons[i].dunlev_ureached; - if(u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) || - newlev.dnum == u.uz.dnum) { - You_feel("very disoriented for a moment."); - } else { - if(!Blind) You("are surrounded by a shimmering sphere!"); - else You_feel("weightless for a moment."); - goto_level(&newlev, FALSE, FALSE, FALSE); - } - break; - } - case ENLIGHTENING: - enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); - break; - case CREATE_AMMO: { - struct obj *otmp = mksobj(ARROW, TRUE, FALSE); + /* + * i is now index into dungeon structure for the new dungeon. + * Find the closest level in the given dungeon, open + * a use-once portal to that dungeon and go there. + * The closest level is either the entry or dunlev_ureached. + */ + newlev.dnum = i; + if (dungeons[i].depth_start >= depth(&u.uz)) + newlev.dlevel = dungeons[i].entry_lev; + else + newlev.dlevel = dungeons[i].dunlev_ureached; + if (u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) + || newlev.dnum == u.uz.dnum) { + You_feel("very disoriented for a moment."); + } else { + if (!Blind) + You("are surrounded by a shimmering sphere!"); + else + You_feel("weightless for a moment."); + goto_level(&newlev, FALSE, FALSE, FALSE); + } + break; + } + case ENLIGHTENING: + enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); + break; + case CREATE_AMMO: { + struct obj *otmp = mksobj(ARROW, TRUE, FALSE); - if (!otmp) goto nothing_special; - otmp->blessed = obj->blessed; - otmp->cursed = obj->cursed; - otmp->bknown = obj->bknown; - if (obj->blessed) { - if (otmp->spe < 0) otmp->spe = 0; - otmp->quan += rnd(10); - } else if (obj->cursed) { - if (otmp->spe > 0) otmp->spe = 0; - } else - otmp->quan += rnd(5); - otmp->owt = weight(otmp); - otmp = hold_another_object(otmp, "Suddenly %s out.", - aobjnam(otmp, "fall"), (const char *)0); - break; - } - } + if (!otmp) + goto nothing_special; + otmp->blessed = obj->blessed; + otmp->cursed = obj->cursed; + otmp->bknown = obj->bknown; + if (obj->blessed) { + if (otmp->spe < 0) + otmp->spe = 0; + otmp->quan += rnd(10); + } else if (obj->cursed) { + if (otmp->spe > 0) + otmp->spe = 0; + } else + otmp->quan += rnd(5); + otmp->owt = weight(otmp); + otmp = + hold_another_object(otmp, "Suddenly %s out.", + aobjnam(otmp, "fall"), (const char *) 0); + break; + } + } } else { - long eprop = (u.uprops[oart->inv_prop].extrinsic ^= W_ARTI), - iprop = u.uprops[oart->inv_prop].intrinsic; - boolean on = (eprop & W_ARTI) != 0; /* true if invoked prop just set */ + long eprop = (u.uprops[oart->inv_prop].extrinsic ^= W_ARTI), + iprop = u.uprops[oart->inv_prop].intrinsic; + boolean on = + (eprop & W_ARTI) != 0; /* true if invoked prop just set */ - if(on && obj->age > monstermoves) { - /* the artifact is tired :-) */ - u.uprops[oart->inv_prop].extrinsic ^= W_ARTI; - You_feel("that %s %s ignoring you.", - the(xname(obj)), otense(obj, "are")); - /* can't just keep repeatedly trying */ - obj->age += (long) d(3,10); - return 1; - } else if(!on) { - /* when turning off property, determine downtime */ - /* arbitrary for now until we can tune this -dlc */ - obj->age = monstermoves + rnz(100); - } + if (on && obj->age > monstermoves) { + /* the artifact is tired :-) */ + u.uprops[oart->inv_prop].extrinsic ^= W_ARTI; + You_feel("that %s %s ignoring you.", the(xname(obj)), + otense(obj, "are")); + /* can't just keep repeatedly trying */ + obj->age += (long) d(3, 10); + return 1; + } else if (!on) { + /* when turning off property, determine downtime */ + /* arbitrary for now until we can tune this -dlc */ + obj->age = monstermoves + rnz(100); + } - if ((eprop & ~W_ARTI) || iprop) { -nothing_special: - /* you had the property from some other source too */ - if (carried(obj)) - You_feel("a surge of power, but nothing seems to happen."); - return 1; - } - switch(oart->inv_prop) { - case CONFLICT: - if(on) You_feel("like a rabble-rouser."); - else You_feel("the tension decrease around you."); - break; - case LEVITATION: - if(on) { - float_up(); - spoteffects(FALSE); - } else (void) float_down(I_SPECIAL|TIMEOUT, W_ARTI); - break; - case INVIS: - if (BInvis || Blind) goto nothing_special; - newsym(u.ux, u.uy); - if (on) - Your("body takes on a %s transparency...", - Hallucination ? "normal" : "strange"); - else - Your("body seems to unfade..."); - break; - } + if ((eprop & ~W_ARTI) || iprop) { + nothing_special: + /* you had the property from some other source too */ + if (carried(obj)) + You_feel("a surge of power, but nothing seems to happen."); + return 1; + } + switch (oart->inv_prop) { + case CONFLICT: + if (on) + You_feel("like a rabble-rouser."); + else + You_feel("the tension decrease around you."); + break; + case LEVITATION: + if (on) { + float_up(); + spoteffects(FALSE); + } else + (void) float_down(I_SPECIAL | TIMEOUT, W_ARTI); + break; + case INVIS: + if (BInvis || Blind) + goto nothing_special; + newsym(u.ux, u.uy); + if (on) + Your("body takes on a %s transparency...", + Hallucination ? "normal" : "strange"); + else + Your("body seems to unfade..."); + break; + } } return 1; @@ -1550,9 +1645,9 @@ struct obj *obj; /* if we aren't levitating or this isn't an artifact which confers levitation via #invoke then freeinv() won't toggle levitation */ - if (!Levitation || (oart = get_artifact(obj)) == 0 || - oart->inv_prop != LEVITATION || !(ELevitation & W_ARTI)) - return FALSE; + if (!Levitation || (oart = get_artifact(obj)) == 0 + || oart->inv_prop != LEVITATION || !(ELevitation & W_ARTI)) + return FALSE; /* arti_invoke(off) -> float_down() clears I_SPECIAL|TIMEOUT & W_ARTI; probe ahead to see whether that actually results in floating down; @@ -1560,9 +1655,9 @@ struct obj *obj; both conferring levitation--safe, since if there were two of them, invoking the 2nd would negate the 1st rather than stack with it) */ save_Lev = u.uprops[LEVITATION]; - HLevitation &= ~(I_SPECIAL|TIMEOUT); + HLevitation &= ~(I_SPECIAL | TIMEOUT); ELevitation &= ~W_ARTI; - result = (boolean)!Levitation; + result = (boolean) !Levitation; u.uprops[LEVITATION] = save_Lev; return result; } @@ -1570,7 +1665,7 @@ struct obj *obj; /* WAC return TRUE if artifact is always lit */ boolean artifact_light(obj) - struct obj *obj; +struct obj *obj; { return (get_artifact(obj) && obj->oartifact == ART_SUNSWORD); } @@ -1578,23 +1673,22 @@ artifact_light(obj) /* KMH -- Talking artifacts are finally implemented */ void arti_speak(obj) - struct obj *obj; +struct obj *obj; { - register const struct artifact *oart = get_artifact(obj); - const char *line; - char buf[BUFSZ]; + register const struct artifact *oart = get_artifact(obj); + const char *line; + char buf[BUFSZ]; + /* Is this a speaking artifact? */ + if (!oart || !(oart->spfx & SPFX_SPEAK)) + return; - /* Is this a speaking artifact? */ - if (!oart || !(oart->spfx & SPFX_SPEAK)) - return; - - line = getrumor(bcsign(obj), buf, TRUE); - if (!*line) - line = "NetHack rumors file closed for renovation."; - pline("%s:", Tobjnam(obj, "whisper")); - verbalize1(line); - return; + line = getrumor(bcsign(obj), buf, TRUE); + if (!*line) + line = "NetHack rumors file closed for renovation."; + pline("%s:", Tobjnam(obj, "whisper")); + verbalize1(line); + return; } boolean @@ -1602,9 +1696,9 @@ artifact_has_invprop(otmp, inv_prop) struct obj *otmp; uchar inv_prop; { - const struct artifact *arti = get_artifact(otmp); + const struct artifact *arti = get_artifact(otmp); - return((boolean)(arti && (arti->inv_prop == inv_prop))); + return ((boolean)(arti && (arti->inv_prop == inv_prop))); } /* Return the price sold to the hero of a given artifact or unique item */ @@ -1612,66 +1706,66 @@ long arti_cost(otmp) struct obj *otmp; { - if (!otmp->oartifact) - return ((long)objects[otmp->otyp].oc_cost); - else if (artilist[(int) otmp->oartifact].cost) - return (artilist[(int) otmp->oartifact].cost); - else - return (100L * (long)objects[otmp->otyp].oc_cost); + if (!otmp->oartifact) + return ((long) objects[otmp->otyp].oc_cost); + else if (artilist[(int) otmp->oartifact].cost) + return (artilist[(int) otmp->oartifact].cost); + else + return (100L * (long) objects[otmp->otyp].oc_cost); } STATIC_OVL uchar abil_to_adtyp(abil) long *abil; { - struct abil2adtyp_tag { - long *abil; - uchar adtyp; - } abil2adtyp[] = { - {&EFire_resistance, AD_FIRE}, - {&ECold_resistance, AD_COLD}, - {&EShock_resistance, AD_ELEC}, - {&EAntimagic, AD_MAGM}, - {&EDisint_resistance, AD_DISN}, - {&EPoison_resistance, AD_DRST}, - }; - int k; + struct abil2adtyp_tag { + long *abil; + uchar adtyp; + } abil2adtyp[] = { + { &EFire_resistance, AD_FIRE }, + { &ECold_resistance, AD_COLD }, + { &EShock_resistance, AD_ELEC }, + { &EAntimagic, AD_MAGM }, + { &EDisint_resistance, AD_DISN }, + { &EPoison_resistance, AD_DRST }, + }; + int k; - for (k = 0; k < SIZE(abil2adtyp); k++) { - if (abil2adtyp[k].abil == abil) - return abil2adtyp[k].adtyp; - } - return 0; + for (k = 0; k < SIZE(abil2adtyp); k++) { + if (abil2adtyp[k].abil == abil) + return abil2adtyp[k].adtyp; + } + return 0; } STATIC_OVL unsigned long abil_to_spfx(abil) long *abil; { - static const struct abil2spfx_tag { - long *abil; - unsigned long spfx; - } abil2spfx[] = { - {&ESearching, SPFX_SEARCH}, - {&EHalluc_resistance, SPFX_HALRES}, - {&ETelepat, SPFX_ESP}, - {&EStealth, SPFX_STLTH}, - {&ERegeneration, SPFX_REGEN}, - {&ETeleport_control, SPFX_TCTRL}, - {&EWarn_of_mon, SPFX_WARN}, - {&EWarning, SPFX_WARN}, - {&EEnergy_regeneration, SPFX_EREGEN}, - {&EHalf_spell_damage, SPFX_HSPDAM}, - {&EHalf_physical_damage, SPFX_HPHDAM}, - {&EReflecting, SPFX_REFLECT}, - }; - int k; + static const struct abil2spfx_tag { + long *abil; + unsigned long spfx; + } abil2spfx[] = { + { &ESearching, SPFX_SEARCH }, + { &EHalluc_resistance, SPFX_HALRES }, + { &ETelepat, SPFX_ESP }, + { &EStealth, SPFX_STLTH }, + { &ERegeneration, SPFX_REGEN }, + { &ETeleport_control, SPFX_TCTRL }, + { &EWarn_of_mon, SPFX_WARN }, + { &EWarning, SPFX_WARN }, + { &EEnergy_regeneration, SPFX_EREGEN }, + { &EHalf_spell_damage, SPFX_HSPDAM }, + { &EHalf_physical_damage, SPFX_HPHDAM }, + { &EReflecting, SPFX_REFLECT }, + }; + int k; - for (k = 0; k < SIZE(abil2spfx); k++) { - if (abil2spfx[k].abil == abil) - return abil2spfx[k].spfx; - } - return 0L; + for (k = 0; k < SIZE(abil2spfx); k++) { + if (abil2spfx[k].abil == abil) + return abil2spfx[k].spfx; + } + return 0L; } /* @@ -1682,48 +1776,50 @@ struct obj * what_gives(abil) long *abil; { - struct obj *obj; - uchar dtyp; - unsigned long spfx; - long wornbits; - long wornmask = (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF | - W_WEP | W_QUIVER | W_SWAPWEP | W_ART | W_ARTI | W_AMUL | - W_RINGL | W_RINGR | W_TOOL | W_BALL | W_CHAIN | W_SADDLE | W_ARMU); + struct obj *obj; + uchar dtyp; + unsigned long spfx; + long wornbits; + long wornmask = + (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF | W_WEP | W_QUIVER + | W_SWAPWEP | W_ART | W_ARTI | W_AMUL | W_RINGL | W_RINGR | W_TOOL + | W_BALL | W_CHAIN | W_SADDLE | W_ARMU); - dtyp = abil_to_adtyp(abil); - spfx = abil_to_spfx(abil); - wornbits = (wornmask & *abil); + dtyp = abil_to_adtyp(abil); + spfx = abil_to_spfx(abil); + wornbits = (wornmask & *abil); - for(obj = invent; obj; obj = obj->nobj) { - if(obj->oartifact && ((abil != &EWarn_of_mon) || context.warntype.obj)) { - register const struct artifact *art = get_artifact(obj); - if (art) { - if (dtyp && - (art->cary.adtyp == dtyp || art->defn.adtyp == dtyp)) - return obj; - if (spfx && ((art->cspfx & spfx) == spfx || - (art->spfx & spfx) == spfx)) - return obj; - } - } else { - if (wornbits && wornbits == (wornmask & obj->owornmask)) - return obj; - } - } - return (struct obj *)0; + for (obj = invent; obj; obj = obj->nobj) { + if (obj->oartifact + && ((abil != &EWarn_of_mon) || context.warntype.obj)) { + register const struct artifact *art = get_artifact(obj); + if (art) { + if (dtyp + && (art->cary.adtyp == dtyp || art->defn.adtyp == dtyp)) + return obj; + if (spfx && ((art->cspfx & spfx) == spfx + || (art->spfx & spfx) == spfx)) + return obj; + } + } else { + if (wornbits && wornbits == (wornmask & obj->owornmask)) + return obj; + } + } + return (struct obj *) 0; } void Sting_effects(orc_count) int orc_count; { - if (uwep && uwep->oartifact == ART_STING) { - if (orc_count > 0 && warn_obj_cnt == 0) - pline("%s %s %s!", bare_artifactname(uwep), - otense(uwep,"glow"), hcolor(NH_LIGHT_BLUE)); - else if (orc_count == 0 && warn_obj_cnt > 0) - pline("%s stops glowing.", bare_artifactname(uwep)); - } + if (uwep && uwep->oartifact == ART_STING) { + if (orc_count > 0 && warn_obj_cnt == 0) + pline("%s %s %s!", bare_artifactname(uwep), otense(uwep, "glow"), + hcolor(NH_LIGHT_BLUE)); + else if (orc_count == 0 && warn_obj_cnt > 0) + pline("%s stops glowing.", bare_artifactname(uwep)); + } } /* called when hero is wielding/applying/invoking a carried item, or @@ -1731,62 +1827,67 @@ int orc_count; polymorph) which might affect item access */ int retouch_object(objp, loseit) -struct obj **objp; /* might be destroyed or unintentionally dropped */ -boolean loseit; /* whether to drop it if hero can longer touch it */ +struct obj **objp; /* might be destroyed or unintentionally dropped */ +boolean loseit; /* whether to drop it if hero can longer touch it */ { struct obj *obj = *objp; if (touch_artifact(obj, &youmonst)) { - char buf[BUFSZ]; - int dmg = 0, tmp; - boolean ag = (objects[obj->otyp].oc_material == SILVER && Hate_silver), - bane = bane_applies(get_artifact(obj), &youmonst); + char buf[BUFSZ]; + int dmg = 0, tmp; + boolean ag = + (objects[obj->otyp].oc_material == SILVER && Hate_silver), + bane = bane_applies(get_artifact(obj), &youmonst); - /* nothing else to do if hero can successfully handle this object */ - if (!ag && !bane) - return 1; + /* nothing else to do if hero can successfully handle this object */ + if (!ag && !bane) + return 1; - /* hero can't handle this object, but didn't get touch_artifact()'s - " evades your grasp|control" message; give an alternate one */ - You_cant("handle %s%s!", - yname(obj), obj->owornmask ? " anymore" : ""); - /* also inflict damage unless touch_artifact() already did so */ - if (!touch_blasted) { - /* damage is somewhat arbitrary; half the usual 1d20 physical - for silver, 1d10 magical for bane, potentially both */ - if (ag) tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); - if (bane) dmg += rnd(10); - Sprintf(buf, "handling %s", killer_xname(obj)); - losehp(dmg, buf, KILLED_BY); - exercise(A_CON, FALSE); - } + /* hero can't handle this object, but didn't get touch_artifact()'s + " evades your grasp|control" message; give an alternate one */ + You_cant("handle %s%s!", yname(obj), + obj->owornmask ? " anymore" : ""); + /* also inflict damage unless touch_artifact() already did so */ + if (!touch_blasted) { + /* damage is somewhat arbitrary; half the usual 1d20 physical + for silver, 1d10 magical for bane, potentially both */ + if (ag) + tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); + if (bane) + dmg += rnd(10); + Sprintf(buf, "handling %s", killer_xname(obj)); + losehp(dmg, buf, KILLED_BY); + exercise(A_CON, FALSE); + } } /* removing a worn item might result in loss of levitation, dropping the hero onto a polymorph trap or into water or lava and potentially dropping or destroying the item */ if (obj->owornmask) { - struct obj *otmp; + struct obj *otmp; - remove_worn_item(obj, FALSE); - for (otmp = invent; otmp; otmp = otmp->nobj) - if (otmp == obj) break; - if (!otmp) *objp = obj = 0; + remove_worn_item(obj, FALSE); + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp == obj) + break; + if (!otmp) + *objp = obj = 0; } /* if we still have it and caller wants us to drop it, do so now */ if (loseit && obj) { - if (Levitation) { - freeinv(obj); - hitfloor(obj); - } else { - /* dropx gives a message iff item lands on an altar */ - if (!IS_ALTAR(levl[u.ux][u.uy].typ)) - pline("%s to the %s.", - Tobjnam(obj, "fall"), surface(u.ux, u.uy)); - dropx(obj); - } - *objp = obj = 0; /* no longer in inventory */ + if (Levitation) { + freeinv(obj); + hitfloor(obj); + } else { + /* dropx gives a message iff item lands on an altar */ + if (!IS_ALTAR(levl[u.ux][u.uy].typ)) + pline("%s to the %s.", Tobjnam(obj, "fall"), + surface(u.ux, u.uy)); + dropx(obj); + } + *objp = obj = 0; /* no longer in inventory */ } return 0; } @@ -1805,30 +1906,30 @@ boolean drop_untouchable; long wearmask = ~(W_QUIVER | (u.twoweap ? 0L : W_SWAPWEP) | W_BALL); beingworn = (obj->owornmask & wearmask) != 0L || - /* some items in use don't have any wornmask setting */ - (obj->oclass == TOOL_CLASS && - (obj->lamplit || - (obj->otyp == LEASH && obj->leashmon) || - (Is_container(obj) && Has_contents(obj)))); + /* some items in use don't have any wornmask setting */ + (obj->oclass == TOOL_CLASS + && (obj->lamplit || (obj->otyp == LEASH && obj->leashmon) + || (Is_container(obj) && Has_contents(obj)))); if ((art = get_artifact(obj)) != 0) { - carryeffect = (art->cary.adtyp || art->cspfx); - invoked = (art->inv_prop > 0 && art->inv_prop <= LAST_PROP && - (u.uprops[art->inv_prop].extrinsic & W_ARTI) != 0L); + carryeffect = (art->cary.adtyp || art->cspfx); + invoked = (art->inv_prop > 0 && art->inv_prop <= LAST_PROP + && (u.uprops[art->inv_prop].extrinsic & W_ARTI) != 0L); } else { - carryeffect = invoked = FALSE; + carryeffect = invoked = FALSE; } if (beingworn || carryeffect || invoked) { - if (!retouch_object(&obj, drop_untouchable)) { - /* " is beyond your control" or "you can't handle - " has been given and it is now unworn/unwielded - and possibly dropped (depending upon caller); if dropped, - carried effect was turned off, else we leave that alone; - we turn off invocation property here if still carried */ - if (invoked && obj) arti_invoke(obj); /* reverse #invoke */ - return TRUE; - } + if (!retouch_object(&obj, drop_untouchable)) { + /* " is beyond your control" or "you can't handle + " has been given and it is now unworn/unwielded + and possibly dropped (depending upon caller); if dropped, + carried effect was turned off, else we leave that alone; + we turn off invocation property here if still carried */ + if (invoked && obj) + arti_invoke(obj); /* reverse #invoke */ + return TRUE; + } } return FALSE; } @@ -1836,9 +1937,9 @@ boolean drop_untouchable; /* check all items currently in use (mostly worn) for touchability */ void retouch_equipment(dropflag) -int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ +int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ { - static int nesting = 0; /* recursion control */ + static int nesting = 0; /* recursion control */ struct obj *obj; boolean dropit, had_gloves = (uarmg != 0); int had_rings = (!!uleft + !!uright); @@ -1854,20 +1955,24 @@ int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ * using the non-helm alignment rather than the helm alignment * which triggered this in the first place. */ - if (!nesting++) clear_bypasses(); /* init upon initial entry */ + if (!nesting++) + clear_bypasses(); /* init upon initial entry */ - dropit = (dropflag > 0); /* drop all or drop weapon */ + dropit = (dropflag > 0); /* drop all or drop weapon */ /* check secondary weapon first, before possibly unwielding primary */ - if (u.twoweap) (void)untouchable(uswapwep, dropit); + if (u.twoweap) + (void) untouchable(uswapwep, dropit); /* check primary weapon next so that they're handled together */ - if (uwep) (void)untouchable(uwep, dropit); + if (uwep) + (void) untouchable(uwep, dropit); /* in case someone is daft enough to add artifact or silver saddle */ if (u.usteed && (obj = which_armor(u.usteed, W_SADDLE)) != 0) { - /* untouchable() calls retouch_object() which expects an object in - hero's inventory, but remove_worn_item() will be harmless for - saddle and we're suppressing drop, so this works as intended */ - if (untouchable(obj, FALSE)) dismount_steed(DISMOUNT_THROWN); + /* untouchable() calls retouch_object() which expects an object in + hero's inventory, but remove_worn_item() will be harmless for + saddle and we're suppressing drop, so this works as intended */ + if (untouchable(obj, FALSE)) + dismount_steed(DISMOUNT_THROWN); } /* * TODO? Force off gloves if either or both rings are going to @@ -1876,20 +1981,22 @@ int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ * not, due to the possibility of unwearing silver rings. */ - dropit = (dropflag == 1); /* all untouchable items */ + dropit = (dropflag == 1); /* all untouchable items */ /* loss of levitation (silver ring, or Heart of Ahriman invocation) might cause hero to lose inventory items (by dropping into lava, for instance), so inventory traversal needs to rescan the whole invent chain each time it moves on to another object; we use bypass handling to keep track of which items have already been processed */ while ((obj = nxt_unbypassed_obj(invent)) != 0) - (void) untouchable(obj, dropit); + (void) untouchable(obj, dropit); if (had_rings != (!!uleft + !!uright) && uarmg && uarmg->cursed) - uncurse(uarmg); /* temporary? hack for ring removal plausibility */ - if (had_gloves && !uarmg) selftouch("After losing your gloves, you"); + uncurse(uarmg); /* temporary? hack for ring removal plausibility */ + if (had_gloves && !uarmg) + selftouch("After losing your gloves, you"); - if (!--nesting) clear_bypasses(); /* reset upon final exit */ + if (!--nesting) + clear_bypasses(); /* reset upon final exit */ } /*artifact.c*/ diff --git a/src/attrib.c b/src/attrib.c index d67658d7a..89db30460 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 attrib.c $NHDT-Date: 1426465433 2015/03/16 00:23:53 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.34 $ */ +/* NetHack 3.6 attrib.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.45 $ */ /* NetHack 3.6 attrib.c $Date: 2011/10/01 00:25:55 $ $Revision: 1.30 $ */ /* Copyright 1988, 1989, 1990, 1992, M. Stephenson */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,154 +8,147 @@ #include "hack.h" #include - /* part of the output on gain or loss of attribute */ -static -const char * const plusattr[] = { - "strong", "smart", "wise", "agile", "tough", "charismatic" -}, - * const minusattr[] = { - "weak", "stupid", "foolish", "clumsy", "fragile", "repulsive" -}; +/* part of the output on gain or loss of attribute */ +static const char *const plusattr[] = { "strong", "smart", "wise", + "agile", "tough", "charismatic" }, + *const minusattr[] = { "weak", "stupid", + "foolish", "clumsy", + "fragile", "repulsive" }; +static const struct innate { + schar ulevel; + long *ability; + const char *gainstr, *losestr; +} arc_abil[] = { { 1, &(HStealth), "", "" }, + { 1, &(HFast), "", "" }, + { 10, &(HSearching), "perceptive", "" }, + { 0, 0, 0, 0 } }, -static -const struct innate { - schar ulevel; - long *ability; - const char *gainstr, *losestr; -} arc_abil[] = { { 1, &(HStealth), "", "" }, - { 1, &(HFast), "", "" }, - { 10, &(HSearching), "perceptive", "" }, - { 0, 0, 0, 0 } }, + bar_abil[] = { { 1, &(HPoison_resistance), "", "" }, + { 7, &(HFast), "quick", "slow" }, + { 15, &(HStealth), "stealthy", "" }, + { 0, 0, 0, 0 } }, - bar_abil[] = { { 1, &(HPoison_resistance), "", "" }, - { 7, &(HFast), "quick", "slow" }, - { 15, &(HStealth), "stealthy", "" }, - { 0, 0, 0, 0 } }, + cav_abil[] = { { 7, &(HFast), "quick", "slow" }, + { 15, &(HWarning), "sensitive", "" }, + { 0, 0, 0, 0 } }, - cav_abil[] = { { 7, &(HFast), "quick", "slow" }, - { 15, &(HWarning), "sensitive", "" }, - { 0, 0, 0, 0 } }, + hea_abil[] = { { 1, &(HPoison_resistance), "", "" }, + { 15, &(HWarning), "sensitive", "" }, + { 0, 0, 0, 0 } }, - hea_abil[] = { { 1, &(HPoison_resistance), "", "" }, - { 15, &(HWarning), "sensitive", "" }, - { 0, 0, 0, 0 } }, + kni_abil[] = { { 7, &(HFast), "quick", "slow" }, { 0, 0, 0, 0 } }, - kni_abil[] = { { 7, &(HFast), "quick", "slow" }, - { 0, 0, 0, 0 } }, + mon_abil[] = { { 1, &(HFast), "", "" }, + { 1, &(HSleep_resistance), "", "" }, + { 1, &(HSee_invisible), "", "" }, + { 3, &(HPoison_resistance), "healthy", "" }, + { 5, &(HStealth), "stealthy", "" }, + { 7, &(HWarning), "sensitive", "" }, + { 9, &(HSearching), "perceptive", "unaware" }, + { 11, &(HFire_resistance), "cool", "warmer" }, + { 13, &(HCold_resistance), "warm", "cooler" }, + { 15, &(HShock_resistance), "insulated", "conductive" }, + { 17, &(HTeleport_control), "controlled", "uncontrolled" }, + { 0, 0, 0, 0 } }, - mon_abil[] = { { 1, &(HFast), "", "" }, - { 1, &(HSleep_resistance), "", "" }, - { 1, &(HSee_invisible), "", "" }, - { 3, &(HPoison_resistance), "healthy", "" }, - { 5, &(HStealth), "stealthy", "" }, - { 7, &(HWarning), "sensitive", "" }, - { 9, &(HSearching), "perceptive", "unaware" }, - { 11, &(HFire_resistance), "cool", "warmer" }, - { 13, &(HCold_resistance), "warm", "cooler" }, - { 15, &(HShock_resistance), "insulated", "conductive" }, - { 17, &(HTeleport_control), "controlled","uncontrolled" }, - { 0, 0, 0, 0 } }, + pri_abil[] = { { 15, &(HWarning), "sensitive", "" }, + { 20, &(HFire_resistance), "cool", "warmer" }, + { 0, 0, 0, 0 } }, - pri_abil[] = { { 15, &(HWarning), "sensitive", "" }, - { 20, &(HFire_resistance), "cool", "warmer" }, - { 0, 0, 0, 0 } }, + ran_abil[] = { { 1, &(HSearching), "", "" }, + { 7, &(HStealth), "stealthy", "" }, + { 15, &(HSee_invisible), "", "" }, + { 0, 0, 0, 0 } }, - ran_abil[] = { { 1, &(HSearching), "", "" }, - { 7, &(HStealth), "stealthy", "" }, - { 15, &(HSee_invisible), "", "" }, - { 0, 0, 0, 0 } }, + rog_abil[] = { { 1, &(HStealth), "", "" }, + { 10, &(HSearching), "perceptive", "" }, + { 0, 0, 0, 0 } }, - rog_abil[] = { { 1, &(HStealth), "", "" }, - { 10, &(HSearching), "perceptive", "" }, - { 0, 0, 0, 0 } }, + sam_abil[] = { { 1, &(HFast), "", "" }, + { 15, &(HStealth), "stealthy", "" }, + { 0, 0, 0, 0 } }, - sam_abil[] = { { 1, &(HFast), "", "" }, - { 15, &(HStealth), "stealthy", "" }, - { 0, 0, 0, 0 } }, + tou_abil[] = { { 10, &(HSearching), "perceptive", "" }, + { 20, &(HPoison_resistance), "hardy", "" }, + { 0, 0, 0, 0 } }, - tou_abil[] = { { 10, &(HSearching), "perceptive", "" }, - { 20, &(HPoison_resistance), "hardy", "" }, - { 0, 0, 0, 0 } }, + val_abil[] = { { 1, &(HCold_resistance), "", "" }, + { 1, &(HStealth), "", "" }, + { 7, &(HFast), "quick", "slow" }, + { 0, 0, 0, 0 } }, - val_abil[] = { { 1, &(HCold_resistance), "", "" }, - { 1, &(HStealth), "", "" }, - { 7, &(HFast), "quick", "slow" }, - { 0, 0, 0, 0 } }, + wiz_abil[] = { { 15, &(HWarning), "sensitive", "" }, + { 17, &(HTeleport_control), "controlled", "uncontrolled" }, + { 0, 0, 0, 0 } }, - wiz_abil[] = { { 15, &(HWarning), "sensitive", "" }, - { 17, &(HTeleport_control), "controlled","uncontrolled" }, - { 0, 0, 0, 0 } }, + /* Intrinsics conferred by race */ + elf_abil[] = { { 4, &(HSleep_resistance), "awake", "tired" }, + { 0, 0, 0, 0 } }, - /* Intrinsics conferred by race */ - elf_abil[] = { { 4, &(HSleep_resistance), "awake", "tired" }, - { 0, 0, 0, 0 } }, - - orc_abil[] = { { 1, &(HPoison_resistance), "", "" }, - { 0, 0, 0, 0 } }; + orc_abil[] = { { 1, &(HPoison_resistance), "", "" }, { 0, 0, 0, 0 } }; STATIC_DCL void NDECL(exerper); STATIC_DCL void FDECL(postadjabil, (long *)); -STATIC_DCL const struct innate *FDECL(check_innate_abil,(long *, long)); +STATIC_DCL const struct innate *FDECL(check_innate_abil, (long *, long)); STATIC_DCL int FDECL(innately, (long *)); /* adjust an attribute; return TRUE if change is made, FALSE otherwise */ boolean adjattrib(ndx, incr, msgflg) - int ndx, incr; - int msgflg; /* positive => no message, zero => message, and */ -{ /* negative => conditional (msg if change made) */ - int old_acurr; - boolean abonflg; - const char *attrstr; +int ndx, incr; +int msgflg; /* positive => no message, zero => message, and */ +{ /* negative => conditional (msg if change made) */ + int old_acurr; + boolean abonflg; + const char *attrstr; - if (Fixed_abil || !incr) return FALSE; + if (Fixed_abil || !incr) + return FALSE; - if ((ndx == A_INT || ndx == A_WIS) - && uarmh && uarmh->otyp == DUNCE_CAP) { - if (msgflg == 0) - Your("cap constricts briefly, then relaxes again."); - return FALSE; - } + if ((ndx == A_INT || ndx == A_WIS) && uarmh && uarmh->otyp == DUNCE_CAP) { + if (msgflg == 0) + Your("cap constricts briefly, then relaxes again."); + return FALSE; + } - old_acurr = ACURR(ndx); - if (incr > 0) { - ABASE(ndx) += incr; - if (ABASE(ndx) > AMAX(ndx)) { - incr = ABASE(ndx) - AMAX(ndx); - AMAX(ndx) += incr; - if (AMAX(ndx) > ATTRMAX(ndx)) - AMAX(ndx) = ATTRMAX(ndx); - ABASE(ndx) = AMAX(ndx); - } - attrstr = plusattr[ndx]; - abonflg = (ABON(ndx) < 0); - } else { - ABASE(ndx) += incr; - if (ABASE(ndx) < ATTRMIN(ndx)) { - incr = ABASE(ndx) - ATTRMIN(ndx); - ABASE(ndx) = ATTRMIN(ndx); - AMAX(ndx) += incr; - if (AMAX(ndx) < ATTRMIN(ndx)) - AMAX(ndx) = ATTRMIN(ndx); - } - attrstr = minusattr[ndx]; - abonflg = (ABON(ndx) > 0); - } - if (ACURR(ndx) == old_acurr) { - if (msgflg == 0 && flags.verbose) - pline("You're %s as %s as you can get.", - abonflg ? "currently" : "already", attrstr); - return FALSE; - } + old_acurr = ACURR(ndx); + if (incr > 0) { + ABASE(ndx) += incr; + if (ABASE(ndx) > AMAX(ndx)) { + incr = ABASE(ndx) - AMAX(ndx); + AMAX(ndx) += incr; + if (AMAX(ndx) > ATTRMAX(ndx)) + AMAX(ndx) = ATTRMAX(ndx); + ABASE(ndx) = AMAX(ndx); + } + attrstr = plusattr[ndx]; + abonflg = (ABON(ndx) < 0); + } else { + ABASE(ndx) += incr; + if (ABASE(ndx) < ATTRMIN(ndx)) { + incr = ABASE(ndx) - ATTRMIN(ndx); + ABASE(ndx) = ATTRMIN(ndx); + AMAX(ndx) += incr; + if (AMAX(ndx) < ATTRMIN(ndx)) + AMAX(ndx) = ATTRMIN(ndx); + } + attrstr = minusattr[ndx]; + abonflg = (ABON(ndx) > 0); + } + if (ACURR(ndx) == old_acurr) { + if (msgflg == 0 && flags.verbose) + pline("You're %s as %s as you can get.", + abonflg ? "currently" : "already", attrstr); + return FALSE; + } - if (msgflg <= 0) - You_feel("%s%s!", - (incr > 1 || incr < -1) ? "very ": "", attrstr); - context.botl = 1; - if (moves > 1 && (ndx == A_STR || ndx == A_CON)) - (void)encumber_msg(); - return TRUE; + if (msgflg <= 0) + You_feel("%s%s!", (incr > 1 || incr < -1) ? "very " : "", attrstr); + context.botl = 1; + if (moves > 1 && (ndx == A_STR || ndx == A_CON)) + (void) encumber_msg(); + return TRUE; } void @@ -164,418 +157,465 @@ struct obj *otmp; int incr; boolean givemsg; { - int num = incr; + int num = incr; - if (!num) { - if (ABASE(A_STR) < 18) num = (rn2(4) ? 1 : rnd(6)); - else if (ABASE(A_STR) < STR18(85)) num = rnd(10); - else num = 1; - } - (void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num, - givemsg ? -1 : 1); + if (!num) { + if (ABASE(A_STR) < 18) + num = (rn2(4) ? 1 : rnd(6)); + else if (ABASE(A_STR) < STR18(85)) + num = rnd(10); + else + num = 1; + } + (void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num, + givemsg ? -1 : 1); } -void -losestr(num) /* may kill you; cause may be poison or monster like 'a' */ - register int num; +void losestr(num) /* may kill you; cause may be poison or monster like 'a' */ +register int num; { - int ustr = ABASE(A_STR) - num; + int ustr = ABASE(A_STR) - num; - while(ustr < 3) { - ++ustr; - --num; - if (Upolyd) { - u.mh -= 6; - u.mhmax -= 6; - } else { - u.uhp -= 6; - u.uhpmax -= 6; - } - } - (void) adjattrib(A_STR, -num, 1); + while (ustr < 3) { + ++ustr; + --num; + if (Upolyd) { + u.mh -= 6; + u.mhmax -= 6; + } else { + u.uhp -= 6; + u.uhpmax -= 6; + } + } + (void) adjattrib(A_STR, -num, 1); } static const struct poison_effect_message { - void VDECL((*delivery_func), (const char *,...)); + void VDECL((*delivery_func), (const char *, ...)); const char *effect_msg; } poiseff[] = { - { You_feel, "weaker" }, /* A_STR */ - { Your, "brain is on fire" }, /* A_INT */ - { Your, "judgement is impaired" }, /* A_WIS */ - { Your, "muscles won't obey you" }, /* A_DEX */ - { You_feel, "very sick" }, /* A_CON */ - { You, "break out in hives" } /* A_CHA */ + { You_feel, "weaker" }, /* A_STR */ + { Your, "brain is on fire" }, /* A_INT */ + { Your, "judgement is impaired" }, /* A_WIS */ + { Your, "muscles won't obey you" }, /* A_DEX */ + { You_feel, "very sick" }, /* A_CON */ + { You, "break out in hives" } /* A_CHA */ }; /* feedback for attribute loss due to poisoning */ void poisontell(typ, exclaim) -int typ; /* which attribute */ -boolean exclaim; /* emphasis */ +int typ; /* which attribute */ +boolean exclaim; /* emphasis */ { - void VDECL((*func), (const char *,...)) = poiseff[typ].delivery_func; + void VDECL((*func), (const char *, ...)) = poiseff[typ].delivery_func; (*func)("%s%c", poiseff[typ].effect_msg, exclaim ? '!' : '.'); } -/* called when an attack or trap has poisoned the hero (used to be in mon.c) */ +/* called when an attack or trap has poisoned the hero (used to be in mon.c) + */ void poisoned(reason, typ, pkiller, fatal, thrown_weapon) -const char *reason, /* controls what messages we display */ - *pkiller; /* for score+log file if fatal */ -int typ, fatal; /* if fatal is 0, limit damage to adjattrib */ -boolean thrown_weapon; /* thrown weapons are less deadly */ +const char *reason, /* controls what messages we display */ + *pkiller; /* for score+log file if fatal */ +int typ, fatal; /* if fatal is 0, limit damage to adjattrib */ +boolean thrown_weapon; /* thrown weapons are less deadly */ { - int i, loss, kprefix = KILLED_BY_AN; + int i, loss, kprefix = KILLED_BY_AN; - /* inform player about being poisoned unless that's already been done; - "blast" has given a "blast of poison gas" message; "poison arrow", - "poison dart", etc have implicitly given poison messages too... */ - if (strcmp(reason, "blast") && !strstri(reason, "poison")) { - boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0; + /* inform player about being poisoned unless that's already been done; + "blast" has given a "blast of poison gas" message; "poison arrow", + "poison dart", etc have implicitly given poison messages too... */ + if (strcmp(reason, "blast") && !strstri(reason, "poison")) { + boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0; - /* avoid "The" Orcus's sting was poisoned... */ - pline("%s%s %s poisoned!", - isupper(*reason) ? "" : "The ", reason, - plural ? "were" : "was"); - } - if (Poison_resistance) { - if (!strcmp(reason, "blast")) shieldeff(u.ux, u.uy); - pline_The("poison doesn't seem to affect you."); - return; - } + /* avoid "The" Orcus's sting was poisoned... */ + pline("%s%s %s poisoned!", isupper(*reason) ? "" : "The ", reason, + plural ? "were" : "was"); + } + if (Poison_resistance) { + if (!strcmp(reason, "blast")) + shieldeff(u.ux, u.uy); + pline_The("poison doesn't seem to affect you."); + return; + } - /* suppress killer prefix if it already has one */ - i = name_to_mon(pkiller); - if (i >= LOW_PM && (mons[i].geno & G_UNIQ)) { - kprefix = KILLED_BY; - if (!type_is_pname(&mons[i])) pkiller = the(pkiller); - } else if (!strncmpi(pkiller, "the ", 4) || - !strncmpi(pkiller, "an ", 3) || - !strncmpi(pkiller, "a ", 2)) { - /*[ does this need a plural check too? ]*/ - kprefix = KILLED_BY; - } + /* suppress killer prefix if it already has one */ + i = name_to_mon(pkiller); + if (i >= LOW_PM && (mons[i].geno & G_UNIQ)) { + kprefix = KILLED_BY; + if (!type_is_pname(&mons[i])) + pkiller = the(pkiller); + } else if (!strncmpi(pkiller, "the ", 4) || !strncmpi(pkiller, "an ", 3) + || !strncmpi(pkiller, "a ", 2)) { + /*[ does this need a plural check too? ]*/ + kprefix = KILLED_BY; + } - i = !fatal ? 1 : rn2(fatal + (thrown_weapon ? 20 : 0)); - if (i == 0 && typ != A_CHA) { - /* instant kill */ - u.uhp = -1; - pline_The("poison was deadly..."); - } else if (i > 5) { - /* HP damage; more likely--but less severe--with missiles */ - loss = thrown_weapon ? rnd(6) : rn1(10,6); - losehp(loss, pkiller, kprefix); /* poison damage */ - } else { - /* attribute loss; if typ is A_STR, reduction in current and - maximum HP will occur once strength has dropped down to 3 */ - loss = (thrown_weapon || !fatal) ? 1 : d(2, 2); /* was rn1(3,3) */ - /* check that a stat change was made */ - if (adjattrib(typ, -loss, 1)) - poisontell(typ, TRUE); - } + i = !fatal ? 1 : rn2(fatal + (thrown_weapon ? 20 : 0)); + if (i == 0 && typ != A_CHA) { + /* instant kill */ + u.uhp = -1; + pline_The("poison was deadly..."); + } else if (i > 5) { + /* HP damage; more likely--but less severe--with missiles */ + loss = thrown_weapon ? rnd(6) : rn1(10, 6); + losehp(loss, pkiller, kprefix); /* poison damage */ + } else { + /* attribute loss; if typ is A_STR, reduction in current and + maximum HP will occur once strength has dropped down to 3 */ + loss = (thrown_weapon || !fatal) ? 1 : d(2, 2); /* was rn1(3,3) */ + /* check that a stat change was made */ + if (adjattrib(typ, -loss, 1)) + poisontell(typ, TRUE); + } - if (u.uhp < 1) { - killer.format = kprefix; - Strcpy(killer.name, pkiller); - /* "Poisoned by a poisoned ___" is redundant */ - done(strstri(pkiller, "poison") ? DIED : POISONING); - } - (void) encumber_msg(); + if (u.uhp < 1) { + killer.format = kprefix; + Strcpy(killer.name, pkiller); + /* "Poisoned by a poisoned ___" is redundant */ + done(strstri(pkiller, "poison") ? DIED : POISONING); + } + (void) encumber_msg(); } void change_luck(n) - register schar n; +register schar n; { - u.uluck += n; - if (u.uluck < 0 && u.uluck < LUCKMIN) u.uluck = LUCKMIN; - if (u.uluck > 0 && u.uluck > LUCKMAX) u.uluck = LUCKMAX; + u.uluck += n; + if (u.uluck < 0 && u.uluck < LUCKMIN) + u.uluck = LUCKMIN; + if (u.uluck > 0 && u.uluck > LUCKMAX) + u.uluck = LUCKMAX; } int stone_luck(parameter) boolean parameter; /* So I can't think up of a good name. So sue me. --KAA */ { - register struct obj *otmp; - register long bonchance = 0; + register struct obj *otmp; + register long bonchance = 0; - for (otmp = invent; otmp; otmp = otmp->nobj) - if (confers_luck(otmp)) { - if (otmp->cursed) bonchance -= otmp->quan; - else if (otmp->blessed) bonchance += otmp->quan; - else if (parameter) bonchance += otmp->quan; - } + for (otmp = invent; otmp; otmp = otmp->nobj) + if (confers_luck(otmp)) { + if (otmp->cursed) + bonchance -= otmp->quan; + else if (otmp->blessed) + bonchance += otmp->quan; + else if (parameter) + bonchance += otmp->quan; + } - return sgn((int)bonchance); + return sgn((int) bonchance); } /* there has just been an inventory change affecting a luck-granting item */ void set_moreluck() { - int luckbon = stone_luck(TRUE); + int luckbon = stone_luck(TRUE); - if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0; - else if (luckbon >= 0) u.moreluck = LUCKADD; - else u.moreluck = -LUCKADD; + if (!luckbon && !carrying(LUCKSTONE)) + u.moreluck = 0; + else if (luckbon >= 0) + u.moreluck = LUCKADD; + else + u.moreluck = -LUCKADD; } void restore_attrib() { - int i; + int i; - for(i = 0; i < A_MAX; i++) { /* all temporary losses/gains */ + for (i = 0; i < A_MAX; i++) { /* all temporary losses/gains */ - if(ATEMP(i) && ATIME(i)) { - if(!(--(ATIME(i)))) { /* countdown for change */ - ATEMP(i) += ATEMP(i) > 0 ? -1 : 1; + if (ATEMP(i) && ATIME(i)) { + if (!(--(ATIME(i)))) { /* countdown for change */ + ATEMP(i) += ATEMP(i) > 0 ? -1 : 1; - if(ATEMP(i)) /* reset timer */ - ATIME(i) = 100 / ACURR(A_CON); - } - } - } - (void)encumber_msg(); + if (ATEMP(i)) /* reset timer */ + ATIME(i) = 100 / ACURR(A_CON); + } + } + } + (void) encumber_msg(); } -#define AVAL 50 /* tune value for exercise gains */ +#define AVAL 50 /* tune value for exercise gains */ void exercise(i, inc_or_dec) -int i; -boolean inc_or_dec; +int i; +boolean inc_or_dec; { - debugpline0("Exercise:"); - if (i == A_INT || i == A_CHA) return; /* can't exercise these */ + debugpline0("Exercise:"); + if (i == A_INT || i == A_CHA) + return; /* can't exercise these */ - /* no physical exercise while polymorphed; the body's temporary */ - if (Upolyd && i != A_WIS) return; + /* no physical exercise while polymorphed; the body's temporary */ + if (Upolyd && i != A_WIS) + return; - if(abs(AEXE(i)) < AVAL) { - /* - * Law of diminishing returns (Part I): - * - * Gain is harder at higher attribute values. - * 79% at "3" --> 0% at "18" - * Loss is even at all levels (50%). - * - * Note: *YES* ACURR is the right one to use. - */ - AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2); - debugpline3("%s, %s AEXE = %d", - (i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" : - (i == A_DEX) ? "Dex" : "Con", - (inc_or_dec) ? "inc" : "dec", AEXE(i)); - } - if (moves > 0 && (i == A_STR || i == A_CON)) (void)encumber_msg(); + if (abs(AEXE(i)) < AVAL) { + /* + * Law of diminishing returns (Part I): + * + * Gain is harder at higher attribute values. + * 79% at "3" --> 0% at "18" + * Loss is even at all levels (50%). + * + * Note: *YES* ACURR is the right one to use. + */ + AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2); + debugpline3("%s, %s AEXE = %d", + (i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" : (i == A_DEX) + ? "Dex" + : "Con", + (inc_or_dec) ? "inc" : "dec", AEXE(i)); + } + if (moves > 0 && (i == A_STR || i == A_CON)) + (void) encumber_msg(); } STATIC_OVL void exerper() { - if(!(moves % 10)) { - /* Hunger Checks */ + if (!(moves % 10)) { + /* Hunger Checks */ - int hs = (u.uhunger > 1000) ? SATIATED : - (u.uhunger > 150) ? NOT_HUNGRY : - (u.uhunger > 50) ? HUNGRY : - (u.uhunger > 0) ? WEAK : FAINTING; + int hs = (u.uhunger > 1000) ? SATIATED : (u.uhunger > 150) + ? NOT_HUNGRY + : (u.uhunger > 50) + ? HUNGRY + : (u.uhunger > 0) + ? WEAK + : FAINTING; - debugpline0("exerper: Hunger checks"); - switch (hs) { - case SATIATED: exercise(A_DEX, FALSE); - if (Role_if(PM_MONK)) - exercise(A_WIS, FALSE); - break; - case NOT_HUNGRY: exercise(A_CON, TRUE); break; - case WEAK: exercise(A_STR, FALSE); - if (Role_if(PM_MONK)) /* fasting */ - exercise(A_WIS, TRUE); - break; - case FAINTING: - case FAINTED: exercise(A_CON, FALSE); break; - } - - /* Encumberance Checks */ - debugpline0("exerper: Encumber checks"); - switch (near_capacity()) { - case MOD_ENCUMBER: exercise(A_STR, TRUE); break; - case HVY_ENCUMBER: exercise(A_STR, TRUE); - exercise(A_DEX, FALSE); break; - case EXT_ENCUMBER: exercise(A_DEX, FALSE); - exercise(A_CON, FALSE); break; - } - - } - - /* status checks */ - if(!(moves % 5)) { - debugpline0("exerper: Status checks"); - if ((HClairvoyant & (INTRINSIC|TIMEOUT)) && - !BClairvoyant) exercise(A_WIS, TRUE); - if (HRegeneration) exercise(A_STR, TRUE); - - if(Sick || Vomiting) exercise(A_CON, FALSE); - if(Confusion || Hallucination) exercise(A_WIS, FALSE); - if((Wounded_legs && !u.usteed) || Fumbling || HStun) + debugpline0("exerper: Hunger checks"); + switch (hs) { + case SATIATED: exercise(A_DEX, FALSE); - } + if (Role_if(PM_MONK)) + exercise(A_WIS, FALSE); + break; + case NOT_HUNGRY: + exercise(A_CON, TRUE); + break; + case WEAK: + exercise(A_STR, FALSE); + if (Role_if(PM_MONK)) /* fasting */ + exercise(A_WIS, TRUE); + break; + case FAINTING: + case FAINTED: + exercise(A_CON, FALSE); + break; + } + + /* Encumberance Checks */ + debugpline0("exerper: Encumber checks"); + switch (near_capacity()) { + case MOD_ENCUMBER: + exercise(A_STR, TRUE); + break; + case HVY_ENCUMBER: + exercise(A_STR, TRUE); + exercise(A_DEX, FALSE); + break; + case EXT_ENCUMBER: + exercise(A_DEX, FALSE); + exercise(A_CON, FALSE); + break; + } + } + + /* status checks */ + if (!(moves % 5)) { + debugpline0("exerper: Status checks"); + if ((HClairvoyant & (INTRINSIC | TIMEOUT)) && !BClairvoyant) + exercise(A_WIS, TRUE); + if (HRegeneration) + exercise(A_STR, TRUE); + + if (Sick || Vomiting) + exercise(A_CON, FALSE); + if (Confusion || Hallucination) + exercise(A_WIS, FALSE); + if ((Wounded_legs && !u.usteed) || Fumbling || HStun) + exercise(A_DEX, FALSE); + } } /* exercise/abuse text (must be in attribute order, not botl order); phrased as "You must have been [][0]." or "You haven't been [][1]." */ -static NEARDATA const char * const exertext[A_MAX][2] = { - { "exercising diligently", "exercising properly" }, /* Str */ - { 0, 0 }, /* Int */ - { "very observant", "paying attention" }, /* Wis */ - { "working on your reflexes", "working on reflexes lately" }, /* Dex */ - { "leading a healthy life-style", "watching your health" }, /* Con */ - { 0, 0 }, /* Cha */ +static NEARDATA const char *const exertext[A_MAX][2] = { + { "exercising diligently", "exercising properly" }, /* Str */ + { 0, 0 }, /* Int */ + { "very observant", "paying attention" }, /* Wis */ + { "working on your reflexes", "working on reflexes lately" }, /* Dex */ + { "leading a healthy life-style", "watching your health" }, /* Con */ + { 0, 0 }, /* Cha */ }; void exerchk() { - int i, ax, mod_val, lolim, hilim; + int i, ax, mod_val, lolim, hilim; - /* Check out the periodic accumulations */ - exerper(); + /* Check out the periodic accumulations */ + exerper(); - if(moves >= context.next_attrib_check) - debugpline1("exerchk: ready to test. multi = %d.", multi); - /* Are we ready for a test? */ - if(moves >= context.next_attrib_check && !multi) { - debugpline0("exerchk: testing."); - /* - * Law of diminishing returns (Part II): - * - * The effects of "exercise" and "abuse" wear - * off over time. Even if you *don't* get an - * increase/decrease, you lose some of the - * accumulated effects. - */ - for (i = 0; i < A_MAX; ++i) { - ax = AEXE(i); - /* nothing to do here if no exercise or abuse has occurred - (Int and Cha always fall into this category) */ - if (!ax) continue; /* ok to skip nextattrib */ + if (moves >= context.next_attrib_check) + debugpline1("exerchk: ready to test. multi = %d.", multi); + /* Are we ready for a test? */ + if (moves >= context.next_attrib_check && !multi) { + debugpline0("exerchk: testing."); + /* + * Law of diminishing returns (Part II): + * + * The effects of "exercise" and "abuse" wear + * off over time. Even if you *don't* get an + * increase/decrease, you lose some of the + * accumulated effects. + */ + for (i = 0; i < A_MAX; ++i) { + ax = AEXE(i); + /* nothing to do here if no exercise or abuse has occurred + (Int and Cha always fall into this category) */ + if (!ax) + continue; /* ok to skip nextattrib */ - mod_val = sgn(ax); /* +1 or -1; used below */ - /* no further effect for exercise if at max or abuse if at min; - can't exceed 18 via exercise even if actual max is higher */ - lolim = ATTRMIN(i); /* usually 3; might be higher */ - hilim = ATTRMAX(i); /* usually 18; maybe lower or higher */ - if (hilim > 18) hilim = 18; - if ((ax < 0) ? (ABASE(i) <= lolim) : (ABASE(i) >= hilim)) - goto nextattrib; - /* can't exercise non-Wisdom while polymorphed; previous - exercise/abuse gradually wears off without impact then */ - if (Upolyd && i != A_WIS) goto nextattrib; + mod_val = sgn(ax); /* +1 or -1; used below */ + /* no further effect for exercise if at max or abuse if at min; + can't exceed 18 via exercise even if actual max is higher */ + lolim = ATTRMIN(i); /* usually 3; might be higher */ + hilim = ATTRMAX(i); /* usually 18; maybe lower or higher */ + if (hilim > 18) + hilim = 18; + if ((ax < 0) ? (ABASE(i) <= lolim) : (ABASE(i) >= hilim)) + goto nextattrib; + /* can't exercise non-Wisdom while polymorphed; previous + exercise/abuse gradually wears off without impact then */ + if (Upolyd && i != A_WIS) + goto nextattrib; - debugpline2("exerchk: testing %s (%d).", - (i == A_STR) ? "Str" : (i == A_INT) ? "Int?" : - (i == A_WIS) ? "Wis" : (i == A_DEX) ? "Dex" : - (i == A_CON) ? "Con" : (i == A_CHA) ? "Cha?" : "???", - ax); - /* - * Law of diminishing returns (Part III): - * - * You don't *always* gain by exercising. - * [MRS 92/10/28 - Treat Wisdom specially for balance.] - */ - if (rn2(AVAL) > ((i != A_WIS) ? (abs(ax) * 2 / 3) : abs(ax))) - goto nextattrib; + debugpline2("exerchk: testing %s (%d).", + (i == A_STR) + ? "Str" + : (i == A_INT) + ? "Int?" + : (i == A_WIS) + ? "Wis" + : (i == A_DEX) + ? "Dex" + : (i == A_CON) + ? "Con" + : (i == A_CHA) ? "Cha?" + : "???", + ax); + /* + * Law of diminishing returns (Part III): + * + * You don't *always* gain by exercising. + * [MRS 92/10/28 - Treat Wisdom specially for balance.] + */ + if (rn2(AVAL) > ((i != A_WIS) ? (abs(ax) * 2 / 3) : abs(ax))) + goto nextattrib; - debugpline1("exerchk: changing %d.", i); - if(adjattrib(i, mod_val, -1)) { - debugpline1("exerchk: changed %d.", i); - /* if you actually changed an attrib - zero accumulation */ - AEXE(i) = ax = 0; - /* then print an explanation */ - You("%s %s.", - (mod_val > 0) ? "must have been" : "haven't been", - exertext[i][(mod_val > 0) ? 0 : 1]); - } - nextattrib: - /* this used to be ``AEXE(i) /= 2'' but that would produce - platform-dependent rounding/truncation for negative vals */ - AEXE(i) = (abs(ax) / 2) * mod_val; - } - context.next_attrib_check += rn1(200,800); - debugpline1("exerchk: next check at %ld.", - context.next_attrib_check); - } + debugpline1("exerchk: changing %d.", i); + if (adjattrib(i, mod_val, -1)) { + debugpline1("exerchk: changed %d.", i); + /* if you actually changed an attrib - zero accumulation */ + AEXE(i) = ax = 0; + /* then print an explanation */ + You("%s %s.", + (mod_val > 0) ? "must have been" : "haven't been", + exertext[i][(mod_val > 0) ? 0 : 1]); + } + nextattrib: + /* this used to be ``AEXE(i) /= 2'' but that would produce + platform-dependent rounding/truncation for negative vals */ + AEXE(i) = (abs(ax) / 2) * mod_val; + } + context.next_attrib_check += rn1(200, 800); + debugpline1("exerchk: next check at %ld.", context.next_attrib_check); + } } void init_attr(np) - register int np; +register int np; { - register int i, x, tryct; + register int i, x, tryct; + for (i = 0; i < A_MAX; i++) { + ABASE(i) = AMAX(i) = urole.attrbase[i]; + ATEMP(i) = ATIME(i) = 0; + np -= urole.attrbase[i]; + } - for(i = 0; i < A_MAX; i++) { - ABASE(i) = AMAX(i) = urole.attrbase[i]; - ATEMP(i) = ATIME(i) = 0; - np -= urole.attrbase[i]; - } + tryct = 0; + while (np > 0 && tryct < 100) { + x = rn2(100); + for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) + ; + if (i >= A_MAX) + continue; /* impossible */ - tryct = 0; - while(np > 0 && tryct < 100) { + if (ABASE(i) >= ATTRMAX(i)) { + tryct++; + continue; + } + tryct = 0; + ABASE(i)++; + AMAX(i)++; + np--; + } - x = rn2(100); - for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ; - if(i >= A_MAX) continue; /* impossible */ + tryct = 0; + while (np < 0 && tryct < 100) { /* for redistribution */ - if(ABASE(i) >= ATTRMAX(i)) { + x = rn2(100); + for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) + ; + if (i >= A_MAX) + continue; /* impossible */ - tryct++; - continue; - } - tryct = 0; - ABASE(i)++; - AMAX(i)++; - np--; - } - - tryct = 0; - while(np < 0 && tryct < 100) { /* for redistribution */ - - x = rn2(100); - for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ; - if(i >= A_MAX) continue; /* impossible */ - - if(ABASE(i) <= ATTRMIN(i)) { - - tryct++; - continue; - } - tryct = 0; - ABASE(i)--; - AMAX(i)--; - np++; - } + if (ABASE(i) <= ATTRMIN(i)) { + tryct++; + continue; + } + tryct = 0; + ABASE(i)--; + AMAX(i)--; + np++; + } } void redist_attr() { - register int i, tmp; + register int i, tmp; - for(i = 0; i < A_MAX; i++) { - if (i==A_INT || i==A_WIS) continue; - /* Polymorphing doesn't change your mind */ - tmp = AMAX(i); - AMAX(i) += (rn2(5)-2); - if (AMAX(i) > ATTRMAX(i)) AMAX(i) = ATTRMAX(i); - if (AMAX(i) < ATTRMIN(i)) AMAX(i) = ATTRMIN(i); - ABASE(i) = ABASE(i) * AMAX(i) / tmp; - /* ABASE(i) > ATTRMAX(i) is impossible */ - if (ABASE(i) < ATTRMIN(i)) ABASE(i) = ATTRMIN(i); - } - (void)encumber_msg(); + for (i = 0; i < A_MAX; i++) { + if (i == A_INT || i == A_WIS) + continue; + /* Polymorphing doesn't change your mind */ + tmp = AMAX(i); + AMAX(i) += (rn2(5) - 2); + if (AMAX(i) > ATTRMAX(i)) + AMAX(i) = ATTRMAX(i); + if (AMAX(i) < ATTRMIN(i)) + AMAX(i) = ATTRMIN(i); + ABASE(i) = ABASE(i) * AMAX(i) / tmp; + /* ABASE(i) > ATTRMAX(i) is impossible */ + if (ABASE(i) < ATTRMIN(i)) + ABASE(i) = ATTRMIN(i); + } + (void) encumber_msg(); } STATIC_OVL @@ -583,9 +623,10 @@ void postadjabil(ability) long *ability; { - if (!ability) return; - if (ability == &(HWarning) || ability == &(HSee_invisible)) - see_monsters(); + if (!ability) + return; + if (ability == &(HWarning) || ability == &(HSee_invisible)) + see_monsters(); } STATIC_OVL const struct innate * @@ -593,41 +634,73 @@ check_innate_abil(ability, frommask) long *ability; long frommask; { - const struct innate *abil = 0; + const struct innate *abil = 0; - if (frommask == FROMEXPER) - switch (Role_switch) { - case PM_ARCHEOLOGIST: abil = arc_abil; break; - case PM_BARBARIAN: abil = bar_abil; break; - case PM_CAVEMAN: abil = cav_abil; break; - case PM_HEALER: abil = hea_abil; break; - case PM_KNIGHT: abil = kni_abil; break; - case PM_MONK: abil = mon_abil; break; - case PM_PRIEST: abil = pri_abil; break; - case PM_RANGER: abil = ran_abil; break; - case PM_ROGUE: abil = rog_abil; break; - case PM_SAMURAI: abil = sam_abil; break; - case PM_TOURIST: abil = tou_abil; break; - case PM_VALKYRIE: abil = val_abil; break; - case PM_WIZARD: abil = wiz_abil; break; - default: break; - } - else if (frommask == FROMRACE) - switch (Race_switch) { - case PM_ELF: abil = elf_abil; break; - case PM_ORC: abil = orc_abil; break; - case PM_HUMAN: - case PM_DWARF: - case PM_GNOME: - default: break; - } + if (frommask == FROMEXPER) + switch (Role_switch) { + case PM_ARCHEOLOGIST: + abil = arc_abil; + break; + case PM_BARBARIAN: + abil = bar_abil; + break; + case PM_CAVEMAN: + abil = cav_abil; + break; + case PM_HEALER: + abil = hea_abil; + break; + case PM_KNIGHT: + abil = kni_abil; + break; + case PM_MONK: + abil = mon_abil; + break; + case PM_PRIEST: + abil = pri_abil; + break; + case PM_RANGER: + abil = ran_abil; + break; + case PM_ROGUE: + abil = rog_abil; + break; + case PM_SAMURAI: + abil = sam_abil; + break; + case PM_TOURIST: + abil = tou_abil; + break; + case PM_VALKYRIE: + abil = val_abil; + break; + case PM_WIZARD: + abil = wiz_abil; + break; + default: + break; + } + else if (frommask == FROMRACE) + switch (Race_switch) { + case PM_ELF: + abil = elf_abil; + break; + case PM_ORC: + abil = orc_abil; + break; + case PM_HUMAN: + case PM_DWARF: + case PM_GNOME: + default: + break; + } - while (abil && abil->ability) { - if((abil->ability == ability) && (u.ulevel >= abil->ulevel)) - return abil; - abil++; - } - return (struct innate *)0; + while (abil && abil->ability) { + if ((abil->ability == ability) && (u.ulevel >= abil->ulevel)) + return abil; + abil++; + } + return (struct innate *) 0; } /* @@ -639,26 +712,27 @@ STATIC_OVL int innately(ability) long *ability; { - const struct innate *iptr; + const struct innate *iptr; - if ((iptr = check_innate_abil(ability, FROMRACE)) != 0) - return 1; - else if ((iptr = check_innate_abil(ability, FROMEXPER)) != 0) - return (iptr->ulevel == 1) ? 1 : 2; - return 0; + if ((iptr = check_innate_abil(ability, FROMRACE)) != 0) + return 1; + else if ((iptr = check_innate_abil(ability, FROMEXPER)) != 0) + return (iptr->ulevel == 1) ? 1 : 2; + return 0; } int is_innate(propidx) int propidx; { - if (propidx == BLINDED && !haseyes(youmonst.data)) return 1; - return innately(&u.uprops[propidx].intrinsic); + if (propidx == BLINDED && !haseyes(youmonst.data)) + return 1; + return innately(&u.uprops[propidx].intrinsic); } char * from_what(propidx) -int propidx; /* special cases can have negative values */ +int propidx; /* special cases can have negative values */ { static char buf[BUFSZ]; @@ -667,204 +741,262 @@ int propidx; /* special cases can have negative values */ * Restrict the source of the attributes just to debug mode for now */ if (wizard) { - static NEARDATA const char because_of[] = " because of %s"; + static NEARDATA const char because_of[] = " because of %s"; - if (propidx >= 0) { - char *p; - struct obj *obj = (struct obj *)0; - int innate = is_innate(propidx); + if (propidx >= 0) { + char *p; + struct obj *obj = (struct obj *) 0; + int innate = is_innate(propidx); - if (innate == 2) - Strcpy(buf, " because of your experience"); - else if (innate == 1) - Strcpy(buf, " innately"); - else if (wizard && (obj = what_gives(&u.uprops[propidx].extrinsic))) - Sprintf(buf, because_of, - obj->oartifact ? bare_artifactname(obj) : - ysimple_name(obj)); - else if (propidx == BLINDED && u.uroleplay.blind) - Sprintf(buf, " from birth"); - else if (propidx == BLINDED && Blindfolded_only) - Sprintf(buf, because_of, ysimple_name(ublindf)); + if (innate == 2) + Strcpy(buf, " because of your experience"); + else if (innate == 1) + Strcpy(buf, " innately"); + else if (wizard + && (obj = what_gives(&u.uprops[propidx].extrinsic))) + Sprintf(buf, because_of, obj->oartifact + ? bare_artifactname(obj) + : ysimple_name(obj)); + else if (propidx == BLINDED && u.uroleplay.blind) + Sprintf(buf, " from birth"); + else if (propidx == BLINDED && Blindfolded_only) + Sprintf(buf, because_of, ysimple_name(ublindf)); - /* remove some verbosity and/or redundancy */ - if ((p = strstri(buf, " pair of ")) != 0) - copynchars(p + 1, p + 9, BUFSZ); /* overlapping buffers ok */ - else if (propidx == STRANGLED && - (p = strstri(buf, " of strangulation")) != 0) - *p = '\0'; + /* remove some verbosity and/or redundancy */ + if ((p = strstri(buf, " pair of ")) != 0) + copynchars(p + 1, p + 9, BUFSZ); /* overlapping buffers ok */ + else if (propidx == STRANGLED + && (p = strstri(buf, " of strangulation")) != 0) + *p = '\0'; - } else { /* negative property index */ - /* if more blocking capabilities get implemented we'll need to - replace this with what_blocks() comparable to what_gives() */ - switch (-propidx) { - case BLINDED: - if (ublindf && ublindf->oartifact == ART_EYES_OF_THE_OVERWORLD) - Sprintf(buf, because_of, bare_artifactname(ublindf)); - break; - case INVIS: - if (u.uprops[INVIS].blocked & W_ARMC) - Sprintf(buf, because_of, ysimple_name(uarmc)); /* mummy wrapping */ - break; - case CLAIRVOYANT: - if (wizard && (u.uprops[CLAIRVOYANT].blocked & W_ARMH)) - Sprintf(buf, because_of, ysimple_name(uarmh)); /* cornuthaum */ - break; - } - } + } else { /* negative property index */ + /* if more blocking capabilities get implemented we'll need to + replace this with what_blocks() comparable to what_gives() */ + switch (-propidx) { + case BLINDED: + if (ublindf + && ublindf->oartifact == ART_EYES_OF_THE_OVERWORLD) + Sprintf(buf, because_of, bare_artifactname(ublindf)); + break; + case INVIS: + if (u.uprops[INVIS].blocked & W_ARMC) + Sprintf(buf, because_of, + ysimple_name(uarmc)); /* mummy wrapping */ + break; + case CLAIRVOYANT: + if (wizard && (u.uprops[CLAIRVOYANT].blocked & W_ARMH)) + Sprintf(buf, because_of, + ysimple_name(uarmh)); /* cornuthaum */ + break; + } + } } /*wizard*/ return buf; } void -adjabil(oldlevel,newlevel) +adjabil(oldlevel, newlevel) int oldlevel, newlevel; { - register const struct innate *abil, *rabil; - long prevabil, mask = FROMEXPER; + register const struct innate *abil, *rabil; + long prevabil, mask = FROMEXPER; - switch (Role_switch) { - case PM_ARCHEOLOGIST: abil = arc_abil; break; - case PM_BARBARIAN: abil = bar_abil; break; - case PM_CAVEMAN: abil = cav_abil; break; - case PM_HEALER: abil = hea_abil; break; - case PM_KNIGHT: abil = kni_abil; break; - case PM_MONK: abil = mon_abil; break; - case PM_PRIEST: abil = pri_abil; break; - case PM_RANGER: abil = ran_abil; break; - case PM_ROGUE: abil = rog_abil; break; - case PM_SAMURAI: abil = sam_abil; break; - case PM_TOURIST: abil = tou_abil; break; - case PM_VALKYRIE: abil = val_abil; break; - case PM_WIZARD: abil = wiz_abil; break; - default: abil = 0; break; - } + switch (Role_switch) { + case PM_ARCHEOLOGIST: + abil = arc_abil; + break; + case PM_BARBARIAN: + abil = bar_abil; + break; + case PM_CAVEMAN: + abil = cav_abil; + break; + case PM_HEALER: + abil = hea_abil; + break; + case PM_KNIGHT: + abil = kni_abil; + break; + case PM_MONK: + abil = mon_abil; + break; + case PM_PRIEST: + abil = pri_abil; + break; + case PM_RANGER: + abil = ran_abil; + break; + case PM_ROGUE: + abil = rog_abil; + break; + case PM_SAMURAI: + abil = sam_abil; + break; + case PM_TOURIST: + abil = tou_abil; + break; + case PM_VALKYRIE: + abil = val_abil; + break; + case PM_WIZARD: + abil = wiz_abil; + break; + default: + abil = 0; + break; + } - switch (Race_switch) { - case PM_ELF: rabil = elf_abil; break; - case PM_ORC: rabil = orc_abil; break; - case PM_HUMAN: - case PM_DWARF: - case PM_GNOME: - default: rabil = 0; break; - } + switch (Race_switch) { + case PM_ELF: + rabil = elf_abil; + break; + case PM_ORC: + rabil = orc_abil; + break; + case PM_HUMAN: + case PM_DWARF: + case PM_GNOME: + default: + rabil = 0; + break; + } - while (abil || rabil) { - /* Have we finished with the intrinsics list? */ - if (!abil || !abil->ability) { - /* Try the race intrinsics */ - if (!rabil || !rabil->ability) break; - abil = rabil; - rabil = 0; - mask = FROMRACE; - } - prevabil = *(abil->ability); - if(oldlevel < abil->ulevel && newlevel >= abil->ulevel) { - /* Abilities gained at level 1 can never be lost - * via level loss, only via means that remove _any_ - * sort of ability. A "gain" of such an ability from - * an outside source is devoid of meaning, so we set - * FROMOUTSIDE to avoid such gains. - */ - if (abil->ulevel == 1) - *(abil->ability) |= (mask|FROMOUTSIDE); - else - *(abil->ability) |= mask; - if(!(*(abil->ability) & INTRINSIC & ~mask)) { - if(*(abil->gainstr)) - You_feel("%s!", abil->gainstr); - } - } else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) { - *(abil->ability) &= ~mask; - if(!(*(abil->ability) & INTRINSIC)) { - if(*(abil->losestr)) - You_feel("%s!", abil->losestr); - else if(*(abil->gainstr)) - You_feel("less %s!", abil->gainstr); - } - } - if (prevabil != *(abil->ability)) /* it changed */ - postadjabil(abil->ability); - abil++; - } + while (abil || rabil) { + /* Have we finished with the intrinsics list? */ + if (!abil || !abil->ability) { + /* Try the race intrinsics */ + if (!rabil || !rabil->ability) + break; + abil = rabil; + rabil = 0; + mask = FROMRACE; + } + prevabil = *(abil->ability); + if (oldlevel < abil->ulevel && newlevel >= abil->ulevel) { + /* Abilities gained at level 1 can never be lost + * via level loss, only via means that remove _any_ + * sort of ability. A "gain" of such an ability from + * an outside source is devoid of meaning, so we set + * FROMOUTSIDE to avoid such gains. + */ + if (abil->ulevel == 1) + *(abil->ability) |= (mask | FROMOUTSIDE); + else + *(abil->ability) |= mask; + if (!(*(abil->ability) & INTRINSIC & ~mask)) { + if (*(abil->gainstr)) + You_feel("%s!", abil->gainstr); + } + } else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) { + *(abil->ability) &= ~mask; + if (!(*(abil->ability) & INTRINSIC)) { + if (*(abil->losestr)) + You_feel("%s!", abil->losestr); + else if (*(abil->gainstr)) + You_feel("less %s!", abil->gainstr); + } + } + if (prevabil != *(abil->ability)) /* it changed */ + postadjabil(abil->ability); + abil++; + } - if (oldlevel > 0) { - if (newlevel > oldlevel) - add_weapon_skill(newlevel - oldlevel); - else - lose_weapon_skill(oldlevel - newlevel); - } + if (oldlevel > 0) { + if (newlevel > oldlevel) + add_weapon_skill(newlevel - oldlevel); + else + lose_weapon_skill(oldlevel - newlevel); + } } - int newhp() { - int hp, conplus; + int hp, conplus; - if (u.ulevel == 0) { - /* Initialize hit points */ - hp = urole.hpadv.infix + urace.hpadv.infix; - if (urole.hpadv.inrnd > 0) hp += rnd(urole.hpadv.inrnd); - if (urace.hpadv.inrnd > 0) hp += rnd(urace.hpadv.inrnd); - if (moves <= 1L) { /* initial hero; skip for polyself to new man */ - /* Initialize alignment stuff */ - u.ualign.type = aligns[flags.initalign].value; - u.ualign.record = urole.initrecord; - } - /* no Con adjustment for initial hit points */ - } else { - if (u.ulevel < urole.xlev) { - hp = urole.hpadv.lofix + urace.hpadv.lofix; - if (urole.hpadv.lornd > 0) hp += rnd(urole.hpadv.lornd); - if (urace.hpadv.lornd > 0) hp += rnd(urace.hpadv.lornd); - } else { - hp = urole.hpadv.hifix + urace.hpadv.hifix; - if (urole.hpadv.hirnd > 0) hp += rnd(urole.hpadv.hirnd); - if (urace.hpadv.hirnd > 0) hp += rnd(urace.hpadv.hirnd); - } - if (ACURR(A_CON) <= 3) conplus = -2; - else if (ACURR(A_CON) <= 6) conplus = -1; - else if (ACURR(A_CON) <= 14) conplus = 0; - else if (ACURR(A_CON) <= 16) conplus = 1; - else if (ACURR(A_CON) == 17) conplus = 2; - else if (ACURR(A_CON) == 18) conplus = 3; - else conplus = 4; - hp += conplus; - } - if (hp <= 0) hp = 1; - if (u.ulevel < MAXULEV) u.uhpinc[u.ulevel] = (xchar)hp; - return hp; + if (u.ulevel == 0) { + /* Initialize hit points */ + hp = urole.hpadv.infix + urace.hpadv.infix; + if (urole.hpadv.inrnd > 0) + hp += rnd(urole.hpadv.inrnd); + if (urace.hpadv.inrnd > 0) + hp += rnd(urace.hpadv.inrnd); + if (moves <= 1L) { /* initial hero; skip for polyself to new man */ + /* Initialize alignment stuff */ + u.ualign.type = aligns[flags.initalign].value; + u.ualign.record = urole.initrecord; + } + /* no Con adjustment for initial hit points */ + } else { + if (u.ulevel < urole.xlev) { + hp = urole.hpadv.lofix + urace.hpadv.lofix; + if (urole.hpadv.lornd > 0) + hp += rnd(urole.hpadv.lornd); + if (urace.hpadv.lornd > 0) + hp += rnd(urace.hpadv.lornd); + } else { + hp = urole.hpadv.hifix + urace.hpadv.hifix; + if (urole.hpadv.hirnd > 0) + hp += rnd(urole.hpadv.hirnd); + if (urace.hpadv.hirnd > 0) + hp += rnd(urace.hpadv.hirnd); + } + if (ACURR(A_CON) <= 3) + conplus = -2; + else if (ACURR(A_CON) <= 6) + conplus = -1; + else if (ACURR(A_CON) <= 14) + conplus = 0; + else if (ACURR(A_CON) <= 16) + conplus = 1; + else if (ACURR(A_CON) == 17) + conplus = 2; + else if (ACURR(A_CON) == 18) + conplus = 3; + else + conplus = 4; + hp += conplus; + } + if (hp <= 0) + hp = 1; + if (u.ulevel < MAXULEV) + u.uhpinc[u.ulevel] = (xchar) hp; + return hp; } schar acurr(x) int x; { - register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]); + register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]); - if (x == A_STR) { - if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) return(125); + if (x == A_STR) { + if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) + return (125); #ifdef WIN32_BUG - else return(x=((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); + else + return (x = ((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); #else - else return((schar)((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); + else + return ((schar)((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); #endif - } else if (x == A_CHA) { - if (tmp < 18 && (youmonst.data->mlet == S_NYMPH || - u.umonnum==PM_SUCCUBUS || u.umonnum == PM_INCUBUS)) - return 18; - } else if (x == A_INT || x == A_WIS) { - /* yes, this may raise int/wis if player is sufficiently - * stupid. there are lower levels of cognition than "dunce". - */ - if (uarmh && uarmh->otyp == DUNCE_CAP) return(6); - } + } else if (x == A_CHA) { + if (tmp < 18 + && (youmonst.data->mlet == S_NYMPH || u.umonnum == PM_SUCCUBUS + || u.umonnum == PM_INCUBUS)) + return 18; + } else if (x == A_INT || x == A_WIS) { + /* yes, this may raise int/wis if player is sufficiently + * stupid. there are lower levels of cognition than "dunce". + */ + if (uarmh && uarmh->otyp == DUNCE_CAP) + return (6); + } #ifdef WIN32_BUG - return(x=((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); + return (x = ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); #else - return((schar)((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); + return ((schar)((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); #endif } @@ -873,18 +1005,21 @@ int x; schar acurrstr() { - register int str = ACURR(A_STR); + register int str = ACURR(A_STR); - if (str <= 18) return((schar)str); - if (str <= 121) return((schar)(19 + str / 50)); /* map to 19-21 */ - else return((schar)(str - 100)); + if (str <= 18) + return ((schar) str); + if (str <= 121) + return ((schar)(19 + str / 50)); /* map to 19-21 */ + else + return ((schar)(str - 100)); } /* when wearing (or taking off) an unID'd item, this routine is used to distinguish between observable +0 result and no-visible-effect due to an attribute not being able to exceed maximum or minimun */ boolean -extremeattr(attrindx) /* does attrindx's value match its max or min? */ +extremeattr(attrindx) /* does attrindx's value match its max or min? */ int attrindx; { /* Fixed_abil and racial MINATTR/MAXATTR aren't relevant here */ @@ -892,16 +1027,16 @@ int attrindx; /* upper limit for Str is 25 but its value is encoded differently */ if (attrindx == A_STR) { - hilimit = STR19(25); /* 125 */ - /* lower limit for Str can also be 25 */ - if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) - lolimit = hilimit; + hilimit = STR19(25); /* 125 */ + /* lower limit for Str can also be 25 */ + if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) + lolimit = hilimit; } /* this exception is hypothetical; the only other worn item affecting Int or Wis is another helmet so can't be in use at the same time */ if (attrindx == A_INT || attrindx == A_WIS) { - if (uarmh && uarmh->otyp == DUNCE_CAP) - hilimit = lolimit = 6; + if (uarmh && uarmh->otyp == DUNCE_CAP) + hilimit = lolimit = 6; } /* are we currently at either limit? */ @@ -915,50 +1050,50 @@ void adjalign(n) register int n; { - register int newalign = u.ualign.record + n; + register int newalign = u.ualign.record + n; - if(n < 0) { - if(newalign < u.ualign.record) - u.ualign.record = newalign; - } else - if(newalign > u.ualign.record) { - u.ualign.record = newalign; - if(u.ualign.record > ALIGNLIM) - u.ualign.record = ALIGNLIM; - } + if (n < 0) { + if (newalign < u.ualign.record) + u.ualign.record = newalign; + } else if (newalign > u.ualign.record) { + u.ualign.record = newalign; + if (u.ualign.record > ALIGNLIM) + u.ualign.record = ALIGNLIM; + } } /* change hero's alignment type, possibly losing use of artifacts */ void uchangealign(newalign, reason) int newalign; -int reason; /* 0==conversion, 1==helm-of-OA on, 2==helm-of-OA off */ +int reason; /* 0==conversion, 1==helm-of-OA on, 2==helm-of-OA off */ { aligntyp oldalign = u.ualign.type; - u.ublessed = 0; /* lose divine protection */ - context.botl = 1; /* status line needs updating */ + u.ublessed = 0; /* lose divine protection */ + context.botl = 1; /* status line needs updating */ if (reason == 0) { - /* conversion via altar */ - u.ualignbase[A_CURRENT] = (aligntyp)newalign; - /* worn helm of opposite alignment might block change */ - if (!uarmh || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT) - u.ualign.type = u.ualignbase[A_CURRENT]; - You("have a %ssense of a new direction.", - (u.ualign.type != oldalign) ? "sudden " : ""); + /* conversion via altar */ + u.ualignbase[A_CURRENT] = (aligntyp) newalign; + /* worn helm of opposite alignment might block change */ + if (!uarmh || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT) + u.ualign.type = u.ualignbase[A_CURRENT]; + You("have a %ssense of a new direction.", + (u.ualign.type != oldalign) ? "sudden " : ""); } else { - /* putting on or taking off a helm of opposite alignment */ - u.ualign.type = (aligntyp)newalign; - if (reason == 1) - Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly"); - else if (reason == 2) - Your("mind is %s.", Hallucination ? "much of a muchness" : - "back in sync with your body"); + /* putting on or taking off a helm of opposite alignment */ + u.ualign.type = (aligntyp) newalign; + if (reason == 1) + Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly"); + else if (reason == 2) + Your("mind is %s.", Hallucination + ? "much of a muchness" + : "back in sync with your body"); } if (u.ualign.type != oldalign) { - u.ualign.record = 0; /* slate is wiped clean */ - retouch_equipment(0); + u.ualign.record = 0; /* slate is wiped clean */ + retouch_equipment(0); } } diff --git a/src/ball.c b/src/ball.c index be76d20b7..56338f6a9 100644 --- a/src/ball.c +++ b/src/ball.c @@ -1,9 +1,10 @@ -/* NetHack 3.6 ball.c $NHDT-Date: 1430365884 2015/04/30 03:51:24 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */ +/* NetHack 3.6 ball.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */ /* NetHack 3.6 ball.c $Date: 2011/08/30 22:13:26 $ $Revision: 1.17 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ -/* Ball & Chain =============================================================*/ +/* Ball & Chain + * =============================================================*/ #include "hack.h" @@ -15,41 +16,41 @@ ballrelease(showmsg) boolean showmsg; { if (carried(uball)) { - if (showmsg) pline("Startled, you drop the iron ball."); - if (uwep == uball) - setuwep((struct obj *)0); - if (uswapwep == uball) - setuswapwep((struct obj *)0); - if (uquiver == uball) - setuqwep((struct obj *)0);; - if (uwep != uball) - freeinv(uball); + if (showmsg) + pline("Startled, you drop the iron ball."); + if (uwep == uball) + setuwep((struct obj *) 0); + if (uswapwep == uball) + setuswapwep((struct obj *) 0); + if (uquiver == uball) + setuqwep((struct obj *) 0); + ; + if (uwep != uball) + freeinv(uball); } } void ballfall() { - boolean gets_hit; + boolean gets_hit; - gets_hit = (((uball->ox != u.ux) || (uball->oy != u.uy)) && - ((uwep == uball)? FALSE : (boolean)rn2(5))); - ballrelease(TRUE); - if(gets_hit){ - int dmg = rn1(7,25); - pline_The("iron ball falls on your %s.", - body_part(HEAD)); - if (uarmh) { - if(is_metallic(uarmh)) { - pline("Fortunately, you are wearing a hard helmet."); - dmg = 3; - } else if (flags.verbose) - pline("%s does not protect you.", Yname2(uarmh)); - } - losehp(Maybe_Half_Phys(dmg), - "crunched in the head by an iron ball", - NO_KILLER_PREFIX); - } + gets_hit = (((uball->ox != u.ux) || (uball->oy != u.uy)) + && ((uwep == uball) ? FALSE : (boolean) rn2(5))); + ballrelease(TRUE); + if (gets_hit) { + int dmg = rn1(7, 25); + pline_The("iron ball falls on your %s.", body_part(HEAD)); + if (uarmh) { + if (is_metallic(uarmh)) { + pline("Fortunately, you are wearing a hard helmet."); + dmg = 3; + } else if (flags.verbose) + pline("%s does not protect you.", Yname2(uarmh)); + } + losehp(Maybe_Half_Phys(dmg), "crunched in the head by an iron ball", + NO_KILLER_PREFIX); + } } /* @@ -90,11 +91,9 @@ ballfall() */ /* values for u.bc_order */ -#define BCPOS_DIFFER 0 /* ball & chain at different positions */ -#define BCPOS_CHAIN 1 /* chain on top of ball */ -#define BCPOS_BALL 2 /* ball on top of chain */ - - +#define BCPOS_DIFFER 0 /* ball & chain at different positions */ +#define BCPOS_CHAIN 1 /* chain on top of ball */ +#define BCPOS_BALL 2 /* ball on top of chain */ /* * Place the ball & chain under the hero. Make sure that the ball & chain @@ -108,61 +107,60 @@ void placebc() { if (!uchain || !uball) { - impossible("Where are your ball and chain?"); - return; + impossible("Where are your ball and chain?"); + return; } - (void) flooreffects(uchain, u.ux, u.uy, ""); /* chain might rust */ + (void) flooreffects(uchain, u.ux, u.uy, ""); /* chain might rust */ - if (carried(uball)) /* the ball is carried */ - u.bc_order = BCPOS_DIFFER; + if (carried(uball)) /* the ball is carried */ + u.bc_order = BCPOS_DIFFER; else { - /* ball might rust -- already checked when carried */ - (void) flooreffects(uball, u.ux, u.uy, ""); - place_object(uball, u.ux, u.uy); - u.bc_order = BCPOS_CHAIN; + /* ball might rust -- already checked when carried */ + (void) flooreffects(uball, u.ux, u.uy, ""); + place_object(uball, u.ux, u.uy); + u.bc_order = BCPOS_CHAIN; } place_object(uchain, u.ux, u.uy); - u.bglyph = u.cglyph = levl[u.ux][u.uy].glyph; /* pick up glyph */ + u.bglyph = u.cglyph = levl[u.ux][u.uy].glyph; /* pick up glyph */ - newsym(u.ux,u.uy); + newsym(u.ux, u.uy); } void unplacebc() { if (u.uswallow) { - if (Is_waterlevel(&u.uz)) { - /* we need to proceed with the removal from the floor - * so that movebubbles() processing will disregard it as - * intended. Ignore all the vision stuff. - */ - if (!carried(uball)) - obj_extract_self(uball); - obj_extract_self(uchain); + if (Is_waterlevel(&u.uz)) { + /* we need to proceed with the removal from the floor + * so that movebubbles() processing will disregard it as + * intended. Ignore all the vision stuff. + */ + if (!carried(uball)) + obj_extract_self(uball); + obj_extract_self(uchain); } /* ball&chain not unplaced while swallowed */ return; } if (!carried(uball)) { - obj_extract_self(uball); - if (Blind && (u.bc_felt & BC_BALL)) /* drop glyph */ - levl[uball->ox][uball->oy].glyph = u.bglyph; + obj_extract_self(uball); + if (Blind && (u.bc_felt & BC_BALL)) /* drop glyph */ + levl[uball->ox][uball->oy].glyph = u.bglyph; - newsym(uball->ox,uball->oy); + newsym(uball->ox, uball->oy); } obj_extract_self(uchain); - if (Blind && (u.bc_felt & BC_CHAIN)) /* drop glyph */ - levl[uchain->ox][uchain->oy].glyph = u.cglyph; + if (Blind && (u.bc_felt & BC_CHAIN)) /* drop glyph */ + levl[uchain->ox][uchain->oy].glyph = u.cglyph; - newsym(uchain->ox,uchain->oy); - u.bc_felt = 0; /* feel nothing */ + newsym(uchain->ox, uchain->oy); + u.bc_felt = 0; /* feel nothing */ } - /* * Return the stacking of the hero's ball & chain. This assumes that the * hero is being punished. @@ -173,12 +171,15 @@ bc_order() struct obj *obj; if (uchain->ox != uball->ox || uchain->oy != uball->oy || carried(uball) - || u.uswallow) - return BCPOS_DIFFER; + || u.uswallow) + return BCPOS_DIFFER; - for (obj = level.objects[uball->ox][uball->oy]; obj; obj = obj->nexthere) { - if (obj == uchain) return BCPOS_CHAIN; - if (obj == uball) return BCPOS_BALL; + for (obj = level.objects[uball->ox][uball->oy]; obj; + obj = obj->nexthere) { + if (obj == uchain) + return BCPOS_CHAIN; + if (obj == uball) + return BCPOS_BALL; } impossible("bc_order: ball&chain not in same location!"); return BCPOS_DIFFER; @@ -196,12 +197,12 @@ int already_blind; { int ball_on_floor = !carried(uball); - u.bc_order = bc_order(); /* get the order */ - u.bc_felt = ball_on_floor ? BC_BALL|BC_CHAIN : BC_CHAIN; /* felt */ + u.bc_order = bc_order(); /* get the order */ + u.bc_felt = ball_on_floor ? BC_BALL | BC_CHAIN : BC_CHAIN; /* felt */ if (already_blind || u.uswallow) { - u.cglyph = u.bglyph = levl[u.ux][u.uy].glyph; - return; + u.cglyph = u.bglyph = levl[u.ux][u.uy].glyph; + return; } /* @@ -210,34 +211,34 @@ int already_blind; * disgusting, but it will work. */ remove_object(uchain); - if (ball_on_floor) remove_object(uball); + if (ball_on_floor) + remove_object(uball); newsym(uchain->ox, uchain->oy); u.cglyph = levl[uchain->ox][uchain->oy].glyph; - if (u.bc_order == BCPOS_DIFFER) { /* different locations */ - place_object(uchain, uchain->ox, uchain->oy); - newsym(uchain->ox, uchain->oy); - if (ball_on_floor) { - newsym(uball->ox, uball->oy); /* see under ball */ - u.bglyph = levl[uball->ox][uball->oy].glyph; - place_object(uball, uball->ox, uball->oy); - newsym(uball->ox, uball->oy); /* restore ball */ - } + if (u.bc_order == BCPOS_DIFFER) { /* different locations */ + place_object(uchain, uchain->ox, uchain->oy); + newsym(uchain->ox, uchain->oy); + if (ball_on_floor) { + newsym(uball->ox, uball->oy); /* see under ball */ + u.bglyph = levl[uball->ox][uball->oy].glyph; + place_object(uball, uball->ox, uball->oy); + newsym(uball->ox, uball->oy); /* restore ball */ + } } else { - u.bglyph = u.cglyph; - if (u.bc_order == BCPOS_CHAIN) { - place_object(uball, uball->ox, uball->oy); - place_object(uchain, uchain->ox, uchain->oy); - } else { - place_object(uchain, uchain->ox, uchain->oy); - place_object(uball, uball->ox, uball->oy); - } - newsym(uball->ox, uball->oy); + u.bglyph = u.cglyph; + if (u.bc_order == BCPOS_CHAIN) { + place_object(uball, uball->ox, uball->oy); + place_object(uchain, uchain->ox, uchain->oy); + } else { + place_object(uchain, uchain->ox, uchain->oy); + place_object(uball, uball->ox, uball->oy); + } + newsym(uball->ox, uball->oy); } } - /* * move_bc() * @@ -250,124 +251,130 @@ int already_blind; */ void move_bc(before, control, ballx, bally, chainx, chainy) -int before, control; -xchar ballx, bally, chainx, chainy; /* only matter !before */ +int before, control; +xchar ballx, bally, chainx, chainy; /* only matter !before */ { if (Blind) { - /* - * The hero is blind. Time to work hard. The ball and chain that - * are attached to the hero are very special. The hero knows that - * they are attached, so when they move, the hero knows that they - * aren't at the last position remembered. This is complicated - * by the fact that the hero can "feel" the surrounding locations - * at any time, hence, making one or both of them show up again. - * So, we have to keep track of which is felt at any one time and - * act accordingly. - */ - if (!before) { - if ((control & BC_CHAIN) && (control & BC_BALL)) { - /* - * Both ball and chain moved. If felt, drop glyph. - */ - if (u.bc_felt & BC_BALL) - levl[uball->ox][uball->oy].glyph = u.bglyph; - if (u.bc_felt & BC_CHAIN) - levl[uchain->ox][uchain->oy].glyph = u.cglyph; - u.bc_felt = 0; + /* + * The hero is blind. Time to work hard. The ball and chain that + * are attached to the hero are very special. The hero knows that + * they are attached, so when they move, the hero knows that they + * aren't at the last position remembered. This is complicated + * by the fact that the hero can "feel" the surrounding locations + * at any time, hence, making one or both of them show up again. + * So, we have to keep track of which is felt at any one time and + * act accordingly. + */ + if (!before) { + if ((control & BC_CHAIN) && (control & BC_BALL)) { + /* + * Both ball and chain moved. If felt, drop glyph. + */ + if (u.bc_felt & BC_BALL) + levl[uball->ox][uball->oy].glyph = u.bglyph; + if (u.bc_felt & BC_CHAIN) + levl[uchain->ox][uchain->oy].glyph = u.cglyph; + u.bc_felt = 0; - /* Pick up glyph at new location. */ - u.bglyph = levl[ballx][bally].glyph; - u.cglyph = levl[chainx][chainy].glyph; + /* Pick up glyph at new location. */ + u.bglyph = levl[ballx][bally].glyph; + u.cglyph = levl[chainx][chainy].glyph; - movobj(uball,ballx,bally); - movobj(uchain,chainx,chainy); - } else if (control & BC_BALL) { - if (u.bc_felt & BC_BALL) { - if (u.bc_order == BCPOS_DIFFER) { /* ball by itself */ - levl[uball->ox][uball->oy].glyph = u.bglyph; - } else if (u.bc_order == BCPOS_BALL) { - if (u.bc_felt & BC_CHAIN) { /* know chain is there */ - map_object(uchain, 0); - } else { - levl[uball->ox][uball->oy].glyph = u.bglyph; - } - } - u.bc_felt &= ~BC_BALL; /* no longer feel the ball */ - } + movobj(uball, ballx, bally); + movobj(uchain, chainx, chainy); + } else if (control & BC_BALL) { + if (u.bc_felt & BC_BALL) { + if (u.bc_order == BCPOS_DIFFER) { /* ball by itself */ + levl[uball->ox][uball->oy].glyph = u.bglyph; + } else if (u.bc_order == BCPOS_BALL) { + if (u.bc_felt & BC_CHAIN) { /* know chain is there */ + map_object(uchain, 0); + } else { + levl[uball->ox][uball->oy].glyph = u.bglyph; + } + } + u.bc_felt &= ~BC_BALL; /* no longer feel the ball */ + } - /* Pick up glyph at new position. */ - u.bglyph = (ballx != chainx || bally != chainy) ? - levl[ballx][bally].glyph : u.cglyph; + /* Pick up glyph at new position. */ + u.bglyph = (ballx != chainx || bally != chainy) + ? levl[ballx][bally].glyph + : u.cglyph; - movobj(uball,ballx,bally); - } else if (control & BC_CHAIN) { - if (u.bc_felt & BC_CHAIN) { - if (u.bc_order == BCPOS_DIFFER) { - levl[uchain->ox][uchain->oy].glyph = u.cglyph; - } else if (u.bc_order == BCPOS_CHAIN) { - if (u.bc_felt & BC_BALL) { - map_object(uball, 0); - } else { - levl[uchain->ox][uchain->oy].glyph = u.cglyph; - } - } - u.bc_felt &= ~BC_CHAIN; - } - /* Pick up glyph at new position. */ - u.cglyph = (ballx != chainx || bally != chainy) ? - levl[chainx][chainy].glyph : u.bglyph; + movobj(uball, ballx, bally); + } else if (control & BC_CHAIN) { + if (u.bc_felt & BC_CHAIN) { + if (u.bc_order == BCPOS_DIFFER) { + levl[uchain->ox][uchain->oy].glyph = u.cglyph; + } else if (u.bc_order == BCPOS_CHAIN) { + if (u.bc_felt & BC_BALL) { + map_object(uball, 0); + } else { + levl[uchain->ox][uchain->oy].glyph = u.cglyph; + } + } + u.bc_felt &= ~BC_CHAIN; + } + /* Pick up glyph at new position. */ + u.cglyph = (ballx != chainx || bally != chainy) + ? levl[chainx][chainy].glyph + : u.bglyph; - movobj(uchain,chainx,chainy); - } + movobj(uchain, chainx, chainy); + } - u.bc_order = bc_order(); /* reset the order */ - } + u.bc_order = bc_order(); /* reset the order */ + } } else { - /* - * The hero is not blind. To make this work correctly, we need to - * pick up the ball and chain before the hero moves, then put them - * in their new positions after the hero moves. - */ - if (before) { - if (!control) { - /* - * Neither ball nor chain is moving, so remember which was - * on top until !before. Use the variable u.bc_order - * since it is only valid when blind. - */ - u.bc_order = bc_order(); - } + /* + * The hero is not blind. To make this work correctly, we need to + * pick up the ball and chain before the hero moves, then put them + * in their new positions after the hero moves. + */ + if (before) { + if (!control) { + /* + * Neither ball nor chain is moving, so remember which was + * on top until !before. Use the variable u.bc_order + * since it is only valid when blind. + */ + u.bc_order = bc_order(); + } - remove_object(uchain); - newsym(uchain->ox, uchain->oy); - if (!carried(uball)) { - remove_object(uball); - newsym(uball->ox, uball->oy); - } - } else { - int on_floor = !carried(uball); + remove_object(uchain); + newsym(uchain->ox, uchain->oy); + if (!carried(uball)) { + remove_object(uball); + newsym(uball->ox, uball->oy); + } + } else { + int on_floor = !carried(uball); - if ((control & BC_CHAIN) || - (!control && u.bc_order == BCPOS_CHAIN)) { - /* If the chain moved or nothing moved & chain on top. */ - if (on_floor) place_object(uball, ballx, bally); - place_object(uchain, chainx, chainy); /* chain on top */ - } else { - place_object(uchain, chainx, chainy); - if (on_floor) place_object(uball, ballx, bally); - /* ball on top */ - } - newsym(chainx, chainy); - if (on_floor) newsym(ballx, bally); - } + if ((control & BC_CHAIN) + || (!control && u.bc_order == BCPOS_CHAIN)) { + /* If the chain moved or nothing moved & chain on top. */ + if (on_floor) + place_object(uball, ballx, bally); + place_object(uchain, chainx, chainy); /* chain on top */ + } else { + place_object(uchain, chainx, chainy); + if (on_floor) + place_object(uball, ballx, bally); + /* ball on top */ + } + newsym(chainx, chainy); + if (on_floor) + newsym(ballx, bally); + } } } /* return TRUE if the caller needs to place the ball and chain down again * * Should not be called while swallowed. Should be called before movement, - * because we might want to move the ball or chain to the hero's old position. + * because we might want to move the ball or chain to the hero's old + * position. * * It is called if we are moving. It is also called if we are teleporting * *if* the ball doesn't move and we thus must drag the chain. It is not @@ -379,296 +386,299 @@ xchar ballx, bally, chainx, chainy; /* only matter !before */ */ boolean drag_ball(x, y, bc_control, ballx, bally, chainx, chainy, cause_delay, - allow_drag) + allow_drag) xchar x, y; int *bc_control; xchar *ballx, *bally, *chainx, *chainy; boolean *cause_delay; boolean allow_drag; { - struct trap *t = (struct trap *)0; - boolean already_in_rock; + struct trap *t = (struct trap *) 0; + boolean already_in_rock; - *ballx = uball->ox; - *bally = uball->oy; - *chainx = uchain->ox; - *chainy = uchain->oy; - *bc_control = 0; - *cause_delay = FALSE; + *ballx = uball->ox; + *bally = uball->oy; + *chainx = uchain->ox; + *chainy = uchain->oy; + *bc_control = 0; + *cause_delay = FALSE; - if (dist2(x, y, uchain->ox, uchain->oy) <= 2) { /* nothing moved */ - move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); - return TRUE; - } + if (dist2(x, y, uchain->ox, uchain->oy) <= 2) { /* nothing moved */ + move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); + return TRUE; + } - /* only need to move the chain? */ - if (carried(uball) || distmin(x, y, uball->ox, uball->oy) <= 2) { - xchar oldchainx = uchain->ox, oldchainy = uchain->oy; - *bc_control = BC_CHAIN; - move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); - if (carried(uball)) { - /* move chain only if necessary */ - if (distmin(x, y, uchain->ox, uchain->oy) > 1) { - *chainx = u.ux; - *chainy = u.uy; - } - return TRUE; - } + /* only need to move the chain? */ + if (carried(uball) || distmin(x, y, uball->ox, uball->oy) <= 2) { + xchar oldchainx = uchain->ox, oldchainy = uchain->oy; + *bc_control = BC_CHAIN; + move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); + if (carried(uball)) { + /* move chain only if necessary */ + if (distmin(x, y, uchain->ox, uchain->oy) > 1) { + *chainx = u.ux; + *chainy = u.uy; + } + return TRUE; + } #define CHAIN_IN_MIDDLE(chx, chy) \ - (distmin(x, y, chx, chy) <= 1 && distmin(chx, chy, uball->ox, uball->oy) <= 1) -#define IS_CHAIN_ROCK(x,y) \ - (IS_ROCK(levl[x][y].typ) || (IS_DOOR(levl[x][y].typ) && \ - (levl[x][y].doormask & (D_CLOSED|D_LOCKED)))) + (distmin(x, y, chx, chy) <= 1 \ + && distmin(chx, chy, uball->ox, uball->oy) <= 1) +#define IS_CHAIN_ROCK(x, y) \ + (IS_ROCK(levl[x][y].typ) \ + || (IS_DOOR(levl[x][y].typ) \ + && (levl[x][y].doormask & (D_CLOSED | D_LOCKED)))) /* Don't ever move the chain into solid rock. If we have to, then instead * undo the move_bc() and jump to the drag ball code. Note that this also * means the "cannot carry and drag" message will not appear, since unless we * moved at least two squares there is no possibility of the chain position * being in solid rock. */ -#define SKIP_TO_DRAG { *chainx = oldchainx; *chainy = oldchainy; \ - move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy); \ - goto drag; } - if (IS_CHAIN_ROCK(u.ux, u.uy) || IS_CHAIN_ROCK(*chainx, *chainy) - || IS_CHAIN_ROCK(uball->ox, uball->oy)) - already_in_rock = TRUE; - else - already_in_rock = FALSE; +#define SKIP_TO_DRAG \ + { \ + *chainx = oldchainx; \ + *chainy = oldchainy; \ + move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy); \ + goto drag; \ + } + if (IS_CHAIN_ROCK(u.ux, u.uy) || IS_CHAIN_ROCK(*chainx, *chainy) + || IS_CHAIN_ROCK(uball->ox, uball->oy)) + already_in_rock = TRUE; + else + already_in_rock = FALSE; - switch(dist2(x, y, uball->ox, uball->oy)) { - /* two spaces diagonal from ball, move chain inbetween */ - case 8: - *chainx = (uball->ox + x)/2; - *chainy = (uball->oy + y)/2; - if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) - SKIP_TO_DRAG; - break; + switch (dist2(x, y, uball->ox, uball->oy)) { + /* two spaces diagonal from ball, move chain inbetween */ + case 8: + *chainx = (uball->ox + x) / 2; + *chainy = (uball->oy + y) / 2; + if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) + SKIP_TO_DRAG; + break; - /* player is distance 2/1 from ball; move chain to one of the - * two spaces between - * @ - * __ - * 0 - */ - case 5: { - xchar tempx, tempy, tempx2, tempy2; + /* player is distance 2/1 from ball; move chain to one of the + * two spaces between + * @ + * __ + * 0 + */ + case 5: { + xchar tempx, tempy, tempx2, tempy2; - /* find position closest to current position of chain */ - /* no effect if current position is already OK */ - if (abs(x - uball->ox) == 1) { - tempx = x; - tempx2 = uball->ox; - tempy = tempy2 = (uball->oy + y)/2; - } else { - tempx = tempx2 = (uball->ox + x)/2; - tempy = y; - tempy2 = uball->oy; - } - if (IS_CHAIN_ROCK(tempx, tempy) && - !IS_CHAIN_ROCK(tempx2, tempy2) && - !already_in_rock) { - if (allow_drag) { - /* Avoid pathological case *if* not teleporting: - * 0 0_ - * _X move northeast -----> X@ - * @ - */ - if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 && - dist2(x, y, tempx, tempy) == 1) - SKIP_TO_DRAG; - /* Avoid pathological case *if* not teleporting: - * 0 0 - * _X move east -----> X_ - * @ @ - */ - if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 && - dist2(x, y, tempx, tempy) == 2) - SKIP_TO_DRAG; - } - *chainx = tempx2; - *chainy = tempy2; - } else if (!IS_CHAIN_ROCK(tempx, tempy) && - IS_CHAIN_ROCK(tempx2, tempy2) && - !already_in_rock) { - if (allow_drag) { - if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 && - dist2(x, y, tempx2, tempy2) == 1) - SKIP_TO_DRAG; - if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 && - dist2(x, y, tempx2, tempy2) == 2) - SKIP_TO_DRAG; - } - *chainx = tempx; - *chainy = tempy; - } else if (IS_CHAIN_ROCK(tempx, tempy) && - IS_CHAIN_ROCK(tempx2, tempy2) && - !already_in_rock) { - SKIP_TO_DRAG; - } else if (dist2(tempx, tempy, uchain->ox, uchain->oy) < - dist2(tempx2, tempy2, uchain->ox, uchain->oy) || - ((dist2(tempx, tempy, uchain->ox, uchain->oy) == - dist2(tempx2, tempy2, uchain->ox, uchain->oy)) && rn2(2))) { - *chainx = tempx; - *chainy = tempy; - } else { - *chainx = tempx2; - *chainy = tempy2; - } - break; - } + /* find position closest to current position of chain */ + /* no effect if current position is already OK */ + if (abs(x - uball->ox) == 1) { + tempx = x; + tempx2 = uball->ox; + tempy = tempy2 = (uball->oy + y) / 2; + } else { + tempx = tempx2 = (uball->ox + x) / 2; + tempy = y; + tempy2 = uball->oy; + } + if (IS_CHAIN_ROCK(tempx, tempy) && !IS_CHAIN_ROCK(tempx2, tempy2) + && !already_in_rock) { + if (allow_drag) { + /* Avoid pathological case *if* not teleporting: + * 0 0_ + * _X move northeast -----> X@ + * @ + */ + if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 + && dist2(x, y, tempx, tempy) == 1) + SKIP_TO_DRAG; + /* Avoid pathological case *if* not teleporting: + * 0 0 + * _X move east -----> X_ + * @ @ + */ + if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 + && dist2(x, y, tempx, tempy) == 2) + SKIP_TO_DRAG; + } + *chainx = tempx2; + *chainy = tempy2; + } else if (!IS_CHAIN_ROCK(tempx, tempy) + && IS_CHAIN_ROCK(tempx2, tempy2) && !already_in_rock) { + if (allow_drag) { + if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 + && dist2(x, y, tempx2, tempy2) == 1) + SKIP_TO_DRAG; + if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 + && dist2(x, y, tempx2, tempy2) == 2) + SKIP_TO_DRAG; + } + *chainx = tempx; + *chainy = tempy; + } else if (IS_CHAIN_ROCK(tempx, tempy) + && IS_CHAIN_ROCK(tempx2, tempy2) && !already_in_rock) { + SKIP_TO_DRAG; + } else if (dist2(tempx, tempy, uchain->ox, uchain->oy) + < dist2(tempx2, tempy2, uchain->ox, uchain->oy) + || ((dist2(tempx, tempy, uchain->ox, uchain->oy) + == dist2(tempx2, tempy2, uchain->ox, uchain->oy)) + && rn2(2))) { + *chainx = tempx; + *chainy = tempy; + } else { + *chainx = tempx2; + *chainy = tempy2; + } + break; + } - /* ball is two spaces horizontal or vertical from player; move*/ - /* chain inbetween *unless* current chain position is OK */ - case 4: - if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy)) - break; - *chainx = (x + uball->ox)/2; - *chainy = (y + uball->oy)/2; - if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) - SKIP_TO_DRAG; - break; - - /* ball is one space diagonal from player. Check for the - * following special case: - * @ - * _ moving southwest becomes @_ - * 0 0 - * (This will also catch teleporting that happens to resemble - * this case, but oh well.) Otherwise fall through. - */ - case 2: - if (dist2(x, y, uball->ox, uball->oy) == 2 && - dist2(x, y, uchain->ox, uchain->oy) == 4) { - if (uchain->oy == y) - *chainx = uball->ox; - else - *chainy = uball->oy; - if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) - SKIP_TO_DRAG; - break; - } - /* fall through */ - case 1: - case 0: - /* do nothing if possible */ - if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy)) - break; - /* otherwise try to drag chain to player's old position */ - if (CHAIN_IN_MIDDLE(u.ux, u.uy)) { - *chainx = u.ux; - *chainy = u.uy; - break; - } - /* otherwise use player's new position (they must have - teleported, for this to happen) */ - *chainx = x; - *chainy = y; - break; - - default: impossible("bad chain movement"); - break; - } + /* ball is two spaces horizontal or vertical from player; move*/ + /* chain inbetween *unless* current chain position is OK */ + case 4: + if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy)) + break; + *chainx = (x + uball->ox) / 2; + *chainy = (y + uball->oy) / 2; + if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) + SKIP_TO_DRAG; + break; + + /* ball is one space diagonal from player. Check for the + * following special case: + * @ + * _ moving southwest becomes @_ + * 0 0 + * (This will also catch teleporting that happens to resemble + * this case, but oh well.) Otherwise fall through. + */ + case 2: + if (dist2(x, y, uball->ox, uball->oy) == 2 + && dist2(x, y, uchain->ox, uchain->oy) == 4) { + if (uchain->oy == y) + *chainx = uball->ox; + else + *chainy = uball->oy; + if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock) + SKIP_TO_DRAG; + break; + } + /* fall through */ + case 1: + case 0: + /* do nothing if possible */ + if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy)) + break; + /* otherwise try to drag chain to player's old position */ + if (CHAIN_IN_MIDDLE(u.ux, u.uy)) { + *chainx = u.ux; + *chainy = u.uy; + break; + } + /* otherwise use player's new position (they must have + teleported, for this to happen) */ + *chainx = x; + *chainy = y; + break; + + default: + impossible("bad chain movement"); + break; + } #undef SKIP_TO_DRAG #undef CHAIN_IN_MIDDLE - return TRUE; - } + return TRUE; + } drag: - if (near_capacity() > SLT_ENCUMBER && dist2(x, y, u.ux, u.uy) <= 2) { - You("cannot %sdrag the heavy iron ball.", - invent ? "carry all that and also " : ""); - nomul(0); - return FALSE; - } + if (near_capacity() > SLT_ENCUMBER && dist2(x, y, u.ux, u.uy) <= 2) { + You("cannot %sdrag the heavy iron ball.", + invent ? "carry all that and also " : ""); + nomul(0); + return FALSE; + } - if ((is_pool(uchain->ox, uchain->oy) && - /* water not mere continuation of previous water */ - (levl[uchain->ox][uchain->oy].typ == POOL || - !is_pool(uball->ox, uball->oy) || - levl[uball->ox][uball->oy].typ == POOL)) - || ((t = t_at(uchain->ox, uchain->oy)) && - (t->ttyp == PIT || - t->ttyp == SPIKED_PIT || - t->ttyp == HOLE || - t->ttyp == TRAPDOOR)) ) { + if ((is_pool(uchain->ox, uchain->oy) && + /* water not mere continuation of previous water */ + (levl[uchain->ox][uchain->oy].typ == POOL + || !is_pool(uball->ox, uball->oy) + || levl[uball->ox][uball->oy].typ == POOL)) + || ((t = t_at(uchain->ox, uchain->oy)) + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == HOLE + || t->ttyp == TRAPDOOR))) { + if (Levitation) { + You_feel("a tug from the iron ball."); + if (t) + t->tseen = 1; + } else { + struct monst *victim; - if (Levitation) { - You_feel("a tug from the iron ball."); - if (t) t->tseen = 1; - } else { - struct monst *victim; + You("are jerked back by the iron ball!"); + if ((victim = m_at(uchain->ox, uchain->oy)) != 0) { + int tmp; - You("are jerked back by the iron ball!"); - if ((victim = m_at(uchain->ox, uchain->oy)) != 0) { - int tmp; + tmp = -2 + Luck + find_mac(victim); + tmp += omon_adj(victim, uball, TRUE); + if (tmp >= rnd(20)) + (void) hmon(victim, uball, HMON_DRAGGED); + else + miss(xname(uball), victim); - tmp = -2 + Luck + find_mac(victim); - tmp += omon_adj(victim, uball, TRUE); - if (tmp >= rnd(20)) - (void) hmon(victim, uball, HMON_DRAGGED); - else - miss(xname(uball), victim); + } /* now check again in case mon died */ + if (!m_at(uchain->ox, uchain->oy)) { + u.ux = uchain->ox; + u.uy = uchain->oy; + newsym(u.ux0, u.uy0); + } + nomul(0); - } /* now check again in case mon died */ - if (!m_at(uchain->ox, uchain->oy)) { - u.ux = uchain->ox; - u.uy = uchain->oy; - newsym(u.ux0, u.uy0); - } - nomul(0); + *bc_control = BC_BALL; + move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); + *ballx = uchain->ox; + *bally = uchain->oy; + move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy); + spoteffects(TRUE); + return FALSE; + } + } - *bc_control = BC_BALL; - move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); - *ballx = uchain->ox; - *bally = uchain->oy; - move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy); - spoteffects(TRUE); - return FALSE; - } - } + *bc_control = BC_BALL | BC_CHAIN; - *bc_control = BC_BALL|BC_CHAIN; + move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); + if (dist2(x, y, u.ux, u.uy) > 2) { + /* Awful case: we're still in range of the ball, so we thought we + * could only move the chain, but it turned out that the target + * square for the chain was rock, so we had to drag it instead. + * But we can't drag it either, because we teleported and are more + * than one square from our old position. Revert to the teleport + * behavior. + */ + *ballx = *chainx = x; + *bally = *chainy = y; + } else { + xchar newchainx = u.ux, newchainy = u.uy; - move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy); - if (dist2(x, y, u.ux, u.uy) > 2) { - /* Awful case: we're still in range of the ball, so we thought we - * could only move the chain, but it turned out that the target - * square for the chain was rock, so we had to drag it instead. - * But we can't drag it either, because we teleported and are more - * than one square from our old position. Revert to the teleport - * behavior. - */ - *ballx = *chainx = x; - *bally = *chainy = y; - } else { - xchar newchainx = u.ux, newchainy = u.uy; + /* + * Generally, chain moves to hero's previous location and ball + * moves to chain's previous location, except that we try to + * keep the chain directly between the hero and the ball. But, + * take the simple approach if the hero's previous location or + * the potential between location is inaccessible. + */ + if (dist2(x, y, uchain->ox, uchain->oy) == 4 + && !IS_CHAIN_ROCK(newchainx, newchainy)) { + newchainx = (x + uchain->ox) / 2; + newchainy = (y + uchain->oy) / 2; + if (IS_CHAIN_ROCK(newchainx, newchainy)) { + /* don't let chain move to inaccessible location */ + newchainx = u.ux; + newchainy = u.uy; + } + } - /* - * Generally, chain moves to hero's previous location and ball - * moves to chain's previous location, except that we try to - * keep the chain directly between the hero and the ball. But, - * take the simple approach if the hero's previous location or - * the potential between location is inaccessible. - */ - if (dist2(x, y, uchain->ox, uchain->oy) == 4 && - !IS_CHAIN_ROCK(newchainx, newchainy)) { - newchainx = (x + uchain->ox)/2; - newchainy = (y + uchain->oy)/2; - if (IS_CHAIN_ROCK(newchainx, newchainy)) { - /* don't let chain move to inaccessible location */ - newchainx = u.ux; - newchainy = u.uy; - } - } - - *ballx = uchain->ox; - *bally = uchain->oy; - *chainx = newchainx; - *chainy = newchainy; - } + *ballx = uchain->ox; + *bally = uchain->oy; + *chainx = newchainx; + *chainy = newchainy; + } #undef IS_CHAIN_ROCK - *cause_delay = TRUE; - return TRUE; + *cause_delay = TRUE; + return TRUE; } /* @@ -685,147 +695,144 @@ drop_ball(x, y) xchar x, y; { if (Blind) { - u.bc_order = bc_order(); /* get the order */ - /* pick up glyph */ - u.bglyph = (u.bc_order) ? u.cglyph : levl[x][y].glyph; + u.bc_order = bc_order(); /* get the order */ + /* pick up glyph */ + u.bglyph = (u.bc_order) ? u.cglyph : levl[x][y].glyph; } if (x != u.ux || y != u.uy) { - struct trap *t; - const char *pullmsg = "The ball pulls you out of the %s!"; + struct trap *t; + const char *pullmsg = "The ball pulls you out of the %s!"; - if (u.utrap && u.utraptype != TT_INFLOOR && u.utraptype != TT_BURIEDBALL) { - switch(u.utraptype) { - case TT_PIT: - pline(pullmsg, "pit"); - break; - case TT_WEB: - pline(pullmsg, "web"); - pline_The("web is destroyed!"); - deltrap(t_at(u.ux,u.uy)); - break; - case TT_LAVA: - pline(pullmsg, "lava"); - break; - case TT_BEARTRAP: { - register long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; - pline(pullmsg, "bear trap"); - set_wounded_legs(side, rn1(1000, 500)); - if (!u.usteed) { - Your("%s %s is severely damaged.", - (side == LEFT_SIDE) ? "left" : "right", - body_part(LEG)); - losehp(Maybe_Half_Phys(2), - "leg damage from being pulled out of a bear trap", - KILLED_BY); - } - break; - } - } - u.utrap = 0; - fill_pit(u.ux, u.uy); - } + if (u.utrap && u.utraptype != TT_INFLOOR + && u.utraptype != TT_BURIEDBALL) { + switch (u.utraptype) { + case TT_PIT: + pline(pullmsg, "pit"); + break; + case TT_WEB: + pline(pullmsg, "web"); + pline_The("web is destroyed!"); + deltrap(t_at(u.ux, u.uy)); + break; + case TT_LAVA: + pline(pullmsg, "lava"); + break; + case TT_BEARTRAP: { + register long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; + pline(pullmsg, "bear trap"); + set_wounded_legs(side, rn1(1000, 500)); + if (!u.usteed) { + Your("%s %s is severely damaged.", + (side == LEFT_SIDE) ? "left" : "right", + body_part(LEG)); + losehp(Maybe_Half_Phys(2), + "leg damage from being pulled out of a bear trap", + KILLED_BY); + } + break; + } + } + u.utrap = 0; + fill_pit(u.ux, u.uy); + } - u.ux0 = u.ux; - u.uy0 = u.uy; - if (!Levitation && !MON_AT(x, y) && !u.utrap && - (is_pool(x, y) || - ((t = t_at(x, y)) && - (t->ttyp == PIT || t->ttyp == SPIKED_PIT || - t->ttyp == TRAPDOOR || t->ttyp == HOLE)))) { - u.ux = x; - u.uy = y; - } else { - u.ux = x - u.dx; - u.uy = y - u.dy; - } - vision_full_recalc = 1; /* hero has moved, recalculate vision later */ + u.ux0 = u.ux; + u.uy0 = u.uy; + if (!Levitation && !MON_AT(x, y) && !u.utrap + && (is_pool(x, y) + || ((t = t_at(x, y)) + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT + || t->ttyp == TRAPDOOR || t->ttyp == HOLE)))) { + u.ux = x; + u.uy = y; + } else { + u.ux = x - u.dx; + u.uy = y - u.dy; + } + vision_full_recalc = 1; /* hero has moved, recalculate vision later */ - if (Blind) { - /* drop glyph under the chain */ - if (u.bc_felt & BC_CHAIN) - levl[uchain->ox][uchain->oy].glyph = u.cglyph; - u.bc_felt = 0; /* feel nothing */ - /* pick up new glyph */ - u.cglyph = (u.bc_order) ? u.bglyph : levl[u.ux][u.uy].glyph; - } - movobj(uchain,u.ux,u.uy); /* has a newsym */ - if (Blind) { - u.bc_order = bc_order(); - } - newsym(u.ux0,u.uy0); /* clean up old position */ - if (u.ux0 != u.ux || u.uy0 != u.uy) { - spoteffects(TRUE); - sokoban_guilt(); - } + if (Blind) { + /* drop glyph under the chain */ + if (u.bc_felt & BC_CHAIN) + levl[uchain->ox][uchain->oy].glyph = u.cglyph; + u.bc_felt = 0; /* feel nothing */ + /* pick up new glyph */ + u.cglyph = (u.bc_order) ? u.bglyph : levl[u.ux][u.uy].glyph; + } + movobj(uchain, u.ux, u.uy); /* has a newsym */ + if (Blind) { + u.bc_order = bc_order(); + } + newsym(u.ux0, u.uy0); /* clean up old position */ + if (u.ux0 != u.ux || u.uy0 != u.uy) { + spoteffects(TRUE); + sokoban_guilt(); + } } } - STATIC_OVL void litter() { - struct obj *otmp = invent, *nextobj; - int capacity = weight_cap(); + struct obj *otmp = invent, *nextobj; + int capacity = weight_cap(); - while (otmp) { - nextobj = otmp->nobj; - if ((otmp != uball) && (rnd(capacity) <= (int)otmp->owt)) { - if (canletgo(otmp, "")) { - pline("%s you down the stairs.", - Yobjnam2(otmp, "follow")); - dropx(otmp); - } - } - otmp = nextobj; - } + while (otmp) { + nextobj = otmp->nobj; + if ((otmp != uball) && (rnd(capacity) <= (int) otmp->owt)) { + if (canletgo(otmp, "")) { + pline("%s you down the stairs.", Yobjnam2(otmp, "follow")); + dropx(otmp); + } + } + otmp = nextobj; + } } void drag_down() { - boolean forward; - uchar dragchance = 3; + boolean forward; + uchar dragchance = 3; - /* - * Assume that the ball falls forward if: - * - * a) the character is wielding it, or - * b) the character has both hands available to hold it (i.e. is - * not wielding any weapon), or - * c) (perhaps) it falls forward out of his non-weapon hand - */ + /* + * Assume that the ball falls forward if: + * + * a) the character is wielding it, or + * b) the character has both hands available to hold it (i.e. is + * not wielding any weapon), or + * c) (perhaps) it falls forward out of his non-weapon hand + */ - forward = carried(uball) && (uwep == uball || !uwep || !rn2(3)); + forward = carried(uball) && (uwep == uball || !uwep || !rn2(3)); - if (carried(uball)) - You("lose your grip on the iron ball."); + if (carried(uball)) + You("lose your grip on the iron ball."); - if (forward) { - if(rn2(6)) { - pline_The("iron ball drags you downstairs!"); - losehp(Maybe_Half_Phys(rnd(6)), - "dragged downstairs by an iron ball", - NO_KILLER_PREFIX); - litter(); - } - } else { - if(rn2(2)) { - pline_The("iron ball smacks into you!"); - losehp(Maybe_Half_Phys(rnd(20)), - "iron ball collision", KILLED_BY_AN); - exercise(A_STR, FALSE); - dragchance -= 2; - } - if( (int) dragchance >= rnd(6)) { - pline_The("iron ball drags you downstairs!"); - losehp(Maybe_Half_Phys(rnd(3)), - "dragged downstairs by an iron ball", - NO_KILLER_PREFIX); - exercise(A_STR, FALSE); - litter(); - } - } + if (forward) { + if (rn2(6)) { + pline_The("iron ball drags you downstairs!"); + losehp(Maybe_Half_Phys(rnd(6)), + "dragged downstairs by an iron ball", NO_KILLER_PREFIX); + litter(); + } + } else { + if (rn2(2)) { + pline_The("iron ball smacks into you!"); + losehp(Maybe_Half_Phys(rnd(20)), "iron ball collision", + KILLED_BY_AN); + exercise(A_STR, FALSE); + dragchance -= 2; + } + if ((int) dragchance >= rnd(6)) { + pline_The("iron ball drags you downstairs!"); + losehp(Maybe_Half_Phys(rnd(3)), + "dragged downstairs by an iron ball", NO_KILLER_PREFIX); + exercise(A_STR, FALSE); + litter(); + } + } } /*ball.c*/ diff --git a/src/bones.c b/src/bones.c index c63d50f5c..74d4a5a8c 100644 --- a/src/bones.c +++ b/src/bones.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 bones.c $NHDT-Date: 1426465433 2015/03/16 00:23:53 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.45 $ */ +/* NetHack 3.6 bones.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.59 $ */ /* NetHack 3.6 bones.c $Date: 2012/02/16 02:40:24 $ $Revision: 1.39 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,33 +6,34 @@ #include "hack.h" #include "lev.h" -extern char bones[]; /* from files.c */ +extern char bones[]; /* from files.c */ #ifdef MFLOPPY extern long bytes_counted; #endif STATIC_DCL boolean FDECL(no_bones_level, (d_level *)); STATIC_DCL void FDECL(goodfruit, (int)); -STATIC_DCL void FDECL(resetobjs,(struct obj *,BOOLEAN_P)); +STATIC_DCL void FDECL(resetobjs, (struct obj *, BOOLEAN_P)); STATIC_DCL boolean FDECL(fixuporacle, (struct monst *)); STATIC_OVL boolean no_bones_level(lev) d_level *lev; { - extern d_level save_dlevel; /* in do.c */ - s_level *sptr; + extern d_level save_dlevel; /* in do.c */ + s_level *sptr; - if (ledger_no(&save_dlevel)) assign_level(lev, &save_dlevel); + if (ledger_no(&save_dlevel)) + assign_level(lev, &save_dlevel); - return (boolean)(((sptr = Is_special(lev)) != 0 && !sptr->boneid) - || !dungeons[lev->dnum].boneid - /* no bones on the last or multiway branch levels */ - /* in any dungeon (level 1 isn't multiway). */ - || Is_botlevel(lev) || (Is_branchlev(lev) && lev->dlevel > 1) - /* no bones in the invocation level */ - || (In_hell(lev) && lev->dlevel == dunlevs_in_dungeon(lev) - 1) - ); + return (boolean)( + ((sptr = Is_special(lev)) != 0 && !sptr->boneid) + || !dungeons[lev->dnum].boneid + /* no bones on the last or multiway branch levels */ + /* in any dungeon (level 1 isn't multiway). */ + || Is_botlevel(lev) || (Is_branchlev(lev) && lev->dlevel > 1) + /* no bones in the invocation level */ + || (In_hell(lev) && lev->dlevel == dunlevs_in_dungeon(lev) - 1)); } /* Call this function for each fruit object saved in the bones level: it marks @@ -44,133 +45,135 @@ STATIC_OVL void goodfruit(id) int id; { - register struct fruit *f; + register struct fruit *f; - for(f=ffruit; f; f=f->nextf) { - if(f->fid == -id) { - f->fid = id; - return; - } - } + for (f = ffruit; f; f = f->nextf) { + if (f->fid == -id) { + f->fid = id; + return; + } + } } STATIC_OVL void -resetobjs(ochain,restore) +resetobjs(ochain, restore) struct obj *ochain; boolean restore; { - struct obj *otmp, *nobj; + struct obj *otmp, *nobj; - for (otmp = ochain; otmp; otmp = nobj) { - nobj = otmp->nobj; - if (otmp->cobj) - resetobjs(otmp->cobj,restore); - if (otmp->in_use) { - obj_extract_self(otmp); - dealloc_obj(otmp); - continue; - } + for (otmp = ochain; otmp; otmp = nobj) { + nobj = otmp->nobj; + if (otmp->cobj) + resetobjs(otmp->cobj, restore); + if (otmp->in_use) { + obj_extract_self(otmp); + dealloc_obj(otmp); + continue; + } - if (restore) { - /* artifact bookeeping needs to be done during - restore; other fixups are done while saving */ - if (otmp->oartifact) { - if (exist_artifact(otmp->otyp, safe_oname(otmp)) || - is_quest_artifact(otmp)) { - /* prevent duplicate--revert to ordinary obj */ - otmp->oartifact = 0; - if (has_oname(otmp)) - free_oname(otmp); - } else { - artifact_exists(otmp, safe_oname(otmp), TRUE); - } - } else if (has_oname(otmp)) { - sanitize_name(ONAME(otmp)); - } - } else { /* saving */ - /* do not zero out o_ids for ghost levels anymore */ + if (restore) { + /* artifact bookeeping needs to be done during + restore; other fixups are done while saving */ + if (otmp->oartifact) { + if (exist_artifact(otmp->otyp, safe_oname(otmp)) + || is_quest_artifact(otmp)) { + /* prevent duplicate--revert to ordinary obj */ + otmp->oartifact = 0; + if (has_oname(otmp)) + free_oname(otmp); + } else { + artifact_exists(otmp, safe_oname(otmp), TRUE); + } + } else if (has_oname(otmp)) { + sanitize_name(ONAME(otmp)); + } + } else { /* saving */ + /* do not zero out o_ids for ghost levels anymore */ - if(objects[otmp->otyp].oc_uses_known) otmp->known = 0; - otmp->dknown = otmp->bknown = 0; - otmp->rknown = 0; - otmp->lknown = 0; - otmp->cknown = 0; - otmp->invlet = 0; - otmp->no_charge = 0; - otmp->was_thrown = 0; + if (objects[otmp->otyp].oc_uses_known) + otmp->known = 0; + otmp->dknown = otmp->bknown = 0; + otmp->rknown = 0; + otmp->lknown = 0; + otmp->cknown = 0; + otmp->invlet = 0; + otmp->no_charge = 0; + otmp->was_thrown = 0; - /* strip user-supplied names */ - /* Statue and some corpse names are left intact, - presumeably in case they came from score file. - [TODO: this ought to be done differently--names - which came from such a source or came from any - stoned or killed monster should be flagged in - some manner; then we could just check the flag - here and keep "real" names (dead pets, &c) while - discarding player notes attached to statues.] */ - if (has_oname(otmp) && - !(otmp->oartifact || otmp->otyp == STATUE || - (otmp->otyp == CORPSE && - otmp->corpsenm >= SPECIAL_PM))) { - free_oname(otmp); - } + /* strip user-supplied names */ + /* Statue and some corpse names are left intact, + presumeably in case they came from score file. + [TODO: this ought to be done differently--names + which came from such a source or came from any + stoned or killed monster should be flagged in + some manner; then we could just check the flag + here and keep "real" names (dead pets, &c) while + discarding player notes attached to statues.] */ + if (has_oname(otmp) + && !(otmp->oartifact || otmp->otyp == STATUE + || (otmp->otyp == CORPSE + && otmp->corpsenm >= SPECIAL_PM))) { + free_oname(otmp); + } - if (otmp->otyp == SLIME_MOLD) goodfruit(otmp->spe); + if (otmp->otyp == SLIME_MOLD) + goodfruit(otmp->spe); #ifdef MAIL - else if (otmp->otyp == SCR_MAIL) otmp->spe = 1; + else if (otmp->otyp == SCR_MAIL) + otmp->spe = 1; #endif - else if (otmp->otyp == EGG) otmp->spe = 0; - else if (otmp->otyp == TIN) { - /* make tins of unique monster's meat be empty */ - if (otmp->corpsenm >= LOW_PM && - unique_corpstat(&mons[otmp->corpsenm])) - otmp->corpsenm = NON_PM; - } else if (otmp->otyp == CORPSE || - otmp->otyp == STATUE) { - int mnum = otmp->corpsenm; + else if (otmp->otyp == EGG) + otmp->spe = 0; + else if (otmp->otyp == TIN) { + /* make tins of unique monster's meat be empty */ + if (otmp->corpsenm >= LOW_PM + && unique_corpstat(&mons[otmp->corpsenm])) + otmp->corpsenm = NON_PM; + } else if (otmp->otyp == CORPSE || otmp->otyp == STATUE) { + int mnum = otmp->corpsenm; - /* Discard incarnation details of unique - monsters (by passing null instead of otmp - for object), shopkeepers (by passing false - for revival flag), temple priests, and - vault guards in order to prevent corpse - revival or statue reanimation. */ - if (has_omonst(otmp) && - cant_revive(&mnum, FALSE, (struct obj *)0)) { - free_omonst(otmp); - /* mnum is now either human_zombie or - doppelganger; for corpses of uniques, - we need to force the transformation - now rather than wait until a revival - attempt, otherwise eating this corpse - would behave as if it remains unique */ - if (mnum == PM_DOPPELGANGER && - otmp->otyp == CORPSE) - set_corpsenm(otmp, mnum); - } - } else if (otmp->otyp == AMULET_OF_YENDOR) { - /* no longer the real Amulet */ - otmp->otyp = FAKE_AMULET_OF_YENDOR; - curse(otmp); - } else if (otmp->otyp == CANDELABRUM_OF_INVOCATION) { - if (otmp->lamplit) - end_burn(otmp, TRUE); - otmp->otyp = WAX_CANDLE; - otmp->age = 50L; /* assume used */ - if (otmp->spe > 0) - otmp->quan = (long)otmp->spe; - otmp->spe = 0; - otmp->owt = weight(otmp); - curse(otmp); - } else if (otmp->otyp == BELL_OF_OPENING) { - otmp->otyp = BELL; - curse(otmp); - } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) { - otmp->otyp = SPE_BLANK_PAPER; - curse(otmp); - } - } - } + /* Discard incarnation details of unique + monsters (by passing null instead of otmp + for object), shopkeepers (by passing false + for revival flag), temple priests, and + vault guards in order to prevent corpse + revival or statue reanimation. */ + if (has_omonst(otmp) + && cant_revive(&mnum, FALSE, (struct obj *) 0)) { + free_omonst(otmp); + /* mnum is now either human_zombie or + doppelganger; for corpses of uniques, + we need to force the transformation + now rather than wait until a revival + attempt, otherwise eating this corpse + would behave as if it remains unique */ + if (mnum == PM_DOPPELGANGER && otmp->otyp == CORPSE) + set_corpsenm(otmp, mnum); + } + } else if (otmp->otyp == AMULET_OF_YENDOR) { + /* no longer the real Amulet */ + otmp->otyp = FAKE_AMULET_OF_YENDOR; + curse(otmp); + } else if (otmp->otyp == CANDELABRUM_OF_INVOCATION) { + if (otmp->lamplit) + end_burn(otmp, TRUE); + otmp->otyp = WAX_CANDLE; + otmp->age = 50L; /* assume used */ + if (otmp->spe > 0) + otmp->quan = (long) otmp->spe; + otmp->spe = 0; + otmp->owt = weight(otmp); + curse(otmp); + } else if (otmp->otyp == BELL_OF_OPENING) { + otmp->otyp = BELL; + curse(otmp); + } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) { + otmp->otyp = SPE_BLANK_PAPER; + curse(otmp); + } + } + } } /* while loading bones, strip out text possibly supplied by old player @@ -179,25 +182,26 @@ void sanitize_name(namebuf) char *namebuf; { - int c; - boolean strip_8th_bit = !strcmp(windowprocs.name, "tty") && - !iflags.wc_eight_bit_input; + int c; + boolean strip_8th_bit = + !strcmp(windowprocs.name, "tty") && !iflags.wc_eight_bit_input; - /* it's tempting to skip this for single-user platforms, since - only the current player could have left these bones--except - things like "hearse" and other bones exchange schemes make - that assumption false */ - while (*namebuf) { - c = *namebuf & 0177; - if (c < ' ' || c == '\177') { - /* non-printable or undesireable */ - *namebuf = '.'; - } else if (c != *namebuf) { - /* expected to be printable if user wants such things */ - if (strip_8th_bit) *namebuf = '_'; - } - ++namebuf; - } + /* it's tempting to skip this for single-user platforms, since + only the current player could have left these bones--except + things like "hearse" and other bones exchange schemes make + that assumption false */ + while (*namebuf) { + c = *namebuf & 0177; + if (c < ' ' || c == '\177') { + /* non-printable or undesireable */ + *namebuf = '.'; + } else if (c != *namebuf) { + /* expected to be printable if user wants such things */ + if (strip_8th_bit) + *namebuf = '_'; + } + ++namebuf; + } } /* called by savebones(); also by finish_paybill(shk.c) */ @@ -207,29 +211,32 @@ struct monst *mtmp; struct obj *cont; int x, y; { - struct obj *otmp; + struct obj *otmp; - u.twoweap = 0; /* ensure curse() won't cause swapwep to drop twice */ - while ((otmp = invent) != 0) { - obj_extract_self(otmp); - obj_no_longer_held(otmp); + u.twoweap = 0; /* ensure curse() won't cause swapwep to drop twice */ + while ((otmp = invent) != 0) { + obj_extract_self(otmp); + obj_no_longer_held(otmp); - otmp->owornmask = 0; - /* lamps don't go out when dropped */ - if ((cont || artifact_light(otmp)) && obj_is_burning(otmp)) - end_burn(otmp, TRUE); /* smother in statue */ + otmp->owornmask = 0; + /* lamps don't go out when dropped */ + if ((cont || artifact_light(otmp)) && obj_is_burning(otmp)) + end_burn(otmp, TRUE); /* smother in statue */ - if(otmp->otyp == SLIME_MOLD) goodfruit(otmp->spe); + if (otmp->otyp == SLIME_MOLD) + goodfruit(otmp->spe); - if(rn2(5)) curse(otmp); - if (mtmp) - (void) add_to_minv(mtmp, otmp); - else if (cont) - (void) add_to_container(cont, otmp); - else - place_object(otmp, x, y); - } - if (cont) cont->owt = weight(cont); + if (rn2(5)) + curse(otmp); + if (mtmp) + (void) add_to_minv(mtmp, otmp); + else if (cont) + (void) add_to_container(cont, otmp); + else + place_object(otmp, x, y); + } + if (cont) + cont->owt = weight(cont); } /* possibly restore oracle's room and/or put her back inside it; returns @@ -246,12 +253,12 @@ struct monst *oracle; activate in such situation hence she won't fall to another level; however, that could change so be prepared to cope with such things */ if (!Is_oracle_level(&u.uz)) - return FALSE; + return FALSE; oracle->mpeaceful = 1; o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET; if (o_ridx >= 0 && rooms[o_ridx].rtype == DELPHI) - return TRUE; /* no fixup needed */ + return TRUE; /* no fixup needed */ /* * The Oracle isn't in DELPHI room. Either hero entered her chamber @@ -262,52 +269,57 @@ struct monst *oracle; /* find original delphi chamber; should always succeed */ for (ridx = 0; ridx < SIZE(rooms); ++ridx) - if (rooms[ridx].orig_rtype == DELPHI) break; + if (rooms[ridx].orig_rtype == DELPHI) + break; if (o_ridx != ridx && ridx < SIZE(rooms)) { - /* room found and she's not not in it, so try to move her there */ - cc.x = (rooms[ridx].lx + rooms[ridx].hx) / 2; - cc.y = (rooms[ridx].ly + rooms[ridx].hy) / 2; - if (enexto(&cc, cc.x, cc.y, oracle->data)) { - rloc_to(oracle, cc.x, cc.y); - o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET; - } - /* [if her room is already full, she might end up outside; - that's ok, next hero just won't get any welcome message, - same as used to happen before this fixup was introduced] */ + /* room found and she's not not in it, so try to move her there */ + cc.x = (rooms[ridx].lx + rooms[ridx].hx) / 2; + cc.y = (rooms[ridx].ly + rooms[ridx].hy) / 2; + if (enexto(&cc, cc.x, cc.y, oracle->data)) { + rloc_to(oracle, cc.x, cc.y); + o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET; + } + /* [if her room is already full, she might end up outside; + that's ok, next hero just won't get any welcome message, + same as used to happen before this fixup was introduced] */ } - if (ridx == o_ridx) /* if she's in her room, mark it as such */ - rooms[ridx].rtype = DELPHI; - return TRUE; /* keep oracle in new bones file */ + if (ridx == o_ridx) /* if she's in her room, mark it as such */ + rooms[ridx].rtype = DELPHI; + return TRUE; /* keep oracle in new bones file */ } /* check whether bones are feasible */ boolean can_make_bones() { - register struct trap *ttmp; + register struct trap *ttmp; - if (!flags.bones) return FALSE; - if (ledger_no(&u.uz) <= 0 || ledger_no(&u.uz) > maxledgerno()) - return FALSE; - if (no_bones_level(&u.uz)) - return FALSE; /* no bones for specific levels */ - if (u.uswallow) { - return FALSE; /* no bones when swallowed */ - } - if (!Is_branchlev(&u.uz)) { - /* no bones on non-branches with portals */ - for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) - if (ttmp->ttyp == MAGIC_PORTAL) return FALSE; - } + if (!flags.bones) + return FALSE; + if (ledger_no(&u.uz) <= 0 || ledger_no(&u.uz) > maxledgerno()) + return FALSE; + if (no_bones_level(&u.uz)) + return FALSE; /* no bones for specific levels */ + if (u.uswallow) { + return FALSE; /* no bones when swallowed */ + } + if (!Is_branchlev(&u.uz)) { + /* no bones on non-branches with portals */ + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) + if (ttmp->ttyp == MAGIC_PORTAL) + return FALSE; + } - if(depth(&u.uz) <= 0 || /* bulletproofing for endgame */ - (!rn2(1 + (depth(&u.uz)>>2)) /* fewer ghosts on low levels */ - && !wizard)) return FALSE; - /* don't let multiple restarts generate multiple copies of objects - * in bones files */ - if (discover) return FALSE; - return TRUE; + if (depth(&u.uz) <= 0 || /* bulletproofing for endgame */ + (!rn2(1 + (depth(&u.uz) >> 2)) /* fewer ghosts on low levels */ + && !wizard)) + return FALSE; + /* don't let multiple restarts generate multiple copies of objects + * in bones files */ + if (discover) + return FALSE; + return TRUE; } /* save bones and possessions of a deceased adventurer */ @@ -317,305 +329,317 @@ int how; time_t when; struct obj *corpse; { - int fd, x, y; - struct trap *ttmp; - struct monst *mtmp; - struct permonst *mptr; - struct fruit *f; - struct cemetery *newbones; - char c, *bonesid; - char whynot[BUFSZ]; + int fd, x, y; + struct trap *ttmp; + struct monst *mtmp; + struct permonst *mptr; + struct fruit *f; + struct cemetery *newbones; + char c, *bonesid; + char whynot[BUFSZ]; - /* caller has already checked `can_make_bones()' */ + /* caller has already checked `can_make_bones()' */ - clear_bypasses(); - fd = open_bonesfile(&u.uz, &bonesid); - if (fd >= 0) { - (void) nhclose(fd); - if (wizard) { - if (yn("Bones file already exists. Replace it?") == 'y') { - if (delete_bonesfile(&u.uz)) goto make_bones; - else pline("Cannot unlink old bones."); - } - } - /* compression can change the file's name, so must - wait until after any attempt to delete this file */ - compress_bonesfile(); - return; - } + clear_bypasses(); + fd = open_bonesfile(&u.uz, &bonesid); + if (fd >= 0) { + (void) nhclose(fd); + if (wizard) { + if (yn("Bones file already exists. Replace it?") == 'y') { + if (delete_bonesfile(&u.uz)) + goto make_bones; + else + pline("Cannot unlink old bones."); + } + } + /* compression can change the file's name, so must + wait until after any attempt to delete this file */ + compress_bonesfile(); + return; + } - make_bones: - unleash_all(); - /* in case these characters are not in their home bases */ - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - mptr = mtmp->data; - if (mtmp->iswiz || mptr == &mons[PM_MEDUSA] || - mptr->msound == MS_NEMESIS || mptr->msound == MS_LEADER || - mptr == &mons[PM_VLAD_THE_IMPALER] || - (mptr == &mons[PM_ORACLE] && !fixuporacle(mtmp))) - mongone(mtmp); - } - if (u.usteed) dismount_steed(DISMOUNT_BONES); - dmonsfree(); /* discard dead or gone monsters */ +make_bones: + unleash_all(); + /* in case these characters are not in their home bases */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + mptr = mtmp->data; + if (mtmp->iswiz || mptr == &mons[PM_MEDUSA] + || mptr->msound == MS_NEMESIS || mptr->msound == MS_LEADER + || mptr == &mons[PM_VLAD_THE_IMPALER] + || (mptr == &mons[PM_ORACLE] && !fixuporacle(mtmp))) + mongone(mtmp); + } + if (u.usteed) + dismount_steed(DISMOUNT_BONES); + dmonsfree(); /* discard dead or gone monsters */ - /* mark all fruits as nonexistent; when we come to them we'll mark - * them as existing (using goodfruit()) - */ - for(f=ffruit; f; f=f->nextf) f->fid = -f->fid; + /* mark all fruits as nonexistent; when we come to them we'll mark + * them as existing (using goodfruit()) + */ + for (f = ffruit; f; f = f->nextf) + f->fid = -f->fid; - /* check iron balls separately--maybe they're not carrying it */ - if (uball) uball->owornmask = uchain->owornmask = 0; + /* check iron balls separately--maybe they're not carrying it */ + if (uball) + uball->owornmask = uchain->owornmask = 0; - /* dispose of your possessions, usually cursed */ - if (u.ugrave_arise == (NON_PM - 1)) { - struct obj *otmp; + /* dispose of your possessions, usually cursed */ + if (u.ugrave_arise == (NON_PM - 1)) { + struct obj *otmp; - /* embed your possessions in your statue */ - otmp = mk_named_object(STATUE, &mons[u.umonnum], - u.ux, u.uy, plname); + /* embed your possessions in your statue */ + otmp = mk_named_object(STATUE, &mons[u.umonnum], u.ux, u.uy, plname); - drop_upon_death((struct monst *)0, otmp, u.ux, u.uy); - if (!otmp) return; /* couldn't make statue */ - mtmp = (struct monst *)0; - } else if (u.ugrave_arise < LOW_PM) { - /* drop everything */ - drop_upon_death((struct monst *)0, (struct obj *)0, u.ux, u.uy); - /* trick makemon() into allowing monster creation - * on your location - */ - in_mklev = TRUE; - mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, MM_NONAME); - in_mklev = FALSE; - if (!mtmp) return; - mtmp = christen_monst(mtmp, plname); - if (corpse) - (void) obj_attach_mid(corpse, mtmp->m_id); - } else { - /* give your possessions to the monster you become */ - in_mklev = TRUE; /* use as-is */ - mtmp = makemon(&mons[u.ugrave_arise], u.ux, u.uy, NO_MINVENT); - in_mklev = FALSE; - if (!mtmp) { - drop_upon_death((struct monst *)0, (struct obj *)0, - u.ux, u.uy); - u.ugrave_arise = NON_PM; /* in case caller cares */ - return; - } - /* give mummy-from-hero a wrapping unless hero already - carries one; don't bother forcing it to become worn */ - if (mtmp->data->mlet == S_MUMMY && !carrying(MUMMY_WRAPPING)) - (void)mongets(mtmp, MUMMY_WRAPPING); - mtmp = christen_monst(mtmp, plname); - newsym(u.ux, u.uy); - /* ["Your body rises from the dead as an ..." used - to be given here, but it has been moved to done() so that - it gets delivered even when savebones() isn't called] */ - drop_upon_death(mtmp, (struct obj *)0, u.ux, u.uy); - m_dowear(mtmp, TRUE); - } - if (mtmp) { - mtmp->m_lev = (u.ulevel ? u.ulevel : 1); - mtmp->mhp = mtmp->mhpmax = u.uhpmax; - mtmp->female = flags.female; - mtmp->msleeping = 1; - } - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - resetobjs(mtmp->minvent,FALSE); - /* do not zero out m_ids for bones levels any more */ - mtmp->mlstmv = 0L; - if(mtmp->mtame) mtmp->mtame = mtmp->mpeaceful = 0; - } - for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { - ttmp->madeby_u = 0; - ttmp->tseen = (ttmp->ttyp == HOLE); - } - resetobjs(fobj,FALSE); - resetobjs(level.buriedobjlist, FALSE); + drop_upon_death((struct monst *) 0, otmp, u.ux, u.uy); + if (!otmp) + return; /* couldn't make statue */ + mtmp = (struct monst *) 0; + } else if (u.ugrave_arise < LOW_PM) { + /* drop everything */ + drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy); + /* trick makemon() into allowing monster creation + * on your location + */ + in_mklev = TRUE; + mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, MM_NONAME); + in_mklev = FALSE; + if (!mtmp) + return; + mtmp = christen_monst(mtmp, plname); + if (corpse) + (void) obj_attach_mid(corpse, mtmp->m_id); + } else { + /* give your possessions to the monster you become */ + in_mklev = TRUE; /* use as-is */ + mtmp = makemon(&mons[u.ugrave_arise], u.ux, u.uy, NO_MINVENT); + in_mklev = FALSE; + if (!mtmp) { + drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy); + u.ugrave_arise = NON_PM; /* in case caller cares */ + return; + } + /* give mummy-from-hero a wrapping unless hero already + carries one; don't bother forcing it to become worn */ + if (mtmp->data->mlet == S_MUMMY && !carrying(MUMMY_WRAPPING)) + (void) mongets(mtmp, MUMMY_WRAPPING); + mtmp = christen_monst(mtmp, plname); + newsym(u.ux, u.uy); + /* ["Your body rises from the dead as an ..." used + to be given here, but it has been moved to done() so that + it gets delivered even when savebones() isn't called] */ + drop_upon_death(mtmp, (struct obj *) 0, u.ux, u.uy); + m_dowear(mtmp, TRUE); + } + if (mtmp) { + mtmp->m_lev = (u.ulevel ? u.ulevel : 1); + mtmp->mhp = mtmp->mhpmax = u.uhpmax; + mtmp->female = flags.female; + mtmp->msleeping = 1; + } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + resetobjs(mtmp->minvent, FALSE); + /* do not zero out m_ids for bones levels any more */ + mtmp->mlstmv = 0L; + if (mtmp->mtame) + mtmp->mtame = mtmp->mpeaceful = 0; + } + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { + ttmp->madeby_u = 0; + ttmp->tseen = (ttmp->ttyp == HOLE); + } + resetobjs(fobj, FALSE); + resetobjs(level.buriedobjlist, FALSE); - /* Hero is no longer on the map. */ - u.ux = u.uy = 0; + /* Hero is no longer on the map. */ + u.ux = u.uy = 0; - /* Clear all memory from the level. */ - for (x = 1; x < COLNO; x++) for (y = 0; ywho, "%s-%.3s-%.3s-%.3s-%.3s", - plname, urole.filecode, urace.filecode, - genders[flags.female].filecode, - aligns[1 - u.ualign.type].filecode); - formatkiller(newbones->how, sizeof newbones->how, how); - Strcpy(newbones->when, yyyymmddhhmmss(when)); - /* final resting place, used to decide when bones are discovered */ - newbones->frpx = u.ux, newbones->frpy = u.uy; - newbones->bonesknown = FALSE; - /* if current character died on a bones level, the cememtery list - will have multiple entries, most recent (this dead hero) first */ - newbones->next = level.bonesinfo; - level.bonesinfo = newbones; - /* flag these bones if they are being created in wizard mode; - they might already be flagged as such, even when we're playing - in normal mode, if this level came from a previous bones file */ - if (wizard) level.flags.wizard_bones = 1; + /* Attach bones info to the current level before saving. */ + newbones = (struct cemetery *) alloc(sizeof *newbones); + /* entries are '\0' terminated but have fixed length allocations, + so pre-fill with spaces to initialize any excess room */ + (void) memset((genericptr_t) newbones, ' ', sizeof *newbones); + /* format name+role,&c, death reason, and date+time; + gender and alignment reflect final values rather than what the + character started out as, same as topten and logfile entries */ + Sprintf(newbones->who, "%s-%.3s-%.3s-%.3s-%.3s", plname, urole.filecode, + urace.filecode, genders[flags.female].filecode, + aligns[1 - u.ualign.type].filecode); + formatkiller(newbones->how, sizeof newbones->how, how); + Strcpy(newbones->when, yyyymmddhhmmss(when)); + /* final resting place, used to decide when bones are discovered */ + newbones->frpx = u.ux, newbones->frpy = u.uy; + newbones->bonesknown = FALSE; + /* if current character died on a bones level, the cememtery list + will have multiple entries, most recent (this dead hero) first */ + newbones->next = level.bonesinfo; + level.bonesinfo = newbones; + /* flag these bones if they are being created in wizard mode; + they might already be flagged as such, even when we're playing + in normal mode, if this level came from a previous bones file */ + if (wizard) + level.flags.wizard_bones = 1; - fd = create_bonesfile(&u.uz, &bonesid, whynot); - if(fd < 0) { - if(wizard) - pline1(whynot); - /* bones file creation problems are silent to the player. - * Keep it that way, but place a clue into the paniclog. - */ - paniclog("savebones", whynot); - return; - } - c = (char) (strlen(bonesid) + 1); + fd = create_bonesfile(&u.uz, &bonesid, whynot); + if (fd < 0) { + if (wizard) + pline1(whynot); + /* bones file creation problems are silent to the player. + * Keep it that way, but place a clue into the paniclog. + */ + paniclog("savebones", whynot); + return; + } + c = (char) (strlen(bonesid) + 1); -#ifdef MFLOPPY /* check whether there is room */ - if (iflags.checkspace) { - savelev(fd, ledger_no(&u.uz), COUNT_SAVE); - /* savelev() initializes bytes_counted to 0, so it must come - * first here even though it does not in the real save. the - * resulting extra bflush() at the end of savelev() may increase - * bytes_counted by a couple over what the real usage will be. - * - * note it is safe to call store_version() here only because - * bufon() is null for ZEROCOMP, which MFLOPPY uses -- otherwise - * this code would have to know the size of the version - * information itself. - */ - store_version(fd); - store_savefileinfo(fd); - bwrite(fd, (genericptr_t) &c, sizeof c); - bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */ - savefruitchn(fd, COUNT_SAVE); - bflush(fd); - if (bytes_counted > freediskspace(bones)) { /* not enough room */ - if (wizard) - pline("Insufficient space to create bones file."); - (void) nhclose(fd); - cancel_bonesfile(); - return; - } - co_false(); /* make sure stuff before savelev() gets written */ - } +#ifdef MFLOPPY /* check whether there is room */ + if (iflags.checkspace) { + savelev(fd, ledger_no(&u.uz), COUNT_SAVE); + /* savelev() initializes bytes_counted to 0, so it must come + * first here even though it does not in the real save. the + * resulting extra bflush() at the end of savelev() may increase + * bytes_counted by a couple over what the real usage will be. + * + * note it is safe to call store_version() here only because + * bufon() is null for ZEROCOMP, which MFLOPPY uses -- otherwise + * this code would have to know the size of the version + * information itself. + */ + store_version(fd); + store_savefileinfo(fd); + bwrite(fd, (genericptr_t) &c, sizeof c); + bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */ + savefruitchn(fd, COUNT_SAVE); + bflush(fd); + if (bytes_counted > freediskspace(bones)) { /* not enough room */ + if (wizard) + pline("Insufficient space to create bones file."); + (void) nhclose(fd); + cancel_bonesfile(); + return; + } + co_false(); /* make sure stuff before savelev() gets written */ + } #endif /* MFLOPPY */ - store_version(fd); - store_savefileinfo(fd); - bwrite(fd, (genericptr_t) &c, sizeof c); - bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */ - savefruitchn(fd, WRITE_SAVE | FREE_SAVE); - update_mlstmv(); /* update monsters for eventual restoration */ - savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); - bclose(fd); - commit_bonesfile(&u.uz); - compress_bonesfile(); + store_version(fd); + store_savefileinfo(fd); + bwrite(fd, (genericptr_t) &c, sizeof c); + bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */ + savefruitchn(fd, WRITE_SAVE | FREE_SAVE); + update_mlstmv(); /* update monsters for eventual restoration */ + savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); + bclose(fd); + commit_bonesfile(&u.uz); + compress_bonesfile(); } int getbones() { - register int fd; - register int ok; - char c, *bonesid, oldbonesid[10]; + register int fd; + register int ok; + char c, *bonesid, oldbonesid[10]; - if(discover) /* save bones files for real games */ - return(0); + if (discover) /* save bones files for real games */ + return (0); - if (!flags.bones) return (0); - /* wizard check added by GAN 02/05/87 */ - if(rn2(3) /* only once in three times do we find bones */ - && !wizard - ) return(0); - if(no_bones_level(&u.uz)) return(0); - fd = open_bonesfile(&u.uz, &bonesid); - if (fd < 0) return(0); + if (!flags.bones) + return (0); + /* wizard check added by GAN 02/05/87 */ + if (rn2(3) /* only once in three times do we find bones */ + && !wizard) + return (0); + if (no_bones_level(&u.uz)) + return (0); + fd = open_bonesfile(&u.uz, &bonesid); + if (fd < 0) + return (0); - if (validate(fd, bones) != 0) { - if (!wizard) - pline("Discarding unuseable bones; no need to panic..."); - ok = FALSE; - } else { - ok = TRUE; - if(wizard) { - if(yn("Get bones?") == 'n') { - (void) nhclose(fd); - compress_bonesfile(); - return(0); - } - } - mread(fd, (genericptr_t) &c, sizeof c); /* length incl. '\0' */ - mread(fd, (genericptr_t) oldbonesid, (unsigned) c); /* DD.nnn */ - if (strcmp(bonesid, oldbonesid) != 0) { - char errbuf[BUFSZ]; + if (validate(fd, bones) != 0) { + if (!wizard) + pline("Discarding unuseable bones; no need to panic..."); + ok = FALSE; + } else { + ok = TRUE; + if (wizard) { + if (yn("Get bones?") == 'n') { + (void) nhclose(fd); + compress_bonesfile(); + return (0); + } + } + mread(fd, (genericptr_t) &c, sizeof c); /* length incl. '\0' */ + mread(fd, (genericptr_t) oldbonesid, (unsigned) c); /* DD.nnn */ + if (strcmp(bonesid, oldbonesid) != 0) { + char errbuf[BUFSZ]; - Sprintf(errbuf, "This is bones level '%s', not '%s'!", - oldbonesid, bonesid); - if (wizard) { - pline1(errbuf); - ok = FALSE; /* won't die of trickery */ - } - trickery(errbuf); - } else { - register struct monst *mtmp; + Sprintf(errbuf, "This is bones level '%s', not '%s'!", oldbonesid, + bonesid); + if (wizard) { + pline1(errbuf); + ok = FALSE; /* won't die of trickery */ + } + trickery(errbuf); + } else { + register struct monst *mtmp; - getlev(fd, 0, 0, TRUE); + getlev(fd, 0, 0, TRUE); - /* Note that getlev() now keeps tabs on unique - * monsters such as demon lords, and tracks the - * birth counts of all species just as makemon() - * does. If a bones monster is extinct or has been - * subject to genocide, their mhpmax will be - * set to the magic DEFUNCT_MONSTER cookie value. - */ - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (has_mname(mtmp)) sanitize_name(MNAME(mtmp)); - if (mtmp->mhpmax == DEFUNCT_MONSTER) { - if (wizard) - debugpline1("Removing defunct monster %s from bones.", - mtmp->data->mname); - mongone(mtmp); - } else - /* to correctly reset named artifacts on the level */ - resetobjs(mtmp->minvent,TRUE); - } - resetobjs(fobj,TRUE); - resetobjs(level.buriedobjlist,TRUE); - } - } - (void) nhclose(fd); - sanitize_engravings(); - u.uroleplay.numbones++; + /* Note that getlev() now keeps tabs on unique + * monsters such as demon lords, and tracks the + * birth counts of all species just as makemon() + * does. If a bones monster is extinct or has been + * subject to genocide, their mhpmax will be + * set to the magic DEFUNCT_MONSTER cookie value. + */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (has_mname(mtmp)) + sanitize_name(MNAME(mtmp)); + if (mtmp->mhpmax == DEFUNCT_MONSTER) { + if (wizard) + debugpline1("Removing defunct monster %s from bones.", + mtmp->data->mname); + mongone(mtmp); + } else + /* to correctly reset named artifacts on the level */ + resetobjs(mtmp->minvent, TRUE); + } + resetobjs(fobj, TRUE); + resetobjs(level.buriedobjlist, TRUE); + } + } + (void) nhclose(fd); + sanitize_engravings(); + u.uroleplay.numbones++; - if(wizard) { - if(yn("Unlink bones?") == 'n') { - compress_bonesfile(); - return(ok); - } - } - if (!delete_bonesfile(&u.uz)) { - /* When N games try to simultaneously restore the same - * bones file, N-1 of them will fail to delete it - * (the first N-1 under AmigaDOS, the last N-1 under UNIX). - * So no point in a mysterious message for a normal event - * -- just generate a new level for those N-1 games. - */ - /* pline("Cannot unlink bones."); */ - return(0); - } - return(ok); + if (wizard) { + if (yn("Unlink bones?") == 'n') { + compress_bonesfile(); + return (ok); + } + } + if (!delete_bonesfile(&u.uz)) { + /* When N games try to simultaneously restore the same + * bones file, N-1 of them will fail to delete it + * (the first N-1 under AmigaDOS, the last N-1 under UNIX). + * So no point in a mysterious message for a normal event + * -- just generate a new level for those N-1 games. + */ + /* pline("Cannot unlink bones."); */ + return (0); + } + return (ok); } /*bones.c*/ diff --git a/src/botl.c b/src/botl.c index d2ca04f1a..0b6415739 100644 --- a/src/botl.c +++ b/src/botl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 botl.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.38 $ */ +/* NetHack 3.6 botl.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.48 $ */ /* NetHack 3.6 botl.c $Date: 2012/01/10 17:47:19 $ $Revision: 1.36 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,25 +6,19 @@ #include "hack.h" #include -extern const char *hu_stat[]; /* defined in eat.c */ +extern const char *hu_stat[]; /* defined in eat.c */ -const char * const enc_stat[] = { - "", - "Burdened", - "Stressed", - "Strained", - "Overtaxed", - "Overloaded" -}; +const char *const enc_stat[] = { "", "Burdened", "Stressed", + "Strained", "Overtaxed", "Overloaded" }; #ifdef STATUS_VIA_WINDOWPORT struct istat_s { - long time; - unsigned anytype; - anything a; - char *val; - int valwidth; - int idxmax; + long time; + unsigned anytype; + anything a; + char *val; + int valwidth; + int idxmax; }; STATIC_DCL void NDECL(init_blstats); @@ -32,10 +26,10 @@ STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int)); STATIC_DCL void FDECL(s_to_anything, (anything *, char *, int)); STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *)); STATIC_OVL int FDECL(compare_blstats, (struct istat_s *, struct istat_s *)); -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES STATIC_DCL boolean FDECL(assign_hilite, (char *, char *, char *, char *)); STATIC_DCL const char *FDECL(clridx_to_s, (char *, int)); -# endif +#endif #else STATIC_DCL void NDECL(bot1); STATIC_DCL void NDECL(bot2); @@ -52,10 +46,11 @@ STATIC_DCL void NDECL(bot2); #if COLNO <= 140 #define MAXCO 160 #else -#define MAXCO (COLNO+20) +#define MAXCO (COLNO + 20) #endif -STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */ +STATIC_OVL NEARDATA int mrank_sz = + 0; /* loaded by max_rank_sz (from u_init) */ STATIC_DCL const char *NDECL(rank); /* convert experience level (1..30) to rank index (0..8) */ @@ -63,10 +58,10 @@ int xlev_to_rank(xlev) int xlev; { - return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8; + return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8; } -#if 0 /* not currently needed */ +#if 0 /* not currently needed */ /* convert rank index (0..8) to experience level (1..30) */ int rank_to_xlev(rank) @@ -78,38 +73,40 @@ int rank; const char * rank_of(lev, monnum, female) - int lev; - short monnum; - boolean female; +int lev; +short monnum; +boolean female; { - register const struct Role *role; - register int i; + register const struct Role *role; + register int i; + /* Find the role */ + for (role = roles; role->name.m; role++) + if (monnum == role->malenum || monnum == role->femalenum) + break; + if (!role->name.m) + role = &urole; - /* Find the role */ - for (role = roles; role->name.m; role++) - if (monnum == role->malenum || monnum == role->femalenum) - break; - if (!role->name.m) - role = &urole; + /* Find the rank */ + for (i = xlev_to_rank((int) lev); i >= 0; i--) { + if (female && role->rank[i].f) + return (role->rank[i].f); + if (role->rank[i].m) + return (role->rank[i].m); + } - /* Find the rank */ - for (i = xlev_to_rank((int)lev); i >= 0; i--) { - if (female && role->rank[i].f) return (role->rank[i].f); - if (role->rank[i].m) return (role->rank[i].m); - } - - /* Try the role name, instead */ - if (female && role->name.f) return (role->name.f); - else if (role->name.m) return (role->name.m); - return ("Player"); + /* Try the role name, instead */ + if (female && role->name.f) + return (role->name.f); + else if (role->name.m) + return (role->name.m); + return ("Player"); } - STATIC_OVL const char * rank() { - return(rank_of(u.ulevel, Role_switch, flags.female)); + return (rank_of(u.ulevel, Role_switch, flags.female)); } int @@ -117,39 +114,46 @@ title_to_mon(str, rank_indx, title_length) const char *str; int *rank_indx, *title_length; { - register int i, j; + register int i, j; - - /* Loop through each of the roles */ - for (i = 0; roles[i].name.m; i++) - for (j = 0; j < 9; j++) { - if (roles[i].rank[j].m && !strncmpi(str, - roles[i].rank[j].m, strlen(roles[i].rank[j].m))) { - if (rank_indx) *rank_indx = j; - if (title_length) *title_length = strlen(roles[i].rank[j].m); - return roles[i].malenum; - } - if (roles[i].rank[j].f && !strncmpi(str, - roles[i].rank[j].f, strlen(roles[i].rank[j].f))) { - if (rank_indx) *rank_indx = j; - if (title_length) *title_length = strlen(roles[i].rank[j].f); - return ((roles[i].femalenum != NON_PM) ? - roles[i].femalenum : roles[i].malenum); - } - } - return NON_PM; + /* Loop through each of the roles */ + for (i = 0; roles[i].name.m; i++) + for (j = 0; j < 9; j++) { + if (roles[i].rank[j].m + && !strncmpi(str, roles[i].rank[j].m, + strlen(roles[i].rank[j].m))) { + if (rank_indx) + *rank_indx = j; + if (title_length) + *title_length = strlen(roles[i].rank[j].m); + return roles[i].malenum; + } + if (roles[i].rank[j].f + && !strncmpi(str, roles[i].rank[j].f, + strlen(roles[i].rank[j].f))) { + if (rank_indx) + *rank_indx = j; + if (title_length) + *title_length = strlen(roles[i].rank[j].f); + return ((roles[i].femalenum != NON_PM) ? roles[i].femalenum + : roles[i].malenum); + } + } + return NON_PM; } void max_rank_sz() { - register int i, r, maxr = 0; - for (i = 0; i < 9; i++) { - if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr) maxr = r; - if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) maxr = r; - } - mrank_sz = maxr; - return; + register int i, r, maxr = 0; + for (i = 0; i < 9; i++) { + if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr) + maxr = r; + if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) + maxr = r; + } + mrank_sz = maxr; + return; } #ifdef SCORE_ON_BOTL @@ -160,10 +164,13 @@ botl_score() long utotal; utotal = money_cnt(invent) + hidden_gold(); - if ((utotal -= u.umoney0) < 0L) utotal = 0L; - utotal += u.urexp + (50 * (deepest - 1)) + - (deepest > 30 ? 10000 : deepest > 20 ? 1000*(deepest - 20) : 0); - if (utotal < u.urexp) utotal = LONG_MAX; /* wrap around */ + if ((utotal -= u.umoney0) < 0L) + utotal = 0L; + utotal += + u.urexp + (50 * (deepest - 1)) + + (deepest > 30 ? 10000 : deepest > 20 ? 1000 * (deepest - 20) : 0); + if (utotal < u.urexp) + utotal = LONG_MAX; /* wrap around */ return utotal; } #endif @@ -172,54 +179,57 @@ botl_score() STATIC_OVL void bot1() { - char newbot1[MAXCO]; - register char *nb; - register int i,j; - Strcpy(newbot1, plname); - if('a' <= newbot1[0] && newbot1[0] <= 'z') newbot1[0] += 'A'-'a'; - newbot1[10] = 0; - Sprintf(nb = eos(newbot1)," the "); + char newbot1[MAXCO]; + register char *nb; + register int i, j; + Strcpy(newbot1, plname); + if ('a' <= newbot1[0] && newbot1[0] <= 'z') + newbot1[0] += 'A' - 'a'; + newbot1[10] = 0; + Sprintf(nb = eos(newbot1), " the "); - if (Upolyd) { - char mbot[BUFSZ]; - int k = 0; + if (Upolyd) { + char mbot[BUFSZ]; + int k = 0; - Strcpy(mbot, mons[u.umonnum].mname); - while(mbot[k] != 0) { - if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) && - 'a' <= mbot[k] && mbot[k] <= 'z') - mbot[k] += 'A' - 'a'; - k++; - } - Sprintf(nb = eos(nb), mbot); - } else - Sprintf(nb = eos(nb), rank()); + Strcpy(mbot, mons[u.umonnum].mname); + while (mbot[k] != 0) { + if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k] + && mbot[k] <= 'z') + mbot[k] += 'A' - 'a'; + k++; + } + Sprintf(nb = eos(nb), mbot); + } else + Sprintf(nb = eos(nb), rank()); - Sprintf(nb = eos(nb)," "); - i = mrank_sz + 15; - j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */ - if((i - j) > 0) - Sprintf(nb = eos(nb),"%*s", i-j, " "); /* pad with spaces */ - if (ACURR(A_STR) > 18) { - if (ACURR(A_STR) > STR18(100)) - Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100); - else if (ACURR(A_STR) < STR18(100)) - Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18); - else - Sprintf(nb = eos(nb),"St:18/** "); - } else - Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR)); - Sprintf(nb = eos(nb), - "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", - ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA)); - Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? " Chaotic" : - (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful"); + Sprintf(nb = eos(nb), " "); + i = mrank_sz + 15; + j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */ + if ((i - j) > 0) + Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */ + if (ACURR(A_STR) > 18) { + if (ACURR(A_STR) > STR18(100)) + Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100); + else if (ACURR(A_STR) < STR18(100)) + Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18); + else + Sprintf(nb = eos(nb), "St:18/** "); + } else + Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR)); + Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", + ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), + ACURR(A_CHA)); + Sprintf(nb = eos(nb), + (u.ualign.type == A_CHAOTIC) + ? " Chaotic" + : (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful"); #ifdef SCORE_ON_BOTL - if (flags.showscore) - Sprintf(nb = eos(nb), " S:%ld", botl_score()); + if (flags.showscore) + Sprintf(nb = eos(nb), " S:%ld", botl_score()); #endif - curs(WIN_STATUS, 1, 0); - putstr(WIN_STATUS, 0, newbot1); + curs(WIN_STATUS, 1, 0); + putstr(WIN_STATUS, 0, newbot1); } #endif @@ -228,189 +238,248 @@ int describe_level(buf) char *buf; { - int ret = 1; + int ret = 1; - /* TODO: Add in dungeon name */ - if (Is_knox(&u.uz)) - Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname); - else if (In_quest(&u.uz)) - Sprintf(buf, "Home %d ", dunlev(&u.uz)); - else if (In_endgame(&u.uz)) - Sprintf(buf, - Is_astralevel(&u.uz) ? "Astral Plane " : "End Game "); - else { - /* ports with more room may expand this one */ - Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz)); - ret = 0; - } - return ret; + /* TODO: Add in dungeon name */ + if (Is_knox(&u.uz)) + Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname); + else if (In_quest(&u.uz)) + Sprintf(buf, "Home %d ", dunlev(&u.uz)); + else if (In_endgame(&u.uz)) + Sprintf(buf, Is_astralevel(&u.uz) ? "Astral Plane " : "End Game "); + else { + /* ports with more room may expand this one */ + Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz)); + ret = 0; + } + return ret; } #ifndef STATUS_VIA_WINDOWPORT STATIC_OVL void bot2() { - char newbot2[MAXCO]; - register char *nb; - int hp, hpmax; - int cap = near_capacity(); + char newbot2[MAXCO]; + register char *nb; + int hp, hpmax; + int cap = near_capacity(); - hp = Upolyd ? u.mh : u.uhp; - hpmax = Upolyd ? u.mhmax : u.uhpmax; + hp = Upolyd ? u.mh : u.uhp; + hpmax = Upolyd ? u.mhmax : u.uhpmax; - if(hp < 0) hp = 0; - (void) describe_level(newbot2); - Sprintf(nb = eos(newbot2), - "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", - encglyph(objnum_to_glyph(GOLD_PIECE)), - money_cnt(invent), - hp, hpmax, u.uen, u.uenmax, u.uac); + if (hp < 0) + hp = 0; + (void) describe_level(newbot2); + Sprintf(nb = eos(newbot2), "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", + encglyph(objnum_to_glyph(GOLD_PIECE)), money_cnt(invent), hp, + hpmax, u.uen, u.uenmax, u.uac); - if (Upolyd) - Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel); - else if(flags.showexp) - Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp); - else - Sprintf(nb = eos(nb), " Exp:%u", u.ulevel); + if (Upolyd) + Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel); + else if (flags.showexp) + Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp); + else + Sprintf(nb = eos(nb), " Exp:%u", u.ulevel); - if(flags.time) - Sprintf(nb = eos(nb), " T:%ld", moves); - if(strcmp(hu_stat[u.uhs], " ")) { - Sprintf(nb = eos(nb), " "); - Strcat(newbot2, hu_stat[u.uhs]); - } - if(Confusion) Sprintf(nb = eos(nb), " Conf"); - if(Sick) { - if (u.usick_type & SICK_VOMITABLE) - Sprintf(nb = eos(nb), " FoodPois"); - if (u.usick_type & SICK_NONVOMITABLE) - Sprintf(nb = eos(nb), " Ill"); - } - if(Blind) Sprintf(nb = eos(nb), " Blind"); - if(Stunned) Sprintf(nb = eos(nb), " Stun"); - if(Hallucination) Sprintf(nb = eos(nb), " Hallu"); - if(Slimed) Sprintf(nb = eos(nb), " Slime"); - if(cap > UNENCUMBERED) - Sprintf(nb = eos(nb), " %s", enc_stat[cap]); - curs(WIN_STATUS, 1, 1); - putmixed(WIN_STATUS, 0, newbot2); + if (flags.time) + Sprintf(nb = eos(nb), " T:%ld", moves); + if (strcmp(hu_stat[u.uhs], " ")) { + Sprintf(nb = eos(nb), " "); + Strcat(newbot2, hu_stat[u.uhs]); + } + if (Confusion) + Sprintf(nb = eos(nb), " Conf"); + if (Sick) { + if (u.usick_type & SICK_VOMITABLE) + Sprintf(nb = eos(nb), " FoodPois"); + if (u.usick_type & SICK_NONVOMITABLE) + Sprintf(nb = eos(nb), " Ill"); + } + if (Blind) + Sprintf(nb = eos(nb), " Blind"); + if (Stunned) + Sprintf(nb = eos(nb), " Stun"); + if (Hallucination) + Sprintf(nb = eos(nb), " Hallu"); + if (Slimed) + Sprintf(nb = eos(nb), " Slime"); + if (cap > UNENCUMBERED) + Sprintf(nb = eos(nb), " %s", enc_stat[cap]); + curs(WIN_STATUS, 1, 1); + putmixed(WIN_STATUS, 0, newbot2); } void bot() { - if (youmonst.data) { - bot1(); - bot2(); - } - context.botl = context.botlx = 0; + if (youmonst.data) { + bot1(); + bot2(); + } + context.botl = context.botlx = 0; } -#else /* STATUS_VIA_WINDOWPORT */ +#else /* STATUS_VIA_WINDOWPORT */ /* If entries are added to this, botl.h will require updating too */ -struct istat_s blstats[2][MAXBLSTATS] = { - { - { 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0 }, /* 0 BL_TITLE */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 1 BL_STR */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 2 BL_DX */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 3 BL_CO */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 4 BL_IN */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 5 BL_WI */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 6 BL_CH */ - { 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 40, 0}, /* 7 BL_ALIGN */ - { 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0}, /* 8 BL_SCORE */ - { 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0}, /* 9 BL_CAP */ - { 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 30, 0}, /* 10 BL_GOLD */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, BL_ENEMAX}, /* 11 BL_ENE */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 12 BL_ENEMAX */ - { 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 13 BL_XP */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 14 BL_AC */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 15 BL_HD */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 20, 0}, /* 16 BL_TIME */ - { 0L, ANY_UINT, {(genericptr_t)0L}, (char *)0, 40, 0}, /* 17 BL_HUNGER */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, BL_HPMAX}, /* 18 BL_HP */ - { 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0}, /* 19 BL_HPMAX */ - { 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0}, /* 20 BL_LEVELDESC */ - { 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0}, /* 21 BL_EXP */ - { 0L, ANY_MASK32,{(genericptr_t)0L},(char *)0, 0, 0} /* 22 BL_CONDITION */ - } -}; +struct istat_s blstats[2][MAXBLSTATS] = { { + { 0L, + ANY_STR, + { (genericptr_t) 0L }, + (char *) 0, + 80, + 0 }, /* 0 BL_TITLE */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 1 BL_STR */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 2 BL_DX */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 3 BL_CO */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 4 BL_IN */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 5 BL_WI */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 6 BL_CH */ + { 0L, + ANY_STR, + { (genericptr_t) 0L }, + (char *) 0, + 40, + 0 }, /* 7 BL_ALIGN */ + { 0L, + ANY_LONG, + { (genericptr_t) 0L }, + (char *) 0, + 20, + 0 }, /* 8 BL_SCORE */ + { 0L, ANY_LONG, { (genericptr_t) 0L }, (char *) 0, 20, 0 }, /* 9 BL_CAP + */ + { 0L, + ANY_LONG, + { (genericptr_t) 0L }, + (char *) 0, + 30, + 0 }, /* 10 BL_GOLD */ + { 0L, + ANY_INT, + { (genericptr_t) 0L }, + (char *) 0, + 10, + BL_ENEMAX }, /* 11 BL_ENE */ + { 0L, + ANY_INT, + { (genericptr_t) 0L }, + (char *) 0, + 10, + 0 }, /* 12 BL_ENEMAX */ + { 0L, ANY_LONG, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 13 BL_XP */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 14 BL_AC */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 10, 0 }, /* 15 BL_HD */ + { 0L, ANY_INT, { (genericptr_t) 0L }, (char *) 0, 20, 0 }, /* 16 BL_TIME + */ + { 0L, + ANY_UINT, + { (genericptr_t) 0L }, + (char *) 0, + 40, + 0 }, /* 17 BL_HUNGER */ + { 0L, + ANY_INT, + { (genericptr_t) 0L }, + (char *) 0, + 10, + BL_HPMAX }, /* 18 BL_HP */ + { 0L, + ANY_INT, + { (genericptr_t) 0L }, + (char *) 0, + 10, + 0 }, /* 19 BL_HPMAX */ + { 0L, + ANY_STR, + { (genericptr_t) 0L }, + (char *) 0, + 80, + 0 }, /* 20 BL_LEVELDESC */ + { 0L, ANY_LONG, { (genericptr_t) 0L }, (char *) 0, 20, 0 }, /* 21 BL_EXP + */ + { 0L, + ANY_MASK32, + { (genericptr_t) 0L }, + (char *) 0, + 0, + 0 } /* 22 BL_CONDITION */ +} }; static boolean blinit = FALSE, update_all = FALSE; const char *status_fieldnames[] = { - "title", "strength", "dexterity", "constitution", "intelligence", - "wisdom", "charisma", "alignment", "score", "carrying-capacity", - "gold", "power", "power-max", "experience-level", "armor-class", - "HD", "time", "hunger", "hitpoints", "hitpoints-max", - "dungeon-level", "experience", "condition" - }; - + "title", "strength", "dexterity", "constitution", "intelligence", + "wisdom", "charisma", "alignment", "score", "carrying-capacity", "gold", + "power", "power-max", "experience-level", "armor-class", "HD", "time", + "hunger", "hitpoints", "hitpoints-max", "dungeon-level", "experience", + "condition" +}; void status_initialize(reassessment) -boolean reassessment; /* TRUE = just reassess fields w/o other initialization*/ +boolean + reassessment; /* TRUE = just reassess fields w/o other initialization*/ { - int i; - const char *fieldfmts[] = { - "%s"," St:%s"," Dx:%s"," Co:%s"," In:%s"," Wi:%s"," Ch:%s", - " %s"," S:%s"," %s"," %s"," Pw:%s", "(%s)"," Xp:%s", " AC:%s", - " HD:%s"," T:%s"," %s"," HP:%s","(%s)","%s","/%s","%s" - }; - if (!reassessment) { - init_blstats(); - (*windowprocs.win_status_init)(); - blinit = TRUE; - } - for (i = 0; i < MAXBLSTATS; ++i) { - if ((i == BL_SCORE && !flags.showscore) || - (i == BL_EXP && !flags.showexp) || - (i == BL_TIME && !flags.time) || - (i == BL_HD && !Upolyd) || - ((i == BL_XP || i == BL_EXP) && Upolyd)) - status_enablefield(i, status_fieldnames[i], - fieldfmts[i], FALSE); - else - status_enablefield(i, status_fieldnames[i], - fieldfmts[i], TRUE); - } - update_all = TRUE; + int i; + const char *fieldfmts[] = { "%s", " St:%s", " Dx:%s", " Co:%s", + " In:%s", " Wi:%s", " Ch:%s", " %s", + " S:%s", " %s", " %s", " Pw:%s", + "(%s)", " Xp:%s", " AC:%s", " HD:%s", + " T:%s", " %s", " HP:%s", "(%s)", + "%s", "/%s", "%s" }; + if (!reassessment) { + init_blstats(); + (*windowprocs.win_status_init)(); + blinit = TRUE; + } + for (i = 0; i < MAXBLSTATS; ++i) { + if ((i == BL_SCORE && !flags.showscore) + || (i == BL_EXP && !flags.showexp) + || (i == BL_TIME && !flags.time) || (i == BL_HD && !Upolyd) + || ((i == BL_XP || i == BL_EXP) && Upolyd)) + status_enablefield(i, status_fieldnames[i], fieldfmts[i], FALSE); + else + status_enablefield(i, status_fieldnames[i], fieldfmts[i], TRUE); + } + update_all = TRUE; } void status_finish() { - int i; + int i; - /* call the window port cleanup routine first */ - (*windowprocs.win_status_finish)(); + /* call the window port cleanup routine first */ + (*windowprocs.win_status_finish)(); - /* free memory that we alloc'd now */ - for (i = 0; i < MAXBLSTATS; ++i) { - if (blstats[0][i].val) free((genericptr_t)blstats[0][i].val); - if (blstats[1][i].val) free((genericptr_t)blstats[1][i].val); - } + /* free memory that we alloc'd now */ + for (i = 0; i < MAXBLSTATS; ++i) { + if (blstats[0][i].val) + free((genericptr_t) blstats[0][i].val); + if (blstats[1][i].val) + free((genericptr_t) blstats[1][i].val); + } } STATIC_OVL void init_blstats() { - int i; + int i; - for (i = 0; i < MAXBLSTATS; ++i) { - /* ensure initial field values set on blstats[1][i] too */ - blstats[1][i] = blstats[0][i]; + for (i = 0; i < MAXBLSTATS; ++i) { + /* ensure initial field values set on blstats[1][i] too */ + blstats[1][i] = blstats[0][i]; - blstats[0][i].a = zeroany; - blstats[1][i].a = zeroany; - if (blstats[0][i].valwidth) { - blstats[0][i].val = (char *)alloc(blstats[0][i].valwidth); - blstats[1][i].val = (char *)alloc(blstats[0][i].valwidth); - } else { - blstats[0][i].val = (char *)0; - blstats[1][i].val = (char *)0; - } - } + blstats[0][i].a = zeroany; + blstats[1][i].a = zeroany; + if (blstats[0][i].valwidth) { + blstats[0][i].val = (char *) alloc(blstats[0][i].valwidth); + blstats[1][i].val = (char *) alloc(blstats[0][i].valwidth); + } else { + blstats[0][i].val = (char *) 0; + blstats[1][i].val = (char *) 0; + } + } } STATIC_OVL char * @@ -419,23 +488,44 @@ char *buf; anything *a; int anytype; { - if (!buf) return (char *)0; + if (!buf) + return (char *) 0; - switch (anytype) { - case ANY_ULONG: Sprintf(buf,"%lu", a->a_ulong); break; - case ANY_MASK32: Sprintf(buf,"%lx", a->a_ulong); break; - case ANY_LONG: Sprintf(buf,"%ld", a->a_long); break; - case ANY_INT: Sprintf(buf,"%d", a->a_int); break; - case ANY_UINT: Sprintf(buf,"%u", a->a_uint); break; - case ANY_IPTR: Sprintf(buf,"%d", *a->a_iptr); break; - case ANY_LPTR: Sprintf(buf,"%ld", *a->a_lptr); break; - case ANY_ULPTR: Sprintf(buf,"%lu", *a->a_ulptr); break; - case ANY_UPTR: Sprintf(buf,"%u", *a->a_uptr); break; - case ANY_STR: /* do nothing */; break; - default: - buf[0] = '\0'; - } - return buf; + switch (anytype) { + case ANY_ULONG: + Sprintf(buf, "%lu", a->a_ulong); + break; + case ANY_MASK32: + Sprintf(buf, "%lx", a->a_ulong); + break; + case ANY_LONG: + Sprintf(buf, "%ld", a->a_long); + break; + case ANY_INT: + Sprintf(buf, "%d", a->a_int); + break; + case ANY_UINT: + Sprintf(buf, "%u", a->a_uint); + break; + case ANY_IPTR: + Sprintf(buf, "%d", *a->a_iptr); + break; + case ANY_LPTR: + Sprintf(buf, "%ld", *a->a_lptr); + break; + case ANY_ULPTR: + Sprintf(buf, "%lu", *a->a_ulptr); + break; + case ANY_UPTR: + Sprintf(buf, "%u", *a->a_uptr); + break; + case ANY_STR: /* do nothing */ + ; + break; + default: + buf[0] = '\0'; + } + return buf; } STATIC_OVL void @@ -444,409 +534,436 @@ anything *a; char *buf; int anytype; { - if (!buf || !a) return; + if (!buf || !a) + return; - switch (anytype) { - case ANY_LONG: a->a_long = atol(buf); break; - case ANY_INT: a->a_int = atoi(buf); break; - case ANY_UINT: a->a_uint = (unsigned) atoi(buf); break; - case ANY_ULONG: a->a_ulong = (unsigned long) atol(buf); break; - case ANY_IPTR: if (a->a_iptr) - *a->a_iptr = atoi(buf); break; - case ANY_UPTR: if (a->a_uptr) - *a->a_uptr = (unsigned) atoi(buf); break; - case ANY_LPTR: if (a->a_lptr) - *a->a_lptr = atol(buf); break; - case ANY_ULPTR: if (a->a_ulptr) - *a->a_ulptr = (unsigned long) atol(buf); break; - case ANY_MASK32: a->a_ulong = (unsigned long) atol(buf); break; - default: a->a_void = 0; break; - } - return; + switch (anytype) { + case ANY_LONG: + a->a_long = atol(buf); + break; + case ANY_INT: + a->a_int = atoi(buf); + break; + case ANY_UINT: + a->a_uint = (unsigned) atoi(buf); + break; + case ANY_ULONG: + a->a_ulong = (unsigned long) atol(buf); + break; + case ANY_IPTR: + if (a->a_iptr) + *a->a_iptr = atoi(buf); + break; + case ANY_UPTR: + if (a->a_uptr) + *a->a_uptr = (unsigned) atoi(buf); + break; + case ANY_LPTR: + if (a->a_lptr) + *a->a_lptr = atol(buf); + break; + case ANY_ULPTR: + if (a->a_ulptr) + *a->a_ulptr = (unsigned long) atol(buf); + break; + case ANY_MASK32: + a->a_ulong = (unsigned long) atol(buf); + break; + default: + a->a_void = 0; + break; + } + return; } STATIC_OVL int compare_blstats(bl1, bl2) struct istat_s *bl1, *bl2; { - int anytype, result = 0; + int anytype, result = 0; - if (!bl1 || !bl2) { - panic("compare_blstat: bad istat pointer %s, %s", - fmt_ptr((genericptr_t)bl1), - fmt_ptr((genericptr_t)bl2)); - } + if (!bl1 || !bl2) { + panic("compare_blstat: bad istat pointer %s, %s", + fmt_ptr((genericptr_t) bl1), fmt_ptr((genericptr_t) bl2)); + } - anytype = bl1->anytype; - if ((!bl1->a.a_void || !bl2->a.a_void) && - (anytype == ANY_IPTR || anytype == ANY_UPTR || - anytype == ANY_LPTR || anytype == ANY_ULPTR)) { - panic("compare_blstat: invalid pointer %s, %s", - fmt_ptr((genericptr_t)bl1->a.a_void), - fmt_ptr((genericptr_t)bl2->a.a_void)); - } + anytype = bl1->anytype; + if ((!bl1->a.a_void || !bl2->a.a_void) + && (anytype == ANY_IPTR || anytype == ANY_UPTR || anytype == ANY_LPTR + || anytype == ANY_ULPTR)) { + panic("compare_blstat: invalid pointer %s, %s", + fmt_ptr((genericptr_t) bl1->a.a_void), + fmt_ptr((genericptr_t) bl2->a.a_void)); + } - switch(anytype) { - case ANY_INT: - result =(bl1->a.a_int < bl2->a.a_int) ? 1 : - (bl1->a.a_int > bl2->a.a_int) ? -1 : - 0; - break; - case ANY_IPTR: - result =(*bl1->a.a_iptr < *bl2->a.a_iptr) ? 1 : - (*bl1->a.a_iptr > *bl2->a.a_iptr) ? -1 : - 0; - break; - case ANY_LONG: - result =(bl1->a.a_long < bl2->a.a_long) ? 1 : - (bl1->a.a_long > bl2->a.a_long) ? -1 : - 0; - break; - case ANY_LPTR: - result =(*bl1->a.a_lptr < *bl2->a.a_lptr) ? 1 : - (*bl1->a.a_lptr > *bl2->a.a_lptr) ? -1 : - 0; - break; - case ANY_UINT: - result =(bl1->a.a_uint < bl2->a.a_uint) ? 1 : - (bl1->a.a_uint > bl2->a.a_uint) ? -1 : - 0; - break; - case ANY_UPTR: - result =(*bl1->a.a_uptr < *bl2->a.a_uptr) ? 1 : - (*bl1->a.a_uptr > *bl2->a.a_uptr) ? -1 : - 0; - break; - case ANY_ULONG: - result =(bl1->a.a_ulong < bl2->a.a_ulong) ? 1 : - (bl1->a.a_ulong > bl2->a.a_ulong) ? -1 : - 0; - break; - case ANY_ULPTR: - result =(*bl1->a.a_ulptr < *bl2->a.a_ulptr) ? 1 : - (*bl1->a.a_ulptr > *bl2->a.a_ulptr) ? -1 : - 0; - break; - case ANY_STR: - if (strcmp(bl1->val, bl2->val) == 0) result = 0; - else result = 1; - break; - case ANY_MASK32: - if (bl1->a.a_ulong == bl2->a.a_ulong) result = 0; - else result = 1; - break; - default: - result = 1; - } - return result; + switch (anytype) { + case ANY_INT: + result = (bl1->a.a_int < bl2->a.a_int) + ? 1 + : (bl1->a.a_int > bl2->a.a_int) ? -1 : 0; + break; + case ANY_IPTR: + result = (*bl1->a.a_iptr < *bl2->a.a_iptr) + ? 1 + : (*bl1->a.a_iptr > *bl2->a.a_iptr) ? -1 : 0; + break; + case ANY_LONG: + result = (bl1->a.a_long < bl2->a.a_long) + ? 1 + : (bl1->a.a_long > bl2->a.a_long) ? -1 : 0; + break; + case ANY_LPTR: + result = (*bl1->a.a_lptr < *bl2->a.a_lptr) + ? 1 + : (*bl1->a.a_lptr > *bl2->a.a_lptr) ? -1 : 0; + break; + case ANY_UINT: + result = (bl1->a.a_uint < bl2->a.a_uint) + ? 1 + : (bl1->a.a_uint > bl2->a.a_uint) ? -1 : 0; + break; + case ANY_UPTR: + result = (*bl1->a.a_uptr < *bl2->a.a_uptr) + ? 1 + : (*bl1->a.a_uptr > *bl2->a.a_uptr) ? -1 : 0; + break; + case ANY_ULONG: + result = (bl1->a.a_ulong < bl2->a.a_ulong) + ? 1 + : (bl1->a.a_ulong > bl2->a.a_ulong) ? -1 : 0; + break; + case ANY_ULPTR: + result = (*bl1->a.a_ulptr < *bl2->a.a_ulptr) + ? 1 + : (*bl1->a.a_ulptr > *bl2->a.a_ulptr) ? -1 : 0; + break; + case ANY_STR: + if (strcmp(bl1->val, bl2->val) == 0) + result = 0; + else + result = 1; + break; + case ANY_MASK32: + if (bl1->a.a_ulong == bl2->a.a_ulong) + result = 0; + else + result = 1; + break; + default: + result = 1; + } + return result; } STATIC_OVL int percentage(bl, maxbl) struct istat_s *bl, *maxbl; { - int result = 0; - int anytype; + int result = 0; + int anytype; - if (!bl || !maxbl) { - impossible("percentage: bad istat pointer %s, %s", - fmt_ptr((genericptr_t)bl), - fmt_ptr((genericptr_t)maxbl)); - return 0; - } + if (!bl || !maxbl) { + impossible("percentage: bad istat pointer %s, %s", + fmt_ptr((genericptr_t) bl), fmt_ptr((genericptr_t) maxbl)); + return 0; + } - anytype = bl->anytype; - if (maxbl->a.a_void) { - switch(anytype) { - case ANY_INT: - result = ((100 * bl->a.a_int) / maxbl->a.a_int); - break; - case ANY_LONG: - result = (int) ((100L * bl->a.a_long) / - maxbl->a.a_long); - break; - case ANY_UINT: - result = (int) ((100U * bl->a.a_uint) / - maxbl->a.a_uint); - break; - case ANY_ULONG: - result = (int) ((100UL * bl->a.a_ulong) / - maxbl->a.a_ulong); - break; - case ANY_IPTR: - result = ((100 * (*bl->a.a_iptr)) / - (*maxbl->a.a_iptr)); - break; - case ANY_LPTR: - result = (int) ((100L * (*bl->a.a_lptr)) / - (*maxbl->a.a_lptr)); - break; - case ANY_UPTR: - result = (int) ((100U * (*bl->a.a_uptr)) / - (*maxbl->a.a_uptr)); - break; - case ANY_ULPTR: - result = (int) ((100UL * (*bl->a.a_ulptr)) / - (*maxbl->a.a_ulptr)); - break; - } - } - return result; + anytype = bl->anytype; + if (maxbl->a.a_void) { + switch (anytype) { + case ANY_INT: + result = ((100 * bl->a.a_int) / maxbl->a.a_int); + break; + case ANY_LONG: + result = (int) ((100L * bl->a.a_long) / maxbl->a.a_long); + break; + case ANY_UINT: + result = (int) ((100U * bl->a.a_uint) / maxbl->a.a_uint); + break; + case ANY_ULONG: + result = (int) ((100UL * bl->a.a_ulong) / maxbl->a.a_ulong); + break; + case ANY_IPTR: + result = ((100 * (*bl->a.a_iptr)) / (*maxbl->a.a_iptr)); + break; + case ANY_LPTR: + result = (int) ((100L * (*bl->a.a_lptr)) / (*maxbl->a.a_lptr)); + break; + case ANY_UPTR: + result = (int) ((100U * (*bl->a.a_uptr)) / (*maxbl->a.a_uptr)); + break; + case ANY_ULPTR: + result = (int) ((100UL * (*bl->a.a_ulptr)) / (*maxbl->a.a_ulptr)); + break; + } + } + return result; } void bot() { - char buf[BUFSZ]; - register char *nb; - static int idx = 0, idx_p, idxmax; - boolean updated = FALSE; - unsigned anytype; - int i, pc, chg, cap; - struct istat_s *curr, *prev; - boolean valset[MAXBLSTATS], chgval = FALSE; + char buf[BUFSZ]; + register char *nb; + static int idx = 0, idx_p, idxmax; + boolean updated = FALSE; + unsigned anytype; + int i, pc, chg, cap; + struct istat_s *curr, *prev; + boolean valset[MAXBLSTATS], chgval = FALSE; - if (!blinit) panic("bot before init."); - if (!youmonst.data) { - context.botl = context.botlx = 0; - update_all = FALSE; - return; - } + if (!blinit) + panic("bot before init."); + if (!youmonst.data) { + context.botl = context.botlx = 0; + update_all = FALSE; + return; + } - cap = near_capacity(); - idx_p = idx; - idx = 1 - idx; /* 0 -> 1, 1 -> 0 */ + cap = near_capacity(); + idx_p = idx; + idx = 1 - idx; /* 0 -> 1, 1 -> 0 */ - /* clear the "value set" indicators */ - (void) memset((genericptr_t)valset, 0, MAXBLSTATS * sizeof(boolean)); + /* clear the "value set" indicators */ + (void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof(boolean)); - /* - * Player name and title. - */ - buf[0] = '\0'; - Strcpy(buf, plname); - if('a' <= buf[0] && buf[0] <= 'z') buf[0] += 'A'-'a'; - buf[10] = 0; - Sprintf(nb = eos(buf)," the "); - if (Upolyd) { - char mbot[BUFSZ]; - int k = 0; + /* + * Player name and title. + */ + buf[0] = '\0'; + Strcpy(buf, plname); + if ('a' <= buf[0] && buf[0] <= 'z') + buf[0] += 'A' - 'a'; + buf[10] = 0; + Sprintf(nb = eos(buf), " the "); + if (Upolyd) { + char mbot[BUFSZ]; + int k = 0; - Strcpy(mbot, mons[u.umonnum].mname); - while(mbot[k] != 0) { - if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) && - 'a' <= mbot[k] && mbot[k] <= 'z') - mbot[k] += 'A' - 'a'; - k++; - } - Sprintf1(nb = eos(nb), mbot); - } else - Sprintf1(nb = eos(nb), rank()); - Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf); - valset[BL_TITLE] = TRUE; /* indicate val already set */ + Strcpy(mbot, mons[u.umonnum].mname); + while (mbot[k] != 0) { + if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k] + && mbot[k] <= 'z') + mbot[k] += 'A' - 'a'; + k++; + } + Sprintf1(nb = eos(nb), mbot); + } else + Sprintf1(nb = eos(nb), rank()); + Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf); + valset[BL_TITLE] = TRUE; /* indicate val already set */ - /* Strength */ + /* Strength */ - buf[0] = '\0'; - blstats[idx][BL_STR].a.a_int = ACURR(A_STR); - if (ACURR(A_STR) > 18) { - if (ACURR(A_STR) > STR18(100)) - Sprintf(buf,"%2d",ACURR(A_STR)-100); - else if (ACURR(A_STR) < STR18(100)) - Sprintf(buf, "18/%02d",ACURR(A_STR)-18); - else - Sprintf(buf,"18/**"); - } else - Sprintf(buf, "%-1d",ACURR(A_STR)); - Strcpy(blstats[idx][BL_STR].val, buf); - valset[BL_STR] = TRUE; /* indicate val already set */ + buf[0] = '\0'; + blstats[idx][BL_STR].a.a_int = ACURR(A_STR); + if (ACURR(A_STR) > 18) { + if (ACURR(A_STR) > STR18(100)) + Sprintf(buf, "%2d", ACURR(A_STR) - 100); + else if (ACURR(A_STR) < STR18(100)) + Sprintf(buf, "18/%02d", ACURR(A_STR) - 18); + else + Sprintf(buf, "18/**"); + } else + Sprintf(buf, "%-1d", ACURR(A_STR)); + Strcpy(blstats[idx][BL_STR].val, buf); + valset[BL_STR] = TRUE; /* indicate val already set */ + /* Dexterity, constitution, intelligence, wisdom, charisma. */ - /* Dexterity, constitution, intelligence, wisdom, charisma. */ - - blstats[idx][BL_DX].a.a_int = ACURR(A_DEX); - blstats[idx][BL_CO].a.a_int = ACURR(A_CON); - blstats[idx][BL_IN].a.a_int = ACURR(A_INT); - blstats[idx][BL_WI].a.a_int = ACURR(A_WIS); - blstats[idx][BL_CH].a.a_int = ACURR(A_CHA); + blstats[idx][BL_DX].a.a_int = ACURR(A_DEX); + blstats[idx][BL_CO].a.a_int = ACURR(A_CON); + blstats[idx][BL_IN].a.a_int = ACURR(A_INT); + blstats[idx][BL_WI].a.a_int = ACURR(A_WIS); + blstats[idx][BL_CH].a.a_int = ACURR(A_CHA); - /* Alignment */ + /* Alignment */ - Strcpy(blstats[idx][BL_ALIGN].val, - (u.ualign.type == A_CHAOTIC) ? "Chaotic" : - (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful"); + Strcpy(blstats[idx][BL_ALIGN].val, + (u.ualign.type == A_CHAOTIC) + ? "Chaotic" + : (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful"); - /* Score */ + /* Score */ - blstats[idx][BL_SCORE].a.a_long = + blstats[idx][BL_SCORE].a.a_long = #ifdef SCORE_ON_BOTL - botl_score(); + botl_score(); #else - 0; + 0; #endif - /* Hit points */ + /* Hit points */ - blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp; - blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax; - if( blstats[idx][BL_HP].a.a_int < 0) - blstats[idx][BL_HP].a.a_int = 0; + blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp; + blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax; + if (blstats[idx][BL_HP].a.a_int < 0) + blstats[idx][BL_HP].a.a_int = 0; - /* Dungeon level. */ + /* Dungeon level. */ - (void) describe_level(blstats[idx][BL_LEVELDESC].val); - valset[BL_LEVELDESC] = TRUE; /* indicate val already set */ + (void) describe_level(blstats[idx][BL_LEVELDESC].val); + valset[BL_LEVELDESC] = TRUE; /* indicate val already set */ - /* Gold */ + /* Gold */ - blstats[idx][BL_GOLD].a.a_long = money_cnt(invent); - /* - * The tty port needs to display the current symbol for gold - * as a field header, so to accomodate that we pass gold with - * that already included. If a window port needs to use the text - * gold amount without the leading "$:" the port will have to - * add 2 to the value pointer it was passed in status_update() - * for the BL_GOLD case. - * - * Another quirk of BL_GOLD is that the field display may have - * changed if a new symbol set was loaded, or we entered or left - * the rogue level. - */ + blstats[idx][BL_GOLD].a.a_long = money_cnt(invent); + /* + * The tty port needs to display the current symbol for gold + * as a field header, so to accomodate that we pass gold with + * that already included. If a window port needs to use the text + * gold amount without the leading "$:" the port will have to + * add 2 to the value pointer it was passed in status_update() + * for the BL_GOLD case. + * + * Another quirk of BL_GOLD is that the field display may have + * changed if a new symbol set was loaded, or we entered or left + * the rogue level. + */ - Sprintf(blstats[idx][BL_GOLD].val, - "%s:%ld", - encglyph(objnum_to_glyph(GOLD_PIECE)), - blstats[idx][BL_GOLD].a.a_long); - valset[BL_GOLD] = TRUE; /* indicate val already set */ + Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld", + encglyph(objnum_to_glyph(GOLD_PIECE)), + blstats[idx][BL_GOLD].a.a_long); + valset[BL_GOLD] = TRUE; /* indicate val already set */ + /* Power (magical energy) */ - /* Power (magical energy) */ + blstats[idx][BL_ENE].a.a_int = u.uen; + blstats[idx][BL_ENEMAX].a.a_int = u.uenmax; - blstats[idx][BL_ENE].a.a_int = u.uen; - blstats[idx][BL_ENEMAX].a.a_int = u.uenmax; + /* Armor class */ - /* Armor class */ + blstats[idx][BL_AC].a.a_int = u.uac; - blstats[idx][BL_AC].a.a_int = u.uac; + /* Monster level (if Upolyd) */ - /* Monster level (if Upolyd) */ + if (Upolyd) + blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel; + else + blstats[idx][BL_HD].a.a_int = 0; - if (Upolyd) - blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel; - else - blstats[idx][BL_HD].a.a_int = 0; + /* Experience */ - /* Experience */ + blstats[idx][BL_XP].a.a_int = u.ulevel; + blstats[idx][BL_EXP].a.a_int = u.uexp; - blstats[idx][BL_XP].a.a_int = u.ulevel; - blstats[idx][BL_EXP].a.a_int = u.uexp; + /* Time (moves) */ - /* Time (moves) */ + blstats[idx][BL_TIME].a.a_long = moves; - blstats[idx][BL_TIME].a.a_long = moves; + /* Hunger */ - /* Hunger */ + blstats[idx][BL_HUNGER].a.a_uint = u.uhs; + *(blstats[idx][BL_HUNGER].val) = '\0'; + if (strcmp(hu_stat[u.uhs], " ") != 0) + Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]); + valset[BL_HUNGER] = TRUE; - blstats[idx][BL_HUNGER].a.a_uint = u.uhs; - *(blstats[idx][BL_HUNGER].val) = '\0'; - if(strcmp(hu_stat[u.uhs], " ") != 0) - Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]); - valset[BL_HUNGER] = TRUE; + /* Carrying capacity */ - /* Carrying capacity */ + *(blstats[idx][BL_CAP].val) = '\0'; + blstats[idx][BL_CAP].a.a_int = cap; + if (cap > UNENCUMBERED) + Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]); + valset[BL_CAP] = TRUE; - *(blstats[idx][BL_CAP].val) = '\0'; - blstats[idx][BL_CAP].a.a_int = cap; - if(cap > UNENCUMBERED) - Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]); - valset[BL_CAP] = TRUE; + /* Conditions */ - /* Conditions */ + if (Blind) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND; - if (Blind) blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND; - - if (Confusion) blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF; + if (Confusion) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF; - if (Sick && u.usick_type & SICK_VOMITABLE) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS; + if (Sick && u.usick_type & SICK_VOMITABLE) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS; - if (Sick && u.usick_type & SICK_NONVOMITABLE) - blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL; - - if (Hallucination) blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU; - - if (Stunned) blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED; + if (Sick && u.usick_type & SICK_NONVOMITABLE) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL; - if (Slimed) blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED; - else blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED; - - /* - * Now pass the changed values to window port. - */ - for (i = 0; i < MAXBLSTATS; i++) { - if (((i == BL_SCORE) && !flags.showscore) || - ((i == BL_EXP) && !flags.showexp) || - ((i == BL_TIME) && !flags.time) || - ((i == BL_HD) && !Upolyd) || - ((i == BL_XP || i == BL_EXP) && Upolyd)) - continue; - anytype = blstats[idx][i].anytype; - curr = &blstats[idx][i]; - prev = &blstats[idx_p][i]; - chg = 0; - if (update_all || ((chg = compare_blstats(prev, curr)) != 0) || - ((chgval = (valset[i] && - strcmp(blstats[idx][i].val,blstats[idx_p][i].val))) != 0)) { - idxmax = blstats[idx][i].idxmax; - pc = (idxmax) ? - percentage(curr, &blstats[idx][idxmax]) : 0; - if (!valset[i]) (void) anything_to_s(curr->val, - &curr->a, anytype); - if (anytype != ANY_MASK32) { - status_update(i, (genericptr_t)curr->val, - valset[i] ? chgval : chg, pc); - } else { - status_update(i, - /* send pointer to mask */ - (genericptr_t) &curr->a.a_ulong, chg, 0); - } - updated = TRUE; - } - } - /* - * It is possible to get here, with nothing having been pushed - * to the window port, when none of the info has changed. In that - * case, we need to force a call to status_update() when - * context.botlx is set. The tty port in particular has a problem - * if that isn't done, since it sets context.botlx when a menu or - * text display obliterates the status line. - * - * To work around it, we call status_update() with ficticious - * index of BL_FLUSH (-1). - */ - if (context.botlx && !updated) - status_update(BL_FLUSH,(genericptr_t)0,0,0); + if (Hallucination) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU; - context.botl = context.botlx = 0; - update_all = FALSE; + if (Stunned) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED; + + if (Slimed) + blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED; + else + blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED; + + /* + * Now pass the changed values to window port. + */ + for (i = 0; i < MAXBLSTATS; i++) { + if (((i == BL_SCORE) && !flags.showscore) + || ((i == BL_EXP) && !flags.showexp) + || ((i == BL_TIME) && !flags.time) || ((i == BL_HD) && !Upolyd) + || ((i == BL_XP || i == BL_EXP) && Upolyd)) + continue; + anytype = blstats[idx][i].anytype; + curr = &blstats[idx][i]; + prev = &blstats[idx_p][i]; + chg = 0; + if (update_all || ((chg = compare_blstats(prev, curr)) != 0) + || ((chgval = (valset[i] && strcmp(blstats[idx][i].val, + blstats[idx_p][i].val))) + != 0)) { + idxmax = blstats[idx][i].idxmax; + pc = (idxmax) ? percentage(curr, &blstats[idx][idxmax]) : 0; + if (!valset[i]) + (void) anything_to_s(curr->val, &curr->a, anytype); + if (anytype != ANY_MASK32) { + status_update(i, (genericptr_t) curr->val, + valset[i] ? chgval : chg, pc); + } else { + status_update(i, + /* send pointer to mask */ + (genericptr_t) &curr->a.a_ulong, chg, 0); + } + updated = TRUE; + } + } + /* + * It is possible to get here, with nothing having been pushed + * to the window port, when none of the info has changed. In that + * case, we need to force a call to status_update() when + * context.botlx is set. The tty port in particular has a problem + * if that isn't done, since it sets context.botlx when a menu or + * text display obliterates the status line. + * + * To work around it, we call status_update() with ficticious + * index of BL_FLUSH (-1). + */ + if (context.botlx && !updated) + status_update(BL_FLUSH, (genericptr_t) 0, 0, 0); + + context.botl = context.botlx = 0; + update_all = FALSE; } /*****************************************************************************/ -/* Core status hiliting support */ +/* Core status hiliting support */ /*****************************************************************************/ #ifdef STATUS_HILITES struct hilite_s { - boolean set; - anything threshold; - int behavior; - int coloridx[2]; + boolean set; + anything threshold; + int behavior; + int coloridx[2]; }; struct hilite_s status_hilites[MAXBLSTATS]; @@ -863,276 +980,287 @@ boolean set_status_hilites(op) char *op; { - char hsbuf[4][QBUFSZ]; - boolean rslt, badopt = FALSE; - int fldnum, num =0, ccount = 0; - char c; + char hsbuf[4][QBUFSZ]; + boolean rslt, badopt = FALSE; + int fldnum, num = 0, ccount = 0; + char c; - num = fldnum = 0; - hsbuf[0][0] = hsbuf[1][0] = hsbuf[2][0] = hsbuf[3][0] = '\0'; - while (*op && fldnum < 4 && ccount < (QBUFSZ - 2)) { - c = lowc(*op); - if (c == ' ') { - if (fldnum >= 2) { - rslt = assign_hilite(&hsbuf[0][0], - &hsbuf[1][0], - &hsbuf[2][0], - &hsbuf[3][0]); - if (!rslt) { - badopt = TRUE; - break; - } - } - hsbuf[0][0] = hsbuf[1][0] = '\0'; - hsbuf[2][0] = hsbuf[3][0] = '\0'; - fldnum = 0; - ccount = 0; - } else if (c == '/') { - fldnum++; - ccount = 0; - } else { - hsbuf[fldnum][ccount++] = c; - hsbuf[fldnum][ccount] = '\0'; - } - op++; - } - if (fldnum >= 2 && !badopt) { - rslt = assign_hilite(&hsbuf[0][0], - &hsbuf[1][0], - &hsbuf[2][0], - &hsbuf[3][0]); - if (!rslt) badopt = TRUE; - } - if (badopt) return FALSE; - return TRUE; + num = fldnum = 0; + hsbuf[0][0] = hsbuf[1][0] = hsbuf[2][0] = hsbuf[3][0] = '\0'; + while (*op && fldnum < 4 && ccount < (QBUFSZ - 2)) { + c = lowc(*op); + if (c == ' ') { + if (fldnum >= 2) { + rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0], + &hsbuf[3][0]); + if (!rslt) { + badopt = TRUE; + break; + } + } + hsbuf[0][0] = hsbuf[1][0] = '\0'; + hsbuf[2][0] = hsbuf[3][0] = '\0'; + fldnum = 0; + ccount = 0; + } else if (c == '/') { + fldnum++; + ccount = 0; + } else { + hsbuf[fldnum][ccount++] = c; + hsbuf[fldnum][ccount] = '\0'; + } + op++; + } + if (fldnum >= 2 && !badopt) { + rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0], + &hsbuf[3][0]); + if (!rslt) + badopt = TRUE; + } + if (badopt) + return FALSE; + return TRUE; } void clear_status_hilites() { - int i; - anything it; - it.a_void = 0; - for (i = 0; i < MAXBLSTATS; ++i) { - (void) memset((genericptr_t)&status_hilites[i], - 0, sizeof(struct hilite_s)); - /* notify window port */ - status_threshold(i, blstats[0][i].anytype,it,0,0,0); - } + int i; + anything it; + it.a_void = 0; + for (i = 0; i < MAXBLSTATS; ++i) { + (void) memset((genericptr_t) &status_hilites[i], 0, + sizeof(struct hilite_s)); + /* notify window port */ + status_threshold(i, blstats[0][i].anytype, it, 0, 0, 0); + } } STATIC_OVL boolean -assign_hilite(sa,sb,sc,sd) +assign_hilite(sa, sb, sc, sd) char *sa, *sb, *sc, *sd; { - char *tmp, *how; - int i = -1, dt = -1, idx = -1; - int coloridx[2] = {-1, -1}; - boolean inverse[2] = {FALSE, FALSE}; - boolean bold[2] = {FALSE, FALSE}; - boolean normal[2] = {0,0}; - boolean percent = FALSE, down_up = FALSE, changed = FALSE; - anything threshold; + char *tmp, *how; + int i = -1, dt = -1, idx = -1; + int coloridx[2] = { -1, -1 }; + boolean inverse[2] = { FALSE, FALSE }; + boolean bold[2] = { FALSE, FALSE }; + boolean normal[2] = { 0, 0 }; + boolean percent = FALSE, down_up = FALSE, changed = FALSE; + anything threshold; - threshold.a_void = 0; + threshold.a_void = 0; - /* Example: - * hilite_status: hitpoints/10%/red/normal - */ + /* Example: + * hilite_status: hitpoints/10%/red/normal + */ - /* field name to idx */ - for (i = 0; sa && i < MAXBLSTATS; ++i) { - if (strcmpi(sa,status_fieldnames[i]) == 0) { - idx = i; - break; - } - } - if (idx == -1) return FALSE; - status_hilites[idx].set = FALSE; /* mark it "unset" */ + /* field name to idx */ + for (i = 0; sa && i < MAXBLSTATS; ++i) { + if (strcmpi(sa, status_fieldnames[i]) == 0) { + idx = i; + break; + } + } + if (idx == -1) + return FALSE; + status_hilites[idx].set = FALSE; /* mark it "unset" */ - /* threshold */ - if (!sb) return FALSE; - if ((strcmpi(sb, "updown") == 0) || (strcmpi(sb, "downup") == 0) || - (strcmpi(sb, "up") == 0) || (strcmpi(sb, "down") == 0)) { - down_up = TRUE; - } else if ((strcmpi(sb, "changed") == 0) && - (idx == BL_TITLE || idx == BL_ALIGN || - idx == BL_LEVELDESC || idx == BL_CONDITION)) { - changed = TRUE; /* changed is only thing allowed */ - } else { - tmp = sb; - while (*tmp) { - if (*tmp == '%') { - *tmp = '\0'; - percent = TRUE; - break; - } else if (!index("0123456789", *tmp)) - return FALSE; - tmp++; - } - if (strlen(sb) > 0) { - dt = blstats[0][idx].anytype; - if (percent) dt = ANY_INT; - (void) s_to_anything(&threshold, sb, dt); - } else return FALSE; - if (percent && - (threshold.a_int < 1 || threshold.a_int > 100)) - return FALSE; - if (!threshold.a_void && (strcmp(sb, "0") != 0)) return FALSE; - } + /* threshold */ + if (!sb) + return FALSE; + if ((strcmpi(sb, "updown") == 0) || (strcmpi(sb, "downup") == 0) + || (strcmpi(sb, "up") == 0) || (strcmpi(sb, "down") == 0)) { + down_up = TRUE; + } else if ((strcmpi(sb, "changed") == 0) + && (idx == BL_TITLE || idx == BL_ALIGN || idx == BL_LEVELDESC + || idx == BL_CONDITION)) { + changed = TRUE; /* changed is only thing allowed */ + } else { + tmp = sb; + while (*tmp) { + if (*tmp == '%') { + *tmp = '\0'; + percent = TRUE; + break; + } else if (!index("0123456789", *tmp)) + return FALSE; + tmp++; + } + if (strlen(sb) > 0) { + dt = blstats[0][idx].anytype; + if (percent) + dt = ANY_INT; + (void) s_to_anything(&threshold, sb, dt); + } else + return FALSE; + if (percent && (threshold.a_int < 1 || threshold.a_int > 100)) + return FALSE; + if (!threshold.a_void && (strcmp(sb, "0") != 0)) + return FALSE; + } - /* actions */ - for (i = 0; i < 2; ++i) { - if (!i) how = sc; - else how = sd; - if (!how) { - if (!i) return FALSE; - else break; /* sc is mandatory; sd is not */ - } + /* actions */ + for (i = 0; i < 2; ++i) { + if (!i) + how = sc; + else + how = sd; + if (!how) { + if (!i) + return FALSE; + else + break; /* sc is mandatory; sd is not */ + } - if (strcmpi(how, "bold") == 0) { - bold[i] = TRUE; - } else if (strcmpi(how, "inverse") == 0) { - inverse[i] = TRUE; - } else if (strcmpi(how, "normal") == 0) { - normal[i] = TRUE; - } else { - int k; - char colorname[BUFSZ]; - for (k = 0; k < CLR_MAX; ++k) { - /* we have to make a copy to change space to dash */ - (void) strcpy(colorname, c_obj_colors[k]); - for(tmp = index(colorname,' '); - tmp; tmp = index(colorname, ' ')) - *tmp = '-'; - if (strcmpi(how, colorname) == 0) { - coloridx[i] = k; - break; - } - } - if (k >= CLR_MAX) return FALSE; - } - } + if (strcmpi(how, "bold") == 0) { + bold[i] = TRUE; + } else if (strcmpi(how, "inverse") == 0) { + inverse[i] = TRUE; + } else if (strcmpi(how, "normal") == 0) { + normal[i] = TRUE; + } else { + int k; + char colorname[BUFSZ]; + for (k = 0; k < CLR_MAX; ++k) { + /* we have to make a copy to change space to dash */ + (void) strcpy(colorname, c_obj_colors[k]); + for (tmp = index(colorname, ' '); tmp; + tmp = index(colorname, ' ')) + *tmp = '-'; + if (strcmpi(how, colorname) == 0) { + coloridx[i] = k; + break; + } + } + if (k >= CLR_MAX) + return FALSE; + } + } - /* Assign the values */ + /* Assign the values */ - for (i = 0; i < 2; ++i) { - if (inverse[i]) status_hilites[idx].coloridx[i] = BL_HILITE_INVERSE; - else if (bold[i]) status_hilites[idx].coloridx[i] = BL_HILITE_BOLD; - else if (coloridx[i]) status_hilites[idx].coloridx[i] = coloridx[i]; - else status_hilites[idx].coloridx[i] = BL_HILITE_NONE; - } + for (i = 0; i < 2; ++i) { + if (inverse[i]) + status_hilites[idx].coloridx[i] = BL_HILITE_INVERSE; + else if (bold[i]) + status_hilites[idx].coloridx[i] = BL_HILITE_BOLD; + else if (coloridx[i]) + status_hilites[idx].coloridx[i] = coloridx[i]; + else + status_hilites[idx].coloridx[i] = BL_HILITE_NONE; + } - if (percent) - status_hilites[idx].behavior = BL_TH_VAL_PERCENTAGE; - else if (down_up) - status_hilites[idx].behavior = BL_TH_UPDOWN; - else if (threshold.a_void) - status_hilites[idx].behavior = BL_TH_VAL_ABSOLUTE; - else - status_hilites[idx].behavior = BL_TH_NONE; + if (percent) + status_hilites[idx].behavior = BL_TH_VAL_PERCENTAGE; + else if (down_up) + status_hilites[idx].behavior = BL_TH_UPDOWN; + else if (threshold.a_void) + status_hilites[idx].behavior = BL_TH_VAL_ABSOLUTE; + else + status_hilites[idx].behavior = BL_TH_NONE; - if (status_hilites[idx].behavior != BL_TH_NONE) { - status_hilites[idx].threshold = threshold; - status_hilites[idx].set = TRUE; - } + if (status_hilites[idx].behavior != BL_TH_NONE) { + status_hilites[idx].threshold = threshold; + status_hilites[idx].set = TRUE; + } - /* Now finally, we notify the window port */ - status_threshold(idx, dt, threshold, - status_hilites[idx].behavior, - status_hilites[idx].coloridx[0], - status_hilites[idx].coloridx[1]); - return TRUE; + /* Now finally, we notify the window port */ + status_threshold(idx, dt, threshold, status_hilites[idx].behavior, + status_hilites[idx].coloridx[0], + status_hilites[idx].coloridx[1]); + return TRUE; } /* * get_status_hilites * * Returns a string containing all the status hilites in the * same format that is used to specify a status hilite preference - * in the config file. + * in the config file. */ char * get_status_hilites(buf, bufsiz) char *buf; int bufsiz; { - int i, j, k, coloridx; - const char *text = (char *)0; - char tmp[BUFSZ], colorname[BUFSZ]; - boolean val_percentage, val_absolute, up_down; - boolean added_one = FALSE; + int i, j, k, coloridx; + const char *text = (char *) 0; + char tmp[BUFSZ], colorname[BUFSZ]; + boolean val_percentage, val_absolute, up_down; + boolean added_one = FALSE; - if (!buf) return (char *)0; - *buf = '\0'; + if (!buf) + return (char *) 0; + *buf = '\0'; - bufsiz--; /* required trailing null */ - for (i = 0; i < MAXBLSTATS; ++i) { - val_percentage = val_absolute = up_down = FALSE; - if (status_hilites[i].set) { - if (!added_one) - added_one = TRUE; - else { - Strcat(buf, " "); - bufsiz--; - } - k = strlen(status_fieldnames[i]); - if (k < bufsiz) { - Strcat(buf,status_fieldnames[i]); - bufsiz -= k; - } - if (bufsiz > 1) { - Strcat(buf, "/"); - bufsiz--; - } - if (status_hilites[i].behavior == BL_TH_VAL_PERCENTAGE) { - val_percentage = TRUE; - } else if (status_hilites[i].behavior == - BL_TH_VAL_ABSOLUTE) { - val_absolute = TRUE; - } else if (status_hilites[i].behavior == BL_TH_UPDOWN) { - up_down = TRUE; - text = "updown"; - } + bufsiz--; /* required trailing null */ + for (i = 0; i < MAXBLSTATS; ++i) { + val_percentage = val_absolute = up_down = FALSE; + if (status_hilites[i].set) { + if (!added_one) + added_one = TRUE; + else { + Strcat(buf, " "); + bufsiz--; + } + k = strlen(status_fieldnames[i]); + if (k < bufsiz) { + Strcat(buf, status_fieldnames[i]); + bufsiz -= k; + } + if (bufsiz > 1) { + Strcat(buf, "/"); + bufsiz--; + } + if (status_hilites[i].behavior == BL_TH_VAL_PERCENTAGE) { + val_percentage = TRUE; + } else if (status_hilites[i].behavior == BL_TH_VAL_ABSOLUTE) { + val_absolute = TRUE; + } else if (status_hilites[i].behavior == BL_TH_UPDOWN) { + up_down = TRUE; + text = "updown"; + } - anything_to_s(tmp, &status_hilites[i].threshold, - blstats[0][i].anytype); - text = tmp; - k = strlen(text); - if (k < (bufsiz - 1)) { - Strcat(buf, text); - if (val_percentage) Strcat(buf, "%"), k++; - bufsiz -= k; - } - for (j = 0; j < 2; ++j) { - if (bufsiz > 1) { - Strcat(buf, "/"); - bufsiz--; - } - coloridx = status_hilites[i].coloridx[j]; - if (coloridx < 0) { - if (coloridx == BL_HILITE_BOLD) - text = "bold"; - else if (coloridx == BL_HILITE_INVERSE) - text = "inverse"; - else - text = "normal"; - } else { - char *blank; - (void) strcpy(colorname, c_obj_colors[coloridx]); - for(blank = index(colorname,' '); - blank; blank = index(colorname, ' ')) - *blank = '-'; - text = colorname; - } - k = strlen(text); - if (k < bufsiz) { - Strcat(buf, text); - bufsiz -= k; - } - } - } - } - return buf; + anything_to_s(tmp, &status_hilites[i].threshold, + blstats[0][i].anytype); + text = tmp; + k = strlen(text); + if (k < (bufsiz - 1)) { + Strcat(buf, text); + if (val_percentage) + Strcat(buf, "%"), k++; + bufsiz -= k; + } + for (j = 0; j < 2; ++j) { + if (bufsiz > 1) { + Strcat(buf, "/"); + bufsiz--; + } + coloridx = status_hilites[i].coloridx[j]; + if (coloridx < 0) { + if (coloridx == BL_HILITE_BOLD) + text = "bold"; + else if (coloridx == BL_HILITE_INVERSE) + text = "inverse"; + else + text = "normal"; + } else { + char *blank; + (void) strcpy(colorname, c_obj_colors[coloridx]); + for (blank = index(colorname, ' '); blank; + blank = index(colorname, ' ')) + *blank = '-'; + text = colorname; + } + k = strlen(text); + if (k < bufsiz) { + Strcat(buf, text); + bufsiz -= k; + } + } + } + } + return buf; } STATIC_OVL const char * @@ -1140,188 +1268,183 @@ clridx_to_s(buf, idx) char *buf; int idx; { - static const char *a[] = { "bold", "inverse", "normal" }; + static const char *a[] = { "bold", "inverse", "normal" }; - if (buf) { - buf[0] = '\0'; - if (idx < 0 && idx >= BL_HILITE_BOLD) - Strcpy(buf, a[idx + 3]); - else if (idx >= 0 && idx < CLR_MAX) - Strcpy(buf, c_obj_colors[idx]); - } - return buf; + if (buf) { + buf[0] = '\0'; + if (idx < 0 && idx >= BL_HILITE_BOLD) + Strcpy(buf, a[idx + 3]); + else if (idx >= 0 && idx < CLR_MAX) + Strcpy(buf, c_obj_colors[idx]); + } + return buf; } boolean status_hilite_menu() { - int i, j, k, pick_cnt, pick_idx, opt_idx; - menu_item *statfield_picks = (menu_item *)0; - const char *fieldname; - int field_picks[MAXBLSTATS], res; - struct hilite_s hltemp[MAXBLSTATS]; - char buf[BUFSZ], thresholdbuf[BUFSZ], below[BUFSZ], above[BUFSZ]; - winid tmpwin; - anything any; + int i, j, k, pick_cnt, pick_idx, opt_idx; + menu_item *statfield_picks = (menu_item *) 0; + const char *fieldname; + int field_picks[MAXBLSTATS], res; + struct hilite_s hltemp[MAXBLSTATS]; + char buf[BUFSZ], thresholdbuf[BUFSZ], below[BUFSZ], above[BUFSZ]; + winid tmpwin; + anything any; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - for (i = 0; i < MAXBLSTATS; i++) { - (void) memset(&hltemp[i], 0, sizeof(struct hilite_s)); - fieldname = status_fieldnames[i]; - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, fieldname, MENU_UNSELECTED); - field_picks[i] = 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + for (i = 0; i < MAXBLSTATS; i++) { + (void) memset(&hltemp[i], 0, sizeof(struct hilite_s)); + fieldname = status_fieldnames[i]; + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, fieldname, + MENU_UNSELECTED); + field_picks[i] = 0; + } + end_menu(tmpwin, "Change hilite on which status field(s):"); + if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &statfield_picks)) > 0) { + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { + opt_idx = statfield_picks[pick_idx].item.a_int - 1; + field_picks[opt_idx] = 1; } - end_menu(tmpwin, "Change hilite on which status field(s):"); - if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &statfield_picks)) > 0) { - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { - opt_idx = statfield_picks[pick_idx].item.a_int - 1; - field_picks[opt_idx] = 1; - } - free((genericptr_t)statfield_picks); - statfield_picks = (menu_item *)0; - } - destroy_nhwindow(tmpwin); - if (pick_cnt < 0) return FALSE; + free((genericptr_t) statfield_picks); + statfield_picks = (menu_item *) 0; + } + destroy_nhwindow(tmpwin); + if (pick_cnt < 0) + return FALSE; - for (i = 0; i < MAXBLSTATS; i++) { - if (field_picks[i]) { - menu_item *pick = (menu_item *)0; - Sprintf(buf, "Threshold behavior options for %s:", - status_fieldnames[i]); - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - if (i == BL_CONDITION) { - any = zeroany; - any.a_int = BL_TH_CONDITION + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, - ATR_NONE, "Condition bitmask threshold.", - MENU_UNSELECTED); - } - any = zeroany; - any.a_int = BL_TH_NONE + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'n', 0, - ATR_NONE,"None", MENU_UNSELECTED); - if (i != BL_CONDITION) { - if (blstats[0][i].idxmax > 0) { - any = zeroany; - any.a_int = BL_TH_VAL_PERCENTAGE + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'p', 0, - ATR_NONE, "Percentage threshold.", - MENU_UNSELECTED); - } - any = zeroany; - any.a_int = BL_TH_UPDOWN + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'u', 0, - ATR_NONE, "UpDown threshold.", - MENU_UNSELECTED); - any = zeroany; - any.a_int = BL_TH_VAL_ABSOLUTE + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'v', 0, - ATR_NONE,"Value threshold.", - MENU_UNSELECTED); - } - end_menu(tmpwin, buf); - if ((res=select_menu(tmpwin, PICK_ONE, &pick)) > 0) { - hltemp[i].behavior = pick->item.a_int - 1; - free((genericptr_t)pick); - } - destroy_nhwindow(tmpwin); - if (res < 0) return FALSE; + for (i = 0; i < MAXBLSTATS; i++) { + if (field_picks[i]) { + menu_item *pick = (menu_item *) 0; + Sprintf(buf, "Threshold behavior options for %s:", + status_fieldnames[i]); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + if (i == BL_CONDITION) { + any = zeroany; + any.a_int = BL_TH_CONDITION + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE, + "Condition bitmask threshold.", MENU_UNSELECTED); + } + any = zeroany; + any.a_int = BL_TH_NONE + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'n', 0, ATR_NONE, "None", + MENU_UNSELECTED); + if (i != BL_CONDITION) { + if (blstats[0][i].idxmax > 0) { + any = zeroany; + any.a_int = BL_TH_VAL_PERCENTAGE + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'p', 0, ATR_NONE, + "Percentage threshold.", MENU_UNSELECTED); + } + any = zeroany; + any.a_int = BL_TH_UPDOWN + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'u', 0, ATR_NONE, + "UpDown threshold.", MENU_UNSELECTED); + any = zeroany; + any.a_int = BL_TH_VAL_ABSOLUTE + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'v', 0, ATR_NONE, + "Value threshold.", MENU_UNSELECTED); + } + end_menu(tmpwin, buf); + if ((res = select_menu(tmpwin, PICK_ONE, &pick)) > 0) { + hltemp[i].behavior = pick->item.a_int - 1; + free((genericptr_t) pick); + } + destroy_nhwindow(tmpwin); + if (res < 0) + return FALSE; - if (hltemp[i].behavior == BL_TH_UPDOWN) { - Sprintf(below, "%s decreases", - status_fieldnames[i]); - Sprintf(above, "%s increases", - status_fieldnames[i]); - } else if (hltemp[i].behavior) { - /* Have them enter the threshold*/ - Sprintf(buf, "Set %s threshold to what%s?", - status_fieldnames[i], - (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? - " percentage" : - (hltemp[i].behavior == BL_TH_CONDITION) ? - " mask" : ""); - getlin(buf, thresholdbuf); - if (thresholdbuf[0] == '\033') return FALSE; - (void) s_to_anything(&hltemp[i].threshold, - thresholdbuf, - blstats[0][i].anytype); - if (!hltemp[i].threshold.a_void) return FALSE; + if (hltemp[i].behavior == BL_TH_UPDOWN) { + Sprintf(below, "%s decreases", status_fieldnames[i]); + Sprintf(above, "%s increases", status_fieldnames[i]); + } else if (hltemp[i].behavior) { + /* Have them enter the threshold*/ + Sprintf( + buf, "Set %s threshold to what%s?", status_fieldnames[i], + (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) + ? " percentage" + : (hltemp[i].behavior == BL_TH_CONDITION) ? " mask" + : ""); + getlin(buf, thresholdbuf); + if (thresholdbuf[0] == '\033') + return FALSE; + (void) s_to_anything(&hltemp[i].threshold, thresholdbuf, + blstats[0][i].anytype); + if (!hltemp[i].threshold.a_void) + return FALSE; - Sprintf(below, "%s falls below %s%s", - status_fieldnames[i], - thresholdbuf, - (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? - "%" : ""); - Sprintf(above, "%s rises above %s%s", - status_fieldnames[i], - thresholdbuf, - (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? - "%" : ""); - } - for (j = 0; j < 2 && (hltemp[i].behavior != BL_TH_NONE); ++j) { - char prompt[QBUFSZ]; - /* j == 0 below, j == 1 above */ - menu_item *pick2 = (menu_item *)0; - Sprintf(prompt, "Display how when %s?", - j ? above : below); - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - for (k = -3; k < CLR_MAX; ++k) { -/* if (k == -1) continue; */ - any = zeroany; - any.a_int = (k >= 0) ? k + 1 : k; - if (k > 0) add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, c_obj_colors[k], - MENU_UNSELECTED); - else if (k == -1) add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE,"normal", - MENU_UNSELECTED); - else if (k == -2) add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE,"inverse", - MENU_UNSELECTED); - else if (k == -3) add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE,"bold", - MENU_UNSELECTED); - } - end_menu(tmpwin, prompt); - if ((res = select_menu(tmpwin, PICK_ONE, &pick2)) > 0) { - hltemp[i].coloridx[j] = (pick2->item.a_char > 0) ? - pick2->item.a_int - 1 : - pick2->item.a_int; - free((genericptr_t)pick2); - } - destroy_nhwindow(tmpwin); - if (res < 0) return FALSE; - } - } - } - buf[0] = '\0'; - for (i = 0; i < MAXBLSTATS; i++) { - if (field_picks[i]) { - Sprintf(eos(buf), "%s/%s%s/", - status_fieldnames[i], - (hltemp[i].behavior == BL_TH_UPDOWN) ? "updown" : - anything_to_s(thresholdbuf, - &hltemp[i].threshold, - blstats[0][i].anytype), - (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" : ""); - /* borrow thresholdbuf for use with these last two */ - Sprintf(eos(buf), "%s/", - clridx_to_s(thresholdbuf, hltemp[i].coloridx[0])); - Sprintf(eos(buf), "%s ", - clridx_to_s(thresholdbuf, hltemp[i].coloridx[1])); - } - } - return set_status_hilites(buf); + Sprintf(below, "%s falls below %s%s", status_fieldnames[i], + thresholdbuf, + (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" + : ""); + Sprintf(above, "%s rises above %s%s", status_fieldnames[i], + thresholdbuf, + (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" + : ""); + } + for (j = 0; j < 2 && (hltemp[i].behavior != BL_TH_NONE); ++j) { + char prompt[QBUFSZ]; + /* j == 0 below, j == 1 above */ + menu_item *pick2 = (menu_item *) 0; + Sprintf(prompt, "Display how when %s?", j ? above : below); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + for (k = -3; k < CLR_MAX; ++k) { + /* if (k == -1) continue; */ + any = zeroany; + any.a_int = (k >= 0) ? k + 1 : k; + if (k > 0) + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + c_obj_colors[k], MENU_UNSELECTED); + else if (k == -1) + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + "normal", MENU_UNSELECTED); + else if (k == -2) + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + "inverse", MENU_UNSELECTED); + else if (k == -3) + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + "bold", MENU_UNSELECTED); + } + end_menu(tmpwin, prompt); + if ((res = select_menu(tmpwin, PICK_ONE, &pick2)) > 0) { + hltemp[i].coloridx[j] = (pick2->item.a_char > 0) + ? pick2->item.a_int - 1 + : pick2->item.a_int; + free((genericptr_t) pick2); + } + destroy_nhwindow(tmpwin); + if (res < 0) + return FALSE; + } + } + } + buf[0] = '\0'; + for (i = 0; i < MAXBLSTATS; i++) { + if (field_picks[i]) { + Sprintf(eos(buf), "%s/%s%s/", status_fieldnames[i], + (hltemp[i].behavior == BL_TH_UPDOWN) + ? "updown" + : anything_to_s(thresholdbuf, &hltemp[i].threshold, + blstats[0][i].anytype), + (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" : ""); + /* borrow thresholdbuf for use with these last two */ + Sprintf(eos(buf), "%s/", + clridx_to_s(thresholdbuf, hltemp[i].coloridx[0])); + Sprintf(eos(buf), "%s ", + clridx_to_s(thresholdbuf, hltemp[i].coloridx[1])); + } + } + return set_status_hilites(buf); } #endif /*STATUS_HILITES*/ /*****************************************************************************/ -/* genl backward compat stuff - probably doesn't belong in botl.c any longer */ +/* genl backward compat stuff - probably doesn't belong in botl.c any longer + */ /*****************************************************************************/ const char *fieldnm[MAXBLSTATS]; @@ -1333,29 +1456,30 @@ NEARDATA winid WIN_STATUS; void genl_status_init() { - int i; - for (i = 0; i < MAXBLSTATS; ++i) { - vals[i] = (char *)alloc(MAXCO); - *vals[i] = '\0'; - activefields[i] = FALSE; - fieldfmt[i] = (const char *)0; - } - /* Use a window for the genl version; backward port compatibility */ - WIN_STATUS = create_nhwindow(NHW_STATUS); - display_nhwindow(WIN_STATUS, FALSE); + int i; + for (i = 0; i < MAXBLSTATS; ++i) { + vals[i] = (char *) alloc(MAXCO); + *vals[i] = '\0'; + activefields[i] = FALSE; + fieldfmt[i] = (const char *) 0; + } + /* Use a window for the genl version; backward port compatibility */ + WIN_STATUS = create_nhwindow(NHW_STATUS); + display_nhwindow(WIN_STATUS, FALSE); } void genl_status_finish() { - /* tear down routine */ - int i; + /* tear down routine */ + int i; - /* free alloc'd memory here */ - for (i = 0; i < MAXBLSTATS; ++i) { - if (vals[i]) free((genericptr_t)vals[i]); - vals[i] = (char *)0; - } + /* free alloc'd memory here */ + for (i = 0; i < MAXBLSTATS; ++i) { + if (vals[i]) + free((genericptr_t) vals[i]); + vals[i] = (char *) 0; + } } void @@ -1365,84 +1489,85 @@ const char *nm; const char *fmt; boolean enable; { - fieldfmt[fieldidx] = fmt; - fieldnm[fieldidx] = nm; - activefields[fieldidx] = enable; + fieldfmt[fieldidx] = fmt; + fieldnm[fieldidx] = nm; + activefields[fieldidx] = enable; } -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES void genl_status_threshold(fldidx, thresholdtype, threshold, behavior, under, over) -int fldidx,thresholdtype; +int fldidx, thresholdtype; int behavior, under, over; anything threshold; { - return; + return; } -# endif /* STATUS_HILITES */ +#endif /* STATUS_HILITES */ void genl_status_update(idx, ptr, chg, percent) int idx, chg, percent; genericptr_t ptr; { - char newbot1[MAXCO], newbot2[MAXCO]; - long cond, *condptr = (long *)ptr; - register int i; - char *text = (char *)ptr; - int fieldorder1[] = { - BL_TITLE, BL_STR, BL_DX,BL_CO, BL_IN, - BL_WI, BL_CH,BL_ALIGN, BL_SCORE, -1 - }; - int fieldorder2[] = { - BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, - BL_ENE, BL_ENEMAX, BL_AC, BL_XP, BL_EXP, BL_HD, - BL_TIME, BL_HUNGER,BL_CAP, BL_CONDITION, -1 - }; + char newbot1[MAXCO], newbot2[MAXCO]; + long cond, *condptr = (long *) ptr; + register int i; + char *text = (char *) ptr; + int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, + BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 }; + int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, + BL_ENE, BL_ENEMAX, BL_AC, BL_XP, + BL_EXP, BL_HD, BL_TIME, BL_HUNGER, + BL_CAP, BL_CONDITION, -1 }; - if (idx != BL_FLUSH) { - if (!activefields[idx]) return; - switch(idx) { - case BL_CONDITION: - cond = *condptr; - *vals[idx] = '\0'; - if (cond & BL_MASK_BLIND) Strcat(vals[idx], " Blind"); - if (cond & BL_MASK_CONF) Strcat(vals[idx], " Conf"); - if (cond & BL_MASK_FOODPOIS) - Strcat(vals[idx], " FoodPois"); - if (cond & BL_MASK_ILL) Strcat(vals[idx], " Ill"); - if (cond & BL_MASK_STUNNED) Strcat(vals[idx], " Stun"); - if (cond & BL_MASK_HALLU) Strcat(vals[idx], " Hallu"); - if (cond & BL_MASK_SLIMED) Strcat(vals[idx], " Slime"); - break; - default: - Sprintf(vals[idx], - fieldfmt[idx] ? fieldfmt[idx] : "%s", text); - break; - } - } + if (idx != BL_FLUSH) { + if (!activefields[idx]) + return; + switch (idx) { + case BL_CONDITION: + cond = *condptr; + *vals[idx] = '\0'; + if (cond & BL_MASK_BLIND) + Strcat(vals[idx], " Blind"); + if (cond & BL_MASK_CONF) + Strcat(vals[idx], " Conf"); + if (cond & BL_MASK_FOODPOIS) + Strcat(vals[idx], " FoodPois"); + if (cond & BL_MASK_ILL) + Strcat(vals[idx], " Ill"); + if (cond & BL_MASK_STUNNED) + Strcat(vals[idx], " Stun"); + if (cond & BL_MASK_HALLU) + Strcat(vals[idx], " Hallu"); + if (cond & BL_MASK_SLIMED) + Strcat(vals[idx], " Slime"); + break; + default: + Sprintf(vals[idx], fieldfmt[idx] ? fieldfmt[idx] : "%s", text); + break; + } + } - /* This genl version updates everything on the display, everytime */ - newbot1[0] = '\0'; - for (i = 0; fieldorder1[i] >= 0; ++i) { - int idx1 = fieldorder1[i]; - if (activefields[idx1]) - Strcat(newbot1, vals[idx1]); - } - newbot2[0] = '\0'; - for (i = 0; fieldorder2[i] >= 0; ++i) { - int idx2 = fieldorder2[i]; - if (activefields[idx2]) - Strcat(newbot2, vals[idx2]); - } - curs(WIN_STATUS, 1, 0); - putstr(WIN_STATUS, 0, newbot1); - curs(WIN_STATUS, 1, 1); - putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */ + /* This genl version updates everything on the display, everytime */ + newbot1[0] = '\0'; + for (i = 0; fieldorder1[i] >= 0; ++i) { + int idx1 = fieldorder1[i]; + if (activefields[idx1]) + Strcat(newbot1, vals[idx1]); + } + newbot2[0] = '\0'; + for (i = 0; fieldorder2[i] >= 0; ++i) { + int idx2 = fieldorder2[i]; + if (activefields[idx2]) + Strcat(newbot2, vals[idx2]); + } + curs(WIN_STATUS, 1, 0); + putstr(WIN_STATUS, 0, newbot1); + curs(WIN_STATUS, 1, 1); + putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */ } #endif /*STATUS_VIA_WINDOWPORT*/ /*botl.c*/ - - diff --git a/src/cmd.c b/src/cmd.c index abd6868a2..e90f97bad 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 cmd.c $NHDT-Date: 1430534601 2015/05/02 02:43:21 $ $NHDT-Branch: master $:$NHDT-Revision: 1.186 $ */ +/* NetHack 3.6 cmd.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.190 $ */ /* NetHack 3.6 cmd.c $Date: 2013/03/16 01:44:28 $ $Revision: 1.162 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,10 +10,10 @@ STATIC_VAR boolean alt_esc = FALSE; #endif -struct cmd Cmd = { 0 }; /* flag.h */ +struct cmd Cmd = { 0 }; /* flag.h */ -extern const char *hu_stat[]; /* hunger status from eat.c */ -extern const char *enc_stat[]; /* encumbrance status from botl.c */ +extern const char *hu_stat[]; /* hunger status from eat.c */ +extern const char *enc_stat[]; /* encumbrance status from botl.c */ #ifdef UNIX /* @@ -21,94 +21,94 @@ extern const char *enc_stat[]; /* encumbrance status from botl.c */ * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs. */ #if defined(SYSV) || defined(DGUX) || defined(HPUX) -#define NR_OF_EOFS 20 +#define NR_OF_EOFS 20 #endif #endif -#define CMD_TRAVEL (char)0x90 -#define CMD_CLICKLOOK (char)0x8F +#define CMD_TRAVEL (char) 0x90 +#define CMD_CLICKLOOK (char) 0x8F #ifdef DEBUG extern int NDECL(wiz_debug_cmd_bury); extern int NDECL(wiz_debug_cmd_traveldisplay); #endif -#ifdef DUMB /* stuff commented out in extern.h, but needed here */ -extern int NDECL(doapply); /**/ -extern int NDECL(dorub); /**/ -extern int NDECL(dojump); /**/ -extern int NDECL(doextlist); /**/ +#ifdef DUMB /* stuff commented out in extern.h, but needed here */ +extern int NDECL(doapply); /**/ +extern int NDECL(dorub); /**/ +extern int NDECL(dojump); /**/ +extern int NDECL(doextlist); /**/ extern int NDECL(enter_explore_mode); /**/ -extern int NDECL(dodrop); /**/ -extern int NDECL(doddrop); /**/ -extern int NDECL(dodown); /**/ -extern int NDECL(doup); /**/ -extern int NDECL(donull); /**/ -extern int NDECL(dowipe); /**/ -extern int NDECL(docallcnd); /**/ -extern int NDECL(dotakeoff); /**/ -extern int NDECL(doremring); /**/ -extern int NDECL(dowear); /**/ -extern int NDECL(doputon); /**/ -extern int NDECL(doddoremarm); /**/ -extern int NDECL(dokick); /**/ -extern int NDECL(dofire); /**/ -extern int NDECL(dothrow); /**/ -extern int NDECL(doeat); /**/ -extern int NDECL(done2); /**/ -extern int NDECL(vanquished); /**/ -extern int NDECL(doengrave); /**/ -extern int NDECL(dopickup); /**/ -extern int NDECL(ddoinv); /**/ -extern int NDECL(dotypeinv); /**/ -extern int NDECL(dolook); /**/ -extern int NDECL(doprgold); /**/ -extern int NDECL(doprwep); /**/ -extern int NDECL(doprarm); /**/ -extern int NDECL(doprring); /**/ -extern int NDECL(dopramulet); /**/ -extern int NDECL(doprtool); /**/ -extern int NDECL(dosuspend); /**/ -extern int NDECL(doforce); /**/ -extern int NDECL(doopen); /**/ -extern int NDECL(doclose); /**/ -extern int NDECL(dosh); /**/ -extern int NDECL(dodiscovered); /**/ -extern int NDECL(doclassdisco); /**/ -extern int NDECL(doset); /**/ -extern int NDECL(dotogglepickup); /**/ -extern int NDECL(dowhatis); /**/ -extern int NDECL(doquickwhatis); /**/ -extern int NDECL(dowhatdoes); /**/ -extern int NDECL(dohelp); /**/ -extern int NDECL(dohistory); /**/ -extern int NDECL(doloot); /**/ -extern int NDECL(dodrink); /**/ -extern int NDECL(dodip); /**/ -extern int NDECL(dosacrifice); /**/ -extern int NDECL(dopray); /**/ -extern int NDECL(dotip); /**/ -extern int NDECL(doturn); /**/ -extern int NDECL(doredraw); /**/ -extern int NDECL(doread); /**/ -extern int NDECL(dosave); /**/ -extern int NDECL(dosearch); /**/ -extern int NDECL(doidtrap); /**/ -extern int NDECL(dopay); /**/ -extern int NDECL(dosit); /**/ -extern int NDECL(dotalk); /**/ -extern int NDECL(docast); /**/ -extern int NDECL(dovspell); /**/ -extern int NDECL(dotele); /**/ -extern int NDECL(dountrap); /**/ -extern int NDECL(doversion); /**/ -extern int NDECL(doextversion); /**/ -extern int NDECL(doswapweapon); /**/ -extern int NDECL(dowield); /**/ -extern int NDECL(dowieldquiver); /**/ -extern int NDECL(dozap); /**/ -extern int NDECL(doorganize); /**/ -#endif /* DUMB */ +extern int NDECL(dodrop); /**/ +extern int NDECL(doddrop); /**/ +extern int NDECL(dodown); /**/ +extern int NDECL(doup); /**/ +extern int NDECL(donull); /**/ +extern int NDECL(dowipe); /**/ +extern int NDECL(docallcnd); /**/ +extern int NDECL(dotakeoff); /**/ +extern int NDECL(doremring); /**/ +extern int NDECL(dowear); /**/ +extern int NDECL(doputon); /**/ +extern int NDECL(doddoremarm); /**/ +extern int NDECL(dokick); /**/ +extern int NDECL(dofire); /**/ +extern int NDECL(dothrow); /**/ +extern int NDECL(doeat); /**/ +extern int NDECL(done2); /**/ +extern int NDECL(vanquished); /**/ +extern int NDECL(doengrave); /**/ +extern int NDECL(dopickup); /**/ +extern int NDECL(ddoinv); /**/ +extern int NDECL(dotypeinv); /**/ +extern int NDECL(dolook); /**/ +extern int NDECL(doprgold); /**/ +extern int NDECL(doprwep); /**/ +extern int NDECL(doprarm); /**/ +extern int NDECL(doprring); /**/ +extern int NDECL(dopramulet); /**/ +extern int NDECL(doprtool); /**/ +extern int NDECL(dosuspend); /**/ +extern int NDECL(doforce); /**/ +extern int NDECL(doopen); /**/ +extern int NDECL(doclose); /**/ +extern int NDECL(dosh); /**/ +extern int NDECL(dodiscovered); /**/ +extern int NDECL(doclassdisco); /**/ +extern int NDECL(doset); /**/ +extern int NDECL(dotogglepickup); /**/ +extern int NDECL(dowhatis); /**/ +extern int NDECL(doquickwhatis); /**/ +extern int NDECL(dowhatdoes); /**/ +extern int NDECL(dohelp); /**/ +extern int NDECL(dohistory); /**/ +extern int NDECL(doloot); /**/ +extern int NDECL(dodrink); /**/ +extern int NDECL(dodip); /**/ +extern int NDECL(dosacrifice); /**/ +extern int NDECL(dopray); /**/ +extern int NDECL(dotip); /**/ +extern int NDECL(doturn); /**/ +extern int NDECL(doredraw); /**/ +extern int NDECL(doread); /**/ +extern int NDECL(dosave); /**/ +extern int NDECL(dosearch); /**/ +extern int NDECL(doidtrap); /**/ +extern int NDECL(dopay); /**/ +extern int NDECL(dosit); /**/ +extern int NDECL(dotalk); /**/ +extern int NDECL(docast); /**/ +extern int NDECL(dovspell); /**/ +extern int NDECL(dotele); /**/ +extern int NDECL(dountrap); /**/ +extern int NDECL(doversion); /**/ +extern int NDECL(doextversion); /**/ +extern int NDECL(doswapweapon); /**/ +extern int NDECL(dowield); /**/ +extern int NDECL(dowieldquiver); /**/ +extern int NDECL(dozap); /**/ +extern int NDECL(doorganize); /**/ +#endif /* DUMB */ static int NDECL(dosuspend_core); /**/ @@ -146,38 +146,43 @@ STATIC_PTR int NDECL(wiz_migrate_mons); #endif STATIC_DCL int FDECL(size_monst, (struct monst *)); STATIC_DCL int FDECL(size_obj, (struct obj *)); -STATIC_DCL void FDECL(count_obj, (struct obj *, long *, long *, BOOLEAN_P, BOOLEAN_P)); -STATIC_DCL void FDECL(obj_chain, (winid, const char *, struct obj *, long *, long *)); -STATIC_DCL void FDECL(mon_invent_chain, (winid, const char *, struct monst *, long *, long *)); -STATIC_DCL void FDECL(mon_chain, (winid, const char *, struct monst *, long *, long *)); +STATIC_DCL void FDECL(count_obj, + (struct obj *, long *, long *, BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL void FDECL(obj_chain, + (winid, const char *, struct obj *, long *, long *)); +STATIC_DCL void FDECL(mon_invent_chain, + (winid, const char *, struct monst *, long *, long *)); +STATIC_DCL void FDECL(mon_chain, + (winid, const char *, struct monst *, long *, long *)); STATIC_DCL void FDECL(contained, (winid, const char *, long *, long *)); STATIC_PTR int NDECL(wiz_show_stats); STATIC_DCL boolean FDECL(accept_menu_prefix, (int NDECL((*)))); -# ifdef PORT_DEBUG +#ifdef PORT_DEBUG STATIC_DCL int NDECL(wiz_port_debug); -# endif +#endif STATIC_PTR int NDECL(wiz_rumor_check); STATIC_DCL char FDECL(cmd_from_func, (int NDECL((*)))); STATIC_PTR int NDECL(doattributes); STATIC_PTR int NDECL(doconduct); /**/ -STATIC_DCL void FDECL(enlght_line, (const char *,const char *,const char *,const char *)); -STATIC_DCL char *FDECL(enlght_combatinc, (const char *,int,int,char *)); -STATIC_DCL void FDECL(enlght_halfdmg, (int,int)); +STATIC_DCL void FDECL(enlght_line, (const char *, const char *, const char *, + const char *)); +STATIC_DCL char *FDECL(enlght_combatinc, (const char *, int, int, char *)); +STATIC_DCL void FDECL(enlght_halfdmg, (int, int)); STATIC_DCL boolean NDECL(walking_on_water); STATIC_DCL boolean FDECL(cause_known, (int)); -STATIC_DCL char *FDECL(attrval, (int,int,char *)); -STATIC_DCL void FDECL(background_enlightenment, (int,int)); -STATIC_DCL void FDECL(characteristics_enlightenment, (int,int)); -STATIC_DCL void FDECL(one_characteristic, (int,int,int)); -STATIC_DCL void FDECL(status_enlightenment, (int,int)); -STATIC_DCL void FDECL(attributes_enlightenment, (int,int)); +STATIC_DCL char *FDECL(attrval, (int, int, char *)); +STATIC_DCL void FDECL(background_enlightenment, (int, int)); +STATIC_DCL void FDECL(characteristics_enlightenment, (int, int)); +STATIC_DCL void FDECL(one_characteristic, (int, int, int)); +STATIC_DCL void FDECL(status_enlightenment, (int, int)); +STATIC_DCL void FDECL(attributes_enlightenment, (int, int)); -static const char* readchar_queue=""; +static const char *readchar_queue = ""; static coord clicklook_cc; STATIC_DCL char *NDECL(parse); -STATIC_DCL boolean FDECL(help_dir, (CHAR_P,const char *)); +STATIC_DCL boolean FDECL(help_dir, (CHAR_P, const char *)); STATIC_PTR int doprev_message(VOID_ARGS) @@ -189,10 +194,10 @@ doprev_message(VOID_ARGS) STATIC_PTR int timed_occupation(VOID_ARGS) { - (*timed_occ_fn)(); - if (multi > 0) - multi--; - return multi > 0; + (*timed_occ_fn)(); + if (multi > 0) + multi--; + return multi > 0; } /* If you have moved since initially setting some occupations, they @@ -212,9 +217,9 @@ timed_occupation(VOID_ARGS) void reset_occupations() { - reset_remarm(); - reset_pick(); - reset_trapset(); + reset_remarm(); + reset_pick(); + reset_trapset(); } /* If a time is given, use it to timeout this function, otherwise the @@ -226,17 +231,16 @@ int NDECL((*fn)); const char *txt; int xtime; { - if (xtime) { - occupation = timed_occupation; - timed_occ_fn = fn; - } else - occupation = fn; - occtxt = txt; - occtime = 0; - return; + if (xtime) { + occupation = timed_occupation; + timed_occ_fn = fn; + } else + occupation = fn; + occtxt = txt; + occtime = 0; + return; } - STATIC_DCL char NDECL(popch); /* Provide a means to redo the last command. The flag `in_doagain' is set @@ -250,24 +254,29 @@ static char pushq[BSIZE], saveq[BSIZE]; static NEARDATA int phead, ptail, shead, stail; STATIC_OVL char -popch() { - /* If occupied, return '\0', letting tgetch know a character should - * be read from the keyboard. If the character read is not the - * ABORT character (as checked in pcmain.c), that character will be - * pushed back on the pushq. - */ - if (occupation) return '\0'; - if (in_doagain) return(char)((shead != stail) ? saveq[stail++] : '\0'); - else return(char)((phead != ptail) ? pushq[ptail++] : '\0'); +popch() +{ + /* If occupied, return '\0', letting tgetch know a character should + * be read from the keyboard. If the character read is not the + * ABORT character (as checked in pcmain.c), that character will be + * pushed back on the pushq. + */ + if (occupation) + return '\0'; + if (in_doagain) + return (char) ((shead != stail) ? saveq[stail++] : '\0'); + else + return (char) ((phead != ptail) ? pushq[ptail++] : '\0'); } char -pgetchar() { /* curtesy of aeb@cwi.nl */ - register int ch; +pgetchar() +{ /* curtesy of aeb@cwi.nl */ + register int ch; - if(!(ch = popch())) - ch = nhgetch(); - return((char)ch); + if (!(ch = popch())) + ch = nhgetch(); + return ((char) ch); } /* A ch == 0 resets the pushq */ @@ -275,11 +284,11 @@ void pushch(ch) char ch; { - if (!ch) - phead = ptail = 0; - if (phead < BSIZE) - pushq[phead++] = ch; - return; + if (!ch) + phead = ptail = 0; + if (phead < BSIZE) + pushq[phead++] = ch; + return; } /* A ch == 0 resets the saveq. Only save keystrokes when not @@ -289,80 +298,80 @@ void savech(ch) char ch; { - if (!in_doagain) { - if (!ch) - phead = ptail = shead = stail = 0; - else if (shead < BSIZE) - saveq[shead++] = ch; - } - return; + if (!in_doagain) { + if (!ch) + phead = ptail = shead = stail = 0; + else if (shead < BSIZE) + saveq[shead++] = ch; + } + return; } STATIC_PTR int -doextcmd(VOID_ARGS) /* here after # - now read a full-word command */ +doextcmd(VOID_ARGS) /* here after # - now read a full-word command */ { - int idx, retval; - int NDECL((*func)); + int idx, retval; + int NDECL((*func)); - /* keep repeating until we don't run help or quit */ - do { - idx = get_ext_cmd(); - if (idx < 0) return 0; /* quit */ + /* keep repeating until we don't run help or quit */ + do { + idx = get_ext_cmd(); + if (idx < 0) + return 0; /* quit */ - func = extcmdlist[idx].ef_funct; - if (iflags.menu_requested && !accept_menu_prefix(func)) { - pline("'m' prefix has no effect for this command."); - iflags.menu_requested = FALSE; - } - retval = (*func)(); - } while (func == doextlist); + func = extcmdlist[idx].ef_funct; + if (iflags.menu_requested && !accept_menu_prefix(func)) { + pline("'m' prefix has no effect for this command."); + iflags.menu_requested = FALSE; + } + retval = (*func)(); + } while (func == doextlist); - return retval; + return retval; } -int -doextlist(VOID_ARGS) /* here after #? - now list all full-word commands */ +int doextlist(VOID_ARGS) /* here after #? - now list all full-word commands */ { - register const struct ext_func_tab *efp; - char buf[BUFSZ]; - winid datawin; + register const struct ext_func_tab *efp; + char buf[BUFSZ]; + winid datawin; - datawin = create_nhwindow(NHW_TEXT); - putstr(datawin, 0, ""); - putstr(datawin, 0, " Extended Commands List"); - putstr(datawin, 0, ""); - putstr(datawin, 0, " Press '#', then type:"); - putstr(datawin, 0, ""); + datawin = create_nhwindow(NHW_TEXT); + putstr(datawin, 0, ""); + putstr(datawin, 0, " Extended Commands List"); + putstr(datawin, 0, ""); + putstr(datawin, 0, " Press '#', then type:"); + putstr(datawin, 0, ""); - for(efp = extcmdlist; efp->ef_txt; efp++) { - Sprintf(buf, " %-15s - %s.", efp->ef_txt, efp->ef_desc); - putstr(datawin, 0, buf); - } - display_nhwindow(datawin, FALSE); - destroy_nhwindow(datawin); - return 0; + for (efp = extcmdlist; efp->ef_txt; efp++) { + Sprintf(buf, " %-15s - %s.", efp->ef_txt, efp->ef_desc); + putstr(datawin, 0, buf); + } + display_nhwindow(datawin, FALSE); + destroy_nhwindow(datawin); + return 0; } #ifdef TTY_GRAPHICS -#define MAX_EXT_CMD 50 /* Change if we ever have > 50 ext cmds */ -/* - * This is currently used only by the tty port and is - * controlled via runtime option 'extmenu'. - * ``# ?'' is counted towards the limit of the number of commands, - * so we actually support MAX_EXT_CMD-1 "real" extended commands. - */ +#define MAX_EXT_CMD 50 /* Change if we ever have > 50 ext cmds */ + /* + * This is currently used only by the tty port and is + * controlled via runtime option 'extmenu'. + * ``# ?'' is counted towards the limit of the number of commands, + * so we actually support MAX_EXT_CMD-1 "real" extended commands. + */ int extcmd_via_menu() /* here after # - now show pick-list of possible commands */ { const struct ext_func_tab *efp; - menu_item *pick_list = (menu_item *)0; + menu_item *pick_list = (menu_item *) 0; winid win; anything any; const struct ext_func_tab *choices[MAX_EXT_CMD + 1]; char buf[BUFSZ]; char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20]; int i, n, nchoices, acount; - int ret, biggest; + int ret, biggest; int accelerator, prevaccelerator; int matchlevel = 0; @@ -370,166 +379,178 @@ extcmd_via_menu() /* here after # - now show pick-list of possible commands */ cbuf[0] = '\0'; biggest = 0; while (!ret) { - i = n = 0; - accelerator = 0; - any = zeroany; - /* populate choices */ - for (efp = extcmdlist; efp->ef_txt; efp++) { - if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) { - choices[i] = efp; - if ((int)strlen(efp->ef_desc) > biggest) { - biggest = strlen(efp->ef_desc); - Sprintf(fmtstr, "%%-%ds", biggest + 15); - } - if (++i > MAX_EXT_CMD) { -# if defined(BETA) - impossible( - "Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.", - MAX_EXT_CMD); -# endif /* BETA */ - iflags.extmenu = 0; - return -1; - } - } - } - choices[i] = (struct ext_func_tab *)0; - nchoices = i; - /* if we're down to one, we have our selection so get out of here */ - if (nchoices == 1) { - for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) - if (!strncmpi(extcmdlist[i].ef_txt, cbuf, matchlevel)) { - ret = i; - break; - } - break; - } + i = n = 0; + accelerator = 0; + any = zeroany; + /* populate choices */ + for (efp = extcmdlist; efp->ef_txt; efp++) { + if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) { + choices[i] = efp; + if ((int) strlen(efp->ef_desc) > biggest) { + biggest = strlen(efp->ef_desc); + Sprintf(fmtstr, "%%-%ds", biggest + 15); + } + if (++i > MAX_EXT_CMD) { +#if defined(BETA) + impossible("Exceeded %d extended commands in doextcmd() " + "menu; 'extmenu' disabled.", + MAX_EXT_CMD); +#endif /* BETA */ + iflags.extmenu = 0; + return -1; + } + } + } + choices[i] = (struct ext_func_tab *) 0; + nchoices = i; + /* if we're down to one, we have our selection so get out of here */ + if (nchoices == 1) { + for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++) + if (!strncmpi(extcmdlist[i].ef_txt, cbuf, matchlevel)) { + ret = i; + break; + } + break; + } - /* otherwise... */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - prevaccelerator = 0; - acount = 0; - for (i = 0; choices[i]; ++i) { - accelerator = choices[i]->ef_txt[matchlevel]; - if (accelerator != prevaccelerator || nchoices < (ROWNO - 3)) { - if (acount) { - /* flush extended cmds for that letter already in buf */ - Sprintf(buf, fmtstr, prompt); - any.a_char = prevaccelerator; - add_menu(win, NO_GLYPH, &any, any.a_char, 0, - ATR_NONE, buf, FALSE); - acount = 0; - } - } - prevaccelerator = accelerator; - if (!acount || nchoices < (ROWNO - 3)) { - Sprintf(prompt, "%s [%s]", choices[i]->ef_txt, - choices[i]->ef_desc); - } else if (acount == 1) { - Sprintf(prompt, "%s or %s", choices[i-1]->ef_txt, - choices[i]->ef_txt); - } else { - Strcat(prompt," or "); - Strcat(prompt, choices[i]->ef_txt); - } - ++acount; - } - if (acount) { - /* flush buf */ - Sprintf(buf, fmtstr, prompt); - any.a_char = prevaccelerator; - add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, buf, FALSE); - } - Sprintf(prompt, "Extended Command: %s", cbuf); - end_menu(win, prompt); - n = select_menu(win, PICK_ONE, &pick_list); - destroy_nhwindow(win); - if (n == 1) { - if (matchlevel > (QBUFSZ - 2)) { - free((genericptr_t)pick_list); -# if defined(BETA) - impossible("Too many chars (%d) entered in extcmd_via_menu()", - matchlevel); -# endif - ret = -1; - } else { - cbuf[matchlevel++] = pick_list[0].item.a_char; - cbuf[matchlevel] = '\0'; - free((genericptr_t)pick_list); - } - } else { - if (matchlevel) { - ret = 0; - matchlevel = 0; - } else - ret = -1; - } + /* otherwise... */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + prevaccelerator = 0; + acount = 0; + for (i = 0; choices[i]; ++i) { + accelerator = choices[i]->ef_txt[matchlevel]; + if (accelerator != prevaccelerator || nchoices < (ROWNO - 3)) { + if (acount) { + /* flush extended cmds for that letter already in buf */ + Sprintf(buf, fmtstr, prompt); + any.a_char = prevaccelerator; + add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, + buf, FALSE); + acount = 0; + } + } + prevaccelerator = accelerator; + if (!acount || nchoices < (ROWNO - 3)) { + Sprintf(prompt, "%s [%s]", choices[i]->ef_txt, + choices[i]->ef_desc); + } else if (acount == 1) { + Sprintf(prompt, "%s or %s", choices[i - 1]->ef_txt, + choices[i]->ef_txt); + } else { + Strcat(prompt, " or "); + Strcat(prompt, choices[i]->ef_txt); + } + ++acount; + } + if (acount) { + /* flush buf */ + Sprintf(buf, fmtstr, prompt); + any.a_char = prevaccelerator; + add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, buf, + FALSE); + } + Sprintf(prompt, "Extended Command: %s", cbuf); + end_menu(win, prompt); + n = select_menu(win, PICK_ONE, &pick_list); + destroy_nhwindow(win); + if (n == 1) { + if (matchlevel > (QBUFSZ - 2)) { + free((genericptr_t) pick_list); +#if defined(BETA) + impossible("Too many chars (%d) entered in extcmd_via_menu()", + matchlevel); +#endif + ret = -1; + } else { + cbuf[matchlevel++] = pick_list[0].item.a_char; + cbuf[matchlevel] = '\0'; + free((genericptr_t) pick_list); + } + } else { + if (matchlevel) { + ret = 0; + matchlevel = 0; + } else + ret = -1; + } } return ret; } -#endif /* TTY_GRAPHICS */ +#endif /* TTY_GRAPHICS */ /* #monster command - use special monster ability while polymorphed */ STATIC_PTR int domonability(VOID_ARGS) { - if (can_breathe(youmonst.data)) return dobreathe(); - else if (attacktype(youmonst.data, AT_SPIT)) return dospit(); - else if (youmonst.data->mlet == S_NYMPH) return doremove(); - else if (attacktype(youmonst.data, AT_GAZE)) return dogaze(); - else if (is_were(youmonst.data)) return dosummon(); - else if (webmaker(youmonst.data)) return dospinweb(); - else if (is_hider(youmonst.data)) return dohide(); - else if (is_mind_flayer(youmonst.data)) return domindblast(); - else if (u.umonnum == PM_GREMLIN) { - if(IS_FOUNTAIN(levl[u.ux][u.uy].typ)) { - if (split_mon(&youmonst, (struct monst *)0)) - dryup(u.ux, u.uy, TRUE); - } else There("is no fountain here."); - } else if (is_unicorn(youmonst.data)) { - use_unicorn_horn((struct obj *)0); - return 1; - } else if (youmonst.data->msound == MS_SHRIEK) { - You("shriek."); - if(u.uburied) - pline("Unfortunately sound does not carry well through rock."); - else aggravate(); - } else if (youmonst.data->mlet == S_VAMPIRE) return dopoly(); - else if (Upolyd) - pline("Any special ability you may have is purely reflexive."); - else You("don't have a special ability in your normal form!"); - return 0; + if (can_breathe(youmonst.data)) + return dobreathe(); + else if (attacktype(youmonst.data, AT_SPIT)) + return dospit(); + else if (youmonst.data->mlet == S_NYMPH) + return doremove(); + else if (attacktype(youmonst.data, AT_GAZE)) + return dogaze(); + else if (is_were(youmonst.data)) + return dosummon(); + else if (webmaker(youmonst.data)) + return dospinweb(); + else if (is_hider(youmonst.data)) + return dohide(); + else if (is_mind_flayer(youmonst.data)) + return domindblast(); + else if (u.umonnum == PM_GREMLIN) { + if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)) { + if (split_mon(&youmonst, (struct monst *) 0)) + dryup(u.ux, u.uy, TRUE); + } else + There("is no fountain here."); + } else if (is_unicorn(youmonst.data)) { + use_unicorn_horn((struct obj *) 0); + return 1; + } else if (youmonst.data->msound == MS_SHRIEK) { + You("shriek."); + if (u.uburied) + pline("Unfortunately sound does not carry well through rock."); + else + aggravate(); + } else if (youmonst.data->mlet == S_VAMPIRE) + return dopoly(); + else if (Upolyd) + pline("Any special ability you may have is purely reflexive."); + else + You("don't have a special ability in your normal form!"); + return 0; } int enter_explore_mode(VOID_ARGS) { if (wizard) { - You("are in debug mode."); + You("are in debug mode."); } else if (discover) { - You("are already in explore mode."); + You("are already in explore mode."); } else { #ifdef SYSCF -# if defined(UNIX) - if (!sysopt.explorers || - !sysopt.explorers[0] || - !check_user_string(sysopt.explorers)) { - You("cannot access explore mode."); - return 0; - } -# endif +#if defined(UNIX) + if (!sysopt.explorers || !sysopt.explorers[0] + || !check_user_string(sysopt.explorers)) { + You("cannot access explore mode."); + return 0; + } #endif - pline( - "Beware! From explore mode there will be no return to normal game."); - if (paranoid_query(ParanoidQuit, - "Do you want to enter explore mode?")) { - clear_nhwindow(WIN_MESSAGE); - You("are now in non-scoring explore mode."); - discover = TRUE; - } else { - clear_nhwindow(WIN_MESSAGE); - pline("Resuming normal game."); - } +#endif + pline("Beware! From explore mode there will be no return to normal " + "game."); + if (paranoid_query(ParanoidQuit, + "Do you want to enter explore mode?")) { + clear_nhwindow(WIN_MESSAGE); + You("are now in non-scoring explore mode."); + discover = TRUE; + } else { + clear_nhwindow(WIN_MESSAGE); + pline("Resuming normal game."); + } } return 0; } @@ -537,112 +558,123 @@ enter_explore_mode(VOID_ARGS) STATIC_PTR int dooverview_or_wiz_where(VOID_ARGS) { - if (wizard) return wiz_where(); - else dooverview(); - return 0; + if (wizard) + return wiz_where(); + else + dooverview(); + return 0; } /* ^W command - wish for something */ STATIC_PTR int -wiz_wish(VOID_ARGS) /* Unlimited wishes for debug mode by Paul Polderman */ +wiz_wish(VOID_ARGS) /* Unlimited wishes for debug mode by Paul Polderman */ { - if (wizard) { - boolean save_verbose = flags.verbose; + if (wizard) { + boolean save_verbose = flags.verbose; - flags.verbose = FALSE; - makewish(); - flags.verbose = save_verbose; - (void) encumber_msg(); - } else - pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_wish))); - return 0; + flags.verbose = FALSE; + makewish(); + flags.verbose = save_verbose; + (void) encumber_msg(); + } else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_wish))); + return 0; } /* ^I command - reveal and optionally identify hero's inventory */ STATIC_PTR int wiz_identify(VOID_ARGS) { - if (wizard) { - iflags.override_ID = (int)cmd_from_func(wiz_identify); - if (display_inventory((char *)0, TRUE) == -1) - identify_pack(0, FALSE); - iflags.override_ID = 0; - } else pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_identify))); - return 0; + if (wizard) { + iflags.override_ID = (int) cmd_from_func(wiz_identify); + if (display_inventory((char *) 0, TRUE) == -1) + identify_pack(0, FALSE); + iflags.override_ID = 0; + } else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_identify))); + return 0; } /* ^F command - reveal the level map and any traps on it */ STATIC_PTR int wiz_map(VOID_ARGS) { - if (wizard) { - struct trap *t; - long save_Hconf = HConfusion, - save_Hhallu = HHallucination; + if (wizard) { + struct trap *t; + long save_Hconf = HConfusion, save_Hhallu = HHallucination; - HConfusion = HHallucination = 0L; - for (t = ftrap; t != 0; t = t->ntrap) { - t->tseen = 1; - map_trap(t, TRUE); - } - do_mapping(); - HConfusion = save_Hconf; - HHallucination = save_Hhallu; - } else - pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_map))); - return 0; + HConfusion = HHallucination = 0L; + for (t = ftrap; t != 0; t = t->ntrap) { + t->tseen = 1; + map_trap(t, TRUE); + } + do_mapping(); + HConfusion = save_Hconf; + HHallucination = save_Hhallu; + } else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_map))); + return 0; } /* ^G command - generate monster(s); a count prefix will be honored */ STATIC_PTR int wiz_genesis(VOID_ARGS) { - if (wizard) (void) create_particular(); - else pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_genesis))); - return 0; + if (wizard) + (void) create_particular(); + else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_genesis))); + return 0; } /* ^O command - display dungeon layout */ STATIC_PTR int wiz_where(VOID_ARGS) { - if (wizard) (void) print_dungeon(FALSE, (schar *)0, (xchar *)0); - else pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_where))); - return 0; + if (wizard) + (void) print_dungeon(FALSE, (schar *) 0, (xchar *) 0); + else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_where))); + return 0; } /* ^E command - detect unseen (secret doors, traps, hidden monsters) */ STATIC_PTR int wiz_detect(VOID_ARGS) { - if(wizard) (void) findit(); - else pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_detect))); - return 0; + if (wizard) + (void) findit(); + else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_detect))); + return 0; } /* ^V command - level teleport */ STATIC_PTR int wiz_level_tele(VOID_ARGS) { - if (wizard) level_tele(); - else pline("Unavailable command '%s'.", - visctrl((int)cmd_from_func(wiz_level_tele))); - return 0; + if (wizard) + level_tele(); + else + pline("Unavailable command '%s'.", + visctrl((int) cmd_from_func(wiz_level_tele))); + return 0; } -/* #monpolycontrol command - choose new form for shapechangers, polymorphees */ +/* #monpolycontrol command - choose new form for shapechangers, polymorphees + */ STATIC_PTR int wiz_mon_polycontrol(VOID_ARGS) { iflags.mon_polycontrol = !iflags.mon_polycontrol; pline("Monster polymorph control is %s.", - iflags.mon_polycontrol ? "on" : "off"); + iflags.mon_polycontrol ? "on" : "off"); return 0; } @@ -655,32 +687,36 @@ wiz_level_change(VOID_ARGS) int ret; getlin("To what experience level do you want to be set?", buf); - (void)mungspaces(buf); - if (buf[0] == '\033' || buf[0] == '\0') ret = 0; - else ret = sscanf(buf, "%d", &newlevel); + (void) mungspaces(buf); + if (buf[0] == '\033' || buf[0] == '\0') + ret = 0; + else + ret = sscanf(buf, "%d", &newlevel); if (ret != 1) { - pline1(Never_mind); - return 0; + pline1(Never_mind); + return 0; } if (newlevel == u.ulevel) { - You("are already that experienced."); + You("are already that experienced."); } else if (newlevel < u.ulevel) { - if (u.ulevel == 1) { - You("are already as inexperienced as you can get."); - return 0; - } - if (newlevel < 1) newlevel = 1; - while (u.ulevel > newlevel) - losexp("#levelchange"); + if (u.ulevel == 1) { + You("are already as inexperienced as you can get."); + return 0; + } + if (newlevel < 1) + newlevel = 1; + while (u.ulevel > newlevel) + losexp("#levelchange"); } else { - if (u.ulevel >= MAXULEV) { - You("are already as experienced as you can get."); - return 0; - } - if (newlevel > MAXULEV) newlevel = MAXULEV; - while (u.ulevel < newlevel) - pluslvl(FALSE); + if (u.ulevel >= MAXULEV) { + You("are already as experienced as you can get."); + return 0; + } + if (newlevel > MAXULEV) + newlevel = MAXULEV; + while (u.ulevel < newlevel) + pluslvl(FALSE); } u.ulevelmax = u.ulevel; return 0; @@ -690,456 +726,490 @@ wiz_level_change(VOID_ARGS) STATIC_PTR int wiz_panic(VOID_ARGS) { - if (yn("Do you want to call panic() and end your game?") == 'y') - panic("Crash test."); - return 0; + if (yn("Do you want to call panic() and end your game?") == 'y') + panic("Crash test."); + return 0; } /* #polyself command - change hero's form */ STATIC_PTR int wiz_polyself(VOID_ARGS) { - polyself(1); - return 0; + polyself(1); + return 0; } /* #seenv command */ STATIC_PTR int wiz_show_seenv(VOID_ARGS) { - winid win; - int x, y, v, startx, stopx, curx; - char row[COLNO+1]; + winid win; + int x, y, v, startx, stopx, curx; + char row[COLNO + 1]; - win = create_nhwindow(NHW_TEXT); - /* - * Each seenv description takes up 2 characters, so center - * the seenv display around the hero. - */ - startx = max(1, u.ux-(COLNO/4)); - stopx = min(startx+(COLNO/2), COLNO); - /* can't have a line exactly 80 chars long */ - if (stopx - startx == COLNO/2) startx++; + win = create_nhwindow(NHW_TEXT); + /* + * Each seenv description takes up 2 characters, so center + * the seenv display around the hero. + */ + startx = max(1, u.ux - (COLNO / 4)); + stopx = min(startx + (COLNO / 2), COLNO); + /* can't have a line exactly 80 chars long */ + if (stopx - startx == COLNO / 2) + startx++; - for (y = 0; y < ROWNO; y++) { - for (x = startx, curx = 0; x < stopx; x++, curx += 2) { - if (x == u.ux && y == u.uy) { - row[curx] = row[curx+1] = '@'; - } else { - v = levl[x][y].seenv & 0xff; - if (v == 0) - row[curx] = row[curx+1] = ' '; - else - Sprintf(&row[curx], "%02x", v); - } - } - /* remove trailing spaces */ - for (x = curx-1; x >= 0; x--) - if (row[x] != ' ') break; - row[x+1] = '\0'; + for (y = 0; y < ROWNO; y++) { + for (x = startx, curx = 0; x < stopx; x++, curx += 2) { + if (x == u.ux && y == u.uy) { + row[curx] = row[curx + 1] = '@'; + } else { + v = levl[x][y].seenv & 0xff; + if (v == 0) + row[curx] = row[curx + 1] = ' '; + else + Sprintf(&row[curx], "%02x", v); + } + } + /* remove trailing spaces */ + for (x = curx - 1; x >= 0; x--) + if (row[x] != ' ') + break; + row[x + 1] = '\0'; - putstr(win, 0, row); - } - display_nhwindow(win, TRUE); - destroy_nhwindow(win); - return 0; + putstr(win, 0, row); + } + display_nhwindow(win, TRUE); + destroy_nhwindow(win); + return 0; } /* #vision command */ STATIC_PTR int wiz_show_vision(VOID_ARGS) { - winid win; - int x, y, v; - char row[COLNO+1]; + winid win; + int x, y, v; + char row[COLNO + 1]; - win = create_nhwindow(NHW_TEXT); - Sprintf(row, "Flags: 0x%x could see, 0x%x in sight, 0x%x temp lit", - COULD_SEE, IN_SIGHT, TEMP_LIT); - putstr(win, 0, row); - putstr(win, 0, ""); - for (y = 0; y < ROWNO; y++) { - for (x = 1; x < COLNO; x++) { - if (x == u.ux && y == u.uy) - row[x] = '@'; - else { - v = viz_array[y][x]; /* data access should be hidden */ - if (v == 0) - row[x] = ' '; - else - row[x] = '0' + viz_array[y][x]; - } - } - /* remove trailing spaces */ - for (x = COLNO-1; x >= 1; x--) - if (row[x] != ' ') break; - row[x+1] = '\0'; + win = create_nhwindow(NHW_TEXT); + Sprintf(row, "Flags: 0x%x could see, 0x%x in sight, 0x%x temp lit", + COULD_SEE, IN_SIGHT, TEMP_LIT); + putstr(win, 0, row); + putstr(win, 0, ""); + for (y = 0; y < ROWNO; y++) { + for (x = 1; x < COLNO; x++) { + if (x == u.ux && y == u.uy) + row[x] = '@'; + else { + v = viz_array[y][x]; /* data access should be hidden */ + if (v == 0) + row[x] = ' '; + else + row[x] = '0' + viz_array[y][x]; + } + } + /* remove trailing spaces */ + for (x = COLNO - 1; x >= 1; x--) + if (row[x] != ' ') + break; + row[x + 1] = '\0'; - putstr(win, 0, &row[1]); - } - display_nhwindow(win, TRUE); - destroy_nhwindow(win); - return 0; + putstr(win, 0, &row[1]); + } + display_nhwindow(win, TRUE); + destroy_nhwindow(win); + return 0; } /* #wmode command */ STATIC_PTR int wiz_show_wmodes(VOID_ARGS) { - winid win; - int x,y; - char row[COLNO+1]; - struct rm *lev; - boolean istty = !strcmp(windowprocs.name, "tty"); + winid win; + int x, y; + char row[COLNO + 1]; + struct rm *lev; + boolean istty = !strcmp(windowprocs.name, "tty"); - win = create_nhwindow(NHW_TEXT); - if (istty) putstr(win, 0, ""); /* tty only: blank top line */ - for (y = 0; y < ROWNO; y++) { - for (x = 0; x < COLNO; x++) { - lev = &levl[x][y]; - if (x == u.ux && y == u.uy) - row[x] = '@'; - else if (IS_WALL(lev->typ) || lev->typ == SDOOR) - row[x] = '0' + (lev->wall_info & WM_MASK); - else if (lev->typ == CORR) - row[x] = '#'; - else if (IS_ROOM(lev->typ) || IS_DOOR(lev->typ)) - row[x] = '.'; - else - row[x] = 'x'; - } - row[COLNO] = '\0'; - /* map column 0, levl[0][], is off the left edge of the screen */ - putstr(win, 0, &row[1]); - } - display_nhwindow(win, TRUE); - destroy_nhwindow(win); - return 0; + win = create_nhwindow(NHW_TEXT); + if (istty) + putstr(win, 0, ""); /* tty only: blank top line */ + for (y = 0; y < ROWNO; y++) { + for (x = 0; x < COLNO; x++) { + lev = &levl[x][y]; + if (x == u.ux && y == u.uy) + row[x] = '@'; + else if (IS_WALL(lev->typ) || lev->typ == SDOOR) + row[x] = '0' + (lev->wall_info & WM_MASK); + else if (lev->typ == CORR) + row[x] = '#'; + else if (IS_ROOM(lev->typ) || IS_DOOR(lev->typ)) + row[x] = '.'; + else + row[x] = 'x'; + } + row[COLNO] = '\0'; + /* map column 0, levl[0][], is off the left edge of the screen */ + putstr(win, 0, &row[1]); + } + display_nhwindow(win, TRUE); + destroy_nhwindow(win); + return 0; } /* wizard mode variant of #terrain; internal levl[][].typ values in base-36 */ STATIC_OVL void wiz_map_levltyp(VOID_ARGS) { - winid win; - int x, y, terrain; - char row[COLNO+1]; - boolean istty = !strcmp(windowprocs.name, "tty"); + winid win; + int x, y, terrain; + char row[COLNO + 1]; + boolean istty = !strcmp(windowprocs.name, "tty"); - win = create_nhwindow(NHW_TEXT); - /* map row 0, levl[][0], is drawn on the second line of tty screen */ - if (istty) putstr(win, 0, ""); /* tty only: blank top line */ - for (y = 0; y < ROWNO; y++) { - /* map column 0, levl[0][], is off the left edge of the screen; - it should always have terrain type "undiggable stone" */ - for (x = 1; x < COLNO; x++) { - terrain = levl[x][y].typ; - /* assumes there aren't more than 10+26+26 terrain types */ - row[x-1] = (char)((terrain == 0 && !may_dig(x, y)) ? '*' : - (terrain < 10) ? '0' + terrain : - (terrain < 36) ? 'a' + terrain - 10 : - 'A' + terrain - 36); - } - if (levl[0][y].typ != 0 || may_dig(0, y)) row[x++] = '!'; - row[x] = '\0'; - putstr(win, 0, row); - } - - { - char dsc[BUFSZ]; - s_level *slev = Is_special(&u.uz); - - Sprintf(dsc, "D:%d,L:%d", u.uz.dnum, u.uz.dlevel); - /* [dungeon branch features currently omitted] */ - /* special level features */ - if (slev) { - Sprintf(eos(dsc), " \"%s\"", slev->proto); - /* special level flags (note: dungeon.def doesn't set `maze' - or `hell' for any specific levels so those never show up) */ - if (slev->flags.maze_like) Strcat(dsc, " mazelike"); - if (slev->flags.hellish) Strcat(dsc, " hellish"); - if (slev->flags.town) Strcat(dsc, " town"); - if (slev->flags.rogue_like) Strcat(dsc, " roguelike"); - /* alignment currently omitted to save space */ - } - /* level features */ - if (level.flags.nfountains) Sprintf(eos(dsc), " %c:%d", - defsyms[S_fountain].sym, - (int)level.flags.nfountains); - if (level.flags.nsinks) Sprintf(eos(dsc), " %c:%d", - defsyms[S_sink].sym, - (int)level.flags.nsinks); - if (level.flags.has_vault) Strcat(dsc, " vault"); - if (level.flags.has_shop) Strcat(dsc, " shop"); - if (level.flags.has_temple) Strcat(dsc, " temple"); - if (level.flags.has_court) Strcat(dsc, " throne"); - if (level.flags.has_zoo) Strcat(dsc, " zoo"); - if (level.flags.has_morgue) Strcat(dsc, " morgue"); - if (level.flags.has_barracks) Strcat(dsc, " barracks"); - if (level.flags.has_beehive) Strcat(dsc, " hive"); - if (level.flags.has_swamp) Strcat(dsc, " swamp"); - /* level flags */ - if (level.flags.noteleport) Strcat(dsc, " noTport"); - if (level.flags.hardfloor) Strcat(dsc, " noDig"); - if (level.flags.nommap) Strcat(dsc, " noMMap"); - if (!level.flags.hero_memory) Strcat(dsc, " noMem"); - if (level.flags.shortsighted) Strcat(dsc, " shortsight"); - if (level.flags.graveyard) Strcat(dsc, " graveyard"); - if (level.flags.is_maze_lev) Strcat(dsc, " maze"); - if (level.flags.is_cavernous_lev) Strcat(dsc, " cave"); - if (level.flags.arboreal) Strcat(dsc, " tree"); - if (Sokoban) Strcat(dsc, " sokoban-rules"); - /* non-flag info; probably should include dungeon branching - checks (extra stairs and magic portals) here */ - if (Invocation_lev(&u.uz)) Strcat(dsc, " invoke"); - if (On_W_tower_level(&u.uz)) Strcat(dsc, " tower"); - /* append a branch identifier for completeness' sake */ - if (u.uz.dnum == 0) Strcat(dsc, " dungeon"); - else if (u.uz.dnum == mines_dnum) Strcat(dsc, " mines"); - else if (In_sokoban(&u.uz)) Strcat(dsc, " sokoban"); - else if (u.uz.dnum == quest_dnum) Strcat(dsc, " quest"); - else if (Is_knox(&u.uz)) Strcat(dsc, " ludios"); - else if (u.uz.dnum == 1) Strcat(dsc, " gehennom"); - else if (u.uz.dnum == tower_dnum) Strcat(dsc, " vlad"); - else if (In_endgame(&u.uz)) Strcat(dsc, " endgame"); - else { - /* somebody's added a dungeon branch we're not expecting */ - const char *brname = dungeons[u.uz.dnum].dname; - - if (!brname || !*brname) brname = "unknown"; - if (!strncmpi(brname, "the ", 4)) brname += 4; - Sprintf(eos(dsc), " %s", brname); - } - /* limit the line length to map width */ - if (strlen(dsc) >= COLNO) dsc[COLNO-1] = '\0'; /* truncate */ - putstr(win, 0, dsc); + win = create_nhwindow(NHW_TEXT); + /* map row 0, levl[][0], is drawn on the second line of tty screen */ + if (istty) + putstr(win, 0, ""); /* tty only: blank top line */ + for (y = 0; y < ROWNO; y++) { + /* map column 0, levl[0][], is off the left edge of the screen; + it should always have terrain type "undiggable stone" */ + for (x = 1; x < COLNO; x++) { + terrain = levl[x][y].typ; + /* assumes there aren't more than 10+26+26 terrain types */ + row[x - 1] = + (char) ((terrain == 0 && !may_dig(x, y)) + ? '*' + : (terrain < 10) + ? '0' + terrain + : (terrain < 36) ? 'a' + terrain - 10 + : 'A' + terrain - 36); + } + if (levl[0][y].typ != 0 || may_dig(0, y)) + row[x++] = '!'; + row[x] = '\0'; + putstr(win, 0, row); } - display_nhwindow(win, TRUE); - destroy_nhwindow(win); - return; + { + char dsc[BUFSZ]; + s_level *slev = Is_special(&u.uz); + + Sprintf(dsc, "D:%d,L:%d", u.uz.dnum, u.uz.dlevel); + /* [dungeon branch features currently omitted] */ + /* special level features */ + if (slev) { + Sprintf(eos(dsc), " \"%s\"", slev->proto); + /* special level flags (note: dungeon.def doesn't set `maze' + or `hell' for any specific levels so those never show up) */ + if (slev->flags.maze_like) + Strcat(dsc, " mazelike"); + if (slev->flags.hellish) + Strcat(dsc, " hellish"); + if (slev->flags.town) + Strcat(dsc, " town"); + if (slev->flags.rogue_like) + Strcat(dsc, " roguelike"); + /* alignment currently omitted to save space */ + } + /* level features */ + if (level.flags.nfountains) + Sprintf(eos(dsc), " %c:%d", defsyms[S_fountain].sym, + (int) level.flags.nfountains); + if (level.flags.nsinks) + Sprintf(eos(dsc), " %c:%d", defsyms[S_sink].sym, + (int) level.flags.nsinks); + if (level.flags.has_vault) + Strcat(dsc, " vault"); + if (level.flags.has_shop) + Strcat(dsc, " shop"); + if (level.flags.has_temple) + Strcat(dsc, " temple"); + if (level.flags.has_court) + Strcat(dsc, " throne"); + if (level.flags.has_zoo) + Strcat(dsc, " zoo"); + if (level.flags.has_morgue) + Strcat(dsc, " morgue"); + if (level.flags.has_barracks) + Strcat(dsc, " barracks"); + if (level.flags.has_beehive) + Strcat(dsc, " hive"); + if (level.flags.has_swamp) + Strcat(dsc, " swamp"); + /* level flags */ + if (level.flags.noteleport) + Strcat(dsc, " noTport"); + if (level.flags.hardfloor) + Strcat(dsc, " noDig"); + if (level.flags.nommap) + Strcat(dsc, " noMMap"); + if (!level.flags.hero_memory) + Strcat(dsc, " noMem"); + if (level.flags.shortsighted) + Strcat(dsc, " shortsight"); + if (level.flags.graveyard) + Strcat(dsc, " graveyard"); + if (level.flags.is_maze_lev) + Strcat(dsc, " maze"); + if (level.flags.is_cavernous_lev) + Strcat(dsc, " cave"); + if (level.flags.arboreal) + Strcat(dsc, " tree"); + if (Sokoban) + Strcat(dsc, " sokoban-rules"); + /* non-flag info; probably should include dungeon branching + checks (extra stairs and magic portals) here */ + if (Invocation_lev(&u.uz)) + Strcat(dsc, " invoke"); + if (On_W_tower_level(&u.uz)) + Strcat(dsc, " tower"); + /* append a branch identifier for completeness' sake */ + if (u.uz.dnum == 0) + Strcat(dsc, " dungeon"); + else if (u.uz.dnum == mines_dnum) + Strcat(dsc, " mines"); + else if (In_sokoban(&u.uz)) + Strcat(dsc, " sokoban"); + else if (u.uz.dnum == quest_dnum) + Strcat(dsc, " quest"); + else if (Is_knox(&u.uz)) + Strcat(dsc, " ludios"); + else if (u.uz.dnum == 1) + Strcat(dsc, " gehennom"); + else if (u.uz.dnum == tower_dnum) + Strcat(dsc, " vlad"); + else if (In_endgame(&u.uz)) + Strcat(dsc, " endgame"); + else { + /* somebody's added a dungeon branch we're not expecting */ + const char *brname = dungeons[u.uz.dnum].dname; + + if (!brname || !*brname) + brname = "unknown"; + if (!strncmpi(brname, "the ", 4)) + brname += 4; + Sprintf(eos(dsc), " %s", brname); + } + /* limit the line length to map width */ + if (strlen(dsc) >= COLNO) + dsc[COLNO - 1] = '\0'; /* truncate */ + putstr(win, 0, dsc); + } + + display_nhwindow(win, TRUE); + destroy_nhwindow(win); + return; } /* temporary? hack, since level type codes aren't the same as screen symbols and only the latter have easily accessible descriptions */ static const char *levltyp[] = { - "stone", - "vertical wall", - "horizontal wall", - "top-left corner wall", - "top-right corner wall", - "bottom-left corner wall", - "bottom-right corner wall", - "cross wall", - "tee-up wall", - "tee-down wall", - "tee-left wall", - "tee-right wall", - "drawbridge wall", - "tree", - "secret door", - "secret corridor", - "pool", - "moat", - "water", - "drawbridge up", - "lava pool", - "iron bars", - "door", - "corridor", - "room", - "stairs", - "ladder", - "fountain", - "throne", - "sink", - "grave", - "altar", - "ice", - "drawbridge down", - "air", - "cloud", - /* not a real terrain type, but used for undiggable stone - by wiz_map_levltyp() */ - "unreachable/undiggable", - /* padding in case the number of entries above is odd */ - "" + "stone", "vertical wall", "horizontal wall", "top-left corner wall", + "top-right corner wall", "bottom-left corner wall", + "bottom-right corner wall", "cross wall", "tee-up wall", "tee-down wall", + "tee-left wall", "tee-right wall", "drawbridge wall", "tree", + "secret door", "secret corridor", "pool", "moat", "water", + "drawbridge up", "lava pool", "iron bars", "door", "corridor", "room", + "stairs", "ladder", "fountain", "throne", "sink", "grave", "altar", "ice", + "drawbridge down", "air", "cloud", + /* not a real terrain type, but used for undiggable stone + by wiz_map_levltyp() */ + "unreachable/undiggable", + /* padding in case the number of entries above is odd */ + "" }; /* explanation of base-36 output from wiz_map_levltyp() */ STATIC_OVL void wiz_levltyp_legend(VOID_ARGS) { - winid win; - int i, j, last, c; - const char *dsc, *fmt; - char buf[BUFSZ]; + winid win; + int i, j, last, c; + const char *dsc, *fmt; + char buf[BUFSZ]; - win = create_nhwindow(NHW_TEXT); - putstr(win, 0, "#terrain encodings:"); - putstr(win, 0, ""); - fmt = " %c - %-28s"; /* TODO: include tab-separated variant for win32 */ - *buf = '\0'; - /* output in pairs, left hand column holds [0],[1],...,[N/2-1] - and right hand column holds [N/2],[N/2+1],...,[N-1]; - N ('last') will always be even, and may or may not include - the empty string entry to pad out the final pair, depending - upon how many other entries are present in levltyp[] */ - last = SIZE(levltyp) & ~1; - for (i = 0; i < last / 2; ++i) - for (j = i; j < last; j += last / 2) { - dsc = levltyp[j]; - c = !*dsc ? ' ' : !strncmp(dsc, "unreachable", 11) ? '*' : - /* same int-to-char conversion as wiz_map_levltyp() */ - (j < 10) ? '0' + j : (j < 36) ? 'a' + j - 10 : 'A' + j - 36; - Sprintf(eos(buf), fmt, c, dsc); - if (j > i) { - putstr(win, 0, buf); - *buf = '\0'; - } - } - display_nhwindow(win, TRUE); - destroy_nhwindow(win); - return; + win = create_nhwindow(NHW_TEXT); + putstr(win, 0, "#terrain encodings:"); + putstr(win, 0, ""); + fmt = " %c - %-28s"; /* TODO: include tab-separated variant for win32 */ + *buf = '\0'; + /* output in pairs, left hand column holds [0],[1],...,[N/2-1] + and right hand column holds [N/2],[N/2+1],...,[N-1]; + N ('last') will always be even, and may or may not include + the empty string entry to pad out the final pair, depending + upon how many other entries are present in levltyp[] */ + last = SIZE(levltyp) & ~1; + for (i = 0; i < last / 2; ++i) + for (j = i; j < last; j += last / 2) { + dsc = levltyp[j]; + c = !*dsc ? ' ' : !strncmp(dsc, "unreachable", 11) + ? '*' + : + /* same int-to-char conversion as + wiz_map_levltyp() */ + (j < 10) ? '0' + j : (j < 36) + ? 'a' + j - 10 + : 'A' + j - 36; + Sprintf(eos(buf), fmt, c, dsc); + if (j > i) { + putstr(win, 0, buf); + *buf = '\0'; + } + } + display_nhwindow(win, TRUE); + destroy_nhwindow(win); + return; } /* #wizsmell command - test usmellmon(). */ STATIC_PTR int wiz_smell(VOID_ARGS) { - int ans = 0; - int mndx; /* monster index */ - coord cc; /* screen pos of unknown glyph */ - int glyph; /* glyph at selected position */ + int ans = 0; + int mndx; /* monster index */ + coord cc; /* screen pos of unknown glyph */ + int glyph; /* glyph at selected position */ - cc.x = u.ux; - cc.y = u.uy; - mndx = 0; /* gcc -Wall lint */ - if (!olfaction(youmonst.data)) { - You("are incapable of detecting odors in your present form."); - return 0; - } + cc.x = u.ux; + cc.y = u.uy; + mndx = 0; /* gcc -Wall lint */ + if (!olfaction(youmonst.data)) { + You("are incapable of detecting odors in your present form."); + return 0; + } - pline("You can move the cursor to a monster that you want to smell."); - do { - pline("Pick a monster to smell."); - ans = getpos(&cc, TRUE, "a monster"); - if (ans < 0 || cc.x < 0) { - return 0; /* done */ - } - /* Convert the glyph at the selected position to a mndxbol. */ - glyph = glyph_at(cc.x,cc.y); - if (glyph_is_monster(glyph)) - mndx = glyph_to_mon(glyph); - else - mndx = 0; - /* Is it a monster? */ - if (mndx) { - if (!usmellmon(&mons[mndx])) - pline("That monster seems to give off no smell."); - } else pline("That is not a monster."); - } while (TRUE); - return 0; + pline("You can move the cursor to a monster that you want to smell."); + do { + pline("Pick a monster to smell."); + ans = getpos(&cc, TRUE, "a monster"); + if (ans < 0 || cc.x < 0) { + return 0; /* done */ + } + /* Convert the glyph at the selected position to a mndxbol. */ + glyph = glyph_at(cc.x, cc.y); + if (glyph_is_monster(glyph)) + mndx = glyph_to_mon(glyph); + else + mndx = 0; + /* Is it a monster? */ + if (mndx) { + if (!usmellmon(&mons[mndx])) + pline("That monster seems to give off no smell."); + } else + pline("That is not a monster."); + } while (TRUE); + return 0; } /* #wizrumorcheck command - verify each rumor access */ STATIC_PTR int wiz_rumor_check(VOID_ARGS) { - rumor_check(); - return 0; + rumor_check(); + return 0; } /* #terrain command */ STATIC_PTR int doterrain(VOID_ARGS) { - int which = 1; /* show known map, ala crawl's '|' command */ + int which = 1; /* show known map, ala crawl's '|' command */ if (discover || wizard) { - /* explore mode #terrain: choose between known map and full map; - wizard mode #terrain: choose between known map, full map, - a dump of the internal levl[][].typ codes w/ level flags, - and a legend for the levl[][].typ codes */ - winid men; - menu_item *sel; - anything any; - int n; + /* explore mode #terrain: choose between known map and full map; + wizard mode #terrain: choose between known map, full map, + a dump of the internal levl[][].typ codes w/ level flags, + and a legend for the levl[][].typ codes */ + winid men; + menu_item *sel; + anything any; + int n; - men = create_nhwindow(NHW_MENU); - any = zeroany; - any.a_int = 1; - add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, - "known map without monsters, objects, and traps", - MENU_SELECTED); - any.a_int = 2; - add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, - "full map without monsters, objects, and traps", - MENU_UNSELECTED); - if (wizard) { - any.a_int = 3; - add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, - "internal levl[][].typ codes in base-36", - MENU_UNSELECTED); - any.a_int = 4; - add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, - "legend of base-36 levl[][].typ codes", - MENU_UNSELECTED); - } - end_menu(men, "View which?"); + men = create_nhwindow(NHW_MENU); + any = zeroany; + any.a_int = 1; + add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, + "known map without monsters, objects, and traps", + MENU_SELECTED); + any.a_int = 2; + add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, + "full map without monsters, objects, and traps", + MENU_UNSELECTED); + if (wizard) { + any.a_int = 3; + add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, + "internal levl[][].typ codes in base-36", + MENU_UNSELECTED); + any.a_int = 4; + add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, + "legend of base-36 levl[][].typ codes", MENU_UNSELECTED); + } + end_menu(men, "View which?"); - n = select_menu(men, PICK_ONE, &sel); - destroy_nhwindow(men); - /* - * n < 0: player used ESC to cancel; - * n == 0: preselected entry was explicitly chosen and got toggled off; - * n == 1: preselected entry was implicitly chosen via |; - * n == 2: another entry was explicitly chosen, so skip preselected one - */ - which = (n < 0) ? -1 : (n == 0) ? 1 : sel[0].item.a_int; - if (n > 1 && which == 1) which = sel[1].item.a_int; - if (n > 0) free((genericptr_t)sel); + n = select_menu(men, PICK_ONE, &sel); + destroy_nhwindow(men); + /* + * n < 0: player used ESC to cancel; + * n == 0: preselected entry was explicitly chosen and got toggled + * off; + * n == 1: preselected entry was implicitly chosen via + * |; + * n == 2: another entry was explicitly chosen, so skip preselected + * one + */ + which = (n < 0) ? -1 : (n == 0) ? 1 : sel[0].item.a_int; + if (n > 1 && which == 1) + which = sel[1].item.a_int; + if (n > 0) + free((genericptr_t) sel); } /* discover || wizard */ switch (which) { - case 1: reveal_terrain(FALSE); break; /* known map */ - case 2: reveal_terrain(TRUE); break; /* full map */ - case 3: wiz_map_levltyp(); break; /* map internals */ - case 4: wiz_levltyp_legend(); break; /* internal details */ - default: break; + case 1: + reveal_terrain(FALSE); + break; /* known map */ + case 2: + reveal_terrain(TRUE); + break; /* full map */ + case 3: + wiz_map_levltyp(); + break; /* map internals */ + case 4: + wiz_levltyp_legend(); + break; /* internal details */ + default: + break; } - return 0; /* no time elapses */ + return 0; /* no time elapses */ } - /* -enlightenment and conduct- */ static winid en_win = WIN_ERR; -static const char - You_[] = "You ", - are[] = "are ", were[] = "were ", - have[] = "have ", had[] = "had ", - can[] = "can ", could[] = "could "; -static const char - have_been[] = "have been ", - have_never[] = "have never ", never[] = "never "; +static const char You_[] = "You ", are[] = "are ", were[] = "were ", + have[] = "have ", had[] = "had ", can[] = "can ", + could[] = "could "; +static const char have_been[] = "have been ", have_never[] = "have never ", + never[] = "never "; -#define enl_msg(prefix,present,past,suffix,ps) \ - enlght_line(prefix, final ? past : present, suffix, ps) -#define you_are(attr,ps) enl_msg(You_,are,were,attr,ps) -#define you_have(attr,ps) enl_msg(You_,have,had,attr,ps) -#define you_can(attr,ps) enl_msg(You_,can,could,attr,ps) -#define you_have_been(goodthing) enl_msg(You_,have_been,were,goodthing,"") -#define you_have_never(badthing) enl_msg(You_,have_never,never,badthing,"") -#define you_have_X(something) enl_msg(You_,have,(const char *)"",something,"") +#define enl_msg(prefix, present, past, suffix, ps) \ + enlght_line(prefix, final ? past : present, suffix, ps) +#define you_are(attr, ps) enl_msg(You_, are, were, attr, ps) +#define you_have(attr, ps) enl_msg(You_, have, had, attr, ps) +#define you_can(attr, ps) enl_msg(You_, can, could, attr, ps) +#define you_have_been(goodthing) enl_msg(You_, have_been, were, goodthing, "") +#define you_have_never(badthing) \ + enl_msg(You_, have_never, never, badthing, "") +#define you_have_X(something) \ + enl_msg(You_, have, (const char *) "", something, "") static void enlght_line(start, middle, end, ps) const char *start, *middle, *end, *ps; { - char buf[BUFSZ]; + char buf[BUFSZ]; - Sprintf(buf, " %s%s%s%s.", start, middle, end, ps); - putstr(en_win, 0, buf); + Sprintf(buf, " %s%s%s%s.", start, middle, end, ps); + putstr(en_win, 0, buf); } /* format increased chance to hit or damage or defense (Protection) */ @@ -1149,33 +1219,37 @@ const char *inctyp; int incamt, final; char *outbuf; { - const char *modif, *bonus; - boolean invrt; - int absamt; + const char *modif, *bonus; + boolean invrt; + int absamt; - absamt = abs(incamt); - /* Protection amount is typically larger than damage or to-hit; - reduce magnitude by a third in order to stretch modifier ranges - (small:1..5, moderate:6..10, large:11..19, huge:20+) */ - if (!strcmp(inctyp, "defense")) absamt = (absamt * 2) / 3; + absamt = abs(incamt); + /* Protection amount is typically larger than damage or to-hit; + reduce magnitude by a third in order to stretch modifier ranges + (small:1..5, moderate:6..10, large:11..19, huge:20+) */ + if (!strcmp(inctyp, "defense")) + absamt = (absamt * 2) / 3; - if (absamt <= 3) modif = "small"; - else if (absamt <= 6) modif = "moderate"; - else if (absamt <= 12) modif = "large"; - else modif = "huge"; + if (absamt <= 3) + modif = "small"; + else if (absamt <= 6) + modif = "moderate"; + else if (absamt <= 12) + modif = "large"; + else + modif = "huge"; - modif = !incamt ? "no" : an(modif); /* ("no" case shouldn't happen) */ - bonus = (incamt >= 0) ? "bonus" : "penalty"; - /* "bonus " (to hit) vs " bonus" (damage, defense) */ - invrt = strcmp(inctyp, "to hit") ? TRUE : FALSE; + modif = !incamt ? "no" : an(modif); /* ("no" case shouldn't happen) */ + bonus = (incamt >= 0) ? "bonus" : "penalty"; + /* "bonus " (to hit) vs " bonus" (damage, defense) */ + invrt = strcmp(inctyp, "to hit") ? TRUE : FALSE; - Sprintf(outbuf, "%s %s %s", modif, - invrt ? inctyp : bonus, invrt ? bonus : inctyp); - if (final || wizard) - Sprintf(eos(outbuf), " (%s%d)", - (incamt > 0) ? "+" : "", incamt); + Sprintf(outbuf, "%s %s %s", modif, invrt ? inctyp : bonus, + invrt ? bonus : inctyp); + if (final || wizard) + Sprintf(eos(outbuf), " (%s%d)", (incamt > 0) ? "+" : "", incamt); - return outbuf; + return outbuf; } /* report half physical or half spell damage */ @@ -1184,25 +1258,32 @@ enlght_halfdmg(category, final) int category; int final; { - const char *category_name; - char buf[BUFSZ]; + const char *category_name; + char buf[BUFSZ]; - switch (category) { - case HALF_PHDAM: category_name = "physical"; break; - case HALF_SPDAM: category_name = "spell"; break; - default: category_name = "unknown"; break; - } - Sprintf(buf, " %s %s damage", - (final || wizard) ? "half" : "reduced", category_name); - enl_msg(You_, "take", "took", buf, from_what(category)); + switch (category) { + case HALF_PHDAM: + category_name = "physical"; + break; + case HALF_SPDAM: + category_name = "spell"; + break; + default: + category_name = "unknown"; + break; + } + Sprintf(buf, " %s %s damage", (final || wizard) ? "half" : "reduced", + category_name); + enl_msg(You_, "take", "took", buf, from_what(category)); } /* is hero actively using water walking capability on water (or lava)? */ STATIC_OVL boolean walking_on_water() { - if (u.uinwater || Levitation || Flying) return FALSE; - return (Wwalking && (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))); + if (u.uinwater || Levitation || Flying) + return FALSE; + return (Wwalking && (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))); } /* check whether hero is wearing something that player definitely knows @@ -1210,61 +1291,63 @@ walking_on_water() discovered but it doesn't necessarily have to be fully identified */ STATIC_OVL boolean cause_known(propindx) -int propindx; /* index of a property which can be conveyed by worn item */ +int propindx; /* index of a property which can be conveyed by worn item */ { - register struct obj *o; - long mask = W_ARMOR | W_AMUL | W_RING | W_TOOL; + register struct obj *o; + long mask = W_ARMOR | W_AMUL | W_RING | W_TOOL; - /* simpler than from_what()/what_gives(); we don't attempt to - handle artifacts and we deliberately ignore wielded items */ - for (o = invent; o; o = o->nobj) { - if (!(o->owornmask & mask)) continue; - if ((int)objects[o->otyp].oc_oprop == propindx && - objects[o->otyp].oc_name_known && o->dknown) - return TRUE; - } - return FALSE; + /* simpler than from_what()/what_gives(); we don't attempt to + handle artifacts and we deliberately ignore wielded items */ + for (o = invent; o; o = o->nobj) { + if (!(o->owornmask & mask)) + continue; + if ((int) objects[o->otyp].oc_oprop == propindx + && objects[o->otyp].oc_name_known && o->dknown) + return TRUE; + } + return FALSE; } /* format a characteristic value, accommodating Strength's strangeness */ STATIC_OVL char * attrval(attrindx, attrvalue, resultbuf) int attrindx, attrvalue; -char resultbuf[]; /* should be at least [7] to hold "18/100\0" */ +char resultbuf[]; /* should be at least [7] to hold "18/100\0" */ { - if (attrindx != A_STR || attrvalue <= 18) - Sprintf(resultbuf, "%d", attrvalue); - else if (attrvalue > STR18(100)) /* 19 to 25 */ - Sprintf(resultbuf, "%d", attrvalue - 100); - else /* simplify "18/ **" to be "18/100" */ - Sprintf(resultbuf, "18/%02d", attrvalue - 18); - return resultbuf; + if (attrindx != A_STR || attrvalue <= 18) + Sprintf(resultbuf, "%d", attrvalue); + else if (attrvalue > STR18(100)) /* 19 to 25 */ + Sprintf(resultbuf, "%d", attrvalue - 100); + else /* simplify "18/ **" to be "18/100" */ + Sprintf(resultbuf, "18/%02d", attrvalue - 18); + return resultbuf; } void enlightenment(mode, final) -int mode; /* BASICENLIGHTENMENT | MAGICENLIGHTENMENT (| both) */ -int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ +int mode; /* BASICENLIGHTENMENT | MAGICENLIGHTENMENT (| both) */ +int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ { char buf[BUFSZ], tmpbuf[BUFSZ]; Strcpy(tmpbuf, plname); - *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */ + *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */ /* as in background_enlighenment, when poly'd we need to use the saved gender in u.mfemale rather than the current you-as-monster gender */ Sprintf(buf, "%s the %s's attributes:", tmpbuf, - ((Upolyd ? u.mfemale : flags.female) && urole.name.f) ? - urole.name.f : urole.name.m); + ((Upolyd ? u.mfemale : flags.female) && urole.name.f) + ? urole.name.f + : urole.name.m); en_win = create_nhwindow(NHW_MENU); /* title */ - putstr(en_win, 0, buf); /* "Conan the Archeologist's attributes:" */ + putstr(en_win, 0, buf); /* "Conan the Archeologist's attributes:" */ /* background and characteristics; ^X or end-of-game disclosure */ if (mode & BASICENLIGHTENMENT) { - /* role, race, alignment, deities */ - background_enlightenment(mode, final); - /* strength, dexterity, &c */ - characteristics_enlightenment(mode, final); + /* role, race, alignment, deities */ + background_enlightenment(mode, final); + /* strength, dexterity, &c */ + characteristics_enlightenment(mode, final); } /* expanded status line information, including things which aren't included there due to space considerations--such as obvious @@ -1275,8 +1358,8 @@ int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ /* remaining attributes; shown for potion,&c or wizard mode and explore mode ^X or end of game disclosure */ if (mode & MAGICENLIGHTENMENT) { - /* intrinsics and other traditional enlightenment feedback */ - attributes_enlightenment(mode, final); + /* intrinsics and other traditional enlightenment feedback */ + attributes_enlightenment(mode, final); } display_nhwindow(en_win, TRUE); destroy_nhwindow(en_win); @@ -1295,12 +1378,13 @@ int final; char buf[BUFSZ], tmpbuf[BUFSZ]; /* note that if poly'd, we need to use u.mfemale instead of flags.female - to access hero's saved gender-as-human/elf/&c rather than current one */ + to access hero's saved gender-as-human/elf/&c rather than current one + */ innategend = (Upolyd ? u.mfemale : flags.female) ? 1 : 0; role_titl = (innategend && urole.name.f) ? urole.name.f : urole.name.m; rank_titl = rank_of(u.ulevel, Role_switch, innategend); - putstr(en_win, 0, ""); /* separator after title */ + putstr(en_win, 0, ""); /* separator after title */ putstr(en_win, 0, "Background:"); /* if polymorphed, report current shape before underlying role; @@ -1310,61 +1394,66 @@ int final; (with countdown timer appended for wizard mode); we really want the player to know he's not a samurai at the moment... */ if (Upolyd) { - struct permonst *uasmon = youmonst.data; + struct permonst *uasmon = youmonst.data; - tmpbuf[0] = '\0'; - /* here we always use current gender, not saved role gender */ - if (!is_male(uasmon) && !is_female(uasmon) && !is_neuter(uasmon)) - Sprintf(tmpbuf, "%s ", genders[flags.female ? 1 : 0].adj); - Sprintf(buf, "%sin %s%s form", - !final ? "currently " : "", tmpbuf, uasmon->mname); - you_are(buf, ""); + tmpbuf[0] = '\0'; + /* here we always use current gender, not saved role gender */ + if (!is_male(uasmon) && !is_female(uasmon) && !is_neuter(uasmon)) + Sprintf(tmpbuf, "%s ", genders[flags.female ? 1 : 0].adj); + Sprintf(buf, "%sin %s%s form", !final ? "currently " : "", tmpbuf, + uasmon->mname); + you_are(buf, ""); } /* report role; omit gender if it's redundant (eg, "female priestess") */ tmpbuf[0] = '\0'; - if (!urole.name.f && - ((urole.allow & ROLE_GENDMASK) == (ROLE_MALE|ROLE_FEMALE) || - innategend != flags.initgend)) - Sprintf(tmpbuf, "%s ", genders[innategend].adj); + if (!urole.name.f + && ((urole.allow & ROLE_GENDMASK) == (ROLE_MALE | ROLE_FEMALE) + || innategend != flags.initgend)) + Sprintf(tmpbuf, "%s ", genders[innategend].adj); buf[0] = '\0'; - if (Upolyd) Strcpy(buf, "actually "); /* "You are actually a ..." */ + if (Upolyd) + Strcpy(buf, "actually "); /* "You are actually a ..." */ if (!strcmpi(rank_titl, role_titl)) { - /* omit role when rank title matches it */ - Sprintf(eos(buf), "%s, level %d %s%s", - an(rank_titl), u.ulevel, tmpbuf, urace.noun); + /* omit role when rank title matches it */ + Sprintf(eos(buf), "%s, level %d %s%s", an(rank_titl), u.ulevel, + tmpbuf, urace.noun); } else { - Sprintf(eos(buf), "%s, a level %d %s%s %s", - an(rank_titl), u.ulevel, tmpbuf, urace.adj, role_titl); + Sprintf(eos(buf), "%s, a level %d %s%s %s", an(rank_titl), u.ulevel, + tmpbuf, urace.adj, role_titl); } you_are(buf, ""); /* report alignment (bypass you_are() in order to omit ending period) */ - Sprintf(buf, " %s%s%s, %son a mission for %s", - You_, !final ? are : were, align_str(u.ualign.type), - /* helm of opposite alignment (might hide conversion) */ - (u.ualign.type != u.ualignbase[A_CURRENT]) ? "temporarily " : - /* permanent conversion */ - (u.ualign.type != u.ualignbase[A_ORIGINAL]) ? "now " : - /* athiest (ignored in very early game); lastly, normal case */ - (!u.uconduct.gnostic && moves > 1000L) ? "nominally " : "", - u_gname()); + Sprintf( + buf, " %s%s%s, %son a mission for %s", You_, !final ? are : were, + align_str(u.ualign.type), + /* helm of opposite alignment (might hide conversion) */ + (u.ualign.type != u.ualignbase[A_CURRENT]) ? "temporarily " : + /* permanent conversion */ + (u.ualign.type != u.ualignbase[A_ORIGINAL]) + ? "now " + : + /* athiest (ignored in very early game); lastly, normal case + */ + (!u.uconduct.gnostic && moves > 1000L) ? "nominally " : "", + u_gname()); putstr(en_win, 0, buf); /* show the rest of this game's pantheon (finishes previous sentence) [appending "also Moloch" at the end would allow for straightforward trailing "and" on all three aligned entries but looks too verbose] */ Sprintf(buf, " who %s opposed by", !final ? "is" : "was"); if (u.ualign.type != A_LAWFUL) - Sprintf(eos(buf), " %s (%s) and", - align_gname(A_LAWFUL), align_str(A_LAWFUL)); + Sprintf(eos(buf), " %s (%s) and", align_gname(A_LAWFUL), + align_str(A_LAWFUL)); if (u.ualign.type != A_NEUTRAL) - Sprintf(eos(buf), " %s (%s)%s", - align_gname(A_NEUTRAL), align_str(A_NEUTRAL), - (u.ualign.type != A_CHAOTIC) ? " and" : ""); + Sprintf(eos(buf), " %s (%s)%s", align_gname(A_NEUTRAL), + align_str(A_NEUTRAL), + (u.ualign.type != A_CHAOTIC) ? " and" : ""); if (u.ualign.type != A_CHAOTIC) - Sprintf(eos(buf), " %s (%s)", - align_gname(A_CHAOTIC), align_str(A_CHAOTIC)); - Strcat(buf, "."); /* terminate sentence */ + Sprintf(eos(buf), " %s (%s)", align_gname(A_CHAOTIC), + align_str(A_CHAOTIC)); + Strcat(buf, "."); /* terminate sentence */ putstr(en_win, 0, buf); /* show original alignment,gender,race,role if any have been changed; @@ -1372,19 +1461,20 @@ int final; for tricky phrasing otherwise necessitated by possibility of having helm of opposite alignment mask a permanent alignment conversion */ difgend = (innategend != flags.initgend); - difalgn = ((u.ualign.type != u.ualignbase[A_CURRENT]) ? 1 : 0) - + ((u.ualignbase[A_CURRENT] != u.ualignbase[A_ORIGINAL]) ? 2 : 0); - if (difalgn & 1) { /* have temporary alignment so report permanent one */ - Sprintf(buf, "actually %s", align_str(u.ualignbase[A_CURRENT])); - you_are(buf, ""); - difalgn &= ~1; /* suppress helm from "started out " message */ + difalgn = + ((u.ualign.type != u.ualignbase[A_CURRENT]) ? 1 : 0) + + ((u.ualignbase[A_CURRENT] != u.ualignbase[A_ORIGINAL]) ? 2 : 0); + if (difalgn & 1) { /* have temporary alignment so report permanent one */ + Sprintf(buf, "actually %s", align_str(u.ualignbase[A_CURRENT])); + you_are(buf, ""); + difalgn &= ~1; /* suppress helm from "started out " message */ } - if (difgend || difalgn) { /* sex change or perm align change or both */ - Sprintf(buf, " You started out %s%s%s.", - difgend ? genders[flags.initgend].adj : "", - (difgend && difalgn) ? " and " : "", - difalgn ? align_str(u.ualignbase[A_ORIGINAL]) : ""); - putstr(en_win, 0, buf); + if (difgend || difalgn) { /* sex change or perm align change or both */ + Sprintf(buf, " You started out %s%s%s.", + difgend ? genders[flags.initgend].adj : "", + (difgend && difalgn) ? " and " : "", + difalgn ? align_str(u.ualignbase[A_ORIGINAL]) : ""); + putstr(en_win, 0, buf); } } @@ -1394,22 +1484,22 @@ characteristics_enlightenment(mode, final) int mode; int final; { - putstr(en_win, 0, ""); /* separator after background */ + putstr(en_win, 0, ""); /* separator after background */ putstr(en_win, 0, - final ? "Final Characteristics:" : "Current Characteristics:"); + final ? "Final Characteristics:" : "Current Characteristics:"); /* bottom line order */ - one_characteristic(mode, final, A_STR); /* strength */ - one_characteristic(mode, final, A_DEX); /* dexterity */ - one_characteristic(mode, final, A_CON); /* constitution */ - one_characteristic(mode, final, A_INT); /* intelligence */ - one_characteristic(mode, final, A_WIS); /* wisdom */ - one_characteristic(mode, final, A_CHA); /* charisma */ + one_characteristic(mode, final, A_STR); /* strength */ + one_characteristic(mode, final, A_DEX); /* dexterity */ + one_characteristic(mode, final, A_CON); /* constitution */ + one_characteristic(mode, final, A_INT); /* intelligence */ + one_characteristic(mode, final, A_WIS); /* wisdom */ + one_characteristic(mode, final, A_CHA); /* charisma */ } /* display one attribute value for characteristics_enlightenment() */ STATIC_OVL void -one_characteristic(mode, final, attrindx) +one_characteristic(mode, final, attrindx) int mode, final, attrindx; { boolean hide_innate_value = FALSE, interesting_alimit; @@ -1424,72 +1514,81 @@ int mode, final, attrindx; and we show those in such case so that player doesn't need to actually resort to doing that */ if (Upolyd) { - hide_innate_value = TRUE; + hide_innate_value = TRUE; } else if (Fixed_abil) { - if (stuck_ring(uleft, RIN_SUSTAIN_ABILITY) || - stuck_ring(uright, RIN_SUSTAIN_ABILITY)) - hide_innate_value = TRUE; + if (stuck_ring(uleft, RIN_SUSTAIN_ABILITY) + || stuck_ring(uright, RIN_SUSTAIN_ABILITY)) + hide_innate_value = TRUE; } switch (attrindx) { - case A_STR: attrname = "strength"; - if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER && - uarmg->cursed) hide_innate_value = TRUE; - break; - case A_DEX: attrname = "dexterity"; - break; - case A_CON: attrname = "constitution"; - break; - case A_INT: attrname = "intelligence"; - if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) - hide_innate_value = TRUE; - break; - case A_WIS: attrname = "wisdom"; - if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) - hide_innate_value = TRUE; - break; - case A_CHA: attrname = "charisma"; - break; - default: return; /* impossible */ + case A_STR: + attrname = "strength"; + if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER && uarmg->cursed) + hide_innate_value = TRUE; + break; + case A_DEX: + attrname = "dexterity"; + break; + case A_CON: + attrname = "constitution"; + break; + case A_INT: + attrname = "intelligence"; + if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) + hide_innate_value = TRUE; + break; + case A_WIS: + attrname = "wisdom"; + if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) + hide_innate_value = TRUE; + break; + case A_CHA: + attrname = "charisma"; + break; + default: + return; /* impossible */ }; /* note: final disclosure includes MAGICENLIGHTENTMENT */ - if ((mode & MAGICENLIGHTENMENT) && !Upolyd) hide_innate_value = FALSE; + if ((mode & MAGICENLIGHTENMENT) && !Upolyd) + hide_innate_value = FALSE; acurrent = ACURR(attrindx); - (void)attrval(attrindx, acurrent, valubuf); /* Sprintf(valubuf,"%d",) */ + (void) attrval(attrindx, acurrent, valubuf); /* Sprintf(valubuf,"%d",) */ Sprintf(subjbuf, "Your %s ", attrname); if (!hide_innate_value) { - /* show abase, amax, and/or attrmax if acurr doesn't match abase - (a magic bonus or penalty is in effect) or abase doesn't match - amax (some points have been lost to poison or exercise abuse - and are restorable) or attrmax is different from normal human - (while game is in progress; trying to reduce dependency on - spoilers to keep track of such stuff) or attrmax was different - from abase (at end of game; this attribute wasn't maxed out) */ - abase = ABASE(attrindx); - apeak = AMAX(attrindx); - alimit = ATTRMAX(attrindx); - /* criterium for whether the limit is interesting varies */ - interesting_alimit = final ? (abase != alimit) : - (alimit != (attrindx != A_STR ? 18 : STR18(100))); - paren_pfx = final ? " (" : " (current; "; - if (acurrent != abase) { - Sprintf(eos(valubuf), "%sbase:%s", paren_pfx, - attrval(attrindx, abase, valstring)); - paren_pfx = ", "; - } - if (abase != apeak) { - Sprintf(eos(valubuf), "%speak:%s", paren_pfx, - attrval(attrindx, apeak, valstring)); - paren_pfx = ", "; - } - if (interesting_alimit) { - Sprintf(eos(valubuf), "%slimit:%s", paren_pfx, - attrval(attrindx, alimit, valstring)); - /* paren_pfx = ", "; */ - } - if (acurrent != abase || abase != apeak || interesting_alimit) - Strcat(valubuf, ")"); + /* show abase, amax, and/or attrmax if acurr doesn't match abase + (a magic bonus or penalty is in effect) or abase doesn't match + amax (some points have been lost to poison or exercise abuse + and are restorable) or attrmax is different from normal human + (while game is in progress; trying to reduce dependency on + spoilers to keep track of such stuff) or attrmax was different + from abase (at end of game; this attribute wasn't maxed out) */ + abase = ABASE(attrindx); + apeak = AMAX(attrindx); + alimit = ATTRMAX(attrindx); + /* criterium for whether the limit is interesting varies */ + interesting_alimit = + final ? (abase != alimit) + : (alimit != (attrindx != A_STR ? 18 : STR18(100))); + paren_pfx = final ? " (" : " (current; "; + if (acurrent != abase) { + Sprintf(eos(valubuf), "%sbase:%s", paren_pfx, + attrval(attrindx, abase, valstring)); + paren_pfx = ", "; + } + if (abase != apeak) { + Sprintf(eos(valubuf), "%speak:%s", paren_pfx, + attrval(attrindx, apeak, valstring)); + paren_pfx = ", "; + } + if (interesting_alimit) { + Sprintf(eos(valubuf), "%slimit:%s", paren_pfx, + attrval(attrindx, alimit, valstring)); + /* paren_pfx = ", "; */ + } + if (acurrent != abase || abase != apeak || interesting_alimit) + Strcat(valubuf, ")"); } enl_msg(subjbuf, "is ", "was ", valubuf, ""); } @@ -1500,228 +1599,259 @@ status_enlightenment(mode, final) int mode; int final; { - boolean magic = (mode & MAGICENLIGHTENMENT) ? TRUE : FALSE; - int cap; - char buf[BUFSZ], youtoo[BUFSZ]; - boolean Riding = (u.usteed && - /* if hero dies while dismounting, u.usteed will still - be set; we want to ignore steed in that situation */ - !(final == ENL_GAMEOVERDEAD && - !strcmp(killer.name, "riding accident"))); - const char *steedname = !Riding ? (char *)0 : - x_monnam(u.usteed, - u.usteed->mtame ? ARTICLE_YOUR : ARTICLE_THE, - (char *)0, - (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION), - FALSE); + boolean magic = (mode & MAGICENLIGHTENMENT) ? TRUE : FALSE; + int cap; + char buf[BUFSZ], youtoo[BUFSZ]; + boolean Riding = (u.usteed + && + /* if hero dies while dismounting, u.usteed will still + be set; we want to ignore steed in that situation */ + !(final == ENL_GAMEOVERDEAD + && !strcmp(killer.name, "riding accident"))); + const char *steedname = + !Riding + ? (char *) 0 + : x_monnam(u.usteed, u.usteed->mtame ? ARTICLE_YOUR : ARTICLE_THE, + (char *) 0, (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION), + FALSE); - /*\ - * Status (many are abbreviated on bottom line; others are or - * should be discernible to the hero hence to the player) - \*/ - putstr(en_win, 0, ""); /* separator after title or characteristics */ - putstr(en_win, 0, final ? "Final Status:" : "Current Status:"); + /*\ + * Status (many are abbreviated on bottom line; others are or + * should be discernible to the hero hence to the player) + \*/ + putstr(en_win, 0, ""); /* separator after title or characteristics */ + putstr(en_win, 0, final ? "Final Status:" : "Current Status:"); - Strcpy(youtoo, You_); - /* not a traditional status but inherently obvious to player; more - detail given below (attributes section) for magic enlightenment */ - if (Upolyd) you_are("transformed", ""); - /* not a trouble, but we want to display riding status before maybe - reporting steed as trapped or hero stuck to cursed saddle */ - if (Riding) { - Sprintf(buf, "riding %s", steedname); - you_are(buf, ""); - Sprintf(eos(youtoo), "and %s ", steedname); - } - /* other movement situations that hero should always know */ - if (Levitation) { - if (Lev_at_will && magic) - you_are("levitating, at will", ""); - else - enl_msg(youtoo, are, were, "levitating", from_what(LEVITATION)); - } else if (Flying) { /* can only fly when not levitating */ - enl_msg(youtoo, are, were, "flying", from_what(FLYING)); - } - if (Underwater) { - you_are("underwater", ""); - } else if (u.uinwater) { - you_are(Swimming ? "swimming" : "in water", from_what(SWIMMING)); - } else if (walking_on_water()) { - /* show active Wwalking here, potential Wwalking elsewhere */ - Sprintf(buf, "walking on %s", - is_pool(u.ux, u.uy) ? "water" : - is_lava(u.ux, u.uy) ? "lava" : - surface(u.ux, u.uy)); /* catchall; shouldn't happen */ - you_are(buf, from_what(WWALKING)); - } - if (Upolyd && (u.uundetected || youmonst.m_ap_type != M_AP_NOTHING)) - youhiding(TRUE, final); + Strcpy(youtoo, You_); + /* not a traditional status but inherently obvious to player; more + detail given below (attributes section) for magic enlightenment */ + if (Upolyd) + you_are("transformed", ""); + /* not a trouble, but we want to display riding status before maybe + reporting steed as trapped or hero stuck to cursed saddle */ + if (Riding) { + Sprintf(buf, "riding %s", steedname); + you_are(buf, ""); + Sprintf(eos(youtoo), "and %s ", steedname); + } + /* other movement situations that hero should always know */ + if (Levitation) { + if (Lev_at_will && magic) + you_are("levitating, at will", ""); + else + enl_msg(youtoo, are, were, "levitating", from_what(LEVITATION)); + } else if (Flying) { /* can only fly when not levitating */ + enl_msg(youtoo, are, were, "flying", from_what(FLYING)); + } + if (Underwater) { + you_are("underwater", ""); + } else if (u.uinwater) { + you_are(Swimming ? "swimming" : "in water", from_what(SWIMMING)); + } else if (walking_on_water()) { + /* show active Wwalking here, potential Wwalking elsewhere */ + Sprintf( + buf, "walking on %s", + is_pool(u.ux, u.uy) + ? "water" + : is_lava(u.ux, u.uy) + ? "lava" + : surface(u.ux, u.uy)); /* catchall; shouldn't happen */ + you_are(buf, from_what(WWALKING)); + } + if (Upolyd && (u.uundetected || youmonst.m_ap_type != M_AP_NOTHING)) + youhiding(TRUE, final); - /* internal troubles, mostly in the order that prayer ranks them */ - if (Stoned) you_are("turning to stone", ""); - if (Slimed) you_are("turning into slime", ""); - if (Strangled) { - if (u.uburied) { - you_are("buried", ""); - } else { - Strcpy(buf, "being strangled"); - if (wizard) Sprintf(eos(buf), " (%ld)", (Strangled & TIMEOUT)); - you_are(buf, from_what(STRANGLED)); - } - } - if (Sick) { - /* prayer lumps these together; botl puts Ill before FoodPois */ - if (u.usick_type & SICK_NONVOMITABLE) - you_are("terminally sick from illness", ""); - if (u.usick_type & SICK_VOMITABLE) - you_are("terminally sick from food poisoning", ""); - } - if (Vomiting) you_are("nauseated", ""); - if (Stunned) you_are("stunned", ""); - if (Confusion) you_are("confused", ""); - if (Hallucination) you_are("hallucinating", ""); - if (Blind) you_are("blind", from_what(BLINDED)); - if (Deaf) you_are("deaf", from_what(DEAF)); + /* internal troubles, mostly in the order that prayer ranks them */ + if (Stoned) + you_are("turning to stone", ""); + if (Slimed) + you_are("turning into slime", ""); + if (Strangled) { + if (u.uburied) { + you_are("buried", ""); + } else { + Strcpy(buf, "being strangled"); + if (wizard) + Sprintf(eos(buf), " (%ld)", (Strangled & TIMEOUT)); + you_are(buf, from_what(STRANGLED)); + } + } + if (Sick) { + /* prayer lumps these together; botl puts Ill before FoodPois */ + if (u.usick_type & SICK_NONVOMITABLE) + you_are("terminally sick from illness", ""); + if (u.usick_type & SICK_VOMITABLE) + you_are("terminally sick from food poisoning", ""); + } + if (Vomiting) + you_are("nauseated", ""); + if (Stunned) + you_are("stunned", ""); + if (Confusion) + you_are("confused", ""); + if (Hallucination) + you_are("hallucinating", ""); + if (Blind) + you_are("blind", from_what(BLINDED)); + if (Deaf) + you_are("deaf", from_what(DEAF)); - /* external troubles, more or less */ - if (Punished) { - if (uball) { - Sprintf(buf, "chained to %s", ansimpleoname(uball)); - } else { - impossible("Punished without uball?"); - Strcpy(buf, "punished"); - } - you_are(buf, ""); - } - if (u.utrap) { - char predicament[BUFSZ]; - struct trap *t; - boolean anchored = (u.utraptype == TT_BURIEDBALL); + /* external troubles, more or less */ + if (Punished) { + if (uball) { + Sprintf(buf, "chained to %s", ansimpleoname(uball)); + } else { + impossible("Punished without uball?"); + Strcpy(buf, "punished"); + } + you_are(buf, ""); + } + if (u.utrap) { + char predicament[BUFSZ]; + struct trap *t; + boolean anchored = (u.utraptype == TT_BURIEDBALL); - if (anchored) { - Strcpy(predicament, "tethered to something buried"); - } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { - Sprintf(predicament, "stuck in %s", the(surface(u.ux, u.uy))); - } else { - Strcpy(predicament, "trapped"); - if ((t = t_at(u.ux, u.uy)) != 0) - Sprintf(eos(predicament), " in %s", - an(defsyms[trap_to_defsym(t->ttyp)].explanation)); - } - if (u.usteed) { /* not `Riding' here */ - Sprintf(buf, "%s%s ", anchored ? "you and " : "", steedname); - *buf = highc(*buf); - enl_msg(buf, (anchored ? "are " : "is "), - (anchored ? "were " : "was "), predicament, ""); - } else - you_are(predicament, ""); - } /* (u.utrap) */ - if (u.uswallow) { - Sprintf(buf, "swallowed by %s", a_monnam(u.ustuck)); - if (wizard) Sprintf(eos(buf), " (%u)", u.uswldtim); - you_are(buf, ""); - } else if (u.ustuck) { - Sprintf(buf, "%s %s", - (Upolyd && sticks(youmonst.data)) ? "holding" : "held by", - a_monnam(u.ustuck)); - you_are(buf, ""); - } - if (Riding) { - struct obj *saddle = which_armor(u.usteed, W_SADDLE); + if (anchored) { + Strcpy(predicament, "tethered to something buried"); + } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { + Sprintf(predicament, "stuck in %s", the(surface(u.ux, u.uy))); + } else { + Strcpy(predicament, "trapped"); + if ((t = t_at(u.ux, u.uy)) != 0) + Sprintf(eos(predicament), " in %s", + an(defsyms[trap_to_defsym(t->ttyp)].explanation)); + } + if (u.usteed) { /* not `Riding' here */ + Sprintf(buf, "%s%s ", anchored ? "you and " : "", steedname); + *buf = highc(*buf); + enl_msg(buf, (anchored ? "are " : "is "), + (anchored ? "were " : "was "), predicament, ""); + } else + you_are(predicament, ""); + } /* (u.utrap) */ + if (u.uswallow) { + Sprintf(buf, "swallowed by %s", a_monnam(u.ustuck)); + if (wizard) + Sprintf(eos(buf), " (%u)", u.uswldtim); + you_are(buf, ""); + } else if (u.ustuck) { + Sprintf(buf, "%s %s", + (Upolyd && sticks(youmonst.data)) ? "holding" : "held by", + a_monnam(u.ustuck)); + you_are(buf, ""); + } + if (Riding) { + struct obj *saddle = which_armor(u.usteed, W_SADDLE); - if (saddle && saddle->cursed) { - Sprintf(buf, "stuck to %s %s", - s_suffix(steedname), simpleonames(saddle)); - you_are(buf, ""); - } - } - if (Wounded_legs) { - /* when mounted, Wounded_legs applies to steed rather than to - hero; we only report steed's wounded legs in wizard mode */ - if (u.usteed) { /* not `Riding' here */ - if (wizard) { - Strcpy(buf, steedname); - *buf = highc(*buf); - enl_msg(buf, " has", " had", " wounded legs", ""); - } - } else { - Sprintf(buf, "wounded %s", makeplural(body_part(LEG))); - you_have(buf, ""); - } - } - if (Glib) { - Sprintf(buf, "slippery %s", makeplural(body_part(FINGER))); - you_have(buf, ""); - } - if (Fumbling) { - if (magic || cause_known(FUMBLING)) - enl_msg(You_, "fumble", "fumbled", "", from_what(FUMBLING)); - } - if (Sleepy) { - if (magic || cause_known(SLEEPY)) { - Strcpy(buf, from_what(SLEEPY)); - if (wizard) Sprintf(eos(buf), " (%ld)", (HSleepy & TIMEOUT)); - enl_msg("You ", "fall", "fell", " asleep uncontrollably", buf); - } - } - /* hunger/nutrition */ - if (Hunger) { - if (magic || cause_known(HUNGER)) - enl_msg(You_, "hunger", "hungered", " rapidly", - from_what(HUNGER)); - } - Strcpy(buf, hu_stat[u.uhs]); /* hunger status; omitted if "normal" */ - mungspaces(buf); /* strip trailing spaces */ - if (*buf) { - *buf = lowc(*buf); /* override capitalization */ - if (!strcmp(buf, "weak")) - Strcat(buf, " from severe hunger"); - else if (!strncmp(buf, "faint", 5)) /* fainting, fainted */ - Strcat(buf, " due to starvation"); - you_are(buf, ""); - } - /* encumbrance */ - if ((cap = near_capacity()) > UNENCUMBERED) { - const char *adj = "?_?"; /* (should always get overridden) */ + if (saddle && saddle->cursed) { + Sprintf(buf, "stuck to %s %s", s_suffix(steedname), + simpleonames(saddle)); + you_are(buf, ""); + } + } + if (Wounded_legs) { + /* when mounted, Wounded_legs applies to steed rather than to + hero; we only report steed's wounded legs in wizard mode */ + if (u.usteed) { /* not `Riding' here */ + if (wizard) { + Strcpy(buf, steedname); + *buf = highc(*buf); + enl_msg(buf, " has", " had", " wounded legs", ""); + } + } else { + Sprintf(buf, "wounded %s", makeplural(body_part(LEG))); + you_have(buf, ""); + } + } + if (Glib) { + Sprintf(buf, "slippery %s", makeplural(body_part(FINGER))); + you_have(buf, ""); + } + if (Fumbling) { + if (magic || cause_known(FUMBLING)) + enl_msg(You_, "fumble", "fumbled", "", from_what(FUMBLING)); + } + if (Sleepy) { + if (magic || cause_known(SLEEPY)) { + Strcpy(buf, from_what(SLEEPY)); + if (wizard) + Sprintf(eos(buf), " (%ld)", (HSleepy & TIMEOUT)); + enl_msg("You ", "fall", "fell", " asleep uncontrollably", buf); + } + } + /* hunger/nutrition */ + if (Hunger) { + if (magic || cause_known(HUNGER)) + enl_msg(You_, "hunger", "hungered", " rapidly", + from_what(HUNGER)); + } + Strcpy(buf, hu_stat[u.uhs]); /* hunger status; omitted if "normal" */ + mungspaces(buf); /* strip trailing spaces */ + if (*buf) { + *buf = lowc(*buf); /* override capitalization */ + if (!strcmp(buf, "weak")) + Strcat(buf, " from severe hunger"); + else if (!strncmp(buf, "faint", 5)) /* fainting, fainted */ + Strcat(buf, " due to starvation"); + you_are(buf, ""); + } + /* encumbrance */ + if ((cap = near_capacity()) > UNENCUMBERED) { + const char *adj = "?_?"; /* (should always get overridden) */ - Strcpy(buf, enc_stat[cap]); - *buf = lowc(*buf); - switch (cap) { - case SLT_ENCUMBER: adj = "slightly"; break; /* burdened */ - case MOD_ENCUMBER: adj = "moderately"; break; /* stressed */ - case HVY_ENCUMBER: adj = "very"; break; /* strained */ - case EXT_ENCUMBER: adj = "extremely"; break; /* overtaxed */ - case OVERLOADED: adj = "not possible"; break; - } - Sprintf(eos(buf), "; movement %s %s%s", !final ? "is" : "was", - adj, (cap < OVERLOADED) ? " slowed" : ""); - you_are(buf, ""); - } else { - /* last resort entry, guarantees Status section is non-empty */ - you_are("unencumbered", ""); - } - /* report being weaponless; distinguish whether gloves are worn */ - if (!uwep) you_are(uarmg ? "empty handed" : /* gloves imply hands */ - /* no weapon and no gloves */ - humanoid(youmonst.data) ? "bare handed" : - /* alternate phrasing for paws or lack of hands */ - "not wielding anything", ""); - /* two-weaponing implies a weapon (not other odd stuff) in each hand */ - else if (u.twoweap) you_are("wielding two weapons at once", ""); - /* report most weapons by their skill class (so a katana will be - described as a long sword, for instance; mattock and hook are - exceptions), or wielded non-weapon item by its object class */ - else { - const char *what = weapon_descr(uwep); + Strcpy(buf, enc_stat[cap]); + *buf = lowc(*buf); + switch (cap) { + case SLT_ENCUMBER: + adj = "slightly"; + break; /* burdened */ + case MOD_ENCUMBER: + adj = "moderately"; + break; /* stressed */ + case HVY_ENCUMBER: + adj = "very"; + break; /* strained */ + case EXT_ENCUMBER: + adj = "extremely"; + break; /* overtaxed */ + case OVERLOADED: + adj = "not possible"; + break; + } + Sprintf(eos(buf), "; movement %s %s%s", !final ? "is" : "was", adj, + (cap < OVERLOADED) ? " slowed" : ""); + you_are(buf, ""); + } else { + /* last resort entry, guarantees Status section is non-empty */ + you_are("unencumbered", ""); + } + /* report being weaponless; distinguish whether gloves are worn */ + if (!uwep) + you_are(uarmg ? "empty handed" : /* gloves imply hands */ + /* no weapon and no gloves */ + humanoid(youmonst.data) + ? "bare handed" + : + /* alternate phrasing for paws or lack of hands */ + "not wielding anything", + ""); + /* two-weaponing implies a weapon (not other odd stuff) in each hand */ + else if (u.twoweap) + you_are("wielding two weapons at once", ""); + /* report most weapons by their skill class (so a katana will be + described as a long sword, for instance; mattock and hook are + exceptions), or wielded non-weapon item by its object class */ + else { + const char *what = weapon_descr(uwep); - if (!strcmpi(what, "armor") || !strcmpi(what, "food") || - !strcmpi(what, "venom")) - Sprintf(buf, "wielding some %s", what); - else - Sprintf(buf, "wielding %s", - (uwep->quan == 1L) ? an(what) : makeplural(what)); - you_are(buf, ""); - } + if (!strcmpi(what, "armor") || !strcmpi(what, "food") + || !strcmpi(what, "venom")) + Sprintf(buf, "wielding some %s", what); + else + Sprintf(buf, "wielding %s", + (uwep->quan == 1L) ? an(what) : makeplural(what)); + you_are(buf, ""); + } } /* attributes: intrinsics and the like, other non-obvious capabilities */ @@ -1730,351 +1860,424 @@ attributes_enlightenment(unused_mode, final) int unused_mode UNUSED; int final; { - static NEARDATA const char - if_surroundings_permitted[] = " if surroundings permitted"; - int ltmp, armpro; - char buf[BUFSZ]; + static NEARDATA const char if_surroundings_permitted[] = + " if surroundings permitted"; + int ltmp, armpro; + char buf[BUFSZ]; - /*\ - * Attributes - \*/ - putstr(en_win, 0, ""); - putstr(en_win, 0, final ? "Final Attributes:" : "Current Attributes:"); + /*\ + * Attributes + \*/ + putstr(en_win, 0, ""); + putstr(en_win, 0, final ? "Final Attributes:" : "Current Attributes:"); - if (u.uevent.uhand_of_elbereth) { - static const char * const hofe_titles[3] = { - "the Hand of Elbereth", - "the Envoy of Balance", - "the Glory of Arioch" - }; - you_are(hofe_titles[u.uevent.uhand_of_elbereth - 1],""); - } + if (u.uevent.uhand_of_elbereth) { + static const char *const hofe_titles[3] = { "the Hand of Elbereth", + "the Envoy of Balance", + "the Glory of Arioch" }; + you_are(hofe_titles[u.uevent.uhand_of_elbereth - 1], ""); + } - /* note: piousness 20 matches MIN_QUEST_ALIGN (quest.h) */ - if (u.ualign.record >= 20) you_are("piously aligned",""); - else if (u.ualign.record > 13) you_are("devoutly aligned",""); - else if (u.ualign.record > 8) you_are("fervently aligned",""); - else if (u.ualign.record > 3) you_are("stridently aligned",""); - else if (u.ualign.record == 3) you_are("aligned",""); - else if (u.ualign.record > 0) you_are("haltingly aligned",""); - else if (u.ualign.record == 0) you_are("nominally aligned",""); - else if (u.ualign.record >= -3) you_have("strayed",""); - else if (u.ualign.record >= -8) you_have("sinned",""); - else you_have("transgressed",""); - if (wizard) { - Sprintf(buf, " %d", u.ualign.record); - enl_msg("Your alignment ", "is", "was", buf, ""); - } + /* note: piousness 20 matches MIN_QUEST_ALIGN (quest.h) */ + if (u.ualign.record >= 20) + you_are("piously aligned", ""); + else if (u.ualign.record > 13) + you_are("devoutly aligned", ""); + else if (u.ualign.record > 8) + you_are("fervently aligned", ""); + else if (u.ualign.record > 3) + you_are("stridently aligned", ""); + else if (u.ualign.record == 3) + you_are("aligned", ""); + else if (u.ualign.record > 0) + you_are("haltingly aligned", ""); + else if (u.ualign.record == 0) + you_are("nominally aligned", ""); + else if (u.ualign.record >= -3) + you_have("strayed", ""); + else if (u.ualign.record >= -8) + you_have("sinned", ""); + else + you_have("transgressed", ""); + if (wizard) { + Sprintf(buf, " %d", u.ualign.record); + enl_msg("Your alignment ", "is", "was", buf, ""); + } - /*** Resistances to troubles ***/ - if (Invulnerable) you_are("invulnerable",from_what(INVULNERABLE)); - if (Antimagic) you_are("magic-protected",from_what(ANTIMAGIC)); - if (Fire_resistance) you_are("fire resistant",from_what(FIRE_RES)); - if (Cold_resistance) you_are("cold resistant",from_what(COLD_RES)); - if (Sleep_resistance) you_are("sleep resistant",from_what(SLEEP_RES)); - if (Disint_resistance) - you_are("disintegration-resistant",from_what(DISINT_RES)); - if (Shock_resistance) you_are("shock resistant",from_what(SHOCK_RES)); - if (Poison_resistance) you_are("poison resistant",from_what(POISON_RES)); - if (Acid_resistance) you_are("acid resistant",from_what(ACID_RES)); - if (Drain_resistance) - you_are("level-drain resistant",from_what(DRAIN_RES)); - if (Sick_resistance) you_are("immune to sickness",from_what(SICK_RES)); - if (Stone_resistance) - you_are("petrification resistant",from_what(STONE_RES)); - if (Halluc_resistance) - enl_msg(You_, "resist", "resisted", " hallucinations", - from_what(HALLUC_RES)); - if (u.uedibility) you_can("recognize detrimental food",""); + /*** Resistances to troubles ***/ + if (Invulnerable) + you_are("invulnerable", from_what(INVULNERABLE)); + if (Antimagic) + you_are("magic-protected", from_what(ANTIMAGIC)); + if (Fire_resistance) + you_are("fire resistant", from_what(FIRE_RES)); + if (Cold_resistance) + you_are("cold resistant", from_what(COLD_RES)); + if (Sleep_resistance) + you_are("sleep resistant", from_what(SLEEP_RES)); + if (Disint_resistance) + you_are("disintegration-resistant", from_what(DISINT_RES)); + if (Shock_resistance) + you_are("shock resistant", from_what(SHOCK_RES)); + if (Poison_resistance) + you_are("poison resistant", from_what(POISON_RES)); + if (Acid_resistance) + you_are("acid resistant", from_what(ACID_RES)); + if (Drain_resistance) + you_are("level-drain resistant", from_what(DRAIN_RES)); + if (Sick_resistance) + you_are("immune to sickness", from_what(SICK_RES)); + if (Stone_resistance) + you_are("petrification resistant", from_what(STONE_RES)); + if (Halluc_resistance) + enl_msg(You_, "resist", "resisted", " hallucinations", + from_what(HALLUC_RES)); + if (u.uedibility) + you_can("recognize detrimental food", ""); - /*** Vision and senses ***/ - if (!Blind && (Blinded || !haseyes(youmonst.data))) - you_can("see", from_what(-BLINDED)); /* Eyes of the Overworld */ - if (See_invisible) { - if (!Blind) - enl_msg(You_, "see", "saw", " invisible", from_what(SEE_INVIS)); - else - enl_msg(You_, "will see", "would have seen", - " invisible when not blind", from_what(SEE_INVIS)); - } - if (Blind_telepat) you_are("telepathic",from_what(TELEPAT)); - if (Warning) you_are("warned", from_what(WARNING)); - if (Warn_of_mon && context.warntype.obj) { - Sprintf(buf, "aware of the presence of %s", - (context.warntype.obj & M2_ORC) ? "orcs" : - (context.warntype.obj & M2_DEMON) ? "demons" : - something); - you_are(buf,from_what(WARN_OF_MON)); - } - if (Warn_of_mon && context.warntype.polyd) { - Sprintf(buf, "aware of the presence of %s", - ((context.warntype.polyd & (M2_HUMAN|M2_ELF)) - == (M2_HUMAN|M2_ELF)) ? "humans and elves" : - (context.warntype.polyd & M2_HUMAN) ? "humans" : - (context.warntype.polyd & M2_ELF) ? "elves" : - (context.warntype.polyd & M2_ORC) ? "orcs" : - (context.warntype.polyd & M2_DEMON) ? "demons" : - "certain monsters"); - you_are(buf,""); - } - if (Warn_of_mon && context.warntype.speciesidx) { - Sprintf(buf, "aware of the presence of %s", - makeplural(mons[context.warntype.speciesidx].mname)); - you_are(buf,from_what(WARN_OF_MON)); - } - if (Undead_warning) you_are("warned of undead",from_what(WARN_UNDEAD)); - if (Searching) you_have("automatic searching",from_what(SEARCHING)); - if (Clairvoyant) you_are("clairvoyant",from_what(CLAIRVOYANT)); - else if ((HClairvoyant || EClairvoyant) && BClairvoyant) { - Strcpy(buf, from_what(-CLAIRVOYANT)); - if (!strncmp(buf, " because of ", 12)) - /* overwrite substring; strncpy doesn't add terminator */ - (void) strncpy(buf, " if not for ", 12); - enl_msg(You_, "could be", "could have been", - " clairvoyant", buf); - } - if (Infravision) you_have("infravision",from_what(INFRAVISION)); - if (Detect_monsters) - you_are("sensing the presence of monsters", ""); - if (u.umconf) you_are("going to confuse monsters",""); + /*** Vision and senses ***/ + if (!Blind && (Blinded || !haseyes(youmonst.data))) + you_can("see", from_what(-BLINDED)); /* Eyes of the Overworld */ + if (See_invisible) { + if (!Blind) + enl_msg(You_, "see", "saw", " invisible", from_what(SEE_INVIS)); + else + enl_msg(You_, "will see", "would have seen", + " invisible when not blind", from_what(SEE_INVIS)); + } + if (Blind_telepat) + you_are("telepathic", from_what(TELEPAT)); + if (Warning) + you_are("warned", from_what(WARNING)); + if (Warn_of_mon && context.warntype.obj) { + Sprintf(buf, "aware of the presence of %s", + (context.warntype.obj & M2_ORC) + ? "orcs" + : (context.warntype.obj & M2_DEMON) ? "demons" + : something); + you_are(buf, from_what(WARN_OF_MON)); + } + if (Warn_of_mon && context.warntype.polyd) { + Sprintf(buf, "aware of the presence of %s", + ((context.warntype.polyd & (M2_HUMAN | M2_ELF)) + == (M2_HUMAN | M2_ELF)) + ? "humans and elves" + : (context.warntype.polyd & M2_HUMAN) + ? "humans" + : (context.warntype.polyd & M2_ELF) + ? "elves" + : (context.warntype.polyd & M2_ORC) + ? "orcs" + : (context.warntype.polyd & M2_DEMON) + ? "demons" + : "certain monsters"); + you_are(buf, ""); + } + if (Warn_of_mon && context.warntype.speciesidx) { + Sprintf(buf, "aware of the presence of %s", + makeplural(mons[context.warntype.speciesidx].mname)); + you_are(buf, from_what(WARN_OF_MON)); + } + if (Undead_warning) + you_are("warned of undead", from_what(WARN_UNDEAD)); + if (Searching) + you_have("automatic searching", from_what(SEARCHING)); + if (Clairvoyant) + you_are("clairvoyant", from_what(CLAIRVOYANT)); + else if ((HClairvoyant || EClairvoyant) && BClairvoyant) { + Strcpy(buf, from_what(-CLAIRVOYANT)); + if (!strncmp(buf, " because of ", 12)) + /* overwrite substring; strncpy doesn't add terminator */ + (void) strncpy(buf, " if not for ", 12); + enl_msg(You_, "could be", "could have been", " clairvoyant", buf); + } + if (Infravision) + you_have("infravision", from_what(INFRAVISION)); + if (Detect_monsters) + you_are("sensing the presence of monsters", ""); + if (u.umconf) + you_are("going to confuse monsters", ""); - /*** Appearance and behavior ***/ - if (Adornment) { - int adorn = 0; + /*** Appearance and behavior ***/ + if (Adornment) { + int adorn = 0; - if (uleft && uleft->otyp == RIN_ADORNMENT) adorn += uleft->spe; - if (uright && uright->otyp == RIN_ADORNMENT) adorn += uright->spe; - /* the sum might be 0 (+0 ring or two which negate each other); - that yields "you are charismatic" (which isn't pointless - because it potentially impacts seduction attacks) */ - Sprintf(buf, "%scharismatic", - (adorn > 0) ? "more " : (adorn < 0) ? "less " : ""); - you_are(buf, from_what(ADORNED)); - } - if (Invisible) you_are("invisible",from_what(INVIS)); - else if (Invis) you_are("invisible to others",from_what(INVIS)); - /* ordinarily "visible" is redundant; this is a special case for - the situation when invisibility would be an expected attribute */ - else if ((HInvis || EInvis) && BInvis) - you_are("visible", from_what(-INVIS)); - if (Displaced) you_are("displaced",from_what(DISPLACED)); - if (Stealth) you_are("stealthy",from_what(STEALTH)); - if (Aggravate_monster) - enl_msg("You aggravate", "", "d", - " monsters",from_what(AGGRAVATE_MONSTER)); - if (Conflict) enl_msg("You cause", "", "d", " conflict",from_what(CONFLICT)); + if (uleft && uleft->otyp == RIN_ADORNMENT) + adorn += uleft->spe; + if (uright && uright->otyp == RIN_ADORNMENT) + adorn += uright->spe; + /* the sum might be 0 (+0 ring or two which negate each other); + that yields "you are charismatic" (which isn't pointless + because it potentially impacts seduction attacks) */ + Sprintf(buf, "%scharismatic", + (adorn > 0) ? "more " : (adorn < 0) ? "less " : ""); + you_are(buf, from_what(ADORNED)); + } + if (Invisible) + you_are("invisible", from_what(INVIS)); + else if (Invis) + you_are("invisible to others", from_what(INVIS)); + /* ordinarily "visible" is redundant; this is a special case for + the situation when invisibility would be an expected attribute */ + else if ((HInvis || EInvis) && BInvis) + you_are("visible", from_what(-INVIS)); + if (Displaced) + you_are("displaced", from_what(DISPLACED)); + if (Stealth) + you_are("stealthy", from_what(STEALTH)); + if (Aggravate_monster) + enl_msg("You aggravate", "", "d", " monsters", + from_what(AGGRAVATE_MONSTER)); + if (Conflict) + enl_msg("You cause", "", "d", " conflict", from_what(CONFLICT)); - /*** Transportation ***/ - if (Jumping) you_can("jump",from_what(JUMPING)); - if (Teleportation) you_can("teleport",from_what(TELEPORT)); - if (Teleport_control) - you_have("teleport control",from_what(TELEPORT_CONTROL)); - /* actively levitating handled earlier as a status condition */ - if (BLevitation) { /* levitation is blocked */ - long save_BLev = BLevitation; + /*** Transportation ***/ + if (Jumping) + you_can("jump", from_what(JUMPING)); + if (Teleportation) + you_can("teleport", from_what(TELEPORT)); + if (Teleport_control) + you_have("teleport control", from_what(TELEPORT_CONTROL)); + /* actively levitating handled earlier as a status condition */ + if (BLevitation) { /* levitation is blocked */ + long save_BLev = BLevitation; - BLevitation = 0L; - if (Levitation) - enl_msg(You_, "would levitate", "would have levitated", - if_surroundings_permitted, ""); - BLevitation = save_BLev; - } - /* actively flying handled earlier as a status condition */ - if (BFlying) { /* flight is blocked */ - long save_BFly = BFlying; + BLevitation = 0L; + if (Levitation) + enl_msg(You_, "would levitate", "would have levitated", + if_surroundings_permitted, ""); + BLevitation = save_BLev; + } + /* actively flying handled earlier as a status condition */ + if (BFlying) { /* flight is blocked */ + long save_BFly = BFlying; - BFlying = 0L; - if (Flying) - enl_msg(You_, "would fly", "would have flown", - Levitation ? "if you weren't levitating" : - (save_BFly == FROMOUTSIDE) ? - if_surroundings_permitted : - /* both surroundings and [latent] levitation */ - " if circumstances permitted", ""); - BFlying = save_BFly; - } - /* actively walking on water handled earlier as a status condition */ - if (Wwalking && !walking_on_water()) - you_can("walk on water",from_what(WWALKING)); - /* actively swimming (in water but not under it) handled earlier */ - if (Swimming && (Underwater || !u.uinwater)) - you_can("swim",from_what(SWIMMING)); - if (Breathless) - you_can("survive without air",from_what(MAGICAL_BREATHING)); - else if (Amphibious) - you_can("breathe water",from_what(MAGICAL_BREATHING)); - if (Passes_walls) you_can("walk through walls",from_what(PASSES_WALLS)); + BFlying = 0L; + if (Flying) + enl_msg(You_, "would fly", "would have flown", + Levitation + ? "if you weren't levitating" + : (save_BFly == FROMOUTSIDE) + ? if_surroundings_permitted + : + /* both surroundings and [latent] levitation */ + " if circumstances permitted", + ""); + BFlying = save_BFly; + } + /* actively walking on water handled earlier as a status condition */ + if (Wwalking && !walking_on_water()) + you_can("walk on water", from_what(WWALKING)); + /* actively swimming (in water but not under it) handled earlier */ + if (Swimming && (Underwater || !u.uinwater)) + you_can("swim", from_what(SWIMMING)); + if (Breathless) + you_can("survive without air", from_what(MAGICAL_BREATHING)); + else if (Amphibious) + you_can("breathe water", from_what(MAGICAL_BREATHING)); + if (Passes_walls) + you_can("walk through walls", from_what(PASSES_WALLS)); - /*** Physical attributes ***/ - if (Regeneration) - enl_msg("You regenerate", "", "d", "",from_what(REGENERATION)); - if (Slow_digestion) - you_have("slower digestion",from_what(SLOW_DIGESTION)); - if (u.uhitinc) - you_have(enlght_combatinc("to hit", u.uhitinc, final, buf),""); - if (u.udaminc) - you_have(enlght_combatinc("damage", u.udaminc, final, buf),""); - if (u.uspellprot || Protection) { - int prot = 0; + /*** Physical attributes ***/ + if (Regeneration) + enl_msg("You regenerate", "", "d", "", from_what(REGENERATION)); + if (Slow_digestion) + you_have("slower digestion", from_what(SLOW_DIGESTION)); + if (u.uhitinc) + you_have(enlght_combatinc("to hit", u.uhitinc, final, buf), ""); + if (u.udaminc) + you_have(enlght_combatinc("damage", u.udaminc, final, buf), ""); + if (u.uspellprot || Protection) { + int prot = 0; - if(uleft && uleft->otyp == RIN_PROTECTION) prot += uleft->spe; - if(uright && uright->otyp == RIN_PROTECTION) prot += uright->spe; - if (HProtection & INTRINSIC) prot += u.ublessed; - prot += u.uspellprot; - if (prot) - you_have(enlght_combatinc("defense", prot, final, buf), ""); - } - if ((armpro = magic_negation(&youmonst)) > 0) { - /* magic cancellation factor, conferred by worn armor */ - static const char * const mc_types[] = { - "" /*ordinary*/, "warded", "guarded", "protected", - }; - /* sanity check */ - if (armpro >= SIZE(mc_types)) armpro = SIZE(mc_types) - 1; - you_are(mc_types[armpro],""); - } - if (Half_physical_damage) enlght_halfdmg(HALF_PHDAM, final); - if (Half_spell_damage) enlght_halfdmg(HALF_SPDAM, final); - /* polymorph and other shape change */ - if (Protection_from_shape_changers) - you_are("protected from shape changers", - from_what(PROT_FROM_SHAPE_CHANGERS)); - if (Unchanging) { - const char *what = 0; + if (uleft && uleft->otyp == RIN_PROTECTION) + prot += uleft->spe; + if (uright && uright->otyp == RIN_PROTECTION) + prot += uright->spe; + if (HProtection & INTRINSIC) + prot += u.ublessed; + prot += u.uspellprot; + if (prot) + you_have(enlght_combatinc("defense", prot, final, buf), ""); + } + if ((armpro = magic_negation(&youmonst)) > 0) { + /* magic cancellation factor, conferred by worn armor */ + static const char *const mc_types[] = { + "" /*ordinary*/, "warded", "guarded", "protected", + }; + /* sanity check */ + if (armpro >= SIZE(mc_types)) + armpro = SIZE(mc_types) - 1; + you_are(mc_types[armpro], ""); + } + if (Half_physical_damage) + enlght_halfdmg(HALF_PHDAM, final); + if (Half_spell_damage) + enlght_halfdmg(HALF_SPDAM, final); + /* polymorph and other shape change */ + if (Protection_from_shape_changers) + you_are("protected from shape changers", + from_what(PROT_FROM_SHAPE_CHANGERS)); + if (Unchanging) { + const char *what = 0; - if (!Upolyd) /* Upolyd handled below after current form */ - you_can("not change from your current form", - from_what(UNCHANGING)); - /* blocked shape changes */ - if (Polymorph) - what = !final ? "polymorph" : "have polymorphed"; - else if (u.ulycn >= LOW_PM) - what = !final ? "change shape" : "have changed shape"; - if (what) { - Sprintf(buf, "would %s periodically", what); - /* omit from_what(UNCHANGING); too verbose */ - enl_msg(You_, buf, buf, - " if not locked into your current form", ""); - } - } else if (Polymorph) { - you_are("polymorphing periodically", from_what(POLYMORPH)); - } - if (Polymorph_control) - you_have("polymorph control",from_what(POLYMORPH_CONTROL)); - if (Upolyd && u.umonnum != u.ulycn) { - /* foreign shape (except were-form which is handled below) */ - Sprintf(buf, "polymorphed into %s", an(youmonst.data->mname)); - if (wizard) Sprintf(eos(buf), " (%d)", u.mtimedone); - you_are(buf,""); - } - if (lays_eggs(youmonst.data) && flags.female) /* Upolyd */ - you_can("lay eggs", ""); - if (u.ulycn >= LOW_PM) { - /* "you are a werecreature [in beast form]" */ - Strcpy(buf, an(mons[u.ulycn].mname)); - if (u.umonnum == u.ulycn) { - Strcat(buf, " in beast form"); - if (wizard) Sprintf(eos(buf), " (%d)", u.mtimedone); - } - you_are(buf,""); - } - if (Unchanging && Upolyd) /* !Upolyd handled above */ - you_can("not change from your current form", - from_what(UNCHANGING)); - if (Hate_silver) you_are("harmed by silver",""); - /* movement and non-armor-based protection */ - if (Fast) you_are(Very_fast ? "very fast" : "fast",from_what(FAST)); - if (Reflecting) you_have("reflection",from_what(REFLECTING)); - if (Free_action) you_have("free action",from_what(FREE_ACTION)); - if (Fixed_abil) you_have("fixed abilities",from_what(FIXED_ABIL)); - if (Lifesaved) - enl_msg("Your life ", "will be", "would have been", " saved",""); + if (!Upolyd) /* Upolyd handled below after current form */ + you_can("not change from your current form", + from_what(UNCHANGING)); + /* blocked shape changes */ + if (Polymorph) + what = !final ? "polymorph" : "have polymorphed"; + else if (u.ulycn >= LOW_PM) + what = !final ? "change shape" : "have changed shape"; + if (what) { + Sprintf(buf, "would %s periodically", what); + /* omit from_what(UNCHANGING); too verbose */ + enl_msg(You_, buf, buf, " if not locked into your current form", + ""); + } + } else if (Polymorph) { + you_are("polymorphing periodically", from_what(POLYMORPH)); + } + if (Polymorph_control) + you_have("polymorph control", from_what(POLYMORPH_CONTROL)); + if (Upolyd && u.umonnum != u.ulycn) { + /* foreign shape (except were-form which is handled below) */ + Sprintf(buf, "polymorphed into %s", an(youmonst.data->mname)); + if (wizard) + Sprintf(eos(buf), " (%d)", u.mtimedone); + you_are(buf, ""); + } + if (lays_eggs(youmonst.data) && flags.female) /* Upolyd */ + you_can("lay eggs", ""); + if (u.ulycn >= LOW_PM) { + /* "you are a werecreature [in beast form]" */ + Strcpy(buf, an(mons[u.ulycn].mname)); + if (u.umonnum == u.ulycn) { + Strcat(buf, " in beast form"); + if (wizard) + Sprintf(eos(buf), " (%d)", u.mtimedone); + } + you_are(buf, ""); + } + if (Unchanging && Upolyd) /* !Upolyd handled above */ + you_can("not change from your current form", from_what(UNCHANGING)); + if (Hate_silver) + you_are("harmed by silver", ""); + /* movement and non-armor-based protection */ + if (Fast) + you_are(Very_fast ? "very fast" : "fast", from_what(FAST)); + if (Reflecting) + you_have("reflection", from_what(REFLECTING)); + if (Free_action) + you_have("free action", from_what(FREE_ACTION)); + if (Fixed_abil) + you_have("fixed abilities", from_what(FIXED_ABIL)); + if (Lifesaved) + enl_msg("Your life ", "will be", "would have been", " saved", ""); - /*** Miscellany ***/ - if (Luck) { - ltmp = abs((int)Luck); - Sprintf(buf, "%s%slucky", - ltmp >= 10 ? "extremely " : ltmp >= 5 ? "very " : "", - Luck < 0 ? "un" : ""); - if (wizard) Sprintf(eos(buf), " (%d)", Luck); - you_are(buf,""); - } else if (wizard) enl_msg("Your luck ", "is", "was", " zero",""); - if (u.moreluck > 0) you_have("extra luck",""); - else if (u.moreluck < 0) you_have("reduced luck",""); - if (carrying(LUCKSTONE) || stone_luck(TRUE)) { - ltmp = stone_luck(0); - if (ltmp <= 0) - enl_msg("Bad luck ", "does", "did", " not time out for you",""); - if (ltmp >= 0) - enl_msg("Good luck ", "does", "did", " not time out for you",""); - } + /*** Miscellany ***/ + if (Luck) { + ltmp = abs((int) Luck); + Sprintf(buf, "%s%slucky", + ltmp >= 10 ? "extremely " : ltmp >= 5 ? "very " : "", + Luck < 0 ? "un" : ""); + if (wizard) + Sprintf(eos(buf), " (%d)", Luck); + you_are(buf, ""); + } else if (wizard) + enl_msg("Your luck ", "is", "was", " zero", ""); + if (u.moreluck > 0) + you_have("extra luck", ""); + else if (u.moreluck < 0) + you_have("reduced luck", ""); + if (carrying(LUCKSTONE) || stone_luck(TRUE)) { + ltmp = stone_luck(0); + if (ltmp <= 0) + enl_msg("Bad luck ", "does", "did", " not time out for you", ""); + if (ltmp >= 0) + enl_msg("Good luck ", "does", "did", " not time out for you", ""); + } - if (u.ugangr) { - Sprintf(buf, " %sangry with you", - u.ugangr > 6 ? "extremely " : u.ugangr > 3 ? "very " : ""); - if (wizard) Sprintf(eos(buf), " (%d)", u.ugangr); - enl_msg(u_gname(), " is", " was", buf,""); - } else - /* - * We need to suppress this when the game is over, because death - * can change the value calculated by can_pray(), potentially - * resulting in a false claim that you could have prayed safely. - */ - if (!final) { + if (u.ugangr) { + Sprintf(buf, " %sangry with you", + u.ugangr > 6 ? "extremely " : u.ugangr > 3 ? "very " : ""); + if (wizard) + Sprintf(eos(buf), " (%d)", u.ugangr); + enl_msg(u_gname(), " is", " was", buf, ""); + } else + /* + * We need to suppress this when the game is over, because death + * can change the value calculated by can_pray(), potentially + * resulting in a false claim that you could have prayed safely. + */ + if (!final) { #if 0 /* "can [not] safely pray" vs "could [not] have safely prayed" */ Sprintf(buf, "%s%ssafely pray%s", can_pray(FALSE) ? "" : "not ", final ? "have " : "", final ? "ed" : ""); #else - Sprintf(buf, "%ssafely pray", can_pray(FALSE) ? "" : "not "); + Sprintf(buf, "%ssafely pray", can_pray(FALSE) ? "" : "not "); #endif - if (wizard) Sprintf(eos(buf), " (%d)", u.ublesscnt); - you_can(buf,""); - } - if (wizard) { - int fcount = 0; - struct fruit *f; - char buf2[BUFSZ]; - for(f=ffruit; f; f = f->nextf) - { - Sprintf(buf, "Fruit %d ", ++fcount); - Sprintf(buf2, "%s (id %d)", f->fname, f->fid); - enl_msg(buf, "is ", "was ", buf2, ""); - } - enl_msg("The current fruit ", "is ", "was ", pl_fruit, ""); - Sprintf(buf, "%d", flags.made_fruit); - enl_msg("The made fruit flag ", "is ", "was ", buf, ""); - } + if (wizard) + Sprintf(eos(buf), " (%d)", u.ublesscnt); + you_can(buf, ""); + } + if (wizard) { + int fcount = 0; + struct fruit *f; + char buf2[BUFSZ]; + for (f = ffruit; f; f = f->nextf) { + Sprintf(buf, "Fruit %d ", ++fcount); + Sprintf(buf2, "%s (id %d)", f->fname, f->fid); + enl_msg(buf, "is ", "was ", buf2, ""); + } + enl_msg("The current fruit ", "is ", "was ", pl_fruit, ""); + Sprintf(buf, "%d", flags.made_fruit); + enl_msg("The made fruit flag ", "is ", "was ", buf, ""); + } { - const char *p; + const char *p; - buf[0] = '\0'; - if (final < 2) { /* still in progress, or quit/escaped/ascended */ - p = "survived after being killed "; - switch (u.umortality) { - case 0: p = !final ? (char *)0 : "survived"; break; - case 1: Strcpy(buf, "once"); break; - case 2: Strcpy(buf, "twice"); break; - case 3: Strcpy(buf, "thrice"); break; - default: Sprintf(buf, "%d times", u.umortality); - break; - } - } else { /* game ended in character's death */ - p = "are dead"; - switch (u.umortality) { - case 0: impossible("dead without dying?"); - case 1: break; /* just "are dead" */ - default: Sprintf(buf, " (%d%s time!)", u.umortality, - ordin(u.umortality)); - break; - } - } - if (p) enl_msg(You_, "have been killed ", p, buf, ""); + buf[0] = '\0'; + if (final < 2) { /* still in progress, or quit/escaped/ascended */ + p = "survived after being killed "; + switch (u.umortality) { + case 0: + p = !final ? (char *) 0 : "survived"; + break; + case 1: + Strcpy(buf, "once"); + break; + case 2: + Strcpy(buf, "twice"); + break; + case 3: + Strcpy(buf, "thrice"); + break; + default: + Sprintf(buf, "%d times", u.umortality); + break; + } + } else { /* game ended in character's death */ + p = "are dead"; + switch (u.umortality) { + case 0: + impossible("dead without dying?"); + case 1: + break; /* just "are dead" */ + default: + Sprintf(buf, " (%d%s time!)", u.umortality, + ordin(u.umortality)); + break; + } + } + if (p) + enl_msg(You_, "have been killed ", p, buf, ""); } } -#if 0 /* no longer used */ +#if 0 /* no longer used */ STATIC_DCL boolean NDECL(minimal_enlightenment); /* @@ -2180,77 +2383,78 @@ minimal_enlightenment() destroy_nhwindow(tmpwin); return (n != -1); } -#endif /*0*/ +#endif /*0*/ /* ^X command */ STATIC_PTR int doattributes(VOID_ARGS) { - int mode = BASICENLIGHTENMENT; + int mode = BASICENLIGHTENMENT; - /* show more--as if final disclosure--for wizard and explore modes */ - if (wizard || discover) mode |= MAGICENLIGHTENMENT; + /* show more--as if final disclosure--for wizard and explore modes */ + if (wizard || discover) + mode |= MAGICENLIGHTENMENT; - enlightenment(mode, ENL_GAMEINPROGRESS); - return 0; + enlightenment(mode, ENL_GAMEINPROGRESS); + return 0; } void youhiding(via_enlghtmt, msgflag) -boolean via_enlghtmt; /* englightment line vs topl message */ -int msgflag; /* for variant message phrasing */ +boolean via_enlghtmt; /* englightment line vs topl message */ +int msgflag; /* for variant message phrasing */ { char *bp, buf[BUFSZ]; Strcpy(buf, "hiding"); if (youmonst.m_ap_type != M_AP_NOTHING) { - /* mimic; hero is only able to mimic a strange object or gold - or hallucinatory alternative to gold, so we skip the details - for the hypothetical furniture and monster cases */ - bp = eos(strcpy(buf, "mimicking")); - if (youmonst.m_ap_type == M_AP_OBJECT) { - Sprintf(bp, " %s", an(simple_typename(youmonst.mappearance))); - } else if (youmonst.m_ap_type == M_AP_FURNITURE) { - Strcpy(bp, " something"); - } else if (youmonst.m_ap_type == M_AP_MONSTER) { - Strcpy(bp, " someone"); - } else { - ; /* something unexpected; leave 'buf' as-is */ - } + /* mimic; hero is only able to mimic a strange object or gold + or hallucinatory alternative to gold, so we skip the details + for the hypothetical furniture and monster cases */ + bp = eos(strcpy(buf, "mimicking")); + if (youmonst.m_ap_type == M_AP_OBJECT) { + Sprintf(bp, " %s", an(simple_typename(youmonst.mappearance))); + } else if (youmonst.m_ap_type == M_AP_FURNITURE) { + Strcpy(bp, " something"); + } else if (youmonst.m_ap_type == M_AP_MONSTER) { + Strcpy(bp, " someone"); + } else { + ; /* something unexpected; leave 'buf' as-is */ + } } else if (u.uundetected) { - bp = eos(buf); /* points past "hiding" */ - if (youmonst.data->mlet == S_EEL) { - if (is_pool(u.ux, u.uy)) - Sprintf(bp, " in the %s", waterbody_name(u.ux, u.uy)); - } else if (hides_under(youmonst.data)) { - struct obj *o = level.objects[u.ux][u.uy]; + bp = eos(buf); /* points past "hiding" */ + if (youmonst.data->mlet == S_EEL) { + if (is_pool(u.ux, u.uy)) + Sprintf(bp, " in the %s", waterbody_name(u.ux, u.uy)); + } else if (hides_under(youmonst.data)) { + struct obj *o = level.objects[u.ux][u.uy]; - if (o) - Sprintf(bp, " underneath %s", ansimpleoname(o)); - } else if (is_clinger(youmonst.data) || Flying) { - /* Flying: 'lurker above' hides on ceiling but doesn't cling */ - Sprintf(bp, " on the %s", ceiling(u.ux, u.uy)); - } else { - /* on floor; is_hider() but otherwise not special: 'trapper' */ - if (u.utrap && u.utraptype == TT_PIT) { - struct trap *t = t_at(u.ux, u.uy); + if (o) + Sprintf(bp, " underneath %s", ansimpleoname(o)); + } else if (is_clinger(youmonst.data) || Flying) { + /* Flying: 'lurker above' hides on ceiling but doesn't cling */ + Sprintf(bp, " on the %s", ceiling(u.ux, u.uy)); + } else { + /* on floor; is_hider() but otherwise not special: 'trapper' */ + if (u.utrap && u.utraptype == TT_PIT) { + struct trap *t = t_at(u.ux, u.uy); - Sprintf(bp, " in a %spit", - (t && t->ttyp == SPIKED_PIT) ? "spiked " : ""); - } else - Sprintf(bp, " on the %s", surface(u.ux, u.uy)); - } + Sprintf(bp, " in a %spit", + (t && t->ttyp == SPIKED_PIT) ? "spiked " : ""); + } else + Sprintf(bp, " on the %s", surface(u.ux, u.uy)); + } } else { - ; /* shouldn't happen; will result in generic "you are hiding" */ + ; /* shouldn't happen; will result in generic "you are hiding" */ } if (via_enlghtmt) { - int final = msgflag; /* 'final' is used by you_are() macro */ + int final = msgflag; /* 'final' is used by you_are() macro */ - you_are(buf, ""); + you_are(buf, ""); } else { - /* for dohide(), when player uses '#monster' command */ - You("are %s %s.", msgflag ? "already" : "now", buf); + /* for dohide(), when player uses '#monster' command */ + You("are %s %s.", msgflag ? "already" : "now", buf); } } @@ -2260,313 +2464,319 @@ int msgflag; /* for variant message phrasing */ STATIC_PTR int doconduct(VOID_ARGS) { - show_conduct(0); - return 0; + show_conduct(0); + return 0; } void show_conduct(final) int final; { - char buf[BUFSZ]; - int ngenocided; + char buf[BUFSZ]; + int ngenocided; - /* Create the conduct window */ - en_win = create_nhwindow(NHW_MENU); - putstr(en_win, 0, "Voluntary challenges:"); + /* Create the conduct window */ + en_win = create_nhwindow(NHW_MENU); + putstr(en_win, 0, "Voluntary challenges:"); - if (u.uroleplay.blind) you_have_been("blind from birth"); - if (u.uroleplay.nudist) you_have_been("faithfully nudist"); + if (u.uroleplay.blind) + you_have_been("blind from birth"); + if (u.uroleplay.nudist) + you_have_been("faithfully nudist"); - if (!u.uconduct.food) - enl_msg(You_, "have gone", "went", " without food", ""); - /* But beverages are okay */ - else if (!u.uconduct.unvegan) - you_have_X("followed a strict vegan diet"); - else if (!u.uconduct.unvegetarian) - you_have_been("vegetarian"); + if (!u.uconduct.food) + enl_msg(You_, "have gone", "went", " without food", ""); + /* But beverages are okay */ + else if (!u.uconduct.unvegan) + you_have_X("followed a strict vegan diet"); + else if (!u.uconduct.unvegetarian) + you_have_been("vegetarian"); - if (!u.uconduct.gnostic) - you_have_been("an atheist"); + if (!u.uconduct.gnostic) + you_have_been("an atheist"); - if (!u.uconduct.weaphit) - you_have_never("hit with a wielded weapon"); - else if (wizard) { - Sprintf(buf, "used a wielded weapon %ld time%s", - u.uconduct.weaphit, plur(u.uconduct.weaphit)); - you_have_X(buf); - } - if (!u.uconduct.killer) - you_have_been("a pacifist"); + if (!u.uconduct.weaphit) + you_have_never("hit with a wielded weapon"); + else if (wizard) { + Sprintf(buf, "used a wielded weapon %ld time%s", u.uconduct.weaphit, + plur(u.uconduct.weaphit)); + you_have_X(buf); + } + if (!u.uconduct.killer) + you_have_been("a pacifist"); - if (!u.uconduct.literate) - you_have_been("illiterate"); - else if (wizard) { - Sprintf(buf, "read items or engraved %ld time%s", - u.uconduct.literate, plur(u.uconduct.literate)); - you_have_X(buf); - } + if (!u.uconduct.literate) + you_have_been("illiterate"); + else if (wizard) { + Sprintf(buf, "read items or engraved %ld time%s", u.uconduct.literate, + plur(u.uconduct.literate)); + you_have_X(buf); + } - ngenocided = num_genocides(); - if (ngenocided == 0) { - you_have_never("genocided any monsters"); - } else { - Sprintf(buf, "genocided %d type%s of monster%s", - ngenocided, plur(ngenocided), plur(ngenocided)); - you_have_X(buf); - } + ngenocided = num_genocides(); + if (ngenocided == 0) { + you_have_never("genocided any monsters"); + } else { + Sprintf(buf, "genocided %d type%s of monster%s", ngenocided, + plur(ngenocided), plur(ngenocided)); + you_have_X(buf); + } - if (!u.uconduct.polypiles) - you_have_never("polymorphed an object"); - else if (wizard) { - Sprintf(buf, "polymorphed %ld item%s", - u.uconduct.polypiles, plur(u.uconduct.polypiles)); - you_have_X(buf); - } + if (!u.uconduct.polypiles) + you_have_never("polymorphed an object"); + else if (wizard) { + Sprintf(buf, "polymorphed %ld item%s", u.uconduct.polypiles, + plur(u.uconduct.polypiles)); + you_have_X(buf); + } - if (!u.uconduct.polyselfs) - you_have_never("changed form"); - else if (wizard) { - Sprintf(buf, "changed form %ld time%s", - u.uconduct.polyselfs, plur(u.uconduct.polyselfs)); - you_have_X(buf); - } + if (!u.uconduct.polyselfs) + you_have_never("changed form"); + else if (wizard) { + Sprintf(buf, "changed form %ld time%s", u.uconduct.polyselfs, + plur(u.uconduct.polyselfs)); + you_have_X(buf); + } - if (!u.uconduct.wishes) - you_have_X("used no wishes"); - else { - Sprintf(buf, "used %ld wish%s", - u.uconduct.wishes, (u.uconduct.wishes > 1L) ? "es" : ""); - you_have_X(buf); + if (!u.uconduct.wishes) + you_have_X("used no wishes"); + else { + Sprintf(buf, "used %ld wish%s", u.uconduct.wishes, + (u.uconduct.wishes > 1L) ? "es" : ""); + you_have_X(buf); - if (!u.uconduct.wisharti) - enl_msg(You_, "have not wished", "did not wish", - " for any artifacts", ""); - } + if (!u.uconduct.wisharti) + enl_msg(You_, "have not wished", "did not wish", + " for any artifacts", ""); + } - /* Pop up the window and wait for a key */ - display_nhwindow(en_win, TRUE); - destroy_nhwindow(en_win); - en_win = WIN_ERR; + /* Pop up the window and wait for a key */ + display_nhwindow(en_win, TRUE); + destroy_nhwindow(en_win); + en_win = WIN_ERR; } #ifndef M -# ifndef NHSTDC -# define M(c) (0x80 | (c)) -# else -# define M(c) ((c) - 128) -# endif /* NHSTDC */ +#ifndef NHSTDC +#define M(c) (0x80 | (c)) +#else +#define M(c) ((c) -128) +#endif /* NHSTDC */ #endif #ifndef C -#define C(c) (0x1f & (c)) +#define C(c) (0x1f & (c)) #endif static const struct func_tab cmdlist[] = { - {C('d'), FALSE, dokick}, /* "D" is for door!...? Msg is in dokick.c */ - {C('e'), TRUE, wiz_detect}, - {C('f'), TRUE, wiz_map}, - {C('g'), TRUE, wiz_genesis}, - {C('i'), TRUE, wiz_identify}, - {C('l'), TRUE, doredraw}, /* if number_pad is set */ - {C('n'), TRUE, donamelevel}, /* if number_pad is set */ - {C('o'), TRUE, dooverview_or_wiz_where}, /* depending on wizard status */ - {C('p'), TRUE, doprev_message}, - {C('r'), TRUE, doredraw}, - {C('t'), TRUE, dotele}, - {C('v'), TRUE, wiz_level_tele}, - {C('w'), TRUE, wiz_wish}, - {C('x'), TRUE, doattributes}, - {C('z'), TRUE, dosuspend_core}, - {'a', FALSE, doapply}, - {'A', FALSE, doddoremarm}, - {M('a'), TRUE, doorganize}, - {M('A'), TRUE, donamelevel}, /* #annotate */ -/* 'b', 'B' : go sw */ - {'c', FALSE, doclose}, - {'C', TRUE, docallcmd}, - {M('c'), TRUE, dotalk}, - {M('C'), TRUE, doconduct}, /* #conduct */ - {'d', FALSE, dodrop}, - {'D', FALSE, doddrop}, - {M('d'), FALSE, dodip}, - {'e', FALSE, doeat}, - {'E', FALSE, doengrave}, - {M('e'), TRUE, enhance_weapon_skill}, - {'f', FALSE, dofire}, -/* 'F' : fight (one time) */ - {M('f'), FALSE, doforce}, -/* 'g', 'G' : multiple go */ -/* 'h', 'H' : go west */ - {'h', TRUE, dohelp}, /* if number_pad is set */ - {'i', TRUE, ddoinv}, - {'I', TRUE, dotypeinv}, /* Robert Viduya */ - {M('i'), TRUE, doinvoke}, -/* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */ - {'j', FALSE, dojump}, /* if number_pad is on */ - {M('j'), FALSE, dojump}, - {'k', FALSE, dokick}, /* if number_pad is on */ - {'l', FALSE, doloot}, /* if number_pad is on */ - {M('l'), FALSE, doloot}, -/* 'n' prefixes a count if number_pad is on */ - {M('m'), TRUE, domonability}, - {'N', TRUE, docallcmd}, /* if number_pad is on */ - {M('n'), TRUE, docallcmd}, - {M('N'), TRUE, docallcmd}, - {'o', FALSE, doopen}, - {'O', TRUE, doset}, - {M('o'), FALSE, dosacrifice}, - {M('O'), TRUE, dooverview}, /* #overview */ - {'p', FALSE, dopay}, - {'P', FALSE, doputon}, - {M('p'), TRUE, dopray}, - {'q', FALSE, dodrink}, - {'Q', FALSE, dowieldquiver}, - {M('q'), TRUE, done2}, - {'r', FALSE, doread}, - {'R', FALSE, doremring}, - {M('r'), FALSE, dorub}, - {M('R'), FALSE, doride}, /* #ride */ - {'s', TRUE, dosearch, "searching"}, - {'S', TRUE, dosave}, - {M('s'), FALSE, dosit}, - {'t', FALSE, dothrow}, - {'T', FALSE, dotakeoff}, - {M('t'), TRUE, doturn}, - {M('T'), FALSE, dotip}, /* #tip */ -/* 'u', 'U' : go ne */ - {'u', FALSE, dountrap}, /* if number_pad is on */ - {M('u'), FALSE, dountrap}, - {'v', TRUE, doversion}, - {'V', TRUE, dohistory}, - {M('v'), TRUE, doextversion}, - {'w', FALSE, dowield}, - {'W', FALSE, dowear}, - {M('w'), FALSE, dowipe}, - {'x', FALSE, doswapweapon}, - {'X', FALSE, dotwoweapon}, -/* 'y', 'Y' : go nw */ - {'z', FALSE, dozap}, - {'Z', TRUE, docast}, - {'<', FALSE, doup}, - {'>', FALSE, dodown}, - {'/', TRUE, dowhatis}, - {'&', TRUE, dowhatdoes}, - {'?', TRUE, dohelp}, - {M('?'), TRUE, doextlist}, + { C('d'), FALSE, dokick }, /* "D" is for door!...? Msg is in dokick.c */ + { C('e'), TRUE, wiz_detect }, + { C('f'), TRUE, wiz_map }, + { C('g'), TRUE, wiz_genesis }, + { C('i'), TRUE, wiz_identify }, + { C('l'), TRUE, doredraw }, /* if number_pad is set */ + { C('n'), TRUE, donamelevel }, /* if number_pad is set */ + { C('o'), TRUE, + dooverview_or_wiz_where }, /* depending on wizard status */ + { C('p'), TRUE, doprev_message }, + { C('r'), TRUE, doredraw }, + { C('t'), TRUE, dotele }, + { C('v'), TRUE, wiz_level_tele }, + { C('w'), TRUE, wiz_wish }, + { C('x'), TRUE, doattributes }, + { C('z'), TRUE, dosuspend_core }, + { 'a', FALSE, doapply }, + { 'A', FALSE, doddoremarm }, + { M('a'), TRUE, doorganize }, + { M('A'), TRUE, donamelevel }, /* #annotate */ + /* 'b', 'B' : go sw */ + { 'c', FALSE, doclose }, + { 'C', TRUE, docallcmd }, + { M('c'), TRUE, dotalk }, + { M('C'), TRUE, doconduct }, /* #conduct */ + { 'd', FALSE, dodrop }, + { 'D', FALSE, doddrop }, + { M('d'), FALSE, dodip }, + { 'e', FALSE, doeat }, + { 'E', FALSE, doengrave }, + { M('e'), TRUE, enhance_weapon_skill }, + { 'f', FALSE, dofire }, + /* 'F' : fight (one time) */ + { M('f'), FALSE, doforce }, + /* 'g', 'G' : multiple go */ + /* 'h', 'H' : go west */ + { 'h', TRUE, dohelp }, /* if number_pad is set */ + { 'i', TRUE, ddoinv }, + { 'I', TRUE, dotypeinv }, /* Robert Viduya */ + { M('i'), TRUE, doinvoke }, + /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */ + { 'j', FALSE, dojump }, /* if number_pad is on */ + { M('j'), FALSE, dojump }, + { 'k', FALSE, dokick }, /* if number_pad is on */ + { 'l', FALSE, doloot }, /* if number_pad is on */ + { M('l'), FALSE, doloot }, + /* 'n' prefixes a count if number_pad is on */ + { M('m'), TRUE, domonability }, + { 'N', TRUE, docallcmd }, /* if number_pad is on */ + { M('n'), TRUE, docallcmd }, + { M('N'), TRUE, docallcmd }, + { 'o', FALSE, doopen }, + { 'O', TRUE, doset }, + { M('o'), FALSE, dosacrifice }, + { M('O'), TRUE, dooverview }, /* #overview */ + { 'p', FALSE, dopay }, + { 'P', FALSE, doputon }, + { M('p'), TRUE, dopray }, + { 'q', FALSE, dodrink }, + { 'Q', FALSE, dowieldquiver }, + { M('q'), TRUE, done2 }, + { 'r', FALSE, doread }, + { 'R', FALSE, doremring }, + { M('r'), FALSE, dorub }, + { M('R'), FALSE, doride }, /* #ride */ + { 's', TRUE, dosearch, "searching" }, + { 'S', TRUE, dosave }, + { M('s'), FALSE, dosit }, + { 't', FALSE, dothrow }, + { 'T', FALSE, dotakeoff }, + { M('t'), TRUE, doturn }, + { M('T'), FALSE, dotip }, /* #tip */ + /* 'u', 'U' : go ne */ + { 'u', FALSE, dountrap }, /* if number_pad is on */ + { M('u'), FALSE, dountrap }, + { 'v', TRUE, doversion }, + { 'V', TRUE, dohistory }, + { M('v'), TRUE, doextversion }, + { 'w', FALSE, dowield }, + { 'W', FALSE, dowear }, + { M('w'), FALSE, dowipe }, + { 'x', FALSE, doswapweapon }, + { 'X', FALSE, dotwoweapon }, + /* 'y', 'Y' : go nw */ + { 'z', FALSE, dozap }, + { 'Z', TRUE, docast }, + { '<', FALSE, doup }, + { '>', FALSE, dodown }, + { '/', TRUE, dowhatis }, + { '&', TRUE, dowhatdoes }, + { '?', TRUE, dohelp }, + { M('?'), TRUE, doextlist }, #ifdef SHELL - {'!', TRUE, dosh}, + { '!', TRUE, dosh }, #endif - {'.', TRUE, donull, "waiting"}, - {' ', TRUE, donull, "waiting"}, - {',', FALSE, dopickup}, - {':', TRUE, dolook}, - {';', TRUE, doquickwhatis}, - {'^', TRUE, doidtrap}, - {'\\', TRUE, dodiscovered}, /* Robert Viduya */ - {'`', TRUE, doclassdisco}, - {'@', TRUE, dotogglepickup}, - {M('2'), FALSE, dotwoweapon}, - {WEAPON_SYM, TRUE, doprwep}, - {ARMOR_SYM, TRUE, doprarm}, - {RING_SYM, TRUE, doprring}, - {AMULET_SYM, TRUE, dopramulet}, - {TOOL_SYM, TRUE, doprtool}, - {'*', TRUE, doprinuse}, /* inventory of all equipment in use */ - {GOLD_SYM, TRUE, doprgold}, - {SPBOOK_SYM, TRUE, dovspell}, /* Mike Stephenson */ - {'#', TRUE, doextcmd}, - {'_', TRUE, dotravel}, - {0,0,0,0} + { '.', TRUE, donull, "waiting" }, + { ' ', TRUE, donull, "waiting" }, + { ',', FALSE, dopickup }, + { ':', TRUE, dolook }, + { ';', TRUE, doquickwhatis }, + { '^', TRUE, doidtrap }, + { '\\', TRUE, dodiscovered }, /* Robert Viduya */ + { '`', TRUE, doclassdisco }, + { '@', TRUE, dotogglepickup }, + { M('2'), FALSE, dotwoweapon }, + { WEAPON_SYM, TRUE, doprwep }, + { ARMOR_SYM, TRUE, doprarm }, + { RING_SYM, TRUE, doprring }, + { AMULET_SYM, TRUE, dopramulet }, + { TOOL_SYM, TRUE, doprtool }, + { '*', TRUE, doprinuse }, /* inventory of all equipment in use */ + { GOLD_SYM, TRUE, doprgold }, + { SPBOOK_SYM, TRUE, dovspell }, /* Mike Stephenson */ + { '#', TRUE, doextcmd }, + { '_', TRUE, dotravel }, + { 0, 0, 0, 0 } }; struct ext_func_tab extcmdlist[] = { - {"adjust", "adjust inventory letters", doorganize, TRUE}, - {"annotate", "name current level", donamelevel, TRUE}, - {"chat", "talk to someone", dotalk, TRUE}, /* converse? */ - {"conduct", "list voluntary challenges you have maintained", - doconduct, TRUE}, - {"dip", "dip an object into something", dodip, FALSE}, - {"enhance", "advance or check weapon and spell skills", - enhance_weapon_skill, TRUE}, - {"exploremode", "enter explore mode", enter_explore_mode, TRUE}, - {"force", "force a lock", doforce, FALSE}, - {"invoke", "invoke an object's powers", doinvoke, TRUE}, - {"jump", "jump to a location", dojump, FALSE}, - {"loot", "loot a box on the floor", doloot, FALSE}, - {"monster", "use a monster's special ability", domonability, TRUE}, - {"name", "name a monster or an object", docallcmd, TRUE}, - {"offer", "offer a sacrifice to the gods", dosacrifice, FALSE}, - {"overview", "show an overview of the dungeon", dooverview, TRUE}, - {"pray", "pray to the gods for help", dopray, TRUE}, - {"quit", "exit without saving current game", done2, TRUE}, - {"ride", "ride (or stop riding) a monster", doride, FALSE}, - {"rub", "rub a lamp or a stone", dorub, FALSE}, - {"sit", "sit down", dosit, FALSE}, - {"terrain", "show map without obstructions", doterrain, TRUE}, - {"tip", "empty a container", dotip, FALSE}, - {"turn", "turn undead", doturn, TRUE}, - {"twoweapon", "toggle two-weapon combat", dotwoweapon, FALSE}, - {"untrap", "untrap something", dountrap, FALSE}, - {"version", "list compile time options for this version of NetHack", - doextversion, TRUE}, - {"wipe", "wipe off your face", dowipe, FALSE}, - {"?", "get this list of extended commands", doextlist, TRUE}, - /* - * There must be a blank entry here for every entry in the table - * below. - */ - {(char *)0, (char *)0, donull, TRUE}, /* levelchange */ - {(char *)0, (char *)0, donull, TRUE}, /* lightsources */ + { "adjust", "adjust inventory letters", doorganize, TRUE }, + { "annotate", "name current level", donamelevel, TRUE }, + { "chat", "talk to someone", dotalk, TRUE }, /* converse? */ + { "conduct", "list voluntary challenges you have maintained", doconduct, + TRUE }, + { "dip", "dip an object into something", dodip, FALSE }, + { "enhance", "advance or check weapon and spell skills", + enhance_weapon_skill, TRUE }, + { "exploremode", "enter explore mode", enter_explore_mode, TRUE }, + { "force", "force a lock", doforce, FALSE }, + { "invoke", "invoke an object's powers", doinvoke, TRUE }, + { "jump", "jump to a location", dojump, FALSE }, + { "loot", "loot a box on the floor", doloot, FALSE }, + { "monster", "use a monster's special ability", domonability, TRUE }, + { "name", "name a monster or an object", docallcmd, TRUE }, + { "offer", "offer a sacrifice to the gods", dosacrifice, FALSE }, + { "overview", "show an overview of the dungeon", dooverview, TRUE }, + { "pray", "pray to the gods for help", dopray, TRUE }, + { "quit", "exit without saving current game", done2, TRUE }, + { "ride", "ride (or stop riding) a monster", doride, FALSE }, + { "rub", "rub a lamp or a stone", dorub, FALSE }, + { "sit", "sit down", dosit, FALSE }, + { "terrain", "show map without obstructions", doterrain, TRUE }, + { "tip", "empty a container", dotip, FALSE }, + { "turn", "turn undead", doturn, TRUE }, + { "twoweapon", "toggle two-weapon combat", dotwoweapon, FALSE }, + { "untrap", "untrap something", dountrap, FALSE }, + { "version", "list compile time options for this version of NetHack", + doextversion, TRUE }, + { "wipe", "wipe off your face", dowipe, FALSE }, + { "?", "get this list of extended commands", doextlist, TRUE }, + /* + * There must be a blank entry here for every entry in the table + * below. + */ + { (char *) 0, (char *) 0, donull, TRUE }, /* levelchange */ + { (char *) 0, (char *) 0, donull, TRUE }, /* lightsources */ #ifdef DEBUG_MIGRATING_MONS - {(char *)0, (char *)0, donull, TRUE}, /* migratemons */ + { (char *) 0, (char *) 0, donull, TRUE }, /* migratemons */ #endif - {(char *)0, (char *)0, donull, TRUE}, /* monpolycontrol */ - {(char *)0, (char *)0, donull, TRUE}, /* panic */ - {(char *)0, (char *)0, donull, TRUE}, /* polyself */ + { (char *) 0, (char *) 0, donull, TRUE }, /* monpolycontrol */ + { (char *) 0, (char *) 0, donull, TRUE }, /* panic */ + { (char *) 0, (char *) 0, donull, TRUE }, /* polyself */ #ifdef PORT_DEBUG - {(char *)0, (char *)0, donull, TRUE}, /* portdebug */ + { (char *) 0, (char *) 0, donull, TRUE }, /* portdebug */ #endif - {(char *)0, (char *)0, donull, TRUE}, /* seenv */ - {(char *)0, (char *)0, donull, TRUE}, /* stats */ - {(char *)0, (char *)0, donull, TRUE}, /* timeout */ - {(char *)0, (char *)0, donull, TRUE}, /* vanquished */ - {(char *)0, (char *)0, donull, TRUE}, /* vision */ - {(char *)0, (char *)0, donull, TRUE}, /* wizsmell */ + { (char *) 0, (char *) 0, donull, TRUE }, /* seenv */ + { (char *) 0, (char *) 0, donull, TRUE }, /* stats */ + { (char *) 0, (char *) 0, donull, TRUE }, /* timeout */ + { (char *) 0, (char *) 0, donull, TRUE }, /* vanquished */ + { (char *) 0, (char *) 0, donull, TRUE }, /* vision */ + { (char *) 0, (char *) 0, donull, TRUE }, /* wizsmell */ #ifdef DEBUG - {(char *)0, (char *)0, donull, TRUE}, /* wizdebug_traveldisplay */ - {(char *)0, (char *)0, donull, TRUE}, /* wizdebug_bury */ + { (char *) 0, (char *) 0, donull, TRUE }, /* wizdebug_traveldisplay */ + { (char *) 0, (char *) 0, donull, TRUE }, /* wizdebug_bury */ #endif - {(char *)0, (char *)0, donull, TRUE}, /* wizrumorcheck */ - {(char *)0, (char *)0, donull, TRUE}, /* wmode */ - {(char *)0, (char *)0, donull, TRUE} /* sentinel */ + { (char *) 0, (char *) 0, donull, TRUE }, /* wizrumorcheck */ + { (char *) 0, (char *) 0, donull, TRUE }, /* wmode */ + { (char *) 0, (char *) 0, donull, TRUE } /* sentinel */ }; /* there must be a placeholder in the table above for every entry here */ static const struct ext_func_tab debug_extcmdlist[] = { - {"levelchange", "change experience level", wiz_level_change, TRUE}, - {"lightsources", "show mobile light sources", wiz_light_sources, TRUE}, + { "levelchange", "change experience level", wiz_level_change, TRUE }, + { "lightsources", "show mobile light sources", wiz_light_sources, TRUE }, #ifdef DEBUG_MIGRATING_MONS - {"migratemons", "migrate n random monsters", wiz_migrate_mons, TRUE}, + { "migratemons", "migrate n random monsters", wiz_migrate_mons, TRUE }, #endif - {"monpolycontrol", "control monster polymorphs", wiz_mon_polycontrol, TRUE}, - {"panic", "test panic routine (fatal to game)", wiz_panic, TRUE}, - {"polyself", "polymorph self", wiz_polyself, TRUE}, + { "monpolycontrol", "control monster polymorphs", wiz_mon_polycontrol, + TRUE }, + { "panic", "test panic routine (fatal to game)", wiz_panic, TRUE }, + { "polyself", "polymorph self", wiz_polyself, TRUE }, #ifdef PORT_DEBUG - {"portdebug", "wizard port debug command", wiz_port_debug, TRUE}, + { "portdebug", "wizard port debug command", wiz_port_debug, TRUE }, #endif - {"seenv", "show seen vectors", wiz_show_seenv, TRUE}, - {"stats", "show memory statistics", wiz_show_stats, TRUE}, - {"timeout", "look at timeout queue", wiz_timeout_queue, TRUE}, - {"vanquished", "list vanquished monsters", dovanquished, TRUE}, - {"vision", "show vision array", wiz_show_vision, TRUE}, - {"wizsmell", "smell monster", wiz_smell, TRUE}, + { "seenv", "show seen vectors", wiz_show_seenv, TRUE }, + { "stats", "show memory statistics", wiz_show_stats, TRUE }, + { "timeout", "look at timeout queue", wiz_timeout_queue, TRUE }, + { "vanquished", "list vanquished monsters", dovanquished, TRUE }, + { "vision", "show vision array", wiz_show_vision, TRUE }, + { "wizsmell", "smell monster", wiz_smell, TRUE }, #ifdef DEBUG - {"wizdebug_traveldisplay", "wizard debug: toggle travel display", wiz_debug_cmd_traveldisplay, TRUE}, - {"wizdebug_bury", "wizard debug: bury objs under and around you", wiz_debug_cmd_bury, TRUE}, + { "wizdebug_traveldisplay", "wizard debug: toggle travel display", + wiz_debug_cmd_traveldisplay, TRUE }, + { "wizdebug_bury", "wizard debug: bury objs under and around you", + wiz_debug_cmd_bury, TRUE }, #endif - {"wizrumorcheck", "verify rumor boundaries", wiz_rumor_check, TRUE}, - {"wmode", "show wall modes", wiz_show_wmodes, TRUE}, - {(char *)0, (char *)0, donull, TRUE} + { "wizrumorcheck", "verify rumor boundaries", wiz_rumor_check, TRUE }, + { "wmode", "show wall modes", wiz_show_wmodes, TRUE }, + { (char *) 0, (char *) 0, donull, TRUE } }; /* @@ -2579,36 +2789,37 @@ static const struct ext_func_tab debug_extcmdlist[] = { void add_debug_extended_commands() { - int i, j, k, n; + int i, j, k, n; - /* count the # of help entries */ - for (n = 0; extcmdlist[n].ef_txt[0] != '?'; n++) - ; + /* count the # of help entries */ + for (n = 0; extcmdlist[n].ef_txt[0] != '?'; n++) + ; - for (i = 0; debug_extcmdlist[i].ef_txt; i++) { - /* need enough room for "?" entry plus terminator */ - if (n + 2 >= SIZE(extcmdlist)) - panic("Too many debugging commands!"); - for (j = 0; j < n; j++) - if (strcmp(debug_extcmdlist[i].ef_txt, extcmdlist[j].ef_txt) < 0) break; + for (i = 0; debug_extcmdlist[i].ef_txt; i++) { + /* need enough room for "?" entry plus terminator */ + if (n + 2 >= SIZE(extcmdlist)) + panic("Too many debugging commands!"); + for (j = 0; j < n; j++) + if (strcmp(debug_extcmdlist[i].ef_txt, extcmdlist[j].ef_txt) < 0) + break; - /* insert i'th debug entry into extcmdlist[j], pushing down */ - for (k = n; k >= j; --k) - extcmdlist[k+1] = extcmdlist[k]; - extcmdlist[j] = debug_extcmdlist[i]; - n++; /* now an extra entry */ - } + /* insert i'th debug entry into extcmdlist[j], pushing down */ + for (k = n; k >= j; --k) + extcmdlist[k + 1] = extcmdlist[k]; + extcmdlist[j] = debug_extcmdlist[i]; + n++; /* now an extra entry */ + } } STATIC_OVL char cmd_from_func(fn) int NDECL((*fn)); { - int i; - for (i = 0; i < SIZE(cmdlist); ++i) - if (cmdlist[i].f_funct == fn) - return cmdlist[i].f_char; - return 0; + int i; + for (i = 0; i < SIZE(cmdlist); ++i) + if (cmdlist[i].f_funct == fn) + return cmdlist[i].f_char; + return 0; } static const char template[] = "%-18s %4ld %6ld"; @@ -2619,147 +2830,159 @@ STATIC_OVL int size_obj(otmp) struct obj *otmp; { - int sz = (int)sizeof (struct obj); + int sz = (int) sizeof(struct obj); - if (otmp->oextra) { - sz += (int)sizeof (struct oextra); - if (ONAME(otmp)) sz += (int)strlen(ONAME(otmp)) + 1; - if (OMONST(otmp)) sz += (int)sizeof (struct monst); - if (OMID(otmp)) sz += (int)sizeof (unsigned); - if (OLONG(otmp)) sz += (int)sizeof (long); - if (OMAILCMD(otmp)) sz += (int)strlen(OMAILCMD(otmp)) + 1; - } - return sz; + if (otmp->oextra) { + sz += (int) sizeof(struct oextra); + if (ONAME(otmp)) + sz += (int) strlen(ONAME(otmp)) + 1; + if (OMONST(otmp)) + sz += (int) sizeof(struct monst); + if (OMID(otmp)) + sz += (int) sizeof(unsigned); + if (OLONG(otmp)) + sz += (int) sizeof(long); + if (OMAILCMD(otmp)) + sz += (int) strlen(OMAILCMD(otmp)) + 1; + } + return sz; } - STATIC_OVL void count_obj(chain, total_count, total_size, top, recurse) - struct obj *chain; - long *total_count; - long *total_size; - boolean top; - boolean recurse; +struct obj *chain; +long *total_count; +long *total_size; +boolean top; +boolean recurse; { - long count, size; - struct obj *obj; + long count, size; + struct obj *obj; - for (count = size = 0, obj = chain; obj; obj = obj->nobj) { - if (top) { - count++; - size += size_obj(obj); - } - if (recurse && obj->cobj) - count_obj(obj->cobj, total_count, total_size, TRUE, TRUE); - } - *total_count += count; - *total_size += size; + for (count = size = 0, obj = chain; obj; obj = obj->nobj) { + if (top) { + count++; + size += size_obj(obj); + } + if (recurse && obj->cobj) + count_obj(obj->cobj, total_count, total_size, TRUE, TRUE); + } + *total_count += count; + *total_size += size; } STATIC_OVL void obj_chain(win, src, chain, total_count, total_size) - winid win; - const char *src; - struct obj *chain; - long *total_count; - long *total_size; +winid win; +const char *src; +struct obj *chain; +long *total_count; +long *total_size; { - char buf[BUFSZ]; - long count = 0, size = 0; + char buf[BUFSZ]; + long count = 0, size = 0; - count_obj(chain, &count, &size, TRUE, FALSE); - *total_count += count; - *total_size += size; - Sprintf(buf, template, src, count, size); - putstr(win, 0, buf); + count_obj(chain, &count, &size, TRUE, FALSE); + *total_count += count; + *total_size += size; + Sprintf(buf, template, src, count, size); + putstr(win, 0, buf); } STATIC_OVL void mon_invent_chain(win, src, chain, total_count, total_size) - winid win; - const char *src; - struct monst *chain; - long *total_count; - long *total_size; +winid win; +const char *src; +struct monst *chain; +long *total_count; +long *total_size; { - char buf[BUFSZ]; - long count = 0, size = 0; - struct monst *mon; + char buf[BUFSZ]; + long count = 0, size = 0; + struct monst *mon; - for (mon = chain; mon; mon = mon->nmon) - count_obj(mon->minvent, &count, &size, TRUE, FALSE); - *total_count += count; - *total_size += size; - Sprintf(buf, template, src, count, size); - putstr(win, 0, buf); + for (mon = chain; mon; mon = mon->nmon) + count_obj(mon->minvent, &count, &size, TRUE, FALSE); + *total_count += count; + *total_size += size; + Sprintf(buf, template, src, count, size); + putstr(win, 0, buf); } STATIC_OVL void contained(win, src, total_count, total_size) - winid win; - const char *src; - long *total_count; - long *total_size; +winid win; +const char *src; +long *total_count; +long *total_size; { - char buf[BUFSZ]; - long count = 0, size = 0; - struct monst *mon; + char buf[BUFSZ]; + long count = 0, size = 0; + struct monst *mon; - count_obj(invent, &count, &size, FALSE, TRUE); - count_obj(fobj, &count, &size, FALSE, TRUE); - count_obj(level.buriedobjlist, &count, &size, FALSE, TRUE); - count_obj(migrating_objs, &count, &size, FALSE, TRUE); - /* DEADMONSTER check not required in this loop since they have no inventory */ - for (mon = fmon; mon; mon = mon->nmon) - count_obj(mon->minvent, &count, &size, FALSE, TRUE); - for (mon = migrating_mons; mon; mon = mon->nmon) - count_obj(mon->minvent, &count, &size, FALSE, TRUE); + count_obj(invent, &count, &size, FALSE, TRUE); + count_obj(fobj, &count, &size, FALSE, TRUE); + count_obj(level.buriedobjlist, &count, &size, FALSE, TRUE); + count_obj(migrating_objs, &count, &size, FALSE, TRUE); + /* DEADMONSTER check not required in this loop since they have no + * inventory */ + for (mon = fmon; mon; mon = mon->nmon) + count_obj(mon->minvent, &count, &size, FALSE, TRUE); + for (mon = migrating_mons; mon; mon = mon->nmon) + count_obj(mon->minvent, &count, &size, FALSE, TRUE); - *total_count += count; *total_size += size; + *total_count += count; + *total_size += size; - Sprintf(buf, template, src, count, size); - putstr(win, 0, buf); + Sprintf(buf, template, src, count, size); + putstr(win, 0, buf); } STATIC_OVL int size_monst(mtmp) struct monst *mtmp; { - int sz = (int)sizeof (struct monst); + int sz = (int) sizeof(struct monst); - if (mtmp->mextra) { - sz += (int)sizeof (struct mextra); - if (MNAME(mtmp)) sz += (int)strlen(MNAME(mtmp)) + 1; - if (EGD(mtmp)) sz += (int)sizeof (struct egd); - if (EPRI(mtmp)) sz += (int)sizeof (struct epri); - if (ESHK(mtmp)) sz += (int)sizeof (struct eshk); - if (EMIN(mtmp)) sz += (int)sizeof (struct emin); - if (EDOG(mtmp)) sz += (int)sizeof (struct edog); - /* mextra->mcorpsenm doesn't point to more memory */ - } - return sz; + if (mtmp->mextra) { + sz += (int) sizeof(struct mextra); + if (MNAME(mtmp)) + sz += (int) strlen(MNAME(mtmp)) + 1; + if (EGD(mtmp)) + sz += (int) sizeof(struct egd); + if (EPRI(mtmp)) + sz += (int) sizeof(struct epri); + if (ESHK(mtmp)) + sz += (int) sizeof(struct eshk); + if (EMIN(mtmp)) + sz += (int) sizeof(struct emin); + if (EDOG(mtmp)) + sz += (int) sizeof(struct edog); + /* mextra->mcorpsenm doesn't point to more memory */ + } + return sz; } STATIC_OVL void mon_chain(win, src, chain, total_count, total_size) - winid win; - const char *src; - struct monst *chain; - long *total_count; - long *total_size; +winid win; +const char *src; +struct monst *chain; +long *total_count; +long *total_size; { - char buf[BUFSZ]; - long count, size; - struct monst *mon; + char buf[BUFSZ]; + long count, size; + struct monst *mon; - for (count = size = 0, mon = chain; mon; mon = mon->nmon) { - count++; - size += size_monst(mon); - } - *total_count += count; - *total_size += size; - Sprintf(buf, template, src, count, size); - putstr(win, 0, buf); + for (count = size = 0, mon = chain; mon; mon = mon->nmon) { + count++; + size += size_monst(mon); + } + *total_count += count; + *total_size += size; + Sprintf(buf, template, src, count, size); + putstr(win, 0, buf); } /* @@ -2768,187 +2991,190 @@ mon_chain(win, src, chain, total_count, total_size) static int wiz_show_stats() { - char buf[BUFSZ]; - winid win; - long total_obj_size = 0, total_obj_count = 0; - long total_mon_size = 0, total_mon_count = 0; + char buf[BUFSZ]; + winid win; + long total_obj_size = 0, total_obj_count = 0; + long total_mon_size = 0, total_mon_count = 0; - win = create_nhwindow(NHW_TEXT); - putstr(win, 0, "Current memory statistics:"); - putstr(win, 0, ""); - Sprintf(buf, "Objects, size %d", (int) sizeof(struct obj)); - putstr(win, 0, buf); - putstr(win, 0, ""); - putstr(win, 0, count_str); + win = create_nhwindow(NHW_TEXT); + putstr(win, 0, "Current memory statistics:"); + putstr(win, 0, ""); + Sprintf(buf, "Objects, size %d", (int) sizeof(struct obj)); + putstr(win, 0, buf); + putstr(win, 0, ""); + putstr(win, 0, count_str); - obj_chain(win, "invent", invent, &total_obj_count, &total_obj_size); - obj_chain(win, "fobj", fobj, &total_obj_count, &total_obj_size); - obj_chain(win, "buried", level.buriedobjlist, - &total_obj_count, &total_obj_size); - obj_chain(win, "migrating obj", migrating_objs, - &total_obj_count, &total_obj_size); - mon_invent_chain(win, "minvent", fmon, - &total_obj_count,&total_obj_size); - mon_invent_chain(win, "migrating minvent", migrating_mons, - &total_obj_count, &total_obj_size); + obj_chain(win, "invent", invent, &total_obj_count, &total_obj_size); + obj_chain(win, "fobj", fobj, &total_obj_count, &total_obj_size); + obj_chain(win, "buried", level.buriedobjlist, &total_obj_count, + &total_obj_size); + obj_chain(win, "migrating obj", migrating_objs, &total_obj_count, + &total_obj_size); + mon_invent_chain(win, "minvent", fmon, &total_obj_count, &total_obj_size); + mon_invent_chain(win, "migrating minvent", migrating_mons, + &total_obj_count, &total_obj_size); - contained(win, "contained", - &total_obj_count, &total_obj_size); + contained(win, "contained", &total_obj_count, &total_obj_size); - putstr(win, 0, separator); - Sprintf(buf, template, "Total", total_obj_count, total_obj_size); - putstr(win, 0, buf); + putstr(win, 0, separator); + Sprintf(buf, template, "Total", total_obj_count, total_obj_size); + putstr(win, 0, buf); - putstr(win, 0, ""); - putstr(win, 0, ""); - Sprintf(buf, "Monsters, size %d", (int) sizeof(struct monst)); - putstr(win, 0, buf); - putstr(win, 0, ""); + putstr(win, 0, ""); + putstr(win, 0, ""); + Sprintf(buf, "Monsters, size %d", (int) sizeof(struct monst)); + putstr(win, 0, buf); + putstr(win, 0, ""); - mon_chain(win, "fmon", fmon, - &total_mon_count, &total_mon_size); - mon_chain(win, "migrating", migrating_mons, - &total_mon_count, &total_mon_size); + mon_chain(win, "fmon", fmon, &total_mon_count, &total_mon_size); + mon_chain(win, "migrating", migrating_mons, &total_mon_count, + &total_mon_size); - putstr(win, 0, separator); - Sprintf(buf, template, "Total", total_mon_count, total_mon_size); - putstr(win, 0, buf); + putstr(win, 0, separator); + Sprintf(buf, template, "Total", total_mon_count, total_mon_size); + putstr(win, 0, buf); #if defined(__BORLANDC__) && !defined(_WIN32) - show_borlandc_stats(win); + show_borlandc_stats(win); #endif - display_nhwindow(win, FALSE); - destroy_nhwindow(win); - return 0; + display_nhwindow(win, FALSE); + destroy_nhwindow(win); + return 0; } void sanity_check() { - obj_sanity_check(); - timer_sanity_check(); + obj_sanity_check(); + timer_sanity_check(); } #ifdef DEBUG_MIGRATING_MONS static int wiz_migrate_mons() { - int mcount = 0; - char inbuf[BUFSZ]; - struct permonst *ptr; - struct monst *mtmp; - d_level tolevel; + int mcount = 0; + char inbuf[BUFSZ]; + struct permonst *ptr; + struct monst *mtmp; + d_level tolevel; - getlin("How many random monsters to migrate? [0]", inbuf); - if (*inbuf == '\033') return 0; - mcount = atoi(inbuf); - if (mcount < 0 || mcount > (COLNO * ROWNO) || Is_botlevel(&u.uz)) - return 0; - while (mcount > 0) { - if (Is_stronghold(&u.uz)) - assign_level(&tolevel, &valley_level); - else - get_level(&tolevel, depth(&u.uz) + 1); - ptr = rndmonst(); - mtmp = makemon(ptr, 0, 0, NO_MM_FLAGS); - if (mtmp) migrate_to_level(mtmp, ledger_no(&tolevel), - MIGR_RANDOM, (coord *)0); - mcount--; - } - return 0; + getlin("How many random monsters to migrate? [0]", inbuf); + if (*inbuf == '\033') + return 0; + mcount = atoi(inbuf); + if (mcount < 0 || mcount > (COLNO * ROWNO) || Is_botlevel(&u.uz)) + return 0; + while (mcount > 0) { + if (Is_stronghold(&u.uz)) + assign_level(&tolevel, &valley_level); + else + get_level(&tolevel, depth(&u.uz) + 1); + ptr = rndmonst(); + mtmp = makemon(ptr, 0, 0, NO_MM_FLAGS); + if (mtmp) + migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM, + (coord *) 0); + mcount--; + } + return 0; } #endif -#define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c)) -#define unmeta(c) (0x7f & (c)) +#define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c)) +#define unmeta(c) (0x7f & (c)) /* called at startup and after number_pad is twiddled */ void reset_commands(initial) boolean initial; { - static const char - sdir[] = "hykulnjb><", sdir_swap_yz[] = "hzkulnjb><", - ndir[] = "47896321><", ndir_phone_layout[] = "41236987><"; - static const int ylist[] = { 'y', 'Y', C('y'), M('y'), M('Y'), M(C('y')) }; + static const char sdir[] = "hykulnjb><", sdir_swap_yz[] = "hzkulnjb><", + ndir[] = "47896321><", + ndir_phone_layout[] = "41236987><"; + static const int ylist[] = { + 'y', 'Y', C('y'), M('y'), M('Y'), M(C('y')) + }; const struct func_tab *cmdtmp; boolean flagtemp; int c, i, updated = 0; if (initial) { - updated = 1; - for (i = 0; i < SIZE(cmdlist); i++) { - c = cmdlist[i].f_char & 0xff; - Cmd.commands[c] = &cmdlist[i]; - } - Cmd.num_pad = FALSE; - Cmd.pcHack_compat = Cmd.phone_layout = Cmd.swap_yz = FALSE; + updated = 1; + for (i = 0; i < SIZE(cmdlist); i++) { + c = cmdlist[i].f_char & 0xff; + Cmd.commands[c] = &cmdlist[i]; + } + Cmd.num_pad = FALSE; + Cmd.pcHack_compat = Cmd.phone_layout = Cmd.swap_yz = FALSE; } else { - /* basic num_pad */ - flagtemp = iflags.num_pad; - if (flagtemp != Cmd.num_pad) { - Cmd.num_pad = flagtemp; - ++updated; - } - /* swap_yz mode (only applicable for !num_pad) */ - flagtemp = (iflags.num_pad_mode & 1) ? !Cmd.num_pad : FALSE; - if (flagtemp != Cmd.swap_yz) { - Cmd.swap_yz = flagtemp; - ++updated; - /* Cmd.swap_yz has been toggled; - perform the swap (or reverse previous one) */ - for (i = 0; i < SIZE(ylist); i++) { - c = ylist[i] & 0xff; - cmdtmp = Cmd.commands[c]; /* tmp = [y] */ - Cmd.commands[c] = Cmd.commands[c + 1]; /* [y] = [z] */ - Cmd.commands[c + 1] = cmdtmp; /* [z] = tmp */ - } - } - /* MSDOS compatibility mode (only applicable for num_pad) */ - flagtemp = (iflags.num_pad_mode & 1) ? Cmd.num_pad : FALSE; - if (flagtemp != Cmd.pcHack_compat) { - Cmd.pcHack_compat = flagtemp; - ++updated; - /* pcHack_compat has been toggled */ - c = M('5') & 0xff; - cmdtmp = Cmd.commands['5']; - Cmd.commands['5'] = Cmd.commands[c]; - Cmd.commands[c] = cmdtmp; - c = M('0') & 0xff; - Cmd.commands[c] = Cmd.pcHack_compat ? Cmd.commands['I'] : 0; - } - /* phone keypad layout (only applicable for num_pad) */ - flagtemp = (iflags.num_pad_mode & 2) ? Cmd.num_pad : FALSE; - if (flagtemp != Cmd.phone_layout) { - Cmd.phone_layout = flagtemp; - ++updated; - /* phone_layout has been toggled */ - for (i = 0; i < 3; i++) { - c = '1' + i; /* 1,2,3 <-> 7,8,9 */ - cmdtmp = Cmd.commands[c]; /* tmp = [1] */ - Cmd.commands[c] = Cmd.commands[c + 6]; /* [1] = [7] */ - Cmd.commands[c + 6] = cmdtmp; /* [7] = tmp */ - c = (M('1') & 0xff) + i; /* M-1,M-2,M-3 <-> M-7,M-8,M-9 */ - cmdtmp = Cmd.commands[c]; /* tmp = [M-1] */ - Cmd.commands[c] = Cmd.commands[c + 6]; /* [M-1] = [M-7] */ - Cmd.commands[c + 6] = cmdtmp; /* [M-7] = tmp */ - } - } + /* basic num_pad */ + flagtemp = iflags.num_pad; + if (flagtemp != Cmd.num_pad) { + Cmd.num_pad = flagtemp; + ++updated; + } + /* swap_yz mode (only applicable for !num_pad) */ + flagtemp = (iflags.num_pad_mode & 1) ? !Cmd.num_pad : FALSE; + if (flagtemp != Cmd.swap_yz) { + Cmd.swap_yz = flagtemp; + ++updated; + /* Cmd.swap_yz has been toggled; + perform the swap (or reverse previous one) */ + for (i = 0; i < SIZE(ylist); i++) { + c = ylist[i] & 0xff; + cmdtmp = Cmd.commands[c]; /* tmp = [y] */ + Cmd.commands[c] = Cmd.commands[c + 1]; /* [y] = [z] */ + Cmd.commands[c + 1] = cmdtmp; /* [z] = tmp */ + } + } + /* MSDOS compatibility mode (only applicable for num_pad) */ + flagtemp = (iflags.num_pad_mode & 1) ? Cmd.num_pad : FALSE; + if (flagtemp != Cmd.pcHack_compat) { + Cmd.pcHack_compat = flagtemp; + ++updated; + /* pcHack_compat has been toggled */ + c = M('5') & 0xff; + cmdtmp = Cmd.commands['5']; + Cmd.commands['5'] = Cmd.commands[c]; + Cmd.commands[c] = cmdtmp; + c = M('0') & 0xff; + Cmd.commands[c] = Cmd.pcHack_compat ? Cmd.commands['I'] : 0; + } + /* phone keypad layout (only applicable for num_pad) */ + flagtemp = (iflags.num_pad_mode & 2) ? Cmd.num_pad : FALSE; + if (flagtemp != Cmd.phone_layout) { + Cmd.phone_layout = flagtemp; + ++updated; + /* phone_layout has been toggled */ + for (i = 0; i < 3; i++) { + c = '1' + i; /* 1,2,3 <-> 7,8,9 */ + cmdtmp = Cmd.commands[c]; /* tmp = [1] */ + Cmd.commands[c] = Cmd.commands[c + 6]; /* [1] = [7] */ + Cmd.commands[c + 6] = cmdtmp; /* [7] = tmp */ + c = (M('1') & 0xff) + i; /* M-1,M-2,M-3 <-> M-7,M-8,M-9 */ + cmdtmp = Cmd.commands[c]; /* tmp = [M-1] */ + Cmd.commands[c] = Cmd.commands[c + 6]; /* [M-1] = [M-7] */ + Cmd.commands[c + 6] = cmdtmp; /* [M-7] = tmp */ + } + } } /*?initial*/ - if (updated) Cmd.serialno++; - Cmd.dirchars = !Cmd.num_pad ? (!Cmd.swap_yz ? sdir : sdir_swap_yz) : - (!Cmd.phone_layout ? ndir : ndir_phone_layout); + if (updated) + Cmd.serialno++; + Cmd.dirchars = !Cmd.num_pad + ? (!Cmd.swap_yz ? sdir : sdir_swap_yz) + : (!Cmd.phone_layout ? ndir : ndir_phone_layout); Cmd.alphadirchars = !Cmd.num_pad ? Cmd.dirchars : sdir; - Cmd.move_W = Cmd.dirchars[0]; + Cmd.move_W = Cmd.dirchars[0]; Cmd.move_NW = Cmd.dirchars[1]; - Cmd.move_N = Cmd.dirchars[2]; + Cmd.move_N = Cmd.dirchars[2]; Cmd.move_NE = Cmd.dirchars[3]; - Cmd.move_E = Cmd.dirchars[4]; + Cmd.move_E = Cmd.dirchars[4]; Cmd.move_SE = Cmd.dirchars[5]; - Cmd.move_S = Cmd.dirchars[6]; + Cmd.move_S = Cmd.dirchars[6]; Cmd.move_SW = Cmd.dirchars[7]; } @@ -2956,9 +3182,8 @@ STATIC_OVL boolean accept_menu_prefix(cmd_func) int NDECL((*cmd_func)); { - if (cmd_func == dopickup || - cmd_func == doextcmd || cmd_func == doextlist) - return TRUE; + if (cmd_func == dopickup || cmd_func == doextcmd || cmd_func == doextlist) + return TRUE; return FALSE; } @@ -2966,273 +3191,289 @@ void rhack(cmd) register char *cmd; { - boolean do_walk, do_rush, prefix_seen, bad_command, - firsttime = (cmd == 0); + boolean do_walk, do_rush, prefix_seen, bad_command, + firsttime = (cmd == 0); - iflags.menu_requested = FALSE; + iflags.menu_requested = FALSE; #ifdef SAFERHANGUP - if (program_state.done_hup) end_of_input(); + if (program_state.done_hup) + end_of_input(); #endif - if (firsttime) { - context.nopick = 0; - cmd = parse(); - } - if (*cmd == '\033') { - context.move = FALSE; - return; - } - if (*cmd == DOAGAIN && !in_doagain && saveq[0]) { - in_doagain = TRUE; - stail = 0; - rhack((char *)0); /* read and execute command */ - in_doagain = FALSE; - return; - } - /* Special case of *cmd == ' ' handled better below */ - if(!*cmd || *cmd == (char)0377) - { - nhbell(); - context.move = FALSE; - return; /* probably we just had an interrupt */ - } + if (firsttime) { + context.nopick = 0; + cmd = parse(); + } + if (*cmd == '\033') { + context.move = FALSE; + return; + } + if (*cmd == DOAGAIN && !in_doagain && saveq[0]) { + in_doagain = TRUE; + stail = 0; + rhack((char *) 0); /* read and execute command */ + in_doagain = FALSE; + return; + } + /* Special case of *cmd == ' ' handled better below */ + if (!*cmd || *cmd == (char) 0377) { + nhbell(); + context.move = FALSE; + return; /* probably we just had an interrupt */ + } - /* handle most movement commands */ - do_walk = do_rush = prefix_seen = FALSE; - context.travel = context.travel1 = 0; - switch (*cmd) { - case 'g': if (movecmd(cmd[1])) { - context.run = 2; - do_rush = TRUE; - } else - prefix_seen = TRUE; - break; - case '5': if (!Cmd.num_pad) break; /* else FALLTHRU */ - case 'G': if (movecmd(lowc(cmd[1]))) { - context.run = 3; - do_rush = TRUE; - } else - prefix_seen = TRUE; - break; - case '-': if (!Cmd.num_pad) break; /* else FALLTHRU */ - /* Effects of movement commands and invisible monsters: - * m: always move onto space (even if 'I' remembered) - * F: always attack space (even if 'I' not remembered) - * normal movement: attack if 'I', move otherwise - */ - case 'F': if (movecmd(cmd[1])) { - context.forcefight = 1; - do_walk = TRUE; - } else - prefix_seen = TRUE; - break; - case 'm': if (movecmd(cmd[1]) || u.dz) { - context.run = 0; - context.nopick = 1; - if (!u.dz) do_walk = TRUE; - else cmd[0] = cmd[1]; /* "m<" or "m>" */ - } else - prefix_seen = TRUE; - break; - case 'M': if (movecmd(lowc(cmd[1]))) { - context.run = 1; - context.nopick = 1; - do_rush = TRUE; - } else - prefix_seen = TRUE; - break; - case '0': if (!Cmd.num_pad) break; - (void)ddoinv(); /* a convenience borrowed from the PC */ - context.move = FALSE; - multi = 0; - return; - case CMD_CLICKLOOK: - if (iflags.clicklook) { - context.move = FALSE; - do_look(2, &clicklook_cc); - } - return; - case CMD_TRAVEL: - if (flags.travelcmd) { - context.travel = 1; - context.travel1 = 1; - context.run = 8; - context.nopick = 1; - do_rush = TRUE; - break; - } - /*FALLTHRU*/ - default: if (movecmd(*cmd)) { /* ordinary movement */ - context.run = 0; /* only matters here if it was 8 */ - do_walk = TRUE; - } else if (movecmd(Cmd.num_pad ? - unmeta(*cmd) : lowc(*cmd))) { - context.run = 1; - do_rush = TRUE; - } else if (movecmd(unctrl(*cmd))) { - context.run = 3; - do_rush = TRUE; - } - break; - } + /* handle most movement commands */ + do_walk = do_rush = prefix_seen = FALSE; + context.travel = context.travel1 = 0; + switch (*cmd) { + case 'g': + if (movecmd(cmd[1])) { + context.run = 2; + do_rush = TRUE; + } else + prefix_seen = TRUE; + break; + case '5': + if (!Cmd.num_pad) + break; /* else FALLTHRU */ + case 'G': + if (movecmd(lowc(cmd[1]))) { + context.run = 3; + do_rush = TRUE; + } else + prefix_seen = TRUE; + break; + case '-': + if (!Cmd.num_pad) + break; /* else FALLTHRU */ + /* Effects of movement commands and invisible monsters: + * m: always move onto space (even if 'I' remembered) + * F: always attack space (even if 'I' not remembered) + * normal movement: attack if 'I', move otherwise + */ + case 'F': + if (movecmd(cmd[1])) { + context.forcefight = 1; + do_walk = TRUE; + } else + prefix_seen = TRUE; + break; + case 'm': + if (movecmd(cmd[1]) || u.dz) { + context.run = 0; + context.nopick = 1; + if (!u.dz) + do_walk = TRUE; + else + cmd[0] = cmd[1]; /* "m<" or "m>" */ + } else + prefix_seen = TRUE; + break; + case 'M': + if (movecmd(lowc(cmd[1]))) { + context.run = 1; + context.nopick = 1; + do_rush = TRUE; + } else + prefix_seen = TRUE; + break; + case '0': + if (!Cmd.num_pad) + break; + (void) ddoinv(); /* a convenience borrowed from the PC */ + context.move = FALSE; + multi = 0; + return; + case CMD_CLICKLOOK: + if (iflags.clicklook) { + context.move = FALSE; + do_look(2, &clicklook_cc); + } + return; + case CMD_TRAVEL: + if (flags.travelcmd) { + context.travel = 1; + context.travel1 = 1; + context.run = 8; + context.nopick = 1; + do_rush = TRUE; + break; + } + /*FALLTHRU*/ + default: + if (movecmd(*cmd)) { /* ordinary movement */ + context.run = 0; /* only matters here if it was 8 */ + do_walk = TRUE; + } else if (movecmd(Cmd.num_pad ? unmeta(*cmd) : lowc(*cmd))) { + context.run = 1; + do_rush = TRUE; + } else if (movecmd(unctrl(*cmd))) { + context.run = 3; + do_rush = TRUE; + } + break; + } - /* some special prefix handling */ - /* overload 'm' prefix to mean "request a menu" */ - if (prefix_seen && cmd[0] == 'm') { - /* (for func_tab cast, see below) */ - const struct func_tab *ft = Cmd.commands[cmd[1] & 0xff]; - int NDECL((*func)) = ft ? ((struct func_tab *)ft)->f_funct : 0; + /* some special prefix handling */ + /* overload 'm' prefix to mean "request a menu" */ + if (prefix_seen && cmd[0] == 'm') { + /* (for func_tab cast, see below) */ + const struct func_tab *ft = Cmd.commands[cmd[1] & 0xff]; + int NDECL((*func)) = ft ? ((struct func_tab *) ft)->f_funct : 0; - if (func && accept_menu_prefix(func)) { - iflags.menu_requested = TRUE; - ++cmd; - } - } + if (func && accept_menu_prefix(func)) { + iflags.menu_requested = TRUE; + ++cmd; + } + } - if ((do_walk || do_rush) && !context.travel && !dxdy_moveok()) { - /* trying to move diagonally as a grid bug; - this used to be treated by movecmd() as not being - a movement attempt, but that didn't provide for any - feedback and led to strangeness if the key pressed - ('u' in particular) was overloaded for num_pad use */ - You_cant("get there from here..."); - context.run = 0; - context.nopick = context.forcefight = FALSE; - context.move = context.mv = FALSE; - multi = 0; - return; - } + if ((do_walk || do_rush) && !context.travel && !dxdy_moveok()) { + /* trying to move diagonally as a grid bug; + this used to be treated by movecmd() as not being + a movement attempt, but that didn't provide for any + feedback and led to strangeness if the key pressed + ('u' in particular) was overloaded for num_pad use */ + You_cant("get there from here..."); + context.run = 0; + context.nopick = context.forcefight = FALSE; + context.move = context.mv = FALSE; + multi = 0; + return; + } - if (do_walk) { - if (multi) context.mv = TRUE; - domove(); - context.forcefight = 0; - return; - } else if (do_rush) { - if (firsttime) { - if (!multi) multi = max(COLNO,ROWNO); - u.last_str_turn = 0; - } - context.mv = TRUE; - domove(); - return; - } else if (prefix_seen && cmd[1] == '\033') { /* */ - /* don't report "unknown command" for change of heart... */ - bad_command = FALSE; - } else if (*cmd == ' ' && !flags.rest_on_space) { - bad_command = TRUE; /* skip cmdlist[] loop */ + if (do_walk) { + if (multi) + context.mv = TRUE; + domove(); + context.forcefight = 0; + return; + } else if (do_rush) { + if (firsttime) { + if (!multi) + multi = max(COLNO, ROWNO); + u.last_str_turn = 0; + } + context.mv = TRUE; + domove(); + return; + } else if (prefix_seen && cmd[1] == '\033') { /* */ + /* don't report "unknown command" for change of heart... */ + bad_command = FALSE; + } else if (*cmd == ' ' && !flags.rest_on_space) { + bad_command = TRUE; /* skip cmdlist[] loop */ - /* handle all other commands */ - } else { - register const struct func_tab *tlist; - int res, NDECL((*func)); + /* handle all other commands */ + } else { + register const struct func_tab *tlist; + int res, NDECL((*func)); #if 0 for (tlist = cmdlist; tlist->f_char; tlist++) { if ((*cmd & 0xff) != (tlist->f_char & 0xff)) continue; #else - if ((tlist = Cmd.commands[*cmd & 0xff]) != 0) { + if ((tlist = Cmd.commands[*cmd & 0xff]) != 0) { #endif - if (u.uburied && !tlist->can_if_buried) { - You_cant("do that while you are buried!"); - res = 0; - } else { - /* we discard 'const' because some compilers seem to have - trouble with the pointer passed to set_occupation() */ - func = ((struct func_tab *)tlist)->f_funct; - if (tlist->f_text && !occupation && multi) - set_occupation(func, tlist->f_text, multi); - res = (*func)(); /* perform the command */ - } - if (!res) { - context.move = FALSE; - multi = 0; - } - return; - } - /* if we reach here, cmd wasn't found in cmdlist[] */ - bad_command = TRUE; - } - - if (bad_command) { - char expcmd[10]; - register char c, *cp = expcmd; - - while ((c = *cmd++) != '\0' && - (int)(cp - expcmd) < (int)(sizeof expcmd - 3)) { - if (c >= 040 && c < 0177) { - *cp++ = c; - } else if (c & 0200) { - *cp++ = 'M'; - *cp++ = '-'; - *cp++ = c & ~0200; - } else { - *cp++ = '^'; - *cp++ = c ^ 0100; - } - } - *cp = '\0'; - if (!prefix_seen || !iflags.cmdassist || - !help_dir(0, "Invalid direction key!")) - Norep("Unknown command '%s'.", expcmd); - } - /* didn't move */ - context.move = FALSE; - multi = 0; - return; + if (u.uburied && !tlist->can_if_buried) { + You_cant("do that while you are buried!"); + res = 0; + } else { + /* we discard 'const' because some compilers seem to have + trouble with the pointer passed to set_occupation() */ + func = ((struct func_tab *) tlist)->f_funct; + if (tlist->f_text && !occupation && multi) + set_occupation(func, tlist->f_text, multi); + res = (*func)(); /* perform the command */ + } + if (!res) { + context.move = FALSE; + multi = 0; + } + return; + } + /* if we reach here, cmd wasn't found in cmdlist[] */ + bad_command = TRUE; } -int -xytod(x, y) /* convert an x,y pair into a direction code */ +if (bad_command) { + char expcmd[10]; + register char c, *cp = expcmd; + + while ((c = *cmd++) != '\0' + && (int) (cp - expcmd) < (int) (sizeof expcmd - 3)) { + if (c >= 040 && c < 0177) { + *cp++ = c; + } else if (c & 0200) { + *cp++ = 'M'; + *cp++ = '-'; + *cp++ = c & ~0200; + } else { + *cp++ = '^'; + *cp++ = c ^ 0100; + } + } + *cp = '\0'; + if (!prefix_seen || !iflags.cmdassist + || !help_dir(0, "Invalid direction key!")) + Norep("Unknown command '%s'.", expcmd); +} +/* didn't move */ +context.move = FALSE; +multi = 0; +return; +} + +int xytod(x, y) /* convert an x,y pair into a direction code */ schar x, y; { - register int dd; + register int dd; - for(dd = 0; dd < 8; dd++) - if(x == xdir[dd] && y == ydir[dd]) return dd; + for (dd = 0; dd < 8; dd++) + if (x == xdir[dd] && y == ydir[dd]) + return dd; - return -1; + return -1; } -void -dtoxy(cc,dd) /* convert a direction code into an x,y pair */ +void dtoxy(cc, dd) /* convert a direction code into an x,y pair */ coord *cc; register int dd; { - cc->x = xdir[dd]; - cc->y = ydir[dd]; - return; + cc->x = xdir[dd]; + cc->y = ydir[dd]; + return; } -int -movecmd(sym) /* also sets u.dz, but returns false for <> */ +int movecmd(sym) /* also sets u.dz, but returns false for <> */ char sym; { - register const char *dp = index(Cmd.dirchars, sym); + register const char *dp = index(Cmd.dirchars, sym); - u.dz = 0; - if (!dp) return 0; - u.dx = xdir[dp - Cmd.dirchars]; - u.dy = ydir[dp - Cmd.dirchars]; - u.dz = zdir[dp - Cmd.dirchars]; -#if 0 /* now handled elsewhere */ + u.dz = 0; + if (!dp) + return 0; + u.dx = xdir[dp - Cmd.dirchars]; + u.dy = ydir[dp - Cmd.dirchars]; + u.dz = zdir[dp - Cmd.dirchars]; +#if 0 /* now handled elsewhere */ if (u.dx && u.dy && NODIAG(u.umonnum)) { u.dx = u.dy = 0; return 0; } #endif - return !u.dz; + return !u.dz; } /* grid bug handling which used to be in movecmd() */ int dxdy_moveok() { - if (u.dx && u.dy && NODIAG(u.umonnum)) u.dx = u.dy = 0; - return u.dx || u.dy; + if (u.dx && u.dy && NODIAG(u.umonnum)) + u.dx = u.dy = 0; + return u.dx || u.dy; } -/* decide whether a character (user input keystroke) requests screen repaint */ +/* decide whether a character (user input keystroke) requests screen repaint + */ boolean redraw_cmd(c) char c; @@ -3250,72 +3491,78 @@ char c; * * Returns non-zero if coordinates in cc are valid. */ -int get_adjacent_loc(prompt,emsg,x,y,cc) +int +get_adjacent_loc(prompt, emsg, x, y, cc) const char *prompt, *emsg; -xchar x,y; +xchar x, y; coord *cc; { - xchar new_x, new_y; - if (!getdir(prompt)) { - pline1(Never_mind); - return 0; - } - new_x = x + u.dx; - new_y = y + u.dy; - if (cc && isok(new_x,new_y)) { - cc->x = new_x; - cc->y = new_y; - } else { - if (emsg) pline1(emsg); - return 0; - } - return 1; + xchar new_x, new_y; + if (!getdir(prompt)) { + pline1(Never_mind); + return 0; + } + new_x = x + u.dx; + new_y = y + u.dy; + if (cc && isok(new_x, new_y)) { + cc->x = new_x; + cc->y = new_y; + } else { + if (emsg) + pline1(emsg); + return 0; + } + return 1; } int getdir(s) const char *s; { - char dirsym; - int is_mov; + char dirsym; + int is_mov; - retry: - if (in_doagain || *readchar_queue) - dirsym = readchar(); - else - dirsym = yn_function((s && *s != '^') ? s : "In what direction?", - (char *)0, '\0'); - /* remove the prompt string so caller won't have to */ - clear_nhwindow(WIN_MESSAGE); +retry: + if (in_doagain || *readchar_queue) + dirsym = readchar(); + else + dirsym = yn_function((s && *s != '^') ? s : "In what direction?", + (char *) 0, '\0'); + /* remove the prompt string so caller won't have to */ + clear_nhwindow(WIN_MESSAGE); - if (redraw_cmd(dirsym)) { /* ^R */ - docrt(); /* redraw */ - goto retry; - } - savech(dirsym); + if (redraw_cmd(dirsym)) { /* ^R */ + docrt(); /* redraw */ + goto retry; + } + savech(dirsym); - if (dirsym == '.' || dirsym == 's') { - u.dx = u.dy = u.dz = 0; - } else if (!(is_mov = movecmd(dirsym)) && !u.dz) { - boolean did_help = FALSE, help_requested; + if (dirsym == '.' || dirsym == 's') { + u.dx = u.dy = u.dz = 0; + } else if (!(is_mov = movecmd(dirsym)) && !u.dz) { + boolean did_help = FALSE, help_requested; - if (!index(quitchars, dirsym)) { - help_requested = (dirsym == '?'); - if (help_requested || iflags.cmdassist) { - did_help = help_dir((s && *s == '^') ? dirsym : 0, - help_requested ? (const char *)0 : - "Invalid direction key!"); - if (help_requested) goto retry; - } - if (!did_help) pline("What a strange direction!"); - } - return 0; - } else if (is_mov && !dxdy_moveok()) { - You_cant("orient yourself that direction."); - return 0; - } - if (!u.dz && (Stunned || (Confusion && !rn2(5)))) confdir(); - return 1; + if (!index(quitchars, dirsym)) { + help_requested = (dirsym == '?'); + if (help_requested || iflags.cmdassist) { + did_help = + help_dir((s && *s == '^') ? dirsym : 0, + help_requested ? (const char *) 0 + : "Invalid direction key!"); + if (help_requested) + goto retry; + } + if (!did_help) + pline("What a strange direction!"); + } + return 0; + } else if (is_mov && !dxdy_moveok()) { + You_cant("orient yourself that direction."); + return 0; + } + if (!u.dz && (Stunned || (Confusion && !rn2(5)))) + confdir(); + return 1; } STATIC_OVL boolean @@ -3323,105 +3570,107 @@ help_dir(sym, msg) char sym; const char *msg; { - char ctrl; - winid win; - static const char wiz_only_list[] = "EFGIOVW"; - char buf[BUFSZ], buf2[BUFSZ], *explain; + char ctrl; + winid win; + static const char wiz_only_list[] = "EFGIOVW"; + char buf[BUFSZ], buf2[BUFSZ], *explain; - win = create_nhwindow(NHW_TEXT); - if (!win) return FALSE; - if (msg) { - Sprintf(buf, "cmdassist: %s", msg); - putstr(win, 0, buf); - putstr(win, 0, ""); - } - if (letter(sym)) { - sym = highc(sym); - ctrl = (sym - 'A') + 1; - if ((explain = dowhatdoes_core(ctrl, buf2)) - && (!index(wiz_only_list, sym) || wizard)) { - Sprintf(buf, "Are you trying to use ^%c%s?", sym, - index(wiz_only_list, sym) ? "" : - " as specified in the Guidebook"); - putstr(win, 0, buf); - putstr(win, 0, ""); - putstr(win, 0, explain); - putstr(win, 0, ""); - putstr(win, 0, "To use that command, you press"); - Sprintf(buf, - "the key, and the <%c> key at the same time.", sym); - putstr(win, 0, buf); - putstr(win, 0, ""); - } - } - if (NODIAG(u.umonnum)) { - putstr(win, 0, "Valid direction keys in your current form are:"); - Sprintf(buf, " %c ", Cmd.move_N); - putstr(win, 0, buf); - putstr(win, 0, " | "); - Sprintf(buf, " %c- . -%c", Cmd.move_W, Cmd.move_E); - putstr(win, 0, buf); - putstr(win, 0, " | "); - Sprintf(buf, " %c ", Cmd.move_S); - putstr(win, 0, buf); - } else { - putstr(win, 0, "Valid direction keys are:"); - Sprintf(buf, " %c %c %c", - Cmd.move_NW, Cmd.move_N, Cmd.move_NE); - putstr(win, 0, buf); - putstr(win, 0, " \\ | / "); - Sprintf(buf, " %c- . -%c", Cmd.move_W, Cmd.move_E); - putstr(win, 0, buf); - putstr(win, 0, " / | \\ "); - Sprintf(buf, " %c %c %c", - Cmd.move_SW, Cmd.move_S, Cmd.move_SE); - putstr(win, 0, buf); - }; - putstr(win, 0, ""); - putstr(win, 0, " < up"); - putstr(win, 0, " > down"); - putstr(win, 0, " . direct at yourself"); - if (msg) { - /* non-null msg means that this wasn't an explicit user request */ - putstr(win, 0, ""); - putstr(win, 0, - "(Suppress this message with !cmdassist in config file.)"); - } - display_nhwindow(win, FALSE); - destroy_nhwindow(win); - return TRUE; + win = create_nhwindow(NHW_TEXT); + if (!win) + return FALSE; + if (msg) { + Sprintf(buf, "cmdassist: %s", msg); + putstr(win, 0, buf); + putstr(win, 0, ""); + } + if (letter(sym)) { + sym = highc(sym); + ctrl = (sym - 'A') + 1; + if ((explain = dowhatdoes_core(ctrl, buf2)) + && (!index(wiz_only_list, sym) || wizard)) { + Sprintf(buf, "Are you trying to use ^%c%s?", sym, + index(wiz_only_list, sym) + ? "" + : " as specified in the Guidebook"); + putstr(win, 0, buf); + putstr(win, 0, ""); + putstr(win, 0, explain); + putstr(win, 0, ""); + putstr(win, 0, "To use that command, you press"); + Sprintf(buf, "the key, and the <%c> key at the same time.", + sym); + putstr(win, 0, buf); + putstr(win, 0, ""); + } + } + if (NODIAG(u.umonnum)) { + putstr(win, 0, "Valid direction keys in your current form are:"); + Sprintf(buf, " %c ", Cmd.move_N); + putstr(win, 0, buf); + putstr(win, 0, " | "); + Sprintf(buf, " %c- . -%c", Cmd.move_W, Cmd.move_E); + putstr(win, 0, buf); + putstr(win, 0, " | "); + Sprintf(buf, " %c ", Cmd.move_S); + putstr(win, 0, buf); + } else { + putstr(win, 0, "Valid direction keys are:"); + Sprintf(buf, " %c %c %c", Cmd.move_NW, Cmd.move_N, + Cmd.move_NE); + putstr(win, 0, buf); + putstr(win, 0, " \\ | / "); + Sprintf(buf, " %c- . -%c", Cmd.move_W, Cmd.move_E); + putstr(win, 0, buf); + putstr(win, 0, " / | \\ "); + Sprintf(buf, " %c %c %c", Cmd.move_SW, Cmd.move_S, + Cmd.move_SE); + putstr(win, 0, buf); + }; + putstr(win, 0, ""); + putstr(win, 0, " < up"); + putstr(win, 0, " > down"); + putstr(win, 0, " . direct at yourself"); + if (msg) { + /* non-null msg means that this wasn't an explicit user request */ + putstr(win, 0, ""); + putstr(win, 0, + "(Suppress this message with !cmdassist in config file.)"); + } + display_nhwindow(win, FALSE); + destroy_nhwindow(win); + return TRUE; } void confdir() { - register int x = NODIAG(u.umonnum) ? 2*rn2(4) : rn2(8); + register int x = NODIAG(u.umonnum) ? 2 * rn2(4) : rn2(8); - u.dx = xdir[x]; - u.dy = ydir[x]; - return; + u.dx = xdir[x]; + u.dy = ydir[x]; + return; } const char * directionname(dir) int dir; { - static NEARDATA const char * const dirnames[] = { - "west", "northwest", "north", "northeast", - "east", "southeast", "south", "southwest", - "down", "up", - }; + static NEARDATA const char *const dirnames[] = { + "west", "northwest", "north", "northeast", "east", + "southeast", "south", "southwest", "down", "up", + }; - if (dir < 0 || dir >= SIZE(dirnames)) return "invalid"; - return dirnames[dir]; + if (dir < 0 || dir >= SIZE(dirnames)) + return "invalid"; + return dirnames[dir]; } int -isok(x,y) +isok(x, y) register int x, y; { - /* x corresponds to curx, so x==1 is the first column. Ach. %% */ - return x >= 1 && x <= COLNO-1 && y >= 0 && y <= ROWNO-1; + /* x corresponds to curx, so x==1 is the first column. Ach. %% */ + return x >= 1 && x <= COLNO - 1 && y >= 0 && y <= ROWNO - 1; } static NEARDATA int last_multi; @@ -3431,50 +3680,54 @@ static NEARDATA int last_multi; */ const char * click_to_cmd(x, y, mod) - int x, y, mod; +int x, y, mod; { int dir; static char cmd[4]; - cmd[1]=0; + cmd[1] = 0; if (iflags.clicklook && mod == CLICK_2) { - clicklook_cc.x = x; - clicklook_cc.y = y; - cmd[0] = CMD_CLICKLOOK; - return cmd; + clicklook_cc.x = x; + clicklook_cc.y = y; + cmd[0] = CMD_CLICKLOOK; + return cmd; } x -= u.ux; y -= u.uy; if (flags.travelcmd) { - if (abs(x) <= 1 && abs(y) <= 1 ) { + if (abs(x) <= 1 && abs(y) <= 1) { x = sgn(x), y = sgn(y); } else { - u.tx = u.ux+x; - u.ty = u.uy+y; + u.tx = u.ux + x; + u.ty = u.uy + y; cmd[0] = CMD_TRAVEL; return cmd; } - if(x == 0 && y == 0) { + if (x == 0 && y == 0) { /* here */ - if(IS_FOUNTAIN(levl[u.ux][u.uy].typ) || IS_SINK(levl[u.ux][u.uy].typ)) { - cmd[0]=mod == CLICK_1 ? 'q' : M('d'); + if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) + || IS_SINK(levl[u.ux][u.uy].typ)) { + cmd[0] = mod == CLICK_1 ? 'q' : M('d'); return cmd; - } else if(IS_THRONE(levl[u.ux][u.uy].typ)) { - cmd[0]=M('s'); + } else if (IS_THRONE(levl[u.ux][u.uy].typ)) { + cmd[0] = M('s'); return cmd; - } else if((u.ux == xupstair && u.uy == yupstair) - || (u.ux == sstairs.sx && u.uy == sstairs.sy && sstairs.up) - || (u.ux == xupladder && u.uy == yupladder)) { + } else if ((u.ux == xupstair && u.uy == yupstair) + || (u.ux == sstairs.sx && u.uy == sstairs.sy + && sstairs.up) + || (u.ux == xupladder && u.uy == yupladder)) { return "<"; - } else if((u.ux == xdnstair && u.uy == ydnstair) - || (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up) - || (u.ux == xdnladder && u.uy == ydnladder)) { + } else if ((u.ux == xdnstair && u.uy == ydnstair) + || (u.ux == sstairs.sx && u.uy == sstairs.sy + && !sstairs.up) + || (u.ux == xdnladder && u.uy == ydnladder)) { return ">"; - } else if(OBJ_AT(u.ux, u.uy)) { - cmd[0] = Is_container(level.objects[u.ux][u.uy]) ? M('l') : ','; + } else if (OBJ_AT(u.ux, u.uy)) { + cmd[0] = + Is_container(level.objects[u.ux][u.uy]) ? M('l') : ','; return cmd; } else { return "."; /* just rest */ @@ -3485,21 +3738,23 @@ click_to_cmd(x, y, mod) dir = xytod(x, y); - if (!m_at(u.ux+x, u.uy+y) && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) { - cmd[1] = Cmd.dirchars[dir]; - cmd[2] = '\0'; - if (IS_DOOR(levl[u.ux+x][u.uy+y].typ)) { - /* slight assistance to the player: choose kick/open for them */ - if (levl[u.ux+x][u.uy+y].doormask & D_LOCKED) { + if (!m_at(u.ux + x, u.uy + y) + && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) { + cmd[1] = Cmd.dirchars[dir]; + cmd[2] = '\0'; + if (IS_DOOR(levl[u.ux + x][u.uy + y].typ)) { + /* slight assistance to the player: choose kick/open for them + */ + if (levl[u.ux + x][u.uy + y].doormask & D_LOCKED) { cmd[0] = C('d'); return cmd; } - if (levl[u.ux+x][u.uy+y].doormask & D_CLOSED) { + if (levl[u.ux + x][u.uy + y].doormask & D_CLOSED) { cmd[0] = 'o'; return cmd; } } - if (levl[u.ux+x][u.uy+y].typ <= SCORR) { + if (levl[u.ux + x][u.uy + y].typ <= SCORR) { cmd[0] = 's'; cmd[1] = 0; return cmd; @@ -3507,18 +3762,18 @@ click_to_cmd(x, y, mod) } } else { /* convert without using floating point, allowing sloppy clicking */ - if(x > 2*abs(y)) + if (x > 2 * abs(y)) x = 1, y = 0; - else if(y > 2*abs(x)) + else if (y > 2 * abs(x)) x = 0, y = 1; - else if(x < -2*abs(y)) + else if (x < -2 * abs(y)) x = -1, y = 0; - else if(y < -2*abs(x)) + else if (y < -2 * abs(x)) x = 0, y = -1; else x = sgn(x), y = sgn(y); - if(x == 0 && y == 0) /* map click on player to "rest" command */ + if (x == 0 && y == 0) /* map click on player to "rest" command */ return "."; dir = xytod(x, y); @@ -3526,11 +3781,12 @@ click_to_cmd(x, y, mod) /* move, attack, etc. */ cmd[1] = 0; - if(mod == CLICK_1) { - cmd[0] = Cmd.dirchars[dir]; + if (mod == CLICK_1) { + cmd[0] = Cmd.dirchars[dir]; } else { - cmd[0] = (Cmd.num_pad ? M(Cmd.dirchars[dir]) : - (Cmd.dirchars[dir] - 'a' + 'A')); /* run command */ + cmd[0] = + (Cmd.num_pad ? M(Cmd.dirchars[dir]) + : (Cmd.dirchars[dir] - 'a' + 'A')); /* run command */ } return cmd; @@ -3539,84 +3795,95 @@ click_to_cmd(x, y, mod) STATIC_OVL char * parse() { -#ifdef LINT /* static char in_line[COLNO]; */ - char in_line[COLNO]; +#ifdef LINT /* static char in_line[COLNO]; */ + char in_line[COLNO]; #else - static char in_line[COLNO]; + static char in_line[COLNO]; #endif - register int foo; - boolean prezero = FALSE; + register int foo; + boolean prezero = FALSE; - multi = 0; - context.move = 1; - flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */ + multi = 0; + context.move = 1; + flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */ #ifdef ALTMETA - alt_esc = iflags.altmeta; /* readchar() hack */ + alt_esc = iflags.altmeta; /* readchar() hack */ #endif - if (!Cmd.num_pad || (foo = readchar()) == 'n') - for (;;) { - foo = readchar(); - if (foo >= '0' && foo <= '9') { - multi = 10 * multi + foo - '0'; - if (multi < 0 || multi >= LARGEST_INT) multi = LARGEST_INT; - if (multi > 9) { - clear_nhwindow(WIN_MESSAGE); - Sprintf(in_line, "Count: %d", multi); - pline1(in_line); - mark_synch(); - } - last_multi = multi; - if (!multi && foo == '0') prezero = TRUE; - } else break; /* not a digit */ - } + if (!Cmd.num_pad || (foo = readchar()) == 'n') + for (;;) { + foo = readchar(); + if (foo >= '0' && foo <= '9') { + multi = 10 * multi + foo - '0'; + if (multi < 0 || multi >= LARGEST_INT) + multi = LARGEST_INT; + if (multi > 9) { + clear_nhwindow(WIN_MESSAGE); + Sprintf(in_line, "Count: %d", multi); + pline1(in_line); + mark_synch(); + } + last_multi = multi; + if (!multi && foo == '0') + prezero = TRUE; + } else + break; /* not a digit */ + } #ifdef ALTMETA - alt_esc = FALSE; /* readchar() reset */ + alt_esc = FALSE; /* readchar() reset */ #endif - if (foo == '\033') { /* esc cancels count (TH) */ - clear_nhwindow(WIN_MESSAGE); - multi = last_multi = 0; - } else if (foo == DOAGAIN || in_doagain) { - multi = last_multi; - } else { - last_multi = multi; - savech(0); /* reset input queue */ - savech((char)foo); - } + if (foo == '\033') { /* esc cancels count (TH) */ + clear_nhwindow(WIN_MESSAGE); + multi = last_multi = 0; + } else if (foo == DOAGAIN || in_doagain) { + multi = last_multi; + } else { + last_multi = multi; + savech(0); /* reset input queue */ + savech((char) foo); + } - if (multi) { - multi--; - save_cm = in_line; - } else { - save_cm = (char *)0; - } - /* in 3.4.3 this was in rhack(), where it was too late to handle M-5 */ - if (Cmd.pcHack_compat) { - /* This handles very old inconsistent DOS/Windows behaviour - in a different way: earlier, the keyboard handler mapped - these, which caused counts to be strange when entered - from the number pad. Now do not map them until here. */ - switch (foo) { - case '5': foo = 'g'; break; - case M('5'): foo = 'G'; break; - case M('0'): foo = 'I'; break; - default: break; /* as is */ - } - } + if (multi) { + multi--; + save_cm = in_line; + } else { + save_cm = (char *) 0; + } + /* in 3.4.3 this was in rhack(), where it was too late to handle M-5 */ + if (Cmd.pcHack_compat) { + /* This handles very old inconsistent DOS/Windows behaviour + in a different way: earlier, the keyboard handler mapped + these, which caused counts to be strange when entered + from the number pad. Now do not map them until here. */ + switch (foo) { + case '5': + foo = 'g'; + break; + case M('5'): + foo = 'G'; + break; + case M('0'): + foo = 'I'; + break; + default: + break; /* as is */ + } + } - in_line[0] = foo; - in_line[1] = '\0'; - if (foo == 'g' || foo == 'G' || foo == 'm' || foo == 'M' || - foo == 'F' || (Cmd.num_pad && (foo == '5' || foo == '-'))) { - foo = readchar(); - savech((char)foo); - in_line[1] = foo; - in_line[2] = 0; - } - clear_nhwindow(WIN_MESSAGE); - if (prezero) in_line[0] = '\033'; - return(in_line); + in_line[0] = foo; + in_line[1] = '\0'; + if (foo == 'g' || foo == 'G' || foo == 'm' || foo == 'M' || foo == 'F' + || (Cmd.num_pad && (foo == '5' || foo == '-'))) { + foo = readchar(); + savech((char) foo); + in_line[1] = foo; + in_line[2] = 0; + } + clear_nhwindow(WIN_MESSAGE); + if (prezero) + in_line[0] = '\033'; + return (in_line); } #ifdef HANGUPHANDLING @@ -3628,120 +3895,124 @@ void hangup(sig_unused) /* called as signal() handler, so sent at least one arg */ int sig_unused UNUSED; { - if (program_state.exiting) program_state.in_moveloop = 0; - nhwindows_hangup(); -# ifdef SAFERHANGUP - /* When using SAFERHANGUP, the done_hup flag it tested in rhack - and a couple of other places; actual hangup handling occurs then. - This is 'safer' because it disallows certain cheats and also - protects against losing objects in the process of being thrown, - but also potentially riskier because the disconnected program - must continue running longer before attempting a hangup save. */ - program_state.done_hup++; - /* defer hangup iff game appears to be in progress */ - if (program_state.in_moveloop && program_state.something_worth_saving) - return; -# endif /* SAFERHANGUP */ - end_of_input(); + if (program_state.exiting) + program_state.in_moveloop = 0; + nhwindows_hangup(); +#ifdef SAFERHANGUP + /* When using SAFERHANGUP, the done_hup flag it tested in rhack + and a couple of other places; actual hangup handling occurs then. + This is 'safer' because it disallows certain cheats and also + protects against losing objects in the process of being thrown, + but also potentially riskier because the disconnected program + must continue running longer before attempting a hangup save. */ + program_state.done_hup++; + /* defer hangup iff game appears to be in progress */ + if (program_state.in_moveloop && program_state.something_worth_saving) + return; +#endif /* SAFERHANGUP */ + end_of_input(); } void end_of_input() { -# ifdef NOSAVEONHANGUP -# ifdef INSURANCE - if (flags.ins_chkpt && program_state.something_worth_saving) - program_statue.preserve_locks = 1; /* keep files for recovery */ -# endif - program_state.something_worth_saving = 0; /* don't save */ -# endif +#ifdef NOSAVEONHANGUP +#ifdef INSURANCE + if (flags.ins_chkpt && program_state.something_worth_saving) + program_statue.preserve_locks = 1; /* keep files for recovery */ +#endif + program_state.something_worth_saving = 0; /* don't save */ +#endif -# ifndef SAFERHANGUP - if (!program_state.done_hup++) -# endif - if (program_state.something_worth_saving) (void) dosave0(); - if (iflags.window_inited) exit_nhwindows((char *)0); - clearlocks(); - terminate(EXIT_SUCCESS); - /*NOTREACHED*/ /* not necessarily true for vms... */ - return; +#ifndef SAFERHANGUP + if (!program_state.done_hup++) +#endif + if (program_state.something_worth_saving) + (void) dosave0(); + if (iflags.window_inited) + exit_nhwindows((char *) 0); + clearlocks(); + terminate(EXIT_SUCCESS); + /*NOTREACHED*/ /* not necessarily true for vms... */ + return; } #endif /* HANGUPHANDLING */ char readchar() { - register int sym; - int x = u.ux, y = u.uy, mod = 0; + register int sym; + int x = u.ux, y = u.uy, mod = 0; - if ( *readchar_queue ) - sym = *readchar_queue++; - else - sym = in_doagain ? pgetchar() : nh_poskey(&x, &y, &mod); + if (*readchar_queue) + sym = *readchar_queue++; + else + sym = in_doagain ? pgetchar() : nh_poskey(&x, &y, &mod); #ifdef NR_OF_EOFS - if (sym == EOF) { - register int cnt = NR_OF_EOFS; - /* - * Some SYSV systems seem to return EOFs for various reasons - * (?like when one hits break or for interrupted systemcalls?), - * and we must see several before we quit. - */ - do { - clearerr(stdin); /* omit if clearerr is undefined */ - sym = pgetchar(); - } while (--cnt && sym == EOF); - } + if (sym == EOF) { + register int cnt = NR_OF_EOFS; + /* + * Some SYSV systems seem to return EOFs for various reasons + * (?like when one hits break or for interrupted systemcalls?), + * and we must see several before we quit. + */ + do { + clearerr(stdin); /* omit if clearerr is undefined */ + sym = pgetchar(); + } while (--cnt && sym == EOF); + } #endif /* NR_OF_EOFS */ - if (sym == EOF) { + if (sym == EOF) { #ifdef HANGUPHANDLING - hangup(0); /* call end_of_input() or set program_state.done_hup */ + hangup(0); /* call end_of_input() or set program_state.done_hup */ #endif - sym = '\033'; + sym = '\033'; #ifdef ALTMETA - } else if (sym == '\033' && alt_esc) { - /* iflags.altmeta: treat two character ``ESC c'' as single `M-c' */ - sym = *readchar_queue ? *readchar_queue++ : pgetchar(); - if (sym == EOF || sym == 0) - sym = '\033'; - else if (sym != '\033') - sym |= 0200; /* force 8th bit on */ -#endif /*ALTMETA*/ - } else if (sym == 0) { - /* click event */ - readchar_queue = click_to_cmd(x, y, mod); - sym = *readchar_queue++; - } - return((char) sym); + } else if (sym == '\033' && alt_esc) { + /* iflags.altmeta: treat two character ``ESC c'' as single `M-c' */ + sym = *readchar_queue ? *readchar_queue++ : pgetchar(); + if (sym == EOF || sym == 0) + sym = '\033'; + else if (sym != '\033') + sym |= 0200; /* force 8th bit on */ +#endif /*ALTMETA*/ + } else if (sym == 0) { + /* click event */ + readchar_queue = click_to_cmd(x, y, mod); + sym = *readchar_queue++; + } + return ((char) sym); } STATIC_PTR int dotravel(VOID_ARGS) { - /* Keyboard travel command */ - static char cmd[2]; - coord cc; + /* Keyboard travel command */ + static char cmd[2]; + coord cc; - if (!flags.travelcmd) return 0; - cmd[1]=0; - cc.x = iflags.travelcc.x; - cc.y = iflags.travelcc.y; - if (cc.x == -1 && cc.y == -1) { - /* No cached destination, start attempt from current position */ - cc.x = u.ux; - cc.y = u.uy; - } - pline("Where do you want to travel to?"); - if (getpos(&cc, TRUE, "the desired destination") < 0) { - /* user pressed ESC */ - return 0; - } - iflags.travelcc.x = u.tx = cc.x; - iflags.travelcc.y = u.ty = cc.y; - cmd[0] = CMD_TRAVEL; - readchar_queue = cmd; - return 0; + if (!flags.travelcmd) + return 0; + cmd[1] = 0; + cc.x = iflags.travelcc.x; + cc.y = iflags.travelcc.y; + if (cc.x == -1 && cc.y == -1) { + /* No cached destination, start attempt from current position */ + cc.x = u.ux; + cc.y = u.uy; + } + pline("Where do you want to travel to?"); + if (getpos(&cc, TRUE, "the desired destination") < 0) { + /* user pressed ESC */ + return 0; + } + iflags.travelcc.x = u.tx = cc.x; + iflags.travelcc.y = u.ty = cc.y; + cmd[0] = CMD_TRAVEL; + readchar_queue = cmd; + return 0; } #ifdef PORT_DEBUG @@ -3751,46 +4022,47 @@ extern void NDECL(win32con_handler_info); int wiz_port_debug() { - int n, k; - winid win; - anything any; - int item = 'a'; - int num_menu_selections; - struct menu_selection_struct { - char *menutext; - void NDECL((*fn)); - } menu_selections[] = { + int n, k; + winid win; + anything any; + int item = 'a'; + int num_menu_selections; + struct menu_selection_struct { + char *menutext; + void NDECL((*fn)); + } menu_selections[] = { #ifdef WIN32 - {"test win32 keystrokes (tty only)", win32con_debug_keystrokes}, - {"show keystroke handler information (tty only)", win32con_handler_info}, + { "test win32 keystrokes (tty only)", win32con_debug_keystrokes }, + { "show keystroke handler information (tty only)", + win32con_handler_info }, #endif - {(char *)0, (void NDECL((*)))0} /* array terminator */ - }; + { (char *) 0, (void NDECL((*) )) 0 } /* array terminator */ + }; - num_menu_selections = SIZE(menu_selections) - 1; - if (num_menu_selections > 0) { - menu_item *pick_list; - win = create_nhwindow(NHW_MENU); - start_menu(win); - for (k=0; k < num_menu_selections; ++k) { - any.a_int = k+1; - add_menu(win, NO_GLYPH, &any, item++, 0, ATR_NONE, - menu_selections[k].menutext, MENU_UNSELECTED); - } - end_menu(win, "Which port debugging feature?"); - n = select_menu(win, PICK_ONE, &pick_list); - destroy_nhwindow(win); - if (n > 0) { - n = pick_list[0].item.a_int - 1; - free((genericptr_t) pick_list); - /* execute the function */ - (*menu_selections[n].fn)(); - } - } else - pline("No port-specific debug capability defined."); - return 0; + num_menu_selections = SIZE(menu_selections) - 1; + if (num_menu_selections > 0) { + menu_item *pick_list; + win = create_nhwindow(NHW_MENU); + start_menu(win); + for (k = 0; k < num_menu_selections; ++k) { + any.a_int = k + 1; + add_menu(win, NO_GLYPH, &any, item++, 0, ATR_NONE, + menu_selections[k].menutext, MENU_UNSELECTED); + } + end_menu(win, "Which port debugging feature?"); + n = select_menu(win, PICK_ONE, &pick_list); + destroy_nhwindow(win); + if (n > 0) { + n = pick_list[0].item.a_int - 1; + free((genericptr_t) pick_list); + /* execute the function */ + (*menu_selections[n].fn)(); + } + } else + pline("No port-specific debug capability defined."); + return 0; } -# endif /*PORT_DEBUG*/ +#endif /*PORT_DEBUG*/ /* * Parameter validator for generic yes/no function to prevent @@ -3802,19 +4074,19 @@ yn_function(query, resp, def) const char *query, *resp; char def; { - char qbuf[QBUFSZ]; + char qbuf[QBUFSZ]; - iflags.last_msg = PLNMSG_UNKNOWN; /* most recent pline is clobbered */ + iflags.last_msg = PLNMSG_UNKNOWN; /* most recent pline is clobbered */ - /* maximum acceptable length is QBUFSZ-1 */ - if (strlen(query) < QBUFSZ) - return (*windowprocs.win_yn_function)(query, resp, def); + /* maximum acceptable length is QBUFSZ-1 */ + if (strlen(query) < QBUFSZ) + return (*windowprocs.win_yn_function)(query, resp, def); - /* caller shouldn't have passed anything this long */ - paniclog("Query truncated: ", query); - (void) strncpy(qbuf, query, QBUFSZ-1 - 3); - Strcpy(&qbuf[QBUFSZ-1 - 3], "..."); - return (*windowprocs.win_yn_function)(qbuf, resp, def); + /* caller shouldn't have passed anything this long */ + paniclog("Query truncated: ", query); + (void) strncpy(qbuf, query, QBUFSZ - 1 - 3); + Strcpy(&qbuf[QBUFSZ - 1 - 3], "..."); + return (*windowprocs.win_yn_function)(qbuf, resp, def); } /* for paranoid_confirm:quit,die,attack prompting */ @@ -3823,47 +4095,50 @@ paranoid_query(be_paranoid, prompt) boolean be_paranoid; const char *prompt; { - boolean confirmed_ok; + boolean confirmed_ok; - /* when paranoid, player must respond with "yes" rather than just 'y' - to give the go-ahead for this query; default is "no" unless the - ParanoidConfirm flag is set in which case there's no default */ - if (be_paranoid) { - char qbuf[QBUFSZ], ans[BUFSZ]; - const char *promptprefix = "", - *responsetype = ParanoidConfirm ? "(yes|no)" : "(yes) [no]"; - int trylimit = 6; /* 1 normal, 5 more with "Yes or No:" prefix */ + /* when paranoid, player must respond with "yes" rather than just 'y' + to give the go-ahead for this query; default is "no" unless the + ParanoidConfirm flag is set in which case there's no default */ + if (be_paranoid) { + char qbuf[QBUFSZ], ans[BUFSZ]; + const char *promptprefix = "", *responsetype = ParanoidConfirm + ? "(yes|no)" + : "(yes) [no]"; + int trylimit = 6; /* 1 normal, 5 more with "Yes or No:" prefix */ - /* in addition to being paranoid about this particular - query, we might be even more paranoid about all paranoia - responses (ie, ParanoidConfirm is set) in which case we - require "no" to reject in addition to "yes" to confirm - (except we won't loop if respose is ESC; it means no) */ - do { - Sprintf(qbuf, "%s%s %s", promptprefix, prompt, responsetype); - getlin(qbuf, ans); - (void) mungspaces(ans); - confirmed_ok = !strcmpi(ans, "yes"); - if (confirmed_ok || *ans == '\033') break; - promptprefix = "\"Yes\" or \"No\": "; - } while (ParanoidConfirm && strcmpi(ans, "no") && --trylimit); - } else - confirmed_ok = (yn(prompt) == 'y'); + /* in addition to being paranoid about this particular + query, we might be even more paranoid about all paranoia + responses (ie, ParanoidConfirm is set) in which case we + require "no" to reject in addition to "yes" to confirm + (except we won't loop if respose is ESC; it means no) */ + do { + Sprintf(qbuf, "%s%s %s", promptprefix, prompt, responsetype); + getlin(qbuf, ans); + (void) mungspaces(ans); + confirmed_ok = !strcmpi(ans, "yes"); + if (confirmed_ok || *ans == '\033') + break; + promptprefix = "\"Yes\" or \"No\": "; + } while (ParanoidConfirm && strcmpi(ans, "no") && --trylimit); + } else + confirmed_ok = (yn(prompt) == 'y'); - return confirmed_ok; + return confirmed_ok; } int -dosuspend_core(){ +dosuspend_core() +{ #ifdef SUSPEND - /* Does current window system support suspend? */ - if( (*windowprocs.win_can_suspend)()){ - /* NB: SYSCF SHELLERS handled in port code. */ - dosuspend(); - } else + /* Does current window system support suspend? */ + if ((*windowprocs.win_can_suspend)()) { + /* NB: SYSCF SHELLERS handled in port code. */ + dosuspend(); + } else #endif - Norep("Suspend command not available."); - return 0; + Norep("Suspend command not available."); + return 0; } /*cmd.c*/ diff --git a/src/dbridge.c b/src/dbridge.c index f82463a1f..19dcc1c20 100644 --- a/src/dbridge.c +++ b/src/dbridge.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dbridge.c $NHDT-Date: 1426465433 2015/03/16 00:23:53 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.23 $ */ +/* NetHack 3.6 dbridge.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.31 $ */ /* NetHack 3.6 dbridge.c $Date: 2012/02/01 00:49:16 $ $Revision: 1.21 $ */ /* Copyright (c) 1989 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -35,12 +35,13 @@ STATIC_DCL boolean FDECL(e_jumps, (struct entity *)); STATIC_DCL void FDECL(do_entity, (struct entity *)); boolean -is_pool(x,y) -int x,y; +is_pool(x, y) +int x, y; { schar ltyp; - if (!isok(x,y)) return FALSE; + if (!isok(x, y)) + return FALSE; ltyp = levl[x][y].typ; /* The ltyp == MOAT is not redundant with is_moat, because the * Juiblex level does not have moats, although it has MOATs. There @@ -51,54 +52,59 @@ int x,y; } boolean -is_lava(x,y) -int x,y; -{ - schar ltyp; - - if (!isok(x,y)) return FALSE; - ltyp = levl[x][y].typ; - if (ltyp == LAVAPOOL - || (ltyp == DRAWBRIDGE_UP - && (levl[x][y].drawbridgemask & DB_UNDER) == DB_LAVA)) return TRUE; - return FALSE; -} - -boolean -is_pool_or_lava(x,y) -int x,y; -{ - if (is_pool(x,y) || is_lava(x,y)) - return TRUE; - else - return FALSE; -} - -boolean -is_ice(x,y) -int x,y; -{ - schar ltyp; - - if (!isok(x,y)) return FALSE; - ltyp = levl[x][y].typ; - if (ltyp == ICE - || (ltyp == DRAWBRIDGE_UP - && (levl[x][y].drawbridgemask & DB_UNDER) == DB_ICE)) return TRUE; - return FALSE; -} - -boolean -is_moat(x,y) +is_lava(x, y) int x, y; { schar ltyp; - if (!isok(x, y)) return FALSE; + if (!isok(x, y)) + return FALSE; ltyp = levl[x][y].typ; - if (!Is_juiblex_level(&u.uz) && - (ltyp == MOAT || (ltyp == DRAWBRIDGE_UP && - (levl[x][y].drawbridgemask & DB_UNDER) == DB_MOAT))) + if (ltyp == LAVAPOOL + || (ltyp == DRAWBRIDGE_UP + && (levl[x][y].drawbridgemask & DB_UNDER) == DB_LAVA)) + return TRUE; + return FALSE; +} + +boolean +is_pool_or_lava(x, y) +int x, y; +{ + if (is_pool(x, y) || is_lava(x, y)) + return TRUE; + else + return FALSE; +} + +boolean +is_ice(x, y) +int x, y; +{ + schar ltyp; + + if (!isok(x, y)) + return FALSE; + ltyp = levl[x][y].typ; + if (ltyp == ICE || (ltyp == DRAWBRIDGE_UP + && (levl[x][y].drawbridgemask & DB_UNDER) == DB_ICE)) + return TRUE; + return FALSE; +} + +boolean +is_moat(x, y) +int x, y; +{ + schar ltyp; + + if (!isok(x, y)) + return FALSE; + ltyp = levl[x][y].typ; + if (!Is_juiblex_level(&u.uz) + && (ltyp == MOAT + || (ltyp == DRAWBRIDGE_UP + && (levl[x][y].drawbridgemask & DB_UNDER) == DB_MOAT))) return TRUE; return FALSE; } @@ -108,10 +114,18 @@ db_under_typ(mask) int mask; { switch (mask & DB_UNDER) { - case DB_ICE: return ICE; break; - case DB_LAVA: return LAVAPOOL; break; - case DB_MOAT: return MOAT; break; - default: return STONE; break; + case DB_ICE: + return ICE; + break; + case DB_LAVA: + return LAVAPOOL; + break; + case DB_MOAT: + return MOAT; + break; + default: + return STONE; + break; } } @@ -123,29 +137,29 @@ int mask; */ int -is_drawbridge_wall(x,y) -int x,y; +is_drawbridge_wall(x, y) +int x, y; { - struct rm *lev; + struct rm *lev; - lev = &levl[x][y]; - if (lev->typ != DOOR && lev->typ != DBWALL) - return (-1); + lev = &levl[x][y]; + if (lev->typ != DOOR && lev->typ != DBWALL) + return (-1); - if (IS_DRAWBRIDGE(levl[x+1][y].typ) && - (levl[x+1][y].drawbridgemask & DB_DIR) == DB_WEST) - return (DB_WEST); - if (IS_DRAWBRIDGE(levl[x-1][y].typ) && - (levl[x-1][y].drawbridgemask & DB_DIR) == DB_EAST) - return (DB_EAST); - if (IS_DRAWBRIDGE(levl[x][y-1].typ) && - (levl[x][y-1].drawbridgemask & DB_DIR) == DB_SOUTH) - return (DB_SOUTH); - if (IS_DRAWBRIDGE(levl[x][y+1].typ) && - (levl[x][y+1].drawbridgemask & DB_DIR) == DB_NORTH) - return (DB_NORTH); + if (IS_DRAWBRIDGE(levl[x + 1][y].typ) + && (levl[x + 1][y].drawbridgemask & DB_DIR) == DB_WEST) + return (DB_WEST); + if (IS_DRAWBRIDGE(levl[x - 1][y].typ) + && (levl[x - 1][y].drawbridgemask & DB_DIR) == DB_EAST) + return (DB_EAST); + if (IS_DRAWBRIDGE(levl[x][y - 1].typ) + && (levl[x][y - 1].drawbridgemask & DB_DIR) == DB_SOUTH) + return (DB_SOUTH); + if (IS_DRAWBRIDGE(levl[x][y + 1].typ) + && (levl[x][y + 1].drawbridgemask & DB_DIR) == DB_NORTH) + return (DB_NORTH); - return (-1); + return (-1); } /* @@ -154,51 +168,66 @@ int x,y; * (instead of UP or DOWN, as with is_drawbridge_wall). */ boolean -is_db_wall(x,y) -int x,y; +is_db_wall(x, y) +int x, y; { - return((boolean)( levl[x][y].typ == DBWALL )); + return ((boolean)(levl[x][y].typ == DBWALL)); } - /* * Return true with x,y pointing to the drawbridge if x,y initially indicate * a drawbridge or drawbridge wall. */ boolean -find_drawbridge(x,y) -int *x,*y; +find_drawbridge(x, y) +int *x, *y; { - int dir; + int dir; - if (IS_DRAWBRIDGE(levl[*x][*y].typ)) - return TRUE; - dir = is_drawbridge_wall(*x,*y); - if (dir >= 0) { - switch(dir) { - case DB_NORTH: (*y)++; break; - case DB_SOUTH: (*y)--; break; - case DB_EAST: (*x)--; break; - case DB_WEST: (*x)++; break; - } - return TRUE; - } - return FALSE; + if (IS_DRAWBRIDGE(levl[*x][*y].typ)) + return TRUE; + dir = is_drawbridge_wall(*x, *y); + if (dir >= 0) { + switch (dir) { + case DB_NORTH: + (*y)++; + break; + case DB_SOUTH: + (*y)--; + break; + case DB_EAST: + (*x)--; + break; + case DB_WEST: + (*x)++; + break; + } + return TRUE; + } + return FALSE; } /* * Find the drawbridge wall associated with a drawbridge. */ STATIC_OVL void -get_wall_for_db(x,y) -int *x,*y; +get_wall_for_db(x, y) +int *x, *y; { - switch (levl[*x][*y].drawbridgemask & DB_DIR) { - case DB_NORTH: (*y)--; break; - case DB_SOUTH: (*y)++; break; - case DB_EAST: (*x)++; break; - case DB_WEST: (*x)--; break; - } + switch (levl[*x][*y].drawbridgemask & DB_DIR) { + case DB_NORTH: + (*y)--; + break; + case DB_SOUTH: + (*y)++; + break; + case DB_EAST: + (*x)++; + break; + case DB_WEST: + (*x)--; + break; + } } /* @@ -208,59 +237,61 @@ int *x,*y; */ boolean -create_drawbridge(x,y,dir,flag) -int x,y,dir; +create_drawbridge(x, y, dir, flag) +int x, y, dir; boolean flag; { - int x2,y2; - boolean horiz; - boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */ + int x2, y2; + boolean horiz; + boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */ - x2 = x; y2 = y; - switch(dir) { - case DB_NORTH: - horiz = TRUE; - y2--; - break; - case DB_SOUTH: - horiz = TRUE; - y2++; - break; - case DB_EAST: - horiz = FALSE; - x2++; - break; - default: - impossible("bad direction in create_drawbridge"); - /* fall through */ - case DB_WEST: - horiz = FALSE; - x2--; - break; - } - if (!IS_WALL(levl[x2][y2].typ)) - return(FALSE); - if (flag) { /* We want the bridge open */ - levl[x][y].typ = DRAWBRIDGE_DOWN; - levl[x2][y2].typ = DOOR; - levl[x2][y2].doormask = D_NODOOR; - } else { - levl[x][y].typ = DRAWBRIDGE_UP; - levl[x2][y2].typ = DBWALL; - /* Drawbridges are non-diggable. */ - levl[x2][y2].wall_info = W_NONDIGGABLE; - } - levl[x][y].horizontal = !horiz; - levl[x2][y2].horizontal = horiz; - levl[x][y].drawbridgemask = dir; - if(lava) levl[x][y].drawbridgemask |= DB_LAVA; - return(TRUE); + x2 = x; + y2 = y; + switch (dir) { + case DB_NORTH: + horiz = TRUE; + y2--; + break; + case DB_SOUTH: + horiz = TRUE; + y2++; + break; + case DB_EAST: + horiz = FALSE; + x2++; + break; + default: + impossible("bad direction in create_drawbridge"); + /* fall through */ + case DB_WEST: + horiz = FALSE; + x2--; + break; + } + if (!IS_WALL(levl[x2][y2].typ)) + return (FALSE); + if (flag) { /* We want the bridge open */ + levl[x][y].typ = DRAWBRIDGE_DOWN; + levl[x2][y2].typ = DOOR; + levl[x2][y2].doormask = D_NODOOR; + } else { + levl[x][y].typ = DRAWBRIDGE_UP; + levl[x2][y2].typ = DBWALL; + /* Drawbridges are non-diggable. */ + levl[x2][y2].wall_info = W_NONDIGGABLE; + } + levl[x][y].horizontal = !horiz; + levl[x2][y2].horizontal = horiz; + levl[x][y].drawbridgemask = dir; + if (lava) + levl[x][y].drawbridgemask |= DB_LAVA; + return (TRUE); } struct entity { - struct monst *emon; /* youmonst for the player */ - struct permonst *edata; /* must be non-zero for record to be valid */ - int ex, ey; + struct monst *emon; /* youmonst for the player */ + struct permonst *edata; /* must be non-zero for record to be valid */ + int ex, ey; }; #define ENTITIES 2 @@ -272,19 +303,18 @@ struct entity * e_at(x, y) int x, y; { - int entitycnt; + int entitycnt; - for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) - if ((occupants[entitycnt].edata) && - (occupants[entitycnt].ex == x) && - (occupants[entitycnt].ey == y)) - break; - debugpline1("entitycnt = %d", entitycnt); + for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) + if ((occupants[entitycnt].edata) && (occupants[entitycnt].ex == x) + && (occupants[entitycnt].ey == y)) + break; + debugpline1("entitycnt = %d", entitycnt); #ifdef D_DEBUG - wait_synch(); + wait_synch(); #endif - return((entitycnt == ENTITIES)? - (struct entity *)0 : &(occupants[entitycnt])); + return ((entitycnt == ENTITIES) ? (struct entity *) 0 + : &(occupants[entitycnt])); } STATIC_OVL void @@ -293,26 +323,26 @@ struct monst *mtmp; int x, y; struct entity *etmp; { - etmp->emon = mtmp; - if (mtmp) { - etmp->ex = x; - etmp->ey = y; - if (mtmp->wormno && (x != mtmp->mx || y != mtmp->my)) - etmp->edata = &mons[PM_LONG_WORM_TAIL]; - else - etmp->edata = mtmp->data; - } else - etmp->edata = (struct permonst *)0; + etmp->emon = mtmp; + if (mtmp) { + etmp->ex = x; + etmp->ey = y; + if (mtmp->wormno && (x != mtmp->mx || y != mtmp->my)) + etmp->edata = &mons[PM_LONG_WORM_TAIL]; + else + etmp->edata = mtmp->data; + } else + etmp->edata = (struct permonst *) 0; } STATIC_OVL void u_to_e(etmp) struct entity *etmp; { - etmp->emon = &youmonst; - etmp->ex = u.ux; - etmp->ey = u.uy; - etmp->edata = youmonst.data; + etmp->emon = &youmonst; + etmp->ex = u.ux; + etmp->ey = u.uy; + etmp->edata = youmonst.data; } STATIC_OVL void @@ -320,16 +350,17 @@ set_entity(x, y, etmp) int x, y; struct entity *etmp; { - if ((x == u.ux) && (y == u.uy)) - u_to_e(etmp); - else if (MON_AT(x, y)) - m_to_e(m_at(x, y), x, y, etmp); - else - etmp->edata = (struct permonst *)0; + if ((x == u.ux) && (y == u.uy)) + u_to_e(etmp); + else if (MON_AT(x, y)) + m_to_e(m_at(x, y), x, y, etmp); + else + etmp->edata = (struct permonst *) 0; } #define is_u(etmp) (etmp->emon == &youmonst) -#define e_canseemon(etmp) (is_u(etmp) ? (boolean)TRUE : canseemon(etmp->emon)) +#define e_canseemon(etmp) \ + (is_u(etmp) ? (boolean) TRUE : canseemon(etmp->emon)) /* * e_strg is a utility routine which is not actually in use anywhere, since @@ -342,7 +373,7 @@ STATIC_OVL const char * e_nam(etmp) struct entity *etmp; { - return(is_u(etmp)? "you" : mon_nam(etmp->emon)); + return (is_u(etmp) ? "you" : mon_nam(etmp->emon)); } /* @@ -355,16 +386,17 @@ E_phrase(etmp, verb) struct entity *etmp; const char *verb; { - static char wholebuf[80]; + static char wholebuf[80]; - Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon)); - if (!*verb) return(wholebuf); - Strcat(wholebuf, " "); - if (is_u(etmp)) - Strcat(wholebuf, verb); - else - Strcat(wholebuf, vtense((char *)0, verb)); - return(wholebuf); + Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon)); + if (!*verb) + return (wholebuf); + Strcat(wholebuf, " "); + if (is_u(etmp)) + Strcat(wholebuf, verb); + else + Strcat(wholebuf, vtense((char *) 0, verb)); + return (wholebuf); } /* @@ -376,22 +408,21 @@ e_survives_at(etmp, x, y) struct entity *etmp; int x, y; { - if (noncorporeal(etmp->edata)) - return(TRUE); - if (is_pool(x, y)) - return (boolean)((is_u(etmp) && - (Wwalking || Amphibious || Swimming || - Flying || Levitation)) || - is_swimmer(etmp->edata) || is_flyer(etmp->edata) || - is_floater(etmp->edata)); - /* must force call to lava_effects in e_died if is_u */ - if (is_lava(x, y)) - return (boolean)((is_u(etmp) && (Levitation || Flying)) || - likes_lava(etmp->edata) || is_flyer(etmp->edata)); - if (is_db_wall(x, y)) - return((boolean)(is_u(etmp) ? Passes_walls : - passes_walls(etmp->edata))); - return(TRUE); + if (noncorporeal(etmp->edata)) + return (TRUE); + if (is_pool(x, y)) + return (boolean)((is_u(etmp) && (Wwalking || Amphibious || Swimming + || Flying || Levitation)) + || is_swimmer(etmp->edata) || is_flyer(etmp->edata) + || is_floater(etmp->edata)); + /* must force call to lava_effects in e_died if is_u */ + if (is_lava(x, y)) + return (boolean)((is_u(etmp) && (Levitation || Flying)) + || likes_lava(etmp->edata) || is_flyer(etmp->edata)); + if (is_db_wall(x, y)) + return ( + (boolean)(is_u(etmp) ? Passes_walls : passes_walls(etmp->edata))); + return (TRUE); } STATIC_OVL void @@ -399,62 +430,61 @@ e_died(etmp, dest, how) struct entity *etmp; int dest, how; { - if (is_u(etmp)) { - if (how == DROWNING) { - killer.name[0] = 0; /* drown() sets its own killer */ - (void) drown(); - } else if (how == BURNING) { - killer.name[0] = 0; /* lava_effects() sets own killer */ - (void) lava_effects(); - } else { - coord xy; + if (is_u(etmp)) { + if (how == DROWNING) { + killer.name[0] = 0; /* drown() sets its own killer */ + (void) drown(); + } else if (how == BURNING) { + killer.name[0] = 0; /* lava_effects() sets own killer */ + (void) lava_effects(); + } else { + coord xy; - /* use more specific killer if specified */ - if (!killer.name[0]) { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "falling drawbridge"); - } - done(how); - /* So, you didn't die */ - if (!e_survives_at(etmp, etmp->ex, etmp->ey)) { - if (enexto(&xy, etmp->ex, etmp->ey, etmp->edata)) { - pline("A %s force teleports you away...", - Hallucination ? "normal" : "strange"); - teleds(xy.x, xy.y, FALSE); - } - /* otherwise on top of the drawbridge is the - * only viable spot in the dungeon, so stay there - */ - } - } - /* we might have crawled out of the moat to survive */ - etmp->ex = u.ux, etmp->ey = u.uy; - } else { - int entitycnt; + /* use more specific killer if specified */ + if (!killer.name[0]) { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "falling drawbridge"); + } + done(how); + /* So, you didn't die */ + if (!e_survives_at(etmp, etmp->ex, etmp->ey)) { + if (enexto(&xy, etmp->ex, etmp->ey, etmp->edata)) { + pline("A %s force teleports you away...", + Hallucination ? "normal" : "strange"); + teleds(xy.x, xy.y, FALSE); + } + /* otherwise on top of the drawbridge is the + * only viable spot in the dungeon, so stay there + */ + } + } + /* we might have crawled out of the moat to survive */ + etmp->ex = u.ux, etmp->ey = u.uy; + } else { + int entitycnt; - killer.name[0] = 0; - /* fake "digested to death" damage-type suppresses corpse */ -#define mk_message(dest) ((dest & 1) ? "" : (char *)0) -#define mk_corpse(dest) ((dest & 2) ? AD_DGST : AD_PHYS) - /* if monsters are moving, one of them caused the destruction */ - if (context.mon_moving) - monkilled(etmp->emon, mk_message(dest), mk_corpse(dest)); - else /* you caused it */ - xkilled(etmp->emon, dest); - etmp->edata = (struct permonst *)0; + killer.name[0] = 0; +/* fake "digested to death" damage-type suppresses corpse */ +#define mk_message(dest) ((dest & 1) ? "" : (char *) 0) +#define mk_corpse(dest) ((dest & 2) ? AD_DGST : AD_PHYS) + /* if monsters are moving, one of them caused the destruction */ + if (context.mon_moving) + monkilled(etmp->emon, mk_message(dest), mk_corpse(dest)); + else /* you caused it */ + xkilled(etmp->emon, dest); + etmp->edata = (struct permonst *) 0; - /* dead long worm handling */ - for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) { - if (etmp != &(occupants[entitycnt]) && - etmp->emon == occupants[entitycnt].emon) - occupants[entitycnt].edata = (struct permonst *)0; - } + /* dead long worm handling */ + for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) { + if (etmp != &(occupants[entitycnt]) + && etmp->emon == occupants[entitycnt].emon) + occupants[entitycnt].edata = (struct permonst *) 0; + } #undef mk_message #undef mk_corpse - } + } } - /* * These are never directly affected by a bridge or portcullis. */ @@ -463,8 +493,8 @@ STATIC_OVL boolean automiss(etmp) struct entity *etmp; { - return (boolean)((is_u(etmp) ? Passes_walls : - passes_walls(etmp->edata)) || noncorporeal(etmp->edata)); + return (boolean)((is_u(etmp) ? Passes_walls : passes_walls(etmp->edata)) + || noncorporeal(etmp->edata)); } /* @@ -476,32 +506,32 @@ e_missed(etmp, chunks) struct entity *etmp; boolean chunks; { - int misses; + int misses; - if (chunks) - debugpline0("Do chunks miss?"); - if (automiss(etmp)) - return(TRUE); + if (chunks) + debugpline0("Do chunks miss?"); + if (automiss(etmp)) + return (TRUE); - if (is_flyer(etmp->edata) && - (is_u(etmp)? !Unaware : - (etmp->emon->mcanmove && !etmp->emon->msleeping))) - /* flying requires mobility */ - misses = 5; /* out of 8 */ - else if (is_floater(etmp->edata) || - (is_u(etmp) && Levitation)) /* doesn't require mobility */ - misses = 3; - else if (chunks && is_pool(etmp->ex, etmp->ey)) - misses = 2; /* sitting ducks */ - else - misses = 0; + if (is_flyer(etmp->edata) + && (is_u(etmp) ? !Unaware + : (etmp->emon->mcanmove && !etmp->emon->msleeping))) + /* flying requires mobility */ + misses = 5; /* out of 8 */ + else if (is_floater(etmp->edata) + || (is_u(etmp) && Levitation)) /* doesn't require mobility */ + misses = 3; + else if (chunks && is_pool(etmp->ex, etmp->ey)) + misses = 2; /* sitting ducks */ + else + misses = 0; - if (is_db_wall(etmp->ex, etmp->ey)) - misses -= 3; /* less airspace */ + if (is_db_wall(etmp->ex, etmp->ey)) + misses -= 3; /* less airspace */ - debugpline1("Miss chance = %d (out of 8)", misses); + debugpline1("Miss chance = %d (out of 8)", misses); - return((boolean)((misses >= rnd(8))? TRUE : FALSE)); + return ((boolean)((misses >= rnd(8)) ? TRUE : FALSE)); } /* @@ -512,221 +542,220 @@ STATIC_OVL boolean e_jumps(etmp) struct entity *etmp; { - int tmp = 4; /* out of 10 */ + int tmp = 4; /* out of 10 */ - if (is_u(etmp) ? (Unaware || Fumbling) : - (!etmp->emon->mcanmove || etmp->emon->msleeping || - !etmp->edata->mmove || etmp->emon->wormno)) - return(FALSE); + if (is_u(etmp) ? (Unaware || Fumbling) + : (!etmp->emon->mcanmove || etmp->emon->msleeping + || !etmp->edata->mmove || etmp->emon->wormno)) + return (FALSE); - if (is_u(etmp)? Confusion : etmp->emon->mconf) - tmp -= 2; + if (is_u(etmp) ? Confusion : etmp->emon->mconf) + tmp -= 2; - if (is_u(etmp)? Stunned : etmp->emon->mstun) - tmp -= 3; + if (is_u(etmp) ? Stunned : etmp->emon->mstun) + tmp -= 3; - if (is_db_wall(etmp->ex, etmp->ey)) - tmp -= 2; /* less room to maneuver */ + if (is_db_wall(etmp->ex, etmp->ey)) + tmp -= 2; /* less room to maneuver */ - debugpline2("%s to jump (%d chances in 10)", - E_phrase(etmp, "try"), tmp); - return((boolean)((tmp >= rnd(10))? TRUE : FALSE)); + debugpline2("%s to jump (%d chances in 10)", E_phrase(etmp, "try"), tmp); + return ((boolean)((tmp >= rnd(10)) ? TRUE : FALSE)); } STATIC_OVL void do_entity(etmp) struct entity *etmp; { - int newx, newy, at_portcullis, oldx, oldy; - boolean must_jump = FALSE, relocates = FALSE, e_inview; - struct rm *crm; + int newx, newy, at_portcullis, oldx, oldy; + boolean must_jump = FALSE, relocates = FALSE, e_inview; + struct rm *crm; - if (!etmp->edata) - return; + if (!etmp->edata) + return; - e_inview = e_canseemon(etmp); - oldx = etmp->ex; - oldy = etmp->ey; - at_portcullis = is_db_wall(oldx, oldy); - crm = &levl[oldx][oldy]; + e_inview = e_canseemon(etmp); + oldx = etmp->ex; + oldy = etmp->ey; + at_portcullis = is_db_wall(oldx, oldy); + crm = &levl[oldx][oldy]; - if (automiss(etmp) && e_survives_at(etmp, oldx, oldy)) { - if (e_inview && (at_portcullis || IS_DRAWBRIDGE(crm->typ))) - pline_The("%s passes through %s!", - at_portcullis ? "portcullis" : "drawbridge", - e_nam(etmp)); - if (is_u(etmp)) spoteffects(FALSE); - return; - } - if (e_missed(etmp, FALSE)) { - if (at_portcullis) - pline_The("portcullis misses %s!", - e_nam(etmp)); - else - debugpline1("The drawbridge misses %s!", e_nam(etmp)); - if (e_survives_at(etmp, oldx, oldy)) - return; - else { - debugpline0("Mon can't survive here"); - if (at_portcullis) - must_jump = TRUE; - else - relocates = TRUE; /* just ride drawbridge in */ - } - } else { - if (crm->typ == DRAWBRIDGE_DOWN) { - pline("%s crushed underneath the drawbridge.", - E_phrase(etmp, "are")); /* no jump */ - e_died(etmp, e_inview? 3 : 2, CRUSHING);/* no corpse */ - return; /* Note: Beyond this point, we know we're */ - } /* not at an opened drawbridge, since all */ - must_jump = TRUE; /* *missable* creatures survive on the */ - } /* square, and all the unmissed ones die. */ - if (must_jump) { - if (at_portcullis) { - if (e_jumps(etmp)) { - relocates = TRUE; - debugpline0("Jump succeeds!"); - } else { - if (e_inview) - pline("%s crushed by the falling portcullis!", - E_phrase(etmp, "are")); - else if (!Deaf) - You_hear("a crushing sound."); - e_died(etmp, e_inview? 3 : 2, CRUSHING); - /* no corpse */ - return; - } - } else { /* tries to jump off bridge to original square */ - relocates = !e_jumps(etmp); - debugpline1("Jump %s!", (relocates)? "fails" : "succeeds"); - } - } + if (automiss(etmp) && e_survives_at(etmp, oldx, oldy)) { + if (e_inview && (at_portcullis || IS_DRAWBRIDGE(crm->typ))) + pline_The("%s passes through %s!", + at_portcullis ? "portcullis" : "drawbridge", + e_nam(etmp)); + if (is_u(etmp)) + spoteffects(FALSE); + return; + } + if (e_missed(etmp, FALSE)) { + if (at_portcullis) + pline_The("portcullis misses %s!", e_nam(etmp)); + else + debugpline1("The drawbridge misses %s!", e_nam(etmp)); + if (e_survives_at(etmp, oldx, oldy)) + return; + else { + debugpline0("Mon can't survive here"); + if (at_portcullis) + must_jump = TRUE; + else + relocates = TRUE; /* just ride drawbridge in */ + } + } else { + if (crm->typ == DRAWBRIDGE_DOWN) { + pline("%s crushed underneath the drawbridge.", + E_phrase(etmp, "are")); /* no jump */ + e_died(etmp, e_inview ? 3 : 2, CRUSHING); /* no corpse */ + return; /* Note: Beyond this point, we know we're */ + } /* not at an opened drawbridge, since all */ + must_jump = TRUE; /* *missable* creatures survive on the */ + } /* square, and all the unmissed ones die. */ + if (must_jump) { + if (at_portcullis) { + if (e_jumps(etmp)) { + relocates = TRUE; + debugpline0("Jump succeeds!"); + } else { + if (e_inview) + pline("%s crushed by the falling portcullis!", + E_phrase(etmp, "are")); + else if (!Deaf) + You_hear("a crushing sound."); + e_died(etmp, e_inview ? 3 : 2, CRUSHING); + /* no corpse */ + return; + } + } else { /* tries to jump off bridge to original square */ + relocates = !e_jumps(etmp); + debugpline1("Jump %s!", (relocates) ? "fails" : "succeeds"); + } + } -/* - * Here's where we try to do relocation. Assumes that etmp is not arriving - * at the portcullis square while the drawbridge is falling, since this square - * would be inaccessible (i.e. etmp started on drawbridge square) or - * unnecessary (i.e. etmp started here) in such a situation. - */ - debugpline0("Doing relocation."); - newx = oldx; - newy = oldy; - (void)find_drawbridge(&newx, &newy); - if ((newx == oldx) && (newy == oldy)) - get_wall_for_db(&newx, &newy); - debugpline0("Checking new square for occupancy."); - if (relocates && (e_at(newx, newy))) { + /* + * Here's where we try to do relocation. Assumes that etmp is not + * arriving + * at the portcullis square while the drawbridge is falling, since this + * square + * would be inaccessible (i.e. etmp started on drawbridge square) or + * unnecessary (i.e. etmp started here) in such a situation. + */ + debugpline0("Doing relocation."); + newx = oldx; + newy = oldy; + (void) find_drawbridge(&newx, &newy); + if ((newx == oldx) && (newy == oldy)) + get_wall_for_db(&newx, &newy); + debugpline0("Checking new square for occupancy."); + if (relocates && (e_at(newx, newy))) { + /* + * Standoff problem: one or both entities must die, and/or both + * switch + * places. Avoid infinite recursion by checking first whether the + * other + * entity is staying put. Clean up if we happen to move/die in + * recursion. + */ + struct entity *other; -/* - * Standoff problem: one or both entities must die, and/or both switch - * places. Avoid infinite recursion by checking first whether the other - * entity is staying put. Clean up if we happen to move/die in recursion. - */ - struct entity *other; - - other = e_at(newx, newy); - debugpline1("New square is occupied by %s", e_nam(other)); - if (e_survives_at(other, newx, newy) && automiss(other)) { - relocates = FALSE; /* "other" won't budge */ - debugpline1("%s suicide.", E_phrase(etmp, "commit")); - } else { - - debugpline1("Handling %s", e_nam(other)); - while ((e_at(newx, newy) != 0) && - (e_at(newx, newy) != etmp)) - do_entity(other); - debugpline1("Checking existence of %s", e_nam(etmp)); + other = e_at(newx, newy); + debugpline1("New square is occupied by %s", e_nam(other)); + if (e_survives_at(other, newx, newy) && automiss(other)) { + relocates = FALSE; /* "other" won't budge */ + debugpline1("%s suicide.", E_phrase(etmp, "commit")); + } else { + debugpline1("Handling %s", e_nam(other)); + while ((e_at(newx, newy) != 0) && (e_at(newx, newy) != etmp)) + do_entity(other); + debugpline1("Checking existence of %s", e_nam(etmp)); #ifdef D_DEBUG - wait_synch(); + wait_synch(); #endif - if (e_at(oldx, oldy) != etmp) { - debugpline1("%s moved or died in recursion somewhere", - E_phrase(etmp, "have")); + if (e_at(oldx, oldy) != etmp) { + debugpline1("%s moved or died in recursion somewhere", + E_phrase(etmp, "have")); #ifdef D_DEBUG - wait_synch(); + wait_synch(); #endif - return; - } - } - } - if (relocates && !e_at(newx, newy)) {/* if e_at() entity = worm tail */ - debugpline1("Moving %s", e_nam(etmp)); - if (!is_u(etmp)) { - remove_monster(etmp->ex, etmp->ey); - place_monster(etmp->emon, newx, newy); - update_monster_region(etmp->emon); - } else { - u.ux = newx; - u.uy = newy; - } - etmp->ex = newx; - etmp->ey = newy; - e_inview = e_canseemon(etmp); - } - debugpline1("Final disposition of %s", e_nam(etmp)); + return; + } + } + } + if (relocates && !e_at(newx, newy)) { /* if e_at() entity = worm tail */ + debugpline1("Moving %s", e_nam(etmp)); + if (!is_u(etmp)) { + remove_monster(etmp->ex, etmp->ey); + place_monster(etmp->emon, newx, newy); + update_monster_region(etmp->emon); + } else { + u.ux = newx; + u.uy = newy; + } + etmp->ex = newx; + etmp->ey = newy; + e_inview = e_canseemon(etmp); + } + debugpline1("Final disposition of %s", e_nam(etmp)); #ifdef D_DEBUG - wait_synch(); + wait_synch(); #endif - if (is_db_wall(etmp->ex, etmp->ey)) { - debugpline1("%s in portcullis chamber", E_phrase(etmp, "are")); + if (is_db_wall(etmp->ex, etmp->ey)) { + debugpline1("%s in portcullis chamber", E_phrase(etmp, "are")); #ifdef D_DEBUG - wait_synch(); + wait_synch(); #endif - if (e_inview) { - if (is_u(etmp)) { - You("tumble towards the closed portcullis!"); - if (automiss(etmp)) - You("pass through it!"); - else - pline_The("drawbridge closes in..."); - } else - pline("%s behind the drawbridge.", - E_phrase(etmp, "disappear")); - } - if (!e_survives_at(etmp, etmp->ex, etmp->ey)) { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "closing drawbridge"); - e_died(etmp, 0, CRUSHING); /* no message */ - return; - } - debugpline1("%s in here", E_phrase(etmp, "survive")); - } else { - debugpline1("%s on drawbridge square", E_phrase(etmp, "are")); - if (is_pool(etmp->ex, etmp->ey) && !e_inview) - if (!Deaf) - You_hear("a splash."); - if (e_survives_at(etmp, etmp->ex, etmp->ey)) { - if (e_inview && !is_flyer(etmp->edata) && - !is_floater(etmp->edata)) - pline("%s from the bridge.", - E_phrase(etmp, "fall")); - return; - } - debugpline1("%s cannot survive on the drawbridge square", - E_phrase(etmp, NULL)); - if (is_pool(etmp->ex, etmp->ey) || is_lava(etmp->ex, etmp->ey)) - if (e_inview && !is_u(etmp)) { - /* drown() will supply msgs if nec. */ - boolean lava = is_lava(etmp->ex, etmp->ey); + if (e_inview) { + if (is_u(etmp)) { + You("tumble towards the closed portcullis!"); + if (automiss(etmp)) + You("pass through it!"); + else + pline_The("drawbridge closes in..."); + } else + pline("%s behind the drawbridge.", + E_phrase(etmp, "disappear")); + } + if (!e_survives_at(etmp, etmp->ex, etmp->ey)) { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "closing drawbridge"); + e_died(etmp, 0, CRUSHING); /* no message */ + return; + } + debugpline1("%s in here", E_phrase(etmp, "survive")); + } else { + debugpline1("%s on drawbridge square", E_phrase(etmp, "are")); + if (is_pool(etmp->ex, etmp->ey) && !e_inview) + if (!Deaf) + You_hear("a splash."); + if (e_survives_at(etmp, etmp->ex, etmp->ey)) { + if (e_inview && !is_flyer(etmp->edata) + && !is_floater(etmp->edata)) + pline("%s from the bridge.", E_phrase(etmp, "fall")); + return; + } + debugpline1("%s cannot survive on the drawbridge square", + E_phrase(etmp, NULL)); + if (is_pool(etmp->ex, etmp->ey) || is_lava(etmp->ex, etmp->ey)) + if (e_inview && !is_u(etmp)) { + /* drown() will supply msgs if nec. */ + boolean lava = is_lava(etmp->ex, etmp->ey); - if (Hallucination) - pline("%s the %s and disappears.", - E_phrase(etmp, "drink"), - lava ? "lava" : "moat"); - else - pline("%s into the %s.", - E_phrase(etmp, "fall"), - lava ? "lava" : "moat"); - } - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "fell from a drawbridge"); - e_died(etmp, e_inview ? 3 : 2, /* CRUSHING is arbitrary */ - (is_pool(etmp->ex, etmp->ey)) ? DROWNING : - (is_lava(etmp->ex, etmp->ey)) ? BURNING : - CRUSHING); /*no corpse*/ - return; - } + if (Hallucination) + pline("%s the %s and disappears.", + E_phrase(etmp, "drink"), lava ? "lava" : "moat"); + else + pline("%s into the %s.", E_phrase(etmp, "fall"), + lava ? "lava" : "moat"); + } + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "fell from a drawbridge"); + e_died(etmp, e_inview ? 3 : 2, /* CRUSHING is arbitrary */ + (is_pool(etmp->ex, etmp->ey)) + ? DROWNING + : (is_lava(etmp->ex, etmp->ey)) ? BURNING + : CRUSHING); /*no corpse*/ + return; + } } /* @@ -734,55 +763,61 @@ struct entity *etmp; */ void -close_drawbridge(x,y) -int x,y; +close_drawbridge(x, y) +int x, y; { - register struct rm *lev1, *lev2; - struct trap *t; - int x2, y2; + register struct rm *lev1, *lev2; + struct trap *t; + int x2, y2; - lev1 = &levl[x][y]; - if (lev1->typ != DRAWBRIDGE_DOWN) return; - x2 = x; y2 = y; - get_wall_for_db(&x2,&y2); - if (cansee(x,y) || cansee(x2,y2)) - You_see("a drawbridge %s up!", - (((u.ux == x || u.uy == y) && !Underwater) || - distu(x2,y2) < distu(x,y)) ? "coming" : "going"); - else /* "5 gears turn" for castle drawbridge tune */ - You_hear("chains rattling and gears turning."); - lev1->typ = DRAWBRIDGE_UP; - lev2 = &levl[x2][y2]; - lev2->typ = DBWALL; - switch (lev1->drawbridgemask & DB_DIR) { - case DB_NORTH: - case DB_SOUTH: - lev2->horizontal = TRUE; - break; - case DB_WEST: - case DB_EAST: - lev2->horizontal = FALSE; - break; - } - lev2->wall_info = W_NONDIGGABLE; - set_entity(x, y, &(occupants[0])); - set_entity(x2, y2, &(occupants[1])); - do_entity(&(occupants[0])); /* Do set_entity after first */ - set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tail */ - do_entity(&(occupants[1])); - if(OBJ_AT(x,y) && !Deaf) - You_hear("smashing and crushing."); - (void) revive_nasty(x,y,(char *)0); - (void) revive_nasty(x2,y2,(char *)0); - delallobj(x, y); - delallobj(x2, y2); - if ((t = t_at(x, y)) != 0) deltrap(t); - if ((t = t_at(x2, y2)) != 0) deltrap(t); - del_engr_at(x, y); - del_engr_at(x2, y2); - newsym(x, y); - newsym(x2, y2); - block_point(x2,y2); /* vision */ + lev1 = &levl[x][y]; + if (lev1->typ != DRAWBRIDGE_DOWN) + return; + x2 = x; + y2 = y; + get_wall_for_db(&x2, &y2); + if (cansee(x, y) || cansee(x2, y2)) + You_see("a drawbridge %s up!", + (((u.ux == x || u.uy == y) && !Underwater) + || distu(x2, y2) < distu(x, y)) + ? "coming" + : "going"); + else /* "5 gears turn" for castle drawbridge tune */ + You_hear("chains rattling and gears turning."); + lev1->typ = DRAWBRIDGE_UP; + lev2 = &levl[x2][y2]; + lev2->typ = DBWALL; + switch (lev1->drawbridgemask & DB_DIR) { + case DB_NORTH: + case DB_SOUTH: + lev2->horizontal = TRUE; + break; + case DB_WEST: + case DB_EAST: + lev2->horizontal = FALSE; + break; + } + lev2->wall_info = W_NONDIGGABLE; + set_entity(x, y, &(occupants[0])); + set_entity(x2, y2, &(occupants[1])); + do_entity(&(occupants[0])); /* Do set_entity after first */ + set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tail */ + do_entity(&(occupants[1])); + if (OBJ_AT(x, y) && !Deaf) + You_hear("smashing and crushing."); + (void) revive_nasty(x, y, (char *) 0); + (void) revive_nasty(x2, y2, (char *) 0); + delallobj(x, y); + delallobj(x2, y2); + if ((t = t_at(x, y)) != 0) + deltrap(t); + if ((t = t_at(x2, y2)) != 0) + deltrap(t); + del_engr_at(x, y); + del_engr_at(x2, y2); + newsym(x, y); + newsym(x2, y2); + block_point(x2, y2); /* vision */ } /* @@ -790,41 +825,46 @@ int x,y; */ void -open_drawbridge(x,y) -int x,y; +open_drawbridge(x, y) +int x, y; { - register struct rm *lev1, *lev2; - struct trap *t; - int x2, y2; + register struct rm *lev1, *lev2; + struct trap *t; + int x2, y2; - lev1 = &levl[x][y]; - if (lev1->typ != DRAWBRIDGE_UP) return; - x2 = x; y2 = y; - get_wall_for_db(&x2,&y2); - if (cansee(x,y) || cansee(x2,y2)) - You_see("a drawbridge %s down!", - (distu(x2,y2) < distu(x,y)) ? "going" : "coming"); - else /* "5 gears turn" for castle drawbridge tune */ - You_hear("gears turning and chains rattling."); - lev1->typ = DRAWBRIDGE_DOWN; - lev2 = &levl[x2][y2]; - lev2->typ = DOOR; - lev2->doormask = D_NODOOR; - set_entity(x, y, &(occupants[0])); - set_entity(x2, y2, &(occupants[1])); - do_entity(&(occupants[0])); /* do set_entity after first */ - set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tails */ - do_entity(&(occupants[1])); - (void) revive_nasty(x,y,(char *)0); - delallobj(x, y); - if ((t = t_at(x, y)) != 0) deltrap(t); - if ((t = t_at(x2, y2)) != 0) deltrap(t); - del_engr_at(x, y); - del_engr_at(x2, y2); - newsym(x, y); - newsym(x2, y2); - unblock_point(x2,y2); /* vision */ - if (Is_stronghold(&u.uz)) u.uevent.uopened_dbridge = TRUE; + lev1 = &levl[x][y]; + if (lev1->typ != DRAWBRIDGE_UP) + return; + x2 = x; + y2 = y; + get_wall_for_db(&x2, &y2); + if (cansee(x, y) || cansee(x2, y2)) + You_see("a drawbridge %s down!", + (distu(x2, y2) < distu(x, y)) ? "going" : "coming"); + else /* "5 gears turn" for castle drawbridge tune */ + You_hear("gears turning and chains rattling."); + lev1->typ = DRAWBRIDGE_DOWN; + lev2 = &levl[x2][y2]; + lev2->typ = DOOR; + lev2->doormask = D_NODOOR; + set_entity(x, y, &(occupants[0])); + set_entity(x2, y2, &(occupants[1])); + do_entity(&(occupants[0])); /* do set_entity after first */ + set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tails */ + do_entity(&(occupants[1])); + (void) revive_nasty(x, y, (char *) 0); + delallobj(x, y); + if ((t = t_at(x, y)) != 0) + deltrap(t); + if ((t = t_at(x2, y2)) != 0) + deltrap(t); + del_engr_at(x, y); + del_engr_at(x2, y2); + newsym(x, y); + newsym(x2, y2); + unblock_point(x2, y2); /* vision */ + if (Is_stronghold(&u.uz)) + u.uevent.uopened_dbridge = TRUE; } /* @@ -832,122 +872,123 @@ int x,y; */ void -destroy_drawbridge(x,y) -int x,y; +destroy_drawbridge(x, y) +int x, y; { - register struct rm *lev1, *lev2; - struct trap *t; - struct obj *otmp; - int x2, y2, i; - boolean e_inview; - struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]); + register struct rm *lev1, *lev2; + struct trap *t; + struct obj *otmp; + int x2, y2, i; + boolean e_inview; + struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]); - lev1 = &levl[x][y]; - if (!IS_DRAWBRIDGE(lev1->typ)) - return; - x2 = x; y2 = y; - get_wall_for_db(&x2,&y2); - lev2 = &levl[x2][y2]; - if ((lev1->drawbridgemask & DB_UNDER) == DB_MOAT || - (lev1->drawbridgemask & DB_UNDER) == DB_LAVA) { - struct obj *otmp2; - boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA; - if (lev1->typ == DRAWBRIDGE_UP) { - if (cansee(x2,y2)) - pline_The("portcullis of the drawbridge falls into the %s!", - lava ? "lava" : "moat"); - else if (!Deaf) - You_hear("a loud *SPLASH*!"); - } else { - if (cansee(x,y)) - pline_The("drawbridge collapses into the %s!", - lava ? "lava" : "moat"); - else if (!Deaf) - You_hear("a loud *SPLASH*!"); - } - lev1->typ = lava ? LAVAPOOL : MOAT; - lev1->drawbridgemask = 0; - if ((otmp2 = sobj_at(BOULDER,x,y)) != 0) { - obj_extract_self(otmp2); - (void) flooreffects(otmp2,x,y,"fall"); - } - } else { - if (cansee(x,y)) - pline_The("drawbridge disintegrates!"); - else - You_hear("a loud *CRASH*!"); - lev1->typ = - ((lev1->drawbridgemask & DB_ICE) ? ICE : ROOM); - lev1->icedpool = - ((lev1->drawbridgemask & DB_ICE) ? ICED_MOAT : 0); - } - wake_nearto(x, y, 500); - lev2->typ = DOOR; - lev2->doormask = D_NODOOR; - if ((t = t_at(x, y)) != 0) deltrap(t); - if ((t = t_at(x2, y2)) != 0) deltrap(t); - del_engr_at(x, y); - del_engr_at(x2, y2); - for (i = rn2(6); i > 0; --i) { /* scatter some debris */ - /* doesn't matter if we happen to pick or ; - since drawbridges are never placed diagonally, those - pairings will always match one of or */ - otmp = mksobj_at(IRON_CHAIN, - rn2(2) ? x : x2, rn2(2) ? y : y2, - TRUE, FALSE); - /* a force of 5 here would yield a radius of 2 for - iron chain; anything less produces a radius of 1 */ - (void) scatter(otmp->ox, otmp->oy, 1, MAY_HIT, otmp); - } - newsym(x,y); - newsym(x2,y2); - if (!does_block(x2,y2,lev2)) unblock_point(x2,y2); /* vision */ - if (Is_stronghold(&u.uz)) u.uevent.uopened_dbridge = TRUE; + lev1 = &levl[x][y]; + if (!IS_DRAWBRIDGE(lev1->typ)) + return; + x2 = x; + y2 = y; + get_wall_for_db(&x2, &y2); + lev2 = &levl[x2][y2]; + if ((lev1->drawbridgemask & DB_UNDER) == DB_MOAT + || (lev1->drawbridgemask & DB_UNDER) == DB_LAVA) { + struct obj *otmp2; + boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA; + if (lev1->typ == DRAWBRIDGE_UP) { + if (cansee(x2, y2)) + pline_The("portcullis of the drawbridge falls into the %s!", + lava ? "lava" : "moat"); + else if (!Deaf) + You_hear("a loud *SPLASH*!"); + } else { + if (cansee(x, y)) + pline_The("drawbridge collapses into the %s!", + lava ? "lava" : "moat"); + else if (!Deaf) + You_hear("a loud *SPLASH*!"); + } + lev1->typ = lava ? LAVAPOOL : MOAT; + lev1->drawbridgemask = 0; + if ((otmp2 = sobj_at(BOULDER, x, y)) != 0) { + obj_extract_self(otmp2); + (void) flooreffects(otmp2, x, y, "fall"); + } + } else { + if (cansee(x, y)) + pline_The("drawbridge disintegrates!"); + else + You_hear("a loud *CRASH*!"); + lev1->typ = ((lev1->drawbridgemask & DB_ICE) ? ICE : ROOM); + lev1->icedpool = ((lev1->drawbridgemask & DB_ICE) ? ICED_MOAT : 0); + } + wake_nearto(x, y, 500); + lev2->typ = DOOR; + lev2->doormask = D_NODOOR; + if ((t = t_at(x, y)) != 0) + deltrap(t); + if ((t = t_at(x2, y2)) != 0) + deltrap(t); + del_engr_at(x, y); + del_engr_at(x2, y2); + for (i = rn2(6); i > 0; --i) { /* scatter some debris */ + /* doesn't matter if we happen to pick or ; + since drawbridges are never placed diagonally, those + pairings will always match one of or */ + otmp = mksobj_at(IRON_CHAIN, rn2(2) ? x : x2, rn2(2) ? y : y2, TRUE, + FALSE); + /* a force of 5 here would yield a radius of 2 for + iron chain; anything less produces a radius of 1 */ + (void) scatter(otmp->ox, otmp->oy, 1, MAY_HIT, otmp); + } + newsym(x, y); + newsym(x2, y2); + if (!does_block(x2, y2, lev2)) + unblock_point(x2, y2); /* vision */ + if (Is_stronghold(&u.uz)) + u.uevent.uopened_dbridge = TRUE; - set_entity(x2, y2, etmp2); /* currently only automissers can be here */ - if (etmp2->edata) { - e_inview = e_canseemon(etmp2); - if (!automiss(etmp2)) { - if (e_inview) - pline("%s blown apart by flying debris.", - E_phrase(etmp2, "are")); - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "exploding drawbridge"); - e_died(etmp2, e_inview? 3 : 2, CRUSHING); /*no corpse*/ - } /* nothing which is vulnerable can survive this */ - } - set_entity(x, y, etmp1); - if (etmp1->edata) { - e_inview = e_canseemon(etmp1); - if (e_missed(etmp1, TRUE)) { - debugpline1("%s spared!", E_phrase(etmp1, "are")); - /* if there is water or lava here, fall in now */ - if (is_u(etmp1)) - spoteffects(FALSE); - else - (void)minliquid(etmp1->emon); - } else { - if (e_inview) { - if (!is_u(etmp1) && Hallucination) - pline("%s into some heavy metal!", - E_phrase(etmp1, "get")); - else - pline("%s hit by a huge chunk of metal!", - E_phrase(etmp1, "are")); - } else { - if (!Deaf && !is_u(etmp1) && !is_pool(x,y)) - You_hear("a crushing sound."); - else - debugpline1("%s from shrapnel", - E_phrase(etmp1, "die")); - } - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "collapsing drawbridge"); - e_died(etmp1, e_inview? 3 : 2, CRUSHING); /*no corpse*/ - if(levl[etmp1->ex][etmp1->ey].typ == MOAT) - do_entity(etmp1); - } - } + set_entity(x2, y2, etmp2); /* currently only automissers can be here */ + if (etmp2->edata) { + e_inview = e_canseemon(etmp2); + if (!automiss(etmp2)) { + if (e_inview) + pline("%s blown apart by flying debris.", + E_phrase(etmp2, "are")); + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "exploding drawbridge"); + e_died(etmp2, e_inview ? 3 : 2, CRUSHING); /*no corpse*/ + } /* nothing which is vulnerable can survive this */ + } + set_entity(x, y, etmp1); + if (etmp1->edata) { + e_inview = e_canseemon(etmp1); + if (e_missed(etmp1, TRUE)) { + debugpline1("%s spared!", E_phrase(etmp1, "are")); + /* if there is water or lava here, fall in now */ + if (is_u(etmp1)) + spoteffects(FALSE); + else + (void) minliquid(etmp1->emon); + } else { + if (e_inview) { + if (!is_u(etmp1) && Hallucination) + pline("%s into some heavy metal!", + E_phrase(etmp1, "get")); + else + pline("%s hit by a huge chunk of metal!", + E_phrase(etmp1, "are")); + } else { + if (!Deaf && !is_u(etmp1) && !is_pool(x, y)) + You_hear("a crushing sound."); + else + debugpline1("%s from shrapnel", E_phrase(etmp1, "die")); + } + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "collapsing drawbridge"); + e_died(etmp1, e_inview ? 3 : 2, CRUSHING); /*no corpse*/ + if (levl[etmp1->ex][etmp1->ey].typ == MOAT) + do_entity(etmp1); + } + } } /*dbridge.c*/ diff --git a/src/decl.c b/src/decl.c index 0bdaed9bf..5e856ae63 100644 --- a/src/decl.c +++ b/src/decl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 decl.c $NHDT-Date: 1430897862 2015/05/06 07:37:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.56 $ */ +/* NetHack 3.6 decl.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.59 $ */ /* NetHack 3.6 decl.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.37 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,13 +9,13 @@ int NDECL((*afternmv)); int NDECL((*occupation)); /* from xxxmain.c */ -const char *hname = 0; /* name of the game (argv[0] of main) */ -int hackpid = 0; /* current process id */ +const char *hname = 0; /* name of the game (argv[0] of main) */ +int hackpid = 0; /* current process id */ #if defined(UNIX) || defined(VMS) -int locknum = 0; /* max num of simultaneous users */ +int locknum = 0; /* max num of simultaneous users */ #endif #ifdef DEF_PAGER -char *catmore = 0; /* default pager */ +char *catmore = 0; /* default pager */ #endif NEARDATA int bases[MAXOCLASSES] = DUMMY; @@ -27,10 +27,9 @@ NEARDATA int nsubroom = 0; NEARDATA int occtime = 0; /* maze limits must be even; masking off lowest bit guarantees that */ -int x_maze_max = (COLNO-1) & ~1, - y_maze_max = (ROWNO-1) & ~1; +int x_maze_max = (COLNO - 1) & ~1, y_maze_max = (ROWNO - 1) & ~1; -int otg_temp; /* used by object_to_glyph() [otg] */ +int otg_temp; /* used by object_to_glyph() [otg] */ NEARDATA int in_doagain = 0; @@ -38,24 +37,24 @@ NEARDATA int in_doagain = 0; * The following structure will be initialized at startup time with * the level numbers of some "important" things in the game. */ -struct dgn_topology dungeon_topology = {DUMMY}; +struct dgn_topology dungeon_topology = { DUMMY }; -struct q_score quest_status = DUMMY; +struct q_score quest_status = DUMMY; NEARDATA int warn_obj_cnt = 0; -NEARDATA int smeq[MAXNROFROOMS+1] = DUMMY; +NEARDATA int smeq[MAXNROFROOMS + 1] = DUMMY; NEARDATA int doorindex = 0; NEARDATA char *save_cm = 0; NEARDATA struct kinfo killer = DUMMY; NEARDATA long done_money = 0; const char *nomovemsg = 0; -NEARDATA char plname[PL_NSIZ] = DUMMY; /* player name */ +NEARDATA char plname[PL_NSIZ] = DUMMY; /* player name */ NEARDATA char pl_character[PL_CSIZ] = DUMMY; NEARDATA char pl_race = '\0'; NEARDATA char pl_fruit[PL_FSIZ] = DUMMY; -NEARDATA struct fruit *ffruit = (struct fruit *)0; +NEARDATA struct fruit *ffruit = (struct fruit *) 0; NEARDATA char tune[6] = DUMMY; @@ -71,16 +70,15 @@ NEARDATA long yn_number = 0L; const char disclosure_options[] = "iavgco"; #if defined(MICRO) || defined(WIN32) -char hackdir[PATHLEN]; /* where rumors, help, record are */ -# ifdef MICRO -char levels[PATHLEN]; /* where levels are */ -# endif +char hackdir[PATHLEN]; /* where rumors, help, record are */ +#ifdef MICRO +char levels[PATHLEN]; /* where levels are */ +#endif #endif /* MICRO || WIN32 */ - #ifdef MFLOPPY -char permbones[PATHLEN]; /* where permanent copy of bones go */ -int ramdisk = FALSE; /* whether to copy bones to levels or not */ +char permbones[PATHLEN]; /* where permanent copy of bones go */ +int ramdisk = FALSE; /* whether to copy bones to levels or not */ int saveprompt = TRUE; const char *alllevels = "levels.*"; const char *allbones = "bones*.*"; @@ -91,43 +89,45 @@ struct linfo level_info[MAXLINFO]; NEARDATA struct sinfo program_state; /* x/y/z deltas for the 10 movement directions (8 compass pts, 2 up/down) */ -const schar xdir[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 }; -const schar ydir[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 }; -const schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 }; +const schar xdir[10] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 }; +const schar ydir[10] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 }; +const schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 }; -NEARDATA schar tbx = 0, tby = 0; /* mthrowu: target */ +NEARDATA schar tbx = 0, tby = 0; /* mthrowu: target */ /* for xname handling of multiple shot missile volleys: number of shots, index of current one, validity check, shoot vs throw */ NEARDATA struct multishot m_shot = { 0, 0, STRANGE_OBJECT, FALSE }; -NEARDATA dungeon dungeons[MAXDUNGEON]; /* ini'ed by init_dungeon() */ +NEARDATA dungeon dungeons[MAXDUNGEON]; /* ini'ed by init_dungeon() */ NEARDATA s_level *sp_levchn; -NEARDATA stairway upstair = { 0, 0, { 0,0 }, 0 }, dnstair = { 0, 0, { 0,0 }, 0 }; -NEARDATA stairway upladder = { 0, 0, { 0,0 }, 0 }, dnladder = { 0, 0, { 0,0 }, 0 }; -NEARDATA stairway sstairs = { 0, 0, { 0,0 }, 0 }; +NEARDATA stairway upstair = { 0, 0, { 0, 0 }, 0 }, + dnstair = { 0, 0, { 0, 0 }, 0 }; +NEARDATA stairway upladder = { 0, 0, { 0, 0 }, 0 }, + dnladder = { 0, 0, { 0, 0 }, 0 }; +NEARDATA stairway sstairs = { 0, 0, { 0, 0 }, 0 }; NEARDATA dest_area updest = { 0, 0, 0, 0, 0, 0, 0, 0 }; NEARDATA dest_area dndest = { 0, 0, 0, 0, 0, 0, 0, 0 }; NEARDATA coord inv_pos = { 0, 0 }; NEARDATA boolean defer_see_monsters = FALSE; NEARDATA boolean in_mklev = FALSE; -NEARDATA boolean stoned = FALSE; /* done to monsters hit by 'c' */ +NEARDATA boolean stoned = FALSE; /* done to monsters hit by 'c' */ NEARDATA boolean unweapon = FALSE; NEARDATA boolean mrg_to_wielded = FALSE; - /* weapon picked is merged with wielded one */ +/* weapon picked is merged with wielded one */ NEARDATA boolean in_steed_dismounting = FALSE; NEARDATA coord bhitpos = DUMMY; -NEARDATA coord doors[DOORMAX] = {DUMMY}; +NEARDATA coord doors[DOORMAX] = { DUMMY }; -NEARDATA struct mkroom rooms[(MAXNROFROOMS+1)*2] = {DUMMY}; -NEARDATA struct mkroom* subrooms = &rooms[MAXNROFROOMS+1]; +NEARDATA struct mkroom rooms[(MAXNROFROOMS + 1) * 2] = { DUMMY }; +NEARDATA struct mkroom *subrooms = &rooms[MAXNROFROOMS + 1]; struct mkroom *upstairs_room, *dnstairs_room, *sstairs_room; -dlevel_t level; /* level map */ -struct trap *ftrap = (struct trap *)0; +dlevel_t level; /* level map */ +struct trap *ftrap = (struct trap *) 0; NEARDATA struct monst youmonst = DUMMY; NEARDATA struct context_info context = DUMMY; NEARDATA struct flag flags = DUMMY; @@ -139,61 +139,60 @@ NEARDATA struct you u = DUMMY; NEARDATA time_t ubirthday = DUMMY; NEARDATA struct u_realtime urealtime = DUMMY; +schar lastseentyp[COLNO][ROWNO] = { + DUMMY +}; /* last seen/touched dungeon typ */ -schar lastseentyp[COLNO][ROWNO] = {DUMMY}; /* last seen/touched dungeon typ */ - -NEARDATA struct obj *invent = (struct obj *)0, - *uwep = (struct obj *)0, *uarm = (struct obj *)0, - *uswapwep = (struct obj *)0, - *uquiver = (struct obj *)0, /* quiver */ - *uarmu = (struct obj *)0, /* under-wear, so to speak */ - *uskin = (struct obj *)0, /* dragon armor, if a dragon */ - *uarmc = (struct obj *)0, *uarmh = (struct obj *)0, - *uarms = (struct obj *)0, *uarmg = (struct obj *)0, - *uarmf = (struct obj *)0, *uamul = (struct obj *)0, - *uright = (struct obj *)0, - *uleft = (struct obj *)0, - *ublindf = (struct obj *)0, - *uchain = (struct obj *)0, - *uball = (struct obj *)0; -/* some objects need special handling during destruction or placement */ NEARDATA struct obj - *current_wand = 0, /* wand currently zapped/applied */ - *thrownobj = 0, /* object in flight due to throwing */ - *kickedobj = 0; /* object in flight due to kicking */ + *invent = (struct obj *) 0, + *uwep = (struct obj *) 0, *uarm = (struct obj *) 0, + *uswapwep = (struct obj *) 0, + *uquiver = (struct obj *) 0, /* quiver */ + *uarmu = (struct obj *) 0, /* under-wear, so to speak */ + *uskin = (struct obj *) 0, /* dragon armor, if a dragon */ + *uarmc = (struct obj *) 0, *uarmh = (struct obj *) 0, + *uarms = (struct obj *) 0, *uarmg = (struct obj *) 0, + *uarmf = (struct obj *) 0, *uamul = (struct obj *) 0, + *uright = (struct obj *) 0, *uleft = (struct obj *) 0, + *ublindf = (struct obj *) 0, *uchain = (struct obj *) 0, + *uball = (struct obj *) 0; +/* some objects need special handling during destruction or placement */ +NEARDATA struct obj *current_wand = 0, /* wand currently zapped/applied */ + *thrownobj = 0, /* object in flight due to throwing */ + *kickedobj = 0; /* object in flight due to kicking */ #ifdef TEXTCOLOR /* * This must be the same order as used for buzz() in zap.c. */ const int zapcolors[NUM_ZAP] = { - HI_ZAP, /* 0 - missile */ - CLR_ORANGE, /* 1 - fire */ - CLR_WHITE, /* 2 - frost */ - HI_ZAP, /* 3 - sleep */ - CLR_BLACK, /* 4 - death */ - CLR_WHITE, /* 5 - lightning */ - CLR_YELLOW, /* 6 - poison gas */ - CLR_GREEN, /* 7 - acid */ + HI_ZAP, /* 0 - missile */ + CLR_ORANGE, /* 1 - fire */ + CLR_WHITE, /* 2 - frost */ + HI_ZAP, /* 3 - sleep */ + CLR_BLACK, /* 4 - death */ + CLR_WHITE, /* 5 - lightning */ + CLR_YELLOW, /* 6 - poison gas */ + CLR_GREEN, /* 7 - acid */ }; #endif /* text color */ const int shield_static[SHIELD_COUNT] = { - S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */ + S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */ S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, }; -NEARDATA struct spell spl_book[MAXSPELL + 1] = {DUMMY}; +NEARDATA struct spell spl_book[MAXSPELL + 1] = { DUMMY }; NEARDATA long moves = 1L, monstermoves = 1L; - /* These diverge when player is Fast */ +/* These diverge when player is Fast */ NEARDATA long wailmsg = 0L; /* objects that are moving to another dungeon level */ -NEARDATA struct obj *migrating_objs = (struct obj *)0; +NEARDATA struct obj *migrating_objs = (struct obj *) 0; /* objects not yet paid for */ -NEARDATA struct obj *billobjs = (struct obj *)0; +NEARDATA struct obj *billobjs = (struct obj *) 0; /* used to zero all elements of a struct obj */ NEARDATA struct obj zeroobj = DUMMY; @@ -204,61 +203,63 @@ NEARDATA anything zeroany; NEARDATA char dogname[PL_PSIZ] = DUMMY; NEARDATA char catname[PL_PSIZ] = DUMMY; NEARDATA char horsename[PL_PSIZ] = DUMMY; -char preferred_pet; /* '\0', 'c', 'd', 'n' (none) */ +char preferred_pet; /* '\0', 'c', 'd', 'n' (none) */ /* monsters that went down/up together with @ */ -NEARDATA struct monst *mydogs = (struct monst *)0; +NEARDATA struct monst *mydogs = (struct monst *) 0; /* monsters that are moving to another dungeon level */ -NEARDATA struct monst *migrating_mons = (struct monst *)0; +NEARDATA struct monst *migrating_mons = (struct monst *) 0; NEARDATA struct mvitals mvitals[NUMMONS]; NEARDATA struct c_color_names c_color_names = { - "black", "amber", "golden", - "light blue", "red", "green", - "silver", "blue", "purple", - "white", "orange" + "black", "amber", "golden", "light blue", "red", "green", + "silver", "blue", "purple", "white", "orange" }; struct menucoloring *menu_colorings = NULL; const char *c_obj_colors[] = { - "black", /* CLR_BLACK */ - "red", /* CLR_RED */ - "green", /* CLR_GREEN */ - "brown", /* CLR_BROWN */ - "blue", /* CLR_BLUE */ - "magenta", /* CLR_MAGENTA */ - "cyan", /* CLR_CYAN */ - "gray", /* CLR_GRAY */ - "transparent", /* no_color */ - "orange", /* CLR_ORANGE */ - "bright green", /* CLR_BRIGHT_GREEN */ - "yellow", /* CLR_YELLOW */ - "bright blue", /* CLR_BRIGHT_BLUE */ - "bright magenta", /* CLR_BRIGHT_MAGENTA */ - "bright cyan", /* CLR_BRIGHT_CYAN */ - "white", /* CLR_WHITE */ + "black", /* CLR_BLACK */ + "red", /* CLR_RED */ + "green", /* CLR_GREEN */ + "brown", /* CLR_BROWN */ + "blue", /* CLR_BLUE */ + "magenta", /* CLR_MAGENTA */ + "cyan", /* CLR_CYAN */ + "gray", /* CLR_GRAY */ + "transparent", /* no_color */ + "orange", /* CLR_ORANGE */ + "bright green", /* CLR_BRIGHT_GREEN */ + "yellow", /* CLR_YELLOW */ + "bright blue", /* CLR_BRIGHT_BLUE */ + "bright magenta", /* CLR_BRIGHT_MAGENTA */ + "bright cyan", /* CLR_BRIGHT_CYAN */ + "white", /* CLR_WHITE */ }; -struct c_common_strings c_common_strings = { - "Nothing happens.", "That's enough tries!", - "That is a silly thing to %s.", "shudder for a moment.", - "something", "Something", "You can move again.", "Never mind.", - "vision quickly clears.", {"the", "your"} -}; +struct c_common_strings c_common_strings = { "Nothing happens.", + "That's enough tries!", + "That is a silly thing to %s.", + "shudder for a moment.", + "something", + "Something", + "You can move again.", + "Never mind.", + "vision quickly clears.", + { "the", "your" } }; /* NOTE: the order of these words exactly corresponds to the order of oc_material values #define'd in objclass.h. */ -const char *materialnm[] = { - "mysterious", "liquid", "wax", "organic", "flesh", - "paper", "cloth", "leather", "wooden", "bone", "dragonhide", - "iron", "metal", "copper", "silver", "gold", "platinum", "mithril", - "plastic", "glass", "gemstone", "stone" -}; +const char *materialnm[] = { "mysterious", "liquid", "wax", "organic", + "flesh", "paper", "cloth", "leather", + "wooden", "bone", "dragonhide", "iron", + "metal", "copper", "silver", "gold", + "platinum", "mithril", "plastic", "glass", + "gemstone", "stone" }; /* Vision */ NEARDATA boolean vision_full_recalc = 0; -NEARDATA char **viz_array = 0;/* used in cansee() and couldsee() macros */ +NEARDATA char **viz_array = 0; /* used in cansee() and couldsee() macros */ /* Global windowing data, defined here for multi-window-system support */ NEARDATA winid WIN_MESSAGE = WIN_ERR; @@ -268,62 +269,63 @@ NEARDATA winid WIN_STATUS = WIN_ERR; NEARDATA winid WIN_MAP = WIN_ERR, WIN_INVEN = WIN_ERR; char toplines[TBUFSZ]; /* Windowing stuff that's really tty oriented, but present for all ports */ -struct tc_gbl_data tc_gbl_data = { 0,0, 0,0 }; /* AS,AE, LI,CO */ +struct tc_gbl_data tc_gbl_data = { 0, 0, 0, 0 }; /* AS,AE, LI,CO */ -char *fqn_prefix[PREFIX_COUNT] = { (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0 , (char *)0 }; +char *fqn_prefix[PREFIX_COUNT] = { (char *) 0, (char *) 0, (char *) 0, + (char *) 0, (char *) 0, (char *) 0, + (char *) 0, (char *) 0, (char *) 0, + (char *) 0 }; #ifdef PREFIXES_IN_USE -char *fqn_prefix_names[PREFIX_COUNT] = { "hackdir", "leveldir", "savedir", - "bonesdir", "datadir", "scoredir", - "lockdir", "sysconfdir", "configdir", - "troubledir" }; +char *fqn_prefix_names[PREFIX_COUNT] = { + "hackdir", "leveldir", "savedir", "bonesdir", "datadir", + "scoredir", "lockdir", "sysconfdir", "configdir", "troubledir" +}; #endif NEARDATA struct savefile_info sfcap = { #ifdef NHSTDC - 0x00000000UL + 0x00000000UL #else - 0x00000000L + 0x00000000L #endif #if defined(COMPRESS) || defined(ZLIB_COMP) - | SFI1_EXTERNALCOMP + | SFI1_EXTERNALCOMP #endif #if defined(ZEROCOMP) - | SFI1_ZEROCOMP + | SFI1_ZEROCOMP #endif #if defined(RLECOMP) - | SFI1_RLECOMP + | SFI1_RLECOMP #endif - , + , #ifdef NHSTDC - 0x00000000UL, 0x00000000UL + 0x00000000UL, 0x00000000UL #else - 0x00000000L, 0x00000000L + 0x00000000L, 0x00000000L #endif }; NEARDATA struct savefile_info sfrestinfo, sfsaveinfo = { #ifdef NHSTDC - 0x00000000UL + 0x00000000UL #else - 0x00000000L + 0x00000000L #endif #if defined(COMPRESS) || defined(ZLIB_COMP) - | SFI1_EXTERNALCOMP + | SFI1_EXTERNALCOMP #endif #if defined(ZEROCOMP) - | SFI1_ZEROCOMP + | SFI1_ZEROCOMP #endif #if defined(RLECOMP) - | SFI1_RLECOMP + | SFI1_RLECOMP #endif - , + , #ifdef NHSTDC - 0x00000000UL, 0x00000000UL + 0x00000000UL, 0x00000000UL #else - 0x00000000L, 0x00000000L + 0x00000000L, 0x00000000L #endif }; diff --git a/src/detect.c b/src/detect.c index 9df7db084..6fc603cf1 100644 --- a/src/detect.c +++ b/src/detect.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 detect.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 detect.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.55 $ */ /* NetHack 3.6 detect.c $Date: 2012/04/16 02:05:40 $ $Revision: 1.47 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,53 +11,60 @@ #include "hack.h" #include "artifact.h" -extern boolean known; /* from read.c */ +extern boolean known; /* from read.c */ STATIC_DCL void FDECL(do_dknown_of, (struct obj *)); -STATIC_DCL boolean FDECL(check_map_spot, (int,int,CHAR_P,unsigned)); -STATIC_DCL boolean FDECL(clear_stale_map, (CHAR_P,unsigned)); -STATIC_DCL void FDECL(sense_trap, (struct trap *,XCHAR_P,XCHAR_P,int)); -STATIC_DCL int FDECL(detect_obj_traps, (struct obj *,BOOLEAN_P,int)); -STATIC_DCL void FDECL(show_map_spot, (int,int)); -STATIC_PTR void FDECL(findone,(int,int,genericptr_t)); -STATIC_PTR void FDECL(openone,(int,int,genericptr_t)); +STATIC_DCL boolean FDECL(check_map_spot, (int, int, CHAR_P, unsigned)); +STATIC_DCL boolean FDECL(clear_stale_map, (CHAR_P, unsigned)); +STATIC_DCL void FDECL(sense_trap, (struct trap *, XCHAR_P, XCHAR_P, int)); +STATIC_DCL int FDECL(detect_obj_traps, (struct obj *, BOOLEAN_P, int)); +STATIC_DCL void FDECL(show_map_spot, (int, int)); +STATIC_PTR void FDECL(findone, (int, int, genericptr_t)); +STATIC_PTR void FDECL(openone, (int, int, genericptr_t)); -/* Recursively search obj for an object in class oclass and return 1st found */ +/* Recursively search obj for an object in class oclass and return 1st found + */ struct obj * o_in(obj, oclass) -struct obj* obj; +struct obj *obj; char oclass; { - register struct obj* otmp; + register struct obj *otmp; struct obj *temp; - if (obj->oclass == oclass) return obj; + if (obj->oclass == oclass) + return obj; if (Has_contents(obj)) { - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) - if (otmp->oclass == oclass) return otmp; - else if (Has_contents(otmp) && (temp = o_in(otmp, oclass))) - return temp; + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) + if (otmp->oclass == oclass) + return otmp; + else if (Has_contents(otmp) && (temp = o_in(otmp, oclass))) + return temp; } return (struct obj *) 0; } -/* Recursively search obj for an object made of specified material and return 1st found */ +/* Recursively search obj for an object made of specified material and return + * 1st found */ struct obj * o_material(obj, material) -struct obj* obj; +struct obj *obj; unsigned material; { - register struct obj* otmp; + register struct obj *otmp; struct obj *temp; - if (objects[obj->otyp].oc_material == material) return obj; + if (objects[obj->otyp].oc_material == material) + return obj; if (Has_contents(obj)) { - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) - if (objects[otmp->otyp].oc_material == material) return otmp; - else if (Has_contents(otmp) && (temp = o_material(otmp, material))) - return temp; + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) + if (objects[otmp->otyp].oc_material == material) + return otmp; + else if (Has_contents(otmp) + && (temp = o_material(otmp, material))) + return temp; } return (struct obj *) 0; } @@ -70,8 +77,8 @@ struct obj *obj; obj->dknown = 1; if (Has_contents(obj)) { - for(otmp = obj->cobj; otmp; otmp = otmp->nobj) - do_dknown_of(otmp); + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) + do_dknown_of(otmp); } } @@ -82,44 +89,52 @@ int x, y; register char oclass; unsigned material; { - register int glyph; - register struct obj *otmp; - register struct monst *mtmp; + register int glyph; + register struct obj *otmp; + register struct monst *mtmp; - glyph = glyph_at(x,y); - if (glyph_is_object(glyph)) { - /* there's some object shown here */ - if (oclass == ALL_CLASSES) { - return((boolean)( !(level.objects[x][y] || /* stale if nothing here */ - ((mtmp = m_at(x,y)) != 0 && ( mtmp->minvent))))); - } else { - if (material && objects[glyph_to_obj(glyph)].oc_material == material) { - /* the object shown here is of interest because material matches */ - for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (o_material(otmp, GOLD)) return FALSE; - /* didn't find it; perhaps a monster is carrying it */ - if ((mtmp = m_at(x,y)) != 0) { - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if (o_material(otmp, GOLD)) return FALSE; - } - /* detection indicates removal of this object from the map */ - return TRUE; - } - if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) { - /* the object shown here is of interest because its class matches */ - for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (o_in(otmp, oclass)) return FALSE; - /* didn't find it; perhaps a monster is carrying it */ - if ((mtmp = m_at(x,y)) != 0) { - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if (o_in(otmp, oclass)) return FALSE; - } - /* detection indicates removal of this object from the map */ - return TRUE; - } - } - } - return FALSE; + glyph = glyph_at(x, y); + if (glyph_is_object(glyph)) { + /* there's some object shown here */ + if (oclass == ALL_CLASSES) { + return ( + (boolean)(!(level.objects[x][y] || /* stale if nothing here */ + ((mtmp = m_at(x, y)) != 0 && (mtmp->minvent))))); + } else { + if (material + && objects[glyph_to_obj(glyph)].oc_material == material) { + /* the object shown here is of interest because material + * matches */ + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (o_material(otmp, GOLD)) + return FALSE; + /* didn't find it; perhaps a monster is carrying it */ + if ((mtmp = m_at(x, y)) != 0) { + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (o_material(otmp, GOLD)) + return FALSE; + } + /* detection indicates removal of this object from the map */ + return TRUE; + } + if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) { + /* the object shown here is of interest because its class + * matches */ + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (o_in(otmp, oclass)) + return FALSE; + /* didn't find it; perhaps a monster is carrying it */ + if ((mtmp = m_at(x, y)) != 0) { + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (o_in(otmp, oclass)) + return FALSE; + } + /* detection indicates removal of this object from the map */ + return TRUE; + } + } + } + return FALSE; } /* @@ -133,17 +148,17 @@ clear_stale_map(oclass, material) register char oclass; unsigned material; { - register int zx, zy; - register boolean change_made = FALSE; + register int zx, zy; + register boolean change_made = FALSE; - for (zx = 1; zx < COLNO; zx++) - for (zy = 0; zy < ROWNO; zy++) - if (check_map_spot(zx, zy, oclass,material)) { - unmap_object(zx, zy); - change_made = TRUE; - } + for (zx = 1; zx < COLNO; zx++) + for (zy = 0; zy < ROWNO; zy++) + if (check_map_spot(zx, zy, oclass, material)) { + unmap_object(zx, zy); + change_made = TRUE; + } - return change_made; + return change_made; } /* look for gold, on the floor or in monsters' possession */ @@ -156,57 +171,61 @@ register struct obj *sobj; struct obj *temp; boolean stale; - known = stale = clear_stale_map(COIN_CLASS, - (unsigned)(sobj->blessed ? GOLD : 0)); + known = stale = + clear_stale_map(COIN_CLASS, (unsigned) (sobj->blessed ? GOLD : 0)); /* look for gold carried by monsters (might be in a container) */ for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; /* probably not needed in this case but... */ - if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { - known = TRUE; - goto outgoldmap; /* skip further searching */ - } else for (obj = mtmp->minvent; obj; obj = obj->nobj) - if (sobj->blessed && o_material(obj, GOLD)) { - known = TRUE; - goto outgoldmap; - } else if (o_in(obj, COIN_CLASS)) { - known = TRUE; - goto outgoldmap; /* skip further searching */ - } + if (DEADMONSTER(mtmp)) + continue; /* probably not needed in this case but... */ + if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { + known = TRUE; + goto outgoldmap; /* skip further searching */ + } else + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if (sobj->blessed && o_material(obj, GOLD)) { + known = TRUE; + goto outgoldmap; + } else if (o_in(obj, COIN_CLASS)) { + known = TRUE; + goto outgoldmap; /* skip further searching */ + } } - + /* look for gold objects */ for (obj = fobj; obj; obj = obj->nobj) { - if (sobj->blessed && o_material(obj, GOLD)) { - known = TRUE; - if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; - } else if (o_in(obj, COIN_CLASS)) { - known = TRUE; - if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; - } + if (sobj->blessed && o_material(obj, GOLD)) { + known = TRUE; + if (obj->ox != u.ux || obj->oy != u.uy) + goto outgoldmap; + } else if (o_in(obj, COIN_CLASS)) { + known = TRUE; + if (obj->ox != u.ux || obj->oy != u.uy) + goto outgoldmap; + } } if (!known) { - /* no gold found on floor or monster's inventory. - adjust message if you have gold in your inventory */ - if (sobj) { - char buf[BUFSZ]; - if (youmonst.data == &mons[PM_GOLD_GOLEM]) { - Sprintf(buf, "You feel like a million %s!", - currency(2L)); - } else if (hidden_gold() || money_cnt(invent)) - Strcpy(buf, - "You feel worried about your future financial situation."); - else - Strcpy(buf, "You feel materially poor."); - strange_feeling(sobj, buf); + /* no gold found on floor or monster's inventory. + adjust message if you have gold in your inventory */ + if (sobj) { + char buf[BUFSZ]; + if (youmonst.data == &mons[PM_GOLD_GOLEM]) { + Sprintf(buf, "You feel like a million %s!", currency(2L)); + } else if (hidden_gold() || money_cnt(invent)) + Strcpy(buf, "You feel worried about your future financial " + "situation."); + else + Strcpy(buf, "You feel materially poor."); + strange_feeling(sobj, buf); } - return(1); + return (1); } /* only under me - no separate display required */ - if (stale) docrt(); + if (stale) + docrt(); You("notice some gold between your %s.", makeplural(body_part(FOOT))); - return(0); + return (0); outgoldmap: cls(); @@ -215,58 +234,62 @@ outgoldmap: u.uinwater = u.uburied = 0; /* Discover gold locations. */ for (obj = fobj; obj; obj = obj->nobj) { - if (sobj->blessed && (temp = o_material(obj, GOLD))) { - if (temp != obj) { - temp->ox = obj->ox; - temp->oy = obj->oy; - } - map_object(temp,1); - } else if ((temp = o_in(obj, COIN_CLASS))) { - if (temp != obj) { - temp->ox = obj->ox; - temp->oy = obj->oy; - } - map_object(temp,1); - } + if (sobj->blessed && (temp = o_material(obj, GOLD))) { + if (temp != obj) { + temp->ox = obj->ox; + temp->oy = obj->oy; + } + map_object(temp, 1); + } else if ((temp = o_in(obj, COIN_CLASS))) { + if (temp != obj) { + temp->ox = obj->ox; + temp->oy = obj->oy; + } + map_object(temp, 1); + } } for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; /* probably overkill here */ - if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { - struct obj gold; - gold = zeroobj; /* ensure oextra is cleared too */ - gold.otyp = GOLD_PIECE; - gold.ox = mtmp->mx; - gold.oy = mtmp->my; - map_object(&gold,1); - } else for (obj = mtmp->minvent; obj; obj = obj->nobj) - if (sobj->blessed && (temp = o_material(obj, GOLD))) { - temp->ox = mtmp->mx; - temp->oy = mtmp->my; - map_object(temp,1); - break; - } else if ((temp = o_in(obj, COIN_CLASS))) { - temp->ox = mtmp->mx; - temp->oy = mtmp->my; - map_object(temp,1); - break; - } + if (DEADMONSTER(mtmp)) + continue; /* probably overkill here */ + if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { + struct obj gold; + gold = zeroobj; /* ensure oextra is cleared too */ + gold.otyp = GOLD_PIECE; + gold.ox = mtmp->mx; + gold.oy = mtmp->my; + map_object(&gold, 1); + } else + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if (sobj->blessed && (temp = o_material(obj, GOLD))) { + temp->ox = mtmp->mx; + temp->oy = mtmp->my; + map_object(temp, 1); + break; + } else if ((temp = o_in(obj, COIN_CLASS))) { + temp->ox = mtmp->mx; + temp->oy = mtmp->my; + map_object(temp, 1); + break; + } } - newsym(u.ux,u.uy); + newsym(u.ux, u.uy); u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You_feel("very greedy, and sense gold!"); exercise(A_WIS, TRUE); display_nhwindow(WIN_MAP, TRUE); docrt(); - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); - return(0); + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); + return (0); } /* returns 1 if nothing was detected */ /* returns 0 if something was detected */ int food_detect(sobj) -register struct obj *sobj; +register struct obj *sobj; { register struct obj *obj; register struct monst *mtmp; @@ -278,90 +301,101 @@ register struct obj *sobj; stale = clear_stale_map(oclass, 0); for (obj = fobj; obj; obj = obj->nobj) - if (o_in(obj, oclass)) { - if (obj->ox == u.ux && obj->oy == u.uy) ctu++; - else ct++; - } + if (o_in(obj, oclass)) { + if (obj->ox == u.ux && obj->oy == u.uy) + ctu++; + else + ct++; + } for (mtmp = fmon; mtmp && !ct; mtmp = mtmp->nmon) { - /* no DEADMONSTER(mtmp) check needed since dmons never have inventory */ - for (obj = mtmp->minvent; obj; obj = obj->nobj) - if (o_in(obj, oclass)) { - ct++; - break; - } + /* no DEADMONSTER(mtmp) check needed since dmons never have inventory + */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if (o_in(obj, oclass)) { + ct++; + break; + } } - + if (!ct && !ctu) { - known = stale && !confused; - if (stale) { - docrt(); - You("sense a lack of %s nearby.", what); - if (sobj && sobj->blessed) { - if (!u.uedibility) Your("%s starts to tingle.", body_part(NOSE)); - u.uedibility = 1; - } - } else if (sobj) { - char buf[BUFSZ]; - Sprintf(buf, "Your %s twitches%s.", body_part(NOSE), - (sobj->blessed && !u.uedibility) ? " then starts to tingle" : ""); - if (sobj->blessed && !u.uedibility) { - boolean savebeginner = flags.beginner; /* prevent non-delivery of */ - flags.beginner = FALSE; /* message */ - strange_feeling(sobj, buf); - flags.beginner = savebeginner; - u.uedibility = 1; - } else - strange_feeling(sobj, buf); - } - return !stale; + known = stale && !confused; + if (stale) { + docrt(); + You("sense a lack of %s nearby.", what); + if (sobj && sobj->blessed) { + if (!u.uedibility) + Your("%s starts to tingle.", body_part(NOSE)); + u.uedibility = 1; + } + } else if (sobj) { + char buf[BUFSZ]; + Sprintf(buf, "Your %s twitches%s.", body_part(NOSE), + (sobj->blessed && !u.uedibility) + ? " then starts to tingle" + : ""); + if (sobj->blessed && !u.uedibility) { + boolean savebeginner = + flags.beginner; /* prevent non-delivery of */ + flags.beginner = FALSE; /* message */ + strange_feeling(sobj, buf); + flags.beginner = savebeginner; + u.uedibility = 1; + } else + strange_feeling(sobj, buf); + } + return !stale; } else if (!ct) { - known = TRUE; - You("%s %s nearby.", sobj ? "smell" : "sense", what); - if (sobj && sobj->blessed) { - if (!u.uedibility) pline("Your %s starts to tingle.", body_part(NOSE)); - u.uedibility = 1; - } + known = TRUE; + You("%s %s nearby.", sobj ? "smell" : "sense", what); + if (sobj && sobj->blessed) { + if (!u.uedibility) + pline("Your %s starts to tingle.", body_part(NOSE)); + u.uedibility = 1; + } } else { - struct obj *temp; - known = TRUE; - cls(); - iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; - u.uinwater = u.uburied = 0; - for (obj = fobj; obj; obj = obj->nobj) - if ((temp = o_in(obj, oclass)) != 0) { - if (temp != obj) { - temp->ox = obj->ox; - temp->oy = obj->oy; - } - map_object(temp,1); - } - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - /* no DEADMONSTER(mtmp) check needed since dmons never have inventory */ - for (obj = mtmp->minvent; obj; obj = obj->nobj) - if ((temp = o_in(obj, oclass)) != 0) { - temp->ox = mtmp->mx; - temp->oy = mtmp->my; - map_object(temp,1); - break; /* skip rest of this monster's inventory */ - } - newsym(u.ux,u.uy); - u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; - if (sobj) { - if (sobj->blessed) { - Your("%s %s to tingle and you smell %s.", body_part(NOSE), - u.uedibility ? "continues" : "starts", what); - u.uedibility = 1; - } else - Your("%s tingles and you smell %s.", body_part(NOSE), what); - } else - You("sense %s.", what); - display_nhwindow(WIN_MAP, TRUE); - exercise(A_WIS, TRUE); - docrt(); - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); + struct obj *temp; + known = TRUE; + cls(); + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; + u.uinwater = u.uburied = 0; + for (obj = fobj; obj; obj = obj->nobj) + if ((temp = o_in(obj, oclass)) != 0) { + if (temp != obj) { + temp->ox = obj->ox; + temp->oy = obj->oy; + } + map_object(temp, 1); + } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + /* no DEADMONSTER(mtmp) check needed since dmons never have + * inventory */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if ((temp = o_in(obj, oclass)) != 0) { + temp->ox = mtmp->mx; + temp->oy = mtmp->my; + map_object(temp, 1); + break; /* skip rest of this monster's inventory */ + } + newsym(u.ux, u.uy); + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; + if (sobj) { + if (sobj->blessed) { + Your("%s %s to tingle and you smell %s.", body_part(NOSE), + u.uedibility ? "continues" : "starts", what); + u.uedibility = 1; + } else + Your("%s tingles and you smell %s.", body_part(NOSE), what); + } else + You("sense %s.", what); + display_nhwindow(WIN_MAP, TRUE); + exercise(A_WIS, TRUE); + docrt(); + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); } - return(0); + return (0); } /* @@ -372,23 +406,23 @@ register struct obj *sobj; */ int object_detect(detector, class) -struct obj *detector; /* object doing the detecting */ -int class; /* an object class, 0 for all */ +struct obj *detector; /* object doing the detecting */ +int class; /* an object class, 0 for all */ { register int x, y; char stuff[BUFSZ]; int is_cursed = (detector && detector->cursed); - int do_dknown = (detector && (detector->oclass == POTION_CLASS || - detector->oclass == SPBOOK_CLASS) && - detector->blessed); + int do_dknown = (detector && (detector->oclass == POTION_CLASS + || detector->oclass == SPBOOK_CLASS) + && detector->blessed); int ct = 0, ctu = 0; - register struct obj *obj, *otmp = (struct obj *)0; + register struct obj *obj, *otmp = (struct obj *) 0; register struct monst *mtmp; int sym, boulder = 0; if (class < 0 || class >= MAXOCLASSES) { - impossible("object_detect: illegal class %d", class); - class = 0; + impossible("object_detect: illegal class %d", class); + class = 0; } /* Special boulder symbol check - does the class symbol happen @@ -399,75 +433,88 @@ int class; /* an object class, 0 for all */ */ sym = class ? def_oc_syms[class].sym : 0; if (sym && iflags.bouldersym && sym == iflags.bouldersym) - boulder = ROCK_CLASS; + boulder = ROCK_CLASS; if (Hallucination || (Confusion && class == SCROLL_CLASS)) - Strcpy(stuff, something); + Strcpy(stuff, something); else - Strcpy(stuff, class ? def_oc_syms[class].name : "objects"); - if (boulder && class != ROCK_CLASS) Strcat(stuff, " and/or large stones"); + Strcpy(stuff, class ? def_oc_syms[class].name : "objects"); + if (boulder && class != ROCK_CLASS) + Strcat(stuff, " and/or large stones"); - if (do_dknown) for(obj = invent; obj; obj = obj->nobj) do_dknown_of(obj); + if (do_dknown) + for (obj = invent; obj; obj = obj->nobj) + do_dknown_of(obj); for (obj = fobj; obj; obj = obj->nobj) { - if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { - if (obj->ox == u.ux && obj->oy == u.uy) ctu++; - else ct++; - } - if (do_dknown) do_dknown_of(obj); + if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { + if (obj->ox == u.ux && obj->oy == u.uy) + ctu++; + else + ct++; + } + if (do_dknown) + do_dknown_of(obj); } for (obj = level.buriedobjlist; obj; obj = obj->nobj) { - if (!class || o_in(obj, class)) { - if (obj->ox == u.ux && obj->oy == u.uy) ctu++; - else ct++; - } - if (do_dknown) do_dknown_of(obj); + if (!class || o_in(obj, class)) { + if (obj->ox == u.ux && obj->oy == u.uy) + ctu++; + else + ct++; + } + if (do_dknown) + do_dknown_of(obj); } for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - for (obj = mtmp->minvent; obj; obj = obj->nobj) { - if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) ct++; - if (do_dknown) do_dknown_of(obj); - } - if ((is_cursed && mtmp->m_ap_type == M_AP_OBJECT && - (!class || class == objects[mtmp->mappearance].oc_class)) || - (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) { - ct++; - break; - } + if (DEADMONSTER(mtmp)) + continue; + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + if ((!class && !boulder) || o_in(obj, class) + || o_in(obj, boulder)) + ct++; + if (do_dknown) + do_dknown_of(obj); + } + if ((is_cursed && mtmp->m_ap_type == M_AP_OBJECT + && (!class || class == objects[mtmp->mappearance].oc_class)) + || (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) { + ct++; + break; + } } if (!clear_stale_map(!class ? ALL_CLASSES : class, 0) && !ct) { - if (!ctu) { - if (detector) - strange_feeling(detector, "You feel a lack of something."); - return 1; - } + if (!ctu) { + if (detector) + strange_feeling(detector, "You feel a lack of something."); + return 1; + } - You("sense %s nearby.", stuff); - return 0; + You("sense %s nearby.", stuff); + return 0; } cls(); iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; -/* - * Map all buried objects first. - */ + /* + * Map all buried objects first. + */ for (obj = level.buriedobjlist; obj; obj = obj->nobj) - if (!class || (otmp = o_in(obj, class))) { - if (class) { - if (otmp != obj) { - otmp->ox = obj->ox; - otmp->oy = obj->oy; - } - map_object(otmp, 1); - } else - map_object(obj, 1); - } + if (!class || (otmp = o_in(obj, class))) { + if (class) { + if (otmp != obj) { + otmp->ox = obj->ox; + otmp->oy = obj->oy; + } + map_object(otmp, 1); + } else + map_object(obj, 1); + } /* * If we are mapping all objects, map only the top object of a pile or * the first object in a monster's inventory. Otherwise, go looking @@ -477,55 +524,58 @@ int class; /* an object class, 0 for all */ * Objects on the floor override buried objects. */ for (x = 1; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - for (obj = level.objects[x][y]; obj; obj = obj->nexthere) - if ((!class && !boulder) || - (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) { - if (class || boulder) { - if (otmp != obj) { - otmp->ox = obj->ox; - otmp->oy = obj->oy; - } - map_object(otmp, 1); - } else - map_object(obj, 1); - break; - } + for (y = 0; y < ROWNO; y++) + for (obj = level.objects[x][y]; obj; obj = obj->nexthere) + if ((!class && !boulder) || (otmp = o_in(obj, class)) + || (otmp = o_in(obj, boulder))) { + if (class || boulder) { + if (otmp != obj) { + otmp->ox = obj->ox; + otmp->oy = obj->oy; + } + map_object(otmp, 1); + } else + map_object(obj, 1); + break; + } /* Objects in the monster's inventory override floor objects. */ - for (mtmp = fmon ; mtmp ; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - for (obj = mtmp->minvent; obj; obj = obj->nobj) - if ((!class && !boulder) || - (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) { - if (!class && !boulder) otmp = obj; - otmp->ox = mtmp->mx; /* at monster location */ - otmp->oy = mtmp->my; - map_object(otmp, 1); - break; - } - /* Allow a mimic to override the detected objects it is carrying. */ - if (is_cursed && mtmp->m_ap_type == M_AP_OBJECT && - (!class || class == objects[mtmp->mappearance].oc_class)) { - struct obj temp; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if ((!class && !boulder) || (otmp = o_in(obj, class)) + || (otmp = o_in(obj, boulder))) { + if (!class && !boulder) + otmp = obj; + otmp->ox = mtmp->mx; /* at monster location */ + otmp->oy = mtmp->my; + map_object(otmp, 1); + break; + } + /* Allow a mimic to override the detected objects it is carrying. */ + if (is_cursed && mtmp->m_ap_type == M_AP_OBJECT + && (!class || class == objects[mtmp->mappearance].oc_class)) { + struct obj temp; - temp.oextra = (struct oextra *)0; - temp.otyp = mtmp->mappearance; /* needed for obj_to_glyph() */ - temp.ox = mtmp->mx; - temp.oy = mtmp->my; - temp.corpsenm = PM_TENGU; /* if mimicing a corpse */ - map_object(&temp, 1); - } else if (findgold(mtmp->minvent) && (!class || class == COIN_CLASS)) { - struct obj gold; - gold = zeroobj; /* ensure oextra is cleared too */ - gold.otyp = GOLD_PIECE; - gold.ox = mtmp->mx; - gold.oy = mtmp->my; - map_object(&gold, 1); - } + temp.oextra = (struct oextra *) 0; + temp.otyp = mtmp->mappearance; /* needed for obj_to_glyph() */ + temp.ox = mtmp->mx; + temp.oy = mtmp->my; + temp.corpsenm = PM_TENGU; /* if mimicing a corpse */ + map_object(&temp, 1); + } else if (findgold(mtmp->minvent) + && (!class || class == COIN_CLASS)) { + struct obj gold; + gold = zeroobj; /* ensure oextra is cleared too */ + gold.otyp = GOLD_PIECE; + gold.ox = mtmp->mx; + gold.oy = mtmp->my; + map_object(&gold, 1); + } } - newsym(u.ux,u.uy); + newsym(u.ux, u.uy); u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You("detect the %s of %s.", ct ? "presence" : "absence", stuff); display_nhwindow(WIN_MAP, TRUE); @@ -533,10 +583,12 @@ int class; /* an object class, 0 for all */ * What are we going to do when the hero does an object detect while blind * and the detected object covers a known pool? */ - docrt(); /* this will correctly reset vision */ + docrt(); /* this will correctly reset vision */ - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); return 0; } @@ -548,62 +600,66 @@ int class; /* an object class, 0 for all */ */ int monster_detect(otmp, mclass) -register struct obj *otmp; /* detecting object (if any) */ -int mclass; /* monster class, 0 for all */ +register struct obj *otmp; /* detecting object (if any) */ +int mclass; /* monster class, 0 for all */ { register struct monst *mtmp; int mcnt = 0; - /* Note: This used to just check fmon for a non-zero value * but in versions since 3.3.0 fmon can test TRUE due to the * presence of dmons, so we have to find at least one * with positive hit-points to know for sure. */ for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (!DEADMONSTER(mtmp)) { - mcnt++; - break; - } + if (!DEADMONSTER(mtmp)) { + mcnt++; + break; + } if (!mcnt) { - if (otmp) - strange_feeling(otmp, Hallucination ? - "You get the heebie jeebies." : - "You feel threatened."); - return 1; + if (otmp) + strange_feeling(otmp, Hallucination + ? "You get the heebie jeebies." + : "You feel threatened."); + return 1; } else { - boolean woken = FALSE; + boolean woken = FALSE; - cls(); - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (!mclass || mtmp->data->mlet == mclass || - (mtmp->data == &mons[PM_LONG_WORM] && mclass == S_WORM_TAIL)) - if (mtmp->mx > 0) { - if (mclass && def_monsyms[mclass].sym == ' ') - show_glyph(mtmp->mx,mtmp->my, - detected_mon_to_glyph(mtmp)); - else - show_glyph(mtmp->mx,mtmp->my,mon_to_glyph(mtmp)); - /* don't be stingy - display entire worm */ - if (mtmp->data == &mons[PM_LONG_WORM]) detect_wsegs(mtmp,0); - } - if (otmp && otmp->cursed && - (mtmp->msleeping || !mtmp->mcanmove)) { - mtmp->msleeping = mtmp->mfrozen = 0; - mtmp->mcanmove = 1; - woken = TRUE; - } - } - display_self(); - You("sense the presence of monsters."); - if (woken) - pline("Monsters sense the presence of you."); - display_nhwindow(WIN_MAP, TRUE); - docrt(); - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); + cls(); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (!mclass || mtmp->data->mlet == mclass + || (mtmp->data == &mons[PM_LONG_WORM] + && mclass == S_WORM_TAIL)) + if (mtmp->mx > 0) { + if (mclass && def_monsyms[mclass].sym == ' ') + show_glyph(mtmp->mx, mtmp->my, + detected_mon_to_glyph(mtmp)); + else + show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp)); + /* don't be stingy - display entire worm */ + if (mtmp->data == &mons[PM_LONG_WORM]) + detect_wsegs(mtmp, 0); + } + if (otmp && otmp->cursed + && (mtmp->msleeping || !mtmp->mcanmove)) { + mtmp->msleeping = mtmp->mfrozen = 0; + mtmp->mcanmove = 1; + woken = TRUE; + } + } + display_self(); + You("sense the presence of monsters."); + if (woken) + pline("Monsters sense the presence of you."); + display_nhwindow(WIN_MAP, TRUE); + docrt(); + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); } return 0; } @@ -615,35 +671,34 @@ xchar x, y; int src_cursed; { if (Hallucination || src_cursed) { - struct obj obj; /* fake object */ + struct obj obj; /* fake object */ - obj.oextra = (struct oextra *)0; - if (trap) { - obj.ox = trap->tx; - obj.oy = trap->ty; - } else { - obj.ox = x; - obj.oy = y; - } - obj.otyp = (src_cursed) ? GOLD_PIECE : random_object(); - obj.corpsenm = random_monster(); /* if otyp == CORPSE */ - map_object(&obj,1); + obj.oextra = (struct oextra *) 0; + if (trap) { + obj.ox = trap->tx; + obj.oy = trap->ty; + } else { + obj.ox = x; + obj.oy = y; + } + obj.otyp = (src_cursed) ? GOLD_PIECE : random_object(); + obj.corpsenm = random_monster(); /* if otyp == CORPSE */ + map_object(&obj, 1); } else if (trap) { - map_trap(trap,1); - trap->tseen = 1; + map_trap(trap, 1); + trap->tseen = 1; } else { - struct trap temp_trap; /* fake trap */ - temp_trap.tx = x; - temp_trap.ty = y; - temp_trap.ttyp = BEAR_TRAP; /* some kind of trap */ - map_trap(&temp_trap,1); + struct trap temp_trap; /* fake trap */ + temp_trap.tx = x; + temp_trap.ty = y; + temp_trap.ttyp = BEAR_TRAP; /* some kind of trap */ + map_trap(&temp_trap, 1); } - } -#define OTRAP_NONE 0 /* nothing found */ -#define OTRAP_HERE 1 /* found at hero's location */ -#define OTRAP_THERE 2 /* found at any other location */ +#define OTRAP_NONE 0 /* nothing found */ +#define OTRAP_HERE 1 /* found at hero's location */ +#define OTRAP_THERE 2 /* found at any other location */ /* check a list of objects for chest traps; return 1 if found at , 2 if found at some other spot, 3 if both, 0 otherwise; optionally @@ -652,20 +707,21 @@ STATIC_OVL int detect_obj_traps(objlist, show_them, how) struct obj *objlist; boolean show_them; -int how; /* 1 for misleading map feedback */ +int how; /* 1 for misleading map feedback */ { struct obj *otmp; xchar x, y; int result = OTRAP_NONE; for (otmp = objlist; otmp; otmp = otmp->nobj) { - if (Is_box(otmp) && otmp->otrapped && - get_obj_location(otmp, &x, &y, BURIED_TOO|CONTAINED_TOO)) { - result |= (x == u.ux && y == u.uy) ? OTRAP_HERE : OTRAP_THERE; - if (show_them) sense_trap((struct trap *)0, x, y, how); - } - if (Has_contents(otmp)) - result |= detect_obj_traps(otmp->cobj, show_them, how); + if (Is_box(otmp) && otmp->otrapped + && get_obj_location(otmp, &x, &y, BURIED_TOO | CONTAINED_TOO)) { + result |= (x == u.ux && y == u.uy) ? OTRAP_HERE : OTRAP_THERE; + if (show_them) + sense_trap((struct trap *) 0, x, y, how); + } + if (Has_contents(otmp)) + result |= detect_obj_traps(otmp->cobj, show_them, how); } return result; } @@ -688,47 +744,57 @@ register struct obj *sobj; /* floor/ceiling traps */ for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { - if (ttmp->tx != u.ux || ttmp->ty != u.uy) - goto outtrapmap; - else found = TRUE; + if (ttmp->tx != u.ux || ttmp->ty != u.uy) + goto outtrapmap; + else + found = TRUE; } /* chest traps (might be buried or carried) */ if ((tr = detect_obj_traps(fobj, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) goto outtrapmap; - else found = TRUE; + if (tr & OTRAP_THERE) + goto outtrapmap; + else + found = TRUE; } - if ((tr = detect_obj_traps(level.buriedobjlist, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) goto outtrapmap; - else found = TRUE; + if ((tr = detect_obj_traps(level.buriedobjlist, FALSE, 0)) + != OTRAP_NONE) { + if (tr & OTRAP_THERE) + goto outtrapmap; + else + found = TRUE; } for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - if ((tr = detect_obj_traps(mon->minvent, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) goto outtrapmap; - else found = TRUE; - } + if (DEADMONSTER(mon)) + continue; + if ((tr = detect_obj_traps(mon->minvent, FALSE, 0)) != OTRAP_NONE) { + if (tr & OTRAP_THERE) + goto outtrapmap; + else + found = TRUE; + } } if (detect_obj_traps(invent, FALSE, 0) != OTRAP_NONE) - found = TRUE; + found = TRUE; /* door traps */ for (door = 0; door < doorindex; door++) { - cc = doors[door]; - if (levl[cc.x][cc.y].doormask & D_TRAPPED) { - if (cc.x != u.ux || cc.y != u.uy) - goto outtrapmap; - else found = TRUE; - } + cc = doors[door]; + if (levl[cc.x][cc.y].doormask & D_TRAPPED) { + if (cc.x != u.ux || cc.y != u.uy) + goto outtrapmap; + else + found = TRUE; + } } if (!found) { - char buf[BUFSZ]; + char buf[BUFSZ]; - Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE))); - strange_feeling(sobj,buf); - return(1); + Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE))); + strange_feeling(sobj, buf); + return (1); } /* traps exist, but only under me - no separate display required */ Your("%s itch.", makeplural(body_part(TOE))); - return(0); + return (0); outtrapmap: cls(); @@ -740,33 +806,36 @@ outtrapmap: (void) detect_obj_traps(fobj, TRUE, cursed_src); (void) detect_obj_traps(level.buriedobjlist, TRUE, cursed_src); for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - (void) detect_obj_traps(mon->minvent, TRUE, cursed_src); + if (DEADMONSTER(mon)) + continue; + (void) detect_obj_traps(mon->minvent, TRUE, cursed_src); } (void) detect_obj_traps(invent, TRUE, cursed_src); for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) - sense_trap(ttmp, 0, 0, cursed_src); + sense_trap(ttmp, 0, 0, cursed_src); for (door = 0; door < doorindex; door++) { - cc = doors[door]; - if (levl[cc.x][cc.y].doormask & D_TRAPPED) - sense_trap((struct trap *)0, cc.x, cc.y, cursed_src); + cc = doors[door]; + if (levl[cc.x][cc.y].doormask & D_TRAPPED) + sense_trap((struct trap *) 0, cc.x, cc.y, cursed_src); } /* redisplay hero unless sense_trap() revealed something at */ glyph = glyph_at(u.ux, u.uy); if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) - newsym(u.ux, u.uy); + newsym(u.ux, u.uy); u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); /* wait for user to respond, then reset map display to normal */ display_nhwindow(WIN_MAP, TRUE); docrt(); - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); - return(0); + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); + return (0); } const char * @@ -777,38 +846,49 @@ d_level *where; register boolean indun = (u.uz.dnum == where->dnum); if (ll < 0) { - if (ll < (-8 - rn2(3))) - if (!indun) return "far away"; - else return "far below"; - else if (ll < -1) - if (!indun) return "away below you"; - else return "below you"; - else - if (!indun) return "in the distance"; - else return "just below"; + if (ll < (-8 - rn2(3))) + if (!indun) + return "far away"; + else + return "far below"; + else if (ll < -1) + if (!indun) + return "away below you"; + else + return "below you"; + else if (!indun) + return "in the distance"; + else + return "just below"; } else if (ll > 0) { - if (ll > (8 + rn2(3))) - if (!indun) return "far away"; - else return "far above"; - else if (ll > 1) - if (!indun) return "away above you"; - else return "above you"; - else - if (!indun) return "in the distance"; - else return "just above"; - } else - if (!indun) return "in the distance"; - else return "near you"; + if (ll > (8 + rn2(3))) + if (!indun) + return "far away"; + else + return "far above"; + else if (ll > 1) + if (!indun) + return "away above you"; + else + return "above you"; + else if (!indun) + return "in the distance"; + else + return "just above"; + } else if (!indun) + return "in the distance"; + else + return "near you"; } static const struct { const char *what; d_level *where; } level_detects[] = { - { "Delphi", &oracle_level }, - { "Medusa's lair", &medusa_level }, - { "a castle", &stronghold_level }, - { "the Wizard of Yendor's tower", &wiz1_level }, + { "Delphi", &oracle_level }, + { "Medusa's lair", &medusa_level }, + { "a castle", &stronghold_level }, + { "the Wizard of Yendor's tower", &wiz1_level }, }; void @@ -819,119 +899,136 @@ struct obj *obj; int oops; if (Blind) { - pline("Too bad you can't see %s.", the(xname(obj))); - return; + pline("Too bad you can't see %s.", the(xname(obj))); + return; } oops = (rnd(20) > ACURR(A_INT) || obj->cursed); if (oops && (obj->spe > 0)) { - switch (rnd(obj->oartifact ? 4 : 5)) { - case 1 : pline("%s too much to comprehend!", Tobjnam(obj, "are")); - break; - case 2 : pline("%s you!", Tobjnam(obj, "confuse")); - make_confused((HConfusion & TIMEOUT) + (long)rnd(100), FALSE); - break; - case 3 : if (!resists_blnd(&youmonst)) { - pline("%s your vision!", Tobjnam(obj, "damage")); - make_blinded((Blinded & TIMEOUT) + (long)rnd(100), FALSE); - if (!Blind) Your1(vision_clears); - } else { - pline("%s your vision.", Tobjnam(obj, "assault")); - You("are unaffected!"); - } - break; - case 4 : pline("%s your mind!", Tobjnam(obj, "zap")); - (void) make_hallucinated((HHallucination & TIMEOUT) + - (long)rnd(100), FALSE, 0L); - break; - case 5 : pline("%s!", Tobjnam(obj, "explode")); - useup(obj); - obj = 0; /* it's gone */ - /* physical damage cause by the shards and force */ - losehp(Maybe_Half_Phys(rnd(30)), - "exploding crystal ball", KILLED_BY_AN); - break; - } - if (obj) consume_obj_charge(obj, TRUE); - return; + switch (rnd(obj->oartifact ? 4 : 5)) { + case 1: + pline("%s too much to comprehend!", Tobjnam(obj, "are")); + break; + case 2: + pline("%s you!", Tobjnam(obj, "confuse")); + make_confused((HConfusion & TIMEOUT) + (long) rnd(100), FALSE); + break; + case 3: + if (!resists_blnd(&youmonst)) { + pline("%s your vision!", Tobjnam(obj, "damage")); + make_blinded((Blinded & TIMEOUT) + (long) rnd(100), FALSE); + if (!Blind) + Your1(vision_clears); + } else { + pline("%s your vision.", Tobjnam(obj, "assault")); + You("are unaffected!"); + } + break; + case 4: + pline("%s your mind!", Tobjnam(obj, "zap")); + (void) make_hallucinated( + (HHallucination & TIMEOUT) + (long) rnd(100), FALSE, 0L); + break; + case 5: + pline("%s!", Tobjnam(obj, "explode")); + useup(obj); + obj = 0; /* it's gone */ + /* physical damage cause by the shards and force */ + losehp(Maybe_Half_Phys(rnd(30)), "exploding crystal ball", + KILLED_BY_AN); + break; + } + if (obj) + consume_obj_charge(obj, TRUE); + return; } if (Hallucination) { - if (!obj->spe) { - pline("All you see is funky %s haze.", hcolor((char *)0)); - } else { - switch(rnd(6)) { - case 1 : You("grok some groovy globs of incandescent lava."); - break; - case 2 : pline("Whoa! Psychedelic colors, %s!", - poly_gender() == 1 ? "babe" : "dude"); - break; - case 3 : pline_The("crystal pulses with sinister %s light!", - hcolor((char *)0)); - break; - case 4 : You_see("goldfish swimming above fluorescent rocks."); - break; - case 5 : You_see("tiny snowflakes spinning around a miniature farmhouse."); - break; - default: pline("Oh wow... like a kaleidoscope!"); - break; - } - consume_obj_charge(obj, TRUE); - } - return; + if (!obj->spe) { + pline("All you see is funky %s haze.", hcolor((char *) 0)); + } else { + switch (rnd(6)) { + case 1: + You("grok some groovy globs of incandescent lava."); + break; + case 2: + pline("Whoa! Psychedelic colors, %s!", + poly_gender() == 1 ? "babe" : "dude"); + break; + case 3: + pline_The("crystal pulses with sinister %s light!", + hcolor((char *) 0)); + break; + case 4: + You_see("goldfish swimming above fluorescent rocks."); + break; + case 5: + You_see( + "tiny snowflakes spinning around a miniature farmhouse."); + break; + default: + pline("Oh wow... like a kaleidoscope!"); + break; + } + consume_obj_charge(obj, TRUE); + } + return; } /* read a single character */ - if (flags.verbose) You("may look for an object or monster symbol."); - ch = yn_function("What do you look for?", (char *)0, '\0'); + if (flags.verbose) + You("may look for an object or monster symbol."); + ch = yn_function("What do you look for?", (char *) 0, '\0'); /* Don't filter out ' ' here; it has a use */ - if ((ch != def_monsyms[S_GHOST].sym) && index(quitchars,ch)) { - if (flags.verbose) pline1(Never_mind); - return; + if ((ch != def_monsyms[S_GHOST].sym) && index(quitchars, ch)) { + if (flags.verbose) + pline1(Never_mind); + return; } You("peer into %s...", the(xname(obj))); nomul(-rnd(10)); multi_reason = "gazing into a crystal ball"; nomovemsg = ""; if (obj->spe <= 0) - pline_The("vision is unclear."); + pline_The("vision is unclear."); else { - int class; - int ret = 0; + int class; + int ret = 0; - makeknown(CRYSTAL_BALL); - consume_obj_charge(obj, TRUE); + makeknown(CRYSTAL_BALL); + consume_obj_charge(obj, TRUE); - /* special case: accept ']' as synonym for mimic - * we have to do this before the def_char_to_objclass check - */ - if (ch == DEF_MIMIC_DEF) ch = DEF_MIMIC; + /* special case: accept ']' as synonym for mimic + * we have to do this before the def_char_to_objclass check + */ + if (ch == DEF_MIMIC_DEF) + ch = DEF_MIMIC; - if ((class = def_char_to_objclass(ch)) != MAXOCLASSES) - ret = object_detect((struct obj *)0, class); - else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) - ret = monster_detect((struct obj *)0, class); - else if (iflags.bouldersym && (ch == iflags.bouldersym)) - ret = object_detect((struct obj *)0, ROCK_CLASS); - else switch(ch) { - case '^': - ret = trap_detect((struct obj *)0); - break; - default: - { - int i = rn2(SIZE(level_detects)); - You_see("%s, %s.", - level_detects[i].what, - level_distance(level_detects[i].where)); - } - ret = 0; - break; - } + if ((class = def_char_to_objclass(ch)) != MAXOCLASSES) + ret = object_detect((struct obj *) 0, class); + else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) + ret = monster_detect((struct obj *) 0, class); + else if (iflags.bouldersym && (ch == iflags.bouldersym)) + ret = object_detect((struct obj *) 0, ROCK_CLASS); + else + switch (ch) { + case '^': + ret = trap_detect((struct obj *) 0); + break; + default: { + int i = rn2(SIZE(level_detects)); + You_see("%s, %s.", level_detects[i].what, + level_distance(level_detects[i].where)); + } + ret = 0; + break; + } - if (ret) { - if (!rn2(100)) /* make them nervous */ - You_see("the Wizard of Yendor gazing out at you."); - else pline_The("vision is unclear."); - } + if (ret) { + if (!rn2(100)) /* make them nervous */ + You_see("the Wizard of Yendor gazing out at you."); + else + pline_The("vision is unclear."); + } } return; } @@ -944,15 +1041,16 @@ register int x, y; struct trap *t; int oldglyph; - if (Confusion && rn2(7)) return; + if (Confusion && rn2(7)) + return; lev = &levl[x][y]; lev->seenv = SVALL; /* Secret corridors are found, but not secret doors. */ if (lev->typ == SCORR) { - lev->typ = CORR; - unblock_point(x,y); + lev->typ = CORR; + unblock_point(x, y); } /* @@ -964,18 +1062,19 @@ register int x, y; */ oldglyph = glyph_at(x, y); if (level.flags.hero_memory) { - magic_map_background(x, y, 0); - newsym(x, y); /* show it, if not blocked */ + magic_map_background(x, y, 0); + newsym(x, y); /* show it, if not blocked */ } else { - magic_map_background(x, y, 1); /* display it */ + magic_map_background(x, y, 1); /* display it */ } if (!IS_FURNITURE(lev->typ)) { - if ((t = t_at(x, y)) != 0 && t->tseen) { - map_trap(t, 1); - } else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) { - show_glyph(x, y, oldglyph); - if (level.flags.hero_memory) lev->glyph = oldglyph; - } + if ((t = t_at(x, y)) != 0 && t->tseen) { + map_trap(t, 1); + } else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) { + show_glyph(x, y, oldglyph); + if (level.flags.hero_memory) + lev->glyph = oldglyph; + } } } @@ -987,13 +1086,13 @@ do_mapping() iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; for (zx = 1; zx < COLNO; zx++) - for (zy = 0; zy < ROWNO; zy++) - show_map_spot(zx, zy); + for (zy = 0; zy < ROWNO; zy++) + show_map_spot(zx, zy); u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; if (!level.flags.hero_memory || Underwater) { - flush_screen(1); /* flush temp screen */ - display_nhwindow(WIN_MAP, TRUE); /* wait */ - docrt(); + flush_screen(1); /* flush temp screen */ + display_nhwindow(WIN_MAP, TRUE); /* wait */ + docrt(); } exercise(A_WIS, TRUE); } @@ -1002,19 +1101,19 @@ void do_vicinity_map() { register int zx, zy; - int lo_y = (u.uy-5 < 0 ? 0 : u.uy-5), - hi_y = (u.uy+6 > ROWNO ? ROWNO : u.uy+6), - lo_x = (u.ux-9 < 1 ? 1 : u.ux-9), /* avoid column 0 */ - hi_x = (u.ux+10 > COLNO ? COLNO : u.ux+10); + int lo_y = (u.uy - 5 < 0 ? 0 : u.uy - 5), + hi_y = (u.uy + 6 > ROWNO ? ROWNO : u.uy + 6), + lo_x = (u.ux - 9 < 1 ? 1 : u.ux - 9), /* avoid column 0 */ + hi_x = (u.ux + 10 > COLNO ? COLNO : u.ux + 10); for (zx = lo_x; zx < hi_x; zx++) - for (zy = lo_y; zy < hi_y; zy++) - show_map_spot(zx, zy); + for (zy = lo_y; zy < hi_y; zy++) + show_map_spot(zx, zy); if (!level.flags.hero_memory || Underwater) { - flush_screen(1); /* flush temp screen */ - display_nhwindow(WIN_MAP, TRUE); /* wait */ - docrt(); + flush_screen(1); /* flush temp screen */ + display_nhwindow(WIN_MAP, TRUE); /* wait */ + docrt(); } } @@ -1023,159 +1122,160 @@ void cvt_sdoor_to_door(lev) struct rm *lev; { - int newmask = lev->doormask & ~WM_MASK; + int newmask = lev->doormask & ~WM_MASK; - if (Is_rogue_level(&u.uz)) - /* rogue didn't have doors, only doorways */ - newmask = D_NODOOR; - else - /* newly exposed door is closed */ - if (!(newmask & D_LOCKED)) newmask |= D_CLOSED; + if (Is_rogue_level(&u.uz)) + /* rogue didn't have doors, only doorways */ + newmask = D_NODOOR; + else + /* newly exposed door is closed */ + if (!(newmask & D_LOCKED)) + newmask |= D_CLOSED; - lev->typ = DOOR; - lev->doormask = newmask; -} - - -STATIC_PTR void -findone(zx,zy,num) -int zx,zy; -genericptr_t num; -{ - register struct trap *ttmp; - register struct monst *mtmp; - - if(levl[zx][zy].typ == SDOOR) { - cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ - magic_map_background(zx, zy, 0); - newsym(zx, zy); - (*(int*)num)++; - } else if(levl[zx][zy].typ == SCORR) { - levl[zx][zy].typ = CORR; - unblock_point(zx,zy); - magic_map_background(zx, zy, 0); - newsym(zx, zy); - (*(int*)num)++; - } else if ((ttmp = t_at(zx, zy)) != 0) { - if(!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { - ttmp->tseen = 1; - newsym(zx,zy); - (*(int*)num)++; - } - } else if ((mtmp = m_at(zx, zy)) != 0) { - if(mtmp->m_ap_type) { - seemimic(mtmp); - (*(int*)num)++; - } - if (mtmp->mundetected && - (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) { - mtmp->mundetected = 0; - newsym(zx, zy); - (*(int*)num)++; - } - if (!canspotmon(mtmp) && - !glyph_is_invisible(levl[zx][zy].glyph)) - map_invisible(zx, zy); - } else if (glyph_is_invisible(levl[zx][zy].glyph)) { - unmap_object(zx, zy); - newsym(zx, zy); - (*(int*)num)++; - } + lev->typ = DOOR; + lev->doormask = newmask; } STATIC_PTR void -openone(zx,zy,num) -int zx,zy; +findone(zx, zy, num) +int zx, zy; genericptr_t num; { - register struct trap *ttmp; - register struct obj *otmp; - int *num_p = (int *)num; + register struct trap *ttmp; + register struct monst *mtmp; - if(OBJ_AT(zx, zy)) { - for(otmp = level.objects[zx][zy]; - otmp; otmp = otmp->nexthere) { - if(Is_box(otmp) && otmp->olocked) { - otmp->olocked = 0; - (*num_p)++; - } - } - /* let it fall to the next cases. could be on trap. */ - } - if(levl[zx][zy].typ == SDOOR || (levl[zx][zy].typ == DOOR && - (levl[zx][zy].doormask & (D_CLOSED|D_LOCKED)))) { - if(levl[zx][zy].typ == SDOOR) - cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ - if(levl[zx][zy].doormask & D_TRAPPED) { - if(distu(zx, zy) < 3) b_trapped("door", 0); - else Norep("You %s an explosion!", - cansee(zx, zy) ? "see" : - (!Deaf ? "hear" : - "feel the shock of")); - wake_nearto(zx, zy, 11*11); - levl[zx][zy].doormask = D_NODOOR; - } else - levl[zx][zy].doormask = D_ISOPEN; - unblock_point(zx, zy); - newsym(zx, zy); - (*num_p)++; - } else if(levl[zx][zy].typ == SCORR) { - levl[zx][zy].typ = CORR; - unblock_point(zx, zy); - newsym(zx, zy); - (*num_p)++; - } else if ((ttmp = t_at(zx, zy)) != 0) { - struct monst *mon; - boolean dummy; /* unneeded "you notice it arg" */ - - if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { - ttmp->tseen = 1; - newsym(zx,zy); - (*num_p)++; - } - mon = (zx == u.ux && zy == u.uy) ? &youmonst : m_at(zx, zy); - if (openholdingtrap(mon, &dummy) || - openfallingtrap(mon, TRUE, &dummy)) - (*num_p)++; - } else if (find_drawbridge(&zx, &zy)) { - /* make sure it isn't an open drawbridge */ - open_drawbridge(zx, zy); - (*num_p)++; - } + if (levl[zx][zy].typ == SDOOR) { + cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ + magic_map_background(zx, zy, 0); + newsym(zx, zy); + (*(int *) num)++; + } else if (levl[zx][zy].typ == SCORR) { + levl[zx][zy].typ = CORR; + unblock_point(zx, zy); + magic_map_background(zx, zy, 0); + newsym(zx, zy); + (*(int *) num)++; + } else if ((ttmp = t_at(zx, zy)) != 0) { + if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { + ttmp->tseen = 1; + newsym(zx, zy); + (*(int *) num)++; + } + } else if ((mtmp = m_at(zx, zy)) != 0) { + if (mtmp->m_ap_type) { + seemimic(mtmp); + (*(int *) num)++; + } + if (mtmp->mundetected + && (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) { + mtmp->mundetected = 0; + newsym(zx, zy); + (*(int *) num)++; + } + if (!canspotmon(mtmp) && !glyph_is_invisible(levl[zx][zy].glyph)) + map_invisible(zx, zy); + } else if (glyph_is_invisible(levl[zx][zy].glyph)) { + unmap_object(zx, zy); + newsym(zx, zy); + (*(int *) num)++; + } } -int -findit() /* returns number of things found */ +STATIC_PTR void +openone(zx, zy, num) +int zx, zy; +genericptr_t num; { - int num = 0; + register struct trap *ttmp; + register struct obj *otmp; + int *num_p = (int *) num; - if(u.uswallow) return(0); - do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &num); - return(num); + if (OBJ_AT(zx, zy)) { + for (otmp = level.objects[zx][zy]; otmp; otmp = otmp->nexthere) { + if (Is_box(otmp) && otmp->olocked) { + otmp->olocked = 0; + (*num_p)++; + } + } + /* let it fall to the next cases. could be on trap. */ + } + if (levl[zx][zy].typ == SDOOR + || (levl[zx][zy].typ == DOOR + && (levl[zx][zy].doormask & (D_CLOSED | D_LOCKED)))) { + if (levl[zx][zy].typ == SDOOR) + cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ + if (levl[zx][zy].doormask & D_TRAPPED) { + if (distu(zx, zy) < 3) + b_trapped("door", 0); + else + Norep("You %s an explosion!", + cansee(zx, zy) ? "see" : (!Deaf ? "hear" + : "feel the shock of")); + wake_nearto(zx, zy, 11 * 11); + levl[zx][zy].doormask = D_NODOOR; + } else + levl[zx][zy].doormask = D_ISOPEN; + unblock_point(zx, zy); + newsym(zx, zy); + (*num_p)++; + } else if (levl[zx][zy].typ == SCORR) { + levl[zx][zy].typ = CORR; + unblock_point(zx, zy); + newsym(zx, zy); + (*num_p)++; + } else if ((ttmp = t_at(zx, zy)) != 0) { + struct monst *mon; + boolean dummy; /* unneeded "you notice it arg" */ + + if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { + ttmp->tseen = 1; + newsym(zx, zy); + (*num_p)++; + } + mon = (zx == u.ux && zy == u.uy) ? &youmonst : m_at(zx, zy); + if (openholdingtrap(mon, &dummy) + || openfallingtrap(mon, TRUE, &dummy)) + (*num_p)++; + } else if (find_drawbridge(&zx, &zy)) { + /* make sure it isn't an open drawbridge */ + open_drawbridge(zx, zy); + (*num_p)++; + } } -int -openit() /* returns number of things found and opened */ +int findit() /* returns number of things found */ { - int num = 0; + int num = 0; - if(u.uswallow) { - if (is_animal(u.ustuck->data)) { - if (Blind) pline("Its mouth opens!"); - else pline("%s opens its mouth!", Monnam(u.ustuck)); - } - expels(u.ustuck, u.ustuck->data, TRUE); - return(-1); - } + if (u.uswallow) + return (0); + do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &num); + return (num); +} - do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num); - return(num); +int openit() /* returns number of things found and opened */ +{ + int num = 0; + + if (u.uswallow) { + if (is_animal(u.ustuck->data)) { + if (Blind) + pline("Its mouth opens!"); + else + pline("%s opens its mouth!", Monnam(u.ustuck)); + } + expels(u.ustuck, u.ustuck->data, TRUE); + return (-1); + } + + do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num); + return (num); } /* callback hack for overriding vision in do_clear_area() */ boolean detecting(func) - void FDECL((*func), (int,int,genericptr_t)); +void FDECL((*func), (int, int, genericptr_t)); { return (func == findone || func == openone); } @@ -1190,217 +1290,231 @@ struct trap *trap; trap->tseen = 1; exercise(A_WIS, TRUE); if (Blind) - feel_location(trap->tx, trap->ty); + feel_location(trap->tx, trap->ty); else - newsym(trap->tx, trap->ty); + newsym(trap->tx, trap->ty); if (levl[trap->tx][trap->ty].glyph != trap_to_glyph(trap)) { - /* There's too much clutter to see your find otherwise */ - cls(); - map_trap(trap, 1); - display_self(); - cleared = TRUE; + /* There's too much clutter to see your find otherwise */ + cls(); + map_trap(trap, 1); + display_self(); + cleared = TRUE; } You("find %s.", an(defsyms[trap_to_defsym(tt)].explanation)); if (cleared) { - display_nhwindow(WIN_MAP, TRUE); /* wait */ - docrt(); + display_nhwindow(WIN_MAP, TRUE); /* wait */ + docrt(); } } int dosearch0(aflag) -register int aflag; /* intrinsic autosearch vs explicit searching */ +register int aflag; /* intrinsic autosearch vs explicit searching */ { #ifdef GCC_BUG -/* some versions of gcc seriously muck up nested loops. if you get strange - crashes while searching in a version compiled with gcc, try putting - #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in the - makefile). - */ - volatile xchar x, y; + /* some versions of gcc seriously muck up nested loops. if you get strange + crashes while searching in a version compiled with gcc, try putting + #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in the + makefile). + */ + volatile xchar x, y; #else - register xchar x, y; + register xchar x, y; #endif - register struct trap *trap; - register struct monst *mtmp; + register struct trap *trap; + register struct monst *mtmp; - if(u.uswallow) { - if (!aflag) - pline("What are you looking for? The exit?"); - } else { - int fund = (uwep && uwep->oartifact && - spec_ability(uwep, SPFX_SEARCH)) ? - uwep->spe : 0; - if (ublindf && ublindf->otyp == LENSES && !Blind) - fund += 2; /* JDS: lenses help searching */ - if (fund > 5) fund = 5; - for(x = u.ux-1; x < u.ux+2; x++) - for(y = u.uy-1; y < u.uy+2; y++) { - if(!isok(x,y)) continue; - if(x != u.ux || y != u.uy) { - if (Blind && !aflag) feel_location(x,y); - if(levl[x][y].typ == SDOOR) { - if(rnl(7-fund)) continue; - cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ - exercise(A_WIS, TRUE); - nomul(0); - feel_location(x, y); /* make sure it shows up */ - You("find a hidden door."); - } else if(levl[x][y].typ == SCORR) { - if(rnl(7-fund)) continue; - levl[x][y].typ = CORR; - unblock_point(x,y); /* vision */ - exercise(A_WIS, TRUE); - nomul(0); - feel_location(x, y); /* make sure it shows up */ - You("find a hidden passage."); - } else { - /* Be careful not to find anything in an SCORR or SDOOR */ - if((mtmp = m_at(x, y)) && !aflag) { - if(mtmp->m_ap_type) { - seemimic(mtmp); - find: exercise(A_WIS, TRUE); - if (!canspotmon(mtmp)) { - if (glyph_is_invisible(levl[x][y].glyph)) { - /* found invisible monster in a square - * which already has an 'I' in it. - * Logically, this should still take - * time and lead to a return(1), but if - * we did that the player would keep - * finding the same monster every turn. - */ - continue; - } else { - You_feel("an unseen monster!"); - map_invisible(x, y); - } - } else if (!sensemon(mtmp)) - You("find %s.", mtmp->mtame ? - y_monnam(mtmp) : - a_monnam(mtmp)); - return(1); - } - if(!canspotmon(mtmp)) { - if (mtmp->mundetected && - (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) - mtmp->mundetected = 0; - newsym(x,y); - goto find; - } - } + if (u.uswallow) { + if (!aflag) + pline("What are you looking for? The exit?"); + } else { + int fund = + (uwep && uwep->oartifact && spec_ability(uwep, SPFX_SEARCH)) + ? uwep->spe + : 0; + if (ublindf && ublindf->otyp == LENSES && !Blind) + fund += 2; /* JDS: lenses help searching */ + if (fund > 5) + fund = 5; + for (x = u.ux - 1; x < u.ux + 2; x++) + for (y = u.uy - 1; y < u.uy + 2; y++) { + if (!isok(x, y)) + continue; + if (x != u.ux || y != u.uy) { + if (Blind && !aflag) + feel_location(x, y); + if (levl[x][y].typ == SDOOR) { + if (rnl(7 - fund)) + continue; + cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ + exercise(A_WIS, TRUE); + nomul(0); + feel_location(x, y); /* make sure it shows up */ + You("find a hidden door."); + } else if (levl[x][y].typ == SCORR) { + if (rnl(7 - fund)) + continue; + levl[x][y].typ = CORR; + unblock_point(x, y); /* vision */ + exercise(A_WIS, TRUE); + nomul(0); + feel_location(x, y); /* make sure it shows up */ + You("find a hidden passage."); + } else { + /* Be careful not to find anything in an SCORR or + * SDOOR */ + if ((mtmp = m_at(x, y)) && !aflag) { + if (mtmp->m_ap_type) { + seemimic(mtmp); + find: + exercise(A_WIS, TRUE); + if (!canspotmon(mtmp)) { + if (glyph_is_invisible( + levl[x][y].glyph)) { + /* found invisible monster in a square + * which already has an 'I' in it. + * Logically, this should still take + * time and lead to a return(1), but + * if + * we did that the player would keep + * finding the same monster every + * turn. + */ + continue; + } else { + You_feel("an unseen monster!"); + map_invisible(x, y); + } + } else if (!sensemon(mtmp)) + You("find %s.", mtmp->mtame + ? y_monnam(mtmp) + : a_monnam(mtmp)); + return (1); + } + if (!canspotmon(mtmp)) { + if (mtmp->mundetected + && (is_hider(mtmp->data) + || mtmp->data->mlet == S_EEL)) + mtmp->mundetected = 0; + newsym(x, y); + goto find; + } + } - /* see if an invisible monster has moved--if Blind, - * feel_location() already did it - */ - if (!aflag && !mtmp && !Blind && - glyph_is_invisible(levl[x][y].glyph)) { - unmap_object(x,y); - newsym(x,y); - } + /* see if an invisible monster has moved--if Blind, + * feel_location() already did it + */ + if (!aflag && !mtmp && !Blind + && glyph_is_invisible(levl[x][y].glyph)) { + unmap_object(x, y); + newsym(x, y); + } - if ((trap = t_at(x,y)) && !trap->tseen && !rnl(8)) { - nomul(0); + if ((trap = t_at(x, y)) && !trap->tseen && !rnl(8)) { + nomul(0); - if (trap->ttyp == STATUE_TRAP) { - if (activate_statue_trap(trap, x, y, FALSE)) - exercise(A_WIS, TRUE); - return(1); - } else { - find_trap(trap); - } - } - } - } - } - } - return(1); + if (trap->ttyp == STATUE_TRAP) { + if (activate_statue_trap(trap, x, y, FALSE)) + exercise(A_WIS, TRUE); + return (1); + } else { + find_trap(trap); + } + } + } + } + } + } + return (1); } /* the 's' command -- explicit searching */ int dosearch() { - return(dosearch0(0)); + return (dosearch0(0)); } /* Pre-map the sokoban levels */ void sokoban_detect() { - register int x, y; - register struct trap *ttmp; - register struct obj *obj; + register int x, y; + register struct trap *ttmp; + register struct obj *obj; - /* Map the background and boulders */ - for (x = 1; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) { - levl[x][y].seenv = SVALL; - levl[x][y].waslit = TRUE; - map_background(x, y, 1); - if ((obj = sobj_at(BOULDER, x, y)) != 0) - map_object(obj, 1); - } + /* Map the background and boulders */ + for (x = 1; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) { + levl[x][y].seenv = SVALL; + levl[x][y].waslit = TRUE; + map_background(x, y, 1); + if ((obj = sobj_at(BOULDER, x, y)) != 0) + map_object(obj, 1); + } - /* Map the traps */ - for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { - ttmp->tseen = 1; - map_trap(ttmp, 1); - /* set sokoban_rules when there is at least one pit or hole */ - if (ttmp->ttyp == PIT || ttmp->ttyp == HOLE) - Sokoban = 1; - } + /* Map the traps */ + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { + ttmp->tseen = 1; + map_trap(ttmp, 1); + /* set sokoban_rules when there is at least one pit or hole */ + if (ttmp->ttyp == PIT || ttmp->ttyp == HOLE) + Sokoban = 1; + } } /* idea from crawl; show known portion of map without any monsters, objects, or traps occluding the view of the underlying terrain */ void reveal_terrain(full) -boolean full; /* wizard|explore modes allow player to request full map */ +boolean full; /* wizard|explore modes allow player to request full map */ { int x, y, glyph, S_stone_glyph; uchar seenv; struct monst *mtmp; if ((Hallucination || Stunned || Confusion) && !full) { - You("are too disoriented for this."); + You("are too disoriented for this."); } else { - iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; - u.uinwater = u.uburied = 0; - S_stone_glyph = cmap_to_glyph(S_stone); - /* rewrite the map, displaying map background for seen spots - (all spots seen if 'full') and stone everywhere else */ - for (x = 1; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) { - seenv = levl[x][y].seenv; - if (full) { - levl[x][y].seenv = SVALL; - glyph = back_to_glyph(x, y); - levl[x][y].seenv = seenv; - } else { - if (!level.flags.hero_memory && !cansee(x, y)) - seenv = 0; - glyph = seenv ? back_to_glyph(x, y) : S_stone_glyph; - /* need to show mimic-as-furniture so that #terrain can't - be used to spot mimics, but this is only approximate; - mimic might have moved and hid here after the player - last saw this spot as some other type of terrain */ - if (seenv && (mtmp = m_at(x, y)) != 0 && - mtmp->m_ap_type == M_AP_FURNITURE) - glyph = cmap_to_glyph(mtmp->mappearance); - } - show_glyph(x, y, glyph); - } - /* [TODO: highlight hero's location somehow] */ - u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; - flush_screen(1); - pline("Showing underlying terrain only..."); - display_nhwindow(WIN_MAP, TRUE); /* give "--More--" prompt */ - docrt(); /* redraw the screen, restoring regular map */ - if (Underwater) under_water(2); - if (u.uburied) under_ground(2); + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; + u.uinwater = u.uburied = 0; + S_stone_glyph = cmap_to_glyph(S_stone); + /* rewrite the map, displaying map background for seen spots + (all spots seen if 'full') and stone everywhere else */ + for (x = 1; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) { + seenv = levl[x][y].seenv; + if (full) { + levl[x][y].seenv = SVALL; + glyph = back_to_glyph(x, y); + levl[x][y].seenv = seenv; + } else { + if (!level.flags.hero_memory && !cansee(x, y)) + seenv = 0; + glyph = seenv ? back_to_glyph(x, y) : S_stone_glyph; + /* need to show mimic-as-furniture so that #terrain can't + be used to spot mimics, but this is only approximate; + mimic might have moved and hid here after the player + last saw this spot as some other type of terrain */ + if (seenv && (mtmp = m_at(x, y)) != 0 + && mtmp->m_ap_type == M_AP_FURNITURE) + glyph = cmap_to_glyph(mtmp->mappearance); + } + show_glyph(x, y, glyph); + } + /* [TODO: highlight hero's location somehow] */ + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; + flush_screen(1); + pline("Showing underlying terrain only..."); + display_nhwindow(WIN_MAP, TRUE); /* give "--More--" prompt */ + docrt(); /* redraw the screen, restoring regular map */ + if (Underwater) + under_water(2); + if (u.uburied) + under_ground(2); } return; } diff --git a/src/dig.c b/src/dig.c index 4b6d0c6e9..f3e9ed22b 100644 --- a/src/dig.c +++ b/src/dig.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dig.c $NHDT-Date: 1430697288 2015/05/03 23:54:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.86 $ */ +/* NetHack 3.6 dig.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.90 $ */ /* NetHack 3.6 dig.c $Date: 2012/02/16 03:01:37 $ $Revision: 1.67 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,33 +8,34 @@ static NEARDATA boolean did_dig_msg; STATIC_DCL boolean NDECL(rm_waslit); -STATIC_DCL void FDECL(mkcavepos, (XCHAR_P,XCHAR_P,int,BOOLEAN_P,BOOLEAN_P)); +STATIC_DCL void FDECL(mkcavepos, + (XCHAR_P, XCHAR_P, int, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL void FDECL(mkcavearea, (BOOLEAN_P)); STATIC_DCL int NDECL(dig); STATIC_DCL void FDECL(dig_up_grave, (coord *)); -STATIC_DCL int FDECL(adj_pit_checks, (coord *,char *)); -STATIC_DCL void FDECL(pit_flow, (struct trap *,SCHAR_P)); +STATIC_DCL int FDECL(adj_pit_checks, (coord *, char *)); +STATIC_DCL void FDECL(pit_flow, (struct trap *, SCHAR_P)); /* Indices returned by dig_typ() */ #define DIGTYP_UNDIGGABLE 0 -#define DIGTYP_ROCK 1 -#define DIGTYP_STATUE 2 -#define DIGTYP_BOULDER 3 -#define DIGTYP_DOOR 4 -#define DIGTYP_TREE 5 - +#define DIGTYP_ROCK 1 +#define DIGTYP_STATUE 2 +#define DIGTYP_BOULDER 3 +#define DIGTYP_DOOR 4 +#define DIGTYP_TREE 5 STATIC_OVL boolean rm_waslit() { register xchar x, y; - if(levl[u.ux][u.uy].typ == ROOM && levl[u.ux][u.uy].waslit) - return(TRUE); - for(x = u.ux-2; x < u.ux+3; x++) - for(y = u.uy-1; y < u.uy+2; y++) - if(isok(x,y) && levl[x][y].waslit) return(TRUE); - return(FALSE); + if (levl[u.ux][u.uy].typ == ROOM && levl[u.ux][u.uy].waslit) + return (TRUE); + for (x = u.ux - 2; x < u.ux + 3; x++) + for (y = u.uy - 1; y < u.uy + 2; y++) + if (isok(x, y) && levl[x][y].waslit) + return (TRUE); + return (FALSE); } /* Change level topology. Messes with vision tables and ignores things like @@ -43,41 +44,49 @@ rm_waslit() */ STATIC_OVL void mkcavepos(x, y, dist, waslit, rockit) - xchar x,y; - int dist; - boolean waslit, rockit; +xchar x, y; +int dist; +boolean waslit, rockit; { register struct rm *lev; - if(!isok(x,y)) return; + if (!isok(x, y)) + return; lev = &levl[x][y]; - if(rockit) { - register struct monst *mtmp; + if (rockit) { + register struct monst *mtmp; - if(IS_ROCK(lev->typ)) return; - if(t_at(x, y)) return; /* don't cover the portal */ - if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */ - if(!passes_walls(mtmp->data)) (void) rloc(mtmp, FALSE); - } else if(lev->typ == ROOM) return; + if (IS_ROCK(lev->typ)) + return; + if (t_at(x, y)) + return; /* don't cover the portal */ + if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */ + if (!passes_walls(mtmp->data)) + (void) rloc(mtmp, FALSE); + } else if (lev->typ == ROOM) + return; - unblock_point(x,y); /* make sure vision knows this location is open */ + unblock_point(x, y); /* make sure vision knows this location is open */ /* fake out saved state */ lev->seenv = 0; lev->doormask = 0; - if(dist < 3) lev->lit = (rockit ? FALSE : TRUE); - if(waslit) lev->waslit = (rockit ? FALSE : TRUE); + if (dist < 3) + lev->lit = (rockit ? FALSE : TRUE); + if (waslit) + lev->waslit = (rockit ? FALSE : TRUE); lev->horizontal = FALSE; - viz_array[y][x] = (dist < 3 ) ? - (IN_SIGHT|COULD_SEE) : /* short-circuit vision recalc */ - COULD_SEE; + viz_array[y][x] = (dist < 3) ? (IN_SIGHT | COULD_SEE) + : /* short-circuit vision recalc */ + COULD_SEE; lev->typ = (rockit ? STONE : ROOM); - if(dist >= 3) - impossible("mkcavepos called with dist %d", dist); - if(Blind) - feel_location(x, y); - else newsym(x,y); + if (dist >= 3) + impossible("mkcavepos called with dist %d", dist); + if (Blind) + feel_location(x, y); + else + newsym(x, y); } STATIC_OVL void @@ -90,40 +99,45 @@ register boolean rockit; register xchar i; register boolean waslit = rm_waslit(); - if(rockit) pline("Crash! The ceiling collapses around you!"); - else pline("A mysterious force %s cave around you!", - (levl[u.ux][u.uy].typ == CORR) ? "creates a" : "extends the"); + if (rockit) + pline("Crash! The ceiling collapses around you!"); + else + pline("A mysterious force %s cave around you!", + (levl[u.ux][u.uy].typ == CORR) ? "creates a" : "extends the"); display_nhwindow(WIN_MESSAGE, TRUE); - for(dist = 1; dist <= 2; dist++) { - xmin--; xmax++; + for (dist = 1; dist <= 2; dist++) { + xmin--; + xmax++; - /* top and bottom */ - if(dist < 2) { /* the area is wider that it is high */ - ymin--; ymax++; - for(i = xmin+1; i < xmax; i++) { - mkcavepos(i, ymin, dist, waslit, rockit); - mkcavepos(i, ymax, dist, waslit, rockit); - } - } + /* top and bottom */ + if (dist < 2) { /* the area is wider that it is high */ + ymin--; + ymax++; + for (i = xmin + 1; i < xmax; i++) { + mkcavepos(i, ymin, dist, waslit, rockit); + mkcavepos(i, ymax, dist, waslit, rockit); + } + } - /* left and right */ - for(i = ymin; i <= ymax; i++) { - mkcavepos(xmin, i, dist, waslit, rockit); - mkcavepos(xmax, i, dist, waslit, rockit); - } + /* left and right */ + for (i = ymin; i <= ymax; i++) { + mkcavepos(xmin, i, dist, waslit, rockit); + mkcavepos(xmax, i, dist, waslit, rockit); + } - flush_screen(1); /* make sure the new glyphs shows up */ - delay_output(); + flush_screen(1); /* make sure the new glyphs shows up */ + delay_output(); } - if(!rockit && levl[u.ux][u.uy].typ == CORR) { - levl[u.ux][u.uy].typ = ROOM; - if(waslit) levl[u.ux][u.uy].waslit = TRUE; - newsym(u.ux, u.uy); /* in case player is invisible */ + if (!rockit && levl[u.ux][u.uy].typ == CORR) { + levl[u.ux][u.uy].typ = ROOM; + if (waslit) + levl[u.ux][u.uy].waslit = TRUE; + newsym(u.ux, u.uy); /* in case player is invisible */ } - vision_full_recalc = 1; /* everything changed */ + vision_full_recalc = 1; /* everything changed */ } /* When digging into location , what are you actually digging into? */ @@ -132,360 +146,378 @@ dig_typ(otmp, x, y) struct obj *otmp; xchar x, y; { - boolean ispick; + boolean ispick; - if (!otmp) return DIGTYP_UNDIGGABLE; - ispick = is_pick(otmp); - if (!ispick && !is_axe(otmp)) return DIGTYP_UNDIGGABLE; + if (!otmp) + return DIGTYP_UNDIGGABLE; + ispick = is_pick(otmp); + if (!ispick && !is_axe(otmp)) + return DIGTYP_UNDIGGABLE; - return (ispick && sobj_at(STATUE, x, y) ? DIGTYP_STATUE : - ispick && sobj_at(BOULDER, x, y) ? DIGTYP_BOULDER : - closed_door(x, y) ? DIGTYP_DOOR : - IS_TREE(levl[x][y].typ) ? - (ispick ? DIGTYP_UNDIGGABLE : DIGTYP_TREE) : - ispick && IS_ROCK(levl[x][y].typ) && - (!level.flags.arboreal || IS_WALL(levl[x][y].typ)) ? - DIGTYP_ROCK : DIGTYP_UNDIGGABLE); + return (ispick && sobj_at(STATUE, x, y) + ? DIGTYP_STATUE + : ispick && sobj_at(BOULDER, x, y) + ? DIGTYP_BOULDER + : closed_door(x, y) + ? DIGTYP_DOOR + : IS_TREE(levl[x][y].typ) + ? (ispick ? DIGTYP_UNDIGGABLE : DIGTYP_TREE) + : ispick && IS_ROCK(levl[x][y].typ) + && (!level.flags.arboreal + || IS_WALL(levl[x][y].typ)) + ? DIGTYP_ROCK + : DIGTYP_UNDIGGABLE); } boolean is_digging() { - if (occupation == dig) { - return TRUE; - } - return FALSE; + if (occupation == dig) { + return TRUE; + } + return FALSE; } -#define BY_YOU (&youmonst) -#define BY_OBJECT ((struct monst *)0) +#define BY_YOU (&youmonst) +#define BY_OBJECT ((struct monst *) 0) boolean dig_check(madeby, verbose, x, y) - struct monst *madeby; - boolean verbose; - int x, y; +struct monst *madeby; +boolean verbose; +int x, y; { - struct trap *ttmp = t_at(x, y); - const char *verb = (madeby == BY_YOU && uwep && is_axe(uwep)) ? "chop" : "dig in"; + struct trap *ttmp = t_at(x, y); + const char *verb = + (madeby == BY_YOU && uwep && is_axe(uwep)) ? "chop" : "dig in"; - if (On_stairs(x, y)) { - if (x == xdnladder || x == xupladder) { - if(verbose) pline_The("ladder resists your effort."); - } else if(verbose) pline_The("stairs are too hard to %s.", verb); - return(FALSE); - } else if (IS_THRONE(levl[x][y].typ) && madeby != BY_OBJECT) { - if(verbose) pline_The("throne is too hard to break apart."); - return(FALSE); - } else if (IS_ALTAR(levl[x][y].typ) && (madeby != BY_OBJECT || - Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) { - if(verbose) pline_The("altar is too hard to break apart."); - return(FALSE); - } else if (Is_airlevel(&u.uz)) { - if(verbose) You("cannot %s thin air.", verb); - return(FALSE); - } else if (Is_waterlevel(&u.uz)) { - if(verbose) pline_The("water splashes and subsides."); - return(FALSE); - } else if ((IS_ROCK(levl[x][y].typ) && levl[x][y].typ != SDOOR && - (levl[x][y].wall_info & W_NONDIGGABLE) != 0) - || (ttmp && - (ttmp->ttyp == MAGIC_PORTAL || - (!Can_dig_down(&u.uz) && !levl[x][y].candig)))) { - if(verbose) pline_The("%s here is too hard to %s.", - surface(x,y), verb); - return(FALSE); - } else if (sobj_at(BOULDER, x, y)) { - if(verbose) There("isn't enough room to %s here.", verb); - return(FALSE); - } else if (madeby == BY_OBJECT && - /* the block against existing traps is mainly to - prevent broken wands from turning holes into pits */ - (ttmp || is_pool_or_lava(x,y))) { - /* digging by player handles pools separately */ - return FALSE; - } - return(TRUE); + if (On_stairs(x, y)) { + if (x == xdnladder || x == xupladder) { + if (verbose) + pline_The("ladder resists your effort."); + } else if (verbose) + pline_The("stairs are too hard to %s.", verb); + return (FALSE); + } else if (IS_THRONE(levl[x][y].typ) && madeby != BY_OBJECT) { + if (verbose) + pline_The("throne is too hard to break apart."); + return (FALSE); + } else if (IS_ALTAR(levl[x][y].typ) + && (madeby != BY_OBJECT || Is_astralevel(&u.uz) + || Is_sanctum(&u.uz))) { + if (verbose) + pline_The("altar is too hard to break apart."); + return (FALSE); + } else if (Is_airlevel(&u.uz)) { + if (verbose) + You("cannot %s thin air.", verb); + return (FALSE); + } else if (Is_waterlevel(&u.uz)) { + if (verbose) + pline_The("water splashes and subsides."); + return (FALSE); + } else if ((IS_ROCK(levl[x][y].typ) && levl[x][y].typ != SDOOR + && (levl[x][y].wall_info & W_NONDIGGABLE) != 0) + || (ttmp + && (ttmp->ttyp == MAGIC_PORTAL + || (!Can_dig_down(&u.uz) && !levl[x][y].candig)))) { + if (verbose) + pline_The("%s here is too hard to %s.", surface(x, y), verb); + return (FALSE); + } else if (sobj_at(BOULDER, x, y)) { + if (verbose) + There("isn't enough room to %s here.", verb); + return (FALSE); + } else if (madeby == BY_OBJECT && + /* the block against existing traps is mainly to + prevent broken wands from turning holes into pits */ + (ttmp || is_pool_or_lava(x, y))) { + /* digging by player handles pools separately */ + return FALSE; + } + return (TRUE); } STATIC_OVL int dig(VOID_ARGS) { - register struct rm *lev; - register xchar dpx = context.digging.pos.x, dpy = context.digging.pos.y; - register boolean ispick = uwep && is_pick(uwep); - const char *verb = - (!uwep || is_pick(uwep)) ? "dig into" : "chop through"; + register struct rm *lev; + register xchar dpx = context.digging.pos.x, dpy = context.digging.pos.y; + register boolean ispick = uwep && is_pick(uwep); + const char *verb = (!uwep || is_pick(uwep)) ? "dig into" : "chop through"; - lev = &levl[dpx][dpy]; - /* perhaps a nymph stole your pick-axe while you were busy digging */ - /* or perhaps you teleported away */ - if (u.uswallow || !uwep || (!ispick && !is_axe(uwep)) || - !on_level(&context.digging.level, &u.uz) || - ((context.digging.down ? (dpx != u.ux || dpy != u.uy) - : (distu(dpx,dpy) > 2)))) - return(0); + lev = &levl[dpx][dpy]; + /* perhaps a nymph stole your pick-axe while you were busy digging */ + /* or perhaps you teleported away */ + if (u.uswallow || !uwep || (!ispick && !is_axe(uwep)) + || !on_level(&context.digging.level, &u.uz) + || ((context.digging.down ? (dpx != u.ux || dpy != u.uy) + : (distu(dpx, dpy) > 2)))) + return (0); - if (context.digging.down) { - if(!dig_check(BY_YOU, TRUE, u.ux, u.uy)) return(0); - } else { /* !context.digging.down */ - if (IS_TREE(lev->typ) && !may_dig(dpx,dpy) && - dig_typ(uwep, dpx, dpy) == DIGTYP_TREE) { - pline("This tree seems to be petrified."); - return(0); - } - if (IS_ROCK(lev->typ) && !may_dig(dpx,dpy) && - dig_typ(uwep, dpx, dpy) == DIGTYP_ROCK) { - pline("This %s is too hard to %s.", - is_db_wall(dpx, dpy) ? "drawbridge" : "wall", verb); - return(0); - } - } - if(Fumbling && !rn2(3)) { - switch(rn2(3)) { - case 0: - if(!welded(uwep)) { - You("fumble and drop %s.", yname(uwep)); - dropx(uwep); - } else { - if (u.usteed) - pline("%s and %s %s!", - Yobjnam2(uwep, "bounce"), otense(uwep, "hit"), - mon_nam(u.usteed)); - else - pline("Ouch! %s and %s you!", - Yobjnam2(uwep, "bounce"), otense(uwep, "hit")); - set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); - } - break; - case 1: - pline("Bang! You hit with the broad side of %s!", - the(xname(uwep))); - break; - default: Your("swing misses its mark."); - break; - } - return(0); - } + if (context.digging.down) { + if (!dig_check(BY_YOU, TRUE, u.ux, u.uy)) + return (0); + } else { /* !context.digging.down */ + if (IS_TREE(lev->typ) && !may_dig(dpx, dpy) + && dig_typ(uwep, dpx, dpy) == DIGTYP_TREE) { + pline("This tree seems to be petrified."); + return (0); + } + if (IS_ROCK(lev->typ) && !may_dig(dpx, dpy) + && dig_typ(uwep, dpx, dpy) == DIGTYP_ROCK) { + pline("This %s is too hard to %s.", + is_db_wall(dpx, dpy) ? "drawbridge" : "wall", verb); + return (0); + } + } + if (Fumbling && !rn2(3)) { + switch (rn2(3)) { + case 0: + if (!welded(uwep)) { + You("fumble and drop %s.", yname(uwep)); + dropx(uwep); + } else { + if (u.usteed) + pline("%s and %s %s!", Yobjnam2(uwep, "bounce"), + otense(uwep, "hit"), mon_nam(u.usteed)); + else + pline("Ouch! %s and %s you!", Yobjnam2(uwep, "bounce"), + otense(uwep, "hit")); + set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); + } + break; + case 1: + pline("Bang! You hit with the broad side of %s!", + the(xname(uwep))); + break; + default: + Your("swing misses its mark."); + break; + } + return (0); + } - context.digging.effort += 10 + rn2(5) + abon() + - uwep->spe - greatest_erosion(uwep) + u.udaminc; - if (Race_if(PM_DWARF)) - context.digging.effort *= 2; - if (context.digging.down) { - struct trap *ttmp = t_at(dpx, dpy); + context.digging.effort += + 10 + rn2(5) + abon() + uwep->spe - greatest_erosion(uwep) + u.udaminc; + if (Race_if(PM_DWARF)) + context.digging.effort *= 2; + if (context.digging.down) { + struct trap *ttmp = t_at(dpx, dpy); - if (context.digging.effort > 250 || - (ttmp && ttmp->ttyp == HOLE)) { - (void) dighole(FALSE, FALSE, (coord *)0); - (void) memset((genericptr_t)&context.digging, 0, - sizeof context.digging); - return(0); /* done with digging */ - } + if (context.digging.effort > 250 || (ttmp && ttmp->ttyp == HOLE)) { + (void) dighole(FALSE, FALSE, (coord *) 0); + (void) memset((genericptr_t) &context.digging, 0, + sizeof context.digging); + return (0); /* done with digging */ + } - if (context.digging.effort <= 50 || - (ttmp && (ttmp->ttyp == TRAPDOOR || - ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT))) { - return(1); - } else if (ttmp && (ttmp->ttyp == LANDMINE || - (ttmp->ttyp == BEAR_TRAP && !u.utrap))) { - /* digging onto a set object trap triggers it; - hero should have used #untrap first */ - dotrap(ttmp, FORCETRAP); - /* restart completely from scratch if we resume digging */ - (void) memset((genericptr_t)&context.digging, 0, - sizeof context.digging); - return 0; - } else if (ttmp && ttmp->ttyp == BEAR_TRAP && u.utrap) { - if (rnl(7) > (Fumbling ? 1 : 4)) { - char kbuf[BUFSZ]; - int dmg = dmgval(uwep, &youmonst) + dbon(); + if (context.digging.effort <= 50 + || (ttmp && (ttmp->ttyp == TRAPDOOR || ttmp->ttyp == PIT + || ttmp->ttyp == SPIKED_PIT))) { + return (1); + } else if (ttmp && (ttmp->ttyp == LANDMINE + || (ttmp->ttyp == BEAR_TRAP && !u.utrap))) { + /* digging onto a set object trap triggers it; + hero should have used #untrap first */ + dotrap(ttmp, FORCETRAP); + /* restart completely from scratch if we resume digging */ + (void) memset((genericptr_t) &context.digging, 0, + sizeof context.digging); + return 0; + } else if (ttmp && ttmp->ttyp == BEAR_TRAP && u.utrap) { + if (rnl(7) > (Fumbling ? 1 : 4)) { + char kbuf[BUFSZ]; + int dmg = dmgval(uwep, &youmonst) + dbon(); - if (dmg < 1) dmg = 1; - else if (uarmf) dmg = (dmg + 1) / 2; - You("hit yourself in the %s.", body_part(FOOT)); - Sprintf(kbuf, "chopping off %s own %s", - uhis(), body_part(FOOT)); - losehp(Maybe_Half_Phys(dmg), kbuf, KILLED_BY); - } else { - You("destroy the bear trap with %s.", - yobjnam(uwep, (const char *)0)); - u.utrap = 0; /* release from trap */ - deltrap(ttmp); - } - /* we haven't made any progress toward a pit yet */ - context.digging.effort = 0; - return 0; - } + if (dmg < 1) + dmg = 1; + else if (uarmf) + dmg = (dmg + 1) / 2; + You("hit yourself in the %s.", body_part(FOOT)); + Sprintf(kbuf, "chopping off %s own %s", uhis(), + body_part(FOOT)); + losehp(Maybe_Half_Phys(dmg), kbuf, KILLED_BY); + } else { + You("destroy the bear trap with %s.", + yobjnam(uwep, (const char *) 0)); + u.utrap = 0; /* release from trap */ + deltrap(ttmp); + } + /* we haven't made any progress toward a pit yet */ + context.digging.effort = 0; + return 0; + } - if (IS_ALTAR(lev->typ)) { - altar_wrath(dpx, dpy); - angry_priest(); - } + if (IS_ALTAR(lev->typ)) { + altar_wrath(dpx, dpy); + angry_priest(); + } - /* make pit at */ - if (dighole(TRUE, FALSE, (coord *)0)) { - context.digging.level.dnum = 0; - context.digging.level.dlevel = -1; - } - return(0); - } + /* make pit at */ + if (dighole(TRUE, FALSE, (coord *) 0)) { + context.digging.level.dnum = 0; + context.digging.level.dlevel = -1; + } + return (0); + } - if (context.digging.effort > 100) { - register const char *digtxt, *dmgtxt = (const char*) 0; - register struct obj *obj; - register boolean shopedge = *in_rooms(dpx, dpy, SHOPBASE); + if (context.digging.effort > 100) { + register const char *digtxt, *dmgtxt = (const char *) 0; + register struct obj *obj; + register boolean shopedge = *in_rooms(dpx, dpy, SHOPBASE); - if ((obj = sobj_at(STATUE, dpx, dpy)) != 0) { - if (break_statue(obj)) - digtxt = "The statue shatters."; - else - /* it was a statue trap; break_statue() - * printed a message and updated the screen - */ - digtxt = (char *)0; - } else if ((obj = sobj_at(BOULDER, dpx, dpy)) != 0) { - struct obj *bobj; + if ((obj = sobj_at(STATUE, dpx, dpy)) != 0) { + if (break_statue(obj)) + digtxt = "The statue shatters."; + else + /* it was a statue trap; break_statue() + * printed a message and updated the screen + */ + digtxt = (char *) 0; + } else if ((obj = sobj_at(BOULDER, dpx, dpy)) != 0) { + struct obj *bobj; - fracture_rock(obj); - if ((bobj = sobj_at(BOULDER, dpx, dpy)) != 0) { - /* another boulder here, restack it to the top */ - obj_extract_self(bobj); - place_object(bobj, dpx, dpy); - } - digtxt = "The boulder falls apart."; - } else if (lev->typ == STONE || lev->typ == SCORR || - IS_TREE(lev->typ)) { - if(Is_earthlevel(&u.uz)) { - if(uwep->blessed && !rn2(3)) { - mkcavearea(FALSE); - goto cleanup; - } else if((uwep->cursed && !rn2(4)) || - (!uwep->blessed && !rn2(6))) { - mkcavearea(TRUE); - goto cleanup; - } - } - if (IS_TREE(lev->typ)) { - digtxt = "You cut down the tree."; - lev->typ = ROOM; - if (!rn2(5)) (void) rnd_treefruit_at(dpx, dpy); - } else { - digtxt = "You succeed in cutting away some rock."; - lev->typ = CORR; - } - } else if(IS_WALL(lev->typ)) { - if(shopedge) { - add_damage(dpx, dpy, 10L * ACURRSTR); - dmgtxt = "damage"; - } - if (level.flags.is_maze_lev) { - lev->typ = ROOM; - } else if (level.flags.is_cavernous_lev && - !in_town(dpx, dpy)) { - lev->typ = CORR; - } else { - lev->typ = DOOR; - lev->doormask = D_NODOOR; - } - digtxt = "You make an opening in the wall."; - } else if(lev->typ == SDOOR) { - cvt_sdoor_to_door(lev); /* ->typ = DOOR */ - digtxt = "You break through a secret door!"; - if(!(lev->doormask & D_TRAPPED)) - lev->doormask = D_BROKEN; - } else if(closed_door(dpx, dpy)) { - digtxt = "You break through the door."; - if(shopedge) { - add_damage(dpx, dpy, 400L); - dmgtxt = "break"; - } - if(!(lev->doormask & D_TRAPPED)) - lev->doormask = D_BROKEN; - } else return(0); /* statue or boulder got taken */ + fracture_rock(obj); + if ((bobj = sobj_at(BOULDER, dpx, dpy)) != 0) { + /* another boulder here, restack it to the top */ + obj_extract_self(bobj); + place_object(bobj, dpx, dpy); + } + digtxt = "The boulder falls apart."; + } else if (lev->typ == STONE || lev->typ == SCORR + || IS_TREE(lev->typ)) { + if (Is_earthlevel(&u.uz)) { + if (uwep->blessed && !rn2(3)) { + mkcavearea(FALSE); + goto cleanup; + } else if ((uwep->cursed && !rn2(4)) + || (!uwep->blessed && !rn2(6))) { + mkcavearea(TRUE); + goto cleanup; + } + } + if (IS_TREE(lev->typ)) { + digtxt = "You cut down the tree."; + lev->typ = ROOM; + if (!rn2(5)) + (void) rnd_treefruit_at(dpx, dpy); + } else { + digtxt = "You succeed in cutting away some rock."; + lev->typ = CORR; + } + } else if (IS_WALL(lev->typ)) { + if (shopedge) { + add_damage(dpx, dpy, 10L * ACURRSTR); + dmgtxt = "damage"; + } + if (level.flags.is_maze_lev) { + lev->typ = ROOM; + } else if (level.flags.is_cavernous_lev && !in_town(dpx, dpy)) { + lev->typ = CORR; + } else { + lev->typ = DOOR; + lev->doormask = D_NODOOR; + } + digtxt = "You make an opening in the wall."; + } else if (lev->typ == SDOOR) { + cvt_sdoor_to_door(lev); /* ->typ = DOOR */ + digtxt = "You break through a secret door!"; + if (!(lev->doormask & D_TRAPPED)) + lev->doormask = D_BROKEN; + } else if (closed_door(dpx, dpy)) { + digtxt = "You break through the door."; + if (shopedge) { + add_damage(dpx, dpy, 400L); + dmgtxt = "break"; + } + if (!(lev->doormask & D_TRAPPED)) + lev->doormask = D_BROKEN; + } else + return (0); /* statue or boulder got taken */ - if(!does_block(dpx,dpy,&levl[dpx][dpy])) - unblock_point(dpx,dpy); /* vision: can see through */ - if(Blind) - feel_location(dpx, dpy); - else - newsym(dpx, dpy); - if(digtxt && !context.digging.quiet) pline1(digtxt); /* after newsym */ - if(dmgtxt) - pay_for_damage(dmgtxt, FALSE); + if (!does_block(dpx, dpy, &levl[dpx][dpy])) + unblock_point(dpx, dpy); /* vision: can see through */ + if (Blind) + feel_location(dpx, dpy); + else + newsym(dpx, dpy); + if (digtxt && !context.digging.quiet) + pline1(digtxt); /* after newsym */ + if (dmgtxt) + pay_for_damage(dmgtxt, FALSE); - if(Is_earthlevel(&u.uz) && !rn2(3)) { - register struct monst *mtmp; + if (Is_earthlevel(&u.uz) && !rn2(3)) { + register struct monst *mtmp; - switch(rn2(2)) { - case 0: - mtmp = makemon(&mons[PM_EARTH_ELEMENTAL], - dpx, dpy, NO_MM_FLAGS); - break; - default: - mtmp = makemon(&mons[PM_XORN], - dpx, dpy, NO_MM_FLAGS); - break; - } - if(mtmp) pline_The("debris from your digging comes to life!"); - } - if(IS_DOOR(lev->typ) && (lev->doormask & D_TRAPPED)) { - lev->doormask = D_NODOOR; - b_trapped("door", 0); - newsym(dpx, dpy); - } -cleanup: - context.digging.lastdigtime = moves; - context.digging.quiet = FALSE; - context.digging.level.dnum = 0; - context.digging.level.dlevel = -1; - return(0); - } else { /* not enough effort has been spent yet */ - static const char *const d_target[6] = { - "", "rock", "statue", "boulder", "door", "tree" - }; - int dig_target = dig_typ(uwep, dpx, dpy); + switch (rn2(2)) { + case 0: + mtmp = + makemon(&mons[PM_EARTH_ELEMENTAL], dpx, dpy, NO_MM_FLAGS); + break; + default: + mtmp = makemon(&mons[PM_XORN], dpx, dpy, NO_MM_FLAGS); + break; + } + if (mtmp) + pline_The("debris from your digging comes to life!"); + } + if (IS_DOOR(lev->typ) && (lev->doormask & D_TRAPPED)) { + lev->doormask = D_NODOOR; + b_trapped("door", 0); + newsym(dpx, dpy); + } + cleanup: + context.digging.lastdigtime = moves; + context.digging.quiet = FALSE; + context.digging.level.dnum = 0; + context.digging.level.dlevel = -1; + return (0); + } else { /* not enough effort has been spent yet */ + static const char *const d_target[6] = { "", "rock", "statue", + "boulder", "door", "tree" }; + int dig_target = dig_typ(uwep, dpx, dpy); - if (IS_WALL(lev->typ) || dig_target == DIGTYP_DOOR) { - if(*in_rooms(dpx, dpy, SHOPBASE)) { - pline("This %s seems too hard to %s.", - IS_DOOR(lev->typ) ? "door" : "wall", verb); - return(0); - } - } else if (dig_target == DIGTYP_UNDIGGABLE || - (dig_target == DIGTYP_ROCK && !IS_ROCK(lev->typ))) - return(0); /* statue or boulder got taken */ + if (IS_WALL(lev->typ) || dig_target == DIGTYP_DOOR) { + if (*in_rooms(dpx, dpy, SHOPBASE)) { + pline("This %s seems too hard to %s.", + IS_DOOR(lev->typ) ? "door" : "wall", verb); + return (0); + } + } else if (dig_target == DIGTYP_UNDIGGABLE + || (dig_target == DIGTYP_ROCK && !IS_ROCK(lev->typ))) + return (0); /* statue or boulder got taken */ - if(!did_dig_msg) { - You("hit the %s with all your might.", - d_target[dig_target]); - did_dig_msg = TRUE; - } - } - return(1); + if (!did_dig_msg) { + You("hit the %s with all your might.", d_target[dig_target]); + did_dig_msg = TRUE; + } + } + return (1); } /* When will hole be finished? Very rough indication used by shopkeeper. */ int holetime() { - if(occupation != dig || !*u.ushops) return(-1); - return ((250 - context.digging.effort) / 20); + if (occupation != dig || !*u.ushops) + return (-1); + return ((250 - context.digging.effort) / 20); } /* Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */ schar -fillholetyp(x,y,fill_if_any) +fillholetyp(x, y, fill_if_any) int x, y; -boolean fill_if_any; /* force filling if it exists at all */ +boolean fill_if_any; /* force filling if it exists at all */ { register int x1, y1; - int lo_x = max(1,x-1), hi_x = min(x+1,COLNO-1), - lo_y = max(0,y-1), hi_y = min(y+1,ROWNO-1); + int lo_x = max(1, x - 1), hi_x = min(x + 1, COLNO - 1), + lo_y = max(0, y - 1), hi_y = min(y + 1, ROWNO - 1); int pool_cnt = 0, moat_cnt = 0, lava_cnt = 0; for (x1 = lo_x; x1 <= hi_x; x1++) - for (y1 = lo_y; y1 <= hi_y; y1++) + for (y1 = lo_y; y1 <= hi_y; y1++) if (is_moat(x1, y1)) moat_cnt++; else if (is_pool(x1, y1)) @@ -495,192 +527,200 @@ boolean fill_if_any; /* force filling if it exists at all */ else if (is_lava(x1, y1)) lava_cnt++; - if (!fill_if_any) pool_cnt /= 3; /* not as much liquid as the others */ + if (!fill_if_any) + pool_cnt /= 3; /* not as much liquid as the others */ - if ((lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1)) || - (lava_cnt && fill_if_any)) - return LAVAPOOL; - else if ((moat_cnt > 0 && rn2(moat_cnt + 1)) || - (moat_cnt && fill_if_any)) - return MOAT; - else if ((pool_cnt > 0 && rn2(pool_cnt + 1)) || - (pool_cnt && fill_if_any)) - return POOL; + if ((lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1)) + || (lava_cnt && fill_if_any)) + return LAVAPOOL; + else if ((moat_cnt > 0 && rn2(moat_cnt + 1)) || (moat_cnt && fill_if_any)) + return MOAT; + else if ((pool_cnt > 0 && rn2(pool_cnt + 1)) || (pool_cnt && fill_if_any)) + return POOL; else - return ROOM; + return ROOM; } void digactualhole(x, y, madeby, ttyp) -register int x, y; -struct monst *madeby; +register int x, y; +struct monst *madeby; int ttyp; { - struct obj *oldobjs, *newobjs; - register struct trap *ttmp; - char surface_type[BUFSZ]; - struct rm *lev = &levl[x][y]; - boolean shopdoor; - struct monst *mtmp = m_at(x, y); /* may be madeby */ - boolean madeby_u = (madeby == BY_YOU); - boolean madeby_obj = (madeby == BY_OBJECT); - boolean at_u = (x == u.ux) && (y == u.uy); - boolean wont_fall = Levitation || Flying; + struct obj *oldobjs, *newobjs; + register struct trap *ttmp; + char surface_type[BUFSZ]; + struct rm *lev = &levl[x][y]; + boolean shopdoor; + struct monst *mtmp = m_at(x, y); /* may be madeby */ + boolean madeby_u = (madeby == BY_YOU); + boolean madeby_obj = (madeby == BY_OBJECT); + boolean at_u = (x == u.ux) && (y == u.uy); + boolean wont_fall = Levitation || Flying; - if (at_u && u.utrap) { - if (u.utraptype == TT_BURIEDBALL) buried_ball_to_punishment(); - else if (u.utraptype == TT_INFLOOR) u.utrap = 0; - } + if (at_u && u.utrap) { + if (u.utraptype == TT_BURIEDBALL) + buried_ball_to_punishment(); + else if (u.utraptype == TT_INFLOOR) + u.utrap = 0; + } - /* these furniture checks were in dighole(), but wand - breaking bypasses that routine and calls us directly */ - if (IS_FOUNTAIN(lev->typ)) { - dogushforth(FALSE); - SET_FOUNTAIN_WARNED(x,y); /* force dryup */ - dryup(x, y, madeby_u); - return; - } else if (IS_SINK(lev->typ)) { - breaksink(x, y); - return; - } else if (lev->typ == DRAWBRIDGE_DOWN || - (is_drawbridge_wall(x, y) >= 0)) { - int bx = x, by = y; - /* if under the portcullis, the bridge is adjacent */ - (void) find_drawbridge(&bx, &by); - destroy_drawbridge(bx, by); - return; - } + /* these furniture checks were in dighole(), but wand + breaking bypasses that routine and calls us directly */ + if (IS_FOUNTAIN(lev->typ)) { + dogushforth(FALSE); + SET_FOUNTAIN_WARNED(x, y); /* force dryup */ + dryup(x, y, madeby_u); + return; + } else if (IS_SINK(lev->typ)) { + breaksink(x, y); + return; + } else if (lev->typ == DRAWBRIDGE_DOWN + || (is_drawbridge_wall(x, y) >= 0)) { + int bx = x, by = y; + /* if under the portcullis, the bridge is adjacent */ + (void) find_drawbridge(&bx, &by); + destroy_drawbridge(bx, by); + return; + } - if (ttyp != PIT && (!Can_dig_down(&u.uz) && !lev->candig)) { - impossible("digactualhole: can't dig %s on this level.", - defsyms[trap_to_defsym(ttyp)].explanation); - ttyp = PIT; - } + if (ttyp != PIT && (!Can_dig_down(&u.uz) && !lev->candig)) { + impossible("digactualhole: can't dig %s on this level.", + defsyms[trap_to_defsym(ttyp)].explanation); + ttyp = PIT; + } - /* maketrap() might change it, also, in this situation, - surface() returns an inappropriate string for a grave */ - if (IS_GRAVE(lev->typ)) - Strcpy(surface_type, "grave"); - else - Strcpy(surface_type, surface(x,y)); - shopdoor = IS_DOOR(lev->typ) && *in_rooms(x, y, SHOPBASE); - oldobjs = level.objects[x][y]; - ttmp = maketrap(x, y, ttyp); - if (!ttmp) return; - newobjs = level.objects[x][y]; - ttmp->madeby_u = madeby_u; - ttmp->tseen = 0; - if (cansee(x,y)) seetrap(ttmp); - else if (madeby_u) feeltrap(ttmp); + /* maketrap() might change it, also, in this situation, + surface() returns an inappropriate string for a grave */ + if (IS_GRAVE(lev->typ)) + Strcpy(surface_type, "grave"); + else + Strcpy(surface_type, surface(x, y)); + shopdoor = IS_DOOR(lev->typ) && *in_rooms(x, y, SHOPBASE); + oldobjs = level.objects[x][y]; + ttmp = maketrap(x, y, ttyp); + if (!ttmp) + return; + newobjs = level.objects[x][y]; + ttmp->madeby_u = madeby_u; + ttmp->tseen = 0; + if (cansee(x, y)) + seetrap(ttmp); + else if (madeby_u) + feeltrap(ttmp); - if (ttyp == PIT) { + if (ttyp == PIT) { + if (madeby_u) { + if (x != u.ux || y != u.uy) + You("dig an adjacent pit."); + else + You("dig a pit in the %s.", surface_type); + if (shopdoor) + pay_for_damage("ruin", FALSE); + } else if (!madeby_obj && canseemon(madeby)) + pline("%s digs a pit in the %s.", Monnam(madeby), surface_type); + else if (cansee(x, y) && flags.verbose) + pline("A pit appears in the %s.", surface_type); - if(madeby_u) { - if (x != u.ux || y != u.uy) - You("dig an adjacent pit."); - else - You("dig a pit in the %s.", surface_type); - if (shopdoor) pay_for_damage("ruin", FALSE); - } else if (!madeby_obj && canseemon(madeby)) - pline("%s digs a pit in the %s.", Monnam(madeby), surface_type); - else if (cansee(x, y) && flags.verbose) - pline("A pit appears in the %s.", surface_type); + if (at_u) { + if (!wont_fall) { + u.utrap = rn1(4, 2); + u.utraptype = TT_PIT; + vision_full_recalc = 1; /* vision limits change */ + } else + u.utrap = 0; + if (oldobjs != newobjs) /* something unearthed */ + (void) pickup(1); /* detects pit */ + } else if (mtmp) { + if (is_flyer(mtmp->data) || is_floater(mtmp->data)) { + if (canseemon(mtmp)) + pline("%s %s over the pit.", Monnam(mtmp), + (is_flyer(mtmp->data)) ? "flies" : "floats"); + } else if (mtmp != madeby) + (void) mintrap(mtmp); + } + } else { /* was TRAPDOOR now a HOLE*/ - if(at_u) { - if (!wont_fall) { - u.utrap = rn1(4,2); - u.utraptype = TT_PIT; - vision_full_recalc = 1; /* vision limits change */ - } else - u.utrap = 0; - if (oldobjs != newobjs) /* something unearthed */ - (void) pickup(1); /* detects pit */ - } else if(mtmp) { - if(is_flyer(mtmp->data) || is_floater(mtmp->data)) { - if(canseemon(mtmp)) - pline("%s %s over the pit.", Monnam(mtmp), - (is_flyer(mtmp->data)) ? - "flies" : "floats"); - } else if(mtmp != madeby) - (void) mintrap(mtmp); - } - } else { /* was TRAPDOOR now a HOLE*/ + if (madeby_u) + You("dig a hole through the %s.", surface_type); + else if (!madeby_obj && canseemon(madeby)) + pline("%s digs a hole through the %s.", Monnam(madeby), + surface_type); + else if (cansee(x, y) && flags.verbose) + pline("A hole appears in the %s.", surface_type); - if(madeby_u) - You("dig a hole through the %s.", surface_type); - else if(!madeby_obj && canseemon(madeby)) - pline("%s digs a hole through the %s.", - Monnam(madeby), surface_type); - else if(cansee(x, y) && flags.verbose) - pline("A hole appears in the %s.", surface_type); + if (at_u) { + if (!u.ustuck && !wont_fall && !next_to_u()) { + You("are jerked back by your pet!"); + wont_fall = TRUE; + } - if (at_u) { - if (!u.ustuck && !wont_fall && !next_to_u()) { - You("are jerked back by your pet!"); - wont_fall = TRUE; - } + /* Floor objects get a chance of falling down. The case where + * the hero does NOT fall down is treated here. The case + * where the hero does fall down is treated in goto_level(). + */ + if (u.ustuck || wont_fall) { + if (newobjs) + impact_drop((struct obj *) 0, x, y, 0); + if (oldobjs != newobjs) + (void) pickup(1); + if (shopdoor && madeby_u) + pay_for_damage("ruin", FALSE); - /* Floor objects get a chance of falling down. The case where - * the hero does NOT fall down is treated here. The case - * where the hero does fall down is treated in goto_level(). - */ - if (u.ustuck || wont_fall) { - if (newobjs) - impact_drop((struct obj *)0, x, y, 0); - if (oldobjs != newobjs) - (void) pickup(1); - if (shopdoor && madeby_u) pay_for_damage("ruin", FALSE); + } else { + d_level newlevel; - } else { - d_level newlevel; + if (*u.ushops && madeby_u) + shopdig(1); /* shk might snatch pack */ + /* handle earlier damage, eg breaking wand of digging */ + else if (!madeby_u) + pay_for_damage("dig into", TRUE); - if (*u.ushops && madeby_u) - shopdig(1); /* shk might snatch pack */ - /* handle earlier damage, eg breaking wand of digging */ - else if (!madeby_u) pay_for_damage("dig into", TRUE); + You("fall through..."); + /* Earlier checks must ensure that the destination + * level exists and is in the present dungeon. + */ + newlevel.dnum = u.uz.dnum; + newlevel.dlevel = u.uz.dlevel + 1; + goto_level(&newlevel, FALSE, TRUE, FALSE); + /* messages for arriving in special rooms */ + spoteffects(FALSE); + } + } else { + if (shopdoor && madeby_u) + pay_for_damage("ruin", FALSE); + if (newobjs) + impact_drop((struct obj *) 0, x, y, 0); + if (mtmp) { + /*[don't we need special sokoban handling here?]*/ + if (is_flyer(mtmp->data) || is_floater(mtmp->data) + || mtmp->data == &mons[PM_WUMPUS] + || (mtmp->wormno && count_wsegs(mtmp) > 5) + || mtmp->data->msize >= MZ_HUGE) + return; + if (mtmp == u.ustuck) /* probably a vortex */ + return; /* temporary? kludge */ - You("fall through..."); - /* Earlier checks must ensure that the destination - * level exists and is in the present dungeon. - */ - newlevel.dnum = u.uz.dnum; - newlevel.dlevel = u.uz.dlevel + 1; - goto_level(&newlevel, FALSE, TRUE, FALSE); - /* messages for arriving in special rooms */ - spoteffects(FALSE); - } - } else { - if (shopdoor && madeby_u) pay_for_damage("ruin", FALSE); - if (newobjs) - impact_drop((struct obj *)0, x, y, 0); - if (mtmp) { - /*[don't we need special sokoban handling here?]*/ - if (is_flyer(mtmp->data) || is_floater(mtmp->data) || - mtmp->data == &mons[PM_WUMPUS] || - (mtmp->wormno && count_wsegs(mtmp) > 5) || - mtmp->data->msize >= MZ_HUGE) return; - if (mtmp == u.ustuck) /* probably a vortex */ - return; /* temporary? kludge */ + if (teleport_pet(mtmp, FALSE)) { + d_level tolevel; - if (teleport_pet(mtmp, FALSE)) { - d_level tolevel; - - if (Is_stronghold(&u.uz)) { - assign_level(&tolevel, &valley_level); - } else if (Is_botlevel(&u.uz)) { - if (canseemon(mtmp)) - pline("%s avoids the trap.", Monnam(mtmp)); - return; - } else { - get_level(&tolevel, depth(&u.uz) + 1); - } - if (mtmp->isshk) make_angry_shk(mtmp, 0, 0); - migrate_to_level(mtmp, ledger_no(&tolevel), - MIGR_RANDOM, (coord *)0); - } - } - } - } + if (Is_stronghold(&u.uz)) { + assign_level(&tolevel, &valley_level); + } else if (Is_botlevel(&u.uz)) { + if (canseemon(mtmp)) + pline("%s avoids the trap.", Monnam(mtmp)); + return; + } else { + get_level(&tolevel, depth(&u.uz) + 1); + } + if (mtmp->isshk) + make_angry_shk(mtmp, 0, 0); + migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM, + (coord *) 0); + } + } + } + } } /* @@ -689,24 +729,26 @@ int ttyp; */ void liquid_flow(x, y, typ, ttmp, fillmsg) -xchar x,y; +xchar x, y; schar typ; struct trap *ttmp; const char *fillmsg; { - boolean u_spot = (x == u.ux && y == u.uy); + boolean u_spot = (x == u.ux && y == u.uy); - if (ttmp) (void) delfloortrap(ttmp); - /* if any objects were frozen here, they're released now */ - unearth_objs(x, y); + if (ttmp) + (void) delfloortrap(ttmp); + /* if any objects were frozen here, they're released now */ + unearth_objs(x, y); - if (fillmsg) pline(fillmsg, typ == LAVAPOOL ? "lava" : "water"); - if (u_spot && !(Levitation || Flying)) { - if (typ == LAVAPOOL) - (void) lava_effects(); - else if (!Wwalking) - (void) drown(); - } + if (fillmsg) + pline(fillmsg, typ == LAVAPOOL ? "lava" : "water"); + if (u_spot && !(Levitation || Flying)) { + if (typ == LAVAPOOL) + (void) lava_effects(); + else if (!Wwalking) + (void) drown(); + } } /* return TRUE if digging succeeded, FALSE otherwise */ @@ -715,252 +757,257 @@ dighole(pit_only, by_magic, cc) boolean pit_only, by_magic; coord *cc; { - register struct trap *ttmp; - struct rm *lev; - struct obj *boulder_here; - schar typ; - xchar dig_x,dig_y; - boolean nohole; + register struct trap *ttmp; + struct rm *lev; + struct obj *boulder_here; + schar typ; + xchar dig_x, dig_y; + boolean nohole; - if (!cc) { - dig_x = u.ux; - dig_y = u.uy; - } else { - dig_x = cc->x; - dig_y = cc->y; - if (!isok(dig_x,dig_y)) return FALSE; - } + if (!cc) { + dig_x = u.ux; + dig_y = u.uy; + } else { + dig_x = cc->x; + dig_y = cc->y; + if (!isok(dig_x, dig_y)) + return FALSE; + } - ttmp = t_at(dig_x, dig_y); - lev = &levl[dig_x][dig_y]; - nohole = (!Can_dig_down(&u.uz) && !lev->candig); + ttmp = t_at(dig_x, dig_y); + lev = &levl[dig_x][dig_y]; + nohole = (!Can_dig_down(&u.uz) && !lev->candig); - if ((ttmp && (ttmp->ttyp == MAGIC_PORTAL || nohole)) || - (IS_ROCK(lev->typ) && lev->typ != SDOOR && - (lev->wall_info & W_NONDIGGABLE) != 0)) { - pline_The("%s %shere is too hard to dig in.", - surface(dig_x,dig_y), - (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); + if ((ttmp && (ttmp->ttyp == MAGIC_PORTAL || nohole)) + || (IS_ROCK(lev->typ) && lev->typ != SDOOR + && (lev->wall_info & W_NONDIGGABLE) != 0)) { + pline_The("%s %shere is too hard to dig in.", surface(dig_x, dig_y), + (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); - } else if (is_pool_or_lava(dig_x, dig_y)) { - pline_The("%s sloshes furiously for a moment, then subsides.", - is_lava(dig_x, dig_y) ? "lava" : "water"); - wake_nearby(); /* splashing */ + } else if (is_pool_or_lava(dig_x, dig_y)) { + pline_The("%s sloshes furiously for a moment, then subsides.", + is_lava(dig_x, dig_y) ? "lava" : "water"); + wake_nearby(); /* splashing */ - } else if (lev->typ == DRAWBRIDGE_DOWN || - (is_drawbridge_wall(dig_x, dig_y) >= 0)) { - /* drawbridge_down is the platform crossing the moat when the - bridge is extended; drawbridge_wall is the open "doorway" or - closed "door" where the portcullis/mechanism is located */ - if (pit_only) { - pline_The("drawbridge seems too hard to dig through."); - return FALSE; - } else { - int x = dig_x, y = dig_y; - /* if under the portcullis, the bridge is adjacent */ - (void) find_drawbridge(&x, &y); - destroy_drawbridge(x, y); - return TRUE; - } + } else if (lev->typ == DRAWBRIDGE_DOWN + || (is_drawbridge_wall(dig_x, dig_y) >= 0)) { + /* drawbridge_down is the platform crossing the moat when the + bridge is extended; drawbridge_wall is the open "doorway" or + closed "door" where the portcullis/mechanism is located */ + if (pit_only) { + pline_The("drawbridge seems too hard to dig through."); + return FALSE; + } else { + int x = dig_x, y = dig_y; + /* if under the portcullis, the bridge is adjacent */ + (void) find_drawbridge(&x, &y); + destroy_drawbridge(x, y); + return TRUE; + } - } else if ((boulder_here = sobj_at(BOULDER, dig_x, dig_y)) != 0) { - if (ttmp && (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) && - rn2(2)) { - pline_The("boulder settles into the %spit.", - (dig_x != u.ux || dig_y != u.uy) ? - "adjacent " : ""); - ttmp->ttyp = PIT; /* crush spikes */ - } else { - /* - * digging makes a hole, but the boulder immediately - * fills it. Final outcome: no hole, no boulder. - */ - pline("KADOOM! The boulder falls in!"); - (void) delfloortrap(ttmp); - } - delobj(boulder_here); - return TRUE; + } else if ((boulder_here = sobj_at(BOULDER, dig_x, dig_y)) != 0) { + if (ttmp && (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) + && rn2(2)) { + pline_The("boulder settles into the %spit.", + (dig_x != u.ux || dig_y != u.uy) ? "adjacent " : ""); + ttmp->ttyp = PIT; /* crush spikes */ + } else { + /* + * digging makes a hole, but the boulder immediately + * fills it. Final outcome: no hole, no boulder. + */ + pline("KADOOM! The boulder falls in!"); + (void) delfloortrap(ttmp); + } + delobj(boulder_here); + return TRUE; - } else if (IS_GRAVE(lev->typ)) { - digactualhole(dig_x, dig_y, BY_YOU, PIT); - dig_up_grave(cc); - return TRUE; - } else if (lev->typ == DRAWBRIDGE_UP) { - /* must be floor or ice, other cases handled above */ - /* dig "pit" and let fluid flow in (if possible) */ - typ = fillholetyp(dig_x,dig_y,FALSE); + } else if (IS_GRAVE(lev->typ)) { + digactualhole(dig_x, dig_y, BY_YOU, PIT); + dig_up_grave(cc); + return TRUE; + } else if (lev->typ == DRAWBRIDGE_UP) { + /* must be floor or ice, other cases handled above */ + /* dig "pit" and let fluid flow in (if possible) */ + typ = fillholetyp(dig_x, dig_y, FALSE); - if (typ == ROOM) { - /* - * We can't dig a hole here since that will destroy - * the drawbridge. The following is a cop-out. --dlc - */ - pline_The("%s %shere is too hard to dig in.", - surface(dig_x, dig_y), - (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); - return FALSE; - } + if (typ == ROOM) { + /* + * We can't dig a hole here since that will destroy + * the drawbridge. The following is a cop-out. --dlc + */ + pline_The("%s %shere is too hard to dig in.", + surface(dig_x, dig_y), + (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); + return FALSE; + } - lev->drawbridgemask &= ~DB_UNDER; - lev->drawbridgemask |= (typ == LAVAPOOL) ? DB_LAVA : DB_MOAT; - liquid_flow(dig_x, dig_y, typ, ttmp, - "As you dig, the hole fills with %s!"); - return TRUE; + lev->drawbridgemask &= ~DB_UNDER; + lev->drawbridgemask |= (typ == LAVAPOOL) ? DB_LAVA : DB_MOAT; + liquid_flow(dig_x, dig_y, typ, ttmp, + "As you dig, the hole fills with %s!"); + return TRUE; - /* the following two are here for the wand of digging */ - } else if (IS_THRONE(lev->typ)) { - pline_The("throne is too hard to break apart."); + /* the following two are here for the wand of digging */ + } else if (IS_THRONE(lev->typ)) { + pline_The("throne is too hard to break apart."); - } else if (IS_ALTAR(lev->typ)) { - pline_The("altar is too hard to break apart."); + } else if (IS_ALTAR(lev->typ)) { + pline_The("altar is too hard to break apart."); - } else { - typ = fillholetyp(dig_x,dig_y,FALSE); + } else { + typ = fillholetyp(dig_x, dig_y, FALSE); - if (typ != ROOM) { - lev->typ = typ; - liquid_flow(dig_x, dig_y, typ, ttmp, - "As you dig, the hole fills with %s!"); - return TRUE; - } + if (typ != ROOM) { + lev->typ = typ; + liquid_flow(dig_x, dig_y, typ, ttmp, + "As you dig, the hole fills with %s!"); + return TRUE; + } - /* magical digging disarms settable traps */ - if (by_magic && ttmp && - (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)) { - int otyp = (ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP; + /* magical digging disarms settable traps */ + if (by_magic && ttmp + && (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)) { + int otyp = (ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP; - /* convert trap into buried object (deletes trap) */ - cnv_trap_obj(otyp, 1, ttmp, TRUE); - } + /* convert trap into buried object (deletes trap) */ + cnv_trap_obj(otyp, 1, ttmp, TRUE); + } - /* finally we get to make a hole */ - if (nohole || pit_only) - digactualhole(dig_x, dig_y, BY_YOU, PIT); - else - digactualhole(dig_x, dig_y, BY_YOU, HOLE); + /* finally we get to make a hole */ + if (nohole || pit_only) + digactualhole(dig_x, dig_y, BY_YOU, PIT); + else + digactualhole(dig_x, dig_y, BY_YOU, HOLE); - return TRUE; - } + return TRUE; + } - return FALSE; + return FALSE; } STATIC_OVL void dig_up_grave(cc) coord *cc; { - struct obj *otmp; - xchar dig_x, dig_y; + struct obj *otmp; + xchar dig_x, dig_y; - if (!cc) { - dig_x = u.ux; - dig_y = u.uy; - } else { - dig_x = cc->x; - dig_y = cc->y; - if (!isok(dig_x,dig_y)) return ; - } + if (!cc) { + dig_x = u.ux; + dig_y = u.uy; + } else { + dig_x = cc->x; + dig_y = cc->y; + if (!isok(dig_x, dig_y)) + return; + } + /* Grave-robbing is frowned upon... */ + exercise(A_WIS, FALSE); + if (Role_if(PM_ARCHEOLOGIST)) { + adjalign(-sgn(u.ualign.type) * 3); + You_feel("like a despicable grave-robber!"); + } else if (Role_if(PM_SAMURAI)) { + adjalign(-sgn(u.ualign.type)); + You("disturb the honorable dead!"); + } else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) { + adjalign(-sgn(u.ualign.type)); + You("have violated the sanctity of this grave!"); + } - /* Grave-robbing is frowned upon... */ - exercise(A_WIS, FALSE); - if (Role_if(PM_ARCHEOLOGIST)) { - adjalign(-sgn(u.ualign.type)*3); - You_feel("like a despicable grave-robber!"); - } else if (Role_if(PM_SAMURAI)) { - adjalign(-sgn(u.ualign.type)); - You("disturb the honorable dead!"); - } else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) { - adjalign(-sgn(u.ualign.type)); - You("have violated the sanctity of this grave!"); - } - - switch (rn2(5)) { - case 0: - case 1: - You("unearth a corpse."); - if (!!(otmp = mk_tt_object(CORPSE, dig_x, dig_y))) - otmp->age -= 100; /* this is an *OLD* corpse */; - break; - case 2: - if (!Blind) pline(Hallucination ? "Dude! The living dead!" : - "The grave's owner is very upset!"); - (void) makemon(mkclass(S_ZOMBIE,0), dig_x, dig_y, NO_MM_FLAGS); - break; - case 3: - if (!Blind) pline(Hallucination ? "I want my mummy!" : - "You've disturbed a tomb!"); - (void) makemon(mkclass(S_MUMMY,0), dig_x, dig_y, NO_MM_FLAGS); - break; - default: - /* No corpse */ - pline_The("grave seems unused. Strange...."); - break; - } - levl[dig_x][dig_y].typ = ROOM; - del_engr_at(dig_x, dig_y); - newsym(dig_x,dig_y); - return; + switch (rn2(5)) { + case 0: + case 1: + You("unearth a corpse."); + if (!!(otmp = mk_tt_object(CORPSE, dig_x, dig_y))) + otmp->age -= 100; /* this is an *OLD* corpse */ + ; + break; + case 2: + if (!Blind) + pline(Hallucination ? "Dude! The living dead!" + : "The grave's owner is very upset!"); + (void) makemon(mkclass(S_ZOMBIE, 0), dig_x, dig_y, NO_MM_FLAGS); + break; + case 3: + if (!Blind) + pline(Hallucination ? "I want my mummy!" + : "You've disturbed a tomb!"); + (void) makemon(mkclass(S_MUMMY, 0), dig_x, dig_y, NO_MM_FLAGS); + break; + default: + /* No corpse */ + pline_The("grave seems unused. Strange...."); + break; + } + levl[dig_x][dig_y].typ = ROOM; + del_engr_at(dig_x, dig_y); + newsym(dig_x, dig_y); + return; } int use_pick_axe(obj) struct obj *obj; { - const char *sdp, *verb; - char *dsp, dirsyms[12], qbuf[BUFSZ]; - boolean ispick; - int rx, ry, downok, res = 0; + const char *sdp, *verb; + char *dsp, dirsyms[12], qbuf[BUFSZ]; + boolean ispick; + int rx, ry, downok, res = 0; - /* Check tool */ - if (obj != uwep) { - if (!wield_tool(obj, "swing")) return 0; - else res = 1; - } - ispick = is_pick(obj); - verb = ispick ? "dig" : "chop"; + /* Check tool */ + if (obj != uwep) { + if (!wield_tool(obj, "swing")) + return 0; + else + res = 1; + } + ispick = is_pick(obj); + verb = ispick ? "dig" : "chop"; - if (u.utrap && u.utraptype == TT_WEB) { - pline("%s you can't %s while entangled in a web.", - /* res==0 => no prior message; - res==1 => just got "You now wield a pick-axe." message */ - !res ? "Unfortunately," : "But", verb); - return res; - } + if (u.utrap && u.utraptype == TT_WEB) { + pline("%s you can't %s while entangled in a web.", + /* res==0 => no prior message; + res==1 => just got "You now wield a pick-axe." message */ + !res ? "Unfortunately," : "But", verb); + return res; + } - /* construct list of directions to show player for likely choices */ - downok = !!can_reach_floor(FALSE); - dsp = dirsyms; - for (sdp = Cmd.dirchars; *sdp; ++sdp) { - /* filter out useless directions */ - if (u.uswallow) { - ; /* all directions are viable when swallowed */ - } else if (movecmd(*sdp)) { - /* normal direction, within plane of the level map; - movecmd() sets u.dx, u.dy, u.dz and returns !u.dz */ - if (!dxdy_moveok()) continue; /* handle NODIAG */ - rx = u.ux + u.dx; - ry = u.uy + u.dy; - if (!isok(rx, ry) || dig_typ(obj, rx, ry) == DIGTYP_UNDIGGABLE) - continue; - } else { - /* up or down; we used to always include down, so that - there would always be at least one choice shown, but - it shouldn't be a likely candidate when floating high - above the floor; include up instead in that situation - (as a silly candidate rather than a likely one...) */ - if ((u.dz > 0) ^ downok) continue; - } - /* include this direction */ - *dsp++ = *sdp; - } - *dsp = 0; - Sprintf(qbuf, "In what direction do you want to %s? [%s]", - verb, dirsyms); - if(!getdir(qbuf)) - return(res); + /* construct list of directions to show player for likely choices */ + downok = !!can_reach_floor(FALSE); + dsp = dirsyms; + for (sdp = Cmd.dirchars; *sdp; ++sdp) { + /* filter out useless directions */ + if (u.uswallow) { + ; /* all directions are viable when swallowed */ + } else if (movecmd(*sdp)) { + /* normal direction, within plane of the level map; + movecmd() sets u.dx, u.dy, u.dz and returns !u.dz */ + if (!dxdy_moveok()) + continue; /* handle NODIAG */ + rx = u.ux + u.dx; + ry = u.uy + u.dy; + if (!isok(rx, ry) || dig_typ(obj, rx, ry) == DIGTYP_UNDIGGABLE) + continue; + } else { + /* up or down; we used to always include down, so that + there would always be at least one choice shown, but + it shouldn't be a likely candidate when floating high + above the floor; include up instead in that situation + (as a silly candidate rather than a likely one...) */ + if ((u.dz > 0) ^ downok) + continue; + } + /* include this direction */ + *dsp++ = *sdp; + } + *dsp = 0; + Sprintf(qbuf, "In what direction do you want to %s? [%s]", verb, dirsyms); + if (!getdir(qbuf)) + return (res); - return(use_pick_axe2(obj)); + return (use_pick_axe2(obj)); } /* MRKR: use_pick_axe() is split in two to allow autodig to bypass */ @@ -968,188 +1015,180 @@ struct obj *obj; /* use_pick_axe2() uses the existing u.dx, u.dy and u.dz */ int -use_pick_axe2(obj) +use_pick_axe2(obj) struct obj *obj; { - register int rx, ry; - register struct rm *lev; - struct trap *trap, *trap_with_u; - int dig_target; - boolean ispick = is_pick(obj); - const char *verbing = ispick ? "digging" : "chopping"; + register int rx, ry; + register struct rm *lev; + struct trap *trap, *trap_with_u; + int dig_target; + boolean ispick = is_pick(obj); + const char *verbing = ispick ? "digging" : "chopping"; - if (u.uswallow && attack(u.ustuck)) { - ; /* return(1) */ - } else if (Underwater) { - pline("Turbulence torpedoes your %s attempts.", verbing); - } else if(u.dz < 0) { - if(Levitation) - You("don't have enough leverage."); - else - You_cant("reach the %s.",ceiling(u.ux,u.uy)); - } else if(!u.dx && !u.dy && !u.dz) { - char buf[BUFSZ]; - int dam; + if (u.uswallow && attack(u.ustuck)) { + ; /* return(1) */ + } else if (Underwater) { + pline("Turbulence torpedoes your %s attempts.", verbing); + } else if (u.dz < 0) { + if (Levitation) + You("don't have enough leverage."); + else + You_cant("reach the %s.", ceiling(u.ux, u.uy)); + } else if (!u.dx && !u.dy && !u.dz) { + char buf[BUFSZ]; + int dam; - dam = rnd(2) + dbon() + obj->spe; - if (dam <= 0) dam = 1; - You("hit yourself with %s.", yname(uwep)); - Sprintf(buf, "%s own %s", uhis(), - OBJ_NAME(objects[obj->otyp])); - losehp(Maybe_Half_Phys(dam), buf, KILLED_BY); - context.botl=1; - return(1); - } else if(u.dz == 0) { - if(Stunned || (Confusion && !rn2(5))) confdir(); - rx = u.ux + u.dx; - ry = u.uy + u.dy; - if(!isok(rx, ry)) { - pline("Clash!"); - return(1); - } - lev = &levl[rx][ry]; - if(MON_AT(rx, ry) && attack(m_at(rx, ry))) - return(1); - dig_target = dig_typ(obj, rx, ry); - if (dig_target == DIGTYP_UNDIGGABLE) { - /* ACCESSIBLE or POOL */ - trap = t_at(rx, ry); - if (trap && trap->ttyp == WEB) { - if (!trap->tseen) { - seetrap(trap); - There("is a spider web there!"); - } - pline("%s entangled in the web.", - Yobjnam2(obj, "become")); - /* you ought to be able to let go; tough luck */ - /* (maybe `move_into_trap()' would be better) */ - nomul(-d(2,2)); - multi_reason = "stuck in a spider web"; - nomovemsg = "You pull free."; - } else if (lev->typ == IRONBARS) { - pline("Clang!"); - wake_nearby(); - } else if (IS_TREE(lev->typ)) - You("need an axe to cut down a tree."); - else if (IS_ROCK(lev->typ)) - You("need a pick to dig rock."); - else if (!ispick && (sobj_at(STATUE, rx, ry) || - sobj_at(BOULDER, rx, ry))) { - boolean vibrate = !rn2(3); - pline("Sparks fly as you whack the %s.%s", - sobj_at(STATUE, rx, ry) ? "statue" : "boulder", - vibrate ? " The axe-handle vibrates violently!" : ""); - if (vibrate) losehp(Maybe_Half_Phys(2), - "axing a hard object", KILLED_BY); - } - else if (u.utrap && u.utraptype == TT_PIT && trap && - (trap_with_u = t_at(u.ux, u.uy)) && - (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) && - !conjoined_pits(trap, trap_with_u, FALSE)) { - int idx; - for (idx = 0; idx < 8; idx++) { - if (xdir[idx] == u.dx && ydir[idx] == u.dy) - break; - } - /* idx is valid if < 8 */ - if (idx < 8) { - int adjidx = (idx + 4) % 8; - trap_with_u->conjoined |= (1 << idx); - trap->conjoined |= (1 << adjidx); - pline( - "You clear some debris from between the pits."); - } - } - else if (u.utrap && u.utraptype == TT_PIT && - (trap_with_u = t_at(u.ux, u.uy))) { - You("swing %s, but the rubble has no place to go.", - yobjnam(obj, (char *)0)); - } - else - You("swing %s through thin air.", - yobjnam(obj, (char *)0)); - } else { - static const char * const d_action[6] = { - "swinging", - "digging", - "chipping the statue", - "hitting the boulder", - "chopping at the door", - "cutting the tree" - }; - did_dig_msg = FALSE; - context.digging.quiet = FALSE; - if (context.digging.pos.x != rx || - context.digging.pos.y != ry || - !on_level(&context.digging.level, &u.uz) || - context.digging.down) { - if (flags.autodig && - dig_target == DIGTYP_ROCK && !context.digging.down && - context.digging.pos.x == u.ux && - context.digging.pos.y == u.uy && - (moves <= context.digging.lastdigtime+2 && - moves >= context.digging.lastdigtime)) { - /* avoid messages if repeated autodigging */ - did_dig_msg = TRUE; - context.digging.quiet = TRUE; - } - context.digging.down = context.digging.chew = FALSE; - context.digging.warned = FALSE; - context.digging.pos.x = rx; - context.digging.pos.y = ry; - assign_level(&context.digging.level, &u.uz); - context.digging.effort = 0; - if (!context.digging.quiet) - You("start %s.", d_action[dig_target]); - } else { - You("%s %s.", context.digging.chew ? "begin" : "continue", - d_action[dig_target]); - context.digging.chew = FALSE; - } - set_occupation(dig, verbing, 0); - } - } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { - /* it must be air -- water checked above */ - You("swing %s through thin air.", yobjnam(obj, (char *)0)); - } else if (!can_reach_floor(FALSE)) { - cant_reach_floor(u.ux, u.uy, FALSE, FALSE); - } else if (is_pool_or_lava(u.ux, u.uy)) { - /* Monsters which swim also happen not to be able to dig */ - You("cannot stay under%s long enough.", - is_pool(u.ux, u.uy) ? "water" : " the lava"); - } else if ((trap = t_at(u.ux, u.uy)) != 0 && - uteetering_at_seen_pit(trap)) { - dotrap(trap, FORCEBUNGLE); - /* might escape trap and still be teetering at brink */ - if (!u.utrap) cant_reach_floor(u.ux, u.uy, FALSE, TRUE); - } else if (!ispick && - /* can only dig down with an axe when doing so will - trigger or disarm a trap here */ - (!trap || (trap->ttyp != LANDMINE && - trap->ttyp != BEAR_TRAP))) { - pline("%s merely scratches the %s.", - Yobjnam2(obj, (char *)0), surface(u.ux,u.uy)); - u_wipe_engr(3); - } else { - if (context.digging.pos.x != u.ux || - context.digging.pos.y != u.uy || - !on_level(&context.digging.level, &u.uz) || - !context.digging.down) { - context.digging.chew = FALSE; - context.digging.down = TRUE; - context.digging.warned = FALSE; - context.digging.pos.x = u.ux; - context.digging.pos.y = u.uy; - assign_level(&context.digging.level, &u.uz); - context.digging.effort = 0; - You("start %s downward.", verbing); - if (*u.ushops) shopdig(0); - } else - You("continue %s downward.", verbing); - did_dig_msg = FALSE; - set_occupation(dig, verbing, 0); - } - return(1); + dam = rnd(2) + dbon() + obj->spe; + if (dam <= 0) + dam = 1; + You("hit yourself with %s.", yname(uwep)); + Sprintf(buf, "%s own %s", uhis(), OBJ_NAME(objects[obj->otyp])); + losehp(Maybe_Half_Phys(dam), buf, KILLED_BY); + context.botl = 1; + return (1); + } else if (u.dz == 0) { + if (Stunned || (Confusion && !rn2(5))) + confdir(); + rx = u.ux + u.dx; + ry = u.uy + u.dy; + if (!isok(rx, ry)) { + pline("Clash!"); + return (1); + } + lev = &levl[rx][ry]; + if (MON_AT(rx, ry) && attack(m_at(rx, ry))) + return (1); + dig_target = dig_typ(obj, rx, ry); + if (dig_target == DIGTYP_UNDIGGABLE) { + /* ACCESSIBLE or POOL */ + trap = t_at(rx, ry); + if (trap && trap->ttyp == WEB) { + if (!trap->tseen) { + seetrap(trap); + There("is a spider web there!"); + } + pline("%s entangled in the web.", Yobjnam2(obj, "become")); + /* you ought to be able to let go; tough luck */ + /* (maybe `move_into_trap()' would be better) */ + nomul(-d(2, 2)); + multi_reason = "stuck in a spider web"; + nomovemsg = "You pull free."; + } else if (lev->typ == IRONBARS) { + pline("Clang!"); + wake_nearby(); + } else if (IS_TREE(lev->typ)) + You("need an axe to cut down a tree."); + else if (IS_ROCK(lev->typ)) + You("need a pick to dig rock."); + else if (!ispick && (sobj_at(STATUE, rx, ry) + || sobj_at(BOULDER, rx, ry))) { + boolean vibrate = !rn2(3); + pline("Sparks fly as you whack the %s.%s", + sobj_at(STATUE, rx, ry) ? "statue" : "boulder", + vibrate ? " The axe-handle vibrates violently!" : ""); + if (vibrate) + losehp(Maybe_Half_Phys(2), "axing a hard object", + KILLED_BY); + } else if (u.utrap && u.utraptype == TT_PIT && trap + && (trap_with_u = t_at(u.ux, u.uy)) + && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) + && !conjoined_pits(trap, trap_with_u, FALSE)) { + int idx; + for (idx = 0; idx < 8; idx++) { + if (xdir[idx] == u.dx && ydir[idx] == u.dy) + break; + } + /* idx is valid if < 8 */ + if (idx < 8) { + int adjidx = (idx + 4) % 8; + trap_with_u->conjoined |= (1 << idx); + trap->conjoined |= (1 << adjidx); + pline("You clear some debris from between the pits."); + } + } else if (u.utrap && u.utraptype == TT_PIT + && (trap_with_u = t_at(u.ux, u.uy))) { + You("swing %s, but the rubble has no place to go.", + yobjnam(obj, (char *) 0)); + } else + You("swing %s through thin air.", yobjnam(obj, (char *) 0)); + } else { + static const char *const d_action[6] = { "swinging", "digging", + "chipping the statue", + "hitting the boulder", + "chopping at the door", + "cutting the tree" }; + did_dig_msg = FALSE; + context.digging.quiet = FALSE; + if (context.digging.pos.x != rx || context.digging.pos.y != ry + || !on_level(&context.digging.level, &u.uz) + || context.digging.down) { + if (flags.autodig && dig_target == DIGTYP_ROCK + && !context.digging.down && context.digging.pos.x == u.ux + && context.digging.pos.y == u.uy + && (moves <= context.digging.lastdigtime + 2 + && moves >= context.digging.lastdigtime)) { + /* avoid messages if repeated autodigging */ + did_dig_msg = TRUE; + context.digging.quiet = TRUE; + } + context.digging.down = context.digging.chew = FALSE; + context.digging.warned = FALSE; + context.digging.pos.x = rx; + context.digging.pos.y = ry; + assign_level(&context.digging.level, &u.uz); + context.digging.effort = 0; + if (!context.digging.quiet) + You("start %s.", d_action[dig_target]); + } else { + You("%s %s.", context.digging.chew ? "begin" : "continue", + d_action[dig_target]); + context.digging.chew = FALSE; + } + set_occupation(dig, verbing, 0); + } + } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { + /* it must be air -- water checked above */ + You("swing %s through thin air.", yobjnam(obj, (char *) 0)); + } else if (!can_reach_floor(FALSE)) { + cant_reach_floor(u.ux, u.uy, FALSE, FALSE); + } else if (is_pool_or_lava(u.ux, u.uy)) { + /* Monsters which swim also happen not to be able to dig */ + You("cannot stay under%s long enough.", + is_pool(u.ux, u.uy) ? "water" : " the lava"); + } else if ((trap = t_at(u.ux, u.uy)) != 0 + && uteetering_at_seen_pit(trap)) { + dotrap(trap, FORCEBUNGLE); + /* might escape trap and still be teetering at brink */ + if (!u.utrap) + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); + } else if (!ispick && + /* can only dig down with an axe when doing so will + trigger or disarm a trap here */ + (!trap + || (trap->ttyp != LANDMINE && trap->ttyp != BEAR_TRAP))) { + pline("%s merely scratches the %s.", Yobjnam2(obj, (char *) 0), + surface(u.ux, u.uy)); + u_wipe_engr(3); + } else { + if (context.digging.pos.x != u.ux || context.digging.pos.y != u.uy + || !on_level(&context.digging.level, &u.uz) + || !context.digging.down) { + context.digging.chew = FALSE; + context.digging.down = TRUE; + context.digging.warned = FALSE; + context.digging.pos.x = u.ux; + context.digging.pos.y = u.uy; + assign_level(&context.digging.level, &u.uz); + context.digging.effort = 0; + You("start %s downward.", verbing); + if (*u.ushops) + shopdig(0); + } else + You("continue %s downward.", verbing); + did_dig_msg = FALSE; + set_occupation(dig, verbing, 0); + } + return (1); } /* @@ -1160,47 +1199,47 @@ struct obj *obj; */ void watch_dig(mtmp, x, y, zap) - struct monst *mtmp; - xchar x, y; - boolean zap; +struct monst *mtmp; +xchar x, y; +boolean zap; { - struct rm *lev = &levl[x][y]; + struct rm *lev = &levl[x][y]; - if (in_town(x, y) && - (closed_door(x, y) || lev->typ == SDOOR || - IS_WALL(lev->typ) || IS_FOUNTAIN(lev->typ) || IS_TREE(lev->typ))) { - if (!mtmp) { - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_watch(mtmp->data) && - mtmp->mcansee && m_canseeu(mtmp) && - couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful) - break; - } - } + if (in_town(x, y) + && (closed_door(x, y) || lev->typ == SDOOR || IS_WALL(lev->typ) + || IS_FOUNTAIN(lev->typ) || IS_TREE(lev->typ))) { + if (!mtmp) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_watch(mtmp->data) && mtmp->mcansee && m_canseeu(mtmp) + && couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful) + break; + } + } - if (mtmp) { - if(zap || context.digging.warned) { - verbalize("Halt, vandal! You're under arrest!"); - (void) angry_guards(!!Deaf); - } else { - const char *str; + if (mtmp) { + if (zap || context.digging.warned) { + verbalize("Halt, vandal! You're under arrest!"); + (void) angry_guards(!!Deaf); + } else { + const char *str; - if (IS_DOOR(lev->typ)) - str = "door"; - else if (IS_TREE(lev->typ)) - str = "tree"; - else if (IS_ROCK(lev->typ)) - str = "wall"; - else - str = "fountain"; - verbalize("Hey, stop damaging that %s!", str); - context.digging.warned = TRUE; - } - if (is_digging()) - stop_occupation(); - } - } + if (IS_DOOR(lev->typ)) + str = "door"; + else if (IS_TREE(lev->typ)) + str = "tree"; + else if (IS_ROCK(lev->typ)) + str = "wall"; + else + str = "fountain"; + verbalize("Hey, stop damaging that %s!", str); + context.digging.warned = TRUE; + } + if (is_digging()) + stop_occupation(); + } + } } /* Return TRUE if monster died, FALSE otherwise. Called from m_move(). */ @@ -1208,272 +1247,278 @@ boolean mdig_tunnel(mtmp) register struct monst *mtmp; { - register struct rm *here; - int pile = rnd(12); + register struct rm *here; + int pile = rnd(12); - here = &levl[mtmp->mx][mtmp->my]; - if (here->typ == SDOOR) - cvt_sdoor_to_door(here); /* ->typ = DOOR */ + here = &levl[mtmp->mx][mtmp->my]; + if (here->typ == SDOOR) + cvt_sdoor_to_door(here); /* ->typ = DOOR */ - /* Eats away door if present & closed or locked */ - if (closed_door(mtmp->mx, mtmp->my)) { - if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) - add_damage(mtmp->mx, mtmp->my, 0L); - unblock_point(mtmp->mx, mtmp->my); /* vision */ - if (here->doormask & D_TRAPPED) { - here->doormask = D_NODOOR; - if (mb_trapped(mtmp)) { /* mtmp is killed */ - newsym(mtmp->mx, mtmp->my); - return TRUE; - } - } else { - if (!rn2(3) && flags.verbose) /* not too often.. */ - You_feel("an unexpected draft."); - here->doormask = D_BROKEN; - } - newsym(mtmp->mx, mtmp->my); - return FALSE; - } else if (!IS_ROCK(here->typ) && !IS_TREE(here->typ)) /* no dig */ - return FALSE; + /* Eats away door if present & closed or locked */ + if (closed_door(mtmp->mx, mtmp->my)) { + if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) + add_damage(mtmp->mx, mtmp->my, 0L); + unblock_point(mtmp->mx, mtmp->my); /* vision */ + if (here->doormask & D_TRAPPED) { + here->doormask = D_NODOOR; + if (mb_trapped(mtmp)) { /* mtmp is killed */ + newsym(mtmp->mx, mtmp->my); + return TRUE; + } + } else { + if (!rn2(3) && flags.verbose) /* not too often.. */ + You_feel("an unexpected draft."); + here->doormask = D_BROKEN; + } + newsym(mtmp->mx, mtmp->my); + return FALSE; + } else if (!IS_ROCK(here->typ) && !IS_TREE(here->typ)) /* no dig */ + return FALSE; - /* Only rock, trees, and walls fall through to this point. */ - if ((here->wall_info & W_NONDIGGABLE) != 0) { - impossible("mdig_tunnel: %s at (%d,%d) is undiggable", - (IS_WALL(here->typ) ? "wall" : "stone"), - (int) mtmp->mx, (int) mtmp->my); - return FALSE; /* still alive */ - } + /* Only rock, trees, and walls fall through to this point. */ + if ((here->wall_info & W_NONDIGGABLE) != 0) { + impossible("mdig_tunnel: %s at (%d,%d) is undiggable", + (IS_WALL(here->typ) ? "wall" : "stone"), (int) mtmp->mx, + (int) mtmp->my); + return FALSE; /* still alive */ + } - if (IS_WALL(here->typ)) { - /* KMH -- Okay on arboreal levels (room walls are still stone) */ - if (flags.verbose && !rn2(5)) - You_hear("crashing rock."); - if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) - add_damage(mtmp->mx, mtmp->my, 0L); - if (level.flags.is_maze_lev) { - here->typ = ROOM; - } else if (level.flags.is_cavernous_lev && - !in_town(mtmp->mx, mtmp->my)) { - here->typ = CORR; - } else { - here->typ = DOOR; - here->doormask = D_NODOOR; - } - } else if (IS_TREE(here->typ)) { - here->typ = ROOM; - if (pile && pile < 5) - (void) rnd_treefruit_at(mtmp->mx, mtmp->my); - } else { - here->typ = CORR; - if (pile && pile < 5) - (void) mksobj_at((pile == 1) ? BOULDER : ROCK, - mtmp->mx, mtmp->my, TRUE, FALSE); - } - newsym(mtmp->mx, mtmp->my); - if (!sobj_at(BOULDER, mtmp->mx, mtmp->my)) - unblock_point(mtmp->mx, mtmp->my); /* vision */ + if (IS_WALL(here->typ)) { + /* KMH -- Okay on arboreal levels (room walls are still stone) */ + if (flags.verbose && !rn2(5)) + You_hear("crashing rock."); + if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) + add_damage(mtmp->mx, mtmp->my, 0L); + if (level.flags.is_maze_lev) { + here->typ = ROOM; + } else if (level.flags.is_cavernous_lev + && !in_town(mtmp->mx, mtmp->my)) { + here->typ = CORR; + } else { + here->typ = DOOR; + here->doormask = D_NODOOR; + } + } else if (IS_TREE(here->typ)) { + here->typ = ROOM; + if (pile && pile < 5) + (void) rnd_treefruit_at(mtmp->mx, mtmp->my); + } else { + here->typ = CORR; + if (pile && pile < 5) + (void) mksobj_at((pile == 1) ? BOULDER : ROCK, mtmp->mx, mtmp->my, + TRUE, FALSE); + } + newsym(mtmp->mx, mtmp->my); + if (!sobj_at(BOULDER, mtmp->mx, mtmp->my)) + unblock_point(mtmp->mx, mtmp->my); /* vision */ - return FALSE; + return FALSE; } /* digging via wand zap or spell cast */ void zap_dig() { - struct rm *room; - struct monst *mtmp; - struct obj *otmp; - struct trap *trap_with_u = (struct trap *)0; - int zx, zy, diridx = 8, digdepth, flow_x = -1, flow_y = -1; - boolean shopdoor, shopwall, maze_dig, pitdig = FALSE, pitflow = FALSE; + struct rm *room; + struct monst *mtmp; + struct obj *otmp; + struct trap *trap_with_u = (struct trap *) 0; + int zx, zy, diridx = 8, digdepth, flow_x = -1, flow_y = -1; + boolean shopdoor, shopwall, maze_dig, pitdig = FALSE, pitflow = FALSE; - /* - * Original effect (approximately): - * from CORR: dig until we pierce a wall - * from ROOM: pierce wall and dig until we reach - * an ACCESSIBLE place. - * Currently: dig for digdepth positions; - * also down on request of Lennart Augustsson. - * 3.5.0: from a PIT: dig one adjacent pit. - */ + /* + * Original effect (approximately): + * from CORR: dig until we pierce a wall + * from ROOM: pierce wall and dig until we reach + * an ACCESSIBLE place. + * Currently: dig for digdepth positions; + * also down on request of Lennart Augustsson. + * 3.5.0: from a PIT: dig one adjacent pit. + */ - if (u.uswallow) { - mtmp = u.ustuck; + if (u.uswallow) { + mtmp = u.ustuck; - if (!is_whirly(mtmp->data)) { - if (is_animal(mtmp->data)) - You("pierce %s %s wall!", - s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH)); - mtmp->mhp = 1; /* almost dead */ - expels(mtmp, mtmp->data, !is_animal(mtmp->data)); - } - return; - } /* swallowed */ + if (!is_whirly(mtmp->data)) { + if (is_animal(mtmp->data)) + You("pierce %s %s wall!", s_suffix(mon_nam(mtmp)), + mbodypart(mtmp, STOMACH)); + mtmp->mhp = 1; /* almost dead */ + expels(mtmp, mtmp->data, !is_animal(mtmp->data)); + } + return; + } /* swallowed */ - if (u.dz) { - if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !Underwater) { - if (u.dz < 0 || On_stairs(u.ux, u.uy)) { - int dmg; - if (On_stairs(u.ux, u.uy)) - pline_The("beam bounces off the %s and hits the %s.", - (u.ux == xdnladder || u.ux == xupladder) ? - "ladder" : "stairs", ceiling(u.ux, u.uy)); - You("loosen a rock from the %s.", ceiling(u.ux, u.uy)); - pline("It falls on your %s!", body_part(HEAD)); - dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); - losehp(Maybe_Half_Phys(dmg), - "falling rock", KILLED_BY_AN); - otmp = mksobj_at(ROCK, u.ux, u.uy, FALSE, FALSE); - if (otmp) { - (void)xname(otmp); /* set dknown, maybe bknown */ - stackobj(otmp); - } - newsym(u.ux, u.uy); - } else { - watch_dig((struct monst *)0, u.ux, u.uy, TRUE); - (void) dighole(FALSE, TRUE, (coord *)0); - } - } - return; - } /* up or down */ + if (u.dz) { + if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !Underwater) { + if (u.dz < 0 || On_stairs(u.ux, u.uy)) { + int dmg; + if (On_stairs(u.ux, u.uy)) + pline_The("beam bounces off the %s and hits the %s.", + (u.ux == xdnladder || u.ux == xupladder) + ? "ladder" + : "stairs", + ceiling(u.ux, u.uy)); + You("loosen a rock from the %s.", ceiling(u.ux, u.uy)); + pline("It falls on your %s!", body_part(HEAD)); + dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); + losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); + otmp = mksobj_at(ROCK, u.ux, u.uy, FALSE, FALSE); + if (otmp) { + (void) xname(otmp); /* set dknown, maybe bknown */ + stackobj(otmp); + } + newsym(u.ux, u.uy); + } else { + watch_dig((struct monst *) 0, u.ux, u.uy, TRUE); + (void) dighole(FALSE, TRUE, (coord *) 0); + } + } + return; + } /* up or down */ - /* normal case: digging across the level */ - shopdoor = shopwall = FALSE; - maze_dig = level.flags.is_maze_lev && !Is_earthlevel(&u.uz); - zx = u.ux + u.dx; - zy = u.uy + u.dy; - if(u.utrap && u.utraptype == TT_PIT && (trap_with_u = t_at(u.ux, u.uy))) { - pitdig = TRUE; - for (diridx = 0; diridx < 8; diridx++) { - if (xdir[diridx] == u.dx && ydir[diridx] == u.dy) - break; - /* diridx is valid if < 8 */ - } - } - digdepth = rn1(18, 8); - tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam)); - while (--digdepth >= 0) { - if (!isok(zx,zy)) break; - room = &levl[zx][zy]; - tmp_at(zx,zy); - delay_output(); /* wait a little bit */ + /* normal case: digging across the level */ + shopdoor = shopwall = FALSE; + maze_dig = level.flags.is_maze_lev && !Is_earthlevel(&u.uz); + zx = u.ux + u.dx; + zy = u.uy + u.dy; + if (u.utrap && u.utraptype == TT_PIT + && (trap_with_u = t_at(u.ux, u.uy))) { + pitdig = TRUE; + for (diridx = 0; diridx < 8; diridx++) { + if (xdir[diridx] == u.dx && ydir[diridx] == u.dy) + break; + /* diridx is valid if < 8 */ + } + } + digdepth = rn1(18, 8); + tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam)); + while (--digdepth >= 0) { + if (!isok(zx, zy)) + break; + room = &levl[zx][zy]; + tmp_at(zx, zy); + delay_output(); /* wait a little bit */ - if (pitdig) { /* we are already in a pit if this is true */ - coord cc; - struct trap *adjpit = t_at(zx,zy); - if ((diridx < 8) && - !conjoined_pits(adjpit, trap_with_u, FALSE)) { - digdepth = 0; /* limited to the adjacent location only */ - if (!(adjpit && (adjpit->ttyp == PIT || - adjpit->ttyp == SPIKED_PIT))) { - char buf[BUFSZ]; - cc.x = zx; cc.y = zy; - if (!adj_pit_checks(&cc, buf)) { - if (buf[0]) pline1(buf); - } else { - /* this can also result in a pool at zx,zy */ - dighole(TRUE, TRUE, &cc); - adjpit = t_at(zx,zy); - } - } - if (adjpit && (adjpit->ttyp == PIT || - adjpit->ttyp == SPIKED_PIT)) { - int adjidx = (diridx + 4) % 8; - trap_with_u->conjoined |= (1 << diridx); - adjpit->conjoined |= (1 << adjidx); - flow_x = zx; - flow_y = zy; - pitflow = TRUE; - } - if (is_pool(zx,zy) || is_lava(zx,zy)) { - flow_x = zx - u.dx; - flow_y = zy - u.dy; - pitflow = TRUE; - } - break; - } - } else if (closed_door(zx, zy) || room->typ == SDOOR) { - if (*in_rooms(zx,zy,SHOPBASE)) { - add_damage(zx, zy, 400L); - shopdoor = TRUE; - } - if (room->typ == SDOOR) - room->typ = DOOR; - else if (cansee(zx, zy)) - pline_The("door is razed!"); - watch_dig((struct monst *)0, zx, zy, TRUE); - room->doormask = D_NODOOR; - unblock_point(zx,zy); /* vision */ - digdepth -= 2; - if (maze_dig) break; - } else if (maze_dig) { - if (IS_WALL(room->typ)) { - if (!(room->wall_info & W_NONDIGGABLE)) { - if (*in_rooms(zx,zy,SHOPBASE)) { - add_damage(zx, zy, 200L); - shopwall = TRUE; - } - room->typ = ROOM; - unblock_point(zx,zy); /* vision */ - } else if (!Blind) - pline_The("wall glows then fades."); - break; - } else if (IS_TREE(room->typ)) { /* check trees before stone */ - if (!(room->wall_info & W_NONDIGGABLE)) { - room->typ = ROOM; - unblock_point(zx,zy); /* vision */ - } else if (!Blind) - pline_The("tree shudders but is unharmed."); - break; - } else if (room->typ == STONE || room->typ == SCORR) { - if (!(room->wall_info & W_NONDIGGABLE)) { - room->typ = CORR; - unblock_point(zx,zy); /* vision */ - } else if (!Blind) - pline_The("rock glows then fades."); - break; - } - } else if (IS_ROCK(room->typ)) { - if (!may_dig(zx,zy)) break; - if (IS_WALL(room->typ) || room->typ == SDOOR) { - if (*in_rooms(zx,zy,SHOPBASE)) { - add_damage(zx, zy, 200L); - shopwall = TRUE; - } - watch_dig((struct monst *)0, zx, zy, TRUE); - if (level.flags.is_cavernous_lev && !in_town(zx, zy)) { - room->typ = CORR; - } else { - room->typ = DOOR; - room->doormask = D_NODOOR; - } - digdepth -= 2; - } else if (IS_TREE(room->typ)) { - room->typ = ROOM; - digdepth -= 2; - } else { /* IS_ROCK but not IS_WALL or SDOOR */ - room->typ = CORR; - digdepth--; - } - unblock_point(zx,zy); /* vision */ - } - zx += u.dx; - zy += u.dy; - } /* while */ - tmp_at(DISP_END,0); /* closing call */ + if (pitdig) { /* we are already in a pit if this is true */ + coord cc; + struct trap *adjpit = t_at(zx, zy); + if ((diridx < 8) && !conjoined_pits(adjpit, trap_with_u, FALSE)) { + digdepth = 0; /* limited to the adjacent location only */ + if (!(adjpit && (adjpit->ttyp == PIT + || adjpit->ttyp == SPIKED_PIT))) { + char buf[BUFSZ]; + cc.x = zx; + cc.y = zy; + if (!adj_pit_checks(&cc, buf)) { + if (buf[0]) + pline1(buf); + } else { + /* this can also result in a pool at zx,zy */ + dighole(TRUE, TRUE, &cc); + adjpit = t_at(zx, zy); + } + } + if (adjpit + && (adjpit->ttyp == PIT || adjpit->ttyp == SPIKED_PIT)) { + int adjidx = (diridx + 4) % 8; + trap_with_u->conjoined |= (1 << diridx); + adjpit->conjoined |= (1 << adjidx); + flow_x = zx; + flow_y = zy; + pitflow = TRUE; + } + if (is_pool(zx, zy) || is_lava(zx, zy)) { + flow_x = zx - u.dx; + flow_y = zy - u.dy; + pitflow = TRUE; + } + break; + } + } else if (closed_door(zx, zy) || room->typ == SDOOR) { + if (*in_rooms(zx, zy, SHOPBASE)) { + add_damage(zx, zy, 400L); + shopdoor = TRUE; + } + if (room->typ == SDOOR) + room->typ = DOOR; + else if (cansee(zx, zy)) + pline_The("door is razed!"); + watch_dig((struct monst *) 0, zx, zy, TRUE); + room->doormask = D_NODOOR; + unblock_point(zx, zy); /* vision */ + digdepth -= 2; + if (maze_dig) + break; + } else if (maze_dig) { + if (IS_WALL(room->typ)) { + if (!(room->wall_info & W_NONDIGGABLE)) { + if (*in_rooms(zx, zy, SHOPBASE)) { + add_damage(zx, zy, 200L); + shopwall = TRUE; + } + room->typ = ROOM; + unblock_point(zx, zy); /* vision */ + } else if (!Blind) + pline_The("wall glows then fades."); + break; + } else if (IS_TREE(room->typ)) { /* check trees before stone */ + if (!(room->wall_info & W_NONDIGGABLE)) { + room->typ = ROOM; + unblock_point(zx, zy); /* vision */ + } else if (!Blind) + pline_The("tree shudders but is unharmed."); + break; + } else if (room->typ == STONE || room->typ == SCORR) { + if (!(room->wall_info & W_NONDIGGABLE)) { + room->typ = CORR; + unblock_point(zx, zy); /* vision */ + } else if (!Blind) + pline_The("rock glows then fades."); + break; + } + } else if (IS_ROCK(room->typ)) { + if (!may_dig(zx, zy)) + break; + if (IS_WALL(room->typ) || room->typ == SDOOR) { + if (*in_rooms(zx, zy, SHOPBASE)) { + add_damage(zx, zy, 200L); + shopwall = TRUE; + } + watch_dig((struct monst *) 0, zx, zy, TRUE); + if (level.flags.is_cavernous_lev && !in_town(zx, zy)) { + room->typ = CORR; + } else { + room->typ = DOOR; + room->doormask = D_NODOOR; + } + digdepth -= 2; + } else if (IS_TREE(room->typ)) { + room->typ = ROOM; + digdepth -= 2; + } else { /* IS_ROCK but not IS_WALL or SDOOR */ + room->typ = CORR; + digdepth--; + } + unblock_point(zx, zy); /* vision */ + } + zx += u.dx; + zy += u.dy; + } /* while */ + tmp_at(DISP_END, 0); /* closing call */ - if (pitflow && isok(flow_x, flow_y)) { - struct trap *ttmp = t_at(flow_x, flow_y); - if (ttmp && (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT)) { - schar filltyp = fillholetyp(ttmp->tx, ttmp->ty, TRUE); - if (filltyp != ROOM) - pit_flow(ttmp, filltyp); - } - } + if (pitflow && isok(flow_x, flow_y)) { + struct trap *ttmp = t_at(flow_x, flow_y); + if (ttmp && (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT)) { + schar filltyp = fillholetyp(ttmp->tx, ttmp->ty, TRUE); + if (filltyp != ROOM) + pit_flow(ttmp, filltyp); + } + } - if (shopdoor || shopwall) - pay_for_damage(shopdoor ? "destroy" : "dig into", FALSE); - return; + if (shopdoor || shopwall) + pay_for_damage(shopdoor ? "destroy" : "dig into", FALSE); + return; } /* @@ -1487,80 +1532,87 @@ adj_pit_checks(cc, msg) coord *cc; char *msg; { - int ltyp; - struct rm *room; - const char *foundation_msg = - "The foundation is too hard to dig through from this angle."; + int ltyp; + struct rm *room; + const char *foundation_msg = + "The foundation is too hard to dig through from this angle."; - if (!cc) return FALSE; - if (!isok(cc->x,cc->y)) return FALSE; - if (msg) *msg = '\0'; - room = &levl[cc->x][cc->y]; - ltyp = room->typ; + if (!cc) + return FALSE; + if (!isok(cc->x, cc->y)) + return FALSE; + if (msg) + *msg = '\0'; + room = &levl[cc->x][cc->y]; + ltyp = room->typ; - - if (is_pool(cc->x, cc->y) || is_lava(cc->x, cc->y)) { - /* this is handled by the caller after we return FALSE */ - return FALSE; - } else if (closed_door(cc->x, cc->y) || room->typ == SDOOR) { - /* We reject this here because dighole() isn't - prepared to deal with this case */ - Strcpy(msg, foundation_msg); - return FALSE; - } else if (IS_WALL(ltyp)) { - /* if (room->wall_info & W_NONDIGGABLE) */ - Strcpy(msg, foundation_msg); - return FALSE; - } else if (IS_TREE(ltyp)) { /* check trees before stone */ - /* if (room->wall_info & W_NONDIGGABLE) */ - Strcpy(msg, "The tree's roots glow then fade."); - return FALSE; - } else if (ltyp == STONE || ltyp == SCORR) { - if (room->wall_info & W_NONDIGGABLE) { - Strcpy(msg, "The rock glows then fades."); - return FALSE; - } - } else if (ltyp == IRONBARS) { - /* "set of iron bars" */ - Strcpy(msg, "The bars go much deeper than your pit."); + if (is_pool(cc->x, cc->y) || is_lava(cc->x, cc->y)) { + /* this is handled by the caller after we return FALSE */ + return FALSE; + } else if (closed_door(cc->x, cc->y) || room->typ == SDOOR) { + /* We reject this here because dighole() isn't + prepared to deal with this case */ + Strcpy(msg, foundation_msg); + return FALSE; + } else if (IS_WALL(ltyp)) { + /* if (room->wall_info & W_NONDIGGABLE) */ + Strcpy(msg, foundation_msg); + return FALSE; + } else if (IS_TREE(ltyp)) { /* check trees before stone */ + /* if (room->wall_info & W_NONDIGGABLE) */ + Strcpy(msg, "The tree's roots glow then fade."); + return FALSE; + } else if (ltyp == STONE || ltyp == SCORR) { + if (room->wall_info & W_NONDIGGABLE) { + Strcpy(msg, "The rock glows then fades."); + return FALSE; + } + } else if (ltyp == IRONBARS) { + /* "set of iron bars" */ + Strcpy(msg, "The bars go much deeper than your pit."); #if 0 } else if (is_lava(cc->x,cc->y)) { } else if (is_ice(cc->x,cc->y)) { } else if (is_pool(cc->x,cc->y)) { } else if (IS_GRAVE(ltyp)) { #endif - } else if (IS_SINK(ltyp)) { - Strcpy(msg, "A tangled mass of plumbing remains below the sink."); - return FALSE; - } else if ((cc->x == xupladder && cc->y == yupladder) || /* "ladder up" */ - (cc->x == xdnladder && cc->y == ydnladder)) { /* "ladder down" */ - Strcpy(msg, "The ladder is unaffected."); - return FALSE; - } else { - const char *supporting = (const char *)0; - if (IS_FOUNTAIN(ltyp)) supporting = "fountain"; - else if (IS_THRONE(ltyp)) supporting = "throne"; - else if (IS_ALTAR(ltyp)) supporting = "altar"; - else if ((cc->x == xupstair && cc->y == yupstair) || - (cc->x == sstairs.sx && cc->y == sstairs.sy && sstairs.up)) - /* "staircase up" */ - supporting = "stairs"; - else if ((cc->x == xdnstair && cc->y == ydnstair) || - (cc->x == sstairs.sx && cc->y == sstairs.sy && !sstairs.up)) - /* "staircase down" */ - supporting = "stairs"; - else if ((ltyp == DRAWBRIDGE_DOWN) || /* "lowered drawbridge" */ - (ltyp == DBWALL)) /* "raised drawbridge" */ - supporting = "drawbridge"; - if (supporting) { - Sprintf(msg, - "The %s%ssupporting structures remain intact.", - supporting ? s_suffix(supporting) : "", - supporting ? " " : ""); - return FALSE; - } - } - return TRUE; + } else if (IS_SINK(ltyp)) { + Strcpy(msg, "A tangled mass of plumbing remains below the sink."); + return FALSE; + } else if ((cc->x == xupladder && cc->y == yupladder) || /* "ladder up" */ + (cc->x == xdnladder + && cc->y == ydnladder)) { /* "ladder down" */ + Strcpy(msg, "The ladder is unaffected."); + return FALSE; + } else { + const char *supporting = (const char *) 0; + if (IS_FOUNTAIN(ltyp)) + supporting = "fountain"; + else if (IS_THRONE(ltyp)) + supporting = "throne"; + else if (IS_ALTAR(ltyp)) + supporting = "altar"; + else if ((cc->x == xupstair && cc->y == yupstair) + || (cc->x == sstairs.sx && cc->y == sstairs.sy + && sstairs.up)) + /* "staircase up" */ + supporting = "stairs"; + else if ((cc->x == xdnstair && cc->y == ydnstair) + || (cc->x == sstairs.sx && cc->y == sstairs.sy + && !sstairs.up)) + /* "staircase down" */ + supporting = "stairs"; + else if ((ltyp == DRAWBRIDGE_DOWN) || /* "lowered drawbridge" */ + (ltyp == DBWALL)) /* "raised drawbridge" */ + supporting = "drawbridge"; + if (supporting) { + Sprintf(msg, "The %s%ssupporting structures remain intact.", + supporting ? s_suffix(supporting) : "", + supporting ? " " : ""); + return FALSE; + } + } + return TRUE; } /* @@ -1571,23 +1623,23 @@ pit_flow(trap, filltyp) struct trap *trap; schar filltyp; { - int idx; - if (trap && (filltyp != ROOM) && - (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { - struct trap t; - t = *trap; - levl[trap->tx][trap->ty].typ = filltyp; - liquid_flow(trap->tx, trap->ty, filltyp, trap, - (trap->tx == u.ux && trap->ty == u.uy) ? - "Suddenly %s flows in from the adjacent pit!": - (char *)0); - for(idx = 0; idx < 8; ++idx) { - if (t.conjoined & (1 << idx)) { - int x, y; - struct trap *t2; - x = t.tx + xdir[idx]; - y = t.ty + ydir[idx]; - t2 = t_at(x,y); + int idx; + if (trap && (filltyp != ROOM) + && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { + struct trap t; + t = *trap; + levl[trap->tx][trap->ty].typ = filltyp; + liquid_flow(trap->tx, trap->ty, filltyp, trap, + (trap->tx == u.ux && trap->ty == u.uy) + ? "Suddenly %s flows in from the adjacent pit!" + : (char *) 0); + for (idx = 0; idx < 8; ++idx) { + if (t.conjoined & (1 << idx)) { + int x, y; + struct trap *t2; + x = t.tx + xdir[idx]; + y = t.ty + ydir[idx]; + t2 = t_at(x, y); #if 0 /* cannot do this back-check; liquid_flow() * called deltrap() which cleaned up the @@ -1596,148 +1648,154 @@ schar filltyp; if (t2 && (t2->conjoined & (1 << ((idx + 4) % 8)))) #endif - /* recursion */ - pit_flow(t2, filltyp); - } - } - } + /* recursion */ + pit_flow(t2, filltyp); + } + } + } } struct obj * buried_ball(cc) coord *cc; { - xchar check_x, check_y; - struct obj *otmp, *otmp2; - if (u.utraptype == TT_BURIEDBALL) - for (otmp = level.buriedobjlist; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (otmp->otyp != HEAVY_IRON_BALL) continue; - /* try the exact location first */ - if (otmp->ox == cc->x && otmp->oy == cc->y) - return otmp; - /* Now try the vicinity */ - /* - * (x-2,y-2) (x+2,y-2) - * (x,y) - * (x-2,y+2) (x+2,y+2) - */ - for (check_x = cc->x-2; check_x <= cc->x+2; ++check_x) - for (check_y = cc->y-2; check_y <= cc->y+2; ++check_y) { - if (check_x == cc->x && check_y == cc->y) continue; - if (isok(check_x, check_y) && - (otmp->ox == check_x && otmp->oy == check_y)) { - cc->x = check_x; - cc->y = check_y; - return otmp; - } - } - } - return (struct obj *)0; + xchar check_x, check_y; + struct obj *otmp, *otmp2; + if (u.utraptype == TT_BURIEDBALL) + for (otmp = level.buriedobjlist; otmp; otmp = otmp2) { + otmp2 = otmp->nobj; + if (otmp->otyp != HEAVY_IRON_BALL) + continue; + /* try the exact location first */ + if (otmp->ox == cc->x && otmp->oy == cc->y) + return otmp; + /* Now try the vicinity */ + /* + * (x-2,y-2) (x+2,y-2) + * (x,y) + * (x-2,y+2) (x+2,y+2) + */ + for (check_x = cc->x - 2; check_x <= cc->x + 2; ++check_x) + for (check_y = cc->y - 2; check_y <= cc->y + 2; ++check_y) { + if (check_x == cc->x && check_y == cc->y) + continue; + if (isok(check_x, check_y) + && (otmp->ox == check_x && otmp->oy == check_y)) { + cc->x = check_x; + cc->y = check_y; + return otmp; + } + } + } + return (struct obj *) 0; } void buried_ball_to_punishment() { - coord cc; - struct obj *ball; - cc.x = u.ux; cc.y = u.uy; - ball = buried_ball(&cc); - if (ball) { - obj_extract_self(ball); + coord cc; + struct obj *ball; + cc.x = u.ux; + cc.y = u.uy; + ball = buried_ball(&cc); + if (ball) { + obj_extract_self(ball); #if 0 /* rusting buried metallic objects is not implemented yet */ if (ball->timed) (void) stop_timer(RUST_METAL, obj_to_any(ball)); #endif - punish(ball); /* use ball as flag for unearthed buried ball */ - u.utrap = 0; - u.utraptype = 0; - del_engr_at(cc.x, cc.y); - newsym(cc.x, cc.y); - } + punish(ball); /* use ball as flag for unearthed buried ball */ + u.utrap = 0; + u.utraptype = 0; + del_engr_at(cc.x, cc.y); + newsym(cc.x, cc.y); + } } void buried_ball_to_freedom() { - coord cc; - struct obj *ball; - cc.x = u.ux; cc.y = u.uy; - ball = buried_ball(&cc); - if (ball) { - obj_extract_self(ball); + coord cc; + struct obj *ball; + cc.x = u.ux; + cc.y = u.uy; + ball = buried_ball(&cc); + if (ball) { + obj_extract_self(ball); #if 0 /* rusting buried metallic objects is not implemented yet */ if (ball->timed) (void) stop_timer(RUST_METAL, obj_to_any(ball)); #endif - place_object(ball, cc.x, cc.y); - stackobj(ball); - u.utrap = 0; - u.utraptype = 0; - del_engr_at(cc.x, cc.y); - newsym(cc.x, cc.y); - } + place_object(ball, cc.x, cc.y); + stackobj(ball); + u.utrap = 0; + u.utraptype = 0; + del_engr_at(cc.x, cc.y); + newsym(cc.x, cc.y); + } } /* move objects from fobj/nexthere lists to buriedobjlist, keeping position */ /* information */ struct obj * bury_an_obj(otmp, dealloced) - struct obj *otmp; - boolean *dealloced; +struct obj *otmp; +boolean *dealloced; { - struct obj *otmp2; - boolean under_ice; + struct obj *otmp2; + boolean under_ice; - debugpline1("bury_an_obj: %s", xname(otmp)); - if (dealloced) *dealloced = FALSE; - if (otmp == uball) { - unpunish(); - u.utrap = rn1(50,20); - u.utraptype = TT_BURIEDBALL; - pline_The("iron ball gets buried!"); - } - /* after unpunish(), or might get deallocated chain */ - otmp2 = otmp->nexthere; - /* - * obj_resists(,0,0) prevents Rider corpses from being buried. - * It also prevents The Amulet and invocation tools from being - * buried. Since they can't be confined to bags and statues, - * it makes sense that they can't be buried either, even though - * the real reason there (direct accessibility when carried) is - * completely different. - */ - if (otmp == uchain || obj_resists(otmp, 0, 0)) - return(otmp2); + debugpline1("bury_an_obj: %s", xname(otmp)); + if (dealloced) + *dealloced = FALSE; + if (otmp == uball) { + unpunish(); + u.utrap = rn1(50, 20); + u.utraptype = TT_BURIEDBALL; + pline_The("iron ball gets buried!"); + } + /* after unpunish(), or might get deallocated chain */ + otmp2 = otmp->nexthere; + /* + * obj_resists(,0,0) prevents Rider corpses from being buried. + * It also prevents The Amulet and invocation tools from being + * buried. Since they can't be confined to bags and statues, + * it makes sense that they can't be buried either, even though + * the real reason there (direct accessibility when carried) is + * completely different. + */ + if (otmp == uchain || obj_resists(otmp, 0, 0)) + return (otmp2); - if (otmp->otyp == LEASH && otmp->leashmon != 0) - o_unleash(otmp); + if (otmp->otyp == LEASH && otmp->leashmon != 0) + o_unleash(otmp); - if (otmp->lamplit && otmp->otyp != POT_OIL) - end_burn(otmp, TRUE); + if (otmp->lamplit && otmp->otyp != POT_OIL) + end_burn(otmp, TRUE); - obj_extract_self(otmp); + obj_extract_self(otmp); - under_ice = is_ice(otmp->ox, otmp->oy); - if (otmp->otyp == ROCK && !under_ice) { - /* merges into burying material */ - if (dealloced) *dealloced = TRUE; - obfree(otmp, (struct obj *)0); - return(otmp2); - } - /* - * Start a rot on organic material. Not corpses -- they - * are already handled. - */ - if (otmp->otyp == CORPSE) { - ; /* should cancel timer if under_ice */ - } else if ((under_ice ? otmp->oclass == POTION_CLASS : is_organic(otmp)) - && !obj_resists(otmp, 5, 95)) { - (void) start_timer((under_ice ? 0L : 250L) + (long)rnd(250), - TIMER_OBJECT, ROT_ORGANIC, obj_to_any(otmp)); - } + under_ice = is_ice(otmp->ox, otmp->oy); + if (otmp->otyp == ROCK && !under_ice) { + /* merges into burying material */ + if (dealloced) + *dealloced = TRUE; + obfree(otmp, (struct obj *) 0); + return (otmp2); + } + /* + * Start a rot on organic material. Not corpses -- they + * are already handled. + */ + if (otmp->otyp == CORPSE) { + ; /* should cancel timer if under_ice */ + } else if ((under_ice ? otmp->oclass == POTION_CLASS : is_organic(otmp)) + && !obj_resists(otmp, 5, 95)) { + (void) start_timer((under_ice ? 0L : 250L) + (long) rnd(250), + TIMER_OBJECT, ROT_ORGANIC, obj_to_any(otmp)); + } #if 0 /* rusting of buried metal not yet implemented */ else if (is_rustprone(otmp)) { @@ -1745,24 +1803,24 @@ bury_an_obj(otmp, dealloced) TIMER_OBJECT, RUST_METAL, obj_to_any(otmp)); } #endif - add_to_buried(otmp); - return(otmp2); + add_to_buried(otmp); + return (otmp2); } void bury_objs(x, y) int x, y; { - struct obj *otmp, *otmp2; + struct obj *otmp, *otmp2; - if(level.objects[x][y] != (struct obj *)0) - debugpline2("bury_objs: at <%d,%d>", x, y); - for (otmp = level.objects[x][y]; otmp; otmp = otmp2) - otmp2 = bury_an_obj(otmp, NULL); + if (level.objects[x][y] != (struct obj *) 0) + debugpline2("bury_objs: at <%d,%d>", x, y); + for (otmp = level.objects[x][y]; otmp; otmp = otmp2) + otmp2 = bury_an_obj(otmp, NULL); - /* don't expect any engravings here, but just in case */ - del_engr_at(x, y); - newsym(x, y); + /* don't expect any engravings here, but just in case */ + del_engr_at(x, y); + newsym(x, y); } /* move objects from buriedobjlist to fobj/nexthere lists */ @@ -1770,28 +1828,29 @@ void unearth_objs(x, y) int x, y; { - struct obj *otmp, *otmp2, *bball; - coord cc; + struct obj *otmp, *otmp2, *bball; + coord cc; - debugpline2("unearth_objs: at <%d,%d>", x, y); - cc.x = x; cc.y = y; - bball = buried_ball(&cc); - for (otmp = level.buriedobjlist; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (otmp->ox == x && otmp->oy == y) { - if (bball && otmp == bball && u.utraptype == TT_BURIEDBALL) - buried_ball_to_punishment(); - else { - obj_extract_self(otmp); - if (otmp->timed) - (void) stop_timer(ROT_ORGANIC, obj_to_any(otmp)); - place_object(otmp, x, y); - stackobj(otmp); - } - } - } - del_engr_at(x, y); - newsym(x, y); + debugpline2("unearth_objs: at <%d,%d>", x, y); + cc.x = x; + cc.y = y; + bball = buried_ball(&cc); + for (otmp = level.buriedobjlist; otmp; otmp = otmp2) { + otmp2 = otmp->nobj; + if (otmp->ox == x && otmp->oy == y) { + if (bball && otmp == bball && u.utraptype == TT_BURIEDBALL) + buried_ball_to_punishment(); + else { + obj_extract_self(otmp); + if (otmp->timed) + (void) stop_timer(ROT_ORGANIC, obj_to_any(otmp)); + place_object(otmp, x, y); + stackobj(otmp); + } + } + } + del_engr_at(x, y); + newsym(x, y); } /* @@ -1809,19 +1868,19 @@ rot_organic(arg, timeout) anything *arg; long timeout UNUSED; { - struct obj *obj = arg->a_obj; + struct obj *obj = arg->a_obj; - while (Has_contents(obj)) { - /* We don't need to place contained object on the floor - first, but we do need to update its map coordinates. */ - obj->cobj->ox = obj->ox, obj->cobj->oy = obj->oy; - /* Everything which can be held in a container can also be - buried, so bury_an_obj's use of obj_extract_self insures - that Has_contents(obj) will eventually become false. */ - (void)bury_an_obj(obj->cobj, NULL); - } - obj_extract_self(obj); - obfree(obj, (struct obj *) 0); + while (Has_contents(obj)) { + /* We don't need to place contained object on the floor + first, but we do need to update its map coordinates. */ + obj->cobj->ox = obj->ox, obj->cobj->oy = obj->oy; + /* Everything which can be held in a container can also be + buried, so bury_an_obj's use of obj_extract_self insures + that Has_contents(obj) will eventually become false. */ + (void) bury_an_obj(obj->cobj, NULL); + } + obj_extract_self(obj); + obfree(obj, (struct obj *) 0); } /* @@ -1830,55 +1889,55 @@ long timeout UNUSED; void rot_corpse(arg, timeout) anything *arg; -long timeout; /* unused */ +long timeout; /* unused */ { - xchar x = 0, y = 0; - struct obj *obj = arg->a_obj; - boolean on_floor = obj->where == OBJ_FLOOR, - in_invent = obj->where == OBJ_INVENT; + xchar x = 0, y = 0; + struct obj *obj = arg->a_obj; + boolean on_floor = obj->where == OBJ_FLOOR, + in_invent = obj->where == OBJ_INVENT; - if (on_floor) { - x = obj->ox; - y = obj->oy; - } else if (in_invent) { - if (flags.verbose) { - char *cname = corpse_xname(obj, (const char *)0, CXN_NO_PFX); + if (on_floor) { + x = obj->ox; + y = obj->oy; + } else if (in_invent) { + if (flags.verbose) { + char *cname = corpse_xname(obj, (const char *) 0, CXN_NO_PFX); - Your("%s%s %s away%c", - obj == uwep ? "wielded " : "", cname, - otense(obj, "rot"), obj == uwep ? '!' : '.'); - } - if (obj == uwep) { - uwepgone(); /* now bare handed */ - stop_occupation(); - } else if (obj == uswapwep) { - uswapwepgone(); - stop_occupation(); - } else if (obj == uquiver) { - uqwepgone(); - stop_occupation(); - } - } else if (obj->where == OBJ_MINVENT && obj->owornmask) { - if (obj == MON_WEP(obj->ocarry)) { - setmnotwielded(obj->ocarry,obj); - MON_NOWEP(obj->ocarry); - } - } else if (obj->where == OBJ_MIGRATING) { - /* clear destination flag so that obfree()'s check for - freeing a worn object doesn't get a false hit */ - obj->owornmask = 0L; - } - rot_organic(arg, timeout); - if (on_floor) { - struct monst *mtmp = m_at(x, y); + Your("%s%s %s away%c", obj == uwep ? "wielded " : "", cname, + otense(obj, "rot"), obj == uwep ? '!' : '.'); + } + if (obj == uwep) { + uwepgone(); /* now bare handed */ + stop_occupation(); + } else if (obj == uswapwep) { + uswapwepgone(); + stop_occupation(); + } else if (obj == uquiver) { + uqwepgone(); + stop_occupation(); + } + } else if (obj->where == OBJ_MINVENT && obj->owornmask) { + if (obj == MON_WEP(obj->ocarry)) { + setmnotwielded(obj->ocarry, obj); + MON_NOWEP(obj->ocarry); + } + } else if (obj->where == OBJ_MIGRATING) { + /* clear destination flag so that obfree()'s check for + freeing a worn object doesn't get a false hit */ + obj->owornmask = 0L; + } + rot_organic(arg, timeout); + if (on_floor) { + struct monst *mtmp = m_at(x, y); - /* a hiding monster may be exposed */ - if (mtmp && !OBJ_AT(x, y) && - mtmp->mundetected && hides_under(mtmp->data)) { - mtmp->mundetected = 0; - } - newsym(x, y); - } else if (in_invent) update_inventory(); + /* a hiding monster may be exposed */ + if (mtmp && !OBJ_AT(x, y) && mtmp->mundetected + && hides_under(mtmp->data)) { + mtmp->mundetected = 0; + } + newsym(x, y); + } else if (in_invent) + update_inventory(); } #if 0 @@ -1975,15 +2034,16 @@ struct obj *otmp; #endif #ifdef DEBUG -int -wiz_debug_cmd_bury() /* in this case, bury everything at your loc and around */ +int wiz_debug_cmd_bury() /* in this case, bury everything at your loc and + around */ { - int x, y; + int x, y; - for (x = u.ux - 1; x <= u.ux + 1; x++) - for (y = u.uy - 1; y <= u.uy + 1; y++) - if (isok(x,y)) bury_objs(x,y); - return 0; + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) + if (isok(x, y)) + bury_objs(x, y); + return 0; } #endif /* DEBUG */ diff --git a/src/display.c b/src/display.c index 5fd946ed5..0fe85a409 100644 --- a/src/display.c +++ b/src/display.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 display.c $NHDT-Date: 1430365890 2015/04/30 03:51:30 $ $NHDT-Branch: master $:$NHDT-Revision: 1.49 $ */ +/* NetHack 3.6 display.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ /* NetHack 3.6 display.c $Date: 2011/12/05 03:17:36 $ $Revision: 1.34 $ */ /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */ /* and Dave Cohrs, 1990. */ @@ -107,7 +107,8 @@ * seenv - A vector of bits representing the directions from which the * hero has seen this position. The vector's primary use is * determining how walls are seen. E.g. a wall sometimes looks - * like stone on one side, but is seen as a wall from the other. + * like stone on one side, but is seen as a wall from the + *other. * Other uses are for unmapping detected objects and felt * locations, where we need to know if the hero has ever * seen the location. @@ -118,26 +119,27 @@ */ #include "hack.h" -STATIC_DCL void FDECL(display_monster,(XCHAR_P,XCHAR_P,struct monst *,int,XCHAR_P)); +STATIC_DCL void FDECL(display_monster, + (XCHAR_P, XCHAR_P, struct monst *, int, XCHAR_P)); STATIC_DCL int FDECL(swallow_to_glyph, (int, int)); -STATIC_DCL void FDECL(display_warning,(struct monst *)); +STATIC_DCL void FDECL(display_warning, (struct monst *)); STATIC_DCL int FDECL(check_pos, (int, int, int)); -/*#define WA_VERBOSE*/ /* give (x,y) locations for all "bad" spots */ +/*#define WA_VERBOSE*/ /* give (x,y) locations for all "bad" spots */ #ifdef WA_VERBOSE STATIC_DCL boolean FDECL(more_than_one, (int, int, int, int, int)); #endif -STATIC_DCL int FDECL(set_twall, (int,int, int,int, int,int, int,int)); +STATIC_DCL int FDECL(set_twall, (int, int, int, int, int, int, int, int)); STATIC_DCL int FDECL(set_wall, (int, int, int)); -STATIC_DCL int FDECL(set_corn, (int,int, int,int, int,int, int,int)); +STATIC_DCL int FDECL(set_corn, (int, int, int, int, int, int, int, int)); STATIC_DCL int FDECL(set_crosswall, (int, int)); STATIC_DCL void FDECL(set_seenv, (struct rm *, int, int, int, int)); STATIC_DCL void FDECL(t_warn, (struct rm *)); STATIC_DCL int FDECL(wall_angle, (struct rm *)); -#define remember_topology(x,y) (lastseentyp[x][y] = levl[x][y].typ) +#define remember_topology(x, y) (lastseentyp[x][y] = levl[x][y].typ) /* * magic_map_background() @@ -147,28 +149,31 @@ STATIC_DCL int FDECL(wall_angle, (struct rm *)); */ void magic_map_background(x, y, show) - xchar x,y; - int show; +xchar x, y; +int show; { - int glyph = back_to_glyph(x,y); /* assumes hero can see x,y */ + int glyph = back_to_glyph(x, y); /* assumes hero can see x,y */ struct rm *lev = &levl[x][y]; /* * Correct for out of sight lit corridors and rooms that the hero * doesn't remember as lit. */ - if (!cansee(x,y) && !lev->waslit) { - /* Floor spaces are dark if unlit. Corridors are dark if unlit. */ - if (lev->typ == ROOM && glyph == cmap_to_glyph(S_room)) - glyph = cmap_to_glyph((flags.dark_room && iflags.use_color) ? (DARKROOMSYM) : S_stone); - else if (lev->typ == CORR && glyph == cmap_to_glyph(S_litcorr)) - glyph = cmap_to_glyph(S_corr); + if (!cansee(x, y) && !lev->waslit) { + /* Floor spaces are dark if unlit. Corridors are dark if unlit. */ + if (lev->typ == ROOM && glyph == cmap_to_glyph(S_room)) + glyph = cmap_to_glyph((flags.dark_room && iflags.use_color) + ? (DARKROOMSYM) + : S_stone); + else if (lev->typ == CORR && glyph == cmap_to_glyph(S_litcorr)) + glyph = cmap_to_glyph(S_corr); } if (level.flags.hero_memory) - lev->glyph = glyph; - if (show) show_glyph(x,y, glyph); + lev->glyph = glyph; + if (show) + show_glyph(x, y, glyph); - remember_topology(x,y); + remember_topology(x, y); } /* @@ -194,14 +199,15 @@ magic_map_background(x, y, show) */ void map_background(x, y, show) - register xchar x,y; - register int show; +register xchar x, y; +register int show; { - register int glyph = back_to_glyph(x,y); + register int glyph = back_to_glyph(x, y); if (level.flags.hero_memory) - levl[x][y].glyph = glyph; - if (show) show_glyph(x,y, glyph); + levl[x][y].glyph = glyph; + if (show) + show_glyph(x, y, glyph); } /* @@ -212,15 +218,16 @@ map_background(x, y, show) */ void map_trap(trap, show) - register struct trap *trap; - register int show; +register struct trap *trap; +register int show; { register int x = trap->tx, y = trap->ty; register int glyph = trap_to_glyph(trap); if (level.flags.hero_memory) - levl[x][y].glyph = glyph; - if (show) show_glyph(x, y, glyph); + levl[x][y].glyph = glyph; + if (show) + show_glyph(x, y, glyph); } /* @@ -231,25 +238,24 @@ map_trap(trap, show) */ void map_object(obj, show) - register struct obj *obj; - register int show; +register struct obj *obj; +register int show; { register int x = obj->ox, y = obj->oy; register int glyph = obj_to_glyph(obj); if (level.flags.hero_memory) { + /* MRKR: While hallucinating, statues are seen as random monsters */ + /* but remembered as random objects. */ - /* MRKR: While hallucinating, statues are seen as random monsters */ - /* but remembered as random objects. */ - - if (Hallucination && obj->otyp == STATUE) { - levl[x][y].glyph = random_obj_to_glyph(); - } - else { - levl[x][y].glyph = glyph; - } + if (Hallucination && obj->otyp == STATUE) { + levl[x][y].glyph = random_obj_to_glyph(); + } else { + levl[x][y].glyph = glyph; + } } - if (show) show_glyph(x, y, glyph); + if (show) + show_glyph(x, y, glyph); } /* @@ -266,9 +272,9 @@ map_invisible(x, y) register xchar x, y; { if (x != u.ux || y != u.uy) { /* don't display I at hero's location */ - if (level.flags.hero_memory) - levl[x][y].glyph = GLYPH_INVISIBLE; - show_glyph(x, y, GLYPH_INVISIBLE); + if (level.flags.hero_memory) + levl[x][y].glyph = GLYPH_INVISIBLE; + show_glyph(x, y, GLYPH_INVISIBLE); } } @@ -283,28 +289,28 @@ register xchar x, y; */ void unmap_object(x, y) - register int x, y; +register int x, y; { register struct trap *trap; - if (!level.flags.hero_memory) return; + if (!level.flags.hero_memory) + return; - if ((trap = t_at(x,y)) != 0 && trap->tseen && !covers_traps(x,y)) - map_trap(trap, 0); + if ((trap = t_at(x, y)) != 0 && trap->tseen && !covers_traps(x, y)) + map_trap(trap, 0); else if (levl[x][y].seenv) { - struct rm *lev = &levl[x][y]; + struct rm *lev = &levl[x][y]; - map_background(x, y, 0); + map_background(x, y, 0); - /* turn remembered dark room squares dark */ - if (!lev->waslit && lev->glyph == cmap_to_glyph(S_room) && - lev->typ == ROOM) - lev->glyph = cmap_to_glyph(S_stone); + /* turn remembered dark room squares dark */ + if (!lev->waslit && lev->glyph == cmap_to_glyph(S_room) + && lev->typ == ROOM) + lev->glyph = cmap_to_glyph(S_stone); } else - levl[x][y].glyph = cmap_to_glyph(S_stone); /* default val */ + levl[x][y].glyph = cmap_to_glyph(S_stone); /* default val */ } - /* * map_location() * @@ -313,31 +319,31 @@ unmap_object(x, y) * * Internal to display.c, this is a #define for speed. */ -#define _map_location(x,y,show) \ -{ \ - register struct obj *obj; \ - register struct trap *trap; \ - \ - if ((obj = vobj_at(x,y)) && !covers_objects(x,y)) \ - map_object(obj,show); \ - else if ((trap = t_at(x,y)) && trap->tseen && !covers_traps(x,y)) \ - map_trap(trap,show); \ - else \ - map_background(x,y,show); \ - \ - remember_topology(x,y); \ -} +#define _map_location(x, y, show) \ + { \ + register struct obj *obj; \ + register struct trap *trap; \ + \ + if ((obj = vobj_at(x, y)) && !covers_objects(x, y)) \ + map_object(obj, show); \ + else if ((trap = t_at(x, y)) && trap->tseen && !covers_traps(x, y)) \ + map_trap(trap, show); \ + else \ + map_background(x, y, show); \ + \ + remember_topology(x, y); \ + } void -map_location(x,y,show) - int x, y, show; +map_location(x, y, show) +int x, y, show; { - _map_location(x,y,show); + _map_location(x, y, show); } -#define DETECTED 2 +#define DETECTED 2 #define PHYSICALLY_SEEN 1 -#define is_worm_tail(mon) ((mon) && ((x != (mon)->mx) || (y != (mon)->my))) +#define is_worm_tail(mon) ((mon) && ((x != (mon)->mx) || (y != (mon)->my))) /* * display_monster() @@ -352,15 +358,15 @@ map_location(x,y,show) */ STATIC_OVL void display_monster(x, y, mon, sightflags, worm_tail) - register xchar x, y; /* display position */ - register struct monst *mon; /* monster to display */ - int sightflags; /* 1 if the monster is physically seen */ - /* 2 if detected using Detect_monsters */ - register xchar worm_tail; /* mon is actually a worm tail */ +register xchar x, y; /* display position */ +register struct monst *mon; /* monster to display */ +int sightflags; /* 1 if the monster is physically seen */ +/* 2 if detected using Detect_monsters */ +register xchar worm_tail; /* mon is actually a worm tail */ { register boolean mon_mimic = (mon->m_ap_type != M_AP_NOTHING); - register int sensed = mon_mimic && - (Protection_from_shape_changers || sensemon(mon)); + register int sensed = + mon_mimic && (Protection_from_shape_changers || sensemon(mon)); /* * We must do the mimic check first. If the mimic is mimicing something, * and the location is in sight, we have to change the hero's memory @@ -369,79 +375,80 @@ display_monster(x, y, mon, sightflags, worm_tail) */ if (mon_mimic && (sightflags == PHYSICALLY_SEEN)) { - switch (mon->m_ap_type) { - default: - impossible("display_monster: bad m_ap_type value [ = %d ]", - (int) mon->m_ap_type); - case M_AP_NOTHING: - show_glyph(x, y, mon_to_glyph(mon)); - break; + switch (mon->m_ap_type) { + default: + impossible("display_monster: bad m_ap_type value [ = %d ]", + (int) mon->m_ap_type); + case M_AP_NOTHING: + show_glyph(x, y, mon_to_glyph(mon)); + break; - case M_AP_FURNITURE: { - /* - * This is a poor man's version of map_background(). I can't - * use map_background() because we are overriding what is in - * the 'typ' field. Maybe have map_background()'s parameters - * be (x,y,glyph) instead of just (x,y). - * - * mappearance is currently set to an S_ index value in - * makemon.c. - */ - int sym = mon->mappearance, glyph = cmap_to_glyph(sym); + case M_AP_FURNITURE: { + /* + * This is a poor man's version of map_background(). I can't + * use map_background() because we are overriding what is in + * the 'typ' field. Maybe have map_background()'s parameters + * be (x,y,glyph) instead of just (x,y). + * + * mappearance is currently set to an S_ index value in + * makemon.c. + */ + int sym = mon->mappearance, glyph = cmap_to_glyph(sym); - levl[x][y].glyph = glyph; - if (!sensed) { - show_glyph(x,y, glyph); - /* override real topology with mimic's fake one */ - lastseentyp[x][y] = cmap_to_type(sym); - } - break; - } + levl[x][y].glyph = glyph; + if (!sensed) { + show_glyph(x, y, glyph); + /* override real topology with mimic's fake one */ + lastseentyp[x][y] = cmap_to_type(sym); + } + break; + } - case M_AP_OBJECT: { - struct obj obj; /* Make a fake object to send */ - /* to map_object(). */ - obj = zeroobj; - obj.ox = x; - obj.oy = y; - obj.otyp = mon->mappearance; - /* might be mimicing a corpse or statue */ - obj.corpsenm = has_mcorpsenm(mon) ? MCORPSENM(mon) : PM_TENGU; - map_object(&obj,!sensed); - break; - } + case M_AP_OBJECT: { + struct obj obj; /* Make a fake object to send */ + /* to map_object(). */ + obj = zeroobj; + obj.ox = x; + obj.oy = y; + obj.otyp = mon->mappearance; + /* might be mimicing a corpse or statue */ + obj.corpsenm = has_mcorpsenm(mon) ? MCORPSENM(mon) : PM_TENGU; + map_object(&obj, !sensed); + break; + } - case M_AP_MONSTER: - show_glyph(x,y, monnum_to_glyph(what_mon((int)mon->mappearance))); - break; - } - + case M_AP_MONSTER: + show_glyph(x, y, + monnum_to_glyph(what_mon((int) mon->mappearance))); + break; + } } - /* If the mimic is unsucessfully mimicing something, display the monster */ + /* If the mimic is unsucessfully mimicing something, display the monster + */ if (!mon_mimic || sensed) { - int num; + int num; - /* [ALI] Only use detected glyphs when monster wouldn't be - * visible by any other means. - */ - if (sightflags == DETECTED) { - if (worm_tail) - num = detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); - else - num = detected_mon_to_glyph(mon); - } else if (mon->mtame && !Hallucination) { - if (worm_tail) - num = petnum_to_glyph(PM_LONG_WORM_TAIL); - else - num = pet_to_glyph(mon); - } else { - if (worm_tail) - num = monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); - else - num = mon_to_glyph(mon); - } - show_glyph(x,y,num); + /* [ALI] Only use detected glyphs when monster wouldn't be + * visible by any other means. + */ + if (sightflags == DETECTED) { + if (worm_tail) + num = detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); + else + num = detected_mon_to_glyph(mon); + } else if (mon->mtame && !Hallucination) { + if (worm_tail) + num = petnum_to_glyph(PM_LONG_WORM_TAIL); + else + num = pet_to_glyph(mon); + } else { + if (worm_tail) + num = monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); + else + num = mon_to_glyph(mon); + } + show_glyph(x, y, num); } } @@ -456,22 +463,24 @@ display_monster(x, y, mon, sightflags, worm_tail) */ STATIC_OVL void display_warning(mon) - register struct monst *mon; +register struct monst *mon; { int x = mon->mx, y = mon->my; int wl = (int) (mon->m_lev / 4); int glyph; if (mon_warning(mon)) { - if (wl > WARNCOUNT - 1) wl = WARNCOUNT - 1; - /* 3.4.1: this really ought to be rn2(WARNCOUNT), but value "0" - isn't handled correctly by the what_is routine so avoid it */ - if (Hallucination) wl = rn1(WARNCOUNT-1,1); + if (wl > WARNCOUNT - 1) + wl = WARNCOUNT - 1; + /* 3.4.1: this really ought to be rn2(WARNCOUNT), but value "0" + isn't handled correctly by the what_is routine so avoid it */ + if (Hallucination) + wl = rn1(WARNCOUNT - 1, 1); glyph = warning_to_glyph(wl); } else if (MATCH_WARN_OF_MON(mon)) { - glyph = mon_to_glyph(mon); + glyph = mon_to_glyph(mon); } else { - impossible("display_warning did not match warning type?"); + impossible("display_warning did not match warning type?"); return; } show_glyph(x, y, glyph); @@ -489,144 +498,154 @@ display_warning(mon) */ void feel_location(x, y) - xchar x, y; +xchar x, y; { struct rm *lev; struct obj *boulder; register struct monst *mon; - if (!isok(x, y)) return; + if (!isok(x, y)) + return; lev = &(levl[x][y]); - /* If the hero's memory of an invisible monster is accurate, we want to keep + /* If the hero's memory of an invisible monster is accurate, we want to + * keep * him from detecting the same monster over and over again on each turn. * We must return (so we don't erase the monster). (We must also, in the * search function, be sure to skip over previously detected 'I's.) */ - if (glyph_is_invisible(lev->glyph) && m_at(x,y)) return; + if (glyph_is_invisible(lev->glyph) && m_at(x, y)) + return; /* The hero can't feel non pool locations while under water. */ - if (Underwater && !Is_waterlevel(&u.uz) && ! is_pool(x,y)) - return; + if (Underwater && !Is_waterlevel(&u.uz) && !is_pool(x, y)) + return; /* Set the seen vector as if the hero had seen it. It doesn't matter */ /* if the hero is levitating or not. */ set_seenv(lev, u.ux, u.uy, x, y); if (!can_reach_floor(FALSE)) { - /* - * Levitation Rules. It is assumed that the hero can feel the state - * of the walls around herself and can tell if she is in a corridor, - * room, or doorway. Boulders are felt because they are large enough. - * Anything else is unknown because the hero can't reach the ground. - * This makes things difficult. - * - * Check (and display) in order: - * - * + Stone, walls, and closed doors. - * + Boulders. [see a boulder before a doorway] - * + Doors. - * + Room/water positions - * + Everything else (hallways!) - */ - if (IS_ROCK(lev->typ) || (IS_DOOR(lev->typ) && - (lev->doormask & (D_LOCKED | D_CLOSED)))) { - map_background(x, y, 1); - } else if ((boulder = sobj_at(BOULDER,x,y)) != 0) { - map_object(boulder, 1); - } else if (IS_DOOR(lev->typ)) { - map_background(x, y, 1); - } else if (IS_ROOM(lev->typ) || IS_POOL(lev->typ)) { - /* - * An open room or water location. Normally we wouldn't touch - * this, but we have to get rid of remembered boulder symbols. - * This will only occur in rare occations when the hero goes - * blind and doesn't find a boulder where expected (something - * came along and picked it up). We know that there is not a - * boulder at this location. Show fountains, pools, etc. - * underneath if already seen. Otherwise, show the appropriate - * floor symbol. - * - * Similarly, if the hero digs a hole in a wall or feels a location - * that used to contain an unseen monster. In these cases, - * there's no reason to assume anything was underneath, so - * just show the appropriate floor symbol. If something was - * embedded in the wall, the glyph will probably already - * reflect that. Don't change the symbol in this case. - * - * This isn't quite correct. If the boulder was on top of some - * other objects they should be seen once the boulder is removed. - * However, we have no way of knowing that what is there now - * was there then. So we let the hero have a lapse of memory. - * We could also just display what is currently on the top of the - * object stack (if anything). - */ - if (lev->glyph == objnum_to_glyph(BOULDER)) { - if (lev->typ != ROOM && lev->seenv) { - map_background(x, y, 1); - } else { - lev->glyph = flags.dark_room ? cmap_to_glyph(S_darkroom) : - (lev->waslit ? cmap_to_glyph(S_room) : - cmap_to_glyph(S_stone)); - show_glyph(x,y,lev->glyph); - } - } else if ((lev->glyph >= cmap_to_glyph(S_stone) && - lev->glyph < cmap_to_glyph(S_darkroom)) || - glyph_is_invisible(levl[x][y].glyph)) { - lev->glyph = flags.dark_room ? cmap_to_glyph(S_darkroom) : - (lev->waslit ? cmap_to_glyph(S_room) : - cmap_to_glyph(S_stone)); - show_glyph(x,y,lev->glyph); - } - } else { - /* We feel it (I think hallways are the only things left). */ - map_background(x, y, 1); - /* Corridors are never felt as lit (unless remembered that way) */ - /* (lit_corridor only). */ - if (lev->typ == CORR && - lev->glyph == cmap_to_glyph(S_litcorr) && !lev->waslit) - show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr)); - else if (lev->typ == ROOM && flags.dark_room && - lev->glyph == cmap_to_glyph(S_room)) - show_glyph(x, y, lev->glyph = cmap_to_glyph(S_darkroom)); - } + /* + * Levitation Rules. It is assumed that the hero can feel the state + * of the walls around herself and can tell if she is in a corridor, + * room, or doorway. Boulders are felt because they are large enough. + * Anything else is unknown because the hero can't reach the ground. + * This makes things difficult. + * + * Check (and display) in order: + * + * + Stone, walls, and closed doors. + * + Boulders. [see a boulder before a doorway] + * + Doors. + * + Room/water positions + * + Everything else (hallways!) + */ + if (IS_ROCK(lev->typ) + || (IS_DOOR(lev->typ) + && (lev->doormask & (D_LOCKED | D_CLOSED)))) { + map_background(x, y, 1); + } else if ((boulder = sobj_at(BOULDER, x, y)) != 0) { + map_object(boulder, 1); + } else if (IS_DOOR(lev->typ)) { + map_background(x, y, 1); + } else if (IS_ROOM(lev->typ) || IS_POOL(lev->typ)) { + /* + * An open room or water location. Normally we wouldn't touch + * this, but we have to get rid of remembered boulder symbols. + * This will only occur in rare occations when the hero goes + * blind and doesn't find a boulder where expected (something + * came along and picked it up). We know that there is not a + * boulder at this location. Show fountains, pools, etc. + * underneath if already seen. Otherwise, show the appropriate + * floor symbol. + * + * Similarly, if the hero digs a hole in a wall or feels a + * location + * that used to contain an unseen monster. In these cases, + * there's no reason to assume anything was underneath, so + * just show the appropriate floor symbol. If something was + * embedded in the wall, the glyph will probably already + * reflect that. Don't change the symbol in this case. + * + * This isn't quite correct. If the boulder was on top of some + * other objects they should be seen once the boulder is removed. + * However, we have no way of knowing that what is there now + * was there then. So we let the hero have a lapse of memory. + * We could also just display what is currently on the top of the + * object stack (if anything). + */ + if (lev->glyph == objnum_to_glyph(BOULDER)) { + if (lev->typ != ROOM && lev->seenv) { + map_background(x, y, 1); + } else { + lev->glyph = flags.dark_room + ? cmap_to_glyph(S_darkroom) + : (lev->waslit ? cmap_to_glyph(S_room) + : cmap_to_glyph(S_stone)); + show_glyph(x, y, lev->glyph); + } + } else if ((lev->glyph >= cmap_to_glyph(S_stone) + && lev->glyph < cmap_to_glyph(S_darkroom)) + || glyph_is_invisible(levl[x][y].glyph)) { + lev->glyph = flags.dark_room + ? cmap_to_glyph(S_darkroom) + : (lev->waslit ? cmap_to_glyph(S_room) + : cmap_to_glyph(S_stone)); + show_glyph(x, y, lev->glyph); + } + } else { + /* We feel it (I think hallways are the only things left). */ + map_background(x, y, 1); + /* Corridors are never felt as lit (unless remembered that way) */ + /* (lit_corridor only). */ + if (lev->typ == CORR && lev->glyph == cmap_to_glyph(S_litcorr) + && !lev->waslit) + show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr)); + else if (lev->typ == ROOM && flags.dark_room + && lev->glyph == cmap_to_glyph(S_room)) + show_glyph(x, y, lev->glyph = cmap_to_glyph(S_darkroom)); + } } else { - _map_location(x, y, 1); + _map_location(x, y, 1); - if (Punished) { - /* - * A ball or chain is only felt if it is first on the object - * location list. Otherwise, we need to clear the felt bit --- - * something has been dropped on the ball/chain. If the bit is - * not cleared, then when the ball/chain is moved it will drop - * the wrong glyph. - */ - if (uchain->ox == x && uchain->oy == y) { - if (level.objects[x][y] == uchain) - u.bc_felt |= BC_CHAIN; - else - u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */ - } - if (!carried(uball) && uball->ox == x && uball->oy == y) { - if (level.objects[x][y] == uball) - u.bc_felt |= BC_BALL; - else - u.bc_felt &= ~BC_BALL; /* do not feel the ball */ - } - } + if (Punished) { + /* + * A ball or chain is only felt if it is first on the object + * location list. Otherwise, we need to clear the felt bit --- + * something has been dropped on the ball/chain. If the bit is + * not cleared, then when the ball/chain is moved it will drop + * the wrong glyph. + */ + if (uchain->ox == x && uchain->oy == y) { + if (level.objects[x][y] == uchain) + u.bc_felt |= BC_CHAIN; + else + u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */ + } + if (!carried(uball) && uball->ox == x && uball->oy == y) { + if (level.objects[x][y] == uball) + u.bc_felt |= BC_BALL; + else + u.bc_felt &= ~BC_BALL; /* do not feel the ball */ + } + } - /* Floor spaces are dark if unlit. Corridors are dark if unlit. */ - if (lev->typ == ROOM && lev->glyph == cmap_to_glyph(S_room) && - (!lev->waslit || flags.dark_room)) - show_glyph(x,y, lev->glyph = cmap_to_glyph(flags.dark_room ? S_darkroom : S_stone)); - else if (lev->typ == CORR && - lev->glyph == cmap_to_glyph(S_litcorr) && !lev->waslit) - show_glyph(x,y, lev->glyph = cmap_to_glyph(S_corr)); + /* Floor spaces are dark if unlit. Corridors are dark if unlit. */ + if (lev->typ == ROOM && lev->glyph == cmap_to_glyph(S_room) + && (!lev->waslit || flags.dark_room)) + show_glyph(x, y, lev->glyph = cmap_to_glyph( + flags.dark_room ? S_darkroom : S_stone)); + else if (lev->typ == CORR && lev->glyph == cmap_to_glyph(S_litcorr) + && !lev->waslit) + show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr)); } /* draw monster on top if we can sense it */ - if ((x != u.ux || y != u.uy) && (mon = m_at(x,y)) && sensemon(mon)) - display_monster(x, y, mon, - (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)) ? PHYSICALLY_SEEN : DETECTED, - is_worm_tail(mon)); + if ((x != u.ux || y != u.uy) && (mon = m_at(x, y)) && sensemon(mon)) + display_monster(x, y, mon, + (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)) + ? PHYSICALLY_SEEN + : DETECTED, + is_worm_tail(mon)); } /* @@ -635,151 +654,163 @@ feel_location(x, y) * Possibly put a new glyph at the given location. */ void -newsym(x,y) - register int x,y; +newsym(x, y) +register int x, y; { register struct monst *mon; register struct rm *lev = &(levl[x][y]); register int see_it; register xchar worm_tail; - if (in_mklev) return; + if (in_mklev) + return; #ifdef HANGUPHANDLING - if (program_state.done_hup) return; + if (program_state.done_hup) + return; #endif /* only permit updating the hero when swallowed */ if (u.uswallow) { - if (x == u.ux && y == u.uy) display_self(); - return; + if (x == u.ux && y == u.uy) + display_self(); + return; } if (Underwater && !Is_waterlevel(&u.uz)) { - /* don't do anything unless (x,y) is an adjacent underwater position */ - int dx, dy; - if (!is_pool(x,y)) return; - dx = x - u.ux; if (dx < 0) dx = -dx; - dy = y - u.uy; if (dy < 0) dy = -dy; - if (dx > 1 || dy > 1) return; + /* don't do anything unless (x,y) is an adjacent underwater position + */ + int dx, dy; + if (!is_pool(x, y)) + return; + dx = x - u.ux; + if (dx < 0) + dx = -dx; + dy = y - u.uy; + if (dy < 0) + dy = -dy; + if (dx > 1 || dy > 1) + return; } /* Can physically see the location. */ - if (cansee(x,y)) { - NhRegion* reg = visible_region_at(x,y); - /* - * Don't use templit here: E.g. - * - * lev->waslit = !!(lev->lit || templit(x,y)); - * - * Otherwise we have the "light pool" problem, where non-permanently - * lit areas just out of sight stay remembered as lit. They should - * re-darken. - * - * Perhaps ALL areas should revert to their "unlit" look when - * out of sight. - */ - lev->waslit = (lev->lit!=0); /* remember lit condition */ + if (cansee(x, y)) { + NhRegion *reg = visible_region_at(x, y); + /* + * Don't use templit here: E.g. + * + * lev->waslit = !!(lev->lit || templit(x,y)); + * + * Otherwise we have the "light pool" problem, where non-permanently + * lit areas just out of sight stay remembered as lit. They should + * re-darken. + * + * Perhaps ALL areas should revert to their "unlit" look when + * out of sight. + */ + lev->waslit = (lev->lit != 0); /* remember lit condition */ - /* normal region shown only on accessible positions, but poison clouds - * also shown above lava, pools and moats. - */ - if (reg != NULL && (ACCESSIBLE(lev->typ) || - (reg->glyph == cmap_to_glyph(S_poisoncloud) && - (lev->typ == LAVAPOOL || lev->typ == POOL || lev->typ == MOAT)))) { - show_region(reg,x,y); - return; - } - if (x == u.ux && y == u.uy) { - if (canspotself()) { - _map_location(x,y,0); /* map *under* self */ - display_self(); - } else - /* we can see what is there */ - _map_location(x,y,1); - } - else { - mon = m_at(x,y); - worm_tail = is_worm_tail(mon); - see_it = mon && (worm_tail - ? (!mon->minvis || See_invisible) - : (mon_visible(mon)) || tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)); - if (mon && (see_it || (!worm_tail && Detect_monsters))) { - if (mon->mtrapped) { - struct trap *trap = t_at(x, y); - int tt = trap ? trap->ttyp : NO_TRAP; + /* normal region shown only on accessible positions, but poison clouds + * also shown above lava, pools and moats. + */ + if (reg != NULL && (ACCESSIBLE(lev->typ) + || (reg->glyph == cmap_to_glyph(S_poisoncloud) + && (lev->typ == LAVAPOOL || lev->typ == POOL + || lev->typ == MOAT)))) { + show_region(reg, x, y); + return; + } + if (x == u.ux && y == u.uy) { + if (canspotself()) { + _map_location(x, y, 0); /* map *under* self */ + display_self(); + } else + /* we can see what is there */ + _map_location(x, y, 1); + } else { + mon = m_at(x, y); + worm_tail = is_worm_tail(mon); + see_it = + mon && (worm_tail ? (!mon->minvis || See_invisible) + : (mon_visible(mon)) || tp_sensemon(mon) + || MATCH_WARN_OF_MON(mon)); + if (mon && (see_it || (!worm_tail && Detect_monsters))) { + if (mon->mtrapped) { + struct trap *trap = t_at(x, y); + int tt = trap ? trap->ttyp : NO_TRAP; - /* if monster is in a physical trap, you see the trap too */ - if (tt == BEAR_TRAP || tt == PIT || - tt == SPIKED_PIT ||tt == WEB) { - trap->tseen = TRUE; - } - } - _map_location(x,y,0); /* map under the monster */ - /* also gets rid of any invisibility glyph */ - display_monster(x, y, mon, see_it ? PHYSICALLY_SEEN : DETECTED, worm_tail); - } - else if (mon && mon_warning(mon) && !is_worm_tail(mon)) - display_warning(mon); - else if (glyph_is_invisible(levl[x][y].glyph)) - map_invisible(x, y); - else - _map_location(x,y,1); /* map the location */ - } + /* if monster is in a physical trap, you see the trap too + */ + if (tt == BEAR_TRAP || tt == PIT || tt == SPIKED_PIT + || tt == WEB) { + trap->tseen = TRUE; + } + } + _map_location(x, y, 0); /* map under the monster */ + /* also gets rid of any invisibility glyph */ + display_monster(x, y, mon, + see_it ? PHYSICALLY_SEEN : DETECTED, + worm_tail); + } else if (mon && mon_warning(mon) && !is_worm_tail(mon)) + display_warning(mon); + else if (glyph_is_invisible(levl[x][y].glyph)) + map_invisible(x, y); + else + _map_location(x, y, 1); /* map the location */ + } } /* Can't see the location. */ else { - if (x == u.ux && y == u.uy) { - feel_location(u.ux, u.uy); /* forces an update */ + if (x == u.ux && y == u.uy) { + feel_location(u.ux, u.uy); /* forces an update */ - if (canspotself()) display_self(); - } - else if ((mon = m_at(x,y)) - && ((see_it = (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon) - || (see_with_infrared(mon) && mon_visible(mon)))) - || Detect_monsters) - && !is_worm_tail(mon)) { - /* Monsters are printed every time. */ - /* This also gets rid of any invisibility glyph */ - display_monster(x, y, mon, see_it ? 0 : DETECTED, 0); - } - else if ((mon = m_at(x,y)) && mon_warning(mon) && - !is_worm_tail(mon)) { - display_warning(mon); - } + if (canspotself()) + display_self(); + } else if ((mon = m_at(x, y)) + && ((see_it = + (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon) + || (see_with_infrared(mon) && mon_visible(mon)))) + || Detect_monsters) && !is_worm_tail(mon)) { + /* Monsters are printed every time. */ + /* This also gets rid of any invisibility glyph */ + display_monster(x, y, mon, see_it ? 0 : DETECTED, 0); + } else if ((mon = m_at(x, y)) && mon_warning(mon) + && !is_worm_tail(mon)) { + display_warning(mon); + } - /* - * If the location is remembered as being both dark (waslit is false) - * and lit (glyph is a lit room or lit corridor) then it was either: - * - * (1) A dark location that the hero could see through night - * vision. - * - * (2) Darkened while out of the hero's sight. This can happen - * when cursed scroll of light is read. - * - * In either case, we have to manually correct the hero's memory to - * match waslit. Deciding when to change waslit is non-trivial. - * - * Note: If flags.lit_corridor is set, then corridors act like room - * squares. That is, they light up if in night vision range. - * If flags.lit_corridor is not set, then corridors will - * remain dark unless lit by a light spell and may darken - * again, as discussed above. - * - * These checks and changes must be here and not in back_to_glyph(). - * They are dependent on the position being out of sight. - */ - else if (!lev->waslit || (flags.dark_room && iflags.use_color)) { - if (lev->glyph == cmap_to_glyph(S_litcorr) && lev->typ == CORR) - show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr)); - else if (lev->glyph == cmap_to_glyph(S_room) && lev->typ == ROOM) - show_glyph(x, y, lev->glyph = cmap_to_glyph(DARKROOMSYM)); - else - goto show_mem; - } else { -show_mem: - show_glyph(x, y, lev->glyph); - } + /* + * If the location is remembered as being both dark (waslit is false) + * and lit (glyph is a lit room or lit corridor) then it was either: + * + * (1) A dark location that the hero could see through night + * vision. + * + * (2) Darkened while out of the hero's sight. This can happen + * when cursed scroll of light is read. + * + * In either case, we have to manually correct the hero's memory to + * match waslit. Deciding when to change waslit is non-trivial. + * + * Note: If flags.lit_corridor is set, then corridors act like room + * squares. That is, they light up if in night vision range. + * If flags.lit_corridor is not set, then corridors will + * remain dark unless lit by a light spell and may darken + * again, as discussed above. + * + * These checks and changes must be here and not in back_to_glyph(). + * They are dependent on the position being out of sight. + */ + else if (!lev->waslit || (flags.dark_room && iflags.use_color)) { + if (lev->glyph == cmap_to_glyph(S_litcorr) && lev->typ == CORR) + show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr)); + else if (lev->glyph == cmap_to_glyph(S_room) && lev->typ == ROOM) + show_glyph(x, y, lev->glyph = cmap_to_glyph(DARKROOMSYM)); + else + goto show_mem; + } else { + show_mem: + show_glyph(x, y, lev->glyph); + } } } @@ -792,23 +823,23 @@ show_mem: * pulled into a platform dependent routine for fancier graphics if desired. */ void -shieldeff(x,y) - xchar x,y; +shieldeff(x, y) +xchar x, y; { register int i; - if (!flags.sparkle) return; - if (cansee(x,y)) { /* Don't see anything if can't see the location */ - for (i = 0; i < SHIELD_COUNT; i++) { - show_glyph(x, y, cmap_to_glyph(shield_static[i])); - flush_screen(1); /* make sure the glyph shows up */ - delay_output(); - } - newsym(x,y); /* restore the old information */ + if (!flags.sparkle) + return; + if (cansee(x, y)) { /* Don't see anything if can't see the location */ + for (i = 0; i < SHIELD_COUNT; i++) { + show_glyph(x, y, cmap_to_glyph(shield_static[i])); + flush_screen(1); /* make sure the glyph shows up */ + delay_output(); + } + newsym(x, y); /* restore the old information */ } } - /* * tmp_at() * @@ -834,103 +865,109 @@ shieldeff(x,y) * DISP_ALWAYS- Like DISP_FLASH, but vision is not taken into account. */ -#define TMP_AT_MAX_GLYPHS (COLNO*2) +#define TMP_AT_MAX_GLYPHS (COLNO * 2) static struct tmp_glyph { - coord saved[TMP_AT_MAX_GLYPHS]; /* previously updated positions */ - int sidx; /* index of next unused slot in saved[] */ - int style; /* either DISP_BEAM or DISP_FLASH or DISP_ALWAYS */ - int glyph; /* glyph to use when printing */ + coord saved[TMP_AT_MAX_GLYPHS]; /* previously updated positions */ + int sidx; /* index of next unused slot in saved[] */ + int style; /* either DISP_BEAM or DISP_FLASH or DISP_ALWAYS */ + int glyph; /* glyph to use when printing */ struct tmp_glyph *prev; } tgfirst; void tmp_at(x, y) - int x, y; +int x, y; { - static struct tmp_glyph *tglyph = (struct tmp_glyph *)0; + static struct tmp_glyph *tglyph = (struct tmp_glyph *) 0; struct tmp_glyph *tmp; switch (x) { - case DISP_BEAM: - case DISP_ALL: - case DISP_FLASH: - case DISP_ALWAYS: - if (!tglyph) - tmp = &tgfirst; - else /* nested effect; we need dynamic memory */ - tmp = (struct tmp_glyph *)alloc(sizeof (struct tmp_glyph)); - tmp->prev = tglyph; - tglyph = tmp; - tglyph->sidx = 0; - tglyph->style = x; - tglyph->glyph = y; - flush_screen(0); /* flush buffered glyphs */ - return; + case DISP_BEAM: + case DISP_ALL: + case DISP_FLASH: + case DISP_ALWAYS: + if (!tglyph) + tmp = &tgfirst; + else /* nested effect; we need dynamic memory */ + tmp = (struct tmp_glyph *) alloc(sizeof(struct tmp_glyph)); + tmp->prev = tglyph; + tglyph = tmp; + tglyph->sidx = 0; + tglyph->style = x; + tglyph->glyph = y; + flush_screen(0); /* flush buffered glyphs */ + return; - case DISP_FREEMEM: /* in case game ends with tmp_at() in progress */ - while (tglyph) { - tmp = tglyph->prev; - if (tglyph != &tgfirst) free((genericptr_t)tglyph); - tglyph = tmp; - } - return; + case DISP_FREEMEM: /* in case game ends with tmp_at() in progress */ + while (tglyph) { + tmp = tglyph->prev; + if (tglyph != &tgfirst) + free((genericptr_t) tglyph); + tglyph = tmp; + } + return; - default: - break; + default: + break; } - if (!tglyph) panic("tmp_at: tglyph not initialized"); + if (!tglyph) + panic("tmp_at: tglyph not initialized"); switch (x) { - case DISP_CHANGE: - tglyph->glyph = y; - break; + case DISP_CHANGE: + tglyph->glyph = y; + break; - case DISP_END: - if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) { - register int i; + case DISP_END: + if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) { + register int i; - /* Erase (reset) from source to end */ - for (i = 0; i < tglyph->sidx; i++) - newsym(tglyph->saved[i].x, tglyph->saved[i].y); - } else { /* DISP_FLASH or DISP_ALWAYS */ - if (tglyph->sidx) /* been called at least once */ - newsym(tglyph->saved[0].x, tglyph->saved[0].y); - } - /* tglyph->sidx = 0; -- about to be freed, so not necessary */ - tmp = tglyph->prev; - if (tglyph != &tgfirst) free((genericptr_t)tglyph); - tglyph = tmp; - break; + /* Erase (reset) from source to end */ + for (i = 0; i < tglyph->sidx; i++) + newsym(tglyph->saved[i].x, tglyph->saved[i].y); + } else { /* DISP_FLASH or DISP_ALWAYS */ + if (tglyph->sidx) /* been called at least once */ + newsym(tglyph->saved[0].x, tglyph->saved[0].y); + } + /* tglyph->sidx = 0; -- about to be freed, so not necessary */ + tmp = tglyph->prev; + if (tglyph != &tgfirst) + free((genericptr_t) tglyph); + tglyph = tmp; + break; - default: /* do it */ - if (!isok(x,y)) break; - if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) { - if (tglyph->style != DISP_ALL && !cansee(x,y)) break; - if (tglyph->sidx >= TMP_AT_MAX_GLYPHS) break; /* too many locations */ - /* save pos for later erasing */ - tglyph->saved[tglyph->sidx].x = x; - tglyph->saved[tglyph->sidx].y = y; - tglyph->sidx += 1; - } else { /* DISP_FLASH/ALWAYS */ - if (tglyph->sidx) { /* not first call, so reset previous pos */ - newsym(tglyph->saved[0].x, tglyph->saved[0].y); - tglyph->sidx = 0; /* display is presently up to date */ - } - if (!cansee(x,y) && tglyph->style != DISP_ALWAYS) break; - tglyph->saved[0].x = x; - tglyph->saved[0].y = y; - tglyph->sidx = 1; - } + default: /* do it */ + if (!isok(x, y)) + break; + if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) { + if (tglyph->style != DISP_ALL && !cansee(x, y)) + break; + if (tglyph->sidx >= TMP_AT_MAX_GLYPHS) + break; /* too many locations */ + /* save pos for later erasing */ + tglyph->saved[tglyph->sidx].x = x; + tglyph->saved[tglyph->sidx].y = y; + tglyph->sidx += 1; + } else { /* DISP_FLASH/ALWAYS */ + if (tglyph->sidx) { /* not first call, so reset previous pos */ + newsym(tglyph->saved[0].x, tglyph->saved[0].y); + tglyph->sidx = 0; /* display is presently up to date */ + } + if (!cansee(x, y) && tglyph->style != DISP_ALWAYS) + break; + tglyph->saved[0].x = x; + tglyph->saved[0].y = y; + tglyph->sidx = 1; + } - show_glyph(x, y, tglyph->glyph); /* show it */ - flush_screen(0); /* make sure it shows up */ - break; + show_glyph(x, y, tglyph->glyph); /* show it */ + flush_screen(0); /* make sure it shows up */ + break; } /* end case */ } - /* * swallowed() * @@ -941,49 +978,54 @@ tmp_at(x, y) */ void swallowed(first) - int first; +int first; { - static xchar lastx, lasty; /* last swallowed position */ + static xchar lastx, lasty; /* last swallowed position */ int swallower, left_ok, rght_ok; if (first) - cls(); + cls(); else { - register int x, y; + register int x, y; - /* Clear old location */ - for (y = lasty-1; y <= lasty+1; y++) - for (x = lastx-1; x <= lastx+1; x++) - if (isok(x,y)) show_glyph(x,y,cmap_to_glyph(S_stone)); + /* Clear old location */ + for (y = lasty - 1; y <= lasty + 1; y++) + for (x = lastx - 1; x <= lastx + 1; x++) + if (isok(x, y)) + show_glyph(x, y, cmap_to_glyph(S_stone)); } swallower = monsndx(u.ustuck->data); /* assume isok(u.ux,u.uy) */ - left_ok = isok(u.ux-1,u.uy); - rght_ok = isok(u.ux+1,u.uy); + left_ok = isok(u.ux - 1, u.uy); + rght_ok = isok(u.ux + 1, u.uy); /* * Display the hero surrounded by the monster's stomach. */ - if(isok(u.ux, u.uy-1)) { - if (left_ok) - show_glyph(u.ux-1, u.uy-1, swallow_to_glyph(swallower, S_sw_tl)); - show_glyph(u.ux , u.uy-1, swallow_to_glyph(swallower, S_sw_tc)); - if (rght_ok) - show_glyph(u.ux+1, u.uy-1, swallow_to_glyph(swallower, S_sw_tr)); + if (isok(u.ux, u.uy - 1)) { + if (left_ok) + show_glyph(u.ux - 1, u.uy - 1, + swallow_to_glyph(swallower, S_sw_tl)); + show_glyph(u.ux, u.uy - 1, swallow_to_glyph(swallower, S_sw_tc)); + if (rght_ok) + show_glyph(u.ux + 1, u.uy - 1, + swallow_to_glyph(swallower, S_sw_tr)); } if (left_ok) - show_glyph(u.ux-1, u.uy , swallow_to_glyph(swallower, S_sw_ml)); + show_glyph(u.ux - 1, u.uy, swallow_to_glyph(swallower, S_sw_ml)); display_self(); if (rght_ok) - show_glyph(u.ux+1, u.uy , swallow_to_glyph(swallower, S_sw_mr)); + show_glyph(u.ux + 1, u.uy, swallow_to_glyph(swallower, S_sw_mr)); - if(isok(u.ux, u.uy+1)) { - if (left_ok) - show_glyph(u.ux-1, u.uy+1, swallow_to_glyph(swallower, S_sw_bl)); - show_glyph(u.ux , u.uy+1, swallow_to_glyph(swallower, S_sw_bc)); - if (rght_ok) - show_glyph(u.ux+1, u.uy+1, swallow_to_glyph(swallower, S_sw_br)); + if (isok(u.ux, u.uy + 1)) { + if (left_ok) + show_glyph(u.ux - 1, u.uy + 1, + swallow_to_glyph(swallower, S_sw_bl)); + show_glyph(u.ux, u.uy + 1, swallow_to_glyph(swallower, S_sw_bc)); + if (rght_ok) + show_glyph(u.ux + 1, u.uy + 1, + swallow_to_glyph(swallower, S_sw_br)); } /* Update the swallowed position. */ @@ -999,40 +1041,41 @@ swallowed(first) */ void under_water(mode) - int mode; +int mode; { static xchar lastx, lasty; static boolean dela; register int x, y; /* swallowing has a higher precedence than under water */ - if (Is_waterlevel(&u.uz) || u.uswallow) return; + if (Is_waterlevel(&u.uz) || u.uswallow) + return; /* full update */ if (mode == 1 || dela) { - cls(); - dela = FALSE; + cls(); + dela = FALSE; } /* delayed full update */ else if (mode == 2) { - dela = TRUE; - return; + dela = TRUE; + return; } /* limited update */ else { - for (y = lasty-1; y <= lasty+1; y++) - for (x = lastx-1; x <= lastx+1; x++) - if (isok(x,y)) - show_glyph(x,y,cmap_to_glyph(S_stone)); + for (y = lasty - 1; y <= lasty + 1; y++) + for (x = lastx - 1; x <= lastx + 1; x++) + if (isok(x, y)) + show_glyph(x, y, cmap_to_glyph(S_stone)); } - for (x = u.ux-1; x <= u.ux+1; x++) - for (y = u.uy-1; y <= u.uy+1; y++) - if (isok(x,y) && is_pool(x,y)) { - if (Blind && !(x == u.ux && y == u.uy)) - show_glyph(x,y,cmap_to_glyph(S_stone)); - else - newsym(x,y); - } + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) + if (isok(x, y) && is_pool(x, y)) { + if (Blind && !(x == u.ux && y == u.uy)) + show_glyph(x, y, cmap_to_glyph(S_stone)); + else + newsym(x, y); + } lastx = u.ux; lasty = u.uy; } @@ -1044,36 +1087,37 @@ under_water(mode) */ void under_ground(mode) - int mode; +int mode; { static boolean dela; /* swallowing has a higher precedence than under ground */ - if (u.uswallow) return; + if (u.uswallow) + return; /* full update */ if (mode == 1 || dela) { - cls(); - dela = FALSE; + cls(); + dela = FALSE; } /* delayed full update */ else if (mode == 2) { - dela = TRUE; - return; + dela = TRUE; + return; } /* limited update */ else - newsym(u.ux,u.uy); + newsym(u.ux, u.uy); } - -/* ========================================================================= */ +/* ========================================================================= + */ /* * Loop through all of the monsters and update them. Called when: * + going blind & telepathic * + regaining sight & telepathic - * + getting and losing infravision + * + getting and losing infravision * + hallucinating * + doing a full screen redraw * + see invisible times out or a ring of see invisible is taken off @@ -1089,24 +1133,28 @@ see_monsters() register struct monst *mon; int new_warn_obj_cnt = 0; - if (defer_see_monsters) return; + if (defer_see_monsters) + return; for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - newsym(mon->mx,mon->my); - if (mon->wormno) see_wsegs(mon); - if (MATCH_WARN_OF_MON(mon)) { - if (context.warntype.obj && - (context.warntype.obj & mon->data->mflags2)) new_warn_obj_cnt++; - } + if (DEADMONSTER(mon)) + continue; + newsym(mon->mx, mon->my); + if (mon->wormno) + see_wsegs(mon); + if (MATCH_WARN_OF_MON(mon)) { + if (context.warntype.obj + && (context.warntype.obj & mon->data->mflags2)) + new_warn_obj_cnt++; + } } /* * Make Sting glow blue or stop glowing if required. */ - if (new_warn_obj_cnt != warn_obj_cnt && - uwep && uwep->oartifact == ART_STING) { - Sting_effects(new_warn_obj_cnt); - warn_obj_cnt = new_warn_obj_cnt; + if (new_warn_obj_cnt != warn_obj_cnt && uwep + && uwep->oartifact == ART_STING) { + Sting_effects(new_warn_obj_cnt); + warn_obj_cnt = new_warn_obj_cnt; } /* when mounted, hero's location gets caught by monster loop */ @@ -1125,16 +1173,18 @@ set_mimic_blocking() register struct monst *mon; for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - if (mon->minvis && - ((mon->m_ap_type == M_AP_FURNITURE && - (mon->mappearance == S_vcdoor || mon->mappearance == S_hcdoor)) || - (mon->m_ap_type == M_AP_OBJECT && mon->mappearance == BOULDER))) { - if(See_invisible) - block_point(mon->mx, mon->my); - else - unblock_point(mon->mx, mon->my); - } + if (DEADMONSTER(mon)) + continue; + if (mon->minvis && ((mon->m_ap_type == M_AP_FURNITURE + && (mon->mappearance == S_vcdoor + || mon->mappearance == S_hcdoor)) + || (mon->m_ap_type == M_AP_OBJECT + && mon->mappearance == BOULDER))) { + if (See_invisible) + block_point(mon->mx, mon->my); + else + unblock_point(mon->mx, mon->my); + } } } @@ -1146,8 +1196,9 @@ void see_objects() { register struct obj *obj; - for(obj = fobj; obj; obj = obj->nobj) - if (vobj_at(obj->ox,obj->oy) == obj) newsym(obj->ox, obj->oy); + for (obj = fobj; obj; obj = obj->nobj) + if (vobj_at(obj->ox, obj->oy) == obj) + newsym(obj->ox, obj->oy); } /* @@ -1160,9 +1211,9 @@ see_traps() int glyph; for (trap = ftrap; trap; trap = trap->ntrap) { - glyph = glyph_at(trap->tx, trap->ty); - if (glyph_is_trap(glyph)) - newsym(trap->tx, trap->ty); + glyph = glyph_at(trap->tx, trap->ty); + if (glyph_is_trap(glyph)) + newsym(trap->tx, trap->ty); } } @@ -1172,7 +1223,7 @@ see_traps() void curs_on_u() { - flush_screen(1); /* Flush waiting glyphs & put cursor on hero */ + flush_screen(1); /* Flush waiting glyphs & put cursor on hero */ } int @@ -1185,22 +1236,23 @@ doredraw() void docrt() { - register int x,y; + register int x, y; register struct rm *lev; - if (!u.ux) return; /* display isn't ready yet */ + if (!u.ux) + return; /* display isn't ready yet */ if (u.uswallow) { - swallowed(1); - return; + swallowed(1); + return; } if (Underwater && !Is_waterlevel(&u.uz)) { - under_water(1); - return; + under_water(1); + return; } if (u.uburied) { - under_ground(1); - return; + under_ground(1); + return; } /* shut down vision */ @@ -1215,10 +1267,10 @@ docrt() /* display memory */ for (x = 1; x < COLNO; x++) { - lev = &levl[x][0]; - for (y = 0; y < ROWNO; y++, lev++) - if (lev->glyph != cmap_to_glyph(S_stone)) - show_glyph(x,y,lev->glyph); + lev = &levl[x][0]; + for (y = 0; y < ROWNO; y++, lev++) + if (lev->glyph != cmap_to_glyph(S_stone)) + show_glyph(x, y, lev->glyph); } /* see what is to be seen */ @@ -1227,16 +1279,17 @@ docrt() /* overlay with monsters */ see_monsters(); - context.botlx = 1; /* force a redraw of the bottom line */ + context.botlx = 1; /* force a redraw of the bottom line */ } - -/* ========================================================================= */ -/* Glyph Buffering (3rd screen) ============================================ */ +/* ========================================================================= + */ +/* Glyph Buffering (3rd screen) ============================================ + */ typedef struct { - xchar new; /* perhaps move this bit into the rm strucure. */ - int glyph; + xchar new; /* perhaps move this bit into the rm strucure. */ + int glyph; } gbuf_entry; static gbuf_entry gbuf[ROWNO][COLNO]; @@ -1247,86 +1300,99 @@ static char gbuf_stop[ROWNO]; * Store the glyph in the 3rd screen for later flushing. */ void -show_glyph(x,y,glyph) - int x, y, glyph; +show_glyph(x, y, glyph) +int x, y, glyph; { /* * Check for bad positions and glyphs. */ if (!isok(x, y)) { - const char *text; - int offset; + const char *text; + int offset; - /* column 0 is invalid, but it's often used as a flag, so ignore it */ - if (x == 0) return; + /* column 0 is invalid, but it's often used as a flag, so ignore it */ + if (x == 0) + return; - /* - * This assumes an ordering of the offsets. See display.h for - * the definition. - */ + /* + * This assumes an ordering of the offsets. See display.h for + * the definition. + */ - if (glyph >= GLYPH_WARNING_OFF - && glyph < GLYPH_STATUE_OFF) { /* a warning */ - text = "warning"; offset = glyph - GLYPH_WARNING_OFF; - } else if (glyph >= GLYPH_SWALLOW_OFF) { /* swallow border */ - text = "swallow border"; offset = glyph - GLYPH_SWALLOW_OFF; - } else if (glyph >= GLYPH_ZAP_OFF) { /* zap beam */ - text = "zap beam"; offset = glyph - GLYPH_ZAP_OFF; - } else if (glyph >= GLYPH_EXPLODE_OFF) { /* explosion */ - text = "explosion"; offset = glyph - GLYPH_EXPLODE_OFF; - } else if (glyph >= GLYPH_CMAP_OFF) { /* cmap */ - text = "cmap_index"; offset = glyph - GLYPH_CMAP_OFF; - } else if (glyph >= GLYPH_OBJ_OFF) { /* object */ - text = "object"; offset = glyph - GLYPH_OBJ_OFF; - } else if (glyph >= GLYPH_RIDDEN_OFF) { /* ridden mon */ - text = "ridden mon"; offset = glyph - GLYPH_RIDDEN_OFF; - } else if (glyph >= GLYPH_BODY_OFF) { /* a corpse */ - text = "corpse"; offset = glyph - GLYPH_BODY_OFF; - } else if (glyph >= GLYPH_DETECT_OFF) { /* detected mon */ - text = "detected mon"; offset = glyph - GLYPH_DETECT_OFF; - } else if (glyph >= GLYPH_INVIS_OFF) { /* invisible mon */ - text = "invisible mon"; offset = glyph - GLYPH_INVIS_OFF; - } else if (glyph >= GLYPH_PET_OFF) { /* a pet */ - text = "pet"; offset = glyph - GLYPH_PET_OFF; - } else { /* a monster */ - text = "monster"; offset = glyph; - } + if (glyph >= GLYPH_WARNING_OFF + && glyph < GLYPH_STATUE_OFF) { /* a warning */ + text = "warning"; + offset = glyph - GLYPH_WARNING_OFF; + } else if (glyph >= GLYPH_SWALLOW_OFF) { /* swallow border */ + text = "swallow border"; + offset = glyph - GLYPH_SWALLOW_OFF; + } else if (glyph >= GLYPH_ZAP_OFF) { /* zap beam */ + text = "zap beam"; + offset = glyph - GLYPH_ZAP_OFF; + } else if (glyph >= GLYPH_EXPLODE_OFF) { /* explosion */ + text = "explosion"; + offset = glyph - GLYPH_EXPLODE_OFF; + } else if (glyph >= GLYPH_CMAP_OFF) { /* cmap */ + text = "cmap_index"; + offset = glyph - GLYPH_CMAP_OFF; + } else if (glyph >= GLYPH_OBJ_OFF) { /* object */ + text = "object"; + offset = glyph - GLYPH_OBJ_OFF; + } else if (glyph >= GLYPH_RIDDEN_OFF) { /* ridden mon */ + text = "ridden mon"; + offset = glyph - GLYPH_RIDDEN_OFF; + } else if (glyph >= GLYPH_BODY_OFF) { /* a corpse */ + text = "corpse"; + offset = glyph - GLYPH_BODY_OFF; + } else if (glyph >= GLYPH_DETECT_OFF) { /* detected mon */ + text = "detected mon"; + offset = glyph - GLYPH_DETECT_OFF; + } else if (glyph >= GLYPH_INVIS_OFF) { /* invisible mon */ + text = "invisible mon"; + offset = glyph - GLYPH_INVIS_OFF; + } else if (glyph >= GLYPH_PET_OFF) { /* a pet */ + text = "pet"; + offset = glyph - GLYPH_PET_OFF; + } else { /* a monster */ + text = "monster"; + offset = glyph; + } - impossible("show_glyph: bad pos %d %d with glyph %d [%s %d].", - x, y, glyph, text, offset); - return; + impossible("show_glyph: bad pos %d %d with glyph %d [%s %d].", x, y, + glyph, text, offset); + return; } if (glyph >= MAX_GLYPH) { - impossible("show_glyph: bad glyph %d [max %d] at (%d,%d).", - glyph, MAX_GLYPH, x, y); - return; + impossible("show_glyph: bad glyph %d [max %d] at (%d,%d).", glyph, + MAX_GLYPH, x, y); + return; } if (gbuf[y][x].glyph != glyph) { - gbuf[y][x].glyph = glyph; - gbuf[y][x].new = 1; - if (gbuf_start[y] > x) gbuf_start[y] = x; - if (gbuf_stop[y] < x) gbuf_stop[y] = x; + gbuf[y][x].glyph = glyph; + gbuf[y][x].new = 1; + if (gbuf_start[y] > x) + gbuf_start[y] = x; + if (gbuf_stop[y] < x) + gbuf_stop[y] = x; } } - /* * Reset the changed glyph borders so that none of the 3rd screen has * changed. */ -#define reset_glyph_bbox() \ - { \ - int i; \ - \ - for (i = 0; i < ROWNO; i++) { \ - gbuf_start[i] = COLNO-1; \ - gbuf_stop[i] = 0; \ - } \ +#define reset_glyph_bbox() \ + { \ + int i; \ + \ + for (i = 0; i < ROWNO; i++) { \ + gbuf_start[i] = COLNO - 1; \ + gbuf_stop[i] = 0; \ + } \ } - static gbuf_entry nul_gbuf = { 0, cmap_to_glyph(S_stone) }; /* * Turn the 3rd screen into stone. @@ -1338,10 +1404,10 @@ clear_glyph_buffer() register gbuf_entry *gptr; for (y = 0; y < ROWNO; y++) { - gptr = &gbuf[y][0]; - for (x = COLNO; x; x--) { - *gptr++ = nul_gbuf; - } + gptr = &gbuf[y][0]; + for (x = COLNO; x; x--) { + *gptr++ = nul_gbuf; + } } reset_glyph_bbox(); } @@ -1350,14 +1416,14 @@ clear_glyph_buffer() * Assumes that the indicated positions are filled with S_stone glyphs. */ void -row_refresh(start,stop,y) - int start,stop,y; +row_refresh(start, stop, y) +int start, stop, y; { register int x; for (x = start; x <= stop; x++) - if (gbuf[y][x].glyph != cmap_to_glyph(S_stone)) - print_glyph(WIN_MAP,x,y,gbuf[y][x].glyph); + if (gbuf[y][x].glyph != cmap_to_glyph(S_stone)) + print_glyph(WIN_MAP, x, y, gbuf[y][x].glyph); } void @@ -1365,13 +1431,14 @@ cls() { static boolean in_cls = 0; - if (in_cls) return; + if (in_cls) + return; in_cls = TRUE; display_nhwindow(WIN_MESSAGE, FALSE); /* flush messages */ - context.botlx = 1; /* force update of botl window */ - clear_nhwindow(WIN_MAP); /* clear physical screen */ + context.botlx = 1; /* force update of botl window */ + clear_nhwindow(WIN_MAP); /* clear physical screen */ - clear_glyph_buffer(); /* this is sort of an extra effort, but OK */ + clear_glyph_buffer(); /* this is sort of an extra effort, but OK */ in_cls = FALSE; } @@ -1380,40 +1447,47 @@ cls() */ void flush_screen(cursor_on_u) - int cursor_on_u; +int cursor_on_u; { /* Prevent infinite loops on errors: * flush_screen->print_glyph->impossible->pline->flush_screen */ - static boolean flushing = 0; - static boolean delay_flushing = 0; - register int x,y; + static boolean flushing = 0; + static boolean delay_flushing = 0; + register int x, y; - if (cursor_on_u == -1) delay_flushing = !delay_flushing; - if (delay_flushing) return; - if (flushing) return; /* if already flushing then return */ + if (cursor_on_u == -1) + delay_flushing = !delay_flushing; + if (delay_flushing) + return; + if (flushing) + return; /* if already flushing then return */ flushing = 1; #ifdef HANGUPHANDLING - if (program_state.done_hup) return; + if (program_state.done_hup) + return; #endif for (y = 0; y < ROWNO; y++) { - register gbuf_entry *gptr = &gbuf[y][x = gbuf_start[y]]; - for (; x <= gbuf_stop[y]; gptr++, x++) - if (gptr->new) { - print_glyph(WIN_MAP,x,y,gptr->glyph); - gptr->new = 0; - } + register gbuf_entry *gptr = &gbuf[y][x = gbuf_start[y]]; + for (; x <= gbuf_stop[y]; gptr++, x++) + if (gptr->new) { + print_glyph(WIN_MAP, x, y, gptr->glyph); + gptr->new = 0; + } } - if (cursor_on_u) curs(WIN_MAP, u.ux,u.uy); /* move cursor to the hero */ + if (cursor_on_u) + curs(WIN_MAP, u.ux, u.uy); /* move cursor to the hero */ display_nhwindow(WIN_MAP, FALSE); reset_glyph_bbox(); flushing = 0; - if(context.botl || context.botlx) bot(); + if (context.botl || context.botlx) + bot(); } -/* ========================================================================= */ +/* ========================================================================= + */ /* * back_to_glyph() @@ -1431,95 +1505,130 @@ flush_screen(cursor_on_u) * variables. */ int -back_to_glyph(x,y) - xchar x,y; +back_to_glyph(x, y) +xchar x, y; { int idx; struct rm *ptr = &(levl[x][y]); switch (ptr->typ) { - case SCORR: - case STONE: - idx = level.flags.arboreal ? S_tree : S_stone; - break; - case ROOM: idx = S_room; break; - case CORR: - idx = (ptr->waslit || flags.lit_corridor) ? S_litcorr : S_corr; - break; - case HWALL: - case VWALL: - case TLCORNER: - case TRCORNER: - case BLCORNER: - case BRCORNER: - case CROSSWALL: - case TUWALL: - case TDWALL: - case TLWALL: - case TRWALL: - case SDOOR: - idx = ptr->seenv ? wall_angle(ptr) : S_stone; - break; - case DOOR: - if (ptr->doormask) { - if (ptr->doormask & D_BROKEN) - idx = S_ndoor; - else if (ptr->doormask & D_ISOPEN) - idx = (ptr->horizontal) ? S_hodoor : S_vodoor; - else /* else is closed */ - idx = (ptr->horizontal) ? S_hcdoor : S_vcdoor; - } else - idx = S_ndoor; - break; - case IRONBARS: idx = S_bars; break; - case TREE: idx = S_tree; break; - case POOL: - case MOAT: idx = S_pool; break; - case STAIRS: - idx = (ptr->ladder & LA_DOWN) ? S_dnstair : S_upstair; - break; - case LADDER: - idx = (ptr->ladder & LA_DOWN) ? S_dnladder : S_upladder; - break; - case FOUNTAIN: idx = S_fountain; break; - case SINK: idx = S_sink; break; - case ALTAR: idx = S_altar; break; - case GRAVE: idx = S_grave; break; - case THRONE: idx = S_throne; break; - case LAVAPOOL: idx = S_lava; break; - case ICE: idx = S_ice; break; - case AIR: idx = S_air; break; - case CLOUD: idx = S_cloud; break; - case WATER: idx = S_water; break; - case DBWALL: - idx = (ptr->horizontal) ? S_hcdbridge : S_vcdbridge; - break; - case DRAWBRIDGE_UP: - switch(ptr->drawbridgemask & DB_UNDER) { - case DB_MOAT: idx = S_pool; break; - case DB_LAVA: idx = S_lava; break; - case DB_ICE: idx = S_ice; break; - case DB_FLOOR: idx = S_room; break; - default: - impossible("Strange db-under: %d", - ptr->drawbridgemask & DB_UNDER); - idx = S_room; /* something is better than nothing */ - break; - } - break; - case DRAWBRIDGE_DOWN: - idx = (ptr->horizontal) ? S_hodbridge : S_vodbridge; - break; - default: - impossible("back_to_glyph: unknown level type [ = %d ]",ptr->typ); - idx = S_room; - break; + case SCORR: + case STONE: + idx = level.flags.arboreal ? S_tree : S_stone; + break; + case ROOM: + idx = S_room; + break; + case CORR: + idx = (ptr->waslit || flags.lit_corridor) ? S_litcorr : S_corr; + break; + case HWALL: + case VWALL: + case TLCORNER: + case TRCORNER: + case BLCORNER: + case BRCORNER: + case CROSSWALL: + case TUWALL: + case TDWALL: + case TLWALL: + case TRWALL: + case SDOOR: + idx = ptr->seenv ? wall_angle(ptr) : S_stone; + break; + case DOOR: + if (ptr->doormask) { + if (ptr->doormask & D_BROKEN) + idx = S_ndoor; + else if (ptr->doormask & D_ISOPEN) + idx = (ptr->horizontal) ? S_hodoor : S_vodoor; + else /* else is closed */ + idx = (ptr->horizontal) ? S_hcdoor : S_vcdoor; + } else + idx = S_ndoor; + break; + case IRONBARS: + idx = S_bars; + break; + case TREE: + idx = S_tree; + break; + case POOL: + case MOAT: + idx = S_pool; + break; + case STAIRS: + idx = (ptr->ladder & LA_DOWN) ? S_dnstair : S_upstair; + break; + case LADDER: + idx = (ptr->ladder & LA_DOWN) ? S_dnladder : S_upladder; + break; + case FOUNTAIN: + idx = S_fountain; + break; + case SINK: + idx = S_sink; + break; + case ALTAR: + idx = S_altar; + break; + case GRAVE: + idx = S_grave; + break; + case THRONE: + idx = S_throne; + break; + case LAVAPOOL: + idx = S_lava; + break; + case ICE: + idx = S_ice; + break; + case AIR: + idx = S_air; + break; + case CLOUD: + idx = S_cloud; + break; + case WATER: + idx = S_water; + break; + case DBWALL: + idx = (ptr->horizontal) ? S_hcdbridge : S_vcdbridge; + break; + case DRAWBRIDGE_UP: + switch (ptr->drawbridgemask & DB_UNDER) { + case DB_MOAT: + idx = S_pool; + break; + case DB_LAVA: + idx = S_lava; + break; + case DB_ICE: + idx = S_ice; + break; + case DB_FLOOR: + idx = S_room; + break; + default: + impossible("Strange db-under: %d", + ptr->drawbridgemask & DB_UNDER); + idx = S_room; /* something is better than nothing */ + break; + } + break; + case DRAWBRIDGE_DOWN: + idx = (ptr->horizontal) ? S_hodbridge : S_vodbridge; + break; + default: + impossible("back_to_glyph: unknown level type [ = %d ]", ptr->typ); + idx = S_room; + break; } return cmap_to_glyph(idx); } - /* * swallow_to_glyph() * @@ -1529,18 +1638,17 @@ back_to_glyph(x,y) */ STATIC_OVL int swallow_to_glyph(mnum, loc) - int mnum; - int loc; +int mnum; +int loc; { if (loc < S_sw_tl || S_sw_br < loc) { - impossible("swallow_to_glyph: bad swallow location"); - loc = S_sw_br; + impossible("swallow_to_glyph: bad swallow location"); + loc = S_sw_br; } - return ((int) (what_mon(mnum)<<3) | (loc - S_sw_tl)) + GLYPH_SWALLOW_OFF; + return ((int) (what_mon(mnum) << 3) | (loc - S_sw_tl)) + + GLYPH_SWALLOW_OFF; } - - /* * zapdir_to_glyph() * @@ -1555,19 +1663,18 @@ swallow_to_glyph(mnum, loc) */ int zapdir_to_glyph(dx, dy, beam_type) - register int dx, dy; - int beam_type; +register int dx, dy; +int beam_type; { if (beam_type >= NUM_ZAP) { - impossible("zapdir_to_glyph: illegal beam type"); - beam_type = 0; + impossible("zapdir_to_glyph: illegal beam type"); + beam_type = 0; } dx = (dx == dy) ? 2 : (dx && dy) ? 3 : dx ? 1 : 0; return ((int) ((beam_type << 2) | dx)) + GLYPH_ZAP_OFF; } - /* * Utility routine for dowhatis() used to find out the glyph displayed at * the location. This isn't necessarily the same as the glyph in the levl @@ -1575,50 +1682,47 @@ zapdir_to_glyph(dx, dy, beam_type) */ int glyph_at(x, y) - xchar x,y; +xchar x, y; { - if(x < 0 || y < 0 || x >= COLNO || y >= ROWNO) - return cmap_to_glyph(S_room); /* XXX */ + if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) + return cmap_to_glyph(S_room); /* XXX */ return gbuf[y][x].glyph; } - -/* ------------------------------------------------------------------------- */ -/* Wall Angle -------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- + */ +/* Wall Angle -------------------------------------------------------------- + */ #ifdef WA_VERBOSE static const char *FDECL(type_to_name, (int)); -static void FDECL(error4, (int,int,int,int,int,int)); +static void FDECL(error4, (int, int, int, int, int, int)); static int bad_count[MAX_TYPE]; /* count of positions flagged as bad */ static const char *type_names[MAX_TYPE] = { - "STONE", "VWALL", "HWALL", "TLCORNER", - "TRCORNER", "BLCORNER", "BRCORNER", "CROSSWALL", - "TUWALL", "TDWALL", "TLWALL", "TRWALL", - "DBWALL", "TREE", "SDOOR", "SCORR", - "POOL", "MOAT", "WATER", "DRAWBRIDGE_UP", - "LAVAPOOL", "IRON_BARS", "DOOR", "CORR", - "ROOM", "STAIRS", "LADDER", "FOUNTAIN", - "THRONE", "SINK", "GRAVE", "ALTAR", - "ICE", "DRAWBRIDGE_DOWN", "AIR", "CLOUD" + "STONE", "VWALL", "HWALL", "TLCORNER", "TRCORNER", "BLCORNER", "BRCORNER", + "CROSSWALL", "TUWALL", "TDWALL", "TLWALL", "TRWALL", "DBWALL", "TREE", + "SDOOR", "SCORR", "POOL", "MOAT", "WATER", "DRAWBRIDGE_UP", "LAVAPOOL", + "IRON_BARS", "DOOR", "CORR", "ROOM", "STAIRS", "LADDER", "FOUNTAIN", + "THRONE", "SINK", "GRAVE", "ALTAR", "ICE", "DRAWBRIDGE_DOWN", "AIR", + "CLOUD" }; - static const char * type_to_name(type) - int type; +int type; { return (type < 0 || type >= MAX_TYPE) ? "unknown" : type_names[type]; } static void error4(x, y, a, b, c, dd) - int x, y, a, b, c, dd; +int x, y, a, b, c, dd; { pline("set_wall_state: %s @ (%d,%d) %s%s%s%s", - type_to_name(levl[x][y].typ), x, y, - a ? "1":"", b ? "2":"", c ? "3":"", dd ? "4":""); + type_to_name(levl[x][y].typ), x, y, a ? "1" : "", b ? "2" : "", + c ? "3" : "", dd ? "4" : ""); bad_count[levl[x][y].typ]++; } #endif /* WA_VERBOSE */ @@ -1631,12 +1735,14 @@ error4(x, y, a, b, c, dd) */ STATIC_OVL int check_pos(x, y, which) - int x, y, which; +int x, y, which; { int type; - if (!isok(x,y)) return which; + if (!isok(x, y)) + return which; type = levl[x][y].typ; - if (IS_ROCK(type) || type == CORR || type == SCORR) return which; + if (IS_ROCK(type) || type == CORR || type == SCORR) + return which; return 0; } @@ -1645,22 +1751,23 @@ check_pos(x, y, which) #ifdef WA_VERBOSE STATIC_OVL boolean more_than_one(x, y, a, b, c) - int x, y, a, b, c; +int x, y, a, b, c; { - if ((a && (b|c)) || (b && (a|c)) || (c && (a|b))) { - error4(x,y,a,b,c,0); - return TRUE; + if ((a && (b | c)) || (b && (a | c)) || (c && (a | b))) { + error4(x, y, a, b, c, 0); + return TRUE; } return FALSE; } #else -#define more_than_one(x, y, a, b, c) (((a) && ((b)|(c))) || ((b) && ((a)|(c))) || ((c) && ((a)|(b)))) +#define more_than_one(x, y, a, b, c) \ + (((a) && ((b) | (c))) || ((b) && ((a) | (c))) || ((c) && ((a) | (b)))) #endif /* Return the wall mode for a T wall. */ STATIC_OVL int -set_twall(x0,y0, x1,y1, x2,y2, x3,y3) -int x0,y0, x1,y1, x2,y2, x3,y3; +set_twall(x0, y0, x1, y1, x2, y2, x3, y3) +int x0, y0, x1, y1, x2, y2, x3, y3; { int wmode, is_1, is_2, is_3; @@ -1668,9 +1775,9 @@ int x0,y0, x1,y1, x2,y2, x3,y3; is_2 = check_pos(x2, y2, WM_T_BL); is_3 = check_pos(x3, y3, WM_T_BR); if (more_than_one(x0, y0, is_1, is_2, is_3)) { - wmode = 0; + wmode = 0; } else { - wmode = is_1 + is_2 + is_3; + wmode = is_1 + is_2 + is_3; } return wmode; } @@ -1678,37 +1785,36 @@ int x0,y0, x1,y1, x2,y2, x3,y3; /* Return wall mode for a horizontal or vertical wall. */ STATIC_OVL int set_wall(x, y, horiz) - int x, y, horiz; +int x, y, horiz; { int wmode, is_1, is_2; if (horiz) { - is_1 = check_pos(x,y-1, WM_W_TOP); - is_2 = check_pos(x,y+1, WM_W_BOTTOM); + is_1 = check_pos(x, y - 1, WM_W_TOP); + is_2 = check_pos(x, y + 1, WM_W_BOTTOM); } else { - is_1 = check_pos(x-1,y, WM_W_LEFT); - is_2 = check_pos(x+1,y, WM_W_RIGHT); + is_1 = check_pos(x - 1, y, WM_W_LEFT); + is_2 = check_pos(x + 1, y, WM_W_RIGHT); } if (more_than_one(x, y, is_1, is_2, 0)) { - wmode = 0; + wmode = 0; } else { - wmode = is_1 + is_2; + wmode = is_1 + is_2; } return wmode; } - /* Return a wall mode for a corner wall. (x4,y4) is the "inner" position. */ STATIC_OVL int -set_corn(x1,y1, x2,y2, x3,y3, x4,y4) - int x1, y1, x2, y2, x3, y3, x4, y4; +set_corn(x1, y1, x2, y2, x3, y3, x4, y4) +int x1, y1, x2, y2, x3, y3, x4, y4; { int wmode, is_1, is_2, is_3, is_4; is_1 = check_pos(x1, y1, 1); is_2 = check_pos(x2, y2, 1); is_3 = check_pos(x3, y3, 1); - is_4 = check_pos(x4, y4, 1); /* inner location */ + is_4 = check_pos(x4, y4, 1); /* inner location */ /* * All 4 should not be true. So if the inner location is rock, @@ -1718,11 +1824,11 @@ set_corn(x1,y1, x2,y2, x3,y3, x4,y4) * by the inner section). */ if (is_4) { - wmode = WM_C_INNER; + wmode = WM_C_INNER; } else if (is_1 && is_2 && is_3) - wmode = WM_C_OUTER; - else - wmode = 0; /* finished walls on all sides */ + wmode = WM_C_OUTER; + else + wmode = 0; /* finished walls on all sides */ return wmode; } @@ -1730,35 +1836,35 @@ set_corn(x1,y1, x2,y2, x3,y3, x4,y4) /* Return mode for a crosswall. */ STATIC_OVL int set_crosswall(x, y) - int x, y; +int x, y; { int wmode, is_1, is_2, is_3, is_4; - is_1 = check_pos(x-1, y-1, 1); - is_2 = check_pos(x+1, y-1, 1); - is_3 = check_pos(x+1, y+1, 1); - is_4 = check_pos(x-1, y+1, 1); + is_1 = check_pos(x - 1, y - 1, 1); + is_2 = check_pos(x + 1, y - 1, 1); + is_3 = check_pos(x + 1, y + 1, 1); + is_4 = check_pos(x - 1, y + 1, 1); - wmode = is_1+is_2+is_3+is_4; + wmode = is_1 + is_2 + is_3 + is_4; if (wmode > 1) { - if (is_1 && is_3 && (is_2+is_4 == 0)) { - wmode = WM_X_TLBR; - } else if (is_2 && is_4 && (is_1+is_3 == 0)) { - wmode = WM_X_BLTR; - } else { + if (is_1 && is_3 && (is_2 + is_4 == 0)) { + wmode = WM_X_TLBR; + } else if (is_2 && is_4 && (is_1 + is_3 == 0)) { + wmode = WM_X_BLTR; + } else { #ifdef WA_VERBOSE - error4(x,y,is_1,is_2,is_3,is_4); + error4(x, y, is_1, is_2, is_3, is_4); #endif - wmode = 0; - } + wmode = 0; + } } else if (is_1) - wmode = WM_X_TL; + wmode = WM_X_TL; else if (is_2) - wmode = WM_X_TR; + wmode = WM_X_TR; else if (is_3) - wmode = WM_X_BR; + wmode = WM_X_BR; else if (is_4) - wmode = WM_X_BL; + wmode = WM_X_BL; return wmode; } @@ -1772,103 +1878,110 @@ set_wall_state() struct rm *lev; #ifdef WA_VERBOSE - for (x = 0; x < MAX_TYPE; x++) bad_count[x] = 0; + for (x = 0; x < MAX_TYPE; x++) + bad_count[x] = 0; #endif for (x = 0; x < COLNO; x++) - for (lev = &levl[x][0], y = 0; y < ROWNO; y++, lev++) { - switch (lev->typ) { - case SDOOR: - wmode = set_wall(x, y, (int) lev->horizontal); - break; - case VWALL: - wmode = set_wall(x, y, 0); - break; - case HWALL: - wmode = set_wall(x, y, 1); - break; - case TDWALL: - wmode = set_twall(x,y, x,y-1, x-1,y+1, x+1,y+1); - break; - case TUWALL: - wmode = set_twall(x,y, x,y+1, x+1,y-1, x-1,y-1); - break; - case TLWALL: - wmode = set_twall(x,y, x+1,y, x-1,y-1, x-1,y+1); - break; - case TRWALL: - wmode = set_twall(x,y, x-1,y, x+1,y+1, x+1,y-1); - break; - case TLCORNER: - wmode = set_corn(x-1,y-1, x,y-1, x-1,y, x+1,y+1); - break; - case TRCORNER: - wmode = set_corn(x,y-1, x+1,y-1, x+1,y, x-1,y+1); - break; - case BLCORNER: - wmode = set_corn(x,y+1, x-1,y+1, x-1,y, x+1,y-1); - break; - case BRCORNER: - wmode = set_corn(x+1,y, x+1,y+1, x,y+1, x-1,y-1); - break; - case CROSSWALL: - wmode = set_crosswall(x, y); - break; + for (lev = &levl[x][0], y = 0; y < ROWNO; y++, lev++) { + switch (lev->typ) { + case SDOOR: + wmode = set_wall(x, y, (int) lev->horizontal); + break; + case VWALL: + wmode = set_wall(x, y, 0); + break; + case HWALL: + wmode = set_wall(x, y, 1); + break; + case TDWALL: + wmode = set_twall(x, y, x, y - 1, x - 1, y + 1, x + 1, y + 1); + break; + case TUWALL: + wmode = set_twall(x, y, x, y + 1, x + 1, y - 1, x - 1, y - 1); + break; + case TLWALL: + wmode = set_twall(x, y, x + 1, y, x - 1, y - 1, x - 1, y + 1); + break; + case TRWALL: + wmode = set_twall(x, y, x - 1, y, x + 1, y + 1, x + 1, y - 1); + break; + case TLCORNER: + wmode = + set_corn(x - 1, y - 1, x, y - 1, x - 1, y, x + 1, y + 1); + break; + case TRCORNER: + wmode = + set_corn(x, y - 1, x + 1, y - 1, x + 1, y, x - 1, y + 1); + break; + case BLCORNER: + wmode = + set_corn(x, y + 1, x - 1, y + 1, x - 1, y, x + 1, y - 1); + break; + case BRCORNER: + wmode = + set_corn(x + 1, y, x + 1, y + 1, x, y + 1, x - 1, y - 1); + break; + case CROSSWALL: + wmode = set_crosswall(x, y); + break; - default: - wmode = -1; /* don't set wall info */ - break; - } + default: + wmode = -1; /* don't set wall info */ + break; + } - if (wmode >= 0) - lev->wall_info = (lev->wall_info & ~WM_MASK) | wmode; - } + if (wmode >= 0) + lev->wall_info = (lev->wall_info & ~WM_MASK) | wmode; + } #ifdef WA_VERBOSE /* check if any bad positions found */ for (x = y = 0; x < MAX_TYPE; x++) - if (bad_count[x]) { - if (y == 0) { - y = 1; /* only print once */ - pline("set_wall_type: wall mode problems with: "); - } - pline("%s %d;", type_names[x], bad_count[x]); - } + if (bad_count[x]) { + if (y == 0) { + y = 1; /* only print once */ + pline("set_wall_type: wall mode problems with: "); + } + pline("%s %d;", type_names[x], bad_count[x]); + } #endif /* WA_VERBOSE */ } -/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- + */ /* This matrix is used here and in vision.c. */ -unsigned char seenv_matrix[3][3] = { {SV2, SV1, SV0}, - {SV3, SVALL, SV7}, - {SV4, SV5, SV6} }; +unsigned char seenv_matrix[3][3] = { { SV2, SV1, SV0 }, + { SV3, SVALL, SV7 }, + { SV4, SV5, SV6 } }; #define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0)) /* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */ STATIC_OVL void set_seenv(lev, x0, y0, x, y) - struct rm *lev; - int x0, y0, x, y; /* from, to */ +struct rm *lev; +int x0, y0, x, y; /* from, to */ { - int dx = x-x0, dy = y0-y; + int dx = x - x0, dy = y0 - y; - lev->seenv |= seenv_matrix[sign(dy)+1][sign(dx)+1]; + lev->seenv |= seenv_matrix[sign(dy) + 1][sign(dx) + 1]; } /* Called by blackout(vault.c) when vault guard removes temporary corridor, turning spot back into stone; is an adjacent spot. */ void unset_seenv(lev, x0, y0, x1, y1) - struct rm *lev; /* &levl[x1][y1] */ - int x0, y0, x1, y1; /* from, to; abs(x1-x0)==1 && abs(y0-y1)==1 */ +struct rm *lev; /* &levl[x1][y1] */ +int x0, y0, x1, y1; /* from, to; abs(x1-x0)==1 && abs(y0-y1)==1 */ { int dx = x1 - x0, dy = y0 - y1; lev->seenv &= ~seenv_matrix[dy + 1][dx + 1]; } -/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- + */ /* T wall types, one for each row in wall_matrix[][]. */ #define T_d 0 @@ -1883,21 +1996,21 @@ unset_seenv(lev, x0, y0, x1, y1) * correct result for the original wall by using different rows for * each of the wall types. */ -#define T_stone 0 +#define T_stone 0 #define T_tlcorn 1 #define T_trcorn 2 -#define T_hwall 3 +#define T_hwall 3 #define T_tdwall 4 static const int wall_matrix[4][5] = { - { S_stone, S_tlcorn, S_trcorn, S_hwall, S_tdwall }, /* tdwall */ - { S_stone, S_trcorn, S_brcorn, S_vwall, S_tlwall }, /* tlwall */ - { S_stone, S_brcorn, S_blcorn, S_hwall, S_tuwall }, /* tuwall */ - { S_stone, S_blcorn, S_tlcorn, S_vwall, S_trwall }, /* trwall */ + { S_stone, S_tlcorn, S_trcorn, S_hwall, S_tdwall }, /* tdwall */ + { S_stone, S_trcorn, S_brcorn, S_vwall, S_tlwall }, /* tlwall */ + { S_stone, S_brcorn, S_blcorn, S_hwall, S_tuwall }, /* tuwall */ + { S_stone, S_blcorn, S_tlcorn, S_vwall, S_trwall }, /* trwall */ }; - -/* Cross wall types, one for each "solid" quarter. Rows of cross_matrix[][]. */ +/* Cross wall types, one for each "solid" quarter. Rows of cross_matrix[][]. + */ #define C_bl 0 #define C_tl 1 #define C_tr 2 @@ -1924,25 +2037,28 @@ static const int cross_matrix[4][6] = { { S_trcorn, S_brcorn, S_blcorn, S_tlwall, S_tuwall, S_crwall }, }; - /* Print out a T wall warning and all interesting info. */ STATIC_OVL void t_warn(lev) - struct rm *lev; +struct rm *lev; { static const char warn_str[] = "wall_angle: %s: case %d: seenv = 0x%x"; const char *wname; - if (lev->typ == TUWALL) wname = "tuwall"; - else if (lev->typ == TLWALL) wname = "tlwall"; - else if (lev->typ == TRWALL) wname = "trwall"; - else if (lev->typ == TDWALL) wname = "tdwall"; - else wname = "unknown"; + if (lev->typ == TUWALL) + wname = "tuwall"; + else if (lev->typ == TLWALL) + wname = "tlwall"; + else if (lev->typ == TRWALL) + wname = "trwall"; + else if (lev->typ == TDWALL) + wname = "tdwall"; + else + wname = "unknown"; impossible(warn_str, wname, lev->wall_info & WM_MASK, - (unsigned int) lev->seenv); + (unsigned int) lev->seenv); } - /* * Return the correct graphics character index using wall type, wall mode, * and the seen vector. It is expected that seenv is non zero. @@ -1957,62 +2073,62 @@ t_warn(lev) */ STATIC_OVL int wall_angle(lev) - struct rm *lev; +struct rm *lev; { register unsigned int seenv = lev->seenv & 0xff; const int *row; int col, idx; -#define only(sv, bits) (((sv) & (bits)) && ! ((sv) & ~(bits))) +#define only(sv, bits) (((sv) & (bits)) && !((sv) & ~(bits))) switch (lev->typ) { - case TUWALL: - row = wall_matrix[T_u]; - seenv = (seenv >> 4 | seenv << 4) & 0xff;/* rotate to tdwall */ - goto do_twall; - case TLWALL: - row = wall_matrix[T_l]; - seenv = (seenv >> 2 | seenv << 6) & 0xff;/* rotate to tdwall */ - goto do_twall; - case TRWALL: - row = wall_matrix[T_r]; - seenv = (seenv >> 6 | seenv << 2) & 0xff;/* rotate to tdwall */ - goto do_twall; - case TDWALL: - row = wall_matrix[T_d]; -do_twall: - switch (lev->wall_info & WM_MASK) { - case 0: - if (seenv == SV4) { - col = T_tlcorn; - } else if (seenv == SV6) { - col = T_trcorn; - } else if (seenv & (SV3|SV5|SV7) || - ((seenv & SV4) && (seenv & SV6))) { - col = T_tdwall; - } else if (seenv & (SV0|SV1|SV2)) { - col = (seenv & (SV4|SV6) ? T_tdwall : T_hwall); - } else { - t_warn(lev); - col = T_stone; - } - break; - case WM_T_LONG: - if (seenv & (SV3|SV4) && !(seenv & (SV5|SV6|SV7))) { - col = T_tlcorn; - } else if (seenv&(SV6|SV7) && !(seenv&(SV3|SV4|SV5))) { - col = T_trcorn; - } else if ((seenv & SV5) || - ((seenv & (SV3|SV4)) && (seenv & (SV6|SV7)))) { - col = T_tdwall; - } else { - /* only SV0|SV1|SV2 */ - if (! only(seenv, SV0|SV1|SV2) ) - t_warn(lev); - col = T_stone; - } - break; - case WM_T_BL: -#if 0 /* older method, fixed */ + case TUWALL: + row = wall_matrix[T_u]; + seenv = (seenv >> 4 | seenv << 4) & 0xff; /* rotate to tdwall */ + goto do_twall; + case TLWALL: + row = wall_matrix[T_l]; + seenv = (seenv >> 2 | seenv << 6) & 0xff; /* rotate to tdwall */ + goto do_twall; + case TRWALL: + row = wall_matrix[T_r]; + seenv = (seenv >> 6 | seenv << 2) & 0xff; /* rotate to tdwall */ + goto do_twall; + case TDWALL: + row = wall_matrix[T_d]; + do_twall: + switch (lev->wall_info & WM_MASK) { + case 0: + if (seenv == SV4) { + col = T_tlcorn; + } else if (seenv == SV6) { + col = T_trcorn; + } else if (seenv & (SV3 | SV5 | SV7) + || ((seenv & SV4) && (seenv & SV6))) { + col = T_tdwall; + } else if (seenv & (SV0 | SV1 | SV2)) { + col = (seenv & (SV4 | SV6) ? T_tdwall : T_hwall); + } else { + t_warn(lev); + col = T_stone; + } + break; + case WM_T_LONG: + if (seenv & (SV3 | SV4) && !(seenv & (SV5 | SV6 | SV7))) { + col = T_tlcorn; + } else if (seenv & (SV6 | SV7) && !(seenv & (SV3 | SV4 | SV5))) { + col = T_trcorn; + } else if ((seenv & SV5) + || ((seenv & (SV3 | SV4)) && (seenv & (SV6 | SV7)))) { + col = T_tdwall; + } else { + /* only SV0|SV1|SV2 */ + if (!only(seenv, SV0 | SV1 | SV2)) + t_warn(lev); + col = T_stone; + } + break; + case WM_T_BL: +#if 0 /* older method, fixed */ if (only(seenv, SV4|SV5)) { col = T_tlcorn; } else if ((seenv & (SV0|SV1|SV2)) && @@ -2026,19 +2142,19 @@ do_twall: t_warn(lev); col = T_stone; } -#endif /* 0 */ - if (only(seenv, SV4|SV5)) - col = T_tlcorn; - else if ((seenv & (SV0|SV1|SV2|SV7)) && - !(seenv & (SV3|SV4|SV5))) - col = T_hwall; - else if (only(seenv, SV6)) - col = T_stone; - else - col = T_tdwall; - break; - case WM_T_BR: -#if 0 /* older method, fixed */ +#endif /* 0 */ + if (only(seenv, SV4 | SV5)) + col = T_tlcorn; + else if ((seenv & (SV0 | SV1 | SV2 | SV7)) + && !(seenv & (SV3 | SV4 | SV5))) + col = T_hwall; + else if (only(seenv, SV6)) + col = T_stone; + else + col = T_tdwall; + break; + case WM_T_BR: +#if 0 /* older method, fixed */ if (only(seenv, SV5|SV6)) { col = T_trcorn; } else if ((seenv & (SV0|SV1|SV2)) && @@ -2052,199 +2168,208 @@ do_twall: t_warn(lev); col = T_stone; } -#endif /* 0 */ - if (only(seenv, SV5|SV6)) - col = T_trcorn; - else if ((seenv & (SV0|SV1|SV2|SV3)) && - !(seenv & (SV5|SV6|SV7))) - col = T_hwall; - else if (only(seenv, SV4)) - col = T_stone; - else - col = T_tdwall; +#endif /* 0 */ + if (only(seenv, SV5 | SV6)) + col = T_trcorn; + else if ((seenv & (SV0 | SV1 | SV2 | SV3)) + && !(seenv & (SV5 | SV6 | SV7))) + col = T_hwall; + else if (only(seenv, SV4)) + col = T_stone; + else + col = T_tdwall; - break; - default: - impossible("wall_angle: unknown T wall mode %d", - lev->wall_info & WM_MASK); - col = T_stone; - break; - } - idx = row[col]; - break; + break; + default: + impossible("wall_angle: unknown T wall mode %d", + lev->wall_info & WM_MASK); + col = T_stone; + break; + } + idx = row[col]; + break; - case SDOOR: - if (lev->horizontal) goto horiz; - /* fall through */ - case VWALL: - switch (lev->wall_info & WM_MASK) { - case 0: idx = seenv ? S_vwall : S_stone; break; - case 1: idx = seenv & (SV1|SV2|SV3|SV4|SV5) ? S_vwall : - S_stone; - break; - case 2: idx = seenv & (SV0|SV1|SV5|SV6|SV7) ? S_vwall : - S_stone; - break; - default: - impossible("wall_angle: unknown vwall mode %d", - lev->wall_info & WM_MASK); - idx = S_stone; - break; - } - break; + case SDOOR: + if (lev->horizontal) + goto horiz; + /* fall through */ + case VWALL: + switch (lev->wall_info & WM_MASK) { + case 0: + idx = seenv ? S_vwall : S_stone; + break; + case 1: + idx = seenv & (SV1 | SV2 | SV3 | SV4 | SV5) ? S_vwall : S_stone; + break; + case 2: + idx = seenv & (SV0 | SV1 | SV5 | SV6 | SV7) ? S_vwall : S_stone; + break; + default: + impossible("wall_angle: unknown vwall mode %d", + lev->wall_info & WM_MASK); + idx = S_stone; + break; + } + break; - case HWALL: -horiz: - switch (lev->wall_info & WM_MASK) { - case 0: idx = seenv ? S_hwall : S_stone; break; - case 1: idx = seenv & (SV3|SV4|SV5|SV6|SV7) ? S_hwall : - S_stone; - break; - case 2: idx = seenv & (SV0|SV1|SV2|SV3|SV7) ? S_hwall : - S_stone; - break; - default: - impossible("wall_angle: unknown hwall mode %d", - lev->wall_info & WM_MASK); - idx = S_stone; - break; - } - break; + case HWALL: + horiz: + switch (lev->wall_info & WM_MASK) { + case 0: + idx = seenv ? S_hwall : S_stone; + break; + case 1: + idx = seenv & (SV3 | SV4 | SV5 | SV6 | SV7) ? S_hwall : S_stone; + break; + case 2: + idx = seenv & (SV0 | SV1 | SV2 | SV3 | SV7) ? S_hwall : S_stone; + break; + default: + impossible("wall_angle: unknown hwall mode %d", + lev->wall_info & WM_MASK); + idx = S_stone; + break; + } + break; -#define set_corner(idx, lev, which, outer, inner, name) \ - switch ((lev)->wall_info & WM_MASK) { \ - case 0: idx = which; break; \ - case WM_C_OUTER: idx = seenv & (outer) ? which : S_stone; break; \ - case WM_C_INNER: idx = seenv & ~(inner) ? which : S_stone; break; \ - default: \ - impossible("wall_angle: unknown %s mode %d", name, \ - (lev)->wall_info & WM_MASK); \ - idx = S_stone; \ - break; \ +#define set_corner(idx, lev, which, outer, inner, name) \ + switch ((lev)->wall_info & WM_MASK) { \ + case 0: \ + idx = which; \ + break; \ + case WM_C_OUTER: \ + idx = seenv & (outer) ? which : S_stone; \ + break; \ + case WM_C_INNER: \ + idx = seenv & ~(inner) ? which : S_stone; \ + break; \ + default: \ + impossible("wall_angle: unknown %s mode %d", name, \ + (lev)->wall_info &WM_MASK); \ + idx = S_stone; \ + break; \ } - case TLCORNER: - set_corner(idx, lev, S_tlcorn, (SV3|SV4|SV5), SV4, "tlcorn"); - break; - case TRCORNER: - set_corner(idx, lev, S_trcorn, (SV5|SV6|SV7), SV6, "trcorn"); - break; - case BLCORNER: - set_corner(idx, lev, S_blcorn, (SV1|SV2|SV3), SV2, "blcorn"); - break; - case BRCORNER: - set_corner(idx, lev, S_brcorn, (SV7|SV0|SV1), SV0, "brcorn"); - break; + case TLCORNER: + set_corner(idx, lev, S_tlcorn, (SV3 | SV4 | SV5), SV4, "tlcorn"); + break; + case TRCORNER: + set_corner(idx, lev, S_trcorn, (SV5 | SV6 | SV7), SV6, "trcorn"); + break; + case BLCORNER: + set_corner(idx, lev, S_blcorn, (SV1 | SV2 | SV3), SV2, "blcorn"); + break; + case BRCORNER: + set_corner(idx, lev, S_brcorn, (SV7 | SV0 | SV1), SV0, "brcorn"); + break; + case CROSSWALL: + switch (lev->wall_info & WM_MASK) { + case 0: + if (seenv == SV0) + idx = S_brcorn; + else if (seenv == SV2) + idx = S_blcorn; + else if (seenv == SV4) + idx = S_tlcorn; + else if (seenv == SV6) + idx = S_trcorn; + else if (!(seenv & ~(SV0 | SV1 | SV2)) + && (seenv & SV1 || seenv == (SV0 | SV2))) + idx = S_tuwall; + else if (!(seenv & ~(SV2 | SV3 | SV4)) + && (seenv & SV3 || seenv == (SV2 | SV4))) + idx = S_trwall; + else if (!(seenv & ~(SV4 | SV5 | SV6)) + && (seenv & SV5 || seenv == (SV4 | SV6))) + idx = S_tdwall; + else if (!(seenv & ~(SV0 | SV6 | SV7)) + && (seenv & SV7 || seenv == (SV0 | SV6))) + idx = S_tlwall; + else + idx = S_crwall; + break; - case CROSSWALL: - switch (lev->wall_info & WM_MASK) { - case 0: - if (seenv == SV0) - idx = S_brcorn; - else if (seenv == SV2) - idx = S_blcorn; - else if (seenv == SV4) - idx = S_tlcorn; - else if (seenv == SV6) - idx = S_trcorn; - else if (!(seenv & ~(SV0|SV1|SV2)) && - (seenv & SV1 || seenv == (SV0|SV2))) - idx = S_tuwall; - else if (!(seenv & ~(SV2|SV3|SV4)) && - (seenv & SV3 || seenv == (SV2|SV4))) - idx = S_trwall; - else if (!(seenv & ~(SV4|SV5|SV6)) && - (seenv & SV5 || seenv == (SV4|SV6))) - idx = S_tdwall; - else if (!(seenv & ~(SV0|SV6|SV7)) && - (seenv & SV7 || seenv == (SV0|SV6))) - idx = S_tlwall; - else - idx = S_crwall; - break; + case WM_X_TL: + row = cross_matrix[C_tl]; + seenv = (seenv >> 4 | seenv << 4) & 0xff; + goto do_crwall; + case WM_X_TR: + row = cross_matrix[C_tr]; + seenv = (seenv >> 6 | seenv << 2) & 0xff; + goto do_crwall; + case WM_X_BL: + row = cross_matrix[C_bl]; + seenv = (seenv >> 2 | seenv << 6) & 0xff; + goto do_crwall; + case WM_X_BR: + row = cross_matrix[C_br]; + do_crwall: + if (seenv == SV4) + idx = S_stone; + else { + seenv = seenv & ~SV4; /* strip SV4 */ + if (seenv == SV0) { + col = C_brcorn; + } else if (seenv & (SV2 | SV3)) { + if (seenv & (SV5 | SV6 | SV7)) + col = C_crwall; + else if (seenv & (SV0 | SV1)) + col = C_tuwall; + else + col = C_blcorn; + } else if (seenv & (SV5 | SV6)) { + if (seenv & (SV1 | SV2 | SV3)) + col = C_crwall; + else if (seenv & (SV0 | SV7)) + col = C_tlwall; + else + col = C_trcorn; + } else if (seenv & SV1) { + col = seenv & SV7 ? C_crwall : C_tuwall; + } else if (seenv & SV7) { + col = seenv & SV1 ? C_crwall : C_tlwall; + } else { + impossible("wall_angle: bottom of crwall check"); + col = C_crwall; + } - case WM_X_TL: - row = cross_matrix[C_tl]; - seenv = (seenv >> 4 | seenv << 4) & 0xff; - goto do_crwall; - case WM_X_TR: - row = cross_matrix[C_tr]; - seenv = (seenv >> 6 | seenv << 2) & 0xff; - goto do_crwall; - case WM_X_BL: - row = cross_matrix[C_bl]; - seenv = (seenv >> 2 | seenv << 6) & 0xff; - goto do_crwall; - case WM_X_BR: - row = cross_matrix[C_br]; -do_crwall: - if (seenv == SV4) - idx = S_stone; - else { - seenv = seenv & ~SV4; /* strip SV4 */ - if (seenv == SV0) { - col = C_brcorn; - } else if (seenv & (SV2|SV3)) { - if (seenv & (SV5|SV6|SV7)) - col = C_crwall; - else if (seenv & (SV0|SV1)) - col = C_tuwall; - else - col = C_blcorn; - } else if (seenv & (SV5|SV6)) { - if (seenv & (SV1|SV2|SV3)) - col = C_crwall; - else if (seenv & (SV0|SV7)) - col = C_tlwall; - else - col = C_trcorn; - } else if (seenv & SV1) { - col = seenv & SV7 ? C_crwall : C_tuwall; - } else if (seenv & SV7) { - col = seenv & SV1 ? C_crwall : C_tlwall; - } else { - impossible( - "wall_angle: bottom of crwall check"); - col = C_crwall; - } + idx = row[col]; + } + break; - idx = row[col]; - } - break; + case WM_X_TLBR: + if (only(seenv, SV1 | SV2 | SV3)) + idx = S_blcorn; + else if (only(seenv, SV5 | SV6 | SV7)) + idx = S_trcorn; + else if (only(seenv, SV0 | SV4)) + idx = S_stone; + else + idx = S_crwall; + break; - case WM_X_TLBR: - if ( only(seenv, SV1|SV2|SV3) ) - idx = S_blcorn; - else if ( only(seenv, SV5|SV6|SV7) ) - idx = S_trcorn; - else if ( only(seenv, SV0|SV4) ) - idx = S_stone; - else - idx = S_crwall; - break; + case WM_X_BLTR: + if (only(seenv, SV0 | SV1 | SV7)) + idx = S_brcorn; + else if (only(seenv, SV3 | SV4 | SV5)) + idx = S_tlcorn; + else if (only(seenv, SV2 | SV6)) + idx = S_stone; + else + idx = S_crwall; + break; - case WM_X_BLTR: - if ( only(seenv, SV0|SV1|SV7) ) - idx = S_brcorn; - else if ( only(seenv, SV3|SV4|SV5) ) - idx = S_tlcorn; - else if ( only(seenv, SV2|SV6) ) - idx = S_stone; - else - idx = S_crwall; - break; + default: + impossible("wall_angle: unknown crosswall mode"); + idx = S_stone; + break; + } + break; - default: - impossible("wall_angle: unknown crosswall mode"); - idx = S_stone; - break; - } - break; - - default: - impossible("wall_angle: unexpected wall type %d", lev->typ); - idx = S_stone; + default: + impossible("wall_angle: unexpected wall type %d", lev->typ); + idx = S_stone; } return idx; } diff --git a/src/dlb.c b/src/dlb.c index 0a1ab10c1..7acdb25b7 100644 --- a/src/dlb.c +++ b/src/dlb.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dlb.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dlb.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 dlb.c $Date: 2012/02/16 03:01:37 $ $Revision: 1.10 $ */ /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */ /* NetHack may be freely redistributed. See license for details. */ @@ -13,12 +13,12 @@ #define DATAPREFIX 4 #if defined(OVERLAY) -# define STATIC_DCL extern -# define STATIC_OVL -#else /* !OVERLAY */ -# define STATIC_DCL static -# define STATIC_OVL static -#endif /* OVERLAY */ +#define STATIC_DCL extern +#define STATIC_OVL +#else /* !OVERLAY */ +#define STATIC_DCL static +#define STATIC_OVL static +#endif /* OVERLAY */ #ifdef DLB /* @@ -30,17 +30,17 @@ typedef struct dlb_procs { boolean NDECL((*dlb_init_proc)); void NDECL((*dlb_cleanup_proc)); - boolean FDECL((*dlb_fopen_proc), (DLB_P,const char *,const char *)); + boolean FDECL((*dlb_fopen_proc), (DLB_P, const char *, const char *)); int FDECL((*dlb_fclose_proc), (DLB_P)); - int FDECL((*dlb_fread_proc), (char *,int,int,DLB_P)); - int FDECL((*dlb_fseek_proc), (DLB_P,long,int)); - char *FDECL((*dlb_fgets_proc), (char *,int,DLB_P)); + int FDECL((*dlb_fread_proc), (char *, int, int, DLB_P)); + int FDECL((*dlb_fseek_proc), (DLB_P, long, int)); + char *FDECL((*dlb_fgets_proc), (char *, int, DLB_P)); int FDECL((*dlb_fgetc_proc), (DLB_P)); long FDECL((*dlb_ftell_proc), (DLB_P)); } dlb_procs_t; /* without extern.h via hack.h, these haven't been declared for us */ -extern FILE *FDECL(fopen_datafile, (const char *,const char *,int)); +extern FILE *FDECL(fopen_datafile, (const char *, const char *, int)); #ifdef DLBLIB /* @@ -62,28 +62,26 @@ extern FILE *FDECL(fopen_datafile, (const char *,const char *,int)); #define MAX_LIBS 4 static library dlb_libs[MAX_LIBS]; -STATIC_DCL boolean FDECL(readlibdir,(library *lp)); -STATIC_DCL boolean FDECL(find_file,(const char *name, library **lib, long *startp, - long *sizep)); +STATIC_DCL boolean FDECL(readlibdir, (library * lp)); +STATIC_DCL boolean FDECL(find_file, (const char *name, library **lib, + long *startp, long *sizep)); STATIC_DCL boolean NDECL(lib_dlb_init); STATIC_DCL void NDECL(lib_dlb_cleanup); -STATIC_DCL boolean FDECL(lib_dlb_fopen,(dlb *, const char *, const char *)); -STATIC_DCL int FDECL(lib_dlb_fclose,(dlb *)); -STATIC_DCL int FDECL(lib_dlb_fread,(char *, int, int, dlb *)); -STATIC_DCL int FDECL(lib_dlb_fseek,(dlb *, long, int)); -STATIC_DCL char *FDECL(lib_dlb_fgets,(char *, int, dlb *)); -STATIC_DCL int FDECL(lib_dlb_fgetc,(dlb *)); -STATIC_DCL long FDECL(lib_dlb_ftell,(dlb *)); +STATIC_DCL boolean FDECL(lib_dlb_fopen, (dlb *, const char *, const char *)); +STATIC_DCL int FDECL(lib_dlb_fclose, (dlb *)); +STATIC_DCL int FDECL(lib_dlb_fread, (char *, int, int, dlb *)); +STATIC_DCL int FDECL(lib_dlb_fseek, (dlb *, long, int)); +STATIC_DCL char *FDECL(lib_dlb_fgets, (char *, int, dlb *)); +STATIC_DCL int FDECL(lib_dlb_fgetc, (dlb *)); +STATIC_DCL long FDECL(lib_dlb_ftell, (dlb *)); /* not static because shared with dlb_main.c */ -boolean FDECL(open_library,(const char *lib_name, library *lp)); -void FDECL(close_library,(library *lp)); +boolean FDECL(open_library, (const char *lib_name, library *lp)); +void FDECL(close_library, (library * lp)); /* without extern.h via hack.h, these haven't been declared for us */ extern char *FDECL(eos, (char *)); - - /* * Read the directory out of the library. Return 1 if successful, * 0 if it failed. @@ -116,8 +114,8 @@ extern char *FDECL(eos, (char *)); * * followed by the contents of the files */ -#define DLB_MIN_VERS 1 /* min library version readable by this code */ -#define DLB_MAX_VERS 1 /* max library version readable by this code */ +#define DLB_MIN_VERS 1 /* min library version readable by this code */ +#define DLB_MAX_VERS 1 /* max library version readable by this code */ /* * Read the directory from the library file. This will allocate and @@ -128,43 +126,44 @@ extern char *FDECL(eos, (char *)); */ STATIC_OVL boolean readlibdir(lp) - library *lp; /* library pointer to fill in */ +library *lp; /* library pointer to fill in */ { int i; char *sp; long liboffset, totalsize; - if (fscanf(lp->fdata, "%ld %ld %ld %ld %ld\n", - &lp->rev,&lp->nentries,&lp->strsize,&liboffset,&totalsize) != 5) - return FALSE; - if (lp->rev > DLB_MAX_VERS || lp->rev < DLB_MIN_VERS) return FALSE; + if (fscanf(lp->fdata, "%ld %ld %ld %ld %ld\n", &lp->rev, &lp->nentries, + &lp->strsize, &liboffset, &totalsize) != 5) + return FALSE; + if (lp->rev > DLB_MAX_VERS || lp->rev < DLB_MIN_VERS) + return FALSE; lp->dir = (libdir *) alloc(lp->nentries * sizeof(libdir)); lp->sspace = (char *) alloc(lp->strsize); /* read in each directory entry */ for (i = 0, sp = lp->sspace; i < lp->nentries; i++) { - lp->dir[i].fname = sp; - if (fscanf(lp->fdata, "%c%s %ld\n", - &lp->dir[i].handling, sp, &lp->dir[i].foffset) != 3) { - free((genericptr_t) lp->dir); - free((genericptr_t) lp->sspace); - lp->dir = (libdir *) 0; - lp->sspace = (char *) 0; - return FALSE; - } - sp = eos(sp) + 1; + lp->dir[i].fname = sp; + if (fscanf(lp->fdata, "%c%s %ld\n", &lp->dir[i].handling, sp, + &lp->dir[i].foffset) != 3) { + free((genericptr_t) lp->dir); + free((genericptr_t) lp->sspace); + lp->dir = (libdir *) 0; + lp->sspace = (char *) 0; + return FALSE; + } + sp = eos(sp) + 1; } /* calculate file sizes using offset information */ for (i = 0; i < lp->nentries; i++) { - if (i == lp->nentries - 1) - lp->dir[i].fsize = totalsize - lp->dir[i].foffset; - else - lp->dir[i].fsize = lp->dir[i+1].foffset - lp->dir[i].foffset; + if (i == lp->nentries - 1) + lp->dir[i].fsize = totalsize - lp->dir[i].foffset; + else + lp->dir[i].fsize = lp->dir[i + 1].foffset - lp->dir[i].foffset; } - (void) fseek(lp->fdata, 0L, SEEK_SET); /* reset back to zero */ + (void) fseek(lp->fdata, 0L, SEEK_SET); /* reset back to zero */ lp->fmark = 0; return TRUE; @@ -176,23 +175,23 @@ readlibdir(lp) */ STATIC_OVL boolean find_file(name, lib, startp, sizep) - const char *name; - library **lib; - long *startp, *sizep; +const char *name; +library **lib; +long *startp, *sizep; { int i, j; library *lp; for (i = 0; i < MAX_LIBS && dlb_libs[i].fdata; i++) { - lp = &dlb_libs[i]; - for (j = 0; j < lp->nentries; j++) { - if (FILENAME_CMP(name, lp->dir[j].fname) == 0) { - *lib = lp; - *startp = lp->dir[j].foffset; - *sizep = lp->dir[j].fsize; - return TRUE; - } - } + lp = &dlb_libs[i]; + for (j = 0; j < lp->nentries; j++) { + if (FILENAME_CMP(name, lp->dir[j].fname) == 0) { + *lib = lp; + *startp = lp->dir[j].foffset; + *sizep = lp->dir[j].fsize; + return TRUE; + } + } } *lib = (library *) 0; *startp = *sizep = 0; @@ -205,32 +204,32 @@ find_file(name, lib, startp, sizep) */ boolean open_library(lib_name, lp) - const char *lib_name; - library *lp; +const char *lib_name; +library *lp; { boolean status = FALSE; lp->fdata = fopen_datafile(lib_name, RDBMODE, DATAPREFIX); if (lp->fdata) { - if (readlibdir(lp)) { - status = TRUE; - } else { - (void) fclose(lp->fdata); - lp->fdata = (FILE *) 0; - } + if (readlibdir(lp)) { + status = TRUE; + } else { + (void) fclose(lp->fdata); + lp->fdata = (FILE *) 0; + } } return status; } void close_library(lp) - library *lp; +library *lp; { (void) fclose(lp->fdata); free((genericptr_t) lp->dir); free((genericptr_t) lp->sspace); - (void) memset((char *)lp, 0, sizeof(library)); + (void) memset((char *) lp, 0, sizeof(library)); } /* @@ -241,14 +240,15 @@ STATIC_OVL boolean lib_dlb_init(VOID_ARGS) { /* zero out array */ - (void) memset((char *)&dlb_libs[0], 0, sizeof(dlb_libs)); + (void) memset((char *) &dlb_libs[0], 0, sizeof(dlb_libs)); /* To open more than one library, add open library calls here. */ - if (!open_library(DLBFILE, &dlb_libs[0])) return FALSE; + if (!open_library(DLBFILE, &dlb_libs[0])) + return FALSE; #ifdef DLBFILE2 - if (!open_library(DLBFILE2, &dlb_libs[1])) { - close_library(&dlb_libs[0]); - return FALSE; + if (!open_library(DLBFILE2, &dlb_libs[1])) { + close_library(&dlb_libs[0]); + return FALSE; } #endif return TRUE; @@ -261,35 +261,35 @@ lib_dlb_cleanup(VOID_ARGS) /* close the data file(s) */ for (i = 0; i < MAX_LIBS && dlb_libs[i].fdata; i++) - close_library(&dlb_libs[i]); + close_library(&dlb_libs[i]); } /*ARGSUSED*/ STATIC_OVL boolean lib_dlb_fopen(dp, name, mode) - dlb *dp; - const char *name; - const char *mode UNUSED; +dlb *dp; +const char *name; +const char *mode UNUSED; { long start, size; library *lp; /* look up file in directory */ if (find_file(name, &lp, &start, &size)) { - dp->lib = lp; - dp->start = start; - dp->size = size; - dp->mark = 0; - return TRUE; + dp->lib = lp; + dp->start = start; + dp->size = size; + dp->mark = 0; + return TRUE; } - return FALSE; /* failed */ + return FALSE; /* failed */ } /*ARGUSED*/ STATIC_OVL int lib_dlb_fclose(dp) - dlb *dp UNUSED; +dlb *dp UNUSED; { /* nothing needs to be done */ return 0; @@ -297,21 +297,22 @@ lib_dlb_fclose(dp) STATIC_OVL int lib_dlb_fread(buf, size, quan, dp) - char *buf; - int size, quan; - dlb *dp; +char *buf; +int size, quan; +dlb *dp; { long pos, nread, nbytes; /* make sure we don't read into the next file */ if ((dp->size - dp->mark) < (size * quan)) - quan = (dp->size - dp->mark) / size; - if (quan == 0) return 0; + quan = (dp->size - dp->mark) / size; + if (quan == 0) + return 0; pos = dp->start + dp->mark; if (dp->lib->fmark != pos) { - fseek(dp->lib->fdata, pos, SEEK_SET); /* check for error??? */ - dp->lib->fmark = pos; + fseek(dp->lib->fdata, pos, SEEK_SET); /* check for error??? */ + dp->lib->fmark = pos; } nread = fread(buf, size, quan, dp->lib->fdata); @@ -324,19 +325,27 @@ lib_dlb_fread(buf, size, quan, dp) STATIC_OVL int lib_dlb_fseek(dp, pos, whence) - dlb *dp; - long pos; - int whence; +dlb *dp; +long pos; +int whence; { long curpos; switch (whence) { - case SEEK_CUR: curpos = dp->mark + pos; break; - case SEEK_END: curpos = dp->size - pos; break; - default: /* set */ curpos = pos; break; + case SEEK_CUR: + curpos = dp->mark + pos; + break; + case SEEK_END: + curpos = dp->size - pos; + break; + default: /* set */ + curpos = pos; + break; } - if (curpos < 0) curpos = 0; - if (curpos > dp->size) curpos = dp->size; + if (curpos < 0) + curpos = 0; + if (curpos > dp->size) + curpos = dp->size; dp->mark = curpos; return 0; @@ -344,30 +353,33 @@ lib_dlb_fseek(dp, pos, whence) STATIC_OVL char * lib_dlb_fgets(buf, len, dp) - char *buf; - int len; - dlb *dp; +char *buf; +int len; +dlb *dp; { int i; char *bp, c = 0; - if (len <= 0) return buf; /* sanity check */ + if (len <= 0) + return buf; /* sanity check */ /* return NULL on EOF */ - if (dp->mark >= dp->size) return (char *) 0; + if (dp->mark >= dp->size) + return (char *) 0; - len--; /* save room for null */ - for (i = 0, bp = buf; - i < len && dp->mark < dp->size && c != '\n'; i++, bp++) { - if (dlb_fread(bp, 1, 1, dp) <= 0) break; /* EOF or error */ - c = *bp; + len--; /* save room for null */ + for (i = 0, bp = buf; i < len && dp->mark < dp->size && c != '\n'; + i++, bp++) { + if (dlb_fread(bp, 1, 1, dp) <= 0) + break; /* EOF or error */ + c = *bp; } *bp = '\0'; #if defined(MSDOS) || defined(WIN32) if ((bp = index(buf, '\r')) != 0) { - *bp++ = '\n'; - *bp = '\0'; + *bp++ = '\n'; + *bp = '\0'; } #endif @@ -376,51 +388,40 @@ lib_dlb_fgets(buf, len, dp) STATIC_OVL int lib_dlb_fgetc(dp) - dlb *dp; +dlb *dp; { char c; - if (lib_dlb_fread(&c, 1, 1, dp) != 1) return EOF; + if (lib_dlb_fread(&c, 1, 1, dp) != 1) + return EOF; return (int) c; } - STATIC_OVL long lib_dlb_ftell(dp) - dlb *dp; +dlb *dp; { return dp->mark; } -const dlb_procs_t lib_dlb_procs = { - lib_dlb_init, - lib_dlb_cleanup, - lib_dlb_fopen, - lib_dlb_fclose, - lib_dlb_fread, - lib_dlb_fseek, - lib_dlb_fgets, - lib_dlb_fgetc, - lib_dlb_ftell -}; +const dlb_procs_t lib_dlb_procs = { lib_dlb_init, lib_dlb_cleanup, + lib_dlb_fopen, lib_dlb_fclose, + lib_dlb_fread, lib_dlb_fseek, + lib_dlb_fgets, lib_dlb_fgetc, + lib_dlb_ftell }; #endif /* DLBLIB */ #ifdef DLBRSRC -const dlb_procs_t rsrc_dlb_procs = { - rsrc_dlb_init, - rsrc_dlb_cleanup, - rsrc_dlb_fopen, - rsrc_dlb_fclose, - rsrc_dlb_fread, - rsrc_dlb_fseek, - rsrc_dlb_fgets, - rsrc_dlb_fgetc, - rsrc_dlb_ftell -}; +const dlb_procs_t rsrc_dlb_procs = { rsrc_dlb_init, rsrc_dlb_cleanup, + rsrc_dlb_fopen, rsrc_dlb_fclose, + rsrc_dlb_fread, rsrc_dlb_fseek, + rsrc_dlb_fgets, rsrc_dlb_fgetc, + rsrc_dlb_ftell }; #endif -/* Global wrapper functions ------------------------------------------------ */ +/* Global wrapper functions ------------------------------------------------ + */ #define do_dlb_init (*dlb_procs->dlb_init_proc) #define do_dlb_cleanup (*dlb_procs->dlb_cleanup_proc) @@ -440,14 +441,14 @@ dlb_init() { if (!dlb_initialized) { #ifdef DLBLIB - dlb_procs = &lib_dlb_procs; + dlb_procs = &lib_dlb_procs; #endif #ifdef DLBRSRC - dlb_procs = &rsrc_dlb_procs; + dlb_procs = &rsrc_dlb_procs; #endif - if (dlb_procs) - dlb_initialized = do_dlb_init(); + if (dlb_procs) + dlb_initialized = do_dlb_init(); } return dlb_initialized; @@ -457,100 +458,114 @@ void dlb_cleanup() { if (dlb_initialized) { - do_dlb_cleanup(); - dlb_initialized = FALSE; + do_dlb_cleanup(); + dlb_initialized = FALSE; } } dlb * dlb_fopen(name, mode) - const char *name, *mode; +const char *name, *mode; { FILE *fp; dlb *dp; - if (!dlb_initialized) return (dlb *) 0; + if (!dlb_initialized) + return (dlb *) 0; - /* only support reading; ignore possible binary flag */ - if (!mode || mode[0] != 'r') return (dlb *)0; + /* only support reading; ignore possible binary flag */ + if (!mode || mode[0] != 'r') + return (dlb *) 0; dp = (dlb *) alloc(sizeof(dlb)); if (do_dlb_fopen(dp, name, mode)) - dp->fp = (FILE *) 0; + dp->fp = (FILE *) 0; else if ((fp = fopen_datafile(name, mode, DATAPREFIX)) != 0) - dp->fp = fp; + dp->fp = fp; else { - /* can't find anything */ - free((genericptr_t) dp); - dp = (dlb *) 0; - } + /* can't find anything */ + free((genericptr_t) dp); + dp = (dlb *) 0; + } return dp; } int dlb_fclose(dp) - dlb *dp; +dlb *dp; { - int ret = 0; + int ret = 0; if (dlb_initialized) { - if (dp->fp) ret = fclose(dp->fp); - else ret = do_dlb_fclose(dp); + if (dp->fp) + ret = fclose(dp->fp); + else + ret = do_dlb_fclose(dp); - free((genericptr_t) dp); + free((genericptr_t) dp); } return ret; } int dlb_fread(buf, size, quan, dp) - char *buf; - int size, quan; - dlb *dp; +char *buf; +int size, quan; +dlb *dp; { - if (!dlb_initialized || size <= 0 || quan <= 0) return 0; - if (dp->fp) return (int) fread(buf, size, quan, dp->fp); + if (!dlb_initialized || size <= 0 || quan <= 0) + return 0; + if (dp->fp) + return (int) fread(buf, size, quan, dp->fp); return do_dlb_fread(buf, size, quan, dp); } int dlb_fseek(dp, pos, whence) - dlb *dp; - long pos; - int whence; +dlb *dp; +long pos; +int whence; { - if (!dlb_initialized) return EOF; - if (dp->fp) return fseek(dp->fp, pos, whence); + if (!dlb_initialized) + return EOF; + if (dp->fp) + return fseek(dp->fp, pos, whence); return do_dlb_fseek(dp, pos, whence); } char * dlb_fgets(buf, len, dp) - char *buf; - int len; - dlb *dp; +char *buf; +int len; +dlb *dp; { - if (!dlb_initialized) return (char *) 0; - if (dp->fp) return fgets(buf, len, dp->fp); + if (!dlb_initialized) + return (char *) 0; + if (dp->fp) + return fgets(buf, len, dp->fp); return do_dlb_fgets(buf, len, dp); } int dlb_fgetc(dp) - dlb *dp; +dlb *dp; { - if (!dlb_initialized) return EOF; - if (dp->fp) return fgetc(dp->fp); + if (!dlb_initialized) + return EOF; + if (dp->fp) + return fgetc(dp->fp); return do_dlb_fgetc(dp); } long dlb_ftell(dp) - dlb *dp; +dlb *dp; { - if (!dlb_initialized) return 0; - if (dp->fp) return ftell(dp->fp); + if (!dlb_initialized) + return 0; + if (dp->fp) + return ftell(dp->fp); return do_dlb_ftell(dp); } diff --git a/src/do.c b/src/do.c index 5a1368451..de387e8e9 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do.c $NHDT-Date: 1429666911 2015/04/22 01:41:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.130 $ */ +/* NetHack 3.6 do.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.141 $ */ /* NetHack 3.6 do.c $Date: 2014/11/18 03:10:39 $ $Revision: 1.101 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -21,10 +21,10 @@ STATIC_DCL int NDECL(currentlevel_rewrite); STATIC_DCL void NDECL(final_level); /* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */ -extern int n_dgns; /* number of dungeons, from dungeon.c */ +extern int n_dgns; /* number of dungeons, from dungeon.c */ -static NEARDATA const char drop_types[] = - { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, 0 }; +static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS, + ALL_CLASSES, 0 }; /* 'd' command: drop one inventory item */ int @@ -32,9 +32,11 @@ dodrop() { int result, i = (invent) ? 0 : (SIZE(drop_types) - 1); - if (*u.ushops) sellobj_state(SELL_DELIBERATE); + if (*u.ushops) + sellobj_state(SELL_DELIBERATE); result = drop(getobj(&drop_types[i], "drop")); - if (*u.ushops) sellobj_state(SELL_NORMAL); + if (*u.ushops) + sellobj_state(SELL_NORMAL); reset_occupations(); return result; @@ -52,70 +54,73 @@ boolean pushing; { if (!otmp || otmp->otyp != BOULDER) impossible("Not a boulder?"); - else if (!Is_waterlevel(&u.uz) && is_pool_or_lava(rx,ry)) { - boolean lava = is_lava(rx,ry), fills_up; - const char *what = waterbody_name(rx,ry); + else if (!Is_waterlevel(&u.uz) && is_pool_or_lava(rx, ry)) { + boolean lava = is_lava(rx, ry), fills_up; + const char *what = waterbody_name(rx, ry); schar ltyp = levl[rx][ry].typ; - int chance = rn2(10); /* water: 90%; lava: 10% */ + int chance = rn2(10); /* water: 90%; lava: 10% */ fills_up = lava ? chance == 0 : chance != 0; if (fills_up) { - struct trap *ttmp = t_at(rx, ry); + struct trap *ttmp = t_at(rx, ry); - if (ltyp == DRAWBRIDGE_UP) { - levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */ - levl[rx][ry].drawbridgemask |= DB_FLOOR; - } else - levl[rx][ry].typ = ROOM; + if (ltyp == DRAWBRIDGE_UP) { + levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */ + levl[rx][ry].drawbridgemask |= DB_FLOOR; + } else + levl[rx][ry].typ = ROOM; - if (ttmp) (void) delfloortrap(ttmp); - bury_objs(rx, ry); - - newsym(rx,ry); - if (pushing) { - char whobuf[BUFSZ]; + if (ttmp) + (void) delfloortrap(ttmp); + bury_objs(rx, ry); - Strcpy(whobuf, "you"); - if (u.usteed) Strcpy(whobuf, y_monnam(u.usteed)); + newsym(rx, ry); + if (pushing) { + char whobuf[BUFSZ]; + + Strcpy(whobuf, "you"); + if (u.usteed) + Strcpy(whobuf, y_monnam(u.usteed)); pline("%s %s %s into the %s.", upstart(whobuf), vtense(whobuf, "push"), the(xname(otmp)), what); - if (flags.verbose && !Blind) - pline("Now you can cross it!"); - /* no splashing in this case */ - } - } - if (!fills_up || !pushing) { /* splashing occurs */ - if (!u.uinwater) { - if (pushing ? !Blind : cansee(rx,ry)) { - There("is a large splash as %s %s the %s.", - the(xname(otmp)), fills_up? "fills":"falls into", - what); - } else if (!Deaf) - You_hear("a%s splash.", lava ? " sizzling" : ""); - wake_nearto(rx, ry, 40); + if (flags.verbose && !Blind) + pline("Now you can cross it!"); + /* no splashing in this case */ + } } + if (!fills_up || !pushing) { /* splashing occurs */ + if (!u.uinwater) { + if (pushing ? !Blind : cansee(rx, ry)) { + There("is a large splash as %s %s the %s.", + the(xname(otmp)), fills_up ? "fills" : "falls into", + what); + } else if (!Deaf) + You_hear("a%s splash.", lava ? " sizzling" : ""); + wake_nearto(rx, ry, 40); + } - if (fills_up && u.uinwater && distu(rx,ry) == 0) { - u.uinwater = 0; - docrt(); - vision_full_recalc = 1; - You("find yourself on dry land again!"); - } else if (lava && distu(rx,ry) <= 2) { - int dmg; - You("are hit by molten lava%c", - Fire_resistance ? '.' : '!'); - burn_away_slime(); - dmg = d((Fire_resistance ? 1 : 3), 6); - losehp(Maybe_Half_Phys(dmg), /* lava damage */ - "molten lava", KILLED_BY); - } else if (!fills_up && flags.verbose && - (pushing ? !Blind : cansee(rx,ry))) - pline("It sinks without a trace!"); + if (fills_up && u.uinwater && distu(rx, ry) == 0) { + u.uinwater = 0; + docrt(); + vision_full_recalc = 1; + You("find yourself on dry land again!"); + } else if (lava && distu(rx, ry) <= 2) { + int dmg; + You("are hit by molten lava%c", Fire_resistance ? '.' : '!'); + burn_away_slime(); + dmg = d((Fire_resistance ? 1 : 3), 6); + losehp(Maybe_Half_Phys(dmg), /* lava damage */ + "molten lava", KILLED_BY); + } else if (!fills_up && flags.verbose + && (pushing ? !Blind : cansee(rx, ry))) + pline("It sinks without a trace!"); } /* boulder is now gone */ - if (pushing) delobj(otmp); - else obfree(otmp, (struct obj *)0); + if (pushing) + delobj(otmp); + else + obfree(otmp, (struct obj *) 0); return TRUE; } return FALSE; @@ -133,50 +138,49 @@ const char *verb; { struct trap *t; struct monst *mtmp; - struct obj* otmp; + struct obj *otmp; if (obj->where != OBJ_FREE) panic("flooreffects: obj not free"); /* make sure things like water_damage() have no pointers to follow */ - obj->nobj = obj->nexthere = (struct obj *)0; + obj->nobj = obj->nexthere = (struct obj *) 0; if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) return TRUE; - else if (obj->otyp == BOULDER && (t = t_at(x,y)) != 0 && - (t->ttyp==PIT || t->ttyp==SPIKED_PIT - || t->ttyp==TRAPDOOR || t->ttyp==HOLE)) { - if (((mtmp = m_at(x, y)) && mtmp->mtrapped) || - (u.utrap && u.ux == x && u.uy == y)) { + else if (obj->otyp == BOULDER && (t = t_at(x, y)) != 0 + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT + || t->ttyp == TRAPDOOR || t->ttyp == HOLE)) { + if (((mtmp = m_at(x, y)) && mtmp->mtrapped) + || (u.utrap && u.ux == x && u.uy == y)) { if (*verb) - pline_The("boulder %s into the pit%s.", - vtense((const char *)0, verb), - (mtmp) ? "" : " with you"); + pline_The("boulder %s into the pit%s.", + vtense((const char *) 0, verb), + (mtmp) ? "" : " with you"); if (mtmp) { - if (!passes_walls(mtmp->data) && - !throws_rocks(mtmp->data)) { - if (hmon(mtmp, obj, TRUE) && !is_whirly(mtmp->data)) - return FALSE; /* still alive */ - } - mtmp->mtrapped = 0; + if (!passes_walls(mtmp->data) && !throws_rocks(mtmp->data)) { + if (hmon(mtmp, obj, TRUE) && !is_whirly(mtmp->data)) + return FALSE; /* still alive */ + } + mtmp->mtrapped = 0; } else { - if (!Passes_walls && !throws_rocks(youmonst.data)) { - losehp(Maybe_Half_Phys(rnd(15)), - "squished under a boulder", - NO_KILLER_PREFIX); - return FALSE; /* player remains trapped */ - } else u.utrap = 0; + if (!Passes_walls && !throws_rocks(youmonst.data)) { + losehp(Maybe_Half_Phys(rnd(15)), + "squished under a boulder", NO_KILLER_PREFIX); + return FALSE; /* player remains trapped */ + } else + u.utrap = 0; } } if (*verb) { if (Blind && (x == u.ux) && (y == u.uy)) { You_hear("a CRASH! beneath you."); } else if (!Blind && cansee(x, y)) { - pline_The("boulder %s%s.", - t->tseen ? "" : "triggers and ", - t->ttyp == TRAPDOOR ? "plugs a trap door" : - t->ttyp == HOLE ? "plugs a hole" : - "fills a pit"); + pline_The("boulder %s%s.", t->tseen ? "" : "triggers and ", + t->ttyp == TRAPDOOR + ? "plugs a trap door" + : t->ttyp == HOLE ? "plugs a hole" + : "fills a pit"); } else { You_hear("a boulder %s.", verb); } @@ -184,7 +188,7 @@ const char *verb; deltrap(t); useupf(obj, 1L); bury_objs(x, y); - newsym(x,y); + newsym(x, y); return TRUE; } else if (is_lava(x, y)) { return fire_damage(obj, FALSE, x, y); @@ -192,64 +196,65 @@ const char *verb; /* Reasonably bulky objects (arbitrary) splash when dropped. * If you're floating above the water even small things make * noise. Stuff dropped near fountains always misses */ - if ((Blind || (Levitation || Flying)) && !Deaf && - ((x == u.ux) && (y == u.uy))) { + if ((Blind || (Levitation || Flying)) && !Deaf + && ((x == u.ux) && (y == u.uy))) { if (!Underwater) { - if (weight(obj) > 9) { - pline("Splash!"); + if (weight(obj) > 9) { + pline("Splash!"); } else if (Levitation || Flying) { - pline("Plop!"); + pline("Plop!"); } } map_background(x, y, 0); newsym(x, y); } return water_damage(obj, NULL, FALSE) == ER_DESTROYED; - } else if (u.ux == x && u.uy == y && - (t = t_at(x,y)) != 0 && uteetering_at_seen_pit(t)) { + } else if (u.ux == x && u.uy == y && (t = t_at(x, y)) != 0 + && uteetering_at_seen_pit(t)) { if (Blind && !Deaf) - You_hear("%s tumble downwards.", - the(xname(obj))); + You_hear("%s tumble downwards.", the(xname(obj))); else - pline("%s %s into %s pit.", - The(xname(obj)), otense(obj, "tumble"), - the_your[t->madeby_u]); + pline("%s %s into %s pit.", The(xname(obj)), + otense(obj, "tumble"), the_your[t->madeby_u]); } else if (obj->globby) { /* Globby things like puddings might stick together */ - while (obj && (otmp = obj_nexto_xy(obj->otyp, x, y, obj->o_id)) != (struct obj*)0) { + while (obj + && (otmp = obj_nexto_xy(obj->otyp, x, y, obj->o_id)) + != (struct obj *) 0) { pudding_merge_message(obj, otmp); - /* intentionally not getting the melded object; obj_meld may set obj to null. */ + /* intentionally not getting the melded object; obj_meld may set + * obj to null. */ (void) obj_meld(&obj, &otmp); } - return (obj == NULL); + return (obj == NULL); } return FALSE; } -void -doaltarobj(obj) /* obj is an object dropped on an altar */ - register struct obj *obj; +void doaltarobj(obj) /* obj is an object dropped on an altar */ +register struct obj *obj; { if (Blind) return; - if (obj->oclass != COIN_CLASS) { - /* KMH, conduct */ - u.uconduct.gnostic++; - } else { - /* coins don't have bless/curse status */ - obj->blessed = obj->cursed = 0; - } - - if (obj->blessed || obj->cursed) { - There("is %s flash as %s %s the altar.", - an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)), - doname(obj), otense(obj, "hit")); - if (!Hallucination) obj->bknown = 1; + if (obj->oclass != COIN_CLASS) { + /* KMH, conduct */ + u.uconduct.gnostic++; } else { - pline("%s %s on the altar.", Doname2(obj), - otense(obj, "land")); - if (obj->oclass != COIN_CLASS) obj->bknown = 1; + /* coins don't have bless/curse status */ + obj->blessed = obj->cursed = 0; + } + + if (obj->blessed || obj->cursed) { + There("is %s flash as %s %s the altar.", + an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)), doname(obj), + otense(obj, "hit")); + if (!Hallucination) + obj->bknown = 1; + } else { + pline("%s %s on the altar.", Doname2(obj), otense(obj, "land")); + if (obj->oclass != COIN_CLASS) + obj->bknown = 1; } } @@ -258,9 +263,8 @@ void trycall(obj) register struct obj *obj; { - if(!objects[obj->otyp].oc_name_known && - !objects[obj->otyp].oc_uname) - docall(obj); + if (!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname) + docall(obj); } /** Transforms the sink at the player's position into @@ -269,32 +273,33 @@ STATIC_DCL void polymorph_sink() { - if (levl[u.ux][u.uy].typ != SINK) return; + if (levl[u.ux][u.uy].typ != SINK) + return; level.flags.nsinks--; levl[u.ux][u.uy].doormask = 0; - switch(rn2(4)) { + switch (rn2(4)) { default: case 0: - levl[u.ux][u.uy].typ = FOUNTAIN; - level.flags.nfountains++; - break; + levl[u.ux][u.uy].typ = FOUNTAIN; + level.flags.nfountains++; + break; case 1: - levl[u.ux][u.uy].typ = THRONE; - break; + levl[u.ux][u.uy].typ = THRONE; + break; case 2: - levl[u.ux][u.uy].typ = ALTAR; - levl[u.ux][u.uy].altarmask = Align2amask(rn2((int)A_LAWFUL+2) - 1); - break; + levl[u.ux][u.uy].typ = ALTAR; + levl[u.ux][u.uy].altarmask = Align2amask(rn2((int) A_LAWFUL + 2) - 1); + break; case 3: - levl[u.ux][u.uy].typ = ROOM; - make_grave(u.ux, u.uy, (char *) 0); - break; + levl[u.ux][u.uy].typ = ROOM; + make_grave(u.ux, u.uy, (char *) 0); + break; } - pline_The("sink transforms into %s!", - (levl[u.ux][u.uy].typ == THRONE) ? - "a throne" : an(surface(u.ux, u.uy))); - newsym(u.ux,u.uy); + pline_The("sink transforms into %s!", (levl[u.ux][u.uy].typ == THRONE) + ? "a throne" + : an(surface(u.ux, u.uy))); + newsym(u.ux, u.uy); } /** Teleports the sink at the player's position. @@ -308,111 +313,108 @@ teleport_sink() struct trap *trp; struct engr *eng; do { - cx = rnd(COLNO-1); - cy = rn2(ROWNO); - trp = t_at(cx,cy); - eng = engr_at(cx,cy); - } while (((levl[cx][cy].typ != ROOM) || (trp) || (eng) || - cansee(cx,cy)) && (cnt++ < 200)); + cx = rnd(COLNO - 1); + cy = rn2(ROWNO); + trp = t_at(cx, cy); + eng = engr_at(cx, cy); + } while (((levl[cx][cy].typ != ROOM) || (trp) || (eng) || cansee(cx, cy)) + && (cnt++ < 200)); if ((levl[cx][cy].typ == ROOM) && !trp && !eng) { - /* create sink at new position */ - levl[cx][cy].typ = SINK; - levl[cx][cy].looted = levl[u.ux][u.uy].looted; - newsym(cx,cy); - /* remove old sink */ - levl[u.ux][u.uy].typ = ROOM; - levl[u.ux][u.uy].looted = 0; - newsym(u.ux,u.uy); - return TRUE; + /* create sink at new position */ + levl[cx][cy].typ = SINK; + levl[cx][cy].looted = levl[u.ux][u.uy].looted; + newsym(cx, cy); + /* remove old sink */ + levl[u.ux][u.uy].typ = ROOM; + levl[u.ux][u.uy].looted = 0; + newsym(u.ux, u.uy); + return TRUE; } return FALSE; } - STATIC_OVL -void -dosinkring(obj) /* obj is a ring being dropped over a kitchen sink */ +void dosinkring(obj) /* obj is a ring being dropped over a kitchen sink */ register struct obj *obj; { - register struct obj *otmp,*otmp2; + register struct obj *otmp, *otmp2; register boolean ideed = TRUE; boolean nosink = FALSE; You("drop %s down the drain.", doname(obj)); - obj->in_use = TRUE; /* block free identification via interrupt */ - switch(obj->otyp) { /* effects that can be noticed without eyes */ - case RIN_SEARCHING: - You("thought %s got lost in the sink, but there it is!", - yname(obj)); + obj->in_use = TRUE; /* block free identification via interrupt */ + switch (obj->otyp) { /* effects that can be noticed without eyes */ + case RIN_SEARCHING: + You("thought %s got lost in the sink, but there it is!", yname(obj)); goto giveback; - case RIN_SLOW_DIGESTION: + case RIN_SLOW_DIGESTION: pline_The("ring is regurgitated!"); -giveback: + giveback: obj->in_use = FALSE; dropx(obj); trycall(obj); return; - case RIN_LEVITATION: + case RIN_LEVITATION: pline_The("sink quivers upward for a moment."); break; - case RIN_POISON_RESISTANCE: + case RIN_POISON_RESISTANCE: You("smell rotten %s.", makeplural(fruitname(FALSE))); break; - case RIN_AGGRAVATE_MONSTER: - pline("Several %s buzz angrily around the sink.", - Hallucination ? makeplural(rndmonnam(NULL)) : "flies"); - break; - case RIN_SHOCK_RESISTANCE: + case RIN_AGGRAVATE_MONSTER: + pline("Several %s buzz angrily around the sink.", + Hallucination ? makeplural(rndmonnam(NULL)) : "flies"); + break; + case RIN_SHOCK_RESISTANCE: pline("Static electricity surrounds the sink."); break; - case RIN_CONFLICT: + case RIN_CONFLICT: You_hear("loud noises coming from the drain."); break; - case RIN_SUSTAIN_ABILITY: /* KMH */ + case RIN_SUSTAIN_ABILITY: /* KMH */ pline_The("water flow seems fixed."); break; - case RIN_GAIN_STRENGTH: + case RIN_GAIN_STRENGTH: pline_The("water flow seems %ser now.", - (obj->spe<0) ? "weak" : "strong"); + (obj->spe < 0) ? "weak" : "strong"); break; - case RIN_GAIN_CONSTITUTION: + case RIN_GAIN_CONSTITUTION: pline_The("water flow seems %ser now.", - (obj->spe<0) ? "less" : "great"); + (obj->spe < 0) ? "less" : "great"); break; - case RIN_INCREASE_ACCURACY: /* KMH */ + case RIN_INCREASE_ACCURACY: /* KMH */ pline_The("water flow %s the drain.", - (obj->spe<0) ? "misses" : "hits"); + (obj->spe < 0) ? "misses" : "hits"); break; - case RIN_INCREASE_DAMAGE: + case RIN_INCREASE_DAMAGE: pline_The("water's force seems %ser now.", - (obj->spe<0) ? "small" : "great"); + (obj->spe < 0) ? "small" : "great"); break; - case RIN_HUNGER: + case RIN_HUNGER: ideed = FALSE; - for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) { + for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) { otmp2 = otmp->nexthere; - if (otmp != uball && otmp != uchain && - !obj_resists(otmp, 1, 99)) { - if (!Blind) { - pline("Suddenly, %s %s from the sink!", - doname(otmp), otense(otmp, "vanish")); - ideed = TRUE; - } - delobj(otmp); + if (otmp != uball && otmp != uchain + && !obj_resists(otmp, 1, 99)) { + if (!Blind) { + pline("Suddenly, %s %s from the sink!", doname(otmp), + otense(otmp, "vanish")); + ideed = TRUE; + } + delobj(otmp); } } break; - case MEAT_RING: + case MEAT_RING: /* Not the same as aggravate monster; besides, it's obvious. */ pline("Several flies buzz around the sink."); break; - default: + default: ideed = FALSE; break; } - if(!Blind && !ideed && obj->otyp != RIN_HUNGER) { + if (!Blind && !ideed && obj->otyp != RIN_HUNGER) { ideed = TRUE; - switch(obj->otyp) { /* effects that need eyes */ + switch (obj->otyp) { /* effects that need eyes */ case RIN_ADORNMENT: pline_The("faucets flash brightly for a moment."); break; @@ -427,44 +429,45 @@ giveback: break; case RIN_SEE_INVISIBLE: You_see("some %s in the sink.", - Hallucination ? "oxygen molecules" : "air"); + Hallucination ? "oxygen molecules" : "air"); break; case RIN_STEALTH: - pline_The("sink seems to blend into the floor for a moment."); + pline_The("sink seems to blend into the floor for a moment."); break; case RIN_FIRE_RESISTANCE: - pline_The("hot water faucet flashes brightly for a moment."); + pline_The("hot water faucet flashes brightly for a moment."); break; case RIN_COLD_RESISTANCE: - pline_The("cold water faucet flashes brightly for a moment."); + pline_The("cold water faucet flashes brightly for a moment."); break; case RIN_PROTECTION_FROM_SHAPE_CHAN: pline_The("sink looks nothing like a fountain."); break; case RIN_PROTECTION: pline_The("sink glows %s for a moment.", - hcolor((obj->spe<0) ? NH_BLACK : NH_SILVER)); + hcolor((obj->spe < 0) ? NH_BLACK : NH_SILVER)); break; case RIN_WARNING: pline_The("sink glows %s for a moment.", hcolor(NH_WHITE)); break; case RIN_TELEPORTATION: - nosink = teleport_sink(); + nosink = teleport_sink(); pline_The("sink %svanishes.", nosink ? "" : "momentarily "); break; case RIN_TELEPORT_CONTROL: - pline_The("sink looks like it is being beamed aboard somewhere."); + pline_The("sink looks like it is being beamed aboard somewhere."); break; case RIN_POLYMORPH: - polymorph_sink(); - nosink = TRUE; + polymorph_sink(); + nosink = TRUE; break; case RIN_POLYMORPH_CONTROL: - pline_The("sink momentarily looks like a regularly erupting geyser."); + pline_The( + "sink momentarily looks like a regularly erupting geyser."); break; } } - if(ideed) + if (ideed) trycall(obj); else if (!nosink) You_hear("the ring bouncing down the drainpipe."); @@ -478,15 +481,14 @@ giveback: /* some common tests when trying to drop or throw items */ boolean -canletgo(obj,word) +canletgo(obj, word) register struct obj *obj; register const char *word; { - if(obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)){ + if (obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) { if (*word) - Norep("You cannot %s %s you are wearing.",word, - something); - return(FALSE); + Norep("You cannot %s %s you are wearing.", word, something); + return (FALSE); } if (obj->otyp == LOADSTONE && obj->cursed) { /* getobj() kludge sets corpsenm to user's specified count @@ -496,27 +498,24 @@ register const char *word; implicitly forced to be 1; replicate its kludge... */ if (!strcmp(word, "throw") && obj->quan > 1L) obj->corpsenm = 1; - pline("For some reason, you cannot %s%s the stone%s!", - word, obj->corpsenm ? " any of" : "", - plur(obj->quan)); + pline("For some reason, you cannot %s%s the stone%s!", word, + obj->corpsenm ? " any of" : "", plur(obj->quan)); } - obj->corpsenm = 0; /* reset */ + obj->corpsenm = 0; /* reset */ obj->bknown = 1; - return(FALSE); + return (FALSE); } if (obj->otyp == LEASH && obj->leashmon != 0) { if (*word) - pline_The("leash is tied around your %s.", - body_part(HAND)); - return(FALSE); + pline_The("leash is tied around your %s.", body_part(HAND)); + return (FALSE); } if (obj->owornmask & W_SADDLE) { if (*word) - You("cannot %s %s you are sitting on.", word, - something); + You("cannot %s %s you are sitting on.", word, something); return (FALSE); } - return(TRUE); + return (TRUE); } STATIC_PTR @@ -524,27 +523,27 @@ int drop(obj) register struct obj *obj; { - if(!obj) return(0); - if(!canletgo(obj,"drop")) - return(0); - if(obj == uwep) { - if(welded(uwep)) { + if (!obj) + return (0); + if (!canletgo(obj, "drop")) + return (0); + if (obj == uwep) { + if (welded(uwep)) { weldmsg(obj); - return(0); + return (0); } - setuwep((struct obj *)0); + setuwep((struct obj *) 0); } - if(obj == uquiver) { - setuqwep((struct obj *)0); + if (obj == uquiver) { + setuqwep((struct obj *) 0); } if (obj == uswapwep) { - setuswapwep((struct obj *)0); + setuswapwep((struct obj *) 0); } if (u.uswallow) { /* barrier between you and the floor */ - if(flags.verbose) - { + if (flags.verbose) { char buf[BUFSZ]; /* doname can call s_suffix, reusing its buffer */ @@ -553,31 +552,35 @@ register struct obj *obj; mbodypart(u.ustuck, STOMACH)); } } else { - if((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING) && - IS_SINK(levl[u.ux][u.uy].typ)) { - dosinkring(obj); - return(1); + if ((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING) + && IS_SINK(levl[u.ux][u.uy].typ)) { + dosinkring(obj); + return (1); } if (!can_reach_floor(TRUE)) { - /* we might be levitating due to #invoke Heart of Ahriman; - if so, levitation would end during call to freeinv() - and we want hitfloor() to happen before float_down() */ - boolean levhack = finesse_ahriman(obj); + /* we might be levitating due to #invoke Heart of Ahriman; + if so, levitation would end during call to freeinv() + and we want hitfloor() to happen before float_down() */ + boolean levhack = finesse_ahriman(obj); - if (levhack) ELevitation = W_ART; /* other than W_ARTI */ - if(flags.verbose) You("drop %s.", doname(obj)); - /* Ensure update when we drop gold objects */ - if (obj->oclass == COIN_CLASS) context.botl = 1; - freeinv(obj); - hitfloor(obj); - if (levhack) float_down(I_SPECIAL|TIMEOUT, W_ARTI|W_ART); - return(1); + if (levhack) + ELevitation = W_ART; /* other than W_ARTI */ + if (flags.verbose) + You("drop %s.", doname(obj)); + /* Ensure update when we drop gold objects */ + if (obj->oclass == COIN_CLASS) + context.botl = 1; + freeinv(obj); + hitfloor(obj); + if (levhack) + float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART); + return (1); } if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose) - You("drop %s.", doname(obj)); + You("drop %s.", doname(obj)); } dropx(obj); - return(1); + return (1); } /* dropx - take dropped item out of inventory; @@ -587,18 +590,21 @@ void dropx(obj) register struct obj *obj; { - /* Ensure update when we drop gold objects */ - if (obj->oclass == COIN_CLASS) context.botl = 1; - freeinv(obj); + /* Ensure update when we drop gold objects */ + if (obj->oclass == COIN_CLASS) + context.botl = 1; + freeinv(obj); if (!u.uswallow) { - if (ship_object(obj, u.ux, u.uy, FALSE)) return; + if (ship_object(obj, u.ux, u.uy, FALSE)) + return; if (IS_ALTAR(levl[u.ux][u.uy].typ)) - doaltarobj(obj); /* set bknown */ + doaltarobj(obj); /* set bknown */ } dropy(obj); } -/* dropy - put dropped object at its destination; called from lots of places */ +/* dropy - put dropped object at its destination; called from lots of places + */ void dropy(obj) struct obj *obj; @@ -612,60 +618,65 @@ dropz(obj, with_impact) struct obj *obj; boolean with_impact; { - if (obj == uwep) setuwep((struct obj *)0); - if (obj == uquiver) setuqwep((struct obj *)0); - if (obj == uswapwep) setuswapwep((struct obj *)0); + if (obj == uwep) + setuwep((struct obj *) 0); + if (obj == uquiver) + setuqwep((struct obj *) 0); + if (obj == uswapwep) + setuswapwep((struct obj *) 0); - if (!u.uswallow && flooreffects(obj,u.ux,u.uy,"drop")) return; + if (!u.uswallow && flooreffects(obj, u.ux, u.uy, "drop")) + return; /* uswallow check done by GAN 01/29/87 */ - if(u.uswallow) { + if (u.uswallow) { boolean could_petrify = FALSE; boolean could_poly = FALSE; boolean could_slime = FALSE; boolean could_grow = FALSE; boolean could_heal = FALSE; - if (obj != uball) { /* mon doesn't pick up ball */ - if (obj->otyp == CORPSE) { - could_petrify = touch_petrifies(&mons[obj->corpsenm]); - could_poly = polyfodder(obj); - could_slime = (obj->corpsenm == PM_GREEN_SLIME); - could_grow = (obj->corpsenm == PM_WRAITH); - could_heal = (obj->corpsenm == PM_NURSE); - } - (void) mpickobj(u.ustuck,obj); - if (is_animal(u.ustuck->data)) { - if (could_poly || could_slime) { - (void) newcham(u.ustuck, - could_poly ? (struct permonst *)0 : - &mons[PM_GREEN_SLIME], - FALSE, could_slime); - delobj(obj); /* corpse is digested */ - } else if (could_petrify) { - minstapetrify(u.ustuck, TRUE); - /* Don't leave a cockatrice corpse in a statue */ - if (!u.uswallow) delobj(obj); - } else if (could_grow) { - (void) grow_up(u.ustuck, (struct monst *)0); - delobj(obj); /* corpse is digested */ - } else if (could_heal) { - u.ustuck->mhp = u.ustuck->mhpmax; - delobj(obj); /* corpse is digested */ + if (obj != uball) { /* mon doesn't pick up ball */ + if (obj->otyp == CORPSE) { + could_petrify = touch_petrifies(&mons[obj->corpsenm]); + could_poly = polyfodder(obj); + could_slime = (obj->corpsenm == PM_GREEN_SLIME); + could_grow = (obj->corpsenm == PM_WRAITH); + could_heal = (obj->corpsenm == PM_NURSE); + } + (void) mpickobj(u.ustuck, obj); + if (is_animal(u.ustuck->data)) { + if (could_poly || could_slime) { + (void) newcham(u.ustuck, + could_poly ? (struct permonst *) 0 + : &mons[PM_GREEN_SLIME], + FALSE, could_slime); + delobj(obj); /* corpse is digested */ + } else if (could_petrify) { + minstapetrify(u.ustuck, TRUE); + /* Don't leave a cockatrice corpse in a statue */ + if (!u.uswallow) + delobj(obj); + } else if (could_grow) { + (void) grow_up(u.ustuck, (struct monst *) 0); + delobj(obj); /* corpse is digested */ + } else if (could_heal) { + u.ustuck->mhp = u.ustuck->mhpmax; + delobj(obj); /* corpse is digested */ + } } } - } - } else { + } else { place_object(obj, u.ux, u.uy); if (with_impact) - container_impact_dmg(obj, u.ux, u.uy); + container_impact_dmg(obj, u.ux, u.uy); if (obj == uball) - drop_ball(u.ux,u.uy); + drop_ball(u.ux, u.uy); else if (level.flags.has_shop) - sellobj(obj, u.ux, u.uy); + sellobj(obj, u.ux, u.uy); stackobj(obj); - if(Blind && Levitation) - map_object(obj, 0); - newsym(u.ux,u.uy); /* remap location under self */ + if (Blind && Levitation) + map_object(obj, 0); + newsym(u.ux, u.uy); /* remap location under self */ } } @@ -681,7 +692,7 @@ struct obj *obj; struct obj *contents; for (contents = obj->cobj; contents; contents = contents->nobj) - obj_no_longer_held(contents); + obj_no_longer_held(contents); } switch (obj->otyp) { case CRYSKNIFE: @@ -692,11 +703,11 @@ struct obj *obj; * but we aren't in any position to handle stack splitting here. */ if (!obj->oerodeproof || !rn2(10)) { - /* if monsters aren't moving, assume player is responsible */ - if (!context.mon_moving && !program_state.gameover) - costly_alteration(obj, COST_DEGRD); - obj->otyp = WORM_TOOTH; - obj->oerodeproof = 0; + /* if monsters aren't moving, assume player is responsible */ + if (!context.mon_moving && !program_state.gameover) + costly_alteration(obj, COST_DEGRD); + obj->otyp = WORM_TOOTH; + obj->oerodeproof = 0; } break; } @@ -709,11 +720,13 @@ doddrop() int result = 0; add_valid_menu_class(0); /* clear any classes already there */ - if (*u.ushops) sellobj_state(SELL_DELIBERATE); - if (flags.menu_style != MENU_TRADITIONAL || - (result = ggetobj("drop", drop, 0, FALSE, (unsigned *)0)) < -1) + if (*u.ushops) + sellobj_state(SELL_DELIBERATE); + if (flags.menu_style != MENU_TRADITIONAL + || (result = ggetobj("drop", drop, 0, FALSE, (unsigned *) 0)) < -1) result = menu_drop(result); - if (*u.ushops) sellobj_state(SELL_NORMAL); + if (*u.ushops) + sellobj_state(SELL_NORMAL); reset_occupations(); return result; @@ -732,101 +745,104 @@ int retry; boolean drop_everything = FALSE; if (retry) { - all_categories = (retry == -2); + all_categories = (retry == -2); } else if (flags.menu_style == MENU_FULL) { - all_categories = FALSE; - n = query_category("Drop what type of items?", - invent, - UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | - BUC_BLESSED | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN, - &pick_list, PICK_ANY); - if (!n) goto drop_done; - for (i = 0; i < n; i++) { - if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) - all_categories = TRUE; - else if (pick_list[i].item.a_int == 'A') - drop_everything = TRUE; - else - add_valid_menu_class(pick_list[i].item.a_int); - } - free((genericptr_t) pick_list); + all_categories = FALSE; + n = query_category("Drop what type of items?", invent, + UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | BUC_BLESSED + | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN, + &pick_list, PICK_ANY); + if (!n) + goto drop_done; + for (i = 0; i < n; i++) { + if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) + all_categories = TRUE; + else if (pick_list[i].item.a_int == 'A') + drop_everything = TRUE; + else + add_valid_menu_class(pick_list[i].item.a_int); + } + free((genericptr_t) pick_list); } else if (flags.menu_style == MENU_COMBINATION) { - unsigned ggoresults = 0; - all_categories = FALSE; - /* Gather valid classes via traditional NetHack method */ - i = ggetobj("drop", drop, 0, TRUE, &ggoresults); - if (i == -2) all_categories = TRUE; - if (ggoresults & ALL_FINISHED) { - n_dropped = i; - goto drop_done; - } + unsigned ggoresults = 0; + all_categories = FALSE; + /* Gather valid classes via traditional NetHack method */ + i = ggetobj("drop", drop, 0, TRUE, &ggoresults); + if (i == -2) + all_categories = TRUE; + if (ggoresults & ALL_FINISHED) { + n_dropped = i; + goto drop_done; + } } if (drop_everything) { - /* - * Dropping a burning potion of oil while levitating can cause - * an explosion which might destroy some of hero's inventory, - * so the old code - * for (otmp = invent; otmp; otmp = otmp2) { - * otmp2 = otmp->nobj; - * n_dropped += drop(otmp); - * } - * was unreliable and could lead to an "object lost" panic. - * - * Use the bypass bit to mark items already processed (hence - * not droppable) and rescan inventory until no unbypassed - * items remain. - */ - bypass_objlist(invent, FALSE); /* clear bypass bit for invent */ - while ((otmp = nxt_unbypassed_obj(invent)) != 0) - n_dropped += drop(otmp); - /* we might not have dropped everything (worn armor, welded weapon, - cursed loadstones), so reset any remaining inventory to normal */ - bypass_objlist(invent, FALSE); - } else { - /* should coordinate with perm invent, maybe not show worn items */ - n = query_objlist("What would you like to drop?", invent, - USE_INVLET|INVORDER_SORT, &pick_list, - PICK_ANY, all_categories ? allow_all : allow_category); - if (n > 0) { /* - * picklist[] contains a set of pointers into inventory, but - * as soon as something gets dropped, they might become stale - * (see the drop_everything code above for an explanation). - * Just checking to see whether one is still in the invent - * chain is not sufficient validation since destroyed items - * will be freed and items we've split here might have already - * reused that memory and put the same pointer value back into - * invent. Ditto for using invlet to validate. So we start - * by setting bypass on all of invent, then check each pointer - * to verify that it is in invent and has that bit set. + * Dropping a burning potion of oil while levitating can cause + * an explosion which might destroy some of hero's inventory, + * so the old code + * for (otmp = invent; otmp; otmp = otmp2) { + * otmp2 = otmp->nobj; + * n_dropped += drop(otmp); + * } + * was unreliable and could lead to an "object lost" panic. + * + * Use the bypass bit to mark items already processed (hence + * not droppable) and rescan inventory until no unbypassed + * items remain. */ - bypass_objlist(invent, TRUE); - for (i = 0; i < n; i++) { - otmp = pick_list[i].item.a_obj; - for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj) - if (otmp2 == otmp) break; - if (!otmp2 || !otmp2->bypass) continue; - /* found next selected invent item */ - cnt = pick_list[i].count; - if (cnt < otmp->quan) { - if (welded(otmp)) { - ; /* don't split */ - } else if (otmp->otyp == LOADSTONE && otmp->cursed) { - /* same kludge as getobj(), for canletgo()'s use */ - otmp->corpsenm = (int) cnt; /* don't split */ - } else { - otmp = splitobj(otmp, cnt); + bypass_objlist(invent, FALSE); /* clear bypass bit for invent */ + while ((otmp = nxt_unbypassed_obj(invent)) != 0) + n_dropped += drop(otmp); + /* we might not have dropped everything (worn armor, welded weapon, + cursed loadstones), so reset any remaining inventory to normal */ + bypass_objlist(invent, FALSE); + } else { + /* should coordinate with perm invent, maybe not show worn items */ + n = query_objlist("What would you like to drop?", invent, + USE_INVLET | INVORDER_SORT, &pick_list, PICK_ANY, + all_categories ? allow_all : allow_category); + if (n > 0) { + /* + * picklist[] contains a set of pointers into inventory, but + * as soon as something gets dropped, they might become stale + * (see the drop_everything code above for an explanation). + * Just checking to see whether one is still in the invent + * chain is not sufficient validation since destroyed items + * will be freed and items we've split here might have already + * reused that memory and put the same pointer value back into + * invent. Ditto for using invlet to validate. So we start + * by setting bypass on all of invent, then check each pointer + * to verify that it is in invent and has that bit set. + */ + bypass_objlist(invent, TRUE); + for (i = 0; i < n; i++) { + otmp = pick_list[i].item.a_obj; + for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj) + if (otmp2 == otmp) + break; + if (!otmp2 || !otmp2->bypass) + continue; + /* found next selected invent item */ + cnt = pick_list[i].count; + if (cnt < otmp->quan) { + if (welded(otmp)) { + ; /* don't split */ + } else if (otmp->otyp == LOADSTONE && otmp->cursed) { + /* same kludge as getobj(), for canletgo()'s use */ + otmp->corpsenm = (int) cnt; /* don't split */ + } else { + otmp = splitobj(otmp, cnt); + } + } + n_dropped += drop(otmp); } + bypass_objlist(invent, FALSE); /* reset invent to normal */ + free((genericptr_t) pick_list); } - n_dropped += drop(otmp); - } - bypass_objlist(invent, FALSE); /* reset invent to normal */ - free((genericptr_t) pick_list); - } } - drop_done: +drop_done: return n_dropped; } @@ -837,11 +853,13 @@ int dodown() { struct trap *trap = 0; - boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair) || - (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up)), - ladder_down = (u.ux == xdnladder && u.uy == ydnladder); + boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair) + || (u.ux == sstairs.sx && u.uy == sstairs.sy + && !sstairs.up)), + ladder_down = (u.ux == xdnladder && u.uy == ydnladder); - if (u_rooted()) return 1; + if (u_rooted()) + return 1; if (stucksteed(TRUE)) { return 0; @@ -850,99 +868,101 @@ dodown() turn off controlled levitaiton */ if (HLevitation || ELevitation) { if ((HLevitation & I_SPECIAL) || (ELevitation & W_ARTI)) { - /* end controlled levitation */ - if (ELevitation & W_ARTI) { - struct obj *obj; + /* end controlled levitation */ + if (ELevitation & W_ARTI) { + struct obj *obj; - for(obj = invent; obj; obj = obj->nobj) { - if (obj->oartifact && - artifact_has_invprop(obj, LEVITATION)) { - if (obj->age < monstermoves) - obj->age = monstermoves; - obj->age += rnz(100); + for (obj = invent; obj; obj = obj->nobj) { + if (obj->oartifact + && artifact_has_invprop(obj, LEVITATION)) { + if (obj->age < monstermoves) + obj->age = monstermoves; + obj->age += rnz(100); + } + } } + if (float_down(I_SPECIAL | TIMEOUT, W_ARTI)) { + return 1; /* came down, so moved */ + } else if (!HLevitation && !ELevitation) { + Your("latent levitation ceases."); + return 1; /* did something, effectively moved */ } } - if (float_down(I_SPECIAL|TIMEOUT, W_ARTI)) { - return 1; /* came down, so moved */ - } else if (!HLevitation && !ELevitation) { - Your("latent levitation ceases."); - return 1; /* did something, effectively moved */ - } - } if (BLevitation) { - ; /* weren't actually floating after all */ + ; /* weren't actually floating after all */ } else if (Blind) { - /* Avoid alerting player to an unknown stair or ladder. - * Changes the message for a covered, known staircase - * too; staircase knowledge is not stored anywhere. - */ - if (stairs_down) - stairs_down = - (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair); - else if (ladder_down) - ladder_down = - (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder); + /* Avoid alerting player to an unknown stair or ladder. + * Changes the message for a covered, known staircase + * too; staircase knowledge is not stored anywhere. + */ + if (stairs_down) + stairs_down = + (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair); + else if (ladder_down) + ladder_down = + (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder); } - floating_above(stairs_down ? "stairs" : ladder_down ? - "ladder" : surface(u.ux, u.uy)); - return (0); /* didn't move */ + floating_above(stairs_down ? "stairs" : ladder_down + ? "ladder" + : surface(u.ux, u.uy)); + return (0); /* didn't move */ } if (!stairs_down && !ladder_down) { - trap = t_at(u.ux,u.uy); + trap = t_at(u.ux, u.uy); if (trap && uteetering_at_seen_pit(trap)) { dotrap(trap, TOOKPLUNGE); - return(1); - } else if (!trap || - (trap->ttyp != TRAPDOOR && trap->ttyp != HOLE) || - !Can_fall_thru(&u.uz) || !trap->tseen) { - if (flags.autodig && !context.nopick && - uwep && is_pick(uwep)) { + return (1); + } else if (!trap || (trap->ttyp != TRAPDOOR && trap->ttyp != HOLE) + || !Can_fall_thru(&u.uz) || !trap->tseen) { + if (flags.autodig && !context.nopick && uwep && is_pick(uwep)) { return use_pick_axe2(uwep); } else { You_cant("go down here."); - return(0); + return (0); } } } - if(u.ustuck) { + if (u.ustuck) { You("are %s, and cannot go down.", - !u.uswallow ? "being held" : is_animal(u.ustuck->data) ? - "swallowed" : "engulfed"); - return(1); + !u.uswallow ? "being held" : is_animal(u.ustuck->data) + ? "swallowed" + : "engulfed"); + return (1); } if (on_level(&valley_level, &u.uz) && !u.uevent.gehennom_entered) { You("are standing at the gate to Gehennom."); pline("Unspeakable cruelty and harm lurk down there."); if (yn("Are you sure you want to enter?") != 'y') - return(0); - else pline("So be it."); - u.uevent.gehennom_entered = 1; /* don't ask again */ + return (0); + else + pline("So be it."); + u.uevent.gehennom_entered = 1; /* don't ask again */ } - if(!next_to_u()) { + if (!next_to_u()) { You("are held back by your pet!"); - return(0); + return (0); } if (trap) You("%s %s.", Flying ? "fly" : locomotion(youmonst.data, "jump"), - trap->ttyp == HOLE ? "down the hole" : "through the trap door"); + trap->ttyp == HOLE ? "down the hole" : "through the trap door"); if (trap && Is_stronghold(&u.uz)) { goto_hell(FALSE, TRUE); } else { - at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); + at_ladder = (boolean)(levl[u.ux][u.uy].typ == LADDER); next_level(!trap); at_ladder = FALSE; } - return(1); + return (1); } int doup() { - if (u_rooted()) return 1; + if (u_rooted()) + return 1; /* "up" to get out of a pit... */ if (u.utrap && u.utraptype == TT_PIT) { @@ -950,44 +970,44 @@ doup() return 1; } - if( (u.ux != xupstair || u.uy != yupstair) - && (!xupladder || u.ux != xupladder || u.uy != yupladder) - && (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy - || !sstairs.up) - ) { + if ((u.ux != xupstair || u.uy != yupstair) + && (!xupladder || u.ux != xupladder || u.uy != yupladder) + && (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy + || !sstairs.up)) { You_cant("go up here."); - return(0); + return (0); } if (stucksteed(TRUE)) { - return(0); + return (0); } - if(u.ustuck) { + if (u.ustuck) { You("are %s, and cannot go up.", - !u.uswallow ? "being held" : is_animal(u.ustuck->data) ? - "swallowed" : "engulfed"); - return(1); + !u.uswallow ? "being held" : is_animal(u.ustuck->data) + ? "swallowed" + : "engulfed"); + return (1); } - if(near_capacity() > SLT_ENCUMBER) { + if (near_capacity() > SLT_ENCUMBER) { /* No levitation check; inv_weight() already allows for it */ Your("load is too heavy to climb the %s.", - levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder"); - return(1); + levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder"); + return (1); } - if(ledger_no(&u.uz) == 1) { + if (ledger_no(&u.uz) == 1) { if (yn("Beware, there will be no return! Still climb?") != 'y') - return(0); + return (0); } - if(!next_to_u()) { + if (!next_to_u()) { You("are held back by your pet!"); - return(0); + return (0); } - at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER); + at_ladder = (boolean)(levl[u.ux][u.uy].typ == LADDER); prev_level(TRUE); at_ladder = FALSE; - return(1); + return (1); } -d_level save_dlevel = {0, 0}; +d_level save_dlevel = { 0, 0 }; /* check that we can write out the current level */ STATIC_OVL int @@ -1015,7 +1035,7 @@ currentlevel_rewrite() #ifdef MFLOPPY if (!savelev(fd, ledger_no(&u.uz), COUNT_SAVE)) { - (void) nhclose(fd); + (void) nhclose(fd); delete_levelfile(ledger_no(&u.uz)); pline("NetHack is out of disk space for making levels!"); You("can save, quit, or continue playing."); @@ -1034,9 +1054,10 @@ save_currentstate() if (flags.ins_chkpt) { /* write out just-attained level, with pets and everything */ fd = currentlevel_rewrite(); - if(fd < 0) return; + if (fd < 0) + return; bufon(fd); - savelev(fd,ledger_no(&u.uz), WRITE_SAVE); + savelev(fd, ledger_no(&u.uz), WRITE_SAVE); bclose(fd); } @@ -1062,12 +1083,11 @@ boolean at_stairs, falling, portal; { int fd, l_idx; xchar new_ledger; - boolean cant_go_back, - up = (depth(newlevel) < depth(&u.uz)), - newdungeon = (u.uz.dnum != newlevel->dnum), - was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz), - familiar = FALSE; - boolean new = FALSE; /* made a new level? */ + boolean cant_go_back, up = (depth(newlevel) < depth(&u.uz)), + newdungeon = (u.uz.dnum != newlevel->dnum), + was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz), + familiar = FALSE; + boolean new = FALSE; /* made a new level? */ struct monst *mtmp; char whynot[BUFSZ]; char *annotation; @@ -1075,53 +1095,54 @@ boolean at_stairs, falling, portal; if (dunlev(newlevel) > dunlevs_in_dungeon(newlevel)) newlevel->dlevel = dunlevs_in_dungeon(newlevel); if (newdungeon && In_endgame(newlevel)) { /* 1st Endgame Level !!! */ - if (!u.uhave.amulet) return; /* must have the Amulet */ - if (!wizard) /* wizard ^V can bypass Earth level */ - assign_level(newlevel, &earth_level); /* (redundant) */ + if (!u.uhave.amulet) + return; /* must have the Amulet */ + if (!wizard) /* wizard ^V can bypass Earth level */ + assign_level(newlevel, &earth_level); /* (redundant) */ } new_ledger = ledger_no(newlevel); if (new_ledger <= 0) - done(ESCAPED); /* in fact < 0 is impossible */ + done(ESCAPED); /* in fact < 0 is impossible */ /* If you have the amulet and are trying to get out of Gehennom, going * up a set of stairs sometimes does some very strange things! - * Biased against law and towards chaos. (The chance to be sent - * down multiple levels when attempting to go up are significantly - * less than the corresponding comment in older versions indicated - * due to overlooking the effect of the call to assign_rnd_lvl().) - * - * Odds for making it to the next level up, or of being sent down: - * "up" L N C - * +1 75.0 75.0 75.0 - * 0 6.25 8.33 12.5 - * -1 11.46 12.50 12.5 - * -2 5.21 4.17 0.0 - * -3 2.08 0.0 0.0 + * Biased against law and towards chaos. (The chance to be sent + * down multiple levels when attempting to go up are significantly + * less than the corresponding comment in older versions indicated + * due to overlooking the effect of the call to assign_rnd_lvl().) + * + * Odds for making it to the next level up, or of being sent down: + * "up" L N C + * +1 75.0 75.0 75.0 + * 0 6.25 8.33 12.5 + * -1 11.46 12.50 12.5 + * -2 5.21 4.17 0.0 + * -3 2.08 0.0 0.0 */ - if (Inhell && up && u.uhave.amulet && !newdungeon && !portal && - (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)-3)) { + if (Inhell && up && u.uhave.amulet && !newdungeon && !portal + && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { if (!rn2(4)) { - int odds = 3 + (int)u.ualign.type, /* 2..4 */ - diff = odds <= 1 ? 0 : rn2(odds); /* paranoia */ + int odds = 3 + (int) u.ualign.type, /* 2..4 */ + diff = odds <= 1 ? 0 : rn2(odds); /* paranoia */ if (diff != 0) { - assign_rnd_level(newlevel, &u.uz, diff); - /* if inside the tower, stay inside */ - if (was_in_W_tower && - !On_W_tower_level(newlevel)) diff = 0; + assign_rnd_level(newlevel, &u.uz, diff); + /* if inside the tower, stay inside */ + if (was_in_W_tower && !On_W_tower_level(newlevel)) + diff = 0; } if (diff == 0) - assign_level(newlevel, &u.uz); + assign_level(newlevel, &u.uz); new_ledger = ledger_no(newlevel); pline("A mysterious force momentarily surrounds you..."); if (on_level(newlevel, &u.uz)) { - (void) safe_teleds(FALSE); - (void) next_to_u(); - return; + (void) safe_teleds(FALSE); + (void) next_to_u(); + return; } else - at_stairs = at_ladder = FALSE; + at_stairs = at_ladder = FALSE; } } @@ -1133,34 +1154,37 @@ boolean at_stairs, falling, portal; return; } - if (on_level(newlevel, &u.uz)) return; /* this can happen */ + if (on_level(newlevel, &u.uz)) + return; /* this can happen */ /* tethered movement makes level change while trapped feasible */ if (u.utrap && u.utraptype == TT_BURIEDBALL) buried_ball_to_punishment(); /* (before we save/leave old level) */ fd = currentlevel_rewrite(); - if (fd < 0) return; + if (fd < 0) + return; if (falling) /* assuming this is only trap door or hole */ - impact_drop((struct obj *)0, u.ux, u.uy, newlevel->dlevel); + impact_drop((struct obj *) 0, u.ux, u.uy, newlevel->dlevel); - check_special_room(TRUE); /* probably was a trap door */ - if (Punished) unplacebc(); - u.utrap = 0; /* needed in level_tele */ + check_special_room(TRUE); /* probably was a trap door */ + if (Punished) + unplacebc(); + u.utrap = 0; /* needed in level_tele */ fill_pit(u.ux, u.uy); - u.ustuck = 0; /* idem */ + u.ustuck = 0; /* idem */ u.uinwater = 0; - u.uundetected = 0; /* not hidden, even if means are available */ + u.uundetected = 0; /* not hidden, even if means are available */ keepdogs(FALSE); - if (u.uswallow) /* idem */ + if (u.uswallow) /* idem */ u.uswldtim = u.uswallow = 0; recalc_mapseen(); /* recalculate map overview before we leave the level */ - /* - * We no longer see anything on the level. Make sure that this - * follows u.uswallow set to null since uswallow overrides all - * normal vision. - */ + /* + * We no longer see anything on the level. Make sure that this + * follows u.uswallow set to null since uswallow overrides all + * normal vision. + */ vision_recalc(2); /* @@ -1172,19 +1196,19 @@ boolean at_stairs, falling, portal; */ cant_go_back = (newdungeon && In_endgame(newlevel)); if (!cant_go_back) { - update_mlstmv(); /* current monsters are becoming inactive */ - bufon(fd); /* use buffered output */ + update_mlstmv(); /* current monsters are becoming inactive */ + bufon(fd); /* use buffered output */ } savelev(fd, ledger_no(&u.uz), - cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE)); + cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE)); bclose(fd); if (cant_go_back) { /* discard unreachable levels; keep #0 */ for (l_idx = maxledgerno(); l_idx > 0; --l_idx) - delete_levelfile(l_idx); + delete_levelfile(l_idx); /* mark #overview data for all dungeon branches as uninteresting */ for (l_idx = 0; l_idx < n_dgns; ++l_idx) - remdun_mapseen(l_idx); + remdun_mapseen(l_idx); } if (Is_rogue_level(newlevel) || Is_rogue_level(&u.uz)) @@ -1203,7 +1227,7 @@ boolean at_stairs, falling, portal; u.utotype = 0; if (dunlev_reached(&u.uz) < dunlev(&u.uz)) dunlev_reached(&u.uz) = dunlev(&u.uz); - reset_rndmonst(NON_PM); /* u.uz change affects monster generation */ + reset_rndmonst(NON_PM); /* u.uz change affects monster generation */ /* set default level change destination areas */ /* the special level code may override these */ @@ -1212,12 +1236,12 @@ boolean at_stairs, falling, portal; if (!(level_info[new_ledger].flags & LFILE_EXISTS)) { /* entering this level for first time; make it now */ - if (level_info[new_ledger].flags & (FORGOTTEN|VISITED)) { + if (level_info[new_ledger].flags & (FORGOTTEN | VISITED)) { impossible("goto_level: returning to discarded level?"); - level_info[new_ledger].flags &= ~(FORGOTTEN|VISITED); + level_info[new_ledger].flags &= ~(FORGOTTEN | VISITED); } mklev(); - new = TRUE; /* made the level */ + new = TRUE; /* made the level */ } else { /* returning to previously visited level; reload it */ fd = open_levelfile(new_ledger, whynot); @@ -1225,94 +1249,97 @@ boolean at_stairs, falling, portal; /* we'll reach here if running in wizard mode */ error("Cannot continue this game."); } - minit(); /* ZEROCOMP */ + minit(); /* ZEROCOMP */ getlev(fd, hackpid, new_ledger, FALSE); - (void) nhclose(fd); + (void) nhclose(fd); oinit(); /* reassign level dependent obj probabilities */ } /* do this prior to level-change pline messages */ - vision_reset(); /* clear old level's line-of-sight */ - vision_full_recalc = 0; /* don't let that reenable vision yet */ - flush_screen(-1); /* ensure all map flushes are postponed */ + vision_reset(); /* clear old level's line-of-sight */ + vision_full_recalc = 0; /* don't let that reenable vision yet */ + flush_screen(-1); /* ensure all map flushes are postponed */ if (portal && !In_endgame(&u.uz)) { /* find the portal on the new level */ register struct trap *ttrap; for (ttrap = ftrap; ttrap; ttrap = ttrap->ntrap) - if (ttrap->ttyp == MAGIC_PORTAL) break; + if (ttrap->ttyp == MAGIC_PORTAL) + break; - if (!ttrap) panic("goto_level: no corresponding portal!"); + if (!ttrap) + panic("goto_level: no corresponding portal!"); seetrap(ttrap); u_on_newpos(ttrap->tx, ttrap->ty); } else if (at_stairs && !In_endgame(&u.uz)) { if (up) { - if (at_ladder) - u_on_newpos(xdnladder, ydnladder); - else if (newdungeon) - u_on_sstairs(1); - else - u_on_dnstairs(); - /* you climb up the {stairs|ladder}; - fly up the stairs; fly up along the ladder */ - pline("%s %s up%s the %s.", - (Punished && !Levitation) ? "With great effort you" : - "You", - Flying ? "fly" : "climb", - (Flying && at_ladder) ? " along" : "", - at_ladder ? "ladder" : "stairs"); - } else { /* down */ - if (at_ladder) - u_on_newpos(xupladder, yupladder); - else if (newdungeon) - u_on_sstairs(0); - else - u_on_upstairs(); - if (!u.dz) { - ; /* stayed on same level? (no transit effects) */ - } else if (Flying) { - if (flags.verbose) - You("fly down %s.", - at_ladder ? "along the ladder" : "the stairs"); - } else if (near_capacity() > UNENCUMBERED || - Punished || Fumbling) { - You("fall down the %s.", at_ladder ? "ladder" : "stairs"); - if (Punished) { - drag_down(); - ballrelease(FALSE); - } - /* falling off steed has its own losehp() call */ - if (u.usteed) - dismount_steed(DISMOUNT_FELL); + if (at_ladder) + u_on_newpos(xdnladder, ydnladder); + else if (newdungeon) + u_on_sstairs(1); else - losehp(Maybe_Half_Phys(rnd(3)), - at_ladder ? "falling off a ladder" : - "tumbling down a flight of stairs", - KILLED_BY); - selftouch("Falling, you"); - } else { /* ordinary descent */ - if (flags.verbose) - You("%s.", at_ladder ? "climb down the ladder" : - "descend the stairs"); + u_on_dnstairs(); + /* you climb up the {stairs|ladder}; + fly up the stairs; fly up along the ladder */ + pline("%s %s up%s the %s.", + (Punished && !Levitation) ? "With great effort you" : "You", + Flying ? "fly" : "climb", + (Flying && at_ladder) ? " along" : "", + at_ladder ? "ladder" : "stairs"); + } else { /* down */ + if (at_ladder) + u_on_newpos(xupladder, yupladder); + else if (newdungeon) + u_on_sstairs(0); + else + u_on_upstairs(); + if (!u.dz) { + ; /* stayed on same level? (no transit effects) */ + } else if (Flying) { + if (flags.verbose) + You("fly down %s.", + at_ladder ? "along the ladder" : "the stairs"); + } else if (near_capacity() > UNENCUMBERED || Punished + || Fumbling) { + You("fall down the %s.", at_ladder ? "ladder" : "stairs"); + if (Punished) { + drag_down(); + ballrelease(FALSE); + } + /* falling off steed has its own losehp() call */ + if (u.usteed) + dismount_steed(DISMOUNT_FELL); + else + losehp(Maybe_Half_Phys(rnd(3)), + at_ladder ? "falling off a ladder" + : "tumbling down a flight of stairs", + KILLED_BY); + selftouch("Falling, you"); + } else { /* ordinary descent */ + if (flags.verbose) + You("%s.", at_ladder ? "climb down the ladder" + : "descend the stairs"); + } } - } - } else { /* trap door or level_tele or In_endgame */ + } else { /* trap door or level_tele or In_endgame */ u_on_rndspot((up ? 1 : 0) | (was_in_W_tower ? 2 : 0)); if (falling) { - if (Punished) ballfall(); - selftouch("Falling, you"); + if (Punished) + ballfall(); + selftouch("Falling, you"); } } - if (Punished) placebc(); + if (Punished) + placebc(); obj_delivery(FALSE); losedogs(); - kill_genocided_monsters(); /* for those wiped out while in limbo */ - /* - * Expire all timers that have gone off while away. Must be - * after migrating monsters and objects are delivered - * (losedogs and obj_delivery). - */ + kill_genocided_monsters(); /* for those wiped out while in limbo */ + /* + * Expire all timers that have gone off while away. Must be + * after migrating monsters and objects are delivered + * (losedogs and obj_delivery). + */ run_timers(); initrack(); @@ -1325,41 +1352,41 @@ boolean at_stairs, falling, portal; the latter was done unconditionally. */ coord cc; - if (!rn2(2) && - enexto(&cc, u.ux, u.uy, youmonst.data) && - distu(cc.x, cc.y) <= 2) - u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/ + if (!rn2(2) && enexto(&cc, u.ux, u.uy, youmonst.data) + && distu(cc.x, cc.y) <= 2) + u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/ else - mnexto(mtmp); + mnexto(mtmp); if ((mtmp = m_at(u.ux, u.uy)) != 0) { - /* there was an unconditional impossible("mnearto failed") - here, but it's not impossible and we're prepared to cope - with the situation, so only say something when debugging */ - if (wizard) pline("(monster in hero's way)"); - if (!rloc(mtmp, TRUE)) - /* no room to move it; send it away, to return later */ - migrate_to_level(mtmp, ledger_no(&u.uz), - MIGR_RANDOM, (coord *)0); + /* there was an unconditional impossible("mnearto failed") + here, but it's not impossible and we're prepared to cope + with the situation, so only say something when debugging */ + if (wizard) + pline("(monster in hero's way)"); + if (!rloc(mtmp, TRUE)) + /* no room to move it; send it away, to return later */ + migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_RANDOM, + (coord *) 0); } } /* initial movement of bubbles just before vision_recalc */ - if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) + if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) movebubbles(); - else if (Is_firelevel(&u.uz)) - fumaroles(); + else if (Is_firelevel(&u.uz)) + fumaroles(); if (level_info[new_ledger].flags & FORGOTTEN) { - forget_map(ALL_MAP); /* forget the map */ - forget_traps(); /* forget all traps too */ + forget_map(ALL_MAP); /* forget the map */ + forget_traps(); /* forget all traps too */ familiar = TRUE; level_info[new_ledger].flags &= ~FORGOTTEN; } /* Reset the screen. */ - vision_reset(); /* reset the blockages */ - docrt(); /* does a full vision recalc */ + vision_reset(); /* reset the blockages */ + docrt(); /* does a full vision recalc */ flush_screen(-1); /* @@ -1378,80 +1405,82 @@ boolean at_stairs, falling, portal; /* Check whether we just entered Gehennom. */ if (!In_hell(&u.uz0) && Inhell) { if (Is_valley(&u.uz)) { - You("arrive at the Valley of the Dead..."); - pline_The("odor of burnt flesh and decay pervades the air."); + You("arrive at the Valley of the Dead..."); + pline_The("odor of burnt flesh and decay pervades the air."); #ifdef MICRO - display_nhwindow(WIN_MESSAGE, FALSE); + display_nhwindow(WIN_MESSAGE, FALSE); #endif - You_hear("groans and moans everywhere."); - } else pline("It is hot here. You smell smoke..."); - u.uachieve.enter_gehennom = 1; + You_hear("groans and moans everywhere."); + } else + pline("It is hot here. You smell smoke..."); + u.uachieve.enter_gehennom = 1; } /* in case we've managed to bypass the Valley's stairway down */ - if (Inhell && !Is_valley(&u.uz)) u.uevent.gehennom_entered = 1; + if (Inhell && !Is_valley(&u.uz)) + u.uevent.gehennom_entered = 1; if (familiar) { - static const char * const fam_msgs[4] = { - "You have a sense of deja vu.", - "You feel like you've been here before.", - "This place %s familiar...", - 0 /* no message */ + static const char *const fam_msgs[4] = { + "You have a sense of deja vu.", + "You feel like you've been here before.", + "This place %s familiar...", 0 /* no message */ }; - static const char * const halu_fam_msgs[4] = { - "Whoa! Everything %s different.", - "You are surrounded by twisty little passages, all alike.", - "Gee, this %s like uncle Conan's place...", - 0 /* no message */ + static const char *const halu_fam_msgs[4] = { + "Whoa! Everything %s different.", + "You are surrounded by twisty little passages, all alike.", + "Gee, this %s like uncle Conan's place...", 0 /* no message */ }; const char *mesg; char buf[BUFSZ]; int which = rn2(4); if (Hallucination) - mesg = halu_fam_msgs[which]; + mesg = halu_fam_msgs[which]; else - mesg = fam_msgs[which]; + mesg = fam_msgs[which]; if (mesg && index(mesg, '%')) { - Sprintf(buf, mesg, !Blind ? "looks" : "seems"); - mesg = buf; + Sprintf(buf, mesg, !Blind ? "looks" : "seems"); + mesg = buf; } - if (mesg) pline1(mesg); + if (mesg) + pline1(mesg); } /* special location arrival messages/events */ if (In_endgame(&u.uz)) { - if (new && on_level(&u.uz, &astral_level)) - final_level(); /* guardian angel,&c */ + if (new &&on_level(&u.uz, &astral_level)) + final_level(); /* guardian angel,&c */ else if (newdungeon && u.uhave.amulet) - resurrect(); /* force confrontation with Wizard */ + resurrect(); /* force confrontation with Wizard */ } else if (In_quest(&u.uz)) { - onquest(); /* might be reaching locate|goal level */ + onquest(); /* might be reaching locate|goal level */ } else if (In_V_tower(&u.uz)) { if (newdungeon && In_hell(&u.uz0)) - pline_The("heat and smoke are gone."); + pline_The("heat and smoke are gone."); } else if (Is_knox(&u.uz)) { /* alarm stops working once Croesus has died */ if (new || !mvitals[PM_CROESUS].died) { - You("have penetrated a high security area!"); - pline("An alarm sounds!"); - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - mtmp->msleeping = 0; - } + You("have penetrated a high security area!"); + pline("An alarm sounds!"); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + mtmp->msleeping = 0; + } } } else { - if (new && Is_rogue_level(&u.uz)) - You("enter what seems to be an older, more primitive world."); + if (new &&Is_rogue_level(&u.uz)) + You("enter what seems to be an older, more primitive world."); /* main dungeon message from your quest leader */ - if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest") && - !(u.uevent.qcompleted || u.uevent.qexpelled || - quest_status.leader_is_dead)) { - if (!u.uevent.qcalled) { - u.uevent.qcalled = 1; - com_pager(2); /* main "leader needs help" message */ - } else { /* reminder message */ - com_pager(Role_if(PM_ROGUE) ? 4 : 3); - } + if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest") + && !(u.uevent.qcompleted || u.uevent.qexpelled + || quest_status.leader_is_dead)) { + if (!u.uevent.qcalled) { + u.uevent.qcalled = 1; + com_pager(2); /* main "leader needs help" message */ + } else { /* reminder message */ + com_pager(Role_if(PM_ROGUE) ? 4 : 3); + } } } @@ -1461,12 +1490,12 @@ boolean at_stairs, falling, portal; #endif if ((annotation = get_annotation(&u.uz))) - You("remember this level as %s.", annotation); + You("remember this level as %s.", annotation); /* assume this will always return TRUE when changing level */ (void) in_out_region(u.ux, u.uy); (void) pickup(1); - context.polearm.hitmon = NULL; + context.polearm.hitmon = NULL; } STATIC_OVL void @@ -1476,7 +1505,8 @@ final_level() /* reset monster hostility relative to player */ for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; reset_hostility(mtmp); } @@ -1487,8 +1517,8 @@ final_level() gain_guardian_angel(); } -static char *dfr_pre_msg = 0, /* pline() before level change */ - *dfr_post_msg = 0; /* pline() after level change */ +static char *dfr_pre_msg = 0, /* pline() before level change */ + *dfr_post_msg = 0; /* pline() after level change */ /* change levels at the end of this turn, after monsters finish moving */ void @@ -1498,13 +1528,17 @@ boolean at_stairs, falling; int portal_flag; const char *pre_msg, *post_msg; { - int typmask = 0100; /* non-zero triggers `deferred_goto' */ + int typmask = 0100; /* non-zero triggers `deferred_goto' */ /* destination flags (`goto_level' args) */ - if (at_stairs) typmask |= 1; - if (falling) typmask |= 2; - if (portal_flag) typmask |= 4; - if (portal_flag < 0) typmask |= 0200; /* flag for portal removal */ + if (at_stairs) + typmask |= 1; + if (falling) + typmask |= 2; + if (portal_flag) + typmask |= 4; + if (portal_flag < 0) + typmask |= 0200; /* flag for portal removal */ u.utotype = typmask; /* destination level */ assign_level(&u.utolev, tolev); @@ -1524,23 +1558,25 @@ deferred_goto() int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */ assign_level(&dest, &u.utolev); - if (dfr_pre_msg) pline1(dfr_pre_msg); - goto_level(&dest, !!(typmask&1), !!(typmask&2), !!(typmask&4)); - if (typmask & 0200) { /* remove portal */ - struct trap *t = t_at(u.ux, u.uy); + if (dfr_pre_msg) + pline1(dfr_pre_msg); + goto_level(&dest, !!(typmask & 1), !!(typmask & 2), !!(typmask & 4)); + if (typmask & 0200) { /* remove portal */ + struct trap *t = t_at(u.ux, u.uy); - if (t) { - deltrap(t); - newsym(u.ux, u.uy); + if (t) { + deltrap(t); + newsym(u.ux, u.uy); + } } - } - if (dfr_post_msg) pline1(dfr_post_msg); + if (dfr_post_msg) + pline1(dfr_post_msg); } - u.utotype = 0; /* our caller keys off of this */ + u.utotype = 0; /* our caller keys off of this */ if (dfr_pre_msg) - free((genericptr_t)dfr_pre_msg), dfr_pre_msg = 0; + free((genericptr_t) dfr_pre_msg), dfr_pre_msg = 0; if (dfr_post_msg) - free((genericptr_t)dfr_post_msg), dfr_post_msg = 0; + free((genericptr_t) dfr_post_msg), dfr_post_msg = 0; } /* @@ -1555,80 +1591,82 @@ struct obj *corpse; boolean is_uwep, chewed; xchar where; char cname[BUFSZ]; - struct obj *container = (struct obj *)0; + struct obj *container = (struct obj *) 0; int container_where = 0; - + where = corpse->where; is_uwep = (corpse == uwep); chewed = (corpse->oeaten != 0); - Strcpy(cname, corpse_xname(corpse, - chewed ? "bite-covered" : (const char *)0, - CXN_SINGULAR)); + Strcpy(cname, + corpse_xname(corpse, chewed ? "bite-covered" : (const char *) 0, + CXN_SINGULAR)); mcarry = (where == OBJ_MINVENT) ? corpse->ocarry : 0; if (where == OBJ_CONTAINED) { - struct monst *mtmp2; + struct monst *mtmp2; - container = corpse->ocontainer; - mtmp2 = get_container_location(container, &container_where, (int *)0); - /* container_where is the outermost container's location even if nested */ - if (container_where == OBJ_MINVENT && mtmp2) mcarry = mtmp2; + container = corpse->ocontainer; + mtmp2 = + get_container_location(container, &container_where, (int *) 0); + /* container_where is the outermost container's location even if + * nested */ + if (container_where == OBJ_MINVENT && mtmp2) + mcarry = mtmp2; } - mtmp = revive(corpse, FALSE); /* corpse is gone if successful */ + mtmp = revive(corpse, FALSE); /* corpse is gone if successful */ if (mtmp) { - switch (where) { + switch (where) { case OBJ_INVENT: - if (is_uwep) - pline_The("%s writhes out of your grasp!", cname); - else - You_feel("squirming in your backpack!"); - break; + if (is_uwep) + pline_The("%s writhes out of your grasp!", cname); + else + You_feel("squirming in your backpack!"); + break; case OBJ_FLOOR: - if (cansee(mtmp->mx, mtmp->my)) - pline("%s rises from the dead!", chewed ? - Adjmonnam(mtmp, "bite-covered") : Monnam(mtmp)); - break; + if (cansee(mtmp->mx, mtmp->my)) + pline("%s rises from the dead!", + chewed ? Adjmonnam(mtmp, "bite-covered") + : Monnam(mtmp)); + break; - case OBJ_MINVENT: /* probably a nymph's */ - if (cansee(mtmp->mx, mtmp->my)) { - if (canseemon(mcarry)) - pline("Startled, %s drops %s as it revives!", - mon_nam(mcarry), an(cname)); - else - pline("%s suddenly appears!", chewed ? - Adjmonnam(mtmp, "bite-covered") : Monnam(mtmp)); - } - break; - case OBJ_CONTAINED: - { - char sackname[BUFSZ]; + case OBJ_MINVENT: /* probably a nymph's */ + if (cansee(mtmp->mx, mtmp->my)) { + if (canseemon(mcarry)) + pline("Startled, %s drops %s as it revives!", + mon_nam(mcarry), an(cname)); + else + pline("%s suddenly appears!", + chewed ? Adjmonnam(mtmp, "bite-covered") + : Monnam(mtmp)); + } + break; + case OBJ_CONTAINED: { + char sackname[BUFSZ]; - if (container_where == OBJ_MINVENT && - cansee(mtmp->mx, mtmp->my) && - mcarry && canseemon(mcarry) && container) { - pline("%s writhes out of %s!", - Amonnam(mtmp), yname(container)); - } else if (container_where == OBJ_INVENT && container) { - Strcpy(sackname, an(xname(container))); - pline("%s %s out of %s in your pack!", - Blind ? Something : Amonnam(mtmp), - locomotion(mtmp->data,"writhes"), - sackname); - } else if (container_where == OBJ_FLOOR && container && - cansee(mtmp->mx, mtmp->my)) { - Strcpy(sackname, an(xname(container))); - pline("%s escapes from %s!", Amonnam(mtmp), sackname); + if (container_where == OBJ_MINVENT && cansee(mtmp->mx, mtmp->my) + && mcarry && canseemon(mcarry) && container) { + pline("%s writhes out of %s!", Amonnam(mtmp), + yname(container)); + } else if (container_where == OBJ_INVENT && container) { + Strcpy(sackname, an(xname(container))); + pline("%s %s out of %s in your pack!", + Blind ? Something : Amonnam(mtmp), + locomotion(mtmp->data, "writhes"), sackname); + } else if (container_where == OBJ_FLOOR && container + && cansee(mtmp->mx, mtmp->my)) { + Strcpy(sackname, an(xname(container))); + pline("%s escapes from %s!", Amonnam(mtmp), sackname); + } + break; } - break; - } default: - /* we should be able to handle the other cases... */ - impossible("revive_corpse: lost corpse @ %d", where); - break; - } - return TRUE; + /* we should be able to handle the other cases... */ + impossible("revive_corpse: lost corpse @ %d", where); + break; + } + return TRUE; } return FALSE; } @@ -1647,72 +1685,78 @@ long timeout UNUSED; /* corpse will revive somewhere else if there is a monster in the way; Riders get a chance to try to bump the obstacle out of their way */ - if ((mptr->mflags3 & M3_DISPLACES) != 0 && body->where == OBJ_FLOOR && - get_obj_location(body, &x, &y, 0) && (mtmp = m_at(x, y)) != 0) { - boolean notice_it = canseemon(mtmp); /* before rloc() */ - char *monname = Monnam(mtmp); + if ((mptr->mflags3 & M3_DISPLACES) != 0 && body->where == OBJ_FLOOR + && get_obj_location(body, &x, &y, 0) && (mtmp = m_at(x, y)) != 0) { + boolean notice_it = canseemon(mtmp); /* before rloc() */ + char *monname = Monnam(mtmp); - if (rloc(mtmp, TRUE)) { - if (notice_it && !canseemon(mtmp)) - pline("%s vanishes.", monname); - else if (!notice_it && canseemon(mtmp)) - pline("%s appears.", Monnam(mtmp)); /* not pre-rloc monname */ - else if (notice_it && dist2(mtmp->mx, mtmp->my, x, y) > 2) - pline("%s teleports.", monname); /* saw it and still see it */ - } + if (rloc(mtmp, TRUE)) { + if (notice_it && !canseemon(mtmp)) + pline("%s vanishes.", monname); + else if (!notice_it && canseemon(mtmp)) + pline("%s appears.", Monnam(mtmp)); /* not pre-rloc monname */ + else if (notice_it && dist2(mtmp->mx, mtmp->my, x, y) > 2) + pline("%s teleports.", monname); /* saw it and still see it */ + } } /* if we succeed, the corpse is gone */ if (!revive_corpse(body)) { - long when; - int action; + long when; + int action; - if (is_rider(mptr) && rn2(99)) { /* Rider usually tries again */ - action = REVIVE_MON; - for (when = 3L; when < 67L; when++) - if (!rn2(3)) break; - } else { /* rot this corpse away */ - You_feel("%sless hassled.", is_rider(mptr) ? "much " : ""); - action = ROT_CORPSE; - when = 250L - (monstermoves - body->age); - if (when < 1L) when = 1L; - } - (void) start_timer(when, TIMER_OBJECT, action, arg); + if (is_rider(mptr) && rn2(99)) { /* Rider usually tries again */ + action = REVIVE_MON; + for (when = 3L; when < 67L; when++) + if (!rn2(3)) + break; + } else { /* rot this corpse away */ + You_feel("%sless hassled.", is_rider(mptr) ? "much " : ""); + action = ROT_CORPSE; + when = 250L - (monstermoves - body->age); + if (when < 1L) + when = 1L; + } + (void) start_timer(when, TIMER_OBJECT, action, arg); } } int donull() { - return(1); /* Do nothing, but let other things happen */ + return (1); /* Do nothing, but let other things happen */ } STATIC_PTR int wipeoff(VOID_ARGS) { - if(u.ucreamed < 4) u.ucreamed = 0; - else u.ucreamed -= 4; - if (Blinded < 4) Blinded = 0; - else Blinded -= 4; + if (u.ucreamed < 4) + u.ucreamed = 0; + else + u.ucreamed -= 4; + if (Blinded < 4) + Blinded = 0; + else + Blinded -= 4; if (!Blinded) { pline("You've got the glop off."); u.ucreamed = 0; if (!gulp_blnd_check()) { Blinded = 1; - make_blinded(0L,TRUE); + make_blinded(0L, TRUE); } - return(0); + return (0); } else if (!u.ucreamed) { Your("%s feels clean now.", body_part(FACE)); - return(0); + return (0); } - return(1); /* still busy */ + return (1); /* still busy */ } int dowipe() { - if(u.ucreamed) { + if (u.ucreamed) { static NEARDATA char buf[39]; Sprintf(buf, "wiping off your %s", body_part(FACE)); @@ -1720,10 +1764,10 @@ dowipe() /* Not totally correct; what if they change back after now * but before they're finished wiping? */ - return(1); + return (1); } Your("%s is already clean.", body_part(FACE)); - return(1); + return (1); } void @@ -1737,15 +1781,15 @@ register int timex; * Caller is also responsible for adjusting messages. */ - if(!Wounded_legs) { + if (!Wounded_legs) { ATEMP(A_DEX)--; context.botl = 1; } - if(!Wounded_legs || (HWounded_legs & TIMEOUT)) + if (!Wounded_legs || (HWounded_legs & TIMEOUT)) HWounded_legs = timex; EWounded_legs = side; - (void)encumber_msg(); + (void) encumber_msg(); } void @@ -1757,12 +1801,11 @@ heal_legs() context.botl = 1; } - if (!u.usteed) - { + if (!u.usteed) { const char *legs = body_part(LEG); if ((EWounded_legs & BOTH_SIDES) == BOTH_SIDES) - legs = makeplural(legs); + legs = makeplural(legs); /* this used to say "somewhat better" but that was misleading since legs are being fully healed */ Your("%s %s better.", legs, vtense(legs, "feel")); @@ -1780,7 +1823,8 @@ heal_legs() it might be immediately contradicted [able to carry more when steed becomes healthy, then possible floor feedback, then able to carry less when back on foot]. */ - if (!in_steed_dismounting) (void)encumber_msg(); + if (!in_steed_dismounting) + (void) encumber_msg(); } } diff --git a/src/do_name.c b/src/do_name.c index 8a5554e7c..3af6569f8 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do_name.c $NHDT-Date: 1428196077 2015/04/05 01:07:57 $ $NHDT-Branch: nhmall-booktribute $:$NHDT-Revision: 1.64 $ */ +/* NetHack 3.6 do_name.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.71 $ */ /* NetHack 3.6 do_name.c $Date: 2012/01/29 03:00:17 $ $Revision: 1.49 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,11 +6,11 @@ #include "hack.h" STATIC_DCL char *NDECL(nextmbuf); -STATIC_DCL void FDECL(getpos_help, (BOOLEAN_P,const char *)); +STATIC_DCL void FDECL(getpos_help, (BOOLEAN_P, const char *)); STATIC_DCL void NDECL(do_mname); STATIC_DCL void FDECL(do_oname, (struct obj *)); -extern const char what_is_an_unknown_object[]; /* from pager.c */ +extern const char what_is_an_unknown_object[]; /* from pager.c */ #define NUMMBUF 5 @@ -18,11 +18,11 @@ extern const char what_is_an_unknown_object[]; /* from pager.c */ STATIC_OVL char * nextmbuf() { - static char NEARDATA bufs[NUMMBUF][BUFSZ]; - static int bufidx = 0; + static char NEARDATA bufs[NUMMBUF][BUFSZ]; + static int bufidx = 0; - bufidx = (bufidx + 1) % NUMMBUF; - return bufs[bufidx]; + bufidx = (bufidx + 1) % NUMMBUF; + return bufs[bufidx]; } /* function for getpos() to highlight desired map locations. @@ -46,14 +46,14 @@ const char *goal; boolean doing_what_is; winid tmpwin = create_nhwindow(NHW_MENU); - Sprintf(sbuf, "Use [%c%c%c%c] to move the cursor to %s.", /* hjkl */ - Cmd.move_W, Cmd.move_S, Cmd.move_N, Cmd.move_E, goal); + Sprintf(sbuf, "Use [%c%c%c%c] to move the cursor to %s.", /* hjkl */ + Cmd.move_W, Cmd.move_S, Cmd.move_N, Cmd.move_E, goal); putstr(tmpwin, 0, sbuf); putstr(tmpwin, 0, "Use [HJKL] to move the cursor 8 units at a time."); putstr(tmpwin, 0, "Or enter a background symbol (ex. <)."); putstr(tmpwin, 0, "Use @ to move the cursor on yourself."); if (getpos_hilitefunc != NULL) - putstr(tmpwin, 0, "Use $ to display valid locations."); + putstr(tmpwin, 0, "Use $ to display valid locations."); putstr(tmpwin, 0, "Use # to toggle automatic description."); /* disgusting hack; the alternate selection characters work for any getpos call, but they only matter for dowhatis (and doquickwhatis) */ @@ -62,7 +62,7 @@ const char *goal; doing_what_is ? " or , or ; or :" : ""); putstr(tmpwin, 0, sbuf); if (!force) - putstr(tmpwin, 0, "Type Space or Escape when you're done."); + putstr(tmpwin, 0, "Type Space or Escape when you're done."); putstr(tmpwin, 0, ""); display_nhwindow(tmpwin, TRUE); destroy_nhwindow(tmpwin); @@ -77,17 +77,18 @@ const char *goal; int result = 0; int cx, cy, i, c; int sidx, tx, ty; - boolean msg_given = TRUE; /* clear message window by default */ + boolean msg_given = TRUE; /* clear message window by default */ boolean auto_msg = FALSE; boolean show_goal_msg = FALSE; static const char pick_chars[] = ".,;:"; const char *cp; boolean hilite_state = FALSE; - if (!goal) goal = "desired location"; + if (!goal) + goal = "desired location"; if (flags.verbose) { - pline("(For instructions type a ?)"); - msg_given = TRUE; + pline("(For instructions type a ?)"); + msg_given = TRUE; } cx = ccp->x; cy = ccp->y; @@ -100,201 +101,209 @@ const char *goal; lock_mouse_cursor(TRUE); #endif for (;;) { + if (show_goal_msg) { + pline("Move cursor to %s:", goal); + curs(WIN_MAP, cx, cy); + flush_screen(0); + show_goal_msg = FALSE; + } else if (auto_msg && !msg_given && !hilite_state) { + coord cc; + int sym = 0; + char tmpbuf[BUFSZ]; + const char *firstmatch = NULL; - if (show_goal_msg) { - pline("Move cursor to %s:", goal); - curs(WIN_MAP, cx, cy); - flush_screen(0); - show_goal_msg = FALSE; - } else if (auto_msg && !msg_given && !hilite_state) { - coord cc; - int sym = 0; - char tmpbuf[BUFSZ]; - const char *firstmatch = NULL; + cc.x = cx; + cc.y = cy; + if (do_screen_description(cc, TRUE, sym, tmpbuf, &firstmatch)) { + pline1(firstmatch); + curs(WIN_MAP, cx, cy); + flush_screen(0); + } + } - cc.x = cx; - cc.y = cy; - if (do_screen_description(cc, TRUE, sym, tmpbuf, &firstmatch)) { - pline1(firstmatch); - curs(WIN_MAP, cx, cy); - flush_screen(0); - } - } + c = nh_poskey(&tx, &ty, &sidx); - c = nh_poskey(&tx, &ty, &sidx); + if (hilite_state) { + (*getpos_hilitefunc)(2); + hilite_state = FALSE; + curs(WIN_MAP, cx, cy); + flush_screen(0); + } - if (hilite_state) { - (*getpos_hilitefunc)(2); - hilite_state = FALSE; - curs(WIN_MAP, cx, cy); - flush_screen(0); - } + if (auto_msg) + msg_given = FALSE; - if (auto_msg) - msg_given = FALSE; + if (c == '\033') { + cx = cy = -10; + msg_given = TRUE; /* force clear */ + result = -1; + break; + } + if (c == 0) { + if (!isok(tx, ty)) + continue; + /* a mouse click event, just assign and return */ + cx = tx; + cy = ty; + break; + } + if ((cp = index(pick_chars, c)) != 0) { + /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */ + result = (int) (cp - pick_chars); + break; + } + for (i = 0; i < 8; i++) { + int dx, dy; - if (c == '\033') { - cx = cy = -10; - msg_given = TRUE; /* force clear */ - result = -1; - break; - } - if(c == 0) { - if (!isok(tx, ty)) continue; - /* a mouse click event, just assign and return */ - cx = tx; - cy = ty; - break; - } - if ((cp = index(pick_chars, c)) != 0) { - /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */ - result = (int)(cp - pick_chars); - break; - } - for (i = 0; i < 8; i++) { - int dx, dy; + if (Cmd.dirchars[i] == c) { + /* a normal movement letter or digit */ + dx = xdir[i]; + dy = ydir[i]; + } else if (Cmd.alphadirchars[i] == lowc((char) c) + || (Cmd.num_pad && Cmd.dirchars[i] == (c & 0177))) { + /* a shifted movement letter or Meta-digit */ + dx = 8 * xdir[i]; + dy = 8 * ydir[i]; + } else + continue; - if (Cmd.dirchars[i] == c) { - /* a normal movement letter or digit */ - dx = xdir[i]; - dy = ydir[i]; - } else if (Cmd.alphadirchars[i] == lowc((char)c) || - (Cmd.num_pad && Cmd.dirchars[i] == (c & 0177))) { - /* a shifted movement letter or Meta-digit */ - dx = 8 * xdir[i]; - dy = 8 * ydir[i]; - } else - continue; + /* truncate at map edge; diagonal moves complicate this... */ + if (cx + dx < 1) { + dy -= sgn(dy) * (1 - (cx + dx)); + dx = 1 - cx; /* so that (cx+dx == 1) */ + } else if (cx + dx > COLNO - 1) { + dy += sgn(dy) * ((COLNO - 1) - (cx + dx)); + dx = (COLNO - 1) - cx; + } + if (cy + dy < 0) { + dx -= sgn(dx) * (0 - (cy + dy)); + dy = 0 - cy; /* so that (cy+dy == 0) */ + } else if (cy + dy > ROWNO - 1) { + dx += sgn(dx) * ((ROWNO - 1) - (cy + dy)); + dy = (ROWNO - 1) - cy; + } + cx += dx; + cy += dy; + goto nxtc; + } - /* truncate at map edge; diagonal moves complicate this... */ - if (cx + dx < 1) { - dy -= sgn(dy) * (1 - (cx + dx)); - dx = 1 - cx; /* so that (cx+dx == 1) */ - } else if (cx + dx > COLNO-1) { - dy += sgn(dy) * ((COLNO-1) - (cx + dx)); - dx = (COLNO-1) - cx; - } - if (cy + dy < 0) { - dx -= sgn(dx) * (0 - (cy + dy)); - dy = 0 - cy; /* so that (cy+dy == 0) */ - } else if (cy + dy > ROWNO-1) { - dx += sgn(dx) * ((ROWNO-1) - (cy + dy)); - dy = (ROWNO-1) - cy; - } - cx += dx; - cy += dy; - goto nxtc; - } + if (c == '?' || redraw_cmd(c)) { + if (c == '?') + getpos_help(force, goal); + else /* ^R */ + docrt(); /* redraw */ + /* update message window to reflect that we're still targetting */ + show_goal_msg = TRUE; + msg_given = TRUE; + } else if ((c == '$') && (getpos_hilitefunc != NULL)) { + if (!hilite_state) { + (*getpos_hilitefunc)(0); + (*getpos_hilitefunc)(1); + hilite_state = TRUE; + } + goto nxtc; + } else if (c == '#') { + auto_msg = !auto_msg; + pline("Automatic description %sis %s.", + flags.verbose ? "of features under cursor " : "", + auto_msg ? "on" : "off"); + if (!auto_msg) + show_goal_msg = TRUE; + msg_given = TRUE; + goto nxtc; + } else if (c == '@') { + cx = u.ux; + cy = u.uy; + goto nxtc; + } else { + if (!index(quitchars, c)) { + char matching[MAXPCHARS]; + int pass, lo_x, lo_y, hi_x, hi_y, k = 0; + (void) memset((genericptr_t) matching, 0, sizeof matching); + for (sidx = 1; sidx < MAXPCHARS; sidx++) + if (c == defsyms[sidx].sym || c == (int) showsyms[sidx]) + matching[sidx] = (char) ++k; + if (k) { + for (pass = 0; pass <= 1; pass++) { + /* pass 0: just past current pos to lower right; + pass 1: upper left corner to current pos */ + lo_y = (pass == 0) ? cy : 0; + hi_y = (pass == 0) ? ROWNO - 1 : cy; + for (ty = lo_y; ty <= hi_y; ty++) { + lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1; + hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1; + for (tx = lo_x; tx <= hi_x; tx++) { + /* look at dungeon feature, not at + * user-visible glyph */ + k = back_to_glyph(tx, ty); + /* uninteresting background glyph */ + if (glyph_is_cmap(k) + && (IS_DOOR(levl[tx][ty].typ) + || glyph_to_cmap(k) == S_room + || glyph_to_cmap(k) == S_darkroom + || glyph_to_cmap(k) == S_corr + || glyph_to_cmap(k) == S_litcorr)) { + /* what the hero remembers to be at tx,ty + */ + k = glyph_at(tx, ty); + } + if (glyph_is_cmap(k) + && matching[glyph_to_cmap(k)] + && levl[tx][ty].seenv + && (!IS_WALL(levl[tx][ty].typ)) + && (levl[tx][ty].typ != SDOOR) + && glyph_to_cmap(k) != S_room + && glyph_to_cmap(k) != S_corr + && glyph_to_cmap(k) != S_litcorr) { + cx = tx, cy = ty; + if (msg_given) { + clear_nhwindow(WIN_MESSAGE); + msg_given = FALSE; + } + goto nxtc; + } + } /* column */ + } /* row */ + } /* pass */ + pline("Can't find dungeon feature '%c'.", c); + msg_given = TRUE; + goto nxtc; + } else { + char note[QBUFSZ]; - if (c == '?' || redraw_cmd(c)) { - if (c == '?') - getpos_help(force, goal); - else /* ^R */ - docrt(); /* redraw */ - /* update message window to reflect that we're still targetting */ - show_goal_msg = TRUE; - msg_given = TRUE; - } else if ((c == '$') && (getpos_hilitefunc != NULL)) { - if (!hilite_state) { - (*getpos_hilitefunc)(0); - (*getpos_hilitefunc)(1); - hilite_state = TRUE; - } - goto nxtc; - } else if (c == '#') { - auto_msg = !auto_msg; - pline("Automatic description %sis %s.", - flags.verbose ? "of features under cursor " : "", - auto_msg ? "on" : "off"); - if (!auto_msg) show_goal_msg = TRUE; - msg_given = TRUE; - goto nxtc; - } else if (c == '@') { - cx = u.ux; - cy = u.uy; - goto nxtc; - } else { - if (!index(quitchars, c)) { - char matching[MAXPCHARS]; - int pass, lo_x, lo_y, hi_x, hi_y, k = 0; - (void)memset((genericptr_t)matching, 0, sizeof matching); - for (sidx = 1; sidx < MAXPCHARS; sidx++) - if (c == defsyms[sidx].sym || c == (int)showsyms[sidx]) - matching[sidx] = (char) ++k; - if (k) { - for (pass = 0; pass <= 1; pass++) { - /* pass 0: just past current pos to lower right; - pass 1: upper left corner to current pos */ - lo_y = (pass == 0) ? cy : 0; - hi_y = (pass == 0) ? ROWNO - 1 : cy; - for (ty = lo_y; ty <= hi_y; ty++) { - lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1; - hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1; - for (tx = lo_x; tx <= hi_x; tx++) { - /* look at dungeon feature, not at user-visible glyph */ - k = back_to_glyph(tx,ty); - /* uninteresting background glyph */ - if (glyph_is_cmap(k) && - (IS_DOOR(levl[tx][ty].typ) || - glyph_to_cmap(k) == S_room || - glyph_to_cmap(k) == S_darkroom || - glyph_to_cmap(k) == S_corr || - glyph_to_cmap(k) == S_litcorr)) { - /* what the hero remembers to be at tx,ty */ - k = glyph_at(tx, ty); - } - if (glyph_is_cmap(k) && - matching[glyph_to_cmap(k)] && - levl[tx][ty].seenv && - (!IS_WALL(levl[tx][ty].typ)) && - (levl[tx][ty].typ != SDOOR) && - glyph_to_cmap(k) != S_room && - glyph_to_cmap(k) != S_corr && - glyph_to_cmap(k) != S_litcorr) { - cx = tx, cy = ty; - if (msg_given) { - clear_nhwindow(WIN_MESSAGE); - msg_given = FALSE; - } - goto nxtc; - } - } /* column */ - } /* row */ - } /* pass */ - pline("Can't find dungeon feature '%c'.", c); - msg_given = TRUE; - goto nxtc; - } else { - char note[QBUFSZ]; - - if (!force) Strcpy(note, "aborted"); - else Sprintf(note, "use %c%c%c%c or .", /* hjkl */ - Cmd.move_W, Cmd.move_S, - Cmd.move_N, Cmd.move_E); - pline("Unknown direction: '%s' (%s).", - visctrl((char)c), note); - msg_given = TRUE; - } /* k => matching */ - } /* !quitchars */ - if (force) goto nxtc; - pline("Done."); - msg_given = FALSE; /* suppress clear */ - cx = -1; - cy = 0; - result = 0; /* not -1 */ - break; - } - nxtc: ; + if (!force) + Strcpy(note, "aborted"); + else + Sprintf(note, "use %c%c%c%c or .", /* hjkl */ + Cmd.move_W, Cmd.move_S, Cmd.move_N, + Cmd.move_E); + pline("Unknown direction: '%s' (%s).", visctrl((char) c), + note); + msg_given = TRUE; + } /* k => matching */ + } /* !quitchars */ + if (force) + goto nxtc; + pline("Done."); + msg_given = FALSE; /* suppress clear */ + cx = -1; + cy = 0; + result = 0; /* not -1 */ + break; + } + nxtc: + ; #ifdef CLIPPING - cliparound(cx, cy); + cliparound(cx, cy); #endif - curs(WIN_MAP, cx, cy); - flush_screen(0); + curs(WIN_MAP, cx, cy); + flush_screen(0); } #ifdef MAC lock_mouse_cursor(FALSE); #endif - if (msg_given) clear_nhwindow(WIN_MESSAGE); + if (msg_given) + clear_nhwindow(WIN_MESSAGE); ccp->x = cx; ccp->y = cy; getpos_hilitefunc = NULL; @@ -305,16 +314,19 @@ const char *goal; void new_mname(mon, lth) struct monst *mon; -int lth; /* desired length (caller handles adding 1 for terminator) */ +int lth; /* desired length (caller handles adding 1 for terminator) */ { if (lth) { - /* allocate mextra if necessary; otherwise get rid of old name */ - if (!mon->mextra) mon->mextra = newmextra(); - else free_mname(mon); /* already has mextra, might also have name */ - MNAME(mon) = (char *) alloc((unsigned) lth); + /* allocate mextra if necessary; otherwise get rid of old name */ + if (!mon->mextra) + mon->mextra = newmextra(); + else + free_mname(mon); /* already has mextra, might also have name */ + MNAME(mon) = (char *) alloc((unsigned) lth); } else { - /* zero length: the new name is empty; get rid of the old name */ - if (has_mname(mon)) free_mname(mon); + /* zero length: the new name is empty; get rid of the old name */ + if (has_mname(mon)) + free_mname(mon); } } @@ -324,8 +336,8 @@ free_mname(mon) struct monst *mon; { if (has_mname(mon)) { - free((genericptr_t)MNAME(mon)); - MNAME(mon) = (char *)0; + free((genericptr_t) MNAME(mon)); + MNAME(mon) = (char *) 0; } } @@ -333,16 +345,19 @@ struct monst *mon; void new_oname(obj, lth) struct obj *obj; -int lth; /* desired length (caller handles adding 1 for terminator) */ +int lth; /* desired length (caller handles adding 1 for terminator) */ { if (lth) { - /* allocate oextra if necessary; otherwise get rid of old name */ - if (!obj->oextra) obj->oextra = newoextra(); - else free_oname(obj); /* already has oextra, might also have name */ - ONAME(obj) = (char *) alloc((unsigned) lth); + /* allocate oextra if necessary; otherwise get rid of old name */ + if (!obj->oextra) + obj->oextra = newoextra(); + else + free_oname(obj); /* already has oextra, might also have name */ + ONAME(obj) = (char *) alloc((unsigned) lth); } else { - /* zero length: the new name is empty; get rid of the old name */ - if (has_oname(obj)) free_oname(obj); + /* zero length: the new name is empty; get rid of the old name */ + if (has_oname(obj)) + free_oname(obj); } } @@ -352,8 +367,8 @@ free_oname(obj) struct obj *obj; { if (has_oname(obj)) { - free((genericptr_t)ONAME(obj)); - ONAME(obj) = (char *)0; + free((genericptr_t) ONAME(obj)); + ONAME(obj) = (char *) 0; } } @@ -367,9 +382,9 @@ safe_oname(obj) struct obj *obj; { if (has_oname(obj)) - return ONAME(obj); + return ONAME(obj); else - return ""; + return ""; } /* historical note: this returns a monster pointer because it used to @@ -379,82 +394,85 @@ christen_monst(mtmp, name) struct monst *mtmp; const char *name; { - int lth; - char buf[PL_PSIZ]; + int lth; + char buf[PL_PSIZ]; - /* dogname & catname are PL_PSIZ arrays; object names have same limit */ - lth = (name && *name) ? ((int)strlen(name) + 1) : 0; - if (lth > PL_PSIZ) { - lth = PL_PSIZ; - name = strncpy(buf, name, PL_PSIZ - 1); - buf[PL_PSIZ - 1] = '\0'; - } - new_mname(mtmp, lth); /* removes old name if one is present */ - if (lth) Strcpy(MNAME(mtmp), name); - return mtmp; + /* dogname & catname are PL_PSIZ arrays; object names have same limit */ + lth = (name && *name) ? ((int) strlen(name) + 1) : 0; + if (lth > PL_PSIZ) { + lth = PL_PSIZ; + name = strncpy(buf, name, PL_PSIZ - 1); + buf[PL_PSIZ - 1] = '\0'; + } + new_mname(mtmp, lth); /* removes old name if one is present */ + if (lth) + Strcpy(MNAME(mtmp), name); + return mtmp; } /* allow player to assign a name to some chosen monster */ STATIC_OVL void do_mname() { - char buf[BUFSZ], monnambuf[BUFSZ]; - coord cc; - register int cx,cy; - register struct monst *mtmp; - char qbuf[QBUFSZ]; + char buf[BUFSZ], monnambuf[BUFSZ]; + coord cc; + register int cx, cy; + register struct monst *mtmp; + char qbuf[QBUFSZ]; - if (Hallucination) { - You("would never recognize it anyway."); - return; - } - cc.x = u.ux; - cc.y = u.uy; - if (getpos(&cc, FALSE, "the monster you want to name") < 0 || - (cx = cc.x) < 0) - return; - cy = cc.y; + if (Hallucination) { + You("would never recognize it anyway."); + return; + } + cc.x = u.ux; + cc.y = u.uy; + if (getpos(&cc, FALSE, "the monster you want to name") < 0 + || (cx = cc.x) < 0) + return; + cy = cc.y; - if (cx == u.ux && cy == u.uy) { - if (u.usteed && canspotmon(u.usteed)) - mtmp = u.usteed; - else { - pline("This %s creature is called %s and cannot be renamed.", - beautiful(), plname); - return; - } - } else - mtmp = m_at(cx, cy); + if (cx == u.ux && cy == u.uy) { + if (u.usteed && canspotmon(u.usteed)) + mtmp = u.usteed; + else { + pline("This %s creature is called %s and cannot be renamed.", + beautiful(), plname); + return; + } + } else + mtmp = m_at(cx, cy); - if (!mtmp || (!sensemon(mtmp) && - (!(cansee(cx,cy) || see_with_infrared(mtmp)) || mtmp->mundetected - || mtmp->m_ap_type == M_AP_FURNITURE - || mtmp->m_ap_type == M_AP_OBJECT - || (mtmp->minvis && !See_invisible)))) { - pline("I see no monster there."); - return; - } - /* special case similar to the one in lookat() */ - Sprintf(qbuf, "What do you want to call %s?", - distant_monnam(mtmp, ARTICLE_THE, monnambuf)); - getlin(qbuf,buf); - if (!*buf || *buf == '\033') return; - /* strip leading and trailing spaces; unnames monster if all spaces */ - (void)mungspaces(buf); + if (!mtmp + || (!sensemon(mtmp) + && (!(cansee(cx, cy) || see_with_infrared(mtmp)) + || mtmp->mundetected || mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT + || (mtmp->minvis && !See_invisible)))) { + pline("I see no monster there."); + return; + } + /* special case similar to the one in lookat() */ + Sprintf(qbuf, "What do you want to call %s?", + distant_monnam(mtmp, ARTICLE_THE, monnambuf)); + getlin(qbuf, buf); + if (!*buf || *buf == '\033') + return; + /* strip leading and trailing spaces; unnames monster if all spaces */ + (void) mungspaces(buf); - /* unique monsters have their own specific names or titles; - shopkeepers, temple priests and other minions use alternate - name formatting routines which ignore any user-supplied name */ - if (mtmp->data->geno & G_UNIQ) - pline("%s doesn't like being called names!", upstart(monnambuf)); - else if (mtmp->isshk && - !(Deaf || mtmp->msleeping || - !mtmp->mcanmove || mtmp->data->msound <= MS_ANIMAL)) - verbalize("I'm %s, not %s.", shkname(mtmp), buf); - else if (mtmp->ispriest || mtmp->isminion || mtmp->isshk) - pline("%s will not accept the name %s.", upstart(monnambuf), buf); - else - (void) christen_monst(mtmp, buf); + /* unique monsters have their own specific names or titles; + shopkeepers, temple priests and other minions use alternate + name formatting routines which ignore any user-supplied name */ + if (mtmp->data->geno & G_UNIQ) + pline("%s doesn't like being called names!", upstart(monnambuf)); + else if (mtmp->isshk + && !(Deaf || mtmp->msleeping || !mtmp->mcanmove + || mtmp->data->msound <= MS_ANIMAL)) + verbalize("I'm %s, not %s.", shkname(mtmp), buf); + else if (mtmp->ispriest || mtmp->isminion || mtmp->isshk) + pline("%s will not accept the name %s.", upstart(monnambuf), buf); + else + (void) christen_monst(mtmp, buf); } /* @@ -467,54 +485,55 @@ void do_oname(obj) register struct obj *obj; { - char *bufp, buf[BUFSZ], bufcpy[BUFSZ], qbuf[QBUFSZ]; - const char *aname; - short objtyp; + char *bufp, buf[BUFSZ], bufcpy[BUFSZ], qbuf[QBUFSZ]; + const char *aname; + short objtyp; - /* Do this now because there's no point in even asking for a name */ - if (obj->otyp == SPE_NOVEL) { - pline("%s already has a published name.", Ysimple_name2(obj)); - return; - } - - Sprintf(qbuf, "What do you want to name %s ", - is_plural(obj) ? "these" : "this"); - (void)safe_qbuf(qbuf, qbuf, "?", obj, xname, simpleonames, "item"); - getlin(qbuf, buf); - if(!*buf || *buf == '\033') return; - /* strip leading and trailing spaces; unnames item if all spaces */ - (void)mungspaces(buf); + /* Do this now because there's no point in even asking for a name */ + if (obj->otyp == SPE_NOVEL) { + pline("%s already has a published name.", Ysimple_name2(obj)); + return; + } - /* relax restrictions over proper capitalization for artifacts */ - if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp) - Strcpy(buf, aname); + Sprintf(qbuf, "What do you want to name %s ", + is_plural(obj) ? "these" : "this"); + (void) safe_qbuf(qbuf, qbuf, "?", obj, xname, simpleonames, "item"); + getlin(qbuf, buf); + if (!*buf || *buf == '\033') + return; + /* strip leading and trailing spaces; unnames item if all spaces */ + (void) mungspaces(buf); - if (obj->oartifact) { - pline_The("artifact seems to resist the attempt."); - return; - } else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) { - /* this used to change one letter, substituting a value - of 'a' through 'y' (due to an off by one error, 'z' - would never be selected) and then force that to - upper case if such was the case of the input; - now, the hand slip scuffs one or two letters as if - the text had been trodden upon, sometimes picking - punctuation instead of an arbitrary letter; - unfortunately, we have to cover the possibility of - it targetting spaces so failing to make any change - (we know that it must eventually target a nonspace - because buf[] matches a valid artifact name) */ - Strcpy(bufcpy, buf); - /* for "the Foo of Bar", only scuff "Foo of Bar" part */ - bufp = !strncmpi(bufcpy, "the ", 4) ? (buf + 4) : buf; - do { - wipeout_text(bufp, rnd(2), (unsigned)0); - } while (!strcmp(buf, bufcpy)); - pline("While engraving, your %s slips.", body_part(HAND)); - display_nhwindow(WIN_MESSAGE, FALSE); - You("engrave: \"%s\".",buf); - } - obj = oname(obj, buf); + /* relax restrictions over proper capitalization for artifacts */ + if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp) + Strcpy(buf, aname); + + if (obj->oartifact) { + pline_The("artifact seems to resist the attempt."); + return; + } else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) { + /* this used to change one letter, substituting a value + of 'a' through 'y' (due to an off by one error, 'z' + would never be selected) and then force that to + upper case if such was the case of the input; + now, the hand slip scuffs one or two letters as if + the text had been trodden upon, sometimes picking + punctuation instead of an arbitrary letter; + unfortunately, we have to cover the possibility of + it targetting spaces so failing to make any change + (we know that it must eventually target a nonspace + because buf[] matches a valid artifact name) */ + Strcpy(bufcpy, buf); + /* for "the Foo of Bar", only scuff "Foo of Bar" part */ + bufp = !strncmpi(bufcpy, "the ", 4) ? (buf + 4) : buf; + do { + wipeout_text(bufp, rnd(2), (unsigned) 0); + } while (!strcmp(buf, bufcpy)); + pline("While engraving, your %s slips.", body_part(HAND)); + display_nhwindow(WIN_MESSAGE, FALSE); + You("engrave: \"%s\".", buf); + } + obj = oname(obj, buf); } struct obj * @@ -522,199 +541,211 @@ oname(obj, name) struct obj *obj; const char *name; { - int lth; - char buf[PL_PSIZ]; + int lth; + char buf[PL_PSIZ]; - lth = *name ? (int)(strlen(name) + 1) : 0; - if (lth > PL_PSIZ) { - lth = PL_PSIZ; - name = strncpy(buf, name, PL_PSIZ - 1); - buf[PL_PSIZ - 1] = '\0'; - } - /* If named artifact exists in the game, do not create another. - * Also trying to create an artifact shouldn't de-artifact - * it (e.g. Excalibur from prayer). In this case the object - * will retain its current name. */ - if (obj->oartifact || (lth && exist_artifact(obj->otyp, name))) - return obj; + lth = *name ? (int) (strlen(name) + 1) : 0; + if (lth > PL_PSIZ) { + lth = PL_PSIZ; + name = strncpy(buf, name, PL_PSIZ - 1); + buf[PL_PSIZ - 1] = '\0'; + } + /* If named artifact exists in the game, do not create another. + * Also trying to create an artifact shouldn't de-artifact + * it (e.g. Excalibur from prayer). In this case the object + * will retain its current name. */ + if (obj->oartifact || (lth && exist_artifact(obj->otyp, name))) + return obj; - new_oname(obj, lth); /* removes old name if one is present */ - if (lth) Strcpy(ONAME(obj), name); + new_oname(obj, lth); /* removes old name if one is present */ + if (lth) + Strcpy(ONAME(obj), name); - if (lth) artifact_exists(obj, name, TRUE); - if (obj->oartifact) { - /* can't dual-wield with artifact as secondary weapon */ - if (obj == uswapwep) untwoweapon(); - /* activate warning if you've just named your weapon "Sting" */ - if (obj == uwep) set_artifact_intrinsic(obj, TRUE, W_WEP); - /* if obj is owned by a shop, increase your bill */ - if (obj->unpaid) alter_cost(obj, 0L); - } - if (carried(obj)) update_inventory(); - return obj; + if (lth) + artifact_exists(obj, name, TRUE); + if (obj->oartifact) { + /* can't dual-wield with artifact as secondary weapon */ + if (obj == uswapwep) + untwoweapon(); + /* activate warning if you've just named your weapon "Sting" */ + if (obj == uwep) + set_artifact_intrinsic(obj, TRUE, W_WEP); + /* if obj is owned by a shop, increase your bill */ + if (obj->unpaid) + alter_cost(obj, 0L); + } + if (carried(obj)) + update_inventory(); + return obj; } static NEARDATA const char callable[] = { - SCROLL_CLASS, POTION_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS, - GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0 }; + SCROLL_CLASS, POTION_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS, + GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0 +}; boolean objtyp_is_callable(i) int i; { - return (boolean)(objects[i].oc_uname || - (OBJ_DESCR(objects[i]) && - index(callable, objects[i].oc_class))); + return (boolean)( + objects[i].oc_uname + || (OBJ_DESCR(objects[i]) && index(callable, objects[i].oc_class))); } /* C and #name commands - player can name monster or object or type of obj */ int docallcmd() { - struct obj *obj; - winid win; - anything any; - menu_item *pick_list = 0; - char ch, allowall[2]; + struct obj *obj; + winid win; + anything any; + menu_item *pick_list = 0; + char ch, allowall[2]; - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; - any.a_char = 'm'; /* entry 'a', group accelator 'C' */ - add_menu(win, NO_GLYPH, &any, 0, 'C', ATR_NONE, - "a monster", MENU_UNSELECTED); - if (invent) { - /* we use y and n as accelerators so that we can accept user's - response keyed to old "name an individual object?" prompt */ - any.a_char = 'i'; /* entry 'b', group accelator 'y' */ - add_menu(win, NO_GLYPH, &any, 0, 'y', ATR_NONE, - "a particular object in inventory", MENU_UNSELECTED); - any.a_char = 'o'; /* entry 'c', group accelator 'n' */ - add_menu(win, NO_GLYPH, &any, 0, 'n', ATR_NONE, - "the type of an object in inventory", MENU_UNSELECTED); - } - any.a_char = 'd'; /* entry 'd' (or 'b'), group accelator 'd' */ - add_menu(win, NO_GLYPH, &any, 0, any.a_char, ATR_NONE, - "the type of an object on discoveries list", MENU_UNSELECTED); - any.a_char = 'e'; - add_menu(win, NO_GLYPH, &any, 0, any.a_char, ATR_NONE, - "the current level", MENU_UNSELECTED); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; + any.a_char = 'm'; /* entry 'a', group accelator 'C' */ + add_menu(win, NO_GLYPH, &any, 0, 'C', ATR_NONE, "a monster", + MENU_UNSELECTED); + if (invent) { + /* we use y and n as accelerators so that we can accept user's + response keyed to old "name an individual object?" prompt */ + any.a_char = 'i'; /* entry 'b', group accelator 'y' */ + add_menu(win, NO_GLYPH, &any, 0, 'y', ATR_NONE, + "a particular object in inventory", MENU_UNSELECTED); + any.a_char = 'o'; /* entry 'c', group accelator 'n' */ + add_menu(win, NO_GLYPH, &any, 0, 'n', ATR_NONE, + "the type of an object in inventory", MENU_UNSELECTED); + } + any.a_char = 'd'; /* entry 'd' (or 'b'), group accelator 'd' */ + add_menu(win, NO_GLYPH, &any, 0, any.a_char, ATR_NONE, + "the type of an object on discoveries list", MENU_UNSELECTED); + any.a_char = 'e'; + add_menu(win, NO_GLYPH, &any, 0, any.a_char, ATR_NONE, + "the current level", MENU_UNSELECTED); #if 0 any.a_char = 'f'; /* entry 'e' (or 'c'), group accelator 'f' */ add_menu(win, NO_GLYPH, &any, 0, any.a_char, ATR_NONE, "the type of an object upon the floor", MENU_UNSELECTED); #endif - end_menu(win, "What do you want to name?"); - if (select_menu(win, PICK_ONE, &pick_list) > 0) { - ch = pick_list[0].item.a_char; - free((genericptr_t)pick_list); - } else - ch = 'q'; - destroy_nhwindow(win); + end_menu(win, "What do you want to name?"); + if (select_menu(win, PICK_ONE, &pick_list) > 0) { + ch = pick_list[0].item.a_char; + free((genericptr_t) pick_list); + } else + ch = 'q'; + destroy_nhwindow(win); - switch (ch) { - default: - case 'q': - break; - case 'm': /* name a visible monster */ - do_mname(); - break; - case 'i': /* name an individual object in inventory */ - allowall[0] = ALL_CLASSES; allowall[1] = '\0'; - obj = getobj(allowall, "name"); - if(obj) do_oname(obj); - break; - case 'o': /* name a type of object in inventory */ - obj = getobj(callable, "call"); - if (obj) { - /* behave as if examining it in inventory; - this might set dknown if it was picked up - while blind and the hero can now see */ - (void) xname(obj); + switch (ch) { + default: + case 'q': + break; + case 'm': /* name a visible monster */ + do_mname(); + break; + case 'i': /* name an individual object in inventory */ + allowall[0] = ALL_CLASSES; + allowall[1] = '\0'; + obj = getobj(allowall, "name"); + if (obj) + do_oname(obj); + break; + case 'o': /* name a type of object in inventory */ + obj = getobj(callable, "call"); + if (obj) { + /* behave as if examining it in inventory; + this might set dknown if it was picked up + while blind and the hero can now see */ + (void) xname(obj); - if (!obj->dknown) { - You("would never recognize another one."); + if (!obj->dknown) { + You("would never recognize another one."); #if 0 } else if (!objtyp_is_callable(obj->otyp)) { You("know those as well as you ever will."); #endif - } else { - docall(obj); - } - } - break; - case 'd': /* name a type of object on the discoveries list */ - rename_disco(); - break; - case 'e': /* annotate level */ - donamelevel(); - break; + } else { + docall(obj); + } + } + break; + case 'd': /* name a type of object on the discoveries list */ + rename_disco(); + break; + case 'e': /* annotate level */ + donamelevel(); + break; #if 0 case 'f': /* name a type of object visible on the floor */ /* [not implemented] */ break; #endif - } - return 0; + } + return 0; } void docall(obj) register struct obj *obj; { - char buf[BUFSZ], qbuf[QBUFSZ]; - struct obj otemp; - register char **str1; + char buf[BUFSZ], qbuf[QBUFSZ]; + struct obj otemp; + register char **str1; - if (!obj->dknown) return; /* probably blind */ - otemp = *obj; - otemp.quan = 1L; - otemp.oextra = (struct oextra *)0; + if (!obj->dknown) + return; /* probably blind */ + otemp = *obj; + otemp.quan = 1L; + otemp.oextra = (struct oextra *) 0; - if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.fromsink) - /* kludge, meaning it's sink water */ - Sprintf(qbuf,"Call a stream of %s fluid:", - OBJ_DESCR(objects[otemp.otyp])); - else - Sprintf(qbuf, "Call %s:", an(xname(&otemp))); - getlin(qbuf, buf); - if(!*buf || *buf == '\033') - return; + if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.fromsink) + /* kludge, meaning it's sink water */ + Sprintf(qbuf, "Call a stream of %s fluid:", + OBJ_DESCR(objects[otemp.otyp])); + else + Sprintf(qbuf, "Call %s:", an(xname(&otemp))); + getlin(qbuf, buf); + if (!*buf || *buf == '\033') + return; - /* clear old name */ - str1 = &(objects[obj->otyp].oc_uname); - if(*str1) free((genericptr_t)*str1); + /* clear old name */ + str1 = &(objects[obj->otyp].oc_uname); + if (*str1) + free((genericptr_t) *str1); - /* strip leading and trailing spaces; uncalls item if all spaces */ - (void)mungspaces(buf); - if (!*buf) { - if (*str1) { /* had name, so possibly remove from disco[] */ - /* strip name first, for the update_inventory() call - from undiscover_object() */ - *str1 = (char *)0; - undiscover_object(obj->otyp); - } - } else { - *str1 = dupstr(buf); - discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */ - } + /* strip leading and trailing spaces; uncalls item if all spaces */ + (void) mungspaces(buf); + if (!*buf) { + if (*str1) { /* had name, so possibly remove from disco[] */ + /* strip name first, for the update_inventory() call + from undiscover_object() */ + *str1 = (char *) 0; + undiscover_object(obj->otyp); + } + } else { + *str1 = dupstr(buf); + discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */ + } } -static const char * const ghostnames[] = { - /* these names should have length < PL_NSIZ */ - /* Capitalize the names for aesthetics -dgk */ - "Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile", - "Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Karnov", - "Kay", "Kenny", "Kevin", "Maud", "Michiel", "Mike", "Peter", "Robert", - "Ron", "Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue", - "Stephan", "Lance Braccus", "Shadowhawk" +static const char *const ghostnames[] = { + /* these names should have length < PL_NSIZ */ + /* Capitalize the names for aesthetics -dgk */ + "Adri", "Andries", "Andreas", "Bert", "David", "Dirk", + "Emile", "Frans", "Fred", "Greg", "Hether", "Jay", + "John", "Jon", "Karnov", "Kay", "Kenny", "Kevin", + "Maud", "Michiel", "Mike", "Peter", "Robert", "Ron", + "Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue", + "Stephan", "Lance Braccus", "Shadowhawk" }; /* ghost names formerly set by x_monnam(), now by makemon() instead */ const char * rndghostname() { - return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *)plname; + return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *) plname; } /* Monster naming functions: @@ -722,7 +753,8 @@ rndghostname() * seen unseen detected named * mon_nam: the newt it the invisible orc Fido * noit_mon_nam:the newt (as if detected) the invisible orc Fido - * l_monnam: newt it invisible orc dog called fido + * l_monnam: newt it invisible orc dog called + *fido * Monnam: The newt It The invisible orc Fido * noit_Monnam: The newt (as if detected) The invisible orc Fido * Adjmonnam: The poor newt It The poor invisible orc The poor Fido @@ -753,187 +785,185 @@ int suppress; */ boolean called; { - char *buf = nextmbuf(); - struct permonst *mdat = mtmp->data; - const char *pm_name = mdat->mname; - boolean do_hallu, do_invis, do_it, do_saddle; - boolean name_at_start, has_adjectives; - char *bp; + char *buf = nextmbuf(); + struct permonst *mdat = mtmp->data; + const char *pm_name = mdat->mname; + boolean do_hallu, do_invis, do_it, do_saddle; + boolean name_at_start, has_adjectives; + char *bp; - if (program_state.gameover) - suppress |= SUPPRESS_HALLUCINATION; - if (article == ARTICLE_YOUR && !mtmp->mtame) - article = ARTICLE_THE; + if (program_state.gameover) + suppress |= SUPPRESS_HALLUCINATION; + if (article == ARTICLE_YOUR && !mtmp->mtame) + article = ARTICLE_THE; - do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION); - do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE); - do_it = !canspotmon(mtmp) && - article != ARTICLE_YOUR && - !program_state.gameover && - mtmp != u.usteed && - !(u.uswallow && mtmp == u.ustuck) && - !(suppress & SUPPRESS_IT); - do_saddle = !(suppress & SUPPRESS_SADDLE); + do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION); + do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE); + do_it = !canspotmon(mtmp) && article != ARTICLE_YOUR + && !program_state.gameover && mtmp != u.usteed + && !(u.uswallow && mtmp == u.ustuck) && !(suppress & SUPPRESS_IT); + do_saddle = !(suppress & SUPPRESS_SADDLE); - buf[0] = '\0'; + buf[0] = '\0'; - /* unseen monsters, etc. Use "it" */ - if (do_it) { - Strcpy(buf, "it"); - return buf; - } + /* unseen monsters, etc. Use "it" */ + if (do_it) { + Strcpy(buf, "it"); + return buf; + } - /* priests and minions: don't even use this function */ - if (mtmp->ispriest || mtmp->isminion) { - char priestnambuf[BUFSZ]; - char *name; - long save_prop = EHalluc_resistance; - unsigned save_invis = mtmp->minvis; + /* priests and minions: don't even use this function */ + if (mtmp->ispriest || mtmp->isminion) { + char priestnambuf[BUFSZ]; + char *name; + long save_prop = EHalluc_resistance; + unsigned save_invis = mtmp->minvis; - /* when true name is wanted, explicitly block Hallucination */ - if (!do_hallu) EHalluc_resistance = 1L; - if (!do_invis) mtmp->minvis = 0; - name = priestname(mtmp, priestnambuf); - EHalluc_resistance = save_prop; - mtmp->minvis = save_invis; - if (article == ARTICLE_NONE && !strncmp(name, "the ", 4)) - name += 4; - return strcpy(buf, name); - } - /* an "aligned priest" not flagged as a priest or minion should be - "priest" or "priestess" (normally handled by priestname()) */ - if (mdat == &mons[PM_ALIGNED_PRIEST]) - pm_name = mtmp->female ? "priestess" : "priest"; - else if (mdat == &mons[PM_HIGH_PRIEST] && mtmp->female) - pm_name = "high priestess"; + /* when true name is wanted, explicitly block Hallucination */ + if (!do_hallu) + EHalluc_resistance = 1L; + if (!do_invis) + mtmp->minvis = 0; + name = priestname(mtmp, priestnambuf); + EHalluc_resistance = save_prop; + mtmp->minvis = save_invis; + if (article == ARTICLE_NONE && !strncmp(name, "the ", 4)) + name += 4; + return strcpy(buf, name); + } + /* an "aligned priest" not flagged as a priest or minion should be + "priest" or "priestess" (normally handled by priestname()) */ + if (mdat == &mons[PM_ALIGNED_PRIEST]) + pm_name = mtmp->female ? "priestess" : "priest"; + else if (mdat == &mons[PM_HIGH_PRIEST] && mtmp->female) + pm_name = "high priestess"; - /* Shopkeepers: use shopkeeper name. For normal shopkeepers, just - * "Asidonhopo"; for unusual ones, "Asidonhopo the invisible - * shopkeeper" or "Asidonhopo the blue dragon". If hallucinating, - * none of this applies. - */ - if (mtmp->isshk && !do_hallu) { - if (adjective && article == ARTICLE_THE) { - /* pathological case: "the angry Asidonhopo the blue dragon" - sounds silly */ - Strcpy(buf, "the "); - Strcat(strcat(buf, adjective), " "); - Strcat(buf, shkname(mtmp)); - return buf; - } - Strcat(buf, shkname(mtmp)); - if (mdat == &mons[PM_SHOPKEEPER] && !do_invis) - return buf; - Strcat(buf, " the "); - if (do_invis) - Strcat(buf, "invisible "); - Strcat(buf, pm_name); - return buf; - } + /* Shopkeepers: use shopkeeper name. For normal shopkeepers, just + * "Asidonhopo"; for unusual ones, "Asidonhopo the invisible + * shopkeeper" or "Asidonhopo the blue dragon". If hallucinating, + * none of this applies. + */ + if (mtmp->isshk && !do_hallu) { + if (adjective && article == ARTICLE_THE) { + /* pathological case: "the angry Asidonhopo the blue dragon" + sounds silly */ + Strcpy(buf, "the "); + Strcat(strcat(buf, adjective), " "); + Strcat(buf, shkname(mtmp)); + return buf; + } + Strcat(buf, shkname(mtmp)); + if (mdat == &mons[PM_SHOPKEEPER] && !do_invis) + return buf; + Strcat(buf, " the "); + if (do_invis) + Strcat(buf, "invisible "); + Strcat(buf, pm_name); + return buf; + } - /* Put the adjectives in the buffer */ - if (adjective) - Strcat(strcat(buf, adjective), " "); - if (do_invis) - Strcat(buf, "invisible "); - if (do_saddle && (mtmp->misc_worn_check & W_SADDLE) && - !Blind && !Hallucination) - Strcat(buf, "saddled "); - if (buf[0] != 0) - has_adjectives = TRUE; - else - has_adjectives = FALSE; + /* Put the adjectives in the buffer */ + if (adjective) + Strcat(strcat(buf, adjective), " "); + if (do_invis) + Strcat(buf, "invisible "); + if (do_saddle && (mtmp->misc_worn_check & W_SADDLE) && !Blind + && !Hallucination) + Strcat(buf, "saddled "); + if (buf[0] != 0) + has_adjectives = TRUE; + else + has_adjectives = FALSE; - /* Put the actual monster name or type into the buffer now */ - /* Be sure to remember whether the buffer starts with a name */ - if (do_hallu) { - char rnamecode; - char *rname = rndmonnam(&rnamecode); - Strcat(buf, rname); - name_at_start = bogon_is_pname(rnamecode); - } else if (has_mname(mtmp)) { - char *name = MNAME(mtmp); + /* Put the actual monster name or type into the buffer now */ + /* Be sure to remember whether the buffer starts with a name */ + if (do_hallu) { + char rnamecode; + char *rname = rndmonnam(&rnamecode); + Strcat(buf, rname); + name_at_start = bogon_is_pname(rnamecode); + } else if (has_mname(mtmp)) { + char *name = MNAME(mtmp); - if (mdat == &mons[PM_GHOST]) { - Sprintf(eos(buf), "%s ghost", s_suffix(name)); - name_at_start = TRUE; - } else if (called) { - Sprintf(eos(buf), "%s called %s", pm_name, name); - name_at_start = (boolean)type_is_pname(mdat); - } else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) { - /* the */ - char pbuf[BUFSZ]; + if (mdat == &mons[PM_GHOST]) { + Sprintf(eos(buf), "%s ghost", s_suffix(name)); + name_at_start = TRUE; + } else if (called) { + Sprintf(eos(buf), "%s called %s", pm_name, name); + name_at_start = (boolean) type_is_pname(mdat); + } else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) { + /* the */ + char pbuf[BUFSZ]; - Strcpy(pbuf, name); - pbuf[bp - name + 5] = '\0'; /* adjectives right after " the " */ - if (has_adjectives) - Strcat(pbuf, buf); - Strcat(pbuf, bp + 5); /* append the rest of the name */ - Strcpy(buf, pbuf); - article = ARTICLE_NONE; - name_at_start = TRUE; - } else { - Strcat(buf, name); - name_at_start = TRUE; - } - } else if (is_mplayer(mdat) && !In_endgame(&u.uz)) { - char pbuf[BUFSZ]; - Strcpy(pbuf, rank_of((int)mtmp->m_lev, - monsndx(mdat), - (boolean)mtmp->female)); - Strcat(buf, lcase(pbuf)); - name_at_start = FALSE; - } else { - Strcat(buf, pm_name); - name_at_start = (boolean)type_is_pname(mdat); - } + Strcpy(pbuf, name); + pbuf[bp - name + 5] = '\0'; /* adjectives right after " the " */ + if (has_adjectives) + Strcat(pbuf, buf); + Strcat(pbuf, bp + 5); /* append the rest of the name */ + Strcpy(buf, pbuf); + article = ARTICLE_NONE; + name_at_start = TRUE; + } else { + Strcat(buf, name); + name_at_start = TRUE; + } + } else if (is_mplayer(mdat) && !In_endgame(&u.uz)) { + char pbuf[BUFSZ]; + Strcpy(pbuf, rank_of((int) mtmp->m_lev, monsndx(mdat), + (boolean) mtmp->female)); + Strcat(buf, lcase(pbuf)); + name_at_start = FALSE; + } else { + Strcat(buf, pm_name); + name_at_start = (boolean) type_is_pname(mdat); + } - if (name_at_start && (article == ARTICLE_YOUR || !has_adjectives)) { - if (mdat == &mons[PM_WIZARD_OF_YENDOR]) - article = ARTICLE_THE; - else - article = ARTICLE_NONE; - } else if ((mdat->geno & G_UNIQ) && article == ARTICLE_A) { - article = ARTICLE_THE; - } + if (name_at_start && (article == ARTICLE_YOUR || !has_adjectives)) { + if (mdat == &mons[PM_WIZARD_OF_YENDOR]) + article = ARTICLE_THE; + else + article = ARTICLE_NONE; + } else if ((mdat->geno & G_UNIQ) && article == ARTICLE_A) { + article = ARTICLE_THE; + } - { - char buf2[BUFSZ]; + { + char buf2[BUFSZ]; - switch(article) { - case ARTICLE_YOUR: - Strcpy(buf2, "your "); - Strcat(buf2, buf); - Strcpy(buf, buf2); - return buf; - case ARTICLE_THE: - Strcpy(buf2, "the "); - Strcat(buf2, buf); - Strcpy(buf, buf2); - return buf; - case ARTICLE_A: - return(an(buf)); - case ARTICLE_NONE: - default: - return buf; - } - } + switch (article) { + case ARTICLE_YOUR: + Strcpy(buf2, "your "); + Strcat(buf2, buf); + Strcpy(buf, buf2); + return buf; + case ARTICLE_THE: + Strcpy(buf2, "the "); + Strcat(buf2, buf); + Strcpy(buf, buf2); + return buf; + case ARTICLE_A: + return (an(buf)); + case ARTICLE_NONE: + default: + return buf; + } + } } char * l_monnam(mtmp) register struct monst *mtmp; { - return(x_monnam(mtmp, ARTICLE_NONE, (char *)0, - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, TRUE)); + return (x_monnam(mtmp, ARTICLE_NONE, (char *) 0, + (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, TRUE)); } char * mon_nam(mtmp) register struct monst *mtmp; { - return(x_monnam(mtmp, ARTICLE_THE, (char *)0, - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE)); + return (x_monnam(mtmp, ARTICLE_THE, (char *) 0, + (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE)); } /* print the name as if mon_nam() was called, but assume that the player @@ -944,29 +974,30 @@ char * noit_mon_nam(mtmp) register struct monst *mtmp; { - return(x_monnam(mtmp, ARTICLE_THE, (char *)0, - (has_mname(mtmp)) ? (SUPPRESS_SADDLE|SUPPRESS_IT) : - SUPPRESS_IT, FALSE)); + return (x_monnam(mtmp, ARTICLE_THE, (char *) 0, + (has_mname(mtmp)) ? (SUPPRESS_SADDLE | SUPPRESS_IT) + : SUPPRESS_IT, + FALSE)); } char * Monnam(mtmp) register struct monst *mtmp; { - register char *bp = mon_nam(mtmp); + register char *bp = mon_nam(mtmp); - *bp = highc(*bp); - return(bp); + *bp = highc(*bp); + return (bp); } char * noit_Monnam(mtmp) register struct monst *mtmp; { - register char *bp = noit_mon_nam(mtmp); + register char *bp = noit_mon_nam(mtmp); - *bp = highc(*bp); - return(bp); + *bp = highc(*bp); + return (bp); } /* monster's own name */ @@ -974,7 +1005,7 @@ char * m_monnam(mtmp) struct monst *mtmp; { - return x_monnam(mtmp, ARTICLE_NONE, (char *)0, EXACT_NAME, FALSE); + return x_monnam(mtmp, ARTICLE_NONE, (char *) 0, EXACT_NAME, FALSE); } /* pet name: "your little dog" */ @@ -982,15 +1013,16 @@ char * y_monnam(mtmp) struct monst *mtmp; { - int prefix, suppression_flag; + int prefix, suppression_flag; - prefix = mtmp->mtame ? ARTICLE_YOUR : ARTICLE_THE; - suppression_flag = (has_mname(mtmp) - /* "saddled" is redundant when mounted */ - || mtmp == u.usteed - ) ? SUPPRESS_SADDLE : 0; + prefix = mtmp->mtame ? ARTICLE_YOUR : ARTICLE_THE; + suppression_flag = (has_mname(mtmp) + /* "saddled" is redundant when mounted */ + || mtmp == u.usteed) + ? SUPPRESS_SADDLE + : 0; - return x_monnam(mtmp, prefix, (char *)0, suppression_flag, FALSE); + return x_monnam(mtmp, prefix, (char *) 0, suppression_flag, FALSE); } char * @@ -998,29 +1030,30 @@ Adjmonnam(mtmp, adj) register struct monst *mtmp; register const char *adj; { - register char *bp = x_monnam(mtmp, ARTICLE_THE, adj, - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE); + register char *bp = + x_monnam(mtmp, ARTICLE_THE, adj, + (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE); - *bp = highc(*bp); - return(bp); + *bp = highc(*bp); + return (bp); } char * a_monnam(mtmp) register struct monst *mtmp; { - return x_monnam(mtmp, ARTICLE_A, (char *)0, - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE); + return x_monnam(mtmp, ARTICLE_A, (char *) 0, + (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE); } char * Amonnam(mtmp) register struct monst *mtmp; { - register char *bp = a_monnam(mtmp); + register char *bp = a_monnam(mtmp); - *bp = highc(*bp); - return(bp); + *bp = highc(*bp); + return (bp); } /* used for monster ID by the '/', ';', and 'C' commands to block remote @@ -1028,188 +1061,188 @@ register struct monst *mtmp; char * distant_monnam(mon, article, outbuf) struct monst *mon; -int article; /* only ARTICLE_NONE and ARTICLE_THE are handled here */ +int article; /* only ARTICLE_NONE and ARTICLE_THE are handled here */ char *outbuf; { /* high priest(ess)'s identity is concealed on the Astral Plane, unless you're adjacent (overridden for hallucination which does its own obfuscation) */ - if (mon->data == &mons[PM_HIGH_PRIEST] && !Hallucination && - Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) { - Strcpy(outbuf, article == ARTICLE_THE ? "the " : ""); - Strcat(outbuf, mon->female ? "high priestess" : "high priest"); + if (mon->data == &mons[PM_HIGH_PRIEST] && !Hallucination + && Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) { + Strcpy(outbuf, article == ARTICLE_THE ? "the " : ""); + Strcat(outbuf, mon->female ? "high priestess" : "high priest"); } else { - Strcpy(outbuf, x_monnam(mon, article, (char *)0, 0, TRUE)); + Strcpy(outbuf, x_monnam(mon, article, (char *) 0, 0, TRUE)); } return outbuf; } -#define BOGUSMONSIZE 100 /* arbitrary */ +#define BOGUSMONSIZE 100 /* arbitrary */ /* return a random monster name, for hallucination */ char * rndmonnam(code) char *code; { - static char buf[BUFSZ]; - char *mname = buf; - int name; + static char buf[BUFSZ]; + char *mname = buf; + int name; - if (code) *code = '\0'; + if (code) + *code = '\0'; - do { - name = rn1(SPECIAL_PM + BOGUSMONSIZE - LOW_PM, LOW_PM); - } while (name < SPECIAL_PM && - (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN))); + do { + name = rn1(SPECIAL_PM + BOGUSMONSIZE - LOW_PM, LOW_PM); + } while (name < SPECIAL_PM + && (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN))); - if (name >= SPECIAL_PM) { - get_rnd_text(BOGUSMONFILE, buf); - /* strip prefix if present */ - if (!letter(*mname)) { - if (code) *code = *mname; - ++mname; - } - } else { - Strcpy(buf, mons[name].mname); - } - return mname; + if (name >= SPECIAL_PM) { + get_rnd_text(BOGUSMONFILE, buf); + /* strip prefix if present */ + if (!letter(*mname)) { + if (code) + *code = *mname; + ++mname; + } + } else { + Strcpy(buf, mons[name].mname); + } + return mname; } #undef BOGUSMONSIZE -/* scan bogusmons to check whether this name is in the list and has a prefix */ +/* scan bogusmons to check whether this name is in the list and has a prefix + */ boolean bogon_is_pname(code) char code; { - if (!code) return FALSE; + if (!code) + return FALSE; return index("-+=", code) ? TRUE : FALSE; } -const char * -roguename() /* Name of a Rogue player */ +const char *roguename() /* Name of a Rogue player */ { - char *i, *opts; + char *i, *opts; - if ((opts = nh_getenv("ROGUEOPTS")) != 0) { - for (i = opts; *i; i++) - if (!strncmp("name=",i,5)) { - char *j; - if ((j = index(i+5,',')) != 0) - *j = (char)0; - return i+5; - } - } - return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold") - : "Glenn Wichman"; + if ((opts = nh_getenv("ROGUEOPTS")) != 0) { + for (i = opts; *i; i++) + if (!strncmp("name=", i, 5)) { + char *j; + if ((j = index(i + 5, ',')) != 0) + *j = (char) 0; + return i + 5; + } + } + return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold") + : "Glenn Wichman"; } -static NEARDATA const char * const hcolors[] = { - "ultraviolet", "infrared", "bluish-orange", - "reddish-green", "dark white", "light black", "sky blue-pink", - "salty", "sweet", "sour", "bitter", - "striped", "spiral", "swirly", "plaid", "checkered", "argyle", - "paisley", "blotchy", "guernsey-spotted", "polka-dotted", - "square", "round", "triangular", - "cabernet", "sangria", "fuchsia", "wisteria", - "lemon-lime", "strawberry-banana", "peppermint", - "romantic", "incandescent", - "octarine", /* Discworld: the Colour of Magic */ +static NEARDATA const char *const hcolors[] = { + "ultraviolet", "infrared", "bluish-orange", "reddish-green", "dark white", + "light black", "sky blue-pink", "salty", "sweet", "sour", "bitter", + "striped", "spiral", "swirly", "plaid", "checkered", "argyle", "paisley", + "blotchy", "guernsey-spotted", "polka-dotted", "square", "round", + "triangular", "cabernet", "sangria", "fuchsia", "wisteria", "lemon-lime", + "strawberry-banana", "peppermint", "romantic", "incandescent", + "octarine", /* Discworld: the Colour of Magic */ }; const char * hcolor(colorpref) const char *colorpref; { - return (Hallucination || !colorpref) ? - hcolors[rn2(SIZE(hcolors))] : colorpref; + return (Hallucination || !colorpref) ? hcolors[rn2(SIZE(hcolors))] + : colorpref; } /* return a random real color unless hallucinating */ const char * rndcolor() { - int k = rn2(CLR_MAX); - return Hallucination ? hcolor((char *)0) : (k == NO_COLOR) ? - "colorless" : c_obj_colors[k]; + int k = rn2(CLR_MAX); + return Hallucination ? hcolor((char *) 0) + : (k == NO_COLOR) ? "colorless" : c_obj_colors[k]; } /* Aliases for road-runner nemesis */ -static const char * const coynames[] = { - "Carnivorous Vulgaris","Road-Runnerus Digestus", - "Eatibus Anythingus" ,"Famishus-Famishus", - "Eatibus Almost Anythingus","Eatius Birdius", - "Famishius Fantasticus","Eternalii Famishiis", - "Famishus Vulgarus","Famishius Vulgaris Ingeniusi", - "Eatius-Slobbius","Hardheadipus Oedipus", - "Carnivorous Slobbius","Hard-Headipus Ravenus", - "Evereadii Eatibus","Apetitius Giganticus", - "Hungrii Flea-Bagius","Overconfidentii Vulgaris", - "Caninus Nervous Rex","Grotesques Appetitus", - "Nemesis Ridiculii","Canis latrans" +static const char *const coynames[] = { + "Carnivorous Vulgaris", "Road-Runnerus Digestus", "Eatibus Anythingus", + "Famishus-Famishus", "Eatibus Almost Anythingus", "Eatius Birdius", + "Famishius Fantasticus", "Eternalii Famishiis", "Famishus Vulgarus", + "Famishius Vulgaris Ingeniusi", "Eatius-Slobbius", "Hardheadipus Oedipus", + "Carnivorous Slobbius", "Hard-Headipus Ravenus", "Evereadii Eatibus", + "Apetitius Giganticus", "Hungrii Flea-Bagius", "Overconfidentii Vulgaris", + "Caninus Nervous Rex", "Grotesques Appetitus", "Nemesis Ridiculii", + "Canis latrans" }; - + char * coyotename(mtmp, buf) struct monst *mtmp; char *buf; { if (mtmp && buf) { - Sprintf(buf, "%s - %s", - x_monnam(mtmp, ARTICLE_NONE, (char *)0, 0, TRUE), - mtmp->mcan ? coynames[SIZE(coynames)-1] : coynames[rn2(SIZE(coynames)-1)]); + Sprintf(buf, "%s - %s", + x_monnam(mtmp, ARTICLE_NONE, (char *) 0, 0, TRUE), + mtmp->mcan ? coynames[SIZE(coynames) - 1] + : coynames[rn2(SIZE(coynames) - 1)]); } return buf; } /* make sure "The Colour of Magic" remains the first entry in here */ -static const char * const sir_Terry_novels[] = { - "The Colour of Magic", "The Light Fantastic", "Equal Rites", - "Mort", "Sourcery", "Wyrd Sisters", "Pyramids", "Guards! Guards!", - "Eric", "Moving Pictures", "Reaper Man", "Witches Abroad", - "Small Gods", "Lords and Ladies", "Men at Arms", "Soul Music", - "Interesting Times", "Maskerade", "Feet of Clay", "Hogfather", - "Jingo", "The Last Continent", "Carpe Jugulum", "The Fifth Elephant", - "The Truth", "Thief of Time", "The Last Hero", - "The Amazing Maurice and his Educated Rodents", "Night Watch", - "The Wee Free Men", "Monstrous Regiment", "A Hat Full of Sky", - "Going Postal", "Thud!", "Wintersmith", "Making Money", - "Unseen Academicals", "I Shall Wear Midnight", "Snuff", - "Raising Steam", "The Shepherd's Crown" +static const char *const sir_Terry_novels[] = { + "The Colour of Magic", "The Light Fantastic", "Equal Rites", "Mort", + "Sourcery", "Wyrd Sisters", "Pyramids", "Guards! Guards!", "Eric", + "Moving Pictures", "Reaper Man", "Witches Abroad", "Small Gods", + "Lords and Ladies", "Men at Arms", "Soul Music", "Interesting Times", + "Maskerade", "Feet of Clay", "Hogfather", "Jingo", "The Last Continent", + "Carpe Jugulum", "The Fifth Elephant", "The Truth", "Thief of Time", + "The Last Hero", "The Amazing Maurice and his Educated Rodents", + "Night Watch", "The Wee Free Men", "Monstrous Regiment", + "A Hat Full of Sky", "Going Postal", "Thud!", "Wintersmith", + "Making Money", "Unseen Academicals", "I Shall Wear Midnight", "Snuff", + "Raising Steam", "The Shepherd's Crown" }; const char * noveltitle(novidx) int *novidx; { - int j, k = SIZE(sir_Terry_novels)-1; + int j, k = SIZE(sir_Terry_novels) - 1; j = rn2(k); if (novidx) { - if (*novidx == -1) *novidx = j; - else if ((*novidx >= 0) && (*novidx <= k)) j = *novidx; + if (*novidx == -1) + *novidx = j; + else if ((*novidx >= 0) && (*novidx <= k)) + j = *novidx; } return sir_Terry_novels[j]; -} +} const char * lookup_novel(lookname, idx) const char *lookname; int *idx; { - int k; + int k; /* Take American or U.K. spelling of this one */ - if (strcmpi(lookname, "The Color of Magic") == 0) - lookname = sir_Terry_novels[0]; + if (strcmpi(lookname, "The Color of Magic") == 0) + lookname = sir_Terry_novels[0]; - for (k = 0; k < SIZE(sir_Terry_novels); ++k) { - if (strcmpi(lookname, sir_Terry_novels[k]) == 0) { - if (idx) *idx = k; - return sir_Terry_novels[k]; - } - } + for (k = 0; k < SIZE(sir_Terry_novels); ++k) { + if (strcmpi(lookname, sir_Terry_novels[k]) == 0) { + if (idx) + *idx = k; + return sir_Terry_novels[k]; + } + } - return (const char *)0; + return (const char *) 0; } /*do_name.c*/ diff --git a/src/do_wear.c b/src/do_wear.c index ee866a078..f17a1bcfd 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do_wear.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 do_wear.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.80 $ */ /* NetHack 3.6 do_wear.c $Date: 2012/02/05 04:26:48 $ $Revision: 1.69 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,51 +7,46 @@ static NEARDATA const char see_yourself[] = "see yourself"; static NEARDATA const char unknown_type[] = "Unknown type of %s (%d)"; -static NEARDATA const char c_armor[] = "armor", - c_suit[] = "suit", - c_shirt[] = "shirt", - c_cloak[] = "cloak", - c_gloves[] = "gloves", - c_boots[] = "boots", - c_helmet[] = "helmet", - c_shield[] = "shield", - c_weapon[] = "weapon", - c_sword[] = "sword", - c_axe[] = "axe", - c_that_[] = "that"; +static NEARDATA const char c_armor[] = "armor", c_suit[] = "suit", + c_shirt[] = "shirt", c_cloak[] = "cloak", + c_gloves[] = "gloves", c_boots[] = "boots", + c_helmet[] = "helmet", c_shield[] = "shield", + c_weapon[] = "weapon", c_sword[] = "sword", + c_axe[] = "axe", c_that_[] = "that"; -static NEARDATA const long takeoff_order[] = { WORN_BLINDF, W_WEP, - WORN_SHIELD, WORN_GLOVES, LEFT_RING, RIGHT_RING, WORN_CLOAK, - WORN_HELMET, WORN_AMUL, WORN_ARMOR, WORN_SHIRT, WORN_BOOTS, W_SWAPWEP, - W_QUIVER, 0L }; +static NEARDATA const long takeoff_order[] = { + WORN_BLINDF, W_WEP, WORN_SHIELD, WORN_GLOVES, LEFT_RING, + RIGHT_RING, WORN_CLOAK, WORN_HELMET, WORN_AMUL, WORN_ARMOR, + WORN_SHIRT, WORN_BOOTS, W_SWAPWEP, W_QUIVER, 0L +}; STATIC_DCL void FDECL(on_msg, (struct obj *)); -STATIC_DCL void FDECL(toggle_stealth, (struct obj *,long,BOOLEAN_P)); -STATIC_DCL void FDECL(toggle_displacement, (struct obj *,long,BOOLEAN_P)); +STATIC_DCL void FDECL(toggle_stealth, (struct obj *, long, BOOLEAN_P)); +STATIC_DCL void FDECL(toggle_displacement, (struct obj *, long, BOOLEAN_P)); STATIC_PTR int NDECL(Armor_on); STATIC_PTR int NDECL(Boots_on); STATIC_PTR int NDECL(Cloak_on); STATIC_PTR int NDECL(Helmet_on); STATIC_PTR int NDECL(Gloves_on); -STATIC_DCL void FDECL(wielding_corpse, (struct obj *,BOOLEAN_P)); +STATIC_DCL void FDECL(wielding_corpse, (struct obj *, BOOLEAN_P)); STATIC_PTR int NDECL(Shield_on); STATIC_PTR int NDECL(Shirt_on); STATIC_DCL void NDECL(Amulet_on); -STATIC_DCL void FDECL(learnring, (struct obj *,BOOLEAN_P)); +STATIC_DCL void FDECL(learnring, (struct obj *, BOOLEAN_P)); STATIC_DCL void FDECL(Ring_off_or_gone, (struct obj *, BOOLEAN_P)); STATIC_PTR int FDECL(select_off, (struct obj *)); STATIC_DCL struct obj *NDECL(do_takeoff); STATIC_PTR int NDECL(take_off); STATIC_DCL int FDECL(menu_remarm, (int)); -STATIC_DCL void FDECL(already_wearing, (const char*)); -STATIC_DCL void FDECL(already_wearing2, (const char*, const char*)); +STATIC_DCL void FDECL(already_wearing, (const char *)); +STATIC_DCL void FDECL(already_wearing2, (const char *, const char *)); void off_msg(otmp) struct obj *otmp; { - if (flags.verbose) - You("were wearing %s.", doname(otmp)); + if (flags.verbose) + You("were wearing %s.", doname(otmp)); } /* for items that involve no delay */ @@ -59,24 +54,23 @@ STATIC_OVL void on_msg(otmp) struct obj *otmp; { - if (flags.verbose) { - char how[BUFSZ]; - /* call xname() before obj_is_pname(); formatting obj's name - might set obj->dknown and that affects the pname test */ - const char *otmp_name = xname(otmp); + if (flags.verbose) { + char how[BUFSZ]; + /* call xname() before obj_is_pname(); formatting obj's name + might set obj->dknown and that affects the pname test */ + const char *otmp_name = xname(otmp); - how[0] = '\0'; - if (otmp->otyp == TOWEL) - Sprintf(how, " around your %s", body_part(HEAD)); - You("are now wearing %s%s.", - obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), - how); - } + how[0] = '\0'; + if (otmp->otyp == TOWEL) + Sprintf(how, " around your %s", body_part(HEAD)); + You("are now wearing %s%s.", + obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), how); + } } /* starting equipment gets auto-worn at beginning of new game, and we don't want stealth or displacement feedback then */ -static boolean initial_don = FALSE; /* manipulated in set_wear() */ +static boolean initial_don = FALSE; /* manipulated in set_wear() */ /* putting on or taking off an item which confers stealth; give feedback and discover it iff stealth state is changing */ @@ -84,29 +78,30 @@ STATIC_OVL void toggle_stealth(obj, oldprop, on) struct obj *obj; -long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ +long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ boolean on; { - if (on ? initial_don : context.takeoff.cancelled_don) return; + if (on ? initial_don : context.takeoff.cancelled_don) + return; - if (!oldprop && /* extrinsic stealth from something else */ - !HStealth && /* intrinsic stealth */ - !BStealth) { /* stealth blocked by something */ - if (obj->otyp == RIN_STEALTH) - learnring(obj, TRUE); - else - makeknown(obj->otyp); + if (!oldprop && /* extrinsic stealth from something else */ + !HStealth && /* intrinsic stealth */ + !BStealth) { /* stealth blocked by something */ + if (obj->otyp == RIN_STEALTH) + learnring(obj, TRUE); + else + makeknown(obj->otyp); - if (on) { - if (!is_boots(obj)) - You("move very quietly."); - else if (Levitation || Flying) - You("float imperceptibly."); - else - You("walk very quietly."); - } else { - You("sure are noisy."); - } + if (on) { + if (!is_boots(obj)) + You("move very quietly."); + else if (Levitation || Flying) + You("float imperceptibly."); + else + You("walk very quietly."); + } else { + You("sure are noisy."); + } } } @@ -117,28 +112,29 @@ STATIC_OVL void toggle_displacement(obj, oldprop, on) struct obj *obj; -long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ +long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */ boolean on; { - if (on ? initial_don : context.takeoff.cancelled_don) return; + if (on ? initial_don : context.takeoff.cancelled_don) + return; - if (!oldprop && /* extrinsic displacement from something else */ - !(u.uprops[DISPLACED].intrinsic) && /* (theoretical) */ - !(u.uprops[DISPLACED].blocked) && /* (also theoretical) */ - /* we don't use canseeself() here because it augments vision - with touch, which isn't appropriate for deciding whether - we'll notice that monsters have trouble spotting the hero */ - ((!Blind && /* see anything */ - !u.uswallow && /* see surroundings */ - !Invisible) || /* see self */ - /* actively sensing nearby monsters via telepathy or extended - monster detection overrides vision considerations because - hero also senses self in this situation */ - (Unblind_telepat || (Blind_telepat && Blind) || Detect_monsters))) { - makeknown(obj->otyp); + if (!oldprop && /* extrinsic displacement from something else */ + !(u.uprops[DISPLACED].intrinsic) && /* (theoretical) */ + !(u.uprops[DISPLACED].blocked) && /* (also theoretical) */ + /* we don't use canseeself() here because it augments vision + with touch, which isn't appropriate for deciding whether + we'll notice that monsters have trouble spotting the hero */ + ((!Blind && /* see anything */ + !u.uswallow && /* see surroundings */ + !Invisible) || /* see self */ + /* actively sensing nearby monsters via telepathy or extended + monster detection overrides vision considerations because + hero also senses self in this situation */ + (Unblind_telepat || (Blind_telepat && Blind) || Detect_monsters))) { + makeknown(obj->otyp); - You_feel("that monsters%s have difficulty pinpointing your location.", - on ? "" : " no longer"); + You_feel("that monsters%s have difficulty pinpointing your location.", + on ? "" : " no longer"); } } @@ -153,46 +149,48 @@ int Boots_on(VOID_ARGS) { long oldprop = - u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS; + u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS; - switch(uarmf->otyp) { - case LOW_BOOTS: - case IRON_SHOES: - case HIGH_BOOTS: - case JUMPING_BOOTS: - case KICKING_BOOTS: - break; - case WATER_WALKING_BOOTS: - if (u.uinwater) spoteffects(TRUE); - /* (we don't need a lava check here since boots can't be - put on while feet are stuck) */ - break; - case SPEED_BOOTS: - /* Speed boots are still better than intrinsic speed, */ - /* though not better than potion speed */ - if (!oldprop && !(HFast & TIMEOUT)) { - makeknown(uarmf->otyp); - You_feel("yourself speed up%s.", - (oldprop || HFast) ? " a bit more" : ""); - } - break; - case ELVEN_BOOTS: - toggle_stealth(uarmf, oldprop, TRUE); - break; - case FUMBLE_BOOTS: - if (!oldprop && !(HFumbling & ~TIMEOUT)) - incr_itimeout(&HFumbling, rnd(20)); - break; - case LEVITATION_BOOTS: - if (!oldprop && !HLevitation && !BLevitation) { - makeknown(uarmf->otyp); - float_up(); - spoteffects(FALSE); - } else { - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ - } - break; - default: impossible(unknown_type, c_boots, uarmf->otyp); + switch (uarmf->otyp) { + case LOW_BOOTS: + case IRON_SHOES: + case HIGH_BOOTS: + case JUMPING_BOOTS: + case KICKING_BOOTS: + break; + case WATER_WALKING_BOOTS: + if (u.uinwater) + spoteffects(TRUE); + /* (we don't need a lava check here since boots can't be + put on while feet are stuck) */ + break; + case SPEED_BOOTS: + /* Speed boots are still better than intrinsic speed, */ + /* though not better than potion speed */ + if (!oldprop && !(HFast & TIMEOUT)) { + makeknown(uarmf->otyp); + You_feel("yourself speed up%s.", + (oldprop || HFast) ? " a bit more" : ""); + } + break; + case ELVEN_BOOTS: + toggle_stealth(uarmf, oldprop, TRUE); + break; + case FUMBLE_BOOTS: + if (!oldprop && !(HFumbling & ~TIMEOUT)) + incr_itimeout(&HFumbling, rnd(20)); + break; + case LEVITATION_BOOTS: + if (!oldprop && !HLevitation && !BLevitation) { + makeknown(uarmf->otyp); + float_up(); + spoteffects(FALSE); + } else { + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + } + break; + default: + impossible(unknown_type, c_boots, uarmf->otyp); } return 0; } @@ -205,53 +203,53 @@ Boots_off(VOID_ARGS) long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_BOOTS; context.takeoff.mask &= ~W_ARMF; - /* For levitation, float_down() returns if Levitation, so we - * must do a setworn() _before_ the levitation case. - */ - setworn((struct obj *)0, W_ARMF); + /* For levitation, float_down() returns if Levitation, so we + * must do a setworn() _before_ the levitation case. + */ + setworn((struct obj *) 0, W_ARMF); switch (otyp) { - case SPEED_BOOTS: - if (!Very_fast && !context.takeoff.cancelled_don) { - makeknown(otyp); - You_feel("yourself slow down%s.", - Fast ? " a bit" : ""); - } - break; - case WATER_WALKING_BOOTS: - /* check for lava since fireproofed boots make it viable */ - if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) && - !Levitation && !Flying && !is_clinger(youmonst.data) && - !context.takeoff.cancelled_don && - /* avoid recursive call to lava_effects() */ - !iflags.in_lava_effects) { - /* make boots known in case you survive the drowning */ - makeknown(otyp); - spoteffects(TRUE); - } - break; - case ELVEN_BOOTS: - toggle_stealth(otmp, oldprop, FALSE); - break; - case FUMBLE_BOOTS: - if (!oldprop && !(HFumbling & ~TIMEOUT)) - HFumbling = EFumbling = 0; - break; - case LEVITATION_BOOTS: - if (!oldprop && !HLevitation && !BLevitation && - !context.takeoff.cancelled_don) { - (void) float_down(0L, 0L); - makeknown(otyp); - } else { - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ - } - break; - case LOW_BOOTS: - case IRON_SHOES: - case HIGH_BOOTS: - case JUMPING_BOOTS: - case KICKING_BOOTS: - break; - default: impossible(unknown_type, c_boots, otyp); + case SPEED_BOOTS: + if (!Very_fast && !context.takeoff.cancelled_don) { + makeknown(otyp); + You_feel("yourself slow down%s.", Fast ? " a bit" : ""); + } + break; + case WATER_WALKING_BOOTS: + /* check for lava since fireproofed boots make it viable */ + if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) && !Levitation + && !Flying && !is_clinger(youmonst.data) + && !context.takeoff.cancelled_don && + /* avoid recursive call to lava_effects() */ + !iflags.in_lava_effects) { + /* make boots known in case you survive the drowning */ + makeknown(otyp); + spoteffects(TRUE); + } + break; + case ELVEN_BOOTS: + toggle_stealth(otmp, oldprop, FALSE); + break; + case FUMBLE_BOOTS: + if (!oldprop && !(HFumbling & ~TIMEOUT)) + HFumbling = EFumbling = 0; + break; + case LEVITATION_BOOTS: + if (!oldprop && !HLevitation && !BLevitation + && !context.takeoff.cancelled_don) { + (void) float_down(0L, 0L); + makeknown(otyp); + } else { + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + } + break; + case LOW_BOOTS: + case IRON_SHOES: + case HIGH_BOOTS: + case JUMPING_BOOTS: + case KICKING_BOOTS: + break; + default: + impossible(unknown_type, c_boots, otyp); } context.takeoff.cancelled_don = FALSE; return 0; @@ -261,51 +259,51 @@ STATIC_PTR int Cloak_on(VOID_ARGS) { long oldprop = - u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK; + u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK; - switch(uarmc->otyp) { - case ORCISH_CLOAK: - case DWARVISH_CLOAK: - case CLOAK_OF_MAGIC_RESISTANCE: - case ROBE: - case LEATHER_CLOAK: - break; - case CLOAK_OF_PROTECTION: - makeknown(uarmc->otyp); - break; - case ELVEN_CLOAK: - toggle_stealth(uarmc, oldprop, TRUE); - break; - case CLOAK_OF_DISPLACEMENT: - toggle_displacement(uarmc, oldprop, TRUE); - break; - case MUMMY_WRAPPING: - /* Note: it's already being worn, so we have to cheat here. */ - if ((HInvis || EInvis) && !Blind) { - newsym(u.ux,u.uy); - You("can %s!", - See_invisible ? "no longer see through yourself" - : see_yourself); - } - break; - case CLOAK_OF_INVISIBILITY: - /* since cloak of invisibility was worn, we know mummy wrapping - wasn't, so no need to check `oldprop' against blocked */ - if (!oldprop && !HInvis && !Blind) { - makeknown(uarmc->otyp); - newsym(u.ux,u.uy); - pline("Suddenly you can%s yourself.", - See_invisible ? " see through" : "not see"); - } - break; - case OILSKIN_CLOAK: - pline("%s very tightly.", Tobjnam(uarmc, "fit")); - break; - /* Alchemy smock gives poison _and_ acid resistance */ - case ALCHEMY_SMOCK: - EAcid_resistance |= WORN_CLOAK; - break; - default: impossible(unknown_type, c_cloak, uarmc->otyp); + switch (uarmc->otyp) { + case ORCISH_CLOAK: + case DWARVISH_CLOAK: + case CLOAK_OF_MAGIC_RESISTANCE: + case ROBE: + case LEATHER_CLOAK: + break; + case CLOAK_OF_PROTECTION: + makeknown(uarmc->otyp); + break; + case ELVEN_CLOAK: + toggle_stealth(uarmc, oldprop, TRUE); + break; + case CLOAK_OF_DISPLACEMENT: + toggle_displacement(uarmc, oldprop, TRUE); + break; + case MUMMY_WRAPPING: + /* Note: it's already being worn, so we have to cheat here. */ + if ((HInvis || EInvis) && !Blind) { + newsym(u.ux, u.uy); + You("can %s!", See_invisible ? "no longer see through yourself" + : see_yourself); + } + break; + case CLOAK_OF_INVISIBILITY: + /* since cloak of invisibility was worn, we know mummy wrapping + wasn't, so no need to check `oldprop' against blocked */ + if (!oldprop && !HInvis && !Blind) { + makeknown(uarmc->otyp); + newsym(u.ux, u.uy); + pline("Suddenly you can%s yourself.", + See_invisible ? " see through" : "not see"); + } + break; + case OILSKIN_CLOAK: + pline("%s very tightly.", Tobjnam(uarmc, "fit")); + break; + /* Alchemy smock gives poison _and_ acid resistance */ + case ALCHEMY_SMOCK: + EAcid_resistance |= WORN_CLOAK; + break; + default: + impossible(unknown_type, c_cloak, uarmc->otyp); } return 0; } @@ -318,45 +316,45 @@ Cloak_off(VOID_ARGS) long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_CLOAK; context.takeoff.mask &= ~W_ARMC; - /* For mummy wrapping, taking it off first resets `Invisible'. */ - setworn((struct obj *)0, W_ARMC); + /* For mummy wrapping, taking it off first resets `Invisible'. */ + setworn((struct obj *) 0, W_ARMC); switch (otyp) { - case ORCISH_CLOAK: - case DWARVISH_CLOAK: - case CLOAK_OF_PROTECTION: - case CLOAK_OF_MAGIC_RESISTANCE: - case OILSKIN_CLOAK: - case ROBE: - case LEATHER_CLOAK: - break; - case ELVEN_CLOAK: - toggle_stealth(otmp, oldprop, FALSE); - break; - case CLOAK_OF_DISPLACEMENT: - toggle_displacement(otmp, oldprop, FALSE); - break; - case MUMMY_WRAPPING: - if (Invis && !Blind) { - newsym(u.ux,u.uy); - You("can %s.", - See_invisible ? "see through yourself" - : "no longer see yourself"); - } - break; - case CLOAK_OF_INVISIBILITY: - if (!oldprop && !HInvis && !Blind) { - makeknown(CLOAK_OF_INVISIBILITY); - newsym(u.ux,u.uy); - pline("Suddenly you can %s.", - See_invisible ? "no longer see through yourself" - : see_yourself); - } - break; - /* Alchemy smock gives poison _and_ acid resistance */ - case ALCHEMY_SMOCK: - EAcid_resistance &= ~WORN_CLOAK; - break; - default: impossible(unknown_type, c_cloak, otyp); + case ORCISH_CLOAK: + case DWARVISH_CLOAK: + case CLOAK_OF_PROTECTION: + case CLOAK_OF_MAGIC_RESISTANCE: + case OILSKIN_CLOAK: + case ROBE: + case LEATHER_CLOAK: + break; + case ELVEN_CLOAK: + toggle_stealth(otmp, oldprop, FALSE); + break; + case CLOAK_OF_DISPLACEMENT: + toggle_displacement(otmp, oldprop, FALSE); + break; + case MUMMY_WRAPPING: + if (Invis && !Blind) { + newsym(u.ux, u.uy); + You("can %s.", See_invisible ? "see through yourself" + : "no longer see yourself"); + } + break; + case CLOAK_OF_INVISIBILITY: + if (!oldprop && !HInvis && !Blind) { + makeknown(CLOAK_OF_INVISIBILITY); + newsym(u.ux, u.uy); + pline("Suddenly you can %s.", + See_invisible ? "no longer see through yourself" + : see_yourself); + } + break; + /* Alchemy smock gives poison _and_ acid resistance */ + case ALCHEMY_SMOCK: + EAcid_resistance &= ~WORN_CLOAK; + break; + default: + impossible(unknown_type, c_cloak, otyp); } return 0; } @@ -365,57 +363,62 @@ STATIC_PTR int Helmet_on(VOID_ARGS) { - switch(uarmh->otyp) { - case FEDORA: - case HELMET: - case DENTED_POT: - case ELVEN_LEATHER_HELM: - case DWARVISH_IRON_HELM: - case ORCISH_HELM: - case HELM_OF_TELEPATHY: - break; - case HELM_OF_BRILLIANCE: - adj_abon(uarmh, uarmh->spe); - break; - case CORNUTHAUM: - /* people think marked wizards know what they're talking - * about, but it takes trained arrogance to pull it off, - * and the actual enchantment of the hat is irrelevant. - */ - ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1); - context.botl = 1; - makeknown(uarmh->otyp); - break; - case HELM_OF_OPPOSITE_ALIGNMENT: - /* changing alignment can toggle off active artifact - properties, including levitation; uarmh could get - dropped or destroyed here */ - uchangealign((u.ualign.type != A_NEUTRAL) ? -u.ualign.type : - (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL, 1); - /* makeknown(uarmh->otyp); -- moved below, after xname() */ - /*FALLTHRU*/ - case DUNCE_CAP: - if (uarmh && !uarmh->cursed) { - if (Blind) - pline("%s for a moment.", Tobjnam(uarmh, "vibrate")); - else - pline("%s %s for a moment.", - Tobjnam(uarmh, "glow"), hcolor(NH_BLACK)); - curse(uarmh); - } - context.botl = 1; /* reveal new alignment or INT & WIS */ - if (Hallucination) { - pline("My brain hurts!"); /* Monty Python's Flying Circus */ - } else if (uarmh && uarmh->otyp == DUNCE_CAP) { - You_feel("%s.", /* track INT change; ignore WIS */ - ACURR(A_INT) <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT)) ? - "like sitting in a corner" : "giddy"); - } else { - /* [message moved to uchangealign()] */ - makeknown(HELM_OF_OPPOSITE_ALIGNMENT); - } - break; - default: impossible(unknown_type, c_helmet, uarmh->otyp); + switch (uarmh->otyp) { + case FEDORA: + case HELMET: + case DENTED_POT: + case ELVEN_LEATHER_HELM: + case DWARVISH_IRON_HELM: + case ORCISH_HELM: + case HELM_OF_TELEPATHY: + break; + case HELM_OF_BRILLIANCE: + adj_abon(uarmh, uarmh->spe); + break; + case CORNUTHAUM: + /* people think marked wizards know what they're talking + * about, but it takes trained arrogance to pull it off, + * and the actual enchantment of the hat is irrelevant. + */ + ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1); + context.botl = 1; + makeknown(uarmh->otyp); + break; + case HELM_OF_OPPOSITE_ALIGNMENT: + /* changing alignment can toggle off active artifact + properties, including levitation; uarmh could get + dropped or destroyed here */ + uchangealign((u.ualign.type != A_NEUTRAL) + ? -u.ualign.type + : (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL, + 1); + /* makeknown(uarmh->otyp); -- moved below, after xname() */ + /*FALLTHRU*/ + case DUNCE_CAP: + if (uarmh && !uarmh->cursed) { + if (Blind) + pline("%s for a moment.", Tobjnam(uarmh, "vibrate")); + else + pline("%s %s for a moment.", Tobjnam(uarmh, "glow"), + hcolor(NH_BLACK)); + curse(uarmh); + } + context.botl = 1; /* reveal new alignment or INT & WIS */ + if (Hallucination) { + pline("My brain hurts!"); /* Monty Python's Flying Circus */ + } else if (uarmh && uarmh->otyp == DUNCE_CAP) { + You_feel("%s.", /* track INT change; ignore WIS */ + ACURR(A_INT) + <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT)) + ? "like sitting in a corner" + : "giddy"); + } else { + /* [message moved to uchangealign()] */ + makeknown(HELM_OF_OPPOSITE_ALIGNMENT); + } + break; + default: + impossible(unknown_type, c_helmet, uarmh->otyp); } return 0; } @@ -425,40 +428,42 @@ Helmet_off(VOID_ARGS) { context.takeoff.mask &= ~W_ARMH; - switch(uarmh->otyp) { - case FEDORA: - case HELMET: - case DENTED_POT: - case ELVEN_LEATHER_HELM: - case DWARVISH_IRON_HELM: - case ORCISH_HELM: - break; - case DUNCE_CAP: - context.botl = 1; - break; - case CORNUTHAUM: - if (!context.takeoff.cancelled_don) { - ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1); - context.botl = 1; - } - break; - case HELM_OF_TELEPATHY: - /* need to update ability before calling see_monsters() */ - setworn((struct obj *)0, W_ARMH); - see_monsters(); - return 0; - case HELM_OF_BRILLIANCE: - if (!context.takeoff.cancelled_don) adj_abon(uarmh, -uarmh->spe); - break; - case HELM_OF_OPPOSITE_ALIGNMENT: - /* changing alignment can toggle off active artifact - properties, including levitation; uarmh could get - dropped or destroyed here */ - uchangealign(u.ualignbase[A_CURRENT], 2); - break; - default: impossible(unknown_type, c_helmet, uarmh->otyp); + switch (uarmh->otyp) { + case FEDORA: + case HELMET: + case DENTED_POT: + case ELVEN_LEATHER_HELM: + case DWARVISH_IRON_HELM: + case ORCISH_HELM: + break; + case DUNCE_CAP: + context.botl = 1; + break; + case CORNUTHAUM: + if (!context.takeoff.cancelled_don) { + ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1); + context.botl = 1; + } + break; + case HELM_OF_TELEPATHY: + /* need to update ability before calling see_monsters() */ + setworn((struct obj *) 0, W_ARMH); + see_monsters(); + return 0; + case HELM_OF_BRILLIANCE: + if (!context.takeoff.cancelled_don) + adj_abon(uarmh, -uarmh->spe); + break; + case HELM_OF_OPPOSITE_ALIGNMENT: + /* changing alignment can toggle off active artifact + properties, including levitation; uarmh could get + dropped or destroyed here */ + uchangealign(u.ualignbase[A_CURRENT], 2); + break; + default: + impossible(unknown_type, c_helmet, uarmh->otyp); } - setworn((struct obj *)0, W_ARMH); + setworn((struct obj *) 0, W_ARMH); context.takeoff.cancelled_don = FALSE; return 0; } @@ -468,23 +473,24 @@ int Gloves_on(VOID_ARGS) { long oldprop = - u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; + u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; - switch(uarmg->otyp) { - case LEATHER_GLOVES: - break; - case GAUNTLETS_OF_FUMBLING: - if (!oldprop && !(HFumbling & ~TIMEOUT)) - incr_itimeout(&HFumbling, rnd(20)); - break; - case GAUNTLETS_OF_POWER: - makeknown(uarmg->otyp); - context.botl = 1; /* taken care of in attrib.c */ - break; - case GAUNTLETS_OF_DEXTERITY: - adj_abon(uarmg, uarmg->spe); - break; - default: impossible(unknown_type, c_gloves, uarmg->otyp); + switch (uarmg->otyp) { + case LEATHER_GLOVES: + break; + case GAUNTLETS_OF_FUMBLING: + if (!oldprop && !(HFumbling & ~TIMEOUT)) + incr_itimeout(&HFumbling, rnd(20)); + break; + case GAUNTLETS_OF_POWER: + makeknown(uarmg->otyp); + context.botl = 1; /* taken care of in attrib.c */ + break; + case GAUNTLETS_OF_DEXTERITY: + adj_abon(uarmg, uarmg->spe); + break; + default: + impossible(unknown_type, c_gloves, uarmg->otyp); } return 0; } @@ -492,23 +498,24 @@ Gloves_on(VOID_ARGS) STATIC_OVL void wielding_corpse(obj, voluntary) struct obj *obj; -boolean voluntary; /* taking gloves off on purpose? */ +boolean voluntary; /* taking gloves off on purpose? */ { char kbuf[BUFSZ]; - if (!obj || obj->otyp != CORPSE) return; - if (obj != uwep && (obj != uswapwep || !u.twoweap)) return; + if (!obj || obj->otyp != CORPSE) + return; + if (obj != uwep && (obj != uswapwep || !u.twoweap)) + return; if (touch_petrifies(&mons[obj->corpsenm]) && !Stone_resistance) { - You("now wield %s in your bare %s.", - corpse_xname(obj, (const char *)0, CXN_ARTICLE), - makeplural(body_part(HAND))); - Sprintf(kbuf, "%s gloves while wielding %s", - voluntary ? "removing" : "losing", - killer_xname(obj)); - instapetrify(kbuf); - /* life-saved; can't continue wielding cockatrice corpse though */ - remove_worn_item(obj, FALSE); + You("now wield %s in your bare %s.", + corpse_xname(obj, (const char *) 0, CXN_ARTICLE), + makeplural(body_part(HAND))); + Sprintf(kbuf, "%s gloves while wielding %s", + voluntary ? "removing" : "losing", killer_xname(obj)); + instapetrify(kbuf); + /* life-saved; can't continue wielding cockatrice corpse though */ + remove_worn_item(obj, FALSE); } } @@ -516,40 +523,42 @@ int Gloves_off(VOID_ARGS) { long oldprop = - u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; + u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; boolean on_purpose = !context.mon_moving && !uarmg->in_use; context.takeoff.mask &= ~W_ARMG; - switch(uarmg->otyp) { - case LEATHER_GLOVES: - break; - case GAUNTLETS_OF_FUMBLING: - if (!oldprop && !(HFumbling & ~TIMEOUT)) - HFumbling = EFumbling = 0; - break; - case GAUNTLETS_OF_POWER: - makeknown(uarmg->otyp); - context.botl = 1; /* taken care of in attrib.c */ - break; - case GAUNTLETS_OF_DEXTERITY: - if (!context.takeoff.cancelled_don) adj_abon(uarmg, -uarmg->spe); - break; - default: impossible(unknown_type, c_gloves, uarmg->otyp); + switch (uarmg->otyp) { + case LEATHER_GLOVES: + break; + case GAUNTLETS_OF_FUMBLING: + if (!oldprop && !(HFumbling & ~TIMEOUT)) + HFumbling = EFumbling = 0; + break; + case GAUNTLETS_OF_POWER: + makeknown(uarmg->otyp); + context.botl = 1; /* taken care of in attrib.c */ + break; + case GAUNTLETS_OF_DEXTERITY: + if (!context.takeoff.cancelled_don) + adj_abon(uarmg, -uarmg->spe); + break; + default: + impossible(unknown_type, c_gloves, uarmg->otyp); } - setworn((struct obj *)0, W_ARMG); + setworn((struct obj *) 0, W_ARMG); context.takeoff.cancelled_don = FALSE; - (void) encumber_msg(); /* immediate feedback for GoP */ + (void) encumber_msg(); /* immediate feedback for GoP */ /* prevent wielding cockatrice when not wearing gloves */ if (uwep && uwep->otyp == CORPSE) - wielding_corpse(uwep, on_purpose); + wielding_corpse(uwep, on_purpose); /* KMH -- ...or your secondary weapon when you're wielding it [This case can't actually happen; twoweapon mode won't engage if a corpse has been set up as the alternate weapon.] */ if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE) - wielding_corpse(uswapwep, on_purpose); + wielding_corpse(uswapwep, on_purpose); return 0; } @@ -557,19 +566,19 @@ Gloves_off(VOID_ARGS) STATIC_PTR int Shield_on(VOID_ARGS) { -/* - switch (uarms->otyp) { - case SMALL_SHIELD: - case ELVEN_SHIELD: - case URUK_HAI_SHIELD: - case ORCISH_SHIELD: - case DWARVISH_ROUNDSHIELD: - case LARGE_SHIELD: - case SHIELD_OF_REFLECTION: - break; - default: impossible(unknown_type, c_shield, uarms->otyp); - } -*/ + /* + switch (uarms->otyp) { + case SMALL_SHIELD: + case ELVEN_SHIELD: + case URUK_HAI_SHIELD: + case ORCISH_SHIELD: + case DWARVISH_ROUNDSHIELD: + case LARGE_SHIELD: + case SHIELD_OF_REFLECTION: + break; + default: impossible(unknown_type, c_shield, uarms->otyp); + } + */ return 0; } @@ -577,34 +586,34 @@ int Shield_off(VOID_ARGS) { context.takeoff.mask &= ~W_ARMS; -/* - switch (uarms->otyp) { - case SMALL_SHIELD: - case ELVEN_SHIELD: - case URUK_HAI_SHIELD: - case ORCISH_SHIELD: - case DWARVISH_ROUNDSHIELD: - case LARGE_SHIELD: - case SHIELD_OF_REFLECTION: - break; - default: impossible(unknown_type, c_shield, uarms->otyp); - } -*/ - setworn((struct obj *)0, W_ARMS); + /* + switch (uarms->otyp) { + case SMALL_SHIELD: + case ELVEN_SHIELD: + case URUK_HAI_SHIELD: + case ORCISH_SHIELD: + case DWARVISH_ROUNDSHIELD: + case LARGE_SHIELD: + case SHIELD_OF_REFLECTION: + break; + default: impossible(unknown_type, c_shield, uarms->otyp); + } + */ + setworn((struct obj *) 0, W_ARMS); return 0; } STATIC_PTR int Shirt_on(VOID_ARGS) { -/* - switch (uarmu->otyp) { - case HAWAIIAN_SHIRT: - case T_SHIRT: - break; - default: impossible(unknown_type, c_shirt, uarmu->otyp); - } -*/ + /* + switch (uarmu->otyp) { + case HAWAIIAN_SHIRT: + case T_SHIRT: + break; + default: impossible(unknown_type, c_shirt, uarmu->otyp); + } + */ return 0; } @@ -612,20 +621,22 @@ int Shirt_off(VOID_ARGS) { context.takeoff.mask &= ~W_ARMU; -/* - switch (uarmu->otyp) { - case HAWAIIAN_SHIRT: - case T_SHIRT: - break; - default: impossible(unknown_type, c_shirt, uarmu->otyp); - } -*/ - setworn((struct obj *)0, W_ARMU); + /* + switch (uarmu->otyp) { + case HAWAIIAN_SHIRT: + case T_SHIRT: + break; + default: impossible(unknown_type, c_shirt, uarmu->otyp); + } + */ + setworn((struct obj *) 0, W_ARMU); return 0; } -/* This must be done in worn.c, because one of the possible intrinsics conferred - * is fire resistance, and we have to immediately set HFire_resistance in worn.c +/* This must be done in worn.c, because one of the possible intrinsics + * conferred + * is fire resistance, and we have to immediately set HFire_resistance in + * worn.c * since worn.c will check it before returning. */ STATIC_PTR @@ -639,7 +650,7 @@ int Armor_off(VOID_ARGS) { context.takeoff.mask &= ~W_ARM; - setworn((struct obj *)0, W_ARM); + setworn((struct obj *) 0, W_ARM); context.takeoff.cancelled_don = FALSE; return 0; } @@ -661,64 +672,66 @@ Amulet_on() { /* make sure amulet isn't wielded; can't use remove_worn_item() here because it has already been set worn in amulet slot */ - if (uamul == uwep) setuwep((struct obj *)0); - else if (uamul == uswapwep) setuswapwep((struct obj *)0); - else if (uamul == uquiver) setuqwep((struct obj *)0); + if (uamul == uwep) + setuwep((struct obj *) 0); + else if (uamul == uswapwep) + setuswapwep((struct obj *) 0); + else if (uamul == uquiver) + setuqwep((struct obj *) 0); - switch(uamul->otyp) { - case AMULET_OF_ESP: - case AMULET_OF_LIFE_SAVING: - case AMULET_VERSUS_POISON: - case AMULET_OF_REFLECTION: - case AMULET_OF_MAGICAL_BREATHING: - case FAKE_AMULET_OF_YENDOR: - break; - case AMULET_OF_UNCHANGING: - if (Slimed) make_slimed(0L, (char *)0); - break; - case AMULET_OF_CHANGE: - { - int orig_sex = poly_gender(); + switch (uamul->otyp) { + case AMULET_OF_ESP: + case AMULET_OF_LIFE_SAVING: + case AMULET_VERSUS_POISON: + case AMULET_OF_REFLECTION: + case AMULET_OF_MAGICAL_BREATHING: + case FAKE_AMULET_OF_YENDOR: + break; + case AMULET_OF_UNCHANGING: + if (Slimed) + make_slimed(0L, (char *) 0); + break; + case AMULET_OF_CHANGE: { + int orig_sex = poly_gender(); - if (Unchanging) break; - change_sex(); - /* Don't use same message as polymorph */ - if (orig_sex != poly_gender()) { - makeknown(AMULET_OF_CHANGE); - You("are suddenly very %s!", flags.female ? "feminine" - : "masculine"); - context.botl = 1; - } else - /* already polymorphed into single-gender monster; only - changed the character's base sex */ - You("don't feel like yourself."); - pline_The("amulet disintegrates!"); - if (orig_sex == poly_gender() && uamul->dknown && - !objects[AMULET_OF_CHANGE].oc_name_known && - !objects[AMULET_OF_CHANGE].oc_uname) - docall(uamul); - useup(uamul); - break; - } - case AMULET_OF_STRANGULATION: - if (can_be_strangled(&youmonst)) { - makeknown(AMULET_OF_STRANGULATION); - pline("It constricts your throat!"); - Strangled = 6L; - } - break; - case AMULET_OF_RESTFUL_SLEEP: - { - long newnap = (long)rnd(100), oldnap = (HSleepy & TIMEOUT); + if (Unchanging) + break; + change_sex(); + /* Don't use same message as polymorph */ + if (orig_sex != poly_gender()) { + makeknown(AMULET_OF_CHANGE); + You("are suddenly very %s!", + flags.female ? "feminine" : "masculine"); + context.botl = 1; + } else + /* already polymorphed into single-gender monster; only + changed the character's base sex */ + You("don't feel like yourself."); + pline_The("amulet disintegrates!"); + if (orig_sex == poly_gender() && uamul->dknown + && !objects[AMULET_OF_CHANGE].oc_name_known + && !objects[AMULET_OF_CHANGE].oc_uname) + docall(uamul); + useup(uamul); + break; + } + case AMULET_OF_STRANGULATION: + if (can_be_strangled(&youmonst)) { + makeknown(AMULET_OF_STRANGULATION); + pline("It constricts your throat!"); + Strangled = 6L; + } + break; + case AMULET_OF_RESTFUL_SLEEP: { + long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT); - /* avoid clobbering FROMOUTSIDE bit, which might have - gotten set by previously eating one of these amulets */ - if (newnap < oldnap || oldnap == 0L) - HSleepy = (HSleepy & ~TIMEOUT) | newnap; - } - break; - case AMULET_OF_YENDOR: - break; + /* avoid clobbering FROMOUTSIDE bit, which might have + gotten set by previously eating one of these amulets */ + if (newnap < oldnap || oldnap == 0L) + HSleepy = (HSleepy & ~TIMEOUT) | newnap; + } break; + case AMULET_OF_YENDOR: + break; } } @@ -727,51 +740,51 @@ Amulet_off() { context.takeoff.mask &= ~W_AMUL; - switch(uamul->otyp) { - case AMULET_OF_ESP: - /* need to update ability before calling see_monsters() */ - setworn((struct obj *)0, W_AMUL); - see_monsters(); - return; - case AMULET_OF_LIFE_SAVING: - case AMULET_VERSUS_POISON: - case AMULET_OF_REFLECTION: - case AMULET_OF_CHANGE: - case AMULET_OF_UNCHANGING: - case FAKE_AMULET_OF_YENDOR: - break; - case AMULET_OF_MAGICAL_BREATHING: - if (Underwater) { - /* HMagical_breathing must be set off - before calling drown() */ - setworn((struct obj *)0, W_AMUL); - if (!breathless(youmonst.data) && !amphibious(youmonst.data) - && !Swimming) { - You("suddenly inhale an unhealthy amount of water!"); - (void) drown(); - } - return; - } - break; - case AMULET_OF_STRANGULATION: - if (Strangled) { - if (Breathless) - Your("%s is no longer constricted!", body_part(NECK)); - else - You("can breathe more easily!"); - Strangled = 0L; - } - break; - case AMULET_OF_RESTFUL_SLEEP: - setworn((struct obj *)0, W_AMUL); - /* HSleepy = 0L; -- avoid clobbering FROMOUTSIDE bit */ - if (!ESleepy && !(HSleepy & ~TIMEOUT)) - HSleepy &= ~TIMEOUT; /* clear timeout bits */ - return; - case AMULET_OF_YENDOR: - break; + switch (uamul->otyp) { + case AMULET_OF_ESP: + /* need to update ability before calling see_monsters() */ + setworn((struct obj *) 0, W_AMUL); + see_monsters(); + return; + case AMULET_OF_LIFE_SAVING: + case AMULET_VERSUS_POISON: + case AMULET_OF_REFLECTION: + case AMULET_OF_CHANGE: + case AMULET_OF_UNCHANGING: + case FAKE_AMULET_OF_YENDOR: + break; + case AMULET_OF_MAGICAL_BREATHING: + if (Underwater) { + /* HMagical_breathing must be set off + before calling drown() */ + setworn((struct obj *) 0, W_AMUL); + if (!breathless(youmonst.data) && !amphibious(youmonst.data) + && !Swimming) { + You("suddenly inhale an unhealthy amount of water!"); + (void) drown(); + } + return; + } + break; + case AMULET_OF_STRANGULATION: + if (Strangled) { + if (Breathless) + Your("%s is no longer constricted!", body_part(NECK)); + else + You("can breathe more easily!"); + Strangled = 0L; + } + break; + case AMULET_OF_RESTFUL_SLEEP: + setworn((struct obj *) 0, W_AMUL); + /* HSleepy = 0L; -- avoid clobbering FROMOUTSIDE bit */ + if (!ESleepy && !(HSleepy & ~TIMEOUT)) + HSleepy &= ~TIMEOUT; /* clear timeout bits */ + return; + case AMULET_OF_YENDOR: + break; } - setworn((struct obj *)0, W_AMUL); + setworn((struct obj *) 0, W_AMUL); return; } @@ -785,15 +798,15 @@ boolean observed; /* if effect was observeable then we usually discover the type */ if (observed) { - /* if we already know the ring type which accomplishes this - effect (assumes there is at most one type for each effect), - mark this ring as having been seen (no need for makeknown); - otherwise if we have seen this ring, discover its type */ - if (objects[ringtype].oc_name_known) - ring->dknown = 1; - else if (ring->dknown) - makeknown(ringtype); -#if 0 /* see learnwand() */ + /* if we already know the ring type which accomplishes this + effect (assumes there is at most one type for each effect), + mark this ring as having been seen (no need for makeknown); + otherwise if we have seen this ring, discover its type */ + if (objects[ringtype].oc_name_known) + ring->dknown = 1; + else if (ring->dknown) + makeknown(ringtype); +#if 0 /* see learnwand() */ else ring->eknown = 1; #endif @@ -802,8 +815,9 @@ boolean observed; /* make enchantment of charged ring known (might be +0) and update perm invent window if we've seen this ring and know its type */ if (ring->dknown && objects[ringtype].oc_name_known) { - if (objects[ringtype].oc_charged) ring->known = 1; - update_inventory(); + if (objects[ringtype].oc_charged) + ring->known = 1; + update_inventory(); } } @@ -817,109 +831,114 @@ register struct obj *obj; /* make sure ring isn't wielded; can't use remove_worn_item() here because it has already been set worn in a ring slot */ - if (obj == uwep) setuwep((struct obj *)0); - else if (obj == uswapwep) setuswapwep((struct obj *)0); - else if (obj == uquiver) setuqwep((struct obj *)0); + if (obj == uwep) + setuwep((struct obj *) 0); + else if (obj == uswapwep) + setuswapwep((struct obj *) 0); + else if (obj == uquiver) + setuqwep((struct obj *) 0); /* only mask out W_RING when we don't have both left and right rings of the same type */ - if ((oldprop & W_RING) != W_RING) oldprop &= ~W_RING; + if ((oldprop & W_RING) != W_RING) + oldprop &= ~W_RING; - switch(obj->otyp){ - case RIN_TELEPORTATION: - case RIN_REGENERATION: - case RIN_SEARCHING: - case RIN_HUNGER: - case RIN_AGGRAVATE_MONSTER: - case RIN_POISON_RESISTANCE: - case RIN_FIRE_RESISTANCE: - case RIN_COLD_RESISTANCE: - case RIN_SHOCK_RESISTANCE: - case RIN_CONFLICT: - case RIN_TELEPORT_CONTROL: - case RIN_POLYMORPH: - case RIN_POLYMORPH_CONTROL: - case RIN_FREE_ACTION: - case RIN_SLOW_DIGESTION: - case RIN_SUSTAIN_ABILITY: - case MEAT_RING: - break; - case RIN_STEALTH: - toggle_stealth(obj, oldprop, TRUE); - break; - case RIN_WARNING: - see_monsters(); - break; - case RIN_SEE_INVISIBLE: - /* can now see invisible monsters */ - set_mimic_blocking(); /* do special mimic handling */ - see_monsters(); + switch (obj->otyp) { + case RIN_TELEPORTATION: + case RIN_REGENERATION: + case RIN_SEARCHING: + case RIN_HUNGER: + case RIN_AGGRAVATE_MONSTER: + case RIN_POISON_RESISTANCE: + case RIN_FIRE_RESISTANCE: + case RIN_COLD_RESISTANCE: + case RIN_SHOCK_RESISTANCE: + case RIN_CONFLICT: + case RIN_TELEPORT_CONTROL: + case RIN_POLYMORPH: + case RIN_POLYMORPH_CONTROL: + case RIN_FREE_ACTION: + case RIN_SLOW_DIGESTION: + case RIN_SUSTAIN_ABILITY: + case MEAT_RING: + break; + case RIN_STEALTH: + toggle_stealth(obj, oldprop, TRUE); + break; + case RIN_WARNING: + see_monsters(); + break; + case RIN_SEE_INVISIBLE: + /* can now see invisible monsters */ + set_mimic_blocking(); /* do special mimic handling */ + see_monsters(); - if (Invis && !oldprop && !HSee_invisible && !Blind) { - newsym(u.ux,u.uy); - pline("Suddenly you are transparent, but there!"); - learnring(obj, TRUE); - } - break; - case RIN_INVISIBILITY: - if (!oldprop && !HInvis && !BInvis && !Blind) { - learnring(obj, TRUE); - newsym(u.ux,u.uy); - self_invis_message(); - } - break; - case RIN_LEVITATION: - if (!oldprop && !HLevitation && !BLevitation) { - float_up(); - learnring(obj, TRUE); - spoteffects(FALSE); /* for sinks */ - } else { - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ - } - break; - case RIN_GAIN_STRENGTH: - which = A_STR; - goto adjust_attrib; - case RIN_GAIN_CONSTITUTION: - which = A_CON; - goto adjust_attrib; - case RIN_ADORNMENT: - which = A_CHA; - adjust_attrib: - old_attrib = ACURR(which); - ABON(which) += obj->spe; - observable = (old_attrib != ACURR(which)); - /* if didn't change, usually means ring is +0 but might - be because nonzero couldn't go below min or above max; - learn +0 enchantment if attribute value is not stuck - at a limit [and ring has been seen and its type is - already discovered, both handled by learnring()] */ - if (observable || !extremeattr(which)) - learnring(obj, observable); - context.botl = 1; - break; - case RIN_INCREASE_ACCURACY: /* KMH */ - u.uhitinc += obj->spe; - break; - case RIN_INCREASE_DAMAGE: - u.udaminc += obj->spe; - break; - case RIN_PROTECTION_FROM_SHAPE_CHAN: - rescham(); - break; - case RIN_PROTECTION: - /* usually learn enchantment and discover type; - won't happen if ring is unseen or if it's +0 - and the type hasn't been discovered yet */ - observable = (obj->spe != 0); - learnring(obj, observable); - if (obj->spe) find_ac(); /* updates botl */ - break; + if (Invis && !oldprop && !HSee_invisible && !Blind) { + newsym(u.ux, u.uy); + pline("Suddenly you are transparent, but there!"); + learnring(obj, TRUE); + } + break; + case RIN_INVISIBILITY: + if (!oldprop && !HInvis && !BInvis && !Blind) { + learnring(obj, TRUE); + newsym(u.ux, u.uy); + self_invis_message(); + } + break; + case RIN_LEVITATION: + if (!oldprop && !HLevitation && !BLevitation) { + float_up(); + learnring(obj, TRUE); + spoteffects(FALSE); /* for sinks */ + } else { + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + } + break; + case RIN_GAIN_STRENGTH: + which = A_STR; + goto adjust_attrib; + case RIN_GAIN_CONSTITUTION: + which = A_CON; + goto adjust_attrib; + case RIN_ADORNMENT: + which = A_CHA; + adjust_attrib: + old_attrib = ACURR(which); + ABON(which) += obj->spe; + observable = (old_attrib != ACURR(which)); + /* if didn't change, usually means ring is +0 but might + be because nonzero couldn't go below min or above max; + learn +0 enchantment if attribute value is not stuck + at a limit [and ring has been seen and its type is + already discovered, both handled by learnring()] */ + if (observable || !extremeattr(which)) + learnring(obj, observable); + context.botl = 1; + break; + case RIN_INCREASE_ACCURACY: /* KMH */ + u.uhitinc += obj->spe; + break; + case RIN_INCREASE_DAMAGE: + u.udaminc += obj->spe; + break; + case RIN_PROTECTION_FROM_SHAPE_CHAN: + rescham(); + break; + case RIN_PROTECTION: + /* usually learn enchantment and discover type; + won't happen if ring is unseen or if it's +0 + and the type hasn't been discovered yet */ + observable = (obj->spe != 0); + learnring(obj, observable); + if (obj->spe) + find_ac(); /* updates botl */ + break; } } STATIC_OVL void -Ring_off_or_gone(obj,gone) +Ring_off_or_gone(obj, gone) register struct obj *obj; boolean gone; { @@ -928,101 +947,105 @@ boolean gone; boolean observable; context.takeoff.mask &= ~mask; - if(!(u.uprops[objects[obj->otyp].oc_oprop].extrinsic & mask)) - impossible("Strange... I didn't know you had that ring."); - if(gone) setnotworn(obj); - else setworn((struct obj *)0, obj->owornmask); + if (!(u.uprops[objects[obj->otyp].oc_oprop].extrinsic & mask)) + impossible("Strange... I didn't know you had that ring."); + if (gone) + setnotworn(obj); + else + setworn((struct obj *) 0, obj->owornmask); - switch(obj->otyp) { - case RIN_TELEPORTATION: - case RIN_REGENERATION: - case RIN_SEARCHING: - case RIN_HUNGER: - case RIN_AGGRAVATE_MONSTER: - case RIN_POISON_RESISTANCE: - case RIN_FIRE_RESISTANCE: - case RIN_COLD_RESISTANCE: - case RIN_SHOCK_RESISTANCE: - case RIN_CONFLICT: - case RIN_TELEPORT_CONTROL: - case RIN_POLYMORPH: - case RIN_POLYMORPH_CONTROL: - case RIN_FREE_ACTION: - case RIN_SLOW_DIGESTION: - case RIN_SUSTAIN_ABILITY: - case MEAT_RING: - break; - case RIN_STEALTH: - toggle_stealth(obj, (EStealth & ~mask), FALSE); - break; - case RIN_WARNING: - see_monsters(); - break; - case RIN_SEE_INVISIBLE: - /* Make invisible monsters go away */ - if (!See_invisible) { - set_mimic_blocking(); /* do special mimic handling */ - see_monsters(); - } + switch (obj->otyp) { + case RIN_TELEPORTATION: + case RIN_REGENERATION: + case RIN_SEARCHING: + case RIN_HUNGER: + case RIN_AGGRAVATE_MONSTER: + case RIN_POISON_RESISTANCE: + case RIN_FIRE_RESISTANCE: + case RIN_COLD_RESISTANCE: + case RIN_SHOCK_RESISTANCE: + case RIN_CONFLICT: + case RIN_TELEPORT_CONTROL: + case RIN_POLYMORPH: + case RIN_POLYMORPH_CONTROL: + case RIN_FREE_ACTION: + case RIN_SLOW_DIGESTION: + case RIN_SUSTAIN_ABILITY: + case MEAT_RING: + break; + case RIN_STEALTH: + toggle_stealth(obj, (EStealth & ~mask), FALSE); + break; + case RIN_WARNING: + see_monsters(); + break; + case RIN_SEE_INVISIBLE: + /* Make invisible monsters go away */ + if (!See_invisible) { + set_mimic_blocking(); /* do special mimic handling */ + see_monsters(); + } - if (Invisible && !Blind) { - newsym(u.ux,u.uy); - pline("Suddenly you cannot see yourself."); - learnring(obj, TRUE); - } - break; - case RIN_INVISIBILITY: - if (!Invis && !BInvis && !Blind) { - newsym(u.ux,u.uy); - Your("body seems to unfade%s.", - See_invisible ? " completely" : ".."); - learnring(obj, TRUE); - } - break; - case RIN_LEVITATION: - if (!BLevitation) { - (void) float_down(0L, 0L); - if (!Levitation) learnring(obj, TRUE); - } else { - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ - } - break; - case RIN_GAIN_STRENGTH: - which = A_STR; - goto adjust_attrib; - case RIN_GAIN_CONSTITUTION: - which = A_CON; - goto adjust_attrib; - case RIN_ADORNMENT: - which = A_CHA; - adjust_attrib: - old_attrib = ACURR(which); - ABON(which) -= obj->spe; - observable = (old_attrib != ACURR(which)); - /* same criteria as Ring_on() */ - if (observable || !extremeattr(which)) - learnring(obj, observable); - context.botl = 1; - break; - case RIN_INCREASE_ACCURACY: /* KMH */ - u.uhitinc -= obj->spe; - break; - case RIN_INCREASE_DAMAGE: - u.udaminc -= obj->spe; - break; - case RIN_PROTECTION: - /* might have been put on while blind and we can now see - or perhaps been forgotten due to amnesia */ - observable = (obj->spe != 0); - learnring(obj, observable); - if (obj->spe) find_ac(); /* updates botl */ - break; - case RIN_PROTECTION_FROM_SHAPE_CHAN: - /* If you're no longer protected, let the chameleons - * change shape again -dgk - */ - restartcham(); - break; + if (Invisible && !Blind) { + newsym(u.ux, u.uy); + pline("Suddenly you cannot see yourself."); + learnring(obj, TRUE); + } + break; + case RIN_INVISIBILITY: + if (!Invis && !BInvis && !Blind) { + newsym(u.ux, u.uy); + Your("body seems to unfade%s.", + See_invisible ? " completely" : ".."); + learnring(obj, TRUE); + } + break; + case RIN_LEVITATION: + if (!BLevitation) { + (void) float_down(0L, 0L); + if (!Levitation) + learnring(obj, TRUE); + } else { + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + } + break; + case RIN_GAIN_STRENGTH: + which = A_STR; + goto adjust_attrib; + case RIN_GAIN_CONSTITUTION: + which = A_CON; + goto adjust_attrib; + case RIN_ADORNMENT: + which = A_CHA; + adjust_attrib: + old_attrib = ACURR(which); + ABON(which) -= obj->spe; + observable = (old_attrib != ACURR(which)); + /* same criteria as Ring_on() */ + if (observable || !extremeattr(which)) + learnring(obj, observable); + context.botl = 1; + break; + case RIN_INCREASE_ACCURACY: /* KMH */ + u.uhitinc -= obj->spe; + break; + case RIN_INCREASE_DAMAGE: + u.udaminc -= obj->spe; + break; + case RIN_PROTECTION: + /* might have been put on while blind and we can now see + or perhaps been forgotten due to amnesia */ + observable = (obj->spe != 0); + learnring(obj, observable); + if (obj->spe) + find_ac(); /* updates botl */ + break; + case RIN_PROTECTION_FROM_SHAPE_CHAN: + /* If you're no longer protected, let the chameleons + * change shape again -dgk + */ + restartcham(); + break; } } @@ -1030,140 +1053,157 @@ void Ring_off(obj) struct obj *obj; { - Ring_off_or_gone(obj,FALSE); + Ring_off_or_gone(obj, FALSE); } void Ring_gone(obj) struct obj *obj; { - Ring_off_or_gone(obj,TRUE); + Ring_off_or_gone(obj, TRUE); } void Blindf_on(otmp) register struct obj *otmp; { - boolean already_blind = Blind, changed = FALSE; + boolean already_blind = Blind, changed = FALSE; - /* blindfold might be wielded; release it for wearing */ - if (otmp->owornmask & (W_WEP|W_SWAPWEP|W_QUIVER)) - remove_worn_item(otmp, FALSE); - setworn(otmp, W_TOOL); - on_msg(otmp); + /* blindfold might be wielded; release it for wearing */ + if (otmp->owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)) + remove_worn_item(otmp, FALSE); + setworn(otmp, W_TOOL); + on_msg(otmp); - if (Blind && !already_blind) { - changed = TRUE; - if (flags.verbose) You_cant("see any more."); - /* set ball&chain variables before the hero goes blind */ - if (Punished) set_bc(0); - } else if (already_blind && !Blind) { - changed = TRUE; - /* "You are now wearing the Eyes of the Overworld." */ - You("can see!"); - } - if (changed) { - /* blindness has just been toggled */ - if (Blind_telepat || Infravision) see_monsters(); - vision_full_recalc = 1; /* recalc vision limits */ - if (!Blind) learn_unseen_invent(); - context.botl = 1; - } + if (Blind && !already_blind) { + changed = TRUE; + if (flags.verbose) + You_cant("see any more."); + /* set ball&chain variables before the hero goes blind */ + if (Punished) + set_bc(0); + } else if (already_blind && !Blind) { + changed = TRUE; + /* "You are now wearing the Eyes of the Overworld." */ + You("can see!"); + } + if (changed) { + /* blindness has just been toggled */ + if (Blind_telepat || Infravision) + see_monsters(); + vision_full_recalc = 1; /* recalc vision limits */ + if (!Blind) + learn_unseen_invent(); + context.botl = 1; + } } void Blindf_off(otmp) register struct obj *otmp; { - boolean was_blind = Blind, changed = FALSE; + boolean was_blind = Blind, changed = FALSE; - context.takeoff.mask &= ~W_TOOL; - setworn((struct obj *)0, otmp->owornmask); - off_msg(otmp); + context.takeoff.mask &= ~W_TOOL; + setworn((struct obj *) 0, otmp->owornmask); + off_msg(otmp); - if (Blind) { - if (was_blind) { - /* "still cannot see" makes no sense when removing lenses - since they can't have been the cause of your blindness */ - if (otmp->otyp != LENSES) - You("still cannot see."); - } else { - changed = TRUE; /* !was_blind */ - /* "You were wearing the Eyes of the Overworld." */ - You_cant("see anything now!"); - /* set ball&chain variables before the hero goes blind */ - if (Punished) set_bc(0); - } - } else if (was_blind) { - if (!gulp_blnd_check()) { - changed = TRUE; /* !Blind */ - You("can see again."); - } - } - if (changed) { - /* blindness has just been toggled */ - if (Blind_telepat || Infravision) see_monsters(); - vision_full_recalc = 1; /* recalc vision limits */ - if (!Blind) learn_unseen_invent(); - context.botl = 1; - } + if (Blind) { + if (was_blind) { + /* "still cannot see" makes no sense when removing lenses + since they can't have been the cause of your blindness */ + if (otmp->otyp != LENSES) + You("still cannot see."); + } else { + changed = TRUE; /* !was_blind */ + /* "You were wearing the Eyes of the Overworld." */ + You_cant("see anything now!"); + /* set ball&chain variables before the hero goes blind */ + if (Punished) + set_bc(0); + } + } else if (was_blind) { + if (!gulp_blnd_check()) { + changed = TRUE; /* !Blind */ + You("can see again."); + } + } + if (changed) { + /* blindness has just been toggled */ + if (Blind_telepat || Infravision) + see_monsters(); + vision_full_recalc = 1; /* recalc vision limits */ + if (!Blind) + learn_unseen_invent(); + context.botl = 1; + } } /* called in moveloop()'s prologue to set side-effects of worn start-up items; also used by poly_obj() when a worn item gets transformed */ void set_wear(obj) -struct obj *obj; /* if null, do all worn items; otherwise just obj itself */ +struct obj *obj; /* if null, do all worn items; otherwise just obj itself */ { - initial_don = !obj; + initial_don = !obj; - if (!obj ? ublindf != 0 : (obj == ublindf)) (void) Blindf_on(ublindf); - if (!obj ? uright != 0 : (obj == uright)) (void) Ring_on(uright); - if (!obj ? uleft != 0 : (obj == uleft)) (void) Ring_on(uleft); - if (!obj ? uamul != 0 : (obj == uamul)) (void) Amulet_on(); + if (!obj ? ublindf != 0 : (obj == ublindf)) + (void) Blindf_on(ublindf); + if (!obj ? uright != 0 : (obj == uright)) + (void) Ring_on(uright); + if (!obj ? uleft != 0 : (obj == uleft)) + (void) Ring_on(uleft); + if (!obj ? uamul != 0 : (obj == uamul)) + (void) Amulet_on(); - if (!obj ? uarmu != 0 : (obj == uarmu)) (void) Shirt_on(); - if (!obj ? uarm != 0 : (obj == uarm)) (void) Armor_on(); - if (!obj ? uarmc != 0 : (obj == uarmc)) (void) Cloak_on(); - if (!obj ? uarmf != 0 : (obj == uarmf)) (void) Boots_on(); - if (!obj ? uarmg != 0 : (obj == uarmg)) (void) Gloves_on(); - if (!obj ? uarmh != 0 : (obj == uarmh)) (void) Helmet_on(); - if (!obj ? uarms != 0 : (obj == uarms)) (void) Shield_on(); + if (!obj ? uarmu != 0 : (obj == uarmu)) + (void) Shirt_on(); + if (!obj ? uarm != 0 : (obj == uarm)) + (void) Armor_on(); + if (!obj ? uarmc != 0 : (obj == uarmc)) + (void) Cloak_on(); + if (!obj ? uarmf != 0 : (obj == uarmf)) + (void) Boots_on(); + if (!obj ? uarmg != 0 : (obj == uarmg)) + (void) Gloves_on(); + if (!obj ? uarmh != 0 : (obj == uarmh)) + (void) Helmet_on(); + if (!obj ? uarms != 0 : (obj == uarms)) + (void) Shield_on(); - initial_don = FALSE; + initial_don = FALSE; } /* check whether the target object is currently being put on (or taken off) */ -boolean -donning(otmp) /* also checks for doffing */ +boolean donning(otmp) /* also checks for doffing */ register struct obj *otmp; { - /* long what = (occupation == take_off) ? context.takeoff.what : 0L; */ - long what = context.takeoff.what; /* if nonzero, occupation is implied */ + /* long what = (occupation == take_off) ? context.takeoff.what : 0L; */ + long what = context.takeoff.what; /* if nonzero, occupation is implied */ boolean result = FALSE; /* 'W' and 'T' set afternmv, 'A' sets context.takeoff.what */ if (otmp == uarm) - result = (afternmv == Armor_on || afternmv == Armor_off || - what == WORN_ARMOR); + result = (afternmv == Armor_on || afternmv == Armor_off + || what == WORN_ARMOR); else if (otmp == uarmu) - result = (afternmv == Shirt_on || afternmv == Shirt_off || - what == WORN_SHIRT); + result = (afternmv == Shirt_on || afternmv == Shirt_off + || what == WORN_SHIRT); else if (otmp == uarmc) - result = (afternmv == Cloak_on || afternmv == Cloak_off || - what == WORN_CLOAK); + result = (afternmv == Cloak_on || afternmv == Cloak_off + || what == WORN_CLOAK); else if (otmp == uarmf) - result = (afternmv == Boots_on || afternmv == Boots_off || - what == WORN_BOOTS); + result = (afternmv == Boots_on || afternmv == Boots_off + || what == WORN_BOOTS); else if (otmp == uarmh) - result = (afternmv == Helmet_on || afternmv == Helmet_off || - what == WORN_HELMET); + result = (afternmv == Helmet_on || afternmv == Helmet_off + || what == WORN_HELMET); else if (otmp == uarmg) - result = (afternmv == Gloves_on || afternmv == Gloves_off || - what == WORN_GLOVES); + result = (afternmv == Gloves_on || afternmv == Gloves_off + || what == WORN_GLOVES); else if (otmp == uarms) - result = (afternmv == Shield_on || afternmv == Shield_off || - what == WORN_SHIELD); + result = (afternmv == Shield_on || afternmv == Shield_off + || what == WORN_SHIELD); return result; } @@ -1179,19 +1219,19 @@ struct obj *otmp; /* 'T' (also 'W') sets afternmv, 'A' sets context.takeoff.what */ if (otmp == uarm) - result = (afternmv == Armor_off || what == WORN_ARMOR); + result = (afternmv == Armor_off || what == WORN_ARMOR); else if (otmp == uarmu) - result = (afternmv == Shirt_off || what == WORN_SHIRT); + result = (afternmv == Shirt_off || what == WORN_SHIRT); else if (otmp == uarmc) - result = (afternmv == Cloak_off || what == WORN_CLOAK); + result = (afternmv == Cloak_off || what == WORN_CLOAK); else if (otmp == uarmf) - result = (afternmv == Boots_off || what == WORN_BOOTS); + result = (afternmv == Boots_off || what == WORN_BOOTS); else if (otmp == uarmh) - result = (afternmv == Helmet_off || what == WORN_HELMET); + result = (afternmv == Helmet_off || what == WORN_HELMET); else if (otmp == uarmg) - result = (afternmv == Gloves_off || what == WORN_GLOVES); + result = (afternmv == Gloves_off || what == WORN_GLOVES); else if (otmp == uarms) - result = (afternmv == Shield_off || what == WORN_SHIELD); + result = (afternmv == Shield_off || what == WORN_SHIELD); return result; } @@ -1199,25 +1239,24 @@ struct obj *otmp; void cancel_don() { - /* the piece of armor we were donning/doffing has vanished, so stop - * wasting time on it (and don't dereference it when donning would - * otherwise finish) - */ - context.takeoff.cancelled_don = (afternmv == Boots_on || - afternmv == Helmet_on || - afternmv == Gloves_on || - afternmv == Armor_on); - afternmv = 0; - nomovemsg = (char *)0; - multi = 0; - context.takeoff.delay = 0; - context.takeoff.what = 0L; + /* the piece of armor we were donning/doffing has vanished, so stop + * wasting time on it (and don't dereference it when donning would + * otherwise finish) + */ + context.takeoff.cancelled_don = + (afternmv == Boots_on || afternmv == Helmet_on + || afternmv == Gloves_on || afternmv == Armor_on); + afternmv = 0; + nomovemsg = (char *) 0; + multi = 0; + context.takeoff.delay = 0; + context.takeoff.what = 0L; } /* called by steal() during theft from hero; interrupt donning/doffing */ int stop_donning(stolenobj) -struct obj *stolenobj; /* no message if stolenobj is already being doffing */ +struct obj *stolenobj; /* no message if stolenobj is already being doffing */ { char buf[BUFSZ]; struct obj *otmp; @@ -1225,9 +1264,11 @@ struct obj *stolenobj; /* no message if stolenobj is already being doffing */ int result = 0; for (otmp = invent; otmp; otmp = otmp->nobj) - if ((otmp->owornmask & W_ARMOR) && donning(otmp)) break; - /* at most one item will pass donning() test at any given time */ - if (!otmp) return 0; + if ((otmp->owornmask & W_ARMOR) && donning(otmp)) + break; + /* at most one item will pass donning() test at any given time */ + if (!otmp) + return 0; /* donning() returns True when doffing too; doffing() is more specific */ putting_on = !doffing(otmp); @@ -1237,12 +1278,12 @@ struct obj *stolenobj; /* no message if stolenobj is already being doffing */ by unmul() since the on or off action isn't completing */ afternmv = 0; if (putting_on || otmp != stolenobj) { - Sprintf(buf, "You stop %s %s.", - putting_on ? "putting on" : "taking off", - thesimpleoname(otmp)); + Sprintf(buf, "You stop %s %s.", + putting_on ? "putting on" : "taking off", + thesimpleoname(otmp)); } else { - buf[0] = '\0'; /* silently stop doffing stolenobj */ - result = -multi; /* remember this before calling unmul() */ + buf[0] = '\0'; /* silently stop doffing stolenobj */ + result = -multi; /* remember this before calling unmul() */ } unmul(buf); /* while putting on, item becomes worn immediately but side-effects are @@ -1250,135 +1291,152 @@ struct obj *stolenobj; /* no message if stolenobj is already being doffing */ (while taking off, item stays worn until the delay expires; when interrupted, leave it worn) */ if (putting_on) - remove_worn_item(otmp, FALSE); + remove_worn_item(otmp, FALSE); return result; } -static NEARDATA const char clothes[] = {ARMOR_CLASS, 0}; -static NEARDATA const char accessories[] = {RING_CLASS, AMULET_CLASS, TOOL_CLASS, FOOD_CLASS, 0}; +static NEARDATA const char clothes[] = { ARMOR_CLASS, 0 }; +static NEARDATA const char accessories[] = { RING_CLASS, AMULET_CLASS, + TOOL_CLASS, FOOD_CLASS, 0 }; /* the 'T' command */ int dotakeoff() { - register struct obj *otmp = (struct obj *)0; - int armorpieces = 0; + register struct obj *otmp = (struct obj *) 0; + int armorpieces = 0; -#define MOREARM(x) if (x) { armorpieces++; otmp = x; } - MOREARM(uarmh); - MOREARM(uarms); - MOREARM(uarmg); - MOREARM(uarmf); - if (uarmc) { - armorpieces++; - otmp = uarmc; - } else if (uarm) { - armorpieces++; - otmp = uarm; - } else if (uarmu) { - armorpieces++; - otmp = uarmu; - } - if (!armorpieces) { - /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */ - if (uskin) - pline_The("%s merged with your skin!", - uskin->otyp >= GRAY_DRAGON_SCALES ? - "dragon scales are" : "dragon scale mail is"); - else - pline("Not wearing any armor.%s", (iflags.cmdassist && - (uleft || uright || uamul || ublindf)) ? - " Use 'R' command to remove accessories." : ""); - return 0; - } - if (armorpieces > 1 || ParanoidRemove) - otmp = getobj(clothes, "take off"); - if (!otmp) return 0; - if (!(otmp->owornmask & W_ARMOR)) { - You("are not wearing that."); - return 0; - } - /* note: the `uskin' case shouldn't be able to happen here; dragons - can't wear any armor so will end up with `armorpieces == 0' above */ - if (otmp == uskin || ((otmp == uarm) && uarmc) - || ((otmp == uarmu) && (uarmc || uarm))) { - char why[BUFSZ], what[BUFSZ]; +#define MOREARM(x) \ + if (x) { \ + armorpieces++; \ + otmp = x; \ + } + MOREARM(uarmh); + MOREARM(uarms); + MOREARM(uarmg); + MOREARM(uarmf); + if (uarmc) { + armorpieces++; + otmp = uarmc; + } else if (uarm) { + armorpieces++; + otmp = uarm; + } else if (uarmu) { + armorpieces++; + otmp = uarmu; + } + if (!armorpieces) { + /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */ + if (uskin) + pline_The("%s merged with your skin!", + uskin->otyp >= GRAY_DRAGON_SCALES + ? "dragon scales are" + : "dragon scale mail is"); + else + pline("Not wearing any armor.%s", + (iflags.cmdassist && (uleft || uright || uamul || ublindf)) + ? " Use 'R' command to remove accessories." + : ""); + return 0; + } + if (armorpieces > 1 || ParanoidRemove) + otmp = getobj(clothes, "take off"); + if (!otmp) + return 0; + if (!(otmp->owornmask & W_ARMOR)) { + You("are not wearing that."); + return 0; + } + /* note: the `uskin' case shouldn't be able to happen here; dragons + can't wear any armor so will end up with `armorpieces == 0' above */ + if (otmp == uskin || ((otmp == uarm) && uarmc) + || ((otmp == uarmu) && (uarmc || uarm))) { + char why[BUFSZ], what[BUFSZ]; - why[0] = what[0] = '\0'; - if (otmp != uskin) { - if (uarmc) Strcat(what, cloak_simple_name(uarmc)); - if ((otmp == uarmu) && uarm) { - if (uarmc) Strcat(what, " and "); - Strcat(what, suit_simple_name(uarm)); - } - Sprintf(why, " without taking off your %s first", what); - } - You_cant("take that off%s.", why); - return 0; - } + why[0] = what[0] = '\0'; + if (otmp != uskin) { + if (uarmc) + Strcat(what, cloak_simple_name(uarmc)); + if ((otmp == uarmu) && uarm) { + if (uarmc) + Strcat(what, " and "); + Strcat(what, suit_simple_name(uarm)); + } + Sprintf(why, " without taking off your %s first", what); + } + You_cant("take that off%s.", why); + return 0; + } - reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */ - (void) select_off(otmp); - if (!context.takeoff.mask) return 0; - reset_remarm(); /* armoroff() doesn't use context.takeoff.mask */ + reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */ + (void) select_off(otmp); + if (!context.takeoff.mask) + return 0; + reset_remarm(); /* armoroff() doesn't use context.takeoff.mask */ - (void) armoroff(otmp); - return(1); + (void) armoroff(otmp); + return (1); } /* the 'R' command */ int doremring() { - register struct obj *otmp = 0; - int Accessories = 0; + register struct obj *otmp = 0; + int Accessories = 0; -#define MOREACC(x) if (x) { Accessories++; otmp = x; } - MOREACC(uleft); - MOREACC(uright); - MOREACC(uamul); - MOREACC(ublindf); +#define MOREACC(x) \ + if (x) { \ + Accessories++; \ + otmp = x; \ + } + MOREACC(uleft); + MOREACC(uright); + MOREACC(uamul); + MOREACC(ublindf); - if(!Accessories) { - pline("Not wearing any accessories.%s", - (iflags.cmdassist - && (uarm || uarmc || uarmu || uarms || uarmh || uarmg - || uarmf)) ? - " Use 'T' command to take off armor." : ""); - return(0); - } - if (Accessories > 1 || ParanoidRemove) - otmp = getobj(accessories, "remove"); - if (!otmp) return 0; - if (!(otmp->owornmask & (W_RING | W_AMUL | W_TOOL))) { - You("are not wearing that."); - return 0; - } + if (!Accessories) { + pline("Not wearing any accessories.%s", + (iflags.cmdassist && (uarm || uarmc || uarmu || uarms || uarmh + || uarmg || uarmf)) + ? " Use 'T' command to take off armor." + : ""); + return (0); + } + if (Accessories > 1 || ParanoidRemove) + otmp = getobj(accessories, "remove"); + if (!otmp) + return 0; + if (!(otmp->owornmask & (W_RING | W_AMUL | W_TOOL))) { + You("are not wearing that."); + return 0; + } - reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */ - (void) select_off(otmp); - if (!context.takeoff.mask) return 0; - reset_remarm(); /* not used by Ring_/Amulet_/Blindf_off() */ + reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */ + (void) select_off(otmp); + if (!context.takeoff.mask) + return 0; + reset_remarm(); /* not used by Ring_/Amulet_/Blindf_off() */ - if (otmp == uright || otmp == uleft) { - /* Sometimes we want to give the off_msg before removing and - * sometimes after; for instance, "you were wearing a moonstone - * ring (on right hand)" is desired but "you were wearing a - * square amulet (being worn)" is not because of the redundant - * "being worn". - */ - off_msg(otmp); - Ring_off(otmp); - } else if (otmp == uamul) { - Amulet_off(); - off_msg(otmp); - } else if (otmp == ublindf) { - Blindf_off(otmp); /* does its own off_msg */ - } else { - impossible("removing strange accessory?"); - } - return(1); + if (otmp == uright || otmp == uleft) { + /* Sometimes we want to give the off_msg before removing and + * sometimes after; for instance, "you were wearing a moonstone + * ring (on right hand)" is desired but "you were wearing a + * square amulet (being worn)" is not because of the redundant + * "being worn". + */ + off_msg(otmp); + Ring_off(otmp); + } else if (otmp == uamul) { + Amulet_off(); + off_msg(otmp); + } else if (otmp == ublindf) { + Blindf_off(otmp); /* does its own off_msg */ + } else { + impossible("removing strange accessory?"); + } + return (1); } /* Check if something worn is cursed _and_ unremovable. */ @@ -1386,88 +1444,87 @@ int cursed(otmp) register struct obj *otmp; { - /* Curses, like chickens, come home to roost. */ - if((otmp == uwep) ? welded(otmp) : (int)otmp->cursed) { - boolean use_plural = (is_boots(otmp) || is_gloves(otmp) || - otmp->otyp == LENSES || otmp->quan > 1L); + /* Curses, like chickens, come home to roost. */ + if ((otmp == uwep) ? welded(otmp) : (int) otmp->cursed) { + boolean use_plural = (is_boots(otmp) || is_gloves(otmp) + || otmp->otyp == LENSES || otmp->quan > 1L); - You("can't. %s cursed.", use_plural ? "They are" : "It is"); - otmp->bknown = TRUE; - return(1); - } - return(0); + You("can't. %s cursed.", use_plural ? "They are" : "It is"); + otmp->bknown = TRUE; + return (1); + } + return (0); } int armoroff(otmp) register struct obj *otmp; { - register int delay = -objects[otmp->otyp].oc_delay; + register int delay = -objects[otmp->otyp].oc_delay; - if(cursed(otmp)) return(0); - if(delay) { - nomul(delay); - multi_reason = "disrobing"; - if (is_helmet(otmp)) { - /* ick... */ - nomovemsg = !strcmp(helm_simple_name(otmp), "hat") ? - "You finish taking off your hat." : - "You finish taking off your helmet."; - afternmv = Helmet_off; - } - else if (is_gloves(otmp)) { - nomovemsg = "You finish taking off your gloves."; - afternmv = Gloves_off; - } - else if (is_boots(otmp)) { - nomovemsg = "You finish taking off your boots."; - afternmv = Boots_off; - } - else { - nomovemsg = "You finish taking off your suit."; - afternmv = Armor_off; - } - } else { - /* Be warned! We want off_msg after removing the item to - * avoid "You were wearing ____ (being worn)." However, an - * item which grants fire resistance might cause some trouble - * if removed in Hell and lifesaving puts it back on; in this - * case the message will be printed at the wrong time (after - * the messages saying you died and were lifesaved). Luckily, - * no cloak, shield, or fast-removable armor grants fire - * resistance, so we can safely do the off_msg afterwards. - * Rings do grant fire resistance, but for rings we want the - * off_msg before removal anyway so there's no problem. Take - * care in adding armors granting fire resistance; this code - * might need modification. - * 3.2 (actually 3.1 even): that comment is obsolete since - * fire resistance is not required for Gehennom so setworn() - * doesn't force the resistance granting item to be re-worn - * after being lifesaved anymore. - */ - if(is_cloak(otmp)) - (void) Cloak_off(); - else if(is_shield(otmp)) - (void) Shield_off(); - else setworn((struct obj *)0, otmp->owornmask & W_ARMOR); - off_msg(otmp); - } - context.takeoff.mask = context.takeoff.what = 0L; - return(1); + if (cursed(otmp)) + return (0); + if (delay) { + nomul(delay); + multi_reason = "disrobing"; + if (is_helmet(otmp)) { + /* ick... */ + nomovemsg = !strcmp(helm_simple_name(otmp), "hat") + ? "You finish taking off your hat." + : "You finish taking off your helmet."; + afternmv = Helmet_off; + } else if (is_gloves(otmp)) { + nomovemsg = "You finish taking off your gloves."; + afternmv = Gloves_off; + } else if (is_boots(otmp)) { + nomovemsg = "You finish taking off your boots."; + afternmv = Boots_off; + } else { + nomovemsg = "You finish taking off your suit."; + afternmv = Armor_off; + } + } else { + /* Be warned! We want off_msg after removing the item to + * avoid "You were wearing ____ (being worn)." However, an + * item which grants fire resistance might cause some trouble + * if removed in Hell and lifesaving puts it back on; in this + * case the message will be printed at the wrong time (after + * the messages saying you died and were lifesaved). Luckily, + * no cloak, shield, or fast-removable armor grants fire + * resistance, so we can safely do the off_msg afterwards. + * Rings do grant fire resistance, but for rings we want the + * off_msg before removal anyway so there's no problem. Take + * care in adding armors granting fire resistance; this code + * might need modification. + * 3.2 (actually 3.1 even): that comment is obsolete since + * fire resistance is not required for Gehennom so setworn() + * doesn't force the resistance granting item to be re-worn + * after being lifesaved anymore. + */ + if (is_cloak(otmp)) + (void) Cloak_off(); + else if (is_shield(otmp)) + (void) Shield_off(); + else + setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); + off_msg(otmp); + } + context.takeoff.mask = context.takeoff.what = 0L; + return (1); } STATIC_OVL void already_wearing(cc) const char *cc; { - You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.'); + You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.'); } STATIC_OVL void already_wearing2(cc1, cc2) const char *cc1, *cc2; { - You_cant("wear %s because you're wearing %s there already.", cc1, cc2); + You_cant("wear %s because you're wearing %s there already.", cc1, cc2); } /* @@ -1478,7 +1535,7 @@ const char *cc1, *cc2; * output: mask (otmp's armor type) */ int -canwearobj(otmp,mask,noisy) +canwearobj(otmp, mask, noisy) struct obj *otmp; long *mask; boolean noisy; @@ -1486,139 +1543,157 @@ boolean noisy; int err = 0; const char *which; - which = is_cloak(otmp) ? c_cloak : - is_shirt(otmp) ? c_shirt : - is_suit(otmp) ? c_suit : 0; + which = is_cloak(otmp) ? c_cloak : is_shirt(otmp) + ? c_shirt + : is_suit(otmp) ? c_suit : 0; if (which && cantweararm(youmonst.data) && - /* same exception for cloaks as used in m_dowear() */ - (which != c_cloak || youmonst.data->msize != MZ_SMALL) && - (racial_exception(&youmonst, otmp) < 1)) { - if (noisy) pline_The("%s will not fit on your body.", which); - return 0; + /* same exception for cloaks as used in m_dowear() */ + (which != c_cloak || youmonst.data->msize != MZ_SMALL) + && (racial_exception(&youmonst, otmp) < 1)) { + if (noisy) + pline_The("%s will not fit on your body.", which); + return 0; } else if (otmp->owornmask & W_ARMOR) { - if (noisy) already_wearing(c_that_); - return 0; + if (noisy) + already_wearing(c_that_); + return 0; } if (welded(uwep) && bimanual(uwep) && (is_suit(otmp) || is_shirt(otmp))) { - if (noisy) - You("cannot do that while holding your %s.", - is_sword(uwep) ? c_sword : c_weapon); - return 0; + if (noisy) + You("cannot do that while holding your %s.", + is_sword(uwep) ? c_sword : c_weapon); + return 0; } if (is_helmet(otmp)) { - if (uarmh) { - if (noisy) already_wearing(an(helm_simple_name(uarmh))); - err++; - } else if (Upolyd && has_horns(youmonst.data) && !is_flimsy(otmp)) { - /* (flimsy exception matches polyself handling) */ - if (noisy) - pline_The("%s won't fit over your horn%s.", - helm_simple_name(otmp), - plur(num_horns(youmonst.data))); - err++; - } else - *mask = W_ARMH; + if (uarmh) { + if (noisy) + already_wearing(an(helm_simple_name(uarmh))); + err++; + } else if (Upolyd && has_horns(youmonst.data) && !is_flimsy(otmp)) { + /* (flimsy exception matches polyself handling) */ + if (noisy) + pline_The("%s won't fit over your horn%s.", + helm_simple_name(otmp), + plur(num_horns(youmonst.data))); + err++; + } else + *mask = W_ARMH; } else if (is_shield(otmp)) { - if (uarms) { - if (noisy) already_wearing(an(c_shield)); - err++; - } else if (uwep && bimanual(uwep)) { - if (noisy) - You("cannot wear a shield while wielding a two-handed %s.", - is_sword(uwep) ? c_sword : - (uwep->otyp == BATTLE_AXE) ? c_axe : c_weapon); - err++; - } else if (u.twoweap) { - if (noisy) - You("cannot wear a shield while wielding two weapons."); - err++; - } else - *mask = W_ARMS; + if (uarms) { + if (noisy) + already_wearing(an(c_shield)); + err++; + } else if (uwep && bimanual(uwep)) { + if (noisy) + You("cannot wear a shield while wielding a two-handed %s.", + is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE) + ? c_axe + : c_weapon); + err++; + } else if (u.twoweap) { + if (noisy) + You("cannot wear a shield while wielding two weapons."); + err++; + } else + *mask = W_ARMS; } else if (is_boots(otmp)) { - if (uarmf) { - if (noisy) already_wearing(c_boots); - err++; - } else if (Upolyd && slithy(youmonst.data)) { - if (noisy) You("have no feet..."); /* not body_part(FOOT) */ - err++; - } else if (Upolyd && youmonst.data->mlet == S_CENTAUR) { - /* break_armor() pushes boots off for centaurs, - so don't let dowear() put them back on... */ - if (noisy) pline("You have too many hooves to wear %s.", - c_boots); /* makeplural(body_part(FOOT)) yields - "rear hooves" which sounds odd */ - err++; - } else if (u.utrap && (u.utraptype == TT_BEARTRAP || - u.utraptype == TT_INFLOOR || - u.utraptype == TT_LAVA || - u.utraptype == TT_BURIEDBALL)) { - if (u.utraptype == TT_BEARTRAP) { - if (noisy) Your("%s is trapped!", body_part(FOOT)); - } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { - if (noisy) Your("%s are stuck in the %s!", - makeplural(body_part(FOOT)), - surface(u.ux, u.uy)); - } else { /*TT_BURIEDBALL*/ - if (noisy) Your("%s is attached to the buried ball!", - body_part(LEG)); - } - err++; - } else - *mask = W_ARMF; + if (uarmf) { + if (noisy) + already_wearing(c_boots); + err++; + } else if (Upolyd && slithy(youmonst.data)) { + if (noisy) + You("have no feet..."); /* not body_part(FOOT) */ + err++; + } else if (Upolyd && youmonst.data->mlet == S_CENTAUR) { + /* break_armor() pushes boots off for centaurs, + so don't let dowear() put them back on... */ + if (noisy) + pline("You have too many hooves to wear %s.", + c_boots); /* makeplural(body_part(FOOT)) yields + "rear hooves" which sounds odd */ + err++; + } else if (u.utrap + && (u.utraptype == TT_BEARTRAP || u.utraptype == TT_INFLOOR + || u.utraptype == TT_LAVA + || u.utraptype == TT_BURIEDBALL)) { + if (u.utraptype == TT_BEARTRAP) { + if (noisy) + Your("%s is trapped!", body_part(FOOT)); + } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { + if (noisy) + Your("%s are stuck in the %s!", + makeplural(body_part(FOOT)), surface(u.ux, u.uy)); + } else { /*TT_BURIEDBALL*/ + if (noisy) + Your("%s is attached to the buried ball!", + body_part(LEG)); + } + err++; + } else + *mask = W_ARMF; } else if (is_gloves(otmp)) { - if (uarmg) { - if (noisy) already_wearing(c_gloves); - err++; - } else if (welded(uwep)) { - if (noisy) You("cannot wear gloves over your %s.", - is_sword(uwep) ? c_sword : c_weapon); - err++; - } else - *mask = W_ARMG; + if (uarmg) { + if (noisy) + already_wearing(c_gloves); + err++; + } else if (welded(uwep)) { + if (noisy) + You("cannot wear gloves over your %s.", + is_sword(uwep) ? c_sword : c_weapon); + err++; + } else + *mask = W_ARMG; } else if (is_shirt(otmp)) { - if (uarm || uarmc || uarmu) { - if (uarmu) { - if (noisy) already_wearing(an(c_shirt)); - } else { - if (noisy) You_cant("wear that over your %s.", - (uarm && !uarmc) ? c_armor : cloak_simple_name(uarmc)); - } - err++; - } else - *mask = W_ARMU; + if (uarm || uarmc || uarmu) { + if (uarmu) { + if (noisy) + already_wearing(an(c_shirt)); + } else { + if (noisy) + You_cant("wear that over your %s.", + (uarm && !uarmc) ? c_armor + : cloak_simple_name(uarmc)); + } + err++; + } else + *mask = W_ARMU; } else if (is_cloak(otmp)) { - if (uarmc) { - if (noisy) already_wearing(an(cloak_simple_name(uarmc))); - err++; - } else - *mask = W_ARMC; + if (uarmc) { + if (noisy) + already_wearing(an(cloak_simple_name(uarmc))); + err++; + } else + *mask = W_ARMC; } else if (is_suit(otmp)) { - if (uarmc) { - if (noisy) You("cannot wear armor over a %s.", - cloak_simple_name(uarmc)); - err++; - } else if (uarm) { - if (noisy) already_wearing("some armor"); - err++; - } else - *mask = W_ARM; + if (uarmc) { + if (noisy) + You("cannot wear armor over a %s.", cloak_simple_name(uarmc)); + err++; + } else if (uarm) { + if (noisy) + already_wearing("some armor"); + err++; + } else + *mask = W_ARM; } else { - /* getobj can't do this after setting its allow_all flag; that - happens if you have armor for slots that are covered up or - extra armor for slots that are filled */ - if (noisy) silly_thing("wear", otmp); - err++; + /* getobj can't do this after setting its allow_all flag; that + happens if you have armor for slots that are covered up or + extra armor for slots that are filled */ + if (noisy) + silly_thing("wear", otmp); + err++; } -/* Unnecessary since now only weapons and special items like pick-axes get - * welded to your hand, not armor - if (welded(otmp)) { - if (!err++) { - if (noisy) weldmsg(otmp); - } - } - */ + /* Unnecessary since now only weapons and special items like pick-axes get + * welded to your hand, not armor + if (welded(otmp)) { + if (!err++) { + if (noisy) weldmsg(otmp); + } + } + */ return !err; } @@ -1626,84 +1701,94 @@ boolean noisy; int dowear() { - struct obj *otmp; - int delay; - long mask = 0; + struct obj *otmp; + int delay; + long mask = 0; - /* cantweararm checks for suits of armor */ - /* verysmall or nohands checks for shields, gloves, etc... */ - if ((verysmall(youmonst.data) || nohands(youmonst.data))) { - pline("Don't even bother."); - return(0); - } + /* cantweararm checks for suits of armor */ + /* verysmall or nohands checks for shields, gloves, etc... */ + if ((verysmall(youmonst.data) || nohands(youmonst.data))) { + pline("Don't even bother."); + return (0); + } - otmp = getobj(clothes, "wear"); - if(!otmp) return(0); + otmp = getobj(clothes, "wear"); + if (!otmp) + return (0); - if (!canwearobj(otmp,&mask,TRUE)) return(0); + if (!canwearobj(otmp, &mask, TRUE)) + return (0); - if (!retouch_object(&otmp, FALSE)) - return 1; /* costs a turn even though it didn't get worn */ + if (!retouch_object(&otmp, FALSE)) + return 1; /* costs a turn even though it didn't get worn */ - if (otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT && - qstart_level.dnum == u.uz.dnum) { /* in quest */ - if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]) - You("narrowly avoid losing all chance at your goal."); - else /* converted */ - You("are suddenly overcome with shame and change your mind."); - u.ublessed = 0; /* lose your god's protection */ - makeknown(otmp->otyp); - context.botl = 1; - return 1; - } + if (otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT + && qstart_level.dnum == u.uz.dnum) { /* in quest */ + if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]) + You("narrowly avoid losing all chance at your goal."); + else /* converted */ + You("are suddenly overcome with shame and change your mind."); + u.ublessed = 0; /* lose your god's protection */ + makeknown(otmp->otyp); + context.botl = 1; + return 1; + } - otmp->known = 1; /* since AC is shown on the status line */ - /* if the armor is wielded, release it for wearing */ - if (otmp->owornmask & (W_WEP|W_SWAPWEP|W_QUIVER)) - remove_worn_item(otmp, FALSE); - setworn(otmp, mask); - delay = -objects[otmp->otyp].oc_delay; - if(delay){ - nomul(delay); - multi_reason = "dressing up"; - if(is_boots(otmp)) afternmv = Boots_on; - if(is_helmet(otmp)) afternmv = Helmet_on; - if(is_gloves(otmp)) afternmv = Gloves_on; - if(otmp == uarm) afternmv = Armor_on; - nomovemsg = "You finish your dressing maneuver."; - } else { - if(is_cloak(otmp)) (void) Cloak_on(); - if (is_shield(otmp)) (void) Shield_on(); - if (is_shirt(otmp)) (void) Shirt_on(); - on_msg(otmp); - } - context.takeoff.mask = context.takeoff.what = 0L; - return(1); + otmp->known = 1; /* since AC is shown on the status line */ + /* if the armor is wielded, release it for wearing */ + if (otmp->owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)) + remove_worn_item(otmp, FALSE); + setworn(otmp, mask); + delay = -objects[otmp->otyp].oc_delay; + if (delay) { + nomul(delay); + multi_reason = "dressing up"; + if (is_boots(otmp)) + afternmv = Boots_on; + if (is_helmet(otmp)) + afternmv = Helmet_on; + if (is_gloves(otmp)) + afternmv = Gloves_on; + if (otmp == uarm) + afternmv = Armor_on; + nomovemsg = "You finish your dressing maneuver."; + } else { + if (is_cloak(otmp)) + (void) Cloak_on(); + if (is_shield(otmp)) + (void) Shield_on(); + if (is_shirt(otmp)) + (void) Shirt_on(); + on_msg(otmp); + } + context.takeoff.mask = context.takeoff.what = 0L; + return (1); } int doputon() { - struct obj *otmp; - long mask = 0L; + struct obj *otmp; + long mask = 0L; - if(uleft && uright && uamul && ublindf) { - Your("%s%s are full, and you're already wearing an amulet and %s.", - humanoid(youmonst.data) ? "ring-" : "", - makeplural(body_part(FINGER)), - ublindf->otyp==LENSES ? "some lenses" : "a blindfold"); - return(0); - } - otmp = getobj(accessories, "put on"); - if(!otmp) return(0); - if(otmp->owornmask & (W_RING | W_AMUL | W_TOOL)) { - already_wearing(c_that_); - return(0); - } - if(welded(otmp)) { - weldmsg(otmp); - return(0); - } + if (uleft && uright && uamul && ublindf) { + Your("%s%s are full, and you're already wearing an amulet and %s.", + humanoid(youmonst.data) ? "ring-" : "", + makeplural(body_part(FINGER)), + ublindf->otyp == LENSES ? "some lenses" : "a blindfold"); + return (0); + } + otmp = getobj(accessories, "put on"); + if (!otmp) + return (0); + if (otmp->owornmask & (W_RING | W_AMUL | W_TOOL)) { + already_wearing(c_that_); + return (0); + } + if (welded(otmp)) { + weldmsg(otmp); + return (0); + } #if 0 /* defer til Xxx_on(); various failures below now leave item wielded */ @@ -1712,231 +1797,252 @@ doputon() remove_worn_item(otmp, FALSE); #endif - if(otmp->oclass == RING_CLASS || otmp->otyp == MEAT_RING) { - if(nolimbs(youmonst.data)) { - You("cannot make the ring stick to your body."); - return(0); - } - if(uleft && uright){ - There("are no more %s%s to fill.", - humanoid(youmonst.data) ? "ring-" : "", - makeplural(body_part(FINGER))); - return(0); - } - if(uleft) mask = RIGHT_RING; - else if(uright) mask = LEFT_RING; - else do { - char qbuf[QBUFSZ]; - char answer; + if (otmp->oclass == RING_CLASS || otmp->otyp == MEAT_RING) { + if (nolimbs(youmonst.data)) { + You("cannot make the ring stick to your body."); + return (0); + } + if (uleft && uright) { + There("are no more %s%s to fill.", + humanoid(youmonst.data) ? "ring-" : "", + makeplural(body_part(FINGER))); + return (0); + } + if (uleft) + mask = RIGHT_RING; + else if (uright) + mask = LEFT_RING; + else + do { + char qbuf[QBUFSZ]; + char answer; - Sprintf(qbuf, "Which %s%s, Right or Left?", - humanoid(youmonst.data) ? "ring-" : "", - body_part(FINGER)); - if(!(answer = yn_function(qbuf, "rl", '\0'))) - return(0); - switch(answer){ - case 'l': - case 'L': - mask = LEFT_RING; - break; - case 'r': - case 'R': - mask = RIGHT_RING; - break; - } - } while(!mask); - if (uarmg && uarmg->cursed) { - uarmg->bknown = TRUE; - You("cannot remove your gloves to put on the ring."); - return(0); - } - if (welded(uwep) && bimanual(uwep)) { - /* welded will set bknown */ - You("cannot free your weapon hands to put on the ring."); - return(0); - } - if (welded(uwep) && mask==RIGHT_RING) { - /* welded will set bknown */ - You("cannot free your weapon hand to put on the ring."); - return(0); - } - if (!retouch_object(&otmp, FALSE)) - return 1; /* costs a turn even though it didn't get worn */ - setworn(otmp, mask); - Ring_on(otmp); - } else if (otmp->oclass == AMULET_CLASS) { - if(uamul) { - already_wearing("an amulet"); - return(0); - } - if (!retouch_object(&otmp, FALSE)) - return 1; - setworn(otmp, W_AMUL); - Amulet_on(); - /* finished now if an amulet of change got used up */ - if (!uamul) return 1; - } else { /* it's a blindfold, towel, or lenses */ - if (ublindf) { - if (ublindf->otyp == TOWEL) - Your("%s is already covered by a towel.", - body_part(FACE)); - else if (ublindf->otyp == BLINDFOLD) { - if (otmp->otyp == LENSES) - already_wearing2("lenses", "a blindfold"); - else - already_wearing("a blindfold"); - } else if (ublindf->otyp == LENSES) { - if (otmp->otyp == BLINDFOLD) - already_wearing2("a blindfold", "some lenses"); - else - already_wearing("some lenses"); - } else - already_wearing(something); /* ??? */ - return(0); - } - if (otmp->otyp != BLINDFOLD && otmp->otyp != TOWEL && otmp->otyp != LENSES) { - You_cant("wear that!"); - return(0); - } - if (!retouch_object(&otmp, FALSE)) - return 1; - Blindf_on(otmp); - return(1); - } - if (is_worn(otmp)) - prinv((char *)0, otmp, 0L); - return(1); + Sprintf(qbuf, "Which %s%s, Right or Left?", + humanoid(youmonst.data) ? "ring-" : "", + body_part(FINGER)); + if (!(answer = yn_function(qbuf, "rl", '\0'))) + return (0); + switch (answer) { + case 'l': + case 'L': + mask = LEFT_RING; + break; + case 'r': + case 'R': + mask = RIGHT_RING; + break; + } + } while (!mask); + if (uarmg && uarmg->cursed) { + uarmg->bknown = TRUE; + You("cannot remove your gloves to put on the ring."); + return (0); + } + if (welded(uwep) && bimanual(uwep)) { + /* welded will set bknown */ + You("cannot free your weapon hands to put on the ring."); + return (0); + } + if (welded(uwep) && mask == RIGHT_RING) { + /* welded will set bknown */ + You("cannot free your weapon hand to put on the ring."); + return (0); + } + if (!retouch_object(&otmp, FALSE)) + return 1; /* costs a turn even though it didn't get worn */ + setworn(otmp, mask); + Ring_on(otmp); + } else if (otmp->oclass == AMULET_CLASS) { + if (uamul) { + already_wearing("an amulet"); + return (0); + } + if (!retouch_object(&otmp, FALSE)) + return 1; + setworn(otmp, W_AMUL); + Amulet_on(); + /* finished now if an amulet of change got used up */ + if (!uamul) + return 1; + } else { /* it's a blindfold, towel, or lenses */ + if (ublindf) { + if (ublindf->otyp == TOWEL) + Your("%s is already covered by a towel.", body_part(FACE)); + else if (ublindf->otyp == BLINDFOLD) { + if (otmp->otyp == LENSES) + already_wearing2("lenses", "a blindfold"); + else + already_wearing("a blindfold"); + } else if (ublindf->otyp == LENSES) { + if (otmp->otyp == BLINDFOLD) + already_wearing2("a blindfold", "some lenses"); + else + already_wearing("some lenses"); + } else + already_wearing(something); /* ??? */ + return (0); + } + if (otmp->otyp != BLINDFOLD && otmp->otyp != TOWEL + && otmp->otyp != LENSES) { + You_cant("wear that!"); + return (0); + } + if (!retouch_object(&otmp, FALSE)) + return 1; + Blindf_on(otmp); + return (1); + } + if (is_worn(otmp)) + prinv((char *) 0, otmp, 0L); + return (1); } void find_ac() { - int uac = mons[u.umonnum].ac; + int uac = mons[u.umonnum].ac; - if(uarm) uac -= ARM_BONUS(uarm); - if(uarmc) uac -= ARM_BONUS(uarmc); - if(uarmh) uac -= ARM_BONUS(uarmh); - if(uarmf) uac -= ARM_BONUS(uarmf); - if(uarms) uac -= ARM_BONUS(uarms); - if(uarmg) uac -= ARM_BONUS(uarmg); - if(uarmu) uac -= ARM_BONUS(uarmu); - if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe; - if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe; - if (HProtection & INTRINSIC) uac -= u.ublessed; - uac -= u.uspellprot; - if (uac < -128) uac = -128; /* u.uac is an schar */ - if(uac != u.uac){ - u.uac = uac; - context.botl = 1; - } + if (uarm) + uac -= ARM_BONUS(uarm); + if (uarmc) + uac -= ARM_BONUS(uarmc); + if (uarmh) + uac -= ARM_BONUS(uarmh); + if (uarmf) + uac -= ARM_BONUS(uarmf); + if (uarms) + uac -= ARM_BONUS(uarms); + if (uarmg) + uac -= ARM_BONUS(uarmg); + if (uarmu) + uac -= ARM_BONUS(uarmu); + if (uleft && uleft->otyp == RIN_PROTECTION) + uac -= uleft->spe; + if (uright && uright->otyp == RIN_PROTECTION) + uac -= uright->spe; + if (HProtection & INTRINSIC) + uac -= u.ublessed; + uac -= u.uspellprot; + if (uac < -128) + uac = -128; /* u.uac is an schar */ + if (uac != u.uac) { + u.uac = uac; + context.botl = 1; + } } void glibr() { - register struct obj *otmp; - int xfl = 0; - boolean leftfall, rightfall, wastwoweap = FALSE; - const char *otherwep = 0, *thiswep, *which, *hand; + register struct obj *otmp; + int xfl = 0; + boolean leftfall, rightfall, wastwoweap = FALSE; + const char *otherwep = 0, *thiswep, *which, *hand; - leftfall = (uleft && !uleft->cursed && - (!uwep || !welded(uwep) || !bimanual(uwep))); - rightfall = (uright && !uright->cursed && (!welded(uwep))); - if (!uarmg && (leftfall || rightfall) && !nolimbs(youmonst.data)) { - /* changed so cursed rings don't fall off, GAN 10/30/86 */ - Your("%s off your %s.", - (leftfall && rightfall) ? "rings slip" : "ring slips", - (leftfall && rightfall) ? makeplural(body_part(FINGER)) : - body_part(FINGER)); - xfl++; - if (leftfall) { - otmp = uleft; - Ring_off(uleft); - dropx(otmp); - } - if (rightfall) { - otmp = uright; - Ring_off(uright); - dropx(otmp); - } - } + leftfall = (uleft && !uleft->cursed + && (!uwep || !welded(uwep) || !bimanual(uwep))); + rightfall = (uright && !uright->cursed && (!welded(uwep))); + if (!uarmg && (leftfall || rightfall) && !nolimbs(youmonst.data)) { + /* changed so cursed rings don't fall off, GAN 10/30/86 */ + Your("%s off your %s.", + (leftfall && rightfall) ? "rings slip" : "ring slips", + (leftfall && rightfall) ? makeplural(body_part(FINGER)) + : body_part(FINGER)); + xfl++; + if (leftfall) { + otmp = uleft; + Ring_off(uleft); + dropx(otmp); + } + if (rightfall) { + otmp = uright; + Ring_off(uright); + dropx(otmp); + } + } - otmp = uswapwep; - if (u.twoweap && otmp) { - /* secondary weapon doesn't need nearly as much handling as - primary; when in two-weapon mode, we know it's one-handed - with something else in the other hand and also that it's - a weapon or weptool rather than something unusual, plus - we don't need to compare its type with the primary */ - otherwep = is_sword(otmp) ? c_sword : weapon_descr(otmp); - if (otmp->quan > 1L) otherwep = makeplural(otherwep); - hand = body_part(HAND); - which = "left "; - Your("%s %s%s from your %s%s.", - otherwep, xfl ? "also " : "", - otense(otmp, "slip"), which, hand); - xfl++; - wastwoweap = TRUE; - setuswapwep((struct obj *)0); /* clears u.twoweap */ - if (canletgo(otmp, "")) - dropx(otmp); - } - otmp = uwep; - if (otmp && !welded(otmp)) { - long savequan = otmp->quan; + otmp = uswapwep; + if (u.twoweap && otmp) { + /* secondary weapon doesn't need nearly as much handling as + primary; when in two-weapon mode, we know it's one-handed + with something else in the other hand and also that it's + a weapon or weptool rather than something unusual, plus + we don't need to compare its type with the primary */ + otherwep = is_sword(otmp) ? c_sword : weapon_descr(otmp); + if (otmp->quan > 1L) + otherwep = makeplural(otherwep); + hand = body_part(HAND); + which = "left "; + Your("%s %s%s from your %s%s.", otherwep, xfl ? "also " : "", + otense(otmp, "slip"), which, hand); + xfl++; + wastwoweap = TRUE; + setuswapwep((struct obj *) 0); /* clears u.twoweap */ + if (canletgo(otmp, "")) + dropx(otmp); + } + otmp = uwep; + if (otmp && !welded(otmp)) { + long savequan = otmp->quan; - /* nice wording if both weapons are the same type */ - thiswep = is_sword(otmp) ? c_sword : weapon_descr(otmp); - if (otherwep && strcmp(thiswep, makesingular(otherwep))) - otherwep = 0; - if (otmp->quan > 1L) { - /* most class names for unconventional wielded items - are ok, but if wielding multiple apples or rations - we don't want "your foods slip", so force non-corpse - food to be singular; skipping makeplural() isn't - enough--we need to fool otense() too */ - if (!strcmp(thiswep, "food")) otmp->quan = 1L; - else thiswep = makeplural(thiswep); - } - hand = body_part(HAND); - which = ""; - if (bimanual(otmp)) - hand = makeplural(hand); - else if (wastwoweap) - which = "right "; /* preceding msg was about left */ - pline("%s %s%s %s%s from your %s%s.", - !strncmp(thiswep, "corpse", 6) ? "The" : "Your", - otherwep ? "other " : "", thiswep, xfl ? "also " : "", - otense(otmp, "slip"), which, hand); - /* xfl++; */ - otmp->quan = savequan; - setuwep((struct obj *)0); - if (canletgo(otmp, "")) - dropx(otmp); - } + /* nice wording if both weapons are the same type */ + thiswep = is_sword(otmp) ? c_sword : weapon_descr(otmp); + if (otherwep && strcmp(thiswep, makesingular(otherwep))) + otherwep = 0; + if (otmp->quan > 1L) { + /* most class names for unconventional wielded items + are ok, but if wielding multiple apples or rations + we don't want "your foods slip", so force non-corpse + food to be singular; skipping makeplural() isn't + enough--we need to fool otense() too */ + if (!strcmp(thiswep, "food")) + otmp->quan = 1L; + else + thiswep = makeplural(thiswep); + } + hand = body_part(HAND); + which = ""; + if (bimanual(otmp)) + hand = makeplural(hand); + else if (wastwoweap) + which = "right "; /* preceding msg was about left */ + pline("%s %s%s %s%s from your %s%s.", + !strncmp(thiswep, "corpse", 6) ? "The" : "Your", + otherwep ? "other " : "", thiswep, xfl ? "also " : "", + otense(otmp, "slip"), which, hand); + /* xfl++; */ + otmp->quan = savequan; + setuwep((struct obj *) 0); + if (canletgo(otmp, "")) + dropx(otmp); + } } struct obj * some_armor(victim) struct monst *victim; { - register struct obj *otmph, *otmp; + register struct obj *otmph, *otmp; - otmph = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC); - if (!otmph) - otmph = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM); - if (!otmph) - otmph = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU); - - otmp = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH); - if(otmp && (!otmph || !rn2(4))) otmph = otmp; - otmp = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG); - if(otmp && (!otmph || !rn2(4))) otmph = otmp; - otmp = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF); - if(otmp && (!otmph || !rn2(4))) otmph = otmp; - otmp = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS); - if(otmp && (!otmph || !rn2(4))) otmph = otmp; - return(otmph); + otmph = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC); + if (!otmph) + otmph = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM); + if (!otmph) + otmph = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU); + + otmp = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH); + if (otmp && (!otmph || !rn2(4))) + otmph = otmp; + otmp = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG); + if (otmp && (!otmph || !rn2(4))) + otmph = otmp; + otmp = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF); + if (otmp && (!otmph || !rn2(4))) + otmph = otmp; + otmp = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS); + if (otmp && (!otmph || !rn2(4))) + otmph = otmp; + return (otmph); } /* used for praying to check and fix levitation trouble */ @@ -1946,29 +2052,33 @@ struct obj *ring; int otyp; { if (ring != uleft && ring != uright) { - impossible("stuck_ring: neither left nor right?"); - return (struct obj *)0; + impossible("stuck_ring: neither left nor right?"); + return (struct obj *) 0; } if (ring && ring->otyp == otyp) { - /* reasons ring can't be removed match those checked by select_off(); - limbless case has extra checks because ordinarily it's temporary */ - if (nolimbs(youmonst.data) && - uamul && uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed) - return uamul; - if (welded(uwep) && (ring == uright || bimanual(uwep))) return uwep; - if (uarmg && uarmg->cursed) return uarmg; - if (ring->cursed) return ring; + /* reasons ring can't be removed match those checked by select_off(); + limbless case has extra checks because ordinarily it's temporary */ + if (nolimbs(youmonst.data) && uamul + && uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed) + return uamul; + if (welded(uwep) && (ring == uright || bimanual(uwep))) + return uwep; + if (uarmg && uarmg->cursed) + return uarmg; + if (ring->cursed) + return ring; } /* either no ring or not right type or nothing prevents its removal */ - return (struct obj *)0; + return (struct obj *) 0; } /* also for praying; find worn item that confers "Unchanging" attribute */ struct obj * unchanger() { - if (uamul && uamul->otyp == AMULET_OF_UNCHANGING) return uamul; + if (uamul && uamul->otyp == AMULET_OF_UNCHANGING) + return uamul; return 0; } @@ -1977,162 +2087,191 @@ int select_off(otmp) register struct obj *otmp; { - struct obj *why; - char buf[BUFSZ]; + struct obj *why; + char buf[BUFSZ]; - if (!otmp) return 0; - *buf = '\0'; /* lint suppresion */ + if (!otmp) + return 0; + *buf = '\0'; /* lint suppresion */ - /* special ring checks */ - if (otmp == uright || otmp == uleft) { - if (nolimbs(youmonst.data)) { - pline_The("ring is stuck."); - return 0; - } - why = 0; /* the item which prevents ring removal */ - if (welded(uwep) && (otmp == uright || bimanual(uwep))) { - Sprintf(buf, "free a weapon %s", body_part(HAND)); - why = uwep; - } else if (uarmg && uarmg->cursed) { - Sprintf(buf, "take off your %s", c_gloves); - why = uarmg; - } - if (why) { - You("cannot %s to remove the ring.", buf); - why->bknown = TRUE; - return 0; - } - } - /* special glove checks */ - if (otmp == uarmg) { - if (welded(uwep)) { - You("are unable to take off your %s while wielding that %s.", - c_gloves, is_sword(uwep) ? c_sword : c_weapon); - uwep->bknown = TRUE; - return 0; - } else if (Glib) { - You_cant("take off the slippery %s with your slippery %s.", - c_gloves, makeplural(body_part(FINGER))); - return 0; - } - } - /* special boot checks */ - if (otmp == uarmf) { - if (u.utrap && u.utraptype == TT_BEARTRAP) { - pline_The("bear trap prevents you from pulling your %s out.", - body_part(FOOT)); - return 0; - } else if (u.utrap && u.utraptype == TT_INFLOOR) { - You("are stuck in the %s, and cannot pull your %s out.", - surface(u.ux, u.uy), makeplural(body_part(FOOT))); - return 0; - } - } - /* special suit and shirt checks */ - if (otmp == uarm || otmp == uarmu) { - why = 0; /* the item which prevents disrobing */ - if (uarmc && uarmc->cursed) { - Sprintf(buf, "remove your %s", cloak_simple_name(uarmc)); - why = uarmc; - } else if (otmp == uarmu && uarm && uarm->cursed) { - Sprintf(buf, "remove your %s", c_suit); - why = uarm; - } else if (welded(uwep) && bimanual(uwep)) { - Sprintf(buf, "release your %s", - is_sword(uwep) ? c_sword : - (uwep->otyp == BATTLE_AXE) ? c_axe : c_weapon); - why = uwep; - } - if (why) { - You("cannot %s to take off %s.", buf, the(xname(otmp))); - why->bknown = TRUE; - return 0; - } - } - /* basic curse check */ - if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) { - ; /* some items can be removed even when cursed */ - } else { - /* otherwise, this is fundamental */ - if (cursed(otmp)) return 0; - } + /* special ring checks */ + if (otmp == uright || otmp == uleft) { + if (nolimbs(youmonst.data)) { + pline_The("ring is stuck."); + return 0; + } + why = 0; /* the item which prevents ring removal */ + if (welded(uwep) && (otmp == uright || bimanual(uwep))) { + Sprintf(buf, "free a weapon %s", body_part(HAND)); + why = uwep; + } else if (uarmg && uarmg->cursed) { + Sprintf(buf, "take off your %s", c_gloves); + why = uarmg; + } + if (why) { + You("cannot %s to remove the ring.", buf); + why->bknown = TRUE; + return 0; + } + } + /* special glove checks */ + if (otmp == uarmg) { + if (welded(uwep)) { + You("are unable to take off your %s while wielding that %s.", + c_gloves, is_sword(uwep) ? c_sword : c_weapon); + uwep->bknown = TRUE; + return 0; + } else if (Glib) { + You_cant("take off the slippery %s with your slippery %s.", + c_gloves, makeplural(body_part(FINGER))); + return 0; + } + } + /* special boot checks */ + if (otmp == uarmf) { + if (u.utrap && u.utraptype == TT_BEARTRAP) { + pline_The("bear trap prevents you from pulling your %s out.", + body_part(FOOT)); + return 0; + } else if (u.utrap && u.utraptype == TT_INFLOOR) { + You("are stuck in the %s, and cannot pull your %s out.", + surface(u.ux, u.uy), makeplural(body_part(FOOT))); + return 0; + } + } + /* special suit and shirt checks */ + if (otmp == uarm || otmp == uarmu) { + why = 0; /* the item which prevents disrobing */ + if (uarmc && uarmc->cursed) { + Sprintf(buf, "remove your %s", cloak_simple_name(uarmc)); + why = uarmc; + } else if (otmp == uarmu && uarm && uarm->cursed) { + Sprintf(buf, "remove your %s", c_suit); + why = uarm; + } else if (welded(uwep) && bimanual(uwep)) { + Sprintf(buf, "release your %s", + is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE) + ? c_axe + : c_weapon); + why = uwep; + } + if (why) { + You("cannot %s to take off %s.", buf, the(xname(otmp))); + why->bknown = TRUE; + return 0; + } + } + /* basic curse check */ + if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) { + ; /* some items can be removed even when cursed */ + } else { + /* otherwise, this is fundamental */ + if (cursed(otmp)) + return 0; + } - if(otmp == uarm) context.takeoff.mask |= WORN_ARMOR; - else if(otmp == uarmc) context.takeoff.mask |= WORN_CLOAK; - else if(otmp == uarmf) context.takeoff.mask |= WORN_BOOTS; - else if(otmp == uarmg) context.takeoff.mask |= WORN_GLOVES; - else if(otmp == uarmh) context.takeoff.mask |= WORN_HELMET; - else if(otmp == uarms) context.takeoff.mask |= WORN_SHIELD; - else if(otmp == uarmu) context.takeoff.mask |= WORN_SHIRT; - else if(otmp == uleft) context.takeoff.mask |= LEFT_RING; - else if(otmp == uright) context.takeoff.mask |= RIGHT_RING; - else if(otmp == uamul) context.takeoff.mask |= WORN_AMUL; - else if(otmp == ublindf) context.takeoff.mask |= WORN_BLINDF; - else if(otmp == uwep) context.takeoff.mask |= W_WEP; - else if(otmp == uswapwep) context.takeoff.mask |= W_SWAPWEP; - else if(otmp == uquiver) context.takeoff.mask |= W_QUIVER; + if (otmp == uarm) + context.takeoff.mask |= WORN_ARMOR; + else if (otmp == uarmc) + context.takeoff.mask |= WORN_CLOAK; + else if (otmp == uarmf) + context.takeoff.mask |= WORN_BOOTS; + else if (otmp == uarmg) + context.takeoff.mask |= WORN_GLOVES; + else if (otmp == uarmh) + context.takeoff.mask |= WORN_HELMET; + else if (otmp == uarms) + context.takeoff.mask |= WORN_SHIELD; + else if (otmp == uarmu) + context.takeoff.mask |= WORN_SHIRT; + else if (otmp == uleft) + context.takeoff.mask |= LEFT_RING; + else if (otmp == uright) + context.takeoff.mask |= RIGHT_RING; + else if (otmp == uamul) + context.takeoff.mask |= WORN_AMUL; + else if (otmp == ublindf) + context.takeoff.mask |= WORN_BLINDF; + else if (otmp == uwep) + context.takeoff.mask |= W_WEP; + else if (otmp == uswapwep) + context.takeoff.mask |= W_SWAPWEP; + else if (otmp == uquiver) + context.takeoff.mask |= W_QUIVER; - else impossible("select_off: %s???", doname(otmp)); + else + impossible("select_off: %s???", doname(otmp)); - return(0); + return (0); } STATIC_OVL struct obj * do_takeoff() { - struct obj *otmp = (struct obj *)0; + struct obj *otmp = (struct obj *) 0; struct takeoff_info *doff = &context.takeoff; if (doff->what == W_WEP) { - if (!cursed(uwep)) { - setuwep((struct obj *) 0); - You("are empty %s.", body_part(HANDED)); - u.twoweap = FALSE; - } + if (!cursed(uwep)) { + setuwep((struct obj *) 0); + You("are empty %s.", body_part(HANDED)); + u.twoweap = FALSE; + } } else if (doff->what == W_SWAPWEP) { - setuswapwep((struct obj *) 0); - You("no longer have a second weapon readied."); - u.twoweap = FALSE; + setuswapwep((struct obj *) 0); + You("no longer have a second weapon readied."); + u.twoweap = FALSE; } else if (doff->what == W_QUIVER) { - setuqwep((struct obj *) 0); - You("no longer have ammunition readied."); + setuqwep((struct obj *) 0); + You("no longer have ammunition readied."); } else if (doff->what == WORN_ARMOR) { - otmp = uarm; - if (!cursed(otmp)) (void) Armor_off(); + otmp = uarm; + if (!cursed(otmp)) + (void) Armor_off(); } else if (doff->what == WORN_CLOAK) { - otmp = uarmc; - if (!cursed(otmp)) (void) Cloak_off(); + otmp = uarmc; + if (!cursed(otmp)) + (void) Cloak_off(); } else if (doff->what == WORN_BOOTS) { - otmp = uarmf; - if (!cursed(otmp)) (void) Boots_off(); + otmp = uarmf; + if (!cursed(otmp)) + (void) Boots_off(); } else if (doff->what == WORN_GLOVES) { - otmp = uarmg; - if (!cursed(otmp)) (void) Gloves_off(); + otmp = uarmg; + if (!cursed(otmp)) + (void) Gloves_off(); } else if (doff->what == WORN_HELMET) { - otmp = uarmh; - if (!cursed(otmp)) (void) Helmet_off(); + otmp = uarmh; + if (!cursed(otmp)) + (void) Helmet_off(); } else if (doff->what == WORN_SHIELD) { - otmp = uarms; - if (!cursed(otmp)) (void) Shield_off(); + otmp = uarms; + if (!cursed(otmp)) + (void) Shield_off(); } else if (doff->what == WORN_SHIRT) { - otmp = uarmu; - if (!cursed(otmp)) (void) Shirt_off(); + otmp = uarmu; + if (!cursed(otmp)) + (void) Shirt_off(); } else if (doff->what == WORN_AMUL) { - otmp = uamul; - if (!cursed(otmp)) Amulet_off(); + otmp = uamul; + if (!cursed(otmp)) + Amulet_off(); } else if (doff->what == LEFT_RING) { - otmp = uleft; - if (!cursed(otmp)) Ring_off(uleft); + otmp = uleft; + if (!cursed(otmp)) + Ring_off(uleft); } else if (doff->what == RIGHT_RING) { - otmp = uright; - if (!cursed(otmp)) Ring_off(uright); + otmp = uright; + if (!cursed(otmp)) + Ring_off(uright); } else if (doff->what == WORN_BLINDF) { - if (!cursed(ublindf)) Blindf_off(ublindf); + if (!cursed(ublindf)) + Blindf_off(ublindf); } else { - impossible("do_takeoff: taking off %lx", doff->what); + impossible("do_takeoff: taking off %lx", doff->what); } - return(otmp); + return (otmp); } /* occupation callback for 'A' */ @@ -2140,92 +2279,98 @@ STATIC_PTR int take_off(VOID_ARGS) { - register int i; - register struct obj *otmp; - struct takeoff_info *doff = &context.takeoff; + register int i; + register struct obj *otmp; + struct takeoff_info *doff = &context.takeoff; - if (doff->what) { - if (doff->delay > 0) { - doff->delay--; - return(1); /* still busy */ - } else { - if ((otmp = do_takeoff())) off_msg(otmp); - } - doff->mask &= ~doff->what; - doff->what = 0L; - } + if (doff->what) { + if (doff->delay > 0) { + doff->delay--; + return (1); /* still busy */ + } else { + if ((otmp = do_takeoff())) + off_msg(otmp); + } + doff->mask &= ~doff->what; + doff->what = 0L; + } - for(i = 0; takeoff_order[i]; i++) - if(doff->mask & takeoff_order[i]) { - doff->what = takeoff_order[i]; - break; - } + for (i = 0; takeoff_order[i]; i++) + if (doff->mask & takeoff_order[i]) { + doff->what = takeoff_order[i]; + break; + } - otmp = (struct obj *) 0; - doff->delay = 0; + otmp = (struct obj *) 0; + doff->delay = 0; - if (doff->what == 0L) { - You("finish %s.", doff->disrobing); - return 0; - } else if (doff->what == W_WEP) { - doff->delay = 1; - } else if (doff->what == W_SWAPWEP) { - doff->delay = 1; - } else if (doff->what == W_QUIVER) { - doff->delay = 1; - } else if (doff->what == WORN_ARMOR) { - otmp = uarm; - /* If a cloak is being worn, add the time to take it off and put - * it back on again. Kludge alert! since that time is 0 for all - * known cloaks, add 1 so that it actually matters... - */ - if (uarmc) doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; - } else if (doff->what == WORN_CLOAK) { - otmp = uarmc; - } else if (doff->what == WORN_BOOTS) { - otmp = uarmf; - } else if (doff->what == WORN_GLOVES) { - otmp = uarmg; - } else if (doff->what == WORN_HELMET) { - otmp = uarmh; - } else if (doff->what == WORN_SHIELD) { - otmp = uarms; - } else if (doff->what == WORN_SHIRT) { - otmp = uarmu; - /* add the time to take off and put back on armor and/or cloak */ - if (uarm) doff->delay += 2 * objects[uarm->otyp].oc_delay; - if (uarmc) doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; - } else if (doff->what == WORN_AMUL) { - doff->delay = 1; - } else if (doff->what == LEFT_RING) { - doff->delay = 1; - } else if (doff->what == RIGHT_RING) { - doff->delay = 1; - } else if (doff->what == WORN_BLINDF) { - doff->delay = 2; - } else { - impossible("take_off: taking off %lx", doff->what); - return 0; /* force done */ - } + if (doff->what == 0L) { + You("finish %s.", doff->disrobing); + return 0; + } else if (doff->what == W_WEP) { + doff->delay = 1; + } else if (doff->what == W_SWAPWEP) { + doff->delay = 1; + } else if (doff->what == W_QUIVER) { + doff->delay = 1; + } else if (doff->what == WORN_ARMOR) { + otmp = uarm; + /* If a cloak is being worn, add the time to take it off and put + * it back on again. Kludge alert! since that time is 0 for all + * known cloaks, add 1 so that it actually matters... + */ + if (uarmc) + doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; + } else if (doff->what == WORN_CLOAK) { + otmp = uarmc; + } else if (doff->what == WORN_BOOTS) { + otmp = uarmf; + } else if (doff->what == WORN_GLOVES) { + otmp = uarmg; + } else if (doff->what == WORN_HELMET) { + otmp = uarmh; + } else if (doff->what == WORN_SHIELD) { + otmp = uarms; + } else if (doff->what == WORN_SHIRT) { + otmp = uarmu; + /* add the time to take off and put back on armor and/or cloak */ + if (uarm) + doff->delay += 2 * objects[uarm->otyp].oc_delay; + if (uarmc) + doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; + } else if (doff->what == WORN_AMUL) { + doff->delay = 1; + } else if (doff->what == LEFT_RING) { + doff->delay = 1; + } else if (doff->what == RIGHT_RING) { + doff->delay = 1; + } else if (doff->what == WORN_BLINDF) { + doff->delay = 2; + } else { + impossible("take_off: taking off %lx", doff->what); + return 0; /* force done */ + } - if (otmp) doff->delay += objects[otmp->otyp].oc_delay; + if (otmp) + doff->delay += objects[otmp->otyp].oc_delay; - /* Since setting the occupation now starts the counter next move, that - * would always produce a delay 1 too big per item unless we subtract - * 1 here to account for it. - */ - if (doff->delay > 0) doff->delay--; + /* Since setting the occupation now starts the counter next move, that + * would always produce a delay 1 too big per item unless we subtract + * 1 here to account for it. + */ + if (doff->delay > 0) + doff->delay--; - set_occupation(take_off, doff->disrobing, 0); - return(1); /* get busy */ + set_occupation(take_off, doff->disrobing, 0); + return (1); /* get busy */ } /* clear saved context to avoid inappropriate resumption of interrupted 'A' */ void reset_remarm() { - context.takeoff.what = context.takeoff.mask = 0L; - context.takeoff.disrobing[0] = '\0'; + context.takeoff.what = context.takeoff.mask = 0L; + context.takeoff.disrobing[0] = '\0'; } /* the 'A' command -- remove multiple worn items */ @@ -2235,28 +2380,30 @@ doddoremarm() int result = 0; if (context.takeoff.what || context.takeoff.mask) { - You("continue %s.", context.takeoff.disrobing); - set_occupation(take_off, context.takeoff.disrobing, 0); - return 0; - } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf && - !uleft && !uright && !wearing_armor()) { - You("are not wearing anything."); - return 0; + You("continue %s.", context.takeoff.disrobing); + set_occupation(take_off, context.takeoff.disrobing, 0); + return 0; + } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf && !uleft + && !uright && !wearing_armor()) { + You("are not wearing anything."); + return 0; } add_valid_menu_class(0); /* reset */ - if (flags.menu_style != MENU_TRADITIONAL || - (result = ggetobj("take off", select_off, 0, FALSE, (unsigned *)0)) < -1) - result = menu_remarm(result); + if (flags.menu_style != MENU_TRADITIONAL + || (result = ggetobj("take off", select_off, 0, FALSE, + (unsigned *) 0)) < -1) + result = menu_remarm(result); if (context.takeoff.mask) { - /* default activity for armor and/or accessories, - possibly combined with weapons */ - (void)strncpy(context.takeoff.disrobing, "disrobing", CONTEXTVERBSZ); - /* specific activity when handling weapons only */ - if (!(context.takeoff.mask & ~(W_WEP|W_SWAPWEP|W_QUIVER))) - (void)strncpy(context.takeoff.disrobing, "disarming", CONTEXTVERBSZ); - (void) take_off(); + /* default activity for armor and/or accessories, + possibly combined with weapons */ + (void) strncpy(context.takeoff.disrobing, "disrobing", CONTEXTVERBSZ); + /* specific activity when handling weapons only */ + if (!(context.takeoff.mask & ~(W_WEP | W_SWAPWEP | W_QUIVER))) + (void) strncpy(context.takeoff.disrobing, "disarming", + CONTEXTVERBSZ); + (void) take_off(); } /* The time to perform the command is already completely accounted for * in take_off(); if we return 1, that would add an extra turn to each @@ -2274,35 +2421,37 @@ int retry; boolean all_worn_categories = TRUE; if (retry) { - all_worn_categories = (retry == -2); + all_worn_categories = (retry == -2); } else if (flags.menu_style == MENU_FULL) { - all_worn_categories = FALSE; - n = query_category("What type of things do you want to take off?", - invent, WORN_TYPES|ALL_TYPES, &pick_list, PICK_ANY); - if (!n) return 0; - for (i = 0; i < n; i++) { - if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) - all_worn_categories = TRUE; - else - add_valid_menu_class(pick_list[i].item.a_int); - } - free((genericptr_t) pick_list); + all_worn_categories = FALSE; + n = query_category("What type of things do you want to take off?", + invent, WORN_TYPES | ALL_TYPES, &pick_list, + PICK_ANY); + if (!n) + return 0; + for (i = 0; i < n; i++) { + if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) + all_worn_categories = TRUE; + else + add_valid_menu_class(pick_list[i].item.a_int); + } + free((genericptr_t) pick_list); } else if (flags.menu_style == MENU_COMBINATION) { - all_worn_categories = FALSE; - if (ggetobj("take off", select_off, 0, TRUE, (unsigned *)0) == -2) - all_worn_categories = TRUE; + all_worn_categories = FALSE; + if (ggetobj("take off", select_off, 0, TRUE, (unsigned *) 0) == -2) + all_worn_categories = TRUE; } n = query_objlist("What do you want to take off?", invent, - SIGNAL_NOMENU|USE_INVLET|INVORDER_SORT, - &pick_list, PICK_ANY, - all_worn_categories ? is_worn : is_worn_by_type); + SIGNAL_NOMENU | USE_INVLET | INVORDER_SORT, &pick_list, + PICK_ANY, + all_worn_categories ? is_worn : is_worn_by_type); if (n > 0) { - for (i = 0; i < n; i++) - (void) select_off(pick_list[i].item.a_obj); - free((genericptr_t) pick_list); + for (i = 0; i < n; i++) + (void) select_off(pick_list[i].item.a_obj); + free((genericptr_t) pick_list); } else if (n < 0 && flags.menu_style != MENU_COMBINATION) { - There("is nothing else you can remove or unwield."); + There("is nothing else you can remove or unwield."); } return 0; } @@ -2312,58 +2461,63 @@ int destroy_arm(atmp) register struct obj *atmp; { - register struct obj *otmp; -#define DESTROY_ARM(o) ((otmp = (o)) != 0 && \ - (!atmp || atmp == otmp) && \ - (!obj_resists(otmp, 0, 90)) ? \ - (otmp->in_use = TRUE) : FALSE) + register struct obj *otmp; +#define DESTROY_ARM(o) \ + ((otmp = (o)) != 0 && (!atmp || atmp == otmp) \ + && (!obj_resists(otmp, 0, 90)) \ + ? (otmp->in_use = TRUE) \ + : FALSE) - if (DESTROY_ARM(uarmc)) { - if (donning(otmp)) cancel_don(); - Your("%s crumbles and turns to dust!", - cloak_simple_name(uarmc)); - (void) Cloak_off(); - useup(otmp); - } else if (DESTROY_ARM(uarm)) { - if (donning(otmp)) cancel_don(); - Your("armor turns to dust and falls to the %s!", - surface(u.ux,u.uy)); - (void) Armor_gone(); - useup(otmp); - } else if (DESTROY_ARM(uarmu)) { - if (donning(otmp)) cancel_don(); - Your("shirt crumbles into tiny threads and falls apart!"); - (void) Shirt_off(); - useup(otmp); - } else if (DESTROY_ARM(uarmh)) { - if (donning(otmp)) cancel_don(); - Your("%s turns to dust and is blown away!", - helm_simple_name(uarmh)); - (void) Helmet_off(); - useup(otmp); - } else if (DESTROY_ARM(uarmg)) { - if (donning(otmp)) cancel_don(); - Your("gloves vanish!"); - (void) Gloves_off(); - useup(otmp); - selftouch("You"); - } else if (DESTROY_ARM(uarmf)) { - if (donning(otmp)) cancel_don(); - Your("boots disintegrate!"); - (void) Boots_off(); - useup(otmp); - } else if (DESTROY_ARM(uarms)) { - if (donning(otmp)) cancel_don(); - Your("shield crumbles away!"); - (void) Shield_off(); - useup(otmp); - } else { - return 0; /* could not destroy anything */ - } + if (DESTROY_ARM(uarmc)) { + if (donning(otmp)) + cancel_don(); + Your("%s crumbles and turns to dust!", cloak_simple_name(uarmc)); + (void) Cloak_off(); + useup(otmp); + } else if (DESTROY_ARM(uarm)) { + if (donning(otmp)) + cancel_don(); + Your("armor turns to dust and falls to the %s!", surface(u.ux, u.uy)); + (void) Armor_gone(); + useup(otmp); + } else if (DESTROY_ARM(uarmu)) { + if (donning(otmp)) + cancel_don(); + Your("shirt crumbles into tiny threads and falls apart!"); + (void) Shirt_off(); + useup(otmp); + } else if (DESTROY_ARM(uarmh)) { + if (donning(otmp)) + cancel_don(); + Your("%s turns to dust and is blown away!", helm_simple_name(uarmh)); + (void) Helmet_off(); + useup(otmp); + } else if (DESTROY_ARM(uarmg)) { + if (donning(otmp)) + cancel_don(); + Your("gloves vanish!"); + (void) Gloves_off(); + useup(otmp); + selftouch("You"); + } else if (DESTROY_ARM(uarmf)) { + if (donning(otmp)) + cancel_don(); + Your("boots disintegrate!"); + (void) Boots_off(); + useup(otmp); + } else if (DESTROY_ARM(uarms)) { + if (donning(otmp)) + cancel_don(); + Your("shield crumbles away!"); + (void) Shield_off(); + useup(otmp); + } else { + return 0; /* could not destroy anything */ + } #undef DESTROY_ARM - stop_occupation(); - return(1); + stop_occupation(); + return (1); } void @@ -2371,21 +2525,21 @@ adj_abon(otmp, delta) register struct obj *otmp; register schar delta; { - if (uarmg && uarmg == otmp && otmp->otyp == GAUNTLETS_OF_DEXTERITY) { - if (delta) { - makeknown(uarmg->otyp); - ABON(A_DEX) += (delta); - } - context.botl = 1; - } - if (uarmh && uarmh == otmp && otmp->otyp == HELM_OF_BRILLIANCE) { - if (delta) { - makeknown(uarmh->otyp); - ABON(A_INT) += (delta); - ABON(A_WIS) += (delta); - } - context.botl = 1; - } + if (uarmg && uarmg == otmp && otmp->otyp == GAUNTLETS_OF_DEXTERITY) { + if (delta) { + makeknown(uarmg->otyp); + ABON(A_DEX) += (delta); + } + context.botl = 1; + } + if (uarmh && uarmh == otmp && otmp->otyp == HELM_OF_BRILLIANCE) { + if (delta) { + makeknown(uarmh->otyp); + ABON(A_INT) += (delta); + ABON(A_WIS) += (delta); + } + context.botl = 1; + } } /* decide whether a worn item is covered up by some other worn item, @@ -2394,52 +2548,56 @@ register schar delta; boolean inaccessible_equipment(obj, verb, only_if_known_cursed) struct obj *obj; -const char *verb; /* "dip" or "grease", or null to avoid messages */ -boolean only_if_known_cursed; /* ignore covering unless known to be cursed */ +const char *verb; /* "dip" or "grease", or null to avoid messages */ +boolean only_if_known_cursed; /* ignore covering unless known to be cursed */ { static NEARDATA const char need_to_take_off_outer_armor[] = - "need to take off %s to %s %s."; + "need to take off %s to %s %s."; char buf[BUFSZ]; boolean anycovering = !only_if_known_cursed; /* more comprehensible... */ -#define BLOCKSACCESS(x) (anycovering || ((x)->cursed && (x)->bknown)) +#define BLOCKSACCESS(x) (anycovering || ((x)->cursed && (x)->bknown)) - if (!obj || !obj->owornmask) return FALSE; /* not inaccessible */ + if (!obj || !obj->owornmask) + return FALSE; /* not inaccessible */ /* check for suit covered by cloak */ if (obj == uarm && uarmc && BLOCKSACCESS(uarmc)) { - if (verb) { - Strcpy(buf, yname(uarmc)); - You(need_to_take_off_outer_armor, buf, verb, yname(obj)); - } - return TRUE; + if (verb) { + Strcpy(buf, yname(uarmc)); + You(need_to_take_off_outer_armor, buf, verb, yname(obj)); + } + return TRUE; } /* check for shirt covered by suit and/or cloak */ - if (obj == uarmu && ((uarm && BLOCKSACCESS(uarm)) || - (uarmc && BLOCKSACCESS(uarmc)))) { - if (verb) { - char cloaktmp[QBUFSZ], suittmp[QBUFSZ]; - /* if sameprefix, use yname and xname to get "your cloak and suit" - or "Manlobbi's cloak and suit"; otherwise, use yname and yname - to get "your cloak and Manlobbi's suit" or vice versa */ - boolean sameprefix = (uarm && uarmc && - !strcmp(shk_your(cloaktmp, uarmc), - shk_your(suittmp, uarm))); + if (obj == uarmu + && ((uarm && BLOCKSACCESS(uarm)) || (uarmc && BLOCKSACCESS(uarmc)))) { + if (verb) { + char cloaktmp[QBUFSZ], suittmp[QBUFSZ]; + /* if sameprefix, use yname and xname to get "your cloak and suit" + or "Manlobbi's cloak and suit"; otherwise, use yname and yname + to get "your cloak and Manlobbi's suit" or vice versa */ + boolean sameprefix = (uarm && uarmc + && !strcmp(shk_your(cloaktmp, uarmc), + shk_your(suittmp, uarm))); - *buf = '\0'; - if (uarmc) Strcat(buf, yname(uarmc)); - if (uarm && uarmc) Strcat(buf, " and "); - if (uarm) Strcat(buf, sameprefix ? xname(uarm) : yname(uarm)); - You(need_to_take_off_outer_armor, buf, verb, yname(obj)); - } - return TRUE; + *buf = '\0'; + if (uarmc) + Strcat(buf, yname(uarmc)); + if (uarm && uarmc) + Strcat(buf, " and "); + if (uarm) + Strcat(buf, sameprefix ? xname(uarm) : yname(uarm)); + You(need_to_take_off_outer_armor, buf, verb, yname(obj)); + } + return TRUE; } /* check for ring covered by gloves */ if ((obj == uleft || obj == uright) && uarmg && BLOCKSACCESS(uarmg)) { - if (verb) { - Strcpy(buf, yname(uarmg)); - You(need_to_take_off_outer_armor, buf, verb, yname(obj)); - } - return TRUE; + if (verb) { + Strcpy(buf, yname(uarmg)); + You(need_to_take_off_outer_armor, buf, verb, yname(obj)); + } + return TRUE; } /* item is not inaccessible */ return FALSE; diff --git a/src/dog.c b/src/dog.c index 6e23fad54..6897ba7a6 100644 --- a/src/dog.c +++ b/src/dog.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dog.c $NHDT-Date: 1425319883 2015/03/02 18:11:23 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */ +/* NetHack 3.6 dog.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.48 $ */ /* NetHack 3.6 dog.c $Date: 2011/04/15 01:55:42 $ $Revision: 1.37 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,188 +11,197 @@ void newedog(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) mtmp->mextra = newmextra(); - if (!EDOG(mtmp)) { - EDOG(mtmp) = (struct edog *)alloc(sizeof(struct edog)); - (void) memset((genericptr_t) EDOG(mtmp), 0, sizeof(struct edog)); - } + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + if (!EDOG(mtmp)) { + EDOG(mtmp) = (struct edog *) alloc(sizeof(struct edog)); + (void) memset((genericptr_t) EDOG(mtmp), 0, sizeof(struct edog)); + } } void free_edog(mtmp) struct monst *mtmp; { - if (mtmp->mextra && EDOG(mtmp)) { - free((genericptr_t) EDOG(mtmp)); - EDOG(mtmp) = (struct edog *)0; - } - mtmp->mtame = 0; + if (mtmp->mextra && EDOG(mtmp)) { + free((genericptr_t) EDOG(mtmp)); + EDOG(mtmp) = (struct edog *) 0; + } + mtmp->mtame = 0; } void initedog(mtmp) register struct monst *mtmp; { - mtmp->mtame = is_domestic(mtmp->data) ? 10 : 5; - mtmp->mpeaceful = 1; - mtmp->mavenge = 0; - set_malign(mtmp); /* recalc alignment now that it's tamed */ - mtmp->mleashed = 0; - mtmp->meating = 0; - EDOG(mtmp)->droptime = 0; - EDOG(mtmp)->dropdist = 10000; - EDOG(mtmp)->apport = 10; - EDOG(mtmp)->whistletime = 0; - EDOG(mtmp)->hungrytime = 1000 + monstermoves; - EDOG(mtmp)->ogoal.x = -1; /* force error if used before set */ - EDOG(mtmp)->ogoal.y = -1; - EDOG(mtmp)->abuse = 0; - EDOG(mtmp)->revivals = 0; - EDOG(mtmp)->mhpmax_penalty = 0; - EDOG(mtmp)->killed_by_u = 0; + mtmp->mtame = is_domestic(mtmp->data) ? 10 : 5; + mtmp->mpeaceful = 1; + mtmp->mavenge = 0; + set_malign(mtmp); /* recalc alignment now that it's tamed */ + mtmp->mleashed = 0; + mtmp->meating = 0; + EDOG(mtmp)->droptime = 0; + EDOG(mtmp)->dropdist = 10000; + EDOG(mtmp)->apport = 10; + EDOG(mtmp)->whistletime = 0; + EDOG(mtmp)->hungrytime = 1000 + monstermoves; + EDOG(mtmp)->ogoal.x = -1; /* force error if used before set */ + EDOG(mtmp)->ogoal.y = -1; + EDOG(mtmp)->abuse = 0; + EDOG(mtmp)->revivals = 0; + EDOG(mtmp)->mhpmax_penalty = 0; + EDOG(mtmp)->killed_by_u = 0; } STATIC_OVL int pet_type() { - if (urole.petnum != NON_PM) - return (urole.petnum); - else if (preferred_pet == 'c') - return (PM_KITTEN); - else if (preferred_pet == 'd') - return (PM_LITTLE_DOG); - else - return (rn2(2) ? PM_KITTEN : PM_LITTLE_DOG); + if (urole.petnum != NON_PM) + return (urole.petnum); + else if (preferred_pet == 'c') + return (PM_KITTEN); + else if (preferred_pet == 'd') + return (PM_LITTLE_DOG); + else + return (rn2(2) ? PM_KITTEN : PM_LITTLE_DOG); } struct monst * -make_familiar(otmp,x,y,quietly) +make_familiar(otmp, x, y, quietly) register struct obj *otmp; xchar x, y; boolean quietly; { - struct permonst *pm; - struct monst *mtmp = 0; - int chance, trycnt = 100; + struct permonst *pm; + struct monst *mtmp = 0; + int chance, trycnt = 100; - do { - if (otmp) { /* figurine; otherwise spell */ - int mndx = otmp->corpsenm; - pm = &mons[mndx]; - /* activating a figurine provides one way to exceed the - maximum number of the target critter created--unless - it has a special limit (erinys, Nazgul) */ - if ((mvitals[mndx].mvflags & G_EXTINCT) && - mbirth_limit(mndx) != MAXMONNO) { - if (!quietly) - /* have just been given "You - the figurine and it transforms." message */ - pline("... into a pile of dust."); - break; /* mtmp is null */ - } - } else if (!rn2(3)) { - pm = &mons[pet_type()]; - } else { - pm = rndmonst(); - if (!pm) { - if (!quietly) - There("seems to be nothing available for a familiar."); - break; - } - } + do { + if (otmp) { /* figurine; otherwise spell */ + int mndx = otmp->corpsenm; + pm = &mons[mndx]; + /* activating a figurine provides one way to exceed the + maximum number of the target critter created--unless + it has a special limit (erinys, Nazgul) */ + if ((mvitals[mndx].mvflags & G_EXTINCT) + && mbirth_limit(mndx) != MAXMONNO) { + if (!quietly) + /* have just been given "You + the figurine and it transforms." message */ + pline("... into a pile of dust."); + break; /* mtmp is null */ + } + } else if (!rn2(3)) { + pm = &mons[pet_type()]; + } else { + pm = rndmonst(); + if (!pm) { + if (!quietly) + There("seems to be nothing available for a familiar."); + break; + } + } - mtmp = makemon(pm, x, y, MM_EDOG|MM_IGNOREWATER|NO_MINVENT); - if (otmp && !mtmp) { /* monster was genocided or square occupied */ - if (!quietly) - pline_The("figurine writhes and then shatters into pieces!"); - break; - } - } while (!mtmp && --trycnt > 0); + mtmp = makemon(pm, x, y, MM_EDOG | MM_IGNOREWATER | NO_MINVENT); + if (otmp && !mtmp) { /* monster was genocided or square occupied */ + if (!quietly) + pline_The("figurine writhes and then shatters into pieces!"); + break; + } + } while (!mtmp && --trycnt > 0); - if (!mtmp) return (struct monst *)0; + if (!mtmp) + return (struct monst *) 0; - if (is_pool(mtmp->mx, mtmp->my) && minliquid(mtmp)) - return (struct monst *)0; + if (is_pool(mtmp->mx, mtmp->my) && minliquid(mtmp)) + return (struct monst *) 0; - initedog(mtmp); - mtmp->msleeping = 0; - if (otmp) { /* figurine; resulting monster might not become a pet */ - chance = rn2(10); /* 0==tame, 1==peaceful, 2==hostile */ - if (chance > 2) chance = otmp->blessed ? 0 : !otmp->cursed ? 1 : 2; - /* 0,1,2: b=80%,10,10; nc=10%,80,10; c=10%,10,80 */ - if (chance > 0) { - mtmp->mtame = 0; /* not tame after all */ - if (chance == 2) { /* hostile (cursed figurine) */ - if (!quietly) - You("get a bad feeling about this."); - mtmp->mpeaceful = 0; - set_malign(mtmp); - } - } - /* if figurine has been named, give same name to the monster */ - if (has_oname(otmp)) - mtmp = christen_monst(mtmp, ONAME(otmp)); - } - set_malign(mtmp); /* more alignment changes */ - newsym(mtmp->mx, mtmp->my); + initedog(mtmp); + mtmp->msleeping = 0; + if (otmp) { /* figurine; resulting monster might not become a pet */ + chance = rn2(10); /* 0==tame, 1==peaceful, 2==hostile */ + if (chance > 2) + chance = otmp->blessed ? 0 : !otmp->cursed ? 1 : 2; + /* 0,1,2: b=80%,10,10; nc=10%,80,10; c=10%,10,80 */ + if (chance > 0) { + mtmp->mtame = 0; /* not tame after all */ + if (chance == 2) { /* hostile (cursed figurine) */ + if (!quietly) + You("get a bad feeling about this."); + mtmp->mpeaceful = 0; + set_malign(mtmp); + } + } + /* if figurine has been named, give same name to the monster */ + if (has_oname(otmp)) + mtmp = christen_monst(mtmp, ONAME(otmp)); + } + set_malign(mtmp); /* more alignment changes */ + newsym(mtmp->mx, mtmp->my); - /* must wield weapon immediately since pets will otherwise drop it */ - if (mtmp->mtame && attacktype(mtmp->data, AT_WEAP)) { - mtmp->weapon_check = NEED_HTH_WEAPON; - (void) mon_wield_item(mtmp); - } - return mtmp; + /* must wield weapon immediately since pets will otherwise drop it */ + if (mtmp->mtame && attacktype(mtmp->data, AT_WEAP)) { + mtmp->weapon_check = NEED_HTH_WEAPON; + (void) mon_wield_item(mtmp); + } + return mtmp; } struct monst * makedog() { - register struct monst *mtmp; - register struct obj *otmp; - const char *petname; - int pettype; - static int petname_used = 0; + register struct monst *mtmp; + register struct obj *otmp; + const char *petname; + int pettype; + static int petname_used = 0; - if (preferred_pet == 'n') return((struct monst *) 0); + if (preferred_pet == 'n') + return ((struct monst *) 0); - pettype = pet_type(); - if (pettype == PM_LITTLE_DOG) - petname = dogname; - else if (pettype == PM_PONY) - petname = horsename; - else - petname = catname; + pettype = pet_type(); + if (pettype == PM_LITTLE_DOG) + petname = dogname; + else if (pettype == PM_PONY) + petname = horsename; + else + petname = catname; - /* default pet names */ - if (!*petname && pettype == PM_LITTLE_DOG) { - /* All of these names were for dogs. */ - if(Role_if(PM_CAVEMAN)) petname = "Slasher"; /* The Warrior */ - if(Role_if(PM_SAMURAI)) petname = "Hachi"; /* Shibuya Station */ - if(Role_if(PM_BARBARIAN)) petname = "Idefix"; /* Obelix */ - if(Role_if(PM_RANGER)) petname = "Sirius"; /* Orion's dog */ - } + /* default pet names */ + if (!*petname && pettype == PM_LITTLE_DOG) { + /* All of these names were for dogs. */ + if (Role_if(PM_CAVEMAN)) + petname = "Slasher"; /* The Warrior */ + if (Role_if(PM_SAMURAI)) + petname = "Hachi"; /* Shibuya Station */ + if (Role_if(PM_BARBARIAN)) + petname = "Idefix"; /* Obelix */ + if (Role_if(PM_RANGER)) + petname = "Sirius"; /* Orion's dog */ + } - mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG); + mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG); - if(!mtmp) return((struct monst *) 0); /* pets were genocided */ + if (!mtmp) + return ((struct monst *) 0); /* pets were genocided */ - context.startingpet_mid = mtmp->m_id; - /* Horses already wear a saddle */ - if (pettype == PM_PONY && !!(otmp = mksobj(SADDLE, TRUE, FALSE))) { - if (mpickobj(mtmp, otmp)) - panic("merged saddle?"); - mtmp->misc_worn_check |= W_SADDLE; - otmp->dknown = otmp->bknown = otmp->rknown = 1; - otmp->owornmask = W_SADDLE; - otmp->leashmon = mtmp->m_id; - update_mon_intrinsics(mtmp, otmp, TRUE, TRUE); - } + context.startingpet_mid = mtmp->m_id; + /* Horses already wear a saddle */ + if (pettype == PM_PONY && !!(otmp = mksobj(SADDLE, TRUE, FALSE))) { + if (mpickobj(mtmp, otmp)) + panic("merged saddle?"); + mtmp->misc_worn_check |= W_SADDLE; + otmp->dknown = otmp->bknown = otmp->rknown = 1; + otmp->owornmask = W_SADDLE; + otmp->leashmon = mtmp->m_id; + update_mon_intrinsics(mtmp, otmp, TRUE, TRUE); + } - if (!petname_used++ && *petname) - mtmp = christen_monst(mtmp, petname); + if (!petname_used++ && *petname) + mtmp = christen_monst(mtmp, petname); - initedog(mtmp); - return(mtmp); + initedog(mtmp); + return (mtmp); } /* record `last move time' for all monsters prior to level save so that @@ -200,82 +209,87 @@ makedog() void update_mlstmv() { - struct monst *mon; + struct monst *mon; - /* monst->mlstmv used to be updated every time `monst' actually moved, - but that is no longer the case so we just do a blanket assignment */ - for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - mon->mlstmv = monstermoves; - } + /* monst->mlstmv used to be updated every time `monst' actually moved, + but that is no longer the case so we just do a blanket assignment */ + for (mon = fmon; mon; mon = mon->nmon) { + if (DEADMONSTER(mon)) + continue; + mon->mlstmv = monstermoves; + } } void losedogs() { - register struct monst *mtmp, *mtmp0 = 0, *mtmp2; - int dismissKops = 0; + register struct monst *mtmp, *mtmp0 = 0, *mtmp2; + int dismissKops = 0; - /* - * First, scan migrating_mons for shopkeepers who want to dismiss Kops, - * and scan mydogs for shopkeepers who want to retain kops. - * Second, dismiss kops if warranted, making more room for arrival. - * Third, place monsters accompanying the hero. - * Last, place migrating monsters coming to this level. - * - * Hero might eventually be displaced (due to the third step, but - * occuring later), which is the main reason to do the second step - * sooner (in turn necessitating the first step, rather than combining - * the list scans with monster placement). - */ + /* + * First, scan migrating_mons for shopkeepers who want to dismiss Kops, + * and scan mydogs for shopkeepers who want to retain kops. + * Second, dismiss kops if warranted, making more room for arrival. + * Third, place monsters accompanying the hero. + * Last, place migrating monsters coming to this level. + * + * Hero might eventually be displaced (due to the third step, but + * occuring later), which is the main reason to do the second step + * sooner (in turn necessitating the first step, rather than combining + * the list scans with monster placement). + */ - /* check for returning shk(s) */ - for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) { - if (mtmp->mux != u.uz.dnum || mtmp->muy != u.uz.dlevel) continue; - if (mtmp->isshk) { - if (ESHK(mtmp)->dismiss_kops) { - if (dismissKops == 0) dismissKops = 1; - ESHK(mtmp)->dismiss_kops = FALSE; /* reset */ - } else if (!mtmp->mpeaceful) { - /* an unpacified shk is returning; don't dismiss kops - even if another pacified one is willing to do so */ - dismissKops = -1; - /* [keep looping; later monsters might need ESHK reset] */ - } - } - } - /* make the same check for mydogs */ - for (mtmp = mydogs; mtmp && dismissKops >= 0; mtmp = mtmp->nmon) { - if (mtmp->isshk) { - /* hostile shk might accompany hero [ESHK(mtmp)->dismiss_kops - can't be set here; it's only used for migrating_mons] */ - if (!mtmp->mpeaceful) dismissKops = -1; - } - } + /* check for returning shk(s) */ + for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) { + if (mtmp->mux != u.uz.dnum || mtmp->muy != u.uz.dlevel) + continue; + if (mtmp->isshk) { + if (ESHK(mtmp)->dismiss_kops) { + if (dismissKops == 0) + dismissKops = 1; + ESHK(mtmp)->dismiss_kops = FALSE; /* reset */ + } else if (!mtmp->mpeaceful) { + /* an unpacified shk is returning; don't dismiss kops + even if another pacified one is willing to do so */ + dismissKops = -1; + /* [keep looping; later monsters might need ESHK reset] */ + } + } + } + /* make the same check for mydogs */ + for (mtmp = mydogs; mtmp && dismissKops >= 0; mtmp = mtmp->nmon) { + if (mtmp->isshk) { + /* hostile shk might accompany hero [ESHK(mtmp)->dismiss_kops + can't be set here; it's only used for migrating_mons] */ + if (!mtmp->mpeaceful) + dismissKops = -1; + } + } - /* when a hostile shopkeeper chases hero to another level - and then gets paid off there, get rid of summoned kops - here now that he has returned to his shop level */ - if (dismissKops > 0) make_happy_shoppers(TRUE); + /* when a hostile shopkeeper chases hero to another level + and then gets paid off there, get rid of summoned kops + here now that he has returned to his shop level */ + if (dismissKops > 0) + make_happy_shoppers(TRUE); - /* place pets and/or any other monsters who accompany hero */ - while ((mtmp = mydogs) != 0) { - mydogs = mtmp->nmon; - mon_arrive(mtmp, TRUE); - } + /* place pets and/or any other monsters who accompany hero */ + while ((mtmp = mydogs) != 0) { + mydogs = mtmp->nmon; + mon_arrive(mtmp, TRUE); + } - /* time for migrating monsters to arrive */ - for(mtmp = migrating_mons; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if (mtmp->mux == u.uz.dnum && mtmp->muy == u.uz.dlevel) { - if(mtmp == migrating_mons) - migrating_mons = mtmp->nmon; - else - mtmp0->nmon = mtmp->nmon; - mon_arrive(mtmp, FALSE); - } else - mtmp0 = mtmp; - } + /* time for migrating monsters to arrive */ + for (mtmp = migrating_mons; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (mtmp->mux == u.uz.dnum && mtmp->muy == u.uz.dlevel) { + if (mtmp == migrating_mons) + migrating_mons = mtmp->nmon; + else + mtmp0->nmon = mtmp->nmon; + mon_arrive(mtmp, FALSE); + } else + mtmp0 = mtmp; + } } /* called from resurrect() in addition to losedogs() */ @@ -284,525 +298,556 @@ mon_arrive(mtmp, with_you) struct monst *mtmp; boolean with_you; { - struct trap *t; - xchar xlocale, ylocale, xyloc, xyflags, wander; - int num_segs; + struct trap *t; + xchar xlocale, ylocale, xyloc, xyflags, wander; + int num_segs; - mtmp->nmon = fmon; - fmon = mtmp; - if (mtmp->isshk) - set_residency(mtmp, FALSE); + mtmp->nmon = fmon; + fmon = mtmp; + if (mtmp->isshk) + set_residency(mtmp, FALSE); - num_segs = mtmp->wormno; - /* baby long worms have no tail so don't use is_longworm() */ - if (mtmp->data == &mons[PM_LONG_WORM]) { - mtmp->wormno = get_wormno(); - if (mtmp->wormno) - initworm(mtmp, num_segs); - } else - mtmp->wormno = 0; + num_segs = mtmp->wormno; + /* baby long worms have no tail so don't use is_longworm() */ + if (mtmp->data == &mons[PM_LONG_WORM]) { + mtmp->wormno = get_wormno(); + if (mtmp->wormno) + initworm(mtmp, num_segs); + } else + mtmp->wormno = 0; - /* some monsters might need to do something special upon arrival - _after_ the current level has been fully set up; see dochug() */ - mtmp->mstrategy |= STRAT_ARRIVE; + /* some monsters might need to do something special upon arrival + _after_ the current level has been fully set up; see dochug() */ + mtmp->mstrategy |= STRAT_ARRIVE; - /* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */ - mtmp->mux = u.ux, mtmp->muy = u.uy; - xyloc = mtmp->mtrack[0].x; - xyflags = mtmp->mtrack[0].y; - xlocale = mtmp->mtrack[1].x; - ylocale = mtmp->mtrack[1].y; - mtmp->mtrack[0].x = mtmp->mtrack[0].y = 0; - mtmp->mtrack[1].x = mtmp->mtrack[1].y = 0; + /* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */ + mtmp->mux = u.ux, mtmp->muy = u.uy; + xyloc = mtmp->mtrack[0].x; + xyflags = mtmp->mtrack[0].y; + xlocale = mtmp->mtrack[1].x; + ylocale = mtmp->mtrack[1].y; + mtmp->mtrack[0].x = mtmp->mtrack[0].y = 0; + mtmp->mtrack[1].x = mtmp->mtrack[1].y = 0; - if (mtmp == u.usteed) - return; /* don't place steed on the map */ - if (with_you) { - /* When a monster accompanies you, sometimes it will arrive - at your intended destination and you'll end up next to - that spot. This code doesn't control the final outcome; - goto_level(do.c) decides who ends up at your target spot - when there is a monster there too. */ - if (!MON_AT(u.ux, u.uy) && - !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2)) - rloc_to(mtmp, u.ux, u.uy); - else - mnexto(mtmp); - return; - } - /* - * The monster arrived on this level independently of the player. - * Its coordinate fields were overloaded for use as flags that - * specify its final destination. - */ + if (mtmp == u.usteed) + return; /* don't place steed on the map */ + if (with_you) { + /* When a monster accompanies you, sometimes it will arrive + at your intended destination and you'll end up next to + that spot. This code doesn't control the final outcome; + goto_level(do.c) decides who ends up at your target spot + when there is a monster there too. */ + if (!MON_AT(u.ux, u.uy) + && !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2)) + rloc_to(mtmp, u.ux, u.uy); + else + mnexto(mtmp); + return; + } + /* + * The monster arrived on this level independently of the player. + * Its coordinate fields were overloaded for use as flags that + * specify its final destination. + */ - if (mtmp->mlstmv < monstermoves - 1L) { - /* heal monster for time spent in limbo */ - long nmv = monstermoves - 1L - mtmp->mlstmv; + if (mtmp->mlstmv < monstermoves - 1L) { + /* heal monster for time spent in limbo */ + long nmv = monstermoves - 1L - mtmp->mlstmv; - mon_catchup_elapsed_time(mtmp, nmv); - mtmp->mlstmv = monstermoves - 1L; + mon_catchup_elapsed_time(mtmp, nmv); + mtmp->mlstmv = monstermoves - 1L; - /* let monster move a bit on new level (see placement code below) */ - wander = (xchar) min(nmv, 8); - } else - wander = 0; + /* let monster move a bit on new level (see placement code below) */ + wander = (xchar) min(nmv, 8); + } else + wander = 0; - switch (xyloc) { - case MIGR_APPROX_XY: /* {x,y}locale set above */ - break; - case MIGR_EXACT_XY: wander = 0; - break; - case MIGR_WITH_HERO: xlocale = u.ux, ylocale = u.uy; - break; - case MIGR_STAIRS_UP: xlocale = xupstair, ylocale = yupstair; - break; - case MIGR_STAIRS_DOWN: xlocale = xdnstair, ylocale = ydnstair; - break; - case MIGR_LADDER_UP: xlocale = xupladder, ylocale = yupladder; - break; - case MIGR_LADDER_DOWN: xlocale = xdnladder, ylocale = ydnladder; - break; - case MIGR_SSTAIRS: xlocale = sstairs.sx, ylocale = sstairs.sy; - break; - case MIGR_PORTAL: - if (In_endgame(&u.uz)) { - /* there is no arrival portal for endgame levels */ - /* BUG[?]: for simplicity, this code relies on the fact - that we know that the current endgame levels always - build upwards and never have any exclusion subregion - inside their TELEPORT_REGION settings. */ - xlocale = rn1(updest.hx - updest.lx + 1, updest.lx); - ylocale = rn1(updest.hy - updest.ly + 1, updest.ly); - break; - } - /* find the arrival portal */ - for (t = ftrap; t; t = t->ntrap) - if (t->ttyp == MAGIC_PORTAL) break; - if (t) { - xlocale = t->tx, ylocale = t->ty; - break; - } else { - impossible("mon_arrive: no corresponding portal?"); - } /*FALLTHRU*/ - default: - case MIGR_RANDOM: xlocale = ylocale = 0; - break; - } + switch (xyloc) { + case MIGR_APPROX_XY: /* {x,y}locale set above */ + break; + case MIGR_EXACT_XY: + wander = 0; + break; + case MIGR_WITH_HERO: + xlocale = u.ux, ylocale = u.uy; + break; + case MIGR_STAIRS_UP: + xlocale = xupstair, ylocale = yupstair; + break; + case MIGR_STAIRS_DOWN: + xlocale = xdnstair, ylocale = ydnstair; + break; + case MIGR_LADDER_UP: + xlocale = xupladder, ylocale = yupladder; + break; + case MIGR_LADDER_DOWN: + xlocale = xdnladder, ylocale = ydnladder; + break; + case MIGR_SSTAIRS: + xlocale = sstairs.sx, ylocale = sstairs.sy; + break; + case MIGR_PORTAL: + if (In_endgame(&u.uz)) { + /* there is no arrival portal for endgame levels */ + /* BUG[?]: for simplicity, this code relies on the fact + that we know that the current endgame levels always + build upwards and never have any exclusion subregion + inside their TELEPORT_REGION settings. */ + xlocale = rn1(updest.hx - updest.lx + 1, updest.lx); + ylocale = rn1(updest.hy - updest.ly + 1, updest.ly); + break; + } + /* find the arrival portal */ + for (t = ftrap; t; t = t->ntrap) + if (t->ttyp == MAGIC_PORTAL) + break; + if (t) { + xlocale = t->tx, ylocale = t->ty; + break; + } else { + impossible("mon_arrive: no corresponding portal?"); + } /*FALLTHRU*/ + default: + case MIGR_RANDOM: + xlocale = ylocale = 0; + break; + } - if (xlocale && wander) { - /* monster moved a bit; pick a nearby location */ - /* mnearto() deals w/stone, et al */ - char *r = in_rooms(xlocale, ylocale, 0); - if (r && *r) { - coord c; - /* somexy() handles irregular rooms */ - if (somexy(&rooms[*r - ROOMOFFSET], &c)) - xlocale = c.x, ylocale = c.y; - else - xlocale = ylocale = 0; - } else { /* not in a room */ - int i, j; - i = max(1, xlocale - wander); - j = min(COLNO-1, xlocale + wander); - xlocale = rn1(j - i, i); - i = max(0, ylocale - wander); - j = min(ROWNO-1, ylocale + wander); - ylocale = rn1(j - i, i); - } - } /* moved a bit */ + if (xlocale && wander) { + /* monster moved a bit; pick a nearby location */ + /* mnearto() deals w/stone, et al */ + char *r = in_rooms(xlocale, ylocale, 0); + if (r && *r) { + coord c; + /* somexy() handles irregular rooms */ + if (somexy(&rooms[*r - ROOMOFFSET], &c)) + xlocale = c.x, ylocale = c.y; + else + xlocale = ylocale = 0; + } else { /* not in a room */ + int i, j; + i = max(1, xlocale - wander); + j = min(COLNO - 1, xlocale + wander); + xlocale = rn1(j - i, i); + i = max(0, ylocale - wander); + j = min(ROWNO - 1, ylocale + wander); + ylocale = rn1(j - i, i); + } + } /* moved a bit */ - mtmp->mx = 0; /*(already is 0)*/ - mtmp->my = xyflags; - if (xlocale) - (void) mnearto(mtmp, xlocale, ylocale, FALSE); - else { - if (!rloc(mtmp,TRUE)) { - /* - * Failed to place migrating monster, - * probably because the level is full. - * Dump the monster's cargo and leave the monster dead. - */ - struct obj *obj; - while ((obj = mtmp->minvent) != 0) { - obj_extract_self(obj); - obj_no_longer_held(obj); - if (obj->owornmask & W_WEP) - setmnotwielded(mtmp,obj); - obj->owornmask = 0L; - if (xlocale && ylocale) - place_object(obj, xlocale, ylocale); - else if (rloco(obj)) { - if (!get_obj_location(obj, &xlocale, &ylocale, 0)) - impossible("Can't find relocated object."); - } - } - (void) mkcorpstat(CORPSE, (struct monst *)0, mtmp->data, - xlocale, ylocale, CORPSTAT_NONE); - mongone(mtmp); - } - } + mtmp->mx = 0; /*(already is 0)*/ + mtmp->my = xyflags; + if (xlocale) + (void) mnearto(mtmp, xlocale, ylocale, FALSE); + else { + if (!rloc(mtmp, TRUE)) { + /* + * Failed to place migrating monster, + * probably because the level is full. + * Dump the monster's cargo and leave the monster dead. + */ + struct obj *obj; + while ((obj = mtmp->minvent) != 0) { + obj_extract_self(obj); + obj_no_longer_held(obj); + if (obj->owornmask & W_WEP) + setmnotwielded(mtmp, obj); + obj->owornmask = 0L; + if (xlocale && ylocale) + place_object(obj, xlocale, ylocale); + else if (rloco(obj)) { + if (!get_obj_location(obj, &xlocale, &ylocale, 0)) + impossible("Can't find relocated object."); + } + } + (void) mkcorpstat(CORPSE, (struct monst *) 0, mtmp->data, xlocale, + ylocale, CORPSTAT_NONE); + mongone(mtmp); + } + } } /* heal monster for time spent elsewhere */ void mon_catchup_elapsed_time(mtmp, nmv) struct monst *mtmp; -long nmv; /* number of moves */ +long nmv; /* number of moves */ { - int imv = 0; /* avoid zillions of casts and lint warnings */ + int imv = 0; /* avoid zillions of casts and lint warnings */ #if defined(DEBUG) || defined(BETA) - if (nmv < 0L) { /* crash likely... */ - panic("catchup from future time?"); - /*NOTREACHED*/ - return; - } else if (nmv == 0L) { /* safe, but should'nt happen */ - impossible("catchup from now?"); - } else + if (nmv < 0L) { /* crash likely... */ + panic("catchup from future time?"); + /*NOTREACHED*/ + return; + } else if (nmv == 0L) { /* safe, but should'nt happen */ + impossible("catchup from now?"); + } else #endif - if (nmv >= LARGEST_INT) /* paranoia */ - imv = LARGEST_INT - 1; - else - imv = (int)nmv; + if (nmv >= LARGEST_INT) /* paranoia */ + imv = LARGEST_INT - 1; + else + imv = (int) nmv; - /* might stop being afraid, blind or frozen */ - /* set to 1 and allow final decrement in movemon() */ - if (mtmp->mblinded) { - if (imv >= (int) mtmp->mblinded) mtmp->mblinded = 1; - else mtmp->mblinded -= imv; - } - if (mtmp->mfrozen) { - if (imv >= (int) mtmp->mfrozen) mtmp->mfrozen = 1; - else mtmp->mfrozen -= imv; - } - if (mtmp->mfleetim) { - if (imv >= (int) mtmp->mfleetim) mtmp->mfleetim = 1; - else mtmp->mfleetim -= imv; - } + /* might stop being afraid, blind or frozen */ + /* set to 1 and allow final decrement in movemon() */ + if (mtmp->mblinded) { + if (imv >= (int) mtmp->mblinded) + mtmp->mblinded = 1; + else + mtmp->mblinded -= imv; + } + if (mtmp->mfrozen) { + if (imv >= (int) mtmp->mfrozen) + mtmp->mfrozen = 1; + else + mtmp->mfrozen -= imv; + } + if (mtmp->mfleetim) { + if (imv >= (int) mtmp->mfleetim) + mtmp->mfleetim = 1; + else + mtmp->mfleetim -= imv; + } - /* might recover from temporary trouble */ - if (mtmp->mtrapped && rn2(imv + 1) > 40/2) mtmp->mtrapped = 0; - if (mtmp->mconf && rn2(imv + 1) > 50/2) mtmp->mconf = 0; - if (mtmp->mstun && rn2(imv + 1) > 10/2) mtmp->mstun = 0; + /* might recover from temporary trouble */ + if (mtmp->mtrapped && rn2(imv + 1) > 40 / 2) + mtmp->mtrapped = 0; + if (mtmp->mconf && rn2(imv + 1) > 50 / 2) + mtmp->mconf = 0; + if (mtmp->mstun && rn2(imv + 1) > 10 / 2) + mtmp->mstun = 0; - /* might finish eating or be able to use special ability again */ - if (imv > mtmp->meating) finish_meating(mtmp); - else mtmp->meating -= imv; - if (imv > mtmp->mspec_used) mtmp->mspec_used = 0; - else mtmp->mspec_used -= imv; + /* might finish eating or be able to use special ability again */ + if (imv > mtmp->meating) + finish_meating(mtmp); + else + mtmp->meating -= imv; + if (imv > mtmp->mspec_used) + mtmp->mspec_used = 0; + else + mtmp->mspec_used -= imv; - /* reduce tameness for every 150 moves you are separated */ - if (mtmp->mtame) { - int wilder = (imv + 75) / 150; - if (mtmp->mtame > wilder) mtmp->mtame -= wilder; /* less tame */ - else if (mtmp->mtame > rn2(wilder)) mtmp->mtame = 0; /* untame */ - else mtmp->mtame = mtmp->mpeaceful = 0; /* hostile! */ - } - /* check to see if it would have died as a pet; if so, go wild instead - * of dying the next time we call dog_move() - */ - if (mtmp->mtame && !mtmp->isminion && - (carnivorous(mtmp->data) || herbivorous(mtmp->data))) { - struct edog *edog = EDOG(mtmp); + /* reduce tameness for every 150 moves you are separated */ + if (mtmp->mtame) { + int wilder = (imv + 75) / 150; + if (mtmp->mtame > wilder) + mtmp->mtame -= wilder; /* less tame */ + else if (mtmp->mtame > rn2(wilder)) + mtmp->mtame = 0; /* untame */ + else + mtmp->mtame = mtmp->mpeaceful = 0; /* hostile! */ + } + /* check to see if it would have died as a pet; if so, go wild instead + * of dying the next time we call dog_move() + */ + if (mtmp->mtame && !mtmp->isminion + && (carnivorous(mtmp->data) || herbivorous(mtmp->data))) { + struct edog *edog = EDOG(mtmp); - if ((monstermoves > edog->hungrytime + 500 && mtmp->mhp < 3) || - (monstermoves > edog->hungrytime + 750)) - mtmp->mtame = mtmp->mpeaceful = 0; - } + if ((monstermoves > edog->hungrytime + 500 && mtmp->mhp < 3) + || (monstermoves > edog->hungrytime + 750)) + mtmp->mtame = mtmp->mpeaceful = 0; + } - if (!mtmp->mtame && mtmp->mleashed) { - /* leashed monsters should always be with hero, consequently - never losing any time to be accounted for later */ - impossible("catching up for leashed monster?"); - m_unleash(mtmp, FALSE); - } + if (!mtmp->mtame && mtmp->mleashed) { + /* leashed monsters should always be with hero, consequently + never losing any time to be accounted for later */ + impossible("catching up for leashed monster?"); + m_unleash(mtmp, FALSE); + } - /* recover lost hit points */ - if (!regenerates(mtmp->data)) imv /= 20; - if (mtmp->mhp + imv >= mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - else mtmp->mhp += imv; + /* recover lost hit points */ + if (!regenerates(mtmp->data)) + imv /= 20; + if (mtmp->mhp + imv >= mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + else + mtmp->mhp += imv; } /* called when you move to another level */ void keepdogs(pets_only) -boolean pets_only; /* true for ascension or final escape */ +boolean pets_only; /* true for ascension or final escape */ { - register struct monst *mtmp, *mtmp2; - register struct obj *obj; - int num_segs; - boolean stay_behind; + register struct monst *mtmp, *mtmp2; + register struct obj *obj; + int num_segs; + boolean stay_behind; - for (mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if (DEADMONSTER(mtmp)) continue; - if (pets_only) { - if (!mtmp->mtame) continue; /* reject non-pets */ - /* don't block pets from accompanying hero's dungeon - escape or ascension simply due to mundane trifles; - unlike level change for steed, don't bother trying - to achieve a normal trap escape first */ - mtmp->mtrapped = 0; - mtmp->meating = 0; - mtmp->msleeping = 0; - mtmp->mfrozen = 0; - mtmp->mcanmove = 1; - } - if (((monnear(mtmp, u.ux, u.uy) && levl_follower(mtmp)) || - /* the wiz will level t-port from anywhere to chase - the amulet; if you don't have it, will chase you - only if in range. -3. */ - (u.uhave.amulet && mtmp->iswiz)) - && ((!mtmp->msleeping && mtmp->mcanmove) - /* eg if level teleport or new trap, steed has no control - to avoid following */ - || (mtmp == u.usteed) - ) - /* monster won't follow if it hasn't noticed you yet */ - && !(mtmp->mstrategy & STRAT_WAITFORU)) { - stay_behind = FALSE; - if (mtmp->mtrapped) (void)mintrap(mtmp); /* try to escape */ - if (mtmp == u.usteed) { - /* make sure steed is eligible to accompany hero */ - mtmp->mtrapped = 0; /* escape trap */ - mtmp->meating = 0; /* terminate eating */ - mdrop_special_objs(mtmp); /* drop Amulet */ - } else - if (mtmp->meating || mtmp->mtrapped) { - if (canseemon(mtmp)) - pline("%s is still %s.", Monnam(mtmp), - mtmp->meating ? "eating" : "trapped"); - stay_behind = TRUE; - } else if (mon_has_amulet(mtmp)) { - if (canseemon(mtmp)) - pline("%s seems very disoriented for a moment.", - Monnam(mtmp)); - stay_behind = TRUE; - } - if (stay_behind) { - if (mtmp->mleashed) { - pline("%s leash suddenly comes loose.", - humanoid(mtmp->data) - ? (mtmp->female ? "Her" : "His") - : "Its"); - m_unleash(mtmp, FALSE); - } - if (mtmp == u.usteed) { - /* can't happen unless someone makes a change - which scrambles the stay_behind logic above */ - impossible("steed left behind?"); - dismount_steed(DISMOUNT_GENERIC); - } - continue; - } - if (mtmp->isshk) - set_residency(mtmp, TRUE); + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (DEADMONSTER(mtmp)) + continue; + if (pets_only) { + if (!mtmp->mtame) + continue; /* reject non-pets */ + /* don't block pets from accompanying hero's dungeon + escape or ascension simply due to mundane trifles; + unlike level change for steed, don't bother trying + to achieve a normal trap escape first */ + mtmp->mtrapped = 0; + mtmp->meating = 0; + mtmp->msleeping = 0; + mtmp->mfrozen = 0; + mtmp->mcanmove = 1; + } + if (((monnear(mtmp, u.ux, u.uy) && levl_follower(mtmp)) || + /* the wiz will level t-port from anywhere to chase + the amulet; if you don't have it, will chase you + only if in range. -3. */ + (u.uhave.amulet && mtmp->iswiz)) + && ((!mtmp->msleeping && mtmp->mcanmove) + /* eg if level teleport or new trap, steed has no control + to avoid following */ + || (mtmp == u.usteed)) + /* monster won't follow if it hasn't noticed you yet */ + && !(mtmp->mstrategy & STRAT_WAITFORU)) { + stay_behind = FALSE; + if (mtmp->mtrapped) + (void) mintrap(mtmp); /* try to escape */ + if (mtmp == u.usteed) { + /* make sure steed is eligible to accompany hero */ + mtmp->mtrapped = 0; /* escape trap */ + mtmp->meating = 0; /* terminate eating */ + mdrop_special_objs(mtmp); /* drop Amulet */ + } else if (mtmp->meating || mtmp->mtrapped) { + if (canseemon(mtmp)) + pline("%s is still %s.", Monnam(mtmp), + mtmp->meating ? "eating" : "trapped"); + stay_behind = TRUE; + } else if (mon_has_amulet(mtmp)) { + if (canseemon(mtmp)) + pline("%s seems very disoriented for a moment.", + Monnam(mtmp)); + stay_behind = TRUE; + } + if (stay_behind) { + if (mtmp->mleashed) { + pline("%s leash suddenly comes loose.", + humanoid(mtmp->data) + ? (mtmp->female ? "Her" : "His") + : "Its"); + m_unleash(mtmp, FALSE); + } + if (mtmp == u.usteed) { + /* can't happen unless someone makes a change + which scrambles the stay_behind logic above */ + impossible("steed left behind?"); + dismount_steed(DISMOUNT_GENERIC); + } + continue; + } + if (mtmp->isshk) + set_residency(mtmp, TRUE); - if (mtmp->wormno) { - register int cnt; - /* NOTE: worm is truncated to # segs = max wormno size */ - cnt = count_wsegs(mtmp); - num_segs = min(cnt, MAX_NUM_WORMS - 1); - wormgone(mtmp); - } else num_segs = 0; + if (mtmp->wormno) { + register int cnt; + /* NOTE: worm is truncated to # segs = max wormno size */ + cnt = count_wsegs(mtmp); + num_segs = min(cnt, MAX_NUM_WORMS - 1); + wormgone(mtmp); + } else + num_segs = 0; - /* set minvent's obj->no_charge to 0 */ - for(obj = mtmp->minvent; obj; obj = obj->nobj) { - if (Has_contents(obj)) - picked_container(obj); /* does the right thing */ - obj->no_charge = 0; - } + /* set minvent's obj->no_charge to 0 */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + if (Has_contents(obj)) + picked_container(obj); /* does the right thing */ + obj->no_charge = 0; + } - relmon(mtmp, &mydogs); /* move it from map to mydogs */ - mtmp->mx = mtmp->my = 0; /* avoid mnexto()/MON_AT() problem */ - mtmp->wormno = num_segs; - mtmp->mlstmv = monstermoves; - } else if (mtmp->iswiz) { - /* we want to be able to find him when his next resurrection - chance comes up, but have him resume his present location - if player returns to this level before that time */ - migrate_to_level(mtmp, ledger_no(&u.uz), - MIGR_EXACT_XY, (coord *)0); - } else if (mtmp->mleashed) { - /* this can happen if your quest leader ejects you from the - "home" level while a leashed pet isn't next to you */ - pline("%s leash goes slack.", s_suffix(Monnam(mtmp))); - m_unleash(mtmp, FALSE); - } - } + relmon(mtmp, &mydogs); /* move it from map to mydogs */ + mtmp->mx = mtmp->my = 0; /* avoid mnexto()/MON_AT() problem */ + mtmp->wormno = num_segs; + mtmp->mlstmv = monstermoves; + } else if (mtmp->iswiz) { + /* we want to be able to find him when his next resurrection + chance comes up, but have him resume his present location + if player returns to this level before that time */ + migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_EXACT_XY, + (coord *) 0); + } else if (mtmp->mleashed) { + /* this can happen if your quest leader ejects you from the + "home" level while a leashed pet isn't next to you */ + pline("%s leash goes slack.", s_suffix(Monnam(mtmp))); + m_unleash(mtmp, FALSE); + } + } } void migrate_to_level(mtmp, tolev, xyloc, cc) - register struct monst *mtmp; - xchar tolev; /* destination level */ - xchar xyloc; /* MIGR_xxx destination xy location: */ - coord *cc; /* optional destination coordinates */ +register struct monst *mtmp; +xchar tolev; /* destination level */ +xchar xyloc; /* MIGR_xxx destination xy location: */ +coord *cc; /* optional destination coordinates */ { - register struct obj *obj; - d_level new_lev; - xchar xyflags; - int num_segs = 0; /* count of worm segments */ + register struct obj *obj; + d_level new_lev; + xchar xyflags; + int num_segs = 0; /* count of worm segments */ - if (mtmp->isshk) - set_residency(mtmp, TRUE); + if (mtmp->isshk) + set_residency(mtmp, TRUE); - if (mtmp->wormno) { - register int cnt; - /* **** NOTE: worm is truncated to # segs = max wormno size **** */ - cnt = count_wsegs(mtmp); - num_segs = min(cnt, MAX_NUM_WORMS - 1); - wormgone(mtmp); - } + if (mtmp->wormno) { + register int cnt; + /* **** NOTE: worm is truncated to # segs = max wormno size **** */ + cnt = count_wsegs(mtmp); + num_segs = min(cnt, MAX_NUM_WORMS - 1); + wormgone(mtmp); + } - /* set minvent's obj->no_charge to 0 */ - for(obj = mtmp->minvent; obj; obj = obj->nobj) { - if (Has_contents(obj)) - picked_container(obj); /* does the right thing */ - obj->no_charge = 0; - } + /* set minvent's obj->no_charge to 0 */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + if (Has_contents(obj)) + picked_container(obj); /* does the right thing */ + obj->no_charge = 0; + } - if (mtmp->mleashed) { - mtmp->mtame--; - m_unleash(mtmp, TRUE); - } - relmon(mtmp, &migrating_mons); /* move it from map to migrating_mons */ + if (mtmp->mleashed) { + mtmp->mtame--; + m_unleash(mtmp, TRUE); + } + relmon(mtmp, &migrating_mons); /* move it from map to migrating_mons */ - new_lev.dnum = ledger_to_dnum((xchar)tolev); - new_lev.dlevel = ledger_to_dlev((xchar)tolev); - /* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as */ - /* destination codes (setup flag bits before altering mx or my) */ - xyflags = (depth(&new_lev) < depth(&u.uz)); /* 1 => up */ - if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) xyflags |= 2; - mtmp->wormno = num_segs; - mtmp->mlstmv = monstermoves; - mtmp->mtrack[1].x = cc ? cc->x : mtmp->mx; - mtmp->mtrack[1].y = cc ? cc->y : mtmp->my; - mtmp->mtrack[0].x = xyloc; - mtmp->mtrack[0].y = xyflags; - mtmp->mux = new_lev.dnum; - mtmp->muy = new_lev.dlevel; - mtmp->mx = mtmp->my = 0; /* this implies migration */ - if (mtmp == context.polearm.hitmon) context.polearm.hitmon = NULL; + new_lev.dnum = ledger_to_dnum((xchar) tolev); + new_lev.dlevel = ledger_to_dlev((xchar) tolev); + /* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as */ + /* destination codes (setup flag bits before altering mx or my) */ + xyflags = (depth(&new_lev) < depth(&u.uz)); /* 1 => up */ + if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) + xyflags |= 2; + mtmp->wormno = num_segs; + mtmp->mlstmv = monstermoves; + mtmp->mtrack[1].x = cc ? cc->x : mtmp->mx; + mtmp->mtrack[1].y = cc ? cc->y : mtmp->my; + mtmp->mtrack[0].x = xyloc; + mtmp->mtrack[0].y = xyflags; + mtmp->mux = new_lev.dnum; + mtmp->muy = new_lev.dlevel; + mtmp->mx = mtmp->my = 0; /* this implies migration */ + if (mtmp == context.polearm.hitmon) + context.polearm.hitmon = NULL; } /* return quality of food; the lower the better */ /* fungi will eat even tainted food */ int -dogfood(mon,obj) +dogfood(mon, obj) struct monst *mon; register struct obj *obj; { - struct permonst *mptr = mon->data, *fptr = 0; - boolean carni = carnivorous(mptr), herbi = herbivorous(mptr), - starving; + struct permonst *mptr = mon->data, *fptr = 0; + boolean carni = carnivorous(mptr), herbi = herbivorous(mptr), starving; - if (is_quest_artifact(obj) || obj_resists(obj, 0, 95)) - return (obj->cursed ? TABU : APPORT); + if (is_quest_artifact(obj) || obj_resists(obj, 0, 95)) + return (obj->cursed ? TABU : APPORT); - switch(obj->oclass) { - case FOOD_CLASS: - if (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG) - fptr = &mons[obj->corpsenm]; + switch (obj->oclass) { + case FOOD_CLASS: + if (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG) + fptr = &mons[obj->corpsenm]; - if (obj->otyp == CORPSE && is_rider(fptr)) return TABU; - if ((obj->otyp == CORPSE || obj->otyp == EGG) && - touch_petrifies(fptr) && !resists_ston(mon)) return POISON; - if (!carni && !herbi) return obj->cursed ? UNDEF : APPORT; + if (obj->otyp == CORPSE && is_rider(fptr)) + return TABU; + if ((obj->otyp == CORPSE || obj->otyp == EGG) && touch_petrifies(fptr) + && !resists_ston(mon)) + return POISON; + if (!carni && !herbi) + return obj->cursed ? UNDEF : APPORT; - /* a starving pet will eat almost anything */ - starving = (mon->mtame && !mon->isminion && - EDOG(mon)->mhpmax_penalty); + /* a starving pet will eat almost anything */ + starving = + (mon->mtame && !mon->isminion && EDOG(mon)->mhpmax_penalty); - /* ghouls prefer old corpses and unhatchable eggs, yum! - they'll eat fresh non-veggy corpses and hatchable eggs - when starving; they never eat stone-to-flesh'd meat */ - if (mptr == &mons[PM_GHOUL]) { - if (obj->otyp == CORPSE) - return - (peek_at_iced_corpse_age(obj) + 50L <= monstermoves && - fptr != &mons[PM_LIZARD] && - fptr != &mons[PM_LICHEN]) ? DOGFOOD : - (starving && !vegan(fptr)) ? ACCFOOD : POISON; - if (obj->otyp == EGG) - return stale_egg(obj) ? CADAVER : - starving ? ACCFOOD : POISON; - return TABU; - } + /* ghouls prefer old corpses and unhatchable eggs, yum! + they'll eat fresh non-veggy corpses and hatchable eggs + when starving; they never eat stone-to-flesh'd meat */ + if (mptr == &mons[PM_GHOUL]) { + if (obj->otyp == CORPSE) + return (peek_at_iced_corpse_age(obj) + 50L <= monstermoves + && fptr != &mons[PM_LIZARD] + && fptr != &mons[PM_LICHEN]) + ? DOGFOOD + : (starving && !vegan(fptr)) ? ACCFOOD : POISON; + if (obj->otyp == EGG) + return stale_egg(obj) ? CADAVER : starving ? ACCFOOD : POISON; + return TABU; + } - switch (obj->otyp) { - case TRIPE_RATION: - case MEATBALL: - case MEAT_RING: - case MEAT_STICK: - case HUGE_CHUNK_OF_MEAT: - return (carni ? DOGFOOD : MANFOOD); - case EGG: - return (carni ? CADAVER : MANFOOD); - case CORPSE: - if ((peek_at_iced_corpse_age(obj) + 50L <= monstermoves - && obj->corpsenm != PM_LIZARD - && obj->corpsenm != PM_LICHEN - && mptr->mlet != S_FUNGUS) || - (acidic(fptr) && !resists_acid(mon)) || - (poisonous(fptr) && !resists_poison(mon))) - return POISON; - /* turning into slime is preferrable to starvation */ - else if (fptr == &mons[PM_GREEN_SLIME] && - !slimeproof(mon->data)) - return (starving ? ACCFOOD : POISON); - else if (vegan(fptr)) - return (herbi ? CADAVER : MANFOOD); - /* most humanoids will avoid cannibalism unless starving; - arbitrary: elves won't eat other elves even then */ - else if (humanoid(mptr) && same_race(mptr, fptr) && - (!is_undead(mptr) && fptr->mlet != S_KOBOLD && - fptr->mlet != S_ORC && fptr->mlet != S_OGRE)) - return ((starving && carni && !is_elf(mptr)) ? - ACCFOOD : TABU); - else - return (carni ? CADAVER : MANFOOD); - case CLOVE_OF_GARLIC: - return ((is_undead(mptr) || is_vampshifter(mon)) ? TABU : - ((herbi || starving) ? ACCFOOD : MANFOOD)); - case TIN: - return (metallivorous(mptr) ? ACCFOOD : MANFOOD); - case APPLE: - case CARROT: - return (herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD); - case BANANA: - return ((mptr->mlet == S_YETI) ? DOGFOOD : - ((herbi || starving) ? ACCFOOD : MANFOOD)); - default: - if (starving) return ACCFOOD; - return (obj->otyp > SLIME_MOLD ? - (carni ? ACCFOOD : MANFOOD) : - (herbi ? ACCFOOD : MANFOOD)); - } - default: - if (obj->otyp == AMULET_OF_STRANGULATION || - obj->otyp == RIN_SLOW_DIGESTION) - return TABU; - if (mon_hates_silver(mon) && - objects[obj->otyp].oc_material == SILVER) - return(TABU); - if (mptr == &mons[PM_GELATINOUS_CUBE] && is_organic(obj)) - return(ACCFOOD); - if (metallivorous(mptr) && is_metallic(obj) && - (is_rustprone(obj) || mptr != &mons[PM_RUST_MONSTER])) { - /* Non-rustproofed ferrous based metals are preferred. */ - return((is_rustprone(obj) && !obj->oerodeproof) ? DOGFOOD : - ACCFOOD); - } - if(!obj->cursed && obj->oclass != BALL_CLASS && - obj->oclass != CHAIN_CLASS) - return(APPORT); - /* fall into next case */ - case ROCK_CLASS: - return(UNDEF); - } + switch (obj->otyp) { + case TRIPE_RATION: + case MEATBALL: + case MEAT_RING: + case MEAT_STICK: + case HUGE_CHUNK_OF_MEAT: + return (carni ? DOGFOOD : MANFOOD); + case EGG: + return (carni ? CADAVER : MANFOOD); + case CORPSE: + if ((peek_at_iced_corpse_age(obj) + 50L <= monstermoves + && obj->corpsenm != PM_LIZARD && obj->corpsenm != PM_LICHEN + && mptr->mlet != S_FUNGUS) + || (acidic(fptr) && !resists_acid(mon)) + || (poisonous(fptr) && !resists_poison(mon))) + return POISON; + /* turning into slime is preferrable to starvation */ + else if (fptr == &mons[PM_GREEN_SLIME] && !slimeproof(mon->data)) + return (starving ? ACCFOOD : POISON); + else if (vegan(fptr)) + return (herbi ? CADAVER : MANFOOD); + /* most humanoids will avoid cannibalism unless starving; + arbitrary: elves won't eat other elves even then */ + else if (humanoid(mptr) && same_race(mptr, fptr) + && (!is_undead(mptr) && fptr->mlet != S_KOBOLD + && fptr->mlet != S_ORC && fptr->mlet != S_OGRE)) + return ((starving && carni && !is_elf(mptr)) ? ACCFOOD + : TABU); + else + return (carni ? CADAVER : MANFOOD); + case CLOVE_OF_GARLIC: + return ((is_undead(mptr) || is_vampshifter(mon)) + ? TABU + : ((herbi || starving) ? ACCFOOD : MANFOOD)); + case TIN: + return (metallivorous(mptr) ? ACCFOOD : MANFOOD); + case APPLE: + case CARROT: + return (herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD); + case BANANA: + return ((mptr->mlet == S_YETI) + ? DOGFOOD + : ((herbi || starving) ? ACCFOOD : MANFOOD)); + default: + if (starving) + return ACCFOOD; + return (obj->otyp > SLIME_MOLD ? (carni ? ACCFOOD : MANFOOD) + : (herbi ? ACCFOOD : MANFOOD)); + } + default: + if (obj->otyp == AMULET_OF_STRANGULATION + || obj->otyp == RIN_SLOW_DIGESTION) + return TABU; + if (mon_hates_silver(mon) && objects[obj->otyp].oc_material == SILVER) + return (TABU); + if (mptr == &mons[PM_GELATINOUS_CUBE] && is_organic(obj)) + return (ACCFOOD); + if (metallivorous(mptr) && is_metallic(obj) + && (is_rustprone(obj) || mptr != &mons[PM_RUST_MONSTER])) { + /* Non-rustproofed ferrous based metals are preferred. */ + return ((is_rustprone(obj) && !obj->oerodeproof) ? DOGFOOD + : ACCFOOD); + } + if (!obj->cursed && obj->oclass != BALL_CLASS + && obj->oclass != CHAIN_CLASS) + return (APPORT); + /* fall into next case */ + case ROCK_CLASS: + return (UNDEF); + } } /* @@ -815,87 +860,88 @@ tamedog(mtmp, obj) register struct monst *mtmp; register struct obj *obj; { - /* The Wiz, Medusa and the quest nemeses aren't even made peaceful. */ - if (mtmp->iswiz || mtmp->data == &mons[PM_MEDUSA] - || (mtmp->data->mflags3 & M3_WANTSARTI)) - return FALSE; + /* The Wiz, Medusa and the quest nemeses aren't even made peaceful. */ + if (mtmp->iswiz || mtmp->data == &mons[PM_MEDUSA] + || (mtmp->data->mflags3 & M3_WANTSARTI)) + return FALSE; - /* worst case, at least it'll be peaceful. */ - mtmp->mpeaceful = 1; - set_malign(mtmp); - if(flags.moonphase == FULL_MOON && night() && rn2(6) && obj - && mtmp->data->mlet == S_DOG) - return FALSE; + /* worst case, at least it'll be peaceful. */ + mtmp->mpeaceful = 1; + set_malign(mtmp); + if (flags.moonphase == FULL_MOON && night() && rn2(6) && obj + && mtmp->data->mlet == S_DOG) + return FALSE; - /* If we cannot tame it, at least it's no longer afraid. */ - mtmp->mflee = 0; - mtmp->mfleetim = 0; + /* If we cannot tame it, at least it's no longer afraid. */ + mtmp->mflee = 0; + mtmp->mfleetim = 0; - /* make grabber let go now, whether it becomes tame or not */ - if (mtmp == u.ustuck) { - if (u.uswallow) - expels(mtmp, mtmp->data, TRUE); - else if (!(Upolyd && sticks(youmonst.data))) - unstuck(mtmp); - } + /* make grabber let go now, whether it becomes tame or not */ + if (mtmp == u.ustuck) { + if (u.uswallow) + expels(mtmp, mtmp->data, TRUE); + else if (!(Upolyd && sticks(youmonst.data))) + unstuck(mtmp); + } - /* feeding it treats makes it tamer */ - if (mtmp->mtame && obj) { - int tasty; + /* feeding it treats makes it tamer */ + if (mtmp->mtame && obj) { + int tasty; - if (mtmp->mcanmove && !mtmp->mconf && !mtmp->meating && - ((tasty = dogfood(mtmp, obj)) == DOGFOOD || - (tasty <= ACCFOOD && EDOG(mtmp)->hungrytime <= monstermoves))) { - /* pet will "catch" and eat this thrown food */ - if (canseemon(mtmp)) { - boolean big_corpse = (obj->otyp == CORPSE && - obj->corpsenm >= LOW_PM && - mons[obj->corpsenm].msize > mtmp->data->msize); - pline("%s catches %s%s", - Monnam(mtmp), the(xname(obj)), - !big_corpse ? "." : ", or vice versa!"); - } else if (cansee(mtmp->mx,mtmp->my)) - pline("%s.", Tobjnam(obj, "stop")); - /* dog_eat expects a floor object */ - place_object(obj, mtmp->mx, mtmp->my); - (void) dog_eat(mtmp, obj, mtmp->mx, mtmp->my, FALSE); - /* eating might have killed it, but that doesn't matter here; - a non-null result suppresses "miss" message for thrown - food and also implies that the object has been deleted */ - return TRUE; - } else - return FALSE; - } + if (mtmp->mcanmove && !mtmp->mconf && !mtmp->meating + && ((tasty = dogfood(mtmp, obj)) == DOGFOOD + || (tasty <= ACCFOOD + && EDOG(mtmp)->hungrytime <= monstermoves))) { + /* pet will "catch" and eat this thrown food */ + if (canseemon(mtmp)) { + boolean big_corpse = + (obj->otyp == CORPSE && obj->corpsenm >= LOW_PM + && mons[obj->corpsenm].msize > mtmp->data->msize); + pline("%s catches %s%s", Monnam(mtmp), the(xname(obj)), + !big_corpse ? "." : ", or vice versa!"); + } else if (cansee(mtmp->mx, mtmp->my)) + pline("%s.", Tobjnam(obj, "stop")); + /* dog_eat expects a floor object */ + place_object(obj, mtmp->mx, mtmp->my); + (void) dog_eat(mtmp, obj, mtmp->mx, mtmp->my, FALSE); + /* eating might have killed it, but that doesn't matter here; + a non-null result suppresses "miss" message for thrown + food and also implies that the object has been deleted */ + return TRUE; + } else + return FALSE; + } - if (mtmp->mtame || !mtmp->mcanmove || - /* monsters with conflicting structures cannot be tamed */ - mtmp->isshk || mtmp->isgd || mtmp->ispriest || mtmp->isminion || - is_covetous(mtmp->data) || is_human(mtmp->data) || - (is_demon(mtmp->data) && !is_demon(youmonst.data)) || - (obj && dogfood(mtmp, obj) >= MANFOOD)) return FALSE; + if (mtmp->mtame || !mtmp->mcanmove || + /* monsters with conflicting structures cannot be tamed */ + mtmp->isshk || mtmp->isgd || mtmp->ispriest || mtmp->isminion + || is_covetous(mtmp->data) || is_human(mtmp->data) + || (is_demon(mtmp->data) && !is_demon(youmonst.data)) + || (obj && dogfood(mtmp, obj) >= MANFOOD)) + return FALSE; - if (mtmp->m_id == quest_status.leader_m_id) - return FALSE; + if (mtmp->m_id == quest_status.leader_m_id) + return FALSE; - /* add the pet extension */ - newedog(mtmp); - initedog(mtmp); + /* add the pet extension */ + newedog(mtmp); + initedog(mtmp); - if (obj) { /* thrown food */ - /* defer eating until the edog extension has been set up */ - place_object(obj, mtmp->mx, mtmp->my); /* put on floor */ - /* devour the food (might grow into larger, genocided monster) */ - if (dog_eat(mtmp, obj, mtmp->mx, mtmp->my, TRUE) == 2) - return TRUE; /* oops, it died... */ - /* `obj' is now obsolete */ - } + if (obj) { /* thrown food */ + /* defer eating until the edog extension has been set up */ + place_object(obj, mtmp->mx, mtmp->my); /* put on floor */ + /* devour the food (might grow into larger, genocided monster) */ + if (dog_eat(mtmp, obj, mtmp->mx, mtmp->my, TRUE) == 2) + return TRUE; /* oops, it died... */ + /* `obj' is now obsolete */ + } - newsym(mtmp->mx, mtmp->my); - if (attacktype(mtmp->data, AT_WEAP)) { - mtmp->weapon_check = NEED_HTH_WEAPON; - (void) mon_wield_item(mtmp); - } - return TRUE; + newsym(mtmp->mx, mtmp->my); + if (attacktype(mtmp->data, AT_WEAP)) { + mtmp->weapon_check = NEED_HTH_WEAPON; + (void) mon_wield_item(mtmp); + } + return TRUE; } /* @@ -915,62 +961,64 @@ boolean was_dead; finish_meating(mtmp); - if (!mtmp->mtame) return; + if (!mtmp->mtame) + return; edog = !mtmp->isminion ? EDOG(mtmp) : 0; /* if monster was starving when it died, undo that now */ if (edog && edog->mhpmax_penalty) { - mtmp->mhpmax += edog->mhpmax_penalty; - mtmp->mhp += edog->mhpmax_penalty; /* heal it */ - edog->mhpmax_penalty = 0; + mtmp->mhpmax += edog->mhpmax_penalty; + mtmp->mhp += edog->mhpmax_penalty; /* heal it */ + edog->mhpmax_penalty = 0; } if (edog && (edog->killed_by_u == 1 || edog->abuse > 2)) { - mtmp->mpeaceful = mtmp->mtame = 0; - if (edog->abuse >= 0 && edog->abuse < 10) - if (!rn2(edog->abuse + 1)) mtmp->mpeaceful = 1; - if(!quietly && cansee(mtmp->mx, mtmp->my)) { - if (haseyes(youmonst.data)) { - if (haseyes(mtmp->data)) - pline("%s %s to look you in the %s.", - Monnam(mtmp), - mtmp->mpeaceful ? "seems unable" : - "refuses", - body_part(EYE)); - else - pline("%s avoids your gaze.", - Monnam(mtmp)); - } - } + mtmp->mpeaceful = mtmp->mtame = 0; + if (edog->abuse >= 0 && edog->abuse < 10) + if (!rn2(edog->abuse + 1)) + mtmp->mpeaceful = 1; + if (!quietly && cansee(mtmp->mx, mtmp->my)) { + if (haseyes(youmonst.data)) { + if (haseyes(mtmp->data)) + pline("%s %s to look you in the %s.", Monnam(mtmp), + mtmp->mpeaceful ? "seems unable" : "refuses", + body_part(EYE)); + else + pline("%s avoids your gaze.", Monnam(mtmp)); + } + } } else { - /* chance it goes wild anyway - Pet Semetary */ - mtmp->mtame = rn2(mtmp->mtame + 1); - if (!mtmp->mtame) mtmp->mpeaceful = rn2(2); + /* chance it goes wild anyway - Pet Semetary */ + mtmp->mtame = rn2(mtmp->mtame + 1); + if (!mtmp->mtame) + mtmp->mpeaceful = rn2(2); } if (!mtmp->mtame) { - if (!quietly && canspotmon(mtmp)) - pline("%s %s.", Monnam(mtmp), - mtmp->mpeaceful ? "is no longer tame" : "has become feral"); - newsym(mtmp->mx, mtmp->my); - /* a life-saved monster might be leashed; - don't leave it that way if it's no longer tame */ - if (mtmp->mleashed) m_unleash(mtmp, TRUE); - if (mtmp == u.usteed) dismount_steed(DISMOUNT_THROWN); + if (!quietly && canspotmon(mtmp)) + pline("%s %s.", Monnam(mtmp), + mtmp->mpeaceful ? "is no longer tame" : "has become feral"); + newsym(mtmp->mx, mtmp->my); + /* a life-saved monster might be leashed; + don't leave it that way if it's no longer tame */ + if (mtmp->mleashed) + m_unleash(mtmp, TRUE); + if (mtmp == u.usteed) + dismount_steed(DISMOUNT_THROWN); } else if (edog) { - /* it's still a pet; start a clean pet-slate now */ - edog->revivals++; - edog->killed_by_u = 0; - edog->abuse = 0; - edog->ogoal.x = edog->ogoal.y = -1; - if (was_dead || edog->hungrytime < monstermoves + 500L) - edog->hungrytime = monstermoves + 500L; - if (was_dead) { - edog->droptime = 0L; - edog->dropdist = 10000; - edog->whistletime = 0L; - edog->apport = 5; - } /* else lifesaved, so retain current values */ + /* it's still a pet; start a clean pet-slate now */ + edog->revivals++; + edog->killed_by_u = 0; + edog->abuse = 0; + edog->ogoal.x = edog->ogoal.y = -1; + if (was_dead || edog->hungrytime < monstermoves + 500L) + edog->hungrytime = monstermoves + 500L; + if (was_dead) { + edog->droptime = 0L; + edog->dropdist = 10000; + edog->whistletime = 0L; + edog->apport = 5; + } /* else lifesaved, so retain current values */ } } @@ -978,25 +1026,31 @@ void abuse_dog(mtmp) struct monst *mtmp; { - if (!mtmp->mtame) return; + if (!mtmp->mtame) + return; - if (Aggravate_monster || Conflict) mtmp->mtame /=2; - else mtmp->mtame--; + if (Aggravate_monster || Conflict) + mtmp->mtame /= 2; + else + mtmp->mtame--; - if (mtmp->mtame && !mtmp->isminion) - EDOG(mtmp)->abuse++; + if (mtmp->mtame && !mtmp->isminion) + EDOG(mtmp)->abuse++; - if (!mtmp->mtame && mtmp->mleashed) - m_unleash(mtmp, TRUE); + if (!mtmp->mtame && mtmp->mleashed) + m_unleash(mtmp, TRUE); - /* don't make a sound if pet is in the middle of leaving the level */ - /* newsym isn't necessary in this case either */ - if (mtmp->mx != 0) { - if (mtmp->mtame && rn2(mtmp->mtame)) yelp(mtmp); - else growl(mtmp); /* give them a moment's worry */ - - if (!mtmp->mtame) newsym(mtmp->mx, mtmp->my); - } + /* don't make a sound if pet is in the middle of leaving the level */ + /* newsym isn't necessary in this case either */ + if (mtmp->mx != 0) { + if (mtmp->mtame && rn2(mtmp->mtame)) + yelp(mtmp); + else + growl(mtmp); /* give them a moment's worry */ + + if (!mtmp->mtame) + newsym(mtmp->mx, mtmp->my); + } } /*dog.c*/ diff --git a/src/dogmove.c b/src/dogmove.c index bfcf9fef3..1d3a5187c 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dogmove.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dogmove.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.51 $ */ /* NetHack 3.6 dogmove.c $Date: 2012/02/10 09:29:28 $ $Revision: 1.35 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,13 +9,15 @@ extern boolean notonhead; -STATIC_DCL boolean FDECL(dog_hunger,(struct monst *,struct edog *)); -STATIC_DCL int FDECL(dog_invent,(struct monst *,struct edog *,int)); -STATIC_DCL int FDECL(dog_goal,(struct monst *,struct edog *,int,int,int)); +STATIC_DCL boolean FDECL(dog_hunger, (struct monst *, struct edog *)); +STATIC_DCL int FDECL(dog_invent, (struct monst *, struct edog *, int)); +STATIC_DCL int FDECL(dog_goal, + (struct monst *, struct edog *, int, int, int)); -STATIC_DCL boolean FDECL(can_reach_location,(struct monst *,XCHAR_P,XCHAR_P, - XCHAR_P,XCHAR_P)); -STATIC_DCL boolean FDECL(could_reach_item,(struct monst *, XCHAR_P,XCHAR_P)); +STATIC_DCL boolean FDECL(can_reach_location, (struct monst *, XCHAR_P, + XCHAR_P, XCHAR_P, XCHAR_P)); +STATIC_DCL boolean +FDECL(could_reach_item, (struct monst *, XCHAR_P, XCHAR_P)); STATIC_DCL void FDECL(quickmimic, (struct monst *)); /* pick a carried item for pet to drop */ @@ -23,93 +25,103 @@ struct obj * droppables(mon) struct monst *mon; { - struct obj *obj, *wep, - dummy, *pickaxe, *unihorn, *key; + struct obj *obj, *wep, dummy, *pickaxe, *unihorn, *key; dummy = zeroobj; - dummy.otyp = GOLD_PIECE; /* not STRANGE_OBJECT or tools of interest */ + dummy.otyp = GOLD_PIECE; /* not STRANGE_OBJECT or tools of interest */ dummy.oartifact = 1; /* so real artifact won't override "don't keep it" */ - pickaxe = unihorn = key = (struct obj *)0; + pickaxe = unihorn = key = (struct obj *) 0; wep = MON_WEP(mon); if (is_animal(mon->data) || mindless(mon->data)) { - /* won't hang on to any objects of these types */ - pickaxe = unihorn = key = &dummy; /* act as if already have them */ + /* won't hang on to any objects of these types */ + pickaxe = unihorn = key = &dummy; /* act as if already have them */ } else { - /* don't hang on to pick-axe if can't use one or don't need one */ - if (!tunnels(mon->data) || !needspick(mon->data)) pickaxe = &dummy; - /* don't hang on to key if can't open doors */ - if (nohands(mon->data) || verysmall(mon->data)) key = &dummy; + /* don't hang on to pick-axe if can't use one or don't need one */ + if (!tunnels(mon->data) || !needspick(mon->data)) + pickaxe = &dummy; + /* don't hang on to key if can't open doors */ + if (nohands(mon->data) || verysmall(mon->data)) + key = &dummy; } if (wep) { - if (is_pick(wep)) pickaxe = wep; - if (wep->otyp == UNICORN_HORN) unihorn = wep; - /* don't need any wielded check for keys... */ + if (is_pick(wep)) + pickaxe = wep; + if (wep->otyp == UNICORN_HORN) + unihorn = wep; + /* don't need any wielded check for keys... */ } for (obj = mon->minvent; obj; obj = obj->nobj) { - switch (obj->otyp) { - case DWARVISH_MATTOCK: - /* reject mattock if couldn't wield it */ - if (which_armor(mon, W_ARMS)) break; - /* keep mattock in preference to pick unless pick is already - wielded or is an artifact and mattock isn't */ - if (pickaxe && pickaxe->otyp == PICK_AXE && - pickaxe != wep && (!pickaxe->oartifact || obj->oartifact)) - return pickaxe; /* drop the one we earlier decided to keep */ - /*FALLTHRU*/ - case PICK_AXE: - if (!pickaxe || (obj->oartifact && !pickaxe->oartifact)) { - if (pickaxe) return pickaxe; - pickaxe = obj; /* keep this digging tool */ - continue; - } - break; + switch (obj->otyp) { + case DWARVISH_MATTOCK: + /* reject mattock if couldn't wield it */ + if (which_armor(mon, W_ARMS)) + break; + /* keep mattock in preference to pick unless pick is already + wielded or is an artifact and mattock isn't */ + if (pickaxe && pickaxe->otyp == PICK_AXE && pickaxe != wep + && (!pickaxe->oartifact || obj->oartifact)) + return pickaxe; /* drop the one we earlier decided to keep */ + /*FALLTHRU*/ + case PICK_AXE: + if (!pickaxe || (obj->oartifact && !pickaxe->oartifact)) { + if (pickaxe) + return pickaxe; + pickaxe = obj; /* keep this digging tool */ + continue; + } + break; - case UNICORN_HORN: - /* reject cursed unicorn horns */ - if (obj->cursed) break; - /* keep artifact unihorn in preference to ordinary one */ - if (!unihorn || (obj->oartifact && !unihorn->oartifact)) { - if (unihorn) return unihorn; - unihorn = obj; /* keep this unicorn horn */ - continue; - } - break; + case UNICORN_HORN: + /* reject cursed unicorn horns */ + if (obj->cursed) + break; + /* keep artifact unihorn in preference to ordinary one */ + if (!unihorn || (obj->oartifact && !unihorn->oartifact)) { + if (unihorn) + return unihorn; + unihorn = obj; /* keep this unicorn horn */ + continue; + } + break; - case SKELETON_KEY: - /* keep key in preference to lock-pick */ - if (key && key->otyp == LOCK_PICK && - (!key->oartifact || obj->oartifact)) - return key; /* drop the one we earlier decided to keep */ - /*FALLTHRU*/ - case LOCK_PICK: - /* keep lock-pick in preference to credit card */ - if (key && key->otyp == CREDIT_CARD && - (!key->oartifact || obj->oartifact)) - return key; - /*FALLTHRU*/ - case CREDIT_CARD: - if (!key || (obj->oartifact && !key->oartifact)) { - if (key) return key; - key = obj; /* keep this unlocking tool */ - continue; - } - break; + case SKELETON_KEY: + /* keep key in preference to lock-pick */ + if (key && key->otyp == LOCK_PICK + && (!key->oartifact || obj->oartifact)) + return key; /* drop the one we earlier decided to keep */ + /*FALLTHRU*/ + case LOCK_PICK: + /* keep lock-pick in preference to credit card */ + if (key && key->otyp == CREDIT_CARD + && (!key->oartifact || obj->oartifact)) + return key; + /*FALLTHRU*/ + case CREDIT_CARD: + if (!key || (obj->oartifact && !key->oartifact)) { + if (key) + return key; + key = obj; /* keep this unlocking tool */ + continue; + } + break; - default: - break; - } + default: + break; + } - if (!obj->owornmask && obj != wep) return obj; + if (!obj->owornmask && obj != wep) + return obj; } - return (struct obj *)0; /* don't drop anything */ + return (struct obj *) 0; /* don't drop anything */ } -static NEARDATA const char nofetch[] = { BALL_CLASS, CHAIN_CLASS, ROCK_CLASS, 0 }; +static NEARDATA const char nofetch[] = { BALL_CLASS, CHAIN_CLASS, ROCK_CLASS, + 0 }; -STATIC_VAR xchar gtyp, gx, gy; /* type and position of dog's current goal */ +STATIC_VAR xchar gtyp, gx, gy; /* type and position of dog's current goal */ STATIC_PTR void FDECL(wantdoor, (int, int, genericptr_t)); @@ -117,11 +129,12 @@ boolean cursed_object_at(x, y) int x, y; { - struct obj *otmp; + struct obj *otmp; - for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (otmp->cursed) return TRUE; - return FALSE; + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (otmp->cursed) + return TRUE; + return FALSE; } int @@ -129,166 +142,185 @@ dog_nutrition(mtmp, obj) struct monst *mtmp; struct obj *obj; { - int nutrit; + int nutrit; - /* - * It is arbitrary that the pet takes the same length of time to eat - * as a human, but gets more nutritional value. - */ - if (obj->oclass == FOOD_CLASS) { - if(obj->otyp == CORPSE) { - mtmp->meating = 3 + (mons[obj->corpsenm].cwt >> 6); - nutrit = mons[obj->corpsenm].cnutrit; - } else { - mtmp->meating = objects[obj->otyp].oc_delay; - nutrit = objects[obj->otyp].oc_nutrition; - } - switch(mtmp->data->msize) { - case MZ_TINY: nutrit *= 8; break; - case MZ_SMALL: nutrit *= 6; break; - default: - case MZ_MEDIUM: nutrit *= 5; break; - case MZ_LARGE: nutrit *= 4; break; - case MZ_HUGE: nutrit *= 3; break; - case MZ_GIGANTIC: nutrit *= 2; break; - } - if(obj->oeaten) { - mtmp->meating = eaten_stat(mtmp->meating, obj); - nutrit = eaten_stat(nutrit, obj); - } - } else if (obj->oclass == COIN_CLASS) { - mtmp->meating = (int)(obj->quan/2000) + 1; - if (mtmp->meating < 0) mtmp->meating = 1; - nutrit = (int)(obj->quan/20); - if (nutrit < 0) nutrit = 0; - } else { - /* Unusual pet such as gelatinous cube eating odd stuff. - * meating made consistent with wild monsters in mon.c. - * nutrit made consistent with polymorphed player nutrit in - * eat.c. (This also applies to pets eating gold.) - */ - mtmp->meating = obj->owt/20 + 1; - nutrit = 5*objects[obj->otyp].oc_nutrition; - } - return nutrit; + /* + * It is arbitrary that the pet takes the same length of time to eat + * as a human, but gets more nutritional value. + */ + if (obj->oclass == FOOD_CLASS) { + if (obj->otyp == CORPSE) { + mtmp->meating = 3 + (mons[obj->corpsenm].cwt >> 6); + nutrit = mons[obj->corpsenm].cnutrit; + } else { + mtmp->meating = objects[obj->otyp].oc_delay; + nutrit = objects[obj->otyp].oc_nutrition; + } + switch (mtmp->data->msize) { + case MZ_TINY: + nutrit *= 8; + break; + case MZ_SMALL: + nutrit *= 6; + break; + default: + case MZ_MEDIUM: + nutrit *= 5; + break; + case MZ_LARGE: + nutrit *= 4; + break; + case MZ_HUGE: + nutrit *= 3; + break; + case MZ_GIGANTIC: + nutrit *= 2; + break; + } + if (obj->oeaten) { + mtmp->meating = eaten_stat(mtmp->meating, obj); + nutrit = eaten_stat(nutrit, obj); + } + } else if (obj->oclass == COIN_CLASS) { + mtmp->meating = (int) (obj->quan / 2000) + 1; + if (mtmp->meating < 0) + mtmp->meating = 1; + nutrit = (int) (obj->quan / 20); + if (nutrit < 0) + nutrit = 0; + } else { + /* Unusual pet such as gelatinous cube eating odd stuff. + * meating made consistent with wild monsters in mon.c. + * nutrit made consistent with polymorphed player nutrit in + * eat.c. (This also applies to pets eating gold.) + */ + mtmp->meating = obj->owt / 20 + 1; + nutrit = 5 * objects[obj->otyp].oc_nutrition; + } + return nutrit; } /* returns 2 if pet dies, otherwise 1 */ int dog_eat(mtmp, obj, x, y, devour) register struct monst *mtmp; -register struct obj *obj; /* if unpaid, then thrown or kicked by hero */ -int x, y; /* dog's starting location, might be different from current */ +register struct obj *obj; /* if unpaid, then thrown or kicked by hero */ +int x, y; /* dog's starting location, might be different from current */ boolean devour; { - register struct edog *edog = EDOG(mtmp); - boolean poly, grow, heal, slimer, deadmimic; - int nutrit; - long oprice; - char objnambuf[BUFSZ]; + register struct edog *edog = EDOG(mtmp); + boolean poly, grow, heal, slimer, deadmimic; + int nutrit; + long oprice; + char objnambuf[BUFSZ]; - objnambuf[0] = '\0'; - if(edog->hungrytime < monstermoves) - edog->hungrytime = monstermoves; - nutrit = dog_nutrition(mtmp, obj); + objnambuf[0] = '\0'; + if (edog->hungrytime < monstermoves) + edog->hungrytime = monstermoves; + nutrit = dog_nutrition(mtmp, obj); - deadmimic = (obj->otyp == CORPSE && - (obj->corpsenm == PM_SMALL_MIMIC || - obj->corpsenm == PM_LARGE_MIMIC || - obj->corpsenm == PM_GIANT_MIMIC)); - slimer = (obj->otyp == CORPSE && obj->corpsenm == PM_GREEN_SLIME); - poly = polyfodder(obj); - grow = mlevelgain(obj); - heal = mhealup(obj); + deadmimic = (obj->otyp == CORPSE && (obj->corpsenm == PM_SMALL_MIMIC + || obj->corpsenm == PM_LARGE_MIMIC + || obj->corpsenm == PM_GIANT_MIMIC)); + slimer = (obj->otyp == CORPSE && obj->corpsenm == PM_GREEN_SLIME); + poly = polyfodder(obj); + grow = mlevelgain(obj); + heal = mhealup(obj); - if (devour) { - if (mtmp->meating > 1) mtmp->meating /= 2; - if (nutrit > 1) nutrit = (nutrit * 3) / 4; - } - edog->hungrytime += nutrit; - mtmp->mconf = 0; - if (edog->mhpmax_penalty) { - /* no longer starving */ - mtmp->mhpmax += edog->mhpmax_penalty; - edog->mhpmax_penalty = 0; - } - if (mtmp->mflee && mtmp->mfleetim > 1) mtmp->mfleetim /= 2; - if (mtmp->mtame < 20) mtmp->mtame++; - if (x != mtmp->mx || y != mtmp->my) { /* moved & ate on same turn */ - newsym(x, y); - newsym(mtmp->mx, mtmp->my); - } + if (devour) { + if (mtmp->meating > 1) + mtmp->meating /= 2; + if (nutrit > 1) + nutrit = (nutrit * 3) / 4; + } + edog->hungrytime += nutrit; + mtmp->mconf = 0; + if (edog->mhpmax_penalty) { + /* no longer starving */ + mtmp->mhpmax += edog->mhpmax_penalty; + edog->mhpmax_penalty = 0; + } + if (mtmp->mflee && mtmp->mfleetim > 1) + mtmp->mfleetim /= 2; + if (mtmp->mtame < 20) + mtmp->mtame++; + if (x != mtmp->mx || y != mtmp->my) { /* moved & ate on same turn */ + newsym(x, y); + newsym(mtmp->mx, mtmp->my); + } - /* food items are eaten one at a time; entire stack for other stuff */ - if (obj->quan > 1L && obj->oclass == FOOD_CLASS) - obj = splitobj(obj, 1L); - if (obj->unpaid) iflags.suppress_price++; - if (is_pool(x, y) && !Underwater) { - /* Don't print obj */ - /* TODO: Reveal presence of sea monster (especially sharks) */ - } else { - /* food is at monster's current location, ; - was monster's location at start of this turn; - they might be the same but will be different when - the monster is moving+eating on same turn */ - boolean seeobj = cansee(mtmp->mx, mtmp->my), - sawpet = cansee(x, y) && mon_visible(mtmp); + /* food items are eaten one at a time; entire stack for other stuff */ + if (obj->quan > 1L && obj->oclass == FOOD_CLASS) + obj = splitobj(obj, 1L); + if (obj->unpaid) + iflags.suppress_price++; + if (is_pool(x, y) && !Underwater) { + /* Don't print obj */ + /* TODO: Reveal presence of sea monster (especially sharks) */ + } else { + /* food is at monster's current location, ; + was monster's location at start of this turn; + they might be the same but will be different when + the monster is moving+eating on same turn */ + boolean seeobj = cansee(mtmp->mx, mtmp->my), + sawpet = cansee(x, y) && mon_visible(mtmp); - /* Observe the action if either the food location or the pet - itself is in view. When pet which was in view moves to an - unseen spot to eat the food there, avoid referring to that - pet as "it". However, we want "it" if invisible/unsensed - pet eats visible food. */ - if (sawpet || (seeobj && canspotmon(mtmp))) { - if (tunnels(mtmp->data)) - pline("%s digs in.", noit_Monnam(mtmp)); - else - pline("%s %s %s.", noit_Monnam(mtmp), - devour ? "devours" : "eats", distant_name(obj, doname)); - } else if (seeobj) - pline("It %s %s.", devour ? "devours" : "eats", - distant_name(obj, doname)); - } - if (obj->unpaid) { - Strcpy(objnambuf, xname(obj)); - iflags.suppress_price--; - } - /* It's a reward if it's DOGFOOD and the player dropped/threw it. */ - /* We know the player had it if invlet is set -dlc */ - if(dogfood(mtmp,obj) == DOGFOOD && obj->invlet) + /* Observe the action if either the food location or the pet + itself is in view. When pet which was in view moves to an + unseen spot to eat the food there, avoid referring to that + pet as "it". However, we want "it" if invisible/unsensed + pet eats visible food. */ + if (sawpet || (seeobj && canspotmon(mtmp))) { + if (tunnels(mtmp->data)) + pline("%s digs in.", noit_Monnam(mtmp)); + else + pline("%s %s %s.", noit_Monnam(mtmp), + devour ? "devours" : "eats", distant_name(obj, doname)); + } else if (seeobj) + pline("It %s %s.", devour ? "devours" : "eats", + distant_name(obj, doname)); + } + if (obj->unpaid) { + Strcpy(objnambuf, xname(obj)); + iflags.suppress_price--; + } + /* It's a reward if it's DOGFOOD and the player dropped/threw it. */ + /* We know the player had it if invlet is set -dlc */ + if (dogfood(mtmp, obj) == DOGFOOD && obj->invlet) #ifdef LINT - edog->apport = 0; + edog->apport = 0; #else - edog->apport += (int)(200L/ - ((long)edog->dropdist + monstermoves - edog->droptime)); + edog->apport += (int) (200L / ((long) edog->dropdist + monstermoves + - edog->droptime)); #endif - if (mtmp->data == &mons[PM_RUST_MONSTER] && obj->oerodeproof) { - /* The object's rustproofing is gone now */ - if (obj->unpaid) costly_alteration(obj, COST_DEGRD); - obj->oerodeproof = 0; - mtmp->mstun = 1; - if (canseemon(mtmp) && flags.verbose) { - pline("%s spits %s out in disgust!", - Monnam(mtmp), distant_name(obj,doname)); - } - } else if (obj == uball) { - unpunish(); - delobj(obj); /* we assume this can't be unpaid */ - } else if (obj == uchain) { - unpunish(); - } else { - if (obj->unpaid) { - /* edible item owned by shop has been thrown or kicked - by hero and caught by tame or food-tameable monst */ - oprice = unpaid_cost(obj, TRUE); - pline("That %s will cost you %ld %s.", - objnambuf, oprice, currency(oprice)); - /* delobj->obfree will handle actual shop billing update */ - } - delobj(obj); - } + if (mtmp->data == &mons[PM_RUST_MONSTER] && obj->oerodeproof) { + /* The object's rustproofing is gone now */ + if (obj->unpaid) + costly_alteration(obj, COST_DEGRD); + obj->oerodeproof = 0; + mtmp->mstun = 1; + if (canseemon(mtmp) && flags.verbose) { + pline("%s spits %s out in disgust!", Monnam(mtmp), + distant_name(obj, doname)); + } + } else if (obj == uball) { + unpunish(); + delobj(obj); /* we assume this can't be unpaid */ + } else if (obj == uchain) { + unpunish(); + } else { + if (obj->unpaid) { + /* edible item owned by shop has been thrown or kicked + by hero and caught by tame or food-tameable monst */ + oprice = unpaid_cost(obj, TRUE); + pline("That %s will cost you %ld %s.", objnambuf, oprice, + currency(oprice)); + /* delobj->obfree will handle actual shop billing update */ + } + delobj(obj); + } -#if 0 /* pet is eating, so slime recovery is not feasible... */ +#if 0 /* pet is eating, so slime recovery is not feasible... */ /* turning into slime might be cureable */ if (slimer && munslime(mtmp, FALSE)) { /* but the cure (fire directed at self) might be fatal */ @@ -297,19 +329,22 @@ boolean devour; } #endif - if (poly || slimer) { - struct permonst *ptr = slimer ? &mons[PM_GREEN_SLIME] : 0; + if (poly || slimer) { + struct permonst *ptr = slimer ? &mons[PM_GREEN_SLIME] : 0; - (void) newcham(mtmp, ptr, FALSE, cansee(mtmp->mx, mtmp->my)); - } + (void) newcham(mtmp, ptr, FALSE, cansee(mtmp->mx, mtmp->my)); + } - /* limit "instant" growth to prevent potential abuse */ - if (grow && (int) mtmp->m_lev < (int)mtmp->data->mlevel + 15) { - if (!grow_up(mtmp, (struct monst *)0)) return 2; - } - if (heal) mtmp->mhp = mtmp->mhpmax; - if (deadmimic) quickmimic(mtmp); - return 1; + /* limit "instant" growth to prevent potential abuse */ + if (grow && (int) mtmp->m_lev < (int) mtmp->data->mlevel + 15) { + if (!grow_up(mtmp, (struct monst *) 0)) + return 2; + } + if (heal) + mtmp->mhp = mtmp->mhpmax; + if (deadmimic) + quickmimic(mtmp); + return 1; } /* hunger effects -- returns TRUE on starvation */ @@ -318,40 +353,41 @@ dog_hunger(mtmp, edog) register struct monst *mtmp; register struct edog *edog; { - if (monstermoves > edog->hungrytime + 500) { - if (!carnivorous(mtmp->data) && !herbivorous(mtmp->data)) { - edog->hungrytime = monstermoves + 500; - /* but not too high; it might polymorph */ - } else if (!edog->mhpmax_penalty) { - /* starving pets are limited in healing */ - int newmhpmax = mtmp->mhpmax / 3; - mtmp->mconf = 1; - edog->mhpmax_penalty = mtmp->mhpmax - newmhpmax; - mtmp->mhpmax = newmhpmax; - if (mtmp->mhp > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - if (mtmp->mhp < 1) goto dog_died; - if (cansee(mtmp->mx, mtmp->my)) - pline("%s is confused from hunger.", Monnam(mtmp)); - else if (couldsee(mtmp->mx, mtmp->my)) - beg(mtmp); - else - You_feel("worried about %s.", y_monnam(mtmp)); - stop_occupation(); - } else if (monstermoves > edog->hungrytime + 750 || mtmp->mhp < 1) { - dog_died: - if (mtmp->mleashed && mtmp != u.usteed) - Your("leash goes slack."); - else if (cansee(mtmp->mx, mtmp->my)) - pline("%s starves.", Monnam(mtmp)); - else - You_feel("%s for a moment.", - Hallucination ? "bummed" : "sad"); - mondied(mtmp); - return(TRUE); - } - } - return(FALSE); + if (monstermoves > edog->hungrytime + 500) { + if (!carnivorous(mtmp->data) && !herbivorous(mtmp->data)) { + edog->hungrytime = monstermoves + 500; + /* but not too high; it might polymorph */ + } else if (!edog->mhpmax_penalty) { + /* starving pets are limited in healing */ + int newmhpmax = mtmp->mhpmax / 3; + mtmp->mconf = 1; + edog->mhpmax_penalty = mtmp->mhpmax - newmhpmax; + mtmp->mhpmax = newmhpmax; + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + if (mtmp->mhp < 1) + goto dog_died; + if (cansee(mtmp->mx, mtmp->my)) + pline("%s is confused from hunger.", Monnam(mtmp)); + else if (couldsee(mtmp->mx, mtmp->my)) + beg(mtmp); + else + You_feel("worried about %s.", y_monnam(mtmp)); + stop_occupation(); + } else if (monstermoves > edog->hungrytime + 750 || mtmp->mhp < 1) { + dog_died: + if (mtmp->mleashed && mtmp != u.usteed) + Your("leash goes slack."); + else if (cansee(mtmp->mx, mtmp->my)) + pline("%s starves.", Monnam(mtmp)); + else + You_feel("%s for a moment.", + Hallucination ? "bummed" : "sad"); + mondied(mtmp); + return (TRUE); + } + } + return (FALSE); } /* do something with object (drop, pick up, eat) at current position @@ -363,61 +399,63 @@ register struct monst *mtmp; register struct edog *edog; int udist; { - register int omx, omy; - struct obj *obj; + register int omx, omy; + struct obj *obj; - if (mtmp->msleeping || !mtmp->mcanmove) return(0); + if (mtmp->msleeping || !mtmp->mcanmove) + return (0); - omx = mtmp->mx; - omy = mtmp->my; + omx = mtmp->mx; + omy = mtmp->my; - /* if we are carrying something then we drop it (perhaps near @) */ - /* Note: if apport == 1 then our behaviour is independent of udist */ - /* Use udist+1 so steed won't cause divide by zero */ - if (droppables(mtmp)) { - if (!rn2(udist+1) || !rn2(edog->apport)) - if(rn2(10) < edog->apport){ - relobj(mtmp, (int)mtmp->minvis, TRUE); - if(edog->apport > 1) edog->apport--; - edog->dropdist = udist; /* hpscdi!jon */ - edog->droptime = monstermoves; - } - } else { - if((obj=level.objects[omx][omy]) && !index(nofetch,obj->oclass) + /* if we are carrying something then we drop it (perhaps near @) */ + /* Note: if apport == 1 then our behaviour is independent of udist */ + /* Use udist+1 so steed won't cause divide by zero */ + if (droppables(mtmp)) { + if (!rn2(udist + 1) || !rn2(edog->apport)) + if (rn2(10) < edog->apport) { + relobj(mtmp, (int) mtmp->minvis, TRUE); + if (edog->apport > 1) + edog->apport--; + edog->dropdist = udist; /* hpscdi!jon */ + edog->droptime = monstermoves; + } + } else { + if ((obj = level.objects[omx][omy]) && !index(nofetch, obj->oclass) #ifdef MAIL - && obj->otyp != SCR_MAIL + && obj->otyp != SCR_MAIL #endif - ){ - int edible = dogfood(mtmp, obj); + ) { + int edible = dogfood(mtmp, obj); - if ((edible <= CADAVER || - /* starving pet is more aggressive about eating */ - (edog->mhpmax_penalty && edible == ACCFOOD)) && - could_reach_item(mtmp, obj->ox, obj->oy)) - return dog_eat(mtmp, obj, omx, omy, FALSE); + if ((edible <= CADAVER || + /* starving pet is more aggressive about eating */ + (edog->mhpmax_penalty && edible == ACCFOOD)) + && could_reach_item(mtmp, obj->ox, obj->oy)) + return dog_eat(mtmp, obj, omx, omy, FALSE); - if(can_carry(mtmp, obj) && !obj->cursed && - could_reach_item(mtmp, obj->ox, obj->oy)) { - if(rn2(20) < edog->apport+3) { - if (rn2(udist) || !rn2(edog->apport)) { - if (cansee(omx, omy) && flags.verbose) - pline("%s picks up %s.", Monnam(mtmp), - distant_name(obj, doname)); - obj_extract_self(obj); - newsym(omx,omy); - (void) mpickobj(mtmp,obj); - if (attacktype(mtmp->data, AT_WEAP) && - mtmp->weapon_check == NEED_WEAPON) { - mtmp->weapon_check = NEED_HTH_WEAPON; - (void) mon_wield_item(mtmp); - } - m_dowear(mtmp, FALSE); - } - } - } - } - } - return 0; + if (can_carry(mtmp, obj) && !obj->cursed + && could_reach_item(mtmp, obj->ox, obj->oy)) { + if (rn2(20) < edog->apport + 3) { + if (rn2(udist) || !rn2(edog->apport)) { + if (cansee(omx, omy) && flags.verbose) + pline("%s picks up %s.", Monnam(mtmp), + distant_name(obj, doname)); + obj_extract_self(obj); + newsym(omx, omy); + (void) mpickobj(mtmp, obj); + if (attacktype(mtmp->data, AT_WEAP) + && mtmp->weapon_check == NEED_WEAPON) { + mtmp->weapon_check = NEED_HTH_WEAPON; + (void) mon_wield_item(mtmp); + } + m_dowear(mtmp, FALSE); + } + } + } + } + } + return 0; } /* set dog's goal -- gtyp, gx, gy @@ -429,465 +467,493 @@ register struct monst *mtmp; struct edog *edog; int after, udist, whappr; { - register int omx, omy; - boolean in_masters_sight, dog_has_minvent; - register struct obj *obj; - xchar otyp; - int appr; + register int omx, omy; + boolean in_masters_sight, dog_has_minvent; + register struct obj *obj; + xchar otyp; + int appr; - /* Steeds don't move on their own will */ - if (mtmp == u.usteed) - return (-2); + /* Steeds don't move on their own will */ + if (mtmp == u.usteed) + return (-2); - omx = mtmp->mx; - omy = mtmp->my; + omx = mtmp->mx; + omy = mtmp->my; - in_masters_sight = couldsee(omx, omy); - dog_has_minvent = (droppables(mtmp) != 0); + in_masters_sight = couldsee(omx, omy); + dog_has_minvent = (droppables(mtmp) != 0); - if (!edog || mtmp->mleashed) { /* he's not going anywhere... */ - gtyp = APPORT; - gx = u.ux; - gy = u.uy; - } else { -#define DDIST(x,y) (dist2(x,y,omx,omy)) + if (!edog || mtmp->mleashed) { /* he's not going anywhere... */ + gtyp = APPORT; + gx = u.ux; + gy = u.uy; + } else { +#define DDIST(x, y) (dist2(x, y, omx, omy)) #define SQSRCHRADIUS 5 - int min_x, max_x, min_y, max_y; - register int nx, ny; + int min_x, max_x, min_y, max_y; + register int nx, ny; - gtyp = UNDEF; /* no goal as yet */ - gx = gy = 0; /* suppress 'used before set' message */ + gtyp = UNDEF; /* no goal as yet */ + gx = gy = 0; /* suppress 'used before set' message */ - if ((min_x = omx - SQSRCHRADIUS) < 1) min_x = 1; - if ((max_x = omx + SQSRCHRADIUS) >= COLNO) max_x = COLNO - 1; - if ((min_y = omy - SQSRCHRADIUS) < 0) min_y = 0; - if ((max_y = omy + SQSRCHRADIUS) >= ROWNO) max_y = ROWNO - 1; + if ((min_x = omx - SQSRCHRADIUS) < 1) + min_x = 1; + if ((max_x = omx + SQSRCHRADIUS) >= COLNO) + max_x = COLNO - 1; + if ((min_y = omy - SQSRCHRADIUS) < 0) + min_y = 0; + if ((max_y = omy + SQSRCHRADIUS) >= ROWNO) + max_y = ROWNO - 1; - /* nearby food is the first choice, then other objects */ - for (obj = fobj; obj; obj = obj->nobj) { - nx = obj->ox; - ny = obj->oy; - if (nx >= min_x && nx <= max_x && ny >= min_y && ny <= max_y) { - otyp = dogfood(mtmp, obj); - /* skip inferior goals */ - if (otyp > gtyp || otyp == UNDEF) - continue; - /* avoid cursed items unless starving */ - if (cursed_object_at(nx, ny) && - !(edog->mhpmax_penalty && otyp < MANFOOD)) - continue; - /* skip completely unreacheable goals */ - if (!could_reach_item(mtmp, nx, ny) || - !can_reach_location(mtmp, mtmp->mx, mtmp->my, nx, ny)) - continue; - if (otyp < MANFOOD) { - if (otyp < gtyp || DDIST(nx,ny) < DDIST(gx,gy)) { - gx = nx; - gy = ny; - gtyp = otyp; - } - } else if(gtyp == UNDEF && in_masters_sight && - !dog_has_minvent && - (!levl[omx][omy].lit || levl[u.ux][u.uy].lit) && - (otyp == MANFOOD || m_cansee(mtmp, nx, ny)) && - edog->apport > rn2(8) && - can_carry(mtmp,obj)) { - gx = nx; - gy = ny; - gtyp = APPORT; - } - } - } - } + /* nearby food is the first choice, then other objects */ + for (obj = fobj; obj; obj = obj->nobj) { + nx = obj->ox; + ny = obj->oy; + if (nx >= min_x && nx <= max_x && ny >= min_y && ny <= max_y) { + otyp = dogfood(mtmp, obj); + /* skip inferior goals */ + if (otyp > gtyp || otyp == UNDEF) + continue; + /* avoid cursed items unless starving */ + if (cursed_object_at(nx, ny) + && !(edog->mhpmax_penalty && otyp < MANFOOD)) + continue; + /* skip completely unreacheable goals */ + if (!could_reach_item(mtmp, nx, ny) + || !can_reach_location(mtmp, mtmp->mx, mtmp->my, nx, ny)) + continue; + if (otyp < MANFOOD) { + if (otyp < gtyp || DDIST(nx, ny) < DDIST(gx, gy)) { + gx = nx; + gy = ny; + gtyp = otyp; + } + } else if (gtyp == UNDEF && in_masters_sight + && !dog_has_minvent + && (!levl[omx][omy].lit || levl[u.ux][u.uy].lit) + && (otyp == MANFOOD || m_cansee(mtmp, nx, ny)) + && edog->apport > rn2(8) && can_carry(mtmp, obj)) { + gx = nx; + gy = ny; + gtyp = APPORT; + } + } + } + } - /* follow player if appropriate */ - if (gtyp == UNDEF || - (gtyp != DOGFOOD && gtyp != APPORT && monstermoves < edog->hungrytime)) { - gx = u.ux; - gy = u.uy; - if (after && udist <= 4 && gx == u.ux && gy == u.uy) - return(-2); - appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; - if (udist > 1) { - if (!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) || - whappr || - (dog_has_minvent && rn2(edog->apport))) - appr = 1; - } - /* if you have dog food it'll follow you more closely */ - if (appr == 0) { - obj = invent; - while (obj) { - if(dogfood(mtmp, obj) == DOGFOOD) { - appr = 1; - break; - } - obj = obj->nobj; - } - } - } else - appr = 1; /* gtyp != UNDEF */ - if(mtmp->mconf) - appr = 0; + /* follow player if appropriate */ + if (gtyp == UNDEF || (gtyp != DOGFOOD && gtyp != APPORT + && monstermoves < edog->hungrytime)) { + gx = u.ux; + gy = u.uy; + if (after && udist <= 4 && gx == u.ux && gy == u.uy) + return (-2); + appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; + if (udist > 1) { + if (!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) || whappr + || (dog_has_minvent && rn2(edog->apport))) + appr = 1; + } + /* if you have dog food it'll follow you more closely */ + if (appr == 0) { + obj = invent; + while (obj) { + if (dogfood(mtmp, obj) == DOGFOOD) { + appr = 1; + break; + } + obj = obj->nobj; + } + } + } else + appr = 1; /* gtyp != UNDEF */ + if (mtmp->mconf) + appr = 0; -#define FARAWAY (COLNO + 2) /* position outside screen */ - if (gx == u.ux && gy == u.uy && !in_masters_sight) { - register coord *cp; +#define FARAWAY (COLNO + 2) /* position outside screen */ + if (gx == u.ux && gy == u.uy && !in_masters_sight) { + register coord *cp; - cp = gettrack(omx,omy); - if (cp) { - gx = cp->x; - gy = cp->y; - if(edog) edog->ogoal.x = 0; - } else { - /* assume master hasn't moved far, and reuse previous goal */ - if(edog && edog->ogoal.x && - ((edog->ogoal.x != omx) || (edog->ogoal.y != omy))) { - gx = edog->ogoal.x; - gy = edog->ogoal.y; - edog->ogoal.x = 0; - } else { - int fardist = FARAWAY * FARAWAY; - gx = gy = FARAWAY; /* random */ - do_clear_area(omx, omy, 9, wantdoor, - (genericptr_t)&fardist); + cp = gettrack(omx, omy); + if (cp) { + gx = cp->x; + gy = cp->y; + if (edog) + edog->ogoal.x = 0; + } else { + /* assume master hasn't moved far, and reuse previous goal */ + if (edog && edog->ogoal.x + && ((edog->ogoal.x != omx) || (edog->ogoal.y != omy))) { + gx = edog->ogoal.x; + gy = edog->ogoal.y; + edog->ogoal.x = 0; + } else { + int fardist = FARAWAY * FARAWAY; + gx = gy = FARAWAY; /* random */ + do_clear_area(omx, omy, 9, wantdoor, (genericptr_t) &fardist); - /* here gx == FARAWAY e.g. when dog is in a vault */ - if (gx == FARAWAY || (gx == omx && gy == omy)) { - gx = u.ux; - gy = u.uy; - } else if(edog) { - edog->ogoal.x = gx; - edog->ogoal.y = gy; - } - } - } - } else if(edog) { - edog->ogoal.x = 0; - } - return appr; + /* here gx == FARAWAY e.g. when dog is in a vault */ + if (gx == FARAWAY || (gx == omx && gy == omy)) { + gx = u.ux; + gy = u.uy; + } else if (edog) { + edog->ogoal.x = gx; + edog->ogoal.y = gy; + } + } + } + } else if (edog) { + edog->ogoal.x = 0; + } + return appr; } /* return 0 (no move), 1 (move) or 2 (dead) */ int dog_move(mtmp, after) register struct monst *mtmp; -register int after; /* this is extra fast monster movement */ +register int after; /* this is extra fast monster movement */ { - int omx, omy; /* original mtmp position */ - int appr, whappr, udist; - int i, j, k; - register struct edog *edog = EDOG(mtmp); - struct obj *obj = (struct obj *) 0; - xchar otyp; - boolean has_edog, cursemsg[9], do_eat = FALSE; - boolean better_with_displacing = FALSE; - xchar nix, niy; /* position mtmp is (considering) moving to */ - register int nx, ny; /* temporary coordinates */ - xchar cnt, uncursedcnt, chcnt; - int chi = -1, nidist, ndist; - coord poss[9]; - long info[9], allowflags; -#define GDIST(x,y) (dist2(x,y,gx,gy)) + int omx, omy; /* original mtmp position */ + int appr, whappr, udist; + int i, j, k; + register struct edog *edog = EDOG(mtmp); + struct obj *obj = (struct obj *) 0; + xchar otyp; + boolean has_edog, cursemsg[9], do_eat = FALSE; + boolean better_with_displacing = FALSE; + xchar nix, niy; /* position mtmp is (considering) moving to */ + register int nx, ny; /* temporary coordinates */ + xchar cnt, uncursedcnt, chcnt; + int chi = -1, nidist, ndist; + coord poss[9]; + long info[9], allowflags; +#define GDIST(x, y) (dist2(x, y, gx, gy)) - /* - * Tame Angels have isminion set and an ispriest structure instead of - * an edog structure. Fortunately, guardian Angels need not worry - * about mundane things like eating and fetching objects, and can - * spend all their energy defending the player. (They are the only - * monsters with other structures that can be tame.) - */ - has_edog = !mtmp->isminion; + /* + * Tame Angels have isminion set and an ispriest structure instead of + * an edog structure. Fortunately, guardian Angels need not worry + * about mundane things like eating and fetching objects, and can + * spend all their energy defending the player. (They are the only + * monsters with other structures that can be tame.) + */ + has_edog = !mtmp->isminion; - omx = mtmp->mx; - omy = mtmp->my; - if (has_edog && dog_hunger(mtmp, edog)) return(2); /* starved */ + omx = mtmp->mx; + omy = mtmp->my; + if (has_edog && dog_hunger(mtmp, edog)) + return (2); /* starved */ - udist = distu(omx,omy); - /* Let steeds eat and maybe throw rider during Conflict */ - if (mtmp == u.usteed) { - if (Conflict && !resist(mtmp, RING_CLASS, 0, 0)) { - dismount_steed(DISMOUNT_THROWN); - return (1); - } - udist = 1; - } else if (!udist) - /* maybe we tamed him while being swallowed --jgm */ - return(0); + udist = distu(omx, omy); + /* Let steeds eat and maybe throw rider during Conflict */ + if (mtmp == u.usteed) { + if (Conflict && !resist(mtmp, RING_CLASS, 0, 0)) { + dismount_steed(DISMOUNT_THROWN); + return (1); + } + udist = 1; + } else if (!udist) + /* maybe we tamed him while being swallowed --jgm */ + return (0); - nix = omx; /* set before newdogpos */ - niy = omy; - cursemsg[0] = FALSE; /* lint suppression */ - info[0] = 0; /* ditto */ + nix = omx; /* set before newdogpos */ + niy = omy; + cursemsg[0] = FALSE; /* lint suppression */ + info[0] = 0; /* ditto */ - if (has_edog) { - j = dog_invent(mtmp, edog, udist); - if (j == 2) return 2; /* died */ - else if (j == 1) goto newdogpos; /* eating something */ + if (has_edog) { + j = dog_invent(mtmp, edog, udist); + if (j == 2) + return 2; /* died */ + else if (j == 1) + goto newdogpos; /* eating something */ - whappr = (monstermoves - edog->whistletime < 5); - } else - whappr = 0; + whappr = (monstermoves - edog->whistletime < 5); + } else + whappr = 0; - appr = dog_goal(mtmp, has_edog ? edog : (struct edog *)0, - after, udist, whappr); - if (appr == -2) return(0); + appr = dog_goal(mtmp, has_edog ? edog : (struct edog *) 0, after, udist, + whappr); + if (appr == -2) + return (0); - allowflags = ALLOW_M | ALLOW_TRAPS | ALLOW_SSM | ALLOW_SANCT; - if (passes_walls(mtmp->data)) allowflags |= (ALLOW_ROCK | ALLOW_WALL); - if (passes_bars(mtmp->data)) allowflags |= ALLOW_BARS; - if (throws_rocks(mtmp->data)) allowflags |= ALLOW_ROCK; - if (is_displacer(mtmp->data)) allowflags |= ALLOW_MDISP; - if (Conflict && !resist(mtmp, RING_CLASS, 0, 0)) { - allowflags |= ALLOW_U; - if (!has_edog) { - /* Guardian angel refuses to be conflicted; rather, - * it disappears, angrily, and sends in some nasties - */ - lose_guardian_angel(mtmp); - return 2; /* current monster is gone */ - } - } -#if 0 /* [this is now handled in dochug()] */ + allowflags = ALLOW_M | ALLOW_TRAPS | ALLOW_SSM | ALLOW_SANCT; + if (passes_walls(mtmp->data)) + allowflags |= (ALLOW_ROCK | ALLOW_WALL); + if (passes_bars(mtmp->data)) + allowflags |= ALLOW_BARS; + if (throws_rocks(mtmp->data)) + allowflags |= ALLOW_ROCK; + if (is_displacer(mtmp->data)) + allowflags |= ALLOW_MDISP; + if (Conflict && !resist(mtmp, RING_CLASS, 0, 0)) { + allowflags |= ALLOW_U; + if (!has_edog) { + /* Guardian angel refuses to be conflicted; rather, + * it disappears, angrily, and sends in some nasties + */ + lose_guardian_angel(mtmp); + return 2; /* current monster is gone */ + } + } +#if 0 /* [this is now handled in dochug()] */ if (!Conflict && !mtmp->mconf && mtmp == u.ustuck && !sticks(youmonst.data)) { unstuck(mtmp); /* swallowed case handled above */ You("get released!"); } #endif - if (!nohands(mtmp->data) && !verysmall(mtmp->data)) { - allowflags |= OPENDOOR; - if (monhaskey(mtmp, TRUE)) allowflags |= UNLOCKDOOR; - /* note: the Wizard and Riders can unlock doors without a key; - they won't use that ability if someone manages to tame them */ - } - if (is_giant(mtmp->data)) allowflags |= BUSTDOOR; - if (tunnels(mtmp->data) - && !Is_rogue_level(&u.uz) /* same restriction as m_move() */ - ) allowflags |= ALLOW_DIG; - cnt = mfndpos(mtmp, poss, info, allowflags); + if (!nohands(mtmp->data) && !verysmall(mtmp->data)) { + allowflags |= OPENDOOR; + if (monhaskey(mtmp, TRUE)) + allowflags |= UNLOCKDOOR; + /* note: the Wizard and Riders can unlock doors without a key; + they won't use that ability if someone manages to tame them */ + } + if (is_giant(mtmp->data)) + allowflags |= BUSTDOOR; + if (tunnels(mtmp->data) + && !Is_rogue_level(&u.uz) /* same restriction as m_move() */ + ) + allowflags |= ALLOW_DIG; + cnt = mfndpos(mtmp, poss, info, allowflags); - /* Normally dogs don't step on cursed items, but if they have no - * other choice they will. This requires checking ahead of time - * to see how many uncursed item squares are around. - */ - uncursedcnt = 0; - for (i = 0; i < cnt; i++) { - nx = poss[i].x; ny = poss[i].y; - if (MON_AT(nx,ny) && !((info[i] & ALLOW_M) || info[i] & ALLOW_MDISP)) - continue; - if (cursed_object_at(nx, ny)) continue; - uncursedcnt++; - } + /* Normally dogs don't step on cursed items, but if they have no + * other choice they will. This requires checking ahead of time + * to see how many uncursed item squares are around. + */ + uncursedcnt = 0; + for (i = 0; i < cnt; i++) { + nx = poss[i].x; + ny = poss[i].y; + if (MON_AT(nx, ny) && !((info[i] & ALLOW_M) || info[i] & ALLOW_MDISP)) + continue; + if (cursed_object_at(nx, ny)) + continue; + uncursedcnt++; + } - better_with_displacing = should_displace(mtmp,poss,info,cnt,gx,gy); + better_with_displacing = should_displace(mtmp, poss, info, cnt, gx, gy); - chcnt = 0; - chi = -1; - nidist = GDIST(nix,niy); + chcnt = 0; + chi = -1; + nidist = GDIST(nix, niy); - for (i = 0; i < cnt; i++) { - nx = poss[i].x; - ny = poss[i].y; - cursemsg[i] = FALSE; + for (i = 0; i < cnt; i++) { + nx = poss[i].x; + ny = poss[i].y; + cursemsg[i] = FALSE; - /* if leashed, we drag him along. */ - if (mtmp->mleashed && distu(nx, ny) > 4) continue; + /* if leashed, we drag him along. */ + if (mtmp->mleashed && distu(nx, ny) > 4) + continue; - /* if a guardian, try to stay close by choice */ - if (!has_edog && - (j = distu(nx, ny)) > 16 && j >= udist) continue; + /* if a guardian, try to stay close by choice */ + if (!has_edog && (j = distu(nx, ny)) > 16 && j >= udist) + continue; - if ((info[i] & ALLOW_M) && MON_AT(nx, ny)) { - int mstatus; - register struct monst *mtmp2 = m_at(nx,ny); + if ((info[i] & ALLOW_M) && MON_AT(nx, ny)) { + int mstatus; + register struct monst *mtmp2 = m_at(nx, ny); - if ((int)mtmp2->m_lev >= (int)mtmp->m_lev+2 || - (mtmp2->data == &mons[PM_FLOATING_EYE] && rn2(10) && - mtmp->mcansee && haseyes(mtmp->data) && mtmp2->mcansee - && (perceives(mtmp->data) || !mtmp2->minvis)) || - (mtmp2->data==&mons[PM_GELATINOUS_CUBE] && rn2(10)) || - (max_passive_dmg(mtmp2, mtmp) >= mtmp->mhp) || - ((mtmp->mhp*4 < mtmp->mhpmax - || mtmp2->data->msound == MS_GUARDIAN - || mtmp2->data->msound == MS_LEADER) && - mtmp2->mpeaceful && !Conflict) || - (touch_petrifies(mtmp2->data) && - !resists_ston(mtmp))) - continue; + if ((int) mtmp2->m_lev >= (int) mtmp->m_lev + 2 + || (mtmp2->data == &mons[PM_FLOATING_EYE] && rn2(10) + && mtmp->mcansee && haseyes(mtmp->data) && mtmp2->mcansee + && (perceives(mtmp->data) || !mtmp2->minvis)) + || (mtmp2->data == &mons[PM_GELATINOUS_CUBE] && rn2(10)) + || (max_passive_dmg(mtmp2, mtmp) >= mtmp->mhp) + || ((mtmp->mhp * 4 < mtmp->mhpmax + || mtmp2->data->msound == MS_GUARDIAN + || mtmp2->data->msound == MS_LEADER) && mtmp2->mpeaceful + && !Conflict) + || (touch_petrifies(mtmp2->data) && !resists_ston(mtmp))) + continue; - if (after) return(0); /* hit only once each move */ + if (after) + return (0); /* hit only once each move */ - notonhead = 0; - mstatus = mattackm(mtmp, mtmp2); + notonhead = 0; + mstatus = mattackm(mtmp, mtmp2); - /* aggressor (pet) died */ - if (mstatus & MM_AGR_DIED) return 2; + /* aggressor (pet) died */ + if (mstatus & MM_AGR_DIED) + return 2; - if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED) && - rn2(4) && mtmp2->mlstmv != monstermoves && - !onscary(mtmp->mx, mtmp->my, mtmp2) && - /* monnear check needed: long worms hit on tail */ - monnear(mtmp2, mtmp->mx, mtmp->my)) { - mstatus = mattackm(mtmp2, mtmp); /* return attack */ - if (mstatus & MM_DEF_DIED) return 2; - } - return 0; - } - if ((info[i] & ALLOW_MDISP) && MON_AT(nx, ny) && - better_with_displacing && - !undesirable_disp(mtmp,nx,ny)) { - int mstatus; - register struct monst *mtmp2 = m_at(nx,ny); - mstatus = mdisplacem(mtmp, mtmp2, FALSE); /* displace monster */ - if (mstatus & MM_DEF_DIED) return 2; - return 0; - } + if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED) && rn2(4) + && mtmp2->mlstmv != monstermoves + && !onscary(mtmp->mx, mtmp->my, mtmp2) && + /* monnear check needed: long worms hit on tail */ + monnear(mtmp2, mtmp->mx, mtmp->my)) { + mstatus = mattackm(mtmp2, mtmp); /* return attack */ + if (mstatus & MM_DEF_DIED) + return 2; + } + return 0; + } + if ((info[i] & ALLOW_MDISP) && MON_AT(nx, ny) + && better_with_displacing && !undesirable_disp(mtmp, nx, ny)) { + int mstatus; + register struct monst *mtmp2 = m_at(nx, ny); + mstatus = mdisplacem(mtmp, mtmp2, FALSE); /* displace monster */ + if (mstatus & MM_DEF_DIED) + return 2; + return 0; + } - { /* Dog avoids harmful traps, but perhaps it has to pass one - * in order to follow player. (Non-harmful traps do not - * have ALLOW_TRAPS in info[].) The dog only avoids the - * trap if you've seen it, unlike enemies who avoid traps - * if they've seen some trap of that type sometime in the - * past. (Neither behavior is really realistic.) - */ - struct trap *trap; + { /* Dog avoids harmful traps, but perhaps it has to pass one + * in order to follow player. (Non-harmful traps do not + * have ALLOW_TRAPS in info[].) The dog only avoids the + * trap if you've seen it, unlike enemies who avoid traps + * if they've seen some trap of that type sometime in the + * past. (Neither behavior is really realistic.) + */ + struct trap *trap; - if ((info[i] & ALLOW_TRAPS) && (trap = t_at(nx,ny))) { - if (mtmp->mleashed) { - if (!Deaf) whimper(mtmp); - } else - /* 1/40 chance of stepping on it anyway, in case - * it has to pass one to follow the player... - */ - if (trap->tseen && rn2(40)) continue; - } - } + if ((info[i] & ALLOW_TRAPS) && (trap = t_at(nx, ny))) { + if (mtmp->mleashed) { + if (!Deaf) + whimper(mtmp); + } else + /* 1/40 chance of stepping on it anyway, in case + * it has to pass one to follow the player... + */ + if (trap->tseen && rn2(40)) + continue; + } + } - /* dog eschews cursed objects, but likes dog food */ - /* (minion isn't interested; `cursemsg' stays FALSE) */ - if (has_edog) - for (obj = level.objects[nx][ny]; obj; obj = obj->nexthere) { - if (obj->cursed) cursemsg[i] = TRUE; - else if ((otyp = dogfood(mtmp, obj)) < MANFOOD && - (otyp < ACCFOOD || edog->hungrytime <= monstermoves)) { - /* Note: our dog likes the food so much that he - * might eat it even when it conceals a cursed object */ - nix = nx; - niy = ny; - chi = i; - do_eat = TRUE; - cursemsg[i] = FALSE; /* not reluctant */ - goto newdogpos; - } - } - /* didn't find something to eat; if we saw a cursed item and - aren't being forced to walk on it, usually keep looking */ - if (cursemsg[i] && !mtmp->mleashed && uncursedcnt > 0 && - rn2(13 * uncursedcnt)) continue; + /* dog eschews cursed objects, but likes dog food */ + /* (minion isn't interested; `cursemsg' stays FALSE) */ + if (has_edog) + for (obj = level.objects[nx][ny]; obj; obj = obj->nexthere) { + if (obj->cursed) + cursemsg[i] = TRUE; + else if ((otyp = dogfood(mtmp, obj)) < MANFOOD + && (otyp < ACCFOOD + || edog->hungrytime <= monstermoves)) { + /* Note: our dog likes the food so much that he + * might eat it even when it conceals a cursed object */ + nix = nx; + niy = ny; + chi = i; + do_eat = TRUE; + cursemsg[i] = FALSE; /* not reluctant */ + goto newdogpos; + } + } + /* didn't find something to eat; if we saw a cursed item and + aren't being forced to walk on it, usually keep looking */ + if (cursemsg[i] && !mtmp->mleashed && uncursedcnt > 0 + && rn2(13 * uncursedcnt)) + continue; - /* lessen the chance of backtracking to previous position(s) */ - k = has_edog ? uncursedcnt : cnt; - for (j = 0; j < MTSZ && j < k - 1; j++) - if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) - if (rn2(MTSZ * (k - j))) goto nxti; + /* lessen the chance of backtracking to previous position(s) */ + k = has_edog ? uncursedcnt : cnt; + for (j = 0; j < MTSZ && j < k - 1; j++) + if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) + if (rn2(MTSZ * (k - j))) + goto nxti; - j = ((ndist = GDIST(nx,ny)) - nidist) * appr; - if ((j == 0 && !rn2(++chcnt)) || j < 0 || - (j > 0 && !whappr && - ((omx == nix && omy == niy && !rn2(3)) - || !rn2(12)) - )) { - nix = nx; - niy = ny; - nidist = ndist; - if(j < 0) chcnt = 0; - chi = i; - } - nxti: ; - } + j = ((ndist = GDIST(nx, ny)) - nidist) * appr; + if ((j == 0 && !rn2(++chcnt)) || j < 0 + || (j > 0 && !whappr + && ((omx == nix && omy == niy && !rn2(3)) || !rn2(12)))) { + nix = nx; + niy = ny; + nidist = ndist; + if (j < 0) + chcnt = 0; + chi = i; + } + nxti: + ; + } newdogpos: - if (nix != omx || niy != omy) { - struct obj *mw_tmp; - boolean wasseen; + if (nix != omx || niy != omy) { + struct obj *mw_tmp; + boolean wasseen; - if (info[chi] & ALLOW_U) { - if (mtmp->mleashed) { /* play it safe */ - pline("%s breaks loose of %s leash!", - Monnam(mtmp), mhis(mtmp)); - m_unleash(mtmp, FALSE); - } - (void) mattacku(mtmp); - return(0); - } - if (!m_in_out_region(mtmp, nix, niy)) - return 1; - if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix,niy)) || - closed_door(nix, niy)) && - mtmp->weapon_check != NO_WEAPON_WANTED && - tunnels(mtmp->data) && needspick(mtmp->data)) { - if (closed_door(nix, niy)) { - if (!(mw_tmp = MON_WEP(mtmp)) || - !is_pick(mw_tmp) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_PICK_OR_AXE; - } else if (IS_TREE(levl[nix][niy].typ)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_AXE; - } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { - mtmp->weapon_check = NEED_PICK_AXE; - } - if (mtmp->weapon_check >= NEED_PICK_AXE && - mon_wield_item(mtmp)) - return 0; - } - /* insert a worm_move() if worms ever begin to eat things */ - wasseen = canseemon(mtmp); - remove_monster(omx, omy); - place_monster(mtmp, nix, niy); - if (cursemsg[chi] && (wasseen || canseemon(mtmp))) - pline("%s moves only reluctantly.", noit_Monnam(mtmp)); - for (j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; - mtmp->mtrack[0].x = omx; - mtmp->mtrack[0].y = omy; - /* We have to know if the pet's gonna do a combined eat and - * move before moving it, but it can't eat until after being - * moved. Thus the do_eat flag. - */ - if (do_eat) { - if (dog_eat(mtmp, obj, omx, omy, FALSE) == 2) return 2; - } - } else if (mtmp->mleashed && distu(omx, omy) > 4) { - /* an incredible kludge, but the only way to keep pooch near - * after it spends time eating or in a trap, etc. - */ - coord cc; + if (info[chi] & ALLOW_U) { + if (mtmp->mleashed) { /* play it safe */ + pline("%s breaks loose of %s leash!", Monnam(mtmp), + mhis(mtmp)); + m_unleash(mtmp, FALSE); + } + (void) mattacku(mtmp); + return (0); + } + if (!m_in_out_region(mtmp, nix, niy)) + return 1; + if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix, niy)) + || closed_door(nix, niy)) + && mtmp->weapon_check != NO_WEAPON_WANTED + && tunnels(mtmp->data) && needspick(mtmp->data)) { + if (closed_door(nix, niy)) { + if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp) + || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_PICK_OR_AXE; + } else if (IS_TREE(levl[nix][niy].typ)) { + if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_AXE; + } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { + mtmp->weapon_check = NEED_PICK_AXE; + } + if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) + return 0; + } + /* insert a worm_move() if worms ever begin to eat things */ + wasseen = canseemon(mtmp); + remove_monster(omx, omy); + place_monster(mtmp, nix, niy); + if (cursemsg[chi] && (wasseen || canseemon(mtmp))) + pline("%s moves only reluctantly.", noit_Monnam(mtmp)); + for (j = MTSZ - 1; j > 0; j--) + mtmp->mtrack[j] = mtmp->mtrack[j - 1]; + mtmp->mtrack[0].x = omx; + mtmp->mtrack[0].y = omy; + /* We have to know if the pet's gonna do a combined eat and + * move before moving it, but it can't eat until after being + * moved. Thus the do_eat flag. + */ + if (do_eat) { + if (dog_eat(mtmp, obj, omx, omy, FALSE) == 2) + return 2; + } + } else if (mtmp->mleashed && distu(omx, omy) > 4) { + /* an incredible kludge, but the only way to keep pooch near + * after it spends time eating or in a trap, etc. + */ + coord cc; - nx = sgn(omx - u.ux); - ny = sgn(omy - u.uy); - cc.x = u.ux + nx; - cc.y = u.uy + ny; - if (goodpos(cc.x, cc.y, mtmp, 0)) goto dognext; + nx = sgn(omx - u.ux); + ny = sgn(omy - u.uy); + cc.x = u.ux + nx; + cc.y = u.uy + ny; + if (goodpos(cc.x, cc.y, mtmp, 0)) + goto dognext; - i = xytod(nx, ny); - for (j = (i + 7)%8; j < (i + 1)%8; j++) { - dtoxy(&cc, j); - if (goodpos(cc.x, cc.y, mtmp, 0)) goto dognext; - } - for (j = (i + 6)%8; j < (i + 2)%8; j++) { - dtoxy(&cc, j); - if (goodpos(cc.x, cc.y, mtmp, 0)) goto dognext; - } - cc.x = mtmp->mx; - cc.y = mtmp->my; -dognext: - if (!m_in_out_region(mtmp, nix, niy)) - return 1; - remove_monster(mtmp->mx, mtmp->my); - place_monster(mtmp, cc.x, cc.y); - newsym(cc.x,cc.y); - set_apparxy(mtmp); - } - return(1); + i = xytod(nx, ny); + for (j = (i + 7) % 8; j < (i + 1) % 8; j++) { + dtoxy(&cc, j); + if (goodpos(cc.x, cc.y, mtmp, 0)) + goto dognext; + } + for (j = (i + 6) % 8; j < (i + 2) % 8; j++) { + dtoxy(&cc, j); + if (goodpos(cc.x, cc.y, mtmp, 0)) + goto dognext; + } + cc.x = mtmp->mx; + cc.y = mtmp->my; + dognext: + if (!m_in_out_region(mtmp, nix, niy)) + return 1; + remove_monster(mtmp->mx, mtmp->my); + place_monster(mtmp, cc.x, cc.y); + newsym(cc.x, cc.y); + set_apparxy(mtmp); + } + return (1); } /* check if a monster could pick up objects from a location */ @@ -896,10 +962,10 @@ could_reach_item(mon, nx, ny) struct monst *mon; xchar nx, ny; { - if ((!is_pool(nx,ny) || is_swimmer(mon->data)) && - (!is_lava(nx,ny) || likes_lava(mon->data)) && - (!sobj_at(BOULDER,nx,ny) || throws_rocks(mon->data))) - return TRUE; + if ((!is_pool(nx, ny) || is_swimmer(mon->data)) + && (!is_lava(nx, ny) || likes_lava(mon->data)) + && (!sobj_at(BOULDER, nx, ny) || throws_rocks(mon->data))) + return TRUE; return FALSE; } @@ -907,7 +973,8 @@ xchar nx, ny; * it can't reach, such as caught in a teleport scroll niche. It recursively * checks to see if the squares in between are good. The checking could be a * little smarter; a full check would probably be useful in m_move() too. - * Since the maximum food distance is 5, this should never be more than 5 calls + * Since the maximum food distance is 5, this should never be more than 5 + * calls * deep. */ STATIC_OVL boolean @@ -918,32 +985,34 @@ xchar mx, my, fx, fy; int i, j; int dist; - if (mx == fx && my == fy) return TRUE; - if (!isok(mx, my)) return FALSE; /* should not happen */ - + if (mx == fx && my == fy) + return TRUE; + if (!isok(mx, my)) + return FALSE; /* should not happen */ + dist = dist2(mx, my, fx, fy); - for(i=mx-1; i<=mx+1; i++) { - for(j=my-1; j<=my+1; j++) { - if (!isok(i, j)) - continue; - if (dist2(i, j, fx, fy) >= dist) - continue; - if (IS_ROCK(levl[i][j].typ) && !passes_walls(mon->data) && - (!may_dig(i,j) || !tunnels(mon->data))) - continue; - if (IS_DOOR(levl[i][j].typ) && - (levl[i][j].doormask & (D_CLOSED | D_LOCKED))) - continue; - if (!could_reach_item(mon, i, j)) - continue; - if (can_reach_location(mon, i, j, fx, fy)) - return TRUE; - } + for (i = mx - 1; i <= mx + 1; i++) { + for (j = my - 1; j <= my + 1; j++) { + if (!isok(i, j)) + continue; + if (dist2(i, j, fx, fy) >= dist) + continue; + if (IS_ROCK(levl[i][j].typ) && !passes_walls(mon->data) + && (!may_dig(i, j) || !tunnels(mon->data))) + continue; + if (IS_DOOR(levl[i][j].typ) + && (levl[i][j].doormask & (D_CLOSED | D_LOCKED))) + continue; + if (!could_reach_item(mon, i, j)) + continue; + if (can_reach_location(mon, i, j, fx, fy)) + return TRUE; + } } return FALSE; } -/*ARGSUSED*/ /* do_clear_area client */ +/*ARGSUSED*/ /* do_clear_area client */ STATIC_PTR void wantdoor(x, y, distance) int x, y; @@ -951,93 +1020,96 @@ genericptr_t distance; { int ndist; - if (*(int*)distance > (ndist = distu(x, y))) { - gx = x; - gy = y; - *(int*)distance = ndist; + if (*(int *) distance > (ndist = distu(x, y))) { + gx = x; + gy = y; + *(int *) distance = ndist; } } - static struct qmchoices { - int mndx; /* type of pet, 0 means any */ - char mlet; /* symbol of pet, 0 means any */ - unsigned mappearance; /* mimic this */ - uchar m_ap_type; /* what is the thing it is mimicing? */ + int mndx; /* type of pet, 0 means any */ + char mlet; /* symbol of pet, 0 means any */ + unsigned mappearance; /* mimic this */ + uchar m_ap_type; /* what is the thing it is mimicing? */ } qm[] = { - /* Things that some pets might be thinking about at the time */ - {PM_LITTLE_DOG, 0, PM_KITTEN, M_AP_MONSTER}, - {PM_DOG, 0, PM_HOUSECAT, M_AP_MONSTER}, - {PM_LARGE_DOG, 0, PM_LARGE_CAT, M_AP_MONSTER}, - {PM_KITTEN, 0, PM_LITTLE_DOG, M_AP_MONSTER}, - {PM_HOUSECAT, 0, PM_DOG, M_AP_MONSTER}, - {PM_LARGE_CAT, 0, PM_LARGE_DOG, M_AP_MONSTER}, - {PM_HOUSECAT, 0, PM_GIANT_RAT, M_AP_MONSTER}, - {0, S_DOG, SINK, M_AP_FURNITURE}, /* sorry, no fire hydrants in NetHack */ - {0, 0, TRIPE_RATION, M_AP_OBJECT}, /* leave this at end */ + /* Things that some pets might be thinking about at the time */ + { PM_LITTLE_DOG, 0, PM_KITTEN, M_AP_MONSTER }, + { PM_DOG, 0, PM_HOUSECAT, M_AP_MONSTER }, + { PM_LARGE_DOG, 0, PM_LARGE_CAT, M_AP_MONSTER }, + { PM_KITTEN, 0, PM_LITTLE_DOG, M_AP_MONSTER }, + { PM_HOUSECAT, 0, PM_DOG, M_AP_MONSTER }, + { PM_LARGE_CAT, 0, PM_LARGE_DOG, M_AP_MONSTER }, + { PM_HOUSECAT, 0, PM_GIANT_RAT, M_AP_MONSTER }, + { 0, S_DOG, SINK, + M_AP_FURNITURE }, /* sorry, no fire hydrants in NetHack */ + { 0, 0, TRIPE_RATION, M_AP_OBJECT }, /* leave this at end */ }; void finish_meating(mtmp) struct monst *mtmp; { - mtmp->meating = 0; - if (mtmp->m_ap_type && mtmp->mappearance && mtmp->cham == NON_PM) { - /* was eating a mimic and now appearance needs resetting */ - mtmp->m_ap_type = 0; - mtmp->mappearance = 0; - newsym(mtmp->mx, mtmp->my); - } + mtmp->meating = 0; + if (mtmp->m_ap_type && mtmp->mappearance && mtmp->cham == NON_PM) { + /* was eating a mimic and now appearance needs resetting */ + mtmp->m_ap_type = 0; + mtmp->mappearance = 0; + newsym(mtmp->mx, mtmp->my); + } } STATIC_OVL void quickmimic(mtmp) struct monst *mtmp; { - int idx = 0, trycnt = 5, spotted; - char buf[BUFSZ]; + int idx = 0, trycnt = 5, spotted; + char buf[BUFSZ]; - if (Protection_from_shape_changers || !mtmp->meating) return; + if (Protection_from_shape_changers || !mtmp->meating) + return; - do { - idx = rn2(SIZE(qm)); - if (qm[idx].mndx != 0 && monsndx(mtmp->data) == qm[idx].mndx) - break; - if (qm[idx].mlet != 0 && mtmp->data->mlet == qm[idx].mlet) - break; - if (qm[idx].mndx == 0 && qm[idx].mlet == 0) - break; - } while (--trycnt > 0); - if (trycnt == 0) idx = SIZE(qm)-1; + do { + idx = rn2(SIZE(qm)); + if (qm[idx].mndx != 0 && monsndx(mtmp->data) == qm[idx].mndx) + break; + if (qm[idx].mlet != 0 && mtmp->data->mlet == qm[idx].mlet) + break; + if (qm[idx].mndx == 0 && qm[idx].mlet == 0) + break; + } while (--trycnt > 0); + if (trycnt == 0) + idx = SIZE(qm) - 1; - Strcpy(buf, mon_nam(mtmp)); - spotted = canspotmon(mtmp); + Strcpy(buf, mon_nam(mtmp)); + spotted = canspotmon(mtmp); - mtmp->m_ap_type = qm[idx].m_ap_type; - mtmp->mappearance = qm[idx].mappearance; + mtmp->m_ap_type = qm[idx].m_ap_type; + mtmp->mappearance = qm[idx].mappearance; - if (spotted || cansee(mtmp->mx, mtmp->my) || canspotmon(mtmp)) { - /* this isn't quite right; if sensing a monster without being - able to see its location, you really shouldn't be told you - sense it becoming furniture or an object that you can't see - (on the other hand, perhaps you're sensing a brief glimpse - of its mind as it changes form) */ - newsym(mtmp->mx, mtmp->my); - You("%s %s appear where %s was!", - cansee(mtmp->mx, mtmp->my) ? "see" : "sense", - (mtmp->m_ap_type == M_AP_FURNITURE) ? - an(defsyms[mtmp->mappearance].explanation) : - (mtmp->m_ap_type == M_AP_OBJECT && - OBJ_DESCR(objects[mtmp->mappearance])) ? - an(OBJ_DESCR(objects[mtmp->mappearance])) : - (mtmp->m_ap_type == M_AP_OBJECT && - OBJ_NAME(objects[mtmp->mappearance])) ? - an(OBJ_NAME(objects[mtmp->mappearance])) : - (mtmp->m_ap_type == M_AP_MONSTER) ? - an(mons[mtmp->mappearance].mname) : something, - buf); - display_nhwindow(WIN_MAP, TRUE); - } + if (spotted || cansee(mtmp->mx, mtmp->my) || canspotmon(mtmp)) { + /* this isn't quite right; if sensing a monster without being + able to see its location, you really shouldn't be told you + sense it becoming furniture or an object that you can't see + (on the other hand, perhaps you're sensing a brief glimpse + of its mind as it changes form) */ + newsym(mtmp->mx, mtmp->my); + You("%s %s appear where %s was!", + cansee(mtmp->mx, mtmp->my) ? "see" : "sense", + (mtmp->m_ap_type == M_AP_FURNITURE) + ? an(defsyms[mtmp->mappearance].explanation) + : (mtmp->m_ap_type == M_AP_OBJECT + && OBJ_DESCR(objects[mtmp->mappearance])) + ? an(OBJ_DESCR(objects[mtmp->mappearance])) + : (mtmp->m_ap_type == M_AP_OBJECT + && OBJ_NAME(objects[mtmp->mappearance])) + ? an(OBJ_NAME(objects[mtmp->mappearance])) + : (mtmp->m_ap_type == M_AP_MONSTER) + ? an(mons[mtmp->mappearance].mname) + : something, + buf); + display_nhwindow(WIN_MAP, TRUE); + } } /*dogmove.c*/ diff --git a/src/dokick.c b/src/dokick.c index 511f4db3c..a56d0693a 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -1,29 +1,31 @@ -/* NetHack 3.6 dokick.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dokick.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.98 $ */ /* NetHack 3.6 dokick.c $Date: 2012/05/06 02:29:33 $ $Revision: 1.78 $ */ /* Copyright (c) Izchak Miller, Mike Stephenson, Steve Linhart, 1989. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -#define is_bigfoot(x) ((x) == &mons[PM_SASQUATCH]) -#define martial() (martial_bonus() || is_bigfoot(youmonst.data) || \ - (uarmf && uarmf->otyp == KICKING_BOOTS)) +#define is_bigfoot(x) ((x) == &mons[PM_SASQUATCH]) +#define martial() \ + (martial_bonus() || is_bigfoot(youmonst.data) \ + || (uarmf && uarmf->otyp == KICKING_BOOTS)) static NEARDATA struct rm *maploc, nowhere; static NEARDATA const char *gate_str; /* kickedobj (decl.c) tracks a kicked object until placed or destroyed */ -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ STATIC_DCL void FDECL(kickdmg, (struct monst *, BOOLEAN_P)); -STATIC_DCL boolean FDECL(maybe_kick_monster, (struct monst *,XCHAR_P,XCHAR_P)); -STATIC_DCL void FDECL(kick_monster, (struct monst *,XCHAR_P,XCHAR_P)); -STATIC_DCL int FDECL(kick_object, (XCHAR_P,XCHAR_P)); -STATIC_DCL int FDECL(really_kick_object, (XCHAR_P,XCHAR_P)); +STATIC_DCL boolean +FDECL(maybe_kick_monster, (struct monst *, XCHAR_P, XCHAR_P)); +STATIC_DCL void FDECL(kick_monster, (struct monst *, XCHAR_P, XCHAR_P)); +STATIC_DCL int FDECL(kick_object, (XCHAR_P, XCHAR_P)); +STATIC_DCL int FDECL(really_kick_object, (XCHAR_P, XCHAR_P)); STATIC_DCL char *FDECL(kickstr, (char *)); STATIC_DCL void FDECL(otransit_msg, (struct obj *, BOOLEAN_P, long)); -STATIC_DCL void FDECL(drop_to, (coord *,SCHAR_P)); +STATIC_DCL void FDECL(drop_to, (coord *, SCHAR_P)); static const char kick_passes_thru[] = "kick passes harmlessly through"; @@ -32,88 +34,96 @@ kickdmg(mon, clumsy) register struct monst *mon; register boolean clumsy; { - register int mdx, mdy; - register int dmg = ( ACURRSTR + ACURR(A_DEX) + ACURR(A_CON) )/ 15; - int kick_skill = P_NONE; - int blessed_foot_damage = 0; - boolean trapkilled = FALSE; + register int mdx, mdy; + register int dmg = (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 15; + int kick_skill = P_NONE; + int blessed_foot_damage = 0; + boolean trapkilled = FALSE; - if (uarmf && uarmf->otyp == KICKING_BOOTS) - dmg += 5; + if (uarmf && uarmf->otyp == KICKING_BOOTS) + dmg += 5; - /* excessive wt affects dex, so it affects dmg */ - if (clumsy) dmg /= 2; + /* excessive wt affects dex, so it affects dmg */ + if (clumsy) + dmg /= 2; - /* kicking a dragon or an elephant will not harm it */ - if (thick_skinned(mon->data)) dmg = 0; + /* kicking a dragon or an elephant will not harm it */ + if (thick_skinned(mon->data)) + dmg = 0; - /* attacking a shade is useless */ - if (mon->data == &mons[PM_SHADE]) - dmg = 0; + /* attacking a shade is useless */ + if (mon->data == &mons[PM_SHADE]) + dmg = 0; - if ((is_undead(mon->data) || is_demon(mon->data) || is_vampshifter(mon)) - && uarmf && uarmf->blessed) - blessed_foot_damage = 1; + if ((is_undead(mon->data) || is_demon(mon->data) || is_vampshifter(mon)) + && uarmf && uarmf->blessed) + blessed_foot_damage = 1; - if (mon->data == &mons[PM_SHADE] && !blessed_foot_damage) { - pline_The("%s.", kick_passes_thru); - /* doesn't exercise skill or abuse alignment or frighten pet, - and shades have no passive counterattack */ - return; - } + if (mon->data == &mons[PM_SHADE] && !blessed_foot_damage) { + pline_The("%s.", kick_passes_thru); + /* doesn't exercise skill or abuse alignment or frighten pet, + and shades have no passive counterattack */ + return; + } - if(mon->m_ap_type) seemimic(mon); + if (mon->m_ap_type) + seemimic(mon); - check_caitiff(mon); + check_caitiff(mon); - /* squeeze some guilt feelings... */ - if(mon->mtame) { - abuse_dog(mon); - if (mon->mtame) - monflee(mon, (dmg ? rnd(dmg) : 1), FALSE, FALSE); - else - mon->mflee = 0; - } + /* squeeze some guilt feelings... */ + if (mon->mtame) { + abuse_dog(mon); + if (mon->mtame) + monflee(mon, (dmg ? rnd(dmg) : 1), FALSE, FALSE); + else + mon->mflee = 0; + } - if (dmg > 0) { - /* convert potential damage to actual damage */ - dmg = rnd(dmg); - if (martial()) { - if (dmg > 1) kick_skill = P_MARTIAL_ARTS; - dmg += rn2(ACURR(A_DEX)/2 + 1); - } - /* a good kick exercises your dex */ - exercise(A_DEX, TRUE); - } - if (blessed_foot_damage) dmg += rnd(4); - if (uarmf) dmg += uarmf->spe; - dmg += u.udaminc; /* add ring(s) of increase damage */ - if (dmg > 0) - mon->mhp -= dmg; - if (mon->mhp > 0 && martial() && !bigmonst(mon->data) && !rn2(3) && - mon->mcanmove && mon != u.ustuck && !mon->mtrapped) { - /* see if the monster has a place to move into */ - mdx = mon->mx + u.dx; - mdy = mon->my + u.dy; - if(goodpos(mdx, mdy, mon, 0)) { - pline("%s reels from the blow.", Monnam(mon)); - if (m_in_out_region(mon, mdx, mdy)) { - remove_monster(mon->mx, mon->my); - newsym(mon->mx, mon->my); - place_monster(mon, mdx, mdy); - newsym(mon->mx, mon->my); - set_apparxy(mon); - if (mintrap(mon) == 2) trapkilled = TRUE; - } - } - } + if (dmg > 0) { + /* convert potential damage to actual damage */ + dmg = rnd(dmg); + if (martial()) { + if (dmg > 1) + kick_skill = P_MARTIAL_ARTS; + dmg += rn2(ACURR(A_DEX) / 2 + 1); + } + /* a good kick exercises your dex */ + exercise(A_DEX, TRUE); + } + if (blessed_foot_damage) + dmg += rnd(4); + if (uarmf) + dmg += uarmf->spe; + dmg += u.udaminc; /* add ring(s) of increase damage */ + if (dmg > 0) + mon->mhp -= dmg; + if (mon->mhp > 0 && martial() && !bigmonst(mon->data) && !rn2(3) + && mon->mcanmove && mon != u.ustuck && !mon->mtrapped) { + /* see if the monster has a place to move into */ + mdx = mon->mx + u.dx; + mdy = mon->my + u.dy; + if (goodpos(mdx, mdy, mon, 0)) { + pline("%s reels from the blow.", Monnam(mon)); + if (m_in_out_region(mon, mdx, mdy)) { + remove_monster(mon->mx, mon->my); + newsym(mon->mx, mon->my); + place_monster(mon, mdx, mdy); + newsym(mon->mx, mon->my); + set_apparxy(mon); + if (mintrap(mon) == 2) + trapkilled = TRUE; + } + } + } - (void) passive(mon, TRUE, mon->mhp > 0, AT_KICK, FALSE); - if (mon->mhp <= 0 && !trapkilled) killed(mon); + (void) passive(mon, TRUE, mon->mhp > 0, AT_KICK, FALSE); + if (mon->mhp <= 0 && !trapkilled) + killed(mon); - /* may bring up a dialog, so put this after all messages */ - if (kick_skill != P_NONE) /* exercise proficiency */ - use_skill(kick_skill, 1); + /* may bring up a dialog, so put this after all messages */ + if (kick_skill != P_NONE) /* exercise proficiency */ + use_skill(kick_skill, 1); } STATIC_OVL boolean @@ -122,18 +132,18 @@ struct monst *mon; xchar x, y; { if (mon) { - boolean save_forcefight = context.forcefight; + boolean save_forcefight = context.forcefight; - bhitpos.x = x; - bhitpos.y = y; - if (!mon->mpeaceful || !canspotmon(mon)) - context.forcefight = TRUE; /* attack even if invisible */ - /* kicking might be halted by discovery of hidden monster, - by player declining to attack peaceful monster, - or by passing out due to encumbrance */ - if (attack_checks(mon, (struct obj *)0) || overexertion()) - mon = 0; /* don't kick after all */ - context.forcefight = save_forcefight; + bhitpos.x = x; + bhitpos.y = y; + if (!mon->mpeaceful || !canspotmon(mon)) + context.forcefight = TRUE; /* attack even if invisible */ + /* kicking might be halted by discovery of hidden monster, + by player declining to attack peaceful monster, + or by passing out due to encumbrance */ + if (attack_checks(mon, (struct obj *) 0) || overexertion()) + mon = 0; /* don't kick after all */ + context.forcefight = save_forcefight; } return (boolean)(mon != 0); } @@ -143,125 +153,137 @@ kick_monster(mon, x, y) struct monst *mon; xchar x, y; { - boolean clumsy = FALSE; - int i, j; + boolean clumsy = FALSE; + int i, j; - /* anger target even if wild miss will occur */ - setmangry(mon); + /* anger target even if wild miss will occur */ + setmangry(mon); - if (Levitation && !rn2(3) && verysmall(mon->data) && - !is_flyer(mon->data)) { - pline("Floating in the air, you miss wildly!"); - exercise(A_DEX, FALSE); - (void) passive(mon, FALSE, 1, AT_KICK, FALSE); - return; - } + if (Levitation && !rn2(3) && verysmall(mon->data) + && !is_flyer(mon->data)) { + pline("Floating in the air, you miss wildly!"); + exercise(A_DEX, FALSE); + (void) passive(mon, FALSE, 1, AT_KICK, FALSE); + return; + } - /* reveal hidden target even if kick ends up missing (note: being - hidden doesn't affect chance to hit so neither does this reveal) */ - if (mon->mundetected || - (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)) { - if (mon->m_ap_type) seemimic(mon); - mon->mundetected = 0; - if (!canspotmon(mon)) map_invisible(x, y); - else newsym(x, y); - There("is %s here.", - canspotmon(mon) ? a_monnam(mon) : "something hidden"); - } + /* reveal hidden target even if kick ends up missing (note: being + hidden doesn't affect chance to hit so neither does this reveal) */ + if (mon->mundetected + || (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)) { + if (mon->m_ap_type) + seemimic(mon); + mon->mundetected = 0; + if (!canspotmon(mon)) + map_invisible(x, y); + else + newsym(x, y); + There("is %s here.", + canspotmon(mon) ? a_monnam(mon) : "something hidden"); + } - /* Kick attacks by kicking monsters are normal attacks, not special. - * This is almost always worthless, since you can either take one turn - * and do all your kicks, or else take one turn and attack the monster - * normally, getting all your attacks _including_ all your kicks. - * If you have >1 kick attack, you get all of them. - */ - if (Upolyd && attacktype(youmonst.data, AT_KICK)) { - struct attack *uattk; - int sum, kickdieroll, armorpenalty, attknum = 0, - tmp = find_roll_to_hit(mon, AT_KICK, (struct obj *)0, - &attknum, &armorpenalty); + /* Kick attacks by kicking monsters are normal attacks, not special. + * This is almost always worthless, since you can either take one turn + * and do all your kicks, or else take one turn and attack the monster + * normally, getting all your attacks _including_ all your kicks. + * If you have >1 kick attack, you get all of them. + */ + if (Upolyd && attacktype(youmonst.data, AT_KICK)) { + struct attack *uattk; + int sum, kickdieroll, armorpenalty, + attknum = 0, + tmp = find_roll_to_hit(mon, AT_KICK, (struct obj *) 0, &attknum, + &armorpenalty); - for (i = 0; i < NATTK; i++) { - /* first of two kicks might have provoked counterattack - that has incapacitated the hero (ie, floating eye) */ - if (multi < 0) break; + for (i = 0; i < NATTK; i++) { + /* first of two kicks might have provoked counterattack + that has incapacitated the hero (ie, floating eye) */ + if (multi < 0) + break; - uattk = &youmonst.data->mattk[i]; - /* we only care about kicking attacks here */ - if (uattk->aatyp != AT_KICK) continue; + uattk = &youmonst.data->mattk[i]; + /* we only care about kicking attacks here */ + if (uattk->aatyp != AT_KICK) + continue; - if (mon->data == &mons[PM_SHADE] && - (!uarmf || !uarmf->blessed)) { - /* doesn't matter whether it would have hit or missed, - and shades have no passive counterattack */ - Your("%s %s.", kick_passes_thru, mon_nam(mon)); - break; /* skip any additional kicks */ - } else if (tmp > (kickdieroll = rnd(20))) { - You("kick %s.", mon_nam(mon)); - sum = damageum(mon, uattk); - (void)passive(mon, (boolean)(sum > 0), (sum != 2), AT_KICK, FALSE); - if (sum == 2) - break; /* Defender died */ - } else { - missum(mon, uattk, (tmp + armorpenalty > kickdieroll)); - (void)passive(mon, 0, 1, AT_KICK,FALSE); - } - } - return; - } + if (mon->data == &mons[PM_SHADE] && (!uarmf || !uarmf->blessed)) { + /* doesn't matter whether it would have hit or missed, + and shades have no passive counterattack */ + Your("%s %s.", kick_passes_thru, mon_nam(mon)); + break; /* skip any additional kicks */ + } else if (tmp > (kickdieroll = rnd(20))) { + You("kick %s.", mon_nam(mon)); + sum = damageum(mon, uattk); + (void) passive(mon, (boolean)(sum > 0), (sum != 2), AT_KICK, + FALSE); + if (sum == 2) + break; /* Defender died */ + } else { + missum(mon, uattk, (tmp + armorpenalty > kickdieroll)); + (void) passive(mon, 0, 1, AT_KICK, FALSE); + } + } + return; + } - i = -inv_weight(); - j = weight_cap(); + i = -inv_weight(); + j = weight_cap(); - if(i < (j*3)/10) { - if(!rn2((i < j/10) ? 2 : (i < j/5) ? 3 : 4)) { - if(martial() && !rn2(2)) goto doit; - Your("clumsy kick does no damage."); - (void) passive(mon, FALSE, 1, AT_KICK, FALSE); - return; - } - if(i < j/10) clumsy = TRUE; - else if(!rn2((i < j/5) ? 2 : 3)) clumsy = TRUE; - } + if (i < (j * 3) / 10) { + if (!rn2((i < j / 10) ? 2 : (i < j / 5) ? 3 : 4)) { + if (martial() && !rn2(2)) + goto doit; + Your("clumsy kick does no damage."); + (void) passive(mon, FALSE, 1, AT_KICK, FALSE); + return; + } + if (i < j / 10) + clumsy = TRUE; + else if (!rn2((i < j / 5) ? 2 : 3)) + clumsy = TRUE; + } - if(Fumbling) clumsy = TRUE; + if (Fumbling) + clumsy = TRUE; - else if(uarm && objects[uarm->otyp].oc_bulky && ACURR(A_DEX) < rnd(25)) - clumsy = TRUE; + else if (uarm && objects[uarm->otyp].oc_bulky && ACURR(A_DEX) < rnd(25)) + clumsy = TRUE; doit: - You("kick %s.", mon_nam(mon)); - if(!rn2(clumsy ? 3 : 4) && (clumsy || !bigmonst(mon->data)) && - mon->mcansee && !mon->mtrapped && !thick_skinned(mon->data) && - mon->data->mlet != S_EEL && haseyes(mon->data) && mon->mcanmove && - !mon->mstun && !mon->mconf && !mon->msleeping && - mon->data->mmove >= 12) { - if(!nohands(mon->data) && !rn2(martial() ? 5 : 3)) { - pline("%s blocks your %skick.", Monnam(mon), - clumsy ? "clumsy " : ""); - (void) passive(mon, FALSE, 1, AT_KICK, FALSE); - return; - } else { - maybe_mnexto(mon); - if(mon->mx != x || mon->my != y) { - if(glyph_is_invisible(levl[x][y].glyph)) { - unmap_object(x, y); - newsym(x, y); - } - pline("%s %s, %s evading your %skick.", Monnam(mon), - (!level.flags.noteleport && can_teleport(mon->data)) ? - "teleports" : - is_floater(mon->data) ? "floats" : - is_flyer(mon->data) ? "swoops" : - (nolimbs(mon->data) || slithy(mon->data)) ? - "slides" : "jumps", - clumsy ? "easily" : "nimbly", - clumsy ? "clumsy " : ""); - (void) passive(mon, FALSE, 1, AT_KICK, FALSE); - return; - } - } - } - kickdmg(mon, clumsy); + You("kick %s.", mon_nam(mon)); + if (!rn2(clumsy ? 3 : 4) && (clumsy || !bigmonst(mon->data)) + && mon->mcansee && !mon->mtrapped && !thick_skinned(mon->data) + && mon->data->mlet != S_EEL && haseyes(mon->data) && mon->mcanmove + && !mon->mstun && !mon->mconf && !mon->msleeping + && mon->data->mmove >= 12) { + if (!nohands(mon->data) && !rn2(martial() ? 5 : 3)) { + pline("%s blocks your %skick.", Monnam(mon), + clumsy ? "clumsy " : ""); + (void) passive(mon, FALSE, 1, AT_KICK, FALSE); + return; + } else { + maybe_mnexto(mon); + if (mon->mx != x || mon->my != y) { + if (glyph_is_invisible(levl[x][y].glyph)) { + unmap_object(x, y); + newsym(x, y); + } + pline("%s %s, %s evading your %skick.", Monnam(mon), + (!level.flags.noteleport && can_teleport(mon->data)) + ? "teleports" + : is_floater(mon->data) + ? "floats" + : is_flyer(mon->data) ? "swoops" + : (nolimbs(mon->data) + || slithy(mon->data)) + ? "slides" + : "jumps", + clumsy ? "easily" : "nimbly", clumsy ? "clumsy " : ""); + (void) passive(mon, FALSE, 1, AT_KICK, FALSE); + return; + } + } + } + kickdmg(mon, clumsy); } /* @@ -273,96 +295,102 @@ ghitm(mtmp, gold) register struct monst *mtmp; register struct obj *gold; { - boolean msg_given = FALSE; + boolean msg_given = FALSE; - if (!likes_gold(mtmp->data) && !mtmp->isshk && !mtmp->ispriest && - !mtmp->isgd && !is_mercenary(mtmp->data)) { - wakeup(mtmp); - } else if (!mtmp->mcanmove) { - /* too light to do real damage */ - if (canseemon(mtmp)) { - pline_The("%s harmlessly %s %s.", xname(gold), - otense(gold, "hit"), mon_nam(mtmp)); - msg_given = TRUE; - } - } else { - long umoney, value = gold->quan * objects[gold->otyp].oc_cost; + if (!likes_gold(mtmp->data) && !mtmp->isshk && !mtmp->ispriest + && !mtmp->isgd && !is_mercenary(mtmp->data)) { + wakeup(mtmp); + } else if (!mtmp->mcanmove) { + /* too light to do real damage */ + if (canseemon(mtmp)) { + pline_The("%s harmlessly %s %s.", xname(gold), + otense(gold, "hit"), mon_nam(mtmp)); + msg_given = TRUE; + } + } else { + long umoney, value = gold->quan * objects[gold->otyp].oc_cost; - mtmp->msleeping = 0; - finish_meating(mtmp); - if (!mtmp->isgd && !rn2(4)) /* not always pleasing */ - setmangry(mtmp); - /* greedy monsters catch gold */ - if (cansee(mtmp->mx, mtmp->my)) - pline("%s catches the gold.", Monnam(mtmp)); - (void)mpickobj(mtmp, gold); - gold = (struct obj *)0; /* obj has been freed */ - if (mtmp->isshk) { - long robbed = ESHK(mtmp)->robbed; + mtmp->msleeping = 0; + finish_meating(mtmp); + if (!mtmp->isgd && !rn2(4)) /* not always pleasing */ + setmangry(mtmp); + /* greedy monsters catch gold */ + if (cansee(mtmp->mx, mtmp->my)) + pline("%s catches the gold.", Monnam(mtmp)); + (void) mpickobj(mtmp, gold); + gold = (struct obj *) 0; /* obj has been freed */ + if (mtmp->isshk) { + long robbed = ESHK(mtmp)->robbed; - if (robbed) { - robbed -= value; - if (robbed < 0L) robbed = 0L; - pline_The("amount %scovers %s recent losses.", - !robbed ? "" : "partially ", - mhis(mtmp)); - ESHK(mtmp)->robbed = robbed; - if(!robbed) - make_happy_shk(mtmp, FALSE); - } else { - if(mtmp->mpeaceful) { - ESHK(mtmp)->credit += value; - You("have %ld %s in credit.", - ESHK(mtmp)->credit, - currency(ESHK(mtmp)->credit)); - } else verbalize("Thanks, scum!"); - } - } else if (mtmp->ispriest) { - if (mtmp->mpeaceful) - verbalize("Thank you for your contribution."); - else verbalize("Thanks, scum!"); - } else if (mtmp->isgd) { - umoney = money_cnt(invent); - /* Some of these are iffy, because a hostile guard - won't become peaceful and resume leading hero - out of the vault. If he did do that, player - could try fighting, then weasle out of being - killed by throwing his/her gold when losing. */ - verbalize(umoney ? "Drop the rest and follow me." : - hidden_gold() ? - "You still have hidden gold. Drop it now." : - mtmp->mpeaceful ? - "I'll take care of that; please move along." : - "I'll take that; now get moving."); - } else if (is_mercenary(mtmp->data)) { - long goldreqd = 0L; + if (robbed) { + robbed -= value; + if (robbed < 0L) + robbed = 0L; + pline_The("amount %scovers %s recent losses.", + !robbed ? "" : "partially ", mhis(mtmp)); + ESHK(mtmp)->robbed = robbed; + if (!robbed) + make_happy_shk(mtmp, FALSE); + } else { + if (mtmp->mpeaceful) { + ESHK(mtmp)->credit += value; + You("have %ld %s in credit.", ESHK(mtmp)->credit, + currency(ESHK(mtmp)->credit)); + } else + verbalize("Thanks, scum!"); + } + } else if (mtmp->ispriest) { + if (mtmp->mpeaceful) + verbalize("Thank you for your contribution."); + else + verbalize("Thanks, scum!"); + } else if (mtmp->isgd) { + umoney = money_cnt(invent); + /* Some of these are iffy, because a hostile guard + won't become peaceful and resume leading hero + out of the vault. If he did do that, player + could try fighting, then weasle out of being + killed by throwing his/her gold when losing. */ + verbalize( + umoney + ? "Drop the rest and follow me." + : hidden_gold() + ? "You still have hidden gold. Drop it now." + : mtmp->mpeaceful + ? "I'll take care of that; please move along." + : "I'll take that; now get moving."); + } else if (is_mercenary(mtmp->data)) { + long goldreqd = 0L; - if (rn2(3)) { - if (mtmp->data == &mons[PM_SOLDIER]) - goldreqd = 100L; - else if (mtmp->data == &mons[PM_SERGEANT]) - goldreqd = 250L; - else if (mtmp->data == &mons[PM_LIEUTENANT]) - goldreqd = 500L; - else if (mtmp->data == &mons[PM_CAPTAIN]) - goldreqd = 750L; + if (rn2(3)) { + if (mtmp->data == &mons[PM_SOLDIER]) + goldreqd = 100L; + else if (mtmp->data == &mons[PM_SERGEANT]) + goldreqd = 250L; + else if (mtmp->data == &mons[PM_LIEUTENANT]) + goldreqd = 500L; + else if (mtmp->data == &mons[PM_CAPTAIN]) + goldreqd = 750L; - if (goldreqd) { - umoney = money_cnt(invent); - if (value > goldreqd + - (umoney + u.ulevel * rn2(5)) / ACURR(A_CHA)) - mtmp->mpeaceful = TRUE; - } - } - if (mtmp->mpeaceful) - verbalize("That should do. Now beat it!"); - else verbalize("That's not enough, coward!"); - } - return TRUE; - } + if (goldreqd) { + umoney = money_cnt(invent); + if (value + > goldreqd + + (umoney + u.ulevel * rn2(5)) / ACURR(A_CHA)) + mtmp->mpeaceful = TRUE; + } + } + if (mtmp->mpeaceful) + verbalize("That should do. Now beat it!"); + else + verbalize("That's not enough, coward!"); + } + return TRUE; + } - if (!msg_given) miss(xname(gold), mtmp); - return FALSE; + if (!msg_given) + miss(xname(gold), mtmp); + return FALSE; } /* container is kicked, dropped, thrown or otherwise impacted by player. @@ -370,65 +398,68 @@ register struct obj *gold; void container_impact_dmg(obj, x, y) struct obj *obj; -xchar x, y; /* coordinates where object was before the impact, not after */ +xchar x, y; /* coordinates where object was before the impact, not after */ { - struct monst *shkp; - struct obj *otmp, *otmp2; - long loss = 0L; - boolean costly, insider, frominv; + struct monst *shkp; + struct obj *otmp, *otmp2; + long loss = 0L; + boolean costly, insider, frominv; - /* only consider normal containers */ - if (!Is_container(obj) || !Has_contents(obj) || Is_mbag(obj)) return; + /* only consider normal containers */ + if (!Is_container(obj) || !Has_contents(obj) || Is_mbag(obj)) + return; - costly = ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) && - costly_spot(x, y)); - insider = (*u.ushops && inside_shop(u.ux, u.uy) && - *in_rooms(x, y, SHOPBASE) == *u.ushops); - /* if dropped or thrown, shop ownership flags are set on this obj */ - frominv = (obj != kickedobj); + costly = ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) + && costly_spot(x, y)); + insider = (*u.ushops && inside_shop(u.ux, u.uy) + && *in_rooms(x, y, SHOPBASE) == *u.ushops); + /* if dropped or thrown, shop ownership flags are set on this obj */ + frominv = (obj != kickedobj); - for (otmp = obj->cobj; otmp; otmp = otmp2) { - const char *result = (char *)0; + for (otmp = obj->cobj; otmp; otmp = otmp2) { + const char *result = (char *) 0; - otmp2 = otmp->nobj; - if (objects[otmp->otyp].oc_material == GLASS && - otmp->oclass != GEM_CLASS && !obj_resists(otmp, 33, 100)) { - result = "shatter"; - } else if (otmp->otyp == EGG && !rn2(3)) { - result = "cracking"; - } - if (result) { - if (otmp->otyp == MIRROR) change_luck(-2); + otmp2 = otmp->nobj; + if (objects[otmp->otyp].oc_material == GLASS + && otmp->oclass != GEM_CLASS && !obj_resists(otmp, 33, 100)) { + result = "shatter"; + } else if (otmp->otyp == EGG && !rn2(3)) { + result = "cracking"; + } + if (result) { + if (otmp->otyp == MIRROR) + change_luck(-2); - /* eggs laid by you. penalty is -1 per egg, max 5, - * but it's always exactly 1 that breaks */ - if (otmp->otyp == EGG && otmp->spe && otmp->corpsenm >= LOW_PM) - change_luck(-1); - You_hear("a muffled %s.", result); - if (costly) { - if (frominv && !otmp->unpaid) otmp->no_charge = 1; - loss += stolen_value(otmp, x, y, - (boolean)shkp->mpeaceful, TRUE); - } - if (otmp->quan > 1L) { - useup(otmp); - } else { - obj_extract_self(otmp); - obfree(otmp, (struct obj *) 0); - } - /* contents of this container are no longer known */ - obj->cknown = 0; - } - } - if (costly && loss) { - if (!insider) { - You("caused %ld %s worth of damage!", loss, currency(loss)); - make_angry_shk(shkp, x, y); - } else { - You("owe %s %ld %s for objects destroyed.", - mon_nam(shkp), loss, currency(loss)); - } - } + /* eggs laid by you. penalty is -1 per egg, max 5, + * but it's always exactly 1 that breaks */ + if (otmp->otyp == EGG && otmp->spe && otmp->corpsenm >= LOW_PM) + change_luck(-1); + You_hear("a muffled %s.", result); + if (costly) { + if (frominv && !otmp->unpaid) + otmp->no_charge = 1; + loss += + stolen_value(otmp, x, y, (boolean) shkp->mpeaceful, TRUE); + } + if (otmp->quan > 1L) { + useup(otmp); + } else { + obj_extract_self(otmp); + obfree(otmp, (struct obj *) 0); + } + /* contents of this container are no longer known */ + obj->cknown = 0; + } + } + if (costly && loss) { + if (!insider) { + You("caused %ld %s worth of damage!", loss, currency(loss)); + make_angry_shk(shkp, x, y); + } else { + You("owe %s %ld %s for objects destroyed.", mon_nam(shkp), loss, + currency(loss)); + } + } } /* jacket around really_kick_object */ @@ -441,9 +472,9 @@ xchar x, y; /* if a pile, the "top" object gets kicked */ kickedobj = level.objects[x][y]; if (kickedobj) { - /* kick object; if doing is fatal, done() will clean up kickedobj */ - res = really_kick_object(x, y); - kickedobj = (struct obj *)0; + /* kick object; if doing is fatal, done() will clean up kickedobj */ + res = really_kick_object(x, y); + kickedobj = (struct obj *) 0; } return res; } @@ -453,215 +484,226 @@ STATIC_OVL int really_kick_object(x, y) xchar x, y; { - int range; - struct monst *mon, *shkp = 0; - struct trap *trap; - char bhitroom; - boolean costly, isgold, slide = FALSE; + int range; + struct monst *mon, *shkp = 0; + struct trap *trap; + char bhitroom; + boolean costly, isgold, slide = FALSE; - /* kickedobj should always be set due to conditions of call */ - if (!kickedobj || kickedobj->otyp == BOULDER || - kickedobj == uball || kickedobj == uchain) - return 0; + /* kickedobj should always be set due to conditions of call */ + if (!kickedobj || kickedobj->otyp == BOULDER || kickedobj == uball + || kickedobj == uchain) + return 0; - if ((trap = t_at(x,y)) != 0 && - (((trap->ttyp == PIT || - trap->ttyp == SPIKED_PIT) && !Passes_walls) || - trap->ttyp == WEB)) { - if (!trap->tseen) find_trap(trap); - You_cant("kick %s that's in a %s!", something, - Hallucination ? "tizzy" : - (trap->ttyp == WEB) ? "web" : "pit"); - return 1; - } + if ((trap = t_at(x, y)) != 0 + && (((trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) && !Passes_walls) + || trap->ttyp == WEB)) { + if (!trap->tseen) + find_trap(trap); + You_cant("kick %s that's in a %s!", something, + Hallucination ? "tizzy" : (trap->ttyp == WEB) ? "web" + : "pit"); + return 1; + } - if(Fumbling && !rn2(3)) { - Your("clumsy kick missed."); - return(1); - } + if (Fumbling && !rn2(3)) { + Your("clumsy kick missed."); + return (1); + } - if (!uarmf && kickedobj->otyp == CORPSE && - touch_petrifies(&mons[kickedobj->corpsenm]) && - !Stone_resistance) { - You("kick %s with your bare %s.", - corpse_xname(kickedobj, (const char *)0, CXN_PFX_THE), - makeplural(body_part(FOOT))); - if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { - ; /* hero has been transformed but kick continues */ - } else { - /* normalize body shape here; foot, not body_part(FOOT) */ - Sprintf(killer.name, "kicking %s barefoot", - killer_xname(kickedobj)); - instapetrify(killer.name); - } - } + if (!uarmf && kickedobj->otyp == CORPSE + && touch_petrifies(&mons[kickedobj->corpsenm]) && !Stone_resistance) { + You("kick %s with your bare %s.", + corpse_xname(kickedobj, (const char *) 0, CXN_PFX_THE), + makeplural(body_part(FOOT))); + if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { + ; /* hero has been transformed but kick continues */ + } else { + /* normalize body shape here; foot, not body_part(FOOT) */ + Sprintf(killer.name, "kicking %s barefoot", + killer_xname(kickedobj)); + instapetrify(killer.name); + } + } - /* range < 2 means the object will not move. */ - /* maybe dexterity should also figure here. */ - range = (int)((ACURRSTR) / 2 - kickedobj->owt / 40); + /* range < 2 means the object will not move. */ + /* maybe dexterity should also figure here. */ + range = (int) ((ACURRSTR) / 2 - kickedobj->owt / 40); - if(martial()) range += rnd(3); + if (martial()) + range += rnd(3); - if (is_pool(x, y)) { - /* you're in the water too; significantly reduce range */ - range = range / 3 + 1; /* {1,2}=>1, {3,4,5}=>2, {6,7,8}=>3 */ - } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { - /* you're in air, since is_pool did not match */ - range += rnd(3); - } else { - if (is_ice(x, y)) range += rnd(3), slide = TRUE; - if (kickedobj->greased) range += rnd(3), slide = TRUE; - } + if (is_pool(x, y)) { + /* you're in the water too; significantly reduce range */ + range = range / 3 + 1; /* {1,2}=>1, {3,4,5}=>2, {6,7,8}=>3 */ + } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { + /* you're in air, since is_pool did not match */ + range += rnd(3); + } else { + if (is_ice(x, y)) + range += rnd(3), slide = TRUE; + if (kickedobj->greased) + range += rnd(3), slide = TRUE; + } - /* Mjollnir is magically too heavy to kick */ - if (kickedobj->oartifact == ART_MJOLLNIR) range = 1; + /* Mjollnir is magically too heavy to kick */ + if (kickedobj->oartifact == ART_MJOLLNIR) + range = 1; - /* see if the object has a place to move into */ - if(!ZAP_POS(levl[x+u.dx][y+u.dy].typ) || closed_door(x+u.dx, y+u.dy)) - range = 1; + /* see if the object has a place to move into */ + if (!ZAP_POS(levl[x + u.dx][y + u.dy].typ) + || closed_door(x + u.dx, y + u.dy)) + range = 1; - costly = (!(kickedobj->no_charge && !Has_contents(kickedobj)) && - (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 && - costly_spot(x, y)); - isgold = (kickedobj->oclass == COIN_CLASS); + costly = (!(kickedobj->no_charge && !Has_contents(kickedobj)) + && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 + && costly_spot(x, y)); + isgold = (kickedobj->oclass == COIN_CLASS); - if (IS_ROCK(levl[x][y].typ) || closed_door(x, y)) { - if ((!martial() && rn2(20) > ACURR(A_DEX)) || - IS_ROCK(levl[u.ux][u.uy].typ) || closed_door(u.ux, u.uy)) { - if (Blind) - pline("It doesn't come loose."); - else - pline("%s %sn't come loose.", - The(distant_name(kickedobj, xname)), - otense(kickedobj, "do")); - return (!rn2(3) || martial()); - } - if (Blind) - pline("It comes loose."); - else - pline("%s %s loose.", - The(distant_name(kickedobj, xname)), - otense(kickedobj, "come")); - obj_extract_self(kickedobj); - newsym(x, y); - if (costly && (!costly_spot(u.ux, u.uy) || - !index(u.urooms, *in_rooms(x, y, SHOPBASE)))) - addtobill(kickedobj, FALSE, FALSE, FALSE); - if (!flooreffects(kickedobj, u.ux, u.uy, "fall")) { - place_object(kickedobj, u.ux, u.uy); - stackobj(kickedobj); - newsym(u.ux, u.uy); - } - return 1; - } + if (IS_ROCK(levl[x][y].typ) || closed_door(x, y)) { + if ((!martial() && rn2(20) > ACURR(A_DEX)) + || IS_ROCK(levl[u.ux][u.uy].typ) || closed_door(u.ux, u.uy)) { + if (Blind) + pline("It doesn't come loose."); + else + pline("%s %sn't come loose.", + The(distant_name(kickedobj, xname)), + otense(kickedobj, "do")); + return (!rn2(3) || martial()); + } + if (Blind) + pline("It comes loose."); + else + pline("%s %s loose.", The(distant_name(kickedobj, xname)), + otense(kickedobj, "come")); + obj_extract_self(kickedobj); + newsym(x, y); + if (costly && (!costly_spot(u.ux, u.uy) + || !index(u.urooms, *in_rooms(x, y, SHOPBASE)))) + addtobill(kickedobj, FALSE, FALSE, FALSE); + if (!flooreffects(kickedobj, u.ux, u.uy, "fall")) { + place_object(kickedobj, u.ux, u.uy); + stackobj(kickedobj); + newsym(u.ux, u.uy); + } + return 1; + } - /* a box gets a chance of breaking open here */ - if (Is_box(kickedobj)) { - boolean otrp = kickedobj->otrapped; + /* a box gets a chance of breaking open here */ + if (Is_box(kickedobj)) { + boolean otrp = kickedobj->otrapped; - if (range < 2) pline("THUD!"); - container_impact_dmg(kickedobj, x, y); - if (kickedobj->olocked) { - if (!rn2(5) || (martial() && !rn2(2))) { - You("break open the lock!"); - breakchestlock(kickedobj, FALSE); - if (otrp) (void) chest_trap(kickedobj, LEG, FALSE); - return(1); - } - } else { - if (!rn2(3) || (martial() && !rn2(2))) { - pline_The("lid slams open, then falls shut."); - kickedobj->lknown = 1; - if (otrp) (void) chest_trap(kickedobj, LEG, FALSE); - return(1); - } - } - if(range < 2) return(1); - /* else let it fall through to the next cases... */ - } + if (range < 2) + pline("THUD!"); + container_impact_dmg(kickedobj, x, y); + if (kickedobj->olocked) { + if (!rn2(5) || (martial() && !rn2(2))) { + You("break open the lock!"); + breakchestlock(kickedobj, FALSE); + if (otrp) + (void) chest_trap(kickedobj, LEG, FALSE); + return (1); + } + } else { + if (!rn2(3) || (martial() && !rn2(2))) { + pline_The("lid slams open, then falls shut."); + kickedobj->lknown = 1; + if (otrp) + (void) chest_trap(kickedobj, LEG, FALSE); + return (1); + } + } + if (range < 2) + return (1); + /* else let it fall through to the next cases... */ + } - /* fragile objects should not be kicked */ - if (hero_breaks(kickedobj, kickedobj->ox, kickedobj->oy, FALSE)) - return 1; + /* fragile objects should not be kicked */ + if (hero_breaks(kickedobj, kickedobj->ox, kickedobj->oy, FALSE)) + return 1; - /* too heavy to move. range is calculated as potential distance from - * player, so range == 2 means the object may move up to one square - * from its current position - */ - if (range < 2) { - if (!Is_box(kickedobj)) pline("Thump!"); - return (!rn2(3) || martial()); - } + /* too heavy to move. range is calculated as potential distance from + * player, so range == 2 means the object may move up to one square + * from its current position + */ + if (range < 2) { + if (!Is_box(kickedobj)) + pline("Thump!"); + return (!rn2(3) || martial()); + } - if (kickedobj->quan > 1L) { - if (!isgold) { - kickedobj = splitobj(kickedobj, 1L); - } else { - if (rn2(20)) { - static NEARDATA const char * const flyingcoinmsg[] = { - "scatter the coins", - "knock coins all over the place", - "send coins flying in all directions", - }; + if (kickedobj->quan > 1L) { + if (!isgold) { + kickedobj = splitobj(kickedobj, 1L); + } else { + if (rn2(20)) { + static NEARDATA const char *const flyingcoinmsg[] = { + "scatter the coins", "knock coins all over the place", + "send coins flying in all directions", + }; - pline("Thwwpingg!"); - You("%s!", flyingcoinmsg[rn2(SIZE(flyingcoinmsg))]); - (void)scatter(x, y, rn2(3)+1, - VIS_EFFECTS|MAY_HIT, kickedobj); - newsym(x, y); - return 1; - } - if (kickedobj->quan > 300L) { - pline("Thump!"); - return(!rn2(3) || martial()); - } - } - } + pline("Thwwpingg!"); + You("%s!", flyingcoinmsg[rn2(SIZE(flyingcoinmsg))]); + (void) scatter(x, y, rn2(3) + 1, VIS_EFFECTS | MAY_HIT, + kickedobj); + newsym(x, y); + return 1; + } + if (kickedobj->quan > 300L) { + pline("Thump!"); + return (!rn2(3) || martial()); + } + } + } - if (slide && !Blind) - pline("Whee! %s %s across the %s.", Doname2(kickedobj), - otense(kickedobj, "slide"), surface(x,y)); + if (slide && !Blind) + pline("Whee! %s %s across the %s.", Doname2(kickedobj), + otense(kickedobj, "slide"), surface(x, y)); - if (costly && !isgold) addtobill(kickedobj, FALSE, FALSE, TRUE); - obj_extract_self(kickedobj); - (void) snuff_candle(kickedobj); - newsym(x, y); - mon = bhit(u.dx, u.dy, range, KICKED_WEAPON, - (int FDECL((*),(MONST_P,OBJ_P)))0, - (int FDECL((*),(OBJ_P,OBJ_P)))0, - &kickedobj); - if (!kickedobj) return 1; /* object broken */ + if (costly && !isgold) + addtobill(kickedobj, FALSE, FALSE, TRUE); + obj_extract_self(kickedobj); + (void) snuff_candle(kickedobj); + newsym(x, y); + mon = bhit(u.dx, u.dy, range, KICKED_WEAPON, + (int FDECL((*), (MONST_P, OBJ_P))) 0, + (int FDECL((*), (OBJ_P, OBJ_P))) 0, &kickedobj); + if (!kickedobj) + return 1; /* object broken */ - if (mon) { - if (mon->isshk && - kickedobj->where == OBJ_MINVENT && - kickedobj->ocarry == mon) - return 1; /* alert shk caught it */ - notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); - if (isgold ? ghitm(mon, kickedobj) : /* caught? */ - thitmonst(mon, kickedobj)) /* hit && used up? */ - return(1); - } + if (mon) { + if (mon->isshk && kickedobj->where == OBJ_MINVENT + && kickedobj->ocarry == mon) + return 1; /* alert shk caught it */ + notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); + if (isgold ? ghitm(mon, kickedobj) : /* caught? */ + thitmonst(mon, kickedobj)) /* hit && used up? */ + return (1); + } - /* the object might have fallen down a hole; - ship_object() will have taken care of shop billing */ - if (kickedobj->where == OBJ_MIGRATING) return 1; + /* the object might have fallen down a hole; + ship_object() will have taken care of shop billing */ + if (kickedobj->where == OBJ_MIGRATING) + return 1; - bhitroom = *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE); - if (costly && (!costly_spot(bhitpos.x, bhitpos.y) || - *in_rooms(x, y, SHOPBASE) != bhitroom)) { - if(isgold) - costly_gold(x, y, kickedobj->quan); - else (void)stolen_value(kickedobj, x, y, - (boolean)shkp->mpeaceful, FALSE); - } + bhitroom = *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE); + if (costly && (!costly_spot(bhitpos.x, bhitpos.y) + || *in_rooms(x, y, SHOPBASE) != bhitroom)) { + if (isgold) + costly_gold(x, y, kickedobj->quan); + else + (void) stolen_value(kickedobj, x, y, (boolean) shkp->mpeaceful, + FALSE); + } - if (flooreffects(kickedobj, bhitpos.x, bhitpos.y, "fall")) return 1; - if (kickedobj->unpaid) subfrombill(kickedobj, shkp); - place_object(kickedobj, bhitpos.x, bhitpos.y); - stackobj(kickedobj); - newsym(kickedobj->ox, kickedobj->oy); - return(1); + if (flooreffects(kickedobj, bhitpos.x, bhitpos.y, "fall")) + return 1; + if (kickedobj->unpaid) + subfrombill(kickedobj, shkp); + place_object(kickedobj, bhitpos.x, bhitpos.y); + stackobj(kickedobj); + newsym(kickedobj->ox, kickedobj->oy); + return (1); } /* cause of death if kicking kills kicker */ @@ -669,564 +711,607 @@ STATIC_OVL char * kickstr(buf) char *buf; { - const char *what; + const char *what; - if (kickedobj) what = killer_xname(kickedobj); - else if (maploc == &nowhere) what = "nothing"; - else if (IS_DOOR(maploc->typ)) what = "a door"; - else if (IS_TREE(maploc->typ)) what = "a tree"; - else if (IS_STWALL(maploc->typ)) what = "a wall"; - else if (IS_ROCK(maploc->typ)) what = "a rock"; - else if (IS_THRONE(maploc->typ)) what = "a throne"; - else if (IS_FOUNTAIN(maploc->typ)) what = "a fountain"; - else if (IS_GRAVE(maploc->typ)) what = "a headstone"; - else if (IS_SINK(maploc->typ)) what = "a sink"; - else if (IS_ALTAR(maploc->typ)) what = "an altar"; - else if (IS_DRAWBRIDGE(maploc->typ)) what = "a drawbridge"; - else if (maploc->typ == STAIRS) what = "the stairs"; - else if (maploc->typ == LADDER) what = "a ladder"; - else if (maploc->typ == IRONBARS) what = "an iron bar"; - else what = "something weird"; - return strcat(strcpy(buf, "kicking "), what); + if (kickedobj) + what = killer_xname(kickedobj); + else if (maploc == &nowhere) + what = "nothing"; + else if (IS_DOOR(maploc->typ)) + what = "a door"; + else if (IS_TREE(maploc->typ)) + what = "a tree"; + else if (IS_STWALL(maploc->typ)) + what = "a wall"; + else if (IS_ROCK(maploc->typ)) + what = "a rock"; + else if (IS_THRONE(maploc->typ)) + what = "a throne"; + else if (IS_FOUNTAIN(maploc->typ)) + what = "a fountain"; + else if (IS_GRAVE(maploc->typ)) + what = "a headstone"; + else if (IS_SINK(maploc->typ)) + what = "a sink"; + else if (IS_ALTAR(maploc->typ)) + what = "an altar"; + else if (IS_DRAWBRIDGE(maploc->typ)) + what = "a drawbridge"; + else if (maploc->typ == STAIRS) + what = "the stairs"; + else if (maploc->typ == LADDER) + what = "a ladder"; + else if (maploc->typ == IRONBARS) + what = "an iron bar"; + else + what = "something weird"; + return strcat(strcpy(buf, "kicking "), what); } int dokick() { - int x, y; - int avrg_attrib; - int dmg = 0, glyph, oldglyph = -1; - register struct monst *mtmp; - boolean no_kick = FALSE; - char buf[BUFSZ]; + int x, y; + int avrg_attrib; + int dmg = 0, glyph, oldglyph = -1; + register struct monst *mtmp; + boolean no_kick = FALSE; + char buf[BUFSZ]; - if (nolimbs(youmonst.data) || slithy(youmonst.data)) { - You("have no legs to kick with."); - no_kick = TRUE; - } else if (verysmall(youmonst.data)) { - You("are too small to do any kicking."); - no_kick = TRUE; - } else if (u.usteed) { - if (yn_function("Kick your steed?", ynchars, 'y') == 'y') { - You("kick %s.", mon_nam(u.usteed)); - kick_steed(); - return 1; - } else { - return 0; - } - } else if (Wounded_legs) { - /* note: jump() has similar code */ - long wl = (EWounded_legs & BOTH_SIDES); - const char *bp = body_part(LEG); + if (nolimbs(youmonst.data) || slithy(youmonst.data)) { + You("have no legs to kick with."); + no_kick = TRUE; + } else if (verysmall(youmonst.data)) { + You("are too small to do any kicking."); + no_kick = TRUE; + } else if (u.usteed) { + if (yn_function("Kick your steed?", ynchars, 'y') == 'y') { + You("kick %s.", mon_nam(u.usteed)); + kick_steed(); + return 1; + } else { + return 0; + } + } else if (Wounded_legs) { + /* note: jump() has similar code */ + long wl = (EWounded_legs & BOTH_SIDES); + const char *bp = body_part(LEG); - if (wl == BOTH_SIDES) bp = makeplural(bp); - Your("%s%s %s in no shape for kicking.", - (wl == LEFT_SIDE) ? "left " : - (wl == RIGHT_SIDE) ? "right " : "", - bp, (wl == BOTH_SIDES) ? "are" : "is"); - no_kick = TRUE; - } else if (near_capacity() > SLT_ENCUMBER) { - Your("load is too heavy to balance yourself for a kick."); - no_kick = TRUE; - } else if (youmonst.data->mlet == S_LIZARD) { - Your("legs cannot kick effectively."); - no_kick = TRUE; - } else if (u.uinwater && !rn2(2)) { - Your("slow motion kick doesn't hit anything."); - no_kick = TRUE; - } else if (u.utrap) { - no_kick = TRUE; - switch (u.utraptype) { - case TT_PIT: - if (!Passes_walls) - pline("There's not enough room to kick down here."); - else no_kick = FALSE; - break; - case TT_WEB: - case TT_BEARTRAP: - You_cant("move your %s!", body_part(LEG)); - break; - default: - break; - } - } + if (wl == BOTH_SIDES) + bp = makeplural(bp); + Your("%s%s %s in no shape for kicking.", + (wl == LEFT_SIDE) ? "left " : (wl == RIGHT_SIDE) ? "right " : "", + bp, (wl == BOTH_SIDES) ? "are" : "is"); + no_kick = TRUE; + } else if (near_capacity() > SLT_ENCUMBER) { + Your("load is too heavy to balance yourself for a kick."); + no_kick = TRUE; + } else if (youmonst.data->mlet == S_LIZARD) { + Your("legs cannot kick effectively."); + no_kick = TRUE; + } else if (u.uinwater && !rn2(2)) { + Your("slow motion kick doesn't hit anything."); + no_kick = TRUE; + } else if (u.utrap) { + no_kick = TRUE; + switch (u.utraptype) { + case TT_PIT: + if (!Passes_walls) + pline("There's not enough room to kick down here."); + else + no_kick = FALSE; + break; + case TT_WEB: + case TT_BEARTRAP: + You_cant("move your %s!", body_part(LEG)); + break; + default: + break; + } + } - if (no_kick) { - /* ignore direction typed before player notices kick failed */ - display_nhwindow(WIN_MESSAGE, TRUE); /* --More-- */ - return 0; - } + if (no_kick) { + /* ignore direction typed before player notices kick failed */ + display_nhwindow(WIN_MESSAGE, TRUE); /* --More-- */ + return 0; + } - if(!getdir((char *)0)) return(0); - if(!u.dx && !u.dy) return(0); + if (!getdir((char *) 0)) + return (0); + if (!u.dx && !u.dy) + return (0); - x = u.ux + u.dx; - y = u.uy + u.dy; + x = u.ux + u.dx; + y = u.uy + u.dy; - /* KMH -- Kicking boots always succeed */ - if (uarmf && uarmf->otyp == KICKING_BOOTS) - avrg_attrib = 99; - else - avrg_attrib = (ACURRSTR+ACURR(A_DEX)+ACURR(A_CON))/3; + /* KMH -- Kicking boots always succeed */ + if (uarmf && uarmf->otyp == KICKING_BOOTS) + avrg_attrib = 99; + else + avrg_attrib = (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 3; - if(u.uswallow) { - switch(rn2(3)) { - case 0: You_cant("move your %s!", body_part(LEG)); - break; - case 1: if (is_animal(u.ustuck->data)) { - pline("%s burps loudly.", Monnam(u.ustuck)); - break; - } - default: Your("feeble kick has no effect."); break; - } - return(1); - } else if(u.utrap && u.utraptype == TT_PIT) { - /* must be Passes_walls */ - You("kick at the side of the pit."); - return 1; - } - if (Levitation) { - int xx, yy; + if (u.uswallow) { + switch (rn2(3)) { + case 0: + You_cant("move your %s!", body_part(LEG)); + break; + case 1: + if (is_animal(u.ustuck->data)) { + pline("%s burps loudly.", Monnam(u.ustuck)); + break; + } + default: + Your("feeble kick has no effect."); + break; + } + return (1); + } else if (u.utrap && u.utraptype == TT_PIT) { + /* must be Passes_walls */ + You("kick at the side of the pit."); + return 1; + } + if (Levitation) { + int xx, yy; - xx = u.ux - u.dx; - yy = u.uy - u.dy; - /* doors can be opened while levitating, so they must be - * reachable for bracing purposes - * Possible extension: allow bracing against stuff on the side? - */ - if (isok(xx,yy) && !IS_ROCK(levl[xx][yy].typ) && - !IS_DOOR(levl[xx][yy].typ) && - (!Is_airlevel(&u.uz) || !OBJ_AT(xx,yy))) { - You("have nothing to brace yourself against."); - return(0); - } - } + xx = u.ux - u.dx; + yy = u.uy - u.dy; + /* doors can be opened while levitating, so they must be + * reachable for bracing purposes + * Possible extension: allow bracing against stuff on the side? + */ + if (isok(xx, yy) && !IS_ROCK(levl[xx][yy].typ) + && !IS_DOOR(levl[xx][yy].typ) + && (!Is_airlevel(&u.uz) || !OBJ_AT(xx, yy))) { + You("have nothing to brace yourself against."); + return (0); + } + } - mtmp = isok(x, y) ? m_at(x, y) : 0; - /* might not kick monster if it is hidden and becomes revealed, - if it is peaceful and player declines to attack, or if the - hero passes out due to enbumbrance with low hp; context.move - will be 1 unless player declines to kick peaceful monster */ - if (mtmp) { - oldglyph = glyph_at(x, y); - if (!maybe_kick_monster(mtmp, x, y)) - return context.move; - } + mtmp = isok(x, y) ? m_at(x, y) : 0; + /* might not kick monster if it is hidden and becomes revealed, + if it is peaceful and player declines to attack, or if the + hero passes out due to enbumbrance with low hp; context.move + will be 1 unless player declines to kick peaceful monster */ + if (mtmp) { + oldglyph = glyph_at(x, y); + if (!maybe_kick_monster(mtmp, x, y)) + return context.move; + } - wake_nearby(); - u_wipe_engr(2); + wake_nearby(); + u_wipe_engr(2); - if (!isok(x, y)) { - maploc = &nowhere; - goto ouch; - } - maploc = &levl[x][y]; + if (!isok(x, y)) { + maploc = &nowhere; + goto ouch; + } + maploc = &levl[x][y]; - /* - * The next five tests should stay in their present order: - * monsters, pools, objects, non-doors, doors. - * - * [FIXME: Monsters who are hidden underneath objects or - * in pools should lead to hero kicking the concealment - * rather than the monster, probably exposing the hidden - * monster in the process. And monsters who are hidden on - * ceiling shouldn't be kickable (unless hero is flying?); - * kicking toward them should just target whatever is on - * the floor at that spot.] - */ + /* + * The next five tests should stay in their present order: + * monsters, pools, objects, non-doors, doors. + * + * [FIXME: Monsters who are hidden underneath objects or + * in pools should lead to hero kicking the concealment + * rather than the monster, probably exposing the hidden + * monster in the process. And monsters who are hidden on + * ceiling shouldn't be kickable (unless hero is flying?); + * kicking toward them should just target whatever is on + * the floor at that spot.] + */ - if (mtmp) { - /* save mtmp->data (for recoil) in case mtmp gets killed */ - struct permonst *mdat = mtmp->data; + if (mtmp) { + /* save mtmp->data (for recoil) in case mtmp gets killed */ + struct permonst *mdat = mtmp->data; - kick_monster(mtmp, x, y); - glyph = glyph_at(x, y); - /* see comment in attack_checks() */ - if (mtmp->mhp <= 0) { /* DEADMONSTER() */ - /* if we mapped an invisible monster and immediately - killed it, we don't want to forget what we thought - was there before the kick */ - if (glyph != oldglyph && glyph_is_invisible(glyph)) - show_glyph(x, y, oldglyph); - } else if (!canspotmon(mtmp) && - /* check ; monster that evades kick by jumping - to an unseen square doesn't leave an I behind */ - mtmp->mx == x && mtmp->my == y && - !glyph_is_invisible(glyph) && - !(u.uswallow && mtmp == u.ustuck)) { - map_invisible(x, y); - } - /* recoil if floating */ - if ((Is_airlevel(&u.uz) || Levitation) && context.move) { - int range; + kick_monster(mtmp, x, y); + glyph = glyph_at(x, y); + /* see comment in attack_checks() */ + if (mtmp->mhp <= 0) { /* DEADMONSTER() */ + /* if we mapped an invisible monster and immediately + killed it, we don't want to forget what we thought + was there before the kick */ + if (glyph != oldglyph && glyph_is_invisible(glyph)) + show_glyph(x, y, oldglyph); + } else if (!canspotmon(mtmp) && + /* check ; monster that evades kick by jumping + to an unseen square doesn't leave an I behind */ + mtmp->mx == x && mtmp->my == y + && !glyph_is_invisible(glyph) + && !(u.uswallow && mtmp == u.ustuck)) { + map_invisible(x, y); + } + /* recoil if floating */ + if ((Is_airlevel(&u.uz) || Levitation) && context.move) { + int range; - range = ((int)youmonst.data->cwt - + (weight_cap() + inv_weight())); - if (range < 1) range = 1; /* divide by zero avoidance */ - range = (3 * (int)mdat->cwt) / range; + range = + ((int) youmonst.data->cwt + (weight_cap() + inv_weight())); + if (range < 1) + range = 1; /* divide by zero avoidance */ + range = (3 * (int) mdat->cwt) / range; - if(range < 1) range = 1; - hurtle(-u.dx, -u.dy, range, TRUE); - } - return(1); - } - if (glyph_is_invisible(levl[x][y].glyph)) { - unmap_object(x, y); - newsym(x, y); - } - if (is_pool(x, y) ^ !!u.uinwater) { - /* objects normally can't be removed from water by kicking */ - You("splash some water around."); - return 1; - } + if (range < 1) + range = 1; + hurtle(-u.dx, -u.dy, range, TRUE); + } + return (1); + } + if (glyph_is_invisible(levl[x][y].glyph)) { + unmap_object(x, y); + newsym(x, y); + } + if (is_pool(x, y) ^ !!u.uinwater) { + /* objects normally can't be removed from water by kicking */ + You("splash some water around."); + return 1; + } - if (OBJ_AT(x, y) && - (!Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) - || sobj_at(BOULDER,x,y))) { - if(kick_object(x, y)) { - if(Is_airlevel(&u.uz)) - hurtle(-u.dx, -u.dy, 1, TRUE); /* assume it's light */ - return(1); - } - goto ouch; - } + if (OBJ_AT(x, y) && (!Levitation || Is_airlevel(&u.uz) + || Is_waterlevel(&u.uz) || sobj_at(BOULDER, x, y))) { + if (kick_object(x, y)) { + if (Is_airlevel(&u.uz)) + hurtle(-u.dx, -u.dy, 1, TRUE); /* assume it's light */ + return (1); + } + goto ouch; + } - if(!IS_DOOR(maploc->typ)) { - if(maploc->typ == SDOOR) { - if(!Levitation && rn2(30) < avrg_attrib) { - cvt_sdoor_to_door(maploc); /* ->typ = DOOR */ - pline("Crash! %s a secret door!", - /* don't "kick open" when it's locked - unless it also happens to be trapped */ - (maploc->doormask & (D_LOCKED|D_TRAPPED)) == D_LOCKED ? - "Your kick uncovers" : "You kick open"); - exercise(A_DEX, TRUE); - if(maploc->doormask & D_TRAPPED) { - maploc->doormask = D_NODOOR; - b_trapped("door", FOOT); - } else if (maploc->doormask != D_NODOOR && - !(maploc->doormask & D_LOCKED)) - maploc->doormask = D_ISOPEN; - if (Blind) - feel_location(x,y); /* we know it's gone */ - else - newsym(x,y); - if (maploc->doormask == D_ISOPEN || - maploc->doormask == D_NODOOR) - unblock_point(x,y); /* vision */ - return(1); - } else goto ouch; - } - if(maploc->typ == SCORR) { - if(!Levitation && rn2(30) < avrg_attrib) { - pline("Crash! You kick open a secret passage!"); - exercise(A_DEX, TRUE); - maploc->typ = CORR; - if (Blind) - feel_location(x,y); /* we know it's gone */ - else - newsym(x,y); - unblock_point(x,y); /* vision */ - return(1); - } else goto ouch; - } - if(IS_THRONE(maploc->typ)) { - register int i; - if(Levitation) goto dumb; - if((Luck < 0 || maploc->doormask) && !rn2(3)) { - maploc->typ = ROOM; - maploc->doormask = 0; /* don't leave loose ends.. */ - (void) mkgold((long)rnd(200), x, y); - if (Blind) - pline("CRASH! You destroy it."); - else { - pline("CRASH! You destroy the throne."); - newsym(x, y); - } - exercise(A_DEX, TRUE); - return(1); - } else if(Luck > 0 && !rn2(3) && !maploc->looted) { - (void) mkgold((long) rn1(201, 300), x, y); - i = Luck + 1; - if(i > 6) i = 6; - while(i--) - (void) mksobj_at(rnd_class(DILITHIUM_CRYSTAL, - LUCKSTONE-1), x, y, FALSE, TRUE); - if (Blind) - You("kick %s loose!", something); - else { - You("kick loose some ornamental coins and gems!"); - newsym(x, y); - } - /* prevent endless milking */ - maploc->looted = T_LOOTED; - return(1); - } else if (!rn2(4)) { - if(dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)) { - fall_through(FALSE); - return(1); - } else goto ouch; - } - goto ouch; - } - if(IS_ALTAR(maploc->typ)) { - if(Levitation) goto dumb; - You("kick %s.",(Blind ? something : "the altar")); - if(!rn2(3)) goto ouch; - altar_wrath(x, y); - exercise(A_DEX, TRUE); - return(1); - } - if(IS_FOUNTAIN(maploc->typ)) { - if(Levitation) goto dumb; - You("kick %s.",(Blind ? something : "the fountain")); - if(!rn2(3)) goto ouch; - /* make metal boots rust */ - if(uarmf && rn2(3)) - if (water_damage(uarmf, "metal boots", TRUE) == - ER_NOTHING) { - Your("boots get wet."); - /* could cause short-lived fumbling here */ - } - exercise(A_DEX, TRUE); - return(1); - } - if (IS_GRAVE(maploc->typ)) { - if(Levitation) goto dumb; - if (rn2(4)) goto ouch; - exercise(A_WIS, FALSE); - if (Role_if(PM_ARCHEOLOGIST) || - Role_if(PM_SAMURAI) || - ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10))) { - adjalign(-sgn(u.ualign.type)); - } - maploc->typ = ROOM; - maploc->doormask = 0; - (void) mksobj_at(ROCK, x,y, TRUE, FALSE); - del_engr_at(x,y); - if (Blind) - pline("Crack! %s broke!", Something); - else { - pline_The("headstone topples over and breaks!"); - newsym(x,y); - } - return 1; - } - if(maploc->typ == IRONBARS) - goto ouch; - if(IS_TREE(maploc->typ)) { - struct obj *treefruit; - /* nothing, fruit or trouble? 75:23.5:1.5% */ - if (rn2(3)) { - if ( !rn2(6) && !(mvitals[PM_KILLER_BEE].mvflags & G_GONE) ) - You_hear("a low buzzing."); /* a warning */ - goto ouch; - } - if (rn2(15) && !(maploc->looted & TREE_LOOTED) && - (treefruit = rnd_treefruit_at(x, y))) { - long nfruit = 8L-rnl(7), nfall; - short frtype = treefruit->otyp; - treefruit->quan = nfruit; - if (is_plural(treefruit)) - pline("Some %s fall from the tree!", xname(treefruit)); - else - pline("%s falls from the tree!", An(xname(treefruit))); - nfall = scatter(x,y,2,MAY_HIT,treefruit); - if (nfall != nfruit) { - /* scatter left some in the tree, but treefruit - * may not refer to the correct object */ - treefruit = mksobj(frtype, TRUE, FALSE); - treefruit->quan = nfruit-nfall; - pline("%ld %s got caught in the branches.", - nfruit-nfall, xname(treefruit)); - dealloc_obj(treefruit); - } - exercise(A_DEX, TRUE); - exercise(A_WIS, TRUE); /* discovered a new food source! */ - newsym(x, y); - maploc->looted |= TREE_LOOTED; - return(1); - } else if (!(maploc->looted & TREE_SWARM)) { - int cnt = rnl(4) + 2; - int made = 0; - coord mm; - mm.x = x; mm.y = y; - while (cnt--) { - if (enexto(&mm, mm.x, mm.y, &mons[PM_KILLER_BEE]) - && makemon(&mons[PM_KILLER_BEE], - mm.x, mm.y, MM_ANGRY)) - made++; - } - if ( made ) - pline("You've attracted the tree's former occupants!"); - else - You("smell stale honey."); - maploc->looted |= TREE_SWARM; - return(1); - } - goto ouch; - } - if(IS_SINK(maploc->typ)) { - int gend = poly_gender(); - short washerndx = (gend == 1 || (gend == 2 && rn2(2))) ? - PM_INCUBUS : PM_SUCCUBUS; + if (!IS_DOOR(maploc->typ)) { + if (maploc->typ == SDOOR) { + if (!Levitation && rn2(30) < avrg_attrib) { + cvt_sdoor_to_door(maploc); /* ->typ = DOOR */ + pline("Crash! %s a secret door!", + /* don't "kick open" when it's locked + unless it also happens to be trapped */ + (maploc->doormask & (D_LOCKED | D_TRAPPED)) == D_LOCKED + ? "Your kick uncovers" + : "You kick open"); + exercise(A_DEX, TRUE); + if (maploc->doormask & D_TRAPPED) { + maploc->doormask = D_NODOOR; + b_trapped("door", FOOT); + } else if (maploc->doormask != D_NODOOR + && !(maploc->doormask & D_LOCKED)) + maploc->doormask = D_ISOPEN; + if (Blind) + feel_location(x, y); /* we know it's gone */ + else + newsym(x, y); + if (maploc->doormask == D_ISOPEN + || maploc->doormask == D_NODOOR) + unblock_point(x, y); /* vision */ + return (1); + } else + goto ouch; + } + if (maploc->typ == SCORR) { + if (!Levitation && rn2(30) < avrg_attrib) { + pline("Crash! You kick open a secret passage!"); + exercise(A_DEX, TRUE); + maploc->typ = CORR; + if (Blind) + feel_location(x, y); /* we know it's gone */ + else + newsym(x, y); + unblock_point(x, y); /* vision */ + return (1); + } else + goto ouch; + } + if (IS_THRONE(maploc->typ)) { + register int i; + if (Levitation) + goto dumb; + if ((Luck < 0 || maploc->doormask) && !rn2(3)) { + maploc->typ = ROOM; + maploc->doormask = 0; /* don't leave loose ends.. */ + (void) mkgold((long) rnd(200), x, y); + if (Blind) + pline("CRASH! You destroy it."); + else { + pline("CRASH! You destroy the throne."); + newsym(x, y); + } + exercise(A_DEX, TRUE); + return (1); + } else if (Luck > 0 && !rn2(3) && !maploc->looted) { + (void) mkgold((long) rn1(201, 300), x, y); + i = Luck + 1; + if (i > 6) + i = 6; + while (i--) + (void) mksobj_at( + rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE - 1), x, y, + FALSE, TRUE); + if (Blind) + You("kick %s loose!", something); + else { + You("kick loose some ornamental coins and gems!"); + newsym(x, y); + } + /* prevent endless milking */ + maploc->looted = T_LOOTED; + return (1); + } else if (!rn2(4)) { + if (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)) { + fall_through(FALSE); + return (1); + } else + goto ouch; + } + goto ouch; + } + if (IS_ALTAR(maploc->typ)) { + if (Levitation) + goto dumb; + You("kick %s.", (Blind ? something : "the altar")); + if (!rn2(3)) + goto ouch; + altar_wrath(x, y); + exercise(A_DEX, TRUE); + return (1); + } + if (IS_FOUNTAIN(maploc->typ)) { + if (Levitation) + goto dumb; + You("kick %s.", (Blind ? something : "the fountain")); + if (!rn2(3)) + goto ouch; + /* make metal boots rust */ + if (uarmf && rn2(3)) + if (water_damage(uarmf, "metal boots", TRUE) == ER_NOTHING) { + Your("boots get wet."); + /* could cause short-lived fumbling here */ + } + exercise(A_DEX, TRUE); + return (1); + } + if (IS_GRAVE(maploc->typ)) { + if (Levitation) + goto dumb; + if (rn2(4)) + goto ouch; + exercise(A_WIS, FALSE); + if (Role_if(PM_ARCHEOLOGIST) || Role_if(PM_SAMURAI) + || ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10))) { + adjalign(-sgn(u.ualign.type)); + } + maploc->typ = ROOM; + maploc->doormask = 0; + (void) mksobj_at(ROCK, x, y, TRUE, FALSE); + del_engr_at(x, y); + if (Blind) + pline("Crack! %s broke!", Something); + else { + pline_The("headstone topples over and breaks!"); + newsym(x, y); + } + return 1; + } + if (maploc->typ == IRONBARS) + goto ouch; + if (IS_TREE(maploc->typ)) { + struct obj *treefruit; + /* nothing, fruit or trouble? 75:23.5:1.5% */ + if (rn2(3)) { + if (!rn2(6) && !(mvitals[PM_KILLER_BEE].mvflags & G_GONE)) + You_hear("a low buzzing."); /* a warning */ + goto ouch; + } + if (rn2(15) && !(maploc->looted & TREE_LOOTED) + && (treefruit = rnd_treefruit_at(x, y))) { + long nfruit = 8L - rnl(7), nfall; + short frtype = treefruit->otyp; + treefruit->quan = nfruit; + if (is_plural(treefruit)) + pline("Some %s fall from the tree!", xname(treefruit)); + else + pline("%s falls from the tree!", An(xname(treefruit))); + nfall = scatter(x, y, 2, MAY_HIT, treefruit); + if (nfall != nfruit) { + /* scatter left some in the tree, but treefruit + * may not refer to the correct object */ + treefruit = mksobj(frtype, TRUE, FALSE); + treefruit->quan = nfruit - nfall; + pline("%ld %s got caught in the branches.", + nfruit - nfall, xname(treefruit)); + dealloc_obj(treefruit); + } + exercise(A_DEX, TRUE); + exercise(A_WIS, TRUE); /* discovered a new food source! */ + newsym(x, y); + maploc->looted |= TREE_LOOTED; + return (1); + } else if (!(maploc->looted & TREE_SWARM)) { + int cnt = rnl(4) + 2; + int made = 0; + coord mm; + mm.x = x; + mm.y = y; + while (cnt--) { + if (enexto(&mm, mm.x, mm.y, &mons[PM_KILLER_BEE]) + && makemon(&mons[PM_KILLER_BEE], mm.x, mm.y, + MM_ANGRY)) + made++; + } + if (made) + pline("You've attracted the tree's former occupants!"); + else + You("smell stale honey."); + maploc->looted |= TREE_SWARM; + return (1); + } + goto ouch; + } + if (IS_SINK(maploc->typ)) { + int gend = poly_gender(); + short washerndx = (gend == 1 || (gend == 2 && rn2(2))) + ? PM_INCUBUS + : PM_SUCCUBUS; - if(Levitation) goto dumb; - if(rn2(5)) { - if(!Deaf) - pline("Klunk! The pipes vibrate noisily."); - else pline("Klunk!"); - exercise(A_DEX, TRUE); - return(1); - } else if(!(maploc->looted & S_LPUDDING) && !rn2(3) && - !(mvitals[PM_BLACK_PUDDING].mvflags & G_GONE)) { - if (Blind) - You_hear("a gushing sound."); - else - pline("A %s ooze gushes up from the drain!", - hcolor(NH_BLACK)); - (void) makemon(&mons[PM_BLACK_PUDDING], - x, y, NO_MM_FLAGS); - exercise(A_DEX, TRUE); - newsym(x,y); - maploc->looted |= S_LPUDDING; - return(1); - } else if(!(maploc->looted & S_LDWASHER) && !rn2(3) && - !(mvitals[washerndx].mvflags & G_GONE)) { - /* can't resist... */ - pline("%s returns!", (Blind ? Something : - "The dish washer")); - if (makemon(&mons[washerndx], x, y, NO_MM_FLAGS)) - newsym(x,y); - maploc->looted |= S_LDWASHER; - exercise(A_DEX, TRUE); - return(1); - } else if(!rn2(3)) { - pline("Flupp! %s.", (Blind ? - "You hear a sloshing sound" : - "Muddy waste pops up from the drain")); - if(!(maploc->looted & S_LRING)) { /* once per sink */ - if (!Blind) - You_see("a ring shining in its midst."); - (void) mkobj_at(RING_CLASS, x, y, TRUE); - newsym(x, y); - exercise(A_DEX, TRUE); - exercise(A_WIS, TRUE); /* a discovery! */ - maploc->looted |= S_LRING; - } - return(1); - } - goto ouch; - } - if (maploc->typ == STAIRS || maploc->typ == LADDER || - IS_STWALL(maploc->typ)) { - if(!IS_STWALL(maploc->typ) && maploc->ladder == LA_DOWN) - goto dumb; -ouch: - pline("Ouch! That hurts!"); - exercise(A_DEX, FALSE); - exercise(A_STR, FALSE); - if (isok(x, y)) { - if (Blind) feel_location(x,y); /* we know we hit it */ - if (is_drawbridge_wall(x,y) >= 0) { - pline_The("drawbridge is unaffected."); - /* update maploc to refer to the drawbridge */ - (void) find_drawbridge(&x,&y); - maploc = &levl[x][y]; - } - } - if(!rn2(3)) set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); - dmg = rnd(ACURR(A_CON) > 15 ? 3 : 5); - losehp(Maybe_Half_Phys(dmg), kickstr(buf), - KILLED_BY); - if(Is_airlevel(&u.uz) || Levitation) - hurtle(-u.dx, -u.dy, rn1(2,4), TRUE); /* assume it's heavy */ - return(1); - } - goto dumb; - } + if (Levitation) + goto dumb; + if (rn2(5)) { + if (!Deaf) + pline("Klunk! The pipes vibrate noisily."); + else + pline("Klunk!"); + exercise(A_DEX, TRUE); + return (1); + } else if (!(maploc->looted & S_LPUDDING) && !rn2(3) + && !(mvitals[PM_BLACK_PUDDING].mvflags & G_GONE)) { + if (Blind) + You_hear("a gushing sound."); + else + pline("A %s ooze gushes up from the drain!", + hcolor(NH_BLACK)); + (void) makemon(&mons[PM_BLACK_PUDDING], x, y, NO_MM_FLAGS); + exercise(A_DEX, TRUE); + newsym(x, y); + maploc->looted |= S_LPUDDING; + return (1); + } else if (!(maploc->looted & S_LDWASHER) && !rn2(3) + && !(mvitals[washerndx].mvflags & G_GONE)) { + /* can't resist... */ + pline("%s returns!", (Blind ? Something : "The dish washer")); + if (makemon(&mons[washerndx], x, y, NO_MM_FLAGS)) + newsym(x, y); + maploc->looted |= S_LDWASHER; + exercise(A_DEX, TRUE); + return (1); + } else if (!rn2(3)) { + pline("Flupp! %s.", + (Blind ? "You hear a sloshing sound" + : "Muddy waste pops up from the drain")); + if (!(maploc->looted & S_LRING)) { /* once per sink */ + if (!Blind) + You_see("a ring shining in its midst."); + (void) mkobj_at(RING_CLASS, x, y, TRUE); + newsym(x, y); + exercise(A_DEX, TRUE); + exercise(A_WIS, TRUE); /* a discovery! */ + maploc->looted |= S_LRING; + } + return (1); + } + goto ouch; + } + if (maploc->typ == STAIRS || maploc->typ == LADDER + || IS_STWALL(maploc->typ)) { + if (!IS_STWALL(maploc->typ) && maploc->ladder == LA_DOWN) + goto dumb; + ouch: + pline("Ouch! That hurts!"); + exercise(A_DEX, FALSE); + exercise(A_STR, FALSE); + if (isok(x, y)) { + if (Blind) + feel_location(x, y); /* we know we hit it */ + if (is_drawbridge_wall(x, y) >= 0) { + pline_The("drawbridge is unaffected."); + /* update maploc to refer to the drawbridge */ + (void) find_drawbridge(&x, &y); + maploc = &levl[x][y]; + } + } + if (!rn2(3)) + set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); + dmg = rnd(ACURR(A_CON) > 15 ? 3 : 5); + losehp(Maybe_Half_Phys(dmg), kickstr(buf), KILLED_BY); + if (Is_airlevel(&u.uz) || Levitation) + hurtle(-u.dx, -u.dy, rn1(2, 4), TRUE); /* assume it's heavy */ + return (1); + } + goto dumb; + } - if(maploc->doormask == D_ISOPEN || - maploc->doormask == D_BROKEN || - maploc->doormask == D_NODOOR) { -dumb: - exercise(A_DEX, FALSE); - if (martial() || ACURR(A_DEX) >= 16 || rn2(3)) { - You("kick at empty space."); - if (Blind) feel_location(x,y); - } else { - pline("Dumb move! You strain a muscle."); - exercise(A_STR, FALSE); - set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); - } - if ((Is_airlevel(&u.uz) || Levitation) && rn2(2)) - hurtle(-u.dx, -u.dy, 1, TRUE); - return 1; /* uses a turn */ - } + if (maploc->doormask == D_ISOPEN || maploc->doormask == D_BROKEN + || maploc->doormask == D_NODOOR) { + dumb: + exercise(A_DEX, FALSE); + if (martial() || ACURR(A_DEX) >= 16 || rn2(3)) { + You("kick at empty space."); + if (Blind) + feel_location(x, y); + } else { + pline("Dumb move! You strain a muscle."); + exercise(A_STR, FALSE); + set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); + } + if ((Is_airlevel(&u.uz) || Levitation) && rn2(2)) + hurtle(-u.dx, -u.dy, 1, TRUE); + return 1; /* uses a turn */ + } - /* not enough leverage to kick open doors while levitating */ - if(Levitation) goto ouch; + /* not enough leverage to kick open doors while levitating */ + if (Levitation) + goto ouch; - exercise(A_DEX, TRUE); - /* door is known to be CLOSED or LOCKED */ - if(rnl(35) < avrg_attrib + (!martial() ? 0 : ACURR(A_DEX))) { - boolean shopdoor = *in_rooms(x, y, SHOPBASE) ? TRUE : FALSE; - /* break the door */ - if(maploc->doormask & D_TRAPPED) { - if (flags.verbose) You("kick the door."); - exercise(A_STR, FALSE); - maploc->doormask = D_NODOOR; - b_trapped("door", FOOT); - } else if(ACURR(A_STR) > 18 && !rn2(5) && !shopdoor) { - pline("As you kick the door, it shatters to pieces!"); - exercise(A_STR, TRUE); - maploc->doormask = D_NODOOR; - } else { - pline("As you kick the door, it crashes open!"); - exercise(A_STR, TRUE); - maploc->doormask = D_BROKEN; - } - if (Blind) - feel_location(x,y); /* we know we broke it */ - else - newsym(x,y); - unblock_point(x,y); /* vision */ - if (shopdoor) { - add_damage(x, y, 400L); - pay_for_damage("break", FALSE); - } - if (in_town(x, y)) - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_watch(mtmp->data) && - couldsee(mtmp->mx, mtmp->my) && - mtmp->mpeaceful) { - mon_yells(mtmp, "Halt, thief! You're under arrest!"); - (void) angry_guards(FALSE); - break; - } - } - } else { - if (Blind) feel_location(x,y); /* we know we hit it */ - exercise(A_STR, TRUE); - pline("WHAMMM!!!"); - if (in_town(x, y)) - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_watch(mtmp->data) && - mtmp->mpeaceful && couldsee(mtmp->mx, mtmp->my)) { - if(levl[x][y].looted & D_WARNED) { - mon_yells(mtmp, "Halt, vandal! You're under arrest!"); - (void) angry_guards(FALSE); - } else { - mon_yells(mtmp, "Hey, stop damaging that door!"); - levl[x][y].looted |= D_WARNED; - } - break; - } - } - } - return(1); + exercise(A_DEX, TRUE); + /* door is known to be CLOSED or LOCKED */ + if (rnl(35) < avrg_attrib + (!martial() ? 0 : ACURR(A_DEX))) { + boolean shopdoor = *in_rooms(x, y, SHOPBASE) ? TRUE : FALSE; + /* break the door */ + if (maploc->doormask & D_TRAPPED) { + if (flags.verbose) + You("kick the door."); + exercise(A_STR, FALSE); + maploc->doormask = D_NODOOR; + b_trapped("door", FOOT); + } else if (ACURR(A_STR) > 18 && !rn2(5) && !shopdoor) { + pline("As you kick the door, it shatters to pieces!"); + exercise(A_STR, TRUE); + maploc->doormask = D_NODOOR; + } else { + pline("As you kick the door, it crashes open!"); + exercise(A_STR, TRUE); + maploc->doormask = D_BROKEN; + } + if (Blind) + feel_location(x, y); /* we know we broke it */ + else + newsym(x, y); + unblock_point(x, y); /* vision */ + if (shopdoor) { + add_damage(x, y, 400L); + pay_for_damage("break", FALSE); + } + if (in_town(x, y)) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_watch(mtmp->data) && couldsee(mtmp->mx, mtmp->my) + && mtmp->mpeaceful) { + mon_yells(mtmp, "Halt, thief! You're under arrest!"); + (void) angry_guards(FALSE); + break; + } + } + } else { + if (Blind) + feel_location(x, y); /* we know we hit it */ + exercise(A_STR, TRUE); + pline("WHAMMM!!!"); + if (in_town(x, y)) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_watch(mtmp->data) && mtmp->mpeaceful + && couldsee(mtmp->mx, mtmp->my)) { + if (levl[x][y].looted & D_WARNED) { + mon_yells(mtmp, + "Halt, vandal! You're under arrest!"); + (void) angry_guards(FALSE); + } else { + mon_yells(mtmp, "Hey, stop damaging that door!"); + levl[x][y].looted |= D_WARNED; + } + break; + } + } + } + return (1); } STATIC_OVL void @@ -1234,152 +1319,156 @@ drop_to(cc, loc) coord *cc; schar loc; { - /* cover all the MIGR_xxx choices generated by down_gate() */ - switch (loc) { - case MIGR_RANDOM: /* trap door or hole */ - if (Is_stronghold(&u.uz)) { - cc->x = valley_level.dnum; - cc->y = valley_level.dlevel; - break; - } else if (In_endgame(&u.uz) || Is_botlevel(&u.uz)) { - cc->y = cc->x = 0; - break; - } /* else fall to the next cases */ - case MIGR_STAIRS_UP: - case MIGR_LADDER_UP: - cc->x = u.uz.dnum; - cc->y = u.uz.dlevel + 1; - break; - case MIGR_SSTAIRS: - cc->x = sstairs.tolev.dnum; - cc->y = sstairs.tolev.dlevel; - break; - default: - case MIGR_NOWHERE: - /* y==0 means "nowhere", in which case x doesn't matter */ - cc->y = cc->x = 0; - break; - } + /* cover all the MIGR_xxx choices generated by down_gate() */ + switch (loc) { + case MIGR_RANDOM: /* trap door or hole */ + if (Is_stronghold(&u.uz)) { + cc->x = valley_level.dnum; + cc->y = valley_level.dlevel; + break; + } else if (In_endgame(&u.uz) || Is_botlevel(&u.uz)) { + cc->y = cc->x = 0; + break; + } /* else fall to the next cases */ + case MIGR_STAIRS_UP: + case MIGR_LADDER_UP: + cc->x = u.uz.dnum; + cc->y = u.uz.dlevel + 1; + break; + case MIGR_SSTAIRS: + cc->x = sstairs.tolev.dnum; + cc->y = sstairs.tolev.dlevel; + break; + default: + case MIGR_NOWHERE: + /* y==0 means "nowhere", in which case x doesn't matter */ + cc->y = cc->x = 0; + break; + } } /* player or missile impacts location, causing objects to fall down */ void impact_drop(missile, x, y, dlev) -struct obj *missile; /* caused impact, won't drop itself */ -xchar x, y; /* location affected */ -xchar dlev; /* if !0 send to dlev near player */ +struct obj *missile; /* caused impact, won't drop itself */ +xchar x, y; /* location affected */ +xchar dlev; /* if !0 send to dlev near player */ { - schar toloc; - register struct obj *obj, *obj2; - register struct monst *shkp; - long oct, dct, price, debit, robbed; - boolean angry, costly, isrock; - coord cc; + schar toloc; + register struct obj *obj, *obj2; + register struct monst *shkp; + long oct, dct, price, debit, robbed; + boolean angry, costly, isrock; + coord cc; - if(!OBJ_AT(x, y)) return; + if (!OBJ_AT(x, y)) + return; - toloc = down_gate(x, y); - drop_to(&cc, toloc); - if (!cc.y) return; + toloc = down_gate(x, y); + drop_to(&cc, toloc); + if (!cc.y) + return; - if (dlev) { - /* send objects next to player falling through trap door. - * checked in obj_delivery(). - */ - toloc = MIGR_WITH_HERO; - cc.y = dlev; - } + if (dlev) { + /* send objects next to player falling through trap door. + * checked in obj_delivery(). + */ + toloc = MIGR_WITH_HERO; + cc.y = dlev; + } - costly = costly_spot(x, y); - price = debit = robbed = 0L; - angry = FALSE; - shkp = (struct monst *) 0; - /* if 'costly', we must keep a record of ESHK(shkp) before - * it undergoes changes through the calls to stolen_value. - * the angry bit must be reset, if needed, in this fn, since - * stolen_value is called under the 'silent' flag to avoid - * unsavory pline repetitions. - */ - if(costly) { - if ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0) { - debit = ESHK(shkp)->debit; - robbed = ESHK(shkp)->robbed; - angry = !shkp->mpeaceful; - } - } + costly = costly_spot(x, y); + price = debit = robbed = 0L; + angry = FALSE; + shkp = (struct monst *) 0; + /* if 'costly', we must keep a record of ESHK(shkp) before + * it undergoes changes through the calls to stolen_value. + * the angry bit must be reset, if needed, in this fn, since + * stolen_value is called under the 'silent' flag to avoid + * unsavory pline repetitions. + */ + if (costly) { + if ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0) { + debit = ESHK(shkp)->debit; + robbed = ESHK(shkp)->robbed; + angry = !shkp->mpeaceful; + } + } - isrock = (missile && missile->otyp == ROCK); - oct = dct = 0L; - for(obj = level.objects[x][y]; obj; obj = obj2) { - obj2 = obj->nexthere; - if(obj == missile) continue; - /* number of objects in the pile */ - oct += obj->quan; - if(obj == uball || obj == uchain) continue; - /* boulders can fall too, but rarely & never due to rocks */ - if((isrock && obj->otyp == BOULDER) || - rn2(obj->otyp == BOULDER ? 30 : 3)) continue; - obj_extract_self(obj); + isrock = (missile && missile->otyp == ROCK); + oct = dct = 0L; + for (obj = level.objects[x][y]; obj; obj = obj2) { + obj2 = obj->nexthere; + if (obj == missile) + continue; + /* number of objects in the pile */ + oct += obj->quan; + if (obj == uball || obj == uchain) + continue; + /* boulders can fall too, but rarely & never due to rocks */ + if ((isrock && obj->otyp == BOULDER) + || rn2(obj->otyp == BOULDER ? 30 : 3)) + continue; + obj_extract_self(obj); - if(costly) { - price += stolen_value(obj, x, y, - (costly_spot(u.ux, u.uy) && - index(u.urooms, *in_rooms(x, y, SHOPBASE))), - TRUE); - /* set obj->no_charge to 0 */ - if (Has_contents(obj)) - picked_container(obj); /* does the right thing */ - if (obj->oclass != COIN_CLASS) - obj->no_charge = 0; - } + if (costly) { + price += stolen_value( + obj, x, y, (costly_spot(u.ux, u.uy) + && index(u.urooms, *in_rooms(x, y, SHOPBASE))), + TRUE); + /* set obj->no_charge to 0 */ + if (Has_contents(obj)) + picked_container(obj); /* does the right thing */ + if (obj->oclass != COIN_CLASS) + obj->no_charge = 0; + } - add_to_migration(obj); - obj->ox = cc.x; - obj->oy = cc.y; - obj->owornmask = (long)toloc; + add_to_migration(obj); + obj->ox = cc.x; + obj->oy = cc.y; + obj->owornmask = (long) toloc; - /* number of fallen objects */ - dct += obj->quan; - } + /* number of fallen objects */ + dct += obj->quan; + } - if (dct && cansee(x,y)) { /* at least one object fell */ - const char *what = (dct == 1L ? "object falls" : "objects fall"); + if (dct && cansee(x, y)) { /* at least one object fell */ + const char *what = (dct == 1L ? "object falls" : "objects fall"); - if (missile) - pline("From the impact, %sother %s.", - dct == oct ? "the " : dct == 1L ? "an" : "", what); - else if (oct == dct) - pline("%s adjacent %s %s.", - dct == 1L ? "The" : "All the", what, gate_str); - else - pline("%s adjacent %s %s.", - dct == 1L ? "One of the" : "Some of the", - dct == 1L ? "objects falls" : what, gate_str); - } - - if(costly && shkp && price) { - if(ESHK(shkp)->robbed > robbed) { - You("removed %ld %s worth of goods!", price, currency(price)); - if(cansee(shkp->mx, shkp->my)) { - if(ESHK(shkp)->customer[0] == 0) - (void) strncpy(ESHK(shkp)->customer, - plname, PL_NSIZ); - if(angry) - pline("%s is infuriated!", Monnam(shkp)); - else pline("\"%s, you are a thief!\"", plname); - } else You_hear("a scream, \"Thief!\""); - hot_pursuit(shkp); - (void) angry_guards(FALSE); - return; - } - if(ESHK(shkp)->debit > debit) { - long amt = (ESHK(shkp)->debit - debit); - You("owe %s %ld %s for goods lost.", - Monnam(shkp), - amt, currency(amt)); - } - } + if (missile) + pline("From the impact, %sother %s.", + dct == oct ? "the " : dct == 1L ? "an" : "", what); + else if (oct == dct) + pline("%s adjacent %s %s.", dct == 1L ? "The" : "All the", what, + gate_str); + else + pline("%s adjacent %s %s.", + dct == 1L ? "One of the" : "Some of the", + dct == 1L ? "objects falls" : what, gate_str); + } + if (costly && shkp && price) { + if (ESHK(shkp)->robbed > robbed) { + You("removed %ld %s worth of goods!", price, currency(price)); + if (cansee(shkp->mx, shkp->my)) { + if (ESHK(shkp)->customer[0] == 0) + (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ); + if (angry) + pline("%s is infuriated!", Monnam(shkp)); + else + pline("\"%s, you are a thief!\"", plname); + } else + You_hear("a scream, \"Thief!\""); + hot_pursuit(shkp); + (void) angry_guards(FALSE); + return; + } + if (ESHK(shkp)->debit > debit) { + long amt = (ESHK(shkp)->debit - debit); + You("owe %s %ld %s for goods lost.", Monnam(shkp), amt, + currency(amt)); + } + } } /* NOTE: ship_object assumes otmp was FREED from fobj or invent. @@ -1388,176 +1477,194 @@ xchar dlev; /* if !0 send to dlev near player */ */ boolean ship_object(otmp, x, y, shop_floor_obj) -xchar x, y; +xchar x, y; struct obj *otmp; boolean shop_floor_obj; { - schar toloc; - xchar ox, oy; - coord cc; - struct obj *obj; - struct trap *t; - boolean nodrop, unpaid, container, impact = FALSE; - long n = 0L; + schar toloc; + xchar ox, oy; + coord cc; + struct obj *obj; + struct trap *t; + boolean nodrop, unpaid, container, impact = FALSE; + long n = 0L; - if (!otmp) return(FALSE); - if ((toloc = down_gate(x, y)) == MIGR_NOWHERE) return(FALSE); - drop_to(&cc, toloc); - if (!cc.y) return(FALSE); + if (!otmp) + return (FALSE); + if ((toloc = down_gate(x, y)) == MIGR_NOWHERE) + return (FALSE); + drop_to(&cc, toloc); + if (!cc.y) + return (FALSE); - /* objects other than attached iron ball always fall down ladder, - but have a chance of staying otherwise */ - nodrop = (otmp == uball) || (otmp == uchain) || - (toloc != MIGR_LADDER_UP && rn2(3)); + /* objects other than attached iron ball always fall down ladder, + but have a chance of staying otherwise */ + nodrop = (otmp == uball) || (otmp == uchain) + || (toloc != MIGR_LADDER_UP && rn2(3)); - container = Has_contents(otmp); - unpaid = is_unpaid(otmp); + container = Has_contents(otmp); + unpaid = is_unpaid(otmp); - if(OBJ_AT(x, y)) { - for(obj = level.objects[x][y]; obj; obj = obj->nexthere) - if(obj != otmp) n += obj->quan; - if(n) impact = TRUE; - } - /* boulders never fall through trap doors, but they might knock - other things down before plugging the hole */ - if (otmp->otyp == BOULDER && - ((t = t_at(x, y)) != 0) && - (t->ttyp == TRAPDOOR || t->ttyp == HOLE)) { - if (impact) impact_drop(otmp, x, y, 0); - return FALSE; /* let caller finish the drop */ - } + if (OBJ_AT(x, y)) { + for (obj = level.objects[x][y]; obj; obj = obj->nexthere) + if (obj != otmp) + n += obj->quan; + if (n) + impact = TRUE; + } + /* boulders never fall through trap doors, but they might knock + other things down before plugging the hole */ + if (otmp->otyp == BOULDER && ((t = t_at(x, y)) != 0) + && (t->ttyp == TRAPDOOR || t->ttyp == HOLE)) { + if (impact) + impact_drop(otmp, x, y, 0); + return FALSE; /* let caller finish the drop */ + } - if (cansee(x, y)) - otransit_msg(otmp, nodrop, n); + if (cansee(x, y)) + otransit_msg(otmp, nodrop, n); - if (nodrop) { - if (impact) impact_drop(otmp, x, y, 0); - return(FALSE); - } + if (nodrop) { + if (impact) + impact_drop(otmp, x, y, 0); + return (FALSE); + } - if(unpaid || shop_floor_obj) { - if(unpaid) { - (void)stolen_value(otmp, u.ux, u.uy, TRUE, FALSE); - } else { - ox = otmp->ox; - oy = otmp->oy; - (void)stolen_value(otmp, ox, oy, - (costly_spot(u.ux, u.uy) && - index(u.urooms, *in_rooms(ox, oy, SHOPBASE))), - FALSE); - } - /* set otmp->no_charge to 0 */ - if(container) - picked_container(otmp); /* happens to do the right thing */ - if(otmp->oclass != COIN_CLASS) - otmp->no_charge = 0; - } + if (unpaid || shop_floor_obj) { + if (unpaid) { + (void) stolen_value(otmp, u.ux, u.uy, TRUE, FALSE); + } else { + ox = otmp->ox; + oy = otmp->oy; + (void) stolen_value( + otmp, ox, oy, + (costly_spot(u.ux, u.uy) + && index(u.urooms, *in_rooms(ox, oy, SHOPBASE))), + FALSE); + } + /* set otmp->no_charge to 0 */ + if (container) + picked_container(otmp); /* happens to do the right thing */ + if (otmp->oclass != COIN_CLASS) + otmp->no_charge = 0; + } - if (otmp->owornmask) remove_worn_item(otmp, TRUE); + if (otmp->owornmask) + remove_worn_item(otmp, TRUE); - /* some things break rather than ship */ - if (breaktest(otmp)) { - const char *result; + /* some things break rather than ship */ + if (breaktest(otmp)) { + const char *result; - if (objects[otmp->otyp].oc_material == GLASS + if (objects[otmp->otyp].oc_material == GLASS || otmp->otyp == EXPENSIVE_CAMERA) { - if (otmp->otyp == MIRROR) - change_luck(-2); - result = "crash"; - } else { - /* penalty for breaking eggs laid by you */ - if (otmp->otyp == EGG && otmp->spe && otmp->corpsenm >= LOW_PM) - change_luck((schar) -min(otmp->quan, 5L)); - result = "splat"; - } - You_hear("a muffled %s.",result); - obj_extract_self(otmp); - obfree(otmp, (struct obj *) 0); - return TRUE; - } + if (otmp->otyp == MIRROR) + change_luck(-2); + result = "crash"; + } else { + /* penalty for breaking eggs laid by you */ + if (otmp->otyp == EGG && otmp->spe && otmp->corpsenm >= LOW_PM) + change_luck((schar) -min(otmp->quan, 5L)); + result = "splat"; + } + You_hear("a muffled %s.", result); + obj_extract_self(otmp); + obfree(otmp, (struct obj *) 0); + return TRUE; + } - add_to_migration(otmp); - otmp->ox = cc.x; - otmp->oy = cc.y; - otmp->owornmask = (long)toloc; - /* boulder from rolling boulder trap, no longer part of the trap */ - if (otmp->otyp == BOULDER) otmp->otrapped = 0; + add_to_migration(otmp); + otmp->ox = cc.x; + otmp->oy = cc.y; + otmp->owornmask = (long) toloc; + /* boulder from rolling boulder trap, no longer part of the trap */ + if (otmp->otyp == BOULDER) + otmp->otrapped = 0; - if(impact) { - /* the objs impacted may be in a shop other than - * the one in which the hero is located. another - * check for a shk is made in impact_drop. it is, e.g., - * possible to kick/throw an object belonging to one - * shop into another shop through a gap in the wall, - * and cause objects belonging to the other shop to - * fall down a trap door--thereby getting two shopkeepers - * angry at the hero in one shot. - */ - impact_drop(otmp, x, y, 0); - newsym(x,y); - } - return(TRUE); + if (impact) { + /* the objs impacted may be in a shop other than + * the one in which the hero is located. another + * check for a shk is made in impact_drop. it is, e.g., + * possible to kick/throw an object belonging to one + * shop into another shop through a gap in the wall, + * and cause objects belonging to the other shop to + * fall down a trap door--thereby getting two shopkeepers + * angry at the hero in one shot. + */ + impact_drop(otmp, x, y, 0); + newsym(x, y); + } + return (TRUE); } void obj_delivery(near_hero) boolean near_hero; { - register struct obj *otmp, *otmp2; - register int nx, ny; - int where; - boolean nobreak, noscatter; + register struct obj *otmp, *otmp2; + register int nx, ny; + int where; + boolean nobreak, noscatter; - for (otmp = migrating_objs; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (otmp->ox != u.uz.dnum || otmp->oy != u.uz.dlevel) continue; + for (otmp = migrating_objs; otmp; otmp = otmp2) { + otmp2 = otmp->nobj; + if (otmp->ox != u.uz.dnum || otmp->oy != u.uz.dlevel) + continue; - where = (int)(otmp->owornmask & 0x7fffL); /* destination code */ - nobreak = (where & MIGR_NOBREAK) != 0; - noscatter = (where & MIGR_WITH_HERO) != 0; - where &= ~(MIGR_NOBREAK | MIGR_NOSCATTER); + where = (int) (otmp->owornmask & 0x7fffL); /* destination code */ + nobreak = (where & MIGR_NOBREAK) != 0; + noscatter = (where & MIGR_WITH_HERO) != 0; + where &= ~(MIGR_NOBREAK | MIGR_NOSCATTER); - if (!near_hero ^ (where == MIGR_WITH_HERO)) continue; + if (!near_hero ^ (where == MIGR_WITH_HERO)) + continue; - obj_extract_self(otmp); - otmp->owornmask = 0L; + obj_extract_self(otmp); + otmp->owornmask = 0L; - switch (where) { - case MIGR_STAIRS_UP: nx = xupstair, ny = yupstair; - break; - case MIGR_LADDER_UP: nx = xupladder, ny = yupladder; - break; - case MIGR_SSTAIRS: nx = sstairs.sx, ny = sstairs.sy; - break; - case MIGR_WITH_HERO: nx = u.ux, ny = u.uy; - break; - default: - case MIGR_RANDOM: nx = ny = 0; - break; - } - if (nx > 0) { - place_object(otmp, nx, ny); - if (!nobreak && !IS_SOFT(levl[nx][ny].typ)) { - if (where == MIGR_WITH_HERO) { - if (breaks(otmp, nx, ny)) continue; - } else if (breaktest(otmp)) { - /* assume it broke before player arrived, no messages */ - delobj(otmp); - continue; - } - } - stackobj(otmp); - if (!noscatter) (void)scatter(nx, ny, rnd(2), 0, otmp); - } else { /* random location */ - /* set dummy coordinates because there's no - current position for rloco() to update */ - otmp->ox = otmp->oy = 0; - if (rloco(otmp) && !nobreak && breaktest(otmp)) { - /* assume it broke before player arrived, no messages */ - delobj(otmp); - } - } - } + switch (where) { + case MIGR_STAIRS_UP: + nx = xupstair, ny = yupstair; + break; + case MIGR_LADDER_UP: + nx = xupladder, ny = yupladder; + break; + case MIGR_SSTAIRS: + nx = sstairs.sx, ny = sstairs.sy; + break; + case MIGR_WITH_HERO: + nx = u.ux, ny = u.uy; + break; + default: + case MIGR_RANDOM: + nx = ny = 0; + break; + } + if (nx > 0) { + place_object(otmp, nx, ny); + if (!nobreak && !IS_SOFT(levl[nx][ny].typ)) { + if (where == MIGR_WITH_HERO) { + if (breaks(otmp, nx, ny)) + continue; + } else if (breaktest(otmp)) { + /* assume it broke before player arrived, no messages */ + delobj(otmp); + continue; + } + } + stackobj(otmp); + if (!noscatter) + (void) scatter(nx, ny, rnd(2), 0, otmp); + } else { /* random location */ + /* set dummy coordinates because there's no + current position for rloco() to update */ + otmp->ox = otmp->oy = 0; + if (rloco(otmp) && !nobreak && breaktest(otmp)) { + /* assume it broke before player arrived, no messages */ + delobj(otmp); + } + } + } } STATIC_OVL void @@ -1566,26 +1673,24 @@ register struct obj *otmp; register boolean nodrop; long num; { - char obuf[BUFSZ]; + char obuf[BUFSZ]; - Sprintf(obuf, "%s%s", - (otmp->otyp == CORPSE && - type_is_pname(&mons[otmp->corpsenm])) ? "" : "The ", - cxname(otmp)); + Sprintf(obuf, "%s%s", + (otmp->otyp == CORPSE && type_is_pname(&mons[otmp->corpsenm])) + ? "" + : "The ", + cxname(otmp)); - if(num) { /* means: other objects are impacted */ - Sprintf(eos(obuf), " %s %s object%s", - otense(otmp, "hit"), - num == 1L ? "another" : "other", - num > 1L ? "s" : ""); - if(nodrop) - Sprintf(eos(obuf), "."); - else - Sprintf(eos(obuf), " and %s %s.", - otense(otmp, "fall"), gate_str); - pline1(obuf); - } else if(!nodrop) - pline("%s %s %s.", obuf, otense(otmp, "fall"), gate_str); + if (num) { /* means: other objects are impacted */ + Sprintf(eos(obuf), " %s %s object%s", otense(otmp, "hit"), + num == 1L ? "another" : "other", num > 1L ? "s" : ""); + if (nodrop) + Sprintf(eos(obuf), "."); + else + Sprintf(eos(obuf), " and %s %s.", otense(otmp, "fall"), gate_str); + pline1(obuf); + } else if (!nodrop) + pline("%s %s %s.", obuf, otense(otmp, "fall"), gate_str); } /* migration destination for objects which fall down to next level */ @@ -1593,31 +1698,31 @@ schar down_gate(x, y) xchar x, y; { - struct trap *ttmp; + struct trap *ttmp; - gate_str = 0; - /* this matches the player restriction in goto_level() */ - if (on_level(&u.uz, &qstart_level) && !ok_to_quest()) - return MIGR_NOWHERE; + gate_str = 0; + /* this matches the player restriction in goto_level() */ + if (on_level(&u.uz, &qstart_level) && !ok_to_quest()) + return MIGR_NOWHERE; - if ((xdnstair == x && ydnstair == y) || - (sstairs.sx == x && sstairs.sy == y && !sstairs.up)) { - gate_str = "down the stairs"; - return (xdnstair == x && ydnstair == y) ? - MIGR_STAIRS_UP : MIGR_SSTAIRS; - } - if (xdnladder == x && ydnladder == y) { - gate_str = "down the ladder"; - return MIGR_LADDER_UP; - } + if ((xdnstair == x && ydnstair == y) + || (sstairs.sx == x && sstairs.sy == y && !sstairs.up)) { + gate_str = "down the stairs"; + return (xdnstair == x && ydnstair == y) ? MIGR_STAIRS_UP + : MIGR_SSTAIRS; + } + if (xdnladder == x && ydnladder == y) { + gate_str = "down the ladder"; + return MIGR_LADDER_UP; + } - if (((ttmp = t_at(x, y)) != 0 && ttmp->tseen) && - (ttmp->ttyp == TRAPDOOR || ttmp->ttyp == HOLE)) { - gate_str = (ttmp->ttyp == TRAPDOOR) ? - "through the trap door" : "through the hole"; - return MIGR_RANDOM; - } - return MIGR_NOWHERE; + if (((ttmp = t_at(x, y)) != 0 && ttmp->tseen) + && (ttmp->ttyp == TRAPDOOR || ttmp->ttyp == HOLE)) { + gate_str = (ttmp->ttyp == TRAPDOOR) ? "through the trap door" + : "through the hole"; + return MIGR_RANDOM; + } + return MIGR_NOWHERE; } /*dokick.c*/ diff --git a/src/dothrow.c b/src/dothrow.c index 8e69174f8..33cefc1ce 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dothrow.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dothrow.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.100 $ */ /* NetHack 3.6 dothrow.c $Date: 2013/11/05 00:57:55 $ $Revision: 1.89 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,30 +7,29 @@ #include "hack.h" -STATIC_DCL int FDECL(throw_obj, (struct obj *,int)); +STATIC_DCL int FDECL(throw_obj, (struct obj *, int)); STATIC_DCL boolean FDECL(ok_to_throw, (int *)); STATIC_DCL void NDECL(autoquiver); STATIC_DCL int FDECL(gem_accept, (struct monst *, struct obj *)); -STATIC_DCL void FDECL(tmiss, (struct obj *, struct monst *,BOOLEAN_P)); +STATIC_DCL void FDECL(tmiss, (struct obj *, struct monst *, BOOLEAN_P)); STATIC_DCL int FDECL(throw_gold, (struct obj *)); -STATIC_DCL void FDECL(check_shop_obj, (struct obj *,XCHAR_P,XCHAR_P,BOOLEAN_P)); -STATIC_DCL void FDECL(breakmsg, (struct obj *,BOOLEAN_P)); -STATIC_DCL boolean FDECL(toss_up,(struct obj *, BOOLEAN_P)); +STATIC_DCL void FDECL(check_shop_obj, + (struct obj *, XCHAR_P, XCHAR_P, BOOLEAN_P)); +STATIC_DCL void FDECL(breakmsg, (struct obj *, BOOLEAN_P)); +STATIC_DCL boolean FDECL(toss_up, (struct obj *, BOOLEAN_P)); STATIC_DCL boolean FDECL(throwing_weapon, (struct obj *)); -STATIC_DCL void FDECL(sho_obj_return_to_u, (struct obj *obj)); -STATIC_DCL boolean FDECL(mhurtle_step, (genericptr_t,int,int)); +STATIC_DCL void FDECL(sho_obj_return_to_u, (struct obj * obj)); +STATIC_DCL boolean FDECL(mhurtle_step, (genericptr_t, int, int)); - -static NEARDATA const char toss_objs[] = - { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, WEAPON_CLASS, 0 }; +static NEARDATA const char toss_objs[] = { ALLOW_COUNT, COIN_CLASS, + ALL_CLASSES, WEAPON_CLASS, 0 }; /* different default choices when wielding a sling (gold must be included) */ -static NEARDATA const char bullets[] = - { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, GEM_CLASS, 0 }; +static NEARDATA const char bullets[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, + GEM_CLASS, 0 }; /* thrownobj (decl.c) tracks an object until it lands */ -extern boolean notonhead; /* for long worms */ - +extern boolean notonhead; /* for long worms */ /* Throw the selected object, asking for direction */ STATIC_OVL int @@ -38,344 +37,352 @@ throw_obj(obj, shotlimit) struct obj *obj; int shotlimit; { - struct obj *otmp; - int multishot; - schar skill; - long wep_mask; - boolean twoweap, weakmultishot; + struct obj *otmp; + int multishot; + schar skill; + long wep_mask; + boolean twoweap, weakmultishot; - /* ask "in what direction?" */ - if (!getdir((char *)0)) { - /* obj might need to be merged back into the singular gold object */ - freeinv(obj); - addinv(obj); - return(0); - } + /* ask "in what direction?" */ + if (!getdir((char *) 0)) { + /* obj might need to be merged back into the singular gold object */ + freeinv(obj); + addinv(obj); + return (0); + } - /* - Throwing money is usually for getting rid of it when - a leprechaun approaches, or for bribing an oncoming - angry monster. So throw the whole object. + /* + Throwing money is usually for getting rid of it when + a leprechaun approaches, or for bribing an oncoming + angry monster. So throw the whole object. - If the money is in quiver, throw one coin at a time, - possibly using a sling. - */ - if(obj->oclass == COIN_CLASS && obj != uquiver) return(throw_gold(obj)); + If the money is in quiver, throw one coin at a time, + possibly using a sling. + */ + if (obj->oclass == COIN_CLASS && obj != uquiver) + return (throw_gold(obj)); - if(!canletgo(obj,"throw")) - return(0); - if (obj->oartifact == ART_MJOLLNIR && obj != uwep) { - pline("%s must be wielded before it can be thrown.", - The(xname(obj))); - return(0); - } - if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) < STR19(25)) - || (obj->otyp == BOULDER && !throws_rocks(youmonst.data))) { - pline("It's too heavy."); - return(1); - } - if(!u.dx && !u.dy && !u.dz) { - You("cannot throw an object at yourself."); - return(0); - } - u_wipe_engr(2); - if (!uarmg && obj->otyp == CORPSE && - touch_petrifies(&mons[obj->corpsenm]) && - !Stone_resistance) { - You("throw %s with your bare %s.", - corpse_xname(obj, (const char *)0, CXN_PFX_THE), - /* throwing with one hand, but pluralize since the - expression "with your bare hands" sounds better */ - makeplural(body_part(HAND))); - Sprintf(killer.name, "throwing %s bare-handed", - killer_xname(obj)); - instapetrify(killer.name); - } - if (welded(obj)) { - weldmsg(obj); - return 1; - } + if (!canletgo(obj, "throw")) + return (0); + if (obj->oartifact == ART_MJOLLNIR && obj != uwep) { + pline("%s must be wielded before it can be thrown.", The(xname(obj))); + return (0); + } + if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) < STR19(25)) + || (obj->otyp == BOULDER && !throws_rocks(youmonst.data))) { + pline("It's too heavy."); + return (1); + } + if (!u.dx && !u.dy && !u.dz) { + You("cannot throw an object at yourself."); + return (0); + } + u_wipe_engr(2); + if (!uarmg && obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm]) + && !Stone_resistance) { + You("throw %s with your bare %s.", + corpse_xname(obj, (const char *) 0, CXN_PFX_THE), + /* throwing with one hand, but pluralize since the + expression "with your bare hands" sounds better */ + makeplural(body_part(HAND))); + Sprintf(killer.name, "throwing %s bare-handed", killer_xname(obj)); + instapetrify(killer.name); + } + if (welded(obj)) { + weldmsg(obj); + return 1; + } - /* Multishot calculations - * (potential volley of up to N missiles; default for N is 1) - */ - multishot = 1; - skill = objects[obj->otyp].oc_skill; - if (obj->quan > 1L && /* no point checking if there's only 1 */ - /* ammo requires corresponding launcher be wielded */ - (is_ammo(obj) ? matching_launcher(obj, uwep) : - /* otherwise any stackable (non-ammo) weapon */ - obj->oclass == WEAPON_CLASS) && - !(Confusion || Stunned)) { - /* some roles don't get a volley bonus until becoming expert */ - weakmultishot = (Role_if(PM_WIZARD) || Role_if(PM_PRIEST) || - (Role_if(PM_HEALER) && skill != P_KNIFE) || - (Role_if(PM_TOURIST) && skill != -P_DART) || - /* poor dexterity also inhibits multishot */ - Fumbling || ACURR(A_DEX) <= 6); + /* Multishot calculations + * (potential volley of up to N missiles; default for N is 1) + */ + multishot = 1; + skill = objects[obj->otyp].oc_skill; + if (obj->quan > 1L && /* no point checking if there's only 1 */ + /* ammo requires corresponding launcher be wielded */ + (is_ammo(obj) ? matching_launcher(obj, uwep) : + /* otherwise any stackable (non-ammo) weapon */ + obj->oclass == WEAPON_CLASS) && !(Confusion || Stunned)) { + /* some roles don't get a volley bonus until becoming expert */ + weakmultishot = (Role_if(PM_WIZARD) || Role_if(PM_PRIEST) + || (Role_if(PM_HEALER) && skill != P_KNIFE) + || (Role_if(PM_TOURIST) && skill != -P_DART) || + /* poor dexterity also inhibits multishot */ + Fumbling || ACURR(A_DEX) <= 6); - /* Bonus if the player is proficient in this weapon... */ - switch (P_SKILL(weapon_type(obj))) { - case P_EXPERT: - multishot++; - /*FALLTHRU*/ - case P_SKILLED: - if (!weakmultishot) multishot++; - break; - default: /* basic or unskilled: no bonus */ - break; - } - /* ...or is using a special weapon for their role... */ - switch (Role_switch) { - case PM_CAVEMAN: - /* give bonus for low-tech gear */ - if (skill == -P_SLING || skill == P_SPEAR) multishot++; - break; - case PM_MONK: - /* allow higher volley count despite skill limitation */ - if (skill == -P_SHURIKEN) multishot++; - break; - case PM_RANGER: - /* arbitrary; encourage use of other missiles beside daggers */ - if (skill != P_DAGGER) multishot++; - break; - case PM_ROGUE: - /* possibly should add knives... */ - if (skill == P_DAGGER) multishot++; - break; - case PM_SAMURAI: - /* role-specific launcher and its ammo */ - if (obj->otyp == YA && uwep && uwep->otyp == YUMI) multishot++; - break; - default: - break; /* No bonus */ - } - /* ...or using their race's special bow; no bonus for spears */ - if (!weakmultishot) - switch (Race_switch) { - case PM_ELF: - if (obj->otyp == ELVEN_ARROW && uwep && - uwep->otyp == ELVEN_BOW) multishot++; - break; - case PM_ORC: - if (obj->otyp == ORCISH_ARROW && uwep && - uwep->otyp == ORCISH_BOW) multishot++; - break; - case PM_GNOME: - /* arbitrary; there isn't any gnome-specific gear */ - if (skill == -P_CROSSBOW) multishot++; - break; - case PM_HUMAN: - case PM_DWARF: - default: - break; /* No bonus */ - } + /* Bonus if the player is proficient in this weapon... */ + switch (P_SKILL(weapon_type(obj))) { + case P_EXPERT: + multishot++; + /*FALLTHRU*/ + case P_SKILLED: + if (!weakmultishot) + multishot++; + break; + default: /* basic or unskilled: no bonus */ + break; + } + /* ...or is using a special weapon for their role... */ + switch (Role_switch) { + case PM_CAVEMAN: + /* give bonus for low-tech gear */ + if (skill == -P_SLING || skill == P_SPEAR) + multishot++; + break; + case PM_MONK: + /* allow higher volley count despite skill limitation */ + if (skill == -P_SHURIKEN) + multishot++; + break; + case PM_RANGER: + /* arbitrary; encourage use of other missiles beside daggers */ + if (skill != P_DAGGER) + multishot++; + break; + case PM_ROGUE: + /* possibly should add knives... */ + if (skill == P_DAGGER) + multishot++; + break; + case PM_SAMURAI: + /* role-specific launcher and its ammo */ + if (obj->otyp == YA && uwep && uwep->otyp == YUMI) + multishot++; + break; + default: + break; /* No bonus */ + } + /* ...or using their race's special bow; no bonus for spears */ + if (!weakmultishot) + switch (Race_switch) { + case PM_ELF: + if (obj->otyp == ELVEN_ARROW && uwep + && uwep->otyp == ELVEN_BOW) + multishot++; + break; + case PM_ORC: + if (obj->otyp == ORCISH_ARROW && uwep + && uwep->otyp == ORCISH_BOW) + multishot++; + break; + case PM_GNOME: + /* arbitrary; there isn't any gnome-specific gear */ + if (skill == -P_CROSSBOW) + multishot++; + break; + case PM_HUMAN: + case PM_DWARF: + default: + break; /* No bonus */ + } - /* crossbows are slow to load and probably shouldn't allow multiple - shots at all, but that would result in players never using them; - instead, high strength is necessary to load and shoot quickly */ - if (multishot > 1 && skill == -P_CROSSBOW && - ammo_and_launcher(obj, uwep) && - (int)ACURRSTR < (Race_if(PM_GNOME) ? 16 : 18)) - multishot = rnd(multishot); + /* crossbows are slow to load and probably shouldn't allow multiple + shots at all, but that would result in players never using them; + instead, high strength is necessary to load and shoot quickly */ + if (multishot > 1 && skill == -P_CROSSBOW + && ammo_and_launcher(obj, uwep) + && (int) ACURRSTR < (Race_if(PM_GNOME) ? 16 : 18)) + multishot = rnd(multishot); - multishot = rnd(multishot); - if ((long)multishot > obj->quan) multishot = (int)obj->quan; - if (shotlimit > 0 && multishot > shotlimit) multishot = shotlimit; - } + multishot = rnd(multishot); + if ((long) multishot > obj->quan) + multishot = (int) obj->quan; + if (shotlimit > 0 && multishot > shotlimit) + multishot = shotlimit; + } - m_shot.s = ammo_and_launcher(obj,uwep) ? TRUE : FALSE; - /* give a message if shooting more than one, or if player - attempted to specify a count */ - if (multishot > 1 || shotlimit > 0) { - /* "You shoot N arrows." or "You throw N daggers." */ - You("%s %d %s.", - m_shot.s ? "shoot" : "throw", - multishot, /* (might be 1 if player gave shotlimit) */ - (multishot == 1) ? singular(obj, xname) : xname(obj)); - } + m_shot.s = ammo_and_launcher(obj, uwep) ? TRUE : FALSE; + /* give a message if shooting more than one, or if player + attempted to specify a count */ + if (multishot > 1 || shotlimit > 0) { + /* "You shoot N arrows." or "You throw N daggers." */ + You("%s %d %s.", m_shot.s ? "shoot" : "throw", + multishot, /* (might be 1 if player gave shotlimit) */ + (multishot == 1) ? singular(obj, xname) : xname(obj)); + } - wep_mask = obj->owornmask; - m_shot.o = obj->otyp; - m_shot.n = multishot; - for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) { - twoweap = u.twoweap; - /* split this object off from its slot if necessary */ - if (obj->quan > 1L) { - otmp = splitobj(obj, 1L); - } else { - otmp = obj; - if (otmp->owornmask) - remove_worn_item(otmp, FALSE); - } - freeinv(otmp); - throwit(otmp, wep_mask, twoweap); - } - m_shot.n = m_shot.i = 0; - m_shot.o = STRANGE_OBJECT; - m_shot.s = FALSE; + wep_mask = obj->owornmask; + m_shot.o = obj->otyp; + m_shot.n = multishot; + for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) { + twoweap = u.twoweap; + /* split this object off from its slot if necessary */ + if (obj->quan > 1L) { + otmp = splitobj(obj, 1L); + } else { + otmp = obj; + if (otmp->owornmask) + remove_worn_item(otmp, FALSE); + } + freeinv(otmp); + throwit(otmp, wep_mask, twoweap); + } + m_shot.n = m_shot.i = 0; + m_shot.o = STRANGE_OBJECT; + m_shot.s = FALSE; - return 1; + return 1; } /* common to dothrow() and dofire() */ STATIC_OVL boolean ok_to_throw(shotlimit_p) -int *shotlimit_p; /* (see dothrow()) */ +int *shotlimit_p; /* (see dothrow()) */ { - /* kludge to work around parse()'s pre-decrement of `multi' */ - *shotlimit_p = (multi || save_cm) ? multi + 1 : 0; - multi = 0; /* reset; it's been used up */ + /* kludge to work around parse()'s pre-decrement of `multi' */ + *shotlimit_p = (multi || save_cm) ? multi + 1 : 0; + multi = 0; /* reset; it's been used up */ - if (notake(youmonst.data)) { - You("are physically incapable of throwing or shooting anything."); - return FALSE; - } else if (nohands(youmonst.data)) { - You_cant("throw or shoot without hands."); /* not body_part(HAND) */ - return FALSE; - /*[what about !freehand(), aside from cursed missile launcher?]*/ - } - if (check_capacity((char *)0)) return FALSE; - return TRUE; + if (notake(youmonst.data)) { + You("are physically incapable of throwing or shooting anything."); + return FALSE; + } else if (nohands(youmonst.data)) { + You_cant("throw or shoot without hands."); /* not body_part(HAND) */ + return FALSE; + /*[what about !freehand(), aside from cursed missile launcher?]*/ + } + if (check_capacity((char *) 0)) + return FALSE; + return TRUE; } /* t command - throw */ int dothrow() { - register struct obj *obj; - int shotlimit; + register struct obj *obj; + int shotlimit; - /* - * Since some characters shoot multiple missiles at one time, - * allow user to specify a count prefix for 'f' or 't' to limit - * number of items thrown (to avoid possibly hitting something - * behind target after killing it, or perhaps to conserve ammo). - * - * Prior to 3.3.0, command ``3t'' meant ``t(shoot) t(shoot) t(shoot)'' - * and took 3 turns. Now it means ``t(shoot at most 3 missiles)''. - * - * [3.5.0: shot count setup has been moved into ok_to_throw().] - */ - if (!ok_to_throw(&shotlimit)) return 0; + /* + * Since some characters shoot multiple missiles at one time, + * allow user to specify a count prefix for 'f' or 't' to limit + * number of items thrown (to avoid possibly hitting something + * behind target after killing it, or perhaps to conserve ammo). + * + * Prior to 3.3.0, command ``3t'' meant ``t(shoot) t(shoot) t(shoot)'' + * and took 3 turns. Now it means ``t(shoot at most 3 missiles)''. + * + * [3.5.0: shot count setup has been moved into ok_to_throw().] + */ + if (!ok_to_throw(&shotlimit)) + return 0; - obj = getobj(uslinging() ? bullets : toss_objs, "throw"); - /* it is also possible to throw food */ - /* (or jewels, or iron balls... ) */ + obj = getobj(uslinging() ? bullets : toss_objs, "throw"); + /* it is also possible to throw food */ + /* (or jewels, or iron balls... ) */ - return obj ? throw_obj(obj, shotlimit) : 0; + return obj ? throw_obj(obj, shotlimit) : 0; } - /* KMH -- Automatically fill quiver */ /* Suggested by Jeffrey Bay */ static void autoquiver() { - struct obj *otmp, *oammo = 0, *omissile = 0, *omisc = 0, *altammo = 0; + struct obj *otmp, *oammo = 0, *omissile = 0, *omisc = 0, *altammo = 0; - if (uquiver) - return; + if (uquiver) + return; - /* Scan through the inventory */ - for (otmp = invent; otmp; otmp = otmp->nobj) { - if (otmp->owornmask || otmp->oartifact || !otmp->dknown) { - ; /* Skip it */ - } else if (otmp->otyp == ROCK || - /* seen rocks or known flint or known glass */ - (objects[otmp->otyp].oc_name_known && - otmp->otyp == FLINT) || - (objects[otmp->otyp].oc_name_known && - otmp->oclass == GEM_CLASS && - objects[otmp->otyp].oc_material == GLASS)) { - if (uslinging()) - oammo = otmp; - else if (ammo_and_launcher(otmp, uswapwep)) - altammo = otmp; - else if (!omisc) - omisc = otmp; - } else if (otmp->oclass == GEM_CLASS) { - ; /* skip non-rock gems--they're ammo but - player has to select them explicitly */ - } else if (is_ammo(otmp)) { - if (ammo_and_launcher(otmp, uwep)) - /* Ammo matched with launcher (bow and arrow, crossbow and bolt) */ - oammo = otmp; - else if (ammo_and_launcher(otmp, uswapwep)) - altammo = otmp; - else - /* Mismatched ammo (no better than an ordinary weapon) */ - omisc = otmp; - } else if (is_missile(otmp)) { - /* Missile (dart, shuriken, etc.) */ - omissile = otmp; - } else if (otmp->oclass == WEAPON_CLASS && throwing_weapon(otmp)) { - /* Ordinary weapon */ - if (objects[otmp->otyp].oc_skill == P_DAGGER - && !omissile) - omissile = otmp; - else - omisc = otmp; - } - } + /* Scan through the inventory */ + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->owornmask || otmp->oartifact || !otmp->dknown) { + ; /* Skip it */ + } else if (otmp->otyp == ROCK || + /* seen rocks or known flint or known glass */ + (objects[otmp->otyp].oc_name_known && otmp->otyp == FLINT) + || (objects[otmp->otyp].oc_name_known + && otmp->oclass == GEM_CLASS + && objects[otmp->otyp].oc_material == GLASS)) { + if (uslinging()) + oammo = otmp; + else if (ammo_and_launcher(otmp, uswapwep)) + altammo = otmp; + else if (!omisc) + omisc = otmp; + } else if (otmp->oclass == GEM_CLASS) { + ; /* skip non-rock gems--they're ammo but + player has to select them explicitly */ + } else if (is_ammo(otmp)) { + if (ammo_and_launcher(otmp, uwep)) + /* Ammo matched with launcher (bow and arrow, crossbow and + * bolt) */ + oammo = otmp; + else if (ammo_and_launcher(otmp, uswapwep)) + altammo = otmp; + else + /* Mismatched ammo (no better than an ordinary weapon) */ + omisc = otmp; + } else if (is_missile(otmp)) { + /* Missile (dart, shuriken, etc.) */ + omissile = otmp; + } else if (otmp->oclass == WEAPON_CLASS && throwing_weapon(otmp)) { + /* Ordinary weapon */ + if (objects[otmp->otyp].oc_skill == P_DAGGER && !omissile) + omissile = otmp; + else + omisc = otmp; + } + } - /* Pick the best choice */ - if (oammo) - setuqwep(oammo); - else if (omissile) - setuqwep(omissile); - else if (altammo) - setuqwep(altammo); - else if (omisc) - setuqwep(omisc); + /* Pick the best choice */ + if (oammo) + setuqwep(oammo); + else if (omissile) + setuqwep(omissile); + else if (altammo) + setuqwep(altammo); + else if (omisc) + setuqwep(omisc); - return; + return; } /* f command -- fire: throw from the quiver */ int dofire() { - int shotlimit; - struct obj *obj; + int shotlimit; + struct obj *obj; - /* - * Same as dothrow(), except we use quivered missile instead - * of asking what to throw/shoot. - * - * If quiver is empty, we use autoquiver to fill it when the - * corresponding option is on. If the option is off or if - * autoquiver doesn't select anything, we ask what to throw. - * For the last, if player's response is a stack, we put - * that stack into quiver slot provided it's not wielded. - */ - if (!ok_to_throw(&shotlimit)) return 0; + /* + * Same as dothrow(), except we use quivered missile instead + * of asking what to throw/shoot. + * + * If quiver is empty, we use autoquiver to fill it when the + * corresponding option is on. If the option is off or if + * autoquiver doesn't select anything, we ask what to throw. + * For the last, if player's response is a stack, we put + * that stack into quiver slot provided it's not wielded. + */ + if (!ok_to_throw(&shotlimit)) + return 0; - if ((obj = uquiver) == 0) { - if (!flags.autoquiver) { - You("have no ammunition readied."); - } else { - autoquiver(); - if ((obj = uquiver) == 0) - You("have nothing appropriate for your quiver."); - } - /* if autoquiver is disabled or has failed, prompt for missile; - fill quiver with it if it's not wielded */ - if (!obj) { - obj = getobj(uslinging() ? bullets : toss_objs, "throw"); - /* Q command doesn't allow gold in quiver */ - if (obj && !obj->owornmask && obj->oclass != COIN_CLASS) - setuqwep(obj); /* demi-autoquiver */ - } - /* give feedback if quiver has now been filled */ - if (uquiver) { - uquiver->owornmask &= ~W_QUIVER; /* less verbose */ - prinv("You ready:", uquiver, 0L); - uquiver->owornmask |= W_QUIVER; - } - } + if ((obj = uquiver) == 0) { + if (!flags.autoquiver) { + You("have no ammunition readied."); + } else { + autoquiver(); + if ((obj = uquiver) == 0) + You("have nothing appropriate for your quiver."); + } + /* if autoquiver is disabled or has failed, prompt for missile; + fill quiver with it if it's not wielded */ + if (!obj) { + obj = getobj(uslinging() ? bullets : toss_objs, "throw"); + /* Q command doesn't allow gold in quiver */ + if (obj && !obj->owornmask && obj->oclass != COIN_CLASS) + setuqwep(obj); /* demi-autoquiver */ + } + /* give feedback if quiver has now been filled */ + if (uquiver) { + uquiver->owornmask &= ~W_QUIVER; /* less verbose */ + prinv("You ready:", uquiver, 0L); + uquiver->owornmask |= W_QUIVER; + } + } - return obj ? throw_obj(obj, shotlimit) : 0; + return obj ? throw_obj(obj, shotlimit) : 0; } /* if in midst of multishot shooting/throwing, stop early */ @@ -384,11 +391,12 @@ endmultishot(verbose) boolean verbose; { if (m_shot.i < m_shot.n) { - if (verbose && !context.mon_moving) { - You("stop %s after the %d%s %s.", m_shot.s ? "firing" : "throwing", - m_shot.i, ordin(m_shot.i), m_shot.s ? "shot" : "toss"); - } - m_shot.n = m_shot.i; /* make current shot be the last */ + if (verbose && !context.mon_moving) { + You("stop %s after the %d%s %s.", + m_shot.s ? "firing" : "throwing", m_shot.i, ordin(m_shot.i), + m_shot.s ? "shot" : "toss"); + } + m_shot.n = m_shot.i; /* make current shot be the last */ } } @@ -399,19 +407,21 @@ void hitfloor(obj) register struct obj *obj; { - if (IS_SOFT(levl[u.ux][u.uy].typ) || u.uinwater) { - dropy(obj); - return; - } - if (IS_ALTAR(levl[u.ux][u.uy].typ)) - doaltarobj(obj); - else - pline("%s hit%s the %s.", Doname2(obj), - (obj->quan == 1L) ? "s" : "", surface(u.ux,u.uy)); + if (IS_SOFT(levl[u.ux][u.uy].typ) || u.uinwater) { + dropy(obj); + return; + } + if (IS_ALTAR(levl[u.ux][u.uy].typ)) + doaltarobj(obj); + else + pline("%s hit%s the %s.", Doname2(obj), (obj->quan == 1L) ? "s" : "", + surface(u.ux, u.uy)); - if (hero_breaks(obj, u.ux, u.uy, TRUE)) return; - if (ship_object(obj, u.ux, u.uy, FALSE)) return; - dropz(obj, TRUE); + if (hero_breaks(obj, u.ux, u.uy, TRUE)) + return; + if (ship_object(obj, u.ux, u.uy, FALSE)) + return; + dropz(obj, TRUE); } /* @@ -422,10 +432,10 @@ register struct obj *obj; */ boolean walk_path(src_cc, dest_cc, check_proc, arg) - coord *src_cc; - coord *dest_cc; - boolean FDECL((*check_proc), (genericptr_t, int, int)); - genericptr_t arg; +coord *src_cc; +coord *dest_cc; +boolean FDECL((*check_proc), (genericptr_t, int, int)); +genericptr_t arg; { int x, y, dx, dy, x_change, y_change, err, i, prev_x, prev_y; boolean keep_going = TRUE; @@ -437,49 +447,49 @@ walk_path(src_cc, dest_cc, check_proc, arg) prev_y = y = src_cc->y; if (dx < 0) { - x_change = -1; - dx = -dx; + x_change = -1; + dx = -dx; } else - x_change = 1; + x_change = 1; if (dy < 0) { - y_change = -1; - dy = -dy; + y_change = -1; + dy = -dy; } else - y_change = 1; + y_change = 1; i = err = 0; if (dx < dy) { - while (i++ < dy) { - prev_x = x; - prev_y = y; - y += y_change; - err += dx << 1; - if (err > dy) { - x += x_change; - err -= dy << 1; - } - /* check for early exit condition */ - if (!(keep_going = (*check_proc)(arg, x, y))) - break; - } + while (i++ < dy) { + prev_x = x; + prev_y = y; + y += y_change; + err += dx << 1; + if (err > dy) { + x += x_change; + err -= dy << 1; + } + /* check for early exit condition */ + if (!(keep_going = (*check_proc)(arg, x, y))) + break; + } } else { - while (i++ < dx) { - prev_x = x; - prev_y = y; - x += x_change; - err += dy << 1; - if (err > dx) { - y += y_change; - err -= dx << 1; - } - /* check for early exit condition */ - if (!(keep_going = (*check_proc)(arg, x, y))) - break; - } + while (i++ < dx) { + prev_x = x; + prev_y = y; + x += x_change; + err += dy << 1; + if (err > dx) { + y += y_change; + err -= dx << 1; + } + /* check for early exit condition */ + if (!(keep_going = (*check_proc)(arg, x, y))) + break; + } } if (keep_going) - return TRUE; /* successful */ + return TRUE; /* successful */ dest_cc->x = prev_x; dest_cc->y = prev_y; @@ -506,94 +516,96 @@ walk_path(src_cc, dest_cc, check_proc, arg) */ boolean hurtle_step(arg, x, y) - genericptr_t arg; - int x, y; +genericptr_t arg; +int x, y; { - int ox, oy, *range = (int *)arg; + int ox, oy, *range = (int *) arg; struct obj *obj; struct monst *mon; boolean may_pass = TRUE; struct trap *ttmp; int dmg = 0; - - if (!isok(x,y)) { - You_feel("the spirits holding you back."); - return FALSE; + + if (!isok(x, y)) { + You_feel("the spirits holding you back."); + return FALSE; } else if (!in_out_region(x, y)) { - return FALSE; + return FALSE; } else if (*range == 0) { - return FALSE; /* previous step wants to stop now */ + return FALSE; /* previous step wants to stop now */ } if (!Passes_walls || !(may_pass = may_passwall(x, y))) { - if (IS_ROCK(levl[x][y].typ) || closed_door(x,y)) { - const char *s; + if (IS_ROCK(levl[x][y].typ) || closed_door(x, y)) { + const char *s; - pline("Ouch!"); - if (IS_TREE(levl[x][y].typ)) - s = "bumping into a tree"; - else if (IS_ROCK(levl[x][y].typ)) - s = "bumping into a wall"; - else - s = "bumping into a door"; - dmg = rnd(2+*range); - losehp(Maybe_Half_Phys(dmg), s, KILLED_BY); - return FALSE; - } - if (levl[x][y].typ == IRONBARS) { - You("crash into some iron bars. Ouch!"); - dmg = rnd(2+*range); - losehp(Maybe_Half_Phys(dmg), "crashing into iron bars", KILLED_BY); - return FALSE; - } - if ((obj = sobj_at(BOULDER,x,y)) != 0) { - You("bump into a %s. Ouch!", xname(obj)); - dmg = rnd(2+*range); - losehp(Maybe_Half_Phys(dmg), "bumping into a boulder", KILLED_BY); - return FALSE; - } - if (!may_pass) { - /* did we hit a no-dig non-wall position? */ - You("smack into something!"); - dmg = rnd(2+*range); - losehp(Maybe_Half_Phys(dmg), "touching the edge of the universe", - KILLED_BY); - return FALSE; - } - if ((u.ux - x) && (u.uy - y) && - bad_rock(youmonst.data,u.ux,y) && bad_rock(youmonst.data,x,u.uy)) { - boolean too_much = (invent && (inv_weight() + weight_cap() > 600)); - /* Move at a diagonal. */ - if (bigmonst(youmonst.data) || too_much) { - You("%sget forcefully wedged into a crevice.", - too_much ? "and all your belongings " : ""); - dmg = rnd(2+*range); - losehp(Maybe_Half_Phys(dmg), "wedging into a narrow crevice", - KILLED_BY); - return FALSE; - } - } + pline("Ouch!"); + if (IS_TREE(levl[x][y].typ)) + s = "bumping into a tree"; + else if (IS_ROCK(levl[x][y].typ)) + s = "bumping into a wall"; + else + s = "bumping into a door"; + dmg = rnd(2 + *range); + losehp(Maybe_Half_Phys(dmg), s, KILLED_BY); + return FALSE; + } + if (levl[x][y].typ == IRONBARS) { + You("crash into some iron bars. Ouch!"); + dmg = rnd(2 + *range); + losehp(Maybe_Half_Phys(dmg), "crashing into iron bars", + KILLED_BY); + return FALSE; + } + if ((obj = sobj_at(BOULDER, x, y)) != 0) { + You("bump into a %s. Ouch!", xname(obj)); + dmg = rnd(2 + *range); + losehp(Maybe_Half_Phys(dmg), "bumping into a boulder", KILLED_BY); + return FALSE; + } + if (!may_pass) { + /* did we hit a no-dig non-wall position? */ + You("smack into something!"); + dmg = rnd(2 + *range); + losehp(Maybe_Half_Phys(dmg), "touching the edge of the universe", + KILLED_BY); + return FALSE; + } + if ((u.ux - x) && (u.uy - y) && bad_rock(youmonst.data, u.ux, y) + && bad_rock(youmonst.data, x, u.uy)) { + boolean too_much = + (invent && (inv_weight() + weight_cap() > 600)); + /* Move at a diagonal. */ + if (bigmonst(youmonst.data) || too_much) { + You("%sget forcefully wedged into a crevice.", + too_much ? "and all your belongings " : ""); + dmg = rnd(2 + *range); + losehp(Maybe_Half_Phys(dmg), "wedging into a narrow crevice", + KILLED_BY); + return FALSE; + } + } } if ((mon = m_at(x, y)) != 0) { - You("bump into %s.", a_monnam(mon)); - wakeup(mon); - return FALSE; + You("bump into %s.", a_monnam(mon)); + wakeup(mon); + return FALSE; } - if ((u.ux - x) && (u.uy - y) && - bad_rock(youmonst.data,u.ux,y) && bad_rock(youmonst.data,x,u.uy)) { - /* Move at a diagonal. */ - if (Sokoban) { - You("come to an abrupt halt!"); - return FALSE; - } + if ((u.ux - x) && (u.uy - y) && bad_rock(youmonst.data, u.ux, y) + && bad_rock(youmonst.data, x, u.uy)) { + /* Move at a diagonal. */ + if (Sokoban) { + You("come to an abrupt halt!"); + return FALSE; + } } ox = u.ux; oy = u.uy; u_on_newpos(x, y); /* set u., u.usteed->; cliparound(); */ - newsym(ox, oy); /* update old position */ - vision_recalc(1); /* update for new position */ + newsym(ox, oy); /* update old position */ + vision_recalc(1); /* update for new position */ flush_screen(1); /* FIXME: * Each trap should really trigger on the recoil if @@ -604,51 +616,51 @@ hurtle_step(arg, x, y) * ones that we have not yet tested. */ if ((ttmp = t_at(x, y)) != 0) { - if (ttmp->ttyp == MAGIC_PORTAL) { - dotrap(ttmp,0); - return FALSE; - } else if (ttmp->ttyp == FIRE_TRAP) { - dotrap(ttmp,0); - } else if ((ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT || - ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR) && - Sokoban) { - /* Air currents overcome the recoil */ - dotrap(ttmp,0); - *range = 0; - return TRUE; - } else { - if (ttmp->tseen) - You("pass right over %s.", - an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation)); - } + if (ttmp->ttyp == MAGIC_PORTAL) { + dotrap(ttmp, 0); + return FALSE; + } else if (ttmp->ttyp == FIRE_TRAP) { + dotrap(ttmp, 0); + } else if ((ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT + || ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR) + && Sokoban) { + /* Air currents overcome the recoil */ + dotrap(ttmp, 0); + *range = 0; + return TRUE; + } else { + if (ttmp->tseen) + You("pass right over %s.", + an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation)); + } } - if (--*range < 0) /* make sure our range never goes negative */ - *range = 0; + if (--*range < 0) /* make sure our range never goes negative */ + *range = 0; if (*range != 0) - delay_output(); + delay_output(); return TRUE; } STATIC_OVL boolean mhurtle_step(arg, x, y) - genericptr_t arg; - int x, y; +genericptr_t arg; +int x, y; { - struct monst *mon = (struct monst *)arg; + struct monst *mon = (struct monst *) arg; - /* TODO: Treat walls, doors, iron bars, pools, lava, etc. specially - * rather than just stopping before. - */ - if (goodpos(x, y, mon, 0) && m_in_out_region(mon, x, y)) { - remove_monster(mon->mx, mon->my); - newsym(mon->mx, mon->my); - place_monster(mon, x, y); - newsym(mon->mx, mon->my); - set_apparxy(mon); - (void) mintrap(mon); - return TRUE; - } - return FALSE; + /* TODO: Treat walls, doors, iron bars, pools, lava, etc. specially + * rather than just stopping before. + */ + if (goodpos(x, y, mon, 0) && m_in_out_region(mon, x, y)) { + remove_monster(mon->mx, mon->my); + newsym(mon->mx, mon->my); + place_monster(mon, x, y); + newsym(mon->mx, mon->my); + set_apparxy(mon); + (void) mintrap(mon); + return TRUE; + } + return FALSE; } /* @@ -660,8 +672,8 @@ mhurtle_step(arg, x, y) */ void hurtle(dx, dy, range, verbose) - int dx, dy, range; - boolean verbose; +int dx, dy, range; +boolean verbose; { coord uc, cc; @@ -673,30 +685,36 @@ hurtle(dx, dy, range, verbose) * bother with all of that, assume that there is no slack in the chain * for diagonal movement, give the player a message and return. */ - if(Punished && !carried(uball)) { - You_feel("a tug from the iron ball."); - nomul(0); - return; + if (Punished && !carried(uball)) { + You_feel("a tug from the iron ball."); + nomul(0); + return; } else if (u.utrap) { - You("are anchored by the %s.", - u.utraptype == TT_WEB ? "web" : u.utraptype == TT_LAVA ? "lava" : - u.utraptype == TT_INFLOOR ? surface(u.ux,u.uy) : - u.utraptype == TT_BURIEDBALL ? "buried ball" : "trap"); - nomul(0); - return; + You("are anchored by the %s.", + u.utraptype == TT_WEB + ? "web" + : u.utraptype == TT_LAVA + ? "lava" + : u.utraptype == TT_INFLOOR + ? surface(u.ux, u.uy) + : u.utraptype == TT_BURIEDBALL ? "buried ball" + : "trap"); + nomul(0); + return; } /* make sure dx and dy are [-1,0,1] */ dx = sgn(dx); dy = sgn(dy); - if(!range || (!dx && !dy) || u.ustuck) return; /* paranoia */ + if (!range || (!dx && !dy) || u.ustuck) + return; /* paranoia */ nomul(-range); multi_reason = "moving through the air"; - nomovemsg = ""; /* it just happens */ + nomovemsg = ""; /* it just happens */ if (verbose) - You("%s in the opposite direction.", range > 1 ? "hurtle" : "float"); + You("%s in the opposite direction.", range > 1 ? "hurtle" : "float"); /* if we're in the midst of shooting multiple projectiles, stop */ endmultishot(TRUE); sokoban_guilt(); @@ -705,42 +723,44 @@ hurtle(dx, dy, range, verbose) /* this setting of cc is only correct if dx and dy are [-1,0,1] only */ cc.x = u.ux + (dx * range); cc.y = u.uy + (dy * range); - (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t)&range); + (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t) &range); } /* Move a monster through the air for a few squares. */ void mhurtle(mon, dx, dy, range) - struct monst *mon; - int dx, dy, range; +struct monst *mon; +int dx, dy, range; { coord mc, cc; - /* At the very least, debilitate the monster */ - mon->movement = 0; - mon->mstun = 1; + /* At the very least, debilitate the monster */ + mon->movement = 0; + mon->mstun = 1; - /* Is the monster stuck or too heavy to push? - * (very large monsters have too much inertia, even floaters and flyers) - */ - if (mon->data->msize >= MZ_HUGE || mon == u.ustuck || mon->mtrapped) - return; + /* Is the monster stuck or too heavy to push? + * (very large monsters have too much inertia, even floaters and flyers) + */ + if (mon->data->msize >= MZ_HUGE || mon == u.ustuck || mon->mtrapped) + return; /* Make sure dx and dy are [-1,0,1] */ dx = sgn(dx); dy = sgn(dy); - if(!range || (!dx && !dy)) return; /* paranoia */ + if (!range || (!dx && !dy)) + return; /* paranoia */ /* don't let grid bugs be hurtled diagonally */ - if (dx && dy && NODIAG(monsndx(mon->data))) return; + if (dx && dy && NODIAG(monsndx(mon->data))) + return; - /* Send the monster along the path */ - mc.x = mon->mx; - mc.y = mon->my; - cc.x = mon->mx + (dx * range); - cc.y = mon->my + (dy * range); - (void) walk_path(&mc, &cc, mhurtle_step, (genericptr_t)mon); - return; + /* Send the monster along the path */ + mc.x = mon->mx; + mc.y = mon->my; + cc.x = mon->mx + (dx * range); + cc.y = mon->my + (dy * range); + (void) walk_path(&mc, &cc, mhurtle_step, (genericptr_t) mon); + return; } STATIC_OVL void @@ -749,25 +769,27 @@ struct obj *obj; xchar x, y; boolean broken; { - struct monst *shkp = shop_keeper(*u.ushops); + struct monst *shkp = shop_keeper(*u.ushops); - if(!shkp) return; + if (!shkp) + return; - if (broken || - !costly_spot(x, y) || *in_rooms(x, y, SHOPBASE) != *u.ushops) { - /* thrown out of a shop or into a different shop */ - if (is_unpaid(obj)) - (void)stolen_value(obj, u.ux, u.uy, - (boolean)shkp->mpeaceful, FALSE); - if (broken) obj->no_charge = 1; - } else { - if (costly_spot(u.ux, u.uy) && costly_spot(x, y)) { - if (is_unpaid(obj)) - subfrombill(obj, shkp); - else if (x != shkp->mx || y != shkp->my) - sellobj(obj, x, y); - } - } + if (broken || !costly_spot(x, y) + || *in_rooms(x, y, SHOPBASE) != *u.ushops) { + /* thrown out of a shop or into a different shop */ + if (is_unpaid(obj)) + (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful, + FALSE); + if (broken) + obj->no_charge = 1; + } else { + if (costly_spot(u.ux, u.uy) && costly_spot(x, y)) { + if (is_unpaid(obj)) + subfrombill(obj, shkp); + else if (x != shkp->mx || y != shkp->my) + sellobj(obj, x, y); + } + } } /* @@ -781,114 +803,125 @@ struct obj *obj; boolean hitsroof; { const char *action; - boolean petrifier = ((obj->otyp == EGG || obj->otyp == CORPSE) && - touch_petrifies(&mons[obj->corpsenm])); + boolean petrifier = ((obj->otyp == EGG || obj->otyp == CORPSE) + && touch_petrifies(&mons[obj->corpsenm])); /* note: obj->quan == 1 */ if (!has_ceiling(&u.uz)) { - action = "flies up into"; /* into "the sky" or "the water above" */ + action = "flies up into"; /* into "the sky" or "the water above" */ } else if (hitsroof) { - if (breaktest(obj)) { - pline("%s hits the %s.", Doname2(obj), ceiling(u.ux, u.uy)); - breakmsg(obj, !Blind); - breakobj(obj, u.ux, u.uy, TRUE, TRUE); - return FALSE; - } - action = "hits"; + if (breaktest(obj)) { + pline("%s hits the %s.", Doname2(obj), ceiling(u.ux, u.uy)); + breakmsg(obj, !Blind); + breakobj(obj, u.ux, u.uy, TRUE, TRUE); + return FALSE; + } + action = "hits"; } else { - action = "almost hits"; + action = "almost hits"; } - pline("%s %s the %s, then falls back on top of your %s.", - Doname2(obj), action, ceiling(u.ux,u.uy), body_part(HEAD)); + pline("%s %s the %s, then falls back on top of your %s.", Doname2(obj), + action, ceiling(u.ux, u.uy), body_part(HEAD)); /* object now hits you */ if (obj->oclass == POTION_CLASS) { - potionhit(&youmonst, obj, TRUE); + potionhit(&youmonst, obj, TRUE); } else if (breaktest(obj)) { - int otyp = obj->otyp; - int blindinc; + int otyp = obj->otyp; + int blindinc; - /* need to check for blindness result prior to destroying obj */ - blindinc = (otyp == CREAM_PIE || otyp == BLINDING_VENOM) && - /* AT_WEAP is ok here even if attack type was AT_SPIT */ - can_blnd(&youmonst, &youmonst, AT_WEAP, obj) ? rnd(25) : 0; + /* need to check for blindness result prior to destroying obj */ + blindinc = + (otyp == CREAM_PIE || otyp == BLINDING_VENOM) && + /* AT_WEAP is ok here even if attack type was AT_SPIT */ + can_blnd(&youmonst, &youmonst, AT_WEAP, obj) + ? rnd(25) + : 0; - breakmsg(obj, !Blind); - breakobj(obj, u.ux, u.uy, TRUE, TRUE); - obj = 0; /* it's now gone */ - switch (otyp) { - case EGG: - if (petrifier && !Stone_resistance && - !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - /* egg ends up "all over your face"; perhaps - visored helmet should still save you here */ - if (uarmh) Your("%s fails to protect you.", - helm_simple_name(uarmh)); - goto petrify; - } - case CREAM_PIE: - case BLINDING_VENOM: - pline("You've got it all over your %s!", body_part(FACE)); - if (blindinc) { - if (otyp == BLINDING_VENOM && !Blind) - pline("It blinds you!"); - u.ucreamed += blindinc; - make_blinded(Blinded + (long)blindinc, FALSE); - if (!Blind) Your1(vision_clears); - } - break; - default: - break; - } - return FALSE; - } else { /* neither potion nor other breaking object */ - boolean less_damage = uarmh && is_metallic(uarmh), artimsg = FALSE; - int dmg = dmgval(obj, &youmonst); + breakmsg(obj, !Blind); + breakobj(obj, u.ux, u.uy, TRUE, TRUE); + obj = 0; /* it's now gone */ + switch (otyp) { + case EGG: + if (petrifier && !Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + /* egg ends up "all over your face"; perhaps + visored helmet should still save you here */ + if (uarmh) + Your("%s fails to protect you.", helm_simple_name(uarmh)); + goto petrify; + } + case CREAM_PIE: + case BLINDING_VENOM: + pline("You've got it all over your %s!", body_part(FACE)); + if (blindinc) { + if (otyp == BLINDING_VENOM && !Blind) + pline("It blinds you!"); + u.ucreamed += blindinc; + make_blinded(Blinded + (long) blindinc, FALSE); + if (!Blind) + Your1(vision_clears); + } + break; + default: + break; + } + return FALSE; + } else { /* neither potion nor other breaking object */ + boolean less_damage = uarmh && is_metallic(uarmh), artimsg = FALSE; + int dmg = dmgval(obj, &youmonst); - if (obj->oartifact) - /* need a fake die roll here; rn1(18,2) avoids 1 and 20 */ - artimsg = artifact_hit((struct monst *)0, &youmonst, - obj, &dmg, rn1(18,2)); + if (obj->oartifact) + /* need a fake die roll here; rn1(18,2) avoids 1 and 20 */ + artimsg = artifact_hit((struct monst *) 0, &youmonst, obj, &dmg, + rn1(18, 2)); - if (!dmg) { /* probably wasn't a weapon; base damage on weight */ - dmg = (int) obj->owt / 100; - if (dmg < 1) dmg = 1; - else if (dmg > 6) dmg = 6; - if (youmonst.data == &mons[PM_SHADE] && - objects[obj->otyp].oc_material != SILVER) - dmg = 0; - } - if (dmg > 1 && less_damage) dmg = 1; - if (dmg > 0) dmg += u.udaminc; - if (dmg < 0) dmg = 0; /* beware negative rings of increase damage */ - dmg = Maybe_Half_Phys(dmg); + if (!dmg) { /* probably wasn't a weapon; base damage on weight */ + dmg = (int) obj->owt / 100; + if (dmg < 1) + dmg = 1; + else if (dmg > 6) + dmg = 6; + if (youmonst.data == &mons[PM_SHADE] + && objects[obj->otyp].oc_material != SILVER) + dmg = 0; + } + if (dmg > 1 && less_damage) + dmg = 1; + if (dmg > 0) + dmg += u.udaminc; + if (dmg < 0) + dmg = 0; /* beware negative rings of increase damage */ + dmg = Maybe_Half_Phys(dmg); - if (uarmh) { - if (less_damage && dmg < (Upolyd ? u.mh : u.uhp)) { - if (!artimsg) - pline("Fortunately, you are wearing a hard helmet."); - /* helmet definitely protects you when it blocks petrification */ - } else if (!petrifier) { - if (flags.verbose) - Your("%s does not protect you.", helm_simple_name(uarmh)); - } - } else if (petrifier && !Stone_resistance && - !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - petrify: - killer.format = KILLED_BY; - Strcpy(killer.name, "elementary physics"); /* "what goes up..." */ - You("turn to stone."); - if (obj) dropy(obj); /* bypass most of hitfloor() */ - thrownobj = 0; /* now either gone or on floor */ - done(STONING); - return obj ? TRUE : FALSE; - } - hitfloor(obj); - thrownobj = 0; - losehp(Maybe_Half_Phys(dmg), "falling object", KILLED_BY_AN); + if (uarmh) { + if (less_damage && dmg < (Upolyd ? u.mh : u.uhp)) { + if (!artimsg) + pline("Fortunately, you are wearing a hard helmet."); + /* helmet definitely protects you when it blocks petrification + */ + } else if (!petrifier) { + if (flags.verbose) + Your("%s does not protect you.", helm_simple_name(uarmh)); + } + } else if (petrifier && !Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + petrify: + killer.format = KILLED_BY; + Strcpy(killer.name, "elementary physics"); /* "what goes up..." */ + You("turn to stone."); + if (obj) + dropy(obj); /* bypass most of hitfloor() */ + thrownobj = 0; /* now either gone or on floor */ + done(STONING); + return obj ? TRUE : FALSE; + } + hitfloor(obj); + thrownobj = 0; + losehp(Maybe_Half_Phys(dmg), "falling object", KILLED_BY_AN); } return TRUE; } @@ -898,12 +931,12 @@ STATIC_OVL boolean throwing_weapon(obj) struct obj *obj; { - return (is_missile(obj) || is_spear(obj) || - /* daggers and knife (excludes scalpel) */ - (is_blade(obj) && !is_sword(obj) && - (objects[obj->otyp].oc_dir & PIERCE)) || - /* special cases [might want to add AXE] */ - obj->otyp == WAR_HAMMER || obj->otyp == AKLYS); + return (is_missile(obj) || is_spear(obj) || + /* daggers and knife (excludes scalpel) */ + (is_blade(obj) && !is_sword(obj) + && (objects[obj->otyp].oc_dir & PIERCE)) || + /* special cases [might want to add AXE] */ + obj->otyp == WAR_HAMMER || obj->otyp == AKLYS); } /* the currently thrown object is returning to you (not for boomerangs) */ @@ -913,15 +946,16 @@ struct obj *obj; { /* might already be our location (bounced off a wall) */ if (bhitpos.x != u.ux || bhitpos.y != u.uy) { - int x = bhitpos.x - u.dx, y = bhitpos.y - u.dy; + int x = bhitpos.x - u.dx, y = bhitpos.y - u.dy; - tmp_at(DISP_FLASH, obj_to_glyph(obj)); - while(x != u.ux || y != u.uy) { - tmp_at(x, y); - delay_output(); - x -= u.dx; y -= u.dy; - } - tmp_at(DISP_END, 0); + tmp_at(DISP_FLASH, obj_to_glyph(obj)); + while (x != u.ux || y != u.uy) { + tmp_at(x, y); + delay_output(); + x -= u.dx; + y -= u.dy; + } + tmp_at(DISP_END, 0); } } @@ -929,317 +963,327 @@ struct obj *obj; void throwit(obj, wep_mask, twoweap) struct obj *obj; -long wep_mask; /* used to re-equip returning boomerang */ -boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */ +long wep_mask; /* used to re-equip returning boomerang */ +boolean + twoweap; /* used to restore twoweapon mode if wielded weapon returns */ { - register struct monst *mon; - register int range, urange; - boolean crossbowing, - impaired = (Confusion || Stunned || Blind || - Hallucination || Fumbling); + register struct monst *mon; + register int range, urange; + boolean crossbowing, impaired = (Confusion || Stunned || Blind + || Hallucination || Fumbling); - notonhead = FALSE; /* reset potentially stale value */ - if ((obj->cursed || obj->greased) && (u.dx || u.dy) && !rn2(7)) { - boolean slipok = TRUE; - if (ammo_and_launcher(obj, uwep)) - pline("%s!", Tobjnam(obj, "misfire")); - else { - /* only slip if it's greased or meant to be thrown */ - if (obj->greased || throwing_weapon(obj)) - /* BUG: this message is grammatically incorrect if obj has - a plural name; greased gloves or boots for instance. */ - pline("%s as you throw it!", Tobjnam(obj, "slip")); - else slipok = FALSE; - } - if (slipok) { - u.dx = rn2(3)-1; - u.dy = rn2(3)-1; - if (!u.dx && !u.dy) u.dz = 1; - impaired = TRUE; - } - } + notonhead = FALSE; /* reset potentially stale value */ + if ((obj->cursed || obj->greased) && (u.dx || u.dy) && !rn2(7)) { + boolean slipok = TRUE; + if (ammo_and_launcher(obj, uwep)) + pline("%s!", Tobjnam(obj, "misfire")); + else { + /* only slip if it's greased or meant to be thrown */ + if (obj->greased || throwing_weapon(obj)) + /* BUG: this message is grammatically incorrect if obj has + a plural name; greased gloves or boots for instance. */ + pline("%s as you throw it!", Tobjnam(obj, "slip")); + else + slipok = FALSE; + } + if (slipok) { + u.dx = rn2(3) - 1; + u.dy = rn2(3) - 1; + if (!u.dx && !u.dy) + u.dz = 1; + impaired = TRUE; + } + } - if ((u.dx || u.dy || (u.dz < 1)) && - calc_capacity((int)obj->owt) > SLT_ENCUMBER && - (Upolyd ? (u.mh < 5 && u.mh != u.mhmax) - : (u.uhp < 10 && u.uhp != u.uhpmax)) && - obj->owt > (unsigned)((Upolyd ? u.mh : u.uhp) * 2) && - !Is_airlevel(&u.uz)) { - You("have so little stamina, %s drops from your grasp.", - the(xname(obj))); - exercise(A_CON, FALSE); - u.dx = u.dy = 0; - u.dz = 1; - } + if ((u.dx || u.dy || (u.dz < 1)) + && calc_capacity((int) obj->owt) > SLT_ENCUMBER + && (Upolyd ? (u.mh < 5 && u.mh != u.mhmax) + : (u.uhp < 10 && u.uhp != u.uhpmax)) + && obj->owt > (unsigned) ((Upolyd ? u.mh : u.uhp) * 2) + && !Is_airlevel(&u.uz)) { + You("have so little stamina, %s drops from your grasp.", + the(xname(obj))); + exercise(A_CON, FALSE); + u.dx = u.dy = 0; + u.dz = 1; + } - thrownobj = obj; - thrownobj->was_thrown = 1; + thrownobj = obj; + thrownobj->was_thrown = 1; - if(u.uswallow) { - mon = u.ustuck; - bhitpos.x = mon->mx; - bhitpos.y = mon->my; - } else if(u.dz) { - if (u.dz < 0 && Role_if(PM_VALKYRIE) && - obj->oartifact == ART_MJOLLNIR && !impaired) { - pline("%s the %s and returns to your hand!", - Tobjnam(obj, "hit"), ceiling(u.ux,u.uy)); - obj = addinv(obj); - (void) encumber_msg(); - setuwep(obj); - u.twoweap = twoweap; - } else if (u.dz < 0) { - (void) toss_up(obj, rn2(5) && !Underwater); - } else if (u.dz > 0 && u.usteed && - obj->oclass == POTION_CLASS && rn2(6)) { - /* alternative to prayer or wand of opening/spell of knock - for dealing with cursed saddle: throw holy water > */ - potionhit(u.usteed, obj, TRUE); - } else { - hitfloor(obj); - } - thrownobj = (struct obj*)0; - return; + if (u.uswallow) { + mon = u.ustuck; + bhitpos.x = mon->mx; + bhitpos.y = mon->my; + } else if (u.dz) { + if (u.dz < 0 && Role_if(PM_VALKYRIE) && obj->oartifact == ART_MJOLLNIR + && !impaired) { + pline("%s the %s and returns to your hand!", Tobjnam(obj, "hit"), + ceiling(u.ux, u.uy)); + obj = addinv(obj); + (void) encumber_msg(); + setuwep(obj); + u.twoweap = twoweap; + } else if (u.dz < 0) { + (void) toss_up(obj, rn2(5) && !Underwater); + } else if (u.dz > 0 && u.usteed && obj->oclass == POTION_CLASS + && rn2(6)) { + /* alternative to prayer or wand of opening/spell of knock + for dealing with cursed saddle: throw holy water > */ + potionhit(u.usteed, obj, TRUE); + } else { + hitfloor(obj); + } + thrownobj = (struct obj *) 0; + return; - } else if(obj->otyp == BOOMERANG && !Underwater) { - if(Is_airlevel(&u.uz) || Levitation) - hurtle(-u.dx, -u.dy, 1, TRUE); - mon = boomhit(obj, u.dx, u.dy); - if(mon == &youmonst) { /* the thing was caught */ - exercise(A_DEX, TRUE); - obj = addinv(obj); - (void) encumber_msg(); - if (wep_mask && !(obj->owornmask & wep_mask)) { - setworn(obj, wep_mask); - u.twoweap = twoweap; - } - thrownobj = (struct obj*)0; - return; - } - } else { - /* crossbow range is independent of strength */ - crossbowing = (ammo_and_launcher(obj, uwep) && - weapon_type(uwep) == P_CROSSBOW); - urange = (crossbowing ? 18 : (int)ACURRSTR) / 2; - /* balls are easy to throw or at least roll; - * also, this insures the maximum range of a ball is greater - * than 1, so the effects from throwing attached balls are - * actually possible - */ - if (obj->otyp == HEAVY_IRON_BALL) - range = urange - (int)(obj->owt/100); - else - range = urange - (int)(obj->owt/40); - if (obj == uball) { - if (u.ustuck) range = 1; - else if (range >= 5) range = 5; - } - if (range < 1) range = 1; + } else if (obj->otyp == BOOMERANG && !Underwater) { + if (Is_airlevel(&u.uz) || Levitation) + hurtle(-u.dx, -u.dy, 1, TRUE); + mon = boomhit(obj, u.dx, u.dy); + if (mon == &youmonst) { /* the thing was caught */ + exercise(A_DEX, TRUE); + obj = addinv(obj); + (void) encumber_msg(); + if (wep_mask && !(obj->owornmask & wep_mask)) { + setworn(obj, wep_mask); + u.twoweap = twoweap; + } + thrownobj = (struct obj *) 0; + return; + } + } else { + /* crossbow range is independent of strength */ + crossbowing = + (ammo_and_launcher(obj, uwep) && weapon_type(uwep) == P_CROSSBOW); + urange = (crossbowing ? 18 : (int) ACURRSTR) / 2; + /* balls are easy to throw or at least roll; + * also, this insures the maximum range of a ball is greater + * than 1, so the effects from throwing attached balls are + * actually possible + */ + if (obj->otyp == HEAVY_IRON_BALL) + range = urange - (int) (obj->owt / 100); + else + range = urange - (int) (obj->owt / 40); + if (obj == uball) { + if (u.ustuck) + range = 1; + else if (range >= 5) + range = 5; + } + if (range < 1) + range = 1; - if (is_ammo(obj)) { - if (ammo_and_launcher(obj, uwep)) { - if (crossbowing) - range = BOLT_LIM; - else - range++; - } else if (obj->oclass != GEM_CLASS) - range /= 2; - } + if (is_ammo(obj)) { + if (ammo_and_launcher(obj, uwep)) { + if (crossbowing) + range = BOLT_LIM; + else + range++; + } else if (obj->oclass != GEM_CLASS) + range /= 2; + } - if (Is_airlevel(&u.uz) || Levitation) { - /* action, reaction... */ - urange -= range; - if(urange < 1) urange = 1; - range -= urange; - if(range < 1) range = 1; - } + if (Is_airlevel(&u.uz) || Levitation) { + /* action, reaction... */ + urange -= range; + if (urange < 1) + urange = 1; + range -= urange; + if (range < 1) + range = 1; + } - if (obj->otyp == BOULDER) - range = 20; /* you must be giant */ - else if (obj->oartifact == ART_MJOLLNIR) - range = (range + 1) / 2; /* it's heavy */ - else if (obj == uball && u.utrap && u.utraptype == TT_INFLOOR) - range = 1; + if (obj->otyp == BOULDER) + range = 20; /* you must be giant */ + else if (obj->oartifact == ART_MJOLLNIR) + range = (range + 1) / 2; /* it's heavy */ + else if (obj == uball && u.utrap && u.utraptype == TT_INFLOOR) + range = 1; - if (Underwater) range = 1; + if (Underwater) + range = 1; - mon = bhit(u.dx, u.dy, range, THROWN_WEAPON, - (int FDECL((*),(MONST_P,OBJ_P)))0, - (int FDECL((*),(OBJ_P,OBJ_P)))0, - &obj); - thrownobj = obj; /* obj may be null now */ + mon = bhit(u.dx, u.dy, range, THROWN_WEAPON, + (int FDECL((*), (MONST_P, OBJ_P))) 0, + (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj); + thrownobj = obj; /* obj may be null now */ - /* have to do this after bhit() so u.ux & u.uy are correct */ - if(Is_airlevel(&u.uz) || Levitation) - hurtle(-u.dx, -u.dy, urange, TRUE); + /* have to do this after bhit() so u.ux & u.uy are correct */ + if (Is_airlevel(&u.uz) || Levitation) + hurtle(-u.dx, -u.dy, urange, TRUE); - if (!obj) return; - } + if (!obj) + return; + } - if (mon) { - boolean obj_gone; + if (mon) { + boolean obj_gone; - if (mon->isshk && - obj->where == OBJ_MINVENT && obj->ocarry == mon) { - thrownobj = (struct obj*)0; - return; /* alert shk caught it */ - } - (void) snuff_candle(obj); - notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my); - obj_gone = thitmonst(mon, obj); - /* Monster may have been tamed; this frees old mon */ - mon = m_at(bhitpos.x, bhitpos.y); + if (mon->isshk && obj->where == OBJ_MINVENT && obj->ocarry == mon) { + thrownobj = (struct obj *) 0; + return; /* alert shk caught it */ + } + (void) snuff_candle(obj); + notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my); + obj_gone = thitmonst(mon, obj); + /* Monster may have been tamed; this frees old mon */ + mon = m_at(bhitpos.x, bhitpos.y); - /* [perhaps this should be moved into thitmonst or hmon] */ - if (mon && mon->isshk && - (!inside_shop(u.ux, u.uy) || - !index(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops))) - hot_pursuit(mon); + /* [perhaps this should be moved into thitmonst or hmon] */ + if (mon && mon->isshk + && (!inside_shop(u.ux, u.uy) + || !index(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops))) + hot_pursuit(mon); - if (obj_gone) thrownobj = 0; - } + if (obj_gone) + thrownobj = 0; + } - if (!thrownobj) { - ; /* missile has already been handled */ - } else if (u.uswallow) { - /* ball is not picked up by monster */ - if (obj != uball) { - (void) mpickobj(u.ustuck, obj); - thrownobj = (struct obj *)0; - } - } else { - /* the code following might become part of dropy() */ - if (obj->oartifact == ART_MJOLLNIR && - Role_if(PM_VALKYRIE) && rn2(100)) { - /* we must be wearing Gauntlets of Power to get here */ - sho_obj_return_to_u(obj); /* display its flight */ + if (!thrownobj) { + ; /* missile has already been handled */ + } else if (u.uswallow) { + /* ball is not picked up by monster */ + if (obj != uball) { + (void) mpickobj(u.ustuck, obj); + thrownobj = (struct obj *) 0; + } + } else { + /* the code following might become part of dropy() */ + if (obj->oartifact == ART_MJOLLNIR && Role_if(PM_VALKYRIE) + && rn2(100)) { + /* we must be wearing Gauntlets of Power to get here */ + sho_obj_return_to_u(obj); /* display its flight */ - if (!impaired && rn2(100)) { - pline("%s to your hand!", Tobjnam(obj, "return")); - obj = addinv(obj); - (void) encumber_msg(); - setuwep(obj); - u.twoweap = twoweap; - if(cansee(bhitpos.x, bhitpos.y)) - newsym(bhitpos.x,bhitpos.y); - } else { - int dmg = rn2(2); - if (!dmg) { - pline(Blind ? "%s lands %s your %s." : - "%s back to you, landing %s your %s.", - Blind ? Something : Tobjnam(obj, "return"), - Levitation ? "beneath" : "at", - makeplural(body_part(FOOT))); - } else { - dmg += rnd(3); - pline(Blind ? "%s your %s!" : - "%s back toward you, hitting your %s!", - Tobjnam(obj, Blind ? "hit" : "fly"), - body_part(ARM)); - (void) artifact_hit((struct monst *)0, - &youmonst, obj, &dmg, 0); - losehp(Maybe_Half_Phys(dmg), - killer_xname(obj), KILLED_BY); - } - if (ship_object(obj, u.ux, u.uy, FALSE)) { - thrownobj = (struct obj*)0; - return; - } - dropy(obj); - } - thrownobj = (struct obj*)0; - return; - } + if (!impaired && rn2(100)) { + pline("%s to your hand!", Tobjnam(obj, "return")); + obj = addinv(obj); + (void) encumber_msg(); + setuwep(obj); + u.twoweap = twoweap; + if (cansee(bhitpos.x, bhitpos.y)) + newsym(bhitpos.x, bhitpos.y); + } else { + int dmg = rn2(2); + if (!dmg) { + pline(Blind ? "%s lands %s your %s." + : "%s back to you, landing %s your %s.", + Blind ? Something : Tobjnam(obj, "return"), + Levitation ? "beneath" : "at", + makeplural(body_part(FOOT))); + } else { + dmg += rnd(3); + pline(Blind ? "%s your %s!" + : "%s back toward you, hitting your %s!", + Tobjnam(obj, Blind ? "hit" : "fly"), + body_part(ARM)); + (void) artifact_hit((struct monst *) 0, &youmonst, obj, + &dmg, 0); + losehp(Maybe_Half_Phys(dmg), killer_xname(obj), + KILLED_BY); + } + if (ship_object(obj, u.ux, u.uy, FALSE)) { + thrownobj = (struct obj *) 0; + return; + } + dropy(obj); + } + thrownobj = (struct obj *) 0; + return; + } - if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ) && - breaktest(obj)) { - tmp_at(DISP_FLASH, obj_to_glyph(obj)); - tmp_at(bhitpos.x, bhitpos.y); - delay_output(); - tmp_at(DISP_END, 0); - breakmsg(obj, cansee(bhitpos.x, bhitpos.y)); - breakobj(obj, bhitpos.x, bhitpos.y, TRUE, TRUE); - return; - } - if(flooreffects(obj,bhitpos.x,bhitpos.y,"fall")) return; - obj_no_longer_held(obj); - if (mon && mon->isshk && is_pick(obj)) { - if (cansee(bhitpos.x, bhitpos.y)) - pline("%s snatches up %s.", - Monnam(mon), the(xname(obj))); - if (*u.ushops || obj->unpaid) - check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE); - (void) mpickobj(mon, obj); /* may merge and free obj */ - thrownobj = (struct obj*)0; - return; - } - (void) snuff_candle(obj); - if (!mon && ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) { - thrownobj = (struct obj*)0; - return; - } - thrownobj = (struct obj*)0; - place_object(obj, bhitpos.x, bhitpos.y); - /* container contents might break; - do so before turning ownership of thrownobj over to shk - (container_impact_dmg handles item already owned by shop) */ - if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ)) - /* is spot where you initiated throw, not bhitpos */ - container_impact_dmg(obj, u.ux, u.uy); - /* charge for items thrown out of shop; - shk takes possession for items thrown into one */ - if ((*u.ushops || obj->unpaid) && obj != uball) - check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE); + if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ) && breaktest(obj)) { + tmp_at(DISP_FLASH, obj_to_glyph(obj)); + tmp_at(bhitpos.x, bhitpos.y); + delay_output(); + tmp_at(DISP_END, 0); + breakmsg(obj, cansee(bhitpos.x, bhitpos.y)); + breakobj(obj, bhitpos.x, bhitpos.y, TRUE, TRUE); + return; + } + if (flooreffects(obj, bhitpos.x, bhitpos.y, "fall")) + return; + obj_no_longer_held(obj); + if (mon && mon->isshk && is_pick(obj)) { + if (cansee(bhitpos.x, bhitpos.y)) + pline("%s snatches up %s.", Monnam(mon), the(xname(obj))); + if (*u.ushops || obj->unpaid) + check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE); + (void) mpickobj(mon, obj); /* may merge and free obj */ + thrownobj = (struct obj *) 0; + return; + } + (void) snuff_candle(obj); + if (!mon && ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) { + thrownobj = (struct obj *) 0; + return; + } + thrownobj = (struct obj *) 0; + place_object(obj, bhitpos.x, bhitpos.y); + /* container contents might break; + do so before turning ownership of thrownobj over to shk + (container_impact_dmg handles item already owned by shop) */ + if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ)) + /* is spot where you initiated throw, not bhitpos */ + container_impact_dmg(obj, u.ux, u.uy); + /* charge for items thrown out of shop; + shk takes possession for items thrown into one */ + if ((*u.ushops || obj->unpaid) && obj != uball) + check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE); - stackobj(obj); - if (obj == uball) - drop_ball(bhitpos.x, bhitpos.y); - if (cansee(bhitpos.x, bhitpos.y)) - newsym(bhitpos.x,bhitpos.y); - if (obj_sheds_light(obj)) - vision_full_recalc = 1; - } + stackobj(obj); + if (obj == uball) + drop_ball(bhitpos.x, bhitpos.y); + if (cansee(bhitpos.x, bhitpos.y)) + newsym(bhitpos.x, bhitpos.y); + if (obj_sheds_light(obj)) + vision_full_recalc = 1; + } } -/* an object may hit a monster; various factors adjust the chance of hitting */ +/* an object may hit a monster; various factors adjust the chance of hitting + */ int omon_adj(mon, obj, mon_notices) struct monst *mon; struct obj *obj; boolean mon_notices; { - int tmp = 0; + int tmp = 0; - /* size of target affects the chance of hitting */ - tmp += (mon->data->msize - MZ_MEDIUM); /* -2..+5 */ - /* sleeping target is more likely to be hit */ - if (mon->msleeping) { - tmp += 2; - if (mon_notices) mon->msleeping = 0; - } - /* ditto for immobilized target */ - if (!mon->mcanmove || !mon->data->mmove) { - tmp += 4; - if (mon_notices && mon->data->mmove && !rn2(10)) { - mon->mcanmove = 1; - mon->mfrozen = 0; - } - } - /* some objects are more likely to hit than others */ - switch (obj->otyp) { - case HEAVY_IRON_BALL: - if (obj != uball) tmp += 2; - break; - case BOULDER: - tmp += 6; - break; - default: - if (obj->oclass == WEAPON_CLASS || is_weptool(obj) || - obj->oclass == GEM_CLASS) - tmp += hitval(obj, mon); - break; - } - return tmp; + /* size of target affects the chance of hitting */ + tmp += (mon->data->msize - MZ_MEDIUM); /* -2..+5 */ + /* sleeping target is more likely to be hit */ + if (mon->msleeping) { + tmp += 2; + if (mon_notices) + mon->msleeping = 0; + } + /* ditto for immobilized target */ + if (!mon->mcanmove || !mon->data->mmove) { + tmp += 4; + if (mon_notices && mon->data->mmove && !rn2(10)) { + mon->mcanmove = 1; + mon->mfrozen = 0; + } + } + /* some objects are more likely to hit than others */ + switch (obj->otyp) { + case HEAVY_IRON_BALL: + if (obj != uball) + tmp += 2; + break; + case BOULDER: + tmp += 6; + break; + default: + if (obj->oclass == WEAPON_CLASS || is_weptool(obj) + || obj->oclass == GEM_CLASS) + tmp += hitval(obj, mon); + break; + } + return tmp; } /* thrown object misses target monster */ @@ -1257,16 +1301,17 @@ boolean maybe_wakeup; an arrow just landing short of any target (no message in that case), so will realize that there is a valid target here anyway. */ if (!canseemon(mon) || (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)) - pline("%s %s.", The(missile), otense(obj, "miss")); + pline("%s %s.", The(missile), otense(obj, "miss")); else - miss(missile, mon); - if (maybe_wakeup && !rn2(3)) wakeup(mon); + miss(missile, mon); + if (maybe_wakeup && !rn2(3)) + wakeup(mon); return; } -#define quest_arti_hits_leader(obj,mon) \ - (obj->oartifact && is_quest_artifact(obj) && \ - mon->m_id == quest_status.leader_m_id) +#define quest_arti_hits_leader(obj, mon) \ + (obj->oartifact && is_quest_artifact(obj) \ + && mon->m_id == quest_status.leader_m_id) /* * Object thrown by player arrives at monster's location. @@ -1277,256 +1322,266 @@ boolean maybe_wakeup; int thitmonst(mon, obj) register struct monst *mon; -register struct obj *obj; /* thrownobj or kickedobj or uwep */ +register struct obj *obj; /* thrownobj or kickedobj or uwep */ { - register int tmp; /* Base chance to hit */ - register int disttmp; /* distance modifier */ - int otyp = obj->otyp, hmode; - boolean guaranteed_hit = (u.uswallow && mon == u.ustuck); + register int tmp; /* Base chance to hit */ + register int disttmp; /* distance modifier */ + int otyp = obj->otyp, hmode; + boolean guaranteed_hit = (u.uswallow && mon == u.ustuck); - hmode = (obj == uwep) ? HMON_APPLIED : - (obj == kickedobj) ? HMON_KICKED : HMON_THROWN; + hmode = (obj == uwep) ? HMON_APPLIED : (obj == kickedobj) ? HMON_KICKED + : HMON_THROWN; - /* Differences from melee weapons: - * - * Dex still gives a bonus, but strength does not. - * Polymorphed players lacking attacks may still throw. - * There's a base -1 to hit. - * No bonuses for fleeing or stunned targets (they don't dodge - * melee blows as readily, but dodging arrows is hard anyway). - * Not affected by traps, etc. - * Certain items which don't in themselves do damage ignore tmp. - * Distance and monster size affect chance to hit. - */ - tmp = -1 + Luck + find_mac(mon) + u.uhitinc + - maybe_polyd(youmonst.data->mlevel, u.ulevel); - if (ACURR(A_DEX) < 4) tmp -= 3; - else if (ACURR(A_DEX) < 6) tmp -= 2; - else if (ACURR(A_DEX) < 8) tmp -= 1; - else if (ACURR(A_DEX) >= 14) tmp += (ACURR(A_DEX) - 14); + /* Differences from melee weapons: + * + * Dex still gives a bonus, but strength does not. + * Polymorphed players lacking attacks may still throw. + * There's a base -1 to hit. + * No bonuses for fleeing or stunned targets (they don't dodge + * melee blows as readily, but dodging arrows is hard anyway). + * Not affected by traps, etc. + * Certain items which don't in themselves do damage ignore tmp. + * Distance and monster size affect chance to hit. + */ + tmp = -1 + Luck + find_mac(mon) + u.uhitinc + + maybe_polyd(youmonst.data->mlevel, u.ulevel); + if (ACURR(A_DEX) < 4) + tmp -= 3; + else if (ACURR(A_DEX) < 6) + tmp -= 2; + else if (ACURR(A_DEX) < 8) + tmp -= 1; + else if (ACURR(A_DEX) >= 14) + tmp += (ACURR(A_DEX) - 14); - /* Modify to-hit depending on distance; but keep it sane. - * Polearms get a distance penalty even when wielded; it's - * hard to hit at a distance. - */ - disttmp = 3 - distmin(u.ux, u.uy, mon->mx, mon->my); - if(disttmp < -4) disttmp = -4; - tmp += disttmp; + /* Modify to-hit depending on distance; but keep it sane. + * Polearms get a distance penalty even when wielded; it's + * hard to hit at a distance. + */ + disttmp = 3 - distmin(u.ux, u.uy, mon->mx, mon->my); + if (disttmp < -4) + disttmp = -4; + tmp += disttmp; - /* gloves are a hinderance to proper use of bows */ - if (uarmg && uwep && objects[uwep->otyp].oc_skill == P_BOW) { - switch (uarmg->otyp) { - case GAUNTLETS_OF_POWER: /* metal */ - tmp -= 2; - break; - case GAUNTLETS_OF_FUMBLING: - tmp -= 3; - break; - case LEATHER_GLOVES: - case GAUNTLETS_OF_DEXTERITY: - break; - default: - impossible("Unknown type of gloves (%d)", uarmg->otyp); - break; - } - } + /* gloves are a hinderance to proper use of bows */ + if (uarmg && uwep && objects[uwep->otyp].oc_skill == P_BOW) { + switch (uarmg->otyp) { + case GAUNTLETS_OF_POWER: /* metal */ + tmp -= 2; + break; + case GAUNTLETS_OF_FUMBLING: + tmp -= 3; + break; + case LEATHER_GLOVES: + case GAUNTLETS_OF_DEXTERITY: + break; + default: + impossible("Unknown type of gloves (%d)", uarmg->otyp); + break; + } + } - tmp += omon_adj(mon, obj, TRUE); - if (is_orc(mon->data) && - maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) - tmp++; - if (guaranteed_hit) { - tmp += 1000; /* Guaranteed hit */ - } + tmp += omon_adj(mon, obj, TRUE); + if (is_orc(mon->data) + && maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) + tmp++; + if (guaranteed_hit) { + tmp += 1000; /* Guaranteed hit */ + } - if (obj->oclass == GEM_CLASS && is_unicorn(mon->data)) { - if (mon->msleeping || !mon->mcanmove) { - tmiss(obj, mon, FALSE); - return 0; - } else if (mon->mtame) { - pline("%s catches and drops %s.", Monnam(mon), the(xname(obj))); - return 0; - } else { - pline("%s catches %s.", Monnam(mon), the(xname(obj))); - return gem_accept(mon, obj); - } - } + if (obj->oclass == GEM_CLASS && is_unicorn(mon->data)) { + if (mon->msleeping || !mon->mcanmove) { + tmiss(obj, mon, FALSE); + return 0; + } else if (mon->mtame) { + pline("%s catches and drops %s.", Monnam(mon), the(xname(obj))); + return 0; + } else { + pline("%s catches %s.", Monnam(mon), the(xname(obj))); + return gem_accept(mon, obj); + } + } - /* don't make game unwinnable if naive player throws artifact - at leader... (kicked artifact is ok too; HMON_APPLIED could - occur if quest artifact polearm or grapnel ever gets added) */ - if (hmode != HMON_APPLIED && quest_arti_hits_leader(obj, mon)) { - /* not wakeup(), which angers non-tame monsters */ - mon->msleeping = 0; - mon->mstrategy &= ~STRAT_WAITMASK; + /* don't make game unwinnable if naive player throws artifact + at leader... (kicked artifact is ok too; HMON_APPLIED could + occur if quest artifact polearm or grapnel ever gets added) */ + if (hmode != HMON_APPLIED && quest_arti_hits_leader(obj, mon)) { + /* not wakeup(), which angers non-tame monsters */ + mon->msleeping = 0; + mon->mstrategy &= ~STRAT_WAITMASK; - if (mon->mcanmove) { - pline("%s catches %s.", Monnam(mon), the(xname(obj))); - if (mon->mpeaceful) { - boolean next2u = monnear(mon, u.ux, u.uy); + if (mon->mcanmove) { + pline("%s catches %s.", Monnam(mon), the(xname(obj))); + if (mon->mpeaceful) { + boolean next2u = monnear(mon, u.ux, u.uy); - finish_quest(obj); /* acknowledge quest completion */ - pline("%s %s %s back to you.", Monnam(mon), - (next2u ? "hands" : "tosses"), the(xname(obj))); - if (!next2u) sho_obj_return_to_u(obj); - obj = addinv(obj); /* back into your inventory */ - (void) encumber_msg(); - } else { - /* angry leader caught it and isn't returning it */ - if (*u.ushops || obj->unpaid) /* not very likely... */ - check_shop_obj(obj, mon->mx, mon->my, FALSE); - (void) mpickobj(mon, obj); - } - return 1; /* caller doesn't need to place it */ - } - return(0); - } + finish_quest(obj); /* acknowledge quest completion */ + pline("%s %s %s back to you.", Monnam(mon), + (next2u ? "hands" : "tosses"), the(xname(obj))); + if (!next2u) + sho_obj_return_to_u(obj); + obj = addinv(obj); /* back into your inventory */ + (void) encumber_msg(); + } else { + /* angry leader caught it and isn't returning it */ + if (*u.ushops || obj->unpaid) /* not very likely... */ + check_shop_obj(obj, mon->mx, mon->my, FALSE); + (void) mpickobj(mon, obj); + } + return 1; /* caller doesn't need to place it */ + } + return (0); + } - if (obj->oclass == WEAPON_CLASS || is_weptool(obj) || - obj->oclass == GEM_CLASS) { - if (hmode == HMON_KICKED) { - /* throwing adjustments and weapon skill bonus don't apply */ - tmp -= (is_ammo(obj) ? 5 : 3); - } else if (is_ammo(obj)) { - if (!ammo_and_launcher(obj, uwep)) { - tmp -= 4; - } else { - tmp += uwep->spe - greatest_erosion(uwep); - tmp += weapon_hit_bonus(uwep); - if (uwep->oartifact) tmp += spec_abon(uwep, mon); - /* - * Elves and Samurais are highly trained w/bows, - * especially their own special types of bow. - * Polymorphing won't make you a bow expert. - */ - if ((Race_if(PM_ELF) || Role_if(PM_SAMURAI)) && - (!Upolyd || your_race(youmonst.data)) && - objects[uwep->otyp].oc_skill == P_BOW) { - tmp++; - if (Race_if(PM_ELF) && uwep->otyp == ELVEN_BOW) - tmp++; - else if (Role_if(PM_SAMURAI) && uwep->otyp == YUMI) - tmp++; - } - } - } else { /* thrown non-ammo or applied polearm/grapnel */ - if (otyp == BOOMERANG) /* arbitrary */ - tmp += 4; - else if (throwing_weapon(obj)) /* meant to be thrown */ - tmp += 2; - else if (obj == thrownobj) /* not meant to be thrown */ - tmp -= 2; - /* we know we're dealing with a weapon or weptool handled - by WEAPON_SKILLS once ammo objects have been excluded */ - tmp += weapon_hit_bonus(obj); - } + if (obj->oclass == WEAPON_CLASS || is_weptool(obj) + || obj->oclass == GEM_CLASS) { + if (hmode == HMON_KICKED) { + /* throwing adjustments and weapon skill bonus don't apply */ + tmp -= (is_ammo(obj) ? 5 : 3); + } else if (is_ammo(obj)) { + if (!ammo_and_launcher(obj, uwep)) { + tmp -= 4; + } else { + tmp += uwep->spe - greatest_erosion(uwep); + tmp += weapon_hit_bonus(uwep); + if (uwep->oartifact) + tmp += spec_abon(uwep, mon); + /* + * Elves and Samurais are highly trained w/bows, + * especially their own special types of bow. + * Polymorphing won't make you a bow expert. + */ + if ((Race_if(PM_ELF) || Role_if(PM_SAMURAI)) + && (!Upolyd || your_race(youmonst.data)) + && objects[uwep->otyp].oc_skill == P_BOW) { + tmp++; + if (Race_if(PM_ELF) && uwep->otyp == ELVEN_BOW) + tmp++; + else if (Role_if(PM_SAMURAI) && uwep->otyp == YUMI) + tmp++; + } + } + } else { /* thrown non-ammo or applied polearm/grapnel */ + if (otyp == BOOMERANG) /* arbitrary */ + tmp += 4; + else if (throwing_weapon(obj)) /* meant to be thrown */ + tmp += 2; + else if (obj == thrownobj) /* not meant to be thrown */ + tmp -= 2; + /* we know we're dealing with a weapon or weptool handled + by WEAPON_SKILLS once ammo objects have been excluded */ + tmp += weapon_hit_bonus(obj); + } - if (tmp >= rnd(20)) { - if (hmode == HMON_APPLIED) u.uconduct.weaphit++; - if (hmon(mon, obj, hmode)) { /* mon still alive */ - cutworm(mon, bhitpos.x, bhitpos.y, obj); - } - exercise(A_DEX, TRUE); - /* if hero is swallowed and projectile kills the engulfer, - obj gets added to engulfer's inventory and then dropped, - so we can't safely use that pointer anymore; it escapes - the chance to be used up here... */ - if (!thrownobj) return 1; - /* projectiles other than magic stones - sometimes disappear when thrown */ - if (objects[otyp].oc_skill < P_NONE && - objects[otyp].oc_skill > -P_BOOMERANG && - !objects[otyp].oc_magic) { - /* we were breaking 2/3 of everything unconditionally. - * we still don't want anything to survive unconditionally, - * but we need ammo to stay around longer on average. - */ - int broken, chance; - chance = 3 + greatest_erosion(obj) - obj->spe; - if (chance > 1) - broken = rn2(chance); - else - broken = !rn2(4); - if (obj->blessed && !rnl(4)) - broken = 0; + if (tmp >= rnd(20)) { + if (hmode == HMON_APPLIED) + u.uconduct.weaphit++; + if (hmon(mon, obj, hmode)) { /* mon still alive */ + cutworm(mon, bhitpos.x, bhitpos.y, obj); + } + exercise(A_DEX, TRUE); + /* if hero is swallowed and projectile kills the engulfer, + obj gets added to engulfer's inventory and then dropped, + so we can't safely use that pointer anymore; it escapes + the chance to be used up here... */ + if (!thrownobj) + return 1; + /* projectiles other than magic stones + sometimes disappear when thrown */ + if (objects[otyp].oc_skill < P_NONE + && objects[otyp].oc_skill > -P_BOOMERANG + && !objects[otyp].oc_magic) { + /* we were breaking 2/3 of everything unconditionally. + * we still don't want anything to survive unconditionally, + * but we need ammo to stay around longer on average. + */ + int broken, chance; + chance = 3 + greatest_erosion(obj) - obj->spe; + if (chance > 1) + broken = rn2(chance); + else + broken = !rn2(4); + if (obj->blessed && !rnl(4)) + broken = 0; - if (broken) { - if (*u.ushops || obj->unpaid) - check_shop_obj(obj, bhitpos.x,bhitpos.y, TRUE); - obfree(obj, (struct obj *)0); - return 1; - } - } - passive_obj(mon, obj, (struct attack *)0); - } else { - tmiss(obj, mon, TRUE); - if (hmode == HMON_APPLIED) wakeup(mon); - } + if (broken) { + if (*u.ushops || obj->unpaid) + check_shop_obj(obj, bhitpos.x, bhitpos.y, TRUE); + obfree(obj, (struct obj *) 0); + return 1; + } + } + passive_obj(mon, obj, (struct attack *) 0); + } else { + tmiss(obj, mon, TRUE); + if (hmode == HMON_APPLIED) + wakeup(mon); + } - } else if (otyp == HEAVY_IRON_BALL) { - exercise(A_STR, TRUE); - if (tmp >= rnd(20)) { - int was_swallowed = guaranteed_hit; + } else if (otyp == HEAVY_IRON_BALL) { + exercise(A_STR, TRUE); + if (tmp >= rnd(20)) { + int was_swallowed = guaranteed_hit; - exercise(A_DEX, TRUE); - if (!hmon(mon, obj, hmode)) { /* mon killed */ - if (was_swallowed && !u.uswallow && obj == uball) - return 1; /* already did placebc() */ - } - } else { - tmiss(obj, mon, TRUE); - } + exercise(A_DEX, TRUE); + if (!hmon(mon, obj, hmode)) { /* mon killed */ + if (was_swallowed && !u.uswallow && obj == uball) + return 1; /* already did placebc() */ + } + } else { + tmiss(obj, mon, TRUE); + } - } else if (otyp == BOULDER) { - exercise(A_STR, TRUE); - if (tmp >= rnd(20)) { - exercise(A_DEX, TRUE); - (void) hmon(mon, obj, hmode); - } else { - tmiss(obj, mon, TRUE); - } + } else if (otyp == BOULDER) { + exercise(A_STR, TRUE); + if (tmp >= rnd(20)) { + exercise(A_DEX, TRUE); + (void) hmon(mon, obj, hmode); + } else { + tmiss(obj, mon, TRUE); + } - } else if ((otyp == EGG || otyp == CREAM_PIE || - otyp == BLINDING_VENOM || otyp == ACID_VENOM) && - (guaranteed_hit || ACURR(A_DEX) > rnd(25))) { - (void) hmon(mon, obj, hmode); - return 1; /* hmon used it up */ + } else if ((otyp == EGG || otyp == CREAM_PIE || otyp == BLINDING_VENOM + || otyp == ACID_VENOM) + && (guaranteed_hit || ACURR(A_DEX) > rnd(25))) { + (void) hmon(mon, obj, hmode); + return 1; /* hmon used it up */ - } else if (obj->oclass == POTION_CLASS && - (guaranteed_hit || ACURR(A_DEX) > rnd(25))) { - potionhit(mon, obj, TRUE); - return 1; + } else if (obj->oclass == POTION_CLASS + && (guaranteed_hit || ACURR(A_DEX) > rnd(25))) { + potionhit(mon, obj, TRUE); + return 1; - } else if (befriend_with_obj(mon->data, obj) || - (mon->mtame && dogfood(mon, obj) <= ACCFOOD)) { - if (tamedog(mon, obj)) { - return 1; /* obj is gone */ - } else { - tmiss(obj, mon, FALSE); - mon->msleeping = 0; - mon->mstrategy &= ~STRAT_WAITMASK; - } - } else if (guaranteed_hit) { - /* this assumes that guaranteed_hit is due to swallowing */ - wakeup(mon); - if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) { - if (is_animal(u.ustuck->data)) { - minstapetrify(u.ustuck, TRUE); - /* Don't leave a cockatrice corpse available in a statue */ - if (!u.uswallow) { - delobj(obj); - return 1; - } - } - } - pline("%s into %s %s.", - Tobjnam(obj, "vanish"), s_suffix(mon_nam(mon)), - is_animal(u.ustuck->data) ? "entrails" : "currents"); - } else { - tmiss(obj, mon, TRUE); - } + } else if (befriend_with_obj(mon->data, obj) + || (mon->mtame && dogfood(mon, obj) <= ACCFOOD)) { + if (tamedog(mon, obj)) { + return 1; /* obj is gone */ + } else { + tmiss(obj, mon, FALSE); + mon->msleeping = 0; + mon->mstrategy &= ~STRAT_WAITMASK; + } + } else if (guaranteed_hit) { + /* this assumes that guaranteed_hit is due to swallowing */ + wakeup(mon); + if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) { + if (is_animal(u.ustuck->data)) { + minstapetrify(u.ustuck, TRUE); + /* Don't leave a cockatrice corpse available in a statue */ + if (!u.uswallow) { + delobj(obj); + return 1; + } + } + } + pline("%s into %s %s.", Tobjnam(obj, "vanish"), + s_suffix(mon_nam(mon)), + is_animal(u.ustuck->data) ? "entrails" : "currents"); + } else { + tmiss(obj, mon, TRUE); + } - return 0; + return 0; } STATIC_OVL int @@ -1534,72 +1589,74 @@ gem_accept(mon, obj) register struct monst *mon; register struct obj *obj; { - char buf[BUFSZ]; - boolean is_buddy = sgn(mon->data->maligntyp) == sgn(u.ualign.type); - boolean is_gem = objects[obj->otyp].oc_material == GEMSTONE; - int ret = 0; - static NEARDATA const char nogood[] = " is not interested in your junk."; - static NEARDATA const char acceptgift[] = " accepts your gift."; - static NEARDATA const char maybeluck[] = " hesitatingly"; - static NEARDATA const char noluck[] = " graciously"; - static NEARDATA const char addluck[] = " gratefully"; + char buf[BUFSZ]; + boolean is_buddy = sgn(mon->data->maligntyp) == sgn(u.ualign.type); + boolean is_gem = objects[obj->otyp].oc_material == GEMSTONE; + int ret = 0; + static NEARDATA const char nogood[] = " is not interested in your junk."; + static NEARDATA const char acceptgift[] = " accepts your gift."; + static NEARDATA const char maybeluck[] = " hesitatingly"; + static NEARDATA const char noluck[] = " graciously"; + static NEARDATA const char addluck[] = " gratefully"; - Strcpy(buf,Monnam(mon)); - mon->mpeaceful = 1; - mon->mavenge = 0; + Strcpy(buf, Monnam(mon)); + mon->mpeaceful = 1; + mon->mavenge = 0; - /* object properly identified */ - if(obj->dknown && objects[obj->otyp].oc_name_known) { - if(is_gem) { - if(is_buddy) { - Strcat(buf,addluck); - change_luck(5); - } else { - Strcat(buf,maybeluck); - change_luck(rn2(7)-3); - } - } else { - Strcat(buf,nogood); - goto nopick; - } - /* making guesses */ - } else if(has_oname(obj) || objects[obj->otyp].oc_uname) { - if(is_gem) { - if(is_buddy) { - Strcat(buf,addluck); - change_luck(2); - } else { - Strcat(buf,maybeluck); - change_luck(rn2(3)-1); - } - } else { - Strcat(buf,nogood); - goto nopick; - } - /* value completely unknown to @ */ - } else { - if(is_gem) { - if(is_buddy) { - Strcat(buf,addluck); - change_luck(1); - } else { - Strcat(buf,maybeluck); - change_luck(rn2(3)-1); - } - } else { - Strcat(buf,noluck); - } - } - Strcat(buf,acceptgift); - if (*u.ushops || obj->unpaid) - check_shop_obj(obj, mon->mx, mon->my, TRUE); - (void) mpickobj(mon, obj); /* may merge and free obj */ - ret = 1; + /* object properly identified */ + if (obj->dknown && objects[obj->otyp].oc_name_known) { + if (is_gem) { + if (is_buddy) { + Strcat(buf, addluck); + change_luck(5); + } else { + Strcat(buf, maybeluck); + change_luck(rn2(7) - 3); + } + } else { + Strcat(buf, nogood); + goto nopick; + } + /* making guesses */ + } else if (has_oname(obj) || objects[obj->otyp].oc_uname) { + if (is_gem) { + if (is_buddy) { + Strcat(buf, addluck); + change_luck(2); + } else { + Strcat(buf, maybeluck); + change_luck(rn2(3) - 1); + } + } else { + Strcat(buf, nogood); + goto nopick; + } + /* value completely unknown to @ */ + } else { + if (is_gem) { + if (is_buddy) { + Strcat(buf, addluck); + change_luck(1); + } else { + Strcat(buf, maybeluck); + change_luck(rn2(3) - 1); + } + } else { + Strcat(buf, noluck); + } + } + Strcat(buf, acceptgift); + if (*u.ushops || obj->unpaid) + check_shop_obj(obj, mon->mx, mon->my, TRUE); + (void) mpickobj(mon, obj); /* may merge and free obj */ + ret = 1; nopick: - if(!Blind) pline1(buf); - if (!tele_restrict(mon)) (void) rloc(mon, FALSE); - return(ret); + if (!Blind) + pline1(buf); + if (!tele_restrict(mon)) + (void) rloc(mon, FALSE); + return (ret); } /* @@ -1637,14 +1694,15 @@ nopick: int hero_breaks(obj, x, y, from_invent) struct obj *obj; -xchar x, y; /* object location (ox, oy may not be right) */ -boolean from_invent; /* thrown or dropped by player; maybe on shop bill */ +xchar x, y; /* object location (ox, oy may not be right) */ +boolean from_invent; /* thrown or dropped by player; maybe on shop bill */ { - boolean in_view = Blind ? FALSE : (from_invent || cansee(x, y)); - if (!breaktest(obj)) return 0; - breakmsg(obj, in_view); - breakobj(obj, x, y, TRUE, from_invent); - return 1; + boolean in_view = Blind ? FALSE : (from_invent || cansee(x, y)); + if (!breaktest(obj)) + return 0; + breakmsg(obj, in_view); + breakobj(obj, x, y, TRUE, from_invent); + return 1; } /* @@ -1655,28 +1713,32 @@ boolean from_invent; /* thrown or dropped by player; maybe on shop bill */ int breaks(obj, x, y) struct obj *obj; -xchar x, y; /* object location (ox, oy may not be right) */ +xchar x, y; /* object location (ox, oy may not be right) */ { - boolean in_view = Blind ? FALSE : cansee(x, y); + boolean in_view = Blind ? FALSE : cansee(x, y); - if (!breaktest(obj)) return 0; - breakmsg(obj, in_view); - breakobj(obj, x, y, FALSE, FALSE); - return 1; + if (!breaktest(obj)) + return 0; + breakmsg(obj, in_view); + breakobj(obj, x, y, FALSE, FALSE); + return 1; } void -release_camera_demon(obj, x,y) +release_camera_demon(obj, x, y) struct obj *obj; -xchar x,y; +xchar x, y; { struct monst *mtmp; - if (!rn2(3) && (mtmp = makemon(&mons[rn2(3) ? PM_HOMUNCULUS : PM_IMP],x,y, NO_MM_FLAGS)) != 0) { - if (canspotmon(mtmp)) - pline("%s is released!", Hallucination ? - An(rndmonnam(NULL)) : "The picture-painting demon"); - mtmp->mpeaceful = !obj->cursed; - set_malign(mtmp); + if (!rn2(3) + && (mtmp = makemon(&mons[rn2(3) ? PM_HOMUNCULUS : PM_IMP], x, y, + NO_MM_FLAGS)) != 0) { + if (canspotmon(mtmp)) + pline("%s is released!", Hallucination + ? An(rndmonnam(NULL)) + : "The picture-painting demon"); + mtmp->mpeaceful = !obj->cursed; + set_malign(mtmp); } } @@ -1687,85 +1749,86 @@ xchar x,y; void breakobj(obj, x, y, hero_caused, from_invent) struct obj *obj; -xchar x, y; /* object location (ox, oy may not be right) */ -boolean hero_caused; /* is this the hero's fault? */ +xchar x, y; /* object location (ox, oy may not be right) */ +boolean hero_caused; /* is this the hero's fault? */ boolean from_invent; { - boolean fracture = FALSE; + boolean fracture = FALSE; - switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { - case MIRROR: - if (hero_caused) - change_luck(-2); - break; - case POT_WATER: /* really, all potions */ - obj->in_use = 1; /* in case it's fatal */ - if (obj->otyp == POT_OIL && obj->lamplit) { - explode_oil(obj, x, y); - } else if (distu(x,y) <= 2) { - if (!breathless(youmonst.data) || haseyes(youmonst.data)) { - if (obj->otyp != POT_WATER) { - if (!breathless(youmonst.data)) { - /* [what about "familiar odor" when known?] */ - You("smell a peculiar odor..."); - } else { - const char *eyes = body_part(EYE); + switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { + case MIRROR: + if (hero_caused) + change_luck(-2); + break; + case POT_WATER: /* really, all potions */ + obj->in_use = 1; /* in case it's fatal */ + if (obj->otyp == POT_OIL && obj->lamplit) { + explode_oil(obj, x, y); + } else if (distu(x, y) <= 2) { + if (!breathless(youmonst.data) || haseyes(youmonst.data)) { + if (obj->otyp != POT_WATER) { + if (!breathless(youmonst.data)) { + /* [what about "familiar odor" when known?] */ + You("smell a peculiar odor..."); + } else { + const char *eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) - eyes = makeplural(eyes); - Your("%s %s.", eyes, - vtense(eyes, "water")); - } - } - potionbreathe(obj); - } - } - /* monster breathing isn't handled... [yet?] */ - break; - case EXPENSIVE_CAMERA: - release_camera_demon(obj, x,y); - break; - case EGG: - /* breaking your own eggs is bad luck */ - if (hero_caused && obj->spe && obj->corpsenm >= LOW_PM) - change_luck((schar) -min(obj->quan, 5L)); - break; - case BOULDER: - case STATUE: - /* caller will handle object disposition; - we're just doing the shop theft handling */ - fracture = TRUE; - break; - default: - break; - } + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your("%s %s.", eyes, vtense(eyes, "water")); + } + } + potionbreathe(obj); + } + } + /* monster breathing isn't handled... [yet?] */ + break; + case EXPENSIVE_CAMERA: + release_camera_demon(obj, x, y); + break; + case EGG: + /* breaking your own eggs is bad luck */ + if (hero_caused && obj->spe && obj->corpsenm >= LOW_PM) + change_luck((schar) -min(obj->quan, 5L)); + break; + case BOULDER: + case STATUE: + /* caller will handle object disposition; + we're just doing the shop theft handling */ + fracture = TRUE; + break; + default: + break; + } - if (hero_caused) { - if (from_invent || obj->unpaid) { - if (*u.ushops || obj->unpaid) - check_shop_obj(obj, x, y, TRUE); - } else if (!obj->no_charge && costly_spot(x, y)) { - /* it is assumed that the obj is a floor-object */ - char *o_shop = in_rooms(x, y, SHOPBASE); - struct monst *shkp = shop_keeper(*o_shop); + if (hero_caused) { + if (from_invent || obj->unpaid) { + if (*u.ushops || obj->unpaid) + check_shop_obj(obj, x, y, TRUE); + } else if (!obj->no_charge && costly_spot(x, y)) { + /* it is assumed that the obj is a floor-object */ + char *o_shop = in_rooms(x, y, SHOPBASE); + struct monst *shkp = shop_keeper(*o_shop); - if (shkp) { /* (implies *o_shop != '\0') */ - static NEARDATA long lastmovetime = 0L; - static NEARDATA boolean peaceful_shk = FALSE; - /* We want to base shk actions on her peacefulness - at start of this turn, so that "simultaneous" - multiple breakage isn't drastically worse than - single breakage. (ought to be done via ESHK) */ - if (moves != lastmovetime) - peaceful_shk = shkp->mpeaceful; - if (stolen_value(obj, x, y, peaceful_shk, FALSE) > 0L && - (*o_shop != u.ushops[0] || !inside_shop(u.ux, u.uy)) && - moves != lastmovetime) make_angry_shk(shkp, x, y); - lastmovetime = moves; - } - } - } - if (!fracture) delobj(obj); + if (shkp) { /* (implies *o_shop != '\0') */ + static NEARDATA long lastmovetime = 0L; + static NEARDATA boolean peaceful_shk = FALSE; + /* We want to base shk actions on her peacefulness + at start of this turn, so that "simultaneous" + multiple breakage isn't drastically worse than + single breakage. (ought to be done via ESHK) */ + if (moves != lastmovetime) + peaceful_shk = shkp->mpeaceful; + if (stolen_value(obj, x, y, peaceful_shk, FALSE) > 0L + && (*o_shop != u.ushops[0] || !inside_shop(u.ux, u.uy)) + && moves != lastmovetime) + make_angry_shk(shkp, x, y); + lastmovetime = moves; + } + } + } + if (!fracture) + delobj(obj); } /* @@ -1776,22 +1839,23 @@ boolean breaktest(obj) struct obj *obj; { - if (obj_resists(obj, 1, 99)) return 0; - if (objects[obj->otyp].oc_material == GLASS && !obj->oartifact && - obj->oclass != GEM_CLASS) - return 1; - switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { - case EXPENSIVE_CAMERA: - case POT_WATER: /* really, all potions */ - case EGG: - case CREAM_PIE: - case MELON: - case ACID_VENOM: - case BLINDING_VENOM: - return 1; - default: - return 0; - } + if (obj_resists(obj, 1, 99)) + return 0; + if (objects[obj->otyp].oc_material == GLASS && !obj->oartifact + && obj->oclass != GEM_CLASS) + return 1; + switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { + case EXPENSIVE_CAMERA: + case POT_WATER: /* really, all potions */ + case EGG: + case CREAM_PIE: + case MELON: + case ACID_VENOM: + case BLINDING_VENOM: + return 1; + default: + return 0; + } } STATIC_OVL void @@ -1799,106 +1863,110 @@ breakmsg(obj, in_view) struct obj *obj; boolean in_view; { - const char *to_pieces; + const char *to_pieces; - to_pieces = ""; - switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { - default: /* glass or crystal wand */ - if (obj->oclass != WAND_CLASS) - impossible("breaking odd object?"); - case CRYSTAL_PLATE_MAIL: - case LENSES: - case MIRROR: - case CRYSTAL_BALL: - case EXPENSIVE_CAMERA: - to_pieces = " into a thousand pieces"; - /*FALLTHRU*/ - case POT_WATER: /* really, all potions */ - if (!in_view) - You_hear("%s shatter!", something); - else - pline("%s shatter%s%s!", Doname2(obj), - (obj->quan==1L) ? "s" : "", to_pieces); - break; - case EGG: - case MELON: - pline("Splat!"); - break; - case CREAM_PIE: - if (in_view) pline("What a mess!"); - break; - case ACID_VENOM: - case BLINDING_VENOM: - pline("Splash!"); - break; - } + to_pieces = ""; + switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) { + default: /* glass or crystal wand */ + if (obj->oclass != WAND_CLASS) + impossible("breaking odd object?"); + case CRYSTAL_PLATE_MAIL: + case LENSES: + case MIRROR: + case CRYSTAL_BALL: + case EXPENSIVE_CAMERA: + to_pieces = " into a thousand pieces"; + /*FALLTHRU*/ + case POT_WATER: /* really, all potions */ + if (!in_view) + You_hear("%s shatter!", something); + else + pline("%s shatter%s%s!", Doname2(obj), + (obj->quan == 1L) ? "s" : "", to_pieces); + break; + case EGG: + case MELON: + pline("Splat!"); + break; + case CREAM_PIE: + if (in_view) + pline("What a mess!"); + break; + case ACID_VENOM: + case BLINDING_VENOM: + pline("Splash!"); + break; + } } STATIC_OVL int throw_gold(obj) struct obj *obj; { - int range, odx, ody; - register struct monst *mon; + int range, odx, ody; + register struct monst *mon; - if(!u.dx && !u.dy && !u.dz) { - You("cannot throw gold at yourself."); - return(0); - } - freeinv(obj); - if(u.uswallow) { - pline(is_animal(u.ustuck->data) ? - "%s in the %s's entrails." : "%s into %s.", - "The money disappears", mon_nam(u.ustuck)); - add_to_minv(u.ustuck, obj); - return(1); - } + if (!u.dx && !u.dy && !u.dz) { + You("cannot throw gold at yourself."); + return (0); + } + freeinv(obj); + if (u.uswallow) { + pline(is_animal(u.ustuck->data) ? "%s in the %s's entrails." + : "%s into %s.", + "The money disappears", mon_nam(u.ustuck)); + add_to_minv(u.ustuck, obj); + return (1); + } - if(u.dz) { - if (u.dz < 0 && !Is_airlevel(&u.uz) && - !Underwater && !Is_waterlevel(&u.uz)) { - pline_The("gold hits the %s, then falls back on top of your %s.", - ceiling(u.ux,u.uy), body_part(HEAD)); - /* some self damage? */ - if (uarmh) pline("Fortunately, you are wearing %s!", - an(helm_simple_name(uarmh))); - } - bhitpos.x = u.ux; - bhitpos.y = u.uy; - } else { - /* consistent with range for normal objects */ - range = (int)((ACURRSTR)/2 - obj->owt/40); + if (u.dz) { + if (u.dz < 0 && !Is_airlevel(&u.uz) && !Underwater + && !Is_waterlevel(&u.uz)) { + pline_The("gold hits the %s, then falls back on top of your %s.", + ceiling(u.ux, u.uy), body_part(HEAD)); + /* some self damage? */ + if (uarmh) + pline("Fortunately, you are wearing %s!", + an(helm_simple_name(uarmh))); + } + bhitpos.x = u.ux; + bhitpos.y = u.uy; + } else { + /* consistent with range for normal objects */ + range = (int) ((ACURRSTR) / 2 - obj->owt / 40); - /* see if the gold has a place to move into */ - odx = u.ux + u.dx; - ody = u.uy + u.dy; - if(!ZAP_POS(levl[odx][ody].typ) || closed_door(odx, ody)) { - bhitpos.x = u.ux; - bhitpos.y = u.uy; - } else { - mon = bhit(u.dx, u.dy, range, THROWN_WEAPON, - (int FDECL((*),(MONST_P,OBJ_P)))0, - (int FDECL((*),(OBJ_P,OBJ_P)))0, - &obj); - if (!obj) return 1; /* object is gone */ - if(mon) { - if (ghitm(mon, obj)) /* was it caught? */ - return 1; - } else { - if(ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) - return 1; - } - } - } + /* see if the gold has a place to move into */ + odx = u.ux + u.dx; + ody = u.uy + u.dy; + if (!ZAP_POS(levl[odx][ody].typ) || closed_door(odx, ody)) { + bhitpos.x = u.ux; + bhitpos.y = u.uy; + } else { + mon = bhit(u.dx, u.dy, range, THROWN_WEAPON, + (int FDECL((*), (MONST_P, OBJ_P))) 0, + (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj); + if (!obj) + return 1; /* object is gone */ + if (mon) { + if (ghitm(mon, obj)) /* was it caught? */ + return 1; + } else { + if (ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) + return 1; + } + } + } - if(flooreffects(obj,bhitpos.x,bhitpos.y,"fall")) return(1); - if(u.dz > 0) - pline_The("gold hits the %s.", surface(bhitpos.x,bhitpos.y)); - place_object(obj,bhitpos.x,bhitpos.y); - if(*u.ushops) sellobj(obj, bhitpos.x, bhitpos.y); - stackobj(obj); - newsym(bhitpos.x,bhitpos.y); - return(1); + if (flooreffects(obj, bhitpos.x, bhitpos.y, "fall")) + return (1); + if (u.dz > 0) + pline_The("gold hits the %s.", surface(bhitpos.x, bhitpos.y)); + place_object(obj, bhitpos.x, bhitpos.y); + if (*u.ushops) + sellobj(obj, bhitpos.x, bhitpos.y); + stackobj(obj); + newsym(bhitpos.x, bhitpos.y); + return (1); } /*dothrow.c*/ diff --git a/src/drawing.c b/src/drawing.c index caff5f679..60ee41685 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 drawing.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 drawing.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.43 $ */ /* NetHack 3.6 drawing.c $Date: 2009/05/06 10:46:09 $ $Revision: 1.28 $ */ /* SCCS Id: @(#)drawing.c 3.5 2007/07/30 */ /* Copyright (c) NetHack Development Team 1992. */ @@ -23,11 +23,11 @@ struct symsetentry symset[NUM_GRAPHICS]; int currentgraphics = 0; -nhsym showsyms[SYM_MAX] = DUMMY; /* symbols to be displayed */ -nhsym l_syms[SYM_MAX] = DUMMY; /* loaded symbols */ -nhsym r_syms[SYM_MAX] = DUMMY; /* rogue symbols */ +nhsym showsyms[SYM_MAX] = DUMMY; /* symbols to be displayed */ +nhsym l_syms[SYM_MAX] = DUMMY; /* loaded symbols */ +nhsym r_syms[SYM_MAX] = DUMMY; /* rogue symbols */ -nhsym warnsyms[WARNCOUNT] = DUMMY; /* the current warning display symbols */ +nhsym warnsyms[WARNCOUNT] = DUMMY; /* the current warning display symbols */ const char invisexplain[] = "remembered, unseen, creature"; /* Default object class symbols. See objclass.h. @@ -36,234 +36,231 @@ const char invisexplain[] = "remembered, unseen, creature"; * explain: used in do_look(). */ const struct class_sym def_oc_syms[MAXOCLASSES] = { -{ '\0', "", ""}, /* placeholder for the "random class" */ -{ ILLOBJ_SYM, "illegal objects", "strange object"}, -{ WEAPON_SYM, "weapons", "weapon"}, -{ ARMOR_SYM, "armor", "suit or piece of armor"}, -{ RING_SYM, "rings", "ring"}, -{ AMULET_SYM, "amulets", "amulet"}, -{ TOOL_SYM, "tools", "useful item (pick-axe, key, lamp...)"}, -{ FOOD_SYM, "food", "piece of food"}, -{ POTION_SYM, "potions", "potion"}, -{ SCROLL_SYM, "scrolls", "scroll"}, -{ SPBOOK_SYM, "spellbooks", "spellbook"}, -{ WAND_SYM, "wands", "wand"}, -{ GOLD_SYM, "coins", "pile of coins"}, -{ GEM_SYM, "rocks", "gem or rock"}, -{ ROCK_SYM, "large stones", "boulder or statue"}, -{ BALL_SYM, "iron balls", "iron ball"}, -{ CHAIN_SYM, "chains", "iron chain"}, -{ VENOM_SYM, "venoms", "splash of venom"} + { '\0', "", "" }, /* placeholder for the "random class" */ + { ILLOBJ_SYM, "illegal objects", "strange object" }, + { WEAPON_SYM, "weapons", "weapon" }, + { ARMOR_SYM, "armor", "suit or piece of armor" }, + { RING_SYM, "rings", "ring" }, + { AMULET_SYM, "amulets", "amulet" }, + { TOOL_SYM, "tools", "useful item (pick-axe, key, lamp...)" }, + { FOOD_SYM, "food", "piece of food" }, + { POTION_SYM, "potions", "potion" }, + { SCROLL_SYM, "scrolls", "scroll" }, + { SPBOOK_SYM, "spellbooks", "spellbook" }, + { WAND_SYM, "wands", "wand" }, + { GOLD_SYM, "coins", "pile of coins" }, + { GEM_SYM, "rocks", "gem or rock" }, + { ROCK_SYM, "large stones", "boulder or statue" }, + { BALL_SYM, "iron balls", "iron ball" }, + { CHAIN_SYM, "chains", "iron chain" }, + { VENOM_SYM, "venoms", "splash of venom" } }; /* Default monster class symbols. See monsym.h. */ const struct class_sym def_monsyms[MAXMCLASSES] = { - { '\0', "", ""}, - { DEF_ANT, "", "ant or other insect"}, - { DEF_BLOB, "", "blob"}, - { DEF_COCKATRICE, "", "cockatrice"}, - { DEF_DOG, "", "dog or other canine"}, - { DEF_EYE, "", "eye or sphere"}, - { DEF_FELINE, "", "cat or other feline"}, - { DEF_GREMLIN, "", "gremlin"}, - { DEF_HUMANOID, "", "humanoid"}, - { DEF_IMP, "", "imp or minor demon"}, - { DEF_JELLY, "", "jelly"}, - { DEF_KOBOLD, "", "kobold"}, - { DEF_LEPRECHAUN, "", "leprechaun"}, - { DEF_MIMIC, "", "mimic"}, - { DEF_NYMPH, "", "nymph"}, - { DEF_ORC, "", "orc"}, - { DEF_PIERCER, "", "piercer"}, - { DEF_QUADRUPED, "", "quadruped"}, - { DEF_RODENT, "", "rodent"}, - { DEF_SPIDER, "", "arachnid or centipede"}, - { DEF_TRAPPER, "", "trapper or lurker above"}, - { DEF_UNICORN, "", "unicorn or horse"}, - { DEF_VORTEX, "", "vortex"}, - { DEF_WORM, "", "worm"}, - { DEF_XAN, "", "xan or other mythical/fantastic insect"}, - { DEF_LIGHT, "", "light"}, - { DEF_ZRUTY, "", "zruty"}, - { DEF_ANGEL, "", "angelic being"}, - { DEF_BAT, "", "bat or bird"}, - { DEF_CENTAUR, "", "centaur"}, - { DEF_DRAGON, "", "dragon"}, - { DEF_ELEMENTAL, "", "elemental"}, - { DEF_FUNGUS, "", "fungus or mold"}, - { DEF_GNOME, "", "gnome"}, - { DEF_GIANT, "", "giant humanoid"}, - { '\0', "", "invisible monster"}, - { DEF_JABBERWOCK, "", "jabberwock"}, - { DEF_KOP, "", "Keystone Kop"}, - { DEF_LICH, "", "lich"}, - { DEF_MUMMY, "", "mummy"}, - { DEF_NAGA, "", "naga"}, - { DEF_OGRE, "", "ogre"}, - { DEF_PUDDING, "", "pudding or ooze"}, - { DEF_QUANTMECH, "", "quantum mechanic"}, - { DEF_RUSTMONST, "", "rust monster or disenchanter"}, - { DEF_SNAKE, "", "snake"}, - { DEF_TROLL, "", "troll"}, - { DEF_UMBER, "", "umber hulk"}, - { DEF_VAMPIRE, "", "vampire"}, - { DEF_WRAITH, "", "wraith"}, - { DEF_XORN, "", "xorn"}, - { DEF_YETI, "", "apelike creature"}, - { DEF_ZOMBIE, "", "zombie"}, - { DEF_HUMAN, "", "human or elf"}, - { DEF_GHOST, "", "ghost"}, - { DEF_GOLEM, "", "golem"}, - { DEF_DEMON, "", "major demon"}, - { DEF_EEL, "", "sea monster"}, - { DEF_LIZARD, "", "lizard"}, - { DEF_WORM_TAIL, "", "long worm tail"}, - { DEF_MIMIC_DEF, "", "mimic"}, + { '\0', "", "" }, + { DEF_ANT, "", "ant or other insect" }, + { DEF_BLOB, "", "blob" }, + { DEF_COCKATRICE, "", "cockatrice" }, + { DEF_DOG, "", "dog or other canine" }, + { DEF_EYE, "", "eye or sphere" }, + { DEF_FELINE, "", "cat or other feline" }, + { DEF_GREMLIN, "", "gremlin" }, + { DEF_HUMANOID, "", "humanoid" }, + { DEF_IMP, "", "imp or minor demon" }, + { DEF_JELLY, "", "jelly" }, + { DEF_KOBOLD, "", "kobold" }, + { DEF_LEPRECHAUN, "", "leprechaun" }, + { DEF_MIMIC, "", "mimic" }, + { DEF_NYMPH, "", "nymph" }, + { DEF_ORC, "", "orc" }, + { DEF_PIERCER, "", "piercer" }, + { DEF_QUADRUPED, "", "quadruped" }, + { DEF_RODENT, "", "rodent" }, + { DEF_SPIDER, "", "arachnid or centipede" }, + { DEF_TRAPPER, "", "trapper or lurker above" }, + { DEF_UNICORN, "", "unicorn or horse" }, + { DEF_VORTEX, "", "vortex" }, + { DEF_WORM, "", "worm" }, + { DEF_XAN, "", "xan or other mythical/fantastic insect" }, + { DEF_LIGHT, "", "light" }, + { DEF_ZRUTY, "", "zruty" }, + { DEF_ANGEL, "", "angelic being" }, + { DEF_BAT, "", "bat or bird" }, + { DEF_CENTAUR, "", "centaur" }, + { DEF_DRAGON, "", "dragon" }, + { DEF_ELEMENTAL, "", "elemental" }, + { DEF_FUNGUS, "", "fungus or mold" }, + { DEF_GNOME, "", "gnome" }, + { DEF_GIANT, "", "giant humanoid" }, + { '\0', "", "invisible monster" }, + { DEF_JABBERWOCK, "", "jabberwock" }, + { DEF_KOP, "", "Keystone Kop" }, + { DEF_LICH, "", "lich" }, + { DEF_MUMMY, "", "mummy" }, + { DEF_NAGA, "", "naga" }, + { DEF_OGRE, "", "ogre" }, + { DEF_PUDDING, "", "pudding or ooze" }, + { DEF_QUANTMECH, "", "quantum mechanic" }, + { DEF_RUSTMONST, "", "rust monster or disenchanter" }, + { DEF_SNAKE, "", "snake" }, + { DEF_TROLL, "", "troll" }, + { DEF_UMBER, "", "umber hulk" }, + { DEF_VAMPIRE, "", "vampire" }, + { DEF_WRAITH, "", "wraith" }, + { DEF_XORN, "", "xorn" }, + { DEF_YETI, "", "apelike creature" }, + { DEF_ZOMBIE, "", "zombie" }, + { DEF_HUMAN, "", "human or elf" }, + { DEF_GHOST, "", "ghost" }, + { DEF_GOLEM, "", "golem" }, + { DEF_DEMON, "", "major demon" }, + { DEF_EEL, "", "sea monster" }, + { DEF_LIZARD, "", "lizard" }, + { DEF_WORM_TAIL, "", "long worm tail" }, + { DEF_MIMIC_DEF, "", "mimic" }, }; const struct symdef def_warnsyms[WARNCOUNT] = { - {'0', "unknown creature causing you worry", C(CLR_WHITE)}, /* white warning */ - {'1', "unknown creature causing you concern", C(CLR_RED)}, /* pink warning */ - {'2', "unknown creature causing you anxiety", C(CLR_RED)}, /* red warning */ - {'3', "unknown creature causing you disquiet", C(CLR_RED)}, /* ruby warning */ - {'4', "unknown creature causing you alarm", - C(CLR_MAGENTA)}, /* purple warning */ - {'5', "unknown creature causing you dread", - C(CLR_BRIGHT_MAGENTA)} /* black warning */ + { '0', "unknown creature causing you worry", + C(CLR_WHITE) }, /* white warning */ + { '1', "unknown creature causing you concern", + C(CLR_RED) }, /* pink warning */ + { '2', "unknown creature causing you anxiety", + C(CLR_RED) }, /* red warning */ + { '3', "unknown creature causing you disquiet", + C(CLR_RED) }, /* ruby warning */ + { '4', "unknown creature causing you alarm", + C(CLR_MAGENTA) }, /* purple warning */ + { '5', "unknown creature causing you dread", + C(CLR_BRIGHT_MAGENTA) } /* black warning */ }; /* * Default screen symbols with explanations and colors. */ const struct symdef defsyms[MAXPCHARS] = { -/* 0*/ {' ', "dark part of a room",C(NO_COLOR)}, /* stone */ - {'|', "wall", C(CLR_GRAY)}, /* vwall */ - {'-', "wall", C(CLR_GRAY)}, /* hwall */ - {'-', "wall", C(CLR_GRAY)}, /* tlcorn */ - {'-', "wall", C(CLR_GRAY)}, /* trcorn */ - {'-', "wall", C(CLR_GRAY)}, /* blcorn */ - {'-', "wall", C(CLR_GRAY)}, /* brcorn */ - {'-', "wall", C(CLR_GRAY)}, /* crwall */ - {'-', "wall", C(CLR_GRAY)}, /* tuwall */ - {'-', "wall", C(CLR_GRAY)}, /* tdwall */ -/*10*/ {'|', "wall", C(CLR_GRAY)}, /* tlwall */ - {'|', "wall", C(CLR_GRAY)}, /* trwall */ - {'.', "doorway", C(CLR_GRAY)}, /* ndoor */ - {'-', "open door", C(CLR_BROWN)}, /* vodoor */ - {'|', "open door", C(CLR_BROWN)}, /* hodoor */ - {'+', "closed door", C(CLR_BROWN)}, /* vcdoor */ - {'+', "closed door", C(CLR_BROWN)}, /* hcdoor */ - {'#', "iron bars", C(HI_METAL)}, /* bars */ - {'#', "tree", C(CLR_GREEN)}, /* tree */ - {'.', "floor of a room",C(CLR_GRAY)}, /* room */ -/*20*/ {'.', "dark part of a room",C(CLR_BLACK)}, /* dark room */ - {'#', "corridor", C(CLR_GRAY)}, /* dark corr */ - {'#', "lit corridor", C(CLR_GRAY)}, /* lit corr (see mapglyph.c) */ - {'<', "staircase up", C(CLR_GRAY)}, /* upstair */ - {'>', "staircase down", C(CLR_GRAY)}, /* dnstair */ - {'<', "ladder up", C(CLR_BROWN)}, /* upladder */ - {'>', "ladder down", C(CLR_BROWN)}, /* dnladder */ - {'_', "altar", C(CLR_GRAY)}, /* altar */ - {'|', "grave", C(CLR_GRAY)}, /* grave */ - {'\\', "opulent throne",C(HI_GOLD)}, /* throne */ -/*30*/ {'#', "sink", C(CLR_GRAY)}, /* sink */ - {'{', "fountain", C(CLR_BLUE)}, /* fountain */ - {'}', "water", C(CLR_BLUE)}, /* pool */ - {'.', "ice", C(CLR_CYAN)}, /* ice */ - {'}', "molten lava", C(CLR_RED)}, /* lava */ - {'.', "lowered drawbridge",C(CLR_BROWN)}, /* vodbridge */ - {'.', "lowered drawbridge",C(CLR_BROWN)}, /* hodbridge */ - {'#', "raised drawbridge",C(CLR_BROWN)}, /* vcdbridge */ - {'#', "raised drawbridge",C(CLR_BROWN)}, /* hcdbridge */ - {' ', "air", C(CLR_CYAN)}, /* open air */ -/*40*/ {'#', "cloud", C(CLR_GRAY)}, /* [part of] a cloud */ - {'}', "water", C(CLR_BLUE)}, /* under water */ - {'^', "arrow trap", C(HI_METAL)}, /* trap */ - {'^', "dart trap", C(HI_METAL)}, /* trap */ - {'^', "falling rock trap",C(CLR_GRAY)}, /* trap */ - {'^', "squeaky board", C(CLR_BROWN)}, /* trap */ - {'^', "bear trap", C(HI_METAL)}, /* trap */ - {'^', "land mine", C(CLR_RED)}, /* trap */ - {'^', "rolling boulder trap", C(CLR_GRAY)}, /* trap */ - {'^', "sleeping gas trap",C(HI_ZAP)}, /* trap */ -/*50*/ {'^', "rust trap", C(CLR_BLUE)}, /* trap */ - {'^', "fire trap", C(CLR_ORANGE)}, /* trap */ - {'^', "pit", C(CLR_BLACK)}, /* trap */ - {'^', "spiked pit", C(CLR_BLACK)}, /* trap */ - {'^', "hole", C(CLR_BROWN)}, /* trap */ - {'^', "trap door", C(CLR_BROWN)}, /* trap */ - {'^', "teleportation trap", C(CLR_MAGENTA)}, /* trap */ - {'^', "level teleporter", C(CLR_MAGENTA)}, /* trap */ - {'^', "magic portal", C(CLR_BRIGHT_MAGENTA)}, /* trap */ - {'"', "web", C(CLR_GRAY)}, /* web */ -/*60*/ {'^', "statue trap", C(CLR_GRAY)}, /* trap */ - {'^', "magic trap", C(HI_ZAP)}, /* trap */ - {'^', "anti-magic field", C(HI_ZAP)}, /* trap */ - {'^', "polymorph trap", C(CLR_BRIGHT_GREEN)}, /* trap */ - {'|', "wall", C(CLR_GRAY)}, /* vbeam */ - {'-', "wall", C(CLR_GRAY)}, /* hbeam */ - {'\\',"wall", C(CLR_GRAY)}, /* lslant */ - {'/', "wall", C(CLR_GRAY)}, /* rslant */ - {'*', "", C(CLR_WHITE)}, /* dig beam */ - {'!', "", C(CLR_WHITE)}, /* camera flash beam */ -/*70*/ {')', "", C(HI_WOOD)}, /* boomerang open left */ - {'(', "", C(HI_WOOD)}, /* boomerang open right */ - {'0', "", C(HI_ZAP)}, /* 4 magic shield symbols */ - {'#', "", C(HI_ZAP)}, - {'@', "", C(HI_ZAP)}, - {'*', "", C(HI_ZAP)}, - {'#', "poison cloud", C(CLR_BRIGHT_GREEN)}, /* [part of] a poison cloud */ - {'?', "valid position", C(CLR_BRIGHT_GREEN)}, /* valid position for targeting */ - {'/', "", C(CLR_GREEN)}, /* swallow top left */ - {'-', "", C(CLR_GREEN)}, /* swallow top center */ -/*80*/ {'\\', "", C(CLR_GREEN)}, /* swallow top right */ - {'|', "", C(CLR_GREEN)}, /* swallow middle left */ - {'|', "", C(CLR_GREEN)}, /* swallow middle right */ - {'\\', "", C(CLR_GREEN)}, /* swallow bottom left */ - {'-', "", C(CLR_GREEN)}, /* swallow bottom center*/ - {'/', "", C(CLR_GREEN)}, /* swallow bottom right */ - {'/', "", C(CLR_ORANGE)}, /* explosion top left */ - {'-', "", C(CLR_ORANGE)}, /* explosion top center */ - {'\\', "", C(CLR_ORANGE)}, /* explosion top right */ - {'|', "", C(CLR_ORANGE)}, /* explosion middle left */ -/*90*/ {' ', "", C(CLR_ORANGE)}, /* explosion middle center*/ - {'|', "", C(CLR_ORANGE)}, /* explosion middle right */ - {'\\', "", C(CLR_ORANGE)}, /* explosion bottom left */ - {'-', "", C(CLR_ORANGE)}, /* explosion bottom center*/ - {'/', "", C(CLR_ORANGE)}, /* explosion bottom right */ + /* 0*/ { ' ', "dark part of a room", C(NO_COLOR) }, /* stone */ + { '|', "wall", C(CLR_GRAY) }, /* vwall */ + { '-', "wall", C(CLR_GRAY) }, /* hwall */ + { '-', "wall", C(CLR_GRAY) }, /* tlcorn */ + { '-', "wall", C(CLR_GRAY) }, /* trcorn */ + { '-', "wall", C(CLR_GRAY) }, /* blcorn */ + { '-', "wall", C(CLR_GRAY) }, /* brcorn */ + { '-', "wall", C(CLR_GRAY) }, /* crwall */ + { '-', "wall", C(CLR_GRAY) }, /* tuwall */ + { '-', "wall", C(CLR_GRAY) }, /* tdwall */ + /*10*/ { '|', "wall", C(CLR_GRAY) }, /* tlwall */ + { '|', "wall", C(CLR_GRAY) }, /* trwall */ + { '.', "doorway", C(CLR_GRAY) }, /* ndoor */ + { '-', "open door", C(CLR_BROWN) }, /* vodoor */ + { '|', "open door", C(CLR_BROWN) }, /* hodoor */ + { '+', "closed door", C(CLR_BROWN) }, /* vcdoor */ + { '+', "closed door", C(CLR_BROWN) }, /* hcdoor */ + { '#', "iron bars", C(HI_METAL) }, /* bars */ + { '#', "tree", C(CLR_GREEN) }, /* tree */ + { '.', "floor of a room", C(CLR_GRAY) }, /* room */ + /*20*/ { '.', "dark part of a room", C(CLR_BLACK) }, /* dark room */ + { '#', "corridor", C(CLR_GRAY) }, /* dark corr */ + { '#', "lit corridor", C(CLR_GRAY) }, /* lit corr (see mapglyph.c) */ + { '<', "staircase up", C(CLR_GRAY) }, /* upstair */ + { '>', "staircase down", C(CLR_GRAY) }, /* dnstair */ + { '<', "ladder up", C(CLR_BROWN) }, /* upladder */ + { '>', "ladder down", C(CLR_BROWN) }, /* dnladder */ + { '_', "altar", C(CLR_GRAY) }, /* altar */ + { '|', "grave", C(CLR_GRAY) }, /* grave */ + { '\\', "opulent throne", C(HI_GOLD) }, /* throne */ + /*30*/ { '#', "sink", C(CLR_GRAY) }, /* sink */ + { '{', "fountain", C(CLR_BLUE) }, /* fountain */ + { '}', "water", C(CLR_BLUE) }, /* pool */ + { '.', "ice", C(CLR_CYAN) }, /* ice */ + { '}', "molten lava", C(CLR_RED) }, /* lava */ + { '.', "lowered drawbridge", C(CLR_BROWN) }, /* vodbridge */ + { '.', "lowered drawbridge", C(CLR_BROWN) }, /* hodbridge */ + { '#', "raised drawbridge", C(CLR_BROWN) }, /* vcdbridge */ + { '#', "raised drawbridge", C(CLR_BROWN) }, /* hcdbridge */ + { ' ', "air", C(CLR_CYAN) }, /* open air */ + /*40*/ { '#', "cloud", C(CLR_GRAY) }, /* [part of] a cloud */ + { '}', "water", C(CLR_BLUE) }, /* under water */ + { '^', "arrow trap", C(HI_METAL) }, /* trap */ + { '^', "dart trap", C(HI_METAL) }, /* trap */ + { '^', "falling rock trap", C(CLR_GRAY) }, /* trap */ + { '^', "squeaky board", C(CLR_BROWN) }, /* trap */ + { '^', "bear trap", C(HI_METAL) }, /* trap */ + { '^', "land mine", C(CLR_RED) }, /* trap */ + { '^', "rolling boulder trap", C(CLR_GRAY) }, /* trap */ + { '^', "sleeping gas trap", C(HI_ZAP) }, /* trap */ + /*50*/ { '^', "rust trap", C(CLR_BLUE) }, /* trap */ + { '^', "fire trap", C(CLR_ORANGE) }, /* trap */ + { '^', "pit", C(CLR_BLACK) }, /* trap */ + { '^', "spiked pit", C(CLR_BLACK) }, /* trap */ + { '^', "hole", C(CLR_BROWN) }, /* trap */ + { '^', "trap door", C(CLR_BROWN) }, /* trap */ + { '^', "teleportation trap", C(CLR_MAGENTA) }, /* trap */ + { '^', "level teleporter", C(CLR_MAGENTA) }, /* trap */ + { '^', "magic portal", C(CLR_BRIGHT_MAGENTA) }, /* trap */ + { '"', "web", C(CLR_GRAY) }, /* web */ + /*60*/ { '^', "statue trap", C(CLR_GRAY) }, /* trap */ + { '^', "magic trap", C(HI_ZAP) }, /* trap */ + { '^', "anti-magic field", C(HI_ZAP) }, /* trap */ + { '^', "polymorph trap", C(CLR_BRIGHT_GREEN) }, /* trap */ + { '|', "wall", C(CLR_GRAY) }, /* vbeam */ + { '-', "wall", C(CLR_GRAY) }, /* hbeam */ + { '\\', "wall", C(CLR_GRAY) }, /* lslant */ + { '/', "wall", C(CLR_GRAY) }, /* rslant */ + { '*', "", C(CLR_WHITE) }, /* dig beam */ + { '!', "", C(CLR_WHITE) }, /* camera flash beam */ + /*70*/ { ')', "", C(HI_WOOD) }, /* boomerang open left */ + { '(', "", C(HI_WOOD) }, /* boomerang open right */ + { '0', "", C(HI_ZAP) }, /* 4 magic shield symbols */ + { '#', "", C(HI_ZAP) }, + { '@', "", C(HI_ZAP) }, + { '*', "", C(HI_ZAP) }, + { '#', "poison cloud", + C(CLR_BRIGHT_GREEN) }, /* [part of] a poison cloud */ + { '?', "valid position", + C(CLR_BRIGHT_GREEN) }, /* valid position for targeting */ + { '/', "", C(CLR_GREEN) }, /* swallow top left */ + { '-', "", C(CLR_GREEN) }, /* swallow top center */ + /*80*/ { '\\', "", C(CLR_GREEN) }, /* swallow top right */ + { '|', "", C(CLR_GREEN) }, /* swallow middle left */ + { '|', "", C(CLR_GREEN) }, /* swallow middle right */ + { '\\', "", C(CLR_GREEN) }, /* swallow bottom left */ + { '-', "", C(CLR_GREEN) }, /* swallow bottom center*/ + { '/', "", C(CLR_GREEN) }, /* swallow bottom right */ + { '/', "", C(CLR_ORANGE) }, /* explosion top left */ + { '-', "", C(CLR_ORANGE) }, /* explosion top center */ + { '\\', "", C(CLR_ORANGE) }, /* explosion top right */ + { '|', "", C(CLR_ORANGE) }, /* explosion middle left */ + /*90*/ { ' ', "", C(CLR_ORANGE) }, /* explosion middle center*/ + { '|', "", C(CLR_ORANGE) }, /* explosion middle right */ + { '\\', "", C(CLR_ORANGE) }, /* explosion bottom left */ + { '-', "", C(CLR_ORANGE) }, /* explosion bottom center*/ + { '/', "", C(CLR_ORANGE) }, /* explosion bottom right */ }; /* default rogue level symbols */ static const uchar def_r_oc_syms[MAXOCLASSES] = { -/* 0*/ '\0', - ILLOBJ_SYM, - WEAPON_SYM, - ']', /* armor */ - RING_SYM, -/* 5*/ ',', /* amulet */ - TOOL_SYM, - ':', /* food */ - POTION_SYM, - SCROLL_SYM, -/*10*/ SPBOOK_SYM, - WAND_SYM, - GEM_SYM, /* gold -- yes it's the same as gems */ - GEM_SYM, - ROCK_SYM, -/*15*/ BALL_SYM, - CHAIN_SYM, - VENOM_SYM + /* 0*/ '\0', ILLOBJ_SYM, WEAPON_SYM, ']', /* armor */ + RING_SYM, + /* 5*/ ',', /* amulet */ + TOOL_SYM, ':', /* food */ + POTION_SYM, SCROLL_SYM, + /*10*/ SPBOOK_SYM, WAND_SYM, + GEM_SYM, /* gold -- yes it's the same as gems */ + GEM_SYM, ROCK_SYM, + /*15*/ BALL_SYM, CHAIN_SYM, VENOM_SYM }; #undef C #ifdef TERMLIB -void NDECL((*decgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ -#endif /* TERMLIB */ +void NDECL((*decgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ +#endif /* TERMLIB */ #ifdef PC9800 -void NDECL((*ibmgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ -void NDECL((*ascgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ +void NDECL((*ibmgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ +void NDECL((*ascgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ #endif /* @@ -273,11 +270,12 @@ void NDECL((*ascgraphics_mode_callback)) = 0; /* set in tty_start_screen() */ */ int def_char_to_objclass(ch) - char ch; +char ch; { int i; for (i = 1; i < MAXOCLASSES; i++) - if (ch == def_oc_syms[i].sym) break; + if (ch == def_oc_syms[i].sym) + break; return i; } @@ -288,11 +286,12 @@ def_char_to_objclass(ch) */ int def_char_to_monclass(ch) - char ch; +char ch; { int i; for (i = 1; i < MAXMCLASSES; i++) - if (ch == def_monsyms[i].sym) break; + if (ch == def_monsyms[i].sym) + break; return i; } @@ -314,7 +313,7 @@ def_char_to_monclass(ch) * or from the loaded symbols. * * If (arg == 0) then showsyms are taken from - * defsyms, def_oc_syms, and def_monsyms. + * defsyms, def_oc_syms, and def_monsyms. * * If (arg != 0), which is the normal expected * usage, then showsyms are taken from the @@ -335,19 +334,19 @@ def_char_to_monclass(ch) * from l_monsyms into showsyms. * * update_l_symset() - * Update a member of the loadable (l_*) symbol set. + * Update a member of the loadable (l_*) symbol set. * * update_r_symset() - * Update a member of the rogue (r_*) symbol set. + * Update a member of the rogue (r_*) symbol set. * */ void init_symbols() { - init_l_symbols(); - init_showsyms(); - init_r_symbols(); + init_l_symbols(); + init_showsyms(); + init_r_symbols(); } void @@ -361,90 +360,90 @@ update_bouldersym() void init_showsyms() { - register int i; + register int i; - for (i = 0; i < MAXPCHARS; i++) - showsyms[i + SYM_OFF_P] = defsyms[i].sym; + for (i = 0; i < MAXPCHARS; i++) + showsyms[i + SYM_OFF_P] = defsyms[i].sym; - for (i = 0; i < MAXOCLASSES; i++) - showsyms[i + SYM_OFF_O] = def_oc_syms[i].sym; + for (i = 0; i < MAXOCLASSES; i++) + showsyms[i + SYM_OFF_O] = def_oc_syms[i].sym; - for (i = 0; i < MAXMCLASSES; i++) - showsyms[i + SYM_OFF_M] = def_monsyms[i].sym; + for (i = 0; i < MAXMCLASSES; i++) + showsyms[i + SYM_OFF_M] = def_monsyms[i].sym; - for (i = 0; i < WARNCOUNT; i++) - showsyms[i + SYM_OFF_W] = def_warnsyms[i].sym; + for (i = 0; i < WARNCOUNT; i++) + showsyms[i + SYM_OFF_W] = def_warnsyms[i].sym; - for (i = 0; i < MAXOTHER; i++) { - if (i == SYM_BOULDER) - showsyms[i + SYM_OFF_X] = iflags.bouldersym; - else if (i == SYM_INVISIBLE) - showsyms[i + SYM_OFF_X] = DEF_INVISIBLE; - } + for (i = 0; i < MAXOTHER; i++) { + if (i == SYM_BOULDER) + showsyms[i + SYM_OFF_X] = iflags.bouldersym; + else if (i == SYM_INVISIBLE) + showsyms[i + SYM_OFF_X] = DEF_INVISIBLE; + } } /* initialize defaults for the loadable symset */ void init_l_symbols() { - register int i; + register int i; - for (i = 0; i < MAXPCHARS; i++) - l_syms[i + SYM_OFF_P] = defsyms[i].sym; + for (i = 0; i < MAXPCHARS; i++) + l_syms[i + SYM_OFF_P] = defsyms[i].sym; - for (i = 0; i < MAXOCLASSES; i++) - l_syms[i + SYM_OFF_O] = def_oc_syms[i].sym; + for (i = 0; i < MAXOCLASSES; i++) + l_syms[i + SYM_OFF_O] = def_oc_syms[i].sym; - for (i = 0; i < MAXMCLASSES; i++) - l_syms[i + SYM_OFF_M] = def_monsyms[i].sym; + for (i = 0; i < MAXMCLASSES; i++) + l_syms[i + SYM_OFF_M] = def_monsyms[i].sym; - for (i = 0; i < WARNCOUNT; i++) - l_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; + for (i = 0; i < WARNCOUNT; i++) + l_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; - for (i = 0; i < MAXOTHER; i++) { - if (i == SYM_BOULDER) - l_syms[i + SYM_OFF_X] = iflags.bouldersym; - else if (i == SYM_INVISIBLE) - l_syms[i + SYM_OFF_X] = DEF_INVISIBLE; - } + for (i = 0; i < MAXOTHER; i++) { + if (i == SYM_BOULDER) + l_syms[i + SYM_OFF_X] = iflags.bouldersym; + else if (i == SYM_INVISIBLE) + l_syms[i + SYM_OFF_X] = DEF_INVISIBLE; + } - clear_symsetentry(PRIMARY, FALSE); + clear_symsetentry(PRIMARY, FALSE); } void init_r_symbols() { - register int i; + register int i; - /* These are defaults that can get overwritten - later by the roguesymbols option */ + /* These are defaults that can get overwritten + later by the roguesymbols option */ - for (i = 0; i < MAXPCHARS; i++) - r_syms[i + SYM_OFF_P] = defsyms[i].sym; - r_syms[S_vodoor] = r_syms[S_hodoor] = r_syms[S_ndoor] = '+'; - r_syms[S_upstair] = r_syms[S_dnstair] = '%'; + for (i = 0; i < MAXPCHARS; i++) + r_syms[i + SYM_OFF_P] = defsyms[i].sym; + r_syms[S_vodoor] = r_syms[S_hodoor] = r_syms[S_ndoor] = '+'; + r_syms[S_upstair] = r_syms[S_dnstair] = '%'; - for (i = 0; i < MAXOCLASSES; i++) - r_syms[i + SYM_OFF_O] = def_r_oc_syms[i]; + for (i = 0; i < MAXOCLASSES; i++) + r_syms[i + SYM_OFF_O] = def_r_oc_syms[i]; - for (i = 0; i < MAXMCLASSES; i++) - r_syms[i + SYM_OFF_M] = def_monsyms[i].sym; + for (i = 0; i < MAXMCLASSES; i++) + r_syms[i + SYM_OFF_M] = def_monsyms[i].sym; - for (i = 0; i < WARNCOUNT; i++) - r_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; + for (i = 0; i < WARNCOUNT; i++) + r_syms[i + SYM_OFF_W] = def_warnsyms[i].sym; - for (i = 0; i < MAXOTHER; i++) { - if (i == SYM_BOULDER) - r_syms[i + SYM_OFF_X] = iflags.bouldersym; - else if (i == SYM_INVISIBLE) - r_syms[i + SYM_OFF_X] = DEF_INVISIBLE; - } + for (i = 0; i < MAXOTHER; i++) { + if (i == SYM_BOULDER) + r_syms[i + SYM_OFF_X] = iflags.bouldersym; + else if (i == SYM_INVISIBLE) + r_syms[i + SYM_OFF_X] = DEF_INVISIBLE; + } - clear_symsetentry(ROGUESET, FALSE); - symset[ROGUESET].nocolor = 1; /* default on Rogue level is no color - * but some symbol sets can - * override that - */ + clear_symsetentry(ROGUESET, FALSE); + symset[ROGUESET].nocolor = 1; /* default on Rogue level is no color + * but some symbol sets can + * override that + */ } void @@ -453,29 +452,31 @@ int whichset; { register int i; - switch(whichset) { + switch (whichset) { case ROGUESET: - /* Adjust graphics display characters on Rogue levels */ + /* Adjust graphics display characters on Rogue levels */ - for (i = 0; i < SYM_MAX; i++) - showsyms[i] = r_syms[i]; + for (i = 0; i < SYM_MAX; i++) + showsyms[i] = r_syms[i]; -# if defined(MSDOS) && defined(USE_TILES) - if (iflags.grmode) tileview(FALSE); -# endif - currentgraphics = ROGUESET; - break; +#if defined(MSDOS) && defined(USE_TILES) + if (iflags.grmode) + tileview(FALSE); +#endif + currentgraphics = ROGUESET; + break; case PRIMARY: default: - for (i = 0; i < SYM_MAX; i++) - showsyms[i] = l_syms[i]; + for (i = 0; i < SYM_MAX; i++) + showsyms[i] = l_syms[i]; -# if defined(MSDOS) && defined(USE_TILES) - if (iflags.grmode) tileview(TRUE); -# endif - currentgraphics = PRIMARY; - break; +#if defined(MSDOS) && defined(USE_TILES) + if (iflags.grmode) + tileview(TRUE); +#endif + currentgraphics = PRIMARY; + break; } } @@ -483,25 +484,23 @@ void switch_symbols(nondefault) int nondefault; { - register int i; + register int i; - if (nondefault) { - for (i = 0; i < SYM_MAX; i++) - showsyms[i] = l_syms[i]; -# ifdef PC9800 - if (SYMHANDLING(H_IBM) - && ibmgraphics_mode_callback) - (*ibmgraphics_mode_callback)(); - else if (!symset[currentgraphics].name && ascgraphics_mode_callback) - (*ascgraphics_mode_callback)(); -# endif -# ifdef TERMLIB - if (SYMHANDLING(H_DEC) - && decgraphics_mode_callback) - (*decgraphics_mode_callback)(); -# endif - } else - init_symbols(); + if (nondefault) { + for (i = 0; i < SYM_MAX; i++) + showsyms[i] = l_syms[i]; +#ifdef PC9800 + if (SYMHANDLING(H_IBM) && ibmgraphics_mode_callback) + (*ibmgraphics_mode_callback)(); + else if (!symset[currentgraphics].name && ascgraphics_mode_callback) + (*ascgraphics_mode_callback)(); +#endif +#ifdef TERMLIB + if (SYMHANDLING(H_DEC) && decgraphics_mode_callback) + (*decgraphics_mode_callback)(); +#endif + } else + init_symbols(); } void @@ -509,7 +508,7 @@ update_l_symset(symp, val) struct symparse *symp; int val; { - l_syms[symp->idx] = val; + l_syms[symp->idx] = val; } void @@ -517,7 +516,7 @@ update_r_symset(symp, val) struct symparse *symp; int val; { - r_syms[symp->idx] = val; + r_syms[symp->idx] = val; } void @@ -525,36 +524,36 @@ clear_symsetentry(which_set, name_too) int which_set; boolean name_too; { - if (symset[which_set].desc) - free((genericptr_t)symset[which_set].desc); - symset[which_set].desc = (char *)0; + if (symset[which_set].desc) + free((genericptr_t) symset[which_set].desc); + symset[which_set].desc = (char *) 0; - symset[which_set].nocolor = 0; - symset[which_set].handling = H_UNK; - symset[which_set].desc = (char *)0; - symset[which_set].nocolor = 0; - /* initialize restriction bits */ - symset[which_set].primary = 0; - symset[which_set].rogue = 0; + symset[which_set].nocolor = 0; + symset[which_set].handling = H_UNK; + symset[which_set].desc = (char *) 0; + symset[which_set].nocolor = 0; + /* initialize restriction bits */ + symset[which_set].primary = 0; + symset[which_set].rogue = 0; - if (name_too) { - if (symset[which_set].name) - free((genericptr_t)symset[which_set].name); - symset[which_set].name = (char *)0; - } + if (name_too) { + if (symset[which_set].name) + free((genericptr_t) symset[which_set].name); + symset[which_set].name = (char *) 0; + } } /* * If you are adding code somewhere to be able to recognize - * particular types of symset "handling", define a + * particular types of symset "handling", define a * H_XXX macro in include/rm.h and add the name * to this array at the matching offset. */ const char *known_handling[] = { - "UNKNOWN", /* H_UNK */ - "IBM", /* H_IBM */ - "DEC", /* H_DEC */ - (const char *)0, + "UNKNOWN", /* H_UNK */ + "IBM", /* H_IBM */ + "DEC", /* H_DEC */ + (const char *) 0, }; /* @@ -571,194 +570,191 @@ const char *known_handling[] = { * - add the field to clear_symsetentry() */ const char *known_restrictions[] = { - "primary", - "rogue", - (const char *)0, + "primary", "rogue", (const char *) 0, }; struct symparse loadsyms[] = { - {SYM_CONTROL, 0, "start"}, - {SYM_CONTROL, 0, "begin"}, - {SYM_CONTROL, 1, "finish"}, - {SYM_CONTROL, 2, "handling"}, - {SYM_CONTROL, 3, "description"}, - {SYM_CONTROL, 4, "color"}, - {SYM_CONTROL, 4, "colour"}, - {SYM_CONTROL, 5, "restrictions"}, - {SYM_PCHAR, S_stone, "S_stone"}, - {SYM_PCHAR, S_vwall, "S_vwall"}, - {SYM_PCHAR, S_hwall, "S_hwall"}, - {SYM_PCHAR, S_tlcorn, "S_tlcorn"}, - {SYM_PCHAR, S_trcorn, "S_trcorn"}, - {SYM_PCHAR, S_blcorn, "S_blcorn"}, - {SYM_PCHAR, S_brcorn, "S_brcorn"}, - {SYM_PCHAR, S_crwall, "S_crwall"}, - {SYM_PCHAR, S_tuwall, "S_tuwall"}, - {SYM_PCHAR, S_tdwall, "S_tdwall"}, - {SYM_PCHAR, S_tlwall, "S_tlwall"}, - {SYM_PCHAR, S_trwall, "S_trwall"}, - {SYM_PCHAR, S_ndoor, "S_ndoor"}, - {SYM_PCHAR, S_vodoor, "S_vodoor"}, - {SYM_PCHAR, S_hodoor, "S_hodoor"}, - {SYM_PCHAR, S_vcdoor, "S_vcdoor"}, - {SYM_PCHAR, S_hcdoor, "S_hcdoor"}, - {SYM_PCHAR, S_bars, "S_bars"}, - {SYM_PCHAR, S_tree, "S_tree"}, - {SYM_PCHAR, S_room, "S_room"}, - {SYM_PCHAR, S_corr, "S_corr"}, - {SYM_PCHAR, S_litcorr, "S_litcorr"}, - {SYM_PCHAR, S_upstair, "S_upstair"}, - {SYM_PCHAR, S_dnstair, "S_dnstair"}, - {SYM_PCHAR, S_upladder, "S_upladder"}, - {SYM_PCHAR, S_dnladder, "S_dnladder"}, - {SYM_PCHAR, S_altar, "S_altar"}, - {SYM_PCHAR, S_grave, "S_grave"}, - {SYM_PCHAR, S_throne, "S_throne"}, - {SYM_PCHAR, S_sink, "S_sink"}, - {SYM_PCHAR, S_fountain, "S_fountain"}, - {SYM_PCHAR, S_pool, "S_pool"}, - {SYM_PCHAR, S_ice, "S_ice"}, - {SYM_PCHAR, S_lava, "S_lava"}, - {SYM_PCHAR, S_vodbridge, "S_vodbridge"}, - {SYM_PCHAR, S_hodbridge, "S_hodbridge"}, - {SYM_PCHAR, S_vcdbridge, "S_vcdbridge"}, - {SYM_PCHAR, S_hcdbridge, "S_hcdbridge"}, - {SYM_PCHAR, S_air, "S_air"}, - {SYM_PCHAR, S_cloud, "S_cloud"}, - {SYM_PCHAR, S_poisoncloud, "S_poisoncloud"}, - {SYM_PCHAR, S_water, "S_water"}, - {SYM_PCHAR, S_arrow_trap, "S_arrow_trap"}, - {SYM_PCHAR, S_dart_trap, "S_dart_trap"}, - {SYM_PCHAR, S_falling_rock_trap, "S_falling_rock_trap"}, - {SYM_PCHAR, S_squeaky_board, "S_squeaky_board"}, - {SYM_PCHAR, S_bear_trap, "S_bear_trap"}, - {SYM_PCHAR, S_land_mine, "S_land_mine"}, - {SYM_PCHAR, S_rolling_boulder_trap, "S_rolling_boulder_trap"}, - {SYM_PCHAR, S_sleeping_gas_trap, "S_sleeping_gas_trap"}, - {SYM_PCHAR, S_rust_trap, "S_rust_trap"}, - {SYM_PCHAR, S_fire_trap, "S_fire_trap"}, - {SYM_PCHAR, S_pit, "S_pit"}, - {SYM_PCHAR, S_spiked_pit, "S_spiked_pit"}, - {SYM_PCHAR, S_hole, "S_hole"}, - {SYM_PCHAR, S_trap_door, "S_trap_door"}, - {SYM_PCHAR, S_teleportation_trap, "S_teleportation_trap"}, - {SYM_PCHAR, S_level_teleporter, "S_level_teleporter"}, - {SYM_PCHAR, S_magic_portal, "S_magic_portal"}, - {SYM_PCHAR, S_web, "S_web"}, - {SYM_PCHAR, S_statue_trap, "S_statue_trap"}, - {SYM_PCHAR, S_magic_trap, "S_magic_trap"}, - {SYM_PCHAR, S_anti_magic_trap, "S_anti_magic_trap"}, - {SYM_PCHAR, S_polymorph_trap, "S_polymorph_trap"}, - {SYM_PCHAR, S_vbeam, "S_vbeam"}, - {SYM_PCHAR, S_hbeam, "S_hbeam"}, - {SYM_PCHAR, S_lslant, "S_lslant"}, - {SYM_PCHAR, S_rslant, "S_rslant"}, - {SYM_PCHAR, S_digbeam, "S_digbeam"}, - {SYM_PCHAR, S_flashbeam, "S_flashbeam"}, - {SYM_PCHAR, S_boomleft, "S_boomleft"}, - {SYM_PCHAR, S_boomright, "S_boomright"}, - {SYM_PCHAR, S_goodpos, "S_goodpos"}, - {SYM_PCHAR, S_ss1, "S_ss1"}, - {SYM_PCHAR, S_ss2, "S_ss2"}, - {SYM_PCHAR, S_ss3, "S_ss3"}, - {SYM_PCHAR, S_ss4, "S_ss4"}, - {SYM_PCHAR, S_sw_tl, "S_sw_tl"}, - {SYM_PCHAR, S_sw_tc, "S_sw_tc"}, - {SYM_PCHAR, S_sw_tr, "S_sw_tr"}, - {SYM_PCHAR, S_sw_ml, "S_sw_ml"}, - {SYM_PCHAR, S_sw_mr, "S_sw_mr"}, - {SYM_PCHAR, S_sw_bl, "S_sw_bl"}, - {SYM_PCHAR, S_sw_bc, "S_sw_bc"}, - {SYM_PCHAR, S_sw_br, "S_sw_br"}, - {SYM_PCHAR, S_explode1, "S_explode1"}, - {SYM_PCHAR, S_explode2, "S_explode2"}, - {SYM_PCHAR, S_explode3, "S_explode3"}, - {SYM_PCHAR, S_explode4, "S_explode4"}, - {SYM_PCHAR, S_explode5, "S_explode5"}, - {SYM_PCHAR, S_explode6, "S_explode6"}, - {SYM_PCHAR, S_explode7, "S_explode7"}, - {SYM_PCHAR, S_explode8, "S_explode8"}, - {SYM_PCHAR, S_explode9, "S_explode9"}, - {SYM_OC, WEAPON_CLASS + SYM_OFF_O, "S_weapon"}, - {SYM_OC, ARMOR_CLASS + SYM_OFF_O, "S_armor"}, - {SYM_OC, ARMOR_CLASS + SYM_OFF_O, "S_armour"}, - {SYM_OC, RING_CLASS + SYM_OFF_O, "S_ring"}, - {SYM_OC, AMULET_CLASS + SYM_OFF_O, "S_amulet"}, - {SYM_OC, TOOL_CLASS + SYM_OFF_O, "S_tool"}, - {SYM_OC, FOOD_CLASS + SYM_OFF_O, "S_food"}, - {SYM_OC, POTION_CLASS + SYM_OFF_O, "S_potion"}, - {SYM_OC, SCROLL_CLASS + SYM_OFF_O, "S_scroll"}, - {SYM_OC, SPBOOK_CLASS + SYM_OFF_O, "S_book"}, - {SYM_OC, WAND_CLASS + SYM_OFF_O, "S_wand"}, - {SYM_OC, COIN_CLASS + SYM_OFF_O, "S_coin"}, - {SYM_OC, GEM_CLASS + SYM_OFF_O, "S_gem"}, - {SYM_OC, ROCK_CLASS + SYM_OFF_O, "S_rock"}, - {SYM_OC, BALL_CLASS + SYM_OFF_O, "S_ball"}, - {SYM_OC, CHAIN_CLASS + SYM_OFF_O, "S_chain"}, - {SYM_OC, VENOM_CLASS + SYM_OFF_O, "S_venom"}, - {SYM_MON, S_ANT + SYM_OFF_M, "S_ant"}, - {SYM_MON, S_BLOB + SYM_OFF_M, "S_blob"}, - {SYM_MON, S_COCKATRICE + SYM_OFF_M, "S_cockatrice"}, - {SYM_MON, S_DOG + SYM_OFF_M, "S_dog"}, - {SYM_MON, S_EYE + SYM_OFF_M, "S_eye"}, - {SYM_MON, S_FELINE + SYM_OFF_M, "S_feline"}, - {SYM_MON, S_GREMLIN + SYM_OFF_M, "S_gremlin"}, - {SYM_MON, S_HUMANOID + SYM_OFF_M, "S_humanoid"}, - {SYM_MON, S_IMP + SYM_OFF_M, "S_imp"}, - {SYM_MON, S_JELLY + SYM_OFF_M, "S_jelly"}, - {SYM_MON, S_KOBOLD + SYM_OFF_M, "S_kobold"}, - {SYM_MON, S_LEPRECHAUN + SYM_OFF_M, "S_leprechaun"}, - {SYM_MON, S_MIMIC + SYM_OFF_M, "S_mimic"}, - {SYM_MON, S_NYMPH + SYM_OFF_M, "S_nymph"}, - {SYM_MON, S_ORC + SYM_OFF_M, "S_orc"}, - {SYM_MON, S_PIERCER + SYM_OFF_M, "S_piercer"}, - {SYM_MON, S_QUADRUPED + SYM_OFF_M, "S_quadruped"}, - {SYM_MON, S_RODENT + SYM_OFF_M, "S_rodent"}, - {SYM_MON, S_SPIDER + SYM_OFF_M, "S_spider"}, - {SYM_MON, S_TRAPPER + SYM_OFF_M, "S_trapper"}, - {SYM_MON, S_UNICORN + SYM_OFF_M, "S_unicorn"}, - {SYM_MON, S_VORTEX + SYM_OFF_M, "S_vortex"}, - {SYM_MON, S_WORM + SYM_OFF_M, "S_worm"}, - {SYM_MON, S_XAN + SYM_OFF_M, "S_xan"}, - {SYM_MON, S_LIGHT + SYM_OFF_M, "S_light"}, - {SYM_MON, S_ZRUTY + SYM_OFF_M, "S_zruty"}, - {SYM_MON, S_ANGEL + SYM_OFF_M, "S_angel"}, - {SYM_MON, S_BAT + SYM_OFF_M, "S_bat"}, - {SYM_MON, S_CENTAUR + SYM_OFF_M, "S_centaur"}, - {SYM_MON, S_DRAGON + SYM_OFF_M, "S_dragon"}, - {SYM_MON, S_ELEMENTAL + SYM_OFF_M, "S_elemental"}, - {SYM_MON, S_FUNGUS + SYM_OFF_M, "S_fungus"}, - {SYM_MON, S_GNOME + SYM_OFF_M, "S_gnome"}, - {SYM_MON, S_GIANT + SYM_OFF_M, "S_giant"}, - {SYM_MON, S_JABBERWOCK + SYM_OFF_M, "S_jabberwock"}, - {SYM_MON, S_KOP + SYM_OFF_M, "S_kop"}, - {SYM_MON, S_LICH + SYM_OFF_M, "S_lich"}, - {SYM_MON, S_MUMMY + SYM_OFF_M, "S_mummy"}, - {SYM_MON, S_NAGA + SYM_OFF_M, "S_naga"}, - {SYM_MON, S_OGRE + SYM_OFF_M, "S_ogre"}, - {SYM_MON, S_PUDDING + SYM_OFF_M, "S_pudding"}, - {SYM_MON, S_QUANTMECH + SYM_OFF_M, "S_quantmech"}, - {SYM_MON, S_RUSTMONST + SYM_OFF_M, "S_rustmonst"}, - {SYM_MON, S_SNAKE + SYM_OFF_M, "S_snake"}, - {SYM_MON, S_TROLL + SYM_OFF_M, "S_troll"}, - {SYM_MON, S_UMBER + SYM_OFF_M, "S_umber"}, - {SYM_MON, S_VAMPIRE + SYM_OFF_M, "S_vampire"}, - {SYM_MON, S_WRAITH + SYM_OFF_M, "S_wraith"}, - {SYM_MON, S_XORN + SYM_OFF_M, "S_xorn"}, - {SYM_MON, S_YETI + SYM_OFF_M, "S_yeti"}, - {SYM_MON, S_ZOMBIE + SYM_OFF_M, "S_zombie"}, - {SYM_MON, S_HUMAN + SYM_OFF_M, "S_human"}, - {SYM_MON, S_GHOST + SYM_OFF_M, "S_ghost"}, - {SYM_MON, S_GOLEM + SYM_OFF_M, "S_golem"}, - {SYM_MON, S_DEMON + SYM_OFF_M, "S_demon"}, - {SYM_MON, S_EEL + SYM_OFF_M, "S_eel"}, - {SYM_MON, S_LIZARD + SYM_OFF_M, "S_lizard"}, - {SYM_MON, S_WORM_TAIL + SYM_OFF_M, "S_worm_tail"}, - {SYM_MON, S_MIMIC_DEF + SYM_OFF_M, "S_mimic_def"}, - {SYM_OTH, SYM_BOULDER + SYM_OFF_X, "S_boulder"}, - {SYM_OTH, SYM_INVISIBLE + SYM_OFF_X, "S_invisible"}, - {0,0,(const char *)0} /* fence post */ + { SYM_CONTROL, 0, "start" }, + { SYM_CONTROL, 0, "begin" }, + { SYM_CONTROL, 1, "finish" }, + { SYM_CONTROL, 2, "handling" }, + { SYM_CONTROL, 3, "description" }, + { SYM_CONTROL, 4, "color" }, + { SYM_CONTROL, 4, "colour" }, + { SYM_CONTROL, 5, "restrictions" }, + { SYM_PCHAR, S_stone, "S_stone" }, + { SYM_PCHAR, S_vwall, "S_vwall" }, + { SYM_PCHAR, S_hwall, "S_hwall" }, + { SYM_PCHAR, S_tlcorn, "S_tlcorn" }, + { SYM_PCHAR, S_trcorn, "S_trcorn" }, + { SYM_PCHAR, S_blcorn, "S_blcorn" }, + { SYM_PCHAR, S_brcorn, "S_brcorn" }, + { SYM_PCHAR, S_crwall, "S_crwall" }, + { SYM_PCHAR, S_tuwall, "S_tuwall" }, + { SYM_PCHAR, S_tdwall, "S_tdwall" }, + { SYM_PCHAR, S_tlwall, "S_tlwall" }, + { SYM_PCHAR, S_trwall, "S_trwall" }, + { SYM_PCHAR, S_ndoor, "S_ndoor" }, + { SYM_PCHAR, S_vodoor, "S_vodoor" }, + { SYM_PCHAR, S_hodoor, "S_hodoor" }, + { SYM_PCHAR, S_vcdoor, "S_vcdoor" }, + { SYM_PCHAR, S_hcdoor, "S_hcdoor" }, + { SYM_PCHAR, S_bars, "S_bars" }, + { SYM_PCHAR, S_tree, "S_tree" }, + { SYM_PCHAR, S_room, "S_room" }, + { SYM_PCHAR, S_corr, "S_corr" }, + { SYM_PCHAR, S_litcorr, "S_litcorr" }, + { SYM_PCHAR, S_upstair, "S_upstair" }, + { SYM_PCHAR, S_dnstair, "S_dnstair" }, + { SYM_PCHAR, S_upladder, "S_upladder" }, + { SYM_PCHAR, S_dnladder, "S_dnladder" }, + { SYM_PCHAR, S_altar, "S_altar" }, + { SYM_PCHAR, S_grave, "S_grave" }, + { SYM_PCHAR, S_throne, "S_throne" }, + { SYM_PCHAR, S_sink, "S_sink" }, + { SYM_PCHAR, S_fountain, "S_fountain" }, + { SYM_PCHAR, S_pool, "S_pool" }, + { SYM_PCHAR, S_ice, "S_ice" }, + { SYM_PCHAR, S_lava, "S_lava" }, + { SYM_PCHAR, S_vodbridge, "S_vodbridge" }, + { SYM_PCHAR, S_hodbridge, "S_hodbridge" }, + { SYM_PCHAR, S_vcdbridge, "S_vcdbridge" }, + { SYM_PCHAR, S_hcdbridge, "S_hcdbridge" }, + { SYM_PCHAR, S_air, "S_air" }, + { SYM_PCHAR, S_cloud, "S_cloud" }, + { SYM_PCHAR, S_poisoncloud, "S_poisoncloud" }, + { SYM_PCHAR, S_water, "S_water" }, + { SYM_PCHAR, S_arrow_trap, "S_arrow_trap" }, + { SYM_PCHAR, S_dart_trap, "S_dart_trap" }, + { SYM_PCHAR, S_falling_rock_trap, "S_falling_rock_trap" }, + { SYM_PCHAR, S_squeaky_board, "S_squeaky_board" }, + { SYM_PCHAR, S_bear_trap, "S_bear_trap" }, + { SYM_PCHAR, S_land_mine, "S_land_mine" }, + { SYM_PCHAR, S_rolling_boulder_trap, "S_rolling_boulder_trap" }, + { SYM_PCHAR, S_sleeping_gas_trap, "S_sleeping_gas_trap" }, + { SYM_PCHAR, S_rust_trap, "S_rust_trap" }, + { SYM_PCHAR, S_fire_trap, "S_fire_trap" }, + { SYM_PCHAR, S_pit, "S_pit" }, + { SYM_PCHAR, S_spiked_pit, "S_spiked_pit" }, + { SYM_PCHAR, S_hole, "S_hole" }, + { SYM_PCHAR, S_trap_door, "S_trap_door" }, + { SYM_PCHAR, S_teleportation_trap, "S_teleportation_trap" }, + { SYM_PCHAR, S_level_teleporter, "S_level_teleporter" }, + { SYM_PCHAR, S_magic_portal, "S_magic_portal" }, + { SYM_PCHAR, S_web, "S_web" }, + { SYM_PCHAR, S_statue_trap, "S_statue_trap" }, + { SYM_PCHAR, S_magic_trap, "S_magic_trap" }, + { SYM_PCHAR, S_anti_magic_trap, "S_anti_magic_trap" }, + { SYM_PCHAR, S_polymorph_trap, "S_polymorph_trap" }, + { SYM_PCHAR, S_vbeam, "S_vbeam" }, + { SYM_PCHAR, S_hbeam, "S_hbeam" }, + { SYM_PCHAR, S_lslant, "S_lslant" }, + { SYM_PCHAR, S_rslant, "S_rslant" }, + { SYM_PCHAR, S_digbeam, "S_digbeam" }, + { SYM_PCHAR, S_flashbeam, "S_flashbeam" }, + { SYM_PCHAR, S_boomleft, "S_boomleft" }, + { SYM_PCHAR, S_boomright, "S_boomright" }, + { SYM_PCHAR, S_goodpos, "S_goodpos" }, + { SYM_PCHAR, S_ss1, "S_ss1" }, + { SYM_PCHAR, S_ss2, "S_ss2" }, + { SYM_PCHAR, S_ss3, "S_ss3" }, + { SYM_PCHAR, S_ss4, "S_ss4" }, + { SYM_PCHAR, S_sw_tl, "S_sw_tl" }, + { SYM_PCHAR, S_sw_tc, "S_sw_tc" }, + { SYM_PCHAR, S_sw_tr, "S_sw_tr" }, + { SYM_PCHAR, S_sw_ml, "S_sw_ml" }, + { SYM_PCHAR, S_sw_mr, "S_sw_mr" }, + { SYM_PCHAR, S_sw_bl, "S_sw_bl" }, + { SYM_PCHAR, S_sw_bc, "S_sw_bc" }, + { SYM_PCHAR, S_sw_br, "S_sw_br" }, + { SYM_PCHAR, S_explode1, "S_explode1" }, + { SYM_PCHAR, S_explode2, "S_explode2" }, + { SYM_PCHAR, S_explode3, "S_explode3" }, + { SYM_PCHAR, S_explode4, "S_explode4" }, + { SYM_PCHAR, S_explode5, "S_explode5" }, + { SYM_PCHAR, S_explode6, "S_explode6" }, + { SYM_PCHAR, S_explode7, "S_explode7" }, + { SYM_PCHAR, S_explode8, "S_explode8" }, + { SYM_PCHAR, S_explode9, "S_explode9" }, + { SYM_OC, WEAPON_CLASS + SYM_OFF_O, "S_weapon" }, + { SYM_OC, ARMOR_CLASS + SYM_OFF_O, "S_armor" }, + { SYM_OC, ARMOR_CLASS + SYM_OFF_O, "S_armour" }, + { SYM_OC, RING_CLASS + SYM_OFF_O, "S_ring" }, + { SYM_OC, AMULET_CLASS + SYM_OFF_O, "S_amulet" }, + { SYM_OC, TOOL_CLASS + SYM_OFF_O, "S_tool" }, + { SYM_OC, FOOD_CLASS + SYM_OFF_O, "S_food" }, + { SYM_OC, POTION_CLASS + SYM_OFF_O, "S_potion" }, + { SYM_OC, SCROLL_CLASS + SYM_OFF_O, "S_scroll" }, + { SYM_OC, SPBOOK_CLASS + SYM_OFF_O, "S_book" }, + { SYM_OC, WAND_CLASS + SYM_OFF_O, "S_wand" }, + { SYM_OC, COIN_CLASS + SYM_OFF_O, "S_coin" }, + { SYM_OC, GEM_CLASS + SYM_OFF_O, "S_gem" }, + { SYM_OC, ROCK_CLASS + SYM_OFF_O, "S_rock" }, + { SYM_OC, BALL_CLASS + SYM_OFF_O, "S_ball" }, + { SYM_OC, CHAIN_CLASS + SYM_OFF_O, "S_chain" }, + { SYM_OC, VENOM_CLASS + SYM_OFF_O, "S_venom" }, + { SYM_MON, S_ANT + SYM_OFF_M, "S_ant" }, + { SYM_MON, S_BLOB + SYM_OFF_M, "S_blob" }, + { SYM_MON, S_COCKATRICE + SYM_OFF_M, "S_cockatrice" }, + { SYM_MON, S_DOG + SYM_OFF_M, "S_dog" }, + { SYM_MON, S_EYE + SYM_OFF_M, "S_eye" }, + { SYM_MON, S_FELINE + SYM_OFF_M, "S_feline" }, + { SYM_MON, S_GREMLIN + SYM_OFF_M, "S_gremlin" }, + { SYM_MON, S_HUMANOID + SYM_OFF_M, "S_humanoid" }, + { SYM_MON, S_IMP + SYM_OFF_M, "S_imp" }, + { SYM_MON, S_JELLY + SYM_OFF_M, "S_jelly" }, + { SYM_MON, S_KOBOLD + SYM_OFF_M, "S_kobold" }, + { SYM_MON, S_LEPRECHAUN + SYM_OFF_M, "S_leprechaun" }, + { SYM_MON, S_MIMIC + SYM_OFF_M, "S_mimic" }, + { SYM_MON, S_NYMPH + SYM_OFF_M, "S_nymph" }, + { SYM_MON, S_ORC + SYM_OFF_M, "S_orc" }, + { SYM_MON, S_PIERCER + SYM_OFF_M, "S_piercer" }, + { SYM_MON, S_QUADRUPED + SYM_OFF_M, "S_quadruped" }, + { SYM_MON, S_RODENT + SYM_OFF_M, "S_rodent" }, + { SYM_MON, S_SPIDER + SYM_OFF_M, "S_spider" }, + { SYM_MON, S_TRAPPER + SYM_OFF_M, "S_trapper" }, + { SYM_MON, S_UNICORN + SYM_OFF_M, "S_unicorn" }, + { SYM_MON, S_VORTEX + SYM_OFF_M, "S_vortex" }, + { SYM_MON, S_WORM + SYM_OFF_M, "S_worm" }, + { SYM_MON, S_XAN + SYM_OFF_M, "S_xan" }, + { SYM_MON, S_LIGHT + SYM_OFF_M, "S_light" }, + { SYM_MON, S_ZRUTY + SYM_OFF_M, "S_zruty" }, + { SYM_MON, S_ANGEL + SYM_OFF_M, "S_angel" }, + { SYM_MON, S_BAT + SYM_OFF_M, "S_bat" }, + { SYM_MON, S_CENTAUR + SYM_OFF_M, "S_centaur" }, + { SYM_MON, S_DRAGON + SYM_OFF_M, "S_dragon" }, + { SYM_MON, S_ELEMENTAL + SYM_OFF_M, "S_elemental" }, + { SYM_MON, S_FUNGUS + SYM_OFF_M, "S_fungus" }, + { SYM_MON, S_GNOME + SYM_OFF_M, "S_gnome" }, + { SYM_MON, S_GIANT + SYM_OFF_M, "S_giant" }, + { SYM_MON, S_JABBERWOCK + SYM_OFF_M, "S_jabberwock" }, + { SYM_MON, S_KOP + SYM_OFF_M, "S_kop" }, + { SYM_MON, S_LICH + SYM_OFF_M, "S_lich" }, + { SYM_MON, S_MUMMY + SYM_OFF_M, "S_mummy" }, + { SYM_MON, S_NAGA + SYM_OFF_M, "S_naga" }, + { SYM_MON, S_OGRE + SYM_OFF_M, "S_ogre" }, + { SYM_MON, S_PUDDING + SYM_OFF_M, "S_pudding" }, + { SYM_MON, S_QUANTMECH + SYM_OFF_M, "S_quantmech" }, + { SYM_MON, S_RUSTMONST + SYM_OFF_M, "S_rustmonst" }, + { SYM_MON, S_SNAKE + SYM_OFF_M, "S_snake" }, + { SYM_MON, S_TROLL + SYM_OFF_M, "S_troll" }, + { SYM_MON, S_UMBER + SYM_OFF_M, "S_umber" }, + { SYM_MON, S_VAMPIRE + SYM_OFF_M, "S_vampire" }, + { SYM_MON, S_WRAITH + SYM_OFF_M, "S_wraith" }, + { SYM_MON, S_XORN + SYM_OFF_M, "S_xorn" }, + { SYM_MON, S_YETI + SYM_OFF_M, "S_yeti" }, + { SYM_MON, S_ZOMBIE + SYM_OFF_M, "S_zombie" }, + { SYM_MON, S_HUMAN + SYM_OFF_M, "S_human" }, + { SYM_MON, S_GHOST + SYM_OFF_M, "S_ghost" }, + { SYM_MON, S_GOLEM + SYM_OFF_M, "S_golem" }, + { SYM_MON, S_DEMON + SYM_OFF_M, "S_demon" }, + { SYM_MON, S_EEL + SYM_OFF_M, "S_eel" }, + { SYM_MON, S_LIZARD + SYM_OFF_M, "S_lizard" }, + { SYM_MON, S_WORM_TAIL + SYM_OFF_M, "S_worm_tail" }, + { SYM_MON, S_MIMIC_DEF + SYM_OFF_M, "S_mimic_def" }, + { SYM_OTH, SYM_BOULDER + SYM_OFF_X, "S_boulder" }, + { SYM_OTH, SYM_INVISIBLE + SYM_OFF_X, "S_invisible" }, + { 0, 0, (const char *) 0 } /* fence post */ }; /*drawing.c*/ - diff --git a/src/dungeon.c b/src/dungeon.c index 28125631a..deec57589 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dungeon.c $NHDT-Date: 1426465434 2015/03/16 00:23:54 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.39 $ */ +/* NetHack 3.6 dungeon.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.57 $ */ /* NetHack 3.6 dungeon.c $Date: 2012/04/14 08:31:05 $ $Revision: 1.34 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,188 +8,195 @@ #include "dlb.h" #include "lev.h" -#define DUNGEON_FILE "dungeon" +#define DUNGEON_FILE "dungeon" -#define X_START "x-strt" -#define X_LOCATE "x-loca" -#define X_GOAL "x-goal" +#define X_START "x-strt" +#define X_LOCATE "x-loca" +#define X_GOAL "x-goal" struct proto_dungeon { - struct tmpdungeon tmpdungeon[MAXDUNGEON]; - struct tmplevel tmplevel[LEV_LIMIT]; - s_level *final_lev[LEV_LIMIT]; /* corresponding level pointers */ - struct tmpbranch tmpbranch[BRANCH_LIMIT]; + struct tmpdungeon tmpdungeon[MAXDUNGEON]; + struct tmplevel tmplevel[LEV_LIMIT]; + s_level *final_lev[LEV_LIMIT]; /* corresponding level pointers */ + struct tmpbranch tmpbranch[BRANCH_LIMIT]; - int start; /* starting index of current dungeon sp levels */ - int n_levs; /* number of tmplevel entries */ - int n_brs; /* number of tmpbranch entries */ + int start; /* starting index of current dungeon sp levels */ + int n_levs; /* number of tmplevel entries */ + int n_brs; /* number of tmpbranch entries */ }; -int n_dgns; /* number of dungeons (also used */ - /* in mklev.c and do.c) */ -static branch *branches = (branch *) 0; /* dungeon branch list */ +int n_dgns; /* number of dungeons (also used */ + /* in mklev.c and do.c) */ +static branch *branches = (branch *) 0; /* dungeon branch list */ struct lchoice { - int idx; - schar lev[MAXLINFO]; - schar playerlev[MAXLINFO]; - xchar dgn[MAXLINFO]; - char menuletter; + int idx; + schar lev[MAXLINFO]; + schar playerlev[MAXLINFO]; + xchar dgn[MAXLINFO]; + char menuletter; }; static void FDECL(Fread, (genericptr_t, int, int, dlb *)); STATIC_DCL xchar FDECL(dname_to_dnum, (const char *)); STATIC_DCL int FDECL(find_branch, (const char *, struct proto_dungeon *)); STATIC_DCL xchar FDECL(parent_dnum, (const char *, struct proto_dungeon *)); -STATIC_DCL int FDECL(level_range, (XCHAR_P,int,int,int,struct proto_dungeon *,int *)); +STATIC_DCL int FDECL(level_range, + (XCHAR_P, int, int, int, struct proto_dungeon *, int *)); STATIC_DCL xchar FDECL(parent_dlevel, (const char *, struct proto_dungeon *)); STATIC_DCL int FDECL(correct_branch_type, (struct tmpbranch *)); STATIC_DCL branch *FDECL(add_branch, (int, int, struct proto_dungeon *)); STATIC_DCL void FDECL(add_level, (s_level *)); -STATIC_DCL void FDECL(init_level, (int,int,struct proto_dungeon *)); -STATIC_DCL int FDECL(possible_places, (int, boolean *, struct proto_dungeon *)); +STATIC_DCL void FDECL(init_level, (int, int, struct proto_dungeon *)); +STATIC_DCL int FDECL(possible_places, + (int, boolean *, struct proto_dungeon *)); STATIC_DCL xchar FDECL(pick_level, (boolean *, int)); STATIC_DCL boolean FDECL(place_level, (int, struct proto_dungeon *)); STATIC_DCL boolean FDECL(unplaced_floater, (struct dungeon *)); -STATIC_DCL boolean FDECL(unreachable_level, (d_level *,BOOLEAN_P)); -STATIC_DCL void FDECL(tport_menu, (winid,char *,struct lchoice *, - d_level *,BOOLEAN_P)); +STATIC_DCL boolean FDECL(unreachable_level, (d_level *, BOOLEAN_P)); +STATIC_DCL void FDECL(tport_menu, (winid, char *, struct lchoice *, d_level *, + BOOLEAN_P)); STATIC_DCL const char *FDECL(br_string, (int)); -STATIC_DCL void FDECL(print_branch, (winid, int, int, int, BOOLEAN_P, struct lchoice *)); +STATIC_DCL void FDECL(print_branch, + (winid, int, int, int, BOOLEAN_P, struct lchoice *)); -mapseen *mapseenchn = (struct mapseen *)0; +mapseen *mapseenchn = (struct mapseen *) 0; STATIC_DCL mapseen *FDECL(load_mapseen, (int)); STATIC_DCL void FDECL(save_mapseen, (int, mapseen *)); STATIC_DCL mapseen *FDECL(find_mapseen, (d_level *)); -STATIC_DCL void FDECL(print_mapseen, (winid,mapseen *,int,int,BOOLEAN_P)); +STATIC_DCL void FDECL(print_mapseen, (winid, mapseen *, int, int, BOOLEAN_P)); STATIC_DCL boolean FDECL(interest_mapseen, (mapseen *)); -STATIC_DCL void FDECL(traverse_mapseenchn, (BOOLEAN_P,winid,int,int,int *)); -STATIC_DCL const char *FDECL(seen_string, (XCHAR_P,const char *)); +STATIC_DCL void FDECL(traverse_mapseenchn, + (BOOLEAN_P, winid, int, int, int *)); +STATIC_DCL const char *FDECL(seen_string, (XCHAR_P, const char *)); STATIC_DCL const char *FDECL(br_string2, (branch *)); -STATIC_DCL const char *FDECL(endgamelevelname, (char *,int)); +STATIC_DCL const char *FDECL(endgamelevelname, (char *, int)); STATIC_DCL const char *FDECL(shop_string, (int)); -STATIC_DCL char *FDECL(tunesuffix, (mapseen *,char *)); +STATIC_DCL char *FDECL(tunesuffix, (mapseen *, char *)); #ifdef DEBUG -#define DD dungeons[i] +#define DD dungeons[i] STATIC_DCL void NDECL(dumpit); STATIC_OVL void dumpit() { - int i; - s_level *x; - branch *br; + int i; + s_level *x; + branch *br; - if (!explicitdebug(__FILE__)) return; + if (!explicitdebug(__FILE__)) + return; - for(i = 0; i < n_dgns; i++) { - fprintf(stderr, "\n#%d \"%s\" (%s):\n", i, - DD.dname, DD.proto); - fprintf(stderr, " num_dunlevs %d, dunlev_ureached %d\n", - DD.num_dunlevs, DD.dunlev_ureached); - fprintf(stderr, " depth_start %d, ledger_start %d\n", - DD.depth_start, DD.ledger_start); - fprintf(stderr, " flags:%s%s%s\n", - DD.flags.rogue_like ? " rogue_like" : "", - DD.flags.maze_like ? " maze_like" : "", - DD.flags.hellish ? " hellish" : ""); - getchar(); - } - fprintf(stderr,"\nSpecial levels:\n"); - for(x = sp_levchn; x; x = x->next) { - fprintf(stderr, "%s (%d): ", x->proto, x->rndlevs); - fprintf(stderr, "on %d, %d; ", x->dlevel.dnum, x->dlevel.dlevel); - fprintf(stderr, "flags:%s%s%s%s\n", - x->flags.rogue_like ? " rogue_like" : "", - x->flags.maze_like ? " maze_like" : "", - x->flags.hellish ? " hellish" : "", - x->flags.town ? " town" : ""); - getchar(); - } - fprintf(stderr,"\nBranches:\n"); - for (br = branches; br; br = br->next) { - fprintf(stderr, "%d: %s, end1 %d %d, end2 %d %d, %s\n", - br->id, - br->type == BR_STAIR ? "stair" : - br->type == BR_NO_END1 ? "no end1" : - br->type == BR_NO_END2 ? "no end2" : - br->type == BR_PORTAL ? "portal" : - "unknown", - br->end1.dnum, br->end1.dlevel, - br->end2.dnum, br->end2.dlevel, - br->end1_up ? "end1 up" : "end1 down"); - } - getchar(); - fprintf(stderr,"\nDone\n"); - getchar(); + for (i = 0; i < n_dgns; i++) { + fprintf(stderr, "\n#%d \"%s\" (%s):\n", i, DD.dname, DD.proto); + fprintf(stderr, " num_dunlevs %d, dunlev_ureached %d\n", + DD.num_dunlevs, DD.dunlev_ureached); + fprintf(stderr, " depth_start %d, ledger_start %d\n", + DD.depth_start, DD.ledger_start); + fprintf(stderr, " flags:%s%s%s\n", + DD.flags.rogue_like ? " rogue_like" : "", + DD.flags.maze_like ? " maze_like" : "", + DD.flags.hellish ? " hellish" : ""); + getchar(); + } + fprintf(stderr, "\nSpecial levels:\n"); + for (x = sp_levchn; x; x = x->next) { + fprintf(stderr, "%s (%d): ", x->proto, x->rndlevs); + fprintf(stderr, "on %d, %d; ", x->dlevel.dnum, x->dlevel.dlevel); + fprintf(stderr, "flags:%s%s%s%s\n", + x->flags.rogue_like ? " rogue_like" : "", + x->flags.maze_like ? " maze_like" : "", + x->flags.hellish ? " hellish" : "", + x->flags.town ? " town" : ""); + getchar(); + } + fprintf(stderr, "\nBranches:\n"); + for (br = branches; br; br = br->next) { + fprintf(stderr, "%d: %s, end1 %d %d, end2 %d %d, %s\n", br->id, + br->type == BR_STAIR + ? "stair" + : br->type == BR_NO_END1 + ? "no end1" + : br->type == BR_NO_END2 + ? "no end2" + : br->type == BR_PORTAL ? "portal" + : "unknown", + br->end1.dnum, br->end1.dlevel, br->end2.dnum, + br->end2.dlevel, br->end1_up ? "end1 up" : "end1 down"); + } + getchar(); + fprintf(stderr, "\nDone\n"); + getchar(); } #endif /* Save the dungeon structures. */ void save_dungeon(fd, perform_write, free_data) - int fd; - boolean perform_write, free_data; +int fd; +boolean perform_write, free_data; { branch *curr, *next; mapseen *curr_ms, *next_ms; - int count; + int count; if (perform_write) { - bwrite(fd, (genericptr_t) &n_dgns, sizeof n_dgns); - bwrite(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned)n_dgns); - bwrite(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology); - bwrite(fd, (genericptr_t) tune, sizeof tune); + bwrite(fd, (genericptr_t) &n_dgns, sizeof n_dgns); + bwrite(fd, (genericptr_t) dungeons, + sizeof(dungeon) * (unsigned) n_dgns); + bwrite(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology); + bwrite(fd, (genericptr_t) tune, sizeof tune); - for (count = 0, curr = branches; curr; curr = curr->next) - count++; - bwrite(fd, (genericptr_t) &count, sizeof(count)); + for (count = 0, curr = branches; curr; curr = curr->next) + count++; + bwrite(fd, (genericptr_t) &count, sizeof(count)); - for (curr = branches; curr; curr = curr->next) - bwrite(fd, (genericptr_t) curr, sizeof (branch)); + for (curr = branches; curr; curr = curr->next) + bwrite(fd, (genericptr_t) curr, sizeof(branch)); - count = maxledgerno(); - bwrite(fd, (genericptr_t) &count, sizeof count); - bwrite(fd, (genericptr_t) level_info, - (unsigned)count * sizeof (struct linfo)); - bwrite(fd, (genericptr_t) &inv_pos, sizeof inv_pos); + count = maxledgerno(); + bwrite(fd, (genericptr_t) &count, sizeof count); + bwrite(fd, (genericptr_t) level_info, + (unsigned) count * sizeof(struct linfo)); + bwrite(fd, (genericptr_t) &inv_pos, sizeof inv_pos); - for (count = 0, curr_ms = mapseenchn; curr_ms; curr_ms = curr_ms->next) - count++; - bwrite(fd, (genericptr_t) &count, sizeof(count)); + for (count = 0, curr_ms = mapseenchn; curr_ms; + curr_ms = curr_ms->next) + count++; + bwrite(fd, (genericptr_t) &count, sizeof(count)); - for (curr_ms = mapseenchn; curr_ms; curr_ms = curr_ms->next) - save_mapseen(fd, curr_ms); + for (curr_ms = mapseenchn; curr_ms; curr_ms = curr_ms->next) + save_mapseen(fd, curr_ms); } if (free_data) { - for (curr = branches; curr; curr = next) { - next = curr->next; - free((genericptr_t) curr); - } - branches = 0; - for (curr_ms = mapseenchn; curr_ms; curr_ms = next_ms) { - next_ms = curr_ms->next; - if (curr_ms->custom) - free((genericptr_t)curr_ms->custom); - free((genericptr_t) curr_ms); - } - mapseenchn = 0; + for (curr = branches; curr; curr = next) { + next = curr->next; + free((genericptr_t) curr); + } + branches = 0; + for (curr_ms = mapseenchn; curr_ms; curr_ms = next_ms) { + next_ms = curr_ms->next; + if (curr_ms->custom) + free((genericptr_t) curr_ms->custom); + free((genericptr_t) curr_ms); + } + mapseenchn = 0; } } /* Restore the dungeon structures. */ void restore_dungeon(fd) - int fd; +int fd; { branch *curr, *last; - int count, i; + int count, i; mapseen *curr_ms, *last_ms; mread(fd, (genericptr_t) &n_dgns, sizeof(n_dgns)); - mread(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned)n_dgns); + mread(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned) n_dgns); mread(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology); mread(fd, (genericptr_t) tune, sizeof tune); @@ -197,128 +204,133 @@ restore_dungeon(fd) mread(fd, (genericptr_t) &count, sizeof(count)); for (i = 0; i < count; i++) { - curr = (branch *) alloc(sizeof(branch)); - mread(fd, (genericptr_t) curr, sizeof(branch)); - curr->next = (branch *) 0; - if (last) - last->next = curr; - else - branches = curr; - last = curr; + curr = (branch *) alloc(sizeof(branch)); + mread(fd, (genericptr_t) curr, sizeof(branch)); + curr->next = (branch *) 0; + if (last) + last->next = curr; + else + branches = curr; + last = curr; } mread(fd, (genericptr_t) &count, sizeof(count)); if (count >= MAXLINFO) - panic("level information count larger (%d) than allocated size", count); - mread(fd, (genericptr_t) level_info, (unsigned)count*sizeof(struct linfo)); + panic("level information count larger (%d) than allocated size", + count); + mread(fd, (genericptr_t) level_info, + (unsigned) count * sizeof(struct linfo)); mread(fd, (genericptr_t) &inv_pos, sizeof inv_pos); mread(fd, (genericptr_t) &count, sizeof(count)); last_ms = (mapseen *) 0; for (i = 0; i < count; i++) { - curr_ms = load_mapseen(fd); - curr_ms->next = (mapseen *) 0; - if (last_ms) - last_ms->next = curr_ms; - else - mapseenchn = curr_ms; - last_ms = curr_ms; + curr_ms = load_mapseen(fd); + curr_ms->next = (mapseen *) 0; + if (last_ms) + last_ms->next = curr_ms; + else + mapseenchn = curr_ms; + last_ms = curr_ms; } } static void Fread(ptr, size, nitems, stream) - genericptr_t ptr; - int size, nitems; - dlb *stream; +genericptr_t ptr; +int size, nitems; +dlb *stream; { - int cnt; + int cnt; - if((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) { - panic( - "Premature EOF on dungeon description file!\r\nExpected %d bytes - got %d.", - (size * nitems), (size * cnt)); - terminate(EXIT_FAILURE); - } + if ((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) { + panic("Premature EOF on dungeon description file!\r\nExpected %d " + "bytes - got %d.", + (size * nitems), (size * cnt)); + terminate(EXIT_FAILURE); + } } STATIC_OVL xchar dname_to_dnum(s) -const char *s; +const char *s; { - xchar i; + xchar i; - for (i = 0; i < n_dgns; i++) - if (!strcmp(dungeons[i].dname, s)) return i; + for (i = 0; i < n_dgns; i++) + if (!strcmp(dungeons[i].dname, s)) + return i; - panic("Couldn't resolve dungeon number for name \"%s\".", s); - /*NOT REACHED*/ - return (xchar)0; + panic("Couldn't resolve dungeon number for name \"%s\".", s); + /*NOT REACHED*/ + return (xchar) 0; } s_level * find_level(s) - const char *s; +const char *s; { - s_level *curr; - for(curr = sp_levchn; curr; curr = curr->next) - if (!strcmpi(s, curr->proto)) break; - return curr; + s_level *curr; + for (curr = sp_levchn; curr; curr = curr->next) + if (!strcmpi(s, curr->proto)) + break; + return curr; } /* Find the branch that links the named dungeon. */ STATIC_OVL int find_branch(s, pd) - const char *s; /* dungeon name */ - struct proto_dungeon *pd; +const char *s; /* dungeon name */ +struct proto_dungeon *pd; { - int i; + int i; - if (pd) { - for (i = 0; i < pd->n_brs; i++) - if (!strcmp(pd->tmpbranch[i].name, s)) break; - if (i == pd->n_brs) panic("find_branch: can't find %s", s); - } else { - /* support for level tport by name */ - branch *br; - const char *dnam; + if (pd) { + for (i = 0; i < pd->n_brs; i++) + if (!strcmp(pd->tmpbranch[i].name, s)) + break; + if (i == pd->n_brs) + panic("find_branch: can't find %s", s); + } else { + /* support for level tport by name */ + branch *br; + const char *dnam; - for (br = branches; br; br = br->next) { - dnam = dungeons[br->end2.dnum].dname; - if (!strcmpi(dnam, s) || - (!strncmpi(dnam, "The ", 4) && !strcmpi(dnam + 4, s))) - break; - } - i = br ? ((ledger_no(&br->end1) << 8) | ledger_no(&br->end2)) : -1; - } - return i; + for (br = branches; br; br = br->next) { + dnam = dungeons[br->end2.dnum].dname; + if (!strcmpi(dnam, s) + || (!strncmpi(dnam, "The ", 4) && !strcmpi(dnam + 4, s))) + break; + } + i = br ? ((ledger_no(&br->end1) << 8) | ledger_no(&br->end2)) : -1; + } + return i; } - /* * Find the "parent" by searching the prototype branch list for the branch * listing, then figuring out to which dungeon it belongs. */ STATIC_OVL xchar parent_dnum(s, pd) -const char *s; /* dungeon name */ +const char *s; /* dungeon name */ struct proto_dungeon *pd; { - int i; - xchar pdnum; + int i; + xchar pdnum; - i = find_branch(s, pd); - /* - * Got branch, now find parent dungeon. Stop if we have reached - * "this" dungeon (if we haven't found it by now it is an error). - */ - for (pdnum = 0; strcmp(pd->tmpdungeon[pdnum].name, s); pdnum++) - if ((i -= pd->tmpdungeon[pdnum].branches) < 0) - return(pdnum); + i = find_branch(s, pd); + /* + * Got branch, now find parent dungeon. Stop if we have reached + * "this" dungeon (if we haven't found it by now it is an error). + */ + for (pdnum = 0; strcmp(pd->tmpdungeon[pdnum].name, s); pdnum++) + if ((i -= pd->tmpdungeon[pdnum].branches) < 0) + return (pdnum); - panic("parent_dnum: couldn't resolve branch."); - /*NOT REACHED*/ - return (xchar)0; + panic("parent_dnum: couldn't resolve branch."); + /*NOT REACHED*/ + return (xchar) 0; } /* @@ -333,74 +345,79 @@ struct proto_dungeon *pd; */ STATIC_OVL int level_range(dgn, base, randc, chain, pd, adjusted_base) - xchar dgn; - int base, randc, chain; - struct proto_dungeon *pd; - int *adjusted_base; +xchar dgn; +int base, randc, chain; +struct proto_dungeon *pd; +int *adjusted_base; { - int lmax = dungeons[dgn].num_dunlevs; + int lmax = dungeons[dgn].num_dunlevs; - if (chain >= 0) { /* relative to a special level */ - s_level *levtmp = pd->final_lev[chain]; - if (!levtmp) panic("level_range: empty chain level!"); + if (chain >= 0) { /* relative to a special level */ + s_level *levtmp = pd->final_lev[chain]; + if (!levtmp) + panic("level_range: empty chain level!"); - base += levtmp->dlevel.dlevel; - } else { /* absolute in the dungeon */ - /* from end of dungeon */ - if (base < 0) base = (lmax + base + 1); - } + base += levtmp->dlevel.dlevel; + } else { /* absolute in the dungeon */ + /* from end of dungeon */ + if (base < 0) + base = (lmax + base + 1); + } - if (base < 1 || base > lmax) - panic("level_range: base value out of range"); + if (base < 1 || base > lmax) + panic("level_range: base value out of range"); - *adjusted_base = base; + *adjusted_base = base; - if (randc == -1) { /* from base to end of dungeon */ - return (lmax - base + 1); - } else if (randc) { - /* make sure we don't run off the end of the dungeon */ - return (((base + randc - 1) > lmax) ? lmax-base+1 : randc); - } /* else only one choice */ - return 1; + if (randc == -1) { /* from base to end of dungeon */ + return (lmax - base + 1); + } else if (randc) { + /* make sure we don't run off the end of the dungeon */ + return (((base + randc - 1) > lmax) ? lmax - base + 1 : randc); + } /* else only one choice */ + return 1; } STATIC_OVL xchar parent_dlevel(s, pd) - const char *s; - struct proto_dungeon *pd; +const char *s; +struct proto_dungeon *pd; { - int i, j, num, base, dnum = parent_dnum(s, pd); - branch *curr; + int i, j, num, base, dnum = parent_dnum(s, pd); + branch *curr; + i = find_branch(s, pd); + num = level_range(dnum, pd->tmpbranch[i].lev.base, + pd->tmpbranch[i].lev.rand, pd->tmpbranch[i].chain, pd, + &base); - i = find_branch(s, pd); - num = level_range(dnum, pd->tmpbranch[i].lev.base, - pd->tmpbranch[i].lev.rand, - pd->tmpbranch[i].chain, - pd, &base); - - /* KMH -- Try our best to find a level without an existing branch */ - i = j = rn2(num); - do { - if (++i >= num) i = 0; - for (curr = branches; curr; curr = curr->next) - if ((curr->end1.dnum == dnum && curr->end1.dlevel == base+i) || - (curr->end2.dnum == dnum && curr->end2.dlevel == base+i)) - break; - } while (curr && i != j); - return (base + i); + /* KMH -- Try our best to find a level without an existing branch */ + i = j = rn2(num); + do { + if (++i >= num) + i = 0; + for (curr = branches; curr; curr = curr->next) + if ((curr->end1.dnum == dnum && curr->end1.dlevel == base + i) + || (curr->end2.dnum == dnum && curr->end2.dlevel == base + i)) + break; + } while (curr && i != j); + return (base + i); } /* Convert from the temporary branch type to the dungeon branch type. */ STATIC_OVL int correct_branch_type(tbr) - struct tmpbranch *tbr; +struct tmpbranch *tbr; { switch (tbr->type) { - case TBR_STAIR: return BR_STAIR; - case TBR_NO_UP: return tbr->up ? BR_NO_END1 : BR_NO_END2; - case TBR_NO_DOWN: return tbr->up ? BR_NO_END2 : BR_NO_END1; - case TBR_PORTAL: return BR_PORTAL; + case TBR_STAIR: + return BR_STAIR; + case TBR_NO_UP: + return tbr->up ? BR_NO_END1 : BR_NO_END2; + case TBR_NO_DOWN: + return tbr->up ? BR_NO_END2 : BR_NO_END1; + case TBR_PORTAL: + return BR_PORTAL; } impossible("correct_branch_type: unknown branch type"); return BR_STAIR; @@ -414,29 +431,31 @@ correct_branch_type(tbr) */ void insert_branch(new_branch, extract_first) - branch *new_branch; - boolean extract_first; +branch *new_branch; +boolean extract_first; { branch *curr, *prev; long new_val, curr_val, prev_val; if (extract_first) { - for (prev = 0, curr = branches; curr; prev = curr, curr = curr->next) - if (curr == new_branch) break; + for (prev = 0, curr = branches; curr; prev = curr, curr = curr->next) + if (curr == new_branch) + break; - if (!curr) panic("insert_branch: not found"); - if (prev) - prev->next = curr->next; - else - branches = curr->next; + if (!curr) + panic("insert_branch: not found"); + if (prev) + prev->next = curr->next; + else + branches = curr->next; } new_branch->next = (branch *) 0; /* Convert the branch into a unique number so we can sort them. */ -#define branch_val(bp) \ - ((((long)(bp)->end1.dnum * (MAXLEVEL+1) + \ - (long)(bp)->end1.dlevel) * (MAXDUNGEON+1) * (MAXLEVEL+1)) + \ - ((long)(bp)->end2.dnum * (MAXLEVEL+1) + (long)(bp)->end2.dlevel)) +#define branch_val(bp) \ + ((((long) (bp)->end1.dnum * (MAXLEVEL + 1) + (long) (bp)->end1.dlevel) \ + * (MAXDUNGEON + 1) * (MAXLEVEL + 1)) \ + + ((long) (bp)->end2.dnum * (MAXLEVEL + 1) + (long) (bp)->end2.dlevel)) /* * Insert the new branch into the correct place in the branch list. @@ -445,31 +464,32 @@ insert_branch(new_branch, extract_first) prev_val = -1; new_val = branch_val(new_branch); for (curr = branches; curr; - prev_val = curr_val, prev = curr, curr = curr->next) { - curr_val = branch_val(curr); - if (prev_val < new_val && new_val <= curr_val) break; + prev_val = curr_val, prev = curr, curr = curr->next) { + curr_val = branch_val(curr); + if (prev_val < new_val && new_val <= curr_val) + break; } if (prev) { - new_branch->next = curr; - prev->next = new_branch; + new_branch->next = curr; + prev->next = new_branch; } else { - new_branch->next = branches; - branches = new_branch; + new_branch->next = branches; + branches = new_branch; } } /* Add a dungeon branch to the branch list. */ STATIC_OVL branch * add_branch(dgn, child_entry_level, pd) - int dgn; - int child_entry_level; - struct proto_dungeon *pd; +int dgn; +int child_entry_level; +struct proto_dungeon *pd; { static int branch_id = 0; int branch_num; branch *new_branch; - branch_num = find_branch(dungeons[dgn].dname,pd); + branch_num = find_branch(dungeons[dgn].dname, pd); new_branch = (branch *) alloc(sizeof(branch)); new_branch->next = (branch *) 0; new_branch->id = branch_id++; @@ -492,84 +512,85 @@ add_branch(dgn, child_entry_level, pd) */ STATIC_OVL void add_level(new_lev) - s_level *new_lev; +s_level *new_lev; { - s_level *prev, *curr; + s_level *prev, *curr; - prev = (s_level *) 0; - for (curr = sp_levchn; curr; curr = curr->next) { - if (curr->dlevel.dnum == new_lev->dlevel.dnum && - curr->dlevel.dlevel > new_lev->dlevel.dlevel) - break; - prev = curr; - } - if (!prev) { - new_lev->next = sp_levchn; - sp_levchn = new_lev; - } else { - new_lev->next = curr; - prev->next = new_lev; - } + prev = (s_level *) 0; + for (curr = sp_levchn; curr; curr = curr->next) { + if (curr->dlevel.dnum == new_lev->dlevel.dnum + && curr->dlevel.dlevel > new_lev->dlevel.dlevel) + break; + prev = curr; + } + if (!prev) { + new_lev->next = sp_levchn; + sp_levchn = new_lev; + } else { + new_lev->next = curr; + prev->next = new_lev; + } } STATIC_OVL void init_level(dgn, proto_index, pd) - int dgn, proto_index; - struct proto_dungeon *pd; +int dgn, proto_index; +struct proto_dungeon *pd; { - s_level *new_level; - struct tmplevel *tlevel = &pd->tmplevel[proto_index]; + s_level *new_level; + struct tmplevel *tlevel = &pd->tmplevel[proto_index]; - pd->final_lev[proto_index] = (s_level *) 0; /* no "real" level */ - if (!wizard && tlevel->chance <= rn2(100)) return; + pd->final_lev[proto_index] = (s_level *) 0; /* no "real" level */ + if (!wizard && tlevel->chance <= rn2(100)) + return; - pd->final_lev[proto_index] = new_level = - (s_level *) alloc(sizeof(s_level)); - /* load new level with data */ - Strcpy(new_level->proto, tlevel->name); - new_level->boneid = tlevel->boneschar; - new_level->dlevel.dnum = dgn; - new_level->dlevel.dlevel = 0; /* for now */ + pd->final_lev[proto_index] = new_level = + (s_level *) alloc(sizeof(s_level)); + /* load new level with data */ + Strcpy(new_level->proto, tlevel->name); + new_level->boneid = tlevel->boneschar; + new_level->dlevel.dnum = dgn; + new_level->dlevel.dlevel = 0; /* for now */ - new_level->flags.town = !!(tlevel->flags & TOWN); - new_level->flags.hellish = !!(tlevel->flags & HELLISH); - new_level->flags.maze_like = !!(tlevel->flags & MAZELIKE); - new_level->flags.rogue_like = !!(tlevel->flags & ROGUELIKE); - new_level->flags.align = ((tlevel->flags & D_ALIGN_MASK) >> 4); - if (!new_level->flags.align) - new_level->flags.align = - ((pd->tmpdungeon[dgn].flags & D_ALIGN_MASK) >> 4); + new_level->flags.town = !!(tlevel->flags & TOWN); + new_level->flags.hellish = !!(tlevel->flags & HELLISH); + new_level->flags.maze_like = !!(tlevel->flags & MAZELIKE); + new_level->flags.rogue_like = !!(tlevel->flags & ROGUELIKE); + new_level->flags.align = ((tlevel->flags & D_ALIGN_MASK) >> 4); + if (!new_level->flags.align) + new_level->flags.align = + ((pd->tmpdungeon[dgn].flags & D_ALIGN_MASK) >> 4); - new_level->rndlevs = tlevel->rndlevs; - new_level->next = (s_level *) 0; + new_level->rndlevs = tlevel->rndlevs; + new_level->next = (s_level *) 0; } STATIC_OVL int possible_places(idx, map, pd) - int idx; /* prototype index */ - boolean *map; /* array MAXLEVEL+1 in length */ - struct proto_dungeon *pd; +int idx; /* prototype index */ +boolean *map; /* array MAXLEVEL+1 in length */ +struct proto_dungeon *pd; { int i, start, count; s_level *lev = pd->final_lev[idx]; /* init level possibilities */ - for (i = 0; i <= MAXLEVEL; i++) map[i] = FALSE; + for (i = 0; i <= MAXLEVEL; i++) + map[i] = FALSE; /* get base and range and set those entried to true */ count = level_range(lev->dlevel.dnum, pd->tmplevel[idx].lev.base, - pd->tmplevel[idx].lev.rand, - pd->tmplevel[idx].chain, - pd, &start); - for (i = start; i < start+count; i++) - map[i] = TRUE; + pd->tmplevel[idx].lev.rand, pd->tmplevel[idx].chain, + pd, &start); + for (i = start; i < start + count; i++) + map[i] = TRUE; /* mark off already placed levels */ for (i = pd->start; i < idx; i++) { - if (pd->final_lev[i] && map[pd->final_lev[i]->dlevel.dlevel]) { - map[pd->final_lev[i]->dlevel.dlevel] = FALSE; - --count; - } + if (pd->final_lev[i] && map[pd->final_lev[i]->dlevel.dlevel]) { + map[pd->final_lev[i]->dlevel.dlevel] = FALSE; + --count; + } } return count; @@ -578,24 +599,26 @@ possible_places(idx, map, pd) /* Pick the nth TRUE entry in the given boolean array. */ STATIC_OVL xchar pick_level(map, nth) - boolean *map; /* an array MAXLEVEL+1 in size */ - int nth; +boolean *map; /* an array MAXLEVEL+1 in size */ +int nth; { int i; for (i = 1; i <= MAXLEVEL; i++) - if (map[i] && !nth--) return (xchar) i; + if (map[i] && !nth--) + return (xchar) i; panic("pick_level: ran out of valid levels"); return 0; } #ifdef DDEBUG -static void FDECL(indent,(int)); +static void FDECL(indent, (int)); static void indent(d) int d; { - while (d-- > 0) fputs(" ", stderr); + while (d-- > 0) + fputs(" ", stderr); } #endif @@ -608,391 +631,401 @@ int d; */ STATIC_OVL boolean place_level(proto_index, pd) - int proto_index; - struct proto_dungeon *pd; +int proto_index; +struct proto_dungeon *pd; { - boolean map[MAXLEVEL+1]; /* valid levels are 1..MAXLEVEL inclusive */ + boolean map[MAXLEVEL + 1]; /* valid levels are 1..MAXLEVEL inclusive */ s_level *lev; int npossible; #ifdef DDEBUG int i; #endif - if (proto_index == pd->n_levs) return TRUE; /* at end of proto levels */ + if (proto_index == pd->n_levs) + return TRUE; /* at end of proto levels */ lev = pd->final_lev[proto_index]; /* No level created for this prototype, goto next. */ - if (!lev) return place_level(proto_index+1, pd); + if (!lev) + return place_level(proto_index + 1, pd); npossible = possible_places(proto_index, map, pd); for (; npossible; --npossible) { - lev->dlevel.dlevel = pick_level(map, rn2(npossible)); + lev->dlevel.dlevel = pick_level(map, rn2(npossible)); #ifdef DDEBUG - indent(proto_index-pd->start); - fprintf(stderr,"%s: trying %d [ ", lev->proto, lev->dlevel.dlevel); - for (i = 1; i <= MAXLEVEL; i++) - if (map[i]) fprintf(stderr,"%d ", i); - fprintf(stderr,"]\n"); + indent(proto_index - pd->start); + fprintf(stderr, "%s: trying %d [ ", lev->proto, lev->dlevel.dlevel); + for (i = 1; i <= MAXLEVEL; i++) + if (map[i]) + fprintf(stderr, "%d ", i); + fprintf(stderr, "]\n"); #endif - if (place_level(proto_index+1, pd)) return TRUE; - map[lev->dlevel.dlevel] = FALSE; /* this choice didn't work */ + if (place_level(proto_index + 1, pd)) + return TRUE; + map[lev->dlevel.dlevel] = FALSE; /* this choice didn't work */ } #ifdef DDEBUG - indent(proto_index-pd->start); - fprintf(stderr,"%s: failed\n", lev->proto); + indent(proto_index - pd->start); + fprintf(stderr, "%s: failed\n", lev->proto); #endif return FALSE; } - struct level_map { - const char *lev_name; - d_level *lev_spec; -} level_map[] = { - { "air", &air_level }, - { "asmodeus", &asmodeus_level }, - { "astral", &astral_level }, - { "baalz", &baalzebub_level }, - { "bigrm", &bigroom_level }, - { "castle", &stronghold_level }, - { "earth", &earth_level }, - { "fakewiz1", &portal_level }, - { "fire", &fire_level }, - { "juiblex", &juiblex_level }, - { "knox", &knox_level }, - { "medusa", &medusa_level }, - { "oracle", &oracle_level }, - { "orcus", &orcus_level }, - { "rogue", &rogue_level }, - { "sanctum", &sanctum_level }, - { "valley", &valley_level }, - { "water", &water_level }, - { "wizard1", &wiz1_level }, - { "wizard2", &wiz2_level }, - { "wizard3", &wiz3_level }, - { "minend", &mineend_level }, - { "soko1", &sokoend_level }, - { X_START, &qstart_level }, - { X_LOCATE, &qlocate_level }, - { X_GOAL, &nemesis_level }, - { "", (d_level *)0 } -}; + const char *lev_name; + d_level *lev_spec; +} level_map[] = { { "air", &air_level }, + { "asmodeus", &asmodeus_level }, + { "astral", &astral_level }, + { "baalz", &baalzebub_level }, + { "bigrm", &bigroom_level }, + { "castle", &stronghold_level }, + { "earth", &earth_level }, + { "fakewiz1", &portal_level }, + { "fire", &fire_level }, + { "juiblex", &juiblex_level }, + { "knox", &knox_level }, + { "medusa", &medusa_level }, + { "oracle", &oracle_level }, + { "orcus", &orcus_level }, + { "rogue", &rogue_level }, + { "sanctum", &sanctum_level }, + { "valley", &valley_level }, + { "water", &water_level }, + { "wizard1", &wiz1_level }, + { "wizard2", &wiz2_level }, + { "wizard3", &wiz3_level }, + { "minend", &mineend_level }, + { "soko1", &sokoend_level }, + { X_START, &qstart_level }, + { X_LOCATE, &qlocate_level }, + { X_GOAL, &nemesis_level }, + { "", (d_level *) 0 } }; -void -init_dungeons() /* initialize the "dungeon" structs */ +void init_dungeons() /* initialize the "dungeon" structs */ { - dlb *dgn_file; - register int i, cl = 0, cb = 0; - register s_level *x; - struct proto_dungeon pd; - struct level_map *lev_map; - struct version_info vers_info; + dlb *dgn_file; + register int i, cl = 0, cb = 0; + register s_level *x; + struct proto_dungeon pd; + struct level_map *lev_map; + struct version_info vers_info; - pd.n_levs = pd.n_brs = 0; + pd.n_levs = pd.n_brs = 0; - dgn_file = dlb_fopen(DUNGEON_FILE, RDBMODE); - if (!dgn_file) { - char tbuf[BUFSZ]; - Sprintf(tbuf, "Cannot open dungeon description - \"%s", - DUNGEON_FILE); + dgn_file = dlb_fopen(DUNGEON_FILE, RDBMODE); + if (!dgn_file) { + char tbuf[BUFSZ]; + Sprintf(tbuf, "Cannot open dungeon description - \"%s", DUNGEON_FILE); #ifdef DLBRSRC /* using a resource from the executable */ - Strcat(tbuf, "\" resource!"); + Strcat(tbuf, "\" resource!"); #else /* using a file or DLB file */ -# if defined(DLB) - Strcat(tbuf, "\" from "); -# ifdef PREFIXES_IN_USE - Strcat(tbuf, "\n\""); - if (fqn_prefix[DATAPREFIX]) Strcat(tbuf, fqn_prefix[DATAPREFIX]); -# else - Strcat(tbuf, "\""); -# endif - Strcat(tbuf, DLBFILE); -# endif - Strcat(tbuf, "\" file!"); +#if defined(DLB) + Strcat(tbuf, "\" from "); +#ifdef PREFIXES_IN_USE + Strcat(tbuf, "\n\""); + if (fqn_prefix[DATAPREFIX]) + Strcat(tbuf, fqn_prefix[DATAPREFIX]); +#else + Strcat(tbuf, "\""); +#endif + Strcat(tbuf, DLBFILE); +#endif + Strcat(tbuf, "\" file!"); #endif #ifdef WIN32 - interject_assistance(1, INTERJECT_PANIC, (genericptr_t)tbuf, - (genericptr_t)fqn_prefix[DATAPREFIX]); + interject_assistance(1, INTERJECT_PANIC, (genericptr_t) tbuf, + (genericptr_t) fqn_prefix[DATAPREFIX]); #endif - panic1(tbuf); - } + panic1(tbuf); + } - /* validate the data's version against the program's version */ - Fread((genericptr_t) &vers_info, sizeof vers_info, 1, dgn_file); - /* we'd better clear the screen now, since when error messages come from - * check_version() they will be printed using pline(), which doesn't - * mix with the raw messages that might be already on the screen - */ - if (iflags.window_inited) clear_nhwindow(WIN_MAP); - if (!check_version(&vers_info, DUNGEON_FILE, TRUE)) - panic("Dungeon description not valid."); + /* validate the data's version against the program's version */ + Fread((genericptr_t) &vers_info, sizeof vers_info, 1, dgn_file); + /* we'd better clear the screen now, since when error messages come from + * check_version() they will be printed using pline(), which doesn't + * mix with the raw messages that might be already on the screen + */ + if (iflags.window_inited) + clear_nhwindow(WIN_MAP); + if (!check_version(&vers_info, DUNGEON_FILE, TRUE)) + panic("Dungeon description not valid."); - /* - * Read in each dungeon and transfer the results to the internal - * dungeon arrays. - */ - sp_levchn = (s_level *) 0; - Fread((genericptr_t)&n_dgns, sizeof(int), 1, dgn_file); - if (n_dgns >= MAXDUNGEON) - panic("init_dungeons: too many dungeons"); + /* + * Read in each dungeon and transfer the results to the internal + * dungeon arrays. + */ + sp_levchn = (s_level *) 0; + Fread((genericptr_t) &n_dgns, sizeof(int), 1, dgn_file); + if (n_dgns >= MAXDUNGEON) + panic("init_dungeons: too many dungeons"); - for (i = 0; i < n_dgns; i++) { - Fread((genericptr_t)&pd.tmpdungeon[i], - sizeof(struct tmpdungeon), 1, dgn_file); - if(!wizard && pd.tmpdungeon[i].chance - && (pd.tmpdungeon[i].chance <= rn2(100))) { - int j; + for (i = 0; i < n_dgns; i++) { + Fread((genericptr_t) &pd.tmpdungeon[i], sizeof(struct tmpdungeon), 1, + dgn_file); + if (!wizard && pd.tmpdungeon[i].chance + && (pd.tmpdungeon[i].chance <= rn2(100))) { + int j; - /* skip over any levels or branches */ - for(j = 0; j < pd.tmpdungeon[i].levels; j++) - Fread((genericptr_t)&pd.tmplevel[cl], sizeof(struct tmplevel), - 1, dgn_file); + /* skip over any levels or branches */ + for (j = 0; j < pd.tmpdungeon[i].levels; j++) + Fread((genericptr_t) &pd.tmplevel[cl], + sizeof(struct tmplevel), 1, dgn_file); - for(j = 0; j < pd.tmpdungeon[i].branches; j++) - Fread((genericptr_t)&pd.tmpbranch[cb], - sizeof(struct tmpbranch), 1, dgn_file); - n_dgns--; i--; - continue; - } + for (j = 0; j < pd.tmpdungeon[i].branches; j++) + Fread((genericptr_t) &pd.tmpbranch[cb], + sizeof(struct tmpbranch), 1, dgn_file); + n_dgns--; + i--; + continue; + } - Strcpy(dungeons[i].dname, pd.tmpdungeon[i].name); - Strcpy(dungeons[i].proto, pd.tmpdungeon[i].protoname); - dungeons[i].boneid = pd.tmpdungeon[i].boneschar; + Strcpy(dungeons[i].dname, pd.tmpdungeon[i].name); + Strcpy(dungeons[i].proto, pd.tmpdungeon[i].protoname); + dungeons[i].boneid = pd.tmpdungeon[i].boneschar; - if(pd.tmpdungeon[i].lev.rand) - dungeons[i].num_dunlevs = (xchar)rn1(pd.tmpdungeon[i].lev.rand, - pd.tmpdungeon[i].lev.base); - else dungeons[i].num_dunlevs = (xchar)pd.tmpdungeon[i].lev.base; + if (pd.tmpdungeon[i].lev.rand) + dungeons[i].num_dunlevs = (xchar) rn1(pd.tmpdungeon[i].lev.rand, + pd.tmpdungeon[i].lev.base); + else + dungeons[i].num_dunlevs = (xchar) pd.tmpdungeon[i].lev.base; - if(!i) { - dungeons[i].ledger_start = 0; - dungeons[i].depth_start = 1; - dungeons[i].dunlev_ureached = 1; - } else { - dungeons[i].ledger_start = dungeons[i-1].ledger_start + - dungeons[i-1].num_dunlevs; - dungeons[i].dunlev_ureached = 0; - } + if (!i) { + dungeons[i].ledger_start = 0; + dungeons[i].depth_start = 1; + dungeons[i].dunlev_ureached = 1; + } else { + dungeons[i].ledger_start = + dungeons[i - 1].ledger_start + dungeons[i - 1].num_dunlevs; + dungeons[i].dunlev_ureached = 0; + } - dungeons[i].flags.hellish = !!(pd.tmpdungeon[i].flags & HELLISH); - dungeons[i].flags.maze_like = !!(pd.tmpdungeon[i].flags & MAZELIKE); - dungeons[i].flags.rogue_like = !!(pd.tmpdungeon[i].flags & ROGUELIKE); - dungeons[i].flags.align = ((pd.tmpdungeon[i].flags & D_ALIGN_MASK) >> 4); - /* - * Set the entry level for this dungeon. The pd.tmpdungeon entry - * value means: - * < 0 from bottom (-1 == bottom level) - * 0 default (top) - * > 0 actual level (1 = top) - * - * Note that the entry_lev field in the dungeon structure is - * redundant. It is used only here and in print_dungeon(). - */ - if (pd.tmpdungeon[i].entry_lev < 0) { - dungeons[i].entry_lev = dungeons[i].num_dunlevs + - pd.tmpdungeon[i].entry_lev + 1; - if (dungeons[i].entry_lev <= 0) dungeons[i].entry_lev = 1; - } else if (pd.tmpdungeon[i].entry_lev > 0) { - dungeons[i].entry_lev = pd.tmpdungeon[i].entry_lev; - if (dungeons[i].entry_lev > dungeons[i].num_dunlevs) - dungeons[i].entry_lev = dungeons[i].num_dunlevs; - } else { /* default */ - dungeons[i].entry_lev = 1; /* defaults to top level */ - } + dungeons[i].flags.hellish = !!(pd.tmpdungeon[i].flags & HELLISH); + dungeons[i].flags.maze_like = !!(pd.tmpdungeon[i].flags & MAZELIKE); + dungeons[i].flags.rogue_like = !!(pd.tmpdungeon[i].flags & ROGUELIKE); + dungeons[i].flags.align = + ((pd.tmpdungeon[i].flags & D_ALIGN_MASK) >> 4); + /* + * Set the entry level for this dungeon. The pd.tmpdungeon entry + * value means: + * < 0 from bottom (-1 == bottom level) + * 0 default (top) + * > 0 actual level (1 = top) + * + * Note that the entry_lev field in the dungeon structure is + * redundant. It is used only here and in print_dungeon(). + */ + if (pd.tmpdungeon[i].entry_lev < 0) { + dungeons[i].entry_lev = + dungeons[i].num_dunlevs + pd.tmpdungeon[i].entry_lev + 1; + if (dungeons[i].entry_lev <= 0) + dungeons[i].entry_lev = 1; + } else if (pd.tmpdungeon[i].entry_lev > 0) { + dungeons[i].entry_lev = pd.tmpdungeon[i].entry_lev; + if (dungeons[i].entry_lev > dungeons[i].num_dunlevs) + dungeons[i].entry_lev = dungeons[i].num_dunlevs; + } else { /* default */ + dungeons[i].entry_lev = 1; /* defaults to top level */ + } - if (i) { /* set depth */ - branch *br; - schar from_depth; - boolean from_up; + if (i) { /* set depth */ + branch *br; + schar from_depth; + boolean from_up; - br = add_branch(i, dungeons[i].entry_lev, &pd); + br = add_branch(i, dungeons[i].entry_lev, &pd); - /* Get the depth of the connecting end. */ - if (br->end1.dnum == i) { - from_depth = depth(&br->end2); - from_up = !br->end1_up; - } else { - from_depth = depth(&br->end1); - from_up = br->end1_up; - } + /* Get the depth of the connecting end. */ + if (br->end1.dnum == i) { + from_depth = depth(&br->end2); + from_up = !br->end1_up; + } else { + from_depth = depth(&br->end1); + from_up = br->end1_up; + } - /* - * Calculate the depth of the top of the dungeon via - * its branch. First, the depth of the entry point: - * - * depth of branch from "parent" dungeon - * + -1 or 1 depending on a up or down stair or - * 0 if portal - * - * Followed by the depth of the top of the dungeon: - * - * - (entry depth - 1) - * - * We'll say that portals stay on the same depth. - */ - dungeons[i].depth_start = from_depth - + (br->type == BR_PORTAL ? 0 : - (from_up ? -1 : 1)) - - (dungeons[i].entry_lev - 1); - } + /* + * Calculate the depth of the top of the dungeon via + * its branch. First, the depth of the entry point: + * + * depth of branch from "parent" dungeon + * + -1 or 1 depending on a up or down stair or + * 0 if portal + * + * Followed by the depth of the top of the dungeon: + * + * - (entry depth - 1) + * + * We'll say that portals stay on the same depth. + */ + dungeons[i].depth_start = + from_depth + (br->type == BR_PORTAL ? 0 : (from_up ? -1 : 1)) + - (dungeons[i].entry_lev - 1); + } - /* this is redundant - it should have been flagged by dgn_comp */ - if(dungeons[i].num_dunlevs > MAXLEVEL) - dungeons[i].num_dunlevs = MAXLEVEL; + /* this is redundant - it should have been flagged by dgn_comp */ + if (dungeons[i].num_dunlevs > MAXLEVEL) + dungeons[i].num_dunlevs = MAXLEVEL; - pd.start = pd.n_levs; /* save starting point */ - pd.n_levs += pd.tmpdungeon[i].levels; - if (pd.n_levs > LEV_LIMIT) - panic("init_dungeon: too many special levels"); - /* - * Read in the prototype special levels. Don't add generated - * special levels until they are all placed. - */ - for(; cl < pd.n_levs; cl++) { - Fread((genericptr_t)&pd.tmplevel[cl], - sizeof(struct tmplevel), 1, dgn_file); - init_level(i, cl, &pd); - } - /* - * Recursively place the generated levels for this dungeon. This - * routine will attempt all possible combinations before giving - * up. - */ - if (!place_level(pd.start, &pd)) - panic("init_dungeon: couldn't place levels"); + pd.start = pd.n_levs; /* save starting point */ + pd.n_levs += pd.tmpdungeon[i].levels; + if (pd.n_levs > LEV_LIMIT) + panic("init_dungeon: too many special levels"); + /* + * Read in the prototype special levels. Don't add generated + * special levels until they are all placed. + */ + for (; cl < pd.n_levs; cl++) { + Fread((genericptr_t) &pd.tmplevel[cl], sizeof(struct tmplevel), 1, + dgn_file); + init_level(i, cl, &pd); + } + /* + * Recursively place the generated levels for this dungeon. This + * routine will attempt all possible combinations before giving + * up. + */ + if (!place_level(pd.start, &pd)) + panic("init_dungeon: couldn't place levels"); #ifdef DDEBUG - fprintf(stderr, "--- end of dungeon %d ---\n", i); - fflush(stderr); - getchar(); + fprintf(stderr, "--- end of dungeon %d ---\n", i); + fflush(stderr); + getchar(); #endif - for (; pd.start < pd.n_levs; pd.start++) - if (pd.final_lev[pd.start]) add_level(pd.final_lev[pd.start]); + for (; pd.start < pd.n_levs; pd.start++) + if (pd.final_lev[pd.start]) + add_level(pd.final_lev[pd.start]); + pd.n_brs += pd.tmpdungeon[i].branches; + if (pd.n_brs > BRANCH_LIMIT) + panic("init_dungeon: too many branches"); + for (; cb < pd.n_brs; cb++) + Fread((genericptr_t) &pd.tmpbranch[cb], sizeof(struct tmpbranch), + 1, dgn_file); + } + (void) dlb_fclose(dgn_file); - pd.n_brs += pd.tmpdungeon[i].branches; - if (pd.n_brs > BRANCH_LIMIT) - panic("init_dungeon: too many branches"); - for(; cb < pd.n_brs; cb++) - Fread((genericptr_t)&pd.tmpbranch[cb], - sizeof(struct tmpbranch), 1, dgn_file); - } - (void) dlb_fclose(dgn_file); + for (i = 0; i < 5; i++) + tune[i] = 'A' + rn2(7); + tune[5] = 0; - for (i = 0; i < 5; i++) tune[i] = 'A' + rn2(7); - tune[5] = 0; + /* + * Find most of the special levels and dungeons so we can access their + * locations quickly. + */ + for (lev_map = level_map; lev_map->lev_name[0]; lev_map++) { + x = find_level(lev_map->lev_name); + if (x) { + assign_level(lev_map->lev_spec, &x->dlevel); + if (!strncmp(lev_map->lev_name, "x-", 2)) { + /* This is where the name substitution on the + * levels of the quest dungeon occur. + */ + Sprintf(x->proto, "%s%s", urole.filecode, + &lev_map->lev_name[1]); + } else if (lev_map->lev_spec == &knox_level) { + branch *br; + /* + * Kludge to allow floating Knox entrance. We + * specify a floating entrance by the fact that + * its entrance (end1) has a bogus dnum, namely + * n_dgns. + */ + for (br = branches; br; br = br->next) + if (on_level(&br->end2, &knox_level)) + break; - /* - * Find most of the special levels and dungeons so we can access their - * locations quickly. - */ - for (lev_map = level_map; lev_map->lev_name[0]; lev_map++) { - x = find_level(lev_map->lev_name); - if (x) { - assign_level(lev_map->lev_spec, &x->dlevel); - if (!strncmp(lev_map->lev_name, "x-", 2)) { - /* This is where the name substitution on the - * levels of the quest dungeon occur. - */ - Sprintf(x->proto, "%s%s", urole.filecode, &lev_map->lev_name[1]); - } else if (lev_map->lev_spec == &knox_level) { - branch *br; - /* - * Kludge to allow floating Knox entrance. We - * specify a floating entrance by the fact that - * its entrance (end1) has a bogus dnum, namely - * n_dgns. - */ - for (br = branches; br; br = br->next) - if (on_level(&br->end2, &knox_level)) break; + if (br) + br->end1.dnum = n_dgns; + /* adjust the branch's position on the list */ + insert_branch(br, TRUE); + } + } + } + /* + * I hate hardwiring these names. :-( + */ + quest_dnum = dname_to_dnum("The Quest"); + sokoban_dnum = dname_to_dnum("Sokoban"); + mines_dnum = dname_to_dnum("The Gnomish Mines"); + tower_dnum = dname_to_dnum("Vlad's Tower"); - if (br) br->end1.dnum = n_dgns; - /* adjust the branch's position on the list */ - insert_branch(br, TRUE); - } - } - } -/* - * I hate hardwiring these names. :-( - */ - quest_dnum = dname_to_dnum("The Quest"); - sokoban_dnum = dname_to_dnum("Sokoban"); - mines_dnum = dname_to_dnum("The Gnomish Mines"); - tower_dnum = dname_to_dnum("Vlad's Tower"); - - /* one special fixup for dummy surface level */ - if ((x = find_level("dummy")) != 0) { - i = x->dlevel.dnum; - /* the code above puts earth one level above dungeon level #1, - making the dummy level overlay level 1; but the whole reason - for having the dummy level is to make earth have depth -1 - instead of 0, so adjust the start point to shift endgame up */ - if (dunlevs_in_dungeon(&x->dlevel) > 1 - dungeons[i].depth_start) - dungeons[i].depth_start -= 1; - /* TO DO: strip "dummy" out all the way here, - so that it's hidden from feedback. */ - } + /* one special fixup for dummy surface level */ + if ((x = find_level("dummy")) != 0) { + i = x->dlevel.dnum; + /* the code above puts earth one level above dungeon level #1, + making the dummy level overlay level 1; but the whole reason + for having the dummy level is to make earth have depth -1 + instead of 0, so adjust the start point to shift endgame up */ + if (dunlevs_in_dungeon(&x->dlevel) > 1 - dungeons[i].depth_start) + dungeons[i].depth_start -= 1; + /* TO DO: strip "dummy" out all the way here, + so that it's hidden from feedback. */ + } #ifdef DEBUG - dumpit(); + dumpit(); #endif } -xchar -dunlev(lev) /* return the level number for lev in *this* dungeon */ -d_level *lev; +xchar dunlev(lev) /* return the level number for lev in *this* dungeon */ +d_level *lev; { - return(lev->dlevel); + return (lev->dlevel); } xchar -dunlevs_in_dungeon(lev) /* return the lowest level number for *this* dungeon*/ -d_level *lev; +dunlevs_in_dungeon(lev) /* return the lowest level number for *this* dungeon*/ +d_level *lev; { - return(dungeons[lev->dnum].num_dunlevs); + return (dungeons[lev->dnum].num_dunlevs); } xchar deepest_lev_reached(noquest) /* return the lowest level explored in the game*/ boolean noquest; { - /* this function is used for three purposes: to provide a factor - * of difficulty in monster generation; to provide a factor of - * difficulty in experience calculations (botl.c and end.c); and - * to insert the deepest level reached in the game in the topten - * display. the 'noquest' arg switch is required for the latter. - * - * from the player's point of view, going into the Quest is _not_ - * going deeper into the dungeon -- it is going back "home", where - * the dungeon starts at level 1. given the setup in dungeon.def, - * the depth of the Quest (thought of as starting at level 1) is - * never lower than the level of entry into the Quest, so we exclude - * the Quest from the topten "deepest level reached" display - * calculation. _However_ the Quest is a difficult dungeon, so we - * include it in the factor of difficulty calculations. - */ - register int i; - d_level tmp; - register schar ret = 0; + /* this function is used for three purposes: to provide a factor + * of difficulty in monster generation; to provide a factor of + * difficulty in experience calculations (botl.c and end.c); and + * to insert the deepest level reached in the game in the topten + * display. the 'noquest' arg switch is required for the latter. + * + * from the player's point of view, going into the Quest is _not_ + * going deeper into the dungeon -- it is going back "home", where + * the dungeon starts at level 1. given the setup in dungeon.def, + * the depth of the Quest (thought of as starting at level 1) is + * never lower than the level of entry into the Quest, so we exclude + * the Quest from the topten "deepest level reached" display + * calculation. _However_ the Quest is a difficult dungeon, so we + * include it in the factor of difficulty calculations. + */ + register int i; + d_level tmp; + register schar ret = 0; - for(i = 0; i < n_dgns; i++) { - if (noquest && i == quest_dnum) continue; - tmp.dlevel = dungeons[i].dunlev_ureached; - if (tmp.dlevel == 0) continue; - tmp.dnum = i; - if(depth(&tmp) > ret) ret = depth(&tmp); - } - return((xchar) ret); + for (i = 0; i < n_dgns; i++) { + if (noquest && i == quest_dnum) + continue; + tmp.dlevel = dungeons[i].dunlev_ureached; + if (tmp.dlevel == 0) + continue; + tmp.dnum = i; + if (depth(&tmp) > ret) + ret = depth(&tmp); + } + return ((xchar) ret); } /* return a bookkeeping level number for purpose of comparisons and * save/restore */ xchar ledger_no(lev) -d_level *lev; +d_level *lev; { - return((xchar)(lev->dlevel + dungeons[lev->dnum].ledger_start)); + return ((xchar)(lev->dlevel + dungeons[lev->dnum].ledger_start)); } /* @@ -1008,63 +1041,65 @@ d_level *lev; xchar maxledgerno() { - return (xchar) (dungeons[n_dgns-1].ledger_start + - dungeons[n_dgns-1].num_dunlevs); + return (xchar)(dungeons[n_dgns - 1].ledger_start + + dungeons[n_dgns - 1].num_dunlevs); } /* return the dungeon that this ledgerno exists in */ xchar ledger_to_dnum(ledgerno) -xchar ledgerno; +xchar ledgerno; { - register int i; + register int i; - /* find i such that (i->base + 1) <= ledgerno <= (i->base + i->count) */ - for (i = 0; i < n_dgns; i++) - if (dungeons[i].ledger_start < ledgerno && - ledgerno <= dungeons[i].ledger_start + dungeons[i].num_dunlevs) - return (xchar)i; + /* find i such that (i->base + 1) <= ledgerno <= (i->base + i->count) */ + for (i = 0; i < n_dgns; i++) + if (dungeons[i].ledger_start < ledgerno + && ledgerno <= dungeons[i].ledger_start + dungeons[i].num_dunlevs) + return (xchar) i; - panic("level number out of range [ledger_to_dnum(%d)]", (int)ledgerno); - /*NOT REACHED*/ - return (xchar)0; + panic("level number out of range [ledger_to_dnum(%d)]", (int) ledgerno); + /*NOT REACHED*/ + return (xchar) 0; } /* return the level of the dungeon this ledgerno exists in */ xchar ledger_to_dlev(ledgerno) -xchar ledgerno; +xchar ledgerno; { - return((xchar)(ledgerno - dungeons[ledger_to_dnum(ledgerno)].ledger_start)); + return ( + (xchar)(ledgerno - dungeons[ledger_to_dnum(ledgerno)].ledger_start)); } /* returns the depth of a level, in floors below the surface */ /* (note levels in different dungeons can have the same depth). */ schar depth(lev) -d_level *lev; +d_level *lev; { - return((schar)( dungeons[lev->dnum].depth_start + lev->dlevel - 1)); + return ((schar)(dungeons[lev->dnum].depth_start + lev->dlevel - 1)); } -boolean -on_level(lev1, lev2) /* are "lev1" and "lev2" actually the same? */ -d_level *lev1, *lev2; +boolean on_level(lev1, lev2) /* are "lev1" and "lev2" actually the same? */ +d_level *lev1, *lev2; { - return((boolean)((lev1->dnum == lev2->dnum) && (lev1->dlevel == lev2->dlevel))); + return ((boolean)((lev1->dnum == lev2->dnum) + && (lev1->dlevel == lev2->dlevel))); } /* is this level referenced in the special level chain? */ s_level * Is_special(lev) -d_level *lev; +d_level *lev; { - s_level *levtmp; + s_level *levtmp; - for (levtmp = sp_levchn; levtmp; levtmp = levtmp->next) - if (on_level(lev, &levtmp->dlevel)) return(levtmp); + for (levtmp = sp_levchn; levtmp; levtmp = levtmp->next) + if (on_level(lev, &levtmp->dlevel)) + return (levtmp); - return((s_level *)0); + return ((s_level *) 0); } /* @@ -1073,153 +1108,152 @@ d_level *lev; */ branch * Is_branchlev(lev) - d_level *lev; +d_level *lev; { - branch *curr; + branch *curr; - for (curr = branches; curr; curr = curr->next) { - if (on_level(lev, &curr->end1) || on_level(lev, &curr->end2)) - return curr; - } - return (branch *) 0; + for (curr = branches; curr; curr = curr->next) { + if (on_level(lev, &curr->end1) || on_level(lev, &curr->end2)) + return curr; + } + return (branch *) 0; } /* goto the next level (or appropriate dungeon) */ void next_level(at_stairs) -boolean at_stairs; +boolean at_stairs; { - if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) { - /* Taking a down dungeon branch. */ - goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE); - } else { - /* Going down a stairs or jump in a trap door. */ - d_level newlevel; + if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) { + /* Taking a down dungeon branch. */ + goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE); + } else { + /* Going down a stairs or jump in a trap door. */ + d_level newlevel; - newlevel.dnum = u.uz.dnum; - newlevel.dlevel = u.uz.dlevel + 1; - goto_level(&newlevel, at_stairs, !at_stairs, FALSE); - } + newlevel.dnum = u.uz.dnum; + newlevel.dlevel = u.uz.dlevel + 1; + goto_level(&newlevel, at_stairs, !at_stairs, FALSE); + } } /* goto the previous level (or appropriate dungeon) */ void prev_level(at_stairs) -boolean at_stairs; +boolean at_stairs; { - if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) { - /* Taking an up dungeon branch. */ - /* KMH -- Upwards branches are okay if not level 1 */ - /* (Just make sure it doesn't go above depth 1) */ - if(!u.uz.dnum && u.uz.dlevel == 1 && !u.uhave.amulet) done(ESCAPED); - else goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE); - } else { - /* Going up a stairs or rising through the ceiling. */ - d_level newlevel; - newlevel.dnum = u.uz.dnum; - newlevel.dlevel = u.uz.dlevel - 1; - goto_level(&newlevel, at_stairs, FALSE, FALSE); - } + if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) { + /* Taking an up dungeon branch. */ + /* KMH -- Upwards branches are okay if not level 1 */ + /* (Just make sure it doesn't go above depth 1) */ + if (!u.uz.dnum && u.uz.dlevel == 1 && !u.uhave.amulet) + done(ESCAPED); + else + goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE); + } else { + /* Going up a stairs or rising through the ceiling. */ + d_level newlevel; + newlevel.dnum = u.uz.dnum; + newlevel.dlevel = u.uz.dlevel - 1; + goto_level(&newlevel, at_stairs, FALSE, FALSE); + } } void u_on_newpos(x, y) int x, y; { - u.ux = x; - u.uy = y; + u.ux = x; + u.uy = y; #ifdef CLIPPING - cliparound(u.ux, u.uy); + cliparound(u.ux, u.uy); #endif - /* ridden steed always shares hero's location */ - if (u.usteed) u.usteed->mx = u.ux, u.usteed->my = u.uy; - /* when changing levels, don't leave old position set with - stale values from previous level */ - if (!on_level(&u.uz, &u.uz0)) u.ux0 = u.ux, u.uy0 = u.uy; + /* ridden steed always shares hero's location */ + if (u.usteed) + u.usteed->mx = u.ux, u.usteed->my = u.uy; + /* when changing levels, don't leave old position set with + stale values from previous level */ + if (!on_level(&u.uz, &u.uz0)) + u.ux0 = u.ux, u.uy0 = u.uy; } -void -u_on_rndspot(upflag) /* place you on a random location */ +void u_on_rndspot(upflag) /* place you on a random location */ int upflag; { - int up = (upflag & 1), - was_in_W_tower = (upflag & 2); + int up = (upflag & 1), was_in_W_tower = (upflag & 2); - /* - * Place the hero at a random location within the relevant region. - * place_lregion(xTELE) -> put_lregion_here(xTELE) -> u_on_newpos() - * Unspecified region (.lx == 0) defaults to entire level. - */ - if (was_in_W_tower && On_W_tower_level(&u.uz)) - /* Stay inside the Wizard's tower when feasible. - We use the W Tower's exclusion region for the - destination instead of its enclosing region. - Note: up vs down doesn't matter in this case - because both specify the same exclusion area. */ - place_lregion(dndest.nlx, dndest.nly, dndest.nhx, dndest.nhy, - 0, 0, 0, 0, LR_DOWNTELE, (d_level *) 0); - else if (up) - place_lregion(updest.lx, updest.ly, updest.hx, updest.hy, - updest.nlx, updest.nly, updest.nhx, updest.nhy, - LR_UPTELE, (d_level *)0); - else - place_lregion(dndest.lx, dndest.ly, dndest.hx, dndest.hy, - dndest.nlx, dndest.nly, dndest.nhx, dndest.nhy, - LR_DOWNTELE, (d_level *)0); + /* + * Place the hero at a random location within the relevant region. + * place_lregion(xTELE) -> put_lregion_here(xTELE) -> u_on_newpos() + * Unspecified region (.lx == 0) defaults to entire level. + */ + if (was_in_W_tower && On_W_tower_level(&u.uz)) + /* Stay inside the Wizard's tower when feasible. + We use the W Tower's exclusion region for the + destination instead of its enclosing region. + Note: up vs down doesn't matter in this case + because both specify the same exclusion area. */ + place_lregion(dndest.nlx, dndest.nly, dndest.nhx, dndest.nhy, 0, 0, 0, + 0, LR_DOWNTELE, (d_level *) 0); + else if (up) + place_lregion(updest.lx, updest.ly, updest.hx, updest.hy, updest.nlx, + updest.nly, updest.nhx, updest.nhy, LR_UPTELE, + (d_level *) 0); + else + place_lregion(dndest.lx, dndest.ly, dndest.hx, dndest.hy, dndest.nlx, + dndest.nly, dndest.nhx, dndest.nhy, LR_DOWNTELE, + (d_level *) 0); } -void -u_on_sstairs(upflag) /* place you on the special staircase */ +void u_on_sstairs(upflag) /* place you on the special staircase */ int upflag; { - if (sstairs.sx) - u_on_newpos(sstairs.sx, sstairs.sy); - else - u_on_rndspot(upflag); + if (sstairs.sx) + u_on_newpos(sstairs.sx, sstairs.sy); + else + u_on_rndspot(upflag); } -void -u_on_upstairs() /* place you on upstairs (or special equivalent) */ +void u_on_upstairs() /* place you on upstairs (or special equivalent) */ { - if (xupstair) - u_on_newpos(xupstair, yupstair); - else - u_on_sstairs(0); /* destination upstairs implies moving down */ + if (xupstair) + u_on_newpos(xupstair, yupstair); + else + u_on_sstairs(0); /* destination upstairs implies moving down */ } -void -u_on_dnstairs() /* place you on dnstairs (or special equivalent) */ +void u_on_dnstairs() /* place you on dnstairs (or special equivalent) */ { - if (xdnstair) - u_on_newpos(xdnstair, ydnstair); - else - u_on_sstairs(1); /* destination dnstairs implies moving up */ + if (xdnstair) + u_on_newpos(xdnstair, ydnstair); + else + u_on_sstairs(1); /* destination dnstairs implies moving up */ } boolean On_stairs(x, y) xchar x, y; { - return((boolean)((x == xupstair && y == yupstair) || - (x == xdnstair && y == ydnstair) || - (x == xdnladder && y == ydnladder) || - (x == xupladder && y == yupladder) || - (x == sstairs.sx && y == sstairs.sy))); + return ((boolean)((x == xupstair && y == yupstair) + || (x == xdnstair && y == ydnstair) + || (x == xdnladder && y == ydnladder) + || (x == xupladder && y == yupladder) + || (x == sstairs.sx && y == sstairs.sy))); } boolean Is_botlevel(lev) d_level *lev; { - return((boolean)(lev->dlevel == dungeons[lev->dnum].num_dunlevs)); + return ((boolean)(lev->dlevel == dungeons[lev->dnum].num_dunlevs)); } boolean Can_dig_down(lev) d_level *lev; { - return((boolean)(!level.flags.hardfloor - && !Is_botlevel(lev) && !Invocation_lev(lev))); + return ((boolean)(!level.flags.hardfloor && !Is_botlevel(lev) + && !Invocation_lev(lev))); } /* @@ -1231,7 +1265,7 @@ boolean Can_fall_thru(lev) d_level *lev; { - return((boolean)(Can_dig_down(lev) || Is_stronghold(lev))); + return ((boolean)(Can_dig_down(lev) || Is_stronghold(lev))); } /* @@ -1242,24 +1276,24 @@ d_level *lev; */ boolean Can_rise_up(x, y, lev) -int x, y; +int x, y; d_level *lev; { /* can't rise up from inside the top of the Wizard's tower */ /* KMH -- or in sokoban */ - if (In_endgame(lev) || In_sokoban(lev) || - (Is_wiz1_level(lev) && In_W_tower(x, y, lev))) - return FALSE; - return (boolean)(lev->dlevel > 1 || - (dungeons[lev->dnum].entry_lev == 1 && ledger_no(lev) != 1 && - sstairs.sx && sstairs.up)); + if (In_endgame(lev) || In_sokoban(lev) + || (Is_wiz1_level(lev) && In_W_tower(x, y, lev))) + return FALSE; + return (boolean)(lev->dlevel > 1 + || (dungeons[lev->dnum].entry_lev == 1 + && ledger_no(lev) != 1 && sstairs.sx && sstairs.up)); } boolean has_ceiling(lev) d_level *lev; { - /* [what about level 1 of the quest?] */ + /* [what about level 1 of the quest?] */ return (!Is_airlevel(lev) && !Is_waterlevel(lev)); } @@ -1279,61 +1313,59 @@ get_level(newlevel, levnum) d_level *newlevel; int levnum; { - branch *br; - xchar dgn = u.uz.dnum; + branch *br; + xchar dgn = u.uz.dnum; - if (levnum <= 0) { - /* can only currently happen in endgame */ - levnum = u.uz.dlevel; - } else if (levnum > dungeons[dgn].depth_start - + dungeons[dgn].num_dunlevs - 1) { - /* beyond end of dungeon, jump to last level */ - levnum = dungeons[dgn].num_dunlevs; - } else { - /* The desired level is in this dungeon or a "higher" one. */ + if (levnum <= 0) { + /* can only currently happen in endgame */ + levnum = u.uz.dlevel; + } else if (levnum + > dungeons[dgn].depth_start + dungeons[dgn].num_dunlevs - 1) { + /* beyond end of dungeon, jump to last level */ + levnum = dungeons[dgn].num_dunlevs; + } else { + /* The desired level is in this dungeon or a "higher" one. */ - /* - * Branch up the tree until we reach a dungeon that contains the - * levnum. - */ - if (levnum < dungeons[dgn].depth_start) { + /* + * Branch up the tree until we reach a dungeon that contains the + * levnum. + */ + if (levnum < dungeons[dgn].depth_start) { + do { + /* + * Find the parent dungeon of this dungeon. + * + * This assumes that end2 is always the "child" and it is + * unique. + */ + for (br = branches; br; br = br->next) + if (br->end2.dnum == dgn) + break; + if (!br) + panic("get_level: can't find parent dungeon"); - do { - /* - * Find the parent dungeon of this dungeon. - * - * This assumes that end2 is always the "child" and it is - * unique. - */ - for (br = branches; br; br = br->next) - if (br->end2.dnum == dgn) break; - if (!br) - panic("get_level: can't find parent dungeon"); + dgn = br->end1.dnum; + } while (levnum < dungeons[dgn].depth_start); + } - dgn = br->end1.dnum; - } while (levnum < dungeons[dgn].depth_start); - } + /* We're within the same dungeon; calculate the level. */ + levnum = levnum - dungeons[dgn].depth_start + 1; + } - /* We're within the same dungeon; calculate the level. */ - levnum = levnum - dungeons[dgn].depth_start + 1; - } - - newlevel->dnum = dgn; - newlevel->dlevel = levnum; + newlevel->dnum = dgn; + newlevel->dlevel = levnum; } -boolean -In_quest(lev) /* are you in the quest dungeon? */ +boolean In_quest(lev) /* are you in the quest dungeon? */ d_level *lev; { - return((boolean)(lev->dnum == quest_dnum)); + return ((boolean)(lev->dnum == quest_dnum)); } -boolean -In_mines(lev) /* are you in the mines dungeon? */ -d_level *lev; +boolean In_mines(lev) /* are you in the mines dungeon? */ +d_level *lev; { - return((boolean)(lev->dnum == mines_dnum)); + return ((boolean)(lev->dnum == mines_dnum)); } /* @@ -1346,18 +1378,20 @@ d_level *lev; */ branch * dungeon_branch(s) - const char *s; +const char *s; { branch *br; - xchar dnum; + xchar dnum; dnum = dname_to_dnum(s); /* Find the branch that connects to dungeon i's branch. */ for (br = branches; br; br = br->next) - if (br->end2.dnum == dnum) break; + if (br->end2.dnum == dnum) + break; - if (!br) panic("dgn_entrance: can't find entrance to %s", s); + if (!br) + panic("dgn_entrance: can't find entrance to %s", s); return br; } @@ -1372,119 +1406,116 @@ dungeon_branch(s) */ boolean at_dgn_entrance(s) - const char *s; +const char *s; { branch *br; br = dungeon_branch(s); - return((boolean)(on_level(&u.uz, &br->end1) ? TRUE : FALSE)); + return ((boolean)(on_level(&u.uz, &br->end1) ? TRUE : FALSE)); } -boolean -In_V_tower(lev) /* is `lev' part of Vlad's tower? */ -d_level *lev; -{ - return((boolean)(lev->dnum == tower_dnum)); -} - -boolean -On_W_tower_level(lev) /* is `lev' a level containing the Wizard's tower? */ -d_level *lev; -{ - return (boolean)(Is_wiz1_level(lev) || - Is_wiz2_level(lev) || - Is_wiz3_level(lev)); -} - -boolean -In_W_tower(x, y, lev) /* is of `lev' inside the Wizard's tower? */ -int x, y; -d_level *lev; -{ - if (!On_W_tower_level(lev)) return FALSE; - /* - * Both of the exclusion regions for arriving via level teleport - * (from above or below) define the tower's boundary. - * assert( updest.nIJ == dndest.nIJ for I={l|h},J={x|y} ); - */ - if (dndest.nlx > 0) - return (boolean)within_bounded_area(x, y, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy); - else - impossible("No boundary for Wizard's Tower?"); - return FALSE; -} - -boolean -In_hell(lev) /* are you in one of the Hell levels? */ -d_level *lev; -{ - return((boolean)(dungeons[lev->dnum].flags.hellish)); -} - -void -find_hell(lev) /* sets *lev to be the gateway to Gehennom... */ +boolean In_V_tower(lev) /* is `lev' part of Vlad's tower? */ d_level *lev; { - lev->dnum = valley_level.dnum; - lev->dlevel = 1; + return ((boolean)(lev->dnum == tower_dnum)); } -void -goto_hell(at_stairs, falling) /* go directly to hell... */ -boolean at_stairs, falling; +boolean +On_W_tower_level(lev) /* is `lev' a level containing the Wizard's tower? */ +d_level *lev; { - d_level lev; - - find_hell(&lev); - goto_level(&lev, at_stairs, falling, FALSE); + return (boolean)(Is_wiz1_level(lev) || Is_wiz2_level(lev) + || Is_wiz3_level(lev)); } -void -assign_level(dest, src) /* equivalent to dest = source */ -d_level *dest, *src; +boolean In_W_tower(x, y, + lev) /* is of `lev' inside the Wizard's tower? */ +int x, y; +d_level *lev; { - dest->dnum = src->dnum; - dest->dlevel = src->dlevel; + if (!On_W_tower_level(lev)) + return FALSE; + /* + * Both of the exclusion regions for arriving via level teleport + * (from above or below) define the tower's boundary. + * assert( updest.nIJ == dndest.nIJ for I={l|h},J={x|y} ); + */ + if (dndest.nlx > 0) + return (boolean) within_bounded_area(x, y, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy); + else + impossible("No boundary for Wizard's Tower?"); + return FALSE; } -void -assign_rnd_level(dest, src, range) /* dest = src + rn1(range) */ -d_level *dest, *src; +boolean In_hell(lev) /* are you in one of the Hell levels? */ +d_level *lev; +{ + return ((boolean)(dungeons[lev->dnum].flags.hellish)); +} + +void find_hell(lev) /* sets *lev to be the gateway to Gehennom... */ +d_level *lev; +{ + lev->dnum = valley_level.dnum; + lev->dlevel = 1; +} + +void goto_hell(at_stairs, falling) /* go directly to hell... */ +boolean at_stairs, falling; +{ + d_level lev; + + find_hell(&lev); + goto_level(&lev, at_stairs, falling, FALSE); +} + +void assign_level(dest, src) /* equivalent to dest = source */ +d_level *dest, *src; +{ + dest->dnum = src->dnum; + dest->dlevel = src->dlevel; +} + +void assign_rnd_level(dest, src, range) /* dest = src + rn1(range) */ +d_level *dest, *src; int range; { - dest->dnum = src->dnum; - dest->dlevel = src->dlevel + ((range > 0) ? rnd(range) : -rnd(-range)) ; + dest->dnum = src->dnum; + dest->dlevel = src->dlevel + ((range > 0) ? rnd(range) : -rnd(-range)); - if(dest->dlevel > dunlevs_in_dungeon(dest)) - dest->dlevel = dunlevs_in_dungeon(dest); - else if(dest->dlevel < 1) - dest->dlevel = 1; + if (dest->dlevel > dunlevs_in_dungeon(dest)) + dest->dlevel = dunlevs_in_dungeon(dest); + else if (dest->dlevel < 1) + dest->dlevel = 1; } int induced_align(pct) -int pct; +int pct; { - s_level *lev = Is_special(&u.uz); - aligntyp al; + s_level *lev = Is_special(&u.uz); + aligntyp al; - if (lev && lev->flags.align) - if(rn2(100) < pct) return(lev->flags.align); + if (lev && lev->flags.align) + if (rn2(100) < pct) + return (lev->flags.align); - if(dungeons[u.uz.dnum].flags.align) - if(rn2(100) < pct) return(dungeons[u.uz.dnum].flags.align); + if (dungeons[u.uz.dnum].flags.align) + if (rn2(100) < pct) + return (dungeons[u.uz.dnum].flags.align); - al = rn2(3) - 1; - return(Align2amask(al)); + al = rn2(3) - 1; + return (Align2amask(al)); } boolean Invocation_lev(lev) d_level *lev; { - return((boolean)(In_hell(lev) && - lev->dlevel == (dungeons[lev->dnum].num_dunlevs - 1))); + return ( + (boolean)(In_hell(lev) + && lev->dlevel == (dungeons[lev->dnum].num_dunlevs - 1))); } /* use instead of depth() wherever a degree of difficulty is made @@ -1493,13 +1524,12 @@ d_level *lev; xchar level_difficulty() { - if (In_endgame(&u.uz)) - return((xchar)(depth(&sanctum_level) + u.ulevel/2)); - else - if (u.uhave.amulet) - return(deepest_lev_reached(FALSE)); - else - return((xchar) depth(&u.uz)); + if (In_endgame(&u.uz)) + return ((xchar)(depth(&sanctum_level) + u.ulevel / 2)); + else if (u.uhave.amulet) + return (deepest_lev_reached(FALSE)); + else + return ((xchar) depth(&u.uz)); } /* Take one word and try to match it to a level. @@ -1517,51 +1547,57 @@ const char *nam; char buf[BUFSZ]; /* allow strings like "the oracle level" to find "oracle" */ - if (!strncmpi(nam, "the ", 4)) nam += 4; - if ((p = strstri(nam, " level")) != 0 && p == eos((char*)nam) - 6) { - nam = strcpy(buf, nam); - *(eos(buf) - 6) = '\0'; + if (!strncmpi(nam, "the ", 4)) + nam += 4; + if ((p = strstri(nam, " level")) != 0 && p == eos((char *) nam) - 6) { + nam = strcpy(buf, nam); + *(eos(buf) - 6) = '\0'; } /* hell is the old name, and wouldn't match; gehennom would match its branch, yielding the castle level instead of the valley of the dead */ if (!strcmpi(nam, "gehennom") || !strcmpi(nam, "hell")) { - if (In_V_tower(&u.uz)) nam = " to Vlad's tower"; /* branch to... */ - else nam = "valley"; + if (In_V_tower(&u.uz)) + nam = " to Vlad's tower"; /* branch to... */ + else + nam = "valley"; } if ((slev = find_level(nam)) != 0) { - dlev = slev->dlevel; - idx = ledger_no(&dlev); - if ((dlev.dnum == u.uz.dnum || - /* within same branch, or else main dungeon <-> gehennom */ - (u.uz.dnum == valley_level.dnum && - dlev.dnum == medusa_level.dnum) || - (u.uz.dnum == medusa_level.dnum && - dlev.dnum == valley_level.dnum)) && - ( /* either wizard mode or else seen and not forgotten */ - wizard || - (level_info[idx].flags & (FORGOTTEN|VISITED)) == VISITED)) { - lev = depth(&slev->dlevel); - } - } else { /* not a specific level; try branch names */ - idx = find_branch(nam, (struct proto_dungeon *)0); - /* " to Xyzzy" */ - if (idx < 0 && (p = strstri(nam, " to ")) != 0) - idx = find_branch(p + 4, (struct proto_dungeon *)0); + dlev = slev->dlevel; + idx = ledger_no(&dlev); + if ((dlev.dnum == u.uz.dnum || + /* within same branch, or else main dungeon <-> gehennom */ + (u.uz.dnum == valley_level.dnum + && dlev.dnum == medusa_level.dnum) + || (u.uz.dnum == medusa_level.dnum + && dlev.dnum == valley_level.dnum)) + && (/* either wizard mode or else seen and not forgotten */ + wizard + || (level_info[idx].flags & (FORGOTTEN | VISITED)) + == VISITED)) { + lev = depth(&slev->dlevel); + } + } else { /* not a specific level; try branch names */ + idx = find_branch(nam, (struct proto_dungeon *) 0); + /* " to Xyzzy" */ + if (idx < 0 && (p = strstri(nam, " to ")) != 0) + idx = find_branch(p + 4, (struct proto_dungeon *) 0); - if (idx >= 0) { - idxtoo = (idx >> 8) & 0x00FF; - idx &= 0x00FF; - if ( /* either wizard mode, or else _both_ sides of branch seen */ - wizard || - ((level_info[idx].flags & (FORGOTTEN|VISITED)) == VISITED && - (level_info[idxtoo].flags & (FORGOTTEN|VISITED)) == VISITED)) { - if (ledger_to_dnum(idxtoo) == u.uz.dnum) idx = idxtoo; - dlev.dnum = ledger_to_dnum(idx); - dlev.dlevel = ledger_to_dlev(idx); - lev = depth(&dlev); - } - } + if (idx >= 0) { + idxtoo = (idx >> 8) & 0x00FF; + idx &= 0x00FF; + if (/* either wizard mode, or else _both_ sides of branch seen */ + wizard + || ((level_info[idx].flags & (FORGOTTEN | VISITED)) == VISITED + && (level_info[idxtoo].flags & (FORGOTTEN | VISITED)) + == VISITED)) { + if (ledger_to_dnum(idxtoo) == u.uz.dnum) + idx = idxtoo; + dlev.dnum = ledger_to_dnum(idx); + dlev.dlevel = ledger_to_dlev(idx); + lev = depth(&dlev); + } + } } return lev; } @@ -1571,12 +1607,14 @@ unplaced_floater(dptr) struct dungeon *dptr; { branch *br; - int idx = (int)(dptr - dungeons); + int idx = (int) (dptr - dungeons); /* if other floating branches are added, this will need to change */ - if (idx != knox_level.dnum) return FALSE; + if (idx != knox_level.dnum) + return FALSE; for (br = branches; br; br = br->next) - if (br->end1.dnum == n_dgns && br->end2.dnum == idx) return TRUE; + if (br->end1.dnum == n_dgns && br->end2.dnum == idx) + return TRUE; return FALSE; } @@ -1587,10 +1625,12 @@ boolean unplaced; { s_level *dummy; - if (unplaced) return TRUE; - if (In_endgame(&u.uz) && !In_endgame(lvl_p)) return TRUE; + if (unplaced) + return TRUE; + if (In_endgame(&u.uz) && !In_endgame(lvl_p)) + return TRUE; if ((dummy = find_level("dummy")) != 0 && on_level(lvl_p, &dummy->dlevel)) - return TRUE; + return TRUE; return FALSE; } @@ -1610,20 +1650,20 @@ boolean unreachable; lchoices->playerlev[lchoices->idx] = depth(lvl_p); any = zeroany; if (unreachable) { - /* not selectable, but still consumes next menuletter; - prepend padding in place of missing menu selector */ - Sprintf(tmpbuf, " %s", entry); - entry = tmpbuf; + /* not selectable, but still consumes next menuletter; + prepend padding in place of missing menu selector */ + Sprintf(tmpbuf, " %s", entry); + entry = tmpbuf; } else { - any.a_int = lchoices->idx + 1; + any.a_int = lchoices->idx + 1; } - add_menu(win, NO_GLYPH, &any, lchoices->menuletter, - 0, ATR_NONE, entry, MENU_UNSELECTED); + add_menu(win, NO_GLYPH, &any, lchoices->menuletter, 0, ATR_NONE, entry, + MENU_UNSELECTED); /* this assumes there are at most 52 interesting levels */ if (lchoices->menuletter == 'z') - lchoices->menuletter = 'A'; + lchoices->menuletter = 'A'; else - lchoices->menuletter++; + lchoices->menuletter++; lchoices->idx++; return; } @@ -1631,13 +1671,17 @@ boolean unreachable; /* Convert a branch type to a string usable by print_dungeon(). */ STATIC_OVL const char * br_string(type) - int type; +int type; { switch (type) { - case BR_PORTAL: return "Portal"; - case BR_NO_END1: return "Connection"; - case BR_NO_END2: return "One way stair"; - case BR_STAIR: return "Stair"; + case BR_PORTAL: + return "Portal"; + case BR_NO_END1: + return "Connection"; + case BR_NO_END2: + return "One way stair"; + case BR_STAIR: + return "Stair"; } return " (unknown)"; } @@ -1645,30 +1689,28 @@ br_string(type) /* Print all child branches between the lower and upper bounds. */ STATIC_OVL void print_branch(win, dnum, lower_bound, upper_bound, bymenu, lchoices_p) - winid win; - int dnum; - int lower_bound; - int upper_bound; - boolean bymenu; - struct lchoice *lchoices_p; +winid win; +int dnum; +int lower_bound; +int upper_bound; +boolean bymenu; +struct lchoice *lchoices_p; { branch *br; char buf[BUFSZ]; /* This assumes that end1 is the "parent". */ for (br = branches; br; br = br->next) { - if (br->end1.dnum == dnum && lower_bound < br->end1.dlevel && - br->end1.dlevel <= upper_bound) { - Sprintf(buf," %s to %s: %d", - br_string(br->type), - dungeons[br->end2.dnum].dname, - depth(&br->end1)); - if (bymenu) - tport_menu(win, buf, lchoices_p, &br->end1, - unreachable_level(&br->end1, FALSE)); - else - putstr(win, 0, buf); - } + if (br->end1.dnum == dnum && lower_bound < br->end1.dlevel + && br->end1.dlevel <= upper_bound) { + Sprintf(buf, " %s to %s: %d", br_string(br->type), + dungeons[br->end2.dnum].dname, depth(&br->end1)); + if (bymenu) + tport_menu(win, buf, lchoices_p, &br->end1, + unreachable_level(&br->end1, FALSE)); + else + putstr(win, 0, buf); + } } } @@ -1679,114 +1721,117 @@ boolean bymenu; schar *rlev; xchar *rdgn; { - int i, last_level, nlev; - char buf[BUFSZ]; + int i, last_level, nlev; + char buf[BUFSZ]; const char *descr; boolean first, unplaced; s_level *slev; dungeon *dptr; - branch *br; + branch *br; anything any; struct lchoice lchoices; - winid win = create_nhwindow(NHW_MENU); + winid win = create_nhwindow(NHW_MENU); if (bymenu) { - start_menu(win); - lchoices.idx = 0; - lchoices.menuletter = 'a'; + start_menu(win); + lchoices.idx = 0; + lchoices.menuletter = 'a'; } for (i = 0, dptr = dungeons; i < n_dgns; i++, dptr++) { - if (bymenu && In_endgame(&u.uz) && i != astral_level.dnum) continue; - unplaced = unplaced_floater(dptr); - descr = unplaced ? "depth" : "level"; - nlev = dptr->num_dunlevs; - if (nlev > 1) - Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr), - dptr->depth_start, dptr->depth_start + nlev - 1); - else - Sprintf(buf, "%s: %s %d", dptr->dname, descr, - dptr->depth_start); + if (bymenu && In_endgame(&u.uz) && i != astral_level.dnum) + continue; + unplaced = unplaced_floater(dptr); + descr = unplaced ? "depth" : "level"; + nlev = dptr->num_dunlevs; + if (nlev > 1) + Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr), + dptr->depth_start, dptr->depth_start + nlev - 1); + else + Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start); - /* Most entrances are uninteresting. */ - if (dptr->entry_lev != 1) { - if (dptr->entry_lev == nlev) - Strcat(buf, ", entrance from below"); - else - Sprintf(eos(buf), ", entrance on %d", - dptr->depth_start + dptr->entry_lev - 1); - } - if (bymenu) { - any = zeroany; - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, MENU_UNSELECTED); - } else - putstr(win, 0, buf); + /* Most entrances are uninteresting. */ + if (dptr->entry_lev != 1) { + if (dptr->entry_lev == nlev) + Strcat(buf, ", entrance from below"); + else + Sprintf(eos(buf), ", entrance on %d", + dptr->depth_start + dptr->entry_lev - 1); + } + if (bymenu) { + any = zeroany; + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, + MENU_UNSELECTED); + } else + putstr(win, 0, buf); - /* - * Circle through the special levels to find levels that are in - * this dungeon. - */ - for (slev = sp_levchn, last_level = 0; slev; slev = slev->next) { - if (slev->dlevel.dnum != i) continue; + /* + * Circle through the special levels to find levels that are in + * this dungeon. + */ + for (slev = sp_levchn, last_level = 0; slev; slev = slev->next) { + if (slev->dlevel.dnum != i) + continue; - /* print any branches before this level */ - print_branch(win, i, last_level, slev->dlevel.dlevel, bymenu, &lchoices); + /* print any branches before this level */ + print_branch(win, i, last_level, slev->dlevel.dlevel, bymenu, + &lchoices); - Sprintf(buf, " %s: %d", slev->proto, depth(&slev->dlevel)); - if (Is_stronghold(&slev->dlevel)) - Sprintf(eos(buf), " (tune %s)", tune); - if (bymenu) - tport_menu(win, buf, &lchoices, &slev->dlevel, - unreachable_level(&slev->dlevel, unplaced)); - else - putstr(win, 0, buf); + Sprintf(buf, " %s: %d", slev->proto, depth(&slev->dlevel)); + if (Is_stronghold(&slev->dlevel)) + Sprintf(eos(buf), " (tune %s)", tune); + if (bymenu) + tport_menu(win, buf, &lchoices, &slev->dlevel, + unreachable_level(&slev->dlevel, unplaced)); + else + putstr(win, 0, buf); - last_level = slev->dlevel.dlevel; - } - /* print branches after the last special level */ - print_branch(win, i, last_level, MAXLEVEL, bymenu, &lchoices); + last_level = slev->dlevel.dlevel; + } + /* print branches after the last special level */ + print_branch(win, i, last_level, MAXLEVEL, bymenu, &lchoices); } if (bymenu) { - int n; - menu_item *selected; - int idx; + int n; + menu_item *selected; + int idx; - end_menu(win, "Level teleport to where:"); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n > 0) { - idx = selected[0].item.a_int - 1; - free((genericptr_t)selected); - if (rlev && rdgn) { - *rlev = lchoices.lev[idx]; - *rdgn = lchoices.dgn[idx]; - return lchoices.playerlev[idx]; - } - } - return 0; + end_menu(win, "Level teleport to where:"); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n > 0) { + idx = selected[0].item.a_int - 1; + free((genericptr_t) selected); + if (rlev && rdgn) { + *rlev = lchoices.lev[idx]; + *rdgn = lchoices.dgn[idx]; + return lchoices.playerlev[idx]; + } + } + return 0; } /* Print out floating branches (if any). */ for (first = TRUE, br = branches; br; br = br->next) { - if (br->end1.dnum == n_dgns) { - if (first) { - putstr(win, 0, ""); - putstr(win, 0, "Floating branches"); - first = FALSE; - } - Sprintf(buf, " %s to %s", - br_string(br->type), dungeons[br->end2.dnum].dname); - putstr(win, 0, buf); - } + if (br->end1.dnum == n_dgns) { + if (first) { + putstr(win, 0, ""); + putstr(win, 0, "Floating branches"); + first = FALSE; + } + Sprintf(buf, " %s to %s", br_string(br->type), + dungeons[br->end2.dnum].dname); + putstr(win, 0, buf); + } } /* I hate searching for the invocation pos while debugging. -dean */ if (Invocation_lev(&u.uz)) { - putstr(win, 0, ""); - Sprintf(buf, "Invocation position @ (%d,%d), hero @ (%d,%d)", - inv_pos.x, inv_pos.y, u.ux, u.uy); - putstr(win, 0, buf); + putstr(win, 0, ""); + Sprintf(buf, "Invocation position @ (%d,%d), hero @ (%d,%d)", + inv_pos.x, inv_pos.y, u.ux, u.uy); + putstr(win, 0, buf); } /* * The following is based on the assumption that the inter-level portals @@ -1794,18 +1839,19 @@ xchar *rdgn; * one per level (currently true, of course). */ else if (Is_earthlevel(&u.uz) || Is_waterlevel(&u.uz) - || Is_firelevel(&u.uz) || Is_airlevel(&u.uz)) { - struct trap *trap; - for (trap = ftrap; trap; trap = trap->ntrap) - if (trap->ttyp == MAGIC_PORTAL) break; + || Is_firelevel(&u.uz) || Is_airlevel(&u.uz)) { + struct trap *trap; + for (trap = ftrap; trap; trap = trap->ntrap) + if (trap->ttyp == MAGIC_PORTAL) + break; - putstr(win, 0, ""); - if (trap) - Sprintf(buf, "Portal @ (%d,%d), hero @ (%d,%d)", - trap->tx, trap->ty, u.ux, u.uy); - else - Sprintf(buf, "No portal found."); - putstr(win, 0, buf); + putstr(win, 0, ""); + if (trap) + Sprintf(buf, "Portal @ (%d,%d), hero @ (%d,%d)", trap->tx, + trap->ty, u.ux, u.uy); + else + Sprintf(buf, "No portal found."); + putstr(win, 0, buf); } display_nhwindow(win, TRUE); @@ -1818,33 +1864,37 @@ xchar *rdgn; * This function should not be called for a transition done via level * teleport or via the Eye. */ -void +void recbranch_mapseen(source, dest) d_level *source; d_level *dest; { mapseen *mptr; - branch* br; + branch *br; /* not a branch */ - if (source->dnum == dest->dnum) return; + if (source->dnum == dest->dnum) + return; /* we only care about forward branches */ for (br = branches; br; br = br->next) { - if (on_level(source, &br->end1) && on_level(dest, &br->end2)) break; - if (on_level(source, &br->end2) && on_level(dest, &br->end1)) return; + if (on_level(source, &br->end1) && on_level(dest, &br->end2)) + break; + if (on_level(source, &br->end2) && on_level(dest, &br->end1)) + return; } /* branch not found, so not a real branch. */ - if (!br) return; + if (!br) + return; if ((mptr = find_mapseen(source)) != 0) { - if (mptr->br && br != mptr->br) - impossible("Two branches on the same level?"); - mptr->br = br; + if (mptr->br && br != mptr->br) + impossible("Two branches on the same level?"); + mptr->br = br; } else { - impossible("Can't note branch for unseen level (%d, %d)", - source->dnum, source->dlevel); + impossible("Can't note branch for unseen level (%d, %d)", + source->dnum, source->dlevel); } } @@ -1854,7 +1904,7 @@ d_level *lev; { mapseen *mptr; if ((mptr = find_mapseen(lev))) - return mptr->custom; + return mptr->custom; return NULL; } @@ -1863,30 +1913,32 @@ int donamelevel() { mapseen *mptr; - char nbuf[BUFSZ]; /* Buffer for response */ + char nbuf[BUFSZ]; /* Buffer for response */ - if (!(mptr = find_mapseen(&u.uz))) return 0; + if (!(mptr = find_mapseen(&u.uz))) + return 0; if (mptr->custom) { - char tmpbuf[BUFSZ]; - Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", - mptr->custom, strlen(mptr->custom) > 30 ? "..." : ""); - getlin(tmpbuf, nbuf); + char tmpbuf[BUFSZ]; + Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom, + strlen(mptr->custom) > 30 ? "..." : ""); + getlin(tmpbuf, nbuf); } else - getlin("What do you want to call this dungeon level?", nbuf); - if (index(nbuf, '\033')) return 0; - (void)mungspaces(nbuf); + getlin("What do you want to call this dungeon level?", nbuf); + if (index(nbuf, '\033')) + return 0; + (void) mungspaces(nbuf); /* discard old annotation, if any */ if (mptr->custom) { - free((genericptr_t)mptr->custom); - mptr->custom = (char *)0; - mptr->custom_lth = 0; + free((genericptr_t) mptr->custom); + mptr->custom = (char *) 0; + mptr->custom_lth = 0; } /* add new annotation, unless it's empty or a single space */ if (*nbuf && strcmp(nbuf, " ")) { - mptr->custom = dupstr(nbuf); - mptr->custom_lth = strlen(mptr->custom); + mptr->custom = dupstr(nbuf); + mptr->custom_lth = strlen(mptr->custom); } return 0; } @@ -1899,7 +1951,8 @@ d_level *lev; mapseen *mptr; for (mptr = mapseenchn; mptr; mptr = mptr->next) - if (on_level(&(mptr->lev), lev)) break; + if (on_level(&(mptr->lev), lev)) + break; return mptr; } @@ -1912,23 +1965,24 @@ int ledger_num; struct cemetery *bp; for (mptr = mapseenchn; mptr; mptr = mptr->next) - if (dungeons[mptr->lev.dnum].ledger_start + - mptr->lev.dlevel == ledger_num) break; + if (dungeons[mptr->lev.dnum].ledger_start + mptr->lev.dlevel + == ledger_num) + break; /* if not found, then nothing to forget */ if (mptr) { - mptr->flags.forgot = 1; - mptr->br = (branch *)0; + mptr->flags.forgot = 1; + mptr->br = (branch *) 0; - /* custom names are erased, not just forgotten until revisted */ - if (mptr->custom) { - mptr->custom_lth = 0; - free((genericptr_t)mptr->custom); - mptr->custom = (char *)0; - } - (void) memset((genericptr_t) mptr->msrooms, 0, sizeof mptr->msrooms); - for (bp = mptr->final_resting_place; bp; bp = bp->next) - bp->bonesknown = FALSE; + /* custom names are erased, not just forgotten until revisted */ + if (mptr->custom) { + mptr->custom_lth = 0; + free((genericptr_t) mptr->custom); + mptr->custom = (char *) 0; + } + (void) memset((genericptr_t) mptr->msrooms, 0, sizeof mptr->msrooms); + for (bp = mptr->final_resting_place; bp; bp = bp->next) + bp->bonesknown = FALSE; } } @@ -1941,7 +1995,8 @@ mapseen *mptr; int brindx; for (brindx = 0, curr = branches; curr; curr = curr->next, ++brindx) - if (curr == mptr->br) break; + if (curr == mptr->br) + break; bwrite(fd, (genericptr_t) &brindx, sizeof brindx); bwrite(fd, (genericptr_t) &mptr->lev, sizeof mptr->lev); @@ -1949,7 +2004,7 @@ mapseen *mptr; bwrite(fd, (genericptr_t) &mptr->flags, sizeof mptr->flags); bwrite(fd, (genericptr_t) &mptr->custom_lth, sizeof mptr->custom_lth); if (mptr->custom_lth) - bwrite(fd, (genericptr_t) mptr->custom, mptr->custom_lth); + bwrite(fd, (genericptr_t) mptr->custom, mptr->custom_lth); bwrite(fd, (genericptr_t) &mptr->msrooms, sizeof mptr->msrooms); savecemetery(fd, WRITE_SAVE, &mptr->final_resting_place); } @@ -1966,7 +2021,8 @@ int fd; mread(fd, (genericptr_t) &branchnum, sizeof branchnum); for (brindx = 0, curr = branches; curr; curr = curr->next, ++brindx) - if (brindx == branchnum) break; + if (brindx == branchnum) + break; load->br = curr; mread(fd, (genericptr_t) &load->lev, sizeof load->lev); @@ -1974,12 +2030,12 @@ int fd; mread(fd, (genericptr_t) &load->flags, sizeof load->flags); mread(fd, (genericptr_t) &load->custom_lth, sizeof load->custom_lth); if (load->custom_lth) { - /* length doesn't include terminator (which isn't saved & restored) */ - load->custom = (char *) alloc(load->custom_lth + 1); - mread(fd, (genericptr_t) load->custom, load->custom_lth); - load->custom[load->custom_lth] = '\0'; + /* length doesn't include terminator (which isn't saved & restored) */ + load->custom = (char *) alloc(load->custom_lth + 1); + mread(fd, (genericptr_t) load->custom, load->custom_lth); + load->custom[load->custom_lth] = '\0'; } else - load->custom = 0; + load->custom = 0; mread(fd, (genericptr_t) &load->msrooms, sizeof load->msrooms); restcemetery(fd, &load->final_resting_place); @@ -1999,20 +2055,20 @@ int dnum; mptraddr = &mapseenchn; while ((mptr = *mptraddr) != 0) { - if (mptr->lev.dnum == dnum) { -#if 1 /* use this... */ - mptr->flags.unreachable = 1; - } -#else /* old deletion code */ - *mptraddr = mptr->next; - if (mptr->custom) - free((genericptr_t) mptr->custom); - if (mptr->final_resting_place) - savecemetery(-1, FREE_SAVE, &mptr->final_resting_place); - free((genericptr_t) mptr); - } else + if (mptr->lev.dnum == dnum) { +#if 1 /* use this... */ + mptr->flags.unreachable = 1; + } +#else /* old deletion code */ + *mptraddr = mptr->next; + if (mptr->custom) + free((genericptr_t) mptr->custom); + if (mptr->final_resting_place) + savecemetery(-1, FREE_SAVE, &mptr->final_resting_place); + free((genericptr_t) mptr); + } else #endif - mptraddr = &mptr->next; + mptraddr = &mptr->next; } } @@ -2026,76 +2082,72 @@ d_level *lev; mapseen *mptr, *init, *prev; init = (mapseen *) alloc(sizeof *init); - (void) memset((genericptr_t)init, 0, sizeof *init); + (void) memset((genericptr_t) init, 0, sizeof *init); /* memset is fine for feature bits, flags, and rooms array; explicitly initialize pointers to null */ init->next = 0, init->br = 0, init->custom = 0; init->final_resting_place = 0; /* lastseentyp[][] is reused for each level, so get rid of previous level's data */ - (void) memset((genericptr_t)lastseentyp, 0, sizeof lastseentyp); + (void) memset((genericptr_t) lastseentyp, 0, sizeof lastseentyp); init->lev.dnum = lev->dnum; init->lev.dlevel = lev->dlevel; /* walk until we get to the place where we should insert init */ for (mptr = mapseenchn, prev = 0; mptr; prev = mptr, mptr = mptr->next) - if (mptr->lev.dnum > init->lev.dnum || - (mptr->lev.dnum == init->lev.dnum && - mptr->lev.dlevel > init->lev.dlevel)) - break; + if (mptr->lev.dnum > init->lev.dnum + || (mptr->lev.dnum == init->lev.dnum + && mptr->lev.dlevel > init->lev.dlevel)) + break; if (!prev) { - init->next = mapseenchn; - mapseenchn = init; + init->next = mapseenchn; + mapseenchn = init; } else { - mptr = prev->next; - prev->next = init; - init->next = mptr; + mptr = prev->next; + prev->next = init; + init->next = mptr; } } -#define INTEREST(feat) \ - ((feat).nfount || \ - (feat).nsink || \ - (feat).nthrone || \ - (feat).naltar || \ - (feat).ngrave || \ - (feat).ntree || \ - (feat).nshop || \ - (feat).ntemple) - /* - || ((feat).water) || \ - ((feat).ice) || \ - ((feat).lava) - */ +#define INTEREST(feat) \ + ((feat).nfount || (feat).nsink || (feat).nthrone || (feat).naltar \ + || (feat).ngrave || (feat).ntree || (feat).nshop || (feat).ntemple) +/* +|| ((feat).water) || \ +((feat).ice) || \ +((feat).lava) +*/ /* returns true if this level has something interesting to print out */ STATIC_OVL boolean interest_mapseen(mptr) mapseen *mptr; { - if (on_level(&u.uz, &mptr->lev)) return TRUE; - if (mptr->flags.unreachable || mptr->flags.forgot) return FALSE; + if (on_level(&u.uz, &mptr->lev)) + return TRUE; + if (mptr->flags.unreachable || mptr->flags.forgot) + return FALSE; /* level is of interest if it has an auto-generated annotation */ - if (mptr->flags.oracle || mptr->flags.bigroom || - mptr->flags.roguelevel || - mptr->flags.castle || mptr->flags.valley || - mptr->flags.msanctum) return TRUE; + if (mptr->flags.oracle || mptr->flags.bigroom || mptr->flags.roguelevel + || mptr->flags.castle || mptr->flags.valley || mptr->flags.msanctum) + return TRUE; /* when in Sokoban, list all sokoban levels visited; when not in it, list any visited Sokoban level which remains unsolved (could only be furthest one reached, unless level teleporting in wizard mode) */ - if (In_sokoban(&mptr->lev) && - (In_sokoban(&u.uz) || !mptr->flags.sokosolved)) return TRUE; + if (In_sokoban(&mptr->lev) + && (In_sokoban(&u.uz) || !mptr->flags.sokosolved)) + return TRUE; /* when in the endgame, list all endgame levels visited, whether they have annotations or not, so that #overview doesn't become extremely sparse once the rest of the dungeon has been flagged as unreachable */ - if (In_endgame(&u.uz)) return In_endgame(&mptr->lev); + if (In_endgame(&u.uz)) + return In_endgame(&mptr->lev); /* level is of interest if it has non-zero feature count or known bones or user annotation or known connection to another dungeon brancth */ - return (INTEREST(mptr->feat) || - (mptr->final_resting_place && - (mptr->flags.knownbones || wizard)) || - mptr->custom || mptr->br); + return (INTEREST(mptr->feat) || (mptr->final_resting_place + && (mptr->flags.knownbones || wizard)) + || mptr->custom || mptr->br); } /* recalculate mapseen for the current level */ @@ -2114,74 +2166,80 @@ recalc_mapseen() * [Since quest explusion no longer deletes quest mapseen data, * null return from find_mapseen() should now be impossible.] */ - if (!(mptr = find_mapseen(&u.uz))) return; + if (!(mptr = find_mapseen(&u.uz))) + return; /* reset all features; mptr->feat.* = 0; */ (void) memset((genericptr_t) &mptr->feat, 0, sizeof mptr->feat); /* reset most flags; some level-specific ones are left as-is */ if (mptr->flags.unreachable) { - mptr->flags.unreachable = 0; /* reached it; Eye of the Aethiopica? */ - if (In_quest(&u.uz)) { - mapseen *mptrtmp = mapseenchn; + mptr->flags.unreachable = 0; /* reached it; Eye of the Aethiopica? */ + if (In_quest(&u.uz)) { + mapseen *mptrtmp = mapseenchn; - /* when quest was unreachable due to ejection and portal removal, - getting back to it via arti-invoke should revive annotation - data for all quest levels, not just the one we're on now */ - do { - if (mptrtmp->lev.dnum == mptr->lev.dnum) - mptrtmp->flags.unreachable = 0; - mptrtmp = mptrtmp->next; - } while (mptrtmp); - } + /* when quest was unreachable due to ejection and portal removal, + getting back to it via arti-invoke should revive annotation + data for all quest levels, not just the one we're on now */ + do { + if (mptrtmp->lev.dnum == mptr->lev.dnum) + mptrtmp->flags.unreachable = 0; + mptrtmp = mptrtmp->next; + } while (mptrtmp); + } } mptr->flags.knownbones = 0; mptr->flags.sokosolved = In_sokoban(&u.uz) && !Sokoban; /* mptr->flags.bigroom retains previous value when hero can't see */ if (!Blind) - mptr->flags.bigroom = Is_bigroom(&u.uz); + mptr->flags.bigroom = Is_bigroom(&u.uz); else if (mptr->flags.forgot) - mptr->flags.bigroom = 0; + mptr->flags.bigroom = 0; mptr->flags.roguelevel = Is_rogue_level(&u.uz); - mptr->flags.oracle = 0; /* recalculated during room traversal below */ + mptr->flags.oracle = 0; /* recalculated during room traversal below */ mptr->flags.castletune = 0; /* flags.castle, flags.valley, flags.msanctum retain previous value */ mptr->flags.forgot = 0; /* track rooms the hero is in */ for (i = 0; i < SIZE(u.urooms); ++i) { - if (!u.urooms[i]) continue; + if (!u.urooms[i]) + continue; - ridx = u.urooms[i] - ROOMOFFSET; - mptr->msrooms[ridx].seen = 1; - mptr->msrooms[ridx].untended = (rooms[ridx].rtype >= SHOPBASE) ? - (!(mtmp = shop_keeper(u.urooms[i])) || !inhishop(mtmp)) : - (rooms[ridx].rtype == TEMPLE) ? - (!(mtmp = findpriest(u.urooms[i])) || !inhistemple(mtmp)) : - 0; + ridx = u.urooms[i] - ROOMOFFSET; + mptr->msrooms[ridx].seen = 1; + mptr->msrooms[ridx].untended = + (rooms[ridx].rtype >= SHOPBASE) + ? (!(mtmp = shop_keeper(u.urooms[i])) || !inhishop(mtmp)) + : (rooms[ridx].rtype == TEMPLE) + ? (!(mtmp = findpriest(u.urooms[i])) + || !inhistemple(mtmp)) + : 0; } /* recalculate room knowledge: for now, just shops and temples * this could be extended to an array of 0..SHOPBASE */ for (i = 0; i < SIZE(mptr->msrooms); ++i) { - if (mptr->msrooms[i].seen) { - if (rooms[i].rtype >= SHOPBASE) { - if (mptr->msrooms[i].untended) - mptr->feat.shoptype = SHOPBASE - 1; - else if (!mptr->feat.nshop) - mptr->feat.shoptype = rooms[i].rtype; - else if (mptr->feat.shoptype != (unsigned)rooms[i].rtype) - mptr->feat.shoptype = 0; - count = mptr->feat.nshop + 1; - if (count <= 3) mptr->feat.nshop = count; - } else if (rooms[i].rtype == TEMPLE) { - /* altar and temple alignment handled below */ - count = mptr->feat.ntemple + 1; - if (count <= 3) mptr->feat.ntemple = count; - } else if (rooms[i].orig_rtype == DELPHI) { - mptr->flags.oracle = 1; - } - } + if (mptr->msrooms[i].seen) { + if (rooms[i].rtype >= SHOPBASE) { + if (mptr->msrooms[i].untended) + mptr->feat.shoptype = SHOPBASE - 1; + else if (!mptr->feat.nshop) + mptr->feat.shoptype = rooms[i].rtype; + else if (mptr->feat.shoptype != (unsigned) rooms[i].rtype) + mptr->feat.shoptype = 0; + count = mptr->feat.nshop + 1; + if (count <= 3) + mptr->feat.nshop = count; + } else if (rooms[i].rtype == TEMPLE) { + /* altar and temple alignment handled below */ + count = mptr->feat.ntemple + 1; + if (count <= 3) + mptr->feat.ntemple = count; + } else if (rooms[i].orig_rtype == DELPHI) { + mptr->flags.oracle = 1; + } + } } /* Update lastseentyp with typ if and only if it is in sight or the @@ -2203,18 +2261,18 @@ recalc_mapseen() * dungeon glyph (i.e. items on fountains). */ for (x = 1; x < COLNO; x++) { - for (y = 0; y < ROWNO; y++) { - if (cansee(x, y) || (x == u.ux && y == u.uy && !Levitation)) { - ltyp = levl[x][y].typ; - if (ltyp == DRAWBRIDGE_UP) - ltyp = db_under_typ(levl[x][y].drawbridgemask); - if ((mtmp = m_at(x, y)) != 0 && - mtmp->m_ap_type == M_AP_FURNITURE && canseemon(mtmp)) - ltyp = cmap_to_type(mtmp->mappearance); - lastseentyp[x][y] = ltyp; - } + for (y = 0; y < ROWNO; y++) { + if (cansee(x, y) || (x == u.ux && y == u.uy && !Levitation)) { + ltyp = levl[x][y].typ; + if (ltyp == DRAWBRIDGE_UP) + ltyp = db_under_typ(levl[x][y].drawbridgemask); + if ((mtmp = m_at(x, y)) != 0 + && mtmp->m_ap_type == M_AP_FURNITURE && canseemon(mtmp)) + ltyp = cmap_to_type(mtmp->mappearance); + lastseentyp[x][y] = ltyp; + } - switch (lastseentyp[x][y]) { + switch (lastseentyp[x][y]) { #if 0 case ICE: count = mptr->feat.ice + 1; @@ -2231,97 +2289,105 @@ recalc_mapseen() if (count <= 3) mptr->feat.lava = count; break; #endif - case TREE: - count = mptr->feat.ntree + 1; - if (count <= 3) mptr->feat.ntree = count; - break; - case FOUNTAIN: - count = mptr->feat.nfount + 1; - if (count <= 3) mptr->feat.nfount = count; - break; - case THRONE: - count = mptr->feat.nthrone + 1; - if (count <= 3) mptr->feat.nthrone = count; - break; - case SINK: - count = mptr->feat.nsink + 1; - if (count <= 3) mptr->feat.nsink = count; - break; - case GRAVE: - count = mptr->feat.ngrave + 1; - if (count <= 3) mptr->feat.ngrave = count; - break; - case ALTAR: - atmp = Amask2msa(levl[x][y].altarmask); - if (!mptr->feat.naltar) - mptr->feat.msalign = atmp; - else if (mptr->feat.msalign != atmp) - mptr->feat.msalign = MSA_NONE; - count = mptr->feat.naltar + 1; - if (count <= 3) mptr->feat.naltar = count; - break; - /* An automatic annotation is added to the Castle and - * to Fort Ludios once their struncture's main entrance - * has been seen (in person or via magic mapping). - * DOOR: possibly a lowered drawbridge's open portcullis; - * DBWALL: a raised drawbridge's "closed door"; - * DRAWBRIDGE_DOWN: the span provided by lowered bridge, - * with moat or other terrain hidden underneath; - * DRAWBRIDGE_UP: moat in front of a raised drawbridge, - * not recognizable as a bridge location unless/until - * the adjacent DBWALL has been seen. - */ - case DOOR: - if (is_drawbridge_wall(x, y) < 0) break; - /* else FALLTHRU */ - case DBWALL: - case DRAWBRIDGE_DOWN: - if (Is_stronghold(&u.uz)) - mptr->flags.castle = 1, mptr->flags.castletune = 1; - else if (Is_knox(&u.uz)) - mptr->flags.ludios = 1; - break; - default: - break; - } - } + case TREE: + count = mptr->feat.ntree + 1; + if (count <= 3) + mptr->feat.ntree = count; + break; + case FOUNTAIN: + count = mptr->feat.nfount + 1; + if (count <= 3) + mptr->feat.nfount = count; + break; + case THRONE: + count = mptr->feat.nthrone + 1; + if (count <= 3) + mptr->feat.nthrone = count; + break; + case SINK: + count = mptr->feat.nsink + 1; + if (count <= 3) + mptr->feat.nsink = count; + break; + case GRAVE: + count = mptr->feat.ngrave + 1; + if (count <= 3) + mptr->feat.ngrave = count; + break; + case ALTAR: + atmp = Amask2msa(levl[x][y].altarmask); + if (!mptr->feat.naltar) + mptr->feat.msalign = atmp; + else if (mptr->feat.msalign != atmp) + mptr->feat.msalign = MSA_NONE; + count = mptr->feat.naltar + 1; + if (count <= 3) + mptr->feat.naltar = count; + break; + /* An automatic annotation is added to the Castle and + * to Fort Ludios once their struncture's main entrance + * has been seen (in person or via magic mapping). + * DOOR: possibly a lowered drawbridge's open portcullis; + * DBWALL: a raised drawbridge's "closed door"; + * DRAWBRIDGE_DOWN: the span provided by lowered bridge, + * with moat or other terrain hidden underneath; + * DRAWBRIDGE_UP: moat in front of a raised drawbridge, + * not recognizable as a bridge location unless/until + * the adjacent DBWALL has been seen. + */ + case DOOR: + if (is_drawbridge_wall(x, y) < 0) + break; + /* else FALLTHRU */ + case DBWALL: + case DRAWBRIDGE_DOWN: + if (Is_stronghold(&u.uz)) + mptr->flags.castle = 1, mptr->flags.castletune = 1; + else if (Is_knox(&u.uz)) + mptr->flags.ludios = 1; + break; + default: + break; + } + } } if (level.bonesinfo && !mptr->final_resting_place) { - /* clone the bonesinfo so we aren't dependent upon this - level being in memory */ - bonesaddr = &mptr->final_resting_place; - bp = level.bonesinfo; - do { - *bonesaddr = (struct cemetery *)alloc(sizeof **bonesaddr); - **bonesaddr = *bp; - bp = bp->next; - bonesaddr = &(*bonesaddr)->next; - } while (bp); - *bonesaddr = 0; + /* clone the bonesinfo so we aren't dependent upon this + level being in memory */ + bonesaddr = &mptr->final_resting_place; + bp = level.bonesinfo; + do { + *bonesaddr = (struct cemetery *) alloc(sizeof **bonesaddr); + **bonesaddr = *bp; + bp = bp->next; + bonesaddr = &(*bonesaddr)->next; + } while (bp); + *bonesaddr = 0; } /* decide which past hero deaths have become known; there's no guarantee of either a grave or a ghost, so we go by whether the current hero has seen the map location where each old one died */ for (bp = mptr->final_resting_place; bp; bp = bp->next) - if (lastseentyp[bp->frpx][bp->frpy]) { - bp->bonesknown = TRUE; - mptr->flags.knownbones = 1; - } + if (lastseentyp[bp->frpx][bp->frpy]) { + bp->bonesknown = TRUE; + mptr->flags.knownbones = 1; + } } /*ARGUSED*/ -/* valley and sanctum levels get automatic annotation once temple is entered */ +/* valley and sanctum levels get automatic annotation once temple is entered + */ void mapseen_temple(priest) -struct monst *priest UNUSED; /* currently unused; might be useful someday */ +struct monst *priest UNUSED; /* currently unused; might be useful someday */ { mapseen *mptr = find_mapseen(&u.uz); if (Is_valley(&u.uz)) - mptr->flags.valley = 1; + mptr->flags.valley = 1; else if (Is_sanctum(&u.uz)) - mptr->flags.msanctum = 1; + mptr->flags.msanctum = 1; } /* room entry message has just been delivered so learn room even if blind */ @@ -2345,9 +2411,9 @@ dooverview() /* called for #overview or for end of game disclosure */ void show_overview(why, reason) -int why; /* 0 => #overview command, - 1 or 2 => final disclosure (1: hero lived, 2: hero died) */ -int reason; /* how hero died; used when disclosing end-of-game level */ +int why; /* 0 => #overview command, + 1 or 2 => final disclosure (1: hero lived, 2: hero died) */ +int reason; /* how hero died; used when disclosing end-of-game level */ { winid win; int lastdun = -1; @@ -2359,10 +2425,10 @@ int reason; /* how hero died; used when disclosing end-of-game level */ /* show the endgame levels before the rest of the dungeon, so that the Planes (dnum 5-ish) come out above main dungeon (dnum 0) */ if (In_endgame(&u.uz)) - traverse_mapseenchn(TRUE, win, why, reason, &lastdun); + traverse_mapseenchn(TRUE, win, why, reason, &lastdun); /* if game is over or we're not in the endgame yet, show the dungeon */ if (why > 0 || !In_endgame(&u.uz)) - traverse_mapseenchn(FALSE, win, why, reason, &lastdun); + traverse_mapseenchn(FALSE, win, why, reason, &lastdun); display_nhwindow(win, TRUE); destroy_nhwindow(win); } @@ -2378,14 +2444,15 @@ int why, reason, *lastdun_p; boolean showheader; for (mptr = mapseenchn; mptr; mptr = mptr->next) { - if (viewendgame ^ In_endgame(&mptr->lev)) continue; + if (viewendgame ^ In_endgame(&mptr->lev)) + continue; - /* only print out info for a level or a dungeon if interest */ - if (why > 0 || interest_mapseen(mptr)) { - showheader = (boolean)(mptr->lev.dnum != *lastdun_p); - print_mapseen(win, mptr, why, reason, showheader); - *lastdun_p = mptr->lev.dnum; - } + /* only print out info for a level or a dungeon if interest */ + if (why > 0 || interest_mapseen(mptr)) { + showheader = (boolean)(mptr->lev.dnum != *lastdun_p); + print_mapseen(win, mptr, why, reason, showheader); + *lastdun_p = mptr->lev.dnum; + } } } @@ -2396,11 +2463,15 @@ const char *obj; { /* players are computer scientists: 0, 1, 2, n */ switch (x) { - case 0: return "no"; - /* an() returns too much. index is ok in this case */ - case 1: return index(vowels, *obj) ? "an" : "a"; - case 2: return "some"; - case 3: return "many"; + case 0: + return "no"; + /* an() returns too much. index is ok in this case */ + case 1: + return index(vowels, *obj) ? "an" : "a"; + case 2: + return "some"; + case 3: + return "many"; } return "(unknown)"; @@ -2412,15 +2483,18 @@ br_string2(br) branch *br; { /* Special case: quest portal says closed if kicked from quest */ - boolean closed_portal = - (br->end2.dnum == quest_dnum && u.uevent.qexpelled); + boolean closed_portal = + (br->end2.dnum == quest_dnum && u.uevent.qexpelled); switch (br->type) { - case BR_PORTAL: return closed_portal ? "Sealed portal" : "Portal"; - case BR_NO_END1: return "Connection"; - case BR_NO_END2: return (br->end1_up) ? "One way stairs up" : - "One way stairs down"; - case BR_STAIR: return (br->end1_up) ? "Stairs up" : "Stairs down"; + case BR_PORTAL: + return closed_portal ? "Sealed portal" : "Portal"; + case BR_NO_END1: + return "Connection"; + case BR_NO_END2: + return (br->end1_up) ? "One way stairs up" : "One way stairs down"; + case BR_STAIR: + return (br->end1_up) ? "Stairs up" : "Stairs down"; } return "(unknown)"; @@ -2436,16 +2510,26 @@ int indx; *outbuf = '\0'; switch (indx) { - case -5: Strcpy(outbuf, "Astral Plane"); break; - case -4: planename = "Water"; break; - case -3: planename = "Fire"; break; - case -2: planename = "Air"; break; - case -1: planename = "Earth"; break; + case -5: + Strcpy(outbuf, "Astral Plane"); + break; + case -4: + planename = "Water"; + break; + case -3: + planename = "Fire"; + break; + case -2: + planename = "Air"; + break; + case -1: + planename = "Earth"; + break; } if (planename) - Sprintf(outbuf, "Plane of %s", planename); + Sprintf(outbuf, "Plane of %s", planename); else if (!*outbuf) - Sprintf(outbuf, "unknown plane #%d", indx); + Sprintf(outbuf, "unknown plane #%d", indx); return outbuf; } @@ -2453,23 +2537,48 @@ STATIC_OVL const char * shop_string(rtype) int rtype; { - const char *str = "shop"; /* catchall */ + const char *str = "shop"; /* catchall */ /* Yuck, redundancy...but shclass.name doesn't cut it as a noun */ switch (rtype) { - case SHOPBASE - 1: str = "untended shop"; break; /* see recalc_mapseen */ - case SHOPBASE: str = "general store"; break; - case ARMORSHOP: str = "armor shop"; break; - case SCROLLSHOP: str = "scroll shop"; break; - case POTIONSHOP: str = "potion shop"; break; - case WEAPONSHOP: str = "weapon shop"; break; - case FOODSHOP: str = "delicatessen"; break; - case RINGSHOP: str = "jewelers"; break; - case WANDSHOP: str = "wand shop"; break; - case BOOKSHOP: str = "bookstore"; break; - case FODDERSHOP: str = "health food store"; break; - case CANDLESHOP: str = "lighting shop"; break; - default: break; + case SHOPBASE - 1: + str = "untended shop"; + break; /* see recalc_mapseen */ + case SHOPBASE: + str = "general store"; + break; + case ARMORSHOP: + str = "armor shop"; + break; + case SCROLLSHOP: + str = "scroll shop"; + break; + case POTIONSHOP: + str = "potion shop"; + break; + case WEAPONSHOP: + str = "weapon shop"; + break; + case FOODSHOP: + str = "delicatessen"; + break; + case RINGSHOP: + str = "jewelers"; + break; + case WANDSHOP: + str = "wand shop"; + break; + case BOOKSHOP: + str = "bookstore"; + break; + case FODDERSHOP: + str = "health food store"; + break; + case CANDLESHOP: + str = "lighting shop"; + break; + default: + break; } return str; } @@ -2483,45 +2592,46 @@ char *outbuf; { *outbuf = '\0'; if (mptr->flags.castletune && u.uevent.uheard_tune) { - char tmp[BUFSZ]; + char tmp[BUFSZ]; - if (u.uevent.uheard_tune == 2) - Sprintf(tmp, "notes \"%s\"", tune); - else - Strcpy(tmp, "5-note tune"); - Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp); + if (u.uevent.uheard_tune == 2) + Sprintf(tmp, "notes \"%s\"", tune); + else + Strcpy(tmp, "5-note tune"); + Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp); } return outbuf; } /* some utility macros for print_mapseen */ -#define TAB " " /* three spaces */ +#define TAB " " /* three spaces */ #if 0 -#define BULLET "" /* empty; otherwise output becomes cluttered */ +#define BULLET "" /* empty; otherwise output becomes cluttered */ #define PREFIX TAB TAB BULLET -#else /*!0*/ +#else /*!0*/ /* K&R: don't require support for concatenation of adjacent string literals */ -#define PREFIX " " /* two TABs + empty BULLET: six spaces */ +#define PREFIX " " /* two TABs + empty BULLET: six spaces */ #endif #define COMMA (i++ > 0 ? ", " : PREFIX) /* "iterate" once; safe to use as ``if (cond) ADDTOBUF(); else whatever;'' */ -#define ADDNTOBUF(nam,var) do { \ - if (var) \ - Sprintf(eos(buf), "%s%s %s%s", \ - COMMA, seen_string((var), (nam)), \ - (nam), plur(var)); \ - } while (0) -#define ADDTOBUF(nam,var) do { \ - if (var) \ - Sprintf(eos(buf), "%s%s", COMMA, (nam)); \ - } while (0) +#define ADDNTOBUF(nam, var) \ + do { \ + if (var) \ + Sprintf(eos(buf), "%s%s %s%s", COMMA, seen_string((var), (nam)), \ + (nam), plur(var)); \ + } while (0) +#define ADDTOBUF(nam, var) \ + do { \ + if (var) \ + Sprintf(eos(buf), "%s%s", COMMA, (nam)); \ + } while (0) STATIC_OVL void print_mapseen(win, mptr, final, how, printdun) winid win; mapseen *mptr; -int final; /* 0: not final; 1: game over, alive; 2: game over, dead */ -int how; /* cause of death; only used if final==2 and mptr->lev==u.uz */ +int final; /* 0: not final; 1: game over, alive; 2: game over, dead */ +int how; /* cause of death; only used if final==2 and mptr->lev==u.uz */ boolean printdun; { char buf[BUFSZ], tmpbuf[BUFSZ]; @@ -2533,169 +2643,173 @@ boolean printdun; * other text. */ if (mptr->lev.dnum == quest_dnum || mptr->lev.dnum == knox_level.dnum) - depthstart = 1; + depthstart = 1; else - depthstart = dungeons[mptr->lev.dnum].depth_start; + depthstart = dungeons[mptr->lev.dnum].depth_start; if (printdun) { - /* Sokoban lies about dunlev_ureached and we should - * suppress the negative numbers in the endgame. - */ - if (dungeons[mptr->lev.dnum].dunlev_ureached == 1 || - mptr->lev.dnum == sokoban_dnum || In_endgame(&mptr->lev)) - Sprintf(buf, "%s:", dungeons[mptr->lev.dnum].dname); - else - Sprintf(buf, "%s: levels %d to %d", - dungeons[mptr->lev.dnum].dname, depthstart, - depthstart + dungeons[mptr->lev.dnum].dunlev_ureached - 1); - putstr(win, !final ? ATR_INVERSE : 0, buf); + /* Sokoban lies about dunlev_ureached and we should + * suppress the negative numbers in the endgame. + */ + if (dungeons[mptr->lev.dnum].dunlev_ureached == 1 + || mptr->lev.dnum == sokoban_dnum || In_endgame(&mptr->lev)) + Sprintf(buf, "%s:", dungeons[mptr->lev.dnum].dname); + else + Sprintf(buf, "%s: levels %d to %d", + dungeons[mptr->lev.dnum].dname, depthstart, + depthstart + dungeons[mptr->lev.dnum].dunlev_ureached + - 1); + putstr(win, !final ? ATR_INVERSE : 0, buf); } /* calculate level number */ i = depthstart + mptr->lev.dlevel - 1; if (In_endgame(&mptr->lev)) - Sprintf(buf, "%s%s:", TAB, endgamelevelname(tmpbuf, i)); + Sprintf(buf, "%s%s:", TAB, endgamelevelname(tmpbuf, i)); else - /* FIXME: when this branch has only one level (Ft.Ludios), - * listing "Level 1:" for it might confuse inexperienced - * players into thinking there's more than one. - */ - Sprintf(buf, "%sLevel %d:", TAB, i); - + /* FIXME: when this branch has only one level (Ft.Ludios), + * listing "Level 1:" for it might confuse inexperienced + * players into thinking there's more than one. + */ + Sprintf(buf, "%sLevel %d:", TAB, i); + /* wizmode prints out proto dungeon names for clarity */ if (wizard) { - s_level *slev; + s_level *slev; - if ((slev = Is_special(&mptr->lev)) != 0) - Sprintf(eos(buf), " [%s]", slev->proto); + if ((slev = Is_special(&mptr->lev)) != 0) + Sprintf(eos(buf), " [%s]", slev->proto); } /* [perhaps print custom annotation on its own line when it's long] */ if (mptr->custom) - Sprintf(eos(buf), " (%s)", mptr->custom); + Sprintf(eos(buf), " (%s)", mptr->custom); if (on_level(&u.uz, &mptr->lev)) - Sprintf(eos(buf), " <- You %s here.", - (!final || (final == 1 && how == ASCENDED)) ? "are" : "were"); + Sprintf(eos(buf), " <- You %s here.", + (!final || (final == 1 && how == ASCENDED)) ? "are" : "were"); putstr(win, !final ? ATR_BOLD : 0, buf); - if (mptr->flags.forgot) return; + if (mptr->flags.forgot) + return; if (INTEREST(mptr->feat)) { - buf[0] = 0; - - i = 0; /* interest counter */ - /* List interests in an order vaguely corresponding to - * how important they are. - */ - if (mptr->feat.nshop > 0) { - if (mptr->feat.nshop > 1) - ADDNTOBUF("shop", mptr->feat.nshop); - else - Sprintf(eos(buf), "%s%s", COMMA, - an(shop_string(mptr->feat.shoptype))); - } - if (mptr->feat.naltar > 0) { - /* Temples + non-temple altars get munged into just "altars" */ - if (mptr->feat.ntemple != mptr->feat.naltar) - ADDNTOBUF("altar", mptr->feat.naltar); - else - ADDNTOBUF("temple", mptr->feat.ntemple); + buf[0] = 0; - /* only print out altar's god if they are all to your god */ - if (Amask2align(Msa2amask(mptr->feat.msalign)) == u.ualign.type) - Sprintf(eos(buf), " to %s", align_gname(u.ualign.type)); - } - ADDNTOBUF("throne", mptr->feat.nthrone); - ADDNTOBUF("fountain", mptr->feat.nfount); - ADDNTOBUF("sink", mptr->feat.nsink); - ADDNTOBUF("grave", mptr->feat.ngrave); - ADDNTOBUF("tree", mptr->feat.ntree); + i = 0; /* interest counter */ + /* List interests in an order vaguely corresponding to + * how important they are. + */ + if (mptr->feat.nshop > 0) { + if (mptr->feat.nshop > 1) + ADDNTOBUF("shop", mptr->feat.nshop); + else + Sprintf(eos(buf), "%s%s", COMMA, + an(shop_string(mptr->feat.shoptype))); + } + if (mptr->feat.naltar > 0) { + /* Temples + non-temple altars get munged into just "altars" */ + if (mptr->feat.ntemple != mptr->feat.naltar) + ADDNTOBUF("altar", mptr->feat.naltar); + else + ADDNTOBUF("temple", mptr->feat.ntemple); + + /* only print out altar's god if they are all to your god */ + if (Amask2align(Msa2amask(mptr->feat.msalign)) == u.ualign.type) + Sprintf(eos(buf), " to %s", align_gname(u.ualign.type)); + } + ADDNTOBUF("throne", mptr->feat.nthrone); + ADDNTOBUF("fountain", mptr->feat.nfount); + ADDNTOBUF("sink", mptr->feat.nsink); + ADDNTOBUF("grave", mptr->feat.ngrave); + ADDNTOBUF("tree", mptr->feat.ntree); #if 0 ADDTOBUF("water", mptr->feat.water); ADDTOBUF("lava", mptr->feat.lava); ADDTOBUF("ice", mptr->feat.ice); #endif - /* capitalize afterwards */ - i = strlen(PREFIX); - buf[i] = highc(buf[i]); - /* capitalizing it makes it a sentence; terminate with '.' */ - Strcat(buf, "."); - putstr(win, 0, buf); + /* capitalize afterwards */ + i = strlen(PREFIX); + buf[i] = highc(buf[i]); + /* capitalizing it makes it a sentence; terminate with '.' */ + Strcat(buf, "."); + putstr(win, 0, buf); } /* we assume that these are mutually exclusive */ *buf = '\0'; if (mptr->flags.oracle) { - Sprintf(buf, "%sOracle of Delphi.", PREFIX); + Sprintf(buf, "%sOracle of Delphi.", PREFIX); } else if (In_sokoban(&mptr->lev)) { - Sprintf(buf, "%s%s.", PREFIX, - mptr->flags.sokosolved ? "Solved" : "Unsolved"); + Sprintf(buf, "%s%s.", PREFIX, + mptr->flags.sokosolved ? "Solved" : "Unsolved"); } else if (mptr->flags.bigroom) { - Sprintf(buf, "%sA very big room.", PREFIX); + Sprintf(buf, "%sA very big room.", PREFIX); } else if (mptr->flags.roguelevel) { - Sprintf(buf, "%sA primitive area.", PREFIX); + Sprintf(buf, "%sA primitive area.", PREFIX); } else if (on_level(&mptr->lev, &qstart_level)) { - Sprintf(buf, "%sHome%s.", PREFIX, - mptr->flags.unreachable ? " (no way back...)" : ""); + Sprintf(buf, "%sHome%s.", PREFIX, + mptr->flags.unreachable ? " (no way back...)" : ""); } else if (mptr->flags.ludios) { - /* presence of the ludios branch in #overview output indicates that - the player has made it onto the level; presence of this annotation - indicates that the fort's entrance has been seen (or mapped) */ - Sprintf(buf, "%sFort Ludios.", PREFIX); + /* presence of the ludios branch in #overview output indicates that + the player has made it onto the level; presence of this annotation + indicates that the fort's entrance has been seen (or mapped) */ + Sprintf(buf, "%sFort Ludios.", PREFIX); } else if (mptr->flags.castle) { - Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf)); + Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf)); } else if (mptr->flags.valley) { - Sprintf(buf, "%sValley of the Dead.", PREFIX); + Sprintf(buf, "%sValley of the Dead.", PREFIX); } else if (mptr->flags.msanctum) { - Sprintf(buf, "%sMoloch's Sanctum.", PREFIX); + Sprintf(buf, "%sMoloch's Sanctum.", PREFIX); } - if (*buf) putstr(win, 0, buf); + if (*buf) + putstr(win, 0, buf); /* print out branches */ if (mptr->br) { - Sprintf(buf, "%s%s to %s", PREFIX, br_string2(mptr->br), - dungeons[mptr->br->end2.dnum].dname); + Sprintf(buf, "%s%s to %s", PREFIX, br_string2(mptr->br), + dungeons[mptr->br->end2.dnum].dname); - /* Since mapseen objects are printed out in increasing order - * of dlevel, clarify which level this branch is going to - * if the branch goes upwards. Unless it's the end game. - */ - if (mptr->br->end1_up && !In_endgame(&(mptr->br->end2))) - Sprintf(eos(buf), ", level %d", depth(&(mptr->br->end2))); - Strcat(buf, "."); - putstr(win, 0, buf); + /* Since mapseen objects are printed out in increasing order + * of dlevel, clarify which level this branch is going to + * if the branch goes upwards. Unless it's the end game. + */ + if (mptr->br->end1_up && !In_endgame(&(mptr->br->end2))) + Sprintf(eos(buf), ", level %d", depth(&(mptr->br->end2))); + Strcat(buf, "."); + putstr(win, 0, buf); } /* maybe print out bones details */ if (mptr->final_resting_place || final) { - struct cemetery *bp; - int kncnt = !died_here ? 0 : 1; + struct cemetery *bp; + int kncnt = !died_here ? 0 : 1; - for (bp = mptr->final_resting_place; bp; bp = bp->next) - if (bp->bonesknown || wizard || final) ++kncnt; - if (kncnt) { - Sprintf(buf, "%s%s", PREFIX, "Final resting place for"); - putstr(win, 0, buf); - if (died_here) { - /* disclosure occurs before bones creation, so listing dead - hero here doesn't give away whether bones are produced */ - formatkiller(tmpbuf, sizeof tmpbuf, how); - /* rephrase a few death reasons to work with "you" */ - (void) strsubst(tmpbuf, " himself", " yourself"); - (void) strsubst(tmpbuf, " herself", " yourself"); - (void) strsubst(tmpbuf, " his ", " your "); - (void) strsubst(tmpbuf, " her ", " your "); - Sprintf(buf, "%s%syou, %s%c", PREFIX, TAB, - tmpbuf, --kncnt ? ',' : '.'); - putstr(win, 0, buf); - } - for (bp = mptr->final_resting_place; bp; bp = bp->next) { - if (bp->bonesknown || wizard || final) { - Sprintf(buf, "%s%s%s, %s%c", PREFIX, TAB, - bp->who, bp->how, --kncnt ? ',' : '.'); - putstr(win, 0, buf); - } - } - } + for (bp = mptr->final_resting_place; bp; bp = bp->next) + if (bp->bonesknown || wizard || final) + ++kncnt; + if (kncnt) { + Sprintf(buf, "%s%s", PREFIX, "Final resting place for"); + putstr(win, 0, buf); + if (died_here) { + /* disclosure occurs before bones creation, so listing dead + hero here doesn't give away whether bones are produced */ + formatkiller(tmpbuf, sizeof tmpbuf, how); + /* rephrase a few death reasons to work with "you" */ + (void) strsubst(tmpbuf, " himself", " yourself"); + (void) strsubst(tmpbuf, " herself", " yourself"); + (void) strsubst(tmpbuf, " his ", " your "); + (void) strsubst(tmpbuf, " her ", " your "); + Sprintf(buf, "%s%syou, %s%c", PREFIX, TAB, tmpbuf, + --kncnt ? ',' : '.'); + putstr(win, 0, buf); + } + for (bp = mptr->final_resting_place; bp; bp = bp->next) { + if (bp->bonesknown || wizard || final) { + Sprintf(buf, "%s%s%s, %s%c", PREFIX, TAB, bp->who, + bp->how, --kncnt ? ',' : '.'); + putstr(win, 0, buf); + } + } + } } } diff --git a/src/eat.c b/src/eat.c index e93ea73af..def2af52b 100644 --- a/src/eat.c +++ b/src/eat.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 eat.c $NHDT-Date: 1426465435 2015/03/16 00:23:55 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.123 $ */ +/* NetHack 3.6 eat.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.142 $ */ /* NetHack 3.6 eat.c $Date: 2012/02/01 00:49:16 $ $Revision: 1.116 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,15 +11,15 @@ STATIC_PTR void FDECL(costly_tin, (int)); STATIC_PTR int NDECL(opentin); STATIC_PTR int NDECL(unfaint); -STATIC_DCL const char *FDECL(food_xname, (struct obj *,BOOLEAN_P)); +STATIC_DCL const char *FDECL(food_xname, (struct obj *, BOOLEAN_P)); STATIC_DCL void FDECL(choke, (struct obj *)); STATIC_DCL void NDECL(recalc_wt); STATIC_DCL struct obj *FDECL(touchfood, (struct obj *)); STATIC_DCL void NDECL(do_reset_eat); STATIC_DCL void FDECL(done_eating, (BOOLEAN_P)); STATIC_DCL void FDECL(cprefx, (int)); -STATIC_DCL int FDECL(intrinsic_possible, (int,struct permonst *)); -STATIC_DCL void FDECL(givit, (int,struct permonst *)); +STATIC_DCL int FDECL(intrinsic_possible, (int, struct permonst *)); +STATIC_DCL void FDECL(givit, (int, struct permonst *)); STATIC_DCL void FDECL(cpostfx, (int)); STATIC_DCL void FDECL(consume_tin, (const char *)); STATIC_DCL void FDECL(start_tin, (struct obj *)); @@ -31,12 +31,12 @@ STATIC_DCL int NDECL(bite); STATIC_DCL int FDECL(edibility_prompts, (struct obj *)); STATIC_DCL int FDECL(rottenfood, (struct obj *)); STATIC_DCL void NDECL(eatspecial); -STATIC_DCL int FDECL(bounded_increase, (int,int,int)); +STATIC_DCL int FDECL(bounded_increase, (int, int, int)); STATIC_DCL void FDECL(accessory_has_effect, (struct obj *)); STATIC_DCL void FDECL(eataccessory, (struct obj *)); STATIC_DCL const char *FDECL(foodword, (struct obj *)); -STATIC_DCL int FDECL(tin_variety, (struct obj *,BOOLEAN_P)); -STATIC_DCL boolean FDECL(maybe_cannibal, (int,BOOLEAN_P)); +STATIC_DCL int FDECL(tin_variety, (struct obj *, BOOLEAN_P)); +STATIC_DCL boolean FDECL(maybe_cannibal, (int, BOOLEAN_P)); char msgbuf[BUFSZ]; @@ -48,35 +48,31 @@ char msgbuf[BUFSZ]; /* Rider corpses are treated as non-rotting so that attempting to eat one will be sure to reach the stage of eating where that meal is fatal */ -#define nonrotting_corpse(mnum) ((mnum) == PM_LIZARD || \ - (mnum) == PM_LICHEN || \ - is_rider(&mons[mnum])) +#define nonrotting_corpse(mnum) \ + ((mnum) == PM_LIZARD || (mnum) == PM_LICHEN || is_rider(&mons[mnum])) /* non-rotting non-corpses; unlike lizard corpses, these items will behave as if rotten if they are cursed (fortune cookies handled elsewhere) */ -#define nonrotting_food(otyp) ((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION) +#define nonrotting_food(otyp) \ + ((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION) STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 }; -STATIC_OVL NEARDATA const char offerfodder[] = { FOOD_CLASS, AMULET_CLASS, 0 }; +STATIC_OVL NEARDATA const char offerfodder[] = { FOOD_CLASS, AMULET_CLASS, + 0 }; /* Gold must come first for getobj(). */ STATIC_OVL NEARDATA const char allobj[] = { - COIN_CLASS, WEAPON_CLASS, ARMOR_CLASS, POTION_CLASS, SCROLL_CLASS, - WAND_CLASS, RING_CLASS, AMULET_CLASS, FOOD_CLASS, TOOL_CLASS, - GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, SPBOOK_CLASS, 0 }; + COIN_CLASS, WEAPON_CLASS, ARMOR_CLASS, POTION_CLASS, + SCROLL_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS, + FOOD_CLASS, TOOL_CLASS, GEM_CLASS, ROCK_CLASS, + BALL_CLASS, CHAIN_CLASS, SPBOOK_CLASS, 0 +}; STATIC_OVL boolean force_save_hs = FALSE; /* see hunger states in hack.h - texts used on bottom line */ -const char *hu_stat[] = { - "Satiated", - " ", - "Hungry ", - "Weak ", - "Fainting", - "Fainted ", - "Starved " -}; +const char *hu_stat[] = { "Satiated", " ", "Hungry ", "Weak ", + "Fainting", "Fainted ", "Starved " }; /* * Decide whether a particular object can be eaten by the possibly @@ -86,114 +82,111 @@ boolean is_edible(obj) register struct obj *obj; { - /* protect invocation tools but not Rider corpses (handled elsewhere)*/ - /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */ - if (objects[obj->otyp].oc_unique) - return FALSE; - /* above also prevents the Amulet from being eaten, so we must never - allow fake amulets to be eaten either [which is already the case] */ + /* protect invocation tools but not Rider corpses (handled elsewhere)*/ + /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */ + if (objects[obj->otyp].oc_unique) + return FALSE; + /* above also prevents the Amulet from being eaten, so we must never + allow fake amulets to be eaten either [which is already the case] */ - if (metallivorous(youmonst.data) && is_metallic(obj) && - (youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj))) - return TRUE; - if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) && - /* [g.cubes can eat containers and retain all contents - as engulfed items, but poly'd player can't do that] */ - !Has_contents(obj)) - return TRUE; + if (metallivorous(youmonst.data) && is_metallic(obj) + && (youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj))) + return TRUE; + if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) && + /* [g.cubes can eat containers and retain all contents + as engulfed items, but poly'd player can't do that] */ + !Has_contents(obj)) + return TRUE; - /* return((boolean)(!!index(comestibles, obj->oclass))); */ - return (boolean)(obj->oclass == FOOD_CLASS); + /* return((boolean)(!!index(comestibles, obj->oclass))); */ + return (boolean)(obj->oclass == FOOD_CLASS); } void init_uhunger() { - u.uhunger = 900; - u.uhs = NOT_HUNGRY; + u.uhunger = 900; + u.uhs = NOT_HUNGRY; } /* tin types [SPINACH_TIN = -1, overrides corpsenm, nut==600] */ static const struct { - const char *txt; /* description */ - int nut; /* nutrition */ - Bitfield(fodder,1); /* stocked by health food shops */ - Bitfield(greasy,1); /* causes slippery fingers */ -} tintxts[] = { - {"rotten", -50, 0, 0}, /* ROTTEN_TIN = 0 */ - {"homemade", 50, 1, 0}, /* HOMEMADE_TIN = 1 */ - {"soup made from", 20, 1, 0}, - {"french fried", 40, 0, 1}, - {"pickled", 40, 1, 0}, - {"boiled", 50, 1, 0}, - {"smoked", 50, 1, 0}, - {"dried", 55, 1, 0}, - {"deep fried", 60, 0, 1}, - {"szechuan", 70, 1, 0}, - {"broiled", 80, 0, 0}, - {"stir fried", 80, 0, 1}, - {"sauteed", 95, 0, 0}, - {"candied", 100, 1, 0}, - {"pureed", 500, 1, 0}, - {"", 0, 0, 0} -}; -#define TTSZ SIZE(tintxts) + const char *txt; /* description */ + int nut; /* nutrition */ + Bitfield(fodder, 1); /* stocked by health food shops */ + Bitfield(greasy, 1); /* causes slippery fingers */ +} tintxts[] = { { "rotten", -50, 0, 0 }, /* ROTTEN_TIN = 0 */ + { "homemade", 50, 1, 0 }, /* HOMEMADE_TIN = 1 */ + { "soup made from", 20, 1, 0 }, + { "french fried", 40, 0, 1 }, + { "pickled", 40, 1, 0 }, + { "boiled", 50, 1, 0 }, + { "smoked", 50, 1, 0 }, + { "dried", 55, 1, 0 }, + { "deep fried", 60, 0, 1 }, + { "szechuan", 70, 1, 0 }, + { "broiled", 80, 0, 0 }, + { "stir fried", 80, 0, 1 }, + { "sauteed", 95, 0, 0 }, + { "candied", 100, 1, 0 }, + { "pureed", 500, 1, 0 }, + { "", 0, 0, 0 } }; +#define TTSZ SIZE(tintxts) -static char *eatmbuf = 0; /* set by cpostfx() */ +static char *eatmbuf = 0; /* set by cpostfx() */ STATIC_PTR -int -eatmdone(VOID_ARGS) /* called after mimicing is over */ +int eatmdone(VOID_ARGS) /* called after mimicing is over */ { - /* release `eatmbuf' */ - if (eatmbuf) { - if (nomovemsg == eatmbuf) nomovemsg = 0; - free((genericptr_t)eatmbuf), eatmbuf = 0; - } - /* update display */ - if (youmonst.m_ap_type) { - youmonst.m_ap_type = M_AP_NOTHING; - newsym(u.ux,u.uy); - } - return 0; + /* release `eatmbuf' */ + if (eatmbuf) { + if (nomovemsg == eatmbuf) + nomovemsg = 0; + free((genericptr_t) eatmbuf), eatmbuf = 0; + } + /* update display */ + if (youmonst.m_ap_type) { + youmonst.m_ap_type = M_AP_NOTHING; + newsym(u.ux, u.uy); + } + return 0; } /* called when hallucination is toggled */ void eatmupdate() { - const char *altmsg = 0; - int altapp = 0; /* lint suppression */ + const char *altmsg = 0; + int altapp = 0; /* lint suppression */ - if (!eatmbuf || nomovemsg != eatmbuf) return; + if (!eatmbuf || nomovemsg != eatmbuf) + return; - if (youmonst.m_ap_type == M_AP_OBJECT && - youmonst.mappearance == ORANGE && - !Hallucination) { - /* revert from hallucinatory to "normal" mimicking */ - altmsg = "You now prefer mimicking yourself."; - altapp = GOLD_PIECE; - } else if (youmonst.m_ap_type == M_AP_OBJECT && - youmonst.mappearance == GOLD_PIECE && - Hallucination) { - /* won't happen; anything which might make immobilized - hero begin hallucinating (black light attack, theft - of Grayswandir) will terminate the mimicry first */ - altmsg = "Your rind escaped intact."; - altapp = ORANGE; - } + if (youmonst.m_ap_type == M_AP_OBJECT && youmonst.mappearance == ORANGE + && !Hallucination) { + /* revert from hallucinatory to "normal" mimicking */ + altmsg = "You now prefer mimicking yourself."; + altapp = GOLD_PIECE; + } else if (youmonst.m_ap_type == M_AP_OBJECT + && youmonst.mappearance == GOLD_PIECE && Hallucination) { + /* won't happen; anything which might make immobilized + hero begin hallucinating (black light attack, theft + of Grayswandir) will terminate the mimicry first */ + altmsg = "Your rind escaped intact."; + altapp = ORANGE; + } - if (altmsg) { - /* replace end-of-mimicking message */ - if (strlen(altmsg) > strlen(eatmbuf)) { - free((genericptr_t) eatmbuf); - eatmbuf = (char *) alloc(strlen(altmsg) + 1); - } - nomovemsg = strcpy(eatmbuf, altmsg); - /* update current image */ - youmonst.mappearance = altapp; - newsym(u.ux, u.uy); - } + if (altmsg) { + /* replace end-of-mimicking message */ + if (strlen(altmsg) > strlen(eatmbuf)) { + free((genericptr_t) eatmbuf); + eatmbuf = (char *) alloc(strlen(altmsg) + 1); + } + nomovemsg = strcpy(eatmbuf, altmsg); + /* update current image */ + youmonst.mappearance = altapp; + newsym(u.ux, u.uy); + } } /* ``[the(] singular(food, xname) [)]'' */ @@ -202,20 +195,22 @@ food_xname(food, the_pfx) struct obj *food; boolean the_pfx; { - const char *result; + const char *result; - if (food->otyp == CORPSE) { - result = corpse_xname(food, (const char *)0, - CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0)); - /* not strictly needed since pname values are capitalized - and the() is a no-op for them */ - if (type_is_pname(&mons[food->corpsenm])) the_pfx = FALSE; - } else { - /* the ordinary case */ - result = singular(food, xname); - } - if (the_pfx) result = the(result); - return result; + if (food->otyp == CORPSE) { + result = corpse_xname(food, (const char *) 0, + CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0)); + /* not strictly needed since pname values are capitalized + and the() is a no-op for them */ + if (type_is_pname(&mons[food->corpsenm])) + the_pfx = FALSE; + } else { + /* the ordinary case */ + result = singular(food, xname); + } + if (the_pfx) + result = the(result); + return result; } /* Created by GAN 01/28/87 @@ -223,111 +218,109 @@ boolean the_pfx; * Amended by 3. 06/12/89: if not hard, sometimes choke anyway, to keep risk. * 11/10/89: if hard, rarely vomit anyway, for slim chance. */ -STATIC_OVL void -choke(food) /* To a full belly all food is bad. (It.) */ - register struct obj *food; +STATIC_OVL void choke(food) /* To a full belly all food is bad. (It.) */ +register struct obj *food; { - /* only happens if you were satiated */ - if (u.uhs != SATIATED) { - if (!food || food->otyp != AMULET_OF_STRANGULATION) - return; - } else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) { - adjalign(-1); /* gluttony is unchivalrous */ - You_feel("like a glutton!"); - } + /* only happens if you were satiated */ + if (u.uhs != SATIATED) { + if (!food || food->otyp != AMULET_OF_STRANGULATION) + return; + } else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) { + adjalign(-1); /* gluttony is unchivalrous */ + You_feel("like a glutton!"); + } - exercise(A_CON, FALSE); + exercise(A_CON, FALSE); - if (Breathless || (!Strangled && !rn2(20))) { - /* choking by eating AoS doesn't involve stuffing yourself */ - if (food && food->otyp == AMULET_OF_STRANGULATION) { - You("choke, but recover your composure."); - return; - } - You("stuff yourself and then vomit voluminously."); - morehungry(1000); /* you just got *very* sick! */ - vomit(); - } else { - killer.format = KILLED_BY_AN; - /* - * Note all "killer"s below read "Choked on %s" on the - * high score list & tombstone. So plan accordingly. - */ - if(food) { - You("choke over your %s.", foodword(food)); - if (food->oclass == COIN_CLASS) { - Strcpy(killer.name, "very rich meal"); - } else { - killer.format = KILLED_BY; - Strcpy(killer.name, killer_xname(food)); - } - } else { - You("choke over it."); - Strcpy(killer.name, "quick snack"); - } - You("die..."); - done(CHOKING); - } + if (Breathless || (!Strangled && !rn2(20))) { + /* choking by eating AoS doesn't involve stuffing yourself */ + if (food && food->otyp == AMULET_OF_STRANGULATION) { + You("choke, but recover your composure."); + return; + } + You("stuff yourself and then vomit voluminously."); + morehungry(1000); /* you just got *very* sick! */ + vomit(); + } else { + killer.format = KILLED_BY_AN; + /* + * Note all "killer"s below read "Choked on %s" on the + * high score list & tombstone. So plan accordingly. + */ + if (food) { + You("choke over your %s.", foodword(food)); + if (food->oclass == COIN_CLASS) { + Strcpy(killer.name, "very rich meal"); + } else { + killer.format = KILLED_BY; + Strcpy(killer.name, killer_xname(food)); + } + } else { + You("choke over it."); + Strcpy(killer.name, "quick snack"); + } + You("die..."); + done(CHOKING); + } } /* modify object wt. depending on time spent consuming it */ STATIC_OVL void recalc_wt() { - struct obj *piece = context.victual.piece; + struct obj *piece = context.victual.piece; - debugpline1("Old weight = %d", piece->owt); - debugpline2("Used time = %d, Req'd time = %d", - context.victual.usedtime, context.victual.reqtime); - piece->owt = weight(piece); - debugpline1("New weight = %d", piece->owt); + debugpline1("Old weight = %d", piece->owt); + debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime, + context.victual.reqtime); + piece->owt = weight(piece); + debugpline1("New weight = %d", piece->owt); } -void -reset_eat() /* called when eating interrupted by an event */ +void reset_eat() /* called when eating interrupted by an event */ { /* we only set a flag here - the actual reset process is done after * the round is spent eating. */ - if(context.victual.eating && !context.victual.doreset) { - debugpline0("reset_eat..."); - context.victual.doreset = TRUE; - } - return; + if (context.victual.eating && !context.victual.doreset) { + debugpline0("reset_eat..."); + context.victual.doreset = TRUE; + } + return; } STATIC_OVL struct obj * touchfood(otmp) register struct obj *otmp; { - if (otmp->quan > 1L) { - if(!carried(otmp)) - (void) splitobj(otmp, otmp->quan - 1L); - else - otmp = splitobj(otmp, 1L); - debugpline0("split object,"); - } + if (otmp->quan > 1L) { + if (!carried(otmp)) + (void) splitobj(otmp, otmp->quan - 1L); + else + otmp = splitobj(otmp, 1L); + debugpline0("split object,"); + } - if (!otmp->oeaten) { - costly_alteration(otmp, COST_BITE); - otmp->oeaten = (otmp->otyp == CORPSE ? - mons[otmp->corpsenm].cnutrit : - objects[otmp->otyp].oc_nutrition); - } + if (!otmp->oeaten) { + costly_alteration(otmp, COST_BITE); + otmp->oeaten = + (otmp->otyp == CORPSE ? mons[otmp->corpsenm].cnutrit + : objects[otmp->otyp].oc_nutrition); + } - if (carried(otmp)) { - freeinv(otmp); - if (inv_cnt(FALSE) >= 52) { - sellobj_state(SELL_DONTSELL); - dropy(otmp); - sellobj_state(SELL_NORMAL); - } else { - otmp->nomerge = 1; /* used to prevent merge */ - otmp = addinv(otmp); - otmp->nomerge = 0; - } - } - return(otmp); + if (carried(otmp)) { + freeinv(otmp); + if (inv_cnt(FALSE) >= 52) { + sellobj_state(SELL_DONTSELL); + dropy(otmp); + sellobj_state(SELL_NORMAL); + } else { + otmp->nomerge = 1; /* used to prevent merge */ + otmp = addinv(otmp); + otmp->nomerge = 0; + } + } + return (otmp); } /* When food decays, in the middle of your meal, we don't want to dereference @@ -339,11 +332,12 @@ void food_disappears(obj) register struct obj *obj; { - if (obj == context.victual.piece) { - context.victual.piece = (struct obj *)0; - context.victual.o_id = 0; - } - if (obj->timed) obj_stop_timers(obj); + if (obj == context.victual.piece) { + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + } + if (obj->timed) + obj_stop_timers(obj); } /* renaming an object usually results in it having a different address; @@ -353,82 +347,88 @@ void food_substitution(old_obj, new_obj) struct obj *old_obj, *new_obj; { - if (old_obj == context.victual.piece) { - context.victual.piece = new_obj; - context.victual.o_id = new_obj->o_id; - } - if (old_obj == context.tin.tin) { - context.tin.tin = new_obj; - context.tin.o_id =new_obj->o_id; - } + if (old_obj == context.victual.piece) { + context.victual.piece = new_obj; + context.victual.o_id = new_obj->o_id; + } + if (old_obj == context.tin.tin) { + context.tin.tin = new_obj; + context.tin.o_id = new_obj->o_id; + } } STATIC_OVL void do_reset_eat() { - debugpline0("do_reset_eat..."); - if (context.victual.piece) { - context.victual.o_id = 0; - context.victual.piece = touchfood(context.victual.piece); - if (context.victual.piece) - context.victual.o_id = context.victual.piece->o_id; - recalc_wt(); - } - context.victual.fullwarn = context.victual.eating = context.victual.doreset = FALSE; - /* Do not set canchoke to FALSE; if we continue eating the same object - * we need to know if canchoke was set when they started eating it the - * previous time. And if we don't continue eating the same object - * canchoke always gets recalculated anyway. - */ - stop_occupation(); - newuhs(FALSE); + debugpline0("do_reset_eat..."); + if (context.victual.piece) { + context.victual.o_id = 0; + context.victual.piece = touchfood(context.victual.piece); + if (context.victual.piece) + context.victual.o_id = context.victual.piece->o_id; + recalc_wt(); + } + context.victual.fullwarn = context.victual.eating = + context.victual.doreset = FALSE; + /* Do not set canchoke to FALSE; if we continue eating the same object + * we need to know if canchoke was set when they started eating it the + * previous time. And if we don't continue eating the same object + * canchoke always gets recalculated anyway. + */ + stop_occupation(); + newuhs(FALSE); } STATIC_PTR -int -eatfood(VOID_ARGS) /* called each move during eating process */ +int eatfood(VOID_ARGS) /* called each move during eating process */ { - if(!context.victual.piece || - (!carried(context.victual.piece) && - !obj_here(context.victual.piece, u.ux, u.uy))) { - /* maybe it was stolen? */ - do_reset_eat(); - return(0); - } - if(!context.victual.eating) return(0); + if (!context.victual.piece + || (!carried(context.victual.piece) + && !obj_here(context.victual.piece, u.ux, u.uy))) { + /* maybe it was stolen? */ + do_reset_eat(); + return (0); + } + if (!context.victual.eating) + return (0); - if(++context.victual.usedtime <= context.victual.reqtime) { - if(bite()) return(0); - return(1); /* still busy */ - } else { /* done */ - done_eating(TRUE); - return(0); - } + if (++context.victual.usedtime <= context.victual.reqtime) { + if (bite()) + return (0); + return (1); /* still busy */ + } else { /* done */ + done_eating(TRUE); + return (0); + } } STATIC_OVL void done_eating(message) boolean message; { - context.victual.piece->in_use = TRUE; - occupation = 0; /* do this early, so newuhs() knows we're done */ - newuhs(FALSE); - if (nomovemsg) { - if (message) pline1(nomovemsg); - nomovemsg = 0; - } else if (message) - You("finish eating %s.", food_xname(context.victual.piece, TRUE)); + context.victual.piece->in_use = TRUE; + occupation = 0; /* do this early, so newuhs() knows we're done */ + newuhs(FALSE); + if (nomovemsg) { + if (message) + pline1(nomovemsg); + nomovemsg = 0; + } else if (message) + You("finish eating %s.", food_xname(context.victual.piece, TRUE)); - if(context.victual.piece->otyp == CORPSE) - cpostfx(context.victual.piece->corpsenm); - else - fpostfx(context.victual.piece); + if (context.victual.piece->otyp == CORPSE) + cpostfx(context.victual.piece->corpsenm); + else + fpostfx(context.victual.piece); - if (carried(context.victual.piece)) useup(context.victual.piece); - else useupf(context.victual.piece, 1L); - context.victual.piece = (struct obj *) 0; - context.victual.o_id = 0; - context.victual.fullwarn = context.victual.eating = context.victual.doreset = FALSE; + if (carried(context.victual.piece)) + useup(context.victual.piece); + else + useupf(context.victual.piece, 1L); + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + context.victual.fullwarn = context.victual.eating = + context.victual.doreset = FALSE; } void @@ -437,9 +437,9 @@ struct permonst *pd; { u.uconduct.food++; if (!vegan(pd)) - u.uconduct.unvegan++; + u.uconduct.unvegan++; if (!vegetarian(pd)) - violated_vegetarian(); + violated_vegetarian(); } /* handle side-effects of mind flayer's tentacle attack */ @@ -447,136 +447,142 @@ int eat_brains(magr, mdef, visflag, dmg_p) struct monst *magr, *mdef; boolean visflag; -int *dmg_p; /* for dishing out extra damage in lieu of Int loss */ +int *dmg_p; /* for dishing out extra damage in lieu of Int loss */ { struct permonst *pd = mdef->data; boolean give_nutrit = FALSE; int result = MM_HIT, xtra_dmg = rnd(10); if (noncorporeal(pd)) { - if (visflag) - pline("%s brain is unharmed.", - (mdef == &youmonst) ? "Your" : s_suffix(Monnam(mdef))); - return MM_MISS; /* side-effects can't occur */ + if (visflag) + pline("%s brain is unharmed.", + (mdef == &youmonst) ? "Your" : s_suffix(Monnam(mdef))); + return MM_MISS; /* side-effects can't occur */ } else if (magr == &youmonst) { - You("eat %s brain!", s_suffix(mon_nam(mdef))); + You("eat %s brain!", s_suffix(mon_nam(mdef))); } else if (mdef == &youmonst) { - Your("brain is eaten!"); - } else { /* monster against monster */ - if (visflag) pline("%s brain is eaten!", s_suffix(Monnam(mdef))); + Your("brain is eaten!"); + } else { /* monster against monster */ + if (visflag) + pline("%s brain is eaten!", s_suffix(Monnam(mdef))); } if (flesh_petrifies(pd)) { - /* mind flayer has attempted to eat the brains of a petrification - inducing critter (most likely Medusa; attacking a cockatrice via - tentacle-touch should have been caught before reaching this far) */ - if (magr == &youmonst) { - if (!Stone_resistance && !Stoned) - make_stoned(5L, (char *)0, KILLED_BY_AN, pd->mname); - } else { - /* no need to check for poly_when_stoned or Stone_resistance; - mind flayers don't have those capabilities */ - if (visflag) pline("%s turns to stone!", Monnam(magr)); - monstone(magr); - if (magr->mhp > 0) { - /* life-saved; don't continue eating the brains */ - return MM_MISS; - } else { - if (magr->mtame && !visflag) - /* parallels mhitm.c's brief_feeling */ - You("have a sad thought for a moment, then is passes."); - return MM_AGR_DIED; - } - } + /* mind flayer has attempted to eat the brains of a petrification + inducing critter (most likely Medusa; attacking a cockatrice via + tentacle-touch should have been caught before reaching this far) */ + if (magr == &youmonst) { + if (!Stone_resistance && !Stoned) + make_stoned(5L, (char *) 0, KILLED_BY_AN, pd->mname); + } else { + /* no need to check for poly_when_stoned or Stone_resistance; + mind flayers don't have those capabilities */ + if (visflag) + pline("%s turns to stone!", Monnam(magr)); + monstone(magr); + if (magr->mhp > 0) { + /* life-saved; don't continue eating the brains */ + return MM_MISS; + } else { + if (magr->mtame && !visflag) + /* parallels mhitm.c's brief_feeling */ + You("have a sad thought for a moment, then is passes."); + return MM_AGR_DIED; + } + } } if (magr == &youmonst) { - /* - * player mind flayer is eating something's brain - */ - eating_conducts(pd); - if (mindless(pd)) { /* (cannibalism not possible here) */ - pline("%s doesn't notice.", Monnam(mdef)); - /* all done; no extra harm inflicted upon target */ - return MM_MISS; - } else if (is_rider(pd)) { - pline("Ingesting that is fatal."); - Sprintf(killer.name, "unwisely ate the brain of %s", pd->mname); - killer.format = NO_KILLER_PREFIX; - done(DIED); - /* life-saving needed to reach here */ - exercise(A_WIS, FALSE); - *dmg_p += xtra_dmg; /* Rider takes extra damage */ - } else { - morehungry(-rnd(30)); /* cannot choke */ - if (ABASE(A_INT) < AMAX(A_INT)) { - /* recover lost Int; won't increase current max */ - ABASE(A_INT) += rnd(4); - if (ABASE(A_INT) > AMAX(A_INT)) ABASE(A_INT) = AMAX(A_INT); - context.botl = 1; - } - exercise(A_WIS, TRUE); - *dmg_p += xtra_dmg; - } - /* targetting another mind flayer or your own underlying species - is cannibalism */ - (void) maybe_cannibal(monsndx(pd), TRUE); + /* + * player mind flayer is eating something's brain + */ + eating_conducts(pd); + if (mindless(pd)) { /* (cannibalism not possible here) */ + pline("%s doesn't notice.", Monnam(mdef)); + /* all done; no extra harm inflicted upon target */ + return MM_MISS; + } else if (is_rider(pd)) { + pline("Ingesting that is fatal."); + Sprintf(killer.name, "unwisely ate the brain of %s", pd->mname); + killer.format = NO_KILLER_PREFIX; + done(DIED); + /* life-saving needed to reach here */ + exercise(A_WIS, FALSE); + *dmg_p += xtra_dmg; /* Rider takes extra damage */ + } else { + morehungry(-rnd(30)); /* cannot choke */ + if (ABASE(A_INT) < AMAX(A_INT)) { + /* recover lost Int; won't increase current max */ + ABASE(A_INT) += rnd(4); + if (ABASE(A_INT) > AMAX(A_INT)) + ABASE(A_INT) = AMAX(A_INT); + context.botl = 1; + } + exercise(A_WIS, TRUE); + *dmg_p += xtra_dmg; + } + /* targetting another mind flayer or your own underlying species + is cannibalism */ + (void) maybe_cannibal(monsndx(pd), TRUE); } else if (mdef == &youmonst) { - /* - * monster mind flayer is eating hero's brain - */ - /* no such thing as mindless players */ - if (ABASE(A_INT) <= ATTRMIN(A_INT)) { - static NEARDATA const char brainlessness[] = "brainlessness"; + /* + * monster mind flayer is eating hero's brain + */ + /* no such thing as mindless players */ + if (ABASE(A_INT) <= ATTRMIN(A_INT)) { + static NEARDATA const char brainlessness[] = "brainlessness"; - if (Lifesaved) { - Strcpy(killer.name, brainlessness); - killer.format = KILLED_BY; - done(DIED); - /* amulet of life saving has now been used up */ - pline("Unfortunately your brain is still gone."); - /* sanity check against adding other forms of life-saving */ - u.uprops[LIFESAVED].extrinsic = - u.uprops[LIFESAVED].intrinsic = 0L; - } else { - Your("last thought fades away."); - } - Strcpy(killer.name, brainlessness); - killer.format = KILLED_BY; - done(DIED); - /* can only get here when in wizard or explore mode and user has - explicitly chosen not to die; arbitrarily boost intelligence */ - ABASE(A_INT) = ATTRMIN(A_INT) + 2; - You_feel("like a scarecrow."); - } - give_nutrit = TRUE; /* in case a conflicted pet is doing this */ - exercise(A_WIS, FALSE); - /* caller handles Int and memory loss */ + if (Lifesaved) { + Strcpy(killer.name, brainlessness); + killer.format = KILLED_BY; + done(DIED); + /* amulet of life saving has now been used up */ + pline("Unfortunately your brain is still gone."); + /* sanity check against adding other forms of life-saving */ + u.uprops[LIFESAVED].extrinsic = + u.uprops[LIFESAVED].intrinsic = 0L; + } else { + Your("last thought fades away."); + } + Strcpy(killer.name, brainlessness); + killer.format = KILLED_BY; + done(DIED); + /* can only get here when in wizard or explore mode and user has + explicitly chosen not to die; arbitrarily boost intelligence */ + ABASE(A_INT) = ATTRMIN(A_INT) + 2; + You_feel("like a scarecrow."); + } + give_nutrit = TRUE; /* in case a conflicted pet is doing this */ + exercise(A_WIS, FALSE); + /* caller handles Int and memory loss */ - } else { /* mhitm */ - /* - * monster mind flayer is eating another monster's brain - */ - if (mindless(pd)) { - if (visflag) pline("%s doesn't notice.", Monnam(mdef)); - return MM_MISS; - } else if (is_rider(pd)) { - mondied(magr); - if (magr->mhp <= 0) result = MM_AGR_DIED; - /* Rider takes extra damage regardless of whether attacker dies */ - *dmg_p += xtra_dmg; - } else { - *dmg_p += xtra_dmg; - give_nutrit = TRUE; - if (*dmg_p >= mdef->mhp && visflag) - pline("%s last thought fades away...", s_suffix(Monnam(mdef))); - } + } else { /* mhitm */ + /* + * monster mind flayer is eating another monster's brain + */ + if (mindless(pd)) { + if (visflag) + pline("%s doesn't notice.", Monnam(mdef)); + return MM_MISS; + } else if (is_rider(pd)) { + mondied(magr); + if (magr->mhp <= 0) + result = MM_AGR_DIED; + /* Rider takes extra damage regardless of whether attacker dies */ + *dmg_p += xtra_dmg; + } else { + *dmg_p += xtra_dmg; + give_nutrit = TRUE; + if (*dmg_p >= mdef->mhp && visflag) + pline("%s last thought fades away...", + s_suffix(Monnam(mdef))); + } } if (give_nutrit && magr->mtame && !magr->isminion) { - EDOG(magr)->hungrytime += rnd(60); - magr->mconf = 0; + EDOG(magr)->hungrytime += rnd(60); + magr->mconf = 0; } return result; @@ -588,99 +594,99 @@ maybe_cannibal(pm, allowmsg) int pm; boolean allowmsg; { - static NEARDATA long ate_brains = 0L; - struct permonst *fptr = &mons[pm]; /* food type */ + static NEARDATA long ate_brains = 0L; + struct permonst *fptr = &mons[pm]; /* food type */ - /* when poly'd into a mind flayer, multiple tentacle hits in one - turn cause multiple digestion checks to occur; avoid giving - multiple luck penalties for the same attack */ - if (moves == ate_brains) return FALSE; - ate_brains = moves; /* ate_anything, not just brains... */ + /* when poly'd into a mind flayer, multiple tentacle hits in one + turn cause multiple digestion checks to occur; avoid giving + multiple luck penalties for the same attack */ + if (moves == ate_brains) + return FALSE; + ate_brains = moves; /* ate_anything, not just brains... */ - if (!CANNIBAL_ALLOWED() && - /* non-cannibalistic heroes shouldn't eat own species ever - and also shouldn't eat current species when polymorphed - (even if having the form of something which doesn't care - about cannibalism--hero's innate traits aren't altered) */ - (your_race(fptr) || - (Upolyd && same_race(youmonst.data, fptr)))) { - if (allowmsg) { - if (Upolyd && your_race(fptr)) - You("have a bad feeling deep inside."); - You("cannibal! You will regret this!"); - } - HAggravate_monster |= FROMOUTSIDE; - change_luck(-rn1(4,2)); /* -5..-2 */ - return TRUE; - } - return FALSE; + if (!CANNIBAL_ALLOWED() && + /* non-cannibalistic heroes shouldn't eat own species ever + and also shouldn't eat current species when polymorphed + (even if having the form of something which doesn't care + about cannibalism--hero's innate traits aren't altered) */ + (your_race(fptr) || (Upolyd && same_race(youmonst.data, fptr)))) { + if (allowmsg) { + if (Upolyd && your_race(fptr)) + You("have a bad feeling deep inside."); + You("cannibal! You will regret this!"); + } + HAggravate_monster |= FROMOUTSIDE; + change_luck(-rn1(4, 2)); /* -5..-2 */ + return TRUE; + } + return FALSE; } STATIC_OVL void cprefx(pm) register int pm; { - (void) maybe_cannibal(pm,TRUE); - if (flesh_petrifies(&mons[pm])) { - if (!Stone_resistance && - !(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) { - Sprintf(killer.name, "tasting %s meat", mons[pm].mname); - killer.format = KILLED_BY; - You("turn to stone."); - done(STONING); - if (context.victual.piece) - context.victual.eating = FALSE; - return; /* lifesaved */ - } - } + (void) maybe_cannibal(pm, TRUE); + if (flesh_petrifies(&mons[pm])) { + if (!Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + Sprintf(killer.name, "tasting %s meat", mons[pm].mname); + killer.format = KILLED_BY; + You("turn to stone."); + done(STONING); + if (context.victual.piece) + context.victual.eating = FALSE; + return; /* lifesaved */ + } + } - switch(pm) { - case PM_LITTLE_DOG: - case PM_DOG: - case PM_LARGE_DOG: - case PM_KITTEN: - case PM_HOUSECAT: - case PM_LARGE_CAT: - if (!CANNIBAL_ALLOWED()) { - You_feel("that eating the %s was a bad idea.", mons[pm].mname); - HAggravate_monster |= FROMOUTSIDE; - } - break; - case PM_LIZARD: - if (Stoned) fix_petrification(); - break; - case PM_DEATH: - case PM_PESTILENCE: - case PM_FAMINE: - { - pline("Eating that is instantly fatal."); - Sprintf(killer.name, "unwisely ate the body of %s", - mons[pm].mname); - killer.format = NO_KILLER_PREFIX; - done(DIED); - /* life-saving needed to reach here */ - exercise(A_WIS, FALSE); - /* It so happens that since we know these monsters */ - /* cannot appear in tins, context.victual.piece will always */ - /* be what we want, which is not generally true. */ - if (revive_corpse(context.victual.piece)) { - context.victual.piece = (struct obj *)0; - context.victual.o_id = 0; - } - return; - } - case PM_GREEN_SLIME: - if (!Slimed && !Unchanging && !slimeproof(youmonst.data)) { - You("don't feel very well."); - make_slimed(10L, (char*) 0); - delayed_killer(SLIMED, KILLED_BY_AN, ""); - } - /* Fall through */ - default: - if (acidic(&mons[pm]) && Stoned) - fix_petrification(); - break; - } + switch (pm) { + case PM_LITTLE_DOG: + case PM_DOG: + case PM_LARGE_DOG: + case PM_KITTEN: + case PM_HOUSECAT: + case PM_LARGE_CAT: + if (!CANNIBAL_ALLOWED()) { + You_feel("that eating the %s was a bad idea.", mons[pm].mname); + HAggravate_monster |= FROMOUTSIDE; + } + break; + case PM_LIZARD: + if (Stoned) + fix_petrification(); + break; + case PM_DEATH: + case PM_PESTILENCE: + case PM_FAMINE: { + pline("Eating that is instantly fatal."); + Sprintf(killer.name, "unwisely ate the body of %s", mons[pm].mname); + killer.format = NO_KILLER_PREFIX; + done(DIED); + /* life-saving needed to reach here */ + exercise(A_WIS, FALSE); + /* It so happens that since we know these monsters */ + /* cannot appear in tins, context.victual.piece will always */ + /* be what we want, which is not generally true. */ + if (revive_corpse(context.victual.piece)) { + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + } + return; + } + case PM_GREEN_SLIME: + if (!Slimed && !Unchanging && !slimeproof(youmonst.data)) { + You("don't feel very well."); + make_slimed(10L, (char *) 0); + delayed_killer(SLIMED, KILLED_BY_AN, ""); + } + /* Fall through */ + default: + if (acidic(&mons[pm]) && Stoned) + fix_petrification(); + break; + } } void @@ -689,11 +695,11 @@ fix_petrification() char buf[BUFSZ]; if (Hallucination) - Sprintf(buf, "What a pity--you just ruined a future piece of %sart!", - ACURR(A_CHA) > 15 ? "fine " : ""); + Sprintf(buf, "What a pity--you just ruined a future piece of %sart!", + ACURR(A_CHA) > 15 ? "fine " : ""); else - Strcpy(buf, "You feel limber!"); - make_stoned(0L, buf, 0, (char *)0); + Strcpy(buf, "You feel limber!"); + make_stoned(0L, buf, 0, (char *) 0); } /* @@ -711,50 +717,59 @@ intrinsic_possible(type, ptr) int type; register struct permonst *ptr; { - int res = 0; + int res = 0; - switch (type) { - case FIRE_RES: - res = (ptr->mconveys & MR_FIRE) != 0; - if (res) debugpline0("can get fire resistance"); - break; - case SLEEP_RES: - res = (ptr->mconveys & MR_SLEEP) != 0; - if (res) debugpline0("can get sleep resistance"); - break; - case COLD_RES: - res = (ptr->mconveys & MR_COLD) != 0; - if (res) debugpline0("can get cold resistance"); - break; - case DISINT_RES: - res = (ptr->mconveys & MR_DISINT) != 0; - if (res) debugpline0("can get disintegration resistance"); - break; - case SHOCK_RES: /* shock (electricity) resistance */ - res = (ptr->mconveys & MR_ELEC) != 0; - if (res) debugpline0("can get shock resistance"); - break; - case POISON_RES: - res = (ptr->mconveys & MR_POISON) != 0; - if (res) debugpline0("can get poison resistance"); - break; - case TELEPORT: - res = can_teleport(ptr); - if (res) debugpline0("can get teleport"); - break; - case TELEPORT_CONTROL: - res = control_teleport(ptr); - if (res) debugpline0("can get teleport control"); - break; - case TELEPAT: - res = telepathic(ptr); - if (res) debugpline0("can get telepathy"); - break; - default: - /* res stays 0 */ - break; - } - return res; + switch (type) { + case FIRE_RES: + res = (ptr->mconveys & MR_FIRE) != 0; + if (res) + debugpline0("can get fire resistance"); + break; + case SLEEP_RES: + res = (ptr->mconveys & MR_SLEEP) != 0; + if (res) + debugpline0("can get sleep resistance"); + break; + case COLD_RES: + res = (ptr->mconveys & MR_COLD) != 0; + if (res) + debugpline0("can get cold resistance"); + break; + case DISINT_RES: + res = (ptr->mconveys & MR_DISINT) != 0; + if (res) + debugpline0("can get disintegration resistance"); + break; + case SHOCK_RES: /* shock (electricity) resistance */ + res = (ptr->mconveys & MR_ELEC) != 0; + if (res) + debugpline0("can get shock resistance"); + break; + case POISON_RES: + res = (ptr->mconveys & MR_POISON) != 0; + if (res) + debugpline0("can get poison resistance"); + break; + case TELEPORT: + res = can_teleport(ptr); + if (res) + debugpline0("can get teleport"); + break; + case TELEPORT_CONTROL: + res = control_teleport(ptr); + if (res) + debugpline0("can get teleport control"); + break; + case TELEPAT: + res = telepathic(ptr); + if (res) + debugpline0("can get telepathy"); + break; + default: + /* res stays 0 */ + break; + } + return res; } /* givit() tries to give you an intrinsic based on the monster's level @@ -765,314 +780,319 @@ givit(type, ptr) int type; register struct permonst *ptr; { - register int chance; + register int chance; - debugpline1("Attempting to give intrinsic %d", type); - /* some intrinsics are easier to get than others */ - switch (type) { - case POISON_RES: - if ((ptr == &mons[PM_KILLER_BEE] || - ptr == &mons[PM_SCORPION]) && !rn2(4)) - chance = 1; - else - chance = 15; - break; - case TELEPORT: - chance = 10; - break; - case TELEPORT_CONTROL: - chance = 12; - break; - case TELEPAT: - chance = 1; - break; - default: - chance = 15; - break; - } + debugpline1("Attempting to give intrinsic %d", type); + /* some intrinsics are easier to get than others */ + switch (type) { + case POISON_RES: + if ((ptr == &mons[PM_KILLER_BEE] || ptr == &mons[PM_SCORPION]) + && !rn2(4)) + chance = 1; + else + chance = 15; + break; + case TELEPORT: + chance = 10; + break; + case TELEPORT_CONTROL: + chance = 12; + break; + case TELEPAT: + chance = 1; + break; + default: + chance = 15; + break; + } - if (ptr->mlevel <= rn2(chance)) - return; /* failed die roll */ + if (ptr->mlevel <= rn2(chance)) + return; /* failed die roll */ - switch (type) { - case FIRE_RES: - debugpline0("Trying to give fire resistance"); - if(!(HFire_resistance & FROMOUTSIDE)) { - You(Hallucination ? "be chillin'." : - "feel a momentary chill."); - HFire_resistance |= FROMOUTSIDE; - } - break; - case SLEEP_RES: - debugpline0("Trying to give sleep resistance"); - if(!(HSleep_resistance & FROMOUTSIDE)) { - You_feel("wide awake."); - HSleep_resistance |= FROMOUTSIDE; - } - break; - case COLD_RES: - debugpline0("Trying to give cold resistance"); - if(!(HCold_resistance & FROMOUTSIDE)) { - You_feel("full of hot air."); - HCold_resistance |= FROMOUTSIDE; - } - break; - case DISINT_RES: - debugpline0("Trying to give disintegration resistance"); - if(!(HDisint_resistance & FROMOUTSIDE)) { - You_feel(Hallucination ? - "totally together, man." : - "very firm."); - HDisint_resistance |= FROMOUTSIDE; - } - break; - case SHOCK_RES: /* shock (electricity) resistance */ - debugpline0("Trying to give shock resistance"); - if(!(HShock_resistance & FROMOUTSIDE)) { - if (Hallucination) - You_feel("grounded in reality."); - else - Your("health currently feels amplified!"); - HShock_resistance |= FROMOUTSIDE; - } - break; - case POISON_RES: - debugpline0("Trying to give poison resistance"); - if(!(HPoison_resistance & FROMOUTSIDE)) { - You_feel(Poison_resistance ? - "especially healthy." : "healthy."); - HPoison_resistance |= FROMOUTSIDE; - } - break; - case TELEPORT: - debugpline0("Trying to give teleport"); - if(!(HTeleportation & FROMOUTSIDE)) { - You_feel(Hallucination ? "diffuse." : - "very jumpy."); - HTeleportation |= FROMOUTSIDE; - } - break; - case TELEPORT_CONTROL: - debugpline0("Trying to give teleport control"); - if(!(HTeleport_control & FROMOUTSIDE)) { - You_feel(Hallucination ? - "centered in your personal space." : - "in control of yourself."); - HTeleport_control |= FROMOUTSIDE; - } - break; - case TELEPAT: - debugpline0("Trying to give telepathy"); - if(!(HTelepat & FROMOUTSIDE)) { - You_feel(Hallucination ? - "in touch with the cosmos." : - "a strange mental acuity."); - HTelepat |= FROMOUTSIDE; - /* If blind, make sure monsters show up. */ - if (Blind) see_monsters(); - } - break; - default: - debugpline0("Tried to give an impossible intrinsic"); - break; - } + switch (type) { + case FIRE_RES: + debugpline0("Trying to give fire resistance"); + if (!(HFire_resistance & FROMOUTSIDE)) { + You(Hallucination ? "be chillin'." : "feel a momentary chill."); + HFire_resistance |= FROMOUTSIDE; + } + break; + case SLEEP_RES: + debugpline0("Trying to give sleep resistance"); + if (!(HSleep_resistance & FROMOUTSIDE)) { + You_feel("wide awake."); + HSleep_resistance |= FROMOUTSIDE; + } + break; + case COLD_RES: + debugpline0("Trying to give cold resistance"); + if (!(HCold_resistance & FROMOUTSIDE)) { + You_feel("full of hot air."); + HCold_resistance |= FROMOUTSIDE; + } + break; + case DISINT_RES: + debugpline0("Trying to give disintegration resistance"); + if (!(HDisint_resistance & FROMOUTSIDE)) { + You_feel(Hallucination ? "totally together, man." : "very firm."); + HDisint_resistance |= FROMOUTSIDE; + } + break; + case SHOCK_RES: /* shock (electricity) resistance */ + debugpline0("Trying to give shock resistance"); + if (!(HShock_resistance & FROMOUTSIDE)) { + if (Hallucination) + You_feel("grounded in reality."); + else + Your("health currently feels amplified!"); + HShock_resistance |= FROMOUTSIDE; + } + break; + case POISON_RES: + debugpline0("Trying to give poison resistance"); + if (!(HPoison_resistance & FROMOUTSIDE)) { + You_feel(Poison_resistance ? "especially healthy." : "healthy."); + HPoison_resistance |= FROMOUTSIDE; + } + break; + case TELEPORT: + debugpline0("Trying to give teleport"); + if (!(HTeleportation & FROMOUTSIDE)) { + You_feel(Hallucination ? "diffuse." : "very jumpy."); + HTeleportation |= FROMOUTSIDE; + } + break; + case TELEPORT_CONTROL: + debugpline0("Trying to give teleport control"); + if (!(HTeleport_control & FROMOUTSIDE)) { + You_feel(Hallucination ? "centered in your personal space." + : "in control of yourself."); + HTeleport_control |= FROMOUTSIDE; + } + break; + case TELEPAT: + debugpline0("Trying to give telepathy"); + if (!(HTelepat & FROMOUTSIDE)) { + You_feel(Hallucination ? "in touch with the cosmos." + : "a strange mental acuity."); + HTelepat |= FROMOUTSIDE; + /* If blind, make sure monsters show up. */ + if (Blind) + see_monsters(); + } + break; + default: + debugpline0("Tried to give an impossible intrinsic"); + break; + } } -STATIC_OVL void -cpostfx(pm) /* called after completely consuming a corpse */ +STATIC_OVL void cpostfx(pm) /* called after completely consuming a corpse */ register int pm; { - register int tmp = 0; - boolean catch_lycanthropy = FALSE; + register int tmp = 0; + boolean catch_lycanthropy = FALSE; - /* in case `afternmv' didn't get called for previously mimicking - gold, clean up now to avoid `eatmbuf' memory leak */ - if (eatmbuf) (void)eatmdone(); + /* in case `afternmv' didn't get called for previously mimicking + gold, clean up now to avoid `eatmbuf' memory leak */ + if (eatmbuf) + (void) eatmdone(); - switch(pm) { - case PM_NEWT: - /* MRKR: "eye of newt" may give small magical energy boost */ - if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) { - int old_uen = u.uen; - u.uen += rnd(3); - if (u.uen > u.uenmax) { - if (!rn2(3)) u.uenmax++; - u.uen = u.uenmax; - } - if (old_uen != u.uen) { - You_feel("a mild buzz."); - context.botl = 1; - } - } - break; - case PM_WRAITH: - pluslvl(FALSE); - break; - case PM_HUMAN_WERERAT: - catch_lycanthropy = TRUE; - u.ulycn = PM_WERERAT; - break; - case PM_HUMAN_WEREJACKAL: - catch_lycanthropy = TRUE; - u.ulycn = PM_WEREJACKAL; - break; - case PM_HUMAN_WEREWOLF: - catch_lycanthropy = TRUE; - u.ulycn = PM_WEREWOLF; - break; - case PM_NURSE: - if (Upolyd) u.mh = u.mhmax; - else u.uhp = u.uhpmax; - context.botl = 1; - break; - case PM_STALKER: - if(!Invis) { - set_itimeout(&HInvis, (long)rn1(100, 50)); - if (!Blind && !BInvis) self_invis_message(); - } else { - if (!(HInvis & INTRINSIC)) You_feel("hidden!"); - HInvis |= FROMOUTSIDE; - HSee_invisible |= FROMOUTSIDE; - } - newsym(u.ux, u.uy); - /* fall into next case */ - case PM_YELLOW_LIGHT: - /* fall into next case */ - case PM_GIANT_BAT: - make_stunned((HStun & TIMEOUT) + 30L, FALSE); - /* fall into next case */ - case PM_BAT: - make_stunned((HStun & TIMEOUT) + 30L, FALSE); - break; - case PM_GIANT_MIMIC: - tmp += 10; - /* fall into next case */ - case PM_LARGE_MIMIC: - tmp += 20; - /* fall into next case */ - case PM_SMALL_MIMIC: - tmp += 20; - if (youmonst.data->mlet != S_MIMIC && !Unchanging) { - char buf[BUFSZ]; + switch (pm) { + case PM_NEWT: + /* MRKR: "eye of newt" may give small magical energy boost */ + if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) { + int old_uen = u.uen; + u.uen += rnd(3); + if (u.uen > u.uenmax) { + if (!rn2(3)) + u.uenmax++; + u.uen = u.uenmax; + } + if (old_uen != u.uen) { + You_feel("a mild buzz."); + context.botl = 1; + } + } + break; + case PM_WRAITH: + pluslvl(FALSE); + break; + case PM_HUMAN_WERERAT: + catch_lycanthropy = TRUE; + u.ulycn = PM_WERERAT; + break; + case PM_HUMAN_WEREJACKAL: + catch_lycanthropy = TRUE; + u.ulycn = PM_WEREJACKAL; + break; + case PM_HUMAN_WEREWOLF: + catch_lycanthropy = TRUE; + u.ulycn = PM_WEREWOLF; + break; + case PM_NURSE: + if (Upolyd) + u.mh = u.mhmax; + else + u.uhp = u.uhpmax; + context.botl = 1; + break; + case PM_STALKER: + if (!Invis) { + set_itimeout(&HInvis, (long) rn1(100, 50)); + if (!Blind && !BInvis) + self_invis_message(); + } else { + if (!(HInvis & INTRINSIC)) + You_feel("hidden!"); + HInvis |= FROMOUTSIDE; + HSee_invisible |= FROMOUTSIDE; + } + newsym(u.ux, u.uy); + /* fall into next case */ + case PM_YELLOW_LIGHT: + /* fall into next case */ + case PM_GIANT_BAT: + make_stunned((HStun & TIMEOUT) + 30L, FALSE); + /* fall into next case */ + case PM_BAT: + make_stunned((HStun & TIMEOUT) + 30L, FALSE); + break; + case PM_GIANT_MIMIC: + tmp += 10; + /* fall into next case */ + case PM_LARGE_MIMIC: + tmp += 20; + /* fall into next case */ + case PM_SMALL_MIMIC: + tmp += 20; + if (youmonst.data->mlet != S_MIMIC && !Unchanging) { + char buf[BUFSZ]; - u.uconduct.polyselfs++; /* you're changing form */ - You_cant("resist the temptation to mimic %s.", - Hallucination ? "an orange" : "a pile of gold"); - /* A pile of gold can't ride. */ - if (u.usteed) dismount_steed(DISMOUNT_FELL); - nomul(-tmp); - multi_reason = "pretending to be a pile of gold"; - Sprintf(buf, Hallucination ? - "You suddenly dread being peeled and mimic %s again!" : - "You now prefer mimicking %s again.", - an(Upolyd ? youmonst.data->mname : urace.noun)); - eatmbuf = dupstr(buf); - nomovemsg = eatmbuf; - afternmv = eatmdone; - /* ??? what if this was set before? */ - youmonst.m_ap_type = M_AP_OBJECT; - youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE; - newsym(u.ux,u.uy); - curs_on_u(); - /* make gold symbol show up now */ - display_nhwindow(WIN_MAP, TRUE); - } - break; - case PM_QUANTUM_MECHANIC: - Your("velocity suddenly seems very uncertain!"); - if (HFast & INTRINSIC) { - HFast &= ~INTRINSIC; - You("seem slower."); - } else { - HFast |= FROMOUTSIDE; - You("seem faster."); - } - break; - case PM_LIZARD: - if ((HStun & TIMEOUT) > 2) make_stunned(2L, FALSE); - if ((HConfusion & TIMEOUT) > 2) make_confused(2L, FALSE); - break; - case PM_CHAMELEON: - case PM_DOPPELGANGER: - case PM_SANDESTIN: /* moot--they don't leave corpses */ - if (Unchanging) { - You_feel("momentarily different."); /* same as poly trap */ - } else { - You_feel("a change coming over you."); - polyself(0); - } - break; - case PM_DISENCHANTER: - /* picks an intrinsic at random and removes it; there's - no feedback if hero already lacks the chosen ability */ - debugpline0("using attrcurse to strip an intrinsic"); - attrcurse(); - break; - case PM_MIND_FLAYER: - case PM_MASTER_MIND_FLAYER: - if (ABASE(A_INT) < ATTRMAX(A_INT)) { - if (!rn2(2)) { - pline("Yum! That was real brain food!"); - (void) adjattrib(A_INT, 1, FALSE); - break; /* don't give them telepathy, too */ - } - } else { - pline("For some reason, that tasted bland."); - } - /*FALLTHRU*/ - default: - { - struct permonst *ptr = &mons[pm]; - boolean conveys_STR = is_giant(ptr); - int i, count; + u.uconduct.polyselfs++; /* you're changing form */ + You_cant("resist the temptation to mimic %s.", + Hallucination ? "an orange" : "a pile of gold"); + /* A pile of gold can't ride. */ + if (u.usteed) + dismount_steed(DISMOUNT_FELL); + nomul(-tmp); + multi_reason = "pretending to be a pile of gold"; + Sprintf( + buf, + Hallucination + ? "You suddenly dread being peeled and mimic %s again!" + : "You now prefer mimicking %s again.", + an(Upolyd ? youmonst.data->mname : urace.noun)); + eatmbuf = dupstr(buf); + nomovemsg = eatmbuf; + afternmv = eatmdone; + /* ??? what if this was set before? */ + youmonst.m_ap_type = M_AP_OBJECT; + youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE; + newsym(u.ux, u.uy); + curs_on_u(); + /* make gold symbol show up now */ + display_nhwindow(WIN_MAP, TRUE); + } + break; + case PM_QUANTUM_MECHANIC: + Your("velocity suddenly seems very uncertain!"); + if (HFast & INTRINSIC) { + HFast &= ~INTRINSIC; + You("seem slower."); + } else { + HFast |= FROMOUTSIDE; + You("seem faster."); + } + break; + case PM_LIZARD: + if ((HStun & TIMEOUT) > 2) + make_stunned(2L, FALSE); + if ((HConfusion & TIMEOUT) > 2) + make_confused(2L, FALSE); + break; + case PM_CHAMELEON: + case PM_DOPPELGANGER: + case PM_SANDESTIN: /* moot--they don't leave corpses */ + if (Unchanging) { + You_feel("momentarily different."); /* same as poly trap */ + } else { + You_feel("a change coming over you."); + polyself(0); + } + break; + case PM_DISENCHANTER: + /* picks an intrinsic at random and removes it; there's + no feedback if hero already lacks the chosen ability */ + debugpline0("using attrcurse to strip an intrinsic"); + attrcurse(); + break; + case PM_MIND_FLAYER: + case PM_MASTER_MIND_FLAYER: + if (ABASE(A_INT) < ATTRMAX(A_INT)) { + if (!rn2(2)) { + pline("Yum! That was real brain food!"); + (void) adjattrib(A_INT, 1, FALSE); + break; /* don't give them telepathy, too */ + } + } else { + pline("For some reason, that tasted bland."); + } + /*FALLTHRU*/ + default: { + struct permonst *ptr = &mons[pm]; + boolean conveys_STR = is_giant(ptr); + int i, count; - if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU) || - pm == PM_VIOLET_FUNGUS) { - pline("Oh wow! Great stuff!"); - (void)make_hallucinated((HHallucination & TIMEOUT) + 200L, - FALSE, 0L); - } + if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU) + || pm == PM_VIOLET_FUNGUS) { + pline("Oh wow! Great stuff!"); + (void) make_hallucinated((HHallucination & TIMEOUT) + 200L, FALSE, + 0L); + } - /* Check the monster for all of the intrinsics. If this - * monster can give more than one, pick one to try to give - * from among all it can give. - * - * Strength from giants is now treated like an intrinsic - * rather than being given unconditionally. - */ - count = 0; /* number of possible intrinsics */ - tmp = 0; /* which one we will try to give */ - if (conveys_STR) { - count = 1; - tmp = -1; /* use -1 as fake prop index for STR */ - debugpline1("\"Intrinsic\" strength, %d", tmp); - } - for (i = 1; i <= LAST_PROP; i++) { - if (!intrinsic_possible(i, ptr)) continue; - ++count; - /* a 1 in count chance of replacing the old choice - with this one, and a count-1 in count chance - of keeping the old choice (note that 1 in 1 and - 0 in 1 are what we want for the first candidate) */ - if (!rn2(count)) { - debugpline2("Intrinsic %d replacing %d", i, tmp); - tmp = i; - } - } - /* if strength is the only candidate, give it 50% chance */ - if (conveys_STR && count == 1 && !rn2(2)) tmp = 0; - /* if something was chosen, give it now (givit() might fail) */ - if (tmp == -1) - gainstr((struct obj *)0, 0, TRUE); - else if (tmp > 0) - givit(tmp, ptr); - } - break; - } + /* Check the monster for all of the intrinsics. If this + * monster can give more than one, pick one to try to give + * from among all it can give. + * + * Strength from giants is now treated like an intrinsic + * rather than being given unconditionally. + */ + count = 0; /* number of possible intrinsics */ + tmp = 0; /* which one we will try to give */ + if (conveys_STR) { + count = 1; + tmp = -1; /* use -1 as fake prop index for STR */ + debugpline1("\"Intrinsic\" strength, %d", tmp); + } + for (i = 1; i <= LAST_PROP; i++) { + if (!intrinsic_possible(i, ptr)) + continue; + ++count; + /* a 1 in count chance of replacing the old choice + with this one, and a count-1 in count chance + of keeping the old choice (note that 1 in 1 and + 0 in 1 are what we want for the first candidate) */ + if (!rn2(count)) { + debugpline2("Intrinsic %d replacing %d", i, tmp); + tmp = i; + } + } + /* if strength is the only candidate, give it 50% chance */ + if (conveys_STR && count == 1 && !rn2(2)) + tmp = 0; + /* if something was chosen, give it now (givit() might fail) */ + if (tmp == -1) + gainstr((struct obj *) 0, 0, TRUE); + else if (tmp > 0) + givit(tmp, ptr); + } break; + } - if (catch_lycanthropy) retouch_equipment(2); + if (catch_lycanthropy) + retouch_equipment(2); - return; + return; } void @@ -1080,8 +1100,8 @@ violated_vegetarian() { u.uconduct.unvegetarian++; if (Role_if(PM_MONK)) { - You_feel("guilty."); - adjalign(-1); + You_feel("guilty."); + adjalign(-1); } return; } @@ -1091,39 +1111,39 @@ violated_vegetarian() STATIC_PTR void costly_tin(alter_type) -int alter_type; /* COST_xxx */ +int alter_type; /* COST_xxx */ { struct obj *tin = context.tin.tin; - if (carried(tin) ? tin->unpaid : - (costly_spot(tin->ox, tin->oy) && !tin->no_charge)) { - if (tin->quan > 1L) { - tin = context.tin.tin = splitobj(tin, 1L); - context.tin.o_id = tin->o_id; - } - costly_alteration(tin, alter_type); + if (carried(tin) ? tin->unpaid + : (costly_spot(tin->ox, tin->oy) && !tin->no_charge)) { + if (tin->quan > 1L) { + tin = context.tin.tin = splitobj(tin, 1L); + context.tin.o_id = tin->o_id; + } + costly_alteration(tin, alter_type); } } int -tin_variety_txt(s,tinvariety) +tin_variety_txt(s, tinvariety) char *s; int *tinvariety; { - int k, l; + int k, l; - if (s && tinvariety) { - *tinvariety = -1; - for (k = 0; k < TTSZ-1; ++k) { - l = (int)strlen(tintxts[k].txt); - if (!strncmpi(s, tintxts[k].txt, l) && - ((int)strlen(s) > l) && s[l] == ' ') { - *tinvariety = k; - return (l + 1); - } - } - } - return 0; + if (s && tinvariety) { + *tinvariety = -1; + for (k = 0; k < TTSZ - 1; ++k) { + l = (int) strlen(tintxts[k].txt); + if (!strncmpi(s, tintxts[k].txt, l) && ((int) strlen(s) > l) + && s[l] == ' ') { + *tinvariety = k; + return (l + 1); + } + } + } + return 0; } /* @@ -1136,32 +1156,32 @@ struct obj *obj; int mnum; char *buf; { - char buf2[BUFSZ]; - int r = tin_variety(obj, TRUE); + char buf2[BUFSZ]; + int r = tin_variety(obj, TRUE); - if (obj && buf) { - if (r == SPINACH_TIN) - Strcat(buf, " of spinach"); - else if (mnum == NON_PM) - Strcpy(buf, "empty tin"); - else { - if ((obj->cknown || iflags.override_ID) && obj->spe < 0) { - if (r == ROTTEN_TIN || r == HOMEMADE_TIN) { - /* put these before the word tin */ - Sprintf(buf2,"%s %s of ", tintxts[r].txt, buf); - Strcpy(buf, buf2); - } else { - Sprintf(eos(buf), " of %s ", tintxts[r].txt); - } - } else { - Strcpy(eos(buf), " of "); - } - if (vegetarian(&mons[mnum])) - Sprintf(eos(buf), "%s", mons[mnum].mname); - else - Sprintf(eos(buf), "%s meat", mons[mnum].mname); - } - } + if (obj && buf) { + if (r == SPINACH_TIN) + Strcat(buf, " of spinach"); + else if (mnum == NON_PM) + Strcpy(buf, "empty tin"); + else { + if ((obj->cknown || iflags.override_ID) && obj->spe < 0) { + if (r == ROTTEN_TIN || r == HOMEMADE_TIN) { + /* put these before the word tin */ + Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf); + Strcpy(buf, buf2); + } else { + Sprintf(eos(buf), " of %s ", tintxts[r].txt); + } + } else { + Strcpy(eos(buf), " of "); + } + if (vegetarian(&mons[mnum])) + Sprintf(eos(buf), "%s", mons[mnum].mname); + else + Sprintf(eos(buf), "%s meat", mons[mnum].mname); + } + } } void @@ -1169,54 +1189,54 @@ set_tin_variety(obj, forcetype) struct obj *obj; int forcetype; { - register int r; + register int r; - if (forcetype == SPINACH_TIN || - (forcetype == HEALTHY_TIN && - (obj->corpsenm == NON_PM || /* empty or already spinach */ - !vegetarian(&mons[obj->corpsenm])))) { /* replace meat */ - obj->corpsenm = NON_PM; /* not based on any monster */ - obj->spe = 1; /* spinach */ - return; - } else if (forcetype == HEALTHY_TIN) { - r = tin_variety(obj, FALSE); - if (r < 0 || r >= TTSZ) r = ROTTEN_TIN; /* shouldn't happen */ - while ((r == ROTTEN_TIN && !obj->cursed) || !tintxts[r].fodder) - r = rn2(TTSZ-1); - } else if (forcetype >= 0 && forcetype < TTSZ-1) { - r = forcetype; - } else { /* RANDOM_TIN */ - r = rn2(TTSZ-1); /* take your pick */ - if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm)) - r = HOMEMADE_TIN; /* lizards don't rot */ - } - obj->spe = -(r+1); /* offset by 1 to allow index 0 */ + if (forcetype == SPINACH_TIN + || (forcetype == HEALTHY_TIN + && (obj->corpsenm == NON_PM || /* empty or already spinach */ + !vegetarian(&mons[obj->corpsenm])))) { /* replace meat */ + obj->corpsenm = NON_PM; /* not based on any monster */ + obj->spe = 1; /* spinach */ + return; + } else if (forcetype == HEALTHY_TIN) { + r = tin_variety(obj, FALSE); + if (r < 0 || r >= TTSZ) + r = ROTTEN_TIN; /* shouldn't happen */ + while ((r == ROTTEN_TIN && !obj->cursed) || !tintxts[r].fodder) + r = rn2(TTSZ - 1); + } else if (forcetype >= 0 && forcetype < TTSZ - 1) { + r = forcetype; + } else { /* RANDOM_TIN */ + r = rn2(TTSZ - 1); /* take your pick */ + if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm)) + r = HOMEMADE_TIN; /* lizards don't rot */ + } + obj->spe = -(r + 1); /* offset by 1 to allow index 0 */ } STATIC_OVL int tin_variety(obj, disp) struct obj *obj; -boolean disp; /* we're just displaying so leave things alone */ +boolean disp; /* we're just displaying so leave things alone */ { - register int r; + register int r; - if (obj->spe == 1) { - r = SPINACH_TIN; - } else if (obj->cursed) { - r = ROTTEN_TIN; /* always rotten if cursed */ - } else if (obj->spe < 0) { - r = -(obj->spe); - --r; /* get rid of the offset */ - } else - r = rn2(TTSZ-1); + if (obj->spe == 1) { + r = SPINACH_TIN; + } else if (obj->cursed) { + r = ROTTEN_TIN; /* always rotten if cursed */ + } else if (obj->spe < 0) { + r = -(obj->spe); + --r; /* get rid of the offset */ + } else + r = rn2(TTSZ - 1); - if (!disp && r == HOMEMADE_TIN && - !obj->blessed && !rn2(7)) - r = ROTTEN_TIN; /* some homemade tins go bad */ + if (!disp && r == HOMEMADE_TIN && !obj->blessed && !rn2(7)) + r = ROTTEN_TIN; /* some homemade tins go bad */ - if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm)) - r = HOMEMADE_TIN; /* lizards don't rot */ - return r; + if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm)) + r = HOMEMADE_TIN; /* lizards don't rot */ + return r; } STATIC_OVL @@ -1230,218 +1250,223 @@ const char *mesg; r = tin_variety(tin, FALSE); if (tin->otrapped || (tin->cursed && r != HOMEMADE_TIN && !rn2(8))) { - b_trapped("tin", 0); - costly_tin(COST_DSTROY); - goto use_up_tin; + b_trapped("tin", 0); + costly_tin(COST_DSTROY); + goto use_up_tin; } - pline1(mesg); /* "You succeed in opening the tin." */ + pline1(mesg); /* "You succeed in opening the tin." */ if (r != SPINACH_TIN) { - mnum = tin->corpsenm; - if (mnum == NON_PM) { - pline("It turns out to be empty."); - tin->dknown = tin->known = 1; - costly_tin(COST_OPEN); - goto use_up_tin; - } + mnum = tin->corpsenm; + if (mnum == NON_PM) { + pline("It turns out to be empty."); + tin->dknown = tin->known = 1; + costly_tin(COST_OPEN); + goto use_up_tin; + } - which = 0; /* 0=>plural, 1=>as-is, 2=>"the" prefix */ - if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) && - (Stone_resistance || Hallucination)) { - what = "chicken"; - which = 1; /* suppress pluralization */ - } else if (Hallucination) { - what = rndmonnam(NULL); - } else { - what = mons[mnum].mname; - if (the_unique_pm(&mons[mnum])) which = 2; - else if (type_is_pname(&mons[mnum])) which = 1; - } - if (which == 0) what = makeplural(what); - else if (which == 2) what = the(what); + which = 0; /* 0=>plural, 1=>as-is, 2=>"the" prefix */ + if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) + && (Stone_resistance || Hallucination)) { + what = "chicken"; + which = 1; /* suppress pluralization */ + } else if (Hallucination) { + what = rndmonnam(NULL); + } else { + what = mons[mnum].mname; + if (the_unique_pm(&mons[mnum])) + which = 2; + else if (type_is_pname(&mons[mnum])) + which = 1; + } + if (which == 0) + what = makeplural(what); + else if (which == 2) + what = the(what); - pline("It smells like %s.", what); - if (yn("Eat it?") == 'n') { - if (flags.verbose) You("discard the open tin."); - if (!Hallucination) tin->dknown = tin->known = 1; - costly_tin(COST_OPEN); - goto use_up_tin; - } + pline("It smells like %s.", what); + if (yn("Eat it?") == 'n') { + if (flags.verbose) + You("discard the open tin."); + if (!Hallucination) + tin->dknown = tin->known = 1; + costly_tin(COST_OPEN); + goto use_up_tin; + } - /* in case stop_occupation() was called on previous meal */ - context.victual.piece = (struct obj *)0; - context.victual.o_id = 0; - context.victual.fullwarn = context.victual.eating = - context.victual.doreset = FALSE; + /* in case stop_occupation() was called on previous meal */ + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + context.victual.fullwarn = context.victual.eating = + context.victual.doreset = FALSE; - You("consume %s %s.", tintxts[r].txt, mons[mnum].mname); + You("consume %s %s.", tintxts[r].txt, mons[mnum].mname); - eating_conducts(&mons[mnum]); + eating_conducts(&mons[mnum]); - tin->dknown = tin->known = 1; - cprefx(mnum); - cpostfx(mnum); + tin->dknown = tin->known = 1; + cprefx(mnum); + cpostfx(mnum); - /* charge for one at pre-eating cost */ - costly_tin(COST_OPEN); + /* charge for one at pre-eating cost */ + costly_tin(COST_OPEN); - if (tintxts[r].nut < 0) /* rotten */ - make_vomiting((long)rn1(15, 10), FALSE); - else - lesshungry(tintxts[r].nut); + if (tintxts[r].nut < 0) /* rotten */ + make_vomiting((long) rn1(15, 10), FALSE); + else + lesshungry(tintxts[r].nut); - if (tintxts[r].greasy) { - /* Assume !Glib, because you can't open tins when Glib. */ - incr_itimeout(&Glib, rnd(15)); - pline("Eating %s food made your %s very slippery.", - tintxts[r].txt, makeplural(body_part(FINGER))); - } + if (tintxts[r].greasy) { + /* Assume !Glib, because you can't open tins when Glib. */ + incr_itimeout(&Glib, rnd(15)); + pline("Eating %s food made your %s very slippery.", + tintxts[r].txt, makeplural(body_part(FINGER))); + } - } else { /* spinach... */ - if (tin->cursed) { - pline("It contains some decaying%s%s substance.", - Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN)); - } else { - pline("It contains spinach."); - tin->dknown = tin->known = 1; - } + } else { /* spinach... */ + if (tin->cursed) { + pline("It contains some decaying%s%s substance.", + Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN)); + } else { + pline("It contains spinach."); + tin->dknown = tin->known = 1; + } - if (yn("Eat it?") == 'n') { - if (flags.verbose) You("discard the open tin."); - costly_tin(COST_OPEN); - goto use_up_tin; - } + if (yn("Eat it?") == 'n') { + if (flags.verbose) + You("discard the open tin."); + costly_tin(COST_OPEN); + goto use_up_tin; + } - /* - * Same order as with non-spinach above: - * conduct update, side-effects, shop handling, and nutrition. - */ - u.uconduct.food++; /* don't need vegan/vegetarian checks for spinach */ - if (!tin->cursed) - pline("This makes you feel like %s!", - Hallucination ? "Swee'pea" : "Popeye"); - gainstr(tin, 0, FALSE); + /* + * Same order as with non-spinach above: + * conduct update, side-effects, shop handling, and nutrition. + */ + u.uconduct + .food++; /* don't need vegan/vegetarian checks for spinach */ + if (!tin->cursed) + pline("This makes you feel like %s!", + Hallucination ? "Swee'pea" : "Popeye"); + gainstr(tin, 0, FALSE); - costly_tin(COST_OPEN); + costly_tin(COST_OPEN); - lesshungry(tin->blessed ? 600 : /* blessed */ - !tin->cursed ? (400 + rnd(200)) : /* uncursed */ - (200 + rnd(400))); /* cursed */ + lesshungry(tin->blessed ? 600 : /* blessed */ + !tin->cursed ? (400 + rnd(200)) : /* uncursed */ + (200 + rnd(400))); /* cursed */ } - use_up_tin: +use_up_tin: if (carried(tin)) - useup(tin); + useup(tin); else - useupf(tin, 1L); - context.tin.tin = (struct obj *)0; + useupf(tin, 1L); + context.tin.tin = (struct obj *) 0; context.tin.o_id = 0; } STATIC_PTR -int -opentin(VOID_ARGS) /* called during each move whilst opening a tin */ +int opentin(VOID_ARGS) /* called during each move whilst opening a tin */ { - /* perhaps it was stolen (although that should cause interruption) */ - if (!carried(context.tin.tin) && - (!obj_here(context.tin.tin, u.ux, u.uy) || - !can_reach_floor(TRUE))) - return(0); /* %% probably we should use tinoid */ - if(context.tin.usedtime++ >= 50) { - You("give up your attempt to open the tin."); - return(0); - } - if(context.tin.usedtime < context.tin.reqtime) - return(1); /* still busy */ + /* perhaps it was stolen (although that should cause interruption) */ + if (!carried(context.tin.tin) + && (!obj_here(context.tin.tin, u.ux, u.uy) || !can_reach_floor(TRUE))) + return (0); /* %% probably we should use tinoid */ + if (context.tin.usedtime++ >= 50) { + You("give up your attempt to open the tin."); + return (0); + } + if (context.tin.usedtime < context.tin.reqtime) + return (1); /* still busy */ - consume_tin("You succeed in opening the tin."); - return(0); + consume_tin("You succeed in opening the tin."); + return (0); } -STATIC_OVL void -start_tin(otmp) /* called when starting to open a tin */ - register struct obj *otmp; +STATIC_OVL void start_tin(otmp) /* called when starting to open a tin */ +register struct obj *otmp; { - const char *mesg = 0; - register int tmp; + const char *mesg = 0; + register int tmp; - if (metallivorous(youmonst.data)) { - mesg = "You bite right into the metal tin..."; - tmp = 0; - } else if (cantwield(youmonst.data)) { /* nohands || verysmall */ - You("cannot handle the tin properly to open it."); - return; - } else if (otmp->blessed) { - /* 50/50 chance for immediate access vs 1 turn delay (unless - wielding blessed tin opener which always yields immediate - access); 1 turn delay case is non-deterministic: getting - interrupted and retrying might yield another 1 turn delay - or might open immediately on 2nd (or 3rd, 4th, ...) try */ - tmp = (uwep && uwep->blessed && uwep->otyp == TIN_OPENER) ? 0 : - rn2(2); - if (!tmp) - mesg = "The tin opens like magic!"; - else - pline_The("tin seems easy to open."); - } else if(uwep) { - switch(uwep->otyp) { - case TIN_OPENER: - mesg = "You easily open the tin."; /* iff tmp==0 */ - tmp = rn2(uwep->cursed ? 3 : !uwep->blessed ? 2 : 1); - break; - case DAGGER: - case SILVER_DAGGER: - case ELVEN_DAGGER: - case ORCISH_DAGGER: - case ATHAME: - case CRYSKNIFE: - tmp = 3; - break; - case PICK_AXE: - case AXE: - tmp = 6; - break; - default: - goto no_opener; - } - pline("Using %s you try to open the tin.", - yobjnam(uwep, (char *)0)); - } else { -no_opener: - pline("It is not so easy to open this tin."); - if(Glib) { - pline_The("tin slips from your %s.", - makeplural(body_part(FINGER))); - if(otmp->quan > 1L) { - otmp = splitobj(otmp, 1L); - } - if (carried(otmp)) dropx(otmp); - else stackobj(otmp); - return; - } - tmp = rn1(1 + 500/((int)(ACURR(A_DEX) + ACURRSTR)), 10); - } + if (metallivorous(youmonst.data)) { + mesg = "You bite right into the metal tin..."; + tmp = 0; + } else if (cantwield(youmonst.data)) { /* nohands || verysmall */ + You("cannot handle the tin properly to open it."); + return; + } else if (otmp->blessed) { + /* 50/50 chance for immediate access vs 1 turn delay (unless + wielding blessed tin opener which always yields immediate + access); 1 turn delay case is non-deterministic: getting + interrupted and retrying might yield another 1 turn delay + or might open immediately on 2nd (or 3rd, 4th, ...) try */ + tmp = + (uwep && uwep->blessed && uwep->otyp == TIN_OPENER) ? 0 : rn2(2); + if (!tmp) + mesg = "The tin opens like magic!"; + else + pline_The("tin seems easy to open."); + } else if (uwep) { + switch (uwep->otyp) { + case TIN_OPENER: + mesg = "You easily open the tin."; /* iff tmp==0 */ + tmp = rn2(uwep->cursed ? 3 : !uwep->blessed ? 2 : 1); + break; + case DAGGER: + case SILVER_DAGGER: + case ELVEN_DAGGER: + case ORCISH_DAGGER: + case ATHAME: + case CRYSKNIFE: + tmp = 3; + break; + case PICK_AXE: + case AXE: + tmp = 6; + break; + default: + goto no_opener; + } + pline("Using %s you try to open the tin.", yobjnam(uwep, (char *) 0)); + } else { + no_opener: + pline("It is not so easy to open this tin."); + if (Glib) { + pline_The("tin slips from your %s.", + makeplural(body_part(FINGER))); + if (otmp->quan > 1L) { + otmp = splitobj(otmp, 1L); + } + if (carried(otmp)) + dropx(otmp); + else + stackobj(otmp); + return; + } + tmp = rn1(1 + 500 / ((int) (ACURR(A_DEX) + ACURRSTR)), 10); + } - context.tin.tin = otmp; - context.tin.o_id = otmp->o_id; - if (!tmp) { - consume_tin(mesg); /* begin immediately */ - } else { - context.tin.reqtime = tmp; - context.tin.usedtime = 0; - set_occupation(opentin, "opening the tin", 0); - } - return; + context.tin.tin = otmp; + context.tin.o_id = otmp->o_id; + if (!tmp) { + consume_tin(mesg); /* begin immediately */ + } else { + context.tin.reqtime = tmp; + context.tin.usedtime = 0; + set_occupation(opentin, "opening the tin", 0); + } + return; } -int -Hear_again(VOID_ARGS) /* called when waking up after fainting */ +int Hear_again(VOID_ARGS) /* called when waking up after fainting */ { - /* Chance of deafness going away while fainted/sleepeing/etc. */ - if (!rn2(2)) - set_itimeout(&HDeaf, 0L); - return 0; + /* Chance of deafness going away while fainted/sleepeing/etc. */ + if (!rn2(2)) + set_itimeout(&HDeaf, 0L); + return 0; } /* called on the "first bite" of rotten food */ @@ -1449,197 +1474,207 @@ STATIC_OVL int rottenfood(obj) struct obj *obj; { - pline("Blecch! Rotten %s!", foodword(obj)); - if(!rn2(4)) { - if (Hallucination) You_feel("rather trippy."); - else You_feel("rather %s.", body_part(LIGHT_HEADED)); - make_confused(HConfusion + d(2,4),FALSE); - } else if(!rn2(4) && !Blind) { - pline("Everything suddenly goes dark."); - make_blinded((long)d(2,10),FALSE); - if (!Blind) Your1(vision_clears); - } else if(!rn2(3)) { - const char *what, *where; - int duration = rnd(10); + pline("Blecch! Rotten %s!", foodword(obj)); + if (!rn2(4)) { + if (Hallucination) + You_feel("rather trippy."); + else + You_feel("rather %s.", body_part(LIGHT_HEADED)); + make_confused(HConfusion + d(2, 4), FALSE); + } else if (!rn2(4) && !Blind) { + pline("Everything suddenly goes dark."); + make_blinded((long) d(2, 10), FALSE); + if (!Blind) + Your1(vision_clears); + } else if (!rn2(3)) { + const char *what, *where; + int duration = rnd(10); - if (!Blind) - what = "goes", where = "dark"; - else if (Levitation || Is_airlevel(&u.uz) || - Is_waterlevel(&u.uz)) - what = "you lose control of", where = "yourself"; - else - what = "you slap against the", where = - (u.usteed) ? "saddle" : - surface(u.ux,u.uy); - pline_The("world spins and %s %s.", what, where); - incr_itimeout(&HDeaf, duration); - nomul(-duration); - multi_reason = "unconscious from rotten food"; - nomovemsg = "You are conscious again."; - afternmv = Hear_again; - return(1); - } - return(0); + if (!Blind) + what = "goes", where = "dark"; + else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) + what = "you lose control of", where = "yourself"; + else + what = "you slap against the", + where = (u.usteed) ? "saddle" : surface(u.ux, u.uy); + pline_The("world spins and %s %s.", what, where); + incr_itimeout(&HDeaf, duration); + nomul(-duration); + multi_reason = "unconscious from rotten food"; + nomovemsg = "You are conscious again."; + afternmv = Hear_again; + return (1); + } + return (0); } -STATIC_OVL int -eatcorpse(otmp) /* called when a corpse is selected as food */ - register struct obj *otmp; +STATIC_OVL int eatcorpse(otmp) /* called when a corpse is selected as food */ +register struct obj *otmp; { - int tp = 0, mnum = otmp->corpsenm; - long rotted = 0L; - int retcode = 0; - boolean stoneable = (flesh_petrifies(&mons[mnum]) && - !Stone_resistance && - !poly_when_stoned(youmonst.data)); + int tp = 0, mnum = otmp->corpsenm; + long rotted = 0L; + int retcode = 0; + boolean stoneable = (flesh_petrifies(&mons[mnum]) && !Stone_resistance + && !poly_when_stoned(youmonst.data)); - /* KMH, conduct */ - if (!vegan(&mons[mnum])) u.uconduct.unvegan++; - if (!vegetarian(&mons[mnum])) violated_vegetarian(); + /* KMH, conduct */ + if (!vegan(&mons[mnum])) + u.uconduct.unvegan++; + if (!vegetarian(&mons[mnum])) + violated_vegetarian(); - if (!nonrotting_corpse(mnum)) { - long age = peek_at_iced_corpse_age(otmp); + if (!nonrotting_corpse(mnum)) { + long age = peek_at_iced_corpse_age(otmp); - rotted = (monstermoves - age)/(10L + rn2(20)); - if (otmp->cursed) rotted += 2L; - else if (otmp->blessed) rotted -= 2L; - } + rotted = (monstermoves - age) / (10L + rn2(20)); + if (otmp->cursed) + rotted += 2L; + else if (otmp->blessed) + rotted -= 2L; + } - if (mnum != PM_ACID_BLOB && !stoneable && rotted > 5L) { - boolean cannibal = maybe_cannibal(mnum, FALSE); - pline("Ulch - that %s was tainted%s!", - mons[mnum].mlet == S_FUNGUS ? "fungoid vegetation" : - !vegetarian(&mons[mnum]) ? "meat" : "protoplasm", - cannibal ? ", you cannibal" : ""); - if (Sick_resistance) { - pline("It doesn't seem at all sickening, though..."); - } else { - long sick_time; + if (mnum != PM_ACID_BLOB && !stoneable && rotted > 5L) { + boolean cannibal = maybe_cannibal(mnum, FALSE); + pline("Ulch - that %s was tainted%s!", + mons[mnum].mlet == S_FUNGUS + ? "fungoid vegetation" + : !vegetarian(&mons[mnum]) ? "meat" : "protoplasm", + cannibal ? ", you cannibal" : ""); + if (Sick_resistance) { + pline("It doesn't seem at all sickening, though..."); + } else { + long sick_time; - sick_time = (long) rn1(10, 10); - /* make sure new ill doesn't result in improvement */ - if (Sick && (sick_time > Sick)) - sick_time = (Sick > 1L) ? Sick - 1L : 1L; - make_sick(sick_time, - corpse_xname(otmp, "rotted", CXN_NORMAL), - TRUE, SICK_VOMITABLE); - } - if (carried(otmp)) useup(otmp); - else useupf(otmp, 1L); - return(2); - } else if (acidic(&mons[mnum]) && !Acid_resistance) { - tp++; - You("have a very bad case of stomach acid."); /* not body_part() */ - losehp(rnd(15), "acidic corpse", KILLED_BY_AN); /* acid damage */ - } else if (poisonous(&mons[mnum]) && rn2(5)) { - tp++; - pline("Ecch - that must have been poisonous!"); - if(!Poison_resistance) { - losestr(rnd(4)); - losehp(rnd(15), "poisonous corpse", KILLED_BY_AN); - } else You("seem unaffected by the poison."); - /* now any corpse left too long will make you mildly ill */ - } else if ((rotted > 5L || (rotted > 3L && rn2(5))) - && !Sick_resistance) { - tp++; - You_feel("%ssick.", (Sick) ? "very " : ""); - losehp(rnd(8), "cadaver", KILLED_BY_AN); - } + sick_time = (long) rn1(10, 10); + /* make sure new ill doesn't result in improvement */ + if (Sick && (sick_time > Sick)) + sick_time = (Sick > 1L) ? Sick - 1L : 1L; + make_sick(sick_time, corpse_xname(otmp, "rotted", CXN_NORMAL), + TRUE, SICK_VOMITABLE); + } + if (carried(otmp)) + useup(otmp); + else + useupf(otmp, 1L); + return (2); + } else if (acidic(&mons[mnum]) && !Acid_resistance) { + tp++; + You("have a very bad case of stomach acid."); /* not body_part() */ + losehp(rnd(15), "acidic corpse", KILLED_BY_AN); /* acid damage */ + } else if (poisonous(&mons[mnum]) && rn2(5)) { + tp++; + pline("Ecch - that must have been poisonous!"); + if (!Poison_resistance) { + losestr(rnd(4)); + losehp(rnd(15), "poisonous corpse", KILLED_BY_AN); + } else + You("seem unaffected by the poison."); + /* now any corpse left too long will make you mildly ill */ + } else if ((rotted > 5L || (rotted > 3L && rn2(5))) && !Sick_resistance) { + tp++; + You_feel("%ssick.", (Sick) ? "very " : ""); + losehp(rnd(8), "cadaver", KILLED_BY_AN); + } - /* delay is weight dependent */ - context.victual.reqtime = 3 + (mons[mnum].cwt >> 6); + /* delay is weight dependent */ + context.victual.reqtime = 3 + (mons[mnum].cwt >> 6); - if (!tp && !nonrotting_corpse(mnum) && (otmp->orotten || !rn2(7))) { - if (rottenfood(otmp)) { - otmp->orotten = TRUE; - (void)touchfood(otmp); - retcode = 1; - } + if (!tp && !nonrotting_corpse(mnum) && (otmp->orotten || !rn2(7))) { + if (rottenfood(otmp)) { + otmp->orotten = TRUE; + (void) touchfood(otmp); + retcode = 1; + } - if (!mons[otmp->corpsenm].cnutrit) { - /* no nutrution: rots away, no message if you passed out */ - if (!retcode) pline_The("corpse rots away completely."); - if (carried(otmp)) useup(otmp); - else useupf(otmp, 1L); - retcode = 2; - } - - if (!retcode) consume_oeaten(otmp, 2); /* oeaten >>= 2 */ - } else if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) && - (Stone_resistance || Hallucination)) { - pline("This tastes just like chicken!"); - } else if (mnum == PM_FLOATING_EYE && u.umonnum == PM_RAVEN) { - You("peck the eyeball with delight."); - } else { - /* [is this right? omnivores end up always disliking the taste] */ - boolean yummy = (vegan(&mons[mnum]) ? - (!carnivorous(youmonst.data) && - herbivorous(youmonst.data)) : - (carnivorous(youmonst.data) && - !herbivorous(youmonst.data))); + if (!mons[otmp->corpsenm].cnutrit) { + /* no nutrution: rots away, no message if you passed out */ + if (!retcode) + pline_The("corpse rots away completely."); + if (carried(otmp)) + useup(otmp); + else + useupf(otmp, 1L); + retcode = 2; + } - pline("%s%s %s!", - type_is_pname(&mons[mnum]) ? "" : - the_unique_pm(&mons[mnum]) ? "The " : "This ", - food_xname(otmp, FALSE), - Hallucination ? - (yummy ? ((u.umonnum == PM_TIGER) ? "is gr-r-reat" : - "is gnarly") : "is grody") : - (yummy ? "is delicious" : "tastes terrible")); - } + if (!retcode) + consume_oeaten(otmp, 2); /* oeaten >>= 2 */ + } else if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) + && (Stone_resistance || Hallucination)) { + pline("This tastes just like chicken!"); + } else if (mnum == PM_FLOATING_EYE && u.umonnum == PM_RAVEN) { + You("peck the eyeball with delight."); + } else { + /* [is this right? omnivores end up always disliking the taste] */ + boolean yummy = + (vegan(&mons[mnum]) + ? (!carnivorous(youmonst.data) && herbivorous(youmonst.data)) + : (carnivorous(youmonst.data) + && !herbivorous(youmonst.data))); - return(retcode); + pline("%s%s %s!", type_is_pname(&mons[mnum]) + ? "" + : the_unique_pm(&mons[mnum]) ? "The " : "This ", + food_xname(otmp, FALSE), + Hallucination + ? (yummy ? ((u.umonnum == PM_TIGER) ? "is gr-r-reat" + : "is gnarly") + : "is grody") + : (yummy ? "is delicious" : "tastes terrible")); + } + + return (retcode); } -STATIC_OVL void -start_eating(otmp) /* called as you start to eat */ - register struct obj *otmp; +STATIC_OVL void start_eating(otmp) /* called as you start to eat */ +register struct obj *otmp; { - const char *old_nomovemsg, *save_nomovemsg; + const char *old_nomovemsg, *save_nomovemsg; - debugpline2("start_eating: %lx (victual = %lx)", - (unsigned long)otmp, (unsigned long)context.victual.piece); - debugpline1("reqtime = %d", context.victual.reqtime); - debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay); - debugpline1("nmod = %d", context.victual.nmod); - debugpline1("oeaten = %d", otmp->oeaten); - context.victual.fullwarn = context.victual.doreset = FALSE; - context.victual.eating = TRUE; + debugpline2("start_eating: %lx (victual = %lx)", (unsigned long) otmp, + (unsigned long) context.victual.piece); + debugpline1("reqtime = %d", context.victual.reqtime); + debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay); + debugpline1("nmod = %d", context.victual.nmod); + debugpline1("oeaten = %d", otmp->oeaten); + context.victual.fullwarn = context.victual.doreset = FALSE; + context.victual.eating = TRUE; - if (otmp->otyp == CORPSE || otmp->globby) { - cprefx(context.victual.piece->corpsenm); - if (!context.victual.piece || !context.victual.eating) { - /* rider revived, or died and lifesaved */ - return; - } - } + if (otmp->otyp == CORPSE || otmp->globby) { + cprefx(context.victual.piece->corpsenm); + if (!context.victual.piece || !context.victual.eating) { + /* rider revived, or died and lifesaved */ + return; + } + } - old_nomovemsg = nomovemsg; - if (bite()) { - /* survived choking, finish off food that's nearly done; - need this to handle cockatrice eggs, fortune cookies, etc */ - if (++context.victual.usedtime >= context.victual.reqtime) { - /* don't want done_eating() to issue nomovemsg if it - is due to vomit() called by bite() */ - save_nomovemsg = nomovemsg; - if (!old_nomovemsg) nomovemsg = 0; - done_eating(FALSE); - if (!old_nomovemsg) nomovemsg = save_nomovemsg; - } - return; - } + old_nomovemsg = nomovemsg; + if (bite()) { + /* survived choking, finish off food that's nearly done; + need this to handle cockatrice eggs, fortune cookies, etc */ + if (++context.victual.usedtime >= context.victual.reqtime) { + /* don't want done_eating() to issue nomovemsg if it + is due to vomit() called by bite() */ + save_nomovemsg = nomovemsg; + if (!old_nomovemsg) + nomovemsg = 0; + done_eating(FALSE); + if (!old_nomovemsg) + nomovemsg = save_nomovemsg; + } + return; + } - if (++context.victual.usedtime >= context.victual.reqtime) { - /* print "finish eating" message if they just resumed -dlc */ - done_eating(context.victual.reqtime > 1 ? TRUE : FALSE); - return; - } + if (++context.victual.usedtime >= context.victual.reqtime) { + /* print "finish eating" message if they just resumed -dlc */ + done_eating(context.victual.reqtime > 1 ? TRUE : FALSE); + return; + } - Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE)); - set_occupation(eatfood, msgbuf, 0); + Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE)); + set_occupation(eatfood, msgbuf, 0); } - /* * called on "first bite" of (non-corpse) food. * used for non-rotten non-tin non-corpse food @@ -1648,86 +1683,87 @@ STATIC_OVL void fprefx(otmp) struct obj *otmp; { - switch(otmp->otyp) { - case FOOD_RATION: - if(u.uhunger <= 200) - pline(Hallucination ? "Oh wow, like, superior, man!" : - "That food really hit the spot!"); - else if(u.uhunger <= 700) pline("That satiated your %s!", - body_part(STOMACH)); - break; - case TRIPE_RATION: - if (carnivorous(youmonst.data) && !humanoid(youmonst.data)) - pline("That tripe ration was surprisingly good!"); - else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) - pline(Hallucination ? "Tastes great! Less filling!" : - "Mmm, tripe... not bad!"); - else { - pline("Yak - dog food!"); - more_experienced(1,0); - newexplevel(); - /* not cannibalism, but we use similar criteria - for deciding whether to be sickened by this meal */ - if (rn2(2) && !CANNIBAL_ALLOWED()) - make_vomiting((long)rn1(context.victual.reqtime, 14), FALSE); - } - break; - case MEATBALL: - case MEAT_STICK: - case HUGE_CHUNK_OF_MEAT: - case MEAT_RING: - goto give_feedback; - /* break; */ - case CLOVE_OF_GARLIC: - if (is_undead(youmonst.data)) { - make_vomiting((long)rn1(context.victual.reqtime, 5), FALSE); - break; - } - /* Fall through otherwise */ - default: - if (otmp->otyp == SLIME_MOLD && !otmp->cursed && - otmp->spe == context.current_fruit) - pline("My, that was a %s %s!", - Hallucination ? "primo" : "yummy", - singular(otmp, xname)); - else if (otmp->otyp == APPLE && otmp->cursed && - !Sleep_resistance) - ; /* skip core joke; feedback deferred til fpostfx() */ - else + switch (otmp->otyp) { + case FOOD_RATION: + if (u.uhunger <= 200) + pline(Hallucination ? "Oh wow, like, superior, man!" + : "That food really hit the spot!"); + else if (u.uhunger <= 700) + pline("That satiated your %s!", body_part(STOMACH)); + break; + case TRIPE_RATION: + if (carnivorous(youmonst.data) && !humanoid(youmonst.data)) + pline("That tripe ration was surprisingly good!"); + else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) + pline(Hallucination ? "Tastes great! Less filling!" + : "Mmm, tripe... not bad!"); + else { + pline("Yak - dog food!"); + more_experienced(1, 0); + newexplevel(); + /* not cannibalism, but we use similar criteria + for deciding whether to be sickened by this meal */ + if (rn2(2) && !CANNIBAL_ALLOWED()) + make_vomiting((long) rn1(context.victual.reqtime, 14), FALSE); + } + break; + case MEATBALL: + case MEAT_STICK: + case HUGE_CHUNK_OF_MEAT: + case MEAT_RING: + goto give_feedback; + /* break; */ + case CLOVE_OF_GARLIC: + if (is_undead(youmonst.data)) { + make_vomiting((long) rn1(context.victual.reqtime, 5), FALSE); + break; + } + /* Fall through otherwise */ + default: + if (otmp->otyp == SLIME_MOLD && !otmp->cursed + && otmp->spe == context.current_fruit) + pline("My, that was a %s %s!", Hallucination ? "primo" : "yummy", + singular(otmp, xname)); + else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) + ; /* skip core joke; feedback deferred til fpostfx() */ + else #ifdef UNIX - if (otmp->otyp == APPLE || otmp->otyp == PEAR) { - if (!Hallucination) { - pline("Core dumped."); - } else { -/* This is based on an old Usenet joke, a fake a.out manual page */ - int x = rnd(100); - if (x <= 75) - pline("Segmentation fault -- core dumped."); - else if (x <= 99) - pline("Bus error -- core dumped."); - else pline("Yo' mama -- core dumped."); - } - } else + if (otmp->otyp == APPLE || otmp->otyp == PEAR) { + if (!Hallucination) { + pline("Core dumped."); + } else { + /* This is based on an old Usenet joke, a fake a.out manual + * page */ + int x = rnd(100); + if (x <= 75) + pline("Segmentation fault -- core dumped."); + else if (x <= 99) + pline("Bus error -- core dumped."); + else + pline("Yo' mama -- core dumped."); + } + } else #endif -#if defined(MAC) || defined(MACOSX) /* KMH -- Why should Unix have all the fun? */ - if (otmp->otyp == APPLE) { - pline("Delicious! Must be a Macintosh!"); - } else +#if defined(MAC) \ + || defined(MACOSX) /* KMH -- Why should Unix have all the fun? */ + if (otmp->otyp == APPLE) { + pline("Delicious! Must be a Macintosh!"); + } else #endif - if (otmp->otyp == EGG && stale_egg(otmp)) { - pline("Ugh. Rotten egg."); /* perhaps others like it */ - make_vomiting((Vomiting & TIMEOUT) + (long)d(10,4), TRUE); - } else - give_feedback: - pline("This %s is %s", singular(otmp, xname), - otmp->cursed ? (Hallucination ? "grody!" : "terrible!") : - (otmp->otyp == CRAM_RATION - || otmp->otyp == K_RATION - || otmp->otyp == C_RATION) - ? "bland." : - Hallucination ? "gnarly!" : "delicious!"); - break; - } + if (otmp->otyp == EGG && stale_egg(otmp)) { + pline("Ugh. Rotten egg."); /* perhaps others like it */ + make_vomiting((Vomiting & TIMEOUT) + (long) d(10, 4), TRUE); + } else + give_feedback: + pline("This %s is %s", singular(otmp, xname), + otmp->cursed + ? (Hallucination ? "grody!" : "terrible!") + : (otmp->otyp == CRAM_RATION || otmp->otyp == K_RATION + || otmp->otyp == C_RATION) + ? "bland." + : Hallucination ? "gnarly!" : "delicious!"); + break; + } } /* increment a combat intrinsic with limits on its growth */ @@ -1738,23 +1774,27 @@ int old, inc, typ; int absold, absinc, sgnold, sgninc; /* don't include any amount coming from worn rings */ - if (uright && uright->otyp == typ) old -= uright->spe; - if (uleft && uleft->otyp == typ) old -= uleft->spe; + if (uright && uright->otyp == typ) + old -= uright->spe; + if (uleft && uleft->otyp == typ) + old -= uleft->spe; absold = abs(old), absinc = abs(inc); sgnold = sgn(old), sgninc = sgn(inc); if (absinc == 0 || sgnold != sgninc || absold + absinc < 10) { - ; /* use inc as-is */ + ; /* use inc as-is */ } else if (absold + absinc < 20) { - absinc = rnd(absinc); /* 1..n */ - if (absold + absinc < 10) absinc = 10 - absold; - inc = sgninc * absinc; + absinc = rnd(absinc); /* 1..n */ + if (absold + absinc < 10) + absinc = 10 - absold; + inc = sgninc * absinc; } else if (absold + absinc < 40) { - absinc = rn2(absinc) ? 1 : 0; - if (absold + absinc < 20) absinc = rnd(20 - absold); - inc = sgninc * absinc; + absinc = rn2(absinc) ? 1 : 0; + if (absold + absinc < 20) + absinc = rnd(20 - absold); + inc = sgninc * absinc; } else { - inc = 0; /* no further increase allowed via this method */ + inc = 0; /* no further increase allowed via this method */ } return old + inc; } @@ -1763,310 +1803,317 @@ STATIC_OVL void accessory_has_effect(otmp) struct obj *otmp; { - pline("Magic spreads through your body as you digest the %s.", - otmp->oclass == RING_CLASS ? "ring" : "amulet"); + pline("Magic spreads through your body as you digest the %s.", + otmp->oclass == RING_CLASS ? "ring" : "amulet"); } STATIC_OVL void eataccessory(otmp) struct obj *otmp; { - int typ = otmp->otyp; - long oldprop; + int typ = otmp->otyp; + long oldprop; - /* Note: rings are not so common that this is unbalancing. */ - /* (How often do you even _find_ 3 rings of polymorph in a game?) */ - oldprop = u.uprops[objects[typ].oc_oprop].intrinsic; - if (otmp == uleft || otmp == uright) { - Ring_gone(otmp); - if (u.uhp <= 0) return; /* died from sink fall */ - } - otmp->known = otmp->dknown = 1; /* by taste */ - if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) { - switch (otmp->otyp) { - default: - if (!objects[typ].oc_oprop) break; /* should never happen */ + /* Note: rings are not so common that this is unbalancing. */ + /* (How often do you even _find_ 3 rings of polymorph in a game?) */ + oldprop = u.uprops[objects[typ].oc_oprop].intrinsic; + if (otmp == uleft || otmp == uright) { + Ring_gone(otmp); + if (u.uhp <= 0) + return; /* died from sink fall */ + } + otmp->known = otmp->dknown = 1; /* by taste */ + if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) { + switch (otmp->otyp) { + default: + if (!objects[typ].oc_oprop) + break; /* should never happen */ - if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE)) - accessory_has_effect(otmp); + if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE)) + accessory_has_effect(otmp); - u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE; + u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE; - switch (typ) { - case RIN_SEE_INVISIBLE: - set_mimic_blocking(); - see_monsters(); - if (Invis && !oldprop && !ESee_invisible && - !perceives(youmonst.data) && !Blind) { - newsym(u.ux,u.uy); - pline("Suddenly you can see yourself."); - makeknown(typ); - } - break; - case RIN_INVISIBILITY: - if (!oldprop && !EInvis && !BInvis && - !See_invisible && !Blind) { - newsym(u.ux,u.uy); - Your("body takes on a %s transparency...", - Hallucination ? "normal" : "strange"); - makeknown(typ); - } - break; - case RIN_PROTECTION_FROM_SHAPE_CHAN: - rescham(); - break; - case RIN_LEVITATION: - /* undo the `.intrinsic |= FROMOUTSIDE' done above */ - u.uprops[LEVITATION].intrinsic = oldprop; - if (!Levitation) { - float_up(); - incr_itimeout(&HLevitation, d(10,20)); - makeknown(typ); - } - break; - } - break; - case RIN_ADORNMENT: - accessory_has_effect(otmp); - if (adjattrib(A_CHA, otmp->spe, -1)) - makeknown(typ); - break; - case RIN_GAIN_STRENGTH: - accessory_has_effect(otmp); - if (adjattrib(A_STR, otmp->spe, -1)) - makeknown(typ); - break; - case RIN_GAIN_CONSTITUTION: - accessory_has_effect(otmp); - if (adjattrib(A_CON, otmp->spe, -1)) - makeknown(typ); - break; - case RIN_INCREASE_ACCURACY: - accessory_has_effect(otmp); - u.uhitinc = (schar)bounded_increase((int)u.uhitinc, otmp->spe, - RIN_INCREASE_ACCURACY); - break; - case RIN_INCREASE_DAMAGE: - accessory_has_effect(otmp); - u.udaminc = (schar)bounded_increase((int)u.udaminc, otmp->spe, - RIN_INCREASE_DAMAGE); - break; - case RIN_PROTECTION: - accessory_has_effect(otmp); - HProtection |= FROMOUTSIDE; - u.ublessed = bounded_increase(u.ublessed, otmp->spe, - RIN_PROTECTION); - context.botl = 1; - break; - case RIN_FREE_ACTION: - /* Give sleep resistance instead */ - if (!(HSleep_resistance & FROMOUTSIDE)) - accessory_has_effect(otmp); - if (!Sleep_resistance) - You_feel("wide awake."); - HSleep_resistance |= FROMOUTSIDE; - break; - case AMULET_OF_CHANGE: - accessory_has_effect(otmp); - makeknown(typ); - change_sex(); - You("are suddenly very %s!", - flags.female ? "feminine" : "masculine"); - context.botl = 1; - break; - case AMULET_OF_UNCHANGING: - /* un-change: it's a pun */ - if (!Unchanging && Upolyd) { - accessory_has_effect(otmp); - makeknown(typ); - rehumanize(); - } - break; - case AMULET_OF_STRANGULATION: /* bad idea! */ - /* no message--this gives no permanent effect */ - choke(otmp); - break; - case AMULET_OF_RESTFUL_SLEEP: /* another bad idea! */ - { - long newnap = (long)rnd(100), oldnap = (HSleepy & TIMEOUT); + switch (typ) { + case RIN_SEE_INVISIBLE: + set_mimic_blocking(); + see_monsters(); + if (Invis && !oldprop && !ESee_invisible + && !perceives(youmonst.data) && !Blind) { + newsym(u.ux, u.uy); + pline("Suddenly you can see yourself."); + makeknown(typ); + } + break; + case RIN_INVISIBILITY: + if (!oldprop && !EInvis && !BInvis && !See_invisible + && !Blind) { + newsym(u.ux, u.uy); + Your("body takes on a %s transparency...", + Hallucination ? "normal" : "strange"); + makeknown(typ); + } + break; + case RIN_PROTECTION_FROM_SHAPE_CHAN: + rescham(); + break; + case RIN_LEVITATION: + /* undo the `.intrinsic |= FROMOUTSIDE' done above */ + u.uprops[LEVITATION].intrinsic = oldprop; + if (!Levitation) { + float_up(); + incr_itimeout(&HLevitation, d(10, 20)); + makeknown(typ); + } + break; + } + break; + case RIN_ADORNMENT: + accessory_has_effect(otmp); + if (adjattrib(A_CHA, otmp->spe, -1)) + makeknown(typ); + break; + case RIN_GAIN_STRENGTH: + accessory_has_effect(otmp); + if (adjattrib(A_STR, otmp->spe, -1)) + makeknown(typ); + break; + case RIN_GAIN_CONSTITUTION: + accessory_has_effect(otmp); + if (adjattrib(A_CON, otmp->spe, -1)) + makeknown(typ); + break; + case RIN_INCREASE_ACCURACY: + accessory_has_effect(otmp); + u.uhitinc = (schar) bounded_increase((int) u.uhitinc, otmp->spe, + RIN_INCREASE_ACCURACY); + break; + case RIN_INCREASE_DAMAGE: + accessory_has_effect(otmp); + u.udaminc = (schar) bounded_increase((int) u.udaminc, otmp->spe, + RIN_INCREASE_DAMAGE); + break; + case RIN_PROTECTION: + accessory_has_effect(otmp); + HProtection |= FROMOUTSIDE; + u.ublessed = + bounded_increase(u.ublessed, otmp->spe, RIN_PROTECTION); + context.botl = 1; + break; + case RIN_FREE_ACTION: + /* Give sleep resistance instead */ + if (!(HSleep_resistance & FROMOUTSIDE)) + accessory_has_effect(otmp); + if (!Sleep_resistance) + You_feel("wide awake."); + HSleep_resistance |= FROMOUTSIDE; + break; + case AMULET_OF_CHANGE: + accessory_has_effect(otmp); + makeknown(typ); + change_sex(); + You("are suddenly very %s!", + flags.female ? "feminine" : "masculine"); + context.botl = 1; + break; + case AMULET_OF_UNCHANGING: + /* un-change: it's a pun */ + if (!Unchanging && Upolyd) { + accessory_has_effect(otmp); + makeknown(typ); + rehumanize(); + } + break; + case AMULET_OF_STRANGULATION: /* bad idea! */ + /* no message--this gives no permanent effect */ + choke(otmp); + break; + case AMULET_OF_RESTFUL_SLEEP: /* another bad idea! */ + { + long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT); - if (!(HSleepy & FROMOUTSIDE)) - accessory_has_effect(otmp); - HSleepy |= FROMOUTSIDE; - /* might also be wearing one; use shorter of two timeouts */ - if (newnap < oldnap || oldnap == 0L) - HSleepy = (HSleepy & ~TIMEOUT) | newnap; - } - break; - case RIN_SUSTAIN_ABILITY: - case AMULET_OF_LIFE_SAVING: - case AMULET_OF_REFLECTION: /* nice try */ - /* can't eat Amulet of Yendor or fakes, - * and no oc_prop even if you could -3. - */ - break; - } - } + if (!(HSleepy & FROMOUTSIDE)) + accessory_has_effect(otmp); + HSleepy |= FROMOUTSIDE; + /* might also be wearing one; use shorter of two timeouts */ + if (newnap < oldnap || oldnap == 0L) + HSleepy = (HSleepy & ~TIMEOUT) | newnap; + } break; + case RIN_SUSTAIN_ABILITY: + case AMULET_OF_LIFE_SAVING: + case AMULET_OF_REFLECTION: /* nice try */ + /* can't eat Amulet of Yendor or fakes, + * and no oc_prop even if you could -3. + */ + break; + } + } } -STATIC_OVL void -eatspecial() /* called after eating non-food */ +STATIC_OVL void eatspecial() /* called after eating non-food */ { - register struct obj *otmp = context.victual.piece; + register struct obj *otmp = context.victual.piece; - /* lesshungry wants an occupation to handle choke messages correctly */ - set_occupation(eatfood, "eating non-food", 0); - lesshungry(context.victual.nmod); - occupation = 0; - context.victual.piece = (struct obj *)0; - context.victual.o_id = 0; - context.victual.eating = 0; - if (otmp->oclass == COIN_CLASS) { - if (carried(otmp)) - useupall(otmp); - else - useupf(otmp, otmp->quan); - vault_gd_watching(GD_EATGOLD); - return; - } + /* lesshungry wants an occupation to handle choke messages correctly */ + set_occupation(eatfood, "eating non-food", 0); + lesshungry(context.victual.nmod); + occupation = 0; + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + context.victual.eating = 0; + if (otmp->oclass == COIN_CLASS) { + if (carried(otmp)) + useupall(otmp); + else + useupf(otmp, otmp->quan); + vault_gd_watching(GD_EATGOLD); + return; + } #ifdef MAIL - if (otmp->otyp == SCR_MAIL) { - /* no nutrition */ - pline("This junk mail is less than satisfying."); - } + if (otmp->otyp == SCR_MAIL) { + /* no nutrition */ + pline("This junk mail is less than satisfying."); + } #endif - if (otmp->oclass == POTION_CLASS) { - otmp->quan++; /* dopotion() does a useup() */ - (void)dopotion(otmp); - } - if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) - eataccessory(otmp); - else if (otmp->otyp == LEASH && otmp->leashmon) - o_unleash(otmp); + if (otmp->oclass == POTION_CLASS) { + otmp->quan++; /* dopotion() does a useup() */ + (void) dopotion(otmp); + } + if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) + eataccessory(otmp); + else if (otmp->otyp == LEASH && otmp->leashmon) + o_unleash(otmp); - /* KMH -- idea by "Tommy the Terrorist" */ - if ((otmp->otyp == TRIDENT) && !otmp->cursed) - { - pline(Hallucination ? "Four out of five dentists agree." : - "That was pure chewing satisfaction!"); - exercise(A_WIS, TRUE); - } - if ((otmp->otyp == FLINT) && !otmp->cursed) - { - pline("Yabba-dabba delicious!"); - exercise(A_CON, TRUE); - } + /* KMH -- idea by "Tommy the Terrorist" */ + if ((otmp->otyp == TRIDENT) && !otmp->cursed) { + pline(Hallucination ? "Four out of five dentists agree." + : "That was pure chewing satisfaction!"); + exercise(A_WIS, TRUE); + } + if ((otmp->otyp == FLINT) && !otmp->cursed) { + pline("Yabba-dabba delicious!"); + exercise(A_CON, TRUE); + } - if (otmp == uwep && otmp->quan == 1L) uwepgone(); - if (otmp == uquiver && otmp->quan == 1L) uqwepgone(); - if (otmp == uswapwep && otmp->quan == 1L) uswapwepgone(); + if (otmp == uwep && otmp->quan == 1L) + uwepgone(); + if (otmp == uquiver && otmp->quan == 1L) + uqwepgone(); + if (otmp == uswapwep && otmp->quan == 1L) + uswapwepgone(); - if (otmp == uball) unpunish(); - if (otmp == uchain) unpunish(); /* but no useup() */ - else if (carried(otmp)) useup(otmp); - else useupf(otmp, 1L); + if (otmp == uball) + unpunish(); + if (otmp == uchain) + unpunish(); /* but no useup() */ + else if (carried(otmp)) + useup(otmp); + else + useupf(otmp, 1L); } /* NOTE: the order of these words exactly corresponds to the order of oc_material values #define'd in objclass.h. */ static const char *foodwords[] = { - "meal", "liquid", "wax", "food", "meat", - "paper", "cloth", "leather", "wood", "bone", "scale", - "metal", "metal", "metal", "silver", "gold", "platinum", "mithril", - "plastic", "glass", "rich food", "stone" + "meal", "liquid", "wax", "food", "meat", "paper", + "cloth", "leather", "wood", "bone", "scale", "metal", + "metal", "metal", "silver", "gold", "platinum", "mithril", + "plastic", "glass", "rich food", "stone" }; STATIC_OVL const char * foodword(otmp) register struct obj *otmp; { - if (otmp->oclass == FOOD_CLASS) return "food"; - if (otmp->oclass == GEM_CLASS && - objects[otmp->otyp].oc_material == GLASS && - otmp->dknown) - makeknown(otmp->otyp); - return foodwords[objects[otmp->otyp].oc_material]; + if (otmp->oclass == FOOD_CLASS) + return "food"; + if (otmp->oclass == GEM_CLASS && objects[otmp->otyp].oc_material == GLASS + && otmp->dknown) + makeknown(otmp->otyp); + return foodwords[objects[otmp->otyp].oc_material]; } -STATIC_OVL void -fpostfx(otmp) /* called after consuming (non-corpse) food */ +STATIC_OVL void fpostfx(otmp) /* called after consuming (non-corpse) food */ register struct obj *otmp; { - switch(otmp->otyp) { - case SPRIG_OF_WOLFSBANE: - if (u.ulycn >= LOW_PM || is_were(youmonst.data)) - you_unwere(TRUE); - break; - case CARROT: - if (!u.uswallow || - !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) - make_blinded((long)u.ucreamed,TRUE); - break; - case FORTUNE_COOKIE: - outrumor(bcsign(otmp), BY_COOKIE); - if (!Blind) u.uconduct.literate++; - break; - case LUMP_OF_ROYAL_JELLY: - /* This stuff seems to be VERY healthy! */ - gainstr(otmp, 1, TRUE); - if (Upolyd) { - u.mh += otmp->cursed ? -rnd(20) : rnd(20); - if (u.mh > u.mhmax) { - if (!rn2(17)) u.mhmax++; - u.mh = u.mhmax; - } else if (u.mh <= 0) { - rehumanize(); - } - } else { - u.uhp += otmp->cursed ? -rnd(20) : rnd(20); - if (u.uhp > u.uhpmax) { - if(!rn2(17)) u.uhpmax++; - u.uhp = u.uhpmax; - } else if (u.uhp <= 0) { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "rotten lump of royal jelly"); - done(POISONING); - } - } - if(!otmp->cursed) heal_legs(); - break; - case EGG: - if (flesh_petrifies(&mons[otmp->corpsenm])) { - if (!Stone_resistance && - !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - if (!Stoned) { - Sprintf(killer.name, - "%s egg", mons[otmp->corpsenm].mname); - make_stoned(5L, (char *)0, - KILLED_BY_AN, killer.name); - } - } - /* note: no "tastes like chicken" message for eggs */ - } - break; - case EUCALYPTUS_LEAF: - if (Sick && !otmp->cursed) - make_sick(0L, (char *)0, TRUE, SICK_ALL); - if (Vomiting && !otmp->cursed) - make_vomiting(0L, TRUE); - break; - case APPLE: - if (otmp->cursed && !Sleep_resistance) { - /* Snow White; 'poisoned' applies to [a subset of] weapons, - not food, so we substitute cursed; fortunately our hero - won't have to wait for a prince to be rescued/revived */ - if (Race_if(PM_DWARF) && Hallucination) - verbalize("Heigh-ho, ho-hum, I think I'll skip work today."); - else if (Deaf || !flags.acoustics) - You("fall asleep."); - else - You_hear("sinister laughter as you fall asleep..."); - fall_asleep(-rn1(11, 20), TRUE); - } - break; - } - return; + switch (otmp->otyp) { + case SPRIG_OF_WOLFSBANE: + if (u.ulycn >= LOW_PM || is_were(youmonst.data)) + you_unwere(TRUE); + break; + case CARROT: + if (!u.uswallow + || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) + make_blinded((long) u.ucreamed, TRUE); + break; + case FORTUNE_COOKIE: + outrumor(bcsign(otmp), BY_COOKIE); + if (!Blind) + u.uconduct.literate++; + break; + case LUMP_OF_ROYAL_JELLY: + /* This stuff seems to be VERY healthy! */ + gainstr(otmp, 1, TRUE); + if (Upolyd) { + u.mh += otmp->cursed ? -rnd(20) : rnd(20); + if (u.mh > u.mhmax) { + if (!rn2(17)) + u.mhmax++; + u.mh = u.mhmax; + } else if (u.mh <= 0) { + rehumanize(); + } + } else { + u.uhp += otmp->cursed ? -rnd(20) : rnd(20); + if (u.uhp > u.uhpmax) { + if (!rn2(17)) + u.uhpmax++; + u.uhp = u.uhpmax; + } else if (u.uhp <= 0) { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "rotten lump of royal jelly"); + done(POISONING); + } + } + if (!otmp->cursed) + heal_legs(); + break; + case EGG: + if (flesh_petrifies(&mons[otmp->corpsenm])) { + if (!Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + if (!Stoned) { + Sprintf(killer.name, "%s egg", + mons[otmp->corpsenm].mname); + make_stoned(5L, (char *) 0, KILLED_BY_AN, killer.name); + } + } + /* note: no "tastes like chicken" message for eggs */ + } + break; + case EUCALYPTUS_LEAF: + if (Sick && !otmp->cursed) + make_sick(0L, (char *) 0, TRUE, SICK_ALL); + if (Vomiting && !otmp->cursed) + make_vomiting(0L, TRUE); + break; + case APPLE: + if (otmp->cursed && !Sleep_resistance) { + /* Snow White; 'poisoned' applies to [a subset of] weapons, + not food, so we substitute cursed; fortunately our hero + won't have to wait for a prince to be rescued/revived */ + if (Race_if(PM_DWARF) && Hallucination) + verbalize("Heigh-ho, ho-hum, I think I'll skip work today."); + else if (Deaf || !flags.acoustics) + You("fall asleep."); + else + You_hear("sinister laughter as you fall asleep..."); + fall_asleep(-rn1(11, 20), TRUE); + } + break; + } + return; } #if 0 @@ -2098,375 +2145,404 @@ STATIC_OVL int edibility_prompts(otmp) struct obj *otmp; { - /* blessed food detection granted you a one-use - ability to detect food that is unfit for consumption - or dangerous and avoid it. */ + /* blessed food detection granted you a one-use + ability to detect food that is unfit for consumption + or dangerous and avoid it. */ - char buf[BUFSZ], foodsmell[BUFSZ], - it_or_they[QBUFSZ], eat_it_anyway[QBUFSZ]; - boolean cadaver = (otmp->otyp == CORPSE), - stoneorslime = FALSE; - int material = objects[otmp->otyp].oc_material, - mnum = otmp->corpsenm; - long rotted = 0L; + char buf[BUFSZ], foodsmell[BUFSZ], it_or_they[QBUFSZ], + eat_it_anyway[QBUFSZ]; + boolean cadaver = (otmp->otyp == CORPSE), stoneorslime = FALSE; + int material = objects[otmp->otyp].oc_material, mnum = otmp->corpsenm; + long rotted = 0L; - Strcpy(foodsmell, Tobjnam(otmp, "smell")); - Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they"); - Sprintf(eat_it_anyway, "Eat %s anyway?", - (otmp->quan == 1L) ? "it" : "one"); + Strcpy(foodsmell, Tobjnam(otmp, "smell")); + Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they"); + Sprintf(eat_it_anyway, "Eat %s anyway?", + (otmp->quan == 1L) ? "it" : "one"); - if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN) { - /* These checks must match those in eatcorpse() */ - stoneorslime = (flesh_petrifies(&mons[mnum]) && - !Stone_resistance && - !poly_when_stoned(youmonst.data)); + if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN) { + /* These checks must match those in eatcorpse() */ + stoneorslime = (flesh_petrifies(&mons[mnum]) && !Stone_resistance + && !poly_when_stoned(youmonst.data)); - if (mnum == PM_GREEN_SLIME || otmp->otyp == GLOB_OF_GREEN_SLIME) - stoneorslime = (!Unchanging && !slimeproof(youmonst.data)); + if (mnum == PM_GREEN_SLIME || otmp->otyp == GLOB_OF_GREEN_SLIME) + stoneorslime = (!Unchanging && !slimeproof(youmonst.data)); - if (cadaver && !nonrotting_corpse(mnum)) { - long age = peek_at_iced_corpse_age(otmp); - /* worst case rather than random - in this calculation to force prompt */ - rotted = (monstermoves - age)/(10L + 0 /* was rn2(20) */); - if (otmp->cursed) rotted += 2L; - else if (otmp->blessed) rotted -= 2L; - } - } + if (cadaver && !nonrotting_corpse(mnum)) { + long age = peek_at_iced_corpse_age(otmp); + /* worst case rather than random + in this calculation to force prompt */ + rotted = (monstermoves - age) / (10L + 0 /* was rn2(20) */); + if (otmp->cursed) + rotted += 2L; + else if (otmp->blessed) + rotted -= 2L; + } + } - /* - * These problems with food should be checked in - * order from most detrimental to least detrimental. - */ + /* + * These problems with food should be checked in + * order from most detrimental to least detrimental. + */ - if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) { - /* Tainted meat */ - Sprintf(buf, "%s like %s could be tainted! %s", - foodsmell, it_or_they, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (stoneorslime) { - Sprintf(buf, "%s like %s could be something very dangerous! %s", - foodsmell, it_or_they, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (otmp->orotten || (cadaver && rotted > 3L)) { - /* Rotten */ - Sprintf(buf, "%s like %s could be rotten! %s", - foodsmell, it_or_they, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) { - /* poisonous */ - Sprintf(buf, "%s like %s might be poisonous! %s", - foodsmell, it_or_they, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) { - /* causes sleep, for long enough to be dangerous */ - Sprintf(buf, "%s like %s might have been poisoned. %s", - foodsmell, it_or_they, eat_it_anyway); - return (yn_function(buf, ynchars, 'n') == 'n') ? 1 : 2; - } - if (cadaver && !vegetarian(&mons[mnum]) && - !u.uconduct.unvegetarian && Role_if(PM_MONK)) { - Sprintf(buf, "%s unhealthy. %s", - foodsmell, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) { - Sprintf(buf, "%s rather acidic. %s", - foodsmell, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (Upolyd && u.umonnum == PM_RUST_MONSTER && - is_metallic(otmp) && otmp->oerodeproof) { - Sprintf(buf, "%s disgusting to you right now. %s", - foodsmell, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } + if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) { + /* Tainted meat */ + Sprintf(buf, "%s like %s could be tainted! %s", foodsmell, it_or_they, + eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (stoneorslime) { + Sprintf(buf, "%s like %s could be something very dangerous! %s", + foodsmell, it_or_they, eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (otmp->orotten || (cadaver && rotted > 3L)) { + /* Rotten */ + Sprintf(buf, "%s like %s could be rotten! %s", foodsmell, it_or_they, + eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) { + /* poisonous */ + Sprintf(buf, "%s like %s might be poisonous! %s", foodsmell, + it_or_they, eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) { + /* causes sleep, for long enough to be dangerous */ + Sprintf(buf, "%s like %s might have been poisoned. %s", foodsmell, + it_or_they, eat_it_anyway); + return (yn_function(buf, ynchars, 'n') == 'n') ? 1 : 2; + } + if (cadaver && !vegetarian(&mons[mnum]) && !u.uconduct.unvegetarian + && Role_if(PM_MONK)) { + Sprintf(buf, "%s unhealthy. %s", foodsmell, eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) { + Sprintf(buf, "%s rather acidic. %s", foodsmell, eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (Upolyd && u.umonnum == PM_RUST_MONSTER && is_metallic(otmp) + && otmp->oerodeproof) { + Sprintf(buf, "%s disgusting to you right now. %s", foodsmell, + eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } - /* - * Breaks conduct, but otherwise safe. - */ - - if (!u.uconduct.unvegan && - ((material == LEATHER || material == BONE || - material == DRAGON_HIDE || material == WAX) || - (cadaver && !vegan(&mons[mnum])))) { - Sprintf(buf, "%s foul and unfamiliar to you. %s", - foodsmell, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - if (!u.uconduct.unvegetarian && - ((material == LEATHER || material == BONE || - material == DRAGON_HIDE) || - (cadaver && !vegetarian(&mons[mnum])))) { - Sprintf(buf, "%s unfamiliar to you. %s", - foodsmell, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } + /* + * Breaks conduct, but otherwise safe. + */ - if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) { - /* Tainted meat with Sick_resistance */ - Sprintf(buf, "%s like %s could be tainted! %s", - foodsmell, it_or_they, eat_it_anyway); - if (yn_function(buf,ynchars,'n')=='n') return 1; - else return 2; - } - return 0; + if (!u.uconduct.unvegan + && ((material == LEATHER || material == BONE + || material == DRAGON_HIDE || material == WAX) + || (cadaver && !vegan(&mons[mnum])))) { + Sprintf(buf, "%s foul and unfamiliar to you. %s", foodsmell, + eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + if (!u.uconduct.unvegetarian + && ((material == LEATHER || material == BONE + || material == DRAGON_HIDE) + || (cadaver && !vegetarian(&mons[mnum])))) { + Sprintf(buf, "%s unfamiliar to you. %s", foodsmell, eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + + if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) { + /* Tainted meat with Sick_resistance */ + Sprintf(buf, "%s like %s could be tainted! %s", foodsmell, it_or_they, + eat_it_anyway); + if (yn_function(buf, ynchars, 'n') == 'n') + return 1; + else + return 2; + } + return 0; } -int -doeat() /* generic "eat" command funtion (see cmd.c) */ +int doeat() /* generic "eat" command funtion (see cmd.c) */ { - struct obj *otmp; - int basenutrit; /* nutrition of full item */ - boolean dont_start = FALSE, nodelicious = FALSE; - - if (Strangled) { - pline("If you can't breathe air, how can you consume solids?"); - return 0; - } - if (!(otmp = floorfood("eat", 0))) return 0; - if (check_capacity((char *)0)) return 0; + struct obj *otmp; + int basenutrit; /* nutrition of full item */ + boolean dont_start = FALSE, nodelicious = FALSE; - if (u.uedibility) { - int res = edibility_prompts(otmp); - if (res) { - Your("%s stops tingling and your sense of smell returns to normal.", - body_part(NOSE)); - u.uedibility = 0; - if (res == 1) return 0; - } - } + if (Strangled) { + pline("If you can't breathe air, how can you consume solids?"); + return 0; + } + if (!(otmp = floorfood("eat", 0))) + return 0; + if (check_capacity((char *) 0)) + return 0; - /* We have to make non-foods take 1 move to eat, unless we want to - * do ridiculous amounts of coding to deal with partly eaten plate - * mails, players who polymorph back to human in the middle of their - * metallic meal, etc.... - */ - if (!(carried(otmp) ? retouch_object(&otmp, FALSE) : - touch_artifact(otmp, &youmonst))) { - return 1; - } else if (!is_edible(otmp)) { - You("cannot eat that!"); - return 0; - } else if ((otmp->owornmask & (W_ARMOR|W_TOOL|W_AMUL|W_SADDLE)) != 0) { - /* let them eat rings */ - You_cant("eat %s you're wearing.", something); - return 0; - } - if (is_metallic(otmp) && - u.umonnum == PM_RUST_MONSTER && otmp->oerodeproof) { - otmp->rknown = TRUE; - if (otmp->quan > 1L) { - if(!carried(otmp)) - (void) splitobj(otmp, otmp->quan - 1L); - else - otmp = splitobj(otmp, 1L); - } - pline("Ulch - that %s was rustproofed!", xname(otmp)); - /* The regurgitated object's rustproofing is gone now */ - otmp->oerodeproof = 0; - make_stunned((HStun & TIMEOUT) + (long)rn2(10), TRUE); - You("spit %s out onto the %s.", the(xname(otmp)), - surface(u.ux, u.uy)); - if (carried(otmp)) { - freeinv(otmp); - dropy(otmp); - } - stackobj(otmp); - return 1; - } - /* KMH -- Slow digestion is... indigestible */ - if (otmp->otyp == RIN_SLOW_DIGESTION) { - pline("This ring is indigestible!"); - (void) rottenfood(otmp); - if (otmp->dknown && !objects[otmp->otyp].oc_name_known - && !objects[otmp->otyp].oc_uname) - docall(otmp); - return (1); - } - if (otmp->oclass != FOOD_CLASS) { - int material; - context.victual.reqtime = 1; - context.victual.piece = otmp; - context.victual.o_id = otmp->o_id; - /* Don't split it, we don't need to if it's 1 move */ - context.victual.usedtime = 0; - context.victual.canchoke = (u.uhs == SATIATED); - /* Note: gold weighs 1 pt. for each 1000 pieces (see */ - /* pickup.c) so gold and non-gold is consistent. */ - if (otmp->oclass == COIN_CLASS) - basenutrit = ((otmp->quan > 200000L) ? 2000 - : (int)(otmp->quan/100L)); - else if(otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS) - basenutrit = weight(otmp); - /* oc_nutrition is usually weight anyway */ - else basenutrit = objects[otmp->otyp].oc_nutrition; + if (u.uedibility) { + int res = edibility_prompts(otmp); + if (res) { + Your("%s stops tingling and your sense of smell returns to " + "normal.", + body_part(NOSE)); + u.uedibility = 0; + if (res == 1) + return 0; + } + } + + /* We have to make non-foods take 1 move to eat, unless we want to + * do ridiculous amounts of coding to deal with partly eaten plate + * mails, players who polymorph back to human in the middle of their + * metallic meal, etc.... + */ + if (!(carried(otmp) ? retouch_object(&otmp, FALSE) + : touch_artifact(otmp, &youmonst))) { + return 1; + } else if (!is_edible(otmp)) { + You("cannot eat that!"); + return 0; + } else if ((otmp->owornmask & (W_ARMOR | W_TOOL | W_AMUL | W_SADDLE)) + != 0) { + /* let them eat rings */ + You_cant("eat %s you're wearing.", something); + return 0; + } + if (is_metallic(otmp) && u.umonnum == PM_RUST_MONSTER + && otmp->oerodeproof) { + otmp->rknown = TRUE; + if (otmp->quan > 1L) { + if (!carried(otmp)) + (void) splitobj(otmp, otmp->quan - 1L); + else + otmp = splitobj(otmp, 1L); + } + pline("Ulch - that %s was rustproofed!", xname(otmp)); + /* The regurgitated object's rustproofing is gone now */ + otmp->oerodeproof = 0; + make_stunned((HStun & TIMEOUT) + (long) rn2(10), TRUE); + You("spit %s out onto the %s.", the(xname(otmp)), + surface(u.ux, u.uy)); + if (carried(otmp)) { + freeinv(otmp); + dropy(otmp); + } + stackobj(otmp); + return 1; + } + /* KMH -- Slow digestion is... indigestible */ + if (otmp->otyp == RIN_SLOW_DIGESTION) { + pline("This ring is indigestible!"); + (void) rottenfood(otmp); + if (otmp->dknown && !objects[otmp->otyp].oc_name_known + && !objects[otmp->otyp].oc_uname) + docall(otmp); + return (1); + } + if (otmp->oclass != FOOD_CLASS) { + int material; + context.victual.reqtime = 1; + context.victual.piece = otmp; + context.victual.o_id = otmp->o_id; + /* Don't split it, we don't need to if it's 1 move */ + context.victual.usedtime = 0; + context.victual.canchoke = (u.uhs == SATIATED); + /* Note: gold weighs 1 pt. for each 1000 pieces (see */ + /* pickup.c) so gold and non-gold is consistent. */ + if (otmp->oclass == COIN_CLASS) + basenutrit = + ((otmp->quan > 200000L) ? 2000 : (int) (otmp->quan / 100L)); + else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS) + basenutrit = weight(otmp); + /* oc_nutrition is usually weight anyway */ + else + basenutrit = objects[otmp->otyp].oc_nutrition; #ifdef MAIL - if (otmp->otyp == SCR_MAIL) { - basenutrit = 0; - nodelicious = TRUE; - } + if (otmp->otyp == SCR_MAIL) { + basenutrit = 0; + nodelicious = TRUE; + } #endif - context.victual.nmod = basenutrit; - context.victual.eating = TRUE; /* needed for lesshungry() */ + context.victual.nmod = basenutrit; + context.victual.eating = TRUE; /* needed for lesshungry() */ - material = objects[otmp->otyp].oc_material; - if (material == LEATHER || - material == BONE || material == DRAGON_HIDE) { - u.uconduct.unvegan++; - violated_vegetarian(); - } else if (material == WAX) - u.uconduct.unvegan++; - u.uconduct.food++; - - if (otmp->cursed) - (void) rottenfood(otmp); + material = objects[otmp->otyp].oc_material; + if (material == LEATHER || material == BONE + || material == DRAGON_HIDE) { + u.uconduct.unvegan++; + violated_vegetarian(); + } else if (material == WAX) + u.uconduct.unvegan++; + u.uconduct.food++; - if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) { - pline("Ecch - that must have been poisonous!"); - if(!Poison_resistance) { - losestr(rnd(4)); - losehp(rnd(15), xname(otmp), KILLED_BY_AN); - } else - You("seem unaffected by the poison."); - } else if (!otmp->cursed && !nodelicious) - pline("%s%s is delicious!", - (obj_is_pname(otmp) && - (otmp->oartifact < ART_ORB_OF_DETECTION)) ? "" : "This ", - otmp->oclass == COIN_CLASS ? foodword(otmp) : - singular(otmp, xname)); + if (otmp->cursed) + (void) rottenfood(otmp); - eatspecial(); - return 1; - } + if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) { + pline("Ecch - that must have been poisonous!"); + if (!Poison_resistance) { + losestr(rnd(4)); + losehp(rnd(15), xname(otmp), KILLED_BY_AN); + } else + You("seem unaffected by the poison."); + } else if (!otmp->cursed && !nodelicious) + pline("%s%s is delicious!", + (obj_is_pname(otmp) + && (otmp->oartifact < ART_ORB_OF_DETECTION)) + ? "" + : "This ", + otmp->oclass == COIN_CLASS ? foodword(otmp) + : singular(otmp, xname)); - if(otmp == context.victual.piece) { - /* If they weren't able to choke, they don't suddenly become able to - * choke just because they were interrupted. On the other hand, if - * they were able to choke before, if they lost food it's possible - * they shouldn't be able to choke now. - */ - if (u.uhs != SATIATED) context.victual.canchoke = FALSE; - context.victual.o_id = 0; - context.victual.piece = touchfood(otmp); - if (context.victual.piece) - context.victual.o_id = context.victual.piece->o_id; - You("resume your meal."); - start_eating(context.victual.piece); - return(1); - } + eatspecial(); + return 1; + } - /* nothing in progress - so try to find something. */ - /* tins are a special case */ - /* tins must also check conduct separately in case they're discarded */ - if(otmp->otyp == TIN) { - start_tin(otmp); - return(1); - } + if (otmp == context.victual.piece) { + /* If they weren't able to choke, they don't suddenly become able to + * choke just because they were interrupted. On the other hand, if + * they were able to choke before, if they lost food it's possible + * they shouldn't be able to choke now. + */ + if (u.uhs != SATIATED) + context.victual.canchoke = FALSE; + context.victual.o_id = 0; + context.victual.piece = touchfood(otmp); + if (context.victual.piece) + context.victual.o_id = context.victual.piece->o_id; + You("resume your meal."); + start_eating(context.victual.piece); + return (1); + } - /* KMH, conduct */ - u.uconduct.food++; + /* nothing in progress - so try to find something. */ + /* tins are a special case */ + /* tins must also check conduct separately in case they're discarded */ + if (otmp->otyp == TIN) { + start_tin(otmp); + return (1); + } - context.victual.o_id = 0; - context.victual.piece = otmp = touchfood(otmp); - if (context.victual.piece) - context.victual.o_id = context.victual.piece->o_id; - context.victual.usedtime = 0; + /* KMH, conduct */ + u.uconduct.food++; - /* Now we need to calculate delay and nutritional info. - * The base nutrition calculated here and in eatcorpse() accounts - * for normal vs. rotten food. The reqtime and nutrit values are - * then adjusted in accordance with the amount of food left. - */ - if(otmp->otyp == CORPSE || otmp->globby) { - int tmp = eatcorpse(otmp); - if (tmp == 2) { - /* used up */ - context.victual.piece = (struct obj *)0; - context.victual.o_id = 0; - return(1); - } else if (tmp) - dont_start = TRUE; - /* if not used up, eatcorpse sets up reqtime and may modify - * oeaten */ - } else { - /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE. These are - * all handled in the != FOOD_CLASS case, above */ - switch (objects[otmp->otyp].oc_material) { - case FLESH: - u.uconduct.unvegan++; - if (otmp->otyp != EGG) { - violated_vegetarian(); - } - break; + context.victual.o_id = 0; + context.victual.piece = otmp = touchfood(otmp); + if (context.victual.piece) + context.victual.o_id = context.victual.piece->o_id; + context.victual.usedtime = 0; - default: - if (otmp->otyp == PANCAKE || - otmp->otyp == FORTUNE_COOKIE || /* eggs */ - otmp->otyp == CREAM_PIE || - otmp->otyp == CANDY_BAR || /* milk */ - otmp->otyp == LUMP_OF_ROYAL_JELLY) - u.uconduct.unvegan++; - break; - } + /* Now we need to calculate delay and nutritional info. + * The base nutrition calculated here and in eatcorpse() accounts + * for normal vs. rotten food. The reqtime and nutrit values are + * then adjusted in accordance with the amount of food left. + */ + if (otmp->otyp == CORPSE || otmp->globby) { + int tmp = eatcorpse(otmp); + if (tmp == 2) { + /* used up */ + context.victual.piece = (struct obj *) 0; + context.victual.o_id = 0; + return (1); + } else if (tmp) + dont_start = TRUE; + /* if not used up, eatcorpse sets up reqtime and may modify + * oeaten */ + } else { + /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE. These are + * all handled in the != FOOD_CLASS case, above */ + switch (objects[otmp->otyp].oc_material) { + case FLESH: + u.uconduct.unvegan++; + if (otmp->otyp != EGG) { + violated_vegetarian(); + } + break; - context.victual.reqtime = objects[otmp->otyp].oc_delay; - if (otmp->otyp != FORTUNE_COOKIE && - (otmp->cursed || (!nonrotting_food(otmp->otyp) && - (monstermoves - otmp->age) > (otmp->blessed ? 50L : 30L) && - (otmp->orotten || !rn2(7))))) { + default: + if (otmp->otyp == PANCAKE || otmp->otyp == FORTUNE_COOKIE + || /* eggs */ + otmp->otyp == CREAM_PIE || otmp->otyp == CANDY_BAR + || /* milk */ + otmp->otyp == LUMP_OF_ROYAL_JELLY) + u.uconduct.unvegan++; + break; + } - if (rottenfood(otmp)) { - otmp->orotten = TRUE; - dont_start = TRUE; - } - consume_oeaten(otmp, 1); /* oeaten >>= 1 */ - } else - fprefx(otmp); - } + context.victual.reqtime = objects[otmp->otyp].oc_delay; + if (otmp->otyp != FORTUNE_COOKIE + && (otmp->cursed || (!nonrotting_food(otmp->otyp) + && (monstermoves - otmp->age) + > (otmp->blessed ? 50L : 30L) + && (otmp->orotten || !rn2(7))))) { + if (rottenfood(otmp)) { + otmp->orotten = TRUE; + dont_start = TRUE; + } + consume_oeaten(otmp, 1); /* oeaten >>= 1 */ + } else + fprefx(otmp); + } - /* re-calc the nutrition */ - if (otmp->otyp == CORPSE) basenutrit = mons[otmp->corpsenm].cnutrit; - else basenutrit = objects[otmp->otyp].oc_nutrition; + /* re-calc the nutrition */ + if (otmp->otyp == CORPSE) + basenutrit = mons[otmp->corpsenm].cnutrit; + else + basenutrit = objects[otmp->otyp].oc_nutrition; - debugpline1("before rounddiv: context.victual.reqtime == %d", - context.victual.reqtime); - debugpline2("oeaten == %d, basenutrit == %d", - otmp->oeaten, basenutrit); - context.victual.reqtime = (basenutrit == 0 ? 0 : - rounddiv(context.victual.reqtime * (long)otmp->oeaten, basenutrit)); - debugpline1("after rounddiv: context.victual.reqtime == %d", - context.victual.reqtime); - /* calculate the modulo value (nutrit. units per round eating) - * note: this isn't exact - you actually lose a little nutrition - * due to this method. - * TODO: add in a "remainder" value to be given at the end of the - * meal. - */ - if (context.victual.reqtime == 0 || otmp->oeaten == 0) - /* possible if most has been eaten before */ - context.victual.nmod = 0; - else if ((int)otmp->oeaten >= context.victual.reqtime) - context.victual.nmod = -((int)otmp->oeaten / context.victual.reqtime); - else - context.victual.nmod = context.victual.reqtime % otmp->oeaten; - context.victual.canchoke = (u.uhs == SATIATED); + debugpline1("before rounddiv: context.victual.reqtime == %d", + context.victual.reqtime); + debugpline2("oeaten == %d, basenutrit == %d", otmp->oeaten, basenutrit); + context.victual.reqtime = + (basenutrit == 0 ? 0 : rounddiv(context.victual.reqtime + * (long) otmp->oeaten, + basenutrit)); + debugpline1("after rounddiv: context.victual.reqtime == %d", + context.victual.reqtime); + /* calculate the modulo value (nutrit. units per round eating) + * note: this isn't exact - you actually lose a little nutrition + * due to this method. + * TODO: add in a "remainder" value to be given at the end of the + * meal. + */ + if (context.victual.reqtime == 0 || otmp->oeaten == 0) + /* possible if most has been eaten before */ + context.victual.nmod = 0; + else if ((int) otmp->oeaten >= context.victual.reqtime) + context.victual.nmod = + -((int) otmp->oeaten / context.victual.reqtime); + else + context.victual.nmod = context.victual.reqtime % otmp->oeaten; + context.victual.canchoke = (u.uhs == SATIATED); - if (!dont_start) start_eating(otmp); - return(1); + if (!dont_start) + start_eating(otmp); + return (1); } /* Take a single bite from a piece of food, checking for choking and @@ -2475,387 +2551,398 @@ doeat() /* generic "eat" command funtion (see cmd.c) */ STATIC_OVL int bite() { - if(context.victual.canchoke && u.uhunger >= 2000) { - choke(context.victual.piece); - return 1; - } - if (context.victual.doreset) { - do_reset_eat(); - return 0; - } - force_save_hs = TRUE; - if(context.victual.nmod < 0) { - lesshungry(-context.victual.nmod); - consume_oeaten(context.victual.piece, context.victual.nmod); /* -= -nmod */ - } else if(context.victual.nmod > 0 && (context.victual.usedtime % context.victual.nmod)) { - lesshungry(1); - consume_oeaten(context.victual.piece, -1); /* -= 1 */ - } - force_save_hs = FALSE; - recalc_wt(); - return 0; + if (context.victual.canchoke && u.uhunger >= 2000) { + choke(context.victual.piece); + return 1; + } + if (context.victual.doreset) { + do_reset_eat(); + return 0; + } + force_save_hs = TRUE; + if (context.victual.nmod < 0) { + lesshungry(-context.victual.nmod); + consume_oeaten(context.victual.piece, + context.victual.nmod); /* -= -nmod */ + } else if (context.victual.nmod > 0 + && (context.victual.usedtime % context.victual.nmod)) { + lesshungry(1); + consume_oeaten(context.victual.piece, -1); /* -= 1 */ + } + force_save_hs = FALSE; + recalc_wt(); + return 0; } -void -gethungry() /* as time goes by - called by moveloop() and domove() */ +void gethungry() /* as time goes by - called by moveloop() and domove() */ { - if (u.uinvulnerable) return; /* you don't feel hungrier */ + if (u.uinvulnerable) + return; /* you don't feel hungrier */ - if ((!u.usleep || !rn2(10)) /* slow metabolic rate while asleep */ - && (carnivorous(youmonst.data) || herbivorous(youmonst.data)) - && !Slow_digestion) - u.uhunger--; /* ordinary food consumption */ + if ((!u.usleep || !rn2(10)) /* slow metabolic rate while asleep */ + && (carnivorous(youmonst.data) || herbivorous(youmonst.data)) + && !Slow_digestion) + u.uhunger--; /* ordinary food consumption */ - if (moves % 2) { /* odd turns */ - /* Regeneration uses up food, unless due to an artifact */ - if ((HRegeneration & ~FROMFORM) || - (ERegeneration & ~(W_ARTI|W_WEP))) u.uhunger--; - if (near_capacity() > SLT_ENCUMBER) u.uhunger--; - } else { /* even turns */ - if (Hunger) u.uhunger--; - /* Conflict uses up food too */ - if (HConflict || (EConflict & (~W_ARTI))) u.uhunger--; - /* +0 charged rings don't do anything, so don't affect hunger */ - /* Slow digestion still uses ring hunger */ - switch ((int)(moves % 20)) { /* note: use even cases only */ - case 4: if (uleft && - (uleft->spe || !objects[uleft->otyp].oc_charged)) - u.uhunger--; - break; - case 8: if (uamul) u.uhunger--; - break; - case 12: if (uright && - (uright->spe || !objects[uright->otyp].oc_charged)) - u.uhunger--; - break; - case 16: if (u.uhave.amulet) u.uhunger--; - break; - default: break; - } - } - newuhs(TRUE); + if (moves % 2) { /* odd turns */ + /* Regeneration uses up food, unless due to an artifact */ + if ((HRegeneration & ~FROMFORM) + || (ERegeneration & ~(W_ARTI | W_WEP))) + u.uhunger--; + if (near_capacity() > SLT_ENCUMBER) + u.uhunger--; + } else { /* even turns */ + if (Hunger) + u.uhunger--; + /* Conflict uses up food too */ + if (HConflict || (EConflict & (~W_ARTI))) + u.uhunger--; + /* +0 charged rings don't do anything, so don't affect hunger */ + /* Slow digestion still uses ring hunger */ + switch ((int) (moves % 20)) { /* note: use even cases only */ + case 4: + if (uleft && (uleft->spe || !objects[uleft->otyp].oc_charged)) + u.uhunger--; + break; + case 8: + if (uamul) + u.uhunger--; + break; + case 12: + if (uright && (uright->spe || !objects[uright->otyp].oc_charged)) + u.uhunger--; + break; + case 16: + if (u.uhave.amulet) + u.uhunger--; + break; + default: + break; + } + } + newuhs(TRUE); } -void -morehungry(num) /* called after vomiting and after performing feats of magic */ +void morehungry( + num) /* called after vomiting and after performing feats of magic */ register int num; { - u.uhunger -= num; - newuhs(TRUE); + u.uhunger -= num; + newuhs(TRUE); } - void -lesshungry(num) /* called after eating (and after drinking fruit juice) */ +lesshungry(num) /* called after eating (and after drinking fruit juice) */ register int num; { - /* See comments in newuhs() for discussion on force_save_hs */ - boolean iseating = (occupation == eatfood) || force_save_hs; - debugpline1("lesshungry(%d)", num); - u.uhunger += num; - if(u.uhunger >= 2000) { - if (!iseating || context.victual.canchoke) { - if (iseating) { - choke(context.victual.piece); - reset_eat(); - } else - choke(occupation == opentin ? context.tin.tin : (struct obj *)0); - /* no reset_eat() */ - } - } else { - /* Have lesshungry() report when you're nearly full so all eating - * warns when you're about to choke. - */ - if (u.uhunger >= 1500) { - if (!context.victual.eating || (context.victual.eating && !context.victual.fullwarn)) { - pline("You're having a hard time getting all of it down."); - nomovemsg = "You're finally finished."; - if (!context.victual.eating) - multi = -2; - else { - context.victual.fullwarn = TRUE; - if (context.victual.canchoke && context.victual.reqtime > 1) { - /* a one-gulp food will not survive a stop */ - if (yn_function("Continue eating?", - ynchars,'n') != 'y') { - reset_eat(); - nomovemsg = (char *)0; - } - } - } - } - } - } - newuhs(FALSE); + /* See comments in newuhs() for discussion on force_save_hs */ + boolean iseating = (occupation == eatfood) || force_save_hs; + debugpline1("lesshungry(%d)", num); + u.uhunger += num; + if (u.uhunger >= 2000) { + if (!iseating || context.victual.canchoke) { + if (iseating) { + choke(context.victual.piece); + reset_eat(); + } else + choke(occupation == opentin ? context.tin.tin + : (struct obj *) 0); + /* no reset_eat() */ + } + } else { + /* Have lesshungry() report when you're nearly full so all eating + * warns when you're about to choke. + */ + if (u.uhunger >= 1500) { + if (!context.victual.eating + || (context.victual.eating && !context.victual.fullwarn)) { + pline("You're having a hard time getting all of it down."); + nomovemsg = "You're finally finished."; + if (!context.victual.eating) + multi = -2; + else { + context.victual.fullwarn = TRUE; + if (context.victual.canchoke + && context.victual.reqtime > 1) { + /* a one-gulp food will not survive a stop */ + if (yn_function("Continue eating?", ynchars, 'n') + != 'y') { + reset_eat(); + nomovemsg = (char *) 0; + } + } + } + } + } + } + newuhs(FALSE); } STATIC_PTR int unfaint(VOID_ARGS) { - (void) Hear_again(); - if(u.uhs > FAINTING) - u.uhs = FAINTING; - stop_occupation(); - context.botl = 1; - return 0; + (void) Hear_again(); + if (u.uhs > FAINTING) + u.uhs = FAINTING; + stop_occupation(); + context.botl = 1; + return 0; } boolean is_fainted() { - return((boolean)(u.uhs == FAINTED)); + return ((boolean)(u.uhs == FAINTED)); } -void -reset_faint() /* call when a faint must be prematurely terminated */ +void reset_faint() /* call when a faint must be prematurely terminated */ { - if (afternmv == unfaint) unmul("You revive."); + if (afternmv == unfaint) + unmul("You revive."); } -void -newuhs(incr) /* compute and comment on your (new?) hunger status */ +void newuhs(incr) /* compute and comment on your (new?) hunger status */ boolean incr; { - unsigned newhs; - static unsigned save_hs; - static boolean saved_hs = FALSE; - int h = u.uhunger; + unsigned newhs; + static unsigned save_hs; + static boolean saved_hs = FALSE; + int h = u.uhunger; - newhs = (h > 1000) ? SATIATED : - (h > 150) ? NOT_HUNGRY : - (h > 50) ? HUNGRY : - (h > 0) ? WEAK : FAINTING; + newhs = (h > 1000) + ? SATIATED + : (h > 150) ? NOT_HUNGRY + : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING; - /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY. - * This should not produce the message "you only feel hungry now"; - * that message should only appear if HUNGRY is an endpoint. Therefore - * we check to see if we're in the middle of eating. If so, we save - * the first hunger status, and at the end of eating we decide what - * message to print based on the _entire_ meal, not on each little bit. - */ - /* It is normally possible to check if you are in the middle of a meal - * by checking occupation == eatfood, but there is one special case: - * start_eating() can call bite() for your first bite before it - * sets the occupation. - * Anyone who wants to get that case to work _without_ an ugly static - * force_save_hs variable, feel free. - */ - /* Note: If you become a certain hunger status in the middle of the - * meal, and still have that same status at the end of the meal, - * this will incorrectly print the associated message at the end of - * the meal instead of the middle. Such a case is currently - * impossible, but could become possible if a message for SATIATED - * were added or if HUNGRY and WEAK were separated by a big enough - * gap to fit two bites. - */ - if (occupation == eatfood || force_save_hs) { - if (!saved_hs) { - save_hs = u.uhs; - saved_hs = TRUE; - } - u.uhs = newhs; - return; - } else { - if (saved_hs) { - u.uhs = save_hs; - saved_hs = FALSE; - } - } + /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY. + * This should not produce the message "you only feel hungry now"; + * that message should only appear if HUNGRY is an endpoint. Therefore + * we check to see if we're in the middle of eating. If so, we save + * the first hunger status, and at the end of eating we decide what + * message to print based on the _entire_ meal, not on each little bit. + */ + /* It is normally possible to check if you are in the middle of a meal + * by checking occupation == eatfood, but there is one special case: + * start_eating() can call bite() for your first bite before it + * sets the occupation. + * Anyone who wants to get that case to work _without_ an ugly static + * force_save_hs variable, feel free. + */ + /* Note: If you become a certain hunger status in the middle of the + * meal, and still have that same status at the end of the meal, + * this will incorrectly print the associated message at the end of + * the meal instead of the middle. Such a case is currently + * impossible, but could become possible if a message for SATIATED + * were added or if HUNGRY and WEAK were separated by a big enough + * gap to fit two bites. + */ + if (occupation == eatfood || force_save_hs) { + if (!saved_hs) { + save_hs = u.uhs; + saved_hs = TRUE; + } + u.uhs = newhs; + return; + } else { + if (saved_hs) { + u.uhs = save_hs; + saved_hs = FALSE; + } + } - if(newhs == FAINTING) { - if(is_fainted()) newhs = FAINTED; - if(u.uhs <= WEAK || rn2(20-u.uhunger/10) >= 19) { - if(!is_fainted() && multi >= 0 /* %% */) { - int duration = 10-(u.uhunger/10); + if (newhs == FAINTING) { + if (is_fainted()) + newhs = FAINTED; + if (u.uhs <= WEAK || rn2(20 - u.uhunger / 10) >= 19) { + if (!is_fainted() && multi >= 0 /* %% */) { + int duration = 10 - (u.uhunger / 10); - /* stop what you're doing, then faint */ - stop_occupation(); - You("faint from lack of food."); - if (!Levitation) selftouch("Falling, you"); - incr_itimeout(&HDeaf, duration); - nomul(-duration); - multi_reason = "fainted from lack of food"; - nomovemsg = "You regain consciousness."; - afternmv = unfaint; - newhs = FAINTED; - } - } else - if(u.uhunger < -(int)(200 + 20*ACURR(A_CON))) { - u.uhs = STARVED; - context.botl = 1; - bot(); - You("die from starvation."); - killer.format = KILLED_BY; - Strcpy(killer.name, "starvation"); - done(STARVING); - /* if we return, we lifesaved, and that calls newuhs */ - return; - } - } + /* stop what you're doing, then faint */ + stop_occupation(); + You("faint from lack of food."); + if (!Levitation) + selftouch("Falling, you"); + incr_itimeout(&HDeaf, duration); + nomul(-duration); + multi_reason = "fainted from lack of food"; + nomovemsg = "You regain consciousness."; + afternmv = unfaint; + newhs = FAINTED; + } + } else if (u.uhunger < -(int) (200 + 20 * ACURR(A_CON))) { + u.uhs = STARVED; + context.botl = 1; + bot(); + You("die from starvation."); + killer.format = KILLED_BY; + Strcpy(killer.name, "starvation"); + done(STARVING); + /* if we return, we lifesaved, and that calls newuhs */ + return; + } + } - if(newhs != u.uhs) { - if(newhs >= WEAK && u.uhs < WEAK) - losestr(1); /* this may kill you -- see below */ - else if(newhs < WEAK && u.uhs >= WEAK) - losestr(-1); - switch(newhs){ - case HUNGRY: - if (Hallucination) { - You((!incr) ? - "now have a lesser case of the munchies." : - "are getting the munchies."); - } else - You((!incr) ? "only feel hungry now." : - (u.uhunger < 145) ? "feel hungry." : - "are beginning to feel hungry."); - if (incr && occupation && - (occupation != eatfood && occupation != opentin)) - stop_occupation(); - context.travel = context.travel1 = context.mv = context.run = 0; - break; - case WEAK: - if (Hallucination) - pline((!incr) ? - "You still have the munchies." : - "The munchies are interfering with your motor capabilities."); - else if (incr && - (Role_if(PM_WIZARD) || Race_if(PM_ELF) || - Role_if(PM_VALKYRIE))) - pline("%s needs food, badly!", - (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ? - urole.name.m : "Elf"); - else - You((!incr) ? "feel weak now." : - (u.uhunger < 45) ? "feel weak." : - "are beginning to feel weak."); - if (incr && occupation && - (occupation != eatfood && occupation != opentin)) - stop_occupation(); - context.travel = context.travel1 = context.mv = context.run = 0; - break; - } - u.uhs = newhs; - context.botl = 1; - bot(); - if ((Upolyd ? u.mh : u.uhp) < 1) { - You("die from hunger and exhaustion."); - killer.format = KILLED_BY; - Strcpy(killer.name, "exhaustion"); - done(STARVING); - return; - } - } + if (newhs != u.uhs) { + if (newhs >= WEAK && u.uhs < WEAK) + losestr(1); /* this may kill you -- see below */ + else if (newhs < WEAK && u.uhs >= WEAK) + losestr(-1); + switch (newhs) { + case HUNGRY: + if (Hallucination) { + You((!incr) ? "now have a lesser case of the munchies." + : "are getting the munchies."); + } else + You((!incr) ? "only feel hungry now." + : (u.uhunger < 145) + ? "feel hungry." + : "are beginning to feel hungry."); + if (incr && occupation + && (occupation != eatfood && occupation != opentin)) + stop_occupation(); + context.travel = context.travel1 = context.mv = context.run = 0; + break; + case WEAK: + if (Hallucination) + pline((!incr) ? "You still have the munchies." + : "The munchies are interfering with your " + "motor capabilities."); + else if (incr && (Role_if(PM_WIZARD) || Race_if(PM_ELF) + || Role_if(PM_VALKYRIE))) + pline("%s needs food, badly!", + (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) + ? urole.name.m + : "Elf"); + else + You((!incr) + ? "feel weak now." + : (u.uhunger < 45) ? "feel weak." + : "are beginning to feel weak."); + if (incr && occupation + && (occupation != eatfood && occupation != opentin)) + stop_occupation(); + context.travel = context.travel1 = context.mv = context.run = 0; + break; + } + u.uhs = newhs; + context.botl = 1; + bot(); + if ((Upolyd ? u.mh : u.uhp) < 1) { + You("die from hunger and exhaustion."); + killer.format = KILLED_BY; + Strcpy(killer.name, "exhaustion"); + done(STARVING); + return; + } + } } /* Returns an object representing food. Object may be either on floor or * in inventory. */ -struct obj * -floorfood(verb,corpsecheck) /* get food from floor or pack */ - const char *verb; - int corpsecheck; /* 0, no check, 1, corpses, 2, tinnable corpses */ +struct obj *floorfood(verb, corpsecheck) /* get food from floor or pack */ +const char *verb; +int corpsecheck; /* 0, no check, 1, corpses, 2, tinnable corpses */ { - register struct obj *otmp; - char qbuf[QBUFSZ]; - char c; - boolean feeding = !strcmp(verb, "eat"), /* corpsecheck==0 */ - offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */ + register struct obj *otmp; + char qbuf[QBUFSZ]; + char c; + boolean feeding = !strcmp(verb, "eat"), /* corpsecheck==0 */ + offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */ - /* if we can't touch floor objects then use invent food only */ - if (!can_reach_floor(TRUE) || - (feeding && u.usteed) || /* can't eat off floor while riding */ - (is_pool_or_lava(u.ux, u.uy) && - (Wwalking || is_clinger(youmonst.data) || - (Flying && !Breathless)))) - goto skipfloor; + /* if we can't touch floor objects then use invent food only */ + if (!can_reach_floor(TRUE) || (feeding && u.usteed) + || /* can't eat off floor while riding */ + (is_pool_or_lava(u.ux, u.uy) && (Wwalking || is_clinger(youmonst.data) + || (Flying && !Breathless)))) + goto skipfloor; - if (feeding && metallivorous(youmonst.data)) { - struct obj *gold; - struct trap *ttmp = t_at(u.ux, u.uy); + if (feeding && metallivorous(youmonst.data)) { + struct obj *gold; + struct trap *ttmp = t_at(u.ux, u.uy); - if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) { - /* If not already stuck in the trap, perhaps there should - be a chance to becoming trapped? Probably not, because - then the trap would just get eaten on the _next_ turn... */ - Sprintf(qbuf, "There is a bear trap here (%s); eat it?", - (u.utrap && u.utraptype == TT_BEARTRAP) ? - "holding you" : "armed"); - if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { - u.utrap = u.utraptype = 0; - deltrap(ttmp); - return mksobj(BEARTRAP, TRUE, FALSE); - } else if (c == 'q') { - return (struct obj *)0; - } - } + if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) { + /* If not already stuck in the trap, perhaps there should + be a chance to becoming trapped? Probably not, because + then the trap would just get eaten on the _next_ turn... */ + Sprintf(qbuf, "There is a bear trap here (%s); eat it?", + (u.utrap && u.utraptype == TT_BEARTRAP) ? "holding you" + : "armed"); + if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { + u.utrap = u.utraptype = 0; + deltrap(ttmp); + return mksobj(BEARTRAP, TRUE, FALSE); + } else if (c == 'q') { + return (struct obj *) 0; + } + } - if (youmonst.data != &mons[PM_RUST_MONSTER] && - (gold = g_at(u.ux, u.uy)) != 0) { - if (gold->quan == 1L) - Sprintf(qbuf, "There is 1 gold piece here; eat it?"); - else - Sprintf(qbuf, "There are %ld gold pieces here; eat them?", - gold->quan); - if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { - return gold; - } else if (c == 'q') { - return (struct obj *)0; - } - } - } + if (youmonst.data != &mons[PM_RUST_MONSTER] + && (gold = g_at(u.ux, u.uy)) != 0) { + if (gold->quan == 1L) + Sprintf(qbuf, "There is 1 gold piece here; eat it?"); + else + Sprintf(qbuf, "There are %ld gold pieces here; eat them?", + gold->quan); + if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { + return gold; + } else if (c == 'q') { + return (struct obj *) 0; + } + } + } - /* Is there some food (probably a heavy corpse) here on the ground? */ - for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { - if (corpsecheck ? - (otmp->otyp==CORPSE && (corpsecheck == 1 || tinnable(otmp))) : - feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp)) : - otmp->oclass==FOOD_CLASS) { - char qsfx[QBUFSZ]; - boolean one = (otmp->quan == 1L); + /* Is there some food (probably a heavy corpse) here on the ground? */ + for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { + if (corpsecheck + ? (otmp->otyp == CORPSE + && (corpsecheck == 1 || tinnable(otmp))) + : feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp)) + : otmp->oclass == FOOD_CLASS) { + char qsfx[QBUFSZ]; + boolean one = (otmp->quan == 1L); - /* "There is here; it?" or - "There are here; one?" */ - Sprintf(qbuf, "There %s ", otense(otmp, "are")); - Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one"); - (void)safe_qbuf(qbuf, qbuf, qsfx, - otmp, doname, ansimpleoname, - one ? something : (const char *)"things"); - if ((c = yn_function(qbuf,ynqchars,'n')) == 'y') - return(otmp); - else if (c == 'q') - return((struct obj *) 0); - } - } + /* "There is here; it?" or + "There are here; one?" */ + Sprintf(qbuf, "There %s ", otense(otmp, "are")); + Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one"); + (void) safe_qbuf(qbuf, qbuf, qsfx, otmp, doname, ansimpleoname, + one ? something : (const char *) "things"); + if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') + return (otmp); + else if (c == 'q') + return ((struct obj *) 0); + } + } - skipfloor: - /* We cannot use ALL_CLASSES since that causes getobj() to skip its - * "ugly checks" and we need to check for inedible items. - */ - otmp = getobj(feeding ? allobj : offering ? offerfodder : comestibles, - verb); - if (corpsecheck && otmp && !(offering && otmp->oclass == AMULET_CLASS)) - if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) { - You_cant("%s that!", verb); - return (struct obj *)0; - } - return otmp; +skipfloor: + /* We cannot use ALL_CLASSES since that causes getobj() to skip its + * "ugly checks" and we need to check for inedible items. + */ + otmp = + getobj(feeding ? allobj : offering ? offerfodder : comestibles, verb); + if (corpsecheck && otmp && !(offering && otmp->oclass == AMULET_CLASS)) + if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) { + You_cant("%s that!", verb); + return (struct obj *) 0; + } + return otmp; } /* Side effects of vomiting */ /* added nomul (MRS) - it makes sense, you're too busy being sick! */ -void -vomit() /* A good idea from David Neves */ +void vomit() /* A good idea from David Neves */ { - if (cantvomit(youmonst.data)) - /* doesn't cure food poisoning; message assumes that we aren't - dealing with some esoteric body_part() */ - Your("jaw gapes convulsively."); - else - make_sick(0L, (char *)0, TRUE, SICK_VOMITABLE); - nomul(-2); - multi_reason = "vomiting"; - nomovemsg = You_can_move_again; + if (cantvomit(youmonst.data)) + /* doesn't cure food poisoning; message assumes that we aren't + dealing with some esoteric body_part() */ + Your("jaw gapes convulsively."); + else + make_sick(0L, (char *) 0, TRUE, SICK_VOMITABLE); + nomul(-2); + multi_reason = "vomiting"; + nomovemsg = You_can_move_again; } int @@ -2863,20 +2950,21 @@ eaten_stat(base, obj) register int base; register struct obj *obj; { - long uneaten_amt, full_amount; + long uneaten_amt, full_amount; - uneaten_amt = (long)obj->oeaten; - full_amount = (obj->otyp == CORPSE) ? (long)mons[obj->corpsenm].cnutrit - : (long)objects[obj->otyp].oc_nutrition; - if (uneaten_amt > full_amount) { - impossible( - "partly eaten food (%ld) more nutritious than untouched food (%ld)", - uneaten_amt, full_amount); - uneaten_amt = full_amount; - } + uneaten_amt = (long) obj->oeaten; + full_amount = (obj->otyp == CORPSE) + ? (long) mons[obj->corpsenm].cnutrit + : (long) objects[obj->otyp].oc_nutrition; + if (uneaten_amt > full_amount) { + impossible("partly eaten food (%ld) more nutritious than untouched " + "food (%ld)", + uneaten_amt, full_amount); + uneaten_amt = full_amount; + } - base = (int)(full_amount ? (long)base * uneaten_amt / full_amount : 0L); - return (base < 1) ? 1 : base; + base = (int) (full_amount ? (long) base * uneaten_amt / full_amount : 0L); + return (base < 1) ? 1 : base; } /* reduce obj's oeaten field, making sure it never hits or passes 0 */ @@ -2912,20 +3000,21 @@ int amt; */ if (amt > 0) { - /* bit shift to divide the remaining amount of food */ - obj->oeaten >>= amt; + /* bit shift to divide the remaining amount of food */ + obj->oeaten >>= amt; } else { - /* simple decrement; value is negative so we actually add it */ - if ((int) obj->oeaten > -amt) - obj->oeaten += amt; - else - obj->oeaten = 0; + /* simple decrement; value is negative so we actually add it */ + if ((int) obj->oeaten > -amt) + obj->oeaten += amt; + else + obj->oeaten = 0; } if (obj->oeaten == 0) { - if (obj == context.victual.piece) /* always true unless wishing... */ - context.victual.reqtime = context.victual.usedtime; /* no bites left */ - obj->oeaten = 1; /* smallest possible positive value */ + if (obj == context.victual.piece) /* always true unless wishing... */ + context.victual.reqtime = + context.victual.usedtime; /* no bites left */ + obj->oeaten = 1; /* smallest possible positive value */ } } @@ -2935,13 +3024,16 @@ boolean maybe_finished_meal(stopping) boolean stopping; { - /* in case consume_oeaten() has decided that the food is all gone */ - if (occupation == eatfood && context.victual.usedtime >= context.victual.reqtime) { - if (stopping) occupation = 0; /* for do_reset_eat */ - (void) eatfood(); /* calls done_eating() to use up context.victual.piece */ - return TRUE; - } - return FALSE; + /* in case consume_oeaten() has decided that the food is all gone */ + if (occupation == eatfood + && context.victual.usedtime >= context.victual.reqtime) { + if (stopping) + occupation = 0; /* for do_reset_eat */ + (void) eatfood(); /* calls done_eating() to use up + context.victual.piece */ + return TRUE; + } + return FALSE; } /* Tin of to the rescue? Decide whether current occupation @@ -2953,33 +3045,35 @@ boolean Popeye(threat) int threat; { - struct obj *otin; + struct obj *otin; int mndx; - if (occupation != opentin) return FALSE; + if (occupation != opentin) + return FALSE; otin = context.tin.tin; /* make sure hero still has access to tin */ - if (!carried(otin) && - (!obj_here(otin, u.ux, u.uy) || !can_reach_floor(TRUE))) - return FALSE; + if (!carried(otin) + && (!obj_here(otin, u.ux, u.uy) || !can_reach_floor(TRUE))) + return FALSE; /* unknown tin is assumed to be helpful */ - if (!otin->known) return TRUE; + if (!otin->known) + return TRUE; /* known tin is helpful if it will stop life-threatening problem */ mndx = otin->corpsenm; switch (threat) { /* note: not used; hunger code bypasses stop_occupation() when eating */ case HUNGER: - return (mndx != NON_PM || otin->spe == 1); + return (mndx != NON_PM || otin->spe == 1); /* flesh from lizards and acidic critters stops petrification */ case STONED: - return (mndx >= LOW_PM && (mndx == PM_LIZARD || acidic(&mons[mndx]))); + return (mndx >= LOW_PM && (mndx == PM_LIZARD || acidic(&mons[mndx]))); /* no tins can cure these (yet?) */ case SLIMED: case SICK: case VOMITING: - break; + break; default: - break; + break; } return FALSE; } diff --git a/src/end.c b/src/end.c index 59c39e35f..893bee0fc 100644 --- a/src/end.c +++ b/src/end.c @@ -1,9 +1,9 @@ -/* NetHack 3.6 end.c $NHDT-Date: 1429953061 2015/04/25 09:11:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.93 $ */ +/* NetHack 3.6 end.c $NHDT-Date: 1431192755 2015/05/09 17:32:35 $ $NHDT-Branch: master $:$NHDT-Revision: 1.96 $ */ /* NetHack 3.6 end.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.79 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ -#define NEED_VARARGS /* comment line for pre-compiled headers */ +#define NEED_VARARGS /* comment line for pre-compiled headers */ #include "hack.h" #include "lev.h" @@ -17,70 +17,74 @@ /* add b to long a, convert wraparound to max value */ #define nowrap_add(a, b) (a = ((a + b) < 0 ? LONG_MAX : (a + b))) - /* these probably ought to be generated by makedefs, like LAST_GEM */ -#define FIRST_GEM DILITHIUM_CRYSTAL +/* these probably ought to be generated by makedefs, like LAST_GEM */ +#define FIRST_GEM DILITHIUM_CRYSTAL #define FIRST_AMULET AMULET_OF_ESP -#define LAST_AMULET AMULET_OF_YENDOR - -struct valuable_data { long count; int typ; }; +#define LAST_AMULET AMULET_OF_YENDOR + +struct valuable_data { + long count; + int typ; +}; static struct valuable_data - gems[LAST_GEM+1 - FIRST_GEM + 1], /* 1 extra for glass */ - amulets[LAST_AMULET+1 - FIRST_AMULET]; + gems[LAST_GEM + 1 - FIRST_GEM + 1], /* 1 extra for glass */ + amulets[LAST_AMULET + 1 - FIRST_AMULET]; -static struct val_list { struct valuable_data *list; int size; } valuables[] = { - { gems, sizeof gems / sizeof *gems }, - { amulets, sizeof amulets / sizeof *amulets }, - { 0, 0 } -}; +static struct val_list { + struct valuable_data *list; + int size; +} valuables[] = { { gems, sizeof gems / sizeof *gems }, + { amulets, sizeof amulets / sizeof *amulets }, + { 0, 0 } }; #ifndef NO_SIGNAL STATIC_PTR void FDECL(done_intr, (int)); -# if defined(UNIX) || defined(VMS) || defined (__EMX__) +#if defined(UNIX) || defined(VMS) || defined(__EMX__) static void FDECL(done_hangup, (int)); -# endif #endif -STATIC_DCL void FDECL(disclose,(int,BOOLEAN_P)); +#endif +STATIC_DCL void FDECL(disclose, (int, BOOLEAN_P)); STATIC_DCL void FDECL(get_valuables, (struct obj *)); -STATIC_DCL void FDECL(sort_valuables, (struct valuable_data *,int)); -STATIC_DCL void FDECL(artifact_score, (struct obj *,BOOLEAN_P,winid)); -STATIC_DCL boolean FDECL(odds_and_ends, (struct obj *,int)); +STATIC_DCL void FDECL(sort_valuables, (struct valuable_data *, int)); +STATIC_DCL void FDECL(artifact_score, (struct obj *, BOOLEAN_P, winid)); +STATIC_DCL boolean FDECL(odds_and_ends, (struct obj *, int)); STATIC_DCL void FDECL(savelife, (int)); -STATIC_DCL void FDECL(list_vanquished, (CHAR_P,BOOLEAN_P)); -STATIC_DCL void FDECL(list_genocided, (CHAR_P,BOOLEAN_P)); -STATIC_DCL boolean FDECL(should_query_disclose_option, (int,char *)); +STATIC_DCL void FDECL(list_vanquished, (CHAR_P, BOOLEAN_P)); +STATIC_DCL void FDECL(list_genocided, (CHAR_P, BOOLEAN_P)); +STATIC_DCL boolean FDECL(should_query_disclose_option, (int, char *)); #if defined(__BEOS__) || defined(MICRO) || defined(WIN32) || defined(OS2) -extern void FDECL(nethack_exit,(int)); +extern void FDECL(nethack_exit, (int)); #else -# define nethack_exit exit +#define nethack_exit exit #endif #define done_stopprint program_state.stopprint #ifndef PANICTRACE -# define NH_abort NH_abort_ +#define NH_abort NH_abort_ #endif #ifdef AMIGA -# define NH_abort_() Abort(0) +#define NH_abort_() Abort(0) #else -# ifdef SYSV -# define NH_abort_() (void) abort() -# else -# ifdef WIN32 -# define NH_abort_() win32_abort() -# else -# define NH_abort_() abort() -# endif -# endif /* !SYSV */ -#endif /* !AMIGA */ +#ifdef SYSV +#define NH_abort_() (void) abort() +#else +#ifdef WIN32 +#define NH_abort_() win32_abort() +#else +#define NH_abort_() abort() +#endif +#endif /* !SYSV */ +#endif /* !AMIGA */ #ifdef PANICTRACE -# include -# ifdef PANICTRACE_LIBC -# include -# endif +#include +#ifdef PANICTRACE_LIBC +#include +#endif /* What do we try and in what order? Tradeoffs: * libc: +no external programs required @@ -90,293 +94,301 @@ extern void FDECL(nethack_exit,(int)); * +works on more OS versions * -requires -g, which may preclude -O on some compilers */ -# ifdef SYSCF -# define SYSOPT_PANICTRACE_GDB sysopt.panictrace_gdb -# ifdef PANICTRACE_LIBC -# define SYSOPT_PANICTRACE_LIBC sysopt.panictrace_libc -# else -# define SYSOPT_PANICTRACE_LIBC 0 -# endif -# else -# define SYSOPT_PANICTRACE_GDB (nh_getenv("NETHACK_USE_GDB")==0?0:2) -# ifdef PANICTRACE_LIBC -# define SYSOPT_PANICTRACE_LIBC 1 -# else -# define SYSOPT_PANICTRACE_LIBC 0 -# endif -# endif +#ifdef SYSCF +#define SYSOPT_PANICTRACE_GDB sysopt.panictrace_gdb +#ifdef PANICTRACE_LIBC +#define SYSOPT_PANICTRACE_LIBC sysopt.panictrace_libc +#else +#define SYSOPT_PANICTRACE_LIBC 0 +#endif +#else +#define SYSOPT_PANICTRACE_GDB (nh_getenv("NETHACK_USE_GDB") == 0 ? 0 : 2) +#ifdef PANICTRACE_LIBC +#define SYSOPT_PANICTRACE_LIBC 1 +#else +#define SYSOPT_PANICTRACE_LIBC 0 +#endif +#endif static void NDECL(NH_abort); -# ifndef NO_SIGNAL +#ifndef NO_SIGNAL static void FDECL(panictrace_handler, (int)); -# endif +#endif static boolean NDECL(NH_panictrace_libc); static boolean NDECL(NH_panictrace_gdb); -# ifndef NO_SIGNAL +#ifndef NO_SIGNAL /*ARGSUSED*/ -void -panictrace_handler(sig_unused) /* called as signal() handler, so sent at least one arg */ +void panictrace_handler( + sig_unused) /* called as signal() handler, so sent at least one arg */ int sig_unused UNUSED; { -# define SIG_MSG "\nSignal received.\n" - (void) write(2, SIG_MSG, sizeof(SIG_MSG)-1); - NH_abort(); +#define SIG_MSG "\nSignal received.\n" + (void) write(2, SIG_MSG, sizeof(SIG_MSG) - 1); + NH_abort(); } void panictrace_setsignals(set) boolean set; { -# define SETSIGNAL(sig) (void) signal(sig, set?(SIG_RET_TYPE)panictrace_handler:SIG_DFL); -# ifdef SIGILL - SETSIGNAL(SIGILL); -# endif -# ifdef SIGTRAP - SETSIGNAL(SIGTRAP); -# endif -# ifdef SIGIOT - SETSIGNAL(SIGIOT); -# endif -# ifdef SIGBUS - SETSIGNAL(SIGBUS); -# endif -# ifdef SIGFPE - SETSIGNAL(SIGFPE); -# endif -# ifdef SIGSEGV - SETSIGNAL(SIGSEGV); -# endif -# ifdef SIGSTKFLT - SETSIGNAL(SIGSTKFLT); -# endif -# ifdef SIGSYS - SETSIGNAL(SIGSYS); -# endif -# ifdef SIGEMT - SETSIGNAL(SIGEMT); -# endif -# undef SETSIGNAL +#define SETSIGNAL(sig) \ + (void) signal(sig, set ? (SIG_RET_TYPE) panictrace_handler : SIG_DFL); +#ifdef SIGILL + SETSIGNAL(SIGILL); +#endif +#ifdef SIGTRAP + SETSIGNAL(SIGTRAP); +#endif +#ifdef SIGIOT + SETSIGNAL(SIGIOT); +#endif +#ifdef SIGBUS + SETSIGNAL(SIGBUS); +#endif +#ifdef SIGFPE + SETSIGNAL(SIGFPE); +#endif +#ifdef SIGSEGV + SETSIGNAL(SIGSEGV); +#endif +#ifdef SIGSTKFLT + SETSIGNAL(SIGSTKFLT); +#endif +#ifdef SIGSYS + SETSIGNAL(SIGSYS); +#endif +#ifdef SIGEMT + SETSIGNAL(SIGEMT); +#endif +#undef SETSIGNAL } -# endif /* NO_SIGNAL */ +#endif /* NO_SIGNAL */ static void NH_abort() { - int gdb_prio = SYSOPT_PANICTRACE_GDB; - int libc_prio = SYSOPT_PANICTRACE_LIBC; - static boolean aborting = FALSE; + int gdb_prio = SYSOPT_PANICTRACE_GDB; + int libc_prio = SYSOPT_PANICTRACE_LIBC; + static boolean aborting = FALSE; - if(aborting) return; - aborting = TRUE; + if (aborting) + return; + aborting = TRUE; -# ifndef VMS - if(gdb_prio == libc_prio && gdb_prio > 0) gdb_prio++; +#ifndef VMS + if (gdb_prio == libc_prio && gdb_prio > 0) + gdb_prio++; - if(gdb_prio > libc_prio){ - NH_panictrace_gdb() || (libc_prio && NH_panictrace_libc()); - } else { - NH_panictrace_libc() || (gdb_prio && NH_panictrace_gdb()); - } + if (gdb_prio > libc_prio) { + NH_panictrace_gdb() || (libc_prio && NH_panictrace_libc()); + } else { + NH_panictrace_libc() || (gdb_prio && NH_panictrace_gdb()); + } -# else /* VMS */ - /* overload otherwise unused priority for debug mode: 1 = show - traceback and exit; 2 = show traceback and stay in debugger */ - /* if (wizard && gdb_prio == 1) gdb_prio = 2; */ - vms_traceback(gdb_prio); - (void)libc_prio; /* half-hearted attempt at lint suppression */ +#else /* VMS */ + /* overload otherwise unused priority for debug mode: 1 = show + traceback and exit; 2 = show traceback and stay in debugger */ + /* if (wizard && gdb_prio == 1) gdb_prio = 2; */ + vms_traceback(gdb_prio); + (void) libc_prio; /* half-hearted attempt at lint suppression */ -# endif /* ?VMS */ +#endif /* ?VMS */ -# ifndef NO_SIGNAL - panictrace_setsignals(FALSE); -# endif - NH_abort_(); +#ifndef NO_SIGNAL + panictrace_setsignals(FALSE); +#endif + NH_abort_(); } static boolean NH_panictrace_libc() { -# ifdef PANICTRACE_LIBC - void *bt[20]; - size_t count, x; - char **info; +#ifdef PANICTRACE_LIBC + void *bt[20]; + size_t count, x; + char **info; - raw_print("Generating more information you may report:\n"); - count = backtrace(bt, SIZE(bt)); - info = backtrace_symbols(bt, count); - for (x = 0; x < count; x++) { - raw_printf("[%lu] %s", (unsigned long)x, info[x]); - } - /* free(info); Don't risk it. */ - return TRUE; -# else - return FALSE; -# endif /* !PANICTRACE_LIBC */ + raw_print("Generating more information you may report:\n"); + count = backtrace(bt, SIZE(bt)); + info = backtrace_symbols(bt, count); + for (x = 0; x < count; x++) { + raw_printf("[%lu] %s", (unsigned long) x, info[x]); + } + /* free(info); Don't risk it. */ + return TRUE; +#else + return FALSE; +#endif /* !PANICTRACE_LIBC */ } /* * fooPATH file system path for foo * fooVAR (possibly const) variable containing fooPATH */ -# ifdef PANICTRACE_GDB -# ifdef SYSCF -# define GDBVAR sysopt.gdbpath -# define GREPVAR sysopt.greppath -# else /* SYSCF */ -# define GDBVAR GDBPATH -# define GREPVAR GREPPATH -# endif /* SYSCF */ -# endif /* PANICTRACE_GDB */ +#ifdef PANICTRACE_GDB +#ifdef SYSCF +#define GDBVAR sysopt.gdbpath +#define GREPVAR sysopt.greppath +#else /* SYSCF */ +#define GDBVAR GDBPATH +#define GREPVAR GREPPATH +#endif /* SYSCF */ +#endif /* PANICTRACE_GDB */ static boolean NH_panictrace_gdb() { -# ifdef PANICTRACE_GDB - /* A (more) generic method to get a stack trace - invoke - * gdb on ourself. */ - char *gdbpath = GDBVAR; - char *greppath = GREPVAR; - char buf[BUFSZ]; - FILE *gdb; +#ifdef PANICTRACE_GDB + /* A (more) generic method to get a stack trace - invoke + * gdb on ourself. */ + char *gdbpath = GDBVAR; + char *greppath = GREPVAR; + char buf[BUFSZ]; + FILE *gdb; - if(gdbpath == NULL || gdbpath[0] == 0) return FALSE; - if(greppath == NULL || greppath[0] == 0) return FALSE; + if (gdbpath == NULL || gdbpath[0] == 0) + return FALSE; + if (greppath == NULL || greppath[0] == 0) + return FALSE; - sprintf(buf, "%s -n -q %s %d 2>&1 | %s '^#'", - gdbpath, ARGV0, getpid(), greppath); - gdb = popen(buf, "w"); - if(gdb){ - raw_print("Generating more information you may report:\n"); - fprintf(gdb, "bt\nquit\ny"); - fflush(gdb); - sleep(4); /* ugly */ - pclose(gdb); - return TRUE; - } else { - return FALSE; - } -# else - return FALSE; -# endif /* !PANICTRACE_GDB */ + sprintf(buf, "%s -n -q %s %d 2>&1 | %s '^#'", gdbpath, ARGV0, getpid(), + greppath); + gdb = popen(buf, "w"); + if (gdb) { + raw_print("Generating more information you may report:\n"); + fprintf(gdb, "bt\nquit\ny"); + fflush(gdb); + sleep(4); /* ugly */ + pclose(gdb); + return TRUE; + } else { + return FALSE; + } +#else + return FALSE; +#endif /* !PANICTRACE_GDB */ } -#endif /* PANICTRACE */ +#endif /* PANICTRACE */ /* * The order of these needs to match the macros in hack.h. */ -static NEARDATA const char *deaths[] = { /* the array of death */ - "died", "choked", "poisoned", "starvation", "drowning", - "burning", "dissolving under the heat and pressure", - "crushed", "turned to stone", "turned into slime", - "genocided", "panic", "trickery", - "quit", "escaped", "ascended" -}; +static NEARDATA const char *deaths[] = + { /* the array of death */ + "died", "choked", "poisoned", "starvation", "drowning", "burning", + "dissolving under the heat and pressure", "crushed", "turned to stone", + "turned into slime", "genocided", "panic", "trickery", "quit", + "escaped", "ascended" + }; -static NEARDATA const char *ends[] = { /* "when you..." */ - "died", "choked", "were poisoned", "starved", "drowned", - "burned", "dissolved in the lava", - "were crushed", "turned to stone", "turned into slime", - "were genocided", "panicked", "were tricked", - "quit", "escaped", "ascended" +static NEARDATA const char *ends[] = { /* "when you..." */ + "died", "choked", "were poisoned", + "starved", "drowned", "burned", + "dissolved in the lava", + "were crushed", "turned to stone", + "turned into slime", "were genocided", + "panicked", "were tricked", "quit", + "escaped", "ascended" }; static boolean Schroedingers_cat = FALSE; /*ARGSUSED*/ void -done1(sig_unused) /* called as signal() handler, so sent at least one arg */ +done1(sig_unused) /* called as signal() handler, so sent at least one arg */ int sig_unused UNUSED; { #ifndef NO_SIGNAL - (void) signal(SIGINT,SIG_IGN); + (void) signal(SIGINT, SIG_IGN); #endif - if(flags.ignintr) { + if (flags.ignintr) { #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); + (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif - clear_nhwindow(WIN_MESSAGE); - curs_on_u(); - wait_synch(); - if(multi > 0) nomul(0); - } else { - (void)done2(); - } + clear_nhwindow(WIN_MESSAGE); + curs_on_u(); + wait_synch(); + if (multi > 0) + nomul(0); + } else { + (void) done2(); + } } - /* "#quit" command or keyboard interrupt */ int done2() { - if (!paranoid_query(ParanoidQuit, "Really quit?")) { + if (!paranoid_query(ParanoidQuit, "Really quit?")) { #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); + (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif - clear_nhwindow(WIN_MESSAGE); - curs_on_u(); - wait_synch(); - if(multi > 0) nomul(0); - if(multi == 0) { - u.uinvulnerable = FALSE; /* avoid ctrl-C bug -dlc */ - u.usleep = 0; - } - return 0; - } + clear_nhwindow(WIN_MESSAGE); + curs_on_u(); + wait_synch(); + if (multi > 0) + nomul(0); + if (multi == 0) { + u.uinvulnerable = FALSE; /* avoid ctrl-C bug -dlc */ + u.usleep = 0; + } + return 0; + } #if (defined(UNIX) || defined(VMS) || defined(LATTICE)) - if(wizard) { - int c; -# ifdef VMS - extern int debuggable; /* sys/vms/vmsmisc.c, vmsunix.c */ + if (wizard) { + int c; +#ifdef VMS + extern int debuggable; /* sys/vms/vmsmisc.c, vmsunix.c */ - c = !debuggable ? 'n' : ynq("Enter debugger?"); -# else -# ifdef LATTICE - c = ynq("Create SnapShot?"); -# else - c = ynq("Dump core?"); -# endif -# endif - if (c == 'y') { -# ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); -# endif - exit_nhwindows((char *)0); - NH_abort(); - } else if (c == 'q') done_stopprint++; - } + c = !debuggable ? 'n' : ynq("Enter debugger?"); +#else +#ifdef LATTICE + c = ynq("Create SnapShot?"); +#else + c = ynq("Dump core?"); +#endif +#endif + if (c == 'y') { +#ifndef NO_SIGNAL + (void) signal(SIGINT, (SIG_RET_TYPE) done1); +#endif + exit_nhwindows((char *) 0); + NH_abort(); + } else if (c == 'q') + done_stopprint++; + } #endif #ifndef LINT - done(QUIT); + done(QUIT); #endif - return 0; + return 0; } #ifndef NO_SIGNAL /*ARGSUSED*/ -STATIC_PTR void -done_intr(sig_unused) /* called as signal() handler, so sent at least one arg */ +STATIC_PTR void done_intr( + sig_unused) /* called as signal() handler, so sent at least one arg */ int sig_unused UNUSED; { - done_stopprint++; - (void) signal(SIGINT, SIG_IGN); -# if defined(UNIX) || defined(VMS) - (void) signal(SIGQUIT, SIG_IGN); -# endif - return; + done_stopprint++; + (void) signal(SIGINT, SIG_IGN); +#if defined(UNIX) || defined(VMS) + (void) signal(SIGQUIT, SIG_IGN); +#endif + return; } -# if defined(UNIX) || defined(VMS) || defined(__EMX__) -static void -done_hangup(sig) /* signal() handler */ +#if defined(UNIX) || defined(VMS) || defined(__EMX__) +static void done_hangup(sig) /* signal() handler */ int sig; { - program_state.done_hup++; - sethanguphandler((void FDECL((*),(int)))SIG_IGN); - done_intr(sig); - return; + program_state.done_hup++; + sethanguphandler((void FDECL((*), (int) )) SIG_IGN); + done_intr(sig); + return; } -# endif +#endif #endif /* NO_SIGNAL */ void @@ -384,189 +396,194 @@ done_in_by(mtmp, how) struct monst *mtmp; int how; { - char buf[BUFSZ]; - struct permonst *mptr = mtmp->data, - *champtr = (mtmp->cham >= LOW_PM) ? &mons[mtmp->cham] : mptr; - boolean distorted = (boolean)(Hallucination && canspotmon(mtmp)), - mimicker = (mtmp->m_ap_type == M_AP_MONSTER), - imitator = (mptr != champtr || mimicker); + char buf[BUFSZ]; + struct permonst *mptr = mtmp->data, *champtr = (mtmp->cham >= LOW_PM) + ? &mons[mtmp->cham] + : mptr; + boolean distorted = (boolean)(Hallucination && canspotmon(mtmp)), + mimicker = (mtmp->m_ap_type == M_AP_MONSTER), + imitator = (mptr != champtr || mimicker); - You((how == STONING) ? "turn to stone..." : "die..."); - mark_synch(); /* flush buffered screen output */ - buf[0] = '\0'; - killer.format = KILLED_BY_AN; - /* "killed by the high priest of Crom" is okay, - "killed by the high priest" alone isn't */ - if ((mptr->geno & G_UNIQ) != 0 && - !(imitator && !mimicker) && - !(mptr == &mons[PM_HIGH_PRIEST] && !mtmp->ispriest)) { - if (!type_is_pname(mptr)) - Strcat(buf, "the "); - killer.format = KILLED_BY; - } - /* _the_ ghost of Dudley */ - if (mptr == &mons[PM_GHOST] && has_mname(mtmp)) { - Strcat(buf, "the "); - killer.format = KILLED_BY; - } - if (mtmp->minvis) - Strcat(buf, "invisible "); - if (distorted) - Strcat(buf, "hallucinogen-distorted "); + You((how == STONING) ? "turn to stone..." : "die..."); + mark_synch(); /* flush buffered screen output */ + buf[0] = '\0'; + killer.format = KILLED_BY_AN; + /* "killed by the high priest of Crom" is okay, + "killed by the high priest" alone isn't */ + if ((mptr->geno & G_UNIQ) != 0 && !(imitator && !mimicker) + && !(mptr == &mons[PM_HIGH_PRIEST] && !mtmp->ispriest)) { + if (!type_is_pname(mptr)) + Strcat(buf, "the "); + killer.format = KILLED_BY; + } + /* _the_ ghost of Dudley */ + if (mptr == &mons[PM_GHOST] && has_mname(mtmp)) { + Strcat(buf, "the "); + killer.format = KILLED_BY; + } + if (mtmp->minvis) + Strcat(buf, "invisible "); + if (distorted) + Strcat(buf, "hallucinogen-distorted "); - if (imitator) { - char shape[BUFSZ]; - const char *realnm = champtr->mname, *fakenm = mptr->mname; - boolean alt = is_vampshifter(mtmp); + if (imitator) { + char shape[BUFSZ]; + const char *realnm = champtr->mname, *fakenm = mptr->mname; + boolean alt = is_vampshifter(mtmp); - if (mimicker) { - /* realnm is already correct because champtr==mptr; - set up fake mptr for type_is_pname/the_unique_pm */ - mptr = &mons[mtmp->mappearance]; - fakenm = mptr->mname; - } else if (alt && strstri(realnm, "vampire") && - !strcmp(fakenm, "vampire bat")) { - /* special case: use "vampire in bat form" in preference - to redundant looking "vampire in vampire bat form" */ - fakenm = "bat"; - } - /* for the alternate format, always suppress any article; - pname and the_unique should also have s_suffix() applied, - but vampires don't take on any shapes which warrant that */ - if (alt || type_is_pname(mptr)) /* no article */ - Strcpy(shape, fakenm); - else if (the_unique_pm(mptr)) /* "the"; don't use the() here */ - Sprintf(shape, "the %s", fakenm); - else /* "a"/"an" */ - Strcpy(shape, an(fakenm)); - /* omit "called" to avoid excessive verbosity */ - Sprintf(eos(buf), - alt ? "%s in %s form" : - mimicker ? "%s disguised as %s" : "%s imitating %s", - realnm, shape); - mptr = mtmp->data; /* reset for mimicker case */ - } else if (mptr == &mons[PM_GHOST]) { - Strcat(buf, "ghost"); - if (has_mname(mtmp)) Sprintf(eos(buf), " of %s", MNAME(mtmp)); - } else if(mtmp->isshk) { - const char *shknm = shkname(mtmp), - *honorific = shkname_is_pname(mtmp) ? "" : - mtmp->female ? "Ms. " : "Mr. "; + if (mimicker) { + /* realnm is already correct because champtr==mptr; + set up fake mptr for type_is_pname/the_unique_pm */ + mptr = &mons[mtmp->mappearance]; + fakenm = mptr->mname; + } else if (alt && strstri(realnm, "vampire") + && !strcmp(fakenm, "vampire bat")) { + /* special case: use "vampire in bat form" in preference + to redundant looking "vampire in vampire bat form" */ + fakenm = "bat"; + } + /* for the alternate format, always suppress any article; + pname and the_unique should also have s_suffix() applied, + but vampires don't take on any shapes which warrant that */ + if (alt || type_is_pname(mptr)) /* no article */ + Strcpy(shape, fakenm); + else if (the_unique_pm(mptr)) /* "the"; don't use the() here */ + Sprintf(shape, "the %s", fakenm); + else /* "a"/"an" */ + Strcpy(shape, an(fakenm)); + /* omit "called" to avoid excessive verbosity */ + Sprintf(eos(buf), + alt ? "%s in %s form" : mimicker ? "%s disguised as %s" + : "%s imitating %s", + realnm, shape); + mptr = mtmp->data; /* reset for mimicker case */ + } else if (mptr == &mons[PM_GHOST]) { + Strcat(buf, "ghost"); + if (has_mname(mtmp)) + Sprintf(eos(buf), " of %s", MNAME(mtmp)); + } else if (mtmp->isshk) { + const char *shknm = shkname(mtmp), + *honorific = shkname_is_pname(mtmp) ? "" : mtmp->female + ? "Ms. " + : "Mr. "; - Sprintf(eos(buf), "%s%s, the shopkeeper", honorific, shknm); - killer.format = KILLED_BY; - } else if (mtmp->ispriest || mtmp->isminion) { - /* m_monnam() suppresses "the" prefix plus "invisible", and - it overrides the effect of Hallucination on priestname() */ - Strcat(buf, m_monnam(mtmp)); - } else { - Strcat(buf, mptr->mname); - if (has_mname(mtmp)) - Sprintf(eos(buf), " called %s", MNAME(mtmp)); - } + Sprintf(eos(buf), "%s%s, the shopkeeper", honorific, shknm); + killer.format = KILLED_BY; + } else if (mtmp->ispriest || mtmp->isminion) { + /* m_monnam() suppresses "the" prefix plus "invisible", and + it overrides the effect of Hallucination on priestname() */ + Strcat(buf, m_monnam(mtmp)); + } else { + Strcat(buf, mptr->mname); + if (has_mname(mtmp)) + Sprintf(eos(buf), " called %s", MNAME(mtmp)); + } - if (multi) { - if (multi_reason) - Sprintf(eos(buf), ", while %s", multi_reason); - else - Strcat(buf, ", while helpless"); - } - Strcpy(killer.name, buf); - if (mptr->mlet == S_WRAITH) - u.ugrave_arise = PM_WRAITH; - else if (mptr->mlet == S_MUMMY && urace.mummynum != NON_PM) - u.ugrave_arise = urace.mummynum; - else if (mptr->mlet == S_VAMPIRE && Race_if(PM_HUMAN)) - u.ugrave_arise = PM_VAMPIRE; - else if (mptr == &mons[PM_GHOUL]) - u.ugrave_arise = PM_GHOUL; - /* this could happen if a high-end vampire kills the hero - when ordinary vampires are genocided; ditto for wraiths */ - if (u.ugrave_arise >= LOW_PM && - (mvitals[u.ugrave_arise].mvflags & G_GENOD)) - u.ugrave_arise = NON_PM; + if (multi) { + if (multi_reason) + Sprintf(eos(buf), ", while %s", multi_reason); + else + Strcat(buf, ", while helpless"); + } + Strcpy(killer.name, buf); + if (mptr->mlet == S_WRAITH) + u.ugrave_arise = PM_WRAITH; + else if (mptr->mlet == S_MUMMY && urace.mummynum != NON_PM) + u.ugrave_arise = urace.mummynum; + else if (mptr->mlet == S_VAMPIRE && Race_if(PM_HUMAN)) + u.ugrave_arise = PM_VAMPIRE; + else if (mptr == &mons[PM_GHOUL]) + u.ugrave_arise = PM_GHOUL; + /* this could happen if a high-end vampire kills the hero + when ordinary vampires are genocided; ditto for wraiths */ + if (u.ugrave_arise >= LOW_PM + && (mvitals[u.ugrave_arise].mvflags & G_GENOD)) + u.ugrave_arise = NON_PM; - done(how); - return; + done(how); + return; } #if defined(WIN32) && !defined(SYSCF) -# define NOTIFY_NETHACK_BUGS +#define NOTIFY_NETHACK_BUGS #endif /*VARARGS1*/ -void -panic VA_DECL(const char *, str) - VA_START(str); - VA_INIT(str, char *); +void panic +VA_DECL(const char *, str) + VA_START(str); + VA_INIT(str, char *); - if (program_state.panicking++) - NH_abort(); /* avoid loops - this should never happen*/ + if (program_state.panicking++) + NH_abort(); /* avoid loops - this should never happen*/ - if (iflags.window_inited) { - raw_print("\r\nOops..."); - wait_synch(); /* make sure all pending output gets flushed */ - exit_nhwindows((char *)0); - iflags.window_inited = 0; /* they're gone; force raw_print()ing */ - } + if (iflags.window_inited) { + raw_print("\r\nOops..."); + wait_synch(); /* make sure all pending output gets flushed */ + exit_nhwindows((char *) 0); + iflags.window_inited = 0; /* they're gone; force raw_print()ing */ + } - raw_print(program_state.gameover ? - "Postgame wrapup disrupted." : - !program_state.something_worth_saving ? - "Program initialization has failed." : - "Suddenly, the dungeon collapses."); + raw_print(program_state.gameover + ? "Postgame wrapup disrupted." + : !program_state.something_worth_saving + ? "Program initialization has failed." + : "Suddenly, the dungeon collapses."); #ifndef MICRO -# if defined(NOTIFY_NETHACK_BUGS) - if (!wizard) - raw_printf("Report the following error to \"%s\" or at \"%s\".", - DEVTEAM_EMAIL, DEVTEAM_URL); - else if (program_state.something_worth_saving) - raw_print("\nError save file being written.\n"); -# else - if (!wizard){ - if(sysopt.support) - raw_printf("To report this error, %s%s.", sysopt.support, - !program_state.something_worth_saving ? "" : - " and it may be possible to rebuild."); - else if(sysopt.wizards){ - char *tmp = build_english_list(sysopt.wizards); - raw_printf("To report this error, contact %s%s", tmp, - !program_state.something_worth_saving ? "" : - " and it may be possible to rebuild."); - free(tmp); - } else - raw_printf("Report error to \"%s\"%s.", - WIZARD_NAME, - !program_state.something_worth_saving ? "" : - " and it may be possible to rebuild."); - } -# endif - /* XXX can we move this above the prints? Then we'd be able to - * suppress "it may be possible to rebuild" based on dosave0() - * or say it's NOT possible to rebuild. */ - if (program_state.something_worth_saving) { - set_error_savefile(); - if(dosave0()){ - /* os/win port specific recover instructions */ - if(sysopt.recover) raw_printf("%s", sysopt.recover); - } - } +#if defined(NOTIFY_NETHACK_BUGS) + if (!wizard) + raw_printf("Report the following error to \"%s\" or at \"%s\".", + DEVTEAM_EMAIL, DEVTEAM_URL); + else if (program_state.something_worth_saving) + raw_print("\nError save file being written.\n"); +#else + if (!wizard) { + if (sysopt.support) + raw_printf("To report this error, %s%s.", sysopt.support, + !program_state.something_worth_saving + ? "" + : " and it may be possible to rebuild."); + else if (sysopt.wizards) { + char *tmp = build_english_list(sysopt.wizards); + raw_printf("To report this error, contact %s%s", tmp, + !program_state.something_worth_saving + ? "" + : " and it may be possible to rebuild."); + free(tmp); + } else + raw_printf("Report error to \"%s\"%s.", WIZARD_NAME, + !program_state.something_worth_saving + ? "" + : " and it may be possible to rebuild."); + } #endif - { - char buf[BUFSZ]; - Vsprintf(buf,str,VA_ARGS); - raw_print(buf); - paniclog("panic", buf); - } + /* XXX can we move this above the prints? Then we'd be able to + * suppress "it may be possible to rebuild" based on dosave0() + * or say it's NOT possible to rebuild. */ + if (program_state.something_worth_saving) { + set_error_savefile(); + if (dosave0()) { + /* os/win port specific recover instructions */ + if (sysopt.recover) + raw_printf("%s", sysopt.recover); + } + } +#endif + { + char buf[BUFSZ]; + Vsprintf(buf, str, VA_ARGS); + raw_print(buf); + paniclog("panic", buf); + } #ifdef WIN32 - interject(INTERJECT_PANIC); + interject(INTERJECT_PANIC); #endif #if defined(UNIX) || defined(VMS) || defined(LATTICE) || defined(WIN32) - if (wizard) - NH_abort(); /* generate core dump */ + if (wizard) + NH_abort(); /* generate core dump */ #endif - VA_END(); - done(PANICKED); + VA_END(); + done(PANICKED); } STATIC_OVL boolean @@ -578,105 +595,113 @@ char *defquery; char *dop = index(disclosure_options, category); if (dop && defquery) { - idx = (int)(dop - disclosure_options); - if (idx < 0 || idx > (NUM_DISCLOSURE_OPTIONS - 1)) { - impossible( - "should_query_disclose_option: bad disclosure index %d %c", - idx, category); - *defquery = DISCLOSE_PROMPT_DEFAULT_YES; - return TRUE; - } - if (flags.end_disclose[idx] == DISCLOSE_YES_WITHOUT_PROMPT) { - *defquery = 'y'; - return FALSE; - } else if (flags.end_disclose[idx] == DISCLOSE_NO_WITHOUT_PROMPT) { - *defquery = 'n'; - return FALSE; - } else if (flags.end_disclose[idx] == DISCLOSE_PROMPT_DEFAULT_YES) { - *defquery = 'y'; - return TRUE; - } else { - *defquery = 'n'; - return TRUE; - } + idx = (int) (dop - disclosure_options); + if (idx < 0 || idx > (NUM_DISCLOSURE_OPTIONS - 1)) { + impossible( + "should_query_disclose_option: bad disclosure index %d %c", + idx, category); + *defquery = DISCLOSE_PROMPT_DEFAULT_YES; + return TRUE; + } + if (flags.end_disclose[idx] == DISCLOSE_YES_WITHOUT_PROMPT) { + *defquery = 'y'; + return FALSE; + } else if (flags.end_disclose[idx] == DISCLOSE_NO_WITHOUT_PROMPT) { + *defquery = 'n'; + return FALSE; + } else if (flags.end_disclose[idx] == DISCLOSE_PROMPT_DEFAULT_YES) { + *defquery = 'y'; + return TRUE; + } else { + *defquery = 'n'; + return TRUE; + } } if (defquery) - impossible("should_query_disclose_option: bad category %c", category); + impossible("should_query_disclose_option: bad category %c", category); else - impossible("should_query_disclose_option: null defquery"); + impossible("should_query_disclose_option: null defquery"); return TRUE; } STATIC_OVL void -disclose(how,taken) +disclose(how, taken) int how; boolean taken; { - char c = 0, defquery; - char qbuf[QBUFSZ]; - boolean ask; + char c = 0, defquery; + char qbuf[QBUFSZ]; + boolean ask; - if (invent && !done_stopprint) { - if (taken) - Sprintf(qbuf, "Do you want to see what you had when you %s?", - (how == QUIT) ? "quit" : "died"); - else - Strcpy(qbuf, "Do you want your possessions identified?"); + if (invent && !done_stopprint) { + if (taken) + Sprintf(qbuf, "Do you want to see what you had when you %s?", + (how == QUIT) ? "quit" : "died"); + else + Strcpy(qbuf, "Do you want your possessions identified?"); - ask = should_query_disclose_option('i', &defquery); - c = ask ? yn_function(qbuf, ynqchars, defquery) : defquery; - if (c == 'y') { - struct obj *obj; - - for (obj = invent; obj; obj = obj->nobj) { - makeknown(obj->otyp); - obj->known = obj->bknown = obj->dknown = obj->rknown = 1; - if (Is_container(obj) || obj->otyp == STATUE) - obj->cknown = obj->lknown = 1; - } - (void) display_inventory((char *)0, TRUE); - container_contents(invent, TRUE, TRUE, FALSE); - } - if (c == 'q') done_stopprint++; - } + ask = should_query_disclose_option('i', &defquery); + c = ask ? yn_function(qbuf, ynqchars, defquery) : defquery; + if (c == 'y') { + struct obj *obj; - if (!done_stopprint) { - ask = should_query_disclose_option('a', &defquery); - c = ask ? yn_function("Do you want to see your attributes?", - ynqchars, defquery) : defquery; - if (c == 'y') - enlightenment((BASICENLIGHTENMENT|MAGICENLIGHTENMENT), - (how >= PANICKED) ? ENL_GAMEOVERALIVE : ENL_GAMEOVERDEAD); - if (c == 'q') done_stopprint++; - } + for (obj = invent; obj; obj = obj->nobj) { + makeknown(obj->otyp); + obj->known = obj->bknown = obj->dknown = obj->rknown = 1; + if (Is_container(obj) || obj->otyp == STATUE) + obj->cknown = obj->lknown = 1; + } + (void) display_inventory((char *) 0, TRUE); + container_contents(invent, TRUE, TRUE, FALSE); + } + if (c == 'q') + done_stopprint++; + } - if (!done_stopprint) { - ask = should_query_disclose_option('v', &defquery); - list_vanquished(defquery, ask); - } + if (!done_stopprint) { + ask = should_query_disclose_option('a', &defquery); + c = ask ? yn_function("Do you want to see your attributes?", ynqchars, + defquery) + : defquery; + if (c == 'y') + enlightenment((BASICENLIGHTENMENT | MAGICENLIGHTENMENT), + (how >= PANICKED) ? ENL_GAMEOVERALIVE + : ENL_GAMEOVERDEAD); + if (c == 'q') + done_stopprint++; + } - if (!done_stopprint) { - ask = should_query_disclose_option('g', &defquery); - list_genocided(defquery, ask); - } + if (!done_stopprint) { + ask = should_query_disclose_option('v', &defquery); + list_vanquished(defquery, ask); + } - if (!done_stopprint) { - ask = should_query_disclose_option('c', &defquery); - c = ask ? yn_function("Do you want to see your conduct?", - ynqchars, defquery) : defquery; - if (c == 'y') - show_conduct((how >= PANICKED) ? 1 : 2); - if (c == 'q') done_stopprint++; - } + if (!done_stopprint) { + ask = should_query_disclose_option('g', &defquery); + list_genocided(defquery, ask); + } - if (!done_stopprint) { - ask = should_query_disclose_option('o', &defquery); - c = ask ? yn_function("Do you want to see the dungeon overview?", - ynqchars, defquery) : defquery; - if (c == 'y') - show_overview((how >= PANICKED) ? 1 : 2, how); - if (c == 'q') done_stopprint++; - } + if (!done_stopprint) { + ask = should_query_disclose_option('c', &defquery); + c = ask ? yn_function("Do you want to see your conduct?", ynqchars, + defquery) + : defquery; + if (c == 'y') + show_conduct((how >= PANICKED) ? 1 : 2); + if (c == 'q') + done_stopprint++; + } + + if (!done_stopprint) { + ask = should_query_disclose_option('o', &defquery); + c = ask ? yn_function("Do you want to see the dungeon overview?", + ynqchars, defquery) + : defquery; + if (c == 'y') + show_overview((how >= PANICKED) ? 1 : 2, how); + if (c == 'q') + done_stopprint++; + } } /* try to get the player back in a viable state after being killed */ @@ -684,29 +709,35 @@ STATIC_OVL void savelife(how) int how; { - int uhpmin = max(2 * u.ulevel, 10); + int uhpmin = max(2 * u.ulevel, 10); - if (u.uhpmax < uhpmin) u.uhpmax = uhpmin; - u.uhp = u.uhpmax; - u.uswldtim = 0; - if (u.uhunger < 500) { - u.uhunger = 500; - newuhs(FALSE); - } - /* cure impending doom of sickness hero won't have time to fix */ - if ((Sick & TIMEOUT) == 1L) { - u.usick_type = 0; - set_itimeout(&Sick, 0L); - } - if (how == CHOKING) init_uhunger(); - nomovemsg = "You survived that attempt on your life."; - context.move = 0; - if(multi > 0) multi = 0; else multi = -1; - if(u.utrap && u.utraptype == TT_LAVA) u.utrap = 0; - context.botl = 1; - u.ugrave_arise = NON_PM; - HUnchanging = 0L; - curs_on_u(); + if (u.uhpmax < uhpmin) + u.uhpmax = uhpmin; + u.uhp = u.uhpmax; + u.uswldtim = 0; + if (u.uhunger < 500) { + u.uhunger = 500; + newuhs(FALSE); + } + /* cure impending doom of sickness hero won't have time to fix */ + if ((Sick & TIMEOUT) == 1L) { + u.usick_type = 0; + set_itimeout(&Sick, 0L); + } + if (how == CHOKING) + init_uhunger(); + nomovemsg = "You survived that attempt on your life."; + context.move = 0; + if (multi > 0) + multi = 0; + else + multi = -1; + if (u.utrap && u.utraptype == TT_LAVA) + u.utrap = 0; + context.botl = 1; + u.ugrave_arise = NON_PM; + HUnchanging = 0L; + curs_on_u(); } /* @@ -715,30 +746,32 @@ int how; */ STATIC_OVL void get_valuables(list) -struct obj *list; /* inventory or container contents */ +struct obj *list; /* inventory or container contents */ { register struct obj *obj; register int i; /* find amulets and gems, ignoring all artifacts */ for (obj = list; obj; obj = obj->nobj) - if (Has_contents(obj)) { - get_valuables(obj->cobj); - } else if (obj->oartifact) { - continue; - } else if (obj->oclass == AMULET_CLASS) { - i = obj->otyp - FIRST_AMULET; - if (!amulets[i].count) { - amulets[i].count = obj->quan; - amulets[i].typ = obj->otyp; - } else amulets[i].count += obj->quan; /* always adds one */ - } else if (obj->oclass == GEM_CLASS && obj->otyp < LUCKSTONE) { - i = min(obj->otyp, LAST_GEM + 1) - FIRST_GEM; - if (!gems[i].count) { - gems[i].count = obj->quan; - gems[i].typ = obj->otyp; - } else gems[i].count += obj->quan; - } + if (Has_contents(obj)) { + get_valuables(obj->cobj); + } else if (obj->oartifact) { + continue; + } else if (obj->oclass == AMULET_CLASS) { + i = obj->otyp - FIRST_AMULET; + if (!amulets[i].count) { + amulets[i].count = obj->quan; + amulets[i].typ = obj->otyp; + } else + amulets[i].count += obj->quan; /* always adds one */ + } else if (obj->oclass == GEM_CLASS && obj->otyp < LUCKSTONE) { + i = min(obj->otyp, LAST_GEM + 1) - FIRST_GEM; + if (!gems[i].count) { + gems[i].count = obj->quan; + gems[i].typ = obj->otyp; + } else + gems[i].count += obj->quan; + } return; } @@ -749,21 +782,23 @@ struct obj *list; /* inventory or container contents */ STATIC_OVL void sort_valuables(list, size) struct valuable_data list[]; -int size; /* max value is less than 20 */ +int size; /* max value is less than 20 */ { register int i, j; struct valuable_data ltmp; /* move greater quantities to the front of the list */ for (i = 1; i < size; i++) { - if (list[i].count == 0) continue; /* empty slot */ - ltmp = list[i]; /* structure copy */ - for (j = i; j > 0; --j) - if (list[j-1].count >= ltmp.count) break; - else { - list[j] = list[j-1]; - } - list[j] = ltmp; + if (list[i].count == 0) + continue; /* empty slot */ + ltmp = list[i]; /* structure copy */ + for (j = i; j > 0; --j) + if (list[j - 1].count >= ltmp.count) + break; + else { + list[j] = list[j - 1]; + } + list[j] = ltmp; } return; } @@ -777,15 +812,15 @@ int what; { struct obj *otmp; for (otmp = list; otmp; otmp = otmp->nobj) { - switch(what) { - case CAT_CHECK: /* Schroedinger's Cat */ - /* Ascending is deterministic */ - if (SchroedingersBox(otmp)) - return rn2(2); - break; - } - if (Has_contents(otmp)) - return odds_and_ends(otmp->cobj, what); + switch (what) { + case CAT_CHECK: /* Schroedinger's Cat */ + /* Ascending is deterministic */ + if (SchroedingersBox(otmp)) + return rn2(2); + break; + } + if (Has_contents(otmp)) + return odds_and_ends(otmp->cobj, what); } return FALSE; } @@ -794,37 +829,36 @@ int what; STATIC_OVL void artifact_score(list, counting, endwin) struct obj *list; -boolean counting; /* true => add up points; false => display them */ +boolean counting; /* true => add up points; false => display them */ winid endwin; { char pbuf[BUFSZ]; struct obj *otmp; long value, points; - short dummy; /* object type returned by artifact_name() */ + short dummy; /* object type returned by artifact_name() */ for (otmp = list; otmp; otmp = otmp->nobj) { - if (otmp->oartifact || - otmp->otyp == BELL_OF_OPENING || - otmp->otyp == SPE_BOOK_OF_THE_DEAD || - otmp->otyp == CANDELABRUM_OF_INVOCATION) { - value = arti_cost(otmp); /* zorkmid value */ - points = value * 5 / 2; /* score value */ - if (counting) { - nowrap_add(u.urexp, points); - } else { - makeknown(otmp->otyp); - otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1; - /* assumes artifacts don't have quan > 1 */ - Sprintf(pbuf, "%s%s (worth %ld %s and %ld points)", - the_unique_obj(otmp) ? "The " : "", - otmp->oartifact ? artifact_name(xname(otmp), &dummy) : - OBJ_NAME(objects[otmp->otyp]), - value, currency(value), points); - putstr(endwin, 0, pbuf); - } - } - if (Has_contents(otmp)) - artifact_score(otmp->cobj, counting, endwin); + if (otmp->oartifact || otmp->otyp == BELL_OF_OPENING + || otmp->otyp == SPE_BOOK_OF_THE_DEAD + || otmp->otyp == CANDELABRUM_OF_INVOCATION) { + value = arti_cost(otmp); /* zorkmid value */ + points = value * 5 / 2; /* score value */ + if (counting) { + nowrap_add(u.urexp, points); + } else { + makeknown(otmp->otyp); + otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1; + /* assumes artifacts don't have quan > 1 */ + Sprintf(pbuf, "%s%s (worth %ld %s and %ld points)", + the_unique_obj(otmp) ? "The " : "", + otmp->oartifact ? artifact_name(xname(otmp), &dummy) + : OBJ_NAME(objects[otmp->otyp]), + value, currency(value), points); + putstr(endwin, 0, pbuf); + } + } + if (Has_contents(otmp)) + artifact_score(otmp->cobj, counting, endwin); } } @@ -833,511 +867,540 @@ void done(how) int how; { - boolean taken; - char pbuf[BUFSZ]; - winid endwin = WIN_ERR; - boolean bones_ok, have_windows = iflags.window_inited; - struct obj *corpse = (struct obj *)0; - time_t endtime; - long umoney; - long tmp; + boolean taken; + char pbuf[BUFSZ]; + winid endwin = WIN_ERR; + boolean bones_ok, have_windows = iflags.window_inited; + struct obj *corpse = (struct obj *) 0; + time_t endtime; + long umoney; + long tmp; - if (how == TRICKED) { - if (killer.name[0]) { - paniclog("trickery", killer.name); - killer.name[0] = 0; - } - if (wizard) { - You("are a very tricky wizard, it seems."); - return; - } - } + if (how == TRICKED) { + if (killer.name[0]) { + paniclog("trickery", killer.name); + killer.name[0] = 0; + } + if (wizard) { + You("are a very tricky wizard, it seems."); + return; + } + } - /* pbuf: holds Sprintf'd output for raw_print and putstr - */ - if (how == ASCENDED || (!killer.name[0] && how == GENOCIDED)) - killer.format = NO_KILLER_PREFIX; - /* Avoid killed by "a" burning or "a" starvation */ - if (!killer.name[0] && (how == STARVING || how == BURNING)) - killer.format = KILLED_BY; - if (!killer.name[0] || how >= PANICKED) - Strcpy(killer.name, deaths[how]); - - if (how < PANICKED) u.umortality++; - if (Lifesaved && (how <= GENOCIDED)) { - pline("But wait..."); - makeknown(AMULET_OF_LIFE_SAVING); - Your("medallion %s!", - !Blind ? "begins to glow" : "feels warm"); - if (how == CHOKING) You("vomit ..."); - You_feel("much better!"); - pline_The("medallion crumbles to dust!"); - if (uamul) useup(uamul); - - (void) adjattrib(A_CON, -1, TRUE); - savelife(how); - if (how == GENOCIDED) - pline("Unfortunately you are still genocided..."); - else { - killer.name[0] = 0; - killer.format = 0; - return; - } - } - if ((wizard || discover) && (how <= GENOCIDED)) { - if (paranoid_query(ParanoidDie, "Die?")) goto die; - pline("OK, so you don't %s.", - (how == CHOKING) ? "choke" : "die"); - savelife(how); - killer.name[0] = 0; - killer.format = 0; - return; - } - - /* - * The game is now over... + /* pbuf: holds Sprintf'd output for raw_print and putstr */ + if (how == ASCENDED || (!killer.name[0] && how == GENOCIDED)) + killer.format = NO_KILLER_PREFIX; + /* Avoid killed by "a" burning or "a" starvation */ + if (!killer.name[0] && (how == STARVING || how == BURNING)) + killer.format = KILLED_BY; + if (!killer.name[0] || how >= PANICKED) + Strcpy(killer.name, deaths[how]); + + if (how < PANICKED) + u.umortality++; + if (Lifesaved && (how <= GENOCIDED)) { + pline("But wait..."); + makeknown(AMULET_OF_LIFE_SAVING); + Your("medallion %s!", !Blind ? "begins to glow" : "feels warm"); + if (how == CHOKING) + You("vomit ..."); + You_feel("much better!"); + pline_The("medallion crumbles to dust!"); + if (uamul) + useup(uamul); + + (void) adjattrib(A_CON, -1, TRUE); + savelife(how); + if (how == GENOCIDED) + pline("Unfortunately you are still genocided..."); + else { + killer.name[0] = 0; + killer.format = 0; + return; + } + } + if ((wizard || discover) && (how <= GENOCIDED)) { + if (paranoid_query(ParanoidDie, "Die?")) + goto die; + pline("OK, so you don't %s.", (how == CHOKING) ? "choke" : "die"); + savelife(how); + killer.name[0] = 0; + killer.format = 0; + return; + } + +/* + * The game is now over... + */ die: - program_state.gameover = 1; - /* in case of a subsequent panic(), there's no point trying to save */ - program_state.something_worth_saving = 0; - /* render vision subsystem inoperative */ - iflags.vision_inited = 0; - /* might have been killed while using a disposable item, so make sure - it's gone prior to inventory disclosure and creation of bones data */ - inven_inuse(TRUE); - /* maybe not on object lists; if an active light source, would cause - big trouble (`obj_is_local' panic) for savebones() -> savelev() */ - if (thrownobj && thrownobj->where == OBJ_FREE) dealloc_obj(thrownobj); - if (kickedobj && kickedobj->where == OBJ_FREE) dealloc_obj(kickedobj); + program_state.gameover = 1; + /* in case of a subsequent panic(), there's no point trying to save */ + program_state.something_worth_saving = 0; + /* render vision subsystem inoperative */ + iflags.vision_inited = 0; + /* might have been killed while using a disposable item, so make sure + it's gone prior to inventory disclosure and creation of bones data */ + inven_inuse(TRUE); + /* maybe not on object lists; if an active light source, would cause + big trouble (`obj_is_local' panic) for savebones() -> savelev() */ + if (thrownobj && thrownobj->where == OBJ_FREE) + dealloc_obj(thrownobj); + if (kickedobj && kickedobj->where == OBJ_FREE) + dealloc_obj(kickedobj); - /* remember time of death here instead of having bones, rip, and - topten figure it out separately and possibly getting different - time or even day if player is slow responding to --More-- */ - endtime = getnow(); - urealtime.realtime += (long)(endtime - urealtime.restored); + /* remember time of death here instead of having bones, rip, and + topten figure it out separately and possibly getting different + time or even day if player is slow responding to --More-- */ + endtime = getnow(); + urealtime.realtime += (long) (endtime - urealtime.restored); - /* Sometimes you die on the first move. Life's not fair. - * On those rare occasions you get hosed immediately, go out - * smiling... :-) -3. - */ - if (moves <= 1 && how < PANICKED) /* You die... --More-- */ - pline("Do not pass go. Do not collect 200 %s.", currency(200L)); + /* Sometimes you die on the first move. Life's not fair. + * On those rare occasions you get hosed immediately, go out + * smiling... :-) -3. + */ + if (moves <= 1 && how < PANICKED) /* You die... --More-- */ + pline("Do not pass go. Do not collect 200 %s.", currency(200L)); - if (have_windows) wait_synch(); /* flush screen output */ + if (have_windows) + wait_synch(); /* flush screen output */ #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done_intr); -# if defined(UNIX) || defined(VMS) || defined (__EMX__) - (void) signal(SIGQUIT, (SIG_RET_TYPE) done_intr); - sethanguphandler(done_hangup); -# endif + (void) signal(SIGINT, (SIG_RET_TYPE) done_intr); +#if defined(UNIX) || defined(VMS) || defined(__EMX__) + (void) signal(SIGQUIT, (SIG_RET_TYPE) done_intr); + sethanguphandler(done_hangup); +#endif #endif /* NO_SIGNAL */ - bones_ok = (how < GENOCIDED) && can_make_bones(); + bones_ok = (how < GENOCIDED) && can_make_bones(); - if (bones_ok && launch_in_progress()) force_launch_placement(); + if (bones_ok && launch_in_progress()) + force_launch_placement(); - /* maintain ugrave_arise even for !bones_ok */ - if (how == BURNING || how == DISSOLVED) /* corpse gets burnt up too */ - u.ugrave_arise = (NON_PM - 2); /* leave no corpse */ - else if (how == STONING) - u.ugrave_arise = (NON_PM - 1); /* statue instead of corpse */ - else if (how == TURNED_SLIME) - u.ugrave_arise = PM_GREEN_SLIME; + /* maintain ugrave_arise even for !bones_ok */ + if (how == BURNING || how == DISSOLVED) /* corpse gets burnt up too */ + u.ugrave_arise = (NON_PM - 2); /* leave no corpse */ + else if (how == STONING) + u.ugrave_arise = (NON_PM - 1); /* statue instead of corpse */ + else if (how == TURNED_SLIME) + u.ugrave_arise = PM_GREEN_SLIME; - /* if pets will contribute to score, populate mydogs list now - (bones creation isn't a factor, but pline() messaging is) */ - if (how == ESCAPED || how == ASCENDED) keepdogs(TRUE); + /* if pets will contribute to score, populate mydogs list now + (bones creation isn't a factor, but pline() messaging is) */ + if (how == ESCAPED || how == ASCENDED) + keepdogs(TRUE); - if (how == QUIT) { - killer.format = NO_KILLER_PREFIX; - if (u.uhp < 1) { - how = DIED; - u.umortality++; /* skipped above when how==QUIT */ - Strcpy(killer.name, "quit while already on Charon's boat"); - } - } - if (how == ESCAPED || how == PANICKED) - killer.format = NO_KILLER_PREFIX; + if (how == QUIT) { + killer.format = NO_KILLER_PREFIX; + if (u.uhp < 1) { + how = DIED; + u.umortality++; /* skipped above when how==QUIT */ + Strcpy(killer.name, "quit while already on Charon's boat"); + } + } + if (how == ESCAPED || how == PANICKED) + killer.format = NO_KILLER_PREFIX; - if (how != PANICKED) { - /* these affect score and/or bones, but avoid them during panic */ - taken = paybill((how == ESCAPED) ? -1 : (how != QUIT)); - paygd(); - clearpriests(); - } else - taken = FALSE; /* lint; assert( !bones_ok ); */ + if (how != PANICKED) { + /* these affect score and/or bones, but avoid them during panic */ + taken = paybill((how == ESCAPED) ? -1 : (how != QUIT)); + paygd(); + clearpriests(); + } else + taken = FALSE; /* lint; assert( !bones_ok ); */ - clearlocks(); + clearlocks(); - if (have_windows) display_nhwindow(WIN_MESSAGE, FALSE); + if (have_windows) + display_nhwindow(WIN_MESSAGE, FALSE); - if (strcmp(flags.end_disclose, "none") && how != PANICKED) - disclose(how, taken); + if (strcmp(flags.end_disclose, "none") && how != PANICKED) + disclose(how, taken); - /* finish_paybill should be called after disclosure but before bones */ - if (bones_ok && taken) finish_paybill(); + /* finish_paybill should be called after disclosure but before bones */ + if (bones_ok && taken) + finish_paybill(); - /* grave creation should be after disclosure so it doesn't have - this grave in the current level's features for #overview */ - if (bones_ok && u.ugrave_arise == NON_PM && - !(mvitals[u.umonnum].mvflags & G_NOCORPSE)) { - int mnum = u.umonnum; + /* grave creation should be after disclosure so it doesn't have + this grave in the current level's features for #overview */ + if (bones_ok && u.ugrave_arise == NON_PM + && !(mvitals[u.umonnum].mvflags & G_NOCORPSE)) { + int mnum = u.umonnum; - if (!Upolyd) { - /* Base corpse on race when not poly'd since original - * u.umonnum is based on role, and all role monsters - * are human. - */ - mnum = (flags.female && urace.femalenum != NON_PM) ? - urace.femalenum : urace.malenum; - } - corpse = mk_named_object(CORPSE, &mons[mnum], - u.ux, u.uy, plname); - Sprintf(pbuf, "%s, ", plname); - formatkiller(eos(pbuf), sizeof pbuf - strlen(pbuf), how); - make_grave(u.ux, u.uy, pbuf); - } + if (!Upolyd) { + /* Base corpse on race when not poly'd since original + * u.umonnum is based on role, and all role monsters + * are human. + */ + mnum = (flags.female && urace.femalenum != NON_PM) + ? urace.femalenum + : urace.malenum; + } + corpse = mk_named_object(CORPSE, &mons[mnum], u.ux, u.uy, plname); + Sprintf(pbuf, "%s, ", plname); + formatkiller(eos(pbuf), sizeof pbuf - strlen(pbuf), how); + make_grave(u.ux, u.uy, pbuf); + } - /* calculate score, before creating bones [container gold] */ - { - int deepest = deepest_lev_reached(FALSE); + /* calculate score, before creating bones [container gold] */ + { + int deepest = deepest_lev_reached(FALSE); - umoney = money_cnt(invent); - tmp = u.umoney0; - umoney += hidden_gold(); /* accumulate gold from containers */ - tmp = umoney - tmp; /* net gain */ + umoney = money_cnt(invent); + tmp = u.umoney0; + umoney += hidden_gold(); /* accumulate gold from containers */ + tmp = umoney - tmp; /* net gain */ - if (tmp < 0L) - tmp = 0L; - if (how < PANICKED) - tmp -= tmp / 10L; - tmp += 50L * (long)(deepest - 1); - if (deepest > 20) - tmp += 1000L * (long)((deepest > 30) ? 10 : deepest - 20); - nowrap_add(u.urexp, tmp); + if (tmp < 0L) + tmp = 0L; + if (how < PANICKED) + tmp -= tmp / 10L; + tmp += 50L * (long) (deepest - 1); + if (deepest > 20) + tmp += 1000L * (long) ((deepest > 30) ? 10 : deepest - 20); + nowrap_add(u.urexp, tmp); - /* ascension gives a score bonus iff offering to original deity */ - if (how == ASCENDED && u.ualign.type == u.ualignbase[A_ORIGINAL]) { - /* retaining original alignment: score *= 2; - converting, then using helm-of-OA to switch back: *= 1.5 */ - tmp = (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]) ? - u.urexp : (u.urexp / 2L); - nowrap_add(u.urexp, tmp); - } - } + /* ascension gives a score bonus iff offering to original deity */ + if (how == ASCENDED && u.ualign.type == u.ualignbase[A_ORIGINAL]) { + /* retaining original alignment: score *= 2; + converting, then using helm-of-OA to switch back: *= 1.5 */ + tmp = (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]) + ? u.urexp + : (u.urexp / 2L); + nowrap_add(u.urexp, tmp); + } + } - if (u.ugrave_arise >= LOW_PM && u.ugrave_arise != PM_GREEN_SLIME) { - /* give this feedback even if bones aren't going to be created, - so that its presence or absence doesn't tip off the player to - new bones or their lack; it might be a lie if makemon fails */ - Your("body rises from the dead as %s...", - an(mons[u.ugrave_arise].mname)); - display_nhwindow(WIN_MESSAGE, FALSE); - } + if (u.ugrave_arise >= LOW_PM && u.ugrave_arise != PM_GREEN_SLIME) { + /* give this feedback even if bones aren't going to be created, + so that its presence or absence doesn't tip off the player to + new bones or their lack; it might be a lie if makemon fails */ + Your("body rises from the dead as %s...", + an(mons[u.ugrave_arise].mname)); + display_nhwindow(WIN_MESSAGE, FALSE); + } - if (bones_ok) { - if (!wizard || paranoid_query(ParanoidBones, "Save bones?")) - savebones(how, endtime, corpse); - /* corpse may be invalid pointer now so - ensure that it isn't used again */ - corpse = (struct obj *)0; - } + if (bones_ok) { + if (!wizard || paranoid_query(ParanoidBones, "Save bones?")) + savebones(how, endtime, corpse); + /* corpse may be invalid pointer now so + ensure that it isn't used again */ + corpse = (struct obj *) 0; + } - /* update gold for the rip output, which can't use hidden_gold() - (containers will be gone by then if bones just got saved...) */ - done_money = umoney; + /* update gold for the rip output, which can't use hidden_gold() + (containers will be gone by then if bones just got saved...) */ + done_money = umoney; - /* clean up unneeded windows */ - if (have_windows) { - wait_synch(); - display_nhwindow(WIN_MESSAGE, TRUE); - destroy_nhwindow(WIN_MAP); + /* clean up unneeded windows */ + if (have_windows) { + wait_synch(); + display_nhwindow(WIN_MESSAGE, TRUE); + destroy_nhwindow(WIN_MAP); #ifndef STATUS_VIA_WINDOWPORT - destroy_nhwindow(WIN_STATUS); + destroy_nhwindow(WIN_STATUS); #endif - destroy_nhwindow(WIN_MESSAGE); + destroy_nhwindow(WIN_MESSAGE); #ifdef STATUS_VIA_WINDOWPORT - WIN_MESSAGE = WIN_MAP = WIN_ERR; + WIN_MESSAGE = WIN_MAP = WIN_ERR; #else - WIN_MESSAGE = WIN_STATUS = WIN_MAP = WIN_ERR; + WIN_MESSAGE = WIN_STATUS = WIN_MAP = WIN_ERR; #endif - if(!done_stopprint || flags.tombstone) - endwin = create_nhwindow(NHW_TEXT); + if (!done_stopprint || flags.tombstone) + endwin = create_nhwindow(NHW_TEXT); - if (how < GENOCIDED && flags.tombstone && endwin != WIN_ERR) - outrip(endwin, how, endtime); - } else - done_stopprint = 1; /* just avoid any more output */ + if (how < GENOCIDED && flags.tombstone && endwin != WIN_ERR) + outrip(endwin, how, endtime); + } else + done_stopprint = 1; /* just avoid any more output */ - if (u.uhave.amulet) Strcat(killer.name, " (with the Amulet)"); - else if (how == ESCAPED) { - if (Is_astralevel(&u.uz)) /* offered Amulet to wrong deity */ - Strcat(killer.name, " (in celestial disgrace)"); - else if (carrying(FAKE_AMULET_OF_YENDOR)) - Strcat(killer.name, " (with a fake Amulet)"); - /* don't bother counting to see whether it should be plural */ - } + if (u.uhave.amulet) + Strcat(killer.name, " (with the Amulet)"); + else if (how == ESCAPED) { + if (Is_astralevel(&u.uz)) /* offered Amulet to wrong deity */ + Strcat(killer.name, " (in celestial disgrace)"); + else if (carrying(FAKE_AMULET_OF_YENDOR)) + Strcat(killer.name, " (with a fake Amulet)"); + /* don't bother counting to see whether it should be plural */ + } - if (!done_stopprint) { - Sprintf(pbuf, "%s %s the %s...", Goodbye(), plname, - how != ASCENDED ? - (const char *) ((flags.female && urole.name.f) ? - urole.name.f : urole.name.m) : - (const char *) (flags.female ? "Demigoddess" : "Demigod")); - putstr(endwin, 0, pbuf); - putstr(endwin, 0, ""); - } + if (!done_stopprint) { + Sprintf( + pbuf, "%s %s the %s...", Goodbye(), plname, + how != ASCENDED + ? (const char *) ((flags.female && urole.name.f) + ? urole.name.f + : urole.name.m) + : (const char *) (flags.female ? "Demigoddess" : "Demigod")); + putstr(endwin, 0, pbuf); + putstr(endwin, 0, ""); + } - if (how == ESCAPED || how == ASCENDED) { - register struct monst *mtmp; - register struct obj *otmp; - register struct val_list *val; - register int i; + if (how == ESCAPED || how == ASCENDED) { + register struct monst *mtmp; + register struct obj *otmp; + register struct val_list *val; + register int i; - for (val = valuables; val->list; val++) - for (i = 0; i < val->size; i++) { - val->list[i].count = 0L; - } - get_valuables(invent); + for (val = valuables; val->list; val++) + for (i = 0; i < val->size; i++) { + val->list[i].count = 0L; + } + get_valuables(invent); - /* add points for collected valuables */ - for (val = valuables; val->list; val++) - for (i = 0; i < val->size; i++) - if (val->list[i].count != 0L) { - tmp = val->list[i].count - * (long)objects[val->list[i].typ].oc_cost; - nowrap_add(u.urexp, tmp); - } + /* add points for collected valuables */ + for (val = valuables; val->list; val++) + for (i = 0; i < val->size; i++) + if (val->list[i].count != 0L) { + tmp = val->list[i].count + * (long) objects[val->list[i].typ].oc_cost; + nowrap_add(u.urexp, tmp); + } - /* count the points for artifacts */ - artifact_score(invent, TRUE, endwin); + /* count the points for artifacts */ + artifact_score(invent, TRUE, endwin); - viz_array[0][0] |= IN_SIGHT; /* need visibility for naming */ - mtmp = mydogs; - if (!done_stopprint) Strcpy(pbuf, "You"); - if (!Schroedingers_cat) /* check here in case disclosure was off */ - Schroedingers_cat = odds_and_ends(invent, CAT_CHECK); - if (Schroedingers_cat) { - int mhp, m_lev = adj_lev(&mons[PM_HOUSECAT]); - mhp = d(m_lev, 8); - nowrap_add(u.urexp, mhp); - if (!done_stopprint) - Strcat(eos(pbuf), " and Schroedinger's cat"); - } - if (mtmp) { - while (mtmp) { - if (!done_stopprint) - Sprintf(eos(pbuf), " and %s", mon_nam(mtmp)); - if (mtmp->mtame) - nowrap_add(u.urexp, mtmp->mhp); - mtmp = mtmp->nmon; - } - if (!done_stopprint) putstr(endwin, 0, pbuf); - pbuf[0] = '\0'; - } else { - if (!done_stopprint) Strcat(pbuf, " "); - } - if (!done_stopprint) { - Sprintf(eos(pbuf), "%s with %ld point%s,", - how==ASCENDED ? "went to your reward" : - "escaped from the dungeon", - u.urexp, plur(u.urexp)); - putstr(endwin, 0, pbuf); - } + viz_array[0][0] |= IN_SIGHT; /* need visibility for naming */ + mtmp = mydogs; + if (!done_stopprint) + Strcpy(pbuf, "You"); + if (!Schroedingers_cat) /* check here in case disclosure was off */ + Schroedingers_cat = odds_and_ends(invent, CAT_CHECK); + if (Schroedingers_cat) { + int mhp, m_lev = adj_lev(&mons[PM_HOUSECAT]); + mhp = d(m_lev, 8); + nowrap_add(u.urexp, mhp); + if (!done_stopprint) + Strcat(eos(pbuf), " and Schroedinger's cat"); + } + if (mtmp) { + while (mtmp) { + if (!done_stopprint) + Sprintf(eos(pbuf), " and %s", mon_nam(mtmp)); + if (mtmp->mtame) + nowrap_add(u.urexp, mtmp->mhp); + mtmp = mtmp->nmon; + } + if (!done_stopprint) + putstr(endwin, 0, pbuf); + pbuf[0] = '\0'; + } else { + if (!done_stopprint) + Strcat(pbuf, " "); + } + if (!done_stopprint) { + Sprintf(eos(pbuf), "%s with %ld point%s,", + how == ASCENDED ? "went to your reward" + : "escaped from the dungeon", + u.urexp, plur(u.urexp)); + putstr(endwin, 0, pbuf); + } - if (!done_stopprint) - artifact_score(invent, FALSE, endwin); /* list artifacts */ + if (!done_stopprint) + artifact_score(invent, FALSE, endwin); /* list artifacts */ - /* list valuables here */ - for (val = valuables; val->list; val++) { - sort_valuables(val->list, val->size); - for (i = 0; i < val->size && !done_stopprint; i++) { - int typ = val->list[i].typ; - long count = val->list[i].count; + /* list valuables here */ + for (val = valuables; val->list; val++) { + sort_valuables(val->list, val->size); + for (i = 0; i < val->size && !done_stopprint; i++) { + int typ = val->list[i].typ; + long count = val->list[i].count; - if (count == 0L) continue; - if (objects[typ].oc_class != GEM_CLASS || typ <= LAST_GEM) { - otmp = mksobj(typ, FALSE, FALSE); - makeknown(otmp->otyp); - otmp->known = 1; /* for fake amulets */ - otmp->dknown = 1; /* seen it (blindness fix) */ - if (has_oname(otmp)) free_oname(otmp); - otmp->quan = count; - Sprintf(pbuf, "%8ld %s (worth %ld %s),", - count, xname(otmp), - count * (long)objects[typ].oc_cost, currency(2L)); - obfree(otmp, (struct obj *)0); - } else { - Sprintf(pbuf, - "%8ld worthless piece%s of colored glass,", - count, plur(count)); - } - putstr(endwin, 0, pbuf); - } - } + if (count == 0L) + continue; + if (objects[typ].oc_class != GEM_CLASS || typ <= LAST_GEM) { + otmp = mksobj(typ, FALSE, FALSE); + makeknown(otmp->otyp); + otmp->known = 1; /* for fake amulets */ + otmp->dknown = 1; /* seen it (blindness fix) */ + if (has_oname(otmp)) + free_oname(otmp); + otmp->quan = count; + Sprintf(pbuf, "%8ld %s (worth %ld %s),", count, + xname(otmp), count * (long) objects[typ].oc_cost, + currency(2L)); + obfree(otmp, (struct obj *) 0); + } else { + Sprintf(pbuf, "%8ld worthless piece%s of colored glass,", + count, plur(count)); + } + putstr(endwin, 0, pbuf); + } + } - } else if (!done_stopprint) { - /* did not escape or ascend */ - if (u.uz.dnum == 0 && u.uz.dlevel <= 0) { - /* level teleported out of the dungeon; `how' is DIED, - due to falling or to "arriving at heaven prematurely" */ - Sprintf(pbuf, "You %s beyond the confines of the dungeon", - (u.uz.dlevel < 0) ? "passed away" : ends[how]); - } else { - /* more conventional demise */ - const char *where = dungeons[u.uz.dnum].dname; + } else if (!done_stopprint) { + /* did not escape or ascend */ + if (u.uz.dnum == 0 && u.uz.dlevel <= 0) { + /* level teleported out of the dungeon; `how' is DIED, + due to falling or to "arriving at heaven prematurely" */ + Sprintf(pbuf, "You %s beyond the confines of the dungeon", + (u.uz.dlevel < 0) ? "passed away" : ends[how]); + } else { + /* more conventional demise */ + const char *where = dungeons[u.uz.dnum].dname; - if (Is_astralevel(&u.uz)) where = "The Astral Plane"; - Sprintf(pbuf, "You %s in %s", ends[how], where); - if (!In_endgame(&u.uz) && !Is_knox(&u.uz)) - Sprintf(eos(pbuf), " on dungeon level %d", - In_quest(&u.uz) ? dunlev(&u.uz) : depth(&u.uz)); - } + if (Is_astralevel(&u.uz)) + where = "The Astral Plane"; + Sprintf(pbuf, "You %s in %s", ends[how], where); + if (!In_endgame(&u.uz) && !Is_knox(&u.uz)) + Sprintf(eos(pbuf), " on dungeon level %d", + In_quest(&u.uz) ? dunlev(&u.uz) : depth(&u.uz)); + } - Sprintf(eos(pbuf), " with %ld point%s,", - u.urexp, plur(u.urexp)); - putstr(endwin, 0, pbuf); - } + Sprintf(eos(pbuf), " with %ld point%s,", u.urexp, plur(u.urexp)); + putstr(endwin, 0, pbuf); + } - if (!done_stopprint) { - Sprintf(pbuf, "and %ld piece%s of gold, after %ld move%s.", - umoney, plur(umoney), moves, plur(moves)); - putstr(endwin, 0, pbuf); - } - if (!done_stopprint) { - Sprintf(pbuf, - "You were level %d with a maximum of %d hit point%s when you %s.", - u.ulevel, u.uhpmax, plur(u.uhpmax), ends[how]); - putstr(endwin, 0, pbuf); - putstr(endwin, 0, ""); - } - if (!done_stopprint) - display_nhwindow(endwin, TRUE); - if (endwin != WIN_ERR) - destroy_nhwindow(endwin); + if (!done_stopprint) { + Sprintf(pbuf, "and %ld piece%s of gold, after %ld move%s.", umoney, + plur(umoney), moves, plur(moves)); + putstr(endwin, 0, pbuf); + } + if (!done_stopprint) { + Sprintf( + pbuf, + "You were level %d with a maximum of %d hit point%s when you %s.", + u.ulevel, u.uhpmax, plur(u.uhpmax), ends[how]); + putstr(endwin, 0, pbuf); + putstr(endwin, 0, ""); + } + if (!done_stopprint) + display_nhwindow(endwin, TRUE); + if (endwin != WIN_ERR) + destroy_nhwindow(endwin); - /* "So when I die, the first thing I will see in Heaven is a - * score list?" */ - if (have_windows && !iflags.toptenwin) - exit_nhwindows((char *)0), have_windows = FALSE; - topten(how, endtime); - if (have_windows) - exit_nhwindows((char *)0); + /* "So when I die, the first thing I will see in Heaven is a + * score list?" */ + if (have_windows && !iflags.toptenwin) + exit_nhwindows((char *) 0), have_windows = FALSE; + topten(how, endtime); + if (have_windows) + exit_nhwindows((char *) 0); - if(done_stopprint) { raw_print(""); raw_print(""); } - terminate(EXIT_SUCCESS); + if (done_stopprint) { + raw_print(""); + raw_print(""); + } + terminate(EXIT_SUCCESS); } - void container_contents(list, identified, all_containers, reportempty) struct obj *list; boolean identified, all_containers, reportempty; { - register struct obj *box, *obj; - struct obj **oarray; - int i,n; - char *invlet; - char buf[BUFSZ]; - boolean cat, deadcat; + register struct obj *box, *obj; + struct obj **oarray; + int i, n; + char *invlet; + char buf[BUFSZ]; + boolean cat, deadcat; - for (box = list; box; box = box->nobj) { - if (Is_container(box) || box->otyp == STATUE) { - box->cknown = 1; /* we're looking at the contents now */ - if (identified) box->lknown = 1; - cat = deadcat = FALSE; - if (SchroedingersBox(box) && !Schroedingers_cat) { - /* Schroedinger's Cat? */ - cat = odds_and_ends(box, CAT_CHECK); - if (cat) Schroedingers_cat = TRUE; - else deadcat = TRUE; - box->spe = 0; - } - if (box->otyp == BAG_OF_TRICKS) { - continue; /* wrong type of container */ - } else if (box->cobj) { - winid tmpwin = create_nhwindow(NHW_MENU); + for (box = list; box; box = box->nobj) { + if (Is_container(box) || box->otyp == STATUE) { + box->cknown = 1; /* we're looking at the contents now */ + if (identified) + box->lknown = 1; + cat = deadcat = FALSE; + if (SchroedingersBox(box) && !Schroedingers_cat) { + /* Schroedinger's Cat? */ + cat = odds_and_ends(box, CAT_CHECK); + if (cat) + Schroedingers_cat = TRUE; + else + deadcat = TRUE; + box->spe = 0; + } + if (box->otyp == BAG_OF_TRICKS) { + continue; /* wrong type of container */ + } else if (box->cobj) { + winid tmpwin = create_nhwindow(NHW_MENU); - /* count the number of items */ - for (n = 0, obj = box->cobj; obj; obj = obj->nobj) n++; - /* Make a temporary array to store the objects sorted */ - oarray = objarr_init(n); + /* count the number of items */ + for (n = 0, obj = box->cobj; obj; obj = obj->nobj) + n++; + /* Make a temporary array to store the objects sorted */ + oarray = objarr_init(n); - /* Add objects to the array */ - i = 0; - invlet = flags.inv_order; - nextclass: - for (obj = box->cobj; obj; obj = obj->nobj) { - if (!flags.sortpack || obj->oclass == *invlet) { - objarr_set(obj, i++, oarray, (flags.sortloot == 'f' || flags.sortloot == 'l') ); - } - } /* for loop */ - if (flags.sortpack) { - if (*++invlet) goto nextclass; - } + /* Add objects to the array */ + i = 0; + invlet = flags.inv_order; + nextclass: + for (obj = box->cobj; obj; obj = obj->nobj) { + if (!flags.sortpack || obj->oclass == *invlet) { + objarr_set( + obj, i++, oarray, + (flags.sortloot == 'f' || flags.sortloot == 'l')); + } + } /* for loop */ + if (flags.sortpack) { + if (*++invlet) + goto nextclass; + } - Sprintf(buf, "Contents of %s:", the(xname(box))); - putstr(tmpwin, 0, buf); - putstr(tmpwin, 0, ""); - for (i = 0; i < n; i++) { - obj = oarray[i]; - if (identified) { - makeknown(obj->otyp); - obj->known = obj->bknown = - obj->dknown = obj->rknown = 1; - if (Is_container(obj) || obj->otyp == STATUE) - obj->cknown = obj->lknown = 1; - } - putstr(tmpwin, 0, doname(obj)); - } - free(oarray); - if (cat) putstr(tmpwin, 0, "Schroedinger's cat"); - else if (deadcat) putstr(tmpwin, 0, "Schroedinger's dead cat"); - display_nhwindow(tmpwin, TRUE); - destroy_nhwindow(tmpwin); - if (all_containers) - container_contents(box->cobj, identified, TRUE, - reportempty); - } else if (cat || deadcat) { - pline("%s Schroedinger's %scat!", - Tobjnam(box, "contain"), deadcat ? "dead " : ""); - display_nhwindow(WIN_MESSAGE, FALSE); - } else if (reportempty) { - pline("%s is empty.", upstart(thesimpleoname(box))); - display_nhwindow(WIN_MESSAGE, FALSE); - } - } - if (!all_containers) - break; - } + Sprintf(buf, "Contents of %s:", the(xname(box))); + putstr(tmpwin, 0, buf); + putstr(tmpwin, 0, ""); + for (i = 0; i < n; i++) { + obj = oarray[i]; + if (identified) { + makeknown(obj->otyp); + obj->known = obj->bknown = obj->dknown = obj->rknown = + 1; + if (Is_container(obj) || obj->otyp == STATUE) + obj->cknown = obj->lknown = 1; + } + putstr(tmpwin, 0, doname(obj)); + } + free(oarray); + if (cat) + putstr(tmpwin, 0, "Schroedinger's cat"); + else if (deadcat) + putstr(tmpwin, 0, "Schroedinger's dead cat"); + display_nhwindow(tmpwin, TRUE); + destroy_nhwindow(tmpwin); + if (all_containers) + container_contents(box->cobj, identified, TRUE, + reportempty); + } else if (cat || deadcat) { + pline("%s Schroedinger's %scat!", Tobjnam(box, "contain"), + deadcat ? "dead " : ""); + display_nhwindow(WIN_MESSAGE, FALSE); + } else if (reportempty) { + pline("%s is empty.", upstart(thesimpleoname(box))); + display_nhwindow(WIN_MESSAGE, FALSE); + } + } + if (!all_containers) + break; + } } - /* should be called with either EXIT_SUCCESS or EXIT_FAILURE */ void terminate(status) int status; { - program_state.in_moveloop = 0; /* won't be returning to normal play */ + program_state.in_moveloop = 0; /* won't be returning to normal play */ #ifdef MAC - getreturn("to exit"); + getreturn("to exit"); #endif - /* don't bother to try to release memory if we're in panic mode, to - avoid trouble in case that happens to be due to memory problems */ - if (!program_state.panicking) { - freedynamicdata(); - dlb_cleanup(); - } + /* don't bother to try to release memory if we're in panic mode, to + avoid trouble in case that happens to be due to memory problems */ + if (!program_state.panicking) { + freedynamicdata(); + dlb_cleanup(); + } #ifdef VMS - /* don't call exit() if already executing within an exit handler; - that would cancel any other pending user-mode handlers */ - if (program_state.exiting) return; + /* don't call exit() if already executing within an exit handler; + that would cancel any other pending user-mode handlers */ + if (program_state.exiting) + return; #endif - program_state.exiting = 1; - nethack_exit(status); + program_state.exiting = 1; + nethack_exit(status); } /* #vanquished command */ @@ -1362,66 +1425,76 @@ boolean ask; /* get totals first */ for (i = LOW_PM; i < NUMMONS; i++) { - if (mvitals[i].died) ntypes++; - total_killed += (long)mvitals[i].died; - if (mons[i].mlevel > max_lev) max_lev = mons[i].mlevel; + if (mvitals[i].died) + ntypes++; + total_killed += (long) mvitals[i].died; + if (mons[i].mlevel > max_lev) + max_lev = mons[i].mlevel; } /* vanquished creatures list; * includes all dead monsters, not just those killed by the player */ if (ntypes != 0) { - c = ask ? yn_function("Do you want an account of creatures vanquished?", - ynqchars, defquery) : defquery; - if (c == 'q') done_stopprint++; - if (c == 'y' || c == 'a') { - klwin = create_nhwindow(NHW_MENU); - putstr(klwin, 0, "Vanquished creatures:"); - putstr(klwin, 0, ""); + c = ask ? yn_function( + "Do you want an account of creatures vanquished?", + ynqchars, defquery) + : defquery; + if (c == 'q') + done_stopprint++; + if (c == 'y' || c == 'a') { + klwin = create_nhwindow(NHW_MENU); + putstr(klwin, 0, "Vanquished creatures:"); + putstr(klwin, 0, ""); - /* countdown by monster "toughness" */ - for (lev = max_lev; lev >= 0; lev--) - for (i = LOW_PM; i < NUMMONS; i++) - if (mons[i].mlevel == lev && (nkilled = mvitals[i].died) > 0) { - if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) { - Sprintf(buf, "%s%s", - !type_is_pname(&mons[i]) ? "The " : "", - mons[i].mname); - if (nkilled > 1) { - switch (nkilled) { - case 2: Sprintf(eos(buf)," (twice)"); break; - case 3: Sprintf(eos(buf)," (thrice)"); break; - default: Sprintf(eos(buf)," (%d times)", - nkilled); - break; - } - } - } else { - /* trolls or undead might have come back, - but we don't keep track of that */ - if (nkilled == 1) - Strcpy(buf, an(mons[i].mname)); - else - Sprintf(buf, "%d %s", - nkilled, makeplural(mons[i].mname)); - } - putstr(klwin, 0, buf); - } - /* - * if (Hallucination) - * putstr(klwin, 0, "and a partridge in a pear tree"); - */ - if (ntypes > 1) { - putstr(klwin, 0, ""); - Sprintf(buf, "%ld creatures vanquished.", total_killed); - putstr(klwin, 0, buf); - } - display_nhwindow(klwin, TRUE); - destroy_nhwindow(klwin); - } + /* countdown by monster "toughness" */ + for (lev = max_lev; lev >= 0; lev--) + for (i = LOW_PM; i < NUMMONS; i++) + if (mons[i].mlevel == lev + && (nkilled = mvitals[i].died) > 0) { + if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) { + Sprintf(buf, "%s%s", + !type_is_pname(&mons[i]) ? "The " : "", + mons[i].mname); + if (nkilled > 1) { + switch (nkilled) { + case 2: + Sprintf(eos(buf), " (twice)"); + break; + case 3: + Sprintf(eos(buf), " (thrice)"); + break; + default: + Sprintf(eos(buf), " (%d times)", nkilled); + break; + } + } + } else { + /* trolls or undead might have come back, + but we don't keep track of that */ + if (nkilled == 1) + Strcpy(buf, an(mons[i].mname)); + else + Sprintf(buf, "%d %s", nkilled, + makeplural(mons[i].mname)); + } + putstr(klwin, 0, buf); + } + /* + * if (Hallucination) + * putstr(klwin, 0, "and a partridge in a pear tree"); + */ + if (ntypes > 1) { + putstr(klwin, 0, ""); + Sprintf(buf, "%ld creatures vanquished.", total_killed); + putstr(klwin, 0, buf); + } + display_nhwindow(klwin, TRUE); + destroy_nhwindow(klwin); + } } else if (defquery == 'a') { - /* #dovanquished rather than final disclosure, so pline() is ok */ - pline("No monsters have been vanquished."); + /* #dovanquished rather than final disclosure, so pline() is ok */ + pline("No monsters have been vanquished."); } } @@ -1432,7 +1505,8 @@ num_genocides() int i, n = 0; for (i = LOW_PM; i < NUMMONS; ++i) - if (mvitals[i].mvflags & G_GENOD) ++n; + if (mvitals[i].mvflags & G_GENOD) + ++n; return n; } @@ -1443,14 +1517,13 @@ num_extinct() int i, n = 0; for (i = LOW_PM; i < NUMMONS; ++i) - if (!(mvitals[i].mvflags & G_GENOD) && - (mvitals[i].mvflags & G_GONE) && - !(mons[i].geno & G_UNIQ)) ++n; + if (!(mvitals[i].mvflags & G_GENOD) && (mvitals[i].mvflags & G_GONE) + && !(mons[i].geno & G_UNIQ)) + ++n; return n; } - STATIC_OVL void list_genocided(defquery, ask) char defquery; @@ -1467,64 +1540,65 @@ boolean ask; /* genocided or extinct species list */ if (ngenocided != 0 || nextinct != 0) { - Sprintf(buf, "Do you want a list of %sspecies%s%s?", - (nextinct && !ngenocided) ? "extinct " : "", - (ngenocided) ? " genocided" : "", - (nextinct && ngenocided) ? " and extinct" : ""); - c = ask ? yn_function(buf, ynqchars, defquery) : defquery; - if (c == 'q') done_stopprint++; - if (c == 'y') { - klwin = create_nhwindow(NHW_MENU); - Sprintf(buf, "%s%s species:", - (ngenocided) ? "Genocided" : "Extinct", - (nextinct && ngenocided) ? " or extinct" : ""); - putstr(klwin, 0, buf); - putstr(klwin, 0, ""); + Sprintf(buf, "Do you want a list of %sspecies%s%s?", + (nextinct && !ngenocided) ? "extinct " : "", + (ngenocided) ? " genocided" : "", + (nextinct && ngenocided) ? " and extinct" : ""); + c = ask ? yn_function(buf, ynqchars, defquery) : defquery; + if (c == 'q') + done_stopprint++; + if (c == 'y') { + klwin = create_nhwindow(NHW_MENU); + Sprintf(buf, "%s%s species:", + (ngenocided) ? "Genocided" : "Extinct", + (nextinct && ngenocided) ? " or extinct" : ""); + putstr(klwin, 0, buf); + putstr(klwin, 0, ""); - for (i = LOW_PM; i < NUMMONS; i++) - if (mvitals[i].mvflags & G_GONE && !(mons[i].geno & G_UNIQ)) { - if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) - Sprintf(buf, "%s%s", - !type_is_pname(&mons[i]) ? "" : "the ", - mons[i].mname); - else - Strcpy(buf, makeplural(mons[i].mname)); - if (!(mvitals[i].mvflags & G_GENOD)) - Strcat(buf, " (extinct)"); - putstr(klwin, 0, buf); - } + for (i = LOW_PM; i < NUMMONS; i++) + if (mvitals[i].mvflags & G_GONE && !(mons[i].geno & G_UNIQ)) { + if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) + Sprintf(buf, "%s%s", + !type_is_pname(&mons[i]) ? "" : "the ", + mons[i].mname); + else + Strcpy(buf, makeplural(mons[i].mname)); + if (!(mvitals[i].mvflags & G_GENOD)) + Strcat(buf, " (extinct)"); + putstr(klwin, 0, buf); + } - putstr(klwin, 0, ""); - if (ngenocided > 0) { - Sprintf(buf, "%d species genocided.", ngenocided); - putstr(klwin, 0, buf); - } - if (nextinct > 0) { - Sprintf(buf, "%d species extinct.", nextinct); - putstr(klwin, 0, buf); - } + putstr(klwin, 0, ""); + if (ngenocided > 0) { + Sprintf(buf, "%d species genocided.", ngenocided); + putstr(klwin, 0, buf); + } + if (nextinct > 0) { + Sprintf(buf, "%d species extinct.", nextinct); + putstr(klwin, 0, buf); + } - display_nhwindow(klwin, TRUE); - destroy_nhwindow(klwin); - } + display_nhwindow(klwin, TRUE); + destroy_nhwindow(klwin); + } } } /* set a delayed killer, ensure non-delayed killer is cleared out */ void delayed_killer(id, format, killername) - int id; - int format; - const char *killername; +int id; +int format; +const char *killername; { struct kinfo *k = find_delayed_killer(id); - if (k == (struct kinfo*) 0) { - /* no match, add a new delayed killer to the list */ - k = (struct kinfo*) alloc(sizeof(struct kinfo)); - k->id = id; - k->next = killer.next; - killer.next = k; + if (k == (struct kinfo *) 0) { + /* no match, add a new delayed killer to the list */ + k = (struct kinfo *) alloc(sizeof(struct kinfo)); + k->id = id; + k->next = killer.next; + killer.next = k; } k->format = format; @@ -1532,14 +1606,15 @@ delayed_killer(id, format, killername) killer.name[0] = 0; } -struct kinfo* +struct kinfo * find_delayed_killer(id) - int id; +int id; { - struct kinfo* k; + struct kinfo *k; - for (k = killer.next; k != (struct kinfo*) 0; k = k->next) { - if (k->id == id) break; + for (k = killer.next; k != (struct kinfo *) 0; k = k->next) { + if (k->id == id) + break; } return k; @@ -1547,121 +1622,129 @@ find_delayed_killer(id) void dealloc_killer(kptr) - struct kinfo *kptr; +struct kinfo *kptr; { struct kinfo *prev = &killer, *k; - if (kptr == (struct kinfo *)0) return; - for (k = killer.next; k != (struct kinfo*) 0; k = k->next) { - if (k == kptr) break; - prev = k; + if (kptr == (struct kinfo *) 0) + return; + for (k = killer.next; k != (struct kinfo *) 0; k = k->next) { + if (k == kptr) + break; + prev = k; } - if (k == (struct kinfo*) 0) { - impossible("dealloc_killer not on list"); + if (k == (struct kinfo *) 0) { + impossible("dealloc_killer not on list"); } else { - prev->next = k->next; - free((genericptr_t) k); + prev->next = k->next; + free((genericptr_t) k); } } void save_killers(fd, mode) - int fd; - int mode; +int fd; +int mode; { struct kinfo *kptr; if (perform_bwrite(mode)) { - for (kptr = &killer; kptr != (struct kinfo*)0; kptr = kptr->next) { - bwrite(fd, (genericptr_t)kptr, sizeof(struct kinfo)); - } + for (kptr = &killer; kptr != (struct kinfo *) 0; kptr = kptr->next) { + bwrite(fd, (genericptr_t) kptr, sizeof(struct kinfo)); + } } if (release_data(mode)) { - while (killer.next) { - kptr = killer.next->next; - free((genericptr_t)killer.next); - killer.next = kptr; - } + while (killer.next) { + kptr = killer.next->next; + free((genericptr_t) killer.next); + killer.next = kptr; + } } } void restore_killers(fd) - int fd; +int fd; { struct kinfo *kptr; - for (kptr = &killer; kptr != (struct kinfo*)0; kptr = kptr->next) { - mread(fd, (genericptr_t)kptr, sizeof(struct kinfo)); - if (kptr->next) { - kptr->next = (struct kinfo*) alloc(sizeof(struct kinfo)); - } + for (kptr = &killer; kptr != (struct kinfo *) 0; kptr = kptr->next) { + mread(fd, (genericptr_t) kptr, sizeof(struct kinfo)); + if (kptr->next) { + kptr->next = (struct kinfo *) alloc(sizeof(struct kinfo)); + } } } static int wordcount(p) - char *p; +char *p; { int words = 0; while (*p) { - while (*p && isspace((uchar)*p)) p++; - if (*p) words++; - while (*p && !isspace((uchar)*p)) p++; + while (*p && isspace((uchar) *p)) + p++; + if (*p) + words++; + while (*p && !isspace((uchar) *p)) + p++; } return words; } static void bel_copy1(inp, out) - char **inp, *out; +char **inp, *out; { char *in = *inp; - out += strlen(out); /* eos() */ - while (*in && isspace((uchar)*in)) in++; - while (*in && !isspace((uchar)*in)) *out++ = *in++; + out += strlen(out); /* eos() */ + while (*in && isspace((uchar) *in)) + in++; + while (*in && !isspace((uchar) *in)) + *out++ = *in++; *out = '\0'; *inp = in; } char * build_english_list(in) - char *in; +char *in; { char *out, *p = in; - int len = (int)strlen(p), words = wordcount(p); + int len = (int) strlen(p), words = wordcount(p); /* +3: " or " - " "; +(words - 1): (N-1)*(", " - " ") */ - if (words > 1) len += 3 + (words - 1); - out = (char *)alloc(len + 1); - *out = '\0'; /* bel_copy1() appends */ + if (words > 1) + len += 3 + (words - 1); + out = (char *) alloc(len + 1); + *out = '\0'; /* bel_copy1() appends */ - switch(words){ + switch (words) { case 0: - impossible("no words in list"); - break; + impossible("no words in list"); + break; case 1: - /* "single" */ - bel_copy1(&p, out); - break; + /* "single" */ + bel_copy1(&p, out); + break; default: - if (words == 2) { - /* "first or second" */ - bel_copy1(&p, out); - Strcat(out, " "); - } else { - /* "first, second, or third */ - do { - bel_copy1(&p, out); - Strcat(out, ", "); - } while (--words > 1); - } - Strcat(out, "or "); - bel_copy1(&p, out); - break; + if (words == 2) { + /* "first or second" */ + bel_copy1(&p, out); + Strcat(out, " "); + } else { + /* "first, second, or third */ + do { + bel_copy1(&p, out); + Strcat(out, ", "); + } while (--words > 1); + } + Strcat(out, "or "); + bel_copy1(&p, out); + break; } return out; } diff --git a/src/engrave.c b/src/engrave.c index 938cff1e5..a26c775a5 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 engrave.c $NHDT-Date: 1430866579 2015/05/05 22:56:19 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.49 $ */ +/* NetHack 3.6 engrave.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.54 $ */ /* NetHack 3.6 engrave.c $Date: 2012/12/20 01:48:36 $ $Revision: 1.39 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,98 +12,133 @@ char * random_engraving(outbuf) char *outbuf; { - const char *rumor; + const char *rumor; - /* a random engraving may come from the "rumors" file, - or from the list above */ - if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor) { - char buf[BUFSZ]; - Strcpy(outbuf, get_rnd_text(ENGRAVEFILE, buf)); - } + /* a random engraving may come from the "rumors" file, + or from the list above */ + if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor) { + char buf[BUFSZ]; + Strcpy(outbuf, get_rnd_text(ENGRAVEFILE, buf)); + } - wipeout_text(outbuf, (int)(strlen(outbuf) / 4), 0); - return outbuf; + wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0); + return outbuf; } /* Partial rubouts for engraving characters. -3. */ static const struct { - char wipefrom; - const char * wipeto; -} rubouts[] = { - {'A', "^"}, {'B', "Pb["}, {'C', "("}, {'D', "|)["}, - {'E', "|FL[_"}, {'F', "|-"}, {'G', "C("}, {'H', "|-"}, - {'I', "|"}, {'K', "|<"}, {'L', "|_"}, {'M', "|"}, - {'N', "|\\"}, {'O', "C("}, {'P', "F"}, {'Q', "C("}, - {'R', "PF"}, {'T', "|"}, {'U', "J"}, {'V', "/\\"}, - {'W', "V/\\"}, {'Z', "/"}, - {'b', "|"}, {'d', "c|"}, {'e', "c"}, {'g', "c"}, - {'h', "n"}, {'j', "i"}, {'k', "|"}, {'l', "|"}, - {'m', "nr"}, {'n', "r"}, {'o', "c"}, {'q', "c"}, - {'w', "v"}, {'y', "v"}, - {':', "."}, {';', ",:"}, {',', "."}, {'=', "-"}, - {'+', "-|"}, {'*', "+"}, {'@', "0"}, - {'0', "C("}, {'1', "|"}, {'6', "o"}, {'7', "/"}, - {'8', "3o"} -}; + char wipefrom; + const char *wipeto; +} rubouts[] = { { 'A', "^" }, + { 'B', "Pb[" }, + { 'C', "(" }, + { 'D', "|)[" }, + { 'E', "|FL[_" }, + { 'F', "|-" }, + { 'G', "C(" }, + { 'H', "|-" }, + { 'I', "|" }, + { 'K', "|<" }, + { 'L', "|_" }, + { 'M', "|" }, + { 'N', "|\\" }, + { 'O', "C(" }, + { 'P', "F" }, + { 'Q', "C(" }, + { 'R', "PF" }, + { 'T', "|" }, + { 'U', "J" }, + { 'V', "/\\" }, + { 'W', "V/\\" }, + { 'Z', "/" }, + { 'b', "|" }, + { 'd', "c|" }, + { 'e', "c" }, + { 'g', "c" }, + { 'h', "n" }, + { 'j', "i" }, + { 'k', "|" }, + { 'l', "|" }, + { 'm', "nr" }, + { 'n', "r" }, + { 'o', "c" }, + { 'q', "c" }, + { 'w', "v" }, + { 'y', "v" }, + { ':', "." }, + { ';', ",:" }, + { ',', "." }, + { '=', "-" }, + { '+', "-|" }, + { '*', "+" }, + { '@', "0" }, + { '0', "C(" }, + { '1', "|" }, + { '6', "o" }, + { '7', "/" }, + { '8', "3o" } }; void wipeout_text(engr, cnt, seed) char *engr; int cnt; -unsigned seed; /* for semi-controlled randomization */ +unsigned seed; /* for semi-controlled randomization */ { - char *s; - int i, j, nxt, use_rubout, lth = (int)strlen(engr); + char *s; + int i, j, nxt, use_rubout, lth = (int) strlen(engr); - if (lth && cnt > 0) { - while (cnt--) { - /* pick next character */ - if (!seed) { - /* random */ - nxt = rn2(lth); - use_rubout = rn2(4); - } else { - /* predictable; caller can reproduce the same sequence by - supplying the same arguments later, or a pseudo-random - sequence by varying any of them */ - nxt = seed % lth; - seed *= 31, seed %= (BUFSZ-1); - use_rubout = seed & 3; - } - s = &engr[nxt]; - if (*s == ' ') continue; + if (lth && cnt > 0) { + while (cnt--) { + /* pick next character */ + if (!seed) { + /* random */ + nxt = rn2(lth); + use_rubout = rn2(4); + } else { + /* predictable; caller can reproduce the same sequence by + supplying the same arguments later, or a pseudo-random + sequence by varying any of them */ + nxt = seed % lth; + seed *= 31, seed %= (BUFSZ - 1); + use_rubout = seed & 3; + } + s = &engr[nxt]; + if (*s == ' ') + continue; - /* rub out unreadable & small punctuation marks */ - if (index("?.,'`-|_", *s)) { - *s = ' '; - continue; - } + /* rub out unreadable & small punctuation marks */ + if (index("?.,'`-|_", *s)) { + *s = ' '; + continue; + } - if (!use_rubout) - i = SIZE(rubouts); - else - for (i = 0; i < SIZE(rubouts); i++) - if (*s == rubouts[i].wipefrom) { - /* - * Pick one of the substitutes at random. - */ - if (!seed) - j = rn2(strlen(rubouts[i].wipeto)); - else { - seed *= 31, seed %= (BUFSZ-1); - j = seed % (strlen(rubouts[i].wipeto)); - } - *s = rubouts[i].wipeto[j]; - break; - } + if (!use_rubout) + i = SIZE(rubouts); + else + for (i = 0; i < SIZE(rubouts); i++) + if (*s == rubouts[i].wipefrom) { + /* + * Pick one of the substitutes at random. + */ + if (!seed) + j = rn2(strlen(rubouts[i].wipeto)); + else { + seed *= 31, seed %= (BUFSZ - 1); + j = seed % (strlen(rubouts[i].wipeto)); + } + *s = rubouts[i].wipeto[j]; + break; + } - /* didn't pick rubout; use '?' for unreadable character */ - if (i == SIZE(rubouts)) *s = '?'; - } - } + /* didn't pick rubout; use '?' for unreadable character */ + if (i == SIZE(rubouts)) + *s = '?'; + } + } - /* trim trailing spaces */ - while (lth && engr[lth-1] == ' ') engr[--lth] = 0; + /* trim trailing spaces */ + while (lth && engr[lth - 1] == ' ') + engr[--lth] = 0; } /* check whether hero can reach something at ground level */ @@ -111,19 +146,21 @@ boolean can_reach_floor(check_pit) boolean check_pit; { - struct trap *t; + struct trap *t; - if (u.uswallow) return FALSE; - /* Restricted/unskilled riders can't reach the floor */ - if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) return FALSE; - if (check_pit && (t = t_at(u.ux, u.uy)) != 0 && - uteetering_at_seen_pit(t) && !Flying) - return FALSE; + if (u.uswallow) + return FALSE; + /* Restricted/unskilled riders can't reach the floor */ + if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) + return FALSE; + if (check_pit && (t = t_at(u.ux, u.uy)) != 0 && uteetering_at_seen_pit(t) + && !Flying) + return FALSE; - return (boolean)((!Levitation || - Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) && - (!u.uundetected || !is_hider(youmonst.data) || - u.umonnum == PM_TRAPPER)); + return (boolean)( + (!Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) + && (!u.uundetected || !is_hider(youmonst.data) + || u.umonnum == PM_TRAPPER)); } /* give a message after caller has determined that hero can't reach */ @@ -132,88 +169,87 @@ cant_reach_floor(x, y, up, check_pit) int x, y; boolean up, check_pit; { - You("can't reach the %s.", - up ? ceiling(x, y) : - (check_pit && can_reach_floor(FALSE)) ? "bottom of the pit" : - surface(x, y)); + You("can't reach the %s.", + up ? ceiling(x, y) : (check_pit && can_reach_floor(FALSE)) + ? "bottom of the pit" + : surface(x, y)); } const char * surface(x, y) register int x, y; { - register struct rm *lev = &levl[x][y]; + register struct rm *lev = &levl[x][y]; - if ((x == u.ux) && (y == u.uy) && u.uswallow && - is_animal(u.ustuck->data)) - return "maw"; - else if (IS_AIR(lev->typ) && Is_airlevel(&u.uz)) - return "air"; - else if (is_pool(x,y)) - return (Underwater && !Is_waterlevel(&u.uz)) ? "bottom" : "water"; - else if (is_ice(x,y)) - return "ice"; - else if (is_lava(x,y)) - return "lava"; - else if (lev->typ == DRAWBRIDGE_DOWN) - return "bridge"; - else if(IS_ALTAR(levl[x][y].typ)) - return "altar"; - else if(IS_GRAVE(levl[x][y].typ)) - return "headstone"; - else if(IS_FOUNTAIN(levl[x][y].typ)) - return "fountain"; - else if ((IS_ROOM(lev->typ) && !Is_earthlevel(&u.uz)) || - IS_WALL(lev->typ) || IS_DOOR(lev->typ) || lev->typ == SDOOR) - return "floor"; - else - return "ground"; + if ((x == u.ux) && (y == u.uy) && u.uswallow && is_animal(u.ustuck->data)) + return "maw"; + else if (IS_AIR(lev->typ) && Is_airlevel(&u.uz)) + return "air"; + else if (is_pool(x, y)) + return (Underwater && !Is_waterlevel(&u.uz)) ? "bottom" : "water"; + else if (is_ice(x, y)) + return "ice"; + else if (is_lava(x, y)) + return "lava"; + else if (lev->typ == DRAWBRIDGE_DOWN) + return "bridge"; + else if (IS_ALTAR(levl[x][y].typ)) + return "altar"; + else if (IS_GRAVE(levl[x][y].typ)) + return "headstone"; + else if (IS_FOUNTAIN(levl[x][y].typ)) + return "fountain"; + else if ((IS_ROOM(lev->typ) && !Is_earthlevel(&u.uz)) || IS_WALL(lev->typ) + || IS_DOOR(lev->typ) || lev->typ == SDOOR) + return "floor"; + else + return "ground"; } const char * ceiling(x, y) register int x, y; { - register struct rm *lev = &levl[x][y]; - const char *what; + register struct rm *lev = &levl[x][y]; + const char *what; - /* other room types will no longer exist when we're interested -- - * see check_special_room() - */ - if (*in_rooms(x,y,VAULT)) - what = "vault's ceiling"; - else if (*in_rooms(x,y,TEMPLE)) - what = "temple's ceiling"; - else if (*in_rooms(x,y,SHOPBASE)) - what = "shop's ceiling"; - else if (Is_waterlevel(&u.uz)) - /* water plane has no surface; its air bubbles aren't below sky */ - what = "water above"; - else if (IS_AIR(lev->typ)) - what = "sky"; - else if (Underwater) - what = "water's surface"; - else if ((IS_ROOM(lev->typ) && !Is_earthlevel(&u.uz)) || - IS_WALL(lev->typ) || IS_DOOR(lev->typ) || lev->typ == SDOOR) - what = "ceiling"; - else - what = "rock above"; + /* other room types will no longer exist when we're interested -- + * see check_special_room() + */ + if (*in_rooms(x, y, VAULT)) + what = "vault's ceiling"; + else if (*in_rooms(x, y, TEMPLE)) + what = "temple's ceiling"; + else if (*in_rooms(x, y, SHOPBASE)) + what = "shop's ceiling"; + else if (Is_waterlevel(&u.uz)) + /* water plane has no surface; its air bubbles aren't below sky */ + what = "water above"; + else if (IS_AIR(lev->typ)) + what = "sky"; + else if (Underwater) + what = "water's surface"; + else if ((IS_ROOM(lev->typ) && !Is_earthlevel(&u.uz)) || IS_WALL(lev->typ) + || IS_DOOR(lev->typ) || lev->typ == SDOOR) + what = "ceiling"; + else + what = "rock above"; - return what; + return what; } struct engr * engr_at(x, y) xchar x, y; { - register struct engr *ep = head_engr; + register struct engr *ep = head_engr; - while(ep) { - if(x == ep->engr_x && y == ep->engr_y) - return(ep); - ep = ep->nxt_engr; - } - return((struct engr *) 0); + while (ep) { + if (x == ep->engr_x && y == ep->engr_y) + return (ep); + ep = ep->nxt_engr; + } + return ((struct engr *) 0); } /* Decide whether a particular string is engraved at a specified @@ -226,147 +262,145 @@ xchar x, y; */ int sengr_at(s, x, y, strict) - const char *s; - xchar x, y; - boolean strict; +const char *s; +xchar x, y; +boolean strict; { - register struct engr *ep = engr_at(x,y); + register struct engr *ep = engr_at(x, y); - if (ep && ep->engr_type != HEADSTONE && ep->engr_time <= moves) { - return strict ? (strncmpi(ep->engr_txt, s, strlen(s)) == 0) : - (strstri(ep->engr_txt, s) != 0); - } - return FALSE; + if (ep && ep->engr_type != HEADSTONE && ep->engr_time <= moves) { + return strict ? (strncmpi(ep->engr_txt, s, strlen(s)) == 0) + : (strstri(ep->engr_txt, s) != 0); + } + return FALSE; } void u_wipe_engr(cnt) register int cnt; { - if (can_reach_floor(TRUE)) - wipe_engr_at(u.ux, u.uy, cnt, FALSE); + if (can_reach_floor(TRUE)) + wipe_engr_at(u.ux, u.uy, cnt, FALSE); } void -wipe_engr_at(x,y,cnt,magical) -register xchar x,y,cnt,magical; +wipe_engr_at(x, y, cnt, magical) +register xchar x, y, cnt, magical; { - register struct engr *ep = engr_at(x,y); + register struct engr *ep = engr_at(x, y); - /* Headstones are indelible */ - if(ep && ep->engr_type != HEADSTONE) { - debugpline1("asked to erode %d characters", cnt); - if(ep->engr_type != BURN || is_ice(x,y) || (magical && !rn2(2))) { - if(ep->engr_type != DUST && ep->engr_type != ENGR_BLOOD) { - cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1; - debugpline1("actually eroding %d characters", cnt); - } - wipeout_text(ep->engr_txt, (int)cnt, 0); - while(ep->engr_txt[0] == ' ') - ep->engr_txt++; - if(!ep->engr_txt[0]) del_engr(ep); - } + /* Headstones are indelible */ + if (ep && ep->engr_type != HEADSTONE) { + debugpline1("asked to erode %d characters", cnt); + if (ep->engr_type != BURN || is_ice(x, y) || (magical && !rn2(2))) { + if (ep->engr_type != DUST && ep->engr_type != ENGR_BLOOD) { + cnt = rn2(1 + 50 / (cnt + 1)) ? 0 : 1; + debugpline1("actually eroding %d characters", cnt); + } + wipeout_text(ep->engr_txt, (int) cnt, 0); + while (ep->engr_txt[0] == ' ') + ep->engr_txt++; + if (!ep->engr_txt[0]) + del_engr(ep); } + } } void -read_engr_at(x,y) -register int x,y; +read_engr_at(x, y) +register int x, y; { - register struct engr *ep = engr_at(x,y); - register int sensed = 0; - char buf[BUFSZ]; - - /* Sensing an engraving does not require sight, - * nor does it necessarily imply comprehension (literacy). - */ - if(ep && ep->engr_txt[0]) { - switch(ep->engr_type) { - case DUST: - if(!Blind) { - sensed = 1; - pline("%s is written here in the %s.", Something, - is_ice(x,y) ? "frost" : "dust"); - } - break; - case ENGRAVE: - case HEADSTONE: - if (!Blind || can_reach_floor(TRUE)) { - sensed = 1; - pline("%s is engraved here on the %s.", - Something, - surface(x,y)); - } - break; - case BURN: - if (!Blind || can_reach_floor(TRUE)) { - sensed = 1; - pline("Some text has been %s into the %s here.", - is_ice(x,y) ? "melted" : "burned", - surface(x,y)); - } - break; - case MARK: - if(!Blind) { - sensed = 1; - pline("There's some graffiti on the %s here.", - surface(x,y)); - } - break; - case ENGR_BLOOD: - /* "It's a message! Scrawled in blood!" - * "What's it say?" - * "It says... `See you next Wednesday.'" -- Thriller - */ - if(!Blind) { - sensed = 1; - You_see("a message scrawled in blood here."); - } - break; - default: - impossible("%s is written in a very strange way.", - Something); - sensed = 1; - } - if (sensed) { - char *et; - unsigned maxelen = BUFSZ - sizeof("You feel the words: \"\". "); - if (strlen(ep->engr_txt) > maxelen) { - (void) strncpy(buf, ep->engr_txt, (int)maxelen); - buf[maxelen] = '\0'; - et = buf; - } else - et = ep->engr_txt; - You("%s: \"%s\".", - (Blind) ? "feel the words" : "read", et); - if(context.run > 1) nomul(0); - } - } + register struct engr *ep = engr_at(x, y); + register int sensed = 0; + char buf[BUFSZ]; + + /* Sensing an engraving does not require sight, + * nor does it necessarily imply comprehension (literacy). + */ + if (ep && ep->engr_txt[0]) { + switch (ep->engr_type) { + case DUST: + if (!Blind) { + sensed = 1; + pline("%s is written here in the %s.", Something, + is_ice(x, y) ? "frost" : "dust"); + } + break; + case ENGRAVE: + case HEADSTONE: + if (!Blind || can_reach_floor(TRUE)) { + sensed = 1; + pline("%s is engraved here on the %s.", Something, + surface(x, y)); + } + break; + case BURN: + if (!Blind || can_reach_floor(TRUE)) { + sensed = 1; + pline("Some text has been %s into the %s here.", + is_ice(x, y) ? "melted" : "burned", surface(x, y)); + } + break; + case MARK: + if (!Blind) { + sensed = 1; + pline("There's some graffiti on the %s here.", surface(x, y)); + } + break; + case ENGR_BLOOD: + /* "It's a message! Scrawled in blood!" + * "What's it say?" + * "It says... `See you next Wednesday.'" -- Thriller + */ + if (!Blind) { + sensed = 1; + You_see("a message scrawled in blood here."); + } + break; + default: + impossible("%s is written in a very strange way.", Something); + sensed = 1; + } + if (sensed) { + char *et; + unsigned maxelen = BUFSZ - sizeof("You feel the words: \"\". "); + if (strlen(ep->engr_txt) > maxelen) { + (void) strncpy(buf, ep->engr_txt, (int) maxelen); + buf[maxelen] = '\0'; + et = buf; + } else + et = ep->engr_txt; + You("%s: \"%s\".", (Blind) ? "feel the words" : "read", et); + if (context.run > 1) + nomul(0); + } + } } void -make_engr_at(x,y,s,e_time,e_type) -register int x,y; +make_engr_at(x, y, s, e_time, e_type) +register int x, y; register const char *s; register long e_time; register xchar e_type; { - register struct engr *ep; + register struct engr *ep; - if ((ep = engr_at(x,y)) != 0) - del_engr(ep); - ep = newengr(strlen(s) + 1); - ep->nxt_engr = head_engr; - head_engr = ep; - ep->engr_x = x; - ep->engr_y = y; - ep->engr_txt = (char *)(ep + 1); - Strcpy(ep->engr_txt, s); - /* engraving Elbereth shows wisdom */ - if (!in_mklev && !strcmp(s, "Elbereth")) exercise(A_WIS, TRUE); - ep->engr_time = e_time; - ep->engr_type = e_type > 0 ? e_type : rnd(N_ENGRAVE-1); - ep->engr_lth = strlen(s) + 1; + if ((ep = engr_at(x, y)) != 0) + del_engr(ep); + ep = newengr(strlen(s) + 1); + ep->nxt_engr = head_engr; + head_engr = ep; + ep->engr_x = x; + ep->engr_y = y; + ep->engr_txt = (char *) (ep + 1); + Strcpy(ep->engr_txt, s); + /* engraving Elbereth shows wisdom */ + if (!in_mklev && !strcmp(s, "Elbereth")) + exercise(A_WIS, TRUE); + ep->engr_time = e_time; + ep->engr_type = e_type > 0 ? e_type : rnd(N_ENGRAVE - 1); + ep->engr_lth = strlen(s) + 1; } /* delete any engraving at location */ @@ -374,9 +408,10 @@ void del_engr_at(x, y) int x, y; { - register struct engr *ep = engr_at(x, y); + register struct engr *ep = engr_at(x, y); - if (ep) del_engr(ep); + if (ep) + del_engr(ep); } /* @@ -385,18 +420,19 @@ int x, y; int freehand() { - return(!uwep || !welded(uwep) || - (!bimanual(uwep) && (!uarms || !uarms->cursed))); -/* if ((uwep && bimanual(uwep)) || - (uwep && uarms)) - return(0); - else - return(1);*/ + return (!uwep || !welded(uwep) + || (!bimanual(uwep) && (!uarms || !uarms->cursed))); + /* if ((uwep && bimanual(uwep)) || + (uwep && uarms)) + return(0); + else + return(1);*/ } -static NEARDATA const char styluses[] = - { ALL_CLASSES, ALLOW_NONE, TOOL_CLASS, WEAPON_CLASS, WAND_CLASS, - GEM_CLASS, RING_CLASS, 0 }; +static NEARDATA const char styluses[] = { ALL_CLASSES, ALLOW_NONE, + TOOL_CLASS, WEAPON_CLASS, + WAND_CLASS, GEM_CLASS, + RING_CLASS, 0 }; /* Mohs' Hardness Scale: * 1 - Talc 6 - Orthoclase @@ -429,696 +465,704 @@ static NEARDATA const char styluses[] = int doengrave() { - boolean dengr = FALSE; /* TRUE if we wipe out the current engraving */ - boolean doblind = FALSE;/* TRUE if engraving blinds the player */ - boolean doknown = FALSE;/* TRUE if we identify the stylus */ - boolean eow = FALSE; /* TRUE if we are overwriting oep */ - boolean jello = FALSE; /* TRUE if we are engraving in slime */ - boolean ptext = TRUE; /* TRUE if we must prompt for engrave text */ - boolean teleengr =FALSE;/* TRUE if we move the old engraving */ - boolean zapwand = FALSE;/* TRUE if we remove a wand charge */ - xchar type = DUST; /* Type of engraving made */ - char buf[BUFSZ]; /* Buffer for final/poly engraving text */ - char ebuf[BUFSZ]; /* Buffer for initial engraving text */ - char fbuf[BUFSZ]; /* Buffer for "your fingers" */ - char qbuf[QBUFSZ]; /* Buffer for query text */ - char post_engr_text[BUFSZ]; /* Text displayed after engraving prompt */ - const char *everb; /* Present tense of engraving type */ - const char *eloc; /* Where the engraving is (ie dust/floor/...) */ - char *sp; /* Place holder for space count of engr text */ - int len; /* # of nonspace chars of new engraving text */ - int maxelen; /* Max allowable length of engraving text */ - struct engr *oep = engr_at(u.ux,u.uy); - /* The current engraving */ - struct obj *otmp; /* Object selected with which to engrave */ - char *writer; + boolean dengr = FALSE; /* TRUE if we wipe out the current engraving */ + boolean doblind = FALSE; /* TRUE if engraving blinds the player */ + boolean doknown = FALSE; /* TRUE if we identify the stylus */ + boolean eow = FALSE; /* TRUE if we are overwriting oep */ + boolean jello = FALSE; /* TRUE if we are engraving in slime */ + boolean ptext = TRUE; /* TRUE if we must prompt for engrave text */ + boolean teleengr = FALSE; /* TRUE if we move the old engraving */ + boolean zapwand = FALSE; /* TRUE if we remove a wand charge */ + xchar type = DUST; /* Type of engraving made */ + char buf[BUFSZ]; /* Buffer for final/poly engraving text */ + char ebuf[BUFSZ]; /* Buffer for initial engraving text */ + char fbuf[BUFSZ]; /* Buffer for "your fingers" */ + char qbuf[QBUFSZ]; /* Buffer for query text */ + char post_engr_text[BUFSZ]; /* Text displayed after engraving prompt */ + const char *everb; /* Present tense of engraving type */ + const char *eloc; /* Where the engraving is (ie dust/floor/...) */ + char *sp; /* Place holder for space count of engr text */ + int len; /* # of nonspace chars of new engraving text */ + int maxelen; /* Max allowable length of engraving text */ + struct engr *oep = engr_at(u.ux, u.uy); + /* The current engraving */ + struct obj *otmp; /* Object selected with which to engrave */ + char *writer; - multi = 0; /* moves consumed */ - nomovemsg = (char *)0; /* occupation end message */ + multi = 0; /* moves consumed */ + nomovemsg = (char *) 0; /* occupation end message */ - buf[0] = (char)0; - ebuf[0] = (char)0; - post_engr_text[0] = (char)0; - maxelen = BUFSZ - 1; - if (is_demon(youmonst.data) || youmonst.data->mlet == S_VAMPIRE) - type = ENGR_BLOOD; + buf[0] = (char) 0; + ebuf[0] = (char) 0; + post_engr_text[0] = (char) 0; + maxelen = BUFSZ - 1; + if (is_demon(youmonst.data) || youmonst.data->mlet == S_VAMPIRE) + type = ENGR_BLOOD; - /* Can the adventurer engrave at all? */ + /* Can the adventurer engrave at all? */ - if(u.uswallow) { - if (is_animal(u.ustuck->data)) { - pline("What would you write? \"Jonah was here\"?"); - return(0); - } else if (is_whirly(u.ustuck->data)) { - cant_reach_floor(u.ux, u.uy, FALSE, FALSE); - return(0); - } else - jello = TRUE; - } else if (is_lava(u.ux, u.uy)) { - You_cant("write on the %s!", surface(u.ux, u.uy)); - return(0); - } else if (is_pool(u.ux,u.uy) || IS_FOUNTAIN(levl[u.ux][u.uy].typ)) { - You_cant("write on the %s!", surface(u.ux, u.uy)); - return(0); - } - if(Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)/* in bubble */) { - You_cant("write in thin air!"); - return(0); - } else if (!accessible(u.ux, u.uy)) { - /* stone, tree, wall, secret corridor, pool, lava, bars */ - You_cant("write here."); - return 0; - } - if (cantwield(youmonst.data)) { - You_cant("even hold anything!"); - return(0); - } - if (check_capacity((char *)0)) return (0); + if (u.uswallow) { + if (is_animal(u.ustuck->data)) { + pline("What would you write? \"Jonah was here\"?"); + return (0); + } else if (is_whirly(u.ustuck->data)) { + cant_reach_floor(u.ux, u.uy, FALSE, FALSE); + return (0); + } else + jello = TRUE; + } else if (is_lava(u.ux, u.uy)) { + You_cant("write on the %s!", surface(u.ux, u.uy)); + return (0); + } else if (is_pool(u.ux, u.uy) || IS_FOUNTAIN(levl[u.ux][u.uy].typ)) { + You_cant("write on the %s!", surface(u.ux, u.uy)); + return (0); + } + if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) /* in bubble */) { + You_cant("write in thin air!"); + return (0); + } else if (!accessible(u.ux, u.uy)) { + /* stone, tree, wall, secret corridor, pool, lava, bars */ + You_cant("write here."); + return 0; + } + if (cantwield(youmonst.data)) { + You_cant("even hold anything!"); + return (0); + } + if (check_capacity((char *) 0)) + return (0); - /* One may write with finger, or weapon, or wand, or..., or... - * Edited by GAN 10/20/86 so as not to change weapon wielded. - */ + /* One may write with finger, or weapon, or wand, or..., or... + * Edited by GAN 10/20/86 so as not to change weapon wielded. + */ - otmp = getobj(styluses, "write with"); - if(!otmp) return(0); /* otmp == zeroobj if fingers */ + otmp = getobj(styluses, "write with"); + if (!otmp) + return (0); /* otmp == zeroobj if fingers */ - if (otmp == &zeroobj) { - Strcat(strcpy(fbuf, "your "), makeplural(body_part(FINGER))); - writer = fbuf; - } else writer = yname(otmp); + if (otmp == &zeroobj) { + Strcat(strcpy(fbuf, "your "), makeplural(body_part(FINGER))); + writer = fbuf; + } else + writer = yname(otmp); - /* There's no reason you should be able to write with a wand - * while both your hands are tied up. - */ - if (!freehand() && otmp != uwep && !otmp->owornmask) { - You("have no free %s to write with!", body_part(HAND)); - return(0); - } + /* There's no reason you should be able to write with a wand + * while both your hands are tied up. + */ + if (!freehand() && otmp != uwep && !otmp->owornmask) { + You("have no free %s to write with!", body_part(HAND)); + return (0); + } - if (jello) { - You("tickle %s with %s.", mon_nam(u.ustuck), writer); - Your("message dissolves..."); - return(0); - } - if (otmp->oclass != WAND_CLASS && !can_reach_floor(TRUE)) { - cant_reach_floor(u.ux, u.uy, FALSE, TRUE); - return(0); - } - if (IS_ALTAR(levl[u.ux][u.uy].typ)) { - You("make a motion towards the altar with %s.", writer); - altar_wrath(u.ux, u.uy); - return(0); - } - if (IS_GRAVE(levl[u.ux][u.uy].typ)) { - if (otmp == &zeroobj) { /* using only finger */ - You("would only make a small smudge on the %s.", - surface(u.ux, u.uy)); - return(0); - } else if (!levl[u.ux][u.uy].disturbed) { - You("disturb the undead!"); - levl[u.ux][u.uy].disturbed = 1; - (void) makemon(&mons[PM_GHOUL], u.ux, u.uy, NO_MM_FLAGS); - exercise(A_WIS, FALSE); - return(1); - } - } + if (jello) { + You("tickle %s with %s.", mon_nam(u.ustuck), writer); + Your("message dissolves..."); + return (0); + } + if (otmp->oclass != WAND_CLASS && !can_reach_floor(TRUE)) { + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); + return (0); + } + if (IS_ALTAR(levl[u.ux][u.uy].typ)) { + You("make a motion towards the altar with %s.", writer); + altar_wrath(u.ux, u.uy); + return (0); + } + if (IS_GRAVE(levl[u.ux][u.uy].typ)) { + if (otmp == &zeroobj) { /* using only finger */ + You("would only make a small smudge on the %s.", + surface(u.ux, u.uy)); + return (0); + } else if (!levl[u.ux][u.uy].disturbed) { + You("disturb the undead!"); + levl[u.ux][u.uy].disturbed = 1; + (void) makemon(&mons[PM_GHOUL], u.ux, u.uy, NO_MM_FLAGS); + exercise(A_WIS, FALSE); + return (1); + } + } - /* SPFX for items */ + /* SPFX for items */ - switch (otmp->oclass) { - default: - case AMULET_CLASS: - case CHAIN_CLASS: - case POTION_CLASS: - case COIN_CLASS: - break; + switch (otmp->oclass) { + default: + case AMULET_CLASS: + case CHAIN_CLASS: + case POTION_CLASS: + case COIN_CLASS: + break; - case RING_CLASS: - /* "diamond" rings and others should work */ - case GEM_CLASS: - /* diamonds & other hard gems should work */ - if (objects[otmp->otyp].oc_tough) { - type = ENGRAVE; - break; - } - break; + case RING_CLASS: + /* "diamond" rings and others should work */ + case GEM_CLASS: + /* diamonds & other hard gems should work */ + if (objects[otmp->otyp].oc_tough) { + type = ENGRAVE; + break; + } + break; - case ARMOR_CLASS: - if (is_boots(otmp)) { - type = DUST; - break; - } - /* fall through */ - /* Objects too large to engrave with */ - case BALL_CLASS: - case ROCK_CLASS: - You_cant("engrave with such a large object!"); - ptext = FALSE; - break; + case ARMOR_CLASS: + if (is_boots(otmp)) { + type = DUST; + break; + } + /* fall through */ + /* Objects too large to engrave with */ + case BALL_CLASS: + case ROCK_CLASS: + You_cant("engrave with such a large object!"); + ptext = FALSE; + break; - /* Objects too silly to engrave with */ - case FOOD_CLASS: - case SCROLL_CLASS: - case SPBOOK_CLASS: - pline("%s would get %s.", Yname2(otmp), - is_ice(u.ux,u.uy) ? "all frosty" : "too dirty"); - ptext = FALSE; - break; + /* Objects too silly to engrave with */ + case FOOD_CLASS: + case SCROLL_CLASS: + case SPBOOK_CLASS: + pline("%s would get %s.", Yname2(otmp), + is_ice(u.ux, u.uy) ? "all frosty" : "too dirty"); + ptext = FALSE; + break; - case RANDOM_CLASS: /* This should mean fingers */ - break; + case RANDOM_CLASS: /* This should mean fingers */ + break; - /* The charge is removed from the wand before prompting for - * the engraving text, because all kinds of setup decisions - * and pre-engraving messages are based upon knowing what type - * of engraving the wand is going to do. Also, the player - * will have potentially seen "You wrest .." message, and - * therefore will know they are using a charge. - */ - case WAND_CLASS: - if (zappable(otmp)) { - check_unpaid(otmp); - if (otmp->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { - wand_explode(otmp, 0); - return 1; - } - zapwand = TRUE; - if (!can_reach_floor(TRUE)) ptext = FALSE; + /* The charge is removed from the wand before prompting for + * the engraving text, because all kinds of setup decisions + * and pre-engraving messages are based upon knowing what type + * of engraving the wand is going to do. Also, the player + * will have potentially seen "You wrest .." message, and + * therefore will know they are using a charge. + */ + case WAND_CLASS: + if (zappable(otmp)) { + check_unpaid(otmp); + if (otmp->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { + wand_explode(otmp, 0); + return 1; + } + zapwand = TRUE; + if (!can_reach_floor(TRUE)) + ptext = FALSE; - switch (otmp->otyp) { - /* DUST wands */ - default: - break; + switch (otmp->otyp) { + /* DUST wands */ + default: + break; - /* NODIR wands */ - case WAN_LIGHT: - case WAN_SECRET_DOOR_DETECTION: - case WAN_CREATE_MONSTER: - case WAN_WISHING: - case WAN_ENLIGHTENMENT: - zapnodir(otmp); - break; + /* NODIR wands */ + case WAN_LIGHT: + case WAN_SECRET_DOOR_DETECTION: + case WAN_CREATE_MONSTER: + case WAN_WISHING: + case WAN_ENLIGHTENMENT: + zapnodir(otmp); + break; - /* IMMEDIATE wands */ - /* If wand is "IMMEDIATE", remember to affect the - * previous engraving even if turning to dust. - */ - case WAN_STRIKING: - Strcpy(post_engr_text, - "The wand unsuccessfully fights your attempt to write!" - ); - break; - case WAN_SLOW_MONSTER: - if (!Blind) { - Sprintf(post_engr_text, - "The bugs on the %s slow down!", - surface(u.ux, u.uy)); - } - break; - case WAN_SPEED_MONSTER: - if (!Blind) { - Sprintf(post_engr_text, - "The bugs on the %s speed up!", - surface(u.ux, u.uy)); - } - break; - case WAN_POLYMORPH: - if(oep) { - if (!Blind) { - type = (xchar)0; /* random */ - (void) random_engraving(buf); - } - dengr = TRUE; - } - break; - case WAN_NOTHING: - case WAN_UNDEAD_TURNING: - case WAN_OPENING: - case WAN_LOCKING: - case WAN_PROBING: - break; + /* IMMEDIATE wands */ + /* If wand is "IMMEDIATE", remember to affect the + * previous engraving even if turning to dust. + */ + case WAN_STRIKING: + Strcpy( + post_engr_text, + "The wand unsuccessfully fights your attempt to write!"); + break; + case WAN_SLOW_MONSTER: + if (!Blind) { + Sprintf(post_engr_text, "The bugs on the %s slow down!", + surface(u.ux, u.uy)); + } + break; + case WAN_SPEED_MONSTER: + if (!Blind) { + Sprintf(post_engr_text, "The bugs on the %s speed up!", + surface(u.ux, u.uy)); + } + break; + case WAN_POLYMORPH: + if (oep) { + if (!Blind) { + type = (xchar) 0; /* random */ + (void) random_engraving(buf); + } + dengr = TRUE; + } + break; + case WAN_NOTHING: + case WAN_UNDEAD_TURNING: + case WAN_OPENING: + case WAN_LOCKING: + case WAN_PROBING: + break; - /* RAY wands */ - case WAN_MAGIC_MISSILE: - ptext = TRUE; - if (!Blind) { - Sprintf(post_engr_text, - "The %s is riddled by bullet holes!", - surface(u.ux, u.uy)); - } - break; + /* RAY wands */ + case WAN_MAGIC_MISSILE: + ptext = TRUE; + if (!Blind) { + Sprintf(post_engr_text, + "The %s is riddled by bullet holes!", + surface(u.ux, u.uy)); + } + break; - /* can't tell sleep from death - Eric Backus */ - case WAN_SLEEP: - case WAN_DEATH: - if (!Blind) { - Sprintf(post_engr_text, - "The bugs on the %s stop moving!", - surface(u.ux, u.uy)); - } - break; + /* can't tell sleep from death - Eric Backus */ + case WAN_SLEEP: + case WAN_DEATH: + if (!Blind) { + Sprintf(post_engr_text, "The bugs on the %s stop moving!", + surface(u.ux, u.uy)); + } + break; - case WAN_COLD: - if (!Blind) - Strcpy(post_engr_text, - "A few ice cubes drop from the wand."); - if(!oep || (oep->engr_type != BURN)) - break; - case WAN_CANCELLATION: - case WAN_MAKE_INVISIBLE: - if (oep && oep->engr_type != HEADSTONE) { - if (!Blind) - pline_The("engraving on the %s vanishes!", - surface(u.ux,u.uy)); - dengr = TRUE; - } - break; - case WAN_TELEPORTATION: - if (oep && oep->engr_type != HEADSTONE) { - if (!Blind) - pline_The("engraving on the %s vanishes!", - surface(u.ux,u.uy)); - teleengr = TRUE; - } - break; + case WAN_COLD: + if (!Blind) + Strcpy(post_engr_text, + "A few ice cubes drop from the wand."); + if (!oep || (oep->engr_type != BURN)) + break; + case WAN_CANCELLATION: + case WAN_MAKE_INVISIBLE: + if (oep && oep->engr_type != HEADSTONE) { + if (!Blind) + pline_The("engraving on the %s vanishes!", + surface(u.ux, u.uy)); + dengr = TRUE; + } + break; + case WAN_TELEPORTATION: + if (oep && oep->engr_type != HEADSTONE) { + if (!Blind) + pline_The("engraving on the %s vanishes!", + surface(u.ux, u.uy)); + teleengr = TRUE; + } + break; - /* type = ENGRAVE wands */ - case WAN_DIGGING: - ptext = TRUE; - type = ENGRAVE; - if(!objects[otmp->otyp].oc_name_known) { - if (flags.verbose) - pline("This %s is a wand of digging!", - xname(otmp)); - doknown = TRUE; - } - if (!Blind) - Strcpy(post_engr_text, - IS_GRAVE(levl[u.ux][u.uy].typ) ? - "Chips fly out from the headstone." : - is_ice(u.ux,u.uy) ? - "Ice chips fly up from the ice surface!" : - (level.locations[u.ux][u.uy].typ == DRAWBRIDGE_DOWN) ? - "Splinters fly up from the bridge." : - "Gravel flies up from the floor."); - else - Strcpy(post_engr_text, "You hear drilling!"); - break; + /* type = ENGRAVE wands */ + case WAN_DIGGING: + ptext = TRUE; + type = ENGRAVE; + if (!objects[otmp->otyp].oc_name_known) { + if (flags.verbose) + pline("This %s is a wand of digging!", xname(otmp)); + doknown = TRUE; + } + if (!Blind) + Strcpy( + post_engr_text, + IS_GRAVE(levl[u.ux][u.uy].typ) + ? "Chips fly out from the headstone." + : is_ice(u.ux, u.uy) + ? "Ice chips fly up from the ice surface!" + : (level.locations[u.ux][u.uy].typ + == DRAWBRIDGE_DOWN) + ? "Splinters fly up from the bridge." + : "Gravel flies up from the floor."); + else + Strcpy(post_engr_text, "You hear drilling!"); + break; - /* type = BURN wands */ - case WAN_FIRE: - ptext = TRUE; - type = BURN; - if(!objects[otmp->otyp].oc_name_known) { - if (flags.verbose) - pline("This %s is a wand of fire!", xname(otmp)); - doknown = TRUE; - } - Strcpy(post_engr_text, - Blind ? "You feel the wand heat up." : - "Flames fly from the wand."); - break; - case WAN_LIGHTNING: - ptext = TRUE; - type = BURN; - if(!objects[otmp->otyp].oc_name_known) { - if (flags.verbose) - pline("This %s is a wand of lightning!", - xname(otmp)); - doknown = TRUE; - } - if (!Blind) { - Strcpy(post_engr_text, - "Lightning arcs from the wand."); - doblind = TRUE; - } else - Strcpy(post_engr_text, "You hear crackling!"); - break; + /* type = BURN wands */ + case WAN_FIRE: + ptext = TRUE; + type = BURN; + if (!objects[otmp->otyp].oc_name_known) { + if (flags.verbose) + pline("This %s is a wand of fire!", xname(otmp)); + doknown = TRUE; + } + Strcpy(post_engr_text, Blind ? "You feel the wand heat up." + : "Flames fly from the wand."); + break; + case WAN_LIGHTNING: + ptext = TRUE; + type = BURN; + if (!objects[otmp->otyp].oc_name_known) { + if (flags.verbose) + pline("This %s is a wand of lightning!", xname(otmp)); + doknown = TRUE; + } + if (!Blind) { + Strcpy(post_engr_text, "Lightning arcs from the wand."); + doblind = TRUE; + } else + Strcpy(post_engr_text, "You hear crackling!"); + break; - /* type = MARK wands */ - /* type = ENGR_BLOOD wands */ - } - } else { /* end if zappable */ - /* failing to wrest one last charge takes time */ - ptext = FALSE; /* use "early exit" below, return 1 */ - /* give feedback here if we won't be getting the - "can't reach floor" message below */ - if (can_reach_floor(TRUE)) { - /* cancelled wand turns to dust */ - if (otmp->spe < 0) zapwand = TRUE; - /* empty wand just doesn't write */ - else pline_The("wand is too worn out to engrave."); - } - } - break; + /* type = MARK wands */ + /* type = ENGR_BLOOD wands */ + } + } else { /* end if zappable */ + /* failing to wrest one last charge takes time */ + ptext = FALSE; /* use "early exit" below, return 1 */ + /* give feedback here if we won't be getting the + "can't reach floor" message below */ + if (can_reach_floor(TRUE)) { + /* cancelled wand turns to dust */ + if (otmp->spe < 0) + zapwand = TRUE; + /* empty wand just doesn't write */ + else + pline_The("wand is too worn out to engrave."); + } + } + break; - case WEAPON_CLASS: - if (is_blade(otmp)) { - if ((int)otmp->spe > -3) - type = ENGRAVE; - else - pline("%s too dull for engraving.", - Yobjnam2(otmp, "are")); - } - break; + case WEAPON_CLASS: + if (is_blade(otmp)) { + if ((int) otmp->spe > -3) + type = ENGRAVE; + else + pline("%s too dull for engraving.", Yobjnam2(otmp, "are")); + } + break; - case TOOL_CLASS: - if(otmp == ublindf) { - pline( - "That is a bit difficult to engrave with, don't you think?"); - return(0); - } - switch (otmp->otyp) { - case MAGIC_MARKER: - if (otmp->spe <= 0) - Your("marker has dried out."); - else - type = MARK; - break; - case TOWEL: - /* Can't really engrave with a towel */ - ptext = FALSE; - if (oep) - if ((oep->engr_type == DUST ) || - (oep->engr_type == ENGR_BLOOD) || - (oep->engr_type == MARK )) { - if (!Blind) - You("wipe out the message here."); - else - pline("%s %s.", Yobjnam2(otmp, "get"), - is_ice(u.ux,u.uy) ? - "frosty" : "dusty"); - dengr = TRUE; - } else - pline("%s can't wipe out this engraving.", - Yname2(otmp)); - else - pline("%s %s.", Yobjnam2(otmp, "get"), - is_ice(u.ux,u.uy) ? "frosty" : "dusty"); - break; - default: - break; - } - break; + case TOOL_CLASS: + if (otmp == ublindf) { + pline( + "That is a bit difficult to engrave with, don't you think?"); + return (0); + } + switch (otmp->otyp) { + case MAGIC_MARKER: + if (otmp->spe <= 0) + Your("marker has dried out."); + else + type = MARK; + break; + case TOWEL: + /* Can't really engrave with a towel */ + ptext = FALSE; + if (oep) + if ((oep->engr_type == DUST) || (oep->engr_type == ENGR_BLOOD) + || (oep->engr_type == MARK)) { + if (!Blind) + You("wipe out the message here."); + else + pline("%s %s.", Yobjnam2(otmp, "get"), + is_ice(u.ux, u.uy) ? "frosty" : "dusty"); + dengr = TRUE; + } else + pline("%s can't wipe out this engraving.", Yname2(otmp)); + else + pline("%s %s.", Yobjnam2(otmp, "get"), + is_ice(u.ux, u.uy) ? "frosty" : "dusty"); + break; + default: + break; + } + break; - case VENOM_CLASS: - if (wizard) { - pline("Writing a poison pen letter??"); - break; - } - case ILLOBJ_CLASS: - impossible("You're engraving with an illegal object!"); - break; - } + case VENOM_CLASS: + if (wizard) { + pline("Writing a poison pen letter??"); + break; + } + case ILLOBJ_CLASS: + impossible("You're engraving with an illegal object!"); + break; + } - if (IS_GRAVE(levl[u.ux][u.uy].typ)) { - if (type == ENGRAVE || type == 0) - type = HEADSTONE; - else { - /* ensures the "cannot wipe out" case */ - type = DUST; - dengr = FALSE; - teleengr = FALSE; - buf[0] = (char)0; - } - } + if (IS_GRAVE(levl[u.ux][u.uy].typ)) { + if (type == ENGRAVE || type == 0) + type = HEADSTONE; + else { + /* ensures the "cannot wipe out" case */ + type = DUST; + dengr = FALSE; + teleengr = FALSE; + buf[0] = (char) 0; + } + } - /* End of implement setup */ + /* End of implement setup */ - /* Identify stylus */ - if (doknown) { - learnwand(otmp); - if (objects[otmp->otyp].oc_name_known) more_experienced(0, 10); - } + /* Identify stylus */ + if (doknown) { + learnwand(otmp); + if (objects[otmp->otyp].oc_name_known) + more_experienced(0, 10); + } - if (teleengr) { - rloc_engr(oep); - oep = (struct engr *)0; - } + if (teleengr) { + rloc_engr(oep); + oep = (struct engr *) 0; + } - if (dengr) { - del_engr(oep); - oep = (struct engr *)0; - } + if (dengr) { + del_engr(oep); + oep = (struct engr *) 0; + } - /* Something has changed the engraving here */ - if (*buf) { - make_engr_at(u.ux, u.uy, buf, moves, type); - pline_The("engraving now reads: \"%s\".", buf); - ptext = FALSE; - } + /* Something has changed the engraving here */ + if (*buf) { + make_engr_at(u.ux, u.uy, buf, moves, type); + pline_The("engraving now reads: \"%s\".", buf); + ptext = FALSE; + } - if (zapwand && (otmp->spe < 0)) { - pline("%s %sturns to dust.", - The(xname(otmp)), Blind ? "" : "glows violently, then "); - if (!IS_GRAVE(levl[u.ux][u.uy].typ)) - You( - "are not going to get anywhere trying to write in the %s with your dust.", - is_ice(u.ux,u.uy) ? "frost" : "dust"); - useup(otmp); - otmp = 0; /* wand is now gone */ - ptext = FALSE; - } + if (zapwand && (otmp->spe < 0)) { + pline("%s %sturns to dust.", The(xname(otmp)), + Blind ? "" : "glows violently, then "); + if (!IS_GRAVE(levl[u.ux][u.uy].typ)) + You("are not going to get anywhere trying to write in the %s " + "with your dust.", + is_ice(u.ux, u.uy) ? "frost" : "dust"); + useup(otmp); + otmp = 0; /* wand is now gone */ + ptext = FALSE; + } - if (!ptext) { /* Early exit for some implements. */ - if (otmp && otmp->oclass == WAND_CLASS && !can_reach_floor(TRUE)) - cant_reach_floor(u.ux, u.uy, FALSE, TRUE); - return(1); - } + if (!ptext) { /* Early exit for some implements. */ + if (otmp && otmp->oclass == WAND_CLASS && !can_reach_floor(TRUE)) + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); + return (1); + } - /* Special effects should have deleted the current engraving (if - * possible) by now. - */ + /* Special effects should have deleted the current engraving (if + * possible) by now. + */ - if (oep) { - register char c = 'n'; + if (oep) { + register char c = 'n'; - /* Give player the choice to add to engraving. */ + /* Give player the choice to add to engraving. */ - if (type == HEADSTONE) { - /* no choice, only append */ - c = 'y'; - } else if ( (type == oep->engr_type) && (!Blind || - (oep->engr_type == BURN) || (oep->engr_type == ENGRAVE)) ) { - c = yn_function("Do you want to add to the current engraving?", - ynqchars, 'y'); - if (c == 'q') { - pline1(Never_mind); - return(0); - } - } + if (type == HEADSTONE) { + /* no choice, only append */ + c = 'y'; + } else if ((type == oep->engr_type) + && (!Blind || (oep->engr_type == BURN) + || (oep->engr_type == ENGRAVE))) { + c = yn_function("Do you want to add to the current engraving?", + ynqchars, 'y'); + if (c == 'q') { + pline1(Never_mind); + return (0); + } + } - if (c == 'n' || Blind) { + if (c == 'n' || Blind) { + if ((oep->engr_type == DUST) || (oep->engr_type == ENGR_BLOOD) + || (oep->engr_type == MARK)) { + if (!Blind) { + You("wipe out the message that was %s here.", + ((oep->engr_type == DUST) + ? "written in the dust" + : ((oep->engr_type == ENGR_BLOOD) + ? "scrawled in blood" + : "written"))); + del_engr(oep); + oep = (struct engr *) 0; + } else + /* Don't delete engr until after we *know* we're engraving + */ + eow = TRUE; + } else if ((type == DUST) || (type == MARK) + || (type == ENGR_BLOOD)) { + You("cannot wipe out the message that is %s the %s here.", + oep->engr_type == BURN + ? (is_ice(u.ux, u.uy) ? "melted into" : "burned into") + : "engraved in", + surface(u.ux, u.uy)); + return (1); + } else if ((type != oep->engr_type) || (c == 'n')) { + if (!Blind || can_reach_floor(TRUE)) + You("will overwrite the current message."); + eow = TRUE; + } + } + } - if( (oep->engr_type == DUST) || (oep->engr_type == ENGR_BLOOD) || - (oep->engr_type == MARK) ) { - if (!Blind) { - You("wipe out the message that was %s here.", - ((oep->engr_type == DUST) ? "written in the dust" : - ((oep->engr_type == ENGR_BLOOD) ? "scrawled in blood" : - "written"))); - del_engr(oep); - oep = (struct engr *)0; - } else - /* Don't delete engr until after we *know* we're engraving */ - eow = TRUE; - } else - if ( (type == DUST) || (type == MARK) || (type == ENGR_BLOOD) ) { - You( - "cannot wipe out the message that is %s the %s here.", - oep->engr_type == BURN ? - (is_ice(u.ux,u.uy) ? "melted into" : "burned into") : - "engraved in", surface(u.ux,u.uy)); - return(1); - } else - if ( (type != oep->engr_type) || (c == 'n') ) { - if (!Blind || can_reach_floor(TRUE)) - You("will overwrite the current message."); - eow = TRUE; - } - } - } + eloc = surface(u.ux, u.uy); + switch (type) { + default: + everb = (oep && !eow ? "add to the weird writing on" + : "write strangely on"); + break; + case DUST: + everb = (oep && !eow ? "add to the writing in" : "write in"); + eloc = is_ice(u.ux, u.uy) ? "frost" : "dust"; + break; + case HEADSTONE: + everb = (oep && !eow ? "add to the epitaph on" : "engrave on"); + break; + case ENGRAVE: + everb = (oep && !eow ? "add to the engraving in" : "engrave in"); + break; + case BURN: + everb = (oep && !eow + ? (is_ice(u.ux, u.uy) ? "add to the text melted into" + : "add to the text burned into") + : (is_ice(u.ux, u.uy) ? "melt into" : "burn into")); + break; + case MARK: + everb = (oep && !eow ? "add to the graffiti on" : "scribble on"); + break; + case ENGR_BLOOD: + everb = (oep && !eow ? "add to the scrawl on" : "scrawl on"); + break; + } - eloc = surface(u.ux,u.uy); - switch(type){ - default: - everb = (oep && !eow ? "add to the weird writing on" : - "write strangely on"); - break; - case DUST: - everb = (oep && !eow ? "add to the writing in" : - "write in"); - eloc = is_ice(u.ux,u.uy) ? "frost" : "dust"; - break; - case HEADSTONE: - everb = (oep && !eow ? "add to the epitaph on" : - "engrave on"); - break; - case ENGRAVE: - everb = (oep && !eow ? "add to the engraving in" : - "engrave in"); - break; - case BURN: - everb = (oep && !eow ? - ( is_ice(u.ux,u.uy) ? "add to the text melted into" : - "add to the text burned into") : - ( is_ice(u.ux,u.uy) ? "melt into" : "burn into")); - break; - case MARK: - everb = (oep && !eow ? "add to the graffiti on" : - "scribble on"); - break; - case ENGR_BLOOD: - everb = (oep && !eow ? "add to the scrawl on" : - "scrawl on"); - break; - } + /* Tell adventurer what is going on */ + if (otmp != &zeroobj) + You("%s the %s with %s.", everb, eloc, doname(otmp)); + else + You("%s the %s with your %s.", everb, eloc, + makeplural(body_part(FINGER))); - /* Tell adventurer what is going on */ - if (otmp != &zeroobj) - You("%s the %s with %s.", everb, eloc, doname(otmp)); - else - You("%s the %s with your %s.", everb, eloc, - makeplural(body_part(FINGER))); + /* Prompt for engraving! */ + Sprintf(qbuf, "What do you want to %s the %s here?", everb, eloc); + getlin(qbuf, ebuf); + /* convert tabs to spaces and condense consecutive spaces to one */ + mungspaces(ebuf); - /* Prompt for engraving! */ - Sprintf(qbuf,"What do you want to %s the %s here?", everb, eloc); - getlin(qbuf, ebuf); - /* convert tabs to spaces and condense consecutive spaces to one */ - mungspaces(ebuf); + /* Count the actual # of chars engraved not including spaces */ + len = strlen(ebuf); + for (sp = ebuf; *sp; sp++) + if (*sp == ' ') + len -= 1; - /* Count the actual # of chars engraved not including spaces */ - len = strlen(ebuf); - for (sp = ebuf; *sp; sp++) - if (*sp == ' ') len -= 1; + if (len == 0 || index(ebuf, '\033')) { + if (zapwand) { + if (!Blind) + pline("%s, then %s.", Tobjnam(otmp, "glow"), + otense(otmp, "fade")); + return (1); + } else { + pline1(Never_mind); + return (0); + } + } - if (len == 0 || index(ebuf, '\033')) { - if (zapwand) { - if (!Blind) - pline("%s, then %s.", - Tobjnam(otmp, "glow"), otense(otmp, "fade")); - return(1); - } else { - pline1(Never_mind); - return(0); - } - } + /* A single `x' is the traditional signature of an illiterate person */ + if (len != 1 || (!index(ebuf, 'x') && !index(ebuf, 'X'))) + u.uconduct.literate++; - /* A single `x' is the traditional signature of an illiterate person */ - if (len != 1 || (!index(ebuf, 'x') && !index(ebuf, 'X'))) - u.uconduct.literate++; + /* Mix up engraving if surface or state of mind is unsound. + Note: this won't add or remove any spaces. */ + for (sp = ebuf; *sp; sp++) { + if (*sp == ' ') + continue; + if (((type == DUST || type == ENGR_BLOOD) && !rn2(25)) + || (Blind && !rn2(11)) || (Confusion && !rn2(7)) + || (Stunned && !rn2(4)) || (Hallucination && !rn2(2))) + *sp = ' ' + rnd(96 - 2); /* ASCII '!' thru '~' + (excludes ' ' and DEL) */ + } - /* Mix up engraving if surface or state of mind is unsound. - Note: this won't add or remove any spaces. */ - for (sp = ebuf; *sp; sp++) { - if (*sp == ' ') continue; - if (((type == DUST || type == ENGR_BLOOD) && !rn2(25)) || - (Blind && !rn2(11)) || (Confusion && !rn2(7)) || - (Stunned && !rn2(4)) || (Hallucination && !rn2(2))) - *sp = ' ' + rnd(96 - 2); /* ASCII '!' thru '~' - (excludes ' ' and DEL) */ - } + /* Previous engraving is overwritten */ + if (eow) { + del_engr(oep); + oep = (struct engr *) 0; + } - /* Previous engraving is overwritten */ - if (eow) { - del_engr(oep); - oep = (struct engr *)0; - } + /* Figure out how long it took to engrave, and if player has + * engraved too much. + */ + switch (type) { + default: + multi = -(len / 10); + if (multi) + nomovemsg = "You finish your weird engraving."; + break; + case DUST: + multi = -(len / 10); + if (multi) + nomovemsg = "You finish writing in the dust."; + break; + case HEADSTONE: + case ENGRAVE: + multi = -(len / 10); + if ((otmp->oclass == WEAPON_CLASS) + && ((otmp->otyp != ATHAME) || otmp->cursed)) { + multi = -len; + maxelen = ((otmp->spe + 3) * 2) + 1; + /* -2 = 3, -1 = 5, 0 = 7, +1 = 9, +2 = 11 + * Note: this does not allow a +0 anything (except + * an athame) to engrave "Elbereth" all at once. + * However, you could now engrave "Elb", then + * "ere", then "th". + */ + pline("%s dull.", Yobjnam2(otmp, "get")); + costly_alteration(otmp, COST_DEGRD); + if (len > maxelen) { + multi = -maxelen; + otmp->spe = -3; + } else if (len > 1) + otmp->spe -= len >> 1; + else + otmp->spe -= 1; /* Prevent infinite engraving */ + } else if ((otmp->oclass == RING_CLASS) + || (otmp->oclass == GEM_CLASS)) + multi = -len; + if (multi) + nomovemsg = "You finish engraving."; + break; + case BURN: + multi = -(len / 10); + if (multi) + nomovemsg = + is_ice(u.ux, u.uy) + ? "You finish melting your message into the ice." + : "You finish burning your message into the floor."; + break; + case MARK: + multi = -(len / 10); + if ((otmp->oclass == TOOL_CLASS) && (otmp->otyp == MAGIC_MARKER)) { + maxelen = (otmp->spe) * 2; /* one charge / 2 letters */ + if (len > maxelen) { + Your("marker dries out."); + otmp->spe = 0; + multi = -(maxelen / 10); + } else if (len > 1) + otmp->spe -= len >> 1; + else + otmp->spe -= 1; /* Prevent infinite grafitti */ + } + if (multi) + nomovemsg = "You finish defacing the dungeon."; + break; + case ENGR_BLOOD: + multi = -(len / 10); + if (multi) + nomovemsg = "You finish scrawling."; + break; + } - /* Figure out how long it took to engrave, and if player has - * engraved too much. - */ - switch(type){ - default: - multi = -(len/10); - if (multi) nomovemsg = "You finish your weird engraving."; - break; - case DUST: - multi = -(len/10); - if (multi) nomovemsg = "You finish writing in the dust."; - break; - case HEADSTONE: - case ENGRAVE: - multi = -(len/10); - if ((otmp->oclass == WEAPON_CLASS) && - ((otmp->otyp != ATHAME) || otmp->cursed)) { - multi = -len; - maxelen = ((otmp->spe + 3) * 2) + 1; - /* -2 = 3, -1 = 5, 0 = 7, +1 = 9, +2 = 11 - * Note: this does not allow a +0 anything (except - * an athame) to engrave "Elbereth" all at once. - * However, you could now engrave "Elb", then - * "ere", then "th". - */ - pline("%s dull.", Yobjnam2(otmp, "get")); - costly_alteration(otmp, COST_DEGRD); - if (len > maxelen) { - multi = -maxelen; - otmp->spe = -3; - } else if (len > 1) - otmp->spe -= len >> 1; - else otmp->spe -= 1; /* Prevent infinite engraving */ - } else - if ( (otmp->oclass == RING_CLASS) || - (otmp->oclass == GEM_CLASS) ) - multi = -len; - if (multi) nomovemsg = "You finish engraving."; - break; - case BURN: - multi = -(len/10); - if (multi) - nomovemsg = is_ice(u.ux,u.uy) ? - "You finish melting your message into the ice.": - "You finish burning your message into the floor."; - break; - case MARK: - multi = -(len/10); - if ((otmp->oclass == TOOL_CLASS) && - (otmp->otyp == MAGIC_MARKER)) { - maxelen = (otmp->spe) * 2; /* one charge / 2 letters */ - if (len > maxelen) { - Your("marker dries out."); - otmp->spe = 0; - multi = -(maxelen/10); - } else - if (len > 1) otmp->spe -= len >> 1; - else otmp->spe -= 1; /* Prevent infinite grafitti */ - } - if (multi) nomovemsg = "You finish defacing the dungeon."; - break; - case ENGR_BLOOD: - multi = -(len/10); - if (multi) nomovemsg = "You finish scrawling."; - break; - } + /* Chop engraving down to size if necessary */ + if (len > maxelen) { + for (sp = ebuf; (maxelen && *sp); sp++) + if (*sp == ' ') + maxelen--; + if (!maxelen && *sp) { + *sp = (char) 0; + if (multi) + nomovemsg = "You cannot write any more."; + You("are only able to write \"%s\".", ebuf); + } + } - /* Chop engraving down to size if necessary */ - if (len > maxelen) { - for (sp = ebuf; (maxelen && *sp); sp++) - if (*sp == ' ') maxelen--; - if (!maxelen && *sp) { - *sp = (char)0; - if (multi) nomovemsg = "You cannot write any more."; - You("are only able to write \"%s\".", ebuf); - } - } + /* Add to existing engraving */ + if (oep) + Strcpy(buf, oep->engr_txt); - /* Add to existing engraving */ - if (oep) Strcpy(buf, oep->engr_txt); + (void) strncat(buf, ebuf, (BUFSZ - (int) strlen(buf) - 1)); - (void) strncat(buf, ebuf, (BUFSZ - (int)strlen(buf) - 1)); + make_engr_at(u.ux, u.uy, buf, (moves - multi), type); - make_engr_at(u.ux, u.uy, buf, (moves - multi), type); + if (post_engr_text[0]) + pline1(post_engr_text); - if (post_engr_text[0]) pline1(post_engr_text); + if (doblind && !resists_blnd(&youmonst)) { + You("are blinded by the flash!"); + make_blinded((long) rnd(50), FALSE); + if (!Blind) + Your1(vision_clears); + } - if (doblind && !resists_blnd(&youmonst)) { - You("are blinded by the flash!"); - make_blinded((long)rnd(50),FALSE); - if (!Blind) Your1(vision_clears); - } - - return(1); + return (1); } /* while loading bones, clean up text which might accidentally @@ -1126,80 +1170,81 @@ doengrave() void sanitize_engravings() { - struct engr *ep; + struct engr *ep; - for (ep = head_engr; ep; ep = ep->nxt_engr) { - sanitize_name(ep->engr_txt); - } + for (ep = head_engr; ep; ep = ep->nxt_engr) { + sanitize_name(ep->engr_txt); + } } void save_engravings(fd, mode) int fd, mode; { - register struct engr *ep = head_engr; - register struct engr *ep2; - unsigned no_more_engr = 0; + register struct engr *ep = head_engr; + register struct engr *ep2; + unsigned no_more_engr = 0; - while (ep) { - ep2 = ep->nxt_engr; - if (ep->engr_lth && ep->engr_txt[0] && perform_bwrite(mode)) { - bwrite(fd, (genericptr_t)&(ep->engr_lth), sizeof(ep->engr_lth)); - bwrite(fd, (genericptr_t)ep, sizeof(struct engr) + ep->engr_lth); - } - if (release_data(mode)) - dealloc_engr(ep); - ep = ep2; - } - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t)&no_more_engr, sizeof no_more_engr); - if (release_data(mode)) - head_engr = 0; + while (ep) { + ep2 = ep->nxt_engr; + if (ep->engr_lth && ep->engr_txt[0] && perform_bwrite(mode)) { + bwrite(fd, (genericptr_t) & (ep->engr_lth), sizeof(ep->engr_lth)); + bwrite(fd, (genericptr_t) ep, sizeof(struct engr) + ep->engr_lth); + } + if (release_data(mode)) + dealloc_engr(ep); + ep = ep2; + } + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) &no_more_engr, sizeof no_more_engr); + if (release_data(mode)) + head_engr = 0; } void rest_engravings(fd) int fd; { - register struct engr *ep; - unsigned lth; + register struct engr *ep; + unsigned lth; - head_engr = 0; - while(1) { - mread(fd, (genericptr_t) <h, sizeof(unsigned)); - if(lth == 0) return; - ep = newengr(lth); - mread(fd, (genericptr_t) ep, sizeof(struct engr) + lth); - ep->nxt_engr = head_engr; - head_engr = ep; - ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */ - /* mark as finished for bones levels -- no problem for - * normal levels as the player must have finished engraving - * to be able to move again */ - ep->engr_time = moves; - } + head_engr = 0; + while (1) { + mread(fd, (genericptr_t) <h, sizeof(unsigned)); + if (lth == 0) + return; + ep = newengr(lth); + mread(fd, (genericptr_t) ep, sizeof(struct engr) + lth); + ep->nxt_engr = head_engr; + head_engr = ep; + ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */ + /* mark as finished for bones levels -- no problem for + * normal levels as the player must have finished engraving + * to be able to move again */ + ep->engr_time = moves; + } } void del_engr(ep) register struct engr *ep; { - if (ep == head_engr) { - head_engr = ep->nxt_engr; - } else { - register struct engr *ept; + if (ep == head_engr) { + head_engr = ep->nxt_engr; + } else { + register struct engr *ept; - for (ept = head_engr; ept; ept = ept->nxt_engr) - if (ept->nxt_engr == ep) { - ept->nxt_engr = ep->nxt_engr; - break; - } - if (!ept) { - impossible("Error in del_engr?"); - return; - } - } - dealloc_engr(ep); + for (ept = head_engr; ept; ept = ept->nxt_engr) + if (ept->nxt_engr == ep) { + ept->nxt_engr = ep->nxt_engr; + break; + } + if (!ept) { + impossible("Error in del_engr?"); + return; + } + } + dealloc_engr(ep); } /* randomly relocate an engraving */ @@ -1207,20 +1252,19 @@ void rloc_engr(ep) struct engr *ep; { - int tx, ty, tryct = 200; + int tx, ty, tryct = 200; - do { - if (--tryct < 0) return; - tx = rn1(COLNO-3,2); - ty = rn2(ROWNO); - } while (engr_at(tx, ty) || - !goodpos(tx, ty, (struct monst *)0, 0)); + do { + if (--tryct < 0) + return; + tx = rn1(COLNO - 3, 2); + ty = rn2(ROWNO); + } while (engr_at(tx, ty) || !goodpos(tx, ty, (struct monst *) 0, 0)); - ep->engr_x = tx; - ep->engr_y = ty; + ep->engr_x = tx; + ep->engr_y = ty; } - /* Create a headstone at the given location. * The caller is responsible for newsym(x, y). */ @@ -1229,20 +1273,22 @@ make_grave(x, y, str) int x, y; const char *str; { - /* Can we put a grave here? */ - if ((levl[x][y].typ != ROOM && levl[x][y].typ != GRAVE) || t_at(x,y)) return; + /* Can we put a grave here? */ + if ((levl[x][y].typ != ROOM && levl[x][y].typ != GRAVE) || t_at(x, y)) + return; - /* Make the grave */ - levl[x][y].typ = GRAVE; + /* Make the grave */ + levl[x][y].typ = GRAVE; - /* Engrave the headstone */ - del_engr_at(x, y); - if (str) make_engr_at(x, y, str, 0L, HEADSTONE); - else { - char buf[BUFSZ]; - make_engr_at(x, y, get_rnd_text(EPITAPHFILE, buf), 0L, HEADSTONE); - } - return; + /* Engrave the headstone */ + del_engr_at(x, y); + if (str) + make_engr_at(x, y, str, 0L, HEADSTONE); + else { + char buf[BUFSZ]; + make_engr_at(x, y, get_rnd_text(EPITAPHFILE, buf), 0L, HEADSTONE); + } + return; } /*engrave.c*/ diff --git a/src/exper.c b/src/exper.c index 1bb18377e..3991d8a2c 100644 --- a/src/exper.c +++ b/src/exper.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 exper.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 exper.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */ /* NetHack 3.6 exper.c $Date: 2009/05/06 10:46:24 $ $Revision: 1.19 $ */ /* SCCS Id: @(#)exper.c 3.5 2005/09/19 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -14,28 +14,30 @@ STATIC_OVL long newuexp(lev) int lev; { - if (lev < 10) return (10L * (1L << lev)); - if (lev < 20) return (10000L * (1L << (lev - 10))); - return (10000000L * ((long)(lev - 19))); + if (lev < 10) + return (10L * (1L << lev)); + if (lev < 20) + return (10000L * (1L << (lev - 10))); + return (10000000L * ((long) (lev - 19))); } STATIC_OVL int enermod(en) int en; { - switch (Role_switch) { - case PM_PRIEST: - case PM_WIZARD: - return(2 * en); - case PM_HEALER: - case PM_KNIGHT: - return((3 * en) / 2); - case PM_BARBARIAN: - case PM_VALKYRIE: - return((3 * en) / 4); - default: - return (en); - } + switch (Role_switch) { + case PM_PRIEST: + case PM_WIZARD: + return (2 * en); + case PM_HEALER: + case PM_KNIGHT: + return ((3 * en) / 2); + case PM_BARBARIAN: + case PM_VALKYRIE: + return ((3 * en) / 4); + default: + return (en); + } } /* calculate spell power/energy points for new level */ @@ -45,178 +47,199 @@ newpw() int en = 0, enrnd, enfix; if (u.ulevel == 0) { - en = urole.enadv.infix + urace.enadv.infix; - if (urole.enadv.inrnd > 0) en += rnd(urole.enadv.inrnd); - if (urace.enadv.inrnd > 0) en += rnd(urace.enadv.inrnd); + en = urole.enadv.infix + urace.enadv.infix; + if (urole.enadv.inrnd > 0) + en += rnd(urole.enadv.inrnd); + if (urace.enadv.inrnd > 0) + en += rnd(urace.enadv.inrnd); } else { - enrnd = (int)ACURR(A_WIS) / 2; - if (u.ulevel < urole.xlev) { - enrnd += urole.enadv.lornd + urace.enadv.lornd; - enfix = urole.enadv.lofix + urace.enadv.lofix; - } else { - enrnd += urole.enadv.hirnd + urace.enadv.hirnd; - enfix = urole.enadv.hifix + urace.enadv.hifix; - } - en = enermod(rn1(enrnd, enfix)); + enrnd = (int) ACURR(A_WIS) / 2; + if (u.ulevel < urole.xlev) { + enrnd += urole.enadv.lornd + urace.enadv.lornd; + enfix = urole.enadv.lofix + urace.enadv.lofix; + } else { + enrnd += urole.enadv.hirnd + urace.enadv.hirnd; + enfix = urole.enadv.hifix + urace.enadv.hifix; + } + en = enermod(rn1(enrnd, enfix)); } - if (en <= 0) en = 1; - if (u.ulevel < MAXULEV) u.ueninc[u.ulevel] = (xchar)en; + if (en <= 0) + en = 1; + if (u.ulevel < MAXULEV) + u.ueninc[u.ulevel] = (xchar) en; return en; } -int -experience(mtmp, nk) /* return # of exp points for mtmp after nk killed */ - register struct monst *mtmp; - register int nk; +int experience(mtmp, nk) /* return # of exp points for mtmp after nk killed */ +register struct monst *mtmp; +register int nk; { - register struct permonst *ptr = mtmp->data; - int i, tmp, tmp2; + register struct permonst *ptr = mtmp->data; + int i, tmp, tmp2; - tmp = 1 + mtmp->m_lev * mtmp->m_lev; + tmp = 1 + mtmp->m_lev * mtmp->m_lev; -/* For higher ac values, give extra experience */ - if ((i = find_mac(mtmp)) < 3) tmp += (7 - i) * ((i < 0) ? 2 : 1); + /* For higher ac values, give extra experience */ + if ((i = find_mac(mtmp)) < 3) + tmp += (7 - i) * ((i < 0) ? 2 : 1); -/* For very fast monsters, give extra experience */ - if (ptr->mmove > NORMAL_SPEED) - tmp += (ptr->mmove > (3*NORMAL_SPEED/2)) ? 5 : 3; + /* For very fast monsters, give extra experience */ + if (ptr->mmove > NORMAL_SPEED) + tmp += (ptr->mmove > (3 * NORMAL_SPEED / 2)) ? 5 : 3; -/* For each "special" attack type give extra experience */ - for(i = 0; i < NATTK; i++) { + /* For each "special" attack type give extra experience */ + for (i = 0; i < NATTK; i++) { + tmp2 = ptr->mattk[i].aatyp; + if (tmp2 > AT_BUTT) { + if (tmp2 == AT_WEAP) + tmp += 5; + else if (tmp2 == AT_MAGC) + tmp += 10; + else + tmp += 3; + } + } - tmp2 = ptr->mattk[i].aatyp; - if(tmp2 > AT_BUTT) { + /* For each "special" damage type give extra experience */ + for (i = 0; i < NATTK; i++) { + tmp2 = ptr->mattk[i].adtyp; + if (tmp2 > AD_PHYS && tmp2 < AD_BLND) + tmp += 2 * mtmp->m_lev; + else if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_SLIM)) + tmp += 50; + else if (tmp2 != AD_PHYS) + tmp += mtmp->m_lev; + /* extra heavy damage bonus */ + if ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23) + tmp += mtmp->m_lev; + if (tmp2 == AD_WRAP && ptr->mlet == S_EEL && !Amphibious) + tmp += 1000; + } - if(tmp2 == AT_WEAP) tmp += 5; - else if(tmp2 == AT_MAGC) tmp += 10; - else tmp += 3; - } - } + /* For certain "extra nasty" monsters, give even more */ + if (extra_nasty(ptr)) + tmp += (7 * mtmp->m_lev); -/* For each "special" damage type give extra experience */ - for(i = 0; i < NATTK; i++) { - tmp2 = ptr->mattk[i].adtyp; - if(tmp2 > AD_PHYS && tmp2 < AD_BLND) tmp += 2*mtmp->m_lev; - else if((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || - (tmp2 == AD_SLIM)) tmp += 50; - else if(tmp2 != AD_PHYS) tmp += mtmp->m_lev; - /* extra heavy damage bonus */ - if((int)(ptr->mattk[i].damd * ptr->mattk[i].damn) > 23) - tmp += mtmp->m_lev; - if (tmp2 == AD_WRAP && ptr->mlet == S_EEL && !Amphibious) - tmp += 1000; - } - -/* For certain "extra nasty" monsters, give even more */ - if (extra_nasty(ptr)) tmp += (7 * mtmp->m_lev); - -/* For higher level monsters, an additional bonus is given */ - if(mtmp->m_lev > 8) tmp += 50; + /* For higher level monsters, an additional bonus is given */ + if (mtmp->m_lev > 8) + tmp += 50; #ifdef MAIL - /* Mail daemons put up no fight. */ - if(mtmp->data == &mons[PM_MAIL_DAEMON]) tmp = 1; + /* Mail daemons put up no fight. */ + if (mtmp->data == &mons[PM_MAIL_DAEMON]) + tmp = 1; #endif - if (mtmp->mrevived || mtmp->mcloned) { - /* - * Reduce experience awarded for repeated killings of - * "the same monster". Kill count includes all of this - * monster's type which have been killed--including the - * current monster--regardless of how they were created. - * 1.. 20 full experience - * 21.. 40 xp / 2 - * 41.. 80 xp / 4 - * 81..120 xp / 8 - * 121..180 xp / 16 - * 181..240 xp / 32 - * 241..255+ xp / 64 - */ - for (i = 0, tmp2 = 20; nk > tmp2 && tmp > 1; ++i) { - tmp = (tmp + 1) / 2; - nk -= tmp2; - if (i & 1) tmp2 += 20; - } - } + if (mtmp->mrevived || mtmp->mcloned) { + /* + * Reduce experience awarded for repeated killings of + * "the same monster". Kill count includes all of this + * monster's type which have been killed--including the + * current monster--regardless of how they were created. + * 1.. 20 full experience + * 21.. 40 xp / 2 + * 41.. 80 xp / 4 + * 81..120 xp / 8 + * 121..180 xp / 16 + * 181..240 xp / 32 + * 241..255+ xp / 64 + */ + for (i = 0, tmp2 = 20; nk > tmp2 && tmp > 1; ++i) { + tmp = (tmp + 1) / 2; + nk -= tmp2; + if (i & 1) + tmp2 += 20; + } + } - return(tmp); + return (tmp); } void more_experienced(exper, rexp) - register int exper, rexp; +register int exper, rexp; { - long newexp = u.uexp + exper; - long rexpincr = 4*exper + rexp; - long newrexp = u.urexp + rexpincr; + long newexp = u.uexp + exper; + long rexpincr = 4 * exper + rexp; + long newrexp = u.urexp + rexpincr; - /* cap experience and score on wraparound */ - if (newexp < 0 && exper > 0) newexp = LONG_MAX; - if (newrexp < 0 && rexpincr > 0) newrexp = LONG_MAX; - u.uexp = newexp; - u.urexp = newrexp; + /* cap experience and score on wraparound */ + if (newexp < 0 && exper > 0) + newexp = LONG_MAX; + if (newrexp < 0 && rexpincr > 0) + newrexp = LONG_MAX; + u.uexp = newexp; + u.urexp = newrexp; - if(exper + if (exper #ifdef SCORE_ON_BOTL - || flags.showscore + || flags.showscore #endif - ) context.botl = 1; - if (u.urexp >= (Role_if(PM_WIZARD) ? 1000 : 2000)) - flags.beginner = 0; + ) + context.botl = 1; + if (u.urexp >= (Role_if(PM_WIZARD) ? 1000 : 2000)) + flags.beginner = 0; } -void -losexp(drainer) /* e.g., hit by drain life attack */ -const char *drainer; /* cause of death, if drain should be fatal */ +void losexp(drainer) /* e.g., hit by drain life attack */ +const char *drainer; /* cause of death, if drain should be fatal */ { - register int num; + register int num; - /* override life-drain resistance when handling an explicit - wizard mode request to reduce level; never fatal though */ - if (drainer && !strcmp(drainer, "#levelchange")) - drainer = 0; - else - if (resists_drli(&youmonst)) return; + /* override life-drain resistance when handling an explicit + wizard mode request to reduce level; never fatal though */ + if (drainer && !strcmp(drainer, "#levelchange")) + drainer = 0; + else if (resists_drli(&youmonst)) + return; - if (u.ulevel > 1) { - pline("%s level %d.", Goodbye(), u.ulevel--); - /* remove intrinsic abilities */ - adjabil(u.ulevel + 1, u.ulevel); - reset_rndmonst(NON_PM); /* new monster selection */ - } else { - if (drainer) { - killer.format = KILLED_BY; - if (killer.name != drainer) Strcpy(killer.name, drainer); - done(DIED); - } - /* no drainer or lifesaved */ - u.uexp = 0; - } - num = (int) u.uhpinc[u.ulevel]; - u.uhpmax -= num; - if (u.uhpmax < 1) u.uhpmax = 1; - u.uhp -= num; - if (u.uhp < 1) u.uhp = 1; - else if (u.uhp > u.uhpmax) u.uhp = u.uhpmax; + if (u.ulevel > 1) { + pline("%s level %d.", Goodbye(), u.ulevel--); + /* remove intrinsic abilities */ + adjabil(u.ulevel + 1, u.ulevel); + reset_rndmonst(NON_PM); /* new monster selection */ + } else { + if (drainer) { + killer.format = KILLED_BY; + if (killer.name != drainer) + Strcpy(killer.name, drainer); + done(DIED); + } + /* no drainer or lifesaved */ + u.uexp = 0; + } + num = (int) u.uhpinc[u.ulevel]; + u.uhpmax -= num; + if (u.uhpmax < 1) + u.uhpmax = 1; + u.uhp -= num; + if (u.uhp < 1) + u.uhp = 1; + else if (u.uhp > u.uhpmax) + u.uhp = u.uhpmax; - num = (int) u.ueninc[u.ulevel]; - u.uenmax -= num; - if (u.uenmax < 0) u.uenmax = 0; - u.uen -= num; - if (u.uen < 0) u.uen = 0; - else if (u.uen > u.uenmax) u.uen = u.uenmax; + num = (int) u.ueninc[u.ulevel]; + u.uenmax -= num; + if (u.uenmax < 0) + u.uenmax = 0; + u.uen -= num; + if (u.uen < 0) + u.uen = 0; + else if (u.uen > u.uenmax) + u.uen = u.uenmax; - if (u.uexp > 0) - u.uexp = newuexp(u.ulevel) - 1; + if (u.uexp > 0) + u.uexp = newuexp(u.ulevel) - 1; - if (Upolyd) { - num = monhp_per_lvl(&youmonst); - u.mhmax -= num; - u.mh -= num; - if (u.mh <= 0) rehumanize(); - } + if (Upolyd) { + num = monhp_per_lvl(&youmonst); + u.mhmax -= num; + u.mh -= num; + if (u.mh <= 0) + rehumanize(); + } - context.botl = 1; + context.botl = 1; } /* @@ -228,50 +251,53 @@ const char *drainer; /* cause of death, if drain should be fatal */ void newexplevel() { - if (u.ulevel < MAXULEV && u.uexp >= newuexp(u.ulevel)) - pluslvl(TRUE); + if (u.ulevel < MAXULEV && u.uexp >= newuexp(u.ulevel)) + pluslvl(TRUE); } void pluslvl(incr) -boolean incr; /* true iff via incremental experience growth */ -{ /* (false for potion of gain level) */ - int hpinc, eninc; +boolean incr; /* true iff via incremental experience growth */ +{ /* (false for potion of gain level) */ + int hpinc, eninc; - if (!incr) You_feel("more experienced."); + if (!incr) + You_feel("more experienced."); - /* increase hit points (when polymorphed, do monster form first - in order to retain normal human/whatever increase for later) */ - if (Upolyd) { - hpinc = monhp_per_lvl(&youmonst); - u.mhmax += hpinc; - u.mh += hpinc; - } - hpinc = newhp(); - u.uhpmax += hpinc; - u.uhp += hpinc; + /* increase hit points (when polymorphed, do monster form first + in order to retain normal human/whatever increase for later) */ + if (Upolyd) { + hpinc = monhp_per_lvl(&youmonst); + u.mhmax += hpinc; + u.mh += hpinc; + } + hpinc = newhp(); + u.uhpmax += hpinc; + u.uhp += hpinc; - /* increase spell power/energy points */ - eninc = newpw(); - u.uenmax += eninc; - u.uen += eninc; + /* increase spell power/energy points */ + eninc = newpw(); + u.uenmax += eninc; + u.uen += eninc; - /* increase level (unless already maxxed) */ - if (u.ulevel < MAXULEV) { - /* increase experience points to reflect new level */ - if (incr) { - long tmp = newuexp(u.ulevel + 1); - if (u.uexp >= tmp) u.uexp = tmp - 1; - } else { - u.uexp = newuexp(u.ulevel); - } - ++u.ulevel; - if (u.ulevelmax < u.ulevel) u.ulevelmax = u.ulevel; - pline("Welcome to experience level %d.", u.ulevel); - adjabil(u.ulevel - 1, u.ulevel); /* give new intrinsics */ - reset_rndmonst(NON_PM); /* new monster selection */ - } - context.botl = 1; + /* increase level (unless already maxxed) */ + if (u.ulevel < MAXULEV) { + /* increase experience points to reflect new level */ + if (incr) { + long tmp = newuexp(u.ulevel + 1); + if (u.uexp >= tmp) + u.uexp = tmp - 1; + } else { + u.uexp = newuexp(u.ulevel); + } + ++u.ulevel; + if (u.ulevelmax < u.ulevel) + u.ulevelmax = u.ulevel; + pline("Welcome to experience level %d.", u.ulevel); + adjabil(u.ulevel - 1, u.ulevel); /* give new intrinsics */ + reset_rndmonst(NON_PM); /* new monster selection */ + } + context.botl = 1; } /* compute a random amount of experience points suitable for the hero's @@ -279,27 +305,28 @@ boolean incr; /* true iff via incremental experience growth */ level plus a random portion of what it takes to get to the next level */ long rndexp(gaining) -boolean gaining; /* gaining XP via potion vs setting XP for polyself */ +boolean gaining; /* gaining XP via potion vs setting XP for polyself */ { - long minexp, maxexp, diff, factor, result; + long minexp, maxexp, diff, factor, result; - minexp = (u.ulevel == 1) ? 0L : newuexp(u.ulevel - 1); - maxexp = newuexp(u.ulevel); - diff = maxexp - minexp, factor = 1L; - /* make sure that `diff' is an argument which rn2() can handle */ - while (diff >= (long)LARGEST_INT) - diff /= 2L, factor *= 2L; - result = minexp + factor * (long)rn2((int)diff); - /* 3.4.1: if already at level 30, add to current experience - points rather than to threshold needed to reach the current - level; otherwise blessed potions of gain level can result - in lowering the experience points instead of raising them */ - if (u.ulevel == MAXULEV && gaining) { - result += (u.uexp - minexp); - /* avoid wrapping (over 400 blessed potions needed for that...) */ - if (result < u.uexp) result = u.uexp; - } - return result; + minexp = (u.ulevel == 1) ? 0L : newuexp(u.ulevel - 1); + maxexp = newuexp(u.ulevel); + diff = maxexp - minexp, factor = 1L; + /* make sure that `diff' is an argument which rn2() can handle */ + while (diff >= (long) LARGEST_INT) + diff /= 2L, factor *= 2L; + result = minexp + factor * (long) rn2((int) diff); + /* 3.4.1: if already at level 30, add to current experience + points rather than to threshold needed to reach the current + level; otherwise blessed potions of gain level can result + in lowering the experience points instead of raising them */ + if (u.ulevel == MAXULEV && gaining) { + result += (u.uexp - minexp); + /* avoid wrapping (over 400 blessed potions needed for that...) */ + if (result < u.uexp) + result = u.uexp; + } + return result; } /*exper.c*/ diff --git a/src/explode.c b/src/explode.c index 29e73c247..a79fc2bfc 100644 --- a/src/explode.c +++ b/src/explode.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 explode.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 explode.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.40 $ */ /* NetHack 3.6 explode.c $Date: 2013/11/05 00:57:55 $ $Revision: 1.34 $ */ /* Copyright (C) 1990 by Ken Arromdee */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,11 +6,9 @@ #include "hack.h" /* Note: Arrays are column first, while the screen is row first */ -static int explosion[3][3] = { - { S_explode1, S_explode4, S_explode7 }, - { S_explode2, S_explode5, S_explode8 }, - { S_explode3, S_explode6, S_explode9 } -}; +static int explosion[3][3] = { { S_explode1, S_explode4, S_explode7 }, + { S_explode2, S_explode5, S_explode8 }, + { S_explode3, S_explode6, S_explode9 } }; /* Note: I had to choose one of three possible kinds of "type" when writing * this function: a wand type (like in zap.c), an adtyp, or an object type. @@ -35,423 +33,480 @@ int dam; char olet; int expltype; { - int i, j, k, damu = dam; - boolean starting = 1; - boolean visible, any_shield; - int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */ - const char *str = (const char *) 0; - int idamres, idamnonres; - struct monst *mtmp, *mdef = 0; - uchar adtyp; - int explmask[3][3]; - /* 0=normal explosion, 1=do shieldeff, 2=do nothing */ - boolean shopdamage = FALSE, generic = FALSE, physical_dmg = FALSE, - do_hallu = FALSE, inside_engulfer; - char hallu_buf[BUFSZ]; - short exploding_wand_typ = 0; + int i, j, k, damu = dam; + boolean starting = 1; + boolean visible, any_shield; + int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */ + const char *str = (const char *) 0; + int idamres, idamnonres; + struct monst *mtmp, *mdef = 0; + uchar adtyp; + int explmask[3][3]; + /* 0=normal explosion, 1=do shieldeff, 2=do nothing */ + boolean shopdamage = FALSE, generic = FALSE, physical_dmg = FALSE, + do_hallu = FALSE, inside_engulfer; + char hallu_buf[BUFSZ]; + short exploding_wand_typ = 0; - if (olet == WAND_CLASS) { /* retributive strike */ - /* 'type' is passed as (wand's object type * -1); save - object type and convert 'type' itself to zap-type */ - if (type < 0) { - type = -type; - exploding_wand_typ = (short)type; - /* most attack wands produce specific explosions; - other types produce a generic magical explosion */ - if (objects[type].oc_dir == RAY && type != WAN_DIGGING) { - type -= WAN_MAGIC_MISSILE; - if (type < 0 || type > 9) { - impossible("explode: wand has bad zap type (%d).", - type); - type = 0; - } - } else - type = 0; - } - switch (Role_switch) { - case PM_PRIEST: - case PM_MONK: - case PM_WIZARD: damu /= 5; - break; - case PM_HEALER: - case PM_KNIGHT: damu /= 2; - break; - default: break; - } - } - /* muse_unslime: SCR_FIRE */ - if (expltype < 0) { - /* hero gets credit/blame for killing this monster, not others */ - mdef = m_at(x, y); - expltype = -expltype; - } - /* if hero is engulfed and caused the explosion, only hero and - engulfer will be affected */ - inside_engulfer = (u.uswallow && type >= 0); + if (olet == WAND_CLASS) { /* retributive strike */ + /* 'type' is passed as (wand's object type * -1); save + object type and convert 'type' itself to zap-type */ + if (type < 0) { + type = -type; + exploding_wand_typ = (short) type; + /* most attack wands produce specific explosions; + other types produce a generic magical explosion */ + if (objects[type].oc_dir == RAY && type != WAN_DIGGING) { + type -= WAN_MAGIC_MISSILE; + if (type < 0 || type > 9) { + impossible("explode: wand has bad zap type (%d).", type); + type = 0; + } + } else + type = 0; + } + switch (Role_switch) { + case PM_PRIEST: + case PM_MONK: + case PM_WIZARD: + damu /= 5; + break; + case PM_HEALER: + case PM_KNIGHT: + damu /= 2; + break; + default: + break; + } + } + /* muse_unslime: SCR_FIRE */ + if (expltype < 0) { + /* hero gets credit/blame for killing this monster, not others */ + mdef = m_at(x, y); + expltype = -expltype; + } + /* if hero is engulfed and caused the explosion, only hero and + engulfer will be affected */ + inside_engulfer = (u.uswallow && type >= 0); - if (olet == MON_EXPLODE) { - str = killer.name; - do_hallu = Hallucination && strstri(str, "'s explosion"); - adtyp = AD_PHYS; - } else - switch (abs(type) % 10) { - case 0: str = "magical blast"; - adtyp = AD_MAGM; - break; - case 1: str = olet == BURNING_OIL ? "burning oil" : - olet == SCROLL_CLASS ? "tower of flame" : - "fireball"; - /* fire damage, not physical damage */ - adtyp = AD_FIRE; - break; - case 2: str = "ball of cold"; - adtyp = AD_COLD; - break; - case 4: str = (olet == WAND_CLASS) ? "death field" : - "disintegration field"; - adtyp = AD_DISN; - break; - case 5: str = "ball of lightning"; - adtyp = AD_ELEC; - break; - case 6: str = "poison gas cloud"; - adtyp = AD_DRST; - break; - case 7: str = "splash of acid"; - adtyp = AD_ACID; - break; - default: impossible("explosion base type %d?", type); return; - } + if (olet == MON_EXPLODE) { + str = killer.name; + do_hallu = Hallucination && strstri(str, "'s explosion"); + adtyp = AD_PHYS; + } else + switch (abs(type) % 10) { + case 0: + str = "magical blast"; + adtyp = AD_MAGM; + break; + case 1: + str = olet == BURNING_OIL ? "burning oil" : olet == SCROLL_CLASS + ? "tower of flame" + : "fireball"; + /* fire damage, not physical damage */ + adtyp = AD_FIRE; + break; + case 2: + str = "ball of cold"; + adtyp = AD_COLD; + break; + case 4: + str = + (olet == WAND_CLASS) ? "death field" : "disintegration field"; + adtyp = AD_DISN; + break; + case 5: + str = "ball of lightning"; + adtyp = AD_ELEC; + break; + case 6: + str = "poison gas cloud"; + adtyp = AD_DRST; + break; + case 7: + str = "splash of acid"; + adtyp = AD_ACID; + break; + default: + impossible("explosion base type %d?", type); + return; + } - any_shield = visible = FALSE; - for (i=0; i<3; i++) for (j=0; j<3; j++) { - if (!isok(i+x-1, j+y-1)) { - explmask[i][j] = 2; - continue; - } else - explmask[i][j] = 0; + any_shield = visible = FALSE; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + if (!isok(i + x - 1, j + y - 1)) { + explmask[i][j] = 2; + continue; + } else + explmask[i][j] = 0; - if (i+x-1 == u.ux && j+y-1 == u.uy) { - switch(adtyp) { - case AD_PHYS: - explmask[i][j] = 0; - break; - case AD_MAGM: - explmask[i][j] = !!Antimagic; - break; - case AD_FIRE: - explmask[i][j] = !!Fire_resistance; - break; - case AD_COLD: - explmask[i][j] = !!Cold_resistance; - break; - case AD_DISN: - explmask[i][j] = (olet == WAND_CLASS) ? - !!(nonliving(youmonst.data) || is_demon(youmonst.data)) : - !!Disint_resistance; - break; - case AD_ELEC: - explmask[i][j] = !!Shock_resistance; - break; - case AD_DRST: - explmask[i][j] = !!Poison_resistance; - break; - case AD_ACID: - explmask[i][j] = !!Acid_resistance; - physical_dmg = TRUE; - break; - default: - impossible("explosion type %d?", adtyp); - break; - } - } - /* can be both you and mtmp if you're swallowed */ - mtmp = m_at(i+x-1, j+y-1); - if (!mtmp && i+x-1 == u.ux && j+y-1 == u.uy) - mtmp = u.usteed; - if (mtmp) { - if (mtmp->mhp < 1) explmask[i][j] = 2; - else switch(adtyp) { - case AD_PHYS: - break; - case AD_MAGM: - explmask[i][j] |= resists_magm(mtmp); - break; - case AD_FIRE: - explmask[i][j] |= resists_fire(mtmp); - break; - case AD_COLD: - explmask[i][j] |= resists_cold(mtmp); - break; - case AD_DISN: - explmask[i][j] |= (olet == WAND_CLASS) ? - (nonliving(mtmp->data) || is_demon(mtmp->data) || is_vampshifter(mtmp)) : - resists_disint(mtmp); - break; - case AD_ELEC: - explmask[i][j] |= resists_elec(mtmp); - break; - case AD_DRST: - explmask[i][j] |= resists_poison(mtmp); - break; - case AD_ACID: - explmask[i][j] |= resists_acid(mtmp); - break; - default: - impossible("explosion type %d?", adtyp); - break; - } - } - if (mtmp && cansee(i+x-1,j+y-1) && !canspotmon(mtmp)) - map_invisible(i+x-1, j+y-1); - else if (!mtmp && glyph_is_invisible(levl[i+x-1][j+y-1].glyph)) { - unmap_object(i+x-1, j+y-1); - newsym(i+x-1, j+y-1); - } - if (cansee(i+x-1, j+y-1)) visible = TRUE; - if (explmask[i][j] == 1) any_shield = TRUE; - } + if (i + x - 1 == u.ux && j + y - 1 == u.uy) { + switch (adtyp) { + case AD_PHYS: + explmask[i][j] = 0; + break; + case AD_MAGM: + explmask[i][j] = !!Antimagic; + break; + case AD_FIRE: + explmask[i][j] = !!Fire_resistance; + break; + case AD_COLD: + explmask[i][j] = !!Cold_resistance; + break; + case AD_DISN: + explmask[i][j] = (olet == WAND_CLASS) + ? !!(nonliving(youmonst.data) + || is_demon(youmonst.data)) + : !!Disint_resistance; + break; + case AD_ELEC: + explmask[i][j] = !!Shock_resistance; + break; + case AD_DRST: + explmask[i][j] = !!Poison_resistance; + break; + case AD_ACID: + explmask[i][j] = !!Acid_resistance; + physical_dmg = TRUE; + break; + default: + impossible("explosion type %d?", adtyp); + break; + } + } + /* can be both you and mtmp if you're swallowed */ + mtmp = m_at(i + x - 1, j + y - 1); + if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy) + mtmp = u.usteed; + if (mtmp) { + if (mtmp->mhp < 1) + explmask[i][j] = 2; + else + switch (adtyp) { + case AD_PHYS: + break; + case AD_MAGM: + explmask[i][j] |= resists_magm(mtmp); + break; + case AD_FIRE: + explmask[i][j] |= resists_fire(mtmp); + break; + case AD_COLD: + explmask[i][j] |= resists_cold(mtmp); + break; + case AD_DISN: + explmask[i][j] |= (olet == WAND_CLASS) + ? (nonliving(mtmp->data) + || is_demon(mtmp->data) + || is_vampshifter(mtmp)) + : resists_disint(mtmp); + break; + case AD_ELEC: + explmask[i][j] |= resists_elec(mtmp); + break; + case AD_DRST: + explmask[i][j] |= resists_poison(mtmp); + break; + case AD_ACID: + explmask[i][j] |= resists_acid(mtmp); + break; + default: + impossible("explosion type %d?", adtyp); + break; + } + } + if (mtmp && cansee(i + x - 1, j + y - 1) && !canspotmon(mtmp)) + map_invisible(i + x - 1, j + y - 1); + else if (!mtmp && glyph_is_invisible( + levl[i + x - 1][j + y - 1].glyph)) { + unmap_object(i + x - 1, j + y - 1); + newsym(i + x - 1, j + y - 1); + } + if (cansee(i + x - 1, j + y - 1)) + visible = TRUE; + if (explmask[i][j] == 1) + any_shield = TRUE; + } - if (visible) { - /* Start the explosion */ - for (i=0; i<3; i++) for (j=0; j<3; j++) { - if (explmask[i][j] == 2) continue; - tmp_at(starting ? DISP_BEAM : DISP_CHANGE, - explosion_to_glyph(expltype,explosion[i][j])); - tmp_at(i+x-1, j+y-1); - starting = 0; - } - curs_on_u(); /* will flush screen and output */ + if (visible) { + /* Start the explosion */ + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + if (explmask[i][j] == 2) + continue; + tmp_at(starting ? DISP_BEAM : DISP_CHANGE, + explosion_to_glyph(expltype, explosion[i][j])); + tmp_at(i + x - 1, j + y - 1); + starting = 0; + } + curs_on_u(); /* will flush screen and output */ - if (any_shield && flags.sparkle) { /* simulate shield effect */ - for (k = 0; k < SHIELD_COUNT; k++) { - for (i=0; i<3; i++) for (j=0; j<3; j++) { - if (explmask[i][j] == 1) - /* - * Bypass tmp_at() and send the shield glyphs - * directly to the buffered screen. tmp_at() - * will clean up the location for us later. - */ - show_glyph(i+x-1, j+y-1, - cmap_to_glyph(shield_static[k])); - } - curs_on_u(); /* will flush screen and output */ - delay_output(); - } + if (any_shield && flags.sparkle) { /* simulate shield effect */ + for (k = 0; k < SHIELD_COUNT; k++) { + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + if (explmask[i][j] == 1) + /* + * Bypass tmp_at() and send the shield glyphs + * directly to the buffered screen. tmp_at() + * will clean up the location for us later. + */ + show_glyph(i + x - 1, j + y - 1, + cmap_to_glyph(shield_static[k])); + } + curs_on_u(); /* will flush screen and output */ + delay_output(); + } - /* Cover last shield glyph with blast symbol. */ - for (i=0; i<3; i++) for (j=0; j<3; j++) { - if (explmask[i][j] == 1) - show_glyph(i+x-1,j+y-1, - explosion_to_glyph(expltype, explosion[i][j])); - } + /* Cover last shield glyph with blast symbol. */ + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + if (explmask[i][j] == 1) + show_glyph( + i + x - 1, j + y - 1, + explosion_to_glyph(expltype, explosion[i][j])); + } - } else { /* delay a little bit. */ - delay_output(); - delay_output(); - } + } else { /* delay a little bit. */ + delay_output(); + delay_output(); + } - tmp_at(DISP_END, 0); /* clear the explosion */ - } else { - if (olet == MON_EXPLODE) { - str = "explosion"; - generic = TRUE; - } - if (!Deaf && olet != SCROLL_CLASS) You_hear("a blast."); - } + tmp_at(DISP_END, 0); /* clear the explosion */ + } else { + if (olet == MON_EXPLODE) { + str = "explosion"; + generic = TRUE; + } + if (!Deaf && olet != SCROLL_CLASS) + You_hear("a blast."); + } if (dam) - for (i=0; i<3; i++) for (j=0; j<3; j++) { - if (explmask[i][j] == 2) continue; - if (i+x-1 == u.ux && j+y-1 == u.uy) - uhurt = (explmask[i][j] == 1) ? 1 : 2; - /* for inside_engulfer, only is affected */ - else if (inside_engulfer) continue; - idamres = idamnonres = 0; - if (type >= 0 && !u.uswallow) - (void)zap_over_floor((xchar)(i+x-1), (xchar)(j+y-1), - type, &shopdamage, exploding_wand_typ); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + if (explmask[i][j] == 2) + continue; + if (i + x - 1 == u.ux && j + y - 1 == u.uy) + uhurt = (explmask[i][j] == 1) ? 1 : 2; + /* for inside_engulfer, only is affected */ + else if (inside_engulfer) + continue; + idamres = idamnonres = 0; + if (type >= 0 && !u.uswallow) + (void) zap_over_floor((xchar)(i + x - 1), + (xchar)(j + y - 1), type, + &shopdamage, exploding_wand_typ); - mtmp = m_at(i+x-1, j+y-1); - if (!mtmp && i+x-1 == u.ux && j+y-1 == u.uy) - mtmp = u.usteed; - if (!mtmp) continue; - if (do_hallu) { - /* replace "gas spore" with a different description - for each target (we can't distinguish personal names - like "Barney" here in order to suppress "the" below, - so avoid any which begins with a capital letter) */ - do { - Sprintf(hallu_buf, "%s explosion", - s_suffix(rndmonnam(NULL))); - } while (*hallu_buf != lowc(*hallu_buf)); - str = hallu_buf; - } - if (u.uswallow && mtmp == u.ustuck) { - if (is_animal(u.ustuck->data)) - pline("%s gets %s!", - Monnam(u.ustuck), - (adtyp == AD_FIRE) ? "heartburn" : - (adtyp == AD_COLD) ? "chilly" : - (adtyp == AD_DISN) ? ((olet == WAND_CLASS) ? - "irradiated by pure energy" : "perforated") : - (adtyp == AD_ELEC) ? "shocked" : - (adtyp == AD_DRST) ? "poisoned" : - (adtyp == AD_ACID) ? "an upset stomach" : - "fried"); - else - pline("%s gets slightly %s!", - Monnam(u.ustuck), - (adtyp == AD_FIRE) ? "toasted" : - (adtyp == AD_COLD) ? "chilly" : - (adtyp == AD_DISN) ? ((olet == WAND_CLASS) ? - "overwhelmed by pure energy" : "perforated") : - (adtyp == AD_ELEC) ? "shocked" : - (adtyp == AD_DRST) ? "intoxicated" : - (adtyp == AD_ACID) ? "burned" : - "fried"); - } else if (cansee(i+x-1, j+y-1)) { - if(mtmp->m_ap_type) seemimic(mtmp); - pline("%s is caught in the %s!", Monnam(mtmp), str); - } + mtmp = m_at(i + x - 1, j + y - 1); + if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy) + mtmp = u.usteed; + if (!mtmp) + continue; + if (do_hallu) { + /* replace "gas spore" with a different description + for each target (we can't distinguish personal names + like "Barney" here in order to suppress "the" below, + so avoid any which begins with a capital letter) */ + do { + Sprintf(hallu_buf, "%s explosion", + s_suffix(rndmonnam(NULL))); + } while (*hallu_buf != lowc(*hallu_buf)); + str = hallu_buf; + } + if (u.uswallow && mtmp == u.ustuck) { + if (is_animal(u.ustuck->data)) + pline("%s gets %s!", Monnam(u.ustuck), + (adtyp == AD_FIRE) + ? "heartburn" + : (adtyp == AD_COLD) + ? "chilly" + : (adtyp == AD_DISN) + ? ((olet == WAND_CLASS) + ? "irradiated by pure " + "energy" + : "perforated") + : (adtyp == AD_ELEC) + ? "shocked" + : (adtyp == AD_DRST) + ? "poisoned" + : (adtyp == AD_ACID) + ? "an upset " + "stomach" + : "fried"); + else + pline("%s gets slightly %s!", Monnam(u.ustuck), + (adtyp == AD_FIRE) + ? "toasted" + : (adtyp == AD_COLD) + ? "chilly" + : (adtyp == AD_DISN) + ? ((olet == WAND_CLASS) + ? "overwhelmed by pure " + "energy" + : "perforated") + : (adtyp == AD_ELEC) + ? "shocked" + : (adtyp == AD_DRST) + ? "intoxicated" + : (adtyp == AD_ACID) + ? "burned" + : "fried"); + } else if (cansee(i + x - 1, j + y - 1)) { + if (mtmp->m_ap_type) + seemimic(mtmp); + pline("%s is caught in the %s!", Monnam(mtmp), str); + } - idamres += destroy_mitem(mtmp, SCROLL_CLASS, (int) adtyp); - idamres += destroy_mitem(mtmp, SPBOOK_CLASS, (int) adtyp); - idamnonres += destroy_mitem(mtmp, POTION_CLASS, (int) adtyp); - idamnonres += destroy_mitem(mtmp, WAND_CLASS, (int) adtyp); - idamnonres += destroy_mitem(mtmp, RING_CLASS, (int) adtyp); + idamres += destroy_mitem(mtmp, SCROLL_CLASS, (int) adtyp); + idamres += destroy_mitem(mtmp, SPBOOK_CLASS, (int) adtyp); + idamnonres += destroy_mitem(mtmp, POTION_CLASS, (int) adtyp); + idamnonres += destroy_mitem(mtmp, WAND_CLASS, (int) adtyp); + idamnonres += destroy_mitem(mtmp, RING_CLASS, (int) adtyp); - if (explmask[i][j] == 1) { - golemeffects(mtmp, (int) adtyp, dam + idamres); - mtmp->mhp -= idamnonres; - } else { - /* call resist with 0 and do damage manually so 1) we can - * get out the message before doing the damage, and 2) we can - * call mondied, not killed, if it's not your blast - */ - int mdam = dam; + if (explmask[i][j] == 1) { + golemeffects(mtmp, (int) adtyp, dam + idamres); + mtmp->mhp -= idamnonres; + } else { + /* call resist with 0 and do damage manually so 1) we can + * get out the message before doing the damage, and 2) we + * can + * call mondied, not killed, if it's not your blast + */ + int mdam = dam; - if (resist(mtmp, olet, 0, FALSE)) { - /* inside_engulfer: == */ - if (cansee(i+x-1,j+y-1) || inside_engulfer) - pline("%s resists the %s!", Monnam(mtmp), str); - mdam = (dam + 1) / 2; - } - if (mtmp == u.ustuck) - mdam *= 2; - if (resists_cold(mtmp) && adtyp == AD_FIRE) - mdam *= 2; - else if (resists_fire(mtmp) && adtyp == AD_COLD) - mdam *= 2; - mtmp->mhp -= mdam; - mtmp->mhp -= (idamres + idamnonres); - } - if (mtmp->mhp <= 0) { - if (mdef ? (mtmp == mdef) : !context.mon_moving) - killed(mtmp); - else - monkilled(mtmp, "", (int)adtyp); - } else if (!context.mon_moving) { - /* all affected monsters, even if mdef is set */ - setmangry(mtmp); - } - } + if (resist(mtmp, olet, 0, FALSE)) { + /* inside_engulfer: == */ + if (cansee(i + x - 1, j + y - 1) || inside_engulfer) + pline("%s resists the %s!", Monnam(mtmp), str); + mdam = (dam + 1) / 2; + } + if (mtmp == u.ustuck) + mdam *= 2; + if (resists_cold(mtmp) && adtyp == AD_FIRE) + mdam *= 2; + else if (resists_fire(mtmp) && adtyp == AD_COLD) + mdam *= 2; + mtmp->mhp -= mdam; + mtmp->mhp -= (idamres + idamnonres); + } + if (mtmp->mhp <= 0) { + if (mdef ? (mtmp == mdef) : !context.mon_moving) + killed(mtmp); + else + monkilled(mtmp, "", (int) adtyp); + } else if (!context.mon_moving) { + /* all affected monsters, even if mdef is set */ + setmangry(mtmp); + } + } - /* Do your injury last */ - if (uhurt) { - /* give message for any monster-induced explosion - or player-induced one other than scroll of fire */ - if (flags.verbose && (type < 0 || olet != SCROLL_CLASS)) { - if (do_hallu) { /* (see explanation above) */ - do { - Sprintf(hallu_buf, "%s explosion", - s_suffix(rndmonnam(NULL))); - } while (*hallu_buf != lowc(*hallu_buf)); - str = hallu_buf; - } - You("are caught in the %s!", str); - iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION; - } - /* do property damage first, in case we end up leaving bones */ - if (adtyp == AD_FIRE) burn_away_slime(); - if (Invulnerable) { - damu = 0; - You("are unharmed!"); - } else if (adtyp == AD_PHYS || physical_dmg) - damu = Maybe_Half_Phys(damu); - if (adtyp == AD_FIRE) (void) burnarmor(&youmonst); - destroy_item(SCROLL_CLASS, (int) adtyp); - destroy_item(SPBOOK_CLASS, (int) adtyp); - destroy_item(POTION_CLASS, (int) adtyp); - destroy_item(RING_CLASS, (int) adtyp); - destroy_item(WAND_CLASS, (int) adtyp); + /* Do your injury last */ + if (uhurt) { + /* give message for any monster-induced explosion + or player-induced one other than scroll of fire */ + if (flags.verbose && (type < 0 || olet != SCROLL_CLASS)) { + if (do_hallu) { /* (see explanation above) */ + do { + Sprintf(hallu_buf, "%s explosion", + s_suffix(rndmonnam(NULL))); + } while (*hallu_buf != lowc(*hallu_buf)); + str = hallu_buf; + } + You("are caught in the %s!", str); + iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION; + } + /* do property damage first, in case we end up leaving bones */ + if (adtyp == AD_FIRE) + burn_away_slime(); + if (Invulnerable) { + damu = 0; + You("are unharmed!"); + } else if (adtyp == AD_PHYS || physical_dmg) + damu = Maybe_Half_Phys(damu); + if (adtyp == AD_FIRE) + (void) burnarmor(&youmonst); + destroy_item(SCROLL_CLASS, (int) adtyp); + destroy_item(SPBOOK_CLASS, (int) adtyp); + destroy_item(POTION_CLASS, (int) adtyp); + destroy_item(RING_CLASS, (int) adtyp); + destroy_item(WAND_CLASS, (int) adtyp); - ugolemeffects((int) adtyp, damu); - if (uhurt == 2) { - if (Upolyd) - u.mh -= damu; - else - u.uhp -= damu; - context.botl = 1; - } + ugolemeffects((int) adtyp, damu); + if (uhurt == 2) { + if (Upolyd) + u.mh -= damu; + else + u.uhp -= damu; + context.botl = 1; + } - if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) { - if (Upolyd) { - rehumanize(); - } else { - if (olet == MON_EXPLODE) { - /* killer handled by caller */ - if (generic) - killer.name[0] = 0; - else if (str != killer.name && str != hallu_buf) - Strcpy(killer.name, str); - killer.format = KILLED_BY_AN; - } else if (type >= 0 && olet != SCROLL_CLASS) { - killer.format = NO_KILLER_PREFIX; - Sprintf(killer.name, "caught %sself in %s own %s", - uhim(), uhis(), str); - } else { - killer.format = (!strcmpi(str, "tower of flame") || - !strcmpi(str, "fireball")) ? - KILLED_BY_AN : KILLED_BY; - Strcpy(killer.name, str); - } - if (iflags.last_msg == PLNMSG_CAUGHT_IN_EXPLOSION || - iflags.last_msg == PLNMSG_TOWER_OF_FLAME) /*seffects()*/ - pline("It is fatal."); - else - pline_The("%s is fatal.", str); - /* Known BUG: BURNING suppresses corpse in bones data, - but done does not handle killer reason correctly */ - done((adtyp == AD_FIRE) ? BURNING : DIED); - } - } - exercise(A_STR, FALSE); - } + if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) { + if (Upolyd) { + rehumanize(); + } else { + if (olet == MON_EXPLODE) { + /* killer handled by caller */ + if (generic) + killer.name[0] = 0; + else if (str != killer.name && str != hallu_buf) + Strcpy(killer.name, str); + killer.format = KILLED_BY_AN; + } else if (type >= 0 && olet != SCROLL_CLASS) { + killer.format = NO_KILLER_PREFIX; + Sprintf(killer.name, "caught %sself in %s own %s", uhim(), + uhis(), str); + } else { + killer.format = (!strcmpi(str, "tower of flame") + || !strcmpi(str, "fireball")) + ? KILLED_BY_AN + : KILLED_BY; + Strcpy(killer.name, str); + } + if (iflags.last_msg == PLNMSG_CAUGHT_IN_EXPLOSION + || iflags.last_msg + == PLNMSG_TOWER_OF_FLAME) /*seffects()*/ + pline("It is fatal."); + else + pline_The("%s is fatal.", str); + /* Known BUG: BURNING suppresses corpse in bones data, + but done does not handle killer reason correctly */ + done((adtyp == AD_FIRE) ? BURNING : DIED); + } + } + exercise(A_STR, FALSE); + } - if (shopdamage) { - pay_for_damage(adtyp == AD_FIRE ? "burn away" : - adtyp == AD_COLD ? "shatter" : - adtyp == AD_DISN ? "disintegrate" : "destroy", - FALSE); - } + if (shopdamage) { + pay_for_damage(adtyp == AD_FIRE + ? "burn away" + : adtyp == AD_COLD + ? "shatter" + : adtyp == AD_DISN ? "disintegrate" + : "destroy", + FALSE); + } - /* explosions are noisy */ - i = dam * dam; - if (i < 50) i = 50; /* in case random damage is very small */ - if (inside_engulfer) i = (i + 3) / 4; - wake_nearto(x, y, i); + /* explosions are noisy */ + i = dam * dam; + if (i < 50) + i = 50; /* in case random damage is very small */ + if (inside_engulfer) + i = (i + 3) / 4; + wake_nearto(x, y, i); } struct scatter_chain { - struct scatter_chain *next; /* pointer to next scatter item */ - struct obj *obj; /* pointer to the object */ - xchar ox; /* location of */ - xchar oy; /* item */ - schar dx; /* direction of */ - schar dy; /* travel */ - int range; /* range of object */ - boolean stopped; /* flag for in-motion/stopped */ + struct scatter_chain *next; /* pointer to next scatter item */ + struct obj *obj; /* pointer to the object */ + xchar ox; /* location of */ + xchar oy; /* item */ + schar dx; /* direction of */ + schar dy; /* travel */ + int range; /* range of object */ + boolean stopped; /* flag for in-motion/stopped */ }; /* @@ -466,158 +521,163 @@ struct scatter_chain { /* returns number of scattered objects */ long -scatter(sx,sy,blastforce,scflags, obj) -int sx,sy; /* location of objects to scatter */ -int blastforce; /* force behind the scattering */ +scatter(sx, sy, blastforce, scflags, obj) +int sx, sy; /* location of objects to scatter */ +int blastforce; /* force behind the scattering */ unsigned int scflags; -struct obj *obj; /* only scatter this obj */ +struct obj *obj; /* only scatter this obj */ { - register struct obj *otmp; - register int tmp; - int farthest = 0; - uchar typ; - long qtmp; - boolean used_up; - boolean individual_object = obj ? TRUE : FALSE; - struct monst *mtmp; - struct scatter_chain *stmp, *stmp2 = 0; - struct scatter_chain *schain = (struct scatter_chain *)0; - long total = 0L; + register struct obj *otmp; + register int tmp; + int farthest = 0; + uchar typ; + long qtmp; + boolean used_up; + boolean individual_object = obj ? TRUE : FALSE; + struct monst *mtmp; + struct scatter_chain *stmp, *stmp2 = 0; + struct scatter_chain *schain = (struct scatter_chain *) 0; + long total = 0L; - while ((otmp = individual_object ? obj : level.objects[sx][sy]) != 0) { - if (otmp->quan > 1L) { - qtmp = otmp->quan - 1L; - if (qtmp > LARGEST_INT) qtmp = LARGEST_INT; - qtmp = (long)rnd((int)qtmp); - otmp = splitobj(otmp, qtmp); - } else { - obj = (struct obj *)0; /* all used */ - } - obj_extract_self(otmp); - used_up = FALSE; + while ((otmp = individual_object ? obj : level.objects[sx][sy]) != 0) { + if (otmp->quan > 1L) { + qtmp = otmp->quan - 1L; + if (qtmp > LARGEST_INT) + qtmp = LARGEST_INT; + qtmp = (long) rnd((int) qtmp); + otmp = splitobj(otmp, qtmp); + } else { + obj = (struct obj *) 0; /* all used */ + } + obj_extract_self(otmp); + used_up = FALSE; - /* 9 in 10 chance of fracturing boulders or statues */ - if ((scflags & MAY_FRACTURE) - && ((otmp->otyp == BOULDER) || (otmp->otyp == STATUE)) - && rn2(10)) { - if (otmp->otyp == BOULDER) { - pline("%s apart.", Tobjnam(otmp, "break")); - fracture_rock(otmp); - place_object(otmp, sx, sy); - if ((otmp = sobj_at(BOULDER, sx, sy)) != 0) { - /* another boulder here, restack it to the top */ - obj_extract_self(otmp); - place_object(otmp, sx, sy); - } - } else { - struct trap *trap; + /* 9 in 10 chance of fracturing boulders or statues */ + if ((scflags & MAY_FRACTURE) + && ((otmp->otyp == BOULDER) || (otmp->otyp == STATUE)) + && rn2(10)) { + if (otmp->otyp == BOULDER) { + pline("%s apart.", Tobjnam(otmp, "break")); + fracture_rock(otmp); + place_object(otmp, sx, sy); + if ((otmp = sobj_at(BOULDER, sx, sy)) != 0) { + /* another boulder here, restack it to the top */ + obj_extract_self(otmp); + place_object(otmp, sx, sy); + } + } else { + struct trap *trap; - if ((trap = t_at(sx,sy)) && trap->ttyp == STATUE_TRAP) - deltrap(trap); - pline("%s.", Tobjnam(otmp, "crumble")); - (void) break_statue(otmp); - place_object(otmp, sx, sy); /* put fragments on floor */ - } - used_up = TRUE; + if ((trap = t_at(sx, sy)) && trap->ttyp == STATUE_TRAP) + deltrap(trap); + pline("%s.", Tobjnam(otmp, "crumble")); + (void) break_statue(otmp); + place_object(otmp, sx, sy); /* put fragments on floor */ + } + used_up = TRUE; - /* 1 in 10 chance of destruction of obj; glass, egg destruction */ - } else if ((scflags & MAY_DESTROY) && (!rn2(10) - || (objects[otmp->otyp].oc_material == GLASS - || otmp->otyp == EGG))) { - if (breaks(otmp, (xchar)sx, (xchar)sy)) used_up = TRUE; - } + /* 1 in 10 chance of destruction of obj; glass, egg destruction */ + } else if ((scflags & MAY_DESTROY) + && (!rn2(10) || (objects[otmp->otyp].oc_material == GLASS + || otmp->otyp == EGG))) { + if (breaks(otmp, (xchar) sx, (xchar) sy)) + used_up = TRUE; + } - if (!used_up) { - stmp = (struct scatter_chain *) - alloc(sizeof(struct scatter_chain)); - stmp->next = (struct scatter_chain *)0; - stmp->obj = otmp; - stmp->ox = sx; - stmp->oy = sy; - tmp = rn2(8); /* get the direction */ - stmp->dx = xdir[tmp]; - stmp->dy = ydir[tmp]; - tmp = blastforce - (otmp->owt/40); - if (tmp < 1) tmp = 1; - stmp->range = rnd(tmp); /* anywhere up to that determ. by wt */ - if (farthest < stmp->range) farthest = stmp->range; - stmp->stopped = FALSE; - if (!schain) - schain = stmp; - else - stmp2->next = stmp; - stmp2 = stmp; - } - } + if (!used_up) { + stmp = + (struct scatter_chain *) alloc(sizeof(struct scatter_chain)); + stmp->next = (struct scatter_chain *) 0; + stmp->obj = otmp; + stmp->ox = sx; + stmp->oy = sy; + tmp = rn2(8); /* get the direction */ + stmp->dx = xdir[tmp]; + stmp->dy = ydir[tmp]; + tmp = blastforce - (otmp->owt / 40); + if (tmp < 1) + tmp = 1; + stmp->range = rnd(tmp); /* anywhere up to that determ. by wt */ + if (farthest < stmp->range) + farthest = stmp->range; + stmp->stopped = FALSE; + if (!schain) + schain = stmp; + else + stmp2->next = stmp; + stmp2 = stmp; + } + } - while (farthest-- > 0) { - for (stmp = schain; stmp; stmp = stmp->next) { - if ((stmp->range-- > 0) && (!stmp->stopped)) { - bhitpos.x = stmp->ox + stmp->dx; - bhitpos.y = stmp->oy + stmp->dy; - typ = levl[bhitpos.x][bhitpos.y].typ; - if(!isok(bhitpos.x, bhitpos.y)) { - bhitpos.x -= stmp->dx; - bhitpos.y -= stmp->dy; - stmp->stopped = TRUE; - } else if(!ZAP_POS(typ) || - closed_door(bhitpos.x, bhitpos.y)) { - bhitpos.x -= stmp->dx; - bhitpos.y -= stmp->dy; - stmp->stopped = TRUE; - } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { - if (scflags & MAY_HITMON) { - stmp->range--; - if (ohitmon(mtmp, stmp->obj, 1, FALSE)) { - stmp->obj = (struct obj *)0; - stmp->stopped = TRUE; - } - } - } else if (bhitpos.x==u.ux && bhitpos.y==u.uy) { - if (scflags & MAY_HITYOU) { - int hitvalu, hitu; + while (farthest-- > 0) { + for (stmp = schain; stmp; stmp = stmp->next) { + if ((stmp->range-- > 0) && (!stmp->stopped)) { + bhitpos.x = stmp->ox + stmp->dx; + bhitpos.y = stmp->oy + stmp->dy; + typ = levl[bhitpos.x][bhitpos.y].typ; + if (!isok(bhitpos.x, bhitpos.y)) { + bhitpos.x -= stmp->dx; + bhitpos.y -= stmp->dy; + stmp->stopped = TRUE; + } else if (!ZAP_POS(typ) + || closed_door(bhitpos.x, bhitpos.y)) { + bhitpos.x -= stmp->dx; + bhitpos.y -= stmp->dy; + stmp->stopped = TRUE; + } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { + if (scflags & MAY_HITMON) { + stmp->range--; + if (ohitmon(mtmp, stmp->obj, 1, FALSE)) { + stmp->obj = (struct obj *) 0; + stmp->stopped = TRUE; + } + } + } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { + if (scflags & MAY_HITYOU) { + int hitvalu, hitu; - if (multi) nomul(0); - hitvalu = 8 + stmp->obj->spe; - if (bigmonst(youmonst.data)) hitvalu++; - hitu = thitu(hitvalu, - dmgval(stmp->obj, &youmonst), - stmp->obj, (char *)0); - if (hitu) { - stmp->range -= 3; - stop_occupation(); - } - } - } else { - if (scflags & VIS_EFFECTS) { - /* tmp_at(bhitpos.x, bhitpos.y); */ - /* delay_output(); */ - } - } - stmp->ox = bhitpos.x; - stmp->oy = bhitpos.y; - } - } - } - for (stmp = schain; stmp; stmp = stmp2) { - int x,y; + if (multi) + nomul(0); + hitvalu = 8 + stmp->obj->spe; + if (bigmonst(youmonst.data)) + hitvalu++; + hitu = thitu(hitvalu, dmgval(stmp->obj, &youmonst), + stmp->obj, (char *) 0); + if (hitu) { + stmp->range -= 3; + stop_occupation(); + } + } + } else { + if (scflags & VIS_EFFECTS) { + /* tmp_at(bhitpos.x, bhitpos.y); */ + /* delay_output(); */ + } + } + stmp->ox = bhitpos.x; + stmp->oy = bhitpos.y; + } + } + } + for (stmp = schain; stmp; stmp = stmp2) { + int x, y; - stmp2 = stmp->next; - x = stmp->ox; y = stmp->oy; - if (stmp->obj) { - if ( x!=sx || y!=sy ) - total += stmp->obj->quan; - place_object(stmp->obj, x, y); - stackobj(stmp->obj); - } - free((genericptr_t)stmp); - newsym(x,y); - } + stmp2 = stmp->next; + x = stmp->ox; + y = stmp->oy; + if (stmp->obj) { + if (x != sx || y != sy) + total += stmp->obj->quan; + place_object(stmp->obj, x, y); + stackobj(stmp->obj); + } + free((genericptr_t) stmp); + newsym(x, y); + } - return total; + return total; } - /* * Splatter burning oil from x,y to the surrounding area. * @@ -632,11 +692,11 @@ struct obj *obj; /* only scatter this obj */ */ void splatter_burning_oil(x, y) - int x, y; +int x, y; { /* ZT_SPELL(ZT_FIRE) = ZT_SPELL(AD_FIRE-1) = 10+(2-1) = 11 */ #define ZT_SPELL_O_FIRE 11 /* value kludge, see zap.c */ - explode(x, y, ZT_SPELL_O_FIRE, d(4,4), BURNING_OIL, EXPL_FIERY); + explode(x, y, ZT_SPELL_O_FIRE, d(4, 4), BURNING_OIL, EXPL_FIERY); } /* lit potion of oil is exploding; extinguish it as a light source before @@ -646,7 +706,8 @@ explode_oil(obj, x, y) struct obj *obj; int x, y; { - if (!obj->lamplit) impossible("exploding unlit oil"); + if (!obj->lamplit) + impossible("exploding unlit oil"); end_burn(obj, TRUE); splatter_burning_oil(x, y); } diff --git a/src/extralev.c b/src/extralev.c index 48dc4c737..7eeaf398c 100644 --- a/src/extralev.c +++ b/src/extralev.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 extralev.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 extralev.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 extralev.c $Date: 2010/01/10 02:35:19 $ $Revision: 1.5 $ */ /* Copyright 1988, 1989 by Ken Arromdee */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,11 +10,11 @@ #include "hack.h" struct rogueroom { - xchar rlx, rly; - xchar dx, dy; - boolean real; - uchar doortable; - int nroom; /* Only meaningful for "real" rooms */ + xchar rlx, rly; + xchar dx, dy; + boolean real; + uchar doortable; + int nroom; /* Only meaningful for "real" rooms */ }; #define UP 1 #define DOWN 2 @@ -22,317 +22,347 @@ struct rogueroom { #define RIGHT 8 static NEARDATA struct rogueroom r[3][3]; -STATIC_DCL void FDECL(roguejoin,(int,int,int,int,int)); -STATIC_DCL void FDECL(roguecorr,(int,int,int)); -STATIC_DCL void FDECL(miniwalk,(int,int)); +STATIC_DCL void FDECL(roguejoin, (int, int, int, int, int)); +STATIC_DCL void FDECL(roguecorr, (int, int, int)); +STATIC_DCL void FDECL(miniwalk, (int, int)); STATIC_OVL void -roguejoin(x1,y1,x2,y2, horiz) -int x1,y1,x2,y2; +roguejoin(x1, y1, x2, y2, horiz) +int x1, y1, x2, y2; int horiz; { - register int x,y,middle; - if (horiz) { - middle = x1 + rn2(x2-x1+1); - for(x=min(x1,middle); x<=max(x1,middle); x++) - corr(x, y1); - for(y=min(y1,y2); y<=max(y1,y2); y++) - corr(middle,y); - for(x=min(middle,x2); x<=max(middle,x2); x++) - corr(x, y2); - } else { - middle = y1 + rn2(y2-y1+1); - for(y=min(y1,middle); y<=max(y1,middle); y++) - corr(x1, y); - for(x=min(x1,x2); x<=max(x1,x2); x++) - corr(x, middle); - for(y=min(middle,y2); y<=max(middle,y2); y++) - corr(x2,y); - } + register int x, y, middle; + if (horiz) { + middle = x1 + rn2(x2 - x1 + 1); + for (x = min(x1, middle); x <= max(x1, middle); x++) + corr(x, y1); + for (y = min(y1, y2); y <= max(y1, y2); y++) + corr(middle, y); + for (x = min(middle, x2); x <= max(middle, x2); x++) + corr(x, y2); + } else { + middle = y1 + rn2(y2 - y1 + 1); + for (y = min(y1, middle); y <= max(y1, middle); y++) + corr(x1, y); + for (x = min(x1, x2); x <= max(x1, x2); x++) + corr(x, middle); + for (y = min(middle, y2); y <= max(middle, y2); y++) + corr(x2, y); + } } STATIC_OVL void roguecorr(x, y, dir) -int x,y,dir; +int x, y, dir; { - register int fromx, fromy, tox, toy; + register int fromx, fromy, tox, toy; - if (dir==DOWN) { - r[x][y].doortable &= ~DOWN; - if (!r[x][y].real) { - fromx = r[x][y].rlx; fromy = r[x][y].rly; - fromx += 1 + 26*x; fromy += 7*y; - } else { - fromx = r[x][y].rlx + rn2(r[x][y].dx); - fromy = r[x][y].rly + r[x][y].dy; - fromx += 1 + 26*x; fromy += 7*y; - if (!IS_WALL(levl[fromx][fromy].typ)) - impossible("down: no wall at %d,%d?",fromx, - fromy); - dodoor(fromx, fromy, &rooms[r[x][y].nroom]); - levl[fromx][fromy].doormask = D_NODOOR; - fromy++; - } - if(y >= 2) { - impossible("down door from %d,%d going nowhere?",x,y); - return; - } - y++; - r[x][y].doortable &= ~UP; - if (!r[x][y].real) { - tox = r[x][y].rlx; toy = r[x][y].rly; - tox += 1 + 26*x; toy += 7*y; - } else { - tox = r[x][y].rlx + rn2(r[x][y].dx); - toy = r[x][y].rly - 1; - tox += 1 + 26*x; toy += 7*y; - if (!IS_WALL(levl[tox][toy].typ)) - impossible("up: no wall at %d,%d?",tox,toy); - dodoor(tox, toy, &rooms[r[x][y].nroom]); - levl[tox][toy].doormask = D_NODOOR; - toy--; - } - roguejoin(fromx, fromy, tox, toy, FALSE); - return; - } else if (dir == RIGHT) { - r[x][y].doortable &= ~RIGHT; - if (!r[x][y].real) { - fromx = r[x][y].rlx; fromy = r[x][y].rly; - fromx += 1 + 26*x; fromy += 7*y; - } else { - fromx = r[x][y].rlx + r[x][y].dx; - fromy = r[x][y].rly + rn2(r[x][y].dy); - fromx += 1 + 26*x; fromy += 7*y; - if (!IS_WALL(levl[fromx][fromy].typ)) - impossible("down: no wall at %d,%d?",fromx, - fromy); - dodoor(fromx, fromy, &rooms[r[x][y].nroom]); - levl[fromx][fromy].doormask = D_NODOOR; - fromx++; - } - if(x >= 2) { - impossible("right door from %d,%d going nowhere?",x,y); - return; - } - x++; - r[x][y].doortable &= ~LEFT; - if (!r[x][y].real) { - tox = r[x][y].rlx; toy = r[x][y].rly; - tox += 1 + 26*x; toy += 7*y; - } else { - tox = r[x][y].rlx - 1; - toy = r[x][y].rly + rn2(r[x][y].dy); - tox += 1 + 26*x; toy += 7*y; - if (!IS_WALL(levl[tox][toy].typ)) - impossible("left: no wall at %d,%d?",tox,toy); - dodoor(tox, toy, &rooms[r[x][y].nroom]); - levl[tox][toy].doormask = D_NODOOR; - tox--; - } - roguejoin(fromx, fromy, tox, toy, TRUE); - return; - } else impossible("corridor in direction %d?",dir); + if (dir == DOWN) { + r[x][y].doortable &= ~DOWN; + if (!r[x][y].real) { + fromx = r[x][y].rlx; + fromy = r[x][y].rly; + fromx += 1 + 26 * x; + fromy += 7 * y; + } else { + fromx = r[x][y].rlx + rn2(r[x][y].dx); + fromy = r[x][y].rly + r[x][y].dy; + fromx += 1 + 26 * x; + fromy += 7 * y; + if (!IS_WALL(levl[fromx][fromy].typ)) + impossible("down: no wall at %d,%d?", fromx, fromy); + dodoor(fromx, fromy, &rooms[r[x][y].nroom]); + levl[fromx][fromy].doormask = D_NODOOR; + fromy++; + } + if (y >= 2) { + impossible("down door from %d,%d going nowhere?", x, y); + return; + } + y++; + r[x][y].doortable &= ~UP; + if (!r[x][y].real) { + tox = r[x][y].rlx; + toy = r[x][y].rly; + tox += 1 + 26 * x; + toy += 7 * y; + } else { + tox = r[x][y].rlx + rn2(r[x][y].dx); + toy = r[x][y].rly - 1; + tox += 1 + 26 * x; + toy += 7 * y; + if (!IS_WALL(levl[tox][toy].typ)) + impossible("up: no wall at %d,%d?", tox, toy); + dodoor(tox, toy, &rooms[r[x][y].nroom]); + levl[tox][toy].doormask = D_NODOOR; + toy--; + } + roguejoin(fromx, fromy, tox, toy, FALSE); + return; + } else if (dir == RIGHT) { + r[x][y].doortable &= ~RIGHT; + if (!r[x][y].real) { + fromx = r[x][y].rlx; + fromy = r[x][y].rly; + fromx += 1 + 26 * x; + fromy += 7 * y; + } else { + fromx = r[x][y].rlx + r[x][y].dx; + fromy = r[x][y].rly + rn2(r[x][y].dy); + fromx += 1 + 26 * x; + fromy += 7 * y; + if (!IS_WALL(levl[fromx][fromy].typ)) + impossible("down: no wall at %d,%d?", fromx, fromy); + dodoor(fromx, fromy, &rooms[r[x][y].nroom]); + levl[fromx][fromy].doormask = D_NODOOR; + fromx++; + } + if (x >= 2) { + impossible("right door from %d,%d going nowhere?", x, y); + return; + } + x++; + r[x][y].doortable &= ~LEFT; + if (!r[x][y].real) { + tox = r[x][y].rlx; + toy = r[x][y].rly; + tox += 1 + 26 * x; + toy += 7 * y; + } else { + tox = r[x][y].rlx - 1; + toy = r[x][y].rly + rn2(r[x][y].dy); + tox += 1 + 26 * x; + toy += 7 * y; + if (!IS_WALL(levl[tox][toy].typ)) + impossible("left: no wall at %d,%d?", tox, toy); + dodoor(tox, toy, &rooms[r[x][y].nroom]); + levl[tox][toy].doormask = D_NODOOR; + tox--; + } + roguejoin(fromx, fromy, tox, toy, TRUE); + return; + } else + impossible("corridor in direction %d?", dir); } /* Modified walkfrom() from mkmaze.c */ STATIC_OVL void miniwalk(x, y) -int x,y; -{ - register int q, dir; - int dirs[4]; - - while(1) { - q = 0; -#define doorhere (r[x][y].doortable) - if (x>0 && (!(doorhere & LEFT)) && - (!r[x-1][y].doortable || !rn2(10))) - dirs[q++] = 0; - if (x<2 && (!(doorhere & RIGHT)) && - (!r[x+1][y].doortable || !rn2(10))) - dirs[q++] = 1; - if (y>0 && (!(doorhere & UP)) && - (!r[x][y-1].doortable || !rn2(10))) - dirs[q++] = 2; - if (y<2 && (!(doorhere & DOWN)) && - (!r[x][y+1].doortable || !rn2(10))) - dirs[q++] = 3; - /* Rogue levels aren't just 3 by 3 mazes; they have some extra - * connections, thus that 1/10 chance - */ - if (!q) return; - dir = dirs[rn2(q)]; - switch(dir) { /* Move in direction */ - case 0: doorhere |= LEFT; - x--; - doorhere |= RIGHT; - break; - case 1: doorhere |= RIGHT; - x++; - doorhere |= LEFT; - break; - case 2: doorhere |= UP; - y--; - doorhere |= DOWN; - break; - case 3: doorhere |= DOWN; - y++; - doorhere |= UP; - break; - } - miniwalk(x,y); - } -} - -void -makeroguerooms() { - register int x,y; - /* Rogue levels are structured 3 by 3, with each section containing - * a room or an intersection. The minimum width is 2 each way. - * One difference between these and "real" Rogue levels: real Rogue - * uses 24 rows and NetHack only 23. So we cheat a bit by making the - * second row of rooms not as deep. - * - * Each normal space has 6/7 rows and 25 columns in which a room may - * actually be placed. Walls go from rows 0-5/6 and columns 0-24. - * Not counting walls, the room may go in - * rows 1-5 and columns 1-23 (numbering starting at 0). A room - * coordinate of this type may be converted to a level coordinate - * by adding 1+28*x to the column, and 7*y to the row. (The 1 - * is because column 0 isn't used [we only use 1-78]). - * Room height may be 2-4 (2-5 on last row), length 2-23 (not - * counting walls) - */ -#define here r[x][y] - - nroom = 0; - for(y=0; y<3; y++) for(x=0; x<3; x++) { - /* Note: we want to insure at least 1 room. So, if the - * first 8 are all dummies, force the last to be a room. - */ - if (!rn2(5) && (nroom || (x<2 && y<2))) { - /* Arbitrary: dummy rooms may only go where real - * ones do. - */ - here.real = FALSE; - here.rlx = rn1(22, 2); - here.rly = rn1((y==2)?4:3, 2); - } else { - here.real = TRUE; - here.dx = rn1(22, 2); /* 2-23 long, plus walls */ - here.dy = rn1((y==2)?4:3, 2); /* 2-5 high, plus walls */ - - /* boundaries of room floor */ - here.rlx = rnd(23 - here.dx + 1); - here.rly = rnd(((y==2) ? 5 : 4)- here.dy + 1); - nroom++; - } - here.doortable = 0; - } - miniwalk(rn2(3), rn2(3)); - nroom = 0; - for(y=0; y<3; y++) for(x=0; x<3; x++) { - if (here.real) { /* Make a room */ - int lowx, lowy, hix, hiy; - - r[x][y].nroom = nroom; - smeq[nroom] = nroom; - - lowx = 1 + 26*x + here.rlx; - lowy = 7*y + here.rly; - hix = 1 + 26*x + here.rlx + here.dx - 1; - hiy = 7*y + here.rly + here.dy - 1; - /* Strictly speaking, it should be lit only if above - * level 10, but since Rogue rooms are only - * encountered below level 10, use !rn2(7). - */ - add_room(lowx, lowy, hix, hiy, - (boolean) !rn2(7), OROOM, FALSE); - } - } - - /* Now, add connecting corridors. */ - for(y=0; y<3; y++) for(x=0; x<3; x++) { - if (here.doortable & DOWN) - roguecorr(x, y, DOWN); - if (here.doortable & RIGHT) - roguecorr(x, y, RIGHT); - if (here.doortable & LEFT) - impossible ("left end of %d, %d never connected?",x,y); - if (here.doortable & UP) - impossible ("up end of %d, %d never connected?",x,y); - } -} - -void -corr(x,y) int x, y; { - if (rn2(50)) { - levl[x][y].typ = CORR; - } else { - levl[x][y].typ = SCORR; - } + register int q, dir; + int dirs[4]; + + while (1) { + q = 0; +#define doorhere (r[x][y].doortable) + if (x > 0 && (!(doorhere & LEFT)) + && (!r[x - 1][y].doortable || !rn2(10))) + dirs[q++] = 0; + if (x < 2 && (!(doorhere & RIGHT)) + && (!r[x + 1][y].doortable || !rn2(10))) + dirs[q++] = 1; + if (y > 0 && (!(doorhere & UP)) + && (!r[x][y - 1].doortable || !rn2(10))) + dirs[q++] = 2; + if (y < 2 && (!(doorhere & DOWN)) + && (!r[x][y + 1].doortable || !rn2(10))) + dirs[q++] = 3; + /* Rogue levels aren't just 3 by 3 mazes; they have some extra + * connections, thus that 1/10 chance + */ + if (!q) + return; + dir = dirs[rn2(q)]; + switch (dir) { /* Move in direction */ + case 0: + doorhere |= LEFT; + x--; + doorhere |= RIGHT; + break; + case 1: + doorhere |= RIGHT; + x++; + doorhere |= LEFT; + break; + case 2: + doorhere |= UP; + y--; + doorhere |= DOWN; + break; + case 3: + doorhere |= DOWN; + y++; + doorhere |= UP; + break; + } + miniwalk(x, y); + } +} + +void +makeroguerooms() +{ + register int x, y; +/* Rogue levels are structured 3 by 3, with each section containing + * a room or an intersection. The minimum width is 2 each way. + * One difference between these and "real" Rogue levels: real Rogue + * uses 24 rows and NetHack only 23. So we cheat a bit by making the + * second row of rooms not as deep. + * + * Each normal space has 6/7 rows and 25 columns in which a room may + * actually be placed. Walls go from rows 0-5/6 and columns 0-24. + * Not counting walls, the room may go in + * rows 1-5 and columns 1-23 (numbering starting at 0). A room + * coordinate of this type may be converted to a level coordinate + * by adding 1+28*x to the column, and 7*y to the row. (The 1 + * is because column 0 isn't used [we only use 1-78]). + * Room height may be 2-4 (2-5 on last row), length 2-23 (not + * counting walls) + */ +#define here r[x][y] + + nroom = 0; + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) { + /* Note: we want to insure at least 1 room. So, if the + * first 8 are all dummies, force the last to be a room. + */ + if (!rn2(5) && (nroom || (x < 2 && y < 2))) { + /* Arbitrary: dummy rooms may only go where real + * ones do. + */ + here.real = FALSE; + here.rlx = rn1(22, 2); + here.rly = rn1((y == 2) ? 4 : 3, 2); + } else { + here.real = TRUE; + here.dx = rn1(22, 2); /* 2-23 long, plus walls */ + here.dy = rn1((y == 2) ? 4 : 3, 2); /* 2-5 high, plus walls */ + + /* boundaries of room floor */ + here.rlx = rnd(23 - here.dx + 1); + here.rly = rnd(((y == 2) ? 5 : 4) - here.dy + 1); + nroom++; + } + here.doortable = 0; + } + miniwalk(rn2(3), rn2(3)); + nroom = 0; + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) { + if (here.real) { /* Make a room */ + int lowx, lowy, hix, hiy; + + r[x][y].nroom = nroom; + smeq[nroom] = nroom; + + lowx = 1 + 26 * x + here.rlx; + lowy = 7 * y + here.rly; + hix = 1 + 26 * x + here.rlx + here.dx - 1; + hiy = 7 * y + here.rly + here.dy - 1; + /* Strictly speaking, it should be lit only if above + * level 10, but since Rogue rooms are only + * encountered below level 10, use !rn2(7). + */ + add_room(lowx, lowy, hix, hiy, (boolean) !rn2(7), OROOM, + FALSE); + } + } + + /* Now, add connecting corridors. */ + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) { + if (here.doortable & DOWN) + roguecorr(x, y, DOWN); + if (here.doortable & RIGHT) + roguecorr(x, y, RIGHT); + if (here.doortable & LEFT) + impossible("left end of %d, %d never connected?", x, y); + if (here.doortable & UP) + impossible("up end of %d, %d never connected?", x, y); + } +} + +void +corr(x, y) +int x, y; +{ + if (rn2(50)) { + levl[x][y].typ = CORR; + } else { + levl[x][y].typ = SCORR; + } } void makerogueghost() { - register struct monst *ghost; - struct obj *ghostobj; - struct mkroom *croom; - int x,y; + register struct monst *ghost; + struct obj *ghostobj; + struct mkroom *croom; + int x, y; - if (!nroom) return; /* Should never happen */ - croom = &rooms[rn2(nroom)]; - x = somex(croom); y = somey(croom); - if (!(ghost = makemon(&mons[PM_GHOST], x, y, NO_MM_FLAGS))) - return; - ghost->msleeping = 1; - ghost = christen_monst(ghost, roguename()); + if (!nroom) + return; /* Should never happen */ + croom = &rooms[rn2(nroom)]; + x = somex(croom); + y = somey(croom); + if (!(ghost = makemon(&mons[PM_GHOST], x, y, NO_MM_FLAGS))) + return; + ghost->msleeping = 1; + ghost = christen_monst(ghost, roguename()); - if (rn2(4)) { - ghostobj = mksobj_at(FOOD_RATION, x, y, FALSE, FALSE); - ghostobj->quan = (long) rnd(7); - ghostobj->owt = weight(ghostobj); - } - if (rn2(2)) { - ghostobj = mksobj_at(MACE, x, y, FALSE, FALSE); - ghostobj->spe = rnd(3); - if (rn2(4)) curse(ghostobj); - } else { - ghostobj = mksobj_at(TWO_HANDED_SWORD, x, y, FALSE, FALSE); - ghostobj->spe = rnd(5) - 2; - if (rn2(4)) curse(ghostobj); - } - ghostobj = mksobj_at(BOW, x, y, FALSE, FALSE); - ghostobj->spe = 1; - if (rn2(4)) curse(ghostobj); + if (rn2(4)) { + ghostobj = mksobj_at(FOOD_RATION, x, y, FALSE, FALSE); + ghostobj->quan = (long) rnd(7); + ghostobj->owt = weight(ghostobj); + } + if (rn2(2)) { + ghostobj = mksobj_at(MACE, x, y, FALSE, FALSE); + ghostobj->spe = rnd(3); + if (rn2(4)) + curse(ghostobj); + } else { + ghostobj = mksobj_at(TWO_HANDED_SWORD, x, y, FALSE, FALSE); + ghostobj->spe = rnd(5) - 2; + if (rn2(4)) + curse(ghostobj); + } + ghostobj = mksobj_at(BOW, x, y, FALSE, FALSE); + ghostobj->spe = 1; + if (rn2(4)) + curse(ghostobj); - ghostobj = mksobj_at(ARROW, x, y, FALSE, FALSE); - ghostobj->spe = 0; - ghostobj->quan = (long) rn1(10,25); - ghostobj->owt = weight(ghostobj); - if (rn2(4)) curse(ghostobj); + ghostobj = mksobj_at(ARROW, x, y, FALSE, FALSE); + ghostobj->spe = 0; + ghostobj->quan = (long) rn1(10, 25); + ghostobj->owt = weight(ghostobj); + if (rn2(4)) + curse(ghostobj); - if (rn2(2)) { - ghostobj = mksobj_at(RING_MAIL, x, y, FALSE, FALSE); - ghostobj->spe = rn2(3); - if (!rn2(3)) ghostobj->oerodeproof = TRUE; - if (rn2(4)) curse(ghostobj); - } else { - ghostobj = mksobj_at(PLATE_MAIL, x, y, FALSE, FALSE); - ghostobj->spe = rnd(5) - 2; - if (!rn2(3)) ghostobj->oerodeproof = TRUE; - if (rn2(4)) curse(ghostobj); - } - if (rn2(2)) { - ghostobj = mksobj_at(FAKE_AMULET_OF_YENDOR, x, y, TRUE, FALSE); - ghostobj->known = TRUE; - } + if (rn2(2)) { + ghostobj = mksobj_at(RING_MAIL, x, y, FALSE, FALSE); + ghostobj->spe = rn2(3); + if (!rn2(3)) + ghostobj->oerodeproof = TRUE; + if (rn2(4)) + curse(ghostobj); + } else { + ghostobj = mksobj_at(PLATE_MAIL, x, y, FALSE, FALSE); + ghostobj->spe = rnd(5) - 2; + if (!rn2(3)) + ghostobj->oerodeproof = TRUE; + if (rn2(4)) + curse(ghostobj); + } + if (rn2(2)) { + ghostobj = mksobj_at(FAKE_AMULET_OF_YENDOR, x, y, TRUE, FALSE); + ghostobj->known = TRUE; + } } /*extralev.c*/ diff --git a/src/files.c b/src/files.c index fdc8eebde..5ba61c28c 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 files.c $NHDT-Date: 1429953063 2015/04/25 09:11:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.166 $ */ +/* NetHack 3.6 files.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.172 $ */ /* NetHack 3.6 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,34 +10,35 @@ #include "wintty.h" /* more() */ #endif -#if (!defined(MAC) && !defined(O_WRONLY) && !defined(AZTEC_C)) || defined(USE_FCNTL) +#if (!defined(MAC) && !defined(O_WRONLY) && !defined(AZTEC_C)) \ + || defined(USE_FCNTL) #include #endif #include -#ifdef _MSC_VER /* MSC 6.0 defines errno quite differently */ -# if (_MSC_VER >= 600) -# define SKIP_ERRNO -# endif +#ifdef _MSC_VER /* MSC 6.0 defines errno quite differently */ +#if (_MSC_VER >= 600) +#define SKIP_ERRNO +#endif #else -# ifdef NHSTDC -# define SKIP_ERRNO -# endif +#ifdef NHSTDC +#define SKIP_ERRNO +#endif #endif #ifndef SKIP_ERRNO -# ifdef _DCC +#ifdef _DCC const -# endif -extern int errno; +#endif + extern int errno; #endif -#ifdef ZLIB_COMP /* RLC 09 Mar 1999: Support internal ZLIB */ +#ifdef ZLIB_COMP /* RLC 09 Mar 1999: Support internal ZLIB */ #include "zlib.h" -# ifndef COMPRESS_EXTENSION +#ifndef COMPRESS_EXTENSION #define COMPRESS_EXTENSION ".gz" -# endif #endif - +#endif + #if defined(UNIX) && defined(QT_GRAPHICS) #include #include @@ -49,14 +50,14 @@ extern int errno; #endif #if defined(MSDOS) || defined(OS2) || defined(TOS) || defined(WIN32) -# ifndef GNUDOS +#ifndef GNUDOS #include -# else +#else #include -# endif #endif -#ifndef O_BINARY /* used for micros, no-op for others */ -# define O_BINARY 0 +#endif +#ifndef O_BINARY /* used for micros, no-op for others */ +#define O_BINARY 0 #endif #ifdef PREFIXES_IN_USE @@ -66,60 +67,60 @@ static char fqn_filename_buffer[FQN_NUMBUF][FQN_MAX_FILENAME]; #if !defined(MFLOPPY) && !defined(VMS) && !defined(WIN32) char bones[] = "bonesnn.xxx"; -char lock[PL_NSIZ+14] = "1lock"; /* long enough for uid+name+.99 */ +char lock[PL_NSIZ + 14] = "1lock"; /* long enough for uid+name+.99 */ #else -# if defined(MFLOPPY) -char bones[FILENAME]; /* pathname of bones files */ -char lock[FILENAME]; /* pathname of level files */ -# endif -# if defined(VMS) +#if defined(MFLOPPY) +char bones[FILENAME]; /* pathname of bones files */ +char lock[FILENAME]; /* pathname of level files */ +#endif +#if defined(VMS) char bones[] = "bonesnn.xxx;1"; -char lock[PL_NSIZ+17] = "1lock"; /* long enough for _uid+name+.99;1 */ -# endif -# if defined(WIN32) +char lock[PL_NSIZ + 17] = "1lock"; /* long enough for _uid+name+.99;1 */ +#endif +#if defined(WIN32) char bones[] = "bonesnn.xxx"; -char lock[PL_NSIZ+25]; /* long enough for username+-+name+.99 */ -# endif +char lock[PL_NSIZ + 25]; /* long enough for username+-+name+.99 */ +#endif #endif #if defined(UNIX) || defined(__BEOS__) -#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */ +#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */ #else -# ifdef VMS -#define SAVESIZE (PL_NSIZ + 22) /* [.save]player.e;1 */ -# else -# if defined(WIN32) -#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */ -# else -#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */ -# endif -# endif +#ifdef VMS +#define SAVESIZE (PL_NSIZ + 22) /* [.save]player.e;1 */ +#else +#if defined(WIN32) +#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */ +#else +#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */ +#endif +#endif #endif #if !defined(SAVE_EXTENSION) -# ifdef MICRO -#define SAVE_EXTENSION ".sav" -# endif -# ifdef WIN32 -#define SAVE_EXTENSION ".NetHack-saved-game" -# endif +#ifdef MICRO +#define SAVE_EXTENSION ".sav" +#endif +#ifdef WIN32 +#define SAVE_EXTENSION ".NetHack-saved-game" +#endif #endif -char SAVEF[SAVESIZE]; /* holds relative path of save file from playground */ +char SAVEF[SAVESIZE]; /* holds relative path of save file from playground */ #ifdef MICRO -char SAVEP[SAVESIZE]; /* holds path of directory for save file */ +char SAVEP[SAVESIZE]; /* holds path of directory for save file */ #endif #ifdef HOLD_LOCKFILE_OPEN struct level_ftrack { -int init; -int fd; /* file descriptor for level file */ -int oflag; /* open flags */ -boolean nethack_thinks_it_is_open; /* Does NetHack think it's open? */ + int init; + int fd; /* file descriptor for level file */ + int oflag; /* open flags */ + boolean nethack_thinks_it_is_open; /* Does NetHack think it's open? */ } lftrack; -# if defined(WIN32) +#if defined(WIN32) #include -# endif +#endif #endif /*HOLD_LOCKFILE_OPEN*/ #define WIZKIT_MAX 128 @@ -128,22 +129,22 @@ STATIC_DCL FILE *NDECL(fopen_wizkit_file); STATIC_DCL void FDECL(wizkit_addinv, (struct obj *)); #ifdef AMIGA -extern char PATH[]; /* see sys/amiga/amidos.c */ +extern char PATH[]; /* see sys/amiga/amidos.c */ extern char bbs_id[]; static int lockptr; -# ifdef __SASC_60 +#ifdef __SASC_60 #include -# endif +#endif #include -extern void FDECL(amii_set_text_font, ( char *, int )); +extern void FDECL(amii_set_text_font, (char *, int)); #endif #if defined(WIN32) || defined(MSDOS) static int lockptr; -# ifdef MSDOS +#ifdef MSDOS #define Delay(a) msleep(a) -# endif +#endif #define Close close #ifndef WIN_CE #define DeleteFile unlink @@ -151,19 +152,20 @@ static int lockptr; #endif #ifdef MAC -# undef unlink -# define unlink macunlink +#undef unlink +#define unlink macunlink #endif -#if (defined(macintosh) && (defined(__SC__) || defined(__MRC__))) || defined(__MWERKS__) -# define PRAGMA_UNUSED +#if (defined(macintosh) && (defined(__SC__) || defined(__MRC__))) \ + || defined(__MWERKS__) +#define PRAGMA_UNUSED #endif #ifdef USER_SOUNDS extern char *sounddir; #endif -extern int n_dgns; /* from dungeon.c */ +extern int n_dgns; /* from dungeon.c */ #if defined(UNIX) && defined(QT_GRAPHICS) #define SELECTSAVED @@ -172,26 +174,27 @@ extern int n_dgns; /* from dungeon.c */ #ifdef SELECTSAVED STATIC_DCL int FDECL(strcmp_wrap, (const void *, const void *)); #endif -STATIC_DCL char *FDECL(set_bonesfile_name, (char *,d_level*)); +STATIC_DCL char *FDECL(set_bonesfile_name, (char *, d_level *)); STATIC_DCL char *NDECL(set_bonestemp_name); #ifdef COMPRESS -STATIC_DCL void FDECL(redirect, (const char *,const char *,FILE *,BOOLEAN_P)); +STATIC_DCL void FDECL(redirect, + (const char *, const char *, FILE *, BOOLEAN_P)); #endif #if defined(COMPRESS) || defined(ZLIB_COMP) -STATIC_DCL void FDECL(docompress_file, (const char *,BOOLEAN_P)); +STATIC_DCL void FDECL(docompress_file, (const char *, BOOLEAN_P)); #endif #if defined(ZLIB_COMP) STATIC_DCL boolean FDECL(make_compressed_name, (const char *, char *)); #endif #ifndef USE_FCNTL -STATIC_DCL char *FDECL(make_lockname, (const char *,char *)); +STATIC_DCL char *FDECL(make_lockname, (const char *, char *)); #endif STATIC_DCL FILE *FDECL(fopen_config_file, (const char *, int)); -STATIC_DCL int FDECL(get_uchars, - (FILE *,char *,char *,uchar *,BOOLEAN_P,int,const char *)); -int FDECL(parse_config_line, (FILE *,char *,int)); +STATIC_DCL int FDECL(get_uchars, (FILE *, char *, char *, uchar *, BOOLEAN_P, + int, const char *)); +int FDECL(parse_config_line, (FILE *, char *, int)); STATIC_DCL FILE *NDECL(fopen_sym_file); -STATIC_DCL void FDECL(set_symhandling, (char *,int)); +STATIC_DCL void FDECL(set_symhandling, (char *, int)); #ifdef NOCWD_ASSUMPTIONS STATIC_DCL void FDECL(adjust_prefix, (char *, int)); #endif @@ -206,15 +209,18 @@ STATIC_DCL int FDECL(open_levelfile_exclusively, (const char *, int, int)); * fname_encode() * * Args: - * legal zero-terminated list of acceptable file name characters - * quotechar lead-in character used to quote illegal characters as hex digits + * legal zero-terminated list of acceptable file name + *characters + * quotechar lead-in character used to quote illegal characters as + *hex digits * s string to encode * callerbuf buffer to house result * bufsz size of callerbuf * * Notes: * The hex digits 0-9 and A-F are always part of the legal set due to - * their use in the encoding scheme, even if not explicitly included in 'legal'. + * their use in the encoding scheme, even if not explicitly included in + *'legal'. * * Sample: * The following call: @@ -237,21 +243,22 @@ int bufsz; sp = s; op = callerbuf; *op = '\0'; - + while (*sp) { /* Do we have room for one more character or encoding? */ - if ((bufsz - cnt) <= 4) return callerbuf; + if ((bufsz - cnt) <= 4) + return callerbuf; if (*sp == quotechar) { - (void)sprintf(op, "%c%02X", quotechar, *sp); - op += 3; - cnt += 3; + (void) sprintf(op, "%c%02X", quotechar, *sp); + op += 3; + cnt += 3; } else if ((index(legal, *sp) != 0) || (index(hexdigits, *sp) != 0)) { *op++ = *sp; *op = '\0'; cnt++; } else { - (void)sprintf(op,"%c%02X", quotechar, *sp); + (void) sprintf(op, "%c%02X", quotechar, *sp); op += 3; cnt += 3; } @@ -264,7 +271,8 @@ int bufsz; * fname_decode() * * Args: - * quotechar lead-in character used to quote illegal characters as hex digits + * quotechar lead-in character used to quote illegal characters as + *hex digits * s string to decode * callerbuf buffer to house result * bufsz size of callerbuf @@ -276,7 +284,7 @@ char *s, *callerbuf; int bufsz; { char *sp, *op; - int k,calc,cnt = 0; + int k, calc, cnt = 0; static char hexdigits[] = "0123456789ABCDEF"; sp = s; @@ -286,16 +294,23 @@ int bufsz; while (*sp) { /* Do we have room for one more character? */ - if ((bufsz - cnt) <= 2) return callerbuf; + if ((bufsz - cnt) <= 2) + return callerbuf; if (*sp == quotechar) { sp++; - for (k=0; k < 16; ++k) if (*sp == hexdigits[k]) break; - if (k >= 16) return callerbuf; /* impossible, so bail */ - calc = k << 4; + for (k = 0; k < 16; ++k) + if (*sp == hexdigits[k]) + break; + if (k >= 16) + return callerbuf; /* impossible, so bail */ + calc = k << 4; sp++; - for (k=0; k < 16; ++k) if (*sp == hexdigits[k]) break; - if (k >= 16) return callerbuf; /* impossible, so bail */ - calc += k; + for (k = 0; k < 16; ++k) + if (*sp == hexdigits[k]) + break; + if (k >= 16) + return callerbuf; /* impossible, so bail */ + calc += k; sp++; *op++ = calc; *op = '\0'; @@ -309,9 +324,9 @@ int bufsz; } #ifdef PREFIXES_IN_USE -# define UNUSED_if_not_PREFIXES_IN_USE /*empty*/ +#define UNUSED_if_not_PREFIXES_IN_USE /*empty*/ #else -# define UNUSED_if_not_PREFIXES_IN_USE UNUSED +#define UNUSED_if_not_PREFIXES_IN_USE UNUSED #endif /*ARGSUSED*/ @@ -329,15 +344,14 @@ int buffnum UNUSED_if_not_PREFIXES_IN_USE; if (!fqn_prefix[whichprefix]) return basenam; if (buffnum < 0 || buffnum >= FQN_NUMBUF) { - impossible("Invalid fqn_filename_buffer specified: %d", - buffnum); + impossible("Invalid fqn_filename_buffer specified: %d", buffnum); buffnum = 0; } - if (strlen(fqn_prefix[whichprefix]) + strlen(basenam) >= - FQN_MAX_FILENAME) { + if (strlen(fqn_prefix[whichprefix]) + strlen(basenam) + >= FQN_MAX_FILENAME) { impossible("fqname too long: %s + %s", fqn_prefix[whichprefix], - basenam); - return basenam; /* XXX */ + basenam); + return basenam; /* XXX */ } Strcpy(fqn_filename_buffer[buffnum], fqn_prefix[whichprefix]); return strcat(fqn_filename_buffer[buffnum], basenam); @@ -346,7 +360,7 @@ int buffnum UNUSED_if_not_PREFIXES_IN_USE; int validate_prefix_locations(reasonbuf) -char *reasonbuf; /* reasonbuf must be at least BUFSZ, supplied by caller */ +char *reasonbuf; /* reasonbuf must be at least BUFSZ, supplied by caller */ { #if defined(NOCWD_ASSUMPTIONS) FILE *fp; @@ -356,39 +370,41 @@ char *reasonbuf; /* reasonbuf must be at least BUFSZ, supplied by caller */ const char *details; #endif - if (reasonbuf) reasonbuf[0] = '\0'; + if (reasonbuf) + reasonbuf[0] = '\0'; #if defined(NOCWD_ASSUMPTIONS) for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) { /* don't test writing to configdir or datadir; they're readonly */ - if (prefcnt == SYSCONFPREFIX || - prefcnt == CONFIGPREFIX || - prefcnt == DATAPREFIX) continue; + if (prefcnt == SYSCONFPREFIX || prefcnt == CONFIGPREFIX + || prefcnt == DATAPREFIX) + continue; filename = fqname("validate", prefcnt, 3); if ((fp = fopen(filename, "w"))) { fclose(fp); (void) unlink(filename); } else { if (reasonbuf) { - if (failcount) Strcat(reasonbuf,", "); + if (failcount) + Strcat(reasonbuf, ", "); Strcat(reasonbuf, fqn_prefix_names[prefcnt]); } /* the paniclog entry gets the value of errno as well */ - Sprintf(panicbuf1,"Invalid %s", fqn_prefix_names[prefcnt]); -#if defined (NHSTDC) && !defined(NOTSTDC) + Sprintf(panicbuf1, "Invalid %s", fqn_prefix_names[prefcnt]); +#if defined(NHSTDC) && !defined(NOTSTDC) if (!(details = strerror(errno))) #endif - details = ""; - Sprintf(panicbuf2,"\"%s\", (%d) %s", - fqn_prefix[prefcnt], errno, details); + details = ""; + Sprintf(panicbuf2, "\"%s\", (%d) %s", fqn_prefix[prefcnt], errno, + details); paniclog(panicbuf1, panicbuf2); failcount++; - } + } } if (failcount) return 0; else #endif - return 1; + return 1; } /* fopen a file, with OS-dependent bells and whistles */ @@ -431,7 +447,6 @@ set_lock_and_bones() } #endif /* MFLOPPY */ - /* Construct a file name for a level-type file, which is of the form * something.level (with any old level stripped off). * This assumes there is space on the end of 'file' to append @@ -446,7 +461,8 @@ int lev; char *tf; tf = rindex(file, '.'); - if (!tf) tf = eos(file); + if (!tf) + tf = eos(file); Sprintf(tf, ".%d", lev); #ifdef VMS Strcat(tf, ";1"); @@ -462,40 +478,39 @@ char errbuf[]; int fd; const char *fq_lock; - if (errbuf) *errbuf = '\0'; + if (errbuf) + *errbuf = '\0'; set_levelfile_name(lock, lev); fq_lock = fqname(lock, LEVELPREFIX, 0); #if defined(MICRO) || defined(WIN32) - /* Use O_TRUNC to force the file to be shortened if it already - * exists and is currently longer. - */ -# ifdef HOLD_LOCKFILE_OPEN +/* Use O_TRUNC to force the file to be shortened if it already + * exists and is currently longer. + */ +#ifdef HOLD_LOCKFILE_OPEN if (lev == 0) - fd = open_levelfile_exclusively(fq_lock, lev, - O_WRONLY |O_CREAT | O_TRUNC | O_BINARY); + fd = open_levelfile_exclusively( + fq_lock, lev, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); else -# endif - fd = open(fq_lock, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); +#endif + fd = open(fq_lock, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, FCMASK); #else -# ifdef MAC +#ifdef MAC fd = maccreat(fq_lock, LEVL_TYPE); -# else +#else fd = creat(fq_lock, FCMASK); -# endif +#endif #endif /* MICRO || WIN32 */ if (fd >= 0) level_info[lev].flags |= LFILE_EXISTS; - else if (errbuf) /* failure explanation */ - Sprintf(errbuf, - "Cannot create file \"%s\" for level %d (errno %d).", - lock, lev, errno); + else if (errbuf) /* failure explanation */ + Sprintf(errbuf, "Cannot create file \"%s\" for level %d (errno %d).", + lock, lev, errno); return fd; } - int open_levelfile(lev, errbuf) int lev; @@ -504,7 +519,8 @@ char errbuf[]; int fd; const char *fq_lock; - if (errbuf) *errbuf = '\0'; + if (errbuf) + *errbuf = '\0'; set_levelfile_name(lock, lev); fq_lock = fqname(lock, LEVELPREFIX, 0); #ifdef MFLOPPY @@ -515,26 +531,24 @@ char errbuf[]; #ifdef MAC fd = macopen(fq_lock, O_RDONLY | O_BINARY, LEVL_TYPE); #else -# ifdef HOLD_LOCKFILE_OPEN +#ifdef HOLD_LOCKFILE_OPEN if (lev == 0) - fd = open_levelfile_exclusively(fq_lock, lev, O_RDONLY | O_BINARY ); + fd = open_levelfile_exclusively(fq_lock, lev, O_RDONLY | O_BINARY); else -# endif - fd = open(fq_lock, O_RDONLY | O_BINARY, 0); +#endif + fd = open(fq_lock, O_RDONLY | O_BINARY, 0); #endif /* for failure, return an explanation that our caller can use; settle for `lock' instead of `fq_lock' because the latter might end up being too big for nethack's BUFSZ */ if (fd < 0 && errbuf) - Sprintf(errbuf, - "Cannot open file \"%s\" for level %d (errno %d).", - lock, lev, errno); + Sprintf(errbuf, "Cannot open file \"%s\" for level %d (errno %d).", + lock, lev, errno); return fd; } - void delete_levelfile(lev) int lev; @@ -546,19 +560,20 @@ int lev; if (lev == 0 || (level_info[lev].flags & LFILE_EXISTS)) { set_levelfile_name(lock, lev); #ifdef HOLD_LOCKFILE_OPEN - if (lev == 0) really_close(); + if (lev == 0) + really_close(); #endif (void) unlink(fqname(lock, LEVELPREFIX, 0)); level_info[lev].flags &= ~LFILE_EXISTS; } } - void clearlocks() { #ifdef HANGUPHANDLING - if (program_state.preserve_locks) return; + if (program_state.preserve_locks) + return; #endif #if !defined(PC_LOCKING) && defined(MFLOPPY) && !defined(AMIGA) eraseall(levels, alllevels); @@ -566,17 +581,17 @@ clearlocks() eraseall(permbones, alllevels); #else { - register int x; + register int x; -# ifndef NO_SIGNAL - (void) signal(SIGINT, SIG_IGN); -# endif -# if defined(UNIX) || defined(VMS) - sethanguphandler((void FDECL((*),(int)))SIG_IGN); -# endif - /* can't access maxledgerno() before dungeons are created -dlc */ - for (x = (n_dgns ? maxledgerno() : 0); x >= 0; x--) - delete_levelfile(x); /* not all levels need be present */ +#ifndef NO_SIGNAL + (void) signal(SIGINT, SIG_IGN); +#endif +#if defined(UNIX) || defined(VMS) + sethanguphandler((void FDECL((*), (int) )) SIG_IGN); +#endif + /* can't access maxledgerno() before dungeons are created -dlc */ + for (x = (n_dgns ? maxledgerno() : 0); x >= 0; x--) + delete_levelfile(x); /* not all levels need be present */ } #endif /* ?PC_LOCKING,&c */ } @@ -589,9 +604,9 @@ const void *q; { #if defined(UNIX) && defined(QT_GRAPHICS) return strncasecmp(*(char **) p, *(char **) q, 16); -# else +#else return strncmpi(*(char **) p, *(char **) q, 16); -# endif +#endif } #endif @@ -616,17 +631,17 @@ int lev, oflag; lftrack.nethack_thinks_it_is_open = TRUE; } else { really_close(); - fd = sopen(name, oflag,SH_DENYRW, FCMASK); + fd = sopen(name, oflag, SH_DENYRW, FCMASK); lftrack.fd = fd; lftrack.oflag = oflag; lftrack.nethack_thinks_it_is_open = TRUE; } } else { - fd = sopen(name, oflag,SH_DENYRW, FCMASK); - lftrack.fd = fd; - lftrack.oflag = oflag; - if (fd >= 0) - lftrack.nethack_thinks_it_is_open = TRUE; + fd = sopen(name, oflag, SH_DENYRW, FCMASK); + lftrack.fd = fd; + lftrack.oflag = oflag; + if (fd >= 0) + lftrack.nethack_thinks_it_is_open = TRUE; } return fd; } @@ -639,7 +654,7 @@ really_close() lftrack.fd = -1; lftrack.oflag = 0; if (fd != -1) - (void)close(fd); + (void) close(fd); return; } @@ -648,25 +663,24 @@ nhclose(fd) int fd; { if (lftrack.fd == fd) { - really_close(); /* close it, but reopen it to hold it */ - fd = open_levelfile(0, (char *)0); + really_close(); /* close it, but reopen it to hold it */ + fd = open_levelfile(0, (char *) 0); lftrack.nethack_thinks_it_is_open = FALSE; return 0; } - return close(fd); + return close(fd); } #else int nhclose(fd) int fd; { - return close(fd); + return close(fd); } #endif /* ---------- END LEVEL FILE HANDLING ----------- */ - /* ---------- BEGIN BONES FILE HANDLING ----------- */ /* set up "file" to be file name for retrieving bones, and return a @@ -690,7 +704,7 @@ d_level *lev; #ifdef VMS Strcat(dptr, ";1"); #endif - return(dptr-2); + return (dptr - 2); } /* set up temporary file name for writing bones, to avoid another game's @@ -705,7 +719,8 @@ set_bonestemp_name() char *tf; tf = rindex(lock, '.'); - if (!tf) tf = eos(lock); + if (!tf) + tf = eos(lock); Sprintf(tf, ".bn"); #ifdef VMS Strcat(tf, ";1"); @@ -722,7 +737,8 @@ char errbuf[]; const char *file; int fd; - if (errbuf) *errbuf = '\0'; + if (errbuf) + *errbuf = '\0'; *bonesid = set_bonesfile_name(bones, lev); file = set_bonestemp_name(); file = fqname(file, BONESPREFIX, 0); @@ -731,20 +747,19 @@ char errbuf[]; /* Use O_TRUNC to force the file to be shortened if it already * exists and is currently longer. */ - fd = open(file, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, FCMASK); #else -# ifdef MAC +#ifdef MAC fd = maccreat(file, BONE_TYPE); -# else +#else fd = creat(file, FCMASK); -# endif +#endif #endif if (fd < 0 && errbuf) /* failure explanation */ - Sprintf(errbuf, - "Cannot create bones \"%s\", id %s (errno %d).", - lock, *bonesid, errno); + Sprintf(errbuf, "Cannot create bones \"%s\", id %s (errno %d).", lock, + *bonesid, errno); -# if defined(VMS) && !defined(SECURE) +#if defined(VMS) && !defined(SECURE) /* Re-protect bones file with world:read+write+execute+delete access. umask() doesn't seem very reliable; also, vaxcrtl won't let us set @@ -753,8 +768,8 @@ char errbuf[]; ANDs the mask with the user's default protection, which usually denies some or all access to world. */ - (void) chmod(file, FCMASK | 007); /* allow other users full access */ -# endif /* VMS && !SECURE */ + (void) chmod(file, FCMASK | 007); /* allow other users full access */ +#endif /* VMS && !SECURE */ return fd; } @@ -799,7 +814,6 @@ d_level *lev; pline("couldn't rename %s to %s.", tempname, fq_bones); } - int open_bonesfile(lev, bonesid) d_level *lev; @@ -810,7 +824,7 @@ char **bonesid; *bonesid = set_bonesfile_name(bones, lev); fq_bones = fqname(bones, BONESPREFIX, 0); - nh_uncompress(fq_bones); /* no effect if nonexistent */ + nh_uncompress(fq_bones); /* no effect if nonexistent */ #ifdef MAC fd = macopen(fq_bones, O_RDONLY | O_BINARY, BONE_TYPE); #else @@ -819,7 +833,6 @@ char **bonesid; return fd; } - int delete_bonesfile(lev) d_level *lev; @@ -828,7 +841,6 @@ d_level *lev; return !(unlink(fqname(bones, BONESPREFIX, 0)) < 0); } - /* assume we're compressing the recently read or created bonesfile, so the * file name is already set properly */ void @@ -839,7 +851,6 @@ compress_bonesfile() /* ---------- END BONES FILE HANDLING ----------- */ - /* ---------- BEGIN SAVE FILE HANDLING ----------- */ /* set savefile name in OS-dependent manner from pre-existing plname, @@ -850,45 +861,49 @@ boolean regularize_it; { #ifdef VMS Sprintf(SAVEF, "[.save]%d%s", getuid(), plname); - if (regularize_it) regularize(SAVEF+7); + if (regularize_it) + regularize(SAVEF + 7); Strcat(SAVEF, ";1"); #else -# if defined(MICRO) +#if defined(MICRO) Strcpy(SAVEF, SAVEP); -# ifdef AMIGA +#ifdef AMIGA strncat(SAVEF, bbs_id, PATHLEN); -# endif +#endif { int i = strlen(SAVEP); -# ifdef AMIGA +#ifdef AMIGA /* plname has to share space with SAVEP and ".sav" */ - (void)strncat(SAVEF, plname, FILENAME - i - 4); -# else - (void)strncat(SAVEF, plname, 8); -# endif - if (regularize_it) regularize(SAVEF+i); + (void) strncat(SAVEF, plname, FILENAME - i - 4); +#else + (void) strncat(SAVEF, plname, 8); +#endif + if (regularize_it) + regularize(SAVEF + i); } Strcat(SAVEF, SAVE_EXTENSION); -# else -# if defined(WIN32) +#else +#if defined(WIN32) { - static const char okchars[] = - "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-."; - const char *legal = okchars; - char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ]; + static const char okchars[] = + "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-."; + const char *legal = okchars; + char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ]; - /* Obtain the name of the logged on user and incorporate - * it into the name. */ - Sprintf(fnamebuf, "%s-%s", get_username(0), plname); - if (regularize_it) ++legal; /* skip '*' wildcard character */ - (void)fname_encode(legal, '%', fnamebuf, encodedfnamebuf, BUFSZ); - Sprintf(SAVEF, "%s%s", encodedfnamebuf,SAVE_EXTENSION); + /* Obtain the name of the logged on user and incorporate + * it into the name. */ + Sprintf(fnamebuf, "%s-%s", get_username(0), plname); + if (regularize_it) + ++legal; /* skip '*' wildcard character */ + (void) fname_encode(legal, '%', fnamebuf, encodedfnamebuf, BUFSZ); + Sprintf(SAVEF, "%s%s", encodedfnamebuf, SAVE_EXTENSION); } -# else /* not VMS or MICRO or WIN32 */ - Sprintf(SAVEF, "save/%d%s", (int)getuid(), plname); - if (regularize_it) regularize(SAVEF+5); /* avoid . or / in name */ -# endif /* WIN32 */ -# endif /* MICRO */ +#else /* not VMS or MICRO or WIN32 */ + Sprintf(SAVEF, "save/%d%s", (int) getuid(), plname); + if (regularize_it) + regularize(SAVEF + 5); /* avoid . or / in name */ +#endif /* WIN32 */ +#endif /* MICRO */ #endif /* VMS */ } @@ -901,29 +916,28 @@ int fd; } #endif - #ifndef MICRO /* change pre-existing savefile name to indicate an error savefile */ void set_error_savefile() { -# ifdef VMS - { - char *semi_colon = rindex(SAVEF, ';'); - if (semi_colon) *semi_colon = '\0'; - } +#ifdef VMS + { + char *semi_colon = rindex(SAVEF, ';'); + if (semi_colon) + *semi_colon = '\0'; + } Strcat(SAVEF, ".e;1"); -# else -# ifdef MAC +#else +#ifdef MAC Strcat(SAVEF, "-e"); -# else +#else Strcat(SAVEF, ".e"); -# endif -# endif +#endif +#endif } #endif - /* create save file, overwriting one if it already exists */ int create_savefile() @@ -935,27 +949,26 @@ create_savefile() #if defined(MICRO) || defined(WIN32) fd = open(fq_save, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); #else -# ifdef MAC +#ifdef MAC fd = maccreat(fq_save, SAVE_TYPE); -# else +#else fd = creat(fq_save, FCMASK); -# endif -# if defined(VMS) && !defined(SECURE) - /* - Make sure the save file is owned by the current process. That's - the default for non-privileged users, but for priv'd users the - file will be owned by the directory's owner instead of the user. - */ -# undef getuid +#endif +#if defined(VMS) && !defined(SECURE) +/* + Make sure the save file is owned by the current process. That's + the default for non-privileged users, but for priv'd users the + file will be owned by the directory's owner instead of the user. + */ +#undef getuid (void) chown(fq_save, getuid(), getgid()); -# define getuid() vms_getuid() -# endif /* VMS && !SECURE */ -#endif /* MICRO */ +#define getuid() vms_getuid() +#endif /* VMS && !SECURE */ +#endif /* MICRO */ return fd; } - /* open savefile for reading */ int open_savefile() @@ -972,16 +985,14 @@ open_savefile() return fd; } - /* delete savefile */ int delete_savefile() { (void) unlink(fqname(SAVEF, SAVEPREFIX, 0)); - return 0; /* for restore_saved_game() (ex-xxxmain.c) test */ + return 0; /* for restore_saved_game() (ex-xxxmain.c) test */ } - /* try to open up a save file and prepare to restore it */ int restore_saved_game() @@ -998,10 +1009,11 @@ restore_saved_game() fq_save = fqname(SAVEF, SAVEPREFIX, 0); nh_uncompress(fq_save); - if ((fd = open_savefile()) < 0) return fd; + if ((fd = open_savefile()) < 0) + return fd; if (validate(fd, fq_save) != 0) { - (void) nhclose(fd), fd = -1; + (void) nhclose(fd), fd = -1; (void) delete_savefile(); } return fd; @@ -1010,41 +1022,41 @@ restore_saved_game() #if defined(SELECTSAVED) char * plname_from_file(filename) -const char* filename; +const char *filename; { int fd; - char* result = 0; + char *result = 0; - Strcpy(SAVEF,filename); -# ifdef COMPRESS_EXTENSION - SAVEF[strlen(SAVEF)-strlen(COMPRESS_EXTENSION)] = '\0'; -# endif + Strcpy(SAVEF, filename); +#ifdef COMPRESS_EXTENSION + SAVEF[strlen(SAVEF) - strlen(COMPRESS_EXTENSION)] = '\0'; +#endif nh_uncompress(SAVEF); if ((fd = open_savefile()) >= 0) { - if (validate(fd, filename)==0) { - char tplname[PL_NSIZ]; - get_plname_from_file(fd, tplname); - result = dupstr(tplname); - } - (void) nhclose(fd); + if (validate(fd, filename) == 0) { + char tplname[PL_NSIZ]; + get_plname_from_file(fd, tplname); + result = dupstr(tplname); + } + (void) nhclose(fd); } nh_compress(SAVEF); return result; -# if 0 +#if 0 /* --------- obsolete - used to be ifndef STORE_PLNAME_IN_FILE ----*/ -# if defined(UNIX) && defined(QT_GRAPHICS) +#if defined(UNIX) && defined(QT_GRAPHICS) /* Name not stored in save file, so we have to extract it from the filename, which loses information (eg. "/", "_", and "." characters are lost. */ int k; int uid; char name[64]; /* more than PL_NSIZ */ -# ifdef COMPRESS_EXTENSION +#ifdef COMPRESS_EXTENSION #define EXTSTR COMPRESS_EXTENSION -# else +#else #define EXTSTR "" -# endif +#endif if ( sscanf( filename, "%*[^/]/%d%63[^.]" EXTSTR, &uid, name ) == 2 ) { #undef EXTSTR /* "_" most likely means " ", which certainly looks nicer */ @@ -1053,104 +1065,105 @@ const char* filename; name[k]=' '; return dupstr(name); } else -# endif /* UNIX && QT_GRAPHICS */ +#endif /* UNIX && QT_GRAPHICS */ { return 0; } /* --------- end of obsolete code ----*/ -# endif /* 0 - WAS STORE_PLNAME_IN_FILE*/ +#endif /* 0 - WAS STORE_PLNAME_IN_FILE*/ } #endif /* defined(SELECTSAVED) */ -char** +char ** get_saved_games() { #if defined(SELECTSAVED) int n, j = 0; char **result = 0; -# ifdef WIN32 +#ifdef WIN32 { - char *foundfile; - const char *fq_save; + char *foundfile; + const char *fq_save; - Strcpy(plname, "*"); - set_savefile_name(FALSE); + Strcpy(plname, "*"); + set_savefile_name(FALSE); #if defined(ZLIB_COMP) - Strcat(SAVEF, COMPRESS_EXTENSION); + Strcat(SAVEF, COMPRESS_EXTENSION); #endif - fq_save = fqname(SAVEF, SAVEPREFIX, 0); + fq_save = fqname(SAVEF, SAVEPREFIX, 0); - n = 0; - foundfile = foundfile_buffer(); - if (findfirst((char *)fq_save)) { - do { - ++n; - } while (findnext()); - } - if (n > 0) { - result = (char**)alloc((n+1)*sizeof(char*)); /* at most */ - (void) memset((genericptr_t) result, 0, (n+1)*sizeof(char*)); - if (findfirst((char *)fq_save)) { - j = n = 0; - do { - char *r; - r = plname_from_file(foundfile); - if (r) - result[j++] = r; - ++n; - } while (findnext()); + n = 0; + foundfile = foundfile_buffer(); + if (findfirst((char *) fq_save)) { + do { + ++n; + } while (findnext()); + } + if (n > 0) { + result = (char **) alloc((n + 1) * sizeof(char *)); /* at most */ + (void) memset((genericptr_t) result, 0, (n + 1) * sizeof(char *)); + if (findfirst((char *) fq_save)) { + j = n = 0; + do { + char *r; + r = plname_from_file(foundfile); + if (r) + result[j++] = r; + ++n; + } while (findnext()); + } } } - } -# endif -# if defined(UNIX) && defined(QT_GRAPHICS) +#endif +#if defined(UNIX) && defined(QT_GRAPHICS) /* posixly correct version */ - int myuid=getuid(); + int myuid = getuid(); DIR *dir; - if((dir=opendir(fqname("save", SAVEPREFIX, 0)))) { - for(n=0; readdir(dir); n++) - ; - closedir(dir); - if(n>0) { - int i; - if(!(dir=opendir(fqname("save", SAVEPREFIX, 0)))) - return 0; - result = (char**)alloc((n+1)*sizeof(char*)); /* at most */ - (void) memset((genericptr_t) result, 0, (n+1)*sizeof(char*)); - for (i=0, j=0; id_name, "%d%63s", &uid, name ) == 2 ) { - if ( uid == myuid ) { - char filename[BUFSZ]; - char* r; - Sprintf(filename,"save/%d%s",uid,name); - r = plname_from_file(filename); - if ( r ) - result[j++] = r; - } - } - } + if ((dir = opendir(fqname("save", SAVEPREFIX, 0)))) { + for (n = 0; readdir(dir); n++) + ; closedir(dir); + if (n > 0) { + int i; + if (!(dir = opendir(fqname("save", SAVEPREFIX, 0)))) + return 0; + result = (char **) alloc((n + 1) * sizeof(char *)); /* at most */ + (void) memset((genericptr_t) result, 0, (n + 1) * sizeof(char *)); + for (i = 0, j = 0; i < n; i++) { + int uid; + char name[64]; /* more than PL_NSIZ */ + struct dirent *entry = readdir(dir); + if (!entry) + break; + if (sscanf(entry->d_name, "%d%63s", &uid, name) == 2) { + if (uid == myuid) { + char filename[BUFSZ]; + char *r; + Sprintf(filename, "save/%d%s", uid, name); + r = plname_from_file(filename); + if (r) + result[j++] = r; + } + } + } + closedir(dir); + } } - } -# endif -# ifdef VMS +#endif +#ifdef VMS Strcpy(plname, "*"); set_savefile_name(FALSE); j = vms_get_saved_games(SAVEF, &result); -# endif /* VMS */ +#endif /* VMS */ if (j > 0) { - if (j > 1) qsort(result, j, sizeof (char *), strcmp_wrap); - result[j] = 0; - return result; + if (j > 1) + qsort(result, j, sizeof(char *), strcmp_wrap); + result[j] = 0; + return result; } else if (result) { /* could happen if save files are obsolete */ - free_saved_games(result); + free_saved_games(result); } #endif /* SELECTSAVED */ return 0; @@ -1158,19 +1171,18 @@ get_saved_games() void free_saved_games(saved) -char** saved; +char **saved; { - if ( saved ) { - int i=0; - while (saved[i]) free((genericptr_t)saved[i++]); - free((genericptr_t)saved); + if (saved) { + int i = 0; + while (saved[i]) + free((genericptr_t) saved[i++]); + free((genericptr_t) saved); } } - /* ---------- END SAVE FILE HANDLING ----------- */ - /* ---------- BEGIN FILE COMPRESSION HANDLING ----------- */ #ifdef COMPRESS @@ -1181,9 +1193,9 @@ const char *filename, *mode; FILE *stream; boolean uncomp; { - if (freopen(filename, mode, stream) == (FILE *)0) { + if (freopen(filename, mode, stream) == (FILE *) 0) { (void) fprintf(stderr, "freopen of %s for %scompress failed\n", - filename, uncomp ? "un" : ""); + filename, uncomp ? "un" : ""); terminate(EXIT_FAILURE); } } @@ -1203,29 +1215,30 @@ boolean uncomp; char cfn[80]; FILE *cf; const char *args[10]; -# ifdef COMPRESS_OPTIONS +#ifdef COMPRESS_OPTIONS char opts[80]; -# endif +#endif int i = 0; int f; -# ifdef TTY_GRAPHICS +#ifdef TTY_GRAPHICS boolean istty = !strncmpi(windowprocs.name, "tty", 3); -# endif +#endif Strcpy(cfn, filename); -# ifdef COMPRESS_EXTENSION +#ifdef COMPRESS_EXTENSION Strcat(cfn, COMPRESS_EXTENSION); -# endif +#endif /* when compressing, we know the file exists */ if (uncomp) { - if ((cf = fopen(cfn, RDBMODE)) == (FILE *)0) + if ((cf = fopen(cfn, RDBMODE)) == (FILE *) 0) return; (void) fclose(cf); } args[0] = COMPRESS; - if (uncomp) args[++i] = "-d"; /* uncompress */ -# ifdef COMPRESS_OPTIONS + if (uncomp) + args[++i] = "-d"; /* uncompress */ +#ifdef COMPRESS_OPTIONS { /* we can't guarantee there's only one additional option, sigh */ char *opt; @@ -1234,32 +1247,32 @@ boolean uncomp; Strcpy(opts, COMPRESS_OPTIONS); opt = opts; while (*opt) { - if ((*opt == ' ') || (*opt == '\t')) { - if (inword) { - *opt = '\0'; - inword = FALSE; + if ((*opt == ' ') || (*opt == '\t')) { + if (inword) { + *opt = '\0'; + inword = FALSE; + } + } else if (!inword) { + args[++i] = opt; + inword = TRUE; } - } else if (!inword) { - args[++i] = opt; - inword = TRUE; - } - opt++; + opt++; } } -# endif - args[++i] = (char *)0; +#endif + args[++i] = (char *) 0; -# ifdef TTY_GRAPHICS +#ifdef TTY_GRAPHICS /* If we don't do this and we are right after a y/n question *and* * there is an error message from the compression, the 'y' or 'n' can * end up being displayed after the error message. */ if (istty) mark_synch(); -# endif +#endif f = fork(); - if (f == 0) { /* child */ -# ifdef TTY_GRAPHICS + if (f == 0) { /* child */ +#ifdef TTY_GRAPHICS /* any error messages from the compression must come out after * the first line, because the more() to let the user read * them will have to clear the first line. This should be @@ -1267,7 +1280,7 @@ boolean uncomp; */ if (istty) raw_print(""); -# endif +#endif /* run compressor without privileges, in case other programs * have surprises along the line of gzip once taking filenames * in GZIP. @@ -1286,22 +1299,22 @@ boolean uncomp; (void) setgid(getgid()); (void) setuid(getuid()); (void) execv(args[0], (char *const *) args); - perror((char *)0); + perror((char *) 0); (void) fprintf(stderr, "Exec to %scompress %s failed.\n", - uncomp ? "un" : "", filename); + uncomp ? "un" : "", filename); terminate(EXIT_FAILURE); } else if (f == -1) { - perror((char *)0); - pline("Fork to %scompress %s failed.", - uncomp ? "un" : "", filename); + perror((char *) 0); + pline("Fork to %scompress %s failed.", uncomp ? "un" : "", filename); return; } -# ifndef NO_SIGNAL +#ifndef NO_SIGNAL (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); - (void) wait((int *)&i); + (void) wait((int *) &i); (void) signal(SIGINT, (SIG_RET_TYPE) done1); - if (wizard) (void) signal(SIGQUIT, SIG_DFL); + if (wizard) + (void) signal(SIGQUIT, SIG_DFL); #else /* I don't think we can really cope with external compression * without signals, so we'll declare that compress failed and @@ -1314,17 +1327,17 @@ boolean uncomp; if (i == 0) { /* (un)compress succeeded: remove file left behind */ if (uncomp) - (void) unlink(cfn); + (void) unlink(cfn); else - (void) unlink(filename); + (void) unlink(filename); } else { /* (un)compress failed; remove the new, bad file */ if (uncomp) { - raw_printf("Unable to uncompress %s", filename); - (void) unlink(filename); + raw_printf("Unable to uncompress %s", filename); + (void) unlink(filename); } else { - /* no message needed for compress case; life will go on */ - (void) unlink(cfn); + /* no message needed for compress case; life will go on */ + (void) unlink(cfn); } #ifdef TTY_GRAPHICS /* Give them a chance to read any error messages from the @@ -1333,22 +1346,21 @@ boolean uncomp; * messages are being written on top of the screen, but at least * the user can read them. */ - if (istty) - { - clear_nhwindow(WIN_MESSAGE); - more(); - /* No way to know if this is feasible */ - /* doredraw(); */ + if (istty) { + clear_nhwindow(WIN_MESSAGE); + more(); + /* No way to know if this is feasible */ + /* doredraw(); */ } #endif } } -#endif /* COMPRESS */ +#endif /* COMPRESS */ #if defined(COMPRESS) || defined(ZLIB_COMP) -# define UNUSED_if_not_COMPRESS /*empty*/ +#define UNUSED_if_not_COMPRESS /*empty*/ #else -# define UNUSED_if_not_COMPRESS UNUSED +#define UNUSED_if_not_COMPRESS UNUSED #endif /* compress file */ @@ -1357,24 +1369,23 @@ nh_compress(filename) const char *filename UNUSED_if_not_COMPRESS; { #if !defined(COMPRESS) && !defined(ZLIB_COMP) -# ifdef PRAGMA_UNUSED -# pragma unused(filename) -# endif +#ifdef PRAGMA_UNUSED +#pragma unused(filename) +#endif #else docompress_file(filename, FALSE); #endif } - /* uncompress file if it exists */ void nh_uncompress(filename) const char *filename UNUSED_if_not_COMPRESS; { #if !defined(COMPRESS) && !defined(ZLIB_COMP) -# ifdef PRAGMA_UNUSED -# pragma unused(filename) -# endif +#ifdef PRAGMA_UNUSED +#pragma unused(filename) +#endif #else docompress_file(filename, TRUE); #endif @@ -1382,7 +1393,7 @@ const char *filename UNUSED_if_not_COMPRESS; #ifdef ZLIB_COMP /* RLC 09 Mar 1999: Support internal ZLIB */ STATIC_OVL boolean -make_compressed_name(filename,cfn) +make_compressed_name(filename, cfn) const char *filename; char *cfn; { @@ -1392,8 +1403,8 @@ char *cfn; strcat(cfn, COMPRESS_EXTENSION); return TRUE; #else -# ifdef SAVE_EXTENSION - char *bp = (char *)0; +#ifdef SAVE_EXTENSION + char *bp = (char *) 0; strcpy(cfn, filename); if ((bp = strstri(cfn, SAVE_EXTENSION))) { strsubst(bp, SAVE_EXTENSION, ".saz"); @@ -1402,13 +1413,13 @@ char *cfn; /* find last occurrence of bon */ bp = eos(cfn); while (bp-- > cfn) { - if (strstri(bp,"bon")) { + if (strstri(bp, "bon")) { strsubst(bp, "bon", "boz"); return TRUE; } } } -# endif /* SAVE_EXTENSION */ +#endif /* SAVE_EXTENSION */ return FALSE; #endif /* SHORT_FILENAMES */ } @@ -1418,7 +1429,7 @@ docompress_file(filename, uncomp) const char *filename; boolean uncomp; { - gzFile compressedfile; + gzFile compressedfile; FILE *uncompressedfile; char cfn[256]; char buf[1024]; @@ -1442,8 +1453,7 @@ boolean uncomp; if (errno == 0) { pline("zlib failed to allocate memory"); } else { - panic("Error in docompress_file %d", - errno); + panic("Error in docompress_file %d", errno); } fclose(uncompressedfile); return; @@ -1458,10 +1468,11 @@ boolean uncomp; pline("Can't compress %s.", filename); fclose(uncompressedfile); gzclose(compressedfile); - (void)unlink(cfn); + (void) unlink(cfn); return; } - if (len == 0) break; /* End of file */ + if (len == 0) + break; /* End of file */ len2 = gzwrite(compressedfile, buf, len); if (len2 == 0) { @@ -1469,7 +1480,7 @@ boolean uncomp; pline("Can't compress %s.", filename); fclose(uncompressedfile); gzclose(compressedfile); - (void)unlink(cfn); + (void) unlink(cfn); return; } } @@ -1479,9 +1490,9 @@ boolean uncomp; /* Delete the file left behind */ - (void)unlink(filename); + (void) unlink(filename); - } else { /* uncomp */ + } else { /* uncomp */ /* Open the input and output files */ /* Note that gzopen takes "rb" as its mode, even on systems where @@ -1492,15 +1503,14 @@ boolean uncomp; if (errno == 0) { pline("zlib failed to allocate memory"); } else if (errno != ENOENT) { - panic("Error in zlib docompress_file %s, %d", - filename, errno); + panic("Error in zlib docompress_file %s, %d", filename, + errno); } return; } uncompressedfile = fopen(filename, WRBMODE); if (!uncompressedfile) { - pline("Error in zlib docompress file uncompress %s", - filename); + pline("Error in zlib docompress file uncompress %s", filename); gzclose(compressedfile); return; } @@ -1509,15 +1519,16 @@ boolean uncomp; while (1) { len = gzread(compressedfile, buf, sizeof(buf)); - if (len == (unsigned)-1) { + if (len == (unsigned) -1) { pline("Failure reading compressed file"); pline("Can't uncompress %s.", filename); fclose(uncompressedfile); gzclose(compressedfile); - (void)unlink(filename); + (void) unlink(filename); return; } - if (len == 0) break; /* End of file */ + if (len == 0) + break; /* End of file */ fwrite(buf, 1, len, uncompressedfile); if (ferror(uncompressedfile)) { @@ -1525,7 +1536,7 @@ boolean uncomp; pline("Can't uncompress %s.", filename); fclose(uncompressedfile); gzclose(compressedfile); - (void)unlink(filename); + (void) unlink(filename); return; } } @@ -1534,26 +1545,25 @@ boolean uncomp; gzclose(compressedfile); /* Delete the file left behind */ - (void)unlink(cfn); + (void) unlink(cfn); } } #endif /* RLC 09 Mar 1999: End ZLIB patch */ /* ---------- END FILE COMPRESSION HANDLING ----------- */ - /* ---------- BEGIN FILE LOCKING HANDLING ----------- */ static int nesting = 0; -#if defined(NO_FILE_LINKS) || defined(USE_FCNTL) /* implies UNIX */ -static int lockfd; /* for lock_file() to pass to unlock_file() */ +#if defined(NO_FILE_LINKS) || defined(USE_FCNTL) /* implies UNIX */ +static int lockfd; /* for lock_file() to pass to unlock_file() */ #endif #ifdef USE_FCNTL struct flock sflock; /* for unlocking, same as above */ #endif -#define HUP if (!program_state.done_hup) +#define HUP if (!program_state.done_hup) #ifndef USE_FCNTL STATIC_OVL char * @@ -1561,30 +1571,32 @@ make_lockname(filename, lockname) const char *filename; char *lockname; { -#if defined(UNIX) || defined(VMS) || defined(AMIGA) || defined(WIN32) || defined(MSDOS) -# ifdef NO_FILE_LINKS +#if defined(UNIX) || defined(VMS) || defined(AMIGA) || defined(WIN32) \ + || defined(MSDOS) +#ifdef NO_FILE_LINKS Strcpy(lockname, LOCKDIR); Strcat(lockname, "/"); Strcat(lockname, filename); -# else +#else Strcpy(lockname, filename); -# endif -# ifdef VMS - { - char *semi_colon = rindex(lockname, ';'); - if (semi_colon) *semi_colon = '\0'; - } +#endif +#ifdef VMS + { + char *semi_colon = rindex(lockname, ';'); + if (semi_colon) + *semi_colon = '\0'; + } Strcat(lockname, ".lock;1"); -# else +#else Strcat(lockname, "_lock"); -# endif +#endif return lockname; -#else /* !(UNIX || VMS || AMIGA || WIN32 || MSDOS) */ -# ifdef PRAGMA_UNUSED -# pragma unused(filename) -# endif +#else /* !(UNIX || VMS || AMIGA || WIN32 || MSDOS) */ +#ifdef PRAGMA_UNUSED +#pragma unused(filename) +#endif lockname[0] = '\0'; - return (char*)0; + return (char *) 0; #endif } #endif /* !USE_FCNTL */ @@ -1596,8 +1608,9 @@ const char *filename; int whichprefix; int retryct; { -#if defined(PRAGMA_UNUSED) && !(defined(UNIX) || defined(VMS)) && !(defined(AMIGA) || defined(WIN32) || defined(MSDOS)) -# pragma unused(retryct) +#if defined(PRAGMA_UNUSED) && !(defined(UNIX) || defined(VMS)) \ + && !(defined(AMIGA) || defined(WIN32) || defined(MSDOS)) +#pragma unused(retryct) #endif #ifndef USE_FCNTL char locknambuf[BUFSZ]; @@ -1612,16 +1625,16 @@ int retryct; #ifndef USE_FCNTL lockname = make_lockname(filename, locknambuf); -#ifndef NO_FILE_LINKS /* LOCKDIR should be subsumed by LOCKPREFIX */ +#ifndef NO_FILE_LINKS /* LOCKDIR should be subsumed by LOCKPREFIX */ lockname = fqname(lockname, LOCKPREFIX, 2); #endif #endif filename = fqname(filename, whichprefix, 0); #ifdef USE_FCNTL - lockfd = open(filename,O_RDWR); + lockfd = open(filename, O_RDWR); if (lockfd == -1) { HUP raw_printf("Cannot open file %s. This is a program bug.", - filename); + filename); } sflock.l_type = F_WRLCK; sflock.l_whence = SEEK_SET; @@ -1630,129 +1643,126 @@ int retryct; #endif #if defined(UNIX) || defined(VMS) -# ifdef USE_FCNTL - while (fcntl(lockfd,F_SETLK,&sflock) == -1) { -# else -# ifdef NO_FILE_LINKS - while ((lockfd = open(lockname, O_RDWR|O_CREAT|O_EXCL, 0666)) == -1) { -# else +#ifdef USE_FCNTL + while (fcntl(lockfd, F_SETLK, &sflock) == -1) { +#else +#ifdef NO_FILE_LINKS + while ((lockfd = open(lockname, O_RDWR | O_CREAT | O_EXCL, 0666)) == -1) { +#else while (link(filename, lockname) == -1) { -# endif -# endif +#endif +#endif #ifdef USE_FCNTL if (retryct--) { - HUP raw_printf( - "Waiting for release of fcntl lock on %s. (%d retries left).", - filename, retryct); - sleep(1); + HUP raw_printf( + "Waiting for release of fcntl lock on %s. (%d retries left).", + filename, retryct); + sleep(1); } else { - HUP (void) raw_print("I give up. Sorry."); - HUP raw_printf("Some other process has an unnatural grip on %s.", - filename); - nesting--; - return FALSE; + HUP(void) raw_print("I give up. Sorry."); + HUP raw_printf("Some other process has an unnatural grip on %s.", + filename); + nesting--; + return FALSE; } #else register int errnosv = errno; - switch (errnosv) { /* George Barbanis */ + switch (errnosv) { /* George Barbanis */ case EEXIST: - if (retryct--) { - HUP raw_printf( - "Waiting for access to %s. (%d retries left).", - filename, retryct); -# if defined(SYSV) || defined(ULTRIX) || defined(VMS) - (void) -# endif - sleep(1); - } else { - HUP (void) raw_print("I give up. Sorry."); - HUP raw_printf("Perhaps there is an old %s around?", - lockname); + if (retryct--) { + HUP raw_printf( + "Waiting for access to %s. (%d retries left).", filename, + retryct); +#if defined(SYSV) || defined(ULTRIX) || defined(VMS) + (void) +#endif + sleep(1); + } else { + HUP(void) raw_print("I give up. Sorry."); + HUP raw_printf("Perhaps there is an old %s around?", + lockname); + nesting--; + return FALSE; + } + + break; + case ENOENT: + HUP raw_printf("Can't find file %s to lock!", filename); + nesting--; + return FALSE; + case EACCES: + HUP raw_printf("No write permission to lock %s!", filename); + nesting--; + return FALSE; +#ifdef VMS /* c__translate(vmsfiles.c) */ + case EPERM: + /* could be misleading, but usually right */ + HUP raw_printf("Can't lock %s due to directory protection.", + filename); + nesting--; + return FALSE; +#endif + case EROFS: + /* take a wild guess at the underlying cause */ + HUP perror(lockname); + HUP raw_printf("Cannot lock %s.", filename); + HUP raw_printf("(Perhaps you are running NetHack from inside the " + "distribution package?)."); + nesting--; + return FALSE; + default: + HUP perror(lockname); + HUP raw_printf("Cannot lock %s for unknown reason (%d).", + filename, errnosv); nesting--; return FALSE; } - - break; - case ENOENT: - HUP raw_printf("Can't find file %s to lock!", filename); - nesting--; - return FALSE; - case EACCES: - HUP raw_printf("No write permission to lock %s!", filename); - nesting--; - return FALSE; -# ifdef VMS /* c__translate(vmsfiles.c) */ - case EPERM: - /* could be misleading, but usually right */ - HUP raw_printf("Can't lock %s due to directory protection.", - filename); - nesting--; - return FALSE; -# endif - case EROFS: - /* take a wild guess at the underlying cause */ - HUP perror(lockname); - HUP raw_printf("Cannot lock %s.", filename); - HUP raw_printf( - "(Perhaps you are running NetHack from inside the distribution package?)." - ); - nesting--; - return FALSE; - default: - HUP perror(lockname); - HUP raw_printf( - "Cannot lock %s for unknown reason (%d).", - filename, errnosv); - nesting--; - return FALSE; - } #endif /* USE_FCNTL */ - } -#endif /* UNIX || VMS */ +#endif /* UNIX || VMS */ -#if (defined(AMIGA) || defined(WIN32) || defined(MSDOS)) && !defined(USE_FCNTL) -# ifdef AMIGA +#if (defined(AMIGA) || defined(WIN32) || defined(MSDOS)) \ + && !defined(USE_FCNTL) +#ifdef AMIGA #define OPENFAILURE(fd) (!fd) lockptr = 0; -# else +#else #define OPENFAILURE(fd) (fd < 0) lockptr = -1; -# endif +#endif while (--retryct && OPENFAILURE(lockptr)) { -# if defined(WIN32) && !defined(WIN_CE) - lockptr = sopen(lockname, O_RDWR|O_CREAT, SH_DENYRW, S_IWRITE); -# else - (void)DeleteFile(lockname); /* in case dead process was here first */ -# ifdef AMIGA - lockptr = Open(lockname,MODE_NEWFILE); -# else - lockptr = open(lockname, O_RDWR|O_CREAT|O_EXCL, S_IWRITE); -# endif -# endif - if (OPENFAILURE(lockptr)) { - raw_printf("Waiting for access to %s. (%d retries left).", - filename, retryct); - Delay(50); - } +#if defined(WIN32) && !defined(WIN_CE) + lockptr = sopen(lockname, O_RDWR | O_CREAT, SH_DENYRW, S_IWRITE); +#else + (void) DeleteFile(lockname); /* in case dead process was here first */ +#ifdef AMIGA + lockptr = Open(lockname, MODE_NEWFILE); +#else + lockptr = open(lockname, O_RDWR | O_CREAT | O_EXCL, S_IWRITE); +#endif +#endif + if (OPENFAILURE(lockptr)) { + raw_printf("Waiting for access to %s. (%d retries left).", + filename, retryct); + Delay(50); + } } if (!retryct) { - raw_printf("I give up. Sorry."); - nesting--; - return FALSE; + raw_printf("I give up. Sorry."); + nesting--; + return FALSE; } #endif /* AMIGA || WIN32 || MSDOS */ return TRUE; } - -#ifdef VMS /* for unlock_file, use the unlink() routine in vmsunix.c */ -# ifdef unlink -# undef unlink -# endif -# define unlink(foo) vms_unlink(foo) +#ifdef VMS /* for unlock_file, use the unlink() routine in vmsunix.c */ +#ifdef unlink +#undef unlink +#endif +#define unlink(foo) vms_unlink(foo) #endif /* unlock file, which must be currently locked by lock_file */ @@ -1768,27 +1778,28 @@ const char *filename; if (nesting == 1) { #ifdef USE_FCNTL sflock.l_type = F_UNLCK; - if (fcntl(lockfd,F_SETLK,&sflock) == -1) { + if (fcntl(lockfd, F_SETLK, &sflock) == -1) { HUP raw_printf("Can't remove fcntl lock on %s.", filename); (void) close(lockfd); } #else lockname = make_lockname(filename, locknambuf); -#ifndef NO_FILE_LINKS /* LOCKDIR should be subsumed by LOCKPREFIX */ +#ifndef NO_FILE_LINKS /* LOCKDIR should be subsumed by LOCKPREFIX */ lockname = fqname(lockname, LOCKPREFIX, 2); #endif #if defined(UNIX) || defined(VMS) if (unlink(lockname) < 0) HUP raw_printf("Can't unlink %s.", lockname); -# ifdef NO_FILE_LINKS - (void) nhclose(lockfd); -# endif +#ifdef NO_FILE_LINKS + (void) nhclose(lockfd); +#endif -#endif /* UNIX || VMS */ +#endif /* UNIX || VMS */ #if defined(AMIGA) || defined(WIN32) || defined(MSDOS) - if (lockptr) Close(lockptr); + if (lockptr) + Close(lockptr); DeleteFile(lockname); lockptr = 0; #endif /* AMIGA || WIN32 || MSDOS */ @@ -1800,22 +1811,21 @@ const char *filename; /* ---------- END FILE LOCKING HANDLING ----------- */ - /* ---------- BEGIN CONFIG FILE HANDLING ----------- */ const char *configfile = #ifdef UNIX - ".nethackrc"; + ".nethackrc"; #else -# if defined(MAC) || defined(__BEOS__) - "NetHack Defaults"; -# else -# if defined(MSDOS) || defined(WIN32) - "defaults.nh"; -# else - "NetHack.cnf"; -# endif -# endif +#if defined(MAC) || defined(__BEOS__) + "NetHack Defaults"; +#else +#if defined(MSDOS) || defined(WIN32) + "defaults.nh"; +#else + "NetHack.cnf"; +#endif +#endif #endif /* used for messaging */ @@ -1829,7 +1839,7 @@ char lastconfigfile[BUFSZ]; * the game will try the old name if there * is no defaults.nh. */ -const char *backward_compat_configfile = "nethack.cnf"; +const char *backward_compat_configfile = "nethack.cnf"; #endif #ifndef MFLOPPY @@ -1852,7 +1862,7 @@ int src; * (if relevant) */ if (filename) { #ifdef UNIX - if ((src!=SET_IN_SYS) && access(filename, 4) == -1) { + if ((src != SET_IN_SYS) && access(filename, 4) == -1) { /* 4 is R_OK on newer systems */ /* nasty sneaky attempt to read file through * NetHack's setuid permissions -- this is the only @@ -1860,60 +1870,60 @@ int src; * control (but SYSCF_FILE is not under the player's * control so it's OK). */ - raw_printf("Access to %s denied (%d).", - filename, errno); + raw_printf("Access to %s denied (%d).", filename, errno); wait_synch(); /* fall through to standard names */ } else #endif #ifdef PREFIXES_IN_USE - if (src == SET_IN_SYS) { - (void) strncpy(lastconfigfile, - fqname(filename, SYSCONFPREFIX, 0), BUFSZ-1); + if (src == SET_IN_SYS) { + (void) strncpy(lastconfigfile, fqname(filename, SYSCONFPREFIX, 0), + BUFSZ - 1); } else #endif - /* always honor sysconf first before anything else */ - (void) strncpy(lastconfigfile, filename, BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) - return(fp); - if ((fp = fopenp(filename, "r")) != (FILE *)0) { - return(fp); + /* always honor sysconf first before anything else */ + (void) strncpy(lastconfigfile, filename, BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) + return (fp); + if ((fp = fopenp(filename, "r")) != (FILE *) 0) { + return (fp); #if defined(UNIX) || defined(VMS) } else { /* access() above probably caught most problems for UNIX */ raw_printf("Couldn't open requested config file %s (%d).", - filename, errno); + filename, errno); wait_synch(); - /* fall through to standard names */ +/* fall through to standard names */ #endif } } #if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32) - if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0) - return(fp); - if ((fp = fopenp(configfile, "r")) != (FILE *)0) - return(fp); -# ifdef MSDOS - if ((fp = fopenp(fqname(backward_compat_configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0) - return(fp); - if ((fp = fopenp(backward_compat_configfile, "r")) != (FILE *)0) - return(fp); -# endif + if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *) 0) + return (fp); + if ((fp = fopenp(configfile, "r")) != (FILE *) 0) + return (fp); +#ifdef MSDOS + if ((fp = fopenp(fqname(backward_compat_configfile, CONFIGPREFIX, 0), + "r")) != (FILE *) 0) + return (fp); + if ((fp = fopenp(backward_compat_configfile, "r")) != (FILE *) 0) + return (fp); +#endif #else - /* constructed full path names don't need fqname() */ -# ifdef VMS +/* constructed full path names don't need fqname() */ +#ifdef VMS (void) strncpy(lastconfigfile, fqname("nethackini", CONFIGPREFIX, 0), - BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { - return(fp); + BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) { + return (fp); } - (void) strncpy(lastconfigfile,"sys$login:nethack.ini", BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { - return(fp); + (void) strncpy(lastconfigfile, "sys$login:nethack.ini", BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) { + return (fp); } envp = nh_getenv("HOME"); @@ -1922,58 +1932,57 @@ int src; else Sprintf(tmp_config, "%s%s", envp, "NetHack.cnf"); - (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(tmp_config, "r")) != (FILE *)0) - return(fp); -# else /* should be only UNIX left */ + (void) strncpy(lastconfigfile, tmp_config, BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(tmp_config, "r")) != (FILE *) 0) + return (fp); +#else /* should be only UNIX left */ envp = nh_getenv("HOME"); if (!envp) Strcpy(tmp_config, ".nethackrc"); else Sprintf(tmp_config, "%s/%s", envp, ".nethackrc"); - (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) - return(fp); -# if defined(__APPLE__) + (void) strncpy(lastconfigfile, tmp_config, BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) + return (fp); +#if defined(__APPLE__) /* try an alternative */ if (envp) { Sprintf(tmp_config, "%s/%s", envp, - "Library/Preferences/NetHack Defaults"); - (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) - return(fp); + "Library/Preferences/NetHack Defaults"); + (void) strncpy(lastconfigfile, tmp_config, BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) + return (fp); Sprintf(tmp_config, "%s/%s", envp, - "Library/Preferences/NetHack Defaults.txt"); - (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); - lastconfigfile[BUFSZ-1] = '\0'; - if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) - return(fp); + "Library/Preferences/NetHack Defaults.txt"); + (void) strncpy(lastconfigfile, tmp_config, BUFSZ - 1); + lastconfigfile[BUFSZ - 1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *) 0) + return (fp); } -# endif +#endif if (errno != ENOENT) { const char *details; - /* e.g., problems when setuid NetHack can't search home - * directory restricted to user */ +/* e.g., problems when setuid NetHack can't search home + * directory restricted to user */ -# if defined (NHSTDC) && !defined(NOTSTDC) +#if defined(NHSTDC) && !defined(NOTSTDC) if ((details = strerror(errno)) == 0) -# endif - details = ""; +#endif + details = ""; raw_printf("Couldn't open default config file %s %s(%d).", - lastconfigfile, details, errno); + lastconfigfile, details, errno); wait_synch(); } -# endif /* Unix */ +#endif /* Unix */ #endif - return (FILE *)0; + return (FILE *) 0; } - /* * Retrieve a list of integers from a file into a uchar array. * @@ -1982,56 +1991,68 @@ int src; */ STATIC_OVL int get_uchars(fp, buf, bufp, list, modlist, size, name) - FILE *fp; /* input file pointer */ - char *buf; /* read buffer, must be of size BUFSZ */ - char *bufp; /* current pointer */ - uchar *list; /* return list */ - boolean modlist; /* TRUE: list is being modified in place */ - int size; /* return list size */ - const char *name; /* name of option for error message */ +FILE *fp; /* input file pointer */ +char *buf; /* read buffer, must be of size BUFSZ */ +char *bufp; /* current pointer */ +uchar *list; /* return list */ +boolean modlist; /* TRUE: list is being modified in place */ +int size; /* return list size */ +const char *name; /* name of option for error message */ { unsigned int num = 0; int count = 0; boolean havenum = FALSE; while (1) { - switch(*bufp) { - case ' ': case '\0': - case '\t': case '\n': - if (havenum) { - /* if modifying in place, don't insert zeros */ - if (num || !modlist) list[count] = num; - count++; - num = 0; - havenum = FALSE; - } - if (count == size || !*bufp) return count; - bufp++; - break; + switch (*bufp) { + case ' ': + case '\0': + case '\t': + case '\n': + if (havenum) { + /* if modifying in place, don't insert zeros */ + if (num || !modlist) + list[count] = num; + count++; + num = 0; + havenum = FALSE; + } + if (count == size || !*bufp) + return count; + bufp++; + break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - havenum = TRUE; - num = num*10 + (*bufp-'0'); - bufp++; - break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + havenum = TRUE; + num = num * 10 + (*bufp - '0'); + bufp++; + break; case '\\': - if (fp == (FILE *)0) - goto gi_error; - do { - if (!fgets(buf, BUFSZ, fp)) goto gi_error; - } while (buf[0] == '#'); - bufp = buf; - break; + if (fp == (FILE *) 0) + goto gi_error; + do { + if (!fgets(buf, BUFSZ, fp)) + goto gi_error; + } while (buf[0] == '#'); + bufp = buf; + break; default: -gi_error: - raw_printf("Syntax error in %s", name); - wait_synch(); - return count; - } + gi_error: + raw_printf("Syntax error in %s", name); + wait_synch(); + return count; + } } /*NOTREACHED*/ } @@ -2044,24 +2065,26 @@ int prefixid; { char *ptr; - if (!bufp) return; - /* Backward compatibility, ignore trailing ;n */ - if ((ptr = index(bufp, ';')) != 0) *ptr = '\0'; + if (!bufp) + return; + /* Backward compatibility, ignore trailing ;n */ + if ((ptr = index(bufp, ';')) != 0) + *ptr = '\0'; if (strlen(bufp) > 0) { - fqn_prefix[prefixid] = (char *)alloc(strlen(bufp)+2); + fqn_prefix[prefixid] = (char *) alloc(strlen(bufp) + 2); Strcpy(fqn_prefix[prefixid], bufp); append_slash(fqn_prefix[prefixid]); } } #endif -#define match_varname(INP,NAM,LEN) match_optname(INP, NAM, LEN, TRUE) +#define match_varname(INP, NAM, LEN) match_optname(INP, NAM, LEN, TRUE) int parse_config_line(fp, origbuf, src) -FILE *fp; -char *origbuf; -int src; +FILE *fp; +char *origbuf; +int src; { #if defined(MICRO) && !defined(NOCWD_ASSUMPTIONS) static boolean ramdisk_specified = FALSE; @@ -2069,49 +2092,54 @@ int src; #ifdef SYSCF int n; #endif - char *bufp, *altp, buf[BUFSZ]; - uchar translate[MAXPCHARS]; - int len; + char *bufp, *altp, buf[BUFSZ]; + uchar translate[MAXPCHARS]; + int len; /* convert any tab to space, condense consecutive spaces into one, remove leading and trailing spaces (exception: if there is nothing but spaces, one of them will be kept even though it leads/trails) */ mungspaces(strcpy(buf, origbuf)); /* lines beginning with '#' are comments; accept empty lines too */ - if (!*buf || *buf == '#' || !strcmp(buf, " ")) return 1; + if (!*buf || *buf == '#' || !strcmp(buf, " ")) + return 1; /* find the '=' or ':' */ bufp = index(buf, '='); altp = index(buf, ':'); - if (!bufp || (altp && altp < bufp)) bufp = altp; - if (!bufp) return 0; + if (!bufp || (altp && altp < bufp)) + bufp = altp; + if (!bufp) + return 0; /* skip past '=', then space between it and value, if any */ ++bufp; - if (*bufp == ' ') ++bufp; + if (*bufp == ' ') + ++bufp; /* Go through possible variables */ /* some of these (at least LEVELS and SAVE) should now set the * appropriate fqn_prefix[] rather than specialized variables */ if (match_varname(buf, "OPTIONS", 4)) { - /* hack: un-mungspaces to allow consecutive spaces in - general options until we verify that this is unnecessary; - '=' or ':' is guaranteed to be present */ - bufp = index(origbuf, '='); - altp = index(origbuf, ':'); - if (!bufp || (altp && altp < bufp)) bufp = altp; - ++bufp; /* skip '='; parseoptions() handles spaces */ + /* hack: un-mungspaces to allow consecutive spaces in + general options until we verify that this is unnecessary; + '=' or ':' is guaranteed to be present */ + bufp = index(origbuf, '='); + altp = index(origbuf, ':'); + if (!bufp || (altp && altp < bufp)) + bufp = altp; + ++bufp; /* skip '='; parseoptions() handles spaces */ parseoptions(bufp, TRUE, TRUE); - if (plname[0]) /* If a name was given */ - plnamesuffix(); /* set the character class */ + if (plname[0]) /* If a name was given */ + plnamesuffix(); /* set the character class */ } else if (match_varname(buf, "AUTOPICKUP_EXCEPTION", 5)) { add_autopickup_exception(bufp); #ifdef NOCWD_ASSUMPTIONS } else if (match_varname(buf, "HACKDIR", 4)) { adjust_prefix(bufp, HACKPREFIX); - } else if (match_varname(buf, "LEVELDIR", 4) || - match_varname(buf, "LEVELS", 4)) { + } else if (match_varname(buf, "LEVELDIR", 4) + || match_varname(buf, "LEVELS", 4)) { adjust_prefix(bufp, LEVELPREFIX); } else if (match_varname(buf, "SAVEDIR", 4)) { adjust_prefix(bufp, SAVEPREFIX); @@ -2128,94 +2156,104 @@ int src; } else if (match_varname(buf, "TROUBLEDIR", 4)) { adjust_prefix(bufp, TROUBLEPREFIX); #else /*NOCWD_ASSUMPTIONS*/ -# ifdef MICRO +#ifdef MICRO } else if (match_varname(buf, "HACKDIR", 4)) { - (void) strncpy(hackdir, bufp, PATHLEN-1); -# ifdef MFLOPPY + (void) strncpy(hackdir, bufp, PATHLEN - 1); +#ifdef MFLOPPY } else if (match_varname(buf, "RAMDISK", 3)) { - /* The following ifdef is NOT in the wrong - * place. For now, we accept and silently - * ignore RAMDISK */ -# ifndef AMIGA - if (strlen(bufp) >= PATHLEN) bufp[PATHLEN-1] = '\0'; +/* The following ifdef is NOT in the wrong + * place. For now, we accept and silently + * ignore RAMDISK */ +#ifndef AMIGA + if (strlen(bufp) >= PATHLEN) + bufp[PATHLEN - 1] = '\0'; Strcpy(levels, bufp); ramdisk = (strcmp(permbones, levels) != 0); ramdisk_specified = TRUE; -# endif -# endif +#endif +#endif } else if (match_varname(buf, "LEVELS", 4)) { - if (strlen(bufp) >= PATHLEN) bufp[PATHLEN-1] = '\0'; + if (strlen(bufp) >= PATHLEN) + bufp[PATHLEN - 1] = '\0'; Strcpy(permbones, bufp); - if (!ramdisk_specified || !*levels) Strcpy(levels, bufp); + if (!ramdisk_specified || !*levels) + Strcpy(levels, bufp); ramdisk = (strcmp(permbones, levels) != 0); } else if (match_varname(buf, "SAVE", 4)) { -# ifdef MFLOPPY - extern int saveprompt; -# endif +#ifdef MFLOPPY + extern int saveprompt; +#endif char *ptr; if ((ptr = index(bufp, ';')) != 0) { *ptr = '\0'; -# ifdef MFLOPPY - if (*(ptr+1) == 'n' || *(ptr+1) == 'N') { +#ifdef MFLOPPY + if (*(ptr + 1) == 'n' || *(ptr + 1) == 'N') { saveprompt = FALSE; } -# endif +#endif } -# if defined(SYSFLAGS) && defined(MFLOPPY) +#if defined(SYSFLAGS) && defined(MFLOPPY) else saveprompt = sysflags.asksavedisk; -# endif +#endif - (void) strncpy(SAVEP, bufp, SAVESIZE-1); + (void) strncpy(SAVEP, bufp, SAVESIZE - 1); append_slash(SAVEP); -# endif /* MICRO */ +#endif /* MICRO */ #endif /*NOCWD_ASSUMPTIONS*/ } else if (match_varname(buf, "NAME", 4)) { - (void) strncpy(plname, bufp, PL_NSIZ-1); + (void) strncpy(plname, bufp, PL_NSIZ - 1); plnamesuffix(); - } else if (match_varname(buf, "ROLE", 4) || - match_varname(buf, "CHARACTER", 4)) { + } else if (match_varname(buf, "ROLE", 4) + || match_varname(buf, "CHARACTER", 4)) { if ((len = str2role(bufp)) >= 0) flags.initrole = len; } else if (match_varname(buf, "DOGNAME", 3)) { - (void) strncpy(dogname, bufp, PL_PSIZ-1); + (void) strncpy(dogname, bufp, PL_PSIZ - 1); } else if (match_varname(buf, "CATNAME", 3)) { - (void) strncpy(catname, bufp, PL_PSIZ-1); + (void) strncpy(catname, bufp, PL_PSIZ - 1); #ifdef SYSCF } else if (src == SET_IN_SYS && match_varname(buf, "WIZARDS", 7)) { - if (sysopt.wizards) free(sysopt.wizards); + if (sysopt.wizards) + free(sysopt.wizards); sysopt.wizards = dupstr(bufp); } else if (src == SET_IN_SYS && match_varname(buf, "SHELLERS", 8)) { - if (sysopt.shellers) free(sysopt.shellers); + if (sysopt.shellers) + free(sysopt.shellers); sysopt.shellers = dupstr(bufp); } else if (src == SET_IN_SYS && match_varname(buf, "EXPLORERS", 7)) { - if (sysopt.explorers) free(sysopt.explorers); - sysopt.explorers = dupstr(bufp); + if (sysopt.explorers) + free(sysopt.explorers); + sysopt.explorers = dupstr(bufp); } else if (src == SET_IN_SYS && match_varname(buf, "DEBUGFILES", 5)) { /* if showdebug() has already been called (perhaps we've added some debugpline() calls to option processing) and has found a value for getenv("DEBUGFILES"), don't override that */ if (sysopt.env_dbgfl == 0) { - if (sysopt.debugfiles) free(sysopt.debugfiles); - sysopt.debugfiles = dupstr(bufp); - } + if (sysopt.debugfiles) + free(sysopt.debugfiles); + sysopt.debugfiles = dupstr(bufp); + } } else if (src == SET_IN_SYS && match_varname(buf, "SUPPORT", 7)) { - if (sysopt.support) free(sysopt.support); + if (sysopt.support) + free(sysopt.support); sysopt.support = dupstr(bufp); } else if (src == SET_IN_SYS && match_varname(buf, "RECOVER", 7)) { - if (sysopt.recover) free(sysopt.recover); + if (sysopt.recover) + free(sysopt.recover); sysopt.recover = dupstr(bufp); - } else if (src == SET_IN_SYS && match_varname(buf, "CHECK_SAVE_UID", 14)) { - n = atoi(bufp); - sysopt.check_save_uid = n; + } else if (src == SET_IN_SYS + && match_varname(buf, "CHECK_SAVE_UID", 14)) { + n = atoi(bufp); + sysopt.check_save_uid = n; } else if (match_varname(buf, "SEDUCE", 6)) { - n = !!atoi(bufp); /* XXX this could be tighter */ + n = !!atoi(bufp); /* XXX this could be tighter */ /* allow anyone to turn it off, but only sysconf to turn it on*/ if (src != SET_IN_SYS && n != 0) { - raw_printf("Illegal value in SEDUCE"); - return 0; + raw_printf("Illegal value in SEDUCE"); + return 0; } sysopt.seduce = n; sysopt_seduce_set(sysopt.seduce); @@ -2223,88 +2261,92 @@ int src; n = atoi(bufp); /* XXX to get more than 25, need to rewrite all lock code */ if (n < 1 || n > 25) { - raw_printf("Illegal value in MAXPLAYERS (maximum is 25)."); - return 0; + raw_printf("Illegal value in MAXPLAYERS (maximum is 25)."); + return 0; } sysopt.maxplayers = n; } else if (src == SET_IN_SYS && match_varname(buf, "PERSMAX", 7)) { n = atoi(bufp); if (n < 1) { - raw_printf("Illegal value in PERSMAX (minimum is 1)."); - return 0; + raw_printf("Illegal value in PERSMAX (minimum is 1)."); + return 0; } sysopt.persmax = n; } else if (src == SET_IN_SYS && match_varname(buf, "PERS_IS_UID", 11)) { n = atoi(bufp); if (n != 0 && n != 1) { - raw_printf("Illegal value in PERS_IS_UID (must be 0 or 1)."); - return 0; + raw_printf("Illegal value in PERS_IS_UID (must be 0 or 1)."); + return 0; } sysopt.pers_is_uid = n; } else if (src == SET_IN_SYS && match_varname(buf, "ENTRYMAX", 8)) { n = atoi(bufp); if (n < 10) { - raw_printf("Illegal value in ENTRYMAX (minimum is 10)."); - return 0; + raw_printf("Illegal value in ENTRYMAX (minimum is 10)."); + return 0; } sysopt.entrymax = n; - } else if ( (src==SET_IN_SYS) && match_varname(buf, "POINTSMIN", 9)) { + } else if ((src == SET_IN_SYS) && match_varname(buf, "POINTSMIN", 9)) { n = atoi(bufp); if (n < 1) { - raw_printf("Illegal value in POINTSMIN (minimum is 1)."); - return 0; + raw_printf("Illegal value in POINTSMIN (minimum is 1)."); + return 0; } sysopt.pointsmin = n; - } else if (src == SET_IN_SYS && match_varname(buf, "MAX_STATUENAME_RANK", 10)) { + } else if (src == SET_IN_SYS + && match_varname(buf, "MAX_STATUENAME_RANK", 10)) { n = atoi(bufp); if (n < 1) { - raw_printf("Illegal value in MAX_STATUENAME_RANK (minimum is 1)."); - return 0; + raw_printf( + "Illegal value in MAX_STATUENAME_RANK (minimum is 1)."); + return 0; } sysopt.tt_oname_maxrank = n; -# ifdef PANICTRACE - } else if (src == SET_IN_SYS && - match_varname(buf, "PANICTRACE_LIBC", 15)) { -# ifdef PANICTRACE_LIBC +#ifdef PANICTRACE + } else if (src == SET_IN_SYS + && match_varname(buf, "PANICTRACE_LIBC", 15)) { +#ifdef PANICTRACE_LIBC n = atoi(bufp); if (n < 0 || n > 2) { - raw_printf("Illegal value in PANICTRACE_LIBC (not 0,1,2)."); - return 0; + raw_printf("Illegal value in PANICTRACE_LIBC (not 0,1,2)."); + return 0; } sysopt.panictrace_libc = n; -# endif /* PANICTRACE_LIBC */ - } else if (src == SET_IN_SYS && - match_varname(buf, "PANICTRACE_GDB", 14)) { +#endif /* PANICTRACE_LIBC */ + } else if (src == SET_IN_SYS + && match_varname(buf, "PANICTRACE_GDB", 14)) { n = atoi(bufp); if (n < 0 || n > 2) { - raw_printf("Illegal value in PANICTRACE_GDB (not 0,1,2)."); - return 0; + raw_printf("Illegal value in PANICTRACE_GDB (not 0,1,2)."); + return 0; } sysopt.panictrace_gdb = n; } else if (src == SET_IN_SYS && match_varname(buf, "GDBPATH", 7)) { if (!file_exists(bufp)) { - raw_printf("File specified in GDBPATH does not exist."); - return 0; + raw_printf("File specified in GDBPATH does not exist."); + return 0; } - if (sysopt.gdbpath) free(sysopt.gdbpath); + if (sysopt.gdbpath) + free(sysopt.gdbpath); sysopt.gdbpath = dupstr(bufp); } else if (src == SET_IN_SYS && match_varname(buf, "GREPPATH", 7)) { if (!file_exists(bufp)) { - raw_printf("File specified in GREPPATH does not exist."); - return 0; + raw_printf("File specified in GREPPATH does not exist."); + return 0; } - if (sysopt.greppath) free(sysopt.greppath); + if (sysopt.greppath) + free(sysopt.greppath); sysopt.greppath = dupstr(bufp); -# endif /* PANICTRACE */ +#endif /* PANICTRACE */ #endif /* SYSCF */ } else if (match_varname(buf, "BOULDER", 3)) { - (void) get_uchars(fp, buf, bufp, &iflags.bouldersym, TRUE, - 1, "BOULDER"); - } else if (match_varname(buf, "MENUCOLOR", 9)) { - (void) add_menu_coloring(bufp); + (void) get_uchars(fp, buf, bufp, &iflags.bouldersym, TRUE, 1, + "BOULDER"); + } else if (match_varname(buf, "MENUCOLOR", 9)) { + (void) add_menu_coloring(bufp); } else if (match_varname(buf, "WARNINGS", 5)) { - (void) get_uchars(fp, buf, bufp, translate, FALSE, - WARNCOUNT, "WARNINGS"); + (void) get_uchars(fp, buf, bufp, translate, FALSE, WARNCOUNT, + "WARNINGS"); assign_warnings(translate); } else if (match_varname(buf, "SYMBOLS", 4)) { char *op, symbuf[BUFSZ]; @@ -2313,141 +2355,133 @@ int src; do { /* check for line continuation (trailing '\') */ op = eos(bufp); - morelines = (--op >= bufp && *op == '\\'); - if (morelines) { + morelines = (--op >= bufp && *op == '\\'); + if (morelines) { *op = '\0'; /* strip trailing space now that '\' is gone */ - if (--op >= bufp && *op == ' ') *op = '\0'; + if (--op >= bufp && *op == ' ') + *op = '\0'; } /* parse here */ - parsesymbols(bufp); + parsesymbols(bufp); if (morelines) { - do { - *symbuf = '\0'; - if (!fgets(symbuf, BUFSZ, fp)) { - morelines = FALSE; - break; - } - mungspaces(symbuf); - bufp = symbuf; - } while (*bufp == '#'); - } + do { + *symbuf = '\0'; + if (!fgets(symbuf, BUFSZ, fp)) { + morelines = FALSE; + break; + } + mungspaces(symbuf); + bufp = symbuf; + } while (*bufp == '#'); + } } while (morelines); switch_symbols(TRUE); } else if (match_varname(buf, "WIZKIT", 6)) { - (void) strncpy(wizkit, bufp, WIZKIT_MAX-1); + (void) strncpy(wizkit, bufp, WIZKIT_MAX - 1); #ifdef AMIGA } else if (match_varname(buf, "FONT", 4)) { char *t; - if( t = strchr( buf+5, ':' ) ) - { + if (t = strchr(buf + 5, ':')) { *t = 0; - amii_set_text_font( buf+5, atoi( t + 1 ) ); + amii_set_text_font(buf + 5, atoi(t + 1)); *t = ':'; } } else if (match_varname(buf, "PATH", 4)) { - (void) strncpy(PATH, bufp, PATHLEN-1); + (void) strncpy(PATH, bufp, PATHLEN - 1); } else if (match_varname(buf, "DEPTH", 5)) { extern int amii_numcolors; - int val = atoi( bufp ); - amii_numcolors = 1L << min( DEPTH, val ); -# ifdef SYSFLAGS + int val = atoi(bufp); + amii_numcolors = 1L << min(DEPTH, val); +#ifdef SYSFLAGS } else if (match_varname(buf, "DRIPENS", 7)) { int i, val; char *t; - for (i = 0, t = strtok(bufp, ",/"); t != (char *)0; - i < 20 && (t = strtok((char*)0, ",/")), ++i) { - sscanf(t, "%d", &val ); + for (i = 0, t = strtok(bufp, ",/"); t != (char *) 0; + i < 20 && (t = strtok((char *) 0, ",/")), ++i) { + sscanf(t, "%d", &val); sysflags.amii_dripens[i] = val; } -# endif - } else if (match_varname(buf, "SCREENMODE", 10 )) { +#endif + } else if (match_varname(buf, "SCREENMODE", 10)) { extern long amii_scrnmode; - if (!stricmp(bufp,"req")) + if (!stricmp(bufp, "req")) amii_scrnmode = 0xffffffff; /* Requester */ - else if( sscanf(bufp, "%x", &amii_scrnmode) != 1 ) + else if (sscanf(bufp, "%x", &amii_scrnmode) != 1) amii_scrnmode = 0; } else if (match_varname(buf, "MSGPENS", 7)) { extern int amii_msgAPen, amii_msgBPen; char *t = strtok(bufp, ",/"); - if( t ) - { + if (t) { sscanf(t, "%d", &amii_msgAPen); - if( t = strtok((char*)0, ",/") ) + if (t = strtok((char *) 0, ",/")) sscanf(t, "%d", &amii_msgBPen); } } else if (match_varname(buf, "TEXTPENS", 8)) { extern int amii_textAPen, amii_textBPen; char *t = strtok(bufp, ",/"); - if( t ) - { + if (t) { sscanf(t, "%d", &amii_textAPen); - if( t = strtok((char*)0, ",/") ) + if (t = strtok((char *) 0, ",/")) sscanf(t, "%d", &amii_textBPen); } } else if (match_varname(buf, "MENUPENS", 8)) { extern int amii_menuAPen, amii_menuBPen; char *t = strtok(bufp, ",/"); - if( t ) - { + if (t) { sscanf(t, "%d", &amii_menuAPen); - if( t = strtok((char*)0, ",/") ) + if (t = strtok((char *) 0, ",/")) sscanf(t, "%d", &amii_menuBPen); } } else if (match_varname(buf, "STATUSPENS", 10)) { extern int amii_statAPen, amii_statBPen; char *t = strtok(bufp, ",/"); - if( t ) - { + if (t) { sscanf(t, "%d", &amii_statAPen); - if( t = strtok((char*)0, ",/") ) + if (t = strtok((char *) 0, ",/")) sscanf(t, "%d", &amii_statBPen); } } else if (match_varname(buf, "OTHERPENS", 9)) { extern int amii_otherAPen, amii_otherBPen; char *t = strtok(bufp, ",/"); - if( t ) - { + if (t) { sscanf(t, "%d", &amii_otherAPen); - if( t = strtok((char*)0, ",/") ) + if (t = strtok((char *) 0, ",/")) sscanf(t, "%d", &amii_otherBPen); } } else if (match_varname(buf, "PENS", 4)) { - extern unsigned short amii_init_map[ AMII_MAXCOLORS ]; + extern unsigned short amii_init_map[AMII_MAXCOLORS]; int i; char *t; for (i = 0, t = strtok(bufp, ",/"); - i < AMII_MAXCOLORS && t != (char *)0; - t = strtok((char *)0, ",/"), ++i) - { + i < AMII_MAXCOLORS && t != (char *) 0; + t = strtok((char *) 0, ",/"), ++i) { sscanf(t, "%hx", &amii_init_map[i]); } - amii_setpens( amii_numcolors = i ); + amii_setpens(amii_numcolors = i); } else if (match_varname(buf, "FGPENS", 6)) { - extern int foreg[ AMII_MAXCOLORS ]; + extern int foreg[AMII_MAXCOLORS]; int i; char *t; for (i = 0, t = strtok(bufp, ",/"); - i < AMII_MAXCOLORS && t != (char *)0; - t = strtok((char *)0, ",/"), ++i) - { + i < AMII_MAXCOLORS && t != (char *) 0; + t = strtok((char *) 0, ",/"), ++i) { sscanf(t, "%d", &foreg[i]); } } else if (match_varname(buf, "BGPENS", 6)) { - extern int backg[ AMII_MAXCOLORS ]; + extern int backg[AMII_MAXCOLORS]; int i; char *t; for (i = 0, t = strtok(bufp, ",/"); - i < AMII_MAXCOLORS && t != (char *)0; - t = strtok((char *)0, ",/"), ++i) - { + i < AMII_MAXCOLORS && t != (char *) 0; + t = strtok((char *) 0, ",/"), ++i) { sscanf(t, "%d", &backg[i]); } -#endif /*AMIGA*/ +#endif /*AMIGA*/ #ifdef USER_SOUNDS } else if (match_varname(buf, "SOUNDDIR", 8)) { sounddir = dupstr(bufp); @@ -2455,14 +2489,14 @@ int src; add_sound_mapping(bufp); #endif #ifdef QT_GRAPHICS - /* These should move to wc_ options */ + /* These should move to wc_ options */ } else if (match_varname(buf, "QT_TILEWIDTH", 12)) { extern char *qt_tilewidth; - if (qt_tilewidth == NULL) + if (qt_tilewidth == NULL) qt_tilewidth = dupstr(bufp); } else if (match_varname(buf, "QT_TILEHEIGHT", 13)) { extern char *qt_tileheight; - if (qt_tileheight == NULL) + if (qt_tileheight == NULL) qt_tileheight = dupstr(bufp); } else if (match_varname(buf, "QT_FONTSIZE", 11)) { extern char *qt_fontsize; @@ -2491,11 +2525,12 @@ read_config_file(filename, src) const char *filename; int src; { - char buf[4*BUFSZ]; - FILE *fp; - boolean rv = TRUE; /* assume successful parse */ + char buf[4 * BUFSZ]; + FILE *fp; + boolean rv = TRUE; /* assume successful parse */ - if (!(fp = fopen_config_file(filename, src))) return FALSE; + if (!(fp = fopen_config_file(filename, src))) + return FALSE; /* begin detection of duplicate configfile options */ set_duplicate_opt_detection(1); @@ -2503,19 +2538,20 @@ int src; while (fgets(buf, sizeof buf, fp)) { #ifdef notyet /* -XXX Don't call read() in parse_config_line, read as callback or reassemble line +XXX Don't call read() in parse_config_line, read as callback or reassemble +line at this level. OR: Forbid multiline stuff for alternate config sources. */ #endif if (!parse_config_line(fp, buf, src)) { - raw_printf("Bad option line: \"%.50s\"", buf); - wait_synch(); - rv = FALSE; + raw_printf("Bad option line: \"%.50s\"", buf); + wait_synch(); + rv = FALSE; } } (void) fclose(fp); - + /* turn off detection of duplicate configfile options */ set_duplicate_opt_detection(0); return rv; @@ -2526,13 +2562,15 @@ fopen_wizkit_file() { FILE *fp; #if defined(VMS) || defined(UNIX) - char tmp_wizkit[BUFSZ]; + char tmp_wizkit[BUFSZ]; #endif char *envp; envp = nh_getenv("WIZKIT"); - if (envp && *envp) (void) strncpy(wizkit, envp, WIZKIT_MAX - 1); - if (!wizkit[0]) return (FILE *)0; + if (envp && *envp) + (void) strncpy(wizkit, envp, WIZKIT_MAX - 1); + if (!wizkit[0]) + return (FILE *) 0; #ifdef UNIX if (access(wizkit, 4) == -1) { @@ -2542,53 +2580,52 @@ fopen_wizkit_file() * place a file name may be wholly under the player's * control */ - raw_printf("Access to %s denied (%d).", - wizkit, errno); + raw_printf("Access to %s denied (%d).", wizkit, errno); wait_synch(); /* fall through to standard names */ } else #endif - if ((fp = fopenp(wizkit, "r")) != (FILE *)0) { - return(fp); + if ((fp = fopenp(wizkit, "r")) != (FILE *) 0) { + return (fp); #if defined(UNIX) || defined(VMS) } else { /* access() above probably caught most problems for UNIX */ - raw_printf("Couldn't open requested config file %s (%d).", - wizkit, errno); + raw_printf("Couldn't open requested config file %s (%d).", wizkit, + errno); wait_synch(); #endif } #if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32) - if ((fp = fopenp(fqname(wizkit, CONFIGPREFIX, 0), "r")) - != (FILE *)0) - return(fp); + if ((fp = fopenp(fqname(wizkit, CONFIGPREFIX, 0), "r")) != (FILE *) 0) + return (fp); #else -# ifdef VMS +#ifdef VMS envp = nh_getenv("HOME"); if (envp) Sprintf(tmp_wizkit, "%s%s", envp, wizkit); else Sprintf(tmp_wizkit, "%s%s", "sys$login:", wizkit); - if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *)0) - return(fp); -# else /* should be only UNIX left */ + if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *) 0) + return (fp); +#else /* should be only UNIX left */ envp = nh_getenv("HOME"); if (envp) Sprintf(tmp_wizkit, "%s/%s", envp, wizkit); - else Strcpy(tmp_wizkit, wizkit); - if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *)0) - return(fp); + else + Strcpy(tmp_wizkit, wizkit); + if ((fp = fopenp(tmp_wizkit, "r")) != (FILE *) 0) + return (fp); else if (errno != ENOENT) { /* e.g., problems when setuid NetHack can't search home * directory restricted to user */ - raw_printf("Couldn't open default wizkit file %s (%d).", - tmp_wizkit, errno); + raw_printf("Couldn't open default wizkit file %s (%d).", tmp_wizkit, + errno); wait_synch(); } -# endif #endif - return (FILE *)0; +#endif + return (FILE *) 0; } /* add to hero's inventory if there's room, otherwise put item on floor */ @@ -2596,22 +2633,25 @@ STATIC_DCL void wizkit_addinv(obj) struct obj *obj; { - if (!obj || obj == &zeroobj) return; + if (!obj || obj == &zeroobj) + return; /* subset of starting inventory pre-ID */ obj->dknown = 1; - if (Role_if(PM_PRIEST)) obj->bknown = 1; + if (Role_if(PM_PRIEST)) + obj->bknown = 1; /* same criteria as lift_object()'s check for available inventory slot */ - if (obj->oclass != COIN_CLASS && - inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) { - /* inventory overflow; can't just place & stack object since - hero isn't in position yet, so schedule for arrival later */ - add_to_migration(obj); - obj->ox = 0; /* index of main dungeon */ - obj->oy = 1; /* starting level number */ - obj->owornmask = (long)(MIGR_WITH_HERO | MIGR_NOBREAK|MIGR_NOSCATTER); + if (obj->oclass != COIN_CLASS && inv_cnt(FALSE) >= 52 + && !merge_choice(invent, obj)) { + /* inventory overflow; can't just place & stack object since + hero isn't in position yet, so schedule for arrival later */ + add_to_migration(obj); + obj->ox = 0; /* index of main dungeon */ + obj->oy = 1; /* starting level number */ + obj->owornmask = + (long) (MIGR_WITH_HERO | MIGR_NOBREAK | MIGR_NOSCATTER); } else { - (void)addinv(obj); + (void) addinv(obj); } } @@ -2623,29 +2663,33 @@ read_wizkit() struct obj *otmp; boolean bad_items = FALSE, skip = FALSE; - if (!wizard || !(fp = fopen_wizkit_file())) return; + if (!wizard || !(fp = fopen_wizkit_file())) + return; program_state.wizkit_wishing = 1; - while (fgets(buf, (int)(sizeof buf), fp)) { + while (fgets(buf, (int) (sizeof buf), fp)) { ep = index(buf, '\n'); - if (skip) { /* in case previous line was too long */ - if (ep) skip = FALSE; /* found newline; next line is normal */ + if (skip) { /* in case previous line was too long */ + if (ep) + skip = FALSE; /* found newline; next line is normal */ } else { - if (!ep) skip = TRUE; /* newline missing; discard next fgets */ - else *ep = '\0'; /* remove newline */ + if (!ep) + skip = TRUE; /* newline missing; discard next fgets */ + else + *ep = '\0'; /* remove newline */ - if (buf[0]) { - otmp = readobjnam(buf, (struct obj *)0); - if (otmp) { - if (otmp != &zeroobj) - wizkit_addinv(otmp); - } else { - /* .60 limits output line width to 79 chars */ - raw_printf("Bad wizkit item: \"%.60s\"", buf); - bad_items = TRUE; + if (buf[0]) { + otmp = readobjnam(buf, (struct obj *) 0); + if (otmp) { + if (otmp != &zeroobj) + wizkit_addinv(otmp); + } else { + /* .60 limits output line width to 79 chars */ + raw_printf("Bad wizkit item: \"%.60s\"", buf); + bad_items = TRUE; + } } } - } } program_state.wizkit_wishing = 0; if (bad_items) @@ -2654,11 +2698,11 @@ read_wizkit() return; } -extern struct symsetentry *symset_list; /* options.c */ -extern struct symparse loadsyms[]; /* drawing.c */ -extern const char *known_handling[]; /* drawing.c */ -extern const char *known_restrictions[]; /* drawing.c */ -static int symset_count = 0; /* for pick-list building only */ +extern struct symsetentry *symset_list; /* options.c */ +extern struct symparse loadsyms[]; /* drawing.c */ +extern const char *known_handling[]; /* drawing.c */ +extern const char *known_restrictions[]; /* drawing.c */ +static int symset_count = 0; /* for pick-list building only */ static boolean chosen_symset_start = FALSE, chosen_symset_end = FALSE; STATIC_OVL @@ -2679,14 +2723,15 @@ int read_sym_file(which_set) int which_set; { - char buf[4*BUFSZ]; + char buf[4 * BUFSZ]; FILE *fp; - if (!(fp = fopen_sym_file())) return 0; + if (!(fp = fopen_sym_file())) + return 0; symset_count = 0; chosen_symset_start = chosen_symset_end = FALSE; - while (fgets(buf, 4*BUFSZ, fp)) { + while (fgets(buf, 4 * BUFSZ, fp)) { if (!parse_sym_line(buf, which_set)) { raw_printf("Bad symbol line: \"%.50s\"", buf); wait_synch(); @@ -2697,8 +2742,8 @@ int which_set; return (symset[which_set].name == 0) ? 1 : 0; if (!chosen_symset_end) { raw_printf("Missing finish for symset \"%s\"", - symset[which_set].name ? - symset[which_set].name : "unknown"); + symset[which_set].name ? symset[which_set].name + : "unknown"); wait_synch(); } return 1; @@ -2711,7 +2756,7 @@ char *buf; int which_set; { int val, i; - struct symparse *symp = (struct symparse *)0; + struct symparse *symp = (struct symparse *) 0; char *bufp, *commentp, *altp; /* convert each instance of whitespace (tabs, consecutive spaces) @@ -2722,28 +2767,31 @@ int which_set; /* remove trailing comment, if any */ if ((commentp = rindex(buf, '#')) != 0) { *commentp = '\0'; - /* remove space preceding the stripped comment, if any; - we know 'commentp > buf' because *buf=='#' was caught above */ - if (commentp[-1] == ' ') *--commentp = '\0'; + /* remove space preceding the stripped comment, if any; + we know 'commentp > buf' because *buf=='#' was caught above */ + if (commentp[-1] == ' ') + *--commentp = '\0'; } /* find the '=' or ':' */ bufp = index(buf, '='); altp = index(buf, ':'); - if (!bufp || (altp && altp < bufp)) bufp = altp; + if (!bufp || (altp && altp < bufp)) + bufp = altp; if (!bufp) { if (strncmpi(buf, "finish", 6) == 0) { - /* end current graphics set */ - if (chosen_symset_start) - chosen_symset_end = TRUE; - chosen_symset_start = FALSE; - return 1; + /* end current graphics set */ + if (chosen_symset_start) + chosen_symset_end = TRUE; + chosen_symset_start = FALSE; + return 1; } return 0; } /* skip '=' and space which follows, if any */ ++bufp; - if (*bufp == ' ') ++bufp; + if (*bufp == ' ') + ++bufp; symp = match_sym(buf); if (!symp) @@ -2754,81 +2802,86 @@ int which_set; building a pick-list of possible symset values from the file, so only do that */ if (symp->range == SYM_CONTROL) { - struct symsetentry *tmpsp; - switch (symp->idx) { - case 0: - tmpsp = (struct symsetentry *)alloc(sizeof(struct symsetentry)); - tmpsp->next = (struct symsetentry *)0; - if (!symset_list) { - symset_list = tmpsp; - symset_count = 0; - } else { - symset_count++; - tmpsp->next = symset_list; - symset_list = tmpsp; - } - tmpsp->idx = symset_count; - tmpsp->name = dupstr(bufp); - tmpsp->desc = (char *)0; - tmpsp->nocolor = 0; - /* initialize restriction bits */ - tmpsp->primary = 0; - tmpsp->rogue = 0; - break; - case 2: - /* handler type identified */ - tmpsp = symset_list; /* most recent symset */ - tmpsp->handling = H_UNK; - i = 0; - while (known_handling[i]) { - if (!strcmpi(known_handling[i], bufp)) { - tmpsp->handling = i; - break; /* while loop */ - } - i++; - } - break; - case 3: /* description:something */ - tmpsp = symset_list; /* most recent symset */ - if (tmpsp && !tmpsp->desc) - tmpsp->desc = dupstr(bufp); - break; - case 5: - /* restrictions: xxxx*/ - tmpsp = symset_list; /* most recent symset */ - for (i = 0; known_restrictions[i]; ++i) { - if (!strcmpi(known_restrictions[i], bufp)) { - switch(i) { - case 0: tmpsp->primary = 1; break; - case 1: tmpsp->rogue = 1; break; + struct symsetentry *tmpsp; + switch (symp->idx) { + case 0: + tmpsp = + (struct symsetentry *) alloc(sizeof(struct symsetentry)); + tmpsp->next = (struct symsetentry *) 0; + if (!symset_list) { + symset_list = tmpsp; + symset_count = 0; + } else { + symset_count++; + tmpsp->next = symset_list; + symset_list = tmpsp; } - break; /* while loop */ + tmpsp->idx = symset_count; + tmpsp->name = dupstr(bufp); + tmpsp->desc = (char *) 0; + tmpsp->nocolor = 0; + /* initialize restriction bits */ + tmpsp->primary = 0; + tmpsp->rogue = 0; + break; + case 2: + /* handler type identified */ + tmpsp = symset_list; /* most recent symset */ + tmpsp->handling = H_UNK; + i = 0; + while (known_handling[i]) { + if (!strcmpi(known_handling[i], bufp)) { + tmpsp->handling = i; + break; /* while loop */ } - } - break; + i++; + } + break; + case 3: /* description:something */ + tmpsp = symset_list; /* most recent symset */ + if (tmpsp && !tmpsp->desc) + tmpsp->desc = dupstr(bufp); + break; + case 5: + /* restrictions: xxxx*/ + tmpsp = symset_list; /* most recent symset */ + for (i = 0; known_restrictions[i]; ++i) { + if (!strcmpi(known_restrictions[i], bufp)) { + switch (i) { + case 0: + tmpsp->primary = 1; + break; + case 1: + tmpsp->rogue = 1; + break; + } + break; /* while loop */ + } + } + break; } } return 1; } if (symp->range) { if (symp->range == SYM_CONTROL) { - switch(symp->idx) { + switch (symp->idx) { case 0: /* start of symset */ if (!strcmpi(bufp, symset[which_set].name)) { - /* matches desired one */ - chosen_symset_start = TRUE; - /* these init_*() functions clear symset fields too */ - if (which_set == ROGUESET) - init_r_symbols(); - else if (which_set == PRIMARY) - init_l_symbols(); + /* matches desired one */ + chosen_symset_start = TRUE; + /* these init_*() functions clear symset fields too */ + if (which_set == ROGUESET) + init_r_symbols(); + else if (which_set == PRIMARY) + init_l_symbols(); } break; case 1: /* finish symset */ if (chosen_symset_start) - chosen_symset_end = TRUE; + chosen_symset_end = TRUE; chosen_symset_start = FALSE; break; case 2: @@ -2836,48 +2889,49 @@ int which_set; if (chosen_symset_start) set_symhandling(bufp, which_set); break; - /* case 3: (description) is ignored here */ - case 4: /* color:off */ + /* case 3: (description) is ignored here */ + case 4: /* color:off */ if (chosen_symset_start) { if (bufp) { - if (!strcmpi(bufp, "true") || - !strcmpi(bufp, "yes") || - !strcmpi(bufp, "on")) - symset[which_set].nocolor = 0; - else if (!strcmpi(bufp, "false") || - !strcmpi(bufp, "no") || - !strcmpi(bufp, "off")) - symset[which_set].nocolor = 1; + if (!strcmpi(bufp, "true") || !strcmpi(bufp, "yes") + || !strcmpi(bufp, "on")) + symset[which_set].nocolor = 0; + else if (!strcmpi(bufp, "false") + || !strcmpi(bufp, "no") + || !strcmpi(bufp, "off")) + symset[which_set].nocolor = 1; } } break; - case 5: /* restrictions: xxxx*/ + case 5: /* restrictions: xxxx*/ if (chosen_symset_start) { int n = 0; while (known_restrictions[n]) { - if (!strcmpi(known_restrictions[n], bufp)) { - switch(n) { - case 0: symset[which_set].primary = 1; - break; - case 1: symset[which_set].rogue = 1; - break; - } - break; /* while loop */ - } - n++; - } + if (!strcmpi(known_restrictions[n], bufp)) { + switch (n) { + case 0: + symset[which_set].primary = 1; + break; + case 1: + symset[which_set].rogue = 1; + break; + } + break; /* while loop */ + } + n++; + } } break; - } - } else { /* !SYM_CONTROL */ - val = sym_val(bufp); - if (chosen_symset_start) { - if (which_set == PRIMARY) { - update_l_symset(symp, val); - } else if (which_set == ROGUESET) { - update_r_symset(symp, val); } - } + } else { /* !SYM_CONTROL */ + val = sym_val(bufp); + if (chosen_symset_start) { + if (which_set == PRIMARY) { + update_l_symset(symp, val); + } else if (which_set == ROGUESET) { + update_r_symset(symp, val); + } + } } } return 1; @@ -2893,8 +2947,8 @@ int which_set; symset[which_set].handling = H_UNK; while (known_handling[i]) { if (!strcmpi(known_handling[i], handling)) { - symset[which_set].handling = i; - return; + symset[which_set].handling = i; + return; } i++; } @@ -2905,9 +2959,9 @@ int which_set; /* ---------- BEGIN SCOREBOARD CREATION ----------- */ #ifdef OS2_CODEVIEW -# define UNUSED_if_not_OS2_CODEVIEW /*empty*/ +#define UNUSED_if_not_OS2_CODEVIEW /*empty*/ #else -# define UNUSED_if_not_OS2_CODEVIEW UNUSED +#define UNUSED_if_not_OS2_CODEVIEW UNUSED #endif /* verify that we can write to scoreboard file; if not, try to create one */ @@ -2917,7 +2971,7 @@ check_recordfile(dir) const char *dir UNUSED_if_not_OS2_CODEVIEW; { #if defined(PRAGMA_UNUSED) && !defined(OS2_CODEVIEW) -# pragma unused(dir) +#pragma unused(dir) #endif const char *fq_record; int fd; @@ -2926,67 +2980,70 @@ const char *dir UNUSED_if_not_OS2_CODEVIEW; fq_record = fqname(RECORD, SCOREPREFIX, 0); fd = open(fq_record, O_RDWR, 0); if (fd >= 0) { -# ifdef VMS /* must be stream-lf to use UPDATE_RECORD_IN_PLACE */ +#ifdef VMS /* must be stream-lf to use UPDATE_RECORD_IN_PLACE */ if (!file_is_stmlf(fd)) { - raw_printf( - "Warning: scoreboard file %s is not in stream_lf format", - fq_record); - wait_synch(); + raw_printf( + "Warning: scoreboard file %s is not in stream_lf format", + fq_record); + wait_synch(); } -# endif - (void) nhclose(fd); /* RECORD is accessible */ - } else if ((fd = open(fq_record, O_CREAT|O_RDWR, FCMASK)) >= 0) { - (void) nhclose(fd); /* RECORD newly created */ -# if defined(VMS) && !defined(SECURE) +#endif + (void) nhclose(fd); /* RECORD is accessible */ + } else if ((fd = open(fq_record, O_CREAT | O_RDWR, FCMASK)) >= 0) { + (void) nhclose(fd); /* RECORD newly created */ +#if defined(VMS) && !defined(SECURE) /* Re-protect RECORD with world:read+write+execute+delete access. */ (void) chmod(fq_record, FCMASK | 007); -# endif /* VMS && !SECURE */ +#endif /* VMS && !SECURE */ } else { raw_printf("Warning: cannot write scoreboard file %s", fq_record); wait_synch(); } -#endif /* !UNIX && !VMS */ +#endif /* !UNIX && !VMS */ #if defined(MICRO) || defined(WIN32) char tmp[PATHLEN]; -# ifdef OS2_CODEVIEW /* explicit path on opening for OS/2 */ +#ifdef OS2_CODEVIEW /* explicit path on opening for OS/2 */ /* how does this work when there isn't an explicit path or fopenp * for later access to the file via fopen_datafile? ? */ (void) strncpy(tmp, dir, PATHLEN - 1); - tmp[PATHLEN-1] = '\0'; + tmp[PATHLEN - 1] = '\0'; if ((strlen(tmp) + 1 + strlen(RECORD)) < (PATHLEN - 1)) { append_slash(tmp); Strcat(tmp, RECORD); } fq_record = tmp; -# else +#else Strcpy(tmp, RECORD); fq_record = fqname(RECORD, SCOREPREFIX, 0); -# endif +#endif if ((fd = open(fq_record, O_RDWR)) < 0) { - /* try to create empty record */ -# if defined(AZTEC_C) || defined(_DCC) || (defined(__GNUC__) && defined(__AMIGA__)) +/* try to create empty record */ +#if defined(AZTEC_C) || defined(_DCC) \ + || (defined(__GNUC__) && defined(__AMIGA__)) /* Aztec doesn't use the third argument */ /* DICE doesn't like it */ - if ((fd = open(fq_record, O_CREAT|O_RDWR)) < 0) { -# else - if ((fd = open(fq_record, O_CREAT|O_RDWR, S_IREAD|S_IWRITE)) < 0) { -# endif - raw_printf("Warning: cannot write record %s", tmp); - wait_synch(); + if ((fd = open(fq_record, O_CREAT | O_RDWR)) < 0) { +#else + if ((fd = open(fq_record, O_CREAT | O_RDWR, S_IREAD | S_IWRITE)) + < 0) { +#endif + raw_printf("Warning: cannot write record %s", tmp); + wait_synch(); } else - (void) nhclose(fd); - } else /* open succeeded */ - (void) nhclose(fd); + (void) nhclose(fd); + } else /* open succeeded */ + (void) nhclose(fd); #else /* MICRO || WIN32*/ -# ifdef MAC +#ifdef MAC /* Create the "record" file, if necessary */ fq_record = fqname(RECORD, SCOREPREFIX, 0); - fd = macopen (fq_record, O_RDWR | O_CREAT, TEXT_TYPE); - if (fd != -1) macclose (fd); -# endif /* MAC */ + fd = macopen(fq_record, O_RDWR | O_CREAT, TEXT_TYPE); + if (fd != -1) + macclose(fd); +#endif /* MAC */ #endif /* MICRO || WIN32*/ } @@ -2998,8 +3055,8 @@ const char *dir UNUSED_if_not_OS2_CODEVIEW; /*ARGSUSED*/ void paniclog(type, reason) -const char *type; /* panic, impossible, trickery */ -const char *reason; /* explanation */ +const char *type; /* panic, impossible, trickery */ +const char *reason; /* explanation */ { #ifdef PANICLOG FILE *lfile; @@ -3014,10 +3071,8 @@ const char *reason; /* explanation */ char playmode = wizard ? 'D' : discover ? 'X' : '-'; (void) fprintf(lfile, "%s %08ld %06ld %d %c: %s %s\n", - version_string(buf), - yyyymmdd(now), hhmmss(now), - uid, playmode, - type, reason); + version_string(buf), yyyymmdd(now), hhmmss(now), + uid, playmode, type, reason); (void) fclose(lfile); } program_state.in_paniclog = 0; @@ -3060,30 +3115,29 @@ recover_savefile() return FALSE; } if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) { - raw_printf( -"\nCheckpoint data incompletely written or subsequently clobbered. Recovery impossible."); - (void)nhclose(gfd); + raw_printf("\nCheckpoint data incompletely written or subsequently " + "clobbered. Recovery impossible."); + (void) nhclose(gfd); return FALSE; } if (read(gfd, (genericptr_t) &savelev, sizeof(savelev)) - != sizeof(savelev)) { - raw_printf("\nCheckpointing was not in effect for %s -- recovery impossible.\n", - lock); - (void)nhclose(gfd); + != sizeof(savelev)) { + raw_printf("\nCheckpointing was not in effect for %s -- recovery " + "impossible.\n", + lock); + (void) nhclose(gfd); return FALSE; } if ((read(gfd, (genericptr_t) savename, sizeof savename) - != sizeof savename) || - (read(gfd, (genericptr_t) &version_data, sizeof version_data) - != sizeof version_data) || - (read(gfd, (genericptr_t) &sfi, sizeof sfi) - != sizeof sfi) || - (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) - != sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ) || - (read(gfd, (genericptr_t) &tmpplbuf, pltmpsiz) - != pltmpsiz)) { + != sizeof savename) + || (read(gfd, (genericptr_t) &version_data, sizeof version_data) + != sizeof version_data) + || (read(gfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi) + || (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) + != sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ) + || (read(gfd, (genericptr_t) &tmpplbuf, pltmpsiz) != pltmpsiz)) { raw_printf("\nError reading %s -- can't recover.\n", lock); - (void)nhclose(gfd); + (void) nhclose(gfd); return FALSE; } @@ -3099,15 +3153,15 @@ recover_savefile() sfd = create_savefile(); if (sfd < 0) { raw_printf("\nCannot recover savefile %s.\n", SAVEF); - (void)nhclose(gfd); + (void) nhclose(gfd); return FALSE; } lfd = open_levelfile(savelev, errbuf); if (lfd < 0) { raw_printf("\n%s\n", errbuf); - (void)nhclose(gfd); - (void)nhclose(sfd); + (void) nhclose(gfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } @@ -3115,61 +3169,56 @@ recover_savefile() if (write(sfd, (genericptr_t) &version_data, sizeof version_data) != sizeof version_data) { raw_printf("\nError writing %s; recovery failed.", SAVEF); - (void)nhclose(gfd); - (void)nhclose(sfd); + (void) nhclose(gfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } - if (write(sfd, (genericptr_t) &sfi, sizeof sfi) - != sizeof sfi) { - raw_printf( - "\nError writing %s; recovery failed (savefile_info).\n", - SAVEF); - (void)nhclose(gfd); - (void)nhclose(sfd); + if (write(sfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi) { + raw_printf("\nError writing %s; recovery failed (savefile_info).\n", + SAVEF); + (void) nhclose(gfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } if (write(sfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) != sizeof pltmpsiz) { - raw_printf( - "Error writing %s; recovery failed (player name size).\n", - SAVEF); - (void)nhclose(gfd); - (void)nhclose(sfd); + raw_printf("Error writing %s; recovery failed (player name size).\n", + SAVEF); + (void) nhclose(gfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } - if (write(sfd, (genericptr_t) &tmpplbuf, pltmpsiz) - != pltmpsiz) { - raw_printf( - "Error writing %s; recovery failed (player name).\n", - SAVEF); - (void)nhclose(gfd); - (void)nhclose(sfd); + if (write(sfd, (genericptr_t) &tmpplbuf, pltmpsiz) != pltmpsiz) { + raw_printf("Error writing %s; recovery failed (player name).\n", + SAVEF); + (void) nhclose(gfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } if (!copy_bytes(lfd, sfd)) { - (void) nhclose(lfd); - (void) nhclose(sfd); + (void) nhclose(lfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } - (void)nhclose(lfd); + (void) nhclose(lfd); processed[savelev] = 1; if (!copy_bytes(gfd, sfd)) { - (void) nhclose(lfd); - (void) nhclose(sfd); + (void) nhclose(lfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } - (void)nhclose(gfd); + (void) nhclose(gfd); processed[0] = 1; for (lev = 1; lev < 256; lev++) { @@ -3177,23 +3226,23 @@ recover_savefile() * maximum level number (for the endlevel) must be < 256 */ if (lev != savelev) { - lfd = open_levelfile(lev, (char *)0); + lfd = open_levelfile(lev, (char *) 0); if (lfd >= 0) { /* any or all of these may not exist */ levc = (xchar) lev; write(sfd, (genericptr_t) &levc, sizeof(levc)); if (!copy_bytes(lfd, sfd)) { - (void) nhclose(lfd); - (void) nhclose(sfd); + (void) nhclose(lfd); + (void) nhclose(sfd); delete_savefile(); return FALSE; } - (void)nhclose(lfd); + (void) nhclose(lfd); processed[lev] = 1; } } } - (void)nhclose(sfd); + (void) nhclose(sfd); #ifdef HOLD_LOCKFILE_OPEN really_close(); @@ -3223,7 +3272,8 @@ int ifd, ofd; do { nfrom = read(ifd, buf, BUFSIZ); nto = write(ofd, buf, nfrom); - if (nto != nfrom) return FALSE; + if (nto != nfrom) + return FALSE; } while (nfrom == BUFSIZ); return TRUE; } @@ -3234,14 +3284,15 @@ int ifd, ofd; /* ---------- OTHER ----------- */ #ifdef SYSCF -# ifdef SYSCF_FILE +#ifdef SYSCF_FILE void -assure_syscf_file() { +assure_syscf_file() +{ /* All we really care about is the end result - can we read the file? * So just check that directly. */ int fd; fd = open(SYSCF_FILE, O_RDONLY); - if(fd >= 0){ + if (fd >= 0) { /* readable */ close(fd); return; @@ -3250,16 +3301,15 @@ assure_syscf_file() { exit(EXIT_FAILURE); } -# endif /* SYSCF_FILE */ +#endif /* SYSCF_FILE */ #endif /* SYSCF */ - #ifdef DEBUG /* used by debugpline() to decide whether to issue a message * from a partiular source file; caller passes __FILE__ and we check * whether it is in the source file list supplied by SYSCF's DEBUGFILES * - * pass FALSE to override wildcard matching; useful for files + * pass FALSE to override wildcard matching; useful for files * like dungeon.c and questpgr.c, which generate a ridiculous amount of * output if DEBUG is defined and effectively block the use of a wildcard */ boolean @@ -3269,36 +3319,40 @@ boolean wildcards; { const char *debugfiles, *p; - if (!filename || !*filename) return FALSE; /* sanity precaution */ + if (!filename || !*filename) + return FALSE; /* sanity precaution */ if (sysopt.env_dbgfl == 0) { - /* check once for DEBUGFILES in the environment; - if found, it supersedes the sysconf value - [note: getenv() rather than nh_getenv() since a long value - is valid and doesn't pose any sort of overflow risk here] */ - if ((p = getenv("DEBUGFILES")) != 0) { - if (sysopt.debugfiles) free(sysopt.debugfiles); - sysopt.debugfiles = dupstr(p); - sysopt.env_dbgfl = 1; - } else - sysopt.env_dbgfl = -1; + /* check once for DEBUGFILES in the environment; + if found, it supersedes the sysconf value + [note: getenv() rather than nh_getenv() since a long value + is valid and doesn't pose any sort of overflow risk here] */ + if ((p = getenv("DEBUGFILES")) != 0) { + if (sysopt.debugfiles) + free(sysopt.debugfiles); + sysopt.debugfiles = dupstr(p); + sysopt.env_dbgfl = 1; + } else + sysopt.env_dbgfl = -1; } debugfiles = sysopt.debugfiles; /* usual case: sysopt.debugfiles will be empty */ - if (!debugfiles || !*debugfiles) return FALSE; + if (!debugfiles || !*debugfiles) + return FALSE; - /* strip filename's path if present */ -# ifdef UNIX - if ((p = rindex(filename, '/')) != 0) filename = p + 1; -# endif -# ifdef VMS +/* strip filename's path if present */ +#ifdef UNIX + if ((p = rindex(filename, '/')) != 0) + filename = p + 1; +#endif +#ifdef VMS filename = vms_basename(filename); /* vms_basename strips off 'type' suffix as well as path and version; we want to put suffix back (".c" assumed); since it always returns a pointer to a static buffer, we can safely modify its result */ - Strcat((char *)filename, ".c"); -# endif + Strcat((char *) filename, ".c"); +#endif /* * Wildcard match will only work if there's a single pattern (which @@ -3309,20 +3363,20 @@ boolean wildcards; * overkill for the intended usage.] */ if (wildcards && pmatch(debugfiles, filename)) - return TRUE; + return TRUE; /* check whether filename is an element of the list */ if ((p = strstr(debugfiles, filename)) != 0) { - int l = (int)strlen(filename); + int l = (int) strlen(filename); - if ((p == debugfiles || p[-1] == ' ' || p[-1] == '/') - && (p[l] == ' ' || p[l] == '\0')) - return TRUE; + if ((p == debugfiles || p[-1] == ' ' || p[-1] == '/') + && (p[l] == ' ' || p[l] == '\0')) + return TRUE; } return FALSE; } -#endif /*DEBUG*/ +#endif /*DEBUG*/ /* ---------- BEGIN TRIBUTE ----------- */ @@ -3333,13 +3387,13 @@ boolean wildcards; */ #define SECTIONSCOPE 1 -#define TITLESCOPE 2 +#define TITLESCOPE 2 #define PASSAGESCOPE 3 boolean read_tribute(tribsection, tribtitle, tribpassage) const char *tribsection, *tribtitle; -int tribpassage; +int tribpassage; { dlb *fp; char *endp; @@ -3354,18 +3408,18 @@ int tribpassage; /* check for mandatories */ if (!tribsection || !tribtitle) { - pline("It's %s of \"%s\"!", - badtranslation, tribtitle); - return grasped; - } + pline("It's %s of \"%s\"!", badtranslation, tribtitle); + return grasped; + } - debugpline3("read_tribute %s, %s, %d.", tribsection, tribtitle, tribpassage); + debugpline3("read_tribute %s, %s, %d.", tribsection, tribtitle, + tribpassage); fp = dlb_fopen(TRIBUTEFILE, "r"); if (!fp) { - /* this is actually an error - cannot open tribute file! */ - pline("You feel too overwhelmed to continue!"); - return grasped; + /* this is actually an error - cannot open tribute file! */ + pline("You feel too overwhelmed to continue!"); + return grasped; } /* @@ -3386,89 +3440,95 @@ int tribpassage; * * %section death */ - + while (dlb_fgets(line, sizeof line, fp) != 0) { - linect++; - if ((endp = index(line, '\n')) != 0) *endp = 0; - switch (line[0]) { - case '%': - if (!strncmpi(&line[1], "section ", sizeof("section ")-1)) { - char *st = &line[9]; /* 9 from "%section " */ - scope = SECTIONSCOPE; - if (!strcmpi(st, tribsection)) - matchedsection = TRUE; - else - matchedsection = FALSE; - } else if (!strncmpi(&line[1], "title ", sizeof("title ")-1)) { - char *st = &line[7]; /* 7 from "%title " */ - char *p1, *p2; - if ((p1 = index(st, '(')) != 0) { - *p1++ = '\0'; - (void)mungspaces(st); - if ((p2 = index(p1, ')')) != 0) { - *p2 = '\0'; - passagecnt = atoi(p1); - /* sanity check here caps #passages at 50 */ - if ((passagecnt > 0) && (passagecnt < 50)) { - scope = TITLESCOPE; - if (matchedsection && !strcmpi(st, tribtitle)) { - matchedtitle = TRUE; - if (!tribpassage) { - targetpassage = rnd(passagecnt); - } else { - if (tribpassage <= passagecnt) - targetpassage = tribpassage; - else - targetpassage = 0; - } - } else { - matchedtitle = FALSE; - } - } - } - } - } else if (!strncmpi(&line[1], "passage ", sizeof("passage ")-1)) { - int passagenum = 0; - char *st = &line[9]; /* 9 from "%passage " */ - while(*st == ' ' || *st == '\t') st++; - if (*st && digit(*st) && (strlen(st) < 3)) - passagenum = atoi(st); - if (passagenum && (passagenum <= passagecnt)) { - scope = PASSAGESCOPE; - if (matchedtitle && (passagenum == targetpassage)) - tribwin = create_nhwindow(NHW_MENU); - } - } else if (!strncmpi(&line[1], "e ", sizeof("e ")-1)) { - if (matchedtitle && (scope == PASSAGESCOPE) && tribwin != WIN_ERR) - goto cleanup; - if (scope == TITLESCOPE) matchedtitle = FALSE; - if (scope == SECTIONSCOPE) matchedsection = FALSE; - if (scope) --scope; - } else { - debugpline1("tribute file error: bad %% command, line %d.", - linect); - } - break; - case '#': - /* comment only, next! */ - break; - default: - if (matchedtitle && (scope == PASSAGESCOPE) && tribwin != WIN_ERR) - putstr(tribwin, 0, line); - } + linect++; + if ((endp = index(line, '\n')) != 0) + *endp = 0; + switch (line[0]) { + case '%': + if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) { + char *st = &line[9]; /* 9 from "%section " */ + scope = SECTIONSCOPE; + if (!strcmpi(st, tribsection)) + matchedsection = TRUE; + else + matchedsection = FALSE; + } else if (!strncmpi(&line[1], "title ", sizeof("title ") - 1)) { + char *st = &line[7]; /* 7 from "%title " */ + char *p1, *p2; + if ((p1 = index(st, '(')) != 0) { + *p1++ = '\0'; + (void) mungspaces(st); + if ((p2 = index(p1, ')')) != 0) { + *p2 = '\0'; + passagecnt = atoi(p1); + /* sanity check here caps #passages at 50 */ + if ((passagecnt > 0) && (passagecnt < 50)) { + scope = TITLESCOPE; + if (matchedsection && !strcmpi(st, tribtitle)) { + matchedtitle = TRUE; + if (!tribpassage) { + targetpassage = rnd(passagecnt); + } else { + if (tribpassage <= passagecnt) + targetpassage = tribpassage; + else + targetpassage = 0; + } + } else { + matchedtitle = FALSE; + } + } + } + } + } else if (!strncmpi(&line[1], "passage ", + sizeof("passage ") - 1)) { + int passagenum = 0; + char *st = &line[9]; /* 9 from "%passage " */ + while (*st == ' ' || *st == '\t') + st++; + if (*st && digit(*st) && (strlen(st) < 3)) + passagenum = atoi(st); + if (passagenum && (passagenum <= passagecnt)) { + scope = PASSAGESCOPE; + if (matchedtitle && (passagenum == targetpassage)) + tribwin = create_nhwindow(NHW_MENU); + } + } else if (!strncmpi(&line[1], "e ", sizeof("e ") - 1)) { + if (matchedtitle && (scope == PASSAGESCOPE) + && tribwin != WIN_ERR) + goto cleanup; + if (scope == TITLESCOPE) + matchedtitle = FALSE; + if (scope == SECTIONSCOPE) + matchedsection = FALSE; + if (scope) + --scope; + } else { + debugpline1("tribute file error: bad %% command, line %d.", + linect); + } + break; + case '#': + /* comment only, next! */ + break; + default: + if (matchedtitle && (scope == PASSAGESCOPE) && tribwin != WIN_ERR) + putstr(tribwin, 0, line); + } } cleanup: (void) dlb_fclose(fp); if (tribwin != WIN_ERR) { - if (matchedtitle && (scope == PASSAGESCOPE)) - display_nhwindow(tribwin, FALSE); - destroy_nhwindow(tribwin); - tribwin = WIN_ERR; - grasped = TRUE; + if (matchedtitle && (scope == PASSAGESCOPE)) + display_nhwindow(tribwin, FALSE); + destroy_nhwindow(tribwin); + tribwin = WIN_ERR; + grasped = TRUE; } else { - pline("It seems to be %s of \"%s\"!", - badtranslation, tribtitle); + pline("It seems to be %s of \"%s\"!", badtranslation, tribtitle); } return grasped; diff --git a/src/fountain.c b/src/fountain.c index ddec565dc..d892b4ba6 100644 --- a/src/fountain.c +++ b/src/fountain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 fountain.c $NHDT-Date: 1426953330 2015/03/21 15:55:30 $ $NHDT-Branch: master $:$NHDT-Revision: 1.40 $ */ +/* NetHack 3.6 fountain.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ /* NetHack 3.6 fountain.c $Date: 2011/08/20 00:22:20 $ $Revision: 1.32 $ */ /* Copyright Scott R. Turner, srt@ucla, 10/27/86 */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,7 +10,7 @@ STATIC_DCL void NDECL(dowatersnakes); STATIC_DCL void NDECL(dowaterdemon); STATIC_DCL void NDECL(dowaternymph); -STATIC_PTR void FDECL(gush, (int,int,genericptr_t)); +STATIC_PTR void FDECL(gush, (int, int, genericptr_t)); STATIC_DCL void NDECL(dofindgem); /* used when trying to dip in or drink from fountain or sink or pool while @@ -22,94 +22,91 @@ const char *what; const char *umsg = "are floating high above the %s."; if (u.utrap && (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA)) { - /* when stuck in floor (not possible at fountain or sink location, - so must be attempting to move down), override the usual message */ - umsg = "are trapped in the %s."; - what = surface(u.ux, u.uy); /* probably redundant */ + /* when stuck in floor (not possible at fountain or sink location, + so must be attempting to move down), override the usual message */ + umsg = "are trapped in the %s."; + what = surface(u.ux, u.uy); /* probably redundant */ } You(umsg, what); } -STATIC_OVL void -dowatersnakes() /* Fountain of snakes! */ +STATIC_OVL void dowatersnakes() /* Fountain of snakes! */ { - register int num = rn1(5,2); + register int num = rn1(5, 2); struct monst *mtmp; if (!(mvitals[PM_WATER_MOCCASIN].mvflags & G_GONE)) { - if (!Blind) - pline("An endless stream of %s pours forth!", - Hallucination ? makeplural(rndmonnam(NULL)) : "snakes"); - else - You_hear("%s hissing!", something); - while(num-- > 0) - if((mtmp = makemon(&mons[PM_WATER_MOCCASIN], - u.ux, u.uy, NO_MM_FLAGS)) && t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); + if (!Blind) + pline("An endless stream of %s pours forth!", + Hallucination ? makeplural(rndmonnam(NULL)) : "snakes"); + else + You_hear("%s hissing!", something); + while (num-- > 0) + if ((mtmp = makemon(&mons[PM_WATER_MOCCASIN], u.ux, u.uy, + NO_MM_FLAGS)) && t_at(mtmp->mx, mtmp->my)) + (void) mintrap(mtmp); } else - pline_The("fountain bubbles furiously for a moment, then calms."); + pline_The("fountain bubbles furiously for a moment, then calms."); } STATIC_OVL -void -dowaterdemon() /* Water demon */ +void dowaterdemon() /* Water demon */ { struct monst *mtmp; - if(!(mvitals[PM_WATER_DEMON].mvflags & G_GONE)) { - if((mtmp = makemon(&mons[PM_WATER_DEMON],u.ux,u.uy, NO_MM_FLAGS))) { - if (!Blind) - You("unleash %s!", a_monnam(mtmp)); - else - You_feel("the presence of evil."); + if (!(mvitals[PM_WATER_DEMON].mvflags & G_GONE)) { + if ((mtmp = + makemon(&mons[PM_WATER_DEMON], u.ux, u.uy, NO_MM_FLAGS))) { + if (!Blind) + You("unleash %s!", a_monnam(mtmp)); + else + You_feel("the presence of evil."); - /* Give those on low levels a (slightly) better chance of survival */ - if (rnd(100) > (80 + level_difficulty())) { - pline("Grateful for %s release, %s grants you a wish!", - mhis(mtmp), mhe(mtmp)); - /* give a wish and discard the monster (mtmp set to null) */ - mongrantswish(&mtmp); - } else if (t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); - } + /* Give those on low levels a (slightly) better chance of survival + */ + if (rnd(100) > (80 + level_difficulty())) { + pline("Grateful for %s release, %s grants you a wish!", + mhis(mtmp), mhe(mtmp)); + /* give a wish and discard the monster (mtmp set to null) */ + mongrantswish(&mtmp); + } else if (t_at(mtmp->mx, mtmp->my)) + (void) mintrap(mtmp); + } } else - pline_The("fountain bubbles furiously for a moment, then calms."); + pline_The("fountain bubbles furiously for a moment, then calms."); } -STATIC_OVL void -dowaternymph() /* Water Nymph */ +STATIC_OVL void dowaternymph() /* Water Nymph */ { - register struct monst *mtmp; + register struct monst *mtmp; - if(!(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) && - (mtmp = makemon(&mons[PM_WATER_NYMPH],u.ux,u.uy, NO_MM_FLAGS))) { - if (!Blind) - You("attract %s!", a_monnam(mtmp)); - else - You_hear("a seductive voice."); - mtmp->msleeping = 0; - if (t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); - } else - if (!Blind) - pline("A large bubble rises to the surface and pops."); - else - You_hear("a loud pop."); + if (!(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) + && (mtmp = makemon(&mons[PM_WATER_NYMPH], u.ux, u.uy, NO_MM_FLAGS))) { + if (!Blind) + You("attract %s!", a_monnam(mtmp)); + else + You_hear("a seductive voice."); + mtmp->msleeping = 0; + if (t_at(mtmp->mx, mtmp->my)) + (void) mintrap(mtmp); + } else if (!Blind) + pline("A large bubble rises to the surface and pops."); + else + You_hear("a loud pop."); } -void -dogushforth(drinking) /* Gushing forth along LOS from (u.ux, u.uy) */ +void dogushforth(drinking) /* Gushing forth along LOS from (u.ux, u.uy) */ int drinking; { - int madepool = 0; + int madepool = 0; - do_clear_area(u.ux, u.uy, 7, gush, (genericptr_t)&madepool); - if (!madepool) { - if (drinking) - Your("thirst is quenched."); - else - pline("Water sprays all over you."); - } + do_clear_area(u.ux, u.uy, 7, gush, (genericptr_t) &madepool); + if (!madepool) { + if (drinking) + Your("thirst is quenched."); + else + pline("Water sprays all over you."); + } } STATIC_PTR void @@ -117,43 +114,43 @@ gush(x, y, poolcnt) int x, y; genericptr_t poolcnt; { - register struct monst *mtmp; - register struct trap *ttmp; + register struct monst *mtmp; + register struct trap *ttmp; - if (((x+y)%2) || (x == u.ux && y == u.uy) || - (rn2(1 + distmin(u.ux, u.uy, x, y))) || - (levl[x][y].typ != ROOM) || - (sobj_at(BOULDER, x, y)) || nexttodoor(x, y)) - return; + if (((x + y) % 2) || (x == u.ux && y == u.uy) + || (rn2(1 + distmin(u.ux, u.uy, x, y))) || (levl[x][y].typ != ROOM) + || (sobj_at(BOULDER, x, y)) || nexttodoor(x, y)) + return; - if ((ttmp = t_at(x, y)) != 0 && !delfloortrap(ttmp)) - return; + if ((ttmp = t_at(x, y)) != 0 && !delfloortrap(ttmp)) + return; - if (!((*(int *)poolcnt)++)) - pline("Water gushes forth from the overflowing fountain!"); + if (!((*(int *) poolcnt)++)) + pline("Water gushes forth from the overflowing fountain!"); - /* Put a pool at x, y */ - levl[x][y].typ = POOL; - /* No kelp! */ - del_engr_at(x, y); - water_damage_chain(level.objects[x][y], TRUE); + /* Put a pool at x, y */ + levl[x][y].typ = POOL; + /* No kelp! */ + del_engr_at(x, y); + water_damage_chain(level.objects[x][y], TRUE); - if ((mtmp = m_at(x, y)) != 0) - (void) minliquid(mtmp); - else - newsym(x,y); + if ((mtmp = m_at(x, y)) != 0) + (void) minliquid(mtmp); + else + newsym(x, y); } -STATIC_OVL void -dofindgem() /* Find a gem in the sparkling waters. */ +STATIC_OVL void dofindgem() /* Find a gem in the sparkling waters. */ { - if (!Blind) You("spot a gem in the sparkling waters!"); - else You_feel("a gem here!"); - (void) mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE-1), - u.ux, u.uy, FALSE, FALSE); - SET_FOUNTAIN_LOOTED(u.ux,u.uy); - newsym(u.ux, u.uy); - exercise(A_WIS, TRUE); /* a discovery! */ + if (!Blind) + You("spot a gem in the sparkling waters!"); + else + You_feel("a gem here!"); + (void) mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE - 1), u.ux, u.uy, + FALSE, FALSE); + SET_FOUNTAIN_LOOTED(u.ux, u.uy); + newsym(u.ux, u.uy); + exercise(A_WIS, TRUE); /* a discovery! */ } void @@ -161,443 +158,466 @@ dryup(x, y, isyou) xchar x, y; boolean isyou; { - if (IS_FOUNTAIN(levl[x][y].typ) && - (!rn2(3) || FOUNTAIN_IS_WARNED(x,y))) { - if(isyou && in_town(x, y) && !FOUNTAIN_IS_WARNED(x,y)) { - struct monst *mtmp; - SET_FOUNTAIN_WARNED(x,y); - /* Warn about future fountain use. */ - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_watch(mtmp->data) && - couldsee(mtmp->mx, mtmp->my) && - mtmp->mpeaceful) { - pline("%s yells:", Amonnam(mtmp)); - verbalize("Hey, stop using that fountain!"); - break; - } - } - /* You can see or hear this effect */ - if(!mtmp) pline_The("flow reduces to a trickle."); - return; - } - if (isyou && wizard) { - if (yn("Dry up fountain?") == 'n') - return; - } - /* replace the fountain with ordinary floor */ - levl[x][y].typ = ROOM; - levl[x][y].looted = 0; - levl[x][y].blessedftn = 0; - if (cansee(x,y)) pline_The("fountain dries up!"); - /* The location is seen if the hero/monster is invisible */ - /* or felt if the hero is blind. */ - newsym(x, y); - level.flags.nfountains--; - if(isyou && in_town(x, y)) - (void) angry_guards(FALSE); - } + if (IS_FOUNTAIN(levl[x][y].typ) + && (!rn2(3) || FOUNTAIN_IS_WARNED(x, y))) { + if (isyou && in_town(x, y) && !FOUNTAIN_IS_WARNED(x, y)) { + struct monst *mtmp; + SET_FOUNTAIN_WARNED(x, y); + /* Warn about future fountain use. */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_watch(mtmp->data) && couldsee(mtmp->mx, mtmp->my) + && mtmp->mpeaceful) { + pline("%s yells:", Amonnam(mtmp)); + verbalize("Hey, stop using that fountain!"); + break; + } + } + /* You can see or hear this effect */ + if (!mtmp) + pline_The("flow reduces to a trickle."); + return; + } + if (isyou && wizard) { + if (yn("Dry up fountain?") == 'n') + return; + } + /* replace the fountain with ordinary floor */ + levl[x][y].typ = ROOM; + levl[x][y].looted = 0; + levl[x][y].blessedftn = 0; + if (cansee(x, y)) + pline_The("fountain dries up!"); + /* The location is seen if the hero/monster is invisible */ + /* or felt if the hero is blind. */ + newsym(x, y); + level.flags.nfountains--; + if (isyou && in_town(x, y)) + (void) angry_guards(FALSE); + } } void drinkfountain() { - /* What happens when you drink from a fountain? */ - register boolean mgkftn = (levl[u.ux][u.uy].blessedftn == 1); - register int fate = rnd(30); + /* What happens when you drink from a fountain? */ + register boolean mgkftn = (levl[u.ux][u.uy].blessedftn == 1); + register int fate = rnd(30); - if (Levitation) { - floating_above("fountain"); - return; - } + if (Levitation) { + floating_above("fountain"); + return; + } - if (mgkftn && u.uluck >= 0 && fate >= 10) { - int i, ii, littleluck = (u.uluck < 4); + if (mgkftn && u.uluck >= 0 && fate >= 10) { + int i, ii, littleluck = (u.uluck < 4); - pline("Wow! This makes you feel great!"); - /* blessed restore ability */ - for (ii = 0; ii < A_MAX; ii++) - if (ABASE(ii) < AMAX(ii)) { - ABASE(ii) = AMAX(ii); - context.botl = 1; - } - /* gain ability, blessed if "natural" luck is high */ - i = rn2(A_MAX); /* start at a random attribute */ - for (ii = 0; ii < A_MAX; ii++) { - if (adjattrib(i, 1, littleluck ? -1 : 0) && littleluck) - break; - if (++i >= A_MAX) i = 0; - } - display_nhwindow(WIN_MESSAGE, FALSE); - pline("A wisp of vapor escapes the fountain..."); - exercise(A_WIS, TRUE); - levl[u.ux][u.uy].blessedftn = 0; - return; - } + pline("Wow! This makes you feel great!"); + /* blessed restore ability */ + for (ii = 0; ii < A_MAX; ii++) + if (ABASE(ii) < AMAX(ii)) { + ABASE(ii) = AMAX(ii); + context.botl = 1; + } + /* gain ability, blessed if "natural" luck is high */ + i = rn2(A_MAX); /* start at a random attribute */ + for (ii = 0; ii < A_MAX; ii++) { + if (adjattrib(i, 1, littleluck ? -1 : 0) && littleluck) + break; + if (++i >= A_MAX) + i = 0; + } + display_nhwindow(WIN_MESSAGE, FALSE); + pline("A wisp of vapor escapes the fountain..."); + exercise(A_WIS, TRUE); + levl[u.ux][u.uy].blessedftn = 0; + return; + } - if (fate < 10) { - pline_The("cool draught refreshes you."); - u.uhunger += rnd(10); /* don't choke on water */ - newuhs(FALSE); - if(mgkftn) return; - } else { - switch (fate) { + if (fate < 10) { + pline_The("cool draught refreshes you."); + u.uhunger += rnd(10); /* don't choke on water */ + newuhs(FALSE); + if (mgkftn) + return; + } else { + switch (fate) { + case 19: /* Self-knowledge */ - case 19: /* Self-knowledge */ + You_feel("self-knowledgeable..."); + display_nhwindow(WIN_MESSAGE, FALSE); + enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); + exercise(A_WIS, TRUE); + pline_The("feeling subsides."); + break; - You_feel("self-knowledgeable..."); - display_nhwindow(WIN_MESSAGE, FALSE); - enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); - exercise(A_WIS, TRUE); - pline_The("feeling subsides."); - break; + case 20: /* Foul water */ - case 20: /* Foul water */ + pline_The("water is foul! You gag and vomit."); + morehungry(rn1(20, 11)); + vomit(); + break; - pline_The("water is foul! You gag and vomit."); - morehungry(rn1(20, 11)); - vomit(); - break; + case 21: /* Poisonous */ - case 21: /* Poisonous */ + pline_The("water is contaminated!"); + if (Poison_resistance) { + pline("Perhaps it is runoff from the nearby %s farm.", + fruitname(FALSE)); + losehp(rnd(4), "unrefrigerated sip of juice", KILLED_BY_AN); + break; + } + losestr(rn1(4, 3)); + losehp(rnd(10), "contaminated water", KILLED_BY); + exercise(A_CON, FALSE); + break; - pline_The("water is contaminated!"); - if (Poison_resistance) { - pline( - "Perhaps it is runoff from the nearby %s farm.", - fruitname(FALSE)); - losehp(rnd(4),"unrefrigerated sip of juice", - KILLED_BY_AN); - break; - } - losestr(rn1(4,3)); - losehp(rnd(10),"contaminated water", KILLED_BY); - exercise(A_CON, FALSE); - break; + case 22: /* Fountain of snakes! */ - case 22: /* Fountain of snakes! */ + dowatersnakes(); + break; - dowatersnakes(); - break; + case 23: /* Water demon */ + dowaterdemon(); + break; - case 23: /* Water demon */ - dowaterdemon(); - break; + case 24: /* Curse an item */ { + register struct obj *obj; - case 24: /* Curse an item */ { - register struct obj *obj; + pline("This water's no good!"); + morehungry(rn1(20, 11)); + exercise(A_CON, FALSE); + for (obj = invent; obj; obj = obj->nobj) + if (!rn2(5)) + curse(obj); + break; + } - pline("This water's no good!"); - morehungry(rn1(20, 11)); - exercise(A_CON, FALSE); - for(obj = invent; obj ; obj = obj->nobj) - if (!rn2(5)) curse(obj); - break; - } + case 25: /* See invisible */ - case 25: /* See invisible */ + if (Blind) { + if (Invisible) { + You("feel transparent."); + } else { + You("feel very self-conscious."); + pline("Then it passes."); + } + } else { + You_see("an image of someone stalking you."); + pline("But it disappears."); + } + HSee_invisible |= FROMOUTSIDE; + newsym(u.ux, u.uy); + exercise(A_WIS, TRUE); + break; - if (Blind) { - if (Invisible) { - You("feel transparent."); - } else { - You("feel very self-conscious."); - pline("Then it passes."); - } - } else { - You_see("an image of someone stalking you."); - pline("But it disappears."); - } - HSee_invisible |= FROMOUTSIDE; - newsym(u.ux,u.uy); - exercise(A_WIS, TRUE); - break; + case 26: /* See Monsters */ - case 26: /* See Monsters */ + (void) monster_detect((struct obj *) 0, 0); + exercise(A_WIS, TRUE); + break; - (void) monster_detect((struct obj *)0, 0); - exercise(A_WIS, TRUE); - break; + case 27: /* Find a gem in the sparkling waters. */ - case 27: /* Find a gem in the sparkling waters. */ + if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) { + dofindgem(); + break; + } - if (!FOUNTAIN_IS_LOOTED(u.ux,u.uy)) { - dofindgem(); - break; - } + case 28: /* Water Nymph */ - case 28: /* Water Nymph */ + dowaternymph(); + break; - dowaternymph(); - break; + case 29: /* Scare */ + { + register struct monst *mtmp; - case 29: /* Scare */ - { - register struct monst *mtmp; + pline("This water gives you bad breath!"); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + monflee(mtmp, 0, FALSE, FALSE); + } + break; + } - pline("This water gives you bad breath!"); - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - monflee(mtmp, 0, FALSE, FALSE); - } - break; - } + case 30: /* Gushing forth in this room */ - case 30: /* Gushing forth in this room */ + dogushforth(TRUE); + break; - dogushforth(TRUE); - break; + default: - default: - - pline("This tepid water is tasteless."); - break; - } - } - dryup(u.ux, u.uy, TRUE); + pline("This tepid water is tasteless."); + break; + } + } + dryup(u.ux, u.uy, TRUE); } void dipfountain(obj) register struct obj *obj; { - if (Levitation) { - floating_above("fountain"); - return; - } + if (Levitation) { + floating_above("fountain"); + return; + } - /* Don't grant Excalibur when there's more than one object. */ - /* (quantity could be > 1 if merged daggers got polymorphed) */ - if (obj->otyp == LONG_SWORD && obj->quan == 1L - && u.ulevel >= 5 && !rn2(6) - && !obj->oartifact - && !exist_artifact(LONG_SWORD, artiname(ART_EXCALIBUR))) { - - if (u.ualign.type != A_LAWFUL) { - /* Ha! Trying to cheat her. */ - pline("A freezing mist rises from the water and envelopes the sword."); - pline_The("fountain disappears!"); - curse(obj); - if (obj->spe > -6 && !rn2(3)) obj->spe--; - obj->oerodeproof = FALSE; - exercise(A_WIS, FALSE); - } else { - /* The lady of the lake acts! - Eric Backus */ - /* Be *REAL* nice */ - pline("From the murky depths, a hand reaches up to bless the sword."); - pline("As the hand retreats, the fountain disappears!"); - obj = oname(obj, artiname(ART_EXCALIBUR)); - discover_artifact(ART_EXCALIBUR); - bless(obj); - obj->oeroded = obj->oeroded2 = 0; - obj->oerodeproof = TRUE; - exercise(A_WIS, TRUE); - } - update_inventory(); - levl[u.ux][u.uy].typ = ROOM; - levl[u.ux][u.uy].looted = 0; - newsym(u.ux, u.uy); - level.flags.nfountains--; - if(in_town(u.ux, u.uy)) - (void) angry_guards(FALSE); - return; - } else { - int er = water_damage(obj, NULL, TRUE); - if (obj->otyp == POT_ACID && er != ER_DESTROYED) { /* Acid and water don't mix */ - useup(obj); - return; - } else if (er != ER_NOTHING && !rn2(2)) { /* no further effect */ - return; + /* Don't grant Excalibur when there's more than one object. */ + /* (quantity could be > 1 if merged daggers got polymorphed) */ + if (obj->otyp == LONG_SWORD && obj->quan == 1L && u.ulevel >= 5 && !rn2(6) + && !obj->oartifact + && !exist_artifact(LONG_SWORD, artiname(ART_EXCALIBUR))) { + if (u.ualign.type != A_LAWFUL) { + /* Ha! Trying to cheat her. */ + pline("A freezing mist rises from the water and envelopes the " + "sword."); + pline_The("fountain disappears!"); + curse(obj); + if (obj->spe > -6 && !rn2(3)) + obj->spe--; + obj->oerodeproof = FALSE; + exercise(A_WIS, FALSE); + } else { + /* The lady of the lake acts! - Eric Backus */ + /* Be *REAL* nice */ + pline("From the murky depths, a hand reaches up to bless the " + "sword."); + pline("As the hand retreats, the fountain disappears!"); + obj = oname(obj, artiname(ART_EXCALIBUR)); + discover_artifact(ART_EXCALIBUR); + bless(obj); + obj->oeroded = obj->oeroded2 = 0; + obj->oerodeproof = TRUE; + exercise(A_WIS, TRUE); } - } + update_inventory(); + levl[u.ux][u.uy].typ = ROOM; + levl[u.ux][u.uy].looted = 0; + newsym(u.ux, u.uy); + level.flags.nfountains--; + if (in_town(u.ux, u.uy)) + (void) angry_guards(FALSE); + return; + } else { + int er = water_damage(obj, NULL, TRUE); + if (obj->otyp == POT_ACID + && er != ER_DESTROYED) { /* Acid and water don't mix */ + useup(obj); + return; + } else if (er != ER_NOTHING && !rn2(2)) { /* no further effect */ + return; + } + } - switch (rnd(30)) { - case 16: /* Curse the item */ - curse(obj); - break; - case 17: - case 18: - case 19: - case 20: /* Uncurse the item */ - if(obj->cursed) { - if (!Blind) - pline_The("water glows for a moment."); - uncurse(obj); - } else { - pline("A feeling of loss comes over you."); - } - break; - case 21: /* Water Demon */ - dowaterdemon(); - break; - case 22: /* Water Nymph */ - dowaternymph(); - break; - case 23: /* an Endless Stream of Snakes */ - dowatersnakes(); - break; - case 24: /* Find a gem */ - if (!FOUNTAIN_IS_LOOTED(u.ux,u.uy)) { - dofindgem(); - break; - } - case 25: /* Water gushes forth */ - dogushforth(FALSE); - break; - case 26: /* Strange feeling */ - pline("A strange tingling runs up your %s.", - body_part(ARM)); - break; - case 27: /* Strange feeling */ - You_feel("a sudden chill."); - break; - case 28: /* Strange feeling */ - pline("An urge to take a bath overwhelms you."); - { - long money = money_cnt(invent); - struct obj *otmp; - if (money > 10) { - /* Amount to lose. Might get rounded up as fountains don't pay change... */ - money = somegold(money) / 10; - for (otmp = invent; otmp && money > 0; otmp = otmp->nobj) if (otmp->oclass == COIN_CLASS) { - int denomination = objects[otmp->otyp].oc_cost; - long coin_loss = (money + denomination - 1) / denomination; - coin_loss = min(coin_loss, otmp->quan); - otmp->quan -= coin_loss; - money -= coin_loss * denomination; - if (!otmp->quan) delobj(otmp); - } - You("lost some of your money in the fountain!"); - CLEAR_FOUNTAIN_LOOTED(u.ux,u.uy); - exercise(A_WIS, FALSE); - } - } - break; - case 29: /* You see coins */ + switch (rnd(30)) { + case 16: /* Curse the item */ + curse(obj); + break; + case 17: + case 18: + case 19: + case 20: /* Uncurse the item */ + if (obj->cursed) { + if (!Blind) + pline_The("water glows for a moment."); + uncurse(obj); + } else { + pline("A feeling of loss comes over you."); + } + break; + case 21: /* Water Demon */ + dowaterdemon(); + break; + case 22: /* Water Nymph */ + dowaternymph(); + break; + case 23: /* an Endless Stream of Snakes */ + dowatersnakes(); + break; + case 24: /* Find a gem */ + if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) { + dofindgem(); + break; + } + case 25: /* Water gushes forth */ + dogushforth(FALSE); + break; + case 26: /* Strange feeling */ + pline("A strange tingling runs up your %s.", body_part(ARM)); + break; + case 27: /* Strange feeling */ + You_feel("a sudden chill."); + break; + case 28: /* Strange feeling */ + pline("An urge to take a bath overwhelms you."); + { + long money = money_cnt(invent); + struct obj *otmp; + if (money > 10) { + /* Amount to lose. Might get rounded up as fountains don't + * pay change... */ + money = somegold(money) / 10; + for (otmp = invent; otmp && money > 0; otmp = otmp->nobj) + if (otmp->oclass == COIN_CLASS) { + int denomination = objects[otmp->otyp].oc_cost; + long coin_loss = + (money + denomination - 1) / denomination; + coin_loss = min(coin_loss, otmp->quan); + otmp->quan -= coin_loss; + money -= coin_loss * denomination; + if (!otmp->quan) + delobj(otmp); + } + You("lost some of your money in the fountain!"); + CLEAR_FOUNTAIN_LOOTED(u.ux, u.uy); + exercise(A_WIS, FALSE); + } + } + break; + case 29: /* You see coins */ - /* We make fountains have more coins the closer you are to the - * surface. After all, there will have been more people going - * by. Just like a shopping mall! Chris Woodbury */ + /* We make fountains have more coins the closer you are to the + * surface. After all, there will have been more people going + * by. Just like a shopping mall! Chris Woodbury */ - if (FOUNTAIN_IS_LOOTED(u.ux,u.uy)) break; - SET_FOUNTAIN_LOOTED(u.ux,u.uy); - (void) mkgold((long) - (rnd((dunlevs_in_dungeon(&u.uz)-dunlev(&u.uz)+1)*2)+5), - u.ux, u.uy); - if (!Blind) - pline("Far below you, you see coins glistening in the water."); - exercise(A_WIS, TRUE); - newsym(u.ux,u.uy); - break; - } - update_inventory(); - dryup(u.ux, u.uy, TRUE); + if (FOUNTAIN_IS_LOOTED(u.ux, u.uy)) + break; + SET_FOUNTAIN_LOOTED(u.ux, u.uy); + (void) mkgold((long) (rnd((dunlevs_in_dungeon(&u.uz) - dunlev(&u.uz) + + 1) * 2) + 5), + u.ux, u.uy); + if (!Blind) + pline("Far below you, you see coins glistening in the water."); + exercise(A_WIS, TRUE); + newsym(u.ux, u.uy); + break; + } + update_inventory(); + dryup(u.ux, u.uy, TRUE); } void -breaksink(x,y) +breaksink(x, y) int x, y; { - if(cansee(x,y) || (x == u.ux && y == u.uy)) - pline_The("pipes break! Water spurts out!"); + if (cansee(x, y) || (x == u.ux && y == u.uy)) + pline_The("pipes break! Water spurts out!"); level.flags.nsinks--; levl[x][y].doormask = 0; levl[x][y].typ = FOUNTAIN; level.flags.nfountains++; - newsym(x,y); + newsym(x, y); } void drinksink() { - struct obj *otmp; - struct monst *mtmp; + struct obj *otmp; + struct monst *mtmp; - if (Levitation) { - floating_above("sink"); - return; - } - switch(rn2(20)) { - case 0: You("take a sip of very cold water."); - break; - case 1: You("take a sip of very warm water."); - break; - case 2: You("take a sip of scalding hot water."); - if (Fire_resistance) - pline("It seems quite tasty."); - else losehp(rnd(6), "sipping boiling water", KILLED_BY); - /* boiling water burns considered fire damage */ - break; - case 3: if (mvitals[PM_SEWER_RAT].mvflags & G_GONE) - pline_The("sink seems quite dirty."); - else { - mtmp = makemon(&mons[PM_SEWER_RAT], - u.ux, u.uy, NO_MM_FLAGS); - if (mtmp) pline("Eek! There's %s in the sink!", - (Blind || !canspotmon(mtmp)) ? - "something squirmy" : - a_monnam(mtmp)); - } - break; - case 4: do { - otmp = mkobj(POTION_CLASS,FALSE); - if (otmp->otyp == POT_WATER) { - obfree(otmp, (struct obj *)0); - otmp = (struct obj *) 0; - } - } while(!otmp); - otmp->cursed = otmp->blessed = 0; - pline("Some %s liquid flows from the faucet.", - Blind ? "odd" : - hcolor(OBJ_DESCR(objects[otmp->otyp]))); - otmp->dknown = !(Blind || Hallucination); - otmp->quan++; /* Avoid panic upon useup() */ - otmp->fromsink = 1; /* kludge for docall() */ - (void) dopotion(otmp); - obfree(otmp, (struct obj *)0); - break; - case 5: if (!(levl[u.ux][u.uy].looted & S_LRING)) { - You("find a ring in the sink!"); - (void) mkobj_at(RING_CLASS, u.ux, u.uy, TRUE); - levl[u.ux][u.uy].looted |= S_LRING; - exercise(A_WIS, TRUE); - newsym(u.ux,u.uy); - } else pline("Some dirty water backs up in the drain."); - break; - case 6: breaksink(u.ux,u.uy); - break; - case 7: pline_The("water moves as though of its own will!"); - if ((mvitals[PM_WATER_ELEMENTAL].mvflags & G_GONE) - || !makemon(&mons[PM_WATER_ELEMENTAL], - u.ux, u.uy, NO_MM_FLAGS)) - pline("But it quiets down."); - break; - case 8: pline("Yuk, this water tastes awful."); - more_experienced(1,0); - newexplevel(); - break; - case 9: pline("Gaggg... this tastes like sewage! You vomit."); - morehungry(rn1(30-ACURR(A_CON), 11)); - vomit(); - break; - case 10: pline("This water contains toxic wastes!"); - if (!Unchanging) { - You("undergo a freakish metamorphosis!"); - polyself(0); - } - break; - /* more odd messages --JJB */ - case 11: You_hear("clanking from the pipes..."); - break; - case 12: You_hear("snatches of song from among the sewers..."); - break; - case 19: if (Hallucination) { - pline("From the murky drain, a hand reaches up... --oops--"); - break; - } - default: You("take a sip of %s water.", - rn2(3) ? (rn2(2) ? "cold" : "warm") : "hot"); - } + if (Levitation) { + floating_above("sink"); + return; + } + switch (rn2(20)) { + case 0: + You("take a sip of very cold water."); + break; + case 1: + You("take a sip of very warm water."); + break; + case 2: + You("take a sip of scalding hot water."); + if (Fire_resistance) + pline("It seems quite tasty."); + else + losehp(rnd(6), "sipping boiling water", KILLED_BY); + /* boiling water burns considered fire damage */ + break; + case 3: + if (mvitals[PM_SEWER_RAT].mvflags & G_GONE) + pline_The("sink seems quite dirty."); + else { + mtmp = makemon(&mons[PM_SEWER_RAT], u.ux, u.uy, NO_MM_FLAGS); + if (mtmp) + pline("Eek! There's %s in the sink!", + (Blind || !canspotmon(mtmp)) ? "something squirmy" + : a_monnam(mtmp)); + } + break; + case 4: + do { + otmp = mkobj(POTION_CLASS, FALSE); + if (otmp->otyp == POT_WATER) { + obfree(otmp, (struct obj *) 0); + otmp = (struct obj *) 0; + } + } while (!otmp); + otmp->cursed = otmp->blessed = 0; + pline("Some %s liquid flows from the faucet.", + Blind ? "odd" : hcolor(OBJ_DESCR(objects[otmp->otyp]))); + otmp->dknown = !(Blind || Hallucination); + otmp->quan++; /* Avoid panic upon useup() */ + otmp->fromsink = 1; /* kludge for docall() */ + (void) dopotion(otmp); + obfree(otmp, (struct obj *) 0); + break; + case 5: + if (!(levl[u.ux][u.uy].looted & S_LRING)) { + You("find a ring in the sink!"); + (void) mkobj_at(RING_CLASS, u.ux, u.uy, TRUE); + levl[u.ux][u.uy].looted |= S_LRING; + exercise(A_WIS, TRUE); + newsym(u.ux, u.uy); + } else + pline("Some dirty water backs up in the drain."); + break; + case 6: + breaksink(u.ux, u.uy); + break; + case 7: + pline_The("water moves as though of its own will!"); + if ((mvitals[PM_WATER_ELEMENTAL].mvflags & G_GONE) + || !makemon(&mons[PM_WATER_ELEMENTAL], u.ux, u.uy, NO_MM_FLAGS)) + pline("But it quiets down."); + break; + case 8: + pline("Yuk, this water tastes awful."); + more_experienced(1, 0); + newexplevel(); + break; + case 9: + pline("Gaggg... this tastes like sewage! You vomit."); + morehungry(rn1(30 - ACURR(A_CON), 11)); + vomit(); + break; + case 10: + pline("This water contains toxic wastes!"); + if (!Unchanging) { + You("undergo a freakish metamorphosis!"); + polyself(0); + } + break; + /* more odd messages --JJB */ + case 11: + You_hear("clanking from the pipes..."); + break; + case 12: + You_hear("snatches of song from among the sewers..."); + break; + case 19: + if (Hallucination) { + pline("From the murky drain, a hand reaches up... --oops--"); + break; + } + default: + You("take a sip of %s water.", + rn2(3) ? (rn2(2) ? "cold" : "warm") : "hot"); + } } /*fountain.c*/ diff --git a/src/hack.c b/src/hack.c index a5eb842b3..f923da9d3 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1,24 +1,24 @@ -/* NetHack 3.6 hack.c $NHDT-Date: 1429412557 2015/04/19 03:02:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.143 $ */ +/* NetHack 3.6 hack.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.148 $ */ /* NetHack 3.6 hack.c $Date: 2013/10/26 21:33:47 $ $Revision: 1.120 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -/* #define DEBUG */ /* uncomment for debugging */ +/* #define DEBUG */ /* uncomment for debugging */ STATIC_DCL void NDECL(maybe_wail); STATIC_DCL int NDECL(moverock); -STATIC_DCL int FDECL(still_chewing,(XCHAR_P,XCHAR_P)); +STATIC_DCL int FDECL(still_chewing, (XCHAR_P, XCHAR_P)); STATIC_DCL void NDECL(dosinkfall); STATIC_DCL boolean FDECL(findtravelpath, (BOOLEAN_P)); -STATIC_DCL boolean FDECL(trapmove, (int,int,struct trap *)); +STATIC_DCL boolean FDECL(trapmove, (int, int, struct trap *)); STATIC_DCL void NDECL(switch_terrain); -STATIC_DCL struct monst *FDECL(monstinroom, (struct permonst *,int)); -STATIC_DCL boolean FDECL(doorless_door, (int,int)); +STATIC_DCL struct monst *FDECL(monstinroom, (struct permonst *, int)); +STATIC_DCL boolean FDECL(doorless_door, (int, int)); STATIC_DCL void FDECL(move_update, (BOOLEAN_P)); -#define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE) +#define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE) static anything tmp_anything; @@ -60,7 +60,7 @@ struct obj *obj; boolean revive_nasty(x, y, msg) -int x,y; +int x, y; const char *msg; { register struct obj *otmp, *otmp2; @@ -68,27 +68,28 @@ const char *msg; coord cc; boolean revived = FALSE; - for(otmp = level.objects[x][y]; otmp; otmp = otmp2) { - otmp2 = otmp->nexthere; - if (otmp->otyp == CORPSE && - (is_rider(&mons[otmp->corpsenm]) || - otmp->corpsenm == PM_WIZARD_OF_YENDOR)) { - /* move any living monster already at that location */ - if((mtmp = m_at(x,y)) && enexto(&cc, x, y, mtmp->data)) - rloc_to(mtmp, cc.x, cc.y); - if(msg) Norep("%s", msg); - revived = revive_corpse(otmp); - } + for (otmp = level.objects[x][y]; otmp; otmp = otmp2) { + otmp2 = otmp->nexthere; + if (otmp->otyp == CORPSE + && (is_rider(&mons[otmp->corpsenm]) + || otmp->corpsenm == PM_WIZARD_OF_YENDOR)) { + /* move any living monster already at that location */ + if ((mtmp = m_at(x, y)) && enexto(&cc, x, y, mtmp->data)) + rloc_to(mtmp, cc.x, cc.y); + if (msg) + Norep("%s", msg); + revived = revive_corpse(otmp); + } } /* this location might not be safe, if not, move revived monster */ if (revived) { - mtmp = m_at(x,y); - if (mtmp && !goodpos(x, y, mtmp, 0) && - enexto(&cc, x, y, mtmp->data)) { - rloc_to(mtmp, cc.x, cc.y); - } - /* else impossible? */ + mtmp = m_at(x, y); + if (mtmp && !goodpos(x, y, mtmp, 0) + && enexto(&cc, x, y, mtmp->data)) { + rloc_to(mtmp, cc.x, cc.y); + } + /* else impossible? */ } return (revived); @@ -102,228 +103,240 @@ moverock() register struct trap *ttmp; register struct monst *mtmp; - sx = u.ux + u.dx, sy = u.uy + u.dy; /* boulder starting position */ + sx = u.ux + u.dx, sy = u.uy + u.dy; /* boulder starting position */ while ((otmp = sobj_at(BOULDER, sx, sy)) != 0) { - /* make sure that this boulder is visible as the top object */ - if (otmp != level.objects[sx][sy]) movobj(otmp, sx, sy); + /* make sure that this boulder is visible as the top object */ + if (otmp != level.objects[sx][sy]) + movobj(otmp, sx, sy); - rx = u.ux + 2 * u.dx; /* boulder destination position */ - ry = u.uy + 2 * u.dy; - nomul(0); - if (Levitation || Is_airlevel(&u.uz)) { - if (Blind) feel_location(sx, sy); - You("don't have enough leverage to push %s.", the(xname(otmp))); - /* Give them a chance to climb over it? */ - return -1; - } - if (verysmall(youmonst.data) && !u.usteed) { - if (Blind) feel_location(sx, sy); - pline("You're too small to push that %s.", xname(otmp)); - goto cannot_push; - } - if (isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) && - levl[rx][ry].typ != IRONBARS && - (!IS_DOOR(levl[rx][ry].typ) || !(u.dx && u.dy) || - doorless_door(rx, ry)) && - !sobj_at(BOULDER, rx, ry)) { - ttmp = t_at(rx, ry); - mtmp = m_at(rx, ry); - - /* KMH -- Sokoban doesn't let you push boulders diagonally */ - if (Sokoban && u.dx && u.dy) { - if (Blind) feel_location(sx,sy); - pline("%s won't roll diagonally on this %s.", - The(xname(otmp)), surface(sx, sy)); - goto cannot_push; - } - - if (revive_nasty(rx, ry, "You sense movement on the other side.")) - return (-1); - - if (mtmp && !noncorporeal(mtmp->data) && - (!mtmp->mtrapped || - !(ttmp && ((ttmp->ttyp == PIT) || - (ttmp->ttyp == SPIKED_PIT))))) { - if (Blind) feel_location(sx, sy); - if (canspotmon(mtmp)) - pline("There's %s on the other side.", a_monnam(mtmp)); - else { - You_hear("a monster behind %s.", the(xname(otmp))); - map_invisible(rx, ry); - } - if (flags.verbose) - pline("Perhaps that's why %s cannot move it.", - u.usteed ? y_monnam(u.usteed) : "you"); - goto cannot_push; - } - - if (ttmp) { - /* if a trap operates on the boulder, don't attempt - to move any others at this location; return -1 - if another boulder is in hero's way, or 0 if he - should advance to the vacated boulder position */ - switch(ttmp->ttyp) { - case LANDMINE: - if (rn2(10)) { - obj_extract_self(otmp); - place_object(otmp, rx, ry); - newsym(sx, sy); - pline("KAABLAMM!!! %s %s land mine.", - Tobjnam(otmp, "trigger"), - ttmp->madeby_u ? "your" : "a"); - blow_up_landmine(ttmp); - /* if the boulder remains, it should fill the pit */ - fill_pit(u.ux, u.uy); - if (cansee(rx,ry)) newsym(rx,ry); - return sobj_at(BOULDER, sx, sy) ? -1 : 0; - } - break; - case SPIKED_PIT: - case PIT: - obj_extract_self(otmp); - /* vision kludge to get messages right; - the pit will temporarily be seen even - if this is one among multiple boulders */ - if (!Blind) viz_array[ry][rx] |= IN_SIGHT; - if (!flooreffects(otmp, rx, ry, "fall")) { - place_object(otmp, rx, ry); - } - if (mtmp && !Blind) newsym(rx, ry); - return sobj_at(BOULDER, sx, sy) ? -1 : 0; - case HOLE: - case TRAPDOOR: + rx = u.ux + 2 * u.dx; /* boulder destination position */ + ry = u.uy + 2 * u.dy; + nomul(0); + if (Levitation || Is_airlevel(&u.uz)) { if (Blind) - pline("Kerplunk! You no longer feel %s.", - the(xname(otmp))); - else - pline("%s%s and %s a %s in the %s!", - Tobjnam(otmp, - (ttmp->ttyp == TRAPDOOR) ? "trigger" : "fall"), - (ttmp->ttyp == TRAPDOOR) ? "" : " into", - otense(otmp, "plug"), - (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole", - surface(rx, ry)); - deltrap(ttmp); - delobj(otmp); - bury_objs(rx, ry); - levl[rx][ry].wall_info &= ~W_NONDIGGABLE; - levl[rx][ry].candig = 1; - if (cansee(rx,ry)) newsym(rx,ry); - return sobj_at(BOULDER, sx, sy) ? -1 : 0; - case LEVEL_TELEP: - case TELEP_TRAP: - { - int newlev = 0; /* lint suppression */ - d_level dest; + feel_location(sx, sy); + You("don't have enough leverage to push %s.", the(xname(otmp))); + /* Give them a chance to climb over it? */ + return -1; + } + if (verysmall(youmonst.data) && !u.usteed) { + if (Blind) + feel_location(sx, sy); + pline("You're too small to push that %s.", xname(otmp)); + goto cannot_push; + } + if (isok(rx, ry) && !IS_ROCK(levl[rx][ry].typ) + && levl[rx][ry].typ != IRONBARS + && (!IS_DOOR(levl[rx][ry].typ) || !(u.dx && u.dy) + || doorless_door(rx, ry)) && !sobj_at(BOULDER, rx, ry)) { + ttmp = t_at(rx, ry); + mtmp = m_at(rx, ry); - if (ttmp->ttyp == LEVEL_TELEP) { - newlev = random_teleport_level(); - if (newlev == depth(&u.uz) || In_endgame(&u.uz)) - /* trap didn't work; skip "disappears" message */ - goto dopush; + /* KMH -- Sokoban doesn't let you push boulders diagonally */ + if (Sokoban && u.dx && u.dy) { + if (Blind) + feel_location(sx, sy); + pline("%s won't roll diagonally on this %s.", + The(xname(otmp)), surface(sx, sy)); + goto cannot_push; } + + if (revive_nasty(rx, ry, "You sense movement on the other side.")) + return (-1); + + if (mtmp && !noncorporeal(mtmp->data) + && (!mtmp->mtrapped + || !(ttmp && ((ttmp->ttyp == PIT) + || (ttmp->ttyp == SPIKED_PIT))))) { + if (Blind) + feel_location(sx, sy); + if (canspotmon(mtmp)) + pline("There's %s on the other side.", a_monnam(mtmp)); + else { + You_hear("a monster behind %s.", the(xname(otmp))); + map_invisible(rx, ry); + } + if (flags.verbose) + pline("Perhaps that's why %s cannot move it.", + u.usteed ? y_monnam(u.usteed) : "you"); + goto cannot_push; + } + + if (ttmp) { + /* if a trap operates on the boulder, don't attempt + to move any others at this location; return -1 + if another boulder is in hero's way, or 0 if he + should advance to the vacated boulder position */ + switch (ttmp->ttyp) { + case LANDMINE: + if (rn2(10)) { + obj_extract_self(otmp); + place_object(otmp, rx, ry); + newsym(sx, sy); + pline("KAABLAMM!!! %s %s land mine.", + Tobjnam(otmp, "trigger"), + ttmp->madeby_u ? "your" : "a"); + blow_up_landmine(ttmp); + /* if the boulder remains, it should fill the pit */ + fill_pit(u.ux, u.uy); + if (cansee(rx, ry)) + newsym(rx, ry); + return sobj_at(BOULDER, sx, sy) ? -1 : 0; + } + break; + case SPIKED_PIT: + case PIT: + obj_extract_self(otmp); + /* vision kludge to get messages right; + the pit will temporarily be seen even + if this is one among multiple boulders */ + if (!Blind) + viz_array[ry][rx] |= IN_SIGHT; + if (!flooreffects(otmp, rx, ry, "fall")) { + place_object(otmp, rx, ry); + } + if (mtmp && !Blind) + newsym(rx, ry); + return sobj_at(BOULDER, sx, sy) ? -1 : 0; + case HOLE: + case TRAPDOOR: + if (Blind) + pline("Kerplunk! You no longer feel %s.", + the(xname(otmp))); + else + pline("%s%s and %s a %s in the %s!", + Tobjnam(otmp, (ttmp->ttyp == TRAPDOOR) + ? "trigger" + : "fall"), + (ttmp->ttyp == TRAPDOOR) ? "" : " into", + otense(otmp, "plug"), + (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole", + surface(rx, ry)); + deltrap(ttmp); + delobj(otmp); + bury_objs(rx, ry); + levl[rx][ry].wall_info &= ~W_NONDIGGABLE; + levl[rx][ry].candig = 1; + if (cansee(rx, ry)) + newsym(rx, ry); + return sobj_at(BOULDER, sx, sy) ? -1 : 0; + case LEVEL_TELEP: + case TELEP_TRAP: { + int newlev = 0; /* lint suppression */ + d_level dest; + + if (ttmp->ttyp == LEVEL_TELEP) { + newlev = random_teleport_level(); + if (newlev == depth(&u.uz) || In_endgame(&u.uz)) + /* trap didn't work; skip "disappears" message */ + goto dopush; + } + if (u.usteed) + pline("%s pushes %s and suddenly it disappears!", + upstart(y_monnam(u.usteed)), the(xname(otmp))); + else + You("push %s and suddenly it disappears!", + the(xname(otmp))); + if (ttmp->ttyp == TELEP_TRAP) { + (void) rloco(otmp); + } else { + obj_extract_self(otmp); + add_to_migration(otmp); + get_level(&dest, newlev); + otmp->ox = dest.dnum; + otmp->oy = dest.dlevel; + otmp->owornmask = (long) MIGR_RANDOM; + } + seetrap(ttmp); + return sobj_at(BOULDER, sx, sy) ? -1 : 0; + } + default: + break; /* boulder not affected by this trap */ + } + } + + if (closed_door(rx, ry)) + goto nopushmsg; + if (boulder_hits_pool(otmp, rx, ry, TRUE)) + continue; + /* + * Re-link at top of fobj chain so that pile order is preserved + * when level is restored. + */ + if (otmp != fobj) { + remove_object(otmp); + place_object(otmp, otmp->ox, otmp->oy); + } + + { +#ifdef LINT /* static long lastmovetime; */ + long lastmovetime; + lastmovetime = 0; +#else + /* note: reset to zero after save/restore cycle */ + static NEARDATA long lastmovetime; +#endif + dopush: + if (!u.usteed) { + if (moves > lastmovetime + 2 || moves < lastmovetime) + pline("With %s effort you move %s.", + throws_rocks(youmonst.data) ? "little" + : "great", + the(xname(otmp))); + exercise(A_STR, TRUE); + } else + pline("%s moves %s.", upstart(y_monnam(u.usteed)), + the(xname(otmp))); + lastmovetime = moves; + } + + /* Move the boulder *after* the message. */ + if (glyph_is_invisible(levl[rx][ry].glyph)) + unmap_object(rx, ry); + movobj(otmp, rx, ry); /* does newsym(rx,ry) */ + if (Blind) { + feel_location(rx, ry); + feel_location(sx, sy); + } else { + newsym(sx, sy); + } + } else { + nopushmsg: if (u.usteed) - pline("%s pushes %s and suddenly it disappears!", + pline("%s tries to move %s, but cannot.", upstart(y_monnam(u.usteed)), the(xname(otmp))); else - You("push %s and suddenly it disappears!", - the(xname(otmp))); - if (ttmp->ttyp == TELEP_TRAP) { - (void)rloco(otmp); - } else { - obj_extract_self(otmp); - add_to_migration(otmp); - get_level(&dest, newlev); - otmp->ox = dest.dnum; - otmp->oy = dest.dlevel; - otmp->owornmask = (long)MIGR_RANDOM; + You("try to move %s, but in vain.", the(xname(otmp))); + if (Blind) + feel_location(sx, sy); + cannot_push: + if (throws_rocks(youmonst.data)) { + if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { + You("aren't skilled enough to %s %s from %s.", + (flags.pickup && !Sokoban) ? "pick up" : "push aside", + the(xname(otmp)), y_monnam(u.usteed)); + } else { + pline("However, you can easily %s.", + (flags.pickup && !Sokoban) ? "pick it up" + : "push it aside"); + sokoban_guilt(); + break; + } + break; } - seetrap(ttmp); - return sobj_at(BOULDER, sx, sy) ? -1 : 0; - } - default: - break; /* boulder not affected by this trap */ - } - } - if (closed_door(rx, ry)) - goto nopushmsg; - if (boulder_hits_pool(otmp, rx, ry, TRUE)) - continue; - /* - * Re-link at top of fobj chain so that pile order is preserved - * when level is restored. - */ - if (otmp != fobj) { - remove_object(otmp); - place_object(otmp, otmp->ox, otmp->oy); + if (!u.usteed + && (((!invent || inv_weight() <= -850) + && (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][sy].typ) + && IS_ROCK(levl[sx][u.uy].typ)))) + || verysmall(youmonst.data))) { + pline("However, you can squeeze yourself into a small " + "opening."); + sokoban_guilt(); + break; + } else + return (-1); } - - { -#ifdef LINT /* static long lastmovetime; */ - long lastmovetime; - lastmovetime = 0; -#else - /* note: reset to zero after save/restore cycle */ - static NEARDATA long lastmovetime; -#endif - dopush: - if (!u.usteed) { - if (moves > lastmovetime+2 || moves < lastmovetime) - pline("With %s effort you move %s.", - throws_rocks(youmonst.data) ? "little" : "great", - the(xname(otmp))); - exercise(A_STR, TRUE); - } else - pline("%s moves %s.", - upstart(y_monnam(u.usteed)), the(xname(otmp))); - lastmovetime = moves; - } - - /* Move the boulder *after* the message. */ - if (glyph_is_invisible(levl[rx][ry].glyph)) - unmap_object(rx, ry); - movobj(otmp, rx, ry); /* does newsym(rx,ry) */ - if (Blind) { - feel_location(rx,ry); - feel_location(sx, sy); - } else { - newsym(sx, sy); - } - } else { - nopushmsg: - if (u.usteed) - pline("%s tries to move %s, but cannot.", - upstart(y_monnam(u.usteed)), the(xname(otmp))); - else - You("try to move %s, but in vain.", the(xname(otmp))); - if (Blind) feel_location(sx, sy); - cannot_push: - if (throws_rocks(youmonst.data)) { - if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { - You("aren't skilled enough to %s %s from %s.", - (flags.pickup && !Sokoban) ? "pick up" : "push aside", - the(xname(otmp)), y_monnam(u.usteed)); - } else { - pline("However, you can easily %s.", - (flags.pickup && !Sokoban) ? - "pick it up" : "push it aside"); - sokoban_guilt(); - break; - } - break; - } - - if (!u.usteed && (((!invent || inv_weight() <= -850) && - (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][sy].typ) - && IS_ROCK(levl[sx][u.uy].typ)))) - || verysmall(youmonst.data))) { - pline("However, you can squeeze yourself into a small opening."); - sokoban_guilt(); - break; - } else - return (-1); - } } return (0); } @@ -335,50 +348,60 @@ moverock() * when done. */ STATIC_OVL int -still_chewing(x,y) - xchar x, y; +still_chewing(x, y) +xchar x, y; { struct rm *lev = &levl[x][y]; - struct obj *boulder = sobj_at(BOULDER,x,y); - const char *digtxt = (char *)0, *dmgtxt = (char *)0; + struct obj *boulder = sobj_at(BOULDER, x, y); + const char *digtxt = (char *) 0, *dmgtxt = (char *) 0; - if (context.digging.down) /* not continuing previous dig (w/ pick-axe) */ - (void) memset((genericptr_t)&context.digging, 0, sizeof(struct dig_info)); + if (context.digging.down) /* not continuing previous dig (w/ pick-axe) */ + (void) memset((genericptr_t) &context.digging, 0, + sizeof(struct dig_info)); - if (!boulder && IS_ROCK(lev->typ) && !may_dig(x,y)) { - You("hurt your teeth on the %s.", - lev->typ == IRONBARS ? "bars" : (IS_TREE(lev->typ) ? "tree" : "hard stone")); - nomul(0); - return 1; - } else if (context.digging.pos.x != x || context.digging.pos.y != y || - !on_level(&context.digging.level, &u.uz)) { - context.digging.down = FALSE; - context.digging.chew = TRUE; - context.digging.warned = FALSE; - context.digging.pos.x = x; - context.digging.pos.y = y; - assign_level(&context.digging.level, &u.uz); - /* solid rock takes more work & time to dig through */ - context.digging.effort = - (IS_ROCK(lev->typ) && !IS_TREE(lev->typ) ? 30 : 60) + u.udaminc; - You("start chewing %s %s.", - (boulder || IS_TREE(lev->typ) || lev->typ == IRONBARS) ? "on a" : "a hole in the", - boulder ? "boulder" : - IS_TREE(lev->typ) ? "tree" : IS_ROCK(lev->typ) ? "rock" : - lev->typ == IRONBARS ? "bar" : "door"); - watch_dig((struct monst *)0, x, y, FALSE); - return 1; - } else if ((context.digging.effort += (30 + u.udaminc)) <= 100) { - if (flags.verbose) - You("%s chewing on the %s.", - context.digging.chew ? "continue" : "begin", - boulder ? "boulder" : - IS_TREE(lev->typ) ? "tree" : - IS_ROCK(lev->typ) ? "rock" : - lev->typ == IRONBARS ? "bars" : "door"); - context.digging.chew = TRUE; - watch_dig((struct monst *)0, x, y, FALSE); - return 1; + if (!boulder && IS_ROCK(lev->typ) && !may_dig(x, y)) { + You("hurt your teeth on the %s.", + lev->typ == IRONBARS + ? "bars" + : (IS_TREE(lev->typ) ? "tree" : "hard stone")); + nomul(0); + return 1; + } else if (context.digging.pos.x != x || context.digging.pos.y != y + || !on_level(&context.digging.level, &u.uz)) { + context.digging.down = FALSE; + context.digging.chew = TRUE; + context.digging.warned = FALSE; + context.digging.pos.x = x; + context.digging.pos.y = y; + assign_level(&context.digging.level, &u.uz); + /* solid rock takes more work & time to dig through */ + context.digging.effort = + (IS_ROCK(lev->typ) && !IS_TREE(lev->typ) ? 30 : 60) + u.udaminc; + You("start chewing %s %s.", + (boulder || IS_TREE(lev->typ) || lev->typ == IRONBARS) + ? "on a" + : "a hole in the", + boulder ? "boulder" : IS_TREE(lev->typ) + ? "tree" + : IS_ROCK(lev->typ) + ? "rock" + : lev->typ == IRONBARS ? "bar" + : "door"); + watch_dig((struct monst *) 0, x, y, FALSE); + return 1; + } else if ((context.digging.effort += (30 + u.udaminc)) <= 100) { + if (flags.verbose) + You("%s chewing on the %s.", + context.digging.chew ? "continue" : "begin", + boulder ? "boulder" + : IS_TREE(lev->typ) + ? "tree" + : IS_ROCK(lev->typ) + ? "rock" + : lev->typ == IRONBARS ? "bars" : "door"); + context.digging.chew = TRUE; + watch_dig((struct monst *) 0, x, y, FALSE); + return 1; } /* Okay, you've chewed through something */ @@ -386,76 +409,81 @@ still_chewing(x,y) u.uhunger += rnd(20); if (boulder) { - delobj(boulder); /* boulder goes bye-bye */ - You("eat the boulder."); /* yum */ + delobj(boulder); /* boulder goes bye-bye */ + You("eat the boulder."); /* yum */ - /* - * The location could still block because of - * 1. More than one boulder - * 2. Boulder stuck in a wall/stone/door. - * - * [perhaps use does_block() below (from vision.c)] - */ - if (IS_ROCK(lev->typ) || closed_door(x,y) || sobj_at(BOULDER,x,y)) { - block_point(x,y); /* delobj will unblock the point */ - /* reset dig state */ - (void) memset((genericptr_t)&context.digging, 0, sizeof(struct dig_info)); - return 1; - } + /* + * The location could still block because of + * 1. More than one boulder + * 2. Boulder stuck in a wall/stone/door. + * + * [perhaps use does_block() below (from vision.c)] + */ + if (IS_ROCK(lev->typ) || closed_door(x, y) + || sobj_at(BOULDER, x, y)) { + block_point(x, y); /* delobj will unblock the point */ + /* reset dig state */ + (void) memset((genericptr_t) &context.digging, 0, + sizeof(struct dig_info)); + return 1; + } } else if (IS_WALL(lev->typ)) { - if (*in_rooms(x, y, SHOPBASE)) { - add_damage(x, y, 10L * ACURRSTR); - dmgtxt = "damage"; - } - digtxt = "chew a hole in the wall."; - if (level.flags.is_maze_lev) { - lev->typ = ROOM; - } else if (level.flags.is_cavernous_lev && !in_town(x, y)) { - lev->typ = CORR; - } else { - lev->typ = DOOR; - lev->doormask = D_NODOOR; - } + if (*in_rooms(x, y, SHOPBASE)) { + add_damage(x, y, 10L * ACURRSTR); + dmgtxt = "damage"; + } + digtxt = "chew a hole in the wall."; + if (level.flags.is_maze_lev) { + lev->typ = ROOM; + } else if (level.flags.is_cavernous_lev && !in_town(x, y)) { + lev->typ = CORR; + } else { + lev->typ = DOOR; + lev->doormask = D_NODOOR; + } } else if (IS_TREE(lev->typ)) { - digtxt = "chew through the tree."; - lev->typ = ROOM; + digtxt = "chew through the tree."; + lev->typ = ROOM; } else if (lev->typ == IRONBARS) { - digtxt = "eat through the bars."; - dissolve_bars(x,y); + digtxt = "eat through the bars."; + dissolve_bars(x, y); } else if (lev->typ == SDOOR) { - if (lev->doormask & D_TRAPPED) { - lev->doormask = D_NODOOR; - b_trapped("secret door", 0); - } else { - digtxt = "chew through the secret door."; - lev->doormask = D_BROKEN; - } - lev->typ = DOOR; + if (lev->doormask & D_TRAPPED) { + lev->doormask = D_NODOOR; + b_trapped("secret door", 0); + } else { + digtxt = "chew through the secret door."; + lev->doormask = D_BROKEN; + } + lev->typ = DOOR; } else if (IS_DOOR(lev->typ)) { - if (*in_rooms(x, y, SHOPBASE)) { - add_damage(x, y, 400L); - dmgtxt = "break"; - } - if (lev->doormask & D_TRAPPED) { - lev->doormask = D_NODOOR; - b_trapped("door", 0); - } else { - digtxt = "chew through the door."; - lev->doormask = D_BROKEN; - } + if (*in_rooms(x, y, SHOPBASE)) { + add_damage(x, y, 400L); + dmgtxt = "break"; + } + if (lev->doormask & D_TRAPPED) { + lev->doormask = D_NODOOR; + b_trapped("door", 0); + } else { + digtxt = "chew through the door."; + lev->doormask = D_BROKEN; + } } else { /* STONE or SCORR */ - digtxt = "chew a passage through the rock."; - lev->typ = CORR; + digtxt = "chew a passage through the rock."; + lev->typ = CORR; } - unblock_point(x, y); /* vision */ + unblock_point(x, y); /* vision */ newsym(x, y); - if (digtxt) You1(digtxt); /* after newsym */ - if (dmgtxt) pay_for_damage(dmgtxt, FALSE); - (void) memset((genericptr_t)&context.digging, 0, sizeof(struct dig_info)); + if (digtxt) + You1(digtxt); /* after newsym */ + if (dmgtxt) + pay_for_damage(dmgtxt, FALSE); + (void) memset((genericptr_t) &context.digging, 0, + sizeof(struct dig_info)); return 0; } @@ -479,12 +507,12 @@ dosinkfall() register struct obj *obj; int dmg; boolean lev_boots = (uarmf && uarmf->otyp == LEVITATION_BOOTS), - innate_lev = ((HLevitation & (FROMOUTSIDE|FROMFORM)) != 0L), + innate_lev = ((HLevitation & (FROMOUTSIDE | FROMFORM)) != 0L), ufall = (!innate_lev && !(HFlying || EFlying)); /* BFlying */ if (!ufall) { - You(innate_lev ? "wobble unsteadily for a moment." : - "gain control of your flight."); + You(innate_lev ? "wobble unsteadily for a moment." + : "gain control of your flight."); } else { long save_ELev = ELevitation, save_HLev = HLevitation; @@ -494,17 +522,17 @@ dosinkfall() are really still worn has no effect on bones data */ ELevitation = HLevitation = 0L; You("crash to the floor!"); - dmg = rn1(8, 25 - (int)ACURR(A_CON)); - losehp(Maybe_Half_Phys(dmg), - fell_on_sink, NO_KILLER_PREFIX); + dmg = rn1(8, 25 - (int) ACURR(A_CON)); + losehp(Maybe_Half_Phys(dmg), fell_on_sink, NO_KILLER_PREFIX); exercise(A_DEX, FALSE); selftouch("Falling, you"); for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere) - if (obj->oclass == WEAPON_CLASS || is_weptool(obj)) { - You("fell on %s.", doname(obj)); - losehp(Maybe_Half_Phys(rnd(3)), fell_on_sink, NO_KILLER_PREFIX); - exercise(A_CON, FALSE); - } + if (obj->oclass == WEAPON_CLASS || is_weptool(obj)) { + You("fell on %s.", doname(obj)); + losehp(Maybe_Half_Phys(rnd(3)), fell_on_sink, + NO_KILLER_PREFIX); + exercise(A_CON, FALSE); + } ELevitation = save_ELev; HLevitation = save_HLev; } @@ -522,28 +550,28 @@ dosinkfall() * haven't fallen (innate floating or flying becoming unblocked). */ if (ufall || lev_boots) { - (void) stop_donning(lev_boots ? uarmf : (struct obj *)0); + (void) stop_donning(lev_boots ? uarmf : (struct obj *) 0); /* recalculate in case uarmf just got set to null */ lev_boots = (uarmf && uarmf->otyp == LEVITATION_BOOTS); } /* remove worn levitation items */ ELevitation &= ~W_ARTI; - HLevitation &= ~(I_SPECIAL|TIMEOUT); + HLevitation &= ~(I_SPECIAL | TIMEOUT); HLevitation++; - if(uleft && uleft->otyp == RIN_LEVITATION) { + if (uleft && uleft->otyp == RIN_LEVITATION) { obj = uleft; Ring_off(obj); off_msg(obj); } - if(uright && uright->otyp == RIN_LEVITATION) { + if (uright && uright->otyp == RIN_LEVITATION) { obj = uright; Ring_off(obj); off_msg(obj); } if (lev_boots) { obj = uarmf; - (void)Boots_off(); + (void) Boots_off(); off_msg(obj); } HLevitation--; @@ -553,55 +581,59 @@ dosinkfall() } boolean -may_dig(x,y) -register xchar x,y; +may_dig(x, y) +register xchar x, y; /* intended to be called only on ROCKs */ { - return (boolean)(!(IS_STWALL(levl[x][y].typ) && - (levl[x][y].wall_info & W_NONDIGGABLE))); + return (boolean)(!(IS_STWALL(levl[x][y].typ) + && (levl[x][y].wall_info & W_NONDIGGABLE))); } boolean -may_passwall(x,y) -register xchar x,y; +may_passwall(x, y) +register xchar x, y; { - return (boolean)(!(IS_STWALL(levl[x][y].typ) && - (levl[x][y].wall_info & W_NONPASSWALL))); + return (boolean)(!(IS_STWALL(levl[x][y].typ) + && (levl[x][y].wall_info & W_NONPASSWALL))); } boolean -bad_rock(mdat,x,y) +bad_rock(mdat, x, y) struct permonst *mdat; -register xchar x,y; +register xchar x, y; { - return((boolean) ((Sokoban && sobj_at(BOULDER,x,y)) || - (IS_ROCK(levl[x][y].typ) - && (!tunnels(mdat) || needspick(mdat) || !may_dig(x,y)) - && !(passes_walls(mdat) && may_passwall(x,y))))); + return ( + (boolean)((Sokoban && sobj_at(BOULDER, x, y)) + || (IS_ROCK(levl[x][y].typ) + && (!tunnels(mdat) || needspick(mdat) || !may_dig(x, y)) + && !(passes_walls(mdat) && may_passwall(x, y))))); } /* caller has already decided that it's a tight diagonal; check whether a monster--who might be the hero--can fit through, and if not then return the reason why: 1: can't fit, 2: possessions won't fit, 3: sokoban */ -int /* returns 0 if we can squeeze through */ -cant_squeeze_thru(mon) +int /* returns 0 if we can squeeze through */ + cant_squeeze_thru(mon) struct monst *mon; { int amt; struct permonst *ptr = mon->data; /* too big? */ - if (bigmonst(ptr) && - !(amorphous(ptr) || is_whirly(ptr) || - noncorporeal(ptr) || slithy(ptr) || can_fog(mon))) return 1; + if (bigmonst(ptr) + && !(amorphous(ptr) || is_whirly(ptr) || noncorporeal(ptr) + || slithy(ptr) || can_fog(mon))) + return 1; /* lugging too much junk? */ - amt = (mon == &youmonst) ? inv_weight() + weight_cap() : - curr_mon_load(mon); - if (amt > 600) return 2; + amt = + (mon == &youmonst) ? inv_weight() + weight_cap() : curr_mon_load(mon); + if (amt > 600) + return 2; /* Sokoban restriction applies to hero only */ - if (mon == &youmonst && Sokoban) return 3; + if (mon == &youmonst && Sokoban) + return 3; /* can squeeze through */ return 0; @@ -611,19 +643,20 @@ boolean invocation_pos(x, y) xchar x, y; { - return((boolean)(Invocation_lev(&u.uz) && x == inv_pos.x && y == inv_pos.y)); + return ( + (boolean)(Invocation_lev(&u.uz) && x == inv_pos.x && y == inv_pos.y)); } /* return TRUE if (dx,dy) is an OK place to move * mode is one of DO_MOVE, TEST_MOVE or TEST_TRAV */ -boolean +boolean test_move(ux, uy, dx, dy, mode) int ux, uy, dx, dy; int mode; { - int x = ux+dx; - int y = uy+dy; + int x = ux + dx; + int y = uy + dy; register struct rm *tmpr = &levl[x][y]; register struct rm *ust; @@ -632,149 +665,166 @@ int mode; * Check for physical obstacles. First, the place we are going. */ if (IS_ROCK(tmpr->typ) || tmpr->typ == IRONBARS) { - if (Blind && mode == DO_MOVE) feel_location(x,y); - if (Passes_walls && may_passwall(x,y)) { - ; /* do nothing */ - } else if (tmpr->typ == IRONBARS) { - if ((dmgtype(youmonst.data, AD_RUST) || - dmgtype(youmonst.data, AD_CORR)) && - mode == DO_MOVE && still_chewing(x,y)) { - return FALSE; - } - if (!(Passes_walls || passes_bars(youmonst.data))) { - if (iflags.mention_walls) - You("cannot pass through the bars."); - return FALSE; - } - } else if (tunnels(youmonst.data) && !needspick(youmonst.data)) { - /* Eat the rock. */ - if (mode == DO_MOVE && still_chewing(x,y)) return FALSE; - } else if (flags.autodig && !context.run && !context.nopick && - uwep && is_pick(uwep)) { - /* MRKR: Automatic digging when wielding the appropriate tool */ - if (mode == DO_MOVE) - (void) use_pick_axe2(uwep); - return FALSE; - } else { - if (mode == DO_MOVE) { - if (Is_stronghold(&u.uz) && is_db_wall(x,y)) - pline_The("drawbridge is up!"); - /* sokoban restriction stays even after puzzle is solved */ - else if (Passes_walls && !may_passwall(x,y) && In_sokoban(&u.uz)) - pline_The("Sokoban walls resist your ability."); - else if (iflags.mention_walls) - pline("It's a wall."); - } - return FALSE; - } - } else if (IS_DOOR(tmpr->typ)) { - if (closed_door(x,y)) { - if (Blind && mode == DO_MOVE) feel_location(x,y); - if (Passes_walls) - ; /* do nothing */ - else if (can_ooze(&youmonst)) { - if (mode == DO_MOVE) You("ooze under the door."); - } else if (tunnels(youmonst.data) && !needspick(youmonst.data)) { - /* Eat the door. */ - if (mode == DO_MOVE && still_chewing(x,y)) return FALSE; - } else { - if (mode == DO_MOVE) { - if (amorphous(youmonst.data)) - You("try to ooze under the door, but can't squeeze your possessions through."); - if (flags.autoopen && !context.run && !Confusion && !Stunned && !Fumbling) { - context.door_opened = context.move = doopen_indir(x, y); - } else if (x == ux || y == uy) { - if (Blind || Stunned || ACURR(A_DEX) < 10 || Fumbling) { - if (u.usteed) { - You_cant("lead %s through that closed door.", - y_monnam(u.usteed)); - } else { - pline("Ouch! You bump into a door."); - exercise(A_DEX, FALSE); - } - } else pline("That door is closed."); - } - } else if (mode == TEST_TRAV) goto testdiag; - return FALSE; - } - } else { - testdiag: - if (dx && dy && !Passes_walls - && (!doorless_door(x, y) || block_door(x, y))) { - /* Diagonal moves into a door are not allowed. */ if (Blind && mode == DO_MOVE) - feel_location(x,y); - return FALSE; + feel_location(x, y); + if (Passes_walls && may_passwall(x, y)) { + ; /* do nothing */ + } else if (tmpr->typ == IRONBARS) { + if ((dmgtype(youmonst.data, AD_RUST) + || dmgtype(youmonst.data, AD_CORR)) && mode == DO_MOVE + && still_chewing(x, y)) { + return FALSE; + } + if (!(Passes_walls || passes_bars(youmonst.data))) { + if (iflags.mention_walls) + You("cannot pass through the bars."); + return FALSE; + } + } else if (tunnels(youmonst.data) && !needspick(youmonst.data)) { + /* Eat the rock. */ + if (mode == DO_MOVE && still_chewing(x, y)) + return FALSE; + } else if (flags.autodig && !context.run && !context.nopick && uwep + && is_pick(uwep)) { + /* MRKR: Automatic digging when wielding the appropriate tool */ + if (mode == DO_MOVE) + (void) use_pick_axe2(uwep); + return FALSE; + } else { + if (mode == DO_MOVE) { + if (Is_stronghold(&u.uz) && is_db_wall(x, y)) + pline_The("drawbridge is up!"); + /* sokoban restriction stays even after puzzle is solved */ + else if (Passes_walls && !may_passwall(x, y) + && In_sokoban(&u.uz)) + pline_The("Sokoban walls resist your ability."); + else if (iflags.mention_walls) + pline("It's a wall."); + } + return FALSE; + } + } else if (IS_DOOR(tmpr->typ)) { + if (closed_door(x, y)) { + if (Blind && mode == DO_MOVE) + feel_location(x, y); + if (Passes_walls) + ; /* do nothing */ + else if (can_ooze(&youmonst)) { + if (mode == DO_MOVE) + You("ooze under the door."); + } else if (tunnels(youmonst.data) && !needspick(youmonst.data)) { + /* Eat the door. */ + if (mode == DO_MOVE && still_chewing(x, y)) + return FALSE; + } else { + if (mode == DO_MOVE) { + if (amorphous(youmonst.data)) + You("try to ooze under the door, but can't squeeze " + "your possessions through."); + if (flags.autoopen && !context.run && !Confusion + && !Stunned && !Fumbling) { + context.door_opened = context.move = + doopen_indir(x, y); + } else if (x == ux || y == uy) { + if (Blind || Stunned || ACURR(A_DEX) < 10 + || Fumbling) { + if (u.usteed) { + You_cant("lead %s through that closed door.", + y_monnam(u.usteed)); + } else { + pline("Ouch! You bump into a door."); + exercise(A_DEX, FALSE); + } + } else + pline("That door is closed."); + } + } else if (mode == TEST_TRAV) + goto testdiag; + return FALSE; + } + } else { + testdiag: + if (dx && dy && !Passes_walls + && (!doorless_door(x, y) || block_door(x, y))) { + /* Diagonal moves into a door are not allowed. */ + if (Blind && mode == DO_MOVE) + feel_location(x, y); + return FALSE; + } } } - } - if (dx && dy - && bad_rock(youmonst.data,ux,y) && bad_rock(youmonst.data,x,uy)) { - /* Move at a diagonal. */ - switch (cant_squeeze_thru(&youmonst)) { - case 3: - if (mode == DO_MOVE) You("cannot pass that way."); - return FALSE; - case 2: - if (mode == DO_MOVE) You("are carrying too much to get through."); - return FALSE; - case 1: - if (mode == DO_MOVE) Your("body is too large to fit through."); - return FALSE; - default: - break; /* can squeeze through */ - } + if (dx && dy && bad_rock(youmonst.data, ux, y) + && bad_rock(youmonst.data, x, uy)) { + /* Move at a diagonal. */ + switch (cant_squeeze_thru(&youmonst)) { + case 3: + if (mode == DO_MOVE) + You("cannot pass that way."); + return FALSE; + case 2: + if (mode == DO_MOVE) + You("are carrying too much to get through."); + return FALSE; + case 1: + if (mode == DO_MOVE) + Your("body is too large to fit through."); + return FALSE; + default: + break; /* can squeeze through */ + } } else if (dx && dy && worm_cross(ux, uy, x, y)) { - /* consecutive long worm segments are at and */ - if (mode == DO_MOVE) pline("%s is in your way.", Monnam(m_at(ux, y))); - return FALSE; + /* consecutive long worm segments are at and */ + if (mode == DO_MOVE) + pline("%s is in your way.", Monnam(m_at(ux, y))); + return FALSE; } /* Pick travel path that does not require crossing a trap. * Avoid water and lava using the usual running rules. * (but not u.ux/u.uy because findtravelpath walks toward u.ux/u.uy) */ if (context.run == 8 && mode != DO_MOVE && (x != u.ux || y != u.uy)) { - struct trap* t = t_at(x, y); + struct trap *t = t_at(x, y); - if ((t && t->tseen) || - (!Levitation && !Flying && - !is_clinger(youmonst.data) && - is_pool_or_lava(x, y) && levl[x][y].seenv)) - return FALSE; + if ((t && t->tseen) + || (!Levitation && !Flying && !is_clinger(youmonst.data) + && is_pool_or_lava(x, y) && levl[x][y].seenv)) + return FALSE; } ust = &levl[ux][uy]; /* Now see if other things block our way . . */ - if (dx && dy && !Passes_walls && IS_DOOR(ust->typ) && - (!doorless_door(ux, uy) || block_entry(x, y))) { - /* Can't move at a diagonal out of a doorway with door. */ - return FALSE; - } - - if (sobj_at(BOULDER,x,y) && (Sokoban || !Passes_walls)) { - if (!(Blind || Hallucination) && (context.run >= 2) && mode != TEST_TRAV) + if (dx && dy && !Passes_walls && IS_DOOR(ust->typ) + && (!doorless_door(ux, uy) || block_entry(x, y))) { + /* Can't move at a diagonal out of a doorway with door. */ return FALSE; - if (mode == DO_MOVE) { - /* tunneling monsters will chew before pushing */ - if (tunnels(youmonst.data) && !needspick(youmonst.data) && - !Sokoban) { - if (still_chewing(x,y)) return FALSE; - } else - if (moverock() < 0) return FALSE; - } else if (mode == TEST_TRAV) { - struct obj* obj; - - /* don't pick two boulders in a row, unless there's a way thru */ - if (sobj_at(BOULDER,ux,uy) && !Sokoban) { - if (!Passes_walls && - !(tunnels(youmonst.data) && !needspick(youmonst.data)) && - !carrying(PICK_AXE) && !carrying(DWARVISH_MATTOCK) && - !((obj = carrying(WAN_DIGGING)) && - !objects[obj->otyp].oc_name_known)) - return FALSE; - } } - /* assume you'll be able to push it when you get there... */ + + if (sobj_at(BOULDER, x, y) && (Sokoban || !Passes_walls)) { + if (!(Blind || Hallucination) && (context.run >= 2) + && mode != TEST_TRAV) + return FALSE; + if (mode == DO_MOVE) { + /* tunneling monsters will chew before pushing */ + if (tunnels(youmonst.data) && !needspick(youmonst.data) + && !Sokoban) { + if (still_chewing(x, y)) + return FALSE; + } else if (moverock() < 0) + return FALSE; + } else if (mode == TEST_TRAV) { + struct obj *obj; + + /* don't pick two boulders in a row, unless there's a way thru */ + if (sobj_at(BOULDER, ux, uy) && !Sokoban) { + if (!Passes_walls + && !(tunnels(youmonst.data) && !needspick(youmonst.data)) + && !carrying(PICK_AXE) && !carrying(DWARVISH_MATTOCK) + && !((obj = carrying(WAN_DIGGING)) + && !objects[obj->otyp].oc_name_known)) + return FALSE; + } + } + /* assume you'll be able to push it when you get there... */ } /* OK, it is a legal place to move. */ @@ -784,8 +834,8 @@ int mode; #ifdef DEBUG static boolean trav_debug = FALSE; -int -wiz_debug_cmd_traveldisplay() /* in this case, toggle display of travel debug info */ +int wiz_debug_cmd_traveldisplay() /* in this case, toggle display of travel + debug info */ { trav_debug = !trav_debug; return 0; @@ -803,174 +853,185 @@ findtravelpath(guess) boolean guess; { /* if travel to adjacent, reachable location, use normal movement rules */ - if (!guess && context.travel1 && distmin(u.ux, u.uy, u.tx, u.ty) == 1 && - !(u.ux != u.tx && u.uy != u.ty && NODIAG(u.umonnum))) { - context.run = 0; - if (test_move(u.ux, u.uy, u.tx-u.ux, u.ty-u.uy, TEST_MOVE)) { - u.dx = u.tx-u.ux; - u.dy = u.ty-u.uy; - nomul(0); - iflags.travelcc.x = iflags.travelcc.y = -1; - return TRUE; - } - context.run = 8; + if (!guess && context.travel1 && distmin(u.ux, u.uy, u.tx, u.ty) == 1 + && !(u.ux != u.tx && u.uy != u.ty && NODIAG(u.umonnum))) { + context.run = 0; + if (test_move(u.ux, u.uy, u.tx - u.ux, u.ty - u.uy, TEST_MOVE)) { + u.dx = u.tx - u.ux; + u.dy = u.ty - u.uy; + nomul(0); + iflags.travelcc.x = iflags.travelcc.y = -1; + return TRUE; + } + context.run = 8; } if (u.tx != u.ux || u.ty != u.uy) { - xchar travel[COLNO][ROWNO]; - xchar travelstepx[2][COLNO*ROWNO]; - xchar travelstepy[2][COLNO*ROWNO]; - xchar tx, ty, ux, uy; - int n = 1; /* max offset in travelsteps */ - int set = 0; /* two sets current and previous */ - int radius = 1; /* search radius */ - int i; + xchar travel[COLNO][ROWNO]; + xchar travelstepx[2][COLNO * ROWNO]; + xchar travelstepy[2][COLNO * ROWNO]; + xchar tx, ty, ux, uy; + int n = 1; /* max offset in travelsteps */ + int set = 0; /* two sets current and previous */ + int radius = 1; /* search radius */ + int i; - /* If guessing, first find an "obvious" goal location. The obvious - * goal is the position the player knows of, or might figure out - * (couldsee) that is closest to the target on a straight path. - */ - if (guess) { - tx = u.ux; ty = u.uy; ux = u.tx; uy = u.ty; - } else { - tx = u.tx; ty = u.ty; ux = u.ux; uy = u.uy; - } + /* If guessing, first find an "obvious" goal location. The obvious + * goal is the position the player knows of, or might figure out + * (couldsee) that is closest to the target on a straight path. + */ + if (guess) { + tx = u.ux; + ty = u.uy; + ux = u.tx; + uy = u.ty; + } else { + tx = u.tx; + ty = u.ty; + ux = u.ux; + uy = u.uy; + } noguess: - (void) memset((genericptr_t)travel, 0, sizeof(travel)); - travelstepx[0][0] = tx; - travelstepy[0][0] = ty; + (void) memset((genericptr_t) travel, 0, sizeof(travel)); + travelstepx[0][0] = tx; + travelstepy[0][0] = ty; - while (n != 0) { - int nn = 0; + while (n != 0) { + int nn = 0; - for (i = 0; i < n; i++) { - int dir; - int x = travelstepx[set][i]; - int y = travelstepy[set][i]; - static int ordered[] = { 0, 2, 4, 6, 1, 3, 5, 7 }; - /* no diagonal movement for grid bugs */ - int dirmax = NODIAG(u.umonnum) ? 4 : 8; + for (i = 0; i < n; i++) { + int dir; + int x = travelstepx[set][i]; + int y = travelstepy[set][i]; + static int ordered[] = { 0, 2, 4, 6, 1, 3, 5, 7 }; + /* no diagonal movement for grid bugs */ + int dirmax = NODIAG(u.umonnum) ? 4 : 8; - for (dir = 0; dir < dirmax; ++dir) { - int nx = x+xdir[ordered[dir]]; - int ny = y+ydir[ordered[dir]]; + for (dir = 0; dir < dirmax; ++dir) { + int nx = x + xdir[ordered[dir]]; + int ny = y + ydir[ordered[dir]]; - if (!isok(nx, ny)) continue; - if ((!Passes_walls && !can_ooze(&youmonst) && - closed_door(x, y)) || sobj_at(BOULDER, x, y)) { - /* closed doors and boulders usually - * cause a delay, so prefer another path */ - if (travel[x][y] > radius-3) { - travelstepx[1-set][nn] = x; - travelstepy[1-set][nn] = y; - /* don't change travel matrix! */ - nn++; - continue; - } - } - if (test_move(x, y, nx-x, ny-y, TEST_TRAV) && - (levl[nx][ny].seenv || (!Blind && couldsee(nx, ny)))) { - if (nx == ux && ny == uy) { - if (!guess) { - u.dx = x-ux; - u.dy = y-uy; - if (x == u.tx && y == u.ty) { - nomul(0); - /* reset run so domove run checks work */ - context.run = 8; - iflags.travelcc.x = iflags.travelcc.y = -1; + if (!isok(nx, ny)) + continue; + if ((!Passes_walls && !can_ooze(&youmonst) + && closed_door(x, y)) || sobj_at(BOULDER, x, y)) { + /* closed doors and boulders usually + * cause a delay, so prefer another path */ + if (travel[x][y] > radius - 3) { + travelstepx[1 - set][nn] = x; + travelstepy[1 - set][nn] = y; + /* don't change travel matrix! */ + nn++; + continue; + } + } + if (test_move(x, y, nx - x, ny - y, TEST_TRAV) + && (levl[nx][ny].seenv + || (!Blind && couldsee(nx, ny)))) { + if (nx == ux && ny == uy) { + if (!guess) { + u.dx = x - ux; + u.dy = y - uy; + if (x == u.tx && y == u.ty) { + nomul(0); + /* reset run so domove run checks work */ + context.run = 8; + iflags.travelcc.x = iflags.travelcc.y = + -1; + } + return TRUE; + } + } else if (!travel[nx][ny]) { + travelstepx[1 - set][nn] = nx; + travelstepy[1 - set][nn] = ny; + travel[nx][ny] = radius; + nn++; + } + } } - return TRUE; - } - } else if (!travel[nx][ny]) { - travelstepx[1-set][nn] = nx; - travelstepy[1-set][nn] = ny; - travel[nx][ny] = radius; - nn++; } - } - } - } #ifdef DEBUG - if (trav_debug) { - /* Use of warning glyph is arbitrary. It stands out. */ - tmp_at(DISP_ALL, warning_to_glyph(1)); - for (i = 0; i < nn; ++i) { - tmp_at(travelstepx[1-set][i], travelstepy[1-set][i]); - } - delay_output(); - if (flags.runmode == RUN_CRAWL) { - delay_output(); - delay_output(); - } - tmp_at(DISP_END,0); - } -#endif /* DEBUG */ - - n = nn; - set = 1-set; - radius++; - } - - /* if guessing, find best location in travel matrix and go there */ - if (guess) { - int px = tx, py = ty; /* pick location */ - int dist, nxtdist, d2, nd2; - - dist = distmin(ux, uy, tx, ty); - d2 = dist2(ux, uy, tx, ty); - for (tx = 1; tx < COLNO; ++tx) - for (ty = 0; ty < ROWNO; ++ty) - if (travel[tx][ty]) { - nxtdist = distmin(ux, uy, tx, ty); - if (nxtdist == dist && couldsee(tx, ty)) { - nd2 = dist2(ux, uy, tx, ty); - if (nd2 < d2) { - /* prefer non-zigzag path */ - px = tx; py = ty; - d2 = nd2; + if (trav_debug) { + /* Use of warning glyph is arbitrary. It stands out. */ + tmp_at(DISP_ALL, warning_to_glyph(1)); + for (i = 0; i < nn; ++i) { + tmp_at(travelstepx[1 - set][i], travelstepy[1 - set][i]); } - } else if (nxtdist < dist && couldsee(tx, ty)) { - px = tx; py = ty; - dist = nxtdist; - d2 = dist2(ux, uy, tx, ty); + delay_output(); + if (flags.runmode == RUN_CRAWL) { + delay_output(); + delay_output(); + } + tmp_at(DISP_END, 0); } - } - - if (px == u.ux && py == u.uy) { - /* no guesses, just go in the general direction */ - u.dx = sgn(u.tx - u.ux); - u.dy = sgn(u.ty - u.uy); - if (test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)) - return TRUE; - goto found; - } -#ifdef DEBUG - if (trav_debug) { - /* Use of warning glyph is arbitrary. It stands out. */ - tmp_at(DISP_ALL, warning_to_glyph(2)); - tmp_at(px, py); - delay_output(); - if (flags.runmode == RUN_CRAWL) { - delay_output(); - delay_output(); - delay_output(); - delay_output(); - } - tmp_at(DISP_END,0); - } #endif /* DEBUG */ - tx = px; - ty = py; - ux = u.ux; - uy = u.uy; - set = 0; - n = radius = 1; - guess = FALSE; - goto noguess; - } - return FALSE; + + n = nn; + set = 1 - set; + radius++; + } + + /* if guessing, find best location in travel matrix and go there */ + if (guess) { + int px = tx, py = ty; /* pick location */ + int dist, nxtdist, d2, nd2; + + dist = distmin(ux, uy, tx, ty); + d2 = dist2(ux, uy, tx, ty); + for (tx = 1; tx < COLNO; ++tx) + for (ty = 0; ty < ROWNO; ++ty) + if (travel[tx][ty]) { + nxtdist = distmin(ux, uy, tx, ty); + if (nxtdist == dist && couldsee(tx, ty)) { + nd2 = dist2(ux, uy, tx, ty); + if (nd2 < d2) { + /* prefer non-zigzag path */ + px = tx; + py = ty; + d2 = nd2; + } + } else if (nxtdist < dist && couldsee(tx, ty)) { + px = tx; + py = ty; + dist = nxtdist; + d2 = dist2(ux, uy, tx, ty); + } + } + + if (px == u.ux && py == u.uy) { + /* no guesses, just go in the general direction */ + u.dx = sgn(u.tx - u.ux); + u.dy = sgn(u.ty - u.uy); + if (test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)) + return TRUE; + goto found; + } +#ifdef DEBUG + if (trav_debug) { + /* Use of warning glyph is arbitrary. It stands out. */ + tmp_at(DISP_ALL, warning_to_glyph(2)); + tmp_at(px, py); + delay_output(); + if (flags.runmode == RUN_CRAWL) { + delay_output(); + delay_output(); + delay_output(); + delay_output(); + } + tmp_at(DISP_END, 0); + } +#endif /* DEBUG */ + tx = px; + ty = py; + ux = u.ux; + uy = u.uy; + set = 0; + n = radius = 1; + guess = FALSE; + goto noguess; + } + return FALSE; } found: @@ -985,72 +1046,74 @@ found: (all failures and most successful escapes leave hero at original spot) */ STATIC_OVL boolean trapmove(x, y, desttrap) -int x, y; /* targetted destination, */ -struct trap *desttrap; /* nonnull if another trap at */ +int x, y; /* targetted destination, */ +struct trap *desttrap; /* nonnull if another trap at */ { boolean anchored; const char *predicament, *culprit; - char *steedname = !u.usteed ? (char *)0 : y_monnam(u.usteed); + char *steedname = !u.usteed ? (char *) 0 : y_monnam(u.usteed); - if (!u.utrap) return TRUE; /* sanity check */ + if (!u.utrap) + return TRUE; /* sanity check */ switch (u.utraptype) { case TT_BEARTRAP: if (flags.verbose) { - predicament = "caught in a bear trap"; - if (u.usteed) - Norep("%s is %s.", upstart(steedname), predicament); - else - Norep("You are %s.", predicament); - } - /* [why does diagonal movement give quickest escape?] */ - if ((u.dx && u.dy) || !rn2(5)) u.utrap--; - break; - case TT_PIT: - if (desttrap && desttrap->tseen && - (desttrap->ttyp == PIT || desttrap->ttyp == SPIKED_PIT)) - return TRUE; /* move into adjacent pit */ - /* try to escape; position stays same regardless of success */ - climb_pit(); - break; - case TT_WEB: - if (uwep && uwep->oartifact == ART_STING) { - u.utrap = 0; - pline("Sting cuts through the web!"); - break; /* escape trap but don't move */ - } - if (--u.utrap) { - if (flags.verbose) { - predicament = "stuck to the web"; + predicament = "caught in a bear trap"; if (u.usteed) Norep("%s is %s.", upstart(steedname), predicament); else Norep("You are %s.", predicament); } + /* [why does diagonal movement give quickest escape?] */ + if ((u.dx && u.dy) || !rn2(5)) + u.utrap--; + break; + case TT_PIT: + if (desttrap && desttrap->tseen + && (desttrap->ttyp == PIT || desttrap->ttyp == SPIKED_PIT)) + return TRUE; /* move into adjacent pit */ + /* try to escape; position stays same regardless of success */ + climb_pit(); + break; + case TT_WEB: + if (uwep && uwep->oartifact == ART_STING) { + u.utrap = 0; + pline("Sting cuts through the web!"); + break; /* escape trap but don't move */ + } + if (--u.utrap) { + if (flags.verbose) { + predicament = "stuck to the web"; + if (u.usteed) + Norep("%s is %s.", upstart(steedname), predicament); + else + Norep("You are %s.", predicament); + } } else { - if (u.usteed) - pline("%s breaks out of the web.", upstart(steedname)); - else - You("disentangle yourself."); + if (u.usteed) + pline("%s breaks out of the web.", upstart(steedname)); + else + You("disentangle yourself."); } break; case TT_LAVA: if (flags.verbose) { - predicament = "stuck in the lava"; - if (u.usteed) - Norep("%s is %s.", upstart(steedname), predicament); - else - Norep("You are %s.", predicament); + predicament = "stuck in the lava"; + if (u.usteed) + Norep("%s is %s.", upstart(steedname), predicament); + else + Norep("You are %s.", predicament); } if (!is_lava(x, y)) { - u.utrap--; - if ((u.utrap & 0xff) == 0) { - u.utrap = 0; - if (u.usteed) - You("lead %s to the edge of the lava.", steedname); - else - You("pull yourself to the edge of the lava."); - } + u.utrap--; + if ((u.utrap & 0xff) == 0) { + u.utrap = 0; + if (u.usteed) + You("lead %s to the edge of the lava.", steedname); + else + You("pull yourself to the edge of the lava."); + } } u.umoved = TRUE; break; @@ -1058,54 +1121,55 @@ struct trap *desttrap; /* nonnull if another trap at */ case TT_BURIEDBALL: anchored = (u.utraptype == TT_BURIEDBALL); if (anchored) { - coord cc; + coord cc; - cc.x = u.ux, cc.y = u.uy; - /* can move normally within radius 1 of buried ball */ - if (buried_ball(&cc) && dist2(x, y, cc.x, cc.y) <= 2) { - /* ugly hack: we need to issue some message here - in case "you are chained to the buried ball" - was the most recent message given, otherwise - our next attempt to move out of tether range - after this successful move would have its - can't-do-that message suppressed by Norep */ - if (flags.verbose) - Norep("You move within the chain's reach."); - return TRUE; - } + cc.x = u.ux, cc.y = u.uy; + /* can move normally within radius 1 of buried ball */ + if (buried_ball(&cc) && dist2(x, y, cc.x, cc.y) <= 2) { + /* ugly hack: we need to issue some message here + in case "you are chained to the buried ball" + was the most recent message given, otherwise + our next attempt to move out of tether range + after this successful move would have its + can't-do-that message suppressed by Norep */ + if (flags.verbose) + Norep("You move within the chain's reach."); + return TRUE; + } } if (--u.utrap) { - if (flags.verbose) { - if (anchored) { - predicament = "chained to the"; - culprit = "buried ball"; - } else { - predicament = "stuck in the"; - culprit = surface(u.ux, u.uy); + if (flags.verbose) { + if (anchored) { + predicament = "chained to the"; + culprit = "buried ball"; + } else { + predicament = "stuck in the"; + culprit = surface(u.ux, u.uy); + } + if (u.usteed) { + if (anchored) + Norep("You and %s are %s %s.", steedname, predicament, + culprit); + else + Norep("%s is %s %s.", upstart(steedname), predicament, + culprit); + } else + Norep("You are %s %s.", predicament, culprit); } - if (u.usteed) { - if (anchored) - Norep("You and %s are %s %s.", steedname, - predicament, culprit); - else - Norep("%s is %s %s.", upstart(steedname), - predicament, culprit); - } else - Norep("You are %s %s.", predicament, culprit); - } } else { - if (u.usteed) - pline("%s finally %s free.", upstart(steedname), - !anchored ? "lurches" : "wrenches the ball"); - else - You("finally %s free.", - !anchored ? "wriggle" : "wrench the ball"); - if (anchored) - buried_ball_to_punishment(); + if (u.usteed) + pline("%s finally %s free.", upstart(steedname), + !anchored ? "lurches" : "wrenches the ball"); + else + You("finally %s free.", + !anchored ? "wriggle" : "wrench the ball"); + if (anchored) + buried_ball_to_punishment(); } break; default: - impossible("trapmove: stuck in unknown trap? (%d)", (int)u.utraptype); + impossible("trapmove: stuck in unknown trap? (%d)", + (int) u.utraptype); break; } return FALSE; @@ -1114,10 +1178,11 @@ struct trap *desttrap; /* nonnull if another trap at */ boolean u_rooted() { - if(!youmonst.data->mmove) { + if (!youmonst.data->mmove) { You("are rooted %s.", - Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ? - "in place" : "to the ground"); + Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) + ? "in place" + : "to the ground"); nomul(0); return TRUE; } @@ -1129,54 +1194,54 @@ domove() { register struct monst *mtmp; register struct rm *tmpr; - register xchar x,y; - struct trap *trap = NULL; + register xchar x, y; + struct trap *trap = NULL; int wtcap; boolean on_ice; - xchar chainx, chainy, ballx, bally; /* ball&chain new positions */ - int bc_control; /* control for ball&chain */ - boolean cause_delay = FALSE; /* dragging ball will skip a move */ + xchar chainx, chainy, ballx, bally; /* ball&chain new positions */ + int bc_control; /* control for ball&chain */ + boolean cause_delay = FALSE; /* dragging ball will skip a move */ u_wipe_engr(rnd(5)); if (context.travel) { if (!findtravelpath(FALSE)) - (void) findtravelpath(TRUE); + (void) findtravelpath(TRUE); context.travel1 = 0; } - if(((wtcap = near_capacity()) >= OVERLOADED - || (wtcap > SLT_ENCUMBER && - (Upolyd ? (u.mh < 5 && u.mh != u.mhmax) - : (u.uhp < 10 && u.uhp != u.uhpmax)))) - && !Is_airlevel(&u.uz)) { - if(wtcap < OVERLOADED) { - You("don't have enough stamina to move."); - exercise(A_CON, FALSE); + if (((wtcap = near_capacity()) >= OVERLOADED + || (wtcap > SLT_ENCUMBER + && (Upolyd ? (u.mh < 5 && u.mh != u.mhmax) + : (u.uhp < 10 && u.uhp != u.uhpmax)))) + && !Is_airlevel(&u.uz)) { + if (wtcap < OVERLOADED) { + You("don't have enough stamina to move."); + exercise(A_CON, FALSE); } else - You("collapse under your load."); + You("collapse under your load."); nomul(0); return; } - if(u.uswallow) { + if (u.uswallow) { u.dx = u.dy = 0; u.ux = x = u.ustuck->mx; u.uy = y = u.ustuck->my; mtmp = u.ustuck; } else { - if (Is_airlevel(&u.uz) && rn2(4) && - !Levitation && !Flying) { - switch(rn2(3)) { + if (Is_airlevel(&u.uz) && rn2(4) && !Levitation && !Flying) { + switch (rn2(3)) { case 0: - You("tumble in place."); - exercise(A_DEX, FALSE); - break; + You("tumble in place."); + exercise(A_DEX, FALSE); + break; case 1: - You_cant("control your movements very well."); break; + You_cant("control your movements very well."); + break; case 2: - pline("It's hard to walk in thin air."); - exercise(A_DEX, TRUE); - break; + pline("It's hard to walk in thin air."); + exercise(A_DEX, TRUE); + break; } return; } @@ -1185,16 +1250,16 @@ domove() on_ice = !Levitation && is_ice(u.ux, u.uy); if (on_ice) { static int skates = 0; - if (!skates) skates = find_skates(); - if ((uarmf && uarmf->otyp == skates) - || resists_cold(&youmonst) || Flying - || is_floater(youmonst.data) || is_clinger(youmonst.data) - || is_whirly(youmonst.data)) - on_ice = FALSE; + if (!skates) + skates = find_skates(); + if ((uarmf && uarmf->otyp == skates) || resists_cold(&youmonst) + || Flying || is_floater(youmonst.data) + || is_clinger(youmonst.data) || is_whirly(youmonst.data)) + on_ice = FALSE; else if (!rn2(Cold_resistance ? 3 : 2)) { - HFumbling |= FROMOUTSIDE; - HFumbling &= ~TIMEOUT; - HFumbling += 1; /* slip on next move */ + HFumbling |= FROMOUTSIDE; + HFumbling &= ~TIMEOUT; + HFumbling += 1; /* slip on next move */ } } if (!on_ice && (HFumbling & FROMOUTSIDE)) @@ -1202,18 +1267,18 @@ domove() x = u.ux + u.dx; y = u.uy + u.dy; - if(Stunned || (Confusion && !rn2(5))) { + if (Stunned || (Confusion && !rn2(5))) { register int tries = 0; do { - if(tries++ > 50) { + if (tries++ > 50) { nomul(0); return; } confdir(); x = u.ux + u.dx; y = u.uy + u.dy; - } while(!isok(x, y) || bad_rock(youmonst.data, x, y)); + } while (!isok(x, y) || bad_rock(youmonst.data, x, y)); } /* turbulence might alter your actual destination */ if (u.uinwater) { @@ -1225,15 +1290,14 @@ domove() x = u.ux + u.dx; y = u.uy + u.dy; } - if(!isok(x, y)) { + if (!isok(x, y)) { nomul(0); return; } - if (((trap = t_at(x, y)) && trap->tseen) || - (Blind && !Levitation && !Flying && - !is_clinger(youmonst.data) && - is_pool_or_lava(x, y) && levl[x][y].seenv)) { - if(context.run >= 2) { + if (((trap = t_at(x, y)) && trap->tseen) + || (Blind && !Levitation && !Flying && !is_clinger(youmonst.data) + && is_pool_or_lava(x, y) && levl[x][y].seenv)) { + if (context.run >= 2) { nomul(0); context.move = 0; return; @@ -1243,58 +1307,58 @@ domove() if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) { if (distu(u.ustuck->mx, u.ustuck->my) > 2) { - /* perhaps it fled (or was teleported or ... ) */ - u.ustuck = 0; - } else if (sticks(youmonst.data)) { - /* When polymorphed into a sticking monster, - * u.ustuck means it's stuck to you, not you to it. - */ - You("release %s.", mon_nam(u.ustuck)); - u.ustuck = 0; - } else { - /* If holder is asleep or paralyzed: - * 37.5% chance of getting away, - * 12.5% chance of waking/releasing it; - * otherwise: - * 7.5% chance of getting away. - * [strength ought to be a factor] - * If holder is tame and there is no conflict, - * guaranteed escape. - */ - switch (rn2(!u.ustuck->mcanmove ? 8 : 40)) { - case 0: case 1: case 2: - pull_free: - You("pull free from %s.", mon_nam(u.ustuck)); + /* perhaps it fled (or was teleported or ... ) */ u.ustuck = 0; - break; - case 3: - if (!u.ustuck->mcanmove) { - /* it's free to move on next turn */ - u.ustuck->mfrozen = 1; - u.ustuck->msleeping = 0; - } + } else if (sticks(youmonst.data)) { + /* When polymorphed into a sticking monster, + * u.ustuck means it's stuck to you, not you to it. + */ + You("release %s.", mon_nam(u.ustuck)); + u.ustuck = 0; + } else { + /* If holder is asleep or paralyzed: + * 37.5% chance of getting away, + * 12.5% chance of waking/releasing it; + * otherwise: + * 7.5% chance of getting away. + * [strength ought to be a factor] + * If holder is tame and there is no conflict, + * guaranteed escape. + */ + switch (rn2(!u.ustuck->mcanmove ? 8 : 40)) { + case 0: + case 1: + case 2: + pull_free: + You("pull free from %s.", mon_nam(u.ustuck)); + u.ustuck = 0; + break; + case 3: + if (!u.ustuck->mcanmove) { + /* it's free to move on next turn */ + u.ustuck->mfrozen = 1; + u.ustuck->msleeping = 0; + } /*FALLTHRU*/ - default: - if (u.ustuck->mtame && - !Conflict && !u.ustuck->mconf) - goto pull_free; - You("cannot escape from %s!", mon_nam(u.ustuck)); - nomul(0); - return; - } + default: + if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) + goto pull_free; + You("cannot escape from %s!", mon_nam(u.ustuck)); + nomul(0); + return; + } } } - mtmp = m_at(x,y); + mtmp = m_at(x, y); if (mtmp) { /* Don't attack if you're running, and can see it */ /* We should never get here if forcefight */ - if (context.run && - ((!Blind && mon_visible(mtmp) && - ((mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT) || - Protection_from_shape_changers)) || - sensemon(mtmp))) { + if (context.run && ((!Blind && mon_visible(mtmp) + && ((mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT) + || Protection_from_shape_changers)) + || sensemon(mtmp))) { nomul(0); context.move = 0; return; @@ -1309,7 +1373,7 @@ domove() tmpr = &levl[x][y]; /* attack monster */ - if(mtmp) { + if (mtmp) { nomul(0); /* only attack if we know it's there */ /* or if we used the 'F' command to fight blindly */ @@ -1324,24 +1388,26 @@ domove() * if the monster is unseen and the player doesn't remember an * invisible monster--then, we fall through to attack() and * attack_check(), which still wastes a turn, but prints a - * different message and makes the player remember the monster. */ - if(context.nopick && - (canspotmon(mtmp) || glyph_is_invisible(levl[x][y].glyph))){ - if(mtmp->m_ap_type && !Protection_from_shape_changers - && !sensemon(mtmp)) - stumble_onto_mimic(mtmp); - else if (mtmp->mpeaceful && !Hallucination) - pline("Pardon me, %s.", m_monnam(mtmp)); - else - You("move right into %s.", mon_nam(mtmp)); - return; + * different message and makes the player remember the monster. + */ + if (context.nopick + && (canspotmon(mtmp) || glyph_is_invisible(levl[x][y].glyph))) { + if (mtmp->m_ap_type && !Protection_from_shape_changers + && !sensemon(mtmp)) + stumble_onto_mimic(mtmp); + else if (mtmp->mpeaceful && !Hallucination) + pline("Pardon me, %s.", m_monnam(mtmp)); + else + You("move right into %s.", mon_nam(mtmp)); + return; } - if(context.forcefight || !mtmp->mundetected || sensemon(mtmp) || - ((hides_under(mtmp->data) || mtmp->data->mlet == S_EEL) && - !is_safepet(mtmp))){ - /* try to attack; note that it might evade */ - /* also, we don't attack tame when _safepet_ */ - if(attack(mtmp)) return; + if (context.forcefight || !mtmp->mundetected || sensemon(mtmp) + || ((hides_under(mtmp->data) || mtmp->data->mlet == S_EEL) + && !is_safepet(mtmp))) { + /* try to attack; note that it might evade */ + /* also, we don't attack tame when _safepet_ */ + if (attack(mtmp)) + return; } } @@ -1351,69 +1417,71 @@ domove() (glyph_is_invisible(levl[x][y].glyph) && !context.nopick)) { struct obj *boulder = 0; boolean explo = (Upolyd && attacktype(youmonst.data, AT_EXPL)), - solid = !accessible(x, y); - int glyph = glyph_at(x, y); /* might be monster */ + solid = !accessible(x, y); + int glyph = glyph_at(x, y); /* might be monster */ char buf[BUFSZ]; - if (!Underwater) { - boulder = sobj_at(BOULDER, x, y); - /* if a statue is displayed at the target location, - player is attempting to attack it [and boulder - handlng below is suitable for handling that] */ - if (glyph_is_statue(glyph) || - (Hallucination && glyph_is_monster(glyph))) - boulder = sobj_at(STATUE, x, y); + if (!Underwater) { + boulder = sobj_at(BOULDER, x, y); + /* if a statue is displayed at the target location, + player is attempting to attack it [and boulder + handlng below is suitable for handling that] */ + if (glyph_is_statue(glyph) + || (Hallucination && glyph_is_monster(glyph))) + boulder = sobj_at(STATUE, x, y); - /* force fight at boulder/statue or wall/door while wielding - pick: start digging to break the boulder or wall */ - if (context.forcefight && - /* can we dig? */ - uwep && dig_typ(uwep, x, y) && - /* should we dig? */ - !glyph_is_invisible(glyph) && - !glyph_is_monster(glyph)) { - (void)use_pick_axe2(uwep); - return; - } - } + /* force fight at boulder/statue or wall/door while wielding + pick: start digging to break the boulder or wall */ + if (context.forcefight && + /* can we dig? */ + uwep && dig_typ(uwep, x, y) && + /* should we dig? */ + !glyph_is_invisible(glyph) && !glyph_is_monster(glyph)) { + (void) use_pick_axe2(uwep); + return; + } + } - /* about to become known empty -- remove 'I' if present */ + /* about to become known empty -- remove 'I' if present */ unmap_object(x, y); - if (boulder) map_object(boulder, TRUE); + if (boulder) + map_object(boulder, TRUE); newsym(x, y); - glyph = glyph_at(x, y); /* might have just changed */ + glyph = glyph_at(x, y); /* might have just changed */ if (boulder) Strcpy(buf, ansimpleoname(boulder)); else if (Underwater && !is_pool(x, y)) /* Underwater, targetting non-water; the map just shows blank - because you don't see remembered terrain while underwater; - although the hero can attack an adjacent monster this way, - assume he can't reach out far enough to distinguish terrain */ - Sprintf(buf, (Is_waterlevel(&u.uz) && levl[x][y].typ == AIR) ? - "an air bubble" : "nothing"); + because you don't see remembered terrain while underwater; + although the hero can attack an adjacent monster this way, + assume he can't reach out far enough to distinguish terrain */ + Sprintf(buf, (Is_waterlevel(&u.uz) && levl[x][y].typ == AIR) + ? "an air bubble" + : "nothing"); else if (solid) - /* glyph might indicate unseen terrain if hero is blind; - unlike searching, this won't reveal what that terrain is - (except for solid rock, where the glyph would otherwise - yield ludicrous "dark part of a room") */ - Strcpy(buf, (levl[x][y].typ == STONE) ? "solid rock" : - glyph_is_cmap(glyph) ? - the(defsyms[glyph_to_cmap(glyph)].explanation) : - (const char *)"an unknown obstacle"); - /* note: 'solid' is misleadingly named and catches pools - of water and lava as well as rock and walls */ + /* glyph might indicate unseen terrain if hero is blind; + unlike searching, this won't reveal what that terrain is + (except for solid rock, where the glyph would otherwise + yield ludicrous "dark part of a room") */ + Strcpy(buf, + (levl[x][y].typ == STONE) + ? "solid rock" + : glyph_is_cmap(glyph) + ? the(defsyms[glyph_to_cmap(glyph)].explanation) + : (const char *) "an unknown obstacle"); + /* note: 'solid' is misleadingly named and catches pools + of water and lava as well as rock and walls */ else - Strcpy(buf, "thin air"); + Strcpy(buf, "thin air"); You("%s%s %s.", !(boulder || solid) ? "" : !explo ? "harmlessly " : "futilely ", - explo ? "explode at" : "attack", - buf); + explo ? "explode at" : "attack", buf); nomul(0); if (explo) { wake_nearby(); - u.mh = -1; /* dead in the current form */ + u.mh = -1; /* dead in the current form */ rehumanize(); } return; @@ -1428,28 +1496,30 @@ domove() return; } - if (u_rooted()) return; + if (u_rooted()) + return; - if(u.utrap) { - if (!trapmove(x, y, trap)) return; + if (u.utrap) { + if (!trapmove(x, y, trap)) + return; } - if (!test_move(u.ux, u.uy, x-u.ux, y-u.uy, DO_MOVE)) { - if (!context.door_opened) { - context.move = 0; - nomul(0); - } - return; + if (!test_move(u.ux, u.uy, x - u.ux, y - u.uy, DO_MOVE)) { + if (!context.door_opened) { + context.move = 0; + nomul(0); + } + return; } /* Move ball and chain. */ if (Punished) - if (!drag_ball(x,y, &bc_control, &ballx, &bally, &chainx, &chainy, - &cause_delay, TRUE)) - return; + if (!drag_ball(x, y, &bc_control, &ballx, &bally, &chainx, &chainy, + &cause_delay, TRUE)) + return; /* Check regions entering/leaving */ - if (!in_out_region(x,y)) + if (!in_out_region(x, y)) return; /* now move the hero */ @@ -1479,106 +1549,106 @@ domove() if (is_safepet(mtmp) && !(is_hider(mtmp->data) && mtmp->mundetected)) { /* if trapped, there's a chance the pet goes wild */ if (mtmp->mtrapped) { - if (!rn2(mtmp->mtame)) { - mtmp->mtame = mtmp->mpeaceful = mtmp->msleeping = 0; - if (mtmp->mleashed) m_unleash(mtmp, TRUE); - growl(mtmp); - } else { - yelp(mtmp); - } + if (!rn2(mtmp->mtame)) { + mtmp->mtame = mtmp->mpeaceful = mtmp->msleeping = 0; + if (mtmp->mleashed) + m_unleash(mtmp, TRUE); + growl(mtmp); + } else { + yelp(mtmp); + } } mtmp->mundetected = 0; - if (mtmp->m_ap_type) seemimic(mtmp); - else if (!mtmp->mtame) newsym(mtmp->mx, mtmp->my); + if (mtmp->m_ap_type) + seemimic(mtmp); + else if (!mtmp->mtame) + newsym(mtmp->mx, mtmp->my); - if (mtmp->mtrapped && - (trap = t_at(mtmp->mx, mtmp->my)) != 0 && - (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) && - sobj_at(BOULDER, trap->tx, trap->ty)) { - /* can't swap places with pet pinned in a pit by a boulder */ - u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ + if (mtmp->mtrapped && (trap = t_at(mtmp->mx, mtmp->my)) != 0 + && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) + && sobj_at(BOULDER, trap->tx, trap->ty)) { + /* can't swap places with pet pinned in a pit by a boulder */ + u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ } else if (u.ux0 != x && u.uy0 != y && NODIAG(mtmp->data - mons)) { - /* can't swap places when pet can't move to your spot */ - u.ux = u.ux0, u.uy = u.uy0; - You("stop. %s can't move diagonally.", - upstart(y_monnam(mtmp))); - } else if (u.ux0 != x && u.uy0 != y && - bad_rock(mtmp->data, x, u.uy0) && - bad_rock(mtmp->data, u.ux0, y) && - (bigmonst(mtmp->data) || (curr_mon_load(mtmp) > 600))) { - /* can't swap places when pet won't fit thru the opening */ - u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ - You("stop. %s won't fit through.", upstart(y_monnam(mtmp))); + /* can't swap places when pet can't move to your spot */ + u.ux = u.ux0, u.uy = u.uy0; + You("stop. %s can't move diagonally.", upstart(y_monnam(mtmp))); + } else if (u.ux0 != x && u.uy0 != y && bad_rock(mtmp->data, x, u.uy0) + && bad_rock(mtmp->data, u.ux0, y) + && (bigmonst(mtmp->data) || (curr_mon_load(mtmp) > 600))) { + /* can't swap places when pet won't fit thru the opening */ + u.ux = u.ux0, u.uy = u.uy0; /* didn't move after all */ + You("stop. %s won't fit through.", upstart(y_monnam(mtmp))); } else { - char pnambuf[BUFSZ]; + char pnambuf[BUFSZ]; - /* save its current description in case of polymorph */ - Strcpy(pnambuf, y_monnam(mtmp)); - mtmp->mtrapped = 0; - remove_monster(x, y); - place_monster(mtmp, u.ux0, u.uy0); - newsym(x, y); - newsym(u.ux0, u.uy0); + /* save its current description in case of polymorph */ + Strcpy(pnambuf, y_monnam(mtmp)); + mtmp->mtrapped = 0; + remove_monster(x, y); + place_monster(mtmp, u.ux0, u.uy0); + newsym(x, y); + newsym(u.ux0, u.uy0); - You("%s %s.", mtmp->mtame ? "swap places with" : "frighten", - pnambuf); + You("%s %s.", mtmp->mtame ? "swap places with" : "frighten", + pnambuf); - /* check for displacing it into pools and traps */ - switch (minliquid(mtmp) ? 2 : mintrap(mtmp)) { - case 0: - break; - case 1: /* trapped */ - case 3: /* changed levels */ - /* there's already been a trap message, reinforce it */ - abuse_dog(mtmp); - adjalign(-3); - break; - case 2: - /* drowned or died... - * you killed your pet by direct action, so get experience - * and possibly penalties; - * we want the level gain message, if it happens, to occur - * before the guilt message below - */ - { - /* minliquid() and mintrap() call mondead() rather than - killed() so we duplicate some of the latter here */ - int tmp, mndx; + /* check for displacing it into pools and traps */ + switch (minliquid(mtmp) ? 2 : mintrap(mtmp)) { + case 0: + break; + case 1: /* trapped */ + case 3: /* changed levels */ + /* there's already been a trap message, reinforce it */ + abuse_dog(mtmp); + adjalign(-3); + break; + case 2: + /* drowned or died... + * you killed your pet by direct action, so get experience + * and possibly penalties; + * we want the level gain message, if it happens, to occur + * before the guilt message below + */ + { + /* minliquid() and mintrap() call mondead() rather than + killed() so we duplicate some of the latter here */ + int tmp, mndx; - u.uconduct.killer++; - mndx = monsndx(mtmp->data); - tmp = experience(mtmp, (int)mvitals[mndx].died); - more_experienced(tmp, 0); - newexplevel(); /* will decide if you go up */ - } - /* That's no way to treat a pet! Your god gets angry. - * - * [This has always been pretty iffy. Why does your - * patron deity care at all, let alone enough to get mad?] - */ - if (rn2(4)) { - You_feel("guilty about losing your pet like this."); - u.ugangr++; - adjalign(-15); + u.uconduct.killer++; + mndx = monsndx(mtmp->data); + tmp = experience(mtmp, (int) mvitals[mndx].died); + more_experienced(tmp, 0); + newexplevel(); /* will decide if you go up */ + } + /* That's no way to treat a pet! Your god gets angry. + * + * [This has always been pretty iffy. Why does your + * patron deity care at all, let alone enough to get mad?] + */ + if (rn2(4)) { + You_feel("guilty about losing your pet like this."); + u.ugangr++; + adjalign(-15); + } + break; + default: + pline("that's strange, unknown mintrap result!"); + break; } - break; - default: - pline("that's strange, unknown mintrap result!"); - break; - } } } reset_occupations(); if (context.run) { - if ( context.run < 8 ) - if (IS_DOOR(tmpr->typ) || IS_ROCK(tmpr->typ) || - IS_FURNITURE(tmpr->typ)) - nomul(0); + if (context.run < 8) + if (IS_DOOR(tmpr->typ) || IS_ROCK(tmpr->typ) + || IS_FURNITURE(tmpr->typ)) + nomul(0); } - if (hides_under(youmonst.data) || (youmonst.data->mlet == S_EEL) || - u.dx || u.dy) + if (hides_under(youmonst.data) || (youmonst.data->mlet == S_EEL) || u.dx + || u.dy) (void) hideunder(&youmonst); /* @@ -1587,22 +1657,22 @@ domove() * to non-moving monsters... */ if ((u.dx || u.dy) && (youmonst.m_ap_type == M_AP_OBJECT - || youmonst.m_ap_type == M_AP_FURNITURE)) + || youmonst.m_ap_type == M_AP_FURNITURE)) youmonst.m_ap_type = M_AP_NOTHING; - check_leash(u.ux0,u.uy0); + check_leash(u.ux0, u.uy0); - if(u.ux0 != u.ux || u.uy0 != u.uy) { + if (u.ux0 != u.ux || u.uy0 != u.uy) { u.umoved = TRUE; /* Clean old position -- vision_recalc() will print our new one. */ - newsym(u.ux0,u.uy0); + newsym(u.ux0, u.uy0); /* Since the hero has moved, adjust what can be seen/unseen. */ - vision_recalc(1); /* Do the work now in the recover time. */ + vision_recalc(1); /* Do the work now in the recover time. */ invocation_message(); } - if (Punished) /* put back ball and chain */ - move_bc(0,bc_control,ballx,bally,chainx,chainy); + if (Punished) /* put back ball and chain */ + move_bc(0, bc_control, ballx, bally, chainx, chainy); spoteffects(TRUE); @@ -1610,22 +1680,23 @@ domove() /* must come after we finished picking up, in spoteffects() */ if (cause_delay) { nomul(-2); - multi_reason = "dragging an iron ball"; + multi_reason = "dragging an iron ball"; nomovemsg = ""; } if (context.run && flags.runmode != RUN_TPORT) { /* display every step or every 7th step depending upon mode */ if (flags.runmode != RUN_LEAP || !(moves % 7L)) { - if (flags.time) context.botl = 1; - curs_on_u(); - delay_output(); - if (flags.runmode == RUN_CRAWL) { + if (flags.time) + context.botl = 1; + curs_on_u(); delay_output(); - delay_output(); - delay_output(); - delay_output(); - } + if (flags.runmode == RUN_CRAWL) { + delay_output(); + delay_output(); + delay_output(); + delay_output(); + } } } } @@ -1639,37 +1710,40 @@ overexertion() execute if you decline to attack a peaceful monster */ gethungry(); if ((moves % 3L) != 0L && near_capacity() >= HVY_ENCUMBER) { - int *hp = (!Upolyd ? &u.uhp : &u.mh); + int *hp = (!Upolyd ? &u.uhp : &u.mh); - if (*hp > 1) { - *hp -= 1; - } else { - You("pass out from exertion!"); - exercise(A_CON, FALSE); - fall_asleep(-10, FALSE); + if (*hp > 1) { + *hp -= 1; + } else { + You("pass out from exertion!"); + exercise(A_CON, FALSE); + fall_asleep(-10, FALSE); + } } - } - return (multi < 0); /* might have fainted (actually gone to sleep) */ + return (multi < 0); /* might have fainted (actually gone to sleep) */ } void invocation_message() { /* a special clue-msg when on the Invocation position */ - if(invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) { + if (invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) { char buf[BUFSZ]; struct obj *otmp = carrying(CANDELABRUM_OF_INVOCATION); - nomul(0); /* stop running or travelling */ - if (u.usteed) Sprintf(buf, "beneath %s", y_monnam(u.usteed)); - else if (Levitation || Flying) Strcpy(buf, "beneath you"); - else Sprintf(buf, "under your %s", makeplural(body_part(FOOT))); + nomul(0); /* stop running or travelling */ + if (u.usteed) + Sprintf(buf, "beneath %s", y_monnam(u.usteed)); + else if (Levitation || Flying) + Strcpy(buf, "beneath you"); + else + Sprintf(buf, "under your %s", makeplural(body_part(FOOT))); You_feel("a strange vibration %s.", buf); u.uevent.uvibrated = 1; if (otmp && otmp->spe == 7 && otmp->lamplit) - pline("%s %s!", The(xname(otmp)), - Blind ? "throbs palpably" : "glows with a strange light"); + pline("%s %s!", The(xname(otmp)), + Blind ? "throbs palpably" : "glows with a strange light"); } } @@ -1680,100 +1754,108 @@ STATIC_OVL void switch_terrain() { struct rm *lev = &levl[u.ux][u.uy]; - boolean blocklev = (IS_ROCK(lev->typ) || closed_door(u.ux, u.uy) || - (Is_waterlevel(&u.uz) && lev->typ == WATER)); + boolean blocklev = (IS_ROCK(lev->typ) || closed_door(u.ux, u.uy) + || (Is_waterlevel(&u.uz) && lev->typ == WATER)); if (blocklev) { - /* called from spoteffects(), skip float_down() */ - if (Levitation) You_cant("levitate in here."); - BLevitation |= FROMOUTSIDE; + /* called from spoteffects(), skip float_down() */ + if (Levitation) + You_cant("levitate in here."); + BLevitation |= FROMOUTSIDE; } else if (BLevitation) { - BLevitation &= ~FROMOUTSIDE; - if (Levitation) float_up(); + BLevitation &= ~FROMOUTSIDE; + if (Levitation) + float_up(); } /* the same terrain that blocks levitation also blocks flight */ if (blocklev) { - if (Flying) You_cant("fly in here."); - BFlying |= FROMOUTSIDE; + if (Flying) + You_cant("fly in here."); + BFlying |= FROMOUTSIDE; } else if (BFlying) { - BFlying &= ~FROMOUTSIDE; - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ - /* [minor bug: we don't know whether this is beginning flight or - resuming it; that could be tracked so that this message could - be adjusted to "resume flying", but isn't worth the effort...] */ - if (Flying) You("start flying."); + BFlying &= ~FROMOUTSIDE; + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + /* [minor bug: we don't know whether this is beginning flight or + resuming it; that could be tracked so that this message could + be adjusted to "resume flying", but isn't worth the effort...] */ + if (Flying) + You("start flying."); } } /* extracted from spoteffects; called by spoteffects to check for entering or - leaving a pool of water/lava, and by moveloop to check for staying on one */ -boolean -pooleffects(newspot) /* returns true to skip rest of spoteffects */ -boolean newspot; /* true if called by spoteffects */ + leaving a pool of water/lava, and by moveloop to check for staying on one + */ +boolean pooleffects(newspot) /* returns true to skip rest of spoteffects */ +boolean newspot; /* true if called by spoteffects */ { /* check for leaving water */ if (u.uinwater) { - boolean still_inwater = FALSE; /* assume we're getting out */ + boolean still_inwater = FALSE; /* assume we're getting out */ - if (!is_pool(u.ux,u.uy)) { - if (Is_waterlevel(&u.uz)) - You("pop into an air bubble."); - else if (is_lava(u.ux, u.uy)) - You("leave the water..."); /* oops! */ - else - You("are on solid %s again.", - is_ice(u.ux, u.uy) ? "ice" : "land"); - } else if (Is_waterlevel(&u.uz)) { - still_inwater = TRUE; - } else if (Levitation) { - You("pop out of the water like a cork!"); - } else if (Flying) { - You("fly out of the water."); - } else if (Wwalking) { - You("slowly rise above the surface."); - } else { - still_inwater = TRUE; - } - if (!still_inwater) { - boolean was_underwater = (Underwater && !Is_waterlevel(&u.uz)); - - u.uinwater = 0; /* leave the water */ - if (was_underwater) { /* restore vision */ - docrt(); - vision_full_recalc = 1; + if (!is_pool(u.ux, u.uy)) { + if (Is_waterlevel(&u.uz)) + You("pop into an air bubble."); + else if (is_lava(u.ux, u.uy)) + You("leave the water..."); /* oops! */ + else + You("are on solid %s again.", + is_ice(u.ux, u.uy) ? "ice" : "land"); + } else if (Is_waterlevel(&u.uz)) { + still_inwater = TRUE; + } else if (Levitation) { + You("pop out of the water like a cork!"); + } else if (Flying) { + You("fly out of the water."); + } else if (Wwalking) { + You("slowly rise above the surface."); + } else { + still_inwater = TRUE; + } + if (!still_inwater) { + boolean was_underwater = (Underwater && !Is_waterlevel(&u.uz)); + + u.uinwater = 0; /* leave the water */ + if (was_underwater) { /* restore vision */ + docrt(); + vision_full_recalc = 1; + } } - } } /* check for entering water or lava */ - if (!u.ustuck && !Levitation && !Flying && - is_pool_or_lava(u.ux, u.uy)) { - if (u.usteed && (is_flyer(u.usteed->data) || - is_floater(u.usteed->data) || is_clinger(u.usteed->data))) { - /* floating or clinging steed keeps hero safe (is_flyer() test - is redundant; it can't be true since Flying yielded false) */ - return FALSE; - } else if (u.usteed) { - /* steed enters pool */ - dismount_steed(Underwater ? DISMOUNT_FELL : DISMOUNT_GENERIC); - /* dismount_steed() -> float_down() -> pickup() - (float_down doesn't do autopickup on Air or Water) */ - if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) return FALSE; - /* even if we actually end up at same location, float_down() - has already done spoteffect()'s trap and pickup actions */ - if (newspot) check_special_room(FALSE); /* spoteffects */ - return TRUE; - } - /* not mounted */ + if (!u.ustuck && !Levitation && !Flying && is_pool_or_lava(u.ux, u.uy)) { + if (u.usteed + && (is_flyer(u.usteed->data) || is_floater(u.usteed->data) + || is_clinger(u.usteed->data))) { + /* floating or clinging steed keeps hero safe (is_flyer() test + is redundant; it can't be true since Flying yielded false) */ + return FALSE; + } else if (u.usteed) { + /* steed enters pool */ + dismount_steed(Underwater ? DISMOUNT_FELL : DISMOUNT_GENERIC); + /* dismount_steed() -> float_down() -> pickup() + (float_down doesn't do autopickup on Air or Water) */ + if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) + return FALSE; + /* even if we actually end up at same location, float_down() + has already done spoteffect()'s trap and pickup actions */ + if (newspot) + check_special_room(FALSE); /* spoteffects */ + return TRUE; + } + /* not mounted */ - /* drown(),lava_effects() return true if hero changes - location while surviving the problem */ - if (is_lava(u.ux, u.uy)) { - if (lava_effects()) return TRUE; - } else if (!Wwalking && - (newspot || !u.uinwater || !(Swimming || Amphibious))) { - if (drown()) return TRUE; - } + /* drown(),lava_effects() return true if hero changes + location while surviving the problem */ + if (is_lava(u.ux, u.uy)) { + if (lava_effects()) + return TRUE; + } else if (!Wwalking + && (newspot || !u.uinwater || !(Swimming || Amphibious))) { + if (drown()) + return TRUE; + } } return FALSE; } @@ -1785,7 +1867,7 @@ boolean pick; static int inspoteffects = 0; static coord spotloc; static int spotterrain; - static struct trap *spottrap = (struct trap *)0; + static struct trap *spottrap = (struct trap *) 0; static unsigned spottraptyp = NO_TRAP; struct trap *trap = t_at(u.ux, u.uy); register struct monst *mtmp; @@ -1808,10 +1890,11 @@ boolean pick; if (spotterrain != levl[u.ux0][u.uy0].typ || !on_level(&u.uz, &u.uz0)) switch_terrain(); - if (pooleffects(TRUE)) goto spotdone; + if (pooleffects(TRUE)) + goto spotdone; check_special_room(FALSE); - if(IS_SINK(levl[u.ux][u.uy].typ) && Levitation) + if (IS_SINK(levl[u.ux][u.uy].typ) && Levitation) dosinkfall(); if (!in_steed_dismounting) { /* if dismounting, we'll check again later */ boolean pit; @@ -1820,101 +1903,101 @@ boolean pick; turn, allowing it to do so could give the perception that a trap here is being triggered twice, so adjust the timeout to prevent that */ - if (trap && (HLevitation & TIMEOUT) == 1L && - !ELevitation && !(HLevitation & ~TIMEOUT)) { - if (rn2(2)) { /* defer timeout */ - incr_itimeout(&HLevitation, 1L); - } else { /* timeout early */ - if (float_down(I_SPECIAL|TIMEOUT, 0L)) { - /* levitation has ended; we've already triggered - any trap and [usually] performed autopickup */ - trap = 0; - pick = FALSE; - } + if (trap && (HLevitation & TIMEOUT) == 1L && !ELevitation + && !(HLevitation & ~TIMEOUT)) { + if (rn2(2)) { /* defer timeout */ + incr_itimeout(&HLevitation, 1L); + } else { /* timeout early */ + if (float_down(I_SPECIAL | TIMEOUT, 0L)) { + /* levitation has ended; we've already triggered + any trap and [usually] performed autopickup */ + trap = 0; + pick = FALSE; + } } } - /* - * If not a pit, pickup before triggering trap. - * If pit, trigger trap before pickup. - */ + /* + * If not a pit, pickup before triggering trap. + * If pit, trigger trap before pickup. + */ pit = (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)); - if (pick && !pit) (void) pickup(1); + if (pick && !pit) + (void) pickup(1); if (trap) { - - /* - * dotrap on a fire trap calls melt_ice() which triggers - * spoteffects() (again) which can trigger the same fire - * trap (again). Use static spottrap to prevent that. - * We track spottraptyp because some traps morph - * (landmine to pit) and any new trap type - * should get triggered. - */ + /* + * dotrap on a fire trap calls melt_ice() which triggers + * spoteffects() (again) which can trigger the same fire + * trap (again). Use static spottrap to prevent that. + * We track spottraptyp because some traps morph + * (landmine to pit) and any new trap type + * should get triggered. + */ if (!spottrap || spottraptyp != trap->ttyp) { spottrap = trap; spottraptyp = trap->ttyp; - dotrap(trap, 0); /* fall into arrow trap, etc. */ - spottrap = (struct trap *)0; + dotrap(trap, 0); /* fall into arrow trap, etc. */ + spottrap = (struct trap *) 0; spottraptyp = NO_TRAP; } } - if (pick && pit) (void) pickup(1); + if (pick && pit) + (void) pickup(1); } /* Warning alerts you to ice danger */ - if (Warning && is_ice(u.ux,u.uy)) { - static const char * const icewarnings[] = { + if (Warning && is_ice(u.ux, u.uy)) { + static const char *const icewarnings[] = { "The ice seems very soft and slushy.", "You feel the ice shift beneath you!", - "The ice, is gonna BREAK!", /* The Dead Zone */ + "The ice, is gonna BREAK!", /* The Dead Zone */ }; long time_left = spot_time_left(u.ux, u.uy, MELT_ICE_AWAY); if (time_left && time_left < 15L) - pline1( - (time_left < 5L) ? icewarnings[2] : - (time_left < 10L) ? icewarnings[1] : icewarnings[0]); + pline1((time_left < 5L) ? icewarnings[2] : (time_left < 10L) + ? icewarnings[1] + : icewarnings[0]); } - if((mtmp = m_at(u.ux, u.uy)) && !u.uswallow) { + if ((mtmp = m_at(u.ux, u.uy)) && !u.uswallow) { mtmp->mundetected = mtmp->msleeping = 0; - switch(mtmp->data->mlet) { - case S_PIERCER: - pline("%s suddenly drops from the %s!", - Amonnam(mtmp), ceiling(u.ux,u.uy)); - if(mtmp->mtame) /* jumps to greet you, not attack */ + switch (mtmp->data->mlet) { + case S_PIERCER: + pline("%s suddenly drops from the %s!", Amonnam(mtmp), + ceiling(u.ux, u.uy)); + if (mtmp->mtame) /* jumps to greet you, not attack */ ; - else if(uarmh && is_metallic(uarmh)) + else if (uarmh && is_metallic(uarmh)) pline("Its blow glances off your %s.", - helm_simple_name(uarmh)); + helm_simple_name(uarmh)); else if (u.uac + 3 <= rnd(20)) You("are almost hit by %s!", - x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE)); + x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE)); else { int dmg; You("are hit by %s!", - x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE)); - dmg = d(4,6); - if(Half_physical_damage) dmg = (dmg+1) / 2; + x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE)); + dmg = d(4, 6); + if (Half_physical_damage) + dmg = (dmg + 1) / 2; mdamageu(mtmp, dmg); } break; - default: /* monster surprises you. */ - if(mtmp->mtame) - pline("%s jumps near you from the %s.", - Amonnam(mtmp), ceiling(u.ux,u.uy)); - else if(mtmp->mpeaceful) { + default: /* monster surprises you. */ + if (mtmp->mtame) + pline("%s jumps near you from the %s.", Amonnam(mtmp), + ceiling(u.ux, u.uy)); + else if (mtmp->mpeaceful) { You("surprise %s!", - Blind && !sensemon(mtmp) ? - something : a_monnam(mtmp)); + Blind && !sensemon(mtmp) ? something : a_monnam(mtmp)); mtmp->mpeaceful = 0; } else - pline("%s attacks you by surprise!", - Amonnam(mtmp)); + pline("%s attacks you by surprise!", Amonnam(mtmp)); break; } mnexto(mtmp); /* have to move the monster */ } - spotdone: +spotdone: if (!--inspoteffects) { - spotterrain = STONE; /* 0 */ + spotterrain = STONE; /* 0 */ spotloc.x = spotloc.y = 0; } return; @@ -1922,19 +2005,20 @@ boolean pick; /* returns first matching monster */ STATIC_OVL struct monst * -monstinroom(mdat,roomno) +monstinroom(mdat, roomno) struct permonst *mdat; int roomno; { register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->data == mdat && - index(in_rooms(mtmp->mx, mtmp->my, 0), roomno + ROOMOFFSET)) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->data == mdat + && index(in_rooms(mtmp->mx, mtmp->my, 0), roomno + ROOMOFFSET)) return mtmp; } - return (struct monst *)0; + return (struct monst *) 0; } char * @@ -1947,31 +2031,31 @@ register int typewanted; int typefound, min_x, min_y, max_x, max_y_offset, step; register struct rm *lev; -#define goodtype(rno) (!typewanted || \ - ((typefound = rooms[rno - ROOMOFFSET].rtype) == typewanted) || \ - ((typewanted == SHOPBASE) && (typefound > SHOPBASE))) \ +#define goodtype(rno) \ + (!typewanted \ + || ((typefound = rooms[rno - ROOMOFFSET].rtype) == typewanted) \ + || ((typewanted == SHOPBASE) && (typefound > SHOPBASE))) switch (rno = levl[x][y].roomno) { - case NO_ROOM: - return(ptr); - case SHARED: - step = 2; - break; - case SHARED_PLUS: - step = 1; - break; - default: /* i.e. a regular room # */ - if (goodtype(rno)) - *(--ptr) = rno; - return(ptr); + case NO_ROOM: + return (ptr); + case SHARED: + step = 2; + break; + case SHARED_PLUS: + step = 1; + break; + default: /* i.e. a regular room # */ + if (goodtype(rno)) + *(--ptr) = rno; + return (ptr); } min_x = x - 1; max_x = x + 1; if (x < 1) min_x += step; - else - if (x >= COLNO) + else if (x >= COLNO) max_x -= step; min_y = y - 1; @@ -1979,30 +2063,29 @@ register int typewanted; if (min_y < 0) { min_y += step; max_y_offset -= step; - } else - if ((min_y + max_y_offset) >= ROWNO) + } else if ((min_y + max_y_offset) >= ROWNO) max_y_offset -= step; for (x = min_x; x <= max_x; x += step) { lev = &levl[x][min_y]; y = 0; - if (((rno = lev[y].roomno) >= ROOMOFFSET) && - !index(ptr, rno) && goodtype(rno)) + if (((rno = lev[y].roomno) >= ROOMOFFSET) && !index(ptr, rno) + && goodtype(rno)) *(--ptr) = rno; y += step; if (y > max_y_offset) continue; - if (((rno = lev[y].roomno) >= ROOMOFFSET) && - !index(ptr, rno) && goodtype(rno)) + if (((rno = lev[y].roomno) >= ROOMOFFSET) && !index(ptr, rno) + && goodtype(rno)) *(--ptr) = rno; y += step; if (y > max_y_offset) continue; - if (((rno = lev[y].roomno) >= ROOMOFFSET) && - !index(ptr, rno) && goodtype(rno)) + if (((rno = lev[y].roomno) >= ROOMOFFSET) && !index(ptr, rno) + && goodtype(rno)) *(--ptr) = rno; } - return(ptr); + return (ptr); } /* is (x,y) in a town? */ @@ -2014,7 +2097,8 @@ register int x, y; register struct mkroom *sroom; boolean has_subrooms = FALSE; - if (!slev || !slev->flags.town) return FALSE; + if (!slev || !slev->flags.town) + return FALSE; /* * See if (x,y) is in a room with subrooms, if so, assume it's the @@ -2022,8 +2106,9 @@ register int x, y; */ for (sroom = &rooms[0]; sroom->hx > 0; sroom++) { if (sroom->nsubrooms > 0) { - has_subrooms = TRUE; - if (inside_room(sroom, x, y)) return TRUE; + has_subrooms = TRUE; + if (inside_room(sroom, x, y)) + return TRUE; } } @@ -2048,10 +2133,8 @@ register boolean newlev; } Strcpy(u.urooms, in_rooms(u.ux, u.uy, 0)); - for (ptr1 = &u.urooms[0], - ptr2 = &u.uentered[0], - ptr3 = &u.ushops[0], - ptr4 = &u.ushops_entered[0]; + for (ptr1 = &u.urooms[0], ptr2 = &u.uentered[0], ptr3 = &u.ushops[0], + ptr4 = &u.ushops_entered[0]; *ptr1; ptr1++) { if (!index(u.urooms0, *ptr1)) *(ptr2++) = *ptr1; @@ -2084,16 +2167,15 @@ register boolean newlev; if (*u.ushops0) u_left_shop(u.ushops_left, newlev); - if (!*u.uentered && !*u.ushops_entered) /* implied by newlev */ - return; /* no entrance messages necessary */ + if (!*u.uentered && !*u.ushops_entered) /* implied by newlev */ + return; /* no entrance messages necessary */ /* Did we just enter a shop? */ if (*u.ushops_entered) u_entered_shop(u.ushops_entered); for (ptr = &u.uentered[0]; *ptr; ptr++) { - int roomno = *ptr - ROOMOFFSET, - rt = rooms[roomno].rtype; + int roomno = *ptr - ROOMOFFSET, rt = rooms[roomno].rtype; boolean msg_given = TRUE; /* Did we just enter some other special room? */ @@ -2105,9 +2187,8 @@ register boolean newlev; pline("Welcome to David's treasure zoo!"); break; case SWAMP: - pline("It %s rather %s down here.", - Blind ? "feels" : "looks", - Blind ? "humid" : "muddy"); + pline("It %s rather %s down here.", Blind ? "feels" : "looks", + Blind ? "humid" : "muddy"); break; case COURT: You("enter an opulent throne room!"); @@ -2116,11 +2197,11 @@ register boolean newlev; You("enter a leprechaun hall!"); break; case MORGUE: - if(midnight()) { - const char *run = locomotion(youmonst.data, "Run"); - pline("%s away! %s away!", run, run); + if (midnight()) { + const char *run = locomotion(youmonst.data, "Run"); + pline("%s away! %s away!", run, run); } else - You("have an uncanny feeling..."); + You("have an uncanny feeling..."); break; case BEEHIVE: You("enter a giant beehive!"); @@ -2132,73 +2213,72 @@ register boolean newlev; You("enter an anthole!"); break; case BARRACKS: - if(monstinroom(&mons[PM_SOLDIER], roomno) || - monstinroom(&mons[PM_SERGEANT], roomno) || - monstinroom(&mons[PM_LIEUTENANT], roomno) || - monstinroom(&mons[PM_CAPTAIN], roomno)) - You("enter a military barracks!"); + if (monstinroom(&mons[PM_SOLDIER], roomno) + || monstinroom(&mons[PM_SERGEANT], roomno) + || monstinroom(&mons[PM_LIEUTENANT], roomno) + || monstinroom(&mons[PM_CAPTAIN], roomno)) + You("enter a military barracks!"); else - You("enter an abandoned barracks."); + You("enter an abandoned barracks."); break; - case DELPHI: - { - struct monst *oracle = monstinroom(&mons[PM_ORACLE], - roomno); + case DELPHI: { + struct monst *oracle = monstinroom(&mons[PM_ORACLE], roomno); if (oracle) { if (!oracle->mpeaceful) - verbalize("You're in Delphi, %s.", - plname); + verbalize("You're in Delphi, %s.", plname); else - verbalize("%s, %s, welcome to Delphi!", - Hello((struct monst *) 0), plname); + verbalize("%s, %s, welcome to Delphi!", + Hello((struct monst *) 0), plname); } else msg_given = FALSE; - break; - } + break; + } case TEMPLE: intemple(roomno + ROOMOFFSET); - /*FALLTHRU*/ + /*FALLTHRU*/ default: msg_given = (rt == TEMPLE); rt = 0; break; } - if (msg_given) room_discovered(roomno); + if (msg_given) + room_discovered(roomno); if (rt != 0) { - rooms[roomno].rtype = OROOM; - if (!search_special(rt)) { - /* No more room of that type */ - switch(rt) { + rooms[roomno].rtype = OROOM; + if (!search_special(rt)) { + /* No more room of that type */ + switch (rt) { case COURT: - level.flags.has_court = 0; - break; + level.flags.has_court = 0; + break; case SWAMP: - level.flags.has_swamp = 0; - break; + level.flags.has_swamp = 0; + break; case MORGUE: - level.flags.has_morgue = 0; - break; + level.flags.has_morgue = 0; + break; case ZOO: - level.flags.has_zoo = 0; - break; + level.flags.has_zoo = 0; + break; case BARRACKS: - level.flags.has_barracks = 0; - break; + level.flags.has_barracks = 0; + break; case TEMPLE: - level.flags.has_temple = 0; - break; + level.flags.has_temple = 0; + break; case BEEHIVE: - level.flags.has_beehive = 0; - break; - } - } - if (rt == COURT || rt == SWAMP || rt == MORGUE || rt == ZOO) - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (!Stealth && !rn2(3)) - mtmp->msleeping = 0; + level.flags.has_beehive = 0; + break; + } } + if (rt == COURT || rt == SWAMP || rt == MORGUE || rt == ZOO) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (!Stealth && !rn2(3)) + mtmp->msleeping = 0; + } } } @@ -2212,68 +2292,67 @@ dopickup() struct trap *traphere = t_at(u.ux, u.uy); /* awful kludge to work around parse()'s pre-decrement */ count = (multi || (save_cm && *save_cm == ',')) ? multi + 1 : 0; - multi = 0; /* always reset */ + multi = 0; /* always reset */ /* uswallow case added by GAN 01/29/87 */ - if(u.uswallow) { + if (u.uswallow) { if (!u.ustuck->minvent) { - if (is_animal(u.ustuck->data)) { - You("pick up %s tongue.", s_suffix(mon_nam(u.ustuck))); - pline("But it's kind of slimy, so you drop it."); - } else - You("don't %s anything in here to pick up.", - Blind ? "feel" : "see"); - return(1); + if (is_animal(u.ustuck->data)) { + You("pick up %s tongue.", s_suffix(mon_nam(u.ustuck))); + pline("But it's kind of slimy, so you drop it."); + } else + You("don't %s anything in here to pick up.", + Blind ? "feel" : "see"); + return (1); } else { int tmpcount = -count; - return loot_mon(u.ustuck, &tmpcount, (boolean *)0); + return loot_mon(u.ustuck, &tmpcount, (boolean *) 0); } } - if(is_pool(u.ux, u.uy)) { + if (is_pool(u.ux, u.uy)) { if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data) || (Flying && !Breathless)) { - You("cannot dive into the water to pick things up."); - return(0); + You("cannot dive into the water to pick things up."); + return (0); } else if (!Underwater) { - You_cant("even see the bottom, let alone pick up %s.", - something); - return(0); + You_cant("even see the bottom, let alone pick up %s.", something); + return (0); } } if (is_lava(u.ux, u.uy)) { - if (Wwalking || is_floater(youmonst.data) || - is_clinger(youmonst.data) || (Flying && !Breathless)) { - You_cant("reach the bottom to pick things up."); - return(0); + if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data) + || (Flying && !Breathless)) { + You_cant("reach the bottom to pick things up."); + return (0); } else if (!likes_lava(youmonst.data)) { - You("would burn to a crisp trying to pick things up."); - return(0); + You("would burn to a crisp trying to pick things up."); + return (0); } } if (!OBJ_AT(u.ux, u.uy)) { - register struct rm *lev = &levl[u.ux][u.uy]; - if (IS_THRONE(lev->typ)) - pline("It must weigh%s a ton!", - lev->looted ? " almost" : ""); - else if (IS_SINK(lev->typ)) - pline_The("plumbing connects it to the floor."); - else if (IS_GRAVE(lev->typ)) - You("don't need a gravestone. Yet."); - else if (IS_FOUNTAIN(lev->typ)) - You("could drink the water..."); - else if (IS_DOOR(lev->typ) && (lev->doormask & D_ISOPEN)) - pline("It won't come off the hinges."); - else There("is nothing here to pick up."); + register struct rm *lev = &levl[u.ux][u.uy]; + if (IS_THRONE(lev->typ)) + pline("It must weigh%s a ton!", lev->looted ? " almost" : ""); + else if (IS_SINK(lev->typ)) + pline_The("plumbing connects it to the floor."); + else if (IS_GRAVE(lev->typ)) + You("don't need a gravestone. Yet."); + else if (IS_FOUNTAIN(lev->typ)) + You("could drink the water..."); + else if (IS_DOOR(lev->typ) && (lev->doormask & D_ISOPEN)) + pline("It won't come off the hinges."); + else + There("is nothing here to pick up."); return 0; } if (!can_reach_floor(TRUE)) { if (traphere && uteetering_at_seen_pit(traphere)) - You("cannot reach the bottom of the pit."); + You("cannot reach the bottom of the pit."); else if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) - rider_cant_reach(); + rider_cant_reach(); else if (Blind && !can_reach_floor(TRUE)) You("cannot reach anything here."); else - You("cannot reach the %s.", surface(u.ux,u.uy)); + You("cannot reach the %s.", surface(u.ux, u.uy)); return 0; } @@ -2294,115 +2373,131 @@ lookaround() /* Grid bugs stop if trying to move diagonal, even if blind. Maybe */ /* they polymorphed while in the middle of a long move. */ if (u.umonnum == PM_GRID_BUG && u.dx && u.dy) { - nomul(0); - return; + nomul(0); + return; } - if(Blind || context.run == 0) return; - for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++) { - if(!isok(x,y)) continue; + if (Blind || context.run == 0) + return; + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (!isok(x, y)) + continue; - if(u.umonnum == PM_GRID_BUG && x != u.ux && y != u.uy) continue; + if (u.umonnum == PM_GRID_BUG && x != u.ux && y != u.uy) + continue; - if(x == u.ux && y == u.uy) continue; + if (x == u.ux && y == u.uy) + continue; - if((mtmp = m_at(x,y)) && - mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT && - (!mtmp->minvis || See_invisible) && !mtmp->mundetected) { - if((context.run != 1 && !mtmp->mtame) - || (x == u.ux+u.dx && y == u.uy+u.dy)) - goto stop; - } - - if (levl[x][y].typ == STONE) continue; - if (x == u.ux-u.dx && y == u.uy-u.dy) continue; - - if (IS_ROCK(levl[x][y].typ) || (levl[x][y].typ == ROOM) || - IS_AIR(levl[x][y].typ)) - continue; - else if (closed_door(x,y) || - (mtmp && mtmp->m_ap_type == M_AP_FURNITURE && - (mtmp->mappearance == S_hcdoor || - mtmp->mappearance == S_vcdoor))) { - if(x != u.ux && y != u.uy) continue; - if(context.run != 1) goto stop; - goto bcorr; - } else if (levl[x][y].typ == CORR) { -bcorr: - if(levl[u.ux][u.uy].typ != ROOM) { - if(context.run == 1 || context.run == 3 || context.run == 8) { - i = dist2(x,y,u.ux+u.dx,u.uy+u.dy); - if(i > 2) continue; - if(corrct == 1 && dist2(x,y,x0,y0) != 1) - noturn = 1; - if(i < i0) { - i0 = i; - x0 = x; - y0 = y; - m0 = mtmp ? 1 : 0; + if ((mtmp = m_at(x, y)) && mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT + && (!mtmp->minvis || See_invisible) && !mtmp->mundetected) { + if ((context.run != 1 && !mtmp->mtame) + || (x == u.ux + u.dx && y == u.uy + u.dy)) + goto stop; } - } - corrct++; - } - continue; - } else if ((trap = t_at(x,y)) && trap->tseen) { - if(context.run == 1) goto bcorr; /* if you must */ - if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop; - continue; - } else if (is_pool_or_lava(x,y)) { - /* water and lava only stop you if directly in front, and stop - * you even if you are running - */ - if(!Levitation && !Flying && !is_clinger(youmonst.data) && - x == u.ux+u.dx && y == u.uy+u.dy) - /* No Wwalking check; otherwise they'd be able - * to test boots by trying to SHIFT-direction - * into a pool and seeing if the game allowed it - */ - goto stop; - continue; - } else { /* e.g. objects or trap or stairs */ - if(context.run == 1) goto bcorr; - if(context.run == 8) continue; - if(mtmp) continue; /* d */ - if(((x == u.ux - u.dx) && (y != u.uy + u.dy)) || - ((y == u.uy - u.dy) && (x != u.ux + u.dx))) - continue; - } -stop: - nomul(0); - return; - } /* end for loops */ - if(corrct > 1 && context.run == 2) goto stop; - if((context.run == 1 || context.run == 3 || context.run == 8) && - !noturn && !m0 && i0 && (corrct == 1 || (corrct == 2 && i0 == 1))) - { - /* make sure that we do not turn too far */ - if(i0 == 2) { - if(u.dx == y0-u.uy && u.dy == u.ux-x0) - i = 2; /* straight turn right */ - else - i = -2; /* straight turn left */ - } else if(u.dx && u.dy) { - if((u.dx == u.dy && y0 == u.uy) || (u.dx != u.dy && y0 != u.uy)) - i = -1; /* half turn left */ - else - i = 1; /* half turn right */ - } else { - if((x0-u.ux == y0-u.uy && !u.dy) || (x0-u.ux != y0-u.uy && u.dy)) - i = 1; /* half turn right */ - else - i = -1; /* half turn left */ - } + if (levl[x][y].typ == STONE) + continue; + if (x == u.ux - u.dx && y == u.uy - u.dy) + continue; - i += u.last_str_turn; - if(i <= 2 && i >= -2) { - u.last_str_turn = i; - u.dx = x0-u.ux; - u.dy = y0-u.uy; - } + if (IS_ROCK(levl[x][y].typ) || (levl[x][y].typ == ROOM) + || IS_AIR(levl[x][y].typ)) + continue; + else if (closed_door(x, y) + || (mtmp && mtmp->m_ap_type == M_AP_FURNITURE + && (mtmp->mappearance == S_hcdoor + || mtmp->mappearance == S_vcdoor))) { + if (x != u.ux && y != u.uy) + continue; + if (context.run != 1) + goto stop; + goto bcorr; + } else if (levl[x][y].typ == CORR) { + bcorr: + if (levl[u.ux][u.uy].typ != ROOM) { + if (context.run == 1 || context.run == 3 + || context.run == 8) { + i = dist2(x, y, u.ux + u.dx, u.uy + u.dy); + if (i > 2) + continue; + if (corrct == 1 && dist2(x, y, x0, y0) != 1) + noturn = 1; + if (i < i0) { + i0 = i; + x0 = x; + y0 = y; + m0 = mtmp ? 1 : 0; + } + } + corrct++; + } + continue; + } else if ((trap = t_at(x, y)) && trap->tseen) { + if (context.run == 1) + goto bcorr; /* if you must */ + if (x == u.ux + u.dx && y == u.uy + u.dy) + goto stop; + continue; + } else if (is_pool_or_lava(x, y)) { + /* water and lava only stop you if directly in front, and stop + * you even if you are running + */ + if (!Levitation && !Flying && !is_clinger(youmonst.data) + && x == u.ux + u.dx && y == u.uy + u.dy) + /* No Wwalking check; otherwise they'd be able + * to test boots by trying to SHIFT-direction + * into a pool and seeing if the game allowed it + */ + goto stop; + continue; + } else { /* e.g. objects or trap or stairs */ + if (context.run == 1) + goto bcorr; + if (context.run == 8) + continue; + if (mtmp) + continue; /* d */ + if (((x == u.ux - u.dx) && (y != u.uy + u.dy)) + || ((y == u.uy - u.dy) && (x != u.ux + u.dx))) + continue; + } + stop: + nomul(0); + return; + } /* end for loops */ + + if (corrct > 1 && context.run == 2) + goto stop; + if ((context.run == 1 || context.run == 3 || context.run == 8) && !noturn + && !m0 && i0 && (corrct == 1 || (corrct == 2 && i0 == 1))) { + /* make sure that we do not turn too far */ + if (i0 == 2) { + if (u.dx == y0 - u.uy && u.dy == u.ux - x0) + i = 2; /* straight turn right */ + else + i = -2; /* straight turn left */ + } else if (u.dx && u.dy) { + if ((u.dx == u.dy && y0 == u.uy) || (u.dx != u.dy && y0 != u.uy)) + i = -1; /* half turn left */ + else + i = 1; /* half turn right */ + } else { + if ((x0 - u.ux == y0 - u.uy && !u.dy) + || (x0 - u.ux != y0 - u.uy && u.dy)) + i = 1; /* half turn right */ + else + i = -1; /* half turn left */ + } + + i += u.last_str_turn; + if (i <= 2 && i >= -2) { + u.last_str_turn = i; + u.dx = x0 - u.ux; + u.dy = y0 - u.uy; + } } } @@ -2413,11 +2508,13 @@ int x, y; { struct rm *lev_p = &levl[x][y]; - if (!IS_DOOR(lev_p->typ)) return FALSE; + if (!IS_DOOR(lev_p->typ)) + return FALSE; /* all rogue level doors are doorless but disallow diagonal access, so we treat them as if their non-existant doors were actually present */ - if (Is_rogue_level(&u.uz)) return FALSE; - return !(lev_p->doormask & ~(D_NODOOR|D_BROKEN)); + if (Is_rogue_level(&u.uz)) + return FALSE; + return !(lev_p->doormask & ~(D_NODOOR | D_BROKEN)); } /* used by drown() to check whether hero can crawl from water to */ @@ -2426,20 +2523,24 @@ crawl_destination(x, y) int x, y; { /* is location ok in general? */ - if (!goodpos(x, y, &youmonst, 0)) return FALSE; + if (!goodpos(x, y, &youmonst, 0)) + return FALSE; /* orthogonal movement is unrestricted when destination is ok */ - if (x == u.ux || y == u.uy) return TRUE; + if (x == u.ux || y == u.uy) + return TRUE; /* diagonal movement has some restrictions */ - if (NODIAG(u.umonnum)) return FALSE; /* poly'd into a grid bug... */ - if (Passes_walls) return TRUE; /* or a xorn... */ + if (NODIAG(u.umonnum)) + return FALSE; /* poly'd into a grid bug... */ + if (Passes_walls) + return TRUE; /* or a xorn... */ /* pool could be next to a door, conceivably even inside a shop */ if (IS_DOOR(levl[x][y].typ) && (!doorless_door(x, y) || block_door(x, y))) - return FALSE; + return FALSE; /* finally, are we trying to squeeze through a too-narrow gap? */ - return !(bad_rock(youmonst.data, u.ux, y) && - bad_rock(youmonst.data, x, u.uy)); + return !(bad_rock(youmonst.data, u.ux, y) + && bad_rock(youmonst.data, x, u.uy)); } /* something like lookaround, but we are not running */ @@ -2447,37 +2548,39 @@ int x, y; int monster_nearby() { - register int x,y; + register int x, y; register struct monst *mtmp; /* Also see the similar check in dochugw() in monmove.c */ - for(x = u.ux-1; x <= u.ux+1; x++) - for(y = u.uy-1; y <= u.uy+1; y++) { - if(!isok(x,y)) continue; - if(x == u.ux && y == u.uy) continue; - if((mtmp = m_at(x,y)) && - mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT && - (!mtmp->mpeaceful || Hallucination) && - (!is_hider(mtmp->data) || !mtmp->mundetected) && - !noattacks(mtmp->data) && - mtmp->mcanmove && !mtmp->msleeping && /* aplvax!jcn */ - !onscary(u.ux, u.uy, mtmp) && - canspotmon(mtmp)) - return(1); - } - return(0); + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (!isok(x, y)) + continue; + if (x == u.ux && y == u.uy) + continue; + if ((mtmp = m_at(x, y)) && mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT + && (!mtmp->mpeaceful || Hallucination) + && (!is_hider(mtmp->data) || !mtmp->mundetected) + && !noattacks(mtmp->data) && mtmp->mcanmove + && !mtmp->msleeping && /* aplvax!jcn */ + !onscary(u.ux, u.uy, mtmp) && canspotmon(mtmp)) + return (1); + } + return (0); } void nomul(nval) - register int nval; +register int nval; { - if(multi < nval) return; /* This is a bug fix by ab@unido */ - u.uinvulnerable = FALSE; /* Kludge to avoid ctrl-C bug -dlc */ + if (multi < nval) + return; /* This is a bug fix by ab@unido */ + u.uinvulnerable = FALSE; /* Kludge to avoid ctrl-C bug -dlc */ u.usleep = 0; multi = nval; - if (nval == 0) multi_reason = NULL; + if (nval == 0) + multi_reason = NULL; context.travel = context.travel1 = context.mv = context.run = 0; } @@ -2486,14 +2589,18 @@ void unmul(msg_override) const char *msg_override; { - multi = 0; /* caller will usually have done this already */ - if (msg_override) nomovemsg = msg_override; - else if (!nomovemsg) nomovemsg = You_can_move_again; - if (*nomovemsg) pline1(nomovemsg); + multi = 0; /* caller will usually have done this already */ + if (msg_override) + nomovemsg = msg_override; + else if (!nomovemsg) + nomovemsg = You_can_move_again; + if (*nomovemsg) + pline1(nomovemsg); nomovemsg = 0; u.usleep = 0; - multi_reason = NULL; - if (afternmv) (*afternmv)(); + multi_reason = NULL; + if (afternmv) + (*afternmv)(); afternmv = 0; } @@ -2501,30 +2608,33 @@ STATIC_OVL void maybe_wail() { static short powers[] = { TELEPORT, SEE_INVIS, POISON_RES, COLD_RES, - SHOCK_RES, FIRE_RES, SLEEP_RES, DISINT_RES, - TELEPORT_CONTROL, STEALTH, FAST, INVIS }; + SHOCK_RES, FIRE_RES, SLEEP_RES, DISINT_RES, + TELEPORT_CONTROL, STEALTH, FAST, INVIS }; - if (moves <= wailmsg + 50) return; + if (moves <= wailmsg + 50) + return; wailmsg = moves; if (Role_if(PM_WIZARD) || Race_if(PM_ELF) || Role_if(PM_VALKYRIE)) { - const char *who; - int i, powercnt; + const char *who; + int i, powercnt; - who = (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ? - urole.name.m : "Elf"; - if (u.uhp == 1) { - pline("%s is about to die.", who); - } else { - for (i = 0, powercnt = 0; i < SIZE(powers); ++i) - if (u.uprops[powers[i]].intrinsic & INTRINSIC) ++powercnt; + who = (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ? urole.name.m + : "Elf"; + if (u.uhp == 1) { + pline("%s is about to die.", who); + } else { + for (i = 0, powercnt = 0; i < SIZE(powers); ++i) + if (u.uprops[powers[i]].intrinsic & INTRINSIC) + ++powercnt; - pline(powercnt >= 4 ? "%s, all your powers will be lost..." - : "%s, your life force is running out.", who); - } + pline(powercnt >= 4 ? "%s, all your powers will be lost..." + : "%s, your life force is running out.", + who); + } } else { - You_hear(u.uhp == 1 ? "the wailing of the Banshee..." - : "the howling of the CwnAnnwn..."); + You_hear(u.uhp == 1 ? "the wailing of the Banshee..." + : "the howling of the CwnAnnwn..."); } } @@ -2536,26 +2646,27 @@ boolean k_format; { if (Upolyd) { u.mh -= n; - if (u.mhmax < u.mh) u.mhmax = u.mh; + if (u.mhmax < u.mh) + u.mhmax = u.mh; context.botl = 1; if (u.mh < 1) rehumanize(); - else if (n > 0 && u.mh*10 < u.mhmax && Unchanging) + else if (n > 0 && u.mh * 10 < u.mhmax && Unchanging) maybe_wail(); return; } u.uhp -= n; - if(u.uhp > u.uhpmax) - u.uhpmax = u.uhp; /* perhaps n was negative */ + if (u.uhp > u.uhpmax) + u.uhpmax = u.uhp; /* perhaps n was negative */ context.botl = 1; - if(u.uhp < 1) { + if (u.uhp < 1) { killer.format = k_format; if (killer.name != knam) /* the thing that killed you */ Strcpy(killer.name, knam ? knam : ""); You("die..."); done(DIED); - } else if (n > 0 && u.uhp*10 < u.uhpmax) { + } else if (n > 0 && u.uhp * 10 < u.uhpmax) { maybe_wail(); } } @@ -2565,34 +2676,38 @@ weight_cap() { register long carrcap; - carrcap = 25*(ACURRSTR + ACURR(A_CON)) + 50; + carrcap = 25 * (ACURRSTR + ACURR(A_CON)) + 50; if (Upolyd) { /* consistent with can_carry() in mon.c */ if (youmonst.data->mlet == S_NYMPH) carrcap = MAX_CARR_CAP; else if (!youmonst.data->cwt) - carrcap = (carrcap * (long)youmonst.data->msize) / MZ_HUMAN; + carrcap = (carrcap * (long) youmonst.data->msize) / MZ_HUMAN; else if (!strongmonst(youmonst.data) - || (strongmonst(youmonst.data) && (youmonst.data->cwt > WT_HUMAN))) - carrcap = (carrcap * (long)youmonst.data->cwt / WT_HUMAN); + || (strongmonst(youmonst.data) + && (youmonst.data->cwt > WT_HUMAN))) + carrcap = (carrcap * (long) youmonst.data->cwt / WT_HUMAN); } - if (Levitation || Is_airlevel(&u.uz) /* pugh@cornell */ - || (u.usteed && strongmonst(u.usteed->data)) - ) + if (Levitation || Is_airlevel(&u.uz) /* pugh@cornell */ + || (u.usteed && strongmonst(u.usteed->data))) carrcap = MAX_CARR_CAP; else { - if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP; + if (carrcap > MAX_CARR_CAP) + carrcap = MAX_CARR_CAP; if (!Flying) { - if(EWounded_legs & LEFT_SIDE) carrcap -= 100; - if(EWounded_legs & RIGHT_SIDE) carrcap -= 100; + if (EWounded_legs & LEFT_SIDE) + carrcap -= 100; + if (EWounded_legs & RIGHT_SIDE) + carrcap -= 100; } - if (carrcap < 0) carrcap = 0; + if (carrcap < 0) + carrcap = 0; } - return((int) carrcap); + return ((int) carrcap); } -static int wc; /* current weight_cap(); valid after call to inv_weight() */ +static int wc; /* current weight_cap(); valid after call to inv_weight() */ /* returns how far beyond the normal capacity the player is currently. */ /* inv_weight() is negative if the player is below normal capacity. */ @@ -2604,7 +2719,7 @@ inv_weight() while (otmp) { if (otmp->oclass == COIN_CLASS) - wt += (int)(((long)otmp->quan + 50L) / 100L); + wt += (int) (((long) otmp->quan + 50L) / 100L); else if (otmp->otyp != BOULDER || !throws_rocks(youmonst.data)) wt += otmp->owt; otmp = otmp->nobj; @@ -2623,9 +2738,11 @@ int xtra_wt; { int cap, wt = inv_weight() + xtra_wt; - if (wt <= 0) return UNENCUMBERED; - if (wc <= 1) return OVERLOADED; - cap = (wt*2 / wc) + 1; + if (wt <= 0) + return UNENCUMBERED; + if (wc <= 1) + return OVERLOADED; + cap = (wt * 2 / wc) + 1; return min(cap, OVERLOADED); } @@ -2647,12 +2764,12 @@ boolean check_capacity(str) const char *str; { - if(near_capacity() >= EXT_ENCUMBER) { - if(str) - pline1(str); - else - You_cant("do that while carrying so much stuff."); - return 1; + if (near_capacity() >= EXT_ENCUMBER) { + if (str) + pline1(str); + else + You_cant("do that while carrying so much stuff."); + return 1; } return 0; } @@ -2664,11 +2781,12 @@ boolean incl_gold; register struct obj *otmp = invent; register int ct = 0; - while(otmp){ - if (incl_gold || otmp->invlet != GOLD_SYM) ct++; + while (otmp) { + if (incl_gold || otmp->invlet != GOLD_SYM) + ct++; otmp = otmp->nobj; } - return(ct); + return (ct); } /* Counts the money in an object chain. */ @@ -2680,9 +2798,10 @@ money_cnt(otmp) struct obj *otmp; { while (otmp) { - /* Must change when silver & copper is implemented: */ - if (otmp->oclass == COIN_CLASS) return otmp->quan; - otmp = otmp->nobj; + /* Must change when silver & copper is implemented: */ + if (otmp->oclass == COIN_CLASS) + return otmp->quan; + otmp = otmp->nobj; } return 0L; } diff --git a/src/hacklib.c b/src/hacklib.c index 55eb4008a..7cbfe39aa 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1,128 +1,124 @@ -/* NetHack 3.6 hacklib.c $NHDT-Date: 1429953063 2015/04/25 09:11:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.38 $ */ +/* NetHack 3.6 hacklib.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */ /* NetHack 3.6 hacklib.c $Date: 2009/05/06 10:46:32 $ $Revision: 1.23 $ */ /* SCCS Id: @(#)hacklib.c 3.5 2007/04/30 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Robert Patrick Rankin, 1991 */ /* NetHack may be freely redistributed. See license for details. */ -#include "hack.h" /* for config.h+extern.h */ -/*= - Assorted 'small' utility routines. They're virtually independent of -NetHack, except that rounddiv may call panic(). setrandom calls one of -srandom(), srand48(), or srand() depending upon configuration. - - return type routine name argument type(s) - boolean digit (char) - boolean letter (char) - char highc (char) - char lowc (char) - char * lcase (char *) - char * ucase (char *) - char * upstart (char *) - char * mungspaces (char *) - char * eos (char *) - char * strkitten (char *,char) - void copynchars (char *,const char *,int) - char chrcasecpy (int,int) - char * strcasecpy (char *,const char *) - char * s_suffix (const char *) - char * ing_suffix (const char *) - char * xcrypt (const char *, char *) - boolean onlyspace (const char *) - char * tabexpand (char *) - char * visctrl (char) - char * strsubst (char *, const char *, const char *) - const char * ordin (int) - char * sitoa (int) - int sgn (int) - int rounddiv (long, int) - int distmin (int, int, int, int) - int dist2 (int, int, int, int) - boolean online2 (int, int) - boolean pmatch (const char *, const char *) - boolean pmatchi (const char *, const char *) - boolean pmatchz (const char *, const char *) - int strncmpi (const char *, const char *, int) - char * strstri (const char *, const char *) - boolean fuzzymatch (const char *,const char *, - const char *,boolean) - void setrandom (void) - time_t getnow (void) - int getyear (void) - char * yymmdd (time_t) - long yyyymmdd (time_t) - long hhmmss (time_t) - char * yyyymmddhhmmss (time_t) - time_t time_from_yyyymmddhhmmss (char *) - int phase_of_the_moon (void) - boolean friday_13th (void) - int night (void) - int midnight (void) -=*/ +#include "hack.h" /* for config.h+extern.h */ + /*= + Assorted 'small' utility routines. They're virtually independent of + NetHack, except that rounddiv may call panic(). setrandom calls one of + srandom(), srand48(), or srand() depending upon configuration. + + return type routine name argument type(s) + boolean digit (char) + boolean letter (char) + char highc (char) + char lowc (char) + char * lcase (char *) + char * ucase (char *) + char * upstart (char *) + char * mungspaces (char *) + char * eos (char *) + char * strkitten (char *,char) + void copynchars (char *,const char *,int) + char chrcasecpy (int,int) + char * strcasecpy (char *,const char *) + char * s_suffix (const char *) + char * ing_suffix (const char *) + char * xcrypt (const char *, char *) + boolean onlyspace (const char *) + char * tabexpand (char *) + char * visctrl (char) + char * strsubst (char *, const char *, const char *) + const char * ordin (int) + char * sitoa (int) + int sgn (int) + int rounddiv (long, int) + int distmin (int, int, int, int) + int dist2 (int, int, int, int) + boolean online2 (int, int) + boolean pmatch (const char *, const char *) + boolean pmatchi (const char *, const char *) + boolean pmatchz (const char *, const char *) + int strncmpi (const char *, const char *, int) + char * strstri (const char *, const char *) + boolean fuzzymatch (const char *,const char *, + const char *,boolean) + void setrandom (void) + time_t getnow (void) + int getyear (void) + char * yymmdd (time_t) + long yyyymmdd (time_t) + long hhmmss (time_t) + char * yyyymmddhhmmss (time_t) + time_t time_from_yyyymmddhhmmss (char *) + int phase_of_the_moon (void) + boolean friday_13th (void) + int night (void) + int midnight (void) + =*/ #ifdef LINT -# define Static /* pacify lint */ +#define Static /* pacify lint */ #else -# define Static static +#define Static static #endif -static boolean FDECL(pmatch_internal, (const char *,const char *, - BOOLEAN_P,const char *)); +static boolean FDECL(pmatch_internal, + (const char *, const char *, BOOLEAN_P, const char *)); -boolean -digit(c) /* is 'c' a digit? */ - char c; +boolean digit(c) /* is 'c' a digit? */ +char c; { - return((boolean)('0' <= c && c <= '9')); + return ((boolean)('0' <= c && c <= '9')); } -boolean -letter(c) /* is 'c' a letter? note: '@' classed as letter */ - char c; +boolean letter(c) /* is 'c' a letter? note: '@' classed as letter */ +char c; { - return((boolean)(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))); + return ((boolean)(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))); } -char -highc(c) /* force 'c' into uppercase */ - char c; +char highc(c) /* force 'c' into uppercase */ +char c; { - return((char)(('a' <= c && c <= 'z') ? (c & ~040) : c)); + return ((char) (('a' <= c && c <= 'z') ? (c & ~040) : c)); } -char -lowc(c) /* force 'c' into lowercase */ - char c; +char lowc(c) /* force 'c' into lowercase */ +char c; { - return((char)(('A' <= c && c <= 'Z') ? (c | 040) : c)); + return ((char) (('A' <= c && c <= 'Z') ? (c | 040) : c)); } -char * -lcase(s) /* convert a string into all lowercase */ - char *s; +char *lcase(s) /* convert a string into all lowercase */ +char *s; { register char *p; for (p = s; *p; p++) - if ('A' <= *p && *p <= 'Z') *p |= 040; + if ('A' <= *p && *p <= 'Z') + *p |= 040; return s; } -char * -ucase(s) /* convert a string into all uppercase */ - char *s; +char *ucase(s) /* convert a string into all uppercase */ +char *s; { register char *p; for (p = s; *p; p++) - if ('a' <= *p && *p <= 'z') *p &= ~040; + if ('a' <= *p && *p <= 'z') + *p &= ~040; return s; } -char * -upstart(s) /* convert first character of a string to uppercase */ - char *s; +char *upstart(s) /* convert first character of a string to uppercase */ +char *s; { - if (s) *s = highc(*s); + if (s) + *s = highc(*s); return s; } @@ -135,29 +131,32 @@ char *bp; boolean was_space = TRUE; for (p = p2 = bp; (c = *p) != '\0'; p++) { - if (c == '\n') break; /* treat newline the same as end-of-string */ - if (c == '\t') c = ' '; - if (c != ' ' || !was_space) *p2++ = c; - was_space = (c == ' '); + if (c == '\n') + break; /* treat newline the same as end-of-string */ + if (c == '\t') + c = ' '; + if (c != ' ' || !was_space) + *p2++ = c; + was_space = (c == ' '); } - if (was_space && p2 > bp) p2--; + if (was_space && p2 > bp) + p2--; *p2 = '\0'; return bp; } -char * -eos(s) /* return the end of a string (pointing at '\0') */ - register char *s; +char *eos(s) /* return the end of a string (pointing at '\0') */ +register char *s; { - while (*s) s++; /* s += strlen(s); */ + while (*s) + s++; /* s += strlen(s); */ return s; } /* strcat(s, {c,'\0'}); */ -char * -strkitten(s, c) /* append a character to a string (in place) */ - char *s; - char c; +char *strkitten(s, c) /* append a character to a string (in place) */ +char *s; +char c; { char *p = eos(s); @@ -166,47 +165,46 @@ strkitten(s, c) /* append a character to a string (in place) */ return s; } -void -copynchars(dst, src, n) /* truncating string copy */ - char *dst; - const char *src; - int n; +void copynchars(dst, src, n) /* truncating string copy */ +char *dst; +const char *src; +int n; { /* copies at most n characters, stopping sooner if terminator reached; treats newline as input terminator; unlike strncpy, always supplies '\0' terminator so dst must be able to hold at least n+1 characters */ while (n > 0 && *src != '\0' && *src != '\n') { - *dst++ = *src++; - --n; + *dst++ = *src++; + --n; } *dst = '\0'; } /* mostly used by strcasecpy */ -char -chrcasecpy(oc, nc) /* convert char nc into oc's case */ - int oc, nc; +char chrcasecpy(oc, nc) /* convert char nc into oc's case */ +int oc, nc; { -#if 0 /* this will be necessary if we switch to */ +#if 0 /* this will be necessary if we switch to */ oc = (int)(unsigned char)oc; nc = (int)(unsigned char)nc; #endif if ('a' <= oc && oc <= 'z') { - /* old char is lower case; if new char is upper case, downcase it */ - if ('A' <= nc && nc <= 'Z') nc += 'a' - 'A'; /* lowc(nc) */ + /* old char is lower case; if new char is upper case, downcase it */ + if ('A' <= nc && nc <= 'Z') + nc += 'a' - 'A'; /* lowc(nc) */ } else if ('A' <= oc && oc <= 'Z') { - /* old char is upper case; if new char is lower case, upcase it */ - if ('a' <= nc && nc <= 'z') nc += 'A' - 'a'; /* highc(nc) */ + /* old char is upper case; if new char is lower case, upcase it */ + if ('a' <= nc && nc <= 'z') + nc += 'A' - 'a'; /* highc(nc) */ } - return (char)nc; + return (char) nc; } /* for case-insensitive editions of makeplural() and makesingular(); src might be shorter, same length, or longer than dst */ -char * -strcasecpy(dst, src) /* overwrite string, preserving old chars' case */ - char *dst; - const char *src; +char *strcasecpy(dst, src) /* overwrite string, preserving old chars' case */ +char *dst; +const char *src; { char *result = dst; int ic, oc, dst_exhausted = 0; @@ -216,36 +214,36 @@ strcasecpy(dst, src) /* overwrite string, preserving old chars' case */ once dst runs out, propagate the case of its last character to any remaining src; if dst starts empty, it must be a pointer to the tail of some other string because we examine the char at dst[-1] */ - while ((ic = (int)*src++) != '\0') { - if (!dst_exhausted && !*dst) dst_exhausted = 1; - oc = (int)*(dst - dst_exhausted); - *dst++ = chrcasecpy(oc, ic); + while ((ic = (int) *src++) != '\0') { + if (!dst_exhausted && !*dst) + dst_exhausted = 1; + oc = (int) *(dst - dst_exhausted); + *dst++ = chrcasecpy(oc, ic); } *dst = '\0'; return result; } -char * -s_suffix(s) /* return a name converted to possessive */ - const char *s; +char *s_suffix(s) /* return a name converted to possessive */ +const char *s; { Static char buf[BUFSZ]; Strcpy(buf, s); - if (!strcmpi(buf, "it")) /* it -> its */ - Strcat(buf, "s"); - else if (!strcmpi(buf, "you")) /* you -> your */ - Strcat(buf, "r"); - else if (*(eos(buf)-1) == 's') /* Xs -> Xs' */ - Strcat(buf, "'"); - else /* X -> X's */ - Strcat(buf, "'s"); + if (!strcmpi(buf, "it")) /* it -> its */ + Strcat(buf, "s"); + else if (!strcmpi(buf, "you")) /* you -> your */ + Strcat(buf, "r"); + else if (*(eos(buf) - 1) == 's') /* Xs -> Xs' */ + Strcat(buf, "'"); + else /* X -> X's */ + Strcat(buf, "'s"); return buf; } char * ing_suffix(s) - const char *s; +const char *s; { const char *vowel = "aeiouy"; static char buf[BUFSZ]; @@ -253,31 +251,30 @@ ing_suffix(s) char *p; Strcpy(buf, s); p = eos(buf); - onoff[0] = *p = *(p+1) = '\0'; - if ((strlen(buf) > 4) && - (!strcmpi(p-3, " on") || - !strcmpi(p-4, " off") || - !strcmpi(p-5, " with"))) { - p = strrchr(buf, ' '); - Strcpy(onoff, p); + onoff[0] = *p = *(p + 1) = '\0'; + if ((strlen(buf) > 4) + && (!strcmpi(p - 3, " on") || !strcmpi(p - 4, " off") + || !strcmpi(p - 5, " with"))) { + p = strrchr(buf, ' '); + Strcpy(onoff, p); } - if (!index(vowel, *(p-1)) && index(vowel, *(p-2)) && !index(vowel, *(p-3))) { - /* tip -> tipp + ing */ - *p = *(p-1); - *(p+1) = '\0'; - } else if (!strcmpi(p-2, "ie")) { /* vie -> vy + ing */ - *(p-2) = 'y'; - *(p-1) = '\0'; - } else if (*(p-1) == 'e') /* grease -> greas + ing */ - *(p-1) = '\0'; + if (!index(vowel, *(p - 1)) && index(vowel, *(p - 2)) + && !index(vowel, *(p - 3))) { + /* tip -> tipp + ing */ + *p = *(p - 1); + *(p + 1) = '\0'; + } else if (!strcmpi(p - 2, "ie")) { /* vie -> vy + ing */ + *(p - 2) = 'y'; + *(p - 1) = '\0'; + } else if (*(p - 1) == 'e') /* grease -> greas + ing */ + *(p - 1) = '\0'; Strcat(buf, "ing"); - if (onoff[0]) Strcat(buf, onoff); + if (onoff[0]) + Strcat(buf, onoff); return buf; } - -char * -xcrypt(str, buf) /* trivial text encryption routine (see makedefs) */ +char *xcrypt(str, buf) /* trivial text encryption routine (see makedefs) */ const char *str; char *buf; { @@ -286,48 +283,51 @@ char *buf; register int bitmask; for (bitmask = 1, p = str, q = buf; *p; q++) { - *q = *p++; - if (*q & (32|64)) *q ^= bitmask; - if ((bitmask <<= 1) >= 32) bitmask = 1; + *q = *p++; + if (*q & (32 | 64)) + *q ^= bitmask; + if ((bitmask <<= 1) >= 32) + bitmask = 1; } *q = '\0'; return buf; } -boolean -onlyspace(s) /* is a string entirely whitespace? */ - const char *s; +boolean onlyspace(s) /* is a string entirely whitespace? */ +const char *s; { for (; *s; s++) - if (*s != ' ' && *s != '\t') return FALSE; + if (*s != ' ' && *s != '\t') + return FALSE; return TRUE; } -char * -tabexpand(sbuf) /* expand tabs into proper number of spaces */ - char *sbuf; +char *tabexpand(sbuf) /* expand tabs into proper number of spaces */ +char *sbuf; { char buf[BUFSZ]; register char *bp, *s = sbuf; register int idx; - if (!*s) return sbuf; + if (!*s) + return sbuf; /* warning: no bounds checking performed */ for (bp = buf, idx = 0; *s; s++) - if (*s == '\t') { - do *bp++ = ' '; while (++idx % 8); - } else { - *bp++ = *s; - idx++; - } + if (*s == '\t') { + do + *bp++ = ' '; + while (++idx % 8); + } else { + *bp++ = *s; + idx++; + } *bp = 0; return strcpy(sbuf, buf); } -char * -visctrl(c) /* make a displayable string from a character */ - char c; +char *visctrl(c) /* make a displayable string from a character */ +char c; { Static char ccc[3]; @@ -335,14 +335,14 @@ visctrl(c) /* make a displayable string from a character */ ccc[2] = '\0'; if (c < 040) { - ccc[0] = '^'; - ccc[1] = c | 0100; /* letter */ + ccc[0] = '^'; + ccc[1] = c | 0100; /* letter */ } else if (c == 0177) { - ccc[0] = '^'; - ccc[1] = c & ~0100; /* '?' */ + ccc[0] = '^'; + ccc[1] = c & ~0100; /* '?' */ } else { - ccc[0] = c; /* printable character */ - ccc[1] = '\0'; + ccc[0] = c; /* printable character */ + ccc[1] = '\0'; } return ccc; } @@ -351,36 +351,34 @@ visctrl(c) /* make a displayable string from a character */ /* caller is responsible for ensuring that bp points to big enough buffer */ char * strsubst(bp, orig, replacement) - char *bp; - const char *orig, *replacement; +char *bp; +const char *orig, *replacement; { char *found, buf[BUFSZ]; if (bp) { - found = strstr(bp, orig); - if (found) { - Strcpy(buf, found + strlen(orig)); - Strcpy(found, replacement); - Strcat(bp, buf); - } + found = strstr(bp, orig); + if (found) { + Strcpy(buf, found + strlen(orig)); + Strcpy(found, replacement); + Strcat(bp, buf); + } } return bp; } - -const char * -ordin(n) /* return the ordinal suffix of a number */ - int n; /* note: should be non-negative */ +const char *ordin(n) /* return the ordinal suffix of a number */ +int n; /* note: should be non-negative */ { register int dd = n % 10; - return (dd == 0 || dd > 3 || (n % 100) / 10 == 1) ? "th" : - (dd == 1) ? "st" : (dd == 2) ? "nd" : "rd"; + return (dd == 0 || dd > 3 || (n % 100) / 10 == 1) + ? "th" + : (dd == 1) ? "st" : (dd == 2) ? "nd" : "rd"; } -char * -sitoa(n) /* make a signed digit string from a number */ - int n; +char *sitoa(n) /* make a signed digit string from a number */ +int n; { Static char buf[13]; @@ -388,52 +386,54 @@ sitoa(n) /* make a signed digit string from a number */ return buf; } -int -sgn(n) /* return the sign of a number: -1, 0, or 1 */ - int n; +int sgn(n) /* return the sign of a number: -1, 0, or 1 */ +int n; { return (n < 0) ? -1 : (n != 0); } -int -rounddiv(x, y) /* calculate x/y, rounding as appropriate */ - long x; - int y; +int rounddiv(x, y) /* calculate x/y, rounding as appropriate */ +long x; +int y; { int r, m; int divsgn = 1; if (y == 0) - panic("division by zero in rounddiv"); + panic("division by zero in rounddiv"); else if (y < 0) { - divsgn = -divsgn; y = -y; + divsgn = -divsgn; + y = -y; } if (x < 0) { - divsgn = -divsgn; x = -x; + divsgn = -divsgn; + x = -x; } r = x / y; m = x % y; - if (2*m >= y) r++; + if (2 * m >= y) + r++; return divsgn * r; } -int -distmin(x0, y0, x1, y1) /* distance between two points, in moves */ - int x0, y0, x1, y1; +int distmin(x0, y0, x1, y1) /* distance between two points, in moves */ +int x0, y0, x1, y1; { register int dx = x0 - x1, dy = y0 - y1; - if (dx < 0) dx = -dx; - if (dy < 0) dy = -dy; - /* The minimum number of moves to get from (x0,y0) to (x1,y1) is the - : larger of the [absolute value of the] two deltas. - */ + if (dx < 0) + dx = -dx; + if (dy < 0) + dy = -dy; + /* The minimum number of moves to get from (x0,y0) to (x1,y1) is the + : larger of the [absolute value of the] two deltas. + */ return (dx < dy) ? dy : dx; } -int -dist2(x0, y0, x1, y1) /* square of euclidean distance between pair of pts */ - int x0, y0, x1, y1; +int dist2(x0, y0, x1, + y1) /* square of euclidean distance between pair of pts */ +int x0, y0, x1, y1; { register int dx = x0 - x1, dy = y0 - y1; return dx * dx + dy * dy; @@ -453,78 +453,85 @@ int val; { int rt = 0; int odd = 1; - while(val >= odd) { - val = val-odd; - odd = odd+2; + while (val >= odd) { + val = val - odd; + odd = odd + 2; rt = rt + 1; } return rt; } -boolean -online2(x0, y0, x1, y1) /* are two points lined up (on a straight line)? */ - int x0, y0, x1, y1; +boolean online2(x0, y0, x1, + y1) /* are two points lined up (on a straight line)? */ +int x0, y0, x1, y1; { int dx = x0 - x1, dy = y0 - y1; /* If either delta is zero then they're on an orthogonal line, * else if the deltas are equal (signs ignored) they're on a diagonal. */ - return((boolean)(!dy || !dx || (dy == dx) || (dy + dx == 0))); /* (dy == -dx) */ + return ((boolean)(!dy || !dx || (dy == dx) + || (dy + dx == 0))); /* (dy == -dx) */ } /* guts of pmatch(), pmatchi(), and pmatchz() */ -static boolean -pmatch_internal(patrn, strng, ci, sk) /* match a string against a pattern */ - const char *patrn, *strng; - boolean ci; /* True => case-insensitive, False => case-sensitive */ - const char *sk; /* set of characters to skip */ +static boolean pmatch_internal(patrn, strng, ci, + sk) /* match a string against a pattern */ +const char *patrn, *strng; +boolean ci; /* True => case-insensitive, False => case-sensitive */ +const char *sk; /* set of characters to skip */ { char s, p; - /* - : Simple pattern matcher: '*' matches 0 or more characters, '?' matches - : any single character. Returns TRUE if 'strng' matches 'patrn'. - */ +/* + : Simple pattern matcher: '*' matches 0 or more characters, '?' matches + : any single character. Returns TRUE if 'strng' matches 'patrn'. + */ pmatch_top: if (!sk) { - s = *strng++; p = *patrn++; /* get next chars and pre-advance */ + s = *strng++; + p = *patrn++; /* get next chars and pre-advance */ } else { - /* fuzzy match variant of pmatch; particular characters are ignored */ - do { s = *strng++; } while (index(sk, s)); - do { p = *patrn++; } while (index(sk, p)); + /* fuzzy match variant of pmatch; particular characters are ignored */ + do { + s = *strng++; + } while (index(sk, s)); + do { + p = *patrn++; + } while (index(sk, p)); } - if (!p) /* end of pattern */ - return (boolean)(s == '\0'); /* matches iff end of string too */ - else if (p == '*') /* wildcard reached */ - return (boolean) - ((!*patrn || pmatch_internal(patrn, strng-1, ci, sk)) ? TRUE : - s ? pmatch_internal(patrn-1, strng, ci, sk) : FALSE); - else if ((ci ? lowc(p) != lowc(s) : p != s) /* check single character */ - && (p != '?' || !s)) /* & single-char wildcard */ - return FALSE; /* doesn't match */ - else /* return pmatch_internal(patrn, strng, ci, sk); */ - goto pmatch_top; /* optimize tail recursion */ + if (!p) /* end of pattern */ + return (boolean)(s == '\0'); /* matches iff end of string too */ + else if (p == '*') /* wildcard reached */ + return (boolean)( + (!*patrn || pmatch_internal(patrn, strng - 1, ci, sk)) + ? TRUE + : s ? pmatch_internal(patrn - 1, strng, ci, sk) : FALSE); + else if ((ci ? lowc(p) != lowc(s) : p != s) /* check single character */ + && (p != '?' || !s)) /* & single-char wildcard */ + return FALSE; /* doesn't match */ + else /* return pmatch_internal(patrn, strng, ci, sk); */ + goto pmatch_top; /* optimize tail recursion */ } /* case-sensitive wildcard match */ boolean pmatch(patrn, strng) - const char *patrn, *strng; +const char *patrn, *strng; { - return pmatch_internal(patrn, strng, FALSE, (const char *)0); + return pmatch_internal(patrn, strng, FALSE, (const char *) 0); } /* case-insensitive wildcard match */ boolean pmatchi(patrn, strng) - const char *patrn, *strng; +const char *patrn, *strng; { - return pmatch_internal(patrn, strng, TRUE, (const char *)0); + return pmatch_internal(patrn, strng, TRUE, (const char *) 0); } /* case-insensitive wildcard fuzzymatch */ boolean pmatchz(patrn, strng) - const char *patrn, *strng; +const char *patrn, *strng; { /* ignore spaces, tabs (just in case), dashes, and underscores */ static const char fuzzychars[] = " \t-_"; @@ -533,83 +540,94 @@ pmatchz(patrn, strng) } #ifndef STRNCMPI -int -strncmpi(s1, s2, n) /* case insensitive counted string comparison */ - register const char *s1, *s2; - register int n; /*(should probably be size_t, which is usually unsigned)*/ -{ /*{ aka strncasecmp }*/ +int strncmpi(s1, s2, n) /* case insensitive counted string comparison */ +register const char *s1, *s2; +register int n; /*(should probably be size_t, which is usually unsigned)*/ +{ /*{ aka strncasecmp }*/ register char t1, t2; while (n--) { - if (!*s2) return (*s1 != 0); /* s1 >= s2 */ - else if (!*s1) return -1; /* s1 < s2 */ - t1 = lowc(*s1++); - t2 = lowc(*s2++); - if (t1 != t2) return (t1 > t2) ? 1 : -1; + if (!*s2) + return (*s1 != 0); /* s1 >= s2 */ + else if (!*s1) + return -1; /* s1 < s2 */ + t1 = lowc(*s1++); + t2 = lowc(*s2++); + if (t1 != t2) + return (t1 > t2) ? 1 : -1; } - return 0; /* s1 == s2 */ + return 0; /* s1 == s2 */ } -#endif /* STRNCMPI */ +#endif /* STRNCMPI */ #ifndef STRSTRI -char * -strstri(str, sub) /* case insensitive substring search */ - const char *str; - const char *sub; +char *strstri(str, sub) /* case insensitive substring search */ +const char *str; +const char *sub; { register const char *s1, *s2; register int i, k; -# define TABSIZ 0x20 /* 0x40 would be case-sensitive */ - char tstr[TABSIZ], tsub[TABSIZ]; /* nibble count tables */ -# if 0 +#define TABSIZ 0x20 /* 0x40 would be case-sensitive */ + char tstr[TABSIZ], tsub[TABSIZ]; /* nibble count tables */ +#if 0 assert( (TABSIZ & ~(TABSIZ-1)) == TABSIZ ); /* must be exact power of 2 */ assert( &lowc != 0 ); /* can't be unsafe macro */ -# endif +#endif /* special case: empty substring */ - if (!*sub) return (char *) str; + if (!*sub) + return (char *) str; /* do some useful work while determining relative lengths */ - for (i = 0; i < TABSIZ; i++) tstr[i] = tsub[i] = 0; /* init */ - for (k = 0, s1 = str; *s1; k++) tstr[*s1++ & (TABSIZ-1)]++; - for ( s2 = sub; *s2; --k) tsub[*s2++ & (TABSIZ-1)]++; + for (i = 0; i < TABSIZ; i++) + tstr[i] = tsub[i] = 0; /* init */ + for (k = 0, s1 = str; *s1; k++) + tstr[*s1++ & (TABSIZ - 1)]++; + for (s2 = sub; *s2; --k) + tsub[*s2++ & (TABSIZ - 1)]++; /* evaluate the info we've collected */ - if (k < 0) return (char *) 0; /* sub longer than str, so can't match */ - for (i = 0; i < TABSIZ; i++) /* does sub have more 'x's than str? */ - if (tsub[i] > tstr[i]) return (char *) 0; /* match not possible */ + if (k < 0) + return (char *) 0; /* sub longer than str, so can't match */ + for (i = 0; i < TABSIZ; i++) /* does sub have more 'x's than str? */ + if (tsub[i] > tstr[i]) + return (char *) 0; /* match not possible */ /* now actually compare the substring repeatedly to parts of the string */ for (i = 0; i <= k; i++) { - s1 = &str[i]; - s2 = sub; - while (lowc(*s1++) == lowc(*s2++)) - if (!*s2) return (char *) &str[i]; /* full match */ + s1 = &str[i]; + s2 = sub; + while (lowc(*s1++) == lowc(*s2++)) + if (!*s2) + return (char *) &str[i]; /* full match */ } - return (char *) 0; /* not found */ + return (char *) 0; /* not found */ } -#endif /* STRSTRI */ +#endif /* STRSTRI */ /* compare two strings for equality, ignoring the presence of specified characters (typically whitespace) and possibly ignoring case */ boolean fuzzymatch(s1, s2, ignore_chars, caseblind) - const char *s1, *s2; - const char *ignore_chars; - boolean caseblind; +const char *s1, *s2; +const char *ignore_chars; +boolean caseblind; { register char c1, c2; do { - while ((c1 = *s1++) != '\0' && index(ignore_chars, c1) != 0) continue; - while ((c2 = *s2++) != '\0' && index(ignore_chars, c2) != 0) continue; - if (!c1 || !c2) break; /* stop when end of either string is reached */ + while ((c1 = *s1++) != '\0' && index(ignore_chars, c1) != 0) + continue; + while ((c2 = *s2++) != '\0' && index(ignore_chars, c2) != 0) + continue; + if (!c1 || !c2) + break; /* stop when end of either string is reached */ - if (caseblind) { - c1 = lowc(c1); - c2 = lowc(c2); - } + if (caseblind) { + c1 = lowc(c1); + c2 = lowc(c2); + } } while (c1 == c2); /* match occurs only when the end of both strings has been reached */ @@ -629,73 +647,76 @@ fuzzymatch(s1, s2, ignore_chars, caseblind) /* TIME_type: type of the argument to time(); we actually use &(time_t) */ #if defined(BSD) && !defined(POSIX_TYPES) -# define TIME_type long * +#define TIME_type long * #else -# define TIME_type time_t * +#define TIME_type time_t * #endif /* LOCALTIME_type: type of the argument to localtime() */ -#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || (defined(BSD) && !defined(POSIX_TYPES)) -# define LOCALTIME_type long * +#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) \ + || (defined(BSD) && !defined(POSIX_TYPES)) +#define LOCALTIME_type long * #else -# define LOCALTIME_type time_t * +#define LOCALTIME_type time_t * #endif -#if defined(AMIGA) && !defined(AZTEC_C) && !defined(__SASC_60) && !defined(_DCC) && !defined(__GNUC__) -extern struct tm *FDECL(localtime,(time_t *)); +#if defined(AMIGA) && !defined(AZTEC_C) && !defined(__SASC_60) \ + && !defined(_DCC) && !defined(__GNUC__) +extern struct tm *FDECL(localtime, (time_t *)); #endif STATIC_DCL struct tm *NDECL(getlt); void setrandom() { - unsigned long seed = (unsigned long)getnow(); /* time((TIME_type) 0) */ + unsigned long seed = (unsigned long) getnow(); /* time((TIME_type) 0) */ #ifdef UNIX - /* Quick dirty band-aid to prevent PRNG prediction */ - seed *= getpid(); + /* Quick dirty band-aid to prevent PRNG prediction */ + seed *= getpid(); #endif - /* the types are different enough here that sweeping the different - * routine names into one via #defines is even more confusing - */ -#ifdef RANDOM /* srandom() from sys/share/random.c */ - srandom((unsigned int) seed); +/* the types are different enough here that sweeping the different + * routine names into one via #defines is even more confusing + */ +#ifdef RANDOM /* srandom() from sys/share/random.c */ + srandom((unsigned int) seed); #else -# if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */ -# if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4) - (void) -# endif - srandom((int) seed); -# else -# ifdef UNIX /* system srand48() */ - srand48((long) seed); -# else /* poor quality system routine */ - srand((int) seed); -# endif -# endif +#if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) \ + || defined(CYGWIN32) /* system srandom() */ +#if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4) + (void) +#endif + srandom((int) seed); +#else +#ifdef UNIX /* system srand48() */ + srand48((long) seed); +#else /* poor quality system routine */ + srand((int) seed); +#endif +#endif #endif } time_t getnow() { - time_t datetime = 0; + time_t datetime = 0; - (void) time((TIME_type) &datetime); - return datetime; + (void) time((TIME_type) &datetime); + return datetime; } STATIC_OVL struct tm * getlt() { - time_t date = getnow(); + time_t date = getnow(); - return localtime((LOCALTIME_type) &date); + return localtime((LOCALTIME_type) &date); } int getyear() { - return(1900 + getlt()->tm_year); + return (1900 + getlt()->tm_year); } #if 0 @@ -722,124 +743,124 @@ long yyyymmdd(date) time_t date; { - long datenum; - struct tm *lt; + long datenum; + struct tm *lt; - if (date == 0) - lt = getlt(); - else - lt = localtime((LOCALTIME_type) &date); + if (date == 0) + lt = getlt(); + else + lt = localtime((LOCALTIME_type) &date); - /* just in case somebody's localtime supplies (year % 100) - rather than the expected (year - 1900) */ - if (lt->tm_year < 70) - datenum = (long)lt->tm_year + 2000L; - else - datenum = (long)lt->tm_year + 1900L; - /* yyyy --> yyyymm */ - datenum = datenum * 100L + (long)(lt->tm_mon + 1); - /* yyyymm --> yyyymmdd */ - datenum = datenum * 100L + (long)lt->tm_mday; - return datenum; + /* just in case somebody's localtime supplies (year % 100) + rather than the expected (year - 1900) */ + if (lt->tm_year < 70) + datenum = (long) lt->tm_year + 2000L; + else + datenum = (long) lt->tm_year + 1900L; + /* yyyy --> yyyymm */ + datenum = datenum * 100L + (long) (lt->tm_mon + 1); + /* yyyymm --> yyyymmdd */ + datenum = datenum * 100L + (long) lt->tm_mday; + return datenum; } long hhmmss(date) time_t date; { - long timenum; - struct tm *lt; + long timenum; + struct tm *lt; - if (date == 0) - lt = getlt(); - else - lt = localtime((LOCALTIME_type) &date); + if (date == 0) + lt = getlt(); + else + lt = localtime((LOCALTIME_type) &date); - timenum = lt->tm_hour * 10000L + lt->tm_min * 100L + lt->tm_sec; - return timenum; + timenum = lt->tm_hour * 10000L + lt->tm_min * 100L + lt->tm_sec; + return timenum; } char * yyyymmddhhmmss(date) time_t date; { - long datenum; - static char datestr[15]; - struct tm *lt; + long datenum; + static char datestr[15]; + struct tm *lt; - if (date == 0) - lt = getlt(); - else -#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || defined(BSD) - lt = localtime((long *)(&date)); + if (date == 0) + lt = getlt(); + else +#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) \ + || defined(BSD) + lt = localtime((long *) (&date)); #else - lt = localtime(&date); + lt = localtime(&date); #endif - /* just in case somebody's localtime supplies (year % 100) - rather than the expected (year - 1900) */ - if (lt->tm_year < 70) - datenum = (long)lt->tm_year + 2000L; - else - datenum = (long)lt->tm_year + 1900L; - Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", - datenum, lt->tm_mon + 1, lt->tm_mday, - lt->tm_hour, lt->tm_min, lt->tm_sec); - debugpline1("yyyymmddhhmmss() produced date string %s", datestr); - return(datestr); + /* just in case somebody's localtime supplies (year % 100) + rather than the expected (year - 1900) */ + if (lt->tm_year < 70) + datenum = (long) lt->tm_year + 2000L; + else + datenum = (long) lt->tm_year + 1900L; + Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1, + lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); + debugpline1("yyyymmddhhmmss() produced date string %s", datestr); + return (datestr); } time_t time_from_yyyymmddhhmmss(buf) char *buf; { - int k; - time_t timeresult = (time_t)0; - struct tm t, *lt; - char *g, *p, y[5],mo[3],md[3],h[3],mi[3],s[3]; - if (buf && strlen(buf) == 14) { - g = buf; - p = y; /* year */ - for (k = 0; k < 4; ++k) - *p++ = *g++; - *p = '\0'; - p = mo; /* month */ - for (k = 0; k < 2; ++k) - *p++ = *g++; - *p = '\0'; - p = md; /* day */ - for (k = 0; k < 2; ++k) - *p++ = *g++; - *p = '\0'; - p = h; /* hour */ - for (k = 0; k < 2; ++k) - *p++ = *g++; - *p = '\0'; - p = mi; /* minutes */ - for (k = 0; k < 2; ++k) - *p++ = *g++; - *p = '\0'; - p = s; /* seconds */ - for (k = 0; k < 2; ++k) - *p++ = *g++; - *p = '\0'; - lt = getlt(); - if (lt) { - t = *lt; - t.tm_year = atoi(y) - 1900; - t.tm_mon = atoi(mo) - 1; - t.tm_mday = atoi(md); - t.tm_hour = atoi(h); - t.tm_min = atoi(mi); - t.tm_sec = atoi(s); - timeresult = mktime(&t); - } - if ((int)timeresult == -1) - debugpline1("time_from_yyyymmddhhmmss(%s) would have returned -1", - buf ? buf : ""); - else - return timeresult; - } - return (time_t)0; + int k; + time_t timeresult = (time_t) 0; + struct tm t, *lt; + char *g, *p, y[5], mo[3], md[3], h[3], mi[3], s[3]; + if (buf && strlen(buf) == 14) { + g = buf; + p = y; /* year */ + for (k = 0; k < 4; ++k) + *p++ = *g++; + *p = '\0'; + p = mo; /* month */ + for (k = 0; k < 2; ++k) + *p++ = *g++; + *p = '\0'; + p = md; /* day */ + for (k = 0; k < 2; ++k) + *p++ = *g++; + *p = '\0'; + p = h; /* hour */ + for (k = 0; k < 2; ++k) + *p++ = *g++; + *p = '\0'; + p = mi; /* minutes */ + for (k = 0; k < 2; ++k) + *p++ = *g++; + *p = '\0'; + p = s; /* seconds */ + for (k = 0; k < 2; ++k) + *p++ = *g++; + *p = '\0'; + lt = getlt(); + if (lt) { + t = *lt; + t.tm_year = atoi(y) - 1900; + t.tm_mon = atoi(mo) - 1; + t.tm_mday = atoi(md); + t.tm_hour = atoi(h); + t.tm_min = atoi(mi); + t.tm_sec = atoi(s); + timeresult = mktime(&t); + } + if ((int) timeresult == -1) + debugpline1("time_from_yyyymmddhhmmss(%s) would have returned -1", + buf ? buf : ""); + else + return timeresult; + } + return (time_t) 0; } /* @@ -855,41 +876,40 @@ char *buf; * 177 ~= 8 reported phases * 22 * + 11/22 for rounding */ -int -phase_of_the_moon() /* 0-7, with 0: new, 4: full */ +int phase_of_the_moon() /* 0-7, with 0: new, 4: full */ { - register struct tm *lt = getlt(); - register int epact, diy, goldn; + register struct tm *lt = getlt(); + register int epact, diy, goldn; - diy = lt->tm_yday; - goldn = (lt->tm_year % 19) + 1; - epact = (11 * goldn + 18) % 30; - if ((epact == 25 && goldn > 11) || epact == 24) - epact++; + diy = lt->tm_yday; + goldn = (lt->tm_year % 19) + 1; + epact = (11 * goldn + 18) % 30; + if ((epact == 25 && goldn > 11) || epact == 24) + epact++; - return( (((((diy + epact) * 6) + 11) % 177) / 22) & 7 ); + return ((((((diy + epact) * 6) + 11) % 177) / 22) & 7); } boolean friday_13th() { - register struct tm *lt = getlt(); + register struct tm *lt = getlt(); - return((boolean)(lt->tm_wday == 5 /* friday */ && lt->tm_mday == 13)); + return ((boolean)(lt->tm_wday == 5 /* friday */ && lt->tm_mday == 13)); } int night() { - register int hour = getlt()->tm_hour; + register int hour = getlt()->tm_hour; - return(hour < 6 || hour > 21); + return (hour < 6 || hour > 21); } int midnight() { - return(getlt()->tm_hour == 0); + return (getlt()->tm_hour == 0); } /*hacklib.c*/ diff --git a/src/invent.c b/src/invent.c index 0808a51c3..42986ade3 100644 --- a/src/invent.c +++ b/src/invent.c @@ -4,35 +4,36 @@ #include "hack.h" -#define NOINVSYM '#' -#define CONTAINED_SYM '>' /* designator for inside a container */ +#define NOINVSYM '#' +#define CONTAINED_SYM '>' /* designator for inside a container */ STATIC_DCL int FDECL(sortloot_cmp, (struct obj *, struct obj *)); STATIC_DCL void NDECL(reorder_invent); -STATIC_DCL boolean FDECL(mergable,(struct obj *,struct obj *)); +STATIC_DCL boolean FDECL(mergable, (struct obj *, struct obj *)); STATIC_DCL void FDECL(noarmor, (BOOLEAN_P)); -STATIC_DCL void FDECL(invdisp_nothing, (const char *,const char *)); +STATIC_DCL void FDECL(invdisp_nothing, (const char *, const char *)); STATIC_DCL boolean FDECL(worn_wield_only, (struct obj *)); STATIC_DCL boolean FDECL(only_here, (struct obj *)); -STATIC_DCL void FDECL(compactify,(char *)); +STATIC_DCL void FDECL(compactify, (char *)); STATIC_DCL boolean FDECL(splittable, (struct obj *)); STATIC_DCL boolean FDECL(taking_off, (const char *)); STATIC_DCL boolean FDECL(putting_on, (const char *)); -STATIC_PTR int FDECL(ckunpaid,(struct obj *)); -STATIC_PTR int FDECL(ckvalidcat,(struct obj *)); +STATIC_PTR int FDECL(ckunpaid, (struct obj *)); +STATIC_PTR int FDECL(ckvalidcat, (struct obj *)); STATIC_PTR char *FDECL(safeq_xprname, (struct obj *)); STATIC_PTR char *FDECL(safeq_shortxprname, (struct obj *)); -STATIC_DCL char FDECL(display_pickinv, (const char *,BOOLEAN_P, long *)); +STATIC_DCL char FDECL(display_pickinv, (const char *, BOOLEAN_P, long *)); STATIC_DCL char FDECL(display_used_invlets, (CHAR_P)); -STATIC_DCL void FDECL(tally_BUCX, (struct obj *,int *,int *,int *,int *,int *)); +STATIC_DCL void FDECL(tally_BUCX, + (struct obj *, int *, int *, int *, int *, int *)); STATIC_DCL boolean FDECL(this_type_only, (struct obj *)); STATIC_DCL void NDECL(dounpaid); -STATIC_DCL struct obj *FDECL(find_unpaid,(struct obj *,struct obj **)); +STATIC_DCL struct obj *FDECL(find_unpaid, (struct obj *, struct obj **)); STATIC_DCL void FDECL(menu_identify, (int)); STATIC_DCL boolean FDECL(tool_in_use, (struct obj *)); -STATIC_DCL char FDECL(obj_to_let,(struct obj *)); +STATIC_DCL char FDECL(obj_to_let, (struct obj *)); -static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */ +static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */ /* wizards can wish for venom, which will become an invisible inventory * item without this. putting it in inv_order would mean venom would @@ -41,68 +42,76 @@ static int lastinvnr = 51; /* 0 ... 51 (never saved&restored) */ * is only WIZARD and not wizard because the wizard can leave venom lying * around on a bones level for normal players to find. */ -static char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ - +static char venom_inv[] = { VENOM_CLASS, 0 }; /* (constant) */ int sortloot_cmp(obj1, obj2) struct obj *obj1; struct obj *obj2; { - int val1 = 0; - int val2 = 0; + int val1 = 0; + int val2 = 0; - /* Sort object names in lexicographical order, ignoring quantity. */ - int name_cmp = strcmpi(cxname_singular(obj1), cxname_singular(obj2)); + /* Sort object names in lexicographical order, ignoring quantity. */ + int name_cmp = strcmpi(cxname_singular(obj1), cxname_singular(obj2)); - if (name_cmp != 0) { - return name_cmp; - } + if (name_cmp != 0) { + return name_cmp; + } - /* Sort by BUC. Map blessed to 4, uncursed to 2, cursed to 1, and unknown to 0. */ - val1 = obj1->bknown ? (obj1->blessed << 2) + ((!obj1->blessed && !obj1->cursed) << 1) + obj1->cursed : 0; - val2 = obj2->bknown ? (obj2->blessed << 2) + ((!obj2->blessed && !obj2->cursed) << 1) + obj2->cursed : 0; - if (val1 != val2) { - return val2 - val1; /* Because bigger is better. */ - } + /* Sort by BUC. Map blessed to 4, uncursed to 2, cursed to 1, and unknown + * to 0. */ + val1 = obj1->bknown + ? (obj1->blessed << 2) + + ((!obj1->blessed && !obj1->cursed) << 1) + obj1->cursed + : 0; + val2 = obj2->bknown + ? (obj2->blessed << 2) + + ((!obj2->blessed && !obj2->cursed) << 1) + obj2->cursed + : 0; + if (val1 != val2) { + return val2 - val1; /* Because bigger is better. */ + } - /* Sort by greasing. This will put the objects in degreasing order. */ - val1 = obj1->greased; - val2 = obj2->greased; - if (val1 != val2) { - return val2 - val1; /* Because bigger is better. */ - } + /* Sort by greasing. This will put the objects in degreasing order. */ + val1 = obj1->greased; + val2 = obj2->greased; + if (val1 != val2) { + return val2 - val1; /* Because bigger is better. */ + } - /* Sort by erosion. The effective amount is what matters. */ - val1 = greatest_erosion(obj1); - val2 = greatest_erosion(obj2); - if (val1 != val2) { - return val1 - val2; /* Because bigger is WORSE. */ - } + /* Sort by erosion. The effective amount is what matters. */ + val1 = greatest_erosion(obj1); + val2 = greatest_erosion(obj2); + if (val1 != val2) { + return val1 - val2; /* Because bigger is WORSE. */ + } - /* Sort by erodeproofing. Map known-invulnerable to 1, and both - * known-vulnerable and unknown-vulnerability to 0, because that's how they're displayed. */ - val1 = obj1->rknown && obj1->oerodeproof; - val2 = obj2->rknown && obj2->oerodeproof; - if (val1 != val2) { - return val2 - val1; /* Because bigger is better. */ - } + /* Sort by erodeproofing. Map known-invulnerable to 1, and both + * known-vulnerable and unknown-vulnerability to 0, because that's how + * they're displayed. */ + val1 = obj1->rknown && obj1->oerodeproof; + val2 = obj2->rknown && obj2->oerodeproof; + if (val1 != val2) { + return val2 - val1; /* Because bigger is better. */ + } - /* Sort by enchantment. Map unknown to -1000, which is comfortably below the range of ->spe. */ - val1 = obj1->known ? obj1->spe : -1000; - val2 = obj2->known ? obj2->spe : -1000; - if (val1 != val2) { - return val2 - val1; /* Because bigger is better. */ - } + /* Sort by enchantment. Map unknown to -1000, which is comfortably below + * the range of ->spe. */ + val1 = obj1->known ? obj1->spe : -1000; + val2 = obj2->known ? obj2->spe : -1000; + if (val1 != val2) { + return val2 - val1; /* Because bigger is better. */ + } - return 0; /* They're identical, as far as we're concerned. */ + return 0; /* They're identical, as far as we're concerned. */ } struct obj ** objarr_init(n) int n; { - return (struct obj **)alloc(n * sizeof(struct obj *)); + return (struct obj **) alloc(n * sizeof(struct obj *)); } void @@ -113,18 +122,18 @@ struct obj **oarray; boolean dosort; { if (dosort) { - int j; - for (j = idx; j; j--) { - if (sortloot_cmp(otmp, oarray[j-1]) > 0) break; - oarray[j] = oarray[j-1]; - } - oarray[j] = otmp; + int j; + for (j = idx; j; j--) { + if (sortloot_cmp(otmp, oarray[j - 1]) > 0) + break; + oarray[j] = oarray[j - 1]; + } + oarray[j] = otmp; } else { - oarray[idx] = otmp; + oarray[idx] = otmp; } } - void assigninvlet(otmp) register struct obj *otmp; @@ -133,28 +142,37 @@ register struct obj *otmp; register int i; register struct obj *obj; - /* there should be at most one of these in inventory... */ + /* there should be at most one of these in inventory... */ if (otmp->oclass == COIN_CLASS) { otmp->invlet = GOLD_SYM; return; } - for(i = 0; i < 52; i++) inuse[i] = FALSE; - for(obj = invent; obj; obj = obj->nobj) if(obj != otmp) { - i = obj->invlet; - if('a' <= i && i <= 'z') inuse[i - 'a'] = TRUE; else - if('A' <= i && i <= 'Z') inuse[i - 'A' + 26] = TRUE; - if(i == otmp->invlet) otmp->invlet = 0; - } - if((i = otmp->invlet) && - (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) + for (i = 0; i < 52; i++) + inuse[i] = FALSE; + for (obj = invent; obj; obj = obj->nobj) + if (obj != otmp) { + i = obj->invlet; + if ('a' <= i && i <= 'z') + inuse[i - 'a'] = TRUE; + else if ('A' <= i && i <= 'Z') + inuse[i - 'A' + 26] = TRUE; + if (i == otmp->invlet) + otmp->invlet = 0; + } + if ((i = otmp->invlet) + && (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) return; - for(i = lastinvnr+1; i != lastinvnr; i++) { - if(i == 52) { i = -1; continue; } - if(!inuse[i]) break; + for (i = lastinvnr + 1; i != lastinvnr; i++) { + if (i == 52) { + i = -1; + continue; + } + if (!inuse[i]) + break; } - otmp->invlet = (inuse[i] ? NOINVSYM : - (i < 26) ? ('a'+i) : ('A'+i-26)); + otmp->invlet = + (inuse[i] ? NOINVSYM : (i < 26) ? ('a' + i) : ('A' + i - 26)); lastinvnr = i; } @@ -174,19 +192,21 @@ reorder_invent() * isn't nearly as inefficient as it may first appear. */ need_more_sorting = FALSE; - for (otmp = invent, prev = 0; otmp; ) { - next = otmp->nobj; - if (next && inv_rank(next) < inv_rank(otmp)) { - need_more_sorting = TRUE; - if (prev) prev->nobj = next; - else invent = next; - otmp->nobj = next->nobj; - next->nobj = otmp; - prev = next; - } else { - prev = otmp; - otmp = next; - } + for (otmp = invent, prev = 0; otmp;) { + next = otmp->nobj; + if (next && inv_rank(next) < inv_rank(otmp)) { + need_more_sorting = TRUE; + if (prev) + prev->nobj = next; + else + invent = next; + otmp->nobj = next->nobj; + next->nobj = otmp; + prev = next; + } else { + prev = otmp; + otmp = next; + } } } while (need_more_sorting); } @@ -203,15 +223,16 @@ struct obj *objlist, *obj; struct monst *shkp; int save_nocharge; - if (obj->otyp == SCR_SCARE_MONSTER) /* punt on these */ - return (struct obj *)0; + if (obj->otyp == SCR_SCARE_MONSTER) /* punt on these */ + return (struct obj *) 0; /* if this is an item on the shop floor, the attributes it will have when carried are different from what they are now; prevent that from eliciting an incorrect result from mergable() */ save_nocharge = obj->no_charge; - if (objlist == invent && obj->where == OBJ_FLOOR && - (shkp = shop_keeper(inside_shop(obj->ox, obj->oy))) != 0) { - if (obj->no_charge) obj->no_charge = 0; + if (objlist == invent && obj->where == OBJ_FLOOR + && (shkp = shop_keeper(inside_shop(obj->ox, obj->oy))) != 0) { + if (obj->no_charge) + obj->no_charge = 0; /* A billable object won't have its `unpaid' bit set, so would erroneously seem to be a candidate to merge with a similar ordinary object. That's no good, because once it's really @@ -219,10 +240,12 @@ struct obj *objlist, *obj; another unpaid object, but we can't check that here (depends too much upon shk's bill) and if it doesn't merge it would end up in the '#' overflow inventory slot, so reject it now. */ - else if (inhishop(shkp)) return (struct obj *)0; + else if (inhishop(shkp)) + return (struct obj *) 0; } while (objlist) { - if (mergable(objlist, obj)) break; + if (mergable(objlist, obj)) + break; objlist = objlist->nobj; } obj->no_charge = save_nocharge; @@ -236,7 +259,7 @@ struct obj **potmp, **pobj; { register struct obj *otmp = *potmp, *obj = *pobj; - if(mergable(otmp, obj)) { + if (mergable(otmp, obj)) { /* Approximate age: we do it this way because if we were to * do it "accurately" (merge only when ages are identical) * we'd wind up never merging any corpses. @@ -247,21 +270,25 @@ struct obj **potmp, **pobj; * then restart the burn. */ if (!obj->lamplit) - otmp->age = ((otmp->age*otmp->quan) + (obj->age*obj->quan)) - / (otmp->quan + obj->quan); + otmp->age = ((otmp->age * otmp->quan) + (obj->age * obj->quan)) + / (otmp->quan + obj->quan); otmp->quan += obj->quan; /* temporary special case for gold objects!!!! */ - if (otmp->oclass == COIN_CLASS) otmp->owt = weight(otmp); + if (otmp->oclass == COIN_CLASS) + otmp->owt = weight(otmp); /* and puddings!!!1!!one! */ - else if (!Is_pudding(otmp)) otmp->owt += obj->owt; - if(!has_oname(otmp) && has_oname(obj)) + else if (!Is_pudding(otmp)) + otmp->owt += obj->owt; + if (!has_oname(otmp) && has_oname(obj)) otmp = *potmp = oname(otmp, ONAME(obj)); obj_extract_self(obj); /* really should merge the timeouts */ - if (obj->lamplit) obj_merge_light_sources(obj, otmp); - if (obj->timed) obj_stop_timers(obj); /* follows lights */ + if (obj->lamplit) + obj_merge_light_sources(obj, otmp); + if (obj->timed) + obj_stop_timers(obj); /* follows lights */ /* fixup for `#adjust' merging wielded darts, daggers, &c */ if (obj->owornmask && carried(otmp)) { @@ -275,14 +302,18 @@ struct obj **potmp, **pobj; (Prior to 3.3.0, it was not possible for the two stacks to be worn in different slots and `obj' didn't need to be unworn when merging.) */ - if (wmask & W_WEP) wmask = W_WEP; - else if (wmask & W_SWAPWEP) wmask = W_SWAPWEP; - else if (wmask & W_QUIVER) wmask = W_QUIVER; + if (wmask & W_WEP) + wmask = W_WEP; + else if (wmask & W_SWAPWEP) + wmask = W_SWAPWEP; + else if (wmask & W_QUIVER) + wmask = W_QUIVER; else { - impossible("merging strangely worn items (%lx)", wmask); - wmask = otmp->owornmask; + impossible("merging strangely worn items (%lx)", wmask); + wmask = otmp->owornmask; } - if ((otmp->owornmask & ~wmask) != 0L) setnotworn(otmp); + if ((otmp->owornmask & ~wmask) != 0L) + setnotworn(otmp); setworn(otmp, wmask); setnotworn(obj); } @@ -299,16 +330,16 @@ struct obj **potmp, **pobj; #endif /*0*/ /* handle puddings a bit differently; absorption will - * free the other object automatically so we can just + * free the other object automatically so we can just * return out from here. */ if (Is_pudding(obj)) { pudding_merge_message(otmp, obj); obj_absorb(potmp, pobj); - return(1); + return (1); } - obfree(obj,otmp); /* free(obj), bill->otmp */ - return(1); + obfree(obj, otmp); /* free(obj), bill->otmp */ + return (1); } return 0; } @@ -331,39 +362,43 @@ struct obj *obj; if (obj->oclass == COIN_CLASS) { context.botl = 1; } else if (obj->otyp == AMULET_OF_YENDOR) { - if (u.uhave.amulet) impossible("already have amulet?"); + if (u.uhave.amulet) + impossible("already have amulet?"); u.uhave.amulet = 1; - u.uachieve.amulet = 1; + u.uachieve.amulet = 1; } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) { - if (u.uhave.menorah) impossible("already have candelabrum?"); + if (u.uhave.menorah) + impossible("already have candelabrum?"); u.uhave.menorah = 1; - u.uachieve.menorah = 1; + u.uachieve.menorah = 1; } else if (obj->otyp == BELL_OF_OPENING) { - if (u.uhave.bell) impossible("already have silver bell?"); + if (u.uhave.bell) + impossible("already have silver bell?"); u.uhave.bell = 1; - u.uachieve.bell = 1; + u.uachieve.bell = 1; } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - if (u.uhave.book) impossible("already have the book?"); + if (u.uhave.book) + impossible("already have the book?"); u.uhave.book = 1; - u.uachieve.book = 1; + u.uachieve.book = 1; } else if (obj->oartifact) { if (is_quest_artifact(obj)) { if (u.uhave.questart) - impossible("already have quest artifact?"); + impossible("already have quest artifact?"); u.uhave.questart = 1; artitouch(obj); } set_artifact_intrinsic(obj, 1, W_ART); } - if(obj->otyp == LUCKSTONE && obj->record_achieve_special) { - u.uachieve.mines_luckstone = 1; - obj->record_achieve_special = 0; - } else if((obj->otyp == AMULET_OF_REFLECTION || - obj->otyp == BAG_OF_HOLDING) && - obj->record_achieve_special) { - u.uachieve.finish_sokoban = 1; - obj->record_achieve_special = 0; - } + if (obj->otyp == LUCKSTONE && obj->record_achieve_special) { + u.uachieve.mines_luckstone = 1; + obj->record_achieve_special = 0; + } else if ((obj->otyp == AMULET_OF_REFLECTION + || obj->otyp == BAG_OF_HOLDING) + && obj->record_achieve_special) { + u.uachieve.finish_sokoban = 1; + obj->record_achieve_special = 0; + } } /* @@ -395,15 +430,16 @@ addinv(obj) struct obj *obj; { struct obj *otmp, *prev; - int saved_otyp = (int)obj->otyp; /* for panic */ + int saved_otyp = (int) obj->otyp; /* for panic */ if (obj->where != OBJ_FREE) panic("addinv: obj not free"); /* normally addtobill() clears no_charge when items in a shop are picked up, but won't do so if the shop has become untended */ - obj->no_charge = 0; /* should not be set in hero's invent */ - if (Has_contents(obj)) picked_container(obj); /* clear no_charge */ - obj->was_thrown = 0; /* not meaningful for invent */ + obj->no_charge = 0; /* should not be set in hero's invent */ + if (Has_contents(obj)) + picked_container(obj); /* clear no_charge */ + obj->was_thrown = 0; /* not meaningful for invent */ addinv_core1(obj); @@ -419,28 +455,29 @@ struct obj *obj; /* merge if possible; find end of chain in the process */ for (prev = 0, otmp = invent; otmp; prev = otmp, otmp = otmp->nobj) if (merged(&otmp, &obj)) { - obj = otmp; - if (!obj) - panic("addinv: null obj after merge otyp=%d", saved_otyp); - goto added; + obj = otmp; + if (!obj) + panic("addinv: null obj after merge otyp=%d", saved_otyp); + goto added; } /* didn't merge, so insert into chain */ assigninvlet(obj); if (flags.invlet_constant || !prev) { - obj->nobj = invent; /* insert at beginning */ + obj->nobj = invent; /* insert at beginning */ invent = obj; - if (flags.invlet_constant) reorder_invent(); + if (flags.invlet_constant) + reorder_invent(); } else { - prev->nobj = obj; /* insert at end */ + prev->nobj = obj; /* insert at end */ obj->nobj = 0; } obj->where = OBJ_INVENT; added: addinv_core2(obj); - carry_obj_effects(obj); /* carrying affects the obj */ + carry_obj_effects(obj); /* carrying affects the obj */ update_inventory(); - return(obj); + return (obj); } /* @@ -456,11 +493,10 @@ struct obj *obj; /* Cursed figurines can spontaneously transform when carried. */ if (obj->otyp == FIGURINE) { - if (obj->cursed - && obj->corpsenm != NON_PM - && !dead_species(obj->corpsenm,TRUE)) { + if (obj->cursed && obj->corpsenm != NON_PM + && !dead_species(obj->corpsenm, TRUE)) { attach_fig_transform_timeout(obj); - } + } } } @@ -478,7 +514,8 @@ const char *drop_fmt, *drop_arg, *hold_msg; { char buf[BUFSZ]; - if (!Blind) obj->dknown = 1; /* maximize mergibility */ + if (!Blind) + obj->dknown = 1; /* maximize mergibility */ if (obj->oartifact) { /* place_object may change these */ boolean crysknife = (obj->otyp == CRYSKNIFE); @@ -489,51 +526,56 @@ const char *drop_fmt, *drop_arg, *hold_msg; place_object(obj, u.ux, u.uy); if (!touch_artifact(obj, &youmonst)) { - obj_extract_self(obj); /* remove it from the floor */ - dropy(obj); /* now put it back again :-) */ - return obj; + obj_extract_self(obj); /* remove it from the floor */ + dropy(obj); /* now put it back again :-) */ + return obj; } else if (wasUpolyd && !Upolyd) { - /* loose your grip if you revert your form */ - if (drop_fmt) pline(drop_fmt, drop_arg); - obj_extract_self(obj); - dropy(obj); - return obj; + /* loose your grip if you revert your form */ + if (drop_fmt) + pline(drop_fmt, drop_arg); + obj_extract_self(obj); + dropy(obj); + return obj; } obj_extract_self(obj); if (crysknife) { - obj->otyp = CRYSKNIFE; - obj->oerodeproof = oerode; + obj->otyp = CRYSKNIFE; + obj->oerodeproof = oerode; } } if (Fumbling) { - if (drop_fmt) pline(drop_fmt, drop_arg); + if (drop_fmt) + pline(drop_fmt, drop_arg); dropy(obj); } else { long oquan = obj->quan; - int prev_encumbr = near_capacity(); /* before addinv() */ + int prev_encumbr = near_capacity(); /* before addinv() */ /* encumbrance only matters if it would now become worse than max( current_value, stressed ) */ - if (prev_encumbr < MOD_ENCUMBER) prev_encumbr = MOD_ENCUMBER; + if (prev_encumbr < MOD_ENCUMBER) + prev_encumbr = MOD_ENCUMBER; /* addinv() may redraw the entire inventory, overwriting drop_arg when it comes from something like doname() */ - if (drop_arg) drop_arg = strcpy(buf, drop_arg); + if (drop_arg) + drop_arg = strcpy(buf, drop_arg); obj = addinv(obj); - if (inv_cnt(FALSE) > 52 - || ((obj->otyp != LOADSTONE || !obj->cursed) - && near_capacity() > prev_encumbr)) { - if (drop_fmt) pline(drop_fmt, drop_arg); - /* undo any merge which took place */ - if (obj->quan > oquan) obj = splitobj(obj, oquan); - dropx(obj); + if (inv_cnt(FALSE) > 52 || ((obj->otyp != LOADSTONE || !obj->cursed) + && near_capacity() > prev_encumbr)) { + if (drop_fmt) + pline(drop_fmt, drop_arg); + /* undo any merge which took place */ + if (obj->quan > oquan) + obj = splitobj(obj, oquan); + dropx(obj); } else { - if (flags.autoquiver && !uquiver && !obj->owornmask && - (is_missile(obj) || - ammo_and_launcher(obj, uwep) || - ammo_and_launcher(obj, uswapwep))) - setuqwep(obj); - if (hold_msg || drop_fmt) prinv(hold_msg, obj, oquan); + if (flags.autoquiver && !uquiver && !obj->owornmask + && (is_missile(obj) || ammo_and_launcher(obj, uwep) + || ammo_and_launcher(obj, uswapwep))) + setuqwep(obj); + if (hold_msg || drop_fmt) + prinv(hold_msg, obj, oquan); } } return obj; @@ -546,7 +588,7 @@ struct obj *obj; { setnotworn(obj); freeinv(obj); - obfree(obj, (struct obj *)0); /* deletes contents also */ + obfree(obj, (struct obj *) 0); /* deletes contents also */ } void @@ -556,7 +598,7 @@ register struct obj *obj; /* Note: This works correctly for containers because they */ /* (containers) don't merge. */ if (obj->quan > 1L) { - obj->in_use = FALSE; /* no longer in use */ + obj->in_use = FALSE; /* no longer in use */ obj->quan--; obj->owt = weight(obj); update_inventory(); @@ -569,11 +611,13 @@ register struct obj *obj; void consume_obj_charge(obj, maybe_unpaid) struct obj *obj; -boolean maybe_unpaid; /* false if caller handles shop billing */ +boolean maybe_unpaid; /* false if caller handles shop billing */ { - if (maybe_unpaid) check_unpaid(obj); + if (maybe_unpaid) + check_unpaid(obj); obj->spe -= 1; - if (obj->known) update_inventory(); + if (obj->known) + update_inventory(); } /* @@ -591,21 +635,25 @@ struct obj *obj; context.botl = 1; return; } else if (obj->otyp == AMULET_OF_YENDOR) { - if (!u.uhave.amulet) impossible("don't have amulet?"); + if (!u.uhave.amulet) + impossible("don't have amulet?"); u.uhave.amulet = 0; } else if (obj->otyp == CANDELABRUM_OF_INVOCATION) { - if (!u.uhave.menorah) impossible("don't have candelabrum?"); + if (!u.uhave.menorah) + impossible("don't have candelabrum?"); u.uhave.menorah = 0; } else if (obj->otyp == BELL_OF_OPENING) { - if (!u.uhave.bell) impossible("don't have silver bell?"); + if (!u.uhave.bell) + impossible("don't have silver bell?"); u.uhave.bell = 0; } else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - if (!u.uhave.book) impossible("don't have the book?"); + if (!u.uhave.book) + impossible("don't have the book?"); u.uhave.book = 0; } else if (obj->oartifact) { if (is_quest_artifact(obj)) { if (!u.uhave.questart) - impossible("don't have quest artifact?"); + impossible("don't have quest artifact?"); u.uhave.questart = 0; } set_artifact_intrinsic(obj, 0, W_ART); @@ -655,10 +703,10 @@ register struct obj *obj; { boolean update_map; - if (obj->otyp == AMULET_OF_YENDOR || - obj->otyp == CANDELABRUM_OF_INVOCATION || - obj->otyp == BELL_OF_OPENING || - obj->otyp == SPE_BOOK_OF_THE_DEAD) { + if (obj->otyp == AMULET_OF_YENDOR + || obj->otyp == CANDELABRUM_OF_INVOCATION + || obj->otyp == BELL_OF_OPENING + || obj->otyp == SPE_BOOK_OF_THE_DEAD) { /* player might be doing something stupid, but we * can't guarantee that. assume special artifacts * are indestructible via drawbridges, and exploding @@ -668,8 +716,9 @@ register struct obj *obj; } update_map = (obj->where == OBJ_FLOOR); obj_extract_self(obj); - if (update_map) newsym(obj->ox, obj->oy); - obfree(obj, (struct obj *) 0); /* frees contents also */ + if (update_map) + newsym(obj->ox, obj->oy); + obfree(obj, (struct obj *) 0); /* frees contents also */ } /* try to find a particular type of object at designated map location */ @@ -681,7 +730,8 @@ int x, y; register struct obj *otmp; for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (otmp->otyp == otyp) break; + if (otmp->otyp == otyp) + break; return otmp; } @@ -695,10 +745,11 @@ boolean by_nexthere; { register struct obj *otmp; - otmp = obj; /* start with the object after this one */ + otmp = obj; /* start with the object after this one */ do { otmp = !by_nexthere ? otmp->nobj : otmp->nexthere; - if (!otmp) break; + if (!otmp) + break; } while (otmp->otyp != type); return otmp; @@ -710,43 +761,47 @@ register int type; { register struct obj *otmp; - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == type) - return(otmp); - return((struct obj *) 0); + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == type) + return (otmp); + return ((struct obj *) 0); } /** Fictional and not-so-fictional currencies. * http://concord.wikia.com/wiki/List_of_Fictional_Currencies */ -static const char * const currencies[] = { - "Altarian Dollar", /* The Hitchhiker's Guide to the Galaxy */ - "Ankh-Morpork Dollar", /* Discworld */ - "auric", /* The Domination of Draka */ - "buckazoid", /* Space Quest */ - "cirbozoid", /* Starslip */ - "credit chit", /* Deus Ex */ - "cubit", /* Battlestar Galactica */ - "Flanian Pobble Bead", /* The Hitchhiker's Guide to the Galaxy */ - "fretzer", /* Jules Verne */ - "imperial credit", /* Star Wars */ - "Hong Kong Luna Dollar",/* The Moon is a Harsh Mistress */ - "kongbuck", /* Snow Crash */ - "nanite", /* System Shock 2 */ - "quatloo", /* Sim City */ - "simoleon", /* Sim City */ - "solari", /* Spaceballs */ - "spacebuck", /* Spaceballs */ - "sporebuck", /* Spore */ - "Triganic Pu", /* The Hitchhiker's Guide to the Galaxy */ - "woolong", /* Cowboy Bebop */ +static const char *const currencies[] = { + "Altarian Dollar", /* The Hitchhiker's Guide to the Galaxy */ + "Ankh-Morpork Dollar", /* Discworld */ + "auric", /* The Domination of Draka */ + "buckazoid", /* Space Quest */ + "cirbozoid", /* Starslip */ + "credit chit", /* Deus Ex */ + "cubit", /* Battlestar Galactica */ + "Flanian Pobble Bead", /* The Hitchhiker's Guide to the Galaxy */ + "fretzer", /* Jules Verne */ + "imperial credit", /* Star Wars */ + "Hong Kong Luna Dollar", /* The Moon is a Harsh Mistress */ + "kongbuck", /* Snow Crash */ + "nanite", /* System Shock 2 */ + "quatloo", /* Sim City */ + "simoleon", /* Sim City */ + "solari", /* Spaceballs */ + "spacebuck", /* Spaceballs */ + "sporebuck", /* Spore */ + "Triganic Pu", /* The Hitchhiker's Guide to the Galaxy */ + "woolong", /* Cowboy Bebop */ }; const char * currency(amount) long amount; { - if (amount == 1L) return (Hallucination ? currencies[rn2(SIZE(currencies))] : "zorkmid"); - else return (Hallucination ? makeplural(currencies[rn2(SIZE(currencies))]) : "zorkmids"); + if (amount == 1L) + return (Hallucination ? currencies[rn2(SIZE(currencies))] + : "zorkmid"); + else + return (Hallucination ? makeplural(currencies[rn2(SIZE(currencies))]) + : "zorkmids"); } boolean @@ -754,10 +809,10 @@ have_lizard() { register struct obj *otmp; - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == CORPSE && otmp->corpsenm == PM_LIZARD) - return(TRUE); - return(FALSE); + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == CORPSE && otmp->corpsenm == PM_LIZARD) + return (TRUE); + return (FALSE); } struct obj * @@ -767,13 +822,14 @@ register struct obj *objchn; { struct obj *temp; - while(objchn) { - if(objchn->o_id == id) return(objchn); - if (Has_contents(objchn) && (temp = o_on(id,objchn->cobj))) + while (objchn) { + if (objchn->o_id == id) + return (objchn); + if (Has_contents(objchn) && (temp = o_on(id, objchn->cobj))) return temp; objchn = objchn->nobj; } - return((struct obj *) 0); + return ((struct obj *) 0); } boolean @@ -783,21 +839,23 @@ int x, y; { register struct obj *otmp; - for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if(obj == otmp) return(TRUE); - return(FALSE); + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (obj == otmp) + return (TRUE); + return (FALSE); } struct obj * -g_at(x,y) +g_at(x, y) register int x, y; { register struct obj *obj = level.objects[x][y]; - while(obj) { - if (obj->oclass == COIN_CLASS) return obj; + while (obj) { + if (obj->oclass == COIN_CLASS) + return obj; obj = obj->nexthere; } - return((struct obj *)0); + return ((struct obj *) 0); } STATIC_OVL void @@ -812,11 +870,11 @@ register char *buf; ilet1 = buf[1]; buf[++i2] = buf[++i1]; ilet = buf[i1]; - while(ilet) { - if(ilet == ilet1+1) { - if(ilet1 == ilet2+1) + while (ilet) { + if (ilet == ilet1 + 1) { + if (ilet1 == ilet2 + 1) buf[i2 - 1] = ilet1 = '-'; - else if(ilet2 == '-') { + else if (ilet2 == '-') { buf[i2 - 1] = ++ilet1; buf[i2] = buf[++i1]; ilet = buf[i1]; @@ -825,11 +883,10 @@ register char *buf; } else if (ilet == NOINVSYM) { /* compact three or more consecutive '#' characters into "#-#" */ - if (i2 >= 2 && buf[i2 - 2] == NOINVSYM && - buf[i2 - 1] == NOINVSYM) + if (i2 >= 2 && buf[i2 - 2] == NOINVSYM && buf[i2 - 1] == NOINVSYM) buf[i2 - 1] = '-'; - else if (i2 >= 3 && buf[i2 - 3] == NOINVSYM && - buf[i2 - 2] == '-' && buf[i2 - 1] == NOINVSYM) + else if (i2 >= 3 && buf[i2 - 3] == NOINVSYM && buf[i2 - 2] == '-' + && buf[i2 - 1] == NOINVSYM) --i2; } ilet2 = ilet1; @@ -844,8 +901,8 @@ STATIC_OVL boolean splittable(obj) struct obj *obj; { - return !((obj->otyp == LOADSTONE && obj->cursed) || - (obj == uwep && welded(uwep))); + return !((obj->otyp == LOADSTONE && obj->cursed) + || (obj == uwep && welded(uwep))); } /* match the prompt for either 'T' or 'R' command */ @@ -873,8 +930,8 @@ const char *action; !!!! may be able to remove "usegold" */ struct obj * -getobj(let,word) -register const char *let,*word; +getobj(let, word) +register const char *let, *word; { register struct obj *otmp; register char ilet; @@ -882,9 +939,9 @@ register const char *let,*word; char lets[BUFSZ], altlets[BUFSZ], *ap; register int foo = 0; register char *bp = buf; - xchar allowcnt = 0; /* 0, 1 or 2 */ + xchar allowcnt = 0; /* 0, 1 or 2 */ struct obj *firstobj = invent; - boolean usegold = FALSE; /* can't use gold because its illegal */ + boolean usegold = FALSE; /* can't use gold because its illegal */ boolean allowall = FALSE; boolean allownone = FALSE; boolean useboulder = FALSE; @@ -893,194 +950,210 @@ register const char *let,*word; boolean prezero; long dummymask; - if(*let == ALLOW_COUNT) let++, allowcnt = 1; - if(*let == COIN_CLASS) let++, usegold = TRUE; + if (*let == ALLOW_COUNT) + let++, allowcnt = 1; + if (*let == COIN_CLASS) + let++, usegold = TRUE; /* Equivalent of an "ugly check" for gold */ - if (usegold && !strcmp(word, "eat") && - (!metallivorous(youmonst.data) - || youmonst.data == &mons[PM_RUST_MONSTER])) + if (usegold && !strcmp(word, "eat") + && (!metallivorous(youmonst.data) + || youmonst.data == &mons[PM_RUST_MONSTER])) usegold = FALSE; - if(*let == ALL_CLASSES) let++, allowall = TRUE; - if(*let == ALLOW_NONE) let++, allownone = TRUE; + if (*let == ALL_CLASSES) + let++, allowall = TRUE; + if (*let == ALLOW_NONE) + let++, allownone = TRUE; /* "ugly check" for reading fortune cookies, part 1 */ /* The normal 'ugly check' keeps the object on the inventory list. * We don't want to do that for shirts/cookies, so the check for * them is handled a bit differently (and also requires that we set * allowall in the caller) */ - if(allowall && !strcmp(word, "read")) allowall = FALSE; + if (allowall && !strcmp(word, "read")) + allowall = FALSE; /* another ugly check: show boulders (not statues) */ - if(*let == WEAPON_CLASS && - !strcmp(word, "throw") && throws_rocks(youmonst.data)) + if (*let == WEAPON_CLASS && !strcmp(word, "throw") + && throws_rocks(youmonst.data)) useboulder = TRUE; - if(allownone) *bp++ = '-'; - if(bp > buf && bp[-1] == '-') *bp++ = ' '; + if (allownone) + *bp++ = '-'; + if (bp > buf && bp[-1] == '-') + *bp++ = ' '; ap = altlets; - if (!flags.invlet_constant) reassign(); + if (!flags.invlet_constant) + reassign(); for (otmp = firstobj; otmp; otmp = otmp->nobj) { - if (&bp[foo] == &buf[sizeof buf - 1] || - ap == &altlets[sizeof altlets - 1]) { - /* we must have a huge number of NOINVSYM items somehow */ - impossible("getobj: inventory overflow"); - break; + if (&bp[foo] == &buf[sizeof buf - 1] + || ap == &altlets[sizeof altlets - 1]) { + /* we must have a huge number of NOINVSYM items somehow */ + impossible("getobj: inventory overflow"); + break; } if (!*let || index(let, otmp->oclass) - || (usegold && otmp->invlet == GOLD_SYM) - || (useboulder && otmp->otyp == BOULDER) - ) { - register int otyp = otmp->otyp; - bp[foo++] = otmp->invlet; + || (usegold && otmp->invlet == GOLD_SYM) + || (useboulder && otmp->otyp == BOULDER)) { + register int otyp = otmp->otyp; + bp[foo++] = otmp->invlet; - /* ugly check: remove inappropriate things */ - if ((taking_off(word) && - !(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))) - || (putting_on(word) && - (otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))) - /* already worn */ -#if 0 /* 3.4.1 -- include currently wielded weapon among the choices */ + /* ugly check: remove inappropriate things */ + if ((taking_off(word) + && !(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))) + || (putting_on(word) + && (otmp->owornmask + & (W_ARMOR | W_RING | W_AMUL | W_TOOL))) +/* already worn */ +#if 0 /* 3.4.1 -- include currently wielded weapon among the choices */ || (!strcmp(word, "wield") && (otmp->owornmask & W_WEP)) #endif - || (!strcmp(word, "ready") && - (otmp == uwep || (otmp == uswapwep && u.twoweap))) - || ((!strcmp(word, "dip") || !strcmp(word, "grease")) && - inaccessible_equipment(otmp, (const char *)0 , FALSE)) - ) { - foo--; - foox++; - } + || (!strcmp(word, "ready") + && (otmp == uwep || (otmp == uswapwep && u.twoweap))) + || ((!strcmp(word, "dip") || !strcmp(word, "grease")) + && inaccessible_equipment(otmp, (const char *) 0, + FALSE))) { + foo--; + foox++; + } - /* Second ugly check; unlike the first it won't trigger an - * "else" in "you don't have anything else to ___". - */ - else if ((putting_on(word) && - ((otmp->oclass == FOOD_CLASS && otmp->otyp != MEAT_RING) || - (otmp->oclass == TOOL_CLASS && - otyp != BLINDFOLD && otyp != TOWEL && otyp != LENSES))) - || (!strcmp(word, "wield") && - (otmp->oclass == TOOL_CLASS && !is_weptool(otmp))) - || (!strcmp(word, "eat") && !is_edible(otmp)) - || (!strcmp(word, "sacrifice") && - (otyp != CORPSE && - otyp != AMULET_OF_YENDOR && otyp != FAKE_AMULET_OF_YENDOR)) - || (!strcmp(word, "write with") && - (otmp->oclass == TOOL_CLASS && - otyp != MAGIC_MARKER && otyp != TOWEL)) - || (!strcmp(word, "tin") && - (otyp != CORPSE || !tinnable(otmp))) - || (!strcmp(word, "rub") && - ((otmp->oclass == TOOL_CLASS && - otyp != OIL_LAMP && otyp != MAGIC_LAMP && - otyp != BRASS_LANTERN) || - (otmp->oclass == GEM_CLASS && !is_graystone(otmp)))) - || ((!strcmp(word, "use or apply") || - !strcmp(word, "untrap with")) && - /* Picks, axes, pole-weapons, bullwhips */ - ((otmp->oclass == WEAPON_CLASS && !is_pick(otmp) && - !is_axe(otmp) && !is_pole(otmp) && otyp != BULLWHIP) || - (otmp->oclass == POTION_CLASS && - /* only applicable potion is oil, and it will only - be offered as a choice when already discovered */ - (otyp != POT_OIL || !otmp->dknown || - !objects[POT_OIL].oc_name_known)) || - (otmp->oclass == FOOD_CLASS && - otyp != CREAM_PIE && otyp != EUCALYPTUS_LEAF) || - (otmp->oclass == GEM_CLASS && !is_graystone(otmp)))) - || (!strcmp(word, "invoke") && - (!otmp->oartifact && !objects[otyp].oc_unique && - (otyp != FAKE_AMULET_OF_YENDOR || otmp->known) && - otyp != CRYSTAL_BALL && /* #invoke synonym for apply */ - /* note: presenting the possibility of invoking non-artifact - mirrors and/or lamps is a simply a cruel deception... */ - otyp != MIRROR && otyp != MAGIC_LAMP && - (otyp != OIL_LAMP || /* don't list known oil lamp */ - (otmp->dknown && objects[OIL_LAMP].oc_name_known)))) - || (!strcmp(word, "untrap with") && - (otmp->oclass == TOOL_CLASS && otyp != CAN_OF_GREASE)) - || (!strcmp(word, "tip") && !Is_container(otmp) && - /* include horn of plenty if sufficiently discovered */ - (otmp->otyp != HORN_OF_PLENTY || !otmp->dknown || - !objects[HORN_OF_PLENTY].oc_name_known)) - || (!strcmp(word, "charge") && !is_chargeable(otmp)) - || (!strcmp(word, "call") && !objtyp_is_callable(otyp)) - ) - foo--; - /* ugly check for unworn armor that can't be worn */ - else if ((putting_on(word) && *let == ARMOR_CLASS && - !canwearobj(otmp, &dummymask, FALSE)) - /* or unsuitable items rubbed on known touchstone */ - || (!strncmp(word, "rub on the stone", 16) && - *let == GEM_CLASS && - otmp->dknown && objects[otyp].oc_name_known) - /* suppress corpses on astral, amulets elsewhere */ - || (!strcmp(word, "sacrifice") && - /* (!astral && amulet) || (astral && !amulet) */ - (!Is_astralevel(&u.uz) ^ (otmp->oclass != AMULET_CLASS))) - /* suppress container being stashed into */ - || (!strcmp(word, "stash") && !ck_bag(otmp)) - /* worn armor or accessory covered by cursed worn armor */ - || (taking_off(word) && - inaccessible_equipment(otmp, (const char *)0, TRUE)) - ) { - /* acceptable but not listed as likely candidate */ - foo--; - allowall = TRUE; - *ap++ = otmp->invlet; - } + /* Second ugly check; unlike the first it won't trigger an + * "else" in "you don't have anything else to ___". + */ + else if ( + (putting_on(word) + && ((otmp->oclass == FOOD_CLASS && otmp->otyp != MEAT_RING) + || (otmp->oclass == TOOL_CLASS && otyp != BLINDFOLD + && otyp != TOWEL && otyp != LENSES))) + || (!strcmp(word, "wield") + && (otmp->oclass == TOOL_CLASS && !is_weptool(otmp))) + || (!strcmp(word, "eat") && !is_edible(otmp)) + || (!strcmp(word, "sacrifice") + && (otyp != CORPSE && otyp != AMULET_OF_YENDOR + && otyp != FAKE_AMULET_OF_YENDOR)) + || (!strcmp(word, "write with") + && (otmp->oclass == TOOL_CLASS && otyp != MAGIC_MARKER + && otyp != TOWEL)) + || (!strcmp(word, "tin") + && (otyp != CORPSE || !tinnable(otmp))) + || (!strcmp(word, "rub") + && ((otmp->oclass == TOOL_CLASS && otyp != OIL_LAMP + && otyp != MAGIC_LAMP && otyp != BRASS_LANTERN) + || (otmp->oclass == GEM_CLASS + && !is_graystone(otmp)))) + || ((!strcmp(word, "use or apply") + || !strcmp(word, "untrap with")) && + /* Picks, axes, pole-weapons, bullwhips */ + ((otmp->oclass == WEAPON_CLASS && !is_pick(otmp) + && !is_axe(otmp) && !is_pole(otmp) && otyp != BULLWHIP) + || (otmp->oclass == POTION_CLASS && + /* only applicable potion is oil, and it will only + be offered as a choice when already discovered */ + (otyp != POT_OIL || !otmp->dknown + || !objects[POT_OIL].oc_name_known)) + || (otmp->oclass == FOOD_CLASS && otyp != CREAM_PIE + && otyp != EUCALYPTUS_LEAF) + || (otmp->oclass == GEM_CLASS && !is_graystone(otmp)))) + || (!strcmp(word, "invoke") + && (!otmp->oartifact && !objects[otyp].oc_unique + && (otyp != FAKE_AMULET_OF_YENDOR || otmp->known) + && otyp != CRYSTAL_BALL + && /* #invoke synonym for apply */ + /* note: presenting the possibility of invoking + non-artifact + mirrors and/or lamps is a simply a cruel + deception... */ + otyp != MIRROR + && otyp != MAGIC_LAMP + && (otyp != OIL_LAMP + || /* don't list known oil lamp */ + (otmp->dknown + && objects[OIL_LAMP].oc_name_known)))) + || (!strcmp(word, "untrap with") + && (otmp->oclass == TOOL_CLASS && otyp != CAN_OF_GREASE)) + || (!strcmp(word, "tip") && !Is_container(otmp) && + /* include horn of plenty if sufficiently discovered */ + (otmp->otyp != HORN_OF_PLENTY || !otmp->dknown + || !objects[HORN_OF_PLENTY].oc_name_known)) + || (!strcmp(word, "charge") && !is_chargeable(otmp)) + || (!strcmp(word, "call") && !objtyp_is_callable(otyp))) + foo--; + /* ugly check for unworn armor that can't be worn */ + else if ((putting_on(word) && *let == ARMOR_CLASS + && !canwearobj(otmp, &dummymask, FALSE)) + /* or unsuitable items rubbed on known touchstone */ + || (!strncmp(word, "rub on the stone", 16) + && *let == GEM_CLASS && otmp->dknown + && objects[otyp].oc_name_known) + /* suppress corpses on astral, amulets elsewhere */ + || (!strcmp(word, "sacrifice") && + /* (!astral && amulet) || (astral && !amulet) */ + (!Is_astralevel(&u.uz) + ^ (otmp->oclass != AMULET_CLASS))) + /* suppress container being stashed into */ + || (!strcmp(word, "stash") && !ck_bag(otmp)) + /* worn armor or accessory covered by cursed worn armor + */ + || (taking_off(word) + && inaccessible_equipment(otmp, (const char *) 0, + TRUE))) { + /* acceptable but not listed as likely candidate */ + foo--; + allowall = TRUE; + *ap++ = otmp->invlet; + } } else { - - /* "ugly check" for reading fortune cookies, part 2 */ - if ((!strcmp(word, "read") - && is_readable(otmp))) - allowall = usegold = TRUE; + /* "ugly check" for reading fortune cookies, part 2 */ + if ((!strcmp(word, "read") && is_readable(otmp))) + allowall = usegold = TRUE; } } bp[foo] = 0; - if(foo == 0 && bp > buf && bp[-1] == ' ') *--bp = 0; - Strcpy(lets, bp); /* necessary since we destroy buf */ - if(foo > 5) /* compactify string */ + if (foo == 0 && bp > buf && bp[-1] == ' ') + *--bp = 0; + Strcpy(lets, bp); /* necessary since we destroy buf */ + if (foo > 5) /* compactify string */ compactify(bp); *ap = '\0'; - if(!foo && !allowall && !allownone) { - You("don't have anything %sto %s.", - foox ? "else " : "", word); - return((struct obj *)0); + if (!foo && !allowall && !allownone) { + You("don't have anything %sto %s.", foox ? "else " : "", word); + return ((struct obj *) 0); } - for(;;) { + for (;;) { cnt = 0; - if (allowcnt == 2) allowcnt = 1; /* abort previous count */ + if (allowcnt == 2) + allowcnt = 1; /* abort previous count */ prezero = FALSE; - if(!buf[0]) { + if (!buf[0]) { Sprintf(qbuf, "What do you want to %s? [*]", word); } else { - Sprintf(qbuf, "What do you want to %s? [%s or ?*]", - word, buf); + Sprintf(qbuf, "What do you want to %s? [%s or ?*]", word, buf); } if (in_doagain) ilet = readchar(); else - ilet = yn_function(qbuf, (char *)0, '\0'); + ilet = yn_function(qbuf, (char *) 0, '\0'); if (digit(ilet) && !allowcnt) { pline("No count allowed with this command."); continue; } - if (ilet == '0') prezero = TRUE; + if (ilet == '0') + prezero = TRUE; while (digit(ilet)) { - if (ilet != '?' && ilet != '*') savech(ilet); + if (ilet != '?' && ilet != '*') + savech(ilet); /* accumulate unless cnt has overflowed */ if (allowcnt < 3) { - prevcnt = cnt; - cnt = 10L * cnt + (long)(ilet - '0'); - /* signal presence of cnt */ - allowcnt = (cnt >= prevcnt) ? 2 : 3; + prevcnt = cnt; + cnt = 10L * cnt + (long) (ilet - '0'); + /* signal presence of cnt */ + allowcnt = (cnt >= prevcnt) ? 2 : 3; } ilet = readchar(); } @@ -1089,63 +1162,68 @@ register const char *let,*word; cnt = -1L; allowcnt = 2; } - if(index(quitchars,ilet)) { - if(flags.verbose) - pline1(Never_mind); - return((struct obj *)0); + if (index(quitchars, ilet)) { + if (flags.verbose) + pline1(Never_mind); + return ((struct obj *) 0); } - if(ilet == '-') { - if (!allownone) { - char *suf = NULL; - strcpy(buf, word); - if ((bp = strstr(buf, " on the ")) != NULL) { /* rub on the stone[s] */ - *bp = '\0'; - suf = (bp + 1); - } - if ((bp = strstr(buf, " or ")) != NULL) { - *bp = '\0'; - bp = (rn2(2) ? buf : (bp + 4)); - } else bp = buf; - You("mime %s something%s%s.", ing_suffix(bp), - suf ? " " : "", suf ? suf : ""); - } - return(allownone ? &zeroobj : (struct obj *) 0); + if (ilet == '-') { + if (!allownone) { + char *suf = NULL; + strcpy(buf, word); + if ((bp = strstr(buf, " on the ")) + != NULL) { /* rub on the stone[s] */ + *bp = '\0'; + suf = (bp + 1); + } + if ((bp = strstr(buf, " or ")) != NULL) { + *bp = '\0'; + bp = (rn2(2) ? buf : (bp + 4)); + } else + bp = buf; + You("mime %s something%s%s.", ing_suffix(bp), suf ? " " : "", + suf ? suf : ""); + } + return (allownone ? &zeroobj : (struct obj *) 0); } - /* since gold is now kept in inventory, we need to do processing for - select-from-invent before checking whether gold has been picked */ + /* since gold is now kept in inventory, we need to do processing for + select-from-invent before checking whether gold has been picked */ if (ilet == '?' || ilet == '*') { - char *allowed_choices = (ilet == '?') ? lets : (char *)0; + char *allowed_choices = (ilet == '?') ? lets : (char *) 0; long ctmp = 0; if (ilet == '?' && !*lets && *altlets) - allowed_choices = altlets; + allowed_choices = altlets; ilet = display_pickinv(allowed_choices, TRUE, - allowcnt ? &ctmp : (long *)0); - if (!ilet) continue; + allowcnt ? &ctmp : (long *) 0); + if (!ilet) + continue; if (allowcnt && ctmp >= 0) { - cnt = ctmp; - if (!cnt) prezero = TRUE; - allowcnt = 2; + cnt = ctmp; + if (!cnt) + prezero = TRUE; + allowcnt = 2; } if (ilet == '\033') { - if (flags.verbose) - pline1(Never_mind); - return (struct obj *)0; + if (flags.verbose) + pline1(Never_mind); + return (struct obj *) 0; } /* they typed a letter (not a space) at the prompt */ } - /* find the item which was picked */ - for (otmp = invent; otmp; otmp = otmp->nobj) - if (otmp->invlet == ilet) break; - /* some items have restrictions */ - if (ilet == def_oc_syms[COIN_CLASS].sym - /* guard against the [hypothetical] chace of having more - than one invent slot of gold and picking the non-'$' one */ - || (otmp && otmp->oclass == COIN_CLASS)) { + /* find the item which was picked */ + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->invlet == ilet) + break; + /* some items have restrictions */ + if (ilet == def_oc_syms[COIN_CLASS].sym + /* guard against the [hypothetical] chace of having more + than one invent slot of gold and picking the non-'$' one */ + || (otmp && otmp->oclass == COIN_CLASS)) { if (!usegold) { You("cannot %s gold.", word); - return(struct obj *)0; - } + return (struct obj *) 0; + } /* Historic note: early Nethack had a bug which was * first reported for Larn, where trying to drop 2^32-n * gold pieces was allowed, and did interesting things @@ -1154,59 +1232,61 @@ register const char *let,*word; */ if (allowcnt == 2 && cnt <= 0) { if (cnt < 0 || !prezero) - pline_The( - "LRS would be very interested to know you have that much."); - return (struct obj *)0; + pline_The("LRS would be very interested to know you have " + "that much."); + return (struct obj *) 0; } } - if (allowcnt == 2 && !strcmp(word,"throw")) { + if (allowcnt == 2 && !strcmp(word, "throw")) { /* permit counts for throwing gold, but don't accept * counts for other things since the throw code will * split off a single item anyway */ - if (ilet != def_oc_syms[COIN_CLASS].sym - && !(otmp && otmp->oclass == COIN_CLASS)) - allowcnt = 1; - if (cnt == 0 && prezero) return (struct obj *)0; + if (ilet != def_oc_syms[COIN_CLASS].sym + && !(otmp && otmp->oclass == COIN_CLASS)) + allowcnt = 1; + if (cnt == 0 && prezero) + return (struct obj *) 0; if (cnt > 1) { - You("can only throw one item at a time."); - continue; + You("can only throw one item at a time."); + continue; } } context.botl = 1; /* May have changed the amount of money */ savech(ilet); - /* [we used to set otmp (by finding ilet in invent) here, but - that's been moved above so that otmp can be checked earlier] */ - /* verify the chosen object */ - if(!otmp) { + /* [we used to set otmp (by finding ilet in invent) here, but + that's been moved above so that otmp can be checked earlier] */ + /* verify the chosen object */ + if (!otmp) { You("don't have that object."); - if (in_doagain) return((struct obj *) 0); + if (in_doagain) + return ((struct obj *) 0); continue; } else if (cnt < 0 || otmp->quan < cnt) { - You("don't have that many! You have only %ld.", - otmp->quan); - if (in_doagain) return((struct obj *) 0); + You("don't have that many! You have only %ld.", otmp->quan); + if (in_doagain) + return ((struct obj *) 0); continue; } break; } - if(!allowall && let && !index(let,otmp->oclass) - && !(usegold && otmp->oclass == COIN_CLASS) - ) { + if (!allowall && let && !index(let, otmp->oclass) + && !(usegold && otmp->oclass == COIN_CLASS)) { silly_thing(word, otmp); - return((struct obj *)0); + return ((struct obj *) 0); } - if(allowcnt == 2) { /* cnt given */ - if(cnt == 0) return (struct obj *)0; - if(cnt != otmp->quan) { - /* don't split a stack of cursed loadstones */ - if (splittable(otmp)) - otmp = splitobj(otmp, cnt); - else if (otmp->otyp == LOADSTONE && otmp->cursed) - /* kludge for canletgo()'s can't-drop-this message */ - otmp->corpsenm = (int) cnt; + if (allowcnt == 2) { /* cnt given */ + if (cnt == 0) + return (struct obj *) 0; + if (cnt != otmp->quan) { + /* don't split a stack of cursed loadstones */ + if (splittable(otmp)) + otmp = splitobj(otmp, cnt); + else if (otmp->otyp == LOADSTONE && otmp->cursed) + /* kludge for canletgo()'s can't-drop-this message */ + otmp->corpsenm = (int) cnt; } } - return(otmp); + return (otmp); } void @@ -1222,23 +1302,23 @@ struct obj *otmp; and for corresponding armor commands ('W','T') on accessories */ if (ocls == ARMOR_CLASS) { if (!strcmp(word, "put on")) - s1 = "W", s2 = "wear", s3 = ""; + s1 = "W", s2 = "wear", s3 = ""; else if (!strcmp(word, "remove")) - s1 = "T", s2 = "take", s3 = " off"; - } else if ((ocls == RING_CLASS || otyp == MEAT_RING) || - ocls == AMULET_CLASS || - (otyp == BLINDFOLD || otyp == TOWEL || otyp == LENSES)) { + s1 = "T", s2 = "take", s3 = " off"; + } else if ((ocls == RING_CLASS || otyp == MEAT_RING) + || ocls == AMULET_CLASS + || (otyp == BLINDFOLD || otyp == TOWEL || otyp == LENSES)) { if (!strcmp(word, "wear")) - s1 = "P", s2 = "put", s3 = " on"; + s1 = "P", s2 = "put", s3 = " on"; else if (!strcmp(word, "take off")) - s1 = "R", s2 = "remove", s3 = ""; + s1 = "R", s2 = "remove", s3 = ""; } if (s1) { what = "that"; /* quantity for armor and accessory objects is always 1, but some things should be referred to as plural */ if (otyp == LENSES || is_gloves(otmp) || is_boots(otmp)) - what = "those"; + what = "those"; pline("Use the '%s' command to %s %s%s.", s1, s2, what, s3); } else { pline(silly_thing_to, word); @@ -1250,7 +1330,7 @@ ckvalidcat(otmp) register struct obj *otmp; { /* use allow_category() from pickup.c */ - return((int)allow_category(otmp)); + return ((int) allow_category(otmp)); } STATIC_PTR int @@ -1263,16 +1343,17 @@ register struct obj *otmp; boolean wearing_armor() { - return((boolean)(uarm || uarmc || uarmf || uarmg || uarmh || uarms - || uarmu)); + return ((boolean)(uarm || uarmc || uarmf || uarmg || uarmh || uarms + || uarmu)); } boolean is_worn(otmp) register struct obj *otmp; { - return((boolean)(!!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | - W_SADDLE | W_WEP | W_SWAPWEP | W_QUIVER)))); + return ((boolean)( + !!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_SADDLE + | W_WEP | W_SWAPWEP | W_QUIVER)))); } /* extra xprname() input that askchain() can't pass through safe_qbuf() */ @@ -1286,9 +1367,8 @@ STATIC_PTR char * safeq_xprname(obj) struct obj *obj; { - return xprname(obj, (char *)0, - safeq_xprn_ctx.let, safeq_xprn_ctx.dot, - 0L, 0L); + return xprname(obj, (char *) 0, safeq_xprn_ctx.let, safeq_xprn_ctx.dot, + 0L, 0L); } /* alternate safe_qbuf() -> short_oname() callback */ @@ -1296,13 +1376,13 @@ STATIC_PTR char * safeq_shortxprname(obj) struct obj *obj; { - return xprname(obj, ansimpleoname(obj), - safeq_xprn_ctx.let, safeq_xprn_ctx.dot, - 0L, 0L); + return xprname(obj, ansimpleoname(obj), safeq_xprn_ctx.let, + safeq_xprn_ctx.dot, 0L, 0L); } -static NEARDATA const char removeables[] = - { ARMOR_CLASS, WEAPON_CLASS, RING_CLASS, AMULET_CLASS, TOOL_CLASS, 0 }; +static NEARDATA const char removeables[] = { ARMOR_CLASS, WEAPON_CLASS, + RING_CLASS, AMULET_CLASS, + TOOL_CLASS, 0 }; /* interactive version of getobj - used for Drop, Identify and */ /* Takeoff (A). Return the number of times fn was called successfully */ @@ -1310,26 +1390,27 @@ static NEARDATA const char removeables[] = int ggetobj(word, fn, mx, combo, resultflags) const char *word; -int FDECL((*fn),(OBJ_P)), mx; -boolean combo; /* combination menu flag */ +int FDECL((*fn), (OBJ_P)), mx; +boolean combo; /* combination menu flag */ unsigned *resultflags; { - int FDECL((*ckfn),(OBJ_P)) = (int FDECL((*),(OBJ_P))) 0; - boolean FDECL((*filter),(OBJ_P)) = (boolean FDECL((*),(OBJ_P))) 0; + int FDECL((*ckfn), (OBJ_P)) = (int FDECL((*), (OBJ_P))) 0; + boolean FDECL((*filter), (OBJ_P)) = (boolean FDECL((*), (OBJ_P))) 0; boolean takeoff, ident, allflag, m_seen; int itemcount; int oletct, iletct, unpaid, oc_of_sym; - char sym, *ip, olets[MAXOCLASSES+5], ilets[MAXOCLASSES+5]; - char extra_removeables[3+1]; /* uwep,uswapwep,uquiver */ + char sym, *ip, olets[MAXOCLASSES + 5], ilets[MAXOCLASSES + 5]; + char extra_removeables[3 + 1]; /* uwep,uswapwep,uquiver */ char buf[BUFSZ], qbuf[QBUFSZ]; - if (resultflags) *resultflags = 0; + if (resultflags) + *resultflags = 0; takeoff = ident = allflag = m_seen = FALSE; - if(!invent){ + if (!invent) { You("have nothing to %s.", word); - return(0); + return (0); } - add_valid_menu_class(0); /* reset */ + add_valid_menu_class(0); /* reset */ if (taking_off(word)) { takeoff = TRUE; filter = is_worn; @@ -1338,88 +1419,98 @@ unsigned *resultflags; filter = not_fully_identified; } - iletct = collect_obj_classes(ilets, invent, - FALSE, - filter, &itemcount); + iletct = collect_obj_classes(ilets, invent, FALSE, filter, &itemcount); unpaid = count_unpaid(invent); if (ident && !iletct) { - return -1; /* no further identifications */ + return -1; /* no further identifications */ } else if (!takeoff && (unpaid || invent)) { ilets[iletct++] = ' '; - if (unpaid) ilets[iletct++] = 'u'; - if (count_buc(invent, BUC_BLESSED)) ilets[iletct++] = 'B'; - if (count_buc(invent, BUC_UNCURSED)) ilets[iletct++] = 'U'; - if (count_buc(invent, BUC_CURSED)) ilets[iletct++] = 'C'; - if (count_buc(invent, BUC_UNKNOWN)) ilets[iletct++] = 'X'; - if (invent) ilets[iletct++] = 'a'; + if (unpaid) + ilets[iletct++] = 'u'; + if (count_buc(invent, BUC_BLESSED)) + ilets[iletct++] = 'B'; + if (count_buc(invent, BUC_UNCURSED)) + ilets[iletct++] = 'U'; + if (count_buc(invent, BUC_CURSED)) + ilets[iletct++] = 'C'; + if (count_buc(invent, BUC_UNKNOWN)) + ilets[iletct++] = 'X'; + if (invent) + ilets[iletct++] = 'a'; } else if (takeoff && invent) { ilets[iletct++] = ' '; } ilets[iletct++] = 'i'; if (!combo) - ilets[iletct++] = 'm'; /* allow menu presentation on request */ + ilets[iletct++] = 'm'; /* allow menu presentation on request */ ilets[iletct] = '\0'; for (;;) { - Sprintf(qbuf,"What kinds of thing do you want to %s? [%s]", - word, ilets); + Sprintf(qbuf, "What kinds of thing do you want to %s? [%s]", word, + ilets); getlin(qbuf, buf); - if (buf[0] == '\033') return(0); + if (buf[0] == '\033') + return (0); if (index(buf, 'i')) { - if (display_inventory((char *)0, TRUE) == '\033') return 0; + if (display_inventory((char *) 0, TRUE) == '\033') + return 0; } else - break; + break; } extra_removeables[0] = '\0'; if (takeoff) { /* arbitrary types of items can be placed in the weapon slots [any duplicate entries in extra_removeables[] won't matter] */ - if (uwep) (void)strkitten(extra_removeables, uwep->oclass); - if (uswapwep) (void)strkitten(extra_removeables, uswapwep->oclass); - if (uquiver) (void)strkitten(extra_removeables, uquiver->oclass); + if (uwep) + (void) strkitten(extra_removeables, uwep->oclass); + if (uswapwep) + (void) strkitten(extra_removeables, uswapwep->oclass); + if (uquiver) + (void) strkitten(extra_removeables, uquiver->oclass); } ip = buf; olets[oletct = 0] = '\0'; while ((sym = *ip++) != '\0') { - if (sym == ' ') continue; + if (sym == ' ') + continue; oc_of_sym = def_char_to_objclass(sym); if (takeoff && oc_of_sym != MAXOCLASSES) { - if (index(extra_removeables, oc_of_sym)) { - ; /* skip rest of takeoff checks */ - } else if (!index(removeables, oc_of_sym)) { - pline("Not applicable."); - return 0; - } else if (oc_of_sym == ARMOR_CLASS && !wearing_armor()) { - noarmor(FALSE); - return 0; - } else if (oc_of_sym == WEAPON_CLASS && - !uwep && !uswapwep && !uquiver) { - You("are not wielding anything."); - return 0; - } else if (oc_of_sym == RING_CLASS && !uright && !uleft) { - You("are not wearing rings."); - return 0; - } else if (oc_of_sym == AMULET_CLASS && !uamul) { - You("are not wearing an amulet."); - return 0; - } else if (oc_of_sym == TOOL_CLASS && !ublindf) { - You("are not wearing a blindfold."); - return 0; - } + if (index(extra_removeables, oc_of_sym)) { + ; /* skip rest of takeoff checks */ + } else if (!index(removeables, oc_of_sym)) { + pline("Not applicable."); + return 0; + } else if (oc_of_sym == ARMOR_CLASS && !wearing_armor()) { + noarmor(FALSE); + return 0; + } else if (oc_of_sym == WEAPON_CLASS && !uwep && !uswapwep + && !uquiver) { + You("are not wielding anything."); + return 0; + } else if (oc_of_sym == RING_CLASS && !uright && !uleft) { + You("are not wearing rings."); + return 0; + } else if (oc_of_sym == AMULET_CLASS && !uamul) { + You("are not wearing an amulet."); + return 0; + } else if (oc_of_sym == TOOL_CLASS && !ublindf) { + You("are not wearing a blindfold."); + return 0; + } } if (oc_of_sym == COIN_CLASS && !combo) { - context.botl = 1; + context.botl = 1; } else if (sym == 'a') { - allflag = TRUE; + allflag = TRUE; } else if (sym == 'A') { - /* same as the default */ ; + /* same as the default */; } else if (sym == 'u') { - add_valid_menu_class('u'); - ckfn = ckunpaid; + add_valid_menu_class('u'); + ckfn = ckunpaid; } else if (sym == 'B') { add_valid_menu_class('B'); ckfn = ckvalidcat; @@ -1428,20 +1519,20 @@ unsigned *resultflags; ckfn = ckvalidcat; } else if (sym == 'C') { add_valid_menu_class('C'); - ckfn = ckvalidcat; + ckfn = ckvalidcat; } else if (sym == 'X') { add_valid_menu_class('X'); - ckfn = ckvalidcat; + ckfn = ckvalidcat; } else if (sym == 'm') { - m_seen = TRUE; + m_seen = TRUE; } else if (oc_of_sym == MAXOCLASSES) { - You("don't have any %c's.", sym); - } else if (oc_of_sym != VENOM_CLASS) { /* suppress venom */ - if (!index(olets, oc_of_sym)) { - add_valid_menu_class(oc_of_sym); - olets[oletct++] = oc_of_sym; - olets[oletct] = 0; - } + You("don't have any %c's.", sym); + } else if (oc_of_sym != VENOM_CLASS) { /* suppress venom */ + if (!index(olets, oc_of_sym)) { + add_valid_menu_class(oc_of_sym); + olets[oletct++] = oc_of_sym; + olets[oletct] = 0; + } } } @@ -1453,15 +1544,15 @@ unsigned *resultflags; !!!! return 1; you dropped gold (or at least tried to) !!!! test gold dropping else*/ { - int cnt = askchain(&invent, olets, allflag, fn, ckfn, mx, word); + int cnt = askchain(&invent, olets, allflag, fn, ckfn, mx, word); /* * askchain() has already finished the job in this case * so set a special flag to convey that back to the caller * so that it won't continue processing. - * Fix for bug C331-1 reported by Irina Rempt-Drijfhout. + * Fix for bug C331-1 reported by Irina Rempt-Drijfhout. */ if (combo && allflag && resultflags) - *resultflags |= ALL_FINISHED; + *resultflags |= ALL_FINISHED; return cnt; } } @@ -1477,8 +1568,8 @@ int askchain(objchn, olets, allflag, fn, ckfn, mx, word) struct obj **objchn; register int allflag, mx; -register const char *olets, *word; /* olets is an Obj Class char array */ -register int FDECL((*fn),(OBJ_P)), FDECL((*ckfn),(OBJ_P)); +register const char *olets, *word; /* olets is an Obj Class char array */ +register int FDECL((*fn), (OBJ_P)), FDECL((*ckfn), (OBJ_P)); { struct obj *otmp, *otmpo; register char sym, ilet; @@ -1490,112 +1581,122 @@ register int FDECL((*fn),(OBJ_P)), FDECL((*ckfn),(OBJ_P)); ident = !strcmp(word, "identify"); take_out = !strcmp(word, "take out"); put_in = !strcmp(word, "put in"); - nodot = (!strcmp(word, "nodot") || !strcmp(word, "drop") || - ident || takeoff || take_out || put_in); + nodot = (!strcmp(word, "nodot") || !strcmp(word, "drop") || ident + || takeoff || take_out || put_in); ininv = (*objchn == invent); first = TRUE; - /* Changed so the askchain is interrogated in the order specified. - * For example, if a person specifies =/ then first all rings will be - * asked about followed by all wands -dgk - */ +/* Changed so the askchain is interrogated in the order specified. + * For example, if a person specifies =/ then first all rings will be + * asked about followed by all wands -dgk + */ nextclass: - ilet = 'a'-1; + ilet = 'a' - 1; if (*objchn && (*objchn)->oclass == COIN_CLASS) - ilet--; /* extra iteration */ - /* - * Multiple Drop can change the invent chain while it operates - * (dropping a burning potion of oil while levitating creates - * an explosion which can destroy inventory items), so simple - * list traversal - * for (otmp = *objchn; otmp; otmp = otmp2) { - * otmp2 = otmp->nobj; - * ... - * } - * is inadeqate here. Use each object's bypass bit to keep - * track of which list elements have already been processed. - */ - bypass_objlist(*objchn, FALSE); /* clear chain's bypass bits */ + ilet--; /* extra iteration */ + /* + * Multiple Drop can change the invent chain while it operates + * (dropping a burning potion of oil while levitating creates + * an explosion which can destroy inventory items), so simple + * list traversal + * for (otmp = *objchn; otmp; otmp = otmp2) { + * otmp2 = otmp->nobj; + * ... + * } + * is inadeqate here. Use each object's bypass bit to keep + * track of which list elements have already been processed. + */ + bypass_objlist(*objchn, FALSE); /* clear chain's bypass bits */ while ((otmp = nxt_unbypassed_obj(*objchn)) != 0) { - if (ilet == 'z') ilet = 'A'; else ilet++; - if (olets && *olets && otmp->oclass != *olets) continue; - if (takeoff && !is_worn(otmp)) continue; - if (ident && !not_fully_identified(otmp)) continue; - if (ckfn && !(*ckfn)(otmp)) continue; + if (ilet == 'z') + ilet = 'A'; + else + ilet++; + if (olets && *olets && otmp->oclass != *olets) + continue; + if (takeoff && !is_worn(otmp)) + continue; + if (ident && !not_fully_identified(otmp)) + continue; + if (ckfn && !(*ckfn)(otmp)) + continue; if (!allflag) { safeq_xprn_ctx.let = ilet; safeq_xprn_ctx.dot = !nodot; *qpfx = '\0'; if (first) { - /* traditional_loot() skips prompting when only one - class of objects is involved, so prefix the first - object being queried here with an explanation why */ - if (take_out || put_in) - Sprintf(qpfx, "%s: ", word), *qpfx = highc(*qpfx); - first = FALSE; + /* traditional_loot() skips prompting when only one + class of objects is involved, so prefix the first + object being queried here with an explanation why */ + if (take_out || put_in) + Sprintf(qpfx, "%s: ", word), *qpfx = highc(*qpfx); + first = FALSE; } - (void)safe_qbuf(qbuf, qpfx, "?", - otmp, ininv ? safeq_xprname : doname, - ininv ? safeq_shortxprname : ansimpleoname, - "item"); - sym = (takeoff || ident || otmp->quan < 2L) ? - nyaq(qbuf) : nyNaq(qbuf); + (void) safe_qbuf( + qbuf, qpfx, "?", otmp, ininv ? safeq_xprname : doname, + ininv ? safeq_shortxprname : ansimpleoname, "item"); + sym = (takeoff || ident || otmp->quan < 2L) ? nyaq(qbuf) + : nyNaq(qbuf); } else sym = 'y'; otmpo = otmp; if (sym == '#') { - /* Number was entered; split the object unless it corresponds - to 'none' or 'all'. 2 special cases: cursed loadstones and - welded weapons (eg, multiple daggers) will remain as merged - unit; done to avoid splitting an object that won't be - droppable (even if we're picking up rather than dropping). - */ + /* Number was entered; split the object unless it corresponds + to 'none' or 'all'. 2 special cases: cursed loadstones and + welded weapons (eg, multiple daggers) will remain as merged + unit; done to avoid splitting an object that won't be + droppable (even if we're picking up rather than dropping). + */ if (!yn_number) - sym = 'n'; + sym = 'n'; else { - sym = 'y'; - if (yn_number < otmp->quan && splittable(otmp)) - otmp = splitobj(otmp, yn_number); + sym = 'y'; + if (yn_number < otmp->quan && splittable(otmp)) + otmp = splitobj(otmp, yn_number); } } - switch(sym){ + switch (sym) { case 'a': allflag = 1; case 'y': tmp = (*fn)(otmp); - if(tmp < 0) { + if (tmp < 0) { if (container_gone(fn)) { - /* otmp caused magic bag to explode; - both are now gone */ - otmp = 0; /* and return */ + /* otmp caused magic bag to explode; + both are now gone */ + otmp = 0; /* and return */ } else if (otmp && otmp != otmpo) { - /* split occurred, merge again */ - (void) merged(&otmpo, &otmp); + /* split occurred, merge again */ + (void) merged(&otmpo, &otmp); } goto ret; } cnt += tmp; - if(--mx == 0) goto ret; + if (--mx == 0) + goto ret; case 'n': - if(nodot) dud++; + if (nodot) + dud++; default: break; case 'q': /* special case for seffects() */ - if (ident) cnt = -1; + if (ident) + cnt = -1; goto ret; } } if (olets && *olets && *++olets) goto nextclass; - if(!takeoff && (dud || cnt)) pline("That was all."); - else if(!dud && !cnt) pline("No applicable objects."); + if (!takeoff && (dud || cnt)) + pline("That was all."); + else if (!dud && !cnt) + pline("No applicable objects."); ret: bypass_objlist(*objchn, FALSE); - return(cnt); + return (cnt); } - /* * Object identification routines: */ @@ -1606,12 +1707,13 @@ fully_identify_obj(otmp) struct obj *otmp; { makeknown(otmp->otyp); - if (otmp->oartifact) discover_artifact((xchar)otmp->oartifact); + if (otmp->oartifact) + discover_artifact((xchar) otmp->oartifact); otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1; if (Is_container(otmp) || otmp->otyp == STATUE) - otmp->cknown = otmp->lknown = 1; + otmp->cknown = otmp->lknown = 1; if (otmp->otyp == EGG && otmp->corpsenm != NON_PM) - learn_egg_type(otmp->corpsenm); + learn_egg_type(otmp->corpsenm); } /* ggetobj callback routine; identify an object and give immediate feedback */ @@ -1620,7 +1722,7 @@ identify(otmp) struct obj *otmp; { fully_identify_obj(otmp); - prinv((char *)0, otmp, 0L); + prinv((char *) 0, otmp, 0L); return 1; } @@ -1635,30 +1737,31 @@ int id_limit; /* assumptions: id_limit > 0 and at least one unID'd item is present */ while (id_limit) { - Sprintf(buf, "What would you like to identify %s?", - first ? "first" : "next"); - n = query_objlist(buf, invent, - SIGNAL_NOMENU|SIGNAL_ESCAPE|USE_INVLET|INVORDER_SORT, - &pick_list, PICK_ANY, not_fully_identified); + Sprintf(buf, "What would you like to identify %s?", + first ? "first" : "next"); + n = query_objlist(buf, invent, SIGNAL_NOMENU | SIGNAL_ESCAPE + | USE_INVLET | INVORDER_SORT, + &pick_list, PICK_ANY, not_fully_identified); - if (n > 0) { - if (n > id_limit) n = id_limit; - for (i = 0; i < n; i++, id_limit--) - (void) identify(pick_list[i].item.a_obj); - free((genericptr_t) pick_list); - mark_synch(); /* Before we loop to pop open another menu */ - first = 0; - } else if (n == -2) { /* player used ESC to quit menu */ - break; - } else if (n == -1) { /* no eligible items found */ - pline("That was all."); - break; - } else if (!--tryct) { /* stop re-prompting */ - pline1(thats_enough_tries); - break; - } else { /* try again */ - pline("Choose an item; use ESC to decline."); - } + if (n > 0) { + if (n > id_limit) + n = id_limit; + for (i = 0; i < n; i++, id_limit--) + (void) identify(pick_list[i].item.a_obj); + free((genericptr_t) pick_list); + mark_synch(); /* Before we loop to pop open another menu */ + first = 0; + } else if (n == -2) { /* player used ESC to quit menu */ + break; + } else if (n == -1) { /* no eligible items found */ + pline("That was all."); + break; + } else if (!--tryct) { /* stop re-prompting */ + pline1(thats_enough_tries); + break; + } else { /* try again */ + pline("Choose an item; use ESC to decline."); + } } } @@ -1666,40 +1769,43 @@ int id_limit; void identify_pack(id_limit, learning_id) int id_limit; -boolean learning_id; /* true if we just read unknown identify scroll */ +boolean learning_id; /* true if we just read unknown identify scroll */ { struct obj *obj, *the_obj; int n, unid_cnt; unid_cnt = 0; - the_obj = 0; /* if unid_cnt ends up 1, this will be it */ + the_obj = 0; /* if unid_cnt ends up 1, this will be it */ for (obj = invent; obj; obj = obj->nobj) - if (not_fully_identified(obj)) ++unid_cnt, the_obj = obj; + if (not_fully_identified(obj)) + ++unid_cnt, the_obj = obj; if (!unid_cnt) { - You("have already identified all %sof your possessions.", - learning_id ? "the rest " : ""); + You("have already identified all %sof your possessions.", + learning_id ? "the rest " : ""); } else if (!id_limit || id_limit >= unid_cnt) { - /* identify everything */ - if (unid_cnt == 1) { - (void) identify(the_obj); + /* identify everything */ + if (unid_cnt == 1) { + (void) identify(the_obj); + } else { + /* TODO: use fully_identify_obj and cornline/menu/whatever here + */ + for (obj = invent; obj; obj = obj->nobj) + if (not_fully_identified(obj)) + (void) identify(obj); + } } else { - - /* TODO: use fully_identify_obj and cornline/menu/whatever here */ - for (obj = invent; obj; obj = obj->nobj) - if (not_fully_identified(obj)) (void) identify(obj); - - } - } else { - /* identify up to `id_limit' items */ - n = 0; - if (flags.menu_style == MENU_TRADITIONAL) - do { - n = ggetobj("identify", identify, id_limit, FALSE, (unsigned *)0); - if (n < 0) break; /* quit or no eligible items */ - } while ((id_limit -= n) > 0); - if (n == 0 || n < -1) - menu_identify(id_limit); + /* identify up to `id_limit' items */ + n = 0; + if (flags.menu_style == MENU_TRADITIONAL) + do { + n = ggetobj("identify", identify, id_limit, FALSE, + (unsigned *) 0); + if (n < 0) + break; /* quit or no eligible items */ + } while ((id_limit -= n) > 0); + if (n == 0 || n < -1) + menu_identify(id_limit); } update_inventory(); } @@ -1711,22 +1817,24 @@ learn_unseen_invent() { struct obj *otmp; - if (Blind) return; /* sanity check */ + if (Blind) + return; /* sanity check */ for (otmp = invent; otmp; otmp = otmp->nobj) { - if (otmp->dknown) continue; /* already seen */ - /* set dknown, perhaps bknown (for priest[ess]) */ - (void) xname(otmp); - /* - * If object->eknown gets implemented (see learnwand(zap.c)), - * handle deferred discovery here. - */ + if (otmp->dknown) + continue; /* already seen */ + /* set dknown, perhaps bknown (for priest[ess]) */ + (void) xname(otmp); + /* + * If object->eknown gets implemented (see learnwand(zap.c)), + * handle deferred discovery here. + */ } update_inventory(); } STATIC_OVL char -obj_to_let(obj) /* should of course only be called for things in invent */ +obj_to_let(obj) /* should of course only be called for things in invent */ register struct obj *obj; { if (!flags.invlet_constant) { @@ -1746,22 +1854,22 @@ const char *prefix; register struct obj *obj; long quan; { - if (!prefix) prefix = ""; - pline("%s%s%s", - prefix, *prefix ? " " : "", - xprname(obj, (char *)0, obj_to_let(obj), TRUE, 0L, quan)); + if (!prefix) + prefix = ""; + pline("%s%s%s", prefix, *prefix ? " " : "", + xprname(obj, (char *) 0, obj_to_let(obj), TRUE, 0L, quan)); } char * xprname(obj, txt, let, dot, cost, quan) struct obj *obj; -const char *txt; /* text to print instead of obj */ -char let; /* inventory letter */ -boolean dot; /* append period; (dot && cost => Iu) */ -long cost; /* cost (for inventory of unpaid or expended items) */ -long quan; /* if non-0, print this quantity, not obj->quan */ +const char *txt; /* text to print instead of obj */ +char let; /* inventory letter */ +boolean dot; /* append period; (dot && cost => Iu) */ +long cost; /* cost (for inventory of unpaid or expended items) */ +long quan; /* if non-0, print this quantity, not obj->quan */ { -#ifdef LINT /* handle static char li[BUFSZ]; */ +#ifdef LINT /* handle static char li[BUFSZ]; */ char li[BUFSZ]; #else static char li[BUFSZ]; @@ -1770,8 +1878,8 @@ long quan; /* if non-0, print this quantity, not obj->quan */ long savequan = 0; if (quan && obj) { - savequan = obj->quan; - obj->quan = quan; + savequan = obj->quan; + obj->quan = quan; } /* @@ -1780,17 +1888,17 @@ long quan; /* if non-0, print this quantity, not obj->quan */ * > Then the object is contained and doesn't have an inventory letter. */ if (cost != 0 || let == '*') { - /* if dot is true, we're doing Iu, otherwise Ix */ - Sprintf(li, "%c - %-45s %6ld %s", - (dot && use_invlet ? obj->invlet : let), - (txt ? txt : doname(obj)), cost, currency(cost)); + /* if dot is true, we're doing Iu, otherwise Ix */ + Sprintf(li, "%c - %-45s %6ld %s", + (dot && use_invlet ? obj->invlet : let), + (txt ? txt : doname(obj)), cost, currency(cost)); } else { - /* ordinary inventory display or pickup message */ - Sprintf(li, "%c - %s%s", - (use_invlet ? obj->invlet : let), - (txt ? txt : doname(obj)), (dot ? "." : "")); + /* ordinary inventory display or pickup message */ + Sprintf(li, "%c - %s%s", (use_invlet ? obj->invlet : let), + (txt ? txt : doname(obj)), (dot ? "." : "")); } - if (savequan) obj->quan = savequan; + if (savequan) + obj->quan = savequan; return li; } @@ -1799,7 +1907,7 @@ long quan; /* if non-0, print this quantity, not obj->quan */ int ddoinv() { - (void) display_inventory((char *)0, FALSE); + (void) display_inventory((char *) 0, FALSE); return 0; } @@ -1814,24 +1922,24 @@ ddoinv() */ STATIC_OVL struct obj * find_unpaid(list, last_found) - struct obj *list, **last_found; +struct obj *list, **last_found; { struct obj *obj; while (list) { - if (list->unpaid) { - if (*last_found) { - /* still looking for previous unpaid object */ - if (list == *last_found) - *last_found = (struct obj *) 0; - } else - return (*last_found = list); - } - if (Has_contents(list)) { - if ((obj = find_unpaid(list->cobj, last_found)) != 0) - return obj; - } - list = list->nobj; + if (list->unpaid) { + if (*last_found) { + /* still looking for previous unpaid object */ + if (list == *last_found) + *last_found = (struct obj *) 0; + } else + return (*last_found = list); + } + if (Has_contents(list)) { + if ((obj = find_unpaid(list->cobj, last_found)) != 0) + return obj; + } + list = list->nobj; } return (struct obj *) 0; } @@ -1845,24 +1953,24 @@ STATIC_OVL char display_pickinv(lets, want_reply, out_cnt) register const char *lets; boolean want_reply; -long* out_cnt; +long *out_cnt; { struct obj *otmp; char ilet, ret; char *invlet = flags.inv_order; - int i, n, classcount; - winid win; /* windows being used */ - static winid local_win = WIN_ERR; /* window for partial menus */ + int i, n, classcount; + winid win; /* windows being used */ + static winid local_win = WIN_ERR; /* window for partial menus */ anything any; menu_item *selected; - struct obj **oarray; + struct obj **oarray; /* overriden by global flag */ if (flags.perm_invent) { win = (lets && *lets) ? local_win : WIN_INVEN; /* create the first time used */ if (win == WIN_ERR) - win = local_win = create_nhwindow(NHW_MENU); + win = local_win = create_nhwindow(NHW_MENU); } else win = WIN_INVEN; @@ -1883,7 +1991,8 @@ long* out_cnt; } /* oxymoron? temporarily assign permanent inventory letters */ - if (!flags.invlet_constant) reassign(); + if (!flags.invlet_constant) + reassign(); if (lets && strlen(lets) == 1 && !iflags.override_ID) { /* when only one item of interest, use pline instead of menus; @@ -1891,29 +2000,31 @@ long* out_cnt; the user to perform selection at the --More-- prompt for tty */ ret = '\0'; for (otmp = invent; otmp; otmp = otmp->nobj) { - if (otmp->invlet == lets[0]) { - ret = message_menu(lets[0], - want_reply ? PICK_ONE : PICK_NONE, - xprname(otmp, (char *)0, lets[0], TRUE, 0L, 0L)); - if (out_cnt) *out_cnt = -1L; /* select all */ - break; - } + if (otmp->invlet == lets[0]) { + ret = message_menu( + lets[0], want_reply ? PICK_ONE : PICK_NONE, + xprname(otmp, (char *) 0, lets[0], TRUE, 0L, 0L)); + if (out_cnt) + *out_cnt = -1L; /* select all */ + break; + } } return ret; } - /* count the number of items */ - for (n = 0, otmp = invent; otmp; otmp = otmp->nobj) - if (!lets || !*lets || index(lets, otmp->invlet)) n++; + /* count the number of items */ + for (n = 0, otmp = invent; otmp; otmp = otmp->nobj) + if (!lets || !*lets || index(lets, otmp->invlet)) + n++; - oarray = objarr_init(n); + oarray = objarr_init(n); - /* Add objects to the array */ - i = 0; - for (otmp = invent; otmp; otmp = otmp->nobj) - if (!lets || !*lets || index(lets, otmp->invlet)) { - objarr_set(otmp, i++, oarray, (flags.sortloot == 'f')); - } + /* Add objects to the array */ + i = 0; + for (otmp = invent; otmp; otmp = otmp->nobj) + if (!lets || !*lets || index(lets, otmp->invlet)) { + objarr_set(otmp, i++, oarray, (flags.sortloot == 'f')); + } start_menu(win); any = zeroany; @@ -1923,46 +2034,49 @@ long* out_cnt; /* wiz_identify stuffed the wiz_identify cmd character into iflags.override_ID */ Sprintf(prompt, "Debug Identify (%s to permanently identify)", - visctrl(iflags.override_ID)); - add_menu(win, NO_GLYPH, &any,'_', iflags.override_ID, ATR_NONE, - prompt, MENU_UNSELECTED); + visctrl(iflags.override_ID)); + add_menu(win, NO_GLYPH, &any, '_', iflags.override_ID, ATR_NONE, + prompt, MENU_UNSELECTED); } nextclass: classcount = 0; - any = zeroany; /* set all bits to zero */ - for(i = 0; i < n; i++) { - otmp = oarray[i]; - ilet = otmp->invlet; - any = zeroany; /* zero */ - if (!flags.sortpack || otmp->oclass == *invlet) { - if (flags.sortpack && !classcount) { - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - let_to_name(*invlet, FALSE, (want_reply && iflags.menu_head_objsym)), MENU_UNSELECTED); - classcount++; - } - any.a_char = ilet; - add_menu(win, obj_to_glyph(otmp), - &any, ilet, 0, ATR_NONE, doname(otmp), - MENU_UNSELECTED); - } - } + any = zeroany; /* set all bits to zero */ + for (i = 0; i < n; i++) { + otmp = oarray[i]; + ilet = otmp->invlet; + any = zeroany; /* zero */ + if (!flags.sortpack || otmp->oclass == *invlet) { + if (flags.sortpack && !classcount) { + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + let_to_name(*invlet, FALSE, + (want_reply && iflags.menu_head_objsym)), + MENU_UNSELECTED); + classcount++; + } + any.a_char = ilet; + add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE, + doname(otmp), MENU_UNSELECTED); + } + } if (flags.sortpack) { - if (*++invlet) goto nextclass; + if (*++invlet) + goto nextclass; if (--invlet != venom_inv) { invlet = venom_inv; goto nextclass; } } - free(oarray); + free(oarray); end_menu(win, (char *) 0); n = select_menu(win, want_reply ? PICK_ONE : PICK_NONE, &selected); if (n > 0) { ret = selected[0].item.a_char; - if (out_cnt) *out_cnt = selected[0].count; - free((genericptr_t)selected); + if (out_cnt) + *out_cnt = selected[0].count; + free((genericptr_t) selected); } else - ret = !n ? '\0' : '\033'; /* cancelled */ + ret = !n ? '\0' : '\033'; /* cancelled */ return ret; } @@ -1979,11 +2093,11 @@ display_inventory(lets, want_reply) register const char *lets; boolean want_reply; { - return display_pickinv(lets, want_reply, (long *)0); + return display_pickinv(lets, want_reply, (long *) 0); } /* - * Show what is current using inventory letters. + * Show what is current using inventory letters. * */ STATIC_OVL char @@ -2002,36 +2116,39 @@ char avoidlet; win = create_nhwindow(NHW_MENU); start_menu(win); while (!invdone) { - any = zeroany; /* set all bits to zero */ - classcount = 0; - for(otmp = invent; otmp; otmp = otmp->nobj) { - ilet = otmp->invlet; - if (ilet == avoidlet) continue; - if (!flags.sortpack || otmp->oclass == *invlet) { - if (flags.sortpack && !classcount) { - any = zeroany; /* zero */ - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - let_to_name(*invlet, FALSE, FALSE), MENU_UNSELECTED); - classcount++; + any = zeroany; /* set all bits to zero */ + classcount = 0; + for (otmp = invent; otmp; otmp = otmp->nobj) { + ilet = otmp->invlet; + if (ilet == avoidlet) + continue; + if (!flags.sortpack || otmp->oclass == *invlet) { + if (flags.sortpack && !classcount) { + any = zeroany; /* zero */ + add_menu(win, NO_GLYPH, &any, 0, 0, + iflags.menu_headings, + let_to_name(*invlet, FALSE, FALSE), + MENU_UNSELECTED); + classcount++; + } + any.a_char = ilet; + add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE, + doname(otmp), MENU_UNSELECTED); + } } - any.a_char = ilet; - add_menu(win, obj_to_glyph(otmp), - &any, ilet, 0, ATR_NONE, doname(otmp), - MENU_UNSELECTED); - } - } - if (flags.sortpack && *++invlet) continue; - invdone = 1; + if (flags.sortpack && *++invlet) + continue; + invdone = 1; } end_menu(win, "Inventory letters used:"); n = select_menu(win, PICK_NONE, &selected); if (n > 0) { - ret = selected[0].item.a_char; - free((genericptr_t)selected); + ret = selected[0].item.a_char; + free((genericptr_t) selected); } else - ret = !n ? '\0' : '\033'; /* cancelled */ - destroy_nhwindow(win); + ret = !n ? '\0' : '\033'; /* cancelled */ + destroy_nhwindow(win); } return ret; } @@ -2042,21 +2159,22 @@ char avoidlet; */ int count_unpaid(list) - struct obj *list; +struct obj *list; { int count = 0; while (list) { - if (list->unpaid) count++; - if (Has_contents(list)) - count += count_unpaid(list->cobj); - list = list->nobj; + if (list->unpaid) + count++; + if (Has_contents(list)) + count += count_unpaid(list->cobj); + list = list->nobj; } return count; } /* - * Returns the number of items with b/u/c/unknown within the given list. + * Returns the number of items with b/u/c/unknown within the given list. * This does NOT include contained objects. * * Assumes that the hero sees or touches or otherwise senses the objects @@ -2064,23 +2182,26 @@ count_unpaid(list) */ int count_buc(list, type) - struct obj *list; - int type; +struct obj *list; +int type; { int count = 0; - for ( ; list; list = list->nobj) { - /* coins are "none of the above" as far as BUCX filtering goes */ - if (list->oclass == COIN_CLASS) continue; - /* priests always know bless/curse state */ - if (Role_if(PM_PRIEST)) list->bknown = 1; + for (; list; list = list->nobj) { + /* coins are "none of the above" as far as BUCX filtering goes */ + if (list->oclass == COIN_CLASS) + continue; + /* priests always know bless/curse state */ + if (Role_if(PM_PRIEST)) + list->bknown = 1; - /* check whether this object matches the requested type */ - if (!list->bknown ? (type == BUC_UNKNOWN) : - list->blessed ? (type == BUC_BLESSED) : - list->cursed ? (type == BUC_CURSED) : - (type == BUC_UNCURSED)) - ++count; + /* check whether this object matches the requested type */ + if (!list->bknown + ? (type == BUC_UNKNOWN) + : list->blessed ? (type == BUC_BLESSED) + : list->cursed ? (type == BUC_CURSED) + : (type == BUC_UNCURSED)) + ++count; } return count; } @@ -2093,40 +2214,41 @@ struct obj *list; int *bcp, *ucp, *ccp, *xcp, *ocp; { *bcp = *ucp = *ccp = *xcp = *ocp = 0; - for ( ; list; list = list->nobj) { - if (list->oclass == COIN_CLASS) { - ++(*ocp); /* "other" */ - continue; - } - /* priests always know bless/curse state */ - if (Role_if(PM_PRIEST)) list->bknown = 1; + for (; list; list = list->nobj) { + if (list->oclass == COIN_CLASS) { + ++(*ocp); /* "other" */ + continue; + } + /* priests always know bless/curse state */ + if (Role_if(PM_PRIEST)) + list->bknown = 1; - if (!list->bknown) - ++(*xcp); - else if (list->blessed) - ++(*bcp); - else if (list->cursed) - ++(*ccp); - else /* neither blessed nor cursed => uncursed */ - ++(*ucp); + if (!list->bknown) + ++(*xcp); + else if (list->blessed) + ++(*bcp); + else if (list->cursed) + ++(*ccp); + else /* neither blessed nor cursed => uncursed */ + ++(*ucp); } } long count_contents(container, nested, quantity, everything) struct obj *container; -boolean nested, /* include contents of any nested containers */ - quantity, /* count all vs count separate stacks */ - everything; /* all objects vs only unpaid objects */ +boolean nested, /* include contents of any nested containers */ + quantity, /* count all vs count separate stacks */ + everything; /* all objects vs only unpaid objects */ { struct obj *otmp; long count = 0L; for (otmp = container->cobj; otmp; otmp = otmp->nobj) { - if (nested && Has_contents(otmp)) - count += count_contents(otmp, nested, quantity, everything); - if (everything || otmp->unpaid) - count += quantity ? otmp->quan : 1L; + if (nested && Has_contents(otmp)) + count += count_contents(otmp, nested, quantity, everything); + if (everything || otmp->unpaid) + count += quantity ? otmp->quan : 1L; } return count; } @@ -2144,106 +2266,116 @@ dounpaid() count = count_unpaid(invent); if (count == 1) { - marker = (struct obj *) 0; - otmp = find_unpaid(invent, &marker); - cost = unpaid_cost(otmp, FALSE); - iflags.suppress_price++; /* suppress "(unpaid)" suffix */ - pline1(xprname(otmp, distant_name(otmp, doname), - carried(otmp) ? otmp->invlet : CONTAINED_SYM, - TRUE, cost, 0L)); - iflags.suppress_price--; - return; + marker = (struct obj *) 0; + otmp = find_unpaid(invent, &marker); + cost = unpaid_cost(otmp, FALSE); + iflags.suppress_price++; /* suppress "(unpaid)" suffix */ + pline1(xprname(otmp, distant_name(otmp, doname), + carried(otmp) ? otmp->invlet : CONTAINED_SYM, TRUE, + cost, 0L)); + iflags.suppress_price--; + return; } win = create_nhwindow(NHW_MENU); cost = totcost = 0; - num_so_far = 0; /* count of # printed so far */ - if (!flags.invlet_constant) reassign(); + num_so_far = 0; /* count of # printed so far */ + if (!flags.invlet_constant) + reassign(); do { - classcount = 0; - for (otmp = invent; otmp; otmp = otmp->nobj) { - ilet = otmp->invlet; - if (otmp->unpaid) { - if (!flags.sortpack || otmp->oclass == *invlet) { - if (flags.sortpack && !classcount) { - putstr(win, 0, let_to_name(*invlet, TRUE, FALSE)); - classcount++; - } + classcount = 0; + for (otmp = invent; otmp; otmp = otmp->nobj) { + ilet = otmp->invlet; + if (otmp->unpaid) { + if (!flags.sortpack || otmp->oclass == *invlet) { + if (flags.sortpack && !classcount) { + putstr(win, 0, let_to_name(*invlet, TRUE, FALSE)); + classcount++; + } - totcost += cost = unpaid_cost(otmp, FALSE); - iflags.suppress_price++; /* suppress "(unpaid)" suffix */ - putstr(win, 0, xprname(otmp, distant_name(otmp, doname), - ilet, TRUE, cost, 0L)); - iflags.suppress_price--; - num_so_far++; + totcost += cost = unpaid_cost(otmp, FALSE); + iflags.suppress_price++; /* suppress "(unpaid)" suffix */ + putstr(win, 0, xprname(otmp, distant_name(otmp, doname), + ilet, TRUE, cost, 0L)); + iflags.suppress_price--; + num_so_far++; + } + } } - } - } } while (flags.sortpack && (*++invlet)); if (count > num_so_far) { - /* something unpaid is contained */ - if (flags.sortpack) - putstr(win, 0, let_to_name(CONTAINED_SYM, TRUE, FALSE)); - /* - * Search through the container objects in the inventory for - * unpaid items. The top level inventory items have already - * been listed. - */ - for (otmp = invent; otmp; otmp = otmp->nobj) { - if (Has_contents(otmp)) { - long contcost = 0L; + /* something unpaid is contained */ + if (flags.sortpack) + putstr(win, 0, let_to_name(CONTAINED_SYM, TRUE, FALSE)); + /* + * Search through the container objects in the inventory for + * unpaid items. The top level inventory items have already + * been listed. + */ + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (Has_contents(otmp)) { + long contcost = 0L; - marker = (struct obj *) 0; /* haven't found any */ - while (find_unpaid(otmp->cobj, &marker)) { - totcost += cost = unpaid_cost(marker, FALSE); - contcost += cost; - if (otmp->cknown) { - iflags.suppress_price++; /* suppress "(unpaid)" sfx */ - putstr(win, 0, - xprname(marker, distant_name(marker, doname), - CONTAINED_SYM, TRUE, cost, 0L)); - iflags.suppress_price--; + marker = (struct obj *) 0; /* haven't found any */ + while (find_unpaid(otmp->cobj, &marker)) { + totcost += cost = unpaid_cost(marker, FALSE); + contcost += cost; + if (otmp->cknown) { + iflags.suppress_price++; /* suppress "(unpaid)" sfx */ + putstr(win, 0, + xprname(marker, distant_name(marker, doname), + CONTAINED_SYM, TRUE, cost, 0L)); + iflags.suppress_price--; + } + } + if (!otmp->cknown) { + char contbuf[BUFSZ]; + + /* Shopkeeper knows what to charge for contents */ + Sprintf(contbuf, "%s contents", s_suffix(xname(otmp))); + putstr(win, 0, + xprname((struct obj *) 0, contbuf, CONTAINED_SYM, + TRUE, contcost, 0L)); + } } } - if (!otmp->cknown) { - char contbuf[BUFSZ]; - - /* Shopkeeper knows what to charge for contents */ - Sprintf(contbuf, "%s contents", s_suffix(xname(otmp))); - putstr(win, 0, - xprname((struct obj *)0, contbuf, - CONTAINED_SYM, TRUE, contcost, 0L)); - } - } - } } putstr(win, 0, ""); - putstr(win, 0, xprname((struct obj *)0, "Total:", '*', FALSE, totcost, 0L)); + putstr(win, 0, + xprname((struct obj *) 0, "Total:", '*', FALSE, totcost, 0L)); display_nhwindow(win, FALSE); destroy_nhwindow(win); } - /* query objlist callback: return TRUE if obj type matches "this_type" */ static int this_type; STATIC_OVL boolean this_type_only(obj) - struct obj *obj; +struct obj *obj; { boolean res = (obj->oclass == this_type); if (obj->oclass != COIN_CLASS) { - switch (this_type) { - case 'B': res = (obj->bknown && obj->blessed); break; - case 'U': res = (obj->bknown && !(obj->blessed || obj->cursed)); break; - case 'C': res = (obj->bknown && obj->cursed); break; - case 'X': res = !obj->bknown; break; - default: break; /* use 'res' as-is */ - } + switch (this_type) { + case 'B': + res = (obj->bknown && obj->blessed); + break; + case 'U': + res = (obj->bknown && !(obj->blessed || obj->cursed)); + break; + case 'C': + res = (obj->bknown && obj->cursed); + break; + case 'X': + res = !obj->bknown; + break; + default: + break; /* use 'res' as-is */ + } } return res; } @@ -2270,115 +2402,145 @@ dotypeinv() tally_BUCX(invent, &bcnt, &ucnt, &ccnt, &xcnt, &ocnt); if (flags.menu_style != MENU_TRADITIONAL) { - if (flags.menu_style == MENU_FULL || - flags.menu_style == MENU_PARTIAL) { - traditional = FALSE; - i = UNPAID_TYPES; - if (billx) i |= BILLED_TYPES; - if (bcnt) i |= BUC_BLESSED; - if (ucnt) i |= BUC_UNCURSED; - if (ccnt) i |= BUC_CURSED; - if (xcnt) i |= BUC_UNKNOWN; - n = query_category(prompt, invent, i, &pick_list, PICK_ONE); - if (!n) return 0; - this_type = c = pick_list[0].item.a_int; - free((genericptr_t) pick_list); + if (flags.menu_style == MENU_FULL + || flags.menu_style == MENU_PARTIAL) { + traditional = FALSE; + i = UNPAID_TYPES; + if (billx) + i |= BILLED_TYPES; + if (bcnt) + i |= BUC_BLESSED; + if (ucnt) + i |= BUC_UNCURSED; + if (ccnt) + i |= BUC_CURSED; + if (xcnt) + i |= BUC_UNKNOWN; + n = query_category(prompt, invent, i, &pick_list, PICK_ONE); + if (!n) + return 0; + this_type = c = pick_list[0].item.a_int; + free((genericptr_t) pick_list); } } if (traditional) { - /* collect a list of classes of objects carried, for use as a prompt */ + /* collect a list of classes of objects carried, for use as a prompt + */ types[0] = 0; - class_count = collect_obj_classes(types, invent, FALSE, - (boolean FDECL((*),(OBJ_P))) 0, - &itemcount); - if (unpaid_count || billx || (bcnt + ccnt + ucnt + xcnt) != 0) - types[class_count++] = ' '; - if (unpaid_count) types[class_count++] = 'u'; - if (billx) types[class_count++] = 'x'; - if (bcnt) types[class_count++] = 'B'; - if (ucnt) types[class_count++] = 'U'; - if (ccnt) types[class_count++] = 'C'; - if (xcnt) types[class_count++] = 'X'; - types[class_count] = '\0'; + class_count = + collect_obj_classes(types, invent, FALSE, + (boolean FDECL((*), (OBJ_P))) 0, &itemcount); + if (unpaid_count || billx || (bcnt + ccnt + ucnt + xcnt) != 0) + types[class_count++] = ' '; + if (unpaid_count) + types[class_count++] = 'u'; + if (billx) + types[class_count++] = 'x'; + if (bcnt) + types[class_count++] = 'B'; + if (ucnt) + types[class_count++] = 'U'; + if (ccnt) + types[class_count++] = 'C'; + if (xcnt) + types[class_count++] = 'X'; + types[class_count] = '\0'; /* add everything not already included; user won't see these */ extra_types = eos(types); *extra_types++ = '\033'; - if (!unpaid_count) *extra_types++ = 'u'; - if (!billx) *extra_types++ = 'x'; - if (!bcnt) *extra_types++ = 'B'; - if (!ucnt) *extra_types++ = 'U'; - if (!ccnt) *extra_types++ = 'C'; - if (!xcnt) *extra_types++ = 'X'; - *extra_types = '\0'; /* for index() */ + if (!unpaid_count) + *extra_types++ = 'u'; + if (!billx) + *extra_types++ = 'x'; + if (!bcnt) + *extra_types++ = 'B'; + if (!ucnt) + *extra_types++ = 'U'; + if (!ccnt) + *extra_types++ = 'C'; + if (!xcnt) + *extra_types++ = 'X'; + *extra_types = '\0'; /* for index() */ for (i = 0; i < MAXOCLASSES; i++) - if (!index(types, def_oc_syms[i].sym)) { - *extra_types++ = def_oc_syms[i].sym; - *extra_types = '\0'; - } + if (!index(types, def_oc_syms[i].sym)) { + *extra_types++ = def_oc_syms[i].sym; + *extra_types = '\0'; + } if (class_count > 1) { - c = yn_function(prompt, types, '\0'); - savech(c); - if (c == '\0') { - clear_nhwindow(WIN_MESSAGE); - return 0; - } + c = yn_function(prompt, types, '\0'); + savech(c); + if (c == '\0') { + clear_nhwindow(WIN_MESSAGE); + return 0; + } } else { - /* only one thing to itemize */ - if (unpaid_count) - c = 'u'; - else if (billx) - c = 'x'; - else - c = types[0]; + /* only one thing to itemize */ + if (unpaid_count) + c = 'u'; + else if (billx) + c = 'x'; + else + c = types[0]; } } if (c == 'x' || (c == 'X' && billx && !xcnt)) { if (billx) - (void) doinvbill(1); - else - pline("No used-up objects%s.", - unpaid_count ? " on your shopping bill" : ""); + (void) doinvbill(1); + else + pline("No used-up objects%s.", + unpaid_count ? " on your shopping bill" : ""); return 0; } if (c == 'u' || (c == 'U' && unpaid_count && !ucnt)) { if (unpaid_count) - dounpaid(); + dounpaid(); else - You("are not carrying any unpaid objects."); + You("are not carrying any unpaid objects."); return 0; } if (traditional) { - if (index("BUCX", c)) - oclass = c; /* not a class but understood by this_type_only() */ - else - oclass = def_char_to_objclass(c); /* change to object class */ + if (index("BUCX", c)) + oclass = c; /* not a class but understood by this_type_only() */ + else + oclass = def_char_to_objclass(c); /* change to object class */ if (oclass == COIN_CLASS) - return doprgold(); + return doprgold(); if (index(types, c) > index(types, '\033')) { - /* '> ESC' => "hidden choice", something known not to be carried */ - const char *which = 0; + /* '> ESC' => "hidden choice", something known not to be carried + */ + const char *which = 0; - switch (c) { - case 'B': which = "known to be blessed"; break; - case 'U': which = "known to be uncursed"; break; - case 'C': which = "known to be cursed"; break; - case 'X': You( - "have no objects whose blessed/uncursed/cursed status is unknown."); - break; /* better phrasing is desirable */ - default: which = "such"; break; - } - if (which) - You("have no %s objects.", which); - return 0; + switch (c) { + case 'B': + which = "known to be blessed"; + break; + case 'U': + which = "known to be uncursed"; + break; + case 'C': + which = "known to be cursed"; + break; + case 'X': + You("have no objects whose blessed/uncursed/cursed status is " + "unknown."); + break; /* better phrasing is desirable */ + default: + which = "such"; + break; + } + if (which) + You("have no %s objects.", which); + return 0; } this_type = oclass; } if (query_objlist((char *) 0, invent, - (flags.invlet_constant ? USE_INVLET : 0)|INVORDER_SORT, - &pick_list, PICK_NONE, this_type_only) > 0) - free((genericptr_t)pick_list); + (flags.invlet_constant ? USE_INVLET : 0) + | INVORDER_SORT, + &pick_list, PICK_NONE, this_type_only) > 0) + free((genericptr_t) pick_list); return 0; } @@ -2396,57 +2558,68 @@ char *buf; if (IS_DOOR(ltyp)) { switch (lev->doormask) { - case D_NODOOR: cmap = S_ndoor; break; /* "doorway" */ - case D_ISOPEN: cmap = S_vodoor; break; /* "open door" */ - case D_BROKEN: dfeature = "broken door"; break; - default: cmap = S_vcdoor; break; /* "closed door" */ + case D_NODOOR: + cmap = S_ndoor; + break; /* "doorway" */ + case D_ISOPEN: + cmap = S_vodoor; + break; /* "open door" */ + case D_BROKEN: + dfeature = "broken door"; + break; + default: + cmap = S_vcdoor; + break; /* "closed door" */ } /* override door description for open drawbridge */ if (is_drawbridge_wall(x, y) >= 0) - dfeature = "open drawbridge portcullis", cmap = -1; + dfeature = "open drawbridge portcullis", cmap = -1; } else if (IS_FOUNTAIN(ltyp)) - cmap = S_fountain; /* "fountain" */ + cmap = S_fountain; /* "fountain" */ else if (IS_THRONE(ltyp)) - cmap = S_throne; /* "opulent throne" */ - else if (is_lava(x,y)) - cmap = S_lava; /* "molten lava" */ - else if (is_ice(x,y)) - cmap = S_ice; /* "ice" */ - else if (is_pool(x,y)) + cmap = S_throne; /* "opulent throne" */ + else if (is_lava(x, y)) + cmap = S_lava; /* "molten lava" */ + else if (is_ice(x, y)) + cmap = S_ice; /* "ice" */ + else if (is_pool(x, y)) dfeature = "pool of water"; else if (IS_SINK(ltyp)) - cmap = S_sink; /* "sink" */ + cmap = S_sink; /* "sink" */ else if (IS_ALTAR(ltyp)) { Sprintf(altbuf, "%saltar to %s (%s)", - ((lev->altarmask & AM_SHRINE) && - (Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) ? - "high " : "", - a_gname(), - align_str(Amask2align(lev->altarmask & ~AM_SHRINE))); + ((lev->altarmask & AM_SHRINE) + && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) + ? "high " + : "", + a_gname(), + align_str(Amask2align(lev->altarmask & ~AM_SHRINE))); dfeature = altbuf; - } else if ((x == xupstair && y == yupstair) || - (x == sstairs.sx && y == sstairs.sy && sstairs.up)) - cmap = S_upstair; /* "staircase up" */ - else if ((x == xdnstair && y == ydnstair) || - (x == sstairs.sx && y == sstairs.sy && !sstairs.up)) - cmap = S_dnstair; /* "staircase down" */ + } else if ((x == xupstair && y == yupstair) + || (x == sstairs.sx && y == sstairs.sy && sstairs.up)) + cmap = S_upstair; /* "staircase up" */ + else if ((x == xdnstair && y == ydnstair) + || (x == sstairs.sx && y == sstairs.sy && !sstairs.up)) + cmap = S_dnstair; /* "staircase down" */ else if (x == xupladder && y == yupladder) - cmap = S_upladder; /* "ladder up" */ + cmap = S_upladder; /* "ladder up" */ else if (x == xdnladder && y == ydnladder) - cmap = S_dnladder; /* "ladder down" */ + cmap = S_dnladder; /* "ladder down" */ else if (ltyp == DRAWBRIDGE_DOWN) - cmap = S_vodbridge; /* "lowered drawbridge" */ + cmap = S_vodbridge; /* "lowered drawbridge" */ else if (ltyp == DBWALL) - cmap = S_vcdbridge; /* "raised drawbridge" */ + cmap = S_vcdbridge; /* "raised drawbridge" */ else if (IS_GRAVE(ltyp)) - cmap = S_grave; /* "grave" */ + cmap = S_grave; /* "grave" */ else if (ltyp == TREE) - cmap = S_tree; /* "tree" */ + cmap = S_tree; /* "tree" */ else if (ltyp == IRONBARS) dfeature = "set of iron bars"; - if (cmap >= 0) dfeature = defsyms[cmap].explanation; - if (dfeature) Strcpy(buf, dfeature); + if (cmap >= 0) + dfeature = defsyms[cmap].explanation; + if (dfeature) + Strcpy(buf, dfeature); return dfeature; } @@ -2454,13 +2627,13 @@ char *buf; don't show them unless obj_cnt is 0 */ int look_here(obj_cnt, picked_some) -int obj_cnt; /* obj_cnt > 0 implies that autopickup is in progess */ +int obj_cnt; /* obj_cnt > 0 implies that autopickup is in progess */ boolean picked_some; { struct obj *otmp; struct trap *trap; const char *verb = Blind ? "feel" : "see"; - const char *dfeature = (char *)0; + const char *dfeature = (char *) 0; char fbuf[BUFSZ], fbuf2[BUFSZ]; winid tmpwin; boolean skip_objects, felt_cockatrice = FALSE; @@ -2470,28 +2643,31 @@ boolean picked_some; skip_objects = (flags.pile_limit > 0 && obj_cnt >= flags.pile_limit); if (u.uswallow && u.ustuck) { struct monst *mtmp = u.ustuck; - Sprintf(fbuf, "Contents of %s %s", - s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH)); + Sprintf(fbuf, "Contents of %s %s", s_suffix(mon_nam(mtmp)), + mbodypart(mtmp, STOMACH)); /* Skip "Contents of " by using fbuf index 12 */ - You("%s to %s what is lying in %s.", - Blind ? "try" : "look around", verb, &fbuf[12]); + You("%s to %s what is lying in %s.", Blind ? "try" : "look around", + verb, &fbuf[12]); otmp = mtmp->minvent; if (otmp) { - for ( ; otmp; otmp = otmp->nobj) { - /* If swallower is an animal, it should have become stone but... */ - if (otmp->otyp == CORPSE) feel_cockatrice(otmp, FALSE); - } - if (Blind) Strcpy(fbuf, "You feel"); - Strcat(fbuf,":"); + for (; otmp; otmp = otmp->nobj) { + /* If swallower is an animal, it should have become stone + * but... */ + if (otmp->otyp == CORPSE) + feel_cockatrice(otmp, FALSE); + } + if (Blind) + Strcpy(fbuf, "You feel"); + Strcat(fbuf, ":"); (void) display_minventory(mtmp, MINV_ALL, fbuf); } else { - You("%s no objects here.", verb); + You("%s no objects here.", verb); } - return(!!Blind); + return (!!Blind); } - if (!skip_objects && (trap = t_at(u.ux,u.uy)) && trap->tseen) + if (!skip_objects && (trap = t_at(u.ux, u.uy)) && trap->tseen) There("is %s here.", - an(defsyms[trap_to_defsym(trap->ttyp)].explanation)); + an(defsyms[trap_to_defsym(trap->ttyp)].explanation)); otmp = level.objects[u.ux][u.uy]; dfeature = dfeature_at(u.ux, u.uy, fbuf2); @@ -2505,91 +2681,98 @@ boolean picked_some; /* don't say "altar" twice, dfeature has more info */ You("try to feel what is here."); } else { - const char *where = (Blind && !can_reach_floor(TRUE)) ? - "lying beneath you" : "lying here on the ", - *onwhat = (Blind && !can_reach_floor(TRUE)) ? - "" : surface(u.ux,u.uy); + const char *where = (Blind && !can_reach_floor(TRUE)) + ? "lying beneath you" + : "lying here on the ", + *onwhat = (Blind && !can_reach_floor(TRUE)) + ? "" + : surface(u.ux, u.uy); - You("try to feel what is %s%s.", - drift ? "floating here" : where, - drift ? "" : onwhat); + You("try to feel what is %s%s.", drift ? "floating here" : where, + drift ? "" : onwhat); } - if (dfeature && !drift && !strcmp(dfeature, surface(u.ux,u.uy))) - dfeature = 0; /* ice already identifed */ + if (dfeature && !drift && !strcmp(dfeature, surface(u.ux, u.uy))) + dfeature = 0; /* ice already identifed */ if (!can_reach_floor(TRUE)) { pline("But you can't reach it!"); - return(0); + return (0); } } if (dfeature) Sprintf(fbuf, "There is %s here.", an(dfeature)); - if (!otmp || is_lava(u.ux,u.uy) || (is_pool(u.ux,u.uy) && !Underwater)) { - if (dfeature) pline1(fbuf); + if (!otmp || is_lava(u.ux, u.uy) + || (is_pool(u.ux, u.uy) && !Underwater)) { + if (dfeature) + pline1(fbuf); read_engr_at(u.ux, u.uy); /* Eric Backus */ if (!skip_objects && (Blind || !dfeature)) You("%s no objects here.", verb); - return(!!Blind); + return (!!Blind); } /* we know there is something here */ if (skip_objects) { - if (dfeature) pline1(fbuf); + if (dfeature) + pline1(fbuf); read_engr_at(u.ux, u.uy); /* Eric Backus */ if (obj_cnt == 1 && otmp->quan == 1L) - There("is %s object here.", picked_some ? "another" : "an"); + There("is %s object here.", picked_some ? "another" : "an"); else - There("are %s%s objects here.", - (obj_cnt < 5) ? "a few" : - (obj_cnt < 10) ? "several" : "many", - picked_some ? " more" : ""); - for ( ; otmp; otmp = otmp->nexthere) - if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) { - pline("%s %s%s.", - (obj_cnt > 1) ? "Including" : - (otmp->quan > 1L) ? "They're" : "It's", - corpse_xname(otmp, (const char *)0, CXN_ARTICLE), - poly_when_stoned(youmonst.data) ? "" : - ", unfortunately"); - feel_cockatrice(otmp, FALSE); - break; - } + There("are %s%s objects here.", + (obj_cnt < 5) ? "a few" : (obj_cnt < 10) ? "several" + : "many", + picked_some ? " more" : ""); + for (; otmp; otmp = otmp->nexthere) + if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) { + pline("%s %s%s.", + (obj_cnt > 1) ? "Including" + : (otmp->quan > 1L) ? "They're" : "It's", + corpse_xname(otmp, (const char *) 0, CXN_ARTICLE), + poly_when_stoned(youmonst.data) ? "" + : ", unfortunately"); + feel_cockatrice(otmp, FALSE); + break; + } } else if (!otmp->nexthere) { /* only one object */ - if (dfeature) pline1(fbuf); + if (dfeature) + pline1(fbuf); read_engr_at(u.ux, u.uy); /* Eric Backus */ You("%s here %s.", verb, doname(otmp)); iflags.last_msg = PLNMSG_ONE_ITEM_HERE; - if (otmp->otyp == CORPSE) feel_cockatrice(otmp, FALSE); + if (otmp->otyp == CORPSE) + feel_cockatrice(otmp, FALSE); } else { char buf[BUFSZ]; display_nhwindow(WIN_MESSAGE, FALSE); tmpwin = create_nhwindow(NHW_MENU); - if(dfeature) { - putstr(tmpwin, 0, fbuf); - putstr(tmpwin, 0, ""); + if (dfeature) { + putstr(tmpwin, 0, fbuf); + putstr(tmpwin, 0, ""); } Sprintf(buf, "%s that %s here:", - picked_some ? "Other things" : "Things", - Blind ? "you feel" : "are"); + picked_some ? "Other things" : "Things", + Blind ? "you feel" : "are"); putstr(tmpwin, 0, buf); - for ( ; otmp; otmp = otmp->nexthere) { - if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) { - felt_cockatrice = TRUE; - Sprintf(buf, "%s...", doname(otmp)); - putstr(tmpwin, 0, buf); - break; - } - putstr(tmpwin, 0, doname(otmp)); + for (; otmp; otmp = otmp->nexthere) { + if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) { + felt_cockatrice = TRUE; + Sprintf(buf, "%s...", doname(otmp)); + putstr(tmpwin, 0, buf); + break; + } + putstr(tmpwin, 0, doname(otmp)); } display_nhwindow(tmpwin, TRUE); destroy_nhwindow(tmpwin); - if (felt_cockatrice) feel_cockatrice(otmp, FALSE); + if (felt_cockatrice) + feel_cockatrice(otmp, FALSE); read_engr_at(u.ux, u.uy); /* Eric Backus */ } - return(!!Blind); + return (!!Blind); } /* explicilty look at what is here, including all objects */ @@ -2604,9 +2787,8 @@ will_feel_cockatrice(otmp, force_touch) struct obj *otmp; boolean force_touch; { - if ((Blind || force_touch) && !uarmg && !Stone_resistance && - (otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm]))) + if ((Blind || force_touch) && !uarmg && !Stone_resistance + && (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]))) return TRUE; return FALSE; } @@ -2620,13 +2802,13 @@ boolean force_touch; if (will_feel_cockatrice(otmp, force_touch)) { /* "the corpse" */ - Strcpy(kbuf, corpse_xname(otmp, (const char *)0, CXN_PFX_THE)); + Strcpy(kbuf, corpse_xname(otmp, (const char *) 0, CXN_PFX_THE)); if (poly_when_stoned(youmonst.data)) - You("touched %s with your bare %s.", - kbuf, makeplural(body_part(HAND))); + You("touched %s with your bare %s.", kbuf, + makeplural(body_part(HAND))); else - pline("Touching %s is a fatal mistake...", kbuf); + pline("Touching %s is a fatal mistake...", kbuf); /* normalize body shape here; hand, not body_part(HAND) */ Sprintf(kbuf, "touching %s bare-handed", killer_xname(otmp)); /* will call polymon() for the poly_when_stoned() case */ @@ -2640,61 +2822,61 @@ struct obj *obj; { struct obj *otmp; - for(otmp = level.objects[obj->ox][obj->oy]; otmp; otmp = otmp->nexthere) - if(otmp != obj && merged(&obj,&otmp)) + for (otmp = level.objects[obj->ox][obj->oy]; otmp; otmp = otmp->nexthere) + if (otmp != obj && merged(&obj, &otmp)) break; return; } STATIC_OVL boolean -mergable(otmp, obj) /* returns TRUE if obj & otmp can be merged */ - register struct obj *otmp, *obj; +mergable(otmp, obj) /* returns TRUE if obj & otmp can be merged */ +register struct obj *otmp, *obj; { int objnamelth = 0, otmpnamelth = 0; - if (obj == otmp) return FALSE; /* already the same object */ - if (obj->otyp != otmp->otyp) return FALSE; + if (obj == otmp) + return FALSE; /* already the same object */ + if (obj->otyp != otmp->otyp) + return FALSE; /* coins of the same kind will always merge */ - if (obj->oclass == COIN_CLASS) return TRUE; - if (obj->unpaid != otmp->unpaid || - obj->spe != otmp->spe || obj->dknown != otmp->dknown || - (obj->bknown != otmp->bknown && !Role_if(PM_PRIEST)) || - obj->cursed != otmp->cursed || obj->blessed != otmp->blessed || - obj->no_charge != otmp->no_charge || - obj->obroken != otmp->obroken || - obj->otrapped != otmp->otrapped || - obj->lamplit != otmp->lamplit || - obj->greased != otmp->greased || - obj->oeroded != otmp->oeroded || - obj->oeroded2 != otmp->oeroded2 || - obj->bypass != otmp->bypass) - return(FALSE); + if (obj->oclass == COIN_CLASS) + return TRUE; + if (obj->unpaid != otmp->unpaid || obj->spe != otmp->spe + || obj->dknown != otmp->dknown + || (obj->bknown != otmp->bknown && !Role_if(PM_PRIEST)) + || obj->cursed != otmp->cursed || obj->blessed != otmp->blessed + || obj->no_charge != otmp->no_charge || obj->obroken != otmp->obroken + || obj->otrapped != otmp->otrapped || obj->lamplit != otmp->lamplit + || obj->greased != otmp->greased || obj->oeroded != otmp->oeroded + || obj->oeroded2 != otmp->oeroded2 || obj->bypass != otmp->bypass) + return (FALSE); - if (obj->nomerge) /* explicitly marked to prevent merge */ + if (obj->nomerge) /* explicitly marked to prevent merge */ return FALSE; - if ((obj->oclass==WEAPON_CLASS || obj->oclass==ARMOR_CLASS) && - (obj->oerodeproof!=otmp->oerodeproof || obj->rknown!=otmp->rknown)) + if ((obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS) + && (obj->oerodeproof != otmp->oerodeproof + || obj->rknown != otmp->rknown)) return FALSE; - if (obj->oclass == FOOD_CLASS && (obj->oeaten != otmp->oeaten || - obj->orotten != otmp->orotten)) - return(FALSE); + if (obj->oclass == FOOD_CLASS + && (obj->oeaten != otmp->oeaten || obj->orotten != otmp->orotten)) + return (FALSE); if (obj->otyp == CORPSE || obj->otyp == EGG || obj->otyp == TIN) { if (obj->corpsenm != otmp->corpsenm) - return FALSE; + return FALSE; } /* hatching eggs don't merge; ditto for revivable corpses */ - if ((obj->otyp == EGG && (obj->timed || otmp->timed)) || - (obj->otyp == CORPSE && otmp->corpsenm >= LOW_PM && - is_reviver(&mons[otmp->corpsenm]))) + if ((obj->otyp == EGG && (obj->timed || otmp->timed)) + || (obj->otyp == CORPSE && otmp->corpsenm >= LOW_PM + && is_reviver(&mons[otmp->corpsenm]))) return FALSE; /* allow candle merging only if their ages are close */ /* see begin_burn() for a reference for the magic "25" */ - if (Is_candle(obj) && obj->age/25 != otmp->age/25) - return(FALSE); + if (Is_candle(obj) && obj->age / 25 != otmp->age / 25) + return (FALSE); /* burning potions of oil never merge */ if (obj->otyp == POT_OIL && obj->lamplit) @@ -2707,24 +2889,24 @@ mergable(otmp, obj) /* returns TRUE if obj & otmp can be merged */ /* if they have names, make sure they're the same */ objnamelth = strlen(safe_oname(obj)); otmpnamelth = strlen(safe_oname(otmp)); - if ( (objnamelth != otmpnamelth && - ((objnamelth && otmpnamelth) || obj->otyp == CORPSE) - ) || - (objnamelth && otmpnamelth && - strncmp(ONAME(obj), ONAME(otmp), objnamelth))) + if ((objnamelth != otmpnamelth + && ((objnamelth && otmpnamelth) || obj->otyp == CORPSE)) + || (objnamelth && otmpnamelth + && strncmp(ONAME(obj), ONAME(otmp), objnamelth))) return FALSE; /* for the moment, any additional information is incompatible */ - if (has_omonst(obj) || has_omid(obj) || has_olong(obj) || - has_omonst(otmp) || has_omid(otmp) || has_olong(otmp)) + if (has_omonst(obj) || has_omid(obj) || has_olong(obj) || has_omonst(otmp) + || has_omid(otmp) || has_olong(otmp)) return FALSE; - if(obj->oartifact != otmp->oartifact) return FALSE; + if (obj->oartifact != otmp->oartifact) + return FALSE; - if(obj->known == otmp->known || - !objects[otmp->otyp].oc_uses_known) { - return((boolean)(objects[obj->otyp].oc_merge)); - } else return(FALSE); + if (obj->known == otmp->known || !objects[otmp->otyp].oc_uses_known) { + return ((boolean)(objects[obj->otyp].oc_merge)); + } else + return (FALSE); } int @@ -2732,8 +2914,8 @@ doprgold() { /* the messages used to refer to "carrying gold", but that didn't take containers into account */ - long umoney = money_cnt(invent); - if(!umoney) + long umoney = money_cnt(invent); + if (!umoney) Your("wallet is empty."); else Your("wallet contains %ld %s.", umoney, currency(umoney)); @@ -2745,10 +2927,11 @@ int doprwep() { if (!uwep) { - You("are empty %s.", body_part(HANDED)); + You("are empty %s.", body_part(HANDED)); } else { - prinv((char *)0, uwep, 0L); - if (u.twoweap) prinv((char *)0, uswapwep, 0L); + prinv((char *) 0, uwep, 0L); + if (u.twoweap) + prinv((char *) 0, uswapwep, 0L); } return 0; } @@ -2759,19 +2942,21 @@ noarmor(report_uskin) boolean report_uskin; { if (!uskin || !report_uskin) { - You("are not wearing any armor."); + You("are not wearing any armor."); } else { - char *p, *uskinname, buf[BUFSZ]; + char *p, *uskinname, buf[BUFSZ]; - uskinname = strcpy(buf, simpleonames(uskin)); - /* shorten "set of dragon scales" to " scales" - and " dragon scale mail" to " scale mail" */ - if (!strncmpi(uskinname, "set of ", 7)) uskinname += 7; - if ((p = strstri(uskinname, " dragon ")) != 0) - while ((p[1] = p[8]) != '\0') ++p; + uskinname = strcpy(buf, simpleonames(uskin)); + /* shorten "set of dragon scales" to " scales" + and " dragon scale mail" to " scale mail" */ + if (!strncmpi(uskinname, "set of ", 7)) + uskinname += 7; + if ((p = strstri(uskinname, " dragon ")) != 0) + while ((p[1] = p[8]) != '\0') + ++p; - You("are not wearing armor but have %s embedded in your skin.", - uskinname); + You("are not wearing armor but have %s embedded in your skin.", + uskinname); } } @@ -2784,13 +2969,20 @@ doprarm() char lets[8]; register int ct = 0; - if(uarmu) lets[ct++] = obj_to_let(uarmu); - if(uarm) lets[ct++] = obj_to_let(uarm); - if(uarmc) lets[ct++] = obj_to_let(uarmc); - if(uarmh) lets[ct++] = obj_to_let(uarmh); - if(uarms) lets[ct++] = obj_to_let(uarms); - if(uarmg) lets[ct++] = obj_to_let(uarmg); - if(uarmf) lets[ct++] = obj_to_let(uarmf); + if (uarmu) + lets[ct++] = obj_to_let(uarmu); + if (uarm) + lets[ct++] = obj_to_let(uarm); + if (uarmc) + lets[ct++] = obj_to_let(uarmc); + if (uarmh) + lets[ct++] = obj_to_let(uarmh); + if (uarms) + lets[ct++] = obj_to_let(uarms); + if (uarmg) + lets[ct++] = obj_to_let(uarmg); + if (uarmf) + lets[ct++] = obj_to_let(uarmf); lets[ct] = 0; (void) display_inventory(lets, FALSE); } @@ -2800,14 +2992,16 @@ doprarm() int doprring() { - if(!uleft && !uright) + if (!uleft && !uright) You("are not wearing any rings."); else { char lets[3]; register int ct = 0; - if(uleft) lets[ct++] = obj_to_let(uleft); - if(uright) lets[ct++] = obj_to_let(uright); + if (uleft) + lets[ct++] = obj_to_let(uleft); + if (uright) + lets[ct++] = obj_to_let(uright); lets[ct] = 0; (void) display_inventory(lets, FALSE); } @@ -2820,7 +3014,7 @@ dopramulet() if (!uamul) You("are not wearing an amulet."); else - prinv((char *)0, uamul, 0L); + prinv((char *) 0, uamul, 0L); return 0; } @@ -2828,10 +3022,12 @@ STATIC_OVL boolean tool_in_use(obj) struct obj *obj; { - if ((obj->owornmask & (W_TOOL | W_SADDLE)) != 0L) return TRUE; - if (obj->oclass != TOOL_CLASS) return FALSE; - return (boolean)(obj == uwep || obj->lamplit || - (obj->otyp == LEASH && obj->leashmon)); + if ((obj->owornmask & (W_TOOL | W_SADDLE)) != 0L) + return TRUE; + if (obj->oclass != TOOL_CLASS) + return FALSE; + return (boolean)(obj == uwep || obj->lamplit + || (obj->otyp == LEASH && obj->leashmon)); } int @@ -2839,14 +3035,16 @@ doprtool() { struct obj *otmp; int ct = 0; - char lets[52+1]; + char lets[52 + 1]; for (otmp = invent; otmp; otmp = otmp->nobj) if (tool_in_use(otmp)) - lets[ct++] = obj_to_let(otmp); + lets[ct++] = obj_to_let(otmp); lets[ct] = '\0'; - if (!ct) You("are not using any tools."); - else (void) display_inventory(lets, FALSE); + if (!ct) + You("are not using any tools."); + else + (void) display_inventory(lets, FALSE); return 0; } @@ -2857,14 +3055,16 @@ doprinuse() { struct obj *otmp; int ct = 0; - char lets[52+1]; + char lets[52 + 1]; for (otmp = invent; otmp; otmp = otmp->nobj) if (is_worn(otmp) || tool_in_use(otmp)) - lets[ct++] = obj_to_let(otmp); + lets[ct++] = obj_to_let(otmp); lets[ct] = '\0'; - if (!ct) You("are not wearing or wielding anything."); - else (void) display_inventory(lets, FALSE); + if (!ct) + You("are not wearing or wielding anything."); + else + (void) display_inventory(lets, FALSE); return 0; } @@ -2885,10 +3085,11 @@ long numused; otmp = splitobj(obj, numused); else otmp = obj; - if(costly_spot(otmp->ox, otmp->oy)) { - if(index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0))) + if (costly_spot(otmp->ox, otmp->oy)) { + if (index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0))) addtobill(otmp, FALSE, FALSE, FALSE); - else (void)stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE); + else + (void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE); } delobj(otmp); if (at_u && u.uundetected && hides_under(youmonst.data)) @@ -2899,32 +3100,26 @@ long numused; * Conversion from a class to a string for printing. * This must match the object class order. */ -STATIC_VAR NEARDATA const char *names[] = { 0, - "Illegal objects", "Weapons", "Armor", "Rings", "Amulets", - "Tools", "Comestibles", "Potions", "Scrolls", "Spellbooks", - "Wands", "Coins", "Gems/Stones", "Boulders/Statues", "Iron balls", - "Chains", "Venoms" +STATIC_VAR NEARDATA const char *names[] = { + 0, "Illegal objects", "Weapons", "Armor", "Rings", "Amulets", "Tools", + "Comestibles", "Potions", "Scrolls", "Spellbooks", "Wands", "Coins", + "Gems/Stones", "Boulders/Statues", "Iron balls", "Chains", "Venoms" }; -static NEARDATA const char oth_symbols[] = { - CONTAINED_SYM, - '\0' -}; +static NEARDATA const char oth_symbols[] = { CONTAINED_SYM, '\0' }; -static NEARDATA const char *oth_names[] = { - "Bagged/Boxed items" -}; +static NEARDATA const char *oth_names[] = { "Bagged/Boxed items" }; -static NEARDATA char *invbuf = (char *)0; +static NEARDATA char *invbuf = (char *) 0; static NEARDATA unsigned invbufsiz = 0; char * -let_to_name(let,unpaid,showsym) +let_to_name(let, unpaid, showsym) char let; -boolean unpaid,showsym; +boolean unpaid, showsym; { - const char *ocsymfmt = " ('%c')"; - const int invbuf_sympadding = 8; /* arbitrary */ + const char *ocsymfmt = " ('%c')"; + const int invbuf_sympadding = 8; /* arbitrary */ const char *class_name; const char *pos; int oclass = (let >= 1 && let < MAXOCLASSES) ? let : 0; @@ -2937,10 +3132,11 @@ boolean unpaid,showsym; else class_name = names[0]; - len = strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof "") + - (oclass ? (strlen(ocsymfmt)+invbuf_sympadding) : 0); + len = strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof "") + + (oclass ? (strlen(ocsymfmt) + invbuf_sympadding) : 0); if (len > invbufsiz) { - if (invbuf) free((genericptr_t)invbuf); + if (invbuf) + free((genericptr_t) invbuf); invbufsiz = len + 10; /* add slop to reduce incremental realloc */ invbuf = (char *) alloc(invbufsiz); } @@ -2948,15 +3144,16 @@ boolean unpaid,showsym; Strcat(strcpy(invbuf, "Unpaid "), class_name); else Strcpy(invbuf, class_name); - if ((oclass != 0) && showsym) { - char *bp = eos(invbuf); - int mlen = invbuf_sympadding - strlen(class_name); - while (--mlen > 0) { - *bp = ' '; bp++; - } - *bp = '\0'; - Sprintf(eos(invbuf), ocsymfmt, def_oc_syms[oclass].sym); - } + if ((oclass != 0) && showsym) { + char *bp = eos(invbuf); + int mlen = invbuf_sympadding - strlen(class_name); + while (--mlen > 0) { + *bp = ' '; + bp++; + } + *bp = '\0'; + Sprintf(eos(invbuf), ocsymfmt, def_oc_syms[oclass].sym); + } return invbuf; } @@ -2964,7 +3161,8 @@ boolean unpaid,showsym; void free_invbuf() { - if (invbuf) free((genericptr_t)invbuf), invbuf = (char *)0; + if (invbuf) + free((genericptr_t) invbuf), invbuf = (char *) 0; invbufsiz = 0; } @@ -2979,24 +3177,26 @@ reassign() /* first, remove [first instance of] gold from invent, if present */ prevobj = goldobj = 0; for (obj = invent; obj; prevobj = obj, obj = obj->nobj) - if (obj->oclass == COIN_CLASS) { - goldobj = obj; - if (prevobj) - prevobj->nobj = goldobj->nobj; - else - invent = goldobj->nobj; - break; - } + if (obj->oclass == COIN_CLASS) { + goldobj = obj; + if (prevobj) + prevobj->nobj = goldobj->nobj; + else + invent = goldobj->nobj; + break; + } /* second, re-letter the rest of the list */ for (obj = invent, i = 0; obj; obj = obj->nobj, i++) - obj->invlet = (i < 26) ? ('a'+i) : (i < 52) ? ('A'+i-26) : NOINVSYM; + obj->invlet = + (i < 26) ? ('a' + i) : (i < 52) ? ('A' + i - 26) : NOINVSYM; /* third, assign gold the "letter" '$' and re-insert it at head */ if (goldobj) { - goldobj->invlet = GOLD_SYM; - goldobj->nobj = invent; - invent = goldobj; + goldobj->invlet = GOLD_SYM; + goldobj->nobj = invent; + invent = goldobj; } - if (i >= 52) i = 52 - 1; + if (i >= 52) + i = 52 - 1; lastinvnr = i; } @@ -3024,15 +3224,14 @@ reassign() * user-assigned names, the 'count' portion being moved is * effectively renamed so that it will merge with 'to' stack. */ -int -doorganize() /* inventory organizer by Del Lamb */ +int doorganize() /* inventory organizer by Del Lamb */ { struct obj *obj, *otmp, *splitting, *bumped; int ix, cur, trycnt; char let; - char alphabet[52+1], buf[52+1]; + char alphabet[52 + 1], buf[52 + 1]; char qbuf[QBUFSZ]; - char allowall[3]; /* { ALLOW_COUNT, ALL_CLASSES, 0 } */ + char allowall[3]; /* { ALLOW_COUNT, ALL_CLASSES, 0 } */ const char *adj_type; if (!invent) { @@ -3040,24 +3239,29 @@ doorganize() /* inventory organizer by Del Lamb */ return 0; } - if (!flags.invlet_constant) reassign(); + if (!flags.invlet_constant) + reassign(); /* get object the user wants to organize (the 'from' slot) */ allowall[0] = ALLOW_COUNT; allowall[1] = ALL_CLASSES; allowall[2] = '\0'; - if (!(obj = getobj(allowall,"adjust"))) return(0); + if (!(obj = getobj(allowall, "adjust"))) + return (0); /* figure out whether user gave a split count to getobj() */ splitting = bumped = 0; for (otmp = invent; otmp; otmp = otmp->nobj) - if (otmp->nobj == obj) { /* knowledge of splitobj() operation */ - if (otmp->invlet == obj->invlet) splitting = otmp; - break; + if (otmp->nobj == obj) { /* knowledge of splitobj() operation */ + if (otmp->invlet == obj->invlet) + splitting = otmp; + break; } /* initialize the list with all lower and upper case letters */ - for (ix = 0, let = 'a'; let <= 'z'; ) alphabet[ix++] = let++; - for (let = 'A'; let <= 'Z'; ) alphabet[ix++] = let++; + for (ix = 0, let = 'a'; let <= 'z';) + alphabet[ix++] = let++; + for (let = 'A'; let <= 'Z';) + alphabet[ix++] = let++; alphabet[ix] = '\0'; /* for floating inv letters, truncate list after the first open slot */ if (!flags.invlet_constant && (ix = inv_cnt(FALSE)) < 52) @@ -3067,45 +3271,52 @@ doorganize() /* inventory organizer by Del Lamb */ /* except those that will be merged with the selected object */ for (otmp = invent; otmp; otmp = otmp->nobj) if (otmp != obj && !mergable(otmp, obj)) { - let = otmp->invlet; - if (let >= 'a' && let <= 'z') - alphabet[let - 'a'] = ' '; - else if (let >= 'A' && let <= 'Z') - alphabet[let - 'A' + 26] = ' '; + let = otmp->invlet; + if (let >= 'a' && let <= 'z') + alphabet[let - 'a'] = ' '; + else if (let >= 'A' && let <= 'Z') + alphabet[let - 'A' + 26] = ' '; } /* compact the list by removing all the blanks */ for (ix = cur = 0; alphabet[ix]; ix++) - if (alphabet[ix] != ' ') buf[cur++] = alphabet[ix]; - if (!cur && obj->invlet == NOINVSYM) buf[cur++] = NOINVSYM; + if (alphabet[ix] != ' ') + buf[cur++] = alphabet[ix]; + if (!cur && obj->invlet == NOINVSYM) + buf[cur++] = NOINVSYM; buf[cur] = '\0'; /* and by dashing runs of letters */ - if(cur > 5) compactify(buf); + if (cur > 5) + compactify(buf); /* get 'to' slot to use as destination */ Sprintf(qbuf, "Adjust letter to what [%s]%s?", buf, - invent ? " (? see used letters)" : ""); - for (trycnt = 1; ; ++trycnt) { - let = yn_function(qbuf, (char *)0, '\0'); - if(let == '?' || let == '*') { - let = display_used_invlets(splitting ? obj->invlet : 0); - if (!let) continue; - if (let == '\033') goto noadjust; + invent ? " (? see used letters)" : ""); + for (trycnt = 1;; ++trycnt) { + let = yn_function(qbuf, (char *) 0, '\0'); + if (let == '?' || let == '*') { + let = display_used_invlets(splitting ? obj->invlet : 0); + if (!let) + continue; + if (let == '\033') + goto noadjust; } if (index(quitchars, let) || /* adjusting to same slot is meaningful since all compatible stacks get collected along the way, but splitting to same slot is not */ (splitting && let == obj->invlet)) { - noadjust: - if (splitting) (void) merged(&splitting, &obj); - pline1(Never_mind); - return 0; + noadjust: + if (splitting) + (void) merged(&splitting, &obj); + pline1(Never_mind); + return 0; } if ((letter(let) && let != '@') || index(buf, let)) - break; /* got one */ - if (trycnt == 5) goto noadjust; - pline("Select an inventory slot letter."); /* else try again */ + break; /* got one */ + if (trycnt == 5) + goto noadjust; + pline("Select an inventory slot letter."); /* else try again */ } /* change the inventory and print the resulting item */ @@ -3117,54 +3328,56 @@ doorganize() /* inventory organizer by Del Lamb */ */ extract_nobj(obj, &invent); - for (otmp = invent; otmp; ) { + for (otmp = invent; otmp;) { if (!splitting) { - if (merged(&otmp, &obj)) { - adj_type = "Merging:"; - obj = otmp; - otmp = otmp->nobj; - extract_nobj(obj, &invent); - continue; /* otmp has already been updated */ - } else if (otmp->invlet == let) { - adj_type = "Swapping:"; - otmp->invlet = obj->invlet; - } - } else { - /* splitting: don't merge extra compatible stacks; - if destination is compatible, do merge with it, - otherwise bump whatever is there to an open slot */ - if (otmp->invlet == let) { - int olth = 0; - - if (has_oname(obj)) olth = strlen(ONAME(obj)); - /* ugly hack: if these objects aren't going to merge - solely because they have conflicting user-assigned - names, strip off the name of the one being moved */ - if (olth && !obj->oartifact && !mergable(otmp, obj)) { - char *holdname = ONAME(obj); - ONAME(obj) = (char *)0; - /* restore name iff merging is still not possible */ - if (!mergable(otmp, obj)) { - ONAME(obj) = holdname; - holdname = (char *)0; - } else free((genericptr_t)holdname); - } - if (merged(&otmp, &obj)) { - obj = otmp; - extract_nobj(obj, &invent); - } else if (inv_cnt(FALSE) >= 52) { - (void) merged(&splitting, &obj); /* undo split */ - /* "knapsack cannot accommodate any more items" */ - Your("pack is too full."); - return 0; - } else { - bumped = otmp; - extract_nobj(bumped, &invent); + adj_type = "Merging:"; + obj = otmp; + otmp = otmp->nobj; + extract_nobj(obj, &invent); + continue; /* otmp has already been updated */ + } else if (otmp->invlet == let) { + adj_type = "Swapping:"; + otmp->invlet = obj->invlet; } - break; - } /* found 'to' slot */ - } /* splitting */ + } else { + /* splitting: don't merge extra compatible stacks; + if destination is compatible, do merge with it, + otherwise bump whatever is there to an open slot */ + if (otmp->invlet == let) { + int olth = 0; + + if (has_oname(obj)) + olth = strlen(ONAME(obj)); + /* ugly hack: if these objects aren't going to merge + solely because they have conflicting user-assigned + names, strip off the name of the one being moved */ + if (olth && !obj->oartifact && !mergable(otmp, obj)) { + char *holdname = ONAME(obj); + ONAME(obj) = (char *) 0; + /* restore name iff merging is still not possible */ + if (!mergable(otmp, obj)) { + ONAME(obj) = holdname; + holdname = (char *) 0; + } else + free((genericptr_t) holdname); + } + + if (merged(&otmp, &obj)) { + obj = otmp; + extract_nobj(obj, &invent); + } else if (inv_cnt(FALSE) >= 52) { + (void) merged(&splitting, &obj); /* undo split */ + /* "knapsack cannot accommodate any more items" */ + Your("pack is too full."); + return 0; + } else { + bumped = otmp; + extract_nobj(bumped, &invent); + } + break; + } /* found 'to' slot */ + } /* splitting */ otmp = otmp->nobj; } @@ -3187,9 +3400,10 @@ doorganize() /* inventory organizer by Del Lamb */ /* messages deferred until inventory has been fully reestablished */ prinv(adj_type, obj, 0L); - if (bumped) prinv("Moving:", bumped, 0L); + if (bumped) + prinv("Moving:", bumped, 0L); update_inventory(); - return(0); + return (0); } /* common to display_minventory and display_cinventory */ @@ -3204,26 +3418,26 @@ const char *hdr, *txt; any = zeroany; win = create_nhwindow(NHW_MENU); start_menu(win); - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, hdr, MENU_UNSELECTED); + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, hdr, + MENU_UNSELECTED); add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, txt, MENU_UNSELECTED); - end_menu(win, (char *)0); + end_menu(win, (char *) 0); if (select_menu(win, PICK_NONE, &selected) > 0) - free((genericptr_t)selected); + free((genericptr_t) selected); destroy_nhwindow(win); return; } -/* query_objlist callback: return things that could possibly be worn/wielded */ +/* query_objlist callback: return things that could possibly be worn/wielded + */ STATIC_OVL boolean worn_wield_only(obj) struct obj *obj; { - return (obj->oclass == WEAPON_CLASS - || obj->oclass == ARMOR_CLASS - || obj->oclass == AMULET_CLASS - || obj->oclass == RING_CLASS - || obj->oclass == TOOL_CLASS); + return (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS + || obj->oclass == AMULET_CLASS || obj->oclass == RING_CLASS + || obj->oclass == TOOL_CLASS); } /* @@ -3249,11 +3463,10 @@ char *title; menu_item *selected = 0; int do_all = (dflags & MINV_ALL) != 0, incl_hero = (do_all && u.uswallow && mon == u.ustuck), - have_inv = (mon->minvent != 0), - have_any = (have_inv || incl_hero); + have_inv = (mon->minvent != 0), have_any = (have_inv || incl_hero); - Sprintf(tmp,"%s %s:", s_suffix(noit_Monnam(mon)), - do_all ? "possessions" : "armament"); + Sprintf(tmp, "%s %s:", s_suffix(noit_Monnam(mon)), + do_all ? "possessions" : "armament"); if (do_all ? have_any : (mon->misc_worn_check || MON_WEP(mon))) { /* Fool the 'weapon in hand' routine into @@ -3262,10 +3475,10 @@ char *title; youmonst.data = mon->data; n = query_objlist(title ? title : tmp, mon->minvent, - INVORDER_SORT | (incl_hero ? INCLUDE_HERO : 0), - &selected, - (dflags & MINV_NOLET) ? PICK_NONE : PICK_ONE, - do_all ? allow_all : worn_wield_only); + INVORDER_SORT | (incl_hero ? INCLUDE_HERO : 0), + &selected, + (dflags & MINV_NOLET) ? PICK_NONE : PICK_ONE, + do_all ? allow_all : worn_wield_only); set_uasmon(); } else { @@ -3275,7 +3488,7 @@ char *title; if (n > 0) { ret = selected[0].item.a_obj; - free((genericptr_t)selected); + free((genericptr_t) selected); } else ret = (struct obj *) 0; return ret; @@ -3294,19 +3507,19 @@ register struct obj *obj; int n; menu_item *selected = 0; - (void)safe_qbuf(qbuf, "Contents of ", ":", - obj, doname, ansimpleoname, "that"); + (void) safe_qbuf(qbuf, "Contents of ", ":", obj, doname, ansimpleoname, + "that"); if (obj->cobj) { n = query_objlist(qbuf, obj->cobj, INVORDER_SORT, &selected, - PICK_NONE, allow_all); + PICK_NONE, allow_all); } else { invdisp_nothing(qbuf, "(empty)"); n = 0; } if (n > 0) { ret = selected[0].item.a_obj; - free((genericptr_t)selected); + free((genericptr_t) selected); } else ret = (struct obj *) 0; obj->cknown = 1; @@ -3318,7 +3531,7 @@ static coord only; STATIC_OVL boolean only_here(obj) - struct obj *obj; +struct obj *obj; { return (obj->ox == only.x && obj->oy == only.y); } @@ -3341,17 +3554,17 @@ boolean as_if_seen; /* count # of objects here */ for (n = 0, obj = level.buriedobjlist; obj; obj = obj->nobj) if (obj->ox == x && obj->oy == y) { - if (as_if_seen) obj->dknown = 1; - n++; + if (as_if_seen) + obj->dknown = 1; + n++; } if (n) { only.x = x; only.y = y; - if (query_objlist("Things that are buried here:", - level.buriedobjlist, INVORDER_SORT, - &selected, PICK_NONE, only_here) > 0) - free((genericptr_t)selected); + if (query_objlist("Things that are buried here:", level.buriedobjlist, + INVORDER_SORT, &selected, PICK_NONE, only_here) > 0) + free((genericptr_t) selected); only.x = only.y = 0; } return n; diff --git a/src/light.c b/src/light.c index 48ccdceb4..c78757c79 100644 --- a/src/light.c +++ b/src/light.c @@ -1,11 +1,11 @@ -/* NetHack 3.6 light.c $NHDT-Date: 1426465436 2015/03/16 00:23:56 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.17 $ */ +/* NetHack 3.6 light.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */ /* NetHack 3.6 light.c $Date: 2009/05/06 10:46:38 $ $Revision: 1.15 $ */ /* SCCS Id: @(#)light.c 3.5 2009/01/20 */ /* Copyright (c) Dean Luick, 1994 */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -#include "lev.h" /* for checking save modes */ +#include "lev.h" /* for checking save modes */ /* * Mobile light sources. @@ -41,8 +41,8 @@ */ /* flags */ -#define LSF_SHOW 0x1 /* display the light source */ -#define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */ +#define LSF_SHOW 0x1 /* display the light source */ +#define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */ static light_source *light_base = 0; @@ -53,19 +53,18 @@ STATIC_DCL int FDECL(maybe_write_ls, (int, int, BOOLEAN_P)); extern char circle_data[]; extern char circle_start[]; - /* Create a new light source. */ void new_light_source(x, y, range, type, id) - xchar x, y; - int range, type; - anything *id; +xchar x, y; +int range, type; +anything *id; { light_source *ls; if (range > MAX_RADIUS || range < 1) { - impossible("new_light_source: illegal range %d", range); - return; + impossible("new_light_source: illegal range %d", range); + return; } ls = (light_source *) alloc(sizeof(light_source)); @@ -79,7 +78,7 @@ new_light_source(x, y, range, type, id) ls->flags = 0; light_base = ls; - vision_full_recalc = 1; /* make the source show up */ + vision_full_recalc = 1; /* make the source show up */ } /* @@ -88,8 +87,8 @@ new_light_source(x, y, range, type, id) */ void del_light_source(type, id) - int type; - anything *id; +int type; +anything *id; { light_source *curr, *prev; anything tmp_id; @@ -99,35 +98,40 @@ del_light_source(type, id) has only been partially restored during a level change (in particular: chameleon vs prot. from shape changers) */ switch (type) { - case LS_OBJECT: tmp_id.a_uint = id->a_obj->o_id; - break; - case LS_MONSTER: tmp_id.a_uint = id->a_monst->m_id; - break; - default: tmp_id.a_uint = 0; - break; + case LS_OBJECT: + tmp_id.a_uint = id->a_obj->o_id; + break; + case LS_MONSTER: + tmp_id.a_uint = id->a_monst->m_id; + break; + default: + tmp_id.a_uint = 0; + break; } for (prev = 0, curr = light_base; curr; prev = curr, curr = curr->next) { - if (curr->type != type) continue; - if (curr->id.a_obj == ((curr->flags & LSF_NEEDS_FIXUP) ? tmp_id.a_obj : id->a_obj)) { - if (prev) - prev->next = curr->next; - else - light_base = curr->next; + if (curr->type != type) + continue; + if (curr->id.a_obj + == ((curr->flags & LSF_NEEDS_FIXUP) ? tmp_id.a_obj : id->a_obj)) { + if (prev) + prev->next = curr->next; + else + light_base = curr->next; - free((genericptr_t)curr); - vision_full_recalc = 1; - return; - } + free((genericptr_t) curr); + vision_full_recalc = 1; + return; + } } - impossible("del_light_source: not found type=%d, id=%s", - type, fmt_ptr((genericptr_t)id->a_obj)); + impossible("del_light_source: not found type=%d, id=%s", type, + fmt_ptr((genericptr_t) id->a_obj)); } /* Mark locations that are temporarily lit via mobile light sources. */ void do_light_sources(cs_rows) - char **cs_rows; +char **cs_rows; { int x, y, min_x, max_x, max_y, offset; char *limits; @@ -136,142 +140,149 @@ do_light_sources(cs_rows) char *row; for (ls = light_base; ls; ls = ls->next) { - ls->flags &= ~LSF_SHOW; + ls->flags &= ~LSF_SHOW; - /* - * Check for moved light sources. It may be possible to - * save some effort if an object has not moved, but not in - * the current setup -- we need to recalculate for every - * vision recalc. - */ - if (ls->type == LS_OBJECT) { - if (get_obj_location(ls->id.a_obj, &ls->x, &ls->y, 0)) - ls->flags |= LSF_SHOW; - } else if (ls->type == LS_MONSTER) { - if (get_mon_location(ls->id.a_monst, &ls->x, &ls->y, 0)) - ls->flags |= LSF_SHOW; - } + /* + * Check for moved light sources. It may be possible to + * save some effort if an object has not moved, but not in + * the current setup -- we need to recalculate for every + * vision recalc. + */ + if (ls->type == LS_OBJECT) { + if (get_obj_location(ls->id.a_obj, &ls->x, &ls->y, 0)) + ls->flags |= LSF_SHOW; + } else if (ls->type == LS_MONSTER) { + if (get_mon_location(ls->id.a_monst, &ls->x, &ls->y, 0)) + ls->flags |= LSF_SHOW; + } - /* minor optimization: don't bother with duplicate light sources */ - /* at hero */ - if (ls->x == u.ux && ls->y == u.uy) { - if (at_hero_range >= ls->range) - ls->flags &= ~LSF_SHOW; - else - at_hero_range = ls->range; - } + /* minor optimization: don't bother with duplicate light sources */ + /* at hero */ + if (ls->x == u.ux && ls->y == u.uy) { + if (at_hero_range >= ls->range) + ls->flags &= ~LSF_SHOW; + else + at_hero_range = ls->range; + } - if (ls->flags & LSF_SHOW) { - /* - * Walk the points in the circle and see if they are - * visible from the center. If so, mark'em. - * - * Kevin's tests indicated that doing this brute-force - * method is faster for radius <= 3 (or so). - */ - limits = circle_ptr(ls->range); - if ((max_y = (ls->y + ls->range)) >= ROWNO) max_y = ROWNO-1; - if ((y = (ls->y - ls->range)) < 0) y = 0; - for (; y <= max_y; y++) { - row = cs_rows[y]; - offset = limits[abs(y - ls->y)]; - if ((min_x = (ls->x - offset)) < 0) min_x = 0; - if ((max_x = (ls->x + offset)) >= COLNO) max_x = COLNO-1; + if (ls->flags & LSF_SHOW) { + /* + * Walk the points in the circle and see if they are + * visible from the center. If so, mark'em. + * + * Kevin's tests indicated that doing this brute-force + * method is faster for radius <= 3 (or so). + */ + limits = circle_ptr(ls->range); + if ((max_y = (ls->y + ls->range)) >= ROWNO) + max_y = ROWNO - 1; + if ((y = (ls->y - ls->range)) < 0) + y = 0; + for (; y <= max_y; y++) { + row = cs_rows[y]; + offset = limits[abs(y - ls->y)]; + if ((min_x = (ls->x - offset)) < 0) + min_x = 0; + if ((max_x = (ls->x + offset)) >= COLNO) + max_x = COLNO - 1; - if (ls->x == u.ux && ls->y == u.uy) { - /* - * If the light source is located at the hero, then - * we can use the COULD_SEE bits already calcualted - * by the vision system. More importantly than - * this optimization, is that it allows the vision - * system to correct problems with clear_path(). - * The function clear_path() is a simple LOS - * path checker that doesn't go out of its way - * make things look "correct". The vision system - * does this. - */ - for (x = min_x; x <= max_x; x++) - if (row[x] & COULD_SEE) - row[x] |= TEMP_LIT; - } else { - for (x = min_x; x <= max_x; x++) - if ((ls->x == x && ls->y == y) - || clear_path((int)ls->x, (int) ls->y, x, y)) - row[x] |= TEMP_LIT; - } - } - } + if (ls->x == u.ux && ls->y == u.uy) { + /* + * If the light source is located at the hero, then + * we can use the COULD_SEE bits already calcualted + * by the vision system. More importantly than + * this optimization, is that it allows the vision + * system to correct problems with clear_path(). + * The function clear_path() is a simple LOS + * path checker that doesn't go out of its way + * make things look "correct". The vision system + * does this. + */ + for (x = min_x; x <= max_x; x++) + if (row[x] & COULD_SEE) + row[x] |= TEMP_LIT; + } else { + for (x = min_x; x <= max_x; x++) + if ((ls->x == x && ls->y == y) + || clear_path((int) ls->x, (int) ls->y, x, y)) + row[x] |= TEMP_LIT; + } + } + } } } /* (mon->mx == 0) implies migrating */ -#define mon_is_local(mon) ((mon)->mx > 0) +#define mon_is_local(mon) ((mon)->mx > 0) struct monst * find_mid(nid, fmflags) unsigned nid; unsigned fmflags; { - struct monst *mtmp; + struct monst *mtmp; - if (!nid) - return &youmonst; - if (fmflags & FM_FMON) - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (!DEADMONSTER(mtmp) && mtmp->m_id == nid) return mtmp; - if (fmflags & FM_MIGRATE) - for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) - if (mtmp->m_id == nid) return mtmp; - if (fmflags & FM_MYDOGS) - for (mtmp = mydogs; mtmp; mtmp = mtmp->nmon) - if (mtmp->m_id == nid) return mtmp; - return (struct monst *) 0; + if (!nid) + return &youmonst; + if (fmflags & FM_FMON) + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (!DEADMONSTER(mtmp) && mtmp->m_id == nid) + return mtmp; + if (fmflags & FM_MIGRATE) + for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) + if (mtmp->m_id == nid) + return mtmp; + if (fmflags & FM_MYDOGS) + for (mtmp = mydogs; mtmp; mtmp = mtmp->nmon) + if (mtmp->m_id == nid) + return mtmp; + return (struct monst *) 0; } /* Save all light sources of the given range. */ void save_light_sources(fd, mode, range) - int fd, mode, range; +int fd, mode, range; { int count, actual, is_global; light_source **prev, *curr; if (perform_bwrite(mode)) { - count = maybe_write_ls(fd, range, FALSE); - bwrite(fd, (genericptr_t) &count, sizeof count); - actual = maybe_write_ls(fd, range, TRUE); - if (actual != count) - panic("counted %d light sources, wrote %d! [range=%d]", - count, actual, range); + count = maybe_write_ls(fd, range, FALSE); + bwrite(fd, (genericptr_t) &count, sizeof count); + actual = maybe_write_ls(fd, range, TRUE); + if (actual != count) + panic("counted %d light sources, wrote %d! [range=%d]", count, + actual, range); } if (release_data(mode)) { - for (prev = &light_base; (curr = *prev) != 0; ) { - if (!curr->id.a_monst) { - impossible("save_light_sources: no id! [range=%d]", range); - is_global = 0; - } else - switch (curr->type) { - case LS_OBJECT: - is_global = !obj_is_local(curr->id.a_obj); - break; - case LS_MONSTER: - is_global = !mon_is_local(curr->id.a_monst); - break; - default: - is_global = 0; - impossible("save_light_sources: bad type (%d) [range=%d]", - curr->type, range); - break; - } - /* if global and not doing local, or vice versa, remove it */ - if (is_global ^ (range == RANGE_LEVEL)) { - *prev = curr->next; - free((genericptr_t)curr); - } else { - prev = &(*prev)->next; - } - } + for (prev = &light_base; (curr = *prev) != 0;) { + if (!curr->id.a_monst) { + impossible("save_light_sources: no id! [range=%d]", range); + is_global = 0; + } else + switch (curr->type) { + case LS_OBJECT: + is_global = !obj_is_local(curr->id.a_obj); + break; + case LS_MONSTER: + is_global = !mon_is_local(curr->id.a_monst); + break; + default: + is_global = 0; + impossible("save_light_sources: bad type (%d) [range=%d]", + curr->type, range); + break; + } + /* if global and not doing local, or vice versa, remove it */ + if (is_global ^ (range == RANGE_LEVEL)) { + *prev = curr->next; + free((genericptr_t) curr); + } else { + prev = &(*prev)->next; + } + } } } @@ -281,7 +292,7 @@ save_light_sources(fd, mode, range) */ void restore_light_sources(fd) - int fd; +int fd; { int count; light_source *ls; @@ -290,45 +301,45 @@ restore_light_sources(fd) mread(fd, (genericptr_t) &count, sizeof count); while (count-- > 0) { - ls = (light_source *) alloc(sizeof(light_source)); - mread(fd, (genericptr_t) ls, sizeof(light_source)); - ls->next = light_base; - light_base = ls; + ls = (light_source *) alloc(sizeof(light_source)); + mread(fd, (genericptr_t) ls, sizeof(light_source)); + ls->next = light_base; + light_base = ls; } } /* Relink all lights that are so marked. */ void relink_light_sources(ghostly) - boolean ghostly; +boolean ghostly; { char which; unsigned nid; light_source *ls; for (ls = light_base; ls; ls = ls->next) { - if (ls->flags & LSF_NEEDS_FIXUP) { - if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { - if (ghostly) { - if (!lookup_id_mapping(ls->id.a_uint, &nid)) - impossible("relink_light_sources: no id mapping"); - } else - nid = ls->id.a_uint; - if (ls->type == LS_OBJECT) { - which = 'o'; - ls->id.a_obj = find_oid(nid); - } else { - which = 'm'; - ls->id.a_monst = find_mid(nid, FM_EVERYWHERE); - } - if (!ls->id.a_monst) - impossible("relink_light_sources: cant find %c_id %d", - which, nid); - } else - impossible("relink_light_sources: bad type (%d)", ls->type); + if (ls->flags & LSF_NEEDS_FIXUP) { + if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { + if (ghostly) { + if (!lookup_id_mapping(ls->id.a_uint, &nid)) + impossible("relink_light_sources: no id mapping"); + } else + nid = ls->id.a_uint; + if (ls->type == LS_OBJECT) { + which = 'o'; + ls->id.a_obj = find_oid(nid); + } else { + which = 'm'; + ls->id.a_monst = find_mid(nid, FM_EVERYWHERE); + } + if (!ls->id.a_monst) + impossible("relink_light_sources: cant find %c_id %d", + which, nid); + } else + impossible("relink_light_sources: bad type (%d)", ls->type); - ls->flags &= ~LSF_NEEDS_FIXUP; - } + ls->flags &= ~LSF_NEEDS_FIXUP; + } } } @@ -339,35 +350,36 @@ relink_light_sources(ghostly) */ STATIC_OVL int maybe_write_ls(fd, range, write_it) - int fd, range; - boolean write_it; +int fd, range; +boolean write_it; { int count = 0, is_global; light_source *ls; for (ls = light_base; ls; ls = ls->next) { - if (!ls->id.a_monst) { - impossible("maybe_write_ls: no id! [range=%d]", range); - continue; - } - switch (ls->type) { - case LS_OBJECT: - is_global = !obj_is_local(ls->id.a_obj); - break; - case LS_MONSTER: - is_global = !mon_is_local(ls->id.a_monst); - break; - default: - is_global = 0; - impossible("maybe_write_ls: bad type (%d) [range=%d]", - ls->type, range); - break; - } - /* if global and not doing local, or vice versa, count it */ - if (is_global ^ (range == RANGE_LEVEL)) { - count++; - if (write_it) write_ls(fd, ls); - } + if (!ls->id.a_monst) { + impossible("maybe_write_ls: no id! [range=%d]", range); + continue; + } + switch (ls->type) { + case LS_OBJECT: + is_global = !obj_is_local(ls->id.a_obj); + break; + case LS_MONSTER: + is_global = !mon_is_local(ls->id.a_monst); + break; + default: + is_global = 0; + impossible("maybe_write_ls: bad type (%d) [range=%d]", ls->type, + range); + break; + } + /* if global and not doing local, or vice versa, count it */ + if (is_global ^ (range == RANGE_LEVEL)) { + count++; + if (write_it) + write_ls(fd, ls); + } } return count; @@ -376,52 +388,54 @@ maybe_write_ls(fd, range, write_it) /* Write a light source structure to disk. */ STATIC_OVL void write_ls(fd, ls) - int fd; - light_source *ls; +int fd; +light_source *ls; { anything arg_save; struct obj *otmp; struct monst *mtmp; if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { - if (ls->flags & LSF_NEEDS_FIXUP) - bwrite(fd, (genericptr_t)ls, sizeof(light_source)); - else { - /* replace object pointer with id for write, then put back */ - arg_save = ls->id; - if (ls->type == LS_OBJECT) { - otmp = ls->id.a_obj; - ls->id = zeroany; - ls->id.a_uint = otmp->o_id; - if (find_oid((unsigned)ls->id.a_uint) != otmp) - impossible("write_ls: can't find obj #%u!", ls->id.a_uint); - } else { /* ls->type == LS_MONSTER */ - mtmp = (struct monst *)ls->id.a_monst; - ls->id = zeroany; - ls->id.a_uint = mtmp->m_id; - if (find_mid((unsigned)ls->id.a_uint, FM_EVERYWHERE) != mtmp) - impossible("write_ls: can't find mon #%u!", ls->id.a_uint); - } - ls->flags |= LSF_NEEDS_FIXUP; - bwrite(fd, (genericptr_t)ls, sizeof(light_source)); - ls->id = arg_save; - ls->flags &= ~LSF_NEEDS_FIXUP; - } + if (ls->flags & LSF_NEEDS_FIXUP) + bwrite(fd, (genericptr_t) ls, sizeof(light_source)); + else { + /* replace object pointer with id for write, then put back */ + arg_save = ls->id; + if (ls->type == LS_OBJECT) { + otmp = ls->id.a_obj; + ls->id = zeroany; + ls->id.a_uint = otmp->o_id; + if (find_oid((unsigned) ls->id.a_uint) != otmp) + impossible("write_ls: can't find obj #%u!", + ls->id.a_uint); + } else { /* ls->type == LS_MONSTER */ + mtmp = (struct monst *) ls->id.a_monst; + ls->id = zeroany; + ls->id.a_uint = mtmp->m_id; + if (find_mid((unsigned) ls->id.a_uint, FM_EVERYWHERE) != mtmp) + impossible("write_ls: can't find mon #%u!", + ls->id.a_uint); + } + ls->flags |= LSF_NEEDS_FIXUP; + bwrite(fd, (genericptr_t) ls, sizeof(light_source)); + ls->id = arg_save; + ls->flags &= ~LSF_NEEDS_FIXUP; + } } else { - impossible("write_ls: bad type (%d)", ls->type); + impossible("write_ls: bad type (%d)", ls->type); } } /* Change light source's ID from src to dest. */ void obj_move_light_source(src, dest) - struct obj *src, *dest; +struct obj *src, *dest; { light_source *ls; for (ls = light_base; ls; ls = ls->next) - if (ls->type == LS_OBJECT && ls->id.a_obj == src) - ls->id.a_obj = dest; + if (ls->type == LS_OBJECT && ls->id.a_obj == src) + ls->id.a_obj = dest; src->lamplit = 0; dest->lamplit = 1; } @@ -439,41 +453,43 @@ any_light_source() */ void snuff_light_source(x, y) - int x, y; +int x, y; { light_source *ls; struct obj *obj; for (ls = light_base; ls; ls = ls->next) - /* - Is this position check valid??? Can I assume that the positions - will always be correct because the objects would have been - updated with the last vision update? [Is that recent enough???] - */ - if (ls->type == LS_OBJECT && ls->x == x && ls->y == y) { - obj = ls->id.a_obj; - if (obj_is_burning(obj)) { - /* The only way to snuff Sunsword is to unwield it. Darkness - * scrolls won't affect it. (If we got here because it was - * dropped or thrown inside a monster, this won't matter anyway - * because it will go out when dropped.) - */ - if (artifact_light(obj)) continue; - end_burn(obj, obj->otyp != MAGIC_LAMP); - /* - * The current ls element has just been removed (and - * ls->next is now invalid). Return assuming that there - * is only one light source attached to each object. - */ - return; - } - } + /* + Is this position check valid??? Can I assume that the positions + will always be correct because the objects would have been + updated with the last vision update? [Is that recent enough???] + */ + if (ls->type == LS_OBJECT && ls->x == x && ls->y == y) { + obj = ls->id.a_obj; + if (obj_is_burning(obj)) { + /* The only way to snuff Sunsword is to unwield it. Darkness + * scrolls won't affect it. (If we got here because it was + * dropped or thrown inside a monster, this won't matter + * anyway + * because it will go out when dropped.) + */ + if (artifact_light(obj)) + continue; + end_burn(obj, obj->otyp != MAGIC_LAMP); + /* + * The current ls element has just been removed (and + * ls->next is now invalid). Return assuming that there + * is only one light source attached to each object. + */ + return; + } + } } /* Return TRUE if object sheds any light at all. */ boolean obj_sheds_light(obj) - struct obj *obj; +struct obj *obj; { /* so far, only burning objects shed light */ return obj_is_burning(obj); @@ -482,39 +498,39 @@ obj_sheds_light(obj) /* Return TRUE if sheds light AND will be snuffed by end_burn(). */ boolean obj_is_burning(obj) - struct obj *obj; +struct obj *obj; { - return (obj->lamplit && - (obj->otyp == MAGIC_LAMP || ignitable(obj) || artifact_light(obj))); + return (obj->lamplit && (obj->otyp == MAGIC_LAMP || ignitable(obj) + || artifact_light(obj))); } /* copy the light source(s) attachted to src, and attach it/them to dest */ void obj_split_light_source(src, dest) - struct obj *src, *dest; +struct obj *src, *dest; { light_source *ls, *new_ls; for (ls = light_base; ls; ls = ls->next) - if (ls->type == LS_OBJECT && ls->id.a_obj == src) { - /* - * Insert the new source at beginning of list. This will - * never interfere us walking down the list - we are already - * past the insertion point. - */ - new_ls = (light_source *) alloc(sizeof(light_source)); - *new_ls = *ls; - if (Is_candle(src)) { - /* split candles may emit less light than original group */ - ls->range = candle_light_range(src); - new_ls->range = candle_light_range(dest); - vision_full_recalc = 1; /* in case range changed */ - } - new_ls->id.a_obj = dest; - new_ls->next = light_base; - light_base = new_ls; - dest->lamplit = 1; /* now an active light source */ - } + if (ls->type == LS_OBJECT && ls->id.a_obj == src) { + /* + * Insert the new source at beginning of list. This will + * never interfere us walking down the list - we are already + * past the insertion point. + */ + new_ls = (light_source *) alloc(sizeof(light_source)); + *new_ls = *ls; + if (Is_candle(src)) { + /* split candles may emit less light than original group */ + ls->range = candle_light_range(src); + new_ls->range = candle_light_range(dest); + vision_full_recalc = 1; /* in case range changed */ + } + new_ls->id.a_obj = dest; + new_ls->next = light_base; + light_base = new_ls; + dest->lamplit = 1; /* now an active light source */ + } } /* light source `src' has been folded into light source `dest'; @@ -526,14 +542,15 @@ struct obj *src, *dest; light_source *ls; /* src == dest implies adding to candelabrum */ - if (src != dest) end_burn(src, TRUE); /* extinguish candles */ + if (src != dest) + end_burn(src, TRUE); /* extinguish candles */ for (ls = light_base; ls; ls = ls->next) - if (ls->type == LS_OBJECT && ls->id.a_obj == dest) { - ls->range = candle_light_range(dest); - vision_full_recalc = 1; /* in case range changed */ - break; - } + if (ls->type == LS_OBJECT && ls->id.a_obj == dest) { + ls->range = candle_light_range(dest); + vision_full_recalc = 1; /* in case range changed */ + break; + } } /* light source `obj' is being made brighter or dimmer */ @@ -545,11 +562,12 @@ int new_radius; light_source *ls; for (ls = light_base; ls; ls = ls->next) - if (ls->type == LS_OBJECT && ls->id.a_obj == obj) { - if (new_radius != ls->range) vision_full_recalc = 1; - ls->range = new_radius; - return; - } + if (ls->type == LS_OBJECT && ls->id.a_obj == obj) { + if (new_radius != ls->range) + vision_full_recalc = 1; + ls->range = new_radius; + return; + } impossible("obj_adjust_light_radius: can't find %s", xname(obj)); } @@ -562,34 +580,34 @@ struct obj *obj; int radius; if (obj->otyp == CANDELABRUM_OF_INVOCATION) { - /* - * The special candelabrum emits more light than the - * corresponding number of candles would. - * 1..3 candles, range 2 (minimum range); - * 4..6 candles, range 3 (normal lamp range); - * 7 candles, range 4 (bright). - */ - radius = (obj->spe < 4) ? 2 : (obj->spe < 7) ? 3 : 4; + /* + * The special candelabrum emits more light than the + * corresponding number of candles would. + * 1..3 candles, range 2 (minimum range); + * 4..6 candles, range 3 (normal lamp range); + * 7 candles, range 4 (bright). + */ + radius = (obj->spe < 4) ? 2 : (obj->spe < 7) ? 3 : 4; } else if (Is_candle(obj)) { - /* - * Range is incremented by powers of 7 so that it will take - * wizard mode quantities of candles to get more light than - * from a lamp, without imposing an arbitrary limit. - * 1..6 candles, range 2; - * 7..48 candles, range 3; - * 49..342 candles, range 4; &c. - */ - long n = obj->quan; + /* + * Range is incremented by powers of 7 so that it will take + * wizard mode quantities of candles to get more light than + * from a lamp, without imposing an arbitrary limit. + * 1..6 candles, range 2; + * 7..48 candles, range 3; + * 49..342 candles, range 4; &c. + */ + long n = obj->quan; - radius = 1; /* always incremented at least once */ - do { - radius++; - n /= 7L; - } while (n > 0L); + radius = 1; /* always incremented at least once */ + do { + radius++; + n /= 7L; + } while (n > 0L); } else { - /* we're only called for lit candelabrum or candles */ - /* impossible("candlelight for %d?", obj->otyp); */ - radius = 3; /* lamp's value */ + /* we're only called for lit candelabrum or candles */ + /* impossible("candlelight for %d?", obj->otyp); */ + radius = 3; /* lamp's value */ } return radius; } @@ -607,7 +625,8 @@ struct obj *obj; */ /* sanity check [simplifies usage by bless()/curse()/&c] */ - if (!obj->lamplit || !artifact_light(obj)) return 0; + if (!obj->lamplit || !artifact_light(obj)) + return 0; /* cursed radius of 1 is not noticeable for an item that's carried by the hero but is if it's carried by a monster @@ -621,10 +640,14 @@ arti_light_description(obj) struct obj *obj; { switch (arti_light_radius(obj)) { - case 3: return "brilliantly"; /* blessed */ - case 2: return "brightly"; /* uncursed */ - case 1: return "dimly"; /* cursed */ - default: break; + case 3: + return "brilliantly"; /* blessed */ + case 2: + return "brightly"; /* uncursed */ + case 1: + return "dimly"; /* cursed */ + default: + break; } return "strangely"; } @@ -636,31 +659,34 @@ wiz_light_sources() char buf[BUFSZ]; light_source *ls; - win = create_nhwindow(NHW_MENU); /* corner text window */ - if (win == WIN_ERR) return 0; + win = create_nhwindow(NHW_MENU); /* corner text window */ + if (win == WIN_ERR) + return 0; Sprintf(buf, "Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy); putstr(win, 0, buf); putstr(win, 0, ""); if (light_base) { - putstr(win, 0, "location range flags type id"); - putstr(win, 0, "-------- ----- ------ ---- -------"); - for (ls = light_base; ls; ls = ls->next) { - Sprintf(buf, " %2d,%2d %2d 0x%04x %s %s", - ls->x, ls->y, ls->range, ls->flags, - (ls->type == LS_OBJECT ? "obj" : - ls->type == LS_MONSTER ? - (mon_is_local(ls->id.a_monst) ? "mon" : - (ls->id.a_monst == &youmonst) ? "you" : - "") : /* migrating monster */ - "???"), - fmt_ptr(ls->id.a_void)); - putstr(win, 0, buf); - } + putstr(win, 0, "location range flags type id"); + putstr(win, 0, "-------- ----- ------ ---- -------"); + for (ls = light_base; ls; ls = ls->next) { + Sprintf(buf, " %2d,%2d %2d 0x%04x %s %s", ls->x, ls->y, + ls->range, ls->flags, + (ls->type == LS_OBJECT + ? "obj" + : ls->type == LS_MONSTER + ? (mon_is_local(ls->id.a_monst) + ? "mon" + : (ls->id.a_monst == &youmonst) ? "you" + : "") + : /* migrating monster */ + "???"), + fmt_ptr(ls->id.a_void)); + putstr(win, 0, buf); + } } else - putstr(win, 0, ""); - + putstr(win, 0, ""); display_nhwindow(win, FALSE); destroy_nhwindow(win); diff --git a/src/lock.c b/src/lock.c index 1537c43c7..343fdb7e9 100644 --- a/src/lock.c +++ b/src/lock.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 lock.c $NHDT-Date: 1429755451 2015/04/23 02:17:31 $ $NHDT-Branch: master $:$NHDT-Revision: 1.56 $ */ +/* NetHack 3.6 lock.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.59 $ */ /* NetHack 3.6 lock.c $Date: 2014/09/20 00:32:01 $ $Revision: 1.39 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,993 +10,1031 @@ STATIC_PTR int NDECL(forcelock); /* at most one of `door' and `box' should be non-null at any given time */ STATIC_VAR NEARDATA struct xlock_s { - struct rm *door; - struct obj *box; - int picktyp, /* key|pick|card for unlock, sharp vs blunt for #force */ - chance, usedtime; + struct rm *door; + struct obj *box; + int picktyp, /* key|pick|card for unlock, sharp vs blunt for #force */ + chance, usedtime; } xlock; STATIC_DCL const char *NDECL(lock_action); -STATIC_DCL boolean FDECL(obstructed,(int,int,BOOLEAN_P)); +STATIC_DCL boolean FDECL(obstructed, (int, int, BOOLEAN_P)); STATIC_DCL void FDECL(chest_shatter_msg, (struct obj *)); boolean picking_lock(x, y) - int *x, *y; +int *x, *y; { - if (occupation == picklock) { - *x = u.ux + u.dx; - *y = u.uy + u.dy; - return TRUE; - } else { - *x = *y = 0; - return FALSE; - } + if (occupation == picklock) { + *x = u.ux + u.dx; + *y = u.uy + u.dy; + return TRUE; + } else { + *x = *y = 0; + return FALSE; + } } boolean picking_at(x, y) int x, y; { - return (boolean)(occupation == picklock && xlock.door == &levl[x][y]); + return (boolean)(occupation == picklock && xlock.door == &levl[x][y]); } /* produce an occupation string appropriate for the current activity */ STATIC_OVL const char * lock_action() { - /* "unlocking"+2 == "locking" */ - static const char *actions[] = { - /* [0] */ "unlocking the door", - /* [1] */ "unlocking the chest", - /* [2] */ "unlocking the box", - /* [3] */ "picking the lock" - }; + /* "unlocking"+2 == "locking" */ + static const char *actions[] = { /* [0] */ "unlocking the door", + /* [1] */ "unlocking the chest", + /* [2] */ "unlocking the box", + /* [3] */ "picking the lock" }; - /* if the target is currently unlocked, we're trying to lock it now */ - if (xlock.door && !(xlock.door->doormask & D_LOCKED)) - return actions[0]+2; /* "locking the door" */ - else if (xlock.box && !xlock.box->olocked) - return xlock.box->otyp == CHEST ? actions[1]+2 : actions[2]+2; - /* otherwise we're trying to unlock it */ - else if (xlock.picktyp == LOCK_PICK) - return actions[3]; /* "picking the lock" */ - else if (xlock.picktyp == CREDIT_CARD) - return actions[3]; /* same as lock_pick */ - else if (xlock.door) - return actions[0]; /* "unlocking the door" */ - else - return xlock.box->otyp == CHEST ? actions[1] : actions[2]; + /* if the target is currently unlocked, we're trying to lock it now */ + if (xlock.door && !(xlock.door->doormask & D_LOCKED)) + return actions[0] + 2; /* "locking the door" */ + else if (xlock.box && !xlock.box->olocked) + return xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2; + /* otherwise we're trying to unlock it */ + else if (xlock.picktyp == LOCK_PICK) + return actions[3]; /* "picking the lock" */ + else if (xlock.picktyp == CREDIT_CARD) + return actions[3]; /* same as lock_pick */ + else if (xlock.door) + return actions[0]; /* "unlocking the door" */ + else + return xlock.box->otyp == CHEST ? actions[1] : actions[2]; } STATIC_PTR -int -picklock(VOID_ARGS) /* try to open/close a lock */ +int picklock(VOID_ARGS) /* try to open/close a lock */ { + if (xlock.box) { + if ((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) { + return ((xlock.usedtime = 0)); /* you or it moved */ + } + } else { /* door */ + if (xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) { + return ((xlock.usedtime = 0)); /* you moved */ + } + switch (xlock.door->doormask) { + case D_NODOOR: + pline("This doorway has no door."); + return ((xlock.usedtime = 0)); + case D_ISOPEN: + You("cannot lock an open door."); + return ((xlock.usedtime = 0)); + case D_BROKEN: + pline("This door is broken."); + return ((xlock.usedtime = 0)); + } + } - if (xlock.box) { - if((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) { - return((xlock.usedtime = 0)); /* you or it moved */ - } - } else { /* door */ - if(xlock.door != &(levl[u.ux+u.dx][u.uy+u.dy])) { - return((xlock.usedtime = 0)); /* you moved */ - } - switch (xlock.door->doormask) { - case D_NODOOR: - pline("This doorway has no door."); - return((xlock.usedtime = 0)); - case D_ISOPEN: - You("cannot lock an open door."); - return((xlock.usedtime = 0)); - case D_BROKEN: - pline("This door is broken."); - return((xlock.usedtime = 0)); - } - } + if (xlock.usedtime++ >= 50 || nohands(youmonst.data)) { + You("give up your attempt at %s.", lock_action()); + exercise(A_DEX, TRUE); /* even if you don't succeed */ + return ((xlock.usedtime = 0)); + } - if (xlock.usedtime++ >= 50 || nohands(youmonst.data)) { - You("give up your attempt at %s.", lock_action()); - exercise(A_DEX, TRUE); /* even if you don't succeed */ - return((xlock.usedtime = 0)); - } + if (rn2(100) >= xlock.chance) + return (1); /* still busy */ - if(rn2(100) >= xlock.chance) return(1); /* still busy */ - - You("succeed in %s.", lock_action()); - if (xlock.door) { - if(xlock.door->doormask & D_TRAPPED) { - b_trapped("door", FINGER); - xlock.door->doormask = D_NODOOR; - unblock_point(u.ux+u.dx, u.uy+u.dy); - if (*in_rooms(u.ux+u.dx, u.uy+u.dy, SHOPBASE)) - add_damage(u.ux+u.dx, u.uy+u.dy, 0L); - newsym(u.ux+u.dx, u.uy+u.dy); - } else if (xlock.door->doormask & D_LOCKED) - xlock.door->doormask = D_CLOSED; - else xlock.door->doormask = D_LOCKED; - } else { - xlock.box->olocked = !xlock.box->olocked; - xlock.box->lknown = 1; - if(xlock.box->otrapped) - (void) chest_trap(xlock.box, FINGER, FALSE); - } - exercise(A_DEX, TRUE); - return((xlock.usedtime = 0)); + You("succeed in %s.", lock_action()); + if (xlock.door) { + if (xlock.door->doormask & D_TRAPPED) { + b_trapped("door", FINGER); + xlock.door->doormask = D_NODOOR; + unblock_point(u.ux + u.dx, u.uy + u.dy); + if (*in_rooms(u.ux + u.dx, u.uy + u.dy, SHOPBASE)) + add_damage(u.ux + u.dx, u.uy + u.dy, 0L); + newsym(u.ux + u.dx, u.uy + u.dy); + } else if (xlock.door->doormask & D_LOCKED) + xlock.door->doormask = D_CLOSED; + else + xlock.door->doormask = D_LOCKED; + } else { + xlock.box->olocked = !xlock.box->olocked; + xlock.box->lknown = 1; + if (xlock.box->otrapped) + (void) chest_trap(xlock.box, FINGER, FALSE); + } + exercise(A_DEX, TRUE); + return ((xlock.usedtime = 0)); } void breakchestlock(box, destroyit) struct obj *box; boolean destroyit; -{ - if (!destroyit) { /* bill for the box but not for its contents */ - struct obj *hide_contents = box->cobj; +{ + if (!destroyit) { /* bill for the box but not for its contents */ + struct obj *hide_contents = box->cobj; - box->cobj = 0; - costly_alteration(box, COST_BRKLCK); - box->cobj = hide_contents; - box->olocked = 0; - box->obroken = 1; - box->lknown = 1; - } else { /* #force has destroyed this box (at ) */ - struct obj *otmp; - struct monst *shkp = (*u.ushops && costly_spot(u.ux, u.uy)) ? - shop_keeper(*u.ushops) : 0; - boolean costly = (boolean)(shkp != 0), - peaceful_shk = costly && (boolean)shkp->mpeaceful; - long loss = 0L; + box->cobj = 0; + costly_alteration(box, COST_BRKLCK); + box->cobj = hide_contents; + box->olocked = 0; + box->obroken = 1; + box->lknown = 1; + } else { /* #force has destroyed this box (at ) */ + struct obj *otmp; + struct monst *shkp = (*u.ushops && costly_spot(u.ux, u.uy)) + ? shop_keeper(*u.ushops) + : 0; + boolean costly = (boolean)(shkp != 0), + peaceful_shk = costly && (boolean) shkp->mpeaceful; + long loss = 0L; - pline("In fact, you've totally destroyed %s.", the(xname(box))); - /* Put the contents on ground at the hero's feet. */ - while ((otmp = box->cobj) != 0) { - obj_extract_self(otmp); - if (!rn2(3) || otmp->oclass == POTION_CLASS) { - chest_shatter_msg(otmp); - if (costly) - loss += stolen_value(otmp, u.ux, u.uy, peaceful_shk, TRUE); - if (otmp->quan == 1L) { - obfree(otmp, (struct obj *) 0); - continue; - } - useup(otmp); - } - if (box->otyp == ICE_BOX && otmp->otyp == CORPSE) { - otmp->age = monstermoves - otmp->age; /* actual age */ - start_corpse_timeout(otmp); - } - place_object(otmp, u.ux, u.uy); - stackobj(otmp); - } - if (costly) - loss += stolen_value(box, u.ux, u.uy, peaceful_shk, TRUE); - if (loss) - You("owe %ld %s for objects destroyed.", loss, currency(loss)); - delobj(box); + pline("In fact, you've totally destroyed %s.", the(xname(box))); + /* Put the contents on ground at the hero's feet. */ + while ((otmp = box->cobj) != 0) { + obj_extract_self(otmp); + if (!rn2(3) || otmp->oclass == POTION_CLASS) { + chest_shatter_msg(otmp); + if (costly) + loss += + stolen_value(otmp, u.ux, u.uy, peaceful_shk, TRUE); + if (otmp->quan == 1L) { + obfree(otmp, (struct obj *) 0); + continue; + } + useup(otmp); + } + if (box->otyp == ICE_BOX && otmp->otyp == CORPSE) { + otmp->age = monstermoves - otmp->age; /* actual age */ + start_corpse_timeout(otmp); + } + place_object(otmp, u.ux, u.uy); + stackobj(otmp); + } + if (costly) + loss += stolen_value(box, u.ux, u.uy, peaceful_shk, TRUE); + if (loss) + You("owe %ld %s for objects destroyed.", loss, currency(loss)); + delobj(box); } } STATIC_PTR -int -forcelock(VOID_ARGS) /* try to force a locked chest */ +int forcelock(VOID_ARGS) /* try to force a locked chest */ { - if((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) - return((xlock.usedtime = 0)); /* you or it moved */ + if ((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) + return ((xlock.usedtime = 0)); /* you or it moved */ - if (xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) { - You("give up your attempt to force the lock."); - if(xlock.usedtime >= 50) /* you made the effort */ - exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); - return((xlock.usedtime = 0)); - } + if (xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) { + You("give up your attempt to force the lock."); + if (xlock.usedtime >= 50) /* you made the effort */ + exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); + return ((xlock.usedtime = 0)); + } - if(xlock.picktyp) { /* blade */ + if (xlock.picktyp) { /* blade */ - if(rn2(1000-(int)uwep->spe) > (992-greatest_erosion(uwep)*10) && - !uwep->cursed && !obj_resists(uwep, 0, 99)) { - /* for a +0 weapon, probability that it survives an unsuccessful - * attempt to force the lock is (.992)^50 = .67 - */ - pline("%sour %s broke!", - (uwep->quan > 1L) ? "One of y" : "Y", xname(uwep)); - useup(uwep); - You("give up your attempt to force the lock."); - exercise(A_DEX, TRUE); - return((xlock.usedtime = 0)); - } - } else /* blunt */ - wake_nearby(); /* due to hammering on the container */ + if (rn2(1000 - (int) uwep->spe) > (992 - greatest_erosion(uwep) * 10) + && !uwep->cursed && !obj_resists(uwep, 0, 99)) { + /* for a +0 weapon, probability that it survives an unsuccessful + * attempt to force the lock is (.992)^50 = .67 + */ + pline("%sour %s broke!", (uwep->quan > 1L) ? "One of y" : "Y", + xname(uwep)); + useup(uwep); + You("give up your attempt to force the lock."); + exercise(A_DEX, TRUE); + return ((xlock.usedtime = 0)); + } + } else /* blunt */ + wake_nearby(); /* due to hammering on the container */ - if(rn2(100) >= xlock.chance) return(1); /* still busy */ + if (rn2(100) >= xlock.chance) + return (1); /* still busy */ - You("succeed in forcing the lock."); - breakchestlock(xlock.box, (boolean)(!xlock.picktyp && !rn2(3))); + You("succeed in forcing the lock."); + breakchestlock(xlock.box, (boolean)(!xlock.picktyp && !rn2(3))); - exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); - return((xlock.usedtime = 0)); + exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE); + return ((xlock.usedtime = 0)); } void reset_pick() { - xlock.usedtime = xlock.chance = xlock.picktyp = 0; - xlock.door = 0; - xlock.box = 0; + xlock.usedtime = xlock.chance = xlock.picktyp = 0; + xlock.door = 0; + xlock.box = 0; } /* for doapply(); if player gives a direction or resumes an interrupted previous attempt then it costs hero a move even if nothing ultimately happens; when told "can't do that" before being asked for direction or player cancels with ESC while giving direction, it doesn't */ -#define PICKLOCK_LEARNED_SOMETHING (-1) /* time passes */ -#define PICKLOCK_DID_NOTHING 0 /* no time passes */ +#define PICKLOCK_LEARNED_SOMETHING (-1) /* time passes */ +#define PICKLOCK_DID_NOTHING 0 /* no time passes */ #define PICKLOCK_DID_SOMETHING 1 /* player is applying a key, lock pick, or credit card */ int pick_lock(pick) - register struct obj *pick; +register struct obj *pick; { - int picktyp, c, ch; - coord cc; - struct rm *door; - struct obj *otmp; - char qbuf[QBUFSZ]; + int picktyp, c, ch; + coord cc; + struct rm *door; + struct obj *otmp; + char qbuf[QBUFSZ]; - picktyp = pick->otyp; + picktyp = pick->otyp; - /* check whether we're resuming an interrupted previous attempt */ - if (xlock.usedtime && picktyp == xlock.picktyp) { - static char no_longer[] = "Unfortunately, you can no longer %s %s."; + /* check whether we're resuming an interrupted previous attempt */ + if (xlock.usedtime && picktyp == xlock.picktyp) { + static char no_longer[] = "Unfortunately, you can no longer %s %s."; - if (nohands(youmonst.data)) { - const char *what = (picktyp == LOCK_PICK) ? "pick" : "key"; - if (picktyp == CREDIT_CARD) what = "card"; - pline(no_longer, "hold the", what); - reset_pick(); - return PICKLOCK_LEARNED_SOMETHING; - } else if (u.uswallow || (xlock.box && !can_reach_floor(TRUE))) { - pline(no_longer, "reach the", "lock"); - reset_pick(); - return PICKLOCK_LEARNED_SOMETHING; - } else { - const char *action = lock_action(); - You("resume your attempt at %s.", action); - set_occupation(picklock, action, 0); - return PICKLOCK_DID_SOMETHING; - } - } + if (nohands(youmonst.data)) { + const char *what = (picktyp == LOCK_PICK) ? "pick" : "key"; + if (picktyp == CREDIT_CARD) + what = "card"; + pline(no_longer, "hold the", what); + reset_pick(); + return PICKLOCK_LEARNED_SOMETHING; + } else if (u.uswallow || (xlock.box && !can_reach_floor(TRUE))) { + pline(no_longer, "reach the", "lock"); + reset_pick(); + return PICKLOCK_LEARNED_SOMETHING; + } else { + const char *action = lock_action(); + You("resume your attempt at %s.", action); + set_occupation(picklock, action, 0); + return PICKLOCK_DID_SOMETHING; + } + } - if(nohands(youmonst.data)) { - You_cant("hold %s -- you have no hands!", doname(pick)); - return PICKLOCK_DID_NOTHING; - } else if (u.uswallow) { - You_cant("%sunlock %s.", - (picktyp == CREDIT_CARD) ? "" : - "lock or ", mon_nam(u.ustuck)); - return PICKLOCK_DID_NOTHING; - } + if (nohands(youmonst.data)) { + You_cant("hold %s -- you have no hands!", doname(pick)); + return PICKLOCK_DID_NOTHING; + } else if (u.uswallow) { + You_cant("%sunlock %s.", (picktyp == CREDIT_CARD) ? "" : "lock or ", + mon_nam(u.ustuck)); + return PICKLOCK_DID_NOTHING; + } - if((picktyp != LOCK_PICK && picktyp != CREDIT_CARD - && picktyp != SKELETON_KEY)) { - impossible("picking lock with object %d?", picktyp); - return PICKLOCK_DID_NOTHING; - } - ch = 0; /* lint suppression */ + if ((picktyp != LOCK_PICK && picktyp != CREDIT_CARD + && picktyp != SKELETON_KEY)) { + impossible("picking lock with object %d?", picktyp); + return PICKLOCK_DID_NOTHING; + } + ch = 0; /* lint suppression */ - if (!get_adjacent_loc((char *)0, "Invalid location!", u.ux, u.uy, &cc)) - return PICKLOCK_DID_NOTHING; + if (!get_adjacent_loc((char *) 0, "Invalid location!", u.ux, u.uy, &cc)) + return PICKLOCK_DID_NOTHING; - if (cc.x == u.ux && cc.y == u.uy) { /* pick lock on a container */ - const char *verb; - char qsfx[QBUFSZ]; - boolean it; - int count; + if (cc.x == u.ux && cc.y == u.uy) { /* pick lock on a container */ + const char *verb; + char qsfx[QBUFSZ]; + boolean it; + int count; - if (u.dz < 0) { - There("isn't any sort of lock up %s.", - Levitation ? "here" : "there"); - return PICKLOCK_LEARNED_SOMETHING; - } else if (is_lava(u.ux, u.uy)) { - pline("Doing that would probably melt %s.", yname(pick)); - return PICKLOCK_LEARNED_SOMETHING; - } else if (is_pool(u.ux, u.uy) && !Underwater) { - pline_The("water has no lock."); - return PICKLOCK_LEARNED_SOMETHING; - } + if (u.dz < 0) { + There("isn't any sort of lock up %s.", + Levitation ? "here" : "there"); + return PICKLOCK_LEARNED_SOMETHING; + } else if (is_lava(u.ux, u.uy)) { + pline("Doing that would probably melt %s.", yname(pick)); + return PICKLOCK_LEARNED_SOMETHING; + } else if (is_pool(u.ux, u.uy) && !Underwater) { + pline_The("water has no lock."); + return PICKLOCK_LEARNED_SOMETHING; + } - count = 0; - c = 'n'; /* in case there are no boxes here */ - for(otmp = level.objects[cc.x][cc.y]; otmp; otmp = otmp->nexthere) - if (Is_box(otmp)) { - ++count; - if (!can_reach_floor(TRUE)) { - You_cant("reach %s from up here.", the(xname(otmp))); - return PICKLOCK_LEARNED_SOMETHING; - } - it = 0; - if (otmp->obroken) verb = "fix"; - else if (!otmp->olocked) verb = "lock", it = 1; - else if (picktyp != LOCK_PICK) verb = "unlock", it = 1; - else verb = "pick"; + count = 0; + c = 'n'; /* in case there are no boxes here */ + for (otmp = level.objects[cc.x][cc.y]; otmp; otmp = otmp->nexthere) + if (Is_box(otmp)) { + ++count; + if (!can_reach_floor(TRUE)) { + You_cant("reach %s from up here.", the(xname(otmp))); + return PICKLOCK_LEARNED_SOMETHING; + } + it = 0; + if (otmp->obroken) + verb = "fix"; + else if (!otmp->olocked) + verb = "lock", it = 1; + else if (picktyp != LOCK_PICK) + verb = "unlock", it = 1; + else + verb = "pick"; - /* "There is here; ?" */ - Sprintf(qsfx, " here; %s %s?", - verb, it ? "it" : "its lock"); - (void)safe_qbuf(qbuf, "There is ", qsfx, - otmp, doname, ansimpleoname, "a box"); - otmp->lknown = 1; + /* "There is here; ?" */ + Sprintf(qsfx, " here; %s %s?", verb, it ? "it" : "its lock"); + (void) safe_qbuf(qbuf, "There is ", qsfx, otmp, doname, + ansimpleoname, "a box"); + otmp->lknown = 1; - c = ynq(qbuf); - if(c == 'q') return(0); - if(c == 'n') continue; + c = ynq(qbuf); + if (c == 'q') + return (0); + if (c == 'n') + continue; - if (otmp->obroken) { - You_cant("fix its broken lock with %s.", doname(pick)); - return PICKLOCK_LEARNED_SOMETHING; - } - else if (picktyp == CREDIT_CARD && !otmp->olocked) { - /* credit cards are only good for unlocking */ - You_cant("do that with %s.", - an(simple_typename(picktyp))); - return PICKLOCK_LEARNED_SOMETHING; - } - switch(picktyp) { - case CREDIT_CARD: - ch = ACURR(A_DEX) + 20*Role_if(PM_ROGUE); - break; - case LOCK_PICK: - ch = 4*ACURR(A_DEX) + 25*Role_if(PM_ROGUE); - break; - case SKELETON_KEY: - ch = 75 + ACURR(A_DEX); - break; - default: ch = 0; - } - if(otmp->cursed) ch /= 2; + if (otmp->obroken) { + You_cant("fix its broken lock with %s.", doname(pick)); + return PICKLOCK_LEARNED_SOMETHING; + } else if (picktyp == CREDIT_CARD && !otmp->olocked) { + /* credit cards are only good for unlocking */ + You_cant("do that with %s.", + an(simple_typename(picktyp))); + return PICKLOCK_LEARNED_SOMETHING; + } + switch (picktyp) { + case CREDIT_CARD: + ch = ACURR(A_DEX) + 20 * Role_if(PM_ROGUE); + break; + case LOCK_PICK: + ch = 4 * ACURR(A_DEX) + 25 * Role_if(PM_ROGUE); + break; + case SKELETON_KEY: + ch = 75 + ACURR(A_DEX); + break; + default: + ch = 0; + } + if (otmp->cursed) + ch /= 2; - xlock.picktyp = picktyp; - xlock.box = otmp; - xlock.door = 0; - break; - } - if (c != 'y') { - if (!count) - There("doesn't seem to be any sort of lock here."); - return PICKLOCK_LEARNED_SOMETHING; /* decided against all boxes */ - } - } else { /* pick the lock in a door */ - struct monst *mtmp; + xlock.picktyp = picktyp; + xlock.box = otmp; + xlock.door = 0; + break; + } + if (c != 'y') { + if (!count) + There("doesn't seem to be any sort of lock here."); + return PICKLOCK_LEARNED_SOMETHING; /* decided against all boxes */ + } + } else { /* pick the lock in a door */ + struct monst *mtmp; - if (u.utrap && u.utraptype == TT_PIT) { - You_cant("reach over the edge of the pit."); - return PICKLOCK_LEARNED_SOMETHING; - } + if (u.utrap && u.utraptype == TT_PIT) { + You_cant("reach over the edge of the pit."); + return PICKLOCK_LEARNED_SOMETHING; + } - door = &levl[cc.x][cc.y]; - mtmp = m_at(cc.x, cc.y); - if (mtmp && canseemon(mtmp) && - mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT) { - if (picktyp == CREDIT_CARD && - (mtmp->isshk || mtmp->data == &mons[PM_ORACLE])) - verbalize("No checks, no credit, no problem."); - else - pline("I don't think %s would appreciate that.", mon_nam(mtmp)); - return PICKLOCK_LEARNED_SOMETHING; - } else if (mtmp && mtmp->m_ap_type == M_AP_FURNITURE && - /* not IS_DOOR() here; for M_AP_FURNITURE, mappearance - holds a map symbol rather than a topology type */ - (mtmp->mappearance == S_vcdoor || - mtmp->mappearance == S_hcdoor)) { - /* "The door actually was a !" */ - stumble_onto_mimic(mtmp); - /* mimic might keep the key (50% chance, 10% for PYEC) */ - maybe_absorb_item(mtmp, pick, 50, 10); - return PICKLOCK_LEARNED_SOMETHING; - } - if(!IS_DOOR(door->typ)) { - if (is_drawbridge_wall(cc.x,cc.y) >= 0) - You("%s no lock on the drawbridge.", - Blind ? "feel" : "see"); - else - You("%s no door there.", - Blind ? "feel" : "see"); - return PICKLOCK_LEARNED_SOMETHING; - } - switch (door->doormask) { - case D_NODOOR: - pline("This doorway has no door."); - return PICKLOCK_LEARNED_SOMETHING; - case D_ISOPEN: - You("cannot lock an open door."); - return PICKLOCK_LEARNED_SOMETHING; - case D_BROKEN: - pline("This door is broken."); - return PICKLOCK_LEARNED_SOMETHING; - default: - /* credit cards are only good for unlocking */ - if(picktyp == CREDIT_CARD && !(door->doormask & D_LOCKED)) { - You_cant("lock a door with a credit card."); - return PICKLOCK_LEARNED_SOMETHING; - } + door = &levl[cc.x][cc.y]; + mtmp = m_at(cc.x, cc.y); + if (mtmp && canseemon(mtmp) && mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT) { + if (picktyp == CREDIT_CARD + && (mtmp->isshk || mtmp->data == &mons[PM_ORACLE])) + verbalize("No checks, no credit, no problem."); + else + pline("I don't think %s would appreciate that.", + mon_nam(mtmp)); + return PICKLOCK_LEARNED_SOMETHING; + } else if (mtmp && mtmp->m_ap_type == M_AP_FURNITURE && + /* not IS_DOOR() here; for M_AP_FURNITURE, mappearance + holds a map symbol rather than a topology type */ + (mtmp->mappearance == S_vcdoor + || mtmp->mappearance == S_hcdoor)) { + /* "The door actually was a !" */ + stumble_onto_mimic(mtmp); + /* mimic might keep the key (50% chance, 10% for PYEC) */ + maybe_absorb_item(mtmp, pick, 50, 10); + return PICKLOCK_LEARNED_SOMETHING; + } + if (!IS_DOOR(door->typ)) { + if (is_drawbridge_wall(cc.x, cc.y) >= 0) + You("%s no lock on the drawbridge.", Blind ? "feel" : "see"); + else + You("%s no door there.", Blind ? "feel" : "see"); + return PICKLOCK_LEARNED_SOMETHING; + } + switch (door->doormask) { + case D_NODOOR: + pline("This doorway has no door."); + return PICKLOCK_LEARNED_SOMETHING; + case D_ISOPEN: + You("cannot lock an open door."); + return PICKLOCK_LEARNED_SOMETHING; + case D_BROKEN: + pline("This door is broken."); + return PICKLOCK_LEARNED_SOMETHING; + default: + /* credit cards are only good for unlocking */ + if (picktyp == CREDIT_CARD && !(door->doormask & D_LOCKED)) { + You_cant("lock a door with a credit card."); + return PICKLOCK_LEARNED_SOMETHING; + } - Sprintf(qbuf,"%s it?", - (door->doormask & D_LOCKED) ? "Unlock" : "Lock"); + Sprintf(qbuf, "%s it?", + (door->doormask & D_LOCKED) ? "Unlock" : "Lock"); - c = yn(qbuf); - if(c == 'n') return(0); + c = yn(qbuf); + if (c == 'n') + return (0); - switch(picktyp) { - case CREDIT_CARD: - ch = 2*ACURR(A_DEX) + 20*Role_if(PM_ROGUE); - break; - case LOCK_PICK: - ch = 3*ACURR(A_DEX) + 30*Role_if(PM_ROGUE); - break; - case SKELETON_KEY: - ch = 70 + ACURR(A_DEX); - break; - default: ch = 0; - } - xlock.door = door; - xlock.box = 0; - } - } - context.move = 0; - xlock.chance = ch; - xlock.picktyp = picktyp; - xlock.usedtime = 0; - set_occupation(picklock, lock_action(), 0); - return PICKLOCK_DID_SOMETHING; + switch (picktyp) { + case CREDIT_CARD: + ch = 2 * ACURR(A_DEX) + 20 * Role_if(PM_ROGUE); + break; + case LOCK_PICK: + ch = 3 * ACURR(A_DEX) + 30 * Role_if(PM_ROGUE); + break; + case SKELETON_KEY: + ch = 70 + ACURR(A_DEX); + break; + default: + ch = 0; + } + xlock.door = door; + xlock.box = 0; + } + } + context.move = 0; + xlock.chance = ch; + xlock.picktyp = picktyp; + xlock.usedtime = 0; + set_occupation(picklock, lock_action(), 0); + return PICKLOCK_DID_SOMETHING; } -int -doforce() /* try to force a chest with your weapon */ +int doforce() /* try to force a chest with your weapon */ { - register struct obj *otmp; - register int c, picktyp; - char qbuf[QBUFSZ]; + register struct obj *otmp; + register int c, picktyp; + char qbuf[QBUFSZ]; - if (u.uswallow) { - You_cant("force anything from inside here."); - return 0; - } - if (!uwep || /* proper type test */ - ((uwep->oclass == WEAPON_CLASS || is_weptool(uwep)) ? - (objects[uwep->otyp].oc_skill < P_DAGGER || - objects[uwep->otyp].oc_skill == P_FLAIL || - objects[uwep->otyp].oc_skill > P_LANCE) : - uwep->oclass != ROCK_CLASS)) { - You_cant("force anything %s weapon.", - !uwep ? "when not wielding a" : - (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep)) ? - "without a proper" : "with that"); - return(0); - } - if (!can_reach_floor(TRUE)) { - cant_reach_floor(u.ux, u.uy, FALSE, TRUE); - return 0; - } + if (u.uswallow) { + You_cant("force anything from inside here."); + return 0; + } + if (!uwep || /* proper type test */ + ((uwep->oclass == WEAPON_CLASS || is_weptool(uwep)) + ? (objects[uwep->otyp].oc_skill < P_DAGGER + || objects[uwep->otyp].oc_skill == P_FLAIL + || objects[uwep->otyp].oc_skill > P_LANCE) + : uwep->oclass != ROCK_CLASS)) { + You_cant("force anything %s weapon.", + !uwep ? "when not wielding a" + : (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep)) + ? "without a proper" + : "with that"); + return (0); + } + if (!can_reach_floor(TRUE)) { + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); + return 0; + } - picktyp = is_blade(uwep) && !is_pick(uwep); - if(xlock.usedtime && xlock.box && picktyp == xlock.picktyp) { - You("resume your attempt to force the lock."); - set_occupation(forcelock, "forcing the lock", 0); - return(1); - } + picktyp = is_blade(uwep) && !is_pick(uwep); + if (xlock.usedtime && xlock.box && picktyp == xlock.picktyp) { + You("resume your attempt to force the lock."); + set_occupation(forcelock, "forcing the lock", 0); + return (1); + } - /* A lock is made only for the honest man, the thief will break it. */ - xlock.box = (struct obj *)0; - for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) - if(Is_box(otmp)) { - if (otmp->obroken || !otmp->olocked) { - There("is %s here, but its lock is already %s.", - doname(otmp), otmp->obroken ? "broken" : "unlocked"); - otmp->lknown = 1; - continue; - } - (void)safe_qbuf(qbuf, "There is ", " here; force its lock?", - otmp, doname, ansimpleoname, "a box"); - otmp->lknown = 1; + /* A lock is made only for the honest man, the thief will break it. */ + xlock.box = (struct obj *) 0; + for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) + if (Is_box(otmp)) { + if (otmp->obroken || !otmp->olocked) { + There("is %s here, but its lock is already %s.", doname(otmp), + otmp->obroken ? "broken" : "unlocked"); + otmp->lknown = 1; + continue; + } + (void) safe_qbuf(qbuf, "There is ", " here; force its lock?", + otmp, doname, ansimpleoname, "a box"); + otmp->lknown = 1; - c = ynq(qbuf); - if(c == 'q') return(0); - if(c == 'n') continue; + c = ynq(qbuf); + if (c == 'q') + return (0); + if (c == 'n') + continue; - if(picktyp) - You("force %s into a crack and pry.", yname(uwep)); - else - You("start bashing it with %s.", yname(uwep)); - xlock.box = otmp; - xlock.chance = objects[uwep->otyp].oc_wldam * 2; - xlock.picktyp = picktyp; - xlock.usedtime = 0; - break; - } + if (picktyp) + You("force %s into a crack and pry.", yname(uwep)); + else + You("start bashing it with %s.", yname(uwep)); + xlock.box = otmp; + xlock.chance = objects[uwep->otyp].oc_wldam * 2; + xlock.picktyp = picktyp; + xlock.usedtime = 0; + break; + } - if(xlock.box) set_occupation(forcelock, "forcing the lock", 0); - else You("decide not to force the issue."); - return(1); + if (xlock.box) + set_occupation(forcelock, "forcing the lock", 0); + else + You("decide not to force the issue."); + return (1); } -int -doopen() /* try to open a door */ +int doopen() /* try to open a door */ { return doopen_indir(0, 0); } boolean -stumble_on_door_mimic(x,y) -int x,y; +stumble_on_door_mimic(x, y) +int x, y; { struct monst *mtmp; - if ((mtmp = m_at(x,y)) && - mtmp->m_ap_type == M_AP_FURNITURE && - (mtmp->mappearance == S_hcdoor || - mtmp->mappearance == S_vcdoor) && - !Protection_from_shape_changers) { - stumble_onto_mimic(mtmp); - return TRUE; + if ((mtmp = m_at(x, y)) && mtmp->m_ap_type == M_AP_FURNITURE + && (mtmp->mappearance == S_hcdoor || mtmp->mappearance == S_vcdoor) + && !Protection_from_shape_changers) { + stumble_onto_mimic(mtmp); + return TRUE; } return FALSE; } -int -doopen_indir(x, y) /* try to open a door in direction u.dx/u.dy */ +int doopen_indir(x, y) /* try to open a door in direction u.dx/u.dy */ int x, y; { - coord cc; - register struct rm *door; - boolean portcullis; - int res = 0; + coord cc; + register struct rm *door; + boolean portcullis; + int res = 0; - if (nohands(youmonst.data)) { - You_cant("open anything -- you have no hands!"); - return 0; - } + if (nohands(youmonst.data)) { + You_cant("open anything -- you have no hands!"); + return 0; + } - if (u.utrap && u.utraptype == TT_PIT) { - You_cant("reach over the edge of the pit."); - return 0; - } + if (u.utrap && u.utraptype == TT_PIT) { + You_cant("reach over the edge of the pit."); + return 0; + } - if (x > 0 && y > 0) { - cc.x = x; - cc.y = y; - } else if(!get_adjacent_loc((char *)0, (char *)0, u.ux, u.uy, &cc)) return(0); + if (x > 0 && y > 0) { + cc.x = x; + cc.y = y; + } else if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc)) + return (0); - if((cc.x == u.ux) && (cc.y == u.uy)) return(0); + if ((cc.x == u.ux) && (cc.y == u.uy)) + return (0); - if (stumble_on_door_mimic(cc.x, cc.y)) return 1; + if (stumble_on_door_mimic(cc.x, cc.y)) + return 1; - /* when choosing a direction is impaired, use a turn - regardless of whether a door is successfully targetted */ - if (Confusion || Stunned) res = 1; + /* when choosing a direction is impaired, use a turn + regardless of whether a door is successfully targetted */ + if (Confusion || Stunned) + res = 1; - door = &levl[cc.x][cc.y]; - portcullis = (is_drawbridge_wall(cc.x, cc.y) >= 0); - if (Blind) { - int oldglyph = door->glyph; - schar oldlastseentyp = lastseentyp[cc.x][cc.y]; + door = &levl[cc.x][cc.y]; + portcullis = (is_drawbridge_wall(cc.x, cc.y) >= 0); + if (Blind) { + int oldglyph = door->glyph; + schar oldlastseentyp = lastseentyp[cc.x][cc.y]; - feel_location(cc.x, cc.y); - if (door->glyph != oldglyph + feel_location(cc.x, cc.y); + if (door->glyph != oldglyph || lastseentyp[cc.x][cc.y] != oldlastseentyp) - res = 1; /* learned something */ - } + res = 1; /* learned something */ + } - if (portcullis || !IS_DOOR(door->typ)) { - /* closed portcullis or spot that opened bridge would span */ - if (is_db_wall(cc.x, cc.y) || door->typ == DRAWBRIDGE_UP) - There("is no obvious way to open the drawbridge."); - else if (portcullis || door->typ == DRAWBRIDGE_DOWN) - pline_The("drawbridge is already open."); - else - You("%s no door there.", Blind ? "feel" : "see"); - return res; - } + if (portcullis || !IS_DOOR(door->typ)) { + /* closed portcullis or spot that opened bridge would span */ + if (is_db_wall(cc.x, cc.y) || door->typ == DRAWBRIDGE_UP) + There("is no obvious way to open the drawbridge."); + else if (portcullis || door->typ == DRAWBRIDGE_DOWN) + pline_The("drawbridge is already open."); + else + You("%s no door there.", Blind ? "feel" : "see"); + return res; + } - if (!(door->doormask & D_CLOSED)) { - const char *mesg; + if (!(door->doormask & D_CLOSED)) { + const char *mesg; - switch (door->doormask) { - case D_BROKEN: mesg = " is broken"; break; - case D_NODOOR: mesg = "way has no door"; break; - case D_ISOPEN: mesg = " is already open"; break; - default: mesg = " is locked"; break; - } - pline("This door%s.", mesg); - return res; - } + switch (door->doormask) { + case D_BROKEN: + mesg = " is broken"; + break; + case D_NODOOR: + mesg = "way has no door"; + break; + case D_ISOPEN: + mesg = " is already open"; + break; + default: + mesg = " is locked"; + break; + } + pline("This door%s.", mesg); + return res; + } - if(verysmall(youmonst.data)) { - pline("You're too small to pull the door open."); - return res; - } + if (verysmall(youmonst.data)) { + pline("You're too small to pull the door open."); + return res; + } - /* door is known to be CLOSED */ - if (rnl(20) < (ACURRSTR+ACURR(A_DEX)+ACURR(A_CON))/3) { - pline_The("door opens."); - if(door->doormask & D_TRAPPED) { - b_trapped("door", FINGER); - door->doormask = D_NODOOR; - if (*in_rooms(cc.x, cc.y, SHOPBASE)) add_damage(cc.x, cc.y, 0L); - } else - door->doormask = D_ISOPEN; - if (Blind) - feel_location(cc.x,cc.y); /* the hero knows she opened it */ - else - newsym(cc.x,cc.y); - unblock_point(cc.x,cc.y); /* vision: new see through there */ - } else { - exercise(A_STR, TRUE); - pline_The("door resists!"); - } + /* door is known to be CLOSED */ + if (rnl(20) < (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 3) { + pline_The("door opens."); + if (door->doormask & D_TRAPPED) { + b_trapped("door", FINGER); + door->doormask = D_NODOOR; + if (*in_rooms(cc.x, cc.y, SHOPBASE)) + add_damage(cc.x, cc.y, 0L); + } else + door->doormask = D_ISOPEN; + if (Blind) + feel_location(cc.x, cc.y); /* the hero knows she opened it */ + else + newsym(cc.x, cc.y); + unblock_point(cc.x, cc.y); /* vision: new see through there */ + } else { + exercise(A_STR, TRUE); + pline_The("door resists!"); + } - return(1); + return (1); } STATIC_OVL boolean -obstructed(x,y,quietly) +obstructed(x, y, quietly) register int x, y; boolean quietly; { - register struct monst *mtmp = m_at(x, y); + register struct monst *mtmp = m_at(x, y); - if(mtmp && mtmp->m_ap_type != M_AP_FURNITURE) { - if (mtmp->m_ap_type == M_AP_OBJECT) goto objhere; - if (!quietly) { - if ((mtmp->mx != x) || (mtmp->my != y)) { - /* worm tail */ - pline("%s%s blocks the way!", - !canspotmon(mtmp) ? Something : - s_suffix(Monnam(mtmp)), - !canspotmon(mtmp) ? "" : " tail"); - } else { - pline("%s blocks the way!", - !canspotmon(mtmp) ? "Some creature" : Monnam(mtmp)); - } - } - if (!canspotmon(mtmp)) - map_invisible(x, y); - return(TRUE); - } - if (OBJ_AT(x, y)) { -objhere: if (!quietly) pline("%s's in the way.", Something); - return(TRUE); - } - return(FALSE); + if (mtmp && mtmp->m_ap_type != M_AP_FURNITURE) { + if (mtmp->m_ap_type == M_AP_OBJECT) + goto objhere; + if (!quietly) { + if ((mtmp->mx != x) || (mtmp->my != y)) { + /* worm tail */ + pline("%s%s blocks the way!", + !canspotmon(mtmp) ? Something : s_suffix(Monnam(mtmp)), + !canspotmon(mtmp) ? "" : " tail"); + } else { + pline("%s blocks the way!", + !canspotmon(mtmp) ? "Some creature" : Monnam(mtmp)); + } + } + if (!canspotmon(mtmp)) + map_invisible(x, y); + return (TRUE); + } + if (OBJ_AT(x, y)) { + objhere: + if (!quietly) + pline("%s's in the way.", Something); + return (TRUE); + } + return (FALSE); } -int -doclose() /* try to close a door */ +int doclose() /* try to close a door */ { - register int x, y; - register struct rm *door; - struct monst *mtmp; - boolean portcullis; - int res = 0; + register int x, y; + register struct rm *door; + struct monst *mtmp; + boolean portcullis; + int res = 0; - if (nohands(youmonst.data)) { - You_cant("close anything -- you have no hands!"); - return 0; - } + if (nohands(youmonst.data)) { + You_cant("close anything -- you have no hands!"); + return 0; + } - if (u.utrap && u.utraptype == TT_PIT) { - You_cant("reach over the edge of the pit."); - return 0; - } + if (u.utrap && u.utraptype == TT_PIT) { + You_cant("reach over the edge of the pit."); + return 0; + } - if(!getdir((char *)0)) return(0); + if (!getdir((char *) 0)) + return (0); - x = u.ux + u.dx; - y = u.uy + u.dy; - if((x == u.ux) && (y == u.uy)) { - You("are in the way!"); - return(1); - } + x = u.ux + u.dx; + y = u.uy + u.dy; + if ((x == u.ux) && (y == u.uy)) { + You("are in the way!"); + return (1); + } - if (!isok(x,y)) goto nodoor; + if (!isok(x, y)) + goto nodoor; - if ((mtmp = m_at(x,y)) && - mtmp->m_ap_type == M_AP_FURNITURE && - (mtmp->mappearance == S_hcdoor || - mtmp->mappearance == S_vcdoor) && - !Protection_from_shape_changers) { + if ((mtmp = m_at(x, y)) && mtmp->m_ap_type == M_AP_FURNITURE + && (mtmp->mappearance == S_hcdoor || mtmp->mappearance == S_vcdoor) + && !Protection_from_shape_changers) { + stumble_onto_mimic(mtmp); + return (1); + } - stumble_onto_mimic(mtmp); - return(1); - } + /* when choosing a direction is impaired, use a turn + regardless of whether a door is successfully targetted */ + if (Confusion || Stunned) + res = 1; - /* when choosing a direction is impaired, use a turn - regardless of whether a door is successfully targetted */ - if (Confusion || Stunned) res = 1; + door = &levl[x][y]; + portcullis = (is_drawbridge_wall(x, y) >= 0); + if (Blind) { + int oldglyph = door->glyph; + schar oldlastseentyp = lastseentyp[x][y]; - door = &levl[x][y]; - portcullis = (is_drawbridge_wall(x, y) >= 0); - if (Blind) { - int oldglyph = door->glyph; - schar oldlastseentyp = lastseentyp[x][y]; + feel_location(x, y); + if (door->glyph != oldglyph || lastseentyp[x][y] != oldlastseentyp) + res = 1; /* learned something */ + } - feel_location(x, y); - if (door->glyph != oldglyph || lastseentyp[x][y] != oldlastseentyp) - res = 1; /* learned something */ - } + if (portcullis || !IS_DOOR(door->typ)) { + /* is_db_wall: closed porcullis */ + if (is_db_wall(x, y) || door->typ == DRAWBRIDGE_UP) + pline_The("drawbridge is already closed."); + else if (portcullis || door->typ == DRAWBRIDGE_DOWN) + There("is no obvious way to close the drawbridge."); + else { + nodoor: + You("%s no door there.", Blind ? "feel" : "see"); + } + return res; + } - if (portcullis || !IS_DOOR(door->typ)) { - /* is_db_wall: closed porcullis */ - if (is_db_wall(x, y) || door->typ == DRAWBRIDGE_UP) - pline_The("drawbridge is already closed."); - else if (portcullis || door->typ == DRAWBRIDGE_DOWN) - There("is no obvious way to close the drawbridge."); - else { -nodoor: - You("%s no door there.", Blind ? "feel" : "see"); - } - return res; - } + if (door->doormask == D_NODOOR) { + pline("This doorway has no door."); + return res; + } else if (obstructed(x, y, FALSE)) { + return res; + } else if (door->doormask == D_BROKEN) { + pline("This door is broken."); + return res; + } else if (door->doormask & (D_CLOSED | D_LOCKED)) { + pline("This door is already closed."); + return res; + } - if (door->doormask == D_NODOOR) { - pline("This doorway has no door."); - return res; - } else if (obstructed(x, y, FALSE)) { - return res; - } else if (door->doormask == D_BROKEN) { - pline("This door is broken."); - return res; - } else if (door->doormask & (D_CLOSED | D_LOCKED)) { - pline("This door is already closed."); - return res; - } + if (door->doormask == D_ISOPEN) { + if (verysmall(youmonst.data) && !u.usteed) { + pline("You're too small to push the door closed."); + return res; + } + if (u.usteed + || rn2(25) < (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 3) { + pline_The("door closes."); + door->doormask = D_CLOSED; + if (Blind) + feel_location(x, y); /* the hero knows she closed it */ + else + newsym(x, y); + block_point(x, y); /* vision: no longer see there */ + } else { + exercise(A_STR, TRUE); + pline_The("door resists!"); + } + } - if(door->doormask == D_ISOPEN) { - if(verysmall(youmonst.data) && !u.usteed) { - pline("You're too small to push the door closed."); - return res; - } - if ( u.usteed || rn2(25) < (ACURRSTR+ACURR(A_DEX)+ACURR(A_CON))/3) { - pline_The("door closes."); - door->doormask = D_CLOSED; - if (Blind) - feel_location(x,y); /* the hero knows she closed it */ - else - newsym(x,y); - block_point(x,y); /* vision: no longer see there */ - } else { - exercise(A_STR, TRUE); - pline_The("door resists!"); - } - } - - return(1); + return (1); } -boolean /* box obj was hit with spell effect otmp */ -boxlock(obj, otmp) /* returns true if something happened */ -register struct obj *obj, *otmp; /* obj *is* a box */ +boolean /* box obj was hit with spell effect otmp */ + boxlock(obj, otmp) /* returns true if something happened */ +register struct obj *obj, *otmp; /* obj *is* a box */ { - register boolean res = 0; + register boolean res = 0; - switch(otmp->otyp) { - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - if (!obj->olocked) { /* lock it; fix if broken */ - pline("Klunk!"); - obj->olocked = 1; - obj->obroken = 0; - if (Role_if(PM_WIZARD)) - obj->lknown = 1; - else - obj->lknown = 0; - res = 1; - } /* else already closed and locked */ - break; - case WAN_OPENING: - case SPE_KNOCK: - if (obj->olocked) { /* unlock; couldn't be broken */ - pline("Klick!"); - obj->olocked = 0; - res = 1; - if (Role_if(PM_WIZARD)) - obj->lknown = 1; - else - obj->lknown = 0; - } else /* silently fix if broken */ - obj->obroken = 0; - break; - case WAN_POLYMORPH: - case SPE_POLYMORPH: - /* maybe start unlocking chest, get interrupted, then zap it; - we must avoid any attempt to resume unlocking it */ - if (xlock.box == obj) - reset_pick(); - break; - } - return res; + switch (otmp->otyp) { + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + if (!obj->olocked) { /* lock it; fix if broken */ + pline("Klunk!"); + obj->olocked = 1; + obj->obroken = 0; + if (Role_if(PM_WIZARD)) + obj->lknown = 1; + else + obj->lknown = 0; + res = 1; + } /* else already closed and locked */ + break; + case WAN_OPENING: + case SPE_KNOCK: + if (obj->olocked) { /* unlock; couldn't be broken */ + pline("Klick!"); + obj->olocked = 0; + res = 1; + if (Role_if(PM_WIZARD)) + obj->lknown = 1; + else + obj->lknown = 0; + } else /* silently fix if broken */ + obj->obroken = 0; + break; + case WAN_POLYMORPH: + case SPE_POLYMORPH: + /* maybe start unlocking chest, get interrupted, then zap it; + we must avoid any attempt to resume unlocking it */ + if (xlock.box == obj) + reset_pick(); + break; + } + return res; } -boolean /* Door/secret door was hit with spell effect otmp */ -doorlock(otmp,x,y) /* returns true if something happened */ +boolean /* Door/secret door was hit with spell effect otmp */ + doorlock(otmp, x, y) /* returns true if something happened */ struct obj *otmp; int x, y; { - register struct rm *door = &levl[x][y]; - boolean res = TRUE; - int loudness = 0; - const char *msg = (const char *)0; - const char *dustcloud = "A cloud of dust"; - const char *quickly_dissipates = "quickly dissipates"; - boolean mysterywand = (otmp->oclass == WAND_CLASS && !otmp->dknown); + register struct rm *door = &levl[x][y]; + boolean res = TRUE; + int loudness = 0; + const char *msg = (const char *) 0; + const char *dustcloud = "A cloud of dust"; + const char *quickly_dissipates = "quickly dissipates"; + boolean mysterywand = (otmp->oclass == WAND_CLASS && !otmp->dknown); - if (door->typ == SDOOR) { - switch (otmp->otyp) { - case WAN_OPENING: - case SPE_KNOCK: - case WAN_STRIKING: - case SPE_FORCE_BOLT: - door->typ = DOOR; - door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); - newsym(x,y); - if (cansee(x,y)) pline("A door appears in the wall!"); - if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) - return TRUE; - break; /* striking: continue door handling below */ - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - default: - return FALSE; - } - } + if (door->typ == SDOOR) { + switch (otmp->otyp) { + case WAN_OPENING: + case SPE_KNOCK: + case WAN_STRIKING: + case SPE_FORCE_BOLT: + door->typ = DOOR; + door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); + newsym(x, y); + if (cansee(x, y)) + pline("A door appears in the wall!"); + if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) + return TRUE; + break; /* striking: continue door handling below */ + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + default: + return FALSE; + } + } - switch(otmp->otyp) { - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - if (Is_rogue_level(&u.uz)) { - boolean vis = cansee(x,y); - /* Can't have real locking in Rogue, so just hide doorway */ - if (vis) pline("%s springs up in the older, more primitive doorway.", - dustcloud); - else - You_hear("a swoosh."); - if (obstructed(x,y,mysterywand)) { - if (vis) pline_The("cloud %s.",quickly_dissipates); - return FALSE; - } - block_point(x, y); - door->typ = SDOOR; - if (vis) pline_The("doorway vanishes!"); - newsym(x,y); - return TRUE; - } - if (obstructed(x,y,mysterywand)) return FALSE; - /* Don't allow doors to close over traps. This is for pits */ - /* & trap doors, but is it ever OK for anything else? */ - if (t_at(x,y)) { - /* maketrap() clears doormask, so it should be NODOOR */ - pline( - "%s springs up in the doorway, but %s.", - dustcloud, quickly_dissipates); - return FALSE; - } + switch (otmp->otyp) { + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + if (Is_rogue_level(&u.uz)) { + boolean vis = cansee(x, y); + /* Can't have real locking in Rogue, so just hide doorway */ + if (vis) + pline("%s springs up in the older, more primitive doorway.", + dustcloud); + else + You_hear("a swoosh."); + if (obstructed(x, y, mysterywand)) { + if (vis) + pline_The("cloud %s.", quickly_dissipates); + return FALSE; + } + block_point(x, y); + door->typ = SDOOR; + if (vis) + pline_The("doorway vanishes!"); + newsym(x, y); + return TRUE; + } + if (obstructed(x, y, mysterywand)) + return FALSE; + /* Don't allow doors to close over traps. This is for pits */ + /* & trap doors, but is it ever OK for anything else? */ + if (t_at(x, y)) { + /* maketrap() clears doormask, so it should be NODOOR */ + pline("%s springs up in the doorway, but %s.", dustcloud, + quickly_dissipates); + return FALSE; + } - switch (door->doormask & ~D_TRAPPED) { - case D_CLOSED: - msg = "The door locks!"; - break; - case D_ISOPEN: - msg = "The door swings shut, and locks!"; - break; - case D_BROKEN: - msg = "The broken door reassembles and locks!"; - break; - case D_NODOOR: - msg = - "A cloud of dust springs up and assembles itself into a door!"; - break; - default: - res = FALSE; - break; - } - block_point(x, y); - door->doormask = D_LOCKED | (door->doormask & D_TRAPPED); - newsym(x,y); - break; - case WAN_OPENING: - case SPE_KNOCK: - if (door->doormask & D_LOCKED) { - msg = "The door unlocks!"; - door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); - } else res = FALSE; - break; - case WAN_STRIKING: - case SPE_FORCE_BOLT: - if (door->doormask & (D_LOCKED | D_CLOSED)) { - if (door->doormask & D_TRAPPED) { - if (MON_AT(x, y)) - (void) mb_trapped(m_at(x,y)); - else if (flags.verbose) { - if (cansee(x,y)) - pline("KABOOM!! You see a door explode."); - else - You_hear("a distant explosion."); - } - door->doormask = D_NODOOR; - unblock_point(x,y); - newsym(x,y); - loudness = 40; - break; - } - door->doormask = D_BROKEN; - if (flags.verbose) { - if (cansee(x,y)) - pline_The("door crashes open!"); - else - You_hear("a crashing sound."); - } - unblock_point(x,y); - newsym(x,y); - /* force vision recalc before printing more messages */ - if (vision_full_recalc) vision_recalc(0); - loudness = 20; - } else res = FALSE; - break; - default: impossible("magic (%d) attempted on door.", otmp->otyp); - break; - } - if (msg && cansee(x,y)) pline1(msg); - if (loudness > 0) { - /* door was destroyed */ - wake_nearto(x, y, loudness); - if (*in_rooms(x, y, SHOPBASE)) add_damage(x, y, 0L); - } + switch (door->doormask & ~D_TRAPPED) { + case D_CLOSED: + msg = "The door locks!"; + break; + case D_ISOPEN: + msg = "The door swings shut, and locks!"; + break; + case D_BROKEN: + msg = "The broken door reassembles and locks!"; + break; + case D_NODOOR: + msg = "A cloud of dust springs up and assembles itself into a " + "door!"; + break; + default: + res = FALSE; + break; + } + block_point(x, y); + door->doormask = D_LOCKED | (door->doormask & D_TRAPPED); + newsym(x, y); + break; + case WAN_OPENING: + case SPE_KNOCK: + if (door->doormask & D_LOCKED) { + msg = "The door unlocks!"; + door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); + } else + res = FALSE; + break; + case WAN_STRIKING: + case SPE_FORCE_BOLT: + if (door->doormask & (D_LOCKED | D_CLOSED)) { + if (door->doormask & D_TRAPPED) { + if (MON_AT(x, y)) + (void) mb_trapped(m_at(x, y)); + else if (flags.verbose) { + if (cansee(x, y)) + pline("KABOOM!! You see a door explode."); + else + You_hear("a distant explosion."); + } + door->doormask = D_NODOOR; + unblock_point(x, y); + newsym(x, y); + loudness = 40; + break; + } + door->doormask = D_BROKEN; + if (flags.verbose) { + if (cansee(x, y)) + pline_The("door crashes open!"); + else + You_hear("a crashing sound."); + } + unblock_point(x, y); + newsym(x, y); + /* force vision recalc before printing more messages */ + if (vision_full_recalc) + vision_recalc(0); + loudness = 20; + } else + res = FALSE; + break; + default: + impossible("magic (%d) attempted on door.", otmp->otyp); + break; + } + if (msg && cansee(x, y)) + pline1(msg); + if (loudness > 0) { + /* door was destroyed */ + wake_nearto(x, y, loudness); + if (*in_rooms(x, y, SHOPBASE)) + add_damage(x, y, 0L); + } - if (res && picking_at(x, y)) { - /* maybe unseen monster zaps door you're unlocking */ - stop_occupation(); - reset_pick(); - } - return res; + if (res && picking_at(x, y)) { + /* maybe unseen monster zaps door you're unlocking */ + stop_occupation(); + reset_pick(); + } + return res; } STATIC_OVL void chest_shatter_msg(otmp) struct obj *otmp; { - const char *disposition; - const char *thing; - long save_Blinded; + const char *disposition; + const char *thing; + long save_Blinded; - if (otmp->oclass == POTION_CLASS) { - You("%s %s shatter!", Blind ? "hear" : "see", an(bottlename())); - if (!breathless(youmonst.data) || haseyes(youmonst.data)) - potionbreathe(otmp); - return; - } - /* We have functions for distant and singular names, but not one */ - /* which does _both_... */ - save_Blinded = Blinded; - Blinded = 1; - thing = singular(otmp, xname); - Blinded = save_Blinded; - switch (objects[otmp->otyp].oc_material) { - case PAPER: disposition = "is torn to shreds"; - break; - case WAX: disposition = "is crushed"; - break; - case VEGGY: disposition = "is pulped"; - break; - case FLESH: disposition = "is mashed"; - break; - case GLASS: disposition = "shatters"; - break; - case WOOD: disposition = "splinters to fragments"; - break; - default: disposition = "is destroyed"; - break; - } - pline("%s %s!", An(thing), disposition); + if (otmp->oclass == POTION_CLASS) { + You("%s %s shatter!", Blind ? "hear" : "see", an(bottlename())); + if (!breathless(youmonst.data) || haseyes(youmonst.data)) + potionbreathe(otmp); + return; + } + /* We have functions for distant and singular names, but not one */ + /* which does _both_... */ + save_Blinded = Blinded; + Blinded = 1; + thing = singular(otmp, xname); + Blinded = save_Blinded; + switch (objects[otmp->otyp].oc_material) { + case PAPER: + disposition = "is torn to shreds"; + break; + case WAX: + disposition = "is crushed"; + break; + case VEGGY: + disposition = "is pulped"; + break; + case FLESH: + disposition = "is mashed"; + break; + case GLASS: + disposition = "shatters"; + break; + case WOOD: + disposition = "splinters to fragments"; + break; + default: + disposition = "is destroyed"; + break; + } + pline("%s %s!", An(thing), disposition); } /*lock.c*/ diff --git a/src/mail.c b/src/mail.c index 96c0ca5f3..0a6790972 100644 --- a/src/mail.c +++ b/src/mail.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mail.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mail.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */ /* NetHack 3.6 mail.c $Date: 2009/05/06 10:46:41 $ $Revision: 1.12 $ */ /* SCCS Id: @(#)mail.c 3.5 2008/01/30 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -22,7 +22,8 @@ * - Open the file MAIL and do fstat instead of stat for efficiency. * (But sh uses stat, so this cannot be too bad.) * - Examine the mail and produce a scroll of mail named "From somebody". - * - Invoke MAILREADER in such a way that only this single letter is read. + * - Invoke MAILREADER in such a way that only this single letter is + *read. * - Do something to the text when the scroll is enchanted or cancelled. * - Make the daemon always appear at a stairwell, and have it find a * path to the hero. @@ -33,86 +34,87 @@ * random intervals. */ -STATIC_DCL boolean FDECL(md_start,(coord *)); -STATIC_DCL boolean FDECL(md_stop,(coord *, coord *)); -STATIC_DCL boolean FDECL(md_rush,(struct monst *,int,int)); +STATIC_DCL boolean FDECL(md_start, (coord *)); +STATIC_DCL boolean FDECL(md_stop, (coord *, coord *)); +STATIC_DCL boolean FDECL(md_rush, (struct monst *, int, int)); STATIC_DCL void FDECL(newmail, (struct mail_info *)); -extern char *viz_rmin, *viz_rmax; /* line-of-sight limits (vision.c) */ +extern char *viz_rmin, *viz_rmax; /* line-of-sight limits (vision.c) */ -# if !defined(UNIX) && !defined(VMS) +#if !defined(UNIX) && !defined(VMS) int mustgetmail = -1; -# endif +#endif -# ifdef UNIX +#ifdef UNIX #include #include /* DON'T trust all Unices to declare getpwuid() in */ -# if !defined(_BULL_SOURCE) && !defined(__sgi) && !defined(_M_UNIX) -# if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) +#if !defined(_BULL_SOURCE) && !defined(__sgi) && !defined(_M_UNIX) +#if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) /* DO trust all SVR4 to typedef uid_t in (probably to a long) */ -# if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) -extern struct passwd *FDECL(getpwuid,(uid_t)); -# else -extern struct passwd *FDECL(getpwuid,(int)); -# endif -# endif -# endif -static struct stat omstat,nmstat; -static char *mailbox = (char *)0; +#if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) +extern struct passwd *FDECL(getpwuid, (uid_t)); +#else +extern struct passwd *FDECL(getpwuid, (int)); +#endif +#endif +#endif +static struct stat omstat, nmstat; +static char *mailbox = (char *) 0; static long laststattime; -# if !defined(MAILPATH) && defined(AMS) /* Just a placeholder for AMS */ -# define MAILPATH "/dev/null" -# endif -# if !defined(MAILPATH) && (defined(LINUX) || defined(__osf__)) -# define MAILPATH "/var/spool/mail/" -# endif -# if !defined(MAILPATH) && defined(__FreeBSD__) -# define MAILPATH "/var/mail/" -# endif -# if !defined(MAILPATH) && (defined(BSD) || defined(ULTRIX)) -# define MAILPATH "/usr/spool/mail/" -# endif -# if !defined(MAILPATH) && (defined(SYSV) || defined(HPUX)) -# define MAILPATH "/usr/mail/" -# endif +#if !defined(MAILPATH) && defined(AMS) /* Just a placeholder for AMS */ +#define MAILPATH "/dev/null" +#endif +#if !defined(MAILPATH) && (defined(LINUX) || defined(__osf__)) +#define MAILPATH "/var/spool/mail/" +#endif +#if !defined(MAILPATH) && defined(__FreeBSD__) +#define MAILPATH "/var/mail/" +#endif +#if !defined(MAILPATH) && (defined(BSD) || defined(ULTRIX)) +#define MAILPATH "/usr/spool/mail/" +#endif +#if !defined(MAILPATH) && (defined(SYSV) || defined(HPUX)) +#define MAILPATH "/usr/mail/" +#endif void getmailstatus() { - if(!mailbox && !(mailbox = nh_getenv("MAIL"))) { -# ifdef MAILPATH -# ifdef AMS - struct passwd ppasswd; + if (!mailbox && !(mailbox = nh_getenv("MAIL"))) { +#ifdef MAILPATH +#ifdef AMS + struct passwd ppasswd; - (void) memcpy(&ppasswd, getpwuid(getuid()), sizeof(struct passwd)); - if (ppasswd.pw_dir) { - mailbox = (char *) alloc((unsigned) strlen(ppasswd.pw_dir)+sizeof(AMS_MAILBOX)); - Strcpy(mailbox, ppasswd.pw_dir); - Strcat(mailbox, AMS_MAILBOX); - } else - return; -# else - const char *pw_name = getpwuid(getuid())->pw_name; - mailbox = (char *) alloc(sizeof(MAILPATH)+strlen(pw_name)); - Strcpy(mailbox, MAILPATH); - Strcat(mailbox, pw_name); -# endif /* AMS */ -# else - return; -# endif - } - if(stat(mailbox, &omstat)){ -# ifdef PERMANENT_MAILBOX - pline("Cannot get status of MAIL=\"%s\".", mailbox); - mailbox = 0; -# else - omstat.st_mtime = 0; -# endif - } + (void) memcpy(&ppasswd, getpwuid(getuid()), sizeof(struct passwd)); + if (ppasswd.pw_dir) { + mailbox = (char *) alloc((unsigned) strlen(ppasswd.pw_dir) + + sizeof(AMS_MAILBOX)); + Strcpy(mailbox, ppasswd.pw_dir); + Strcat(mailbox, AMS_MAILBOX); + } else + return; +#else + const char *pw_name = getpwuid(getuid())->pw_name; + mailbox = (char *) alloc(sizeof(MAILPATH) + strlen(pw_name)); + Strcpy(mailbox, MAILPATH); + Strcat(mailbox, pw_name); +#endif /* AMS */ +#else + return; +#endif + } + if (stat(mailbox, &omstat)) { +#ifdef PERMANENT_MAILBOX + pline("Cannot get status of MAIL=\"%s\".", mailbox); + mailbox = 0; +#else + omstat.st_mtime = 0; +#endif + } } -# endif /* UNIX */ +#endif /* UNIX */ /* * Pick coordinates for a starting position for the mail daemon. Called @@ -120,22 +122,22 @@ getmailstatus() */ STATIC_OVL boolean md_start(startp) - coord *startp; +coord *startp; { - coord testcc; /* scratch coordinates */ - int row; /* current row we are checking */ - int lax; /* if TRUE, pick a position in sight. */ - int dd; /* distance to current point */ - int max_distance; /* max distance found so far */ + coord testcc; /* scratch coordinates */ + int row; /* current row we are checking */ + int lax; /* if TRUE, pick a position in sight. */ + int dd; /* distance to current point */ + int max_distance; /* max distance found so far */ /* * If blind and not telepathic, then it doesn't matter what we pick --- * the hero is not going to see it anyway. So pick a nearby position. */ if (Blind && !Blind_telepat) { - if (!enexto(startp, u.ux, u.uy, (struct permonst *) 0)) - return FALSE; /* no good posiitons */ - return TRUE; + if (!enexto(startp, u.ux, u.uy, (struct permonst *) 0)) + return FALSE; /* no good posiitons */ + return TRUE; } /* @@ -143,14 +145,14 @@ md_start(startp) * hero. */ if (couldsee(upstair.sx, upstair.sy)) { - startp->x = upstair.sx; - startp->y = upstair.sy; - return TRUE; + startp->x = upstair.sx; + startp->y = upstair.sy; + return TRUE; } if (couldsee(dnstair.sx, dnstair.sy)) { - startp->x = dnstair.sx; - startp->y = dnstair.sy; - return TRUE; + startp->x = dnstair.sx; + startp->y = dnstair.sy; + return TRUE; } /* @@ -162,52 +164,51 @@ md_start(startp) * The arrays viz_rmin[] and viz_rmax[] are set even when blind. These * are the LOS limits for each row. */ - lax = 0; /* be picky */ + lax = 0; /* be picky */ max_distance = -1; retry: for (row = 0; row < ROWNO; row++) { - if (viz_rmin[row] < viz_rmax[row]) { - /* There are valid positions on this row. */ - dd = distu(viz_rmin[row],row); - if (dd > max_distance) { - if (lax) { - max_distance = dd; - startp->y = row; - startp->x = viz_rmin[row]; - - } else if (enexto(&testcc, (xchar)viz_rmin[row], row, - (struct permonst *) 0) && - !cansee(testcc.x, testcc.y) && - couldsee(testcc.x, testcc.y)) { - max_distance = dd; - *startp = testcc; - } - } - dd = distu(viz_rmax[row],row); - if (dd > max_distance) { - if (lax) { - max_distance = dd; - startp->y = row; - startp->x = viz_rmax[row]; - - } else if (enexto(&testcc, (xchar)viz_rmax[row], row, - (struct permonst *) 0) && - !cansee(testcc.x,testcc.y) && - couldsee(testcc.x, testcc.y)) { + if (viz_rmin[row] < viz_rmax[row]) { + /* There are valid positions on this row. */ + dd = distu(viz_rmin[row], row); + if (dd > max_distance) { + if (lax) { + max_distance = dd; + startp->y = row; + startp->x = viz_rmin[row]; - max_distance = dd; - *startp = testcc; - } - } - } + } else if (enexto(&testcc, (xchar) viz_rmin[row], row, + (struct permonst *) 0) + && !cansee(testcc.x, testcc.y) + && couldsee(testcc.x, testcc.y)) { + max_distance = dd; + *startp = testcc; + } + } + dd = distu(viz_rmax[row], row); + if (dd > max_distance) { + if (lax) { + max_distance = dd; + startp->y = row; + startp->x = viz_rmax[row]; + + } else if (enexto(&testcc, (xchar) viz_rmax[row], row, + (struct permonst *) 0) + && !cansee(testcc.x, testcc.y) + && couldsee(testcc.x, testcc.y)) { + max_distance = dd; + *startp = testcc; + } + } + } } if (max_distance < 0) { - if (!lax) { - lax = 1; /* just find a position */ - goto retry; - } - return FALSE; + if (!lax) { + lax = 1; /* just find a position */ + goto retry; + } + return FALSE; } return TRUE; @@ -221,41 +222,38 @@ retry: */ STATIC_OVL boolean md_stop(stopp, startp) - coord *stopp; /* stopping position (we fill it in) */ - coord *startp; /* starting positon (read only) */ +coord *stopp; /* stopping position (we fill it in) */ +coord *startp; /* starting positon (read only) */ { int x, y, distance, min_distance = -1; - for (x = u.ux-1; x <= u.ux+1; x++) - for (y = u.uy-1; y <= u.uy+1; y++) { - if (!isok(x, y) || (x == u.ux && y == u.uy)) continue; + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (!isok(x, y) || (x == u.ux && y == u.uy)) + continue; - if (accessible(x, y) && !MON_AT(x,y)) { - distance = dist2(x,y,startp->x,startp->y); - if (min_distance < 0 || distance < min_distance || - (distance == min_distance && rn2(2))) { - stopp->x = x; - stopp->y = y; - min_distance = distance; - } - } - } + if (accessible(x, y) && !MON_AT(x, y)) { + distance = dist2(x, y, startp->x, startp->y); + if (min_distance < 0 || distance < min_distance + || (distance == min_distance && rn2(2))) { + stopp->x = x; + stopp->y = y; + min_distance = distance; + } + } + } /* If we didn't find a good spot, try enexto(). */ - if (min_distance < 0 && - !enexto(stopp, u.ux, u.uy, &mons[PM_MAIL_DAEMON])) - return FALSE; + if (min_distance < 0 && !enexto(stopp, u.ux, u.uy, &mons[PM_MAIL_DAEMON])) + return FALSE; return TRUE; } /* Let the mail daemon have a larger vocabulary. */ -static NEARDATA const char *mail_text[] = { - "Gangway!", - "Look out!", - "Pardon me!" -}; -#define md_exclamations() (mail_text[rn2(3)]) +static NEARDATA const char *mail_text[] = { "Gangway!", "Look out!", + "Pardon me!" }; +#define md_exclamations() (mail_text[rn2(3)]) /* * Make the mail daemon run through the dungeon. The daemon will run over @@ -264,23 +262,23 @@ static NEARDATA const char *mail_text[] = { * TRUE otherwise. */ STATIC_OVL boolean -md_rush(md,tx,ty) - struct monst *md; - register int tx, ty; /* destination of mail daemon */ +md_rush(md, tx, ty) +struct monst *md; +register int tx, ty; /* destination of mail daemon */ { - struct monst *mon; /* displaced monster */ - register int dx, dy; /* direction counters */ - int fx = md->mx, fy = md->my; /* current location */ - int nfx = fx, nfy = fy, /* new location */ - d1, d2; /* shortest distances */ + struct monst *mon; /* displaced monster */ + register int dx, dy; /* direction counters */ + int fx = md->mx, fy = md->my; /* current location */ + int nfx = fx, nfy = fy, /* new location */ + d1, d2; /* shortest distances */ /* * It is possible that the monster at (fx,fy) is not the md when: * the md rushed the hero and failed, and is now starting back. */ if (m_at(fx, fy) == md) { - remove_monster(fx, fy); /* pick up from orig position */ - newsym(fx, fy); + remove_monster(fx, fy); /* pick up from orig position */ + newsym(fx, fy); } /* @@ -288,47 +286,50 @@ md_rush(md,tx,ty) * dungeon. */ while (1) { - /* Find a good location next to (fx,fy) closest to (tx,ty). */ - d1 = dist2(fx,fy,tx,ty); - for (dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) - if ((dx || dy) && isok(fx+dx,fy+dy) && - !IS_STWALL(levl[fx+dx][fy+dy].typ)) { - d2 = dist2(fx+dx,fy+dy,tx,ty); - if (d2 < d1) { - d1 = d2; - nfx = fx+dx; - nfy = fy+dy; - } - } + /* Find a good location next to (fx,fy) closest to (tx,ty). */ + d1 = dist2(fx, fy, tx, ty); + for (dx = -1; dx <= 1; dx++) + for (dy = -1; dy <= 1; dy++) + if ((dx || dy) && isok(fx + dx, fy + dy) + && !IS_STWALL(levl[fx + dx][fy + dy].typ)) { + d2 = dist2(fx + dx, fy + dy, tx, ty); + if (d2 < d1) { + d1 = d2; + nfx = fx + dx; + nfy = fy + dy; + } + } - /* Break if the md couldn't find a new position. */ - if (nfx == fx && nfy == fy) break; + /* Break if the md couldn't find a new position. */ + if (nfx == fx && nfy == fy) + break; - fx = nfx; /* this is our new position */ - fy = nfy; + fx = nfx; /* this is our new position */ + fy = nfy; - /* Break if the md reaches its destination. */ - if (fx == tx && fy == ty) break; + /* Break if the md reaches its destination. */ + if (fx == tx && fy == ty) + break; - if ((mon = m_at(fx,fy)) != 0) /* save monster at this position */ - verbalize1(md_exclamations()); - else if (fx == u.ux && fy == u.uy) - verbalize("Excuse me."); + if ((mon = m_at(fx, fy)) != 0) /* save monster at this position */ + verbalize1(md_exclamations()); + else if (fx == u.ux && fy == u.uy) + verbalize("Excuse me."); - place_monster(md,fx,fy); /* put md down */ - newsym(fx,fy); /* see it */ - flush_screen(0); /* make sure md shows up */ - delay_output(); /* wait a little bit */ + place_monster(md, fx, fy); /* put md down */ + newsym(fx, fy); /* see it */ + flush_screen(0); /* make sure md shows up */ + delay_output(); /* wait a little bit */ - /* Remove md from the dungeon. Restore original mon, if necessary. */ - if (mon) { - if ((mon->mx != fx) || (mon->my != fy)) - place_worm_seg(mon, fx, fy); - else - place_monster(mon, fx, fy); - } else - remove_monster(fx, fy); - newsym(fx,fy); + /* Remove md from the dungeon. Restore original mon, if necessary. */ + if (mon) { + if ((mon->mx != fx) || (mon->my != fy)) + place_worm_seg(mon, fx, fy); + else + place_monster(mon, fx, fy); + } else + remove_monster(fx, fy); + newsym(fx, fy); } /* @@ -336,28 +337,27 @@ md_rush(md,tx,ty) * very unlikely). If one exists, then have the md leave in disgust. */ if ((mon = m_at(fx, fy)) != 0) { - place_monster(md, fx, fy); /* display md with text below */ - newsym(fx, fy); - verbalize("This place's too crowded. I'm outta here."); + place_monster(md, fx, fy); /* display md with text below */ + newsym(fx, fy); + verbalize("This place's too crowded. I'm outta here."); - if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */ - place_worm_seg(mon, fx, fy); - else - place_monster(mon, fx, fy); + if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */ + place_worm_seg(mon, fx, fy); + else + place_monster(mon, fx, fy); - newsym(fx, fy); - return FALSE; + newsym(fx, fy); + return FALSE; } - place_monster(md, fx, fy); /* place at final spot */ + place_monster(md, fx, fy); /* place at final spot */ newsym(fx, fy); flush_screen(0); - delay_output(); /* wait a little bit */ + delay_output(); /* wait a little bit */ return TRUE; } - /* Deliver a scroll of mail. */ /*ARGSUSED*/ STATIC_OVL void @@ -369,59 +369,63 @@ struct mail_info *info; boolean message_seen = FALSE; /* Try to find good starting and stopping places. */ - if (!md_start(&start) || !md_stop(&stop,&start)) goto give_up; + if (!md_start(&start) || !md_stop(&stop, &start)) + goto give_up; /* Make the daemon. Have it rush towards the hero. */ if (!(md = makemon(&mons[PM_MAIL_DAEMON], start.x, start.y, NO_MM_FLAGS))) - goto give_up; - if (!md_rush(md, stop.x, stop.y)) goto go_back; + goto give_up; + if (!md_rush(md, stop.x, stop.y)) + goto go_back; message_seen = TRUE; verbalize("%s, %s! %s.", Hello(md), plname, info->display_txt); if (info->message_typ) { - struct obj *obj = mksobj(SCR_MAIL, FALSE, FALSE); + struct obj *obj = mksobj(SCR_MAIL, FALSE, FALSE); - if (info->object_nam) - obj = oname(obj, info->object_nam); - if (info->response_cmd) - new_omailcmd(obj, info->response_cmd); + if (info->object_nam) + obj = oname(obj, info->object_nam); + if (info->response_cmd) + new_omailcmd(obj, info->response_cmd); - if (distu(md->mx,md->my) > 2) - verbalize("Catch!"); - display_nhwindow(WIN_MESSAGE, FALSE); - obj = hold_another_object(obj, "Oops!", - (const char *)0, (const char *)0); + if (distu(md->mx, md->my) > 2) + verbalize("Catch!"); + display_nhwindow(WIN_MESSAGE, FALSE); + obj = hold_another_object(obj, "Oops!", (const char *) 0, + (const char *) 0); } - /* zip back to starting location */ +/* zip back to starting location */ go_back: (void) md_rush(md, start.x, start.y); mongone(md); - /* deliver some classes of messages even if no daemon ever shows up */ +/* deliver some classes of messages even if no daemon ever shows up */ give_up: if (!message_seen && info->message_typ == MSG_OTHER) - pline("Hark! \"%s.\"", info->display_txt); + pline("Hark! \"%s.\"", info->display_txt); } -# if !defined(UNIX) && !defined(VMS) +#if !defined(UNIX) && !defined(VMS) void ckmailstatus() { - if (u.uswallow || !flags.biff) return; - if (mustgetmail < 0) { + if (u.uswallow || !flags.biff) + return; + if (mustgetmail < 0) { #if defined(AMIGA) || defined(MSDOS) || defined(TOS) - mustgetmail=(moves<2000)?(100+rn2(2000)):(2000+rn2(3000)); + mustgetmail = (moves < 2000) ? (100 + rn2(2000)) : (2000 + rn2(3000)); #endif - return; - } - if (--mustgetmail <= 0) { - static struct mail_info - deliver = {MSG_MAIL,"I have some mail for you",0,0}; - newmail(&deliver); - mustgetmail = -1; - } + return; + } + if (--mustgetmail <= 0) { + static struct mail_info deliver = { MSG_MAIL, + "I have some mail for you", 0, + 0 }; + newmail(&deliver); + mustgetmail = -1; + } } /*ARGSUSED*/ @@ -430,72 +434,71 @@ readmail(otmp) struct obj *otmp; { static char *junk[] = { - NULL, /* placeholder for "Report bugs to .", */ - "Please disregard previous letter.", - "Welcome to NetHack.", + NULL, /* placeholder for "Report bugs to .", */ + "Please disregard previous letter.", "Welcome to NetHack.", #ifdef AMIGA - "Only Amiga makes it possible.", - "CATS have all the answers.", + "Only Amiga makes it possible.", "CATS have all the answers.", #endif - "This mail complies with the Yendorian Anti-Spam Act (YASA)", - "Please find enclosed a small token to represent your Owlbear", - "**FR33 P0T10N 0F FULL H34L1NG**", - "Please return to sender (Asmodeus)", - "Buy a potion of gain level for only $19.99! Guaranteed to be blessed!", - "Invitation: Visit the NetHack web site at http://www.nethack.org!" + "This mail complies with the Yendorian Anti-Spam Act (YASA)", + "Please find enclosed a small token to represent your Owlbear", + "**FR33 P0T10N 0F FULL H34L1NG**", + "Please return to sender (Asmodeus)", "Buy a potion of gain level " + "for only $19.99! Guaranteed " + "to be blessed!", + "Invitation: Visit the NetHack web site at http://www.nethack.org!" }; - /* XXX replace with more general substitution code and add local - * contact message. Also use DEVTEAM_URL */ - if(junk[0] == NULL){ + /* XXX replace with more general substitution code and add local + * contact message. Also use DEVTEAM_URL */ + if (junk[0] == NULL) { #define BUGS_FORMAT "Report bugs to %s." - junk[0] = (char *)alloc(strlen(BUGS_FORMAT) + strlen(DEVTEAM_EMAIL)); - sprintf(junk[0], DEVTEAM_EMAIL); + junk[0] = (char *) alloc(strlen(BUGS_FORMAT) + strlen(DEVTEAM_EMAIL)); + sprintf(junk[0], DEVTEAM_EMAIL); #undef BUGS_FORMAT } if (Blind) { - pline("Unfortunately you cannot see what it says."); + pline("Unfortunately you cannot see what it says."); } else - pline("It reads: \"%s\"", junk[rn2(SIZE(junk))]); + pline("It reads: \"%s\"", junk[rn2(SIZE(junk))]); } -# endif /* !UNIX && !VMS */ +#endif /* !UNIX && !VMS */ -# ifdef UNIX +#ifdef UNIX void ckmailstatus() { - if(!mailbox || u.uswallow || !flags.biff -# ifdef MAILCKFREQ - || moves < laststattime + MAILCKFREQ -# endif - ) - return; + if (!mailbox || u.uswallow || !flags.biff +#ifdef MAILCKFREQ + || moves < laststattime + MAILCKFREQ +#endif + ) + return; - laststattime = moves; - if(stat(mailbox, &nmstat)){ -# ifdef PERMANENT_MAILBOX - pline("Cannot get status of MAIL=\"%s\" anymore.", mailbox); - mailbox = 0; -# else - nmstat.st_mtime = 0; -# endif - } else if(nmstat.st_mtime > omstat.st_mtime) { - if (nmstat.st_size) { - static struct mail_info deliver = { -# ifndef NO_MAILREADER - MSG_MAIL, "I have some mail for you", -# else - /* suppress creation and delivery of scroll of mail */ - MSG_OTHER, "You have some mail in the outside world", -# endif - 0, 0 - }; - newmail(&deliver); - } - getmailstatus(); /* might be too late ... */ - } + laststattime = moves; + if (stat(mailbox, &nmstat)) { +#ifdef PERMANENT_MAILBOX + pline("Cannot get status of MAIL=\"%s\" anymore.", mailbox); + mailbox = 0; +#else + nmstat.st_mtime = 0; +#endif + } else if (nmstat.st_mtime > omstat.st_mtime) { + if (nmstat.st_size) { + static struct mail_info deliver = { +#ifndef NO_MAILREADER + MSG_MAIL, "I have some mail for you", +#else + /* suppress creation and delivery of scroll of mail */ + MSG_OTHER, "You have some mail in the outside world", +#endif + 0, 0 + }; + newmail(&deliver); + } + getmailstatus(); /* might be too late ... */ + } } /*ARGSUSED*/ @@ -503,31 +506,31 @@ void readmail(otmp) struct obj *otmp; { -# ifdef DEF_MAILREADER /* This implies that UNIX is defined */ - register const char *mr = 0; +#ifdef DEF_MAILREADER /* This implies that UNIX is defined */ + register const char *mr = 0; - display_nhwindow(WIN_MESSAGE, FALSE); - if(!(mr = nh_getenv("MAILREADER"))) - mr = DEF_MAILREADER; + display_nhwindow(WIN_MESSAGE, FALSE); + if (!(mr = nh_getenv("MAILREADER"))) + mr = DEF_MAILREADER; - if(child(1)){ - (void) execl(mr, mr, (char *)0); - terminate(EXIT_FAILURE); - } -# else -# ifndef AMS /* AMS mailboxes are directories */ - display_file(mailbox, TRUE); -# endif /* AMS */ -# endif /* DEF_MAILREADER */ + if (child(1)) { + (void) execl(mr, mr, (char *) 0); + terminate(EXIT_FAILURE); + } +#else +#ifndef AMS /* AMS mailboxes are directories */ + display_file(mailbox, TRUE); +#endif /* AMS */ +#endif /* DEF_MAILREADER */ - /* get new stat; not entirely correct: there is a small time - window where we do not see new mail */ - getmailstatus(); + /* get new stat; not entirely correct: there is a small time + window where we do not see new mail */ + getmailstatus(); } -# endif /* UNIX */ +#endif /* UNIX */ -# ifdef VMS +#ifdef VMS extern NDECL(struct mail_info *parse_next_broadcast); @@ -538,14 +541,15 @@ ckmailstatus() { struct mail_info *brdcst; - if (u.uswallow || !flags.biff) return; + if (u.uswallow || !flags.biff) + return; - while (broadcasts > 0) { /* process all trapped broadcasts [until] */ - broadcasts--; - if ((brdcst = parse_next_broadcast()) != 0) { - newmail(brdcst); - break; /* only handle one real message at a time */ - } + while (broadcasts > 0) { /* process all trapped broadcasts [until] */ + broadcasts--; + if ((brdcst = parse_next_broadcast()) != 0) { + newmail(brdcst); + break; /* only handle one real message at a time */ + } } } @@ -553,35 +557,40 @@ void readmail(otmp) struct obj *otmp; { -# ifdef SHELL /* can't access mail reader without spawning subprocess */ +#ifdef SHELL /* can't access mail reader without spawning subprocess */ const char *txt, *cmd; char *p, buf[BUFSZ], qbuf[BUFSZ]; int len; /* there should be a command in OMAILCMD */ - if (has_oname(otmp)) txt = ONAME(otmp); - else txt = ""; + if (has_oname(otmp)) + txt = ONAME(otmp); + else + txt = ""; len = strlen(txt); if (has_omailcmd(otmp)) - cmd = OMAILCMD(otmp); - if (!cmd || !*cmd) cmd = "SPAWN"; + cmd = OMAILCMD(otmp); + if (!cmd || !*cmd) + cmd = "SPAWN"; Sprintf(qbuf, "System command (%s)", cmd); getlin(qbuf, buf); if (*buf != '\033') { - for (p = eos(buf); p > buf; *p = '\0') - if (*--p != ' ') break; /* strip trailing spaces */ - if (*buf) cmd = buf; /* use user entered command */ - if (!strcmpi(cmd, "SPAWN") || !strcmp(cmd, "!")) - cmd = (char *) 0; /* interactive escape */ + for (p = eos(buf); p > buf; *p = '\0') + if (*--p != ' ') + break; /* strip trailing spaces */ + if (*buf) + cmd = buf; /* use user entered command */ + if (!strcmpi(cmd, "SPAWN") || !strcmp(cmd, "!")) + cmd = (char *) 0; /* interactive escape */ - vms_doshell(cmd, TRUE); - (void) sleep(1); + vms_doshell(cmd, TRUE); + (void) sleep(1); } -# endif /* SHELL */ +#endif /* SHELL */ } -# endif /* VMS */ +#endif /* VMS */ #endif /* MAIL */ /*mail.c*/ diff --git a/src/makemon.c b/src/makemon.c index 393dd3440..bcd54868c 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 makemon.c $NHDT-Date: 1427440865 2015/03/27 07:21:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.75 $ */ +/* NetHack 3.6 makemon.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.87 $ */ /* NetHack 3.6 makemon.c $Date: 2012/01/29 00:34:33 $ $Revision: 1.69 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,38 +12,42 @@ STATIC_VAR NEARDATA struct monst zeromonst; /* this assumes that a human quest leader or nemesis is an archetype of the corresponding role; that isn't so for some roles (tourist for instance) but is for the priests and monks we use it for... */ -#define quest_mon_represents_role(mptr,role_pm) \ - (mptr->mlet == S_HUMAN && Role_if(role_pm) && \ - (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS)) +#define quest_mon_represents_role(mptr, role_pm) \ + (mptr->mlet == S_HUMAN && Role_if(role_pm) \ + && (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS)) STATIC_DCL boolean FDECL(uncommon, (int)); STATIC_DCL int FDECL(align_shift, (struct permonst *)); -STATIC_DCL boolean FDECL(mk_gen_ok, (int,int,int)); +STATIC_DCL boolean FDECL(mk_gen_ok, (int, int, int)); STATIC_DCL boolean FDECL(wrong_elem_type, (struct permonst *)); -STATIC_DCL void FDECL(m_initgrp,(struct monst *,int,int,int)); -STATIC_DCL void FDECL(m_initthrow,(struct monst *,int,int)); -STATIC_DCL void FDECL(m_initweap,(struct monst *)); -STATIC_DCL void FDECL(m_initinv,(struct monst *)); +STATIC_DCL void FDECL(m_initgrp, (struct monst *, int, int, int)); +STATIC_DCL void FDECL(m_initthrow, (struct monst *, int, int)); +STATIC_DCL void FDECL(m_initweap, (struct monst *)); +STATIC_DCL void FDECL(m_initinv, (struct monst *)); extern const int monstr[]; -#define m_initsgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 3) -#define m_initlgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 10) +#define m_initsgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 3) +#define m_initlgrp(mtmp, x, y) m_initgrp(mtmp, x, y, 10) #define toostrong(monindx, lev) (monstr[monindx] > lev) -#define tooweak(monindx, lev) (monstr[monindx] < lev) +#define tooweak(monindx, lev) (monstr[monindx] < lev) boolean is_home_elemental(ptr) register struct permonst *ptr; { - if (ptr->mlet == S_ELEMENTAL) - switch (monsndx(ptr)) { - case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz); - case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz); - case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz); - case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz); - } - return FALSE; + if (ptr->mlet == S_ELEMENTAL) + switch (monsndx(ptr)) { + case PM_AIR_ELEMENTAL: + return Is_airlevel(&u.uz); + case PM_FIRE_ELEMENTAL: + return Is_firelevel(&u.uz); + case PM_EARTH_ELEMENTAL: + return Is_earthlevel(&u.uz); + case PM_WATER_ELEMENTAL: + return Is_waterlevel(&u.uz); + } + return FALSE; } /* @@ -51,414 +55,465 @@ register struct permonst *ptr; */ STATIC_OVL boolean wrong_elem_type(ptr) - register struct permonst *ptr; +register struct permonst *ptr; { if (ptr->mlet == S_ELEMENTAL) { - return((boolean)(!is_home_elemental(ptr))); + return ((boolean)(!is_home_elemental(ptr))); } else if (Is_earthlevel(&u.uz)) { - /* no restrictions? */ + /* no restrictions? */ } else if (Is_waterlevel(&u.uz)) { - /* just monsters that can swim */ - if(!is_swimmer(ptr)) return TRUE; + /* just monsters that can swim */ + if (!is_swimmer(ptr)) + return TRUE; } else if (Is_firelevel(&u.uz)) { - if (!pm_resistance(ptr,MR_FIRE)) return TRUE; + if (!pm_resistance(ptr, MR_FIRE)) + return TRUE; } else if (Is_airlevel(&u.uz)) { - if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr) - && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr)) - return TRUE; + if (!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr) + && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr)) + return TRUE; } return FALSE; } -STATIC_OVL void -m_initgrp(mtmp, x, y, n) /* make a group just like mtmp */ +STATIC_OVL void m_initgrp(mtmp, x, y, n) /* make a group just like mtmp */ register struct monst *mtmp; register int x, y, n; { - coord mm; - register int cnt = rnd(n); - struct monst *mon; + coord mm; + register int cnt = rnd(n); + struct monst *mon; #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) - /* There is an unresolved problem with several people finding that - * the game hangs eating CPU; if interrupted and restored, the level - * will be filled with monsters. Of those reports giving system type, - * there were two DG/UX and two HP-UX, all using gcc as the compiler. - * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the - * problem went away for him and another reporter-to-newsgroup - * after adding this debugging code. This has almost got to be a - * compiler bug, but until somebody tracks it down and gets it fixed, - * might as well go with the "but it went away when I tried to find - * it" code. - */ - int cnttmp,cntdiv; + /* There is an unresolved problem with several people finding that + * the game hangs eating CPU; if interrupted and restored, the level + * will be filled with monsters. Of those reports giving system type, + * there were two DG/UX and two HP-UX, all using gcc as the compiler. + * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the + * problem went away for him and another reporter-to-newsgroup + * after adding this debugging code. This has almost got to be a + * compiler bug, but until somebody tracks it down and gets it fixed, + * might as well go with the "but it went away when I tried to find + * it" code. + */ + int cnttmp, cntdiv; - cnttmp = cnt; - debugpline4("init group call <%d,%d>, n=%d, cnt=%d.", x, y, n, cnt); - cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1); + cnttmp = cnt; + debugpline4("init group call <%d,%d>, n=%d, cnt=%d.", x, y, n, cnt); + cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1); #endif - /* Tuning: cut down on swarming at low character levels [mrs] */ - cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1; + /* Tuning: cut down on swarming at low character levels [mrs] */ + cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1; #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) - if (cnt != (cnttmp/cntdiv)) { - pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt, - (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1, - cnttmp, cntdiv); - } + if (cnt != (cnttmp / cntdiv)) { + pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt, + (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1, cnttmp, cntdiv); + } #endif - if(!cnt) cnt++; + if (!cnt) + cnt++; #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) - if (cnt < 0) cnt = 1; - if (cnt > 10) cnt = 10; + if (cnt < 0) + cnt = 1; + if (cnt > 10) + cnt = 10; #endif - mm.x = x; - mm.y = y; - while(cnt--) { - if (peace_minded(mtmp->data)) continue; - /* Don't create groups of peaceful monsters since they'll get - * in our way. If the monster has a percentage chance so some - * are peaceful and some are not, the result will just be a - * smaller group. - */ - if (enexto(&mm, mm.x, mm.y, mtmp->data)) { - mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS); - if (mon) { - mon->mpeaceful = FALSE; - mon->mavenge = 0; - set_malign(mon); - /* Undo the second peace_minded() check in makemon(); if the - * monster turned out to be peaceful the first time we - * didn't create it at all; we don't want a second check. - */ - } - } - } + mm.x = x; + mm.y = y; + while (cnt--) { + if (peace_minded(mtmp->data)) + continue; + /* Don't create groups of peaceful monsters since they'll get + * in our way. If the monster has a percentage chance so some + * are peaceful and some are not, the result will just be a + * smaller group. + */ + if (enexto(&mm, mm.x, mm.y, mtmp->data)) { + mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS); + if (mon) { + mon->mpeaceful = FALSE; + mon->mavenge = 0; + set_malign(mon); + /* Undo the second peace_minded() check in makemon(); if the + * monster turned out to be peaceful the first time we + * didn't create it at all; we don't want a second check. + */ + } + } + } } STATIC_OVL void -m_initthrow(mtmp,otyp,oquan) +m_initthrow(mtmp, otyp, oquan) struct monst *mtmp; -int otyp,oquan; +int otyp, oquan; { - register struct obj *otmp; + register struct obj *otmp; - otmp = mksobj(otyp, TRUE, FALSE); - otmp->quan = (long) rn1(oquan, 3); - otmp->owt = weight(otmp); - if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE; - (void) mpickobj(mtmp, otmp); + otmp = mksobj(otyp, TRUE, FALSE); + otmp->quan = (long) rn1(oquan, 3); + otmp->owt = weight(otmp); + if (otyp == ORCISH_ARROW) + otmp->opoisoned = TRUE; + (void) mpickobj(mtmp, otmp); } STATIC_OVL void m_initweap(mtmp) register struct monst *mtmp; { - register struct permonst *ptr = mtmp->data; - register int mm = monsndx(ptr); - struct obj *otmp; + register struct permonst *ptr = mtmp->data; + register int mm = monsndx(ptr); + struct obj *otmp; - if (Is_rogue_level(&u.uz)) return; -/* - * first a few special cases: - * - * giants get a boulder to throw sometimes. - * ettins get clubs - * kobolds get darts to throw - * centaurs get some sort of bow & arrows or bolts - * soldiers get all sorts of things. - * kops get clubs & cream pies. - */ - switch (ptr->mlet) { - case S_GIANT: - if (rn2(2)) (void)mongets(mtmp, (mm != PM_ETTIN) ? - BOULDER : CLUB); - break; - case S_HUMAN: - if(is_mercenary(ptr)) { - int w1 = 0, w2 = 0; - switch (mm) { + if (Is_rogue_level(&u.uz)) + return; + /* + * first a few special cases: + * + * giants get a boulder to throw sometimes. + * ettins get clubs + * kobolds get darts to throw + * centaurs get some sort of bow & arrows or bolts + * soldiers get all sorts of things. + * kops get clubs & cream pies. + */ + switch (ptr->mlet) { + case S_GIANT: + if (rn2(2)) + (void) mongets(mtmp, (mm != PM_ETTIN) ? BOULDER : CLUB); + break; + case S_HUMAN: + if (is_mercenary(ptr)) { + int w1 = 0, w2 = 0; + switch (mm) { + case PM_WATCHMAN: + case PM_SOLDIER: + if (!rn2(3)) { + w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN); + w2 = rn2(2) ? DAGGER : KNIFE; + } else + w1 = rn2(2) ? SPEAR : SHORT_SWORD; + break; + case PM_SERGEANT: + w1 = rn2(2) ? FLAIL : MACE; + break; + case PM_LIEUTENANT: + w1 = rn2(2) ? BROADSWORD : LONG_SWORD; + break; + case PM_CAPTAIN: + case PM_WATCH_CAPTAIN: + w1 = rn2(2) ? LONG_SWORD : SILVER_SABER; + break; + default: + if (!rn2(4)) + w1 = DAGGER; + if (!rn2(7)) + w2 = SPEAR; + break; + } + if (w1) + (void) mongets(mtmp, w1); + if (!w2 && w1 != DAGGER && !rn2(4)) + w2 = KNIFE; + if (w2) + (void) mongets(mtmp, w2); + } else if (is_elf(ptr)) { + if (rn2(2)) + (void) mongets(mtmp, + rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK); + if (rn2(2)) + (void) mongets(mtmp, ELVEN_LEATHER_HELM); + else if (!rn2(4)) + (void) mongets(mtmp, ELVEN_BOOTS); + if (rn2(2)) + (void) mongets(mtmp, ELVEN_DAGGER); + switch (rn2(3)) { + case 0: + if (!rn2(4)) + (void) mongets(mtmp, ELVEN_SHIELD); + if (rn2(3)) + (void) mongets(mtmp, ELVEN_SHORT_SWORD); + (void) mongets(mtmp, ELVEN_BOW); + m_initthrow(mtmp, ELVEN_ARROW, 12); + break; + case 1: + (void) mongets(mtmp, ELVEN_BROADSWORD); + if (rn2(2)) + (void) mongets(mtmp, ELVEN_SHIELD); + break; + case 2: + if (rn2(2)) { + (void) mongets(mtmp, ELVEN_SPEAR); + (void) mongets(mtmp, ELVEN_SHIELD); + } + break; + } + if (mm == PM_ELVENKING) { + if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) + (void) mongets(mtmp, PICK_AXE); + if (!rn2(50)) + (void) mongets(mtmp, CRYSTAL_BALL); + } + } else if (ptr->msound == MS_PRIEST + || quest_mon_represents_role(ptr, PM_PRIEST)) { + otmp = mksobj(MACE, FALSE, FALSE); + if (otmp) { + otmp->spe = rnd(3); + if (!rn2(2)) + curse(otmp); + (void) mpickobj(mtmp, otmp); + } + } else if (mm == PM_NINJA) { /* extra quest villains */ + (void) mongets(mtmp, rn2(4) ? SHURIKEN : DART); + (void) mongets(mtmp, rn2(4) ? SHORT_SWORD : AXE); + } + break; - case PM_WATCHMAN: - case PM_SOLDIER: - if (!rn2(3)) { - w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN); - w2 = rn2(2) ? DAGGER : KNIFE; - } else w1 = rn2(2) ? SPEAR : SHORT_SWORD; - break; - case PM_SERGEANT: - w1 = rn2(2) ? FLAIL : MACE; - break; - case PM_LIEUTENANT: - w1 = rn2(2) ? BROADSWORD : LONG_SWORD; - break; - case PM_CAPTAIN: - case PM_WATCH_CAPTAIN: - w1 = rn2(2) ? LONG_SWORD : SILVER_SABER; - break; - default: - if (!rn2(4)) w1 = DAGGER; - if (!rn2(7)) w2 = SPEAR; - break; - } - if (w1) (void)mongets(mtmp, w1); - if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE; - if (w2) (void)mongets(mtmp, w2); - } else if (is_elf(ptr)) { - if (rn2(2)) - (void) mongets(mtmp, - rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK); - if (rn2(2)) (void)mongets(mtmp, ELVEN_LEATHER_HELM); - else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS); - if (rn2(2)) (void)mongets(mtmp, ELVEN_DAGGER); - switch (rn2(3)) { - case 0: - if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD); - if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD); - (void)mongets(mtmp, ELVEN_BOW); - m_initthrow(mtmp, ELVEN_ARROW, 12); - break; - case 1: - (void)mongets(mtmp, ELVEN_BROADSWORD); - if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD); - break; - case 2: - if (rn2(2)) { - (void)mongets(mtmp, ELVEN_SPEAR); - (void)mongets(mtmp, ELVEN_SHIELD); - } - break; - } - if (mm == PM_ELVENKING) { - if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) - (void)mongets(mtmp, PICK_AXE); - if (!rn2(50)) (void)mongets(mtmp, CRYSTAL_BALL); - } - } else if (ptr->msound == MS_PRIEST || - quest_mon_represents_role(ptr,PM_PRIEST)) { - otmp = mksobj(MACE, FALSE, FALSE); - if(otmp) { - otmp->spe = rnd(3); - if(!rn2(2)) curse(otmp); - (void) mpickobj(mtmp, otmp); - } - } else if (mm == PM_NINJA) { /* extra quest villains */ - (void)mongets(mtmp, rn2(4) ? SHURIKEN : DART); - (void)mongets(mtmp, rn2(4) ? SHORT_SWORD : AXE); - } - break; + case S_ANGEL: + if (humanoid(ptr)) { + int spe2; - case S_ANGEL: - if (humanoid(ptr)) { - int spe2; + /* create minion stuff; can't use mongets */ + otmp = mksobj(LONG_SWORD, FALSE, FALSE); - /* create minion stuff; can't use mongets */ - otmp = mksobj(LONG_SWORD, FALSE, FALSE); + /* maybe make it special */ + if (!rn2(20) || is_lord(ptr)) + otmp = oname(otmp, + artiname(rn2(2) ? ART_DEMONBANE : ART_SUNSWORD)); + bless(otmp); + otmp->oerodeproof = TRUE; + spe2 = rn2(4); + otmp->spe = max(otmp->spe, spe2); + (void) mpickobj(mtmp, otmp); - /* maybe make it special */ - if (!rn2(20) || is_lord(ptr)) - otmp = oname(otmp, artiname( - rn2(2) ? ART_DEMONBANE : ART_SUNSWORD)); - bless(otmp); - otmp->oerodeproof = TRUE; - spe2 = rn2(4); - otmp->spe = max(otmp->spe, spe2); - (void) mpickobj(mtmp, otmp); + otmp = mksobj(!rn2(4) || is_lord(ptr) ? SHIELD_OF_REFLECTION + : LARGE_SHIELD, + FALSE, FALSE); + otmp->cursed = FALSE; + otmp->oerodeproof = TRUE; + otmp->spe = 0; + (void) mpickobj(mtmp, otmp); + } + break; - otmp = mksobj(!rn2(4) || is_lord(ptr) ? - SHIELD_OF_REFLECTION : LARGE_SHIELD, - FALSE, FALSE); - otmp->cursed = FALSE; - otmp->oerodeproof = TRUE; - otmp->spe = 0; - (void) mpickobj(mtmp, otmp); - } - break; + case S_HUMANOID: + if (mm == PM_HOBBIT) { + switch (rn2(3)) { + case 0: + (void) mongets(mtmp, DAGGER); + break; + case 1: + (void) mongets(mtmp, ELVEN_DAGGER); + break; + case 2: + (void) mongets(mtmp, SLING); + break; + } + if (!rn2(10)) + (void) mongets(mtmp, ELVEN_MITHRIL_COAT); + if (!rn2(10)) + (void) mongets(mtmp, DWARVISH_CLOAK); + } else if (is_dwarf(ptr)) { + if (rn2(7)) + (void) mongets(mtmp, DWARVISH_CLOAK); + if (rn2(7)) + (void) mongets(mtmp, IRON_SHOES); + if (!rn2(4)) { + (void) mongets(mtmp, DWARVISH_SHORT_SWORD); + /* note: you can't use a mattock with a shield */ + if (rn2(2)) + (void) mongets(mtmp, DWARVISH_MATTOCK); + else { + (void) mongets(mtmp, AXE); + (void) mongets(mtmp, DWARVISH_ROUNDSHIELD); + } + (void) mongets(mtmp, DWARVISH_IRON_HELM); + if (!rn2(3)) + (void) mongets(mtmp, DWARVISH_MITHRIL_COAT); + } else { + (void) mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER); + } + } + break; + case S_KOP: /* create Keystone Kops with cream pies to + * throw. As suggested by KAA. [MRS] + */ + if (!rn2(4)) + m_initthrow(mtmp, CREAM_PIE, 2); + if (!rn2(3)) + (void) mongets(mtmp, (rn2(2)) ? CLUB : RUBBER_HOSE); + break; + case S_ORC: + if (rn2(2)) + (void) mongets(mtmp, ORCISH_HELM); + switch (mm != PM_ORC_CAPTAIN ? mm : rn2(2) ? PM_MORDOR_ORC + : PM_URUK_HAI) { + case PM_MORDOR_ORC: + if (!rn2(3)) + (void) mongets(mtmp, SCIMITAR); + if (!rn2(3)) + (void) mongets(mtmp, ORCISH_SHIELD); + if (!rn2(3)) + (void) mongets(mtmp, KNIFE); + if (!rn2(3)) + (void) mongets(mtmp, ORCISH_CHAIN_MAIL); + break; + case PM_URUK_HAI: + if (!rn2(3)) + (void) mongets(mtmp, ORCISH_CLOAK); + if (!rn2(3)) + (void) mongets(mtmp, ORCISH_SHORT_SWORD); + if (!rn2(3)) + (void) mongets(mtmp, IRON_SHOES); + if (!rn2(3)) { + (void) mongets(mtmp, ORCISH_BOW); + m_initthrow(mtmp, ORCISH_ARROW, 12); + } + if (!rn2(3)) + (void) mongets(mtmp, URUK_HAI_SHIELD); + break; + default: + if (mm != PM_ORC_SHAMAN && rn2(2)) + (void) mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0) + ? ORCISH_DAGGER + : SCIMITAR); + } + break; + case S_OGRE: + if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12)) + (void) mongets(mtmp, BATTLE_AXE); + else + (void) mongets(mtmp, CLUB); + break; + case S_TROLL: + if (!rn2(2)) + switch (rn2(4)) { + case 0: + (void) mongets(mtmp, RANSEUR); + break; + case 1: + (void) mongets(mtmp, PARTISAN); + break; + case 2: + (void) mongets(mtmp, GLAIVE); + break; + case 3: + (void) mongets(mtmp, SPETUM); + break; + } + break; + case S_KOBOLD: + if (!rn2(4)) + m_initthrow(mtmp, DART, 12); + break; - case S_HUMANOID: - if (mm == PM_HOBBIT) { - switch (rn2(3)) { - case 0: - (void)mongets(mtmp, DAGGER); - break; - case 1: - (void)mongets(mtmp, ELVEN_DAGGER); - break; - case 2: - (void)mongets(mtmp, SLING); - break; - } - if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT); - if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK); - } else if (is_dwarf(ptr)) { - if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK); - if (rn2(7)) (void)mongets(mtmp, IRON_SHOES); - if (!rn2(4)) { - (void)mongets(mtmp, DWARVISH_SHORT_SWORD); - /* note: you can't use a mattock with a shield */ - if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK); - else { - (void)mongets(mtmp, AXE); - (void)mongets(mtmp, DWARVISH_ROUNDSHIELD); - } - (void)mongets(mtmp, DWARVISH_IRON_HELM); - if (!rn2(3)) - (void)mongets(mtmp, DWARVISH_MITHRIL_COAT); - } else { - (void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER); - } - } - break; - case S_KOP: /* create Keystone Kops with cream pies to - * throw. As suggested by KAA. [MRS] - */ - if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2); - if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE); - break; - case S_ORC: - if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM); - switch (mm != PM_ORC_CAPTAIN ? mm : - rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) { - case PM_MORDOR_ORC: - if(!rn2(3)) (void)mongets(mtmp, SCIMITAR); - if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD); - if(!rn2(3)) (void)mongets(mtmp, KNIFE); - if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL); - break; - case PM_URUK_HAI: - if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK); - if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD); - if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES); - if(!rn2(3)) { - (void)mongets(mtmp, ORCISH_BOW); - m_initthrow(mtmp, ORCISH_ARROW, 12); - } - if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD); - break; - default: - if (mm != PM_ORC_SHAMAN && rn2(2)) - (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0) - ? ORCISH_DAGGER : SCIMITAR); - } - break; - case S_OGRE: - if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12)) - (void) mongets(mtmp, BATTLE_AXE); - else - (void) mongets(mtmp, CLUB); - break; - case S_TROLL: - if (!rn2(2)) switch (rn2(4)) { - case 0: (void)mongets(mtmp, RANSEUR); break; - case 1: (void)mongets(mtmp, PARTISAN); break; - case 2: (void)mongets(mtmp, GLAIVE); break; - case 3: (void)mongets(mtmp, SPETUM); break; - } - break; - case S_KOBOLD: - if (!rn2(4)) m_initthrow(mtmp, DART, 12); - break; + case S_CENTAUR: + if (rn2(2)) { + if (ptr == &mons[PM_FOREST_CENTAUR]) { + (void) mongets(mtmp, BOW); + m_initthrow(mtmp, ARROW, 12); + } else { + (void) mongets(mtmp, CROSSBOW); + m_initthrow(mtmp, CROSSBOW_BOLT, 12); + } + } + break; + case S_WRAITH: + (void) mongets(mtmp, KNIFE); + (void) mongets(mtmp, LONG_SWORD); + break; + case S_ZOMBIE: + if (!rn2(4)) + (void) mongets(mtmp, LEATHER_ARMOR); + if (!rn2(4)) + (void) mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD)); + break; + case S_LIZARD: + if (mm == PM_SALAMANDER) + (void) mongets(mtmp, + (rn2(7) ? SPEAR : rn2(3) ? TRIDENT : STILETTO)); + break; + case S_DEMON: + switch (mm) { + case PM_BALROG: + (void) mongets(mtmp, BULLWHIP); + (void) mongets(mtmp, BROADSWORD); + break; + case PM_ORCUS: + (void) mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */ + break; + case PM_HORNED_DEVIL: + (void) mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP); + break; + case PM_DISPATER: + (void) mongets(mtmp, WAN_STRIKING); + break; + case PM_YEENOGHU: + (void) mongets(mtmp, FLAIL); + break; + } + /* prevent djinn and mail daemons from leaving objects when + * they vanish + */ + if (!is_demon(ptr)) + break; + /* fall thru */ + /* + * Now the general case, Some chance of getting some type + * of weapon for "normal" monsters. Certain special types + * of monsters will get a bonus chance or different selections. + */ + default: { + int bias; - case S_CENTAUR: - if (rn2(2)) { - if(ptr == &mons[PM_FOREST_CENTAUR]) { - (void)mongets(mtmp, BOW); - m_initthrow(mtmp, ARROW, 12); - } else { - (void)mongets(mtmp, CROSSBOW); - m_initthrow(mtmp, CROSSBOW_BOLT, 12); - } - } - break; - case S_WRAITH: - (void)mongets(mtmp, KNIFE); - (void)mongets(mtmp, LONG_SWORD); - break; - case S_ZOMBIE: - if (!rn2(4)) (void)mongets(mtmp, LEATHER_ARMOR); - if (!rn2(4)) - (void)mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD)); - break; - case S_LIZARD: - if (mm == PM_SALAMANDER) - (void)mongets(mtmp, (rn2(7) ? SPEAR : rn2(3) ? - TRIDENT : STILETTO)); - break; - case S_DEMON: - switch (mm) { - case PM_BALROG: - (void)mongets(mtmp, BULLWHIP); - (void)mongets(mtmp, BROADSWORD); - break; - case PM_ORCUS: - (void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */ - break; - case PM_HORNED_DEVIL: - (void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP); - break; - case PM_DISPATER: - (void)mongets(mtmp, WAN_STRIKING); - break; - case PM_YEENOGHU: - (void)mongets(mtmp, FLAIL); - break; - } - /* prevent djinn and mail daemons from leaving objects when - * they vanish - */ - if (!is_demon(ptr)) break; - /* fall thru */ -/* - * Now the general case, Some chance of getting some type - * of weapon for "normal" monsters. Certain special types - * of monsters will get a bonus chance or different selections. - */ - default: - { - int bias; - - bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr); - switch(rnd(14 - (2 * bias))) { - case 1: - if(strongmonst(ptr)) (void) mongets(mtmp, BATTLE_AXE); - else m_initthrow(mtmp, DART, 12); - break; - case 2: - if(strongmonst(ptr)) - (void) mongets(mtmp, TWO_HANDED_SWORD); - else { - (void) mongets(mtmp, CROSSBOW); - m_initthrow(mtmp, CROSSBOW_BOLT, 12); - } - break; - case 3: - (void) mongets(mtmp, BOW); - m_initthrow(mtmp, ARROW, 12); - break; - case 4: - if(strongmonst(ptr)) (void) mongets(mtmp, LONG_SWORD); - else m_initthrow(mtmp, DAGGER, 3); - break; - case 5: - if(strongmonst(ptr)) - (void) mongets(mtmp, LUCERN_HAMMER); - else (void) mongets(mtmp, AKLYS); - break; - default: - break; - } - } - break; - } - if ((int) mtmp->m_lev > rn2(75)) - (void) mongets(mtmp, rnd_offensive_item(mtmp)); + bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr); + switch (rnd(14 - (2 * bias))) { + case 1: + if (strongmonst(ptr)) + (void) mongets(mtmp, BATTLE_AXE); + else + m_initthrow(mtmp, DART, 12); + break; + case 2: + if (strongmonst(ptr)) + (void) mongets(mtmp, TWO_HANDED_SWORD); + else { + (void) mongets(mtmp, CROSSBOW); + m_initthrow(mtmp, CROSSBOW_BOLT, 12); + } + break; + case 3: + (void) mongets(mtmp, BOW); + m_initthrow(mtmp, ARROW, 12); + break; + case 4: + if (strongmonst(ptr)) + (void) mongets(mtmp, LONG_SWORD); + else + m_initthrow(mtmp, DAGGER, 3); + break; + case 5: + if (strongmonst(ptr)) + (void) mongets(mtmp, LUCERN_HAMMER); + else + (void) mongets(mtmp, AKLYS); + break; + default: + break; + } + } break; + } + if ((int) mtmp->m_lev > rn2(75)) + (void) mongets(mtmp, rnd_offensive_item(mtmp)); } /* * Makes up money for monster's inventory. * This will change with silver & copper coins */ -void +void mkmonmoney(mtmp, amount) struct monst *mtmp; long amount; @@ -470,273 +525,303 @@ long amount; STATIC_OVL void m_initinv(mtmp) -register struct monst *mtmp; +register struct monst *mtmp; { - register int cnt; - register struct obj *otmp; - register struct permonst *ptr = mtmp->data; - if (Is_rogue_level(&u.uz)) return; -/* - * Soldiers get armour & rations - armour approximates their ac. - * Nymphs may get mirror or potion of object detection. - */ - switch(ptr->mlet) { + register int cnt; + register struct obj *otmp; + register struct permonst *ptr = mtmp->data; + if (Is_rogue_level(&u.uz)) + return; + /* + * Soldiers get armour & rations - armour approximates their ac. + * Nymphs may get mirror or potion of object detection. + */ + switch (ptr->mlet) { + case S_HUMAN: + if (is_mercenary(ptr)) { + register int mac; - case S_HUMAN: - if(is_mercenary(ptr)) { - register int mac; + switch (monsndx(ptr)) { + case PM_GUARD: + mac = -1; + break; + case PM_SOLDIER: + mac = 3; + break; + case PM_SERGEANT: + mac = 0; + break; + case PM_LIEUTENANT: + mac = -2; + break; + case PM_CAPTAIN: + mac = -3; + break; + case PM_WATCHMAN: + mac = 3; + break; + case PM_WATCH_CAPTAIN: + mac = -2; + break; + default: + impossible("odd mercenary %d?", monsndx(ptr)); + mac = 0; + break; + } - switch(monsndx(ptr)) { - case PM_GUARD: mac = -1; break; - case PM_SOLDIER: mac = 3; break; - case PM_SERGEANT: mac = 0; break; - case PM_LIEUTENANT: mac = -2; break; - case PM_CAPTAIN: mac = -3; break; - case PM_WATCHMAN: mac = 3; break; - case PM_WATCH_CAPTAIN: mac = -2; break; - default: impossible("odd mercenary %d?", monsndx(ptr)); - mac = 0; - break; - } + if (mac < -1 && rn2(5)) + mac += 7 + mongets(mtmp, (rn2(5)) ? PLATE_MAIL + : CRYSTAL_PLATE_MAIL); + else if (mac < 3 && rn2(5)) + mac += + 6 + mongets(mtmp, (rn2(3)) ? SPLINT_MAIL : BANDED_MAIL); + else if (rn2(5)) + mac += 3 + mongets(mtmp, (rn2(3)) ? RING_MAIL + : STUDDED_LEATHER_ARMOR); + else + mac += 2 + mongets(mtmp, LEATHER_ARMOR); - if (mac < -1 && rn2(5)) - mac += 7 + mongets(mtmp, (rn2(5)) ? - PLATE_MAIL : CRYSTAL_PLATE_MAIL); - else if (mac < 3 && rn2(5)) - mac += 6 + mongets(mtmp, (rn2(3)) ? - SPLINT_MAIL : BANDED_MAIL); - else if (rn2(5)) - mac += 3 + mongets(mtmp, (rn2(3)) ? - RING_MAIL : STUDDED_LEATHER_ARMOR); - else - mac += 2 + mongets(mtmp, LEATHER_ARMOR); + if (mac < 10 && rn2(3)) + mac += 1 + mongets(mtmp, HELMET); + else if (mac < 10 && rn2(2)) + mac += 1 + mongets(mtmp, DENTED_POT); + if (mac < 10 && rn2(3)) + mac += 1 + mongets(mtmp, SMALL_SHIELD); + else if (mac < 10 && rn2(2)) + mac += 2 + mongets(mtmp, LARGE_SHIELD); + if (mac < 10 && rn2(3)) + mac += 1 + mongets(mtmp, LOW_BOOTS); + else if (mac < 10 && rn2(2)) + mac += 2 + mongets(mtmp, HIGH_BOOTS); + if (mac < 10 && rn2(3)) + mac += 1 + mongets(mtmp, LEATHER_GLOVES); + else if (mac < 10 && rn2(2)) + mac += 1 + mongets(mtmp, LEATHER_CLOAK); - if (mac < 10 && rn2(3)) - mac += 1 + mongets(mtmp, HELMET); - else if (mac < 10 && rn2(2)) - mac += 1 + mongets(mtmp, DENTED_POT); - if (mac < 10 && rn2(3)) - mac += 1 + mongets(mtmp, SMALL_SHIELD); - else if (mac < 10 && rn2(2)) - mac += 2 + mongets(mtmp, LARGE_SHIELD); - if (mac < 10 && rn2(3)) - mac += 1 + mongets(mtmp, LOW_BOOTS); - else if (mac < 10 && rn2(2)) - mac += 2 + mongets(mtmp, HIGH_BOOTS); - if (mac < 10 && rn2(3)) - mac += 1 + mongets(mtmp, LEATHER_GLOVES); - else if (mac < 10 && rn2(2)) - mac += 1 + mongets(mtmp, LEATHER_CLOAK); + if (ptr != &mons[PM_GUARD] && ptr != &mons[PM_WATCHMAN] + && ptr != &mons[PM_WATCH_CAPTAIN]) { + if (!rn2(3)) + (void) mongets(mtmp, K_RATION); + if (!rn2(2)) + (void) mongets(mtmp, C_RATION); + if (ptr != &mons[PM_SOLDIER] && !rn2(3)) + (void) mongets(mtmp, BUGLE); + } else if (ptr == &mons[PM_WATCHMAN] && rn2(3)) + (void) mongets(mtmp, TIN_WHISTLE); + } else if (ptr == &mons[PM_SHOPKEEPER]) { + (void) mongets(mtmp, SKELETON_KEY); + switch (rn2(4)) { + /* MAJOR fall through ... */ + case 0: + (void) mongets(mtmp, WAN_MAGIC_MISSILE); + case 1: + (void) mongets(mtmp, POT_EXTRA_HEALING); + case 2: + (void) mongets(mtmp, POT_HEALING); + case 3: + (void) mongets(mtmp, WAN_STRIKING); + } + } else if (ptr->msound == MS_PRIEST + || quest_mon_represents_role(ptr, PM_PRIEST)) { + (void) mongets(mtmp, rn2(7) ? ROBE + : rn2(3) ? CLOAK_OF_PROTECTION + : CLOAK_OF_MAGIC_RESISTANCE); + (void) mongets(mtmp, SMALL_SHIELD); + mkmonmoney(mtmp, (long) rn1(10, 20)); + } else if (quest_mon_represents_role(ptr, PM_MONK)) { + (void) mongets(mtmp, rn2(11) ? ROBE : CLOAK_OF_MAGIC_RESISTANCE); + } + break; + case S_NYMPH: + if (!rn2(2)) + (void) mongets(mtmp, MIRROR); + if (!rn2(2)) + (void) mongets(mtmp, POT_OBJECT_DETECTION); + break; + case S_GIANT: + if (ptr == &mons[PM_MINOTAUR]) { + if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) + (void) mongets(mtmp, WAN_DIGGING); + } else if (is_giant(ptr)) { + for (cnt = rn2((int) (mtmp->m_lev / 2)); cnt; cnt--) { + otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE - 1), + FALSE, FALSE); + otmp->quan = (long) rn1(2, 3); + otmp->owt = weight(otmp); + (void) mpickobj(mtmp, otmp); + } + } + break; + case S_WRAITH: + if (ptr == &mons[PM_NAZGUL]) { + otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE); + curse(otmp); + (void) mpickobj(mtmp, otmp); + } + break; + case S_LICH: + if (ptr == &mons[PM_MASTER_LICH] && !rn2(13)) + (void) mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING)); + else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) { + otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF, TRUE, + rn2(13) ? FALSE : TRUE); + if (otmp->spe < 2) + otmp->spe = rnd(3); + if (!rn2(4)) + otmp->oerodeproof = 1; + (void) mpickobj(mtmp, otmp); + } + break; + case S_MUMMY: + if (rn2(7)) + (void) mongets(mtmp, MUMMY_WRAPPING); + break; + case S_QUANTMECH: + if (!rn2(20)) { + otmp = mksobj(LARGE_BOX, FALSE, FALSE); + otmp->spe = 1; /* flag for special box */ + otmp->owt = weight(otmp); + (void) mpickobj(mtmp, otmp); + } + break; + case S_LEPRECHAUN: + mkmonmoney(mtmp, (long) d(level_difficulty(), 30)); + break; + case S_DEMON: + /* moved here from m_initweap() because these don't + have AT_WEAP so m_initweap() is not called for them */ + if (ptr == &mons[PM_ICE_DEVIL] && !rn2(4)) { + (void) mongets(mtmp, SPEAR); + } else if (ptr == &mons[PM_ASMODEUS]) { + (void) mongets(mtmp, WAN_COLD); + (void) mongets(mtmp, WAN_FIRE); + } + break; + case S_GNOME: + if (!rn2((In_mines(&u.uz) ? 5 : 10))) { + otmp = mksobj(rn2(4) ? TALLOW_CANDLE : WAX_CANDLE, TRUE, FALSE); + otmp->quan = 1; + otmp->owt = weight(otmp); + if (!mpickobj(mtmp, otmp) && !levl[mtmp->mx][mtmp->my].lit) + begin_burn(otmp, FALSE); + } + break; + default: + break; + } - if(ptr != &mons[PM_GUARD] && - ptr != &mons[PM_WATCHMAN] && - ptr != &mons[PM_WATCH_CAPTAIN]) { - if (!rn2(3)) (void) mongets(mtmp, K_RATION); - if (!rn2(2)) (void) mongets(mtmp, C_RATION); - if (ptr != &mons[PM_SOLDIER] && !rn2(3)) - (void) mongets(mtmp, BUGLE); - } else - if (ptr == &mons[PM_WATCHMAN] && rn2(3)) - (void) mongets(mtmp, TIN_WHISTLE); - } else if (ptr == &mons[PM_SHOPKEEPER]) { - (void) mongets(mtmp,SKELETON_KEY); - switch (rn2(4)) { - /* MAJOR fall through ... */ - case 0: (void) mongets(mtmp, WAN_MAGIC_MISSILE); - case 1: (void) mongets(mtmp, POT_EXTRA_HEALING); - case 2: (void) mongets(mtmp, POT_HEALING); - case 3: (void) mongets(mtmp, WAN_STRIKING); - } - } else if (ptr->msound == MS_PRIEST || - quest_mon_represents_role(ptr,PM_PRIEST)) { - (void) mongets(mtmp, rn2(7) ? ROBE : - rn2(3) ? CLOAK_OF_PROTECTION : - CLOAK_OF_MAGIC_RESISTANCE); - (void) mongets(mtmp, SMALL_SHIELD); - mkmonmoney(mtmp,(long)rn1(10,20)); - } else if (quest_mon_represents_role(ptr,PM_MONK)) { - (void) mongets(mtmp, rn2(11) ? ROBE : - CLOAK_OF_MAGIC_RESISTANCE); - } - break; - case S_NYMPH: - if(!rn2(2)) (void) mongets(mtmp, MIRROR); - if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION); - break; - case S_GIANT: - if (ptr == &mons[PM_MINOTAUR]) { - if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) - (void) mongets(mtmp, WAN_DIGGING); - } else if (is_giant(ptr)) { - for (cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) { - otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1), - FALSE, FALSE); - otmp->quan = (long) rn1(2, 3); - otmp->owt = weight(otmp); - (void) mpickobj(mtmp, otmp); - } - } - break; - case S_WRAITH: - if (ptr == &mons[PM_NAZGUL]) { - otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE); - curse(otmp); - (void) mpickobj(mtmp, otmp); - } - break; - case S_LICH: - if (ptr == &mons[PM_MASTER_LICH] && !rn2(13)) - (void)mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING)); - else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) { - otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF, - TRUE, rn2(13) ? FALSE : TRUE); - if (otmp->spe < 2) otmp->spe = rnd(3); - if (!rn2(4)) otmp->oerodeproof = 1; - (void) mpickobj(mtmp, otmp); - } - break; - case S_MUMMY: - if (rn2(7)) (void)mongets(mtmp, MUMMY_WRAPPING); - break; - case S_QUANTMECH: - if (!rn2(20)) { - otmp = mksobj(LARGE_BOX, FALSE, FALSE); - otmp->spe = 1; /* flag for special box */ - otmp->owt = weight(otmp); - (void) mpickobj(mtmp, otmp); - } - break; - case S_LEPRECHAUN: - mkmonmoney(mtmp, (long) d(level_difficulty(), 30)); - break; - case S_DEMON: - /* moved here from m_initweap() because these don't - have AT_WEAP so m_initweap() is not called for them */ - if (ptr == &mons[PM_ICE_DEVIL] && !rn2(4)) { - (void)mongets(mtmp, SPEAR); - } else if (ptr == &mons[PM_ASMODEUS]) { - (void)mongets(mtmp, WAN_COLD); - (void)mongets(mtmp, WAN_FIRE); - } - break; - case S_GNOME: - if (!rn2((In_mines(&u.uz) ? 5 : 10))) { - otmp = mksobj(rn2(4) ? TALLOW_CANDLE : WAX_CANDLE, TRUE, FALSE); - otmp->quan = 1; - otmp->owt = weight(otmp); - if (!mpickobj(mtmp, otmp) && !levl[mtmp->mx][mtmp->my].lit) - begin_burn(otmp, FALSE); - } - break; - default: - break; - } + /* ordinary soldiers rarely have access to magic (or gold :-) */ + if (ptr == &mons[PM_SOLDIER] && rn2(13)) + return; - /* ordinary soldiers rarely have access to magic (or gold :-) */ - if (ptr == &mons[PM_SOLDIER] && rn2(13)) return; - - if ((int) mtmp->m_lev > rn2(50)) - (void) mongets(mtmp, rnd_defensive_item(mtmp)); - if ((int) mtmp->m_lev > rn2(100)) - (void) mongets(mtmp, rnd_misc_item(mtmp)); - if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5)) - mkmonmoney(mtmp, (long) d(level_difficulty(), mtmp->minvent ? 5 : 10)); + if ((int) mtmp->m_lev > rn2(50)) + (void) mongets(mtmp, rnd_defensive_item(mtmp)); + if ((int) mtmp->m_lev > rn2(100)) + (void) mongets(mtmp, rnd_misc_item(mtmp)); + if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5)) + mkmonmoney(mtmp, + (long) d(level_difficulty(), mtmp->minvent ? 5 : 10)); } /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */ struct monst * clone_mon(mon, x, y) struct monst *mon; -xchar x, y; /* clone's preferred location or 0 (near mon) */ +xchar x, y; /* clone's preferred location or 0 (near mon) */ { - coord mm; - struct monst *m2; + coord mm; + struct monst *m2; - /* may be too weak or have been extinguished for population control */ - if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT)) - return (struct monst *)0; + /* may be too weak or have been extinguished for population control */ + if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT)) + return (struct monst *) 0; - if (x == 0) { - mm.x = mon->mx; - mm.y = mon->my; - if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y)) - return (struct monst *)0; - } else if (!isok(x, y)) { - return (struct monst *)0; /* paranoia */ - } else { - mm.x = x; - mm.y = y; - if (MON_AT(mm.x, mm.y)) { - if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y)) - return (struct monst *)0; - } - } - m2 = newmonst(); - *m2 = *mon; /* copy condition of old monster */ - m2->mextra = (struct mextra *)0; - m2->nmon = fmon; - fmon = m2; - m2->m_id = context.ident++; - if (!m2->m_id) m2->m_id = context.ident++; /* ident overflowed */ - m2->mx = mm.x; - m2->my = mm.y; + if (x == 0) { + mm.x = mon->mx; + mm.y = mon->my; + if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y)) + return (struct monst *) 0; + } else if (!isok(x, y)) { + return (struct monst *) 0; /* paranoia */ + } else { + mm.x = x; + mm.y = y; + if (MON_AT(mm.x, mm.y)) { + if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y)) + return (struct monst *) 0; + } + } + m2 = newmonst(); + *m2 = *mon; /* copy condition of old monster */ + m2->mextra = (struct mextra *) 0; + m2->nmon = fmon; + fmon = m2; + m2->m_id = context.ident++; + if (!m2->m_id) + m2->m_id = context.ident++; /* ident overflowed */ + m2->mx = mm.x; + m2->my = mm.y; - m2->mcloned = 1; - m2->minvent = (struct obj *) 0; /* objects don't clone */ - m2->mleashed = FALSE; - /* Max HP the same, but current HP halved for both. The caller - * might want to override this by halving the max HP also. - * When current HP is odd, the original keeps the extra point. - */ - m2->mhpmax = mon->mhpmax; - m2->mhp = mon->mhp / 2; - mon->mhp -= m2->mhp; + m2->mcloned = 1; + m2->minvent = (struct obj *) 0; /* objects don't clone */ + m2->mleashed = FALSE; + /* Max HP the same, but current HP halved for both. The caller + * might want to override this by halving the max HP also. + * When current HP is odd, the original keeps the extra point. + */ + m2->mhpmax = mon->mhpmax; + m2->mhp = mon->mhp / 2; + mon->mhp -= m2->mhp; - /* since shopkeepers and guards will only be cloned if they've been - * polymorphed away from their original forms, the clone doesn't have - * room for the extra information. we also don't want two shopkeepers - * around for the same shop. - */ - if (mon->isshk) m2->isshk = FALSE; - if (mon->isgd) m2->isgd = FALSE; - if (mon->ispriest) m2->ispriest = FALSE; - place_monster(m2, m2->mx, m2->my); - if (emits_light(m2->data)) - new_light_source(m2->mx, m2->my, emits_light(m2->data), - LS_MONSTER, monst_to_any(m2)); - if (has_mname(mon)) { - m2 = christen_monst(m2, MNAME(mon)); - } else if (mon->isshk) { - m2 = christen_monst(m2, shkname(mon)); - } + /* since shopkeepers and guards will only be cloned if they've been + * polymorphed away from their original forms, the clone doesn't have + * room for the extra information. we also don't want two shopkeepers + * around for the same shop. + */ + if (mon->isshk) + m2->isshk = FALSE; + if (mon->isgd) + m2->isgd = FALSE; + if (mon->ispriest) + m2->ispriest = FALSE; + place_monster(m2, m2->mx, m2->my); + if (emits_light(m2->data)) + new_light_source(m2->mx, m2->my, emits_light(m2->data), LS_MONSTER, + monst_to_any(m2)); + if (has_mname(mon)) { + m2 = christen_monst(m2, MNAME(mon)); + } else if (mon->isshk) { + m2 = christen_monst(m2, shkname(mon)); + } - /* not all clones caused by player are tame or peaceful */ - if (!context.mon_moving) { - if (mon->mtame) - m2->mtame = rn2(max(2 + u.uluck, 2)) ? mon->mtame : 0; - else if (mon->mpeaceful) - m2->mpeaceful = rn2(max(2 + u.uluck, 2)) ? 1 : 0; - } + /* not all clones caused by player are tame or peaceful */ + if (!context.mon_moving) { + if (mon->mtame) + m2->mtame = rn2(max(2 + u.uluck, 2)) ? mon->mtame : 0; + else if (mon->mpeaceful) + m2->mpeaceful = rn2(max(2 + u.uluck, 2)) ? 1 : 0; + } - newsym(m2->mx,m2->my); /* display the new monster */ - if (m2->mtame) { - if (mon->isminion) { - newemin(m2); - if (EMIN(mon)) *(EMIN(m2)) = *(EMIN(mon)); - } else { - /* because m2 is a copy of mon it is tame but not init'ed. - * however, tamedog will not re-tame a tame dog, so m2 - * must be made non-tame to get initialized properly. - */ - m2->mtame = 0; - if (tamedog(m2, (struct obj *)0)) { - *(EDOG(m2)) = *(EDOG(mon)); - } - } - } - set_malign(m2); + newsym(m2->mx, m2->my); /* display the new monster */ + if (m2->mtame) { + if (mon->isminion) { + newemin(m2); + if (EMIN(mon)) + *(EMIN(m2)) = *(EMIN(mon)); + } else { + /* because m2 is a copy of mon it is tame but not init'ed. + * however, tamedog will not re-tame a tame dog, so m2 + * must be made non-tame to get initialized properly. + */ + m2->mtame = 0; + if (tamedog(m2, (struct obj *) 0)) { + *(EDOG(m2)) = *(EDOG(mon)); + } + } + } + set_malign(m2); - return m2; + return m2; } /* @@ -756,25 +841,29 @@ int mndx; boolean tally; boolean ghostly; { - boolean result; - uchar lim = mbirth_limit(mndx); - boolean gone = (mvitals[mndx].mvflags & G_GONE); /* genocided or extinct */ + boolean result; + uchar lim = mbirth_limit(mndx); + boolean gone = + (mvitals[mndx].mvflags & G_GONE); /* genocided or extinct */ - result = (((int) mvitals[mndx].born < lim) && !gone) ? TRUE : FALSE; + result = (((int) mvitals[mndx].born < lim) && !gone) ? TRUE : FALSE; - /* if it's unique, don't ever make it again */ - if (mons[mndx].geno & G_UNIQ) mvitals[mndx].mvflags |= G_EXTINCT; + /* if it's unique, don't ever make it again */ + if (mons[mndx].geno & G_UNIQ) + mvitals[mndx].mvflags |= G_EXTINCT; - if (mvitals[mndx].born < 255 && tally && (!ghostly || (ghostly && result))) - mvitals[mndx].born++; - if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) && - !(mvitals[mndx].mvflags & G_EXTINCT)) { - if (wizard) debugpline1("Automatically extinguished %s.", - makeplural(mons[mndx].mname)); - mvitals[mndx].mvflags |= G_EXTINCT; - reset_rndmonst(mndx); - } - return result; + if (mvitals[mndx].born < 255 && tally + && (!ghostly || (ghostly && result))) + mvitals[mndx].born++; + if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) + && !(mvitals[mndx].mvflags & G_EXTINCT)) { + if (wizard) + debugpline1("Automatically extinguished %s.", + makeplural(mons[mndx].mname)); + mvitals[mndx].mvflags |= G_EXTINCT; + reset_rndmonst(mndx); + } + return result; } /* amount of HP to lose from level drain (or gain from Stormbringer) */ @@ -783,21 +872,22 @@ monhp_per_lvl(mon) struct monst *mon; { struct permonst *ptr = mon->data; - int hp = rnd(8); /* default is d8 */ + int hp = rnd(8); /* default is d8 */ /* like newmonhp, but home elementals are ignored, riders use normal d8 */ if (is_golem(ptr)) { - /* draining usually won't be applicable for these critters */ - hp = golemhp(monsndx(ptr)) / (int)ptr->mlevel; + /* draining usually won't be applicable for these critters */ + hp = golemhp(monsndx(ptr)) / (int) ptr->mlevel; } else if (ptr->mlevel > 49) { - /* arbitrary; such monsters won't be involved in draining anyway */ - hp = 4 + rnd(4); /* 5..8 */ + /* arbitrary; such monsters won't be involved in draining anyway */ + hp = 4 + rnd(4); /* 5..8 */ } else if (ptr->mlet == S_DRAGON && monsndx(ptr) >= PM_GRAY_DRAGON) { - /* adult dragons; newmonhp() uses In_endgame(&u.uz) ? 8 : 4 + rnd(4) */ - hp = 4 + rn2(5); /* 4..8 */ + /* adult dragons; newmonhp() uses In_endgame(&u.uz) ? 8 : 4 + rnd(4) + */ + hp = 4 + rn2(5); /* 4..8 */ } else if (!mon->m_lev) { - /* level 0 monsters use 1d4 instead of Nd8 */ - hp = rnd(4); + /* level 0 monsters use 1d4 instead of Nd8 */ + hp = rnd(4); } return hp; } @@ -813,44 +903,46 @@ int mndx; mon->m_lev = adj_lev(ptr); if (is_golem(ptr)) { - mon->mhpmax = mon->mhp = golemhp(mndx); + mon->mhpmax = mon->mhp = golemhp(mndx); } else if (is_rider(ptr)) { - /* we want low HP, but a high mlevel so they can attack well */ - mon->mhpmax = mon->mhp = d(10,8); + /* we want low HP, but a high mlevel so they can attack well */ + mon->mhpmax = mon->mhp = d(10, 8); } else if (ptr->mlevel > 49) { - /* "special" fixed hp monster - * the hit points are encoded in the mlevel in a somewhat strange - * way to fit in the 50..127 positive range of a signed character - * above the 1..49 that indicate "normal" monster levels */ - mon->mhpmax = mon->mhp = 2 * (ptr->mlevel - 6); - mon->m_lev = mon->mhp / 4; /* approximation */ + /* "special" fixed hp monster + * the hit points are encoded in the mlevel in a somewhat strange + * way to fit in the 50..127 positive range of a signed character + * above the 1..49 that indicate "normal" monster levels */ + mon->mhpmax = mon->mhp = 2 * (ptr->mlevel - 6); + mon->m_lev = mon->mhp / 4; /* approximation */ } else if (ptr->mlet == S_DRAGON && mndx >= PM_GRAY_DRAGON) { - /* adult dragons */ - mon->mhpmax = mon->mhp = (int) (In_endgame(&u.uz) ? - (8 * mon->m_lev) : (4 * mon->m_lev + d((int)mon->m_lev, 4))); + /* adult dragons */ + mon->mhpmax = mon->mhp = + (int) (In_endgame(&u.uz) + ? (8 * mon->m_lev) + : (4 * mon->m_lev + d((int) mon->m_lev, 4))); } else if (!mon->m_lev) { - mon->mhpmax = mon->mhp = rnd(4); + mon->mhpmax = mon->mhp = rnd(4); } else { - mon->mhpmax = mon->mhp = d((int)mon->m_lev, 8); - if (is_home_elemental(ptr)) - mon->mhpmax = (mon->mhp *= 3); + mon->mhpmax = mon->mhp = d((int) mon->m_lev, 8); + if (is_home_elemental(ptr)) + mon->mhpmax = (mon->mhp *= 3); } } struct mextra * newmextra() { - struct mextra *mextra; + struct mextra *mextra; - mextra = (struct mextra *)alloc(sizeof(struct mextra)); - mextra->mname = 0; - mextra->egd = 0; - mextra->epri = 0; - mextra->eshk = 0; - mextra->emin = 0; - mextra->edog = 0; - mextra->mcorpsenm = NON_PM; - return mextra; + mextra = (struct mextra *) alloc(sizeof(struct mextra)); + mextra->mname = 0; + mextra->egd = 0; + mextra->epri = 0; + mextra->eshk = 0; + mextra->emin = 0; + mextra->edog = 0; + mextra->mcorpsenm = NON_PM; + return mextra; } /* @@ -863,299 +955,314 @@ newmextra() struct monst * makemon(ptr, x, y, mmflags) register struct permonst *ptr; -register int x, y; -register int mmflags; +register int x, y; +register int mmflags; { - register struct monst *mtmp; - int mndx, mcham, ct, mitem; - boolean anymon = (!ptr); - boolean byyou = (x == u.ux && y == u.uy); - boolean allow_minvent = ((mmflags & NO_MINVENT) == 0); - boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0); - unsigned gpflags = (mmflags & MM_IGNOREWATER) ? MM_IGNOREWATER : 0; + register struct monst *mtmp; + int mndx, mcham, ct, mitem; + boolean anymon = (!ptr); + boolean byyou = (x == u.ux && y == u.uy); + boolean allow_minvent = ((mmflags & NO_MINVENT) == 0); + boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0); + unsigned gpflags = (mmflags & MM_IGNOREWATER) ? MM_IGNOREWATER : 0; - /* if caller wants random location, do it here */ - if(x == 0 && y == 0) { - int tryct = 0; /* careful with bigrooms */ - struct monst fakemon; + /* if caller wants random location, do it here */ + if (x == 0 && y == 0) { + int tryct = 0; /* careful with bigrooms */ + struct monst fakemon; - fakemon.data = ptr; /* set up for goodpos */ - do { - x = rn1(COLNO-3,2); - y = rn2(ROWNO); - } while(!goodpos(x, y, ptr ? &fakemon : (struct monst *)0, gpflags) || - (!in_mklev && tryct++ < 50 && cansee(x, y))); - } else if (byyou && !in_mklev) { - coord bypos; + fakemon.data = ptr; /* set up for goodpos */ + do { + x = rn1(COLNO - 3, 2); + y = rn2(ROWNO); + } while (!goodpos(x, y, ptr ? &fakemon : (struct monst *) 0, gpflags) + || (!in_mklev && tryct++ < 50 && cansee(x, y))); + } else if (byyou && !in_mklev) { + coord bypos; - if(enexto_core(&bypos, u.ux, u.uy, ptr, gpflags)) { - x = bypos.x; - y = bypos.y; - } else - return((struct monst *)0); - } + if (enexto_core(&bypos, u.ux, u.uy, ptr, gpflags)) { + x = bypos.x; + y = bypos.y; + } else + return ((struct monst *) 0); + } - /* Does monster already exist at the position? */ - if(MON_AT(x, y)) { - if ((mmflags & MM_ADJACENTOK) != 0) { - coord bypos; - if(enexto_core(&bypos, x, y, ptr, gpflags)) { - x = bypos.x; - y = bypos.y; - } else - return((struct monst *) 0); - } else - return((struct monst *) 0); - } + /* Does monster already exist at the position? */ + if (MON_AT(x, y)) { + if ((mmflags & MM_ADJACENTOK) != 0) { + coord bypos; + if (enexto_core(&bypos, x, y, ptr, gpflags)) { + x = bypos.x; + y = bypos.y; + } else + return ((struct monst *) 0); + } else + return ((struct monst *) 0); + } - if(ptr){ - mndx = monsndx(ptr); - /* if you are to make a specific monster and it has - already been genocided, return */ - if (mvitals[mndx].mvflags & G_GENOD) return((struct monst *) 0); - if (wizard && (mvitals[mndx].mvflags & G_EXTINCT)) - debugpline1("Explicitly creating extinct monster %s.", - mons[mndx].mname); - } else { - /* make a random (common) monster that can survive here. - * (the special levels ask for random monsters at specific - * positions, causing mass drowning on the medusa level, - * for instance.) - */ - int tryct = 0; /* maybe there are no good choices */ - struct monst fakemon; + if (ptr) { + mndx = monsndx(ptr); + /* if you are to make a specific monster and it has + already been genocided, return */ + if (mvitals[mndx].mvflags & G_GENOD) + return ((struct monst *) 0); + if (wizard && (mvitals[mndx].mvflags & G_EXTINCT)) + debugpline1("Explicitly creating extinct monster %s.", + mons[mndx].mname); + } else { + /* make a random (common) monster that can survive here. + * (the special levels ask for random monsters at specific + * positions, causing mass drowning on the medusa level, + * for instance.) + */ + int tryct = 0; /* maybe there are no good choices */ + struct monst fakemon; - do { - if(!(ptr = rndmonst())) { - debugpline0("Warning: no monster."); - return((struct monst *) 0); /* no more monsters! */ - } - fakemon.data = ptr; /* set up for goodpos */ - } while (++tryct <= 50 && - /* in Sokoban, don't accept a giant on first try; - after that, boulder carriers are fair game */ - ((tryct == 1 && throws_rocks(ptr) && In_sokoban(&u.uz)) || - !goodpos(x, y, &fakemon, gpflags))); - mndx = monsndx(ptr); - } - (void) propagate(mndx, countbirth, FALSE); - mtmp = newmonst(); - *mtmp = zeromonst; /* clear all entries in structure */ + do { + if (!(ptr = rndmonst())) { + debugpline0("Warning: no monster."); + return ((struct monst *) 0); /* no more monsters! */ + } + fakemon.data = ptr; /* set up for goodpos */ + } while (++tryct <= 50 && + /* in Sokoban, don't accept a giant on first try; + after that, boulder carriers are fair game */ + ((tryct == 1 && throws_rocks(ptr) && In_sokoban(&u.uz)) + || !goodpos(x, y, &fakemon, gpflags))); + mndx = monsndx(ptr); + } + (void) propagate(mndx, countbirth, FALSE); + mtmp = newmonst(); + *mtmp = zeromonst; /* clear all entries in structure */ - if (mmflags & MM_EGD) newegd(mtmp); - if (mmflags & MM_EPRI) newepri(mtmp); - if (mmflags & MM_ESHK) neweshk(mtmp); - if (mmflags & MM_EMIN) newemin(mtmp); - if (mmflags & MM_EDOG) newedog(mtmp); + if (mmflags & MM_EGD) + newegd(mtmp); + if (mmflags & MM_EPRI) + newepri(mtmp); + if (mmflags & MM_ESHK) + neweshk(mtmp); + if (mmflags & MM_EMIN) + newemin(mtmp); + if (mmflags & MM_EDOG) + newedog(mtmp); - mtmp->nmon = fmon; - fmon = mtmp; - mtmp->m_id = context.ident++; - if (!mtmp->m_id) mtmp->m_id = context.ident++; /* ident overflowed */ - set_mon_data(mtmp, ptr, 0); - if (ptr->msound == MS_LEADER && quest_info(MS_LEADER) == mndx) - quest_status.leader_m_id = mtmp->m_id; - mtmp->mnum = mndx; + mtmp->nmon = fmon; + fmon = mtmp; + mtmp->m_id = context.ident++; + if (!mtmp->m_id) + mtmp->m_id = context.ident++; /* ident overflowed */ + set_mon_data(mtmp, ptr, 0); + if (ptr->msound == MS_LEADER && quest_info(MS_LEADER) == mndx) + quest_status.leader_m_id = mtmp->m_id; + mtmp->mnum = mndx; - /* set up level and hit points */ - newmonhp(mtmp, mndx); + /* set up level and hit points */ + newmonhp(mtmp, mndx); - if (is_female(ptr)) mtmp->female = TRUE; - else if (is_male(ptr)) mtmp->female = FALSE; - /* leader and nemesis gender is usually hardcoded in mons[], - but for ones which can be random, it has already been chosen - (in role_init(), for possible use by the quest pager code) */ - else if (ptr->msound == MS_LEADER && quest_info(MS_LEADER) == mndx) - mtmp->female = quest_status.ldrgend; - else if (ptr->msound == MS_NEMESIS && quest_info(MS_NEMESIS) == mndx) - mtmp->female = quest_status.nemgend; - else mtmp->female = rn2(2); /* ignored for neuters */ + if (is_female(ptr)) + mtmp->female = TRUE; + else if (is_male(ptr)) + mtmp->female = FALSE; + /* leader and nemesis gender is usually hardcoded in mons[], + but for ones which can be random, it has already been chosen + (in role_init(), for possible use by the quest pager code) */ + else if (ptr->msound == MS_LEADER && quest_info(MS_LEADER) == mndx) + mtmp->female = quest_status.ldrgend; + else if (ptr->msound == MS_NEMESIS && quest_info(MS_NEMESIS) == mndx) + mtmp->female = quest_status.nemgend; + else + mtmp->female = rn2(2); /* ignored for neuters */ - if (In_sokoban(&u.uz) && !mindless(ptr)) /* know about traps here */ - mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1)); - /* quest leader and nemesis both know about all trap types */ - if (ptr->msound == MS_LEADER || ptr->msound == MS_NEMESIS) - mtmp->mtrapseen = ~0; + if (In_sokoban(&u.uz) && !mindless(ptr)) /* know about traps here */ + mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1)); + /* quest leader and nemesis both know about all trap types */ + if (ptr->msound == MS_LEADER || ptr->msound == MS_NEMESIS) + mtmp->mtrapseen = ~0; - place_monster(mtmp, x, y); - mtmp->mcansee = mtmp->mcanmove = TRUE; - mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr); + place_monster(mtmp, x, y); + mtmp->mcansee = mtmp->mcanmove = TRUE; + mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr); - switch(ptr->mlet) { - case S_MIMIC: - set_mimic_sym(mtmp); - break; - case S_SPIDER: - case S_SNAKE: - if(in_mklev) - if(x && y) - (void) mkobj_at(0, x, y, TRUE); - (void) hideunder(mtmp); - break; - case S_LIGHT: - case S_ELEMENTAL: - if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) { - mtmp->perminvis = TRUE; - mtmp->minvis = TRUE; - } - break; - case S_EEL: - (void) hideunder(mtmp); - break; - case S_LEPRECHAUN: - mtmp->msleeping = 1; - break; - case S_JABBERWOCK: - case S_NYMPH: - if (rn2(5) && !u.uhave.amulet) mtmp->msleeping = 1; - break; - case S_ORC: - if (Race_if(PM_ELF)) mtmp->mpeaceful = FALSE; - break; - case S_UNICORN: - if (is_unicorn(ptr) && - sgn(u.ualign.type) == sgn(ptr->maligntyp)) - mtmp->mpeaceful = TRUE; - break; - case S_BAT: - if (Inhell && is_bat(ptr)) - mon_adjust_speed(mtmp, 2, (struct obj *)0); - break; - } - if ((ct = emits_light(mtmp->data)) > 0) - new_light_source(mtmp->mx, mtmp->my, ct, - LS_MONSTER, monst_to_any(mtmp)); - mitem = 0; /* extra inventory item for this monster */ + switch (ptr->mlet) { + case S_MIMIC: + set_mimic_sym(mtmp); + break; + case S_SPIDER: + case S_SNAKE: + if (in_mklev) + if (x && y) + (void) mkobj_at(0, x, y, TRUE); + (void) hideunder(mtmp); + break; + case S_LIGHT: + case S_ELEMENTAL: + if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) { + mtmp->perminvis = TRUE; + mtmp->minvis = TRUE; + } + break; + case S_EEL: + (void) hideunder(mtmp); + break; + case S_LEPRECHAUN: + mtmp->msleeping = 1; + break; + case S_JABBERWOCK: + case S_NYMPH: + if (rn2(5) && !u.uhave.amulet) + mtmp->msleeping = 1; + break; + case S_ORC: + if (Race_if(PM_ELF)) + mtmp->mpeaceful = FALSE; + break; + case S_UNICORN: + if (is_unicorn(ptr) && sgn(u.ualign.type) == sgn(ptr->maligntyp)) + mtmp->mpeaceful = TRUE; + break; + case S_BAT: + if (Inhell && is_bat(ptr)) + mon_adjust_speed(mtmp, 2, (struct obj *) 0); + break; + } + if ((ct = emits_light(mtmp->data)) > 0) + new_light_source(mtmp->mx, mtmp->my, ct, LS_MONSTER, + monst_to_any(mtmp)); + mitem = 0; /* extra inventory item for this monster */ - if (mndx == PM_VLAD_THE_IMPALER) - mitem = CANDELABRUM_OF_INVOCATION; - mtmp->cham = NON_PM; /* default is "not a shapechanger" */ - if ((mcham = pm_to_cham(mndx)) != NON_PM) { - /* this is a shapechanger after all */ - if (Protection_from_shape_changers) { - ; /* stuck in its natural form (NON_PM) */ - } else { - /* Note: shapechanger's initial form used to be - chosen with rndmonst(), yielding a monster - which was approriate to the level's difficulty - but ignored the changer's usual type selection - so would be inppropriate for vampshifters. */ - mtmp->cham = mcham; /* remember base form */ - if (mcham != PM_VLAD_THE_IMPALER && - /* select initial shape */ - (mcham = select_newcham_form(mtmp)) != NON_PM) { - /* take on initial shape; if successful, - avoid giving that shape's usual inventory */ - if (newcham(mtmp, &mons[mcham], FALSE, FALSE)) - allow_minvent = FALSE; - } - } - } else if (mndx == PM_WIZARD_OF_YENDOR) { - mtmp->iswiz = TRUE; - context.no_of_wizards++; - if (context.no_of_wizards == 1 && Is_earthlevel(&u.uz)) - mitem = SPE_DIG; - } else if (mndx == PM_GHOST && !(mmflags & MM_NONAME)) { - mtmp = christen_monst(mtmp, rndghostname()); - } else if (mndx == PM_CROESUS) { - mitem = TWO_HANDED_SWORD; - } else if (ptr->msound == MS_NEMESIS) { - mitem = BELL_OF_OPENING; - } else if (mndx == PM_PESTILENCE) { - mitem = POT_SICKNESS; - } - if (mitem && allow_minvent) (void) mongets(mtmp, mitem); + if (mndx == PM_VLAD_THE_IMPALER) + mitem = CANDELABRUM_OF_INVOCATION; + mtmp->cham = NON_PM; /* default is "not a shapechanger" */ + if ((mcham = pm_to_cham(mndx)) != NON_PM) { + /* this is a shapechanger after all */ + if (Protection_from_shape_changers) { + ; /* stuck in its natural form (NON_PM) */ + } else { + /* Note: shapechanger's initial form used to be + chosen with rndmonst(), yielding a monster + which was approriate to the level's difficulty + but ignored the changer's usual type selection + so would be inppropriate for vampshifters. */ + mtmp->cham = mcham; /* remember base form */ + if (mcham != PM_VLAD_THE_IMPALER && + /* select initial shape */ + (mcham = select_newcham_form(mtmp)) != NON_PM) { + /* take on initial shape; if successful, + avoid giving that shape's usual inventory */ + if (newcham(mtmp, &mons[mcham], FALSE, FALSE)) + allow_minvent = FALSE; + } + } + } else if (mndx == PM_WIZARD_OF_YENDOR) { + mtmp->iswiz = TRUE; + context.no_of_wizards++; + if (context.no_of_wizards == 1 && Is_earthlevel(&u.uz)) + mitem = SPE_DIG; + } else if (mndx == PM_GHOST && !(mmflags & MM_NONAME)) { + mtmp = christen_monst(mtmp, rndghostname()); + } else if (mndx == PM_CROESUS) { + mitem = TWO_HANDED_SWORD; + } else if (ptr->msound == MS_NEMESIS) { + mitem = BELL_OF_OPENING; + } else if (mndx == PM_PESTILENCE) { + mitem = POT_SICKNESS; + } + if (mitem && allow_minvent) + (void) mongets(mtmp, mitem); - if(in_mklev) { - if(((is_ndemon(ptr)) || - (mndx == PM_WUMPUS) || - (mndx == PM_LONG_WORM) || - (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5)) - mtmp->msleeping = TRUE; - } else { - if(byyou) { - newsym(mtmp->mx,mtmp->my); - set_apparxy(mtmp); - } - } - if(is_dprince(ptr) && ptr->msound == MS_BRIBE) { - mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1; - mtmp->mavenge = 0; - if (uwep && uwep->oartifact == ART_EXCALIBUR) - mtmp->mpeaceful = mtmp->mtame = FALSE; - } + if (in_mklev) { + if (((is_ndemon(ptr)) || (mndx == PM_WUMPUS) || (mndx == PM_LONG_WORM) + || (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5)) + mtmp->msleeping = TRUE; + } else { + if (byyou) { + newsym(mtmp->mx, mtmp->my); + set_apparxy(mtmp); + } + } + if (is_dprince(ptr) && ptr->msound == MS_BRIBE) { + mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1; + mtmp->mavenge = 0; + if (uwep && uwep->oartifact == ART_EXCALIBUR) + mtmp->mpeaceful = mtmp->mtame = FALSE; + } #ifndef DCC30_BUG - if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno()) != 0) + if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno()) != 0) #else - /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the - * same expression. - */ - if (mndx == PM_LONG_WORM && - (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) + /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the + * same expression. + */ + if (mndx == PM_LONG_WORM + && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) #endif - { - /* we can now create worms with tails - 11/91 */ - initworm(mtmp, rn2(5)); - if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y); - } - /* it's possible to create an ordinary monster of some special - types; make sure their extended data is initialized to - something sensible if caller hasn't specified MM_EPRI|MM_EMIN - (when they're specified, caller intends to handle this itself) */ - if ((mndx == PM_ALIGNED_PRIEST || mndx == PM_HIGH_PRIEST) ? - !(mmflags & (MM_EPRI|MM_EMIN)) : - (mndx == PM_ANGEL && !(mmflags & MM_EMIN) && !rn2(3))) { - struct emin *eminp; - newemin(mtmp); - eminp = EMIN(mtmp); + { + /* we can now create worms with tails - 11/91 */ + initworm(mtmp, rn2(5)); + if (count_wsegs(mtmp)) + place_worm_tail_randomly(mtmp, x, y); + } + /* it's possible to create an ordinary monster of some special + types; make sure their extended data is initialized to + something sensible if caller hasn't specified MM_EPRI|MM_EMIN + (when they're specified, caller intends to handle this itself) */ + if ((mndx == PM_ALIGNED_PRIEST || mndx == PM_HIGH_PRIEST) + ? !(mmflags & (MM_EPRI | MM_EMIN)) + : (mndx == PM_ANGEL && !(mmflags & MM_EMIN) && !rn2(3))) { + struct emin *eminp; + newemin(mtmp); + eminp = EMIN(mtmp); - mtmp->isminion = 1; /* make priest be a roamer */ - eminp->min_align = rn2(3) - 1; /* no A_NONE */ - eminp->renegade = (boolean)((mmflags & MM_ANGRY) ? 1 : !rn2(3)); - mtmp->mpeaceful = (eminp->min_align == u.ualign.type) ? - !eminp->renegade : eminp->renegade; - } - set_malign(mtmp); /* having finished peaceful changes */ - if(anymon) { - if ((ptr->geno & G_SGROUP) && rn2(2)) { - m_initsgrp(mtmp, mtmp->mx, mtmp->my); - } else if (ptr->geno & G_LGROUP) { - if(rn2(3)) m_initlgrp(mtmp, mtmp->mx, mtmp->my); - else m_initsgrp(mtmp, mtmp->mx, mtmp->my); - } - } + mtmp->isminion = 1; /* make priest be a roamer */ + eminp->min_align = rn2(3) - 1; /* no A_NONE */ + eminp->renegade = (boolean)((mmflags & MM_ANGRY) ? 1 : !rn2(3)); + mtmp->mpeaceful = (eminp->min_align == u.ualign.type) + ? !eminp->renegade + : eminp->renegade; + } + set_malign(mtmp); /* having finished peaceful changes */ + if (anymon) { + if ((ptr->geno & G_SGROUP) && rn2(2)) { + m_initsgrp(mtmp, mtmp->mx, mtmp->my); + } else if (ptr->geno & G_LGROUP) { + if (rn2(3)) + m_initlgrp(mtmp, mtmp->mx, mtmp->my); + else + m_initsgrp(mtmp, mtmp->mx, mtmp->my); + } + } - if (allow_minvent) { - if(is_armed(ptr)) - m_initweap(mtmp); /* equip with weapons / armor */ - m_initinv(mtmp); /* add on a few special items incl. more armor */ - m_dowear(mtmp, TRUE); - } else { - /* no initial inventory is allowed */ - if (mtmp->minvent) discard_minvent(mtmp); - mtmp->minvent = (struct obj *)0; /* caller expects this */ - } - if (ptr->mflags3 && !(mmflags & MM_NOWAIT)) { - if (ptr->mflags3 & M3_WAITFORU) - mtmp->mstrategy |= STRAT_WAITFORU; - if (ptr->mflags3 & M3_CLOSE) - mtmp->mstrategy |= STRAT_CLOSE; - if (ptr->mflags3 & (M3_WAITMASK|M3_COVETOUS)) - mtmp->mstrategy |= STRAT_APPEARMSG; - } + if (allow_minvent) { + if (is_armed(ptr)) + m_initweap(mtmp); /* equip with weapons / armor */ + m_initinv(mtmp); /* add on a few special items incl. more armor */ + m_dowear(mtmp, TRUE); + } else { + /* no initial inventory is allowed */ + if (mtmp->minvent) + discard_minvent(mtmp); + mtmp->minvent = (struct obj *) 0; /* caller expects this */ + } + if (ptr->mflags3 && !(mmflags & MM_NOWAIT)) { + if (ptr->mflags3 & M3_WAITFORU) + mtmp->mstrategy |= STRAT_WAITFORU; + if (ptr->mflags3 & M3_CLOSE) + mtmp->mstrategy |= STRAT_CLOSE; + if (ptr->mflags3 & (M3_WAITMASK | M3_COVETOUS)) + mtmp->mstrategy |= STRAT_APPEARMSG; + } - if (!in_mklev) - newsym(mtmp->mx,mtmp->my); /* make sure the mon shows up */ + if (!in_mklev) + newsym(mtmp->mx, mtmp->my); /* make sure the mon shows up */ - return(mtmp); + return (mtmp); } int mbirth_limit(mndx) int mndx; { - /* assert(MAXMONNO < 255); */ - return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO); + /* assert(MAXMONNO < 255); */ + return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO); } /* used for wand/scroll/spell of create monster */ @@ -1163,45 +1270,48 @@ int mndx; boolean create_critters(cnt, mptr, neverask) int cnt; -struct permonst *mptr; /* usually null; used for confused reading */ +struct permonst *mptr; /* usually null; used for confused reading */ boolean neverask; { - coord c; - int x, y; - struct monst *mon; - boolean known = FALSE; - boolean ask = (wizard && !neverask); + coord c; + int x, y; + struct monst *mon; + boolean known = FALSE; + boolean ask = (wizard && !neverask); - while (cnt--) { - if (ask) { - if (create_particular()) { - known = TRUE; - continue; - } - else ask = FALSE; /* ESC will shut off prompting */ - } - x = u.ux, y = u.uy; - /* if in water, try to encourage an aquatic monster - by finding and then specifying another wet location */ - if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL])) - x = c.x, y = c.y; + while (cnt--) { + if (ask) { + if (create_particular()) { + known = TRUE; + continue; + } else + ask = FALSE; /* ESC will shut off prompting */ + } + x = u.ux, y = u.uy; + /* if in water, try to encourage an aquatic monster + by finding and then specifying another wet location */ + if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL])) + x = c.x, y = c.y; - mon = makemon(mptr, x, y, NO_MM_FLAGS); - if (mon && canspotmon(mon)) known = TRUE; - } - return known; + mon = makemon(mptr, x, y, NO_MM_FLAGS); + if (mon && canspotmon(mon)) + known = TRUE; + } + return known; } STATIC_OVL boolean uncommon(mndx) int mndx; { - if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) return TRUE; - if (mvitals[mndx].mvflags & G_GONE) return TRUE; - if (Inhell) - return(mons[mndx].maligntyp > A_NEUTRAL); - else - return((mons[mndx].geno & G_HELL) != 0); + if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) + return TRUE; + if (mvitals[mndx].mvflags & G_GONE) + return TRUE; + if (Inhell) + return (mons[mndx].maligntyp > A_NEUTRAL); + else + return ((mons[mndx].geno & G_HELL) != 0); } /* @@ -1213,126 +1323,136 @@ STATIC_OVL int align_shift(ptr) register struct permonst *ptr; { - static NEARDATA long oldmoves = 0L; /* != 1, starting value of moves */ + static NEARDATA long oldmoves = 0L; /* != 1, starting value of moves */ static NEARDATA s_level *lev; register int alshift; - if(oldmoves != moves) { - lev = Is_special(&u.uz); - oldmoves = moves; + if (oldmoves != moves) { + lev = Is_special(&u.uz); + oldmoves = moves; } - switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) { - default: /* just in case */ - case AM_NONE: alshift = 0; - break; - case AM_LAWFUL: alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT); - break; - case AM_NEUTRAL: alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT; - break; - case AM_CHAOTIC: alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT); - break; + switch ((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) { + default: /* just in case */ + case AM_NONE: + alshift = 0; + break; + case AM_LAWFUL: + alshift = (ptr->maligntyp + 20) / (2 * ALIGNWEIGHT); + break; + case AM_NEUTRAL: + alshift = (20 - abs(ptr->maligntyp)) / ALIGNWEIGHT; + break; + case AM_CHAOTIC: + alshift = (-(ptr->maligntyp - 20)) / (2 * ALIGNWEIGHT); + break; } return alshift; } static NEARDATA struct { - int choice_count; - char mchoices[SPECIAL_PM]; /* value range is 0..127 */ -} rndmonst_state = { -1, {0} }; + int choice_count; + char mchoices[SPECIAL_PM]; /* value range is 0..127 */ +} rndmonst_state = { -1, { 0 } }; /* select a random monster type */ struct permonst * rndmonst() { - register struct permonst *ptr; - register int mndx, ct; + register struct permonst *ptr; + register int mndx, ct; - if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0) - return ptr; + if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0) + return ptr; - if (rndmonst_state.choice_count < 0) { /* need to recalculate */ - int zlevel, minmlev, maxmlev; - boolean elemlevel; - boolean upper; + if (rndmonst_state.choice_count < 0) { /* need to recalculate */ + int zlevel, minmlev, maxmlev; + boolean elemlevel; + boolean upper; - rndmonst_state.choice_count = 0; - /* look for first common monster */ - for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) { - if (!uncommon(mndx)) break; - rndmonst_state.mchoices[mndx] = 0; - } - if (mndx == SPECIAL_PM) { - /* evidently they've all been exterminated */ - debugpline0("rndmonst: no common mons!"); - return (struct permonst *)0; - } /* else `mndx' now ready for use below */ - zlevel = level_difficulty(); - /* determine the level of the weakest monster to make. */ - minmlev = zlevel / 6; - /* determine the level of the strongest monster to make. */ - maxmlev = (zlevel + u.ulevel) / 2; - upper = Is_rogue_level(&u.uz); - elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz); + rndmonst_state.choice_count = 0; + /* look for first common monster */ + for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) { + if (!uncommon(mndx)) + break; + rndmonst_state.mchoices[mndx] = 0; + } + if (mndx == SPECIAL_PM) { + /* evidently they've all been exterminated */ + debugpline0("rndmonst: no common mons!"); + return (struct permonst *) 0; + } /* else `mndx' now ready for use below */ + zlevel = level_difficulty(); + /* determine the level of the weakest monster to make. */ + minmlev = zlevel / 6; + /* determine the level of the strongest monster to make. */ + maxmlev = (zlevel + u.ulevel) / 2; + upper = Is_rogue_level(&u.uz); + elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz); -/* - * Find out how many monsters exist in the range we have selected. - */ - /* (`mndx' initialized above) */ - for ( ; mndx < SPECIAL_PM; mndx++) { - ptr = &mons[mndx]; - rndmonst_state.mchoices[mndx] = 0; - if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev)) - continue; - if (upper && !isupper(def_monsyms[(int)(ptr->mlet)].sym)) continue; - if (elemlevel && wrong_elem_type(ptr)) continue; - if (uncommon(mndx)) continue; - if (Inhell && (ptr->geno & G_NOHELL)) continue; - ct = (int)(ptr->geno & G_FREQ) + align_shift(ptr); - if (ct < 0 || ct > 127) - panic("rndmonst: bad count [#%d: %d]", mndx, ct); - rndmonst_state.choice_count += ct; - rndmonst_state.mchoices[mndx] = (char)ct; - } -/* - * Possible modification: if choice_count is "too low", - * expand minmlev..maxmlev range and try again. - */ - } /* choice_count+mchoices[] recalc */ + /* + * Find out how many monsters exist in the range we have + *selected. + */ + /* (`mndx' initialized above) */ + for (; mndx < SPECIAL_PM; mndx++) { + ptr = &mons[mndx]; + rndmonst_state.mchoices[mndx] = 0; + if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev)) + continue; + if (upper && !isupper(def_monsyms[(int) (ptr->mlet)].sym)) + continue; + if (elemlevel && wrong_elem_type(ptr)) + continue; + if (uncommon(mndx)) + continue; + if (Inhell && (ptr->geno & G_NOHELL)) + continue; + ct = (int) (ptr->geno & G_FREQ) + align_shift(ptr); + if (ct < 0 || ct > 127) + panic("rndmonst: bad count [#%d: %d]", mndx, ct); + rndmonst_state.choice_count += ct; + rndmonst_state.mchoices[mndx] = (char) ct; + } + /* + * Possible modification: if choice_count is "too low", + * expand minmlev..maxmlev range and try again. + */ + } /* choice_count+mchoices[] recalc */ - if (rndmonst_state.choice_count <= 0) { - /* maybe no common mons left, or all are too weak or too strong */ - debugpline1("rndmonst: choice_count=%d", - rndmonst_state.choice_count); - return (struct permonst *)0; - } + if (rndmonst_state.choice_count <= 0) { + /* maybe no common mons left, or all are too weak or too strong */ + debugpline1("rndmonst: choice_count=%d", rndmonst_state.choice_count); + return (struct permonst *) 0; + } -/* - * Now, select a monster at random. - */ - ct = rnd(rndmonst_state.choice_count); - for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) - if ((ct -= (int)rndmonst_state.mchoices[mndx]) <= 0) break; + /* + * Now, select a monster at random. + */ + ct = rnd(rndmonst_state.choice_count); + for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) + if ((ct -= (int) rndmonst_state.mchoices[mndx]) <= 0) + break; - if (mndx == SPECIAL_PM || uncommon(mndx)) { /* shouldn't happen */ - impossible("rndmonst: bad `mndx' [#%d]", mndx); - return (struct permonst *)0; - } - return &mons[mndx]; + if (mndx == SPECIAL_PM || uncommon(mndx)) { /* shouldn't happen */ + impossible("rndmonst: bad `mndx' [#%d]", mndx); + return (struct permonst *) 0; + } + return &mons[mndx]; } /* called when you change level (experience or dungeon depth) or when monster species can no longer be created (genocide or extinction) */ void reset_rndmonst(mndx) -int mndx; /* particular species that can no longer be created */ +int mndx; /* particular species that can no longer be created */ { - /* cached selection info is out of date */ - if (mndx == NON_PM) { - rndmonst_state.choice_count = -1; /* full recalc needed */ - } else if (mndx < SPECIAL_PM) { - rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx]; - rndmonst_state.mchoices[mndx] = 0; - } /* note: safe to ignore extinction of unique monsters */ + /* cached selection info is out of date */ + if (mndx == NON_PM) { + rndmonst_state.choice_count = -1; /* full recalc needed */ + } else if (mndx < SPECIAL_PM) { + rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx]; + rndmonst_state.mchoices[mndx] = 0; + } /* note: safe to ignore extinction of unique monsters */ } /* decide whether it's ok to generate a candidate monster by mkclass() */ @@ -1340,16 +1460,20 @@ STATIC_OVL boolean mk_gen_ok(mndx, mvflagsmask, genomask) int mndx, mvflagsmask, genomask; { - struct permonst *ptr = &mons[mndx]; + struct permonst *ptr = &mons[mndx]; - if (mvitals[mndx].mvflags & mvflagsmask) return FALSE; - if (ptr->geno & genomask) return FALSE; - if (is_placeholder(ptr)) return FALSE; + if (mvitals[mndx].mvflags & mvflagsmask) + return FALSE; + if (ptr->geno & genomask) + return FALSE; + if (is_placeholder(ptr)) + return FALSE; #ifdef MAIL - /* special levels might ask for random demon type; reject this one */ - if (ptr == &mons[PM_MAIL_DAEMON]) return FALSE; + /* special levels might ask for random demon type; reject this one */ + if (ptr == &mons[PM_MAIL_DAEMON]) + return FALSE; #endif - return TRUE; + return TRUE; } /* The routine below is used to make one of the multiple types @@ -1360,201 +1484,216 @@ int mndx, mvflagsmask, genomask; */ struct permonst * -mkclass(class,spc) -char class; -int spc; +mkclass(class, spc) +char class; +int spc; { - register int first, last, num = 0; - int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc; + register int first, last, num = 0; + int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc; - maxmlev = level_difficulty() >> 1; - if(class < 1 || class >= MAXMCLASSES) { - impossible("mkclass called with bad class!"); - return((struct permonst *) 0); - } -/* Assumption #1: monsters of a given class are contiguous in the - * mons[] array. - */ - for (first = LOW_PM; first < SPECIAL_PM; first++) - if (mons[first].mlet == class) break; - if (first == SPECIAL_PM) return (struct permonst *) 0; + maxmlev = level_difficulty() >> 1; + if (class < 1 || class >= MAXMCLASSES) { + impossible("mkclass called with bad class!"); + return ((struct permonst *) 0); + } + /* Assumption #1: monsters of a given class are contiguous in the + * mons[] array. + */ + for (first = LOW_PM; first < SPECIAL_PM; first++) + if (mons[first].mlet == class) + break; + if (first == SPECIAL_PM) + return (struct permonst *) 0; - for (last = first; - last < SPECIAL_PM && mons[last].mlet == class; last++) - if (mk_gen_ok(last, G_GONE, mask)) { - /* consider it */ - if(num && toostrong(last, maxmlev) && - monstr[last] != monstr[last-1] && rn2(2)) break; - num += mons[last].geno & G_FREQ; - } + for (last = first; last < SPECIAL_PM && mons[last].mlet == class; last++) + if (mk_gen_ok(last, G_GONE, mask)) { + /* consider it */ + if (num && toostrong(last, maxmlev) + && monstr[last] != monstr[last - 1] && rn2(2)) + break; + num += mons[last].geno & G_FREQ; + } - if(!num) return((struct permonst *) 0); + if (!num) + return ((struct permonst *) 0); -/* Assumption #2: monsters of a given class are presented in ascending - * order of strength. - */ - for(num = rnd(num); num > 0; first++) - if (mk_gen_ok(first, G_GONE, mask)) { - /* skew towards lower value monsters at lower exp. levels */ - num -= mons[first].geno & G_FREQ; - if (num && adj_lev(&mons[first]) > (u.ulevel*2)) { - /* but not when multiple monsters are same level */ - if (mons[first].mlevel != mons[first+1].mlevel) - num--; - } - } - first--; /* correct an off-by-one error */ + /* Assumption #2: monsters of a given class are presented in ascending + * order of strength. + */ + for (num = rnd(num); num > 0; first++) + if (mk_gen_ok(first, G_GONE, mask)) { + /* skew towards lower value monsters at lower exp. levels */ + num -= mons[first].geno & G_FREQ; + if (num && adj_lev(&mons[first]) > (u.ulevel * 2)) { + /* but not when multiple monsters are same level */ + if (mons[first].mlevel != mons[first + 1].mlevel) + num--; + } + } + first--; /* correct an off-by-one error */ - return(&mons[first]); + return (&mons[first]); } /* like mkclass(), but excludes difficulty considerations; used when player with polycontrol picks a class instead of a specific type; genocided types are avoided but extinct ones are acceptable; we don't check polyok() here--caller accepts some choices !polyok() would reject */ -int -mkclass_poly(class) +int mkclass_poly(class) int class; { - register int first, last, num = 0; + register int first, last, num = 0; - for (first = LOW_PM; first < SPECIAL_PM; first++) - if (mons[first].mlet == class) break; - if (first == SPECIAL_PM) return NON_PM; + for (first = LOW_PM; first < SPECIAL_PM; first++) + if (mons[first].mlet == class) + break; + if (first == SPECIAL_PM) + return NON_PM; - for (last = first; - last < SPECIAL_PM && mons[last].mlet == class; last++) - if (mk_gen_ok(last, G_GENOD, (G_NOGEN|G_UNIQ))) - num += mons[last].geno & G_FREQ; - if (!num) return NON_PM; + for (last = first; last < SPECIAL_PM && mons[last].mlet == class; last++) + if (mk_gen_ok(last, G_GENOD, (G_NOGEN | G_UNIQ))) + num += mons[last].geno & G_FREQ; + if (!num) + return NON_PM; - for (num = rnd(num); num > 0; first++) - if (mk_gen_ok(first, G_GENOD, (G_NOGEN|G_UNIQ))) - num -= mons[first].geno & G_FREQ; - first--; /* correct an off-by-one error */ + for (num = rnd(num); num > 0; first++) + if (mk_gen_ok(first, G_GENOD, (G_NOGEN | G_UNIQ))) + num -= mons[first].geno & G_FREQ; + first--; /* correct an off-by-one error */ - return first; + return first; } -int -adj_lev(ptr) /* adjust strength of monsters based on u.uz and u.ulevel */ +int adj_lev(ptr) /* adjust strength of monsters based on u.uz and u.ulevel */ register struct permonst *ptr; { - int tmp, tmp2; + int tmp, tmp2; - if (ptr == &mons[PM_WIZARD_OF_YENDOR]) { - /* does not depend on other strengths, but does get stronger - * every time he is killed - */ - tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died; - if (tmp > 49) tmp = 49; - return tmp; - } + if (ptr == &mons[PM_WIZARD_OF_YENDOR]) { + /* does not depend on other strengths, but does get stronger + * every time he is killed + */ + tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died; + if (tmp > 49) + tmp = 49; + return tmp; + } - if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */ - tmp2 = (level_difficulty() - tmp); - if(tmp2 < 0) tmp--; /* if mlevel > u.uz decrement tmp */ - else tmp += (tmp2 / 5); /* else increment 1 per five diff */ + if ((tmp = ptr->mlevel) > 49) + return (50); /* "special" demons/devils */ + tmp2 = (level_difficulty() - tmp); + if (tmp2 < 0) + tmp--; /* if mlevel > u.uz decrement tmp */ + else + tmp += (tmp2 / 5); /* else increment 1 per five diff */ - tmp2 = (u.ulevel - ptr->mlevel); /* adjust vs. the player */ - if(tmp2 > 0) tmp += (tmp2 / 4); /* level as well */ + tmp2 = (u.ulevel - ptr->mlevel); /* adjust vs. the player */ + if (tmp2 > 0) + tmp += (tmp2 / 4); /* level as well */ - tmp2 = (3 * ((int) ptr->mlevel))/ 2; /* crude upper limit */ - if (tmp2 > 49) tmp2 = 49; /* hard upper limit */ - return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */ + tmp2 = (3 * ((int) ptr->mlevel)) / 2; /* crude upper limit */ + if (tmp2 > 49) + tmp2 = 49; /* hard upper limit */ + return ((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */ } struct permonst * -grow_up(mtmp, victim) /* `mtmp' might "grow up" into a bigger version */ +grow_up(mtmp, victim) /* `mtmp' might "grow up" into a bigger version */ struct monst *mtmp, *victim; { - int oldtype, newtype, max_increase, cur_increase, - lev_limit, hp_threshold; - struct permonst *ptr = mtmp->data; + int oldtype, newtype, max_increase, cur_increase, lev_limit, hp_threshold; + struct permonst *ptr = mtmp->data; - /* monster died after killing enemy but before calling this function */ - /* currently possible if killing a gas spore */ - if (mtmp->mhp <= 0) - return ((struct permonst *)0); + /* monster died after killing enemy but before calling this function */ + /* currently possible if killing a gas spore */ + if (mtmp->mhp <= 0) + return ((struct permonst *) 0); - /* note: none of the monsters with special hit point calculations - have both little and big forms */ - oldtype = monsndx(ptr); - newtype = little_to_big(oldtype); - if (newtype == PM_PRIEST && mtmp->female) newtype = PM_PRIESTESS; + /* note: none of the monsters with special hit point calculations + have both little and big forms */ + oldtype = monsndx(ptr); + newtype = little_to_big(oldtype); + if (newtype == PM_PRIEST && mtmp->female) + newtype = PM_PRIESTESS; - /* growth limits differ depending on method of advancement */ - if (victim) { /* killed a monster */ - /* - * The HP threshold is the maximum number of hit points for the - * current level; once exceeded, a level will be gained. - * Possible bug: if somehow the hit points are already higher - * than that, monster will gain a level without any increase in HP. - */ - hp_threshold = mtmp->m_lev * 8; /* normal limit */ - if (!mtmp->m_lev) - hp_threshold = 4; - else if (is_golem(ptr)) /* strange creatures */ - hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1; - else if (is_home_elemental(ptr)) - hp_threshold *= 3; - lev_limit = 3 * (int)ptr->mlevel / 2; /* same as adj_lev() */ - /* If they can grow up, be sure the level is high enough for that */ - if (oldtype != newtype && mons[newtype].mlevel > lev_limit) - lev_limit = (int)mons[newtype].mlevel; - /* number of hit points to gain; unlike for the player, we put - the limit at the bottom of the next level rather than the top */ - max_increase = rnd((int)victim->m_lev + 1); - if (mtmp->mhpmax + max_increase > hp_threshold + 1) - max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0); - cur_increase = (max_increase > 1) ? rn2(max_increase) : 0; - } else { - /* a gain level potion or wraith corpse; always go up a level - unless already at maximum (49 is hard upper limit except - for demon lords, who start at 50 and can't go any higher) */ - max_increase = cur_increase = rnd(8); - hp_threshold = 0; /* smaller than `mhpmax + max_increase' */ - lev_limit = 50; /* recalc below */ - } + /* growth limits differ depending on method of advancement */ + if (victim) { /* killed a monster */ + /* + * The HP threshold is the maximum number of hit points for the + * current level; once exceeded, a level will be gained. + * Possible bug: if somehow the hit points are already higher + * than that, monster will gain a level without any increase in HP. + */ + hp_threshold = mtmp->m_lev * 8; /* normal limit */ + if (!mtmp->m_lev) + hp_threshold = 4; + else if (is_golem(ptr)) /* strange creatures */ + hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1; + else if (is_home_elemental(ptr)) + hp_threshold *= 3; + lev_limit = 3 * (int) ptr->mlevel / 2; /* same as adj_lev() */ + /* If they can grow up, be sure the level is high enough for that */ + if (oldtype != newtype && mons[newtype].mlevel > lev_limit) + lev_limit = (int) mons[newtype].mlevel; + /* number of hit points to gain; unlike for the player, we put + the limit at the bottom of the next level rather than the top */ + max_increase = rnd((int) victim->m_lev + 1); + if (mtmp->mhpmax + max_increase > hp_threshold + 1) + max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0); + cur_increase = (max_increase > 1) ? rn2(max_increase) : 0; + } else { + /* a gain level potion or wraith corpse; always go up a level + unless already at maximum (49 is hard upper limit except + for demon lords, who start at 50 and can't go any higher) */ + max_increase = cur_increase = rnd(8); + hp_threshold = 0; /* smaller than `mhpmax + max_increase' */ + lev_limit = 50; /* recalc below */ + } - mtmp->mhpmax += max_increase; - mtmp->mhp += cur_increase; - if (mtmp->mhpmax <= hp_threshold) - return ptr; /* doesn't gain a level */ + mtmp->mhpmax += max_increase; + mtmp->mhp += cur_increase; + if (mtmp->mhpmax <= hp_threshold) + return ptr; /* doesn't gain a level */ - if (is_mplayer(ptr)) lev_limit = 30; /* same as player */ - else if (lev_limit < 5) lev_limit = 5; /* arbitrary */ - else if (lev_limit > 49) lev_limit = (ptr->mlevel > 49 ? 50 : 49); + if (is_mplayer(ptr)) + lev_limit = 30; /* same as player */ + else if (lev_limit < 5) + lev_limit = 5; /* arbitrary */ + else if (lev_limit > 49) + lev_limit = (ptr->mlevel > 49 ? 50 : 49); - if ((int)++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) { - ptr = &mons[newtype]; - if (mvitals[newtype].mvflags & G_GENOD) { /* allow G_EXTINCT */ - if (canspotmon(mtmp)) - pline("As %s grows up into %s, %s %s!", mon_nam(mtmp), - an(ptr->mname), mhe(mtmp), - nonliving(ptr) ? "expires" : "dies"); - set_mon_data(mtmp, ptr, -1); /* keep mvitals[] accurate */ - mondied(mtmp); - return (struct permonst *)0; - } else if (canspotmon(mtmp)) { - pline("%s %s %s.", Monnam(mtmp), - humanoid(ptr) ? "becomes" : "grows up into", - an(ptr->mname)); - } - set_mon_data(mtmp, ptr, 1); /* preserve intrinsics */ - newsym(mtmp->mx, mtmp->my); /* color may change */ - lev_limit = (int)mtmp->m_lev; /* never undo increment */ - } - /* sanity checks */ - if ((int)mtmp->m_lev > lev_limit) { - mtmp->m_lev--; /* undo increment */ - /* HP might have been allowed to grow when it shouldn't */ - if (mtmp->mhpmax == hp_threshold + 1) mtmp->mhpmax--; - } - if (mtmp->mhpmax > 50*8) mtmp->mhpmax = 50*8; /* absolute limit */ - if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; + if ((int) ++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) { + ptr = &mons[newtype]; + if (mvitals[newtype].mvflags & G_GENOD) { /* allow G_EXTINCT */ + if (canspotmon(mtmp)) + pline("As %s grows up into %s, %s %s!", mon_nam(mtmp), + an(ptr->mname), mhe(mtmp), + nonliving(ptr) ? "expires" : "dies"); + set_mon_data(mtmp, ptr, -1); /* keep mvitals[] accurate */ + mondied(mtmp); + return (struct permonst *) 0; + } else if (canspotmon(mtmp)) { + pline("%s %s %s.", Monnam(mtmp), + humanoid(ptr) ? "becomes" : "grows up into", + an(ptr->mname)); + } + set_mon_data(mtmp, ptr, 1); /* preserve intrinsics */ + newsym(mtmp->mx, mtmp->my); /* color may change */ + lev_limit = (int) mtmp->m_lev; /* never undo increment */ + } + /* sanity checks */ + if ((int) mtmp->m_lev > lev_limit) { + mtmp->m_lev--; /* undo increment */ + /* HP might have been allowed to grow when it shouldn't */ + if (mtmp->mhpmax == hp_threshold + 1) + mtmp->mhpmax--; + } + if (mtmp->mhpmax > 50 * 8) + mtmp->mhpmax = 50 * 8; /* absolute limit */ + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; - return ptr; + return ptr; } int @@ -1562,68 +1701,84 @@ mongets(mtmp, otyp) register struct monst *mtmp; register int otyp; { - register struct obj *otmp; - int spe; + register struct obj *otmp; + int spe; - if (!otyp) return 0; - otmp = mksobj(otyp, TRUE, FALSE); - if (otmp) { - if (mtmp->data->mlet == S_DEMON) { - /* demons never get blessed objects */ - if (otmp->blessed) curse(otmp); - } else if(is_lminion(mtmp)) { - /* lawful minions don't get cursed, bad, or rusting objects */ - otmp->cursed = FALSE; - if(otmp->spe < 0) otmp->spe = 0; - otmp->oerodeproof = TRUE; - } else if(is_mplayer(mtmp->data) && is_sword(otmp)) { - otmp->spe = (3 + rn2(4)); - } + if (!otyp) + return 0; + otmp = mksobj(otyp, TRUE, FALSE); + if (otmp) { + if (mtmp->data->mlet == S_DEMON) { + /* demons never get blessed objects */ + if (otmp->blessed) + curse(otmp); + } else if (is_lminion(mtmp)) { + /* lawful minions don't get cursed, bad, or rusting objects */ + otmp->cursed = FALSE; + if (otmp->spe < 0) + otmp->spe = 0; + otmp->oerodeproof = TRUE; + } else if (is_mplayer(mtmp->data) && is_sword(otmp)) { + otmp->spe = (3 + rn2(4)); + } - if(otmp->otyp == CANDELABRUM_OF_INVOCATION) { - otmp->spe = 0; - otmp->age = 0L; - otmp->lamplit = FALSE; - otmp->blessed = otmp->cursed = FALSE; - } else if (otmp->otyp == BELL_OF_OPENING) { - otmp->blessed = otmp->cursed = FALSE; - } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) { - otmp->blessed = FALSE; - otmp->cursed = TRUE; - } + if (otmp->otyp == CANDELABRUM_OF_INVOCATION) { + otmp->spe = 0; + otmp->age = 0L; + otmp->lamplit = FALSE; + otmp->blessed = otmp->cursed = FALSE; + } else if (otmp->otyp == BELL_OF_OPENING) { + otmp->blessed = otmp->cursed = FALSE; + } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) { + otmp->blessed = FALSE; + otmp->cursed = TRUE; + } - /* leaders don't tolerate inferior quality battle gear */ - if (is_prince(mtmp->data)) { - if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1) - otmp->spe = 1; - else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0) - otmp->spe = 0; - } + /* leaders don't tolerate inferior quality battle gear */ + if (is_prince(mtmp->data)) { + if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1) + otmp->spe = 1; + else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0) + otmp->spe = 0; + } - spe = otmp->spe; - (void) mpickobj(mtmp, otmp); /* might free otmp */ - return(spe); - } else return(0); + spe = otmp->spe; + (void) mpickobj(mtmp, otmp); /* might free otmp */ + return (spe); + } else + return (0); } int golemhp(type) int type; { - switch(type) { - case PM_STRAW_GOLEM: return 20; - case PM_PAPER_GOLEM: return 20; - case PM_ROPE_GOLEM: return 30; - case PM_LEATHER_GOLEM: return 40; - case PM_GOLD_GOLEM: return 40; - case PM_WOOD_GOLEM: return 50; - case PM_FLESH_GOLEM: return 40; - case PM_CLAY_GOLEM: return 50; - case PM_STONE_GOLEM: return 60; - case PM_GLASS_GOLEM: return 60; - case PM_IRON_GOLEM: return 80; - default: return 0; - } + switch (type) { + case PM_STRAW_GOLEM: + return 20; + case PM_PAPER_GOLEM: + return 20; + case PM_ROPE_GOLEM: + return 30; + case PM_LEATHER_GOLEM: + return 40; + case PM_GOLD_GOLEM: + return 40; + case PM_WOOD_GOLEM: + return 50; + case PM_FLESH_GOLEM: + return 40; + case PM_CLAY_GOLEM: + return 50; + case PM_STONE_GOLEM: + return 60; + case PM_GLASS_GOLEM: + return 60; + case PM_IRON_GOLEM: + return 80; + default: + return 0; + } } /* @@ -1634,33 +1789,42 @@ boolean peace_minded(ptr) register struct permonst *ptr; { - aligntyp mal = ptr->maligntyp, ual = u.ualign.type; + aligntyp mal = ptr->maligntyp, ual = u.ualign.type; - if (always_peaceful(ptr)) return TRUE; - if (always_hostile(ptr)) return FALSE; - if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN) - return TRUE; - if (ptr->msound == MS_NEMESIS) return FALSE; + if (always_peaceful(ptr)) + return TRUE; + if (always_hostile(ptr)) + return FALSE; + if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN) + return TRUE; + if (ptr->msound == MS_NEMESIS) + return FALSE; - if (race_peaceful(ptr)) return TRUE; - if (race_hostile(ptr)) return FALSE; + if (race_peaceful(ptr)) + return TRUE; + if (race_hostile(ptr)) + return FALSE; - /* the monster is hostile if its alignment is different from the - * player's */ - if (sgn(mal) != sgn(ual)) return FALSE; + /* the monster is hostile if its alignment is different from the + * player's */ + if (sgn(mal) != sgn(ual)) + return FALSE; - /* Negative monster hostile to player with Amulet. */ - if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE; + /* Negative monster hostile to player with Amulet. */ + if (mal < A_NEUTRAL && u.uhave.amulet) + return FALSE; - /* minions are hostile to players that have strayed at all */ - if (is_minion(ptr)) return((boolean)(u.ualign.record >= 0)); + /* minions are hostile to players that have strayed at all */ + if (is_minion(ptr)) + return ((boolean)(u.ualign.record >= 0)); - /* Last case: a chance of a co-aligned monster being - * hostile. This chance is greater if the player has strayed - * (u.ualign.record negative) or the monster is not strongly aligned. - */ - return((boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) && - !!rn2(2 + abs(mal)))); + /* Last case: a chance of a co-aligned monster being + * hostile. This chance is greater if the player has strayed + * (u.ualign.record negative) or the monster is not strongly aligned. + */ + return ( + (boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) + && !!rn2(2 + abs(mal)))); } /* Set malign to have the proper effect on player alignment if monster is @@ -1677,49 +1841,49 @@ void set_malign(mtmp) struct monst *mtmp; { - schar mal = mtmp->data->maligntyp; - boolean coaligned; + schar mal = mtmp->data->maligntyp; + boolean coaligned; - if (mtmp->ispriest || mtmp->isminion) { - /* some monsters have individual alignments; check them */ - if (mtmp->ispriest && EPRI(mtmp)) - mal = EPRI(mtmp)->shralign; - else if (mtmp->isminion && EMIN(mtmp)) - mal = EMIN(mtmp)->min_align; - /* unless alignment is none, set mal to -5,0,5 */ - /* (see align.h for valid aligntyp values) */ - if(mal != A_NONE) - mal *= 5; - } + if (mtmp->ispriest || mtmp->isminion) { + /* some monsters have individual alignments; check them */ + if (mtmp->ispriest && EPRI(mtmp)) + mal = EPRI(mtmp)->shralign; + else if (mtmp->isminion && EMIN(mtmp)) + mal = EMIN(mtmp)->min_align; + /* unless alignment is none, set mal to -5,0,5 */ + /* (see align.h for valid aligntyp values) */ + if (mal != A_NONE) + mal *= 5; + } - coaligned = (sgn(mal) == sgn(u.ualign.type)); - if (mtmp->data->msound == MS_LEADER) { - mtmp->malign = -20; - } else if (mal == A_NONE) { - if (mtmp->mpeaceful) - mtmp->malign = 0; - else - mtmp->malign = 20; /* really hostile */ - } else if (always_peaceful(mtmp->data)) { - int absmal = abs(mal); - if (mtmp->mpeaceful) - mtmp->malign = -3*max(5,absmal); - else - mtmp->malign = 3*max(5,absmal); /* renegade */ - } else if (always_hostile(mtmp->data)) { - int absmal = abs(mal); - if (coaligned) - mtmp->malign = 0; - else - mtmp->malign = max(5,absmal); - } else if (coaligned) { - int absmal = abs(mal); - if (mtmp->mpeaceful) - mtmp->malign = -3*max(3,absmal); - else /* renegade */ - mtmp->malign = max(3,absmal); - } else /* not coaligned and therefore hostile */ - mtmp->malign = abs(mal); + coaligned = (sgn(mal) == sgn(u.ualign.type)); + if (mtmp->data->msound == MS_LEADER) { + mtmp->malign = -20; + } else if (mal == A_NONE) { + if (mtmp->mpeaceful) + mtmp->malign = 0; + else + mtmp->malign = 20; /* really hostile */ + } else if (always_peaceful(mtmp->data)) { + int absmal = abs(mal); + if (mtmp->mpeaceful) + mtmp->malign = -3 * max(5, absmal); + else + mtmp->malign = 3 * max(5, absmal); /* renegade */ + } else if (always_hostile(mtmp->data)) { + int absmal = abs(mal); + if (coaligned) + mtmp->malign = 0; + else + mtmp->malign = max(5, absmal); + } else if (coaligned) { + int absmal = abs(mal); + if (mtmp->mpeaceful) + mtmp->malign = -3 * max(3, absmal); + else /* renegade */ + mtmp->malign = max(3, absmal); + } else /* not coaligned and therefore hostile */ + mtmp->malign = abs(mal); } /* allocate a new mcorpsenm field for a monster; only need mextra itself */ @@ -1727,8 +1891,9 @@ void newmcorpsenm(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) mtmp->mextra = newmextra(); - MCORPSENM(mtmp) = NON_PM; /* not initialized yet */ + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + MCORPSENM(mtmp) = NON_PM; /* not initialized yet */ } /* release monster's mcorpsenm field; basically a no-op */ @@ -1736,169 +1901,175 @@ void freemcorpsenm(mtmp) struct monst *mtmp; { - if (has_mcorpsenm(mtmp)) MCORPSENM(mtmp) = NON_PM; + if (has_mcorpsenm(mtmp)) + MCORPSENM(mtmp) = NON_PM; } static NEARDATA char syms[] = { - MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS, - FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS, - AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS, - S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF, + MAXOCLASSES, MAXOCLASSES + 1, RING_CLASS, WAND_CLASS, WEAPON_CLASS, + FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS, + AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS, + S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF, }; -void -set_mimic_sym(mtmp) /* KAA, modified by ERS */ +void set_mimic_sym(mtmp) /* KAA, modified by ERS */ register struct monst *mtmp; { - int typ, roomno, rt; - unsigned appear, ap_type; - int s_sym; - struct obj *otmp; - int mx, my; + int typ, roomno, rt; + unsigned appear, ap_type; + int s_sym; + struct obj *otmp; + int mx, my; - if (!mtmp) return; - mx = mtmp->mx; my = mtmp->my; - typ = levl[mx][my].typ; - /* only valid for INSIDE of room */ - roomno = levl[mx][my].roomno - ROOMOFFSET; - if (roomno >= 0) - rt = rooms[roomno].rtype; + if (!mtmp) + return; + mx = mtmp->mx; + my = mtmp->my; + typ = levl[mx][my].typ; + /* only valid for INSIDE of room */ + roomno = levl[mx][my].roomno - ROOMOFFSET; + if (roomno >= 0) + rt = rooms[roomno].rtype; #ifdef SPECIALIZATION - else if (IS_ROOM(typ)) - rt = OROOM, roomno = 0; + else if (IS_ROOM(typ)) + rt = OROOM, roomno = 0; #endif - else rt = 0; /* roomno < 0 case for GCC_WARN */ + else + rt = 0; /* roomno < 0 case for GCC_WARN */ - if (OBJ_AT(mx, my)) { - ap_type = M_AP_OBJECT; - appear = level.objects[mx][my]->otyp; - } else if (IS_DOOR(typ) || IS_WALL(typ) || - typ == SDOOR || typ == SCORR) { - ap_type = M_AP_FURNITURE; - /* - * If there is a wall to the left that connects to this - * location, then the mimic mimics a horizontal closed door. - * This does not allow doors to be in corners of rooms. - * Since rogue has no closed doors, mimic a wall there - * (yes, mimics can end up on this level by various means). - */ - if (mx != 0 && - (levl[mx-1][my].typ == HWALL || - levl[mx-1][my].typ == TLCORNER || - levl[mx-1][my].typ == TRWALL || - levl[mx-1][my].typ == BLCORNER || - levl[mx-1][my].typ == TDWALL || - levl[mx-1][my].typ == CROSSWALL|| - levl[mx-1][my].typ == TUWALL )) - appear = Is_rogue_level(&u.uz) ? S_hwall : S_hcdoor; - else - appear = Is_rogue_level(&u.uz) ? S_vwall : S_vcdoor; - if(!mtmp->minvis || See_invisible) - block_point(mx,my); /* vision */ - } else if (level.flags.is_maze_lev && !In_sokoban(&u.uz) && rn2(2)) { - ap_type = M_AP_OBJECT; - appear = STATUE; - } else if (roomno < 0 && !t_at(mx, my)) { - ap_type = M_AP_OBJECT; - appear = BOULDER; - if(!mtmp->minvis || See_invisible) - block_point(mx,my); /* vision */ - } else if (rt == ZOO || rt == VAULT) { - ap_type = M_AP_OBJECT; - appear = GOLD_PIECE; - } else if (rt == DELPHI) { - if (rn2(2)) { - ap_type = M_AP_OBJECT; - appear = STATUE; - } else { - ap_type = M_AP_FURNITURE; - appear = S_fountain; - } - } else if (rt == TEMPLE) { - ap_type = M_AP_FURNITURE; - appear = S_altar; - /* - * We won't bother with beehives, morgues, barracks, throne rooms - * since they shouldn't contain too many mimics anyway... - */ - } else if (rt >= SHOPBASE) { - s_sym = get_shop_item(rt - SHOPBASE); - if (s_sym < 0) { - ap_type = M_AP_OBJECT; - appear = -s_sym; - } else { - if (s_sym == RANDOM_CLASS) - s_sym = syms[rn2((int)sizeof(syms)-2) + 2]; - goto assign_sym; - } - } else { - s_sym = syms[rn2((int)sizeof(syms))]; -assign_sym: - if (s_sym >= MAXOCLASSES) { - ap_type = M_AP_FURNITURE; - appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair; - } else { - ap_type = M_AP_OBJECT; - if (s_sym == S_MIMIC_DEF) { - appear = STRANGE_OBJECT; - } else if (s_sym == COIN_CLASS) { - appear = GOLD_PIECE; - } else { - otmp = mkobj((char) s_sym, FALSE); - appear = otmp->otyp; - /* make sure container contents are free'ed */ - obfree(otmp, (struct obj *) 0); - } - } - } - mtmp->m_ap_type = ap_type; - mtmp->mappearance = appear; - if (ap_type == M_AP_OBJECT && - (appear == STATUE || appear == CORPSE || - appear == FIGURINE || appear == EGG)) { - newmcorpsenm(mtmp); - MCORPSENM(mtmp) = rndmonnum(); - if (appear == EGG && !can_be_hatched(MCORPSENM(mtmp))) - MCORPSENM(mtmp) = NON_PM; /* revert to generic egg */ - } + if (OBJ_AT(mx, my)) { + ap_type = M_AP_OBJECT; + appear = level.objects[mx][my]->otyp; + } else if (IS_DOOR(typ) || IS_WALL(typ) || typ == SDOOR || typ == SCORR) { + ap_type = M_AP_FURNITURE; + /* + * If there is a wall to the left that connects to this + * location, then the mimic mimics a horizontal closed door. + * This does not allow doors to be in corners of rooms. + * Since rogue has no closed doors, mimic a wall there + * (yes, mimics can end up on this level by various means). + */ + if (mx != 0 && (levl[mx - 1][my].typ == HWALL + || levl[mx - 1][my].typ == TLCORNER + || levl[mx - 1][my].typ == TRWALL + || levl[mx - 1][my].typ == BLCORNER + || levl[mx - 1][my].typ == TDWALL + || levl[mx - 1][my].typ == CROSSWALL + || levl[mx - 1][my].typ == TUWALL)) + appear = Is_rogue_level(&u.uz) ? S_hwall : S_hcdoor; + else + appear = Is_rogue_level(&u.uz) ? S_vwall : S_vcdoor; + if (!mtmp->minvis || See_invisible) + block_point(mx, my); /* vision */ + } else if (level.flags.is_maze_lev && !In_sokoban(&u.uz) && rn2(2)) { + ap_type = M_AP_OBJECT; + appear = STATUE; + } else if (roomno < 0 && !t_at(mx, my)) { + ap_type = M_AP_OBJECT; + appear = BOULDER; + if (!mtmp->minvis || See_invisible) + block_point(mx, my); /* vision */ + } else if (rt == ZOO || rt == VAULT) { + ap_type = M_AP_OBJECT; + appear = GOLD_PIECE; + } else if (rt == DELPHI) { + if (rn2(2)) { + ap_type = M_AP_OBJECT; + appear = STATUE; + } else { + ap_type = M_AP_FURNITURE; + appear = S_fountain; + } + } else if (rt == TEMPLE) { + ap_type = M_AP_FURNITURE; + appear = S_altar; + /* + * We won't bother with beehives, morgues, barracks, throne rooms + * since they shouldn't contain too many mimics anyway... + */ + } else if (rt >= SHOPBASE) { + s_sym = get_shop_item(rt - SHOPBASE); + if (s_sym < 0) { + ap_type = M_AP_OBJECT; + appear = -s_sym; + } else { + if (s_sym == RANDOM_CLASS) + s_sym = syms[rn2((int) sizeof(syms) - 2) + 2]; + goto assign_sym; + } + } else { + s_sym = syms[rn2((int) sizeof(syms))]; + assign_sym: + if (s_sym >= MAXOCLASSES) { + ap_type = M_AP_FURNITURE; + appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair; + } else { + ap_type = M_AP_OBJECT; + if (s_sym == S_MIMIC_DEF) { + appear = STRANGE_OBJECT; + } else if (s_sym == COIN_CLASS) { + appear = GOLD_PIECE; + } else { + otmp = mkobj((char) s_sym, FALSE); + appear = otmp->otyp; + /* make sure container contents are free'ed */ + obfree(otmp, (struct obj *) 0); + } + } + } + mtmp->m_ap_type = ap_type; + mtmp->mappearance = appear; + if (ap_type == M_AP_OBJECT && (appear == STATUE || appear == CORPSE + || appear == FIGURINE || appear == EGG)) { + newmcorpsenm(mtmp); + MCORPSENM(mtmp) = rndmonnum(); + if (appear == EGG && !can_be_hatched(MCORPSENM(mtmp))) + MCORPSENM(mtmp) = NON_PM; /* revert to generic egg */ + } } -/* release a monster from a bag of tricks; return number of monsters created */ +/* release a monster from a bag of tricks; return number of monsters created + */ int bagotricks(bag, tipping, seencount) struct obj *bag; -boolean tipping; /* caller emptying entire contents; affects shop handling */ -int *seencount; /* secondary output */ +boolean tipping; /* caller emptying entire contents; affects shop handling */ +int *seencount; /* secondary output */ { int moncount = 0; if (!bag || bag->otyp != BAG_OF_TRICKS) { - impossible("bad bag o' tricks"); + impossible("bad bag o' tricks"); } else if (bag->spe < 1) { - /* if tipping known empty bag, give normal empty container message */ - pline1((tipping && bag->cknown) ? "It's empty." : nothing_happens); - /* now known to be empty if sufficiently discovered */ - if (bag->dknown && objects[bag->otyp].oc_name_known) bag->cknown = 1; + /* if tipping known empty bag, give normal empty container message */ + pline1((tipping && bag->cknown) ? "It's empty." : nothing_happens); + /* now known to be empty if sufficiently discovered */ + if (bag->dknown && objects[bag->otyp].oc_name_known) + bag->cknown = 1; } else { - struct monst *mtmp; - int creatcnt = 1, seecount = 0; + struct monst *mtmp; + int creatcnt = 1, seecount = 0; - consume_obj_charge(bag, !tipping); + consume_obj_charge(bag, !tipping); - if (!rn2(23)) creatcnt += rnd(7); - do { - mtmp = makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS); - if (mtmp) { - ++moncount; - if (canspotmon(mtmp)) ++seecount; - } - } while (--creatcnt > 0); - if (seecount) { - if (seencount) *seencount += seecount; - if (bag->dknown) makeknown(BAG_OF_TRICKS); - } else if (!tipping) { - pline1(!moncount ? nothing_happens : "Nothing seems to happen."); - } + if (!rn2(23)) + creatcnt += rnd(7); + do { + mtmp = makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); + if (mtmp) { + ++moncount; + if (canspotmon(mtmp)) + ++seecount; + } + } while (--creatcnt > 0); + if (seecount) { + if (seencount) + *seencount += seecount; + if (bag->dknown) + makeknown(BAG_OF_TRICKS); + } else if (!tipping) { + pline1(!moncount ? nothing_happens : "Nothing seems to happen."); + } } return moncount; } diff --git a/src/mapglyph.c b/src/mapglyph.c index 02d0cf4cf..16c9ad368 100644 --- a/src/mapglyph.c +++ b/src/mapglyph.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mapglyph.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mapglyph.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ /* NetHack 3.6 mapglyph.c $Date: 2009/05/06 10:46:45 $ $Revision: 1.24 $ */ /* SCCS Id: @(#)mapglyph.c 3.5 2006/10/01 */ /* Copyright (c) David Cohrs, 1991 */ @@ -6,36 +6,37 @@ #include "hack.h" #if defined(TTY_GRAPHICS) -#include "wintty.h" /* for prototype of has_color() only */ +#include "wintty.h" /* for prototype of has_color() only */ #endif #include "color.h" -#define HI_DOMESTIC CLR_WHITE /* monst.c */ +#define HI_DOMESTIC CLR_WHITE /* monst.c */ int explcolors[] = { - CLR_BLACK, /* dark */ - CLR_GREEN, /* noxious */ - CLR_BROWN, /* muddy */ - CLR_BLUE, /* wet */ - CLR_MAGENTA, /* magical */ - CLR_ORANGE, /* fiery */ - CLR_WHITE, /* frosty */ + CLR_BLACK, /* dark */ + CLR_GREEN, /* noxious */ + CLR_BROWN, /* muddy */ + CLR_BLUE, /* wet */ + CLR_MAGENTA, /* magical */ + CLR_ORANGE, /* fiery */ + CLR_WHITE, /* frosty */ }; #if !defined(TTY_GRAPHICS) -#define has_color(n) TRUE +#define has_color(n) TRUE #endif #ifdef TEXTCOLOR -#define zap_color(n) color = iflags.use_color ? zapcolors[n] : NO_COLOR +#define zap_color(n) color = iflags.use_color ? zapcolors[n] : NO_COLOR #define cmap_color(n) color = iflags.use_color ? defsyms[n].color : NO_COLOR -#define obj_color(n) color = iflags.use_color ? objects[n].oc_color : NO_COLOR -#define mon_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define obj_color(n) color = iflags.use_color ? objects[n].oc_color : NO_COLOR +#define mon_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR #define invis_color(n) color = NO_COLOR -#define pet_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR -#define warn_color(n) color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR +#define pet_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define warn_color(n) \ + color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR #define explode_color(n) color = iflags.use_color ? explcolors[n] : NO_COLOR -#else /* no text color */ +#else /* no text color */ #define zap_color(n) #define cmap_color(n) @@ -47,13 +48,13 @@ int explcolors[] = { #define explode_color(n) #endif -# if defined(USE_TILES) && defined(MSDOS) -#define HAS_ROGUE_IBM_GRAPHICS (currentgraphics == ROGUESET && \ - SYMHANDLING(H_IBM) && !iflags.grmode) -# else -#define HAS_ROGUE_IBM_GRAPHICS (currentgraphics == ROGUESET && \ - SYMHANDLING(H_IBM)) -# endif +#if defined(USE_TILES) && defined(MSDOS) +#define HAS_ROGUE_IBM_GRAPHICS \ + (currentgraphics == ROGUESET && SYMHANDLING(H_IBM) && !iflags.grmode) +#else +#define HAS_ROGUE_IBM_GRAPHICS \ + (currentgraphics == ROGUESET && SYMHANDLING(H_IBM)) +#endif /*ARGSUSED*/ int @@ -62,14 +63,14 @@ int glyph, *ocolor, x, y; int *ochar; unsigned *ospecial; { - register int offset, idx; - int color = NO_COLOR; - nhsym ch; - unsigned special = 0; - /* condense multiple tests in macro version down to single */ - boolean has_rogue_ibm_graphics = HAS_ROGUE_IBM_GRAPHICS; - boolean has_rogue_color = (has_rogue_ibm_graphics && - (symset[currentgraphics].nocolor == 0)); + register int offset, idx; + int color = NO_COLOR; + nhsym ch; + unsigned special = 0; + /* condense multiple tests in macro version down to single */ + boolean has_rogue_ibm_graphics = HAS_ROGUE_IBM_GRAPHICS; + boolean has_rogue_color = + (has_rogue_ibm_graphics && (symset[currentgraphics].nocolor == 0)); /* * Map the glyph back to a character and color. @@ -77,138 +78,147 @@ unsigned *ospecial; * Warning: For speed, this makes an assumption on the order of * offsets. The order is set in display.h. */ - if ((offset = (glyph - GLYPH_STATUE_OFF)) >= 0) { /* a statue */ - idx = mons[offset].mlet + SYM_OFF_M; - if (has_rogue_color) - color = CLR_RED; - else - obj_color(STATUE); - special |= MG_STATUE; - } else if ((offset = (glyph - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ - idx = offset + SYM_OFF_W; - if (has_rogue_color) - color = NO_COLOR; - else - warn_color(offset); - } else if ((offset = (glyph - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ - /* see swallow_to_glyph() in display.c */ - idx = (S_sw_tl + (offset & 0x7)) + SYM_OFF_P; - if (has_rogue_color && iflags.use_color) - color = NO_COLOR; - else - mon_color(offset >> 3); - } else if ((offset = (glyph - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ - /* see zapdir_to_glyph() in display.c */ - idx = (S_vbeam + (offset & 0x3)) + SYM_OFF_P; - if (has_rogue_color && iflags.use_color) - color = NO_COLOR; - else - zap_color((offset >> 2)); - } else if ((offset = (glyph - GLYPH_EXPLODE_OFF)) >= 0) { /* explosion */ - idx = ((offset % MAXEXPCHARS) + S_explode1) + SYM_OFF_P; - explode_color(offset / MAXEXPCHARS); - } else if ((offset = (glyph - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ - idx = offset + SYM_OFF_P; - if (has_rogue_color && iflags.use_color) { - if (offset >= S_vwall && offset <= S_hcdoor) - color = CLR_BROWN; - else if (offset >= S_arrow_trap && offset <= S_polymorph_trap) - color = CLR_MAGENTA; - else if (offset == S_corr || offset == S_litcorr) - color = CLR_GRAY; - else if (offset >= S_room && offset <= S_water && offset != S_darkroom) - color = CLR_GREEN; - else - color = NO_COLOR; - } else + if ((offset = (glyph - GLYPH_STATUE_OFF)) >= 0) { /* a statue */ + idx = mons[offset].mlet + SYM_OFF_M; + if (has_rogue_color) + color = CLR_RED; + else + obj_color(STATUE); + special |= MG_STATUE; + } else if ((offset = (glyph - GLYPH_WARNING_OFF)) + >= 0) { /* a warning flash */ + idx = offset + SYM_OFF_W; + if (has_rogue_color) + color = NO_COLOR; + else + warn_color(offset); + } else if ((offset = (glyph - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ + /* see swallow_to_glyph() in display.c */ + idx = (S_sw_tl + (offset & 0x7)) + SYM_OFF_P; + if (has_rogue_color && iflags.use_color) + color = NO_COLOR; + else + mon_color(offset >> 3); + } else if ((offset = (glyph - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ + /* see zapdir_to_glyph() in display.c */ + idx = (S_vbeam + (offset & 0x3)) + SYM_OFF_P; + if (has_rogue_color && iflags.use_color) + color = NO_COLOR; + else + zap_color((offset >> 2)); + } else if ((offset = (glyph - GLYPH_EXPLODE_OFF)) >= 0) { /* explosion */ + idx = ((offset % MAXEXPCHARS) + S_explode1) + SYM_OFF_P; + explode_color(offset / MAXEXPCHARS); + } else if ((offset = (glyph - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ + idx = offset + SYM_OFF_P; + if (has_rogue_color && iflags.use_color) { + if (offset >= S_vwall && offset <= S_hcdoor) + color = CLR_BROWN; + else if (offset >= S_arrow_trap && offset <= S_polymorph_trap) + color = CLR_MAGENTA; + else if (offset == S_corr || offset == S_litcorr) + color = CLR_GRAY; + else if (offset >= S_room && offset <= S_water + && offset != S_darkroom) + color = CLR_GREEN; + else + color = NO_COLOR; + } else #ifdef TEXTCOLOR - /* provide a visible difference if normal and lit corridor - * use the same symbol */ - if (iflags.use_color && offset == S_litcorr && - showsyms[idx] == showsyms[S_corr + SYM_OFF_P]) - color = CLR_WHITE; - else + /* provide a visible difference if normal and lit corridor + * use the same symbol */ + if (iflags.use_color && offset == S_litcorr + && showsyms[idx] == showsyms[S_corr + SYM_OFF_P]) + color = CLR_WHITE; + else #endif - cmap_color(offset); - } else if ((offset = (glyph - GLYPH_OBJ_OFF)) >= 0) { /* object */ - idx = objects[offset].oc_class + SYM_OFF_O; - if (offset == BOULDER && iflags.bouldersym) - idx = SYM_BOULDER + SYM_OFF_X; - if (has_rogue_color && iflags.use_color) { - switch(objects[offset].oc_class) { - case COIN_CLASS: color = CLR_YELLOW; break; - case FOOD_CLASS: color = CLR_RED; break; - default: color = CLR_BRIGHT_BLUE; break; - } - } else - obj_color(offset); - } else if ((offset = (glyph - GLYPH_RIDDEN_OFF)) >= 0) { /* mon ridden */ - idx = mons[offset].mlet + SYM_OFF_M; - if (has_rogue_color) - /* This currently implies that the hero is here -- monsters */ - /* don't ride (yet...). Should we set it to yellow like in */ - /* the monster case below? There is no equivalent in rogue. */ - color = NO_COLOR; /* no need to check iflags.use_color */ - else - mon_color(offset); - special |= MG_RIDDEN; - } else if ((offset = (glyph - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ - idx = objects[CORPSE].oc_class + SYM_OFF_O; - if (has_rogue_color && iflags.use_color) - color = CLR_RED; - else - mon_color(offset); - special |= MG_CORPSE; - } else if ((offset = (glyph - GLYPH_DETECT_OFF)) >= 0) { /* mon detect */ - idx = mons[offset].mlet + SYM_OFF_M; - if (has_rogue_color) - color = NO_COLOR; /* no need to check iflags.use_color */ - else - mon_color(offset); - /* Disabled for now; anyone want to get reverse video to work? */ - /* is_reverse = TRUE; */ - special |= MG_DETECT; - } else if ((offset = (glyph - GLYPH_INVIS_OFF)) >= 0) { /* invisible */ - idx = SYM_INVISIBLE + SYM_OFF_X; - if (has_rogue_color) - color = NO_COLOR; /* no need to check iflags.use_color */ - else - invis_color(offset); - special |= MG_INVIS; - } else if ((offset = (glyph - GLYPH_PET_OFF)) >= 0) { /* a pet */ - idx = mons[offset].mlet + SYM_OFF_M; - if (has_rogue_color) - color = NO_COLOR; /* no need to check iflags.use_color */ - else - pet_color(offset); - special |= MG_PET; - } else { /* a monster */ - idx = mons[glyph].mlet + SYM_OFF_M; - if (has_rogue_color && iflags.use_color) { - if (x == u.ux && y == u.uy) - /* actually player should be yellow-on-gray if in a corridor */ - color = CLR_YELLOW; - else - color = NO_COLOR; - } else { - mon_color(glyph); - /* special case the hero for `showrace' option */ + cmap_color(offset); + } else if ((offset = (glyph - GLYPH_OBJ_OFF)) >= 0) { /* object */ + idx = objects[offset].oc_class + SYM_OFF_O; + if (offset == BOULDER && iflags.bouldersym) + idx = SYM_BOULDER + SYM_OFF_X; + if (has_rogue_color && iflags.use_color) { + switch (objects[offset].oc_class) { + case COIN_CLASS: + color = CLR_YELLOW; + break; + case FOOD_CLASS: + color = CLR_RED; + break; + default: + color = CLR_BRIGHT_BLUE; + break; + } + } else + obj_color(offset); + } else if ((offset = (glyph - GLYPH_RIDDEN_OFF)) >= 0) { /* mon ridden */ + idx = mons[offset].mlet + SYM_OFF_M; + if (has_rogue_color) + /* This currently implies that the hero is here -- monsters */ + /* don't ride (yet...). Should we set it to yellow like in */ + /* the monster case below? There is no equivalent in rogue. */ + color = NO_COLOR; /* no need to check iflags.use_color */ + else + mon_color(offset); + special |= MG_RIDDEN; + } else if ((offset = (glyph - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ + idx = objects[CORPSE].oc_class + SYM_OFF_O; + if (has_rogue_color && iflags.use_color) + color = CLR_RED; + else + mon_color(offset); + special |= MG_CORPSE; + } else if ((offset = (glyph - GLYPH_DETECT_OFF)) >= 0) { /* mon detect */ + idx = mons[offset].mlet + SYM_OFF_M; + if (has_rogue_color) + color = NO_COLOR; /* no need to check iflags.use_color */ + else + mon_color(offset); + /* Disabled for now; anyone want to get reverse video to work? */ + /* is_reverse = TRUE; */ + special |= MG_DETECT; + } else if ((offset = (glyph - GLYPH_INVIS_OFF)) >= 0) { /* invisible */ + idx = SYM_INVISIBLE + SYM_OFF_X; + if (has_rogue_color) + color = NO_COLOR; /* no need to check iflags.use_color */ + else + invis_color(offset); + special |= MG_INVIS; + } else if ((offset = (glyph - GLYPH_PET_OFF)) >= 0) { /* a pet */ + idx = mons[offset].mlet + SYM_OFF_M; + if (has_rogue_color) + color = NO_COLOR; /* no need to check iflags.use_color */ + else + pet_color(offset); + special |= MG_PET; + } else { /* a monster */ + idx = mons[glyph].mlet + SYM_OFF_M; + if (has_rogue_color && iflags.use_color) { + if (x == u.ux && y == u.uy) + /* actually player should be yellow-on-gray if in a corridor + */ + color = CLR_YELLOW; + else + color = NO_COLOR; + } else { + mon_color(glyph); +/* special case the hero for `showrace' option */ #ifdef TEXTCOLOR - if (iflags.use_color && x == u.ux && y == u.uy && - flags.showrace && !Upolyd) - color = HI_DOMESTIC; + if (iflags.use_color && x == u.ux && y == u.uy && flags.showrace + && !Upolyd) + color = HI_DOMESTIC; #endif - } + } } ch = showsyms[idx]; #ifdef TEXTCOLOR /* Turn off color if no color defined, or rogue level w/o PC graphics. */ if (!has_color(color) || (Is_rogue_level(&u.uz) && !has_rogue_color)) - color = NO_COLOR; + color = NO_COLOR; #endif - *ochar = (int)ch; + *ochar = (int) ch; *ospecial = special; #ifdef TEXTCOLOR *ocolor = color; @@ -220,9 +230,9 @@ char * encglyph(glyph) int glyph; { - static char encbuf[20]; - Sprintf(encbuf, "\\G%04X%04X", context.rndencode, glyph); - return encbuf; + static char encbuf[20]; + Sprintf(encbuf, "\\G%04X%04X", context.rndencode, glyph); + return encbuf; } /* @@ -230,7 +240,7 @@ int glyph; * contain a sequence of characters representing: * \GXXXXNNNN a glyph value, encoded by encglyph(). * - * For window ports that haven't yet written their own + * For window ports that haven't yet written their own * XXX_putmixed() routine, this general one can be used. * It replaces the encoded glyph sequence with a single * showsyms[] char, then just passes that string onto @@ -239,39 +249,41 @@ int glyph; void genl_putmixed(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { - char buf[BUFSZ]; - const char *cp = str; - char *put = buf; - while (*cp) { - if (*cp == '\\') { - int rndchk = 0, so = 0, gv = 0, ch, oc, dcount; - unsigned os; - const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; - const char *save_cp = cp; - - cp++; - switch(*cp) { - case 'G': /* glyph value \GXXXXNNNN*/ - dcount = 0; - for (++cp; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); cp++) - rndchk = (int)((rndchk * 16) + ((int)(dp - hex) / 2)); + char buf[BUFSZ]; + const char *cp = str; + char *put = buf; + while (*cp) { + if (*cp == '\\') { + int rndchk = 0, so = 0, gv = 0, ch, oc, dcount; + unsigned os; + const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; + const char *save_cp = cp; - if (rndchk == context.rndencode) { - dcount = 0; - for (; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); cp++) - gv = (int)((gv * 16) + ((int)(dp - hex) / 2)); - so = mapglyph(gv, &ch, &oc, &os, 0, 0); - *put++ = showsyms[so]; - } else { - /* possible forgery - leave it the way it is */ - cp = save_cp; - } - break; -# if 0 + cp++; + switch (*cp) { + case 'G': /* glyph value \GXXXXNNNN*/ + dcount = 0; + for (++cp; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); + cp++) + rndchk = (int) ((rndchk * 16) + ((int) (dp - hex) / 2)); + + if (rndchk == context.rndencode) { + dcount = 0; + for (; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); + cp++) + gv = (int) ((gv * 16) + ((int) (dp - hex) / 2)); + so = mapglyph(gv, &ch, &oc, &os, 0, 0); + *put++ = showsyms[so]; + } else { + /* possible forgery - leave it the way it is */ + cp = save_cp; + } + break; +#if 0 case 'S': /* symbol offset */ dcount = 0; for (++cp; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); cp++) @@ -284,15 +296,15 @@ genl_putmixed(window, attr, str) } *put++ = showsyms[so]; break; -# endif - case '\\': - break; - } - } - *put++ = *cp++; - } - *put = '\0'; - /* now send it to the normal putstr */ - putstr(window, attr, buf); +#endif + case '\\': + break; + } + } + *put++ = *cp++; + } + *put = '\0'; + /* now send it to the normal putstr */ + putstr(window, attr, buf); } /*mapglyph.c*/ diff --git a/src/mcastu.c b/src/mcastu.c index 5d55dc74f..bef7ddede 100644 --- a/src/mcastu.c +++ b/src/mcastu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mcastu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mcastu.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.42 $ */ /* NetHack 3.6 mcastu.c $Date: 2011/12/30 23:14:58 $ $Revision: 1.37 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,40 +6,41 @@ #include "hack.h" /* monster mage spells */ -#define MGC_PSI_BOLT 0 -#define MGC_CURE_SELF 1 -#define MGC_HASTE_SELF 2 -#define MGC_STUN_YOU 3 -#define MGC_DISAPPEAR 4 -#define MGC_WEAKEN_YOU 5 -#define MGC_DESTRY_ARMR 6 -#define MGC_CURSE_ITEMS 7 -#define MGC_AGGRAVATION 8 -#define MGC_SUMMON_MONS 9 -#define MGC_CLONE_WIZ 10 -#define MGC_DEATH_TOUCH 11 +#define MGC_PSI_BOLT 0 +#define MGC_CURE_SELF 1 +#define MGC_HASTE_SELF 2 +#define MGC_STUN_YOU 3 +#define MGC_DISAPPEAR 4 +#define MGC_WEAKEN_YOU 5 +#define MGC_DESTRY_ARMR 6 +#define MGC_CURSE_ITEMS 7 +#define MGC_AGGRAVATION 8 +#define MGC_SUMMON_MONS 9 +#define MGC_CLONE_WIZ 10 +#define MGC_DEATH_TOUCH 11 /* monster cleric spells */ -#define CLC_OPEN_WOUNDS 0 -#define CLC_CURE_SELF 1 -#define CLC_CONFUSE_YOU 2 -#define CLC_PARALYZE 3 -#define CLC_BLIND_YOU 4 -#define CLC_INSECTS 5 -#define CLC_CURSE_ITEMS 6 -#define CLC_LIGHTNING 7 -#define CLC_FIRE_PILLAR 8 -#define CLC_GEYSER 9 +#define CLC_OPEN_WOUNDS 0 +#define CLC_CURE_SELF 1 +#define CLC_CONFUSE_YOU 2 +#define CLC_PARALYZE 3 +#define CLC_BLIND_YOU 4 +#define CLC_INSECTS 5 +#define CLC_CURSE_ITEMS 6 +#define CLC_LIGHTNING 7 +#define CLC_FIRE_PILLAR 8 +#define CLC_GEYSER 9 -STATIC_DCL void FDECL(cursetxt,(struct monst *,BOOLEAN_P)); +STATIC_DCL void FDECL(cursetxt, (struct monst *, BOOLEAN_P)); STATIC_DCL int FDECL(choose_magic_spell, (int)); STATIC_DCL int FDECL(choose_clerical_spell, (int)); -STATIC_DCL void FDECL(cast_wizard_spell,(struct monst *, int,int)); -STATIC_DCL void FDECL(cast_cleric_spell,(struct monst *, int,int)); -STATIC_DCL boolean FDECL(is_undirected_spell,(unsigned int,int)); -STATIC_DCL boolean FDECL(spell_would_be_useless,(struct monst *,unsigned int,int)); +STATIC_DCL void FDECL(cast_wizard_spell, (struct monst *, int, int)); +STATIC_DCL void FDECL(cast_cleric_spell, (struct monst *, int, int)); +STATIC_DCL boolean FDECL(is_undirected_spell, (unsigned int, int)); +STATIC_DCL boolean +FDECL(spell_would_be_useless, (struct monst *, unsigned int, int)); -extern const char * const flash_types[]; /* from zap.c */ +extern const char *const flash_types[]; /* from zap.c */ /* feedback when frustrated monster couldn't cast a spell */ STATIC_OVL @@ -48,26 +49,27 @@ cursetxt(mtmp, undirected) struct monst *mtmp; boolean undirected; { - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) { - const char *point_msg; /* spellcasting monsters are impolite */ + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) { + const char *point_msg; /* spellcasting monsters are impolite */ - if (undirected) - point_msg = "all around, then curses"; - else if ((Invis && !perceives(mtmp->data) && - (mtmp->mux != u.ux || mtmp->muy != u.uy)) || - (youmonst.m_ap_type == M_AP_OBJECT && - youmonst.mappearance == STRANGE_OBJECT) || - u.uundetected) - point_msg = "and curses in your general direction"; - else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) - point_msg = "and curses at your displaced image"; - else - point_msg = "at you, then curses"; + if (undirected) + point_msg = "all around, then curses"; + else if ((Invis && !perceives(mtmp->data) + && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + || (youmonst.m_ap_type == M_AP_OBJECT + && youmonst.mappearance == STRANGE_OBJECT) + || u.uundetected) + point_msg = "and curses in your general direction"; + else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + point_msg = "and curses at your displaced image"; + else + point_msg = "at you, then curses"; - pline("%s points %s.", Monnam(mtmp), point_msg); - } else if ((!(moves % 4) || !rn2(4))) { - if (!Deaf) Norep("You hear a mumbled curse."); - } + pline("%s points %s.", Monnam(mtmp), point_msg); + } else if ((!(moves % 4) || !rn2(4))) { + if (!Deaf) + Norep("You hear a mumbled curse."); + } } /* convert a level based random selection into a specific mage spell; @@ -76,50 +78,53 @@ STATIC_OVL int choose_magic_spell(spellval) int spellval; { - /* for 3.4.3 and earlier, val greater than 22 selected the default spell */ - while (spellval > 24 && rn2(25)) spellval = rn2(spellval); + /* for 3.4.3 and earlier, val greater than 22 selected the default spell + */ + while (spellval > 24 && rn2(25)) + spellval = rn2(spellval); switch (spellval) { case 24: case 23: - if (Antimagic || Hallucination) return MGC_PSI_BOLT; - /* else FALL THROUGH */ + if (Antimagic || Hallucination) + return MGC_PSI_BOLT; + /* else FALL THROUGH */ case 22: case 21: case 20: - return MGC_DEATH_TOUCH; + return MGC_DEATH_TOUCH; case 19: case 18: - return MGC_CLONE_WIZ; + return MGC_CLONE_WIZ; case 17: case 16: case 15: - return MGC_SUMMON_MONS; + return MGC_SUMMON_MONS; case 14: case 13: - return MGC_AGGRAVATION; + return MGC_AGGRAVATION; case 12: case 11: case 10: - return MGC_CURSE_ITEMS; + return MGC_CURSE_ITEMS; case 9: case 8: - return MGC_DESTRY_ARMR; + return MGC_DESTRY_ARMR; case 7: case 6: - return MGC_WEAKEN_YOU; + return MGC_WEAKEN_YOU; case 5: case 4: - return MGC_DISAPPEAR; + return MGC_DISAPPEAR; case 3: - return MGC_STUN_YOU; + return MGC_STUN_YOU; case 2: - return MGC_HASTE_SELF; + return MGC_HASTE_SELF; case 1: - return MGC_CURE_SELF; + return MGC_CURE_SELF; case 0: default: - return MGC_PSI_BOLT; + return MGC_PSI_BOLT; } } @@ -128,39 +133,42 @@ STATIC_OVL int choose_clerical_spell(spellnum) int spellnum; { - /* for 3.4.3 and earlier, num greater than 13 selected the default spell */ - while (spellnum > 15 && rn2(16)) spellnum = rn2(spellnum); + /* for 3.4.3 and earlier, num greater than 13 selected the default spell + */ + while (spellnum > 15 && rn2(16)) + spellnum = rn2(spellnum); switch (spellnum) { case 15: case 14: - if (rn2(3)) return CLC_OPEN_WOUNDS; - /* else FALL THROUGH */ + if (rn2(3)) + return CLC_OPEN_WOUNDS; + /* else FALL THROUGH */ case 13: - return CLC_GEYSER; + return CLC_GEYSER; case 12: - return CLC_FIRE_PILLAR; + return CLC_FIRE_PILLAR; case 11: - return CLC_LIGHTNING; + return CLC_LIGHTNING; case 10: case 9: - return CLC_CURSE_ITEMS; + return CLC_CURSE_ITEMS; case 8: - return CLC_INSECTS; + return CLC_INSECTS; case 7: case 6: - return CLC_BLIND_YOU; + return CLC_BLIND_YOU; case 5: case 4: - return CLC_PARALYZE; + return CLC_PARALYZE; case 3: case 2: - return CLC_CONFUSE_YOU; + return CLC_CONFUSE_YOU; case 1: - return CLC_CURE_SELF; + return CLC_CURE_SELF; case 0: default: - return CLC_OPEN_WOUNDS; + return CLC_OPEN_WOUNDS; } } @@ -170,151 +178,159 @@ int spellnum; */ int castmu(mtmp, mattk, thinks_it_foundyou, foundyou) - register struct monst *mtmp; - register struct attack *mattk; - boolean thinks_it_foundyou; - boolean foundyou; +register struct monst *mtmp; +register struct attack *mattk; +boolean thinks_it_foundyou; +boolean foundyou; { - int dmg, ml = mtmp->m_lev; - int ret; - int spellnum = 0; + int dmg, ml = mtmp->m_lev; + int ret; + int spellnum = 0; - /* Three cases: - * -- monster is attacking you. Search for a useful spell. - * -- monster thinks it's attacking you. Search for a useful spell, - * without checking for undirected. If the spell found is directed, - * it fails with cursetxt() and loss of mspec_used. - * -- monster isn't trying to attack. Select a spell once. Don't keep - * searching; if that spell is not useful (or if it's directed), - * return and do something else. - * Since most spells are directed, this means that a monster that isn't - * attacking casts spells only a small portion of the time that an - * attacking monster does. - */ - if ((mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) && ml) { - int cnt = 40; + /* Three cases: + * -- monster is attacking you. Search for a useful spell. + * -- monster thinks it's attacking you. Search for a useful spell, + * without checking for undirected. If the spell found is directed, + * it fails with cursetxt() and loss of mspec_used. + * -- monster isn't trying to attack. Select a spell once. Don't keep + * searching; if that spell is not useful (or if it's directed), + * return and do something else. + * Since most spells are directed, this means that a monster that isn't + * attacking casts spells only a small portion of the time that an + * attacking monster does. + */ + if ((mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) && ml) { + int cnt = 40; - do { - spellnum = rn2(ml); - if (mattk->adtyp == AD_SPEL) - spellnum = choose_magic_spell(spellnum); - else - spellnum = choose_clerical_spell(spellnum); - /* not trying to attack? don't allow directed spells */ - if (!thinks_it_foundyou) { - if (!is_undirected_spell(mattk->adtyp, spellnum) || - spell_would_be_useless(mtmp, mattk->adtyp, spellnum)) { - if (foundyou) - impossible("spellcasting monster found you and doesn't know it?"); - return 0; - } - break; - } - } while(--cnt > 0 && - spell_would_be_useless(mtmp, mattk->adtyp, spellnum)); - if (cnt == 0) return 0; - } + do { + spellnum = rn2(ml); + if (mattk->adtyp == AD_SPEL) + spellnum = choose_magic_spell(spellnum); + else + spellnum = choose_clerical_spell(spellnum); + /* not trying to attack? don't allow directed spells */ + if (!thinks_it_foundyou) { + if (!is_undirected_spell(mattk->adtyp, spellnum) + || spell_would_be_useless(mtmp, mattk->adtyp, spellnum)) { + if (foundyou) + impossible("spellcasting monster found you and " + "doesn't know it?"); + return 0; + } + break; + } + } while (--cnt > 0 + && spell_would_be_useless(mtmp, mattk->adtyp, spellnum)); + if (cnt == 0) + return 0; + } - /* monster unable to cast spells? */ - if(mtmp->mcan || mtmp->mspec_used || !ml) { - cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum)); - return(0); - } + /* monster unable to cast spells? */ + if (mtmp->mcan || mtmp->mspec_used || !ml) { + cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum)); + return (0); + } - if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) { - mtmp->mspec_used = 10 - mtmp->m_lev; - if (mtmp->mspec_used < 2) mtmp->mspec_used = 2; - } + if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) { + mtmp->mspec_used = 10 - mtmp->m_lev; + if (mtmp->mspec_used < 2) + mtmp->mspec_used = 2; + } - /* monster can cast spells, but is casting a directed spell at the - wrong place? If so, give a message, and return. Do this *after* - penalizing mspec_used. */ - if (!foundyou && thinks_it_foundyou && - !is_undirected_spell(mattk->adtyp, spellnum)) { - pline("%s casts a spell at %s!", - canseemon(mtmp) ? Monnam(mtmp) : "Something", - levl[mtmp->mux][mtmp->muy].typ == WATER - ? "empty water" : "thin air"); - return(0); - } + /* monster can cast spells, but is casting a directed spell at the + wrong place? If so, give a message, and return. Do this *after* + penalizing mspec_used. */ + if (!foundyou && thinks_it_foundyou + && !is_undirected_spell(mattk->adtyp, spellnum)) { + pline("%s casts a spell at %s!", + canseemon(mtmp) ? Monnam(mtmp) : "Something", + levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water" + : "thin air"); + return (0); + } - nomul(0); - if(rn2(ml*10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */ - if (canseemon(mtmp) && !Deaf) - pline_The("air crackles around %s.", mon_nam(mtmp)); - return(0); - } - if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) { - pline("%s casts a spell%s!", - canspotmon(mtmp) ? Monnam(mtmp) : "Something", - is_undirected_spell(mattk->adtyp, spellnum) ? "" : - (Invisible && !perceives(mtmp->data) && - (mtmp->mux != u.ux || mtmp->muy != u.uy)) ? - " at a spot near you" : - (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) ? - " at your displaced image" : - " at you"); - } + nomul(0); + if (rn2(ml * 10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */ + if (canseemon(mtmp) && !Deaf) + pline_The("air crackles around %s.", mon_nam(mtmp)); + return (0); + } + if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) { + pline("%s casts a spell%s!", + canspotmon(mtmp) ? Monnam(mtmp) : "Something", + is_undirected_spell(mattk->adtyp, spellnum) + ? "" + : (Invisible && !perceives(mtmp->data) + && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + ? " at a spot near you" + : (Displaced + && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + ? " at your displaced image" + : " at you"); + } -/* - * As these are spells, the damage is related to the level - * of the monster casting the spell. - */ - if (!foundyou) { - dmg = 0; - if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) { - impossible( - "%s casting non-hand-to-hand version of hand-to-hand spell %d?", - Monnam(mtmp), mattk->adtyp); - return(0); - } - } else if (mattk->damd) - dmg = d((int)((ml/2) + mattk->damn), (int)mattk->damd); - else dmg = d((int)((ml/2) + 1), 6); - if (Half_spell_damage) dmg = (dmg+1) / 2; + /* + * As these are spells, the damage is related to the level + * of the monster casting the spell. + */ + if (!foundyou) { + dmg = 0; + if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) { + impossible("%s casting non-hand-to-hand version of hand-to-hand " + "spell %d?", + Monnam(mtmp), mattk->adtyp); + return (0); + } + } else if (mattk->damd) + dmg = d((int) ((ml / 2) + mattk->damn), (int) mattk->damd); + else + dmg = d((int) ((ml / 2) + 1), 6); + if (Half_spell_damage) + dmg = (dmg + 1) / 2; - ret = 1; + ret = 1; - switch (mattk->adtyp) { - - case AD_FIRE: - pline("You're enveloped in flames."); - if(Fire_resistance) { - shieldeff(u.ux, u.uy); - pline("But you resist the effects."); - dmg = 0; - } - burn_away_slime(); - break; - case AD_COLD: - pline("You're covered in frost."); - if(Cold_resistance) { - shieldeff(u.ux, u.uy); - pline("But you resist the effects."); - dmg = 0; - } - break; - case AD_MAGM: - You("are hit by a shower of missiles!"); - if(Antimagic) { - shieldeff(u.ux, u.uy); - pline_The("missiles bounce off!"); - dmg = 0; - } else dmg = d((int)mtmp->m_lev/2 + 1,6); - break; - case AD_SPEL: /* wizard spell */ - case AD_CLRC: /* clerical spell */ - { - if (mattk->adtyp == AD_SPEL) - cast_wizard_spell(mtmp, dmg, spellnum); - else - cast_cleric_spell(mtmp, dmg, spellnum); - dmg = 0; /* done by the spell casting functions */ - break; - } - } - if(dmg) mdamageu(mtmp, dmg); - return(ret); + switch (mattk->adtyp) { + case AD_FIRE: + pline("You're enveloped in flames."); + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + pline("But you resist the effects."); + dmg = 0; + } + burn_away_slime(); + break; + case AD_COLD: + pline("You're covered in frost."); + if (Cold_resistance) { + shieldeff(u.ux, u.uy); + pline("But you resist the effects."); + dmg = 0; + } + break; + case AD_MAGM: + You("are hit by a shower of missiles!"); + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline_The("missiles bounce off!"); + dmg = 0; + } else + dmg = d((int) mtmp->m_lev / 2 + 1, 6); + break; + case AD_SPEL: /* wizard spell */ + case AD_CLRC: /* clerical spell */ + { + if (mattk->adtyp == AD_SPEL) + cast_wizard_spell(mtmp, dmg, spellnum); + else + cast_cleric_spell(mtmp, dmg, spellnum); + dmg = 0; /* done by the spell casting functions */ + break; + } + } + if (dmg) + mdamageu(mtmp, dmg); + return (ret); } /* monster wizard and cleric spellcasting functions */ @@ -334,155 +350,158 @@ int dmg; int spellnum; { if (dmg == 0 && !is_undirected_spell(AD_SPEL, spellnum)) { - impossible("cast directed wizard spell (%d) with dmg=0?", spellnum); - return; + impossible("cast directed wizard spell (%d) with dmg=0?", spellnum); + return; } switch (spellnum) { case MGC_DEATH_TOUCH: - pline("Oh no, %s's using the touch of death!", mhe(mtmp)); - if (nonliving(youmonst.data) || is_demon(youmonst.data)) { - You("seem no deader than before."); - } else if (!Antimagic && rn2(mtmp->m_lev) > 12) { - if (Hallucination) { - You("have an out of body experience."); - } else { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "touch of death"); - done(DIED); - } - } else { - if (Antimagic) shieldeff(u.ux, u.uy); - pline("Lucky for you, it didn't work!"); - } - dmg = 0; - break; + pline("Oh no, %s's using the touch of death!", mhe(mtmp)); + if (nonliving(youmonst.data) || is_demon(youmonst.data)) { + You("seem no deader than before."); + } else if (!Antimagic && rn2(mtmp->m_lev) > 12) { + if (Hallucination) { + You("have an out of body experience."); + } else { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "touch of death"); + done(DIED); + } + } else { + if (Antimagic) + shieldeff(u.ux, u.uy); + pline("Lucky for you, it didn't work!"); + } + dmg = 0; + break; case MGC_CLONE_WIZ: - if (mtmp->iswiz && context.no_of_wizards == 1) { - pline("Double Trouble..."); - clonewiz(); - dmg = 0; - } else - impossible("bad wizard cloning?"); - break; - case MGC_SUMMON_MONS: - { - int count; + if (mtmp->iswiz && context.no_of_wizards == 1) { + pline("Double Trouble..."); + clonewiz(); + dmg = 0; + } else + impossible("bad wizard cloning?"); + break; + case MGC_SUMMON_MONS: { + int count; - count = nasty(mtmp); /* summon something nasty */ - if (mtmp->iswiz) - verbalize("Destroy the thief, my pet%s!", plur(count)); - else { - const char *mappear = - (count == 1) ? "A monster appears" : "Monsters appear"; + count = nasty(mtmp); /* summon something nasty */ + if (mtmp->iswiz) + verbalize("Destroy the thief, my pet%s!", plur(count)); + else { + const char *mappear = + (count == 1) ? "A monster appears" : "Monsters appear"; - /* messages not quite right if plural monsters created but - only a single monster is seen */ - if (Invisible && !perceives(mtmp->data) && - (mtmp->mux != u.ux || mtmp->muy != u.uy)) - pline("%s around a spot near you!", mappear); - else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) - pline("%s around your displaced image!", mappear); - else - pline("%s from nowhere!", mappear); - } - dmg = 0; - break; + /* messages not quite right if plural monsters created but + only a single monster is seen */ + if (Invisible && !perceives(mtmp->data) + && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + pline("%s around a spot near you!", mappear); + else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + pline("%s around your displaced image!", mappear); + else + pline("%s from nowhere!", mappear); + } + dmg = 0; + break; } case MGC_AGGRAVATION: - You_feel("that monsters are aware of your presence."); - aggravate(); - dmg = 0; - break; + You_feel("that monsters are aware of your presence."); + aggravate(); + dmg = 0; + break; case MGC_CURSE_ITEMS: - You_feel("as if you need some help."); - rndcurse(); - dmg = 0; - break; + You_feel("as if you need some help."); + rndcurse(); + dmg = 0; + break; case MGC_DESTRY_ARMR: - if (Antimagic) { - shieldeff(u.ux, u.uy); - pline("A field of force surrounds you!"); - } else if (!destroy_arm(some_armor(&youmonst))) { - Your("skin itches."); - } - dmg = 0; - break; - case MGC_WEAKEN_YOU: /* drain strength */ - if (Antimagic) { - shieldeff(u.ux, u.uy); - You_feel("momentarily weakened."); - } else { - You("suddenly feel weaker!"); - dmg = mtmp->m_lev - 6; - if (Half_spell_damage) dmg = (dmg + 1) / 2; - losestr(rnd(dmg)); - if (u.uhp < 1) - done_in_by(mtmp, DIED); - } - dmg = 0; - break; - case MGC_DISAPPEAR: /* makes self invisible */ - if (!mtmp->minvis && !mtmp->invis_blkd) { - if (canseemon(mtmp)) - pline("%s suddenly %s!", Monnam(mtmp), - !See_invisible ? "disappears" : "becomes transparent"); - mon_set_minvis(mtmp); - dmg = 0; - } else - impossible("no reason for monster to cast disappear spell?"); - break; + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline("A field of force surrounds you!"); + } else if (!destroy_arm(some_armor(&youmonst))) { + Your("skin itches."); + } + dmg = 0; + break; + case MGC_WEAKEN_YOU: /* drain strength */ + if (Antimagic) { + shieldeff(u.ux, u.uy); + You_feel("momentarily weakened."); + } else { + You("suddenly feel weaker!"); + dmg = mtmp->m_lev - 6; + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + losestr(rnd(dmg)); + if (u.uhp < 1) + done_in_by(mtmp, DIED); + } + dmg = 0; + break; + case MGC_DISAPPEAR: /* makes self invisible */ + if (!mtmp->minvis && !mtmp->invis_blkd) { + if (canseemon(mtmp)) + pline("%s suddenly %s!", Monnam(mtmp), + !See_invisible ? "disappears" : "becomes transparent"); + mon_set_minvis(mtmp); + dmg = 0; + } else + impossible("no reason for monster to cast disappear spell?"); + break; case MGC_STUN_YOU: - if (Antimagic || Free_action) { - shieldeff(u.ux, u.uy); - if (!Stunned) - You_feel("momentarily disoriented."); - make_stunned(1L, FALSE); - } else { - You(Stunned ? "struggle to keep your balance." : "reel..."); - dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4); - if (Half_spell_damage) dmg = (dmg + 1) / 2; - make_stunned((HStun & TIMEOUT) + (long)dmg, FALSE); - } - dmg = 0; - break; + if (Antimagic || Free_action) { + shieldeff(u.ux, u.uy); + if (!Stunned) + You_feel("momentarily disoriented."); + make_stunned(1L, FALSE); + } else { + You(Stunned ? "struggle to keep your balance." : "reel..."); + dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4); + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + make_stunned((HStun & TIMEOUT) + (long) dmg, FALSE); + } + dmg = 0; + break; case MGC_HASTE_SELF: - mon_adjust_speed(mtmp, 1, (struct obj *)0); - dmg = 0; - break; + mon_adjust_speed(mtmp, 1, (struct obj *) 0); + dmg = 0; + break; case MGC_CURE_SELF: - if (mtmp->mhp < mtmp->mhpmax) { - if (canseemon(mtmp)) - pline("%s looks better.", Monnam(mtmp)); - /* note: player healing does 6d4; this used to do 1d8 */ - if ((mtmp->mhp += d(3,6)) > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - dmg = 0; - } - break; + if (mtmp->mhp < mtmp->mhpmax) { + if (canseemon(mtmp)) + pline("%s looks better.", Monnam(mtmp)); + /* note: player healing does 6d4; this used to do 1d8 */ + if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + dmg = 0; + } + break; case MGC_PSI_BOLT: - /* prior to 3.4.0 Antimagic was setting the damage to 1--this - made the spell virtually harmless to players with magic res. */ - if (Antimagic) { - shieldeff(u.ux, u.uy); - dmg = (dmg + 1) / 2; - } - if (dmg <= 5) - You("get a slight %sache.", body_part(HEAD)); - else if (dmg <= 10) - Your("brain is on fire!"); - else if (dmg <= 20) - Your("%s suddenly aches painfully!", body_part(HEAD)); - else - Your("%s suddenly aches very painfully!", body_part(HEAD)); - break; + /* prior to 3.4.0 Antimagic was setting the damage to 1--this + made the spell virtually harmless to players with magic res. */ + if (Antimagic) { + shieldeff(u.ux, u.uy); + dmg = (dmg + 1) / 2; + } + if (dmg <= 5) + You("get a slight %sache.", body_part(HEAD)); + else if (dmg <= 10) + Your("brain is on fire!"); + else if (dmg <= 20) + Your("%s suddenly aches painfully!", body_part(HEAD)); + else + Your("%s suddenly aches very painfully!", body_part(HEAD)); + break; default: - impossible("mcastu: invalid magic spell (%d)", spellnum); - dmg = 0; - break; + impossible("mcastu: invalid magic spell (%d)", spellnum); + dmg = 0; + break; } - if (dmg) mdamageu(mtmp, dmg); + if (dmg) + mdamageu(mtmp, dmg); } STATIC_OVL @@ -493,207 +512,215 @@ int dmg; int spellnum; { if (dmg == 0 && !is_undirected_spell(AD_CLRC, spellnum)) { - impossible("cast directed cleric spell (%d) with dmg=0?", spellnum); - return; + impossible("cast directed cleric spell (%d) with dmg=0?", spellnum); + return; } switch (spellnum) { case CLC_GEYSER: - /* this is physical damage (force not heat), - * not magical damage or fire damage - */ - pline("A sudden geyser slams into you from nowhere!"); - dmg = d(8, 6); - if (Half_physical_damage) dmg = (dmg + 1) / 2; - break; + /* this is physical damage (force not heat), + * not magical damage or fire damage + */ + pline("A sudden geyser slams into you from nowhere!"); + dmg = d(8, 6); + if (Half_physical_damage) + dmg = (dmg + 1) / 2; + break; case CLC_FIRE_PILLAR: - pline("A pillar of fire strikes all around you!"); - if (Fire_resistance) { - shieldeff(u.ux, u.uy); - dmg = 0; - } else - dmg = d(8, 6); - if (Half_spell_damage) dmg = (dmg + 1) / 2; - burn_away_slime(); - (void) burnarmor(&youmonst); - destroy_item(SCROLL_CLASS, AD_FIRE); - destroy_item(POTION_CLASS, AD_FIRE); - destroy_item(SPBOOK_CLASS, AD_FIRE); - (void) burn_floor_objects(u.ux, u.uy, TRUE, FALSE); - break; - case CLC_LIGHTNING: - { - boolean reflects; + pline("A pillar of fire strikes all around you!"); + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + dmg = 0; + } else + dmg = d(8, 6); + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + burn_away_slime(); + (void) burnarmor(&youmonst); + destroy_item(SCROLL_CLASS, AD_FIRE); + destroy_item(POTION_CLASS, AD_FIRE); + destroy_item(SPBOOK_CLASS, AD_FIRE); + (void) burn_floor_objects(u.ux, u.uy, TRUE, FALSE); + break; + case CLC_LIGHTNING: { + boolean reflects; - pline("A bolt of lightning strikes down at you from above!"); - reflects = ureflects("It bounces off your %s%s.", ""); - if (reflects || Shock_resistance) { - shieldeff(u.ux, u.uy); - dmg = 0; - if (reflects) - break; - } else - dmg = d(8, 6); - if (Half_spell_damage) dmg = (dmg + 1) / 2; - destroy_item(WAND_CLASS, AD_ELEC); - destroy_item(RING_CLASS, AD_ELEC); - (void) flashburn((long)rnd(100)); - break; + pline("A bolt of lightning strikes down at you from above!"); + reflects = ureflects("It bounces off your %s%s.", ""); + if (reflects || Shock_resistance) { + shieldeff(u.ux, u.uy); + dmg = 0; + if (reflects) + break; + } else + dmg = d(8, 6); + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + destroy_item(WAND_CLASS, AD_ELEC); + destroy_item(RING_CLASS, AD_ELEC); + (void) flashburn((long) rnd(100)); + break; } case CLC_CURSE_ITEMS: - You_feel("as if you need some help."); - rndcurse(); - dmg = 0; - break; - case CLC_INSECTS: - { - /* Try for insects, and if there are none - left, go for (sticks to) snakes. -3. */ - struct permonst *pm = mkclass(S_ANT,0); - struct monst *mtmp2 = (struct monst *)0; - char let = (pm ? S_ANT : S_SNAKE); - boolean success = FALSE, seecaster; - int i, quan, oldseen, newseen; - coord bypos; - const char *fmt; + You_feel("as if you need some help."); + rndcurse(); + dmg = 0; + break; + case CLC_INSECTS: { + /* Try for insects, and if there are none + left, go for (sticks to) snakes. -3. */ + struct permonst *pm = mkclass(S_ANT, 0); + struct monst *mtmp2 = (struct monst *) 0; + char let = (pm ? S_ANT : S_SNAKE); + boolean success = FALSE, seecaster; + int i, quan, oldseen, newseen; + coord bypos; + const char *fmt; - oldseen = monster_census(TRUE); - quan = (mtmp->m_lev < 2) ? 1 : rnd((int)mtmp->m_lev / 2); - if (quan < 3) quan = 3; - for (i = 0; i <= quan; i++) { - if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data)) - break; - if ((pm = mkclass(let,0)) != 0 && - (mtmp2 = makemon(pm, bypos.x, bypos.y, MM_ANGRY)) != 0) { - success = TRUE; - mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0; - set_malign(mtmp2); - } - } - newseen = monster_census(TRUE); + oldseen = monster_census(TRUE); + quan = (mtmp->m_lev < 2) ? 1 : rnd((int) mtmp->m_lev / 2); + if (quan < 3) + quan = 3; + for (i = 0; i <= quan; i++) { + if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data)) + break; + if ((pm = mkclass(let, 0)) != 0 + && (mtmp2 = makemon(pm, bypos.x, bypos.y, MM_ANGRY)) != 0) { + success = TRUE; + mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0; + set_malign(mtmp2); + } + } + newseen = monster_census(TRUE); - /* not canspotmon(), which includes unseen things sensed via warning */ - seecaster = canseemon(mtmp) || tp_sensemon(mtmp) || Detect_monsters; + /* not canspotmon(), which includes unseen things sensed via warning + */ + seecaster = canseemon(mtmp) || tp_sensemon(mtmp) || Detect_monsters; - fmt = 0; - if (!seecaster) { - char *arg; /* [not const: upstart(N==1 ? an() : makeplural())] */ - const char *what = (let == S_SNAKE) ? "snake" : "insect"; + fmt = 0; + if (!seecaster) { + char *arg; /* [not const: upstart(N==1 ? an() : makeplural())] */ + const char *what = (let == S_SNAKE) ? "snake" : "insect"; - if (newseen <= oldseen || Unaware) { - /* unseen caster fails or summons unseen critters, - or unconscious hero ("You dream that you hear...") */ - You_hear("someone summoning %s.", makeplural(what)); - } else { - /* unseen caster summoned seen critter(s) */ - arg = (newseen == oldseen + 1) ? an(what) : makeplural(what); - if (!Deaf) - You_hear("someone summoning something, and %s %s.", - arg, vtense(arg, "appear")); - else - pline("%s %s.", upstart(arg), vtense(arg, "appear")); - } + if (newseen <= oldseen || Unaware) { + /* unseen caster fails or summons unseen critters, + or unconscious hero ("You dream that you hear...") */ + You_hear("someone summoning %s.", makeplural(what)); + } else { + /* unseen caster summoned seen critter(s) */ + arg = (newseen == oldseen + 1) ? an(what) : makeplural(what); + if (!Deaf) + You_hear("someone summoning something, and %s %s.", arg, + vtense(arg, "appear")); + else + pline("%s %s.", upstart(arg), vtense(arg, "appear")); + } - /* seen caster, possibly producing unseen--or just one--critters; - hero is told what the caster is doing and doesn't necessarily - observe complete accuracy of that caster's results (in other - words, no need to fuss with visibility or singularization; - player is told what's happening even if hero is unconscious) */ - } else if (!success) - fmt = "%s casts at a clump of sticks, but nothing happens."; - else if (let == S_SNAKE) - fmt = "%s transforms a clump of sticks into snakes!"; - else if (Invisible && !perceives(mtmp->data) && - (mtmp->mux != u.ux || mtmp->muy != u.uy)) - fmt = "%s summons insects around a spot near you!"; - else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) - fmt = "%s summons insects around your displaced image!"; - else - fmt = "%s summons insects!"; - if (fmt) pline(fmt, Monnam(mtmp)); + /* seen caster, possibly producing unseen--or just one--critters; + hero is told what the caster is doing and doesn't necessarily + observe complete accuracy of that caster's results (in other + words, no need to fuss with visibility or singularization; + player is told what's happening even if hero is unconscious) */ + } else if (!success) + fmt = "%s casts at a clump of sticks, but nothing happens."; + else if (let == S_SNAKE) + fmt = "%s transforms a clump of sticks into snakes!"; + else if (Invisible && !perceives(mtmp->data) + && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + fmt = "%s summons insects around a spot near you!"; + else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) + fmt = "%s summons insects around your displaced image!"; + else + fmt = "%s summons insects!"; + if (fmt) + pline(fmt, Monnam(mtmp)); - dmg = 0; - break; - } + dmg = 0; + break; + } case CLC_BLIND_YOU: - /* note: resists_blnd() doesn't apply here */ - if (!Blinded) { - int num_eyes = eyecount(youmonst.data); - pline("Scales cover your %s!", - (num_eyes == 1) ? - body_part(EYE) : makeplural(body_part(EYE))); - make_blinded(Half_spell_damage ? 100L : 200L, FALSE); - if (!Blind) Your1(vision_clears); - dmg = 0; - } else - impossible("no reason for monster to cast blindness spell?"); - break; + /* note: resists_blnd() doesn't apply here */ + if (!Blinded) { + int num_eyes = eyecount(youmonst.data); + pline("Scales cover your %s!", (num_eyes == 1) + ? body_part(EYE) + : makeplural(body_part(EYE))); + make_blinded(Half_spell_damage ? 100L : 200L, FALSE); + if (!Blind) + Your1(vision_clears); + dmg = 0; + } else + impossible("no reason for monster to cast blindness spell?"); + break; case CLC_PARALYZE: - if (Antimagic || Free_action) { - shieldeff(u.ux, u.uy); - if (multi >= 0) - You("stiffen briefly."); - nomul(-1); - multi_reason = "paralyzed by a monster"; - } else { - if (multi >= 0) - You("are frozen in place!"); - dmg = 4 + (int)mtmp->m_lev; - if (Half_spell_damage) dmg = (dmg + 1) / 2; - nomul(-dmg); - multi_reason = "paralyzed by a monster"; - } - nomovemsg = 0; - dmg = 0; - break; + if (Antimagic || Free_action) { + shieldeff(u.ux, u.uy); + if (multi >= 0) + You("stiffen briefly."); + nomul(-1); + multi_reason = "paralyzed by a monster"; + } else { + if (multi >= 0) + You("are frozen in place!"); + dmg = 4 + (int) mtmp->m_lev; + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + nomul(-dmg); + multi_reason = "paralyzed by a monster"; + } + nomovemsg = 0; + dmg = 0; + break; case CLC_CONFUSE_YOU: - if (Antimagic) { - shieldeff(u.ux, u.uy); - You_feel("momentarily dizzy."); - } else { - boolean oldprop = !!Confusion; + if (Antimagic) { + shieldeff(u.ux, u.uy); + You_feel("momentarily dizzy."); + } else { + boolean oldprop = !!Confusion; - dmg = (int)mtmp->m_lev; - if (Half_spell_damage) dmg = (dmg + 1) / 2; - make_confused(HConfusion + dmg, TRUE); - if (Hallucination) - You_feel("%s!", oldprop ? "trippier" : "trippy"); - else - You_feel("%sconfused!", oldprop ? "more " : ""); - } - dmg = 0; - break; + dmg = (int) mtmp->m_lev; + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + make_confused(HConfusion + dmg, TRUE); + if (Hallucination) + You_feel("%s!", oldprop ? "trippier" : "trippy"); + else + You_feel("%sconfused!", oldprop ? "more " : ""); + } + dmg = 0; + break; case CLC_CURE_SELF: - if (mtmp->mhp < mtmp->mhpmax) { - if (canseemon(mtmp)) - pline("%s looks better.", Monnam(mtmp)); - /* note: player healing does 6d4; this used to do 1d8 */ - if ((mtmp->mhp += d(3,6)) > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - dmg = 0; - } - break; + if (mtmp->mhp < mtmp->mhpmax) { + if (canseemon(mtmp)) + pline("%s looks better.", Monnam(mtmp)); + /* note: player healing does 6d4; this used to do 1d8 */ + if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + dmg = 0; + } + break; case CLC_OPEN_WOUNDS: - if (Antimagic) { - shieldeff(u.ux, u.uy); - dmg = (dmg + 1) / 2; - } - if (dmg <= 5) - Your("skin itches badly for a moment."); - else if (dmg <= 10) - pline("Wounds appear on your body!"); - else if (dmg <= 20) - pline("Severe wounds appear on your body!"); - else - Your("body is covered with painful wounds!"); - break; + if (Antimagic) { + shieldeff(u.ux, u.uy); + dmg = (dmg + 1) / 2; + } + if (dmg <= 5) + Your("skin itches badly for a moment."); + else if (dmg <= 10) + pline("Wounds appear on your body!"); + else if (dmg <= 20) + pline("Severe wounds appear on your body!"); + else + Your("body is covered with painful wounds!"); + break; default: - impossible("mcastu: invalid clerical spell (%d)", spellnum); - dmg = 0; - break; + impossible("mcastu: invalid clerical spell (%d)", spellnum); + dmg = 0; + break; } - if (dmg) mdamageu(mtmp, dmg); + if (dmg) + mdamageu(mtmp, dmg); } STATIC_DCL @@ -703,25 +730,25 @@ unsigned int adtyp; int spellnum; { if (adtyp == AD_SPEL) { - switch (spellnum) { - case MGC_CLONE_WIZ: - case MGC_SUMMON_MONS: - case MGC_AGGRAVATION: - case MGC_DISAPPEAR: - case MGC_HASTE_SELF: - case MGC_CURE_SELF: - return TRUE; - default: - break; - } + switch (spellnum) { + case MGC_CLONE_WIZ: + case MGC_SUMMON_MONS: + case MGC_AGGRAVATION: + case MGC_DISAPPEAR: + case MGC_HASTE_SELF: + case MGC_CURE_SELF: + return TRUE; + default: + break; + } } else if (adtyp == AD_CLRC) { - switch (spellnum) { - case CLC_INSECTS: - case CLC_CURE_SELF: - return TRUE; - default: - break; - } + switch (spellnum) { + case CLC_INSECTS: + case CLC_CURE_SELF: + return TRUE; + default: + break; + } } return FALSE; } @@ -743,92 +770,98 @@ int spellnum; boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my); if (adtyp == AD_SPEL) { - /* aggravate monsters, etc. won't be cast by peaceful monsters */ - if (mtmp->mpeaceful && (spellnum == MGC_AGGRAVATION || - spellnum == MGC_SUMMON_MONS || spellnum == MGC_CLONE_WIZ)) - return TRUE; - /* haste self when already fast */ - if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF) - return TRUE; - /* invisibility when already invisible */ - if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR) - return TRUE; - /* peaceful monster won't cast invisibility if you can't see invisible, - same as when monsters drink potions of invisibility. This doesn't - really make a lot of sense, but lets the player avoid hitting - peaceful monsters by mistake */ - if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR) - return TRUE; - /* healing when already healed */ - if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF) - return TRUE; - /* don't summon monsters if it doesn't think you're around */ - if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS || - (!mtmp->iswiz && spellnum == MGC_CLONE_WIZ))) - return TRUE; - if ((!mtmp->iswiz || context.no_of_wizards > 1) - && spellnum == MGC_CLONE_WIZ) - return TRUE; - /* aggravation (global wakeup) when everyone is already active */ - if (spellnum == MGC_AGGRAVATION) { - struct monst *nxtmon; + /* aggravate monsters, etc. won't be cast by peaceful monsters */ + if (mtmp->mpeaceful + && (spellnum == MGC_AGGRAVATION || spellnum == MGC_SUMMON_MONS + || spellnum == MGC_CLONE_WIZ)) + return TRUE; + /* haste self when already fast */ + if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF) + return TRUE; + /* invisibility when already invisible */ + if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR) + return TRUE; + /* peaceful monster won't cast invisibility if you can't see + invisible, + same as when monsters drink potions of invisibility. This doesn't + really make a lot of sense, but lets the player avoid hitting + peaceful monsters by mistake */ + if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR) + return TRUE; + /* healing when already healed */ + if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF) + return TRUE; + /* don't summon monsters if it doesn't think you're around */ + if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS + || (!mtmp->iswiz && spellnum == MGC_CLONE_WIZ))) + return TRUE; + if ((!mtmp->iswiz || context.no_of_wizards > 1) + && spellnum == MGC_CLONE_WIZ) + return TRUE; + /* aggravation (global wakeup) when everyone is already active */ + if (spellnum == MGC_AGGRAVATION) { + struct monst *nxtmon; - for (nxtmon = fmon; nxtmon; nxtmon = nxtmon->nmon) { - if (DEADMONSTER(nxtmon)) continue; - if ((nxtmon->mstrategy & STRAT_WAITFORU) != 0 || - nxtmon->msleeping || !nxtmon->mcanmove) break; - } - /* if nothing needs to be awakened then this spell is useless - but caster might not realize that [chance to pick it then - must be very small otherwise caller's many retry attempts - will eventually end up picking it too often] */ - if (!nxtmon) return rn2(100) ? TRUE : FALSE; - } + for (nxtmon = fmon; nxtmon; nxtmon = nxtmon->nmon) { + if (DEADMONSTER(nxtmon)) + continue; + if ((nxtmon->mstrategy & STRAT_WAITFORU) != 0 + || nxtmon->msleeping || !nxtmon->mcanmove) + break; + } + /* if nothing needs to be awakened then this spell is useless + but caster might not realize that [chance to pick it then + must be very small otherwise caller's many retry attempts + will eventually end up picking it too often] */ + if (!nxtmon) + return rn2(100) ? TRUE : FALSE; + } } else if (adtyp == AD_CLRC) { - /* summon insects/sticks to snakes won't be cast by peaceful monsters */ - if (mtmp->mpeaceful && spellnum == CLC_INSECTS) - return TRUE; - /* healing when already healed */ - if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF) - return TRUE; - /* don't summon insects if it doesn't think you're around */ - if (!mcouldseeu && spellnum == CLC_INSECTS) - return TRUE; - /* blindness spell on blinded player */ - if (Blinded && spellnum == CLC_BLIND_YOU) - return TRUE; + /* summon insects/sticks to snakes won't be cast by peaceful monsters + */ + if (mtmp->mpeaceful && spellnum == CLC_INSECTS) + return TRUE; + /* healing when already healed */ + if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF) + return TRUE; + /* don't summon insects if it doesn't think you're around */ + if (!mcouldseeu && spellnum == CLC_INSECTS) + return TRUE; + /* blindness spell on blinded player */ + if (Blinded && spellnum == CLC_BLIND_YOU) + return TRUE; } return FALSE; } /* convert 1..10 to 0..9; add 10 for second group (spell casting) */ -#define ad_to_typ(k) (10 + (int)k - 1) +#define ad_to_typ(k) (10 + (int) k - 1) -int -buzzmu(mtmp, mattk) /* monster uses spell (ranged) */ - register struct monst *mtmp; - register struct attack *mattk; +int buzzmu(mtmp, mattk) /* monster uses spell (ranged) */ +register struct monst *mtmp; +register struct attack *mattk; { - /* don't print constant stream of curse messages for 'normal' - spellcasting monsters at range */ - if (mattk->adtyp > AD_SPC2) - return(0); + /* don't print constant stream of curse messages for 'normal' + spellcasting monsters at range */ + if (mattk->adtyp > AD_SPC2) + return (0); - if (mtmp->mcan) { - cursetxt(mtmp, FALSE); - return(0); - } - if(lined_up(mtmp) && rn2(3)) { - nomul(0); - if(mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */ - if(canseemon(mtmp)) - pline("%s zaps you with a %s!", Monnam(mtmp), - flash_types[ad_to_typ(mattk->adtyp)]); - buzz(-ad_to_typ(mattk->adtyp), (int)mattk->damn, - mtmp->mx, mtmp->my, sgn(tbx), sgn(tby)); - } else impossible("Monster spell %d cast", mattk->adtyp-1); - } - return(1); + if (mtmp->mcan) { + cursetxt(mtmp, FALSE); + return (0); + } + if (lined_up(mtmp) && rn2(3)) { + nomul(0); + if (mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */ + if (canseemon(mtmp)) + pline("%s zaps you with a %s!", Monnam(mtmp), + flash_types[ad_to_typ(mattk->adtyp)]); + buzz(-ad_to_typ(mattk->adtyp), (int) mattk->damn, mtmp->mx, + mtmp->my, sgn(tbx), sgn(tby)); + } else + impossible("Monster spell %d cast", mattk->adtyp - 1); + } + return (1); } /*mcastu.c*/ diff --git a/src/mhitm.c b/src/mhitm.c index 32159a9d1..6f061da25 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhitm.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhitm.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.76 $ */ /* NetHack 3.6 mhitm.c $Date: 2011/04/07 20:59:40 $ $Revision: 1.57 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -13,18 +13,26 @@ static NEARDATA long noisetime; static NEARDATA struct obj *otmp; static const char brief_feeling[] = - "have a %s feeling for a moment, then it passes."; + "have a %s feeling for a moment, then it passes."; -STATIC_DCL char *FDECL(mon_nam_too, (char *,struct monst *,struct monst *)); -STATIC_DCL int FDECL(hitmm, (struct monst *,struct monst *,struct attack *)); -STATIC_DCL int FDECL(gazemm, (struct monst *,struct monst *,struct attack *)); -STATIC_DCL int FDECL(gulpmm, (struct monst *,struct monst *,struct attack *)); -STATIC_DCL int FDECL(explmm, (struct monst *,struct monst *,struct attack *)); -STATIC_DCL int FDECL(mdamagem, (struct monst *,struct monst *,struct attack *)); -STATIC_DCL void FDECL(mswingsm, (struct monst *, struct monst *, struct obj *)); -STATIC_DCL void FDECL(noises,(struct monst *,struct attack *)); -STATIC_DCL void FDECL(missmm,(struct monst *,struct monst *,struct attack *)); -STATIC_DCL int FDECL(passivemm, (struct monst *, struct monst *, BOOLEAN_P, int)); +STATIC_DCL char *FDECL(mon_nam_too, (char *, struct monst *, struct monst *)); +STATIC_DCL int FDECL(hitmm, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL int FDECL(gazemm, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL int FDECL(gulpmm, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL int FDECL(explmm, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL int FDECL(mdamagem, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL void FDECL(mswingsm, + (struct monst *, struct monst *, struct obj *)); +STATIC_DCL void FDECL(noises, (struct monst *, struct attack *)); +STATIC_DCL void FDECL(missmm, + (struct monst *, struct monst *, struct attack *)); +STATIC_DCL int FDECL(passivemm, + (struct monst *, struct monst *, BOOLEAN_P, int)); /* Needed for the special case of monsters wielding vorpal blades (rare). * If we use this a lot it should probably be a parameter to mdamagem() @@ -39,53 +47,63 @@ mon_nam_too(outbuf, mon, other_mon) char *outbuf; struct monst *mon, *other_mon; { - Strcpy(outbuf, mon_nam(mon)); - if (mon == other_mon) - switch (pronoun_gender(mon)) { - case 0: Strcpy(outbuf, "himself"); break; - case 1: Strcpy(outbuf, "herself"); break; - default: Strcpy(outbuf, "itself"); break; - } - return outbuf; + Strcpy(outbuf, mon_nam(mon)); + if (mon == other_mon) + switch (pronoun_gender(mon)) { + case 0: + Strcpy(outbuf, "himself"); + break; + case 1: + Strcpy(outbuf, "herself"); + break; + default: + Strcpy(outbuf, "itself"); + break; + } + return outbuf; } STATIC_OVL void noises(magr, mattk) - register struct monst *magr; - register struct attack *mattk; +register struct monst *magr; +register struct attack *mattk; { - boolean farq = (distu(magr->mx, magr->my) > 15); + boolean farq = (distu(magr->mx, magr->my) > 15); - if(!Deaf && (farq != far_noise || moves-noisetime > 10)) { - far_noise = farq; - noisetime = moves; - You_hear("%s%s.", - (mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises", - farq ? " in the distance" : ""); - } + if (!Deaf && (farq != far_noise || moves - noisetime > 10)) { + far_noise = farq; + noisetime = moves; + You_hear("%s%s.", + (mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises", + farq ? " in the distance" : ""); + } } STATIC_OVL void missmm(magr, mdef, mattk) - register struct monst *magr, *mdef; - struct attack *mattk; +register struct monst *magr, *mdef; +struct attack *mattk; { - const char *fmt; - char buf[BUFSZ], mdef_name[BUFSZ]; + const char *fmt; + char buf[BUFSZ], mdef_name[BUFSZ]; - if (vis) { - if (!canspotmon(magr)) - map_invisible(magr->mx, magr->my); - if (!canspotmon(mdef)) - map_invisible(mdef->mx, mdef->my); - if (mdef->m_ap_type) seemimic(mdef); - if (magr->m_ap_type) seemimic(magr); - fmt = (could_seduce(magr,mdef,mattk) && !magr->mcan) ? - "%s pretends to be friendly to" : "%s misses"; - Sprintf(buf, fmt, Monnam(magr)); - pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr)); - } else noises(magr, mattk); + if (vis) { + if (!canspotmon(magr)) + map_invisible(magr->mx, magr->my); + if (!canspotmon(mdef)) + map_invisible(mdef->mx, mdef->my); + if (mdef->m_ap_type) + seemimic(mdef); + if (magr->m_ap_type) + seemimic(magr); + fmt = (could_seduce(magr, mdef, mattk) && !magr->mcan) + ? "%s pretends to be friendly to" + : "%s misses"; + Sprintf(buf, fmt, Monnam(magr)); + pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr)); + } else + noises(magr, mattk); } /* @@ -99,72 +117,74 @@ missmm(magr, mdef, mattk) * then we report that the monster did nothing so it will continue to * digest the hero. */ -int -fightm(mtmp) /* have monsters fight each other */ - register struct monst *mtmp; +int fightm(mtmp) /* have monsters fight each other */ +register struct monst *mtmp; { - register struct monst *mon, *nmon; - int result, has_u_swallowed; + register struct monst *mon, *nmon; + int result, has_u_swallowed; #ifdef LINT - nmon = 0; + nmon = 0; #endif - /* perhaps the monster will resist Conflict */ - if(resist(mtmp, RING_CLASS, 0, 0)) - return(0); + /* perhaps the monster will resist Conflict */ + if (resist(mtmp, RING_CLASS, 0, 0)) + return (0); - if(u.ustuck == mtmp) { - /* perhaps we're holding it... */ - if(itsstuck(mtmp)) - return(0); - } - has_u_swallowed = (u.uswallow && (mtmp == u.ustuck)); + if (u.ustuck == mtmp) { + /* perhaps we're holding it... */ + if (itsstuck(mtmp)) + return (0); + } + has_u_swallowed = (u.uswallow && (mtmp == u.ustuck)); - for(mon = fmon; mon; mon = nmon) { - nmon = mon->nmon; - if(nmon == mtmp) nmon = mtmp->nmon; - /* Be careful to ignore monsters that are already dead, since we - * might be calling this before we've cleaned them up. This can - * happen if the monster attacked a cockatrice bare-handedly, for - * instance. - */ - if(mon != mtmp && !DEADMONSTER(mon)) { - if(monnear(mtmp,mon->mx,mon->my)) { - if(!u.uswallow && (mtmp == u.ustuck)) { - if(!rn2(4)) { - pline("%s releases you!", Monnam(mtmp)); - u.ustuck = 0; - } else - break; - } + for (mon = fmon; mon; mon = nmon) { + nmon = mon->nmon; + if (nmon == mtmp) + nmon = mtmp->nmon; + /* Be careful to ignore monsters that are already dead, since we + * might be calling this before we've cleaned them up. This can + * happen if the monster attacked a cockatrice bare-handedly, for + * instance. + */ + if (mon != mtmp && !DEADMONSTER(mon)) { + if (monnear(mtmp, mon->mx, mon->my)) { + if (!u.uswallow && (mtmp == u.ustuck)) { + if (!rn2(4)) { + pline("%s releases you!", Monnam(mtmp)); + u.ustuck = 0; + } else + break; + } - /* mtmp can be killed */ - bhitpos.x = mon->mx; - bhitpos.y = mon->my; - notonhead = 0; - result = mattackm(mtmp,mon); + /* mtmp can be killed */ + bhitpos.x = mon->mx; + bhitpos.y = mon->my; + notonhead = 0; + result = mattackm(mtmp, mon); - if (result & MM_AGR_DIED) return 1; /* mtmp died */ - /* - * If mtmp has the hero swallowed, lie and say there - * was no attack (this allows mtmp to digest the hero). - */ - if (has_u_swallowed) return 0; + if (result & MM_AGR_DIED) + return 1; /* mtmp died */ + /* + * If mtmp has the hero swallowed, lie and say there + * was no attack (this allows mtmp to digest the hero). + */ + if (has_u_swallowed) + return 0; - /* Allow attacked monsters a chance to hit back. Primarily - * to allow monsters that resist conflict to respond. - */ - if ((result & MM_HIT) && !(result & MM_DEF_DIED) && - rn2(4) && mon->movement >= NORMAL_SPEED) { - mon->movement -= NORMAL_SPEED; - notonhead = 0; - (void) mattackm(mon, mtmp); /* return attack */ - } + /* Allow attacked monsters a chance to hit back. Primarily + * to allow monsters that resist conflict to respond. + */ + if ((result & MM_HIT) && !(result & MM_DEF_DIED) && rn2(4) + && mon->movement >= NORMAL_SPEED) { + mon->movement -= NORMAL_SPEED; + notonhead = 0; + (void) mattackm(mon, mtmp); /* return attack */ + } - return ((result & MM_HIT) ? 1 : 0); - } - } - } - return 0; + return ((result & MM_HIT) ? 1 : 0); + } + } + } + return 0; } /* @@ -173,74 +193,78 @@ fightm(mtmp) /* have monsters fight each other */ */ int mdisplacem(magr, mdef, quietly) -register struct monst *magr,*mdef; +register struct monst *magr, *mdef; boolean quietly; { - struct permonst *pa, *pd; - int tx, ty, fx, fy; + struct permonst *pa, *pd; + int tx, ty, fx, fy; - /* sanity checks; could matter if we unexpectedly get a long worm */ - if (!magr || !mdef || magr == mdef) return MM_MISS; - pa = magr->data, pd =mdef->data; - tx = mdef->mx, ty = mdef->my; /* destination */ - fx = magr->mx, fy = magr->my; /* current location */ - if (m_at(fx, fy) != magr || m_at(tx, ty) != mdef) return MM_MISS; + /* sanity checks; could matter if we unexpectedly get a long worm */ + if (!magr || !mdef || magr == mdef) + return MM_MISS; + pa = magr->data, pd = mdef->data; + tx = mdef->mx, ty = mdef->my; /* destination */ + fx = magr->mx, fy = magr->my; /* current location */ + if (m_at(fx, fy) != magr || m_at(tx, ty) != mdef) + return MM_MISS; - /* The 1 in 7 failure below matches the chance in attack() - * for pet displacement. - */ - if (!rn2(7)) return(MM_MISS); + /* The 1 in 7 failure below matches the chance in attack() + * for pet displacement. + */ + if (!rn2(7)) + return (MM_MISS); - /* Grid bugs cannot displace at an angle. */ - if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx - && magr->my != mdef->my) - return(MM_MISS); + /* Grid bugs cannot displace at an angle. */ + if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx + && magr->my != mdef->my) + return (MM_MISS); - /* undetected monster becomes un-hidden if it is displaced */ - if (mdef->mundetected) mdef->mundetected = 0; - if (mdef->m_ap_type && mdef->m_ap_type != M_AP_MONSTER) seemimic(mdef); - /* wake up the displaced defender */ - mdef->msleeping = 0; - mdef->mstrategy &= ~STRAT_WAITMASK; - finish_meating(mdef); + /* undetected monster becomes un-hidden if it is displaced */ + if (mdef->mundetected) + mdef->mundetected = 0; + if (mdef->m_ap_type && mdef->m_ap_type != M_AP_MONSTER) + seemimic(mdef); + /* wake up the displaced defender */ + mdef->msleeping = 0; + mdef->mstrategy &= ~STRAT_WAITMASK; + finish_meating(mdef); - /* - * Set up the visibility of action. - * You can observe monster displacement if you can see both of - * the monsters involved. - */ - vis = (canspotmon(magr) && canspotmon(mdef)); + /* + * Set up the visibility of action. + * You can observe monster displacement if you can see both of + * the monsters involved. + */ + vis = (canspotmon(magr) && canspotmon(mdef)); - if (touch_petrifies(pd) && !resists_ston(magr)) { - if (which_armor(magr, W_ARMG) != 0) { - if (poly_when_stoned(pa)) { - mon_to_stone(magr); - return MM_HIT; /* no damage during the polymorph */ - } - if (!quietly && canspotmon(magr)) - pline("%s turns to stone!", Monnam(magr)); - monstone(magr); - if (magr->mhp > 0) - return MM_HIT; /* lifesaved */ - else if (magr->mtame && !vis) - You(brief_feeling, "peculiarly sad"); - return MM_AGR_DIED; - } - } + if (touch_petrifies(pd) && !resists_ston(magr)) { + if (which_armor(magr, W_ARMG) != 0) { + if (poly_when_stoned(pa)) { + mon_to_stone(magr); + return MM_HIT; /* no damage during the polymorph */ + } + if (!quietly && canspotmon(magr)) + pline("%s turns to stone!", Monnam(magr)); + monstone(magr); + if (magr->mhp > 0) + return MM_HIT; /* lifesaved */ + else if (magr->mtame && !vis) + You(brief_feeling, "peculiarly sad"); + return MM_AGR_DIED; + } + } - remove_monster(fx, fy); /* pick up from orig position */ - remove_monster(tx, ty); - place_monster(magr, tx, ty); /* put down at target spot */ - place_monster(mdef, fx, fy); - if (vis && !quietly) - pline("%s moves %s out of %s way!", - Monnam(magr), mon_nam(mdef), - is_rider(pa) ? "the" : mhis(magr)); - newsym(fx, fy); /* see it */ - newsym(tx, ty); /* all happen */ - flush_screen(0); /* make sure it shows up */ + remove_monster(fx, fy); /* pick up from orig position */ + remove_monster(tx, ty); + place_monster(magr, tx, ty); /* put down at target spot */ + place_monster(mdef, fx, fy); + if (vis && !quietly) + pline("%s moves %s out of %s way!", Monnam(magr), mon_nam(mdef), + is_rider(pa) ? "the" : mhis(magr)); + newsym(fx, fy); /* see it */ + newsym(tx, ty); /* all happen */ + flush_screen(0); /* make sure it shows up */ - return MM_HIT; + return MM_HIT; } /* @@ -257,58 +281,65 @@ boolean quietly; * 0x1 MM_HIT * 0x0 MM_MISS * - * Each successive attack has a lower probability of hitting. Some rely on the + * Each successive attack has a lower probability of hitting. Some rely on + *the * success of previous attacks. ** this doen't seem to be implemented -dl ** * * In the case of exploding monsters, the monster dies as well. */ int mattackm(magr, mdef) - register struct monst *magr,*mdef; +register struct monst *magr, *mdef; { - int i, /* loop counter */ - tmp, /* amour class difference */ - strike, /* hit this attack */ - attk, /* attack attempted this time */ - struck = 0, /* hit at least once */ - res[NATTK]; /* results of all attacks */ - struct attack *mattk, alt_attk; + int i, /* loop counter */ + tmp, /* amour class difference */ + strike, /* hit this attack */ + attk, /* attack attempted this time */ + struck = 0, /* hit at least once */ + res[NATTK]; /* results of all attacks */ + struct attack *mattk, alt_attk; struct permonst *pa, *pd; - if (!magr || !mdef) return(MM_MISS); /* mike@genat */ - if (!magr->mcanmove || magr->msleeping) return(MM_MISS); - pa = magr->data; pd = mdef->data; + if (!magr || !mdef) + return (MM_MISS); /* mike@genat */ + if (!magr->mcanmove || magr->msleeping) + return (MM_MISS); + pa = magr->data; + pd = mdef->data; /* Grid bugs cannot attack at an angle. */ if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx - && magr->my != mdef->my) - return(MM_MISS); + && magr->my != mdef->my) + return (MM_MISS); /* Calculate the armour class differential. */ tmp = find_mac(mdef) + magr->m_lev; if (mdef->mconf || !mdef->mcanmove || mdef->msleeping) { - tmp += 4; - mdef->msleeping = 0; + tmp += 4; + mdef->msleeping = 0; } /* undetect monsters become un-hidden if they are attacked */ if (mdef->mundetected) { - mdef->mundetected = 0; - newsym(mdef->mx, mdef->my); - if(canseemon(mdef) && !sensemon(mdef)) { - if (Unaware) You("dream of %s.", - (mdef->data->geno & G_UNIQ) ? - a_monnam(mdef) : makeplural(m_monnam(mdef))); - else pline("Suddenly, you notice %s.", a_monnam(mdef)); - } + mdef->mundetected = 0; + newsym(mdef->mx, mdef->my); + if (canseemon(mdef) && !sensemon(mdef)) { + if (Unaware) + You("dream of %s.", (mdef->data->geno & G_UNIQ) + ? a_monnam(mdef) + : makeplural(m_monnam(mdef))); + else + pline("Suddenly, you notice %s.", a_monnam(mdef)); + } } /* Elves hate orcs. */ - if (is_elf(pa) && is_orc(pd)) tmp++; - + if (is_elf(pa) && is_orc(pd)) + tmp++; /* Set up the visibility of action */ - vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my) && (canspotmon(magr) || canspotmon(mdef))); + vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my) + && (canspotmon(magr) || canspotmon(mdef))); /* Set flag indicating monster has moved this turn. Necessary since a * monster might get an attack out of sequence (i.e. before its move) in @@ -319,230 +350,241 @@ mattackm(magr, mdef) /* Now perform all attacks for the monster. */ for (i = 0; i < NATTK; i++) { - res[i] = MM_MISS; - mattk = getmattk(pa, i, res, &alt_attk); - otmp = (struct obj *)0; - attk = 1; - switch (mattk->aatyp) { - case AT_WEAP: /* "hand to hand" attacks */ - if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) { - magr->weapon_check = NEED_HTH_WEAPON; - if (mon_wield_item(magr) != 0) return 0; - } - possibly_unwield(magr, FALSE); - otmp = MON_WEP(magr); + res[i] = MM_MISS; + mattk = getmattk(pa, i, res, &alt_attk); + otmp = (struct obj *) 0; + attk = 1; + switch (mattk->aatyp) { + case AT_WEAP: /* "hand to hand" attacks */ + if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) { + magr->weapon_check = NEED_HTH_WEAPON; + if (mon_wield_item(magr) != 0) + return 0; + } + possibly_unwield(magr, FALSE); + otmp = MON_WEP(magr); - if (otmp) { - if (vis) mswingsm(magr, mdef, otmp); - tmp += hitval(otmp, mdef); - } - /* fall through */ - case AT_CLAW: - case AT_KICK: - case AT_BITE: - case AT_STNG: - case AT_TUCH: - case AT_BUTT: - case AT_TENT: - /* Nymph that teleported away on first attack? */ - if (distmin(magr->mx,magr->my,mdef->mx,mdef->my) > 1) - return MM_MISS; - /* Monsters won't attack cockatrices physically if they - * have a weapon instead. This instinct doesn't work for - * players, or under conflict or confusion. - */ - if (!magr->mconf && !Conflict && otmp && - mattk->aatyp != AT_WEAP && touch_petrifies(mdef->data)) { - strike = 0; - break; - } - dieroll = rnd(20 + i); - strike = (tmp > dieroll); - /* KMH -- don't accumulate to-hit bonuses */ - if (otmp) - tmp -= hitval(otmp, mdef); - if (strike) { - res[i] = hitmm(magr, mdef, mattk); - if((mdef->data == &mons[PM_BLACK_PUDDING] || mdef->data == &mons[PM_BROWN_PUDDING]) - && otmp && objects[otmp->otyp].oc_material == IRON - && mdef->mhp > 1 && !mdef->mcan) - { - if (clone_mon(mdef, 0, 0)) { - if (vis) { - char buf[BUFSZ]; + if (otmp) { + if (vis) + mswingsm(magr, mdef, otmp); + tmp += hitval(otmp, mdef); + } + /* fall through */ + case AT_CLAW: + case AT_KICK: + case AT_BITE: + case AT_STNG: + case AT_TUCH: + case AT_BUTT: + case AT_TENT: + /* Nymph that teleported away on first attack? */ + if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1) + return MM_MISS; + /* Monsters won't attack cockatrices physically if they + * have a weapon instead. This instinct doesn't work for + * players, or under conflict or confusion. + */ + if (!magr->mconf && !Conflict && otmp && mattk->aatyp != AT_WEAP + && touch_petrifies(mdef->data)) { + strike = 0; + break; + } + dieroll = rnd(20 + i); + strike = (tmp > dieroll); + /* KMH -- don't accumulate to-hit bonuses */ + if (otmp) + tmp -= hitval(otmp, mdef); + if (strike) { + res[i] = hitmm(magr, mdef, mattk); + if ((mdef->data == &mons[PM_BLACK_PUDDING] + || mdef->data == &mons[PM_BROWN_PUDDING]) && otmp + && objects[otmp->otyp].oc_material == IRON + && mdef->mhp > 1 + && !mdef->mcan) { + if (clone_mon(mdef, 0, 0)) { + if (vis) { + char buf[BUFSZ]; - Strcpy(buf, Monnam(mdef)); - pline("%s divides as %s hits it!", buf, mon_nam(magr)); - } - } - } - } else - missmm(magr, mdef, mattk); - break; + Strcpy(buf, Monnam(mdef)); + pline("%s divides as %s hits it!", buf, + mon_nam(magr)); + } + } + } + } else + missmm(magr, mdef, mattk); + break; - case AT_HUGS: /* automatic if prev two attacks succeed */ - strike = (i >= 2 && res[i-1] == MM_HIT && res[i-2] == MM_HIT); - if (strike) - res[i] = hitmm(magr, mdef, mattk); + case AT_HUGS: /* automatic if prev two attacks succeed */ + strike = (i >= 2 && res[i - 1] == MM_HIT && res[i - 2] == MM_HIT); + if (strike) + res[i] = hitmm(magr, mdef, mattk); - break; + break; - case AT_GAZE: - strike = 0; - res[i] = gazemm(magr, mdef, mattk); - break; + case AT_GAZE: + strike = 0; + res[i] = gazemm(magr, mdef, mattk); + break; - case AT_EXPL: - res[i] = explmm(magr, mdef, mattk); - if (res[i] == MM_MISS) { /* cancelled--no attack */ - strike = 0; - attk = 0; - } else - strike = 1; /* automatic hit */ - break; + case AT_EXPL: + res[i] = explmm(magr, mdef, mattk); + if (res[i] == MM_MISS) { /* cancelled--no attack */ + strike = 0; + attk = 0; + } else + strike = 1; /* automatic hit */ + break; - case AT_ENGL: - if (u.usteed && (mdef == u.usteed)) { - strike = 0; - break; - } - /* Engulfing attacks are directed at the hero if - * possible. -dlc - */ - if (u.uswallow && magr == u.ustuck) - strike = 0; - else { - if ((strike = (tmp > rnd(20+i)))) - res[i] = gulpmm(magr, mdef, mattk); - else - missmm(magr, mdef, mattk); - } - break; + case AT_ENGL: + if (u.usteed && (mdef == u.usteed)) { + strike = 0; + break; + } + /* Engulfing attacks are directed at the hero if + * possible. -dlc + */ + if (u.uswallow && magr == u.ustuck) + strike = 0; + else { + if ((strike = (tmp > rnd(20 + i)))) + res[i] = gulpmm(magr, mdef, mattk); + else + missmm(magr, mdef, mattk); + } + break; - default: /* no attack */ - strike = 0; - attk = 0; - break; - } + default: /* no attack */ + strike = 0; + attk = 0; + break; + } - if (attk && !(res[i] & MM_AGR_DIED)) - res[i] = passivemm(magr, mdef, strike, res[i] & MM_DEF_DIED); + if (attk && !(res[i] & MM_AGR_DIED)) + res[i] = passivemm(magr, mdef, strike, res[i] & MM_DEF_DIED); - if (res[i] & MM_DEF_DIED) return res[i]; + if (res[i] & MM_DEF_DIED) + return res[i]; - if (res[i] & MM_AGR_DIED) return res[i]; - /* return if aggressor can no longer attack */ - if (!magr->mcanmove || magr->msleeping) return res[i]; - if (res[i] & MM_HIT) struck = 1; /* at least one hit */ + if (res[i] & MM_AGR_DIED) + return res[i]; + /* return if aggressor can no longer attack */ + if (!magr->mcanmove || magr->msleeping) + return res[i]; + if (res[i] & MM_HIT) + struck = 1; /* at least one hit */ } - return(struck ? MM_HIT : MM_MISS); + return (struck ? MM_HIT : MM_MISS); } /* Returns the result of mdamagem(). */ STATIC_OVL int hitmm(magr, mdef, mattk) - register struct monst *magr,*mdef; - struct attack *mattk; +register struct monst *magr, *mdef; +struct attack *mattk; { - if(vis){ - int compat; - char buf[BUFSZ], mdef_name[BUFSZ]; + if (vis) { + int compat; + char buf[BUFSZ], mdef_name[BUFSZ]; - if (!canspotmon(magr)) - map_invisible(magr->mx, magr->my); - if (!canspotmon(mdef)) - map_invisible(mdef->mx, mdef->my); - if(mdef->m_ap_type) seemimic(mdef); - if(magr->m_ap_type) seemimic(magr); - if((compat = could_seduce(magr,mdef,mattk)) && !magr->mcan) { - Sprintf(buf, "%s %s", Monnam(magr), - mdef->mcansee ? "smiles at" : "talks to"); - pline("%s %s %s.", buf, mon_nam(mdef), - compat == 2 ? - "engagingly" : "seductively"); - } else { - char magr_name[BUFSZ]; + if (!canspotmon(magr)) + map_invisible(magr->mx, magr->my); + if (!canspotmon(mdef)) + map_invisible(mdef->mx, mdef->my); + if (mdef->m_ap_type) + seemimic(mdef); + if (magr->m_ap_type) + seemimic(magr); + if ((compat = could_seduce(magr, mdef, mattk)) && !magr->mcan) { + Sprintf(buf, "%s %s", Monnam(magr), + mdef->mcansee ? "smiles at" : "talks to"); + pline("%s %s %s.", buf, mon_nam(mdef), + compat == 2 ? "engagingly" : "seductively"); + } else { + char magr_name[BUFSZ]; - Strcpy(magr_name, Monnam(magr)); - switch (mattk->aatyp) { - case AT_BITE: - Sprintf(buf,"%s bites", magr_name); - break; - case AT_STNG: - Sprintf(buf,"%s stings", magr_name); - break; - case AT_BUTT: - Sprintf(buf,"%s butts", magr_name); - break; - case AT_TUCH: - Sprintf(buf,"%s touches", magr_name); - break; - case AT_TENT: - Sprintf(buf, "%s tentacles suck", - s_suffix(magr_name)); - break; - case AT_HUGS: - if (magr != u.ustuck) { - Sprintf(buf,"%s squeezes", magr_name); - break; - } - default: - Sprintf(buf,"%s hits", magr_name); - } - pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr)); - } - } else noises(magr, mattk); - return(mdamagem(magr, mdef, mattk)); + Strcpy(magr_name, Monnam(magr)); + switch (mattk->aatyp) { + case AT_BITE: + Sprintf(buf, "%s bites", magr_name); + break; + case AT_STNG: + Sprintf(buf, "%s stings", magr_name); + break; + case AT_BUTT: + Sprintf(buf, "%s butts", magr_name); + break; + case AT_TUCH: + Sprintf(buf, "%s touches", magr_name); + break; + case AT_TENT: + Sprintf(buf, "%s tentacles suck", s_suffix(magr_name)); + break; + case AT_HUGS: + if (magr != u.ustuck) { + Sprintf(buf, "%s squeezes", magr_name); + break; + } + default: + Sprintf(buf, "%s hits", magr_name); + } + pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr)); + } + } else + noises(magr, mattk); + return (mdamagem(magr, mdef, mattk)); } /* Returns the same values as mdamagem(). */ STATIC_OVL int gazemm(magr, mdef, mattk) - register struct monst *magr, *mdef; - struct attack *mattk; +register struct monst *magr, *mdef; +struct attack *mattk; { - char buf[BUFSZ]; + char buf[BUFSZ]; - if(vis) { - Sprintf(buf,"%s gazes at", Monnam(magr)); - pline("%s %s...", buf, mon_nam(mdef)); - } + if (vis) { + Sprintf(buf, "%s gazes at", Monnam(magr)); + pline("%s %s...", buf, mon_nam(mdef)); + } - if (magr->mcan || !magr->mcansee || - (magr->minvis && !perceives(mdef->data)) || - !mdef->mcansee || mdef->msleeping) { - if(vis) pline("but nothing happens."); - return(MM_MISS); - } - /* call mon_reflects 2x, first test, then, if visible, print message */ - if (magr->data == &mons[PM_MEDUSA] && mon_reflects(mdef, (char *)0)) { - if (canseemon(mdef)) - (void) mon_reflects(mdef, - "The gaze is reflected away by %s %s."); - if (mdef->mcansee) { - if (mon_reflects(magr, (char *)0)) { - if (canseemon(magr)) - (void) mon_reflects(magr, - "The gaze is reflected away by %s %s."); - return (MM_MISS); - } - if (mdef->minvis && !perceives(magr->data)) { - if (canseemon(magr)) { - pline("%s doesn't seem to notice that %s gaze was reflected.", - Monnam(magr), mhis(magr)); - } - return (MM_MISS); - } - if (canseemon(magr)) - pline("%s is turned to stone!", Monnam(magr)); - monstone(magr); - if (magr->mhp > 0) return (MM_MISS); - return (MM_AGR_DIED); - } - } + if (magr->mcan || !magr->mcansee + || (magr->minvis && !perceives(mdef->data)) || !mdef->mcansee + || mdef->msleeping) { + if (vis) + pline("but nothing happens."); + return (MM_MISS); + } + /* call mon_reflects 2x, first test, then, if visible, print message */ + if (magr->data == &mons[PM_MEDUSA] && mon_reflects(mdef, (char *) 0)) { + if (canseemon(mdef)) + (void) mon_reflects(mdef, "The gaze is reflected away by %s %s."); + if (mdef->mcansee) { + if (mon_reflects(magr, (char *) 0)) { + if (canseemon(magr)) + (void) mon_reflects( + magr, "The gaze is reflected away by %s %s."); + return (MM_MISS); + } + if (mdef->minvis && !perceives(magr->data)) { + if (canseemon(magr)) { + pline("%s doesn't seem to notice that %s gaze was " + "reflected.", + Monnam(magr), mhis(magr)); + } + return (MM_MISS); + } + if (canseemon(magr)) + pline("%s is turned to stone!", Monnam(magr)); + monstone(magr); + if (magr->mhp > 0) + return (MM_MISS); + return (MM_AGR_DIED); + } + } - return(mdamagem(magr, mdef, mattk)); + return (mdamagem(magr, mdef, mattk)); } /* return True if magr is allowed to swallow mdef, False otherwise */ @@ -550,127 +592,132 @@ boolean engulf_target(magr, mdef) struct monst *magr, *mdef; { - struct rm *lev; - int dx, dy; + struct rm *lev; + int dx, dy; - /* can't swallow something that's too big */ - if (mdef->data->msize >= MZ_HUGE) - return FALSE; + /* can't swallow something that's too big */ + if (mdef->data->msize >= MZ_HUGE) + return FALSE; - /* (hypothetical) engulfers who can pass through walls aren't - limited by rock|trees|bars */ - if ((magr == &youmonst) ? Passes_walls : passes_walls(magr->data)) - return TRUE; + /* (hypothetical) engulfers who can pass through walls aren't + limited by rock|trees|bars */ + if ((magr == &youmonst) ? Passes_walls : passes_walls(magr->data)) + return TRUE; - /* don't swallow something in a spot where attacker wouldn't - otherwise be able to move onto; we don't want to engulf - a wall-phaser and end up with a non-phaser inside a wall */ - dx = mdef->mx, dy = mdef->my; - if (mdef == &youmonst) dx = u.ux, dy = u.uy; - lev = &levl[dx][dy]; - if (IS_ROCK(lev->typ) || closed_door(dx, dy) || IS_TREE(lev->typ) || - /* not passes_bars(); engulfer isn't squeezing through */ - (lev->typ == IRONBARS && !is_whirly(magr->data))) - return FALSE; + /* don't swallow something in a spot where attacker wouldn't + otherwise be able to move onto; we don't want to engulf + a wall-phaser and end up with a non-phaser inside a wall */ + dx = mdef->mx, dy = mdef->my; + if (mdef == &youmonst) + dx = u.ux, dy = u.uy; + lev = &levl[dx][dy]; + if (IS_ROCK(lev->typ) || closed_door(dx, dy) || IS_TREE(lev->typ) || + /* not passes_bars(); engulfer isn't squeezing through */ + (lev->typ == IRONBARS && !is_whirly(magr->data))) + return FALSE; - return TRUE; + return TRUE; } /* Returns the same values as mattackm(). */ STATIC_OVL int gulpmm(magr, mdef, mattk) - register struct monst *magr, *mdef; - register struct attack *mattk; +register struct monst *magr, *mdef; +register struct attack *mattk; { - xchar ax, ay, dx, dy; - int status; - char buf[BUFSZ]; - struct obj *obj; + xchar ax, ay, dx, dy; + int status; + char buf[BUFSZ]; + struct obj *obj; - if (!engulf_target(magr, mdef)) return MM_MISS; + if (!engulf_target(magr, mdef)) + return MM_MISS; - if (vis) { - Sprintf(buf,"%s swallows", Monnam(magr)); - pline("%s %s.", buf, mon_nam(mdef)); - } - for (obj = mdef->minvent; obj; obj = obj->nobj) - (void) snuff_lit(obj); + if (vis) { + Sprintf(buf, "%s swallows", Monnam(magr)); + pline("%s %s.", buf, mon_nam(mdef)); + } + for (obj = mdef->minvent; obj; obj = obj->nobj) + (void) snuff_lit(obj); - /* - * All of this maniuplation is needed to keep the display correct. - * There is a flush at the next pline(). - */ - ax = magr->mx; - ay = magr->my; - dx = mdef->mx; - dy = mdef->my; - /* - * Leave the defender in the monster chain at it's current position, - * but don't leave it on the screen. Move the agressor to the def- - * ender's position. - */ - remove_monster(ax, ay); - place_monster(magr, dx, dy); - newsym(ax,ay); /* erase old position */ - newsym(dx,dy); /* update new position */ + /* + * All of this maniuplation is needed to keep the display correct. + * There is a flush at the next pline(). + */ + ax = magr->mx; + ay = magr->my; + dx = mdef->mx; + dy = mdef->my; + /* + * Leave the defender in the monster chain at it's current position, + * but don't leave it on the screen. Move the agressor to the def- + * ender's position. + */ + remove_monster(ax, ay); + place_monster(magr, dx, dy); + newsym(ax, ay); /* erase old position */ + newsym(dx, dy); /* update new position */ - status = mdamagem(magr, mdef, mattk); + status = mdamagem(magr, mdef, mattk); - if ((status & (MM_AGR_DIED|MM_DEF_DIED)) == (MM_AGR_DIED|MM_DEF_DIED)) { - ; /* both died -- do nothing */ - } else if (status & MM_DEF_DIED) { /* defender died */ - /* - * Note: remove_monster() was called in relmon(), wiping out - * magr from level.monsters[mdef->mx][mdef->my]. We need to - * put it back and display it. -kd - */ - place_monster(magr, dx, dy); - newsym(dx, dy); - /* aggressor moves to and might encounter trouble there */ - if (minliquid(magr) || (t_at(dx, dy) && mintrap(magr) == 2)) - status |= MM_AGR_DIED; - } else if (status & MM_AGR_DIED) { /* aggressor died */ - place_monster(mdef, dx, dy); - newsym(dx, dy); - } else { /* both alive, put them back */ - if (cansee(dx, dy)) - pline("%s is regurgitated!", Monnam(mdef)); + if ((status & (MM_AGR_DIED | MM_DEF_DIED)) + == (MM_AGR_DIED | MM_DEF_DIED)) { + ; /* both died -- do nothing */ + } else if (status & MM_DEF_DIED) { /* defender died */ + /* + * Note: remove_monster() was called in relmon(), wiping out + * magr from level.monsters[mdef->mx][mdef->my]. We need to + * put it back and display it. -kd + */ + place_monster(magr, dx, dy); + newsym(dx, dy); + /* aggressor moves to and might encounter trouble there */ + if (minliquid(magr) || (t_at(dx, dy) && mintrap(magr) == 2)) + status |= MM_AGR_DIED; + } else if (status & MM_AGR_DIED) { /* aggressor died */ + place_monster(mdef, dx, dy); + newsym(dx, dy); + } else { /* both alive, put them back */ + if (cansee(dx, dy)) + pline("%s is regurgitated!", Monnam(mdef)); - place_monster(magr, ax, ay); - place_monster(mdef, dx, dy); - newsym(ax, ay); - newsym(dx, dy); - } + place_monster(magr, ax, ay); + place_monster(mdef, dx, dy); + newsym(ax, ay); + newsym(dx, dy); + } - return status; + return status; } STATIC_OVL int explmm(magr, mdef, mattk) - register struct monst *magr, *mdef; - register struct attack *mattk; +register struct monst *magr, *mdef; +register struct attack *mattk; { - int result; + int result; - if (magr->mcan) - return MM_MISS; + if (magr->mcan) + return MM_MISS; - if(cansee(magr->mx, magr->my)) - pline("%s explodes!", Monnam(magr)); - else noises(magr, mattk); + if (cansee(magr->mx, magr->my)) + pline("%s explodes!", Monnam(magr)); + else + noises(magr, mattk); - result = mdamagem(magr, mdef, mattk); + result = mdamagem(magr, mdef, mattk); - /* Kill off agressor if it didn't die. */ - if (!(result & MM_AGR_DIED)) { - mondead(magr); - if (magr->mhp > 0) return result; /* life saved */ - result |= MM_AGR_DIED; - } - if (magr->mtame) /* give this one even if it was visible */ - You(brief_feeling, "melancholy"); + /* Kill off agressor if it didn't die. */ + if (!(result & MM_AGR_DIED)) { + mondead(magr); + if (magr->mhp > 0) + return result; /* life saved */ + result |= MM_AGR_DIED; + } + if (magr->mtame) /* give this one even if it was visible */ + You(brief_feeling, "melancholy"); - return result; + return result; } /* @@ -678,564 +725,606 @@ explmm(magr, mdef, mattk) */ STATIC_OVL int mdamagem(magr, mdef, mattk) - register struct monst *magr, *mdef; - register struct attack *mattk; +register struct monst *magr, *mdef; +register struct attack *mattk; { - struct obj *obj; - char buf[BUFSZ]; - struct permonst *pa = magr->data, *pd = mdef->data; - int armpro, num, tmp = d((int)mattk->damn, (int)mattk->damd), - res = MM_MISS; - boolean cancelled; + struct obj *obj; + char buf[BUFSZ]; + struct permonst *pa = magr->data, *pd = mdef->data; + int armpro, num, tmp = d((int) mattk->damn, (int) mattk->damd), + res = MM_MISS; + boolean cancelled; - if ((touch_petrifies(pd) || /* or flesh_petrifies() */ - (mattk->adtyp == AD_DGST && pd == &mons[PM_MEDUSA])) && - !resists_ston(magr)) { - long protector = attk_protection((int)mattk->aatyp), - wornitems = magr->misc_worn_check; + if ((touch_petrifies(pd) || /* or flesh_petrifies() */ + (mattk->adtyp == AD_DGST && pd == &mons[PM_MEDUSA])) + && !resists_ston(magr)) { + long protector = attk_protection((int) mattk->aatyp), + wornitems = magr->misc_worn_check; - /* wielded weapon gives same protection as gloves here */ - if (otmp != 0) wornitems |= W_ARMG; + /* wielded weapon gives same protection as gloves here */ + if (otmp != 0) + wornitems |= W_ARMG; - if (protector == 0L || - (protector != ~0L && (wornitems & protector) != protector)) { - if (poly_when_stoned(pa)) { - mon_to_stone(magr); - return MM_HIT; /* no damage during the polymorph */ - } - if (vis) pline("%s turns to stone!", Monnam(magr)); - monstone(magr); - if (magr->mhp > 0) - return MM_HIT; /* lifesaved */ - else if (magr->mtame && !vis) - You(brief_feeling, "peculiarly sad"); - return MM_AGR_DIED; - } - } + if (protector == 0L + || (protector != ~0L && (wornitems & protector) != protector)) { + if (poly_when_stoned(pa)) { + mon_to_stone(magr); + return MM_HIT; /* no damage during the polymorph */ + } + if (vis) + pline("%s turns to stone!", Monnam(magr)); + monstone(magr); + if (magr->mhp > 0) + return MM_HIT; /* lifesaved */ + else if (magr->mtame && !vis) + You(brief_feeling, "peculiarly sad"); + return MM_AGR_DIED; + } + } - /* cancellation factor is the same as when attacking the hero */ - armpro = magic_negation(mdef); - cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + /* cancellation factor is the same as when attacking the hero */ + armpro = magic_negation(mdef); + cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); - switch(mattk->adtyp) { - case AD_DGST: - /* eating a Rider or its corpse is fatal */ - if (is_rider(pd)) { - if (vis) - pline("%s %s!", Monnam(magr), - pd == &mons[PM_FAMINE] ? - "belches feebly, shrivels up and dies" : - pd == &mons[PM_PESTILENCE] ? - "coughs spasmodically and collapses" : - "vomits violently and drops dead"); - mondied(magr); - if (magr->mhp > 0) return 0; /* lifesaved */ - else if (magr->mtame && !vis) - You(brief_feeling, "queasy"); - return MM_AGR_DIED; - } - if(flags.verbose && !Deaf) verbalize("Burrrrp!"); - tmp = mdef->mhp; - /* Use up amulet of life saving */ - if (!!(obj = mlifesaver(mdef))) m_useup(mdef, obj); + switch (mattk->adtyp) { + case AD_DGST: + /* eating a Rider or its corpse is fatal */ + if (is_rider(pd)) { + if (vis) + pline("%s %s!", Monnam(magr), + pd == &mons[PM_FAMINE] + ? "belches feebly, shrivels up and dies" + : pd == &mons[PM_PESTILENCE] + ? "coughs spasmodically and collapses" + : "vomits violently and drops dead"); + mondied(magr); + if (magr->mhp > 0) + return 0; /* lifesaved */ + else if (magr->mtame && !vis) + You(brief_feeling, "queasy"); + return MM_AGR_DIED; + } + if (flags.verbose && !Deaf) + verbalize("Burrrrp!"); + tmp = mdef->mhp; + /* Use up amulet of life saving */ + if (!!(obj = mlifesaver(mdef))) + m_useup(mdef, obj); - /* Is a corpse for nutrition possible? It may kill magr */ - if (!corpse_chance(mdef, magr, TRUE) || magr->mhp < 1) - break; + /* Is a corpse for nutrition possible? It may kill magr */ + if (!corpse_chance(mdef, magr, TRUE) || magr->mhp < 1) + break; - /* Pets get nutrition from swallowing monster whole. - * No nutrition from G_NOCORPSE monster, eg, undead. - * DGST monsters don't die from undead corpses - */ - num = monsndx(pd); - if (magr->mtame && !magr->isminion && - !(mvitals[num].mvflags & G_NOCORPSE)) { - struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE); - int nutrit; + /* Pets get nutrition from swallowing monster whole. + * No nutrition from G_NOCORPSE monster, eg, undead. + * DGST monsters don't die from undead corpses + */ + num = monsndx(pd); + if (magr->mtame && !magr->isminion + && !(mvitals[num].mvflags & G_NOCORPSE)) { + struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE); + int nutrit; - set_corpsenm(virtualcorpse, num); - nutrit = dog_nutrition(magr, virtualcorpse); - dealloc_obj(virtualcorpse); + set_corpsenm(virtualcorpse, num); + nutrit = dog_nutrition(magr, virtualcorpse); + dealloc_obj(virtualcorpse); - /* only 50% nutrition, 25% of normal eating time */ - if (magr->meating > 1) magr->meating = (magr->meating+3)/4; - if (nutrit > 1) nutrit /= 2; - EDOG(magr)->hungrytime += nutrit; - } - break; - case AD_STUN: - if (magr->mcan) break; - if (canseemon(mdef)) - pline("%s %s for a moment.", Monnam(mdef), - makeplural(stagger(pd, "stagger"))); - mdef->mstun = 1; - goto physical; - case AD_LEGS: - if (magr->mcan) { - tmp = 0; - break; - } - goto physical; - case AD_WERE: - case AD_HEAL: - case AD_PHYS: - physical: - if (mattk->aatyp == AT_KICK && thick_skinned(pd)) { - tmp = 0; - } else if(mattk->aatyp == AT_WEAP) { - if(otmp) { - if (otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm])) - goto do_stone; - tmp += dmgval(otmp, mdef); - if (otmp->oartifact) { - (void)artifact_hit(magr,mdef, otmp, &tmp, dieroll); - if (mdef->mhp <= 0) - return (MM_DEF_DIED | - (grow_up(magr,mdef) ? 0 : MM_AGR_DIED)); - } - if (tmp) - rustm(mdef, otmp); - } - } else if (pa == &mons[PM_PURPLE_WORM] && - pd == &mons[PM_SHRIEKER]) { - /* hack to enhance mm_aggression(); we don't want purple - worm's bite attack to kill a shrieker because then it - won't swallow the corpse; but if the target survives, - the subsequent engulf attack should accomplish that */ - if (tmp >= mdef->mhp && mdef->mhp > 1) tmp = mdef->mhp - 1; - } - break; - case AD_FIRE: - if (cancelled) { - tmp = 0; - break; - } - if (vis) - pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); - if (pd == &mons[PM_STRAW_GOLEM] || - pd == &mons[PM_PAPER_GOLEM]) { - if (vis) pline("%s burns completely!", Monnam(mdef)); - mondied(mdef); - if (mdef->mhp > 0) return 0; - else if (mdef->mtame && !vis) - pline("May %s roast in peace.", mon_nam(mdef)); - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - } - tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); - tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); - if (resists_fire(mdef)) { - if (vis) - pline_The("fire doesn't seem to burn %s!", - mon_nam(mdef)); - shieldeff(mdef->mx, mdef->my); - golemeffects(mdef, AD_FIRE, tmp); - tmp = 0; - } - /* only potions damage resistant players in destroy_item */ - tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE); - break; - case AD_COLD: - if (cancelled) { - tmp = 0; - break; - } - if (vis) pline("%s is covered in frost!", Monnam(mdef)); - if (resists_cold(mdef)) { - if (vis) - pline_The("frost doesn't seem to chill %s!", - mon_nam(mdef)); - shieldeff(mdef->mx, mdef->my); - golemeffects(mdef, AD_COLD, tmp); - tmp = 0; - } - tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD); - break; - case AD_ELEC: - if (cancelled) { - tmp = 0; - break; - } - if (vis) pline("%s gets zapped!", Monnam(mdef)); - tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); - if (resists_elec(mdef)) { - if (vis) pline_The("zap doesn't shock %s!", mon_nam(mdef)); - shieldeff(mdef->mx, mdef->my); - golemeffects(mdef, AD_ELEC, tmp); - tmp = 0; - } - /* only rings damage resistant players in destroy_item */ - tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC); - break; - case AD_ACID: - if (magr->mcan) { - tmp = 0; - break; - } - if (resists_acid(mdef)) { - if (vis) - pline("%s is covered in acid, but it seems harmless.", - Monnam(mdef)); - tmp = 0; - } else if (vis) { - pline("%s is covered in acid!", Monnam(mdef)); - pline("It burns %s!", mon_nam(mdef)); - } - if (!rn2(30)) erode_armor(mdef, ERODE_CORRODE); - if (!rn2(6)) acid_damage(MON_WEP(mdef)); - break; - case AD_RUST: - if (magr->mcan) break; - if (pd == &mons[PM_IRON_GOLEM]) { - if (vis) pline("%s falls to pieces!", Monnam(mdef)); - mondied(mdef); - if (mdef->mhp > 0) return 0; - else if (mdef->mtame && !vis) - pline("May %s rust in peace.", mon_nam(mdef)); - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - } - erode_armor(mdef, ERODE_RUST); - mdef->mstrategy &= ~STRAT_WAITFORU; - tmp = 0; - break; - case AD_CORR: - if (magr->mcan) break; - erode_armor(mdef, ERODE_CORRODE); - mdef->mstrategy &= ~STRAT_WAITFORU; - tmp = 0; - break; - case AD_DCAY: - if (magr->mcan) break; - if (pd == &mons[PM_WOOD_GOLEM] || - pd == &mons[PM_LEATHER_GOLEM]) { - if (vis) pline("%s falls to pieces!", Monnam(mdef)); - mondied(mdef); - if (mdef->mhp > 0) return 0; - else if (mdef->mtame && !vis) - pline("May %s rot in peace.", mon_nam(mdef)); - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - } - erode_armor(mdef, ERODE_CORRODE); - mdef->mstrategy &= ~STRAT_WAITFORU; - tmp = 0; - break; - case AD_STON: - if (magr->mcan) break; - do_stone: - /* may die from the acid if it eats a stone-curing corpse */ - if (munstone(mdef, FALSE)) goto post_stone; - if (poly_when_stoned(pd)) { - mon_to_stone(mdef); - tmp = 0; - break; - } - if (!resists_ston(mdef)) { - if (vis) pline("%s turns to stone!", Monnam(mdef)); - monstone(mdef); - post_stone: if (mdef->mhp > 0) return 0; - else if (mdef->mtame && !vis) - You(brief_feeling, "peculiarly sad"); - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - } - tmp = (mattk->adtyp == AD_STON ? 0 : 1); - break; - case AD_TLPT: - if (!cancelled && tmp < mdef->mhp && !tele_restrict(mdef)) { - char mdef_Monnam[BUFSZ]; - /* save the name before monster teleports, otherwise - we'll get "it" in the suddenly disappears message */ - if (vis) Strcpy(mdef_Monnam, Monnam(mdef)); - mdef->mstrategy &= ~STRAT_WAITFORU; - (void) rloc(mdef, FALSE); - if (vis && !canspotmon(mdef) && mdef != u.usteed) - pline("%s suddenly disappears!", mdef_Monnam); - } - break; - case AD_SLEE: - if (!cancelled && !mdef->msleeping && - sleep_monst(mdef, rnd(10), -1)) { - if (vis) { - Strcpy(buf, Monnam(mdef)); - pline("%s is put to sleep by %s.", buf, mon_nam(magr)); - } - mdef->mstrategy &= ~STRAT_WAITFORU; - slept_monst(mdef); - } - break; - case AD_PLYS: - if(!cancelled && mdef->mcanmove) { - if (vis) { - Strcpy(buf, Monnam(mdef)); - pline("%s is frozen by %s.", buf, mon_nam(magr)); - } - paralyze_monst(mdef, rnd(10)); - } - break; - case AD_SLOW: - if (!cancelled && mdef->mspeed != MSLOW) { - unsigned int oldspeed = mdef->mspeed; - - mon_adjust_speed(mdef, -1, (struct obj *)0); - mdef->mstrategy &= ~STRAT_WAITFORU; - if (mdef->mspeed != oldspeed && vis) - pline("%s slows down.", Monnam(mdef)); - } - break; - case AD_CONF: - /* Since confusing another monster doesn't have a real time - * limit, setting spec_used would not really be right (though - * we still should check for it). - */ - if (!magr->mcan && !mdef->mconf && !magr->mspec_used) { - if (vis) pline("%s looks confused.", Monnam(mdef)); - mdef->mconf = 1; - mdef->mstrategy &= ~STRAT_WAITFORU; - } - break; - case AD_BLND: - if (can_blnd(magr, mdef, mattk->aatyp, (struct obj*)0)) { - register unsigned rnd_tmp; - - if (vis && mdef->mcansee) - pline("%s is blinded.", Monnam(mdef)); - rnd_tmp = d((int)mattk->damn, (int)mattk->damd); - if ((rnd_tmp += mdef->mblinded) > 127) rnd_tmp = 127; - mdef->mblinded = rnd_tmp; - mdef->mcansee = 0; - mdef->mstrategy &= ~STRAT_WAITFORU; - } - tmp = 0; - break; - case AD_HALU: - if (!magr->mcan && haseyes(pd) && mdef->mcansee) { - if (vis) pline("%s looks %sconfused.", - Monnam(mdef), mdef->mconf ? "more " : ""); - mdef->mconf = 1; - mdef->mstrategy &= ~STRAT_WAITFORU; - } - tmp = 0; - break; - case AD_CURS: - if (!night() && (pa == &mons[PM_GREMLIN])) break; - if (!magr->mcan && !rn2(10)) { - mdef->mcan = 1; /* cancelled regardless of lifesave */ - mdef->mstrategy &= ~STRAT_WAITFORU; - if (is_were(pd) && pd->mlet != S_HUMAN) - were_change(mdef); - if (pd == &mons[PM_CLAY_GOLEM]) { - if (vis) { - pline("Some writing vanishes from %s head!", - s_suffix(mon_nam(mdef))); - pline("%s is destroyed!", Monnam(mdef)); - } - mondied(mdef); - if (mdef->mhp > 0) return 0; - else if (mdef->mtame && !vis) - You(brief_feeling, "strangely sad"); - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - } - if (!Deaf) { - if (!vis) You_hear("laughter."); - else pline("%s chuckles.", Monnam(magr)); - } - } - break; - case AD_SGLD: - tmp = 0; - if (magr->mcan) break; - /* technically incorrect; no check for stealing gold from - * between mdef's feet... - */ - { - struct obj *gold = findgold(mdef->minvent); - if (!gold) break; - obj_extract_self(gold); - add_to_minv(magr, gold); + /* only 50% nutrition, 25% of normal eating time */ + if (magr->meating > 1) + magr->meating = (magr->meating + 3) / 4; + if (nutrit > 1) + nutrit /= 2; + EDOG(magr)->hungrytime += nutrit; + } + break; + case AD_STUN: + if (magr->mcan) + break; + if (canseemon(mdef)) + pline("%s %s for a moment.", Monnam(mdef), + makeplural(stagger(pd, "stagger"))); + mdef->mstun = 1; + goto physical; + case AD_LEGS: + if (magr->mcan) { + tmp = 0; + break; + } + goto physical; + case AD_WERE: + case AD_HEAL: + case AD_PHYS: + physical: + if (mattk->aatyp == AT_KICK && thick_skinned(pd)) { + tmp = 0; + } else if (mattk->aatyp == AT_WEAP) { + if (otmp) { + if (otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm])) + goto do_stone; + tmp += dmgval(otmp, mdef); + if (otmp->oartifact) { + (void) artifact_hit(magr, mdef, otmp, &tmp, dieroll); + if (mdef->mhp <= 0) + return (MM_DEF_DIED + | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); } - mdef->mstrategy &= ~STRAT_WAITFORU; - if (vis) { - Strcpy(buf, Monnam(magr)); - pline("%s steals some gold from %s.", buf, mon_nam(mdef)); - } - if (!tele_restrict(magr)) { - (void) rloc(magr, FALSE); - if (vis && !canspotmon(magr)) - pline("%s suddenly disappears!", buf); - } - break; - case AD_DRLI: - if (!cancelled && !rn2(3) && !resists_drli(mdef)) { - tmp = d(2,6); - if (vis) - pline("%s suddenly seems weaker!", Monnam(mdef)); - mdef->mhpmax -= tmp; - if (mdef->m_lev == 0) - tmp = mdef->mhp; - else mdef->m_lev--; - /* Automatic kill if drained past level 0 */ - } - break; - case AD_SSEX: - case AD_SITM: /* for now these are the same */ - case AD_SEDU: - if (magr->mcan) break; - /* find an object to steal, non-cursed if magr is tame */ - for (obj = mdef->minvent; obj; obj = obj->nobj) - if (!magr->mtame || !obj->cursed) - break; + if (tmp) + rustm(mdef, otmp); + } + } else if (pa == &mons[PM_PURPLE_WORM] && pd == &mons[PM_SHRIEKER]) { + /* hack to enhance mm_aggression(); we don't want purple + worm's bite attack to kill a shrieker because then it + won't swallow the corpse; but if the target survives, + the subsequent engulf attack should accomplish that */ + if (tmp >= mdef->mhp && mdef->mhp > 1) + tmp = mdef->mhp - 1; + } + break; + case AD_FIRE: + if (cancelled) { + tmp = 0; + break; + } + if (vis) + pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); + if (pd == &mons[PM_STRAW_GOLEM] || pd == &mons[PM_PAPER_GOLEM]) { + if (vis) + pline("%s burns completely!", Monnam(mdef)); + mondied(mdef); + if (mdef->mhp > 0) + return 0; + else if (mdef->mtame && !vis) + pline("May %s roast in peace.", mon_nam(mdef)); + return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); + tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); + if (resists_fire(mdef)) { + if (vis) + pline_The("fire doesn't seem to burn %s!", mon_nam(mdef)); + shieldeff(mdef->mx, mdef->my); + golemeffects(mdef, AD_FIRE, tmp); + tmp = 0; + } + /* only potions damage resistant players in destroy_item */ + tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE); + break; + case AD_COLD: + if (cancelled) { + tmp = 0; + break; + } + if (vis) + pline("%s is covered in frost!", Monnam(mdef)); + if (resists_cold(mdef)) { + if (vis) + pline_The("frost doesn't seem to chill %s!", mon_nam(mdef)); + shieldeff(mdef->mx, mdef->my); + golemeffects(mdef, AD_COLD, tmp); + tmp = 0; + } + tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD); + break; + case AD_ELEC: + if (cancelled) { + tmp = 0; + break; + } + if (vis) + pline("%s gets zapped!", Monnam(mdef)); + tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); + if (resists_elec(mdef)) { + if (vis) + pline_The("zap doesn't shock %s!", mon_nam(mdef)); + shieldeff(mdef->mx, mdef->my); + golemeffects(mdef, AD_ELEC, tmp); + tmp = 0; + } + /* only rings damage resistant players in destroy_item */ + tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + break; + case AD_ACID: + if (magr->mcan) { + tmp = 0; + break; + } + if (resists_acid(mdef)) { + if (vis) + pline("%s is covered in acid, but it seems harmless.", + Monnam(mdef)); + tmp = 0; + } else if (vis) { + pline("%s is covered in acid!", Monnam(mdef)); + pline("It burns %s!", mon_nam(mdef)); + } + if (!rn2(30)) + erode_armor(mdef, ERODE_CORRODE); + if (!rn2(6)) + acid_damage(MON_WEP(mdef)); + break; + case AD_RUST: + if (magr->mcan) + break; + if (pd == &mons[PM_IRON_GOLEM]) { + if (vis) + pline("%s falls to pieces!", Monnam(mdef)); + mondied(mdef); + if (mdef->mhp > 0) + return 0; + else if (mdef->mtame && !vis) + pline("May %s rust in peace.", mon_nam(mdef)); + return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + erode_armor(mdef, ERODE_RUST); + mdef->mstrategy &= ~STRAT_WAITFORU; + tmp = 0; + break; + case AD_CORR: + if (magr->mcan) + break; + erode_armor(mdef, ERODE_CORRODE); + mdef->mstrategy &= ~STRAT_WAITFORU; + tmp = 0; + break; + case AD_DCAY: + if (magr->mcan) + break; + if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) { + if (vis) + pline("%s falls to pieces!", Monnam(mdef)); + mondied(mdef); + if (mdef->mhp > 0) + return 0; + else if (mdef->mtame && !vis) + pline("May %s rot in peace.", mon_nam(mdef)); + return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + erode_armor(mdef, ERODE_CORRODE); + mdef->mstrategy &= ~STRAT_WAITFORU; + tmp = 0; + break; + case AD_STON: + if (magr->mcan) + break; + do_stone: + /* may die from the acid if it eats a stone-curing corpse */ + if (munstone(mdef, FALSE)) + goto post_stone; + if (poly_when_stoned(pd)) { + mon_to_stone(mdef); + tmp = 0; + break; + } + if (!resists_ston(mdef)) { + if (vis) + pline("%s turns to stone!", Monnam(mdef)); + monstone(mdef); + post_stone: + if (mdef->mhp > 0) + return 0; + else if (mdef->mtame && !vis) + You(brief_feeling, "peculiarly sad"); + return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + tmp = (mattk->adtyp == AD_STON ? 0 : 1); + break; + case AD_TLPT: + if (!cancelled && tmp < mdef->mhp && !tele_restrict(mdef)) { + char mdef_Monnam[BUFSZ]; + /* save the name before monster teleports, otherwise + we'll get "it" in the suddenly disappears message */ + if (vis) + Strcpy(mdef_Monnam, Monnam(mdef)); + mdef->mstrategy &= ~STRAT_WAITFORU; + (void) rloc(mdef, FALSE); + if (vis && !canspotmon(mdef) && mdef != u.usteed) + pline("%s suddenly disappears!", mdef_Monnam); + } + break; + case AD_SLEE: + if (!cancelled && !mdef->msleeping + && sleep_monst(mdef, rnd(10), -1)) { + if (vis) { + Strcpy(buf, Monnam(mdef)); + pline("%s is put to sleep by %s.", buf, mon_nam(magr)); + } + mdef->mstrategy &= ~STRAT_WAITFORU; + slept_monst(mdef); + } + break; + case AD_PLYS: + if (!cancelled && mdef->mcanmove) { + if (vis) { + Strcpy(buf, Monnam(mdef)); + pline("%s is frozen by %s.", buf, mon_nam(magr)); + } + paralyze_monst(mdef, rnd(10)); + } + break; + case AD_SLOW: + if (!cancelled && mdef->mspeed != MSLOW) { + unsigned int oldspeed = mdef->mspeed; - if (obj) { - char onambuf[BUFSZ], mdefnambuf[BUFSZ]; + mon_adjust_speed(mdef, -1, (struct obj *) 0); + mdef->mstrategy &= ~STRAT_WAITFORU; + if (mdef->mspeed != oldspeed && vis) + pline("%s slows down.", Monnam(mdef)); + } + break; + case AD_CONF: + /* Since confusing another monster doesn't have a real time + * limit, setting spec_used would not really be right (though + * we still should check for it). + */ + if (!magr->mcan && !mdef->mconf && !magr->mspec_used) { + if (vis) + pline("%s looks confused.", Monnam(mdef)); + mdef->mconf = 1; + mdef->mstrategy &= ~STRAT_WAITFORU; + } + break; + case AD_BLND: + if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) { + register unsigned rnd_tmp; - /* make a special x_monnam() call that never omits - the saddle, and save it for later messages */ - Strcpy(mdefnambuf, x_monnam(mdef, ARTICLE_THE, (char *)0, 0, FALSE)); + if (vis && mdef->mcansee) + pline("%s is blinded.", Monnam(mdef)); + rnd_tmp = d((int) mattk->damn, (int) mattk->damd); + if ((rnd_tmp += mdef->mblinded) > 127) + rnd_tmp = 127; + mdef->mblinded = rnd_tmp; + mdef->mcansee = 0; + mdef->mstrategy &= ~STRAT_WAITFORU; + } + tmp = 0; + break; + case AD_HALU: + if (!magr->mcan && haseyes(pd) && mdef->mcansee) { + if (vis) + pline("%s looks %sconfused.", Monnam(mdef), + mdef->mconf ? "more " : ""); + mdef->mconf = 1; + mdef->mstrategy &= ~STRAT_WAITFORU; + } + tmp = 0; + break; + case AD_CURS: + if (!night() && (pa == &mons[PM_GREMLIN])) + break; + if (!magr->mcan && !rn2(10)) { + mdef->mcan = 1; /* cancelled regardless of lifesave */ + mdef->mstrategy &= ~STRAT_WAITFORU; + if (is_were(pd) && pd->mlet != S_HUMAN) + were_change(mdef); + if (pd == &mons[PM_CLAY_GOLEM]) { + if (vis) { + pline("Some writing vanishes from %s head!", + s_suffix(mon_nam(mdef))); + pline("%s is destroyed!", Monnam(mdef)); + } + mondied(mdef); + if (mdef->mhp > 0) + return 0; + else if (mdef->mtame && !vis) + You(brief_feeling, "strangely sad"); + return (MM_DEF_DIED + | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + if (!Deaf) { + if (!vis) + You_hear("laughter."); + else + pline("%s chuckles.", Monnam(magr)); + } + } + break; + case AD_SGLD: + tmp = 0; + if (magr->mcan) + break; + /* technically incorrect; no check for stealing gold from + * between mdef's feet... + */ + { + struct obj *gold = findgold(mdef->minvent); + if (!gold) + break; + obj_extract_self(gold); + add_to_minv(magr, gold); + } + mdef->mstrategy &= ~STRAT_WAITFORU; + if (vis) { + Strcpy(buf, Monnam(magr)); + pline("%s steals some gold from %s.", buf, mon_nam(mdef)); + } + if (!tele_restrict(magr)) { + (void) rloc(magr, FALSE); + if (vis && !canspotmon(magr)) + pline("%s suddenly disappears!", buf); + } + break; + case AD_DRLI: + if (!cancelled && !rn2(3) && !resists_drli(mdef)) { + tmp = d(2, 6); + if (vis) + pline("%s suddenly seems weaker!", Monnam(mdef)); + mdef->mhpmax -= tmp; + if (mdef->m_lev == 0) + tmp = mdef->mhp; + else + mdef->m_lev--; + /* Automatic kill if drained past level 0 */ + } + break; + case AD_SSEX: + case AD_SITM: /* for now these are the same */ + case AD_SEDU: + if (magr->mcan) + break; + /* find an object to steal, non-cursed if magr is tame */ + for (obj = mdef->minvent; obj; obj = obj->nobj) + if (!magr->mtame || !obj->cursed) + break; - otmp = obj; - if (u.usteed == mdef && - otmp == which_armor(mdef, W_SADDLE)) - /* "You can no longer ride ." */ - dismount_steed(DISMOUNT_POLY); - obj_extract_self(otmp); - if (otmp->owornmask) { - mdef->misc_worn_check &= ~otmp->owornmask; - if (otmp->owornmask & W_WEP) mwepgone(mdef); - otmp->owornmask = 0L; - update_mon_intrinsics(mdef, otmp, FALSE, FALSE); - } - /* add_to_minv() might free otmp [if it merges] */ - if (vis) - Strcpy(onambuf, doname(otmp)); - (void) add_to_minv(magr, otmp); - if (vis) { - Strcpy(buf, Monnam(magr)); - pline("%s steals %s from %s!", buf, - onambuf, mdefnambuf); - } - possibly_unwield(mdef, FALSE); - mdef->mstrategy &= ~STRAT_WAITFORU; - mselftouch(mdef, (const char *)0, FALSE); - if (mdef->mhp <= 0) - return (MM_DEF_DIED | (grow_up(magr,mdef) ? - 0 : MM_AGR_DIED)); - if (pa->mlet == S_NYMPH && !tele_restrict(magr)) { - (void) rloc(magr, FALSE); - if (vis && !canspotmon(magr)) - pline("%s suddenly disappears!", buf); - } - } - tmp = 0; - break; - case AD_DREN: - if (!cancelled && !rn2(4)) - xdrainenergym(mdef, vis && mattk->aatyp != AT_ENGL); - tmp = 0; - break; - case AD_DRST: - case AD_DRDX: - case AD_DRCO: - if (!cancelled && !rn2(8)) { - if (vis) - pline("%s %s was poisoned!", s_suffix(Monnam(magr)), - mpoisons_subj(magr, mattk)); - if (resists_poison(mdef)) { - if (vis) - pline_The("poison doesn't seem to affect %s.", - mon_nam(mdef)); - } else { - if (rn2(10)) tmp += rn1(10,6); - else { - if (vis) pline_The("poison was deadly..."); - tmp = mdef->mhp; - } - } - } - break; - case AD_DRIN: - if (notonhead || !has_head(pd)) { - if (vis) pline("%s doesn't seem harmed.", Monnam(mdef)); - /* Not clear what to do for green slimes */ - tmp = 0; - break; - } - if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) { - if (vis) { - Strcpy(buf, s_suffix(Monnam(mdef))); - pline("%s helmet blocks %s attack to %s head.", - buf, s_suffix(mon_nam(magr)), - mhis(mdef)); - } - break; - } - res = eat_brains(magr, mdef, vis, &tmp); - break; - case AD_SLIM: - if (cancelled) break; /* physical damage only */ - if (!rn2(4) && !slimeproof(pd)) { - if (!munslime(mdef, FALSE) && mdef->mhp > 0) { - if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, vis)) - pd = mdef->data; - mdef->mstrategy &= ~STRAT_WAITFORU; - res = MM_HIT; - } - /* munslime attempt could have been fatal, - potentially to multiple monsters (SCR_FIRE) */ - if (magr->mhp < 1) res |= MM_AGR_DIED; - if (mdef->mhp < 1) res |= MM_DEF_DIED; - tmp = 0; - } - break; - case AD_STCK: - if (cancelled) tmp = 0; - break; - case AD_WRAP: /* monsters cannot grab one another, it's too hard */ - if (magr->mcan) tmp = 0; - break; - case AD_ENCH: - /* there's no msomearmor() function, so just do damage */ - /* if (cancelled) break; */ - break; - default: tmp = 0; - break; - } - if (!tmp) return res; + if (obj) { + char onambuf[BUFSZ], mdefnambuf[BUFSZ]; - if((mdef->mhp -= tmp) < 1) { - if (m_at(mdef->mx, mdef->my) == magr) { /* see gulpmm() */ - remove_monster(mdef->mx, mdef->my); - mdef->mhp = 1; /* otherwise place_monster will complain */ - place_monster(mdef, mdef->mx, mdef->my); - mdef->mhp = 0; - } - monkilled(mdef, "", (int)mattk->adtyp); - if (mdef->mhp > 0) return res; /* mdef lifesaved */ - else if (res == MM_AGR_DIED) return (MM_DEF_DIED | MM_AGR_DIED); + /* make a special x_monnam() call that never omits + the saddle, and save it for later messages */ + Strcpy(mdefnambuf, + x_monnam(mdef, ARTICLE_THE, (char *) 0, 0, FALSE)); - if (mattk->adtyp == AD_DGST) { - /* various checks similar to dog_eat and meatobj. - * after monkilled() to provide better message ordering */ - if (mdef->cham >= LOW_PM) { - (void) newcham(magr, (struct permonst *)0, FALSE, TRUE); - } else if (pd == &mons[PM_GREEN_SLIME] && !slimeproof(pa)) { - (void) newcham(magr, &mons[PM_GREEN_SLIME], FALSE, TRUE); - } else if (pd == &mons[PM_WRAITH]) { - (void) grow_up(magr, (struct monst *)0); - /* don't grow up twice */ - return (MM_DEF_DIED | (magr->mhp > 0 ? 0 : MM_AGR_DIED)); - } else if (pd == &mons[PM_NURSE]) { - magr->mhp = magr->mhpmax; - } - } - /* caveat: above digestion handling doesn't keep `pa' up to date */ + otmp = obj; + if (u.usteed == mdef && otmp == which_armor(mdef, W_SADDLE)) + /* "You can no longer ride ." */ + dismount_steed(DISMOUNT_POLY); + obj_extract_self(otmp); + if (otmp->owornmask) { + mdef->misc_worn_check &= ~otmp->owornmask; + if (otmp->owornmask & W_WEP) + mwepgone(mdef); + otmp->owornmask = 0L; + update_mon_intrinsics(mdef, otmp, FALSE, FALSE); + } + /* add_to_minv() might free otmp [if it merges] */ + if (vis) + Strcpy(onambuf, doname(otmp)); + (void) add_to_minv(magr, otmp); + if (vis) { + Strcpy(buf, Monnam(magr)); + pline("%s steals %s from %s!", buf, onambuf, mdefnambuf); + } + possibly_unwield(mdef, FALSE); + mdef->mstrategy &= ~STRAT_WAITFORU; + mselftouch(mdef, (const char *) 0, FALSE); + if (mdef->mhp <= 0) + return (MM_DEF_DIED + | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + if (pa->mlet == S_NYMPH && !tele_restrict(magr)) { + (void) rloc(magr, FALSE); + if (vis && !canspotmon(magr)) + pline("%s suddenly disappears!", buf); + } + } + tmp = 0; + break; + case AD_DREN: + if (!cancelled && !rn2(4)) + xdrainenergym(mdef, vis && mattk->aatyp != AT_ENGL); + tmp = 0; + break; + case AD_DRST: + case AD_DRDX: + case AD_DRCO: + if (!cancelled && !rn2(8)) { + if (vis) + pline("%s %s was poisoned!", s_suffix(Monnam(magr)), + mpoisons_subj(magr, mattk)); + if (resists_poison(mdef)) { + if (vis) + pline_The("poison doesn't seem to affect %s.", + mon_nam(mdef)); + } else { + if (rn2(10)) + tmp += rn1(10, 6); + else { + if (vis) + pline_The("poison was deadly..."); + tmp = mdef->mhp; + } + } + } + break; + case AD_DRIN: + if (notonhead || !has_head(pd)) { + if (vis) + pline("%s doesn't seem harmed.", Monnam(mdef)); + /* Not clear what to do for green slimes */ + tmp = 0; + break; + } + if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) { + if (vis) { + Strcpy(buf, s_suffix(Monnam(mdef))); + pline("%s helmet blocks %s attack to %s head.", buf, + s_suffix(mon_nam(magr)), mhis(mdef)); + } + break; + } + res = eat_brains(magr, mdef, vis, &tmp); + break; + case AD_SLIM: + if (cancelled) + break; /* physical damage only */ + if (!rn2(4) && !slimeproof(pd)) { + if (!munslime(mdef, FALSE) && mdef->mhp > 0) { + if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, vis)) + pd = mdef->data; + mdef->mstrategy &= ~STRAT_WAITFORU; + res = MM_HIT; + } + /* munslime attempt could have been fatal, + potentially to multiple monsters (SCR_FIRE) */ + if (magr->mhp < 1) + res |= MM_AGR_DIED; + if (mdef->mhp < 1) + res |= MM_DEF_DIED; + tmp = 0; + } + break; + case AD_STCK: + if (cancelled) + tmp = 0; + break; + case AD_WRAP: /* monsters cannot grab one another, it's too hard */ + if (magr->mcan) + tmp = 0; + break; + case AD_ENCH: + /* there's no msomearmor() function, so just do damage */ + /* if (cancelled) break; */ + break; + default: + tmp = 0; + break; + } + if (!tmp) + return res; - return (MM_DEF_DIED | (grow_up(magr,mdef) ? 0 : MM_AGR_DIED)); - } - return (res == MM_AGR_DIED) ? MM_AGR_DIED : MM_HIT; + if ((mdef->mhp -= tmp) < 1) { + if (m_at(mdef->mx, mdef->my) == magr) { /* see gulpmm() */ + remove_monster(mdef->mx, mdef->my); + mdef->mhp = 1; /* otherwise place_monster will complain */ + place_monster(mdef, mdef->mx, mdef->my); + mdef->mhp = 0; + } + monkilled(mdef, "", (int) mattk->adtyp); + if (mdef->mhp > 0) + return res; /* mdef lifesaved */ + else if (res == MM_AGR_DIED) + return (MM_DEF_DIED | MM_AGR_DIED); + + if (mattk->adtyp == AD_DGST) { + /* various checks similar to dog_eat and meatobj. + * after monkilled() to provide better message ordering */ + if (mdef->cham >= LOW_PM) { + (void) newcham(magr, (struct permonst *) 0, FALSE, TRUE); + } else if (pd == &mons[PM_GREEN_SLIME] && !slimeproof(pa)) { + (void) newcham(magr, &mons[PM_GREEN_SLIME], FALSE, TRUE); + } else if (pd == &mons[PM_WRAITH]) { + (void) grow_up(magr, (struct monst *) 0); + /* don't grow up twice */ + return (MM_DEF_DIED | (magr->mhp > 0 ? 0 : MM_AGR_DIED)); + } else if (pd == &mons[PM_NURSE]) { + magr->mhp = magr->mhpmax; + } + } + /* caveat: above digestion handling doesn't keep `pa' up to date */ + + return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + } + return (res == MM_AGR_DIED) ? MM_AGR_DIED : MM_HIT; } void @@ -1243,12 +1332,13 @@ paralyze_monst(mon, amt) struct monst *mon; int amt; { - if (amt > 127) amt = 127; + if (amt > 127) + amt = 127; - mon->mcanmove = 0; - mon->mfrozen = amt; - mon->meating = 0; /* terminate any meal-in-progress */ - mon->mstrategy &= ~STRAT_WAITFORU; + mon->mcanmove = 0; + mon->mfrozen = amt; + mon->meating = 0; /* terminate any meal-in-progress */ + mon->mstrategy &= ~STRAT_WAITFORU; } /* `mon' is hit by a sleep attack; return 1 if it's affected, 0 otherwise */ @@ -1257,21 +1347,21 @@ sleep_monst(mon, amt, how) struct monst *mon; int amt, how; { - if (resists_sleep(mon) || - (how >= 0 && resist(mon, (char)how, 0, NOTELL))) { - shieldeff(mon->mx, mon->my); - } else if (mon->mcanmove) { - finish_meating(mon); /* terminate any meal-in-progress */ - amt += (int) mon->mfrozen; - if (amt > 0) { /* sleep for N turns */ - mon->mcanmove = 0; - mon->mfrozen = min(amt, 127); - } else { /* sleep until awakened */ - mon->msleeping = 1; - } - return 1; - } - return 0; + if (resists_sleep(mon) + || (how >= 0 && resist(mon, (char) how, 0, NOTELL))) { + shieldeff(mon->mx, mon->my); + } else if (mon->mcanmove) { + finish_meating(mon); /* terminate any meal-in-progress */ + amt += (int) mon->mfrozen; + if (amt > 0) { /* sleep for N turns */ + mon->mcanmove = 0; + mon->mfrozen = min(amt, 127); + } else { /* sleep until awakened */ + mon->msleeping = 1; + } + return 1; + } + return 0; } /* sleeping grabber releases, engulfer doesn't; don't use for paralysis! */ @@ -1279,11 +1369,11 @@ void slept_monst(mon) struct monst *mon; { - if ((mon->msleeping || !mon->mcanmove) && mon == u.ustuck && - !sticks(youmonst.data) && !u.uswallow) { - pline("%s grip relaxes.", s_suffix(Monnam(mon))); - unstuck(mon); - } + if ((mon->msleeping || !mon->mcanmove) && mon == u.ustuck + && !sticks(youmonst.data) && !u.uswallow) { + pline("%s grip relaxes.", s_suffix(Monnam(mon))); + unstuck(mon); + } } void @@ -1291,19 +1381,20 @@ rustm(mdef, obj) register struct monst *mdef; register struct obj *obj; { - int dmgtyp; + int dmgtyp; - if (!mdef || !obj) return; /* just in case */ - /* AD_ACID is handled in passivemm */ - if (dmgtype(mdef->data, AD_CORR)) - dmgtyp = ERODE_CORRODE; - else if (dmgtype(mdef->data, AD_RUST)) - dmgtyp = ERODE_RUST; - else if (dmgtype(mdef->data, AD_FIRE)) - dmgtyp = ERODE_BURN; - else - return; - (void) erode_obj(obj, NULL, dmgtyp, EF_GREASE | EF_VERBOSE); + if (!mdef || !obj) + return; /* just in case */ + /* AD_ACID is handled in passivemm */ + if (dmgtype(mdef->data, AD_CORR)) + dmgtyp = ERODE_CORRODE; + else if (dmgtype(mdef->data, AD_RUST)) + dmgtyp = ERODE_RUST; + else if (dmgtype(mdef->data, AD_FIRE)) + dmgtyp = ERODE_BURN; + else + return; + (void) erode_obj(obj, NULL, dmgtyp, EF_GREASE | EF_VERBOSE); } STATIC_OVL void @@ -1312,10 +1403,10 @@ struct monst *magr, *mdef; struct obj *otemp; { if (flags.verbose && !Blind && mon_visible(magr)) { - pline("%s %s %s%s %s at %s.", Monnam(magr), - (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings", - (otemp->quan > 1L) ? "one of " : "", - mhis(magr), xname(otemp), mon_nam(mdef)); + pline("%s %s %s%s %s at %s.", Monnam(magr), + (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings", + (otemp->quan > 1L) ? "one of " : "", mhis(magr), xname(otemp), + mon_nam(mdef)); } } @@ -1324,144 +1415,155 @@ struct obj *otemp; * handled above. Returns same values as mattackm. */ STATIC_OVL int -passivemm(magr,mdef,mhit,mdead) +passivemm(magr, mdef, mhit, mdead) register struct monst *magr, *mdef; boolean mhit; int mdead; { - register struct permonst *mddat = mdef->data; - register struct permonst *madat = magr->data; - char buf[BUFSZ]; - int i, tmp; + register struct permonst *mddat = mdef->data; + register struct permonst *madat = magr->data; + char buf[BUFSZ]; + int i, tmp; - for(i = 0; ; i++) { - if(i >= NATTK) return (mdead | mhit); /* no passive attacks */ - if(mddat->mattk[i].aatyp == AT_NONE) break; - } - if (mddat->mattk[i].damn) - tmp = d((int)mddat->mattk[i].damn, - (int)mddat->mattk[i].damd); - else if(mddat->mattk[i].damd) - tmp = d((int)mddat->mlevel+1, (int)mddat->mattk[i].damd); - else - tmp = 0; + for (i = 0;; i++) { + if (i >= NATTK) + return (mdead | mhit); /* no passive attacks */ + if (mddat->mattk[i].aatyp == AT_NONE) + break; + } + if (mddat->mattk[i].damn) + tmp = d((int) mddat->mattk[i].damn, (int) mddat->mattk[i].damd); + else if (mddat->mattk[i].damd) + tmp = d((int) mddat->mlevel + 1, (int) mddat->mattk[i].damd); + else + tmp = 0; - /* These affect the enemy even if defender killed */ - switch(mddat->mattk[i].adtyp) { - case AD_ACID: - if (mhit && !rn2(2)) { - Strcpy(buf, Monnam(magr)); - if(canseemon(magr)) - pline("%s is splashed by %s acid!", - buf, s_suffix(mon_nam(mdef))); - if (resists_acid(magr)) { - if(canseemon(magr)) - pline("%s is not affected.", Monnam(magr)); - tmp = 0; - } - } else tmp = 0; - if (!rn2(30)) erode_armor(magr, ERODE_CORRODE); - if (!rn2(6)) acid_damage(MON_WEP(magr)); - goto assess_dmg; - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - if (mhit && !mdef->mcan && otmp) { - (void) drain_item(otmp); - /* No message */ - } - break; - default: - break; - } - if (mdead || mdef->mcan) return (mdead|mhit); + /* These affect the enemy even if defender killed */ + switch (mddat->mattk[i].adtyp) { + case AD_ACID: + if (mhit && !rn2(2)) { + Strcpy(buf, Monnam(magr)); + if (canseemon(magr)) + pline("%s is splashed by %s acid!", buf, + s_suffix(mon_nam(mdef))); + if (resists_acid(magr)) { + if (canseemon(magr)) + pline("%s is not affected.", Monnam(magr)); + tmp = 0; + } + } else + tmp = 0; + if (!rn2(30)) + erode_armor(magr, ERODE_CORRODE); + if (!rn2(6)) + acid_damage(MON_WEP(magr)); + goto assess_dmg; + case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ + if (mhit && !mdef->mcan && otmp) { + (void) drain_item(otmp); + /* No message */ + } + break; + default: + break; + } + if (mdead || mdef->mcan) + return (mdead | mhit); - /* These affect the enemy only if defender is still alive */ - if (rn2(3)) switch(mddat->mattk[i].adtyp) { - case AD_PLYS: /* Floating eye */ - if (tmp > 127) tmp = 127; - if (mddat == &mons[PM_FLOATING_EYE]) { - if (!rn2(4)) tmp = 127; - if (magr->mcansee && haseyes(madat) && mdef->mcansee && - (perceives(madat) || !mdef->minvis)) { - Sprintf(buf, "%s gaze is reflected by %%s %%s.", - s_suffix(Monnam(mdef))); - if (mon_reflects(magr, - canseemon(magr) ? buf : (char *)0)) - return(mdead|mhit); - Strcpy(buf, Monnam(magr)); - if(canseemon(magr)) - pline("%s is frozen by %s gaze!", - buf, s_suffix(mon_nam(mdef))); - paralyze_monst(magr, tmp); - return (mdead|mhit); - } - } else { /* gelatinous cube */ - Strcpy(buf, Monnam(magr)); - if(canseemon(magr)) - pline("%s is frozen by %s.", buf, mon_nam(mdef)); - paralyze_monst(magr, tmp); - return (mdead|mhit); - } - return 1; - case AD_COLD: - if (resists_cold(magr)) { - if (canseemon(magr)) { - pline("%s is mildly chilly.", Monnam(magr)); - golemeffects(magr, AD_COLD, tmp); - } - tmp = 0; - break; - } - if(canseemon(magr)) - pline("%s is suddenly very cold!", Monnam(magr)); - mdef->mhp += tmp / 2; - if (mdef->mhpmax < mdef->mhp) mdef->mhpmax = mdef->mhp; - if (mdef->mhpmax > ((int) (mdef->m_lev+1) * 8)) - (void)split_mon(mdef, magr); - break; - case AD_STUN: - if (!magr->mstun) { - magr->mstun = 1; - if (canseemon(magr)) - pline("%s %s...", Monnam(magr), - makeplural(stagger(magr->data, "stagger"))); - } - tmp = 0; - break; - case AD_FIRE: - if (resists_fire(magr)) { - if (canseemon(magr)) { - pline("%s is mildly warmed.", Monnam(magr)); - golemeffects(magr, AD_FIRE, tmp); - } - tmp = 0; - break; - } - if(canseemon(magr)) - pline("%s is suddenly very hot!", Monnam(magr)); - break; - case AD_ELEC: - if (resists_elec(magr)) { - if (canseemon(magr)) { - pline("%s is mildly tingled.", Monnam(magr)); - golemeffects(magr, AD_ELEC, tmp); - } - tmp = 0; - break; - } - if(canseemon(magr)) - pline("%s is jolted with electricity!", Monnam(magr)); - break; - default: tmp = 0; - break; - } - else tmp = 0; + /* These affect the enemy only if defender is still alive */ + if (rn2(3)) + switch (mddat->mattk[i].adtyp) { + case AD_PLYS: /* Floating eye */ + if (tmp > 127) + tmp = 127; + if (mddat == &mons[PM_FLOATING_EYE]) { + if (!rn2(4)) + tmp = 127; + if (magr->mcansee && haseyes(madat) && mdef->mcansee + && (perceives(madat) || !mdef->minvis)) { + Sprintf(buf, "%s gaze is reflected by %%s %%s.", + s_suffix(Monnam(mdef))); + if (mon_reflects(magr, + canseemon(magr) ? buf : (char *) 0)) + return (mdead | mhit); + Strcpy(buf, Monnam(magr)); + if (canseemon(magr)) + pline("%s is frozen by %s gaze!", buf, + s_suffix(mon_nam(mdef))); + paralyze_monst(magr, tmp); + return (mdead | mhit); + } + } else { /* gelatinous cube */ + Strcpy(buf, Monnam(magr)); + if (canseemon(magr)) + pline("%s is frozen by %s.", buf, mon_nam(mdef)); + paralyze_monst(magr, tmp); + return (mdead | mhit); + } + return 1; + case AD_COLD: + if (resists_cold(magr)) { + if (canseemon(magr)) { + pline("%s is mildly chilly.", Monnam(magr)); + golemeffects(magr, AD_COLD, tmp); + } + tmp = 0; + break; + } + if (canseemon(magr)) + pline("%s is suddenly very cold!", Monnam(magr)); + mdef->mhp += tmp / 2; + if (mdef->mhpmax < mdef->mhp) + mdef->mhpmax = mdef->mhp; + if (mdef->mhpmax > ((int) (mdef->m_lev + 1) * 8)) + (void) split_mon(mdef, magr); + break; + case AD_STUN: + if (!magr->mstun) { + magr->mstun = 1; + if (canseemon(magr)) + pline("%s %s...", Monnam(magr), + makeplural(stagger(magr->data, "stagger"))); + } + tmp = 0; + break; + case AD_FIRE: + if (resists_fire(magr)) { + if (canseemon(magr)) { + pline("%s is mildly warmed.", Monnam(magr)); + golemeffects(magr, AD_FIRE, tmp); + } + tmp = 0; + break; + } + if (canseemon(magr)) + pline("%s is suddenly very hot!", Monnam(magr)); + break; + case AD_ELEC: + if (resists_elec(magr)) { + if (canseemon(magr)) { + pline("%s is mildly tingled.", Monnam(magr)); + golemeffects(magr, AD_ELEC, tmp); + } + tmp = 0; + break; + } + if (canseemon(magr)) + pline("%s is jolted with electricity!", Monnam(magr)); + break; + default: + tmp = 0; + break; + } + else + tmp = 0; - assess_dmg: - if((magr->mhp -= tmp) <= 0) { - monkilled(magr, "", (int)mddat->mattk[i].adtyp); - return (mdead | mhit | MM_AGR_DIED); - } - return (mdead | mhit); +assess_dmg: + if ((magr->mhp -= tmp) <= 0) { + monkilled(magr, "", (int) mddat->mattk[i].adtyp); + return (mdead | mhit | MM_AGR_DIED); + } + return (mdead | mhit); } /* hero or monster has successfully hit target mon with drain energy attack */ @@ -1470,10 +1572,11 @@ xdrainenergym(mon, givemsg) struct monst *mon; boolean givemsg; { - if (mon->mspec_used < 20 && /* limit draining */ - (attacktype(mon->data, AT_MAGC) || attacktype(mon->data, AT_BREA))) { - mon->mspec_used += d(2, 2); - if (givemsg) pline("%s seems lethargic.", Monnam(mon)); + if (mon->mspec_used < 20 && /* limit draining */ + (attacktype(mon->data, AT_MAGC) || attacktype(mon->data, AT_BREA))) { + mon->mspec_used += d(2, 2); + if (givemsg) + pline("%s seems lethargic.", Monnam(mon)); } } @@ -1493,29 +1596,29 @@ int aatyp; case AT_GAZE: case AT_BREA: case AT_MAGC: - w_mask = ~0L; /* special case; no defense needed */ - break; + w_mask = ~0L; /* special case; no defense needed */ + break; case AT_CLAW: case AT_TUCH: case AT_WEAP: - w_mask = W_ARMG; /* caller needs to check for weapon */ - break; + w_mask = W_ARMG; /* caller needs to check for weapon */ + break; case AT_KICK: - w_mask = W_ARMF; - break; + w_mask = W_ARMF; + break; case AT_BUTT: - w_mask = W_ARMH; - break; + w_mask = W_ARMH; + break; case AT_HUGS: - w_mask = (W_ARMC|W_ARMG); /* attacker needs both to be protected */ - break; + w_mask = (W_ARMC | W_ARMG); /* attacker needs both to be protected */ + break; case AT_BITE: case AT_STNG: case AT_ENGL: case AT_TENT: default: - w_mask = 0L; /* no defense available */ - break; + w_mask = 0L; /* no defense available */ + break; } return w_mask; } diff --git a/src/mhitu.c b/src/mhitu.c index 741c6e0c3..90a439234 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhitu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhitu.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.125 $ */ /* NetHack 3.6 mhitu.c $Date: 2012/02/05 04:26:48 $ $Revision: 1.104 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,20 +8,21 @@ STATIC_VAR NEARDATA struct obj *otmp; -STATIC_DCL boolean FDECL(u_slip_free, (struct monst *,struct attack *)); -STATIC_DCL int FDECL(passiveum, (struct permonst *,struct monst *,struct attack *)); +STATIC_DCL boolean FDECL(u_slip_free, (struct monst *, struct attack *)); +STATIC_DCL int FDECL(passiveum, + (struct permonst *, struct monst *, struct attack *)); STATIC_DCL void FDECL(mayberem, (struct obj *, const char *)); STATIC_DCL boolean FDECL(diseasemu, (struct permonst *)); -STATIC_DCL int FDECL(hitmu, (struct monst *,struct attack *)); -STATIC_DCL int FDECL(gulpmu, (struct monst *,struct attack *)); -STATIC_DCL int FDECL(explmu, (struct monst *,struct attack *,BOOLEAN_P)); -STATIC_DCL void FDECL(missmu,(struct monst *,BOOLEAN_P,struct attack *)); -STATIC_DCL void FDECL(mswings,(struct monst *,struct obj *)); -STATIC_DCL void FDECL(wildmiss, (struct monst *,struct attack *)); +STATIC_DCL int FDECL(hitmu, (struct monst *, struct attack *)); +STATIC_DCL int FDECL(gulpmu, (struct monst *, struct attack *)); +STATIC_DCL int FDECL(explmu, (struct monst *, struct attack *, BOOLEAN_P)); +STATIC_DCL void FDECL(missmu, (struct monst *, BOOLEAN_P, struct attack *)); +STATIC_DCL void FDECL(mswings, (struct monst *, struct obj *)); +STATIC_DCL void FDECL(wildmiss, (struct monst *, struct attack *)); -STATIC_DCL void FDECL(hitmsg,(struct monst *,struct attack *)); +STATIC_DCL void FDECL(hitmsg, (struct monst *, struct attack *)); /* See comment in mhitm.c. If we use this a lot it probably should be */ /* changed to a parameter to mhitu. */ @@ -32,76 +33,71 @@ hitmsg(mtmp, mattk) register struct monst *mtmp; register struct attack *mattk; { - int compat; + int compat; - /* Note: if opposite gender, "seductively" */ - /* If same gender, "engagingly" for nymph, normal msg for others */ - if((compat = could_seduce(mtmp, &youmonst, mattk)) - && !mtmp->mcan && !mtmp->mspec_used) { - pline("%s %s you %s.", Monnam(mtmp), - Blind ? "talks to" : "smiles at", - compat == 2 ? "engagingly" : "seductively"); - } else - switch (mattk->aatyp) { - case AT_BITE: - pline("%s bites!", Monnam(mtmp)); - break; - case AT_KICK: - pline("%s kicks%c", Monnam(mtmp), - thick_skinned(youmonst.data) ? '.' : '!'); - break; - case AT_STNG: - pline("%s stings!", Monnam(mtmp)); - break; - case AT_BUTT: - pline("%s butts!", Monnam(mtmp)); - break; - case AT_TUCH: - pline("%s touches you!", Monnam(mtmp)); - break; - case AT_TENT: - pline("%s tentacles suck you!", - s_suffix(Monnam(mtmp))); - break; - case AT_EXPL: - case AT_BOOM: - pline("%s explodes!", Monnam(mtmp)); - break; - default: - pline("%s hits!", Monnam(mtmp)); - } + /* Note: if opposite gender, "seductively" */ + /* If same gender, "engagingly" for nymph, normal msg for others */ + if ((compat = could_seduce(mtmp, &youmonst, mattk)) && !mtmp->mcan + && !mtmp->mspec_used) { + pline("%s %s you %s.", Monnam(mtmp), Blind ? "talks to" : "smiles at", + compat == 2 ? "engagingly" : "seductively"); + } else + switch (mattk->aatyp) { + case AT_BITE: + pline("%s bites!", Monnam(mtmp)); + break; + case AT_KICK: + pline("%s kicks%c", Monnam(mtmp), + thick_skinned(youmonst.data) ? '.' : '!'); + break; + case AT_STNG: + pline("%s stings!", Monnam(mtmp)); + break; + case AT_BUTT: + pline("%s butts!", Monnam(mtmp)); + break; + case AT_TUCH: + pline("%s touches you!", Monnam(mtmp)); + break; + case AT_TENT: + pline("%s tentacles suck you!", s_suffix(Monnam(mtmp))); + break; + case AT_EXPL: + case AT_BOOM: + pline("%s explodes!", Monnam(mtmp)); + break; + default: + pline("%s hits!", Monnam(mtmp)); + } } -STATIC_OVL void -missmu(mtmp, nearmiss, mattk) /* monster missed you */ +STATIC_OVL void missmu(mtmp, nearmiss, mattk) /* monster missed you */ register struct monst *mtmp; register boolean nearmiss; register struct attack *mattk; { - if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); - if(could_seduce(mtmp, &youmonst, mattk) && !mtmp->mcan) - pline("%s pretends to be friendly.", Monnam(mtmp)); - else { - if (!flags.verbose || !nearmiss) - pline("%s misses.", Monnam(mtmp)); - else - pline("%s just misses!", Monnam(mtmp)); - } - stop_occupation(); + if (could_seduce(mtmp, &youmonst, mattk) && !mtmp->mcan) + pline("%s pretends to be friendly.", Monnam(mtmp)); + else { + if (!flags.verbose || !nearmiss) + pline("%s misses.", Monnam(mtmp)); + else + pline("%s just misses!", Monnam(mtmp)); + } + stop_occupation(); } -STATIC_OVL void -mswings(mtmp, otemp) /* monster swings obj */ +STATIC_OVL void mswings(mtmp, otemp) /* monster swings obj */ struct monst *mtmp; struct obj *otemp; { if (flags.verbose && !Blind && mon_visible(mtmp)) { - pline("%s %s %s%s %s.", Monnam(mtmp), - (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings", - (otemp->quan > 1L) ? "one of " : "", - mhis(mtmp), xname(otemp)); + pline("%s %s %s%s %s.", Monnam(mtmp), + (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings", + (otemp->quan > 1L) ? "one of " : "", mhis(mtmp), xname(otemp)); } } @@ -111,144 +107,152 @@ mpoisons_subj(mtmp, mattk) struct monst *mtmp; struct attack *mattk; { - if (mattk->aatyp == AT_WEAP) { - struct obj *mwep = (mtmp == &youmonst) ? uwep : MON_WEP(mtmp); - /* "Foo's attack was poisoned." is pretty lame, but at least - it's better than "sting" when not a stinging attack... */ - return (!mwep || !mwep->opoisoned) ? "attack" : "weapon"; - } else { - return (mattk->aatyp == AT_TUCH) ? "contact" : - (mattk->aatyp == AT_GAZE) ? "gaze" : - (mattk->aatyp == AT_BITE) ? "bite" : "sting"; - } + if (mattk->aatyp == AT_WEAP) { + struct obj *mwep = (mtmp == &youmonst) ? uwep : MON_WEP(mtmp); + /* "Foo's attack was poisoned." is pretty lame, but at least + it's better than "sting" when not a stinging attack... */ + return (!mwep || !mwep->opoisoned) ? "attack" : "weapon"; + } else { + return (mattk->aatyp == AT_TUCH) + ? "contact" + : (mattk->aatyp == AT_GAZE) + ? "gaze" + : (mattk->aatyp == AT_BITE) ? "bite" : "sting"; + } } /* called when your intrinsic speed is taken away */ void u_slow_down() { - HFast = 0L; - if (!Fast) - You("slow down."); - else /* speed boots */ - Your("quickness feels less natural."); - exercise(A_DEX, FALSE); + HFast = 0L; + if (!Fast) + You("slow down."); + else /* speed boots */ + Your("quickness feels less natural."); + exercise(A_DEX, FALSE); } -STATIC_OVL void -wildmiss(mtmp, mattk) /* monster attacked your displaced image */ - register struct monst *mtmp; - register struct attack *mattk; +STATIC_OVL void wildmiss(mtmp, + mattk) /* monster attacked your displaced image */ +register struct monst *mtmp; +register struct attack *mattk; { - int compat; + int compat; - /* no map_invisible() -- no way to tell where _this_ is coming from */ + /* no map_invisible() -- no way to tell where _this_ is coming from */ - if (!flags.verbose) return; - if (!cansee(mtmp->mx, mtmp->my)) return; - /* maybe it's attacking an image around the corner? */ + if (!flags.verbose) + return; + if (!cansee(mtmp->mx, mtmp->my)) + return; + /* maybe it's attacking an image around the corner? */ - compat = (mattk->adtyp == AD_SEDU || mattk->adtyp == AD_SSEX) && - could_seduce(mtmp, &youmonst, (struct attack *)0); + compat = (mattk->adtyp == AD_SEDU || mattk->adtyp == AD_SSEX) + && could_seduce(mtmp, &youmonst, (struct attack *) 0); - if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) { - const char *swings = - mattk->aatyp == AT_BITE ? "snaps" : - mattk->aatyp == AT_KICK ? "kicks" : - (mattk->aatyp == AT_STNG || - mattk->aatyp == AT_BUTT || - nolimbs(mtmp->data)) ? "lunges" : "swings"; + if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) { + const char *swings = + mattk->aatyp == AT_BITE + ? "snaps" + : mattk->aatyp == AT_KICK + ? "kicks" + : (mattk->aatyp == AT_STNG || mattk->aatyp == AT_BUTT + || nolimbs(mtmp->data)) + ? "lunges" + : "swings"; - if (compat) - pline("%s tries to touch you and misses!", Monnam(mtmp)); - else - switch(rn2(3)) { - case 0: pline("%s %s wildly and misses!", Monnam(mtmp), - swings); - break; - case 1: pline("%s attacks a spot beside you.", Monnam(mtmp)); - break; - case 2: pline("%s strikes at %s!", Monnam(mtmp), - levl[mtmp->mux][mtmp->muy].typ == WATER - ? "empty water" : "thin air"); - break; - default:pline("%s %s wildly!", Monnam(mtmp), swings); - break; - } + if (compat) + pline("%s tries to touch you and misses!", Monnam(mtmp)); + else + switch (rn2(3)) { + case 0: + pline("%s %s wildly and misses!", Monnam(mtmp), swings); + break; + case 1: + pline("%s attacks a spot beside you.", Monnam(mtmp)); + break; + case 2: + pline("%s strikes at %s!", Monnam(mtmp), + levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water" + : "thin air"); + break; + default: + pline("%s %s wildly!", Monnam(mtmp), swings); + break; + } - } else if (Displaced) { - if (compat) - pline("%s smiles %s at your %sdisplaced image...", - Monnam(mtmp), - compat == 2 ? "engagingly" : "seductively", - Invis ? "invisible " : ""); - else - pline("%s strikes at your %sdisplaced image and misses you!", - /* Note: if you're both invisible and displaced, - * only monsters which see invisible will attack your - * displaced image, since the displaced image is also - * invisible. - */ - Monnam(mtmp), - Invis ? "invisible " : ""); + } else if (Displaced) { + if (compat) + pline("%s smiles %s at your %sdisplaced image...", Monnam(mtmp), + compat == 2 ? "engagingly" : "seductively", + Invis ? "invisible " : ""); + else + pline("%s strikes at your %sdisplaced image and misses you!", + /* Note: if you're both invisible and displaced, + * only monsters which see invisible will attack your + * displaced image, since the displaced image is also + * invisible. + */ + Monnam(mtmp), Invis ? "invisible " : ""); - } else if (Underwater) { - /* monsters may miss especially on water level where - bubbles shake the player here and there */ - if (compat) - pline("%s reaches towards your distorted image.",Monnam(mtmp)); - else - pline("%s is fooled by water reflections and misses!",Monnam(mtmp)); + } else if (Underwater) { + /* monsters may miss especially on water level where + bubbles shake the player here and there */ + if (compat) + pline("%s reaches towards your distorted image.", Monnam(mtmp)); + else + pline("%s is fooled by water reflections and misses!", + Monnam(mtmp)); - } else impossible("%s attacks you without knowing your location?", - Monnam(mtmp)); + } else + impossible("%s attacks you without knowing your location?", + Monnam(mtmp)); } void expels(mtmp, mdat, message) register struct monst *mtmp; -register struct permonst *mdat; /* if mtmp is polymorphed, mdat != mtmp->data */ +register struct permonst + *mdat; /* if mtmp is polymorphed, mdat != mtmp->data */ boolean message; { - if (message) { - if (is_animal(mdat)) - You("get regurgitated!"); - else { - char blast[40]; - register int i; + if (message) { + if (is_animal(mdat)) + You("get regurgitated!"); + else { + char blast[40]; + register int i; - blast[0] = '\0'; - for(i = 0; i < NATTK; i++) - if(mdat->mattk[i].aatyp == AT_ENGL) - break; - if (mdat->mattk[i].aatyp != AT_ENGL) - impossible("Swallower has no engulfing attack?"); - else { - if (is_whirly(mdat)) { - switch (mdat->mattk[i].adtyp) { - case AD_ELEC: - Strcpy(blast, - " in a shower of sparks"); - break; - case AD_COLD: - Strcpy(blast, - " in a blast of frost"); - break; - } - } else - Strcpy(blast, " with a squelch"); - You("get expelled from %s%s!", - mon_nam(mtmp), blast); - } - } - } - unstuck(mtmp); /* ball&chain returned in unstuck() */ - mnexto(mtmp); - newsym(u.ux,u.uy); - spoteffects(TRUE); - /* to cover for a case where mtmp is not in a next square */ - if(um_dist(mtmp->mx,mtmp->my,1)) - pline("Brrooaa... You land hard at some distance."); + blast[0] = '\0'; + for (i = 0; i < NATTK; i++) + if (mdat->mattk[i].aatyp == AT_ENGL) + break; + if (mdat->mattk[i].aatyp != AT_ENGL) + impossible("Swallower has no engulfing attack?"); + else { + if (is_whirly(mdat)) { + switch (mdat->mattk[i].adtyp) { + case AD_ELEC: + Strcpy(blast, " in a shower of sparks"); + break; + case AD_COLD: + Strcpy(blast, " in a blast of frost"); + break; + } + } else + Strcpy(blast, " with a squelch"); + You("get expelled from %s%s!", mon_nam(mtmp), blast); + } + } + } + unstuck(mtmp); /* ball&chain returned in unstuck() */ + mnexto(mtmp); + newsym(u.ux, u.uy); + spoteffects(TRUE); + /* to cover for a case where mtmp is not in a next square */ + if (um_dist(mtmp->mx, mtmp->my, 1)) + pline("Brrooaa... You land hard at some distance."); } /* select a monster's next attack, possibly substituting for its usual one */ @@ -263,14 +267,13 @@ struct attack *alt_attk_buf; /* prevent a monster with two consecutive disease or hunger attacks from hitting with both of them on the same turn; if the first has already hit, switch to a stun attack for the second */ - if (indx > 0 && prev_result[indx - 1] > 0 && - (attk->adtyp == AD_DISE || - attk->adtyp == AD_PEST || - attk->adtyp == AD_FAMN) && - attk->adtyp == mptr->mattk[indx - 1].adtyp) { - *alt_attk_buf = *attk; - attk = alt_attk_buf; - attk->adtyp = AD_STUN; + if (indx > 0 && prev_result[indx - 1] > 0 + && (attk->adtyp == AD_DISE || attk->adtyp == AD_PEST + || attk->adtyp == AD_FAMN) + && attk->adtyp == mptr->mattk[indx - 1].adtyp) { + *alt_attk_buf = *attk; + attk = alt_attk_buf; + attk->adtyp = AD_STUN; } return attk; } @@ -286,444 +289,467 @@ struct attack *alt_attk_buf; */ int mattacku(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - struct attack *mattk, alt_attk; - int i, j, tmp, sum[NATTK]; - struct permonst *mdat = mtmp->data; - boolean ranged = (distu(mtmp->mx, mtmp->my) > 3); - /* Is it near you? Affects your actions */ - boolean range2 = !monnear(mtmp, mtmp->mux, mtmp->muy); - /* Does it think it's near you? Affects its actions */ - boolean foundyou = (mtmp->mux==u.ux && mtmp->muy==u.uy); - /* Is it attacking you or your image? */ - boolean youseeit = canseemon(mtmp); - /* Might be attacking your image around the corner, or - * invisible, or you might be blind.... - */ - boolean skipnonmagc = FALSE; - /* Are further physical attack attempts useless? */ + struct attack *mattk, alt_attk; + int i, j, tmp, sum[NATTK]; + struct permonst *mdat = mtmp->data; + boolean ranged = (distu(mtmp->mx, mtmp->my) > 3); + /* Is it near you? Affects your actions */ + boolean range2 = !monnear(mtmp, mtmp->mux, mtmp->muy); + /* Does it think it's near you? Affects its actions */ + boolean foundyou = (mtmp->mux == u.ux && mtmp->muy == u.uy); + /* Is it attacking you or your image? */ + boolean youseeit = canseemon(mtmp); + /* Might be attacking your image around the corner, or + * invisible, or you might be blind.... + */ + boolean skipnonmagc = FALSE; + /* Are further physical attack attempts useless? */ - if(!ranged) nomul(0); - if(mtmp->mhp <= 0 || (Underwater && !is_swimmer(mtmp->data))) - return(0); + if (!ranged) + nomul(0); + if (mtmp->mhp <= 0 || (Underwater && !is_swimmer(mtmp->data))) + return (0); - /* If swallowed, can only be affected by u.ustuck */ - if(u.uswallow) { - if(mtmp != u.ustuck) - return(0); - u.ustuck->mux = u.ux; - u.ustuck->muy = u.uy; - range2 = 0; - foundyou = 1; - if(u.uinvulnerable) return (0); /* stomachs can't hurt you! */ - } + /* If swallowed, can only be affected by u.ustuck */ + if (u.uswallow) { + if (mtmp != u.ustuck) + return (0); + u.ustuck->mux = u.ux; + u.ustuck->muy = u.uy; + range2 = 0; + foundyou = 1; + if (u.uinvulnerable) + return (0); /* stomachs can't hurt you! */ + } - else if (u.usteed) { - if (mtmp == u.usteed) - /* Your steed won't attack you */ - return (0); - /* Orcs like to steal and eat horses and the like */ - if (!rn2(is_orc(mtmp->data) ? 2 : 4) && - distu(mtmp->mx, mtmp->my) <= 2) { - /* Attack your steed instead */ - i = mattackm(mtmp, u.usteed); - if ((i & MM_AGR_DIED)) - return (1); - /* make sure steed is still alive and within range */ - if ((i & MM_DEF_DIED) || !u.usteed || - distu(mtmp->mx, mtmp->my) > 2) - return (0); - /* Let your steed retaliate */ - return (!!(mattackm(u.usteed, mtmp) & MM_DEF_DIED)); - } - } + else if (u.usteed) { + if (mtmp == u.usteed) + /* Your steed won't attack you */ + return (0); + /* Orcs like to steal and eat horses and the like */ + if (!rn2(is_orc(mtmp->data) ? 2 : 4) + && distu(mtmp->mx, mtmp->my) <= 2) { + /* Attack your steed instead */ + i = mattackm(mtmp, u.usteed); + if ((i & MM_AGR_DIED)) + return (1); + /* make sure steed is still alive and within range */ + if ((i & MM_DEF_DIED) || !u.usteed + || distu(mtmp->mx, mtmp->my) > 2) + return (0); + /* Let your steed retaliate */ + return (!!(mattackm(u.usteed, mtmp) & MM_DEF_DIED)); + } + } - if (u.uundetected && !range2 && foundyou && !u.uswallow) { - if (!canspotmon(mtmp)) map_invisible(mtmp->mx, mtmp->my); - u.uundetected = 0; - if (is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) { - /* ceiling hider */ - coord cc; /* maybe we need a unexto() function? */ - struct obj *obj; + if (u.uundetected && !range2 && foundyou && !u.uswallow) { + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + u.uundetected = 0; + if (is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) { + /* ceiling hider */ + coord cc; /* maybe we need a unexto() function? */ + struct obj *obj; - You("fall from the %s!", ceiling(u.ux,u.uy)); - /* take monster off map now so that its location - is eligible for placing hero; we assume that a - removed monster remembers its old spot */ - remove_monster(mtmp->mx, mtmp->my); - if (!enexto(&cc, u.ux, u.uy, youmonst.data) || - /* a fish won't voluntarily swap positions - when it's in water and hero is over land */ - (mtmp->data->mlet == S_EEL && - is_pool(mtmp->mx, mtmp->my) && - !is_pool(u.ux, u.uy))) { - /* couldn't find any spot for hero; this used to - kill off attacker, but now we just give a "miss" - message and keep both mtmp and hero at their - original positions; hero has become unconcealed - so mtmp's next move will be a regular attack */ - place_monster(mtmp, mtmp->mx, mtmp->my); /* put back */ - newsym(u.ux, u.uy); /* u.uundetected was toggled */ - pline("%s draws back as you drop!", Monnam(mtmp)); - return 0; - } + You("fall from the %s!", ceiling(u.ux, u.uy)); + /* take monster off map now so that its location + is eligible for placing hero; we assume that a + removed monster remembers its old spot */ + remove_monster(mtmp->mx, mtmp->my); + if (!enexto(&cc, u.ux, u.uy, youmonst.data) || + /* a fish won't voluntarily swap positions + when it's in water and hero is over land */ + (mtmp->data->mlet == S_EEL && is_pool(mtmp->mx, mtmp->my) + && !is_pool(u.ux, u.uy))) { + /* couldn't find any spot for hero; this used to + kill off attacker, but now we just give a "miss" + message and keep both mtmp and hero at their + original positions; hero has become unconcealed + so mtmp's next move will be a regular attack */ + place_monster(mtmp, mtmp->mx, mtmp->my); /* put back */ + newsym(u.ux, u.uy); /* u.uundetected was toggled */ + pline("%s draws back as you drop!", Monnam(mtmp)); + return 0; + } - /* put mtmp at hero's spot and move hero to */ - newsym(mtmp->mx, mtmp->my); /* finish removal */ - place_monster(mtmp, u.ux, u.uy); - if (mtmp->wormno) { - worm_move(mtmp); - /* tail hasn't grown, so if it now occupies - then one of its original spots must be free */ - if (m_at(cc.x, cc.y)) - (void)enexto(&cc, u.ux, u.uy, youmonst.data); - } - teleds(cc.x, cc.y, TRUE); /* move hero */ - set_apparxy(mtmp); - newsym(u.ux, u.uy); + /* put mtmp at hero's spot and move hero to */ + newsym(mtmp->mx, mtmp->my); /* finish removal */ + place_monster(mtmp, u.ux, u.uy); + if (mtmp->wormno) { + worm_move(mtmp); + /* tail hasn't grown, so if it now occupies + then one of its original spots must be free */ + if (m_at(cc.x, cc.y)) + (void) enexto(&cc, u.ux, u.uy, youmonst.data); + } + teleds(cc.x, cc.y, TRUE); /* move hero */ + set_apparxy(mtmp); + newsym(u.ux, u.uy); - if (youmonst.data->mlet != S_PIERCER) - return(0); /* lurkers don't attack */ + if (youmonst.data->mlet != S_PIERCER) + return (0); /* lurkers don't attack */ - obj = which_armor(mtmp, WORN_HELMET); - if (obj && is_metallic(obj)) { - Your("blow glances off %s %s.", - s_suffix(mon_nam(mtmp)), helm_simple_name(obj)); - } else { - if (3 + find_mac(mtmp) <= rnd(20)) { - pline("%s is hit by a falling piercer (you)!", - Monnam(mtmp)); - if ((mtmp->mhp -= d(3,6)) < 1) - killed(mtmp); - } else - pline("%s is almost hit by a falling piercer (you)!", - Monnam(mtmp)); - } + obj = which_armor(mtmp, WORN_HELMET); + if (obj && is_metallic(obj)) { + Your("blow glances off %s %s.", s_suffix(mon_nam(mtmp)), + helm_simple_name(obj)); + } else { + if (3 + find_mac(mtmp) <= rnd(20)) { + pline("%s is hit by a falling piercer (you)!", + Monnam(mtmp)); + if ((mtmp->mhp -= d(3, 6)) < 1) + killed(mtmp); + } else + pline("%s is almost hit by a falling piercer (you)!", + Monnam(mtmp)); + } - } else { - /* surface hider */ - if (!youseeit) - pline("It tries to move where you are hiding."); - else { - /* Ugly kludge for eggs. The message is phrased so as - * to be directed at the monster, not the player, - * which makes "laid by you" wrong. For the - * parallelism to work, we can't rephrase it, so we - * zap the "laid by you" momentarily instead. - */ - struct obj *obj = level.objects[u.ux][u.uy]; + } else { + /* surface hider */ + if (!youseeit) + pline("It tries to move where you are hiding."); + else { + /* Ugly kludge for eggs. The message is phrased so as + * to be directed at the monster, not the player, + * which makes "laid by you" wrong. For the + * parallelism to work, we can't rephrase it, so we + * zap the "laid by you" momentarily instead. + */ + struct obj *obj = level.objects[u.ux][u.uy]; - if (obj || u.umonnum == PM_TRAPPER || - (youmonst.data->mlet == S_EEL && is_pool(u.ux, u.uy))) { - int save_spe = 0; /* suppress warning */ - if (obj) { - save_spe = obj->spe; - if (obj->otyp == EGG) obj->spe = 0; - } - if (youmonst.data->mlet == S_EEL || - u.umonnum == PM_TRAPPER) - pline("Wait, %s! There's a hidden %s named %s there!", - m_monnam(mtmp), youmonst.data->mname, plname); - else - pline("Wait, %s! There's a %s named %s hiding under %s!", - m_monnam(mtmp), youmonst.data->mname, plname, - doname(level.objects[u.ux][u.uy])); - if (obj) obj->spe = save_spe; - } else - impossible("hiding under nothing?"); - } - newsym(u.ux,u.uy); - } - return(0); - } + if (obj || u.umonnum == PM_TRAPPER + || (youmonst.data->mlet == S_EEL + && is_pool(u.ux, u.uy))) { + int save_spe = 0; /* suppress warning */ + if (obj) { + save_spe = obj->spe; + if (obj->otyp == EGG) + obj->spe = 0; + } + if (youmonst.data->mlet == S_EEL + || u.umonnum == PM_TRAPPER) + pline( + "Wait, %s! There's a hidden %s named %s there!", + m_monnam(mtmp), youmonst.data->mname, plname); + else + pline("Wait, %s! There's a %s named %s hiding under " + "%s!", + m_monnam(mtmp), youmonst.data->mname, plname, + doname(level.objects[u.ux][u.uy])); + if (obj) + obj->spe = save_spe; + } else + impossible("hiding under nothing?"); + } + newsym(u.ux, u.uy); + } + return (0); + } - /* hero might be a mimic, concealed via #monster */ - if (youmonst.data->mlet == S_MIMIC && youmonst.m_ap_type && - !range2 && foundyou && !u.uswallow) { - boolean sticky = sticks(youmonst.data); + /* hero might be a mimic, concealed via #monster */ + if (youmonst.data->mlet == S_MIMIC && youmonst.m_ap_type && !range2 + && foundyou && !u.uswallow) { + boolean sticky = sticks(youmonst.data); - if (!canspotmon(mtmp)) map_invisible(mtmp->mx, mtmp->my); - if (sticky && !youseeit) pline("It gets stuck on you."); - else pline("Wait, %s! That's a %s named %s!", - m_monnam(mtmp), youmonst.data->mname, plname); - if (sticky) u.ustuck = mtmp; - youmonst.m_ap_type = M_AP_NOTHING; - youmonst.mappearance = 0; - newsym(u.ux,u.uy); - return(0); - } + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + if (sticky && !youseeit) + pline("It gets stuck on you."); + else + pline("Wait, %s! That's a %s named %s!", m_monnam(mtmp), + youmonst.data->mname, plname); + if (sticky) + u.ustuck = mtmp; + youmonst.m_ap_type = M_AP_NOTHING; + youmonst.mappearance = 0; + newsym(u.ux, u.uy); + return (0); + } - /* non-mimic hero might be mimicking an object after eating m corpse */ - if (youmonst.m_ap_type == M_AP_OBJECT && !range2 && foundyou && !u.uswallow) { - if (!canspotmon(mtmp)) map_invisible(mtmp->mx, mtmp->my); - if (!youseeit) - pline("%s %s!", Something, - (likes_gold(mtmp->data) && youmonst.mappearance == GOLD_PIECE) ? - "tries to pick you up" : "disturbs you"); - else pline("Wait, %s! That %s is really %s named %s!", - m_monnam(mtmp), - mimic_obj_name(&youmonst), - an(mons[u.umonnum].mname), - plname); - if (multi < 0) { /* this should always be the case */ - char buf[BUFSZ]; - Sprintf(buf, "You appear to be %s again.", - Upolyd ? (const char *) an(youmonst.data->mname) : - (const char *) "yourself"); - unmul(buf); /* immediately stop mimicking */ - } - return 0; - } + /* non-mimic hero might be mimicking an object after eating m corpse */ + if (youmonst.m_ap_type == M_AP_OBJECT && !range2 && foundyou + && !u.uswallow) { + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + if (!youseeit) + pline("%s %s!", Something, (likes_gold(mtmp->data) + && youmonst.mappearance == GOLD_PIECE) + ? "tries to pick you up" + : "disturbs you"); + else + pline("Wait, %s! That %s is really %s named %s!", m_monnam(mtmp), + mimic_obj_name(&youmonst), an(mons[u.umonnum].mname), + plname); + if (multi < 0) { /* this should always be the case */ + char buf[BUFSZ]; + Sprintf(buf, "You appear to be %s again.", + Upolyd ? (const char *) an(youmonst.data->mname) + : (const char *) "yourself"); + unmul(buf); /* immediately stop mimicking */ + } + return 0; + } -/* Work out the armor class differential */ - tmp = AC_VALUE(u.uac) + 10; /* tmp ~= 0 - 20 */ - tmp += mtmp->m_lev; - if(multi < 0) tmp += 4; - if((Invis && !perceives(mdat)) || !mtmp->mcansee) - tmp -= 2; - if(mtmp->mtrapped) tmp -= 2; - if(tmp <= 0) tmp = 1; + /* Work out the armor class differential */ + tmp = AC_VALUE(u.uac) + 10; /* tmp ~= 0 - 20 */ + tmp += mtmp->m_lev; + if (multi < 0) + tmp += 4; + if ((Invis && !perceives(mdat)) || !mtmp->mcansee) + tmp -= 2; + if (mtmp->mtrapped) + tmp -= 2; + if (tmp <= 0) + tmp = 1; - /* make eels visible the moment they hit/miss us */ - if(mdat->mlet == S_EEL && mtmp->minvis && cansee(mtmp->mx,mtmp->my)) { - mtmp->minvis = 0; - newsym(mtmp->mx,mtmp->my); - } + /* make eels visible the moment they hit/miss us */ + if (mdat->mlet == S_EEL && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) { + mtmp->minvis = 0; + newsym(mtmp->mx, mtmp->my); + } -/* Special demon handling code */ - if((mtmp->cham == NON_PM) && is_demon(mdat) && !range2 - && mtmp->data != &mons[PM_BALROG] - && mtmp->data != &mons[PM_SUCCUBUS] - && mtmp->data != &mons[PM_INCUBUS]) - if (!mtmp->mcan && !rn2(13)) (void)msummon(mtmp); + /* Special demon handling code */ + if ((mtmp->cham == NON_PM) && is_demon(mdat) && !range2 + && mtmp->data != &mons[PM_BALROG] && mtmp->data != &mons[PM_SUCCUBUS] + && mtmp->data != &mons[PM_INCUBUS]) + if (!mtmp->mcan && !rn2(13)) + (void) msummon(mtmp); -/* Special lycanthrope handling code */ - if((mtmp->cham == NON_PM) && is_were(mdat) && !range2) { + /* Special lycanthrope handling code */ + if ((mtmp->cham == NON_PM) && is_were(mdat) && !range2) { + if (is_human(mdat)) { + if (!rn2(5 - (night() * 2)) && !mtmp->mcan) + new_were(mtmp); + } else if (!rn2(30) && !mtmp->mcan) + new_were(mtmp); + mdat = mtmp->data; - if(is_human(mdat)) { - if(!rn2(5 - (night() * 2)) && !mtmp->mcan) new_were(mtmp); - } else if(!rn2(30) && !mtmp->mcan) new_were(mtmp); - mdat = mtmp->data; + if (!rn2(10) && !mtmp->mcan) { + int numseen, numhelp; + char buf[BUFSZ], genericwere[BUFSZ]; - if(!rn2(10) && !mtmp->mcan) { - int numseen, numhelp; - char buf[BUFSZ], genericwere[BUFSZ]; + Strcpy(genericwere, "creature"); + numhelp = were_summon(mdat, FALSE, &numseen, genericwere); + if (youseeit) { + pline("%s summons help!", Monnam(mtmp)); + if (numhelp > 0) { + if (numseen == 0) + You_feel("hemmed in."); + } else + pline("But none comes."); + } else { + const char *from_nowhere; - Strcpy(genericwere, "creature"); - numhelp = were_summon(mdat, FALSE, &numseen, genericwere); - if (youseeit) { - pline("%s summons help!", Monnam(mtmp)); - if (numhelp > 0) { - if (numseen == 0) - You_feel("hemmed in."); - } else pline("But none comes."); - } else { - const char *from_nowhere; + if (!Deaf) { + pline("%s %s!", Something, makeplural(growl_sound(mtmp))); + from_nowhere = ""; + } else + from_nowhere = " from nowhere"; + if (numhelp > 0) { + if (numseen < 1) + You_feel("hemmed in."); + else { + if (numseen == 1) + Sprintf(buf, "%s appears", an(genericwere)); + else + Sprintf(buf, "%s appear", + makeplural(genericwere)); + pline("%s%s!", upstart(buf), from_nowhere); + } + } /* else no help came; but you didn't know it tried */ + } + } + } - if (!Deaf) { - pline("%s %s!", Something, - makeplural(growl_sound(mtmp))); - from_nowhere = ""; - } else from_nowhere = " from nowhere"; - if (numhelp > 0) { - if (numseen < 1) You_feel("hemmed in."); - else { - if (numseen == 1) - Sprintf(buf, "%s appears", - an(genericwere)); - else - Sprintf(buf, "%s appear", - makeplural(genericwere)); - pline("%s%s!", upstart(buf), from_nowhere); - } - } /* else no help came; but you didn't know it tried */ - } - } - } + if (u.uinvulnerable) { + /* monsters won't attack you */ + if (mtmp == u.ustuck) + pline("%s loosens its grip slightly.", Monnam(mtmp)); + else if (!range2) { + if (youseeit || sensemon(mtmp)) + pline("%s starts to attack you, but pulls back.", + Monnam(mtmp)); + else + You_feel("%s move nearby.", something); + } + return (0); + } - if(u.uinvulnerable) { - /* monsters won't attack you */ - if(mtmp == u.ustuck) - pline("%s loosens its grip slightly.", Monnam(mtmp)); - else if(!range2) { - if (youseeit || sensemon(mtmp)) - pline("%s starts to attack you, but pulls back.", - Monnam(mtmp)); - else - You_feel("%s move nearby.", something); - } - return (0); - } + /* Unlike defensive stuff, don't let them use item _and_ attack. */ + if (find_offensive(mtmp)) { + int foo = use_offensive(mtmp); - /* Unlike defensive stuff, don't let them use item _and_ attack. */ - if(find_offensive(mtmp)) { - int foo = use_offensive(mtmp); + if (foo != 0) + return (foo == 1); + } - if (foo != 0) return(foo==1); - } + for (i = 0; i < NATTK; i++) { + sum[i] = 0; + mattk = getmattk(mdat, i, sum, &alt_attk); + if ((u.uswallow && mattk->aatyp != AT_ENGL) + || (skipnonmagc && mattk->aatyp != AT_MAGC)) + continue; - for(i = 0; i < NATTK; i++) { + switch (mattk->aatyp) { + case AT_CLAW: /* "hand to hand" attacks */ + case AT_KICK: + case AT_BITE: + case AT_STNG: + case AT_TUCH: + case AT_BUTT: + case AT_TENT: + if (!range2 && (!MON_WEP(mtmp) || mtmp->mconf || Conflict + || !touch_petrifies(youmonst.data))) { + if (foundyou) { + if (tmp > (j = rnd(20 + i))) { + if (mattk->aatyp != AT_KICK + || !thick_skinned(youmonst.data)) + sum[i] = hitmu(mtmp, mattk); + } else + missmu(mtmp, (tmp == j), mattk); + } else { + wildmiss(mtmp, mattk); + /* skip any remaining non-spell attacks */ + skipnonmagc = TRUE; + } + } + break; - sum[i] = 0; - mattk = getmattk(mdat, i, sum, &alt_attk); - if ((u.uswallow && mattk->aatyp != AT_ENGL) || - (skipnonmagc && mattk->aatyp != AT_MAGC)) - continue; + case AT_HUGS: /* automatic if prev two attacks succeed */ + /* Note: if displaced, prev attacks never succeeded */ + if ((!range2 && i >= 2 && sum[i - 1] && sum[i - 2]) + || mtmp == u.ustuck) + sum[i] = hitmu(mtmp, mattk); + break; - switch(mattk->aatyp) { - case AT_CLAW: /* "hand to hand" attacks */ - case AT_KICK: - case AT_BITE: - case AT_STNG: - case AT_TUCH: - case AT_BUTT: - case AT_TENT: - if(!range2 && (!MON_WEP(mtmp) || mtmp->mconf || Conflict || - !touch_petrifies(youmonst.data))) { - if (foundyou) { - if(tmp > (j = rnd(20+i))) { - if (mattk->aatyp != AT_KICK || - !thick_skinned(youmonst.data)) - sum[i] = hitmu(mtmp, mattk); - } else - missmu(mtmp, (tmp == j), mattk); - } else { - wildmiss(mtmp, mattk); - /* skip any remaining non-spell attacks */ - skipnonmagc = TRUE; - } - } - break; + case AT_GAZE: /* can affect you either ranged or not */ + /* Medusa gaze already operated through m_respond in + * dochug(); don't gaze more than once per round. + */ + if (mdat != &mons[PM_MEDUSA]) + sum[i] = gazemu(mtmp, mattk); + break; - case AT_HUGS: /* automatic if prev two attacks succeed */ - /* Note: if displaced, prev attacks never succeeded */ - if((!range2 && i>=2 && sum[i-1] && sum[i-2]) - || mtmp == u.ustuck) - sum[i]= hitmu(mtmp, mattk); - break; + case AT_EXPL: /* automatic hit if next to, and aimed at you */ + if (!range2) + sum[i] = explmu(mtmp, mattk, foundyou); + break; - case AT_GAZE: /* can affect you either ranged or not */ - /* Medusa gaze already operated through m_respond in - * dochug(); don't gaze more than once per round. - */ - if (mdat != &mons[PM_MEDUSA]) - sum[i] = gazemu(mtmp, mattk); - break; + case AT_ENGL: + if (!range2) { + if (foundyou) { + if (u.uswallow || tmp > (j = rnd(20 + i))) { + /* Force swallowing monster to be + * displayed even when player is + * moving away */ + flush_screen(1); + sum[i] = gulpmu(mtmp, mattk); + } else { + missmu(mtmp, (tmp == j), mattk); + } + } else if (is_animal(mtmp->data)) { + pline("%s gulps some air!", Monnam(mtmp)); + } else { + if (youseeit) + pline("%s lunges forward and recoils!", Monnam(mtmp)); + else + You_hear("a %s nearby.", is_whirly(mtmp->data) + ? "rushing noise" + : "splat"); + } + } + break; + case AT_BREA: + if (range2) + sum[i] = breamu(mtmp, mattk); + /* Note: breamu takes care of displacement */ + break; + case AT_SPIT: + if (range2) + sum[i] = spitmu(mtmp, mattk); + /* Note: spitmu takes care of displacement */ + break; + case AT_WEAP: + if (range2) { + if (!Is_rogue_level(&u.uz)) + thrwmu(mtmp); + } else { + int hittmp = 0; - case AT_EXPL: /* automatic hit if next to, and aimed at you */ - if(!range2) sum[i] = explmu(mtmp, mattk, foundyou); - break; + /* Rare but not impossible. Normally the monster + * wields when 2 spaces away, but it can be + * teleported or whatever.... + */ + if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { + mtmp->weapon_check = NEED_HTH_WEAPON; + /* mon_wield_item resets weapon_check as + * appropriate */ + if (mon_wield_item(mtmp) != 0) + break; + } + if (foundyou) { + otmp = MON_WEP(mtmp); + if (otmp) { + hittmp = hitval(otmp, &youmonst); + tmp += hittmp; + mswings(mtmp, otmp); + } + if (tmp > (j = dieroll = rnd(20 + i))) + sum[i] = hitmu(mtmp, mattk); + else + missmu(mtmp, (tmp == j), mattk); + /* KMH -- Don't accumulate to-hit bonuses */ + if (otmp) + tmp -= hittmp; + } else { + wildmiss(mtmp, mattk); + /* skip any remaining non-spell attacks */ + skipnonmagc = TRUE; + } + } + break; + case AT_MAGC: + if (range2) + sum[i] = buzzmu(mtmp, mattk); + else + sum[i] = castmu(mtmp, mattk, TRUE, foundyou); + break; - case AT_ENGL: - if (!range2) { - if(foundyou) { - if(u.uswallow || tmp > (j = rnd(20+i))) { - /* Force swallowing monster to be - * displayed even when player is - * moving away */ - flush_screen(1); - sum[i] = gulpmu(mtmp, mattk); - } else { - missmu(mtmp, (tmp == j), mattk); - } - } else if (is_animal(mtmp->data)) { - pline("%s gulps some air!", Monnam(mtmp)); - } else { - if (youseeit) - pline("%s lunges forward and recoils!", - Monnam(mtmp)); - else - You_hear("a %s nearby.", - is_whirly(mtmp->data) ? - "rushing noise" : "splat"); - } - } - break; - case AT_BREA: - if(range2) sum[i] = breamu(mtmp, mattk); - /* Note: breamu takes care of displacement */ - break; - case AT_SPIT: - if(range2) sum[i] = spitmu(mtmp, mattk); - /* Note: spitmu takes care of displacement */ - break; - case AT_WEAP: - if(range2) { - if (!Is_rogue_level(&u.uz)) - thrwmu(mtmp); - } else { - int hittmp = 0; - - /* Rare but not impossible. Normally the monster - * wields when 2 spaces away, but it can be - * teleported or whatever.... - */ - if (mtmp->weapon_check == NEED_WEAPON || - !MON_WEP(mtmp)) { - mtmp->weapon_check = NEED_HTH_WEAPON; - /* mon_wield_item resets weapon_check as - * appropriate */ - if (mon_wield_item(mtmp) != 0) break; - } - if (foundyou) { - otmp = MON_WEP(mtmp); - if(otmp) { - hittmp = hitval(otmp, &youmonst); - tmp += hittmp; - mswings(mtmp, otmp); - } - if(tmp > (j = dieroll = rnd(20+i))) - sum[i] = hitmu(mtmp, mattk); - else - missmu(mtmp, (tmp == j), mattk); - /* KMH -- Don't accumulate to-hit bonuses */ - if (otmp) - tmp -= hittmp; - } else { - wildmiss(mtmp, mattk); - /* skip any remaining non-spell attacks */ - skipnonmagc = TRUE; - } - } - break; - case AT_MAGC: - if (range2) - sum[i] = buzzmu(mtmp, mattk); - else - sum[i] = castmu(mtmp, mattk, TRUE, foundyou); - break; - - default: /* no attack */ - break; - } - if(context.botl) bot(); - /* give player a chance of waking up before dying -kaa */ - if(sum[i] == 1) { /* successful attack */ - if (u.usleep && u.usleep < monstermoves && !rn2(10)) { - multi = -1; - nomovemsg = "The combat suddenly awakens you."; - } - } - if(sum[i] == 2) return 1; /* attacker dead */ - if(sum[i] == 3) break; /* attacker teleported, no more attacks */ - /* sum[i] == 0: unsuccessful attack */ - } - return(0); + default: /* no attack */ + break; + } + if (context.botl) + bot(); + /* give player a chance of waking up before dying -kaa */ + if (sum[i] == 1) { /* successful attack */ + if (u.usleep && u.usleep < monstermoves && !rn2(10)) { + multi = -1; + nomovemsg = "The combat suddenly awakens you."; + } + } + if (sum[i] == 2) + return 1; /* attacker dead */ + if (sum[i] == 3) + break; /* attacker teleported, no more attacks */ + /* sum[i] == 0: unsuccessful attack */ + } + return (0); } STATIC_OVL boolean diseasemu(mdat) struct permonst *mdat; { - if (Sick_resistance) { - You_feel("a slight illness."); - return FALSE; - } else { - make_sick(Sick ? Sick/3L + 1L : (long)rn1(ACURR(A_CON), 20), - mdat->mname, TRUE, SICK_NONVOMITABLE); - return TRUE; - } + if (Sick_resistance) { + You_feel("a slight illness."); + return FALSE; + } else { + make_sick(Sick ? Sick / 3L + 1L : (long) rn1(ACURR(A_CON), 20), + mdat->mname, TRUE, SICK_NONVOMITABLE); + return TRUE; + } } /* check whether slippery clothing protects from hug or wrap attack */ @@ -732,33 +758,35 @@ u_slip_free(mtmp, mattk) struct monst *mtmp; struct attack *mattk; { - struct obj *obj = (uarmc ? uarmc : uarm); + struct obj *obj = (uarmc ? uarmc : uarm); - if (!obj) obj = uarmu; - if (mattk->adtyp == AD_DRIN) obj = uarmh; + if (!obj) + obj = uarmu; + if (mattk->adtyp == AD_DRIN) + obj = uarmh; - /* if your cloak/armor is greased, monster slips off; this - protection might fail (33% chance) when the armor is cursed */ - if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) && - (!obj->cursed || rn2(3))) { - pline("%s %s your %s %s!", - Monnam(mtmp), - (mattk->adtyp == AD_WRAP) ? - "slips off of" : "grabs you, but cannot hold onto", - obj->greased ? "greased" : "slippery", - /* avoid "slippery slippery cloak" - for undiscovered oilskin cloak */ - (obj->greased || objects[obj->otyp].oc_name_known) ? - xname(obj) : cloak_simple_name(obj)); + /* if your cloak/armor is greased, monster slips off; this + protection might fail (33% chance) when the armor is cursed */ + if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) + && (!obj->cursed || rn2(3))) { + pline("%s %s your %s %s!", Monnam(mtmp), + (mattk->adtyp == AD_WRAP) ? "slips off of" + : "grabs you, but cannot hold onto", + obj->greased ? "greased" : "slippery", + /* avoid "slippery slippery cloak" + for undiscovered oilskin cloak */ + (obj->greased || objects[obj->otyp].oc_name_known) + ? xname(obj) + : cloak_simple_name(obj)); - if (obj->greased && !rn2(2)) { - pline_The("grease wears off."); - obj->greased = 0; - update_inventory(); - } - return TRUE; - } - return FALSE; + if (obj->greased && !rn2(2)) { + pline_The("grease wears off."); + obj->greased = 0; + update_inventory(); + } + return TRUE; + } + return FALSE; } /* armor that sufficiently covers the body might be able to block magic */ @@ -766,42 +794,46 @@ int magic_negation(mon) struct monst *mon; { - struct obj *o; - long wearmask; - int armpro, mc = 0; - boolean is_you = (mon == &youmonst), - gotprot = is_you ? (EProtection != 0L) : - /* high priests have innate protection */ - (mon->data == &mons[PM_HIGH_PRIEST]); + struct obj *o; + long wearmask; + int armpro, mc = 0; + boolean is_you = (mon == &youmonst), + gotprot = is_you ? (EProtection != 0L) : + /* high priests have innate protection */ + (mon->data == &mons[PM_HIGH_PRIEST]); - for (o = is_you ? invent : mon->minvent; o; o = o->nobj) { - /* a_can field is only applicable for armor (which must be worn) */ - if ((o->owornmask & W_ARMOR) != 0L) { - armpro = objects[o->otyp].a_can; - if (armpro > mc) mc = armpro; - } - /* if we've already confirmed Protection, skip additional checks */ - if (is_you || gotprot) continue; + for (o = is_you ? invent : mon->minvent; o; o = o->nobj) { + /* a_can field is only applicable for armor (which must be worn) */ + if ((o->owornmask & W_ARMOR) != 0L) { + armpro = objects[o->otyp].a_can; + if (armpro > mc) + mc = armpro; + } + /* if we've already confirmed Protection, skip additional checks */ + if (is_you || gotprot) + continue; - /* omit W_SWAPWEP+W_QUIVER; W_ART+W_ARTI handled by protects() */ - wearmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; - if (o->oclass == WEAPON_CLASS || is_weptool(o)) wearmask |= W_WEP; - if (protects(o, ((o->owornmask & wearmask) != 0L) ? TRUE : FALSE)) - gotprot = TRUE; - } + /* omit W_SWAPWEP+W_QUIVER; W_ART+W_ARTI handled by protects() */ + wearmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; + if (o->oclass == WEAPON_CLASS || is_weptool(o)) + wearmask |= W_WEP; + if (protects(o, ((o->owornmask & wearmask) != 0L) ? TRUE : FALSE)) + gotprot = TRUE; + } - if (gotprot) { - /* extrinsic Protection increases mc by 1 */ - if (mc < 3) mc += 1; - } else if (mc < 1) { - /* intrinsic Protection is weaker (play balance; obtaining divine - protection is too easy); it confers minimum mc 1 instead of 0 */ - if ((is_you && ((HProtection && u.ublessed) || u.uspellprot)) || - /* aligned priests and angels have innate intrinsic Protection */ - (mon->data == &mons[PM_ALIGNED_PRIEST] || is_minion(mon->data))) - mc = 1; - } - return mc; + if (gotprot) { + /* extrinsic Protection increases mc by 1 */ + if (mc < 3) + mc += 1; + } else if (mc < 1) { + /* intrinsic Protection is weaker (play balance; obtaining divine + protection is too easy); it confers minimum mc 1 instead of 0 */ + if ((is_you && ((HProtection && u.ublessed) || u.uspellprot)) || + /* aligned priests and angels have innate intrinsic Protection */ + (mon->data == &mons[PM_ALIGNED_PRIEST] || is_minion(mon->data))) + mc = 1; + } + return mc; } /* @@ -812,728 +844,775 @@ struct monst *mon; */ STATIC_OVL int hitmu(mtmp, mattk) - register struct monst *mtmp; - register struct attack *mattk; +register struct monst *mtmp; +register struct attack *mattk; { - register struct permonst *mdat = mtmp->data; - register int uncancelled, ptmp; - int dmg, armpro, permdmg; - char buf[BUFSZ]; - struct permonst *olduasmon = youmonst.data; - int res; + register struct permonst *mdat = mtmp->data; + register int uncancelled, ptmp; + int dmg, armpro, permdmg; + char buf[BUFSZ]; + struct permonst *olduasmon = youmonst.data; + int res; - if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); -/* If the monster is undetected & hits you, you should know where - * the attack came from. - */ - if(mtmp->mundetected && (hides_under(mdat) || mdat->mlet == S_EEL)) { - mtmp->mundetected = 0; - if (!(Blind ? Blind_telepat : Unblind_telepat)) { - struct obj *obj; - const char *what; + /* If the monster is undetected & hits you, you should know where + * the attack came from. + */ + if (mtmp->mundetected && (hides_under(mdat) || mdat->mlet == S_EEL)) { + mtmp->mundetected = 0; + if (!(Blind ? Blind_telepat : Unblind_telepat)) { + struct obj *obj; + const char *what; - if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0) { - if (Blind && !obj->dknown) - what = something; - else if (is_pool(mtmp->mx, mtmp->my) && !Underwater) - what = "the water"; - else - what = doname(obj); + if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0) { + if (Blind && !obj->dknown) + what = something; + else if (is_pool(mtmp->mx, mtmp->my) && !Underwater) + what = "the water"; + else + what = doname(obj); - pline("%s was hidden under %s!", Amonnam(mtmp), what); - } - newsym(mtmp->mx, mtmp->my); - } - } + pline("%s was hidden under %s!", Amonnam(mtmp), what); + } + newsym(mtmp->mx, mtmp->my); + } + } -/* First determine the base damage done */ - dmg = d((int)mattk->damn, (int)mattk->damd); - if((is_undead(mdat) || is_vampshifter(mtmp)) && midnight()) - dmg += d((int)mattk->damn, (int)mattk->damd); /* extra damage */ + /* First determine the base damage done */ + dmg = d((int) mattk->damn, (int) mattk->damd); + if ((is_undead(mdat) || is_vampshifter(mtmp)) && midnight()) + dmg += d((int) mattk->damn, (int) mattk->damd); /* extra damage */ -/* Next a cancellation factor */ -/* Use uncancelled when the cancellation factor takes into account certain - * armor's special magic protection. Otherwise just use !mtmp->mcan. - */ - armpro = magic_negation(&youmonst); - uncancelled = !mtmp->mcan && (rn2(10) >= 3 * armpro); + /* Next a cancellation factor */ + /* Use uncancelled when the cancellation factor takes into account + *certain + * armor's special magic protection. Otherwise just use !mtmp->mcan. + */ + armpro = magic_negation(&youmonst); + uncancelled = !mtmp->mcan && (rn2(10) >= 3 * armpro); - permdmg = 0; -/* Now, adjust damages via resistances or specific attacks */ - switch(mattk->adtyp) { - case AD_PHYS: - if (mattk->aatyp == AT_HUGS && !sticks(youmonst.data)) { - if(!u.ustuck && rn2(2)) { - if (u_slip_free(mtmp, mattk)) { - dmg = 0; - } else { - u.ustuck = mtmp; - pline("%s grabs you!", Monnam(mtmp)); - } - } else if(u.ustuck == mtmp) { - exercise(A_STR, FALSE); - You("are being %s.", - (mtmp->data == &mons[PM_ROPE_GOLEM]) - ? "choked" : "crushed"); - } - } else { /* hand to hand weapon */ - if(mattk->aatyp == AT_WEAP && otmp) { - int tmp; + permdmg = 0; + /* Now, adjust damages via resistances or specific attacks */ + switch (mattk->adtyp) { + case AD_PHYS: + if (mattk->aatyp == AT_HUGS && !sticks(youmonst.data)) { + if (!u.ustuck && rn2(2)) { + if (u_slip_free(mtmp, mattk)) { + dmg = 0; + } else { + u.ustuck = mtmp; + pline("%s grabs you!", Monnam(mtmp)); + } + } else if (u.ustuck == mtmp) { + exercise(A_STR, FALSE); + You("are being %s.", (mtmp->data == &mons[PM_ROPE_GOLEM]) + ? "choked" + : "crushed"); + } + } else { /* hand to hand weapon */ + if (mattk->aatyp == AT_WEAP && otmp) { + int tmp; - if (otmp->otyp == CORPSE - && touch_petrifies(&mons[otmp->corpsenm])) { - dmg = 1; - pline("%s hits you with the %s corpse.", - Monnam(mtmp), mons[otmp->corpsenm].mname); - if (!Stoned) - goto do_stone; - } - dmg += dmgval(otmp, &youmonst); - if (dmg <= 0) dmg = 1; - if (!(otmp->oartifact && - artifact_hit(mtmp, &youmonst, otmp, &dmg,dieroll))) - hitmsg(mtmp, mattk); - if (!dmg) break; - if (objects[otmp->otyp].oc_material == SILVER && - Hate_silver) { - pline_The("silver sears your flesh!"); - exercise(A_CON, FALSE); - } - /* this redundancy necessary because you have - to take the damage _before_ being cloned; - need to have at least 2 hp left to split */ - tmp = dmg; - if (u.uac < 0) tmp -= rnd(-u.uac); - if (tmp < 1) tmp = 1; - if (u.mh - tmp > 1 && - objects[otmp->otyp].oc_material == IRON && - (u.umonnum == PM_BLACK_PUDDING || - u.umonnum == PM_BROWN_PUDDING)) { - if (tmp > 1) exercise(A_STR, FALSE); - /* inflict damage now; we know it can't be fatal */ - u.mh -= tmp; - context.botl = 1; - dmg = 0; /* don't inflict more damage below */ - if (cloneu()) - You("divide as %s hits you!", mon_nam(mtmp)); - } - rustm(&youmonst, otmp); - } else if (mattk->aatyp != AT_TUCH || dmg != 0 || - mtmp != u.ustuck) - hitmsg(mtmp, mattk); - } - break; - case AD_DISE: - hitmsg(mtmp, mattk); - if (!diseasemu(mdat)) dmg = 0; - break; - case AD_FIRE: - hitmsg(mtmp, mattk); - if (uncancelled) { - pline("You're %s!", on_fire(youmonst.data, mattk)); - if (youmonst.data == &mons[PM_STRAW_GOLEM] || - youmonst.data == &mons[PM_PAPER_GOLEM]) { - You("roast!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } else if (Fire_resistance) { - pline_The("fire doesn't feel hot!"); - dmg = 0; - } - if((int) mtmp->m_lev > rn2(20)) - destroy_item(SCROLL_CLASS, AD_FIRE); - if((int) mtmp->m_lev > rn2(20)) - destroy_item(POTION_CLASS, AD_FIRE); - if((int) mtmp->m_lev > rn2(25)) - destroy_item(SPBOOK_CLASS, AD_FIRE); - burn_away_slime(); - } else dmg = 0; - break; - case AD_COLD: - hitmsg(mtmp, mattk); - if (uncancelled) { - pline("You're covered in frost!"); - if (Cold_resistance) { - pline_The("frost doesn't seem cold!"); - dmg = 0; - } - if((int) mtmp->m_lev > rn2(20)) - destroy_item(POTION_CLASS, AD_COLD); - } else dmg = 0; - break; - case AD_ELEC: - hitmsg(mtmp, mattk); - if (uncancelled) { - You("get zapped!"); - if (Shock_resistance) { - pline_The("zap doesn't shock you!"); - dmg = 0; - } - if((int) mtmp->m_lev > rn2(20)) - destroy_item(WAND_CLASS, AD_ELEC); - if((int) mtmp->m_lev > rn2(20)) - destroy_item(RING_CLASS, AD_ELEC); - } else dmg = 0; - break; - case AD_SLEE: - hitmsg(mtmp, mattk); - if (uncancelled && multi >= 0 && !rn2(5)) { - if (Sleep_resistance) break; - fall_asleep(-rnd(10), TRUE); - if (Blind) You("are put to sleep!"); - else You("are put to sleep by %s!", mon_nam(mtmp)); - } - break; - case AD_BLND: - if (can_blnd(mtmp, &youmonst, mattk->aatyp, (struct obj*)0)) { - if (!Blind) pline("%s blinds you!", Monnam(mtmp)); - make_blinded(Blinded+(long)dmg,FALSE); - if (!Blind) Your1(vision_clears); - } - dmg = 0; - break; - case AD_DRST: - ptmp = A_STR; - goto dopois; - case AD_DRDX: - ptmp = A_DEX; - goto dopois; - case AD_DRCO: - ptmp = A_CON; -dopois: - hitmsg(mtmp, mattk); - if (uncancelled && !rn2(8)) { - Sprintf(buf, "%s %s", - s_suffix(Monnam(mtmp)), mpoisons_subj(mtmp, mattk)); - poisoned(buf, ptmp, mdat->mname, 30, FALSE); - } - break; - case AD_DRIN: - hitmsg(mtmp, mattk); - if (defends(AD_DRIN, uwep) || !has_head(youmonst.data)) { - You("don't seem harmed."); - /* Not clear what to do for green slimes */ - break; - } - if (u_slip_free(mtmp,mattk)) break; + if (otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm])) { + dmg = 1; + pline("%s hits you with the %s corpse.", Monnam(mtmp), + mons[otmp->corpsenm].mname); + if (!Stoned) + goto do_stone; + } + dmg += dmgval(otmp, &youmonst); + if (dmg <= 0) + dmg = 1; + if (!(otmp->oartifact + && artifact_hit(mtmp, &youmonst, otmp, &dmg, dieroll))) + hitmsg(mtmp, mattk); + if (!dmg) + break; + if (objects[otmp->otyp].oc_material == SILVER + && Hate_silver) { + pline_The("silver sears your flesh!"); + exercise(A_CON, FALSE); + } + /* this redundancy necessary because you have + to take the damage _before_ being cloned; + need to have at least 2 hp left to split */ + tmp = dmg; + if (u.uac < 0) + tmp -= rnd(-u.uac); + if (tmp < 1) + tmp = 1; + if (u.mh - tmp > 1 && objects[otmp->otyp].oc_material == IRON + && (u.umonnum == PM_BLACK_PUDDING + || u.umonnum == PM_BROWN_PUDDING)) { + if (tmp > 1) + exercise(A_STR, FALSE); + /* inflict damage now; we know it can't be fatal */ + u.mh -= tmp; + context.botl = 1; + dmg = 0; /* don't inflict more damage below */ + if (cloneu()) + You("divide as %s hits you!", mon_nam(mtmp)); + } + rustm(&youmonst, otmp); + } else if (mattk->aatyp != AT_TUCH || dmg != 0 + || mtmp != u.ustuck) + hitmsg(mtmp, mattk); + } + break; + case AD_DISE: + hitmsg(mtmp, mattk); + if (!diseasemu(mdat)) + dmg = 0; + break; + case AD_FIRE: + hitmsg(mtmp, mattk); + if (uncancelled) { + pline("You're %s!", on_fire(youmonst.data, mattk)); + if (youmonst.data == &mons[PM_STRAW_GOLEM] + || youmonst.data == &mons[PM_PAPER_GOLEM]) { + You("roast!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + break; + } else if (Fire_resistance) { + pline_The("fire doesn't feel hot!"); + dmg = 0; + } + if ((int) mtmp->m_lev > rn2(20)) + destroy_item(SCROLL_CLASS, AD_FIRE); + if ((int) mtmp->m_lev > rn2(20)) + destroy_item(POTION_CLASS, AD_FIRE); + if ((int) mtmp->m_lev > rn2(25)) + destroy_item(SPBOOK_CLASS, AD_FIRE); + burn_away_slime(); + } else + dmg = 0; + break; + case AD_COLD: + hitmsg(mtmp, mattk); + if (uncancelled) { + pline("You're covered in frost!"); + if (Cold_resistance) { + pline_The("frost doesn't seem cold!"); + dmg = 0; + } + if ((int) mtmp->m_lev > rn2(20)) + destroy_item(POTION_CLASS, AD_COLD); + } else + dmg = 0; + break; + case AD_ELEC: + hitmsg(mtmp, mattk); + if (uncancelled) { + You("get zapped!"); + if (Shock_resistance) { + pline_The("zap doesn't shock you!"); + dmg = 0; + } + if ((int) mtmp->m_lev > rn2(20)) + destroy_item(WAND_CLASS, AD_ELEC); + if ((int) mtmp->m_lev > rn2(20)) + destroy_item(RING_CLASS, AD_ELEC); + } else + dmg = 0; + break; + case AD_SLEE: + hitmsg(mtmp, mattk); + if (uncancelled && multi >= 0 && !rn2(5)) { + if (Sleep_resistance) + break; + fall_asleep(-rnd(10), TRUE); + if (Blind) + You("are put to sleep!"); + else + You("are put to sleep by %s!", mon_nam(mtmp)); + } + break; + case AD_BLND: + if (can_blnd(mtmp, &youmonst, mattk->aatyp, (struct obj *) 0)) { + if (!Blind) + pline("%s blinds you!", Monnam(mtmp)); + make_blinded(Blinded + (long) dmg, FALSE); + if (!Blind) + Your1(vision_clears); + } + dmg = 0; + break; + case AD_DRST: + ptmp = A_STR; + goto dopois; + case AD_DRDX: + ptmp = A_DEX; + goto dopois; + case AD_DRCO: + ptmp = A_CON; + dopois: + hitmsg(mtmp, mattk); + if (uncancelled && !rn2(8)) { + Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)), + mpoisons_subj(mtmp, mattk)); + poisoned(buf, ptmp, mdat->mname, 30, FALSE); + } + break; + case AD_DRIN: + hitmsg(mtmp, mattk); + if (defends(AD_DRIN, uwep) || !has_head(youmonst.data)) { + You("don't seem harmed."); + /* Not clear what to do for green slimes */ + break; + } + if (u_slip_free(mtmp, mattk)) + break; - if (uarmh && rn2(8)) { - /* not body_part(HEAD) */ - Your("%s blocks the attack to your head.", - helm_simple_name(uarmh)); - break; - } - if (Half_physical_damage) dmg = (dmg+1) / 2; - mdamageu(mtmp, dmg); + if (uarmh && rn2(8)) { + /* not body_part(HEAD) */ + Your("%s blocks the attack to your head.", + helm_simple_name(uarmh)); + break; + } + if (Half_physical_damage) + dmg = (dmg + 1) / 2; + mdamageu(mtmp, dmg); - if (!uarmh || uarmh->otyp != DUNCE_CAP) { - /* eat_brains() will miss if target is mindless (won't - happen here; hero is considered to retain his mind - regardless of current shape) or is noncorporeal - (can't happen here; no one can poly into a ghost - or shade) so this check for missing is academic */ - if (eat_brains(mtmp, &youmonst, TRUE, (int *)0) == MM_MISS) - break; - } - /* adjattrib gives dunce cap message when appropriate */ - (void) adjattrib(A_INT, -rnd(2), FALSE); - forget_levels(25); /* lose memory of 25% of levels */ - forget_objects(25); /* lose memory of 25% of objects */ - break; - case AD_PLYS: - hitmsg(mtmp, mattk); - if (uncancelled && multi >= 0 && !rn2(3)) { - if (Free_action) { - You("momentarily stiffen."); - } else { - if (Blind) You("are frozen!"); - else You("are frozen by %s!", mon_nam(mtmp)); - nomovemsg = You_can_move_again; - nomul(-rnd(10)); - multi_reason = "paralyzed by a monster"; - exercise(A_DEX, FALSE); - } - } - break; - case AD_DRLI: - hitmsg(mtmp, mattk); - if (uncancelled && !rn2(3) && !Drain_resistance) { - losexp("life drainage"); - } - break; - case AD_LEGS: - { register long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; - const char *sidestr = (side == RIGHT_SIDE) ? "right" : "left"; + if (!uarmh || uarmh->otyp != DUNCE_CAP) { + /* eat_brains() will miss if target is mindless (won't + happen here; hero is considered to retain his mind + regardless of current shape) or is noncorporeal + (can't happen here; no one can poly into a ghost + or shade) so this check for missing is academic */ + if (eat_brains(mtmp, &youmonst, TRUE, (int *) 0) == MM_MISS) + break; + } + /* adjattrib gives dunce cap message when appropriate */ + (void) adjattrib(A_INT, -rnd(2), FALSE); + forget_levels(25); /* lose memory of 25% of levels */ + forget_objects(25); /* lose memory of 25% of objects */ + break; + case AD_PLYS: + hitmsg(mtmp, mattk); + if (uncancelled && multi >= 0 && !rn2(3)) { + if (Free_action) { + You("momentarily stiffen."); + } else { + if (Blind) + You("are frozen!"); + else + You("are frozen by %s!", mon_nam(mtmp)); + nomovemsg = You_can_move_again; + nomul(-rnd(10)); + multi_reason = "paralyzed by a monster"; + exercise(A_DEX, FALSE); + } + } + break; + case AD_DRLI: + hitmsg(mtmp, mattk); + if (uncancelled && !rn2(3) && !Drain_resistance) { + losexp("life drainage"); + } + break; + case AD_LEGS: { + register long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; + const char *sidestr = (side == RIGHT_SIDE) ? "right" : "left"; - /* This case is too obvious to ignore, but Nethack is not in - * general very good at considering height--most short monsters - * still _can_ attack you when you're flying or mounted. - * [FIXME: why can't a flying attacker overcome this?] - */ - if (u.usteed || Levitation || Flying) { - pline("%s tries to reach your %s %s!", Monnam(mtmp), - sidestr, body_part(LEG)); - dmg = 0; - } else if (mtmp->mcan) { - pline("%s nuzzles against your %s %s!", Monnam(mtmp), - sidestr, body_part(LEG)); - dmg = 0; - } else { - if (uarmf) { - if (rn2(2) && (uarmf->otyp == LOW_BOOTS || - uarmf->otyp == IRON_SHOES)) - pline("%s pricks the exposed part of your %s %s!", - Monnam(mtmp), sidestr, body_part(LEG)); - else if (!rn2(5)) - pline("%s pricks through your %s boot!", - Monnam(mtmp), sidestr); - else { - pline("%s scratches your %s boot!", Monnam(mtmp), - sidestr); - dmg = 0; - break; - } - } else pline("%s pricks your %s %s!", Monnam(mtmp), - sidestr, body_part(LEG)); - set_wounded_legs(side, rnd(60-ACURR(A_DEX))); - exercise(A_STR, FALSE); - exercise(A_DEX, FALSE); - } - break; - } - case AD_STON: /* cockatrice */ - hitmsg(mtmp, mattk); - if(!rn2(3)) { - if (mtmp->mcan) { - if (!Deaf) - You_hear("a cough from %s!", mon_nam(mtmp)); - } else { - if (!Deaf) - You_hear("%s hissing!", s_suffix(mon_nam(mtmp))); - if(!rn2(10) || - (flags.moonphase == NEW_MOON && !have_lizard())) { - do_stone: - if (!Stoned && !Stone_resistance - && !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - int kformat = KILLED_BY_AN; - const char *kname = mtmp->data->mname; + /* This case is too obvious to ignore, but Nethack is not in + * general very good at considering height--most short monsters + * still _can_ attack you when you're flying or mounted. + * [FIXME: why can't a flying attacker overcome this?] + */ + if (u.usteed || Levitation || Flying) { + pline("%s tries to reach your %s %s!", Monnam(mtmp), sidestr, + body_part(LEG)); + dmg = 0; + } else if (mtmp->mcan) { + pline("%s nuzzles against your %s %s!", Monnam(mtmp), sidestr, + body_part(LEG)); + dmg = 0; + } else { + if (uarmf) { + if (rn2(2) && (uarmf->otyp == LOW_BOOTS + || uarmf->otyp == IRON_SHOES)) + pline("%s pricks the exposed part of your %s %s!", + Monnam(mtmp), sidestr, body_part(LEG)); + else if (!rn2(5)) + pline("%s pricks through your %s boot!", Monnam(mtmp), + sidestr); + else { + pline("%s scratches your %s boot!", Monnam(mtmp), + sidestr); + dmg = 0; + break; + } + } else + pline("%s pricks your %s %s!", Monnam(mtmp), sidestr, + body_part(LEG)); + set_wounded_legs(side, rnd(60 - ACURR(A_DEX))); + exercise(A_STR, FALSE); + exercise(A_DEX, FALSE); + } + break; + } + case AD_STON: /* cockatrice */ + hitmsg(mtmp, mattk); + if (!rn2(3)) { + if (mtmp->mcan) { + if (!Deaf) + You_hear("a cough from %s!", mon_nam(mtmp)); + } else { + if (!Deaf) + You_hear("%s hissing!", s_suffix(mon_nam(mtmp))); + if (!rn2(10) + || (flags.moonphase == NEW_MOON && !have_lizard())) { + do_stone: + if (!Stoned && !Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + int kformat = KILLED_BY_AN; + const char *kname = mtmp->data->mname; - if (mtmp->data->geno & G_UNIQ) { - if (!type_is_pname(mtmp->data)) - kname = the(kname); - kformat = KILLED_BY; - } - make_stoned(5L, (char *)0, kformat, kname); - return(1); - /* done_in_by(mtmp, STONING); */ - } - } - } - } - break; - case AD_STCK: - hitmsg(mtmp, mattk); - if (uncancelled && !u.ustuck && !sticks(youmonst.data)) - u.ustuck = mtmp; - break; - case AD_WRAP: - if ((!mtmp->mcan || u.ustuck == mtmp) && !sticks(youmonst.data)) { - if (!u.ustuck && !rn2(10)) { - if (u_slip_free(mtmp, mattk)) { - dmg = 0; - } else { - pline("%s swings itself around you!", - Monnam(mtmp)); - u.ustuck = mtmp; - } - } else if(u.ustuck == mtmp) { - if (is_pool(mtmp->mx,mtmp->my) && !Swimming - && !Amphibious) { - boolean moat = - (levl[mtmp->mx][mtmp->my].typ != POOL) && - (levl[mtmp->mx][mtmp->my].typ != WATER) && - !Is_medusa_level(&u.uz) && - !Is_waterlevel(&u.uz); + if (mtmp->data->geno & G_UNIQ) { + if (!type_is_pname(mtmp->data)) + kname = the(kname); + kformat = KILLED_BY; + } + make_stoned(5L, (char *) 0, kformat, kname); + return (1); + /* done_in_by(mtmp, STONING); */ + } + } + } + } + break; + case AD_STCK: + hitmsg(mtmp, mattk); + if (uncancelled && !u.ustuck && !sticks(youmonst.data)) + u.ustuck = mtmp; + break; + case AD_WRAP: + if ((!mtmp->mcan || u.ustuck == mtmp) && !sticks(youmonst.data)) { + if (!u.ustuck && !rn2(10)) { + if (u_slip_free(mtmp, mattk)) { + dmg = 0; + } else { + pline("%s swings itself around you!", Monnam(mtmp)); + u.ustuck = mtmp; + } + } else if (u.ustuck == mtmp) { + if (is_pool(mtmp->mx, mtmp->my) && !Swimming && !Amphibious) { + boolean moat = (levl[mtmp->mx][mtmp->my].typ != POOL) + && (levl[mtmp->mx][mtmp->my].typ != WATER) + && !Is_medusa_level(&u.uz) + && !Is_waterlevel(&u.uz); - pline("%s drowns you...", Monnam(mtmp)); - killer.format = KILLED_BY_AN; - Sprintf(killer.name, "%s by %s", - moat ? "moat" : "pool of water", - an(mtmp->data->mname)); - done(DROWNING); - } else if(mattk->aatyp == AT_HUGS) - You("are being crushed."); - } else { - dmg = 0; - if(flags.verbose) - pline("%s brushes against your %s.", Monnam(mtmp), - body_part(LEG)); - } - } else dmg = 0; - break; - case AD_WERE: - hitmsg(mtmp, mattk); - if (uncancelled && !rn2(4) && u.ulycn == NON_PM && - !Protection_from_shape_changers && - !defends(AD_WERE,uwep)) { - You_feel("feverish."); - exercise(A_CON, FALSE); - u.ulycn = monsndx(mdat); - retouch_equipment(2); - } - break; - case AD_SGLD: - hitmsg(mtmp, mattk); - if (youmonst.data->mlet == mdat->mlet) break; - if(!mtmp->mcan) stealgold(mtmp); - break; + pline("%s drowns you...", Monnam(mtmp)); + killer.format = KILLED_BY_AN; + Sprintf(killer.name, "%s by %s", + moat ? "moat" : "pool of water", + an(mtmp->data->mname)); + done(DROWNING); + } else if (mattk->aatyp == AT_HUGS) + You("are being crushed."); + } else { + dmg = 0; + if (flags.verbose) + pline("%s brushes against your %s.", Monnam(mtmp), + body_part(LEG)); + } + } else + dmg = 0; + break; + case AD_WERE: + hitmsg(mtmp, mattk); + if (uncancelled && !rn2(4) && u.ulycn == NON_PM + && !Protection_from_shape_changers && !defends(AD_WERE, uwep)) { + You_feel("feverish."); + exercise(A_CON, FALSE); + u.ulycn = monsndx(mdat); + retouch_equipment(2); + } + break; + case AD_SGLD: + hitmsg(mtmp, mattk); + if (youmonst.data->mlet == mdat->mlet) + break; + if (!mtmp->mcan) + stealgold(mtmp); + break; - case AD_SSEX: - if(SYSOPT_SEDUCE){ - if(could_seduce(mtmp, &youmonst, mattk) == 1 - && !mtmp->mcan) - if (doseduce(mtmp)) - return 3; - break; - } - /* else FALLTHRU */ - case AD_SITM: /* for now these are the same */ - case AD_SEDU: - if (is_animal(mtmp->data)) { - hitmsg(mtmp, mattk); - if (mtmp->mcan) break; - /* Continue below */ - } else if (dmgtype(youmonst.data, AD_SEDU) - || (SYSOPT_SEDUCE && dmgtype(youmonst.data, AD_SSEX))) { - pline("%s %s.", Monnam(mtmp), mtmp->minvent ? - "brags about the goods some dungeon explorer provided" : - "makes some remarks about how difficult theft is lately"); - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - return 3; - } else if (mtmp->mcan) { - if (!Blind) { - pline("%s tries to %s you, but you seem %s.", - Adjmonnam(mtmp, "plain"), - flags.female ? "charm" : "seduce", - flags.female ? "unaffected" : "uninterested"); - } - if(rn2(3)) { - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - return 3; - } - break; - } - buf[0] = '\0'; - switch (steal(mtmp, buf)) { - case -1: - return 2; - case 0: - break; - default: - if (!is_animal(mtmp->data) && !tele_restrict(mtmp)) - (void) rloc(mtmp, FALSE); - if (is_animal(mtmp->data) && *buf) { - if (canseemon(mtmp)) - pline("%s tries to %s away with %s.", - Monnam(mtmp), - locomotion(mtmp->data, "run"), - buf); - } - monflee(mtmp, 0, FALSE, FALSE); - return 3; - } - break; + case AD_SSEX: + if (SYSOPT_SEDUCE) { + if (could_seduce(mtmp, &youmonst, mattk) == 1 && !mtmp->mcan) + if (doseduce(mtmp)) + return 3; + break; + } + /* else FALLTHRU */ + case AD_SITM: /* for now these are the same */ + case AD_SEDU: + if (is_animal(mtmp->data)) { + hitmsg(mtmp, mattk); + if (mtmp->mcan) + break; + /* Continue below */ + } else if (dmgtype(youmonst.data, AD_SEDU) + || (SYSOPT_SEDUCE && dmgtype(youmonst.data, AD_SSEX))) { + pline("%s %s.", Monnam(mtmp), + mtmp->minvent + ? "brags about the goods some dungeon explorer provided" + : "makes some remarks about how difficult theft is " + "lately"); + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + return 3; + } else if (mtmp->mcan) { + if (!Blind) { + pline("%s tries to %s you, but you seem %s.", + Adjmonnam(mtmp, "plain"), + flags.female ? "charm" : "seduce", + flags.female ? "unaffected" : "uninterested"); + } + if (rn2(3)) { + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + return 3; + } + break; + } + buf[0] = '\0'; + switch (steal(mtmp, buf)) { + case -1: + return 2; + case 0: + break; + default: + if (!is_animal(mtmp->data) && !tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + if (is_animal(mtmp->data) && *buf) { + if (canseemon(mtmp)) + pline("%s tries to %s away with %s.", Monnam(mtmp), + locomotion(mtmp->data, "run"), buf); + } + monflee(mtmp, 0, FALSE, FALSE); + return 3; + } + break; - case AD_SAMU: - hitmsg(mtmp, mattk); - /* when the Wiz hits, 1/20 steals the amulet */ - if (u.uhave.amulet || - u.uhave.bell || u.uhave.book || u.uhave.menorah - || u.uhave.questart) /* carrying the Quest Artifact */ - if (!rn2(20)) stealamulet(mtmp); - break; + case AD_SAMU: + hitmsg(mtmp, mattk); + /* when the Wiz hits, 1/20 steals the amulet */ + if (u.uhave.amulet || u.uhave.bell || u.uhave.book || u.uhave.menorah + || u.uhave.questart) /* carrying the Quest Artifact */ + if (!rn2(20)) + stealamulet(mtmp); + break; - case AD_TLPT: - hitmsg(mtmp, mattk); - if (uncancelled) { - if(flags.verbose) - Your("position suddenly seems very uncertain!"); - tele(); - } - break; - case AD_RUST: - hitmsg(mtmp, mattk); - if (mtmp->mcan) break; - if (u.umonnum == PM_IRON_GOLEM) { - You("rust!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } - erode_armor(&youmonst, ERODE_RUST); - break; - case AD_CORR: - hitmsg(mtmp, mattk); - if (mtmp->mcan) break; - erode_armor(&youmonst, ERODE_CORRODE); - break; - case AD_DCAY: - hitmsg(mtmp, mattk); - if (mtmp->mcan) break; - if (u.umonnum == PM_WOOD_GOLEM || - u.umonnum == PM_LEATHER_GOLEM) { - You("rot!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } - erode_armor(&youmonst, ERODE_ROT); - break; - case AD_HEAL: - /* a cancelled nurse is just an ordinary monster, - * nurses don't heal those that cause petrification */ - if (mtmp->mcan || (Upolyd && touch_petrifies(youmonst.data))) { - hitmsg(mtmp, mattk); - break; - } - if(!uwep && !uarmu && !uarm && !uarmh && !uarms && !uarmg && !uarmc + case AD_TLPT: + hitmsg(mtmp, mattk); + if (uncancelled) { + if (flags.verbose) + Your("position suddenly seems very uncertain!"); + tele(); + } + break; + case AD_RUST: + hitmsg(mtmp, mattk); + if (mtmp->mcan) + break; + if (u.umonnum == PM_IRON_GOLEM) { + You("rust!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + break; + } + erode_armor(&youmonst, ERODE_RUST); + break; + case AD_CORR: + hitmsg(mtmp, mattk); + if (mtmp->mcan) + break; + erode_armor(&youmonst, ERODE_CORRODE); + break; + case AD_DCAY: + hitmsg(mtmp, mattk); + if (mtmp->mcan) + break; + if (u.umonnum == PM_WOOD_GOLEM || u.umonnum == PM_LEATHER_GOLEM) { + You("rot!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + break; + } + erode_armor(&youmonst, ERODE_ROT); + break; + case AD_HEAL: + /* a cancelled nurse is just an ordinary monster, + * nurses don't heal those that cause petrification */ + if (mtmp->mcan || (Upolyd && touch_petrifies(youmonst.data))) { + hitmsg(mtmp, mattk); + break; + } + if (!uwep && !uarmu && !uarm && !uarmh && !uarms && !uarmg && !uarmc && !uarmf) { - boolean goaway = FALSE; - pline("%s hits! (I hope you don't mind.)", Monnam(mtmp)); - if (Upolyd) { - u.mh += rnd(7); - if (!rn2(7)) { - /* no upper limit necessary; effect is temporary */ - u.mhmax++; - if (!rn2(13)) goaway = TRUE; - } - if (u.mh > u.mhmax) u.mh = u.mhmax; - } else { - u.uhp += rnd(7); - if (!rn2(7)) { - /* hard upper limit via nurse care: 25 * ulevel */ - if (u.uhpmax < 5 * u.ulevel + d(2 * u.ulevel, 10)) - u.uhpmax++; - if (!rn2(13)) goaway = TRUE; - } - if (u.uhp > u.uhpmax) u.uhp = u.uhpmax; - } - if (!rn2(3)) exercise(A_STR, TRUE); - if (!rn2(3)) exercise(A_CON, TRUE); - if (Sick) make_sick(0L, (char *) 0, FALSE, SICK_ALL); - context.botl = 1; - if (goaway) { - mongone(mtmp); - return 2; - } else if (!rn2(33)) { - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - monflee(mtmp, d(3, 6), TRUE, FALSE); - return 3; - } - dmg = 0; - } else { - if (Role_if(PM_HEALER)) { - if (!Deaf && !(moves % 5)) - verbalize("Doc, I can't help you unless you cooperate."); - dmg = 0; - } else hitmsg(mtmp, mattk); - } - break; - case AD_CURS: - hitmsg(mtmp, mattk); - if(!night() && mdat == &mons[PM_GREMLIN]) break; - if(!mtmp->mcan && !rn2(10)) { - if (!Deaf) { - if (Blind) You_hear("laughter."); - else pline("%s chuckles.", Monnam(mtmp)); - } - if (u.umonnum == PM_CLAY_GOLEM) { - pline("Some writing vanishes from your head!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } - attrcurse(); - } - break; - case AD_STUN: - hitmsg(mtmp, mattk); - if(!mtmp->mcan && !rn2(4)) { - make_stunned((HStun & TIMEOUT) + (long)dmg, TRUE); - dmg /= 2; - } - break; - case AD_ACID: - hitmsg(mtmp, mattk); - if (!mtmp->mcan && !rn2(3)) - if (Acid_resistance) { - pline("You're covered in acid, but it seems harmless."); - dmg = 0; - } else { - pline("You're covered in acid! It burns!"); - exercise(A_STR, FALSE); - } - else dmg = 0; - break; - case AD_SLOW: - hitmsg(mtmp, mattk); - if (uncancelled && HFast && - !defends(AD_SLOW, uwep) && !rn2(4)) - u_slow_down(); - break; - case AD_DREN: - hitmsg(mtmp, mattk); - if (uncancelled && !rn2(4)) - drain_en(dmg); - dmg = 0; - break; - case AD_CONF: - hitmsg(mtmp, mattk); - if(!mtmp->mcan && !rn2(4) && !mtmp->mspec_used) { - mtmp->mspec_used = mtmp->mspec_used + (dmg + rn2(6)); - if(Confusion) - You("are getting even more confused."); - else You("are getting confused."); - make_confused(HConfusion + dmg, FALSE); - } - dmg = 0; - break; - case AD_DETH: - pline("%s reaches out with its deadly touch.", Monnam(mtmp)); - if (is_undead(youmonst.data)) { - /* Still does normal damage */ - pline("Was that the touch of death?"); - break; - } - switch (rn2(20)) { - case 19: case 18: case 17: - if (!Antimagic) { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "touch of death"); - done(DIED); - dmg = 0; - break; - } /* else FALLTHRU */ - default: /* case 16: ... case 5: */ - You_feel("your life force draining away..."); - permdmg = 1; /* actual damage done below */ - break; - case 4: case 3: case 2: case 1: case 0: - if (Antimagic) shieldeff(u.ux, u.uy); - pline("Lucky for you, it didn't work!"); - dmg = 0; - break; - } - break; - case AD_PEST: - pline("%s reaches out, and you feel fever and chills.", - Monnam(mtmp)); - (void) diseasemu(mdat); /* plus the normal damage */ - break; - case AD_FAMN: - pline("%s reaches out, and your body shrivels.", - Monnam(mtmp)); - exercise(A_CON, FALSE); - if (!is_fainted()) morehungry(rn1(40,40)); - /* plus the normal damage */ - break; - case AD_SLIM: - hitmsg(mtmp, mattk); - if (!uncancelled) break; - if (flaming(youmonst.data)) { - pline_The("slime burns away!"); - dmg = 0; - } else if (Unchanging || - noncorporeal(youmonst.data) || - youmonst.data == &mons[PM_GREEN_SLIME]) { - You("are unaffected."); - dmg = 0; - } else if (!Slimed) { - You("don't feel very well."); - make_slimed(10L, (char*) 0); - delayed_killer(SLIMED, KILLED_BY_AN, mtmp->data->mname); - } else - pline("Yuck!"); - break; - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - hitmsg(mtmp, mattk); - /* uncancelled is sufficient enough; please - don't make this attack less frequent */ - if (uncancelled) { - struct obj *obj = some_armor(&youmonst); + boolean goaway = FALSE; + pline("%s hits! (I hope you don't mind.)", Monnam(mtmp)); + if (Upolyd) { + u.mh += rnd(7); + if (!rn2(7)) { + /* no upper limit necessary; effect is temporary */ + u.mhmax++; + if (!rn2(13)) + goaway = TRUE; + } + if (u.mh > u.mhmax) + u.mh = u.mhmax; + } else { + u.uhp += rnd(7); + if (!rn2(7)) { + /* hard upper limit via nurse care: 25 * ulevel */ + if (u.uhpmax < 5 * u.ulevel + d(2 * u.ulevel, 10)) + u.uhpmax++; + if (!rn2(13)) + goaway = TRUE; + } + if (u.uhp > u.uhpmax) + u.uhp = u.uhpmax; + } + if (!rn2(3)) + exercise(A_STR, TRUE); + if (!rn2(3)) + exercise(A_CON, TRUE); + if (Sick) + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + context.botl = 1; + if (goaway) { + mongone(mtmp); + return 2; + } else if (!rn2(33)) { + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + monflee(mtmp, d(3, 6), TRUE, FALSE); + return 3; + } + dmg = 0; + } else { + if (Role_if(PM_HEALER)) { + if (!Deaf && !(moves % 5)) + verbalize("Doc, I can't help you unless you cooperate."); + dmg = 0; + } else + hitmsg(mtmp, mattk); + } + break; + case AD_CURS: + hitmsg(mtmp, mattk); + if (!night() && mdat == &mons[PM_GREMLIN]) + break; + if (!mtmp->mcan && !rn2(10)) { + if (!Deaf) { + if (Blind) + You_hear("laughter."); + else + pline("%s chuckles.", Monnam(mtmp)); + } + if (u.umonnum == PM_CLAY_GOLEM) { + pline("Some writing vanishes from your head!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + break; + } + attrcurse(); + } + break; + case AD_STUN: + hitmsg(mtmp, mattk); + if (!mtmp->mcan && !rn2(4)) { + make_stunned((HStun & TIMEOUT) + (long) dmg, TRUE); + dmg /= 2; + } + break; + case AD_ACID: + hitmsg(mtmp, mattk); + if (!mtmp->mcan && !rn2(3)) + if (Acid_resistance) { + pline("You're covered in acid, but it seems harmless."); + dmg = 0; + } else { + pline("You're covered in acid! It burns!"); + exercise(A_STR, FALSE); + } + else + dmg = 0; + break; + case AD_SLOW: + hitmsg(mtmp, mattk); + if (uncancelled && HFast && !defends(AD_SLOW, uwep) && !rn2(4)) + u_slow_down(); + break; + case AD_DREN: + hitmsg(mtmp, mattk); + if (uncancelled && !rn2(4)) + drain_en(dmg); + dmg = 0; + break; + case AD_CONF: + hitmsg(mtmp, mattk); + if (!mtmp->mcan && !rn2(4) && !mtmp->mspec_used) { + mtmp->mspec_used = mtmp->mspec_used + (dmg + rn2(6)); + if (Confusion) + You("are getting even more confused."); + else + You("are getting confused."); + make_confused(HConfusion + dmg, FALSE); + } + dmg = 0; + break; + case AD_DETH: + pline("%s reaches out with its deadly touch.", Monnam(mtmp)); + if (is_undead(youmonst.data)) { + /* Still does normal damage */ + pline("Was that the touch of death?"); + break; + } + switch (rn2(20)) { + case 19: + case 18: + case 17: + if (!Antimagic) { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "touch of death"); + done(DIED); + dmg = 0; + break; + } /* else FALLTHRU */ + default: /* case 16: ... case 5: */ + You_feel("your life force draining away..."); + permdmg = 1; /* actual damage done below */ + break; + case 4: + case 3: + case 2: + case 1: + case 0: + if (Antimagic) + shieldeff(u.ux, u.uy); + pline("Lucky for you, it didn't work!"); + dmg = 0; + break; + } + break; + case AD_PEST: + pline("%s reaches out, and you feel fever and chills.", Monnam(mtmp)); + (void) diseasemu(mdat); /* plus the normal damage */ + break; + case AD_FAMN: + pline("%s reaches out, and your body shrivels.", Monnam(mtmp)); + exercise(A_CON, FALSE); + if (!is_fainted()) + morehungry(rn1(40, 40)); + /* plus the normal damage */ + break; + case AD_SLIM: + hitmsg(mtmp, mattk); + if (!uncancelled) + break; + if (flaming(youmonst.data)) { + pline_The("slime burns away!"); + dmg = 0; + } else if (Unchanging || noncorporeal(youmonst.data) + || youmonst.data == &mons[PM_GREEN_SLIME]) { + You("are unaffected."); + dmg = 0; + } else if (!Slimed) { + You("don't feel very well."); + make_slimed(10L, (char *) 0); + delayed_killer(SLIMED, KILLED_BY_AN, mtmp->data->mname); + } else + pline("Yuck!"); + break; + case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ + hitmsg(mtmp, mattk); + /* uncancelled is sufficient enough; please + don't make this attack less frequent */ + if (uncancelled) { + struct obj *obj = some_armor(&youmonst); - if (drain_item(obj)) { - pline("%s less effective.", Yobjnam2(obj, "seem")); - } - } - break; - default: dmg = 0; - break; - } - if (u.uhp < 1) done_in_by(mtmp, DIED); + if (drain_item(obj)) { + pline("%s less effective.", Yobjnam2(obj, "seem")); + } + } + break; + default: + dmg = 0; + break; + } + if (u.uhp < 1) + done_in_by(mtmp, DIED); -/* Negative armor class reduces damage done instead of fully protecting - * against hits. - */ - if (dmg && u.uac < 0) { - dmg -= rnd(-u.uac); - if (dmg < 1) dmg = 1; - } + /* Negative armor class reduces damage done instead of fully protecting + * against hits. + */ + if (dmg && u.uac < 0) { + dmg -= rnd(-u.uac); + if (dmg < 1) + dmg = 1; + } - if(dmg) { - if (Half_physical_damage - /* Mitre of Holiness */ - || (Role_if(PM_PRIEST) && uarmh && is_quest_artifact(uarmh) && - (is_undead(mtmp->data) || - is_demon(mtmp->data) || is_vampshifter(mtmp)))) - dmg = (dmg+1) / 2; + if (dmg) { + if (Half_physical_damage + /* Mitre of Holiness */ + || (Role_if(PM_PRIEST) && uarmh && is_quest_artifact(uarmh) + && (is_undead(mtmp->data) || is_demon(mtmp->data) + || is_vampshifter(mtmp)))) + dmg = (dmg + 1) / 2; - if (permdmg) { /* Death's life force drain */ - int lowerlimit, *hpmax_p; - /* - * Apply some of the damage to permanent hit points: - * polymorphed 100% against poly'd hpmax - * hpmax > 25*lvl 100% against normal hpmax - * hpmax > 10*lvl 50..100% - * hpmax > 5*lvl 25..75% - * otherwise 0..50% - * Never reduces hpmax below 1 hit point per level. - */ - permdmg = rn2(dmg / 2 + 1); - if (Upolyd || u.uhpmax > 25 * u.ulevel) permdmg = dmg; - else if (u.uhpmax > 10 * u.ulevel) permdmg += dmg / 2; - else if (u.uhpmax > 5 * u.ulevel) permdmg += dmg / 4; + if (permdmg) { /* Death's life force drain */ + int lowerlimit, *hpmax_p; + /* + * Apply some of the damage to permanent hit points: + * polymorphed 100% against poly'd hpmax + * hpmax > 25*lvl 100% against normal hpmax + * hpmax > 10*lvl 50..100% + * hpmax > 5*lvl 25..75% + * otherwise 0..50% + * Never reduces hpmax below 1 hit point per level. + */ + permdmg = rn2(dmg / 2 + 1); + if (Upolyd || u.uhpmax > 25 * u.ulevel) + permdmg = dmg; + else if (u.uhpmax > 10 * u.ulevel) + permdmg += dmg / 2; + else if (u.uhpmax > 5 * u.ulevel) + permdmg += dmg / 4; - if (Upolyd) { - hpmax_p = &u.mhmax; - /* [can't use youmonst.m_lev] */ - lowerlimit = min((int)youmonst.data->mlevel, u.ulevel); - } else { - hpmax_p = &u.uhpmax; - lowerlimit = u.ulevel; - } - if (*hpmax_p - permdmg > lowerlimit) - *hpmax_p -= permdmg; - else if (*hpmax_p > lowerlimit) - *hpmax_p = lowerlimit; - /* else unlikely... - * already at or below minimum threshold; do nothing */ - context.botl = 1; - } + if (Upolyd) { + hpmax_p = &u.mhmax; + /* [can't use youmonst.m_lev] */ + lowerlimit = min((int) youmonst.data->mlevel, u.ulevel); + } else { + hpmax_p = &u.uhpmax; + lowerlimit = u.ulevel; + } + if (*hpmax_p - permdmg > lowerlimit) + *hpmax_p -= permdmg; + else if (*hpmax_p > lowerlimit) + *hpmax_p = lowerlimit; + /* else unlikely... + * already at or below minimum threshold; do nothing */ + context.botl = 1; + } - mdamageu(mtmp, dmg); - } + mdamageu(mtmp, dmg); + } - if (dmg) - res = passiveum(olduasmon, mtmp, mattk); - else - res = 1; - stop_occupation(); - return res; + if (dmg) + res = passiveum(olduasmon, mtmp, mattk); + else + res = 1; + stop_occupation(); + return res; } /* An interface for use when taking a blindfold off, for example, @@ -1542,586 +1621,624 @@ dopois: boolean gulp_blnd_check() { - struct attack *mattk; + struct attack *mattk; - if (!Blinded && u.uswallow && - (mattk = attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) && - can_blnd(u.ustuck, &youmonst, mattk->aatyp, (struct obj*)0)) { - ++u.uswldtim; /* compensate for gulpmu change */ - (void) gulpmu(u.ustuck, mattk); - return TRUE; - } - return FALSE; + if (!Blinded && u.uswallow + && (mattk = attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) + && can_blnd(u.ustuck, &youmonst, mattk->aatyp, (struct obj *) 0)) { + ++u.uswldtim; /* compensate for gulpmu change */ + (void) gulpmu(u.ustuck, mattk); + return TRUE; + } + return FALSE; } STATIC_OVL int -gulpmu(mtmp, mattk) /* monster swallows you, or damage if u.uswallow */ - register struct monst *mtmp; - register struct attack *mattk; -{ - struct trap *t = t_at(u.ux, u.uy); - int tmp = d((int)mattk->damn, (int)mattk->damd); - int tim_tmp; - register struct obj *otmp2; - int i; - boolean physical_damage = FALSE; - - if (!u.uswallow) { /* swallows you */ - int omx = mtmp->mx, omy = mtmp->my; - - if (!engulf_target(mtmp, &youmonst)) return 0; - if ((t && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT))) && - sobj_at(BOULDER, u.ux, u.uy)) - return(0); - - if (Punished) unplacebc(); /* ball&chain go away */ - remove_monster(omx, omy); - mtmp->mtrapped = 0; /* no longer on old trap */ - place_monster(mtmp, u.ux, u.uy); - u.ustuck = mtmp; - newsym(mtmp->mx,mtmp->my); - if (is_animal(mtmp->data) && u.usteed) { - char buf[BUFSZ]; - /* Too many quirks presently if hero and steed - * are swallowed. Pretend purple worms don't - * like horses for now :-) - */ - Strcpy(buf, mon_nam(u.usteed)); - pline ("%s lunges forward and plucks you off %s!", - Monnam(mtmp), buf); - dismount_steed(DISMOUNT_ENGULFED); - } else - pline("%s engulfs you!", Monnam(mtmp)); - stop_occupation(); - reset_occupations(); /* behave as if you had moved */ - - if (u.utrap) { - You("are released from the %s!", - u.utraptype==TT_WEB ? "web" : "trap"); - u.utrap = 0; - } - - i = number_leashed(); - if (i > 0) { - const char *s = (i > 1) ? "leashes" : "leash"; - pline_The("%s %s loose.", s, vtense(s, "snap")); - unleash_all(); - } - - if (touch_petrifies(youmonst.data) && !resists_ston(mtmp)) { - /* put the attacker back where it started; - the resulting statue will end up there */ - remove_monster(mtmp->mx, mtmp->my); /* u.ux,u.uy */ - place_monster(mtmp, omx, omy); - minstapetrify(mtmp, TRUE); - /* normally unstuck() would do this, but we're not - fully swallowed yet so that won't work here */ - if (Punished) placebc(); - u.ustuck = 0; - return (mtmp->mhp > 0) ? 0 : 2; - } - - display_nhwindow(WIN_MESSAGE, FALSE); - vision_recalc(2); /* hero can't see anything */ - u.uswallow = 1; - /* for digestion, shorter time is more dangerous; - for other swallowings, longer time means more - chances for the swallower to attack */ - if (mattk->adtyp == AD_DGST) { - tim_tmp = 25 - (int)mtmp->m_lev; - if (tim_tmp > 0) tim_tmp = rnd(tim_tmp) / 2; - else if (tim_tmp < 0) tim_tmp = -(rnd(-tim_tmp) / 2); - /* having good armor & high constitution makes - it take longer for you to be digested, but - you'll end up trapped inside for longer too */ - tim_tmp += -u.uac + 10 + (ACURR(A_CON) / 3 - 1); - } else { - /* higher level attacker takes longer to eject hero */ - tim_tmp = rnd((int)mtmp->m_lev + 10 / 2); - } - /* u.uswldtim always set > 1 */ - u.uswldtim = (unsigned)((tim_tmp < 2) ? 2 : tim_tmp); - swallowed(1); - for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj) - (void) snuff_lit(otmp2); - } - - if (mtmp != u.ustuck) return(0); - if (u.uswldtim > 0) u.uswldtim -= 1; - - switch(mattk->adtyp) { - - case AD_DGST: - physical_damage = TRUE; - if (Slow_digestion) { - /* Messages are handled below */ - u.uswldtim = 0; - tmp = 0; - } else if (u.uswldtim == 0) { - pline("%s totally digests you!", Monnam(mtmp)); - tmp = u.uhp; - if (Half_physical_damage) tmp *= 2; /* sorry */ - } else { - pline("%s%s digests you!", Monnam(mtmp), - (u.uswldtim == 2) ? " thoroughly" : - (u.uswldtim == 1) ? " utterly" : ""); - exercise(A_STR, FALSE); - } - break; - case AD_PHYS: - physical_damage = TRUE; - if (mtmp->data == &mons[PM_FOG_CLOUD]) { - You("are laden with moisture and %s", - flaming(youmonst.data) ? "are smoldering out!" : - Breathless ? "find it mildly uncomfortable." : - amphibious(youmonst.data) ? "feel comforted." : - "can barely breathe!"); - /* NB: Amphibious includes Breathless */ - if (Amphibious && !flaming(youmonst.data)) tmp = 0; - } else { - You("are pummeled with debris!"); - exercise(A_STR, FALSE); - } - break; - case AD_ACID: - if (Acid_resistance) { - You("are covered with a seemingly harmless goo."); - tmp = 0; - } else { - if (Hallucination) pline("Ouch! You've been slimed!"); - else You("are covered in slime! It burns!"); - exercise(A_STR, FALSE); - } - break; - case AD_BLND: - if (can_blnd(mtmp, &youmonst, mattk->aatyp, (struct obj*)0)) { - if(!Blind) { - long was_blinded = Blinded; - if (!Blinded) You_cant("see in here!"); - make_blinded((long)tmp,FALSE); - if (!was_blinded && !Blind) Your1(vision_clears); - } else - /* keep him blind until disgorged */ - make_blinded(Blinded+1,FALSE); - } - tmp = 0; - break; - case AD_ELEC: - if(!mtmp->mcan && rn2(2)) { - pline_The("air around you crackles with electricity."); - if (Shock_resistance) { - shieldeff(u.ux, u.uy); - You("seem unhurt."); - ugolemeffects(AD_ELEC,tmp); - tmp = 0; - } - } else tmp = 0; - break; - case AD_COLD: - if(!mtmp->mcan && rn2(2)) { - if (Cold_resistance) { - shieldeff(u.ux, u.uy); - You_feel("mildly chilly."); - ugolemeffects(AD_COLD,tmp); - tmp = 0; - } else You("are freezing to death!"); - } else tmp = 0; - break; - case AD_FIRE: - if(!mtmp->mcan && rn2(2)) { - if (Fire_resistance) { - shieldeff(u.ux, u.uy); - You_feel("mildly hot."); - ugolemeffects(AD_FIRE,tmp); - tmp = 0; - } else You("are burning to a crisp!"); - burn_away_slime(); - } else tmp = 0; - break; - case AD_DISE: - if (!diseasemu(mtmp->data)) tmp = 0; - break; - case AD_DREN: - /* AC magic cancellation doesn't help when engulfed */ - if (!mtmp->mcan && rn2(4)) - drain_en(tmp); - tmp = 0; - break; - default: - physical_damage = TRUE; - tmp = 0; - break; - } - - if (physical_damage) tmp = Maybe_Half_Phys(tmp); - - mdamageu(mtmp, tmp); - if (tmp) stop_occupation(); - - if (touch_petrifies(youmonst.data) && !resists_ston(mtmp)) { - pline("%s very hurriedly %s you!", Monnam(mtmp), - is_animal(mtmp->data)? "regurgitates" : "expels"); - expels(mtmp, mtmp->data, FALSE); - } else if (!u.uswldtim || youmonst.data->msize >= MZ_HUGE) { - You("get %s!", is_animal(mtmp->data)? "regurgitated" : "expelled"); - if (flags.verbose && (is_animal(mtmp->data) || - (dmgtype(mtmp->data, AD_DGST) && Slow_digestion))) - pline("Obviously %s doesn't like your taste.", mon_nam(mtmp)); - expels(mtmp, mtmp->data, FALSE); - } - return(1); -} - -STATIC_OVL int -explmu(mtmp, mattk, ufound) /* monster explodes in your face */ +gulpmu(mtmp, mattk) /* monster swallows you, or damage if u.uswallow */ register struct monst *mtmp; -register struct attack *mattk; +register struct attack *mattk; +{ + struct trap *t = t_at(u.ux, u.uy); + int tmp = d((int) mattk->damn, (int) mattk->damd); + int tim_tmp; + register struct obj *otmp2; + int i; + boolean physical_damage = FALSE; + + if (!u.uswallow) { /* swallows you */ + int omx = mtmp->mx, omy = mtmp->my; + + if (!engulf_target(mtmp, &youmonst)) + return 0; + if ((t && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT))) + && sobj_at(BOULDER, u.ux, u.uy)) + return (0); + + if (Punished) + unplacebc(); /* ball&chain go away */ + remove_monster(omx, omy); + mtmp->mtrapped = 0; /* no longer on old trap */ + place_monster(mtmp, u.ux, u.uy); + u.ustuck = mtmp; + newsym(mtmp->mx, mtmp->my); + if (is_animal(mtmp->data) && u.usteed) { + char buf[BUFSZ]; + /* Too many quirks presently if hero and steed + * are swallowed. Pretend purple worms don't + * like horses for now :-) + */ + Strcpy(buf, mon_nam(u.usteed)); + pline("%s lunges forward and plucks you off %s!", Monnam(mtmp), + buf); + dismount_steed(DISMOUNT_ENGULFED); + } else + pline("%s engulfs you!", Monnam(mtmp)); + stop_occupation(); + reset_occupations(); /* behave as if you had moved */ + + if (u.utrap) { + You("are released from the %s!", + u.utraptype == TT_WEB ? "web" : "trap"); + u.utrap = 0; + } + + i = number_leashed(); + if (i > 0) { + const char *s = (i > 1) ? "leashes" : "leash"; + pline_The("%s %s loose.", s, vtense(s, "snap")); + unleash_all(); + } + + if (touch_petrifies(youmonst.data) && !resists_ston(mtmp)) { + /* put the attacker back where it started; + the resulting statue will end up there */ + remove_monster(mtmp->mx, mtmp->my); /* u.ux,u.uy */ + place_monster(mtmp, omx, omy); + minstapetrify(mtmp, TRUE); + /* normally unstuck() would do this, but we're not + fully swallowed yet so that won't work here */ + if (Punished) + placebc(); + u.ustuck = 0; + return (mtmp->mhp > 0) ? 0 : 2; + } + + display_nhwindow(WIN_MESSAGE, FALSE); + vision_recalc(2); /* hero can't see anything */ + u.uswallow = 1; + /* for digestion, shorter time is more dangerous; + for other swallowings, longer time means more + chances for the swallower to attack */ + if (mattk->adtyp == AD_DGST) { + tim_tmp = 25 - (int) mtmp->m_lev; + if (tim_tmp > 0) + tim_tmp = rnd(tim_tmp) / 2; + else if (tim_tmp < 0) + tim_tmp = -(rnd(-tim_tmp) / 2); + /* having good armor & high constitution makes + it take longer for you to be digested, but + you'll end up trapped inside for longer too */ + tim_tmp += -u.uac + 10 + (ACURR(A_CON) / 3 - 1); + } else { + /* higher level attacker takes longer to eject hero */ + tim_tmp = rnd((int) mtmp->m_lev + 10 / 2); + } + /* u.uswldtim always set > 1 */ + u.uswldtim = (unsigned) ((tim_tmp < 2) ? 2 : tim_tmp); + swallowed(1); + for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj) + (void) snuff_lit(otmp2); + } + + if (mtmp != u.ustuck) + return (0); + if (u.uswldtim > 0) + u.uswldtim -= 1; + + switch (mattk->adtyp) { + case AD_DGST: + physical_damage = TRUE; + if (Slow_digestion) { + /* Messages are handled below */ + u.uswldtim = 0; + tmp = 0; + } else if (u.uswldtim == 0) { + pline("%s totally digests you!", Monnam(mtmp)); + tmp = u.uhp; + if (Half_physical_damage) + tmp *= 2; /* sorry */ + } else { + pline("%s%s digests you!", Monnam(mtmp), + (u.uswldtim == 2) ? " thoroughly" + : (u.uswldtim == 1) ? " utterly" : ""); + exercise(A_STR, FALSE); + } + break; + case AD_PHYS: + physical_damage = TRUE; + if (mtmp->data == &mons[PM_FOG_CLOUD]) { + You("are laden with moisture and %s", + flaming(youmonst.data) + ? "are smoldering out!" + : Breathless ? "find it mildly uncomfortable." + : amphibious(youmonst.data) + ? "feel comforted." + : "can barely breathe!"); + /* NB: Amphibious includes Breathless */ + if (Amphibious && !flaming(youmonst.data)) + tmp = 0; + } else { + You("are pummeled with debris!"); + exercise(A_STR, FALSE); + } + break; + case AD_ACID: + if (Acid_resistance) { + You("are covered with a seemingly harmless goo."); + tmp = 0; + } else { + if (Hallucination) + pline("Ouch! You've been slimed!"); + else + You("are covered in slime! It burns!"); + exercise(A_STR, FALSE); + } + break; + case AD_BLND: + if (can_blnd(mtmp, &youmonst, mattk->aatyp, (struct obj *) 0)) { + if (!Blind) { + long was_blinded = Blinded; + if (!Blinded) + You_cant("see in here!"); + make_blinded((long) tmp, FALSE); + if (!was_blinded && !Blind) + Your1(vision_clears); + } else + /* keep him blind until disgorged */ + make_blinded(Blinded + 1, FALSE); + } + tmp = 0; + break; + case AD_ELEC: + if (!mtmp->mcan && rn2(2)) { + pline_The("air around you crackles with electricity."); + if (Shock_resistance) { + shieldeff(u.ux, u.uy); + You("seem unhurt."); + ugolemeffects(AD_ELEC, tmp); + tmp = 0; + } + } else + tmp = 0; + break; + case AD_COLD: + if (!mtmp->mcan && rn2(2)) { + if (Cold_resistance) { + shieldeff(u.ux, u.uy); + You_feel("mildly chilly."); + ugolemeffects(AD_COLD, tmp); + tmp = 0; + } else + You("are freezing to death!"); + } else + tmp = 0; + break; + case AD_FIRE: + if (!mtmp->mcan && rn2(2)) { + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + You_feel("mildly hot."); + ugolemeffects(AD_FIRE, tmp); + tmp = 0; + } else + You("are burning to a crisp!"); + burn_away_slime(); + } else + tmp = 0; + break; + case AD_DISE: + if (!diseasemu(mtmp->data)) + tmp = 0; + break; + case AD_DREN: + /* AC magic cancellation doesn't help when engulfed */ + if (!mtmp->mcan && rn2(4)) + drain_en(tmp); + tmp = 0; + break; + default: + physical_damage = TRUE; + tmp = 0; + break; + } + + if (physical_damage) + tmp = Maybe_Half_Phys(tmp); + + mdamageu(mtmp, tmp); + if (tmp) + stop_occupation(); + + if (touch_petrifies(youmonst.data) && !resists_ston(mtmp)) { + pline("%s very hurriedly %s you!", Monnam(mtmp), + is_animal(mtmp->data) ? "regurgitates" : "expels"); + expels(mtmp, mtmp->data, FALSE); + } else if (!u.uswldtim || youmonst.data->msize >= MZ_HUGE) { + You("get %s!", is_animal(mtmp->data) ? "regurgitated" : "expelled"); + if (flags.verbose + && (is_animal(mtmp->data) + || (dmgtype(mtmp->data, AD_DGST) && Slow_digestion))) + pline("Obviously %s doesn't like your taste.", mon_nam(mtmp)); + expels(mtmp, mtmp->data, FALSE); + } + return (1); +} + +STATIC_OVL int explmu(mtmp, mattk, ufound) /* monster explodes in your face */ +register struct monst *mtmp; +register struct attack *mattk; boolean ufound; { boolean physical_damage = TRUE, kill_agr = TRUE; - if (mtmp->mcan) return(0); + if (mtmp->mcan) + return (0); if (!ufound) - pline("%s explodes at a spot in %s!", - canseemon(mtmp) ? Monnam(mtmp) : "It", - levl[mtmp->mux][mtmp->muy].typ == WATER - ? "empty water" : "thin air"); + pline("%s explodes at a spot in %s!", + canseemon(mtmp) ? Monnam(mtmp) : "It", + levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water" + : "thin air"); else { - register int tmp = d((int)mattk->damn, (int)mattk->damd); - register boolean not_affected = defends((int)mattk->adtyp, uwep); + register int tmp = d((int) mattk->damn, (int) mattk->damd); + register boolean not_affected = defends((int) mattk->adtyp, uwep); - hitmsg(mtmp, mattk); + hitmsg(mtmp, mattk); - switch (mattk->adtyp) { - case AD_COLD: - physical_damage = FALSE; - not_affected |= Cold_resistance; - goto common; - case AD_FIRE: - physical_damage = FALSE; - not_affected |= Fire_resistance; - goto common; - case AD_ELEC: - physical_damage = FALSE; - not_affected |= Shock_resistance; -common: + switch (mattk->adtyp) { + case AD_COLD: + physical_damage = FALSE; + not_affected |= Cold_resistance; + goto common; + case AD_FIRE: + physical_damage = FALSE; + not_affected |= Fire_resistance; + goto common; + case AD_ELEC: + physical_damage = FALSE; + not_affected |= Shock_resistance; + common: - if (!not_affected) { - if (ACURR(A_DEX) > rnd(20)) { - You("duck some of the blast."); - tmp = (tmp+1) / 2; - } else { - if (flags.verbose) You("get blasted!"); - } - if (mattk->adtyp == AD_FIRE) burn_away_slime(); - if (physical_damage) tmp = Maybe_Half_Phys(tmp); - mdamageu(mtmp, tmp); - } - break; + if (!not_affected) { + if (ACURR(A_DEX) > rnd(20)) { + You("duck some of the blast."); + tmp = (tmp + 1) / 2; + } else { + if (flags.verbose) + You("get blasted!"); + } + if (mattk->adtyp == AD_FIRE) + burn_away_slime(); + if (physical_damage) + tmp = Maybe_Half_Phys(tmp); + mdamageu(mtmp, tmp); + } + break; - case AD_BLND: - not_affected = resists_blnd(&youmonst); - if (!not_affected) { - /* sometimes you're affected even if it's invisible */ - if (mon_visible(mtmp) || (rnd(tmp /= 2) > u.ulevel)) { - You("are blinded by a blast of light!"); - make_blinded((long)tmp, FALSE); - if (!Blind) Your1(vision_clears); - } else if (flags.verbose) - You("get the impression it was not terribly bright."); - } - break; + case AD_BLND: + not_affected = resists_blnd(&youmonst); + if (!not_affected) { + /* sometimes you're affected even if it's invisible */ + if (mon_visible(mtmp) || (rnd(tmp /= 2) > u.ulevel)) { + You("are blinded by a blast of light!"); + make_blinded((long) tmp, FALSE); + if (!Blind) + Your1(vision_clears); + } else if (flags.verbose) + You("get the impression it was not terribly bright."); + } + break; - case AD_HALU: - not_affected |= Blind || - (u.umonnum == PM_BLACK_LIGHT || - u.umonnum == PM_VIOLET_FUNGUS || - dmgtype(youmonst.data, AD_STUN)); - if (!not_affected) { - boolean chg; - if (!Hallucination) - You("are caught in a blast of kaleidoscopic light!"); - /* avoid hallucinating the black light as it dies */ - mondead(mtmp); /* remove it from map now */ - kill_agr = FALSE; /* already killed (maybe lifesaved) */ - chg = make_hallucinated(HHallucination + (long)tmp,FALSE,0L); - You("%s.", chg ? "are freaked out" : "seem unaffected"); - } - break; + case AD_HALU: + not_affected |= Blind || (u.umonnum == PM_BLACK_LIGHT + || u.umonnum == PM_VIOLET_FUNGUS + || dmgtype(youmonst.data, AD_STUN)); + if (!not_affected) { + boolean chg; + if (!Hallucination) + You("are caught in a blast of kaleidoscopic light!"); + /* avoid hallucinating the black light as it dies */ + mondead(mtmp); /* remove it from map now */ + kill_agr = FALSE; /* already killed (maybe lifesaved) */ + chg = + make_hallucinated(HHallucination + (long) tmp, FALSE, 0L); + You("%s.", chg ? "are freaked out" : "seem unaffected"); + } + break; - default: - break; - } - if (not_affected) { - You("seem unaffected by it."); - ugolemeffects((int)mattk->adtyp, tmp); - } + default: + break; + } + if (not_affected) { + You("seem unaffected by it."); + ugolemeffects((int) mattk->adtyp, tmp); + } } - if (kill_agr) mondead(mtmp); - wake_nearto(mtmp->mx, mtmp->my, 7*7); + if (kill_agr) + mondead(mtmp); + wake_nearto(mtmp->mx, mtmp->my, 7 * 7); return (mtmp->mhp > 0) ? 0 : 2; } -int -gazemu(mtmp, mattk) /* monster gazes at you */ - register struct monst *mtmp; - register struct attack *mattk; +int gazemu(mtmp, mattk) /* monster gazes at you */ +register struct monst *mtmp; +register struct attack *mattk; { - static const char * const reactions[] = { - "confused", /* [0] */ - "stunned", /* [1] */ - "puzzled", "dazzled", /* [2,3] */ - "irritated", "inflamed", /* [4,5] */ - "tired", /* [6] */ - "dulled", /* [7] */ - }; - int react = -1; - boolean cancelled = (mtmp->mcan != 0), already = FALSE; + static const char *const reactions[] = { + "confused", /* [0] */ + "stunned", /* [1] */ + "puzzled", "dazzled", /* [2,3] */ + "irritated", "inflamed", /* [4,5] */ + "tired", /* [6] */ + "dulled", /* [7] */ + }; + int react = -1; + boolean cancelled = (mtmp->mcan != 0), already = FALSE; - /* assumes that hero has to see monster's gaze in order to be - affected, rather than monster just having to look at hero; - when hallucinating, hero's brain doesn't register what - it's seeing correctly so the gaze is usually ineffective - [this could be taken a lot farther and select a gaze effect - appropriate to what's currently being displayed, giving - ordinary monsters a gaze attack when hero thinks he or she - is facing a gazing creature, but let's not go that far...] */ - if (Hallucination && rn2(4)) cancelled = TRUE; + /* assumes that hero has to see monster's gaze in order to be + affected, rather than monster just having to look at hero; + when hallucinating, hero's brain doesn't register what + it's seeing correctly so the gaze is usually ineffective + [this could be taken a lot farther and select a gaze effect + appropriate to what's currently being displayed, giving + ordinary monsters a gaze attack when hero thinks he or she + is facing a gazing creature, but let's not go that far...] */ + if (Hallucination && rn2(4)) + cancelled = TRUE; - switch(mattk->adtyp) { - case AD_STON: - if (cancelled || !mtmp->mcansee) { - if (!canseemon(mtmp)) break; /* silently */ - pline("%s %s.", Monnam(mtmp), - (mtmp->data == &mons[PM_MEDUSA] && mtmp->mcan) ? - "doesn't look all that ugly" : - "gazes ineffectually"); - break; - } - if (Reflecting && couldsee(mtmp->mx, mtmp->my) && - mtmp->data == &mons[PM_MEDUSA]) { - /* hero has line of sight to Medusa and she's not blind */ - boolean useeit = canseemon(mtmp); + switch (mattk->adtyp) { + case AD_STON: + if (cancelled || !mtmp->mcansee) { + if (!canseemon(mtmp)) + break; /* silently */ + pline("%s %s.", Monnam(mtmp), + (mtmp->data == &mons[PM_MEDUSA] && mtmp->mcan) + ? "doesn't look all that ugly" + : "gazes ineffectually"); + break; + } + if (Reflecting && couldsee(mtmp->mx, mtmp->my) + && mtmp->data == &mons[PM_MEDUSA]) { + /* hero has line of sight to Medusa and she's not blind */ + boolean useeit = canseemon(mtmp); - if (useeit) - (void) ureflects("%s gaze is reflected by your %s.", - s_suffix(Monnam(mtmp))); - if (mon_reflects(mtmp, !useeit ? (char *)0 : - "The gaze is reflected away by %s %s!")) - break; - if (!m_canseeu(mtmp)) { /* probably you're invisible */ - if (useeit) - pline( - "%s doesn't seem to notice that %s gaze was reflected.", - Monnam(mtmp), mhis(mtmp)); - break; - } - if (useeit) - pline("%s is turned to stone!", Monnam(mtmp)); - stoned = TRUE; - killed(mtmp); + if (useeit) + (void) ureflects("%s gaze is reflected by your %s.", + s_suffix(Monnam(mtmp))); + if (mon_reflects( + mtmp, !useeit ? (char *) 0 + : "The gaze is reflected away by %s %s!")) + break; + if (!m_canseeu(mtmp)) { /* probably you're invisible */ + if (useeit) + pline("%s doesn't seem to notice that %s gaze was " + "reflected.", + Monnam(mtmp), mhis(mtmp)); + break; + } + if (useeit) + pline("%s is turned to stone!", Monnam(mtmp)); + stoned = TRUE; + killed(mtmp); - if (mtmp->mhp > 0) break; - return 2; - } - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - !Stone_resistance) { - You("meet %s gaze.", s_suffix(mon_nam(mtmp))); - stop_occupation(); - if(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) - break; - You("turn to stone..."); - killer.format = KILLED_BY; - Strcpy(killer.name, mtmp->data->mname); - done(STONING); - } - break; - case AD_CONF: - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - mtmp->mcansee && !mtmp->mspec_used && rn2(5)) { - if (cancelled) { - react = 0; /* "confused" */ - already = (mtmp->mconf != 0); - } else { - int conf = d(3,4); + if (mtmp->mhp > 0) + break; + return 2; + } + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) + && !Stone_resistance) { + You("meet %s gaze.", s_suffix(mon_nam(mtmp))); + stop_occupation(); + if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) + break; + You("turn to stone..."); + killer.format = KILLED_BY; + Strcpy(killer.name, mtmp->data->mname); + done(STONING); + } + break; + case AD_CONF: + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && mtmp->mcansee + && !mtmp->mspec_used && rn2(5)) { + if (cancelled) { + react = 0; /* "confused" */ + already = (mtmp->mconf != 0); + } else { + int conf = d(3, 4); - mtmp->mspec_used = mtmp->mspec_used + (conf + rn2(6)); - if(!Confusion) - pline("%s gaze confuses you!", - s_suffix(Monnam(mtmp))); - else - You("are getting more and more confused."); - make_confused(HConfusion + conf, FALSE); - stop_occupation(); - } - } - break; - case AD_STUN: - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - mtmp->mcansee && !mtmp->mspec_used && rn2(5)) { - if (cancelled) { - react = 1; /* "stunned" */ - already = (mtmp->mstun != 0); - } else { - int stun = d(2,6); + mtmp->mspec_used = mtmp->mspec_used + (conf + rn2(6)); + if (!Confusion) + pline("%s gaze confuses you!", s_suffix(Monnam(mtmp))); + else + You("are getting more and more confused."); + make_confused(HConfusion + conf, FALSE); + stop_occupation(); + } + } + break; + case AD_STUN: + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && mtmp->mcansee + && !mtmp->mspec_used && rn2(5)) { + if (cancelled) { + react = 1; /* "stunned" */ + already = (mtmp->mstun != 0); + } else { + int stun = d(2, 6); - mtmp->mspec_used = mtmp->mspec_used + (stun + rn2(6)); - pline("%s stares piercingly at you!", Monnam(mtmp)); - make_stunned((HStun & TIMEOUT) + (long)stun, TRUE); - stop_occupation(); - } - } - break; - case AD_BLND: - if (canseemon(mtmp) && !resists_blnd(&youmonst) && - distu(mtmp->mx,mtmp->my) <= BOLT_LIM*BOLT_LIM) { - if (cancelled) { - react = rn1(2,2); /* "puzzled" || "dazzled" */ - already = (mtmp->mcansee == 0); - /* Archons gaze every round; we don't want cancelled ones - giving the "seems puzzled/dazzled" message that often */ - if (mtmp->mcan && mtmp->data == &mons[PM_ARCHON] && rn2(5)) - react = -1; - } else { - int blnd = d((int)mattk->damn, (int)mattk->damd); + mtmp->mspec_used = mtmp->mspec_used + (stun + rn2(6)); + pline("%s stares piercingly at you!", Monnam(mtmp)); + make_stunned((HStun & TIMEOUT) + (long) stun, TRUE); + stop_occupation(); + } + } + break; + case AD_BLND: + if (canseemon(mtmp) && !resists_blnd(&youmonst) + && distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM) { + if (cancelled) { + react = rn1(2, 2); /* "puzzled" || "dazzled" */ + already = (mtmp->mcansee == 0); + /* Archons gaze every round; we don't want cancelled ones + giving the "seems puzzled/dazzled" message that often */ + if (mtmp->mcan && mtmp->data == &mons[PM_ARCHON] && rn2(5)) + react = -1; + } else { + int blnd = d((int) mattk->damn, (int) mattk->damd); - You("are blinded by %s radiance!", - s_suffix(mon_nam(mtmp))); - make_blinded((long)blnd,FALSE); - stop_occupation(); - /* not blind at this point implies you're wearing - the Eyes of the Overworld; make them block this - particular stun attack too */ - if (!Blind) Your1(vision_clears); - else make_stunned((long)d(1,3),TRUE); - } - } - break; - case AD_FIRE: - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - mtmp->mcansee && !mtmp->mspec_used && rn2(5)) { - if (cancelled) { - react = rn1(2,4); /* "irritated" || "inflamed" */ - } else { - int dmg = d(2,6), lev = (int)mtmp->m_lev; + You("are blinded by %s radiance!", s_suffix(mon_nam(mtmp))); + make_blinded((long) blnd, FALSE); + stop_occupation(); + /* not blind at this point implies you're wearing + the Eyes of the Overworld; make them block this + particular stun attack too */ + if (!Blind) + Your1(vision_clears); + else + make_stunned((long) d(1, 3), TRUE); + } + } + break; + case AD_FIRE: + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && mtmp->mcansee + && !mtmp->mspec_used && rn2(5)) { + if (cancelled) { + react = rn1(2, 4); /* "irritated" || "inflamed" */ + } else { + int dmg = d(2, 6), lev = (int) mtmp->m_lev; - pline("%s attacks you with a fiery gaze!", Monnam(mtmp)); - stop_occupation(); - if (Fire_resistance) { - pline_The("fire doesn't feel hot!"); - dmg = 0; - } - burn_away_slime(); - if (lev > rn2(20)) destroy_item(SCROLL_CLASS, AD_FIRE); - if (lev > rn2(20)) destroy_item(POTION_CLASS, AD_FIRE); - if (lev > rn2(25)) destroy_item(SPBOOK_CLASS, AD_FIRE); - if (dmg) mdamageu(mtmp, dmg); - } - } - break; + pline("%s attacks you with a fiery gaze!", Monnam(mtmp)); + stop_occupation(); + if (Fire_resistance) { + pline_The("fire doesn't feel hot!"); + dmg = 0; + } + burn_away_slime(); + if (lev > rn2(20)) + destroy_item(SCROLL_CLASS, AD_FIRE); + if (lev > rn2(20)) + destroy_item(POTION_CLASS, AD_FIRE); + if (lev > rn2(25)) + destroy_item(SPBOOK_CLASS, AD_FIRE); + if (dmg) + mdamageu(mtmp, dmg); + } + } + break; #ifdef PM_BEHOLDER /* work in progress */ - case AD_SLEE: - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - mtmp->mcansee && multi >= 0 && !rn2(5) && !Sleep_resistance) { - if (cancelled) { - react = 6; /* "tired" */ - already = (mtmp->mfrozen != 0); /* can't happen... */ - } else { - fall_asleep(-rnd(10), TRUE); - pline("%s gaze makes you very sleepy...", - s_suffix(Monnam(mtmp))); - } - } - break; - case AD_SLOW: - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && - mtmp->mcansee && (HFast & (INTRINSIC|TIMEOUT)) && - !defends(AD_SLOW, uwep) && !rn2(4)) { - if (cancelled) { - react = 7; /* "dulled" */ - already = (mtmp->mspeed == MSLOW); - } else { - u_slow_down(); - stop_occupation(); - } - } - break; + case AD_SLEE: + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && mtmp->mcansee + && multi >= 0 && !rn2(5) && !Sleep_resistance) { + if (cancelled) { + react = 6; /* "tired" */ + already = (mtmp->mfrozen != 0); /* can't happen... */ + } else { + fall_asleep(-rnd(10), TRUE); + pline("%s gaze makes you very sleepy...", + s_suffix(Monnam(mtmp))); + } + } + break; + case AD_SLOW: + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my) && mtmp->mcansee + && (HFast & (INTRINSIC | TIMEOUT)) && !defends(AD_SLOW, uwep) + && !rn2(4)) { + if (cancelled) { + react = 7; /* "dulled" */ + already = (mtmp->mspeed == MSLOW); + } else { + u_slow_down(); + stop_occupation(); + } + } + break; #endif /* BEHOLDER */ - default: - impossible("Gaze attack %d?", mattk->adtyp); - break; - } - if (react >= 0) { - if (Hallucination && rn2(3)) react = rn2(SIZE(reactions)); - /* cancelled/hallucinatory feedback; monster might look "confused", - "stunned",&c but we don't actually set corresponding attribute */ - pline("%s looks %s%s.", Monnam(mtmp), - !rn2(3) ? "" : already ? "quite " : - (!rn2(2) ? "a bit " : "somewhat "), - reactions[react]); - } - return(0); + default: + impossible("Gaze attack %d?", mattk->adtyp); + break; + } + if (react >= 0) { + if (Hallucination && rn2(3)) + react = rn2(SIZE(reactions)); + /* cancelled/hallucinatory feedback; monster might look "confused", + "stunned",&c but we don't actually set corresponding attribute */ + pline("%s looks %s%s.", Monnam(mtmp), + !rn2(3) ? "" : already ? "quite " + : (!rn2(2) ? "a bit " : "somewhat "), + reactions[react]); + } + return (0); } -void -mdamageu(mtmp, n) /* mtmp hits you for n points damage */ +void mdamageu(mtmp, n) /* mtmp hits you for n points damage */ register struct monst *mtmp; register int n; { - context.botl = 1; - if (Upolyd) { - u.mh -= n; - if (u.mh < 1) rehumanize(); - } else { - u.uhp -= n; - if (u.uhp < 1) done_in_by(mtmp, DIED); - } + context.botl = 1; + if (Upolyd) { + u.mh -= n; + if (u.mh < 1) + rehumanize(); + } else { + u.uhp -= n; + if (u.uhp < 1) + done_in_by(mtmp, DIED); + } } int -could_seduce(magr,mdef,mattk) +could_seduce(magr, mdef, mattk) struct monst *magr, *mdef; struct attack *mattk; /* returns 0 if seduction impossible, * 1 if fine, * 2 if wrong gender for nymph */ { - register struct permonst *pagr; - boolean agrinvis, defperc; - xchar genagr, gendef; + register struct permonst *pagr; + boolean agrinvis, defperc; + xchar genagr, gendef; - if (is_animal(magr->data)) return (0); - if(magr == &youmonst) { - pagr = youmonst.data; - agrinvis = (Invis != 0); - genagr = poly_gender(); - } else { - pagr = magr->data; - agrinvis = magr->minvis; - genagr = gender(magr); - } - if(mdef == &youmonst) { - defperc = (See_invisible != 0); - gendef = poly_gender(); - } else { - defperc = perceives(mdef->data); - gendef = gender(mdef); - } + if (is_animal(magr->data)) + return (0); + if (magr == &youmonst) { + pagr = youmonst.data; + agrinvis = (Invis != 0); + genagr = poly_gender(); + } else { + pagr = magr->data; + agrinvis = magr->minvis; + genagr = gender(magr); + } + if (mdef == &youmonst) { + defperc = (See_invisible != 0); + gendef = poly_gender(); + } else { + defperc = perceives(mdef->data); + gendef = gender(mdef); + } - if(agrinvis && !defperc && - (!SYSOPT_SEDUCE || ( mattk && mattk->adtyp != AD_SSEX))) - return 0; + if (agrinvis && !defperc + && (!SYSOPT_SEDUCE || (mattk && mattk->adtyp != AD_SSEX))) + return 0; - if(pagr->mlet != S_NYMPH - && ((pagr != &mons[PM_INCUBUS] && pagr != &mons[PM_SUCCUBUS]) - || (SYSOPT_SEDUCE && mattk && mattk->adtyp != AD_SSEX))) - return 0; - - if(genagr == 1 - gendef) - return 1; - else - return (pagr->mlet == S_NYMPH) ? 2 : 0; + if (pagr->mlet != S_NYMPH + && ((pagr != &mons[PM_INCUBUS] && pagr != &mons[PM_SUCCUBUS]) + || (SYSOPT_SEDUCE && mattk && mattk->adtyp != AD_SSEX))) + return 0; + + if (genagr == 1 - gendef) + return 1; + else + return (pagr->mlet == S_NYMPH) ? 2 : 0; } /* Returns 1 if monster teleported */ @@ -2129,234 +2246,265 @@ int doseduce(mon) register struct monst *mon; { - register struct obj *ring, *nring; - boolean fem = (mon->data == &mons[PM_SUCCUBUS]); /* otherwise incubus */ - int tried_gloves = 0; - char qbuf[QBUFSZ]; + register struct obj *ring, *nring; + boolean fem = (mon->data == &mons[PM_SUCCUBUS]); /* otherwise incubus */ + int tried_gloves = 0; + char qbuf[QBUFSZ]; - if (mon->mcan || mon->mspec_used) { - pline("%s acts as though %s has got a %sheadache.", - Monnam(mon), mhe(mon), - mon->mcan ? "severe " : ""); - return 0; - } + if (mon->mcan || mon->mspec_used) { + pline("%s acts as though %s has got a %sheadache.", Monnam(mon), + mhe(mon), mon->mcan ? "severe " : ""); + return 0; + } - if (unconscious()) { - pline("%s seems dismayed at your lack of response.", - Monnam(mon)); - return 0; - } + if (unconscious()) { + pline("%s seems dismayed at your lack of response.", Monnam(mon)); + return 0; + } - if (Blind) pline("It caresses you..."); - else You_feel("very attracted to %s.", mon_nam(mon)); - /* if in the process of putting armor on or taking armor off, - interrupt that activity now */ - (void) stop_donning((struct obj *)0); - /* don't try to take off gloves if cursed weapon blocks them */ - if (welded(uwep)) tried_gloves = 1; + if (Blind) + pline("It caresses you..."); + else + You_feel("very attracted to %s.", mon_nam(mon)); + /* if in the process of putting armor on or taking armor off, + interrupt that activity now */ + (void) stop_donning((struct obj *) 0); + /* don't try to take off gloves if cursed weapon blocks them */ + if (welded(uwep)) + tried_gloves = 1; - for(ring = invent; ring; ring = nring) { - nring = ring->nobj; - if (ring->otyp != RIN_ADORNMENT) continue; - if (fem) { - if (ring->owornmask && uarmg) { - /* don't take off worn ring if gloves are in the way */ - if (!tried_gloves++) mayberem(uarmg, "gloves"); - if (uarmg) continue; /* next ring might not be worn */ - } - if (rn2(20) < ACURR(A_CHA)) { - (void)safe_qbuf(qbuf, "\"That ", - " looks pretty. May I have it?\"", - ring, xname, simpleonames, "ring"); - makeknown(RIN_ADORNMENT); - if (yn(qbuf) == 'n') continue; - } else pline("%s decides she'd like %s, and takes it.", - Blind ? "She" : Monnam(mon), yname(ring)); - makeknown(RIN_ADORNMENT); - if (ring==uleft || ring==uright) Ring_gone(ring); - if (ring==uwep) setuwep((struct obj *)0); - if (ring==uswapwep) setuswapwep((struct obj *)0); - if (ring==uquiver) setuqwep((struct obj *)0); - freeinv(ring); - (void) mpickobj(mon,ring); - } else { - if (uleft && uright && uleft->otyp == RIN_ADORNMENT - && uright->otyp==RIN_ADORNMENT) - break; - if (ring==uleft || ring==uright) continue; - if (uarmg) { - /* don't put on ring if gloves are in the way */ - if (!tried_gloves++) mayberem(uarmg, "gloves"); - if (uarmg) break; /* no point trying further rings */ - } - if (rn2(20) < ACURR(A_CHA)) { - (void)safe_qbuf(qbuf, "\"That ", - " looks pretty. Would you wear it for me?\"", - ring, xname, simpleonames, "ring"); - makeknown(RIN_ADORNMENT); - if (yn(qbuf) == 'n') continue; - } else { - pline("%s decides you'd look prettier wearing %s,", - Blind ? "He" : Monnam(mon), yname(ring)); - pline("and puts it on your finger."); - } - makeknown(RIN_ADORNMENT); - if (!uright) { - pline("%s puts %s on your right %s.", - Blind ? "He" : Monnam(mon), the(xname(ring)), body_part(HAND)); - setworn(ring, RIGHT_RING); - } else if (!uleft) { - pline("%s puts %s on your left %s.", - Blind ? "He" : Monnam(mon), the(xname(ring)), body_part(HAND)); - setworn(ring, LEFT_RING); - } else if (uright && uright->otyp != RIN_ADORNMENT) { - pline("%s replaces %s with %s.", - Blind ? "He" : Monnam(mon), yname(uright), yname(ring)); - Ring_gone(uright); - setworn(ring, RIGHT_RING); - } else if (uleft && uleft->otyp != RIN_ADORNMENT) { - pline("%s replaces %s with %s.", - Blind ? "He" : Monnam(mon), yname(uleft), yname(ring)); - Ring_gone(uleft); - setworn(ring, LEFT_RING); - } else impossible("ring replacement"); - Ring_on(ring); - prinv((char *)0, ring, 0L); - } - } + for (ring = invent; ring; ring = nring) { + nring = ring->nobj; + if (ring->otyp != RIN_ADORNMENT) + continue; + if (fem) { + if (ring->owornmask && uarmg) { + /* don't take off worn ring if gloves are in the way */ + if (!tried_gloves++) + mayberem(uarmg, "gloves"); + if (uarmg) + continue; /* next ring might not be worn */ + } + if (rn2(20) < ACURR(A_CHA)) { + (void) safe_qbuf(qbuf, "\"That ", + " looks pretty. May I have it?\"", ring, + xname, simpleonames, "ring"); + makeknown(RIN_ADORNMENT); + if (yn(qbuf) == 'n') + continue; + } else + pline("%s decides she'd like %s, and takes it.", + Blind ? "She" : Monnam(mon), yname(ring)); + makeknown(RIN_ADORNMENT); + if (ring == uleft || ring == uright) + Ring_gone(ring); + if (ring == uwep) + setuwep((struct obj *) 0); + if (ring == uswapwep) + setuswapwep((struct obj *) 0); + if (ring == uquiver) + setuqwep((struct obj *) 0); + freeinv(ring); + (void) mpickobj(mon, ring); + } else { + if (uleft && uright && uleft->otyp == RIN_ADORNMENT + && uright->otyp == RIN_ADORNMENT) + break; + if (ring == uleft || ring == uright) + continue; + if (uarmg) { + /* don't put on ring if gloves are in the way */ + if (!tried_gloves++) + mayberem(uarmg, "gloves"); + if (uarmg) + break; /* no point trying further rings */ + } + if (rn2(20) < ACURR(A_CHA)) { + (void) safe_qbuf( + qbuf, "\"That ", + " looks pretty. Would you wear it for me?\"", ring, + xname, simpleonames, "ring"); + makeknown(RIN_ADORNMENT); + if (yn(qbuf) == 'n') + continue; + } else { + pline("%s decides you'd look prettier wearing %s,", + Blind ? "He" : Monnam(mon), yname(ring)); + pline("and puts it on your finger."); + } + makeknown(RIN_ADORNMENT); + if (!uright) { + pline("%s puts %s on your right %s.", + Blind ? "He" : Monnam(mon), the(xname(ring)), + body_part(HAND)); + setworn(ring, RIGHT_RING); + } else if (!uleft) { + pline("%s puts %s on your left %s.", + Blind ? "He" : Monnam(mon), the(xname(ring)), + body_part(HAND)); + setworn(ring, LEFT_RING); + } else if (uright && uright->otyp != RIN_ADORNMENT) { + pline("%s replaces %s with %s.", Blind ? "He" : Monnam(mon), + yname(uright), yname(ring)); + Ring_gone(uright); + setworn(ring, RIGHT_RING); + } else if (uleft && uleft->otyp != RIN_ADORNMENT) { + pline("%s replaces %s with %s.", Blind ? "He" : Monnam(mon), + yname(uleft), yname(ring)); + Ring_gone(uleft); + setworn(ring, LEFT_RING); + } else + impossible("ring replacement"); + Ring_on(ring); + prinv((char *) 0, ring, 0L); + } + } - if (!uarmc && !uarmf && !uarmg && !uarms && !uarmh - && !uarmu) - pline("%s murmurs sweet nothings into your ear.", - Blind ? (fem ? "She" : "He") : Monnam(mon)); - else - pline("%s murmurs in your ear, while helping you undress.", - Blind ? (fem ? "She" : "He") : Monnam(mon)); - mayberem(uarmc, cloak_simple_name(uarmc)); - if(!uarmc) - mayberem(uarm, "suit"); - mayberem(uarmf, "boots"); - if (!tried_gloves) - mayberem(uarmg, "gloves"); - mayberem(uarms, "shield"); - mayberem(uarmh, helm_simple_name(uarmh)); - if(!uarmc && !uarm) - mayberem(uarmu, "shirt"); + if (!uarmc && !uarmf && !uarmg && !uarms && !uarmh && !uarmu) + pline("%s murmurs sweet nothings into your ear.", + Blind ? (fem ? "She" : "He") : Monnam(mon)); + else + pline("%s murmurs in your ear, while helping you undress.", + Blind ? (fem ? "She" : "He") : Monnam(mon)); + mayberem(uarmc, cloak_simple_name(uarmc)); + if (!uarmc) + mayberem(uarm, "suit"); + mayberem(uarmf, "boots"); + if (!tried_gloves) + mayberem(uarmg, "gloves"); + mayberem(uarms, "shield"); + mayberem(uarmh, helm_simple_name(uarmh)); + if (!uarmc && !uarm) + mayberem(uarmu, "shirt"); - if (uarm || uarmc) { - verbalize("You're such a %s; I wish...", - flags.female ? "sweet lady" : "nice guy"); - if (!tele_restrict(mon)) (void) rloc(mon, FALSE); - return 1; - } - if (u.ualign.type == A_CHAOTIC) - adjalign(1); + if (uarm || uarmc) { + verbalize("You're such a %s; I wish...", + flags.female ? "sweet lady" : "nice guy"); + if (!tele_restrict(mon)) + (void) rloc(mon, FALSE); + return 1; + } + if (u.ualign.type == A_CHAOTIC) + adjalign(1); - /* by this point you have discovered mon's identity, blind or not... */ - pline("Time stands still while you and %s lie in each other's arms...", - noit_mon_nam(mon)); - if (rn2(35) > ACURR(A_CHA) + ACURR(A_INT)) { - /* Don't bother with mspec_used here... it didn't get tired! */ - pline("%s seems to have enjoyed it more than you...", - noit_Monnam(mon)); - switch (rn2(5)) { - case 0: You_feel("drained of energy."); - u.uen = 0; - u.uenmax -= rnd(Half_physical_damage ? 5 : 10); - exercise(A_CON, FALSE); - if (u.uenmax < 0) u.uenmax = 0; - break; - case 1: You("are down in the dumps."); - (void) adjattrib(A_CON, -1, TRUE); - exercise(A_CON, FALSE); - context.botl = 1; - break; - case 2: Your("senses are dulled."); - (void) adjattrib(A_WIS, -1, TRUE); - exercise(A_WIS, FALSE); - context.botl = 1; - break; - case 3: - if (!resists_drli(&youmonst)) { - You_feel("out of shape."); - losexp("overexertion"); - } else { - You("have a curious feeling..."); - } - break; - case 4: { - int tmp; - You_feel("exhausted."); - exercise(A_STR, FALSE); - tmp = rn1(10, 6); - losehp(Maybe_Half_Phys(tmp), "exhaustion", KILLED_BY); - break; - } - } - } else { - mon->mspec_used = rnd(100); /* monster is worn out */ - You("seem to have enjoyed it more than %s...", - noit_mon_nam(mon)); - switch (rn2(5)) { - case 0: You_feel("raised to your full potential."); - exercise(A_CON, TRUE); - u.uen = (u.uenmax += rnd(5)); - break; - case 1: You_feel("good enough to do it again."); - (void) adjattrib(A_CON, 1, TRUE); - exercise(A_CON, TRUE); - context.botl = 1; - break; - case 2: You("will always remember %s...", noit_mon_nam(mon)); - (void) adjattrib(A_WIS, 1, TRUE); - exercise(A_WIS, TRUE); - context.botl = 1; - break; - case 3: pline("That was a very educational experience."); - pluslvl(FALSE); - exercise(A_WIS, TRUE); - break; - case 4: You_feel("restored to health!"); - u.uhp = u.uhpmax; - if (Upolyd) u.mh = u.mhmax; - exercise(A_STR, TRUE); - context.botl = 1; - break; - } - } + /* by this point you have discovered mon's identity, blind or not... */ + pline("Time stands still while you and %s lie in each other's arms...", + noit_mon_nam(mon)); + if (rn2(35) > ACURR(A_CHA) + ACURR(A_INT)) { + /* Don't bother with mspec_used here... it didn't get tired! */ + pline("%s seems to have enjoyed it more than you...", + noit_Monnam(mon)); + switch (rn2(5)) { + case 0: + You_feel("drained of energy."); + u.uen = 0; + u.uenmax -= rnd(Half_physical_damage ? 5 : 10); + exercise(A_CON, FALSE); + if (u.uenmax < 0) + u.uenmax = 0; + break; + case 1: + You("are down in the dumps."); + (void) adjattrib(A_CON, -1, TRUE); + exercise(A_CON, FALSE); + context.botl = 1; + break; + case 2: + Your("senses are dulled."); + (void) adjattrib(A_WIS, -1, TRUE); + exercise(A_WIS, FALSE); + context.botl = 1; + break; + case 3: + if (!resists_drli(&youmonst)) { + You_feel("out of shape."); + losexp("overexertion"); + } else { + You("have a curious feeling..."); + } + break; + case 4: { + int tmp; + You_feel("exhausted."); + exercise(A_STR, FALSE); + tmp = rn1(10, 6); + losehp(Maybe_Half_Phys(tmp), "exhaustion", KILLED_BY); + break; + } + } + } else { + mon->mspec_used = rnd(100); /* monster is worn out */ + You("seem to have enjoyed it more than %s...", noit_mon_nam(mon)); + switch (rn2(5)) { + case 0: + You_feel("raised to your full potential."); + exercise(A_CON, TRUE); + u.uen = (u.uenmax += rnd(5)); + break; + case 1: + You_feel("good enough to do it again."); + (void) adjattrib(A_CON, 1, TRUE); + exercise(A_CON, TRUE); + context.botl = 1; + break; + case 2: + You("will always remember %s...", noit_mon_nam(mon)); + (void) adjattrib(A_WIS, 1, TRUE); + exercise(A_WIS, TRUE); + context.botl = 1; + break; + case 3: + pline("That was a very educational experience."); + pluslvl(FALSE); + exercise(A_WIS, TRUE); + break; + case 4: + You_feel("restored to health!"); + u.uhp = u.uhpmax; + if (Upolyd) + u.mh = u.mhmax; + exercise(A_STR, TRUE); + context.botl = 1; + break; + } + } - if (mon->mtame) /* don't charge */ ; - else if (rn2(20) < ACURR(A_CHA)) { - pline("%s demands that you pay %s, but you refuse...", - noit_Monnam(mon), - Blind ? (fem ? "her" : "him") : mhim(mon)); - } else if (u.umonnum == PM_LEPRECHAUN) - pline("%s tries to take your money, but fails...", - noit_Monnam(mon)); - else { - long cost; - long umoney = money_cnt(invent); + if (mon->mtame) /* don't charge */ + ; + else if (rn2(20) < ACURR(A_CHA)) { + pline("%s demands that you pay %s, but you refuse...", + noit_Monnam(mon), Blind ? (fem ? "her" : "him") : mhim(mon)); + } else if (u.umonnum == PM_LEPRECHAUN) + pline("%s tries to take your money, but fails...", noit_Monnam(mon)); + else { + long cost; + long umoney = money_cnt(invent); - if (umoney > (long)LARGEST_INT - 10L) - cost = (long) rnd(LARGEST_INT) + 500L; - else - cost = (long) rnd((int)umoney + 10) + 500L; - if (mon->mpeaceful) { - cost /= 5L; - if (!cost) cost = 1L; - } - if (cost > umoney) cost = umoney; - if (!cost) verbalize("It's on the house!"); - else { - pline("%s takes %ld %s for services rendered!", - noit_Monnam(mon), cost, currency(cost)); - money2mon(mon, cost); - context.botl = 1; - } - } - if (!rn2(25)) mon->mcan = 1; /* monster is worn out */ - if (!tele_restrict(mon)) (void) rloc(mon, FALSE); - return 1; + if (umoney > (long) LARGEST_INT - 10L) + cost = (long) rnd(LARGEST_INT) + 500L; + else + cost = (long) rnd((int) umoney + 10) + 500L; + if (mon->mpeaceful) { + cost /= 5L; + if (!cost) + cost = 1L; + } + if (cost > umoney) + cost = umoney; + if (!cost) + verbalize("It's on the house!"); + else { + pline("%s takes %ld %s for services rendered!", noit_Monnam(mon), + cost, currency(cost)); + money2mon(mon, cost); + context.botl = 1; + } + } + if (!rn2(25)) + mon->mcan = 1; /* monster is worn out */ + if (!tele_restrict(mon)) + (void) rloc(mon, FALSE); + return 1; } STATIC_OVL void @@ -2364,210 +2512,235 @@ mayberem(obj, str) register struct obj *obj; const char *str; { - char qbuf[QBUFSZ]; + char qbuf[QBUFSZ]; - if (!obj || !obj->owornmask) return; + if (!obj || !obj->owornmask) + return; - if (rn2(20) < ACURR(A_CHA)) { - Sprintf(qbuf,"\"Shall I remove your %s, %s?\"", - str, - (!rn2(2) ? "lover" : !rn2(2) ? "dear" : "sweetheart")); - if (yn(qbuf) == 'n') return; - } else { - char hairbuf[BUFSZ]; + if (rn2(20) < ACURR(A_CHA)) { + Sprintf(qbuf, "\"Shall I remove your %s, %s?\"", str, + (!rn2(2) ? "lover" : !rn2(2) ? "dear" : "sweetheart")); + if (yn(qbuf) == 'n') + return; + } else { + char hairbuf[BUFSZ]; - Sprintf(hairbuf, "let me run my fingers through your %s", - body_part(HAIR)); - verbalize("Take off your %s; %s.", str, - (obj == uarm) ? "let's get a little closer" : - (obj == uarmc || obj == uarms) ? "it's in the way" : - (obj == uarmf) ? "let me rub your feet" : - (obj == uarmg) ? "they're too clumsy" : - (obj == uarmu) ? "let me massage you" : - /* obj == uarmh */ - hairbuf); - } - remove_worn_item(obj, TRUE); + Sprintf(hairbuf, "let me run my fingers through your %s", + body_part(HAIR)); + verbalize("Take off your %s; %s.", str, + (obj == uarm) ? "let's get a little closer" + : (obj == uarmc || obj == uarms) + ? "it's in the way" + : (obj == uarmf) + ? "let me rub your feet" + : (obj == uarmg) + ? "they're too clumsy" + : (obj == uarmu) + ? "let me massage you" + : + /* obj == uarmh */ + hairbuf); + } + remove_worn_item(obj, TRUE); } STATIC_OVL int -passiveum(olduasmon,mtmp,mattk) +passiveum(olduasmon, mtmp, mattk) struct permonst *olduasmon; register struct monst *mtmp; register struct attack *mattk; { - int i, tmp; + int i, tmp; - for (i = 0; ; i++) { - if (i >= NATTK) return 1; - if (olduasmon->mattk[i].aatyp == AT_NONE || - olduasmon->mattk[i].aatyp == AT_BOOM) break; - } - if (olduasmon->mattk[i].damn) - tmp = d((int)olduasmon->mattk[i].damn, - (int)olduasmon->mattk[i].damd); - else if(olduasmon->mattk[i].damd) - tmp = d((int)olduasmon->mlevel+1, (int)olduasmon->mattk[i].damd); - else - tmp = 0; + for (i = 0;; i++) { + if (i >= NATTK) + return 1; + if (olduasmon->mattk[i].aatyp == AT_NONE + || olduasmon->mattk[i].aatyp == AT_BOOM) + break; + } + if (olduasmon->mattk[i].damn) + tmp = + d((int) olduasmon->mattk[i].damn, (int) olduasmon->mattk[i].damd); + else if (olduasmon->mattk[i].damd) + tmp = d((int) olduasmon->mlevel + 1, (int) olduasmon->mattk[i].damd); + else + tmp = 0; - /* These affect the enemy even if you were "killed" (rehumanized) */ - switch(olduasmon->mattk[i].adtyp) { - case AD_ACID: - if (!rn2(2)) { - pline("%s is splashed by your acid!", Monnam(mtmp)); - if (resists_acid(mtmp)) { - pline("%s is not affected.", Monnam(mtmp)); - tmp = 0; - } - } else tmp = 0; - if (!rn2(30)) erode_armor(mtmp, ERODE_CORRODE); - if (!rn2(6)) acid_damage(MON_WEP(mtmp)); - goto assess_dmg; - case AD_STON: /* cockatrice */ - { - long protector = attk_protection((int)mattk->aatyp), - wornitems = mtmp->misc_worn_check; + /* These affect the enemy even if you were "killed" (rehumanized) */ + switch (olduasmon->mattk[i].adtyp) { + case AD_ACID: + if (!rn2(2)) { + pline("%s is splashed by your acid!", Monnam(mtmp)); + if (resists_acid(mtmp)) { + pline("%s is not affected.", Monnam(mtmp)); + tmp = 0; + } + } else + tmp = 0; + if (!rn2(30)) + erode_armor(mtmp, ERODE_CORRODE); + if (!rn2(6)) + acid_damage(MON_WEP(mtmp)); + goto assess_dmg; + case AD_STON: /* cockatrice */ + { + long protector = attk_protection((int) mattk->aatyp), + wornitems = mtmp->misc_worn_check; - /* wielded weapon gives same protection as gloves here */ - if (MON_WEP(mtmp) != 0) wornitems |= W_ARMG; + /* wielded weapon gives same protection as gloves here */ + if (MON_WEP(mtmp) != 0) + wornitems |= W_ARMG; - if (!resists_ston(mtmp) && (protector == 0L || - (protector != ~0L && - (wornitems & protector) != protector))) { - if (poly_when_stoned(mtmp->data)) { - mon_to_stone(mtmp); - return (1); - } - pline("%s turns to stone!", Monnam(mtmp)); - stoned = 1; - xkilled(mtmp, 0); - if (mtmp->mhp > 0) return 1; - return 2; - } - return 1; - } - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - if (otmp) { - (void) drain_item(otmp); - /* No message */ - } - return (1); - default: - break; - } - if (!Upolyd) return 1; + if (!resists_ston(mtmp) + && (protector == 0L + || (protector != ~0L + && (wornitems & protector) != protector))) { + if (poly_when_stoned(mtmp->data)) { + mon_to_stone(mtmp); + return (1); + } + pline("%s turns to stone!", Monnam(mtmp)); + stoned = 1; + xkilled(mtmp, 0); + if (mtmp->mhp > 0) + return 1; + return 2; + } + return 1; + } + case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ + if (otmp) { + (void) drain_item(otmp); + /* No message */ + } + return (1); + default: + break; + } + if (!Upolyd) + return 1; - /* These affect the enemy only if you are still a monster */ - if (rn2(3)) switch(youmonst.data->mattk[i].adtyp) { - case AD_PHYS: - if (youmonst.data->mattk[i].aatyp == AT_BOOM) { - You("explode!"); - /* KMH, balance patch -- this is okay with unchanging */ - rehumanize(); - goto assess_dmg; - } - break; - case AD_PLYS: /* Floating eye */ - if (tmp > 127) tmp = 127; - if (u.umonnum == PM_FLOATING_EYE) { - if (!rn2(4)) tmp = 127; - if (mtmp->mcansee && haseyes(mtmp->data) && rn2(3) && - (perceives(mtmp->data) || !Invis)) { - if (Blind) - pline("As a blind %s, you cannot defend yourself.", - youmonst.data->mname); - else { - if (mon_reflects(mtmp, - "Your gaze is reflected by %s %s.")) - return 1; - pline("%s is frozen by your gaze!", Monnam(mtmp)); - paralyze_monst(mtmp, tmp); - return 3; - } - } - } else { /* gelatinous cube */ - pline("%s is frozen by you.", Monnam(mtmp)); - paralyze_monst(mtmp, tmp); - return 3; - } - return 1; - case AD_COLD: /* Brown mold or blue jelly */ - if (resists_cold(mtmp)) { - shieldeff(mtmp->mx, mtmp->my); - pline("%s is mildly chilly.", Monnam(mtmp)); - golemeffects(mtmp, AD_COLD, tmp); - tmp = 0; - break; - } - pline("%s is suddenly very cold!", Monnam(mtmp)); - u.mh += tmp / 2; - if (u.mhmax < u.mh) u.mhmax = u.mh; - if (u.mhmax > ((youmonst.data->mlevel+1) * 8)) - (void)split_mon(&youmonst, mtmp); - break; - case AD_STUN: /* Yellow mold */ - if (!mtmp->mstun) { - mtmp->mstun = 1; - pline("%s %s.", Monnam(mtmp), - makeplural(stagger(mtmp->data, "stagger"))); - } - tmp = 0; - break; - case AD_FIRE: /* Red mold */ - if (resists_fire(mtmp)) { - shieldeff(mtmp->mx, mtmp->my); - pline("%s is mildly warm.", Monnam(mtmp)); - golemeffects(mtmp, AD_FIRE, tmp); - tmp = 0; - break; - } - pline("%s is suddenly very hot!", Monnam(mtmp)); - break; - case AD_ELEC: - if (resists_elec(mtmp)) { - shieldeff(mtmp->mx, mtmp->my); - pline("%s is slightly tingled.", Monnam(mtmp)); - golemeffects(mtmp, AD_ELEC, tmp); - tmp = 0; - break; - } - pline("%s is jolted with your electricity!", Monnam(mtmp)); - break; - default: tmp = 0; - break; - } - else tmp = 0; + /* These affect the enemy only if you are still a monster */ + if (rn2(3)) + switch (youmonst.data->mattk[i].adtyp) { + case AD_PHYS: + if (youmonst.data->mattk[i].aatyp == AT_BOOM) { + You("explode!"); + /* KMH, balance patch -- this is okay with unchanging */ + rehumanize(); + goto assess_dmg; + } + break; + case AD_PLYS: /* Floating eye */ + if (tmp > 127) + tmp = 127; + if (u.umonnum == PM_FLOATING_EYE) { + if (!rn2(4)) + tmp = 127; + if (mtmp->mcansee && haseyes(mtmp->data) && rn2(3) + && (perceives(mtmp->data) || !Invis)) { + if (Blind) + pline("As a blind %s, you cannot defend yourself.", + youmonst.data->mname); + else { + if (mon_reflects(mtmp, + "Your gaze is reflected by %s %s.")) + return 1; + pline("%s is frozen by your gaze!", Monnam(mtmp)); + paralyze_monst(mtmp, tmp); + return 3; + } + } + } else { /* gelatinous cube */ + pline("%s is frozen by you.", Monnam(mtmp)); + paralyze_monst(mtmp, tmp); + return 3; + } + return 1; + case AD_COLD: /* Brown mold or blue jelly */ + if (resists_cold(mtmp)) { + shieldeff(mtmp->mx, mtmp->my); + pline("%s is mildly chilly.", Monnam(mtmp)); + golemeffects(mtmp, AD_COLD, tmp); + tmp = 0; + break; + } + pline("%s is suddenly very cold!", Monnam(mtmp)); + u.mh += tmp / 2; + if (u.mhmax < u.mh) + u.mhmax = u.mh; + if (u.mhmax > ((youmonst.data->mlevel + 1) * 8)) + (void) split_mon(&youmonst, mtmp); + break; + case AD_STUN: /* Yellow mold */ + if (!mtmp->mstun) { + mtmp->mstun = 1; + pline("%s %s.", Monnam(mtmp), + makeplural(stagger(mtmp->data, "stagger"))); + } + tmp = 0; + break; + case AD_FIRE: /* Red mold */ + if (resists_fire(mtmp)) { + shieldeff(mtmp->mx, mtmp->my); + pline("%s is mildly warm.", Monnam(mtmp)); + golemeffects(mtmp, AD_FIRE, tmp); + tmp = 0; + break; + } + pline("%s is suddenly very hot!", Monnam(mtmp)); + break; + case AD_ELEC: + if (resists_elec(mtmp)) { + shieldeff(mtmp->mx, mtmp->my); + pline("%s is slightly tingled.", Monnam(mtmp)); + golemeffects(mtmp, AD_ELEC, tmp); + tmp = 0; + break; + } + pline("%s is jolted with your electricity!", Monnam(mtmp)); + break; + default: + tmp = 0; + break; + } + else + tmp = 0; - assess_dmg: - if((mtmp->mhp -= tmp) <= 0) { - pline("%s dies!", Monnam(mtmp)); - xkilled(mtmp,0); - if (mtmp->mhp > 0) return 1; - return 2; - } - return 1; +assess_dmg: + if ((mtmp->mhp -= tmp) <= 0) { + pline("%s dies!", Monnam(mtmp)); + xkilled(mtmp, 0); + if (mtmp->mhp > 0) + return 1; + return 2; + } + return 1; } struct monst * cloneu() { - register struct monst *mon; - int mndx = monsndx(youmonst.data); + register struct monst *mon; + int mndx = monsndx(youmonst.data); - if (u.mh <= 1) return(struct monst *)0; - if (mvitals[mndx].mvflags & G_EXTINCT) return(struct monst *)0; - mon = makemon(youmonst.data, u.ux, u.uy, NO_MINVENT|MM_EDOG); - if (!mon) return NULL; - mon->mcloned = 1; - mon = christen_monst(mon, plname); - initedog(mon); - mon->m_lev = youmonst.data->mlevel; - mon->mhpmax = u.mhmax; - mon->mhp = u.mh / 2; - u.mh -= mon->mhp; - context.botl = 1; - return(mon); + if (u.mh <= 1) + return (struct monst *) 0; + if (mvitals[mndx].mvflags & G_EXTINCT) + return (struct monst *) 0; + mon = makemon(youmonst.data, u.ux, u.uy, NO_MINVENT | MM_EDOG); + if (!mon) + return NULL; + mon->mcloned = 1; + mon = christen_monst(mon, plname); + initedog(mon); + mon->m_lev = youmonst.data->mlevel; + mon->mhpmax = u.mhmax; + mon->mhp = u.mh / 2; + u.mh -= mon->mhp; + context.botl = 1; + return (mon); } /*mhitu.c*/ diff --git a/src/minion.c b/src/minion.c index 1d3e065c9..916fcdad3 100644 --- a/src/minion.c +++ b/src/minion.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 minion.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 minion.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.31 $ */ /* NetHack 3.6 minion.c $Date: 2009/05/06 10:46:52 $ $Revision: 1.26 $ */ /* SCCS Id: @(#)minion.c 3.5 2008/11/14 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -10,131 +10,140 @@ void newemin(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) mtmp->mextra = newmextra(); - if (!EMIN(mtmp)) { - EMIN(mtmp) = (struct emin *)alloc(sizeof(struct emin)); - (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); - } + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + if (!EMIN(mtmp)) { + EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); + (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); + } } void free_emin(mtmp) struct monst *mtmp; { - if (mtmp->mextra && EMIN(mtmp)) { - free((genericptr_t) EMIN(mtmp)); - EMIN(mtmp) = (struct emin *)0; - } - mtmp->isminion = 0; + if (mtmp->mextra && EMIN(mtmp)) { + free((genericptr_t) EMIN(mtmp)); + EMIN(mtmp) = (struct emin *) 0; + } + mtmp->isminion = 0; } /* count the number of monsters on the level */ int monster_census(spotted) -boolean spotted; /* seen|sensed vs all */ +boolean spotted; /* seen|sensed vs all */ { struct monst *mtmp; int count = 0; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (spotted && !canspotmon(mtmp)) continue; - ++count; + if (DEADMONSTER(mtmp)) + continue; + if (spotted && !canspotmon(mtmp)) + continue; + ++count; } return count; } -int -msummon(mon) /* mon summons a monster */ +int msummon(mon) /* mon summons a monster */ struct monst *mon; { - struct permonst *ptr; - int dtype = NON_PM, cnt = 0, result = 0, census; - aligntyp atyp; - struct monst *mtmp; + struct permonst *ptr; + int dtype = NON_PM, cnt = 0, result = 0, census; + aligntyp atyp; + struct monst *mtmp; - if (mon) { - ptr = mon->data; - atyp = mon->ispriest ? EPRI(mon)->shralign : - mon->isminion ? EMIN(mon)->min_align : - (ptr->maligntyp == A_NONE) ? A_NONE : sgn(ptr->maligntyp); - } else { - ptr = &mons[PM_WIZARD_OF_YENDOR]; - atyp = (ptr->maligntyp==A_NONE) ? A_NONE : sgn(ptr->maligntyp); - } + if (mon) { + ptr = mon->data; + atyp = mon->ispriest ? EPRI(mon)->shralign + : mon->isminion ? EMIN(mon)->min_align + : (ptr->maligntyp == A_NONE) + ? A_NONE + : sgn(ptr->maligntyp); + } else { + ptr = &mons[PM_WIZARD_OF_YENDOR]; + atyp = (ptr->maligntyp == A_NONE) ? A_NONE : sgn(ptr->maligntyp); + } - if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) { - dtype = (!rn2(20)) ? dprince(atyp) : - (!rn2(4)) ? dlord(atyp) : ndemon(atyp); - cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; - } else if (is_dlord(ptr)) { - dtype = (!rn2(50)) ? dprince(atyp) : - (!rn2(20)) ? dlord(atyp) : ndemon(atyp); - cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; - } else if (is_ndemon(ptr)) { - dtype = (!rn2(20)) ? dlord(atyp) : - (!rn2(6)) ? ndemon(atyp) : monsndx(ptr); - cnt = 1; - } else if (is_lminion(mon)) { - dtype = (is_lord(ptr) && !rn2(20)) ? llord() : - (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr); - cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1; - } else if (ptr == &mons[PM_ANGEL]) { - /* non-lawful angels can also summon */ - if (!rn2(6)) { - switch (atyp) { /* see summon_minion */ - case A_NEUTRAL: - dtype = PM_AIR_ELEMENTAL + rn2(4); - break; - case A_CHAOTIC: - case A_NONE: - dtype = ndemon(atyp); - break; - } - } else { - dtype = PM_ANGEL; - } - cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1; - } + if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) { + dtype = (!rn2(20)) ? dprince(atyp) : (!rn2(4)) ? dlord(atyp) + : ndemon(atyp); + cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; + } else if (is_dlord(ptr)) { + dtype = (!rn2(50)) ? dprince(atyp) : (!rn2(20)) ? dlord(atyp) + : ndemon(atyp); + cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; + } else if (is_ndemon(ptr)) { + dtype = (!rn2(20)) ? dlord(atyp) : (!rn2(6)) ? ndemon(atyp) + : monsndx(ptr); + cnt = 1; + } else if (is_lminion(mon)) { + dtype = (is_lord(ptr) && !rn2(20)) + ? llord() + : (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr); + cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1; + } else if (ptr == &mons[PM_ANGEL]) { + /* non-lawful angels can also summon */ + if (!rn2(6)) { + switch (atyp) { /* see summon_minion */ + case A_NEUTRAL: + dtype = PM_AIR_ELEMENTAL + rn2(4); + break; + case A_CHAOTIC: + case A_NONE: + dtype = ndemon(atyp); + break; + } + } else { + dtype = PM_ANGEL; + } + cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1; + } - if (dtype == NON_PM) return 0; + if (dtype == NON_PM) + return 0; - /* sanity checks */ - if (cnt > 1 && (mons[dtype].geno & G_UNIQ)) cnt = 1; - /* - * If this daemon is unique and being re-summoned (the only way we - * could get this far with an extinct dtype), try another. - */ - if (mvitals[dtype].mvflags & G_GONE) { - dtype = ndemon(atyp); - if (dtype == NON_PM) return 0; - } + /* sanity checks */ + if (cnt > 1 && (mons[dtype].geno & G_UNIQ)) + cnt = 1; + /* + * If this daemon is unique and being re-summoned (the only way we + * could get this far with an extinct dtype), try another. + */ + if (mvitals[dtype].mvflags & G_GONE) { + dtype = ndemon(atyp); + if (dtype == NON_PM) + return 0; + } - /* some candidates can generate a group of monsters, so simple - count of non-null makemon() result is not sufficient */ - census = monster_census(FALSE); + /* some candidates can generate a group of monsters, so simple + count of non-null makemon() result is not sufficient */ + census = monster_census(FALSE); - while (cnt > 0) { - mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN); - if (mtmp) { - result++; - /* an angel's alignment should match the summoner */ - if (dtype == PM_ANGEL) { - mtmp->isminion = 1; - EMIN(mtmp)->min_align = atyp; - /* renegade if same alignment but not peaceful - or peaceful but different alignment */ - EMIN(mtmp)->renegade = - (atyp != u.ualign.type) ^ !mtmp->mpeaceful; - } - } - cnt--; - } + while (cnt > 0) { + mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN); + if (mtmp) { + result++; + /* an angel's alignment should match the summoner */ + if (dtype == PM_ANGEL) { + mtmp->isminion = 1; + EMIN(mtmp)->min_align = atyp; + /* renegade if same alignment but not peaceful + or peaceful but different alignment */ + EMIN(mtmp)->renegade = + (atyp != u.ualign.type) ^ !mtmp->mpeaceful; + } + } + cnt--; + } - /* how many monsters exist now compared to before? */ - if (result) result = monster_census(FALSE) - census; + /* how many monsters exist now compared to before? */ + if (result) + result = monster_census(FALSE) - census; - return result; + return result; } void @@ -145,261 +154,265 @@ boolean talk; register struct monst *mon; int mnum; - switch ((int)alignment) { - case A_LAWFUL: - mnum = lminion(); - break; - case A_NEUTRAL: - mnum = PM_AIR_ELEMENTAL + rn2(4); - break; - case A_CHAOTIC: - case A_NONE: - mnum = ndemon(alignment); - break; - default: - impossible("unaligned player?"); - mnum = ndemon(A_NONE); - break; + switch ((int) alignment) { + case A_LAWFUL: + mnum = lminion(); + break; + case A_NEUTRAL: + mnum = PM_AIR_ELEMENTAL + rn2(4); + break; + case A_CHAOTIC: + case A_NONE: + mnum = ndemon(alignment); + break; + default: + impossible("unaligned player?"); + mnum = ndemon(A_NONE); + break; } if (mnum == NON_PM) { - mon = 0; + mon = 0; } else if (mnum == PM_ANGEL) { - mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN); - if (mon) { - mon->isminion = 1; - EMIN(mon)->min_align = alignment; - EMIN(mon)->renegade = FALSE; - } - } else if (mnum != PM_SHOPKEEPER && mnum != PM_GUARD && - mnum != PM_ALIGNED_PRIEST && mnum != PM_HIGH_PRIEST) { + mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN); + if (mon) { + mon->isminion = 1; + EMIN(mon)->min_align = alignment; + EMIN(mon)->renegade = FALSE; + } + } else if (mnum != PM_SHOPKEEPER && mnum != PM_GUARD + && mnum != PM_ALIGNED_PRIEST && mnum != PM_HIGH_PRIEST) { /* This was mons[mnum].pxlth == 0 but is this restriction - appropriate or necessary now that the structures are separate? */ - mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN); - if (mon) { - mon->isminion = 1; - EMIN(mon)->min_align = alignment; - EMIN(mon)->renegade = FALSE; - } + appropriate or necessary now that the structures are separate? */ + mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN); + if (mon) { + mon->isminion = 1; + EMIN(mon)->min_align = alignment; + EMIN(mon)->renegade = FALSE; + } } else { - mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS); + mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS); } if (mon) { - if (talk) { - pline_The("voice of %s booms:", align_gname(alignment)); - verbalize("Thou shalt pay for thine indiscretion!"); - if (!Blind) - pline("%s appears before you.", Amonnam(mon)); - mon->mstrategy &= ~STRAT_APPEARMSG; - } - mon->mpeaceful = FALSE; - /* don't call set_malign(); player was naughty */ + if (talk) { + pline_The("voice of %s booms:", align_gname(alignment)); + verbalize("Thou shalt pay for thine indiscretion!"); + if (!Blind) + pline("%s appears before you.", Amonnam(mon)); + mon->mstrategy &= ~STRAT_APPEARMSG; + } + mon->mpeaceful = FALSE; + /* don't call set_malign(); player was naughty */ } } -#define Athome (Inhell && (mtmp->cham == NON_PM)) +#define Athome (Inhell && (mtmp->cham == NON_PM)) -int -demon_talk(mtmp) /* returns 1 if it won't attack. */ +int demon_talk(mtmp) /* returns 1 if it won't attack. */ register struct monst *mtmp; { - long cash, demand, offer; + long cash, demand, offer; - if (uwep && uwep->oartifact == ART_EXCALIBUR) { - pline("%s looks very angry.", Amonnam(mtmp)); - mtmp->mpeaceful = mtmp->mtame = 0; - set_malign(mtmp); - newsym(mtmp->mx, mtmp->my); - return 0; - } + if (uwep && uwep->oartifact == ART_EXCALIBUR) { + pline("%s looks very angry.", Amonnam(mtmp)); + mtmp->mpeaceful = mtmp->mtame = 0; + set_malign(mtmp); + newsym(mtmp->mx, mtmp->my); + return 0; + } - if (is_fainted()) { - reset_faint(); /* if fainted - wake up */ - } else { - stop_occupation(); - if (multi > 0) { nomul(0); unmul((char *)0); } - } + if (is_fainted()) { + reset_faint(); /* if fainted - wake up */ + } else { + stop_occupation(); + if (multi > 0) { + nomul(0); + unmul((char *) 0); + } + } - /* Slight advantage given. */ - if (is_dprince(mtmp->data) && mtmp->minvis) { - boolean wasunseen = !canspotmon(mtmp); + /* Slight advantage given. */ + if (is_dprince(mtmp->data) && mtmp->minvis) { + boolean wasunseen = !canspotmon(mtmp); - mtmp->minvis = mtmp->perminvis = 0; - if (wasunseen && canspotmon(mtmp)) { - pline("%s appears before you.", Amonnam(mtmp)); - mtmp->mstrategy &= ~STRAT_APPEARMSG; - } - newsym(mtmp->mx,mtmp->my); - } - if (youmonst.data->mlet == S_DEMON) { /* Won't blackmail their own. */ - pline("%s says, \"Good hunting, %s.\"", - Amonnam(mtmp), flags.female ? "Sister" : "Brother"); - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - return(1); - } - cash = money_cnt(invent); - demand = (cash * (rnd(80) + 20 * Athome)) / - (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp)))); + mtmp->minvis = mtmp->perminvis = 0; + if (wasunseen && canspotmon(mtmp)) { + pline("%s appears before you.", Amonnam(mtmp)); + mtmp->mstrategy &= ~STRAT_APPEARMSG; + } + newsym(mtmp->mx, mtmp->my); + } + if (youmonst.data->mlet == S_DEMON) { /* Won't blackmail their own. */ + pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp), + flags.female ? "Sister" : "Brother"); + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + return (1); + } + cash = money_cnt(invent); + demand = + (cash * (rnd(80) + 20 * Athome)) + / (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp)))); - if (!demand || multi < 0) { /* you have no gold or can't move */ - mtmp->mpeaceful = 0; - set_malign(mtmp); - return 0; - } else { - /* make sure that the demand is unmeetable if the monster - has the Amulet, preventing monster from being satisified - and removed from the game (along with said Amulet...) */ - if (mon_has_amulet(mtmp)) - demand = cash + (long)rn1(1000,40); + if (!demand || multi < 0) { /* you have no gold or can't move */ + mtmp->mpeaceful = 0; + set_malign(mtmp); + return 0; + } else { + /* make sure that the demand is unmeetable if the monster + has the Amulet, preventing monster from being satisified + and removed from the game (along with said Amulet...) */ + if (mon_has_amulet(mtmp)) + demand = cash + (long) rn1(1000, 40); - pline("%s demands %ld %s for safe passage.", - Amonnam(mtmp), demand, currency(demand)); + pline("%s demands %ld %s for safe passage.", Amonnam(mtmp), demand, + currency(demand)); - if ((offer = bribe(mtmp)) >= demand) { - pline("%s vanishes, laughing about cowardly mortals.", - Amonnam(mtmp)); - } else if (offer > 0L && (long)rnd(40) > (demand - offer)) { - pline("%s scowls at you menacingly, then vanishes.", - Amonnam(mtmp)); - } else { - pline("%s gets angry...", Amonnam(mtmp)); - mtmp->mpeaceful = 0; - set_malign(mtmp); - return 0; - } - } - mongone(mtmp); - return(1); + if ((offer = bribe(mtmp)) >= demand) { + pline("%s vanishes, laughing about cowardly mortals.", + Amonnam(mtmp)); + } else if (offer > 0L && (long) rnd(40) > (demand - offer)) { + pline("%s scowls at you menacingly, then vanishes.", + Amonnam(mtmp)); + } else { + pline("%s gets angry...", Amonnam(mtmp)); + mtmp->mpeaceful = 0; + set_malign(mtmp); + return 0; + } + } + mongone(mtmp); + return (1); } long bribe(mtmp) struct monst *mtmp; { - char buf[BUFSZ]; - long offer; - long umoney = money_cnt(invent); + char buf[BUFSZ]; + long offer; + long umoney = money_cnt(invent); - getlin("How much will you offer?", buf); - if (sscanf(buf, "%ld", &offer) != 1) offer = 0L; + getlin("How much will you offer?", buf); + if (sscanf(buf, "%ld", &offer) != 1) + offer = 0L; - /*Michael Paddon -- fix for negative offer to monster*/ - /*JAR880815 - */ - if (offer < 0L) { - You("try to shortchange %s, but fumble.", - mon_nam(mtmp)); - return 0L; - } else if (offer == 0L) { - You("refuse."); - return 0L; - } else if (offer >= umoney) { - You("give %s all your gold.", mon_nam(mtmp)); - offer = umoney; - } else { - You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer)); - } - (void) money2mon(mtmp, offer); - context.botl = 1; - return(offer); + /*Michael Paddon -- fix for negative offer to monster*/ + /*JAR880815 - */ + if (offer < 0L) { + You("try to shortchange %s, but fumble.", mon_nam(mtmp)); + return 0L; + } else if (offer == 0L) { + You("refuse."); + return 0L; + } else if (offer >= umoney) { + You("give %s all your gold.", mon_nam(mtmp)); + offer = umoney; + } else { + You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer)); + } + (void) money2mon(mtmp, offer); + context.botl = 1; + return (offer); } int dprince(atyp) aligntyp atyp; { - int tryct, pm; + int tryct, pm; - for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) { - pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS); - if (!(mvitals[pm].mvflags & G_GONE) && - (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp))) - return(pm); - } - return(dlord(atyp)); /* approximate */ + for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) { + pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS); + if (!(mvitals[pm].mvflags & G_GONE) + && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp))) + return (pm); + } + return (dlord(atyp)); /* approximate */ } int dlord(atyp) aligntyp atyp; { - int tryct, pm; + int tryct, pm; - for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) { - pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX); - if (!(mvitals[pm].mvflags & G_GONE) && - (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp))) - return(pm); - } - return(ndemon(atyp)); /* approximate */ + for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) { + pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX); + if (!(mvitals[pm].mvflags & G_GONE) + && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp))) + return (pm); + } + return (ndemon(atyp)); /* approximate */ } /* create lawful (good) lord */ int llord() { - if (!(mvitals[PM_ARCHON].mvflags & G_GONE)) - return(PM_ARCHON); + if (!(mvitals[PM_ARCHON].mvflags & G_GONE)) + return (PM_ARCHON); - return(lminion()); /* approximate */ + return (lminion()); /* approximate */ } int lminion() { - int tryct; - struct permonst *ptr; + int tryct; + struct permonst *ptr; - for (tryct = 0; tryct < 20; tryct++) { - ptr = mkclass(S_ANGEL,0); - if (ptr && !is_lord(ptr)) - return(monsndx(ptr)); - } + for (tryct = 0; tryct < 20; tryct++) { + ptr = mkclass(S_ANGEL, 0); + if (ptr && !is_lord(ptr)) + return (monsndx(ptr)); + } - return NON_PM; + return NON_PM; } int ndemon(atyp) aligntyp atyp; { - int tryct; - struct permonst *ptr; + int tryct; + struct permonst *ptr; - for (tryct = 0; tryct < 20; tryct++) { - ptr = mkclass(S_DEMON, 0); - if (ptr && is_ndemon(ptr) && - (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp))) - return(monsndx(ptr)); - } + for (tryct = 0; tryct < 20; tryct++) { + ptr = mkclass(S_DEMON, 0); + if (ptr && is_ndemon(ptr) + && (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp))) + return (monsndx(ptr)); + } - return NON_PM; + return NON_PM; } /* guardian angel has been affected by conflict so is abandoning hero */ void lose_guardian_angel(mon) -struct monst *mon; /* if null, angel hasn't been created yet */ +struct monst *mon; /* if null, angel hasn't been created yet */ { coord mm; int i; if (mon) { - if (canspotmon(mon)) { - if (!Deaf) { - pline("%s rebukes you, saying:", Monnam(mon)); - verbalize("Since you desire conflict, have some more!"); - } else { - pline("%s vanishes!", Monnam(mon)); - } - } - mongone(mon); + if (canspotmon(mon)) { + if (!Deaf) { + pline("%s rebukes you, saying:", Monnam(mon)); + verbalize("Since you desire conflict, have some more!"); + } else { + pline("%s vanishes!", Monnam(mon)); + } + } + mongone(mon); } /* create 2 to 4 hostile angels to replace the lost guardian */ - for (i = rn1(3,2); i > 0; --i) { - mm.x = u.ux; - mm.y = u.uy; - if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])) - (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type, - mm.x, mm.y, FALSE); + for (i = rn1(3, 2); i > 0; --i) { + mm.x = u.ux; + mm.y = u.uy; + if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])) + (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y, + FALSE); } } @@ -411,47 +424,49 @@ gain_guardian_angel() struct obj *otmp; coord mm; - Hear_again(); /* attempt to cure any deafness now (divine - message will be heard even if that fails) */ + Hear_again(); /* attempt to cure any deafness now (divine + message will be heard even if that fails) */ if (Conflict) { - pline("A voice booms:"); - verbalize("Thy desire for conflict shall be fulfilled!"); - /* send in some hostile angels instead */ - lose_guardian_angel((struct monst *)0); - } else if (u.ualign.record > 8) { /* fervent */ - pline("A voice whispers:"); - verbalize("Thou hast been worthy of me!"); - mm.x = u.ux; - mm.y = u.uy; - if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]) && - (mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type, - mm.x, mm.y, TRUE)) != 0) { - mtmp->mstrategy &= ~STRAT_APPEARMSG; - if (!Blind) - pline("An angel appears near you."); - else - You_feel("the presence of a friendly angel near you."); - /* guardian angel -- the one case mtame doesn't - * imply an edog structure, so we don't want to - * call tamedog(). - */ - mtmp->mtame = 10; - /* make him strong enough vs. endgame foes */ - mtmp->m_lev = rn1(8,15); - mtmp->mhp = mtmp->mhpmax = d((int)mtmp->m_lev,10) + 30 + rnd(30); - if ((otmp = select_hwep(mtmp)) == 0) { - otmp = mksobj(SILVER_SABER, FALSE, FALSE); - if (mpickobj(mtmp, otmp)) - panic("merged weapon?"); - } - bless(otmp); - if (otmp->spe < 4) otmp->spe += rnd(4); - if ((otmp = which_armor(mtmp, W_ARMS)) == 0 || - otmp->otyp != SHIELD_OF_REFLECTION) { - (void) mongets(mtmp, AMULET_OF_REFLECTION); - m_dowear(mtmp, TRUE); - } - } + pline("A voice booms:"); + verbalize("Thy desire for conflict shall be fulfilled!"); + /* send in some hostile angels instead */ + lose_guardian_angel((struct monst *) 0); + } else if (u.ualign.record > 8) { /* fervent */ + pline("A voice whispers:"); + verbalize("Thou hast been worthy of me!"); + mm.x = u.ux; + mm.y = u.uy; + if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]) + && (mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y, + TRUE)) != 0) { + mtmp->mstrategy &= ~STRAT_APPEARMSG; + if (!Blind) + pline("An angel appears near you."); + else + You_feel("the presence of a friendly angel near you."); + /* guardian angel -- the one case mtame doesn't + * imply an edog structure, so we don't want to + * call tamedog(). + */ + mtmp->mtame = 10; + /* make him strong enough vs. endgame foes */ + mtmp->m_lev = rn1(8, 15); + mtmp->mhp = mtmp->mhpmax = + d((int) mtmp->m_lev, 10) + 30 + rnd(30); + if ((otmp = select_hwep(mtmp)) == 0) { + otmp = mksobj(SILVER_SABER, FALSE, FALSE); + if (mpickobj(mtmp, otmp)) + panic("merged weapon?"); + } + bless(otmp); + if (otmp->spe < 4) + otmp->spe += rnd(4); + if ((otmp = which_armor(mtmp, W_ARMS)) == 0 + || otmp->otyp != SHIELD_OF_REFLECTION) { + (void) mongets(mtmp, AMULET_OF_REFLECTION); + m_dowear(mtmp, TRUE); + } + } } } diff --git a/src/mklev.c b/src/mklev.c index 1ecf46f67..02d90200e 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mklev.c $NHDT-Date: 1430172946 2015/04/27 22:15:46 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.38 $ */ +/* NetHack 3.6 mklev.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,173 +8,182 @@ /* croom->lx etc are schar (width <= int), so % arith ensures that */ /* conversion of result to int is reasonable */ - -STATIC_DCL void FDECL(mkfount,(int,struct mkroom *)); -STATIC_DCL void FDECL(mksink,(struct mkroom *)); -STATIC_DCL void FDECL(mkaltar,(struct mkroom *)); -STATIC_DCL void FDECL(mkgrave,(struct mkroom *)); +STATIC_DCL void FDECL(mkfount, (int, struct mkroom *)); +STATIC_DCL void FDECL(mksink, (struct mkroom *)); +STATIC_DCL void FDECL(mkaltar, (struct mkroom *)); +STATIC_DCL void FDECL(mkgrave, (struct mkroom *)); STATIC_DCL void NDECL(makevtele); STATIC_DCL void NDECL(clear_level_structures); STATIC_DCL void NDECL(makelevel); -STATIC_DCL boolean FDECL(bydoor,(XCHAR_P,XCHAR_P)); +STATIC_DCL boolean FDECL(bydoor, (XCHAR_P, XCHAR_P)); STATIC_DCL struct mkroom *FDECL(find_branch_room, (coord *)); STATIC_DCL struct mkroom *FDECL(pos_to_room, (XCHAR_P, XCHAR_P)); -STATIC_DCL boolean FDECL(place_niche,(struct mkroom *,int*,int*,int*)); -STATIC_DCL void FDECL(makeniche,(int)); +STATIC_DCL boolean FDECL(place_niche, (struct mkroom *, int *, int *, int *)); +STATIC_DCL void FDECL(makeniche, (int)); STATIC_DCL void NDECL(make_niches); -STATIC_PTR int FDECL( CFDECLSPEC do_comp,(const genericptr,const genericptr)); +STATIC_PTR int FDECL(CFDECLSPEC do_comp, + (const genericptr, const genericptr)); -STATIC_DCL void FDECL(dosdoor,(XCHAR_P,XCHAR_P,struct mkroom *,int)); -STATIC_DCL void FDECL(join,(int,int,BOOLEAN_P)); -STATIC_DCL void FDECL(do_room_or_subroom, (struct mkroom *,int,int,int,int, - BOOLEAN_P,SCHAR_P,BOOLEAN_P,BOOLEAN_P)); +STATIC_DCL void FDECL(dosdoor, (XCHAR_P, XCHAR_P, struct mkroom *, int)); +STATIC_DCL void FDECL(join, (int, int, BOOLEAN_P)); +STATIC_DCL void FDECL(do_room_or_subroom, + (struct mkroom *, int, int, int, int, BOOLEAN_P, + SCHAR_P, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL void NDECL(makerooms); -STATIC_DCL void FDECL(finddpos,(coord *,XCHAR_P,XCHAR_P,XCHAR_P,XCHAR_P)); -STATIC_DCL void FDECL(mkinvpos, (XCHAR_P,XCHAR_P,int)); -STATIC_DCL void FDECL(mk_knox_portal, (XCHAR_P,XCHAR_P)); +STATIC_DCL void FDECL(finddpos, + (coord *, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P)); +STATIC_DCL void FDECL(mkinvpos, (XCHAR_P, XCHAR_P, int)); +STATIC_DCL void FDECL(mk_knox_portal, (XCHAR_P, XCHAR_P)); -#define create_vault() create_room(-1, -1, 2, 2, -1, -1, VAULT, TRUE) -#define init_vault() vault_x = -1 -#define do_vault() (vault_x != -1) -static xchar vault_x, vault_y; -boolean goldseen; /* XXX do we need this variable? It does nothing. */ -static boolean made_branch; /* used only during level creation */ +#define create_vault() create_room(-1, -1, 2, 2, -1, -1, VAULT, TRUE) +#define init_vault() vault_x = -1 +#define do_vault() (vault_x != -1) +static xchar vault_x, vault_y; +boolean goldseen; /* XXX do we need this variable? It does nothing. */ +static boolean made_branch; /* used only during level creation */ /* Args must be (const genericptr) so that qsort will always be happy. */ STATIC_PTR int CFDECLSPEC -do_comp(vx,vy) +do_comp(vx, vy) const genericptr vx; const genericptr vy; { #ifdef LINT -/* lint complains about possible pointer alignment problems, but we know - that vx and vy are always properly aligned. Hence, the following - bogus definition: -*/ - return (vx == vy) ? 0 : -1; + /* lint complains about possible pointer alignment problems, but we know + that vx and vy are always properly aligned. Hence, the following + bogus definition: + */ + return (vx == vy) ? 0 : -1; #else - register const struct mkroom *x, *y; + register const struct mkroom *x, *y; - x = (const struct mkroom *)vx; - y = (const struct mkroom *)vy; - if(x->lx < y->lx) return(-1); - return(x->lx > y->lx); + x = (const struct mkroom *) vx; + y = (const struct mkroom *) vy; + if (x->lx < y->lx) + return (-1); + return (x->lx > y->lx); #endif /* LINT */ } STATIC_OVL void -finddpos(cc, xl,yl,xh,yh) +finddpos(cc, xl, yl, xh, yh) coord *cc; -xchar xl,yl,xh,yh; +xchar xl, yl, xh, yh; { - register xchar x, y; + register xchar x, y; - x = rn1(xh - xl + 1, xl); - y = rn1(yh - yl + 1, yl); - if(okdoor(x, y)) - goto gotit; + x = rn1(xh - xl + 1, xl); + y = rn1(yh - yl + 1, yl); + if (okdoor(x, y)) + goto gotit; - for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) - if(okdoor(x, y)) - goto gotit; + for (x = xl; x <= xh; x++) + for (y = yl; y <= yh; y++) + if (okdoor(x, y)) + goto gotit; - for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) - if(IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR) - goto gotit; - /* cannot find something reasonable -- strange */ - x = xl; - y = yh; + for (x = xl; x <= xh; x++) + for (y = yl; y <= yh; y++) + if (IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR) + goto gotit; + /* cannot find something reasonable -- strange */ + x = xl; + y = yh; gotit: - cc->x = x; - cc->y = y; - return; + cc->x = x; + cc->y = y; + return; } void sort_rooms() { #if defined(SYSV) || defined(DGUX) - qsort((genericptr_t) rooms, (unsigned)nroom, sizeof(struct mkroom), do_comp); + qsort((genericptr_t) rooms, (unsigned) nroom, sizeof(struct mkroom), + do_comp); #else - qsort((genericptr_t) rooms, nroom, sizeof(struct mkroom), do_comp); + qsort((genericptr_t) rooms, nroom, sizeof(struct mkroom), do_comp); #endif } STATIC_OVL void do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special, is_room) - register struct mkroom *croom; - int lowx, lowy; - register int hix, hiy; - boolean lit; - schar rtype; - boolean special; - boolean is_room; +register struct mkroom *croom; +int lowx, lowy; +register int hix, hiy; +boolean lit; +schar rtype; +boolean special; +boolean is_room; { - register int x, y; - struct rm *lev; + register int x, y; + struct rm *lev; - /* locations might bump level edges in wall-less rooms */ - /* add/subtract 1 to allow for edge locations */ - if(!lowx) lowx++; - if(!lowy) lowy++; - if(hix >= COLNO-1) hix = COLNO-2; - if(hiy >= ROWNO-1) hiy = ROWNO-2; + /* locations might bump level edges in wall-less rooms */ + /* add/subtract 1 to allow for edge locations */ + if (!lowx) + lowx++; + if (!lowy) + lowy++; + if (hix >= COLNO - 1) + hix = COLNO - 2; + if (hiy >= ROWNO - 1) + hiy = ROWNO - 2; - if(lit) { - for(x = lowx-1; x <= hix+1; x++) { - lev = &levl[x][max(lowy-1,0)]; - for(y = lowy-1; y <= hiy+1; y++) - lev++->lit = 1; - } - croom->rlit = 1; - } else - croom->rlit = 0; + if (lit) { + for (x = lowx - 1; x <= hix + 1; x++) { + lev = &levl[x][max(lowy - 1, 0)]; + for (y = lowy - 1; y <= hiy + 1; y++) + lev++->lit = 1; + } + croom->rlit = 1; + } else + croom->rlit = 0; - croom->lx = lowx; - croom->hx = hix; - croom->ly = lowy; - croom->hy = hiy; - croom->rtype = rtype; - croom->doorct = 0; - /* if we're not making a vault, doorindex will still be 0 - * if we are, we'll have problems adding niches to the previous room - * unless fdoor is at least doorindex - */ - croom->fdoor = doorindex; - croom->irregular = FALSE; + croom->lx = lowx; + croom->hx = hix; + croom->ly = lowy; + croom->hy = hiy; + croom->rtype = rtype; + croom->doorct = 0; + /* if we're not making a vault, doorindex will still be 0 + * if we are, we'll have problems adding niches to the previous room + * unless fdoor is at least doorindex + */ + croom->fdoor = doorindex; + croom->irregular = FALSE; - croom->nsubrooms = 0; - croom->sbrooms[0] = (struct mkroom *) 0; - if (!special) { - for(x = lowx-1; x <= hix+1; x++) - for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) { - levl[x][y].typ = HWALL; - levl[x][y].horizontal = 1; /* For open/secret doors. */ - } - for(x = lowx-1; x <= hix+1; x += (hix-lowx+2)) - for(y = lowy; y <= hiy; y++) { - levl[x][y].typ = VWALL; - levl[x][y].horizontal = 0; /* For open/secret doors. */ - } - for(x = lowx; x <= hix; x++) { - lev = &levl[x][lowy]; - for(y = lowy; y <= hiy; y++) - lev++->typ = ROOM; - } - if (is_room) { - levl[lowx-1][lowy-1].typ = TLCORNER; - levl[hix+1][lowy-1].typ = TRCORNER; - levl[lowx-1][hiy+1].typ = BLCORNER; - levl[hix+1][hiy+1].typ = BRCORNER; - } else { /* a subroom */ - wallification(lowx-1, lowy-1, hix+1, hiy+1); - } - } + croom->nsubrooms = 0; + croom->sbrooms[0] = (struct mkroom *) 0; + if (!special) { + for (x = lowx - 1; x <= hix + 1; x++) + for (y = lowy - 1; y <= hiy + 1; y += (hiy - lowy + 2)) { + levl[x][y].typ = HWALL; + levl[x][y].horizontal = 1; /* For open/secret doors. */ + } + for (x = lowx - 1; x <= hix + 1; x += (hix - lowx + 2)) + for (y = lowy; y <= hiy; y++) { + levl[x][y].typ = VWALL; + levl[x][y].horizontal = 0; /* For open/secret doors. */ + } + for (x = lowx; x <= hix; x++) { + lev = &levl[x][lowy]; + for (y = lowy; y <= hiy; y++) + lev++->typ = ROOM; + } + if (is_room) { + levl[lowx - 1][lowy - 1].typ = TLCORNER; + levl[hix + 1][lowy - 1].typ = TRCORNER; + levl[lowx - 1][hiy + 1].typ = BLCORNER; + levl[hix + 1][hiy + 1].typ = BRCORNER; + } else { /* a subroom */ + wallification(lowx - 1, lowy - 1, hix + 1, hiy + 1); + } + } } - void add_room(lowx, lowy, hix, hiy, lit, rtype, special) register int lowx, lowy, hix, hiy; @@ -182,14 +191,14 @@ boolean lit; schar rtype; boolean special; { - register struct mkroom *croom; + register struct mkroom *croom; - croom = &rooms[nroom]; - do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, - rtype, special, (boolean) TRUE); - croom++; - croom->hx = -1; - nroom++; + croom = &rooms[nroom]; + do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special, + (boolean) TRUE); + croom++; + croom->hx = -1; + nroom++; } void @@ -200,352 +209,365 @@ boolean lit; schar rtype; boolean special; { - register struct mkroom *croom; + register struct mkroom *croom; - croom = &subrooms[nsubroom]; - do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, - rtype, special, (boolean) FALSE); - proom->sbrooms[proom->nsubrooms++] = croom; - croom++; - croom->hx = -1; - nsubroom++; + croom = &subrooms[nsubroom]; + do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special, + (boolean) FALSE); + proom->sbrooms[proom->nsubrooms++] = croom; + croom++; + croom->hx = -1; + nsubroom++; } STATIC_OVL void makerooms() { - boolean tried_vault = FALSE; + boolean tried_vault = FALSE; - /* make rooms until satisfied */ - /* rnd_rect() will returns 0 if no more rects are available... */ - while(nroom < MAXNROFROOMS && rnd_rect()) { - if(nroom >= (MAXNROFROOMS/6) && rn2(2) && !tried_vault) { - tried_vault = TRUE; - if (create_vault()) { - vault_x = rooms[nroom].lx; - vault_y = rooms[nroom].ly; - rooms[nroom].hx = -1; - } - } else - if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1)) - return; - } - return; + /* make rooms until satisfied */ + /* rnd_rect() will returns 0 if no more rects are available... */ + while (nroom < MAXNROFROOMS && rnd_rect()) { + if (nroom >= (MAXNROFROOMS / 6) && rn2(2) && !tried_vault) { + tried_vault = TRUE; + if (create_vault()) { + vault_x = rooms[nroom].lx; + vault_y = rooms[nroom].ly; + rooms[nroom].hx = -1; + } + } else if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1)) + return; + } + return; } STATIC_OVL void -join(a,b,nxcor) +join(a, b, nxcor) register int a, b; boolean nxcor; { - coord cc,tt, org, dest; - register xchar tx, ty, xx, yy; - register struct mkroom *croom, *troom; - register int dx, dy; + coord cc, tt, org, dest; + register xchar tx, ty, xx, yy; + register struct mkroom *croom, *troom; + register int dx, dy; - croom = &rooms[a]; - troom = &rooms[b]; + croom = &rooms[a]; + troom = &rooms[b]; - /* find positions cc and tt for doors in croom and troom - and direction for a corridor between them */ + /* find positions cc and tt for doors in croom and troom + and direction for a corridor between them */ - if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return; - if(troom->lx > croom->hx) { - dx = 1; - dy = 0; - xx = croom->hx+1; - tx = troom->lx-1; - finddpos(&cc, xx, croom->ly, xx, croom->hy); - finddpos(&tt, tx, troom->ly, tx, troom->hy); - } else if(troom->hy < croom->ly) { - dy = -1; - dx = 0; - yy = croom->ly-1; - finddpos(&cc, croom->lx, yy, croom->hx, yy); - ty = troom->hy+1; - finddpos(&tt, troom->lx, ty, troom->hx, ty); - } else if(troom->hx < croom->lx) { - dx = -1; - dy = 0; - xx = croom->lx-1; - tx = troom->hx+1; - finddpos(&cc, xx, croom->ly, xx, croom->hy); - finddpos(&tt, tx, troom->ly, tx, troom->hy); - } else { - dy = 1; - dx = 0; - yy = croom->hy+1; - ty = troom->ly-1; - finddpos(&cc, croom->lx, yy, croom->hx, yy); - finddpos(&tt, troom->lx, ty, troom->hx, ty); - } - xx = cc.x; - yy = cc.y; - tx = tt.x - dx; - ty = tt.y - dy; - if(nxcor && levl[xx+dx][yy+dy].typ) - return; - if (okdoor(xx,yy) || !nxcor) - dodoor(xx,yy,croom); + if (troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) + return; + if (troom->lx > croom->hx) { + dx = 1; + dy = 0; + xx = croom->hx + 1; + tx = troom->lx - 1; + finddpos(&cc, xx, croom->ly, xx, croom->hy); + finddpos(&tt, tx, troom->ly, tx, troom->hy); + } else if (troom->hy < croom->ly) { + dy = -1; + dx = 0; + yy = croom->ly - 1; + finddpos(&cc, croom->lx, yy, croom->hx, yy); + ty = troom->hy + 1; + finddpos(&tt, troom->lx, ty, troom->hx, ty); + } else if (troom->hx < croom->lx) { + dx = -1; + dy = 0; + xx = croom->lx - 1; + tx = troom->hx + 1; + finddpos(&cc, xx, croom->ly, xx, croom->hy); + finddpos(&tt, tx, troom->ly, tx, troom->hy); + } else { + dy = 1; + dx = 0; + yy = croom->hy + 1; + ty = troom->ly - 1; + finddpos(&cc, croom->lx, yy, croom->hx, yy); + finddpos(&tt, troom->lx, ty, troom->hx, ty); + } + xx = cc.x; + yy = cc.y; + tx = tt.x - dx; + ty = tt.y - dy; + if (nxcor && levl[xx + dx][yy + dy].typ) + return; + if (okdoor(xx, yy) || !nxcor) + dodoor(xx, yy, croom); - org.x = xx+dx; org.y = yy+dy; - dest.x = tx; dest.y = ty; + org.x = xx + dx; + org.y = yy + dy; + dest.x = tx; + dest.y = ty; - if (!dig_corridor(&org, &dest, nxcor, - level.flags.arboreal ? ROOM : CORR, STONE)) - return; + if (!dig_corridor(&org, &dest, nxcor, level.flags.arboreal ? ROOM : CORR, + STONE)) + return; - /* we succeeded in digging the corridor */ - if (okdoor(tt.x, tt.y) || !nxcor) - dodoor(tt.x, tt.y, troom); + /* we succeeded in digging the corridor */ + if (okdoor(tt.x, tt.y) || !nxcor) + dodoor(tt.x, tt.y, troom); - if(smeq[a] < smeq[b]) - smeq[b] = smeq[a]; - else - smeq[a] = smeq[b]; + if (smeq[a] < smeq[b]) + smeq[b] = smeq[a]; + else + smeq[a] = smeq[b]; } void makecorridors() { - int a, b, i; - boolean any = TRUE; + int a, b, i; + boolean any = TRUE; - for(a = 0; a < nroom-1; a++) { - join(a, a+1, FALSE); - if(!rn2(50)) break; /* allow some randomness */ - } - for(a = 0; a < nroom-2; a++) - if(smeq[a] != smeq[a+2]) - join(a, a+2, FALSE); - for(a = 0; any && a < nroom; a++) { - any = FALSE; - for(b = 0; b < nroom; b++) - if(smeq[a] != smeq[b]) { - join(a, b, FALSE); - any = TRUE; - } - } - if(nroom > 2) - for(i = rn2(nroom) + 4; i; i--) { - a = rn2(nroom); - b = rn2(nroom-2); - if(b >= a) b += 2; - join(a, b, TRUE); - } + for (a = 0; a < nroom - 1; a++) { + join(a, a + 1, FALSE); + if (!rn2(50)) + break; /* allow some randomness */ + } + for (a = 0; a < nroom - 2; a++) + if (smeq[a] != smeq[a + 2]) + join(a, a + 2, FALSE); + for (a = 0; any && a < nroom; a++) { + any = FALSE; + for (b = 0; b < nroom; b++) + if (smeq[a] != smeq[b]) { + join(a, b, FALSE); + any = TRUE; + } + } + if (nroom > 2) + for (i = rn2(nroom) + 4; i; i--) { + a = rn2(nroom); + b = rn2(nroom - 2); + if (b >= a) + b += 2; + join(a, b, TRUE); + } } void -add_door(x,y,aroom) +add_door(x, y, aroom) register int x, y; register struct mkroom *aroom; { - register struct mkroom *broom; - register int tmp; - int i; + register struct mkroom *broom; + register int tmp; + int i; - if (aroom->doorct == 0) - aroom->fdoor = doorindex; + if (aroom->doorct == 0) + aroom->fdoor = doorindex; - aroom->doorct++; + aroom->doorct++; - for (tmp = doorindex; tmp > aroom->fdoor; tmp--) - doors[tmp] = doors[tmp - 1]; + for (tmp = doorindex; tmp > aroom->fdoor; tmp--) + doors[tmp] = doors[tmp - 1]; - for (i = 0; i < nroom; i++) { - broom = &rooms[i]; - if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor) - broom->fdoor++; - } - for (i = 0; i < nsubroom; i++) { - broom = &subrooms[i]; - if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor) - broom->fdoor++; - } + for (i = 0; i < nroom; i++) { + broom = &rooms[i]; + if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor) + broom->fdoor++; + } + for (i = 0; i < nsubroom; i++) { + broom = &subrooms[i]; + if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor) + broom->fdoor++; + } - doorindex++; - doors[aroom->fdoor].x = x; - doors[aroom->fdoor].y = y; + doorindex++; + doors[aroom->fdoor].x = x; + doors[aroom->fdoor].y = y; } STATIC_OVL void -dosdoor(x,y,aroom,type) +dosdoor(x, y, aroom, type) register xchar x, y; register struct mkroom *aroom; register int type; { - boolean shdoor = ((*in_rooms(x, y, SHOPBASE))? TRUE : FALSE); + boolean shdoor = ((*in_rooms(x, y, SHOPBASE)) ? TRUE : FALSE); - if(!IS_WALL(levl[x][y].typ)) /* avoid SDOORs on already made doors */ - type = DOOR; - levl[x][y].typ = type; - if(type == DOOR) { - if(!rn2(3)) { /* is it a locked door, closed, or a doorway? */ - if(!rn2(5)) - levl[x][y].doormask = D_ISOPEN; - else if(!rn2(6)) - levl[x][y].doormask = D_LOCKED; - else - levl[x][y].doormask = D_CLOSED; + if (!IS_WALL(levl[x][y].typ)) /* avoid SDOORs on already made doors */ + type = DOOR; + levl[x][y].typ = type; + if (type == DOOR) { + if (!rn2(3)) { /* is it a locked door, closed, or a doorway? */ + if (!rn2(5)) + levl[x][y].doormask = D_ISOPEN; + else if (!rn2(6)) + levl[x][y].doormask = D_LOCKED; + else + levl[x][y].doormask = D_CLOSED; - if (levl[x][y].doormask != D_ISOPEN && !shdoor && - level_difficulty() >= 5 && !rn2(25)) - levl[x][y].doormask |= D_TRAPPED; - } else + if (levl[x][y].doormask != D_ISOPEN && !shdoor + && level_difficulty() >= 5 && !rn2(25)) + levl[x][y].doormask |= D_TRAPPED; + } else #ifdef STUPID - if (shdoor) - levl[x][y].doormask = D_ISOPEN; - else - levl[x][y].doormask = D_NODOOR; + if (shdoor) + levl[x][y].doormask = D_ISOPEN; + else + levl[x][y].doormask = D_NODOOR; #else - levl[x][y].doormask = (shdoor ? D_ISOPEN : D_NODOOR); + levl[x][y].doormask = (shdoor ? D_ISOPEN : D_NODOOR); #endif - /* also done in roguecorr(); doing it here first prevents - making mimics in place of trapped doors on rogue level */ - if (Is_rogue_level(&u.uz)) levl[x][y].doormask = D_NODOOR; + /* also done in roguecorr(); doing it here first prevents + making mimics in place of trapped doors on rogue level */ + if (Is_rogue_level(&u.uz)) + levl[x][y].doormask = D_NODOOR; - if(levl[x][y].doormask & D_TRAPPED) { - struct monst *mtmp; + if (levl[x][y].doormask & D_TRAPPED) { + struct monst *mtmp; - if (level_difficulty() >= 9 && !rn2(5) && - !((mvitals[PM_SMALL_MIMIC].mvflags & G_GONE) && - (mvitals[PM_LARGE_MIMIC].mvflags & G_GONE) && - (mvitals[PM_GIANT_MIMIC].mvflags & G_GONE))) { - /* make a mimic instead */ - levl[x][y].doormask = D_NODOOR; - mtmp = makemon(mkclass(S_MIMIC,0), x, y, NO_MM_FLAGS); - if (mtmp) - set_mimic_sym(mtmp); - } - } - /* newsym(x,y); */ - } else { /* SDOOR */ - if(shdoor || !rn2(5)) levl[x][y].doormask = D_LOCKED; - else levl[x][y].doormask = D_CLOSED; + if (level_difficulty() >= 9 && !rn2(5) + && !((mvitals[PM_SMALL_MIMIC].mvflags & G_GONE) + && (mvitals[PM_LARGE_MIMIC].mvflags & G_GONE) + && (mvitals[PM_GIANT_MIMIC].mvflags & G_GONE))) { + /* make a mimic instead */ + levl[x][y].doormask = D_NODOOR; + mtmp = makemon(mkclass(S_MIMIC, 0), x, y, NO_MM_FLAGS); + if (mtmp) + set_mimic_sym(mtmp); + } + } + /* newsym(x,y); */ + } else { /* SDOOR */ + if (shdoor || !rn2(5)) + levl[x][y].doormask = D_LOCKED; + else + levl[x][y].doormask = D_CLOSED; - if(!shdoor && level_difficulty() >= 4 && !rn2(20)) - levl[x][y].doormask |= D_TRAPPED; - } + if (!shdoor && level_difficulty() >= 4 && !rn2(20)) + levl[x][y].doormask |= D_TRAPPED; + } - add_door(x,y,aroom); + add_door(x, y, aroom); } STATIC_OVL boolean -place_niche(aroom,dy,xx,yy) +place_niche(aroom, dy, xx, yy) register struct mkroom *aroom; int *dy, *xx, *yy; { - coord dd; + coord dd; - if(rn2(2)) { - *dy = 1; - finddpos(&dd, aroom->lx, aroom->hy+1, aroom->hx, aroom->hy+1); - } else { - *dy = -1; - finddpos(&dd, aroom->lx, aroom->ly-1, aroom->hx, aroom->ly-1); - } - *xx = dd.x; - *yy = dd.y; - return((boolean)((isok(*xx,*yy+*dy) && levl[*xx][*yy+*dy].typ == STONE) - && (isok(*xx,*yy-*dy) && !IS_POOL(levl[*xx][*yy-*dy].typ) - && !IS_FURNITURE(levl[*xx][*yy-*dy].typ)))); + if (rn2(2)) { + *dy = 1; + finddpos(&dd, aroom->lx, aroom->hy + 1, aroom->hx, aroom->hy + 1); + } else { + *dy = -1; + finddpos(&dd, aroom->lx, aroom->ly - 1, aroom->hx, aroom->ly - 1); + } + *xx = dd.x; + *yy = dd.y; + return ((boolean)( + (isok(*xx, *yy + *dy) && levl[*xx][*yy + *dy].typ == STONE) + && (isok(*xx, *yy - *dy) && !IS_POOL(levl[*xx][*yy - *dy].typ) + && !IS_FURNITURE(levl[*xx][*yy - *dy].typ)))); } /* there should be one of these per trap, in the same order as trap.h */ static NEARDATA const char *trap_engravings[TRAPNUM] = { - (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0, (char *)0, (char *)0, (char *)0, - /* 14..16: trap door, teleport, level-teleport */ - "Vlad was here", "ad aerarium", "ad aerarium", - (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0, + (char *) 0, (char *) 0, (char *) 0, (char *) 0, (char *) 0, + (char *) 0, (char *) 0, (char *) 0, (char *) 0, (char *) 0, + (char *) 0, (char *) 0, (char *) 0, (char *) 0, + /* 14..16: trap door, teleport, level-teleport */ + "Vlad was here", "ad aerarium", "ad aerarium", (char *) 0, (char *) 0, + (char *) 0, (char *) 0, (char *) 0, (char *) 0, }; STATIC_OVL void makeniche(trap_type) int trap_type; { - register struct mkroom *aroom; - register struct rm *rm; - register int vct = 8; - int dy, xx, yy; - register struct trap *ttmp; + register struct mkroom *aroom; + register struct rm *rm; + register int vct = 8; + int dy, xx, yy; + register struct trap *ttmp; - if(doorindex < DOORMAX) - while(vct--) { - aroom = &rooms[rn2(nroom)]; - if(aroom->rtype != OROOM) continue; /* not an ordinary room */ - if(aroom->doorct == 1 && rn2(5)) continue; - if(!place_niche(aroom,&dy,&xx,&yy)) continue; + if (doorindex < DOORMAX) + while (vct--) { + aroom = &rooms[rn2(nroom)]; + if (aroom->rtype != OROOM) + continue; /* not an ordinary room */ + if (aroom->doorct == 1 && rn2(5)) + continue; + if (!place_niche(aroom, &dy, &xx, &yy)) + continue; - rm = &levl[xx][yy+dy]; - if(trap_type || !rn2(4)) { - - rm->typ = SCORR; - if(trap_type) { - if((trap_type == HOLE || trap_type == TRAPDOOR) - && !Can_fall_thru(&u.uz)) - trap_type = ROCKTRAP; - ttmp = maketrap(xx, yy+dy, trap_type); - if (ttmp) { - if (trap_type != ROCKTRAP) ttmp->once = 1; - if (trap_engravings[trap_type]) { - make_engr_at(xx, yy-dy, - trap_engravings[trap_type], 0L, DUST); - wipe_engr_at(xx, yy-dy, 5, FALSE); /* age it a little */ - } - } - } - dosdoor(xx, yy, aroom, SDOOR); - } else { - rm->typ = CORR; - if(rn2(7)) - dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR); - else { - /* inaccessible niches occasionally have iron bars */ + rm = &levl[xx][yy + dy]; + if (trap_type || !rn2(4)) { + rm->typ = SCORR; + if (trap_type) { + if ((trap_type == HOLE || trap_type == TRAPDOOR) + && !Can_fall_thru(&u.uz)) + trap_type = ROCKTRAP; + ttmp = maketrap(xx, yy + dy, trap_type); + if (ttmp) { + if (trap_type != ROCKTRAP) + ttmp->once = 1; + if (trap_engravings[trap_type]) { + make_engr_at(xx, yy - dy, + trap_engravings[trap_type], 0L, + DUST); + wipe_engr_at(xx, yy - dy, 5, + FALSE); /* age it a little */ + } + } + } + dosdoor(xx, yy, aroom, SDOOR); + } else { + rm->typ = CORR; + if (rn2(7)) + dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR); + else { + /* inaccessible niches occasionally have iron bars */ if (!rn2(5) && IS_WALL(levl[xx][yy].typ)) { levl[xx][yy].typ = IRONBARS; if (rn2(3)) - (void) mkcorpstat(CORPSE, - (struct monst *)0, - mkclass(S_HUMAN, 0), - xx, yy+dy, TRUE); + (void) mkcorpstat(CORPSE, (struct monst *) 0, + mkclass(S_HUMAN, 0), xx, + yy + dy, TRUE); } - if (!level.flags.noteleport) - (void) mksobj_at(SCR_TELEPORTATION, - xx, yy+dy, TRUE, FALSE); - if (!rn2(3)) (void) mkobj_at(0, xx, yy+dy, TRUE); - } - } - return; - } + if (!level.flags.noteleport) + (void) mksobj_at(SCR_TELEPORTATION, xx, yy + dy, TRUE, + FALSE); + if (!rn2(3)) + (void) mkobj_at(0, xx, yy + dy, TRUE); + } + } + return; + } } STATIC_OVL void make_niches() { - register int ct = rnd((nroom>>1) + 1), dep = depth(&u.uz); + register int ct = rnd((nroom >> 1) + 1), dep = depth(&u.uz); - boolean ltptr = (!level.flags.noteleport && dep > 15), - vamp = (dep > 5 && dep < 25); + boolean ltptr = (!level.flags.noteleport && dep > 15), + vamp = (dep > 5 && dep < 25); - while(ct--) { - if (ltptr && !rn2(6)) { - ltptr = FALSE; - makeniche(LEVEL_TELEP); - } else if (vamp && !rn2(6)) { - vamp = FALSE; - makeniche(TRAPDOOR); - } else makeniche(NO_TRAP); - } + while (ct--) { + if (ltptr && !rn2(6)) { + ltptr = FALSE; + makeniche(LEVEL_TELEP); + } else if (vamp && !rn2(6)) { + vamp = FALSE; + makeniche(TRAPDOOR); + } else + makeniche(NO_TRAP); + } } STATIC_OVL void makevtele() { - makeniche(TELEP_TRAP); + makeniche(TELEP_TRAP); } /* clear out various globals that keep information on the current level. @@ -556,278 +578,301 @@ makevtele() STATIC_OVL void clear_level_structures() { - static struct rm zerorm = { cmap_to_glyph(S_stone), - 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - register int x,y; - register struct rm *lev; + static struct rm zerorm = { cmap_to_glyph(S_stone), 0, 0, 0, 0, 0, 0, 0, + 0, 0 }; + register int x, y; + register struct rm *lev; - for(x=0; xproto); - return; - } else if (dungeons[u.uz.dnum].proto[0]) { - makemaz(""); - return; - } else if (In_mines(&u.uz)) { - makemaz("minefill"); - return; - } else if (In_quest(&u.uz)) { - char fillname[9]; - s_level *loc_lev; - - Sprintf(fillname, "%s-loca", urole.filecode); - loc_lev = find_level(fillname); - - Sprintf(fillname, "%s-fil", urole.filecode); - Strcat(fillname, - (u.uz.dlevel < loc_lev->dlevel.dlevel) ? "a" : "b"); - makemaz(fillname); - return; - } else if(In_hell(&u.uz) || - (rn2(5) && u.uz.dnum == medusa_level.dnum - && depth(&u.uz) > depth(&medusa_level))) { - makemaz(""); - return; - } - } - - /* otherwise, fall through - it's a "regular" level. */ - - if (Is_rogue_level(&u.uz)) { - makeroguerooms(); - makerogueghost(); - } else - makerooms(); - sort_rooms(); - - /* construct stairs (up and down in different rooms if possible) */ - croom = &rooms[rn2(nroom)]; - if (!Is_botlevel(&u.uz)) - mkstairs(somex(croom), somey(croom), 0, croom); /* down */ - if (nroom > 1) { - troom = croom; - croom = &rooms[rn2(nroom-1)]; - if (croom == troom) croom++; - } - - if (u.uz.dlevel != 1) { - xchar sx, sy; - do { - sx = somex(croom); - sy = somey(croom); - } while(occupied(sx, sy)); - mkstairs(sx, sy, 1, croom); /* up */ - } - - branchp = Is_branchlev(&u.uz); /* possible dungeon branch */ - room_threshold = branchp ? 4 : 3; /* minimum number of rooms needed - to allow a random special room */ - if (Is_rogue_level(&u.uz)) goto skip0; - makecorridors(); - make_niches(); - - /* make a secret treasure vault, not connected to the rest */ - if(do_vault()) { - xchar w,h; - debugpline0("trying to make a vault..."); - w = 1; - h = 1; - if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) { - fill_vault: - add_room(vault_x, vault_y, vault_x+w, - vault_y+h, TRUE, VAULT, FALSE); - level.flags.has_vault = 1; - ++room_threshold; - fill_room(&rooms[nroom - 1], FALSE); - mk_knox_portal(vault_x+w, vault_y+h); - if(!level.flags.noteleport && !rn2(3)) makevtele(); - } else if(rnd_rect() && create_vault()) { - vault_x = rooms[nroom].lx; - vault_y = rooms[nroom].ly; - if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) - goto fill_vault; - else - rooms[nroom].hx = -1; - } - } + if (wiz1_level.dlevel == 0) + init_dungeons(); + oinit(); /* assign level dependent obj probabilities */ + clear_level_structures(); { - register int u_depth = depth(&u.uz); + register s_level *slev = Is_special(&u.uz); - if(wizard && nh_getenv("SHOPTYPE")) mkroom(SHOPBASE); else - if (u_depth > 1 && - u_depth < depth(&medusa_level) && - nroom >= room_threshold && - rn2(u_depth) < 3) mkroom(SHOPBASE); - else if (u_depth > 4 && !rn2(6)) mkroom(COURT); - else if (u_depth > 5 && !rn2(8) && - !(mvitals[PM_LEPRECHAUN].mvflags & G_GONE)) mkroom(LEPREHALL); - else if (u_depth > 6 && !rn2(7)) mkroom(ZOO); - else if (u_depth > 8 && !rn2(5)) mkroom(TEMPLE); - else if (u_depth > 9 && !rn2(5) && - !(mvitals[PM_KILLER_BEE].mvflags & G_GONE)) mkroom(BEEHIVE); - else if (u_depth > 11 && !rn2(6)) mkroom(MORGUE); - else if (u_depth > 12 && !rn2(8) && antholemon()) mkroom(ANTHOLE); - else if (u_depth > 14 && !rn2(4) && - !(mvitals[PM_SOLDIER].mvflags & G_GONE)) mkroom(BARRACKS); - else if (u_depth > 15 && !rn2(6)) mkroom(SWAMP); - else if (u_depth > 16 && !rn2(8) && - !(mvitals[PM_COCKATRICE].mvflags & G_GONE)) mkroom(COCKNEST); + /* check for special levels */ + if (slev && !Is_rogue_level(&u.uz)) { + makemaz(slev->proto); + return; + } else if (dungeons[u.uz.dnum].proto[0]) { + makemaz(""); + return; + } else if (In_mines(&u.uz)) { + makemaz("minefill"); + return; + } else if (In_quest(&u.uz)) { + char fillname[9]; + s_level *loc_lev; + + Sprintf(fillname, "%s-loca", urole.filecode); + loc_lev = find_level(fillname); + + Sprintf(fillname, "%s-fil", urole.filecode); + Strcat(fillname, + (u.uz.dlevel < loc_lev->dlevel.dlevel) ? "a" : "b"); + makemaz(fillname); + return; + } else if (In_hell(&u.uz) + || (rn2(5) && u.uz.dnum == medusa_level.dnum + && depth(&u.uz) > depth(&medusa_level))) { + makemaz(""); + return; + } + } + + /* otherwise, fall through - it's a "regular" level. */ + + if (Is_rogue_level(&u.uz)) { + makeroguerooms(); + makerogueghost(); + } else + makerooms(); + sort_rooms(); + + /* construct stairs (up and down in different rooms if possible) */ + croom = &rooms[rn2(nroom)]; + if (!Is_botlevel(&u.uz)) + mkstairs(somex(croom), somey(croom), 0, croom); /* down */ + if (nroom > 1) { + troom = croom; + croom = &rooms[rn2(nroom - 1)]; + if (croom == troom) + croom++; + } + + if (u.uz.dlevel != 1) { + xchar sx, sy; + do { + sx = somex(croom); + sy = somey(croom); + } while (occupied(sx, sy)); + mkstairs(sx, sy, 1, croom); /* up */ + } + + branchp = Is_branchlev(&u.uz); /* possible dungeon branch */ + room_threshold = branchp ? 4 : 3; /* minimum number of rooms needed + to allow a random special room */ + if (Is_rogue_level(&u.uz)) + goto skip0; + makecorridors(); + make_niches(); + + /* make a secret treasure vault, not connected to the rest */ + if (do_vault()) { + xchar w, h; + debugpline0("trying to make a vault..."); + w = 1; + h = 1; + if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) { + fill_vault: + add_room(vault_x, vault_y, vault_x + w, vault_y + h, TRUE, VAULT, + FALSE); + level.flags.has_vault = 1; + ++room_threshold; + fill_room(&rooms[nroom - 1], FALSE); + mk_knox_portal(vault_x + w, vault_y + h); + if (!level.flags.noteleport && !rn2(3)) + makevtele(); + } else if (rnd_rect() && create_vault()) { + vault_x = rooms[nroom].lx; + vault_y = rooms[nroom].ly; + if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) + goto fill_vault; + else + rooms[nroom].hx = -1; + } + } + + { + register int u_depth = depth(&u.uz); + + if (wizard && nh_getenv("SHOPTYPE")) + mkroom(SHOPBASE); + else if (u_depth > 1 && u_depth < depth(&medusa_level) + && nroom >= room_threshold && rn2(u_depth) < 3) + mkroom(SHOPBASE); + else if (u_depth > 4 && !rn2(6)) + mkroom(COURT); + else if (u_depth > 5 && !rn2(8) + && !(mvitals[PM_LEPRECHAUN].mvflags & G_GONE)) + mkroom(LEPREHALL); + else if (u_depth > 6 && !rn2(7)) + mkroom(ZOO); + else if (u_depth > 8 && !rn2(5)) + mkroom(TEMPLE); + else if (u_depth > 9 && !rn2(5) + && !(mvitals[PM_KILLER_BEE].mvflags & G_GONE)) + mkroom(BEEHIVE); + else if (u_depth > 11 && !rn2(6)) + mkroom(MORGUE); + else if (u_depth > 12 && !rn2(8) && antholemon()) + mkroom(ANTHOLE); + else if (u_depth > 14 && !rn2(4) + && !(mvitals[PM_SOLDIER].mvflags & G_GONE)) + mkroom(BARRACKS); + else if (u_depth > 15 && !rn2(6)) + mkroom(SWAMP); + else if (u_depth > 16 && !rn2(8) + && !(mvitals[PM_COCKATRICE].mvflags & G_GONE)) + mkroom(COCKNEST); } skip0: - /* Place multi-dungeon branch. */ - place_branch(branchp, 0, 0); + /* Place multi-dungeon branch. */ + place_branch(branchp, 0, 0); - /* for each room: put things inside */ - for(croom = rooms; croom->hx > 0; croom++) { - if(croom->rtype != OROOM) continue; + /* for each room: put things inside */ + for (croom = rooms; croom->hx > 0; croom++) { + if (croom->rtype != OROOM) + continue; - /* put a sleeping monster inside */ - /* Note: monster may be on the stairs. This cannot be - avoided: maybe the player fell through a trap door - while a monster was on the stairs. Conclusion: - we have to check for monsters on the stairs anyway. */ + /* put a sleeping monster inside */ + /* Note: monster may be on the stairs. This cannot be + avoided: maybe the player fell through a trap door + while a monster was on the stairs. Conclusion: + we have to check for monsters on the stairs anyway. */ - if(u.uhave.amulet || !rn2(3)) { - x = somex(croom); y = somey(croom); - tmonst = makemon((struct permonst *) 0, x,y,NO_MM_FLAGS); - if (tmonst && tmonst->data == &mons[PM_GIANT_SPIDER] && - !occupied(x, y)) - (void) maketrap(x, y, WEB); - } - /* put traps and mimics inside */ - goldseen = FALSE; - x = 8 - (level_difficulty()/6); - if (x <= 1) x = 2; - while (!rn2(x)) - mktrap(0,0,croom,(coord*)0); - if (!goldseen && !rn2(3)) - (void) mkgold(0L, somex(croom), somey(croom)); - if(Is_rogue_level(&u.uz)) goto skip_nonrogue; - if(!rn2(10)) mkfount(0,croom); - if(!rn2(60)) mksink(croom); - if(!rn2(60)) mkaltar(croom); - x = 80 - (depth(&u.uz) * 2); - if (x < 2) x = 2; - if(!rn2(x)) mkgrave(croom); + if (u.uhave.amulet || !rn2(3)) { + x = somex(croom); + y = somey(croom); + tmonst = makemon((struct permonst *) 0, x, y, NO_MM_FLAGS); + if (tmonst && tmonst->data == &mons[PM_GIANT_SPIDER] + && !occupied(x, y)) + (void) maketrap(x, y, WEB); + } + /* put traps and mimics inside */ + goldseen = FALSE; + x = 8 - (level_difficulty() / 6); + if (x <= 1) + x = 2; + while (!rn2(x)) + mktrap(0, 0, croom, (coord *) 0); + if (!goldseen && !rn2(3)) + (void) mkgold(0L, somex(croom), somey(croom)); + if (Is_rogue_level(&u.uz)) + goto skip_nonrogue; + if (!rn2(10)) + mkfount(0, croom); + if (!rn2(60)) + mksink(croom); + if (!rn2(60)) + mkaltar(croom); + x = 80 - (depth(&u.uz) * 2); + if (x < 2) + x = 2; + if (!rn2(x)) + mkgrave(croom); - /* put statues inside */ - if(!rn2(20)) - (void) mkcorpstat(STATUE, (struct monst *)0, - (struct permonst *)0, - somex(croom), somey(croom), CORPSTAT_INIT); - /* put box/chest inside; - * 40% chance for at least 1 box, regardless of number - * of rooms; about 5 - 7.5% for 2 boxes, least likely - * when few rooms; chance for 3 or more is neglible. - */ - if(!rn2(nroom * 5 / 2)) - (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, - somex(croom), somey(croom), TRUE, FALSE); + /* put statues inside */ + if (!rn2(20)) + (void) mkcorpstat(STATUE, (struct monst *) 0, + (struct permonst *) 0, somex(croom), + somey(croom), CORPSTAT_INIT); + /* put box/chest inside; + * 40% chance for at least 1 box, regardless of number + * of rooms; about 5 - 7.5% for 2 boxes, least likely + * when few rooms; chance for 3 or more is neglible. + */ + if (!rn2(nroom * 5 / 2)) + (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, somex(croom), + somey(croom), TRUE, FALSE); - /* maybe make some graffiti */ - if(!rn2(27 + 3 * abs(depth(&u.uz)))) { - char buf[BUFSZ]; - const char *mesg = random_engraving(buf); - if (mesg) { - do { - x = somex(croom); y = somey(croom); - } while(levl[x][y].typ != ROOM && !rn2(40)); - if (!(IS_POOL(levl[x][y].typ) || - IS_FURNITURE(levl[x][y].typ))) - make_engr_at(x, y, mesg, 0L, MARK); - } - } + /* maybe make some graffiti */ + if (!rn2(27 + 3 * abs(depth(&u.uz)))) { + char buf[BUFSZ]; + const char *mesg = random_engraving(buf); + if (mesg) { + do { + x = somex(croom); + y = somey(croom); + } while (levl[x][y].typ != ROOM && !rn2(40)); + if (!(IS_POOL(levl[x][y].typ) + || IS_FURNITURE(levl[x][y].typ))) + make_engr_at(x, y, mesg, 0L, MARK); + } + } - skip_nonrogue: - if(!rn2(3)) { - (void) mkobj_at(0, somex(croom), somey(croom), TRUE); - tryct = 0; - while(!rn2(5)) { - if(++tryct > 100) { - impossible("tryct overflow4"); - break; - } - (void) mkobj_at(0, somex(croom), somey(croom), TRUE); - } - } - } + skip_nonrogue: + if (!rn2(3)) { + (void) mkobj_at(0, somex(croom), somey(croom), TRUE); + tryct = 0; + while (!rn2(5)) { + if (++tryct > 100) { + impossible("tryct overflow4"); + break; + } + (void) mkobj_at(0, somex(croom), somey(croom), TRUE); + } + } + } } /* @@ -841,210 +886,222 @@ mineralize(kelp_pool, kelp_moat, goldprob, gemprob, skip_lvl_checks) int kelp_pool, kelp_moat, goldprob, gemprob; boolean skip_lvl_checks; { - s_level *sp; - struct obj *otmp; - int x, y, cnt; + s_level *sp; + struct obj *otmp; + int x, y, cnt; - if (kelp_pool < 0) kelp_pool = 10; - if (kelp_moat < 0) kelp_moat = 30; + if (kelp_pool < 0) + kelp_pool = 10; + if (kelp_moat < 0) + kelp_moat = 30; - /* Place kelp, except on the plane of water */ - if (!skip_lvl_checks && In_endgame(&u.uz)) return; - for (x = 2; x < (COLNO - 2); x++) - for (y = 1; y < (ROWNO - 1); y++) - if ((kelp_pool && levl[x][y].typ == POOL && !rn2(kelp_pool)) || - (kelp_moat && levl[x][y].typ == MOAT && !rn2(kelp_moat))) - (void) mksobj_at(KELP_FROND, x, y, TRUE, FALSE); + /* Place kelp, except on the plane of water */ + if (!skip_lvl_checks && In_endgame(&u.uz)) + return; + for (x = 2; x < (COLNO - 2); x++) + for (y = 1; y < (ROWNO - 1); y++) + if ((kelp_pool && levl[x][y].typ == POOL && !rn2(kelp_pool)) + || (kelp_moat && levl[x][y].typ == MOAT && !rn2(kelp_moat))) + (void) mksobj_at(KELP_FROND, x, y, TRUE, FALSE); - /* determine if it is even allowed; - almost all special levels are excluded */ - if (!skip_lvl_checks && (In_hell(&u.uz) || In_V_tower(&u.uz) || - Is_rogue_level(&u.uz) || - level.flags.arboreal || - ((sp = Is_special(&u.uz)) != 0 && !Is_oracle_level(&u.uz) - && (!In_mines(&u.uz) || sp->flags.town) - ))) return; + /* determine if it is even allowed; + almost all special levels are excluded */ + if (!skip_lvl_checks + && (In_hell(&u.uz) || In_V_tower(&u.uz) || Is_rogue_level(&u.uz) + || level.flags.arboreal + || ((sp = Is_special(&u.uz)) != 0 && !Is_oracle_level(&u.uz) + && (!In_mines(&u.uz) || sp->flags.town)))) + return; - /* basic level-related probabilities */ - if (goldprob < 0) goldprob = 20 + depth(&u.uz) / 3; - if (gemprob < 0) gemprob = goldprob / 4; + /* basic level-related probabilities */ + if (goldprob < 0) + goldprob = 20 + depth(&u.uz) / 3; + if (gemprob < 0) + gemprob = goldprob / 4; - /* mines have ***MORE*** goodies - otherwise why mine? */ - if (!skip_lvl_checks) { - if (In_mines(&u.uz)) { - goldprob *= 2; - gemprob *= 3; - } else if (In_quest(&u.uz)) { - goldprob /= 4; - gemprob /= 6; - } - } + /* mines have ***MORE*** goodies - otherwise why mine? */ + if (!skip_lvl_checks) { + if (In_mines(&u.uz)) { + goldprob *= 2; + gemprob *= 3; + } else if (In_quest(&u.uz)) { + goldprob /= 4; + gemprob /= 6; + } + } - /* - * Seed rock areas with gold and/or gems. - * We use fairly low level object handling to avoid unnecessary - * overhead from placing things in the floor chain prior to burial. - */ - for (x = 2; x < (COLNO - 2); x++) - for (y = 1; y < (ROWNO - 1); y++) - if (levl[x][y+1].typ != STONE) { /* spot not eligible */ - y += 2; /* next two spots aren't eligible either */ - } else if (levl[x][y].typ != STONE) { /* this spot not eligible */ - y += 1; /* next spot isn't eligible either */ - } else if (!(levl[x][y].wall_info & W_NONDIGGABLE) && - levl[x][y-1].typ == STONE && - levl[x+1][y-1].typ == STONE && levl[x-1][y-1].typ == STONE && - levl[x+1][y].typ == STONE && levl[x-1][y].typ == STONE && - levl[x+1][y+1].typ == STONE && levl[x-1][y+1].typ == STONE) { - if (rn2(1000) < goldprob) { - if ((otmp = mksobj(GOLD_PIECE, FALSE, FALSE)) != 0) { - otmp->ox = x, otmp->oy = y; - otmp->quan = 1L + rnd(goldprob * 3); - otmp->owt = weight(otmp); - if (!rn2(3)) add_to_buried(otmp); - else place_object(otmp, x, y); - } - } - if (rn2(1000) < gemprob) { - for (cnt = rnd(2 + dunlev(&u.uz) / 3); cnt > 0; cnt--) - if ((otmp = mkobj(GEM_CLASS, FALSE)) != 0) { - if (otmp->otyp == ROCK) { - dealloc_obj(otmp); /* discard it */ - } else { - otmp->ox = x, otmp->oy = y; - if (!rn2(3)) add_to_buried(otmp); - else place_object(otmp, x, y); - } - } - } - } + /* + * Seed rock areas with gold and/or gems. + * We use fairly low level object handling to avoid unnecessary + * overhead from placing things in the floor chain prior to burial. + */ + for (x = 2; x < (COLNO - 2); x++) + for (y = 1; y < (ROWNO - 1); y++) + if (levl[x][y + 1].typ != STONE) { /* spot not eligible */ + y += 2; /* next two spots aren't eligible either */ + } else if (levl[x][y].typ != STONE) { /* this spot not eligible */ + y += 1; /* next spot isn't eligible either */ + } else if (!(levl[x][y].wall_info & W_NONDIGGABLE) + && levl[x][y - 1].typ == STONE + && levl[x + 1][y - 1].typ == STONE + && levl[x - 1][y - 1].typ == STONE + && levl[x + 1][y].typ == STONE + && levl[x - 1][y].typ == STONE + && levl[x + 1][y + 1].typ == STONE + && levl[x - 1][y + 1].typ == STONE) { + if (rn2(1000) < goldprob) { + if ((otmp = mksobj(GOLD_PIECE, FALSE, FALSE)) != 0) { + otmp->ox = x, otmp->oy = y; + otmp->quan = 1L + rnd(goldprob * 3); + otmp->owt = weight(otmp); + if (!rn2(3)) + add_to_buried(otmp); + else + place_object(otmp, x, y); + } + } + if (rn2(1000) < gemprob) { + for (cnt = rnd(2 + dunlev(&u.uz) / 3); cnt > 0; cnt--) + if ((otmp = mkobj(GEM_CLASS, FALSE)) != 0) { + if (otmp->otyp == ROCK) { + dealloc_obj(otmp); /* discard it */ + } else { + otmp->ox = x, otmp->oy = y; + if (!rn2(3)) + add_to_buried(otmp); + else + place_object(otmp, x, y); + } + } + } + } } void mklev() { - struct mkroom *croom; - int ridx; + struct mkroom *croom; + int ridx; - init_mapseen(&u.uz); - if(getbones()) return; + init_mapseen(&u.uz); + if (getbones()) + return; - in_mklev = TRUE; - makelevel(); - bound_digging(); - mineralize(-1, -1, -1, -1, FALSE); - in_mklev = FALSE; - /* has_morgue gets cleared once morgue is entered; graveyard stays - set (graveyard might already be set even when has_morgue is clear - [see fixup_special()], so don't update it unconditionally) */ - if (level.flags.has_morgue) - level.flags.graveyard = 1; - if (!level.flags.is_maze_lev) { - for (croom = &rooms[0]; croom != &rooms[nroom]; croom++) + in_mklev = TRUE; + makelevel(); + bound_digging(); + mineralize(-1, -1, -1, -1, FALSE); + in_mklev = FALSE; + /* has_morgue gets cleared once morgue is entered; graveyard stays + set (graveyard might already be set even when has_morgue is clear + [see fixup_special()], so don't update it unconditionally) */ + if (level.flags.has_morgue) + level.flags.graveyard = 1; + if (!level.flags.is_maze_lev) { + for (croom = &rooms[0]; croom != &rooms[nroom]; croom++) #ifdef SPECIALIZATION - topologize(croom, FALSE); + topologize(croom, FALSE); #else - topologize(croom); + topologize(croom); #endif - } - set_wall_state(); - /* for many room types, rooms[].rtype is zeroed once the room has been - entered; rooms[].orig_rtype always retains original rtype value */ - for (ridx = 0; ridx < SIZE(rooms); ridx++) - rooms[ridx].orig_rtype = rooms[ridx].rtype; + } + set_wall_state(); + /* for many room types, rooms[].rtype is zeroed once the room has been + entered; rooms[].orig_rtype always retains original rtype value */ + for (ridx = 0; ridx < SIZE(rooms); ridx++) + rooms[ridx].orig_rtype = rooms[ridx].rtype; } void #ifdef SPECIALIZATION -topologize(croom, do_ordinary) -register struct mkroom *croom; +topologize(croom, do_ordinary) register struct mkroom *croom; boolean do_ordinary; #else -topologize(croom) -register struct mkroom *croom; +topologize(croom) register struct mkroom *croom; #endif { - register int x, y, roomno = (int)((croom - rooms) + ROOMOFFSET); - register int lowx = croom->lx, lowy = croom->ly; - register int hix = croom->hx, hiy = croom->hy; + register int x, y, roomno = (int) ((croom - rooms) + ROOMOFFSET); + register int lowx = croom->lx, lowy = croom->ly; + register int hix = croom->hx, hiy = croom->hy; #ifdef SPECIALIZATION - register schar rtype = croom->rtype; + register schar rtype = croom->rtype; #endif - register int subindex, nsubrooms = croom->nsubrooms; + register int subindex, nsubrooms = croom->nsubrooms; - /* skip the room if already done; i.e. a shop handled out of order */ - /* also skip if this is non-rectangular (it _must_ be done already) */ - if ((int) levl[lowx][lowy].roomno == roomno || croom->irregular) - return; + /* skip the room if already done; i.e. a shop handled out of order */ + /* also skip if this is non-rectangular (it _must_ be done already) */ + if ((int) levl[lowx][lowy].roomno == roomno || croom->irregular) + return; #ifdef SPECIALIZATION - if (Is_rogue_level(&u.uz)) - do_ordinary = TRUE; /* vision routine helper */ - if ((rtype != OROOM) || do_ordinary) + if (Is_rogue_level(&u.uz)) + do_ordinary = TRUE; /* vision routine helper */ + if ((rtype != OROOM) || do_ordinary) #endif - { - /* do innards first */ - for(x = lowx; x <= hix; x++) - for(y = lowy; y <= hiy; y++) + { + /* do innards first */ + for (x = lowx; x <= hix; x++) + for (y = lowy; y <= hiy; y++) #ifdef SPECIALIZATION - if (rtype == OROOM) - levl[x][y].roomno = NO_ROOM; - else + if (rtype == OROOM) + levl[x][y].roomno = NO_ROOM; + else #endif - levl[x][y].roomno = roomno; - /* top and bottom edges */ - for(x = lowx-1; x <= hix+1; x++) - for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) { - levl[x][y].edge = 1; - if (levl[x][y].roomno) - levl[x][y].roomno = SHARED; - else - levl[x][y].roomno = roomno; - } - /* sides */ - for(x = lowx-1; x <= hix+1; x += (hix-lowx+2)) - for(y = lowy; y <= hiy; y++) { - levl[x][y].edge = 1; - if (levl[x][y].roomno) - levl[x][y].roomno = SHARED; - else - levl[x][y].roomno = roomno; - } - } - /* subrooms */ - for (subindex = 0; subindex < nsubrooms; subindex++) + levl[x][y].roomno = roomno; + /* top and bottom edges */ + for (x = lowx - 1; x <= hix + 1; x++) + for (y = lowy - 1; y <= hiy + 1; y += (hiy - lowy + 2)) { + levl[x][y].edge = 1; + if (levl[x][y].roomno) + levl[x][y].roomno = SHARED; + else + levl[x][y].roomno = roomno; + } + /* sides */ + for (x = lowx - 1; x <= hix + 1; x += (hix - lowx + 2)) + for (y = lowy; y <= hiy; y++) { + levl[x][y].edge = 1; + if (levl[x][y].roomno) + levl[x][y].roomno = SHARED; + else + levl[x][y].roomno = roomno; + } + } + /* subrooms */ + for (subindex = 0; subindex < nsubrooms; subindex++) #ifdef SPECIALIZATION - topologize(croom->sbrooms[subindex], (rtype != OROOM)); + topologize(croom->sbrooms[subindex], (rtype != OROOM)); #else - topologize(croom->sbrooms[subindex]); + topologize(croom->sbrooms[subindex]); #endif } /* Find an unused room for a branch location. */ STATIC_OVL struct mkroom * find_branch_room(mp) - coord *mp; +coord *mp; { struct mkroom *croom = 0; if (nroom == 0) { - mazexy(mp); /* already verifies location */ + mazexy(mp); /* already verifies location */ } else { - /* not perfect - there may be only one stairway */ - if(nroom > 2) { - int tryct = 0; + /* not perfect - there may be only one stairway */ + if (nroom > 2) { + int tryct = 0; - do - croom = &rooms[rn2(nroom)]; - while((croom == dnstairs_room || croom == upstairs_room || - croom->rtype != OROOM) && (++tryct < 100)); - } else - croom = &rooms[rn2(nroom)]; + do + croom = &rooms[rn2(nroom)]; + while ((croom == dnstairs_room || croom == upstairs_room + || croom->rtype != OROOM) && (++tryct < 100)); + } else + croom = &rooms[rn2(nroom)]; - do { - if (!somexy(croom, mp)) - impossible("Can't place branch!"); - } while(occupied(mp->x, mp->y) || - (levl[mp->x][mp->y].typ != CORR && levl[mp->x][mp->y].typ != ROOM)); + do { + if (!somexy(croom, mp)) + impossible("Can't place branch!"); + } while (occupied(mp->x, mp->y) + || (levl[mp->x][mp->y].typ != CORR + && levl[mp->x][mp->y].typ != ROOM)); } return croom; } @@ -1052,135 +1109,138 @@ find_branch_room(mp) /* Find the room for (x,y). Return null if not in a room. */ STATIC_OVL struct mkroom * pos_to_room(x, y) - xchar x, y; +xchar x, y; { int i; struct mkroom *curr; for (curr = rooms, i = 0; i < nroom; curr++, i++) - if (inside_room(curr, x, y)) return curr;; + if (inside_room(curr, x, y)) + return curr; + ; return (struct mkroom *) 0; } - /* If given a branch, randomly place a special stair or portal. */ void place_branch(br, x, y) -branch *br; /* branch to place */ -xchar x, y; /* location */ +branch *br; /* branch to place */ +xchar x, y; /* location */ { - coord m; - d_level *dest; - boolean make_stairs; - struct mkroom *br_room; + coord m; + d_level *dest; + boolean make_stairs; + struct mkroom *br_room; - /* - * Return immediately if there is no branch to make or we have - * already made one. This routine can be called twice when - * a special level is loaded that specifies an SSTAIR location - * as a favored spot for a branch. - */ - if (!br || made_branch) return; + /* + * Return immediately if there is no branch to make or we have + * already made one. This routine can be called twice when + * a special level is loaded that specifies an SSTAIR location + * as a favored spot for a branch. + */ + if (!br || made_branch) + return; - if (!x) { /* find random coordinates for branch */ - br_room = find_branch_room(&m); - x = m.x; - y = m.y; - } else { - br_room = pos_to_room(x, y); - } + if (!x) { /* find random coordinates for branch */ + br_room = find_branch_room(&m); + x = m.x; + y = m.y; + } else { + br_room = pos_to_room(x, y); + } - if (on_level(&br->end1, &u.uz)) { - /* we're on end1 */ - make_stairs = br->type != BR_NO_END1; - dest = &br->end2; - } else { - /* we're on end2 */ - make_stairs = br->type != BR_NO_END2; - dest = &br->end1; - } + if (on_level(&br->end1, &u.uz)) { + /* we're on end1 */ + make_stairs = br->type != BR_NO_END1; + dest = &br->end2; + } else { + /* we're on end2 */ + make_stairs = br->type != BR_NO_END2; + dest = &br->end1; + } - if (br->type == BR_PORTAL) { - mkportal(x, y, dest->dnum, dest->dlevel); - } else if (make_stairs) { - sstairs.sx = x; - sstairs.sy = y; - sstairs.up = (char) on_level(&br->end1, &u.uz) ? - br->end1_up : !br->end1_up; - assign_level(&sstairs.tolev, dest); - sstairs_room = br_room; + if (br->type == BR_PORTAL) { + mkportal(x, y, dest->dnum, dest->dlevel); + } else if (make_stairs) { + sstairs.sx = x; + sstairs.sy = y; + sstairs.up = + (char) on_level(&br->end1, &u.uz) ? br->end1_up : !br->end1_up; + assign_level(&sstairs.tolev, dest); + sstairs_room = br_room; - levl[x][y].ladder = sstairs.up ? LA_UP : LA_DOWN; - levl[x][y].typ = STAIRS; - } - /* - * Set made_branch to TRUE even if we didn't make a stairwell (i.e. - * make_stairs is false) since there is currently only one branch - * per level, if we failed once, we're going to fail again on the - * next call. - */ - made_branch = TRUE; + levl[x][y].ladder = sstairs.up ? LA_UP : LA_DOWN; + levl[x][y].typ = STAIRS; + } + /* + * Set made_branch to TRUE even if we didn't make a stairwell (i.e. + * make_stairs is false) since there is currently only one branch + * per level, if we failed once, we're going to fail again on the + * next call. + */ + made_branch = TRUE; } STATIC_OVL boolean bydoor(x, y) register xchar x, y; { - register int typ; + register int typ; - if (isok(x+1, y)) { - typ = levl[x+1][y].typ; - if (IS_DOOR(typ) || typ == SDOOR) return TRUE; - } - if (isok(x-1, y)) { - typ = levl[x-1][y].typ; - if (IS_DOOR(typ) || typ == SDOOR) return TRUE; - } - if (isok(x, y+1)) { - typ = levl[x][y+1].typ; - if (IS_DOOR(typ) || typ == SDOOR) return TRUE; - } - if (isok(x, y-1)) { - typ = levl[x][y-1].typ; - if (IS_DOOR(typ) || typ == SDOOR) return TRUE; - } - return FALSE; + if (isok(x + 1, y)) { + typ = levl[x + 1][y].typ; + if (IS_DOOR(typ) || typ == SDOOR) + return TRUE; + } + if (isok(x - 1, y)) { + typ = levl[x - 1][y].typ; + if (IS_DOOR(typ) || typ == SDOOR) + return TRUE; + } + if (isok(x, y + 1)) { + typ = levl[x][y + 1].typ; + if (IS_DOOR(typ) || typ == SDOOR) + return TRUE; + } + if (isok(x, y - 1)) { + typ = levl[x][y - 1].typ; + if (IS_DOOR(typ) || typ == SDOOR) + return TRUE; + } + return FALSE; } /* see whether it is allowable to create a door at [x,y] */ int -okdoor(x,y) +okdoor(x, y) register xchar x, y; { - register boolean near_door = bydoor(x, y); + register boolean near_door = bydoor(x, y); - return((levl[x][y].typ == HWALL || levl[x][y].typ == VWALL) && - doorindex < DOORMAX && !near_door); + return ((levl[x][y].typ == HWALL || levl[x][y].typ == VWALL) + && doorindex < DOORMAX && !near_door); } void -dodoor(x,y,aroom) +dodoor(x, y, aroom) register int x, y; register struct mkroom *aroom; { - if(doorindex >= DOORMAX) { - impossible("DOORMAX exceeded?"); - return; - } + if (doorindex >= DOORMAX) { + impossible("DOORMAX exceeded?"); + return; + } - dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR); + dosdoor(x, y, aroom, rn2(8) ? DOOR : SDOOR); } boolean occupied(x, y) register xchar x, y; { - return((boolean)(t_at(x, y) - || IS_FURNITURE(levl[x][y].typ) - || is_lava(x,y) - || is_pool(x,y) - || invocation_pos(x,y) - )); + return ((boolean)(t_at(x, y) || IS_FURNITURE(levl[x][y].typ) + || is_lava(x, y) || is_pool(x, y) + || invocation_pos(x, y))); } /* make a trap somewhere (in croom if mazeflag = 0 && !tm) */ @@ -1191,229 +1251,269 @@ register int num, mazeflag; register struct mkroom *croom; coord *tm; { - register int kind; - coord m; + register int kind; + coord m; - /* no traps in pools */ - if (tm && is_pool(tm->x,tm->y)) return; + /* no traps in pools */ + if (tm && is_pool(tm->x, tm->y)) + return; - if (num > 0 && num < TRAPNUM) { - kind = num; - } else if (Is_rogue_level(&u.uz)) { - switch (rn2(7)) { - default: kind = BEAR_TRAP; break; /* 0 */ - case 1: kind = ARROW_TRAP; break; - case 2: kind = DART_TRAP; break; - case 3: kind = TRAPDOOR; break; - case 4: kind = PIT; break; - case 5: kind = SLP_GAS_TRAP; break; - case 6: kind = RUST_TRAP; break; - } - } else if (Inhell && !rn2(5)) { - /* bias the frequency of fire traps in Gehennom */ - kind = FIRE_TRAP; - } else { - unsigned lvl = level_difficulty(); + if (num > 0 && num < TRAPNUM) { + kind = num; + } else if (Is_rogue_level(&u.uz)) { + switch (rn2(7)) { + default: + kind = BEAR_TRAP; + break; /* 0 */ + case 1: + kind = ARROW_TRAP; + break; + case 2: + kind = DART_TRAP; + break; + case 3: + kind = TRAPDOOR; + break; + case 4: + kind = PIT; + break; + case 5: + kind = SLP_GAS_TRAP; + break; + case 6: + kind = RUST_TRAP; + break; + } + } else if (Inhell && !rn2(5)) { + /* bias the frequency of fire traps in Gehennom */ + kind = FIRE_TRAP; + } else { + unsigned lvl = level_difficulty(); - do { - kind = rnd(TRAPNUM-1); - /* reject "too hard" traps */ - switch (kind) { - case MAGIC_PORTAL: - kind = NO_TRAP; break; - case ROLLING_BOULDER_TRAP: - case SLP_GAS_TRAP: - if (lvl < 2) kind = NO_TRAP; break; - case LEVEL_TELEP: - if (lvl < 5 || level.flags.noteleport) - kind = NO_TRAP; break; - case SPIKED_PIT: - if (lvl < 5) kind = NO_TRAP; break; - case LANDMINE: - if (lvl < 6) kind = NO_TRAP; break; - case WEB: - if (lvl < 7) kind = NO_TRAP; break; - case STATUE_TRAP: - case POLY_TRAP: - if (lvl < 8) kind = NO_TRAP; break; - case FIRE_TRAP: - if (!Inhell) kind = NO_TRAP; break; - case TELEP_TRAP: - if (level.flags.noteleport) kind = NO_TRAP; break; - case HOLE: - /* make these much less often than other traps */ - if (rn2(7)) kind = NO_TRAP; break; - } - } while (kind == NO_TRAP); - } + do { + kind = rnd(TRAPNUM - 1); + /* reject "too hard" traps */ + switch (kind) { + case MAGIC_PORTAL: + kind = NO_TRAP; + break; + case ROLLING_BOULDER_TRAP: + case SLP_GAS_TRAP: + if (lvl < 2) + kind = NO_TRAP; + break; + case LEVEL_TELEP: + if (lvl < 5 || level.flags.noteleport) + kind = NO_TRAP; + break; + case SPIKED_PIT: + if (lvl < 5) + kind = NO_TRAP; + break; + case LANDMINE: + if (lvl < 6) + kind = NO_TRAP; + break; + case WEB: + if (lvl < 7) + kind = NO_TRAP; + break; + case STATUE_TRAP: + case POLY_TRAP: + if (lvl < 8) + kind = NO_TRAP; + break; + case FIRE_TRAP: + if (!Inhell) + kind = NO_TRAP; + break; + case TELEP_TRAP: + if (level.flags.noteleport) + kind = NO_TRAP; + break; + case HOLE: + /* make these much less often than other traps */ + if (rn2(7)) + kind = NO_TRAP; + break; + } + } while (kind == NO_TRAP); + } - if ((kind == TRAPDOOR || kind == HOLE) && !Can_fall_thru(&u.uz)) - kind = ROCKTRAP; + if ((kind == TRAPDOOR || kind == HOLE) && !Can_fall_thru(&u.uz)) + kind = ROCKTRAP; - if (tm) - m = *tm; - else { - register int tryct = 0; - boolean avoid_boulder = (kind == PIT || kind == SPIKED_PIT || - kind == TRAPDOOR || kind == HOLE); + if (tm) + m = *tm; + else { + register int tryct = 0; + boolean avoid_boulder = (kind == PIT || kind == SPIKED_PIT + || kind == TRAPDOOR || kind == HOLE); - do { - if (++tryct > 200) - return; - if (mazeflag) - mazexy(&m); - else if (!somexy(croom,&m)) - return; - } while (occupied(m.x, m.y) || - (avoid_boulder && sobj_at(BOULDER, m.x, m.y))); - } + do { + if (++tryct > 200) + return; + if (mazeflag) + mazexy(&m); + else if (!somexy(croom, &m)) + return; + } while (occupied(m.x, m.y) + || (avoid_boulder && sobj_at(BOULDER, m.x, m.y))); + } - (void) maketrap(m.x, m.y, kind); - if (kind == WEB) (void) makemon(&mons[PM_GIANT_SPIDER], - m.x, m.y, NO_MM_FLAGS); + (void) maketrap(m.x, m.y, kind); + if (kind == WEB) + (void) makemon(&mons[PM_GIANT_SPIDER], m.x, m.y, NO_MM_FLAGS); } void mkstairs(x, y, up, croom) xchar x, y; -char up; +char up; struct mkroom *croom; { - if (!x) { - impossible("mkstairs: bogus stair attempt at <%d,%d>", x, y); - return; - } + if (!x) { + impossible("mkstairs: bogus stair attempt at <%d,%d>", x, y); + return; + } - /* - * We can't make a regular stair off an end of the dungeon. This - * attempt can happen when a special level is placed at an end and - * has an up or down stair specified in its description file. - */ - if ((dunlev(&u.uz) == 1 && up) || - (dunlev(&u.uz) == dunlevs_in_dungeon(&u.uz) && !up)) - return; + /* + * We can't make a regular stair off an end of the dungeon. This + * attempt can happen when a special level is placed at an end and + * has an up or down stair specified in its description file. + */ + if ((dunlev(&u.uz) == 1 && up) + || (dunlev(&u.uz) == dunlevs_in_dungeon(&u.uz) && !up)) + return; - if(up) { - xupstair = x; - yupstair = y; - upstairs_room = croom; - } else { - xdnstair = x; - ydnstair = y; - dnstairs_room = croom; - } + if (up) { + xupstair = x; + yupstair = y; + upstairs_room = croom; + } else { + xdnstair = x; + ydnstair = y; + dnstairs_room = croom; + } - levl[x][y].typ = STAIRS; - levl[x][y].ladder = up ? LA_UP : LA_DOWN; + levl[x][y].typ = STAIRS; + levl[x][y].ladder = up ? LA_UP : LA_DOWN; } STATIC_OVL void -mkfount(mazeflag,croom) +mkfount(mazeflag, croom) register int mazeflag; register struct mkroom *croom; { - coord m; - register int tryct = 0; + coord m; + register int tryct = 0; - do { - if(++tryct > 200) return; - if(mazeflag) - mazexy(&m); - else - if (!somexy(croom, &m)) - return; - } while(occupied(m.x, m.y) || bydoor(m.x, m.y)); + do { + if (++tryct > 200) + return; + if (mazeflag) + mazexy(&m); + else if (!somexy(croom, &m)) + return; + } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); - /* Put a fountain at m.x, m.y */ - levl[m.x][m.y].typ = FOUNTAIN; - /* Is it a "blessed" fountain? (affects drinking from fountain) */ - if(!rn2(7)) levl[m.x][m.y].blessedftn = 1; + /* Put a fountain at m.x, m.y */ + levl[m.x][m.y].typ = FOUNTAIN; + /* Is it a "blessed" fountain? (affects drinking from fountain) */ + if (!rn2(7)) + levl[m.x][m.y].blessedftn = 1; - level.flags.nfountains++; + level.flags.nfountains++; } STATIC_OVL void mksink(croom) register struct mkroom *croom; { - coord m; - register int tryct = 0; + coord m; + register int tryct = 0; - do { - if(++tryct > 200) return; - if (!somexy(croom, &m)) - return; - } while(occupied(m.x, m.y) || bydoor(m.x, m.y)); + do { + if (++tryct > 200) + return; + if (!somexy(croom, &m)) + return; + } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); - /* Put a sink at m.x, m.y */ - levl[m.x][m.y].typ = SINK; + /* Put a sink at m.x, m.y */ + levl[m.x][m.y].typ = SINK; - level.flags.nsinks++; + level.flags.nsinks++; } STATIC_OVL void mkaltar(croom) register struct mkroom *croom; { - coord m; - register int tryct = 0; - aligntyp al; + coord m; + register int tryct = 0; + aligntyp al; - if (croom->rtype != OROOM) return; + if (croom->rtype != OROOM) + return; - do { - if(++tryct > 200) return; - if (!somexy(croom, &m)) - return; - } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); + do { + if (++tryct > 200) + return; + if (!somexy(croom, &m)) + return; + } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); - /* Put an altar at m.x, m.y */ - levl[m.x][m.y].typ = ALTAR; + /* Put an altar at m.x, m.y */ + levl[m.x][m.y].typ = ALTAR; - /* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */ - al = rn2((int)A_LAWFUL+2) - 1; - levl[m.x][m.y].altarmask = Align2amask( al ); + /* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */ + al = rn2((int) A_LAWFUL + 2) - 1; + levl[m.x][m.y].altarmask = Align2amask(al); } static void mkgrave(croom) struct mkroom *croom; { - coord m; - register int tryct = 0; - register struct obj *otmp; - boolean dobell = !rn2(10); + coord m; + register int tryct = 0; + register struct obj *otmp; + boolean dobell = !rn2(10); + if (croom->rtype != OROOM) + return; - if(croom->rtype != OROOM) return; + do { + if (++tryct > 200) + return; + if (!somexy(croom, &m)) + return; + } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); - do { - if(++tryct > 200) return; - if (!somexy(croom, &m)) - return; - } while (occupied(m.x, m.y) || bydoor(m.x, m.y)); + /* Put a grave at m.x, m.y */ + make_grave(m.x, m.y, dobell ? "Saved by the bell!" : (char *) 0); - /* Put a grave at m.x, m.y */ - make_grave(m.x, m.y, dobell ? "Saved by the bell!" : (char *) 0); + /* Possibly fill it with objects */ + if (!rn2(3)) + (void) mkgold(0L, m.x, m.y); + for (tryct = rn2(5); tryct; tryct--) { + otmp = mkobj(RANDOM_CLASS, TRUE); + if (!otmp) + return; + curse(otmp); + otmp->ox = m.x; + otmp->oy = m.y; + add_to_buried(otmp); + } - /* Possibly fill it with objects */ - if (!rn2(3)) (void) mkgold(0L, m.x, m.y); - for (tryct = rn2(5); tryct; tryct--) { - otmp = mkobj(RANDOM_CLASS, TRUE); - if (!otmp) return; - curse(otmp); - otmp->ox = m.x; - otmp->oy = m.y; - add_to_buried(otmp); - } - - /* Leave a bell, in case we accidentally buried someone alive */ - if (dobell) (void) mksobj_at(BELL, m.x, m.y, TRUE, FALSE); - return; + /* Leave a bell, in case we accidentally buried someone alive */ + if (dobell) + (void) mksobj_at(BELL, m.x, m.y, TRUE, FALSE); + return; } - /* maze levels have slightly different constraints from normal levels */ #define x_maze_min 2 #define y_maze_min 2 @@ -1439,45 +1539,48 @@ mkinvokearea() /* any trap hero is stuck in will be going away now */ if (u.utrap) { - u.utrap = 0; - if (u.utraptype == TT_BURIEDBALL) buried_ball_to_punishment(); + u.utrap = 0; + if (u.utraptype == TT_BURIEDBALL) + buried_ball_to_punishment(); } - mkinvpos(xmin, ymin, 0); /* middle, before placing stairs */ + mkinvpos(xmin, ymin, 0); /* middle, before placing stairs */ - for(dist = 1; dist < 7; dist++) { - xmin--; xmax++; + for (dist = 1; dist < 7; dist++) { + xmin--; + xmax++; - /* top and bottom */ - if(dist != 3) { /* the area is wider that it is high */ - ymin--; ymax++; - for(i = xmin+1; i < xmax; i++) { - mkinvpos(i, ymin, dist); - mkinvpos(i, ymax, dist); - } - } + /* top and bottom */ + if (dist != 3) { /* the area is wider that it is high */ + ymin--; + ymax++; + for (i = xmin + 1; i < xmax; i++) { + mkinvpos(i, ymin, dist); + mkinvpos(i, ymax, dist); + } + } - /* left and right */ - for(i = ymin; i <= ymax; i++) { - mkinvpos(xmin, i, dist); - mkinvpos(xmax, i, dist); - } + /* left and right */ + for (i = ymin; i <= ymax; i++) { + mkinvpos(xmin, i, dist); + mkinvpos(xmax, i, dist); + } - flush_screen(1); /* make sure the new glyphs shows up */ - delay_output(); + flush_screen(1); /* make sure the new glyphs shows up */ + delay_output(); } You("are standing at the top of a stairwell leading down!"); - mkstairs(u.ux, u.uy, 0, (struct mkroom *)0); /* down */ + mkstairs(u.ux, u.uy, 0, (struct mkroom *) 0); /* down */ newsym(u.ux, u.uy); - vision_full_recalc = 1; /* everything changed */ + vision_full_recalc = 1; /* everything changed */ } /* Change level topology. Boulders in the vicinity are eliminated. * Temporarily overrides vision in the name of a nice effect. */ STATIC_OVL void -mkinvpos(x,y,dist) -xchar x,y; +mkinvpos(x, y, dist) +xchar x, y; int dist; { struct trap *ttmp; @@ -1487,64 +1590,69 @@ int dist; /* clip at existing map borders if necessary */ if (!within_bounded_area(x, y, x_maze_min + 1, y_maze_min + 1, - x_maze_max - 1, y_maze_max - 1)) { - /* only outermost 2 columns and/or rows may be truncated due to edge */ - if (dist < (7 - 2)) - panic("mkinvpos: <%d,%d> (%d) off map edge!", x, y, dist); - return; + x_maze_max - 1, y_maze_max - 1)) { + /* only outermost 2 columns and/or rows may be truncated due to edge + */ + if (dist < (7 - 2)) + panic("mkinvpos: <%d,%d> (%d) off map edge!", x, y, dist); + return; } /* clear traps */ - if ((ttmp = t_at(x,y)) != 0) deltrap(ttmp); + if ((ttmp = t_at(x, y)) != 0) + deltrap(ttmp); /* clear boulders; leave some rocks for non-{moat|trap} locations */ make_rocks = (dist != 1 && dist != 4 && dist != 5) ? TRUE : FALSE; while ((otmp = sobj_at(BOULDER, x, y)) != 0) { - if (make_rocks) { - fracture_rock(otmp); - make_rocks = FALSE; /* don't bother with more rocks */ - } else { - obj_extract_self(otmp); - obfree(otmp, (struct obj *)0); - } + if (make_rocks) { + fracture_rock(otmp); + make_rocks = FALSE; /* don't bother with more rocks */ + } else { + obj_extract_self(otmp); + obfree(otmp, (struct obj *) 0); + } } - unblock_point(x,y); /* make sure vision knows this location is open */ + unblock_point(x, y); /* make sure vision knows this location is open */ /* fake out saved state */ lev->seenv = 0; lev->doormask = 0; - if(dist < 6) lev->lit = TRUE; + if (dist < 6) + lev->lit = TRUE; lev->waslit = TRUE; lev->horizontal = FALSE; - viz_array[y][x] = (dist < 6 ) ? - (IN_SIGHT|COULD_SEE) : /* short-circuit vision recalc */ - COULD_SEE; + viz_array[y][x] = (dist < 6) ? (IN_SIGHT | COULD_SEE) + : /* short-circuit vision recalc */ + COULD_SEE; - switch(dist) { + switch (dist) { case 1: /* fire traps */ - if (is_pool(x,y)) break; - lev->typ = ROOM; - ttmp = maketrap(x, y, FIRE_TRAP); - if (ttmp) ttmp->tseen = TRUE; - break; + if (is_pool(x, y)) + break; + lev->typ = ROOM; + ttmp = maketrap(x, y, FIRE_TRAP); + if (ttmp) + ttmp->tseen = TRUE; + break; case 0: /* lit room locations */ case 2: case 3: case 6: /* unlit room locations */ - lev->typ = ROOM; - break; + lev->typ = ROOM; + break; case 4: /* pools (aka a wide moat) */ case 5: - lev->typ = MOAT; - /* No kelp! */ - break; + lev->typ = MOAT; + /* No kelp! */ + break; default: - impossible("mkinvpos called with dist %d", dist); - break; + impossible("mkinvpos called with dist %d", dist); + break; } /* display new value of position; could have a monster/object on it */ - newsym(x,y); + newsym(x, y); } /* @@ -1559,36 +1667,37 @@ STATIC_OVL void mk_knox_portal(x, y) xchar x, y; { - extern int n_dgns; /* from dungeon.c */ - d_level *source; - branch *br; - schar u_depth; + extern int n_dgns; /* from dungeon.c */ + d_level *source; + branch *br; + schar u_depth; - br = dungeon_branch("Fort Ludios"); - if (on_level(&knox_level, &br->end1)) { - source = &br->end2; - } else { - /* disallow Knox branch on a level with one branch already */ - if(Is_branchlev(&u.uz)) - return; - source = &br->end1; - } + br = dungeon_branch("Fort Ludios"); + if (on_level(&knox_level, &br->end1)) { + source = &br->end2; + } else { + /* disallow Knox branch on a level with one branch already */ + if (Is_branchlev(&u.uz)) + return; + source = &br->end1; + } - /* Already set or 2/3 chance of deferring until a later level. */ - if (source->dnum < n_dgns || (rn2(3) && !wizard)) return; + /* Already set or 2/3 chance of deferring until a later level. */ + if (source->dnum < n_dgns || (rn2(3) && !wizard)) + return; - if (! (u.uz.dnum == oracle_level.dnum /* in main dungeon */ - && !at_dgn_entrance("The Quest") /* but not Quest's entry */ - && (u_depth = depth(&u.uz)) > 10 /* beneath 10 */ - && u_depth < depth(&medusa_level))) /* and above Medusa */ - return; + if (!(u.uz.dnum == oracle_level.dnum /* in main dungeon */ + && !at_dgn_entrance("The Quest") /* but not Quest's entry */ + && (u_depth = depth(&u.uz)) > 10 /* beneath 10 */ + && u_depth < depth(&medusa_level))) /* and above Medusa */ + return; - /* Adjust source to be current level and re-insert branch. */ - *source = u.uz; - insert_branch(br, TRUE); + /* Adjust source to be current level and re-insert branch. */ + *source = u.uz; + insert_branch(br, TRUE); - debugpline0("Made knox portal."); - place_branch(br, x, y); + debugpline0("Made knox portal."); + place_branch(br, x, y); } /*mklev.c*/ diff --git a/src/mkmap.c b/src/mkmap.c index 310b2322a..9a53e46bf 100644 --- a/src/mkmap.c +++ b/src/mkmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mkmap.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mkmap.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.15 $ */ /* NetHack 3.6 mkmap.c $Date: 2009/05/06 10:46:55 $ $Revision: 1.12 $ */ /* SCCS Id: @(#)mkmap.c 3.5 2008/02/29 */ /* Copyright (c) J. C. Collet, M. Stephenson and D. Cohrs, 1992 */ @@ -7,19 +7,20 @@ #include "hack.h" #include "sp_lev.h" -#define HEIGHT (ROWNO - 1) -#define WIDTH (COLNO - 2) +#define HEIGHT (ROWNO - 1) +#define WIDTH (COLNO - 2) -STATIC_DCL void FDECL(init_map,(SCHAR_P)); -STATIC_DCL void FDECL(init_fill,(SCHAR_P,SCHAR_P)); -STATIC_DCL schar FDECL(get_map,(int,int,SCHAR_P)); -STATIC_DCL void FDECL(pass_one,(SCHAR_P,SCHAR_P)); -STATIC_DCL void FDECL(pass_two,(SCHAR_P,SCHAR_P)); -STATIC_DCL void FDECL(pass_three,(SCHAR_P,SCHAR_P)); +STATIC_DCL void FDECL(init_map, (SCHAR_P)); +STATIC_DCL void FDECL(init_fill, (SCHAR_P, SCHAR_P)); +STATIC_DCL schar FDECL(get_map, (int, int, SCHAR_P)); +STATIC_DCL void FDECL(pass_one, (SCHAR_P, SCHAR_P)); +STATIC_DCL void FDECL(pass_two, (SCHAR_P, SCHAR_P)); +STATIC_DCL void FDECL(pass_three, (SCHAR_P, SCHAR_P)); STATIC_DCL void NDECL(wallify_map); -STATIC_DCL void FDECL(join_map,(SCHAR_P,SCHAR_P)); -STATIC_DCL void FDECL(finish_map,(SCHAR_P,SCHAR_P,BOOLEAN_P,BOOLEAN_P,BOOLEAN_P)); -STATIC_DCL void FDECL(remove_room,(unsigned)); +STATIC_DCL void FDECL(join_map, (SCHAR_P, SCHAR_P)); +STATIC_DCL void FDECL(finish_map, + (SCHAR_P, SCHAR_P, BOOLEAN_P, BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL void FDECL(remove_room, (unsigned)); void FDECL(mkmap, (lev_init *)); char *new_locations; @@ -28,129 +29,127 @@ static int n_loc_filled; STATIC_OVL void init_map(bg_typ) - schar bg_typ; +schar bg_typ; { - register int i,j; + register int i, j; - for(i=1; i WIDTH || row >= HEIGHT) - return bg_typ; - return levl[col][row].typ; + if (col <= 0 || row < 0 || col > WIDTH || row >= HEIGHT) + return bg_typ; + return levl[col][row].typ; } -static int dirs[16] = { - -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, - 0, -1 /**/, 0, 1 /**/, - 1, -1 /**/, 1, 0 /**/, 1, 1}; +static int dirs[16] = { -1, -1 /**/, -1, 0 /**/, -1, 1 /**/, 0, -1 /**/, + 0, 1 /**/, 1, -1 /**/, 1, 0 /**/, 1, 1 }; STATIC_OVL void pass_one(bg_typ, fg_typ) - schar bg_typ, fg_typ; +schar bg_typ, fg_typ; { - register int i,j; - short count, dr; + register int i, j; + short count, dr; - for(i=2; i<=WIDTH; i++) - for(j=1; j 0 && - (anyroom ? IS_ROOM(levl[sx][sy].typ) : levl[sx][sy].typ == fg_typ) && - (int) levl[sx][sy].roomno != rmno) - sx--; + while (sx > 0 && (anyroom ? IS_ROOM(levl[sx][sy].typ) + : levl[sx][sy].typ == fg_typ) + && (int) levl[sx][sy].roomno != rmno) + sx--; sx++; /* compensate for extra decrement */ /* assume sx,sy is valid */ - if(sx < min_rx) min_rx = sx; - if(sy < min_ry) min_ry = sy; + if (sx < min_rx) + min_rx = sx; + if (sy < min_ry) + min_ry = sy; - for(i=sx; i<=WIDTH && levl[i][sy].typ == fg_typ; i++) { - levl[i][sy].roomno = rmno; - levl[i][sy].lit = lit; - if(anyroom) { - /* add walls to room as well */ - register int ii,jj; - for(ii= (i == sx ? i-1 : i); ii <= i+1; ii++) - for(jj = sy-1; jj <= sy+1; jj++) - if(isok(ii,jj) && - (IS_WALL(levl[ii][jj].typ) || - IS_DOOR(levl[ii][jj].typ) || - levl[ii][jj].typ == SDOOR)) { - levl[ii][jj].edge = 1; - if(lit) levl[ii][jj].lit = lit; - if ((int) levl[ii][jj].roomno != rmno) - levl[ii][jj].roomno = SHARED; - } - } - n_loc_filled++; + for (i = sx; i <= WIDTH && levl[i][sy].typ == fg_typ; i++) { + levl[i][sy].roomno = rmno; + levl[i][sy].lit = lit; + if (anyroom) { + /* add walls to room as well */ + register int ii, jj; + for (ii = (i == sx ? i - 1 : i); ii <= i + 1; ii++) + for (jj = sy - 1; jj <= sy + 1; jj++) + if (isok(ii, jj) && (IS_WALL(levl[ii][jj].typ) + || IS_DOOR(levl[ii][jj].typ) + || levl[ii][jj].typ == SDOOR)) { + levl[ii][jj].edge = 1; + if (lit) + levl[ii][jj].lit = lit; + if ((int) levl[ii][jj].roomno != rmno) + levl[ii][jj].roomno = SHARED; + } + } + n_loc_filled++; } nx = i; - if(isok(sx,sy-1)) { - for(i=sx; isx || isok(i-1,sy-1)) && - levl[i-1][sy-1].typ == fg_typ) { - if ((int) levl[i-1][sy-1].roomno != rmno) - flood_fill_rm(i-1,sy-1,rmno,lit,anyroom); - } - if((i sx || isok(i - 1, sy - 1)) + && levl[i - 1][sy - 1].typ == fg_typ) { + if ((int) levl[i - 1][sy - 1].roomno != rmno) + flood_fill_rm(i - 1, sy - 1, rmno, lit, anyroom); + } + if ((i < nx - 1 || isok(i + 1, sy - 1)) + && levl[i + 1][sy - 1].typ == fg_typ) { + if ((int) levl[i + 1][sy - 1].roomno != rmno) + flood_fill_rm(i + 1, sy - 1, rmno, lit, anyroom); + } + } } - if(isok(sx,sy+1)) { - for(i=sx; isx || isok(i-1,sy+1)) && - levl[i-1][sy+1].typ == fg_typ) { - if ((int) levl[i-1][sy+1].roomno != rmno) - flood_fill_rm(i-1,sy+1,rmno,lit,anyroom); - } - if((i sx || isok(i - 1, sy + 1)) + && levl[i - 1][sy + 1].typ == fg_typ) { + if ((int) levl[i - 1][sy + 1].roomno != rmno) + flood_fill_rm(i - 1, sy + 1, rmno, lit, anyroom); + } + if ((i < nx - 1 || isok(i + 1, sy + 1)) + && levl[i + 1][sy + 1].typ == fg_typ) { + if ((int) levl[i + 1][sy + 1].roomno != rmno) + flood_fill_rm(i + 1, sy + 1, rmno, lit, anyroom); + } + } } - if(nx > max_rx) max_rx = nx - 1; /* nx is just past valid region */ - if(sy > max_ry) max_ry = sy; + if (nx > max_rx) + max_rx = nx - 1; /* nx is just past valid region */ + if (sy > max_ry) + max_ry = sy; } /* @@ -252,24 +255,25 @@ flood_fill_rm(sx, sy, rmno, lit, anyroom) STATIC_OVL void wallify_map() { - int x, y, xx, yy; - for(x = 1; x < COLNO; x++) - for(y = 0; y < ROWNO; y++) - if(levl[x][y].typ == STONE) { - for(yy = y - 1; yy <= y+1; yy++) - for(xx = x - 1; xx <= x+1; xx++) - if(isok(xx,yy) && levl[xx][yy].typ == ROOM) { - if(yy != y) levl[x][y].typ = HWALL; - else levl[x][y].typ = VWALL; - } - } + for (x = 1; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + if (levl[x][y].typ == STONE) { + for (yy = y - 1; yy <= y + 1; yy++) + for (xx = x - 1; xx <= x + 1; xx++) + if (isok(xx, yy) && levl[xx][yy].typ == ROOM) { + if (yy != y) + levl[x][y].typ = HWALL; + else + levl[x][y].typ = VWALL; + } + } } STATIC_OVL void join_map(bg_typ, fg_typ) - schar bg_typ, fg_typ; +schar bg_typ, fg_typ; { register struct mkroom *croom, *croom2; @@ -277,35 +281,36 @@ join_map(bg_typ, fg_typ) int sx, sy; coord sm, em; - /* first, use flood filling to find all of the regions that need joining */ - for(i=2; i<=WIDTH; i++) - for(j=1; j 3) { - add_room(min_rx, min_ry, max_rx, max_ry, - FALSE, OROOM, TRUE); - rooms[nroom-1].irregular = TRUE; - if(nroom >= (MAXNROFROOMS*2)) - goto joinm; - } else { - /* - * it's a tiny hole; erase it from the map to avoid - * having the player end up here with no way out. - */ - for(sx = min_rx; sx<=max_rx; sx++) - for(sy = min_ry; sy<=max_ry; sy++) - if ((int) levl[sx][sy].roomno == - nroom + ROOMOFFSET) { - levl[sx][sy].typ = bg_typ; - levl[sx][sy].roomno = NO_ROOM; - } - } - } - } + /* first, use flood filling to find all of the regions that need joining + */ + for (i = 2; i <= WIDTH; i++) + for (j = 1; j < HEIGHT; j++) { + if (levl[i][j].typ == fg_typ && levl[i][j].roomno == NO_ROOM) { + min_rx = max_rx = i; + min_ry = max_ry = j; + n_loc_filled = 0; + flood_fill_rm(i, j, nroom + ROOMOFFSET, FALSE, FALSE); + if (n_loc_filled > 3) { + add_room(min_rx, min_ry, max_rx, max_ry, FALSE, OROOM, + TRUE); + rooms[nroom - 1].irregular = TRUE; + if (nroom >= (MAXNROFROOMS * 2)) + goto joinm; + } else { + /* + * it's a tiny hole; erase it from the map to avoid + * having the player end up here with no way out. + */ + for (sx = min_rx; sx <= max_rx; sx++) + for (sy = min_ry; sy <= max_ry; sy++) + if ((int) levl[sx][sy].roomno + == nroom + ROOMOFFSET) { + levl[sx][sy].typ = bg_typ; + levl[sx][sy].roomno = NO_ROOM; + } + } + } + } joinm: /* @@ -314,59 +319,61 @@ joinm: * so don't call sort_rooms(), which can screw up the roomno's * validity in the levl structure. */ - for(croom = &rooms[0], croom2 = croom + 1; croom2 < &rooms[nroom]; ) { - /* pick random starting and end locations for "corridor" */ - if(!somexy(croom, &sm) || !somexy(croom2, &em)) { - /* ack! -- the level is going to be busted */ - /* arbitrarily pick centers of both rooms and hope for the best */ - impossible("No start/end room loc in join_map."); - sm.x = croom->lx + ((croom->hx - croom->lx) / 2); - sm.y = croom->ly + ((croom->hy - croom->ly) / 2); - em.x = croom2->lx + ((croom2->hx - croom2->lx) / 2); - em.y = croom2->ly + ((croom2->hy - croom2->ly) / 2); - } + for (croom = &rooms[0], croom2 = croom + 1; croom2 < &rooms[nroom];) { + /* pick random starting and end locations for "corridor" */ + if (!somexy(croom, &sm) || !somexy(croom2, &em)) { + /* ack! -- the level is going to be busted */ + /* arbitrarily pick centers of both rooms and hope for the best */ + impossible("No start/end room loc in join_map."); + sm.x = croom->lx + ((croom->hx - croom->lx) / 2); + sm.y = croom->ly + ((croom->hy - croom->ly) / 2); + em.x = croom2->lx + ((croom2->hx - croom2->lx) / 2); + em.y = croom2->ly + ((croom2->hy - croom2->ly) / 2); + } - (void) dig_corridor(&sm, &em, FALSE, fg_typ, bg_typ); + (void) dig_corridor(&sm, &em, FALSE, fg_typ, bg_typ); - /* choose next region to join */ - /* only increment croom if croom and croom2 are non-overlapping */ - if(croom2->lx > croom->hx || - ((croom2->ly > croom->hy || croom2->hy < croom->ly) && rn2(3))) { - croom = croom2; - } - croom2++; /* always increment the next room */ + /* choose next region to join */ + /* only increment croom if croom and croom2 are non-overlapping */ + if (croom2->lx > croom->hx + || ((croom2->ly > croom->hy || croom2->hy < croom->ly) + && rn2(3))) { + croom = croom2; + } + croom2++; /* always increment the next room */ } } STATIC_OVL void finish_map(fg_typ, bg_typ, lit, walled, icedpools) - schar fg_typ, bg_typ; - boolean lit, walled, icedpools; +schar fg_typ, bg_typ; +boolean lit, walled, icedpools; { - int i, j; + int i, j; - if(walled) wallify_map(); + if (walled) + wallify_map(); - if(lit) { - for(i=1; i= 0; --i) { - croom = &rooms[i]; - if (croom->hx < lx || croom->lx >= hx || - croom->hy < ly || croom->ly >= hy) continue; /* no overlap */ + croom = &rooms[i]; + if (croom->hx < lx || croom->lx >= hx || croom->hy < ly + || croom->ly >= hy) + continue; /* no overlap */ - if (croom->lx < lx || croom->hx >= hx || - croom->ly < ly || croom->hy >= hy) { /* partial overlap */ - /* TODO: ensure remaining parts of room are still joined */ + if (croom->lx < lx || croom->hx >= hx || croom->ly < ly + || croom->hy >= hy) { /* partial overlap */ + /* TODO: ensure remaining parts of room are still joined */ - if (!croom->irregular) impossible("regular room in joined map"); - } else { - /* total overlap, remove the room */ - remove_room((unsigned)i); - } + if (!croom->irregular) + impossible("regular room in joined map"); + } else { + /* total overlap, remove the room */ + remove_room((unsigned) i); + } } } @@ -410,7 +419,7 @@ remove_rooms(lx, ly, hx, hy) */ STATIC_OVL void remove_room(roomno) - unsigned roomno; +unsigned roomno; { struct mkroom *croom = &rooms[roomno]; struct mkroom *maxroom = &rooms[--nroom]; @@ -418,70 +427,67 @@ remove_room(roomno) unsigned oroomno; if (croom != maxroom) { - /* since the order in the array only matters for making corridors, - * copy the last room over the one being removed on the assumption - * that corridors have already been dug. */ - (void) memcpy((genericptr_t)croom, (genericptr_t)maxroom, - sizeof(struct mkroom)); + /* since the order in the array only matters for making corridors, + * copy the last room over the one being removed on the assumption + * that corridors have already been dug. */ + (void) memcpy((genericptr_t) croom, (genericptr_t) maxroom, + sizeof(struct mkroom)); - /* since maxroom moved, update affected level roomno values */ - oroomno = nroom + ROOMOFFSET; - roomno += ROOMOFFSET; - for (i = croom->lx; i <= croom->hx; ++i) - for (j = croom->ly; j <= croom->hy; ++j) { - if (levl[i][j].roomno == oroomno) - levl[i][j].roomno = roomno; - } + /* since maxroom moved, update affected level roomno values */ + oroomno = nroom + ROOMOFFSET; + roomno += ROOMOFFSET; + for (i = croom->lx; i <= croom->hx; ++i) + for (j = croom->ly; j <= croom->hy; ++j) { + if (levl[i][j].roomno == oroomno) + levl[i][j].roomno = roomno; + } } - maxroom->hx = -1; /* just like add_room */ + maxroom->hx = -1; /* just like add_room */ } -#define N_P1_ITER 1 /* tune map generation via this value */ -#define N_P2_ITER 1 /* tune map generation via this value */ -#define N_P3_ITER 2 /* tune map smoothing via this value */ +#define N_P1_ITER 1 /* tune map generation via this value */ +#define N_P2_ITER 1 /* tune map generation via this value */ +#define N_P3_ITER 2 /* tune map smoothing via this value */ void mkmap(init_lev) - lev_init *init_lev; +lev_init *init_lev; { - schar bg_typ = init_lev->bg, - fg_typ = init_lev->fg; - boolean smooth = init_lev->smoothed, - join = init_lev->joined; - xchar lit = init_lev->lit, - walled = init_lev->walled; - int i; + schar bg_typ = init_lev->bg, fg_typ = init_lev->fg; + boolean smooth = init_lev->smoothed, join = init_lev->joined; + xchar lit = init_lev->lit, walled = init_lev->walled; + int i; - if(lit < 0) - lit = (rnd(1+abs(depth(&u.uz))) < 11 && rn2(77)) ? 1 : 0; + if (lit < 0) + lit = (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? 1 : 0; - new_locations = (char *)alloc((WIDTH+1) * HEIGHT); + new_locations = (char *) alloc((WIDTH + 1) * HEIGHT); - init_map(bg_typ); - init_fill(bg_typ, fg_typ); + init_map(bg_typ); + init_fill(bg_typ, fg_typ); - for(i = 0; i < N_P1_ITER; i++) - pass_one(bg_typ, fg_typ); + for (i = 0; i < N_P1_ITER; i++) + pass_one(bg_typ, fg_typ); - for(i = 0; i < N_P2_ITER; i++) - pass_two(bg_typ, fg_typ); + for (i = 0; i < N_P2_ITER; i++) + pass_two(bg_typ, fg_typ); - if(smooth) - for(i = 0; i < N_P3_ITER; i++) - pass_three(bg_typ, fg_typ); + if (smooth) + for (i = 0; i < N_P3_ITER; i++) + pass_three(bg_typ, fg_typ); - if(join) - join_map(bg_typ, fg_typ); + if (join) + join_map(bg_typ, fg_typ); - finish_map(fg_typ, bg_typ, (boolean)lit, (boolean)walled, - init_lev->icedpools); - /* a walled, joined level is cavernous, not mazelike -dlc */ - if (walled && join) { - level.flags.is_maze_lev = FALSE; - level.flags.is_cavernous_lev = TRUE; - } - free(new_locations); + finish_map(fg_typ, bg_typ, (boolean) lit, (boolean) walled, + init_lev->icedpools); + /* a walled, joined level is cavernous, not mazelike -dlc */ + if (walled && join) { + level.flags.is_maze_lev = FALSE; + level.flags.is_cavernous_lev = TRUE; + } + free(new_locations); } /*mkmap.c*/ diff --git a/src/mkmaze.c b/src/mkmaze.c index 5d35cb25e..842e0f72a 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mkmaze.c $NHDT-Date: 1426465437 2015/03/16 00:23:57 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.20 $ */ +/* NetHack 3.6 mkmaze.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.36 $ */ /* NetHack 3.6 mkmaze.c $Date: 2009/05/06 10:46:56 $ $Revision: 1.18 $ */ /* SCCS Id: @(#)mkmaze.c 3.5 2007/06/18 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -6,61 +6,62 @@ #include "hack.h" #include "sp_lev.h" -#include "lev.h" /* save & restore info */ +#include "lev.h" /* save & restore info */ /* from sp_lev.c, for fixup_special() */ extern lev_region *lregions; extern int num_lregions; -STATIC_DCL boolean FDECL(iswall,(int,int)); -STATIC_DCL boolean FDECL(iswall_or_stone,(int,int)); -STATIC_DCL boolean FDECL(is_solid,(int,int)); -STATIC_DCL int FDECL(extend_spine, (int [3][3], int, int, int)); -STATIC_DCL boolean FDECL(okay,(int,int,int)); -STATIC_DCL void FDECL(maze0xy,(coord *)); -STATIC_DCL boolean FDECL(put_lregion_here,(XCHAR_P,XCHAR_P,XCHAR_P, - XCHAR_P,XCHAR_P,XCHAR_P,XCHAR_P,BOOLEAN_P,d_level *)); +STATIC_DCL boolean FDECL(iswall, (int, int)); +STATIC_DCL boolean FDECL(iswall_or_stone, (int, int)); +STATIC_DCL boolean FDECL(is_solid, (int, int)); +STATIC_DCL int FDECL(extend_spine, (int[3][3], int, int, int)); +STATIC_DCL boolean FDECL(okay, (int, int, int)); +STATIC_DCL void FDECL(maze0xy, (coord *)); +STATIC_DCL boolean +FDECL(put_lregion_here, (XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, + XCHAR_P, BOOLEAN_P, d_level *)); STATIC_DCL void NDECL(fixup_special); -STATIC_DCL void FDECL(move, (int *,int *,int)); +STATIC_DCL void FDECL(move, (int *, int *, int)); STATIC_DCL void NDECL(setup_waterlevel); STATIC_DCL void NDECL(unsetup_waterlevel); - STATIC_OVL boolean -iswall(x,y) -int x,y; +iswall(x, y) +int x, y; { register int type; - if (!isok(x,y)) return FALSE; + if (!isok(x, y)) + return FALSE; type = levl[x][y].typ; - return (IS_WALL(type) || IS_DOOR(type) || - type == SDOOR || type == IRONBARS); + return (IS_WALL(type) || IS_DOOR(type) || type == SDOOR + || type == IRONBARS); } STATIC_OVL boolean -iswall_or_stone(x,y) - int x,y; +iswall_or_stone(x, y) +int x, y; { register int type; /* out of bounds = stone */ - if (!isok(x,y)) return TRUE; + if (!isok(x, y)) + return TRUE; type = levl[x][y].typ; - return (type == STONE || IS_WALL(type) || IS_DOOR(type) || - type == SDOOR || type == IRONBARS); + return (type == STONE || IS_WALL(type) || IS_DOOR(type) || type == SDOOR + || type == IRONBARS); } /* return TRUE if out of bounds, wall or rock */ STATIC_OVL boolean -is_solid(x,y) - int x, y; +is_solid(x, y) +int x, y; { - return (!isok(x,y) || IS_STWALL(levl[x][y].typ)); + return (!isok(x, y) || IS_STWALL(levl[x][y].typ)); } - /* * Return 1 (not TRUE - we're doing bit vectors here) if we want to extend * a wall spine in the (dx,dy) direction. Return 0 otherwise. @@ -81,38 +82,37 @@ is_solid(x,y) */ STATIC_OVL int extend_spine(locale, wall_there, dx, dy) - int locale[3][3]; - int wall_there, dx, dy; +int locale[3][3]; +int wall_there, dx, dy; { int spine, nx, ny; nx = 1 + dx; ny = 1 + dy; - if (wall_there) { /* wall in that direction */ - if (dx) { - if (locale[ 1][0] && locale[ 1][2] && /* EW are wall/stone */ - locale[nx][0] && locale[nx][2]) { /* diag are wall/stone */ - spine = 0; - } else { - spine = 1; - } - } else { /* dy */ - if (locale[0][ 1] && locale[2][ 1] && /* NS are wall/stone */ - locale[0][ny] && locale[2][ny]) { /* diag are wall/stone */ - spine = 0; - } else { - spine = 1; - } - } + if (wall_there) { /* wall in that direction */ + if (dx) { + if (locale[1][0] && locale[1][2] && /* EW are wall/stone */ + locale[nx][0] && locale[nx][2]) { /* diag are wall/stone */ + spine = 0; + } else { + spine = 1; + } + } else { /* dy */ + if (locale[0][1] && locale[2][1] && /* NS are wall/stone */ + locale[0][ny] && locale[2][ny]) { /* diag are wall/stone */ + spine = 0; + } else { + spine = 1; + } + } } else { - spine = 0; + spine = 0; } return spine; } - /* * Wall cleanup. This function has two purposes: (1) remove walls that * are totally surrounded by stone - they are redundant. (2) correct @@ -122,98 +122,95 @@ void wallification(x1, y1, x2, y2) int x1, y1, x2, y2; { - uchar type; - register int x,y; - struct rm *lev; - int bits; - int locale[3][3]; /* rock or wall status surrounding positions */ - /* - * Value 0 represents a free-standing wall. It could be anything, - * so even though this table says VWALL, we actually leave whatever - * typ was there alone. - */ - static xchar spine_array[16] = { - VWALL, HWALL, HWALL, HWALL, - VWALL, TRCORNER, TLCORNER, TDWALL, - VWALL, BRCORNER, BLCORNER, TUWALL, - VWALL, TLWALL, TRWALL, CROSSWALL - }; + uchar type; + register int x, y; + struct rm *lev; + int bits; + int locale[3][3]; /* rock or wall status surrounding positions */ + /* + * Value 0 represents a free-standing wall. It could be anything, + * so even though this table says VWALL, we actually leave whatever + * typ was there alone. + */ + static xchar spine_array[16] = { VWALL, HWALL, HWALL, HWALL, + VWALL, TRCORNER, TLCORNER, TDWALL, + VWALL, BRCORNER, BLCORNER, TUWALL, + VWALL, TLWALL, TRWALL, CROSSWALL }; - /* sanity check on incoming variables */ - if (x1<0 || x2>=COLNO || x1>x2 || y1<0 || y2>=ROWNO || y1>y2) - panic("wallification: bad bounds (%d,%d) to (%d,%d)",x1,y1,x2,y2); + /* sanity check on incoming variables */ + if (x1 < 0 || x2 >= COLNO || x1 > x2 || y1 < 0 || y2 >= ROWNO || y1 > y2) + panic("wallification: bad bounds (%d,%d) to (%d,%d)", x1, y1, x2, y2); - /* Step 1: change walls surrounded by rock to rock. */ - for(x = x1; x <= x2; x++) - for(y = y1; y <= y2; y++) { - lev = &levl[x][y]; - type = lev->typ; - if (IS_WALL(type) && type != DBWALL) { - if (is_solid(x-1,y-1) && - is_solid(x-1,y ) && - is_solid(x-1,y+1) && - is_solid(x, y-1) && - is_solid(x, y+1) && - is_solid(x+1,y-1) && - is_solid(x+1,y ) && - is_solid(x+1,y+1)) - lev->typ = STONE; - } - } + /* Step 1: change walls surrounded by rock to rock. */ + for (x = x1; x <= x2; x++) + for (y = y1; y <= y2; y++) { + lev = &levl[x][y]; + type = lev->typ; + if (IS_WALL(type) && type != DBWALL) { + if (is_solid(x - 1, y - 1) && is_solid(x - 1, y) + && is_solid(x - 1, y + 1) && is_solid(x, y - 1) + && is_solid(x, y + 1) && is_solid(x + 1, y - 1) + && is_solid(x + 1, y) && is_solid(x + 1, y + 1)) + lev->typ = STONE; + } + } - /* - * Step 2: set the correct wall type. We can't combine steps - * 1 and 2 into a single sweep because we depend on knowing if - * the surrounding positions are stone. - */ - for(x = x1; x <= x2; x++) - for(y = y1; y <= y2; y++) { - lev = &levl[x][y]; - type = lev->typ; - if ( !(IS_WALL(type) && type != DBWALL)) continue; + /* + * Step 2: set the correct wall type. We can't combine steps + * 1 and 2 into a single sweep because we depend on knowing if + * the surrounding positions are stone. + */ + for (x = x1; x <= x2; x++) + for (y = y1; y <= y2; y++) { + lev = &levl[x][y]; + type = lev->typ; + if (!(IS_WALL(type) && type != DBWALL)) + continue; - /* set the locations TRUE if rock or wall or out of bounds */ - locale[0][0] = iswall_or_stone(x-1,y-1); - locale[1][0] = iswall_or_stone( x,y-1); - locale[2][0] = iswall_or_stone(x+1,y-1); + /* set the locations TRUE if rock or wall or out of bounds */ + locale[0][0] = iswall_or_stone(x - 1, y - 1); + locale[1][0] = iswall_or_stone(x, y - 1); + locale[2][0] = iswall_or_stone(x + 1, y - 1); - locale[0][1] = iswall_or_stone(x-1, y); - locale[2][1] = iswall_or_stone(x+1, y); + locale[0][1] = iswall_or_stone(x - 1, y); + locale[2][1] = iswall_or_stone(x + 1, y); - locale[0][2] = iswall_or_stone(x-1,y+1); - locale[1][2] = iswall_or_stone( x,y+1); - locale[2][2] = iswall_or_stone(x+1,y+1); + locale[0][2] = iswall_or_stone(x - 1, y + 1); + locale[1][2] = iswall_or_stone(x, y + 1); + locale[2][2] = iswall_or_stone(x + 1, y + 1); - /* determine if wall should extend to each direction NSEW */ - bits = (extend_spine(locale, iswall(x,y-1), 0, -1) << 3) - | (extend_spine(locale, iswall(x,y+1), 0, 1) << 2) - | (extend_spine(locale, iswall(x+1,y), 1, 0) << 1) - | extend_spine(locale, iswall(x-1,y), -1, 0); + /* determine if wall should extend to each direction NSEW */ + bits = (extend_spine(locale, iswall(x, y - 1), 0, -1) << 3) + | (extend_spine(locale, iswall(x, y + 1), 0, 1) << 2) + | (extend_spine(locale, iswall(x + 1, y), 1, 0) << 1) + | extend_spine(locale, iswall(x - 1, y), -1, 0); - /* don't change typ if wall is free-standing */ - if (bits) lev->typ = spine_array[bits]; - } + /* don't change typ if wall is free-standing */ + if (bits) + lev->typ = spine_array[bits]; + } } STATIC_OVL boolean -okay(x,y,dir) -int x,y; +okay(x, y, dir) +int x, y; register int dir; { - move(&x,&y,dir); - move(&x,&y,dir); - if(x<3 || y<3 || x>x_maze_max || y>y_maze_max || levl[x][y].typ != 0) - return(FALSE); - return(TRUE); + move(&x, &y, dir); + move(&x, &y, dir); + if (x < 3 || y < 3 || x > x_maze_max || y > y_maze_max + || levl[x][y].typ != 0) + return (FALSE); + return (TRUE); } STATIC_OVL void -maze0xy(cc) /* find random starting point for maze generation */ - coord *cc; +maze0xy(cc) /* find random starting point for maze generation */ +coord *cc; { - cc->x = 3 + 2*rn2((x_maze_max>>1) - 1); - cc->y = 3 + 2*rn2((y_maze_max>>1) - 1); - return; + cc->x = 3 + 2 * rn2((x_maze_max >> 1) - 1); + cc->y = 3 + 2 * rn2((y_maze_max >> 1) - 1); + return; } /* @@ -224,65 +221,68 @@ maze0xy(cc) /* find random starting point for maze generation */ */ boolean bad_location(x, y, lx, ly, hx, hy) - xchar x, y; - xchar lx, ly, hx, hy; +xchar x, y; +xchar lx, ly, hx, hy; { - return((boolean)(occupied(x, y) || - within_bounded_area(x,y, lx,ly, hx,hy) || - !((levl[x][y].typ == CORR && level.flags.is_maze_lev) || - levl[x][y].typ == ROOM || levl[x][y].typ == AIR))); + return ( + (boolean)(occupied(x, y) || within_bounded_area(x, y, lx, ly, hx, hy) + || !((levl[x][y].typ == CORR && level.flags.is_maze_lev) + || levl[x][y].typ == ROOM || levl[x][y].typ == AIR))); } /* pick a location in area (lx, ly, hx, hy) but not in (nlx, nly, nhx, nhy) */ /* and place something (based on rtype) in that region */ void place_lregion(lx, ly, hx, hy, nlx, nly, nhx, nhy, rtype, lev) - xchar lx, ly, hx, hy; - xchar nlx, nly, nhx, nhy; - xchar rtype; - d_level *lev; +xchar lx, ly, hx, hy; +xchar nlx, nly, nhx, nhy; +xchar rtype; +d_level *lev; { int trycnt; boolean oneshot; xchar x, y; - if(!lx) { /* default to whole level */ - /* - * if there are rooms and this a branch, let place_branch choose - * the branch location (to avoid putting branches in corridors). - */ - if(rtype == LR_BRANCH && nroom) { - place_branch(Is_branchlev(&u.uz), 0, 0); - return; - } + if (!lx) { /* default to whole level */ + /* + * if there are rooms and this a branch, let place_branch choose + * the branch location (to avoid putting branches in corridors). + */ + if (rtype == LR_BRANCH && nroom) { + place_branch(Is_branchlev(&u.uz), 0, 0); + return; + } - lx = 1; hx = COLNO-1; - ly = 1; hy = ROWNO-1; + lx = 1; + hx = COLNO - 1; + ly = 1; + hy = ROWNO - 1; } /* first a probabilistic approach */ oneshot = (lx == hx && ly == hy); for (trycnt = 0; trycnt < 200; trycnt++) { - x = rn1((hx - lx) + 1, lx); - y = rn1((hy - ly) + 1, ly); - if (put_lregion_here(x,y,nlx,nly,nhx,nhy,rtype,oneshot,lev)) - return; + x = rn1((hx - lx) + 1, lx); + y = rn1((hy - ly) + 1, ly); + if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, lev)) + return; } /* then a deterministic one */ oneshot = TRUE; for (x = lx; x <= hx; x++) - for (y = ly; y <= hy; y++) - if (put_lregion_here(x,y,nlx,nly,nhx,nhy,rtype,oneshot,lev)) - return; + for (y = ly; y <= hy; y++) + if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, + lev)) + return; impossible("Couldn't place lregion type %d!", rtype); } STATIC_OVL boolean -put_lregion_here(x,y,nlx,nly,nhx,nhy,rtype,oneshot,lev) +put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, lev) xchar x, y; xchar nlx, nly, nhx, nhy; xchar rtype; @@ -290,42 +290,46 @@ boolean oneshot; d_level *lev; { if (bad_location(x, y, nlx, nly, nhx, nhy)) { - if (!oneshot) { - return FALSE; /* caller should try again */ - } else { - /* Must make do with the only location possible; - avoid failure due to a misplaced trap. - It might still fail if there's a dungeon feature here. */ - struct trap *t = t_at(x,y); + if (!oneshot) { + return FALSE; /* caller should try again */ + } else { + /* Must make do with the only location possible; + avoid failure due to a misplaced trap. + It might still fail if there's a dungeon feature here. */ + struct trap *t = t_at(x, y); - if (t && t->ttyp != MAGIC_PORTAL) deltrap(t); - if (bad_location(x, y, nlx, nly, nhx, nhy)) return FALSE; - } + if (t && t->ttyp != MAGIC_PORTAL) + deltrap(t); + if (bad_location(x, y, nlx, nly, nhx, nhy)) + return FALSE; + } } switch (rtype) { case LR_TELE: case LR_UPTELE: case LR_DOWNTELE: - /* "something" means the player in this case */ - if(MON_AT(x, y)) { - /* move the monster if no choice, or just try again */ - if(oneshot) (void) rloc(m_at(x,y), FALSE); - else return(FALSE); - } - u_on_newpos(x, y); - break; + /* "something" means the player in this case */ + if (MON_AT(x, y)) { + /* move the monster if no choice, or just try again */ + if (oneshot) + (void) rloc(m_at(x, y), FALSE); + else + return (FALSE); + } + u_on_newpos(x, y); + break; case LR_PORTAL: - mkportal(x, y, lev->dnum, lev->dlevel); - break; + mkportal(x, y, lev->dnum, lev->dlevel); + break; case LR_DOWNSTAIR: case LR_UPSTAIR: - mkstairs(x, y, (char)rtype, (struct mkroom *)0); - break; + mkstairs(x, y, (char) rtype, (struct mkroom *) 0); + break; case LR_BRANCH: - place_branch(Is_branchlev(&u.uz), x, y); - break; + place_branch(Is_branchlev(&u.uz), x, y); + break; } - return(TRUE); + return (TRUE); } static boolean was_waterlevel; /* ugh... this shouldn't be needed */ @@ -341,140 +345,151 @@ fixup_special() boolean added_branch = FALSE; if (was_waterlevel) { - was_waterlevel = FALSE; - u.uinwater = 0; - unsetup_waterlevel(); + was_waterlevel = FALSE; + u.uinwater = 0; + unsetup_waterlevel(); } if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { - level.flags.hero_memory = 0; - was_waterlevel = TRUE; - /* water level is an odd beast - it has to be set up - before calling place_lregions etc. */ - setup_waterlevel(); + level.flags.hero_memory = 0; + was_waterlevel = TRUE; + /* water level is an odd beast - it has to be set up + before calling place_lregions etc. */ + setup_waterlevel(); } - for(x = 0; x < num_lregions; x++, r++) { - switch(r->rtype) { - case LR_BRANCH: - added_branch = TRUE; - goto place_it; + for (x = 0; x < num_lregions; x++, r++) { + switch (r->rtype) { + case LR_BRANCH: + added_branch = TRUE; + goto place_it; - case LR_PORTAL: - if(*r->rname.str >= '0' && *r->rname.str <= '9') { - /* "chutes and ladders" */ - lev = u.uz; - lev.dlevel = atoi(r->rname.str); - } else { - s_level *sp = find_level(r->rname.str); - lev = sp->dlevel; - } - /* fall into... */ + case LR_PORTAL: + if (*r->rname.str >= '0' && *r->rname.str <= '9') { + /* "chutes and ladders" */ + lev = u.uz; + lev.dlevel = atoi(r->rname.str); + } else { + s_level *sp = find_level(r->rname.str); + lev = sp->dlevel; + } + /* fall into... */ - case LR_UPSTAIR: - case LR_DOWNSTAIR: - place_it: - place_lregion(r->inarea.x1, r->inarea.y1, - r->inarea.x2, r->inarea.y2, - r->delarea.x1, r->delarea.y1, - r->delarea.x2, r->delarea.y2, - r->rtype, &lev); - break; + case LR_UPSTAIR: + case LR_DOWNSTAIR: + place_it: + place_lregion(r->inarea.x1, r->inarea.y1, r->inarea.x2, + r->inarea.y2, r->delarea.x1, r->delarea.y1, + r->delarea.x2, r->delarea.y2, r->rtype, &lev); + break; - case LR_TELE: - case LR_UPTELE: - case LR_DOWNTELE: - /* save the region outlines for goto_level() */ - if(r->rtype == LR_TELE || r->rtype == LR_UPTELE) { - updest.lx = r->inarea.x1; updest.ly = r->inarea.y1; - updest.hx = r->inarea.x2; updest.hy = r->inarea.y2; - updest.nlx = r->delarea.x1; updest.nly = r->delarea.y1; - updest.nhx = r->delarea.x2; updest.nhy = r->delarea.y2; - } - if(r->rtype == LR_TELE || r->rtype == LR_DOWNTELE) { - dndest.lx = r->inarea.x1; dndest.ly = r->inarea.y1; - dndest.hx = r->inarea.x2; dndest.hy = r->inarea.y2; - dndest.nlx = r->delarea.x1; dndest.nly = r->delarea.y1; - dndest.nhx = r->delarea.x2; dndest.nhy = r->delarea.y2; - } - /* place_lregion gets called from goto_level() */ - break; - } + case LR_TELE: + case LR_UPTELE: + case LR_DOWNTELE: + /* save the region outlines for goto_level() */ + if (r->rtype == LR_TELE || r->rtype == LR_UPTELE) { + updest.lx = r->inarea.x1; + updest.ly = r->inarea.y1; + updest.hx = r->inarea.x2; + updest.hy = r->inarea.y2; + updest.nlx = r->delarea.x1; + updest.nly = r->delarea.y1; + updest.nhx = r->delarea.x2; + updest.nhy = r->delarea.y2; + } + if (r->rtype == LR_TELE || r->rtype == LR_DOWNTELE) { + dndest.lx = r->inarea.x1; + dndest.ly = r->inarea.y1; + dndest.hx = r->inarea.x2; + dndest.hy = r->inarea.y2; + dndest.nlx = r->delarea.x1; + dndest.nly = r->delarea.y1; + dndest.nhx = r->delarea.x2; + dndest.nhy = r->delarea.y2; + } + /* place_lregion gets called from goto_level() */ + break; + } - if (r->rname.str) free((genericptr_t) r->rname.str), r->rname.str = 0; + if (r->rname.str) + free((genericptr_t) r->rname.str), r->rname.str = 0; } /* place dungeon branch if not placed above */ if (!added_branch && Is_branchlev(&u.uz)) { - place_lregion(0,0,0,0,0,0,0,0,LR_BRANCH,(d_level *)0); + place_lregion(0, 0, 0, 0, 0, 0, 0, 0, LR_BRANCH, (d_level *) 0); } /* Still need to add some stuff to level file */ if (Is_medusa_level(&u.uz)) { - struct obj *otmp; - int tryct; + struct obj *otmp; + int tryct; - croom = &rooms[0]; /* only one room on the medusa level */ - for (tryct = rnd(4); tryct; tryct--) { - x = somex(croom); y = somey(croom); - if (goodpos(x, y, (struct monst *)0, 0)) { - otmp = mk_tt_object(STATUE, x, y); - while (otmp && (poly_when_stoned(&mons[otmp->corpsenm]) || - pm_resistance(&mons[otmp->corpsenm],MR_STONE))) { - /* set_corpsenm() handles weight too */ - set_corpsenm(otmp, rndmonnum()); - } - } - } + croom = &rooms[0]; /* only one room on the medusa level */ + for (tryct = rnd(4); tryct; tryct--) { + x = somex(croom); + y = somey(croom); + if (goodpos(x, y, (struct monst *) 0, 0)) { + otmp = mk_tt_object(STATUE, x, y); + while (otmp && (poly_when_stoned(&mons[otmp->corpsenm]) + || pm_resistance(&mons[otmp->corpsenm], + MR_STONE))) { + /* set_corpsenm() handles weight too */ + set_corpsenm(otmp, rndmonnum()); + } + } + } - if (rn2(2)) - otmp = mk_tt_object(STATUE, somex(croom), somey(croom)); - else /* Medusa statues don't contain books */ - otmp = mkcorpstat(STATUE, (struct monst *)0, (struct permonst *)0, - somex(croom), somey(croom), CORPSTAT_NONE); - if (otmp) { - while (pm_resistance(&mons[otmp->corpsenm],MR_STONE) - || poly_when_stoned(&mons[otmp->corpsenm])) { - /* set_corpsenm() handles weight too */ - set_corpsenm(otmp, rndmonnum()); - } - } - } else if(Is_wiz1_level(&u.uz)) { - croom = search_special(MORGUE); + if (rn2(2)) + otmp = mk_tt_object(STATUE, somex(croom), somey(croom)); + else /* Medusa statues don't contain books */ + otmp = + mkcorpstat(STATUE, (struct monst *) 0, (struct permonst *) 0, + somex(croom), somey(croom), CORPSTAT_NONE); + if (otmp) { + while (pm_resistance(&mons[otmp->corpsenm], MR_STONE) + || poly_when_stoned(&mons[otmp->corpsenm])) { + /* set_corpsenm() handles weight too */ + set_corpsenm(otmp, rndmonnum()); + } + } + } else if (Is_wiz1_level(&u.uz)) { + croom = search_special(MORGUE); - create_secret_door(croom, W_SOUTH|W_EAST|W_WEST); - } else if(Is_knox(&u.uz)) { - /* using an unfilled morgue for rm id */ - croom = search_special(MORGUE); - /* avoid inappropriate morgue-related messages */ - level.flags.graveyard = level.flags.has_morgue = 0; - croom->rtype = OROOM; /* perhaps it should be set to VAULT? */ - /* stock the main vault */ - for(x = croom->lx; x <= croom->hx; x++) - for(y = croom->ly; y <= croom->hy; y++) { - (void) mkgold((long) rn1(300, 600), x, y); - if (!rn2(3) && !is_pool(x,y)) - (void)maketrap(x, y, rn2(3) ? LANDMINE : SPIKED_PIT); - } + create_secret_door(croom, W_SOUTH | W_EAST | W_WEST); + } else if (Is_knox(&u.uz)) { + /* using an unfilled morgue for rm id */ + croom = search_special(MORGUE); + /* avoid inappropriate morgue-related messages */ + level.flags.graveyard = level.flags.has_morgue = 0; + croom->rtype = OROOM; /* perhaps it should be set to VAULT? */ + /* stock the main vault */ + for (x = croom->lx; x <= croom->hx; x++) + for (y = croom->ly; y <= croom->hy; y++) { + (void) mkgold((long) rn1(300, 600), x, y); + if (!rn2(3) && !is_pool(x, y)) + (void) maketrap(x, y, rn2(3) ? LANDMINE : SPIKED_PIT); + } } else if (Role_if(PM_PRIEST) && In_quest(&u.uz)) { - /* less chance for undead corpses (lured from lower morgues) */ - level.flags.graveyard = 1; + /* less chance for undead corpses (lured from lower morgues) */ + level.flags.graveyard = 1; } else if (Is_stronghold(&u.uz)) { - level.flags.graveyard = 1; - } else if(Is_sanctum(&u.uz)) { - croom = search_special(TEMPLE); + level.flags.graveyard = 1; + } else if (Is_sanctum(&u.uz)) { + croom = search_special(TEMPLE); - create_secret_door(croom, W_ANY); - } else if(on_level(&u.uz, &orcus_level)) { - register struct monst *mtmp, *mtmp2; + create_secret_door(croom, W_ANY); + } else if (on_level(&u.uz, &orcus_level)) { + register struct monst *mtmp, *mtmp2; - /* it's a ghost town, get rid of shopkeepers */ - for(mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if(mtmp->isshk) mongone(mtmp); - } + /* it's a ghost town, get rid of shopkeepers */ + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (mtmp->isshk) + mongone(mtmp); + } } if (lregions) - free((genericptr_t) lregions), lregions = 0; + free((genericptr_t) lregions), lregions = 0; num_lregions = 0; } @@ -482,156 +497,160 @@ void makemaz(s) register const char *s; { - int x,y; - char protofile[20]; - s_level *sp = Is_special(&u.uz); - coord mm; + int x, y; + char protofile[20]; + s_level *sp = Is_special(&u.uz); + coord mm; - if(*s) { - if(sp && sp->rndlevs) Sprintf(protofile, "%s-%d", s, - rnd((int) sp->rndlevs)); - else Strcpy(protofile, s); - } else if(*(dungeons[u.uz.dnum].proto)) { - if(dunlevs_in_dungeon(&u.uz) > 1) { - if(sp && sp->rndlevs) - Sprintf(protofile, "%s%d-%d", dungeons[u.uz.dnum].proto, - dunlev(&u.uz), - rnd((int) sp->rndlevs)); - else Sprintf(protofile, "%s%d", dungeons[u.uz.dnum].proto, - dunlev(&u.uz)); - } else if(sp && sp->rndlevs) { - Sprintf(protofile, "%s-%d", dungeons[u.uz.dnum].proto, - rnd((int) sp->rndlevs)); - } else Strcpy(protofile, dungeons[u.uz.dnum].proto); - - } else Strcpy(protofile, ""); - - /* SPLEVTYPE format is "level-choice,level-choice"... */ - if (wizard && *protofile && sp && sp->rndlevs) { - char *ep = getenv("SPLEVTYPE"); /* not nh_getenv */ - if (ep) { - /* rindex always succeeds due to code in prior block */ - int len = (int)((rindex(protofile, '-') - protofile) + 1); - - while (ep && *ep) { - if (!strncmp(ep, protofile, len)) { - int pick = atoi(ep + len); - /* use choice only if valid */ - if (pick > 0 && pick <= (int) sp->rndlevs) - Sprintf(protofile + len, "%d", pick); - break; - } else { - ep = index(ep, ','); - if (ep) ++ep; - } - } - } - } - - if(*protofile) { - Strcat(protofile, LEV_EXT); - if(load_special(protofile)) { - fixup_special(); - /* some levels can end up with monsters - on dead mon list, including light source monsters */ - dmonsfree(); - return; /* no mazification right now */ - } - impossible("Couldn't load \"%s\" - making a maze.", protofile); - } - - level.flags.is_maze_lev = TRUE; - level.flags.corrmaze = !rn2(3); - - if (level.flags.corrmaze) - for(x = 2; x < x_maze_max; x++) - for(y = 2; y < y_maze_max; y++) - levl[x][y].typ = STONE; + if (*s) { + if (sp && sp->rndlevs) + Sprintf(protofile, "%s-%d", s, rnd((int) sp->rndlevs)); else - for(x = 2; x <= x_maze_max; x++) - for(y = 2; y <= y_maze_max; y++) - levl[x][y].typ = ((x % 2) && (y % 2)) ? STONE : HWALL; + Strcpy(protofile, s); + } else if (*(dungeons[u.uz.dnum].proto)) { + if (dunlevs_in_dungeon(&u.uz) > 1) { + if (sp && sp->rndlevs) + Sprintf(protofile, "%s%d-%d", dungeons[u.uz.dnum].proto, + dunlev(&u.uz), rnd((int) sp->rndlevs)); + else + Sprintf(protofile, "%s%d", dungeons[u.uz.dnum].proto, + dunlev(&u.uz)); + } else if (sp && sp->rndlevs) { + Sprintf(protofile, "%s-%d", dungeons[u.uz.dnum].proto, + rnd((int) sp->rndlevs)); + } else + Strcpy(protofile, dungeons[u.uz.dnum].proto); - maze0xy(&mm); - walkfrom((int) mm.x, (int) mm.y, 0); - /* put a boulder at the maze center */ - (void) mksobj_at(BOULDER, (int) mm.x, (int) mm.y, TRUE, FALSE); + } else + Strcpy(protofile, ""); - if (!level.flags.corrmaze) - wallification(2, 2, x_maze_max, y_maze_max); + /* SPLEVTYPE format is "level-choice,level-choice"... */ + if (wizard && *protofile && sp && sp->rndlevs) { + char *ep = getenv("SPLEVTYPE"); /* not nh_getenv */ + if (ep) { + /* rindex always succeeds due to code in prior block */ + int len = (int) ((rindex(protofile, '-') - protofile) + 1); - mazexy(&mm); - mkstairs(mm.x, mm.y, 1, (struct mkroom *)0); /* up */ - if (!Invocation_lev(&u.uz)) { - mazexy(&mm); - mkstairs(mm.x, mm.y, 0, (struct mkroom *)0); /* down */ - } else { /* choose "vibrating square" location */ + while (ep && *ep) { + if (!strncmp(ep, protofile, len)) { + int pick = atoi(ep + len); + /* use choice only if valid */ + if (pick > 0 && pick <= (int) sp->rndlevs) + Sprintf(protofile + len, "%d", pick); + break; + } else { + ep = index(ep, ','); + if (ep) + ++ep; + } + } + } + } + + if (*protofile) { + Strcat(protofile, LEV_EXT); + if (load_special(protofile)) { + fixup_special(); + /* some levels can end up with monsters + on dead mon list, including light source monsters */ + dmonsfree(); + return; /* no mazification right now */ + } + impossible("Couldn't load \"%s\" - making a maze.", protofile); + } + + level.flags.is_maze_lev = TRUE; + level.flags.corrmaze = !rn2(3); + + if (level.flags.corrmaze) + for (x = 2; x < x_maze_max; x++) + for (y = 2; y < y_maze_max; y++) + levl[x][y].typ = STONE; + else + for (x = 2; x <= x_maze_max; x++) + for (y = 2; y <= y_maze_max; y++) + levl[x][y].typ = ((x % 2) && (y % 2)) ? STONE : HWALL; + + maze0xy(&mm); + walkfrom((int) mm.x, (int) mm.y, 0); + /* put a boulder at the maze center */ + (void) mksobj_at(BOULDER, (int) mm.x, (int) mm.y, TRUE, FALSE); + + if (!level.flags.corrmaze) + wallification(2, 2, x_maze_max, y_maze_max); + + mazexy(&mm); + mkstairs(mm.x, mm.y, 1, (struct mkroom *) 0); /* up */ + if (!Invocation_lev(&u.uz)) { + mazexy(&mm); + mkstairs(mm.x, mm.y, 0, (struct mkroom *) 0); /* down */ + } else { /* choose "vibrating square" location */ #define x_maze_min 2 #define y_maze_min 2 - /* - * Pick a position where the stairs down to Moloch's Sanctum - * level will ultimately be created. At that time, an area - * will be altered: walls removed, moat and traps generated, - * boulders destroyed. The position picked here must ensure - * that that invocation area won't extend off the map. - * - * We actually allow up to 2 squares around the usual edge of - * the area to get truncated; see mkinvokearea(mklev.c). - */ +/* + * Pick a position where the stairs down to Moloch's Sanctum + * level will ultimately be created. At that time, an area + * will be altered: walls removed, moat and traps generated, + * boulders destroyed. The position picked here must ensure + * that that invocation area won't extend off the map. + * + * We actually allow up to 2 squares around the usual edge of + * the area to get truncated; see mkinvokearea(mklev.c). + */ #define INVPOS_X_MARGIN (6 - 2) #define INVPOS_Y_MARGIN (5 - 2) #define INVPOS_DISTANCE 11 - int x_range = x_maze_max - x_maze_min - 2*INVPOS_X_MARGIN - 1, - y_range = y_maze_max - y_maze_min - 2*INVPOS_Y_MARGIN - 1; + int x_range = x_maze_max - x_maze_min - 2 * INVPOS_X_MARGIN - 1, + y_range = y_maze_max - y_maze_min - 2 * INVPOS_Y_MARGIN - 1; - if (x_range <= INVPOS_X_MARGIN || y_range <= INVPOS_Y_MARGIN || - (x_range * y_range) <= (INVPOS_DISTANCE * INVPOS_DISTANCE)) - debugpline2("inv_pos: maze is too small! (%d x %d)", - x_maze_max, y_maze_max); - inv_pos.x = inv_pos.y = 0; /*{occupied() => invocation_pos()}*/ - do { - x = rn1(x_range, x_maze_min + INVPOS_X_MARGIN + 1); - y = rn1(y_range, y_maze_min + INVPOS_Y_MARGIN + 1); - /* we don't want it to be too near the stairs, nor - to be on a spot that's already in use (wall|trap) */ - } while (x == xupstair || y == yupstair || /*(direct line)*/ - abs(x - xupstair) == abs(y - yupstair) || - distmin(x, y, xupstair, yupstair) <= INVPOS_DISTANCE || - !SPACE_POS(levl[x][y].typ) || occupied(x, y)); - inv_pos.x = x; - inv_pos.y = y; + if (x_range <= INVPOS_X_MARGIN || y_range <= INVPOS_Y_MARGIN + || (x_range * y_range) <= (INVPOS_DISTANCE * INVPOS_DISTANCE)) + debugpline2("inv_pos: maze is too small! (%d x %d)", x_maze_max, + y_maze_max); + inv_pos.x = inv_pos.y = 0; /*{occupied() => invocation_pos()}*/ + do { + x = rn1(x_range, x_maze_min + INVPOS_X_MARGIN + 1); + y = rn1(y_range, y_maze_min + INVPOS_Y_MARGIN + 1); + /* we don't want it to be too near the stairs, nor + to be on a spot that's already in use (wall|trap) */ + } while (x == xupstair || y == yupstair || /*(direct line)*/ + abs(x - xupstair) == abs(y - yupstair) + || distmin(x, y, xupstair, yupstair) <= INVPOS_DISTANCE + || !SPACE_POS(levl[x][y].typ) || occupied(x, y)); + inv_pos.x = x; + inv_pos.y = y; #undef INVPOS_X_MARGIN #undef INVPOS_Y_MARGIN #undef INVPOS_DISTANCE #undef x_maze_min #undef y_maze_min - } + } - /* place branch stair or portal */ - place_branch(Is_branchlev(&u.uz), 0, 0); + /* place branch stair or portal */ + place_branch(Is_branchlev(&u.uz), 0, 0); - for(x = rn1(8,11); x; x--) { - mazexy(&mm); - (void) mkobj_at(rn2(2) ? GEM_CLASS : 0, mm.x, mm.y, TRUE); - } - for(x = rn1(10,2); x; x--) { - mazexy(&mm); - (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE); - } - for (x = rn2(3); x; x--) { - mazexy(&mm); - (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS); - } - for(x = rn1(5,7); x; x--) { - mazexy(&mm); - (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS); - } - for(x = rn1(6,7); x; x--) { - mazexy(&mm); - (void) mkgold(0L,mm.x,mm.y); - } - for(x = rn1(6,7); x; x--) - mktrap(0,1,(struct mkroom *) 0, (coord*) 0); + for (x = rn1(8, 11); x; x--) { + mazexy(&mm); + (void) mkobj_at(rn2(2) ? GEM_CLASS : 0, mm.x, mm.y, TRUE); + } + for (x = rn1(10, 2); x; x--) { + mazexy(&mm); + (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE); + } + for (x = rn2(3); x; x--) { + mazexy(&mm); + (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS); + } + for (x = rn1(5, 7); x; x--) { + mazexy(&mm); + (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS); + } + for (x = rn1(6, 7); x; x--) { + mazexy(&mm); + (void) mkgold(0L, mm.x, mm.y); + } + for (x = rn1(6, 7); x; x--) + mktrap(0, 1, (struct mkroom *) 0, (coord *) 0); } #ifdef MICRO @@ -641,128 +660,141 @@ register const char *s; * that is totally safe. */ void -walkfrom(x,y,typ) -int x,y; +walkfrom(x, y, typ) +int x, y; schar typ; { -#define CELLS (ROWNO * COLNO) / 4 /* a maze cell is 4 squares */ - char mazex[CELLS + 1], mazey[CELLS + 1]; /* char's are OK */ - int q, a, dir, pos; - int dirs[4]; +#define CELLS (ROWNO * COLNO) / 4 /* a maze cell is 4 squares */ + char mazex[CELLS + 1], mazey[CELLS + 1]; /* char's are OK */ + int q, a, dir, pos; + int dirs[4]; - if (!typ) { - if (level.flags.corrmaze) - typ = CORR; - else - typ = ROOM; + if (!typ) { + if (level.flags.corrmaze) + typ = CORR; + else + typ = ROOM; + } + + pos = 1; + mazex[pos] = (char) x; + mazey[pos] = (char) y; + while (pos) { + x = (int) mazex[pos]; + y = (int) mazey[pos]; + if (!IS_DOOR(levl[x][y].typ)) { + /* might still be on edge of MAP, so don't overwrite */ + levl[x][y].typ = typ; + levl[x][y].flags = 0; } - - pos = 1; - mazex[pos] = (char) x; - mazey[pos] = (char) y; - while (pos) { - x = (int) mazex[pos]; - y = (int) mazey[pos]; - if(!IS_DOOR(levl[x][y].typ)) { - /* might still be on edge of MAP, so don't overwrite */ - levl[x][y].typ = typ; - levl[x][y].flags = 0; - } - q = 0; - for (a = 0; a < 4; a++) - if(okay(x, y, a)) dirs[q++]= a; - if (!q) - pos--; - else { - dir = dirs[rn2(q)]; - move(&x, &y, dir); - levl[x][y].typ = typ; - move(&x, &y, dir); - pos++; - if (pos > CELLS) - panic("Overflow in walkfrom"); - mazex[pos] = (char) x; - mazey[pos] = (char) y; - } - } + q = 0; + for (a = 0; a < 4; a++) + if (okay(x, y, a)) + dirs[q++] = a; + if (!q) + pos--; + else { + dir = dirs[rn2(q)]; + move(&x, &y, dir); + levl[x][y].typ = typ; + move(&x, &y, dir); + pos++; + if (pos > CELLS) + panic("Overflow in walkfrom"); + mazex[pos] = (char) x; + mazey[pos] = (char) y; + } + } } #else void -walkfrom(x,y,typ) -int x,y; +walkfrom(x, y, typ) +int x, y; schar typ; { - register int q,a,dir; - int dirs[4]; + register int q, a, dir; + int dirs[4]; - if (!typ) { - if (level.flags.corrmaze) - typ = CORR; - else - typ = ROOM; - } + if (!typ) { + if (level.flags.corrmaze) + typ = CORR; + else + typ = ROOM; + } - if(!IS_DOOR(levl[x][y].typ)) { - /* might still be on edge of MAP, so don't overwrite */ - levl[x][y].typ = typ; - levl[x][y].flags = 0; - } + if (!IS_DOOR(levl[x][y].typ)) { + /* might still be on edge of MAP, so don't overwrite */ + levl[x][y].typ = typ; + levl[x][y].flags = 0; + } - while(1) { - q = 0; - for(a = 0; a < 4; a++) - if(okay(x,y,a)) dirs[q++]= a; - if(!q) return; - dir = dirs[rn2(q)]; - move(&x,&y,dir); - levl[x][y].typ = typ; - move(&x,&y,dir); - walkfrom(x,y,typ); - } + while (1) { + q = 0; + for (a = 0; a < 4; a++) + if (okay(x, y, a)) + dirs[q++] = a; + if (!q) + return; + dir = dirs[rn2(q)]; + move(&x, &y, dir); + levl[x][y].typ = typ; + move(&x, &y, dir); + walkfrom(x, y, typ); + } } #endif /* MICRO */ STATIC_OVL void -move(x,y,dir) +move(x, y, dir) register int *x, *y; register int dir; { - switch(dir){ - case 0: --(*y); break; - case 1: (*x)++; break; - case 2: (*y)++; break; - case 3: --(*x); break; - default: panic("move: bad direction"); - } + switch (dir) { + case 0: + --(*y); + break; + case 1: + (*x)++; + break; + case 2: + (*y)++; + break; + case 3: + --(*x); + break; + default: + panic("move: bad direction"); + } } -void -mazexy(cc) /* find random point in generated corridors, - so we don't create items in moats, bunkers, or walls */ - coord *cc; +void mazexy(cc) /* find random point in generated corridors, + so we don't create items in moats, bunkers, or walls */ +coord *cc; { - int cpt=0; + int cpt = 0; - do { - cc->x = 3 + 2*rn2((x_maze_max>>1) - 1); - cc->y = 3 + 2*rn2((y_maze_max>>1) - 1); - cpt++; - } while (cpt < 100 && - levl[cc->x][cc->y].typ != (level.flags.corrmaze ? CORR : ROOM)); - if (cpt >= 100) { - register int x, y; - /* last try */ - for (x = 0; x < (x_maze_max>>1) - 1; x++) - for (y = 0; y < (y_maze_max>>1) - 1; y++) { - cc->x = 3 + 2 * x; - cc->y = 3 + 2 * y; - if (levl[cc->x][cc->y].typ == (level.flags.corrmaze ? CORR : ROOM)) - return; - } - panic("mazexy: can't find a place!"); - } - return; + do { + cc->x = 3 + 2 * rn2((x_maze_max >> 1) - 1); + cc->y = 3 + 2 * rn2((y_maze_max >> 1) - 1); + cpt++; + } while (cpt < 100 + && levl[cc->x][cc->y].typ + != (level.flags.corrmaze ? CORR : ROOM)); + if (cpt >= 100) { + register int x, y; + /* last try */ + for (x = 0; x < (x_maze_max >> 1) - 1; x++) + for (y = 0; y < (y_maze_max >> 1) - 1; y++) { + cc->x = 3 + 2 * x; + cc->y = 3 + 2 * y; + if (levl[cc->x][cc->y].typ + == (level.flags.corrmaze ? CORR : ROOM)) + return; + } + panic("mazexy: can't find a place!"); + } + return; } void @@ -778,97 +810,104 @@ bound_digging() * that provides a window of abuse for wallified special levels */ { - register int x,y; - register unsigned typ; - register struct rm *lev; - boolean found, nonwall; - int xmin,xmax,ymin,ymax; + register int x, y; + register unsigned typ; + register struct rm *lev; + boolean found, nonwall; + int xmin, xmax, ymin, ymax; - if(Is_earthlevel(&u.uz)) return; /* everything diggable here */ + if (Is_earthlevel(&u.uz)) + return; /* everything diggable here */ - found = nonwall = FALSE; - for(xmin=0; !found; xmin++) { - lev = &levl[xmin][0]; - for(y=0; y<=ROWNO-1; y++, lev++) { - typ = lev->typ; - if(typ != STONE) { - found = TRUE; - if(!IS_WALL(typ)) nonwall = TRUE; - } - } - } - xmin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; - if (xmin < 0) xmin = 0; + found = nonwall = FALSE; + for (xmin = 0; !found; xmin++) { + lev = &levl[xmin][0]; + for (y = 0; y <= ROWNO - 1; y++, lev++) { + typ = lev->typ; + if (typ != STONE) { + found = TRUE; + if (!IS_WALL(typ)) + nonwall = TRUE; + } + } + } + xmin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; + if (xmin < 0) + xmin = 0; - found = nonwall = FALSE; - for(xmax=COLNO-1; !found; xmax--) { - lev = &levl[xmax][0]; - for(y=0; y<=ROWNO-1; y++, lev++) { - typ = lev->typ; - if(typ != STONE) { - found = TRUE; - if(!IS_WALL(typ)) nonwall = TRUE; - } - } - } - xmax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; - if (xmax >= COLNO) xmax = COLNO-1; + found = nonwall = FALSE; + for (xmax = COLNO - 1; !found; xmax--) { + lev = &levl[xmax][0]; + for (y = 0; y <= ROWNO - 1; y++, lev++) { + typ = lev->typ; + if (typ != STONE) { + found = TRUE; + if (!IS_WALL(typ)) + nonwall = TRUE; + } + } + } + xmax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; + if (xmax >= COLNO) + xmax = COLNO - 1; - found = nonwall = FALSE; - for(ymin=0; !found; ymin++) { - lev = &levl[xmin][ymin]; - for(x=xmin; x<=xmax; x++, lev += ROWNO) { - typ = lev->typ; - if(typ != STONE) { - found = TRUE; - if(!IS_WALL(typ)) nonwall = TRUE; - } - } - } - ymin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; + found = nonwall = FALSE; + for (ymin = 0; !found; ymin++) { + lev = &levl[xmin][ymin]; + for (x = xmin; x <= xmax; x++, lev += ROWNO) { + typ = lev->typ; + if (typ != STONE) { + found = TRUE; + if (!IS_WALL(typ)) + nonwall = TRUE; + } + } + } + ymin -= (nonwall || !level.flags.is_maze_lev) ? 2 : 1; - found = nonwall = FALSE; - for(ymax=ROWNO-1; !found; ymax--) { - lev = &levl[xmin][ymax]; - for(x=xmin; x<=xmax; x++, lev += ROWNO) { - typ = lev->typ; - if(typ != STONE) { - found = TRUE; - if(!IS_WALL(typ)) nonwall = TRUE; - } - } - } - ymax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; + found = nonwall = FALSE; + for (ymax = ROWNO - 1; !found; ymax--) { + lev = &levl[xmin][ymax]; + for (x = xmin; x <= xmax; x++, lev += ROWNO) { + typ = lev->typ; + if (typ != STONE) { + found = TRUE; + if (!IS_WALL(typ)) + nonwall = TRUE; + } + } + } + ymax += (nonwall || !level.flags.is_maze_lev) ? 2 : 1; - for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (y <= ymin || y >= ymax || x <= xmin || x >= xmax) { + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + if (y <= ymin || y >= ymax || x <= xmin || x >= xmax) { #ifdef DCC30_BUG - lev = &levl[x][y]; - lev->wall_info |= W_NONDIGGABLE; + lev = &levl[x][y]; + lev->wall_info |= W_NONDIGGABLE; #else - levl[x][y].wall_info |= W_NONDIGGABLE; + levl[x][y].wall_info |= W_NONDIGGABLE; #endif - } + } } void mkportal(x, y, todnum, todlevel) register xchar x, y, todnum, todlevel; { - /* a portal "trap" must be matched by a */ - /* portal in the destination dungeon/dlevel */ - register struct trap *ttmp = maketrap(x, y, MAGIC_PORTAL); + /* a portal "trap" must be matched by a */ + /* portal in the destination dungeon/dlevel */ + register struct trap *ttmp = maketrap(x, y, MAGIC_PORTAL); - if (!ttmp) { - impossible("portal on top of portal??"); - return; - } - debugpline4("mkportal: at <%d,%d>, to %s, level %d", - x, y, dungeons[todnum].dname, todlevel); - ttmp->dst.dnum = todnum; - ttmp->dst.dlevel = todlevel; - return; + if (!ttmp) { + impossible("portal on top of portal??"); + return; + } + debugpline4("mkportal: at <%d,%d>, to %s, level %d", x, y, + dungeons[todnum].dname, todlevel); + ttmp->dst.dnum = todnum; + ttmp->dst.dlevel = todlevel; + return; } void @@ -876,18 +915,19 @@ fumaroles() { xchar n; boolean snd = FALSE, loud = FALSE; - for (n = rn2(3)+2; n; n--) { - xchar x = rn1(COLNO-4,3); - xchar y = rn1(ROWNO-4,3); - if (levl[x][y].typ == LAVAPOOL) { - NhRegion *r = create_gas_cloud(x,y, 4+rn2(5), rn1(10,5)); - clear_heros_fault(r); - snd = TRUE; - if (distu(x,y) < 15) loud = TRUE; - } + for (n = rn2(3) + 2; n; n--) { + xchar x = rn1(COLNO - 4, 3); + xchar y = rn1(ROWNO - 4, 3); + if (levl[x][y].typ == LAVAPOOL) { + NhRegion *r = create_gas_cloud(x, y, 4 + rn2(5), rn1(10, 5)); + clear_heros_fault(r); + snd = TRUE; + if (distu(x, y) < 15) + loud = TRUE; + } } if (snd && !Deaf) - Norep("You hear a %swhoosh!", loud ? "loud " : ""); + Norep("You hear a %swhoosh!", loud ? "loud " : ""); } /* @@ -900,15 +940,15 @@ fumaroles() /* to ease the work of debuggers at this stage */ #define register -#define CONS_OBJ 0 -#define CONS_MON 1 -#define CONS_HERO 2 -#define CONS_TRAP 3 +#define CONS_OBJ 0 +#define CONS_MON 1 +#define CONS_HERO 2 +#define CONS_TRAP 3 static struct bubble *bbubbles, *ebubbles; static struct trap *wportal; -static int xmin, ymin, xmax, ymax; /* level boundaries */ +static int xmin, ymin, xmax, ymax; /* level boundaries */ /* bubble movement boundaries */ #define bxmin (xmin + 1) #define bymin (ymin + 1) @@ -916,376 +956,388 @@ static int xmin, ymin, xmax, ymax; /* level boundaries */ #define bymax (ymax - 1) STATIC_DCL void NDECL(set_wportal); -STATIC_DCL void FDECL(mk_bubble, (int,int,int)); -STATIC_DCL void FDECL(mv_bubble, (struct bubble *,int,int,BOOLEAN_P)); +STATIC_DCL void FDECL(mk_bubble, (int, int, int)); +STATIC_DCL void FDECL(mv_bubble, (struct bubble *, int, int, BOOLEAN_P)); void movebubbles() { - static boolean up; - register struct bubble *b; - register int x, y, i, j; - struct trap *btrap; - static const struct rm water_pos = - { cmap_to_glyph(S_water), WATER, 0, 0, 0, 0, 0, 0, 0, 0 }; - static const struct rm air_pos = - { cmap_to_glyph(S_cloud), AIR, 0, 0, 0, 1, 0, 0, 0, 0 }; + static boolean up; + register struct bubble *b; + register int x, y, i, j; + struct trap *btrap; + static const struct rm water_pos = { cmap_to_glyph(S_water), WATER, 0, 0, + 0, 0, 0, 0, 0, 0 }; + static const struct rm air_pos = { cmap_to_glyph(S_cloud), AIR, 0, 0, 0, + 1, 0, 0, 0, 0 }; - /* set up the portal the first time bubbles are moved */ - if (!wportal) set_wportal(); + /* set up the portal the first time bubbles are moved */ + if (!wportal) + set_wportal(); - vision_recalc(2); + vision_recalc(2); - if (Is_waterlevel(&u.uz)) { + if (Is_waterlevel(&u.uz)) { + /* keep attached ball&chain separate from bubble objects */ + if (Punished) + unplacebc(); - /* keep attached ball&chain separate from bubble objects */ - if (Punished) unplacebc(); + /* + * Pick up everything inside of a bubble then fill all bubble + * locations. + */ - /* - * Pick up everything inside of a bubble then fill all bubble - * locations. - */ + for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + if (b->cons) + panic("movebubbles: cons != null"); + for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) + for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) + if (b->bm[j + 2] & (1 << i)) { + if (!isok(x, y)) { + impossible("movebubbles: bad pos (%d,%d)", x, y); + continue; + } - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { - if (b->cons) panic("movebubbles: cons != null"); - for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) - for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) - if (b->bm[j + 2] & (1 << i)) { - if (!isok(x,y)) { - impossible("movebubbles: bad pos (%d,%d)", x,y); - continue; - } + /* pick up objects, monsters, hero, and traps */ + if (OBJ_AT(x, y)) { + struct obj *olist = (struct obj *) 0, *otmp; + struct container *cons = + (struct container *) alloc( + sizeof(struct container)); - /* pick up objects, monsters, hero, and traps */ - if (OBJ_AT(x,y)) { - struct obj *olist = (struct obj *) 0, *otmp; - struct container *cons = (struct container *) - alloc(sizeof(struct container)); + while ((otmp = level.objects[x][y]) != 0) { + remove_object(otmp); + otmp->ox = otmp->oy = 0; + otmp->nexthere = olist; + olist = otmp; + } - while ((otmp = level.objects[x][y]) != 0) { - remove_object(otmp); - otmp->ox = otmp->oy = 0; - otmp->nexthere = olist; - olist = otmp; - } + cons->x = x; + cons->y = y; + cons->what = CONS_OBJ; + cons->list = (genericptr_t) olist; + cons->next = b->cons; + b->cons = cons; + } + if (MON_AT(x, y)) { + struct monst *mon = m_at(x, y); + struct container *cons = + (struct container *) alloc( + sizeof(struct container)); - cons->x = x; - cons->y = y; - cons->what = CONS_OBJ; - cons->list = (genericptr_t) olist; - cons->next = b->cons; - b->cons = cons; - } - if (MON_AT(x,y)) { - struct monst *mon = m_at(x,y); - struct container *cons = (struct container *) - alloc(sizeof(struct container)); + cons->x = x; + cons->y = y; + cons->what = CONS_MON; + cons->list = (genericptr_t) mon; - cons->x = x; - cons->y = y; - cons->what = CONS_MON; - cons->list = (genericptr_t) mon; + cons->next = b->cons; + b->cons = cons; - cons->next = b->cons; - b->cons = cons; + if (mon->wormno) + remove_worm(mon); + else + remove_monster(x, y); - if(mon->wormno) - remove_worm(mon); - else - remove_monster(x, y); + newsym(x, y); /* clean up old position */ + mon->mx = mon->my = 0; + } + if (!u.uswallow && x == u.ux && y == u.uy) { + struct container *cons = + (struct container *) alloc( + sizeof(struct container)); - newsym(x,y); /* clean up old position */ - mon->mx = mon->my = 0; - } - if (!u.uswallow && x == u.ux && y == u.uy) { - struct container *cons = (struct container *) - alloc(sizeof(struct container)); + cons->x = x; + cons->y = y; + cons->what = CONS_HERO; + cons->list = (genericptr_t) 0; - cons->x = x; - cons->y = y; - cons->what = CONS_HERO; - cons->list = (genericptr_t) 0; + cons->next = b->cons; + b->cons = cons; + } + if ((btrap = t_at(x, y)) != 0) { + struct container *cons = + (struct container *) alloc( + sizeof(struct container)); - cons->next = b->cons; - b->cons = cons; - } - if ((btrap = t_at(x,y)) != 0) { - struct container *cons = (struct container *) - alloc(sizeof(struct container)); + cons->x = x; + cons->y = y; + cons->what = CONS_TRAP; + cons->list = (genericptr_t) btrap; - cons->x = x; - cons->y = y; - cons->what = CONS_TRAP; - cons->list = (genericptr_t) btrap; + cons->next = b->cons; + b->cons = cons; + } - cons->next = b->cons; - b->cons = cons; - } + levl[x][y] = water_pos; + block_point(x, y); + } + } + } else if (Is_airlevel(&u.uz)) { + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) { + levl[x][y] = air_pos; + unblock_point(x, y); + } + } - levl[x][y] = water_pos; - block_point(x,y); - } - } - } else if (Is_airlevel(&u.uz)) { - for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) { - levl[x][y] = air_pos; - unblock_point(x,y); - } - } + /* + * Every second time traverse down. This is because otherwise + * all the junk that changes owners when bubbles overlap + * would eventually end up in the last bubble in the chain. + */ - /* - * Every second time traverse down. This is because otherwise - * all the junk that changes owners when bubbles overlap - * would eventually end up in the last bubble in the chain. - */ + up = !up; + for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { + register int rx = rn2(3), ry = rn2(3); - up = !up; - for (b = up ? bbubbles : ebubbles; b; b = up ? b->next : b->prev) { - register int rx = rn2(3), ry = rn2(3); + mv_bubble(b, b->dx + 1 - (!b->dx ? rx : (rx ? 1 : 0)), + b->dy + 1 - (!b->dy ? ry : (ry ? 1 : 0)), FALSE); + } - mv_bubble(b,b->dx + 1 - (!b->dx ? rx : (rx ? 1 : 0)), - b->dy + 1 - (!b->dy ? ry : (ry ? 1 : 0)), - FALSE); - } - - /* put attached ball&chain back */ - if (Is_waterlevel(&u.uz) && Punished) placebc(); - vision_full_recalc = 1; + /* put attached ball&chain back */ + if (Is_waterlevel(&u.uz) && Punished) + placebc(); + vision_full_recalc = 1; } /* when moving in water, possibly (1 in 3) alter the intended destination */ void water_friction() { - register int x, y, dx, dy; - register boolean eff = FALSE; + register int x, y, dx, dy; + register boolean eff = FALSE; - if (Swimming && rn2(4)) - return; /* natural swimmers have advantage */ + if (Swimming && rn2(4)) + return; /* natural swimmers have advantage */ - if (u.dx && !rn2(!u.dy ? 3 : 6)) { /* 1/3 chance or half that */ - /* cancel delta x and choose an arbitrary delta y value */ - x = u.ux; - do { - dy = rn2(3) - 1; /* -1, 0, 1 */ - y = u.uy + dy; - } while (dy && (!isok(x,y) || !is_pool(x,y))); - u.dx = 0; - u.dy = dy; - eff = TRUE; - } else if (u.dy && !rn2(!u.dx ? 3 : 5)) { /* 1/3 or 1/5*(5/6) */ - /* cancel delta y and choose an arbitrary delta x value */ - y = u.uy; - do { - dx = rn2(3) - 1; /* -1 .. 1 */ - x = u.ux + dx; - } while (dx && (!isok(x,y) || !is_pool(x,y))); - u.dy = 0; - u.dx = dx; - eff = TRUE; - } - if (eff) pline("Water turbulence affects your movements."); + if (u.dx && !rn2(!u.dy ? 3 : 6)) { /* 1/3 chance or half that */ + /* cancel delta x and choose an arbitrary delta y value */ + x = u.ux; + do { + dy = rn2(3) - 1; /* -1, 0, 1 */ + y = u.uy + dy; + } while (dy && (!isok(x, y) || !is_pool(x, y))); + u.dx = 0; + u.dy = dy; + eff = TRUE; + } else if (u.dy && !rn2(!u.dx ? 3 : 5)) { /* 1/3 or 1/5*(5/6) */ + /* cancel delta y and choose an arbitrary delta x value */ + y = u.uy; + do { + dx = rn2(3) - 1; /* -1 .. 1 */ + x = u.ux + dx; + } while (dx && (!isok(x, y) || !is_pool(x, y))); + u.dy = 0; + u.dx = dx; + eff = TRUE; + } + if (eff) + pline("Water turbulence affects your movements."); } void save_waterlevel(fd, mode) int fd, mode; { - register struct bubble *b; + register struct bubble *b; - if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) return; + if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) + return; - if (perform_bwrite(mode)) { - int n = 0; - for (b = bbubbles; b; b = b->next) ++n; - bwrite(fd, (genericptr_t)&n, sizeof (int)); - bwrite(fd, (genericptr_t)&xmin, sizeof (int)); - bwrite(fd, (genericptr_t)&ymin, sizeof (int)); - bwrite(fd, (genericptr_t)&xmax, sizeof (int)); - bwrite(fd, (genericptr_t)&ymax, sizeof (int)); - for (b = bbubbles; b; b = b->next) - bwrite(fd, (genericptr_t)b, sizeof (struct bubble)); - } - if (release_data(mode)) - unsetup_waterlevel(); + if (perform_bwrite(mode)) { + int n = 0; + for (b = bbubbles; b; b = b->next) + ++n; + bwrite(fd, (genericptr_t) &n, sizeof(int)); + bwrite(fd, (genericptr_t) &xmin, sizeof(int)); + bwrite(fd, (genericptr_t) &ymin, sizeof(int)); + bwrite(fd, (genericptr_t) &xmax, sizeof(int)); + bwrite(fd, (genericptr_t) &ymax, sizeof(int)); + for (b = bbubbles; b; b = b->next) + bwrite(fd, (genericptr_t) b, sizeof(struct bubble)); + } + if (release_data(mode)) + unsetup_waterlevel(); } void restore_waterlevel(fd) register int fd; { - register struct bubble *b = (struct bubble *)0, *btmp; - register int i; - int n; + register struct bubble *b = (struct bubble *) 0, *btmp; + register int i; + int n; - if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) return; + if (!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz)) + return; - set_wportal(); - mread(fd,(genericptr_t)&n,sizeof(int)); - mread(fd,(genericptr_t)&xmin,sizeof(int)); - mread(fd,(genericptr_t)&ymin,sizeof(int)); - mread(fd,(genericptr_t)&xmax,sizeof(int)); - mread(fd,(genericptr_t)&ymax,sizeof(int)); - for (i = 0; i < n; i++) { - btmp = b; - b = (struct bubble *)alloc(sizeof(struct bubble)); - mread(fd,(genericptr_t)b,sizeof(struct bubble)); - if (bbubbles) { - btmp->next = b; - b->prev = btmp; - } else { - bbubbles = b; - b->prev = (struct bubble *)0; - } - mv_bubble(b,0,0,TRUE); - } - ebubbles = b; - b->next = (struct bubble *)0; - was_waterlevel = TRUE; + set_wportal(); + mread(fd, (genericptr_t) &n, sizeof(int)); + mread(fd, (genericptr_t) &xmin, sizeof(int)); + mread(fd, (genericptr_t) &ymin, sizeof(int)); + mread(fd, (genericptr_t) &xmax, sizeof(int)); + mread(fd, (genericptr_t) &ymax, sizeof(int)); + for (i = 0; i < n; i++) { + btmp = b; + b = (struct bubble *) alloc(sizeof(struct bubble)); + mread(fd, (genericptr_t) b, sizeof(struct bubble)); + if (bbubbles) { + btmp->next = b; + b->prev = btmp; + } else { + bbubbles = b; + b->prev = (struct bubble *) 0; + } + mv_bubble(b, 0, 0, TRUE); + } + ebubbles = b; + b->next = (struct bubble *) 0; + was_waterlevel = TRUE; } const char * waterbody_name(x, y) -xchar x,y; +xchar x, y; { - register struct rm *lev; - schar ltyp; + register struct rm *lev; + schar ltyp; - if (!isok(x,y)) - return "drink"; /* should never happen */ - lev = &levl[x][y]; - ltyp = lev->typ; - if (ltyp == DRAWBRIDGE_UP) - ltyp = db_under_typ(lev->drawbridgemask); + if (!isok(x, y)) + return "drink"; /* should never happen */ + lev = &levl[x][y]; + ltyp = lev->typ; + if (ltyp == DRAWBRIDGE_UP) + ltyp = db_under_typ(lev->drawbridgemask); - if (ltyp == LAVAPOOL) - return "lava"; - else if (ltyp == ICE) - return "ice"; - else if (ltyp == POOL) - return "pool of water"; - else if (ltyp == WATER || Is_waterlevel(&u.uz)) - ; /* fall through to default return value */ - else if (Is_juiblex_level(&u.uz)) - return "swamp"; - else if (ltyp == MOAT && !Is_medusa_level(&u.uz)) - return "moat"; + if (ltyp == LAVAPOOL) + return "lava"; + else if (ltyp == ICE) + return "ice"; + else if (ltyp == POOL) + return "pool of water"; + else if (ltyp == WATER || Is_waterlevel(&u.uz)) + ; /* fall through to default return value */ + else if (Is_juiblex_level(&u.uz)) + return "swamp"; + else if (ltyp == MOAT && !Is_medusa_level(&u.uz)) + return "moat"; - return "water"; + return "water"; } STATIC_OVL void set_wportal() { - /* there better be only one magic portal on water level... */ - for (wportal = ftrap; wportal; wportal = wportal->ntrap) - if (wportal->ttyp == MAGIC_PORTAL) return; - impossible("set_wportal(): no portal!"); + /* there better be only one magic portal on water level... */ + for (wportal = ftrap; wportal; wportal = wportal->ntrap) + if (wportal->ttyp == MAGIC_PORTAL) + return; + impossible("set_wportal(): no portal!"); } STATIC_OVL void setup_waterlevel() { - register int x, y; - register int xskip, yskip; - register int water_glyph = cmap_to_glyph(S_water); - register int air_glyph = cmap_to_glyph(S_air); + register int x, y; + register int xskip, yskip; + register int water_glyph = cmap_to_glyph(S_water); + register int air_glyph = cmap_to_glyph(S_air); - /* ouch, hardcoded... */ + /* ouch, hardcoded... */ - xmin = 3; - ymin = 1; - xmax = 78; - ymax = 20; + xmin = 3; + ymin = 1; + xmax = 78; + ymax = 20; - /* set hero's memory to water */ + /* set hero's memory to water */ - for (x = xmin; x <= xmax; x++) - for (y = ymin; y <= ymax; y++) - levl[x][y].glyph = Is_waterlevel(&u.uz) ? water_glyph : air_glyph; + for (x = xmin; x <= xmax; x++) + for (y = ymin; y <= ymax; y++) + levl[x][y].glyph = Is_waterlevel(&u.uz) ? water_glyph : air_glyph; - /* make bubbles */ + /* make bubbles */ - if (Is_waterlevel(&u.uz)) { - xskip = 10 + rn2(10); - yskip = 4 + rn2(4); - } else { - xskip = 6 + rn2(4); - yskip = 3 + rn2(3); - } + if (Is_waterlevel(&u.uz)) { + xskip = 10 + rn2(10); + yskip = 4 + rn2(4); + } else { + xskip = 6 + rn2(4); + yskip = 3 + rn2(3); + } - for (x = bxmin; x <= bxmax; x += xskip) - for (y = bymin; y <= bymax; y += yskip) - mk_bubble(x,y,rn2(7)); + for (x = bxmin; x <= bxmax; x += xskip) + for (y = bymin; y <= bymax; y += yskip) + mk_bubble(x, y, rn2(7)); } STATIC_OVL void unsetup_waterlevel() { - register struct bubble *b, *bb; + register struct bubble *b, *bb; - /* free bubbles */ + /* free bubbles */ - for (b = bbubbles; b; b = bb) { - bb = b->next; - free((genericptr_t)b); - } - bbubbles = ebubbles = (struct bubble *)0; + for (b = bbubbles; b; b = bb) { + bb = b->next; + free((genericptr_t) b); + } + bbubbles = ebubbles = (struct bubble *) 0; } STATIC_OVL void -mk_bubble(x,y,n) +mk_bubble(x, y, n) register int x, y, n; { - /* - * These bit masks make visually pleasing bubbles on a normal aspect - * 25x80 terminal, which naturally results in them being mathematically - * anything but symmetric. For this reason they cannot be computed - * in situ, either. The first two elements tell the dimensions of - * the bubble's bounding box. - */ - static uchar - bm2[] = {2,1,0x3}, - bm3[] = {3,2,0x7,0x7}, - bm4[] = {4,3,0x6,0xf,0x6}, - bm5[] = {5,3,0xe,0x1f,0xe}, - bm6[] = {6,4,0x1e,0x3f,0x3f,0x1e}, - bm7[] = {7,4,0x3e,0x7f,0x7f,0x3e}, - bm8[] = {8,4,0x7e,0xff,0xff,0x7e}, - *bmask[] = {bm2,bm3,bm4,bm5,bm6,bm7,bm8}; + /* + * These bit masks make visually pleasing bubbles on a normal aspect + * 25x80 terminal, which naturally results in them being mathematically + * anything but symmetric. For this reason they cannot be computed + * in situ, either. The first two elements tell the dimensions of + * the bubble's bounding box. + */ + static uchar bm2[] = { 2, 1, 0x3 }, bm3[] = { 3, 2, 0x7, 0x7 }, + bm4[] = { 4, 3, 0x6, 0xf, 0x6 }, + bm5[] = { 5, 3, 0xe, 0x1f, 0xe }, + bm6[] = { 6, 4, 0x1e, 0x3f, 0x3f, 0x1e }, + bm7[] = { 7, 4, 0x3e, 0x7f, 0x7f, 0x3e }, + bm8[] = { 8, 4, 0x7e, 0xff, 0xff, 0x7e }, + *bmask[] = { bm2, bm3, bm4, bm5, bm6, bm7, bm8 }; - register struct bubble *b; + register struct bubble *b; - if (x >= bxmax || y >= bymax) return; - if (n >= SIZE(bmask)) { - impossible("n too large (mk_bubble)"); - n = SIZE(bmask) - 1; - } - if (bmask[n][1] > MAX_BMASK) { - panic("bmask size is larger than MAX_BMASK"); - } - b = (struct bubble *)alloc(sizeof(struct bubble)); - if ((x + (int) bmask[n][0] - 1) > bxmax) x = bxmax - bmask[n][0] + 1; - if ((y + (int) bmask[n][1] - 1) > bymax) y = bymax - bmask[n][1] + 1; - b->x = x; - b->y = y; - b->dx = 1 - rn2(3); - b->dy = 1 - rn2(3); - /* y dimension is the length of bitmap data - see bmask above */ - (void)memcpy((genericptr_t)b->bm, (genericptr_t)bmask[n], - (bmask[n][1]+2)*sizeof(b->bm[0])); - b->cons = 0; - if (!bbubbles) bbubbles = b; - if (ebubbles) { - ebubbles->next = b; - b->prev = ebubbles; - } - else - b->prev = (struct bubble *)0; - b->next = (struct bubble *)0; - ebubbles = b; - mv_bubble(b,0,0,TRUE); + if (x >= bxmax || y >= bymax) + return; + if (n >= SIZE(bmask)) { + impossible("n too large (mk_bubble)"); + n = SIZE(bmask) - 1; + } + if (bmask[n][1] > MAX_BMASK) { + panic("bmask size is larger than MAX_BMASK"); + } + b = (struct bubble *) alloc(sizeof(struct bubble)); + if ((x + (int) bmask[n][0] - 1) > bxmax) + x = bxmax - bmask[n][0] + 1; + if ((y + (int) bmask[n][1] - 1) > bymax) + y = bymax - bmask[n][1] + 1; + b->x = x; + b->y = y; + b->dx = 1 - rn2(3); + b->dy = 1 - rn2(3); + /* y dimension is the length of bitmap data - see bmask above */ + (void) memcpy((genericptr_t) b->bm, (genericptr_t) bmask[n], + (bmask[n][1] + 2) * sizeof(b->bm[0])); + b->cons = 0; + if (!bbubbles) + bbubbles = b; + if (ebubbles) { + ebubbles->next = b; + b->prev = ebubbles; + } else + b->prev = (struct bubble *) 0; + b->next = (struct bubble *) 0; + ebubbles = b; + mv_bubble(b, 0, 0, TRUE); } /* @@ -1297,143 +1349,156 @@ register int x, y, n; * This property also makes leaving a bubble slightly difficult. */ STATIC_OVL void -mv_bubble(b,dx,dy,ini) +mv_bubble(b, dx, dy, ini) register struct bubble *b; register int dx, dy; register boolean ini; { - register int x, y, i, j, colli = 0; - struct container *cons, *ctemp; + register int x, y, i, j, colli = 0; + struct container *cons, *ctemp; - /* clouds move slowly */ - if (!Is_airlevel(&u.uz) || !rn2(6)) { - /* move bubble */ - if (dx < -1 || dx > 1 || dy < -1 || dy > 1) { - /* pline("mv_bubble: dx = %d, dy = %d", dx, dy); */ - dx = sgn(dx); - dy = sgn(dy); - } + /* clouds move slowly */ + if (!Is_airlevel(&u.uz) || !rn2(6)) { + /* move bubble */ + if (dx < -1 || dx > 1 || dy < -1 || dy > 1) { + /* pline("mv_bubble: dx = %d, dy = %d", dx, dy); */ + dx = sgn(dx); + dy = sgn(dy); + } - /* - * collision with level borders? - * 1 = horizontal border, 2 = vertical, 3 = corner - */ - if (b->x <= bxmin) colli |= 2; - if (b->y <= bymin) colli |= 1; - if ((int) (b->x + b->bm[0] - 1) >= bxmax) colli |= 2; - if ((int) (b->y + b->bm[1] - 1) >= bymax) colli |= 1; + /* + * collision with level borders? + * 1 = horizontal border, 2 = vertical, 3 = corner + */ + if (b->x <= bxmin) + colli |= 2; + if (b->y <= bymin) + colli |= 1; + if ((int) (b->x + b->bm[0] - 1) >= bxmax) + colli |= 2; + if ((int) (b->y + b->bm[1] - 1) >= bymax) + colli |= 1; - if (b->x < bxmin) { - pline("bubble xmin: x = %d, xmin = %d", b->x, bxmin); - b->x = bxmin; - } - if (b->y < bymin) { - pline("bubble ymin: y = %d, ymin = %d", b->y, bymin); - b->y = bymin; - } - if ((int) (b->x + b->bm[0] - 1) > bxmax) { - pline("bubble xmax: x = %d, xmax = %d", - b->x + b->bm[0] - 1, bxmax); - b->x = bxmax - b->bm[0] + 1; - } - if ((int) (b->y + b->bm[1] - 1) > bymax) { - pline("bubble ymax: y = %d, ymax = %d", - b->y + b->bm[1] - 1, bymax); - b->y = bymax - b->bm[1] + 1; - } + if (b->x < bxmin) { + pline("bubble xmin: x = %d, xmin = %d", b->x, bxmin); + b->x = bxmin; + } + if (b->y < bymin) { + pline("bubble ymin: y = %d, ymin = %d", b->y, bymin); + b->y = bymin; + } + if ((int) (b->x + b->bm[0] - 1) > bxmax) { + pline("bubble xmax: x = %d, xmax = %d", b->x + b->bm[0] - 1, + bxmax); + b->x = bxmax - b->bm[0] + 1; + } + if ((int) (b->y + b->bm[1] - 1) > bymax) { + pline("bubble ymax: y = %d, ymax = %d", b->y + b->bm[1] - 1, + bymax); + b->y = bymax - b->bm[1] + 1; + } - /* bounce if we're trying to move off the border */ - if (b->x == bxmin && dx < 0) dx = -dx; - if (b->x + b->bm[0] - 1 == bxmax && dx > 0) dx = -dx; - if (b->y == bymin && dy < 0) dy = -dy; - if (b->y + b->bm[1] - 1 == bymax && dy > 0) dy = -dy; + /* bounce if we're trying to move off the border */ + if (b->x == bxmin && dx < 0) + dx = -dx; + if (b->x + b->bm[0] - 1 == bxmax && dx > 0) + dx = -dx; + if (b->y == bymin && dy < 0) + dy = -dy; + if (b->y + b->bm[1] - 1 == bymax && dy > 0) + dy = -dy; - b->x += dx; - b->y += dy; - } + b->x += dx; + b->y += dy; + } - /* draw the bubbles */ - for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) - for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) - if (b->bm[j + 2] & (1 << i)) { - if (Is_waterlevel(&u.uz)) { - levl[x][y].typ = AIR; - levl[x][y].lit = 1; - unblock_point(x,y); - } else if (Is_airlevel(&u.uz)) { - levl[x][y].typ = CLOUD; - levl[x][y].lit = 1; - block_point(x,y); - } - } + /* draw the bubbles */ + for (i = 0, x = b->x; i < (int) b->bm[0]; i++, x++) + for (j = 0, y = b->y; j < (int) b->bm[1]; j++, y++) + if (b->bm[j + 2] & (1 << i)) { + if (Is_waterlevel(&u.uz)) { + levl[x][y].typ = AIR; + levl[x][y].lit = 1; + unblock_point(x, y); + } else if (Is_airlevel(&u.uz)) { + levl[x][y].typ = CLOUD; + levl[x][y].lit = 1; + block_point(x, y); + } + } - if (Is_waterlevel(&u.uz)) { - /* replace contents of bubble */ - for (cons = b->cons; cons; cons = ctemp) { - ctemp = cons->next; - cons->x += dx; - cons->y += dy; + if (Is_waterlevel(&u.uz)) { + /* replace contents of bubble */ + for (cons = b->cons; cons; cons = ctemp) { + ctemp = cons->next; + cons->x += dx; + cons->y += dy; - switch(cons->what) { - case CONS_OBJ: { - struct obj *olist, *otmp; + switch (cons->what) { + case CONS_OBJ: { + struct obj *olist, *otmp; - for (olist=(struct obj *)cons->list; olist; olist=otmp) { - otmp = olist->nexthere; - place_object(olist, cons->x, cons->y); - } - break; - } + for (olist = (struct obj *) cons->list; olist; olist = otmp) { + otmp = olist->nexthere; + place_object(olist, cons->x, cons->y); + } + break; + } - case CONS_MON: { - struct monst *mon = (struct monst *) cons->list; - (void) mnearto(mon, cons->x, cons->y, TRUE); - break; - } + case CONS_MON: { + struct monst *mon = (struct monst *) cons->list; + (void) mnearto(mon, cons->x, cons->y, TRUE); + break; + } - case CONS_HERO: { - int ux0 = u.ux, uy0 = u.uy; + case CONS_HERO: { + int ux0 = u.ux, uy0 = u.uy; - /* change u.ux0 and u.uy0? */ - u.ux = cons->x; - u.uy = cons->y; - newsym(ux0, uy0); /* clean up old position */ + /* change u.ux0 and u.uy0? */ + u.ux = cons->x; + u.uy = cons->y; + newsym(ux0, uy0); /* clean up old position */ - if (MON_AT(cons->x, cons->y)) { - mnexto(m_at(cons->x,cons->y)); - } - break; - } + if (MON_AT(cons->x, cons->y)) { + mnexto(m_at(cons->x, cons->y)); + } + break; + } - case CONS_TRAP: { - struct trap *btrap = (struct trap *) cons->list; - btrap->tx = cons->x; - btrap->ty = cons->y; - break; - } + case CONS_TRAP: { + struct trap *btrap = (struct trap *) cons->list; + btrap->tx = cons->x; + btrap->ty = cons->y; + break; + } - default: - impossible("mv_bubble: unknown bubble contents"); - break; - } - free((genericptr_t)cons); - } - b->cons = 0; - } + default: + impossible("mv_bubble: unknown bubble contents"); + break; + } + free((genericptr_t) cons); + } + b->cons = 0; + } - /* boing? */ - switch (colli) { - case 1: b->dy = -b->dy; break; - case 3: b->dy = -b->dy; /* fall through */ - case 2: b->dx = -b->dx; break; - default: - /* sometimes alter direction for fun anyway - (higher probability for stationary bubbles) */ - if (!ini && ((b->dx || b->dy) ? !rn2(20) : !rn2(5))) { - b->dx = 1 - rn2(3); - b->dy = 1 - rn2(3); - } - } + /* boing? */ + switch (colli) { + case 1: + b->dy = -b->dy; + break; + case 3: + b->dy = -b->dy; /* fall through */ + case 2: + b->dx = -b->dx; + break; + default: + /* sometimes alter direction for fun anyway + (higher probability for stationary bubbles) */ + if (!ini && ((b->dx || b->dy) ? !rn2(20) : !rn2(5))) { + b->dx = 1 - rn2(3); + b->dy = 1 - rn2(3); + } + } } /*mkmaze.c*/ diff --git a/src/mkobj.c b/src/mkobj.c index 9cb460465..fb9440840 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1,83 +1,76 @@ -/* NetHack 3.6 mkobj.c $NHDT-Date: 1430697424 2015/05/03 23:57:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.97 $ */ +/* NetHack 3.6 mkobj.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.100 $ */ /* NetHack 3.6 mkobj.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.70 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -STATIC_DCL void FDECL(mkbox_cnts,(struct obj *)); -STATIC_DCL void FDECL(maybe_adjust_light, (struct obj *,int)); -STATIC_DCL void FDECL(obj_timer_checks,(struct obj *, XCHAR_P, XCHAR_P, int)); +STATIC_DCL void FDECL(mkbox_cnts, (struct obj *)); +STATIC_DCL void FDECL(maybe_adjust_light, (struct obj *, int)); +STATIC_DCL void FDECL(obj_timer_checks, + (struct obj *, XCHAR_P, XCHAR_P, int)); STATIC_DCL void FDECL(container_weight, (struct obj *)); STATIC_DCL struct obj *FDECL(save_mtraits, (struct obj *, struct monst *)); -STATIC_DCL void FDECL(objlist_sanity, (struct obj *,int,const char *)); -STATIC_DCL void FDECL(mon_obj_sanity, (struct monst *,const char *)); +STATIC_DCL void FDECL(objlist_sanity, (struct obj *, int, const char *)); +STATIC_DCL void FDECL(mon_obj_sanity, (struct monst *, const char *)); STATIC_DCL const char *FDECL(where_name, (struct obj *)); -STATIC_DCL void FDECL(insane_object, - (struct obj *,const char *,const char *,struct monst *)); -STATIC_DCL void FDECL(check_contained, (struct obj *,const char *)); +STATIC_DCL void FDECL(insane_object, (struct obj *, const char *, + const char *, struct monst *)); +STATIC_DCL void FDECL(check_contained, (struct obj *, const char *)); STATIC_DCL void FDECL(sanity_check_worn, (struct obj *)); struct icp { - int iprob; /* probability of an item type */ - char iclass; /* item class */ + int iprob; /* probability of an item type */ + char iclass; /* item class */ }; -const struct icp mkobjprobs[] = { -{10, WEAPON_CLASS}, -{10, ARMOR_CLASS}, -{20, FOOD_CLASS}, -{ 8, TOOL_CLASS}, -{ 8, GEM_CLASS}, -{16, POTION_CLASS}, -{16, SCROLL_CLASS}, -{ 4, SPBOOK_CLASS}, -{ 4, WAND_CLASS}, -{ 3, RING_CLASS}, -{ 1, AMULET_CLASS} -}; +const struct icp mkobjprobs[] = { { 10, WEAPON_CLASS }, + { 10, ARMOR_CLASS }, + { 20, FOOD_CLASS }, + { 8, TOOL_CLASS }, + { 8, GEM_CLASS }, + { 16, POTION_CLASS }, + { 16, SCROLL_CLASS }, + { 4, SPBOOK_CLASS }, + { 4, WAND_CLASS }, + { 3, RING_CLASS }, + { 1, AMULET_CLASS } }; -const struct icp boxiprobs[] = { -{18, GEM_CLASS}, -{15, FOOD_CLASS}, -{18, POTION_CLASS}, -{18, SCROLL_CLASS}, -{12, SPBOOK_CLASS}, -{ 7, COIN_CLASS}, -{ 6, WAND_CLASS}, -{ 5, RING_CLASS}, -{ 1, AMULET_CLASS} -}; +const struct icp boxiprobs[] = { { 18, GEM_CLASS }, + { 15, FOOD_CLASS }, + { 18, POTION_CLASS }, + { 18, SCROLL_CLASS }, + { 12, SPBOOK_CLASS }, + { 7, COIN_CLASS }, + { 6, WAND_CLASS }, + { 5, RING_CLASS }, + { 1, AMULET_CLASS } }; -const struct icp rogueprobs[] = { -{12, WEAPON_CLASS}, -{12, ARMOR_CLASS}, -{22, FOOD_CLASS}, -{22, POTION_CLASS}, -{22, SCROLL_CLASS}, -{ 5, WAND_CLASS}, -{ 5, RING_CLASS} -}; +const struct icp rogueprobs[] = { { 12, WEAPON_CLASS }, + { 12, ARMOR_CLASS }, + { 22, FOOD_CLASS }, + { 22, POTION_CLASS }, + { 22, SCROLL_CLASS }, + { 5, WAND_CLASS }, + { 5, RING_CLASS } }; -const struct icp hellprobs[] = { -{20, WEAPON_CLASS}, -{20, ARMOR_CLASS}, -{16, FOOD_CLASS}, -{12, TOOL_CLASS}, -{10, GEM_CLASS}, -{ 1, POTION_CLASS}, -{ 1, SCROLL_CLASS}, -{ 8, WAND_CLASS}, -{ 8, RING_CLASS}, -{ 4, AMULET_CLASS} -}; +const struct icp hellprobs[] = { { 20, WEAPON_CLASS }, + { 20, ARMOR_CLASS }, + { 16, FOOD_CLASS }, + { 12, TOOL_CLASS }, + { 10, GEM_CLASS }, + { 1, POTION_CLASS }, + { 1, SCROLL_CLASS }, + { 8, WAND_CLASS }, + { 8, RING_CLASS }, + { 4, AMULET_CLASS } }; struct oextra * newoextra() { struct oextra *oextra; - oextra = (struct oextra *)alloc(sizeof(struct oextra)); + oextra = (struct oextra *) alloc(sizeof(struct oextra)); oextra->oname = 0; oextra->omonst = 0; oextra->omid = 0; @@ -91,12 +84,17 @@ dealloc_oextra(x) struct oextra *x; { if (x) { - if (x->oname) free((genericptr_t)x->oname); - if (x->omonst) free((genericptr_t)x->omonst); - if (x->omid) free((genericptr_t)x->omid); - if (x->olong) free((genericptr_t)x->olong); - if (x->omailcmd) free((genericptr_t)x->omailcmd); - free((genericptr_t)x); + if (x->oname) + free((genericptr_t) x->oname); + if (x->omonst) + free((genericptr_t) x->omonst); + if (x->omid) + free((genericptr_t) x->omid); + if (x->olong) + free((genericptr_t) x->olong); + if (x->omailcmd) + free((genericptr_t) x->omailcmd); + free((genericptr_t) x); } } @@ -104,9 +102,10 @@ void newomonst(otmp) struct obj *otmp; { - if (!otmp->oextra) otmp->oextra = newoextra(); + if (!otmp->oextra) + otmp->oextra = newoextra(); if (!OMONST(otmp)) { - OMONST(otmp) = (struct monst *)alloc(sizeof(struct monst)); + OMONST(otmp) = (struct monst *) alloc(sizeof(struct monst)); (void) memset((genericptr_t) OMONST(otmp), 0, sizeof(struct monst)); } } @@ -117,7 +116,7 @@ struct obj *otmp; { if (otmp->oextra && OMONST(otmp)) { free((genericptr_t) OMONST(otmp)); - OMONST(otmp) = (struct monst *)0; + OMONST(otmp) = (struct monst *) 0; } } @@ -125,9 +124,10 @@ void newomid(otmp) struct obj *otmp; { - if (!otmp->oextra) otmp->oextra = newoextra(); + if (!otmp->oextra) + otmp->oextra = newoextra(); if (!OMID(otmp)) { - OMID(otmp) = (unsigned *)alloc(sizeof(unsigned)); + OMID(otmp) = (unsigned *) alloc(sizeof(unsigned)); (void) memset((genericptr_t) OMID(otmp), 0, sizeof(unsigned)); } } @@ -138,7 +138,7 @@ struct obj *otmp; { if (otmp->oextra && OMID(otmp)) { free((genericptr_t) OMID(otmp)); - OMID(otmp) = (unsigned *)0; + OMID(otmp) = (unsigned *) 0; } } @@ -146,9 +146,10 @@ void newolong(otmp) struct obj *otmp; { - if (!otmp->oextra) otmp->oextra = newoextra(); + if (!otmp->oextra) + otmp->oextra = newoextra(); if (!OLONG(otmp)) { - OLONG(otmp) = (long *)alloc(sizeof(long)); + OLONG(otmp) = (long *) alloc(sizeof(long)); (void) memset((genericptr_t) OLONG(otmp), 0, sizeof(long)); } } @@ -159,7 +160,7 @@ struct obj *otmp; { if (otmp->oextra && OLONG(otmp)) { free((genericptr_t) OLONG(otmp)); - OLONG(otmp) = (long *)0; + OLONG(otmp) = (long *) 0; } } @@ -168,8 +169,10 @@ new_omailcmd(otmp, response_cmd) struct obj *otmp; const char *response_cmd; { - if (!otmp->oextra) otmp->oextra = newoextra(); - if (OMAILCMD(otmp)) free_omailcmd(otmp); + if (!otmp->oextra) + otmp->oextra = newoextra(); + if (OMAILCMD(otmp)) + free_omailcmd(otmp); OMAILCMD(otmp) = dupstr(response_cmd); } @@ -179,7 +182,7 @@ struct obj *otmp; { if (otmp->oextra && OMAILCMD(otmp)) { free((genericptr_t) OMAILCMD(otmp)); - OMAILCMD(otmp) = (char *)0; + OMAILCMD(otmp) = (char *) 0; } } @@ -193,7 +196,7 @@ boolean artif; otmp = mkobj(let, artif); place_object(otmp, x, y); - return(otmp); + return (otmp); } struct obj * @@ -205,7 +208,7 @@ boolean init, artif; otmp = mksobj(otyp, init, artif); place_object(otmp, x, y); - return(otmp); + return (otmp); } struct obj * @@ -215,26 +218,26 @@ boolean artif; { int tprob, i, prob = rnd(1000); - if(oclass == RANDOM_CLASS) { + if (oclass == RANDOM_CLASS) { const struct icp *iprobs = - (Is_rogue_level(&u.uz)) ? - (const struct icp *)rogueprobs : - Inhell ? (const struct icp *)hellprobs : - (const struct icp *)mkobjprobs; + (Is_rogue_level(&u.uz)) + ? (const struct icp *) rogueprobs + : Inhell ? (const struct icp *) hellprobs + : (const struct icp *) mkobjprobs; - for(tprob = rnd(100); - (tprob -= iprobs->iprob) > 0; - iprobs++); + for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++) + ; oclass = iprobs->iclass; } - i = bases[(int)oclass]; - while((prob -= objects[i].oc_prob) > 0) i++; + i = bases[(int) oclass]; + while ((prob -= objects[i].oc_prob) > 0) + i++; - if(objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) + if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) panic("probtype error, oclass=%d i=%d", (int) oclass, i); - return(mksobj(i, TRUE, artif)); + return (mksobj(i, TRUE, artif)); } STATIC_OVL void @@ -247,70 +250,88 @@ struct obj *box; box->cobj = (struct obj *) 0; switch (box->otyp) { - case ICE_BOX: n = 20; break; - case CHEST: n = 5; break; - case LARGE_BOX: n = 3; break; + case ICE_BOX: + n = 20; + break; + case CHEST: + n = 5; + break; + case LARGE_BOX: + n = 3; + break; case SACK: case OILSKIN_SACK: - /* initial inventory: sack starts out empty */ - if (moves <= 1 && !in_mklev) { n = 0; break; } - /*else FALLTHRU*/ - case BAG_OF_HOLDING: n = 1; break; - default: n = 0; break; + /* initial inventory: sack starts out empty */ + if (moves <= 1 && !in_mklev) { + n = 0; + break; + } + /*else FALLTHRU*/ + case BAG_OF_HOLDING: + n = 1; + break; + default: + n = 0; + break; } - for (n = rn2(n+1); n > 0; n--) { + for (n = rn2(n + 1); n > 0; n--) { if (box->otyp == ICE_BOX) { - if (!(otmp = mksobj(CORPSE, TRUE, TRUE))) continue; - /* Note: setting age to 0 is correct. Age has a different - * from usual meaning for objects stored in ice boxes. -KAA - */ - otmp->age = 0L; - if (otmp->timed) { - (void) stop_timer(ROT_CORPSE, obj_to_any(otmp)); - (void) stop_timer(REVIVE_MON, obj_to_any(otmp)); - } + if (!(otmp = mksobj(CORPSE, TRUE, TRUE))) + continue; + /* Note: setting age to 0 is correct. Age has a different + * from usual meaning for objects stored in ice boxes. -KAA + */ + otmp->age = 0L; + if (otmp->timed) { + (void) stop_timer(ROT_CORPSE, obj_to_any(otmp)); + (void) stop_timer(REVIVE_MON, obj_to_any(otmp)); + } } else { - register int tprob; - const struct icp *iprobs = boxiprobs; + register int tprob; + const struct icp *iprobs = boxiprobs; - for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++) - ; - if (!(otmp = mkobj(iprobs->iclass, TRUE))) continue; + for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++) + ; + if (!(otmp = mkobj(iprobs->iclass, TRUE))) + continue; - /* handle a couple of special cases */ - if (otmp->oclass == COIN_CLASS) { - /* 2.5 x level's usual amount; weight adjusted below */ - otmp->quan = (long)(rnd(level_difficulty()+2) * rnd(75)); - otmp->owt = weight(otmp); - } else while (otmp->otyp == ROCK) { - otmp->otyp = rnd_class(DILITHIUM_CRYSTAL, LOADSTONE); - if (otmp->quan > 2L) otmp->quan = 1L; - otmp->owt = weight(otmp); - } - if (box->otyp == BAG_OF_HOLDING) { - if (Is_mbag(otmp)) { - otmp->otyp = SACK; - otmp->spe = 0; - otmp->owt = weight(otmp); - } else while (otmp->otyp == WAN_CANCELLATION) - otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); - } + /* handle a couple of special cases */ + if (otmp->oclass == COIN_CLASS) { + /* 2.5 x level's usual amount; weight adjusted below */ + otmp->quan = (long) (rnd(level_difficulty() + 2) * rnd(75)); + otmp->owt = weight(otmp); + } else + while (otmp->otyp == ROCK) { + otmp->otyp = rnd_class(DILITHIUM_CRYSTAL, LOADSTONE); + if (otmp->quan > 2L) + otmp->quan = 1L; + otmp->owt = weight(otmp); + } + if (box->otyp == BAG_OF_HOLDING) { + if (Is_mbag(otmp)) { + otmp->otyp = SACK; + otmp->spe = 0; + otmp->owt = weight(otmp); + } else + while (otmp->otyp == WAN_CANCELLATION) + otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); + } } (void) add_to_container(box, otmp); } } -int -rndmonnum() /* select a random, common monster type */ +int rndmonnum() /* select a random, common monster type */ { register struct permonst *ptr; - register int i; + register int i; unsigned short excludeflags; /* Plan A: get a level-appropriate common monster */ ptr = rndmonst(); - if (ptr) return(monsndx(ptr)); + if (ptr) + return (monsndx(ptr)); /* Plan B: get any common monster */ excludeflags = G_UNIQ | G_NOGEN | (Inhell ? G_NOHELL : G_HELL); @@ -319,43 +340,46 @@ rndmonnum() /* select a random, common monster type */ ptr = &mons[i]; } while ((ptr->geno & excludeflags) != 0); - return(i); + return (i); } void copy_oextra(obj2, obj1) struct obj *obj2, *obj1; { - if(!obj2 || !obj1 || !obj1->oextra) return; + if (!obj2 || !obj1 || !obj1->oextra) + return; - if (!obj2->oextra) obj2->oextra = newoextra(); - if (has_oname(obj1)) oname(obj2, ONAME(obj1)); + if (!obj2->oextra) + obj2->oextra = newoextra(); + if (has_oname(obj1)) + oname(obj2, ONAME(obj1)); if (has_omonst(obj1)) { - if (!OMONST(obj2)) newomonst(obj2); - (void)memcpy((genericptr_t)OMONST(obj2), - (genericptr_t)OMONST(obj1), - sizeof(struct monst)); - OMONST(obj2)->mextra = (struct mextra *)0; - OMONST(obj2)->nmon = (struct monst *)0; + if (!OMONST(obj2)) + newomonst(obj2); + (void) memcpy((genericptr_t) OMONST(obj2), + (genericptr_t) OMONST(obj1), sizeof(struct monst)); + OMONST(obj2)->mextra = (struct mextra *) 0; + OMONST(obj2)->nmon = (struct monst *) 0; #if 0 OMONST(obj2)->m_id = context.ident++; if (OMONST(obj2)->m_id) /* ident overflowed */ OMONST(obj2)->m_id = context.ident++; #endif if (OMONST(obj1)->mextra) - copy_mextra(OMONST(obj2),OMONST(obj1)); + copy_mextra(OMONST(obj2), OMONST(obj1)); } if (has_omid(obj1)) { - if (!OMID(obj2)) newomid(obj2); - (void)memcpy((genericptr_t)OMID(obj2), - (genericptr_t)OMID(obj1), - sizeof(unsigned)); + if (!OMID(obj2)) + newomid(obj2); + (void) memcpy((genericptr_t) OMID(obj2), (genericptr_t) OMID(obj1), + sizeof(unsigned)); } if (has_olong(obj1)) { - if (!OLONG(obj2)) newolong(obj2); - (void)memcpy((genericptr_t)OLONG(obj2), - (genericptr_t)OLONG(obj1), - sizeof(long)); + if (!OLONG(obj2)) + newolong(obj2); + (void) memcpy((genericptr_t) OLONG(obj2), (genericptr_t) OLONG(obj1), + sizeof(long)); } if (has_omailcmd(obj1)) { new_omailcmd(obj2, OMAILCMD(obj1)); @@ -376,29 +400,34 @@ long num; struct obj *otmp; if (obj->cobj || num <= 0L || obj->quan <= num) - panic("splitobj"); /* can't split containers */ + panic("splitobj"); /* can't split containers */ otmp = newobj(); - *otmp = *obj; /* copies whole structure */ - otmp->oextra = (struct oextra *)0; + *otmp = *obj; /* copies whole structure */ + otmp->oextra = (struct oextra *) 0; otmp->o_id = context.ident++; - if (!otmp->o_id) otmp->o_id = context.ident++; /* ident overflowed */ - otmp->timed = 0; /* not timed, yet */ - otmp->lamplit = 0; /* ditto */ - otmp->owornmask = 0L; /* new object isn't worn */ + if (!otmp->o_id) + otmp->o_id = context.ident++; /* ident overflowed */ + otmp->timed = 0; /* not timed, yet */ + otmp->lamplit = 0; /* ditto */ + otmp->owornmask = 0L; /* new object isn't worn */ obj->quan -= num; obj->owt = weight(obj); otmp->quan = num; - otmp->owt = weight(otmp); /* -= obj->owt ? */ + otmp->owt = weight(otmp); /* -= obj->owt ? */ obj->nobj = otmp; /* Only set nexthere when on the floor, nexthere is also used */ /* as a back pointer to the container object when contained. */ if (obj->where == OBJ_FLOOR) obj->nexthere = otmp; copy_oextra(otmp, obj); - if (has_omid(otmp)) free_omid(otmp); /* only one association with m_id*/ - if (obj->unpaid) splitbill(obj,otmp); - if (obj->timed) obj_split_timers(obj, otmp); - if (obj_sheds_light(obj)) obj_split_light_source(obj, otmp); + if (has_omid(otmp)) + free_omid(otmp); /* only one association with m_id*/ + if (obj->unpaid) + splitbill(obj, otmp); + if (obj->timed) + obj_split_timers(obj, otmp); + if (obj_sheds_light(obj)) + obj_split_light_source(obj, otmp); return otmp; } @@ -419,38 +448,38 @@ struct obj *otmp; otmp->where = obj->where; switch (obj->where) { case OBJ_FREE: - /* do nothing */ - break; + /* do nothing */ + break; case OBJ_INVENT: - otmp->nobj = obj->nobj; - obj->nobj = otmp; - extract_nobj(obj, &invent); - break; + otmp->nobj = obj->nobj; + obj->nobj = otmp; + extract_nobj(obj, &invent); + break; case OBJ_CONTAINED: - otmp->nobj = obj->nobj; - otmp->ocontainer = obj->ocontainer; - obj->nobj = otmp; - extract_nobj(obj, &obj->ocontainer->cobj); - break; + otmp->nobj = obj->nobj; + otmp->ocontainer = obj->ocontainer; + obj->nobj = otmp; + extract_nobj(obj, &obj->ocontainer->cobj); + break; case OBJ_MINVENT: - otmp->nobj = obj->nobj; - otmp->ocarry = obj->ocarry; - obj->nobj = otmp; - extract_nobj(obj, &obj->ocarry->minvent); - break; + otmp->nobj = obj->nobj; + otmp->ocarry = obj->ocarry; + obj->nobj = otmp; + extract_nobj(obj, &obj->ocarry->minvent); + break; case OBJ_FLOOR: - otmp->nobj = obj->nobj; - otmp->nexthere = obj->nexthere; - otmp->ox = obj->ox; - otmp->oy = obj->oy; - obj->nobj = otmp; - obj->nexthere = otmp; - extract_nobj(obj, &fobj); - extract_nexthere(obj, &level.objects[obj->ox][obj->oy]); - break; + otmp->nobj = obj->nobj; + otmp->nexthere = obj->nexthere; + otmp->ox = obj->ox; + otmp->oy = obj->oy; + obj->nobj = otmp; + obj->nexthere = otmp; + extract_nobj(obj, &fobj); + extract_nexthere(obj, &level.objects[obj->ox][obj->oy]); + break; default: - panic("replace_object: obj position"); - break; + panic("replace_object: obj position"); + break; } } @@ -481,29 +510,32 @@ register struct obj *otmp; } dummy = newobj(); *dummy = *otmp; - dummy->oextra = (struct oextra *)0; + dummy->oextra = (struct oextra *) 0; dummy->where = OBJ_FREE; dummy->o_id = context.ident++; - if (!dummy->o_id) dummy->o_id = context.ident++; /* ident overflowed */ + if (!dummy->o_id) + dummy->o_id = context.ident++; /* ident overflowed */ dummy->timed = 0; copy_oextra(dummy, otmp); - if (has_omid(dummy)) free_omid(dummy); /* only one association with m_id*/ - if (Is_candle(dummy)) dummy->lamplit = 0; + if (has_omid(dummy)) + free_omid(dummy); /* only one association with m_id*/ + if (Is_candle(dummy)) + dummy->lamplit = 0; addtobill(dummy, FALSE, TRUE, TRUE); - if (cost) alter_cost(dummy, -cost); + if (cost) + alter_cost(dummy, -cost); /* no_charge is only valid for some locations */ - otmp->no_charge = (otmp->where == OBJ_FLOOR || - otmp->where == OBJ_CONTAINED) ? 1 : 0; + otmp->no_charge = + (otmp->where == OBJ_FLOOR || otmp->where == OBJ_CONTAINED) ? 1 : 0; otmp->unpaid = 0; return; } /* alteration types; must match COST_xxx macros in hack.h */ -static const char * const alteration_verbs[] = { - "cancel", "drain", "uncharge", "unbless", "uncurse", - "disenchant", "degrade", "dilute", "erase", "burn", - "neutralize", "destroy", "splatter", "bite", "open", - "break the lock on", "rust", "rot", "tarnish" +static const char *const alteration_verbs[] = { + "cancel", "drain", "uncharge", "unbless", "uncurse", "disenchant", + "degrade", "dilute", "erase", "burn", "neutralize", "destroy", "splatter", + "bite", "open", "break the lock on", "rust", "rot", "tarnish" }; /* possibly bill for an object which the player has just modified */ @@ -519,34 +551,37 @@ int alter_type; struct monst *shkp = 0; if (alter_type < 0 || alter_type >= SIZE(alteration_verbs)) { - impossible("invalid alteration type (%d)", alter_type); - alter_type = 0; + impossible("invalid alteration type (%d)", alter_type); + alter_type = 0; } - ox = oy = 0; /* lint suppression */ - objroom = '\0'; /* ditto */ + ox = oy = 0; /* lint suppression */ + objroom = '\0'; /* ditto */ if (carried(obj) || obj->where == OBJ_FREE) { - /* OBJ_FREE catches obj_no_longer_held()'s transformation - of crysknife back into worm tooth; the object has been - removed from inventory but not necessarily placed at - its new location yet--the unpaid flag will still be set - if this item is owned by a shop */ - if (!obj->unpaid) return; + /* OBJ_FREE catches obj_no_longer_held()'s transformation + of crysknife back into worm tooth; the object has been + removed from inventory but not necessarily placed at + its new location yet--the unpaid flag will still be set + if this item is owned by a shop */ + if (!obj->unpaid) + return; } else { - /* this get_obj_location shouldn't fail, but if it does, - use hero's location */ - if (!get_obj_location(obj, &ox, &oy, CONTAINED_TOO)) - ox = u.ux, oy = u.uy; - if (!costly_spot(ox, oy)) return; - objroom = *in_rooms(ox, oy, SHOPBASE); - /* if no shop cares about it, we're done */ - if (!billable(&shkp, obj, objroom, FALSE)) return; + /* this get_obj_location shouldn't fail, but if it does, + use hero's location */ + if (!get_obj_location(obj, &ox, &oy, CONTAINED_TOO)) + ox = u.ux, oy = u.uy; + if (!costly_spot(ox, oy)) + return; + objroom = *in_rooms(ox, oy, SHOPBASE); + /* if no shop cares about it, we're done */ + if (!billable(&shkp, obj, objroom, FALSE)) + return; } if (obj->quan == 1L) - those = "that", them = "it"; + those = "that", them = "it"; else - those = "those", them = "them"; + those = "those", them = "them"; /* when shopkeeper describes the object as being uncursed or unblessed hero will know that it is now uncursed; will also make the feedback @@ -554,31 +589,32 @@ int alter_type; set_bknown = (alter_type == COST_UNCURS || alter_type == COST_UNBLSS); switch (obj->where) { - case OBJ_FREE: /* obj_no_longer_held() */ + case OBJ_FREE: /* obj_no_longer_held() */ case OBJ_INVENT: - if (set_bknown) obj->bknown = 1; - verbalize("You %s %s %s, you pay for %s!", - alteration_verbs[alter_type], those, - simpleonames(obj), them); - bill_dummy_object(obj); - break; - case OBJ_FLOOR: - if (set_bknown) obj->bknown = 1; - if (costly_spot(u.ux, u.uy) && objroom == *u.ushops) { - verbalize("You %s %s, you pay for %s!", - alteration_verbs[alter_type], those, them); + if (set_bknown) + obj->bknown = 1; + verbalize("You %s %s %s, you pay for %s!", + alteration_verbs[alter_type], those, simpleonames(obj), + them); bill_dummy_object(obj); - } else { - (void) stolen_value(obj, ox, oy, FALSE, FALSE); - } - break; + break; + case OBJ_FLOOR: + if (set_bknown) + obj->bknown = 1; + if (costly_spot(u.ux, u.uy) && objroom == *u.ushops) { + verbalize("You %s %s, you pay for %s!", + alteration_verbs[alter_type], those, them); + bill_dummy_object(obj); + } else { + (void) stolen_value(obj, ox, oy, FALSE, FALSE); + } + break; } } -static const char dknowns[] = { - WAND_CLASS, RING_CLASS, POTION_CLASS, SCROLL_CLASS, - GEM_CLASS, SPBOOK_CLASS, WEAPON_CLASS, TOOL_CLASS, 0 -}; +static const char dknowns[] = { WAND_CLASS, RING_CLASS, POTION_CLASS, + SCROLL_CLASS, GEM_CLASS, SPBOOK_CLASS, + WEAPON_CLASS, TOOL_CLASS, 0 }; struct obj * mksobj(otyp, init, artif) @@ -594,14 +630,15 @@ boolean artif; *otmp = zeroobj; otmp->age = monstermoves; otmp->o_id = context.ident++; - if (!otmp->o_id) otmp->o_id = context.ident++; /* ident overflowed */ + if (!otmp->o_id) + otmp->o_id = context.ident++; /* ident overflowed */ otmp->quan = 1L; otmp->oclass = let; otmp->otyp = otyp; otmp->where = OBJ_FREE; otmp->dknown = index(dknowns, let) ? 0 : 1; - if ((otmp->otyp >= ELVEN_SHIELD && otmp->otyp <= ORCISH_SHIELD) || - otmp->otyp == SHIELD_OF_REFLECTION) + if ((otmp->otyp >= ELVEN_SHIELD && otmp->otyp <= ORCISH_SHIELD) + || otmp->otyp == SHIELD_OF_REFLECTION) otmp->dknown = 0; if (!objects[otmp->otyp].oc_uses_known) otmp->known = 1; @@ -609,61 +646,69 @@ boolean artif; otmp->cknown = 0; otmp->corpsenm = NON_PM; - if (init) switch (let) { - case WEAPON_CLASS: - otmp->quan = is_multigen(otmp) ? (long) rn1(6,6) : 1L; - if(!rn2(11)) { - otmp->spe = rne(3); - otmp->blessed = rn2(2); - } else if(!rn2(10)) { - curse(otmp); - otmp->spe = -rne(3); - } else blessorcurse(otmp, 10); - if (is_poisonable(otmp) && !rn2(100)) - otmp->opoisoned = 1; + if (init) + switch (let) { + case WEAPON_CLASS: + otmp->quan = is_multigen(otmp) ? (long) rn1(6, 6) : 1L; + if (!rn2(11)) { + otmp->spe = rne(3); + otmp->blessed = rn2(2); + } else if (!rn2(10)) { + curse(otmp); + otmp->spe = -rne(3); + } else + blessorcurse(otmp, 10); + if (is_poisonable(otmp) && !rn2(100)) + otmp->opoisoned = 1; - if (artif && !rn2(20)) - otmp = mk_artifact(otmp, (aligntyp)A_NONE); - break; - case FOOD_CLASS: - otmp->oeaten = 0; - switch(otmp->otyp) { + if (artif && !rn2(20)) + otmp = mk_artifact(otmp, (aligntyp) A_NONE); + break; + case FOOD_CLASS: + otmp->oeaten = 0; + switch (otmp->otyp) { case CORPSE: /* possibly overridden by mkcorpstat() */ tryct = 50; - do otmp->corpsenm = undead_to_corpse(rndmonnum()); - while ((mvitals[otmp->corpsenm].mvflags & G_NOCORPSE) && (--tryct > 0)); + do + otmp->corpsenm = undead_to_corpse(rndmonnum()); + while ((mvitals[otmp->corpsenm].mvflags & G_NOCORPSE) + && (--tryct > 0)); if (tryct == 0) { - /* perhaps rndmonnum() only wants to make G_NOCORPSE monsters on - this level; let's create an adventurer's corpse instead, then */ + /* perhaps rndmonnum() only wants to make G_NOCORPSE + monsters on + this level; let's create an adventurer's corpse + instead, then */ otmp->corpsenm = PM_HUMAN; } /* timer set below */ break; case EGG: - otmp->corpsenm = NON_PM; /* generic egg */ - if (!rn2(3)) for (tryct = 200; tryct > 0; --tryct) { - mndx = can_be_hatched(rndmonnum()); - if (mndx != NON_PM && !dead_species(mndx, TRUE)) { - otmp->corpsenm = mndx; /* typed egg */ - break; + otmp->corpsenm = NON_PM; /* generic egg */ + if (!rn2(3)) + for (tryct = 200; tryct > 0; --tryct) { + mndx = can_be_hatched(rndmonnum()); + if (mndx != NON_PM && !dead_species(mndx, TRUE)) { + otmp->corpsenm = mndx; /* typed egg */ + break; + } } - } /* timer set below */ break; case TIN: - otmp->corpsenm = NON_PM; /* empty (so far) */ + otmp->corpsenm = NON_PM; /* empty (so far) */ if (!rn2(6)) set_tin_variety(otmp, SPINACH_TIN); - else for (tryct = 200; tryct > 0; --tryct) { - mndx = undead_to_corpse(rndmonnum()); - if (mons[mndx].cnutrit && - !(mvitals[mndx].mvflags & G_NOCORPSE)) { - otmp->corpsenm = mndx; - set_tin_variety(otmp, RANDOM_TIN); - break; + else + for (tryct = 200; tryct > 0; --tryct) { + mndx = undead_to_corpse(rndmonnum()); + if (mons[mndx].cnutrit + && !(mvitals[mndx].mvflags & G_NOCORPSE)) { + otmp->corpsenm = mndx; + set_tin_variety(otmp, RANDOM_TIN); + break; + } } - } blessorcurse(otmp, 10); break; case SLIME_MOLD: @@ -673,218 +718,239 @@ boolean artif; case KELP_FROND: otmp->quan = (long) rnd(2); break; - } - if (Is_pudding(otmp)) { - otmp->globby = 1; - otmp->known = otmp->bknown = otmp->rknown = otmp->dknown = 1; - otmp->corpsenm = PM_GRAY_OOZE + (otmp->otyp - GLOB_OF_GRAY_OOZE); - /* this ensures that they don't fail merging because of - * BUC status or other irrelevancies */ - } else { - if (otmp->otyp != CORPSE && otmp->otyp != MEAT_RING + } + if (Is_pudding(otmp)) { + otmp->globby = 1; + otmp->known = otmp->bknown = otmp->rknown = otmp->dknown = 1; + otmp->corpsenm = + PM_GRAY_OOZE + (otmp->otyp - GLOB_OF_GRAY_OOZE); + /* this ensures that they don't fail merging because of + * BUC status or other irrelevancies */ + } else { + if (otmp->otyp != CORPSE && otmp->otyp != MEAT_RING && otmp->otyp != KELP_FROND && !rn2(6)) { - otmp->quan = 2L; - } - } - break; - case GEM_CLASS: - otmp->corpsenm = 0; /* LOADSTONE hack */ - if (otmp->otyp == LOADSTONE) curse(otmp); - else if (otmp->otyp == ROCK) otmp->quan = (long) rn1(6,6); - else if (otmp->otyp != LUCKSTONE && !rn2(6)) otmp->quan = 2L; - else otmp->quan = 1L; - break; - case TOOL_CLASS: - switch(otmp->otyp) { - case TALLOW_CANDLE: - case WAX_CANDLE: otmp->spe = 1; - otmp->age = 20L * /* 400 or 200 */ - (long)objects[otmp->otyp].oc_cost; - otmp->lamplit = 0; - otmp->quan = 1L + - (long)(rn2(2) ? rn2(7) : 0); - blessorcurse(otmp, 5); - break; - case BRASS_LANTERN: - case OIL_LAMP: otmp->spe = 1; - otmp->age = (long) rn1(500,1000); - otmp->lamplit = 0; - blessorcurse(otmp, 5); - break; - case MAGIC_LAMP: otmp->spe = 1; - otmp->lamplit = 0; - blessorcurse(otmp, 2); - break; - case CHEST: - case LARGE_BOX: otmp->olocked = !!(rn2(5)); - otmp->otrapped = !(rn2(10)); - case ICE_BOX: - case SACK: - case OILSKIN_SACK: - case BAG_OF_HOLDING: mkbox_cnts(otmp); - break; - case LEASH: otmp->leashmon = 0; - break; - case EXPENSIVE_CAMERA: - case TINNING_KIT: - case MAGIC_MARKER: otmp->spe = rn1(70,30); - break; - case CAN_OF_GREASE: otmp->spe = rnd(25); - blessorcurse(otmp, 10); - break; - case CRYSTAL_BALL: otmp->spe = rnd(5); - blessorcurse(otmp, 2); - break; - case HORN_OF_PLENTY: - case BAG_OF_TRICKS: otmp->spe = rnd(20); - break; - case FIGURINE: { int tryct2 = 0; - do - otmp->corpsenm = rndmonnum(); - while(is_human(&mons[otmp->corpsenm]) - && tryct2++ < 30); - blessorcurse(otmp, 4); - break; + otmp->quan = 2L; } - case BELL_OF_OPENING: otmp->spe = 3; - break; - case MAGIC_FLUTE: - case MAGIC_HARP: - case FROST_HORN: - case FIRE_HORN: - case DRUM_OF_EARTHQUAKE: - otmp->spe = rn1(5,4); - break; - } - break; - case AMULET_CLASS: - if (otmp->otyp == AMULET_OF_YENDOR) context.made_amulet = TRUE; - if(rn2(10) && (otmp->otyp == AMULET_OF_STRANGULATION || - otmp->otyp == AMULET_OF_CHANGE || - otmp->otyp == AMULET_OF_RESTFUL_SLEEP)) { - curse(otmp); - } else blessorcurse(otmp, 10); - case VENOM_CLASS: - case CHAIN_CLASS: - case BALL_CLASS: - break; - case POTION_CLASS: - otmp->fromsink = 0; - if (otmp->otyp == POT_OIL) - otmp->age = MAX_OIL_IN_FLASK; /* amount of oil */ - /* fall through */ - case SCROLL_CLASS: -#ifdef MAIL - if (otmp->otyp != SCR_MAIL) -#endif - blessorcurse(otmp, 4); - break; - case SPBOOK_CLASS: - otmp->spestudied = 0; - blessorcurse(otmp, 17); - break; - case ARMOR_CLASS: - if(rn2(10) && (otmp->otyp == FUMBLE_BOOTS || - otmp->otyp == LEVITATION_BOOTS || - otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT || - otmp->otyp == GAUNTLETS_OF_FUMBLING || - !rn2(11))) { - curse(otmp); - otmp->spe = -rne(3); - } else if(!rn2(10)) { - otmp->blessed = rn2(2); - otmp->spe = rne(3); - } else blessorcurse(otmp, 10); - if (artif && !rn2(40)) - otmp = mk_artifact(otmp, (aligntyp)A_NONE); - /* simulate lacquered armor for samurai */ - if (Role_if(PM_SAMURAI) && otmp->otyp == SPLINT_MAIL && - (moves <= 1 || In_quest(&u.uz))) { -#ifdef UNIXPC - /* optimizer bitfield bug */ - otmp->oerodeproof = 1; - otmp->rknown = 1; -#else - otmp->oerodeproof = otmp->rknown = 1; -#endif - } - break; - case WAND_CLASS: - if(otmp->otyp == WAN_WISHING) otmp->spe = rnd(3); else - otmp->spe = rn1(5, - (objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4); - blessorcurse(otmp, 17); - otmp->recharged = 0; /* used to control recharging */ - break; - case RING_CLASS: - if(objects[otmp->otyp].oc_charged) { - blessorcurse(otmp, 3); - if(rn2(10)) { - if(rn2(10) && bcsign(otmp)) - otmp->spe = bcsign(otmp) * rne(3); - else otmp->spe = rn2(2) ? rne(3) : -rne(3); } - /* make useless +0 rings much less common */ - if (otmp->spe == 0) otmp->spe = rn2(4) - rn2(3); - /* negative rings are usually cursed */ - if (otmp->spe < 0 && rn2(5)) curse(otmp); - } else if(rn2(10) && (otmp->otyp == RIN_TELEPORTATION || - otmp->otyp == RIN_POLYMORPH || - otmp->otyp == RIN_AGGRAVATE_MONSTER || - otmp->otyp == RIN_HUNGER || !rn2(9))) { - curse(otmp); - } - break; - case ROCK_CLASS: - switch (otmp->otyp) { + break; + case GEM_CLASS: + otmp->corpsenm = 0; /* LOADSTONE hack */ + if (otmp->otyp == LOADSTONE) + curse(otmp); + else if (otmp->otyp == ROCK) + otmp->quan = (long) rn1(6, 6); + else if (otmp->otyp != LUCKSTONE && !rn2(6)) + otmp->quan = 2L; + else + otmp->quan = 1L; + break; + case TOOL_CLASS: + switch (otmp->otyp) { + case TALLOW_CANDLE: + case WAX_CANDLE: + otmp->spe = 1; + otmp->age = 20L * /* 400 or 200 */ + (long) objects[otmp->otyp].oc_cost; + otmp->lamplit = 0; + otmp->quan = 1L + (long) (rn2(2) ? rn2(7) : 0); + blessorcurse(otmp, 5); + break; + case BRASS_LANTERN: + case OIL_LAMP: + otmp->spe = 1; + otmp->age = (long) rn1(500, 1000); + otmp->lamplit = 0; + blessorcurse(otmp, 5); + break; + case MAGIC_LAMP: + otmp->spe = 1; + otmp->lamplit = 0; + blessorcurse(otmp, 2); + break; + case CHEST: + case LARGE_BOX: + otmp->olocked = !!(rn2(5)); + otmp->otrapped = !(rn2(10)); + case ICE_BOX: + case SACK: + case OILSKIN_SACK: + case BAG_OF_HOLDING: + mkbox_cnts(otmp); + break; + case LEASH: + otmp->leashmon = 0; + break; + case EXPENSIVE_CAMERA: + case TINNING_KIT: + case MAGIC_MARKER: + otmp->spe = rn1(70, 30); + break; + case CAN_OF_GREASE: + otmp->spe = rnd(25); + blessorcurse(otmp, 10); + break; + case CRYSTAL_BALL: + otmp->spe = rnd(5); + blessorcurse(otmp, 2); + break; + case HORN_OF_PLENTY: + case BAG_OF_TRICKS: + otmp->spe = rnd(20); + break; + case FIGURINE: { + int tryct2 = 0; + do + otmp->corpsenm = rndmonnum(); + while (is_human(&mons[otmp->corpsenm]) && tryct2++ < 30); + blessorcurse(otmp, 4); + break; + } + case BELL_OF_OPENING: + otmp->spe = 3; + break; + case MAGIC_FLUTE: + case MAGIC_HARP: + case FROST_HORN: + case FIRE_HORN: + case DRUM_OF_EARTHQUAKE: + otmp->spe = rn1(5, 4); + break; + } + break; + case AMULET_CLASS: + if (otmp->otyp == AMULET_OF_YENDOR) + context.made_amulet = TRUE; + if (rn2(10) && (otmp->otyp == AMULET_OF_STRANGULATION + || otmp->otyp == AMULET_OF_CHANGE + || otmp->otyp == AMULET_OF_RESTFUL_SLEEP)) { + curse(otmp); + } else + blessorcurse(otmp, 10); + case VENOM_CLASS: + case CHAIN_CLASS: + case BALL_CLASS: + break; + case POTION_CLASS: + otmp->fromsink = 0; + if (otmp->otyp == POT_OIL) + otmp->age = MAX_OIL_IN_FLASK; /* amount of oil */ + /* fall through */ + case SCROLL_CLASS: +#ifdef MAIL + if (otmp->otyp != SCR_MAIL) +#endif + blessorcurse(otmp, 4); + break; + case SPBOOK_CLASS: + otmp->spestudied = 0; + blessorcurse(otmp, 17); + break; + case ARMOR_CLASS: + if (rn2(10) + && (otmp->otyp == FUMBLE_BOOTS + || otmp->otyp == LEVITATION_BOOTS + || otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT + || otmp->otyp == GAUNTLETS_OF_FUMBLING || !rn2(11))) { + curse(otmp); + otmp->spe = -rne(3); + } else if (!rn2(10)) { + otmp->blessed = rn2(2); + otmp->spe = rne(3); + } else + blessorcurse(otmp, 10); + if (artif && !rn2(40)) + otmp = mk_artifact(otmp, (aligntyp) A_NONE); + /* simulate lacquered armor for samurai */ + if (Role_if(PM_SAMURAI) && otmp->otyp == SPLINT_MAIL + && (moves <= 1 || In_quest(&u.uz))) { +#ifdef UNIXPC + /* optimizer bitfield bug */ + otmp->oerodeproof = 1; + otmp->rknown = 1; +#else + otmp->oerodeproof = otmp->rknown = 1; +#endif + } + break; + case WAND_CLASS: + if (otmp->otyp == WAN_WISHING) + otmp->spe = rnd(3); + else + otmp->spe = + rn1(5, (objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4); + blessorcurse(otmp, 17); + otmp->recharged = 0; /* used to control recharging */ + break; + case RING_CLASS: + if (objects[otmp->otyp].oc_charged) { + blessorcurse(otmp, 3); + if (rn2(10)) { + if (rn2(10) && bcsign(otmp)) + otmp->spe = bcsign(otmp) * rne(3); + else + otmp->spe = rn2(2) ? rne(3) : -rne(3); + } + /* make useless +0 rings much less common */ + if (otmp->spe == 0) + otmp->spe = rn2(4) - rn2(3); + /* negative rings are usually cursed */ + if (otmp->spe < 0 && rn2(5)) + curse(otmp); + } else if (rn2(10) && (otmp->otyp == RIN_TELEPORTATION + || otmp->otyp == RIN_POLYMORPH + || otmp->otyp == RIN_AGGRAVATE_MONSTER + || otmp->otyp == RIN_HUNGER || !rn2(9))) { + curse(otmp); + } + break; + case ROCK_CLASS: + switch (otmp->otyp) { case STATUE: - /* possibly overridden by mkcorpstat() */ - otmp->corpsenm = rndmonnum(); - if (!verysmall(&mons[otmp->corpsenm]) && - rn2(level_difficulty()/2 + 10) > 10) - (void) add_to_container(otmp, - mkobj(SPBOOK_CLASS,FALSE)); + /* possibly overridden by mkcorpstat() */ + otmp->corpsenm = rndmonnum(); + if (!verysmall(&mons[otmp->corpsenm]) + && rn2(level_difficulty() / 2 + 10) > 10) + (void) add_to_container(otmp, mkobj(SPBOOK_CLASS, FALSE)); + } + break; + case COIN_CLASS: + break; /* do nothing */ + default: + impossible("impossible mkobj %d, sym '%c'.", otmp->otyp, + objects[otmp->otyp].oc_class); + return (struct obj *) 0; } - break; - case COIN_CLASS: - break; /* do nothing */ - default: - impossible("impossible mkobj %d, sym '%c'.", otmp->otyp, - objects[otmp->otyp].oc_class); - return (struct obj *)0; - } /* some things must get done (corpsenm, timers) even if init = 0 */ switch (otmp->otyp) { - case CORPSE: + case CORPSE: if (otmp->corpsenm == NON_PM) { otmp->corpsenm = undead_to_corpse(rndmonnum()); - if (mvitals[otmp->corpsenm].mvflags & (G_NOCORPSE|G_GONE)) - otmp->corpsenm = urole.malenum; + if (mvitals[otmp->corpsenm].mvflags & (G_NOCORPSE | G_GONE)) + otmp->corpsenm = urole.malenum; } - /*FALLTHRU*/ - case STATUE: - case FIGURINE: - if (otmp->corpsenm == NON_PM) otmp->corpsenm = rndmonnum(); - /*FALLTHRU*/ - case EGG: - /* case TIN: */ + /*FALLTHRU*/ + case STATUE: + case FIGURINE: + if (otmp->corpsenm == NON_PM) + otmp->corpsenm = rndmonnum(); + /*FALLTHRU*/ + case EGG: + /* case TIN: */ set_corpsenm(otmp, otmp->corpsenm); break; - case SPE_NOVEL: - { - int novidx = -1; - otmp = oname(otmp, noveltitle(&novidx)); - otmp->novelidx = novidx; - } - break; + case SPE_NOVEL: { + int novidx = -1; + otmp = oname(otmp, noveltitle(&novidx)); + otmp->novelidx = novidx; + } break; } /* unique objects may have an associated artifact entry */ if (objects[otyp].oc_unique && !otmp->oartifact) - otmp = mk_artifact(otmp, (aligntyp)A_NONE); + otmp = mk_artifact(otmp, (aligntyp) A_NONE); otmp->owt = weight(otmp); - return(otmp); + return (otmp); } /* @@ -892,7 +958,7 @@ boolean artif; * to obj->corpsenm. Because some special handling is * required in certain cases, place that handling here * and call this routine in place of the direct assignment. - * + * * If the object was a lizard or lichen corpse: * - ensure that you don't end up with some * other corpse type which has no rot-away timer. @@ -916,31 +982,29 @@ int id; if (obj->timed) { if (obj->otyp == EGG) - when = stop_timer(HATCH_EGG, obj_to_any(obj)); + when = stop_timer(HATCH_EGG, obj_to_any(obj)); else { when = 0L; - obj_stop_timers(obj); /* corpse or figurine */ + obj_stop_timers(obj); /* corpse or figurine */ } } obj->corpsenm = id; - switch(obj->otyp) { - case CORPSE: + switch (obj->otyp) { + case CORPSE: start_corpse_timeout(obj); obj->owt = weight(obj); break; - case FIGURINE: - if (obj->corpsenm != NON_PM - && !dead_species(obj->corpsenm,TRUE) + case FIGURINE: + if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE) && (carried(obj) || mcarried(obj))) attach_fig_transform_timeout(obj); obj->owt = weight(obj); break; - case EGG: - if (obj->corpsenm != NON_PM - && !dead_species(obj->corpsenm,TRUE)) + case EGG: + if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE)) attach_egg_hatch_timeout(obj, when); break; - default: /* tin, etc. */ + default: /* tin, etc. */ obj->owt = weight(obj); break; } @@ -952,28 +1016,29 @@ int id; */ void start_corpse_timeout(body) - struct obj *body; +struct obj *body; { - long when; /* rot away when this old */ - long corpse_age; /* age of corpse */ + long when; /* rot away when this old */ + long corpse_age; /* age of corpse */ int rot_adjust; short action; -#define TAINT_AGE (50L) /* age when corpses go bad */ -#define TROLL_REVIVE_CHANCE 37 /* 1/37 chance for 50 turns ~ 75% chance */ -#define ROT_AGE (250L) /* age when corpses rot away */ +#define TAINT_AGE (50L) /* age when corpses go bad */ +#define TROLL_REVIVE_CHANCE 37 /* 1/37 chance for 50 turns ~ 75% chance */ +#define ROT_AGE (250L) /* age when corpses rot away */ /* lizards and lichen don't rot or revive */ - if (body->corpsenm == PM_LIZARD || body->corpsenm == PM_LICHEN) return; + if (body->corpsenm == PM_LIZARD || body->corpsenm == PM_LICHEN) + return; - action = ROT_CORPSE; /* default action: rot away */ - rot_adjust = in_mklev ? 25 : 10; /* give some variation */ + action = ROT_CORPSE; /* default action: rot away */ + rot_adjust = in_mklev ? 25 : 10; /* give some variation */ corpse_age = monstermoves - body->age; if (corpse_age > ROT_AGE) when = rot_adjust; else when = ROT_AGE - corpse_age; - when += (long)(rnz(rot_adjust) - rot_adjust); + when += (long) (rnz(rot_adjust) - rot_adjust); if (is_rider(&mons[body->corpsenm])) { /* @@ -982,19 +1047,21 @@ start_corpse_timeout(body) */ action = REVIVE_MON; for (when = 12L; when < 500L; when++) - if (!rn2(3)) break; + if (!rn2(3)) + break; } else if (mons[body->corpsenm].mlet == S_TROLL && !body->norevive) { long age; for (age = 2; age <= TAINT_AGE; age++) - if (!rn2(TROLL_REVIVE_CHANCE)) { /* troll revives */ - action = REVIVE_MON; - when = age; - break; + if (!rn2(TROLL_REVIVE_CHANCE)) { /* troll revives */ + action = REVIVE_MON; + when = age; + break; } } - - if (body->norevive) body->norevive = 0; + + if (body->norevive) + body->norevive = 0; (void) start_timer(when, TIMER_OBJECT, action, obj_to_any(body)); } @@ -1005,8 +1072,7 @@ int old_range; { char buf[BUFSZ]; xchar ox, oy; - int new_range = arti_light_radius(obj), - delta = new_range - old_range; + int new_range = arti_light_radius(obj), delta = new_range - old_range; /* radius of light emitting artifact varies by curse/bless state so will change after blessing or cursing */ @@ -1016,23 +1082,22 @@ int old_range; artifacts have to be in use to emit light and monsters' gear won't change bless or curse state */ if (!Blind && get_obj_location(obj, &ox, &oy, 0)) { - *buf = '\0'; - if (iflags.last_msg == PLNMSG_OBJ_GLOWS) - /* we just saw "The glows ." from dipping */ - Strcpy(buf, (obj->quan == 1L) ? "It" : "They"); - else if (carried(obj) || cansee(ox, oy)) - Strcpy(buf, Yname2(obj)); - if (*buf) { - /* initial activation says "dimly" if cursed, - "brightly" if uncursed, and "brilliantly" if blessed; - when changing intensity, using "less brightly" is - straightforward for dimming, but we need "brighter" - rather than "more brightly" for brightening; ugh */ - pline("%s %s %s%s.", - buf, otense(obj, "shine"), - (abs(delta) > 1) ? "much " : "", - (delta > 0) ? "brighter" : "less brightly"); - } + *buf = '\0'; + if (iflags.last_msg == PLNMSG_OBJ_GLOWS) + /* we just saw "The glows ." from dipping */ + Strcpy(buf, (obj->quan == 1L) ? "It" : "They"); + else if (carried(obj) || cansee(ox, oy)) + Strcpy(buf, Yname2(obj)); + if (*buf) { + /* initial activation says "dimly" if cursed, + "brightly" if uncursed, and "brilliantly" if blessed; + when changing intensity, using "less brightly" is + straightforward for dimming, but we need "brighter" + rather than "more brightly" for brightening; ugh */ + pline("%s %s %s%s.", buf, otense(obj, "shine"), + (abs(delta) > 1) ? "much " : "", + (delta > 0) ? "brighter" : "less brightly"); + } } } } @@ -1049,8 +1114,10 @@ register struct obj *otmp; { int old_light = 0; - if (otmp->oclass == COIN_CLASS) return; - if (otmp->lamplit) old_light = arti_light_radius(otmp); + if (otmp->oclass == COIN_CLASS) + return; + if (otmp->lamplit) + old_light = arti_light_radius(otmp); otmp->cursed = 0; otmp->blessed = 1; if (carried(otmp) && confers_luck(otmp)) @@ -1059,7 +1126,8 @@ register struct obj *otmp; otmp->owt = weight(otmp); else if (otmp->otyp == FIGURINE && otmp->timed) (void) stop_timer(FIG_TRANSFORM, obj_to_any(otmp)); - if (otmp->lamplit) maybe_adjust_light(otmp, old_light); + if (otmp->lamplit) + maybe_adjust_light(otmp, old_light); return; } @@ -1069,13 +1137,15 @@ register struct obj *otmp; { int old_light = 0; - if (otmp->lamplit) old_light = arti_light_radius(otmp); + if (otmp->lamplit) + old_light = arti_light_radius(otmp); otmp->blessed = 0; if (carried(otmp) && confers_luck(otmp)) set_moreluck(); else if (otmp->otyp == BAG_OF_HOLDING) otmp->owt = weight(otmp); - if (otmp->lamplit) maybe_adjust_light(otmp, old_light); + if (otmp->lamplit) + maybe_adjust_light(otmp, old_light); } void @@ -1084,12 +1154,15 @@ register struct obj *otmp; { int old_light = 0; - if (otmp->oclass == COIN_CLASS) return; - if (otmp->lamplit) old_light = arti_light_radius(otmp); + if (otmp->oclass == COIN_CLASS) + return; + if (otmp->lamplit) + old_light = arti_light_radius(otmp); otmp->blessed = 0; otmp->cursed = 1; /* welded two-handed weapon interferes with some armor removal */ - if (otmp == uwep && bimanual(uwep)) reset_remarm(); + if (otmp == uwep && bimanual(uwep)) + reset_remarm(); /* rules at top of wield.c state that twoweapon cannot be done with cursed alternate weapon */ if (otmp == uswapwep && u.twoweap) @@ -1100,12 +1173,12 @@ register struct obj *otmp; else if (otmp->otyp == BAG_OF_HOLDING) otmp->owt = weight(otmp); else if (otmp->otyp == FIGURINE) { - if (otmp->corpsenm != NON_PM - && !dead_species(otmp->corpsenm,TRUE) + if (otmp->corpsenm != NON_PM && !dead_species(otmp->corpsenm, TRUE) && (carried(otmp) || mcarried(otmp))) attach_fig_transform_timeout(otmp); } - if (otmp->lamplit) maybe_adjust_light(otmp, old_light); + if (otmp->lamplit) + maybe_adjust_light(otmp, old_light); return; } @@ -1115,7 +1188,8 @@ register struct obj *otmp; { int old_light = 0; - if (otmp->lamplit) old_light = arti_light_radius(otmp); + if (otmp->lamplit) + old_light = arti_light_radius(otmp); otmp->cursed = 0; if (carried(otmp) && confers_luck(otmp)) set_moreluck(); @@ -1123,7 +1197,8 @@ register struct obj *otmp; otmp->owt = weight(otmp); else if (otmp->otyp == FIGURINE && otmp->timed) (void) stop_timer(FIG_TRANSFORM, obj_to_any(otmp)); - if (otmp->lamplit) maybe_adjust_light(otmp, old_light); + if (otmp->lamplit) + maybe_adjust_light(otmp, old_light); return; } @@ -1132,13 +1207,14 @@ blessorcurse(otmp, chance) register struct obj *otmp; register int chance; { - if(otmp->blessed || otmp->cursed) return; + if (otmp->blessed || otmp->cursed) + return; - if(!rn2(chance)) { - if(!rn2(2)) { - curse(otmp); + if (!rn2(chance)) { + if (!rn2(2)) { + curse(otmp); } else { - bless(otmp); + bless(otmp); } } return; @@ -1148,7 +1224,7 @@ int bcsign(otmp) register struct obj *otmp; { - return(!!otmp->blessed - !!otmp->cursed); + return (!!otmp->blessed - !!otmp->cursed); } /* @@ -1172,10 +1248,9 @@ register struct obj *obj; register int cwt = 0; if (obj->otyp == STATUE && obj->corpsenm >= LOW_PM) - wt = (int)obj->quan * - ((int)mons[obj->corpsenm].cwt * 3 / 2); + wt = (int) obj->quan * ((int) mons[obj->corpsenm].cwt * 3 / 2); - for(contents=obj->cobj; contents; contents=contents->nobj) + for (contents = obj->cobj; contents; contents = contents->nobj) cwt += weight(contents); /* * The weight of bags of holding is calculated as the weight @@ -1192,31 +1267,31 @@ register struct obj *obj; * weight equations. */ if (obj->otyp == BAG_OF_HOLDING) - cwt = obj->cursed ? (cwt * 2) : - obj->blessed ? ((cwt + 3) / 4) : - ((cwt + 1) / 2); + cwt = obj->cursed ? (cwt * 2) : obj->blessed ? ((cwt + 3) / 4) + : ((cwt + 1) / 2); return wt + cwt; } if (obj->otyp == CORPSE && obj->corpsenm >= LOW_PM) { long long_wt = obj->quan * (long) mons[obj->corpsenm].cwt; - wt = (long_wt > LARGEST_INT) ? LARGEST_INT : (int)long_wt; - if (obj->oeaten) wt = eaten_stat(wt, obj); + wt = (long_wt > LARGEST_INT) ? LARGEST_INT : (int) long_wt; + if (obj->oeaten) + wt = eaten_stat(wt, obj); return wt; } else if (obj->oclass == FOOD_CLASS && obj->oeaten) { - return eaten_stat((int)obj->quan * wt, obj); + return eaten_stat((int) obj->quan * wt, obj); } else if (obj->oclass == COIN_CLASS) - return (int)((obj->quan + 50L) / 100L); + return (int) ((obj->quan + 50L) / 100L); else if (obj->otyp == HEAVY_IRON_BALL && obj->owt != 0) - return((int)(obj->owt)); /* kludge for "very" heavy iron ball */ - return(wt ? wt*(int)obj->quan : ((int)obj->quan + 1)>>1); + return ((int) (obj->owt)); /* kludge for "very" heavy iron ball */ + return (wt ? wt * (int) obj->quan : ((int) obj->quan + 1) >> 1); } -static int treefruits[] = {APPLE,ORANGE,PEAR,BANANA,EUCALYPTUS_LEAF}; +static int treefruits[] = { APPLE, ORANGE, PEAR, BANANA, EUCALYPTUS_LEAF }; struct obj * -rnd_treefruit_at(x,y) +rnd_treefruit_at(x, y) int x, y; { return mksobj_at(treefruits[rn2(SIZE(treefruits))], x, y, TRUE, FALSE); @@ -1227,25 +1302,24 @@ mkgold(amount, x, y) long amount; int x, y; { - register struct obj *gold = g_at(x,y); + register struct obj *gold = g_at(x, y); if (amount <= 0L) - amount = (long)(1 + rnd(level_difficulty()+2) * rnd(30)); + amount = (long) (1 + rnd(level_difficulty() + 2) * rnd(30)); if (gold) { - gold->quan += amount; + gold->quan += amount; } else { - gold = mksobj_at(GOLD_PIECE, x, y, TRUE, FALSE); - gold->quan = amount; + gold = mksobj_at(GOLD_PIECE, x, y, TRUE, FALSE); + gold->quan = amount; } gold->owt = weight(gold); return (gold); } /* return TRUE if the corpse has special timing */ -#define special_corpse(num) (((num) == PM_LIZARD) \ - || ((num) == PM_LICHEN) \ - || (is_rider(&mons[num])) \ - || (mons[num].mlet == S_TROLL)) +#define special_corpse(num) \ + (((num) == PM_LIZARD) || ((num) == PM_LICHEN) || (is_rider(&mons[num])) \ + || (mons[num].mlet == S_TROLL)) /* * OEXTRA note: Passing mtmp causes mtraits to be saved @@ -1258,7 +1332,7 @@ int x, y; */ struct obj * mkcorpstat(objtype, mtmp, ptr, x, y, corpstatflags) -int objtype; /* CORPSE or STATUE */ +int objtype; /* CORPSE or STATUE */ struct monst *mtmp; struct permonst *ptr; int x, y; @@ -1269,36 +1343,38 @@ unsigned corpstatflags; if (objtype != CORPSE && objtype != STATUE) impossible("making corpstat type %d", objtype); - if (x == 0 && y == 0) { /* special case - random placement */ + if (x == 0 && y == 0) { /* special case - random placement */ otmp = mksobj(objtype, init, FALSE); - if (otmp) (void)rloco(otmp); + if (otmp) + (void) rloco(otmp); } else otmp = mksobj_at(objtype, x, y, init, FALSE); if (otmp) { if (mtmp) { - struct obj *otmp2; + struct obj *otmp2; - if (!ptr) ptr = mtmp->data; - /* save_mtraits frees original data pointed to by otmp */ - otmp2 = save_mtraits(otmp, mtmp); - if (otmp2) otmp = otmp2; + if (!ptr) + ptr = mtmp->data; + /* save_mtraits frees original data pointed to by otmp */ + otmp2 = save_mtraits(otmp, mtmp); + if (otmp2) + otmp = otmp2; } /* use the corpse or statue produced by mksobj() as-is unless `ptr' is non-null */ if (ptr) { - int old_corpsenm = otmp->corpsenm; + int old_corpsenm = otmp->corpsenm; - otmp->corpsenm = monsndx(ptr); - otmp->owt = weight(otmp); - if (otmp->otyp == CORPSE && - (special_corpse(old_corpsenm) || - special_corpse(otmp->corpsenm))) { - obj_stop_timers(otmp); - start_corpse_timeout(otmp); - } + otmp->corpsenm = monsndx(ptr); + otmp->owt = weight(otmp); + if (otmp->otyp == CORPSE && (special_corpse(old_corpsenm) + || special_corpse(otmp->corpsenm))) { + obj_stop_timers(otmp); + start_corpse_timeout(otmp); + } } } - return(otmp); + return (otmp); } /* @@ -1315,8 +1391,8 @@ struct obj *obj; { int revivetype; struct monst *mtmp; - if (has_omonst(obj) && - ((mtmp = get_mtraits(obj, FALSE)) != (struct monst *)0)) { + if (has_omonst(obj) + && ((mtmp = get_mtraits(obj, FALSE)) != (struct monst *) 0)) { /* mtmp is a temporary pointer to a monster's stored attributes, not a real monster */ revivetype = mtmp->mnum; @@ -1334,7 +1410,8 @@ obj_attach_mid(obj, mid) struct obj *obj; unsigned mid; { - if (!mid || !obj) return (struct obj *)0; + if (!mid || !obj) + return (struct obj *) 0; newomid(obj); *OMID(obj) = mid; return obj; @@ -1345,20 +1422,24 @@ save_mtraits(obj, mtmp) struct obj *obj; struct monst *mtmp; { - if (mtmp->ispriest) forget_temple_entry(mtmp); /* EPRI() */ - if (!has_omonst(obj)) newomonst(obj); + if (mtmp->ispriest) + forget_temple_entry(mtmp); /* EPRI() */ + if (!has_omonst(obj)) + newomonst(obj); if (has_omonst(obj)) { struct monst *mtmp2 = OMONST(obj); *mtmp2 = *mtmp; - mtmp2->mextra = (struct mextra *)0; - if (mtmp->data) mtmp2->mnum = monsndx(mtmp->data); + mtmp2->mextra = (struct mextra *) 0; + if (mtmp->data) + mtmp2->mnum = monsndx(mtmp->data); /* invalidate pointers */ /* m_id is needed to know if this is a revived quest leader */ /* but m_id must be cleared when loading bones */ - mtmp2->nmon = (struct monst *)0; - mtmp2->data = (struct permonst *)0; - mtmp2->minvent = (struct obj *)0; - if (mtmp->mextra) copy_mextra(mtmp2, mtmp); + mtmp2->nmon = (struct monst *) 0; + mtmp2->data = (struct permonst *) 0; + mtmp2->minvent = (struct obj *) 0; + if (mtmp->mextra) + copy_mextra(mtmp2, mtmp); } return obj; } @@ -1371,18 +1452,20 @@ get_mtraits(obj, copyof) struct obj *obj; boolean copyof; { - struct monst *mtmp = (struct monst *)0; - struct monst *mnew = (struct monst *)0; + struct monst *mtmp = (struct monst *) 0; + struct monst *mnew = (struct monst *) 0; - if (has_omonst(obj)) mtmp = OMONST(obj); + if (has_omonst(obj)) + mtmp = OMONST(obj); if (mtmp) { if (copyof) { - mnew = newmonst(); - *mnew = *mtmp; - mnew->mextra = (struct mextra *)0; - if (mtmp->mextra) copy_mextra(mnew, mtmp); + mnew = newmonst(); + *mnew = *mtmp; + mnew->mextra = (struct mextra *) 0; + if (mtmp->mextra) + copy_mextra(mnew, mtmp); } else { - /* Never insert this returned pointer into mon chains! */ + /* Never insert this returned pointer into mon chains! */ mnew = mtmp; } } @@ -1402,28 +1485,28 @@ register int x, y; initialize_it = (objtype != STATUE); if ((otmp = mksobj_at(objtype, x, y, initialize_it, FALSE)) != 0) { /* tt_oname will return null if the scoreboard is empty */ - if ((otmp2 = tt_oname(otmp)) != 0) otmp = otmp2; + if ((otmp2 = tt_oname(otmp)) != 0) + otmp = otmp2; } - return(otmp); + return (otmp); } /* make a new corpse or statue, uninitialized if a statue (i.e. no books) */ struct obj * mk_named_object(objtype, ptr, x, y, nm) -int objtype; /* CORPSE or STATUE */ +int objtype; /* CORPSE or STATUE */ struct permonst *ptr; int x, y; const char *nm; { struct obj *otmp; - unsigned corpstatflags = (objtype != STATUE) ? - CORPSTAT_INIT : CORPSTAT_NONE; + unsigned corpstatflags = + (objtype != STATUE) ? CORPSTAT_INIT : CORPSTAT_NONE; - otmp = mkcorpstat(objtype, (struct monst *)0, ptr, - x, y, corpstatflags); + otmp = mkcorpstat(objtype, (struct monst *) 0, ptr, x, y, corpstatflags); if (nm) otmp = oname(otmp, nm); - return(otmp); + return (otmp); } boolean @@ -1443,7 +1526,7 @@ register struct obj *otmp; if (objects[otyp].oc_oprop == FIRE_RES || otyp == WAN_FIRE) return FALSE; - return((boolean)((omat <= WOOD && omat != LIQUID) || omat == PLASTIC)); + return ((boolean)((omat <= WOOD && omat != LIQUID) || omat == PLASTIC)); } boolean @@ -1452,8 +1535,8 @@ register struct obj *otmp; { int otyp = otmp->otyp; - return((boolean)(objects[otyp].oc_material <= WOOD && - objects[otyp].oc_material != LIQUID)); + return ((boolean)(objects[otyp].oc_material <= WOOD + && objects[otyp].oc_material != LIQUID)); } /* @@ -1470,19 +1553,20 @@ int x, y; register struct obj *otmp2 = level.objects[x][y]; if (otmp->where != OBJ_FREE) - panic("place_object: obj not free"); + panic("place_object: obj not free"); obj_no_longer_held(otmp); /* (could bypass this vision update if there is already a boulder here) */ - if (otmp->otyp == BOULDER) block_point(x,y); /* vision */ + if (otmp->otyp == BOULDER) + block_point(x, y); /* vision */ /* obj goes under boulders */ if (otmp2 && (otmp2->otyp == BOULDER)) { - otmp->nexthere = otmp2->nexthere; - otmp2->nexthere = otmp; + otmp->nexthere = otmp2->nexthere; + otmp2->nexthere = otmp; } else { - otmp->nexthere = otmp2; - level.objects[x][y] = otmp; + otmp->nexthere = otmp2; + level.objects[x][y] = otmp; } /* set the new object's location */ @@ -1494,10 +1578,11 @@ int x, y; /* add to floor chain */ otmp->nobj = fobj; fobj = otmp; - if (otmp->timed) obj_timer_checks(otmp, x, y, 0); + if (otmp->timed) + obj_timer_checks(otmp, x, y, 0); } -#define ROT_ICE_ADJUSTMENT 2 /* rotting on ice takes 2 times as long */ +#define ROT_ICE_ADJUSTMENT 2 /* rotting on ice takes 2 times as long */ /* If ice was affecting any objects correct that now * Also used for starting ice effects too. [zap.c] @@ -1510,13 +1595,15 @@ boolean do_buried; struct obj *otmp; for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) { - if (otmp->timed) obj_timer_checks(otmp, x, y, 0); + if (otmp->timed) + obj_timer_checks(otmp, x, y, 0); } if (do_buried) { for (otmp = level.buriedobjlist; otmp; otmp = otmp->nobj) { - if (otmp->ox == x && otmp->oy == y) { - if (otmp->timed) obj_timer_checks(otmp, x, y, 0); - } + if (otmp->ox == x && otmp->oy == y) { + if (otmp->timed) + obj_timer_checks(otmp, x, y, 0); + } } } } @@ -1533,14 +1620,15 @@ peek_at_iced_corpse_age(otmp) struct obj *otmp; { long age, retval = otmp->age; - + if (otmp->otyp == CORPSE && otmp->on_ice) { - /* Adjust the age; must be same as obj_timer_checks() for off ice*/ - age = monstermoves - otmp->age; - retval += age * (ROT_ICE_ADJUSTMENT-1) / ROT_ICE_ADJUSTMENT; - debugpline3("The %s age has ice modifications: otmp->age = %ld, returning %ld.", - s_suffix(doname(otmp)), otmp->age, retval); - debugpline1("Effective age of corpse: %ld.", monstermoves - retval); + /* Adjust the age; must be same as obj_timer_checks() for off ice*/ + age = monstermoves - otmp->age; + retval += age * (ROT_ICE_ADJUSTMENT - 1) / ROT_ICE_ADJUSTMENT; + debugpline3("The %s age has ice modifications: otmp->age = %ld, " + "returning %ld.", + s_suffix(doname(otmp)), otmp->age, retval); + debugpline1("Effective age of corpse: %ld.", monstermoves - retval); } return retval; } @@ -1549,7 +1637,7 @@ STATIC_OVL void obj_timer_checks(otmp, x, y, force) struct obj *otmp; xchar x, y; -int force; /* 0 = no force so do checks, <0 = force off, >0 force on */ +int force; /* 0 = no force so do checks, <0 = force off, >0 force on */ { long tleft = 0L; short action = ROT_CORPSE; @@ -1558,57 +1646,56 @@ int force; /* 0 = no force so do checks, <0 = force off, >0 force on */ boolean buried = (otmp->where == OBJ_BURIED); /* Check for corpses just placed on or in ice */ - if (otmp->otyp == CORPSE && (on_floor || buried) && is_ice(x,y)) { - tleft = stop_timer(action, obj_to_any(otmp)); - if (tleft == 0L) { - action = REVIVE_MON; + if (otmp->otyp == CORPSE && (on_floor || buried) && is_ice(x, y)) { tleft = stop_timer(action, obj_to_any(otmp)); - } - if (tleft != 0L) { - long age; - - /* mark the corpse as being on ice */ - otmp->on_ice = 1; - debugpline3("%s is now on ice at <%d,%d>.", - The(xname(otmp)), x, y); - /* Adjust the time remaining */ - tleft *= ROT_ICE_ADJUSTMENT; - restart_timer = TRUE; - /* Adjust the age; time spent off ice needs to be multiplied - by the ice adjustment and subtracted from the age so that - later calculations behave as if it had been on ice during - that time (longwinded way of saying this is the inverse - of removing it from the ice and of peeking at its age). */ - age = monstermoves - otmp->age; - otmp->age = monstermoves - (age * ROT_ICE_ADJUSTMENT); - } + if (tleft == 0L) { + action = REVIVE_MON; + tleft = stop_timer(action, obj_to_any(otmp)); + } + if (tleft != 0L) { + long age; + + /* mark the corpse as being on ice */ + otmp->on_ice = 1; + debugpline3("%s is now on ice at <%d,%d>.", The(xname(otmp)), x, + y); + /* Adjust the time remaining */ + tleft *= ROT_ICE_ADJUSTMENT; + restart_timer = TRUE; + /* Adjust the age; time spent off ice needs to be multiplied + by the ice adjustment and subtracted from the age so that + later calculations behave as if it had been on ice during + that time (longwinded way of saying this is the inverse + of removing it from the ice and of peeking at its age). */ + age = monstermoves - otmp->age; + otmp->age = monstermoves - (age * ROT_ICE_ADJUSTMENT); + } } /* Check for corpses coming off ice */ - else if ((force < 0) || - (otmp->otyp == CORPSE && otmp->on_ice && - !((on_floor || buried) && is_ice(x,y)))) { - tleft = stop_timer(action, obj_to_any(otmp)); - if (tleft == 0L) { - action = REVIVE_MON; + else if ((force < 0) || (otmp->otyp == CORPSE && otmp->on_ice + && !((on_floor || buried) && is_ice(x, y)))) { tleft = stop_timer(action, obj_to_any(otmp)); - } - if (tleft != 0L) { - long age; + if (tleft == 0L) { + action = REVIVE_MON; + tleft = stop_timer(action, obj_to_any(otmp)); + } + if (tleft != 0L) { + long age; - otmp->on_ice = 0; - debugpline3("%s is no longer on ice at <%d,%d>.", - The(xname(otmp)), x, y); - /* Adjust the remaining time */ - tleft /= ROT_ICE_ADJUSTMENT; - restart_timer = TRUE; - /* Adjust the age */ - age = monstermoves - otmp->age; - otmp->age += age * (ROT_ICE_ADJUSTMENT-1) / ROT_ICE_ADJUSTMENT; + otmp->on_ice = 0; + debugpline3("%s is no longer on ice at <%d,%d>.", + The(xname(otmp)), x, y); + /* Adjust the remaining time */ + tleft /= ROT_ICE_ADJUSTMENT; + restart_timer = TRUE; + /* Adjust the age */ + age = monstermoves - otmp->age; + otmp->age += age * (ROT_ICE_ADJUSTMENT - 1) / ROT_ICE_ADJUSTMENT; + } } - } - /* now re-start the timer with the appropriate modifications */ + /* now re-start the timer with the appropriate modifications */ if (restart_timer) - (void) start_timer(tleft, TIMER_OBJECT, action, obj_to_any(otmp)); + (void) start_timer(tleft, TIMER_OBJECT, action, obj_to_any(otmp)); } #undef ROT_ICE_ADJUSTMENT @@ -1621,13 +1708,14 @@ register struct obj *otmp; xchar y = otmp->oy; if (otmp->where != OBJ_FLOOR) - panic("remove_object: obj not on floor"); + panic("remove_object: obj not on floor"); extract_nexthere(otmp, &level.objects[x][y]); extract_nobj(otmp, &fobj); /* update vision iff this was the only boulder at its spot */ if (otmp->otyp == BOULDER && !sobj_at(BOULDER, x, y)) - unblock_point(x,y); /* vision */ - if (otmp->timed) obj_timer_checks(otmp,x,y,0); + unblock_point(x, y); /* vision */ + if (otmp->timed) + obj_timer_checks(otmp, x, y, 0); } /* throw away all of a monster's inventory */ @@ -1639,17 +1727,18 @@ struct monst *mtmp; boolean keeping_mon = (mtmp->mhp > 0); while ((otmp = mtmp->minvent) != 0) { - /* this has now become very similar to m_useupall()... */ - obj_extract_self(otmp); - if (otmp->owornmask) { - if (keeping_mon) { - if (otmp == mwep) mwepgone(mtmp), mwep = 0; - mtmp->misc_worn_check &= ~otmp->owornmask; - update_mon_intrinsics(mtmp, otmp, FALSE, TRUE); + /* this has now become very similar to m_useupall()... */ + obj_extract_self(otmp); + if (otmp->owornmask) { + if (keeping_mon) { + if (otmp == mwep) + mwepgone(mtmp), mwep = 0; + mtmp->misc_worn_check &= ~otmp->owornmask; + update_mon_intrinsics(mtmp, otmp, FALSE, TRUE); + } + otmp->owornmask = 0L; /* obfree() expects this */ } - otmp->owornmask = 0L; /* obfree() expects this */ - } - obfree(otmp, (struct obj *)0); /* dealloc_obj() isn't sufficient */ + obfree(otmp, (struct obj *) 0); /* dealloc_obj() isn't sufficient */ } } @@ -1670,7 +1759,7 @@ struct monst *mtmp; */ void obj_extract_self(obj) - struct obj *obj; +struct obj *obj; { switch (obj->where) { case OBJ_FREE: @@ -1703,29 +1792,28 @@ obj_extract_self(obj) } } - /* Extract the given object from the chain, following nobj chain. */ void extract_nobj(obj, head_ptr) - struct obj *obj, **head_ptr; +struct obj *obj, **head_ptr; { struct obj *curr, *prev; curr = *head_ptr; for (prev = (struct obj *) 0; curr; prev = curr, curr = curr->nobj) { - if (curr == obj) { - if (prev) - prev->nobj = curr->nobj; - else - *head_ptr = curr->nobj; - break; + if (curr == obj) { + if (prev) + prev->nobj = curr->nobj; + else + *head_ptr = curr->nobj; + break; + } } - } - if (!curr) panic("extract_nobj: object lost"); + if (!curr) + panic("extract_nobj: object lost"); obj->where = OBJ_FREE; } - /* * Extract the given object from the chain, following nexthere chain. * @@ -1734,24 +1822,24 @@ extract_nobj(obj, head_ptr) */ void extract_nexthere(obj, head_ptr) - struct obj *obj, **head_ptr; +struct obj *obj, **head_ptr; { struct obj *curr, *prev; curr = *head_ptr; for (prev = (struct obj *) 0; curr; prev = curr, curr = curr->nexthere) { - if (curr == obj) { - if (prev) - prev->nexthere = curr->nexthere; - else - *head_ptr = curr->nexthere; - break; + if (curr == obj) { + if (prev) + prev->nexthere = curr->nexthere; + else + *head_ptr = curr->nexthere; + break; + } } - } - if (!curr) panic("extract_nexthere: object lost"); + if (!curr) + panic("extract_nexthere: object lost"); } - /* * Add obj to mon's inventory. If obj is able to merge with something already * in the inventory, then the passed obj is deleted and 1 is returned. @@ -1759,24 +1847,24 @@ extract_nexthere(obj, head_ptr) */ int add_to_minv(mon, obj) - struct monst *mon; - struct obj *obj; +struct monst *mon; +struct obj *obj; { struct obj *otmp; if (obj->where != OBJ_FREE) - panic("add_to_minv: obj not free"); + panic("add_to_minv: obj not free"); /* merge if possible */ for (otmp = mon->minvent; otmp; otmp = otmp->nobj) - if (merged(&otmp, &obj)) - return 1; /* obj merged and then free'd */ + if (merged(&otmp, &obj)) + return 1; /* obj merged and then free'd */ /* else insert; don't bother forcing it to end of chain */ obj->where = OBJ_MINVENT; obj->ocarry = mon; obj->nobj = mon->minvent; mon->minvent = obj; - return 0; /* obj on mon's inventory chain */ + return 0; /* obj on mon's inventory chain */ } /* @@ -1785,18 +1873,19 @@ add_to_minv(mon, obj) */ struct obj * add_to_container(container, obj) - struct obj *container, *obj; +struct obj *container, *obj; { struct obj *otmp; if (obj->where != OBJ_FREE) - panic("add_to_container: obj not free"); + panic("add_to_container: obj not free"); if (container->where != OBJ_INVENT && container->where != OBJ_MINVENT) - obj_no_longer_held(obj); + obj_no_longer_held(obj); /* merge if possible */ for (otmp = container->cobj; otmp; otmp = otmp->nobj) - if (merged(&otmp, &obj)) return (otmp); + if (merged(&otmp, &obj)) + return (otmp); obj->where = OBJ_CONTAINED; obj->ocontainer = container; @@ -1807,10 +1896,10 @@ add_to_container(container, obj) void add_to_migration(obj) - struct obj *obj; +struct obj *obj; { if (obj->where != OBJ_FREE) - panic("add_to_migration: obj not free"); + panic("add_to_migration: obj not free"); obj->where = OBJ_MIGRATING; obj->nobj = migrating_objs; @@ -1819,10 +1908,10 @@ add_to_migration(obj) void add_to_buried(obj) - struct obj *obj; +struct obj *obj; { if (obj->where != OBJ_FREE) - panic("add_to_buried: obj not free"); + panic("add_to_buried: obj not free"); obj->where = OBJ_BURIED; obj->nobj = level.buriedobjlist; @@ -1832,15 +1921,15 @@ add_to_buried(obj) /* Recalculate the weight of this container and all of _its_ containers. */ STATIC_OVL void container_weight(container) - struct obj *container; +struct obj *container; { container->owt = weight(container); if (container->where == OBJ_CONTAINED) - container_weight(container->ocontainer); -/* - else if (container->where == OBJ_INVENT) - recalculate load delay here ??? -*/ + container_weight(container->ocontainer); + /* + else if (container->where == OBJ_INVENT) + recalculate load delay here ??? + */ } /* @@ -1849,14 +1938,14 @@ container_weight(container) */ void dealloc_obj(obj) - struct obj *obj; +struct obj *obj; { if (obj->where != OBJ_FREE) - panic("dealloc_obj: obj not free"); + panic("dealloc_obj: obj not free"); /* free up any timers attached to the object */ if (obj->timed) - obj_stop_timers(obj); + obj_stop_timers(obj); /* * Free up any light sources attached to the object. @@ -1867,12 +1956,15 @@ dealloc_obj(obj) * attached to it (and also requires lamplit to be set). */ if (obj_sheds_light(obj)) - del_light_source(LS_OBJECT, obj_to_any(obj)); + del_light_source(LS_OBJECT, obj_to_any(obj)); - if (obj == thrownobj) thrownobj = 0; - if (obj == kickedobj) kickedobj = 0; + if (obj == thrownobj) + thrownobj = 0; + if (obj == kickedobj) + kickedobj = 0; - if (obj->oextra) dealloc_oextra(obj->oextra); + if (obj->oextra) + dealloc_oextra(obj->oextra); free((genericptr_t) obj); } @@ -1880,81 +1972,80 @@ dealloc_obj(obj) int hornoplenty(horn, tipping) struct obj *horn; -boolean tipping; /* caller emptying entire contents; affects shop handling */ +boolean tipping; /* caller emptying entire contents; affects shop handling */ { int objcount = 0; if (!horn || horn->otyp != HORN_OF_PLENTY) { - impossible("bad horn o' plenty"); + impossible("bad horn o' plenty"); } else if (horn->spe < 1) { - pline1(nothing_happens); + pline1(nothing_happens); } else { - struct obj *obj; - const char *what; + struct obj *obj; + const char *what; - consume_obj_charge(horn, !tipping); - if (!rn2(13)) { - obj = mkobj(POTION_CLASS, FALSE); - if (objects[obj->otyp].oc_magic) do { - obj->otyp = rnd_class(POT_BOOZE, POT_WATER); - } while (obj->otyp == POT_SICKNESS); - what = (obj->quan > 1L) ? "Some potions" : "A potion"; - } else { - obj = mkobj(FOOD_CLASS, FALSE); - if (obj->otyp == FOOD_RATION && !rn2(7)) - obj->otyp = LUMP_OF_ROYAL_JELLY; - what = "Some food"; - } - ++objcount; - pline("%s %s out.", what, vtense(what, "spill")); - obj->blessed = horn->blessed; - obj->cursed = horn->cursed; - obj->owt = weight(obj); - /* using a shop's horn of plenty entails a usage fee and also - confers ownership of the created item to the shopkeeper */ - if (horn->unpaid) - addtobill(obj, FALSE, FALSE, tipping); - /* if it ended up on bill, we don't want "(unpaid, N zorkids)" - being included in its formatted name during next message */ - iflags.suppress_price++; - if (!tipping) { - obj = hold_another_object(obj, u.uswallow ? - "Oops! %s out of your reach!" : - (Is_airlevel(&u.uz) || - Is_waterlevel(&u.uz) || - levl[u.ux][u.uy].typ < IRONBARS || - levl[u.ux][u.uy].typ >= ICE) ? - "Oops! %s away from you!" : - "Oops! %s to the floor!", - The(aobjnam(obj, "slip")), - (const char *)0); - } else { - /* assumes this is taking place at hero's location */ - if (!can_reach_floor(TRUE)) { - hitfloor(obj); /* does altar check, message, drop */ + consume_obj_charge(horn, !tipping); + if (!rn2(13)) { + obj = mkobj(POTION_CLASS, FALSE); + if (objects[obj->otyp].oc_magic) + do { + obj->otyp = rnd_class(POT_BOOZE, POT_WATER); + } while (obj->otyp == POT_SICKNESS); + what = (obj->quan > 1L) ? "Some potions" : "A potion"; } else { - if (IS_ALTAR(levl[u.ux][u.uy].typ)) - doaltarobj(obj); /* does its own drop message */ - else - pline("%s %s to the %s.", Doname2(obj), - otense(obj, "drop"), surface(u.ux, u.uy)); - dropy(obj); + obj = mkobj(FOOD_CLASS, FALSE); + if (obj->otyp == FOOD_RATION && !rn2(7)) + obj->otyp = LUMP_OF_ROYAL_JELLY; + what = "Some food"; } - } - iflags.suppress_price--; - if (horn->dknown) makeknown(HORN_OF_PLENTY); + ++objcount; + pline("%s %s out.", what, vtense(what, "spill")); + obj->blessed = horn->blessed; + obj->cursed = horn->cursed; + obj->owt = weight(obj); + /* using a shop's horn of plenty entails a usage fee and also + confers ownership of the created item to the shopkeeper */ + if (horn->unpaid) + addtobill(obj, FALSE, FALSE, tipping); + /* if it ended up on bill, we don't want "(unpaid, N zorkids)" + being included in its formatted name during next message */ + iflags.suppress_price++; + if (!tipping) { + obj = hold_another_object( + obj, u.uswallow ? "Oops! %s out of your reach!" + : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) + || levl[u.ux][u.uy].typ < IRONBARS + || levl[u.ux][u.uy].typ >= ICE) + ? "Oops! %s away from you!" + : "Oops! %s to the floor!", + The(aobjnam(obj, "slip")), (const char *) 0); + } else { + /* assumes this is taking place at hero's location */ + if (!can_reach_floor(TRUE)) { + hitfloor(obj); /* does altar check, message, drop */ + } else { + if (IS_ALTAR(levl[u.ux][u.uy].typ)) + doaltarobj(obj); /* does its own drop message */ + else + pline("%s %s to the %s.", Doname2(obj), + otense(obj, "drop"), surface(u.ux, u.uy)); + dropy(obj); + } + } + iflags.suppress_price--; + if (horn->dknown) + makeknown(HORN_OF_PLENTY); } return objcount; } /* support for wizard-mode's `sanity_check' option */ -static const char NEARDATA /* pline formats for insane_object() */ +static const char NEARDATA /* pline formats for insane_object() */ ofmt0[] = "%s obj %s %s: %s", ofmt3[] = "%s [not null] %s %s: %s", /* " held by mon %p (%s)" will be appended, filled by M,mon_nam(M) */ - mfmt1[] = "%s obj %s %s (%s)", - mfmt2[] = "%s obj %s %s (%s) *not*"; + mfmt1[] = "%s obj %s %s (%s)", mfmt2[] = "%s obj %s %s (%s) *not*"; /* Check all object lists for consistency. */ void @@ -1969,19 +2060,19 @@ obj_sanity_check() those objects should have already been sanity checked via the floor list so container contents are skipped here */ for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - for (obj = level.objects[x][y]; obj; obj = obj->nexthere) { - /* should match ; <0,*> should always be empty */ - if (obj->where != OBJ_FLOOR || x == 0 || - obj->ox != x || obj->oy != y) { - char at_fmt[BUFSZ]; + for (y = 0; y < ROWNO; y++) + for (obj = level.objects[x][y]; obj; obj = obj->nexthere) { + /* should match ; <0,*> should always be empty */ + if (obj->where != OBJ_FLOOR || x == 0 || obj->ox != x + || obj->oy != y) { + char at_fmt[BUFSZ]; - Sprintf(at_fmt, "%%s obj@<%d,%d> %%s %%s: %%s@<%d,%d>", - x, y, obj->ox, obj->oy); - insane_object(obj, at_fmt, "location sanity", - (struct monst *)0); - } - } + Sprintf(at_fmt, "%%s obj@<%d,%d> %%s %%s: %%s@<%d,%d>", x, + y, obj->ox, obj->oy); + insane_object(obj, at_fmt, "location sanity", + (struct monst *) 0); + } + } objlist_sanity(invent, OBJ_INVENT, "invent sanity"); objlist_sanity(migrating_objs, OBJ_MIGRATING, "migrating sanity"); @@ -1993,16 +2084,18 @@ obj_sanity_check() /* monsters temporarily in transit; they should have arrived with hero by the time we get called */ if (mydogs) { - pline("mydogs sanity [not empty]"); - mon_obj_sanity(mydogs, "mydogs minvent sanity"); + pline("mydogs sanity [not empty]"); + mon_obj_sanity(mydogs, "mydogs minvent sanity"); } /* objects temporarily freed from invent/floor lists; they should have arrived somewhere by the time we get called */ if (thrownobj) - insane_object(thrownobj, ofmt3, "thrownobj sanity", (struct monst *)0); + insane_object(thrownobj, ofmt3, "thrownobj sanity", + (struct monst *) 0); if (kickedobj) - insane_object(kickedobj, ofmt3, "kickedobj sanity", (struct monst *)0); + insane_object(kickedobj, ofmt3, "kickedobj sanity", + (struct monst *) 0); /* [how about current_wand too?] */ } @@ -2016,43 +2109,43 @@ const char *mesg; struct obj *obj; for (obj = objlist; obj; obj = obj->nobj) { - if (obj->where != wheretype) - insane_object(obj, ofmt0, mesg, (struct monst *)0); - if (Has_contents(obj)) { - if (wheretype == OBJ_ONBILL) - /* containers on shop bill should always be empty */ - insane_object(obj, "%s obj contains something! %s %s: %s", - mesg, (struct monst *)0); - check_contained(obj, mesg); - } - if (obj->owornmask) { - char maskbuf[40]; - boolean bc_ok = FALSE; + if (obj->where != wheretype) + insane_object(obj, ofmt0, mesg, (struct monst *) 0); + if (Has_contents(obj)) { + if (wheretype == OBJ_ONBILL) + /* containers on shop bill should always be empty */ + insane_object(obj, "%s obj contains something! %s %s: %s", + mesg, (struct monst *) 0); + check_contained(obj, mesg); + } + if (obj->owornmask) { + char maskbuf[40]; + boolean bc_ok = FALSE; - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - sanity_check_worn(obj); - break; - case OBJ_MIGRATING: - /* migrating objects overload the owornmask field - with a destination code; skip attempt to check it */ - break; - case OBJ_FLOOR: - /* note: ball and chain can also be OBJ_FREE, but not across - turns so this sanity check shouldn't encounter that */ - bc_ok = TRUE; - /*FALLTHRU*/ - default: - if ((obj != uchain && obj != uball) || !bc_ok) { - /* discovered an object not in inventory which - erroneously has worn mask set */ - Sprintf(maskbuf, "worn mask 0x%08lx", obj->owornmask); - insane_object(obj, ofmt0, maskbuf, (struct monst *)0); - } - break; - } - } + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + sanity_check_worn(obj); + break; + case OBJ_MIGRATING: + /* migrating objects overload the owornmask field + with a destination code; skip attempt to check it */ + break; + case OBJ_FLOOR: + /* note: ball and chain can also be OBJ_FREE, but not across + turns so this sanity check shouldn't encounter that */ + bc_ok = TRUE; + /*FALLTHRU*/ + default: + if ((obj != uchain && obj != uball) || !bc_ok) { + /* discovered an object not in inventory which + erroneously has worn mask set */ + Sprintf(maskbuf, "worn mask 0x%08lx", obj->owornmask); + insane_object(obj, ofmt0, maskbuf, (struct monst *) 0); + } + break; + } + } } } @@ -2066,33 +2159,34 @@ const char *mesg; struct obj *obj; for (mon = monlist; mon; mon = mon->nmon) - for (obj = mon->minvent; obj; obj = obj->nobj) { - if (obj->where != OBJ_MINVENT) - insane_object(obj, mfmt1, mesg, mon); - if (obj->ocarry != mon) - insane_object(obj, mfmt2, mesg, mon); - check_contained(obj, mesg); - } + for (obj = mon->minvent; obj; obj = obj->nobj) { + if (obj->where != OBJ_MINVENT) + insane_object(obj, mfmt1, mesg, mon); + if (obj->ocarry != mon) + insane_object(obj, mfmt2, mesg, mon); + check_contained(obj, mesg); + } } /* This must stay consistent with the defines in obj.h. */ -static const char *obj_state_names[NOBJ_STATES] = { - "free", "floor", "contained", "invent", - "minvent", "migrating", "buried", "onbill" -}; +static const char *obj_state_names[NOBJ_STATES] = { "free", "floor", + "contained", "invent", + "minvent", "migrating", + "buried", "onbill" }; STATIC_OVL const char * where_name(obj) struct obj *obj; { - static char unknown[32]; /* big enough to handle rogue 64-bit int */ + static char unknown[32]; /* big enough to handle rogue 64-bit int */ int where; - if (!obj) return "nowhere"; + if (!obj) + return "nowhere"; where = obj->where; if (where < 0 || where >= NOBJ_STATES || !obj_state_names[where]) { - Sprintf(unknown, "unknown[%d]", where); - return unknown; + Sprintf(unknown, "unknown[%d]", where); + return unknown; } return obj_state_names[where]; } @@ -2108,64 +2202,65 @@ struct monst *mon; objnm = monnm = "null!"; if (obj) { - iflags.override_ID++; - objnm = doname(obj); - iflags.override_ID--; + iflags.override_ID++; + objnm = doname(obj); + iflags.override_ID--; } if (mon || (strstri(mesg, "minvent") && !strstri(mesg, "contained"))) { - Strcat(strcpy(altfmt, fmt), " held by mon %s (%s)"); - if (mon) - monnm = x_monnam(mon, ARTICLE_A, (char *)0, EXACT_NAME, TRUE); - pline(altfmt, mesg, - fmt_ptr((genericptr_t)obj), where_name(obj), objnm, - fmt_ptr((genericptr_t)mon), monnm); + Strcat(strcpy(altfmt, fmt), " held by mon %s (%s)"); + if (mon) + monnm = x_monnam(mon, ARTICLE_A, (char *) 0, EXACT_NAME, TRUE); + pline(altfmt, mesg, fmt_ptr((genericptr_t) obj), where_name(obj), + objnm, fmt_ptr((genericptr_t) mon), monnm); } else { - pline(fmt, mesg, fmt_ptr((genericptr_t)obj), where_name(obj), objnm); + pline(fmt, mesg, fmt_ptr((genericptr_t) obj), where_name(obj), objnm); } } /* obj sanity check: check objects inside container */ STATIC_OVL void check_contained(container, mesg) - struct obj *container; - const char *mesg; +struct obj *container; +const char *mesg; { struct obj *obj; /* big enough to work with, not too big to blow out stack in recursion */ char mesgbuf[40], nestedmesg[120]; - if (!Has_contents(container)) return; + if (!Has_contents(container)) + return; /* change "invent sanity" to "contained invent sanity" but leave "nested contained invent sanity" as is */ if (!strstri(mesg, "contained")) - mesg = strcat(strcpy(mesgbuf, "contained "), mesg); + mesg = strcat(strcpy(mesgbuf, "contained "), mesg); for (obj = container->cobj; obj; obj = obj->nobj) { - /* catch direct cycle to avoid unbounded recursion */ - if (obj == container) - panic("failed sanity check: container holds itself"); - if (obj->where != OBJ_CONTAINED) - insane_object(obj, "%s obj %s %s: %s", mesg, (struct monst *)0); - else if (obj->ocontainer != container) - pline("%s obj %s in container %s, not %s", mesg, - fmt_ptr((genericptr_t)obj), - fmt_ptr((genericptr_t)obj->ocontainer), - fmt_ptr((genericptr_t)container)); + /* catch direct cycle to avoid unbounded recursion */ + if (obj == container) + panic("failed sanity check: container holds itself"); + if (obj->where != OBJ_CONTAINED) + insane_object(obj, "%s obj %s %s: %s", mesg, (struct monst *) 0); + else if (obj->ocontainer != container) + pline("%s obj %s in container %s, not %s", mesg, + fmt_ptr((genericptr_t) obj), + fmt_ptr((genericptr_t) obj->ocontainer), + fmt_ptr((genericptr_t) container)); - if (Has_contents(obj)) { - /* catch most likely indirect cycle; we won't notice if - parent is present when something comes before it, or - notice more deeply embedded cycles (grandparent, &c) */ - if (obj->cobj == container) - panic("failed sanity check: container holds its parent"); - /* change "contained... sanity" to "nested contained... sanity" - and "nested contained..." to "nested nested contained..." */ - Strcpy(nestedmesg, "nested "); - copynchars(eos(nestedmesg), mesg, - (int)sizeof nestedmesg - (int)strlen(nestedmesg) - 1); - /* recursively check contents */ - check_contained(obj, nestedmesg); - } + if (Has_contents(obj)) { + /* catch most likely indirect cycle; we won't notice if + parent is present when something comes before it, or + notice more deeply embedded cycles (grandparent, &c) */ + if (obj->cobj == container) + panic("failed sanity check: container holds its parent"); + /* change "contained... sanity" to "nested contained... sanity" + and "nested contained..." to "nested nested contained..." */ + Strcpy(nestedmesg, "nested "); + copynchars(eos(nestedmesg), mesg, (int) sizeof nestedmesg + - (int) strlen(nestedmesg) + - 1); + /* recursively check contents */ + check_contained(obj, nestedmesg); + } } } @@ -2176,11 +2271,10 @@ struct obj *obj; { #if defined(BETA) || defined(DEBUG) static unsigned long wearbits[] = { - W_ARM, W_ARMC, W_ARMH, W_ARMS, W_ARMG, W_ARMF, W_ARMU, - W_WEP, W_QUIVER, W_SWAPWEP, W_AMUL, W_RINGL, W_RINGR, - W_TOOL, W_SADDLE, W_BALL, W_CHAIN, - 0 - /* [W_ART,W_ARTI are property bits for items which aren't worn] */ + W_ARM, W_ARMC, W_ARMH, W_ARMS, W_ARMG, W_ARMF, W_ARMU, + W_WEP, W_QUIVER, W_SWAPWEP, W_AMUL, W_RINGL, W_RINGR, W_TOOL, + W_SADDLE, W_BALL, W_CHAIN, 0 + /* [W_ART,W_ARTI are property bits for items which aren't worn] */ }; char maskbuf[60]; const char *what; @@ -2192,133 +2286,172 @@ struct obj *obj; owornmask = obj->owornmask; /* figure out how many bits are set, and also which are viable */ for (i = 0; wearbits[i]; ++i) { - if ((owornmask & wearbits[i]) != 0L) ++n; - allmask |= wearbits[i]; + if ((owornmask & wearbits[i]) != 0L) + ++n; + allmask |= wearbits[i]; } if (n == 2 && carried(obj) && obj == uball && (owornmask & W_BALL) != 0L - && (owornmask & (W_WEP|W_SWAPWEP|W_QUIVER)) != 0L) { - /* chained ball can be wielded/alt-wielded/quivered; if so, - pretend it's not chained in order to check the weapon pointer - (we've already verified the ball pointer by successfully passing - the if-condition to get here...) */ - owornmask &= ~W_BALL; - n = 1; + && (owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)) != 0L) { + /* chained ball can be wielded/alt-wielded/quivered; if so, + pretend it's not chained in order to check the weapon pointer + (we've already verified the ball pointer by successfully passing + the if-condition to get here...) */ + owornmask &= ~W_BALL; + n = 1; } if (n > 1) { - /* multiple bits set */ - Sprintf(maskbuf, "worn mask (multiple) 0x%08lx", obj->owornmask); - insane_object(obj, ofmt0, maskbuf, (struct monst *)0); + /* multiple bits set */ + Sprintf(maskbuf, "worn mask (multiple) 0x%08lx", obj->owornmask); + insane_object(obj, ofmt0, maskbuf, (struct monst *) 0); } if ((owornmask & ~allmask) != 0L - || (carried(obj) && (owornmask & W_SADDLE) != 0L)) { - /* non-wearable bit(s) set */ - Sprintf(maskbuf, "worn mask (bogus)) 0x%08lx", obj->owornmask); - insane_object(obj, ofmt0, maskbuf, (struct monst *)0); + || (carried(obj) && (owornmask & W_SADDLE) != 0L)) { + /* non-wearable bit(s) set */ + Sprintf(maskbuf, "worn mask (bogus)) 0x%08lx", obj->owornmask); + insane_object(obj, ofmt0, maskbuf, (struct monst *) 0); } - if (n == 1 && (carried(obj) || (owornmask & (W_BALL|W_CHAIN)) != 0L)) { - what = 0; - /* verify that obj in hero's invent (or ball/chain elsewhere) - with owornmask of W_foo is the object pointed to by ufoo */ - switch (owornmask) { - case W_ARM: if (obj != uarm) what = "suit"; - break; - case W_ARMC: if (obj != uarmc) what = "cloak"; - break; - case W_ARMH: if (obj != uarmh) what = "helm"; - break; - case W_ARMS: if (obj != uarms) what = "shield"; - break; - case W_ARMG: if (obj != uarmg) what = "gloves"; - break; - case W_ARMF: if (obj != uarmf) what = "boots"; - break; - case W_ARMU: if (obj != uarmu) what = "shirt"; - break; - case W_WEP: if (obj != uwep) what = "primary weapon"; - break; - case W_QUIVER: if (obj != uquiver) what = "quiver"; - break; - case W_SWAPWEP: if (obj != uswapwep) - what = u.twoweap ? "secondary weapon" : "alternate weapon"; - break; - case W_AMUL: if (obj != uamul) what = "amulet"; - break; - case W_RINGL: if (obj != uleft) what = "left ring"; - break; - case W_RINGR: if (obj != uright) what = "right ring"; - break; - case W_TOOL: if (obj != ublindf) what = "blindfold"; - break; - /* case W_SADDLE: */ - case W_BALL: if (obj != uball) what = "ball"; - break; - case W_CHAIN: if (obj != uchain) what = "chain"; - break; - default: break; - } - if (what) { - Sprintf(maskbuf, "worn mask 0x%08lx != %s", obj->owornmask, what); - insane_object(obj, ofmt0, maskbuf, (struct monst *)0); - } + if (n == 1 && (carried(obj) || (owornmask & (W_BALL | W_CHAIN)) != 0L)) { + what = 0; + /* verify that obj in hero's invent (or ball/chain elsewhere) + with owornmask of W_foo is the object pointed to by ufoo */ + switch (owornmask) { + case W_ARM: + if (obj != uarm) + what = "suit"; + break; + case W_ARMC: + if (obj != uarmc) + what = "cloak"; + break; + case W_ARMH: + if (obj != uarmh) + what = "helm"; + break; + case W_ARMS: + if (obj != uarms) + what = "shield"; + break; + case W_ARMG: + if (obj != uarmg) + what = "gloves"; + break; + case W_ARMF: + if (obj != uarmf) + what = "boots"; + break; + case W_ARMU: + if (obj != uarmu) + what = "shirt"; + break; + case W_WEP: + if (obj != uwep) + what = "primary weapon"; + break; + case W_QUIVER: + if (obj != uquiver) + what = "quiver"; + break; + case W_SWAPWEP: + if (obj != uswapwep) + what = u.twoweap ? "secondary weapon" : "alternate weapon"; + break; + case W_AMUL: + if (obj != uamul) + what = "amulet"; + break; + case W_RINGL: + if (obj != uleft) + what = "left ring"; + break; + case W_RINGR: + if (obj != uright) + what = "right ring"; + break; + case W_TOOL: + if (obj != ublindf) + what = "blindfold"; + break; + /* case W_SADDLE: */ + case W_BALL: + if (obj != uball) + what = "ball"; + break; + case W_CHAIN: + if (obj != uchain) + what = "chain"; + break; + default: + break; + } + if (what) { + Sprintf(maskbuf, "worn mask 0x%08lx != %s", obj->owornmask, what); + insane_object(obj, ofmt0, maskbuf, (struct monst *) 0); + } } - if (n == 1 && (carried(obj) || (owornmask & (W_BALL|W_CHAIN)) != 0L - || mcarried(obj))) { - /* check for items worn in invalid slots; practically anything can - be wielded/alt-wielded/quivered, so tests on those are limited */ - what = 0; - if (owornmask & W_ARMOR) { - if (obj->oclass != ARMOR_CLASS) what = "armor"; - } else if (owornmask & (W_WEP|W_SWAPWEP|W_QUIVER)) { - /* monsters don't maintain alternate weapon or quiver */ - if (mcarried(obj) && (owornmask & (W_SWAPWEP|W_QUIVER)) != 0L) - what = (owornmask & W_SWAPWEP) != 0L ? "monst alt weapon?" - : "monst quiver?"; - /* hero can quiver gold but not wield it (hence not alt-wield - it either); also catches monster wielding gold */ - else if (obj->oclass == COIN_CLASS - && (owornmask & (W_WEP|W_SWAPWEP)) != 0L) - what = (owornmask & W_WEP) != 0L ? "weapon" : "alt weapon"; - } else if (owornmask & W_AMUL) { - if (obj->oclass != AMULET_CLASS) what = "amulet"; - } else if (owornmask & W_RING) { - if (obj->oclass != RING_CLASS && obj->otyp != MEAT_RING) - what = "ring"; - } else if (owornmask & W_TOOL) { - if (obj->otyp != BLINDFOLD && obj->otyp != TOWEL - && obj->otyp != LENSES) what = "blindfold"; - } else if (owornmask & W_BALL) { - if (obj->oclass != BALL_CLASS) what = "chained ball"; - } else if (owornmask & W_CHAIN) { - if (obj->oclass != CHAIN_CLASS) what = "chain"; - } else if (owornmask & W_SADDLE) { - if (obj->otyp != SADDLE) what = "saddle"; - } - if (what) { - char oclassname[30]; - struct monst *mon = mcarried(obj) ? obj->ocarry : 0; + if (n == 1 && (carried(obj) || (owornmask & (W_BALL | W_CHAIN)) != 0L + || mcarried(obj))) { + /* check for items worn in invalid slots; practically anything can + be wielded/alt-wielded/quivered, so tests on those are limited */ + what = 0; + if (owornmask & W_ARMOR) { + if (obj->oclass != ARMOR_CLASS) + what = "armor"; + } else if (owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)) { + /* monsters don't maintain alternate weapon or quiver */ + if (mcarried(obj) && (owornmask & (W_SWAPWEP | W_QUIVER)) != 0L) + what = (owornmask & W_SWAPWEP) != 0L ? "monst alt weapon?" + : "monst quiver?"; + /* hero can quiver gold but not wield it (hence not alt-wield + it either); also catches monster wielding gold */ + else if (obj->oclass == COIN_CLASS + && (owornmask & (W_WEP | W_SWAPWEP)) != 0L) + what = (owornmask & W_WEP) != 0L ? "weapon" : "alt weapon"; + } else if (owornmask & W_AMUL) { + if (obj->oclass != AMULET_CLASS) + what = "amulet"; + } else if (owornmask & W_RING) { + if (obj->oclass != RING_CLASS && obj->otyp != MEAT_RING) + what = "ring"; + } else if (owornmask & W_TOOL) { + if (obj->otyp != BLINDFOLD && obj->otyp != TOWEL + && obj->otyp != LENSES) + what = "blindfold"; + } else if (owornmask & W_BALL) { + if (obj->oclass != BALL_CLASS) + what = "chained ball"; + } else if (owornmask & W_CHAIN) { + if (obj->oclass != CHAIN_CLASS) + what = "chain"; + } else if (owornmask & W_SADDLE) { + if (obj->otyp != SADDLE) + what = "saddle"; + } + if (what) { + char oclassname[30]; + struct monst *mon = mcarried(obj) ? obj->ocarry : 0; - /* if we've found a potion worn in the amulet slot, - this yields "worn (potion amulet)" */ - Strcpy(oclassname, def_oc_syms[(uchar)obj->oclass].name); - Sprintf(maskbuf, "worn (%s %s)", - makesingular(oclassname), what); - insane_object(obj, ofmt0, maskbuf, mon); - } + /* if we've found a potion worn in the amulet slot, + this yields "worn (potion amulet)" */ + Strcpy(oclassname, def_oc_syms[(uchar) obj->oclass].name); + Sprintf(maskbuf, "worn (%s %s)", makesingular(oclassname), what); + insane_object(obj, ofmt0, maskbuf, mon); + } } -#else /* not (BETA || DEBUG) */ +#else /* not (BETA || DEBUG) */ /* dummy use of obj to avoid "arg not used" complaint */ - if (!obj) insane_object(obj, ofmt0, "", (struct monst *)0); + if (!obj) + insane_object(obj, ofmt0, "", (struct monst *) 0); #endif } -/* +/* * wrapper to make "near this object" convenient */ -struct obj* +struct obj * obj_nexto(otmp) - struct obj* otmp; +struct obj *otmp; { - struct obj* otmp2 = NULL; + struct obj *otmp2 = NULL; if (otmp) { otmp2 = obj_nexto_xy(otmp->otyp, otmp->ox, otmp->oy, otmp->o_id); @@ -2329,21 +2462,20 @@ obj_nexto(otmp) return otmp2; } - /* * looks for objects of a particular type next to x, y * skips over oid if found (lets us avoid ourselves if * we're looking for a second type of an existing object) * * TODO: return a list of all objects near us so we can more - * reliably predict which one we want to 'find' first + * reliably predict which one we want to 'find' first */ -struct obj* +struct obj * obj_nexto_xy(otyp, x, y, oid) int otyp, x, y; unsigned oid; { - struct obj* otmp; + struct obj *otmp; int fx, fy, ex, ey; short dx, dy; @@ -2351,10 +2483,12 @@ unsigned oid; otmp = sobj_at(otyp, x, y); while (otmp) { /* don't be clever and find ourselves */ - if (otmp->o_id != oid) { return otmp; } + if (otmp->o_id != oid) { + return otmp; + } otmp = nxtobj(otmp, otyp, TRUE); } - + /* search in a random order */ dx = (rn2(2) ? -1 : 1); dy = (rn2(2) ? -1 : 1); @@ -2364,7 +2498,7 @@ unsigned oid; for (fx = ex; abs(fx - ex) < 3; fx += dx) { for (fy = ey; abs(fy - ey) < 3; fy += dy) { /* 0, 0 was checked above */ - if (isok(fx,fy) && (fx != x || fy != y)) { + if (isok(fx, fy) && (fx != x || fy != y)) { if ((otmp = sobj_at(otyp, fx, fy)) != 0) { return otmp; } @@ -2374,15 +2508,14 @@ unsigned oid; return NULL; } - /* - * Causes one object to absorb another, increasing + * Causes one object to absorb another, increasing * weight accordingly. Frees obj2; obj1 remains and * is returned. */ -struct obj* +struct obj * obj_absorb(obj1, obj2) - struct obj **obj1, **obj2; +struct obj **obj1, **obj2; { struct obj *otmp1 = NULL, *otmp2 = NULL; int extrawt = 0; @@ -2408,15 +2541,14 @@ obj_absorb(obj1, obj2) return NULL; } - /* * Causes the heavier object to absorb the lighter object; * wrapper for obj_absorb so that floor_effects works more * cleanly (since we don't know which we want to stay around) */ -struct obj* +struct obj * obj_meld(obj1, obj2) - struct obj **obj1, **obj2; +struct obj **obj1, **obj2; { struct obj *otmp1 = NULL, *otmp2 = NULL; diff --git a/src/mkroom.c b/src/mkroom.c index cd2093ab4..50953ab13 100644 --- a/src/mkroom.c +++ b/src/mkroom.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mkroom.c $NHDT-Date: 1427239202 2015/03/24 23:20:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ +/* NetHack 3.6 mkroom.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */ /* NetHack 3.6 mkroom.c $Date: 2012/01/10 17:47:19 $ $Revision: 1.15 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -18,162 +18,187 @@ #include "hack.h" STATIC_DCL boolean FDECL(isbig, (struct mkroom *)); -STATIC_DCL struct mkroom * FDECL(pick_room,(BOOLEAN_P)); -STATIC_DCL void NDECL(mkshop), FDECL(mkzoo,(int)), NDECL(mkswamp); +STATIC_DCL struct mkroom *FDECL(pick_room, (BOOLEAN_P)); +STATIC_DCL void NDECL(mkshop), FDECL(mkzoo, (int)), NDECL(mkswamp); STATIC_DCL void NDECL(mktemple); -STATIC_DCL coord * FDECL(shrine_pos, (int)); -STATIC_DCL struct permonst * NDECL(morguemon); -STATIC_DCL struct permonst * NDECL(squadmon); -STATIC_DCL void FDECL(save_room, (int,struct mkroom *)); -STATIC_DCL void FDECL(rest_room, (int,struct mkroom *)); +STATIC_DCL coord *FDECL(shrine_pos, (int)); +STATIC_DCL struct permonst *NDECL(morguemon); +STATIC_DCL struct permonst *NDECL(squadmon); +STATIC_DCL void FDECL(save_room, (int, struct mkroom *)); +STATIC_DCL void FDECL(rest_room, (int, struct mkroom *)); -#define sq(x) ((x)*(x)) +#define sq(x) ((x) * (x)) -extern const struct shclass shtypes[]; /* defined in shknam.c */ +extern const struct shclass shtypes[]; /* defined in shknam.c */ STATIC_OVL boolean isbig(sroom) register struct mkroom *sroom; { - register int area = (sroom->hx - sroom->lx + 1) - * (sroom->hy - sroom->ly + 1); - return((boolean)( area > 20 )); + register int area = + (sroom->hx - sroom->lx + 1) * (sroom->hy - sroom->ly + 1); + return ((boolean)(area > 20)); } void mkroom(roomtype) /* make and stock a room of a given type */ -int roomtype; +int roomtype; { if (roomtype >= SHOPBASE) - mkshop(); /* someday, we should be able to specify shop type */ - else switch(roomtype) { - case COURT: mkzoo(COURT); break; - case ZOO: mkzoo(ZOO); break; - case BEEHIVE: mkzoo(BEEHIVE); break; - case MORGUE: mkzoo(MORGUE); break; - case BARRACKS: mkzoo(BARRACKS); break; - case SWAMP: mkswamp(); break; - case TEMPLE: mktemple(); break; - case LEPREHALL: mkzoo(LEPREHALL); break; - case COCKNEST: mkzoo(COCKNEST); break; - case ANTHOLE: mkzoo(ANTHOLE); break; - default: impossible("Tried to make a room of type %d.", roomtype); - } + mkshop(); /* someday, we should be able to specify shop type */ + else + switch (roomtype) { + case COURT: + mkzoo(COURT); + break; + case ZOO: + mkzoo(ZOO); + break; + case BEEHIVE: + mkzoo(BEEHIVE); + break; + case MORGUE: + mkzoo(MORGUE); + break; + case BARRACKS: + mkzoo(BARRACKS); + break; + case SWAMP: + mkswamp(); + break; + case TEMPLE: + mktemple(); + break; + case LEPREHALL: + mkzoo(LEPREHALL); + break; + case COCKNEST: + mkzoo(COCKNEST); + break; + case ANTHOLE: + mkzoo(ANTHOLE); + break; + default: + impossible("Tried to make a room of type %d.", roomtype); + } } STATIC_OVL void mkshop() { - register struct mkroom *sroom; - int i = -1; - char *ep = (char *)0; /* (init == lint suppression) */ + register struct mkroom *sroom; + int i = -1; + char *ep = (char *) 0; /* (init == lint suppression) */ - /* first determine shoptype */ - if(wizard){ + /* first determine shoptype */ + if (wizard) { #ifndef MAC - ep = nh_getenv("SHOPTYPE"); - if(ep){ - if(*ep == 'z' || *ep == 'Z'){ - mkzoo(ZOO); - return; - } - if(*ep == 'm' || *ep == 'M'){ - mkzoo(MORGUE); - return; - } - if(*ep == 'b' || *ep == 'B'){ - mkzoo(BEEHIVE); - return; - } - if(*ep == 't' || *ep == 'T' || *ep == '\\'){ - mkzoo(COURT); - return; - } - if(*ep == 's' || *ep == 'S'){ - mkzoo(BARRACKS); - return; - } - if(*ep == 'a' || *ep == 'A'){ - mkzoo(ANTHOLE); - return; - } - if(*ep == 'c' || *ep == 'C'){ - mkzoo(COCKNEST); - return; - } - if(*ep == 'l' || *ep == 'L'){ - mkzoo(LEPREHALL); - return; - } - if(*ep == '_'){ - mktemple(); - return; - } - if(*ep == '}'){ - mkswamp(); - return; - } - for(i=0; shtypes[i].name; i++) - if(*ep == def_oc_syms[(int)shtypes[i].symb].sym) - goto gottype; - if(*ep == 'g' || *ep == 'G') - i = 0; - else if (*ep == 'v' || *ep == 'V') - i = FODDERSHOP - SHOPBASE; /* veggy food */ - else - i = -1; - } + ep = nh_getenv("SHOPTYPE"); + if (ep) { + if (*ep == 'z' || *ep == 'Z') { + mkzoo(ZOO); + return; + } + if (*ep == 'm' || *ep == 'M') { + mkzoo(MORGUE); + return; + } + if (*ep == 'b' || *ep == 'B') { + mkzoo(BEEHIVE); + return; + } + if (*ep == 't' || *ep == 'T' || *ep == '\\') { + mkzoo(COURT); + return; + } + if (*ep == 's' || *ep == 'S') { + mkzoo(BARRACKS); + return; + } + if (*ep == 'a' || *ep == 'A') { + mkzoo(ANTHOLE); + return; + } + if (*ep == 'c' || *ep == 'C') { + mkzoo(COCKNEST); + return; + } + if (*ep == 'l' || *ep == 'L') { + mkzoo(LEPREHALL); + return; + } + if (*ep == '_') { + mktemple(); + return; + } + if (*ep == '}') { + mkswamp(); + return; + } + for (i = 0; shtypes[i].name; i++) + if (*ep == def_oc_syms[(int) shtypes[i].symb].sym) + goto gottype; + if (*ep == 'g' || *ep == 'G') + i = 0; + else if (*ep == 'v' || *ep == 'V') + i = FODDERSHOP - SHOPBASE; /* veggy food */ + else + i = -1; + } #endif - } + } #ifndef MAC gottype: #endif - for(sroom = &rooms[0]; ; sroom++){ - if(sroom->hx < 0) return; - if(sroom - rooms >= nroom) { - pline("rooms not closed by -1?"); - return; - } - if(sroom->rtype != OROOM) continue; - if(has_dnstairs(sroom) || has_upstairs(sroom)) - continue; - if( (wizard && ep && sroom->doorct != 0) || sroom->doorct == 1) - break; - } - if (!sroom->rlit) { - int x, y; + for (sroom = &rooms[0];; sroom++) { + if (sroom->hx < 0) + return; + if (sroom - rooms >= nroom) { + pline("rooms not closed by -1?"); + return; + } + if (sroom->rtype != OROOM) + continue; + if (has_dnstairs(sroom) || has_upstairs(sroom)) + continue; + if ((wizard && ep && sroom->doorct != 0) || sroom->doorct == 1) + break; + } + if (!sroom->rlit) { + int x, y; - for(x = sroom->lx - 1; x <= sroom->hx + 1; x++) - for(y = sroom->ly - 1; y <= sroom->hy + 1; y++) - levl[x][y].lit = 1; - sroom->rlit = 1; - } + for (x = sroom->lx - 1; x <= sroom->hx + 1; x++) + for (y = sroom->ly - 1; y <= sroom->hy + 1; y++) + levl[x][y].lit = 1; + sroom->rlit = 1; + } - if(i < 0) { /* shoptype not yet determined */ - register int j; + if (i < 0) { /* shoptype not yet determined */ + register int j; - /* pick a shop type at random */ - for (j = rnd(100), i = 0; (j -= shtypes[i].prob) > 0; i++) - continue; + /* pick a shop type at random */ + for (j = rnd(100), i = 0; (j -= shtypes[i].prob) > 0; i++) + continue; - /* big rooms cannot be wand or book shops, - * - so make them general stores - */ - if(isbig(sroom) && (shtypes[i].symb == WAND_CLASS - || shtypes[i].symb == SPBOOK_CLASS)) i = 0; - } - sroom->rtype = SHOPBASE + i; + /* big rooms cannot be wand or book shops, + * - so make them general stores + */ + if (isbig(sroom) && (shtypes[i].symb == WAND_CLASS + || shtypes[i].symb == SPBOOK_CLASS)) + i = 0; + } + sroom->rtype = SHOPBASE + i; - /* set room bits before stocking the shop */ +/* set room bits before stocking the shop */ #ifdef SPECIALIZATION - topologize(sroom, FALSE); /* doesn't matter - this is a special room */ + topologize(sroom, FALSE); /* doesn't matter - this is a special room */ #else - topologize(sroom); + topologize(sroom); #endif - /* stock the room with a shopkeeper and artifacts */ - stock_room(i, sroom); + /* stock the room with a shopkeeper and artifacts */ + stock_room(i, sroom); } STATIC_OVL struct mkroom * @@ -181,199 +206,207 @@ pick_room(strict) register boolean strict; /* pick an unused room, preferably with only one door */ { - register struct mkroom *sroom; - register int i = nroom; + register struct mkroom *sroom; + register int i = nroom; - for(sroom = &rooms[rn2(nroom)]; i--; sroom++) { - if(sroom == &rooms[nroom]) - sroom = &rooms[0]; - if(sroom->hx < 0) - return (struct mkroom *)0; - if(sroom->rtype != OROOM) continue; - if(!strict) { - if(has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3))) - continue; - } else if(has_upstairs(sroom) || has_dnstairs(sroom)) - continue; - if(sroom->doorct == 1 || !rn2(5) || wizard) - return sroom; - } - return (struct mkroom *)0; + for (sroom = &rooms[rn2(nroom)]; i--; sroom++) { + if (sroom == &rooms[nroom]) + sroom = &rooms[0]; + if (sroom->hx < 0) + return (struct mkroom *) 0; + if (sroom->rtype != OROOM) + continue; + if (!strict) { + if (has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3))) + continue; + } else if (has_upstairs(sroom) || has_dnstairs(sroom)) + continue; + if (sroom->doorct == 1 || !rn2(5) || wizard) + return sroom; + } + return (struct mkroom *) 0; } STATIC_OVL void mkzoo(type) int type; { - register struct mkroom *sroom; + register struct mkroom *sroom; - if ((sroom = pick_room(FALSE)) != 0) { - sroom->rtype = type; - fill_zoo(sroom); - } + if ((sroom = pick_room(FALSE)) != 0) { + sroom->rtype = type; + fill_zoo(sroom); + } } void fill_zoo(sroom) struct mkroom *sroom; { - struct monst *mon; - register int sx,sy,i; - int sh, tx = 0, ty = 0, goldlim = 0, type = sroom->rtype; - int rmno = (int)((sroom - rooms) + ROOMOFFSET); - coord mm; + struct monst *mon; + register int sx, sy, i; + int sh, tx = 0, ty = 0, goldlim = 0, type = sroom->rtype; + int rmno = (int) ((sroom - rooms) + ROOMOFFSET); + coord mm; - sh = sroom->fdoor; - switch(type) { - case COURT: - if(level.flags.is_maze_lev) { - for(tx = sroom->lx; tx <= sroom->hx; tx++) - for(ty = sroom->ly; ty <= sroom->hy; ty++) - if(IS_THRONE(levl[tx][ty].typ)) - goto throne_placed; - } - i = 100; - do { /* don't place throne on top of stairs */ - (void) somexy(sroom, &mm); - tx = mm.x; ty = mm.y; - } while (occupied((xchar)tx, (xchar)ty) && --i > 0); - throne_placed: - /* TODO: try to ensure the enthroned monster is an M2_PRINCE */ - break; - case BEEHIVE: - tx = sroom->lx + (sroom->hx - sroom->lx + 1)/2; - ty = sroom->ly + (sroom->hy - sroom->ly + 1)/2; - if(sroom->irregular) { - /* center might not be valid, so put queen elsewhere */ - if ((int) levl[tx][ty].roomno != rmno || - levl[tx][ty].edge) { - (void) somexy(sroom, &mm); - tx = mm.x; ty = mm.y; - } - } - break; - case ZOO: - case LEPREHALL: - goldlim = 500 * level_difficulty(); - break; - } - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++) { - if(sroom->irregular) { - if ((int) levl[sx][sy].roomno != rmno || - levl[sx][sy].edge || - (sroom->doorct && - distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1)) - continue; - } else if(!SPACE_POS(levl[sx][sy].typ) || - (sroom->doorct && - ((sx == sroom->lx && doors[sh].x == sx-1) || - (sx == sroom->hx && doors[sh].x == sx+1) || - (sy == sroom->ly && doors[sh].y == sy-1) || - (sy == sroom->hy && doors[sh].y == sy+1)))) - continue; - /* don't place monster on explicitly placed throne */ - if(type == COURT && IS_THRONE(levl[sx][sy].typ)) - continue; - mon = makemon( - (type == COURT) ? courtmon() : - (type == BARRACKS) ? squadmon() : - (type == MORGUE) ? morguemon() : - (type == BEEHIVE) ? - (sx == tx && sy == ty ? &mons[PM_QUEEN_BEE] : - &mons[PM_KILLER_BEE]) : - (type == LEPREHALL) ? &mons[PM_LEPRECHAUN] : - (type == COCKNEST) ? &mons[PM_COCKATRICE] : - (type == ANTHOLE) ? antholemon() : - (struct permonst *) 0, - sx, sy, NO_MM_FLAGS); - if(mon) { - mon->msleeping = 1; - if (type==COURT && mon->mpeaceful) { - mon->mpeaceful = 0; - set_malign(mon); - } - } - switch(type) { - case ZOO: - case LEPREHALL: - if(sroom->doorct) - { - int distval = dist2(sx,sy,doors[sh].x,doors[sh].y); - i = sq(distval); - } - else - i = goldlim; - if(i >= goldlim) i = 5*level_difficulty(); - goldlim -= i; - (void) mkgold((long) rn1(i, 10), sx, sy); - break; - case MORGUE: - if(!rn2(5)) - (void) mk_tt_object(CORPSE, sx, sy); - if(!rn2(10)) /* lots of treasure buried with dead */ - (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, - sx, sy, TRUE, FALSE); - if (!rn2(5)) - make_grave(sx, sy, (char *)0); - break; - case BEEHIVE: - if(!rn2(3)) - (void) mksobj_at(LUMP_OF_ROYAL_JELLY, - sx, sy, TRUE, FALSE); - break; - case BARRACKS: - if(!rn2(20)) /* the payroll and some loot */ - (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, - sx, sy, TRUE, FALSE); - break; - case COCKNEST: - if(!rn2(3)) { - struct obj *sobj = mk_tt_object(STATUE, sx, sy); + sh = sroom->fdoor; + switch (type) { + case COURT: + if (level.flags.is_maze_lev) { + for (tx = sroom->lx; tx <= sroom->hx; tx++) + for (ty = sroom->ly; ty <= sroom->hy; ty++) + if (IS_THRONE(levl[tx][ty].typ)) + goto throne_placed; + } + i = 100; + do { /* don't place throne on top of stairs */ + (void) somexy(sroom, &mm); + tx = mm.x; + ty = mm.y; + } while (occupied((xchar) tx, (xchar) ty) && --i > 0); + throne_placed: + /* TODO: try to ensure the enthroned monster is an M2_PRINCE */ + break; + case BEEHIVE: + tx = sroom->lx + (sroom->hx - sroom->lx + 1) / 2; + ty = sroom->ly + (sroom->hy - sroom->ly + 1) / 2; + if (sroom->irregular) { + /* center might not be valid, so put queen elsewhere */ + if ((int) levl[tx][ty].roomno != rmno || levl[tx][ty].edge) { + (void) somexy(sroom, &mm); + tx = mm.x; + ty = mm.y; + } + } + break; + case ZOO: + case LEPREHALL: + goldlim = 500 * level_difficulty(); + break; + } + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) { + if (sroom->irregular) { + if ((int) levl[sx][sy].roomno != rmno || levl[sx][sy].edge + || (sroom->doorct + && distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1)) + continue; + } else if (!SPACE_POS(levl[sx][sy].typ) + || (sroom->doorct + && ((sx == sroom->lx && doors[sh].x == sx - 1) + || (sx == sroom->hx && doors[sh].x == sx + 1) + || (sy == sroom->ly && doors[sh].y == sy - 1) + || (sy == sroom->hy + && doors[sh].y == sy + 1)))) + continue; + /* don't place monster on explicitly placed throne */ + if (type == COURT && IS_THRONE(levl[sx][sy].typ)) + continue; + mon = makemon( + (type == COURT) + ? courtmon() + : (type == BARRACKS) + ? squadmon() + : (type == MORGUE) + ? morguemon() + : (type == BEEHIVE) + ? (sx == tx && sy == ty + ? &mons[PM_QUEEN_BEE] + : &mons[PM_KILLER_BEE]) + : (type == LEPREHALL) + ? &mons[PM_LEPRECHAUN] + : (type == COCKNEST) + ? &mons[PM_COCKATRICE] + : (type == ANTHOLE) + ? antholemon() + : (struct permonst + *) 0, + sx, sy, NO_MM_FLAGS); + if (mon) { + mon->msleeping = 1; + if (type == COURT && mon->mpeaceful) { + mon->mpeaceful = 0; + set_malign(mon); + } + } + switch (type) { + case ZOO: + case LEPREHALL: + if (sroom->doorct) { + int distval = dist2(sx, sy, doors[sh].x, doors[sh].y); + i = sq(distval); + } else + i = goldlim; + if (i >= goldlim) + i = 5 * level_difficulty(); + goldlim -= i; + (void) mkgold((long) rn1(i, 10), sx, sy); + break; + case MORGUE: + if (!rn2(5)) + (void) mk_tt_object(CORPSE, sx, sy); + if (!rn2(10)) /* lots of treasure buried with dead */ + (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, sx, sy, + TRUE, FALSE); + if (!rn2(5)) + make_grave(sx, sy, (char *) 0); + break; + case BEEHIVE: + if (!rn2(3)) + (void) mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy, TRUE, + FALSE); + break; + case BARRACKS: + if (!rn2(20)) /* the payroll and some loot */ + (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, sx, sy, + TRUE, FALSE); + break; + case COCKNEST: + if (!rn2(3)) { + struct obj *sobj = mk_tt_object(STATUE, sx, sy); - if (sobj) { - for (i = rn2(5); i; i--) - (void) add_to_container(sobj, - mkobj(RANDOM_CLASS, FALSE)); - sobj->owt = weight(sobj); - } - } - break; - case ANTHOLE: - if(!rn2(3)) - (void) mkobj_at(FOOD_CLASS, sx, sy, FALSE); - break; - } - } - switch (type) { - case COURT: - { - struct obj *chest; - levl[tx][ty].typ = THRONE; - (void) somexy(sroom, &mm); - (void) mkgold((long) rn1(50 * level_difficulty(),10), mm.x, mm.y); - /* the royal coffers */ - chest = mksobj_at(CHEST, mm.x, mm.y, TRUE, FALSE); - chest->spe = 2; /* so it can be found later */ - level.flags.has_court = 1; - break; - } - case BARRACKS: - level.flags.has_barracks = 1; - break; - case ZOO: - level.flags.has_zoo = 1; - break; - case MORGUE: - level.flags.has_morgue = 1; - break; - case SWAMP: - level.flags.has_swamp = 1; - break; - case BEEHIVE: - level.flags.has_beehive = 1; - break; - } + if (sobj) { + for (i = rn2(5); i; i--) + (void) add_to_container( + sobj, mkobj(RANDOM_CLASS, FALSE)); + sobj->owt = weight(sobj); + } + } + break; + case ANTHOLE: + if (!rn2(3)) + (void) mkobj_at(FOOD_CLASS, sx, sy, FALSE); + break; + } + } + switch (type) { + case COURT: { + struct obj *chest; + levl[tx][ty].typ = THRONE; + (void) somexy(sroom, &mm); + (void) mkgold((long) rn1(50 * level_difficulty(), 10), mm.x, mm.y); + /* the royal coffers */ + chest = mksobj_at(CHEST, mm.x, mm.y, TRUE, FALSE); + chest->spe = 2; /* so it can be found later */ + level.flags.has_court = 1; + break; + } + case BARRACKS: + level.flags.has_barracks = 1; + break; + case ZOO: + level.flags.has_zoo = 1; + break; + case MORGUE: + level.flags.has_morgue = 1; + break; + case SWAMP: + level.flags.has_swamp = 1; + break; + case BEEHIVE: + level.flags.has_beehive = 1; + break; + } } /* make a swarm of undead around mm */ @@ -383,196 +416,205 @@ coord *mm; boolean revive_corpses; int mm_flags; { - int cnt = (level_difficulty() + 1)/10 + rnd(5); - struct permonst *mdat; - struct obj *otmp; - coord cc; + int cnt = (level_difficulty() + 1) / 10 + rnd(5); + struct permonst *mdat; + struct obj *otmp; + coord cc; - while (cnt--) { - mdat = morguemon(); - if (enexto(&cc, mm->x, mm->y, mdat) && - (!revive_corpses || - !(otmp = sobj_at(CORPSE, cc.x, cc.y)) || - !revive(otmp, FALSE))) - (void) makemon(mdat, cc.x, cc.y, mm_flags); - } - level.flags.graveyard = TRUE; /* reduced chance for undead corpse */ + while (cnt--) { + mdat = morguemon(); + if (enexto(&cc, mm->x, mm->y, mdat) + && (!revive_corpses || !(otmp = sobj_at(CORPSE, cc.x, cc.y)) + || !revive(otmp, FALSE))) + (void) makemon(mdat, cc.x, cc.y, mm_flags); + } + level.flags.graveyard = TRUE; /* reduced chance for undead corpse */ } STATIC_OVL struct permonst * morguemon() { - register int i = rn2(100), hd = rn2(level_difficulty()); + register int i = rn2(100), hd = rn2(level_difficulty()); - if(hd > 10 && i < 10) { - if (Inhell || In_endgame(&u.uz)) { - return(mkclass(S_DEMON,0)); - } else { - int ndemon_res = ndemon(A_NONE); - if (ndemon_res != NON_PM) - return(&mons[ndemon_res]); - /* else do what? As is, it will drop to ghost/wraith/zombie */ - } - } + if (hd > 10 && i < 10) { + if (Inhell || In_endgame(&u.uz)) { + return (mkclass(S_DEMON, 0)); + } else { + int ndemon_res = ndemon(A_NONE); + if (ndemon_res != NON_PM) + return (&mons[ndemon_res]); + /* else do what? As is, it will drop to ghost/wraith/zombie */ + } + } - if(hd > 8 && i > 85) - return(mkclass(S_VAMPIRE,0)); + if (hd > 8 && i > 85) + return (mkclass(S_VAMPIRE, 0)); - return((i < 20) ? &mons[PM_GHOST] - : (i < 40) ? &mons[PM_WRAITH] : mkclass(S_ZOMBIE,0)); + return ((i < 20) ? &mons[PM_GHOST] : (i < 40) ? &mons[PM_WRAITH] + : mkclass(S_ZOMBIE, 0)); } struct permonst * antholemon() { - int mtyp, indx, trycnt = 0; + int mtyp, indx, trycnt = 0; - /* casts are for dealing with time_t */ - indx = (int)((long)ubirthday % 3L); - indx += level_difficulty(); - /* Same monsters within a level, different ones between levels */ - do { - switch ((indx + trycnt) % 3) { - case 0: mtyp = PM_SOLDIER_ANT; break; - case 1: mtyp = PM_FIRE_ANT; break; - default: mtyp = PM_GIANT_ANT; break; - } - /* try again if chosen type has been genocided or used up */ - } while (++trycnt < 3 && (mvitals[mtyp].mvflags & G_GONE)); - return ((mvitals[mtyp].mvflags & G_GONE) ? - (struct permonst *)0 : &mons[mtyp]); + /* casts are for dealing with time_t */ + indx = (int) ((long) ubirthday % 3L); + indx += level_difficulty(); + /* Same monsters within a level, different ones between levels */ + do { + switch ((indx + trycnt) % 3) { + case 0: + mtyp = PM_SOLDIER_ANT; + break; + case 1: + mtyp = PM_FIRE_ANT; + break; + default: + mtyp = PM_GIANT_ANT; + break; + } + /* try again if chosen type has been genocided or used up */ + } while (++trycnt < 3 && (mvitals[mtyp].mvflags & G_GONE)); + return ((mvitals[mtyp].mvflags & G_GONE) ? (struct permonst *) 0 + : &mons[mtyp]); } -STATIC_OVL void -mkswamp() /* Michiel Huisjes & Fred de Wilde */ +STATIC_OVL void mkswamp() /* Michiel Huisjes & Fred de Wilde */ { - register struct mkroom *sroom; - register int sx,sy,i,eelct = 0; + register struct mkroom *sroom; + register int sx, sy, i, eelct = 0; - for(i=0; i<5; i++) { /* turn up to 5 rooms swampy */ - sroom = &rooms[rn2(nroom)]; - if(sroom->hx < 0 || sroom->rtype != OROOM || - has_upstairs(sroom) || has_dnstairs(sroom)) - continue; + for (i = 0; i < 5; i++) { /* turn up to 5 rooms swampy */ + sroom = &rooms[rn2(nroom)]; + if (sroom->hx < 0 || sroom->rtype != OROOM || has_upstairs(sroom) + || has_dnstairs(sroom)) + continue; - /* satisfied; make a swamp */ - sroom->rtype = SWAMP; - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++) - if(!OBJ_AT(sx, sy) && - !MON_AT(sx, sy) && !t_at(sx,sy) && !nexttodoor(sx,sy)) { - if((sx+sy)%2) { - levl[sx][sy].typ = POOL; - if(!eelct || !rn2(4)) { - /* mkclass() won't do, as we might get kraken */ - (void) makemon(rn2(5) ? &mons[PM_GIANT_EEL] - : rn2(2) ? &mons[PM_PIRANHA] - : &mons[PM_ELECTRIC_EEL], - sx, sy, NO_MM_FLAGS); - eelct++; - } - } else - if(!rn2(4)) /* swamps tend to be moldy */ - (void) makemon(mkclass(S_FUNGUS,0), - sx, sy, NO_MM_FLAGS); - } - level.flags.has_swamp = 1; - } + /* satisfied; make a swamp */ + sroom->rtype = SWAMP; + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) + if (!OBJ_AT(sx, sy) && !MON_AT(sx, sy) && !t_at(sx, sy) + && !nexttodoor(sx, sy)) { + if ((sx + sy) % 2) { + levl[sx][sy].typ = POOL; + if (!eelct || !rn2(4)) { + /* mkclass() won't do, as we might get kraken */ + (void) makemon( + rn2(5) ? &mons[PM_GIANT_EEL] + : rn2(2) ? &mons[PM_PIRANHA] + : &mons[PM_ELECTRIC_EEL], + sx, sy, NO_MM_FLAGS); + eelct++; + } + } else if (!rn2(4)) /* swamps tend to be moldy */ + (void) makemon(mkclass(S_FUNGUS, 0), sx, sy, + NO_MM_FLAGS); + } + level.flags.has_swamp = 1; + } } STATIC_OVL coord * shrine_pos(roomno) int roomno; { - static coord buf; - int delta; - struct mkroom *troom = &rooms[roomno - ROOMOFFSET]; + static coord buf; + int delta; + struct mkroom *troom = &rooms[roomno - ROOMOFFSET]; - /* if width and height are odd, placement will be the exact center; - if either or both are even, center point is a hypothetical spot - between map locations and placement will be adjacent to that */ - delta = troom->hx - troom->lx; - buf.x = troom->lx + delta / 2; - if ((delta % 2) && rn2(2)) buf.x++; - delta = troom->hy - troom->ly; - buf.y = troom->ly + delta / 2; - if ((delta % 2) && rn2(2)) buf.y++; - return &buf; + /* if width and height are odd, placement will be the exact center; + if either or both are even, center point is a hypothetical spot + between map locations and placement will be adjacent to that */ + delta = troom->hx - troom->lx; + buf.x = troom->lx + delta / 2; + if ((delta % 2) && rn2(2)) + buf.x++; + delta = troom->hy - troom->ly; + buf.y = troom->ly + delta / 2; + if ((delta % 2) && rn2(2)) + buf.y++; + return &buf; } STATIC_OVL void mktemple() { - register struct mkroom *sroom; - coord *shrine_spot; - register struct rm *lev; + register struct mkroom *sroom; + coord *shrine_spot; + register struct rm *lev; - if(!(sroom = pick_room(TRUE))) return; + if (!(sroom = pick_room(TRUE))) + return; - /* set up Priest and shrine */ - sroom->rtype = TEMPLE; - /* - * In temples, shrines are blessed altars - * located in the center of the room - */ - shrine_spot = shrine_pos((int)((sroom - rooms) + ROOMOFFSET)); - lev = &levl[shrine_spot->x][shrine_spot->y]; - lev->typ = ALTAR; - lev->altarmask = induced_align(80); - priestini(&u.uz, sroom, shrine_spot->x, shrine_spot->y, FALSE); - lev->altarmask |= AM_SHRINE; - level.flags.has_temple = 1; + /* set up Priest and shrine */ + sroom->rtype = TEMPLE; + /* + * In temples, shrines are blessed altars + * located in the center of the room + */ + shrine_spot = shrine_pos((int) ((sroom - rooms) + ROOMOFFSET)); + lev = &levl[shrine_spot->x][shrine_spot->y]; + lev->typ = ALTAR; + lev->altarmask = induced_align(80); + priestini(&u.uz, sroom, shrine_spot->x, shrine_spot->y, FALSE); + lev->altarmask |= AM_SHRINE; + level.flags.has_temple = 1; } boolean -nexttodoor(sx,sy) +nexttodoor(sx, sy) register int sx, sy; { - register int dx, dy; - register struct rm *lev; - for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) { - if(!isok(sx+dx, sy+dy)) continue; - if(IS_DOOR((lev = &levl[sx+dx][sy+dy])->typ) || - lev->typ == SDOOR) - return(TRUE); - } - return(FALSE); + register int dx, dy; + register struct rm *lev; + for (dx = -1; dx <= 1; dx++) + for (dy = -1; dy <= 1; dy++) { + if (!isok(sx + dx, sy + dy)) + continue; + if (IS_DOOR((lev = &levl[sx + dx][sy + dy])->typ) + || lev->typ == SDOOR) + return (TRUE); + } + return (FALSE); } boolean has_dnstairs(sroom) register struct mkroom *sroom; { - if (sroom == dnstairs_room) - return TRUE; - if (sstairs.sx && !sstairs.up) - return((boolean)(sroom == sstairs_room)); - return FALSE; + if (sroom == dnstairs_room) + return TRUE; + if (sstairs.sx && !sstairs.up) + return ((boolean)(sroom == sstairs_room)); + return FALSE; } boolean has_upstairs(sroom) register struct mkroom *sroom; { - if (sroom == upstairs_room) - return TRUE; - if (sstairs.sx && sstairs.up) - return((boolean)(sroom == sstairs_room)); - return FALSE; + if (sroom == upstairs_room) + return TRUE; + if (sstairs.sx && sstairs.up) + return ((boolean)(sroom == sstairs_room)); + return FALSE; } int somex(croom) register struct mkroom *croom; { - return rn1(croom->hx - croom->lx + 1, croom->lx); + return rn1(croom->hx - croom->lx + 1, croom->lx); } int somey(croom) register struct mkroom *croom; { - return rn1(croom->hy - croom->ly + 1, croom->ly); + return rn1(croom->hy - croom->ly + 1, croom->ly); } boolean @@ -580,8 +622,8 @@ inside_room(croom, x, y) struct mkroom *croom; xchar x, y; { - return((boolean)(x >= croom->lx-1 && x <= croom->hx+1 && - y >= croom->ly-1 && y <= croom->hy+1)); + return ((boolean)(x >= croom->lx - 1 && x <= croom->hx + 1 + && y >= croom->ly - 1 && y <= croom->hy + 1)); } boolean @@ -589,50 +631,50 @@ somexy(croom, c) struct mkroom *croom; coord *c; { - int try_cnt = 0; - int i; + int try_cnt = 0; + int i; - if (croom->irregular) { - i = (int)((croom - rooms) + ROOMOFFSET); + if (croom->irregular) { + i = (int) ((croom - rooms) + ROOMOFFSET); - while(try_cnt++ < 100) { - c->x = somex(croom); - c->y = somey(croom); - if (!levl[c->x][c->y].edge && - (int) levl[c->x][c->y].roomno == i) - return TRUE; - } - /* try harder; exhaustively search until one is found */ - for(c->x = croom->lx; c->x <= croom->hx; c->x++) - for(c->y = croom->ly; c->y <= croom->hy; c->y++) - if (!levl[c->x][c->y].edge && - (int) levl[c->x][c->y].roomno == i) - return TRUE; - return FALSE; - } + while (try_cnt++ < 100) { + c->x = somex(croom); + c->y = somey(croom); + if (!levl[c->x][c->y].edge && (int) levl[c->x][c->y].roomno == i) + return TRUE; + } + /* try harder; exhaustively search until one is found */ + for (c->x = croom->lx; c->x <= croom->hx; c->x++) + for (c->y = croom->ly; c->y <= croom->hy; c->y++) + if (!levl[c->x][c->y].edge + && (int) levl[c->x][c->y].roomno == i) + return TRUE; + return FALSE; + } - if (!croom->nsubrooms) { - c->x = somex(croom); - c->y = somey(croom); - return TRUE; - } + if (!croom->nsubrooms) { + c->x = somex(croom); + c->y = somey(croom); + return TRUE; + } - /* Check that coords doesn't fall into a subroom or into a wall */ + /* Check that coords doesn't fall into a subroom or into a wall */ - while(try_cnt++ < 100) { - c->x = somex(croom); - c->y = somey(croom); - if (IS_WALL(levl[c->x][c->y].typ)) - continue; - for(i=0 ; insubrooms;i++) - if(inside_room(croom->sbrooms[i], c->x, c->y)) - goto you_lose; - break; -you_lose: ; - } - if (try_cnt >= 100) - return FALSE; - return TRUE; + while (try_cnt++ < 100) { + c->x = somex(croom); + c->y = somey(croom); + if (IS_WALL(levl[c->x][c->y].typ)) + continue; + for (i = 0; i < croom->nsubrooms; i++) + if (inside_room(croom->sbrooms[i], c->x, c->y)) + goto you_lose; + break; + you_lose: + ; + } + if (try_cnt >= 100) + return FALSE; + return TRUE; } /* @@ -646,64 +688,75 @@ struct mkroom * search_special(type) schar type; { - register struct mkroom *croom; + register struct mkroom *croom; - for(croom = &rooms[0]; croom->hx >= 0; croom++) - if((type == ANY_TYPE && croom->rtype != OROOM) || - (type == ANY_SHOP && croom->rtype >= SHOPBASE) || - croom->rtype == type) - return croom; - for(croom = &subrooms[0]; croom->hx >= 0; croom++) - if((type == ANY_TYPE && croom->rtype != OROOM) || - (type == ANY_SHOP && croom->rtype >= SHOPBASE) || - croom->rtype == type) - return croom; - return (struct mkroom *) 0; + for (croom = &rooms[0]; croom->hx >= 0; croom++) + if ((type == ANY_TYPE && croom->rtype != OROOM) + || (type == ANY_SHOP && croom->rtype >= SHOPBASE) + || croom->rtype == type) + return croom; + for (croom = &subrooms[0]; croom->hx >= 0; croom++) + if ((type == ANY_TYPE && croom->rtype != OROOM) + || (type == ANY_SHOP && croom->rtype >= SHOPBASE) + || croom->rtype == type) + return croom; + return (struct mkroom *) 0; } struct permonst * courtmon() { - int i = rn2(60) + rn2(3*level_difficulty()); - if (i > 100) return(mkclass(S_DRAGON,0)); - else if (i > 95) return(mkclass(S_GIANT,0)); - else if (i > 85) return(mkclass(S_TROLL,0)); - else if (i > 75) return(mkclass(S_CENTAUR,0)); - else if (i > 60) return(mkclass(S_ORC,0)); - else if (i > 45) return(&mons[PM_BUGBEAR]); - else if (i > 30) return(&mons[PM_HOBGOBLIN]); - else if (i > 15) return(mkclass(S_GNOME,0)); - else return(mkclass(S_KOBOLD,0)); + int i = rn2(60) + rn2(3 * level_difficulty()); + if (i > 100) + return (mkclass(S_DRAGON, 0)); + else if (i > 95) + return (mkclass(S_GIANT, 0)); + else if (i > 85) + return (mkclass(S_TROLL, 0)); + else if (i > 75) + return (mkclass(S_CENTAUR, 0)); + else if (i > 60) + return (mkclass(S_ORC, 0)); + else if (i > 45) + return (&mons[PM_BUGBEAR]); + else if (i > 30) + return (&mons[PM_HOBGOBLIN]); + else if (i > 15) + return (mkclass(S_GNOME, 0)); + else + return (mkclass(S_KOBOLD, 0)); } #define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1) static struct { - unsigned pm; - unsigned prob; -} squadprob[NSTYPES] = { - {PM_SOLDIER, 80}, {PM_SERGEANT, 15}, {PM_LIEUTENANT, 4}, {PM_CAPTAIN, 1} -}; + unsigned pm; + unsigned prob; +} squadprob[NSTYPES] = { { PM_SOLDIER, 80 }, + { PM_SERGEANT, 15 }, + { PM_LIEUTENANT, 4 }, + { PM_CAPTAIN, 1 } }; -STATIC_OVL struct permonst * -squadmon() /* return soldier types. */ +STATIC_OVL struct permonst *squadmon() /* return soldier types. */ { - int sel_prob, i, cpro, mndx; + int sel_prob, i, cpro, mndx; - sel_prob = rnd(80+level_difficulty()); + sel_prob = rnd(80 + level_difficulty()); - cpro = 0; - for (i = 0; i < NSTYPES; i++) { - cpro += squadprob[i].prob; - if (cpro > sel_prob) { - mndx = squadprob[i].pm; - goto gotone; - } - } - mndx = squadprob[rn2(NSTYPES)].pm; + cpro = 0; + for (i = 0; i < NSTYPES; i++) { + cpro += squadprob[i].prob; + if (cpro > sel_prob) { + mndx = squadprob[i].pm; + goto gotone; + } + } + mndx = squadprob[rn2(NSTYPES)].pm; gotone: - if (!(mvitals[mndx].mvflags & G_GONE)) return(&mons[mndx]); - else return((struct permonst *) 0); + if (!(mvitals[mndx].mvflags & G_GONE)) + return (&mons[mndx]); + else + return ((struct permonst *) 0); } /* @@ -713,18 +766,18 @@ gotone: STATIC_OVL void save_room(fd, r) -int fd; +int fd; struct mkroom *r; { - short i; - /* - * Well, I really should write only useful information instead - * of writing the whole structure. That is I should not write - * the subrooms pointers, but who cares ? - */ - bwrite(fd, (genericptr_t) r, sizeof(struct mkroom)); - for(i=0; insubrooms; i++) - save_room(fd, r->sbrooms[i]); + short i; + /* + * Well, I really should write only useful information instead + * of writing the whole structure. That is I should not write + * the subrooms pointers, but who cares ? + */ + bwrite(fd, (genericptr_t) r, sizeof(struct mkroom)); + for (i = 0; i < r->nsubrooms; i++) + save_room(fd, r->sbrooms[i]); } /* @@ -735,12 +788,12 @@ void save_rooms(fd) int fd; { - short i; + short i; - /* First, write the number of rooms */ - bwrite(fd, (genericptr_t) &nroom, sizeof(nroom)); - for(i=0; insubrooms; i++) { - r->sbrooms[i] = &subrooms[nsubroom]; - rest_room(fd, &subrooms[nsubroom]); - subrooms[nsubroom++].resident = (struct monst *)0; - } + mread(fd, (genericptr_t) r, sizeof(struct mkroom)); + for (i = 0; i < r->nsubrooms; i++) { + r->sbrooms[i] = &subrooms[nsubroom]; + rest_room(fd, &subrooms[nsubroom]); + subrooms[nsubroom++].resident = (struct monst *) 0; + } } /* @@ -765,18 +818,18 @@ struct mkroom *r; void rest_rooms(fd) -int fd; +int fd; { - short i; + short i; - mread(fd, (genericptr_t) &nroom, sizeof(nroom)); - nsubroom = 0; - for(i = 0; i -STATIC_DCL boolean FDECL(restrap,(struct monst *)); -STATIC_DCL long FDECL(mm_aggression, (struct monst *,struct monst *)); -STATIC_DCL long FDECL(mm_displacement, (struct monst *,struct monst *)); +STATIC_DCL boolean FDECL(restrap, (struct monst *)); +STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *)); +STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *)); STATIC_DCL int NDECL(pick_animal); STATIC_DCL void FDECL(kill_eggs, (struct obj *)); STATIC_DCL void FDECL(dealloc_mextra, (struct mextra *)); STATIC_DCL int FDECL(pickvampshape, (struct monst *)); STATIC_DCL boolean FDECL(isspecmon, (struct monst *)); -STATIC_DCL boolean FDECL(validspecmon, (struct monst *,int)); -STATIC_DCL boolean FDECL(validvamp, (struct monst *,int *,int)); +STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int)); +STATIC_DCL boolean FDECL(validvamp, (struct monst *, int *, int)); STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int)); #define LEVEL_SPECIFIC_NOCORPSE(mdat) \ - (Is_rogue_level(&u.uz) || \ - (level.flags.graveyard && is_undead(mdat) && rn2(3))) + (Is_rogue_level(&u.uz) \ + || (level.flags.graveyard && is_undead(mdat) && rn2(3))) #if 0 /* part of the original warning code which was replaced in 3.3.1 */ @@ -35,7 +35,7 @@ const char *warnings[] = { }; #endif /* 0 */ -STATIC_DCL struct obj *FDECL(make_corpse,(struct monst *, unsigned)); +STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned)); STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *)); STATIC_DCL void FDECL(lifesaved_monster, (struct monst *)); @@ -46,27 +46,44 @@ int mndx; { switch (mndx) { case PM_KOBOLD_ZOMBIE: - case PM_KOBOLD_MUMMY: mndx = PM_KOBOLD; break; + case PM_KOBOLD_MUMMY: + mndx = PM_KOBOLD; + break; case PM_DWARF_ZOMBIE: - case PM_DWARF_MUMMY: mndx = PM_DWARF; break; + case PM_DWARF_MUMMY: + mndx = PM_DWARF; + break; case PM_GNOME_ZOMBIE: - case PM_GNOME_MUMMY: mndx = PM_GNOME; break; + case PM_GNOME_MUMMY: + mndx = PM_GNOME; + break; case PM_ORC_ZOMBIE: - case PM_ORC_MUMMY: mndx = PM_ORC; break; + case PM_ORC_MUMMY: + mndx = PM_ORC; + break; case PM_ELF_ZOMBIE: - case PM_ELF_MUMMY: mndx = PM_ELF; break; + case PM_ELF_MUMMY: + mndx = PM_ELF; + break; case PM_VAMPIRE: case PM_VAMPIRE_LORD: -#if 0 /* DEFERRED */ +#if 0 /* DEFERRED */ case PM_VAMPIRE_MAGE: #endif case PM_HUMAN_ZOMBIE: - case PM_HUMAN_MUMMY: mndx = PM_HUMAN; break; + case PM_HUMAN_MUMMY: + mndx = PM_HUMAN; + break; case PM_GIANT_ZOMBIE: - case PM_GIANT_MUMMY: mndx = PM_GIANT; break; + case PM_GIANT_MUMMY: + mndx = PM_GIANT; + break; case PM_ETTIN_ZOMBIE: - case PM_ETTIN_MUMMY: mndx = PM_ETTIN; break; - default: break; + case PM_ETTIN_MUMMY: + mndx = PM_ETTIN; + break; + default: + break; } return mndx; } @@ -82,28 +99,59 @@ genus(mndx, mode) int mndx, mode; { switch (mndx) { -/* Quest guardians */ - case PM_STUDENT: mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN; break; - case PM_CHIEFTAIN: mndx = mode ? PM_BARBARIAN : PM_HUMAN; break; - case PM_NEANDERTHAL: mndx = mode ? PM_CAVEMAN : PM_HUMAN; break; - case PM_ATTENDANT: mndx = mode ? PM_HEALER : PM_HUMAN; break; - case PM_PAGE: mndx = mode ? PM_KNIGHT : PM_HUMAN; break; - case PM_ABBOT: mndx = mode ? PM_MONK : PM_HUMAN; break; - case PM_ACOLYTE: mndx = mode ? PM_PRIEST : PM_HUMAN; break; - case PM_HUNTER: mndx = mode ? PM_RANGER : PM_HUMAN; break; - case PM_THUG: mndx = mode ? PM_ROGUE : PM_HUMAN; break; - case PM_ROSHI: mndx = mode ? PM_SAMURAI : PM_HUMAN; break; - case PM_GUIDE: mndx = mode ? PM_TOURIST : PM_HUMAN; break; - case PM_APPRENTICE: mndx = mode ? PM_WIZARD : PM_HUMAN; break; - case PM_WARRIOR: mndx = mode ? PM_VALKYRIE : PM_HUMAN; break; + /* Quest guardians */ + case PM_STUDENT: + mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN; + break; + case PM_CHIEFTAIN: + mndx = mode ? PM_BARBARIAN : PM_HUMAN; + break; + case PM_NEANDERTHAL: + mndx = mode ? PM_CAVEMAN : PM_HUMAN; + break; + case PM_ATTENDANT: + mndx = mode ? PM_HEALER : PM_HUMAN; + break; + case PM_PAGE: + mndx = mode ? PM_KNIGHT : PM_HUMAN; + break; + case PM_ABBOT: + mndx = mode ? PM_MONK : PM_HUMAN; + break; + case PM_ACOLYTE: + mndx = mode ? PM_PRIEST : PM_HUMAN; + break; + case PM_HUNTER: + mndx = mode ? PM_RANGER : PM_HUMAN; + break; + case PM_THUG: + mndx = mode ? PM_ROGUE : PM_HUMAN; + break; + case PM_ROSHI: + mndx = mode ? PM_SAMURAI : PM_HUMAN; + break; + case PM_GUIDE: + mndx = mode ? PM_TOURIST : PM_HUMAN; + break; + case PM_APPRENTICE: + mndx = mode ? PM_WIZARD : PM_HUMAN; + break; + case PM_WARRIOR: + mndx = mode ? PM_VALKYRIE : PM_HUMAN; + break; default: if (mndx >= LOW_PM && mndx < NUMMONS) { struct permonst *ptr = &mons[mndx]; - if (is_human(ptr)) mndx = PM_HUMAN; - else if (is_elf(ptr)) mndx = PM_ELF; - else if (is_dwarf(ptr)) mndx = PM_DWARF; - else if (is_gnome(ptr)) mndx = PM_GNOME; - else if (is_orc(ptr)) mndx = PM_ORC; + if (is_human(ptr)) + mndx = PM_HUMAN; + else if (is_elf(ptr)) + mndx = PM_ELF; + else if (is_dwarf(ptr)) + mndx = PM_DWARF; + else if (is_gnome(ptr)) + mndx = PM_GNOME; + else if (is_orc(ptr)) + mndx = PM_ORC; } break; } @@ -121,20 +169,21 @@ int mndx; * As of 3.5.0 we just check M2_SHAPESHIFTER instead of having a * big switch statement with hardcoded shapeshifter types here. */ - if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx])) mcham = mndx; + if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx])) + mcham = mndx; return mcham; } /* for deciding whether corpse will carry along full monster data */ -#define KEEPTRAITS(mon) ((mon)->isshk || (mon)->mtame || \ - unique_corpstat(mon->data) || \ - is_reviver((mon)->data) || \ - /* normally leader the will be unique, */ \ - /* but he might have been polymorphed */ \ - (mon)->m_id == quest_status.leader_m_id || \ - /* special cancellation handling for these */ \ - (dmgtype((mon)->data, AD_SEDU) || \ - dmgtype((mon)->data, AD_SSEX))) +#define KEEPTRAITS(mon) \ + ( \ + (mon)->isshk || (mon)->mtame || unique_corpstat(mon->data) \ + || is_reviver((mon)->data) \ + || /* normally leader the will be unique, */ /* but he might have \ + been polymorphed */ \ + (mon)->m_id == quest_status.leader_m_id \ + || /* special cancellation handling for these */ \ + (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX))) /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't * leave corpses. Monsters which leave "special" corpses should have @@ -142,32 +191,32 @@ int mndx; * etc.... */ STATIC_OVL struct obj * -make_corpse(mtmp,corpseflags) +make_corpse(mtmp, corpseflags) register struct monst *mtmp; unsigned corpseflags; { register struct permonst *mdat = mtmp->data; int num; - struct obj *obj = (struct obj *)0; - struct obj* otmp = (struct obj*)0; + struct obj *obj = (struct obj *) 0; + struct obj *otmp = (struct obj *) 0; int x = mtmp->mx, y = mtmp->my; int mndx = monsndx(mdat); unsigned corpstatflags = corpseflags; boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0); - switch(mndx) { - case PM_GRAY_DRAGON: - case PM_SILVER_DRAGON: -#if 0 /* DEFERRED */ + switch (mndx) { + case PM_GRAY_DRAGON: + case PM_SILVER_DRAGON: +#if 0 /* DEFERRED */ case PM_SHIMMERING_DRAGON: #endif - case PM_RED_DRAGON: - case PM_ORANGE_DRAGON: - case PM_WHITE_DRAGON: - case PM_BLACK_DRAGON: - case PM_BLUE_DRAGON: - case PM_GREEN_DRAGON: - case PM_YELLOW_DRAGON: + case PM_RED_DRAGON: + case PM_ORANGE_DRAGON: + case PM_WHITE_DRAGON: + case PM_BLACK_DRAGON: + case PM_BLUE_DRAGON: + case PM_GREEN_DRAGON: + case PM_YELLOW_DRAGON: /* Make dragon scales. This assumes that the order of the */ /* dragons is the same as the order of the scales. */ if (!rn2(mtmp->mrevived ? 20 : 3)) { @@ -178,143 +227,145 @@ unsigned corpseflags; } goto default_1; - case PM_WHITE_UNICORN: - case PM_GRAY_UNICORN: - case PM_BLACK_UNICORN: + case PM_WHITE_UNICORN: + case PM_GRAY_UNICORN: + case PM_BLACK_UNICORN: if (mtmp->mrevived && rn2(2)) { if (canseemon(mtmp)) - pline("%s recently regrown horn crumbles to dust.", - s_suffix(Monnam(mtmp))); + pline("%s recently regrown horn crumbles to dust.", + s_suffix(Monnam(mtmp))); } else { obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE); - if (obj && mtmp->mrevived) obj->degraded_horn = 1; + if (obj && mtmp->mrevived) + obj->degraded_horn = 1; } goto default_1; - case PM_LONG_WORM: + case PM_LONG_WORM: (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE); goto default_1; - case PM_VAMPIRE: - case PM_VAMPIRE_LORD: + case PM_VAMPIRE: + case PM_VAMPIRE_LORD: /* include mtmp in the mkcorpstat() call */ num = undead_to_corpse(mndx); corpstatflags |= CORPSTAT_INIT; obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags); - obj->age -= 100; /* this is an *OLD* corpse */ + obj->age -= 100; /* this is an *OLD* corpse */ break; - case PM_KOBOLD_MUMMY: - case PM_DWARF_MUMMY: - case PM_GNOME_MUMMY: - case PM_ORC_MUMMY: - case PM_ELF_MUMMY: - case PM_HUMAN_MUMMY: - case PM_GIANT_MUMMY: - case PM_ETTIN_MUMMY: - case PM_KOBOLD_ZOMBIE: - case PM_DWARF_ZOMBIE: - case PM_GNOME_ZOMBIE: - case PM_ORC_ZOMBIE: - case PM_ELF_ZOMBIE: - case PM_HUMAN_ZOMBIE: - case PM_GIANT_ZOMBIE: - case PM_ETTIN_ZOMBIE: + case PM_KOBOLD_MUMMY: + case PM_DWARF_MUMMY: + case PM_GNOME_MUMMY: + case PM_ORC_MUMMY: + case PM_ELF_MUMMY: + case PM_HUMAN_MUMMY: + case PM_GIANT_MUMMY: + case PM_ETTIN_MUMMY: + case PM_KOBOLD_ZOMBIE: + case PM_DWARF_ZOMBIE: + case PM_GNOME_ZOMBIE: + case PM_ORC_ZOMBIE: + case PM_ELF_ZOMBIE: + case PM_HUMAN_ZOMBIE: + case PM_GIANT_ZOMBIE: + case PM_ETTIN_ZOMBIE: num = undead_to_corpse(mndx); corpstatflags |= CORPSTAT_INIT; obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags); - obj->age -= 100; /* this is an *OLD* corpse */ + obj->age -= 100; /* this is an *OLD* corpse */ break; - case PM_IRON_GOLEM: - num = d(2,6); + case PM_IRON_GOLEM: + num = d(2, 6); while (num--) obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE); - free_mname(mtmp); /* don't christen obj */ + free_mname(mtmp); /* don't christen obj */ break; - case PM_GLASS_GOLEM: - num = d(2,4); /* very low chance of creating all glass gems */ + case PM_GLASS_GOLEM: + num = d(2, 4); /* very low chance of creating all glass gems */ while (num--) obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE); free_mname(mtmp); break; - case PM_CLAY_GOLEM: + case PM_CLAY_GOLEM: obj = mksobj_at(ROCK, x, y, FALSE, FALSE); - obj->quan = (long)(rn2(20) + 50); + obj->quan = (long) (rn2(20) + 50); obj->owt = weight(obj); free_mname(mtmp); break; - case PM_STONE_GOLEM: - corpstatflags &= ~CORPSTAT_INIT; - obj = mkcorpstat(STATUE, (struct monst *)0, - mdat, x, y, corpstatflags); + case PM_STONE_GOLEM: + corpstatflags &= ~CORPSTAT_INIT; + obj = + mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags); break; - case PM_WOOD_GOLEM: - num = d(2,4); - while(num--) { + case PM_WOOD_GOLEM: + num = d(2, 4); + while (num--) { obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE); } free_mname(mtmp); break; - case PM_LEATHER_GOLEM: - num = d(2,4); - while(num--) + case PM_LEATHER_GOLEM: + num = d(2, 4); + while (num--) obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE); free_mname(mtmp); break; - case PM_GOLD_GOLEM: + case PM_GOLD_GOLEM: /* Good luck gives more coins */ - obj = mkgold((long)(200 - rnl(101)), x, y); + obj = mkgold((long) (200 - rnl(101)), x, y); free_mname(mtmp); break; - case PM_PAPER_GOLEM: + case PM_PAPER_GOLEM: num = rnd(4); while (num--) obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE); free_mname(mtmp); break; - /* expired puddings will congeal into a large blob - like dragons, relies on the order remaining consistent */ - case PM_GRAY_OOZE: - case PM_BROWN_PUDDING: - case PM_GREEN_SLIME: - case PM_BLACK_PUDDING: - /* we have to do this here because most other places - * expect there to be an object coming back; not this one */ - obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx), - x, y, TRUE, FALSE); + /* expired puddings will congeal into a large blob + like dragons, relies on the order remaining consistent */ + case PM_GRAY_OOZE: + case PM_BROWN_PUDDING: + case PM_GREEN_SLIME: + case PM_BLACK_PUDDING: + /* we have to do this here because most other places + * expect there to be an object coming back; not this one */ + obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx), x, + y, TRUE, FALSE); - while ((obj && (otmp = obj_nexto(obj)) != (struct obj*)0)) { - pudding_merge_message(obj, otmp); - obj = obj_meld(&obj, &otmp); - } - free_mname(mtmp); - return obj; + while ((obj && (otmp = obj_nexto(obj)) != (struct obj *) 0)) { + pudding_merge_message(obj, otmp); + obj = obj_meld(&obj, &otmp); + } + free_mname(mtmp); + return obj; break; - default_1: - default: - if (mvitals[mndx].mvflags & G_NOCORPSE) - return (struct obj *)0; - else { - corpstatflags |= CORPSTAT_INIT; - /* preserve the unique traits of some creatures */ - obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0, - mdat, x, y, corpstatflags); - if (burythem) { - boolean dealloc; - (void) bury_an_obj(obj, &dealloc); + default_1: + default: + if (mvitals[mndx].mvflags & G_NOCORPSE) + return (struct obj *) 0; + else { + corpstatflags |= CORPSTAT_INIT; + /* preserve the unique traits of some creatures */ + obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0, mdat, x, y, + corpstatflags); + if (burythem) { + boolean dealloc; + (void) bury_an_obj(obj, &dealloc); newsym(x, y); - return (dealloc ? NULL : obj); - } + return (dealloc ? NULL : obj); } + } break; } /* All special cases should precede the G_NOCORPSE check */ /* if polymorph or undead turning has killed this monster, prevent the same attack beam from hitting its corpse */ - if (context.bypasses) bypass_obj(obj); + if (context.bypasses) + bypass_obj(obj); if (has_mname(mtmp)) obj = oname(obj, MNAME(mtmp)); - /* Avoid "It was hidden under a green mold corpse!" + /* Avoid "It was hidden under a green mold corpse!" * during Blind combat. An unseen monster referred to as "it" * could be killed and leave a corpse. If a hider then hid * underneath it, you could be told the corpse type of a @@ -322,7 +373,8 @@ unsigned corpseflags; * The code in hitmu() substitutes the word "something" * if the corpses obj->dknown is 0. */ - if (Blind && !sensemon(mtmp)) obj->dknown = 0; + if (Blind && !sensemon(mtmp)) + obj->dknown = 0; stackobj(obj); newsym(x, y); @@ -336,10 +388,10 @@ register struct monst *mtmp; { boolean inpool, inlava, infountain; - inpool = is_pool(mtmp->mx,mtmp->my) && - !is_flyer(mtmp->data) && !is_floater(mtmp->data); - inlava = is_lava(mtmp->mx,mtmp->my) && - !is_flyer(mtmp->data) && !is_floater(mtmp->data); + inpool = is_pool(mtmp->mx, mtmp->my) && !is_flyer(mtmp->data) + && !is_floater(mtmp->data); + inlava = is_lava(mtmp->mx, mtmp->my) && !is_flyer(mtmp->data) + && !is_floater(mtmp->data); infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ); /* Flying and levitation keeps our steed out of the liquid */ @@ -352,91 +404,93 @@ register struct monst *mtmp; * function will fail. */ if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) { - if (split_mon(mtmp, (struct monst *)0)) - dryup(mtmp->mx, mtmp->my, FALSE); - if (inpool) water_damage_chain(mtmp->minvent, FALSE); - return (0); + if (split_mon(mtmp, (struct monst *) 0)) + dryup(mtmp->mx, mtmp->my, FALSE); + if (inpool) + water_damage_chain(mtmp->minvent, FALSE); + return (0); } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) { - int dam = d(2,6); - if (cansee(mtmp->mx,mtmp->my)) - pline("%s rusts.", Monnam(mtmp)); - mtmp->mhp -= dam; - if (mtmp->mhpmax > dam) mtmp->mhpmax -= dam; - if (mtmp->mhp < 1) { - mondead(mtmp); - if (mtmp->mhp < 1) return (1); - } - water_damage_chain(mtmp->minvent, FALSE); - return (0); + int dam = d(2, 6); + if (cansee(mtmp->mx, mtmp->my)) + pline("%s rusts.", Monnam(mtmp)); + mtmp->mhp -= dam; + if (mtmp->mhpmax > dam) + mtmp->mhpmax -= dam; + if (mtmp->mhp < 1) { + mondead(mtmp); + if (mtmp->mhp < 1) + return (1); + } + water_damage_chain(mtmp->minvent, FALSE); + return (0); } if (inlava) { - /* - * Lava effects much as water effects. Lava likers are able to - * protect their stuff. Fire resistant monsters can only protect - * themselves --ALI - */ - if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) { - if (!resists_fire(mtmp)) { - if (cansee(mtmp->mx,mtmp->my)) - pline("%s %s.", Monnam(mtmp), - mtmp->data == &mons[PM_WATER_ELEMENTAL] ? - "boils away" : "burns to a crisp"); - mondead(mtmp); + /* + * Lava effects much as water effects. Lava likers are able to + * protect their stuff. Fire resistant monsters can only protect + * themselves --ALI + */ + if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) { + if (!resists_fire(mtmp)) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s %s.", Monnam(mtmp), + mtmp->data == &mons[PM_WATER_ELEMENTAL] + ? "boils away" + : "burns to a crisp"); + mondead(mtmp); + } else { + if (--mtmp->mhp < 1) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s surrenders to the fire.", Monnam(mtmp)); + mondead(mtmp); + } else if (cansee(mtmp->mx, mtmp->my)) + pline("%s burns slightly.", Monnam(mtmp)); + } + if (mtmp->mhp > 0) { + (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE, + mtmp->mx, mtmp->my); + (void) rloc(mtmp, FALSE); + return 0; + } + return (1); } - else { - if (--mtmp->mhp < 1) { - if (cansee(mtmp->mx,mtmp->my)) - pline("%s surrenders to the fire.", Monnam(mtmp)); - mondead(mtmp); - } - else if (cansee(mtmp->mx,mtmp->my)) - pline("%s burns slightly.", Monnam(mtmp)); - } - if (mtmp->mhp > 0) { - (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE, mtmp->mx, - mtmp->my); - (void) rloc(mtmp, FALSE); - return 0; - } - return (1); - } } else if (inpool) { - /* Most monsters drown in pools. flooreffects() will take care of - * water damage to dead monsters' inventory, but survivors need to - * be handled here. Swimmers are able to protect their stuff... - */ - if (!is_clinger(mtmp->data) - && !is_swimmer(mtmp->data) && !amphibious(mtmp->data)) { - if (cansee(mtmp->mx,mtmp->my)) { - pline("%s drowns.", Monnam(mtmp)); + /* Most monsters drown in pools. flooreffects() will take care of + * water damage to dead monsters' inventory, but survivors need to + * be handled here. Swimmers are able to protect their stuff... + */ + if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data) + && !amphibious(mtmp->data)) { + if (cansee(mtmp->mx, mtmp->my)) { + pline("%s drowns.", Monnam(mtmp)); + } + if (u.ustuck && u.uswallow && u.ustuck == mtmp) { + /* This can happen after a purple worm plucks you off a + flying steed while you are over water. */ + pline("%s sinks as water rushes in and flushes you out.", + Monnam(mtmp)); + } + mondead(mtmp); + if (mtmp->mhp > 0) { + water_damage_chain(mtmp->minvent, FALSE); + (void) rloc(mtmp, FALSE); + return 0; + } + return (1); } - if (u.ustuck && u.uswallow && u.ustuck == mtmp) { - /* This can happen after a purple worm plucks you off a - flying steed while you are over water. */ - pline("%s sinks as water rushes in and flushes you out.", - Monnam(mtmp)); - } - mondead(mtmp); - if (mtmp->mhp > 0) { - water_damage_chain(mtmp->minvent, FALSE); - (void) rloc(mtmp, FALSE); - return 0; - } - return (1); - } } else { - /* but eels have a difficult time outside */ - if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) { - /* as mhp gets lower, the rate of further loss slows down */ - if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8)) mtmp->mhp--; - monflee(mtmp, 2, FALSE, FALSE); - } + /* but eels have a difficult time outside */ + if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) { + /* as mhp gets lower, the rate of further loss slows down */ + if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8)) + mtmp->mhp--; + monflee(mtmp, 2, FALSE, FALSE); + } } return (0); } - int mcalcmove(mon) struct monst *mon; @@ -448,22 +502,23 @@ struct monst *mon; * both adjustments have negligible effect on higher speeds. */ if (mon->mspeed == MSLOW) - mmove = (2 * mmove + 1) / 3; + mmove = (2 * mmove + 1) / 3; else if (mon->mspeed == MFAST) - mmove = (4 * mmove + 2) / 3; + mmove = (4 * mmove + 2) / 3; if (mon == u.usteed) { - if (u.ugallop && context.mv) { - /* average movement is 1.50 times normal */ - mmove = ((rn2(2) ? 4 : 5) * mmove) / 3; - } + if (u.ugallop && context.mv) { + /* average movement is 1.50 times normal */ + mmove = ((rn2(2) ? 4 : 5) * mmove) / 3; + } } else if (mmove) { - /* vary movement points allocated to slightly reduce predictability; - random increment (avg +2) exceeds random decrement (avg +1) by - a small amount; normal speed monsters will occasionally get an - extra move and slow ones won't be quite as slow */ - mmove += rn2(5) - rn2(3); /* + 0..4 - 0..2, average net +1 */ - if (mmove < 1) mmove = 1; + /* vary movement points allocated to slightly reduce predictability; + random increment (avg +2) exceeds random decrement (avg +1) by + a small amount; normal speed monsters will occasionally get an + extra move and slow ones won't be quite as slow */ + mmove += rn2(5) - rn2(3); /* + 0..4 - 0..2, average net +1 */ + if (mmove < 1) + mmove = 1; } return mmove; @@ -478,36 +533,39 @@ mcalcdistress() struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; - /* must check non-moving monsters once/turn in case - * they managed to end up in liquid */ - if (mtmp->data->mmove == 0) { - if (vision_full_recalc) vision_recalc(0); - if (minliquid(mtmp)) continue; - } + /* must check non-moving monsters once/turn in case + * they managed to end up in liquid */ + if (mtmp->data->mmove == 0) { + if (vision_full_recalc) + vision_recalc(0); + if (minliquid(mtmp)) + continue; + } - /* regenerate hit points */ - mon_regen(mtmp, FALSE); + /* regenerate hit points */ + mon_regen(mtmp, FALSE); - /* possibly polymorph shapechangers and lycanthropes */ - if (mtmp->cham >= LOW_PM) { - if (is_vampshifter(mtmp) || mtmp->data->mlet == S_VAMPIRE) - decide_to_shapeshift(mtmp,0); - else if (!rn2(6)) - (void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE); - } - were_change(mtmp); + /* possibly polymorph shapechangers and lycanthropes */ + if (mtmp->cham >= LOW_PM) { + if (is_vampshifter(mtmp) || mtmp->data->mlet == S_VAMPIRE) + decide_to_shapeshift(mtmp, 0); + else if (!rn2(6)) + (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); + } + were_change(mtmp); - /* gradually time out temporary problems */ - if (mtmp->mblinded && !--mtmp->mblinded) - mtmp->mcansee = 1; - if (mtmp->mfrozen && !--mtmp->mfrozen) - mtmp->mcanmove = 1; - if (mtmp->mfleetim && !--mtmp->mfleetim) - mtmp->mflee = 0; + /* gradually time out temporary problems */ + if (mtmp->mblinded && !--mtmp->mblinded) + mtmp->mcansee = 1; + if (mtmp->mfrozen && !--mtmp->mfrozen) + mtmp->mcanmove = 1; + if (mtmp->mfleetim && !--mtmp->mfleetim) + mtmp->mflee = 0; - /* FIXME: mtmp->mlstmv ought to be updated here */ + /* FIXME: mtmp->mlstmv ought to be updated here */ } } @@ -536,83 +594,90 @@ movemon() teleport another, this scheme would have problems. */ - for(mtmp = fmon; mtmp; mtmp = nmtmp) { + for (mtmp = fmon; mtmp; mtmp = nmtmp) { #ifdef SAFERHANGUP - if (program_state.done_hup) { - somebody_can_move = FALSE; - break; - } + if (program_state.done_hup) { + somebody_can_move = FALSE; + break; + } #endif - nmtmp = mtmp->nmon; - /* one dead monster needs to perform a move after death: - vault guard whose temporary corridor is still on the map */ - if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0) (void)gd_move(mtmp); - if (DEADMONSTER(mtmp)) continue; - - /* Find a monster that we have not treated yet. */ - if(mtmp->movement < NORMAL_SPEED) - continue; - - mtmp->movement -= NORMAL_SPEED; - if (mtmp->movement >= NORMAL_SPEED) - somebody_can_move = TRUE; - - if (vision_full_recalc) vision_recalc(0); /* vision! */ - - if (minliquid(mtmp)) continue; - - if (is_hider(mtmp->data)) { - /* unwatched mimics and piercers may hide again [MRS] */ - if(restrap(mtmp)) continue; - if(mtmp->m_ap_type == M_AP_FURNITURE || - mtmp->m_ap_type == M_AP_OBJECT) + nmtmp = mtmp->nmon; + /* one dead monster needs to perform a move after death: + vault guard whose temporary corridor is still on the map */ + if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0) + (void) gd_move(mtmp); + if (DEADMONSTER(mtmp)) continue; - if(mtmp->mundetected) continue; - } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected && - (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2) && - !canseemon(mtmp) && !rn2(4)) { - /* some eels end up stuck in isolated pools, where they - can't--or at least won't--move, so they never reach - their post-move chance to re-hide */ - if (hideunder(mtmp)) continue; - } - /* continue if the monster died fighting */ - if (Conflict && !mtmp->iswiz && mtmp->mcansee) { - /* Note: - * Conflict does not take effect in the first round. - * Therefore, A monster when stepping into the area will - * get to swing at you. - * - * The call to fightm() must be _last_. The monster might - * have died if it returns 1. - */ - if (couldsee(mtmp->mx,mtmp->my) && - (distu(mtmp->mx,mtmp->my) <= BOLT_LIM*BOLT_LIM) && - fightm(mtmp)) - continue; /* mon might have died */ - } - if(dochugw(mtmp)) /* otherwise just move the monster */ - continue; + /* Find a monster that we have not treated yet. */ + if (mtmp->movement < NORMAL_SPEED) + continue; + + mtmp->movement -= NORMAL_SPEED; + if (mtmp->movement >= NORMAL_SPEED) + somebody_can_move = TRUE; + + if (vision_full_recalc) + vision_recalc(0); /* vision! */ + + if (minliquid(mtmp)) + continue; + + if (is_hider(mtmp->data)) { + /* unwatched mimics and piercers may hide again [MRS] */ + if (restrap(mtmp)) + continue; + if (mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT) + continue; + if (mtmp->mundetected) + continue; + } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected + && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2) + && !canseemon(mtmp) && !rn2(4)) { + /* some eels end up stuck in isolated pools, where they + can't--or at least won't--move, so they never reach + their post-move chance to re-hide */ + if (hideunder(mtmp)) + continue; + } + + /* continue if the monster died fighting */ + if (Conflict && !mtmp->iswiz && mtmp->mcansee) { + /* Note: + * Conflict does not take effect in the first round. + * Therefore, A monster when stepping into the area will + * get to swing at you. + * + * The call to fightm() must be _last_. The monster might + * have died if it returns 1. + */ + if (couldsee(mtmp->mx, mtmp->my) + && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM) + && fightm(mtmp)) + continue; /* mon might have died */ + } + if (dochugw(mtmp)) /* otherwise just move the monster */ + continue; } if (any_light_source()) - vision_full_recalc = 1; /* in case a mon moved with a light source */ - dmonsfree(); /* remove all dead monsters */ + vision_full_recalc = 1; /* in case a mon moved with a light source */ + dmonsfree(); /* remove all dead monsters */ /* a monster may have levteleported player -dlc */ if (u.utotype) { - deferred_goto(); - /* changed levels, so these monsters are dormant */ - somebody_can_move = FALSE; + deferred_goto(); + /* changed levels, so these monsters are dormant */ + somebody_can_move = FALSE; } return somebody_can_move; } -#define mstoning(obj) (ofood(obj) && \ - (touch_petrifies(&mons[(obj)->corpsenm]) || \ - (obj)->corpsenm == PM_MEDUSA)) +#define mstoning(obj) \ + (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \ + || (obj)->corpsenm == PM_MEDUSA)) /* * Maybe eat a metallic object (not just gold). @@ -623,98 +688,99 @@ movemon() */ int meatmetal(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { register struct obj *otmp; struct permonst *ptr; int poly, grow, heal, mstone; /* If a pet, eating is handled separately, in dog.c */ - if (mtmp->mtame) return 0; + if (mtmp->mtame) + return 0; /* Eats topmost metal object if it is there */ - for (otmp = level.objects[mtmp->mx][mtmp->my]; - otmp; otmp = otmp->nexthere) { - /* Don't eat indigestible/choking/inappropriate objects */ - if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp)) || - (otmp->otyp == AMULET_OF_STRANGULATION) || - (otmp->otyp == RIN_SLOW_DIGESTION)) - continue; - if (is_metallic(otmp) && !obj_resists(otmp, 5, 95) && - touch_artifact(otmp,mtmp)) { - if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) { - if (canseemon(mtmp) && flags.verbose) { - pline("%s eats %s!", - Monnam(mtmp), - distant_name(otmp,doname)); - } - /* The object's rustproofing is gone now */ - otmp->oerodeproof = 0; - mtmp->mstun = 1; - if (canseemon(mtmp) && flags.verbose) { - pline("%s spits %s out in disgust!", - Monnam(mtmp), distant_name(otmp,doname)); - } - } else { - if (cansee(mtmp->mx,mtmp->my) && flags.verbose) - pline("%s eats %s!", Monnam(mtmp), - distant_name(otmp,doname)); - else if (flags.verbose) - You_hear("a crunching sound."); - mtmp->meating = otmp->owt/2 + 1; - /* Heal up to the object's weight in hp */ - if (mtmp->mhp < mtmp->mhpmax) { - mtmp->mhp += objects[otmp->otyp].oc_weight; - if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; - } - if(otmp == uball) { - unpunish(); - delobj(otmp); - } else if (otmp == uchain) { - unpunish(); /* frees uchain */ - } else { - poly = polyfodder(otmp); - grow = mlevelgain(otmp); - heal = mhealup(otmp); - mstone = mstoning(otmp); - delobj(otmp); - ptr = mtmp->data; - if (poly) { - if (newcham(mtmp, (struct permonst *)0, - FALSE, FALSE)) - ptr = mtmp->data; - } else if (grow) { - ptr = grow_up(mtmp, (struct monst *)0); - } else if (mstone) { - if (poly_when_stoned(ptr)) { - mon_to_stone(mtmp); - ptr = mtmp->data; - } else if (!resists_ston(mtmp)) { - if (canseemon(mtmp)) - pline("%s turns to stone!", Monnam(mtmp)); - monstone(mtmp); - ptr = (struct permonst *)0; + for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; + otmp = otmp->nexthere) { + /* Don't eat indigestible/choking/inappropriate objects */ + if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp)) + || (otmp->otyp == AMULET_OF_STRANGULATION) + || (otmp->otyp == RIN_SLOW_DIGESTION)) + continue; + if (is_metallic(otmp) && !obj_resists(otmp, 5, 95) + && touch_artifact(otmp, mtmp)) { + if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) { + if (canseemon(mtmp) && flags.verbose) { + pline("%s eats %s!", Monnam(mtmp), + distant_name(otmp, doname)); } - } else if (heal) { - mtmp->mhp = mtmp->mhpmax; + /* The object's rustproofing is gone now */ + otmp->oerodeproof = 0; + mtmp->mstun = 1; + if (canseemon(mtmp) && flags.verbose) { + pline("%s spits %s out in disgust!", Monnam(mtmp), + distant_name(otmp, doname)); + } + } else { + if (cansee(mtmp->mx, mtmp->my) && flags.verbose) + pline("%s eats %s!", Monnam(mtmp), + distant_name(otmp, doname)); + else if (flags.verbose) + You_hear("a crunching sound."); + mtmp->meating = otmp->owt / 2 + 1; + /* Heal up to the object's weight in hp */ + if (mtmp->mhp < mtmp->mhpmax) { + mtmp->mhp += objects[otmp->otyp].oc_weight; + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + } + if (otmp == uball) { + unpunish(); + delobj(otmp); + } else if (otmp == uchain) { + unpunish(); /* frees uchain */ + } else { + poly = polyfodder(otmp); + grow = mlevelgain(otmp); + heal = mhealup(otmp); + mstone = mstoning(otmp); + delobj(otmp); + ptr = mtmp->data; + if (poly) { + if (newcham(mtmp, (struct permonst *) 0, FALSE, + FALSE)) + ptr = mtmp->data; + } else if (grow) { + ptr = grow_up(mtmp, (struct monst *) 0); + } else if (mstone) { + if (poly_when_stoned(ptr)) { + mon_to_stone(mtmp); + ptr = mtmp->data; + } else if (!resists_ston(mtmp)) { + if (canseemon(mtmp)) + pline("%s turns to stone!", Monnam(mtmp)); + monstone(mtmp); + ptr = (struct permonst *) 0; + } + } else if (heal) { + mtmp->mhp = mtmp->mhpmax; + } + if (!ptr) + return 2; /* it died */ + } + /* Left behind a pile? */ + if (rnd(25) < 3) + (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE); + newsym(mtmp->mx, mtmp->my); + return 1; } - if (!ptr) return 2; /* it died */ - } - /* Left behind a pile? */ - if (rnd(25) < 3) - (void)mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE); - newsym(mtmp->mx, mtmp->my); - return 1; - } } } return 0; } /* monster eats a pile of objects */ -int -meatobj(mtmp) /* for gelatinous cubes */ - register struct monst *mtmp; +int meatobj(mtmp) /* for gelatinous cubes */ +register struct monst *mtmp; { register struct obj *otmp, *otmp2; struct permonst *ptr, *original_ptr = mtmp->data; @@ -723,7 +789,8 @@ meatobj(mtmp) /* for gelatinous cubes */ buf[0] = '\0'; /* If a pet, eating is handled separately, in dog.c */ - if (mtmp->mtame) return 0; + if (mtmp->mtame) + return 0; /* eat organic objects, including cloth and wood, if present; engulf others, except huge rocks and metal attached to player @@ -732,158 +799,164 @@ meatobj(mtmp) /* for gelatinous cubes */ otmp2 = otmp->nexthere; /* touch senstive items */ - if (otmp->otyp == CORPSE && - is_rider(&mons[otmp->corpsenm])) { - /* Rider corpse isn't just inedible; can't engulf it either */ - (void)revive_corpse(otmp); + if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) { + /* Rider corpse isn't just inedible; can't engulf it either */ + (void) revive_corpse(otmp); - /* untouchable (or inaccessible) items */ - } else if ((otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm]) && - !resists_ston(mtmp)) || - /* don't engulf boulders and statues or ball&chain */ - otmp->oclass == ROCK_CLASS || - otmp == uball || otmp == uchain) { - /* do nothing--neither eaten nor engulfed */ - continue; + /* untouchable (or inaccessible) items */ + } else if ((otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm]) + && !resists_ston(mtmp)) || + /* don't engulf boulders and statues or ball&chain */ + otmp->oclass == ROCK_CLASS || otmp == uball + || otmp == uchain) { + /* do nothing--neither eaten nor engulfed */ + continue; - /* inedible items -- engulf these */ - } else if (!is_organic(otmp) || - obj_resists(otmp, 5, 95) || - !touch_artifact(otmp, mtmp) || - /* redundant due to non-organic composition but - included for emphasis */ - (otmp->otyp == AMULET_OF_STRANGULATION || - otmp->otyp == RIN_SLOW_DIGESTION) || - /* cockatrice corpses handled above; this - touch_petrifies() check catches eggs */ - ((otmp->otyp == CORPSE || otmp->otyp == EGG) && - ((touch_petrifies(&mons[otmp->corpsenm]) && - !resists_ston(mtmp)) || - (otmp->corpsenm == PM_GREEN_SLIME && - !slimeproof(mtmp->data))))) { - /* engulf */ - ++ecount; - if (ecount == 1) - Sprintf(buf, "%s engulfs %s.", Monnam(mtmp), - distant_name(otmp,doname)); - else if (ecount == 2) - Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp)); - obj_extract_self(otmp); - (void) mpickobj(mtmp, otmp); /* slurp */ + /* inedible items -- engulf these */ + } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95) + || !touch_artifact(otmp, mtmp) || + /* redundant due to non-organic composition but + included for emphasis */ + (otmp->otyp == AMULET_OF_STRANGULATION + || otmp->otyp == RIN_SLOW_DIGESTION) || + /* cockatrice corpses handled above; this + touch_petrifies() check catches eggs */ + ((otmp->otyp == CORPSE || otmp->otyp == EGG) + && ((touch_petrifies(&mons[otmp->corpsenm]) + && !resists_ston(mtmp)) + || (otmp->corpsenm == PM_GREEN_SLIME + && !slimeproof(mtmp->data))))) { + /* engulf */ + ++ecount; + if (ecount == 1) + Sprintf(buf, "%s engulfs %s.", Monnam(mtmp), + distant_name(otmp, doname)); + else if (ecount == 2) + Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp)); + obj_extract_self(otmp); + (void) mpickobj(mtmp, otmp); /* slurp */ - /* lastly, edible items; yum! */ + /* lastly, edible items; yum! */ } else { - /* devour */ - ++count; - if (cansee(mtmp->mx,mtmp->my) && flags.verbose) - pline("%s eats %s!", Monnam(mtmp), - distant_name(otmp, doname)); - else if (flags.verbose) - You_hear("a slurping sound."); - /* Heal up to the object's weight in hp */ - if (mtmp->mhp < mtmp->mhpmax) { - mtmp->mhp += objects[otmp->otyp].oc_weight; - if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; - } - if (Has_contents(otmp)) { - register struct obj *otmp3; - /* contents of eaten containers become engulfed; this - is arbitrary, but otherwise g.cubes are too powerful */ - while ((otmp3 = otmp->cobj) != 0) { - obj_extract_self(otmp3); - if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) { - otmp3->age = monstermoves - otmp3->age; - start_corpse_timeout(otmp3); + /* devour */ + ++count; + if (cansee(mtmp->mx, mtmp->my) && flags.verbose) + pline("%s eats %s!", Monnam(mtmp), + distant_name(otmp, doname)); + else if (flags.verbose) + You_hear("a slurping sound."); + /* Heal up to the object's weight in hp */ + if (mtmp->mhp < mtmp->mhpmax) { + mtmp->mhp += objects[otmp->otyp].oc_weight; + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; } - (void) mpickobj(mtmp, otmp3); + if (Has_contents(otmp)) { + register struct obj *otmp3; + /* contents of eaten containers become engulfed; this + is arbitrary, but otherwise g.cubes are too powerful */ + while ((otmp3 = otmp->cobj) != 0) { + obj_extract_self(otmp3); + if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) { + otmp3->age = monstermoves - otmp3->age; + start_corpse_timeout(otmp3); + } + (void) mpickobj(mtmp, otmp3); + } } - } - poly = polyfodder(otmp); - grow = mlevelgain(otmp); - heal = mhealup(otmp); - delobj(otmp); /* munch */ - ptr = mtmp->data; - if (poly) { - if (newcham(mtmp, (struct permonst *)0, FALSE, FALSE)) + poly = polyfodder(otmp); + grow = mlevelgain(otmp); + heal = mhealup(otmp); + delobj(otmp); /* munch */ ptr = mtmp->data; - } else if (grow) { - ptr = grow_up(mtmp, (struct monst *)0); - } else if (heal) { - mtmp->mhp = mtmp->mhpmax; - } - /* in case it polymorphed or died */ - if (ptr != original_ptr) - return !ptr ? 2 : 1; + if (poly) { + if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE)) + ptr = mtmp->data; + } else if (grow) { + ptr = grow_up(mtmp, (struct monst *) 0); + } else if (heal) { + mtmp->mhp = mtmp->mhpmax; + } + /* in case it polymorphed or died */ + if (ptr != original_ptr) + return !ptr ? 2 : 1; } /* Engulf & devour is instant, so don't set meating */ - if (mtmp->minvis) newsym(mtmp->mx, mtmp->my); + if (mtmp->minvis) + newsym(mtmp->mx, mtmp->my); } if (ecount > 0) { if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0]) - pline1(buf); + pline1(buf); else if (flags.verbose) - You_hear("%s slurping sound%s.", - ecount == 1 ? "a" : "several", - ecount == 1 ? "" : "s"); + You_hear("%s slurping sound%s.", ecount == 1 ? "a" : "several", + ecount == 1 ? "" : "s"); } return ((count > 0) || (ecount > 0)) ? 1 : 0; } void mpickgold(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { register struct obj *gold; int mat_idx; if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) { - mat_idx = objects[gold->otyp].oc_material; + mat_idx = objects[gold->otyp].oc_material; obj_extract_self(gold); add_to_minv(mtmp, gold); - if (cansee(mtmp->mx, mtmp->my) ) { - if (flags.verbose && !mtmp->isgd) - pline("%s picks up some %s.", Monnam(mtmp), - mat_idx == GOLD ? "gold" : "money"); - newsym(mtmp->mx, mtmp->my); - } + if (cansee(mtmp->mx, mtmp->my)) { + if (flags.verbose && !mtmp->isgd) + pline("%s picks up some %s.", Monnam(mtmp), + mat_idx == GOLD ? "gold" : "money"); + newsym(mtmp->mx, mtmp->my); + } } } boolean mpickstuff(mtmp, str) - register struct monst *mtmp; - register const char *str; +register struct monst *mtmp; +register const char *str; { register struct obj *otmp, *otmp2; -/* prevent shopkeepers from leaving the door of their shop */ - if(mtmp->isshk && inhishop(mtmp)) return FALSE; + /* prevent shopkeepers from leaving the door of their shop */ + if (mtmp->isshk && inhishop(mtmp)) + return FALSE; - for(otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) { + for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) { otmp2 = otmp->nexthere; -/* Nymphs take everything. Most monsters don't pick up corpses. */ - if (!str ? searches_for_item(mtmp,otmp) : - !!(index(str, otmp->oclass))) { - if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH && - /* let a handful of corpse types thru to can_carry() */ - !touch_petrifies(&mons[otmp->corpsenm]) && - otmp->corpsenm != PM_LIZARD && - !acidic(&mons[otmp->corpsenm])) continue; - if (!touch_artifact(otmp,mtmp)) continue; - if (!can_carry(mtmp,otmp)) continue; - if (is_pool(mtmp->mx,mtmp->my)) continue; - if (cansee(mtmp->mx,mtmp->my) && flags.verbose) - pline("%s picks up %s.", Monnam(mtmp), - (distu(mtmp->mx, mtmp->my) <= 5) ? - doname(otmp) : distant_name(otmp, doname)); - obj_extract_self(otmp); /* remove from floor */ - (void) mpickobj(mtmp, otmp); /* may merge and free otmp */ - m_dowear(mtmp, FALSE); - newsym(mtmp->mx, mtmp->my); - return TRUE; /* pick only one object */ + /* Nymphs take everything. Most monsters don't pick up corpses. + */ + if (!str ? searches_for_item(mtmp, otmp) + : !!(index(str, otmp->oclass))) { + if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH && + /* let a handful of corpse types thru to can_carry() */ + !touch_petrifies(&mons[otmp->corpsenm]) + && otmp->corpsenm != PM_LIZARD + && !acidic(&mons[otmp->corpsenm])) + continue; + if (!touch_artifact(otmp, mtmp)) + continue; + if (!can_carry(mtmp, otmp)) + continue; + if (is_pool(mtmp->mx, mtmp->my)) + continue; + if (cansee(mtmp->mx, mtmp->my) && flags.verbose) + pline("%s picks up %s.", Monnam(mtmp), + (distu(mtmp->mx, mtmp->my) <= 5) + ? doname(otmp) + : distant_name(otmp, doname)); + obj_extract_self(otmp); /* remove from floor */ + (void) mpickobj(mtmp, otmp); /* may merge and free otmp */ + m_dowear(mtmp, FALSE); + newsym(mtmp->mx, mtmp->my); + return TRUE; /* pick only one object */ } } return FALSE; @@ -896,8 +969,8 @@ register struct monst *mtmp; register int curload = 0; register struct obj *obj; - for(obj = mtmp->minvent; obj; obj = obj->nobj) { - if(obj->otyp != BOULDER || !throws_rocks(mtmp->data)) + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + if (obj->otyp != BOULDER || !throws_rocks(mtmp->data)) curload += obj->owt; } @@ -918,22 +991,25 @@ register struct monst *mtmp; * proportional to their size instead of weight. */ if (!mtmp->data->cwt) - maxload = (MAX_CARR_CAP * (long)mtmp->data->msize) / MZ_HUMAN; + maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN; else if (!strongmonst(mtmp->data) - || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN))) - maxload = (MAX_CARR_CAP * (long)mtmp->data->cwt) / WT_HUMAN; - else maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/ + || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN))) + maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN; + else + maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/ - if (!strongmonst(mtmp->data)) maxload /= 2; + if (!strongmonst(mtmp->data)) + maxload /= 2; - if (maxload < 1) maxload = 1; + if (maxload < 1) + maxload = 1; return (int) maxload; } /* for restricting monsters' object-pickup */ boolean -can_carry(mtmp,otmp) +can_carry(mtmp, otmp) struct monst *mtmp; struct obj *otmp; { @@ -942,15 +1018,16 @@ struct obj *otmp; short nattk = 0; boolean glomper = FALSE; - if (notake(mdat)) return FALSE; /* can't carry anything */ + if (notake(mdat)) + return FALSE; /* can't carry anything */ - if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]) && - !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp)) + if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]) + && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp)) return FALSE; if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) return FALSE; - if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp) && - (otyp != BELL_OF_OPENING || !is_covetous(mdat))) + if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp) + && (otyp != BELL_OF_OPENING || !is_covetous(mdat))) return FALSE; /* monsters without hands can't pick up multiple objects at once @@ -962,47 +1039,51 @@ struct obj *otmp; glomper = (glomper || mtmp->data->mattk[nattk].aatyp == AT_ENGL); if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper - && (!(mtmp->data->mlet == S_DRAGON - && otmp->oclass == COIN_CLASS))) { - return FALSE; + && (!(mtmp->data->mlet == S_DRAGON + && otmp->oclass == COIN_CLASS))) { + return FALSE; } } /* Steeds don't pick up stuff (to avoid shop abuse) */ - if (mtmp == u.usteed) return (FALSE); - if (mtmp->isshk) return(TRUE); /* no limit */ - if (mtmp->mpeaceful && !mtmp->mtame) return(FALSE); + if (mtmp == u.usteed) + return (FALSE); + if (mtmp->isshk) + return (TRUE); /* no limit */ + if (mtmp->mpeaceful && !mtmp->mtame) + return (FALSE); /* otherwise players might find themselves obligated to violate * their alignment if the monster takes something they need */ /* special--boulder throwers carry unlimited amounts of boulders */ if (throws_rocks(mdat) && otyp == BOULDER) - return(TRUE); + return (TRUE); /* nymphs deal in stolen merchandise, but not boulders or statues */ if (mdat->mlet == S_NYMPH) return (boolean)(otmp->oclass != ROCK_CLASS); - if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp)) return FALSE; + if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp)) + return FALSE; - return(TRUE); + return (TRUE); } /* return number of acceptable neighbour positions */ int mfndpos(mon, poss, info, flag) - register struct monst *mon; - coord *poss; /* coord poss[9] */ - long *info; /* long info[9] */ - long flag; +register struct monst *mon; +coord *poss; /* coord poss[9] */ +long *info; /* long info[9] */ +long flag; { struct permonst *mdat = mon->data; - register xchar x,y,nx,ny; + register xchar x, y, nx, ny; register int cnt = 0; register uchar ntyp; uchar nowtyp; - boolean wantpool,poolok,lavaok,nodiag; + boolean wantpool, poolok, lavaok, nodiag; boolean rockok = FALSE, treeok = FALSE, thrudoor; int maxx, maxy; @@ -1012,198 +1093,209 @@ mfndpos(mon, poss, info, flag) nodiag = NODIAG(mdat - mons); wantpool = mdat->mlet == S_EEL; - poolok = is_flyer(mdat) || is_clinger(mdat) || - (is_swimmer(mdat) && !wantpool); + poolok = + is_flyer(mdat) || is_clinger(mdat) || (is_swimmer(mdat) && !wantpool); lavaok = is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat); - thrudoor = ((flag & (ALLOW_WALL|BUSTDOOR)) != 0L); + thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L); if (flag & ALLOW_DIG) { struct obj *mw_tmp; /* need to be specific about what can currently be dug */ if (!needspick(mdat)) { - rockok = treeok = TRUE; - } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed && - mon->weapon_check == NO_WEAPON_WANTED) { - rockok = is_pick(mw_tmp); - treeok = is_axe(mw_tmp); + rockok = treeok = TRUE; + } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed + && mon->weapon_check == NO_WEAPON_WANTED) { + rockok = is_pick(mw_tmp); + treeok = is_axe(mw_tmp); } else { - rockok = (m_carrying(mon, PICK_AXE) || - (m_carrying(mon, DWARVISH_MATTOCK) && - !which_armor(mon, W_ARMS))); - treeok = (m_carrying(mon, AXE) || - (m_carrying(mon, BATTLE_AXE) && - !which_armor(mon, W_ARMS))); + rockok = (m_carrying(mon, PICK_AXE) + || (m_carrying(mon, DWARVISH_MATTOCK) + && !which_armor(mon, W_ARMS))); + treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE) + && !which_armor(mon, W_ARMS))); } thrudoor |= rockok || treeok; } -nexttry: /* eels prefer the water, but if there is no water nearby, - they will crawl over land */ - if(mon->mconf) { +nexttry: /* eels prefer the water, but if there is no water nearby, + they will crawl over land */ + if (mon->mconf) { flag |= ALLOW_ALL; flag &= ~NOTONL; } - if(!mon->mcansee) + if (!mon->mcansee) flag |= ALLOW_SSM; - maxx = min(x+1,COLNO-1); - maxy = min(y+1,ROWNO-1); - for(nx = max(1,x-1); nx <= maxx; nx++) - for(ny = max(0,y-1); ny <= maxy; ny++) { - if(nx == x && ny == y) continue; - if(IS_ROCK(ntyp = levl[nx][ny].typ) && - !((flag & ALLOW_WALL) && may_passwall(nx,ny)) && - !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx,ny))) continue; - /* KMH -- Added iron bars */ - if (ntyp == IRONBARS && !(flag & ALLOW_BARS)) continue; - if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon)) && - (((levl[nx][ny].doormask & D_CLOSED) && - !(flag & OPENDOOR)) || - ((levl[nx][ny].doormask & D_LOCKED) && - !(flag & UNLOCKDOOR))) && - !thrudoor) continue; - /* first diagonal checks (tight squeezes handled below) */ - if (nx != x && ny != y && (nodiag || - (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN)) || - (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN)) || - ((IS_DOOR(nowtyp) || IS_DOOR(ntyp)) && Is_rogue_level(&u.uz)) || - /* mustn't pass between adjacent long worm segments, - but can attack that way */ - (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny) && - !m_at(nx, ny) && (nx != u.ux || ny != u.uy)))) - continue; - if((is_pool(nx,ny) == wantpool || poolok) && - (lavaok || !is_lava(nx,ny))) { - int dispx, dispy; - boolean monseeu = (mon->mcansee && (!Invis || perceives(mdat))); - boolean checkobj = OBJ_AT(nx,ny); - - /* Displacement also displaces the Elbereth/scare monster, - * as long as you are visible. - */ - if(Displaced && monseeu && (mon->mux==nx) && (mon->muy==ny)) { - dispx = u.ux; - dispy = u.uy; - } else { - dispx = nx; - dispy = ny; - } - - info[cnt] = 0; - if (onscary(dispx, dispy, mon)) { - if(!(flag & ALLOW_SSM)) continue; - info[cnt] |= ALLOW_SSM; - } - if((nx == u.ux && ny == u.uy) || - (nx == mon->mux && ny == mon->muy)) { - if (nx == u.ux && ny == u.uy) { - /* If it's right next to you, it found you, - * displaced or no. We must set mux and muy - * right now, so when we return we can tell - * that the ALLOW_U means to attack _you_ and - * not the image. - */ - mon->mux = u.ux; - mon->muy = u.uy; - } - if(!(flag & ALLOW_U)) continue; - info[cnt] |= ALLOW_U; - } else { - if(MON_AT(nx, ny)) { - struct monst *mtmp2 = m_at(nx, ny); - long mmflag = flag | mm_aggression(mon, mtmp2); - - if (mmflag & ALLOW_M) { - info[cnt] |= ALLOW_M; - if (mtmp2->mtame) { - if (!(mmflag & ALLOW_TM)) continue; - info[cnt] |= ALLOW_TM; - } - } else { - mmflag = flag | mm_displacement(mon, mtmp2); - if (!(mmflag & ALLOW_MDISP)) continue; - info[cnt] |= ALLOW_MDISP; - } - } - /* Note: ALLOW_SANCT only prevents movement, not */ - /* attack, into a temple. */ - if(level.flags.has_temple && - *in_rooms(nx, ny, TEMPLE) && - !*in_rooms(x, y, TEMPLE) && - in_your_sanctuary((struct monst *)0, nx, ny)) { - if(!(flag & ALLOW_SANCT)) continue; - info[cnt] |= ALLOW_SANCT; - } - } - if(checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) { - if(flag & NOGARLIC) continue; - info[cnt] |= NOGARLIC; - } - if(checkobj && sobj_at(BOULDER, nx, ny)) { - if(!(flag & ALLOW_ROCK)) continue; - info[cnt] |= ALLOW_ROCK; - } - if (monseeu && onlineu(nx,ny)) { - if(flag & NOTONL) continue; - info[cnt] |= NOTONL; - } - /* check for diagonal tight squeeze */ - if (nx != x && ny != y && bad_rock(mdat, x, ny) && - bad_rock(mdat, nx, y) && cant_squeeze_thru(mon)) - continue; - /* The monster avoids a particular type of trap if it's familiar - * with the trap type. Pets get ALLOW_TRAPS and checking is - * done in dogmove.c. In either case, "harmless" traps are - * neither avoided nor marked in info[]. - */ - { register struct trap *ttmp = t_at(nx, ny); - if(ttmp) { - if(ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) { -impossible("A monster looked at a very strange trap of type %d.", ttmp->ttyp); + maxx = min(x + 1, COLNO - 1); + maxy = min(y + 1, ROWNO - 1); + for (nx = max(1, x - 1); nx <= maxx; nx++) + for (ny = max(0, y - 1); ny <= maxy; ny++) { + if (nx == x && ny == y) continue; - } - if ((ttmp->ttyp != RUST_TRAP - || mdat == &mons[PM_IRON_GOLEM]) - && ttmp->ttyp != STATUE_TRAP - && ((ttmp->ttyp != PIT - && ttmp->ttyp != SPIKED_PIT - && ttmp->ttyp != TRAPDOOR - && ttmp->ttyp != HOLE) - || (!is_flyer(mdat) - && !is_floater(mdat) - && !is_clinger(mdat)) - || Sokoban) - && (ttmp->ttyp != SLP_GAS_TRAP || - !resists_sleep(mon)) - && (ttmp->ttyp != BEAR_TRAP || - (mdat->msize > MZ_SMALL && - !amorphous(mdat) && !is_flyer(mdat) && - !is_whirly(mdat) && !unsolid(mdat))) - && (ttmp->ttyp != FIRE_TRAP || - !resists_fire(mon)) - && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat)) - && (ttmp->ttyp != WEB || (!amorphous(mdat) && - !webmaker(mdat))) - && (ttmp->ttyp != ANTI_MAGIC || - !resists_magm(mon)) - ) { - if (!(flag & ALLOW_TRAPS)) { - if (mon->mtrapseen & (1L << (ttmp->ttyp - 1))) - continue; + if (IS_ROCK(ntyp = levl[nx][ny].typ) + && !((flag & ALLOW_WALL) && may_passwall(nx, ny)) + && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny))) + continue; + /* KMH -- Added iron bars */ + if (ntyp == IRONBARS && !(flag & ALLOW_BARS)) + continue; + if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon)) + && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR)) + || ((levl[nx][ny].doormask & D_LOCKED) + && !(flag & UNLOCKDOOR))) && !thrudoor) + continue; + /* first diagonal checks (tight squeezes handled below) */ + if (nx != x && ny != y + && (nodiag + || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN)) + || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN)) + || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp)) + && Is_rogue_level(&u.uz)) || + /* mustn't pass between adjacent long worm segments, + but can attack that way */ + (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny) + && !m_at(nx, ny) && (nx != u.ux || ny != u.uy)))) + continue; + if ((is_pool(nx, ny) == wantpool || poolok) + && (lavaok || !is_lava(nx, ny))) { + int dispx, dispy; + boolean monseeu = + (mon->mcansee && (!Invis || perceives(mdat))); + boolean checkobj = OBJ_AT(nx, ny); + + /* Displacement also displaces the Elbereth/scare monster, + * as long as you are visible. + */ + if (Displaced && monseeu && (mon->mux == nx) + && (mon->muy == ny)) { + dispx = u.ux; + dispy = u.uy; + } else { + dispx = nx; + dispy = ny; } - info[cnt] |= ALLOW_TRAPS; - } + + info[cnt] = 0; + if (onscary(dispx, dispy, mon)) { + if (!(flag & ALLOW_SSM)) + continue; + info[cnt] |= ALLOW_SSM; + } + if ((nx == u.ux && ny == u.uy) + || (nx == mon->mux && ny == mon->muy)) { + if (nx == u.ux && ny == u.uy) { + /* If it's right next to you, it found you, + * displaced or no. We must set mux and muy + * right now, so when we return we can tell + * that the ALLOW_U means to attack _you_ and + * not the image. + */ + mon->mux = u.ux; + mon->muy = u.uy; + } + if (!(flag & ALLOW_U)) + continue; + info[cnt] |= ALLOW_U; + } else { + if (MON_AT(nx, ny)) { + struct monst *mtmp2 = m_at(nx, ny); + long mmflag = flag | mm_aggression(mon, mtmp2); + + if (mmflag & ALLOW_M) { + info[cnt] |= ALLOW_M; + if (mtmp2->mtame) { + if (!(mmflag & ALLOW_TM)) + continue; + info[cnt] |= ALLOW_TM; + } + } else { + mmflag = flag | mm_displacement(mon, mtmp2); + if (!(mmflag & ALLOW_MDISP)) + continue; + info[cnt] |= ALLOW_MDISP; + } + } + /* Note: ALLOW_SANCT only prevents movement, not */ + /* attack, into a temple. */ + if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE) + && !*in_rooms(x, y, TEMPLE) + && in_your_sanctuary((struct monst *) 0, nx, ny)) { + if (!(flag & ALLOW_SANCT)) + continue; + info[cnt] |= ALLOW_SANCT; + } + } + if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) { + if (flag & NOGARLIC) + continue; + info[cnt] |= NOGARLIC; + } + if (checkobj && sobj_at(BOULDER, nx, ny)) { + if (!(flag & ALLOW_ROCK)) + continue; + info[cnt] |= ALLOW_ROCK; + } + if (monseeu && onlineu(nx, ny)) { + if (flag & NOTONL) + continue; + info[cnt] |= NOTONL; + } + /* check for diagonal tight squeeze */ + if (nx != x && ny != y && bad_rock(mdat, x, ny) + && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon)) + continue; + /* The monster avoids a particular type of trap if it's + * familiar + * with the trap type. Pets get ALLOW_TRAPS and checking is + * done in dogmove.c. In either case, "harmless" traps are + * neither avoided nor marked in info[]. + */ + { + register struct trap *ttmp = t_at(nx, ny); + if (ttmp) { + if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) { + impossible("A monster looked at a very strange " + "trap of type %d.", + ttmp->ttyp); + continue; + } + if ((ttmp->ttyp != RUST_TRAP + || mdat == &mons[PM_IRON_GOLEM]) + && ttmp->ttyp != STATUE_TRAP + && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT + && ttmp->ttyp != TRAPDOOR + && ttmp->ttyp != HOLE) + || (!is_flyer(mdat) && !is_floater(mdat) + && !is_clinger(mdat)) || Sokoban) + && (ttmp->ttyp != SLP_GAS_TRAP + || !resists_sleep(mon)) + && (ttmp->ttyp != BEAR_TRAP + || (mdat->msize > MZ_SMALL && !amorphous(mdat) + && !is_flyer(mdat) && !is_whirly(mdat) + && !unsolid(mdat))) + && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon)) + && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat)) + && (ttmp->ttyp != WEB + || (!amorphous(mdat) && !webmaker(mdat))) + && (ttmp->ttyp != ANTI_MAGIC + || !resists_magm(mon))) { + if (!(flag & ALLOW_TRAPS)) { + if (mon->mtrapseen & (1L << (ttmp->ttyp - 1))) + continue; + } + info[cnt] |= ALLOW_TRAPS; + } + } + } + poss[cnt].x = nx; + poss[cnt].y = ny; + cnt++; } } - poss[cnt].x = nx; - poss[cnt].y = ny; - cnt++; - } - } - if(!cnt && wantpool && !is_pool(x,y)) { + if (!cnt && wantpool && !is_pool(x, y)) { wantpool = FALSE; goto nexttry; } - return(cnt); + return (cnt); } /* Monster against monster special attacks; for the specified monster @@ -1213,14 +1305,14 @@ impossible("A monster looked at a very strange trap of type %d.", ttmp->ttyp); next to each other. */ STATIC_OVL long mm_aggression(magr, mdef) -struct monst *magr, /* monster that is currently deciding where to move */ - *mdef; /* another monster which is next to it */ +struct monst *magr, /* monster that is currently deciding where to move */ + *mdef; /* another monster which is next to it */ { /* supposedly purple worms are attracted to shrieking because they like to eat shriekers, so attack the latter when feasible */ - if (magr->data == &mons[PM_PURPLE_WORM] && - mdef->data == &mons[PM_SHRIEKER]) - return ALLOW_M|ALLOW_TM; + if (magr->data == &mons[PM_PURPLE_WORM] + && mdef->data == &mons[PM_SHRIEKER]) + return ALLOW_M | ALLOW_TM; /* Various other combinations such as dog vs cat, cat vs rat, and elf vs orc have been suggested. For the time being we don't support those. */ @@ -1230,21 +1322,20 @@ struct monst *magr, /* monster that is currently deciding where to move */ /* Monster displacing another monster out of the way */ STATIC_OVL long mm_displacement(magr, mdef) -struct monst *magr, /* monster that is currently deciding where to move */ - *mdef; /* another monster which is next to it */ +struct monst *magr, /* monster that is currently deciding where to move */ + *mdef; /* another monster which is next to it */ { - struct permonst *pa = magr->data, - *pd = mdef->data; + struct permonst *pa = magr->data, *pd = mdef->data; /* if attacker can't barge through, there's nothing to do; or if defender can barge through too, don't let attacker do so, otherwise they might just end up swapping places again when defender gets its chance to move */ - if ((pa->mflags3 & M3_DISPLACES) != 0 && - (pd->mflags3 & M3_DISPLACES) == 0 && + if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0 + && /* no displacing grid bugs diagonally */ - !(magr->mx != mdef->mx && magr->my != mdef->my && - NODIAG(monsndx(pd))) && + !(magr->mx != mdef->mx && magr->my != mdef->my && NODIAG(monsndx(pd))) + && /* no displacing trapped monsters or multi-location longworms */ !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef)) && /* riders can move anything; others, same size or smaller only */ @@ -1256,13 +1347,14 @@ struct monst *magr, /* monster that is currently deciding where to move */ boolean monnear(mon, x, y) register struct monst *mon; -register int x,y; +register int x, y; /* Is the square close enough for the monster to move or attack into? */ { register int distance = dist2(mon->mx, mon->my, x, y); - if (distance == 2 && NODIAG(mon->data - mons)) return 0; - return((boolean)(distance < 3)); + if (distance == 2 && NODIAG(mon->data - mons)) + return 0; + return ((boolean)(distance < 3)); } /* really free dead monsters */ @@ -1273,18 +1365,18 @@ dmonsfree() int count = 0; for (mtmp = &fmon; *mtmp;) { - freetmp = *mtmp; - if (freetmp->mhp <= 0 && !freetmp->isgd) { - *mtmp = freetmp->nmon; - dealloc_monst(freetmp); - count++; - } else - mtmp = &(freetmp->nmon); + freetmp = *mtmp; + if (freetmp->mhp <= 0 && !freetmp->isgd) { + *mtmp = freetmp->nmon; + dealloc_monst(freetmp); + count++; + } else + mtmp = &(freetmp->nmon); } if (count != iflags.purge_monsters) - impossible("dmonsfree: %d removed doesn't match %d pending", - count, iflags.purge_monsters); + impossible("dmonsfree: %d removed doesn't match %d pending", count, + iflags.purge_monsters); iflags.purge_monsters = 0; } @@ -1297,33 +1389,36 @@ register struct monst *mtmp, *mtmp2; /* transfer the monster's inventory */ for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) { - if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp) - debugpline0("replmon: minvent inconsistency"); - otmp->ocarry = mtmp2; + if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp) + debugpline0("replmon: minvent inconsistency"); + otmp->ocarry = mtmp2; } mtmp->minvent = 0; /* remove the old monster from the map and from `fmon' list */ - relmon(mtmp, (struct monst **)0); + relmon(mtmp, (struct monst **) 0); /* finish adding its replacement */ - if (mtmp != u.usteed) /* don't place steed onto the map */ + if (mtmp != u.usteed) /* don't place steed onto the map */ place_monster(mtmp2, mtmp2->mx, mtmp2->my); - if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */ - place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */ + if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */ + place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */ if (emits_light(mtmp2->data)) { - /* since this is so rare, we don't have any `mon_move_light_source' */ - new_light_source(mtmp2->mx, mtmp2->my, - emits_light(mtmp2->data), - LS_MONSTER, monst_to_any(mtmp2)); - /* here we rely on the fact that `mtmp' hasn't actually been deleted */ - del_light_source(LS_MONSTER, monst_to_any(mtmp)); + /* since this is so rare, we don't have any `mon_move_light_source' */ + new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data), + LS_MONSTER, monst_to_any(mtmp2)); + /* here we rely on the fact that `mtmp' hasn't actually been deleted + */ + del_light_source(LS_MONSTER, monst_to_any(mtmp)); } mtmp2->nmon = fmon; fmon = mtmp2; - if (u.ustuck == mtmp) u.ustuck = mtmp2; - if (u.usteed == mtmp) u.usteed = mtmp2; - if (mtmp2->isshk) replshk(mtmp,mtmp2); + if (u.ustuck == mtmp) + u.ustuck = mtmp2; + if (u.usteed == mtmp) + u.usteed = mtmp2; + if (mtmp2->isshk) + replshk(mtmp, mtmp2); /* discard the old monster */ dealloc_monst(mtmp); @@ -1334,13 +1429,14 @@ register struct monst *mtmp, *mtmp2; void relmon(mon, monst_list) register struct monst *mon; -struct monst **monst_list; /* &migrating_mons or &mydogs or null */ +struct monst **monst_list; /* &migrating_mons or &mydogs or null */ { register struct monst *mtmp; boolean unhide = (monst_list != 0); int mx = mon->mx, my = mon->my; - if (!fmon) panic("relmon: no fmon available."); + if (!fmon) + panic("relmon: no fmon available."); if (unhide) { /* can't remain hidden across level changes (exception: wizard @@ -1348,7 +1444,7 @@ struct monst **monst_list; /* &migrating_mons or &mydogs or null */ might be imitating a boulder so need line-of-sight unblocking */ mon->mundetected = 0; if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER) - seemimic(mon); + seemimic(mon); } remove_monster(mx, my); @@ -1357,10 +1453,13 @@ struct monst **monst_list; /* &migrating_mons or &mydogs or null */ fmon = fmon->nmon; } else { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (mtmp->nmon == mon) break; + if (mtmp->nmon == mon) + break; - if (mtmp) mtmp->nmon = mon->nmon; - else panic("relmon: mon not in list."); + if (mtmp) + mtmp->nmon = mon->nmon; + else + panic("relmon: mon not in list."); } if (unhide) { @@ -1378,44 +1477,47 @@ void copy_mextra(mtmp2, mtmp1) struct monst *mtmp2, *mtmp1; { - if(!mtmp2 || !mtmp1 || !mtmp1->mextra) return; + if (!mtmp2 || !mtmp1 || !mtmp1->mextra) + return; - if (!mtmp2->mextra) mtmp2->mextra = newmextra(); + if (!mtmp2->mextra) + mtmp2->mextra = newmextra(); if (MNAME(mtmp1)) { - new_mname(mtmp2, (int)strlen(MNAME(mtmp1)) + 1); + new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1); Strcpy(MNAME(mtmp2), MNAME(mtmp1)); } if (EGD(mtmp1)) { - if (!EGD(mtmp2)) newegd(mtmp2); - (void)memcpy((genericptr_t)EGD(mtmp2), - (genericptr_t)EGD(mtmp1), - sizeof(struct egd)); + if (!EGD(mtmp2)) + newegd(mtmp2); + (void) memcpy((genericptr_t) EGD(mtmp2), (genericptr_t) EGD(mtmp1), + sizeof(struct egd)); } if (EPRI(mtmp1)) { - if (!EPRI(mtmp2)) newepri(mtmp2); - (void)memcpy((genericptr_t)EPRI(mtmp2), - (genericptr_t)EPRI(mtmp1), - sizeof(struct epri)); + if (!EPRI(mtmp2)) + newepri(mtmp2); + (void) memcpy((genericptr_t) EPRI(mtmp2), (genericptr_t) EPRI(mtmp1), + sizeof(struct epri)); } if (ESHK(mtmp1)) { - if (!ESHK(mtmp2)) neweshk(mtmp2); - (void)memcpy((genericptr_t)ESHK(mtmp2), - (genericptr_t)ESHK(mtmp1), - sizeof(struct eshk)); + if (!ESHK(mtmp2)) + neweshk(mtmp2); + (void) memcpy((genericptr_t) ESHK(mtmp2), (genericptr_t) ESHK(mtmp1), + sizeof(struct eshk)); } if (EMIN(mtmp1)) { - if (!EMIN(mtmp2)) newemin(mtmp2); - (void)memcpy((genericptr_t)EMIN(mtmp2), - (genericptr_t)EMIN(mtmp1), - sizeof(struct emin)); + if (!EMIN(mtmp2)) + newemin(mtmp2); + (void) memcpy((genericptr_t) EMIN(mtmp2), (genericptr_t) EMIN(mtmp1), + sizeof(struct emin)); } if (EDOG(mtmp1)) { - if (!EDOG(mtmp2)) newedog(mtmp2); - (void)memcpy((genericptr_t)EDOG(mtmp2), - (genericptr_t)EDOG(mtmp1), - sizeof(struct edog)); + if (!EDOG(mtmp2)) + newedog(mtmp2); + (void) memcpy((genericptr_t) EDOG(mtmp2), (genericptr_t) EDOG(mtmp1), + sizeof(struct edog)); } - if (has_mcorpsenm(mtmp1)) MCORPSENM(mtmp2) = MCORPSENM(mtmp1); + if (has_mcorpsenm(mtmp1)) + MCORPSENM(mtmp2) = MCORPSENM(mtmp1); } STATIC_OVL void @@ -1423,14 +1525,20 @@ dealloc_mextra(x) struct mextra *x; { if (x) { - if (x->mname) free((genericptr_t)x->mname); - if (x->egd) free((genericptr_t)x->egd); - if (x->epri) free((genericptr_t)x->epri); - if (x->eshk) free((genericptr_t)x->eshk); - if (x->emin) free((genericptr_t)x->emin); - if (x->edog) free((genericptr_t)x->edog); + if (x->mname) + free((genericptr_t) x->mname); + if (x->egd) + free((genericptr_t) x->egd); + if (x->epri) + free((genericptr_t) x->epri); + if (x->eshk) + free((genericptr_t) x->eshk); + if (x->emin) + free((genericptr_t) x->emin); + if (x->edog) + free((genericptr_t) x->edog); /* [no action needed for x->mcorpsenm] */ - free((genericptr_t)x); + free((genericptr_t) x); } } @@ -1438,32 +1546,36 @@ void dealloc_monst(mon) struct monst *mon; { - if (mon->mextra) dealloc_mextra(mon->mextra); - free((genericptr_t)mon); + if (mon->mextra) + dealloc_mextra(mon->mextra); + free((genericptr_t) mon); } /* remove effects of mtmp from other data structures */ STATIC_OVL void m_detach(mtmp, mptr) struct monst *mtmp; -struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */ +struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */ { if (mtmp == context.polearm.hitmon) - context.polearm.hitmon = 0; - if (mtmp->mleashed) m_unleash(mtmp, FALSE); - /* to prevent an infinite relobj-flooreffects-hmon-killed loop */ + context.polearm.hitmon = 0; + if (mtmp->mleashed) + m_unleash(mtmp, FALSE); + /* to prevent an infinite relobj-flooreffects-hmon-killed loop */ mtmp->mtrapped = 0; mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */ relobj(mtmp, 0, FALSE); remove_monster(mtmp->mx, mtmp->my); if (emits_light(mptr)) del_light_source(LS_MONSTER, monst_to_any(mtmp)); - newsym(mtmp->mx,mtmp->my); + newsym(mtmp->mx, mtmp->my); unstuck(mtmp); fill_pit(mtmp->mx, mtmp->my); - if(mtmp->isshk) shkgone(mtmp); - if(mtmp->wormno) wormgone(mtmp); + if (mtmp->isshk) + shkgone(mtmp); + if (mtmp->wormno) + wormgone(mtmp); iflags.purge_monsters++; } @@ -1476,9 +1588,9 @@ struct monst *mon; struct obj *otmp = which_armor(mon, W_AMUL); if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING) - return otmp; + return otmp; } - return (struct obj *)0; + return (struct obj *) 0; } STATIC_OVL void @@ -1495,16 +1607,15 @@ struct monst *mtmp; * disintegrating amulets are always visible. */ if (cansee(mtmp->mx, mtmp->my)) { pline("But wait..."); - pline("%s medallion begins to glow!", - s_suffix(Monnam(mtmp))); + pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp))); makeknown(AMULET_OF_LIFE_SAVING); /* amulet is visible, but monster might not be */ if (canseemon(mtmp)) { - if (attacktype(mtmp->data, AT_EXPL) - || attacktype(mtmp->data, AT_BOOM)) - pline("%s reconstitutes!", Monnam(mtmp)); - else - pline("%s looks much better!", Monnam(mtmp)); + if (attacktype(mtmp->data, AT_EXPL) + || attacktype(mtmp->data, AT_BOOM)) + pline("%s reconstitutes!", Monnam(mtmp)); + else + pline("%s looks much better!", Monnam(mtmp)); } pline_The("medallion crumbles to dust!"); } @@ -1516,14 +1627,15 @@ struct monst *mtmp; if (mtmp->mtame && !mtmp->isminion) { wary_dog(mtmp, !surviver); } - if (mtmp->mhpmax <= 0) mtmp->mhpmax = 10; + if (mtmp->mhpmax <= 0) + mtmp->mhpmax = 10; mtmp->mhp = mtmp->mhpmax; - if (surviver) return; + if (surviver) + return; /* genocided monster can't be life-saved */ if (cansee(mtmp->mx, mtmp->my)) - pline("Unfortunately, %s is still genocided...", - mon_nam(mtmp)); + pline("Unfortunately, %s is still genocided...", mon_nam(mtmp)); } mtmp->mhp = 0; } @@ -1536,7 +1648,8 @@ register struct monst *mtmp; int tmp; lifesaved_monster(mtmp); - if (mtmp->mhp > 0) return; + if (mtmp->mhp > 0) + return; if (is_vampshifter(mtmp)) { int mndx = mtmp->cham; @@ -1544,31 +1657,32 @@ register struct monst *mtmp; /* this only happens if shapeshifted */ if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)) { char buf[BUFSZ]; - boolean in_door = amorphous(mtmp->data) && - closed_door(mtmp->mx,mtmp->my); - Sprintf(buf, - "The %s%s suddenly %s and rises as %%s!", - (nonliving(mtmp->data) || - noncorporeal(mtmp->data) || - amorphous(mtmp->data)) ? "" : "seemingly dead ", - x_monnam(mtmp, ARTICLE_NONE, (char *)0, - SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION | - SUPPRESS_INVISIBLE | SUPPRESS_IT, FALSE), - (nonliving(mtmp->data) || - noncorporeal(mtmp->data) || - amorphous(mtmp->data)) ? - "reconstitutes" : "transforms"); + boolean in_door = + amorphous(mtmp->data) && closed_door(mtmp->mx, mtmp->my); + Sprintf(buf, "The %s%s suddenly %s and rises as %%s!", + (nonliving(mtmp->data) || noncorporeal(mtmp->data) + || amorphous(mtmp->data)) + ? "" + : "seemingly dead ", + x_monnam(mtmp, ARTICLE_NONE, (char *) 0, + SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION + | SUPPRESS_INVISIBLE | SUPPRESS_IT, + FALSE), + (nonliving(mtmp->data) || noncorporeal(mtmp->data) + || amorphous(mtmp->data)) + ? "reconstitutes" + : "transforms"); mtmp->mcanmove = 1; mtmp->mfrozen = 0; - if (mtmp->mhpmax <= 0) mtmp->mhpmax = 10; + if (mtmp->mhpmax <= 0) + mtmp->mhpmax = 10; mtmp->mhp = mtmp->mhpmax; /* this can happen if previously a fog cloud */ if (u.uswallow && (mtmp == u.ustuck)) expels(mtmp, mtmp->data, FALSE); if (in_door) { coord new_xy; - if (enexto(&new_xy, - mtmp->mx, mtmp->my, &mons[mndx])) { + if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) { rloc_to(mtmp, new_xy.x, new_xy.y); } } @@ -1579,7 +1693,7 @@ register struct monst *mtmp; mtmp->cham = mndx; if ((!Blind && canseemon(mtmp)) || sensemon(mtmp)) pline(buf, a_monnam(mtmp)); - newsym(x,y); + newsym(x, y); return; } } @@ -1587,19 +1701,19 @@ register struct monst *mtmp; /* dead vault guard is actually kept at coordinate <0,0> until his temporary corridor to/from the vault has been removed; need to do this after life-saving and before m_detach() */ - if (mtmp->isgd && !grddead(mtmp)) return; + if (mtmp->isgd && !grddead(mtmp)) + return; /* Player is thrown from his steed when it dies */ if (mtmp == u.usteed) dismount_steed(DISMOUNT_GENERIC); - mptr = mtmp->data; /* save this for m_detach() */ + mptr = mtmp->data; /* save this for m_detach() */ /* restore chameleon, lycanthropes to true form at death */ if (mtmp->cham >= LOW_PM) { set_mon_data(mtmp, &mons[mtmp->cham], -1); mtmp->cham = NON_PM; - } - else if (mtmp->data == &mons[PM_WEREJACKAL]) + } else if (mtmp->data == &mons[PM_WEREJACKAL]) set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1); else if (mtmp->data == &mons[PM_WEREWOLF]) set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1); @@ -1619,34 +1733,38 @@ register struct monst *mtmp; * for rings of conflict and such. */ tmp = monsndx(mtmp->data); - if (mvitals[tmp].died < 255) mvitals[tmp].died++; + if (mvitals[tmp].died < 255) + mvitals[tmp].died++; /* if it's a (possibly polymorphed) quest leader, mark him as dead */ if (mtmp->m_id == quest_status.leader_m_id) quest_status.leader_is_dead = TRUE; #ifdef MAIL /* if the mail daemon dies, no more mail delivery. -3. */ - if (tmp == PM_MAIL_DAEMON) mvitals[tmp].mvflags |= G_GENOD; + if (tmp == PM_MAIL_DAEMON) + mvitals[tmp].mvflags |= G_GENOD; #endif if (mtmp->data->mlet == S_KOP) { /* Dead Kops may come back. */ - switch(rnd(5)) { - case 1: /* returns near the stairs */ - (void) makemon(mtmp->data,xdnstair,ydnstair,NO_MM_FLAGS); + switch (rnd(5)) { + case 1: /* returns near the stairs */ + (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS); break; - case 2: /* randomly */ - (void) makemon(mtmp->data,0,0,NO_MM_FLAGS); + case 2: /* randomly */ + (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS); break; default: break; } } - if(mtmp->iswiz) wizdead(); - if(mtmp->data->msound == MS_NEMESIS) nemdead(); - if(mtmp->data == &mons[PM_MEDUSA]) + if (mtmp->iswiz) + wizdead(); + if (mtmp->data->msound == MS_NEMESIS) + nemdead(); + if (mtmp->data == &mons[PM_MEDUSA]) u.uachieve.killed_medusa = 1; - if(glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) + if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) unmap_object(mtmp->mx, mtmp->my); m_detach(mtmp, mptr); } @@ -1655,52 +1773,51 @@ register struct monst *mtmp; boolean corpse_chance(mon, magr, was_swallowed) struct monst *mon; -struct monst *magr; /* killer, if swallowed */ -boolean was_swallowed; /* digestion */ +struct monst *magr; /* killer, if swallowed */ +boolean was_swallowed; /* digestion */ { struct permonst *mdat = mon->data; int i, tmp; if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) { if (cansee(mon->mx, mon->my) && !was_swallowed) - pline("%s body crumbles into dust.", s_suffix(Monnam(mon))); + pline("%s body crumbles into dust.", s_suffix(Monnam(mon))); return FALSE; } /* Gas spores always explode upon death */ - for(i = 0; i < NATTK; i++) { + for (i = 0; i < NATTK; i++) { if (mdat->mattk[i].aatyp == AT_BOOM) { if (mdat->mattk[i].damn) - tmp = d((int)mdat->mattk[i].damn, - (int)mdat->mattk[i].damd); - else if(mdat->mattk[i].damd) - tmp = d((int)mdat->mlevel+1, (int)mdat->mattk[i].damd); - else tmp = 0; - if (was_swallowed && magr) { - if (magr == &youmonst) { - There("is an explosion in your %s!", - body_part(STOMACH)); - Sprintf(killer.name, "%s explosion", - s_suffix(mdat->mname)); - losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN); - } else { - You_hear("an explosion."); - magr->mhp -= tmp; - if (magr->mhp < 1) mondied(magr); - if (magr->mhp < 1) { /* maybe lifesaved */ - if (canspotmon(magr)) - pline("%s rips open!", Monnam(magr)); - } else if (canseemon(magr)) - pline("%s seems to have indigestion.", - Monnam(magr)); - } + tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd); + else if (mdat->mattk[i].damd) + tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd); + else + tmp = 0; + if (was_swallowed && magr) { + if (magr == &youmonst) { + There("is an explosion in your %s!", body_part(STOMACH)); + Sprintf(killer.name, "%s explosion", + s_suffix(mdat->mname)); + losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN); + } else { + You_hear("an explosion."); + magr->mhp -= tmp; + if (magr->mhp < 1) + mondied(magr); + if (magr->mhp < 1) { /* maybe lifesaved */ + if (canspotmon(magr)) + pline("%s rips open!", Monnam(magr)); + } else if (canseemon(magr)) + pline("%s seems to have indigestion.", Monnam(magr)); + } - return FALSE; - } + return FALSE; + } Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname)); killer.format = KILLED_BY_AN; - explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS); + explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS); return (FALSE); } } @@ -1711,8 +1828,8 @@ boolean was_swallowed; /* digestion */ if (LEVEL_SPECIFIC_NOCORPSE(mdat)) return FALSE; - if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned) || - is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat)) + if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned) + || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat)) return TRUE; tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat); return (boolean) !rn2(tmp); @@ -1724,11 +1841,12 @@ mondied(mdef) register struct monst *mdef; { mondead(mdef); - if (mdef->mhp > 0) return; /* lifesaved */ + if (mdef->mhp > 0) + return; /* lifesaved */ - if (corpse_chance(mdef, (struct monst *)0, FALSE) && - (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my))) - (void) make_corpse(mdef,CORPSTAT_NONE); + if (corpse_chance(mdef, (struct monst *) 0, FALSE) + && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my))) + (void) make_corpse(mdef, CORPSTAT_NONE); } /* monster disappears, not dies */ @@ -1736,11 +1854,12 @@ void mongone(mdef) register struct monst *mdef; { - mdef->mhp = 0; /* can skip some inventory bookkeeping */ + mdef->mhp = 0; /* can skip some inventory bookkeeping */ /* dead vault guard is actually kept at coordinate <0,0> until his temporary corridor to/from the vault has been removed */ - if (mdef->isgd && !grddead(mdef)) return; + if (mdef->isgd && !grddead(mdef)) + return; /* hero is thrown from his steed when it disappears */ if (mdef == u.usteed) dismount_steed(DISMOUNT_GENERIC); @@ -1767,40 +1886,44 @@ register struct monst *mdef; * making the statue.... */ lifesaved_monster(mdef); - if (mdef->mhp > 0) return; + if (mdef->mhp > 0) + return; - mdef->mtrapped = 0; /* (see m_detach) */ + mdef->mtrapped = 0; /* (see m_detach) */ - if ((int)mdef->data->msize > MZ_TINY || - !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) { + if ((int) mdef->data->msize > MZ_TINY + || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) { oldminvent = 0; /* some objects may end up outside the statue */ while ((obj = mdef->minvent) != 0) { obj_extract_self(obj); if (obj->owornmask) - update_mon_intrinsics(mdef, obj, FALSE, TRUE); + update_mon_intrinsics(mdef, obj, FALSE, TRUE); obj_no_longer_held(obj); if (obj->owornmask & W_WEP) - setmnotwielded(mdef,obj); + setmnotwielded(mdef, obj); obj->owornmask = 0L; if (obj->otyp == BOULDER || -#if 0 /* monsters don't carry statues */ +#if 0 /* monsters don't carry statues */ (obj->otyp == STATUE && mons[obj->corpsenm].msize >= mdef->data->msize) || #endif obj_resists(obj, 0, 0)) { - if (flooreffects(obj, x, y, "fall")) continue; - place_object(obj, x, y); + if (flooreffects(obj, x, y, "fall")) + continue; + place_object(obj, x, y); } else { - if (obj->lamplit) end_burn(obj, TRUE); - obj->nobj = oldminvent; - oldminvent = obj; + if (obj->lamplit) + end_burn(obj, TRUE); + obj->nobj = oldminvent; + oldminvent = obj; } } /* defer statue creation until after inventory removal so that saved monster traits won't retain any stale item-conferred attributes */ otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE); - if (has_mname(mdef)) otmp = oname(otmp, MNAME(mdef)); + if (has_mname(mdef)) + otmp = oname(otmp, MNAME(mdef)); while ((obj = oldminvent) != 0) { oldminvent = obj->nobj; (void) add_to_container(otmp, obj); @@ -1814,17 +1937,19 @@ register struct monst *mdef; stackobj(otmp); /* mondead() already does this, but we must do it before the newsym */ - if(glyph_is_invisible(levl[x][y].glyph)) + if (glyph_is_invisible(levl[x][y].glyph)) unmap_object(x, y); - if (cansee(x, y)) newsym(x,y); - /* We don't currently trap the hero in the statue in this case but we could */ - if (u.uswallow && u.ustuck == mdef) wasinside = TRUE; + if (cansee(x, y)) + newsym(x, y); + /* We don't currently trap the hero in the statue in this case but we + * could */ + if (u.uswallow && u.ustuck == mdef) + wasinside = TRUE; mondead(mdef); if (wasinside) { if (is_animal(mdef->data)) You("%s through an opening in the new %s.", - locomotion(youmonst.data, "jump"), - xname(otmp)); + locomotion(youmonst.data, "jump"), xname(otmp)); } } @@ -1835,20 +1960,18 @@ register struct monst *mdef; const char *fltxt; int how; { - boolean be_sad = FALSE; /* true if unseen pet is killed */ + boolean be_sad = FALSE; /* true if unseen pet is killed */ if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my)) && fltxt) pline("%s is %s%s%s!", Monnam(mdef), - nonliving(mdef->data) ? "destroyed" : "killed", - *fltxt ? " by the " : "", - fltxt - ); + nonliving(mdef->data) ? "destroyed" : "killed", + *fltxt ? " by the " : "", fltxt); else be_sad = (mdef->mtame != 0); /* no corpses if digested or disintegrated */ - if(how == AD_DGST || how == -AD_RBRE) + if (how == AD_DGST || how == -AD_RBRE) mondead(mdef); else mondied(mdef); @@ -1861,13 +1984,14 @@ void unstuck(mtmp) register struct monst *mtmp; { - if(u.ustuck == mtmp) { - if(u.uswallow){ + if (u.ustuck == mtmp) { + if (u.uswallow) { u.ux = mtmp->mx; u.uy = mtmp->my; u.uswallow = 0; u.uswldtim = 0; - if (Punished && uchain->where != OBJ_FLOOR) placebc(); + if (Punished && uchain->where != OBJ_FLOOR) + placebc(); vision_full_recalc = 1; docrt(); } @@ -1906,37 +2030,38 @@ int dest; const char *verb = nonliving(mtmp->data) ? "destroy" : "kill"; if (!wasinside && !canspotmon(mtmp)) - You("%s it!", verb); + You("%s it!", verb); else { - You("%s %s!", verb, - !mtmp->mtame ? mon_nam(mtmp) : - x_monnam(mtmp, - (has_mname(mtmp)) ? ARTICLE_NONE : ARTICLE_THE, - "poor", - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, - FALSE)); + You("%s %s!", verb, + !mtmp->mtame + ? mon_nam(mtmp) + : x_monnam(mtmp, + (has_mname(mtmp)) ? ARTICLE_NONE : ARTICLE_THE, + "poor", + (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, + FALSE)); } } - if (mtmp->mtrapped && (t = t_at(x, y)) != 0 && - (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { - + if (mtmp->mtrapped && (t = t_at(x, y)) != 0 + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { if (sobj_at(BOULDER, x, y)) - dest |= 2; /* - * Prevent corpses/treasure being created "on top" - * of the boulder that is about to fall in. This is - * out of order, but cannot be helped unless this - * whole routine is rearranged. - */ + dest |= 2; /* + * Prevent corpses/treasure being created "on top" + * of the boulder that is about to fall in. This is + * out of order, but cannot be helped unless this + * whole routine is rearranged. + */ if (m_carrying(mtmp, BOULDER)) burycorpse = TRUE; } /* your pet knows who just killed it...watch out */ - if (mtmp->mtame && !mtmp->isminion) EDOG(mtmp)->killed_by_u = 1; + if (mtmp->mtame && !mtmp->isminion) + EDOG(mtmp)->killed_by_u = 1; if (wasinside && thrownobj && thrownobj != uball) { - /* thrown object has killed hero's engulfer; add it to mon's + /* thrown object has killed hero's engulfer; add it to mon's inventory now so that it will be placed with mon's other stuff prior to lookhere/autopickup when hero is expelled below (as a side-effect, this missile has immunity from @@ -1947,17 +2072,20 @@ int dest; } /* dispose of monster and make cadaver */ - if(stoned) monstone(mtmp); - else mondead(mtmp); + if (stoned) + monstone(mtmp); + else + mondead(mtmp); if (mtmp->mhp > 0) { /* monster lifesaved */ - /* Cannot put the non-visible lifesaving message in - * lifesaved_monster() since the message appears only when you - * kill it (as opposed to visible lifesaving which always - * appears). - */ + /* Cannot put the non-visible lifesaving message in + * lifesaved_monster() since the message appears only when you + * kill it (as opposed to visible lifesaving which always + * appears). + */ stoned = FALSE; - if (!cansee(x,y)) pline("Maybe not..."); + if (!cansee(x, y)) + pline("Maybe not..."); return; } @@ -1969,11 +2097,11 @@ int dest; goto cleanup; } - if((dest & 2) || LEVEL_SPECIFIC_NOCORPSE(mdat)) + if ((dest & 2) || LEVEL_SPECIFIC_NOCORPSE(mdat)) goto cleanup; #ifdef MAIL - if(mdat == &mons[PM_MAIL_DAEMON]) { + if (mdat == &mons[PM_MAIL_DAEMON]) { stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE)); } #endif @@ -1989,78 +2117,83 @@ int dest; && mdat->mlet != S_KOP /* no items from cloned monsters */ && !mtmp->mcloned) { - otmp = mkobj(RANDOM_CLASS, TRUE); - /* don't create large objects from small monsters */ - otyp = otmp->otyp; - if (mdat->msize < MZ_HUMAN && otyp != FIGURINE && - /* oc_big is also oc_bimanual and oc_bulky */ - (otmp->owt > 30 || objects[otyp].oc_big)) { - delobj(otmp); - } else if (!flooreffects(otmp, x, y, - (dest & 1) ? "fall" : "")) { - place_object(otmp, x, y); - stackobj(otmp); - } + otmp = mkobj(RANDOM_CLASS, TRUE); + /* don't create large objects from small monsters */ + otyp = otmp->otyp; + if (mdat->msize < MZ_HUMAN && otyp != FIGURINE && + /* oc_big is also oc_bimanual and oc_bulky */ + (otmp->owt > 30 || objects[otyp].oc_big)) { + delobj(otmp); + } else if (!flooreffects(otmp, x, y, (dest & 1) ? "fall" : "")) { + place_object(otmp, x, y); + stackobj(otmp); + } } /* corpse--none if hero was inside the monster */ - if (!wasinside && corpse_chance(mtmp, (struct monst *)0, FALSE)) { - cadaver = make_corpse(mtmp, burycorpse ? - CORPSTAT_BURIED : CORPSTAT_NONE); - if (burycorpse && cadaver && cansee(x,y) && !mtmp->minvis && - cadaver->where == OBJ_BURIED && (dest & 1)) { - pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp))); - } + if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) { + cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED + : CORPSTAT_NONE); + if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis + && cadaver->where == OBJ_BURIED && (dest & 1)) { + pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp))); + } } } - if (wasinside) spoteffects(TRUE); /* poor man's expels() */ + if (wasinside) + spoteffects(TRUE); /* poor man's expels() */ /* monster is gone, corpse or other object might now be visible */ newsym(x, y); cleanup: /* punish bad behaviour */ - if(is_human(mdat) && (!always_hostile(mdat) && mtmp->malign <= 0) && - (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD) && - u.ualign.type != A_CHAOTIC) { + if (is_human(mdat) && (!always_hostile(mdat) && mtmp->malign <= 0) + && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD) + && u.ualign.type != A_CHAOTIC) { HTelepat &= ~INTRINSIC; change_luck(-2); You("murderer!"); if (Blind && !Blind_telepat) see_monsters(); /* Can't sense monsters any more. */ } - if((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame) change_luck(-1); - if (is_unicorn(mdat) && - sgn(u.ualign.type) == sgn(mdat->maligntyp)) { + if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame) + change_luck(-1); + if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) { change_luck(-5); You_feel("guilty..."); } /* give experience points */ - tmp = experience(mtmp, (int)mvitals[mndx].died); + tmp = experience(mtmp, (int) mvitals[mndx].died); more_experienced(tmp, 0); - newexplevel(); /* will decide if you go up */ + newexplevel(); /* will decide if you go up */ /* adjust alignment points */ - if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */ - adjalign(-(u.ualign.record+(int)ALIGNLIM/2)); + if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */ + adjalign(-(u.ualign.record + (int) ALIGNLIM / 2)); pline("That was %sa bad idea...", - u.uevent.qcompleted ? "probably " : ""); - } else if (mdat->msound == MS_NEMESIS) /* Real good! */ - adjalign((int)(ALIGNLIM/4)); - else if (mdat->msound == MS_GUARDIAN) { /* Bad */ - adjalign(-(int)(ALIGNLIM/8)); - if (!Hallucination) pline("That was probably a bad idea..."); - else pline("Whoopsie-daisy!"); - }else if (mtmp->ispriest) { + u.uevent.qcompleted ? "probably " : ""); + } else if (mdat->msound == MS_NEMESIS) /* Real good! */ + adjalign((int) (ALIGNLIM / 4)); + else if (mdat->msound == MS_GUARDIAN) { /* Bad */ + adjalign(-(int) (ALIGNLIM / 8)); + if (!Hallucination) + pline("That was probably a bad idea..."); + else + pline("Whoopsie-daisy!"); + } else if (mtmp->ispriest) { adjalign((p_coaligned(mtmp)) ? -2 : 2); /* cancel divine protection for killing your priest */ - if (p_coaligned(mtmp)) u.ublessed = 0; + if (p_coaligned(mtmp)) + u.ublessed = 0; if (mdat->maligntyp == A_NONE) - adjalign((int)(ALIGNLIM / 4)); /* BIG bonus */ + adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */ } else if (mtmp->mtame) { - adjalign(-15); /* bad!! */ + adjalign(-15); /* bad!! */ /* your god is mighty displeased... */ - if (!Hallucination) You_hear("the rumble of distant thunder..."); - else You_hear("the studio audience applaud!"); + if (!Hallucination) + You_hear("the rumble of distant thunder..."); + else + You_hear("the studio audience applaud!"); } else if (mtmp->mpeaceful) adjalign(-5); @@ -2072,27 +2205,26 @@ cleanup: /* this should only be called when poly_when_stoned() is true */ void mon_to_stone(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - if(mtmp->data->mlet == S_GOLEM) { - /* it's a golem, and not a stone golem */ - if(canseemon(mtmp)) - pline("%s solidifies...", Monnam(mtmp)); - if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) { - if(canseemon(mtmp)) - pline("Now it's %s.", an(mtmp->data->mname)); - } else { - if(canseemon(mtmp)) - pline("... and returns to normal."); - } + if (mtmp->data->mlet == S_GOLEM) { + /* it's a golem, and not a stone golem */ + if (canseemon(mtmp)) + pline("%s solidifies...", Monnam(mtmp)); + if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) { + if (canseemon(mtmp)) + pline("Now it's %s.", an(mtmp->data->mname)); + } else { + if (canseemon(mtmp)) + pline("... and returns to normal."); + } } else - impossible("Can't polystone %s!", a_monnam(mtmp)); + impossible("Can't polystone %s!", a_monnam(mtmp)); } /* might place monst on far side of a wall or boulder */ -void -mnexto(mtmp) /* Make monster mtmp next to you (if possible) */ - struct monst *mtmp; +void mnexto(mtmp) /* Make monster mtmp next to you (if possible) */ +struct monst *mtmp; { coord mm; boolean couldspot = canspotmon(mtmp); @@ -2104,13 +2236,14 @@ mnexto(mtmp) /* Make monster mtmp next to you (if possible) */ return; } - if(!enexto(&mm, u.ux, u.uy, mtmp->data)) return; + if (!enexto(&mm, u.ux, u.uy, mtmp->data)) + return; rloc_to(mtmp, mm.x, mm.y); if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) { - mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */ + mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */ if (!couldspot && canspotmon(mtmp)) - pline("%s suddenly %s!", Amonnam(mtmp), - !Blind ? "appears" : "arrives"); + pline("%s suddenly %s!", Amonnam(mtmp), + !Blind ? "appears" : "arrives"); } return; } @@ -2126,12 +2259,13 @@ struct monst *mtmp; int tryct = 20; do { - if (!enexto(&mm, u.ux, u.uy, ptr)) return; + if (!enexto(&mm, u.ux, u.uy, ptr)) + return; if (couldsee(mm.x, mm.y) && /* don't move grid bugs diagonally */ (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) { - rloc_to(mtmp, mm.x, mm.y); - return; + rloc_to(mtmp, mm.x, mm.y); + return; } } while (--tryct > 0); } @@ -2143,16 +2277,17 @@ struct monst *mtmp; * 0 - in most cases. */ boolean -mnearto(mtmp,x,y,move_other) +mnearto(mtmp, x, y, move_other) register struct monst *mtmp; xchar x, y; -boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ +boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ { - struct monst *othermon = (struct monst *)0; + struct monst *othermon = (struct monst *) 0; xchar newx, newy; coord mm; - if ((mtmp->mx == x) && (mtmp->my == y)) return(FALSE); + if ((mtmp->mx == x) && (mtmp->my == y)) + return (FALSE); if (move_other && (othermon = m_at(x, y))) { if (othermon->wormno) @@ -2169,8 +2304,10 @@ boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ * migrating_mons that need to be placed will cause * no end of trouble. */ - if (!enexto(&mm, newx, newy, mtmp->data)) return(FALSE); - newx = mm.x; newy = mm.y; + if (!enexto(&mm, newx, newy, mtmp->data)) + return (FALSE); + newx = mm.x; + newy = mm.y; } rloc_to(mtmp, newx, newy); @@ -2179,10 +2316,10 @@ boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */ othermon->mx = othermon->my = 0; (void) mnearto(othermon, x, y, FALSE); if ((othermon->mx != x) || (othermon->my != y)) - return(TRUE); + return (TRUE); } - return(FALSE); + return (FALSE); } /* monster responds to player action; not the same as a passive attack */ @@ -2191,27 +2328,26 @@ void m_respond(mtmp) register struct monst *mtmp; { - if(mtmp->data->msound == MS_SHRIEK) { - if(!Deaf) { - pline("%s shrieks.", Monnam(mtmp)); - stop_occupation(); + if (mtmp->data->msound == MS_SHRIEK) { + if (!Deaf) { + pline("%s shrieks.", Monnam(mtmp)); + stop_occupation(); + } + if (!rn2(10)) { + if (!rn2(13)) + (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS); + else + (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS); + } + aggravate(); } - if (!rn2(10)) { - if (!rn2(13)) - (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS); - else - (void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS); - - } - aggravate(); - } - if(mtmp->data == &mons[PM_MEDUSA]) { - register int i; - for(i = 0; i < NATTK; i++) - if(mtmp->data->mattk[i].aatyp == AT_GAZE) { - (void) gazemu(mtmp, &mtmp->data->mattk[i]); - break; - } + if (mtmp->data == &mons[PM_MEDUSA]) { + register int i; + for (i = 0; i < NATTK; i++) + if (mtmp->data->mattk[i].aatyp == AT_GAZE) { + (void) gazemu(mtmp, &mtmp->data->mattk[i]); + break; + } } } @@ -2220,22 +2356,27 @@ setmangry(mtmp) register struct monst *mtmp; { mtmp->mstrategy &= ~STRAT_WAITMASK; - if(!mtmp->mpeaceful) return; - if(mtmp->mtame) return; + if (!mtmp->mpeaceful) + return; + if (mtmp->mtame) + return; mtmp->mpeaceful = 0; - if(mtmp->ispriest) { - if(p_coaligned(mtmp)) adjalign(-5); /* very bad */ - else adjalign(2); + if (mtmp->ispriest) { + if (p_coaligned(mtmp)) + adjalign(-5); /* very bad */ + else + adjalign(2); } else - adjalign(-1); /* attacking peaceful monsters is bad */ + adjalign(-1); /* attacking peaceful monsters is bad */ if (couldsee(mtmp->mx, mtmp->my)) { if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd) pline("%s gets angry!", Monnam(mtmp)); - else if (flags.verbose && !Deaf) growl(mtmp); + else if (flags.verbose && !Deaf) + growl(mtmp); } /* attacking your own quest leader will anger his or her guardians */ - if (!context.mon_moving && /* should always be the case here */ + if (!context.mon_moving && /* should always be the case here */ mtmp->data == &mons[quest_info(MS_LEADER)]) { struct monst *mon; struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)]; @@ -2243,17 +2384,19 @@ register struct monst *mtmp; /* guardians will sense this attack even if they can't see it */ for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon)) continue; - if (mon->data == q_guardian && mon->mpeaceful) { - mon->mpeaceful = 0; - if (canseemon(mon)) ++got_mad; - } + if (DEADMONSTER(mon)) + continue; + if (mon->data == q_guardian && mon->mpeaceful) { + mon->mpeaceful = 0; + if (canseemon(mon)) + ++got_mad; + } } if (got_mad && !Hallucination) - pline_The("%s appear%s to be angry too...", - got_mad == 1 ? q_guardian->mname : - makeplural(q_guardian->mname), - got_mad == 1 ? "s" : ""); + pline_The("%s appear%s to be angry too...", + got_mad == 1 ? q_guardian->mname + : makeplural(q_guardian->mname), + got_mad == 1 ? "s" : ""); } } @@ -2266,8 +2409,8 @@ register struct monst *mtmp; setmangry(mtmp); if (mtmp->m_ap_type) { seemimic(mtmp); - } else if (context.forcefight && !context.mon_moving && - mtmp->mundetected) { + } else if (context.forcefight && !context.mon_moving + && mtmp->mundetected) { mtmp->mundetected = 0; newsym(mtmp->mx, mtmp->my); } @@ -2280,12 +2423,13 @@ wake_nearby() register struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (distu(mtmp->mx,mtmp->my) < u.ulevel * 20) { - mtmp->msleeping = 0; - mtmp->mstrategy &= ~STRAT_WAITMASK; - if (mtmp->mtame && !mtmp->isminion) - EDOG(mtmp)->whistletime = moves; + if (DEADMONSTER(mtmp)) + continue; + if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) { + mtmp->msleeping = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; + if (mtmp->mtame && !mtmp->isminion) + EDOG(mtmp)->whistletime = moves; } } } @@ -2298,10 +2442,11 @@ register int x, y, distance; register struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) { - mtmp->msleeping = 0; - mtmp->mstrategy &= ~STRAT_WAITMASK; + mtmp->msleeping = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; } } } @@ -2314,7 +2459,8 @@ register struct monst *mtmp; unsigned old_app = mtmp->mappearance; uchar old_ap_type = mtmp->m_ap_type; - if (has_mcorpsenm(mtmp)) freemcorpsenm(mtmp); + if (has_mcorpsenm(mtmp)) + freemcorpsenm(mtmp); mtmp->m_ap_type = M_AP_NOTHING; mtmp->mappearance = 0; @@ -2322,13 +2468,13 @@ register struct monst *mtmp; /* * Discovered mimics don't block light. */ - if (((old_ap_type == M_AP_FURNITURE && - (old_app == S_hcdoor || old_app == S_vcdoor)) || - (old_ap_type == M_AP_OBJECT && old_app == BOULDER)) && - !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my])) + if (((old_ap_type == M_AP_FURNITURE + && (old_app == S_hcdoor || old_app == S_vcdoor)) + || (old_ap_type == M_AP_OBJECT && old_app == BOULDER)) + && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my])) unblock_point(mtmp->mx, mtmp->my); - newsym(mtmp->mx,mtmp->my); + newsym(mtmp->mx, mtmp->my); } /* force all chameleons to become normal */ @@ -2338,17 +2484,17 @@ rescham() register struct monst *mtmp; int mcham; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; mcham = (int) mtmp->cham; if (mcham >= LOW_PM) { - (void) newcham(mtmp, &mons[mcham], - FALSE, FALSE); + (void) newcham(mtmp, &mons[mcham], FALSE, FALSE); mtmp->cham = NON_PM; } - if(is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN) + if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN) new_were(mtmp); - if(mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) { + if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) { seemimic(mtmp); /* we pretend that the mimic doesn't */ /* know that it has been unmasked. */ @@ -2364,12 +2510,13 @@ restartcham() register struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; mtmp->cham = pm_to_cham(monsndx(mtmp->data)); - if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping && - cansee(mtmp->mx, mtmp->my)) { + if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping + && cansee(mtmp->mx, mtmp->my)) { set_mimic_sym(mtmp); - newsym(mtmp->mx,mtmp->my); + newsym(mtmp->mx, mtmp->my); } } } @@ -2386,10 +2533,10 @@ struct monst *mon; if (Protection_from_shape_changers) { mcham = (int) mon->cham; if (mcham >= LOW_PM) { - mon->cham = NON_PM; - (void) newcham(mon, &mons[mcham], FALSE, FALSE); + mon->cham = NON_PM; + (void) newcham(mon, &mons[mcham], FALSE, FALSE); } else if (is_were(mon->data) && !is_human(mon->data)) { - new_were(mon); + new_were(mon); } } else if (mon->cham == NON_PM) { mon->cham = pm_to_cham(monsndx(mon->data)); @@ -2403,24 +2550,23 @@ register struct monst *mtmp; { struct trap *t; - if (mtmp->mcan || mtmp->m_ap_type || - cansee(mtmp->mx, mtmp->my) || rn2(3) || (mtmp == u.ustuck) || - /* can't hide while trapped except in pits */ - (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0 && - !(t->ttyp == PIT || t->ttyp == SPIKED_PIT)) || - (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2)) - return(FALSE); + if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my) || rn2(3) + || (mtmp == u.ustuck) || + /* can't hide while trapped except in pits */ + (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0 + && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT)) + || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2)) + return (FALSE); - if(mtmp->data->mlet == S_MIMIC) { + if (mtmp->data->mlet == S_MIMIC) { set_mimic_sym(mtmp); - return(TRUE); - } else - if(levl[mtmp->mx][mtmp->my].typ == ROOM) { + return (TRUE); + } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) { mtmp->mundetected = 1; - return(TRUE); - } + return (TRUE); + } - return(FALSE); + return (FALSE); } /* monster/hero tries to hide under something at the current location */ @@ -2429,31 +2575,31 @@ hideunder(mtmp) struct monst *mtmp; { struct trap *t; - boolean undetected = FALSE, - is_u = (mtmp == &youmonst); - xchar x = is_u ? u.ux : mtmp->mx, - y = is_u ? u.uy : mtmp->my; + boolean undetected = FALSE, is_u = (mtmp == &youmonst); + xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my; if (mtmp == u.ustuck) { - ; /* can't hide if holding you or held by you */ - } else if (is_u ? (u.utrap && u.utraptype != TT_PIT) : - (mtmp->mtrapped && (t = t_at(x, y)) != 0 && - !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) { - ; /* can't hide while stuck in a non-pit trap */ + ; /* can't hide if holding you or held by you */ + } else if (is_u ? (u.utrap && u.utraptype != TT_PIT) + : (mtmp->mtrapped && (t = t_at(x, y)) != 0 + && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) { + ; /* can't hide while stuck in a non-pit trap */ } else if (mtmp->data->mlet == S_EEL) { undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz)); } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) { struct obj *otmp = level.objects[x][y]; /* most monsters won't hide under cockatrice corpse */ - if (otmp->nexthere || otmp->otyp != CORPSE || - (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp)) || - !touch_petrifies(&mons[otmp->corpsenm])) - undetected = TRUE; + if (otmp->nexthere || otmp->otyp != CORPSE + || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp)) + || !touch_petrifies(&mons[otmp->corpsenm])) + undetected = TRUE; } - if (is_u) u.uundetected = undetected; - else mtmp->mundetected = undetected; + if (is_u) + u.uundetected = undetected; + else + mtmp->mundetected = undetected; return undetected; } @@ -2464,22 +2610,25 @@ struct monst *mon; { boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL; - if ((is_hider(mon->data) || hider_under) && - !(mon->mundetected || mon->m_ap_type)) { - xchar x = mon->mx, y = mon->my; - char save_viz = viz_array[y][x]; + if ((is_hider(mon->data) || hider_under) + && !(mon->mundetected || mon->m_ap_type)) { + xchar x = mon->mx, y = mon->my; + char save_viz = viz_array[y][x]; - /* override vision, forcing hero to be unable to see monster's spot */ - viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE); - if (is_hider(mon->data)) (void)restrap(mon); - /* try again if mimic missed its 1/3 chance to hide */ - if (mon->data->mlet == S_MIMIC && !mon->m_ap_type) (void)restrap(mon); - if (hider_under) (void)hideunder(mon); - viz_array[y][x] = save_viz; + /* override vision, forcing hero to be unable to see monster's spot */ + viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE); + if (is_hider(mon->data)) + (void) restrap(mon); + /* try again if mimic missed its 1/3 chance to hide */ + if (mon->data->mlet == S_MIMIC && !mon->m_ap_type) + (void) restrap(mon); + if (hider_under) + (void) hideunder(mon); + viz_array[y][x] = save_viz; } } -short *animal_list = 0; /* list of PM values for animal monsters */ +short *animal_list = 0; /* list of PM values for animal monsters */ int animal_list_count; void @@ -2490,19 +2639,20 @@ boolean construct; short animal_temp[SPECIAL_PM]; int i, n; - /* if (animal_list) impossible("animal_list already exists"); */ + /* if (animal_list) impossible("animal_list already exists"); */ for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++) - if (is_animal(&mons[i])) animal_temp[n++] = i; - /* if (n == 0) animal_temp[n++] = NON_PM; */ + if (is_animal(&mons[i])) + animal_temp[n++] = i; + /* if (n == 0) animal_temp[n++] = NON_PM; */ - animal_list = (short *)alloc(n * sizeof *animal_list); - (void) memcpy((genericptr_t)animal_list, - (genericptr_t)animal_temp, - n * sizeof *animal_list); + animal_list = (short *) alloc(n * sizeof *animal_list); + (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp, + n * sizeof *animal_list); animal_list_count = n; - } else { /* release */ - if (animal_list) free((genericptr_t)animal_list), animal_list = 0; + } else { /* release */ + if (animal_list) + free((genericptr_t) animal_list), animal_list = 0; animal_list_count = 0; } } @@ -2510,7 +2660,8 @@ boolean construct; STATIC_OVL int pick_animal() { - if (!animal_list) mon_animal_list(TRUE); + if (!animal_list) + mon_animal_list(TRUE); return animal_list[rn2(animal_list_count)]; } @@ -2524,8 +2675,9 @@ int shiftflags; unsigned was_female = mon->female; boolean msg = FALSE; - if ((shiftflags & SHIFT_MSG) || - ((shiftflags & SHIFT_SEENMSG) && sensemon(mon))) msg = TRUE; + if ((shiftflags & SHIFT_MSG) + || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon))) + msg = TRUE; if (is_vampshifter(mon)) { /* The vampire has to be in good health (mhp) to maintain @@ -2534,12 +2686,11 @@ int shiftflags; * If we're shifted and getting low on hp, maybe shift back. * If we're not already shifted and in good health, maybe shift. */ - if ((mon->mhp <= mon->mhpmax / 6) && - rn2(4) && (mon->cham >= LOW_PM)) + if ((mon->mhp <= mon->mhpmax / 6) && rn2(4) && (mon->cham >= LOW_PM)) (void) newcham(mon, &mons[mon->cham], FALSE, msg); - } else if (mon->data->mlet == S_VAMPIRE && mon->cham == NON_PM && - !rn2(6) && (mon->mhp > mon->mhpmax - ((mon->mhpmax / 10) + 1))) { - (void) newcham(mon, (struct permonst *)0, FALSE, msg); + } else if (mon->data->mlet == S_VAMPIRE && mon->cham == NON_PM && !rn2(6) + && (mon->mhp > mon->mhpmax - ((mon->mhpmax / 10) + 1))) { + (void) newcham(mon, (struct permonst *) 0, FALSE, msg); } /* override the 10% chance for sex change */ ptr = mon->data; @@ -2556,15 +2707,16 @@ struct monst *mon; switch (mndx) { case PM_VLAD_THE_IMPALER: /* ensure Vlad can keep carrying the Candelabrum */ - if (mon_has_special(mon)) break; /* leave mndx as is */ - /*FALLTHRU*/ - case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */ + if (mon_has_special(mon)) + break; /* leave mndx as is */ + /*FALLTHRU*/ + case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */ if (!rn2(10)) { - mndx = PM_WOLF; - break; + mndx = PM_WOLF; + break; } - /*FALLTHRU*/ - case PM_VAMPIRE: /* any vampire can become fog or bat */ + /*FALLTHRU*/ + case PM_VAMPIRE: /* any vampire can become fog or bat */ mndx = !rn2(4) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT; break; } @@ -2576,8 +2728,8 @@ STATIC_OVL boolean isspecmon(mon) struct monst *mon; { - return (mon->isshk || mon->ispriest || mon->isgd || - mon->m_id == quest_status.leader_m_id); + return (mon->isshk || mon->ispriest || mon->isgd + || mon->m_id == quest_status.leader_m_id); } /* restrict certain special monsters (shopkeepers, aligned priests, @@ -2588,19 +2740,22 @@ validspecmon(mon, mndx) struct monst *mon; int mndx; { - if (mndx == NON_PM) return TRUE; /* caller wants random */ + if (mndx == NON_PM) + return TRUE; /* caller wants random */ - if (!accept_newcham_form(mndx)) return FALSE; /* geno'd or !polyok */ + if (!accept_newcham_form(mndx)) + return FALSE; /* geno'd or !polyok */ if (isspecmon(mon)) { struct permonst *ptr = &mons[mndx]; /* reject notake because object manipulation is expected and nohead because speech capability is expected */ - if (notake(ptr) || !has_head(ptr)) return FALSE; + if (notake(ptr) || !has_head(ptr)) + return FALSE; /* [should we check ptr->msound here too?] */ } - return TRUE; /* potential new form is ok */ + return TRUE; /* potential new form is ok */ } /* prevent wizard mode user from specifying invalid vampshifter shape */ @@ -2610,10 +2765,11 @@ struct monst *mon; int *mndx_p, monclass; { /* simplify caller's usage */ - if (!is_vampshifter(mon)) return validspecmon(mon, *mndx_p); + if (!is_vampshifter(mon)) + return validspecmon(mon, *mndx_p); - if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD || - *mndx_p == PM_VLAD_THE_IMPALER) { + if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD + || *mndx_p == PM_VLAD_THE_IMPALER) { /* player picked some type of vampire; use mon's self */ *mndx_p = mon->cham; return TRUE; @@ -2624,20 +2780,31 @@ int *mndx_p, monclass; return TRUE; } /* basic vampires can't become wolves; any can become fog or bat */ - if (*mndx_p == PM_WOLF) return (mon->cham != PM_VAMPIRE); - if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT) return TRUE; + if (*mndx_p == PM_WOLF) + return (mon->cham != PM_VAMPIRE); + if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT) + return TRUE; /* if we get here, specific type was no good; try by class */ switch (monclass) { - case S_VAMPIRE: *mndx_p = mon->cham; break; - case S_BAT: *mndx_p = PM_VAMPIRE_BAT; break; - case S_VORTEX: *mndx_p = PM_FOG_CLOUD; break; - case S_DOG: if (mon->cham != PM_VAMPIRE) { - *mndx_p = PM_WOLF; - break; - } - /*FALLTHRU*/ - default: *mndx_p = NON_PM; break; + case S_VAMPIRE: + *mndx_p = mon->cham; + break; + case S_BAT: + *mndx_p = PM_VAMPIRE_BAT; + break; + case S_VORTEX: + *mndx_p = PM_FOG_CLOUD; + break; + case S_DOG: + if (mon->cham != PM_VAMPIRE) { + *mndx_p = PM_WOLF; + break; + } + /*FALLTHRU*/ + default: + *mndx_p = NON_PM; + break; } return (*mndx_p != NON_PM); } @@ -2649,95 +2816,99 @@ struct monst *mon; int mndx = NON_PM, tryct; switch (mon->cham) { - case PM_SANDESTIN: - if (rn2(7)) mndx = pick_nasty(); + case PM_SANDESTIN: + if (rn2(7)) + mndx = pick_nasty(); break; - case PM_DOPPELGANGER: + case PM_DOPPELGANGER: if (!rn2(7)) { mndx = pick_nasty(); - } else if (rn2(3)) { /* role monsters */ - mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, - PM_ARCHEOLOGIST); - } else if (!rn2(3)) { /* quest guardians */ - mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, - PM_STUDENT); + } else if (rn2(3)) { /* role monsters */ + mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST); + } else if (!rn2(3)) { /* quest guardians */ + mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT); /* avoid own role's guardian */ - if (mndx == urole.guardnum) mndx = NON_PM; - } else { /* general humanoids */ + if (mndx == urole.guardnum) + mndx = NON_PM; + } else { /* general humanoids */ tryct = 5; do { - mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM); - if (humanoid(&mons[mndx]) && polyok(&mons[mndx])) break; + mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM); + if (humanoid(&mons[mndx]) && polyok(&mons[mndx])) + break; } while (--tryct > 0); - if (!tryct) mndx = NON_PM; + if (!tryct) + mndx = NON_PM; } break; - case PM_CHAMELEON: - if (!rn2(3)) mndx = pick_animal(); + case PM_CHAMELEON: + if (!rn2(3)) + mndx = pick_animal(); break; - case PM_VLAD_THE_IMPALER: - case PM_VAMPIRE_LORD: - case PM_VAMPIRE: + case PM_VLAD_THE_IMPALER: + case PM_VAMPIRE_LORD: + case PM_VAMPIRE: mndx = pickvampshape(mon); break; - case NON_PM: /* ordinary */ - { + case NON_PM: /* ordinary */ + { struct obj *m_armr = which_armor(mon, W_ARM); if (m_armr && Is_dragon_scales(m_armr)) - mndx = (int)(Dragon_scales_to_pm(m_armr) - mons); + mndx = (int) (Dragon_scales_to_pm(m_armr) - mons); else if (m_armr && Is_dragon_mail(m_armr)) - mndx = (int)(Dragon_mail_to_pm(m_armr) - mons); - } - break; + mndx = (int) (Dragon_mail_to_pm(m_armr) - mons); + } break; } /* for debugging: allow control of polymorphed monster */ if (wizard && iflags.mon_polycontrol) { char pprompt[BUFSZ], buf[BUFSZ]; int monclass; - Sprintf(pprompt, - "Change %s @ <%d,%d> into what kind of monster?", - noit_mon_nam(mon), (int)mon->mx, (int)mon->my); + Sprintf(pprompt, "Change %s @ <%d,%d> into what kind of monster?", + noit_mon_nam(mon), (int) mon->mx, (int) mon->my); tryct = 5; do { - monclass = 0; - getlin(pprompt, buf); - mungspaces(buf); - /* for ESC, take form selected above (might be NON_PM) */ - if (*buf == '\033') break; - /* for "*", use NON_PM to pick an arbitrary shape below */ - if (!strcmp(buf, "*") || !strcmp(buf, "random")) { - mndx = NON_PM; - break; - } - mndx = name_to_mon(buf); - if (mndx == NON_PM) { - /* didn't get a type, so check whether it's a class - (single letter or text match with def_monsyms[]) */ - monclass = name_to_monclass(buf, &mndx); - if (monclass && mndx == NON_PM) - mndx = mkclass_poly(monclass); - } - if (mndx >= LOW_PM) { - /* got a specific type of monster; use it if we can */ - if (validvamp(mon, &mndx, monclass)) break; - /* can't; revert to random in case we exhaust tryct */ - mndx = NON_PM; - } + monclass = 0; + getlin(pprompt, buf); + mungspaces(buf); + /* for ESC, take form selected above (might be NON_PM) */ + if (*buf == '\033') + break; + /* for "*", use NON_PM to pick an arbitrary shape below */ + if (!strcmp(buf, "*") || !strcmp(buf, "random")) { + mndx = NON_PM; + break; + } + mndx = name_to_mon(buf); + if (mndx == NON_PM) { + /* didn't get a type, so check whether it's a class + (single letter or text match with def_monsyms[]) */ + monclass = name_to_monclass(buf, &mndx); + if (monclass && mndx == NON_PM) + mndx = mkclass_poly(monclass); + } + if (mndx >= LOW_PM) { + /* got a specific type of monster; use it if we can */ + if (validvamp(mon, &mndx, monclass)) + break; + /* can't; revert to random in case we exhaust tryct */ + mndx = NON_PM; + } - pline("It can't become that."); + pline("It can't become that."); } while (--tryct > 0); - if (!tryct) pline1(thats_enough_tries); + if (!tryct) + pline1(thats_enough_tries); if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass)) - mndx = pickvampshape(mon); /* don't resort to arbitrary */ + mndx = pickvampshape(mon); /* don't resort to arbitrary */ } /* if no form was specified above, pick one at random now */ if (mndx == NON_PM) { tryct = 50; do { - mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM); + mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM); } while (--tryct > 0 && !validspecmon(mon, mndx)); } return mndx; @@ -2750,14 +2921,18 @@ int mndx; { struct permonst *mdat; - if (mndx == NON_PM) return 0; + if (mndx == NON_PM) + return 0; mdat = &mons[mndx]; - if ((mvitals[mndx].mvflags & G_GENOD) != 0) return 0; - if (is_placeholder(mdat)) return 0; + if ((mvitals[mndx].mvflags & G_GENOD) != 0) + return 0; + if (is_placeholder(mdat)) + return 0; /* select_newcham_form() might deliberately pick a player character type (random selection never does) which polyok() rejects, so we need a special case here */ - if (is_mplayer(mdat)) return mdat; + if (is_mplayer(mdat)) + return mdat; /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */ return polyok(mdat) ? mdat : 0; } @@ -2767,12 +2942,15 @@ mgender_from_permonst(mtmp, mdat) struct monst *mtmp; struct permonst *mdat; { - if(is_male(mdat)) { - if(mtmp->female) mtmp->female = FALSE; + if (is_male(mdat)) { + if (mtmp->female) + mtmp->female = FALSE; } else if (is_female(mdat)) { - if(!mtmp->female) mtmp->female = TRUE; + if (!mtmp->female) + mtmp->female = TRUE; } else if (!is_neuter(mdat)) { - if(!rn2(10)) mtmp->female = !mtmp->female; + if (!rn2(10)) + mtmp->female = !mtmp->female; } } @@ -2783,8 +2961,8 @@ int newcham(mtmp, mdat, polyspot, msg) struct monst *mtmp; struct permonst *mdat; -boolean polyspot; /* change is the result of wand or spell of polymorph */ -boolean msg; /* "The oldmon turns into a newmon!" */ +boolean polyspot; /* change is the result of wand or spell of polymorph */ +boolean msg; /* "The oldmon turns into a newmon!" */ { int hpn, hpd; int mndx, tryct; @@ -2792,12 +2970,13 @@ boolean msg; /* "The oldmon turns into a newmon!" */ char oldname[BUFSZ], newname[BUFSZ]; /* Riders are immune to polymorph and green slime */ - if (is_rider(mtmp->data)) return 0; + if (is_rider(mtmp->data)) + return 0; if (msg) { /* like Monnam() but never mention saddle */ - Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *)0, - SUPPRESS_SADDLE, FALSE)); + Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0, + SUPPRESS_SADDLE, FALSE)); oldname[0] = highc(oldname[0]); } @@ -2807,13 +2986,15 @@ boolean msg; /* "The oldmon turns into a newmon!" */ it doesn't always pick that so we still retry here too */ tryct = 20; do { - mndx = select_newcham_form(mtmp); - mdat = accept_newcham_form(mndx); - if (mdat) break; + mndx = select_newcham_form(mtmp); + mdat = accept_newcham_form(mndx); + if (mdat) + break; } while (--tryct > 0); - if (!tryct) return 0; + if (!tryct) + return 0; } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD) - return(0); /* passed in mdat is genocided */ + return (0); /* passed in mdat is genocided */ mgender_from_permonst(mtmp, mdat); @@ -2830,14 +3011,15 @@ boolean msg; /* "The oldmon turns into a newmon!" */ } } - if(mdat == mtmp->data) return(0); /* still the same monster */ + if (mdat == mtmp->data) + return (0); /* still the same monster */ - if(mtmp->wormno) { /* throw tail away */ + if (mtmp->wormno) { /* throw tail away */ wormgone(mtmp); place_monster(mtmp, mtmp->mx, mtmp->my); } if (mtmp->m_ap_type && mdat->mlet != S_MIMIC) - seemimic(mtmp); /* revert to normal monster */ + seemimic(mtmp); /* revert to normal monster */ /* (this code used to try to adjust the monster's health based on a normal one of its type but there are too many special cases @@ -2847,15 +3029,17 @@ boolean msg; /* "The oldmon turns into a newmon!" */ hpd = mtmp->mhpmax; /* set level and hit points */ newmonhp(mtmp, monsndx(mdat)); - /* new hp: same fraction of max as before */ +/* new hp: same fraction of max as before */ #ifndef LINT - mtmp->mhp = (int)(((long)hpn * (long)mtmp->mhp) / (long)hpd); + mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd); #endif /* sanity check (potentional overflow) */ - if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; + if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; /* unlikely but not impossible; a 1HD creature with 1HP that changes into a 0HD creature will require this statement */ - if (!mtmp->mhp) mtmp->mhp = 1; + if (!mtmp->mhp) + mtmp->mhp = 1; /* take on the new form... */ set_mon_data(mtmp, mdat, 0); @@ -2864,26 +3048,25 @@ boolean msg; /* "The oldmon turns into a newmon!" */ /* used to give light, now doesn't, or vice versa, or light's range has changed */ if (emits_light(olddata)) - del_light_source(LS_MONSTER, monst_to_any(mtmp)); + del_light_source(LS_MONSTER, monst_to_any(mtmp)); if (emits_light(mtmp->data)) - new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data), - LS_MONSTER, monst_to_any(mtmp)); + new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data), + LS_MONSTER, monst_to_any(mtmp)); } if (!mtmp->perminvis || pm_invisible(olddata)) mtmp->perminvis = pm_invisible(mdat); mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis; - if (mtmp->mundetected) (void) hideunder(mtmp); + if (mtmp->mundetected) + (void) hideunder(mtmp); if (u.ustuck == mtmp) { - if(u.uswallow) { - if(!attacktype(mdat,AT_ENGL)) { + if (u.uswallow) { + if (!attacktype(mdat, AT_ENGL)) { /* Does mdat care? */ - if (!noncorporeal(mdat) && !amorphous(mdat) && - !is_whirly(mdat) && - (mdat != &mons[PM_YELLOW_LIGHT])) { + if (!noncorporeal(mdat) && !amorphous(mdat) + && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) { You("break out of %s%s!", mon_nam(mtmp), - (is_animal(mdat)? - "'s stomach" : "")); - mtmp->mhp = 1; /* almost dead */ + (is_animal(mdat) ? "'s stomach" : "")); + mtmp->mhp = 1; /* almost dead */ } expels(mtmp, olddata, FALSE); } else { @@ -2900,39 +3083,41 @@ boolean msg; /* "The oldmon turns into a newmon!" */ /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the * same expression. */ - if (mdat == &mons[PM_LONG_WORM] && - (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) { + if (mdat == &mons[PM_LONG_WORM] + && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) { #endif /* we can now create worms with tails - 11/91 */ initworm(mtmp, rn2(5)); if (count_wsegs(mtmp)) - place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my); + place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my); } - newsym(mtmp->mx,mtmp->my); + newsym(mtmp->mx, mtmp->my); if (msg) { char *save_mname = 0; if (has_mname(mtmp)) { - save_mname = MNAME(mtmp); - MNAME(mtmp) = (char *)0; + save_mname = MNAME(mtmp); + MNAME(mtmp) = (char *) 0; } - Strcpy(newname, - (mdat == &mons[PM_GREEN_SLIME]) ? "slime" : - x_monnam(mtmp, ARTICLE_A, (char *)0,SUPPRESS_SADDLE, FALSE)); - if (!strcmpi(oldname,"it") && !strcmpi(newname,"it")) + Strcpy(newname, (mdat == &mons[PM_GREEN_SLIME]) + ? "slime" + : x_monnam(mtmp, ARTICLE_A, (char *) 0, + SUPPRESS_SADDLE, FALSE)); + if (!strcmpi(oldname, "it") && !strcmpi(newname, "it")) (void) usmellmon(mdat); else pline("%s turns into %s!", oldname, newname); - if (save_mname) MNAME(mtmp) = save_mname; + if (save_mname) + MNAME(mtmp) = save_mname; } - possibly_unwield(mtmp, polyspot); /* might lose use of weapon */ + possibly_unwield(mtmp, polyspot); /* might lose use of weapon */ mon_break_armor(mtmp, polyspot); if (!(mtmp->misc_worn_check & W_ARMG)) mselftouch(mtmp, "No longer petrify-resistant, ", - !context.mon_moving); + !context.mon_moving); m_dowear(mtmp, FALSE); /* This ought to re-test can_carry() on each item in the inventory @@ -2945,20 +3130,22 @@ boolean msg; /* "The oldmon turns into a newmon!" */ register struct obj *otmp, *otmp2; for (otmp = mtmp->minvent; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (otmp->otyp == BOULDER) { - /* this keeps otmp from being polymorphed in the - same zap that the monster that held it is polymorphed */ - if (polyspot) bypass_obj(otmp); - obj_extract_self(otmp); - /* probably ought to give some "drop" message here */ - if (flooreffects(otmp, mtmp->mx, mtmp->my, "")) continue; - place_object(otmp, mtmp->mx, mtmp->my); - } + otmp2 = otmp->nobj; + if (otmp->otyp == BOULDER) { + /* this keeps otmp from being polymorphed in the + same zap that the monster that held it is polymorphed */ + if (polyspot) + bypass_obj(otmp); + obj_extract_self(otmp); + /* probably ought to give some "drop" message here */ + if (flooreffects(otmp, mtmp->mx, mtmp->my, "")) + continue; + place_object(otmp, mtmp->mx, mtmp->my); + } } } - return(1); + return (1); } /* sometimes an egg will be special */ @@ -2976,29 +3163,33 @@ int mnum; /* ranger quest nemesis has the oviparous bit set, making it be possible to wish for eggs of that unique monster; turn such into ordinary eggs rather than forbidding them outright */ - if (mnum == PM_SCORPIUS) mnum = PM_SCORPION; + if (mnum == PM_SCORPIUS) + mnum = PM_SCORPION; mnum = little_to_big(mnum); /* * Queen bees lay killer bee eggs (usually), but killer bees don't * grow into queen bees. Ditto for [winged-]gargoyles. */ - if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE || - (lays_eggs(&mons[mnum]) && (BREEDER_EGG || - (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE)))) - return mnum; + if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE + || (lays_eggs(&mons[mnum]) + && (BREEDER_EGG + || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE)))) + return mnum; return NON_PM; } /* type of egg laid by #sit; usually matches parent */ int egg_type_from_parent(mnum, force_ordinary) -int mnum; /* parent monster; caller must handle lays_eggs() check */ +int mnum; /* parent monster; caller must handle lays_eggs() check */ boolean force_ordinary; { if (force_ordinary || !BREEDER_EGG) { - if (mnum == PM_QUEEN_BEE) mnum = PM_KILLER_BEE; - else if (mnum == PM_WINGED_GARGOYLE) mnum = PM_GARGOYLE; + if (mnum == PM_QUEEN_BEE) + mnum = PM_KILLER_BEE; + else if (mnum == PM_WINGED_GARGOYLE) + mnum = PM_GARGOYLE; } return mnum; } @@ -3017,11 +3208,11 @@ boolean egg; * fortunately, none of them have eggs. Species extinction due to * overpopulation does not kill eggs. */ - return (boolean) - (m_idx >= LOW_PM && - ((mvitals[m_idx].mvflags & G_GENOD) != 0 || - (egg && - (mvitals[big_to_little(m_idx)].mvflags & G_GENOD) != 0))); + return (boolean)( + m_idx >= LOW_PM + && ((mvitals[m_idx].mvflags & G_GENOD) != 0 + || (egg + && (mvitals[big_to_little(m_idx)].mvflags & G_GENOD) != 0))); } /* kill off any eggs of genocided monsters */ @@ -3033,16 +3224,16 @@ struct obj *obj_list; for (otmp = obj_list; otmp; otmp = otmp->nobj) if (otmp->otyp == EGG) { - if (dead_species(otmp->corpsenm, TRUE)) { - /* - * It seems we could also just catch this when - * it attempted to hatch, so we wouldn't have to - * search all of the objlists.. or stop all - * hatch timers based on a corpsenm. - */ - kill_egg(otmp); - } -#if 0 /* not used */ + if (dead_species(otmp->corpsenm, TRUE)) { + /* + * It seems we could also just catch this when + * it attempted to hatch, so we wouldn't have to + * search all of the objlists.. or stop all + * hatch timers based on a corpsenm. + */ + kill_egg(otmp); + } +#if 0 /* not used */ } else if (otmp->otyp == TIN) { if (dead_species(otmp->corpsenm, FALSE)) otmp->corpsenm = NON_PM; /* empty tin */ @@ -3051,7 +3242,7 @@ struct obj *obj_list; ; /* not yet implemented... */ #endif } else if (Has_contents(otmp)) { - kill_eggs(otmp->cobj); + kill_eggs(otmp->cobj); } } @@ -3076,17 +3267,19 @@ kill_genocided_monsters() */ for (mtmp = fmon; mtmp; mtmp = mtmp2) { mtmp2 = mtmp->nmon; - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; mndx = monsndx(mtmp->data); - kill_cham = (mtmp->cham >= LOW_PM && - (mvitals[mtmp->cham].mvflags & G_GENOD)); + kill_cham = + (mtmp->cham >= LOW_PM && (mvitals[mtmp->cham].mvflags & G_GENOD)); if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) { - if (mtmp->cham >= LOW_PM && !kill_cham) - (void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE); - else - mondead(mtmp); + if (mtmp->cham >= LOW_PM && !kill_cham) + (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); + else + mondead(mtmp); } - if (mtmp->minvent) kill_eggs(mtmp->minvent); + if (mtmp->minvent) + kill_eggs(mtmp->minvent); } kill_eggs(invent); @@ -3103,25 +3296,30 @@ int damtype, dam; int heal = 0, slow = 0; if (mon->data == &mons[PM_FLESH_GOLEM]) { - if (damtype == AD_ELEC) heal = dam / 6; - else if (damtype == AD_FIRE || damtype == AD_COLD) slow = 1; + if (damtype == AD_ELEC) + heal = dam / 6; + else if (damtype == AD_FIRE || damtype == AD_COLD) + slow = 1; } else if (mon->data == &mons[PM_IRON_GOLEM]) { - if (damtype == AD_ELEC) slow = 1; - else if (damtype == AD_FIRE) heal = dam; + if (damtype == AD_ELEC) + slow = 1; + else if (damtype == AD_FIRE) + heal = dam; } else { - return; + return; } if (slow) { - if (mon->mspeed != MSLOW) - mon_adjust_speed(mon, -1, (struct obj *)0); + if (mon->mspeed != MSLOW) + mon_adjust_speed(mon, -1, (struct obj *) 0); } if (heal) { - if (mon->mhp < mon->mhpmax) { - mon->mhp += dam; - if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax; - if (cansee(mon->mx, mon->my)) - pline("%s seems healthier.", Monnam(mon)); - } + if (mon->mhp < mon->mhpmax) { + mon->mhp += dam; + if (mon->mhp > mon->mhpmax) + mon->mhp = mon->mhpmax; + if (cansee(mon->mx, mon->my)) + pline("%s seems healthier.", Monnam(mon)); + } } } @@ -3132,13 +3330,16 @@ register boolean silent; register struct monst *mtmp; register int ct = 0, nct = 0, sct = 0, slct = 0; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; if (is_watch(mtmp->data) && mtmp->mpeaceful) { ct++; - if(cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) { - if (distu(mtmp->mx, mtmp->my) == 2) nct++; - else sct++; + if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) { + if (distu(mtmp->mx, mtmp->my) == 2) + nct++; + else + sct++; } if (mtmp->msleeping || mtmp->mfrozen) { slct++; @@ -3147,22 +3348,24 @@ register boolean silent; mtmp->mpeaceful = 0; } } - if(ct) { - if(!silent) { /* do we want pline msgs? */ - if(slct) pline_The("guard%s wake%s up!", - slct > 1 ? "s" : "", slct == 1 ? "s" : ""); - if(nct || sct) { - if(nct) pline_The("guard%s get%s angry!", - nct == 1 ? "" : "s", nct == 1 ? "s" : ""); - else if(!Blind) - You_see("%sangry guard%s approaching!", - sct == 1 ? "an " : "", sct > 1 ? "s" : ""); - } else - You_hear("the shrill sound of a guard's whistle."); + if (ct) { + if (!silent) { /* do we want pline msgs? */ + if (slct) + pline_The("guard%s wake%s up!", slct > 1 ? "s" : "", + slct == 1 ? "s" : ""); + if (nct || sct) { + if (nct) + pline_The("guard%s get%s angry!", nct == 1 ? "" : "s", + nct == 1 ? "s" : ""); + else if (!Blind) + You_see("%sangry guard%s approaching!", + sct == 1 ? "an " : "", sct > 1 ? "s" : ""); + } else + You_hear("the shrill sound of a guard's whistle."); } - return(TRUE); + return (TRUE); } - return(FALSE); + return (FALSE); } void @@ -3171,9 +3374,10 @@ pacify_guards() register struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; + if (DEADMONSTER(mtmp)) + continue; if (is_watch(mtmp->data)) - mtmp->mpeaceful = 1; + mtmp->mpeaceful = 1; } } @@ -3184,16 +3388,16 @@ short otyp; { short ap = mtmp->mappearance; - switch(mtmp->m_ap_type) { - case M_AP_NOTHING: - case M_AP_FURNITURE: - case M_AP_MONSTER: + switch (mtmp->m_ap_type) { + case M_AP_NOTHING: + case M_AP_FURNITURE: + case M_AP_MONSTER: break; - case M_AP_OBJECT: + case M_AP_OBJECT: if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) { pline("%s seems a more vivid %s than before.", - The(simple_typename(ap)), - c_obj_colors[objects[ap].oc_color]); + The(simple_typename(ap)), + c_obj_colors[objects[ap].oc_color]); } break; } @@ -3208,7 +3412,8 @@ struct permonst *mdat; boolean msg_given = FALSE; if (mdat) { - if (!olfaction(youmonst.data)) return FALSE; + if (!olfaction(youmonst.data)) + return FALSE; mndx = monsndx(mdat); switch (mndx) { case PM_ROTHE: @@ -3223,12 +3428,12 @@ struct permonst *mdat; You("smell body odor."); msg_given = TRUE; break; -/* - case PM_PESTILENCE: - case PM_FAMINE: - case PM_DEATH: - break; -*/ + /* + case PM_PESTILENCE: + case PM_FAMINE: + case PM_DEATH: + break; + */ case PM_HORNED_DEVIL: case PM_BALROG: case PM_ASMODEUS: @@ -3246,10 +3451,10 @@ struct permonst *mdat; You("detect an odor reminiscent of an animal's den."); msg_given = TRUE; break; -/* - case PM_PURPLE_WORM: - break; -*/ + /* + case PM_PURPLE_WORM: + break; + */ case PM_STEAM_VORTEX: You("smell steam."); msg_given = TRUE; @@ -3275,43 +3480,43 @@ struct permonst *mdat; break; } - if (nonspecific) switch(mdat->mlet) { + if (nonspecific) + switch (mdat->mlet) { case S_DOG: - You("notice a dog smell."); - msg_given = TRUE; - break; - case S_DRAGON: - You("smell a dragon!"); - msg_given = TRUE; - break; + You("notice a dog smell."); + msg_given = TRUE; + break; + case S_DRAGON: + You("smell a dragon!"); + msg_given = TRUE; + break; case S_FUNGUS: - pline("%s smells moldy.", Something); - msg_given = TRUE; - break; - case S_UNICORN: - You("detect a%s odor reminiscent of a stable.", - (mndx == PM_PONY) ? "n" : " strong"); - msg_given = TRUE; - break; - case S_ZOMBIE: - You("smell rotting flesh."); - msg_given = TRUE; - break; - case S_EEL: - You("smell fish."); - msg_given = TRUE; - break; - case S_ORC: - if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) - You("notice an attractive smell."); - else - pline( - "A foul stench makes you feel a little nauseated."); - msg_given = TRUE; - break; - default: - break; - } + pline("%s smells moldy.", Something); + msg_given = TRUE; + break; + case S_UNICORN: + You("detect a%s odor reminiscent of a stable.", + (mndx == PM_PONY) ? "n" : " strong"); + msg_given = TRUE; + break; + case S_ZOMBIE: + You("smell rotting flesh."); + msg_given = TRUE; + break; + case S_EEL: + You("smell fish."); + msg_given = TRUE; + break; + case S_ORC: + if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) + You("notice an attractive smell."); + else + pline("A foul stench makes you feel a little nauseated."); + msg_given = TRUE; + break; + default: + break; + } } return (msg_given) ? TRUE : FALSE; } diff --git a/src/mondata.c b/src/mondata.c index 5298d23fd..cdefe7379 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mondata.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mondata.c $NHDT-Date: 1431192756 2015/05/09 17:32:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ /* NetHack 3.6 mondata.c $Date: 2011/10/02 02:18:54 $ $Revision: 1.44 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,12 +14,13 @@ struct permonst *ptr; int flag; { mon->data = ptr; - if (flag == -1) return; /* "don't care" */ + if (flag == -1) + return; /* "don't care" */ if (flag == 1) - mon->mintrinsics |= (ptr->mresists & 0x00FF); + mon->mintrinsics |= (ptr->mresists & 0x00FF); else - mon->mintrinsics = (ptr->mresists & 0x00FF); + mon->mintrinsics = (ptr->mresists & 0x00FF); return; } @@ -31,10 +32,10 @@ int atyp, dtyp; struct attack *a; for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++) - if (a->aatyp == atyp && (dtyp == AD_ANY || a->adtyp == dtyp)) - return a; + if (a->aatyp == atyp && (dtyp == AD_ANY || a->adtyp == dtyp)) + return a; - return (struct attack *)0; + return (struct attack *) 0; } boolean @@ -54,11 +55,13 @@ struct permonst *ptr; struct attack *mattk = ptr->mattk; for (i = 0; i < NATTK; i++) { - /* AT_BOOM "passive attack" (gas spore's explosion upon death) - isn't an attack as far as our callers are concerned */ - if (mattk[i].aatyp == AT_BOOM) continue; + /* AT_BOOM "passive attack" (gas spore's explosion upon death) + isn't an attack as far as our callers are concerned */ + if (mattk[i].aatyp == AT_BOOM) + continue; - if (mattk[i].aatyp) return FALSE; + if (mattk[i].aatyp) + return FALSE; } return TRUE; @@ -66,57 +69,57 @@ struct permonst *ptr; boolean poly_when_stoned(ptr) - struct permonst *ptr; +struct permonst *ptr; { - return((boolean)(is_golem(ptr) && ptr != &mons[PM_STONE_GOLEM] && - !(mvitals[PM_STONE_GOLEM].mvflags & G_GENOD))); - /* allow G_EXTINCT */ + return ((boolean)(is_golem(ptr) && ptr != &mons[PM_STONE_GOLEM] + && !(mvitals[PM_STONE_GOLEM].mvflags & G_GENOD))); + /* allow G_EXTINCT */ } boolean -resists_drli(mon) /* returns TRUE if monster is drain-life resistant */ +resists_drli(mon) /* returns TRUE if monster is drain-life resistant */ struct monst *mon; { - struct permonst *ptr = mon->data; - struct obj *wep = ((mon == &youmonst) ? uwep : MON_WEP(mon)); + struct permonst *ptr = mon->data; + struct obj *wep = ((mon == &youmonst) ? uwep : MON_WEP(mon)); - return (boolean)(is_undead(ptr) || is_demon(ptr) || is_were(ptr) || - /* is_were() doesn't handle hero in human form */ - (mon == &youmonst && u.ulycn >= LOW_PM) || - ptr == &mons[PM_DEATH] || is_vampshifter(mon) || - (wep && wep->oartifact && defends(AD_DRLI, wep))); + return (boolean)(is_undead(ptr) || is_demon(ptr) || is_were(ptr) || + /* is_were() doesn't handle hero in human form */ + (mon == &youmonst && u.ulycn >= LOW_PM) + || ptr == &mons[PM_DEATH] || is_vampshifter(mon) + || (wep && wep->oartifact && defends(AD_DRLI, wep))); } -boolean -resists_magm(mon) /* TRUE if monster is magic-missile resistant */ +boolean resists_magm(mon) /* TRUE if monster is magic-missile resistant */ struct monst *mon; { - struct permonst *ptr = mon->data; - boolean is_you = (mon == &youmonst); - long slotmask; - struct obj *o; + struct permonst *ptr = mon->data; + boolean is_you = (mon == &youmonst); + long slotmask; + struct obj *o; - /* as of 3.2.0: gray dragons, Angels, Oracle, Yeenoghu */ - if (dmgtype(ptr, AD_MAGM) || ptr == &mons[PM_BABY_GRAY_DRAGON] || - dmgtype(ptr, AD_RBRE)) /* Chromatic Dragon */ - return TRUE; - /* check for magic resistance granted by wielded weapon */ - o = is_you ? uwep : MON_WEP(mon); - if (o && o->oartifact && defends(AD_MAGM, o)) - return TRUE; - /* check for magic resistance granted by worn or carried items */ - o = is_you ? invent : mon->minvent; - slotmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; - if (!is_you || /* assumes monsters don't wield non-weapons */ - (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))) - slotmask |= W_WEP; - if (is_you && u.twoweap) slotmask |= W_SWAPWEP; - for ( ; o; o = o->nobj) - if (((o->owornmask & slotmask) != 0L && - objects[o->otyp].oc_oprop == ANTIMAGIC) || - (o->oartifact && defends_when_carried(AD_MAGM, o))) - return TRUE; - return FALSE; + /* as of 3.2.0: gray dragons, Angels, Oracle, Yeenoghu */ + if (dmgtype(ptr, AD_MAGM) || ptr == &mons[PM_BABY_GRAY_DRAGON] + || dmgtype(ptr, AD_RBRE)) /* Chromatic Dragon */ + return TRUE; + /* check for magic resistance granted by wielded weapon */ + o = is_you ? uwep : MON_WEP(mon); + if (o && o->oartifact && defends(AD_MAGM, o)) + return TRUE; + /* check for magic resistance granted by worn or carried items */ + o = is_you ? invent : mon->minvent; + slotmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; + if (!is_you || /* assumes monsters don't wield non-weapons */ + (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))) + slotmask |= W_WEP; + if (is_you && u.twoweap) + slotmask |= W_SWAPWEP; + for (; o; o = o->nobj) + if (((o->owornmask & slotmask) != 0L + && objects[o->otyp].oc_oprop == ANTIMAGIC) + || (o->oartifact && defends_when_carried(AD_MAGM, o))) + return TRUE; + return FALSE; } /* TRUE iff monster is resistant to light-induced blindness */ @@ -124,148 +127,156 @@ boolean resists_blnd(mon) struct monst *mon; { - struct permonst *ptr = mon->data; - boolean is_you = (mon == &youmonst); - long slotmask; - struct obj *o; + struct permonst *ptr = mon->data; + boolean is_you = (mon == &youmonst); + long slotmask; + struct obj *o; - if (is_you ? (Blind || Unaware) : - (mon->mblinded || !mon->mcansee || !haseyes(ptr) || - /* BUG: temporary sleep sets mfrozen, but since - paralysis does too, we can't check it */ - mon->msleeping)) - return TRUE; - /* yellow light, Archon; !dust vortex, !cobra, !raven */ - if (dmgtype_fromattack(ptr, AD_BLND, AT_EXPL) || - dmgtype_fromattack(ptr, AD_BLND, AT_GAZE)) - return TRUE; - o = is_you ? uwep : MON_WEP(mon); - if (o && o->oartifact && defends(AD_BLND, o)) - return TRUE; - o = is_you ? invent : mon->minvent; - slotmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; - if (!is_you || /* assumes monsters don't wield non-weapons */ - (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))) - slotmask |= W_WEP; - if (is_you && u.twoweap) slotmask |= W_SWAPWEP; - for ( ; o; o = o->nobj) - if (((o->owornmask & slotmask) != 0L && - objects[o->otyp].oc_oprop == BLINDED) || - (o->oartifact && defends_when_carried(AD_BLND, o))) - return TRUE; - return FALSE; + if (is_you ? (Blind || Unaware) + : (mon->mblinded || !mon->mcansee || !haseyes(ptr) || + /* BUG: temporary sleep sets mfrozen, but since + paralysis does too, we can't check it */ + mon->msleeping)) + return TRUE; + /* yellow light, Archon; !dust vortex, !cobra, !raven */ + if (dmgtype_fromattack(ptr, AD_BLND, AT_EXPL) + || dmgtype_fromattack(ptr, AD_BLND, AT_GAZE)) + return TRUE; + o = is_you ? uwep : MON_WEP(mon); + if (o && o->oartifact && defends(AD_BLND, o)) + return TRUE; + o = is_you ? invent : mon->minvent; + slotmask = W_ARMOR | W_RING | W_AMUL | W_TOOL; + if (!is_you || /* assumes monsters don't wield non-weapons */ + (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))) + slotmask |= W_WEP; + if (is_you && u.twoweap) + slotmask |= W_SWAPWEP; + for (; o; o = o->nobj) + if (((o->owornmask & slotmask) != 0L + && objects[o->otyp].oc_oprop == BLINDED) + || (o->oartifact && defends_when_carried(AD_BLND, o))) + return TRUE; + return FALSE; } /* TRUE iff monster can be blinded by the given attack */ /* Note: may return TRUE when mdef is blind (e.g. new cream-pie attack) */ boolean can_blnd(magr, mdef, aatyp, obj) -struct monst *magr; /* NULL == no specific aggressor */ +struct monst *magr; /* NULL == no specific aggressor */ struct monst *mdef; uchar aatyp; -struct obj *obj; /* aatyp == AT_WEAP, AT_SPIT */ +struct obj *obj; /* aatyp == AT_WEAP, AT_SPIT */ { - boolean is_you = (mdef == &youmonst); - boolean check_visor = FALSE; - struct obj *o; - const char *s; + boolean is_you = (mdef == &youmonst); + boolean check_visor = FALSE; + struct obj *o; + const char *s; - /* no eyes protect against all attacks for now */ - if (!haseyes(mdef->data)) - return FALSE; + /* no eyes protect against all attacks for now */ + if (!haseyes(mdef->data)) + return FALSE; - switch(aatyp) { - case AT_EXPL: case AT_BOOM: case AT_GAZE: case AT_MAGC: - case AT_BREA: /* assumed to be lightning */ - /* light-based attacks may be cancelled or resisted */ - if (magr && magr->mcan) - return FALSE; - return !resists_blnd(mdef); + switch (aatyp) { + case AT_EXPL: + case AT_BOOM: + case AT_GAZE: + case AT_MAGC: + case AT_BREA: /* assumed to be lightning */ + /* light-based attacks may be cancelled or resisted */ + if (magr && magr->mcan) + return FALSE; + return !resists_blnd(mdef); - case AT_WEAP: case AT_SPIT: case AT_NONE: - /* an object is used (thrown/spit/other) */ - if (obj && (obj->otyp == CREAM_PIE)) { - if (is_you && Blindfolded) - return FALSE; - } else if (obj && (obj->otyp == BLINDING_VENOM)) { - /* all ublindf, including LENSES, protect, cream-pies too */ - if (is_you && (ublindf || u.ucreamed)) - return FALSE; - check_visor = TRUE; - } else if (obj && (obj->otyp == POT_BLINDNESS)) { - return TRUE; /* no defense */ - } else - return FALSE; /* other objects cannot cause blindness yet */ - if ((magr == &youmonst) && u.uswallow) - return FALSE; /* can't affect eyes while inside monster */ - break; + case AT_WEAP: + case AT_SPIT: + case AT_NONE: + /* an object is used (thrown/spit/other) */ + if (obj && (obj->otyp == CREAM_PIE)) { + if (is_you && Blindfolded) + return FALSE; + } else if (obj && (obj->otyp == BLINDING_VENOM)) { + /* all ublindf, including LENSES, protect, cream-pies too */ + if (is_you && (ublindf || u.ucreamed)) + return FALSE; + check_visor = TRUE; + } else if (obj && (obj->otyp == POT_BLINDNESS)) { + return TRUE; /* no defense */ + } else + return FALSE; /* other objects cannot cause blindness yet */ + if ((magr == &youmonst) && u.uswallow) + return FALSE; /* can't affect eyes while inside monster */ + break; - case AT_ENGL: - if (is_you && (Blindfolded || Unaware || u.ucreamed)) - return FALSE; - if (!is_you && mdef->msleeping) - return FALSE; - break; + case AT_ENGL: + if (is_you && (Blindfolded || Unaware || u.ucreamed)) + return FALSE; + if (!is_you && mdef->msleeping) + return FALSE; + break; - case AT_CLAW: - /* e.g. raven: all ublindf, including LENSES, protect */ - if (is_you && ublindf) - return FALSE; - if ((magr == &youmonst) && u.uswallow) - return FALSE; /* can't affect eyes while inside monster */ - check_visor = TRUE; - break; + case AT_CLAW: + /* e.g. raven: all ublindf, including LENSES, protect */ + if (is_you && ublindf) + return FALSE; + if ((magr == &youmonst) && u.uswallow) + return FALSE; /* can't affect eyes while inside monster */ + check_visor = TRUE; + break; - case AT_TUCH: case AT_STNG: - /* some physical, blind-inducing attacks can be cancelled */ - if (magr && magr->mcan) - return FALSE; - break; + case AT_TUCH: + case AT_STNG: + /* some physical, blind-inducing attacks can be cancelled */ + if (magr && magr->mcan) + return FALSE; + break; - default: - break; - } + default: + break; + } - /* check if wearing a visor (only checked if visor might help) */ - if (check_visor) { - o = (mdef == &youmonst) ? invent : mdef->minvent; - for ( ; o; o = o->nobj) - if ((o->owornmask & W_ARMH) && - (s = OBJ_DESCR(objects[o->otyp])) != (char *)0 && - !strcmp(s, "visored helmet")) - return FALSE; - } + /* check if wearing a visor (only checked if visor might help) */ + if (check_visor) { + o = (mdef == &youmonst) ? invent : mdef->minvent; + for (; o; o = o->nobj) + if ((o->owornmask & W_ARMH) + && (s = OBJ_DESCR(objects[o->otyp])) != (char *) 0 + && !strcmp(s, "visored helmet")) + return FALSE; + } - return TRUE; + return TRUE; } -boolean -ranged_attk(ptr) /* returns TRUE if monster can attack at range */ +boolean ranged_attk(ptr) /* returns TRUE if monster can attack at range */ struct permonst *ptr; { - register int i, atyp; - long atk_mask = (1L << AT_BREA) | (1L << AT_SPIT) | (1L << AT_GAZE); + register int i, atyp; + long atk_mask = (1L << AT_BREA) | (1L << AT_SPIT) | (1L << AT_GAZE); - /* was: (attacktype(ptr, AT_BREA) || attacktype(ptr, AT_WEAP) || - attacktype(ptr, AT_SPIT) || attacktype(ptr, AT_GAZE) || - attacktype(ptr, AT_MAGC)); - but that's too slow -dlc - */ - for (i = 0; i < NATTK; i++) { - atyp = ptr->mattk[i].aatyp; - if (atyp >= AT_WEAP) return TRUE; - /* assert(atyp < 32); */ - if ((atk_mask & (1L << atyp)) != 0L) return TRUE; - } + /* was: (attacktype(ptr, AT_BREA) || attacktype(ptr, AT_WEAP) || + attacktype(ptr, AT_SPIT) || attacktype(ptr, AT_GAZE) || + attacktype(ptr, AT_MAGC)); + but that's too slow -dlc + */ + for (i = 0; i < NATTK; i++) { + atyp = ptr->mattk[i].aatyp; + if (atyp >= AT_WEAP) + return TRUE; + /* assert(atyp < 32); */ + if ((atk_mask & (1L << atyp)) != 0L) + return TRUE; + } - return FALSE; + return FALSE; } boolean mon_hates_silver(mon) struct monst *mon; { - return (is_vampshifter(mon) || hates_silver(mon->data)); + return (is_vampshifter(mon) || hates_silver(mon->data)); } /* TRUE if monster is especially affected by silver weapons */ @@ -273,9 +284,9 @@ boolean hates_silver(ptr) register struct permonst *ptr; { - return (boolean)(is_were(ptr) || ptr->mlet == S_VAMPIRE || - is_demon(ptr) || ptr == &mons[PM_SHADE] || - (ptr->mlet == S_IMP && ptr != &mons[PM_TENGU])); + return (boolean)(is_were(ptr) || ptr->mlet == S_VAMPIRE || is_demon(ptr) + || ptr == &mons[PM_SHADE] + || (ptr->mlet == S_IMP && ptr != &mons[PM_TENGU])); } /* true iff the type of monster pass through iron bars */ @@ -283,26 +294,25 @@ boolean passes_bars(mptr) struct permonst *mptr; { - return (boolean) (passes_walls(mptr) || amorphous(mptr) || - unsolid(mptr) || is_whirly(mptr) || verysmall(mptr) || - dmgtype(mptr, AD_CORR) || dmgtype(mptr, AD_RUST) || - (slithy(mptr) && !bigmonst(mptr))); + return (boolean)(passes_walls(mptr) || amorphous(mptr) || unsolid(mptr) + || is_whirly(mptr) || verysmall(mptr) + || dmgtype(mptr, AD_CORR) || dmgtype(mptr, AD_RUST) + || (slithy(mptr) && !bigmonst(mptr))); } -boolean -can_blow(mtmp) /* returns TRUE if monster can blow (whistle, etc) */ +boolean can_blow(mtmp) /* returns TRUE if monster can blow (whistle, etc) */ register struct monst *mtmp; { - if ((is_silent(mtmp->data) || mtmp->data->msound == MS_BUZZ) && - (breathless(mtmp->data) || verysmall(mtmp->data) || - !has_head(mtmp->data) || mtmp->data->mlet == S_EEL)) - return FALSE; - if ((mtmp == &youmonst) && Strangled) return FALSE; - return TRUE; + if ((is_silent(mtmp->data) || mtmp->data->msound == MS_BUZZ) + && (breathless(mtmp->data) || verysmall(mtmp->data) + || !has_head(mtmp->data) || mtmp->data->mlet == S_EEL)) + return FALSE; + if ((mtmp == &youmonst) && Strangled) + return FALSE; + return TRUE; } -boolean -can_be_strangled(mon) /* TRUE if mon is vulnerable to strangulation */ +boolean can_be_strangled(mon) /* TRUE if mon is vulnerable to strangulation */ struct monst *mon; { struct obj *mamul; @@ -315,57 +325,54 @@ struct monst *mon; who don't need to breathe (brain, if any, doesn't care). Mindless creatures who do need to breath are vulnerable, as are non-breathing creatures which have higher brain function. */ - if (!has_head(mon->data)) return FALSE; + if (!has_head(mon->data)) + return FALSE; if (mon == &youmonst) { - /* hero can't be mindless but poly'ing into mindless form can - confer strangulation protection */ - nobrainer = mindless(youmonst.data); - nonbreathing = Breathless; + /* hero can't be mindless but poly'ing into mindless form can + confer strangulation protection */ + nobrainer = mindless(youmonst.data); + nonbreathing = Breathless; } else { - nobrainer = mindless(mon->data); - /* monsters don't wear amulets of magical breathing, - so second part doesn't achieve anything useful... */ - nonbreathing = (breathless(mon->data) || - ((mamul = which_armor(mon, W_AMUL)) != 0 && - (mamul->otyp == AMULET_OF_MAGICAL_BREATHING))); + nobrainer = mindless(mon->data); + /* monsters don't wear amulets of magical breathing, + so second part doesn't achieve anything useful... */ + nonbreathing = (breathless(mon->data) + || ((mamul = which_armor(mon, W_AMUL)) != 0 + && (mamul->otyp == AMULET_OF_MAGICAL_BREATHING))); } return (boolean)(!nobrainer || !nonbreathing); } -boolean -can_track(ptr) /* returns TRUE if monster can track well */ - register struct permonst *ptr; +boolean can_track(ptr) /* returns TRUE if monster can track well */ +register struct permonst *ptr; { - if (uwep && uwep->oartifact == ART_EXCALIBUR) - return TRUE; - else - return((boolean)haseyes(ptr)); + if (uwep && uwep->oartifact == ART_EXCALIBUR) + return TRUE; + else + return ((boolean) haseyes(ptr)); } -boolean -sliparm(ptr) /* creature will slide out of armor */ - register struct permonst *ptr; +boolean sliparm(ptr) /* creature will slide out of armor */ +register struct permonst *ptr; { - return((boolean)(is_whirly(ptr) || ptr->msize <= MZ_SMALL || - noncorporeal(ptr))); + return ((boolean)(is_whirly(ptr) || ptr->msize <= MZ_SMALL + || noncorporeal(ptr))); } -boolean -breakarm(ptr) /* creature will break out of armor */ - register struct permonst *ptr; +boolean breakarm(ptr) /* creature will break out of armor */ +register struct permonst *ptr; { - return ((bigmonst(ptr) || (ptr->msize > MZ_SMALL && !humanoid(ptr)) || - /* special cases of humanoids that cannot wear body armor */ - ptr == &mons[PM_MARILITH] || ptr == &mons[PM_WINGED_GARGOYLE]) - && !sliparm(ptr)); + return ((bigmonst(ptr) || (ptr->msize > MZ_SMALL && !humanoid(ptr)) || + /* special cases of humanoids that cannot wear body armor */ + ptr == &mons[PM_MARILITH] || ptr == &mons[PM_WINGED_GARGOYLE]) + && !sliparm(ptr)); } -boolean -sticks(ptr) /* creature sticks other creatures it hits */ - register struct permonst *ptr; +boolean sticks(ptr) /* creature sticks other creatures it hits */ +register struct permonst *ptr; { - return((boolean)(dmgtype(ptr,AD_STCK) || dmgtype(ptr,AD_WRAP) || - attacktype(ptr,AT_HUGS))); + return ((boolean)(dmgtype(ptr, AD_STCK) || dmgtype(ptr, AD_WRAP) + || attacktype(ptr, AT_HUGS))); } boolean @@ -374,10 +381,9 @@ struct permonst *ptr; { /* rats and mice are incapable of vomitting; which other creatures have the same limitation? */ - if (ptr->mlet == S_RODENT && - ptr != &mons[PM_ROCK_MOLE] && - ptr != &mons[PM_WOODCHUCK]) - return TRUE; + if (ptr->mlet == S_RODENT && ptr != &mons[PM_ROCK_MOLE] + && ptr != &mons[PM_WOODCHUCK]) + return TRUE; return FALSE; } @@ -387,18 +393,18 @@ num_horns(ptr) struct permonst *ptr; { switch (monsndx(ptr)) { - case PM_HORNED_DEVIL: /* ? "more than one" */ + case PM_HORNED_DEVIL: /* ? "more than one" */ case PM_MINOTAUR: case PM_ASMODEUS: case PM_BALROG: - return 2; + return 2; case PM_WHITE_UNICORN: case PM_GRAY_UNICORN: case PM_BLACK_UNICORN: case PM_KI_RIN: - return 1; + return 1; default: - break; + break; } return 0; } @@ -411,10 +417,10 @@ int dtyp, atyp; struct attack *a; for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++) - if (a->adtyp == dtyp && (atyp == AT_ANY || a->aatyp == atyp)) - return a; + if (a->adtyp == dtyp && (atyp == AT_ANY || a->aatyp == atyp)) + return a; - return (struct attack *)0; + return (struct attack *) 0; } boolean @@ -429,38 +435,48 @@ int dtyp; * a passive defense */ int max_passive_dmg(mdef, magr) - register struct monst *mdef, *magr; +register struct monst *mdef, *magr; { - int i, dmg = 0, multi2 = 0; + int i, dmg = 0, multi2 = 0; uchar adtyp; /* each attack by magr can result in passive damage */ - for(i = 0; i < NATTK; i++) - switch (magr->data->mattk[i].aatyp) { - case AT_CLAW: case AT_BITE: case AT_KICK: case AT_BUTT: case AT_TUCH: - case AT_STNG: case AT_HUGS: case AT_ENGL: case AT_TENT: case AT_WEAP: - multi2++; - break; - default: - break; - } + for (i = 0; i < NATTK; i++) + switch (magr->data->mattk[i].aatyp) { + case AT_CLAW: + case AT_BITE: + case AT_KICK: + case AT_BUTT: + case AT_TUCH: + case AT_STNG: + case AT_HUGS: + case AT_ENGL: + case AT_TENT: + case AT_WEAP: + multi2++; + break; + default: + break; + } - for(i = 0; i < NATTK; i++) - if(mdef->data->mattk[i].aatyp == AT_NONE || - mdef->data->mattk[i].aatyp == AT_BOOM) { - adtyp = mdef->data->mattk[i].adtyp; - if ((adtyp == AD_ACID && !resists_acid(magr)) || - (adtyp == AD_COLD && !resists_cold(magr)) || - (adtyp == AD_FIRE && !resists_fire(magr)) || - (adtyp == AD_ELEC && !resists_elec(magr)) || - adtyp == AD_PHYS) { - dmg = mdef->data->mattk[i].damn; - if(!dmg) dmg = mdef->data->mlevel+1; - dmg *= mdef->data->mattk[i].damd; - } else dmg = 0; + for (i = 0; i < NATTK; i++) + if (mdef->data->mattk[i].aatyp == AT_NONE + || mdef->data->mattk[i].aatyp == AT_BOOM) { + adtyp = mdef->data->mattk[i].adtyp; + if ((adtyp == AD_ACID && !resists_acid(magr)) + || (adtyp == AD_COLD && !resists_cold(magr)) + || (adtyp == AD_FIRE && !resists_fire(magr)) + || (adtyp == AD_ELEC && !resists_elec(magr)) + || adtyp == AD_PHYS) { + dmg = mdef->data->mattk[i].damn; + if (!dmg) + dmg = mdef->data->mlevel + 1; + dmg *= mdef->data->mattk[i].damd; + } else + dmg = 0; - return dmg * multi2; - } + return dmg * multi2; + } return 0; } @@ -471,84 +487,116 @@ struct permonst *pm1, *pm2; { char let1 = pm1->mlet, let2 = pm2->mlet; - if (pm1 == pm2) return TRUE; /* exact match */ + if (pm1 == pm2) + return TRUE; /* exact match */ /* player races have their own predicates */ - if (is_human(pm1)) return is_human(pm2); - if (is_elf(pm1)) return is_elf(pm2); - if (is_dwarf(pm1)) return is_dwarf(pm2); - if (is_gnome(pm1)) return is_gnome(pm2); - if (is_orc(pm1)) return is_orc(pm2); + if (is_human(pm1)) + return is_human(pm2); + if (is_elf(pm1)) + return is_elf(pm2); + if (is_dwarf(pm1)) + return is_dwarf(pm2); + if (is_gnome(pm1)) + return is_gnome(pm2); + if (is_orc(pm1)) + return is_orc(pm2); /* other creatures are less precise */ - if (is_giant(pm1)) return is_giant(pm2); /* open to quibbling here */ - if (is_golem(pm1)) return is_golem(pm2); /* even moreso... */ - if (is_mind_flayer(pm1)) return is_mind_flayer(pm2); - if (let1 == S_KOBOLD || - pm1 == &mons[PM_KOBOLD_ZOMBIE] || - pm1 == &mons[PM_KOBOLD_MUMMY]) - return (let2 == S_KOBOLD || - pm2 == &mons[PM_KOBOLD_ZOMBIE] || - pm2 == &mons[PM_KOBOLD_MUMMY]); - if (let1 == S_OGRE) return (let2 == S_OGRE); - if (let1 == S_NYMPH) return (let2 == S_NYMPH); - if (let1 == S_CENTAUR) return (let2 == S_CENTAUR); - if (is_unicorn(pm1)) return is_unicorn(pm2); - if (let1 == S_DRAGON) return (let2 == S_DRAGON); - if (let1 == S_NAGA) return (let2 == S_NAGA); + if (is_giant(pm1)) + return is_giant(pm2); /* open to quibbling here */ + if (is_golem(pm1)) + return is_golem(pm2); /* even moreso... */ + if (is_mind_flayer(pm1)) + return is_mind_flayer(pm2); + if (let1 == S_KOBOLD || pm1 == &mons[PM_KOBOLD_ZOMBIE] + || pm1 == &mons[PM_KOBOLD_MUMMY]) + return (let2 == S_KOBOLD || pm2 == &mons[PM_KOBOLD_ZOMBIE] + || pm2 == &mons[PM_KOBOLD_MUMMY]); + if (let1 == S_OGRE) + return (let2 == S_OGRE); + if (let1 == S_NYMPH) + return (let2 == S_NYMPH); + if (let1 == S_CENTAUR) + return (let2 == S_CENTAUR); + if (is_unicorn(pm1)) + return is_unicorn(pm2); + if (let1 == S_DRAGON) + return (let2 == S_DRAGON); + if (let1 == S_NAGA) + return (let2 == S_NAGA); /* other critters get steadily messier */ - if (is_rider(pm1)) return is_rider(pm2); /* debatable */ - if (is_minion(pm1)) return is_minion(pm2); /* [needs work?] */ + if (is_rider(pm1)) + return is_rider(pm2); /* debatable */ + if (is_minion(pm1)) + return is_minion(pm2); /* [needs work?] */ /* tengu don't match imps (first test handled case of both being tengu) */ - if (pm1 == &mons[PM_TENGU] || pm2 == &mons[PM_TENGU]) return FALSE; - if (let1 == S_IMP) return (let2 == S_IMP); + if (pm1 == &mons[PM_TENGU] || pm2 == &mons[PM_TENGU]) + return FALSE; + if (let1 == S_IMP) + return (let2 == S_IMP); /* and minor demons (imps) don't match major demons */ - else if (let2 == S_IMP) return FALSE; - if (is_demon(pm1)) return is_demon(pm2); + else if (let2 == S_IMP) + return FALSE; + if (is_demon(pm1)) + return is_demon(pm2); if (is_undead(pm1)) { - if (let1 == S_ZOMBIE) return (let2 == S_ZOMBIE); - if (let1 == S_MUMMY) return (let2 == S_MUMMY); - if (let1 == S_VAMPIRE) return (let2 == S_VAMPIRE); - if (let1 == S_LICH) return (let2 == S_LICH); - if (let1 == S_WRAITH) return (let2 == S_WRAITH); - if (let1 == S_GHOST) return (let2 == S_GHOST); - } else if (is_undead(pm2)) return FALSE; - /* check for monsters--mainly animals--which grow into more mature forms */ + if (let1 == S_ZOMBIE) + return (let2 == S_ZOMBIE); + if (let1 == S_MUMMY) + return (let2 == S_MUMMY); + if (let1 == S_VAMPIRE) + return (let2 == S_VAMPIRE); + if (let1 == S_LICH) + return (let2 == S_LICH); + if (let1 == S_WRAITH) + return (let2 == S_WRAITH); + if (let1 == S_GHOST) + return (let2 == S_GHOST); + } else if (is_undead(pm2)) + return FALSE; + /* check for monsters--mainly animals--which grow into more mature forms + */ if (let1 == let2) { - int m1 = monsndx(pm1), m2 = monsndx(pm2), prv, nxt; + int m1 = monsndx(pm1), m2 = monsndx(pm2), prv, nxt; - /* we know m1 != m2 (very first check above); test all smaller - forms of m1 against m2, then all larger ones; don't need to - make the corresponding tests for variants of m2 against m1 */ - for (prv = m1, nxt = big_to_little(m1); nxt != prv; - prv = nxt, nxt = big_to_little(nxt)) if (nxt == m2) return TRUE; - for (prv = m1, nxt = little_to_big(m1); nxt != prv; - prv = nxt, nxt = little_to_big(nxt)) if (nxt == m2) return TRUE; + /* we know m1 != m2 (very first check above); test all smaller + forms of m1 against m2, then all larger ones; don't need to + make the corresponding tests for variants of m2 against m1 */ + for (prv = m1, nxt = big_to_little(m1); nxt != prv; + prv = nxt, nxt = big_to_little(nxt)) + if (nxt == m2) + return TRUE; + for (prv = m1, nxt = little_to_big(m1); nxt != prv; + prv = nxt, nxt = little_to_big(nxt)) + if (nxt == m2) + return TRUE; } /* not caught by little/big handling */ if (pm1 == &mons[PM_GARGOYLE] || pm1 == &mons[PM_WINGED_GARGOYLE]) - return (pm2 == &mons[PM_GARGOYLE] || pm2 == &mons[PM_WINGED_GARGOYLE]); + return (pm2 == &mons[PM_GARGOYLE] + || pm2 == &mons[PM_WINGED_GARGOYLE]); if (pm1 == &mons[PM_KILLER_BEE] || pm1 == &mons[PM_QUEEN_BEE]) - return (pm2 == &mons[PM_KILLER_BEE] || pm2 == &mons[PM_QUEEN_BEE]); - if (is_longworm(pm1)) return is_longworm(pm2); /* handles tail */ + return (pm2 == &mons[PM_KILLER_BEE] || pm2 == &mons[PM_QUEEN_BEE]); + if (is_longworm(pm1)) + return is_longworm(pm2); /* handles tail */ /* [currently there's no reason to bother matching up - assorted bugs and blobs with their closest variants] */ + assorted bugs and blobs with their closest variants] */ /* didn't match */ return FALSE; } -int -monsndx(ptr) /* return an index into the mons array */ - struct permonst *ptr; +int monsndx(ptr) /* return an index into the mons array */ +struct permonst *ptr; { - register int i; + register int i; - i = (int)(ptr - &mons[0]); - if (i < LOW_PM || i >= NUMMONS) { - panic("monsndx - could not index monster (%s)", - fmt_ptr((genericptr_t)ptr)); - return NON_PM; /* will not get here */ - } + i = (int) (ptr - &mons[0]); + if (i < LOW_PM || i >= NUMMONS) { + panic("monsndx - could not index monster (%s)", + fmt_ptr((genericptr_t) ptr)); + return NON_PM; /* will not get here */ + } - return(i); + return (i); } /* for handling alternate spellings */ @@ -562,124 +610,127 @@ int name_to_mon(in_str) const char *in_str; { - /* Be careful. We must check the entire string in case it was - * something such as "ettin zombie corpse". The calling routine - * doesn't know about the "corpse" until the monster name has - * already been taken off the front, so we have to be able to - * read the name with extraneous stuff such as "corpse" stuck on - * the end. - * This causes a problem for names which prefix other names such - * as "ettin" on "ettin zombie". In this case we want the _longest_ - * name which exists. - * This also permits plurals created by adding suffixes such as 's' - * or 'es'. Other plurals must still be handled explicitly. - */ - register int i; - register int mntmp = NON_PM; - register char *s, *str, *term; - char buf[BUFSZ]; - int len, slen; + /* Be careful. We must check the entire string in case it was + * something such as "ettin zombie corpse". The calling routine + * doesn't know about the "corpse" until the monster name has + * already been taken off the front, so we have to be able to + * read the name with extraneous stuff such as "corpse" stuck on + * the end. + * This causes a problem for names which prefix other names such + * as "ettin" on "ettin zombie". In this case we want the _longest_ + * name which exists. + * This also permits plurals created by adding suffixes such as 's' + * or 'es'. Other plurals must still be handled explicitly. + */ + register int i; + register int mntmp = NON_PM; + register char *s, *str, *term; + char buf[BUFSZ]; + int len, slen; - str = strcpy(buf, in_str); + str = strcpy(buf, in_str); - if (!strncmp(str, "a ", 2)) str += 2; - else if (!strncmp(str, "an ", 3)) str += 3; - else if (!strncmp(str, "the ", 4)) str += 4; + if (!strncmp(str, "a ", 2)) + str += 2; + else if (!strncmp(str, "an ", 3)) + str += 3; + else if (!strncmp(str, "the ", 4)) + str += 4; - slen = strlen(str); - term = str + slen; + slen = strlen(str); + term = str + slen; - if ((s = strstri(str, "vortices")) != 0) - Strcpy(s+4, "ex"); - /* be careful with "ies"; "priest", "zombies" */ - else if (slen > 3 && !strcmpi(term-3, "ies") && - (slen < 7 || strcmpi(term-7, "zombies"))) - Strcpy(term-3, "y"); - /* luckily no monster names end in fe or ve with ves plurals */ - else if (slen > 3 && !strcmpi(term-3, "ves")) - Strcpy(term-3, "f"); + if ((s = strstri(str, "vortices")) != 0) + Strcpy(s + 4, "ex"); + /* be careful with "ies"; "priest", "zombies" */ + else if (slen > 3 && !strcmpi(term - 3, "ies") + && (slen < 7 || strcmpi(term - 7, "zombies"))) + Strcpy(term - 3, "y"); + /* luckily no monster names end in fe or ve with ves plurals */ + else if (slen > 3 && !strcmpi(term - 3, "ves")) + Strcpy(term - 3, "f"); - slen = strlen(str); /* length possibly needs recomputing */ + slen = strlen(str); /* length possibly needs recomputing */ { - static const struct alt_spl names[] = { - /* Alternate spellings */ - { "grey dragon", PM_GRAY_DRAGON }, - { "baby grey dragon", PM_BABY_GRAY_DRAGON }, - { "grey unicorn", PM_GRAY_UNICORN }, - { "grey ooze", PM_GRAY_OOZE }, - { "gray-elf", PM_GREY_ELF }, - { "mindflayer", PM_MIND_FLAYER }, - { "master mindflayer", PM_MASTER_MIND_FLAYER }, - /* More alternates; priest and priestess are separate monster - types but that isn't the case for {aligned,high} priests */ - { "aligned priestess", PM_ALIGNED_PRIEST }, - { "high priestess", PM_HIGH_PRIEST }, - /* Inappropriate singularization by -ves check above */ - { "master of thief", PM_MASTER_OF_THIEVES }, - /* Potential misspellings where we want to avoid falling back - to the rank title prefix (input has been singularized) */ - { "master thief", PM_MASTER_OF_THIEVES }, - { "master of assassin", PM_MASTER_ASSASSIN }, - /* Outdated names */ - { "invisible stalker", PM_STALKER }, - { "high-elf", PM_ELVENKING }, /* PM_HIGH_ELF is obsolete */ - { "halfling", PM_HOBBIT }, /* potential guess for polyself */ - /* Hyphenated names */ - { "ki rin", PM_KI_RIN }, - { "uruk hai", PM_URUK_HAI }, - { "orc captain", PM_ORC_CAPTAIN }, - { "woodland elf", PM_WOODLAND_ELF }, - { "green elf", PM_GREEN_ELF }, - { "grey elf", PM_GREY_ELF }, - { "gray elf", PM_GREY_ELF }, - { "elf lord", PM_ELF_LORD }, - { "olog hai", PM_OLOG_HAI }, - { "arch lich", PM_ARCH_LICH }, - /* Some irregular plurals */ - { "incubi", PM_INCUBUS }, - { "succubi", PM_SUCCUBUS }, - { "violet fungi", PM_VIOLET_FUNGUS }, - { "homunculi", PM_HOMUNCULUS }, - { "baluchitheria", PM_BALUCHITHERIUM }, - { "lurkers above", PM_LURKER_ABOVE }, - { "cavemen", PM_CAVEMAN }, - { "cavewomen", PM_CAVEWOMAN }, - { "djinn", PM_DJINNI }, - { "mumakil", PM_MUMAK }, - { "erinyes", PM_ERINYS }, - /* end of list */ - { 0, NON_PM } - }; - register const struct alt_spl *namep; + static const struct alt_spl names[] = { + /* Alternate spellings */ + { "grey dragon", PM_GRAY_DRAGON }, + { "baby grey dragon", PM_BABY_GRAY_DRAGON }, + { "grey unicorn", PM_GRAY_UNICORN }, + { "grey ooze", PM_GRAY_OOZE }, + { "gray-elf", PM_GREY_ELF }, + { "mindflayer", PM_MIND_FLAYER }, + { "master mindflayer", PM_MASTER_MIND_FLAYER }, + /* More alternates; priest and priestess are separate monster + types but that isn't the case for {aligned,high} priests */ + { "aligned priestess", PM_ALIGNED_PRIEST }, + { "high priestess", PM_HIGH_PRIEST }, + /* Inappropriate singularization by -ves check above */ + { "master of thief", PM_MASTER_OF_THIEVES }, + /* Potential misspellings where we want to avoid falling back + to the rank title prefix (input has been singularized) */ + { "master thief", PM_MASTER_OF_THIEVES }, + { "master of assassin", PM_MASTER_ASSASSIN }, + /* Outdated names */ + { "invisible stalker", PM_STALKER }, + { "high-elf", PM_ELVENKING }, /* PM_HIGH_ELF is obsolete */ + { "halfling", PM_HOBBIT }, /* potential guess for polyself */ + /* Hyphenated names */ + { "ki rin", PM_KI_RIN }, + { "uruk hai", PM_URUK_HAI }, + { "orc captain", PM_ORC_CAPTAIN }, + { "woodland elf", PM_WOODLAND_ELF }, + { "green elf", PM_GREEN_ELF }, + { "grey elf", PM_GREY_ELF }, + { "gray elf", PM_GREY_ELF }, + { "elf lord", PM_ELF_LORD }, + { "olog hai", PM_OLOG_HAI }, + { "arch lich", PM_ARCH_LICH }, + /* Some irregular plurals */ + { "incubi", PM_INCUBUS }, + { "succubi", PM_SUCCUBUS }, + { "violet fungi", PM_VIOLET_FUNGUS }, + { "homunculi", PM_HOMUNCULUS }, + { "baluchitheria", PM_BALUCHITHERIUM }, + { "lurkers above", PM_LURKER_ABOVE }, + { "cavemen", PM_CAVEMAN }, + { "cavewomen", PM_CAVEWOMAN }, + { "djinn", PM_DJINNI }, + { "mumakil", PM_MUMAK }, + { "erinyes", PM_ERINYS }, + /* end of list */ + { 0, NON_PM } + }; + register const struct alt_spl *namep; - for (namep = names; namep->name; namep++) - if (!strncmpi(str, namep->name, (int)strlen(namep->name))) - return namep->pm_val; + for (namep = names; namep->name; namep++) + if (!strncmpi(str, namep->name, (int) strlen(namep->name))) + return namep->pm_val; } - for (len = 0, i = LOW_PM; i < NUMMONS; i++) { - register int m_i_len = strlen(mons[i].mname); - if (m_i_len > len && !strncmpi(mons[i].mname, str, m_i_len)) { - if (m_i_len == slen) { - return i; /* exact match */ - } else if (slen > m_i_len && - (str[m_i_len] == ' ' || - !strcmpi(&str[m_i_len], "s") || - !strncmpi(&str[m_i_len], "s ", 2) || - !strcmpi(&str[m_i_len], "'") || - !strncmpi(&str[m_i_len], "' ", 2) || - !strcmpi(&str[m_i_len], "'s") || - !strncmpi(&str[m_i_len], "'s ", 3) || - !strcmpi(&str[m_i_len], "es") || - !strncmpi(&str[m_i_len], "es ", 3))) { - mntmp = i; - len = m_i_len; - } - } - } - if (mntmp == NON_PM) mntmp = title_to_mon(str, (int *)0, (int *)0); - return mntmp; + for (len = 0, i = LOW_PM; i < NUMMONS; i++) { + register int m_i_len = strlen(mons[i].mname); + if (m_i_len > len && !strncmpi(mons[i].mname, str, m_i_len)) { + if (m_i_len == slen) { + return i; /* exact match */ + } else if (slen > m_i_len + && (str[m_i_len] == ' ' || !strcmpi(&str[m_i_len], "s") + || !strncmpi(&str[m_i_len], "s ", 2) + || !strcmpi(&str[m_i_len], "'") + || !strncmpi(&str[m_i_len], "' ", 2) + || !strcmpi(&str[m_i_len], "'s") + || !strncmpi(&str[m_i_len], "'s ", 3) + || !strcmpi(&str[m_i_len], "es") + || !strncmpi(&str[m_i_len], "es ", 3))) { + mntmp = i; + len = m_i_len; + } + } + } + if (mntmp == NON_PM) + mntmp = title_to_mon(str, (int *) 0, (int *) 0); + return mntmp; } /* monster class from user input; used for genocide and controlled polymorph; @@ -697,72 +748,79 @@ int *mndx_p; such partial matches must start at beginning of a word. Some class descriptions include "foo or bar" and "foo or other foo" so we don't want to accept "or", "other", "or other" there. */ - static NEARDATA const char * const falsematch[] = { - /* multiple-letter input which matches any of these gets rejected */ - "an", "the", "or", "other", "or other", 0 + static NEARDATA const char *const falsematch[] = { + /* multiple-letter input which matches any of these gets rejected */ + "an", "the", "or", "other", "or other", 0 }; /* positive pm_val => specific monster; negative => class */ static NEARDATA const struct alt_spl truematch[] = { - /* "long worm" won't match "worm" class but would accidentally match - "long worm tail" class before the comparison with monster types */ - { "long worm", PM_LONG_WORM }, - /* matches wrong--or at least suboptimal--class */ - { "demon", -S_DEMON }, /* hits "imp or minor demon" */ - /* matches specific monster (overly restrictive) */ - { "devil", -S_DEMON }, /* always "horned devil" */ - /* some plausible guesses which need help */ - { "bug", -S_XAN }, /* would match bugbear... */ - { "fish", -S_EEL }, /* wouldn't match anything */ - /* end of list */ - { 0, NON_PM } + /* "long worm" won't match "worm" class but would accidentally match + "long worm tail" class before the comparison with monster types */ + { "long worm", PM_LONG_WORM }, + /* matches wrong--or at least suboptimal--class */ + { "demon", -S_DEMON }, /* hits "imp or minor demon" */ + /* matches specific monster (overly restrictive) */ + { "devil", -S_DEMON }, /* always "horned devil" */ + /* some plausible guesses which need help */ + { "bug", -S_XAN }, /* would match bugbear... */ + { "fish", -S_EEL }, /* wouldn't match anything */ + /* end of list */ + { 0, NON_PM } }; const char *p, *x; int i; - if (mndx_p) *mndx_p = NON_PM; /* haven't [yet] matched a specific type */ + if (mndx_p) + *mndx_p = NON_PM; /* haven't [yet] matched a specific type */ if (!in_str || !in_str[0]) { - /* empty input */ - return 0; + /* empty input */ + return 0; } else if (!in_str[1]) { - /* single character */ - i = def_char_to_monclass(*in_str); - if (i == S_MIMIC_DEF) { /* ']' -> 'm' */ - i = S_MIMIC; - } else if (i == S_WORM_TAIL) { /* '~' -> 'w' */ - i = S_WORM; - if (mndx_p) *mndx_p = PM_LONG_WORM; - } else if (i == MAXMCLASSES) /* maybe 'I' */ - i = (*in_str == DEF_INVISIBLE) ? S_invisible : 0; - return i; + /* single character */ + i = def_char_to_monclass(*in_str); + if (i == S_MIMIC_DEF) { /* ']' -> 'm' */ + i = S_MIMIC; + } else if (i == S_WORM_TAIL) { /* '~' -> 'w' */ + i = S_WORM; + if (mndx_p) + *mndx_p = PM_LONG_WORM; + } else if (i == MAXMCLASSES) /* maybe 'I' */ + i = (*in_str == DEF_INVISIBLE) ? S_invisible : 0; + return i; } else { - /* multiple characters */ - in_str = makesingular(in_str); - /* check for special cases */ - for (i = 0; falsematch[i]; i++) - if (!strcmpi(in_str, falsematch[i])) return 0; - for (i = 0; truematch[i].name; i++) - if (!strcmpi(in_str, truematch[i].name)) { - i = truematch[i].pm_val; - if (i < 0) return -i; /* class */ - if (mndx_p) *mndx_p = i; /* monster */ - return mons[i].mlet; - } - /* check monster class descriptions */ - for (i = 1; i < MAXMCLASSES; i++) { - x = def_monsyms[i].explain; - if ((p = strstri(x, in_str)) != 0 && (p == x || *(p - 1) == ' ')) - return i; - } - /* check individual species names; not as thorough as mon_to_name() - but our caller can call that directly if desired */ - for (i = LOW_PM; i < NUMMONS; i++) { - x = mons[i].mname; - if ((p = strstri(x, in_str)) != 0 && (p == x || *(p - 1) == ' ')) { - if (mndx_p) *mndx_p = i; - return mons[i].mlet; - } - } + /* multiple characters */ + in_str = makesingular(in_str); + /* check for special cases */ + for (i = 0; falsematch[i]; i++) + if (!strcmpi(in_str, falsematch[i])) + return 0; + for (i = 0; truematch[i].name; i++) + if (!strcmpi(in_str, truematch[i].name)) { + i = truematch[i].pm_val; + if (i < 0) + return -i; /* class */ + if (mndx_p) + *mndx_p = i; /* monster */ + return mons[i].mlet; + } + /* check monster class descriptions */ + for (i = 1; i < MAXMCLASSES; i++) { + x = def_monsyms[i].explain; + if ((p = strstri(x, in_str)) != 0 && (p == x || *(p - 1) == ' ')) + return i; + } + /* check individual species names; not as thorough as mon_to_name() + but our caller can call that directly if desired */ + for (i = LOW_PM; i < NUMMONS; i++) { + x = mons[i].mname; + if ((p = strstri(x, in_str)) != 0 + && (p == x || *(p - 1) == ' ')) { + if (mndx_p) + *mndx_p = i; + return mons[i].mlet; + } + } } return 0; } @@ -772,8 +830,9 @@ int gender(mtmp) register struct monst *mtmp; { - if (is_neuter(mtmp->data)) return 2; - return mtmp->female; + if (is_neuter(mtmp->data)) + return 2; + return mtmp->female; } /* Like gender(), but lower animals and such are still "it". */ @@ -782,9 +841,12 @@ int pronoun_gender(mtmp) register struct monst *mtmp; { - if (is_neuter(mtmp->data) || !canspotmon(mtmp)) return 2; - return (humanoid(mtmp->data) || (mtmp->data->geno & G_UNIQ) || - type_is_pname(mtmp->data)) ? (int)mtmp->female : 2; + if (is_neuter(mtmp->data) || !canspotmon(mtmp)) + return 2; + return (humanoid(mtmp->data) || (mtmp->data->geno & G_UNIQ) + || type_is_pname(mtmp->data)) + ? (int) mtmp->female + : 2; } /* used for nearby monsters when you go to another level */ @@ -792,77 +854,94 @@ boolean levl_follower(mtmp) struct monst *mtmp; { - if (mtmp == u.usteed) return TRUE; + if (mtmp == u.usteed) + return TRUE; - /* Wizard with Amulet won't bother trying to follow across levels */ - if (mtmp->iswiz && mon_has_amulet(mtmp)) return FALSE; + /* Wizard with Amulet won't bother trying to follow across levels */ + if (mtmp->iswiz && mon_has_amulet(mtmp)) + return FALSE; - /* some monsters will follow even while intending to flee from you */ - if (mtmp->mtame || mtmp->iswiz || is_fshk(mtmp)) return TRUE; + /* some monsters will follow even while intending to flee from you */ + if (mtmp->mtame || mtmp->iswiz || is_fshk(mtmp)) + return TRUE; - /* stalking types follow, but won't when fleeing unless you hold - the Amulet */ - return (boolean)((mtmp->data->mflags2 & M2_STALK) && - (!mtmp->mflee || u.uhave.amulet)); + /* stalking types follow, but won't when fleeing unless you hold + the Amulet */ + return (boolean)((mtmp->data->mflags2 & M2_STALK) + && (!mtmp->mflee || u.uhave.amulet)); } static const short grownups[][2] = { - {PM_CHICKATRICE, PM_COCKATRICE}, - {PM_LITTLE_DOG, PM_DOG}, {PM_DOG, PM_LARGE_DOG}, - {PM_HELL_HOUND_PUP, PM_HELL_HOUND}, - {PM_WINTER_WOLF_CUB, PM_WINTER_WOLF}, - {PM_KITTEN, PM_HOUSECAT}, {PM_HOUSECAT, PM_LARGE_CAT}, - {PM_PONY, PM_HORSE}, {PM_HORSE, PM_WARHORSE}, - {PM_KOBOLD, PM_LARGE_KOBOLD}, {PM_LARGE_KOBOLD, PM_KOBOLD_LORD}, - {PM_GNOME, PM_GNOME_LORD}, {PM_GNOME_LORD, PM_GNOME_KING}, - {PM_DWARF, PM_DWARF_LORD}, {PM_DWARF_LORD, PM_DWARF_KING}, - {PM_MIND_FLAYER, PM_MASTER_MIND_FLAYER}, - {PM_ORC, PM_ORC_CAPTAIN}, {PM_HILL_ORC, PM_ORC_CAPTAIN}, - {PM_MORDOR_ORC, PM_ORC_CAPTAIN}, {PM_URUK_HAI, PM_ORC_CAPTAIN}, - {PM_SEWER_RAT, PM_GIANT_RAT}, - {PM_CAVE_SPIDER, PM_GIANT_SPIDER}, - {PM_OGRE, PM_OGRE_LORD}, {PM_OGRE_LORD, PM_OGRE_KING}, - {PM_ELF, PM_ELF_LORD}, {PM_WOODLAND_ELF, PM_ELF_LORD}, - {PM_GREEN_ELF, PM_ELF_LORD}, {PM_GREY_ELF, PM_ELF_LORD}, - {PM_ELF_LORD, PM_ELVENKING}, - {PM_LICH, PM_DEMILICH}, {PM_DEMILICH, PM_MASTER_LICH}, - {PM_MASTER_LICH, PM_ARCH_LICH}, - {PM_VAMPIRE, PM_VAMPIRE_LORD}, {PM_BAT, PM_GIANT_BAT}, - {PM_BABY_GRAY_DRAGON, PM_GRAY_DRAGON}, - {PM_BABY_SILVER_DRAGON, PM_SILVER_DRAGON}, -#if 0 /* DEFERRED */ + { PM_CHICKATRICE, PM_COCKATRICE }, + { PM_LITTLE_DOG, PM_DOG }, + { PM_DOG, PM_LARGE_DOG }, + { PM_HELL_HOUND_PUP, PM_HELL_HOUND }, + { PM_WINTER_WOLF_CUB, PM_WINTER_WOLF }, + { PM_KITTEN, PM_HOUSECAT }, + { PM_HOUSECAT, PM_LARGE_CAT }, + { PM_PONY, PM_HORSE }, + { PM_HORSE, PM_WARHORSE }, + { PM_KOBOLD, PM_LARGE_KOBOLD }, + { PM_LARGE_KOBOLD, PM_KOBOLD_LORD }, + { PM_GNOME, PM_GNOME_LORD }, + { PM_GNOME_LORD, PM_GNOME_KING }, + { PM_DWARF, PM_DWARF_LORD }, + { PM_DWARF_LORD, PM_DWARF_KING }, + { PM_MIND_FLAYER, PM_MASTER_MIND_FLAYER }, + { PM_ORC, PM_ORC_CAPTAIN }, + { PM_HILL_ORC, PM_ORC_CAPTAIN }, + { PM_MORDOR_ORC, PM_ORC_CAPTAIN }, + { PM_URUK_HAI, PM_ORC_CAPTAIN }, + { PM_SEWER_RAT, PM_GIANT_RAT }, + { PM_CAVE_SPIDER, PM_GIANT_SPIDER }, + { PM_OGRE, PM_OGRE_LORD }, + { PM_OGRE_LORD, PM_OGRE_KING }, + { PM_ELF, PM_ELF_LORD }, + { PM_WOODLAND_ELF, PM_ELF_LORD }, + { PM_GREEN_ELF, PM_ELF_LORD }, + { PM_GREY_ELF, PM_ELF_LORD }, + { PM_ELF_LORD, PM_ELVENKING }, + { PM_LICH, PM_DEMILICH }, + { PM_DEMILICH, PM_MASTER_LICH }, + { PM_MASTER_LICH, PM_ARCH_LICH }, + { PM_VAMPIRE, PM_VAMPIRE_LORD }, + { PM_BAT, PM_GIANT_BAT }, + { PM_BABY_GRAY_DRAGON, PM_GRAY_DRAGON }, + { PM_BABY_SILVER_DRAGON, PM_SILVER_DRAGON }, +#if 0 /* DEFERRED */ {PM_BABY_SHIMMERING_DRAGON, PM_SHIMMERING_DRAGON}, #endif - {PM_BABY_RED_DRAGON, PM_RED_DRAGON}, - {PM_BABY_WHITE_DRAGON, PM_WHITE_DRAGON}, - {PM_BABY_ORANGE_DRAGON, PM_ORANGE_DRAGON}, - {PM_BABY_BLACK_DRAGON, PM_BLACK_DRAGON}, - {PM_BABY_BLUE_DRAGON, PM_BLUE_DRAGON}, - {PM_BABY_GREEN_DRAGON, PM_GREEN_DRAGON}, - {PM_BABY_YELLOW_DRAGON, PM_YELLOW_DRAGON}, - {PM_RED_NAGA_HATCHLING, PM_RED_NAGA}, - {PM_BLACK_NAGA_HATCHLING, PM_BLACK_NAGA}, - {PM_GOLDEN_NAGA_HATCHLING, PM_GOLDEN_NAGA}, - {PM_GUARDIAN_NAGA_HATCHLING, PM_GUARDIAN_NAGA}, - {PM_SMALL_MIMIC, PM_LARGE_MIMIC}, {PM_LARGE_MIMIC, PM_GIANT_MIMIC}, - {PM_BABY_LONG_WORM, PM_LONG_WORM}, - {PM_BABY_PURPLE_WORM, PM_PURPLE_WORM}, - {PM_BABY_CROCODILE, PM_CROCODILE}, - {PM_SOLDIER, PM_SERGEANT}, - {PM_SERGEANT, PM_LIEUTENANT}, - {PM_LIEUTENANT, PM_CAPTAIN}, - {PM_WATCHMAN, PM_WATCH_CAPTAIN}, - {PM_ALIGNED_PRIEST, PM_HIGH_PRIEST}, - {PM_STUDENT, PM_ARCHEOLOGIST}, - {PM_ATTENDANT, PM_HEALER}, - {PM_PAGE, PM_KNIGHT}, - {PM_ACOLYTE, PM_PRIEST}, - {PM_APPRENTICE, PM_WIZARD}, - {PM_MANES,PM_LEMURE}, - {PM_KEYSTONE_KOP, PM_KOP_SERGEANT}, - {PM_KOP_SERGEANT, PM_KOP_LIEUTENANT}, - {PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN}, - {NON_PM,NON_PM} + { PM_BABY_RED_DRAGON, PM_RED_DRAGON }, + { PM_BABY_WHITE_DRAGON, PM_WHITE_DRAGON }, + { PM_BABY_ORANGE_DRAGON, PM_ORANGE_DRAGON }, + { PM_BABY_BLACK_DRAGON, PM_BLACK_DRAGON }, + { PM_BABY_BLUE_DRAGON, PM_BLUE_DRAGON }, + { PM_BABY_GREEN_DRAGON, PM_GREEN_DRAGON }, + { PM_BABY_YELLOW_DRAGON, PM_YELLOW_DRAGON }, + { PM_RED_NAGA_HATCHLING, PM_RED_NAGA }, + { PM_BLACK_NAGA_HATCHLING, PM_BLACK_NAGA }, + { PM_GOLDEN_NAGA_HATCHLING, PM_GOLDEN_NAGA }, + { PM_GUARDIAN_NAGA_HATCHLING, PM_GUARDIAN_NAGA }, + { PM_SMALL_MIMIC, PM_LARGE_MIMIC }, + { PM_LARGE_MIMIC, PM_GIANT_MIMIC }, + { PM_BABY_LONG_WORM, PM_LONG_WORM }, + { PM_BABY_PURPLE_WORM, PM_PURPLE_WORM }, + { PM_BABY_CROCODILE, PM_CROCODILE }, + { PM_SOLDIER, PM_SERGEANT }, + { PM_SERGEANT, PM_LIEUTENANT }, + { PM_LIEUTENANT, PM_CAPTAIN }, + { PM_WATCHMAN, PM_WATCH_CAPTAIN }, + { PM_ALIGNED_PRIEST, PM_HIGH_PRIEST }, + { PM_STUDENT, PM_ARCHEOLOGIST }, + { PM_ATTENDANT, PM_HEALER }, + { PM_PAGE, PM_KNIGHT }, + { PM_ACOLYTE, PM_PRIEST }, + { PM_APPRENTICE, PM_WIZARD }, + { PM_MANES, PM_LEMURE }, + { PM_KEYSTONE_KOP, PM_KOP_SERGEANT }, + { PM_KOP_SERGEANT, PM_KOP_LIEUTENANT }, + { PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN }, + { NON_PM, NON_PM } }; int @@ -870,25 +949,27 @@ little_to_big(montype) int montype; { #ifndef AIXPS2_BUG - register int i; + register int i; - for (i = 0; grownups[i][0] >= LOW_PM; i++) - if(montype == grownups[i][0]) return grownups[i][1]; - return montype; + for (i = 0; grownups[i][0] >= LOW_PM; i++) + if (montype == grownups[i][0]) + return grownups[i][1]; + return montype; #else -/* AIX PS/2 C-compiler 1.1.1 optimizer does not like the above for loop, - * and causes segmentation faults at runtime. (The problem does not - * occur if -O is not used.) - * lehtonen@cs.Helsinki.FI (Tapio Lehtonen) 28031990 - */ - int i; - int monvalue; + /* AIX PS/2 C-compiler 1.1.1 optimizer does not like the above for loop, + * and causes segmentation faults at runtime. (The problem does not + * occur if -O is not used.) + * lehtonen@cs.Helsinki.FI (Tapio Lehtonen) 28031990 + */ + int i; + int monvalue; - monvalue = montype; - for (i = 0; grownups[i][0] >= LOW_PM; i++) - if(montype == grownups[i][0]) monvalue = grownups[i][1]; + monvalue = montype; + for (i = 0; grownups[i][0] >= LOW_PM; i++) + if (montype == grownups[i][0]) + monvalue = grownups[i][1]; - return monvalue; + return monvalue; #endif } @@ -896,11 +977,12 @@ int big_to_little(montype) int montype; { - register int i; + register int i; - for (i = 0; grownups[i][0] >= LOW_PM; i++) - if(montype == grownups[i][1]) return grownups[i][0]; - return montype; + for (i = 0; grownups[i][0] >= LOW_PM; i++) + if (montype == grownups[i][1]) + return grownups[i][0]; + return montype; } /* @@ -912,36 +994,42 @@ const struct permonst * raceptr(mtmp) struct monst *mtmp; { - if (mtmp == &youmonst && !Upolyd) return(&mons[urace.malenum]); - else return(mtmp->data); + if (mtmp == &youmonst && !Upolyd) + return (&mons[urace.malenum]); + else + return (mtmp->data); } -static const char *levitate[4] = { "float", "Float", "wobble", "Wobble" }; -static const char *flys[4] = { "fly", "Fly", "flutter", "Flutter" }; -static const char *flyl[4] = { "fly", "Fly", "stagger", "Stagger" }; -static const char *slither[4] = { "slither", "Slither", "falter", "Falter" }; -static const char *ooze[4] = { "ooze", "Ooze", "tremble", "Tremble" }; -static const char *immobile[4] = { "wiggle", "Wiggle", "pulsate", "Pulsate" }; -static const char *crawl[4] = { "crawl", "Crawl", "falter", "Falter" }; +static const char *levitate[4] = { "float", "Float", "wobble", "Wobble" }; +static const char *flys[4] = { "fly", "Fly", "flutter", "Flutter" }; +static const char *flyl[4] = { "fly", "Fly", "stagger", "Stagger" }; +static const char *slither[4] = { "slither", "Slither", "falter", "Falter" }; +static const char *ooze[4] = { "ooze", "Ooze", "tremble", "Tremble" }; +static const char *immobile[4] = { "wiggle", "Wiggle", "pulsate", "Pulsate" }; +static const char *crawl[4] = { "crawl", "Crawl", "falter", "Falter" }; const char * locomotion(ptr, def) const struct permonst *ptr; const char *def; { - int capitalize = (*def == highc(*def)); - - return ( - is_floater(ptr) ? levitate[capitalize] : - (is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[capitalize] : - (is_flyer(ptr) && ptr->msize > MZ_SMALL) ? flyl[capitalize] : - slithy(ptr) ? slither[capitalize] : - amorphous(ptr) ? ooze[capitalize] : - !ptr->mmove ? immobile[capitalize] : - nolimbs(ptr) ? crawl[capitalize] : - def - ); + int capitalize = (*def == highc(*def)); + return (is_floater(ptr) + ? levitate[capitalize] + : (is_flyer(ptr) && ptr->msize <= MZ_SMALL) + ? flys[capitalize] + : (is_flyer(ptr) && ptr->msize > MZ_SMALL) + ? flyl[capitalize] + : slithy(ptr) + ? slither[capitalize] + : amorphous(ptr) + ? ooze[capitalize] + : !ptr->mmove + ? immobile[capitalize] + : nolimbs(ptr) + ? crawl[capitalize] + : def); } const char * @@ -949,22 +1037,27 @@ stagger(ptr, def) const struct permonst *ptr; const char *def; { - int capitalize = 2 + (*def == highc(*def)); - - return ( - is_floater(ptr) ? levitate[capitalize] : - (is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[capitalize] : - (is_flyer(ptr) && ptr->msize > MZ_SMALL) ? flyl[capitalize] : - slithy(ptr) ? slither[capitalize] : - amorphous(ptr) ? ooze[capitalize] : - !ptr->mmove ? immobile[capitalize] : - nolimbs(ptr) ? crawl[capitalize] : - def - ); + int capitalize = 2 + (*def == highc(*def)); + return (is_floater(ptr) + ? levitate[capitalize] + : (is_flyer(ptr) && ptr->msize <= MZ_SMALL) + ? flys[capitalize] + : (is_flyer(ptr) && ptr->msize > MZ_SMALL) + ? flyl[capitalize] + : slithy(ptr) + ? slither[capitalize] + : amorphous(ptr) + ? ooze[capitalize] + : !ptr->mmove + ? immobile[capitalize] + : nolimbs(ptr) + ? crawl[capitalize] + : def); } -/* return a phrase describing the effect of fire attack on a type of monster */ +/* return a phrase describing the effect of fire attack on a type of monster + */ const char * on_fire(mptr, mattk) struct permonst *mptr; @@ -977,17 +1070,17 @@ struct attack *mattk; case PM_FIRE_VORTEX: case PM_FIRE_ELEMENTAL: case PM_SALAMANDER: - what = "already on fire"; - break; + what = "already on fire"; + break; case PM_WATER_ELEMENTAL: case PM_FOG_CLOUD: case PM_STEAM_VORTEX: - what = "boiling"; - break; + what = "boiling"; + break; case PM_ICE_VORTEX: case PM_GLASS_GOLEM: - what = "melting"; - break; + what = "melting"; + break; case PM_STONE_GOLEM: case PM_CLAY_GOLEM: case PM_GOLD_GOLEM: @@ -995,11 +1088,11 @@ struct attack *mattk; case PM_EARTH_ELEMENTAL: case PM_DUST_VORTEX: case PM_ENERGY_VORTEX: - what = "heating up"; - break; + what = "heating up"; + break; default: - what = (mattk->aatyp == AT_HUGS) ? "being roasted" : "on fire"; - break; + what = (mattk->aatyp == AT_HUGS) ? "being roasted" : "on fire"; + break; } return what; } @@ -1017,17 +1110,14 @@ boolean olfaction(mdat) struct permonst *mdat; { - if (mdat && (is_golem(mdat) || - mdat->mlet == S_EYE || /* spheres */ - mdat->mlet == S_JELLY || - mdat->mlet == S_PUDDING || - mdat->mlet == S_BLOB || - mdat->mlet == S_VORTEX || - mdat->mlet == S_ELEMENTAL || - mdat->mlet == S_FUNGUS || /* mushrooms and fungi */ - mdat->mlet == S_LIGHT)) - return FALSE; - return TRUE; + if (mdat && (is_golem(mdat) || mdat->mlet == S_EYE || /* spheres */ + mdat->mlet == S_JELLY || mdat->mlet == S_PUDDING + || mdat->mlet == S_BLOB || mdat->mlet == S_VORTEX + || mdat->mlet == S_ELEMENTAL || mdat->mlet == S_FUNGUS + || /* mushrooms and fungi */ + mdat->mlet == S_LIGHT)) + return FALSE; + return TRUE; } /*mondata.c*/ diff --git a/src/monmove.c b/src/monmove.c index 633e66e21..4eda8d769 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 monmove.c $NHDT-Date: 1430172947 2015/04/27 22:15:47 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.62 $ */ +/* NetHack 3.6 monmove.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.67 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,44 +8,45 @@ extern boolean notonhead; -STATIC_DCL void FDECL(watch_on_duty,(struct monst *)); -STATIC_DCL int FDECL(disturb,(struct monst *)); +STATIC_DCL void FDECL(watch_on_duty, (struct monst *)); +STATIC_DCL int FDECL(disturb, (struct monst *)); STATIC_DCL void FDECL(release_hero, (struct monst *)); -STATIC_DCL void FDECL(distfleeck,(struct monst *,int *,int *,int *)); +STATIC_DCL void FDECL(distfleeck, (struct monst *, int *, int *, int *)); STATIC_DCL int FDECL(m_arrival, (struct monst *)); STATIC_DCL boolean FDECL(stuff_prevents_passage, (struct monst *)); -STATIC_DCL int FDECL(vamp_shift, (struct monst *,struct permonst *)); +STATIC_DCL int FDECL(vamp_shift, (struct monst *, struct permonst *)); boolean /* TRUE : mtmp died */ -mb_trapped(mtmp) + mb_trapped(mtmp) register struct monst *mtmp; { - if (flags.verbose) { - if (cansee(mtmp->mx, mtmp->my) && !Unaware) - pline("KABOOM!! You see a door explode."); - else if (!Deaf) - You_hear("a distant explosion."); - } - wake_nearto(mtmp->mx, mtmp->my, 7*7); - mtmp->mstun = 1; - mtmp->mhp -= rnd(15); - if(mtmp->mhp <= 0) { - mondied(mtmp); - if (mtmp->mhp > 0) /* lifesaved */ - return(FALSE); - else - return(TRUE); - } - return(FALSE); + if (flags.verbose) { + if (cansee(mtmp->mx, mtmp->my) && !Unaware) + pline("KABOOM!! You see a door explode."); + else if (!Deaf) + You_hear("a distant explosion."); + } + wake_nearto(mtmp->mx, mtmp->my, 7 * 7); + mtmp->mstun = 1; + mtmp->mhp -= rnd(15); + if (mtmp->mhp <= 0) { + mondied(mtmp); + if (mtmp->mhp > 0) /* lifesaved */ + return (FALSE); + else + return (TRUE); + } + return (FALSE); } /* check whether a monster is carrying a locking/unlocking tool */ boolean monhaskey(mon, for_unlocking) struct monst *mon; -boolean for_unlocking; /* true => credit card ok, false => not ok */ +boolean for_unlocking; /* true => credit card ok, false => not ok */ { - if (for_unlocking && m_carrying(mon, CREDIT_CARD)) return TRUE; + if (for_unlocking && m_carrying(mon, CREDIT_CARD)) + return TRUE; return m_carrying(mon, SKELETON_KEY) || m_carrying(mon, LOCK_PICK); } @@ -55,9 +56,9 @@ struct monst *mon; const char *shout; { if (canspotmon(mon)) - pline("%s yells:", Amonnam(mon)); + pline("%s yells:", Amonnam(mon)); else - You_hear("someone yell:"); + You_hear("someone yell:"); verbalize(shout); } @@ -65,56 +66,54 @@ STATIC_OVL void watch_on_duty(mtmp) register struct monst *mtmp; { - int x, y; + int x, y; - if(mtmp->mpeaceful && in_town(u.ux+u.dx, u.uy+u.dy) && - mtmp->mcansee && m_canseeu(mtmp) && !rn2(3)) { - - if(picking_lock(&x, &y) && IS_DOOR(levl[x][y].typ) && - (levl[x][y].doormask & D_LOCKED)) { - - if(couldsee(mtmp->mx, mtmp->my)) { - if(levl[x][y].looted & D_WARNED) { - mon_yells(mtmp, "Halt, thief! You're under arrest!"); - (void) angry_guards(!!Deaf); - } else { - mon_yells(mtmp, "Hey, stop picking that lock!"); - levl[x][y].looted |= D_WARNED; - } - stop_occupation(); - } - } else if (is_digging()) { - /* chewing, wand/spell of digging are checked elsewhere */ - watch_dig(mtmp, context.digging.pos.x, context.digging.pos.y, FALSE); - } - } + if (mtmp->mpeaceful && in_town(u.ux + u.dx, u.uy + u.dy) && mtmp->mcansee + && m_canseeu(mtmp) && !rn2(3)) { + if (picking_lock(&x, &y) && IS_DOOR(levl[x][y].typ) + && (levl[x][y].doormask & D_LOCKED)) { + if (couldsee(mtmp->mx, mtmp->my)) { + if (levl[x][y].looted & D_WARNED) { + mon_yells(mtmp, "Halt, thief! You're under arrest!"); + (void) angry_guards(!!Deaf); + } else { + mon_yells(mtmp, "Hey, stop picking that lock!"); + levl[x][y].looted |= D_WARNED; + } + stop_occupation(); + } + } else if (is_digging()) { + /* chewing, wand/spell of digging are checked elsewhere */ + watch_dig(mtmp, context.digging.pos.x, context.digging.pos.y, + FALSE); + } + } } int dochugw(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - register int x = mtmp->mx, y = mtmp->my; - boolean already_saw_mon = !occupation ? 0 : canspotmon(mtmp); - int rd = dochug(mtmp); + register int x = mtmp->mx, y = mtmp->my; + boolean already_saw_mon = !occupation ? 0 : canspotmon(mtmp); + int rd = dochug(mtmp); - /* a similar check is in monster_nearby() in hack.c */ - /* check whether hero notices monster and stops current activity */ - if (occupation && !rd && !Confusion && - (!mtmp->mpeaceful || Hallucination) && - /* it's close enough to be a threat */ - distu(mtmp->mx,mtmp->my) <= (BOLT_LIM+1)*(BOLT_LIM+1) && - /* and either couldn't see it before, or it was too far away */ - (!already_saw_mon || !couldsee(x,y) || - distu(x,y) > (BOLT_LIM+1)*(BOLT_LIM+1)) && - /* can see it now, or sense it and would normally see it */ - (canseemon(mtmp) || - (sensemon(mtmp) && couldsee(mtmp->mx,mtmp->my))) && - mtmp->mcanmove && - !noattacks(mtmp->data) && !onscary(u.ux, u.uy, mtmp)) - stop_occupation(); + /* a similar check is in monster_nearby() in hack.c */ + /* check whether hero notices monster and stops current activity */ + if (occupation && !rd && !Confusion && (!mtmp->mpeaceful || Hallucination) + && + /* it's close enough to be a threat */ + distu(mtmp->mx, mtmp->my) <= (BOLT_LIM + 1) * (BOLT_LIM + 1) && + /* and either couldn't see it before, or it was too far away */ + (!already_saw_mon || !couldsee(x, y) + || distu(x, y) > (BOLT_LIM + 1) * (BOLT_LIM + 1)) && + /* can see it now, or sense it and would normally see it */ + (canseemon(mtmp) || (sensemon(mtmp) && couldsee(mtmp->mx, mtmp->my))) + && mtmp->mcanmove && !noattacks(mtmp->data) + && !onscary(u.ux, u.uy, mtmp)) + stop_occupation(); - return(rd); + return (rd); } boolean @@ -122,42 +121,42 @@ onscary(x, y, mtmp) int x, y; struct monst *mtmp; { - boolean epresent = sengr_at("Elbereth", x, y, TRUE); - - /* creatures who are directly resistant to magical scaring: - * Rodney, lawful minions, angels, the Riders - */ - if (mtmp->iswiz || is_lminion(mtmp) - || mtmp->data == &mons[PM_ANGEL] - || is_rider(mtmp->data)) - return(FALSE); + boolean epresent = sengr_at("Elbereth", x, y, TRUE); - /* creatures who don't (or can't) fear a written Elbereth: - * all the above plus shopkeepers, guards, blind or - * peaceful monsters, humans, and minotaurs. - * - * Elbereth doesn't work in Gehennom, the Elemental Planes, or the - * Astral Plane; the influence of the Valar only reaches so far. - */ - if (epresent && (mtmp->isshk || mtmp->isgd || !mtmp->mcansee - || mtmp->mpeaceful || mtmp->data->mlet == S_HUMAN - || mtmp->data == &mons[PM_MINOTAUR] - || Inhell || In_endgame(&u.uz))) - return(FALSE); + /* creatures who are directly resistant to magical scaring: + * Rodney, lawful minions, angels, the Riders + */ + if (mtmp->iswiz || is_lminion(mtmp) || mtmp->data == &mons[PM_ANGEL] + || is_rider(mtmp->data)) + return (FALSE); - /* should this still be true for defiled/molochian altars? */ - if (IS_ALTAR(levl[x][y].typ) && (mtmp->data->mlet == S_VAMPIRE - || is_vampshifter(mtmp))) - return(TRUE); + /* creatures who don't (or can't) fear a written Elbereth: + * all the above plus shopkeepers, guards, blind or + * peaceful monsters, humans, and minotaurs. + * + * Elbereth doesn't work in Gehennom, the Elemental Planes, or the + * Astral Plane; the influence of the Valar only reaches so far. + */ + if (epresent + && (mtmp->isshk || mtmp->isgd || !mtmp->mcansee || mtmp->mpeaceful + || mtmp->data->mlet == S_HUMAN || mtmp->data == &mons[PM_MINOTAUR] + || Inhell || In_endgame(&u.uz))) + return (FALSE); - /* if the player isn't actually on the square OR the player's image - * isn't displaced to the square, no protection is being granted - * - * the scare monster scroll, though, is quite powerful. - */ - return (boolean)(sobj_at(SCR_SCARE_MONSTER, x, y) - || (epresent && ((u.ux == x && u.uy == y) - || (Displaced && mtmp->mux == x && mtmp->muy == y)))); + /* should this still be true for defiled/molochian altars? */ + if (IS_ALTAR(levl[x][y].typ) + && (mtmp->data->mlet == S_VAMPIRE || is_vampshifter(mtmp))) + return (TRUE); + + /* if the player isn't actually on the square OR the player's image + * isn't displaced to the square, no protection is being granted + * + * the scare monster scroll, though, is quite powerful. + */ + return (boolean)(sobj_at(SCR_SCARE_MONSTER, x, y) + || (epresent && ((u.ux == x && u.uy == y) + || (Displaced && mtmp->mux == x + && mtmp->muy == y)))); } /* regenerate lost hit points */ @@ -166,15 +165,17 @@ mon_regen(mon, digest_meal) struct monst *mon; boolean digest_meal; { - if (mon->mhp < mon->mhpmax && - (moves % 20 == 0 || regenerates(mon->data))) mon->mhp++; - if (mon->mspec_used) mon->mspec_used--; - if (digest_meal) { - if (mon->meating) { - mon->meating--; - if (mon->meating <= 0) finish_meating(mon); - } - } + if (mon->mhp < mon->mhpmax && (moves % 20 == 0 || regenerates(mon->data))) + mon->mhp++; + if (mon->mspec_used) + mon->mspec_used--; + if (digest_meal) { + if (mon->meating) { + mon->meating--; + if (mon->meating <= 0) + finish_meating(mon); + } + } } /* @@ -183,38 +184,36 @@ boolean digest_meal; */ STATIC_OVL int disturb(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - /* - * + Ettins are hard to surprise. - * + Nymphs, jabberwocks, and leprechauns do not easily wake up. - * - * Wake up if: - * in direct LOS AND - * within 10 squares AND - * not stealthy or (mon is an ettin and 9/10) AND - * (mon is not a nymph, jabberwock, or leprechaun) or 1/50 AND - * Aggravate or mon is (dog or human) or - * (1/7 and mon is not mimicing furniture or object) - */ - if(couldsee(mtmp->mx,mtmp->my) && - distu(mtmp->mx,mtmp->my) <= 100 && - (!Stealth || (mtmp->data == &mons[PM_ETTIN] && rn2(10))) && - (!(mtmp->data->mlet == S_NYMPH - || mtmp->data == &mons[PM_JABBERWOCK] -#if 0 /* DEFERRED */ + /* + * + Ettins are hard to surprise. + * + Nymphs, jabberwocks, and leprechauns do not easily wake up. + * + * Wake up if: + * in direct LOS AND + * within 10 squares AND + * not stealthy or (mon is an ettin and 9/10) AND + * (mon is not a nymph, jabberwock, or leprechaun) or 1/50 AND + * Aggravate or mon is (dog or human) or + * (1/7 and mon is not mimicing furniture or object) + */ + if (couldsee(mtmp->mx, mtmp->my) && distu(mtmp->mx, mtmp->my) <= 100 + && (!Stealth || (mtmp->data == &mons[PM_ETTIN] && rn2(10))) + && (!(mtmp->data->mlet == S_NYMPH + || mtmp->data == &mons[PM_JABBERWOCK] +#if 0 /* DEFERRED */ || mtmp->data == &mons[PM_VORPAL_JABBERWOCK] #endif - || mtmp->data->mlet == S_LEPRECHAUN) || !rn2(50)) && - (Aggravate_monster - || (mtmp->data->mlet == S_DOG || - mtmp->data->mlet == S_HUMAN) - || (!rn2(7) && mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT) )) { - mtmp->msleeping = 0; - return(1); - } - return(0); + || mtmp->data->mlet == S_LEPRECHAUN) || !rn2(50)) + && (Aggravate_monster + || (mtmp->data->mlet == S_DOG || mtmp->data->mlet == S_HUMAN) + || (!rn2(7) && mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT))) { + mtmp->msleeping = 0; + return (1); + } + return (0); } /* ungrab/expel held/swallowed hero */ @@ -222,14 +221,14 @@ STATIC_OVL void release_hero(mon) struct monst *mon; { - if (mon == u.ustuck) { - if (u.uswallow) { - expels(mon, mon->data, TRUE); - } else if (!sticks(youmonst.data)) { - unstuck(mon); /* let go */ - You("get released!"); - } - } + if (mon == u.ustuck) { + if (u.uswallow) { + expels(mon, mon->data, TRUE); + } else if (!sticks(youmonst.data)) { + unstuck(mon); /* let go */ + You("get released!"); + } + } } /* monster begins fleeing for the specified time, 0 means untimed flee @@ -242,34 +241,37 @@ int fleetime; boolean first; boolean fleemsg; { - /* shouldn't happen; maybe warrants impossible()? */ - if (DEADMONSTER(mtmp)) return; + /* shouldn't happen; maybe warrants impossible()? */ + if (DEADMONSTER(mtmp)) + return; - if (mtmp == u.ustuck) release_hero(mtmp); /* expels/unstuck */ + if (mtmp == u.ustuck) + release_hero(mtmp); /* expels/unstuck */ - if (!first || !mtmp->mflee) { - /* don't lose untimed scare */ - if (!fleetime) - mtmp->mfleetim = 0; - else if (!mtmp->mflee || mtmp->mfleetim) { - fleetime += (int)mtmp->mfleetim; - /* ensure monster flees long enough to visibly stop fighting */ - if (fleetime == 1) fleetime++; - mtmp->mfleetim = (unsigned)min(fleetime, 127); - } - if (!mtmp->mflee && fleemsg && canseemon(mtmp) && - mtmp->m_ap_type != M_AP_FURNITURE && - mtmp->m_ap_type != M_AP_OBJECT) { - /* unfortunately we can't distinguish between temporary - sleep and temporary paralysis, so both conditions - receive the same alternate message */ - if (!mtmp->mcanmove || !mtmp->data->mmove) - pline("%s seems to flinch.", Adjmonnam(mtmp, "immobile")); - else - pline("%s turns to flee.", Monnam(mtmp)); - } - mtmp->mflee = 1; - } + if (!first || !mtmp->mflee) { + /* don't lose untimed scare */ + if (!fleetime) + mtmp->mfleetim = 0; + else if (!mtmp->mflee || mtmp->mfleetim) { + fleetime += (int) mtmp->mfleetim; + /* ensure monster flees long enough to visibly stop fighting */ + if (fleetime == 1) + fleetime++; + mtmp->mfleetim = (unsigned) min(fleetime, 127); + } + if (!mtmp->mflee && fleemsg && canseemon(mtmp) + && mtmp->m_ap_type != M_AP_FURNITURE + && mtmp->m_ap_type != M_AP_OBJECT) { + /* unfortunately we can't distinguish between temporary + sleep and temporary paralysis, so both conditions + receive the same alternate message */ + if (!mtmp->mcanmove || !mtmp->data->mmove) + pline("%s seems to flinch.", Adjmonnam(mtmp, "immobile")); + else + pline("%s turns to flee.", Monnam(mtmp)); + } + mtmp->mflee = 1; + } } STATIC_OVL void @@ -277,41 +279,41 @@ distfleeck(mtmp, inrange, nearby, scared) register struct monst *mtmp; int *inrange, *nearby, *scared; { - int seescaryx, seescaryy; - boolean sawscary = FALSE; + int seescaryx, seescaryy; + boolean sawscary = FALSE; - *inrange = (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= - (BOLT_LIM * BOLT_LIM)); - *nearby = *inrange && monnear(mtmp, mtmp->mux, mtmp->muy); + *inrange = (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) + <= (BOLT_LIM * BOLT_LIM)); + *nearby = *inrange && monnear(mtmp, mtmp->mux, mtmp->muy); - /* Note: if your image is displaced, the monster sees the Elbereth - * at your displaced position, thus never attacking your displaced - * position, but possibly attacking you by accident. If you are - * invisible, it sees the Elbereth at your real position, thus never - * running into you by accident but possibly attacking the spot - * where it guesses you are. - */ - if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) { - seescaryx = mtmp->mux; - seescaryy = mtmp->muy; - } else { - seescaryx = u.ux; - seescaryy = u.uy; - } + /* Note: if your image is displaced, the monster sees the Elbereth + * at your displaced position, thus never attacking your displaced + * position, but possibly attacking you by accident. If you are + * invisible, it sees the Elbereth at your real position, thus never + * running into you by accident but possibly attacking the spot + * where it guesses you are. + */ + if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) { + seescaryx = mtmp->mux; + seescaryy = mtmp->muy; + } else { + seescaryx = u.ux; + seescaryy = u.uy; + } - sawscary = onscary(seescaryx, seescaryy, mtmp); - if (*nearby && (sawscary || (!mtmp->mpeaceful - && in_your_sanctuary(mtmp, 0, 0)))) { - *scared = 1; - monflee(mtmp, rnd(rn2(7) ? 10 : 100), TRUE, TRUE); + sawscary = onscary(seescaryx, seescaryy, mtmp); + if (*nearby && (sawscary + || (!mtmp->mpeaceful && in_your_sanctuary(mtmp, 0, 0)))) { + *scared = 1; + monflee(mtmp, rnd(rn2(7) ? 10 : 100), TRUE, TRUE); - /* magical protection won't last forever, so there'll be a - * chance of the magic being used up regardless of type */ - if (sawscary) { - wipe_engr_at(seescaryx, seescaryy, 1, TRUE); - } - } else - *scared = 0; + /* magical protection won't last forever, so there'll be a + * chance of the magic being used up regardless of type */ + if (sawscary) { + wipe_engr_at(seescaryx, seescaryy, 1, TRUE); + } + } else + *scared = 0; } /* perform a special one-time action for a monster; returns -1 if nothing @@ -320,9 +322,9 @@ STATIC_OVL int m_arrival(mon) struct monst *mon; { - mon->mstrategy &= ~STRAT_ARRIVE; /* always reset */ + mon->mstrategy &= ~STRAT_ARRIVE; /* always reset */ - return -1; + return -1; } /* returns 1 if monster died moving, 0 otherwise */ @@ -333,279 +335,303 @@ int dochug(mtmp) register struct monst *mtmp; { - register struct permonst *mdat; - register int tmp=0; - int inrange, nearby, scared; + register struct permonst *mdat; + register int tmp = 0; + int inrange, nearby, scared; -/* Pre-movement adjustments */ + /* Pre-movement adjustments */ - mdat = mtmp->data; + mdat = mtmp->data; - if (mtmp->mstrategy & STRAT_ARRIVE) { - int res = m_arrival(mtmp); - if (res >= 0) return res; - } + if (mtmp->mstrategy & STRAT_ARRIVE) { + int res = m_arrival(mtmp); + if (res >= 0) + return res; + } - /* check for waitmask status change */ - if ((mtmp->mstrategy & STRAT_WAITFORU) && - (m_canseeu(mtmp) || mtmp->mhp < mtmp->mhpmax)) - mtmp->mstrategy &= ~STRAT_WAITFORU; + /* check for waitmask status change */ + if ((mtmp->mstrategy & STRAT_WAITFORU) + && (m_canseeu(mtmp) || mtmp->mhp < mtmp->mhpmax)) + mtmp->mstrategy &= ~STRAT_WAITFORU; - /* update quest status flags */ - quest_stat_check(mtmp); + /* update quest status flags */ + quest_stat_check(mtmp); - if (!mtmp->mcanmove || (mtmp->mstrategy & STRAT_WAITMASK)) { - if (Hallucination) newsym(mtmp->mx,mtmp->my); - if (mtmp->mcanmove && (mtmp->mstrategy & STRAT_CLOSE) && - !mtmp->msleeping && monnear(mtmp, u.ux, u.uy)) - quest_talk(mtmp); /* give the leaders a chance to speak */ - return(0); /* other frozen monsters can't do anything */ - } + if (!mtmp->mcanmove || (mtmp->mstrategy & STRAT_WAITMASK)) { + if (Hallucination) + newsym(mtmp->mx, mtmp->my); + if (mtmp->mcanmove && (mtmp->mstrategy & STRAT_CLOSE) + && !mtmp->msleeping && monnear(mtmp, u.ux, u.uy)) + quest_talk(mtmp); /* give the leaders a chance to speak */ + return (0); /* other frozen monsters can't do anything */ + } - /* there is a chance we will wake it */ - if (mtmp->msleeping && !disturb(mtmp)) { - if (Hallucination) newsym(mtmp->mx,mtmp->my); - return(0); - } + /* there is a chance we will wake it */ + if (mtmp->msleeping && !disturb(mtmp)) { + if (Hallucination) + newsym(mtmp->mx, mtmp->my); + return (0); + } - /* not frozen or sleeping: wipe out texts written in the dust */ - wipe_engr_at(mtmp->mx, mtmp->my, 1, FALSE); + /* not frozen or sleeping: wipe out texts written in the dust */ + wipe_engr_at(mtmp->mx, mtmp->my, 1, FALSE); - /* confused monsters get unconfused with small probability */ - if (mtmp->mconf && !rn2(50)) mtmp->mconf = 0; + /* confused monsters get unconfused with small probability */ + if (mtmp->mconf && !rn2(50)) + mtmp->mconf = 0; - /* stunned monsters get un-stunned with larger probability */ - if (mtmp->mstun && !rn2(10)) mtmp->mstun = 0; + /* stunned monsters get un-stunned with larger probability */ + if (mtmp->mstun && !rn2(10)) + mtmp->mstun = 0; - /* some monsters teleport */ - if (mtmp->mflee && !rn2(40) && can_teleport(mdat) && !mtmp->iswiz && - !level.flags.noteleport) { - (void) rloc(mtmp, FALSE); - return(0); - } - if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1)) - m_respond(mtmp); - if (mdat == &mons[PM_MEDUSA] && couldsee(mtmp->mx, mtmp->my)) - m_respond(mtmp); - if (mtmp->mhp <= 0) return(1); /* m_respond gaze can kill medusa */ + /* some monsters teleport */ + if (mtmp->mflee && !rn2(40) && can_teleport(mdat) && !mtmp->iswiz + && !level.flags.noteleport) { + (void) rloc(mtmp, FALSE); + return (0); + } + if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1)) + m_respond(mtmp); + if (mdat == &mons[PM_MEDUSA] && couldsee(mtmp->mx, mtmp->my)) + m_respond(mtmp); + if (mtmp->mhp <= 0) + return (1); /* m_respond gaze can kill medusa */ - /* fleeing monsters might regain courage */ - if (mtmp->mflee && !mtmp->mfleetim - && mtmp->mhp == mtmp->mhpmax && !rn2(25)) mtmp->mflee = 0; + /* fleeing monsters might regain courage */ + if (mtmp->mflee && !mtmp->mfleetim && mtmp->mhp == mtmp->mhpmax + && !rn2(25)) + mtmp->mflee = 0; - /* cease conflict-induced swallow/grab if conflict has ended */ - if (mtmp == u.ustuck && mtmp->mpeaceful && !mtmp->mconf && !Conflict) { - release_hero(mtmp); - return 0; /* uses up monster's turn */ - } + /* cease conflict-induced swallow/grab if conflict has ended */ + if (mtmp == u.ustuck && mtmp->mpeaceful && !mtmp->mconf && !Conflict) { + release_hero(mtmp); + return 0; /* uses up monster's turn */ + } - set_apparxy(mtmp); - /* Must be done after you move and before the monster does. The - * set_apparxy() call in m_move() doesn't suffice since the variables - * inrange, etc. all depend on stuff set by set_apparxy(). - */ + set_apparxy(mtmp); + /* Must be done after you move and before the monster does. The + * set_apparxy() call in m_move() doesn't suffice since the variables + * inrange, etc. all depend on stuff set by set_apparxy(). + */ - /* Monsters that want to acquire things */ - /* may teleport, so do it before inrange is set */ - if(is_covetous(mdat)) (void) tactics(mtmp); + /* Monsters that want to acquire things */ + /* may teleport, so do it before inrange is set */ + if (is_covetous(mdat)) + (void) tactics(mtmp); - /* check distance and scariness of attacks */ - distfleeck(mtmp,&inrange,&nearby,&scared); + /* check distance and scariness of attacks */ + distfleeck(mtmp, &inrange, &nearby, &scared); - if(find_defensive(mtmp)) { - if (use_defensive(mtmp) != 0) - return 1; - } else if(find_misc(mtmp)) { - if (use_misc(mtmp) != 0) - return 1; - } + if (find_defensive(mtmp)) { + if (use_defensive(mtmp) != 0) + return 1; + } else if (find_misc(mtmp)) { + if (use_misc(mtmp) != 0) + return 1; + } - /* Demonic Blackmail! */ - if(nearby && mdat->msound == MS_BRIBE && - mtmp->mpeaceful && !mtmp->mtame && !u.uswallow) { - if (mtmp->mux != u.ux || mtmp->muy != u.uy) { - pline("%s whispers at thin air.", - cansee(mtmp->mux, mtmp->muy) ? Monnam(mtmp) : "It"); + /* Demonic Blackmail! */ + if (nearby && mdat->msound == MS_BRIBE && mtmp->mpeaceful && !mtmp->mtame + && !u.uswallow) { + if (mtmp->mux != u.ux || mtmp->muy != u.uy) { + pline("%s whispers at thin air.", + cansee(mtmp->mux, mtmp->muy) ? Monnam(mtmp) : "It"); - if (is_demon(youmonst.data)) { - /* "Good hunting, brother" */ - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - } else { - mtmp->minvis = mtmp->perminvis = 0; - /* Why? For the same reason in real demon talk */ - pline("%s gets angry!", Amonnam(mtmp)); - mtmp->mpeaceful = 0; - set_malign(mtmp); - /* since no way is an image going to pay it off */ - } - } else if(demon_talk(mtmp)) return(1); /* you paid it off */ - } + if (is_demon(youmonst.data)) { + /* "Good hunting, brother" */ + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + } else { + mtmp->minvis = mtmp->perminvis = 0; + /* Why? For the same reason in real demon talk */ + pline("%s gets angry!", Amonnam(mtmp)); + mtmp->mpeaceful = 0; + set_malign(mtmp); + /* since no way is an image going to pay it off */ + } + } else if (demon_talk(mtmp)) + return (1); /* you paid it off */ + } - /* the watch will look around and see if you are up to no good :-) */ - if (is_watch(mdat)) - watch_on_duty(mtmp); + /* the watch will look around and see if you are up to no good :-) */ + if (is_watch(mdat)) + watch_on_duty(mtmp); - else if (is_mind_flayer(mdat) && !rn2(20)) { - struct monst *m2, *nmon = (struct monst *)0; + else if (is_mind_flayer(mdat) && !rn2(20)) { + struct monst *m2, *nmon = (struct monst *) 0; - if (canseemon(mtmp)) - pline("%s concentrates.", Monnam(mtmp)); - if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM) { - You("sense a faint wave of psychic energy."); - goto toofar; - } - pline("A wave of psychic energy pours over you!"); - if (mtmp->mpeaceful && - (!Conflict || resist(mtmp, RING_CLASS, 0, 0))) { - pline("It feels quite soothing."); - } else if (!u.uinvulnerable) { - register boolean m_sen = sensemon(mtmp); + if (canseemon(mtmp)) + pline("%s concentrates.", Monnam(mtmp)); + if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM) { + You("sense a faint wave of psychic energy."); + goto toofar; + } + pline("A wave of psychic energy pours over you!"); + if (mtmp->mpeaceful + && (!Conflict || resist(mtmp, RING_CLASS, 0, 0))) { + pline("It feels quite soothing."); + } else if (!u.uinvulnerable) { + register boolean m_sen = sensemon(mtmp); - if (m_sen || (Blind_telepat && rn2(2)) || !rn2(10)) { - int dmg; - pline("It locks on to your %s!", - m_sen ? "telepathy" : - Blind_telepat ? "latent telepathy" : "mind"); - dmg = rnd(15); - if (Half_spell_damage) dmg = (dmg+1) / 2; - losehp(dmg, "psychic blast", KILLED_BY_AN); - } - } - for(m2=fmon; m2; m2 = nmon) { - nmon = m2->nmon; - if (DEADMONSTER(m2)) continue; - if (m2->mpeaceful == mtmp->mpeaceful) continue; - if (mindless(m2->data)) continue; - if (m2 == mtmp) continue; - if ((telepathic(m2->data) && - (rn2(2) || m2->mblinded)) || !rn2(10)) { - if (cansee(m2->mx, m2->my)) - pline("It locks on to %s.", mon_nam(m2)); - m2->mhp -= rnd(15); - if (m2->mhp <= 0) - monkilled(m2, "", AD_DRIN); - else - m2->msleeping = 0; - } - } - } + if (m_sen || (Blind_telepat && rn2(2)) || !rn2(10)) { + int dmg; + pline("It locks on to your %s!", + m_sen ? "telepathy" : Blind_telepat ? "latent telepathy" + : "mind"); + dmg = rnd(15); + if (Half_spell_damage) + dmg = (dmg + 1) / 2; + losehp(dmg, "psychic blast", KILLED_BY_AN); + } + } + for (m2 = fmon; m2; m2 = nmon) { + nmon = m2->nmon; + if (DEADMONSTER(m2)) + continue; + if (m2->mpeaceful == mtmp->mpeaceful) + continue; + if (mindless(m2->data)) + continue; + if (m2 == mtmp) + continue; + if ((telepathic(m2->data) && (rn2(2) || m2->mblinded)) + || !rn2(10)) { + if (cansee(m2->mx, m2->my)) + pline("It locks on to %s.", mon_nam(m2)); + m2->mhp -= rnd(15); + if (m2->mhp <= 0) + monkilled(m2, "", AD_DRIN); + else + m2->msleeping = 0; + } + } + } toofar: - /* If monster is nearby you, and has to wield a weapon, do so. This - * costs the monster a move, of course. - */ - if((!mtmp->mpeaceful || Conflict) && inrange && - dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8 - && attacktype(mdat, AT_WEAP)) { - struct obj *mw_tmp; + /* If monster is nearby you, and has to wield a weapon, do so. This + * costs the monster a move, of course. + */ + if ((!mtmp->mpeaceful || Conflict) && inrange + && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8 + && attacktype(mdat, AT_WEAP)) { + struct obj *mw_tmp; - /* The scared check is necessary. Otherwise a monster that is - * one square near the player but fleeing into a wall would keep - * switching between pick-axe and weapon. If monster is stuck - * in a trap, prefer ranged weapon (wielding is done in thrwmu). - * This may cost the monster an attack, but keeps the monster - * from switching back and forth if carrying both. - */ - mw_tmp = MON_WEP(mtmp); - if (!(scared && mw_tmp && is_pick(mw_tmp)) && - mtmp->weapon_check == NEED_WEAPON && - !(mtmp->mtrapped && !nearby && select_rwep(mtmp))) { - mtmp->weapon_check = NEED_HTH_WEAPON; - if (mon_wield_item(mtmp) != 0) return(0); - } - } + /* The scared check is necessary. Otherwise a monster that is + * one square near the player but fleeing into a wall would keep + * switching between pick-axe and weapon. If monster is stuck + * in a trap, prefer ranged weapon (wielding is done in thrwmu). + * This may cost the monster an attack, but keeps the monster + * from switching back and forth if carrying both. + */ + mw_tmp = MON_WEP(mtmp); + if (!(scared && mw_tmp && is_pick(mw_tmp)) + && mtmp->weapon_check == NEED_WEAPON + && !(mtmp->mtrapped && !nearby && select_rwep(mtmp))) { + mtmp->weapon_check = NEED_HTH_WEAPON; + if (mon_wield_item(mtmp) != 0) + return (0); + } + } -/* Now the actual movement phase */ + /* Now the actual movement phase */ - if(!nearby || mtmp->mflee || scared || - mtmp->mconf || mtmp->mstun || (mtmp->minvis && !rn2(3)) || - (mdat->mlet == S_LEPRECHAUN && - !findgold(invent) && (findgold(mtmp->minvent) || rn2(2))) || - (is_wanderer(mdat) && !rn2(4)) || (Conflict && !mtmp->iswiz) || - (!mtmp->mcansee && !rn2(4)) || mtmp->mpeaceful) { - /* Possibly cast an undirected spell if not attacking you */ - /* note that most of the time castmu() will pick a directed - spell and do nothing, so the monster moves normally */ - /* arbitrary distance restriction to keep monster far away - from you from having cast dozens of sticks-to-snakes - or similar spells by the time you reach it */ - if (dist2(mtmp->mx, mtmp->my, u.ux, u.uy) <= 49 && !mtmp->mspec_used) { - struct attack *a; + if (!nearby || mtmp->mflee || scared || mtmp->mconf || mtmp->mstun + || (mtmp->minvis && !rn2(3)) + || (mdat->mlet == S_LEPRECHAUN && !findgold(invent) + && (findgold(mtmp->minvent) || rn2(2))) + || (is_wanderer(mdat) && !rn2(4)) || (Conflict && !mtmp->iswiz) + || (!mtmp->mcansee && !rn2(4)) || mtmp->mpeaceful) { + /* Possibly cast an undirected spell if not attacking you */ + /* note that most of the time castmu() will pick a directed + spell and do nothing, so the monster moves normally */ + /* arbitrary distance restriction to keep monster far away + from you from having cast dozens of sticks-to-snakes + or similar spells by the time you reach it */ + if (dist2(mtmp->mx, mtmp->my, u.ux, u.uy) <= 49 + && !mtmp->mspec_used) { + struct attack *a; - for (a = &mdat->mattk[0]; a < &mdat->mattk[NATTK]; a++) { - if (a->aatyp == AT_MAGC && (a->adtyp == AD_SPEL || a->adtyp == AD_CLRC)) { - if (castmu(mtmp, a, FALSE, FALSE)) { - tmp = 3; - break; - } - } - } - } + for (a = &mdat->mattk[0]; a < &mdat->mattk[NATTK]; a++) { + if (a->aatyp == AT_MAGC + && (a->adtyp == AD_SPEL || a->adtyp == AD_CLRC)) { + if (castmu(mtmp, a, FALSE, FALSE)) { + tmp = 3; + break; + } + } + } + } - tmp = m_move(mtmp, 0); - if (tmp != 2) - distfleeck(mtmp, &inrange, &nearby, &scared); /* recalc */ + tmp = m_move(mtmp, 0); + if (tmp != 2) + distfleeck(mtmp, &inrange, &nearby, &scared); /* recalc */ - switch (tmp) { - case 0: /* no movement, but it can still attack you */ - case 3: /* absolutely no movement */ - /* for pets, case 0 and 3 are equivalent */ - /* vault guard might have vanished */ - if (mtmp->isgd && (mtmp->mhp < 1 || - (mtmp->mx == 0 && mtmp->my == 0))) - return 1; /* behave as if it died */ - /* During hallucination, monster appearance should - * still change - even if it doesn't move. - */ - if(Hallucination) newsym(mtmp->mx,mtmp->my); - break; - case 1: /* monster moved */ - /* Maybe it stepped on a trap and fell asleep... */ - if (mtmp->msleeping || !mtmp->mcanmove) return(0); - /* Monsters can move and then shoot on same turn; - our hero can't. Is that fair? */ - if (!nearby && - (ranged_attk(mdat) || find_offensive(mtmp))) - break; - /* engulfer/grabber checks */ - if (mtmp == u.ustuck) { - /* a monster that's digesting you can move at the - * same time -dlc - */ - if (u.uswallow) return mattacku(mtmp); - /* if confused grabber has wandered off, let go */ - if (distu(mtmp->mx, mtmp->my) > 2) unstuck(mtmp); - } - return(0); - case 2: /* monster died */ - return(1); - } - } + switch (tmp) { + case 0: /* no movement, but it can still attack you */ + case 3: /* absolutely no movement */ + /* for pets, case 0 and 3 are equivalent */ + /* vault guard might have vanished */ + if (mtmp->isgd + && (mtmp->mhp < 1 || (mtmp->mx == 0 && mtmp->my == 0))) + return 1; /* behave as if it died */ + /* During hallucination, monster appearance should + * still change - even if it doesn't move. + */ + if (Hallucination) + newsym(mtmp->mx, mtmp->my); + break; + case 1: /* monster moved */ + /* Maybe it stepped on a trap and fell asleep... */ + if (mtmp->msleeping || !mtmp->mcanmove) + return (0); + /* Monsters can move and then shoot on same turn; + our hero can't. Is that fair? */ + if (!nearby && (ranged_attk(mdat) || find_offensive(mtmp))) + break; + /* engulfer/grabber checks */ + if (mtmp == u.ustuck) { + /* a monster that's digesting you can move at the + * same time -dlc + */ + if (u.uswallow) + return mattacku(mtmp); + /* if confused grabber has wandered off, let go */ + if (distu(mtmp->mx, mtmp->my) > 2) + unstuck(mtmp); + } + return (0); + case 2: /* monster died */ + return (1); + } + } -/* Now, attack the player if possible - one attack set per monst */ + /* Now, attack the player if possible - one attack set per monst */ - if (!mtmp->mpeaceful || - (Conflict && !resist(mtmp, RING_CLASS, 0, 0))) { - if(inrange && !noattacks(mdat) && u.uhp > 0 && !scared && tmp != 3) - if(mattacku(mtmp)) return(1); /* monster died (e.g. exploded) */ + if (!mtmp->mpeaceful || (Conflict && !resist(mtmp, RING_CLASS, 0, 0))) { + if (inrange && !noattacks(mdat) && u.uhp > 0 && !scared && tmp != 3) + if (mattacku(mtmp)) + return (1); /* monster died (e.g. exploded) */ - if(mtmp->wormno) wormhitu(mtmp); - } - /* special speeches for quest monsters */ - if (!mtmp->msleeping && mtmp->mcanmove && nearby) - quest_talk(mtmp); - /* extra emotional attack for vile monsters */ - if (inrange && mtmp->data->msound == MS_CUSS && !mtmp->mpeaceful && - couldsee(mtmp->mx, mtmp->my) && !mtmp->minvis && !rn2(5)) - cuss(mtmp); + if (mtmp->wormno) + wormhitu(mtmp); + } + /* special speeches for quest monsters */ + if (!mtmp->msleeping && mtmp->mcanmove && nearby) + quest_talk(mtmp); + /* extra emotional attack for vile monsters */ + if (inrange && mtmp->data->msound == MS_CUSS && !mtmp->mpeaceful + && couldsee(mtmp->mx, mtmp->my) && !mtmp->minvis && !rn2(5)) + cuss(mtmp); - return(tmp == 2); + return (tmp == 2); } -static NEARDATA const char practical[] = { WEAPON_CLASS, ARMOR_CLASS, GEM_CLASS, FOOD_CLASS, 0 }; -static NEARDATA const char magical[] = { - AMULET_CLASS, POTION_CLASS, SCROLL_CLASS, WAND_CLASS, RING_CLASS, - SPBOOK_CLASS, 0 }; +static NEARDATA const char practical[] = { WEAPON_CLASS, ARMOR_CLASS, + GEM_CLASS, FOOD_CLASS, 0 }; +static NEARDATA const char magical[] = { AMULET_CLASS, POTION_CLASS, + SCROLL_CLASS, WAND_CLASS, + RING_CLASS, SPBOOK_CLASS, + 0 }; static NEARDATA const char indigestion[] = { BALL_CLASS, ROCK_CLASS, 0 }; static NEARDATA const char boulder_class[] = { ROCK_CLASS, 0 }; static NEARDATA const char gem_class[] = { GEM_CLASS, 0 }; @@ -614,11 +640,11 @@ boolean itsstuck(mtmp) register struct monst *mtmp; { - if (sticks(youmonst.data) && mtmp==u.ustuck && !u.uswallow) { - pline("%s cannot escape from you!", Monnam(mtmp)); - return(TRUE); - } - return(FALSE); + if (sticks(youmonst.data) && mtmp == u.ustuck && !u.uswallow) { + pline("%s cannot escape from you!", Monnam(mtmp)); + return (TRUE); + } + return (FALSE); } /* @@ -631,38 +657,38 @@ register struct monst *mtmp; boolean should_displace(mtmp, poss, info, cnt, gx, gy) struct monst *mtmp; -coord *poss; /* coord poss[9] */ -long *info; /* long info[9] */ +coord *poss; /* coord poss[9] */ +long *info; /* long info[9] */ int cnt; xchar gx, gy; { - int shortest_with_displacing = -1; - int shortest_without_displacing = -1; - int count_without_displacing = 0; - register int i, nx, ny; - int ndist; + int shortest_with_displacing = -1; + int shortest_without_displacing = -1; + int count_without_displacing = 0; + register int i, nx, ny; + int ndist; - for (i = 0; i < cnt; i++) { - nx = poss[i].x; ny = poss[i].y; - ndist = dist2(nx,ny,gx,gy); - if (MON_AT(nx,ny) && - (info[i] & ALLOW_MDISP) && !(info[i] & ALLOW_M) && - !undesirable_disp(mtmp,nx,ny)) { - if (shortest_with_displacing == -1 || - (ndist < shortest_with_displacing)) - shortest_with_displacing = ndist; - } else { - if ((shortest_without_displacing == -1) || - (ndist < shortest_without_displacing)) - shortest_without_displacing = ndist; - count_without_displacing++; - } + for (i = 0; i < cnt; i++) { + nx = poss[i].x; + ny = poss[i].y; + ndist = dist2(nx, ny, gx, gy); + if (MON_AT(nx, ny) && (info[i] & ALLOW_MDISP) && !(info[i] & ALLOW_M) + && !undesirable_disp(mtmp, nx, ny)) { + if (shortest_with_displacing == -1 + || (ndist < shortest_with_displacing)) + shortest_with_displacing = ndist; + } else { + if ((shortest_without_displacing == -1) + || (ndist < shortest_without_displacing)) + shortest_without_displacing = ndist; + count_without_displacing++; } - if (shortest_with_displacing > -1 && - (shortest_with_displacing < shortest_without_displacing || - !count_without_displacing)) - return TRUE; - return FALSE; + } + if (shortest_with_displacing > -1 + && (shortest_with_displacing < shortest_without_displacing + || !count_without_displacing)) + return TRUE; + return FALSE; } /* Return values: @@ -676,650 +702,713 @@ m_move(mtmp, after) register struct monst *mtmp; register int after; { - register int appr; - xchar gx,gy,nix,niy,chcnt; - int chi; /* could be schar except for stupid Sun-2 compiler */ - boolean likegold=0, likegems=0, likeobjs=0, likemagic=0, conceals=0; - boolean likerock=0, can_tunnel=0; - boolean can_open=0, can_unlock=0, doorbuster=0; - boolean uses_items=0, setlikes=0; - boolean avoid=FALSE; - boolean better_with_displacing = FALSE; - struct permonst *ptr; - struct monst *mtoo; - schar mmoved = 0; /* not strictly nec.: chi >= 0 will do */ - long info[9]; - long flag; - int omx = mtmp->mx, omy = mtmp->my; - struct obj *mw_tmp; + register int appr; + xchar gx, gy, nix, niy, chcnt; + int chi; /* could be schar except for stupid Sun-2 compiler */ + boolean likegold = 0, likegems = 0, likeobjs = 0, likemagic = 0, + conceals = 0; + boolean likerock = 0, can_tunnel = 0; + boolean can_open = 0, can_unlock = 0, doorbuster = 0; + boolean uses_items = 0, setlikes = 0; + boolean avoid = FALSE; + boolean better_with_displacing = FALSE; + struct permonst *ptr; + struct monst *mtoo; + schar mmoved = 0; /* not strictly nec.: chi >= 0 will do */ + long info[9]; + long flag; + int omx = mtmp->mx, omy = mtmp->my; + struct obj *mw_tmp; - if(mtmp->mtrapped) { - int i = mintrap(mtmp); - if(i >= 2) { newsym(mtmp->mx,mtmp->my); return(2); }/* it died */ - if(i == 1) return(0); /* still in trap, so didn't move */ - } - ptr = mtmp->data; /* mintrap() can change mtmp->data -dlc */ + if (mtmp->mtrapped) { + int i = mintrap(mtmp); + if (i >= 2) { + newsym(mtmp->mx, mtmp->my); + return (2); + } /* it died */ + if (i == 1) + return (0); /* still in trap, so didn't move */ + } + ptr = mtmp->data; /* mintrap() can change mtmp->data -dlc */ - if (mtmp->meating) { - mtmp->meating--; - if (mtmp->meating <= 0) finish_meating(mtmp); - return 3; /* still eating */ - } - if (hides_under(ptr) && OBJ_AT(mtmp->mx, mtmp->my) && rn2(10)) - return 0; /* do not leave hiding place */ + if (mtmp->meating) { + mtmp->meating--; + if (mtmp->meating <= 0) + finish_meating(mtmp); + return 3; /* still eating */ + } + if (hides_under(ptr) && OBJ_AT(mtmp->mx, mtmp->my) && rn2(10)) + return 0; /* do not leave hiding place */ - set_apparxy(mtmp); - /* where does mtmp think you are? */ - /* Not necessary if m_move called from this file, but necessary in - * other calls of m_move (ex. leprechauns dodging) - */ - if (!Is_rogue_level(&u.uz)) - can_tunnel = tunnels(ptr); - can_open = !(nohands(ptr) || verysmall(ptr)); - can_unlock = ((can_open && monhaskey(mtmp, TRUE)) || - mtmp->iswiz || is_rider(ptr)); - doorbuster = is_giant(ptr); - if(mtmp->wormno) goto not_special; - /* my dog gets special treatment */ - if(mtmp->mtame) { - mmoved = dog_move(mtmp, after); - goto postmov; - } + set_apparxy(mtmp); + /* where does mtmp think you are? */ + /* Not necessary if m_move called from this file, but necessary in + * other calls of m_move (ex. leprechauns dodging) + */ + if (!Is_rogue_level(&u.uz)) + can_tunnel = tunnels(ptr); + can_open = !(nohands(ptr) || verysmall(ptr)); + can_unlock = + ((can_open && monhaskey(mtmp, TRUE)) || mtmp->iswiz || is_rider(ptr)); + doorbuster = is_giant(ptr); + if (mtmp->wormno) + goto not_special; + /* my dog gets special treatment */ + if (mtmp->mtame) { + mmoved = dog_move(mtmp, after); + goto postmov; + } - /* likewise for shopkeeper */ - if(mtmp->isshk) { - mmoved = shk_move(mtmp); - if(mmoved == -2) return(2); - if(mmoved >= 0) goto postmov; - mmoved = 0; /* follow player outside shop */ - } + /* likewise for shopkeeper */ + if (mtmp->isshk) { + mmoved = shk_move(mtmp); + if (mmoved == -2) + return (2); + if (mmoved >= 0) + goto postmov; + mmoved = 0; /* follow player outside shop */ + } - /* and for the guard */ - if(mtmp->isgd) { - mmoved = gd_move(mtmp); - if(mmoved == -2) return(2); - if(mmoved >= 0) goto postmov; - mmoved = 0; - } + /* and for the guard */ + if (mtmp->isgd) { + mmoved = gd_move(mtmp); + if (mmoved == -2) + return (2); + if (mmoved >= 0) + goto postmov; + mmoved = 0; + } - /* and the acquisitive monsters get special treatment */ - if(is_covetous(ptr)) { - xchar tx = STRAT_GOALX(mtmp->mstrategy), - ty = STRAT_GOALY(mtmp->mstrategy); - struct monst *intruder = m_at(tx, ty); - /* - * if there's a monster on the object or in possesion of it, - * attack it. - */ - if((dist2(mtmp->mx, mtmp->my, tx, ty) < 2) && - intruder && (intruder != mtmp)) { + /* and the acquisitive monsters get special treatment */ + if (is_covetous(ptr)) { + xchar tx = STRAT_GOALX(mtmp->mstrategy), + ty = STRAT_GOALY(mtmp->mstrategy); + struct monst *intruder = m_at(tx, ty); + /* + * if there's a monster on the object or in possesion of it, + * attack it. + */ + if ((dist2(mtmp->mx, mtmp->my, tx, ty) < 2) && intruder + && (intruder != mtmp)) { + notonhead = (intruder->mx != tx || intruder->my != ty); + if (mattackm(mtmp, intruder) == 2) + return (2); + mmoved = 1; + } else + mmoved = 0; + goto postmov; + } - notonhead = (intruder->mx != tx || intruder->my != ty); - if(mattackm(mtmp, intruder) == 2) return(2); - mmoved = 1; - } else mmoved = 0; - goto postmov; - } - - /* and for the priest */ - if(mtmp->ispriest) { - mmoved = pri_move(mtmp); - if(mmoved == -2) return(2); - if(mmoved >= 0) goto postmov; - mmoved = 0; - } + /* and for the priest */ + if (mtmp->ispriest) { + mmoved = pri_move(mtmp); + if (mmoved == -2) + return (2); + if (mmoved >= 0) + goto postmov; + mmoved = 0; + } #ifdef MAIL - if(ptr == &mons[PM_MAIL_DAEMON]) { - if(!Deaf && canseemon(mtmp)) - verbalize("I'm late!"); - mongone(mtmp); - return(2); - } + if (ptr == &mons[PM_MAIL_DAEMON]) { + if (!Deaf && canseemon(mtmp)) + verbalize("I'm late!"); + mongone(mtmp); + return (2); + } #endif - /* teleport if that lies in our nature */ - if(ptr == &mons[PM_TENGU] && !rn2(5) && !mtmp->mcan && - !tele_restrict(mtmp)) { - if(mtmp->mhp < 7 || mtmp->mpeaceful || rn2(2)) - (void) rloc(mtmp, FALSE); - else - mnexto(mtmp); - mmoved = 1; - goto postmov; - } + /* teleport if that lies in our nature */ + if (ptr == &mons[PM_TENGU] && !rn2(5) && !mtmp->mcan + && !tele_restrict(mtmp)) { + if (mtmp->mhp < 7 || mtmp->mpeaceful || rn2(2)) + (void) rloc(mtmp, FALSE); + else + mnexto(mtmp); + mmoved = 1; + goto postmov; + } not_special: - if(u.uswallow && !mtmp->mflee && u.ustuck != mtmp) return(1); - omx = mtmp->mx; - omy = mtmp->my; - gx = mtmp->mux; - gy = mtmp->muy; - appr = mtmp->mflee ? -1 : 1; - if (mtmp->mconf || (u.uswallow && mtmp == u.ustuck)) - appr = 0; - else { - struct obj *lepgold, *ygold; - boolean should_see = (couldsee(omx, omy) && - (levl[gx][gy].lit || - !levl[omx][omy].lit) && - (dist2(omx, omy, gx, gy) <= 36)); + if (u.uswallow && !mtmp->mflee && u.ustuck != mtmp) + return (1); + omx = mtmp->mx; + omy = mtmp->my; + gx = mtmp->mux; + gy = mtmp->muy; + appr = mtmp->mflee ? -1 : 1; + if (mtmp->mconf || (u.uswallow && mtmp == u.ustuck)) + appr = 0; + else { + struct obj *lepgold, *ygold; + boolean should_see = + (couldsee(omx, omy) && (levl[gx][gy].lit || !levl[omx][omy].lit) + && (dist2(omx, omy, gx, gy) <= 36)); - if (!mtmp->mcansee || - (should_see && Invis && !perceives(ptr) && rn2(11)) || - (youmonst.m_ap_type == M_AP_OBJECT && youmonst.mappearance == STRANGE_OBJECT) || u.uundetected || - (youmonst.m_ap_type == M_AP_OBJECT && youmonst.mappearance == GOLD_PIECE && !likes_gold(ptr)) || - (mtmp->mpeaceful && !mtmp->isshk) || /* allow shks to follow */ - ((monsndx(ptr) == PM_STALKER || ptr->mlet == S_BAT || - ptr->mlet == S_LIGHT) && !rn2(3))) - appr = 0; + if (!mtmp->mcansee + || (should_see && Invis && !perceives(ptr) && rn2(11)) + || (youmonst.m_ap_type == M_AP_OBJECT + && youmonst.mappearance == STRANGE_OBJECT) || u.uundetected + || (youmonst.m_ap_type == M_AP_OBJECT + && youmonst.mappearance == GOLD_PIECE && !likes_gold(ptr)) + || (mtmp->mpeaceful && !mtmp->isshk) || /* allow shks to follow */ + ((monsndx(ptr) == PM_STALKER || ptr->mlet == S_BAT + || ptr->mlet == S_LIGHT) && !rn2(3))) + appr = 0; - if(monsndx(ptr) == PM_LEPRECHAUN && (appr == 1) && - ( (lepgold = findgold(mtmp->minvent)) && - (lepgold->quan > ((ygold = findgold(invent)) ? ygold->quan : 0L)) )) - appr = -1; + if (monsndx(ptr) == PM_LEPRECHAUN && (appr == 1) + && ((lepgold = findgold(mtmp->minvent)) + && (lepgold->quan + > ((ygold = findgold(invent)) ? ygold->quan : 0L)))) + appr = -1; - if (!should_see && can_track(ptr)) { - register coord *cp; + if (!should_see && can_track(ptr)) { + register coord *cp; - cp = gettrack(omx,omy); - if (cp) { - gx = cp->x; - gy = cp->y; - } - } - } + cp = gettrack(omx, omy); + if (cp) { + gx = cp->x; + gy = cp->y; + } + } + } - if ((!mtmp->mpeaceful || !rn2(10)) && (!Is_rogue_level(&u.uz))) { - boolean in_line = lined_up(mtmp) && - (distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= - (throws_rocks(youmonst.data) ? 20 : ACURRSTR/2+1) - ); + if ((!mtmp->mpeaceful || !rn2(10)) && (!Is_rogue_level(&u.uz))) { + boolean in_line = + lined_up(mtmp) + && (distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) + <= (throws_rocks(youmonst.data) ? 20 : ACURRSTR / 2 + 1)); - if (appr != 1 || !in_line) { - /* Monsters in combat won't pick stuff up, avoiding the - * situation where you toss arrows at it and it has nothing - * better to do than pick the arrows up. - */ - register int pctload = (curr_mon_load(mtmp) * 100) / - max_mon_load(mtmp); + if (appr != 1 || !in_line) { + /* Monsters in combat won't pick stuff up, avoiding the + * situation where you toss arrows at it and it has nothing + * better to do than pick the arrows up. + */ + register int pctload = + (curr_mon_load(mtmp) * 100) / max_mon_load(mtmp); - /* look for gold or jewels nearby */ - likegold = (likes_gold(ptr) && pctload < 95); - likegems = (likes_gems(ptr) && pctload < 85); - uses_items = (!mindless(ptr) && !is_animal(ptr) - && pctload < 75); - likeobjs = (likes_objs(ptr) && pctload < 75); - likemagic = (likes_magic(ptr) && pctload < 85); - likerock = (throws_rocks(ptr) && pctload < 50 && !Sokoban); - conceals = hides_under(ptr); - setlikes = TRUE; - } - } + /* look for gold or jewels nearby */ + likegold = (likes_gold(ptr) && pctload < 95); + likegems = (likes_gems(ptr) && pctload < 85); + uses_items = (!mindless(ptr) && !is_animal(ptr) && pctload < 75); + likeobjs = (likes_objs(ptr) && pctload < 75); + likemagic = (likes_magic(ptr) && pctload < 85); + likerock = (throws_rocks(ptr) && pctload < 50 && !Sokoban); + conceals = hides_under(ptr); + setlikes = TRUE; + } + } -#define SQSRCHRADIUS 5 +#define SQSRCHRADIUS 5 - { register int minr = SQSRCHRADIUS; /* not too far away */ - register struct obj *otmp; - register int xx, yy; - int oomx, oomy, lmx, lmy; + { + register int minr = SQSRCHRADIUS; /* not too far away */ + register struct obj *otmp; + register int xx, yy; + int oomx, oomy, lmx, lmy; - /* cut down the search radius if it thinks character is closer. */ - if(distmin(mtmp->mux, mtmp->muy, omx, omy) < SQSRCHRADIUS && - !mtmp->mpeaceful) minr--; - /* guards shouldn't get too distracted */ - if(!mtmp->mpeaceful && is_mercenary(ptr)) minr = 1; + /* cut down the search radius if it thinks character is closer. */ + if (distmin(mtmp->mux, mtmp->muy, omx, omy) < SQSRCHRADIUS + && !mtmp->mpeaceful) + minr--; + /* guards shouldn't get too distracted */ + if (!mtmp->mpeaceful && is_mercenary(ptr)) + minr = 1; - if((likegold || likegems || likeobjs || likemagic || likerock || conceals) - && (!*in_rooms(omx, omy, SHOPBASE) || (!rn2(25) && !mtmp->isshk))) { - look_for_obj: - oomx = min(COLNO-1, omx+minr); - oomy = min(ROWNO-1, omy+minr); - lmx = max(1, omx-minr); - lmy = max(0, omy-minr); - for(otmp = fobj; otmp; otmp = otmp->nobj) { - /* monsters may pick rocks up, but won't go out of their way - to grab them; this might hamper sling wielders, but it cuts - down on move overhead by filtering out most common item */ - if (otmp->otyp == ROCK) continue; - xx = otmp->ox; - yy = otmp->oy; - /* Nymphs take everything. Most other creatures should not - * pick up corpses except as a special case like in - * searches_for_item(). We need to do this check in - * mpickstuff() as well. - */ - if(xx >= lmx && xx <= oomx && yy >= lmy && yy <= oomy) { - /* don't get stuck circling around an object that's underneath - an immobile or hidden monster; paralysis victims excluded */ - if ((mtoo = m_at(xx,yy)) != 0 && - (mtoo->msleeping || mtoo->mundetected || - (mtoo->mappearance && !mtoo->iswiz) || - !mtoo->data->mmove)) continue; + if ((likegold || likegems || likeobjs || likemagic || likerock + || conceals) && (!*in_rooms(omx, omy, SHOPBASE) + || (!rn2(25) && !mtmp->isshk))) { + look_for_obj: + oomx = min(COLNO - 1, omx + minr); + oomy = min(ROWNO - 1, omy + minr); + lmx = max(1, omx - minr); + lmy = max(0, omy - minr); + for (otmp = fobj; otmp; otmp = otmp->nobj) { + /* monsters may pick rocks up, but won't go out of their way + to grab them; this might hamper sling wielders, but it cuts + down on move overhead by filtering out most common item */ + if (otmp->otyp == ROCK) + continue; + xx = otmp->ox; + yy = otmp->oy; + /* Nymphs take everything. Most other creatures should not + * pick up corpses except as a special case like in + * searches_for_item(). We need to do this check in + * mpickstuff() as well. + */ + if (xx >= lmx && xx <= oomx && yy >= lmy && yy <= oomy) { + /* don't get stuck circling around an object that's + underneath + an immobile or hidden monster; paralysis victims + excluded */ + if ((mtoo = m_at(xx, yy)) != 0 + && (mtoo->msleeping || mtoo->mundetected + || (mtoo->mappearance && !mtoo->iswiz) + || !mtoo->data->mmove)) + continue; - if(((likegold && otmp->oclass == COIN_CLASS) || - (likeobjs && index(practical, otmp->oclass) && - (otmp->otyp != CORPSE || (ptr->mlet == S_NYMPH - && !is_rider(&mons[otmp->corpsenm])))) || - (likemagic && index(magical, otmp->oclass)) || - (uses_items && searches_for_item(mtmp, otmp)) || - (likerock && otmp->otyp == BOULDER) || - (likegems && otmp->oclass == GEM_CLASS && - objects[otmp->otyp].oc_material != MINERAL) || - (conceals && !cansee(otmp->ox,otmp->oy)) || - (ptr == &mons[PM_GELATINOUS_CUBE] && - !index(indigestion, otmp->oclass) && - !(otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm]))) - ) && touch_artifact(otmp,mtmp)) { - if(can_carry(mtmp,otmp) && - (throws_rocks(ptr) || - !sobj_at(BOULDER,xx,yy)) && - (!is_unicorn(ptr) || - objects[otmp->otyp].oc_material == GEMSTONE) && - /* Don't get stuck circling an Elbereth */ - !(onscary(xx, yy, mtmp))) { - minr = distmin(omx,omy,xx,yy); - oomx = min(COLNO-1, omx+minr); - oomy = min(ROWNO-1, omy+minr); - lmx = max(1, omx-minr); - lmy = max(0, omy-minr); - gx = otmp->ox; - gy = otmp->oy; - if (gx == omx && gy == omy) { - mmoved = 3; /* actually unnecessary */ - goto postmov; - } - } - } - } - } - } else if(likegold) { - /* don't try to pick up anything else, but use the same loop */ - uses_items = 0; - likegems = likeobjs = likemagic = likerock = conceals = 0; - goto look_for_obj; - } + if (((likegold && otmp->oclass == COIN_CLASS) + || (likeobjs && index(practical, otmp->oclass) + && (otmp->otyp != CORPSE + || (ptr->mlet == S_NYMPH + && !is_rider(&mons[otmp->corpsenm])))) + || (likemagic && index(magical, otmp->oclass)) + || (uses_items && searches_for_item(mtmp, otmp)) + || (likerock && otmp->otyp == BOULDER) + || (likegems && otmp->oclass == GEM_CLASS + && objects[otmp->otyp].oc_material != MINERAL) + || (conceals && !cansee(otmp->ox, otmp->oy)) + || (ptr == &mons[PM_GELATINOUS_CUBE] + && !index(indigestion, otmp->oclass) + && !(otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm])))) + && touch_artifact(otmp, mtmp)) { + if (can_carry(mtmp, otmp) + && (throws_rocks(ptr) + || !sobj_at(BOULDER, xx, yy)) + && (!is_unicorn(ptr) + || objects[otmp->otyp].oc_material + == GEMSTONE) && + /* Don't get stuck circling an Elbereth */ + !(onscary(xx, yy, mtmp))) { + minr = distmin(omx, omy, xx, yy); + oomx = min(COLNO - 1, omx + minr); + oomy = min(ROWNO - 1, omy + minr); + lmx = max(1, omx - minr); + lmy = max(0, omy - minr); + gx = otmp->ox; + gy = otmp->oy; + if (gx == omx && gy == omy) { + mmoved = 3; /* actually unnecessary */ + goto postmov; + } + } + } + } + } + } else if (likegold) { + /* don't try to pick up anything else, but use the same loop */ + uses_items = 0; + likegems = likeobjs = likemagic = likerock = conceals = 0; + goto look_for_obj; + } - if(minr < SQSRCHRADIUS && appr == -1) { - if(distmin(omx,omy,mtmp->mux,mtmp->muy) <= 3) { - gx = mtmp->mux; - gy = mtmp->muy; - } else - appr = 1; - } - } + if (minr < SQSRCHRADIUS && appr == -1) { + if (distmin(omx, omy, mtmp->mux, mtmp->muy) <= 3) { + gx = mtmp->mux; + gy = mtmp->muy; + } else + appr = 1; + } + } - /* don't tunnel if hostile and close enough to prefer a weapon */ - if (can_tunnel && needspick(ptr) && - ((!mtmp->mpeaceful || Conflict) && - dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8)) - can_tunnel = FALSE; + /* don't tunnel if hostile and close enough to prefer a weapon */ + if (can_tunnel && needspick(ptr) + && ((!mtmp->mpeaceful || Conflict) + && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8)) + can_tunnel = FALSE; - nix = omx; - niy = omy; - flag = 0L; - if (mtmp->mpeaceful && (!Conflict || resist(mtmp, RING_CLASS, 0, 0))) - flag |= (ALLOW_SANCT | ALLOW_SSM); - else flag |= ALLOW_U; - if (is_minion(ptr) || is_rider(ptr)) flag |= ALLOW_SANCT; - /* unicorn may not be able to avoid hero on a noteleport level */ - if (is_unicorn(ptr) && !level.flags.noteleport) flag |= NOTONL; - if (passes_walls(ptr)) flag |= (ALLOW_WALL | ALLOW_ROCK); - if (passes_bars(ptr)) flag |= ALLOW_BARS; - if (can_tunnel) flag |= ALLOW_DIG; - if (is_human(ptr) || ptr == &mons[PM_MINOTAUR]) flag |= ALLOW_SSM; - if (is_undead(ptr) && ptr->mlet != S_GHOST) flag |= NOGARLIC; - if (is_vampshifter(mtmp)) flag |= NOGARLIC; - if (throws_rocks(ptr)) flag |= ALLOW_ROCK; - if (can_open) flag |= OPENDOOR; - if (can_unlock) flag |= UNLOCKDOOR; - if (doorbuster) flag |= BUSTDOOR; - { - register int i, j, nx, ny, nearer; - int jcnt, cnt; - int ndist, nidist; - register coord *mtrk; - coord poss[9]; + nix = omx; + niy = omy; + flag = 0L; + if (mtmp->mpeaceful && (!Conflict || resist(mtmp, RING_CLASS, 0, 0))) + flag |= (ALLOW_SANCT | ALLOW_SSM); + else + flag |= ALLOW_U; + if (is_minion(ptr) || is_rider(ptr)) + flag |= ALLOW_SANCT; + /* unicorn may not be able to avoid hero on a noteleport level */ + if (is_unicorn(ptr) && !level.flags.noteleport) + flag |= NOTONL; + if (passes_walls(ptr)) + flag |= (ALLOW_WALL | ALLOW_ROCK); + if (passes_bars(ptr)) + flag |= ALLOW_BARS; + if (can_tunnel) + flag |= ALLOW_DIG; + if (is_human(ptr) || ptr == &mons[PM_MINOTAUR]) + flag |= ALLOW_SSM; + if (is_undead(ptr) && ptr->mlet != S_GHOST) + flag |= NOGARLIC; + if (is_vampshifter(mtmp)) + flag |= NOGARLIC; + if (throws_rocks(ptr)) + flag |= ALLOW_ROCK; + if (can_open) + flag |= OPENDOOR; + if (can_unlock) + flag |= UNLOCKDOOR; + if (doorbuster) + flag |= BUSTDOOR; + { + register int i, j, nx, ny, nearer; + int jcnt, cnt; + int ndist, nidist; + register coord *mtrk; + coord poss[9]; - cnt = mfndpos(mtmp, poss, info, flag); - chcnt = 0; - jcnt = min(MTSZ, cnt-1); - chi = -1; - nidist = dist2(nix,niy,gx,gy); - /* allow monsters be shortsighted on some levels for balance */ - if(!mtmp->mpeaceful && level.flags.shortsighted && - nidist > (couldsee(nix,niy) ? 144 : 36) && appr == 1) appr = 0; - if (is_unicorn(ptr) && level.flags.noteleport) { - /* on noteleport levels, perhaps we cannot avoid hero */ - for(i = 0; i < cnt; i++) - if(!(info[i] & NOTONL)) avoid=TRUE; - } - better_with_displacing = should_displace(mtmp,poss,info,cnt,gx,gy); - for(i=0; i < cnt; i++) { - if (avoid && (info[i] & NOTONL)) continue; - nx = poss[i].x; - ny = poss[i].y; + cnt = mfndpos(mtmp, poss, info, flag); + chcnt = 0; + jcnt = min(MTSZ, cnt - 1); + chi = -1; + nidist = dist2(nix, niy, gx, gy); + /* allow monsters be shortsighted on some levels for balance */ + if (!mtmp->mpeaceful && level.flags.shortsighted + && nidist > (couldsee(nix, niy) ? 144 : 36) && appr == 1) + appr = 0; + if (is_unicorn(ptr) && level.flags.noteleport) { + /* on noteleport levels, perhaps we cannot avoid hero */ + for (i = 0; i < cnt; i++) + if (!(info[i] & NOTONL)) + avoid = TRUE; + } + better_with_displacing = + should_displace(mtmp, poss, info, cnt, gx, gy); + for (i = 0; i < cnt; i++) { + if (avoid && (info[i] & NOTONL)) + continue; + nx = poss[i].x; + ny = poss[i].y; - if (MON_AT(nx,ny) && - (info[i] & ALLOW_MDISP) && !(info[i] & ALLOW_M) && - !better_with_displacing) continue; - if (appr != 0) { - mtrk = &mtmp->mtrack[0]; - for(j=0; j < jcnt; mtrk++, j++) - if(nx == mtrk->x && ny == mtrk->y) - if(rn2(4*(cnt-j))) - goto nxti; - } + if (MON_AT(nx, ny) && (info[i] & ALLOW_MDISP) + && !(info[i] & ALLOW_M) && !better_with_displacing) + continue; + if (appr != 0) { + mtrk = &mtmp->mtrack[0]; + for (j = 0; j < jcnt; mtrk++, j++) + if (nx == mtrk->x && ny == mtrk->y) + if (rn2(4 * (cnt - j))) + goto nxti; + } - nearer = ((ndist = dist2(nx,ny,gx,gy)) < nidist); + nearer = ((ndist = dist2(nx, ny, gx, gy)) < nidist); - if((appr == 1 && nearer) || (appr == -1 && !nearer) || - (!appr && !rn2(++chcnt)) || !mmoved) { - nix = nx; - niy = ny; - nidist = ndist; - chi = i; - mmoved = 1; - } - nxti: ; - } - } + if ((appr == 1 && nearer) || (appr == -1 && !nearer) + || (!appr && !rn2(++chcnt)) || !mmoved) { + nix = nx; + niy = ny; + nidist = ndist; + chi = i; + mmoved = 1; + } + nxti: + ; + } + } - if(mmoved) { - register int j; + if (mmoved) { + register int j; - if (mmoved==1 && (u.ux != nix || u.uy != niy) && itsstuck(mtmp)) - return(3); + if (mmoved == 1 && (u.ux != nix || u.uy != niy) && itsstuck(mtmp)) + return (3); - if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix,niy)) || - closed_door(nix, niy)) && - mmoved==1 && can_tunnel && needspick(ptr)) { - if (closed_door(nix, niy)) { - if (!(mw_tmp = MON_WEP(mtmp)) || - !is_pick(mw_tmp) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_PICK_OR_AXE; - } else if (IS_TREE(levl[nix][niy].typ)) { - if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) - mtmp->weapon_check = NEED_AXE; - } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { - mtmp->weapon_check = NEED_PICK_AXE; - } - if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) - return(3); - } - /* If ALLOW_U is set, either it's trying to attack you, or it - * thinks it is. In either case, attack this spot in preference to - * all others. - */ - /* Actually, this whole section of code doesn't work as you'd expect. - * Most attacks are handled in dochug(). It calls distfleeck(), which - * among other things sets nearby if the monster is near you--and if - * nearby is set, we never call m_move unless it is a special case - * (confused, stun, etc.) The effect is that this ALLOW_U (and - * mfndpos) has no effect for normal attacks, though it lets a confused - * monster attack you by accident. - */ - if(info[chi] & ALLOW_U) { - nix = mtmp->mux; - niy = mtmp->muy; - } - if (nix == u.ux && niy == u.uy) { - mtmp->mux = u.ux; - mtmp->muy = u.uy; - return(0); - } - /* The monster may attack another based on 1 of 2 conditions: - * 1 - It may be confused. - * 2 - It may mistake the monster for your (displaced) image. - * Pets get taken care of above and shouldn't reach this code. - * Conflict gets handled even farther away (movemon()). - */ - if((info[chi] & ALLOW_M) || - (nix == mtmp->mux && niy == mtmp->muy)) { - struct monst *mtmp2; - int mstatus; - mtmp2 = m_at(nix,niy); + if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix, niy)) + || closed_door(nix, niy)) && mmoved == 1 + && can_tunnel && needspick(ptr)) { + if (closed_door(nix, niy)) { + if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp) + || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_PICK_OR_AXE; + } else if (IS_TREE(levl[nix][niy].typ)) { + if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp)) + mtmp->weapon_check = NEED_AXE; + } else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) { + mtmp->weapon_check = NEED_PICK_AXE; + } + if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp)) + return (3); + } + /* If ALLOW_U is set, either it's trying to attack you, or it + * thinks it is. In either case, attack this spot in preference to + * all others. + */ + /* Actually, this whole section of code doesn't work as you'd expect. + * Most attacks are handled in dochug(). It calls distfleeck(), which + * among other things sets nearby if the monster is near you--and if + * nearby is set, we never call m_move unless it is a special case + * (confused, stun, etc.) The effect is that this ALLOW_U (and + * mfndpos) has no effect for normal attacks, though it lets a + * confused + * monster attack you by accident. + */ + if (info[chi] & ALLOW_U) { + nix = mtmp->mux; + niy = mtmp->muy; + } + if (nix == u.ux && niy == u.uy) { + mtmp->mux = u.ux; + mtmp->muy = u.uy; + return (0); + } + /* The monster may attack another based on 1 of 2 conditions: + * 1 - It may be confused. + * 2 - It may mistake the monster for your (displaced) image. + * Pets get taken care of above and shouldn't reach this code. + * Conflict gets handled even farther away (movemon()). + */ + if ((info[chi] & ALLOW_M) || (nix == mtmp->mux && niy == mtmp->muy)) { + struct monst *mtmp2; + int mstatus; + mtmp2 = m_at(nix, niy); - notonhead = mtmp2 && (nix != mtmp2->mx || niy != mtmp2->my); - /* note: mstatus returns 0 if mtmp2 is nonexistent */ - mstatus = mattackm(mtmp, mtmp2); + notonhead = mtmp2 && (nix != mtmp2->mx || niy != mtmp2->my); + /* note: mstatus returns 0 if mtmp2 is nonexistent */ + mstatus = mattackm(mtmp, mtmp2); - if (mstatus & MM_AGR_DIED) /* aggressor died */ - return 2; + if (mstatus & MM_AGR_DIED) /* aggressor died */ + return 2; - if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED) && - rn2(4) && mtmp2->movement >= NORMAL_SPEED) { - mtmp2->movement -= NORMAL_SPEED; - notonhead = 0; - mstatus = mattackm(mtmp2, mtmp); /* return attack */ - if (mstatus & MM_DEF_DIED) - return 2; - } - return 3; - } + if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED) && rn2(4) + && mtmp2->movement >= NORMAL_SPEED) { + mtmp2->movement -= NORMAL_SPEED; + notonhead = 0; + mstatus = mattackm(mtmp2, mtmp); /* return attack */ + if (mstatus & MM_DEF_DIED) + return 2; + } + return 3; + } - if((info[chi] & ALLOW_MDISP)) { - struct monst *mtmp2; - int mstatus; - mtmp2 = m_at(nix,niy); - mstatus = mdisplacem(mtmp, mtmp2, FALSE); - if ((mstatus & MM_AGR_DIED) || (mstatus & MM_DEF_DIED)) - return 2; - if (mstatus & MM_HIT) return 1; - return 3; - } + if ((info[chi] & ALLOW_MDISP)) { + struct monst *mtmp2; + int mstatus; + mtmp2 = m_at(nix, niy); + mstatus = mdisplacem(mtmp, mtmp2, FALSE); + if ((mstatus & MM_AGR_DIED) || (mstatus & MM_DEF_DIED)) + return 2; + if (mstatus & MM_HIT) + return 1; + return 3; + } - if (!m_in_out_region(mtmp,nix,niy)) - return 3; - remove_monster(omx, omy); - place_monster(mtmp, nix, niy); - for(j = MTSZ-1; j > 0; j--) - mtmp->mtrack[j] = mtmp->mtrack[j-1]; - mtmp->mtrack[0].x = omx; - mtmp->mtrack[0].y = omy; - /* Place a segment at the old position. */ - if (mtmp->wormno) worm_move(mtmp); - } else { - if(is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) { - (void) rloc(mtmp, FALSE); - return(1); - } - if(mtmp->wormno) worm_nomove(mtmp); - } + if (!m_in_out_region(mtmp, nix, niy)) + return 3; + remove_monster(omx, omy); + place_monster(mtmp, nix, niy); + for (j = MTSZ - 1; j > 0; j--) + mtmp->mtrack[j] = mtmp->mtrack[j - 1]; + mtmp->mtrack[0].x = omx; + mtmp->mtrack[0].y = omy; + /* Place a segment at the old position. */ + if (mtmp->wormno) + worm_move(mtmp); + } else { + if (is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) { + (void) rloc(mtmp, FALSE); + return (1); + } + if (mtmp->wormno) + worm_nomove(mtmp); + } postmov: - if(mmoved == 1 || mmoved == 3) { - boolean canseeit = cansee(mtmp->mx, mtmp->my); + if (mmoved == 1 || mmoved == 3) { + boolean canseeit = cansee(mtmp->mx, mtmp->my); - if(mmoved == 1) { - newsym(omx,omy); /* update the old position */ - if (mintrap(mtmp) >= 2) { - if(mtmp->mx) newsym(mtmp->mx,mtmp->my); - return(2); /* it died */ - } - ptr = mtmp->data; + if (mmoved == 1) { + newsym(omx, omy); /* update the old position */ + if (mintrap(mtmp) >= 2) { + if (mtmp->mx) + newsym(mtmp->mx, mtmp->my); + return (2); /* it died */ + } + ptr = mtmp->data; - /* open a door, or crash through it, if you can */ - if(IS_DOOR(levl[mtmp->mx][mtmp->my].typ) - && !passes_walls(ptr) /* doesn't need to open doors */ - && !can_tunnel /* taken care of below */ - ) { - struct rm *here = &levl[mtmp->mx][mtmp->my]; - boolean btrapped = (here->doormask & D_TRAPPED), - observeit = canseeit && canspotmon(mtmp); + /* open a door, or crash through it, if you can */ + if (IS_DOOR(levl[mtmp->mx][mtmp->my].typ) + && !passes_walls(ptr) /* doesn't need to open doors */ + && !can_tunnel /* taken care of below */ + ) { + struct rm *here = &levl[mtmp->mx][mtmp->my]; + boolean btrapped = (here->doormask & D_TRAPPED), + observeit = canseeit && canspotmon(mtmp); - if(here->doormask & (D_LOCKED|D_CLOSED) && - (amorphous(ptr) || (!amorphous(ptr) && can_fog(mtmp) && - vamp_shift(mtmp, &mons[PM_FOG_CLOUD])))) { - if (flags.verbose && canseemon(mtmp)) - pline("%s %s under the door.", Monnam(mtmp), - (ptr == &mons[PM_FOG_CLOUD] || - ptr == &mons[PM_YELLOW_LIGHT]) - ? "flows" : "oozes"); - } else if(here->doormask & D_LOCKED && can_unlock) { - if(btrapped) { - here->doormask = D_NODOOR; - newsym(mtmp->mx, mtmp->my); - unblock_point(mtmp->mx,mtmp->my); /* vision */ - if(mb_trapped(mtmp)) return(2); - } else { - if (flags.verbose) { - if (observeit) - pline("%s unlocks and opens a door.", - Monnam(mtmp)); - else if (canseeit) - You_see("a door unlock and open."); - else if (!Deaf) - You_hear("a door unlock and open."); - } - here->doormask = D_ISOPEN; - /* newsym(mtmp->mx, mtmp->my); */ - unblock_point(mtmp->mx,mtmp->my); /* vision */ - } - } else if (here->doormask == D_CLOSED && can_open) { - if(btrapped) { - here->doormask = D_NODOOR; - newsym(mtmp->mx, mtmp->my); - unblock_point(mtmp->mx,mtmp->my); /* vision */ - if(mb_trapped(mtmp)) return(2); - } else { - if (flags.verbose) { - if (observeit) - pline("%s opens a door.", Monnam(mtmp)); - else if (canseeit) - You_see("a door open."); - else if (!Deaf) - You_hear("a door open."); - } - here->doormask = D_ISOPEN; - /* newsym(mtmp->mx, mtmp->my); */ /* done below */ - unblock_point(mtmp->mx,mtmp->my); /* vision */ - } - } else if (here->doormask & (D_LOCKED|D_CLOSED)) { - /* mfndpos guarantees this must be a doorbuster */ - if(btrapped) { - here->doormask = D_NODOOR; - newsym(mtmp->mx, mtmp->my); - unblock_point(mtmp->mx,mtmp->my); /* vision */ - if(mb_trapped(mtmp)) return(2); - } else { - if (flags.verbose) { - if (observeit) - pline("%s smashes down a door.", - Monnam(mtmp)); - else if (canseeit) - You_see("a door crash open."); - else if (!Deaf) - You_hear("a door crash open."); - } - if (here->doormask & D_LOCKED && !rn2(2)) - here->doormask = D_NODOOR; - else here->doormask = D_BROKEN; - /* newsym(mtmp->mx, mtmp->my); */ /* done below */ - unblock_point(mtmp->mx,mtmp->my); /* vision */ - } - /* if it's a shop door, schedule repair */ - if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) - add_damage(mtmp->mx, mtmp->my, 0L); - } - } else if (levl[mtmp->mx][mtmp->my].typ == IRONBARS) { - if (may_dig(mtmp->mx,mtmp->my) && - (dmgtype(ptr, AD_RUST) || dmgtype(ptr, AD_CORR))) { - if (canseemon(mtmp)) - pline("%s eats through the iron bars.", - Monnam(mtmp)); - dissolve_bars(mtmp->mx, mtmp->my); - return(3); - } else if (flags.verbose && canseemon(mtmp)) - Norep("%s %s %s the iron bars.", Monnam(mtmp), - /* pluralization fakes verb conjugation */ - makeplural(locomotion(ptr, "pass")), - passes_walls(ptr) ? "through" : "between"); - } + if (here->doormask & (D_LOCKED | D_CLOSED) + && (amorphous(ptr) + || (!amorphous(ptr) && can_fog(mtmp) + && vamp_shift(mtmp, &mons[PM_FOG_CLOUD])))) { + if (flags.verbose && canseemon(mtmp)) + pline("%s %s under the door.", Monnam(mtmp), + (ptr == &mons[PM_FOG_CLOUD] + || ptr == &mons[PM_YELLOW_LIGHT]) + ? "flows" + : "oozes"); + } else if (here->doormask & D_LOCKED && can_unlock) { + if (btrapped) { + here->doormask = D_NODOOR; + newsym(mtmp->mx, mtmp->my); + unblock_point(mtmp->mx, mtmp->my); /* vision */ + if (mb_trapped(mtmp)) + return (2); + } else { + if (flags.verbose) { + if (observeit) + pline("%s unlocks and opens a door.", + Monnam(mtmp)); + else if (canseeit) + You_see("a door unlock and open."); + else if (!Deaf) + You_hear("a door unlock and open."); + } + here->doormask = D_ISOPEN; + /* newsym(mtmp->mx, mtmp->my); */ + unblock_point(mtmp->mx, mtmp->my); /* vision */ + } + } else if (here->doormask == D_CLOSED && can_open) { + if (btrapped) { + here->doormask = D_NODOOR; + newsym(mtmp->mx, mtmp->my); + unblock_point(mtmp->mx, mtmp->my); /* vision */ + if (mb_trapped(mtmp)) + return (2); + } else { + if (flags.verbose) { + if (observeit) + pline("%s opens a door.", Monnam(mtmp)); + else if (canseeit) + You_see("a door open."); + else if (!Deaf) + You_hear("a door open."); + } + here->doormask = D_ISOPEN; + /* newsym(mtmp->mx, mtmp->my); */ /* done below */ + unblock_point(mtmp->mx, mtmp->my); /* vision */ + } + } else if (here->doormask & (D_LOCKED | D_CLOSED)) { + /* mfndpos guarantees this must be a doorbuster */ + if (btrapped) { + here->doormask = D_NODOOR; + newsym(mtmp->mx, mtmp->my); + unblock_point(mtmp->mx, mtmp->my); /* vision */ + if (mb_trapped(mtmp)) + return (2); + } else { + if (flags.verbose) { + if (observeit) + pline("%s smashes down a door.", + Monnam(mtmp)); + else if (canseeit) + You_see("a door crash open."); + else if (!Deaf) + You_hear("a door crash open."); + } + if (here->doormask & D_LOCKED && !rn2(2)) + here->doormask = D_NODOOR; + else + here->doormask = D_BROKEN; + /* newsym(mtmp->mx, mtmp->my); */ /* done below */ + unblock_point(mtmp->mx, mtmp->my); /* vision */ + } + /* if it's a shop door, schedule repair */ + if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) + add_damage(mtmp->mx, mtmp->my, 0L); + } + } else if (levl[mtmp->mx][mtmp->my].typ == IRONBARS) { + if (may_dig(mtmp->mx, mtmp->my) + && (dmgtype(ptr, AD_RUST) || dmgtype(ptr, AD_CORR))) { + if (canseemon(mtmp)) + pline("%s eats through the iron bars.", Monnam(mtmp)); + dissolve_bars(mtmp->mx, mtmp->my); + return (3); + } else if (flags.verbose && canseemon(mtmp)) + Norep("%s %s %s the iron bars.", Monnam(mtmp), + /* pluralization fakes verb conjugation */ + makeplural(locomotion(ptr, "pass")), + passes_walls(ptr) ? "through" : "between"); + } - /* possibly dig */ - if (can_tunnel && mdig_tunnel(mtmp)) - return(2); /* mon died (position already updated) */ + /* possibly dig */ + if (can_tunnel && mdig_tunnel(mtmp)) + return (2); /* mon died (position already updated) */ - /* set also in domove(), hack.c */ - if (u.uswallow && mtmp == u.ustuck && - (mtmp->mx != omx || mtmp->my != omy)) { - /* If the monster moved, then update */ - u.ux0 = u.ux; - u.uy0 = u.uy; - u.ux = mtmp->mx; - u.uy = mtmp->my; - swallowed(0); - } else - newsym(mtmp->mx,mtmp->my); - } - if(OBJ_AT(mtmp->mx, mtmp->my) && mtmp->mcanmove) { - /* recompute the likes tests, in case we polymorphed - * or if the "likegold" case got taken above */ - if (setlikes) { - register int pctload = (curr_mon_load(mtmp) * 100) / - max_mon_load(mtmp); + /* set also in domove(), hack.c */ + if (u.uswallow && mtmp == u.ustuck + && (mtmp->mx != omx || mtmp->my != omy)) { + /* If the monster moved, then update */ + u.ux0 = u.ux; + u.uy0 = u.uy; + u.ux = mtmp->mx; + u.uy = mtmp->my; + swallowed(0); + } else + newsym(mtmp->mx, mtmp->my); + } + if (OBJ_AT(mtmp->mx, mtmp->my) && mtmp->mcanmove) { + /* recompute the likes tests, in case we polymorphed + * or if the "likegold" case got taken above */ + if (setlikes) { + register int pctload = + (curr_mon_load(mtmp) * 100) / max_mon_load(mtmp); - /* look for gold or jewels nearby */ - likegold = (likes_gold(ptr) && pctload < 95); - likegems = (likes_gems(ptr) && pctload < 85); - uses_items = (!mindless(ptr) && !is_animal(ptr) - && pctload < 75); - likeobjs = (likes_objs(ptr) && pctload < 75); - likemagic = (likes_magic(ptr) && pctload < 85); - likerock = (throws_rocks(ptr) && pctload < 50 && !Sokoban); - conceals = hides_under(ptr); - } + /* look for gold or jewels nearby */ + likegold = (likes_gold(ptr) && pctload < 95); + likegems = (likes_gems(ptr) && pctload < 85); + uses_items = + (!mindless(ptr) && !is_animal(ptr) && pctload < 75); + likeobjs = (likes_objs(ptr) && pctload < 75); + likemagic = (likes_magic(ptr) && pctload < 85); + likerock = (throws_rocks(ptr) && pctload < 50 && !Sokoban); + conceals = hides_under(ptr); + } - /* Maybe a rock mole just ate some metal object */ - if (metallivorous(ptr)) { - if (meatmetal(mtmp) == 2) return 2; /* it died */ - } + /* Maybe a rock mole just ate some metal object */ + if (metallivorous(ptr)) { + if (meatmetal(mtmp) == 2) + return 2; /* it died */ + } - if(g_at(mtmp->mx,mtmp->my) && likegold) mpickgold(mtmp); + if (g_at(mtmp->mx, mtmp->my) && likegold) + mpickgold(mtmp); - /* Maybe a cube ate just about anything */ - if (ptr == &mons[PM_GELATINOUS_CUBE]) { - if (meatobj(mtmp) == 2) return 2; /* it died */ - } + /* Maybe a cube ate just about anything */ + if (ptr == &mons[PM_GELATINOUS_CUBE]) { + if (meatobj(mtmp) == 2) + return 2; /* it died */ + } - if(!*in_rooms(mtmp->mx, mtmp->my, SHOPBASE) || !rn2(25)) { - boolean picked = FALSE; + if (!*in_rooms(mtmp->mx, mtmp->my, SHOPBASE) || !rn2(25)) { + boolean picked = FALSE; - if(likeobjs) picked |= mpickstuff(mtmp, practical); - if(likemagic) picked |= mpickstuff(mtmp, magical); - if(likerock) picked |= mpickstuff(mtmp, boulder_class); - if(likegems) picked |= mpickstuff(mtmp, gem_class); - if(uses_items) picked |= mpickstuff(mtmp, (char *)0); - if(picked) mmoved = 3; - } + if (likeobjs) + picked |= mpickstuff(mtmp, practical); + if (likemagic) + picked |= mpickstuff(mtmp, magical); + if (likerock) + picked |= mpickstuff(mtmp, boulder_class); + if (likegems) + picked |= mpickstuff(mtmp, gem_class); + if (uses_items) + picked |= mpickstuff(mtmp, (char *) 0); + if (picked) + mmoved = 3; + } - if(mtmp->minvis) { - newsym(mtmp->mx, mtmp->my); - if (mtmp->wormno) see_wsegs(mtmp); - } - } + if (mtmp->minvis) { + newsym(mtmp->mx, mtmp->my); + if (mtmp->wormno) + see_wsegs(mtmp); + } + } - if(hides_under(ptr) || ptr->mlet == S_EEL) { - /* Always set--or reset--mundetected if it's already hidden - (just in case the object it was hiding under went away); - usually set mundetected unless monster can't move. */ - if (mtmp->mundetected || - (mtmp->mcanmove && !mtmp->msleeping && rn2(5))) - (void) hideunder(mtmp); - newsym(mtmp->mx, mtmp->my); - } - if (mtmp->isshk) { - after_shk_move(mtmp); - } - } - return(mmoved); + if (hides_under(ptr) || ptr->mlet == S_EEL) { + /* Always set--or reset--mundetected if it's already hidden + (just in case the object it was hiding under went away); + usually set mundetected unless monster can't move. */ + if (mtmp->mundetected + || (mtmp->mcanmove && !mtmp->msleeping && rn2(5))) + (void) hideunder(mtmp); + newsym(mtmp->mx, mtmp->my); + } + if (mtmp->isshk) { + after_shk_move(mtmp); + } + } + return (mmoved); } void dissolve_bars(x, y) register int x, y; { - levl[x][y].typ = (Is_special(&u.uz) || *in_rooms(x,y,0)) ? ROOM : CORR; + levl[x][y].typ = (Is_special(&u.uz) || *in_rooms(x, y, 0)) ? ROOM : CORR; newsym(x, y); } @@ -1327,21 +1416,21 @@ boolean closed_door(x, y) register int x, y; { - return((boolean)(IS_DOOR(levl[x][y].typ) && - (levl[x][y].doormask & (D_LOCKED | D_CLOSED)))); + return ((boolean)(IS_DOOR(levl[x][y].typ) + && (levl[x][y].doormask & (D_LOCKED | D_CLOSED)))); } boolean accessible(x, y) register int x, y; { - int levtyp = levl[x][y].typ; + int levtyp = levl[x][y].typ; - /* use underlying terrain in front of closed drawbridge */ - if (levtyp == DRAWBRIDGE_UP) - levtyp = db_under_typ(levl[x][y].drawbridgemask); + /* use underlying terrain in front of closed drawbridge */ + if (levtyp == DRAWBRIDGE_UP) + levtyp = db_under_typ(levl[x][y].drawbridgemask); - return (boolean)(ACCESSIBLE(levtyp) && !closed_door(x, y)); + return (boolean)(ACCESSIBLE(levtyp) && !closed_door(x, y)); } /* decide where the monster thinks you are standing */ @@ -1349,66 +1438,70 @@ void set_apparxy(mtmp) register struct monst *mtmp; { - boolean notseen, gotu; - register int disp, mx = mtmp->mux, my = mtmp->muy; - long umoney = money_cnt(invent); + boolean notseen, gotu; + register int disp, mx = mtmp->mux, my = mtmp->muy; + long umoney = money_cnt(invent); - /* - * do cheapest and/or most likely tests first - */ + /* + * do cheapest and/or most likely tests first + */ - /* pet knows your smell; grabber still has hold of you */ - if (mtmp->mtame || mtmp == u.ustuck) goto found_you; + /* pet knows your smell; grabber still has hold of you */ + if (mtmp->mtame || mtmp == u.ustuck) + goto found_you; - /* monsters which know where you are don't suddenly forget, - if you haven't moved away */ - if (mx == u.ux && my == u.uy) goto found_you; + /* monsters which know where you are don't suddenly forget, + if you haven't moved away */ + if (mx == u.ux && my == u.uy) + goto found_you; - notseen = (!mtmp->mcansee || (Invis && !perceives(mtmp->data))); - /* add cases as required. eg. Displacement ... */ - if (notseen || Underwater) { - /* Xorns can smell quantities of valuable metal - like that in solid gold coins, treat as seen */ - if ((mtmp->data == &mons[PM_XORN]) && umoney && !Underwater) - disp = 0; - else - disp = 1; - } else if (Displaced) { - disp = couldsee(mx, my) ? 2 : 1; - } else disp = 0; - if (!disp) goto found_you; + notseen = (!mtmp->mcansee || (Invis && !perceives(mtmp->data))); + /* add cases as required. eg. Displacement ... */ + if (notseen || Underwater) { + /* Xorns can smell quantities of valuable metal + like that in solid gold coins, treat as seen */ + if ((mtmp->data == &mons[PM_XORN]) && umoney && !Underwater) + disp = 0; + else + disp = 1; + } else if (Displaced) { + disp = couldsee(mx, my) ? 2 : 1; + } else + disp = 0; + if (!disp) + goto found_you; - /* without something like the following, invis. and displ. - are too powerful */ - gotu = notseen ? !rn2(3) : Displaced ? !rn2(4) : FALSE; + /* without something like the following, invis. and displ. + are too powerful */ + gotu = notseen ? !rn2(3) : Displaced ? !rn2(4) : FALSE; -#if 0 /* this never worked as intended & isn't needed anyway */ +#if 0 /* this never worked as intended & isn't needed anyway */ /* If invis but not displaced, staying around gets you 'discovered' */ gotu |= (!Displaced && u.dx == 0 && u.dy == 0); #endif - if (!gotu) { - register int try_cnt = 0; - do { - if (++try_cnt > 200) goto found_you; /* punt */ - mx = u.ux - disp + rn2(2*disp+1); - my = u.uy - disp + rn2(2*disp+1); - } while (!isok(mx,my) - || (disp != 2 && mx == mtmp->mx && my == mtmp->my) - || ((mx != u.ux || my != u.uy) && - !passes_walls(mtmp->data) && - !(accessible(mx, my) || - (closed_door(mx, my) && - (can_ooze(mtmp) || can_fog(mtmp))))) - || !couldsee(mx, my)); - } else { -found_you: - mx = u.ux; - my = u.uy; - } + if (!gotu) { + register int try_cnt = 0; + do { + if (++try_cnt > 200) + goto found_you; /* punt */ + mx = u.ux - disp + rn2(2 * disp + 1); + my = u.uy - disp + rn2(2 * disp + 1); + } while (!isok(mx, my) + || (disp != 2 && mx == mtmp->mx && my == mtmp->my) + || ((mx != u.ux || my != u.uy) && !passes_walls(mtmp->data) + && !(accessible(mx, my) + || (closed_door(mx, my) + && (can_ooze(mtmp) || can_fog(mtmp))))) + || !couldsee(mx, my)); + } else { + found_you: + mx = u.ux; + my = u.uy; + } - mtmp->mux = mx; - mtmp->muy = my; + mtmp->mux = mx; + mtmp->muy = my; } /* @@ -1422,25 +1515,25 @@ found_you: boolean undesirable_disp(mtmp, x, y) struct monst *mtmp; -xchar x,y; +xchar x, y; { - boolean is_pet = (mtmp && mtmp->mtame && !mtmp->isminion); - struct trap *trap = t_at(x,y); + boolean is_pet = (mtmp && mtmp->mtame && !mtmp->isminion); + struct trap *trap = t_at(x, y); - if (is_pet) { - /* Pets avoid a trap if you've seen it usually. */ - if (trap && trap->tseen && rn2(40)) - return TRUE; - /* Pets avoid cursed locations */ - if (cursed_object_at(x,y)) - return TRUE; - } - /* Monsters avoid a trap if they've seen that type before */ - else if (trap && rn2(40) && - (mtmp->mtrapseen & (1 << (trap->ttyp -1))) != 0) - return TRUE; + if (is_pet) { + /* Pets avoid a trap if you've seen it usually. */ + if (trap && trap->tseen && rn2(40)) + return TRUE; + /* Pets avoid cursed locations */ + if (cursed_object_at(x, y)) + return TRUE; + } + /* Monsters avoid a trap if they've seen that type before */ + else if (trap && rn2(40) + && (mtmp->mtrapseen & (1 << (trap->ttyp - 1))) != 0) + return TRUE; - return FALSE; + return FALSE; } /* @@ -1451,52 +1544,47 @@ STATIC_OVL boolean stuff_prevents_passage(mtmp) struct monst *mtmp; { - struct obj *chain, *obj; + struct obj *chain, *obj; - if (mtmp == &youmonst) { - chain = invent; - } else { - chain = mtmp->minvent; - } - for (obj = chain; obj; obj = obj->nobj) { - int typ = obj->otyp; + if (mtmp == &youmonst) { + chain = invent; + } else { + chain = mtmp->minvent; + } + for (obj = chain; obj; obj = obj->nobj) { + int typ = obj->otyp; - if (typ == COIN_CLASS && obj->quan > 100L) return TRUE; - if (obj->oclass != GEM_CLASS && - !(typ >= ARROW && typ <= BOOMERANG) && - !(typ >= DAGGER && typ <= CRYSKNIFE) && - typ != SLING && - !is_cloak(obj) && typ != FEDORA && - !is_gloves(obj) && typ != LEATHER_JACKET && - typ != CREDIT_CARD && !is_shirt(obj) && - !(typ == CORPSE && verysmall(&mons[obj->corpsenm])) && - typ != FORTUNE_COOKIE && typ != CANDY_BAR && - typ != PANCAKE && typ != LEMBAS_WAFER && - typ != LUMP_OF_ROYAL_JELLY && - obj->oclass != AMULET_CLASS && - obj->oclass != RING_CLASS && - obj->oclass != VENOM_CLASS && - typ != SACK && typ != BAG_OF_HOLDING && - typ != BAG_OF_TRICKS && !Is_candle(obj) && - typ != OILSKIN_SACK && typ != LEASH && - typ != STETHOSCOPE && typ != BLINDFOLD && typ != TOWEL && - typ != TIN_WHISTLE && typ != MAGIC_WHISTLE && - typ != MAGIC_MARKER && typ != TIN_OPENER && - typ != SKELETON_KEY && typ != LOCK_PICK - ) return TRUE; - if (Is_container(obj) && obj->cobj) return TRUE; - } - return FALSE; + if (typ == COIN_CLASS && obj->quan > 100L) + return TRUE; + if (obj->oclass != GEM_CLASS && !(typ >= ARROW && typ <= BOOMERANG) + && !(typ >= DAGGER && typ <= CRYSKNIFE) && typ != SLING + && !is_cloak(obj) && typ != FEDORA && !is_gloves(obj) + && typ != LEATHER_JACKET && typ != CREDIT_CARD && !is_shirt(obj) + && !(typ == CORPSE && verysmall(&mons[obj->corpsenm])) + && typ != FORTUNE_COOKIE && typ != CANDY_BAR && typ != PANCAKE + && typ != LEMBAS_WAFER && typ != LUMP_OF_ROYAL_JELLY + && obj->oclass != AMULET_CLASS && obj->oclass != RING_CLASS + && obj->oclass != VENOM_CLASS && typ != SACK + && typ != BAG_OF_HOLDING && typ != BAG_OF_TRICKS + && !Is_candle(obj) && typ != OILSKIN_SACK && typ != LEASH + && typ != STETHOSCOPE && typ != BLINDFOLD && typ != TOWEL + && typ != TIN_WHISTLE && typ != MAGIC_WHISTLE + && typ != MAGIC_MARKER && typ != TIN_OPENER && typ != SKELETON_KEY + && typ != LOCK_PICK) + return TRUE; + if (Is_container(obj) && obj->cobj) + return TRUE; + } + return FALSE; } boolean can_ooze(mtmp) struct monst *mtmp; { - if (!amorphous(mtmp->data) || - stuff_prevents_passage(mtmp)) - return FALSE; - return TRUE; + if (!amorphous(mtmp->data) || stuff_prevents_passage(mtmp)) + return FALSE; + return TRUE; } /* monster can change form into a fog if necessary */ @@ -1504,27 +1592,27 @@ boolean can_fog(mtmp) struct monst *mtmp; { - if ((is_vampshifter(mtmp) || mtmp->data->mlet == S_VAMPIRE) && - !Protection_from_shape_changers && !stuff_prevents_passage(mtmp)) - return TRUE; - return FALSE; + if ((is_vampshifter(mtmp) || mtmp->data->mlet == S_VAMPIRE) + && !Protection_from_shape_changers && !stuff_prevents_passage(mtmp)) + return TRUE; + return FALSE; } STATIC_OVL int -vamp_shift(mon,ptr) +vamp_shift(mon, ptr) struct monst *mon; struct permonst *ptr; { - int reslt = 0; - if (mon->cham >= LOW_PM) { - if (ptr == &mons[mon->cham]) - mon->cham = NON_PM; - reslt = newcham(mon, ptr, FALSE, FALSE); - } else if (mon->cham == NON_PM && ptr != mon->data) { - mon->cham = monsndx(mon->data); - reslt = newcham(mon, ptr, FALSE, FALSE); - } - return reslt; + int reslt = 0; + if (mon->cham >= LOW_PM) { + if (ptr == &mons[mon->cham]) + mon->cham = NON_PM; + reslt = newcham(mon, ptr, FALSE, FALSE); + } else if (mon->cham == NON_PM && ptr != mon->data) { + mon->cham = monsndx(mon->data); + reslt = newcham(mon, ptr, FALSE, FALSE); + } + return reslt; } /*monmove.c*/ diff --git a/src/monst.c b/src/monst.c index 48cbeb160..8efc5206f 100644 --- a/src/monst.c +++ b/src/monst.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 monst.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 monst.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.50 $ */ /* NetHack 3.6 monst.c $Date: 2011/09/02 21:44:09 $ $Revision: 1.38 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,9 +7,12 @@ #include "permonst.h" #include "monsym.h" -#define NO_ATTK {0,0,0,0} +#define NO_ATTK \ + { \ + 0, 0, 0, 0 \ + } -#define WT_ELF 800 +#define WT_ELF 800 #define WT_DRAGON 4500 #ifdef C @@ -17,9 +20,9 @@ #endif #ifdef TEXTCOLOR #include "color.h" -#define C(color) color -#define HI_DOMESTIC CLR_WHITE /* use for player + friendlies */ -#define HI_LORD CLR_MAGENTA +#define C(color) color +#define HI_DOMESTIC CLR_WHITE /* use for player + friendlies */ +#define HI_LORD CLR_MAGENTA #else #define C(color) #endif @@ -38,15 +41,23 @@ void NDECL(monst_init); * 3 * flag bitmaps (M1_*, M2_*, and M3_* defines respectively) * symbol color (C(x) macro) */ -#define MON(nam,sym,lvl,gen,atk,siz,mr1,mr2,flg1,flg2,flg3,col) \ - {nam,sym,lvl,gen,atk,siz,mr1,mr2,flg1,flg2,flg3,C(col)} -/* LVL() and SIZ() collect several fields to cut down on # of args for MON() */ -#define LVL(lvl,mov,ac,mr,aln) lvl,mov,ac,mr,aln -#define SIZ(wt,nut,snd,siz) wt,nut,snd,siz +#define MON(nam, sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, col) \ + { \ + nam, sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, C(col) \ + } +/* LVL() and SIZ() collect several fields to cut down on # of args for MON() + */ +#define LVL(lvl, mov, ac, mr, aln) lvl, mov, ac, mr, aln +#define SIZ(wt, nut, snd, siz) wt, nut, snd, siz /* ATTK() and A() are to avoid braces and commas within args to MON() */ -#define ATTK(at,ad,n,d) {at,ad,n,d} -#define A(a1,a2,a3,a4,a5,a6) {a1,a2,a3,a4,a5,a6} - +#define ATTK(at, ad, n, d) \ + { \ + at, ad, n, d \ + } +#define A(a1, a2, a3, a4, a5, a6) \ + { \ + a1, a2, a3, a4, a5, a6 \ + } /* * Rule #1: monsters of a given class are contiguous in the @@ -88,263 +99,238 @@ void NDECL(monst_init); #ifndef SPLITMON_2 NEARDATA struct permonst mons[] = { -/* - * ants - */ - MON("giant ant", S_ANT, - LVL(2, 18, 3, 0, 0), (G_GENO|G_SGROUP|3), - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_BROWN), - MON("killer bee", S_ANT, - LVL(1, 18, -1, 0, 0), (G_GENO|G_LGROUP|2), - A(ATTK(AT_STNG, AD_DRST, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1, 5, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, - M1_ANIMAL|M1_FLY|M1_NOHANDS|M1_POIS, - M2_HOSTILE|M2_FEMALE, 0, CLR_YELLOW), - MON("soldier ant", S_ANT, - LVL(3, 18, 3, 0, 0), (G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_STNG, AD_DRST, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(20, 5, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, - M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_POIS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_BLUE), - MON("fire ant", S_ANT, - LVL(3, 18, 3, 10, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_BITE, AD_FIRE, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 10, MS_SILENT, MZ_TINY), MR_FIRE, MR_FIRE, - M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_CARNIVORE, - M2_HOSTILE, M3_INFRAVISIBLE, CLR_RED), - MON("giant beetle", S_ANT, - LVL(5, 6, 4, 0, 0), (G_GENO|3), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_LARGE), MR_POISON, MR_POISON, - M1_ANIMAL|M1_NOHANDS|M1_POIS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_BLACK), - MON("queen bee", S_ANT, - LVL(9, 24, -4, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_STNG, AD_DRST, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1, 5, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, - M1_ANIMAL|M1_FLY|M1_NOHANDS|M1_OVIPAROUS|M1_POIS, - M2_HOSTILE|M2_FEMALE|M2_PRINCE, 0, HI_LORD), -/* - * blobs - */ - MON("acid blob", S_BLOB, - LVL(1, 3, 8, 0, 0), (G_GENO|2), - A(ATTK(AT_NONE, AD_ACID, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 10, MS_SILENT, MZ_TINY), - MR_SLEEP|MR_POISON|MR_ACID|MR_STONE, MR_STONE, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_ACID, - M2_WANDER|M2_NEUTER, 0, CLR_GREEN), - MON("quivering blob", S_BLOB, - LVL(5, 1, 8, 0, 0), (G_GENO|2), - A(ATTK(AT_TUCH, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 100, MS_SILENT, MZ_SMALL), - MR_SLEEP|MR_POISON, MR_POISON, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS, - M2_WANDER|M2_HOSTILE|M2_NEUTER, 0, CLR_WHITE), - MON("gelatinous cube", S_BLOB, - LVL(6, 6, 8, 0, 0), (G_GENO|2), - A(ATTK(AT_TUCH, AD_PLYS, 2, 4), ATTK(AT_NONE, AD_PLYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 150, MS_SILENT, MZ_LARGE), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON|MR_ACID|MR_STONE, - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_OMNIVORE|M1_ACID, - M2_WANDER|M2_HOSTILE|M2_NEUTER, 0, CLR_CYAN), -/* - * cockatrice - */ - MON("chickatrice", S_COCKATRICE, - LVL(4, 4, 8, 30, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 2), ATTK(AT_TUCH, AD_STON, 0, 0), - ATTK(AT_NONE, AD_STON, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_HISS, MZ_TINY), - MR_POISON|MR_STONE, MR_POISON|MR_STONE, - M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE, M2_HOSTILE, - M3_INFRAVISIBLE, CLR_BROWN), - MON("cockatrice", S_COCKATRICE, - LVL(5, 6, 6, 30, 0), (G_GENO|5), - A(ATTK(AT_BITE, AD_PHYS, 1, 3), ATTK(AT_TUCH, AD_STON, 0, 0), - ATTK(AT_NONE, AD_STON, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_HISS, MZ_SMALL), - MR_POISON|MR_STONE, MR_POISON|MR_STONE, - M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE|M1_OVIPAROUS, M2_HOSTILE, - M3_INFRAVISIBLE, CLR_YELLOW), - MON("pyrolisk", S_COCKATRICE, - LVL(6, 6, 6, 30, 0), (G_GENO|1), - A(ATTK(AT_GAZE, AD_FIRE, 2, 6), NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_HISS, MZ_SMALL), - MR_POISON|MR_FIRE, MR_POISON|MR_FIRE, - M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE|M1_OVIPAROUS, M2_HOSTILE, - M3_INFRAVISIBLE, CLR_RED), -/* - * dogs & other canines - */ - MON("jackal", S_DOG, - LVL(0, 12, 7, 0, 0), (G_GENO|G_SGROUP|3), - A(ATTK(AT_BITE, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("fox", S_DOG, - LVL(0, 15, 7, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_RED), - MON("coyote", S_DOG, - LVL(1, 12, 7, 0, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("werejackal", S_DOG, - LVL(2, 12, 7, 10, -7), (G_NOGEN|G_NOCORPSE), - A(ATTK(AT_BITE, AD_WERE, 1, 4), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 250, MS_BARK, MZ_SMALL), MR_POISON, 0, - M1_NOHANDS|M1_POIS|M1_REGEN|M1_CARNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), - MON("little dog", S_DOG, - LVL(2, 18, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(150, 150, MS_BARK, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("dingo", S_DOG, - LVL(4, 16, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1 ,6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 200, MS_BARK, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_YELLOW), - MON("dog", S_DOG, - LVL(4, 16, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1 ,6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 200, MS_BARK, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("large dog", S_DOG, - LVL(6, 15, 4, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 250, MS_BARK, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_STRONG|M2_DOMESTIC, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("wolf", S_DOG, - LVL(5, 12, 4, 0, 0), (G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 250, MS_BARK, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("werewolf", S_DOG, - LVL(5, 12, 4, 20, -7), (G_NOGEN|G_NOCORPSE), - A(ATTK(AT_BITE, AD_WERE, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 250, MS_BARK, MZ_MEDIUM), MR_POISON, 0, - M1_NOHANDS|M1_POIS|M1_REGEN|M1_CARNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), - MON("winter wolf cub", S_DOG, - LVL(5, 12, 4, 0, -5), (G_NOHELL|G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 8), ATTK(AT_BREA, AD_COLD, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(250, 200, MS_BARK, MZ_SMALL), MR_COLD, MR_COLD, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, 0, CLR_CYAN), - MON("warg", S_DOG, - LVL(7, 12, 4, 0, -5), (G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(850, 350, MS_BARK, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("winter wolf", S_DOG, - LVL(7, 12, 4, 20, 0), (G_NOHELL|G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_BREA, AD_COLD, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(700, 300, MS_BARK, MZ_LARGE), MR_COLD, MR_COLD, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG, 0, CLR_CYAN), - MON("hell hound pup", S_DOG, - LVL(7, 12, 4, 20, -5), (G_HELL|G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_BREA, AD_FIRE, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 200, MS_BARK, MZ_SMALL), MR_FIRE, MR_FIRE, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_RED), - MON("hell hound", S_DOG, - LVL(12, 14, 2, 20, 0), (G_HELL|G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_BREA, AD_FIRE, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_BARK, MZ_MEDIUM), MR_FIRE, MR_FIRE, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE|M2_STRONG, - M3_INFRAVISIBLE, CLR_RED), + /* + * ants + */ + MON("giant ant", S_ANT, LVL(2, 18, 3, 0, 0), (G_GENO | G_SGROUP | 3), + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_CARNIVORE, M2_HOSTILE, 0, + CLR_BROWN), + MON("killer bee", S_ANT, LVL(1, 18, -1, 0, 0), (G_GENO | G_LGROUP | 2), + A(ATTK(AT_STNG, AD_DRST, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1, 5, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, + M1_ANIMAL | M1_FLY | M1_NOHANDS | M1_POIS, M2_HOSTILE | M2_FEMALE, 0, + CLR_YELLOW), + MON("soldier ant", S_ANT, LVL(3, 18, 3, 0, 0), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_STNG, AD_DRST, 3, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(20, 5, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, + M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_POIS | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_BLUE), + MON("fire ant", S_ANT, LVL(3, 18, 3, 10, 0), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_BITE, AD_FIRE, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(30, 10, MS_SILENT, MZ_TINY), MR_FIRE, MR_FIRE, + M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_CARNIVORE, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_RED), + MON("giant beetle", S_ANT, LVL(5, 6, 4, 0, 0), (G_GENO | 3), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_LARGE), MR_POISON, MR_POISON, + M1_ANIMAL | M1_NOHANDS | M1_POIS | M1_CARNIVORE, M2_HOSTILE, 0, + CLR_BLACK), + MON("queen bee", S_ANT, LVL(9, 24, -4, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_STNG, AD_DRST, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1, 5, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, + M1_ANIMAL | M1_FLY | M1_NOHANDS | M1_OVIPAROUS | M1_POIS, + M2_HOSTILE | M2_FEMALE | M2_PRINCE, 0, HI_LORD), + /* + * blobs + */ + MON("acid blob", S_BLOB, LVL(1, 3, 8, 0, 0), (G_GENO | 2), + A(ATTK(AT_NONE, AD_ACID, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 10, MS_SILENT, MZ_TINY), + MR_SLEEP | MR_POISON | MR_ACID | MR_STONE, MR_STONE, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_ACID, + M2_WANDER | M2_NEUTER, 0, CLR_GREEN), + MON("quivering blob", S_BLOB, LVL(5, 1, 8, 0, 0), (G_GENO | 2), + A(ATTK(AT_TUCH, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(200, 100, MS_SILENT, MZ_SMALL), MR_SLEEP | MR_POISON, MR_POISON, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS, + M2_WANDER | M2_HOSTILE | M2_NEUTER, 0, CLR_WHITE), + MON("gelatinous cube", S_BLOB, LVL(6, 6, 8, 0, 0), (G_GENO | 2), + A(ATTK(AT_TUCH, AD_PLYS, 2, 4), ATTK(AT_NONE, AD_PLYS, 1, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 150, MS_SILENT, MZ_LARGE), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON | MR_ACID + | MR_STONE, + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS | M1_OMNIVORE + | M1_ACID, + M2_WANDER | M2_HOSTILE | M2_NEUTER, 0, CLR_CYAN), + /* + * cockatrice + */ + MON("chickatrice", S_COCKATRICE, LVL(4, 4, 8, 30, 0), + (G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 2), ATTK(AT_TUCH, AD_STON, 0, 0), + ATTK(AT_NONE, AD_STON, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(10, 10, MS_HISS, MZ_TINY), MR_POISON | MR_STONE, + MR_POISON | MR_STONE, M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), + MON("cockatrice", S_COCKATRICE, LVL(5, 6, 6, 30, 0), (G_GENO | 5), + A(ATTK(AT_BITE, AD_PHYS, 1, 3), ATTK(AT_TUCH, AD_STON, 0, 0), + ATTK(AT_NONE, AD_STON, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(30, 30, MS_HISS, MZ_SMALL), MR_POISON | MR_STONE, + MR_POISON | MR_STONE, + M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE | M1_OVIPAROUS, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_YELLOW), + MON("pyrolisk", S_COCKATRICE, LVL(6, 6, 6, 30, 0), (G_GENO | 1), + A(ATTK(AT_GAZE, AD_FIRE, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_HISS, MZ_SMALL), MR_POISON | MR_FIRE, + MR_POISON | MR_FIRE, + M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE | M1_OVIPAROUS, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_RED), + /* + * dogs & other canines + */ + MON("jackal", S_DOG, LVL(0, 12, 7, 0, 0), (G_GENO | G_SGROUP | 3), + A(ATTK(AT_BITE, AD_PHYS, 1, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("fox", S_DOG, LVL(0, 15, 7, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_RED), + MON("coyote", S_DOG, LVL(1, 12, 7, 0, 0), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 250, MS_BARK, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("werejackal", S_DOG, LVL(2, 12, 7, 10, -7), (G_NOGEN | G_NOCORPSE), + A(ATTK(AT_BITE, AD_WERE, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 250, MS_BARK, MZ_SMALL), MR_POISON, 0, + M1_NOHANDS | M1_POIS | M1_REGEN | M1_CARNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), + MON("little dog", S_DOG, LVL(2, 18, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(150, 150, MS_BARK, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("dingo", S_DOG, LVL(4, 16, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 200, MS_BARK, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_YELLOW), + MON("dog", S_DOG, LVL(4, 16, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 200, MS_BARK, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("large dog", S_DOG, LVL(6, 15, 4, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(800, 250, MS_BARK, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_STRONG | M2_DOMESTIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("wolf", S_DOG, LVL(5, 12, 4, 0, 0), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 250, MS_BARK, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("werewolf", S_DOG, LVL(5, 12, 4, 20, -7), (G_NOGEN | G_NOCORPSE), + A(ATTK(AT_BITE, AD_WERE, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 250, MS_BARK, MZ_MEDIUM), MR_POISON, 0, + M1_NOHANDS | M1_POIS | M1_REGEN | M1_CARNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), + MON("winter wolf cub", S_DOG, LVL(5, 12, 4, 0, -5), + (G_NOHELL | G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 8), ATTK(AT_BREA, AD_COLD, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(250, 200, MS_BARK, MZ_SMALL), MR_COLD, MR_COLD, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, 0, CLR_CYAN), + MON("warg", S_DOG, LVL(7, 12, 4, 0, -5), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(850, 350, MS_BARK, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("winter wolf", S_DOG, LVL(7, 12, 4, 20, 0), (G_NOHELL | G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_BREA, AD_COLD, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(700, 300, MS_BARK, MZ_LARGE), MR_COLD, MR_COLD, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE | M2_STRONG, 0, + CLR_CYAN), + MON("hell hound pup", S_DOG, LVL(7, 12, 4, 20, -5), + (G_HELL | G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_BREA, AD_FIRE, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(200, 200, MS_BARK, MZ_SMALL), MR_FIRE, MR_FIRE, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_RED), + MON("hell hound", S_DOG, LVL(12, 14, 2, 20, 0), (G_HELL | G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_BREA, AD_FIRE, 3, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_BARK, MZ_MEDIUM), MR_FIRE, MR_FIRE, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE | M2_STRONG, + M3_INFRAVISIBLE, CLR_RED), #ifdef CHARON - MON("Cerberus", S_DOG, - LVL(12, 10, 2, 20, -7), (G_NOGEN|G_UNIQ|G_HELL), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_BITE, AD_PHYS, 3, 6), - ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 350, MS_BARK, MZ_LARGE), MR_FIRE, MR_FIRE, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_NOPOLY|M2_HOSTILE|M2_STRONG|M2_PNAME|M2_MALE, M3_INFRAVISIBLE, - CLR_RED), + MON("Cerberus", S_DOG, LVL(12, 10, 2, 20, -7), + (G_NOGEN | G_UNIQ | G_HELL), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_BITE, AD_PHYS, 3, 6), + ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1000, 350, MS_BARK, MZ_LARGE), MR_FIRE, MR_FIRE, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_NOPOLY | M2_HOSTILE | M2_STRONG | M2_PNAME | M2_MALE, + M3_INFRAVISIBLE, CLR_RED), #endif -/* - * eyes - */ - MON("gas spore", S_EYE, - LVL(1, 3, 10, 0, 0), (G_NOCORPSE|G_GENO|1), - A(ATTK(AT_BOOM, AD_PHYS, 4, 6), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_SMALL), 0, 0, - M1_FLY|M1_BREATHLESS|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS, - M2_HOSTILE|M2_NEUTER, 0, CLR_GRAY), - MON("floating eye", S_EYE, - LVL(2, 1, 9, 10, 0), (G_GENO|5), - A(ATTK(AT_NONE, AD_PLYS, 0,70), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_SMALL), 0, 0, - M1_FLY|M1_AMPHIBIOUS|M1_NOLIMBS|M1_NOHEAD|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_BLUE), - MON("freezing sphere", S_EYE, - LVL(6, 13, 4, 0, 0), (G_NOCORPSE|G_NOHELL|G_GENO|2), - A(ATTK(AT_EXPL, AD_COLD, 4, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_COLD, MR_COLD, - M1_FLY|M1_BREATHLESS|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_WHITE), - MON("flaming sphere", S_EYE, - LVL(6, 13, 4, 0, 0), (G_NOCORPSE|G_GENO|2), - A(ATTK(AT_EXPL, AD_FIRE, 4, 6), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_FIRE, MR_FIRE, - M1_FLY|M1_BREATHLESS|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_RED), - MON("shocking sphere", S_EYE, - LVL(6, 13, 4, 0, 0), (G_NOCORPSE|G_GENO|2), - A(ATTK(AT_EXPL, AD_ELEC, 4, 6), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_ELEC, MR_ELEC, - M1_FLY|M1_BREATHLESS|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, HI_ZAP), -#if 0 /* not yet implemented */ + /* + * eyes + */ + MON("gas spore", S_EYE, LVL(1, 3, 10, 0, 0), (G_NOCORPSE | G_GENO | 1), + A(ATTK(AT_BOOM, AD_PHYS, 4, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_SMALL), 0, 0, + M1_FLY | M1_BREATHLESS | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS, + M2_HOSTILE | M2_NEUTER, 0, CLR_GRAY), + MON("floating eye", S_EYE, LVL(2, 1, 9, 10, 0), (G_GENO | 5), + A(ATTK(AT_NONE, AD_PLYS, 0, 70), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_SMALL), 0, 0, + M1_FLY | M1_AMPHIBIOUS | M1_NOLIMBS | M1_NOHEAD | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_BLUE), + MON("freezing sphere", S_EYE, LVL(6, 13, 4, 0, 0), + (G_NOCORPSE | G_NOHELL | G_GENO | 2), + A(ATTK(AT_EXPL, AD_COLD, 4, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_COLD, MR_COLD, + M1_FLY | M1_BREATHLESS | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_WHITE), + MON("flaming sphere", S_EYE, LVL(6, 13, 4, 0, 0), + (G_NOCORPSE | G_GENO | 2), A(ATTK(AT_EXPL, AD_FIRE, 4, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_FIRE, MR_FIRE, + M1_FLY | M1_BREATHLESS | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_RED), + MON("shocking sphere", S_EYE, LVL(6, 13, 4, 0, 0), + (G_NOCORPSE | G_GENO | 2), A(ATTK(AT_EXPL, AD_ELEC, 4, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(10, 10, MS_SILENT, MZ_SMALL), MR_ELEC, MR_ELEC, + M1_FLY | M1_BREATHLESS | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, HI_ZAP), +#if 0 /* not yet implemented */ MON("beholder", S_EYE, LVL(6, 3, 4, 0, -10), (G_GENO|2), A(ATTK(AT_GAZE, AD_SLOW, 0, 0), ATTK(AT_GAZE, AD_SLEE, 2,25), @@ -354,849 +340,770 @@ NEARDATA struct permonst mons[] = { M1_FLY|M1_BREATHLESS|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS, M2_NOPOLY|M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_BROWN), #endif -/* - * felines - */ - MON("kitten", S_FELINE, - LVL(2, 18, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(150, 150, MS_MEW, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_WANDER|M2_DOMESTIC, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("housecat", S_FELINE, - LVL(4, 16, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 200, MS_MEW, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("jaguar", S_FELINE, - LVL(4, 15, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_BITE, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("lynx", S_FELINE, - LVL(5, 15, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_BITE, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_GROWL, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE,M2_HOSTILE, M3_INFRAVISIBLE, - CLR_CYAN), - MON("panther", S_FELINE, - LVL(5, 15, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - ATTK(AT_BITE, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE,M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BLACK), - MON("large cat", S_FELINE, - LVL(6, 15, 4, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(250, 250, MS_MEW, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_STRONG|M2_DOMESTIC, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("tiger", S_FELINE, - LVL(6, 12, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), - ATTK(AT_BITE, AD_PHYS, 1,10), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_YELLOW), -/* - * gremlins and gargoyles - */ - MON("gremlin", S_GREMLIN, - LVL(5, 12, 2, 25, -9), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - ATTK(AT_BITE, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_CURS, 0, 0), - NO_ATTK, NO_ATTK), - SIZ(100, 20, MS_LAUGH, MZ_SMALL), MR_POISON, MR_POISON, - M1_SWIM|M1_HUMANOID|M1_POIS, M2_STALK, M3_INFRAVISIBLE, CLR_GREEN), - MON("gargoyle", S_GREMLIN, - LVL(6, 10, -4, 0, -9), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_PHYS, 2, 6), - ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 200, MS_GRUNT, MZ_HUMAN), MR_STONE, MR_STONE, - M1_HUMANOID|M1_THICK_HIDE|M1_BREATHLESS, - M2_HOSTILE|M2_STRONG, 0, CLR_BROWN), - MON("winged gargoyle", S_GREMLIN, - LVL(9, 15, -2, 0, -12), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 6), - ATTK(AT_BITE, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 300, MS_GRUNT, MZ_HUMAN), MR_STONE, MR_STONE, - M1_FLY|M1_HUMANOID|M1_THICK_HIDE|M1_BREATHLESS|M1_OVIPAROUS, - M2_LORD|M2_HOSTILE|M2_STRONG|M2_MAGIC, 0, HI_LORD), -/* - * humanoids - */ - MON("hobbit", S_HUMANOID, - LVL(1, 9, 10, 0, 6), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 200, MS_HUMANOID, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_GREEN), - MON("dwarf", S_HUMANOID, - LVL(2, 6, 10, 10, 4), (G_GENO|3), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_TUNNEL|M1_NEEDPICK|M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_DWARF|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("bugbear", S_HUMANOID, - LVL(3, 9, 5, 0, -6), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1250, 250, MS_GROWL, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("dwarf lord", S_HUMANOID, - LVL(4, 6, 10, 10, 5), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_TUNNEL|M1_NEEDPICK|M1_HUMANOID|M1_OMNIVORE, - M2_DWARF|M2_STRONG|M2_LORD|M2_MALE|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - MON("dwarf king", S_HUMANOID, - LVL(6, 6, 10, 20, 6), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_TUNNEL|M1_NEEDPICK|M1_HUMANOID|M1_OMNIVORE, - M2_DWARF|M2_STRONG|M2_PRINCE|M2_MALE|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("mind flayer", S_HUMANOID, - LVL(9, 12, 5, 90, -8), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), ATTK(AT_TENT, AD_DRIN, 2, 1), - ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1), - NO_ATTK, NO_ATTK), - SIZ(1450, 400, MS_HISS, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_FLY|M1_SEE_INVIS|M1_OMNIVORE, - M2_HOSTILE|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_MAGENTA), - MON("master mind flayer", S_HUMANOID, - LVL(13, 12, 0, 90, -8), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_TENT, AD_DRIN, 2, 1), - ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1), - ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1)), - SIZ(1450, 400, MS_HISS, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_FLY|M1_SEE_INVIS|M1_OMNIVORE, - M2_HOSTILE|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_MAGENTA), -/* - * imps & other minor demons/devils - */ - MON("manes", S_IMP, - LVL(1, 3, 7, 0, -7), (G_GENO|G_LGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), - ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 100, MS_SILENT, MZ_SMALL), MR_SLEEP|MR_POISON, 0, - M1_POIS, M2_HOSTILE|M2_STALK, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("homunculus", S_IMP, - LVL(2, 12, 6, 10, -7), (G_GENO|2), - A(ATTK(AT_BITE, AD_SLEE, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(60, 100, MS_SILENT, MZ_TINY), - MR_SLEEP|MR_POISON, MR_SLEEP|MR_POISON, - M1_FLY|M1_POIS, M2_STALK, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GREEN), - MON("imp", S_IMP, - LVL(3, 12, 2, 20, -7), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(20, 10, MS_CUSS, MZ_TINY), 0, 0, - M1_REGEN, M2_WANDER|M2_STALK, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("lemure", S_IMP, - LVL(3, 3, 7, 0, -7), (G_HELL|G_GENO|G_LGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(150, 100, MS_SILENT, MZ_MEDIUM), - MR_SLEEP|MR_POISON, MR_SLEEP, M1_POIS|M1_REGEN, - M2_HOSTILE|M2_WANDER|M2_STALK|M2_NEUTER, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("quasit", S_IMP, - LVL(3, 15, 2, 20, -7), (G_GENO|2), - A(ATTK(AT_CLAW, AD_DRDX, 1, 2), ATTK(AT_CLAW, AD_DRDX, 1, 2), - ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 200, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, - M1_REGEN, M2_STALK, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - MON("tengu", S_IMP, - LVL(6, 13, 5, 30, 7), (G_GENO|3), - A(ATTK(AT_BITE, AD_PHYS, 1, 7), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 200, MS_SQAWK, MZ_SMALL), MR_POISON, MR_POISON, - M1_TPORT|M1_TPORT_CNTRL, M2_STALK, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_CYAN), -/* - * jellies - */ - MON("blue jelly", S_JELLY, - LVL(4, 0, 8, 10, 0), (G_GENO|2), - A(ATTK(AT_NONE, AD_COLD, 0, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 20, MS_SILENT, MZ_MEDIUM), - MR_COLD|MR_POISON, MR_COLD|MR_POISON, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS - |M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_BLUE), - MON("spotted jelly", S_JELLY, - LVL(5, 0, 8, 10, 0), (G_GENO|1), - A(ATTK(AT_NONE, AD_ACID, 0, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 20, MS_SILENT, MZ_MEDIUM), MR_ACID|MR_STONE, 0, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_ACID|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_GREEN), - MON("ochre jelly", S_JELLY, - LVL(6, 3, 8, 20, 0), (G_GENO|2), - A(ATTK(AT_ENGL, AD_ACID, 3, 6), ATTK(AT_NONE, AD_ACID, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 20, MS_SILENT, MZ_MEDIUM), MR_ACID|MR_STONE, 0, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_ACID|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_BROWN), -/* - * kobolds - */ - MON("kobold", S_KOBOLD, - LVL(0, 6, 10, 0, -2), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 100, MS_ORC, MZ_SMALL), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_OMNIVORE, M2_HOSTILE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("large kobold", S_KOBOLD, - LVL(1, 6, 10, 0, -3), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(450, 150, MS_ORC, MZ_SMALL), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_OMNIVORE, M2_HOSTILE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("kobold lord", S_KOBOLD, - LVL(2, 6, 10, 0, -4), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 200, MS_ORC, MZ_SMALL), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_OMNIVORE, - M2_HOSTILE|M2_LORD|M2_MALE|M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, - HI_LORD), - MON("kobold shaman", S_KOBOLD, - LVL(2, 6, 6, 10, -4), (G_GENO|1), - A(ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(450, 150, MS_ORC, MZ_SMALL), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_OMNIVORE, M2_HOSTILE|M2_MAGIC, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_ZAP), -/* - * leprechauns - */ - MON("leprechaun", S_LEPRECHAUN, - LVL(5, 15, 8, 20, 0), (G_GENO|4), - A(ATTK(AT_CLAW, AD_SGLD, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(60, 30, MS_LAUGH, MZ_TINY), 0, 0, - M1_HUMANOID|M1_TPORT, M2_HOSTILE|M2_GREEDY, M3_INFRAVISIBLE, CLR_GREEN), -/* - * mimics - */ - MON("small mimic", S_MIMIC, - LVL(7, 3, 7, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 200, MS_SILENT, MZ_MEDIUM), MR_ACID, 0, - M1_BREATHLESS|M1_AMORPHOUS|M1_HIDE|M1_ANIMAL|M1_NOEYES| - M1_NOHEAD|M1_NOLIMBS|M1_THICK_HIDE|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_BROWN), - MON("large mimic", S_MIMIC, - LVL(8, 3, 7, 10, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_STCK, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 400, MS_SILENT, MZ_LARGE), MR_ACID, 0, - M1_CLING|M1_BREATHLESS|M1_AMORPHOUS|M1_HIDE|M1_ANIMAL|M1_NOEYES| - M1_NOHEAD|M1_NOLIMBS|M1_THICK_HIDE|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG, 0, CLR_RED), - MON("giant mimic", S_MIMIC, - LVL(9, 3, 7, 20, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_STCK, 3, 6), ATTK(AT_CLAW, AD_STCK, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 500, MS_SILENT, MZ_LARGE), MR_ACID, 0, - M1_CLING|M1_BREATHLESS|M1_AMORPHOUS|M1_HIDE|M1_ANIMAL|M1_NOEYES| - M1_NOHEAD|M1_NOLIMBS|M1_THICK_HIDE|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG, 0, HI_LORD), -/* - * nymphs - */ - MON("wood nymph", S_NYMPH, - LVL(3, 12, 9, 20, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_TPORT, M2_HOSTILE|M2_FEMALE|M2_COLLECT, M3_INFRAVISIBLE, - CLR_GREEN), - MON("water nymph", S_NYMPH, - LVL(3, 12, 9, 20, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_TPORT|M1_SWIM, - M2_HOSTILE|M2_FEMALE|M2_COLLECT, M3_INFRAVISIBLE, CLR_BLUE), - MON("mountain nymph", S_NYMPH, - LVL(3, 12, 9, 20, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_TPORT, M2_HOSTILE|M2_FEMALE|M2_COLLECT, - M3_INFRAVISIBLE, CLR_BROWN), -/* - * orcs - */ - MON("goblin", S_ORC, - LVL(0, 6, 10, 0, -3), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 100, MS_ORC, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_ORC|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("hobgoblin", S_ORC, - LVL(1, 9, 10, 0, -4), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 200, MS_ORC, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_ORC|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - /* plain "orc" for zombie corpses only; not created at random - */ - MON("orc", S_ORC, - LVL(1, 9, 10, 0, -3), (G_GENO|G_NOGEN|G_LGROUP), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(850, 150, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("hill orc", S_ORC, - LVL(2, 9, 10, 0, -4), (G_GENO|G_LGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 200, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_YELLOW), - MON("Mordor orc", S_ORC, - LVL(3, 5, 10, 0, -5), (G_GENO|G_LGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 200, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - MON("Uruk-hai", S_ORC, - LVL(3, 7, 10, 0, -4), (G_GENO|G_LGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1300, 300, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLACK), - MON("orc shaman", S_ORC, - LVL(3, 9, 5, 10, -5), (G_GENO|1), - A(ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 300, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_MAGIC, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_ZAP), - MON("orc-captain", S_ORC, - LVL(5, 5, 10, 0, -5), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1350, 350, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID|M1_OMNIVORE, - M2_ORC|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), -/* - * piercers - */ - MON("rock piercer", S_PIERCER, - LVL(3, 1, 3, 0, 0), (G_GENO|4), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 200, MS_SILENT, MZ_SMALL), 0, 0, - M1_CLING|M1_HIDE|M1_ANIMAL|M1_NOEYES|M1_NOLIMBS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_GRAY), - MON("iron piercer", S_PIERCER, - LVL(5, 1, 0, 0, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 300, MS_SILENT, MZ_MEDIUM), 0, 0, - M1_CLING|M1_HIDE|M1_ANIMAL|M1_NOEYES|M1_NOLIMBS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_CYAN), - MON("glass piercer", S_PIERCER, - LVL(7, 1, 0, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 4, 6), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 300, MS_SILENT, MZ_MEDIUM), MR_ACID, 0, - M1_CLING|M1_HIDE|M1_ANIMAL|M1_NOEYES|M1_NOLIMBS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_WHITE), -/* - * quadrupeds - */ - MON("rothe", S_QUADRUPED, - LVL(2, 9, 7, 0, 0), (G_GENO|G_SGROUP|4), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_BITE, AD_PHYS, 1, 3), - ATTK(AT_BITE, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 100, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("mumak", S_QUADRUPED, - LVL(5, 9, 0, 0, -2), (G_GENO|1), - A(ATTK(AT_BUTT, AD_PHYS, 4,12), ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2500, 500, MS_ROAR, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_THICK_HIDE|M1_NOHANDS|M1_HERBIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), - MON("leocrotta", S_QUADRUPED, - LVL(6, 18, 4, 10, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_BITE, AD_PHYS, 2, 6), - ATTK(AT_CLAW, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 500, MS_IMITATE, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE, M2_HOSTILE|M2_STRONG, - M3_INFRAVISIBLE, CLR_RED), - MON("wumpus", S_QUADRUPED, - LVL(8, 3, 2, 10, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2500, 500, MS_BURBLE, MZ_LARGE), 0, 0, - M1_CLING|M1_ANIMAL|M1_NOHANDS|M1_OMNIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_CYAN), - MON("titanothere", S_QUADRUPED, - LVL(12, 12, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2650, 650, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_THICK_HIDE|M1_NOHANDS|M1_HERBIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), - MON("baluchitherium", S_QUADRUPED, - LVL(14, 12, 5, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 5, 4), ATTK(AT_CLAW, AD_PHYS, 5, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(3800, 800, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_THICK_HIDE|M1_NOHANDS|M1_HERBIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), - MON("mastodon", S_QUADRUPED, - LVL(20, 12, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BUTT, AD_PHYS, 4, 8), ATTK(AT_BUTT, AD_PHYS, 4, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(3800, 800, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_THICK_HIDE|M1_NOHANDS|M1_HERBIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_BLACK), -/* - * rodents - */ - MON("sewer rat", S_RODENT, - LVL(0, 12, 7, 0, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(20, 12, MS_SQEEK, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("giant rat", S_RODENT, - LVL(1, 10, 7, 0, 0), (G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_SQEEK, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("rabid rat", S_RODENT, - LVL(2, 12, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_DRCO, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 5, MS_SQEEK, MZ_TINY), MR_POISON, 0, - M1_ANIMAL|M1_NOHANDS|M1_POIS|M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_BROWN), - MON("wererat", S_RODENT, - LVL(2, 12, 6, 10, -7), (G_NOGEN|G_NOCORPSE), - A(ATTK(AT_BITE, AD_WERE, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(40, 30, MS_SQEEK, MZ_TINY), MR_POISON, 0, - M1_NOHANDS|M1_POIS|M1_REGEN|M1_CARNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), - MON("rock mole", S_RODENT, - LVL(3, 3, 0, 20, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_SILENT, MZ_SMALL), 0, 0, - M1_TUNNEL|M1_ANIMAL|M1_NOHANDS|M1_METALLIVORE, - M2_HOSTILE|M2_GREEDY|M2_JEWELS|M2_COLLECT, M3_INFRAVISIBLE, CLR_GRAY), - MON("woodchuck", S_RODENT, - LVL(3, 3, 0, 20, 0), (G_NOGEN|G_GENO), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_SILENT, MZ_SMALL), 0, 0, - M1_TUNNEL/*LOGGING*/|M1_ANIMAL|M1_NOHANDS|M1_SWIM|M1_HERBIVORE, - /* In reality, they tunnel instead of cutting lumber. Oh, well. */ - M2_WANDER|M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), -/* - * spiders & scorpions (keep webmaker() in sync if new critters are added) - */ - MON("cave spider", S_SPIDER, - LVL(1, 12, 3, 0, 0), (G_GENO|G_SGROUP|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 50, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, - M1_CONCEAL|M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_GRAY), - MON("centipede", S_SPIDER, - LVL(2, 4, 3, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_DRST, 1, 3), NO_ATTK, NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 50, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, - M1_CONCEAL|M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_YELLOW), - MON("giant spider", S_SPIDER, - LVL(5, 15, 4, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_DRST, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 100, MS_SILENT, MZ_LARGE), MR_POISON, MR_POISON, - M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_POIS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG, 0, CLR_MAGENTA), - MON("scorpion", S_SPIDER, - LVL(5, 15, 3, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 2), - ATTK(AT_STNG, AD_DRST, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 100, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, - M1_CONCEAL|M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_POIS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_RED), -/* - * trappers, lurkers, &c - */ - MON("lurker above", S_TRAPPER, - LVL(10, 3, 3, 0, 0), (G_GENO|2), - A(ATTK(AT_ENGL, AD_DGST, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 350, MS_SILENT, MZ_HUGE), 0, 0, - M1_HIDE|M1_FLY|M1_ANIMAL|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_CARNIVORE, - M2_HOSTILE|M2_STALK|M2_STRONG, 0, CLR_GRAY), - MON("trapper", S_TRAPPER, - LVL(12, 3, 3, 0, 0), (G_GENO|2), - A(ATTK(AT_ENGL, AD_DGST, 1,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 350, MS_SILENT, MZ_HUGE), 0, 0, - M1_HIDE|M1_ANIMAL|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_CARNIVORE, - M2_HOSTILE|M2_STALK|M2_STRONG, 0, CLR_GREEN), -/* - * unicorns and horses - */ - MON("pony", S_UNICORN, - LVL(3, 16, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_KICK, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1300, 250, MS_NEIGH, MZ_MEDIUM), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_DOMESTIC, - M3_INFRAVISIBLE, CLR_BROWN), - MON("white unicorn", S_UNICORN, - LVL(4, 24, 2, 70, 7), (G_GENO|2), - A(ATTK(AT_BUTT, AD_PHYS, 1,12), ATTK(AT_KICK, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, - M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_JEWELS, - M3_INFRAVISIBLE, CLR_WHITE), - MON("gray unicorn", S_UNICORN, - LVL(4, 24, 2, 70, 0), (G_GENO|1), - A(ATTK(AT_BUTT, AD_PHYS, 1,12), ATTK(AT_KICK, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, - M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_JEWELS, - M3_INFRAVISIBLE, CLR_GRAY), - MON("black unicorn", S_UNICORN, - LVL(4, 24, 2, 70, -7), (G_GENO|1), - A(ATTK(AT_BUTT, AD_PHYS, 1,12), ATTK(AT_KICK, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, - M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_JEWELS, - M3_INFRAVISIBLE, CLR_BLACK), - MON("horse", S_UNICORN, - LVL(5, 20, 5, 0, 0), (G_GENO|2), - A(ATTK(AT_KICK, AD_PHYS, 1, 8), ATTK(AT_BITE, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 300, MS_NEIGH, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_DOMESTIC, - M3_INFRAVISIBLE, CLR_BROWN), - MON("warhorse", S_UNICORN, - LVL(7, 24, 4, 0, 0), (G_GENO|2), - A(ATTK(AT_KICK, AD_PHYS, 1, 10), ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1800, 350, MS_NEIGH, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_HERBIVORE, M2_WANDER|M2_STRONG|M2_DOMESTIC, - M3_INFRAVISIBLE, CLR_BROWN), -/* - * vortices - */ - MON("fog cloud", S_VORTEX, - LVL(3, 1, 0, 0, 0), (G_GENO|G_NOCORPSE|2), - A(ATTK(AT_ENGL, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS| - M1_AMORPHOUS|M1_UNSOLID, - M2_HOSTILE|M2_NEUTER, 0, CLR_GRAY), - MON("dust vortex", S_VORTEX, - LVL(4, 20, 2, 30, 0), (G_GENO|G_NOCORPSE|2), - A(ATTK(AT_ENGL, AD_BLND, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS, - M2_HOSTILE|M2_NEUTER, 0, CLR_BROWN), - MON("ice vortex", S_VORTEX, - LVL(5, 20, 2, 30, 0), (G_NOHELL|G_GENO|G_NOCORPSE|1), - A(ATTK(AT_ENGL, AD_COLD, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), - MR_COLD|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_CYAN), - MON("energy vortex", S_VORTEX, - LVL(6, 20, 2, 30, 0), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_ENGL, AD_ELEC, 1, 6), ATTK(AT_ENGL, AD_DREN, 4, 6), - ATTK(AT_NONE, AD_ELEC, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), - MR_ELEC|MR_SLEEP|MR_DISINT|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS| - M1_UNSOLID, - M2_HOSTILE|M2_NEUTER, 0, HI_ZAP), - MON("steam vortex", S_VORTEX, - LVL(7, 22, 2, 30, 0), (G_HELL|G_GENO|G_NOCORPSE|2), - A(ATTK(AT_ENGL, AD_FIRE, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), - MR_FIRE|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS| - M1_UNSOLID, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_BLUE), - MON("fire vortex", S_VORTEX, - LVL(8, 22, 2, 30, 0), (G_HELL|G_GENO|G_NOCORPSE|1), - A(ATTK(AT_ENGL, AD_FIRE, 1,10), ATTK(AT_NONE, AD_FIRE, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), - MR_FIRE|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS| - M1_UNSOLID, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), -/* - * worms - */ - MON("baby long worm", S_WORM, - LVL(5, 3, 5, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 250, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_SLITHY|M1_NOLIMBS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_BROWN), - MON("baby purple worm", S_WORM, - LVL(8, 3, 5, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 250, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_SLITHY|M1_NOLIMBS|M1_CARNIVORE, M2_HOSTILE, - 0, CLR_MAGENTA), - MON("long worm", S_WORM, - LVL(9, 3, 5, 10, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_SILENT, MZ_GIGANTIC), 0, 0, - M1_ANIMAL|M1_SLITHY|M1_NOLIMBS|M1_OVIPAROUS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE|M2_STRONG|M2_NASTY, 0, CLR_BROWN), - MON("purple worm", S_WORM, - LVL(15, 9, 6, 20, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 2, 8), ATTK(AT_ENGL, AD_DGST, 1,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2700, 700, MS_SILENT, MZ_GIGANTIC), 0, 0, - M1_ANIMAL|M1_SLITHY|M1_NOLIMBS|M1_OVIPAROUS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY, 0, CLR_MAGENTA), -/* - * xan, &c - */ - MON("grid bug", S_XAN, - LVL(0, 12, 9, 0, 0), (G_GENO|G_SGROUP|G_NOCORPSE|3), - A(ATTK(AT_BITE, AD_ELEC, 1, 1), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(15, 10, MS_BUZZ, MZ_TINY), MR_ELEC|MR_POISON, 0, - M1_ANIMAL, M2_HOSTILE, M3_INFRAVISIBLE, CLR_MAGENTA), - MON("xan", S_XAN, - LVL(7, 18, -4, 0, 0), (G_GENO|3), - A(ATTK(AT_STNG, AD_LEGS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 300, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_POIS, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_RED), -/* - * lights - */ - MON("yellow light", S_LIGHT, - LVL(3, 15, 0, 0, 0), (G_NOCORPSE|G_GENO|4), - A(ATTK(AT_EXPL, AD_BLND, 10,20), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_SMALL), - MR_FIRE|MR_COLD|MR_ELEC|MR_DISINT|MR_SLEEP|MR_POISON|MR_ACID| - MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_UNSOLID|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), - MON("black light", S_LIGHT, - LVL(5, 15, 0, 0, 0), (G_NOCORPSE|G_GENO|2), - A(ATTK(AT_EXPL, AD_HALU, 10,12), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_SMALL), - MR_FIRE|MR_COLD|MR_ELEC|MR_DISINT|MR_SLEEP|MR_POISON|MR_ACID| - MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_UNSOLID|M1_SEE_INVIS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_BLACK), -/* - * zruty - */ - MON("zruty", S_ZRUTY, - LVL(9, 8, 3, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), - ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 600, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_BROWN), -/* - * Angels and other lawful minions - */ - MON("couatl", S_ANGEL, - LVL(8, 10, 5, 30, 7), (G_NOHELL|G_SGROUP|G_NOCORPSE|1), - A(ATTK(AT_BITE, AD_DRST, 2, 4), ATTK(AT_BITE, AD_PHYS, 1, 3), - ATTK(AT_HUGS, AD_WRAP, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 400, MS_HISS, MZ_LARGE), MR_POISON, 0, - M1_FLY|M1_NOHANDS|M1_SLITHY|M1_POIS, - M2_MINION|M2_STALK|M2_STRONG|M2_NASTY, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_GREEN), - MON("Aleax", S_ANGEL, - LVL(10, 8, 0, 30, 7), (G_NOHELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - ATTK(AT_KICK, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_IMITATE, MZ_HUMAN), - MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_HUMANOID|M1_SEE_INVIS, - M2_MINION|M2_STALK|M2_NASTY|M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_YELLOW), - /* Angels start with the emin extension attached, and usually have - the isminion flag set; however, non-minion Angels can be tamed - and will switch to edog (guardian Angel is handled specially and - always sticks with emin) */ - MON("Angel", S_ANGEL, - LVL(14, 10, -4, 55, 12), (G_NOHELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_MAGC, AD_MAGM, 2, 6), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_CUSS, MZ_HUMAN), - MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_HUMANOID|M1_SEE_INVIS, - M2_NOPOLY|M2_MINION|M2_STALK|M2_STRONG|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_WHITE), - MON("ki-rin", S_ANGEL, - LVL(16, 18, -5, 90, 15), (G_NOHELL|G_NOCORPSE|1), - A(ATTK(AT_KICK, AD_PHYS, 2, 4), ATTK(AT_KICK, AD_PHYS, 2, 4), - ATTK(AT_BUTT, AD_PHYS, 3, 6), ATTK(AT_MAGC, AD_SPEL, 2, 6), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEIGH, MZ_LARGE), 0, 0, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_SEE_INVIS, - M2_NOPOLY|M2_MINION|M2_STALK|M2_STRONG|M2_NASTY|M2_LORD, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_GOLD), - MON("Archon", S_ANGEL, - LVL(19, 16, -6, 80, 15), (G_NOHELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - ATTK(AT_GAZE, AD_BLND, 2, 6), ATTK(AT_CLAW, AD_PHYS, 1, 8), - ATTK(AT_MAGC, AD_SPEL, 4, 6), NO_ATTK), - SIZ(WT_HUMAN, 400, MS_CUSS, MZ_LARGE), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_HUMANOID|M1_SEE_INVIS|M1_REGEN, - M2_NOPOLY|M2_MINION|M2_STALK|M2_STRONG|M2_NASTY|M2_LORD| - M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), -/* - * Bats - */ - MON("bat", S_BAT, - LVL(0, 22, 8, 0, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(20, 20, MS_SQEEK, MZ_TINY), 0, 0, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_WANDER, M3_INFRAVISIBLE, - CLR_BROWN), - MON("giant bat", S_BAT, - LVL(2, 22, 7, 0, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_SQEEK, MZ_SMALL), 0, 0, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_WANDER|M2_HOSTILE, M3_INFRAVISIBLE, CLR_RED), - MON("raven", S_BAT, - LVL(4, 20, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_BLND, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(40, 20, MS_SQAWK, MZ_SMALL), 0, 0, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_WANDER|M2_HOSTILE, M3_INFRAVISIBLE, CLR_BLACK), - MON("vampire bat", S_BAT, - LVL(5, 20, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_DRST, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 20, MS_SQEEK, MZ_SMALL), MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_ANIMAL|M1_NOHANDS|M1_POIS|M1_REGEN|M1_OMNIVORE, - M2_HOSTILE, M3_INFRAVISIBLE, CLR_BLACK), -/* - * Centaurs - */ - MON("plains centaur", S_CENTAUR, - LVL(4, 18, 4, 0, 0), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_KICK, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2500, 500, MS_HUMANOID, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_STRONG|M2_GREEDY|M2_COLLECT, - M3_INFRAVISIBLE, CLR_BROWN), - MON("forest centaur", S_CENTAUR, - LVL(5, 18, 3, 10, -1), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_KICK, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2550, 600, MS_HUMANOID, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_STRONG|M2_GREEDY|M2_COLLECT, - M3_INFRAVISIBLE, CLR_GREEN), - MON("mountain centaur", S_CENTAUR, - LVL(6, 20, 2, 10, -3), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1,10), ATTK(AT_KICK, AD_PHYS, 1, 6), - ATTK(AT_KICK, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2550, 500, MS_HUMANOID, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_STRONG|M2_GREEDY|M2_COLLECT, - M3_INFRAVISIBLE, CLR_CYAN), -/* - * Dragons - */ - /* The order of the dragons is VERY IMPORTANT. Quite a few - * pieces of code depend on gray being first and yellow being last. - * The code also depends on the *order* being the same as that for - * dragon scale mail and dragon scales in objects.c. Baby dragons - * cannot confer intrinsics, to avoid polyself/egg abuse. - * - * As reptiles, dragons are cold-blooded and thus aren't seen - * with infravision. Red dragons are the exception. - */ - MON("baby gray dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), 0, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_GRAY), - MON("baby silver dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), 0, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, DRAGON_SILVER), -#if 0 /* DEFERRED */ + /* + * felines + */ + MON("kitten", S_FELINE, LVL(2, 18, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(150, 150, MS_MEW, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_WANDER | M2_DOMESTIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("housecat", S_FELINE, LVL(4, 16, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(200, 200, MS_MEW, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_DOMESTIC, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("jaguar", S_FELINE, LVL(4, 15, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_BITE, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("lynx", S_FELINE, LVL(5, 15, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_BITE, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_GROWL, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_CYAN), + MON("panther", S_FELINE, LVL(5, 15, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), + ATTK(AT_BITE, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BLACK), + MON("large cat", S_FELINE, LVL(6, 15, 4, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(250, 250, MS_MEW, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_STRONG | M2_DOMESTIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("tiger", S_FELINE, LVL(6, 12, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), + ATTK(AT_BITE, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_YELLOW), + /* + * gremlins and gargoyles + */ + MON("gremlin", S_GREMLIN, LVL(5, 12, 2, 25, -9), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), + ATTK(AT_BITE, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_CURS, 0, 0), NO_ATTK, + NO_ATTK), + SIZ(100, 20, MS_LAUGH, MZ_SMALL), MR_POISON, MR_POISON, + M1_SWIM | M1_HUMANOID | M1_POIS, M2_STALK, M3_INFRAVISIBLE, + CLR_GREEN), + MON("gargoyle", S_GREMLIN, LVL(6, 10, -4, 0, -9), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_PHYS, 2, 6), + ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1000, 200, MS_GRUNT, MZ_HUMAN), MR_STONE, MR_STONE, + M1_HUMANOID | M1_THICK_HIDE | M1_BREATHLESS, M2_HOSTILE | M2_STRONG, + 0, CLR_BROWN), + MON("winged gargoyle", S_GREMLIN, LVL(9, 15, -2, 0, -12), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 6), + ATTK(AT_BITE, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 300, MS_GRUNT, MZ_HUMAN), MR_STONE, MR_STONE, + M1_FLY | M1_HUMANOID | M1_THICK_HIDE | M1_BREATHLESS | M1_OVIPAROUS, + M2_LORD | M2_HOSTILE | M2_STRONG | M2_MAGIC, 0, HI_LORD), + /* + * humanoids + */ + MON("hobbit", S_HUMANOID, LVL(1, 9, 10, 0, 6), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 200, MS_HUMANOID, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_COLLECT, M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GREEN), + MON("dwarf", S_HUMANOID, LVL(2, 6, 10, 10, 4), (G_GENO | 3), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_TUNNEL | M1_NEEDPICK | M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_DWARF | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("bugbear", S_HUMANOID, LVL(3, 9, 5, 0, -6), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1250, 250, MS_GROWL, MZ_LARGE), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("dwarf lord", S_HUMANOID, LVL(4, 6, 10, 10, 5), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_TUNNEL | M1_NEEDPICK | M1_HUMANOID | M1_OMNIVORE, + M2_DWARF | M2_STRONG | M2_LORD | M2_MALE | M2_GREEDY | M2_JEWELS + | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), + MON("dwarf king", S_HUMANOID, LVL(6, 6, 10, 20, 6), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(900, 300, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_TUNNEL | M1_NEEDPICK | M1_HUMANOID | M1_OMNIVORE, + M2_DWARF | M2_STRONG | M2_PRINCE | M2_MALE | M2_GREEDY | M2_JEWELS + | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("mind flayer", S_HUMANOID, LVL(9, 12, 5, 90, -8), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), ATTK(AT_TENT, AD_DRIN, 2, 1), + ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1), NO_ATTK, + NO_ATTK), + SIZ(1450, 400, MS_HISS, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_FLY | M1_SEE_INVIS | M1_OMNIVORE, + M2_HOSTILE | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_MAGENTA), + MON("master mind flayer", S_HUMANOID, LVL(13, 12, 0, 90, -8), + (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_TENT, AD_DRIN, 2, 1), + ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1), + ATTK(AT_TENT, AD_DRIN, 2, 1), ATTK(AT_TENT, AD_DRIN, 2, 1)), + SIZ(1450, 400, MS_HISS, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_FLY | M1_SEE_INVIS | M1_OMNIVORE, + M2_HOSTILE | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_MAGENTA), + /* + * imps & other minor demons/devils + */ + MON("manes", S_IMP, LVL(1, 3, 7, 0, -7), + (G_GENO | G_LGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), + ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(100, 100, MS_SILENT, MZ_SMALL), MR_SLEEP | MR_POISON, 0, M1_POIS, + M2_HOSTILE | M2_STALK, M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("homunculus", S_IMP, LVL(2, 12, 6, 10, -7), (G_GENO | 2), + A(ATTK(AT_BITE, AD_SLEE, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(60, 100, MS_SILENT, MZ_TINY), MR_SLEEP | MR_POISON, + MR_SLEEP | MR_POISON, M1_FLY | M1_POIS, M2_STALK, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GREEN), + MON("imp", S_IMP, LVL(3, 12, 2, 20, -7), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(20, 10, MS_CUSS, MZ_TINY), 0, 0, M1_REGEN, M2_WANDER | M2_STALK, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("lemure", S_IMP, LVL(3, 3, 7, 0, -7), + (G_HELL | G_GENO | G_LGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(150, 100, MS_SILENT, MZ_MEDIUM), MR_SLEEP | MR_POISON, MR_SLEEP, + M1_POIS | M1_REGEN, M2_HOSTILE | M2_WANDER | M2_STALK | M2_NEUTER, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("quasit", S_IMP, LVL(3, 15, 2, 20, -7), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_DRDX, 1, 2), ATTK(AT_CLAW, AD_DRDX, 1, 2), + ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(200, 200, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, M1_REGEN, + M2_STALK, M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), + MON("tengu", S_IMP, LVL(6, 13, 5, 30, 7), (G_GENO | 3), + A(ATTK(AT_BITE, AD_PHYS, 1, 7), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 200, MS_SQAWK, MZ_SMALL), MR_POISON, MR_POISON, + M1_TPORT | M1_TPORT_CNTRL, M2_STALK, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_CYAN), + /* + * jellies + */ + MON("blue jelly", S_JELLY, LVL(4, 0, 8, 10, 0), (G_GENO | 2), + A(ATTK(AT_NONE, AD_COLD, 0, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 20, MS_SILENT, MZ_MEDIUM), MR_COLD | MR_POISON, + MR_COLD | MR_POISON, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_BLUE), + MON("spotted jelly", S_JELLY, LVL(5, 0, 8, 10, 0), (G_GENO | 1), + A(ATTK(AT_NONE, AD_ACID, 0, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 20, MS_SILENT, MZ_MEDIUM), MR_ACID | MR_STONE, 0, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_ACID | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_GREEN), + MON("ochre jelly", S_JELLY, LVL(6, 3, 8, 20, 0), (G_GENO | 2), + A(ATTK(AT_ENGL, AD_ACID, 3, 6), ATTK(AT_NONE, AD_ACID, 3, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(50, 20, MS_SILENT, MZ_MEDIUM), MR_ACID | MR_STONE, 0, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_ACID | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_BROWN), + /* + * kobolds + */ + MON("kobold", S_KOBOLD, LVL(0, 6, 10, 0, -2), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 100, MS_ORC, MZ_SMALL), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_OMNIVORE, M2_HOSTILE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("large kobold", S_KOBOLD, LVL(1, 6, 10, 0, -3), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(450, 150, MS_ORC, MZ_SMALL), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_OMNIVORE, M2_HOSTILE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("kobold lord", S_KOBOLD, LVL(2, 6, 10, 0, -4), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 200, MS_ORC, MZ_SMALL), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_OMNIVORE, + M2_HOSTILE | M2_LORD | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("kobold shaman", S_KOBOLD, LVL(2, 6, 6, 10, -4), (G_GENO | 1), + A(ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(450, 150, MS_ORC, MZ_SMALL), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_OMNIVORE, M2_HOSTILE | M2_MAGIC, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_ZAP), + /* + * leprechauns + */ + MON("leprechaun", S_LEPRECHAUN, LVL(5, 15, 8, 20, 0), (G_GENO | 4), + A(ATTK(AT_CLAW, AD_SGLD, 1, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(60, 30, MS_LAUGH, MZ_TINY), 0, 0, M1_HUMANOID | M1_TPORT, + M2_HOSTILE | M2_GREEDY, M3_INFRAVISIBLE, CLR_GREEN), + /* + * mimics + */ + MON("small mimic", S_MIMIC, LVL(7, 3, 7, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 200, MS_SILENT, MZ_MEDIUM), MR_ACID, 0, + M1_BREATHLESS | M1_AMORPHOUS | M1_HIDE | M1_ANIMAL | M1_NOEYES + | M1_NOHEAD | M1_NOLIMBS | M1_THICK_HIDE | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_BROWN), + MON("large mimic", S_MIMIC, LVL(8, 3, 7, 10, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_STCK, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(600, 400, MS_SILENT, MZ_LARGE), MR_ACID, 0, + M1_CLING | M1_BREATHLESS | M1_AMORPHOUS | M1_HIDE | M1_ANIMAL + | M1_NOEYES | M1_NOHEAD | M1_NOLIMBS | M1_THICK_HIDE + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG, 0, CLR_RED), + MON("giant mimic", S_MIMIC, LVL(9, 3, 7, 20, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_STCK, 3, 6), ATTK(AT_CLAW, AD_STCK, 3, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(800, 500, MS_SILENT, MZ_LARGE), MR_ACID, 0, + M1_CLING | M1_BREATHLESS | M1_AMORPHOUS | M1_HIDE | M1_ANIMAL + | M1_NOEYES | M1_NOHEAD | M1_NOLIMBS | M1_THICK_HIDE + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG, 0, HI_LORD), + /* + * nymphs + */ + MON("wood nymph", S_NYMPH, LVL(3, 12, 9, 20, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_TPORT, + M2_HOSTILE | M2_FEMALE | M2_COLLECT, M3_INFRAVISIBLE, CLR_GREEN), + MON("water nymph", S_NYMPH, LVL(3, 12, 9, 20, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_TPORT | M1_SWIM, M2_HOSTILE | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BLUE), + MON("mountain nymph", S_NYMPH, LVL(3, 12, 9, 20, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_CLAW, AD_SEDU, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_SEDUCE, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_TPORT, + M2_HOSTILE | M2_FEMALE | M2_COLLECT, M3_INFRAVISIBLE, CLR_BROWN), + /* + * orcs + */ + MON("goblin", S_ORC, LVL(0, 6, 10, 0, -3), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 100, MS_ORC, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_COLLECT, M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("hobgoblin", S_ORC, LVL(1, 9, 10, 0, -4), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1000, 200, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BROWN), + /* plain "orc" for zombie corpses only; not created at random + */ + MON("orc", S_ORC, LVL(1, 9, 10, 0, -3), (G_GENO | G_NOGEN | G_LGROUP), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(850, 150, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("hill orc", S_ORC, LVL(2, 9, 10, 0, -4), (G_GENO | G_LGROUP | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1000, 200, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_YELLOW), + MON("Mordor orc", S_ORC, LVL(3, 5, 10, 0, -5), (G_GENO | G_LGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1200, 200, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), + MON("Uruk-hai", S_ORC, LVL(3, 7, 10, 0, -4), (G_GENO | G_LGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1300, 300, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLACK), + MON("orc shaman", S_ORC, LVL(3, 9, 5, 10, -5), (G_GENO | 1), + A(ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1000, 300, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_MAGIC, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_ZAP), + MON("orc-captain", S_ORC, LVL(5, 5, 10, 0, -5), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1350, 350, MS_ORC, MZ_HUMAN), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_ORC | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + /* + * piercers + */ + MON("rock piercer", S_PIERCER, LVL(3, 1, 3, 0, 0), (G_GENO | 4), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(200, 200, MS_SILENT, MZ_SMALL), 0, 0, + M1_CLING | M1_HIDE | M1_ANIMAL | M1_NOEYES | M1_NOLIMBS | M1_CARNIVORE + | M1_NOTAKE, + M2_HOSTILE, 0, CLR_GRAY), + MON("iron piercer", S_PIERCER, LVL(5, 1, 0, 0, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 300, MS_SILENT, MZ_MEDIUM), 0, 0, + M1_CLING | M1_HIDE | M1_ANIMAL | M1_NOEYES | M1_NOLIMBS | M1_CARNIVORE + | M1_NOTAKE, + M2_HOSTILE, 0, CLR_CYAN), + MON("glass piercer", S_PIERCER, LVL(7, 1, 0, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 4, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 300, MS_SILENT, MZ_MEDIUM), MR_ACID, 0, + M1_CLING | M1_HIDE | M1_ANIMAL | M1_NOEYES | M1_NOLIMBS | M1_CARNIVORE + | M1_NOTAKE, + M2_HOSTILE, 0, CLR_WHITE), + /* + * quadrupeds + */ + MON("rothe", S_QUADRUPED, LVL(2, 9, 7, 0, 0), (G_GENO | G_SGROUP | 4), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_BITE, AD_PHYS, 1, 3), + ATTK(AT_BITE, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 100, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("mumak", S_QUADRUPED, LVL(5, 9, 0, 0, -2), (G_GENO | 1), + A(ATTK(AT_BUTT, AD_PHYS, 4, 12), ATTK(AT_BITE, AD_PHYS, 2, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2500, 500, MS_ROAR, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_THICK_HIDE | M1_NOHANDS | M1_HERBIVORE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), + MON("leocrotta", S_QUADRUPED, LVL(6, 18, 4, 10, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_BITE, AD_PHYS, 2, 6), + ATTK(AT_CLAW, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 500, MS_IMITATE, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE, M2_HOSTILE | M2_STRONG, + M3_INFRAVISIBLE, CLR_RED), + MON("wumpus", S_QUADRUPED, LVL(8, 3, 2, 10, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2500, 500, MS_BURBLE, MZ_LARGE), 0, 0, + M1_CLING | M1_ANIMAL | M1_NOHANDS | M1_OMNIVORE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_CYAN), + MON("titanothere", S_QUADRUPED, LVL(12, 12, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2650, 650, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_THICK_HIDE | M1_NOHANDS | M1_HERBIVORE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), + MON("baluchitherium", S_QUADRUPED, LVL(14, 12, 5, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 5, 4), ATTK(AT_CLAW, AD_PHYS, 5, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(3800, 800, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_THICK_HIDE | M1_NOHANDS | M1_HERBIVORE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_GRAY), + MON("mastodon", S_QUADRUPED, LVL(20, 12, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BUTT, AD_PHYS, 4, 8), ATTK(AT_BUTT, AD_PHYS, 4, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(3800, 800, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_THICK_HIDE | M1_NOHANDS | M1_HERBIVORE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_BLACK), + /* + * rodents + */ + MON("sewer rat", S_RODENT, LVL(0, 12, 7, 0, 0), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(20, 12, MS_SQEEK, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("giant rat", S_RODENT, LVL(1, 10, 7, 0, 0), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_SQEEK, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, M3_INFRAVISIBLE, + CLR_BROWN), + MON("rabid rat", S_RODENT, LVL(2, 12, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_DRCO, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 5, MS_SQEEK, MZ_TINY), MR_POISON, 0, + M1_ANIMAL | M1_NOHANDS | M1_POIS | M1_CARNIVORE, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_BROWN), + MON("wererat", S_RODENT, LVL(2, 12, 6, 10, -7), (G_NOGEN | G_NOCORPSE), + A(ATTK(AT_BITE, AD_WERE, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(40, 30, MS_SQEEK, MZ_TINY), MR_POISON, 0, + M1_NOHANDS | M1_POIS | M1_REGEN | M1_CARNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), + MON("rock mole", S_RODENT, LVL(3, 3, 0, 20, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_SILENT, MZ_SMALL), 0, 0, + M1_TUNNEL | M1_ANIMAL | M1_NOHANDS | M1_METALLIVORE, + M2_HOSTILE | M2_GREEDY | M2_JEWELS | M2_COLLECT, M3_INFRAVISIBLE, + CLR_GRAY), + MON("woodchuck", S_RODENT, LVL(3, 3, 0, 20, 0), (G_NOGEN | G_GENO), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_SILENT, MZ_SMALL), 0, 0, + M1_TUNNEL /*LOGGING*/ | M1_ANIMAL | M1_NOHANDS | M1_SWIM + | M1_HERBIVORE, + /* In reality, they tunnel instead of cutting lumber. Oh, well. */ + M2_WANDER | M2_HOSTILE, M3_INFRAVISIBLE, CLR_BROWN), + /* + * spiders & scorpions (keep webmaker() in sync if new critters are added) + */ + MON("cave spider", S_SPIDER, LVL(1, 12, 3, 0, 0), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 50, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, + M1_CONCEAL | M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_GRAY), + MON("centipede", S_SPIDER, LVL(2, 4, 3, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_DRST, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 50, MS_SILENT, MZ_TINY), MR_POISON, MR_POISON, + M1_CONCEAL | M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_YELLOW), + MON("giant spider", S_SPIDER, LVL(5, 15, 4, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_DRST, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(100, 100, MS_SILENT, MZ_LARGE), MR_POISON, MR_POISON, + M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_POIS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG, 0, CLR_MAGENTA), + MON("scorpion", S_SPIDER, LVL(5, 15, 3, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 2), + ATTK(AT_STNG, AD_DRST, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(50, 100, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, + M1_CONCEAL | M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_POIS + | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_RED), + /* + * trappers, lurkers, &c + */ + MON("lurker above", S_TRAPPER, LVL(10, 3, 3, 0, 0), (G_GENO | 2), + A(ATTK(AT_ENGL, AD_DGST, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(800, 350, MS_SILENT, MZ_HUGE), 0, 0, + M1_HIDE | M1_FLY | M1_ANIMAL | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_CARNIVORE, + M2_HOSTILE | M2_STALK | M2_STRONG, 0, CLR_GRAY), + MON("trapper", S_TRAPPER, LVL(12, 3, 3, 0, 0), (G_GENO | 2), + A(ATTK(AT_ENGL, AD_DGST, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(800, 350, MS_SILENT, MZ_HUGE), 0, 0, + M1_HIDE | M1_ANIMAL | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_CARNIVORE, + M2_HOSTILE | M2_STALK | M2_STRONG, 0, CLR_GREEN), + /* + * unicorns and horses + */ + MON("pony", S_UNICORN, LVL(3, 16, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_KICK, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_PHYS, 1, 2), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1300, 250, MS_NEIGH, MZ_MEDIUM), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_HERBIVORE, + M2_WANDER | M2_STRONG | M2_DOMESTIC, M3_INFRAVISIBLE, CLR_BROWN), + MON("white unicorn", S_UNICORN, LVL(4, 24, 2, 70, 7), (G_GENO | 2), + A(ATTK(AT_BUTT, AD_PHYS, 1, 12), ATTK(AT_KICK, AD_PHYS, 1, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, + M1_NOHANDS | M1_HERBIVORE, M2_WANDER | M2_STRONG | M2_JEWELS, + M3_INFRAVISIBLE, CLR_WHITE), + MON("gray unicorn", S_UNICORN, LVL(4, 24, 2, 70, 0), (G_GENO | 1), + A(ATTK(AT_BUTT, AD_PHYS, 1, 12), ATTK(AT_KICK, AD_PHYS, 1, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, + M1_NOHANDS | M1_HERBIVORE, M2_WANDER | M2_STRONG | M2_JEWELS, + M3_INFRAVISIBLE, CLR_GRAY), + MON("black unicorn", S_UNICORN, LVL(4, 24, 2, 70, -7), (G_GENO | 1), + A(ATTK(AT_BUTT, AD_PHYS, 1, 12), ATTK(AT_KICK, AD_PHYS, 1, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1300, 300, MS_NEIGH, MZ_LARGE), MR_POISON, MR_POISON, + M1_NOHANDS | M1_HERBIVORE, M2_WANDER | M2_STRONG | M2_JEWELS, + M3_INFRAVISIBLE, CLR_BLACK), + MON("horse", S_UNICORN, LVL(5, 20, 5, 0, 0), (G_GENO | 2), + A(ATTK(AT_KICK, AD_PHYS, 1, 8), ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 300, MS_NEIGH, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_HERBIVORE, + M2_WANDER | M2_STRONG | M2_DOMESTIC, M3_INFRAVISIBLE, CLR_BROWN), + MON("warhorse", S_UNICORN, LVL(7, 24, 4, 0, 0), (G_GENO | 2), + A(ATTK(AT_KICK, AD_PHYS, 1, 10), ATTK(AT_BITE, AD_PHYS, 1, 4), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1800, 350, MS_NEIGH, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_HERBIVORE, + M2_WANDER | M2_STRONG | M2_DOMESTIC, M3_INFRAVISIBLE, CLR_BROWN), + /* + * vortices + */ + MON("fog cloud", S_VORTEX, LVL(3, 1, 0, 0, 0), (G_GENO | G_NOCORPSE | 2), + A(ATTK(AT_ENGL, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_AMORPHOUS | M1_UNSOLID, + M2_HOSTILE | M2_NEUTER, 0, CLR_GRAY), + MON("dust vortex", S_VORTEX, LVL(4, 20, 2, 30, 0), + (G_GENO | G_NOCORPSE | 2), A(ATTK(AT_ENGL, AD_BLND, 2, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS, + M2_HOSTILE | M2_NEUTER, 0, CLR_BROWN), + MON("ice vortex", S_VORTEX, LVL(5, 20, 2, 30, 0), + (G_NOHELL | G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_ENGL, AD_COLD, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), + MR_COLD | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_CYAN), + MON("energy vortex", S_VORTEX, LVL(6, 20, 2, 30, 0), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_ENGL, AD_ELEC, 1, 6), ATTK(AT_ENGL, AD_DREN, 4, 6), + ATTK(AT_NONE, AD_ELEC, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), + MR_ELEC | MR_SLEEP | MR_DISINT | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_UNSOLID, + M2_HOSTILE | M2_NEUTER, 0, HI_ZAP), + MON("steam vortex", S_VORTEX, LVL(7, 22, 2, 30, 0), + (G_HELL | G_GENO | G_NOCORPSE | 2), + A(ATTK(AT_ENGL, AD_FIRE, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), + MR_FIRE | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_UNSOLID, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_BLUE), + MON("fire vortex", S_VORTEX, LVL(8, 22, 2, 30, 0), + (G_HELL | G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_ENGL, AD_FIRE, 1, 10), ATTK(AT_NONE, AD_FIRE, 0, 4), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), + MR_FIRE | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_UNSOLID, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), + /* + * worms + */ + MON("baby long worm", S_WORM, LVL(5, 3, 5, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(600, 250, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_SLITHY | M1_NOLIMBS | M1_CARNIVORE | M1_NOTAKE, + M2_HOSTILE, 0, CLR_BROWN), + MON("baby purple worm", S_WORM, LVL(8, 3, 5, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(600, 250, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_SLITHY | M1_NOLIMBS | M1_CARNIVORE, M2_HOSTILE, 0, + CLR_MAGENTA), + MON("long worm", S_WORM, LVL(9, 3, 5, 10, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_SILENT, MZ_GIGANTIC), 0, 0, + M1_ANIMAL | M1_SLITHY | M1_NOLIMBS | M1_OVIPAROUS | M1_CARNIVORE + | M1_NOTAKE, + M2_HOSTILE | M2_STRONG | M2_NASTY, 0, CLR_BROWN), + MON("purple worm", S_WORM, LVL(15, 9, 6, 20, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 2, 8), ATTK(AT_ENGL, AD_DGST, 1, 10), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2700, 700, MS_SILENT, MZ_GIGANTIC), 0, 0, + M1_ANIMAL | M1_SLITHY | M1_NOLIMBS | M1_OVIPAROUS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY, 0, CLR_MAGENTA), + /* + * xan, &c + */ + MON("grid bug", S_XAN, LVL(0, 12, 9, 0, 0), + (G_GENO | G_SGROUP | G_NOCORPSE | 3), + A(ATTK(AT_BITE, AD_ELEC, 1, 1), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(15, 10, MS_BUZZ, MZ_TINY), MR_ELEC | MR_POISON, 0, M1_ANIMAL, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_MAGENTA), + MON("xan", S_XAN, LVL(7, 18, -4, 0, 0), (G_GENO | 3), + A(ATTK(AT_STNG, AD_LEGS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(300, 300, MS_BUZZ, MZ_TINY), MR_POISON, MR_POISON, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_POIS, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_RED), + /* + * lights + */ + MON("yellow light", S_LIGHT, LVL(3, 15, 0, 0, 0), + (G_NOCORPSE | G_GENO | 4), A(ATTK(AT_EXPL, AD_BLND, 10, 20), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_SMALL), + MR_FIRE | MR_COLD | MR_ELEC | MR_DISINT | MR_SLEEP | MR_POISON + | MR_ACID | MR_STONE, + 0, M1_FLY | M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS + | M1_NOHEAD | M1_MINDLESS | M1_UNSOLID | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), + MON("black light", S_LIGHT, LVL(5, 15, 0, 0, 0), + (G_NOCORPSE | G_GENO | 2), A(ATTK(AT_EXPL, AD_HALU, 10, 12), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_SMALL), + MR_FIRE | MR_COLD | MR_ELEC | MR_DISINT | MR_SLEEP | MR_POISON + | MR_ACID | MR_STONE, + 0, + M1_FLY | M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS + | M1_NOHEAD | M1_MINDLESS | M1_UNSOLID | M1_SEE_INVIS | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_BLACK), + /* + * zruty + */ + MON("zruty", S_ZRUTY, LVL(9, 8, 3, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), + ATTK(AT_BITE, AD_PHYS, 3, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 600, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, M2_HOSTILE | M2_STRONG, + M3_INFRAVISIBLE, CLR_BROWN), + /* + * Angels and other lawful minions + */ + MON("couatl", S_ANGEL, LVL(8, 10, 5, 30, 7), + (G_NOHELL | G_SGROUP | G_NOCORPSE | 1), + A(ATTK(AT_BITE, AD_DRST, 2, 4), ATTK(AT_BITE, AD_PHYS, 1, 3), + ATTK(AT_HUGS, AD_WRAP, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(900, 400, MS_HISS, MZ_LARGE), MR_POISON, 0, + M1_FLY | M1_NOHANDS | M1_SLITHY | M1_POIS, + M2_MINION | M2_STALK | M2_STRONG | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GREEN), + MON("Aleax", S_ANGEL, LVL(10, 8, 0, 30, 7), (G_NOHELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), + ATTK(AT_KICK, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_IMITATE, MZ_HUMAN), + MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_HUMANOID | M1_SEE_INVIS, + M2_MINION | M2_STALK | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_YELLOW), + /* Angels start with the emin extension attached, and usually have + the isminion flag set; however, non-minion Angels can be tamed + and will switch to edog (guardian Angel is handled specially and + always sticks with emin) */ + MON("Angel", S_ANGEL, LVL(14, 10, -4, 55, 12), + (G_NOHELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_MAGC, AD_MAGM, 2, 6), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_CUSS, MZ_HUMAN), + MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_HUMANOID | M1_SEE_INVIS, + M2_NOPOLY | M2_MINION | M2_STALK | M2_STRONG | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_WHITE), + MON("ki-rin", S_ANGEL, LVL(16, 18, -5, 90, 15), + (G_NOHELL | G_NOCORPSE | 1), + A(ATTK(AT_KICK, AD_PHYS, 2, 4), ATTK(AT_KICK, AD_PHYS, 2, 4), + ATTK(AT_BUTT, AD_PHYS, 3, 6), ATTK(AT_MAGC, AD_SPEL, 2, 6), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEIGH, MZ_LARGE), 0, 0, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_SEE_INVIS, + M2_NOPOLY | M2_MINION | M2_STALK | M2_STRONG | M2_NASTY | M2_LORD, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_GOLD), + MON("Archon", S_ANGEL, LVL(19, 16, -6, 80, 15), + (G_NOHELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), + ATTK(AT_GAZE, AD_BLND, 2, 6), ATTK(AT_CLAW, AD_PHYS, 1, 8), + ATTK(AT_MAGC, AD_SPEL, 4, 6), NO_ATTK), + SIZ(WT_HUMAN, 400, MS_CUSS, MZ_LARGE), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_HUMANOID | M1_SEE_INVIS | M1_REGEN, + M2_NOPOLY | M2_MINION | M2_STALK | M2_STRONG | M2_NASTY | M2_LORD + | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + /* + * Bats + */ + MON("bat", S_BAT, LVL(0, 22, 8, 0, 0), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(20, 20, MS_SQEEK, MZ_TINY), 0, 0, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_WANDER, + M3_INFRAVISIBLE, CLR_BROWN), + MON("giant bat", S_BAT, LVL(2, 22, 7, 0, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_SQEEK, MZ_SMALL), 0, 0, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_WANDER | M2_HOSTILE, M3_INFRAVISIBLE, CLR_RED), + MON("raven", S_BAT, LVL(4, 20, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_BLND, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(40, 20, MS_SQAWK, MZ_SMALL), 0, 0, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_WANDER | M2_HOSTILE, M3_INFRAVISIBLE, CLR_BLACK), + MON("vampire bat", S_BAT, LVL(5, 20, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_DRST, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(30, 20, MS_SQEEK, MZ_SMALL), MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_ANIMAL | M1_NOHANDS | M1_POIS | M1_REGEN | M1_OMNIVORE, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_BLACK), + /* + * Centaurs + */ + MON("plains centaur", S_CENTAUR, LVL(4, 18, 4, 0, 0), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_KICK, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2500, 500, MS_HUMANOID, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_STRONG | M2_GREEDY | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BROWN), + MON("forest centaur", S_CENTAUR, LVL(5, 18, 3, 10, -1), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_KICK, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2550, 600, MS_HUMANOID, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_STRONG | M2_GREEDY | M2_COLLECT, + M3_INFRAVISIBLE, CLR_GREEN), + MON("mountain centaur", S_CENTAUR, LVL(6, 20, 2, 10, -3), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 10), ATTK(AT_KICK, AD_PHYS, 1, 6), + ATTK(AT_KICK, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2550, 500, MS_HUMANOID, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_STRONG | M2_GREEDY | M2_COLLECT, + M3_INFRAVISIBLE, CLR_CYAN), + /* + * Dragons + */ + /* The order of the dragons is VERY IMPORTANT. Quite a few + * pieces of code depend on gray being first and yellow being last. + * The code also depends on the *order* being the same as that for + * dragon scale mail and dragon scales in objects.c. Baby dragons + * cannot confer intrinsics, to avoid polyself/egg abuse. + * + * As reptiles, dragons are cold-blooded and thus aren't seen + * with infravision. Red dragons are the exception. + */ + MON("baby gray dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), 0, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_GRAY), + MON("baby silver dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), 0, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, DRAGON_SILVER), +#if 0 /* DEFERRED */ MON("baby shimmering dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, A(ATTK(AT_BITE, AD_PHYS, 2, 6), @@ -1205,75 +1112,68 @@ NEARDATA struct permonst mons[] = { M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_CYAN), #endif - MON("baby red dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_FIRE, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, M3_INFRAVISIBLE, CLR_RED), - MON("baby white dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_COLD, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_WHITE), - MON("baby orange dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_SLEEP, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_ORANGE), - MON("baby black dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_DISINT, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_BLACK), - MON("baby blue dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_ELEC, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_BLUE), - MON("baby green dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_POISON, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE|M1_POIS, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_GREEN), - MON("baby yellow dragon", S_DRAGON, - LVL(12, 9, 2, 10, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_ACID|MR_STONE, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE|M1_ACID, - M2_HOSTILE|M2_STRONG|M2_GREEDY|M2_JEWELS, 0, CLR_YELLOW), - MON("gray dragon", S_DRAGON, - LVL(15, 9, -1, 20, 4), (G_GENO|1), - A(ATTK(AT_BREA, AD_MAGM, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), 0, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_GRAY), - MON("silver dragon", S_DRAGON, - LVL(15, 9, -1, 20, 4), (G_GENO|1), - A(ATTK(AT_BREA, AD_COLD, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_COLD, 0, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, - 0, DRAGON_SILVER), -#if 0 /* DEFERRED */ + MON("baby red dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_FIRE, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, M3_INFRAVISIBLE, + CLR_RED), + MON("baby white dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_COLD, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_WHITE), + MON("baby orange dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_SLEEP, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_ORANGE), + MON("baby black dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_DISINT, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_BLACK), + MON("baby blue dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_ELEC, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_BLUE), + MON("baby green dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_POISON, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE | M1_POIS, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_GREEN), + MON("baby yellow dragon", S_DRAGON, LVL(12, 9, 2, 10, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_ROAR, MZ_HUGE), MR_ACID | MR_STONE, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE | M1_ACID, + M2_HOSTILE | M2_STRONG | M2_GREEDY | M2_JEWELS, 0, CLR_YELLOW), + MON("gray dragon", S_DRAGON, LVL(15, 9, -1, 20, 4), (G_GENO | 1), + A(ATTK(AT_BREA, AD_MAGM, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), 0, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_GRAY), + MON("silver dragon", S_DRAGON, LVL(15, 9, -1, 20, 4), (G_GENO | 1), + A(ATTK(AT_BREA, AD_COLD, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_COLD, 0, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, DRAGON_SILVER), +#if 0 /* DEFERRED */ MON("shimmering dragon", S_DRAGON, LVL(15, 9, -1, 20, 4), (G_GENO|1), A(ATTK(AT_BREA, AD_MAGM, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), @@ -1285,198 +1185,185 @@ NEARDATA struct permonst mons[] = { M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_CYAN), #endif - MON("red dragon", S_DRAGON, - LVL(15, 9, -1, 20, -4), (G_GENO|1), - A(ATTK(AT_BREA, AD_FIRE, 6, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_FIRE, MR_FIRE, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, - M3_INFRAVISIBLE, CLR_RED), - MON("white dragon", S_DRAGON, - LVL(15, 9, -1, 20, -5), (G_GENO|1), - A(ATTK(AT_BREA, AD_COLD, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_COLD, MR_COLD, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_WHITE), - MON("orange dragon", S_DRAGON, - LVL(15, 9, -1, 20, 5), (G_GENO|1), - A(ATTK(AT_BREA, AD_SLEE, 4,25), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_SLEEP, MR_SLEEP, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, - 0, CLR_ORANGE), - MON("black dragon", S_DRAGON, - LVL(15, 9, -1, 20, -6), (G_GENO|1), - A(ATTK(AT_BREA, AD_DISN, 4,10), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_DISINT, MR_DISINT, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_BLACK), - MON("blue dragon", S_DRAGON, - LVL(15, 9, -1, 20, -7), (G_GENO|1), - A(ATTK(AT_BREA, AD_ELEC, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_ELEC, MR_ELEC, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_BLUE), - MON("green dragon", S_DRAGON, - LVL(15, 9, -1, 20, 6), (G_GENO|1), - A(ATTK(AT_BREA, AD_DRST, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_POISON, MR_POISON, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE|M1_POIS, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, 0, CLR_GREEN), - MON("yellow dragon", S_DRAGON, - LVL(15, 9, -1, 20, 7), (G_GENO|1), - A(ATTK(AT_BREA, AD_ACID, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), - ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), - MR_ACID|MR_STONE, MR_STONE, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_SEE_INVIS|M1_OVIPAROUS| - M1_CARNIVORE|M1_ACID, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_GREEDY|M2_JEWELS|M2_MAGIC, - 0, CLR_YELLOW), -/* - * Elementals - */ - MON("stalker", S_ELEMENTAL, - LVL(8, 12, 3, 0, 0), (G_GENO|3), - A(ATTK(AT_CLAW, AD_PHYS, 4, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 400, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_FLY|M1_SEE_INVIS, - M2_WANDER|M2_STALK|M2_HOSTILE|M2_STRONG, M3_INFRAVISION, CLR_WHITE), - MON("air elemental", S_ELEMENTAL, - LVL(8, 36, 2, 30, 0), (G_NOCORPSE|1), - A(ATTK(AT_ENGL, AD_PHYS, 1, 10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_POISON|MR_STONE, 0, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_BREATHLESS|M1_UNSOLID|M1_FLY, - M2_STRONG|M2_NEUTER, 0, CLR_CYAN), - MON("fire elemental", S_ELEMENTAL, - LVL(8, 12, 2, 30, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_FIRE, 3, 6), ATTK(AT_NONE, AD_FIRE, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_FIRE|MR_POISON|MR_STONE, 0, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_BREATHLESS|M1_UNSOLID|M1_FLY|M1_NOTAKE, - M2_STRONG|M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), - MON("earth elemental", S_ELEMENTAL, - LVL(8, 6, 2, 30, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 4, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2500, 0, MS_SILENT, MZ_HUGE), - MR_FIRE|MR_COLD|MR_POISON|MR_STONE, 0, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_BREATHLESS| - M1_WALLWALK|M1_THICK_HIDE, - M2_STRONG|M2_NEUTER, 0, CLR_BROWN), - MON("water elemental", S_ELEMENTAL, - LVL(8, 6, 2, 30, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 5, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2500, 0, MS_SILENT, MZ_HUGE), MR_POISON|MR_STONE, 0, - M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_BREATHLESS|M1_UNSOLID| - M1_AMPHIBIOUS|M1_SWIM, - M2_STRONG|M2_NEUTER, 0, CLR_BLUE), -/* - * Fungi - */ - MON("lichen", S_FUNGUS, - LVL(0, 1, 9, 0, 0), (G_GENO|4), - A(ATTK(AT_TUCH, AD_STCK, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(20, 200, MS_SILENT, MZ_SMALL), 0, 0, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_BRIGHT_GREEN), - MON("brown mold", S_FUNGUS, - LVL(1, 0, 9, 0, 0), (G_GENO|1), - A(ATTK(AT_NONE, AD_COLD, 0, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 30, MS_SILENT, MZ_SMALL), - MR_COLD|MR_POISON, MR_COLD|MR_POISON, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_BROWN), - MON("yellow mold", S_FUNGUS, - LVL(1, 0, 9, 0, 0), (G_GENO|2), - A(ATTK(AT_NONE, AD_STUN, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_POIS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_YELLOW), - MON("green mold", S_FUNGUS, - LVL(1, 0, 9, 0, 0), (G_GENO|1), - A(ATTK(AT_NONE, AD_ACID, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_ACID|MR_STONE, MR_STONE, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_ACID|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_GREEN), - MON("red mold", S_FUNGUS, - LVL(1, 0, 9, 0, 0), (G_GENO|1), - A(ATTK(AT_NONE, AD_FIRE, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 30, MS_SILENT, MZ_SMALL), - MR_FIRE|MR_POISON, MR_FIRE|MR_POISON, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, M3_INFRAVISIBLE, CLR_RED), - MON("shrieker", S_FUNGUS, - LVL(3, 1, 7, 0, 0), (G_GENO|1), - A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 100, MS_SHRIEK, MZ_SMALL), MR_POISON, MR_POISON, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_MAGENTA), - MON("violet fungus", S_FUNGUS, - LVL(3, 1, 7, 0, 0), (G_GENO|2), - A(ATTK(AT_TUCH, AD_PHYS, 1, 4), ATTK(AT_TUCH, AD_STCK, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 100, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, - M1_BREATHLESS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD|M1_MINDLESS|M1_NOTAKE, - M2_HOSTILE|M2_NEUTER, 0, CLR_MAGENTA), -/* - * Gnomes - */ - MON("gnome", S_GNOME, - LVL(1, 6, 10, 4, 0), (G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(650, 100, MS_ORC, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_NOPOLY|M2_GNOME|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("gnome lord", S_GNOME, - LVL(3, 8, 10, 4, 0), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(700, 120, MS_ORC, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_GNOME|M2_LORD|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - MON("gnomish wizard", S_GNOME, - LVL(3, 10, 4, 10, 0), (G_GENO|1), - A(ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(700, 120, MS_ORC, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_GNOME|M2_MAGIC, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_ZAP), - MON("gnome king", S_GNOME, - LVL(5, 10, 10, 20, 0), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(750, 150, MS_ORC, MZ_SMALL), 0, 0, - M1_HUMANOID|M1_OMNIVORE, M2_GNOME|M2_PRINCE|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), + MON("red dragon", S_DRAGON, LVL(15, 9, -1, 20, -4), (G_GENO | 1), + A(ATTK(AT_BREA, AD_FIRE, 6, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_FIRE, MR_FIRE, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + M3_INFRAVISIBLE, CLR_RED), + MON("white dragon", S_DRAGON, LVL(15, 9, -1, 20, -5), (G_GENO | 1), + A(ATTK(AT_BREA, AD_COLD, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_COLD, MR_COLD, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_WHITE), + MON("orange dragon", S_DRAGON, LVL(15, 9, -1, 20, 5), (G_GENO | 1), + A(ATTK(AT_BREA, AD_SLEE, 4, 25), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_SLEEP, MR_SLEEP, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_ORANGE), + MON("black dragon", S_DRAGON, LVL(15, 9, -1, 20, -6), (G_GENO | 1), + A(ATTK(AT_BREA, AD_DISN, 4, 10), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_DISINT, MR_DISINT, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_BLACK), + MON("blue dragon", S_DRAGON, LVL(15, 9, -1, 20, -7), (G_GENO | 1), + A(ATTK(AT_BREA, AD_ELEC, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_ELEC, MR_ELEC, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_BLUE), + MON("green dragon", S_DRAGON, LVL(15, 9, -1, 20, 6), (G_GENO | 1), + A(ATTK(AT_BREA, AD_DRST, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_POISON, MR_POISON, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS | M1_OVIPAROUS + | M1_CARNIVORE | M1_POIS, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_GREEN), + MON("yellow dragon", S_DRAGON, LVL(15, 9, -1, 20, 7), (G_GENO | 1), + A(ATTK(AT_BREA, AD_ACID, 4, 6), ATTK(AT_BITE, AD_PHYS, 3, 8), + ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_DRAGON, 1500, MS_ROAR, MZ_GIGANTIC), MR_ACID | MR_STONE, + MR_STONE, M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_SEE_INVIS + | M1_OVIPAROUS | M1_CARNIVORE | M1_ACID, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_GREEDY | M2_JEWELS | M2_MAGIC, + 0, CLR_YELLOW), + /* + * Elementals + */ + MON("stalker", S_ELEMENTAL, LVL(8, 12, 3, 0, 0), (G_GENO | 3), + A(ATTK(AT_CLAW, AD_PHYS, 4, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(900, 400, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_FLY | M1_SEE_INVIS, + M2_WANDER | M2_STALK | M2_HOSTILE | M2_STRONG, M3_INFRAVISION, + CLR_WHITE), + MON("air elemental", S_ELEMENTAL, LVL(8, 36, 2, 30, 0), (G_NOCORPSE | 1), + A(ATTK(AT_ENGL, AD_PHYS, 1, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_POISON | MR_STONE, 0, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS | M1_BREATHLESS + | M1_UNSOLID | M1_FLY, + M2_STRONG | M2_NEUTER, 0, CLR_CYAN), + MON("fire elemental", S_ELEMENTAL, LVL(8, 12, 2, 30, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_FIRE, 3, 6), ATTK(AT_NONE, AD_FIRE, 0, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUGE), MR_FIRE | MR_POISON | MR_STONE, 0, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS | M1_BREATHLESS + | M1_UNSOLID | M1_FLY | M1_NOTAKE, + M2_STRONG | M2_NEUTER, M3_INFRAVISIBLE, CLR_YELLOW), + MON("earth elemental", S_ELEMENTAL, LVL(8, 6, 2, 30, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 4, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2500, 0, MS_SILENT, MZ_HUGE), + MR_FIRE | MR_COLD | MR_POISON | MR_STONE, 0, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS | M1_BREATHLESS + | M1_WALLWALK | M1_THICK_HIDE, + M2_STRONG | M2_NEUTER, 0, CLR_BROWN), + MON("water elemental", S_ELEMENTAL, LVL(8, 6, 2, 30, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 5, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2500, 0, MS_SILENT, MZ_HUGE), MR_POISON | MR_STONE, 0, + M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS | M1_BREATHLESS + | M1_UNSOLID | M1_AMPHIBIOUS | M1_SWIM, + M2_STRONG | M2_NEUTER, 0, CLR_BLUE), + /* + * Fungi + */ + MON("lichen", S_FUNGUS, LVL(0, 1, 9, 0, 0), (G_GENO | 4), + A(ATTK(AT_TUCH, AD_STCK, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(20, 200, MS_SILENT, MZ_SMALL), 0, 0, + M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_BRIGHT_GREEN), + MON("brown mold", S_FUNGUS, LVL(1, 0, 9, 0, 0), (G_GENO | 1), + A(ATTK(AT_NONE, AD_COLD, 0, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_COLD | MR_POISON, + MR_COLD | MR_POISON, M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS + | M1_NOHEAD | M1_MINDLESS | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_BROWN), + MON("yellow mold", S_FUNGUS, LVL(1, 0, 9, 0, 0), (G_GENO | 2), + A(ATTK(AT_NONE, AD_STUN, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, + M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_POIS | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_YELLOW), + MON("green mold", S_FUNGUS, LVL(1, 0, 9, 0, 0), (G_GENO | 1), + A(ATTK(AT_NONE, AD_ACID, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_ACID | MR_STONE, MR_STONE, + M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_ACID | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_GREEN), + MON("red mold", S_FUNGUS, LVL(1, 0, 9, 0, 0), (G_GENO | 1), + A(ATTK(AT_NONE, AD_FIRE, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 30, MS_SILENT, MZ_SMALL), MR_FIRE | MR_POISON, + MR_FIRE | MR_POISON, M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS + | M1_NOHEAD | M1_MINDLESS | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, M3_INFRAVISIBLE, CLR_RED), + MON("shrieker", S_FUNGUS, LVL(3, 1, 7, 0, 0), (G_GENO | 1), + A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(100, 100, MS_SHRIEK, MZ_SMALL), MR_POISON, MR_POISON, + M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_MAGENTA), + MON("violet fungus", S_FUNGUS, LVL(3, 1, 7, 0, 0), (G_GENO | 2), + A(ATTK(AT_TUCH, AD_PHYS, 1, 4), ATTK(AT_TUCH, AD_STCK, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(100, 100, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, + M1_BREATHLESS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD | M1_MINDLESS + | M1_NOTAKE, + M2_HOSTILE | M2_NEUTER, 0, CLR_MAGENTA), + /* + * Gnomes + */ + MON("gnome", S_GNOME, LVL(1, 6, 10, 4, 0), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(650, 100, MS_ORC, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_GNOME | M2_COLLECT, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BROWN), + MON("gnome lord", S_GNOME, LVL(3, 8, 10, 4, 0), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(700, 120, MS_ORC, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_GNOME | M2_LORD | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), + MON("gnomish wizard", S_GNOME, LVL(3, 10, 4, 10, 0), (G_GENO | 1), + A(ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(700, 120, MS_ORC, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_GNOME | M2_MAGIC, M3_INFRAVISIBLE | M3_INFRAVISION, HI_ZAP), + MON("gnome king", S_GNOME, LVL(5, 10, 10, 20, 0), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(750, 150, MS_ORC, MZ_SMALL), 0, 0, M1_HUMANOID | M1_OMNIVORE, + M2_GNOME | M2_PRINCE | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), #ifdef SPLITMON_1 }; #endif @@ -1496,96 +1383,88 @@ NEARDATA struct permonst mons[] = { #ifdef SPLITMON_2 struct permonst _mons2[] = { #endif -/* - * giant Humanoids - */ - MON("giant", S_GIANT, - LVL(6, 6, 0, 0, 2), (G_GENO|G_NOGEN|1), - A(ATTK(AT_WEAP, AD_PHYS, 2,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 750, MS_BOAST, MZ_HUGE), 0, 0, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("stone giant", S_GIANT, - LVL(6, 6, 0, 0, 2), (G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 2,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 750, MS_BOAST, MZ_HUGE), 0, 0, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("hill giant", S_GIANT, - LVL(8, 10, 6, 0, -2), (G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2200, 700, MS_BOAST, MZ_HUGE), 0, 0, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_CYAN), - MON("fire giant", S_GIANT, - LVL(9, 12, 4, 5, 2), (G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 2,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_FIRE, MR_FIRE, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_YELLOW), - MON("frost giant", S_GIANT, - LVL(10, 12, 3, 10, -3), (G_NOHELL|G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 2,12), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_COLD, MR_COLD, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_WHITE), - MON("ettin", S_GIANT, - LVL(10, 12, 3, 0, 0), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_WEAP, AD_PHYS, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 500, MS_GRUNT, MZ_HUGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("storm giant", S_GIANT, - LVL(16, 12, 3, 10, -3), (G_GENO|G_SGROUP|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 12), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_ELEC, MR_ELEC, - M1_HUMANOID|M1_CARNIVORE, - M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_JEWELS, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - MON("titan", S_GIANT, - LVL(16, 18, -3, 70, 9), (1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2300, 900, MS_SPELL, MZ_HUGE), 0, 0, - M1_FLY|M1_HUMANOID|M1_OMNIVORE, - M2_STRONG|M2_ROCKTHROW|M2_NASTY|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_MAGENTA), - MON("minotaur", S_GIANT, - LVL(15, 15, 6, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_CLAW, AD_PHYS, 3,10), ATTK(AT_CLAW, AD_PHYS, 3,10), - ATTK(AT_BUTT, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 700, MS_SILENT, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_BROWN), -/* 'I' is a visual marker for all invisible monsters and must be unused */ -/* - * Jabberwock - */ - /* the illustration from _Through_the_Looking_Glass_ - depicts hands as well as wings */ - MON("jabberwock", S_JABBERWOCK, - LVL(15, 12, -2, 50, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2,10), ATTK(AT_BITE, AD_PHYS, 2,10), - ATTK(AT_CLAW, AD_PHYS, 2,10), ATTK(AT_CLAW, AD_PHYS, 2,10), - NO_ATTK, NO_ATTK), - SIZ(1300, 600, MS_BURBLE, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_FLY|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY|M2_COLLECT, M3_INFRAVISIBLE, CLR_ORANGE), -#if 0 /* DEFERRED */ + /* + * giant Humanoids + */ + MON("giant", S_GIANT, LVL(6, 6, 0, 0, 2), (G_GENO | G_NOGEN | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2250, 750, MS_BOAST, MZ_HUGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_GIANT | M2_STRONG | M2_ROCKTHROW | M2_NASTY | M2_COLLECT + | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("stone giant", S_GIANT, LVL(6, 6, 0, 0, 2), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2250, 750, MS_BOAST, MZ_HUGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_GIANT | M2_STRONG | M2_ROCKTHROW | M2_NASTY | M2_COLLECT + | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("hill giant", S_GIANT, LVL(8, 10, 6, 0, -2), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2200, 700, MS_BOAST, MZ_HUGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_GIANT | M2_STRONG | M2_ROCKTHROW | M2_NASTY | M2_COLLECT + | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_CYAN), + MON("fire giant", S_GIANT, LVL(9, 12, 4, 5, 2), (G_GENO | G_SGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_FIRE, MR_FIRE, + M1_HUMANOID | M1_CARNIVORE, M2_GIANT | M2_STRONG | M2_ROCKTHROW + | M2_NASTY | M2_COLLECT | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_YELLOW), + MON("frost giant", S_GIANT, LVL(10, 12, 3, 10, -3), + (G_NOHELL | G_GENO | G_SGROUP | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 12), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_COLD, MR_COLD, + M1_HUMANOID | M1_CARNIVORE, M2_GIANT | M2_STRONG | M2_ROCKTHROW + | M2_NASTY | M2_COLLECT | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_WHITE), + MON("ettin", S_GIANT, LVL(10, 12, 3, 0, 0), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_WEAP, AD_PHYS, 3, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1700, 500, MS_GRUNT, MZ_HUGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("storm giant", S_GIANT, LVL(16, 12, 3, 10, -3), + (G_GENO | G_SGROUP | 1), A(ATTK(AT_WEAP, AD_PHYS, 2, 12), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2250, 750, MS_BOAST, MZ_HUGE), MR_ELEC, MR_ELEC, + M1_HUMANOID | M1_CARNIVORE, M2_GIANT | M2_STRONG | M2_ROCKTHROW + | M2_NASTY | M2_COLLECT | M2_JEWELS, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), + MON("titan", S_GIANT, LVL(16, 18, -3, 70, 9), (1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2300, 900, MS_SPELL, MZ_HUGE), 0, 0, + M1_FLY | M1_HUMANOID | M1_OMNIVORE, + M2_STRONG | M2_ROCKTHROW | M2_NASTY | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_MAGENTA), + MON("minotaur", S_GIANT, LVL(15, 15, 6, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_CLAW, AD_PHYS, 3, 10), ATTK(AT_CLAW, AD_PHYS, 3, 10), + ATTK(AT_BUTT, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 700, MS_SILENT, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BROWN), + /* 'I' is a visual marker for all invisible monsters and must be unused */ + /* + * Jabberwock + */ + /* the illustration from _Through_the_Looking_Glass_ + depicts hands as well as wings */ + MON("jabberwock", S_JABBERWOCK, LVL(15, 12, -2, 50, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 10), ATTK(AT_BITE, AD_PHYS, 2, 10), + ATTK(AT_CLAW, AD_PHYS, 2, 10), ATTK(AT_CLAW, AD_PHYS, 2, 10), + NO_ATTK, NO_ATTK), + SIZ(1300, 600, MS_BURBLE, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_FLY | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY | M2_COLLECT, M3_INFRAVISIBLE, + CLR_ORANGE), +#if 0 /* DEFERRED */ MON("vorpal jabberwock", S_JABBERWOCK, LVL(20, 12, -2, 50, 0), (G_GENO|1), A(ATTK(AT_BITE, AD_PHYS, 3, 10), ATTK(AT_BITE, AD_PHYS, 3, 10), @@ -1595,422 +1474,388 @@ struct permonst _mons2[] = { M1_ANIMAL|M1_FLY|M1_CARNIVORE, M2_HOSTILE|M2_STRONG|M2_NASTY|M2_COLLECT, M3_INFRAVISIBLE, HI_LORD), #endif -/* - * Kops - */ - MON("Keystone Kop", S_KOP, - LVL(1, 6, 10, 10, 9), (G_GENO|G_LGROUP|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, - M2_HUMAN|M2_WANDER|M2_HOSTILE|M2_MALE|M2_COLLECT, M3_INFRAVISIBLE, - CLR_BLUE), - MON("Kop Sergeant", S_KOP, - LVL(2, 8, 10, 10, 10), (G_GENO|G_SGROUP|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, - M2_HUMAN|M2_WANDER|M2_HOSTILE|M2_STRONG|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE, CLR_BLUE), - MON("Kop Lieutenant", S_KOP, - LVL(3, 10, 10, 20, 11), (G_GENO|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, - M2_HUMAN|M2_WANDER|M2_HOSTILE|M2_STRONG|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE, CLR_CYAN), - MON("Kop Kaptain", S_KOP, - LVL(4, 12, 10, 20, 12), (G_GENO|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, - M2_HUMAN|M2_WANDER|M2_HOSTILE|M2_STRONG|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE, HI_LORD), -/* - * Liches - */ - MON("lich", S_LICH, - LVL(11, 6, 0, 30, -9), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_TUCH, AD_COLD, 1,10), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, MR_COLD, - M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_HOSTILE|M2_MAGIC, M3_INFRAVISION, CLR_BROWN), - MON("demilich", S_LICH, - LVL(14, 9, -2, 60, -12), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_TUCH, AD_COLD, 3, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, MR_COLD, - M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_HOSTILE|M2_MAGIC, M3_INFRAVISION, CLR_RED), - MON("master lich", S_LICH, - LVL(17, 9, -4, 90, -15), (G_HELL|G_GENO|G_NOCORPSE|1), - A(ATTK(AT_TUCH, AD_COLD, 3, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_SLEEP|MR_POISON, MR_FIRE|MR_COLD, - M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_HOSTILE|M2_MAGIC, M3_WANTSBOOK|M3_INFRAVISION, HI_LORD), - MON("arch-lich", S_LICH, - LVL(25, 9, -6, 90, -15), (G_HELL|G_GENO|G_NOCORPSE|1), - A(ATTK(AT_TUCH, AD_COLD, 5, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_SLEEP|MR_ELEC|MR_POISON, MR_FIRE|MR_COLD, - M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_HOSTILE|M2_MAGIC, M3_WANTSBOOK|M3_INFRAVISION, HI_LORD), -/* - * Mummies - */ - MON("kobold mummy", S_MUMMY, - LVL(3, 8, 6, 20, -2), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 50, MS_SILENT, MZ_SMALL), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE, M3_INFRAVISION, CLR_BROWN), - MON("gnome mummy", S_MUMMY, - LVL(4, 10, 6, 20, -3), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(650, 50, MS_SILENT, MZ_SMALL), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_GNOME, M3_INFRAVISION, CLR_RED), - MON("orc mummy", S_MUMMY, - LVL(5, 10, 5, 20, -4), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(850, 75, MS_SILENT, MZ_HUMAN), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_ORC|M2_GREEDY|M2_JEWELS, M3_INFRAVISION, - CLR_GRAY), - MON("dwarf mummy", S_MUMMY, - LVL(5, 10, 5, 20, -4), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 150, MS_SILENT, MZ_HUMAN), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_DWARF|M2_GREEDY|M2_JEWELS, M3_INFRAVISION, - CLR_RED), - MON("elf mummy", S_MUMMY, - LVL(6, 12, 4, 30, -5), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 175, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_ELF, M3_INFRAVISION, CLR_GREEN), - MON("human mummy", S_MUMMY, - LVL(6, 12, 4, 30, -5), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE, M3_INFRAVISION, CLR_GRAY), - MON("ettin mummy", S_MUMMY, - LVL(7, 12, 4, 30, -6), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 250, MS_SILENT, MZ_HUGE), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_STRONG, M3_INFRAVISION, CLR_BLUE), - MON("giant mummy", S_MUMMY, - LVL(8, 14, 3, 30, -7), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2050, 375, MS_SILENT, MZ_HUGE), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_HOSTILE|M2_GIANT|M2_STRONG|M2_JEWELS, M3_INFRAVISION, - CLR_CYAN), -/* - * Nagas - */ - MON("red naga hatchling", S_NAGA, - LVL(3, 10, 6, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 100, MS_MUMBLE, MZ_LARGE), - MR_FIRE|MR_POISON, MR_FIRE|MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_NOTAKE|M1_OMNIVORE, M2_STRONG, - M3_INFRAVISIBLE, CLR_RED), - MON("black naga hatchling", S_NAGA, - LVL(3, 10, 6, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 100, MS_MUMBLE, MZ_LARGE), - MR_POISON|MR_ACID|MR_STONE, MR_POISON|MR_STONE, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_ACID|M1_NOTAKE|M1_CARNIVORE, - M2_STRONG, 0, CLR_BLACK), - MON("golden naga hatchling", S_NAGA, - LVL(3, 10, 6, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_POISON, MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_NOTAKE|M1_OMNIVORE, - M2_STRONG, 0, HI_GOLD), - MON("guardian naga hatchling", S_NAGA, - LVL(3, 10, 6, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_POISON, MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_NOTAKE|M1_OMNIVORE, - M2_STRONG, 0, CLR_GREEN), - MON("red naga", S_NAGA, - LVL(6, 12, 4, 0, -4), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_BREA, AD_FIRE, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), - MR_FIRE|MR_POISON, MR_FIRE|MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_OVIPAROUS|M1_NOTAKE|M1_OMNIVORE, - M2_STRONG, M3_INFRAVISIBLE, CLR_RED), - MON("black naga", S_NAGA, - LVL(8, 14, 2, 10, 4), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_SPIT, AD_ACID, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), - MR_POISON|MR_ACID|MR_STONE, MR_POISON|MR_STONE, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_OVIPAROUS|M1_ACID|M1_NOTAKE| - M1_CARNIVORE, - M2_STRONG, 0, CLR_BLACK), - MON("golden naga", S_NAGA, - LVL(10, 14, 2, 70, 5), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_MAGC, AD_SPEL, 4, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_POISON, MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_OVIPAROUS|M1_NOTAKE|M1_OMNIVORE, - M2_STRONG, 0, HI_GOLD), - MON("guardian naga", S_NAGA, - LVL(12, 16, 0, 50, 7), (G_GENO|1), - A(ATTK(AT_BITE, AD_PLYS, 1, 6), ATTK(AT_SPIT, AD_DRST, 1, 6), - ATTK(AT_HUGS, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_POISON, MR_POISON, - M1_NOLIMBS|M1_SLITHY|M1_THICK_HIDE|M1_OVIPAROUS|M1_POIS|M1_NOTAKE| - M1_OMNIVORE, - M2_STRONG, 0, CLR_GREEN), -/* - * Ogres - */ - MON("ogre", S_OGRE, - LVL(5, 10, 5, 0, -3), (G_SGROUP|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 5), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1600, 500, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID|M1_CARNIVORE, - M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BROWN), - MON("ogre lord", S_OGRE, - LVL(7, 12, 3, 30, -5), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 700, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID|M1_CARNIVORE, - M2_STRONG|M2_LORD|M2_MALE|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("ogre king", S_OGRE, - LVL(9, 14, 4, 60, -7), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 3, 5), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 750, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID|M1_CARNIVORE, - M2_STRONG|M2_PRINCE|M2_MALE|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), -/* - * Puddings - * - * must be in the same order as the pudding globs in objects.c - */ - MON("gray ooze", S_PUDDING, - LVL(3, 1, 8, 0, 0), (G_GENO|G_NOCORPSE|2), - A(ATTK(AT_BITE, AD_RUST, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 250, MS_SILENT, MZ_MEDIUM), - MR_FIRE|MR_COLD|MR_POISON|MR_ACID|MR_STONE, MR_FIRE|MR_COLD|MR_POISON, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_OMNIVORE|M1_ACID, - M2_HOSTILE|M2_NEUTER, 0, CLR_GRAY), - MON("brown pudding", S_PUDDING, - LVL(5, 3, 8, 0, 0), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_BITE, AD_DCAY, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 250, MS_SILENT, MZ_MEDIUM), - MR_COLD|MR_ELEC|MR_POISON|MR_ACID|MR_STONE, MR_COLD|MR_ELEC|MR_POISON, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_OMNIVORE|M1_ACID, - M2_HOSTILE|M2_NEUTER, 0, CLR_BROWN), - MON("green slime", S_PUDDING, - LVL(6, 6, 6, 0, 0), (G_HELL|G_GENO|G_NOCORPSE|1), - A(ATTK(AT_TUCH, AD_SLIM, 1, 4), ATTK(AT_NONE, AD_SLIM, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 150, MS_SILENT, MZ_LARGE), - MR_COLD|MR_ELEC|MR_POISON|MR_ACID|MR_STONE, 0, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_OMNIVORE|M1_ACID|M1_POIS, - M2_HOSTILE|M2_NEUTER, 0, CLR_GREEN), - MON("black pudding", S_PUDDING, - LVL(10, 6, 6, 0, 0), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_BITE, AD_CORR, 3, 8), ATTK(AT_NONE, AD_CORR, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 250, MS_SILENT, MZ_LARGE), - MR_COLD|MR_ELEC|MR_POISON|MR_ACID|MR_STONE, MR_COLD|MR_ELEC|MR_POISON, - M1_BREATHLESS|M1_AMORPHOUS|M1_NOEYES|M1_NOLIMBS|M1_NOHEAD| - M1_MINDLESS|M1_OMNIVORE|M1_ACID, - M2_HOSTILE|M2_NEUTER, 0, CLR_BLACK), -/* - * Quantum mechanics - */ - MON("quantum mechanic", S_QUANTMECH, - LVL(7, 12, 3, 10, 0), (G_GENO|3), - A(ATTK(AT_CLAW, AD_TLPT, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 20, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE|M1_POIS|M1_TPORT, M2_HOSTILE, M3_INFRAVISIBLE, - CLR_CYAN), -/* - * Rust monster or disenchanter - */ - MON("rust monster", S_RUSTMONST, - LVL(5, 18, 2, 0, 0), (G_GENO|2), - A(ATTK(AT_TUCH, AD_RUST, 0, 0), ATTK(AT_TUCH, AD_RUST, 0, 0), - ATTK(AT_NONE, AD_RUST, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 250, MS_SILENT, MZ_MEDIUM), 0, 0, - M1_SWIM|M1_ANIMAL|M1_NOHANDS|M1_METALLIVORE, M2_HOSTILE, - M3_INFRAVISIBLE, CLR_BROWN), - MON("disenchanter", S_RUSTMONST, - LVL(12, 12, -10, 0, -3), (G_HELL|G_GENO|2), - A(ATTK(AT_CLAW, AD_ENCH, 4, 4), ATTK(AT_NONE, AD_ENCH, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(750, 200, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_CARNIVORE, M2_HOSTILE, - M3_INFRAVISIBLE, CLR_BLUE), -/* - * Snakes - */ - MON("garter snake", S_SNAKE, - LVL(1, 8, 8, 0, 0), (G_LGROUP|G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(50, 60, MS_HISS, MZ_TINY), 0, 0, - M1_SWIM|M1_CONCEAL|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY|M1_OVIPAROUS| - M1_CARNIVORE|M1_NOTAKE, - 0, 0, CLR_GREEN), - MON("snake", S_SNAKE, - LVL(4, 15, 3, 0, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_DRST, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 80, MS_HISS, MZ_SMALL), MR_POISON, MR_POISON, - M1_SWIM|M1_CONCEAL|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY|M1_POIS| - M1_OVIPAROUS|M1_CARNIVORE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_BROWN), - MON("water moccasin", S_SNAKE, - LVL(4, 15, 3, 0, 0), (G_GENO|G_NOGEN|G_LGROUP), - A(ATTK(AT_BITE, AD_DRST, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(150, 80, MS_HISS, MZ_SMALL), MR_POISON, MR_POISON, - M1_SWIM|M1_CONCEAL|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY|M1_POIS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, 0, CLR_RED), - MON("python", S_SNAKE, - LVL(6, 3, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 1, 4), ATTK(AT_TUCH, AD_PHYS, 0, 0), - ATTK(AT_HUGS, AD_WRAP, 1, 4), ATTK(AT_HUGS, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK), - SIZ(250, 100, MS_HISS, MZ_LARGE), 0, 0, - M1_SWIM|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE|M2_STRONG, M3_INFRAVISION, CLR_MAGENTA), - MON("pit viper", S_SNAKE, - LVL(6, 15, 2, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_DRST, 1, 4), ATTK(AT_BITE, AD_DRST, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 60, MS_HISS, MZ_MEDIUM), - MR_POISON, MR_POISON, - M1_SWIM|M1_CONCEAL|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY|M1_POIS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, M3_INFRAVISION, CLR_BLUE), - MON("cobra", S_SNAKE, - LVL(6, 18, 2, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_DRST, 2, 4), ATTK(AT_SPIT, AD_BLND, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(250, 100, MS_HISS, MZ_MEDIUM), - MR_POISON, MR_POISON, - M1_SWIM|M1_CONCEAL|M1_NOLIMBS|M1_ANIMAL|M1_SLITHY|M1_POIS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, 0, CLR_BLUE), -/* - * Trolls - */ - MON("troll", S_TROLL, - LVL(7, 12, 4, 0, -3), (G_GENO|2), - A(ATTK(AT_WEAP, AD_PHYS, 4, 2), ATTK(AT_CLAW, AD_PHYS, 4, 2), - ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 350, MS_GRUNT, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_REGEN|M1_CARNIVORE, - M2_STRONG|M2_STALK|M2_HOSTILE, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_BROWN), - MON("ice troll", S_TROLL, - LVL(9, 10, 2, 20, -3), (G_NOHELL|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_COLD, 2, 6), - ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1000, 300, MS_GRUNT, MZ_LARGE), MR_COLD, MR_COLD, - M1_HUMANOID|M1_REGEN|M1_CARNIVORE, - M2_STRONG|M2_STALK|M2_HOSTILE, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_WHITE), - MON("rock troll", S_TROLL, - LVL(9, 12, 0, 0, -3), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 2, 8), - ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 300, MS_GRUNT, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_REGEN|M1_CARNIVORE, - M2_STRONG|M2_STALK|M2_HOSTILE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_CYAN), - MON("water troll", S_TROLL, - LVL(11, 14, 4, 40, -3), (G_NOGEN|G_GENO), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), - ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 350, MS_GRUNT, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_REGEN|M1_CARNIVORE|M1_SWIM, - M2_STRONG|M2_STALK|M2_HOSTILE, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_BLUE), - MON("Olog-hai", S_TROLL, - LVL(13, 12, -4, 0, -7), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 2, 8), - ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 400, MS_GRUNT, MZ_LARGE), 0, 0, - M1_HUMANOID|M1_REGEN|M1_CARNIVORE, - M2_STRONG|M2_STALK|M2_HOSTILE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), -/* - * Umber hulk - */ - MON("umber hulk", S_UMBER, - LVL(9, 6, 2, 25, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), - ATTK(AT_BITE, AD_PHYS, 2, 5), ATTK(AT_GAZE, AD_CONF, 0, 0), - NO_ATTK, NO_ATTK), - SIZ(1200, 500, MS_SILENT, MZ_LARGE), 0, 0, - M1_TUNNEL|M1_CARNIVORE, M2_STRONG, M3_INFRAVISIBLE, CLR_BROWN), -/* - * Vampires - */ - MON("vampire", S_VAMPIRE, - LVL(10, 12, 1, 25, -8), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_DRLI, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_SHAPESHIFTER, - M3_INFRAVISIBLE, CLR_RED), - MON("vampire lord", S_VAMPIRE, - LVL(12, 14, 0, 50, -9), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_BITE, AD_DRLI, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_LORD|M2_MALE| - M2_SHAPESHIFTER, M3_INFRAVISIBLE, CLR_BLUE), -#if 0 /* DEFERRED */ + /* + * Kops + */ + MON("Keystone Kop", S_KOP, LVL(1, 6, 10, 10, 9), + (G_GENO | G_LGROUP | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, + M2_HUMAN | M2_WANDER | M2_HOSTILE | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BLUE), + MON("Kop Sergeant", S_KOP, LVL(2, 8, 10, 10, 10), + (G_GENO | G_SGROUP | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, + M2_HUMAN | M2_WANDER | M2_HOSTILE | M2_STRONG | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BLUE), + MON("Kop Lieutenant", S_KOP, LVL(3, 10, 10, 20, 11), (G_GENO | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, + M2_HUMAN | M2_WANDER | M2_HOSTILE | M2_STRONG | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, CLR_CYAN), + MON("Kop Kaptain", S_KOP, LVL(4, 12, 10, 20, 12), (G_GENO | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 200, MS_ARREST, MZ_HUMAN), 0, 0, M1_HUMANOID, + M2_HUMAN | M2_WANDER | M2_HOSTILE | M2_STRONG | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_LORD), + /* + * Liches + */ + MON("lich", S_LICH, LVL(11, 6, 0, 30, -9), (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_TUCH, AD_COLD, 1, 10), ATTK(AT_MAGC, AD_SPEL, 0, 0), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, + MR_COLD, M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_HOSTILE | M2_MAGIC, M3_INFRAVISION, CLR_BROWN), + MON("demilich", S_LICH, LVL(14, 9, -2, 60, -12), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_TUCH, AD_COLD, 3, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, + MR_COLD, M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_HOSTILE | M2_MAGIC, M3_INFRAVISION, CLR_RED), + MON("master lich", S_LICH, LVL(17, 9, -4, 90, -15), + (G_HELL | G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_TUCH, AD_COLD, 3, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_SLEEP | MR_POISON, MR_FIRE | MR_COLD, + M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_HOSTILE | M2_MAGIC, M3_WANTSBOOK | M3_INFRAVISION, + HI_LORD), + MON("arch-lich", S_LICH, LVL(25, 9, -6, 90, -15), + (G_HELL | G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_TUCH, AD_COLD, 5, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 100, MS_MUMBLE, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_SLEEP | MR_ELEC | MR_POISON, MR_FIRE | MR_COLD, + M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_HOSTILE | M2_MAGIC, M3_WANTSBOOK | M3_INFRAVISION, + HI_LORD), + /* + * Mummies + */ + MON("kobold mummy", S_MUMMY, LVL(3, 8, 6, 20, -2), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 50, MS_SILENT, MZ_SMALL), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE, M3_INFRAVISION, CLR_BROWN), + MON("gnome mummy", S_MUMMY, LVL(4, 10, 6, 20, -3), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(650, 50, MS_SILENT, MZ_SMALL), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_GNOME, M3_INFRAVISION, CLR_RED), + MON("orc mummy", S_MUMMY, LVL(5, 10, 5, 20, -4), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(850, 75, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_ORC | M2_GREEDY | M2_JEWELS, + M3_INFRAVISION, CLR_GRAY), + MON("dwarf mummy", S_MUMMY, LVL(5, 10, 5, 20, -4), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(900, 150, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_DWARF | M2_GREEDY | M2_JEWELS, + M3_INFRAVISION, CLR_RED), + MON("elf mummy", S_MUMMY, LVL(6, 12, 4, 30, -5), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_ELF, 175, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, + 0, M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_ELF, M3_INFRAVISION, CLR_GREEN), + MON("human mummy", S_MUMMY, LVL(6, 12, 4, 30, -5), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 200, MS_SILENT, MZ_HUMAN), + MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE, M3_INFRAVISION, CLR_GRAY), + MON("ettin mummy", S_MUMMY, LVL(7, 12, 4, 30, -6), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_PHYS, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1700, 250, MS_SILENT, MZ_HUGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_STRONG, M3_INFRAVISION, CLR_BLUE), + MON("giant mummy", S_MUMMY, LVL(8, 14, 3, 30, -7), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2050, 375, MS_SILENT, MZ_HUGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_HOSTILE | M2_GIANT | M2_STRONG | M2_JEWELS, + M3_INFRAVISION, CLR_CYAN), + /* + * Nagas + */ + MON("red naga hatchling", S_NAGA, LVL(3, 10, 6, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_FIRE | MR_POISON, + MR_FIRE | MR_POISON, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_NOTAKE | M1_OMNIVORE, + M2_STRONG, M3_INFRAVISIBLE, CLR_RED), + MON("black naga hatchling", S_NAGA, LVL(3, 10, 6, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_POISON | MR_ACID | MR_STONE, + MR_POISON | MR_STONE, M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_ACID + | M1_NOTAKE | M1_CARNIVORE, + M2_STRONG, 0, CLR_BLACK), + MON("golden naga hatchling", S_NAGA, LVL(3, 10, 6, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_POISON, MR_POISON, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_NOTAKE | M1_OMNIVORE, + M2_STRONG, 0, HI_GOLD), + MON("guardian naga hatchling", S_NAGA, LVL(3, 10, 6, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 100, MS_MUMBLE, MZ_LARGE), MR_POISON, MR_POISON, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_NOTAKE | M1_OMNIVORE, + M2_STRONG, 0, CLR_GREEN), + MON("red naga", S_NAGA, LVL(6, 12, 4, 0, -4), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_BREA, AD_FIRE, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_FIRE | MR_POISON, + MR_FIRE | MR_POISON, M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE + | M1_OVIPAROUS | M1_NOTAKE | M1_OMNIVORE, + M2_STRONG, M3_INFRAVISIBLE, CLR_RED), + MON("black naga", S_NAGA, LVL(8, 14, 2, 10, 4), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_SPIT, AD_ACID, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_POISON | MR_ACID | MR_STONE, + MR_POISON | MR_STONE, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_OVIPAROUS | M1_ACID + | M1_NOTAKE | M1_CARNIVORE, + M2_STRONG, 0, CLR_BLACK), + MON("golden naga", S_NAGA, LVL(10, 14, 2, 70, 5), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), ATTK(AT_MAGC, AD_SPEL, 4, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_POISON, MR_POISON, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_OVIPAROUS | M1_NOTAKE + | M1_OMNIVORE, + M2_STRONG, 0, HI_GOLD), + MON("guardian naga", S_NAGA, LVL(12, 16, 0, 50, 7), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PLYS, 1, 6), ATTK(AT_SPIT, AD_DRST, 1, 6), + ATTK(AT_HUGS, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2600, 400, MS_MUMBLE, MZ_HUGE), MR_POISON, MR_POISON, + M1_NOLIMBS | M1_SLITHY | M1_THICK_HIDE | M1_OVIPAROUS | M1_POIS + | M1_NOTAKE | M1_OMNIVORE, + M2_STRONG, 0, CLR_GREEN), + /* + * Ogres + */ + MON("ogre", S_OGRE, LVL(5, 10, 5, 0, -3), (G_SGROUP | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 5), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1600, 500, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("ogre lord", S_OGRE, LVL(7, 12, 3, 30, -5), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1700, 700, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_STRONG | M2_LORD | M2_MALE | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("ogre king", S_OGRE, LVL(9, 14, 4, 60, -7), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 3, 5), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1700, 750, MS_GRUNT, MZ_LARGE), 0, 0, M1_HUMANOID | M1_CARNIVORE, + M2_STRONG | M2_PRINCE | M2_MALE | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + /* + * Puddings + * + * must be in the same order as the pudding globs in objects.c + */ + MON("gray ooze", S_PUDDING, LVL(3, 1, 8, 0, 0), (G_GENO | G_NOCORPSE | 2), + A(ATTK(AT_BITE, AD_RUST, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 250, MS_SILENT, MZ_MEDIUM), + MR_FIRE | MR_COLD | MR_POISON | MR_ACID | MR_STONE, + MR_FIRE | MR_COLD | MR_POISON, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_OMNIVORE | M1_ACID, + M2_HOSTILE | M2_NEUTER, 0, CLR_GRAY), + MON("brown pudding", S_PUDDING, LVL(5, 3, 8, 0, 0), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_BITE, AD_DCAY, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(500, 250, MS_SILENT, MZ_MEDIUM), + MR_COLD | MR_ELEC | MR_POISON | MR_ACID | MR_STONE, + MR_COLD | MR_ELEC | MR_POISON, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_OMNIVORE | M1_ACID, + M2_HOSTILE | M2_NEUTER, 0, CLR_BROWN), + MON("green slime", S_PUDDING, LVL(6, 6, 6, 0, 0), + (G_HELL | G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_TUCH, AD_SLIM, 1, 4), ATTK(AT_NONE, AD_SLIM, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 150, MS_SILENT, MZ_LARGE), + MR_COLD | MR_ELEC | MR_POISON | MR_ACID | MR_STONE, 0, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_OMNIVORE | M1_ACID | M1_POIS, + M2_HOSTILE | M2_NEUTER, 0, CLR_GREEN), + MON("black pudding", S_PUDDING, LVL(10, 6, 6, 0, 0), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_BITE, AD_CORR, 3, 8), ATTK(AT_NONE, AD_CORR, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(900, 250, MS_SILENT, MZ_LARGE), + MR_COLD | MR_ELEC | MR_POISON | MR_ACID | MR_STONE, + MR_COLD | MR_ELEC | MR_POISON, + M1_BREATHLESS | M1_AMORPHOUS | M1_NOEYES | M1_NOLIMBS | M1_NOHEAD + | M1_MINDLESS | M1_OMNIVORE | M1_ACID, + M2_HOSTILE | M2_NEUTER, 0, CLR_BLACK), + /* + * Quantum mechanics + */ + MON("quantum mechanic", S_QUANTMECH, LVL(7, 12, 3, 10, 0), (G_GENO | 3), + A(ATTK(AT_CLAW, AD_TLPT, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 20, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE | M1_POIS | M1_TPORT, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_CYAN), + /* + * Rust monster or disenchanter + */ + MON("rust monster", S_RUSTMONST, LVL(5, 18, 2, 0, 0), (G_GENO | 2), + A(ATTK(AT_TUCH, AD_RUST, 0, 0), ATTK(AT_TUCH, AD_RUST, 0, 0), + ATTK(AT_NONE, AD_RUST, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1000, 250, MS_SILENT, MZ_MEDIUM), 0, 0, + M1_SWIM | M1_ANIMAL | M1_NOHANDS | M1_METALLIVORE, M2_HOSTILE, + M3_INFRAVISIBLE, CLR_BROWN), + MON("disenchanter", S_RUSTMONST, LVL(12, 12, -10, 0, -3), + (G_HELL | G_GENO | 2), + A(ATTK(AT_CLAW, AD_ENCH, 4, 4), ATTK(AT_NONE, AD_ENCH, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(750, 200, MS_GROWL, MZ_LARGE), 0, 0, M1_ANIMAL | M1_CARNIVORE, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_BLUE), + /* + * Snakes + */ + MON("garter snake", S_SNAKE, LVL(1, 8, 8, 0, 0), (G_LGROUP | G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(50, 60, MS_HISS, MZ_TINY), 0, 0, + M1_SWIM | M1_CONCEAL | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY + | M1_OVIPAROUS | M1_CARNIVORE | M1_NOTAKE, + 0, 0, CLR_GREEN), + MON("snake", S_SNAKE, LVL(4, 15, 3, 0, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_DRST, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(100, 80, MS_HISS, MZ_SMALL), MR_POISON, MR_POISON, + M1_SWIM | M1_CONCEAL | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY | M1_POIS + | M1_OVIPAROUS | M1_CARNIVORE | M1_NOTAKE, + M2_HOSTILE, 0, CLR_BROWN), + MON("water moccasin", S_SNAKE, LVL(4, 15, 3, 0, 0), + (G_GENO | G_NOGEN | G_LGROUP), + A(ATTK(AT_BITE, AD_DRST, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(150, 80, MS_HISS, MZ_SMALL), MR_POISON, MR_POISON, + M1_SWIM | M1_CONCEAL | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY | M1_POIS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, 0, CLR_RED), + MON("python", S_SNAKE, LVL(6, 3, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 1, 4), ATTK(AT_TUCH, AD_PHYS, 0, 0), + ATTK(AT_HUGS, AD_WRAP, 1, 4), ATTK(AT_HUGS, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK), + SIZ(250, 100, MS_HISS, MZ_LARGE), 0, 0, + M1_SWIM | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY | M1_CARNIVORE + | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE | M2_STRONG, M3_INFRAVISION, CLR_MAGENTA), + MON("pit viper", S_SNAKE, LVL(6, 15, 2, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_DRST, 1, 4), ATTK(AT_BITE, AD_DRST, 1, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(100, 60, MS_HISS, MZ_MEDIUM), MR_POISON, MR_POISON, + M1_SWIM | M1_CONCEAL | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY | M1_POIS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, M3_INFRAVISION, CLR_BLUE), + MON("cobra", S_SNAKE, LVL(6, 18, 2, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_DRST, 2, 4), ATTK(AT_SPIT, AD_BLND, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(250, 100, MS_HISS, MZ_MEDIUM), MR_POISON, MR_POISON, + M1_SWIM | M1_CONCEAL | M1_NOLIMBS | M1_ANIMAL | M1_SLITHY | M1_POIS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, 0, CLR_BLUE), + /* + * Trolls + */ + MON("troll", S_TROLL, LVL(7, 12, 4, 0, -3), (G_GENO | 2), + A(ATTK(AT_WEAP, AD_PHYS, 4, 2), ATTK(AT_CLAW, AD_PHYS, 4, 2), + ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(800, 350, MS_GRUNT, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_REGEN | M1_CARNIVORE, + M2_STRONG | M2_STALK | M2_HOSTILE, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BROWN), + MON("ice troll", S_TROLL, LVL(9, 10, 2, 20, -3), (G_NOHELL | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_COLD, 2, 6), + ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1000, 300, MS_GRUNT, MZ_LARGE), MR_COLD, MR_COLD, + M1_HUMANOID | M1_REGEN | M1_CARNIVORE, + M2_STRONG | M2_STALK | M2_HOSTILE, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_WHITE), + MON("rock troll", S_TROLL, LVL(9, 12, 0, 0, -3), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 2, 8), + ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 300, MS_GRUNT, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_REGEN | M1_CARNIVORE, + M2_STRONG | M2_STALK | M2_HOSTILE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_CYAN), + MON("water troll", S_TROLL, LVL(11, 14, 4, 40, -3), (G_NOGEN | G_GENO), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), + ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 350, MS_GRUNT, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_REGEN | M1_CARNIVORE | M1_SWIM, + M2_STRONG | M2_STALK | M2_HOSTILE, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BLUE), + MON("Olog-hai", S_TROLL, LVL(13, 12, -4, 0, -7), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 2, 8), + ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 400, MS_GRUNT, MZ_LARGE), 0, 0, + M1_HUMANOID | M1_REGEN | M1_CARNIVORE, + M2_STRONG | M2_STALK | M2_HOSTILE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + /* + * Umber hulk + */ + MON("umber hulk", S_UMBER, LVL(9, 6, 2, 25, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_CLAW, AD_PHYS, 3, 4), + ATTK(AT_BITE, AD_PHYS, 2, 5), ATTK(AT_GAZE, AD_CONF, 0, 0), NO_ATTK, + NO_ATTK), + SIZ(1200, 500, MS_SILENT, MZ_LARGE), 0, 0, M1_TUNNEL | M1_CARNIVORE, + M2_STRONG, M3_INFRAVISIBLE, CLR_BROWN), + /* + * Vampires + */ + MON("vampire", S_VAMPIRE, LVL(10, 12, 1, 25, -8), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_BITE, AD_DRLI, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY + | M2_SHAPESHIFTER, + M3_INFRAVISIBLE, CLR_RED), + MON("vampire lord", S_VAMPIRE, LVL(12, 14, 0, 50, -9), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_BITE, AD_DRLI, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY | M2_LORD + | M2_MALE | M2_SHAPESHIFTER, + M3_INFRAVISIBLE, CLR_BLUE), +#if 0 /* DEFERRED */ MON("vampire mage", S_VAMPIRE, LVL(20, 14, -4, 50, -9), (G_GENO|G_NOCORPSE|1), A(ATTK(AT_CLAW, AD_DRLI, 2, 8), ATTK(AT_BITE, AD_DRLI, 1, 8), @@ -2020,1057 +1865,988 @@ struct permonst _mons2[] = { M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_LORD|M2_MALE| M2_MAGIC|M2_SHAPESHIFTER, M3_INFRAVISIBLE, HI_ZAP), #endif - MON("Vlad the Impaler", S_VAMPIRE, - LVL(14, 18, -3, 80, -10), (G_NOGEN|G_NOCORPSE|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 10), ATTK(AT_BITE, AD_DRLI, 1, 10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP|MR_POISON, 0, - M1_FLY|M1_BREATHLESS|M1_HUMANOID|M1_POIS|M1_REGEN, - M2_NOPOLY|M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_PNAME|M2_STRONG| - M2_NASTY|M2_PRINCE|M2_MALE|M2_SHAPESHIFTER, - M3_WAITFORU|M3_WANTSCAND|M3_INFRAVISIBLE, HI_LORD), -/* - * Wraiths - */ - MON("barrow wight", S_WRAITH, - LVL(3, 12, 5, 5, -3), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_DRLI, 0, 0), ATTK(AT_MAGC, AD_SPEL, 0, 0), - ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1200, 0, MS_SPELL, MZ_HUMAN), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_HUMANOID, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_COLLECT, 0, CLR_GRAY), - MON("wraith", S_WRAITH, - LVL(6, 12, 4, 15, -6), (G_GENO|2), - A(ATTK(AT_TUCH, AD_DRLI, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_BREATHLESS|M1_FLY|M1_HUMANOID|M1_UNSOLID, - M2_UNDEAD|M2_STALK|M2_HOSTILE, 0, CLR_BLACK), - MON("Nazgul", S_WRAITH, - LVL(13, 12, 0, 25, -17), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_DRLI, 1, 4), ATTK(AT_BREA, AD_SLEE, 2,25), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 0, MS_SPELL, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, 0, M1_BREATHLESS|M1_HUMANOID, - M2_NOPOLY|M2_UNDEAD|M2_STALK|M2_STRONG|M2_HOSTILE|M2_MALE|M2_COLLECT, - 0, HI_LORD), -/* - * Xorn - */ - MON("xorn", S_XORN, - LVL(8, 9,-2, 20, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), - ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_BITE, AD_PHYS, 4, 6), - NO_ATTK, NO_ATTK), - SIZ(1200, 700, MS_ROAR, MZ_MEDIUM), - MR_FIRE|MR_COLD|MR_STONE, MR_STONE, - M1_BREATHLESS|M1_WALLWALK|M1_THICK_HIDE|M1_METALLIVORE, - M2_HOSTILE|M2_STRONG, 0, CLR_BROWN), -/* - * Apelike beasts - */ - MON("monkey", S_YETI, - LVL(2, 12, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_BITE, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 50, MS_GROWL, MZ_SMALL), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, 0, M3_INFRAVISIBLE, CLR_GRAY), - MON("ape", S_YETI, - LVL(4, 12, 6, 0, 0), (G_GENO|G_SGROUP|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), - ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1100, 500, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, M2_STRONG, M3_INFRAVISIBLE, - CLR_BROWN), - MON("owlbear", S_YETI, - LVL(5, 12, 5, 0, 0), (G_GENO|3), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - ATTK(AT_HUGS, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 700, MS_ROAR, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, - M2_HOSTILE|M2_STRONG|M2_NASTY, M3_INFRAVISIBLE, CLR_BROWN), - MON("yeti", S_YETI, - LVL(5, 15, 6, 0, 0), (G_GENO|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1600, 700, MS_GROWL, MZ_LARGE), MR_COLD, MR_COLD, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, M2_HOSTILE|M2_STRONG, - M3_INFRAVISIBLE, CLR_WHITE), - MON("carnivorous ape", S_YETI, - LVL(6, 12, 6, 0, 0), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_HUGS, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1250, 550, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_CARNIVORE, M2_HOSTILE|M2_STRONG, - M3_INFRAVISIBLE, CLR_BLACK), - MON("sasquatch", S_YETI, - LVL(7, 15, 6, 0, 2), (G_GENO|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - ATTK(AT_KICK, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1550, 750, MS_GROWL, MZ_LARGE), 0, 0, - M1_ANIMAL|M1_HUMANOID|M1_SEE_INVIS|M1_OMNIVORE, M2_STRONG, - M3_INFRAVISIBLE, CLR_GRAY), -/* - * Zombies - */ - MON("kobold zombie", S_ZOMBIE, - LVL(0, 6, 10, 0, -2), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 50, MS_SILENT, MZ_SMALL), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_STALK|M2_HOSTILE, M3_INFRAVISION, CLR_BROWN), - MON("gnome zombie", S_ZOMBIE, - LVL(1, 6, 10, 0, -2), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 5), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(650, 50, MS_SILENT, MZ_SMALL), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_GNOME, M3_INFRAVISION, CLR_BROWN), - MON("orc zombie", S_ZOMBIE, - LVL(2, 6, 9, 0, -3), (G_GENO|G_SGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(850, 75, MS_SILENT, MZ_HUMAN), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_ORC, M3_INFRAVISION, CLR_GRAY), - MON("dwarf zombie", S_ZOMBIE, - LVL(2, 6, 9, 0, -3), (G_GENO|G_SGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 150, MS_SILENT, MZ_HUMAN), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_DWARF, M3_INFRAVISION, CLR_RED), - MON("elf zombie", S_ZOMBIE, - LVL(3, 6, 9, 0, -3), (G_GENO|G_SGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 7), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 175, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_ELF, M3_INFRAVISION, CLR_GREEN), - MON("human zombie", S_ZOMBIE, - LVL(4, 6, 8, 0, -3), (G_GENO|G_SGROUP|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 200, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_UNDEAD|M2_STALK|M2_HOSTILE, M3_INFRAVISION, HI_DOMESTIC), - MON("ettin zombie", S_ZOMBIE, - LVL(6, 8, 6, 0, -4), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1,10), ATTK(AT_CLAW, AD_PHYS, 1,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1700, 250, MS_SILENT, MZ_HUGE), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_STRONG, M3_INFRAVISION, CLR_BLUE), - MON("ghoul", S_ZOMBIE, - LVL(3, 6, 10, 0, -2), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PLYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 50, MS_SILENT, MZ_SMALL), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_POIS|M1_OMNIVORE, - M2_UNDEAD|M2_WANDER|M2_HOSTILE, M3_INFRAVISION, CLR_BLACK), - MON("giant zombie", S_ZOMBIE, - LVL(8, 8, 6, 0, -4), (G_GENO|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2050, 375, MS_SILENT, MZ_HUGE), - MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_UNDEAD|M2_STALK|M2_HOSTILE|M2_GIANT|M2_STRONG, M3_INFRAVISION, - CLR_CYAN), - MON("skeleton", S_ZOMBIE, - LVL(12, 8, 4, 0, 0), (G_NOCORPSE|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_TUCH, AD_SLOW, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(300, 5, MS_BONES, MZ_HUMAN), - MR_COLD|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_UNDEAD|M2_WANDER|M2_HOSTILE|M2_STRONG|M2_COLLECT|M2_NASTY, - M3_INFRAVISION, CLR_WHITE), -/* - * golems - */ - MON("straw golem", S_GOLEM, - LVL(3, 12, 10, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 0, MS_SILENT, MZ_LARGE), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_HOSTILE|M2_NEUTER, 0, CLR_YELLOW), - MON("paper golem", S_GOLEM, - LVL(3, 12, 10, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(400, 0, MS_SILENT, MZ_LARGE), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_HOSTILE|M2_NEUTER, 0, HI_PAPER), - MON("rope golem", S_GOLEM, - LVL(4, 9, 8, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_HUGS, AD_PHYS, 6, 1), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(450, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_HOSTILE|M2_NEUTER, 0, CLR_BROWN), - MON("gold golem", S_GOLEM, - LVL(5, 9, 6, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 3), ATTK(AT_CLAW, AD_PHYS, 2, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(450, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON|MR_ACID, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_HOSTILE|M2_NEUTER, 0, HI_GOLD), - MON("leather golem", S_GOLEM, - LVL(6, 6, 6, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(800, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_HOSTILE|M2_NEUTER, 0, HI_LEATHER), - MON("wood golem", S_GOLEM, - LVL(7, 3, 4, 0, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(900, 0, MS_SILENT, MZ_LARGE), MR_COLD|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_HOSTILE|M2_NEUTER, 0, HI_WOOD), - MON("flesh golem", S_GOLEM, - LVL(9, 8, 9, 30, 0), (1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1400, 600, MS_SILENT, MZ_LARGE), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID, - M2_HOSTILE|M2_STRONG, 0, CLR_RED), - MON("clay golem", S_GOLEM, - LVL(11, 7, 7, 40, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 3,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1550, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_HOSTILE|M2_STRONG, 0, CLR_BROWN), - MON("stone golem", S_GOLEM, - LVL(14, 6, 5, 50, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 3, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1900, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_HOSTILE|M2_STRONG, 0, CLR_GRAY), - MON("glass golem", S_GOLEM, - LVL(16, 6, 1, 50, 0), (G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1800, 0, MS_SILENT, MZ_LARGE), MR_SLEEP|MR_POISON|MR_ACID, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE, - M2_HOSTILE|M2_STRONG, 0, CLR_CYAN), - MON("iron golem", S_GOLEM, - LVL(18, 6, 3, 60, 0), (G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 4,10), ATTK(AT_BREA, AD_DRST, 4, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2000, 0, MS_SILENT, MZ_LARGE), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_BREATHLESS|M1_MINDLESS|M1_HUMANOID|M1_THICK_HIDE|M1_POIS, - M2_HOSTILE|M2_STRONG|M2_COLLECT, 0, HI_METAL), -/* - * humans, including elves and were-critters - */ - MON("human", S_HUMAN, - LVL(0, 12, 10, 0, 0), G_NOGEN, /* for corpses */ - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("wererat", S_HUMAN, - LVL(2, 12, 10, 10, -7), (1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_REGEN|M1_OMNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE|M2_HUMAN|M2_COLLECT, M3_INFRAVISIBLE, - CLR_BROWN), - MON("werejackal", S_HUMAN, - LVL(2, 12, 10, 10, -7), (1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_REGEN|M1_OMNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE|M2_HUMAN|M2_COLLECT, M3_INFRAVISIBLE, - CLR_RED), - MON("werewolf", S_HUMAN, - LVL(5, 12, 10, 20, -7), (1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_REGEN|M1_OMNIVORE, - M2_NOPOLY|M2_WERE|M2_HOSTILE|M2_HUMAN|M2_COLLECT, - M3_INFRAVISIBLE, CLR_ORANGE), - MON("elf", S_HUMAN, - LVL(10, 12, 10, 2, -3), G_NOGEN, /* for corpses */ - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_NOPOLY|M2_ELF|M2_STRONG|M2_COLLECT, M3_INFRAVISION|M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("Woodland-elf", S_HUMAN, - LVL(4, 12, 10, 10, -5), (G_GENO|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_ELF|M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GREEN), - MON("Green-elf", S_HUMAN, - LVL(5, 12, 10, 10, -6), (G_GENO|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_ELF|M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BRIGHT_GREEN), - MON("Grey-elf", S_HUMAN, - LVL(6, 12, 10, 10, -7), (G_GENO|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_ELF|M2_COLLECT, M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("elf-lord", S_HUMAN, - LVL(8, 12, 10, 20, -9), (G_GENO|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_ELF|M2_STRONG|M2_LORD|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BRIGHT_BLUE), - MON("Elvenking", S_HUMAN, - LVL(9, 12, 10, 25, -10), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS, - M2_ELF|M2_STRONG|M2_PRINCE|M2_MALE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("doppelganger", S_HUMAN, - LVL(9, 12, 5, 20, 0), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 12), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_IMITATE, MZ_HUMAN), MR_SLEEP, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_HOSTILE|M2_STRONG|M2_COLLECT|M2_SHAPESHIFTER, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("shopkeeper", S_HUMAN, - LVL(12, 18, 0, 50, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 4, 4), ATTK(AT_WEAP, AD_PHYS, 4, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SELL, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("guard", S_HUMAN, - LVL(12, 12, 10, 40, 10), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 4,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARD, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_PEACEFUL|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_BLUE), - MON("prisoner", S_HUMAN, - LVL(12, 12, 10, 0, 0), G_NOGEN, /* for special levels */ - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_DJINNI, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE|M3_CLOSE, HI_DOMESTIC), - MON("Oracle", S_HUMAN, - LVL(12, 0, 0, 50, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_NONE, AD_MAGM, 0, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_ORACLE, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_FEMALE, M3_INFRAVISIBLE, HI_ZAP), - /* aligned priests always have the epri extension attached; - individual instantiations should always have either ispriest - or isminion set */ - MON("aligned priest", S_HUMAN, - LVL(12, 12, 10, 50, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 4,10), ATTK(AT_KICK, AD_PHYS, 1, 4), - ATTK(AT_MAGC, AD_CLRC, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_PRIEST, MZ_HUMAN), - MR_ELEC, 0, M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_LORD|M2_PEACEFUL|M2_COLLECT, M3_INFRAVISIBLE, - CLR_WHITE), - /* high priests always have epri and always have ispriest set */ - MON("high priest", S_HUMAN, - LVL(25, 15, 7, 70, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 4,10), ATTK(AT_KICK, AD_PHYS, 2, 8), - ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_PRIEST, MZ_HUMAN), - MR_FIRE|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_HUMANOID|M1_SEE_INVIS|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MINION|M2_PRINCE|M2_NASTY|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE, CLR_WHITE), - MON("soldier", S_HUMAN, - LVL(6, 10, 10, 0, -2), (G_SGROUP|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_HOSTILE|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_GRAY), - MON("sergeant", S_HUMAN, - LVL(8, 10, 10, 5, -3), (G_SGROUP|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_HOSTILE|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_RED), - MON("nurse", S_HUMAN, - LVL(11, 6, 0, 0, 0), (G_GENO|3), - A(ATTK(AT_CLAW, AD_HEAL, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NURSE, MZ_HUMAN), MR_POISON, MR_POISON, - M1_HUMANOID|M1_OMNIVORE, M2_NOPOLY|M2_HUMAN|M2_HOSTILE, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("lieutenant", S_HUMAN, - LVL(10, 10, 10, 15, -4), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_WEAP, AD_PHYS, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_HOSTILE|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_GREEN), - MON("captain", S_HUMAN, - LVL(12, 10, 10, 15, -5), (G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 4, 4), ATTK(AT_WEAP, AD_PHYS, 4, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_HOSTILE|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_BLUE), - /* Keep these separate - some of the mkroom code assumes that - * all the soldiers are contiguous. - */ - MON("watchman", S_HUMAN, - LVL(6, 10, 10, 0, -2), (G_SGROUP|G_NOGEN|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_PEACEFUL|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_GRAY), - MON("watch captain", S_HUMAN, - LVL(10, 10, 10, 15, -4), (G_NOGEN|G_GENO|1), - A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_WEAP, AD_PHYS, 3, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_MERC|M2_STALK|M2_PEACEFUL|M2_STRONG|M2_COLLECT, - M3_INFRAVISIBLE, CLR_GREEN), - /* Unique humans not tied to quests. - */ - MON("Medusa", S_HUMAN, - LVL(20, 12, 2, 50, -15), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 1, 8), - ATTK(AT_GAZE, AD_STON, 0, 0), ATTK(AT_BITE, AD_DRST, 1, 6), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HISS, MZ_LARGE), - MR_POISON|MR_STONE, MR_POISON|MR_STONE, - M1_FLY|M1_SWIM|M1_AMPHIBIOUS|M1_HUMANOID|M1_POIS|M1_OMNIVORE, - M2_NOPOLY|M2_HOSTILE|M2_STRONG|M2_PNAME|M2_FEMALE, - M3_WAITFORU|M3_INFRAVISIBLE, CLR_BRIGHT_GREEN), - MON("Wizard of Yendor", S_HUMAN, - LVL(30, 12, -8, 100, A_NONE), (G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_SAMU, 2,12), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_CUSS, MZ_HUMAN), - MR_FIRE|MR_POISON, MR_FIRE|MR_POISON, - M1_FLY|M1_BREATHLESS|M1_HUMANOID|M1_REGEN|M1_SEE_INVIS|M1_TPORT| - M1_TPORT_CNTRL|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_HOSTILE|M2_STRONG|M2_NASTY| - M2_PRINCE|M2_MALE|M2_MAGIC, - M3_COVETOUS|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), - MON("Croesus", S_HUMAN, - LVL(20, 15, 0, 40, 15), (G_UNIQ|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 4,10), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARD, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_SEE_INVIS|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_PNAME| - M2_PRINCE|M2_MALE|M2_GREEDY|M2_JEWELS|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE, HI_LORD), + MON("Vlad the Impaler", S_VAMPIRE, LVL(14, 18, -3, 80, -10), + (G_NOGEN | G_NOCORPSE | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 10), ATTK(AT_BITE, AD_DRLI, 1, 10), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_VAMPIRE, MZ_HUMAN), MR_SLEEP | MR_POISON, 0, + M1_FLY | M1_BREATHLESS | M1_HUMANOID | M1_POIS | M1_REGEN, + M2_NOPOLY | M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_PNAME | M2_STRONG + | M2_NASTY | M2_PRINCE | M2_MALE | M2_SHAPESHIFTER, + M3_WAITFORU | M3_WANTSCAND | M3_INFRAVISIBLE, HI_LORD), + /* + * Wraiths + */ + MON("barrow wight", S_WRAITH, LVL(3, 12, 5, 5, -3), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_DRLI, 0, 0), ATTK(AT_MAGC, AD_SPEL, 0, 0), + ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1200, 0, MS_SPELL, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_HUMANOID, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_COLLECT, 0, CLR_GRAY), + MON("wraith", S_WRAITH, LVL(6, 12, 4, 15, -6), (G_GENO | 2), + A(ATTK(AT_TUCH, AD_DRLI, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(0, 0, MS_SILENT, MZ_HUMAN), + MR_COLD | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_BREATHLESS | M1_FLY | M1_HUMANOID | M1_UNSOLID, + M2_UNDEAD | M2_STALK | M2_HOSTILE, 0, CLR_BLACK), + MON("Nazgul", S_WRAITH, LVL(13, 12, 0, 25, -17), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_DRLI, 1, 4), ATTK(AT_BREA, AD_SLEE, 2, 25), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 0, MS_SPELL, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, + 0, M1_BREATHLESS | M1_HUMANOID, + M2_NOPOLY | M2_UNDEAD | M2_STALK | M2_STRONG | M2_HOSTILE | M2_MALE + | M2_COLLECT, + 0, HI_LORD), + /* + * Xorn + */ + MON("xorn", S_XORN, LVL(8, 9, -2, 20, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), + ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_BITE, AD_PHYS, 4, 6), NO_ATTK, + NO_ATTK), + SIZ(1200, 700, MS_ROAR, MZ_MEDIUM), MR_FIRE | MR_COLD | MR_STONE, + MR_STONE, + M1_BREATHLESS | M1_WALLWALK | M1_THICK_HIDE | M1_METALLIVORE, + M2_HOSTILE | M2_STRONG, 0, CLR_BROWN), + /* + * Apelike beasts + */ + MON("monkey", S_YETI, LVL(2, 12, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_SITM, 0, 0), ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(100, 50, MS_GROWL, MZ_SMALL), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, 0, M3_INFRAVISIBLE, CLR_GRAY), + MON("ape", S_YETI, LVL(4, 12, 6, 0, 0), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), + ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1100, 500, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, M2_STRONG, M3_INFRAVISIBLE, + CLR_BROWN), + MON("owlbear", S_YETI, LVL(5, 12, 5, 0, 0), (G_GENO | 3), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), + ATTK(AT_HUGS, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1700, 700, MS_ROAR, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, + M2_HOSTILE | M2_STRONG | M2_NASTY, M3_INFRAVISIBLE, CLR_BROWN), + MON("yeti", S_YETI, LVL(5, 15, 6, 0, 0), (G_GENO | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), + ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1600, 700, MS_GROWL, MZ_LARGE), MR_COLD, MR_COLD, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, M2_HOSTILE | M2_STRONG, + M3_INFRAVISIBLE, CLR_WHITE), + MON("carnivorous ape", S_YETI, LVL(6, 12, 6, 0, 0), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_HUGS, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1250, 550, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_CARNIVORE, M2_HOSTILE | M2_STRONG, + M3_INFRAVISIBLE, CLR_BLACK), + MON("sasquatch", S_YETI, LVL(7, 15, 6, 0, 2), (G_GENO | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), + ATTK(AT_KICK, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1550, 750, MS_GROWL, MZ_LARGE), 0, 0, + M1_ANIMAL | M1_HUMANOID | M1_SEE_INVIS | M1_OMNIVORE, M2_STRONG, + M3_INFRAVISIBLE, CLR_GRAY), + /* + * Zombies + */ + MON("kobold zombie", S_ZOMBIE, LVL(0, 6, 10, 0, -2), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 50, MS_SILENT, MZ_SMALL), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_STALK | M2_HOSTILE, M3_INFRAVISION, CLR_BROWN), + MON("gnome zombie", S_ZOMBIE, LVL(1, 6, 10, 0, -2), + (G_GENO | G_NOCORPSE | 1), A(ATTK(AT_CLAW, AD_PHYS, 1, 5), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(650, 50, MS_SILENT, MZ_SMALL), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_GNOME, M3_INFRAVISION, + CLR_BROWN), + MON("orc zombie", S_ZOMBIE, LVL(2, 6, 9, 0, -3), + (G_GENO | G_SGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(850, 75, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_ORC, M3_INFRAVISION, CLR_GRAY), + MON("dwarf zombie", S_ZOMBIE, LVL(2, 6, 9, 0, -3), + (G_GENO | G_SGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(900, 150, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_DWARF, M3_INFRAVISION, + CLR_RED), + MON("elf zombie", S_ZOMBIE, LVL(3, 6, 9, 0, -3), + (G_GENO | G_SGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 7), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_ELF, 175, MS_SILENT, MZ_HUMAN), MR_COLD | MR_SLEEP | MR_POISON, + 0, M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_ELF, M3_INFRAVISION, + CLR_GREEN), + MON("human zombie", S_ZOMBIE, LVL(4, 6, 8, 0, -3), + (G_GENO | G_SGROUP | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 200, MS_SILENT, MZ_HUMAN), + MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, + M2_UNDEAD | M2_STALK | M2_HOSTILE, M3_INFRAVISION, HI_DOMESTIC), + MON("ettin zombie", S_ZOMBIE, LVL(6, 8, 6, 0, -4), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 10), ATTK(AT_CLAW, AD_PHYS, 1, 10), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1700, 250, MS_SILENT, MZ_HUGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_STRONG, M3_INFRAVISION, + CLR_BLUE), + MON("ghoul", S_ZOMBIE, LVL(3, 6, 10, 0, -2), (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PLYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 3), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 50, MS_SILENT, MZ_SMALL), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_POIS | M1_OMNIVORE, + M2_UNDEAD | M2_WANDER | M2_HOSTILE, M3_INFRAVISION, CLR_BLACK), + MON("giant zombie", S_ZOMBIE, LVL(8, 8, 6, 0, -4), + (G_GENO | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2050, 375, MS_SILENT, MZ_HUGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, + M2_UNDEAD | M2_STALK | M2_HOSTILE | M2_GIANT | M2_STRONG, + M3_INFRAVISION, CLR_CYAN), + MON("skeleton", S_ZOMBIE, LVL(12, 8, 4, 0, 0), (G_NOCORPSE | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_TUCH, AD_SLOW, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(300, 5, MS_BONES, MZ_HUMAN), + MR_COLD | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_UNDEAD | M2_WANDER | M2_HOSTILE | M2_STRONG | M2_COLLECT + | M2_NASTY, + M3_INFRAVISION, CLR_WHITE), + /* + * golems + */ + MON("straw golem", S_GOLEM, LVL(3, 12, 10, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 2), ATTK(AT_CLAW, AD_PHYS, 1, 2), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(400, 0, MS_SILENT, MZ_LARGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, M2_HOSTILE | M2_NEUTER, 0, + CLR_YELLOW), + MON("paper golem", S_GOLEM, LVL(3, 12, 10, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(400, 0, MS_SILENT, MZ_LARGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, M2_HOSTILE | M2_NEUTER, 0, + HI_PAPER), + MON("rope golem", S_GOLEM, LVL(4, 9, 8, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_HUGS, AD_PHYS, 6, 1), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(450, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, M2_HOSTILE | M2_NEUTER, 0, + CLR_BROWN), + MON("gold golem", S_GOLEM, LVL(5, 9, 6, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 3), ATTK(AT_CLAW, AD_PHYS, 2, 3), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(450, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON | MR_ACID, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_HOSTILE | M2_NEUTER, 0, HI_GOLD), + MON("leather golem", S_GOLEM, LVL(6, 6, 6, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 6), ATTK(AT_CLAW, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(800, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, M2_HOSTILE | M2_NEUTER, 0, + HI_LEATHER), + MON("wood golem", S_GOLEM, LVL(7, 3, 4, 0, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(900, 0, MS_SILENT, MZ_LARGE), MR_COLD | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_HOSTILE | M2_NEUTER, 0, HI_WOOD), + MON("flesh golem", S_GOLEM, LVL(9, 8, 9, 30, 0), (1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1400, 600, MS_SILENT, MZ_LARGE), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID, M2_HOSTILE | M2_STRONG, 0, + CLR_RED), + MON("clay golem", S_GOLEM, LVL(11, 7, 7, 40, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 3, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1550, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_HOSTILE | M2_STRONG, 0, CLR_BROWN), + MON("stone golem", S_GOLEM, LVL(14, 6, 5, 50, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 3, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1900, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_HOSTILE | M2_STRONG, 0, CLR_GRAY), + MON("glass golem", S_GOLEM, LVL(16, 6, 1, 50, 0), (G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 2, 8), ATTK(AT_CLAW, AD_PHYS, 2, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1800, 0, MS_SILENT, MZ_LARGE), MR_SLEEP | MR_POISON | MR_ACID, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE, + M2_HOSTILE | M2_STRONG, 0, CLR_CYAN), + MON("iron golem", S_GOLEM, LVL(18, 6, 3, 60, 0), (G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), ATTK(AT_BREA, AD_DRST, 4, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2000, 0, MS_SILENT, MZ_LARGE), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_BREATHLESS | M1_MINDLESS | M1_HUMANOID | M1_THICK_HIDE | M1_POIS, + M2_HOSTILE | M2_STRONG | M2_COLLECT, 0, HI_METAL), + /* + * humans, including elves and were-critters + */ + MON("human", S_HUMAN, LVL(0, 12, 10, 0, 0), G_NOGEN, /* for corpses */ + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("wererat", S_HUMAN, LVL(2, 12, 10, 10, -7), (1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_REGEN | M1_OMNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE | M2_HUMAN | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BROWN), + MON("werejackal", S_HUMAN, LVL(2, 12, 10, 10, -7), (1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_REGEN | M1_OMNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE | M2_HUMAN | M2_COLLECT, + M3_INFRAVISIBLE, CLR_RED), + MON("werewolf", S_HUMAN, LVL(5, 12, 10, 20, -7), (1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_WERE, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_REGEN | M1_OMNIVORE, + M2_NOPOLY | M2_WERE | M2_HOSTILE | M2_HUMAN | M2_COLLECT, + M3_INFRAVISIBLE, CLR_ORANGE), + MON("elf", S_HUMAN, LVL(10, 12, 10, 2, -3), G_NOGEN, /* for corpses */ + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, + M2_NOPOLY | M2_ELF | M2_STRONG | M2_COLLECT, + M3_INFRAVISION | M3_INFRAVISIBLE, HI_DOMESTIC), + MON("Woodland-elf", S_HUMAN, LVL(4, 12, 10, 10, -5), + (G_GENO | G_SGROUP | 2), A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, M2_ELF | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GREEN), + MON("Green-elf", S_HUMAN, LVL(5, 12, 10, 10, -6), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, M2_ELF | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BRIGHT_GREEN), + MON("Grey-elf", S_HUMAN, LVL(6, 12, 10, 10, -7), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, M2_ELF | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("elf-lord", S_HUMAN, LVL(8, 12, 10, 20, -9), (G_GENO | G_SGROUP | 2), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, + M2_ELF | M2_STRONG | M2_LORD | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BRIGHT_BLUE), + MON("Elvenking", S_HUMAN, LVL(9, 12, 10, 25, -10), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_ELF, 350, MS_HUMANOID, MZ_HUMAN), MR_SLEEP, MR_SLEEP, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS, + M2_ELF | M2_STRONG | M2_PRINCE | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("doppelganger", S_HUMAN, LVL(9, 12, 5, 20, 0), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 12), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_IMITATE, MZ_HUMAN), MR_SLEEP, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_HOSTILE | M2_STRONG | M2_COLLECT + | M2_SHAPESHIFTER, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("shopkeeper", S_HUMAN, LVL(12, 18, 0, 50, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 4, 4), ATTK(AT_WEAP, AD_PHYS, 4, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SELL, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_PEACEFUL + | M2_STRONG | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("guard", S_HUMAN, LVL(12, 12, 10, 40, 10), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARD, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_MERC | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BLUE), + MON("prisoner", S_HUMAN, LVL(12, 12, 10, 0, 0), + G_NOGEN, /* for special levels */ + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_DJINNI, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE | M3_CLOSE, HI_DOMESTIC), + MON("Oracle", S_HUMAN, LVL(12, 0, 0, 50, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_NONE, AD_MAGM, 0, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_ORACLE, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_FEMALE, M3_INFRAVISIBLE, + HI_ZAP), + /* aligned priests always have the epri extension attached; + individual instantiations should always have either ispriest + or isminion set */ + MON("aligned priest", S_HUMAN, LVL(12, 12, 10, 50, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), ATTK(AT_KICK, AD_PHYS, 1, 4), + ATTK(AT_MAGC, AD_CLRC, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_PRIEST, MZ_HUMAN), MR_ELEC, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_LORD | M2_PEACEFUL | M2_COLLECT, + M3_INFRAVISIBLE, CLR_WHITE), + /* high priests always have epri and always have ispriest set */ + MON("high priest", S_HUMAN, LVL(25, 15, 7, 70, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), ATTK(AT_KICK, AD_PHYS, 2, 8), + ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_PRIEST, MZ_HUMAN), + MR_FIRE | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_HUMANOID | M1_SEE_INVIS | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_MINION | M2_PRINCE | M2_NASTY | M2_COLLECT + | M2_MAGIC, + M3_INFRAVISIBLE, CLR_WHITE), + MON("soldier", S_HUMAN, LVL(6, 10, 10, 0, -2), (G_SGROUP | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_HOSTILE | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_GRAY), + MON("sergeant", S_HUMAN, LVL(8, 10, 10, 5, -3), (G_SGROUP | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_HOSTILE | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_RED), + MON("nurse", S_HUMAN, LVL(11, 6, 0, 0, 0), (G_GENO | 3), + A(ATTK(AT_CLAW, AD_HEAL, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NURSE, MZ_HUMAN), MR_POISON, MR_POISON, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_HOSTILE, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("lieutenant", S_HUMAN, LVL(10, 10, 10, 15, -4), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_WEAP, AD_PHYS, 3, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_HOSTILE | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_GREEN), + MON("captain", S_HUMAN, LVL(12, 10, 10, 15, -5), (G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 4, 4), ATTK(AT_WEAP, AD_PHYS, 4, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_HOSTILE | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_BLUE), + /* Keep these separate - some of the mkroom code assumes that + * all the soldiers are contiguous. + */ + MON("watchman", S_HUMAN, LVL(6, 10, 10, 0, -2), + (G_SGROUP | G_NOGEN | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_GRAY), + MON("watch captain", S_HUMAN, LVL(10, 10, 10, 15, -4), + (G_NOGEN | G_GENO | 1), + A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_WEAP, AD_PHYS, 3, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SOLDIER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_MERC | M2_STALK + | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, CLR_GREEN), + /* Unique humans not tied to quests. + */ + MON("Medusa", S_HUMAN, LVL(20, 12, 2, 50, -15), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 1, 8), + ATTK(AT_GAZE, AD_STON, 0, 0), ATTK(AT_BITE, AD_DRST, 1, 6), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HISS, MZ_LARGE), MR_POISON | MR_STONE, + MR_POISON | MR_STONE, M1_FLY | M1_SWIM | M1_AMPHIBIOUS | M1_HUMANOID + | M1_POIS | M1_OMNIVORE, + M2_NOPOLY | M2_HOSTILE | M2_STRONG | M2_PNAME | M2_FEMALE, + M3_WAITFORU | M3_INFRAVISIBLE, CLR_BRIGHT_GREEN), + MON("Wizard of Yendor", S_HUMAN, LVL(30, 12, -8, 100, A_NONE), + (G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_SAMU, 2, 12), ATTK(AT_MAGC, AD_SPEL, 0, 0), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_CUSS, MZ_HUMAN), MR_FIRE | MR_POISON, + MR_FIRE | MR_POISON, + M1_FLY | M1_BREATHLESS | M1_HUMANOID | M1_REGEN | M1_SEE_INVIS + | M1_TPORT | M1_TPORT_CNTRL | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_HOSTILE | M2_STRONG | M2_NASTY | M2_PRINCE + | M2_MALE | M2_MAGIC, + M3_COVETOUS | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), + MON("Croesus", S_HUMAN, LVL(20, 15, 0, 40, 15), (G_UNIQ | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARD, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_SEE_INVIS | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY + | M2_PNAME | M2_PRINCE | M2_MALE | M2_GREEDY | M2_JEWELS + | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE, HI_LORD), #ifdef CHARON - MON("Charon", S_HUMAN, - LVL(76, 18, -5, 120, 0), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_TUCH, AD_PLYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_FERRY, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_POISON|MR_STONE, 0, - M1_BREATHLESS|M1_SEE_INVIS|M1_HUMANOID, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_PNAME|M2_MALE|M2_GREEDY|M2_COLLECT, - M3_INFRAVISIBLE, CLR_WHITE), + MON("Charon", S_HUMAN, LVL(76, 18, -5, 120, 0), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_TUCH, AD_PLYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_FERRY, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_POISON | MR_STONE, 0, + M1_BREATHLESS | M1_SEE_INVIS | M1_HUMANOID, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_PNAME | M2_MALE | M2_GREEDY + | M2_COLLECT, + M3_INFRAVISIBLE, CLR_WHITE), #endif -/* - * ghosts + /* + * ghosts + */ + MON("ghost", S_GHOST, LVL(10, 3, -5, 50, -5), (G_NOCORPSE | G_NOGEN), + A(ATTK(AT_TUCH, AD_PHYS, 1, 1), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 0, MS_SILENT, MZ_HUMAN), + MR_COLD | MR_DISINT | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_WALLWALK | M1_HUMANOID | M1_UNSOLID, + M2_NOPOLY | M2_UNDEAD | M2_STALK | M2_HOSTILE, M3_INFRAVISION, + CLR_GRAY), + MON("shade", S_GHOST, LVL(12, 10, 10, 0, 0), (G_NOCORPSE | G_NOGEN), + A(ATTK(AT_TUCH, AD_PLYS, 2, 6), ATTK(AT_TUCH, AD_SLOW, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 0, MS_WAIL, MZ_HUMAN), + MR_COLD | MR_DISINT | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_BREATHLESS | M1_WALLWALK | M1_HUMANOID | M1_UNSOLID + | M1_SEE_INVIS, + M2_NOPOLY | M2_UNDEAD | M2_WANDER | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISION, CLR_BLACK), + /* + * (major) demons + */ + MON("water demon", S_DEMON, LVL(8, 12, -4, 30, -7), + (G_NOCORPSE | G_NOGEN), + A(ATTK(AT_WEAP, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), + ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_DJINNI, MZ_HUMAN), MR_FIRE | MR_POISON, 0, + M1_HUMANOID | M1_POIS | M1_SWIM, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BLUE), +/* standard demons & devils */ - MON("ghost", S_GHOST, - LVL(10, 3, -5, 50, -5), (G_NOCORPSE|G_NOGEN), - A(ATTK(AT_TUCH, AD_PHYS, 1, 1), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 0, MS_SILENT, MZ_HUMAN), - MR_COLD|MR_DISINT|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_WALLWALK|M1_HUMANOID|M1_UNSOLID, - M2_NOPOLY|M2_UNDEAD|M2_STALK|M2_HOSTILE, M3_INFRAVISION, CLR_GRAY), - MON("shade", S_GHOST, - LVL(12, 10, 10, 0, 0), (G_NOCORPSE|G_NOGEN), - A(ATTK(AT_TUCH, AD_PLYS, 2, 6), ATTK(AT_TUCH, AD_SLOW, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 0, MS_WAIL, MZ_HUMAN), - MR_COLD|MR_DISINT|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_BREATHLESS|M1_WALLWALK|M1_HUMANOID|M1_UNSOLID|M1_SEE_INVIS, - M2_NOPOLY|M2_UNDEAD|M2_WANDER|M2_STALK|M2_HOSTILE|M2_NASTY, - M3_INFRAVISION, CLR_BLACK), -/* - * (major) demons - */ - MON("water demon", S_DEMON, - LVL(8, 12,-4, 30, -7), (G_NOCORPSE|G_NOGEN), - A(ATTK(AT_WEAP, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), - ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_DJINNI, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_POIS|M1_SWIM, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_BLUE), - /* standard demons & devils - */ -#define SEDUCTION_ATTACKS_YES \ - A(ATTK(AT_BITE, AD_SSEX, 0, 0), ATTK(AT_CLAW, AD_PHYS, 1, 3), \ - ATTK(AT_CLAW, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK) -#define SEDUCTION_ATTACKS_NO \ - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), \ - ATTK(AT_BITE, AD_DRLI, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK) - MON("succubus", S_DEMON, - LVL(6, 12, 0, 70, -9), (G_NOCORPSE|1), - SEDUCTION_ATTACKS_YES, - SIZ(WT_HUMAN, 400, MS_SEDUCE, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_FLY|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_FEMALE, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("horned devil", S_DEMON, - LVL(6, 9, -5, 50, 11), (G_HELL|G_NOCORPSE|2), - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_BITE, AD_PHYS, 2, 3), ATTK(AT_STNG, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_POIS|M1_THICK_HIDE, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_BROWN), - MON("incubus", S_DEMON, - LVL(6, 12, 0, 70, -9), (G_NOCORPSE|1), - SEDUCTION_ATTACKS_YES, - SIZ(WT_HUMAN, 400, MS_SEDUCE, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_FLY|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_MALE, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), +#define SEDUCTION_ATTACKS_YES \ + A(ATTK(AT_BITE, AD_SSEX, 0, 0), ATTK(AT_CLAW, AD_PHYS, 1, 3), \ + ATTK(AT_CLAW, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK) +#define SEDUCTION_ATTACKS_NO \ + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), \ + ATTK(AT_BITE, AD_DRLI, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK) + MON("succubus", S_DEMON, LVL(6, 12, 0, 70, -9), (G_NOCORPSE | 1), + SEDUCTION_ATTACKS_YES, SIZ(WT_HUMAN, 400, MS_SEDUCE, MZ_HUMAN), + MR_FIRE | MR_POISON, 0, M1_HUMANOID | M1_FLY | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_FEMALE, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("horned devil", S_DEMON, LVL(6, 9, -5, 50, 11), + (G_HELL | G_NOCORPSE | 2), + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_BITE, AD_PHYS, 2, 3), ATTK(AT_STNG, AD_PHYS, 1, 3), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE | MR_POISON, 0, + M1_POIS | M1_THICK_HIDE, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_BROWN), + MON("incubus", S_DEMON, LVL(6, 12, 0, 70, -9), (G_NOCORPSE | 1), + SEDUCTION_ATTACKS_YES, SIZ(WT_HUMAN, 400, MS_SEDUCE, MZ_HUMAN), + MR_FIRE | MR_POISON, 0, M1_HUMANOID | M1_FLY | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_MALE, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), /* Used by AD&D for a type of demon, originally one of the Furies */ /* and spelled this way */ - MON("erinys", S_DEMON, - LVL(7, 12, 2, 30, 10), (G_HELL|G_NOCORPSE|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_DRST, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_FEMALE| - M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("barbed devil", S_DEMON, - LVL(8, 12, 0, 35, 8), (G_HELL|G_NOCORPSE|G_SGROUP|2), - A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), - ATTK(AT_STNG, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_POIS|M1_THICK_HIDE, M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("marilith", S_DEMON, - LVL(7, 12, -6, 80, -12), (G_HELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), - ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), - ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4)), - SIZ(WT_HUMAN, 400, MS_CUSS, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_SLITHY|M1_SEE_INVIS|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_FEMALE|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("vrock", S_DEMON, - LVL(8, 12, 0, 50, -9), (G_HELL|G_NOCORPSE|G_SGROUP|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_CLAW, AD_PHYS, 1, 8), - ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_POIS, M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("hezrou", S_DEMON, - LVL(9, 6, -2, 55, -10), (G_HELL|G_NOCORPSE|G_SGROUP|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), - ATTK(AT_BITE, AD_PHYS, 4, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_POIS, M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("bone devil", S_DEMON, - LVL(9, 15, -1, 40, -9), (G_HELL|G_NOCORPSE|G_SGROUP|2), - A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_STNG, AD_DRST, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_POIS, M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("ice devil", S_DEMON, - LVL(11, 6, -4, 55, -12), (G_HELL|G_NOCORPSE|2), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_STNG, AD_COLD, 3, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), - MR_FIRE|MR_COLD|MR_POISON, 0, M1_SEE_INVIS|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_WHITE), - MON("nalfeshnee", S_DEMON, - LVL(11, 9, -1, 65, -11), (G_HELL|G_NOCORPSE|1), - A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), - ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SPELL, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_HUMANOID|M1_POIS, M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("pit fiend", S_DEMON, - LVL(13, 6, -3, 65, -13), (G_HELL|G_NOCORPSE|2), - A(ATTK(AT_WEAP, AD_PHYS, 4, 2), ATTK(AT_WEAP, AD_PHYS, 4, 2), - ATTK(AT_HUGS, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GROWL, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_SEE_INVIS|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - MON("sandestin", S_DEMON, - LVL(13, 12, 4, 60, -5), (G_HELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 400, MS_CUSS, MZ_HUMAN), MR_STONE, 0, - M1_HUMANOID, M2_NOPOLY|M2_STALK|M2_STRONG|M2_COLLECT|M2_SHAPESHIFTER, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_GRAY), - MON("balrog", S_DEMON, - LVL(16, 5, -2, 75, -14), (G_HELL|G_NOCORPSE|1), - A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_DEMON|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_COLLECT, - M3_INFRAVISIBLE|M3_INFRAVISION, CLR_RED), - /* Named demon lords & princes plus Arch-Devils. - * (their order matters; see minion.c) - */ - MON("Juiblex", S_DEMON, - LVL(50, 3, -7, 65, -15), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_ENGL, AD_DISE, 4,10), ATTK(AT_SPIT, AD_ACID, 3, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 0, MS_GURGLE, MZ_LARGE), - MR_FIRE|MR_POISON|MR_ACID|MR_STONE, 0, - M1_AMPHIBIOUS|M1_AMORPHOUS|M1_NOHEAD|M1_FLY|M1_SEE_INVIS|M1_ACID| - M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY|M2_LORD| - M2_MALE, - M3_WAITFORU|M3_WANTSAMUL|M3_INFRAVISION, CLR_BRIGHT_GREEN), - MON("Yeenoghu", S_DEMON, - LVL(56, 18, -5, 80, -15), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_WEAP, AD_CONF, 2, 8), - ATTK(AT_CLAW, AD_PLYS, 1, 6), ATTK(AT_MAGC, AD_MAGM, 2, 6), - NO_ATTK, NO_ATTK), - SIZ(900, 500, MS_ORC, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY|M2_LORD| - M2_MALE|M2_COLLECT, - M3_WANTSAMUL|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("Orcus", S_DEMON, - LVL(66, 9, -6, 85, -20), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 4), - ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_MAGC, AD_SPEL, 8, 6), - ATTK(AT_STNG, AD_DRST, 2, 4), NO_ATTK), - SIZ(1500, 500, MS_ORC, MZ_HUGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY|M2_PRINCE| - M2_MALE|M2_COLLECT, - M3_WAITFORU|M3_WANTSBOOK|M3_WANTSAMUL|M3_INFRAVISIBLE|M3_INFRAVISION, - HI_LORD), - MON("Geryon", S_DEMON, - LVL(72, 3, -3, 75, 15), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 6), - ATTK(AT_STNG, AD_DRST, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_BRIBE, MZ_HUGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS|M1_SLITHY, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY| - M2_PRINCE|M2_MALE, - M3_WANTSAMUL|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("Dispater", S_DEMON, - LVL(78, 15, -2, 80, 15), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 4, 6), ATTK(AT_MAGC, AD_SPEL, 6, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_BRIBE, MZ_HUMAN), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS|M1_HUMANOID, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY| - M2_PRINCE|M2_MALE|M2_COLLECT, - M3_WANTSAMUL|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("Baalzebub", S_DEMON, - LVL(89, 9, -5, 85, 20), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_BITE, AD_DRST, 2, 6), ATTK(AT_GAZE, AD_STUN, 2, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_BRIBE, MZ_LARGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY| - M2_PRINCE|M2_MALE, - M3_WANTSAMUL|M3_WAITFORU|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("Asmodeus", S_DEMON, - LVL(105, 12, -7, 90, 20), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_PHYS, 4, 4), ATTK(AT_MAGC, AD_COLD, 6, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_BRIBE, MZ_HUGE), MR_FIRE|MR_COLD|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_HUMANOID|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_STRONG| - M2_NASTY|M2_PRINCE|M2_MALE, - M3_WANTSAMUL|M3_WAITFORU|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - MON("Demogorgon", S_DEMON, - LVL(106, 15, -8, 95, -20), (G_HELL|G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_MAGC, AD_SPEL, 8, 6), ATTK(AT_STNG, AD_DRLI, 1, 4), - ATTK(AT_CLAW, AD_DISE, 1, 6), ATTK(AT_CLAW, AD_DISE, 1, 6), - NO_ATTK, NO_ATTK), - SIZ(1500, 500, MS_GROWL, MZ_HUGE), MR_FIRE|MR_POISON, 0, - M1_FLY|M1_SEE_INVIS|M1_NOHANDS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_PNAME|M2_NASTY| - M2_PRINCE|M2_MALE, - M3_WANTSAMUL|M3_INFRAVISIBLE|M3_INFRAVISION, HI_LORD), - /* Riders -- the Four Horsemen of the Apocalypse ("War" == player) - */ - MON("Death", S_DEMON, - LVL(30, 12, -5, 100, 0), (G_UNIQ|G_NOGEN), - A(ATTK(AT_TUCH, AD_DETH, 8, 8), ATTK(AT_TUCH, AD_DETH, 8, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_HUMANOID|M1_REGEN|M1_SEE_INVIS|M1_TPORT_CNTRL, - M2_NOPOLY|M2_STALK|M2_HOSTILE|M2_PNAME|M2_STRONG|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION|M3_DISPLACES, HI_LORD), - MON("Pestilence", S_DEMON, - LVL(30, 12, -5, 100, 0), (G_UNIQ|G_NOGEN), - A(ATTK(AT_TUCH, AD_PEST, 8, 8), ATTK(AT_TUCH, AD_PEST, 8, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_HUMANOID|M1_REGEN|M1_SEE_INVIS|M1_TPORT_CNTRL, - M2_NOPOLY|M2_STALK|M2_HOSTILE|M2_PNAME|M2_STRONG|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION|M3_DISPLACES, HI_LORD), - MON("Famine", S_DEMON, - LVL(30, 12, -5, 100, 0), (G_UNIQ|G_NOGEN), - A(ATTK(AT_TUCH, AD_FAMN, 8, 8), ATTK(AT_TUCH, AD_FAMN, 8, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_HUMANOID|M1_REGEN|M1_SEE_INVIS|M1_TPORT_CNTRL, - M2_NOPOLY|M2_STALK|M2_HOSTILE|M2_PNAME|M2_STRONG|M2_NASTY, - M3_INFRAVISIBLE|M3_INFRAVISION|M3_DISPLACES, HI_LORD), - /* other demons - */ + MON("erinys", S_DEMON, LVL(7, 12, 2, 30, 10), + (G_HELL | G_NOCORPSE | G_SGROUP | 2), + A(ATTK(AT_WEAP, AD_DRST, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE | MR_POISON, 0, + M1_HUMANOID | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY + | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("barbed devil", S_DEMON, LVL(8, 12, 0, 35, 8), + (G_HELL | G_NOCORPSE | G_SGROUP | 2), + A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), + ATTK(AT_STNG, AD_PHYS, 3, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_HUMAN), MR_FIRE | MR_POISON, 0, + M1_POIS | M1_THICK_HIDE, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("marilith", S_DEMON, LVL(7, 12, -6, 80, -12), + (G_HELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_WEAP, AD_PHYS, 2, 4), + ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), + ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4)), + SIZ(WT_HUMAN, 400, MS_CUSS, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_HUMANOID | M1_SLITHY | M1_SEE_INVIS | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("vrock", S_DEMON, LVL(8, 12, 0, 50, -9), + (G_HELL | G_NOCORPSE | G_SGROUP | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_CLAW, AD_PHYS, 1, 8), + ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_POIS, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("hezrou", S_DEMON, LVL(9, 6, -2, 55, -10), + (G_HELL | G_NOCORPSE | G_SGROUP | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 3), ATTK(AT_CLAW, AD_PHYS, 1, 3), + ATTK(AT_BITE, AD_PHYS, 4, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_HUMANOID | M1_POIS, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("bone devil", S_DEMON, LVL(9, 15, -1, 40, -9), + (G_HELL | G_NOCORPSE | G_SGROUP | 2), + A(ATTK(AT_WEAP, AD_PHYS, 3, 4), ATTK(AT_STNG, AD_DRST, 2, 4), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_POIS, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("ice devil", S_DEMON, LVL(11, 6, -4, 55, -12), + (G_HELL | G_NOCORPSE | 2), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_STNG, AD_COLD, 3, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), + MR_FIRE | MR_COLD | MR_POISON, 0, M1_SEE_INVIS | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_WHITE), + MON("nalfeshnee", S_DEMON, LVL(11, 9, -1, 65, -11), + (G_HELL | G_NOCORPSE | 1), + A(ATTK(AT_CLAW, AD_PHYS, 1, 4), ATTK(AT_CLAW, AD_PHYS, 1, 4), + ATTK(AT_BITE, AD_PHYS, 2, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SPELL, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_HUMANOID | M1_POIS, M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("pit fiend", S_DEMON, LVL(13, 6, -3, 65, -13), + (G_HELL | G_NOCORPSE | 2), + A(ATTK(AT_WEAP, AD_PHYS, 4, 2), ATTK(AT_WEAP, AD_PHYS, 4, 2), + ATTK(AT_HUGS, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GROWL, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_SEE_INVIS | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + MON("sandestin", S_DEMON, LVL(13, 12, 4, 60, -5), + (G_HELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 400, MS_CUSS, MZ_HUMAN), MR_STONE, 0, M1_HUMANOID, + M2_NOPOLY | M2_STALK | M2_STRONG | M2_COLLECT | M2_SHAPESHIFTER, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_GRAY), + MON("balrog", S_DEMON, LVL(16, 5, -2, 75, -14), (G_HELL | G_NOCORPSE | 1), + A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_DEMON | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY | M2_COLLECT, + M3_INFRAVISIBLE | M3_INFRAVISION, CLR_RED), + /* Named demon lords & princes plus Arch-Devils. + * (their order matters; see minion.c) + */ + MON("Juiblex", S_DEMON, LVL(50, 3, -7, 65, -15), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_ENGL, AD_DISE, 4, 10), ATTK(AT_SPIT, AD_ACID, 3, 6), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 0, MS_GURGLE, MZ_LARGE), + MR_FIRE | MR_POISON | MR_ACID | MR_STONE, 0, + M1_AMPHIBIOUS | M1_AMORPHOUS | M1_NOHEAD | M1_FLY | M1_SEE_INVIS + | M1_ACID | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_LORD | M2_MALE, + M3_WAITFORU | M3_WANTSAMUL | M3_INFRAVISION, CLR_BRIGHT_GREEN), + MON("Yeenoghu", S_DEMON, LVL(56, 18, -5, 80, -15), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_WEAP, AD_CONF, 2, 8), + ATTK(AT_CLAW, AD_PLYS, 1, 6), ATTK(AT_MAGC, AD_MAGM, 2, 6), NO_ATTK, + NO_ATTK), + SIZ(900, 500, MS_ORC, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_LORD | M2_MALE | M2_COLLECT, + M3_WANTSAMUL | M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("Orcus", S_DEMON, LVL(66, 9, -6, 85, -20), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 4), + ATTK(AT_CLAW, AD_PHYS, 3, 4), ATTK(AT_MAGC, AD_SPEL, 8, 6), + ATTK(AT_STNG, AD_DRST, 2, 4), NO_ATTK), + SIZ(1500, 500, MS_ORC, MZ_HUGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_PRINCE | M2_MALE | M2_COLLECT, + M3_WAITFORU | M3_WANTSBOOK | M3_WANTSAMUL | M3_INFRAVISIBLE + | M3_INFRAVISION, + HI_LORD), + MON("Geryon", S_DEMON, LVL(72, 3, -3, 75, 15), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_PHYS, 3, 6), ATTK(AT_CLAW, AD_PHYS, 3, 6), + ATTK(AT_STNG, AD_DRST, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 500, MS_BRIBE, MZ_HUGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS | M1_SLITHY, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_PRINCE | M2_MALE, + M3_WANTSAMUL | M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("Dispater", S_DEMON, LVL(78, 15, -2, 80, 15), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 4, 6), ATTK(AT_MAGC, AD_SPEL, 6, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 500, MS_BRIBE, MZ_HUMAN), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS | M1_HUMANOID, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_PRINCE | M2_MALE | M2_COLLECT, + M3_WANTSAMUL | M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + MON("Baalzebub", S_DEMON, LVL(89, 9, -5, 85, 20), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_BITE, AD_DRST, 2, 6), ATTK(AT_GAZE, AD_STUN, 2, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 500, MS_BRIBE, MZ_LARGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_PRINCE | M2_MALE, + M3_WANTSAMUL | M3_WAITFORU | M3_INFRAVISIBLE | M3_INFRAVISION, + HI_LORD), + MON("Asmodeus", S_DEMON, LVL(105, 12, -7, 90, 20), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_PHYS, 4, 4), ATTK(AT_MAGC, AD_COLD, 6, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1500, 500, MS_BRIBE, MZ_HUGE), MR_FIRE | MR_COLD | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_HUMANOID | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_STRONG + | M2_NASTY | M2_PRINCE | M2_MALE, + M3_WANTSAMUL | M3_WAITFORU | M3_INFRAVISIBLE | M3_INFRAVISION, + HI_LORD), + MON("Demogorgon", S_DEMON, LVL(106, 15, -8, 95, -20), + (G_HELL | G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_MAGC, AD_SPEL, 8, 6), ATTK(AT_STNG, AD_DRLI, 1, 4), + ATTK(AT_CLAW, AD_DISE, 1, 6), ATTK(AT_CLAW, AD_DISE, 1, 6), NO_ATTK, + NO_ATTK), + SIZ(1500, 500, MS_GROWL, MZ_HUGE), MR_FIRE | MR_POISON, 0, + M1_FLY | M1_SEE_INVIS | M1_NOHANDS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_PNAME | M2_NASTY + | M2_PRINCE | M2_MALE, + M3_WANTSAMUL | M3_INFRAVISIBLE | M3_INFRAVISION, HI_LORD), + /* Riders -- the Four Horsemen of the Apocalypse ("War" == player) + */ + MON("Death", S_DEMON, LVL(30, 12, -5, 100, 0), (G_UNIQ | G_NOGEN), + A(ATTK(AT_TUCH, AD_DETH, 8, 8), ATTK(AT_TUCH, AD_DETH, 8, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_HUMANOID | M1_REGEN | M1_SEE_INVIS | M1_TPORT_CNTRL, + M2_NOPOLY | M2_STALK | M2_HOSTILE | M2_PNAME | M2_STRONG | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION | M3_DISPLACES, HI_LORD), + MON("Pestilence", S_DEMON, LVL(30, 12, -5, 100, 0), (G_UNIQ | G_NOGEN), + A(ATTK(AT_TUCH, AD_PEST, 8, 8), ATTK(AT_TUCH, AD_PEST, 8, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_HUMANOID | M1_REGEN | M1_SEE_INVIS | M1_TPORT_CNTRL, + M2_NOPOLY | M2_STALK | M2_HOSTILE | M2_PNAME | M2_STRONG | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION | M3_DISPLACES, HI_LORD), + MON("Famine", S_DEMON, LVL(30, 12, -5, 100, 0), (G_UNIQ | G_NOGEN), + A(ATTK(AT_TUCH, AD_FAMN, 8, 8), ATTK(AT_TUCH, AD_FAMN, 8, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 1, MS_RIDER, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_HUMANOID | M1_REGEN | M1_SEE_INVIS | M1_TPORT_CNTRL, + M2_NOPOLY | M2_STALK | M2_HOSTILE | M2_PNAME | M2_STRONG | M2_NASTY, + M3_INFRAVISIBLE | M3_INFRAVISION | M3_DISPLACES, HI_LORD), +/* other demons + */ #ifdef MAIL - MON("mail daemon", S_DEMON, - LVL(56, 24, 10, 127, 0), (G_NOGEN|G_NOCORPSE), - A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(600, 300, MS_SILENT, MZ_HUMAN), - MR_FIRE|MR_COLD|MR_ELEC|MR_SLEEP|MR_POISON|MR_STONE, 0, - M1_FLY|M1_SWIM|M1_BREATHLESS|M1_SEE_INVIS|M1_HUMANOID|M1_POIS, - M2_NOPOLY|M2_STALK|M2_PEACEFUL, M3_INFRAVISIBLE|M3_INFRAVISION, - CLR_BRIGHT_BLUE), + MON("mail daemon", S_DEMON, LVL(56, 24, 10, 127, 0), + (G_NOGEN | G_NOCORPSE), + A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(600, 300, MS_SILENT, MZ_HUMAN), + MR_FIRE | MR_COLD | MR_ELEC | MR_SLEEP | MR_POISON | MR_STONE, 0, + M1_FLY | M1_SWIM | M1_BREATHLESS | M1_SEE_INVIS | M1_HUMANOID + | M1_POIS, + M2_NOPOLY | M2_STALK | M2_PEACEFUL, M3_INFRAVISIBLE | M3_INFRAVISION, + CLR_BRIGHT_BLUE), #endif - MON("djinni", S_DEMON, - LVL(7, 12, 4, 30, 0), (G_NOGEN|G_NOCORPSE), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1500, 400, MS_DJINNI, MZ_HUMAN), MR_POISON|MR_STONE, 0, - M1_HUMANOID|M1_FLY|M1_POIS, - M2_NOPOLY|M2_STALK|M2_COLLECT, M3_INFRAVISIBLE, CLR_YELLOW), -/* - * sea monsters - */ - MON("jellyfish", S_EEL, - LVL(3, 3, 6, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_STNG, AD_DRST, 3, 3), NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(80, 20, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, - M1_SWIM|M1_AMPHIBIOUS|M1_SLITHY|M1_NOLIMBS|M1_NOHEAD|M1_NOTAKE|M1_POIS, - M2_HOSTILE, 0, CLR_BLUE), - MON("piranha", S_EEL, - LVL(5, 12, 4, 0, 0), (G_GENO|G_NOGEN|G_SGROUP), - A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(60, 30, MS_SILENT, MZ_SMALL), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_SLITHY|M1_NOLIMBS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, 0, CLR_RED), - MON("shark", S_EEL, - LVL(7, 12, 2, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_BITE, AD_PHYS, 5, 6), NO_ATTK, - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(500, 350, MS_SILENT, MZ_LARGE), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_SLITHY|M1_NOLIMBS| - M1_CARNIVORE|M1_OVIPAROUS|M1_THICK_HIDE|M1_NOTAKE, - M2_HOSTILE, 0, CLR_GRAY), - MON("giant eel", S_EEL, - LVL(5, 9, -1, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_TUCH, AD_WRAP, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 250, MS_SILENT, MZ_HUGE), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_SLITHY|M1_NOLIMBS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, M3_INFRAVISIBLE, CLR_CYAN), - MON("electric eel", S_EEL, - LVL(7, 10, -3, 0, 0), (G_GENO|G_NOGEN), - A(ATTK(AT_BITE, AD_ELEC, 4, 6), ATTK(AT_TUCH, AD_WRAP, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 250, MS_SILENT, MZ_HUGE), MR_ELEC, MR_ELEC, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_SLITHY|M1_NOLIMBS| - M1_CARNIVORE|M1_OVIPAROUS|M1_NOTAKE, - M2_HOSTILE, M3_INFRAVISIBLE, CLR_BRIGHT_BLUE), - MON("kraken", S_EEL, - LVL(20, 3, 6, 0, -3), (G_GENO|G_NOGEN), - A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), - ATTK(AT_HUGS, AD_WRAP, 2, 6), ATTK(AT_BITE, AD_PHYS, 5, 4), - NO_ATTK, NO_ATTK), - SIZ(1800, 1000, MS_SILENT, MZ_HUGE), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_NOPOLY|M2_HOSTILE|M2_STRONG, M3_INFRAVISIBLE, CLR_RED), -/* - * lizards, &c - */ - MON("newt", S_LIZARD, - LVL(0, 6, 8, 0, 0), (G_GENO|5), - A(ATTK(AT_BITE, AD_PHYS, 1, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 20, MS_SILENT, MZ_TINY), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_YELLOW), - MON("gecko", S_LIZARD, - LVL(1, 6, 8, 0, 0), (G_GENO|5), - A(ATTK(AT_BITE, AD_PHYS, 1, 3), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 20, MS_SQEEK, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, 0, CLR_GREEN), - MON("iguana", S_LIZARD, - LVL(2, 6, 7, 0, 0), (G_GENO|5), - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(30, 30, MS_SILENT, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, 0, CLR_BROWN), - MON("baby crocodile", S_LIZARD, - LVL(3, 6, 7, 0, 0), G_GENO, - A(ATTK(AT_BITE, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(200, 200, MS_SILENT, MZ_MEDIUM), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, - M2_HOSTILE, 0, CLR_BROWN), - MON("lizard", S_LIZARD, - LVL(5, 6, 6, 10, 0), (G_GENO|5), - A(ATTK(AT_BITE, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(10, 40, MS_SILENT, MZ_TINY), MR_STONE, MR_STONE, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_HOSTILE, 0, CLR_GREEN), - MON("chameleon", S_LIZARD, - LVL(6, 5, 6, 10, 0), (G_GENO|2), - A(ATTK(AT_BITE, AD_PHYS, 4, 2), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(100, 100, MS_SILENT, MZ_TINY), 0, 0, - M1_ANIMAL|M1_NOHANDS|M1_CARNIVORE, M2_NOPOLY|M2_HOSTILE|M2_SHAPESHIFTER, - 0, CLR_BROWN), - MON("crocodile", S_LIZARD, - LVL(6, 9, 5, 0, 0), (G_GENO|1), - A(ATTK(AT_BITE, AD_PHYS, 4, 2), ATTK(AT_CLAW, AD_PHYS, 1,12), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), 0, 0, - M1_SWIM|M1_AMPHIBIOUS|M1_ANIMAL|M1_THICK_HIDE|M1_NOHANDS| - M1_OVIPAROUS|M1_CARNIVORE, - M2_STRONG|M2_HOSTILE, 0, CLR_BROWN), - MON("salamander", S_LIZARD, - LVL(8, 12, -1, 0, -9), (G_HELL|1), - A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_TUCH, AD_FIRE, 1, 6), - ATTK(AT_HUGS, AD_PHYS, 2, 6), ATTK(AT_HUGS, AD_FIRE, 3, 6), - NO_ATTK, NO_ATTK), - SIZ(1500, 400, MS_MUMBLE, MZ_HUMAN), MR_SLEEP|MR_FIRE, MR_FIRE, - M1_HUMANOID|M1_SLITHY|M1_THICK_HIDE|M1_POIS, - M2_STALK|M2_HOSTILE|M2_COLLECT|M2_MAGIC, M3_INFRAVISIBLE, CLR_ORANGE), + MON("djinni", S_DEMON, LVL(7, 12, 4, 30, 0), (G_NOGEN | G_NOCORPSE), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(1500, 400, MS_DJINNI, MZ_HUMAN), MR_POISON | MR_STONE, 0, + M1_HUMANOID | M1_FLY | M1_POIS, M2_NOPOLY | M2_STALK | M2_COLLECT, + M3_INFRAVISIBLE, CLR_YELLOW), + /* + * sea monsters + */ + MON("jellyfish", S_EEL, LVL(3, 3, 6, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_STNG, AD_DRST, 3, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(80, 20, MS_SILENT, MZ_SMALL), MR_POISON, MR_POISON, + M1_SWIM | M1_AMPHIBIOUS | M1_SLITHY | M1_NOLIMBS | M1_NOHEAD + | M1_NOTAKE | M1_POIS, + M2_HOSTILE, 0, CLR_BLUE), + MON("piranha", S_EEL, LVL(5, 12, 4, 0, 0), (G_GENO | G_NOGEN | G_SGROUP), + A(ATTK(AT_BITE, AD_PHYS, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(60, 30, MS_SILENT, MZ_SMALL), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_SLITHY | M1_NOLIMBS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, 0, CLR_RED), + MON("shark", S_EEL, LVL(7, 12, 2, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_BITE, AD_PHYS, 5, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(500, 350, MS_SILENT, MZ_LARGE), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_SLITHY | M1_NOLIMBS + | M1_CARNIVORE | M1_OVIPAROUS | M1_THICK_HIDE | M1_NOTAKE, + M2_HOSTILE, 0, CLR_GRAY), + MON("giant eel", S_EEL, LVL(5, 9, -1, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_BITE, AD_PHYS, 3, 6), ATTK(AT_TUCH, AD_WRAP, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(200, 250, MS_SILENT, MZ_HUGE), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_SLITHY | M1_NOLIMBS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_CYAN), + MON("electric eel", S_EEL, LVL(7, 10, -3, 0, 0), (G_GENO | G_NOGEN), + A(ATTK(AT_BITE, AD_ELEC, 4, 6), ATTK(AT_TUCH, AD_WRAP, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(200, 250, MS_SILENT, MZ_HUGE), MR_ELEC, MR_ELEC, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_SLITHY | M1_NOLIMBS + | M1_CARNIVORE | M1_OVIPAROUS | M1_NOTAKE, + M2_HOSTILE, M3_INFRAVISIBLE, CLR_BRIGHT_BLUE), + MON("kraken", S_EEL, LVL(20, 3, 6, 0, -3), (G_GENO | G_NOGEN), + A(ATTK(AT_CLAW, AD_PHYS, 2, 4), ATTK(AT_CLAW, AD_PHYS, 2, 4), + ATTK(AT_HUGS, AD_WRAP, 2, 6), ATTK(AT_BITE, AD_PHYS, 5, 4), NO_ATTK, + NO_ATTK), + SIZ(1800, 1000, MS_SILENT, MZ_HUGE), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_NOPOLY | M2_HOSTILE | M2_STRONG, M3_INFRAVISIBLE, CLR_RED), + /* + * lizards, &c + */ + MON("newt", S_LIZARD, LVL(0, 6, 8, 0, 0), (G_GENO | 5), + A(ATTK(AT_BITE, AD_PHYS, 1, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 20, MS_SILENT, MZ_TINY), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_YELLOW), + MON("gecko", S_LIZARD, LVL(1, 6, 8, 0, 0), (G_GENO | 5), + A(ATTK(AT_BITE, AD_PHYS, 1, 3), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 20, MS_SQEEK, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, 0, CLR_GREEN), + MON("iguana", S_LIZARD, LVL(2, 6, 7, 0, 0), (G_GENO | 5), + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(30, 30, MS_SILENT, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, 0, CLR_BROWN), + MON("baby crocodile", S_LIZARD, LVL(3, 6, 7, 0, 0), G_GENO, + A(ATTK(AT_BITE, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(200, 200, MS_SILENT, MZ_MEDIUM), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_HOSTILE, 0, CLR_BROWN), + MON("lizard", S_LIZARD, LVL(5, 6, 6, 10, 0), (G_GENO | 5), + A(ATTK(AT_BITE, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(10, 40, MS_SILENT, MZ_TINY), MR_STONE, MR_STONE, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, M2_HOSTILE, 0, CLR_GREEN), + MON("chameleon", S_LIZARD, LVL(6, 5, 6, 10, 0), (G_GENO | 2), + A(ATTK(AT_BITE, AD_PHYS, 4, 2), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(100, 100, MS_SILENT, MZ_TINY), 0, 0, + M1_ANIMAL | M1_NOHANDS | M1_CARNIVORE, + M2_NOPOLY | M2_HOSTILE | M2_SHAPESHIFTER, 0, CLR_BROWN), + MON("crocodile", S_LIZARD, LVL(6, 9, 5, 0, 0), (G_GENO | 1), + A(ATTK(AT_BITE, AD_PHYS, 4, 2), ATTK(AT_CLAW, AD_PHYS, 1, 12), + NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_SILENT, MZ_LARGE), 0, 0, + M1_SWIM | M1_AMPHIBIOUS | M1_ANIMAL | M1_THICK_HIDE | M1_NOHANDS + | M1_OVIPAROUS | M1_CARNIVORE, + M2_STRONG | M2_HOSTILE, 0, CLR_BROWN), + MON("salamander", S_LIZARD, LVL(8, 12, -1, 0, -9), (G_HELL | 1), + A(ATTK(AT_WEAP, AD_PHYS, 2, 8), ATTK(AT_TUCH, AD_FIRE, 1, 6), + ATTK(AT_HUGS, AD_PHYS, 2, 6), ATTK(AT_HUGS, AD_FIRE, 3, 6), NO_ATTK, + NO_ATTK), + SIZ(1500, 400, MS_MUMBLE, MZ_HUMAN), MR_SLEEP | MR_FIRE, MR_FIRE, + M1_HUMANOID | M1_SLITHY | M1_THICK_HIDE | M1_POIS, + M2_STALK | M2_HOSTILE | M2_COLLECT | M2_MAGIC, M3_INFRAVISIBLE, + CLR_ORANGE), -/* - * dummy monster needed for visual interface - */ - /* (marking it unique prevents figurines) - */ - MON("long worm tail", S_WORM_TAIL, - LVL(0, 0, 0, 0, 0), (G_NOGEN|G_NOCORPSE|G_UNIQ), - A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, 0, 0), 0, 0, 0L, M2_NOPOLY, 0, CLR_BROWN), + /* + * dummy monster needed for visual interface + */ + /* (marking it unique prevents figurines) + */ + MON("long worm tail", S_WORM_TAIL, LVL(0, 0, 0, 0, 0), + (G_NOGEN | G_NOCORPSE | G_UNIQ), + A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, 0, 0), 0, 0, 0L, M2_NOPOLY, 0, CLR_BROWN), - /* Note: - * Worm tail must be between the normal monsters and the special - * quest & pseudo-character ones because an optimization in the - * random monster selection code assumes everything beyond here - * has the G_NOGEN and M2_NOPOLY attributes. - */ + /* Note: + * Worm tail must be between the normal monsters and the special + * quest & pseudo-character ones because an optimization in the + * random monster selection code assumes everything beyond here + * has the G_NOGEN and M2_NOPOLY attributes. + */ -/* - * character classes - */ - MON("archeologist", S_HUMAN, - LVL(10, 12, 10, 1, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_TUNNEL|M1_NEEDPICK|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("barbarian", S_HUMAN, - LVL(10, 12, 10, 1, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("caveman", S_HUMAN, - LVL(10, 12, 10, 0, 1), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_MALE|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("cavewoman", S_HUMAN, - LVL(10, 12, 10, 0, 1), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_FEMALE|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("healer", S_HUMAN, - LVL(10, 12, 10, 1, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("knight", S_HUMAN, - LVL(10, 12, 10, 1, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("monk", S_HUMAN, - LVL(10, 12, 10, 2, 0), G_NOGEN, - A(ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_KICK, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_HERBIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT|M2_MALE, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("priest", S_HUMAN, - LVL(10, 12, 10, 2, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_MALE|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("priestess", S_HUMAN, - LVL(10, 12, 10, 2, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_FEMALE|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("ranger", S_HUMAN, - LVL(10, 12, 10, 2, -3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("rogue", S_HUMAN, - LVL(10, 12, 10, 1, -3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_GREEDY|M2_JEWELS|M2_COLLECT, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("samurai", S_HUMAN, - LVL(10, 12, 10, 1, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("tourist", S_HUMAN, - LVL(10, 12, 10, 1, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, HI_DOMESTIC), - MON("valkyrie", S_HUMAN, - LVL(10, 12, 10, 1, -1), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_COLD, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_FEMALE|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("wizard", S_HUMAN, - LVL(10, 12, 10, 3, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_COLLECT|M2_MAGIC, M3_INFRAVISIBLE, - HI_DOMESTIC), -/* - * quest leaders - */ - MON("Lord Carnarvon", S_HUMAN, - LVL(20, 12, 0, 30, 20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_TUNNEL|M1_NEEDPICK|M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Pelias", S_HUMAN, - LVL(20, 12, 0, 30, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Shaman Karnov", S_HUMAN, - LVL(20, 12, 0, 30, 20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), -#if 0 /* OBSOLETE */ + /* + * character classes + */ + MON("archeologist", S_HUMAN, LVL(10, 12, 10, 1, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_TUNNEL | M1_NEEDPICK | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("barbarian", S_HUMAN, LVL(10, 12, 10, 1, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("caveman", S_HUMAN, LVL(10, 12, 10, 0, 1), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("cavewoman", S_HUMAN, LVL(10, 12, 10, 0, 1), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("healer", S_HUMAN, LVL(10, 12, 10, 1, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("knight", S_HUMAN, LVL(10, 12, 10, 1, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("monk", S_HUMAN, LVL(10, 12, 10, 2, 0), G_NOGEN, + A(ATTK(AT_CLAW, AD_PHYS, 1, 8), ATTK(AT_KICK, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_HERBIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT | M2_MALE, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("priest", S_HUMAN, LVL(10, 12, 10, 2, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_MALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("priestess", S_HUMAN, LVL(10, 12, 10, 2, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("ranger", S_HUMAN, LVL(10, 12, 10, 2, -3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("rogue", S_HUMAN, LVL(10, 12, 10, 1, -3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_GREEDY | M2_JEWELS | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("samurai", S_HUMAN, LVL(10, 12, 10, 1, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("tourist", S_HUMAN, LVL(10, 12, 10, 1, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT, M3_INFRAVISIBLE, + HI_DOMESTIC), + MON("valkyrie", S_HUMAN, LVL(10, 12, 10, 1, -1), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), MR_COLD, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_FEMALE | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("wizard", S_HUMAN, LVL(10, 12, 10, 3, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + /* + * quest leaders + */ + MON("Lord Carnarvon", S_HUMAN, LVL(20, 12, 0, 30, 20), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_TUNNEL | M1_NEEDPICK | M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Pelias", S_HUMAN, LVL(20, 12, 0, 30, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Shaman Karnov", S_HUMAN, LVL(20, 12, 0, 30, 20), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), +#if 0 /* OBSOLETE */ /* Two for elves - one of each sex. */ MON("Earendil", S_HUMAN, @@ -3092,138 +2868,136 @@ struct permonst _mons2[] = { M2_FEMALE|M2_COLLECT|M2_MAGIC, M3_CLOSE|M3_INFRAVISION|M3_INFRAVISIBLE, HI_LORD), #endif - MON("Hippocrates", S_HUMAN, - LVL(20, 12, 0, 40, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("King Arthur", S_HUMAN, - LVL(20, 12, 0, 40, 20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Grand Master", S_HUMAN, - LVL(25, 12, 0, 70, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_PHYS, 4, 10), ATTK(AT_KICK, AD_PHYS, 2, 8), - ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), - MR_FIRE|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_HUMANOID|M1_SEE_INVIS|M1_HERBIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_MALE|M2_NASTY|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, CLR_BLACK), - MON("Arch Priest", S_HUMAN, - LVL(25, 12, 7, 70, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 4,10), ATTK(AT_KICK, AD_PHYS, 2, 8), - ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), - MR_FIRE|MR_ELEC|MR_SLEEP|MR_POISON, 0, - M1_HUMANOID|M1_SEE_INVIS|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_MALE|M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, CLR_WHITE), - MON("Orion", S_HUMAN, - LVL(20, 12, 0, 30, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2200, 700, MS_LEADER, MZ_HUGE), 0, 0, - M1_HUMANOID|M1_OMNIVORE|M1_SEE_INVIS|M1_SWIM|M1_AMPHIBIOUS, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISION|M3_INFRAVISIBLE, HI_LORD), - /* Note: Master of Thieves is also the Tourist's nemesis. - */ - MON("Master of Thieves", S_HUMAN, - LVL(20, 12, 0, 30, -20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), - ATTK(AT_CLAW, AD_SAMU, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_MALE|M2_GREEDY| - M2_JEWELS|M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Lord Sato", S_HUMAN, - LVL(20, 12, 0, 30, 20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Twoflower", S_HUMAN, - LVL(20, 12, 10, 20, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_PEACEFUL|M2_STRONG|M2_MALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_DOMESTIC), - MON("Norn", S_HUMAN, - LVL(20, 12, 0, 80, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1800, 550, MS_LEADER, MZ_HUGE), MR_COLD, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_FEMALE| - M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, HI_LORD), - MON("Neferet the Green", S_HUMAN, - LVL(20, 12, 0, 60, 0), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 2, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_FEMALE|M2_PNAME|M2_PEACEFUL| - M2_STRONG|M2_COLLECT|M2_MAGIC, - M3_CLOSE|M3_INFRAVISIBLE, CLR_GREEN), -/* - * quest nemeses - */ - MON("Minion of Huhetotl", S_DEMON, - LVL(16, 12, -2, 75, -14), (G_NOCORPSE|G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), - ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 2, 6), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_LARGE), - MR_FIRE|MR_POISON|MR_STONE, 0, M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_STALK|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_COLLECT, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISION|M3_INFRAVISIBLE, CLR_RED), - MON("Thoth Amon", S_HUMAN, - LVL(16, 12, 0, 10, -14), (G_NOGEN|G_UNIQ|G_NOCORPSE), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), - ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_POISON|MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_STRONG|M2_MALE|M2_STALK|M2_HOSTILE| - M2_NASTY|M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), - /* Multi-headed, possessing the breath attacks of all the other dragons - * (selected at random when attacking). - */ - MON("Chromatic Dragon", S_DRAGON, - LVL(16, 12, 0, 30, -14), (G_NOGEN|G_UNIQ), - A(ATTK(AT_BREA, AD_RBRE, 6, 8), ATTK(AT_MAGC, AD_SPEL, 0, 0), - ATTK(AT_CLAW, AD_SAMU, 2, 8), ATTK(AT_BITE, AD_PHYS, 4, 8), - ATTK(AT_BITE, AD_PHYS, 4, 8), ATTK(AT_STNG, AD_PHYS, 1, 6)), - SIZ(WT_DRAGON, 1700, MS_NEMESIS, MZ_GIGANTIC), - MR_FIRE|MR_COLD|MR_SLEEP|MR_DISINT|MR_ELEC|MR_POISON|MR_ACID|MR_STONE, - MR_FIRE|MR_COLD|MR_SLEEP|MR_DISINT|MR_ELEC|MR_POISON|MR_STONE, - M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_HOSTILE|M2_FEMALE|M2_STALK|M2_STRONG|M2_NASTY| - M2_GREEDY|M2_JEWELS|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), -#if 0 /* OBSOLETE */ + MON("Hippocrates", S_HUMAN, LVL(20, 12, 0, 40, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("King Arthur", S_HUMAN, LVL(20, 12, 0, 40, 20), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Grand Master", S_HUMAN, LVL(25, 12, 0, 70, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_PHYS, 4, 10), ATTK(AT_KICK, AD_PHYS, 2, 8), + ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), + MR_FIRE | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_HUMANOID | M1_SEE_INVIS | M1_HERBIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_MALE | M2_NASTY + | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, CLR_BLACK), + MON("Arch Priest", S_HUMAN, LVL(25, 12, 7, 70, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 4, 10), ATTK(AT_KICK, AD_PHYS, 2, 8), + ATTK(AT_MAGC, AD_CLRC, 2, 8), ATTK(AT_MAGC, AD_CLRC, 2, 8), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), + MR_FIRE | MR_ELEC | MR_SLEEP | MR_POISON, 0, + M1_HUMANOID | M1_SEE_INVIS | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_MALE | M2_COLLECT + | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, CLR_WHITE), + MON("Orion", S_HUMAN, LVL(20, 12, 0, 30, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(2200, 700, MS_LEADER, MZ_HUGE), 0, 0, + M1_HUMANOID | M1_OMNIVORE | M1_SEE_INVIS | M1_SWIM | M1_AMPHIBIOUS, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISION | M3_INFRAVISIBLE, HI_LORD), + /* Note: Master of Thieves is also the Tourist's nemesis. + */ + MON("Master of Thieves", S_HUMAN, LVL(20, 12, 0, 30, -20), + (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), + ATTK(AT_CLAW, AD_SAMU, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_MALE | M2_GREEDY + | M2_JEWELS | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Lord Sato", S_HUMAN, LVL(20, 12, 0, 30, 20), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Twoflower", S_HUMAN, LVL(20, 12, 10, 20, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_PEACEFUL | M2_STRONG | M2_MALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_DOMESTIC), + MON("Norn", S_HUMAN, LVL(20, 12, 0, 80, 0), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1800, 550, MS_LEADER, MZ_HUGE), MR_COLD, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_FEMALE + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, HI_LORD), + MON("Neferet the Green", S_HUMAN, LVL(20, 12, 0, 60, 0), + (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 2, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_LEADER, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_FEMALE | M2_PNAME | M2_PEACEFUL | M2_STRONG + | M2_COLLECT | M2_MAGIC, + M3_CLOSE | M3_INFRAVISIBLE, CLR_GREEN), + /* + * quest nemeses + */ + MON("Minion of Huhetotl", S_DEMON, LVL(16, 12, -2, 75, -14), + (G_NOCORPSE | G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), + ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_LARGE), + MR_FIRE | MR_POISON | MR_STONE, 0, M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_STALK | M2_HOSTILE | M2_STRONG | M2_NASTY + | M2_COLLECT, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISION | M3_INFRAVISIBLE, + CLR_RED), + MON("Thoth Amon", S_HUMAN, LVL(16, 12, 0, 10, -14), + (G_NOGEN | G_UNIQ | G_NOCORPSE), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), + ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_POISON | MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_STRONG | M2_MALE | M2_STALK + | M2_HOSTILE | M2_NASTY | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), + /* Multi-headed, possessing the breath attacks of all the other dragons + * (selected at random when attacking). + */ + MON("Chromatic Dragon", S_DRAGON, LVL(16, 12, 0, 30, -14), + (G_NOGEN | G_UNIQ), + A(ATTK(AT_BREA, AD_RBRE, 6, 8), ATTK(AT_MAGC, AD_SPEL, 0, 0), + ATTK(AT_CLAW, AD_SAMU, 2, 8), ATTK(AT_BITE, AD_PHYS, 4, 8), + ATTK(AT_BITE, AD_PHYS, 4, 8), ATTK(AT_STNG, AD_PHYS, 1, 6)), + SIZ(WT_DRAGON, 1700, MS_NEMESIS, MZ_GIGANTIC), + MR_FIRE | MR_COLD | MR_SLEEP | MR_DISINT | MR_ELEC | MR_POISON + | MR_ACID | MR_STONE, + MR_FIRE | MR_COLD | MR_SLEEP | MR_DISINT | MR_ELEC | MR_POISON + | MR_STONE, + M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_HOSTILE | M2_FEMALE | M2_STALK | M2_STRONG | M2_NASTY + | M2_GREEDY | M2_JEWELS | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), +#if 0 /* OBSOLETE */ MON("Goblin King", S_ORC, LVL(15, 12, 10, 0, -15), (G_NOGEN|G_UNIQ), A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), @@ -3234,127 +3008,121 @@ struct permonst _mons2[] = { M2_GREEDY|M2_JEWELS|M2_COLLECT|M2_MAGIC, M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISION|M3_INFRAVISIBLE, HI_LORD), #endif - MON("Cyclops", S_GIANT, - LVL(18, 12, 0, 0, -15), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 4, 8), ATTK(AT_WEAP, AD_PHYS, 4, 8), - ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(1900, 700, MS_NEMESIS, MZ_HUGE), MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_GIANT|M2_STRONG|M2_ROCKTHROW|M2_STALK|M2_HOSTILE| - M2_NASTY|M2_MALE|M2_JEWELS|M2_COLLECT, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISION|M3_INFRAVISIBLE, CLR_GRAY), - MON("Ixoth", S_DRAGON, - LVL(15, 12, -1, 20, -14), (G_NOGEN|G_UNIQ), - A(ATTK(AT_BREA, AD_FIRE, 8, 6), ATTK(AT_BITE, AD_PHYS, 4, 8), - ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_PHYS, 2, 4), - ATTK(AT_CLAW, AD_SAMU, 2, 4), NO_ATTK ), - SIZ(WT_DRAGON, 1600, MS_NEMESIS, MZ_GIGANTIC), - MR_FIRE|MR_STONE, MR_FIRE, - M1_FLY|M1_THICK_HIDE|M1_NOHANDS|M1_CARNIVORE|M1_SEE_INVIS, - M2_NOPOLY|M2_MALE|M2_PNAME|M2_HOSTILE|M2_STRONG|M2_NASTY|M2_STALK| - M2_GREEDY|M2_JEWELS|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, CLR_RED), - MON("Master Kaen", S_HUMAN, - LVL(25, 12, -10, 10, -20), (G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_PHYS, 16, 2), ATTK(AT_CLAW, AD_PHYS, 16, 2), - ATTK(AT_MAGC, AD_CLRC, 0, 0), ATTK(AT_CLAW, AD_SAMU, 1, 4), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), - MR_POISON|MR_STONE, MR_POISON, - M1_HUMANOID|M1_HERBIVORE|M1_SEE_INVIS, - M2_NOPOLY|M2_HUMAN|M2_MALE|M2_PNAME|M2_HOSTILE|M2_STRONG|M2_NASTY| - M2_STALK|M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), - MON("Nalzok", S_DEMON, - LVL(16, 12, -2, 85, -127), (G_NOGEN|G_UNIQ|G_NOCORPSE), - A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), - ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 2, 6), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_LARGE), - MR_FIRE|MR_POISON|MR_STONE, 0, M1_FLY|M1_SEE_INVIS|M1_POIS, - M2_NOPOLY|M2_DEMON|M2_MALE|M2_PNAME|M2_HOSTILE|M2_STRONG|M2_STALK| - M2_NASTY|M2_COLLECT, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISION|M3_INFRAVISIBLE, CLR_RED), - MON("Scorpius", S_SPIDER, - LVL(15, 12, 10, 0, -15), (G_NOGEN|G_UNIQ), - A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_SAMU, 2, 6), - ATTK(AT_STNG, AD_DISE, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(750, 350, MS_NEMESIS, MZ_HUMAN), MR_POISON|MR_STONE, MR_POISON, - M1_ANIMAL|M1_NOHANDS|M1_OVIPAROUS|M1_POIS|M1_CARNIVORE, - M2_NOPOLY|M2_MALE|M2_PNAME|M2_HOSTILE|M2_STRONG|M2_STALK|M2_NASTY| - M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU, HI_LORD), - MON("Master Assassin", S_HUMAN, - LVL(15, 12, 0, 30, 18), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_DRST, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 8), - ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_MALE|M2_HOSTILE|M2_STALK|M2_NASTY| - M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), - /* A renegade daimyo who led a 13 year civil war against the shogun - * of his time. - */ - MON("Ashikaga Takauji", S_HUMAN, - LVL(15, 12, 0, 40, -13), (G_NOGEN|G_UNIQ|G_NOCORPSE), - A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), - ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PNAME|M2_HOSTILE|M2_STRONG|M2_STALK| - M2_NASTY|M2_MALE|M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, HI_LORD), - /* - * Note: the Master of Thieves was defined above. - */ - MON("Lord Surtur", S_GIANT, - LVL(15, 12, 2, 50, 12), (G_NOGEN|G_UNIQ), - A(ATTK(AT_WEAP, AD_PHYS, 2,10), ATTK(AT_WEAP, AD_PHYS, 2,10), - ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(2250, 850, MS_NEMESIS, MZ_HUGE), MR_FIRE|MR_STONE, MR_FIRE, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_GIANT|M2_MALE|M2_PNAME|M2_HOSTILE|M2_STALK| - M2_STRONG|M2_NASTY|M2_ROCKTHROW|M2_JEWELS|M2_COLLECT, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISION|M3_INFRAVISIBLE, HI_LORD), - MON("Dark One", S_HUMAN, - LVL(15, 12, 0, 80, -10), (G_NOGEN|G_UNIQ|G_NOCORPSE), - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - ATTK(AT_CLAW, AD_SAMU, 1, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_STRONG|M2_HOSTILE|M2_STALK|M2_NASTY| - M2_COLLECT|M2_MAGIC, - M3_WANTSARTI|M3_WAITFORU|M3_INFRAVISIBLE, CLR_BLACK), -/* - * quest "guardians" - */ - MON("student", S_HUMAN, - LVL(5, 12, 10, 10, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_TUNNEL|M1_NEEDPICK|M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("chieftain", S_HUMAN, - LVL(5, 12, 10, 10, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("neanderthal", S_HUMAN, - LVL(5, 12, 10, 10, 1), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 2, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), -#if 0 /* OBSOLETE */ + MON("Cyclops", S_GIANT, LVL(18, 12, 0, 0, -15), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 4, 8), ATTK(AT_WEAP, AD_PHYS, 4, 8), + ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(1900, 700, MS_NEMESIS, MZ_HUGE), MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_GIANT | M2_STRONG | M2_ROCKTHROW | M2_STALK + | M2_HOSTILE | M2_NASTY | M2_MALE | M2_JEWELS | M2_COLLECT, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISION | M3_INFRAVISIBLE, + CLR_GRAY), + MON("Ixoth", S_DRAGON, LVL(15, 12, -1, 20, -14), (G_NOGEN | G_UNIQ), + A(ATTK(AT_BREA, AD_FIRE, 8, 6), ATTK(AT_BITE, AD_PHYS, 4, 8), + ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_PHYS, 2, 4), + ATTK(AT_CLAW, AD_SAMU, 2, 4), NO_ATTK), + SIZ(WT_DRAGON, 1600, MS_NEMESIS, MZ_GIGANTIC), MR_FIRE | MR_STONE, + MR_FIRE, + M1_FLY | M1_THICK_HIDE | M1_NOHANDS | M1_CARNIVORE | M1_SEE_INVIS, + M2_NOPOLY | M2_MALE | M2_PNAME | M2_HOSTILE | M2_STRONG | M2_NASTY + | M2_STALK | M2_GREEDY | M2_JEWELS | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, CLR_RED), + MON("Master Kaen", S_HUMAN, LVL(25, 12, -10, 10, -20), (G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_PHYS, 16, 2), ATTK(AT_CLAW, AD_PHYS, 16, 2), + ATTK(AT_MAGC, AD_CLRC, 0, 0), ATTK(AT_CLAW, AD_SAMU, 1, 4), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_POISON | MR_STONE, + MR_POISON, M1_HUMANOID | M1_HERBIVORE | M1_SEE_INVIS, + M2_NOPOLY | M2_HUMAN | M2_MALE | M2_PNAME | M2_HOSTILE | M2_STRONG + | M2_NASTY | M2_STALK | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), + MON("Nalzok", S_DEMON, LVL(16, 12, -2, 85, -127), + (G_NOGEN | G_UNIQ | G_NOCORPSE), + A(ATTK(AT_WEAP, AD_PHYS, 8, 4), ATTK(AT_WEAP, AD_PHYS, 4, 6), + ATTK(AT_MAGC, AD_SPEL, 0, 0), ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_LARGE), + MR_FIRE | MR_POISON | MR_STONE, 0, M1_FLY | M1_SEE_INVIS | M1_POIS, + M2_NOPOLY | M2_DEMON | M2_MALE | M2_PNAME | M2_HOSTILE | M2_STRONG + | M2_STALK | M2_NASTY | M2_COLLECT, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISION | M3_INFRAVISIBLE, + CLR_RED), + MON("Scorpius", S_SPIDER, LVL(15, 12, 10, 0, -15), (G_NOGEN | G_UNIQ), + A(ATTK(AT_CLAW, AD_PHYS, 2, 6), ATTK(AT_CLAW, AD_SAMU, 2, 6), + ATTK(AT_STNG, AD_DISE, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(750, 350, MS_NEMESIS, MZ_HUMAN), MR_POISON | MR_STONE, MR_POISON, + M1_ANIMAL | M1_NOHANDS | M1_OVIPAROUS | M1_POIS | M1_CARNIVORE, + M2_NOPOLY | M2_MALE | M2_PNAME | M2_HOSTILE | M2_STRONG | M2_STALK + | M2_NASTY | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU, HI_LORD), + MON("Master Assassin", S_HUMAN, LVL(15, 12, 0, 30, 18), + (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_DRST, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 8), + ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_MALE | M2_HOSTILE | M2_STALK + | M2_NASTY | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), + /* A renegade daimyo who led a 13 year civil war against the shogun + * of his time. + */ + MON("Ashikaga Takauji", S_HUMAN, LVL(15, 12, 0, 40, -13), + (G_NOGEN | G_UNIQ | G_NOCORPSE), + A(ATTK(AT_WEAP, AD_PHYS, 2, 6), ATTK(AT_WEAP, AD_PHYS, 2, 6), + ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PNAME | M2_HOSTILE | M2_STRONG | M2_STALK + | M2_NASTY | M2_MALE | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, HI_LORD), + /* + * Note: the Master of Thieves was defined above. + */ + MON("Lord Surtur", S_GIANT, LVL(15, 12, 2, 50, 12), (G_NOGEN | G_UNIQ), + A(ATTK(AT_WEAP, AD_PHYS, 2, 10), ATTK(AT_WEAP, AD_PHYS, 2, 10), + ATTK(AT_CLAW, AD_SAMU, 2, 6), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(2250, 850, MS_NEMESIS, MZ_HUGE), MR_FIRE | MR_STONE, MR_FIRE, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_GIANT | M2_MALE | M2_PNAME | M2_HOSTILE | M2_STALK + | M2_STRONG | M2_NASTY | M2_ROCKTHROW | M2_JEWELS | M2_COLLECT, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISION | M3_INFRAVISIBLE, + HI_LORD), + MON("Dark One", S_HUMAN, LVL(15, 12, 0, 80, -10), + (G_NOGEN | G_UNIQ | G_NOCORPSE), + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), + ATTK(AT_CLAW, AD_SAMU, 1, 4), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_NEMESIS, MZ_HUMAN), MR_STONE, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_STRONG | M2_HOSTILE | M2_STALK | M2_NASTY + | M2_COLLECT | M2_MAGIC, + M3_WANTSARTI | M3_WAITFORU | M3_INFRAVISIBLE, CLR_BLACK), + /* + * quest "guardians" + */ + MON("student", S_HUMAN, LVL(5, 12, 10, 10, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_TUNNEL | M1_NEEDPICK | M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("chieftain", S_HUMAN, LVL(5, 12, 10, 10, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("neanderthal", S_HUMAN, LVL(5, 12, 10, 10, 1), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 2, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), +#if 0 /* OBSOLETE */ MON("High-elf", S_HUMAN, LVL(5, 12, 10, 10, -7), G_NOGEN, A(ATTK(AT_WEAP, AD_PHYS, 2, 4), ATTK(AT_MAGC, AD_CLRC, 0, 0), @@ -3364,101 +3132,89 @@ struct permonst _mons2[] = { M2_NOPOLY|M2_ELF|M2_PEACEFUL|M2_COLLECT, M3_INFRAVISION|M3_INFRAVISIBLE, HI_DOMESTIC), #endif - MON("attendant", S_HUMAN, - LVL(5, 12, 10, 10, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), MR_POISON, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("page", S_HUMAN, - LVL(5, 12, 10, 10, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("abbot", S_HUMAN, - LVL(5, 12, 10, 20, 0), G_NOGEN, - A(ATTK(AT_CLAW, AD_PHYS, 8, 2), ATTK(AT_KICK, AD_STUN, 3, 2), - ATTK(AT_MAGC, AD_CLRC, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_HERBIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("acolyte", S_HUMAN, - LVL(5, 12, 10, 20, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_CLRC, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("hunter", S_HUMAN, - LVL(5, 12, 10, 10, -7), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 4), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_SEE_INVIS|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, - M3_INFRAVISION|M3_INFRAVISIBLE, HI_DOMESTIC), - MON("thug", S_HUMAN, - LVL(5, 12, 10, 10, -3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_GREEDY|M2_COLLECT, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("ninja", S_HUMAN, - LVL(5, 12, 10, 10, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_HOSTILE|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("roshi", S_HUMAN, - LVL(5, 12, 10, 10, 3), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("guide", S_HUMAN, - LVL(5, 12, 10, 20, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL | M2_STRONG|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE, HI_DOMESTIC), - MON("warrior", S_HUMAN, - LVL(5, 12, 10, 10, -1), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT|M2_FEMALE, M3_INFRAVISIBLE, - HI_DOMESTIC), - MON("apprentice", S_HUMAN, - LVL(5, 12, 10, 30, 0), G_NOGEN, - A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), - NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, - M1_HUMANOID|M1_OMNIVORE, - M2_NOPOLY|M2_HUMAN|M2_PEACEFUL|M2_STRONG|M2_COLLECT|M2_MAGIC, - M3_INFRAVISIBLE, HI_DOMESTIC), -/* - * array terminator - */ - MON("", 0, - LVL(0, 0, 0, 0, 0), (0), - A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), - SIZ(0, 0, 0, 0), 0, 0, 0L, 0L, 0, 0) + MON("attendant", S_HUMAN, LVL(5, 12, 10, 10, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), MR_POISON, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("page", S_HUMAN, LVL(5, 12, 10, 10, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("abbot", S_HUMAN, LVL(5, 12, 10, 20, 0), G_NOGEN, + A(ATTK(AT_CLAW, AD_PHYS, 8, 2), ATTK(AT_KICK, AD_STUN, 3, 2), + ATTK(AT_MAGC, AD_CLRC, 0, 0), NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_HERBIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("acolyte", S_HUMAN, LVL(5, 12, 10, 20, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_CLRC, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("hunter", S_HUMAN, LVL(5, 12, 10, 10, -7), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 4), NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, + NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_SEE_INVIS | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISION | M3_INFRAVISIBLE, HI_DOMESTIC), + MON("thug", S_HUMAN, LVL(5, 12, 10, 10, -3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_WEAP, AD_PHYS, 1, 6), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_PEACEFUL + | M2_STRONG | M2_GREEDY | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("ninja", S_HUMAN, LVL(5, 12, 10, 10, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_HUMANOID, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_HOSTILE | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("roshi", S_HUMAN, LVL(5, 12, 10, 10, 3), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, + M2_NOPOLY | M2_HUMAN | M2_PEACEFUL | M2_STRONG | M2_COLLECT, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("guide", S_HUMAN, LVL(5, 12, 10, 20, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_PEACEFUL + | M2_STRONG | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("warrior", S_HUMAN, LVL(5, 12, 10, 10, -1), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 8), ATTK(AT_WEAP, AD_PHYS, 1, 8), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_PEACEFUL + | M2_STRONG | M2_COLLECT | M2_FEMALE, + M3_INFRAVISIBLE, HI_DOMESTIC), + MON("apprentice", S_HUMAN, LVL(5, 12, 10, 30, 0), G_NOGEN, + A(ATTK(AT_WEAP, AD_PHYS, 1, 6), ATTK(AT_MAGC, AD_SPEL, 0, 0), NO_ATTK, + NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(WT_HUMAN, 400, MS_GUARDIAN, MZ_HUMAN), 0, 0, + M1_HUMANOID | M1_OMNIVORE, M2_NOPOLY | M2_HUMAN | M2_PEACEFUL + | M2_STRONG | M2_COLLECT | M2_MAGIC, + M3_INFRAVISIBLE, HI_DOMESTIC), + /* + * array terminator + */ + MON("", 0, LVL(0, 0, 0, 0, 0), (0), + A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK), + SIZ(0, 0, 0, 0), 0, 0, 0L, 0L, 0, 0) }; #endif /* !SPLITMON_1 */ diff --git a/src/mplayer.c b/src/mplayer.c index 3f79eef2e..e87171431 100644 --- a/src/mplayer.c +++ b/src/mplayer.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mplayer.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mplayer.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */ /* NetHack 3.6 mplayer.c $Date: 2009/05/06 10:47:09 $ $Revision: 1.11 $ */ /* SCCS Id: @(#)mplayer.c 3.5 2006/12/15 */ /* Copyright (c) Izchak Miller, 1992. */ @@ -17,53 +17,55 @@ STATIC_DCL void FDECL(mk_mplayer_armor, (struct monst *, SHORT_P)); * Same first name is entered once within each team. */ static const char *developers[] = { - /* devteam */ - "Dave", "Dean", "Eric", "Izchak", "Janet", "Jessie", - "Ken", "Kevin", "Michael", "Mike", "Pat", "Paul", "Steve", "Timo", - "Warwick", - /* PC team */ - "Bill", "Eric", "Keizo", "Ken", "Kevin", "Michael", "Mike", "Paul", - "Stephen", "Steve", "Timo", "Yitzhak", - /* Amiga team */ - "Andy", "Gregg", "Janne", "Keni", "Mike", "Olaf", "Richard", - /* Mac team */ - "Andy", "Chris", "Dean", "Jon", "Jonathan", "Kevin", "Wang", - /* Atari team */ - "Eric", "Marvin", "Warwick", - /* NT team */ - "Alex", "Dion", "Michael", - /* OS/2 team */ - "Helge", "Ron", "Timo", - /* VMS team */ - "Joshua", "Pat", - ""}; - + /* devteam */ + "Dave", "Dean", "Eric", "Izchak", "Janet", "Jessie", + "Ken", "Kevin", "Michael", "Mike", "Pat", "Paul", + "Steve", "Timo", "Warwick", + /* PC team */ + "Bill", "Eric", "Keizo", "Ken", "Kevin", "Michael", + "Mike", "Paul", "Stephen", "Steve", "Timo", "Yitzhak", + /* Amiga team */ + "Andy", "Gregg", "Janne", "Keni", "Mike", "Olaf", + "Richard", + /* Mac team */ + "Andy", "Chris", "Dean", "Jon", "Jonathan", "Kevin", + "Wang", + /* Atari team */ + "Eric", "Marvin", "Warwick", + /* NT team */ + "Alex", "Dion", "Michael", + /* OS/2 team */ + "Helge", "Ron", "Timo", + /* VMS team */ + "Joshua", "Pat", "" +}; /* return a randomly chosen developer name */ STATIC_OVL const char * dev_name() { - register int i, m = 0, n = SIZE(developers); - register struct monst *mtmp; - register boolean match; + register int i, m = 0, n = SIZE(developers); + register struct monst *mtmp; + register boolean match; - do { - match = FALSE; - i = rn2(n); - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if(!is_mplayer(mtmp->data)) continue; - if(!strncmp(developers[i], - (has_mname(mtmp)) ? MNAME(mtmp) : "", - strlen(developers[i]))) { - match = TRUE; - break; - } - } - m++; - } while (match && m < 100); /* m for insurance */ + do { + match = FALSE; + i = rn2(n); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (!is_mplayer(mtmp->data)) + continue; + if (!strncmp(developers[i], (has_mname(mtmp)) ? MNAME(mtmp) : "", + strlen(developers[i]))) { + match = TRUE; + break; + } + } + m++; + } while (match && m < 100); /* m for insurance */ - if (match) return (const char *)0; - return(developers[i]); + if (match) + return (const char *) 0; + return (developers[i]); } STATIC_OVL void @@ -71,24 +73,24 @@ get_mplname(mtmp, nam) register struct monst *mtmp; char *nam; { - boolean fmlkind = is_female(mtmp->data); - const char *devnam; + boolean fmlkind = is_female(mtmp->data); + const char *devnam; - devnam = dev_name(); - if (!devnam) - Strcpy(nam, fmlkind ? "Eve" : "Adam"); - else if (fmlkind && !!strcmp(devnam, "Janet")) - Strcpy(nam, rn2(2) ? "Maud" : "Eve"); - else Strcpy(nam, devnam); + devnam = dev_name(); + if (!devnam) + Strcpy(nam, fmlkind ? "Eve" : "Adam"); + else if (fmlkind && !!strcmp(devnam, "Janet")) + Strcpy(nam, rn2(2) ? "Maud" : "Eve"); + else + Strcpy(nam, devnam); - if (fmlkind || !strcmp(nam, "Janet")) - mtmp->female = 1; - else - mtmp->female = 0; - Strcat(nam, " the "); - Strcat(nam, rank_of((int)mtmp->m_lev, - monsndx(mtmp->data), - (boolean)mtmp->female)); + if (fmlkind || !strcmp(nam, "Janet")) + mtmp->female = 1; + else + mtmp->female = 0; + Strcat(nam, " the "); + Strcat(nam, rank_of((int) mtmp->m_lev, monsndx(mtmp->data), + (boolean) mtmp->female)); } STATIC_OVL void @@ -96,19 +98,23 @@ mk_mplayer_armor(mon, typ) struct monst *mon; short typ; { - struct obj *obj; + struct obj *obj; - if (typ == STRANGE_OBJECT) return; - obj = mksobj(typ, FALSE, FALSE); - if (!rn2(3)) obj->oerodeproof = 1; - if (!rn2(3)) curse(obj); - if (!rn2(3)) bless(obj); - /* Most players who get to the endgame who have cursed equipment - * have it because the wizard or other monsters cursed it, so its - * chances of having plusses is the same as usual.... - */ - obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4,4)) : -rnd(3); - (void) mpickobj(mon, obj); + if (typ == STRANGE_OBJECT) + return; + obj = mksobj(typ, FALSE, FALSE); + if (!rn2(3)) + obj->oerodeproof = 1; + if (!rn2(3)) + curse(obj); + if (!rn2(3)) + bless(obj); + /* Most players who get to the endgame who have cursed equipment + * have it because the wizard or other monsters cursed it, so its + * chances of having plusses is the same as usual.... + */ + obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4, 4)) : -rnd(3); + (void) mpickobj(mon, obj); } struct monst * @@ -117,166 +123,199 @@ register struct permonst *ptr; xchar x, y; register boolean special; { - register struct monst *mtmp; - char nam[PL_NSIZ]; + register struct monst *mtmp; + char nam[PL_NSIZ]; - if(!is_mplayer(ptr)) - return((struct monst *)0); + if (!is_mplayer(ptr)) + return ((struct monst *) 0); - if(MON_AT(x, y)) - (void) rloc(m_at(x, y), FALSE); /* insurance */ + if (MON_AT(x, y)) + (void) rloc(m_at(x, y), FALSE); /* insurance */ - if(!In_endgame(&u.uz)) special = FALSE; + if (!In_endgame(&u.uz)) + special = FALSE; - if ((mtmp = makemon(ptr, x, y, NO_MM_FLAGS)) != 0) { - short weapon = rn2(2) ? LONG_SWORD : rnd_class(SPEAR, BULLWHIP); - short armor = rnd_class(GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL); - short cloak = !rn2(8) ? STRANGE_OBJECT : - rnd_class(OILSKIN_CLOAK, CLOAK_OF_DISPLACEMENT); - short helm = !rn2(8) ? STRANGE_OBJECT : - rnd_class(ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY); - short shield = !rn2(8) ? STRANGE_OBJECT : - rnd_class(ELVEN_SHIELD, SHIELD_OF_REFLECTION); - int quan; - struct obj *otmp; + if ((mtmp = makemon(ptr, x, y, NO_MM_FLAGS)) != 0) { + short weapon = rn2(2) ? LONG_SWORD : rnd_class(SPEAR, BULLWHIP); + short armor = + rnd_class(GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL); + short cloak = !rn2(8) + ? STRANGE_OBJECT + : rnd_class(OILSKIN_CLOAK, CLOAK_OF_DISPLACEMENT); + short helm = !rn2(8) ? STRANGE_OBJECT : rnd_class(ELVEN_LEATHER_HELM, + HELM_OF_TELEPATHY); + short shield = !rn2(8) + ? STRANGE_OBJECT + : rnd_class(ELVEN_SHIELD, SHIELD_OF_REFLECTION); + int quan; + struct obj *otmp; - mtmp->m_lev = (special ? rn1(16,15) : rnd(16)); - mtmp->mhp = mtmp->mhpmax = d((int)mtmp->m_lev,10) + - (special ? (30 + rnd(30)) : 30); - if(special) { - get_mplname(mtmp, nam); - mtmp = christen_monst(mtmp, nam); - /* that's why they are "stuck" in the endgame :-) */ - (void)mongets(mtmp, FAKE_AMULET_OF_YENDOR); - } - mtmp->mpeaceful = 0; - set_malign(mtmp); /* peaceful may have changed again */ + mtmp->m_lev = (special ? rn1(16, 15) : rnd(16)); + mtmp->mhp = mtmp->mhpmax = + d((int) mtmp->m_lev, 10) + (special ? (30 + rnd(30)) : 30); + if (special) { + get_mplname(mtmp, nam); + mtmp = christen_monst(mtmp, nam); + /* that's why they are "stuck" in the endgame :-) */ + (void) mongets(mtmp, FAKE_AMULET_OF_YENDOR); + } + mtmp->mpeaceful = 0; + set_malign(mtmp); /* peaceful may have changed again */ - switch(monsndx(ptr)) { - case PM_ARCHEOLOGIST: - if (rn2(2)) weapon = BULLWHIP; - break; - case PM_BARBARIAN: - if (rn2(2)) { - weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE; - shield = STRANGE_OBJECT; - } - if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); - if (helm == HELM_OF_BRILLIANCE) helm = STRANGE_OBJECT; - break; - case PM_CAVEMAN: - case PM_CAVEWOMAN: - if (rn2(4)) weapon = MACE; - else if (rn2(2)) weapon = CLUB; - if (helm == HELM_OF_BRILLIANCE) helm = STRANGE_OBJECT; - break; - case PM_HEALER: - if (rn2(4)) weapon = QUARTERSTAFF; - else if (rn2(2)) weapon = rn2(2) ? UNICORN_HORN : SCALPEL; - if (rn2(4)) helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY; - if (rn2(2)) shield = STRANGE_OBJECT; - break; - case PM_KNIGHT: - if (rn2(4)) weapon = LONG_SWORD; - if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); - break; - case PM_MONK: - weapon = !rn2(3) ? SHURIKEN : STRANGE_OBJECT; - armor = STRANGE_OBJECT; - cloak = ROBE; - if (rn2(2)) shield = STRANGE_OBJECT; - break; - case PM_PRIEST: - case PM_PRIESTESS: - if (rn2(2)) weapon = MACE; - if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); - if (rn2(4)) cloak = ROBE; - if (rn2(4)) helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY; - if (rn2(2)) shield = STRANGE_OBJECT; - break; - case PM_RANGER: - if (rn2(2)) weapon = ELVEN_DAGGER; - break; - case PM_ROGUE: - if (rn2(2)) weapon = rn2(2) ? SHORT_SWORD : ORCISH_DAGGER; - break; - case PM_SAMURAI: - if (rn2(2)) weapon = KATANA; - break; - case PM_TOURIST: - /* Defaults are just fine */ - break; - case PM_VALKYRIE: - if (rn2(2)) weapon = WAR_HAMMER; - if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); - break; - case PM_WIZARD: - if (rn2(4)) weapon = rn2(2) ? QUARTERSTAFF : ATHAME; - if (rn2(2)) { - armor = rn2(2) ? BLACK_DRAGON_SCALE_MAIL : - SILVER_DRAGON_SCALE_MAIL; - cloak = CLOAK_OF_MAGIC_RESISTANCE; - } - if (rn2(4)) helm = HELM_OF_BRILLIANCE; - shield = STRANGE_OBJECT; - break; - default: impossible("bad mplayer monster"); - weapon = 0; - break; - } + switch (monsndx(ptr)) { + case PM_ARCHEOLOGIST: + if (rn2(2)) + weapon = BULLWHIP; + break; + case PM_BARBARIAN: + if (rn2(2)) { + weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE; + shield = STRANGE_OBJECT; + } + if (rn2(2)) + armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); + if (helm == HELM_OF_BRILLIANCE) + helm = STRANGE_OBJECT; + break; + case PM_CAVEMAN: + case PM_CAVEWOMAN: + if (rn2(4)) + weapon = MACE; + else if (rn2(2)) + weapon = CLUB; + if (helm == HELM_OF_BRILLIANCE) + helm = STRANGE_OBJECT; + break; + case PM_HEALER: + if (rn2(4)) + weapon = QUARTERSTAFF; + else if (rn2(2)) + weapon = rn2(2) ? UNICORN_HORN : SCALPEL; + if (rn2(4)) + helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY; + if (rn2(2)) + shield = STRANGE_OBJECT; + break; + case PM_KNIGHT: + if (rn2(4)) + weapon = LONG_SWORD; + if (rn2(2)) + armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); + break; + case PM_MONK: + weapon = !rn2(3) ? SHURIKEN : STRANGE_OBJECT; + armor = STRANGE_OBJECT; + cloak = ROBE; + if (rn2(2)) + shield = STRANGE_OBJECT; + break; + case PM_PRIEST: + case PM_PRIESTESS: + if (rn2(2)) + weapon = MACE; + if (rn2(2)) + armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); + if (rn2(4)) + cloak = ROBE; + if (rn2(4)) + helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY; + if (rn2(2)) + shield = STRANGE_OBJECT; + break; + case PM_RANGER: + if (rn2(2)) + weapon = ELVEN_DAGGER; + break; + case PM_ROGUE: + if (rn2(2)) + weapon = rn2(2) ? SHORT_SWORD : ORCISH_DAGGER; + break; + case PM_SAMURAI: + if (rn2(2)) + weapon = KATANA; + break; + case PM_TOURIST: + /* Defaults are just fine */ + break; + case PM_VALKYRIE: + if (rn2(2)) + weapon = WAR_HAMMER; + if (rn2(2)) + armor = rnd_class(PLATE_MAIL, CHAIN_MAIL); + break; + case PM_WIZARD: + if (rn2(4)) + weapon = rn2(2) ? QUARTERSTAFF : ATHAME; + if (rn2(2)) { + armor = rn2(2) ? BLACK_DRAGON_SCALE_MAIL + : SILVER_DRAGON_SCALE_MAIL; + cloak = CLOAK_OF_MAGIC_RESISTANCE; + } + if (rn2(4)) + helm = HELM_OF_BRILLIANCE; + shield = STRANGE_OBJECT; + break; + default: + impossible("bad mplayer monster"); + weapon = 0; + break; + } - if (weapon != STRANGE_OBJECT) { - otmp = mksobj(weapon, TRUE, FALSE); - otmp->spe = (special ? rn1(5,4) : rn2(4)); - if (!rn2(3)) otmp->oerodeproof = 1; - else if (!rn2(2)) otmp->greased = 1; - if (special && rn2(2)) - otmp = mk_artifact(otmp, A_NONE); - /* usually increase stack size if stackable weapon */ - if (objects[otmp->otyp].oc_merge && !otmp->oartifact) - otmp->quan += (long) rn2(is_spear(otmp) ? 4 : 8); - /* mplayers knew better than to overenchant Magicbane */ - if (otmp->oartifact == ART_MAGICBANE) - otmp->spe = rnd(4); - (void) mpickobj(mtmp, otmp); - } + if (weapon != STRANGE_OBJECT) { + otmp = mksobj(weapon, TRUE, FALSE); + otmp->spe = (special ? rn1(5, 4) : rn2(4)); + if (!rn2(3)) + otmp->oerodeproof = 1; + else if (!rn2(2)) + otmp->greased = 1; + if (special && rn2(2)) + otmp = mk_artifact(otmp, A_NONE); + /* usually increase stack size if stackable weapon */ + if (objects[otmp->otyp].oc_merge && !otmp->oartifact) + otmp->quan += (long) rn2(is_spear(otmp) ? 4 : 8); + /* mplayers knew better than to overenchant Magicbane */ + if (otmp->oartifact == ART_MAGICBANE) + otmp->spe = rnd(4); + (void) mpickobj(mtmp, otmp); + } - if(special) { - if (!rn2(10)) - (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE); - mk_mplayer_armor(mtmp, armor); - mk_mplayer_armor(mtmp, cloak); - mk_mplayer_armor(mtmp, helm); - mk_mplayer_armor(mtmp, shield); - if (rn2(8)) - mk_mplayer_armor(mtmp, rnd_class(LEATHER_GLOVES, - GAUNTLETS_OF_DEXTERITY)); - if (rn2(8)) - mk_mplayer_armor(mtmp, rnd_class(LOW_BOOTS, LEVITATION_BOOTS)); - m_dowear(mtmp, TRUE); + if (special) { + if (!rn2(10)) + (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE); + mk_mplayer_armor(mtmp, armor); + mk_mplayer_armor(mtmp, cloak); + mk_mplayer_armor(mtmp, helm); + mk_mplayer_armor(mtmp, shield); + if (rn2(8)) + mk_mplayer_armor( + mtmp, rnd_class(LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY)); + if (rn2(8)) + mk_mplayer_armor(mtmp, + rnd_class(LOW_BOOTS, LEVITATION_BOOTS)); + m_dowear(mtmp, TRUE); - quan = rn2(3) ? rn2(3) : rn2(16); - while(quan--) - (void)mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE)); - /* To get the gold "right" would mean a player can double his */ - /* gold supply by killing one mplayer. Not good. */ - mkmonmoney(mtmp, rn2(1000)); - quan = rn2(10); - while(quan--) - (void) mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE)); - } - quan = rnd(3); - while(quan--) - (void)mongets(mtmp, rnd_offensive_item(mtmp)); - quan = rnd(3); - while(quan--) - (void)mongets(mtmp, rnd_defensive_item(mtmp)); - quan = rnd(3); - while(quan--) - (void)mongets(mtmp, rnd_misc_item(mtmp)); - } + quan = rn2(3) ? rn2(3) : rn2(16); + while (quan--) + (void) mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE)); + /* To get the gold "right" would mean a player can double his */ + /* gold supply by killing one mplayer. Not good. */ + mkmonmoney(mtmp, rn2(1000)); + quan = rn2(10); + while (quan--) + (void) mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE)); + } + quan = rnd(3); + while (quan--) + (void) mongets(mtmp, rnd_offensive_item(mtmp)); + quan = rnd(3); + while (quan--) + (void) mongets(mtmp, rnd_defensive_item(mtmp)); + quan = rnd(3); + while (quan--) + (void) mongets(mtmp, rnd_misc_item(mtmp)); + } - return(mtmp); + return (mtmp); } /* create the indicated number (num) of monster-players, @@ -291,50 +330,52 @@ create_mplayers(num, special) register int num; boolean special; { - int pm, x, y; - struct monst fakemon; + int pm, x, y; + struct monst fakemon; - while(num) { - int tryct = 0; + while (num) { + int tryct = 0; - /* roll for character class */ - pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1); - fakemon.data = &mons[pm]; + /* roll for character class */ + pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1); + fakemon.data = &mons[pm]; - /* roll for an available location */ - do { - x = rn1(COLNO-4, 2); - y = rnd(ROWNO-2); - } while(!goodpos(x, y, &fakemon, 0) && tryct++ <= 50); + /* roll for an available location */ + do { + x = rn1(COLNO - 4, 2); + y = rnd(ROWNO - 2); + } while (!goodpos(x, y, &fakemon, 0) && tryct++ <= 50); - /* if pos not found in 50 tries, don't bother to continue */ - if(tryct > 50) return; + /* if pos not found in 50 tries, don't bother to continue */ + if (tryct > 50) + return; - (void) mk_mplayer(&mons[pm], (xchar)x, (xchar)y, special); - num--; - } + (void) mk_mplayer(&mons[pm], (xchar) x, (xchar) y, special); + num--; + } } void mplayer_talk(mtmp) register struct monst *mtmp; { - static const char *same_class_msg[3] = { - "I can't win, and neither will you!", - "You don't deserve to win!", - "Mine should be the honor, not yours!", - }, *other_class_msg[3] = { - "The low-life wants to talk, eh?", - "Fight, scum!", - "Here is what I have to say!", - }; + static const char *same_class_msg[3] = + { + "I can't win, and neither will you!", "You don't deserve to win!", + "Mine should be the honor, not yours!", + }, + *other_class_msg[3] = { + "The low-life wants to talk, eh?", "Fight, scum!", + "Here is what I have to say!", + }; - if(mtmp->mpeaceful) return; /* will drop to humanoid talk */ + if (mtmp->mpeaceful) + return; /* will drop to humanoid talk */ - pline("Talk? -- %s", - (mtmp->data == &mons[urole.malenum] || - mtmp->data == &mons[urole.femalenum]) ? - same_class_msg[rn2(3)] : other_class_msg[rn2(3)]); + pline("Talk? -- %s", (mtmp->data == &mons[urole.malenum] + || mtmp->data == &mons[urole.femalenum]) + ? same_class_msg[rn2(3)] + : other_class_msg[rn2(3)]); } /*mplayer.c*/ diff --git a/src/mthrowu.c b/src/mthrowu.c index cbaa9a112..5105b33fe 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -1,86 +1,86 @@ -/* NetHack 3.6 mthrowu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mthrowu.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.54 $ */ /* NetHack 3.6 mthrowu.c $Date: 2011/12/30 23:47:06 $ $Revision: 1.43 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -STATIC_DCL int FDECL(drop_throw,(struct obj *,BOOLEAN_P,int,int)); +STATIC_DCL int FDECL(drop_throw, (struct obj *, BOOLEAN_P, int, int)); -#define URETREATING(x,y) (distmin(u.ux,u.uy,x,y) > distmin(u.ux0,u.uy0,x,y)) +#define URETREATING(x, y) \ + (distmin(u.ux, u.uy, x, y) > distmin(u.ux0, u.uy0, x, y)) -#define POLE_LIM 5 /* How far monsters can use pole-weapons */ +#define POLE_LIM 5 /* How far monsters can use pole-weapons */ /* * Keep consistent with breath weapons in zap.c, and AD_* in monattk.h. */ STATIC_OVL NEARDATA const char *breathwep[] = { - "fragments", - "fire", - "frost", - "sleep gas", - "a disintegration blast", - "lightning", - "poison gas", - "acid", - "strange breath #8", - "strange breath #9" + "fragments", "fire", "frost", "sleep gas", "a disintegration blast", + "lightning", "poison gas", "acid", "strange breath #8", + "strange breath #9" }; -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ /* hero is hit by something other than a monster */ int thitu(tlev, dam, obj, name) int tlev, dam; struct obj *obj; -const char *name; /* if null, then format `obj' */ +const char *name; /* if null, then format `obj' */ { - const char *onm, *knm; - boolean is_acid; - int kprefix = KILLED_BY_AN; - char onmbuf[BUFSZ], knmbuf[BUFSZ]; + const char *onm, *knm; + boolean is_acid; + int kprefix = KILLED_BY_AN; + char onmbuf[BUFSZ], knmbuf[BUFSZ]; - if (!name) { - if (!obj) panic("thitu: name & obj both null?"); - name = strcpy(onmbuf, - (obj->quan > 1L) ? doname(obj) : mshot_xname(obj)); - knm = strcpy(knmbuf, killer_xname(obj)); - kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */ - } else { - knm = name; - /* [perhaps ought to check for plural here to] */ - if (!strncmpi(name, "the ", 4) || - !strncmpi(name, "an ", 3) || - !strncmpi(name, "a ", 2)) kprefix = KILLED_BY; - } - onm = (obj && obj_is_pname(obj)) ? the(name) : - (obj && obj->quan > 1L) ? name : an(name); - is_acid = (obj && obj->otyp == ACID_VENOM); + if (!name) { + if (!obj) + panic("thitu: name & obj both null?"); + name = + strcpy(onmbuf, (obj->quan > 1L) ? doname(obj) : mshot_xname(obj)); + knm = strcpy(knmbuf, killer_xname(obj)); + kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */ + } else { + knm = name; + /* [perhaps ought to check for plural here to] */ + if (!strncmpi(name, "the ", 4) || !strncmpi(name, "an ", 3) + || !strncmpi(name, "a ", 2)) + kprefix = KILLED_BY; + } + onm = (obj && obj_is_pname(obj)) ? the(name) : (obj && obj->quan > 1L) + ? name + : an(name); + is_acid = (obj && obj->otyp == ACID_VENOM); - if(u.uac + tlev <= rnd(20)) { - if(Blind || !flags.verbose) pline("It misses."); - else You("are almost hit by %s.", onm); - return(0); - } else { - if (Blind || !flags.verbose) You("are hit%s", exclam(dam)); - else You("are hit by %s%s", onm, exclam(dam)); + if (u.uac + tlev <= rnd(20)) { + if (Blind || !flags.verbose) + pline("It misses."); + else + You("are almost hit by %s.", onm); + return (0); + } else { + if (Blind || !flags.verbose) + You("are hit%s", exclam(dam)); + else + You("are hit by %s%s", onm, exclam(dam)); - if (obj && objects[obj->otyp].oc_material == SILVER && - Hate_silver) { - /* extra damage already applied by dmgval() */ - pline_The("silver sears your flesh!"); - exercise(A_CON, FALSE); - } - if (is_acid && Acid_resistance) - pline("It doesn't seem to hurt you."); - else { - if (is_acid) pline("It burns!"); - losehp(dam, knm, kprefix); /* acid damage */ - exercise(A_STR, FALSE); - } - return(1); - } + if (obj && objects[obj->otyp].oc_material == SILVER && Hate_silver) { + /* extra damage already applied by dmgval() */ + pline_The("silver sears your flesh!"); + exercise(A_CON, FALSE); + } + if (is_acid && Acid_resistance) + pline("It doesn't seem to hurt you."); + else { + if (is_acid) + pline("It burns!"); + losehp(dam, knm, kprefix); /* acid damage */ + exercise(A_STR, FALSE); + } + return (1); + } } /* Be sure this corresponds with what happens to player-thrown objects in @@ -92,364 +92,393 @@ STATIC_OVL int drop_throw(obj, ohit, x, y) register struct obj *obj; boolean ohit; -int x,y; +int x, y; { - int retvalu = 1; - int create; - struct monst *mtmp; - struct trap *t; + int retvalu = 1; + int create; + struct monst *mtmp; + struct trap *t; - if (obj->otyp == CREAM_PIE || obj->oclass == VENOM_CLASS || - (ohit && obj->otyp == EGG)) - create = 0; - else if (ohit && (is_multigen(obj) || obj->otyp == ROCK)) - create = !rn2(3); - else create = 1; + if (obj->otyp == CREAM_PIE || obj->oclass == VENOM_CLASS + || (ohit && obj->otyp == EGG)) + create = 0; + else if (ohit && (is_multigen(obj) || obj->otyp == ROCK)) + create = !rn2(3); + else + create = 1; - if (create && !((mtmp = m_at(x, y)) && (mtmp->mtrapped) && - (t = t_at(x, y)) && ((t->ttyp == PIT) || - (t->ttyp == SPIKED_PIT)))) { - int objgone = 0; + if (create + && !((mtmp = m_at(x, y)) && (mtmp->mtrapped) && (t = t_at(x, y)) + && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT)))) { + int objgone = 0; - if (down_gate(x, y) != -1) - objgone = ship_object(obj, x, y, FALSE); - if (!objgone) { - if (!flooreffects(obj,x,y,"fall")) { /* don't double-dip on damage */ - place_object(obj, x, y); - if (!mtmp && x == u.ux && y == u.uy) - mtmp = &youmonst; - if (mtmp && ohit) - passive_obj(mtmp, obj, (struct attack *)0); - stackobj(obj); - retvalu = 0; - } - } - } else obfree(obj, (struct obj*) 0); - return retvalu; + if (down_gate(x, y) != -1) + objgone = ship_object(obj, x, y, FALSE); + if (!objgone) { + if (!flooreffects(obj, x, y, + "fall")) { /* don't double-dip on damage */ + place_object(obj, x, y); + if (!mtmp && x == u.ux && y == u.uy) + mtmp = &youmonst; + if (mtmp && ohit) + passive_obj(mtmp, obj, (struct attack *) 0); + stackobj(obj); + retvalu = 0; + } + } + } else + obfree(obj, (struct obj *) 0); + return retvalu; } /* an object launched by someone/thing other than player attacks a monster; return 1 if the object has stopped moving (hit or its range used up) */ int ohitmon(mtmp, otmp, range, verbose) -struct monst *mtmp; /* accidental target, located at */ -struct obj *otmp; /* missile; might be destroyed by drop_throw */ -int range; /* how much farther will object travel if it misses */ - /* Use -1 to signify to keep going even after hit, */ - /* unless its gone (used for rolling_boulder_traps) */ -boolean verbose; /* give message(s) even when you can't see what happened */ +struct monst *mtmp; /* accidental target, located at */ +struct obj *otmp; /* missile; might be destroyed by drop_throw */ +int range; /* how much farther will object travel if it misses */ + /* Use -1 to signify to keep going even after hit, */ + /* unless its gone (used for rolling_boulder_traps) */ +boolean verbose; /* give message(s) even when you can't see what happened */ { - int damage, tmp; - boolean vis, ismimic; - int objgone = 1; + int damage, tmp; + boolean vis, ismimic; + int objgone = 1; - notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); - ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER; - vis = cansee(bhitpos.x, bhitpos.y); + notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER; + vis = cansee(bhitpos.x, bhitpos.y); - tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE); - if (tmp < rnd(20)) { - if (!ismimic) { - if (vis) miss(distant_name(otmp, mshot_xname), mtmp); - else if (verbose) pline("It is missed."); - } - if (!range) { /* Last position; object drops */ - (void) drop_throw(otmp, 0, mtmp->mx, mtmp->my); - return 1; - } - } else if (otmp->oclass == POTION_CLASS) { - if (ismimic) seemimic(mtmp); - mtmp->msleeping = 0; - if (vis) otmp->dknown = 1; - potionhit(mtmp, otmp, FALSE); - return 1; - } else { - damage = dmgval(otmp, mtmp); - if (otmp->otyp == ACID_VENOM && resists_acid(mtmp)) - damage = 0; - if (ismimic) seemimic(mtmp); - mtmp->msleeping = 0; - if (vis) hit(distant_name(otmp,mshot_xname), mtmp, exclam(damage)); - else if (verbose) pline("%s is hit%s", Monnam(mtmp), exclam(damage)); + tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE); + if (tmp < rnd(20)) { + if (!ismimic) { + if (vis) + miss(distant_name(otmp, mshot_xname), mtmp); + else if (verbose) + pline("It is missed."); + } + if (!range) { /* Last position; object drops */ + (void) drop_throw(otmp, 0, mtmp->mx, mtmp->my); + return 1; + } + } else if (otmp->oclass == POTION_CLASS) { + if (ismimic) + seemimic(mtmp); + mtmp->msleeping = 0; + if (vis) + otmp->dknown = 1; + potionhit(mtmp, otmp, FALSE); + return 1; + } else { + damage = dmgval(otmp, mtmp); + if (otmp->otyp == ACID_VENOM && resists_acid(mtmp)) + damage = 0; + if (ismimic) + seemimic(mtmp); + mtmp->msleeping = 0; + if (vis) + hit(distant_name(otmp, mshot_xname), mtmp, exclam(damage)); + else if (verbose) + pline("%s is hit%s", Monnam(mtmp), exclam(damage)); - if (otmp->opoisoned && is_poisonable(otmp)) { - if (resists_poison(mtmp)) { - if (vis) pline_The("poison doesn't seem to affect %s.", - mon_nam(mtmp)); - } else { - if (rn2(30)) { - damage += rnd(6); - } else { - if (vis) pline_The("poison was deadly..."); - damage = mtmp->mhp; - } - } - } - if (objects[otmp->otyp].oc_material == SILVER && - mon_hates_silver(mtmp)) { - if (vis) pline_The("silver sears %s flesh!", - s_suffix(mon_nam(mtmp))); - else if (verbose) pline("Its flesh is seared!"); - } - if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx,mtmp->my)) { - if (resists_acid(mtmp)) { - if (vis || verbose) - pline("%s is unaffected.", Monnam(mtmp)); - damage = 0; - } else { - if (vis) pline_The("acid burns %s!", mon_nam(mtmp)); - else if (verbose) pline("It is burned!"); - } - } - mtmp->mhp -= damage; - if (mtmp->mhp < 1) { - if (vis || verbose) - pline("%s is %s!", Monnam(mtmp), - (nonliving(mtmp->data) || - is_vampshifter(mtmp) || !canspotmon(mtmp)) - ? "destroyed" : "killed"); - /* don't blame hero for unknown rolling boulder trap */ - if (!context.mon_moving && - (otmp->otyp != BOULDER || range >= 0 || otmp->otrapped)) - xkilled(mtmp,0); - else mondied(mtmp); - } + if (otmp->opoisoned && is_poisonable(otmp)) { + if (resists_poison(mtmp)) { + if (vis) + pline_The("poison doesn't seem to affect %s.", + mon_nam(mtmp)); + } else { + if (rn2(30)) { + damage += rnd(6); + } else { + if (vis) + pline_The("poison was deadly..."); + damage = mtmp->mhp; + } + } + } + if (objects[otmp->otyp].oc_material == SILVER + && mon_hates_silver(mtmp)) { + if (vis) + pline_The("silver sears %s flesh!", s_suffix(mon_nam(mtmp))); + else if (verbose) + pline("Its flesh is seared!"); + } + if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx, mtmp->my)) { + if (resists_acid(mtmp)) { + if (vis || verbose) + pline("%s is unaffected.", Monnam(mtmp)); + damage = 0; + } else { + if (vis) + pline_The("acid burns %s!", mon_nam(mtmp)); + else if (verbose) + pline("It is burned!"); + } + } + mtmp->mhp -= damage; + if (mtmp->mhp < 1) { + if (vis || verbose) + pline("%s is %s!", Monnam(mtmp), + (nonliving(mtmp->data) || is_vampshifter(mtmp) + || !canspotmon(mtmp)) + ? "destroyed" + : "killed"); + /* don't blame hero for unknown rolling boulder trap */ + if (!context.mon_moving + && (otmp->otyp != BOULDER || range >= 0 || otmp->otrapped)) + xkilled(mtmp, 0); + else + mondied(mtmp); + } - if (can_blnd((struct monst*)0, mtmp, - (uchar)(otmp->otyp == BLINDING_VENOM ? AT_SPIT : AT_WEAP), - otmp)) { - if (vis && mtmp->mcansee) - pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp))); - mtmp->mcansee = 0; - tmp = (int)mtmp->mblinded + rnd(25) + 20; - if (tmp > 127) tmp = 127; - mtmp->mblinded = tmp; - } + if (can_blnd( + (struct monst *) 0, mtmp, + (uchar)(otmp->otyp == BLINDING_VENOM ? AT_SPIT : AT_WEAP), + otmp)) { + if (vis && mtmp->mcansee) + pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp))); + mtmp->mcansee = 0; + tmp = (int) mtmp->mblinded + rnd(25) + 20; + if (tmp > 127) + tmp = 127; + mtmp->mblinded = tmp; + } - objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y); - if (!objgone && range == -1) { /* special case */ - obj_extract_self(otmp); /* free it for motion again */ - return 0; - } - return 1; - } - return 0; + objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y); + if (!objgone && range == -1) { /* special case */ + obj_extract_self(otmp); /* free it for motion again */ + return 0; + } + return 1; + } + return 0; } void m_throw(mon, x, y, dx, dy, range, obj) -struct monst *mon; /* launching monster */ -int x, y, dx, dy, range; /* launch point, direction, and range */ -struct obj *obj; /* missile (or stack providing it) */ +struct monst *mon; /* launching monster */ +int x, y, dx, dy, range; /* launch point, direction, and range */ +struct obj *obj; /* missile (or stack providing it) */ { - struct monst *mtmp; - struct obj *singleobj; - char sym = obj->oclass; - int hitu, oldumort, blindinc = 0; + struct monst *mtmp; + struct obj *singleobj; + char sym = obj->oclass; + int hitu, oldumort, blindinc = 0; - bhitpos.x = x; - bhitpos.y = y; - notonhead = FALSE; /* reset potentially stale value */ + bhitpos.x = x; + bhitpos.y = y; + notonhead = FALSE; /* reset potentially stale value */ - if (obj->quan == 1L) { - /* - * Remove object from minvent. This cannot be done later on; - * what if the player dies before then, leaving the monster - * with 0 daggers? (This caused the infamous 2^32-1 orcish - * dagger bug). - * - * VENOM is not in minvent - it should already be OBJ_FREE. - * The extract below does nothing. - */ + if (obj->quan == 1L) { + /* + * Remove object from minvent. This cannot be done later on; + * what if the player dies before then, leaving the monster + * with 0 daggers? (This caused the infamous 2^32-1 orcish + * dagger bug). + * + * VENOM is not in minvent - it should already be OBJ_FREE. + * The extract below does nothing. + */ - /* not possibly_unwield, which checks the object's */ - /* location, not its existence */ - if (MON_WEP(mon) == obj) { - setmnotwielded(mon,obj); - MON_NOWEP(mon); - } - obj_extract_self(obj); - singleobj = obj; - obj = (struct obj *) 0; - } else { - singleobj = splitobj(obj, 1L); - obj_extract_self(singleobj); - } + /* not possibly_unwield, which checks the object's */ + /* location, not its existence */ + if (MON_WEP(mon) == obj) { + setmnotwielded(mon, obj); + MON_NOWEP(mon); + } + obj_extract_self(obj); + singleobj = obj; + obj = (struct obj *) 0; + } else { + singleobj = splitobj(obj, 1L); + obj_extract_self(singleobj); + } - singleobj->owornmask = 0; /* threw one of multiple weapons in hand? */ + singleobj->owornmask = 0; /* threw one of multiple weapons in hand? */ - if ((singleobj->cursed || singleobj->greased) && (dx || dy) && - !rn2(7)) { - if(canseemon(mon) && flags.verbose) { - if(is_ammo(singleobj)) - pline("%s misfires!", Monnam(mon)); - else - pline("%s as %s throws it!", - Tobjnam(singleobj, "slip"), mon_nam(mon)); - } - dx = rn2(3)-1; - dy = rn2(3)-1; - /* check validity of new direction */ - if (!dx && !dy) { - (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); - return; - } - } + if ((singleobj->cursed || singleobj->greased) && (dx || dy) && !rn2(7)) { + if (canseemon(mon) && flags.verbose) { + if (is_ammo(singleobj)) + pline("%s misfires!", Monnam(mon)); + else + pline("%s as %s throws it!", Tobjnam(singleobj, "slip"), + mon_nam(mon)); + } + dx = rn2(3) - 1; + dy = rn2(3) - 1; + /* check validity of new direction */ + if (!dx && !dy) { + (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); + return; + } + } - /* pre-check for doors, walls and boundaries. - Also need to pre-check for bars regardless of direction; - the random chance for small objects hitting bars is - skipped when reaching them at point blank range */ - if (!isok(bhitpos.x+dx,bhitpos.y+dy) - || IS_ROCK(levl[bhitpos.x+dx][bhitpos.y+dy].typ) - || closed_door(bhitpos.x+dx, bhitpos.y+dy) - || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS && - hits_bars(&singleobj, bhitpos.x, bhitpos.y, 0, 0))) { - (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); - return; - } + /* pre-check for doors, walls and boundaries. + Also need to pre-check for bars regardless of direction; + the random chance for small objects hitting bars is + skipped when reaching them at point blank range */ + if (!isok(bhitpos.x + dx, bhitpos.y + dy) + || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ) + || closed_door(bhitpos.x + dx, bhitpos.y + dy) + || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS + && hits_bars(&singleobj, bhitpos.x, bhitpos.y, 0, 0))) { + (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); + return; + } - /* Note: drop_throw may destroy singleobj. Since obj must be destroyed - * early to avoid the dagger bug, anyone who modifies this code should - * be careful not to use either one after it's been freed. - */ - if (sym) tmp_at(DISP_FLASH, obj_to_glyph(singleobj)); - while(range-- > 0) { /* Actually the loop is always exited by break */ - bhitpos.x += dx; - bhitpos.y += dy; - if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { - if (ohitmon(mtmp, singleobj, range, TRUE)) - break; - } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { - if (multi) nomul(0); + /* Note: drop_throw may destroy singleobj. Since obj must be destroyed + * early to avoid the dagger bug, anyone who modifies this code should + * be careful not to use either one after it's been freed. + */ + if (sym) + tmp_at(DISP_FLASH, obj_to_glyph(singleobj)); + while (range-- > 0) { /* Actually the loop is always exited by break */ + bhitpos.x += dx; + bhitpos.y += dy; + if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { + if (ohitmon(mtmp, singleobj, range, TRUE)) + break; + } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { + if (multi) + nomul(0); - if (singleobj->oclass == GEM_CLASS && - singleobj->otyp <= LAST_GEM+9 /* 9 glass colors */ - && is_unicorn(youmonst.data)) { - if (singleobj->otyp > LAST_GEM) { - You("catch the %s.", xname(singleobj)); - You("are not interested in %s junk.", - s_suffix(mon_nam(mon))); - makeknown(singleobj->otyp); - dropy(singleobj); - } else { - You("accept %s gift in the spirit in which it was intended.", - s_suffix(mon_nam(mon))); - (void)hold_another_object(singleobj, - "You catch, but drop, %s.", xname(singleobj), - "You catch:"); - } - break; - } - if (singleobj->oclass == POTION_CLASS) { - if (!Blind) singleobj->dknown = 1; - potionhit(&youmonst, singleobj, FALSE); - break; - } - oldumort = u.umortality; - switch(singleobj->otyp) { - int dam, hitv; - case EGG: - if (!touch_petrifies(&mons[singleobj->corpsenm])) { - impossible("monster throwing egg type %d", - singleobj->corpsenm); - hitu = 0; - break; - } - /* fall through */ - case CREAM_PIE: - case BLINDING_VENOM: - hitu = thitu(8, 0, singleobj, (char *)0); - break; - default: - dam = dmgval(singleobj, &youmonst); - hitv = 3 - distmin(u.ux,u.uy, mon->mx,mon->my); - if (hitv < -4) hitv = -4; - if (is_elf(mon->data) && - objects[singleobj->otyp].oc_skill == P_BOW) { - hitv++; - if (MON_WEP(mon) && - MON_WEP(mon)->otyp == ELVEN_BOW) - hitv++; - if(singleobj->otyp == ELVEN_ARROW) dam++; - } - if (bigmonst(youmonst.data)) hitv++; - hitv += 8 + singleobj->spe; - if (dam < 1) dam = 1; - hitu = thitu(hitv, dam, singleobj, (char *)0); - } - if (hitu && singleobj->opoisoned && - is_poisonable(singleobj)) { - char onmbuf[BUFSZ], knmbuf[BUFSZ]; + if (singleobj->oclass == GEM_CLASS + && singleobj->otyp <= LAST_GEM + 9 /* 9 glass colors */ + && is_unicorn(youmonst.data)) { + if (singleobj->otyp > LAST_GEM) { + You("catch the %s.", xname(singleobj)); + You("are not interested in %s junk.", + s_suffix(mon_nam(mon))); + makeknown(singleobj->otyp); + dropy(singleobj); + } else { + You("accept %s gift in the spirit in which it was " + "intended.", + s_suffix(mon_nam(mon))); + (void) hold_another_object( + singleobj, "You catch, but drop, %s.", + xname(singleobj), "You catch:"); + } + break; + } + if (singleobj->oclass == POTION_CLASS) { + if (!Blind) + singleobj->dknown = 1; + potionhit(&youmonst, singleobj, FALSE); + break; + } + oldumort = u.umortality; + switch (singleobj->otyp) { + int dam, hitv; + case EGG: + if (!touch_petrifies(&mons[singleobj->corpsenm])) { + impossible("monster throwing egg type %d", + singleobj->corpsenm); + hitu = 0; + break; + } + /* fall through */ + case CREAM_PIE: + case BLINDING_VENOM: + hitu = thitu(8, 0, singleobj, (char *) 0); + break; + default: + dam = dmgval(singleobj, &youmonst); + hitv = 3 - distmin(u.ux, u.uy, mon->mx, mon->my); + if (hitv < -4) + hitv = -4; + if (is_elf(mon->data) + && objects[singleobj->otyp].oc_skill == P_BOW) { + hitv++; + if (MON_WEP(mon) && MON_WEP(mon)->otyp == ELVEN_BOW) + hitv++; + if (singleobj->otyp == ELVEN_ARROW) + dam++; + } + if (bigmonst(youmonst.data)) + hitv++; + hitv += 8 + singleobj->spe; + if (dam < 1) + dam = 1; + hitu = thitu(hitv, dam, singleobj, (char *) 0); + } + if (hitu && singleobj->opoisoned && is_poisonable(singleobj)) { + char onmbuf[BUFSZ], knmbuf[BUFSZ]; - Strcpy(onmbuf, xname(singleobj)); - Strcpy(knmbuf, killer_xname(singleobj)); - poisoned(onmbuf, A_STR, knmbuf, - /* if damage triggered life-saving, - poison is limited to attrib loss */ - (u.umortality > oldumort) ? 0 : 10, TRUE); - } - if(hitu && - can_blnd((struct monst*)0, &youmonst, - (uchar)(singleobj->otyp == BLINDING_VENOM ? - AT_SPIT : AT_WEAP), singleobj)) { - blindinc = rnd(25); - if(singleobj->otyp == CREAM_PIE) { - if(!Blind) pline("Yecch! You've been creamed."); - else pline("There's %s sticky all over your %s.", - something, - body_part(FACE)); - } else if(singleobj->otyp == BLINDING_VENOM) { - const char *eyes = body_part(EYE); + Strcpy(onmbuf, xname(singleobj)); + Strcpy(knmbuf, killer_xname(singleobj)); + poisoned(onmbuf, A_STR, knmbuf, + /* if damage triggered life-saving, + poison is limited to attrib loss */ + (u.umortality > oldumort) ? 0 : 10, TRUE); + } + if (hitu && can_blnd((struct monst *) 0, &youmonst, + (uchar)(singleobj->otyp == BLINDING_VENOM + ? AT_SPIT + : AT_WEAP), + singleobj)) { + blindinc = rnd(25); + if (singleobj->otyp == CREAM_PIE) { + if (!Blind) + pline("Yecch! You've been creamed."); + else + pline("There's %s sticky all over your %s.", + something, body_part(FACE)); + } else if (singleobj->otyp == BLINDING_VENOM) { + const char *eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) - eyes = makeplural(eyes); - /* venom in the eyes */ - if(!Blind) pline_The("venom blinds you."); - else Your("%s %s.", eyes, vtense(eyes, "sting")); - } - } - if (hitu && singleobj->otyp == EGG) { - if (!Stoned && !Stone_resistance - && !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - make_stoned(5L, (char *)0, KILLED_BY, ""); - } - } - stop_occupation(); - if (hitu || !range) { - (void) drop_throw(singleobj, hitu, u.ux, u.uy); - break; - } - } - if (!range /* reached end of path */ - /* missile hits edge of screen */ - || !isok(bhitpos.x+dx,bhitpos.y+dy) - /* missile hits the wall */ - || IS_ROCK(levl[bhitpos.x+dx][bhitpos.y+dy].typ) - /* missile hit closed door */ - || closed_door(bhitpos.x+dx, bhitpos.y+dy) - /* missile might hit iron bars */ - || (levl[bhitpos.x+dx][bhitpos.y+dy].typ == IRONBARS && - hits_bars(&singleobj, bhitpos.x, bhitpos.y, !rn2(5), 0)) - /* Thrown objects "sink" */ - || IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) { - if (singleobj) /* hits_bars might have destroyed it */ - (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); - break; - } - tmp_at(bhitpos.x, bhitpos.y); - delay_output(); - } - tmp_at(bhitpos.x, bhitpos.y); - delay_output(); - tmp_at(DISP_END, 0); + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + /* venom in the eyes */ + if (!Blind) + pline_The("venom blinds you."); + else + Your("%s %s.", eyes, vtense(eyes, "sting")); + } + } + if (hitu && singleobj->otyp == EGG) { + if (!Stoned && !Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + make_stoned(5L, (char *) 0, KILLED_BY, ""); + } + } + stop_occupation(); + if (hitu || !range) { + (void) drop_throw(singleobj, hitu, u.ux, u.uy); + break; + } + } + if (!range /* reached end of path */ + /* missile hits edge of screen */ + || !isok(bhitpos.x + dx, bhitpos.y + dy) + /* missile hits the wall */ + || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ) + /* missile hit closed door */ + || closed_door(bhitpos.x + dx, bhitpos.y + dy) + /* missile might hit iron bars */ + || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS + && hits_bars(&singleobj, bhitpos.x, bhitpos.y, !rn2(5), 0)) + /* Thrown objects "sink" */ + || IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) { + if (singleobj) /* hits_bars might have destroyed it */ + (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y); + break; + } + tmp_at(bhitpos.x, bhitpos.y); + delay_output(); + } + tmp_at(bhitpos.x, bhitpos.y); + delay_output(); + tmp_at(DISP_END, 0); - if (blindinc) { - u.ucreamed += blindinc; - make_blinded(Blinded + (long)blindinc, FALSE); - if (!Blind) Your1(vision_clears); - } + if (blindinc) { + u.ucreamed += blindinc; + make_blinded(Blinded + (long) blindinc, FALSE); + if (!Blind) + Your1(vision_clears); + } } /* remove an entire item from a monster's inventory; destroy that item */ @@ -458,14 +487,15 @@ m_useupall(mon, obj) struct monst *mon; struct obj *obj; { - obj_extract_self(obj); - if (obj->owornmask) { - if (obj == MON_WEP(mon)) mwepgone(mon); - mon->misc_worn_check &= ~obj->owornmask; - update_mon_intrinsics(mon, obj, FALSE, FALSE); - obj->owornmask = 0L; - } - obfree(obj, (struct obj*) 0); + obj_extract_self(obj); + if (obj->owornmask) { + if (obj == MON_WEP(mon)) + mwepgone(mon); + mon->misc_worn_check &= ~obj->owornmask; + update_mon_intrinsics(mon, obj, FALSE, FALSE); + obj->owornmask = 0L; + } + obfree(obj, (struct obj *) 0); } /* remove one instance of an item from a monster's inventory */ @@ -474,12 +504,12 @@ m_useup(mon, obj) struct monst *mon; struct obj *obj; { - if (obj->quan > 1L) { - obj->quan--; - obj->owt = weight(obj); - } else { - m_useupall(mon, obj); - } + if (obj->quan > 1L) { + obj->quan--; + obj->owt = weight(obj); + } else { + m_useupall(mon, obj); + } } /* monster attempts ranged weapon attack against player */ @@ -487,287 +517,296 @@ void thrwmu(mtmp) struct monst *mtmp; { - struct obj *otmp, *mwep; - xchar x, y; - int multishot; - const char *onm; + struct obj *otmp, *mwep; + xchar x, y; + int multishot; + const char *onm; - /* Rearranged beginning so monsters can use polearms not in a line */ - if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { - mtmp->weapon_check = NEED_RANGED_WEAPON; - /* mon_wield_item resets weapon_check as appropriate */ - if(mon_wield_item(mtmp) != 0) return; - } + /* Rearranged beginning so monsters can use polearms not in a line */ + if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) { + mtmp->weapon_check = NEED_RANGED_WEAPON; + /* mon_wield_item resets weapon_check as appropriate */ + if (mon_wield_item(mtmp) != 0) + return; + } - /* Pick a weapon */ - otmp = select_rwep(mtmp); - if (!otmp) return; + /* Pick a weapon */ + otmp = select_rwep(mtmp); + if (!otmp) + return; - if (is_pole(otmp)) { - int dam, hitv; + if (is_pole(otmp)) { + int dam, hitv; - if (otmp != MON_WEP(mtmp)) return; /* polearm must be wielded */ - if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM || - !couldsee(mtmp->mx, mtmp->my)) - return; /* Out of range, or intervening wall */ + if (otmp != MON_WEP(mtmp)) + return; /* polearm must be wielded */ + if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM + || !couldsee(mtmp->mx, mtmp->my)) + return; /* Out of range, or intervening wall */ - if (canseemon(mtmp)) { - onm = xname(otmp); - pline("%s thrusts %s.", Monnam(mtmp), - obj_is_pname(otmp) ? the(onm) : an(onm)); - } + if (canseemon(mtmp)) { + onm = xname(otmp); + pline("%s thrusts %s.", Monnam(mtmp), + obj_is_pname(otmp) ? the(onm) : an(onm)); + } - dam = dmgval(otmp, &youmonst); - hitv = 3 - distmin(u.ux,u.uy, mtmp->mx,mtmp->my); - if (hitv < -4) hitv = -4; - if (bigmonst(youmonst.data)) hitv++; - hitv += 8 + otmp->spe; - if (dam < 1) dam = 1; + dam = dmgval(otmp, &youmonst); + hitv = 3 - distmin(u.ux, u.uy, mtmp->mx, mtmp->my); + if (hitv < -4) + hitv = -4; + if (bigmonst(youmonst.data)) + hitv++; + hitv += 8 + otmp->spe; + if (dam < 1) + dam = 1; - (void) thitu(hitv, dam, otmp, (char *)0); - stop_occupation(); - return; - } + (void) thitu(hitv, dam, otmp, (char *) 0); + stop_occupation(); + return; + } - x = mtmp->mx; - y = mtmp->my; - /* If you are coming toward the monster, the monster - * should try to soften you up with missiles. If you are - * going away, you are probably hurt or running. Give - * chase, but if you are getting too far away, throw. - */ - if (!lined_up(mtmp) || - (URETREATING(x,y) && - rn2(BOLT_LIM - distmin(x,y,mtmp->mux,mtmp->muy)))) - return; + x = mtmp->mx; + y = mtmp->my; + /* If you are coming toward the monster, the monster + * should try to soften you up with missiles. If you are + * going away, you are probably hurt or running. Give + * chase, but if you are getting too far away, throw. + */ + if (!lined_up(mtmp) + || (URETREATING(x, y) + && rn2(BOLT_LIM - distmin(x, y, mtmp->mux, mtmp->muy)))) + return; - mwep = MON_WEP(mtmp); /* wielded weapon */ + mwep = MON_WEP(mtmp); /* wielded weapon */ - /* Multishot calculations */ - multishot = 1; - if (otmp->quan > 1L && /* no point checking if there's only 1 */ - /* ammo requires corresponding launcher be wielded */ - (is_ammo(otmp) ? matching_launcher(otmp, mwep) : - /* otherwise any stackable (non-ammo) weapon */ - otmp->oclass == WEAPON_CLASS) && - !mtmp->mconf) { - int skill = (int)objects[otmp->otyp].oc_skill; + /* Multishot calculations */ + multishot = 1; + if (otmp->quan > 1L && /* no point checking if there's only 1 */ + /* ammo requires corresponding launcher be wielded */ + (is_ammo(otmp) ? matching_launcher(otmp, mwep) : + /* otherwise any stackable (non-ammo) weapon */ + otmp->oclass == WEAPON_CLASS) && !mtmp->mconf) { + int skill = (int) objects[otmp->otyp].oc_skill; - /* Assumes lords are skilled, princes are expert */ - if (is_prince(mtmp->data)) multishot += 2; - else if (is_lord(mtmp->data)) multishot++; - /* fake players treated as skilled (regardless of role limits) */ - else if (is_mplayer(mtmp->data)) multishot++; + /* Assumes lords are skilled, princes are expert */ + if (is_prince(mtmp->data)) + multishot += 2; + else if (is_lord(mtmp->data)) + multishot++; + /* fake players treated as skilled (regardless of role limits) */ + else if (is_mplayer(mtmp->data)) + multishot++; - /* class bonus */ - switch (monsndx(mtmp->data)) { - case PM_MONK: - if (skill == -P_SHURIKEN) multishot++; - break; - case PM_RANGER: - multishot++; - break; - case PM_ROGUE: - if (skill == P_DAGGER) multishot++; - break; - case PM_NINJA: - if (skill == -P_SHURIKEN || skill == -P_DART) multishot++; - /*FALLTHRU*/ - case PM_SAMURAI: - if (otmp->otyp == YA && mwep && - mwep->otyp == YUMI) multishot++; - break; - default: - break; - } - /* racial bonus */ - if ((is_elf(mtmp->data) && - otmp->otyp == ELVEN_ARROW && - mwep && mwep->otyp == ELVEN_BOW) || - (is_orc(mtmp->data) && - otmp->otyp == ORCISH_ARROW && - mwep && mwep->otyp == ORCISH_BOW)) - multishot++; + /* class bonus */ + switch (monsndx(mtmp->data)) { + case PM_MONK: + if (skill == -P_SHURIKEN) + multishot++; + break; + case PM_RANGER: + multishot++; + break; + case PM_ROGUE: + if (skill == P_DAGGER) + multishot++; + break; + case PM_NINJA: + if (skill == -P_SHURIKEN || skill == -P_DART) + multishot++; + /*FALLTHRU*/ + case PM_SAMURAI: + if (otmp->otyp == YA && mwep && mwep->otyp == YUMI) + multishot++; + break; + default: + break; + } + /* racial bonus */ + if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW && mwep + && mwep->otyp == ELVEN_BOW) + || (is_orc(mtmp->data) && otmp->otyp == ORCISH_ARROW && mwep + && mwep->otyp == ORCISH_BOW)) + multishot++; - multishot = rnd(multishot); - if ((long)multishot > otmp->quan) multishot = (int)otmp->quan; - } + multishot = rnd(multishot); + if ((long) multishot > otmp->quan) + multishot = (int) otmp->quan; + } - if (canseemon(mtmp)) { - char onmbuf[BUFSZ]; + if (canseemon(mtmp)) { + char onmbuf[BUFSZ]; - if (multishot > 1) { - /* "N arrows"; multishot > 1 implies otmp->quan > 1, so - xname()'s result will already be pluralized */ - Sprintf(onmbuf, "%d %s", multishot, xname(otmp)); - onm = onmbuf; - } else { - /* "an arrow" */ - onm = singular(otmp, xname); - onm = obj_is_pname(otmp) ? the(onm) : an(onm); - } - m_shot.s = ammo_and_launcher(otmp,mwep) ? TRUE : FALSE; - pline("%s %s %s!", Monnam(mtmp), - m_shot.s ? "shoots" : "throws", onm); - m_shot.o = otmp->otyp; - } else { - m_shot.o = STRANGE_OBJECT; /* don't give multishot feedback */ - } + if (multishot > 1) { + /* "N arrows"; multishot > 1 implies otmp->quan > 1, so + xname()'s result will already be pluralized */ + Sprintf(onmbuf, "%d %s", multishot, xname(otmp)); + onm = onmbuf; + } else { + /* "an arrow" */ + onm = singular(otmp, xname); + onm = obj_is_pname(otmp) ? the(onm) : an(onm); + } + m_shot.s = ammo_and_launcher(otmp, mwep) ? TRUE : FALSE; + pline("%s %s %s!", Monnam(mtmp), m_shot.s ? "shoots" : "throws", onm); + m_shot.o = otmp->otyp; + } else { + m_shot.o = STRANGE_OBJECT; /* don't give multishot feedback */ + } - m_shot.n = multishot; - for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) { - m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), - distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); - /* conceptually all N missiles are in flight at once, but - if mtmp gets killed (shot kills adjacent gas spore and - triggers explosion, perhaps), inventory will be dropped - and otmp might go away via merging into another stack */ - if (mtmp->mhp <= 0 && m_shot.i < m_shot.n) { - /* cancel pending shots (ought to give a message here since - we gave one above about throwing/shooting N missiles) */ - break; /* endmultishot(FALSE); */ - } - } - m_shot.n = m_shot.i = 0; - m_shot.o = STRANGE_OBJECT; - m_shot.s = FALSE; + m_shot.n = multishot; + for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) { + m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), + distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); + /* conceptually all N missiles are in flight at once, but + if mtmp gets killed (shot kills adjacent gas spore and + triggers explosion, perhaps), inventory will be dropped + and otmp might go away via merging into another stack */ + if (mtmp->mhp <= 0 && m_shot.i < m_shot.n) { + /* cancel pending shots (ought to give a message here since + we gave one above about throwing/shooting N missiles) */ + break; /* endmultishot(FALSE); */ + } + } + m_shot.n = m_shot.i = 0; + m_shot.o = STRANGE_OBJECT; + m_shot.s = FALSE; - nomul(0); + nomul(0); } -int -spitmu(mtmp, mattk) /* monster spits substance at you */ +int spitmu(mtmp, mattk) /* monster spits substance at you */ register struct monst *mtmp; register struct attack *mattk; { - register struct obj *otmp; + register struct obj *otmp; - if(mtmp->mcan) { - - if(!Deaf) - pline("A dry rattle comes from %s throat.", - s_suffix(mon_nam(mtmp))); - return 0; - } - if(lined_up(mtmp)) { - switch (mattk->adtyp) { - case AD_BLND: - case AD_DRST: - otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); - break; - default: - impossible("bad attack type in spitmu"); - /* fall through */ - case AD_ACID: - otmp = mksobj(ACID_VENOM, TRUE, FALSE); - break; - } - if(!rn2(BOLT_LIM-distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy))) { - if (canseemon(mtmp)) - pline("%s spits venom!", Monnam(mtmp)); - m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), - distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy), otmp); - nomul(0); - return 0; - } - } - return 0; + if (mtmp->mcan) { + if (!Deaf) + pline("A dry rattle comes from %s throat.", + s_suffix(mon_nam(mtmp))); + return 0; + } + if (lined_up(mtmp)) { + switch (mattk->adtyp) { + case AD_BLND: + case AD_DRST: + otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); + break; + default: + impossible("bad attack type in spitmu"); + /* fall through */ + case AD_ACID: + otmp = mksobj(ACID_VENOM, TRUE, FALSE); + break; + } + if (!rn2(BOLT_LIM + - distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy))) { + if (canseemon(mtmp)) + pline("%s spits venom!", Monnam(mtmp)); + m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby), + distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); + nomul(0); + return 0; + } + } + return 0; } -int -breamu(mtmp, mattk) /* monster breathes at you (ranged) */ - register struct monst *mtmp; - register struct attack *mattk; +int breamu(mtmp, mattk) /* monster breathes at you (ranged) */ +register struct monst *mtmp; +register struct attack *mattk; { - /* if new breath types are added, change AD_ACID to max type */ - int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp ; + /* if new breath types are added, change AD_ACID to max type */ + int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp; - if(lined_up(mtmp)) { - - if(mtmp->mcan) { - if(!Deaf) { - if(canseemon(mtmp)) - pline("%s coughs.", Monnam(mtmp)); - else - You_hear("a cough."); - } - return(0); - } - if(!mtmp->mspec_used && rn2(3)) { - - if((typ >= AD_MAGM) && (typ <= AD_ACID)) { - - if(canseemon(mtmp)) - pline("%s breathes %s!", Monnam(mtmp), - breathwep[typ-1]); - buzz((int) (-20 - (typ-1)), (int)mattk->damn, - mtmp->mx, mtmp->my, sgn(tbx), sgn(tby)); - nomul(0); - /* breath runs out sometimes. Also, give monster some - * cunning; don't breath if the player fell asleep. - */ - if(!rn2(3)) - mtmp->mspec_used = 10+rn2(20); - if(typ == AD_SLEE && !Sleep_resistance) - mtmp->mspec_used += rnd(20); - } else impossible("Breath weapon %d used", typ-1); - } - } - return(1); + if (lined_up(mtmp)) { + if (mtmp->mcan) { + if (!Deaf) { + if (canseemon(mtmp)) + pline("%s coughs.", Monnam(mtmp)); + else + You_hear("a cough."); + } + return (0); + } + if (!mtmp->mspec_used && rn2(3)) { + if ((typ >= AD_MAGM) && (typ <= AD_ACID)) { + if (canseemon(mtmp)) + pline("%s breathes %s!", Monnam(mtmp), + breathwep[typ - 1]); + buzz((int) (-20 - (typ - 1)), (int) mattk->damn, mtmp->mx, + mtmp->my, sgn(tbx), sgn(tby)); + nomul(0); + /* breath runs out sometimes. Also, give monster some + * cunning; don't breath if the player fell asleep. + */ + if (!rn2(3)) + mtmp->mspec_used = 10 + rn2(20); + if (typ == AD_SLEE && !Sleep_resistance) + mtmp->mspec_used += rnd(20); + } else + impossible("Breath weapon %d used", typ - 1); + } + } + return (1); } boolean linedup(ax, ay, bx, by, boulderhandling) register xchar ax, ay, bx, by; -int boulderhandling; /* 0=block, 1=ignore, 2=conditionally block */ +int boulderhandling; /* 0=block, 1=ignore, 2=conditionally block */ { - int dx, dy, boulderspots; + int dx, dy, boulderspots; - tbx = ax - bx; /* These two values are set for use */ - tby = ay - by; /* after successful return. */ + tbx = ax - bx; /* These two values are set for use */ + tby = ay - by; /* after successful return. */ - /* sometimes displacement makes a monster think that you're at its - own location; prevent it from throwing and zapping in that case */ - if (!tbx && !tby) return FALSE; + /* sometimes displacement makes a monster think that you're at its + own location; prevent it from throwing and zapping in that case */ + if (!tbx && !tby) + return FALSE; - if((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */ - && distmin(tbx, tby, 0, 0) < BOLT_LIM) { - if ((ax == u.ux && ay == u.uy) ? (boolean)couldsee(bx, by) : - clear_path(ax, ay, bx, by)) return TRUE; - /* don't have line of sight, but might still be lined up - if that lack of sight is due solely to boulders */ - if (boulderhandling == 0) return FALSE; - dx = sgn(ax - bx), dy = sgn(ay - by); - boulderspots = 0; - do { - /* is guaranteed to eventually converge with */ - bx += dx, by += dy; - if (IS_ROCK(levl[bx][by].typ) || closed_door(bx, by)) - return FALSE; - if (sobj_at(BOULDER, bx, by)) ++boulderspots; - } while (bx != ax || by != ay); - /* reached target position without encountering obstacle */ - if (boulderhandling == 1 || rn2(2 + boulderspots) < 2) return TRUE; - } - return FALSE; + if ((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */ + && distmin(tbx, tby, 0, 0) < BOLT_LIM) { + if ((ax == u.ux && ay == u.uy) ? (boolean) couldsee(bx, by) + : clear_path(ax, ay, bx, by)) + return TRUE; + /* don't have line of sight, but might still be lined up + if that lack of sight is due solely to boulders */ + if (boulderhandling == 0) + return FALSE; + dx = sgn(ax - bx), dy = sgn(ay - by); + boulderspots = 0; + do { + /* is guaranteed to eventually converge with */ + bx += dx, by += dy; + if (IS_ROCK(levl[bx][by].typ) || closed_door(bx, by)) + return FALSE; + if (sobj_at(BOULDER, bx, by)) + ++boulderspots; + } while (bx != ax || by != ay); + /* reached target position without encountering obstacle */ + if (boulderhandling == 1 || rn2(2 + boulderspots) < 2) + return TRUE; + } + return FALSE; } -boolean -lined_up(mtmp) /* is mtmp in position to use ranged attack? */ - register struct monst *mtmp; +boolean lined_up(mtmp) /* is mtmp in position to use ranged attack? */ +register struct monst *mtmp; { - boolean ignore_boulders; + boolean ignore_boulders; - /* hero concealment usually trumps monst awareness of being lined up */ - if (Upolyd && rn2(25) && - (u.uundetected || (youmonst.m_ap_type != M_AP_NOTHING && - youmonst.m_ap_type != M_AP_MONSTER))) - return FALSE; + /* hero concealment usually trumps monst awareness of being lined up */ + if (Upolyd && rn2(25) + && (u.uundetected || (youmonst.m_ap_type != M_AP_NOTHING + && youmonst.m_ap_type != M_AP_MONSTER))) + return FALSE; - ignore_boulders = (throws_rocks(mtmp->data) || - m_carrying(mtmp, WAN_STRIKING)); - return linedup(mtmp->mux, mtmp->muy, mtmp->mx, mtmp->my, - ignore_boulders ? 1 : 2); + ignore_boulders = + (throws_rocks(mtmp->data) || m_carrying(mtmp, WAN_STRIKING)); + return linedup(mtmp->mux, mtmp->muy, mtmp->mx, mtmp->my, + ignore_boulders ? 1 : 2); } /* Check if a monster is carrying a particular item. @@ -777,84 +816,79 @@ m_carrying(mtmp, type) struct monst *mtmp; int type; { - register struct obj *otmp; + register struct obj *otmp; - for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if(otmp->otyp == type) - return(otmp); - return((struct obj *) 0); + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->otyp == type) + return (otmp); + return ((struct obj *) 0); } /* TRUE iff thrown/kicked/rolled object doesn't pass through iron bars */ boolean hits_bars(obj_p, x, y, always_hit, whodidit) -struct obj **obj_p; /* *obj_p will be set to NULL if object breaks */ +struct obj **obj_p; /* *obj_p will be set to NULL if object breaks */ int x, y; -int always_hit; /* caller can force a hit for items which would fit through */ -int whodidit; /* 1==hero, 0=other, -1==just check whether it'll pass thru */ +int always_hit; /* caller can force a hit for items which would fit through */ +int whodidit; /* 1==hero, 0=other, -1==just check whether it'll pass thru */ { struct obj *otmp = *obj_p; int obj_type = otmp->otyp; boolean hits = always_hit; if (!hits) - switch (otmp->oclass) { - case WEAPON_CLASS: - { - int oskill = objects[obj_type].oc_skill; + switch (otmp->oclass) { + case WEAPON_CLASS: { + int oskill = objects[obj_type].oc_skill; - hits = (oskill != -P_BOW && oskill != -P_CROSSBOW && - oskill != -P_DART && oskill != -P_SHURIKEN && - oskill != P_SPEAR && - oskill != P_KNIFE); /* but not dagger */ - break; - } - case ARMOR_CLASS: - hits = (objects[obj_type].oc_armcat != ARM_GLOVES); - break; - case TOOL_CLASS: - hits = (obj_type != SKELETON_KEY && - obj_type != LOCK_PICK && - obj_type != CREDIT_CARD && - obj_type != TALLOW_CANDLE && - obj_type != WAX_CANDLE && - obj_type != LENSES && - obj_type != TIN_WHISTLE && - obj_type != MAGIC_WHISTLE); - break; - case ROCK_CLASS: /* includes boulder */ - if (obj_type != STATUE || - mons[otmp->corpsenm].msize > MZ_TINY) hits = TRUE; - break; - case FOOD_CLASS: - if (obj_type == CORPSE && - mons[otmp->corpsenm].msize > MZ_TINY) hits = TRUE; - else - hits = (obj_type == MEAT_STICK || - obj_type == HUGE_CHUNK_OF_MEAT); - break; - case SPBOOK_CLASS: - case WAND_CLASS: - case BALL_CLASS: - case CHAIN_CLASS: - hits = TRUE; - break; - default: - break; - } + hits = (oskill != -P_BOW && oskill != -P_CROSSBOW + && oskill != -P_DART && oskill != -P_SHURIKEN + && oskill != P_SPEAR + && oskill != P_KNIFE); /* but not dagger */ + break; + } + case ARMOR_CLASS: + hits = (objects[obj_type].oc_armcat != ARM_GLOVES); + break; + case TOOL_CLASS: + hits = (obj_type != SKELETON_KEY && obj_type != LOCK_PICK + && obj_type != CREDIT_CARD && obj_type != TALLOW_CANDLE + && obj_type != WAX_CANDLE && obj_type != LENSES + && obj_type != TIN_WHISTLE && obj_type != MAGIC_WHISTLE); + break; + case ROCK_CLASS: /* includes boulder */ + if (obj_type != STATUE || mons[otmp->corpsenm].msize > MZ_TINY) + hits = TRUE; + break; + case FOOD_CLASS: + if (obj_type == CORPSE && mons[otmp->corpsenm].msize > MZ_TINY) + hits = TRUE; + else + hits = (obj_type == MEAT_STICK + || obj_type == HUGE_CHUNK_OF_MEAT); + break; + case SPBOOK_CLASS: + case WAND_CLASS: + case BALL_CLASS: + case CHAIN_CLASS: + hits = TRUE; + break; + default: + break; + } if (hits && whodidit != -1) { - if (whodidit ? hero_breaks(otmp, x, y, FALSE) : breaks(otmp, x, y)) - *obj_p = otmp = 0; /* object is now gone */ - /* breakage makes its own noises */ - else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL) - pline("Whang!"); - else if (otmp->oclass == COIN_CLASS || - objects[obj_type].oc_material == GOLD || - objects[obj_type].oc_material == SILVER) - pline("Clink!"); - else - pline("Clonk!"); + if (whodidit ? hero_breaks(otmp, x, y, FALSE) : breaks(otmp, x, y)) + *obj_p = otmp = 0; /* object is now gone */ + /* breakage makes its own noises */ + else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL) + pline("Whang!"); + else if (otmp->oclass == COIN_CLASS + || objects[obj_type].oc_material == GOLD + || objects[obj_type].oc_material == SILVER) + pline("Clink!"); + else + pline("Clonk!"); } return hits; diff --git a/src/muse.c b/src/muse.c index d93161581..a77fe1883 100644 --- a/src/muse.c +++ b/src/muse.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 muse.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 muse.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.61 $ */ /* NetHack 3.6 muse.c $Date: 2012/04/12 23:26:47 $ $Revision: 1.49 $ */ /* Copyright (C) 1990 by Ken Arromdee */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,48 +14,52 @@ extern const int monstr[]; boolean m_using = FALSE; /* Let monsters use magic items. Arbitrary assumptions: Monsters only use - * scrolls when they can see, monsters know when wands have 0 charges, monsters + * scrolls when they can see, monsters know when wands have 0 charges, + * monsters * cannot recognize if items are cursed are not, monsters which are confused * don't know not to read scrolls, etc.... */ STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *)); -STATIC_DCL int FDECL(precheck, (struct monst *,struct obj *)); -STATIC_DCL void FDECL(mzapmsg, (struct monst *,struct obj *,BOOLEAN_P)); -STATIC_DCL void FDECL(mreadmsg, (struct monst *,struct obj *)); -STATIC_DCL void FDECL(mquaffmsg, (struct monst *,struct obj *)); -STATIC_PTR int FDECL(mbhitm, (struct monst *,struct obj *)); +STATIC_DCL int FDECL(precheck, (struct monst *, struct obj *)); +STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P)); +STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *)); +STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *)); +STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *)); STATIC_DCL void FDECL(mbhit, - (struct monst *,int,int FDECL((*),(MONST_P,OBJ_P)), - int FDECL((*),(OBJ_P,OBJ_P)),struct obj *)); + (struct monst *, int, int FDECL((*), (MONST_P, OBJ_P)), + int FDECL((*), (OBJ_P, OBJ_P)), struct obj *)); STATIC_DCL void FDECL(you_aggravate, (struct monst *)); -STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *,struct obj *, - BOOLEAN_P,BOOLEAN_P)); -STATIC_DCL boolean FDECL(cures_stoning, (struct monst *,struct obj *,BOOLEAN_P)); +STATIC_DCL void FDECL(mon_consume_unstone, + (struct monst *, struct obj *, BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL boolean +FDECL(cures_stoning, (struct monst *, struct obj *, BOOLEAN_P)); STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *)); -STATIC_DCL boolean FDECL(muse_unslime, (struct monst *,struct obj *,BOOLEAN_P)); -STATIC_DCL int FDECL(cures_sliming, (struct monst *,struct obj *)); +STATIC_DCL boolean +FDECL(muse_unslime, (struct monst *, struct obj *, BOOLEAN_P)); +STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); STATIC_DCL boolean FDECL(green_mon, (struct monst *)); static struct musable { - struct obj *offensive; - struct obj *defensive; - struct obj *misc; - int has_offense, has_defense, has_misc; - /* =0, no capability; otherwise, different numbers. - * If it's an object, the object is also set (it's 0 otherwise). - */ + struct obj *offensive; + struct obj *defensive; + struct obj *misc; + int has_offense, has_defense, has_misc; + /* =0, no capability; otherwise, different numbers. + * If it's an object, the object is also set (it's 0 otherwise). + */ } m; static int trapx, trapy; static boolean zap_oseen; - /* for wands which use mbhitm and are zapped at players. We usually - * want an oseen local to the function, but this is impossible since the - * function mbhitm has to be compatible with the normal zap routines, - * and those routines don't remember who zapped the wand. - */ +/* for wands which use mbhitm and are zapped at players. We usually + * want an oseen local to the function, but this is impossible since the + * function mbhitm has to be compatible with the normal zap routines, + * and those routines don't remember who zapped the wand. + */ /* Any preliminary checks which may result in the monster being unable to use - * the item. Returns 0 if nothing happened, 2 if the monster can't do anything + * the item. Returns 0 if nothing happened, 2 if the monster can't do + * anything * (i.e. it teleported) and 1 if it's dead. */ STATIC_OVL int @@ -63,87 +67,98 @@ precheck(mon, obj) struct monst *mon; struct obj *obj; { - boolean vis; + boolean vis; - if (!obj) return 0; - vis = cansee(mon->mx, mon->my); + if (!obj) + return 0; + vis = cansee(mon->mx, mon->my); - if (obj->oclass == POTION_CLASS) { - coord cc; - static const char *empty = "The potion turns out to be empty."; - const char *potion_descr; - struct monst *mtmp; + if (obj->oclass == POTION_CLASS) { + coord cc; + static const char *empty = "The potion turns out to be empty."; + const char *potion_descr; + struct monst *mtmp; - potion_descr = OBJ_DESCR(objects[obj->otyp]); - if (potion_descr && !strcmp(potion_descr, "milky")) { - if (!(mvitals[PM_GHOST].mvflags & G_GONE) && - !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { - if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST])) return 0; - mquaffmsg(mon, obj); - m_useup(mon, obj); - mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS); - if (!mtmp) { - if (vis) pline1(empty); - } else { - if (vis) { - pline("As %s opens the bottle, an enormous %s emerges!", - mon_nam(mon), - Hallucination ? rndmonnam(NULL) : (const char *)"ghost"); - pline("%s is frightened to death, and unable to move.", - Monnam(mon)); - } - paralyze_monst(mon, 3); - } - return 2; - } - } - if (potion_descr && !strcmp(potion_descr, "smoky") && - !(mvitals[PM_DJINNI].mvflags & G_GONE) && - !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { - if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI])) return 0; - mquaffmsg(mon, obj); - m_useup(mon, obj); - mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS); - if (!mtmp) { - if (vis) pline1(empty); - } else { - if (vis) - pline("In a cloud of smoke, %s emerges!", - a_monnam(mtmp)); - pline("%s speaks.", vis ? Monnam(mtmp) : Something); - /* I suspect few players will be upset that monsters */ - /* can't wish for wands of death here.... */ - if (rn2(2)) { - verbalize("You freed me!"); - mtmp->mpeaceful = 1; - set_malign(mtmp); - } else { - verbalize("It is about time."); - if (vis) pline("%s vanishes.", Monnam(mtmp)); - mongone(mtmp); - } - } - return 2; - } - } - if (obj->oclass == WAND_CLASS && obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { - int dam = d(obj->spe+2, 6); + potion_descr = OBJ_DESCR(objects[obj->otyp]); + if (potion_descr && !strcmp(potion_descr, "milky")) { + if (!(mvitals[PM_GHOST].mvflags & G_GONE) + && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { + if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST])) + return 0; + mquaffmsg(mon, obj); + m_useup(mon, obj); + mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS); + if (!mtmp) { + if (vis) + pline1(empty); + } else { + if (vis) { + pline( + "As %s opens the bottle, an enormous %s emerges!", + mon_nam(mon), + Hallucination ? rndmonnam(NULL) + : (const char *) "ghost"); + pline( + "%s is frightened to death, and unable to move.", + Monnam(mon)); + } + paralyze_monst(mon, 3); + } + return 2; + } + } + if (potion_descr && !strcmp(potion_descr, "smoky") + && !(mvitals[PM_DJINNI].mvflags & G_GONE) + && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { + if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI])) + return 0; + mquaffmsg(mon, obj); + m_useup(mon, obj); + mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS); + if (!mtmp) { + if (vis) + pline1(empty); + } else { + if (vis) + pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp)); + pline("%s speaks.", vis ? Monnam(mtmp) : Something); + /* I suspect few players will be upset that monsters */ + /* can't wish for wands of death here.... */ + if (rn2(2)) { + verbalize("You freed me!"); + mtmp->mpeaceful = 1; + set_malign(mtmp); + } else { + verbalize("It is about time."); + if (vis) + pline("%s vanishes.", Monnam(mtmp)); + mongone(mtmp); + } + } + return 2; + } + } + if (obj->oclass == WAND_CLASS && obj->cursed + && !rn2(WAND_BACKFIRE_CHANCE)) { + int dam = d(obj->spe + 2, 6); - if (!Deaf) { - if (vis) pline("%s zaps %s, which suddenly explodes!", - Monnam(mon), an(xname(obj))); - else You_hear("a zap and an explosion in the distance."); - } - m_useup(mon, obj); - if (mon->mhp <= dam) { - monkilled(mon, "", AD_RBRE); - return 1; - } - else mon->mhp -= dam; - m.has_defense = m.has_offense = m.has_misc = 0; - /* Only one needed to be set to 0 but the others are harmless */ - } - return 0; + if (!Deaf) { + if (vis) + pline("%s zaps %s, which suddenly explodes!", Monnam(mon), + an(xname(obj))); + else + You_hear("a zap and an explosion in the distance."); + } + m_useup(mon, obj); + if (mon->mhp <= dam) { + monkilled(mon, "", AD_RBRE); + return 1; + } else + mon->mhp -= dam; + m.has_defense = m.has_offense = m.has_misc = 0; + /* Only one needed to be set to 0 but the others are harmless */ + } + return 0; } STATIC_OVL void @@ -152,18 +167,19 @@ struct monst *mtmp; struct obj *otmp; boolean self; { - if (!canseemon(mtmp)) { - if (!Deaf) - You_hear("a %s zap.", - (distu(mtmp->mx,mtmp->my) <= (BOLT_LIM+1)*(BOLT_LIM+1)) ? - "nearby" : "distant"); - } else if (self) - pline("%s zaps %sself with %s!", - Monnam(mtmp), mhim(mtmp), doname(otmp)); - else { - pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp))); - stop_occupation(); - } + if (!canseemon(mtmp)) { + if (!Deaf) + You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my) + <= (BOLT_LIM + 1) * (BOLT_LIM + 1)) + ? "nearby" + : "distant"); + } else if (self) + pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp), + doname(otmp)); + else { + pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp))); + stop_occupation(); + } } STATIC_OVL void @@ -171,38 +187,40 @@ mreadmsg(mtmp, otmp) struct monst *mtmp; struct obj *otmp; { - boolean vismon = canseemon(mtmp); - char onambuf[BUFSZ]; - short saverole; - unsigned savebknown; + boolean vismon = canseemon(mtmp); + char onambuf[BUFSZ]; + short saverole; + unsigned savebknown; - if (!vismon && Deaf) - return; /* no feedback */ + if (!vismon && Deaf) + return; /* no feedback */ - otmp->dknown = 1; /* seeing or hearing it read reveals its label */ - /* shouldn't be able to hear curse/bless status of unseen scrolls; - for priest characters, bknown will always be set during naming */ - savebknown = otmp->bknown; - saverole = Role_switch; - if (!vismon) { - otmp->bknown = 0; - if (Role_if(PM_PRIEST)) Role_switch = 0; - } - Strcpy(onambuf, singular(otmp, doname)); - Role_switch = saverole; - otmp->bknown = savebknown; + otmp->dknown = 1; /* seeing or hearing it read reveals its label */ + /* shouldn't be able to hear curse/bless status of unseen scrolls; + for priest characters, bknown will always be set during naming */ + savebknown = otmp->bknown; + saverole = Role_switch; + if (!vismon) { + otmp->bknown = 0; + if (Role_if(PM_PRIEST)) + Role_switch = 0; + } + Strcpy(onambuf, singular(otmp, doname)); + Role_switch = saverole; + otmp->bknown = savebknown; - if (vismon) - pline("%s reads %s!", Monnam(mtmp), onambuf); - else - You_hear("%s reading %s.", - x_monnam(mtmp, ARTICLE_A, (char *)0, - (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE), FALSE), - onambuf); + if (vismon) + pline("%s reads %s!", Monnam(mtmp), onambuf); + else + You_hear("%s reading %s.", x_monnam(mtmp, ARTICLE_A, (char *) 0, + (SUPPRESS_IT | SUPPRESS_INVISIBLE + | SUPPRESS_SADDLE), + FALSE), + onambuf); - if (mtmp->mconf) - pline("Being confused, %s mispronounces the magic words...", - vismon ? mon_nam(mtmp) : mhe(mtmp)); + if (mtmp->mconf) + pline("Being confused, %s mispronounces the magic words...", + vismon ? mon_nam(mtmp) : mhe(mtmp)); } STATIC_OVL void @@ -210,12 +228,11 @@ mquaffmsg(mtmp, otmp) struct monst *mtmp; struct obj *otmp; { - if (canseemon(mtmp)) { - otmp->dknown = 1; - pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname)); - } else - if (!Deaf) - You_hear("a chugging sound."); + if (canseemon(mtmp)) { + otmp->dknown = 1; + pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname)); + } else if (!Deaf) + You_hear("a chugging sound."); } /* Defines for various types of stuff. The order in which monsters prefer @@ -245,7 +262,8 @@ struct obj *otmp; #define MUSE_INNATE_TPT 9999 * We cannot use this. Since monsters get unlimited teleportation, if they * were allowed to teleport at will you could never catch them. Instead, - * assume they only teleport at random times, despite the inconsistency that if + * assume they only teleport at random times, despite the inconsistency that +if * you polymorph into one you teleport at will. */ @@ -256,279 +274,294 @@ boolean find_defensive(mtmp) struct monst *mtmp; { - register struct obj *obj = 0; - struct trap *t; - int x=mtmp->mx, y=mtmp->my; - boolean stuck = (mtmp == u.ustuck); - boolean immobile = (mtmp->data->mmove == 0); - int fraction; + register struct obj *obj = 0; + struct trap *t; + int x = mtmp->mx, y = mtmp->my; + boolean stuck = (mtmp == u.ustuck); + boolean immobile = (mtmp->data->mmove == 0); + int fraction; - if (is_animal(mtmp->data) || mindless(mtmp->data)) - return FALSE; - if(dist2(x, y, mtmp->mux, mtmp->muy) > 25) - return FALSE; - if (u.uswallow && stuck) return FALSE; + if (is_animal(mtmp->data) || mindless(mtmp->data)) + return FALSE; + if (dist2(x, y, mtmp->mux, mtmp->muy) > 25) + return FALSE; + if (u.uswallow && stuck) + return FALSE; - m.defensive = (struct obj *)0; - m.has_defense = 0; + m.defensive = (struct obj *) 0; + m.has_defense = 0; - /* since unicorn horns don't get used up, the monster would look - * silly trying to use the same cursed horn round after round - */ - if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) { - if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) { - for(obj = mtmp->minvent; obj; obj = obj->nobj) - if (obj->otyp == UNICORN_HORN && !obj->cursed) - break; - } - if (obj || is_unicorn(mtmp->data)) { - m.defensive = obj; - m.has_defense = MUSE_UNICORN_HORN; - return TRUE; - } - } + /* since unicorn horns don't get used up, the monster would look + * silly trying to use the same cursed horn round after round + */ + if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) { + if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) { + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if (obj->otyp == UNICORN_HORN && !obj->cursed) + break; + } + if (obj || is_unicorn(mtmp->data)) { + m.defensive = obj; + m.has_defense = MUSE_UNICORN_HORN; + return TRUE; + } + } - if (mtmp->mconf || mtmp->mstun) { - struct obj *liztin = 0; + if (mtmp->mconf || mtmp->mstun) { + struct obj *liztin = 0; - for (obj = mtmp->minvent; obj; obj = obj->nobj) { - if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { - m.defensive = obj; - m.has_defense = MUSE_LIZARD_CORPSE; - return TRUE; - } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) { - liztin = obj; - } - } - /* confused or stunned monster might not be able to open tin */ - if (liztin && mcould_eat_tin(mtmp) && rn2(3)) { - m.defensive = liztin; - /* tin and corpse ultimately end up being handled the same */ - m.has_defense = MUSE_LIZARD_CORPSE; - return TRUE; - } - } + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { + m.defensive = obj; + m.has_defense = MUSE_LIZARD_CORPSE; + return TRUE; + } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) { + liztin = obj; + } + } + /* confused or stunned monster might not be able to open tin */ + if (liztin && mcould_eat_tin(mtmp) && rn2(3)) { + m.defensive = liztin; + /* tin and corpse ultimately end up being handled the same */ + m.has_defense = MUSE_LIZARD_CORPSE; + return TRUE; + } + } - /* It so happens there are two unrelated cases when we might want to - * check specifically for healing alone. The first is when the monster - * is blind (healing cures blindness). The second is when the monster - * is peaceful; then we don't want to flee the player, and by - * coincidence healing is all there is that doesn't involve fleeing. - * These would be hard to combine because of the control flow. - * Pestilence won't use healing even when blind. - */ - if (!mtmp->mcansee && !nohands(mtmp->data) && - mtmp->data != &mons[PM_PESTILENCE]) { - if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; - return TRUE; - } - if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; - return TRUE; - } - if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; - return TRUE; - } - } + /* It so happens there are two unrelated cases when we might want to + * check specifically for healing alone. The first is when the monster + * is blind (healing cures blindness). The second is when the monster + * is peaceful; then we don't want to flee the player, and by + * coincidence healing is all there is that doesn't involve fleeing. + * These would be hard to combine because of the control flow. + * Pestilence won't use healing even when blind. + */ + if (!mtmp->mcansee && !nohands(mtmp->data) + && mtmp->data != &mons[PM_PESTILENCE]) { + if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_FULL_HEALING; + return TRUE; + } + if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_EXTRA_HEALING; + return TRUE; + } + if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_HEALING; + return TRUE; + } + } - fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; - if(mtmp->mhp >= mtmp->mhpmax || - (mtmp->mhp >= 10 && mtmp->mhp*fraction >= mtmp->mhpmax)) - return FALSE; + fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; + if (mtmp->mhp >= mtmp->mhpmax + || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax)) + return FALSE; - if (mtmp->mpeaceful) { - if (!nohands(mtmp->data)) { - if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; - return TRUE; - } - if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; - return TRUE; - } - if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; - return TRUE; - } - } - return FALSE; - } + if (mtmp->mpeaceful) { + if (!nohands(mtmp->data)) { + if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_FULL_HEALING; + return TRUE; + } + if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_EXTRA_HEALING; + return TRUE; + } + if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { + m.defensive = obj; + m.has_defense = MUSE_POT_HEALING; + return TRUE; + } + } + return FALSE; + } - if (levl[x][y].typ == STAIRS && !stuck && !immobile) { - if (x == xdnstair && y == ydnstair && !is_floater(mtmp->data)) - m.has_defense = MUSE_DOWNSTAIRS; - if (x == xupstair && y == yupstair && ledger_no(&u.uz) != 1) - /* Unfair to let the monsters leave the dungeon with the Amulet */ - /* (or go to the endlevel since you also need it, to get there) */ - m.has_defense = MUSE_UPSTAIRS; - } else if (levl[x][y].typ == LADDER && !stuck && !immobile) { - if (x == xupladder && y == yupladder) - m.has_defense = MUSE_UP_LADDER; - if (x == xdnladder && y == ydnladder && !is_floater(mtmp->data)) - m.has_defense = MUSE_DN_LADDER; - } else if (sstairs.sx && sstairs.sx == x && sstairs.sy == y) { - m.has_defense = MUSE_SSTAIRS; - } else if (!stuck && !immobile) { - /* Note: trap doors take precedence over teleport traps. */ - int xx, yy; + if (levl[x][y].typ == STAIRS && !stuck && !immobile) { + if (x == xdnstair && y == ydnstair && !is_floater(mtmp->data)) + m.has_defense = MUSE_DOWNSTAIRS; + if (x == xupstair && y == yupstair && ledger_no(&u.uz) != 1) + /* Unfair to let the monsters leave the dungeon with the Amulet */ + /* (or go to the endlevel since you also need it, to get there) */ + m.has_defense = MUSE_UPSTAIRS; + } else if (levl[x][y].typ == LADDER && !stuck && !immobile) { + if (x == xupladder && y == yupladder) + m.has_defense = MUSE_UP_LADDER; + if (x == xdnladder && y == ydnladder && !is_floater(mtmp->data)) + m.has_defense = MUSE_DN_LADDER; + } else if (sstairs.sx && sstairs.sx == x && sstairs.sy == y) { + m.has_defense = MUSE_SSTAIRS; + } else if (!stuck && !immobile) { + /* Note: trap doors take precedence over teleport traps. */ + int xx, yy; - for(xx = x-1; xx <= x+1; xx++) for(yy = y-1; yy <= y+1; yy++) - if (isok(xx,yy)) - if (xx != u.ux || yy != u.uy) - if (mtmp->data != &mons[PM_GRID_BUG] || xx == x || yy == y) - if ((xx==x && yy==y) || !level.monsters[xx][yy]) - if ((t = t_at(xx,yy)) != 0) - if ((verysmall(mtmp->data) || throws_rocks(mtmp->data) || - passes_walls(mtmp->data)) || !sobj_at(BOULDER, xx, yy)) - if (!onscary(xx,yy,mtmp)) { - if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE) - && !is_floater(mtmp->data) - && !mtmp->isshk && !mtmp->isgd - && !mtmp->ispriest - && Can_fall_thru(&u.uz) - ) { - trapx = xx; - trapy = yy; - m.has_defense = MUSE_TRAPDOOR; - } else if (t->ttyp == TELEP_TRAP && m.has_defense != MUSE_TRAPDOOR) { - trapx = xx; - trapy = yy; - m.has_defense = MUSE_TELEPORT_TRAP; - } - } - } + for (xx = x - 1; xx <= x + 1; xx++) + for (yy = y - 1; yy <= y + 1; yy++) + if (isok(xx, yy)) + if (xx != u.ux || yy != u.uy) + if (mtmp->data != &mons[PM_GRID_BUG] || xx == x + || yy == y) + if ((xx == x && yy == y) + || !level.monsters[xx][yy]) + if ((t = t_at(xx, yy)) != 0) + if ((verysmall(mtmp->data) + || throws_rocks(mtmp->data) + || passes_walls(mtmp->data)) + || !sobj_at(BOULDER, xx, yy)) + if (!onscary(xx, yy, mtmp)) { + if ((t->ttyp == TRAPDOOR + || t->ttyp == HOLE) + && !is_floater(mtmp->data) + && !mtmp->isshk && !mtmp->isgd + && !mtmp->ispriest + && Can_fall_thru(&u.uz)) { + trapx = xx; + trapy = yy; + m.has_defense = MUSE_TRAPDOOR; + } else if ( + t->ttyp == TELEP_TRAP + && m.has_defense + != MUSE_TRAPDOOR) { + trapx = xx; + trapy = yy; + m.has_defense = + MUSE_TELEPORT_TRAP; + } + } + } - if (nohands(mtmp->data)) /* can't use objects */ - goto botm; + if (nohands(mtmp->data)) /* can't use objects */ + goto botm; - if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE))) { - int xx, yy; - struct monst *mon; + if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE))) { + int xx, yy; + struct monst *mon; - /* Distance is arbitrary. What we really want to do is - * have the soldier play the bugle when it sees or - * remembers soldiers nearby... - */ - for(xx = x-3; xx <= x+3; xx++) for(yy = y-3; yy <= y+3; yy++) - if (isok(xx,yy)) - if ((mon = m_at(xx,yy)) && is_mercenary(mon->data) && - mon->data != &mons[PM_GUARD] && - (mon->msleeping || (!mon->mcanmove))) { - m.defensive = obj; - m.has_defense = MUSE_BUGLE; - } - } + /* Distance is arbitrary. What we really want to do is + * have the soldier play the bugle when it sees or + * remembers soldiers nearby... + */ + for (xx = x - 3; xx <= x + 3; xx++) + for (yy = y - 3; yy <= y + 3; yy++) + if (isok(xx, yy)) + if ((mon = m_at(xx, yy)) && is_mercenary(mon->data) + && mon->data != &mons[PM_GUARD] + && (mon->msleeping || (!mon->mcanmove))) { + m.defensive = obj; + m.has_defense = MUSE_BUGLE; + } + } - /* use immediate physical escape prior to attempting magic */ - if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ - goto botm; + /* use immediate physical escape prior to attempting magic */ + if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ + goto botm; - /* kludge to cut down on trap destruction (particularly portals) */ - t = t_at(x,y); - if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || - t->ttyp == WEB || t->ttyp == BEAR_TRAP)) - t = 0; /* ok for monster to dig here */ + /* kludge to cut down on trap destruction (particularly portals) */ + t = t_at(x, y); + if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == WEB + || t->ttyp == BEAR_TRAP)) + t = 0; /* ok for monster to dig here */ -#define nomore(x) if(m.has_defense==x) continue; - for (obj = mtmp->minvent; obj; obj = obj->nobj) { - /* don't always use the same selection pattern */ - if (m.has_defense && !rn2(3)) break; +#define nomore(x) \ + if (m.has_defense == x) \ + continue; + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + /* don't always use the same selection pattern */ + if (m.has_defense && !rn2(3)) + break; - /* nomore(MUSE_WAN_DIGGING); */ - if (m.has_defense == MUSE_WAN_DIGGING) break; - if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t - && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest - && !is_floater(mtmp->data) - /* monsters digging in Sokoban can ruin things */ - && !Sokoban - /* digging wouldn't be effective; assume they know that */ - && !(levl[x][y].wall_info & W_NONDIGGABLE) - && !(Is_botlevel(&u.uz) || In_endgame(&u.uz)) - && !(is_ice(x,y) || is_pool(x,y) || is_lava(x,y)) - && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER] - && In_V_tower(&u.uz))) { - m.defensive = obj; - m.has_defense = MUSE_WAN_DIGGING; - } - nomore(MUSE_WAN_TELEPORTATION_SELF); - nomore(MUSE_WAN_TELEPORTATION); - if(obj->otyp == WAN_TELEPORTATION && obj->spe > 0) { - /* use the TELEP_TRAP bit to determine if they know - * about noteleport on this level or not. Avoids - * ineffective re-use of teleportation. This does - * mean if the monster leaves the level, they'll know - * about teleport traps. - */ - if (!level.flags.noteleport || - !(mtmp->mtrapseen & (1 << (TELEP_TRAP-1)))) { - m.defensive = obj; - m.has_defense = (mon_has_amulet(mtmp)) - ? MUSE_WAN_TELEPORTATION - : MUSE_WAN_TELEPORTATION_SELF; - } - } - nomore(MUSE_SCR_TELEPORTATION); - if(obj->otyp == SCR_TELEPORTATION && mtmp->mcansee - && haseyes(mtmp->data) - && (!obj->cursed || - (!(mtmp->isshk && inhishop(mtmp)) - && !mtmp->isgd && !mtmp->ispriest))) { - /* see WAN_TELEPORTATION case above */ - if (!level.flags.noteleport || - !(mtmp->mtrapseen & (1 << (TELEP_TRAP-1)))) { - m.defensive = obj; - m.has_defense = MUSE_SCR_TELEPORTATION; - } - } + /* nomore(MUSE_WAN_DIGGING); */ + if (m.has_defense == MUSE_WAN_DIGGING) + break; + if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t + && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest + && !is_floater(mtmp->data) + /* monsters digging in Sokoban can ruin things */ + && !Sokoban + /* digging wouldn't be effective; assume they know that */ + && !(levl[x][y].wall_info & W_NONDIGGABLE) + && !(Is_botlevel(&u.uz) || In_endgame(&u.uz)) + && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y)) + && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER] + && In_V_tower(&u.uz))) { + m.defensive = obj; + m.has_defense = MUSE_WAN_DIGGING; + } + nomore(MUSE_WAN_TELEPORTATION_SELF); + nomore(MUSE_WAN_TELEPORTATION); + if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) { + /* use the TELEP_TRAP bit to determine if they know + * about noteleport on this level or not. Avoids + * ineffective re-use of teleportation. This does + * mean if the monster leaves the level, they'll know + * about teleport traps. + */ + if (!level.flags.noteleport + || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { + m.defensive = obj; + m.has_defense = (mon_has_amulet(mtmp)) + ? MUSE_WAN_TELEPORTATION + : MUSE_WAN_TELEPORTATION_SELF; + } + } + nomore(MUSE_SCR_TELEPORTATION); + if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee + && haseyes(mtmp->data) + && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp)) + && !mtmp->isgd && !mtmp->ispriest))) { + /* see WAN_TELEPORTATION case above */ + if (!level.flags.noteleport + || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { + m.defensive = obj; + m.has_defense = MUSE_SCR_TELEPORTATION; + } + } - if (mtmp->data != &mons[PM_PESTILENCE]) { - nomore(MUSE_POT_FULL_HEALING); - if(obj->otyp == POT_FULL_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; - } - nomore(MUSE_POT_EXTRA_HEALING); - if(obj->otyp == POT_EXTRA_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_EXTRA_HEALING; - } - nomore(MUSE_WAN_CREATE_MONSTER); - if(obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; - } - nomore(MUSE_POT_HEALING); - if(obj->otyp == POT_HEALING) { - m.defensive = obj; - m.has_defense = MUSE_POT_HEALING; - } - } else { /* Pestilence */ - nomore(MUSE_POT_FULL_HEALING); - if (obj->otyp == POT_SICKNESS) { - m.defensive = obj; - m.has_defense = MUSE_POT_FULL_HEALING; - } - nomore(MUSE_WAN_CREATE_MONSTER); - if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { - m.defensive = obj; - m.has_defense = MUSE_WAN_CREATE_MONSTER; - } - } - nomore(MUSE_SCR_CREATE_MONSTER); - if(obj->otyp == SCR_CREATE_MONSTER) { - m.defensive = obj; - m.has_defense = MUSE_SCR_CREATE_MONSTER; - } - } -botm: return((boolean)(!!m.has_defense)); + if (mtmp->data != &mons[PM_PESTILENCE]) { + nomore(MUSE_POT_FULL_HEALING); + if (obj->otyp == POT_FULL_HEALING) { + m.defensive = obj; + m.has_defense = MUSE_POT_FULL_HEALING; + } + nomore(MUSE_POT_EXTRA_HEALING); + if (obj->otyp == POT_EXTRA_HEALING) { + m.defensive = obj; + m.has_defense = MUSE_POT_EXTRA_HEALING; + } + nomore(MUSE_WAN_CREATE_MONSTER); + if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { + m.defensive = obj; + m.has_defense = MUSE_WAN_CREATE_MONSTER; + } + nomore(MUSE_POT_HEALING); + if (obj->otyp == POT_HEALING) { + m.defensive = obj; + m.has_defense = MUSE_POT_HEALING; + } + } else { /* Pestilence */ + nomore(MUSE_POT_FULL_HEALING); + if (obj->otyp == POT_SICKNESS) { + m.defensive = obj; + m.has_defense = MUSE_POT_FULL_HEALING; + } + nomore(MUSE_WAN_CREATE_MONSTER); + if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { + m.defensive = obj; + m.has_defense = MUSE_WAN_CREATE_MONSTER; + } + } + nomore(MUSE_SCR_CREATE_MONSTER); + if (obj->otyp == SCR_CREATE_MONSTER) { + m.defensive = obj; + m.has_defense = MUSE_SCR_CREATE_MONSTER; + } + } +botm: + return ((boolean)(!!m.has_defense)); #undef nomore } @@ -540,374 +573,411 @@ int use_defensive(mtmp) struct monst *mtmp; { - int i, fleetim, how = 0; - struct obj *otmp = m.defensive; - boolean vis, vismon, oseen; - const char *mcsa = "%s can see again."; + int i, fleetim, how = 0; + struct obj *otmp = m.defensive; + boolean vis, vismon, oseen; + const char *mcsa = "%s can see again."; - if ((i = precheck(mtmp, otmp)) != 0) return i; - vis = cansee(mtmp->mx, mtmp->my); - vismon = canseemon(mtmp); - oseen = otmp && vismon; + if ((i = precheck(mtmp, otmp)) != 0) + return i; + vis = cansee(mtmp->mx, mtmp->my); + vismon = canseemon(mtmp); + oseen = otmp && vismon; - /* when using defensive choice to run away, we want monster to avoid - rushing right straight back; don't override if already scared */ - fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0; -#define m_flee(m) if (fleetim && !m->iswiz) \ - { monflee(m, fleetim, FALSE, FALSE); } + /* when using defensive choice to run away, we want monster to avoid + rushing right straight back; don't override if already scared */ + fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0; +#define m_flee(m) \ + if (fleetim && !m->iswiz) { \ + monflee(m, fleetim, FALSE, FALSE); \ + } - switch(m.has_defense) { - case MUSE_UNICORN_HORN: - if (vismon) { - if (otmp) - pline("%s uses a unicorn horn!", Monnam(mtmp)); - else - pline_The("tip of %s's horn glows!", mon_nam(mtmp)); - } - if (!mtmp->mcansee) { - mtmp->mcansee = 1; - mtmp->mblinded = 0; - if (vismon) pline(mcsa, Monnam(mtmp)); - } else if (mtmp->mconf || mtmp->mstun) { - mtmp->mconf = mtmp->mstun = 0; - if (vismon) - pline("%s seems steadier now.", Monnam(mtmp)); - } else impossible("No need for unicorn horn?"); - return 2; - case MUSE_BUGLE: - if (vismon) - pline("%s plays %s!", Monnam(mtmp), doname(otmp)); - else if (!Deaf) - You_hear("a bugle playing reveille!"); - awaken_soldiers(mtmp); - return 2; - case MUSE_WAN_TELEPORTATION_SELF: - if ((mtmp->isshk && inhishop(mtmp)) - || mtmp->isgd || mtmp->ispriest) return 2; - m_flee(mtmp); - mzapmsg(mtmp, otmp, TRUE); - otmp->spe--; - how = WAN_TELEPORTATION; -mon_tele: - if (tele_restrict(mtmp)) { /* mysterious force... */ - if (vismon && how) /* mentions 'teleport' */ - makeknown(how); - /* monster learns that teleportation isn't useful here */ - if (level.flags.noteleport) - mtmp->mtrapseen |= (1 << (TELEP_TRAP-1)); - return 2; - } - if (( + switch (m.has_defense) { + case MUSE_UNICORN_HORN: + if (vismon) { + if (otmp) + pline("%s uses a unicorn horn!", Monnam(mtmp)); + else + pline_The("tip of %s's horn glows!", mon_nam(mtmp)); + } + if (!mtmp->mcansee) { + mtmp->mcansee = 1; + mtmp->mblinded = 0; + if (vismon) + pline(mcsa, Monnam(mtmp)); + } else if (mtmp->mconf || mtmp->mstun) { + mtmp->mconf = mtmp->mstun = 0; + if (vismon) + pline("%s seems steadier now.", Monnam(mtmp)); + } else + impossible("No need for unicorn horn?"); + return 2; + case MUSE_BUGLE: + if (vismon) + pline("%s plays %s!", Monnam(mtmp), doname(otmp)); + else if (!Deaf) + You_hear("a bugle playing reveille!"); + awaken_soldiers(mtmp); + return 2; + case MUSE_WAN_TELEPORTATION_SELF: + if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest) + return 2; + m_flee(mtmp); + mzapmsg(mtmp, otmp, TRUE); + otmp->spe--; + how = WAN_TELEPORTATION; + mon_tele: + if (tele_restrict(mtmp)) { /* mysterious force... */ + if (vismon && how) /* mentions 'teleport' */ + makeknown(how); + /* monster learns that teleportation isn't useful here */ + if (level.flags.noteleport) + mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1)); + return 2; + } + if (( #if 0 mon_has_amulet(mtmp) || #endif - On_W_tower_level(&u.uz)) && !rn2(3)) { - if (vismon) - pline("%s seems disoriented for a moment.", - Monnam(mtmp)); - return 2; - } - if (oseen && how) makeknown(how); - (void) rloc(mtmp, FALSE); - return 2; - case MUSE_WAN_TELEPORTATION: - zap_oseen = oseen; - mzapmsg(mtmp, otmp, FALSE); - otmp->spe--; - m_using = TRUE; - mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp); - /* monster learns that teleportation isn't useful here */ - if (level.flags.noteleport) - mtmp->mtrapseen |= (1 << (TELEP_TRAP-1)); - m_using = FALSE; - return 2; - case MUSE_SCR_TELEPORTATION: - { - int obj_is_cursed = otmp->cursed; + On_W_tower_level(&u.uz)) && !rn2(3)) { + if (vismon) + pline("%s seems disoriented for a moment.", Monnam(mtmp)); + return 2; + } + if (oseen && how) + makeknown(how); + (void) rloc(mtmp, FALSE); + return 2; + case MUSE_WAN_TELEPORTATION: + zap_oseen = oseen; + mzapmsg(mtmp, otmp, FALSE); + otmp->spe--; + m_using = TRUE; + mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); + /* monster learns that teleportation isn't useful here */ + if (level.flags.noteleport) + mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1)); + m_using = FALSE; + return 2; + case MUSE_SCR_TELEPORTATION: { + int obj_is_cursed = otmp->cursed; - if (mtmp->isshk || mtmp->isgd || mtmp->ispriest) return 2; - m_flee(mtmp); - mreadmsg(mtmp, otmp); - m_useup(mtmp, otmp); /* otmp might be free'ed */ - how = SCR_TELEPORTATION; - if (obj_is_cursed || mtmp->mconf) { - int nlev; - d_level flev; + if (mtmp->isshk || mtmp->isgd || mtmp->ispriest) + return 2; + m_flee(mtmp); + mreadmsg(mtmp, otmp); + m_useup(mtmp, otmp); /* otmp might be free'ed */ + how = SCR_TELEPORTATION; + if (obj_is_cursed || mtmp->mconf) { + int nlev; + d_level flev; - if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { - if (vismon) - pline("%s seems very disoriented for a moment.", - Monnam(mtmp)); - return 2; - } - nlev = random_teleport_level(); - if (nlev == depth(&u.uz)) { - if (vismon) - pline("%s shudders for a moment.", - Monnam(mtmp)); - return 2; - } - get_level(&flev, nlev); - migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM, - (coord *)0); - if (oseen) makeknown(SCR_TELEPORTATION); - } else goto mon_tele; - return 2; - } - case MUSE_WAN_DIGGING: - { struct trap *ttmp; + if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { + if (vismon) + pline("%s seems very disoriented for a moment.", + Monnam(mtmp)); + return 2; + } + nlev = random_teleport_level(); + if (nlev == depth(&u.uz)) { + if (vismon) + pline("%s shudders for a moment.", Monnam(mtmp)); + return 2; + } + get_level(&flev, nlev); + migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM, + (coord *) 0); + if (oseen) + makeknown(SCR_TELEPORTATION); + } else + goto mon_tele; + return 2; + } + case MUSE_WAN_DIGGING: { + struct trap *ttmp; - m_flee(mtmp); - mzapmsg(mtmp, otmp, FALSE); - otmp->spe--; - if (oseen) makeknown(WAN_DIGGING); - if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ) || - IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ) || - (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0) || - (sstairs.sx && sstairs.sx == mtmp->mx && - sstairs.sy == mtmp->my)) { - pline_The("digging ray is ineffective."); - return 2; - } - if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) { - if(canseemon(mtmp)) - pline_The("%s here is too hard to dig in.", - surface(mtmp->mx, mtmp->my)); - return 2; - } - ttmp = maketrap(mtmp->mx, mtmp->my, HOLE); - if (!ttmp) return 2; - seetrap(ttmp); - if (vis) { - pline("%s has made a hole in the %s.", Monnam(mtmp), - surface(mtmp->mx, mtmp->my)); - pline("%s %s through...", Monnam(mtmp), - is_flyer(mtmp->data) ? "dives" : "falls"); - } else if (!Deaf) - You_hear("%s crash through the %s.", something, - surface(mtmp->mx, mtmp->my)); - /* we made sure that there is a level for mtmp to go to */ - migrate_to_level(mtmp, ledger_no(&u.uz) + 1, - MIGR_RANDOM, (coord *)0); - return 2; - } - case MUSE_WAN_CREATE_MONSTER: - { coord cc; - /* pm: 0 => random, eel => aquatic, croc => amphibious */ - struct permonst *pm = !is_pool(mtmp->mx, mtmp->my) ? 0 : - &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; - struct monst *mon; + m_flee(mtmp); + mzapmsg(mtmp, otmp, FALSE); + otmp->spe--; + if (oseen) + makeknown(WAN_DIGGING); + if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ) + || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ) + || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0) + || (sstairs.sx && sstairs.sx == mtmp->mx + && sstairs.sy == mtmp->my)) { + pline_The("digging ray is ineffective."); + return 2; + } + if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) { + if (canseemon(mtmp)) + pline_The("%s here is too hard to dig in.", + surface(mtmp->mx, mtmp->my)); + return 2; + } + ttmp = maketrap(mtmp->mx, mtmp->my, HOLE); + if (!ttmp) + return 2; + seetrap(ttmp); + if (vis) { + pline("%s has made a hole in the %s.", Monnam(mtmp), + surface(mtmp->mx, mtmp->my)); + pline("%s %s through...", Monnam(mtmp), + is_flyer(mtmp->data) ? "dives" : "falls"); + } else if (!Deaf) + You_hear("%s crash through the %s.", something, + surface(mtmp->mx, mtmp->my)); + /* we made sure that there is a level for mtmp to go to */ + migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, + (coord *) 0); + return 2; + } + case MUSE_WAN_CREATE_MONSTER: { + coord cc; + /* pm: 0 => random, eel => aquatic, croc => amphibious */ + struct permonst *pm = + !is_pool(mtmp->mx, mtmp->my) + ? 0 + : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; + struct monst *mon; - if (!enexto(&cc, mtmp->mx, mtmp->my, pm)) return 0; - mzapmsg(mtmp, otmp, FALSE); - otmp->spe--; - mon = makemon((struct permonst *)0, cc.x, cc.y, NO_MM_FLAGS); - if (mon && canspotmon(mon) && oseen) - makeknown(WAN_CREATE_MONSTER); - return 2; - } - case MUSE_SCR_CREATE_MONSTER: - { coord cc; - struct permonst *pm = 0, *fish = 0; - int cnt = 1; - struct monst *mon; - boolean known = FALSE; + if (!enexto(&cc, mtmp->mx, mtmp->my, pm)) + return 0; + mzapmsg(mtmp, otmp, FALSE); + otmp->spe--; + mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS); + if (mon && canspotmon(mon) && oseen) + makeknown(WAN_CREATE_MONSTER); + return 2; + } + case MUSE_SCR_CREATE_MONSTER: { + coord cc; + struct permonst *pm = 0, *fish = 0; + int cnt = 1; + struct monst *mon; + boolean known = FALSE; - if (!rn2(73)) cnt += rnd(4); - if (mtmp->mconf || otmp->cursed) cnt += 12; - if (mtmp->mconf) pm = fish = &mons[PM_ACID_BLOB]; - else if (is_pool(mtmp->mx, mtmp->my)) - fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; - mreadmsg(mtmp, otmp); - while(cnt--) { - /* `fish' potentially gives bias towards water locations; - `pm' is what to actually create (0 => random) */ - if (!enexto(&cc, mtmp->mx, mtmp->my, fish)) break; - mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS); - if (mon && canspotmon(mon)) known = TRUE; - } - /* The only case where we don't use oseen. For wands, you - * have to be able to see the monster zap the wand to know - * what type it is. For teleport scrolls, you have to see - * the monster to know it teleported. - */ - if (known) - makeknown(SCR_CREATE_MONSTER); - else if (!objects[SCR_CREATE_MONSTER].oc_name_known - && !objects[SCR_CREATE_MONSTER].oc_uname) - docall(otmp); - m_useup(mtmp, otmp); - return 2; - } - case MUSE_TRAPDOOR: - /* trap doors on "bottom" levels of dungeons are rock-drop - * trap doors, not holes in the floor. We check here for - * safety. - */ - if (Is_botlevel(&u.uz)) return 0; - m_flee(mtmp); - if (vis) { - struct trap *t; - t = t_at(trapx,trapy); - pline("%s %s into a %s!", Monnam(mtmp), - makeplural(locomotion(mtmp->data, "jump")), - t->ttyp == TRAPDOOR ? "trap door" : "hole"); - if (levl[trapx][trapy].typ == SCORR) { - levl[trapx][trapy].typ = CORR; - unblock_point(trapx, trapy); - } - seetrap(t_at(trapx,trapy)); - } + if (!rn2(73)) + cnt += rnd(4); + if (mtmp->mconf || otmp->cursed) + cnt += 12; + if (mtmp->mconf) + pm = fish = &mons[PM_ACID_BLOB]; + else if (is_pool(mtmp->mx, mtmp->my)) + fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; + mreadmsg(mtmp, otmp); + while (cnt--) { + /* `fish' potentially gives bias towards water locations; + `pm' is what to actually create (0 => random) */ + if (!enexto(&cc, mtmp->mx, mtmp->my, fish)) + break; + mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS); + if (mon && canspotmon(mon)) + known = TRUE; + } + /* The only case where we don't use oseen. For wands, you + * have to be able to see the monster zap the wand to know + * what type it is. For teleport scrolls, you have to see + * the monster to know it teleported. + */ + if (known) + makeknown(SCR_CREATE_MONSTER); + else if (!objects[SCR_CREATE_MONSTER].oc_name_known + && !objects[SCR_CREATE_MONSTER].oc_uname) + docall(otmp); + m_useup(mtmp, otmp); + return 2; + } + case MUSE_TRAPDOOR: + /* trap doors on "bottom" levels of dungeons are rock-drop + * trap doors, not holes in the floor. We check here for + * safety. + */ + if (Is_botlevel(&u.uz)) + return 0; + m_flee(mtmp); + if (vis) { + struct trap *t; + t = t_at(trapx, trapy); + pline("%s %s into a %s!", Monnam(mtmp), + makeplural(locomotion(mtmp->data, "jump")), + t->ttyp == TRAPDOOR ? "trap door" : "hole"); + if (levl[trapx][trapy].typ == SCORR) { + levl[trapx][trapy].typ = CORR; + unblock_point(trapx, trapy); + } + seetrap(t_at(trapx, trapy)); + } - /* don't use rloc_to() because worm tails must "move" */ - remove_monster(mtmp->mx, mtmp->my); - newsym(mtmp->mx, mtmp->my); /* update old location */ - place_monster(mtmp, trapx, trapy); - if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + /* don't use rloc_to() because worm tails must "move" */ + remove_monster(mtmp->mx, mtmp->my); + newsym(mtmp->mx, mtmp->my); /* update old location */ + place_monster(mtmp, trapx, trapy); + if (mtmp->wormno) + worm_move(mtmp); + newsym(trapx, trapy); - migrate_to_level(mtmp, ledger_no(&u.uz) + 1, - MIGR_RANDOM, (coord *)0); - return 2; - case MUSE_UPSTAIRS: - /* Monsters without amulets escape the dungeon and are - * gone for good when they leave up the up stairs. - * Monsters with amulets would reach the endlevel, - * which we cannot allow since that would leave the - * player stranded. - */ - if (ledger_no(&u.uz) == 1) { - if (mon_has_special(mtmp)) - return 0; - if (vismon) - pline("%s escapes the dungeon!", Monnam(mtmp)); - mongone(mtmp); - return 2; - } - m_flee(mtmp); - if (Inhell && mon_has_amulet(mtmp) && !rn2(4) && - (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { - if (vismon) pline( - "As %s climbs the stairs, a mysterious force momentarily surrounds %s...", - mon_nam(mtmp), mhim(mtmp)); - /* simpler than for the player; this will usually be - the Wizard and he'll immediately go right to the - upstairs, so there's not much point in having any - chance for a random position on the current level */ - migrate_to_level(mtmp, ledger_no(&u.uz) + 1, - MIGR_RANDOM, (coord *)0); - } else { - if (vismon) pline("%s escapes upstairs!", Monnam(mtmp)); - migrate_to_level(mtmp, ledger_no(&u.uz) - 1, - MIGR_STAIRS_DOWN, (coord *)0); - } - return 2; - case MUSE_DOWNSTAIRS: - m_flee(mtmp); - if (vismon) pline("%s escapes downstairs!", Monnam(mtmp)); - migrate_to_level(mtmp, ledger_no(&u.uz) + 1, - MIGR_STAIRS_UP, (coord *)0); - return 2; - case MUSE_UP_LADDER: - m_flee(mtmp); - if (vismon) pline("%s escapes up the ladder!", Monnam(mtmp)); - migrate_to_level(mtmp, ledger_no(&u.uz) - 1, - MIGR_LADDER_DOWN, (coord *)0); - return 2; - case MUSE_DN_LADDER: - m_flee(mtmp); - if (vismon) pline("%s escapes down the ladder!", Monnam(mtmp)); - migrate_to_level(mtmp, ledger_no(&u.uz) + 1, - MIGR_LADDER_UP, (coord *)0); - return 2; - case MUSE_SSTAIRS: - m_flee(mtmp); - /* the stairs leading up from the 1st level are */ - /* regular stairs, not sstairs. */ - if (sstairs.up) { - if (vismon) - pline("%s escapes upstairs!", Monnam(mtmp)); - if(Inhell) { - migrate_to_level(mtmp, ledger_no(&sstairs.tolev), - MIGR_RANDOM, (coord *)0); - return 2; - } - } else if (vismon) - pline("%s escapes downstairs!", Monnam(mtmp)); - migrate_to_level(mtmp, ledger_no(&sstairs.tolev), - MIGR_SSTAIRS, (coord *)0); - return 2; - case MUSE_TELEPORT_TRAP: - m_flee(mtmp); - if (vis) { - pline("%s %s onto a teleport trap!", Monnam(mtmp), - makeplural(locomotion(mtmp->data, "jump"))); - if (levl[trapx][trapy].typ == SCORR) { - levl[trapx][trapy].typ = CORR; - unblock_point(trapx, trapy); - } - seetrap(t_at(trapx,trapy)); - } - /* don't use rloc_to() because worm tails must "move" */ - remove_monster(mtmp->mx, mtmp->my); - newsym(mtmp->mx, mtmp->my); /* update old location */ - place_monster(mtmp, trapx, trapy); - if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, + (coord *) 0); + return 2; + case MUSE_UPSTAIRS: + /* Monsters without amulets escape the dungeon and are + * gone for good when they leave up the up stairs. + * Monsters with amulets would reach the endlevel, + * which we cannot allow since that would leave the + * player stranded. + */ + if (ledger_no(&u.uz) == 1) { + if (mon_has_special(mtmp)) + return 0; + if (vismon) + pline("%s escapes the dungeon!", Monnam(mtmp)); + mongone(mtmp); + return 2; + } + m_flee(mtmp); + if (Inhell && mon_has_amulet(mtmp) && !rn2(4) + && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { + if (vismon) + pline("As %s climbs the stairs, a mysterious force " + "momentarily surrounds %s...", + mon_nam(mtmp), mhim(mtmp)); + /* simpler than for the player; this will usually be + the Wizard and he'll immediately go right to the + upstairs, so there's not much point in having any + chance for a random position on the current level */ + migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, + (coord *) 0); + } else { + if (vismon) + pline("%s escapes upstairs!", Monnam(mtmp)); + migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN, + (coord *) 0); + } + return 2; + case MUSE_DOWNSTAIRS: + m_flee(mtmp); + if (vismon) + pline("%s escapes downstairs!", Monnam(mtmp)); + migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP, + (coord *) 0); + return 2; + case MUSE_UP_LADDER: + m_flee(mtmp); + if (vismon) + pline("%s escapes up the ladder!", Monnam(mtmp)); + migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN, + (coord *) 0); + return 2; + case MUSE_DN_LADDER: + m_flee(mtmp); + if (vismon) + pline("%s escapes down the ladder!", Monnam(mtmp)); + migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP, + (coord *) 0); + return 2; + case MUSE_SSTAIRS: + m_flee(mtmp); + /* the stairs leading up from the 1st level are */ + /* regular stairs, not sstairs. */ + if (sstairs.up) { + if (vismon) + pline("%s escapes upstairs!", Monnam(mtmp)); + if (Inhell) { + migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_RANDOM, + (coord *) 0); + return 2; + } + } else if (vismon) + pline("%s escapes downstairs!", Monnam(mtmp)); + migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS, + (coord *) 0); + return 2; + case MUSE_TELEPORT_TRAP: + m_flee(mtmp); + if (vis) { + pline("%s %s onto a teleport trap!", Monnam(mtmp), + makeplural(locomotion(mtmp->data, "jump"))); + if (levl[trapx][trapy].typ == SCORR) { + levl[trapx][trapy].typ = CORR; + unblock_point(trapx, trapy); + } + seetrap(t_at(trapx, trapy)); + } + /* don't use rloc_to() because worm tails must "move" */ + remove_monster(mtmp->mx, mtmp->my); + newsym(mtmp->mx, mtmp->my); /* update old location */ + place_monster(mtmp, trapx, trapy); + if (mtmp->wormno) + worm_move(mtmp); + newsym(trapx, trapy); - goto mon_tele; - case MUSE_POT_HEALING: - mquaffmsg(mtmp, otmp); - i = d(6 + 2 * bcsign(otmp), 4); - mtmp->mhp += i; - if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = ++mtmp->mhpmax; - if (!otmp->cursed && !mtmp->mcansee) { - mtmp->mcansee = 1; - mtmp->mblinded = 0; - if (vismon) pline(mcsa, Monnam(mtmp)); - } - if (vismon) pline("%s looks better.", Monnam(mtmp)); - if (oseen) makeknown(POT_HEALING); - m_useup(mtmp, otmp); - return 2; - case MUSE_POT_EXTRA_HEALING: - mquaffmsg(mtmp, otmp); - i = d(6 + 2 * bcsign(otmp), 8); - mtmp->mhp += i; - if (mtmp->mhp > mtmp->mhpmax) - mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2)); - if (!mtmp->mcansee) { - mtmp->mcansee = 1; - mtmp->mblinded = 0; - if (vismon) pline(mcsa, Monnam(mtmp)); - } - if (vismon) pline("%s looks much better.", Monnam(mtmp)); - if (oseen) makeknown(POT_EXTRA_HEALING); - m_useup(mtmp, otmp); - return 2; - case MUSE_POT_FULL_HEALING: - mquaffmsg(mtmp, otmp); - if (otmp->otyp == POT_SICKNESS) unbless(otmp); /* Pestilence */ - mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4)); - if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) { - mtmp->mcansee = 1; - mtmp->mblinded = 0; - if (vismon) pline(mcsa, Monnam(mtmp)); - } - if (vismon) pline("%s looks completely healed.", Monnam(mtmp)); - if (oseen) makeknown(otmp->otyp); - m_useup(mtmp, otmp); - return 2; - case MUSE_LIZARD_CORPSE: - /* not actually called for its unstoning effect */ - mon_consume_unstone(mtmp, otmp, FALSE, FALSE); - return 2; - case 0: return 0; /* i.e. an exploded wand */ - default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_defense); - break; - } - return 0; + goto mon_tele; + case MUSE_POT_HEALING: + mquaffmsg(mtmp, otmp); + i = d(6 + 2 * bcsign(otmp), 4); + mtmp->mhp += i; + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = ++mtmp->mhpmax; + if (!otmp->cursed && !mtmp->mcansee) { + mtmp->mcansee = 1; + mtmp->mblinded = 0; + if (vismon) + pline(mcsa, Monnam(mtmp)); + } + if (vismon) + pline("%s looks better.", Monnam(mtmp)); + if (oseen) + makeknown(POT_HEALING); + m_useup(mtmp, otmp); + return 2; + case MUSE_POT_EXTRA_HEALING: + mquaffmsg(mtmp, otmp); + i = d(6 + 2 * bcsign(otmp), 8); + mtmp->mhp += i; + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2)); + if (!mtmp->mcansee) { + mtmp->mcansee = 1; + mtmp->mblinded = 0; + if (vismon) + pline(mcsa, Monnam(mtmp)); + } + if (vismon) + pline("%s looks much better.", Monnam(mtmp)); + if (oseen) + makeknown(POT_EXTRA_HEALING); + m_useup(mtmp, otmp); + return 2; + case MUSE_POT_FULL_HEALING: + mquaffmsg(mtmp, otmp); + if (otmp->otyp == POT_SICKNESS) + unbless(otmp); /* Pestilence */ + mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4)); + if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) { + mtmp->mcansee = 1; + mtmp->mblinded = 0; + if (vismon) + pline(mcsa, Monnam(mtmp)); + } + if (vismon) + pline("%s looks completely healed.", Monnam(mtmp)); + if (oseen) + makeknown(otmp->otyp); + m_useup(mtmp, otmp); + return 2; + case MUSE_LIZARD_CORPSE: + /* not actually called for its unstoning effect */ + mon_consume_unstone(mtmp, otmp, FALSE, FALSE); + return 2; + case 0: + return 0; /* i.e. an exploded wand */ + default: + impossible("%s wanted to perform action %d?", Monnam(mtmp), + m.has_defense); + break; + } + return 0; #undef m_flee } @@ -915,40 +985,47 @@ int rnd_defensive_item(mtmp) struct monst *mtmp; { - struct permonst *pm = mtmp->data; - int difficulty = monstr[(monsndx(pm))]; - int trycnt = 0; + struct permonst *pm = mtmp->data; + int difficulty = monstr[(monsndx(pm))]; + int trycnt = 0; - if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) - || pm->mlet == S_GHOST || pm->mlet == S_KOP) + if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) + || pm->mlet == S_GHOST || pm->mlet == S_KOP) + return 0; +try_again: + switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) { + case 6: + case 9: + if (level.flags.noteleport && ++trycnt < 2) + goto try_again; + if (!rn2(3)) + return WAN_TELEPORTATION; + /* else FALLTHRU */ + case 0: + case 1: + return SCR_TELEPORTATION; + case 8: + case 10: + if (!rn2(3)) + return WAN_CREATE_MONSTER; + /* else FALLTHRU */ + case 2: + return SCR_CREATE_MONSTER; + case 3: + return POT_HEALING; + case 4: + return POT_EXTRA_HEALING; + case 5: + return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING + : POT_SICKNESS; + case 7: + if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest) return 0; - try_again: - switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + - (difficulty > 8))) { - case 6: case 9: - if (level.flags.noteleport && ++trycnt < 2) - goto try_again; - if (!rn2(3)) return WAN_TELEPORTATION; - /* else FALLTHRU */ - case 0: case 1: - return SCR_TELEPORTATION; - case 8: case 10: - if (!rn2(3)) return WAN_CREATE_MONSTER; - /* else FALLTHRU */ - case 2: return SCR_CREATE_MONSTER; - case 3: return POT_HEALING; - case 4: return POT_EXTRA_HEALING; - case 5: return (mtmp->data != &mons[PM_PESTILENCE]) ? - POT_FULL_HEALING : POT_SICKNESS; - case 7: if (is_floater(pm) || mtmp->isshk || mtmp->isgd - || mtmp->ispriest - ) - return 0; - else - return WAN_DIGGING; - } - /*NOTREACHED*/ - return 0; + else + return WAN_DIGGING; + } + /*NOTREACHED*/ + return 0; } #define MUSE_WAN_DEATH 1 @@ -976,115 +1053,118 @@ boolean find_offensive(mtmp) struct monst *mtmp; { - register struct obj *obj; - boolean ranged_stuff = lined_up(mtmp); - boolean reflection_skip = (Reflecting && rn2(2)); - struct obj *helmet = which_armor(mtmp, W_ARMH); + register struct obj *obj; + boolean ranged_stuff = lined_up(mtmp); + boolean reflection_skip = (Reflecting && rn2(2)); + struct obj *helmet = which_armor(mtmp, W_ARMH); - m.offensive = (struct obj *)0; - m.has_offense = 0; - if (mtmp->mpeaceful || is_animal(mtmp->data) || - mindless(mtmp->data) || nohands(mtmp->data)) - return FALSE; - if (u.uswallow) return FALSE; - if (in_your_sanctuary(mtmp, 0, 0)) return FALSE; - if (dmgtype(mtmp->data, AD_HEAL) && !uwep && !uarmu && !uarm && !uarmh - && !uarms && !uarmg && !uarmc && !uarmf) - return FALSE; + m.offensive = (struct obj *) 0; + m.has_offense = 0; + if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data) + || nohands(mtmp->data)) + return FALSE; + if (u.uswallow) + return FALSE; + if (in_your_sanctuary(mtmp, 0, 0)) + return FALSE; + if (dmgtype(mtmp->data, AD_HEAL) && !uwep && !uarmu && !uarm && !uarmh + && !uarms && !uarmg && !uarmc && !uarmf) + return FALSE; - if (!ranged_stuff) return FALSE; -#define nomore(x) if(m.has_offense==x) continue; - for(obj=mtmp->minvent; obj; obj=obj->nobj) { - /* nomore(MUSE_WAN_DEATH); */ - if (!reflection_skip) { - if(obj->otyp == WAN_DEATH && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_DEATH; - } - nomore(MUSE_WAN_SLEEP); - if(obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_SLEEP; - } - nomore(MUSE_WAN_FIRE); - if(obj->otyp == WAN_FIRE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_FIRE; - } - nomore(MUSE_FIRE_HORN); - if(obj->otyp == FIRE_HORN && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_FIRE_HORN; - } - nomore(MUSE_WAN_COLD); - if(obj->otyp == WAN_COLD && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_COLD; - } - nomore(MUSE_FROST_HORN); - if(obj->otyp == FROST_HORN && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_FROST_HORN; - } - nomore(MUSE_WAN_LIGHTNING); - if(obj->otyp == WAN_LIGHTNING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_LIGHTNING; - } - nomore(MUSE_WAN_MAGIC_MISSILE); - if(obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_MAGIC_MISSILE; - } - } - nomore(MUSE_WAN_STRIKING); - if(obj->otyp == WAN_STRIKING && obj->spe > 0) { - m.offensive = obj; - m.has_offense = MUSE_WAN_STRIKING; - } - nomore(MUSE_POT_PARALYSIS); - if(obj->otyp == POT_PARALYSIS && multi >= 0) { - m.offensive = obj; - m.has_offense = MUSE_POT_PARALYSIS; - } - nomore(MUSE_POT_BLINDNESS); - if(obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { - m.offensive = obj; - m.has_offense = MUSE_POT_BLINDNESS; - } - nomore(MUSE_POT_CONFUSION); - if(obj->otyp == POT_CONFUSION) { - m.offensive = obj; - m.has_offense = MUSE_POT_CONFUSION; - } - nomore(MUSE_POT_SLEEPING); - if(obj->otyp == POT_SLEEPING) { - m.offensive = obj; - m.has_offense = MUSE_POT_SLEEPING; - } - nomore(MUSE_POT_ACID); - if(obj->otyp == POT_ACID) { - m.offensive = obj; - m.has_offense = MUSE_POT_ACID; - } - /* we can safely put this scroll here since the locations that - * are in a 1 square radius are a subset of the locations that - * are in wand range - */ - nomore(MUSE_SCR_EARTH); - if (obj->otyp == SCR_EARTH - && ((helmet && is_metallic(helmet)) || - mtmp->mconf || amorphous(mtmp->data) || - passes_walls(mtmp->data) || - noncorporeal(mtmp->data) || - unsolid(mtmp->data) || !rn2(10)) - && dist2(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy) <= 2 - && mtmp->mcansee && haseyes(mtmp->data) - && !Is_rogue_level(&u.uz) - && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { - m.offensive = obj; - m.has_offense = MUSE_SCR_EARTH; - } + if (!ranged_stuff) + return FALSE; +#define nomore(x) \ + if (m.has_offense == x) \ + continue; + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + /* nomore(MUSE_WAN_DEATH); */ + if (!reflection_skip) { + if (obj->otyp == WAN_DEATH && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_DEATH; + } + nomore(MUSE_WAN_SLEEP); + if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_SLEEP; + } + nomore(MUSE_WAN_FIRE); + if (obj->otyp == WAN_FIRE && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_FIRE; + } + nomore(MUSE_FIRE_HORN); + if (obj->otyp == FIRE_HORN && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_FIRE_HORN; + } + nomore(MUSE_WAN_COLD); + if (obj->otyp == WAN_COLD && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_COLD; + } + nomore(MUSE_FROST_HORN); + if (obj->otyp == FROST_HORN && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_FROST_HORN; + } + nomore(MUSE_WAN_LIGHTNING); + if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_LIGHTNING; + } + nomore(MUSE_WAN_MAGIC_MISSILE); + if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_MAGIC_MISSILE; + } + } + nomore(MUSE_WAN_STRIKING); + if (obj->otyp == WAN_STRIKING && obj->spe > 0) { + m.offensive = obj; + m.has_offense = MUSE_WAN_STRIKING; + } + nomore(MUSE_POT_PARALYSIS); + if (obj->otyp == POT_PARALYSIS && multi >= 0) { + m.offensive = obj; + m.has_offense = MUSE_POT_PARALYSIS; + } + nomore(MUSE_POT_BLINDNESS); + if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { + m.offensive = obj; + m.has_offense = MUSE_POT_BLINDNESS; + } + nomore(MUSE_POT_CONFUSION); + if (obj->otyp == POT_CONFUSION) { + m.offensive = obj; + m.has_offense = MUSE_POT_CONFUSION; + } + nomore(MUSE_POT_SLEEPING); + if (obj->otyp == POT_SLEEPING) { + m.offensive = obj; + m.has_offense = MUSE_POT_SLEEPING; + } + nomore(MUSE_POT_ACID); + if (obj->otyp == POT_ACID) { + m.offensive = obj; + m.has_offense = MUSE_POT_ACID; + } + /* we can safely put this scroll here since the locations that + * are in a 1 square radius are a subset of the locations that + * are in wand range + */ + nomore(MUSE_SCR_EARTH); + if (obj->otyp == SCR_EARTH + && ((helmet && is_metallic(helmet)) || mtmp->mconf + || amorphous(mtmp->data) || passes_walls(mtmp->data) + || noncorporeal(mtmp->data) || unsolid(mtmp->data) + || !rn2(10)) + && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2 + && mtmp->mcansee && haseyes(mtmp->data) && !Is_rogue_level(&u.uz) + && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { + m.offensive = obj; + m.has_offense = MUSE_SCR_EARTH; + } #if 0 nomore(MUSE_SCR_FIRE); if (obj->otyp == SCR_FIRE && resists_fire(mtmp) @@ -1094,8 +1174,8 @@ struct monst *mtmp; m.has_offense = MUSE_SCR_FIRE; } #endif - } - return((boolean)(!!m.has_offense)); + } + return ((boolean)(!!m.has_offense)); #undef nomore } @@ -1105,69 +1185,73 @@ mbhitm(mtmp, otmp) register struct monst *mtmp; register struct obj *otmp; { - int tmp; + int tmp; - boolean reveal_invis = FALSE; - if (mtmp != &youmonst) { - mtmp->msleeping = 0; - if (mtmp->m_ap_type) seemimic(mtmp); - } - switch(otmp->otyp) { - case WAN_STRIKING: - reveal_invis = TRUE; - if (mtmp == &youmonst) { - if (zap_oseen) makeknown(WAN_STRIKING); - if (Antimagic) { - shieldeff(u.ux, u.uy); - pline("Boing!"); - } else if (rnd(20) < 10 + u.uac) { - pline_The("wand hits you!"); - tmp = d(2,12); - if(Half_spell_damage) tmp = (tmp+1) / 2; - losehp(tmp, "wand", KILLED_BY_AN); - } else pline_The("wand misses you."); - stop_occupation(); - nomul(0); - } else if (resists_magm(mtmp)) { - shieldeff(mtmp->mx, mtmp->my); - pline("Boing!"); - } else if (rnd(20) < 10+find_mac(mtmp)) { - tmp = d(2,12); - hit("wand", mtmp, exclam(tmp)); - (void) resist(mtmp, otmp->oclass, tmp, TELL); - if (cansee(mtmp->mx, mtmp->my) && zap_oseen) - makeknown(WAN_STRIKING); - } else { - miss("wand", mtmp); - if (cansee(mtmp->mx, mtmp->my) && zap_oseen) - makeknown(WAN_STRIKING); - } - break; - case WAN_TELEPORTATION: - if (mtmp == &youmonst) { - if (zap_oseen) makeknown(WAN_TELEPORTATION); - tele(); - } else { - /* for consistency with zap.c, don't identify */ - if (mtmp->ispriest && - *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { - if (cansee(mtmp->mx, mtmp->my)) - pline("%s resists the magic!", Monnam(mtmp)); - } else if (!tele_restrict(mtmp)) - (void) rloc(mtmp, FALSE); - } - break; - case WAN_CANCELLATION: - case SPE_CANCELLATION: - (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE); - break; - } - if (reveal_invis) { - if (mtmp->mhp > 0 && cansee(bhitpos.x,bhitpos.y) - && !canspotmon(mtmp)) - map_invisible(bhitpos.x, bhitpos.y); - } - return 0; + boolean reveal_invis = FALSE; + if (mtmp != &youmonst) { + mtmp->msleeping = 0; + if (mtmp->m_ap_type) + seemimic(mtmp); + } + switch (otmp->otyp) { + case WAN_STRIKING: + reveal_invis = TRUE; + if (mtmp == &youmonst) { + if (zap_oseen) + makeknown(WAN_STRIKING); + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline("Boing!"); + } else if (rnd(20) < 10 + u.uac) { + pline_The("wand hits you!"); + tmp = d(2, 12); + if (Half_spell_damage) + tmp = (tmp + 1) / 2; + losehp(tmp, "wand", KILLED_BY_AN); + } else + pline_The("wand misses you."); + stop_occupation(); + nomul(0); + } else if (resists_magm(mtmp)) { + shieldeff(mtmp->mx, mtmp->my); + pline("Boing!"); + } else if (rnd(20) < 10 + find_mac(mtmp)) { + tmp = d(2, 12); + hit("wand", mtmp, exclam(tmp)); + (void) resist(mtmp, otmp->oclass, tmp, TELL); + if (cansee(mtmp->mx, mtmp->my) && zap_oseen) + makeknown(WAN_STRIKING); + } else { + miss("wand", mtmp); + if (cansee(mtmp->mx, mtmp->my) && zap_oseen) + makeknown(WAN_STRIKING); + } + break; + case WAN_TELEPORTATION: + if (mtmp == &youmonst) { + if (zap_oseen) + makeknown(WAN_TELEPORTATION); + tele(); + } else { + /* for consistency with zap.c, don't identify */ + if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s resists the magic!", Monnam(mtmp)); + } else if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + } + break; + case WAN_CANCELLATION: + case SPE_CANCELLATION: + (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE); + break; + } + if (reveal_invis) { + if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y) + && !canspotmon(mtmp)) + map_invisible(bhitpos.x, bhitpos.y); + } + return 0; } /* A modified bhit() for monsters. Based on bhit() in zap.c. Unlike @@ -1176,91 +1260,93 @@ register struct obj *otmp; * to merge the two functions...) */ STATIC_OVL void -mbhit(mon,range,fhitm,fhito,obj) -struct monst *mon; /* monster shooting the wand */ -register int range; /* direction and range */ -int FDECL((*fhitm),(MONST_P,OBJ_P)); -int FDECL((*fhito),(OBJ_P,OBJ_P)); /* fns called when mon/obj hit */ -struct obj *obj; /* 2nd arg to fhitm/fhito */ +mbhit(mon, range, fhitm, fhito, obj) +struct monst *mon; /* monster shooting the wand */ +register int range; /* direction and range */ +int FDECL((*fhitm), (MONST_P, OBJ_P)); +int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */ +struct obj *obj; /* 2nd arg to fhitm/fhito */ { - register struct monst *mtmp; - register struct obj *otmp; - register uchar typ; - int ddx, ddy; + register struct monst *mtmp; + register struct obj *otmp; + register uchar typ; + int ddx, ddy; - bhitpos.x = mon->mx; - bhitpos.y = mon->my; - ddx = sgn(mon->mux - mon->mx); - ddy = sgn(mon->muy - mon->my); + bhitpos.x = mon->mx; + bhitpos.y = mon->my; + ddx = sgn(mon->mux - mon->mx); + ddy = sgn(mon->muy - mon->my); - while(range-- > 0) { - int x,y; + while (range-- > 0) { + int x, y; - bhitpos.x += ddx; - bhitpos.y += ddy; - x = bhitpos.x; y = bhitpos.y; + bhitpos.x += ddx; + bhitpos.y += ddy; + x = bhitpos.x; + y = bhitpos.y; - if (!isok(x,y)) { - bhitpos.x -= ddx; - bhitpos.y -= ddy; - break; - } - if (find_drawbridge(&x,&y)) - switch (obj->otyp) { - case WAN_STRIKING: - destroy_drawbridge(x,y); - } - if(bhitpos.x==u.ux && bhitpos.y==u.uy) { - (*fhitm)(&youmonst, obj); - range -= 3; - } else if(MON_AT(bhitpos.x, bhitpos.y)){ - mtmp = m_at(bhitpos.x,bhitpos.y); - if (cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp)) - map_invisible(bhitpos.x, bhitpos.y); - (*fhitm)(mtmp, obj); - range -= 3; - } - /* modified by GAN to hit all objects */ - if(fhito){ - int hitanything = 0; - register struct obj *next_obj; + if (!isok(x, y)) { + bhitpos.x -= ddx; + bhitpos.y -= ddy; + break; + } + if (find_drawbridge(&x, &y)) + switch (obj->otyp) { + case WAN_STRIKING: + destroy_drawbridge(x, y); + } + if (bhitpos.x == u.ux && bhitpos.y == u.uy) { + (*fhitm)(&youmonst, obj); + range -= 3; + } else if (MON_AT(bhitpos.x, bhitpos.y)) { + mtmp = m_at(bhitpos.x, bhitpos.y); + if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) + map_invisible(bhitpos.x, bhitpos.y); + (*fhitm)(mtmp, obj); + range -= 3; + } + /* modified by GAN to hit all objects */ + if (fhito) { + int hitanything = 0; + register struct obj *next_obj; - for(otmp = level.objects[bhitpos.x][bhitpos.y]; - otmp; otmp = next_obj) { - /* Fix for polymorph bug, Tim Wright */ - next_obj = otmp->nexthere; - hitanything += (*fhito)(otmp, obj); - } - if(hitanything) range--; - } - typ = levl[bhitpos.x][bhitpos.y].typ; - if(IS_DOOR(typ) || typ == SDOOR) { - switch (obj->otyp) { - /* note: monsters don't use opening or locking magic - at present, but keep these as placeholders */ - case WAN_OPENING: - case WAN_LOCKING: - case WAN_STRIKING: - if (doorlock(obj, bhitpos.x, bhitpos.y)) { - if (zap_oseen) makeknown(obj->otyp); - /* if a shop door gets broken, add it to - the shk's fix list (no cost to player) */ - if (levl[bhitpos.x][bhitpos.y].doormask == - D_BROKEN && - *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) - add_damage(bhitpos.x, bhitpos.y, 0L); - } - break; - } - } - if(!ZAP_POS(typ) || (IS_DOOR(typ) && - (levl[bhitpos.x][bhitpos.y].doormask & (D_LOCKED | D_CLOSED))) - ) { - bhitpos.x -= ddx; - bhitpos.y -= ddy; - break; - } - } + for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp; + otmp = next_obj) { + /* Fix for polymorph bug, Tim Wright */ + next_obj = otmp->nexthere; + hitanything += (*fhito)(otmp, obj); + } + if (hitanything) + range--; + } + typ = levl[bhitpos.x][bhitpos.y].typ; + if (IS_DOOR(typ) || typ == SDOOR) { + switch (obj->otyp) { + /* note: monsters don't use opening or locking magic + at present, but keep these as placeholders */ + case WAN_OPENING: + case WAN_LOCKING: + case WAN_STRIKING: + if (doorlock(obj, bhitpos.x, bhitpos.y)) { + if (zap_oseen) + makeknown(obj->otyp); + /* if a shop door gets broken, add it to + the shk's fix list (no cost to player) */ + if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN + && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) + add_damage(bhitpos.x, bhitpos.y, 0L); + } + break; + } + } + if (!ZAP_POS(typ) + || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask + & (D_LOCKED | D_CLOSED)))) { + bhitpos.x -= ddx; + bhitpos.y -= ddy; + break; + } + } } /* Perform an offensive action for a monster. Must be called immediately @@ -1270,100 +1356,99 @@ int use_offensive(mtmp) struct monst *mtmp; { - int i; - struct obj *otmp = m.offensive; - boolean oseen; + int i; + struct obj *otmp = m.offensive; + boolean oseen; - /* offensive potions are not drunk, they're thrown */ - if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0) - return i; - oseen = otmp && canseemon(mtmp); + /* offensive potions are not drunk, they're thrown */ + if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0) + return i; + oseen = otmp && canseemon(mtmp); - switch(m.has_offense) { - case MUSE_WAN_DEATH: - case MUSE_WAN_SLEEP: - case MUSE_WAN_FIRE: - case MUSE_WAN_COLD: - case MUSE_WAN_LIGHTNING: - case MUSE_WAN_MAGIC_MISSILE: - mzapmsg(mtmp, otmp, FALSE); - otmp->spe--; - if (oseen) makeknown(otmp->otyp); - m_using = TRUE; - buzz((int)(-30 - (otmp->otyp - WAN_MAGIC_MISSILE)), - (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, - mtmp->mx, mtmp->my, - sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my)); - m_using = FALSE; - return (mtmp->mhp <= 0) ? 1 : 2; - case MUSE_FIRE_HORN: - case MUSE_FROST_HORN: - if (oseen) { - makeknown(otmp->otyp); - pline("%s plays a %s!", Monnam(mtmp), xname(otmp)); - } else - You_hear("a horn being played."); - otmp->spe--; - m_using = TRUE; - buzz(-30 - ((otmp->otyp==FROST_HORN) ? AD_COLD-1 : AD_FIRE-1), - rn1(6,6), mtmp->mx, mtmp->my, - sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my)); - m_using = FALSE; - return (mtmp->mhp <= 0) ? 1 : 2; - case MUSE_WAN_TELEPORTATION: - case MUSE_WAN_STRIKING: - zap_oseen = oseen; - mzapmsg(mtmp, otmp, FALSE); - otmp->spe--; - m_using = TRUE; - mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp); - m_using = FALSE; - return 2; - case MUSE_SCR_EARTH: - { - /* TODO: handle steeds */ - register int x, y; - /* don't use monster fields after killing it */ - boolean confused = (mtmp->mconf ? TRUE : FALSE); - int mmx = mtmp->mx, mmy = mtmp->my; + switch (m.has_offense) { + case MUSE_WAN_DEATH: + case MUSE_WAN_SLEEP: + case MUSE_WAN_FIRE: + case MUSE_WAN_COLD: + case MUSE_WAN_LIGHTNING: + case MUSE_WAN_MAGIC_MISSILE: + mzapmsg(mtmp, otmp, FALSE); + otmp->spe--; + if (oseen) + makeknown(otmp->otyp); + m_using = TRUE; + buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)), + (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my, + sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my)); + m_using = FALSE; + return (mtmp->mhp <= 0) ? 1 : 2; + case MUSE_FIRE_HORN: + case MUSE_FROST_HORN: + if (oseen) { + makeknown(otmp->otyp); + pline("%s plays a %s!", Monnam(mtmp), xname(otmp)); + } else + You_hear("a horn being played."); + otmp->spe--; + m_using = TRUE; + buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1), + rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), + sgn(mtmp->muy - mtmp->my)); + m_using = FALSE; + return (mtmp->mhp <= 0) ? 1 : 2; + case MUSE_WAN_TELEPORTATION: + case MUSE_WAN_STRIKING: + zap_oseen = oseen; + mzapmsg(mtmp, otmp, FALSE); + otmp->spe--; + m_using = TRUE; + mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); + m_using = FALSE; + return 2; + case MUSE_SCR_EARTH: { + /* TODO: handle steeds */ + register int x, y; + /* don't use monster fields after killing it */ + boolean confused = (mtmp->mconf ? TRUE : FALSE); + int mmx = mtmp->mx, mmy = mtmp->my; - mreadmsg(mtmp, otmp); - /* Identify the scroll */ - if (canspotmon(mtmp)) { - pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my), - otmp->blessed ? "around" : "above", - mon_nam(mtmp)); - if (oseen) makeknown(otmp->otyp); - } else if (cansee(mtmp->mx, mtmp->my)) { - pline_The("%s rumbles in the middle of nowhere!", - ceiling(mtmp->mx, mtmp->my)); - if (mtmp->minvis) - map_invisible(mtmp->mx, mtmp->my); - if (oseen) makeknown(otmp->otyp); - } + mreadmsg(mtmp, otmp); + /* Identify the scroll */ + if (canspotmon(mtmp)) { + pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my), + otmp->blessed ? "around" : "above", mon_nam(mtmp)); + if (oseen) + makeknown(otmp->otyp); + } else if (cansee(mtmp->mx, mtmp->my)) { + pline_The("%s rumbles in the middle of nowhere!", + ceiling(mtmp->mx, mtmp->my)); + if (mtmp->minvis) + map_invisible(mtmp->mx, mtmp->my); + if (oseen) + makeknown(otmp->otyp); + } - /* Loop through the surrounding squares */ - for (x = mmx-1; x <= mmx+1; x++) { - for (y = mmy-1; y <= mmy+1; y++) { - /* Is this a suitable spot? */ - if (isok(x, y) && !closed_door(x, y) && - !IS_ROCK(levl[x][y].typ) && - !IS_AIR(levl[x][y].typ) && - (((x == mmx) && (y == mmy)) ? - !otmp->blessed : !otmp->cursed) && - (x != u.ux || y != u.uy)) { - (void) drop_boulder_on_monster(x,y, confused, FALSE); - } - } - } - m_useup(mtmp, otmp); - /* Attack the player */ - if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !otmp->cursed) { - drop_boulder_on_player(confused, !otmp->cursed, FALSE, TRUE); - } + /* Loop through the surrounding squares */ + for (x = mmx - 1; x <= mmx + 1; x++) { + for (y = mmy - 1; y <= mmy + 1; y++) { + /* Is this a suitable spot? */ + if (isok(x, y) && !closed_door(x, y) + && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ) + && (((x == mmx) && (y == mmy)) ? !otmp->blessed + : !otmp->cursed) + && (x != u.ux || y != u.uy)) { + (void) drop_boulder_on_monster(x, y, confused, FALSE); + } + } + } + m_useup(mtmp, otmp); + /* Attack the player */ + if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !otmp->cursed) { + drop_boulder_on_player(confused, !otmp->cursed, FALSE, TRUE); + } - return (mtmp->mhp <= 0) ? 1 : 2; - } + return (mtmp->mhp <= 0) ? 1 : 2; + } #if 0 case MUSE_SCR_FIRE: { @@ -1407,67 +1492,81 @@ struct monst *mtmp; } return 2; } -#endif /* 0 */ - case MUSE_POT_PARALYSIS: - case MUSE_POT_BLINDNESS: - case MUSE_POT_CONFUSION: - case MUSE_POT_SLEEPING: - case MUSE_POT_ACID: - /* Note: this setting of dknown doesn't suffice. A monster - * which is out of sight might throw and it hits something _in_ - * sight, a problem not existing with wands because wand rays - * are not objects. Also set dknown in mthrowu.c. - */ - if (cansee(mtmp->mx, mtmp->my)) { - otmp->dknown = 1; - pline("%s hurls %s!", Monnam(mtmp), - singular(otmp, doname)); - } - m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux-mtmp->mx), - sgn(mtmp->muy-mtmp->my), - distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy), otmp); - return 2; - case 0: return 0; /* i.e. an exploded wand */ - default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_offense); - break; - } - return 0; +#endif /* 0 */ + case MUSE_POT_PARALYSIS: + case MUSE_POT_BLINDNESS: + case MUSE_POT_CONFUSION: + case MUSE_POT_SLEEPING: + case MUSE_POT_ACID: + /* Note: this setting of dknown doesn't suffice. A monster + * which is out of sight might throw and it hits something _in_ + * sight, a problem not existing with wands because wand rays + * are not objects. Also set dknown in mthrowu.c. + */ + if (cansee(mtmp->mx, mtmp->my)) { + otmp->dknown = 1; + pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname)); + } + m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), + sgn(mtmp->muy - mtmp->my), + distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); + return 2; + case 0: + return 0; /* i.e. an exploded wand */ + default: + impossible("%s wanted to perform action %d?", Monnam(mtmp), + m.has_offense); + break; + } + return 0; } int rnd_offensive_item(mtmp) struct monst *mtmp; { - struct permonst *pm = mtmp->data; - int difficulty = monstr[(monsndx(pm))]; + struct permonst *pm = mtmp->data; + int difficulty = monstr[(monsndx(pm))]; - if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) - || pm->mlet == S_GHOST || pm->mlet == S_KOP) - return 0; - if (difficulty > 7 && !rn2(35)) return WAN_DEATH; - switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) { - case 0: { - struct obj *helmet = which_armor(mtmp, W_ARMH); + if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) + || pm->mlet == S_GHOST || pm->mlet == S_KOP) + return 0; + if (difficulty > 7 && !rn2(35)) + return WAN_DEATH; + switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) { + case 0: { + struct obj *helmet = which_armor(mtmp, W_ARMH); - if ((helmet && is_metallic(helmet)) || amorphous(pm) || passes_walls(pm) || noncorporeal(pm) || unsolid(pm)) - return SCR_EARTH; - } /* fall through */ - case 1: return WAN_STRIKING; - case 2: return POT_ACID; - case 3: return POT_CONFUSION; - case 4: return POT_BLINDNESS; - case 5: return POT_SLEEPING; - case 6: return POT_PARALYSIS; - case 7: case 8: - return WAN_MAGIC_MISSILE; - case 9: return WAN_SLEEP; - case 10: return WAN_FIRE; - case 11: return WAN_COLD; - case 12: return WAN_LIGHTNING; - } - /*NOTREACHED*/ - return 0; + if ((helmet && is_metallic(helmet)) || amorphous(pm) + || passes_walls(pm) || noncorporeal(pm) || unsolid(pm)) + return SCR_EARTH; + } /* fall through */ + case 1: + return WAN_STRIKING; + case 2: + return POT_ACID; + case 3: + return POT_CONFUSION; + case 4: + return POT_BLINDNESS; + case 5: + return POT_SLEEPING; + case 6: + return POT_PARALYSIS; + case 7: + case 8: + return WAN_MAGIC_MISSILE; + case 9: + return WAN_SLEEP; + case 10: + return WAN_FIRE; + case 11: + return WAN_COLD; + case 12: + return WAN_LIGHTNING; + } + /*NOTREACHED*/ + return 0; } #define MUSE_POT_GAIN_LEVEL 1 @@ -1484,122 +1583,120 @@ boolean find_misc(mtmp) struct monst *mtmp; { - register struct obj *obj; - struct permonst *mdat = mtmp->data; - int x = mtmp->mx, y = mtmp->my; - struct trap *t; - int xx, yy; - boolean immobile = (mdat->mmove == 0); - boolean stuck = (mtmp == u.ustuck); + register struct obj *obj; + struct permonst *mdat = mtmp->data; + int x = mtmp->mx, y = mtmp->my; + struct trap *t; + int xx, yy; + boolean immobile = (mdat->mmove == 0); + boolean stuck = (mtmp == u.ustuck); - m.misc = (struct obj *)0; - m.has_misc = 0; - if (is_animal(mdat) || mindless(mdat)) - return 0; - if (u.uswallow && stuck) return FALSE; + m.misc = (struct obj *) 0; + m.has_misc = 0; + if (is_animal(mdat) || mindless(mdat)) + return 0; + if (u.uswallow && stuck) + return FALSE; - /* We arbitrarily limit to times when a player is nearby for the - * same reason as Junior Pac-Man doesn't have energizers eaten until - * you can see them... - */ - if(dist2(x, y, mtmp->mux, mtmp->muy) > 36) - return FALSE; + /* We arbitrarily limit to times when a player is nearby for the + * same reason as Junior Pac-Man doesn't have energizers eaten until + * you can see them... + */ + if (dist2(x, y, mtmp->mux, mtmp->muy) > 36) + return FALSE; - if (!stuck && !immobile && - (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) { - boolean ignore_boulders = (verysmall(mdat) || - throws_rocks(mdat) || - passes_walls(mdat)); - for(xx = x-1; xx <= x+1; xx++) - for(yy = y-1; yy <= y+1; yy++) - if (isok(xx,yy) && (xx != u.ux || yy != u.uy)) - if (mdat != &mons[PM_GRID_BUG] || xx == x || yy == y) - if (/* (xx==x && yy==y) || */ !level.monsters[xx][yy]) - if ((t = t_at(xx, yy)) != 0 && - (ignore_boulders || !sobj_at(BOULDER, xx, yy)) - && !onscary(xx, yy, mtmp)) { - if (t->ttyp == POLY_TRAP) { - trapx = xx; - trapy = yy; - m.has_misc = MUSE_POLY_TRAP; - return TRUE; - } - } - } - if (nohands(mdat)) - return 0; + if (!stuck && !immobile && (mtmp->cham == NON_PM) + && monstr[monsndx(mdat)] < 6) { + boolean ignore_boulders = + (verysmall(mdat) || throws_rocks(mdat) || passes_walls(mdat)); + for (xx = x - 1; xx <= x + 1; xx++) + for (yy = y - 1; yy <= y + 1; yy++) + if (isok(xx, yy) && (xx != u.ux || yy != u.uy)) + if (mdat != &mons[PM_GRID_BUG] || xx == x || yy == y) + if (/* (xx==x && yy==y) || */ !level.monsters[xx][yy]) + if ((t = t_at(xx, yy)) != 0 + && (ignore_boulders + || !sobj_at(BOULDER, xx, yy)) + && !onscary(xx, yy, mtmp)) { + if (t->ttyp == POLY_TRAP) { + trapx = xx; + trapy = yy; + m.has_misc = MUSE_POLY_TRAP; + return TRUE; + } + } + } + if (nohands(mdat)) + return 0; -#define nomore(x) if(m.has_misc==x) continue; - for(obj=mtmp->minvent; obj; obj=obj->nobj) { - /* Monsters shouldn't recognize cursed items; this kludge is */ - /* necessary to prevent serious problems though... */ - if(obj->otyp == POT_GAIN_LEVEL && (!obj->cursed || - (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { - m.misc = obj; - m.has_misc = MUSE_POT_GAIN_LEVEL; - } - nomore(MUSE_BULLWHIP); - if (obj->otyp == BULLWHIP && !mtmp->mpeaceful && - /* the random test prevents whip-wielding - monster from attempting disarm every turn */ - uwep && !rn2(5) && obj == MON_WEP(mtmp) && - /* hero's location must be known and adjacent */ - mtmp->mux == u.ux && mtmp->muy == u.uy && - distu(mtmp->mx, mtmp->my) <= 2 && - /* don't bother if it can't work (this doesn't - prevent cursed weapons from being targetted) */ - (canletgo(uwep, "") || - (u.twoweap && canletgo(uswapwep, "")))) { - m.misc = obj; - m.has_misc = MUSE_BULLWHIP; - } - /* Note: peaceful/tame monsters won't make themselves - * invisible unless you can see them. Not really right, but... - */ - nomore(MUSE_WAN_MAKE_INVISIBLE); - if(obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && - !mtmp->minvis && !mtmp->invis_blkd && - (!mtmp->mpeaceful || See_invisible) && - (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_WAN_MAKE_INVISIBLE; - } - nomore(MUSE_POT_INVISIBILITY); - if(obj->otyp == POT_INVISIBILITY && - !mtmp->minvis && !mtmp->invis_blkd && - (!mtmp->mpeaceful || See_invisible) && - (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { - m.misc = obj; - m.has_misc = MUSE_POT_INVISIBILITY; - } - nomore(MUSE_WAN_SPEED_MONSTER); - if(obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 - && mtmp->mspeed != MFAST && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_WAN_SPEED_MONSTER; - } - nomore(MUSE_POT_SPEED); - if(obj->otyp == POT_SPEED && mtmp->mspeed != MFAST - && !mtmp->isgd) { - m.misc = obj; - m.has_misc = MUSE_POT_SPEED; - } - nomore(MUSE_WAN_POLYMORPH); - if(obj->otyp == WAN_POLYMORPH && obj->spe > 0 - && (mtmp->cham == NON_PM) - && monstr[monsndx(mdat)] < 6) { - m.misc = obj; - m.has_misc = MUSE_WAN_POLYMORPH; - } - nomore(MUSE_POT_POLYMORPH); - if(obj->otyp == POT_POLYMORPH - && (mtmp->cham == NON_PM) - && monstr[monsndx(mdat)] < 6) { - m.misc = obj; - m.has_misc = MUSE_POT_POLYMORPH; - } - } - return((boolean)(!!m.has_misc)); +#define nomore(x) \ + if (m.has_misc == x) \ + continue; + for (obj = mtmp->minvent; obj; obj = obj->nobj) { + /* Monsters shouldn't recognize cursed items; this kludge is */ + /* necessary to prevent serious problems though... */ + if (obj->otyp == POT_GAIN_LEVEL + && (!obj->cursed + || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { + m.misc = obj; + m.has_misc = MUSE_POT_GAIN_LEVEL; + } + nomore(MUSE_BULLWHIP); + if (obj->otyp == BULLWHIP && !mtmp->mpeaceful && + /* the random test prevents whip-wielding + monster from attempting disarm every turn */ + uwep && !rn2(5) && obj == MON_WEP(mtmp) && + /* hero's location must be known and adjacent */ + mtmp->mux == u.ux && mtmp->muy == u.uy + && distu(mtmp->mx, mtmp->my) <= 2 && + /* don't bother if it can't work (this doesn't + prevent cursed weapons from being targetted) */ + (canletgo(uwep, "") || (u.twoweap && canletgo(uswapwep, "")))) { + m.misc = obj; + m.has_misc = MUSE_BULLWHIP; + } + /* Note: peaceful/tame monsters won't make themselves + * invisible unless you can see them. Not really right, but... + */ + nomore(MUSE_WAN_MAKE_INVISIBLE); + if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis + && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) + && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { + m.misc = obj; + m.has_misc = MUSE_WAN_MAKE_INVISIBLE; + } + nomore(MUSE_POT_INVISIBILITY); + if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis + && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) + && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { + m.misc = obj; + m.has_misc = MUSE_POT_INVISIBILITY; + } + nomore(MUSE_WAN_SPEED_MONSTER); + if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 + && mtmp->mspeed != MFAST && !mtmp->isgd) { + m.misc = obj; + m.has_misc = MUSE_WAN_SPEED_MONSTER; + } + nomore(MUSE_POT_SPEED); + if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) { + m.misc = obj; + m.has_misc = MUSE_POT_SPEED; + } + nomore(MUSE_WAN_POLYMORPH); + if (obj->otyp == WAN_POLYMORPH && obj->spe > 0 + && (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) { + m.misc = obj; + m.has_misc = MUSE_WAN_POLYMORPH; + } + nomore(MUSE_POT_POLYMORPH); + if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM) + && monstr[monsndx(mdat)] < 6) { + m.misc = obj; + m.has_misc = MUSE_POT_POLYMORPH; + } + } + return ((boolean)(!!m.has_misc)); #undef nomore } @@ -1609,269 +1706,283 @@ static struct permonst * muse_newcham_mon(mon) struct monst *mon; { - struct obj *m_armr; + struct obj *m_armr; - if ((m_armr = which_armor(mon, W_ARM)) != 0) { - if (Is_dragon_scales(m_armr)) - return Dragon_scales_to_pm(m_armr); - else if (Is_dragon_mail(m_armr)) - return Dragon_mail_to_pm(m_armr); - } - return rndmonst(); + if ((m_armr = which_armor(mon, W_ARM)) != 0) { + if (Is_dragon_scales(m_armr)) + return Dragon_scales_to_pm(m_armr); + else if (Is_dragon_mail(m_armr)) + return Dragon_mail_to_pm(m_armr); + } + return rndmonst(); } int use_misc(mtmp) struct monst *mtmp; { - int i; - struct obj *otmp = m.misc; - boolean vis, vismon, oseen; - char nambuf[BUFSZ]; + int i; + struct obj *otmp = m.misc; + boolean vis, vismon, oseen; + char nambuf[BUFSZ]; - if ((i = precheck(mtmp, otmp)) != 0) return i; - vis = cansee(mtmp->mx, mtmp->my); - vismon = canseemon(mtmp); - oseen = otmp && vismon; + if ((i = precheck(mtmp, otmp)) != 0) + return i; + vis = cansee(mtmp->mx, mtmp->my); + vismon = canseemon(mtmp); + oseen = otmp && vismon; - switch(m.has_misc) { - case MUSE_POT_GAIN_LEVEL: - mquaffmsg(mtmp, otmp); - if (otmp->cursed) { - if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) { - register int tolev = depth(&u.uz)-1; - d_level tolevel; + switch (m.has_misc) { + case MUSE_POT_GAIN_LEVEL: + mquaffmsg(mtmp, otmp); + if (otmp->cursed) { + if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) { + register int tolev = depth(&u.uz) - 1; + d_level tolevel; - get_level(&tolevel, tolev); - /* insurance against future changes... */ - if(on_level(&tolevel, &u.uz)) goto skipmsg; - if (vismon) { - pline("%s rises up, through the %s!", - Monnam(mtmp), ceiling(mtmp->mx, mtmp->my)); - if(!objects[POT_GAIN_LEVEL].oc_name_known - && !objects[POT_GAIN_LEVEL].oc_uname) - docall(otmp); - } - m_useup(mtmp, otmp); - migrate_to_level(mtmp, ledger_no(&tolevel), - MIGR_RANDOM, (coord *)0); - return 2; - } else { -skipmsg: - if (vismon) { - pline("%s looks uneasy.", Monnam(mtmp)); - if(!objects[POT_GAIN_LEVEL].oc_name_known - && !objects[POT_GAIN_LEVEL].oc_uname) - docall(otmp); - } - m_useup(mtmp, otmp); - return 2; - } - } - if (vismon) pline("%s seems more experienced.", Monnam(mtmp)); - if (oseen) makeknown(POT_GAIN_LEVEL); - m_useup(mtmp, otmp); - if (!grow_up(mtmp,(struct monst *)0)) return 1; - /* grew into genocided monster */ - return 2; - case MUSE_WAN_MAKE_INVISIBLE: - case MUSE_POT_INVISIBILITY: - if (otmp->otyp == WAN_MAKE_INVISIBLE) { - mzapmsg(mtmp, otmp, TRUE); - otmp->spe--; - } else - mquaffmsg(mtmp, otmp); - /* format monster's name before altering its visibility */ - Strcpy(nambuf, mon_nam(mtmp)); - mon_set_minvis(mtmp); - if (vismon && mtmp->minvis) { /* was seen, now invisible */ - if (canspotmon(mtmp)) - pline("%s body takes on a %s transparency.", - upstart(s_suffix(nambuf)), - Hallucination ? "normal" : "strange"); - else - pline("Suddenly you cannot see %s.", nambuf); - if (oseen) makeknown(otmp->otyp); - } - if (otmp->otyp == POT_INVISIBILITY) { - if (otmp->cursed) you_aggravate(mtmp); - m_useup(mtmp, otmp); - } - return 2; - case MUSE_WAN_SPEED_MONSTER: - mzapmsg(mtmp, otmp, TRUE); - otmp->spe--; - mon_adjust_speed(mtmp, 1, otmp); - return 2; - case MUSE_POT_SPEED: - mquaffmsg(mtmp, otmp); - /* note difference in potion effect due to substantially - different methods of maintaining speed ratings: - player's character becomes "very fast" temporarily; - monster becomes "one stage faster" permanently */ - mon_adjust_speed(mtmp, 1, otmp); - m_useup(mtmp, otmp); - return 2; - case MUSE_WAN_POLYMORPH: - mzapmsg(mtmp, otmp, TRUE); - otmp->spe--; - (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE); - if (oseen) makeknown(WAN_POLYMORPH); - return 2; - case MUSE_POT_POLYMORPH: - mquaffmsg(mtmp, otmp); - if (vismon) pline("%s suddenly mutates!", Monnam(mtmp)); - (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE); - if (oseen) makeknown(POT_POLYMORPH); - m_useup(mtmp, otmp); - return 2; - case MUSE_POLY_TRAP: - if (vismon) - pline("%s deliberately %s onto a polymorph trap!", - Monnam(mtmp), - makeplural(locomotion(mtmp->data, "jump"))); - if (vis) seetrap(t_at(trapx,trapy)); + get_level(&tolevel, tolev); + /* insurance against future changes... */ + if (on_level(&tolevel, &u.uz)) + goto skipmsg; + if (vismon) { + pline("%s rises up, through the %s!", Monnam(mtmp), + ceiling(mtmp->mx, mtmp->my)); + if (!objects[POT_GAIN_LEVEL].oc_name_known + && !objects[POT_GAIN_LEVEL].oc_uname) + docall(otmp); + } + m_useup(mtmp, otmp); + migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM, + (coord *) 0); + return 2; + } else { + skipmsg: + if (vismon) { + pline("%s looks uneasy.", Monnam(mtmp)); + if (!objects[POT_GAIN_LEVEL].oc_name_known + && !objects[POT_GAIN_LEVEL].oc_uname) + docall(otmp); + } + m_useup(mtmp, otmp); + return 2; + } + } + if (vismon) + pline("%s seems more experienced.", Monnam(mtmp)); + if (oseen) + makeknown(POT_GAIN_LEVEL); + m_useup(mtmp, otmp); + if (!grow_up(mtmp, (struct monst *) 0)) + return 1; + /* grew into genocided monster */ + return 2; + case MUSE_WAN_MAKE_INVISIBLE: + case MUSE_POT_INVISIBILITY: + if (otmp->otyp == WAN_MAKE_INVISIBLE) { + mzapmsg(mtmp, otmp, TRUE); + otmp->spe--; + } else + mquaffmsg(mtmp, otmp); + /* format monster's name before altering its visibility */ + Strcpy(nambuf, mon_nam(mtmp)); + mon_set_minvis(mtmp); + if (vismon && mtmp->minvis) { /* was seen, now invisible */ + if (canspotmon(mtmp)) + pline("%s body takes on a %s transparency.", + upstart(s_suffix(nambuf)), + Hallucination ? "normal" : "strange"); + else + pline("Suddenly you cannot see %s.", nambuf); + if (oseen) + makeknown(otmp->otyp); + } + if (otmp->otyp == POT_INVISIBILITY) { + if (otmp->cursed) + you_aggravate(mtmp); + m_useup(mtmp, otmp); + } + return 2; + case MUSE_WAN_SPEED_MONSTER: + mzapmsg(mtmp, otmp, TRUE); + otmp->spe--; + mon_adjust_speed(mtmp, 1, otmp); + return 2; + case MUSE_POT_SPEED: + mquaffmsg(mtmp, otmp); + /* note difference in potion effect due to substantially + different methods of maintaining speed ratings: + player's character becomes "very fast" temporarily; + monster becomes "one stage faster" permanently */ + mon_adjust_speed(mtmp, 1, otmp); + m_useup(mtmp, otmp); + return 2; + case MUSE_WAN_POLYMORPH: + mzapmsg(mtmp, otmp, TRUE); + otmp->spe--; + (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE); + if (oseen) + makeknown(WAN_POLYMORPH); + return 2; + case MUSE_POT_POLYMORPH: + mquaffmsg(mtmp, otmp); + if (vismon) + pline("%s suddenly mutates!", Monnam(mtmp)); + (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE); + if (oseen) + makeknown(POT_POLYMORPH); + m_useup(mtmp, otmp); + return 2; + case MUSE_POLY_TRAP: + if (vismon) + pline("%s deliberately %s onto a polymorph trap!", Monnam(mtmp), + makeplural(locomotion(mtmp->data, "jump"))); + if (vis) + seetrap(t_at(trapx, trapy)); - /* don't use rloc() due to worms */ - remove_monster(mtmp->mx, mtmp->my); - newsym(mtmp->mx, mtmp->my); - place_monster(mtmp, trapx, trapy); - if (mtmp->wormno) worm_move(mtmp); - newsym(trapx, trapy); + /* don't use rloc() due to worms */ + remove_monster(mtmp->mx, mtmp->my); + newsym(mtmp->mx, mtmp->my); + place_monster(mtmp, trapx, trapy); + if (mtmp->wormno) + worm_move(mtmp); + newsym(trapx, trapy); - (void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE); - return 2; - case MUSE_BULLWHIP: - /* attempt to disarm hero */ - { - const char *The_whip = vismon ? "The bullwhip" : "A whip"; - int where_to = rn2(4); - struct obj *obj = uwep; - const char *hand; - char the_weapon[BUFSZ]; + (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); + return 2; + case MUSE_BULLWHIP: + /* attempt to disarm hero */ + { + const char *The_whip = vismon ? "The bullwhip" : "A whip"; + int where_to = rn2(4); + struct obj *obj = uwep; + const char *hand; + char the_weapon[BUFSZ]; - if (!obj || !canletgo(obj, "") || - (u.twoweap && canletgo(uswapwep, "") && rn2(2))) - obj = uswapwep; - if (!obj) break; /* shouldn't happen after find_misc() */ + if (!obj || !canletgo(obj, "") + || (u.twoweap && canletgo(uswapwep, "") && rn2(2))) + obj = uswapwep; + if (!obj) + break; /* shouldn't happen after find_misc() */ - Strcpy(the_weapon, the(xname(obj))); - hand = body_part(HAND); - if (bimanual(obj)) hand = makeplural(hand); + Strcpy(the_weapon, the(xname(obj))); + hand = body_part(HAND); + if (bimanual(obj)) + hand = makeplural(hand); - if (vismon) - pline("%s flicks a bullwhip towards your %s!", - Monnam(mtmp), hand); - if (obj->otyp == HEAVY_IRON_BALL) { - pline("%s fails to wrap around %s.", - The_whip, the_weapon); - return 1; - } - pline("%s wraps around %s you're wielding!", - The_whip, the_weapon); - if (welded(obj)) { - pline("%s welded to your %s%c", - !is_plural(obj) ? "It is" : "They are", - hand, !obj->bknown ? '!' : '.'); - /* obj->bknown = 1; */ /* welded() takes care of this */ - where_to = 0; - } - if (!where_to) { - pline_The("whip slips free."); /* not `The_whip' */ - return 1; - } else if (where_to == 3 && mon_hates_silver(mtmp) && - objects[obj->otyp].oc_material == SILVER) { - /* this monster won't want to catch a silver - weapon; drop it at hero's feet instead */ - where_to = 2; - } - remove_worn_item(obj, FALSE); - freeinv(obj); - switch (where_to) { - case 1: /* onto floor beneath mon */ - pline("%s yanks %s from your %s!", Monnam(mtmp), - the_weapon, hand); - place_object(obj, mtmp->mx, mtmp->my); - break; - case 2: /* onto floor beneath you */ - pline("%s yanks %s to the %s!", Monnam(mtmp), - the_weapon, surface(u.ux, u.uy)); - dropy(obj); - break; - case 3: /* into mon's inventory */ - pline("%s snatches %s!", Monnam(mtmp), - the_weapon); - (void) mpickobj(mtmp,obj); - break; - } - return 1; - } - return 0; - case 0: return 0; /* i.e. an exploded wand */ - default: impossible("%s wanted to perform action %d?", Monnam(mtmp), - m.has_misc); - break; - } - return 0; + if (vismon) + pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp), + hand); + if (obj->otyp == HEAVY_IRON_BALL) { + pline("%s fails to wrap around %s.", The_whip, the_weapon); + return 1; + } + pline("%s wraps around %s you're wielding!", The_whip, + the_weapon); + if (welded(obj)) { + pline("%s welded to your %s%c", + !is_plural(obj) ? "It is" : "They are", hand, + !obj->bknown ? '!' : '.'); + /* obj->bknown = 1; */ /* welded() takes care of this */ + where_to = 0; + } + if (!where_to) { + pline_The("whip slips free."); /* not `The_whip' */ + return 1; + } else if (where_to == 3 && mon_hates_silver(mtmp) + && objects[obj->otyp].oc_material == SILVER) { + /* this monster won't want to catch a silver + weapon; drop it at hero's feet instead */ + where_to = 2; + } + remove_worn_item(obj, FALSE); + freeinv(obj); + switch (where_to) { + case 1: /* onto floor beneath mon */ + pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon, + hand); + place_object(obj, mtmp->mx, mtmp->my); + break; + case 2: /* onto floor beneath you */ + pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon, + surface(u.ux, u.uy)); + dropy(obj); + break; + case 3: /* into mon's inventory */ + pline("%s snatches %s!", Monnam(mtmp), the_weapon); + (void) mpickobj(mtmp, obj); + break; + } + return 1; + } + return 0; + case 0: + return 0; /* i.e. an exploded wand */ + default: + impossible("%s wanted to perform action %d?", Monnam(mtmp), + m.has_misc); + break; + } + return 0; } STATIC_OVL void you_aggravate(mtmp) struct monst *mtmp; { - pline("For some reason, %s presence is known to you.", - s_suffix(noit_mon_nam(mtmp))); - cls(); + pline("For some reason, %s presence is known to you.", + s_suffix(noit_mon_nam(mtmp))); + cls(); #ifdef CLIPPING - cliparound(mtmp->mx, mtmp->my); + cliparound(mtmp->mx, mtmp->my); #endif - show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp)); - display_self(); - You_feel("aggravated at %s.", noit_mon_nam(mtmp)); - display_nhwindow(WIN_MAP, TRUE); - docrt(); - if (unconscious()) { - multi = -1; - nomovemsg = - "Aggravated, you are jolted into full consciousness."; - } - newsym(mtmp->mx,mtmp->my); - if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); + show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp)); + display_self(); + You_feel("aggravated at %s.", noit_mon_nam(mtmp)); + display_nhwindow(WIN_MAP, TRUE); + docrt(); + if (unconscious()) { + multi = -1; + nomovemsg = "Aggravated, you are jolted into full consciousness."; + } + newsym(mtmp->mx, mtmp->my); + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); } int rnd_misc_item(mtmp) struct monst *mtmp; { - struct permonst *pm = mtmp->data; - int difficulty = monstr[(monsndx(pm))]; + struct permonst *pm = mtmp->data; + int difficulty = monstr[(monsndx(pm))]; - if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) - || pm->mlet == S_GHOST || pm->mlet == S_KOP) + if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) + || pm->mlet == S_GHOST || pm->mlet == S_KOP) + return 0; + /* Unlike other rnd_item functions, we only allow _weak_ monsters + * to have this item; after all, the item will be used to strengthen + * the monster and strong monsters won't use it at all... + */ + if (difficulty < 6 && !rn2(30)) + return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH; + + if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp)) + return AMULET_OF_LIFE_SAVING; + + switch (rn2(3)) { + case 0: + if (mtmp->isgd) return 0; - /* Unlike other rnd_item functions, we only allow _weak_ monsters - * to have this item; after all, the item will be used to strengthen - * the monster and strong monsters won't use it at all... - */ - if (difficulty < 6 && !rn2(30)) - return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH; - - if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp)) - return AMULET_OF_LIFE_SAVING; - - switch (rn2(3)) { - case 0: - if (mtmp->isgd) return 0; - return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER; - case 1: - if (mtmp->mpeaceful && !See_invisible) return 0; - return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE; - case 2: - return POT_GAIN_LEVEL; - } - /*NOTREACHED*/ - return 0; + return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER; + case 1: + if (mtmp->mpeaceful && !See_invisible) + return 0; + return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE; + case 2: + return POT_GAIN_LEVEL; + } + /*NOTREACHED*/ + return 0; } boolean @@ -1879,157 +1990,151 @@ searches_for_item(mon, obj) struct monst *mon; struct obj *obj; { - int typ = obj->otyp; + int typ = obj->otyp; - if (is_animal(mon->data) || - mindless(mon->data) || - mon->data == &mons[PM_GHOST]) /* don't loot bones piles */ - return FALSE; + if (is_animal(mon->data) || mindless(mon->data) + || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */ + return FALSE; - if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY) - return (boolean)(!mon->minvis && !mon->invis_blkd && !attacktype(mon->data, AT_GAZE)); - if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED) - return (boolean)(mon->mspeed != MFAST); + if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY) + return (boolean)(!mon->minvis && !mon->invis_blkd + && !attacktype(mon->data, AT_GAZE)); + if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED) + return (boolean)(mon->mspeed != MFAST); - switch (obj->oclass) { - case WAND_CLASS: - if (obj->spe <= 0) - return FALSE; - if (typ == WAN_DIGGING) - return (boolean)(!is_floater(mon->data)); - if (typ == WAN_POLYMORPH) - return (boolean)(monstr[monsndx(mon->data)] < 6); - if (objects[typ].oc_dir == RAY || - typ == WAN_STRIKING || - typ == WAN_TELEPORTATION || - typ == WAN_CREATE_MONSTER) - return TRUE; - break; - case POTION_CLASS: - if (typ == POT_HEALING || - typ == POT_EXTRA_HEALING || - typ == POT_FULL_HEALING || - typ == POT_POLYMORPH || - typ == POT_GAIN_LEVEL || - typ == POT_PARALYSIS || - typ == POT_SLEEPING || - typ == POT_ACID || - typ == POT_CONFUSION) - return TRUE; - if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE)) - return TRUE; - break; - case SCROLL_CLASS: - if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER || - typ == SCR_EARTH || typ == SCR_FIRE) - return TRUE; - break; - case AMULET_CLASS: - if (typ == AMULET_OF_LIFE_SAVING) - return (boolean)(!(nonliving(mon->data) || is_vampshifter(mon))); - if (typ == AMULET_OF_REFLECTION) - return TRUE; - break; - case TOOL_CLASS: - if (typ == PICK_AXE) - return (boolean)needspick(mon->data); - if (typ == UNICORN_HORN) - return (boolean)(!obj->cursed && !is_unicorn(mon->data)); - if (typ == FROST_HORN || typ == FIRE_HORN) - return (obj->spe > 0); - break; - case FOOD_CLASS: - if (typ == CORPSE) - return (boolean)(((mon->misc_worn_check & W_ARMG) && - touch_petrifies(&mons[obj->corpsenm])) || - (!resists_ston(mon) && - cures_stoning(mon, obj, FALSE))); - if (typ == TIN) - return (boolean)(mcould_eat_tin(mon) && - (!resists_ston(mon) && - cures_stoning(mon, obj, TRUE))); - if (typ == EGG) - return (boolean)(touch_petrifies(&mons[obj->corpsenm])); - break; - default: - break; - } + switch (obj->oclass) { + case WAND_CLASS: + if (obj->spe <= 0) + return FALSE; + if (typ == WAN_DIGGING) + return (boolean)(!is_floater(mon->data)); + if (typ == WAN_POLYMORPH) + return (boolean)(monstr[monsndx(mon->data)] < 6); + if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING + || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER) + return TRUE; + break; + case POTION_CLASS: + if (typ == POT_HEALING || typ == POT_EXTRA_HEALING + || typ == POT_FULL_HEALING || typ == POT_POLYMORPH + || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS + || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION) + return TRUE; + if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE)) + return TRUE; + break; + case SCROLL_CLASS: + if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER + || typ == SCR_EARTH || typ == SCR_FIRE) + return TRUE; + break; + case AMULET_CLASS: + if (typ == AMULET_OF_LIFE_SAVING) + return (boolean)(!(nonliving(mon->data) || is_vampshifter(mon))); + if (typ == AMULET_OF_REFLECTION) + return TRUE; + break; + case TOOL_CLASS: + if (typ == PICK_AXE) + return (boolean) needspick(mon->data); + if (typ == UNICORN_HORN) + return (boolean)(!obj->cursed && !is_unicorn(mon->data)); + if (typ == FROST_HORN || typ == FIRE_HORN) + return (obj->spe > 0); + break; + case FOOD_CLASS: + if (typ == CORPSE) + return (boolean)( + ((mon->misc_worn_check & W_ARMG) + && touch_petrifies(&mons[obj->corpsenm])) + || (!resists_ston(mon) && cures_stoning(mon, obj, FALSE))); + if (typ == TIN) + return (boolean)( + mcould_eat_tin(mon) + && (!resists_ston(mon) && cures_stoning(mon, obj, TRUE))); + if (typ == EGG) + return (boolean)(touch_petrifies(&mons[obj->corpsenm])); + break; + default: + break; + } - return FALSE; + return FALSE; } boolean -mon_reflects(mon,str) +mon_reflects(mon, str) struct monst *mon; const char *str; { - struct obj *orefl = which_armor(mon, W_ARMS); + struct obj *orefl = which_armor(mon, W_ARMS); - if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) { - if (str) { - pline(str, s_suffix(mon_nam(mon)), "shield"); - makeknown(SHIELD_OF_REFLECTION); - } - return TRUE; - } else if (arti_reflects(MON_WEP(mon))) { - /* due to wielded artifact weapon */ - if (str) - pline(str, s_suffix(mon_nam(mon)), "weapon"); - return TRUE; - } else if ((orefl = which_armor(mon, W_AMUL)) && - orefl->otyp == AMULET_OF_REFLECTION) { - if (str) { - pline(str, s_suffix(mon_nam(mon)), "amulet"); - makeknown(AMULET_OF_REFLECTION); - } - return TRUE; - } else if ((orefl = which_armor(mon, W_ARM)) && - (orefl->otyp == SILVER_DRAGON_SCALES || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) { - if (str) - pline(str, s_suffix(mon_nam(mon)), "armor"); - return TRUE; - } else if (mon->data == &mons[PM_SILVER_DRAGON] || - mon->data == &mons[PM_CHROMATIC_DRAGON]) { - /* Silver dragons only reflect when mature; babies do not */ - if (str) - pline(str, s_suffix(mon_nam(mon)), "scales"); - return TRUE; - } - return FALSE; + if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) { + if (str) { + pline(str, s_suffix(mon_nam(mon)), "shield"); + makeknown(SHIELD_OF_REFLECTION); + } + return TRUE; + } else if (arti_reflects(MON_WEP(mon))) { + /* due to wielded artifact weapon */ + if (str) + pline(str, s_suffix(mon_nam(mon)), "weapon"); + return TRUE; + } else if ((orefl = which_armor(mon, W_AMUL)) + && orefl->otyp == AMULET_OF_REFLECTION) { + if (str) { + pline(str, s_suffix(mon_nam(mon)), "amulet"); + makeknown(AMULET_OF_REFLECTION); + } + return TRUE; + } else if ((orefl = which_armor(mon, W_ARM)) + && (orefl->otyp == SILVER_DRAGON_SCALES + || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) { + if (str) + pline(str, s_suffix(mon_nam(mon)), "armor"); + return TRUE; + } else if (mon->data == &mons[PM_SILVER_DRAGON] + || mon->data == &mons[PM_CHROMATIC_DRAGON]) { + /* Silver dragons only reflect when mature; babies do not */ + if (str) + pline(str, s_suffix(mon_nam(mon)), "scales"); + return TRUE; + } + return FALSE; } boolean ureflects(fmt, str) const char *fmt, *str; { - /* Check from outermost to innermost objects */ - if (EReflecting & W_ARMS) { - if (fmt && str) { - pline(fmt, str, "shield"); - makeknown(SHIELD_OF_REFLECTION); - } - return TRUE; - } else if (EReflecting & W_WEP) { - /* Due to wielded artifact weapon */ - if (fmt && str) - pline(fmt, str, "weapon"); - return TRUE; - } else if (EReflecting & W_AMUL) { - if (fmt && str) { - pline(fmt, str, "medallion"); - makeknown(AMULET_OF_REFLECTION); - } - return TRUE; - } else if (EReflecting & W_ARM) { - if (fmt && str) - pline(fmt, str, uskin ? "luster" : "armor"); - return TRUE; - } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) { - if (fmt && str) - pline(fmt, str, "scales"); - return TRUE; - } - return FALSE; + /* Check from outermost to innermost objects */ + if (EReflecting & W_ARMS) { + if (fmt && str) { + pline(fmt, str, "shield"); + makeknown(SHIELD_OF_REFLECTION); + } + return TRUE; + } else if (EReflecting & W_WEP) { + /* Due to wielded artifact weapon */ + if (fmt && str) + pline(fmt, str, "weapon"); + return TRUE; + } else if (EReflecting & W_AMUL) { + if (fmt && str) { + pline(fmt, str, "medallion"); + makeknown(AMULET_OF_REFLECTION); + } + return TRUE; + } else if (EReflecting & W_ARM) { + if (fmt && str) + pline(fmt, str, uskin ? "luster" : "armor"); + return TRUE; + } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) { + if (fmt && str) + pline(fmt, str, "scales"); + return TRUE; + } + return FALSE; } /* TRUE if the monster ate something */ @@ -2038,21 +2143,23 @@ munstone(mon, by_you) struct monst *mon; boolean by_you; { - struct obj *obj; - boolean tinok; + struct obj *obj; + boolean tinok; - if (resists_ston(mon)) return FALSE; - if (mon->meating || !mon->mcanmove || mon->msleeping) return FALSE; - mon->mstrategy &= ~STRAT_WAITFORU; + if (resists_ston(mon)) + return FALSE; + if (mon->meating || !mon->mcanmove || mon->msleeping) + return FALSE; + mon->mstrategy &= ~STRAT_WAITFORU; - tinok = mcould_eat_tin(mon); - for (obj = mon->minvent; obj; obj = obj->nobj) { - if (cures_stoning(mon, obj, tinok)) { - mon_consume_unstone(mon, obj, by_you, TRUE); - return TRUE; - } - } - return FALSE; + tinok = mcould_eat_tin(mon); + for (obj = mon->minvent; obj; obj = obj->nobj) { + if (cures_stoning(mon, obj, tinok)) { + mon_consume_unstone(mon, obj, by_you, TRUE); + return TRUE; + } + } + return FALSE; } STATIC_OVL void @@ -2062,63 +2169,69 @@ struct obj *obj; boolean by_you; boolean stoning; { - boolean vis = canseemon(mon), - tinned = obj->otyp == TIN, - food = obj->otyp == CORPSE || tinned, - acid = obj->otyp == POT_ACID || (food && acidic(&mons[obj->corpsenm])), - lizard = food && obj->corpsenm == PM_LIZARD; - int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */ + boolean vis = canseemon(mon), tinned = obj->otyp == TIN, + food = obj->otyp == CORPSE || tinned, + acid = obj->otyp == POT_ACID + || (food && acidic(&mons[obj->corpsenm])), + lizard = food && obj->corpsenm == PM_LIZARD; + int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */ /* give a " is slowing down" message and also remove intrinsic speed (comparable to similar effect on the hero) */ - if (stoning) mon_adjust_speed(mon, -3, (struct obj *)0); + if (stoning) + mon_adjust_speed(mon, -3, (struct obj *) 0); if (vis) { - long save_quan = obj->quan; + long save_quan = obj->quan; - obj->quan = 1L; - pline("%s %s %s.", Monnam(mon), - (obj->oclass == POTION_CLASS) ? "quaffs" : - (obj->otyp == TIN) ? "opens and eats the contents of" : - "eats", - distant_name(obj, doname)); - obj->quan = save_quan; + obj->quan = 1L; + pline("%s %s %s.", Monnam(mon), + (obj->oclass == POTION_CLASS) + ? "quaffs" + : (obj->otyp == TIN) ? "opens and eats the contents of" + : "eats", + distant_name(obj, doname)); + obj->quan = save_quan; } else if (!Deaf) - You_hear("%s.", (obj->oclass == POTION_CLASS) ? "drinking" : "chewing"); + You_hear("%s.", + (obj->oclass == POTION_CLASS) ? "drinking" : "chewing"); m_useup(mon, obj); /* obj is now gone */ if (acid && !tinned && !resists_acid(mon)) { - mon->mhp -= rnd(15); - if (vis) - pline("%s has a very bad case of stomach acid.", Monnam(mon)); - if (mon->mhp <= 0) { - pline("%s dies!", Monnam(mon)); - if (by_you) xkilled(mon, 0); - else mondead(mon); - return; - } + mon->mhp -= rnd(15); + if (vis) + pline("%s has a very bad case of stomach acid.", Monnam(mon)); + if (mon->mhp <= 0) { + pline("%s dies!", Monnam(mon)); + if (by_you) + xkilled(mon, 0); + else + mondead(mon); + return; + } } if (stoning && vis) { - if (Hallucination) - pline("What a pity - %s just ruined a future piece of art!", - mon_nam(mon)); - else - pline("%s seems limber!", Monnam(mon)); + if (Hallucination) + pline("What a pity - %s just ruined a future piece of art!", + mon_nam(mon)); + else + pline("%s seems limber!", Monnam(mon)); } if (lizard && (mon->mconf || mon->mstun)) { - mon->mconf = 0; - mon->mstun = 0; - if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER]) - pline("%s seems steadier now.", Monnam(mon)); + mon->mconf = 0; + mon->mstun = 0; + if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER]) + pline("%s seems steadier now.", Monnam(mon)); } if (mon->mtame && !mon->isminion && nutrit > 0) { - struct edog *edog = EDOG(mon); + struct edog *edog = EDOG(mon); - if (edog->hungrytime < monstermoves) edog->hungrytime = monstermoves; - edog->hungrytime += nutrit; - mon->mconf = 0; + if (edog->hungrytime < monstermoves) + edog->hungrytime = monstermoves; + edog->hungrytime += nutrit; + mon->mconf = 0; } /* use up monster's next move */ mon->movement -= NORMAL_SPEED; @@ -2132,39 +2245,45 @@ struct monst *mon; struct obj *obj; boolean tinok; { - if (obj->otyp == POT_ACID) return TRUE; - if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok)) return FALSE; + if (obj->otyp == POT_ACID) + return TRUE; + if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok)) + return FALSE; /* corpse, or tin that mon can open */ - return (boolean)(obj->corpsenm == PM_LIZARD || - (acidic(&mons[obj->corpsenm]) && - (obj->corpsenm != PM_GREEN_SLIME || slimeproof(mon->data)))); + return (boolean)( + obj->corpsenm == PM_LIZARD + || (acidic(&mons[obj->corpsenm]) + && (obj->corpsenm != PM_GREEN_SLIME || slimeproof(mon->data)))); } STATIC_OVL boolean mcould_eat_tin(mon) struct monst *mon; { - struct obj *obj, *mwep; - boolean welded_wep; + struct obj *obj, *mwep; + boolean welded_wep; - /* monkeys who manage to steal tins can't open and eat them - even if they happen to also have the appropriate tool */ - if (is_animal(mon->data)) return FALSE; + /* monkeys who manage to steal tins can't open and eat them + even if they happen to also have the appropriate tool */ + if (is_animal(mon->data)) + return FALSE; - mwep = MON_WEP(mon); - welded_wep = mwep && mwelded(mwep); - /* this is different from the player; tin opener or dagger doesn't - have to be wielded, and knife can be used instead of dagger */ - for (obj = mon->minvent; obj; obj = obj->nobj) { - /* if stuck with a cursed weapon, don't check rest of inventory */ - if (welded_wep && obj != mwep) continue; + mwep = MON_WEP(mon); + welded_wep = mwep && mwelded(mwep); + /* this is different from the player; tin opener or dagger doesn't + have to be wielded, and knife can be used instead of dagger */ + for (obj = mon->minvent; obj; obj = obj->nobj) { + /* if stuck with a cursed weapon, don't check rest of inventory */ + if (welded_wep && obj != mwep) + continue; - if (obj->otyp == TIN_OPENER || - (obj->oclass == WEAPON_CLASS && - (objects[obj->otyp].oc_skill == P_DAGGER || - objects[obj->otyp].oc_skill == P_KNIFE))) return TRUE; - } - return FALSE; + if (obj->otyp == TIN_OPENER + || (obj->oclass == WEAPON_CLASS + && (objects[obj->otyp].oc_skill == P_DAGGER + || objects[obj->otyp].oc_skill == P_KNIFE))) + return TRUE; + } + return FALSE; } /* TRUE if monster does something to avoid turning into green slime */ @@ -2182,8 +2301,10 @@ boolean by_you; * (via our caller) newcham()'s "mon turns into slime" feedback. */ - if (slimeproof(mon->data)) return FALSE; - if (mon->meating || !mon->mcanmove || mon->msleeping) return FALSE; + if (slimeproof(mon->data)) + return FALSE; + if (mon->meating || !mon->mcanmove || mon->msleeping) + return FALSE; mon->mstrategy &= ~STRAT_WAITFORU; /* if monster can breathe fire, do so upon self; a monster who deals @@ -2191,15 +2312,15 @@ boolean by_you; isn't able to cure itself of green slime with its own attack [possible extension: monst capable of casting high level clerical spells could toss pillar of fire at self--probably too suicidal] */ - if (!mon->mcan && !mon->mspec_used && - attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) { - odummy = zeroobj; /* otyp == STRANGE_OBJECT */ - return muse_unslime(mon, &odummy, by_you); + if (!mon->mcan && !mon->mspec_used + && attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) { + odummy = zeroobj; /* otyp == STRANGE_OBJECT */ + return muse_unslime(mon, &odummy, by_you); } for (obj = mon->minvent; obj; obj = obj->nobj) - if (cures_sliming(mon, obj)) - return muse_unslime(mon, obj, by_you); + if (cures_sliming(mon, obj)) + return muse_unslime(mon, obj, by_you); /* TODO: check for and move onto an adjacent fire trap */ @@ -2211,54 +2332,57 @@ STATIC_OVL boolean muse_unslime(mon, obj, by_you) struct monst *mon; struct obj *obj; -boolean by_you; /* true: if mon kills itself, hero gets credit/blame */ +boolean by_you; /* true: if mon kills itself, hero gets credit/blame */ { struct obj *odummyp; int otyp = obj->otyp, dmg; boolean vis = canseemon(mon), res = TRUE; if (vis) - pline("%s starts turning %s.", Monnam(mon), - green_mon(mon) ? "into ooze" : hcolor(NH_GREEN)); + pline("%s starts turning %s.", Monnam(mon), + green_mon(mon) ? "into ooze" : hcolor(NH_GREEN)); /* -4 => sliming, causes quiet loss of enhanced speed */ - mon_adjust_speed(mon, -4, (struct obj *)0); + mon_adjust_speed(mon, -4, (struct obj *) 0); if (otyp == STRANGE_OBJECT) { - /* monster is using fire breath on self */ - if (vis) - pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon)); - if (!rn2(3)) mon->mspec_used = rn1(10, 5); - /* -21 => monster's fire breath; 1 => # of damage dice */ - (void)zhitm(mon, by_you ? 21 : -21, 1, &odummyp); + /* monster is using fire breath on self */ + if (vis) + pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon)); + if (!rn2(3)) + mon->mspec_used = rn1(10, 5); + /* -21 => monster's fire breath; 1 => # of damage dice */ + (void) zhitm(mon, by_you ? 21 : -21, 1, &odummyp); } else if (otyp == SCR_FIRE) { - mreadmsg(mon, obj); - if (mon->mconf) { - if (cansee(mon->mx, mon->my)) - pline("Oh, what a pretty fire!"); - if (vis && !objects[otyp].oc_name_known && !objects[otyp].oc_uname) - docall(obj); - m_useup(mon, obj); /* after docall() */ - vis = FALSE; /* skip makeknown() below */ - res = FALSE; /* failed to cure sliming */ - } else { - m_useup(mon, obj); /* before explode() */ - dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3; - /* -11 => monster's fireball */ - explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS, - /* by_you: override -11 for mon but not others */ - by_you ? -EXPL_FIERY : EXPL_FIERY); - } - } else { /* wand/horn of fire w/ positive charge count */ - mzapmsg(mon, obj, TRUE); - obj->spe--; - /* -1 => monster's wand of fire; 2 => # of damage dice */ - (void)zhitm(mon, by_you ? 1 : -1, 2, &odummyp); + mreadmsg(mon, obj); + if (mon->mconf) { + if (cansee(mon->mx, mon->my)) + pline("Oh, what a pretty fire!"); + if (vis && !objects[otyp].oc_name_known + && !objects[otyp].oc_uname) + docall(obj); + m_useup(mon, obj); /* after docall() */ + vis = FALSE; /* skip makeknown() below */ + res = FALSE; /* failed to cure sliming */ + } else { + m_useup(mon, obj); /* before explode() */ + dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3; + /* -11 => monster's fireball */ + explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS, + /* by_you: override -11 for mon but not others */ + by_you ? -EXPL_FIERY : EXPL_FIERY); + } + } else { /* wand/horn of fire w/ positive charge count */ + mzapmsg(mon, obj, TRUE); + obj->spe--; + /* -1 => monster's wand of fire; 2 => # of damage dice */ + (void) zhitm(mon, by_you ? 1 : -1, 2, &odummyp); } if (vis) { - if (res && mon->mhp > 0) - pline("%s slime is burned away!", s_suffix(Monnam(mon))); - if (otyp != STRANGE_OBJECT) makeknown(otyp); + if (res && mon->mhp > 0) + pline("%s slime is burned away!", s_suffix(Monnam(mon))); + if (otyp != STRANGE_OBJECT) + makeknown(otyp); } /* use up monster's next move */ mon->movement -= NORMAL_SPEED; @@ -2274,9 +2398,10 @@ struct obj *obj; { /* scroll of fire, non-empty wand or horn of fire */ if (obj->otyp == SCR_FIRE) - return (haseyes(mon->data) && mon->mcansee); + return (haseyes(mon->data) && mon->mcansee); /* hero doesn't need hands or even limbs to zap, so mon doesn't either */ - return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN) && obj->spe > 0); + return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN) + && obj->spe > 0); } /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by @@ -2288,13 +2413,15 @@ struct monst *mon; { struct permonst *ptr = mon->data; - if (Hallucination) return FALSE; + if (Hallucination) + return FALSE; #ifdef TEXTCOLOR if (iflags.use_color) - return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN); + return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN); #endif /* approximation */ - if (strstri(ptr->mname, "green")) return TRUE; + if (strstri(ptr->mname, "green")) + return TRUE; switch (monsndx(ptr)) { case PM_FOREST_CENTAUR: case PM_GARTER_SNAKE: @@ -2306,11 +2433,12 @@ struct monst *mon; case PM_LICHEN: case PM_LIZARD: case PM_WOOD_NYMPH: - return TRUE; + return TRUE; default: - if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr) && - ptr != &mons[PM_GREY_ELF]) return TRUE; - break; + if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr) + && ptr != &mons[PM_GREY_ELF]) + return TRUE; + break; } return FALSE; } diff --git a/src/music.c b/src/music.c index 01b103a35..12605843b 100644 --- a/src/music.c +++ b/src/music.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 music.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 music.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.37 $ */ /* NetHack 3.6 music.c $Date: 2011/12/30 23:47:06 $ $Revision: 1.27 $ */ /* Copyright (c) 1989 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,7 +12,8 @@ * (wooden) flute may calm snakes if player has enough dexterity * magic flute may put monsters to sleep: area of effect depends * on player level. - * (tooled) horn Will awaken monsters: area of effect depends on player + * (tooled) horn Will awaken monsters: area of effect depends on + *player * level. May also scare monsters. * fire horn Acts like a wand of fire. * frost horn Acts like a wand of cold. @@ -29,29 +30,29 @@ #include "hack.h" -STATIC_DCL void FDECL(awaken_monsters,(int)); -STATIC_DCL void FDECL(put_monsters_to_sleep,(int)); -STATIC_DCL void FDECL(charm_snakes,(int)); -STATIC_DCL void FDECL(calm_nymphs,(int)); -STATIC_DCL void FDECL(charm_monsters,(int)); -STATIC_DCL void FDECL(do_earthquake,(int)); -STATIC_DCL int FDECL(do_improvisation,(struct obj *)); +STATIC_DCL void FDECL(awaken_monsters, (int)); +STATIC_DCL void FDECL(put_monsters_to_sleep, (int)); +STATIC_DCL void FDECL(charm_snakes, (int)); +STATIC_DCL void FDECL(calm_nymphs, (int)); +STATIC_DCL void FDECL(charm_monsters, (int)); +STATIC_DCL void FDECL(do_earthquake, (int)); +STATIC_DCL int FDECL(do_improvisation, (struct obj *)); #ifdef UNIX386MUSIC STATIC_DCL int NDECL(atconsole); -STATIC_DCL void FDECL(speaker,(struct obj *,char *)); +STATIC_DCL void FDECL(speaker, (struct obj *, char *)); #endif #ifdef VPIX_MUSIC -extern int sco_flag_console; /* will need changing if not _M_UNIX */ +extern int sco_flag_console; /* will need changing if not _M_UNIX */ STATIC_DCL void NDECL(playinit); -STATIC_DCL void FDECL(playstring, (char *,size_t)); -STATIC_DCL void FDECL(speaker,(struct obj *,char *)); +STATIC_DCL void FDECL(playstring, (char *, size_t)); +STATIC_DCL void FDECL(speaker, (struct obj *, char *)); #endif #ifdef PCMUSIC -void FDECL( pc_speaker, ( struct obj *, char * ) ); +void FDECL(pc_speaker, (struct obj *, char *)); #endif #ifdef AMIGA -void FDECL( amii_speaker, ( struct obj *, char *, int ) ); +void FDECL(amii_speaker, (struct obj *, char *, int)); #endif /* @@ -62,23 +63,24 @@ STATIC_OVL void awaken_monsters(distance) int distance; { - register struct monst *mtmp; - register int distm; + register struct monst *mtmp; + register int distm; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((distm = distu(mtmp->mx, mtmp->my)) < distance) { - mtmp->msleeping = 0; - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - /* may scare some monsters -- waiting monsters excluded */ - if ((mtmp->mstrategy & STRAT_WAITMASK) != 0) - mtmp->mstrategy &= ~STRAT_WAITMASK; - else if (distm < distance/3 && - !resist(mtmp, TOOL_CLASS, 0, NOTELL)) - monflee(mtmp, 0, FALSE, TRUE); - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((distm = distu(mtmp->mx, mtmp->my)) < distance) { + mtmp->msleeping = 0; + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + /* may scare some monsters -- waiting monsters excluded */ + if ((mtmp->mstrategy & STRAT_WAITMASK) != 0) + mtmp->mstrategy &= ~STRAT_WAITMASK; + else if (distm < distance / 3 + && !resist(mtmp, TOOL_CLASS, 0, NOTELL)) + monflee(mtmp, 0, FALSE, TRUE); + } + } } /* @@ -89,16 +91,17 @@ STATIC_OVL void put_monsters_to_sleep(distance) int distance; { - register struct monst *mtmp; + register struct monst *mtmp; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (distu(mtmp->mx, mtmp->my) < distance && - sleep_monst(mtmp, d(10,10), TOOL_CLASS)) { - mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */ - slept_monst(mtmp); - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (distu(mtmp->mx, mtmp->my) < distance + && sleep_monst(mtmp, d(10, 10), TOOL_CLASS)) { + mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */ + slept_monst(mtmp); + } + } } /* @@ -109,31 +112,31 @@ STATIC_OVL void charm_snakes(distance) int distance; { - register struct monst *mtmp; - int could_see_mon, was_peaceful; + register struct monst *mtmp; + int could_see_mon, was_peaceful; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->data->mlet == S_SNAKE && mtmp->mcanmove && - distu(mtmp->mx, mtmp->my) < distance) { - was_peaceful = mtmp->mpeaceful; - mtmp->mpeaceful = 1; - mtmp->mavenge = 0; - mtmp->mstrategy &= ~STRAT_WAITMASK; - could_see_mon = canseemon(mtmp); - mtmp->mundetected = 0; - newsym(mtmp->mx, mtmp->my); - if (canseemon(mtmp)) { - if (!could_see_mon) - You("notice %s, swaying with the music.", - a_monnam(mtmp)); - else - pline("%s freezes, then sways with the music%s.", - Monnam(mtmp), - was_peaceful ? "" : ", and now seems quieter"); - } - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->data->mlet == S_SNAKE && mtmp->mcanmove + && distu(mtmp->mx, mtmp->my) < distance) { + was_peaceful = mtmp->mpeaceful; + mtmp->mpeaceful = 1; + mtmp->mavenge = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; + could_see_mon = canseemon(mtmp); + mtmp->mundetected = 0; + newsym(mtmp->mx, mtmp->my); + if (canseemon(mtmp)) { + if (!could_see_mon) + You("notice %s, swaying with the music.", a_monnam(mtmp)); + else + pline("%s freezes, then sways with the music%s.", + Monnam(mtmp), + was_peaceful ? "" : ", and now seems quieter"); + } + } + } } /* @@ -144,61 +147,62 @@ STATIC_OVL void calm_nymphs(distance) int distance; { - register struct monst *mtmp; + register struct monst *mtmp; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->data->mlet == S_NYMPH && mtmp->mcanmove && - distu(mtmp->mx, mtmp->my) < distance) { - mtmp->msleeping = 0; - mtmp->mpeaceful = 1; - mtmp->mavenge = 0; - mtmp->mstrategy &= ~STRAT_WAITMASK; - if (canseemon(mtmp)) - pline( - "%s listens cheerfully to the music, then seems quieter.", - Monnam(mtmp)); - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->data->mlet == S_NYMPH && mtmp->mcanmove + && distu(mtmp->mx, mtmp->my) < distance) { + mtmp->msleeping = 0; + mtmp->mpeaceful = 1; + mtmp->mavenge = 0; + mtmp->mstrategy &= ~STRAT_WAITMASK; + if (canseemon(mtmp)) + pline( + "%s listens cheerfully to the music, then seems quieter.", + Monnam(mtmp)); + } + } } /* Awake soldiers anywhere the level (and any nearby monster). */ void awaken_soldiers(bugler) - struct monst *bugler; /* monster that played instrument */ +struct monst *bugler; /* monster that played instrument */ { - register struct monst *mtmp; - int distance, distm; + register struct monst *mtmp; + int distance, distm; - /* distance of affected non-soldier monsters to bugler */ - distance = ((bugler == &youmonst) ? - u.ulevel : bugler->data->mlevel) * 30; + /* distance of affected non-soldier monsters to bugler */ + distance = ((bugler == &youmonst) ? u.ulevel : bugler->data->mlevel) * 30; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) { - mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0; - mtmp->mcanmove = 1; - mtmp->mstrategy &= ~STRAT_WAITMASK; - if (canseemon(mtmp)) - pline("%s is now ready for battle!", Monnam(mtmp)); - else - Norep("You hear the rattle of battle gear being readied."); - } else if ((distm = ((bugler == &youmonst) ? - distu(mtmp->mx, mtmp->my) : - dist2(bugler->mx, bugler->my, mtmp->mx, mtmp->my))) - < distance) { - mtmp->msleeping = 0; - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - /* may scare some monsters -- waiting monsters excluded */ - if ((mtmp->mstrategy & STRAT_WAITMASK) != 0) - mtmp->mstrategy &= ~STRAT_WAITMASK; - else if (distm < distance/3 && - !resist(mtmp, TOOL_CLASS, 0, NOTELL)) - monflee(mtmp, 0, FALSE, TRUE); - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) { + mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0; + mtmp->mcanmove = 1; + mtmp->mstrategy &= ~STRAT_WAITMASK; + if (canseemon(mtmp)) + pline("%s is now ready for battle!", Monnam(mtmp)); + else + Norep("You hear the rattle of battle gear being readied."); + } else if ((distm = ((bugler == &youmonst) + ? distu(mtmp->mx, mtmp->my) + : dist2(bugler->mx, bugler->my, mtmp->mx, + mtmp->my))) < distance) { + mtmp->msleeping = 0; + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + /* may scare some monsters -- waiting monsters excluded */ + if ((mtmp->mstrategy & STRAT_WAITMASK) != 0) + mtmp->mstrategy &= ~STRAT_WAITMASK; + else if (distm < distance / 3 + && !resist(mtmp, TOOL_CLASS, 0, NOTELL)) + monflee(mtmp, 0, FALSE, TRUE); + } + } } /* Charm monsters in range. Note that they may resist the spell. @@ -209,23 +213,23 @@ STATIC_OVL void charm_monsters(distance) int distance; { - struct monst *mtmp, *mtmp2; + struct monst *mtmp, *mtmp2; - if (u.uswallow) { - if (!resist(u.ustuck, TOOL_CLASS, 0, NOTELL)) - (void) tamedog(u.ustuck, (struct obj *) 0); - } else { - for (mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if (DEADMONSTER(mtmp)) continue; - - if (distu(mtmp->mx, mtmp->my) <= distance) { - if (!resist(mtmp, TOOL_CLASS, 0, NOTELL)) - (void) tamedog(mtmp, (struct obj *) 0); - } - } - } + if (u.uswallow) { + if (!resist(u.ustuck, TOOL_CLASS, 0, NOTELL)) + (void) tamedog(u.ustuck, (struct obj *) 0); + } else { + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (DEADMONSTER(mtmp)) + continue; + if (distu(mtmp->mx, mtmp->my) <= distance) { + if (!resist(mtmp, TOOL_CLASS, 0, NOTELL)) + (void) tamedog(mtmp, (struct obj *) 0); + } + } + } } /* Generate earthquake :-) of desired force. @@ -236,176 +240,193 @@ STATIC_OVL void do_earthquake(force) int force; { - register int x,y; - struct monst *mtmp; - struct obj *otmp; - struct trap *chasm, *trap_at_u = t_at(u.ux, u.uy); - int start_x, start_y, end_x, end_y; - schar filltype; - unsigned tu_pit = 0; + register int x, y; + struct monst *mtmp; + struct obj *otmp; + struct trap *chasm, *trap_at_u = t_at(u.ux, u.uy); + int start_x, start_y, end_x, end_y; + schar filltype; + unsigned tu_pit = 0; - if (trap_at_u) - tu_pit = (trap_at_u->ttyp == PIT || trap_at_u->ttyp ==SPIKED_PIT); - start_x = u.ux - (force * 2); - start_y = u.uy - (force * 2); - end_x = u.ux + (force * 2); - end_y = u.uy + (force * 2); - if (start_x < 1) start_x = 1; - if (start_y < 1) start_y = 1; - if (end_x >= COLNO) end_x = COLNO - 1; - if (end_y >= ROWNO) end_y = ROWNO - 1; - for (x=start_x; x<=end_x; x++) for (y=start_y; y<=end_y; y++) { - if ((mtmp = m_at(x,y)) != 0) { - wakeup(mtmp); /* peaceful monster will become hostile */ - if (mtmp->mundetected && is_hider(mtmp->data)) { - mtmp->mundetected = 0; - if (cansee(x,y)) - pline("%s is shaken loose from the ceiling!", - Amonnam(mtmp)); - else - You_hear("a thumping sound."); - if (x==u.ux && y==u.uy) - You("easily dodge the falling %s.", - mon_nam(mtmp)); - newsym(x,y); - } - } - if (!rn2(14 - force)) switch (levl[x][y].typ) { - case FOUNTAIN : /* Make the fountain disappear */ - if (cansee(x,y)) - pline_The("fountain falls into a chasm."); - goto do_pit; - case SINK : - if (cansee(x,y)) - pline_The("kitchen sink falls into a chasm."); - goto do_pit; - case ALTAR : - if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) break; + if (trap_at_u) + tu_pit = (trap_at_u->ttyp == PIT || trap_at_u->ttyp == SPIKED_PIT); + start_x = u.ux - (force * 2); + start_y = u.uy - (force * 2); + end_x = u.ux + (force * 2); + end_y = u.uy + (force * 2); + if (start_x < 1) + start_x = 1; + if (start_y < 1) + start_y = 1; + if (end_x >= COLNO) + end_x = COLNO - 1; + if (end_y >= ROWNO) + end_y = ROWNO - 1; + for (x = start_x; x <= end_x; x++) + for (y = start_y; y <= end_y; y++) { + if ((mtmp = m_at(x, y)) != 0) { + wakeup(mtmp); /* peaceful monster will become hostile */ + if (mtmp->mundetected && is_hider(mtmp->data)) { + mtmp->mundetected = 0; + if (cansee(x, y)) + pline("%s is shaken loose from the ceiling!", + Amonnam(mtmp)); + else + You_hear("a thumping sound."); + if (x == u.ux && y == u.uy) + You("easily dodge the falling %s.", mon_nam(mtmp)); + newsym(x, y); + } + } + if (!rn2(14 - force)) + switch (levl[x][y].typ) { + case FOUNTAIN: /* Make the fountain disappear */ + if (cansee(x, y)) + pline_The("fountain falls into a chasm."); + goto do_pit; + case SINK: + if (cansee(x, y)) + pline_The("kitchen sink falls into a chasm."); + goto do_pit; + case ALTAR: + if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) + break; - if (cansee(x,y)) - pline_The("altar falls into a chasm."); - goto do_pit; - case GRAVE : - if (cansee(x,y)) - pline_The("headstone topples into a chasm."); - goto do_pit; - case THRONE : - if (cansee(x,y)) - pline_The("throne falls into a chasm."); - /* Falls into next case */ - case ROOM : - case CORR : /* Try to make a pit */ -do_pit: chasm = maketrap(x,y,PIT); - if (!chasm) break; /* no pit if portal at that location */ - chasm->tseen = 1; + if (cansee(x, y)) + pline_The("altar falls into a chasm."); + goto do_pit; + case GRAVE: + if (cansee(x, y)) + pline_The("headstone topples into a chasm."); + goto do_pit; + case THRONE: + if (cansee(x, y)) + pline_The("throne falls into a chasm."); + /* Falls into next case */ + case ROOM: + case CORR: /* Try to make a pit */ + do_pit: + chasm = maketrap(x, y, PIT); + if (!chasm) + break; /* no pit if portal at that location */ + chasm->tseen = 1; - levl[x][y].doormask = 0; - /* - * Let liquid flow into the newly created chasm. - * Adjust corresponding code in apply.c for - * exploding wand of digging if you alter this sequence. - */ - filltype = fillholetyp(x,y,FALSE); - if (filltype != ROOM) { - levl[x][y].typ = filltype; - liquid_flow(x, y, filltype, chasm, (char *)0); - } + levl[x][y].doormask = 0; + /* + * Let liquid flow into the newly created chasm. + * Adjust corresponding code in apply.c for + * exploding wand of digging if you alter this sequence. + */ + filltype = fillholetyp(x, y, FALSE); + if (filltype != ROOM) { + levl[x][y].typ = filltype; + liquid_flow(x, y, filltype, chasm, (char *) 0); + } - mtmp = m_at(x,y); + mtmp = m_at(x, y); - if ((otmp = sobj_at(BOULDER, x, y)) != 0) { - if (cansee(x, y)) - pline("KADOOM! The boulder falls into a chasm%s!", - ((x == u.ux) && (y == u.uy)) ? " below you" : ""); - if (mtmp) - mtmp->mtrapped = 0; - obj_extract_self(otmp); - (void) flooreffects(otmp, x, y, ""); - break; - } + if ((otmp = sobj_at(BOULDER, x, y)) != 0) { + if (cansee(x, y)) + pline("KADOOM! The boulder falls into a chasm%s!", + ((x == u.ux) && (y == u.uy)) ? " below you" + : ""); + if (mtmp) + mtmp->mtrapped = 0; + obj_extract_self(otmp); + (void) flooreffects(otmp, x, y, ""); + break; + } - /* We have to check whether monsters or player - falls in a chasm... */ + /* We have to check whether monsters or player + falls in a chasm... */ - if (mtmp) { - if(!is_flyer(mtmp->data) && !is_clinger(mtmp->data)) { - boolean m_already_trapped = mtmp->mtrapped; - mtmp->mtrapped = 1; - if (!m_already_trapped) { /* suppress messages */ - if(cansee(x,y)) - pline("%s falls into a chasm!", Monnam(mtmp)); - else if (humanoid(mtmp->data)) - You_hear("a scream!"); - } - /* Falling is okay for falling down - within a pit from jostling too */ - mselftouch(mtmp, "Falling, ", TRUE); - if (mtmp->mhp > 0) - if ((mtmp->mhp -= - rnd(m_already_trapped ? 4 : 6)) <= 0) { - if(!cansee(x,y)) - pline("It is destroyed!"); - else { - You("destroy %s!", mtmp->mtame ? - x_monnam(mtmp, ARTICLE_THE, "poor", - (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE): - mon_nam(mtmp)); - } - xkilled(mtmp,0); - } - } - } else if (x == u.ux && y == u.uy) { - if (Levitation || Flying || - is_clinger(youmonst.data)) { - if (!tu_pit) { /* no pit here previously */ - pline("A chasm opens up under you!"); - You("don't fall in!"); - } - } else if (!tu_pit || !u.utrap || - (u.utrap && u.utraptype != TT_PIT)) { - /* no pit here previously, or you were - not in it even it there was */ - You("fall into a chasm!"); - u.utrap = rn1(6,2); - u.utraptype = TT_PIT; - losehp(Maybe_Half_Phys(rnd(6)), - "fell into a chasm", - NO_KILLER_PREFIX); - selftouch("Falling, you"); - } else if (u.utrap && u.utraptype == TT_PIT) { - boolean keepfooting = ( - (Fumbling && !rn2(5)) || - (!rnl(Role_if(PM_ARCHEOLOGIST) ? 3 : 9)) || - ((ACURR(A_DEX) > 7) && rn2(5))); - You("are jostled around violently!"); - u.utrap = rn1(6,2); - u.utraptype = TT_PIT; /* superfluous */ - losehp(Maybe_Half_Phys( - rnd(keepfooting ? 2 : 4)), - "hurt in a chasm", - NO_KILLER_PREFIX); - if (keepfooting) - exercise(A_DEX, TRUE); - else - selftouch((Upolyd && - (slithy(youmonst.data) || - nolimbs(youmonst.data))) ? - "Shaken, you" : "Falling down, you"); - } - } else newsym(x,y); - break; - case DOOR : /* Make the door collapse */ - if (levl[x][y].doormask == D_NODOOR) goto do_pit; - if (cansee(x,y)) - pline_The("door collapses."); - if (*in_rooms(x, y, SHOPBASE)) - add_damage(x, y, 0L); - levl[x][y].doormask = D_NODOOR; - unblock_point(x,y); - newsym(x,y); - break; - } - } + if (mtmp) { + if (!is_flyer(mtmp->data) + && !is_clinger(mtmp->data)) { + boolean m_already_trapped = mtmp->mtrapped; + mtmp->mtrapped = 1; + if (!m_already_trapped) { /* suppress messages */ + if (cansee(x, y)) + pline("%s falls into a chasm!", + Monnam(mtmp)); + else if (humanoid(mtmp->data)) + You_hear("a scream!"); + } + /* Falling is okay for falling down + within a pit from jostling too */ + mselftouch(mtmp, "Falling, ", TRUE); + if (mtmp->mhp > 0) + if ((mtmp->mhp -= + rnd(m_already_trapped ? 4 : 6)) <= 0) { + if (!cansee(x, y)) + pline("It is destroyed!"); + else { + You("destroy %s!", + mtmp->mtame + ? x_monnam( + mtmp, ARTICLE_THE, + "poor", + (has_mname(mtmp)) + ? SUPPRESS_SADDLE + : 0, + FALSE) + : mon_nam(mtmp)); + } + xkilled(mtmp, 0); + } + } + } else if (x == u.ux && y == u.uy) { + if (Levitation || Flying + || is_clinger(youmonst.data)) { + if (!tu_pit) { /* no pit here previously */ + pline("A chasm opens up under you!"); + You("don't fall in!"); + } + } else if (!tu_pit || !u.utrap + || (u.utrap && u.utraptype != TT_PIT)) { + /* no pit here previously, or you were + not in it even it there was */ + You("fall into a chasm!"); + u.utrap = rn1(6, 2); + u.utraptype = TT_PIT; + losehp(Maybe_Half_Phys(rnd(6)), + "fell into a chasm", NO_KILLER_PREFIX); + selftouch("Falling, you"); + } else if (u.utrap && u.utraptype == TT_PIT) { + boolean keepfooting = + ((Fumbling && !rn2(5)) + || (!rnl(Role_if(PM_ARCHEOLOGIST) ? 3 : 9)) + || ((ACURR(A_DEX) > 7) && rn2(5))); + You("are jostled around violently!"); + u.utrap = rn1(6, 2); + u.utraptype = TT_PIT; /* superfluous */ + losehp(Maybe_Half_Phys(rnd(keepfooting ? 2 : 4)), + "hurt in a chasm", NO_KILLER_PREFIX); + if (keepfooting) + exercise(A_DEX, TRUE); + else + selftouch( + (Upolyd && (slithy(youmonst.data) + || nolimbs(youmonst.data))) + ? "Shaken, you" + : "Falling down, you"); + } + } else + newsym(x, y); + break; + case DOOR: /* Make the door collapse */ + if (levl[x][y].doormask == D_NODOOR) + goto do_pit; + if (cansee(x, y)) + pline_The("door collapses."); + if (*in_rooms(x, y, SHOPBASE)) + add_damage(x, y, 0L); + levl[x][y].doormask = D_NODOOR; + unblock_point(x, y); + newsym(x, y); + break; + } + } } /* @@ -416,125 +437,128 @@ STATIC_OVL int do_improvisation(instr) struct obj *instr; { - int damage, do_spec = !Confusion; -#if defined(MAC) || defined(AMIGA) || defined(VPIX_MUSIC) || defined (PCMUSIC) - struct obj itmp; + int damage, do_spec = !Confusion; +#if defined(MAC) || defined(AMIGA) || defined(VPIX_MUSIC) || defined(PCMUSIC) + struct obj itmp; - itmp = *instr; - itmp.oextra = (struct oextra *)0; /* ok on this copy as instr maintains - the ptr to free at some point if - there is one */ + itmp = *instr; + itmp.oextra = (struct oextra *) 0; /* ok on this copy as instr maintains + the ptr to free at some point if + there is one */ - /* if won't yield special effect, make sound of mundane counterpart */ - if (!do_spec || instr->spe <= 0) - while (objects[itmp.otyp].oc_magic) itmp.otyp -= 1; -# ifdef MAC - mac_speaker(&itmp, "C"); -# endif -# ifdef AMIGA - amii_speaker(&itmp, "Cw", AMII_OKAY_VOLUME); -# endif -# ifdef VPIX_MUSIC - if (sco_flag_console) - speaker(&itmp, "C"); -# endif + /* if won't yield special effect, make sound of mundane counterpart */ + if (!do_spec || instr->spe <= 0) + while (objects[itmp.otyp].oc_magic) + itmp.otyp -= 1; +#ifdef MAC + mac_speaker(&itmp, "C"); +#endif +#ifdef AMIGA + amii_speaker(&itmp, "Cw", AMII_OKAY_VOLUME); +#endif +#ifdef VPIX_MUSIC + if (sco_flag_console) + speaker(&itmp, "C"); +#endif #ifdef PCMUSIC - pc_speaker ( &itmp, "C"); + pc_speaker(&itmp, "C"); #endif #endif /* MAC || AMIGA || VPIX_MUSIC || PCMUSIC */ - if (!do_spec) - pline("What you produce is quite far from music..."); - else - You("start playing %s.", the(xname(instr))); + if (!do_spec) + pline("What you produce is quite far from music..."); + else + You("start playing %s.", the(xname(instr))); - switch (instr->otyp) { - case MAGIC_FLUTE: /* Make monster fall asleep */ - if (do_spec && instr->spe > 0) { - consume_obj_charge(instr, TRUE); + switch (instr->otyp) { + case MAGIC_FLUTE: /* Make monster fall asleep */ + if (do_spec && instr->spe > 0) { + consume_obj_charge(instr, TRUE); - You("produce %s music.", Hallucination ? "piped" : "soft"); - put_monsters_to_sleep(u.ulevel * 5); - exercise(A_DEX, TRUE); - break; - } /* else FALLTHRU */ - case WOODEN_FLUTE: /* May charm snakes */ - do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25); - pline("%s.", Tobjnam(instr, do_spec ? "trill" : "toot")); - if (do_spec) charm_snakes(u.ulevel * 3); - exercise(A_DEX, TRUE); - break; - case FIRE_HORN: /* Idem wand of fire */ - case FROST_HORN: /* Idem wand of cold */ - if (do_spec && instr->spe > 0) { - consume_obj_charge(instr, TRUE); + You("produce %s music.", Hallucination ? "piped" : "soft"); + put_monsters_to_sleep(u.ulevel * 5); + exercise(A_DEX, TRUE); + break; + } /* else FALLTHRU */ + case WOODEN_FLUTE: /* May charm snakes */ + do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25); + pline("%s.", Tobjnam(instr, do_spec ? "trill" : "toot")); + if (do_spec) + charm_snakes(u.ulevel * 3); + exercise(A_DEX, TRUE); + break; + case FIRE_HORN: /* Idem wand of fire */ + case FROST_HORN: /* Idem wand of cold */ + if (do_spec && instr->spe > 0) { + consume_obj_charge(instr, TRUE); - if (!getdir((char *)0)) { - pline("%s.", Tobjnam(instr, "vibrate")); - break; - } else if (!u.dx && !u.dy && !u.dz) { - if ((damage = zapyourself(instr, TRUE)) != 0) { - char buf[BUFSZ]; - Sprintf(buf, "using a magical horn on %sself", uhim()); - losehp(damage, buf, KILLED_BY); /* frost damage */ - /* fire damage */ - } - } else { - buzz((instr->otyp == FROST_HORN) ? AD_COLD-1 : AD_FIRE-1, - rn1(6,6), u.ux, u.uy, u.dx, u.dy); - } - makeknown(instr->otyp); - break; - } /* else FALLTHRU */ - case TOOLED_HORN: /* Awaken or scare monsters */ - You("produce a frightful, grave sound."); - awaken_monsters(u.ulevel * 30); - exercise(A_WIS, FALSE); - break; - case BUGLE: /* Awaken & attract soldiers */ - You("extract a loud noise from %s.", the(xname(instr))); - awaken_soldiers(&youmonst); - exercise(A_WIS, FALSE); - break; - case MAGIC_HARP: /* Charm monsters */ - if (do_spec && instr->spe > 0) { - consume_obj_charge(instr, TRUE); + if (!getdir((char *) 0)) { + pline("%s.", Tobjnam(instr, "vibrate")); + break; + } else if (!u.dx && !u.dy && !u.dz) { + if ((damage = zapyourself(instr, TRUE)) != 0) { + char buf[BUFSZ]; + Sprintf(buf, "using a magical horn on %sself", uhim()); + losehp(damage, buf, KILLED_BY); /* frost damage */ + /* fire damage */ + } + } else { + buzz((instr->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1, + rn1(6, 6), u.ux, u.uy, u.dx, u.dy); + } + makeknown(instr->otyp); + break; + } /* else FALLTHRU */ + case TOOLED_HORN: /* Awaken or scare monsters */ + You("produce a frightful, grave sound."); + awaken_monsters(u.ulevel * 30); + exercise(A_WIS, FALSE); + break; + case BUGLE: /* Awaken & attract soldiers */ + You("extract a loud noise from %s.", the(xname(instr))); + awaken_soldiers(&youmonst); + exercise(A_WIS, FALSE); + break; + case MAGIC_HARP: /* Charm monsters */ + if (do_spec && instr->spe > 0) { + consume_obj_charge(instr, TRUE); - pline("%s very attractive music.", Tobjnam(instr, "produce")); - charm_monsters((u.ulevel - 1) / 3 + 1); - exercise(A_DEX, TRUE); - break; - } /* else FALLTHRU */ - case WOODEN_HARP: /* May calm Nymph */ - do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25); - pline("%s %s.", The(xname(instr)), - do_spec ? "produces a lilting melody" : "twangs"); - if (do_spec) calm_nymphs(u.ulevel * 3); - exercise(A_DEX, TRUE); - break; - case DRUM_OF_EARTHQUAKE: /* create several pits */ - if (do_spec && instr->spe > 0) { - consume_obj_charge(instr, TRUE); + pline("%s very attractive music.", Tobjnam(instr, "produce")); + charm_monsters((u.ulevel - 1) / 3 + 1); + exercise(A_DEX, TRUE); + break; + } /* else FALLTHRU */ + case WOODEN_HARP: /* May calm Nymph */ + do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25); + pline("%s %s.", The(xname(instr)), + do_spec ? "produces a lilting melody" : "twangs"); + if (do_spec) + calm_nymphs(u.ulevel * 3); + exercise(A_DEX, TRUE); + break; + case DRUM_OF_EARTHQUAKE: /* create several pits */ + if (do_spec && instr->spe > 0) { + consume_obj_charge(instr, TRUE); - You("produce a heavy, thunderous rolling!"); - pline_The("entire dungeon is shaking around you!"); - do_earthquake((u.ulevel - 1) / 3 + 1); - /* shake up monsters in a much larger radius... */ - awaken_monsters(ROWNO * COLNO); - makeknown(DRUM_OF_EARTHQUAKE); - break; - } /* else FALLTHRU */ - case LEATHER_DRUM: /* Awaken monsters */ - You("beat a deafening row!"); - awaken_monsters(u.ulevel * 40); - incr_itimeout(&HDeaf, rn1(20,30)); - exercise(A_WIS, FALSE); - break; - default: - impossible("What a weird instrument (%d)!", instr->otyp); - break; - } - return 2; /* That takes time */ + You("produce a heavy, thunderous rolling!"); + pline_The("entire dungeon is shaking around you!"); + do_earthquake((u.ulevel - 1) / 3 + 1); + /* shake up monsters in a much larger radius... */ + awaken_monsters(ROWNO * COLNO); + makeknown(DRUM_OF_EARTHQUAKE); + break; + } /* else FALLTHRU */ + case LEATHER_DRUM: /* Awaken monsters */ + You("beat a deafening row!"); + awaken_monsters(u.ulevel * 40); + incr_itimeout(&HDeaf, rn1(20, 30)); + exercise(A_WIS, FALSE); + break; + default: + impossible("What a weird instrument (%d)!", instr->otyp); + break; + } + return 2; /* That takes time */ } /* @@ -547,149 +571,156 @@ struct obj *instr; { char buf[BUFSZ], c = 'y'; char *s; - int x,y; + int x, y; boolean ok; if (Underwater) { - You_cant("play music underwater!"); - return(0); - } else if ((instr->otyp == WOODEN_FLUTE || instr->otyp == MAGIC_FLUTE || - instr->otyp == TOOLED_HORN || instr->otyp == FROST_HORN || - instr->otyp == FIRE_HORN || instr->otyp == BUGLE) && - !can_blow(&youmonst)) { - You("are incapable of playing %s.", the(distant_name(instr, xname))); - return(0); + You_cant("play music underwater!"); + return (0); + } else if ((instr->otyp == WOODEN_FLUTE || instr->otyp == MAGIC_FLUTE + || instr->otyp == TOOLED_HORN || instr->otyp == FROST_HORN + || instr->otyp == FIRE_HORN || instr->otyp == BUGLE) + && !can_blow(&youmonst)) { + You("are incapable of playing %s.", the(distant_name(instr, xname))); + return (0); } if (instr->otyp != LEATHER_DRUM && instr->otyp != DRUM_OF_EARTHQUAKE) { - c = ynq("Improvise?"); - if (c == 'q') goto nevermind; + c = ynq("Improvise?"); + if (c == 'q') + goto nevermind; } if (c == 'n') { - if (u.uevent.uheard_tune == 2) c = ynq("Play the passtune?"); - if (c == 'q') { - goto nevermind; - } else if (c == 'y') { - Strcpy(buf, tune); - } else { - getlin("What tune are you playing? [5 notes, A-G]", buf); - (void)mungspaces(buf); - if (*buf == '\033') goto nevermind; + if (u.uevent.uheard_tune == 2) + c = ynq("Play the passtune?"); + if (c == 'q') { + goto nevermind; + } else if (c == 'y') { + Strcpy(buf, tune); + } else { + getlin("What tune are you playing? [5 notes, A-G]", buf); + (void) mungspaces(buf); + if (*buf == '\033') + goto nevermind; - /* convert to uppercase and change any "H" to the expected "B" */ - for (s = buf; *s; s++) { + /* convert to uppercase and change any "H" to the expected "B" */ + for (s = buf; *s; s++) { #ifndef AMIGA - *s = highc(*s); + *s = highc(*s); #else - /* The AMIGA supports two octaves of notes */ - if (*s == 'h') *s = 'b'; + /* The AMIGA supports two octaves of notes */ + if (*s == 'h') + *s = 'b'; #endif - if (*s == 'H') *s = 'B'; - } - } - You("extract a strange sound from %s!", the(xname(instr))); + if (*s == 'H') + *s = 'B'; + } + } + You("extract a strange sound from %s!", the(xname(instr))); #ifdef UNIX386MUSIC - /* if user is at the console, play through the console speaker */ - if (atconsole()) - speaker(instr, buf); + /* if user is at the console, play through the console speaker */ + if (atconsole()) + speaker(instr, buf); #endif #ifdef VPIX_MUSIC - if (sco_flag_console) - speaker(instr, buf); + if (sco_flag_console) + speaker(instr, buf); #endif #ifdef MAC - mac_speaker ( instr , buf ) ; + mac_speaker(instr, buf); #endif #ifdef PCMUSIC - pc_speaker ( instr, buf ); + pc_speaker(instr, buf); #endif #ifdef AMIGA - { - char nbuf[ 20 ]; - int i; - for( i = 0; buf[i] && i < 5; ++i ) - { - nbuf[ i*2 ] = buf[ i ]; - nbuf[ (i*2)+1 ] = 'h'; - } - nbuf[ i*2 ] = 0; - amii_speaker ( instr , nbuf, AMII_OKAY_VOLUME ) ; - } + { + char nbuf[20]; + int i; + for (i = 0; buf[i] && i < 5; ++i) { + nbuf[i * 2] = buf[i]; + nbuf[(i * 2) + 1] = 'h'; + } + nbuf[i * 2] = 0; + amii_speaker(instr, nbuf, AMII_OKAY_VOLUME); + } #endif - /* Check if there was the Stronghold drawbridge near - * and if the tune conforms to what we're waiting for. - */ - if(Is_stronghold(&u.uz)) { - exercise(A_WIS, TRUE); /* just for trying */ - if(!strcmp(buf,tune)) { - /* Search for the drawbridge */ - for(y=u.uy-1; y<=u.uy+1; y++) - for(x=u.ux-1;x<=u.ux+1;x++) - if(isok(x,y)) - if(find_drawbridge(&x,&y)) { - u.uevent.uheard_tune = 2; /* tune now fully known */ - if(levl[x][y].typ == DRAWBRIDGE_DOWN) - close_drawbridge(x,y); - else - open_drawbridge(x,y); - return 1; - } - } else if(!Deaf) { - if (u.uevent.uheard_tune < 1) u.uevent.uheard_tune = 1; - /* Okay, it wasn't the right tune, but perhaps - * we can give the player some hints like in the - * Mastermind game */ - ok = FALSE; - for(y = u.uy-1; y <= u.uy+1 && !ok; y++) - for(x = u.ux-1; x <= u.ux+1 && !ok; x++) - if(isok(x,y)) - if(IS_DRAWBRIDGE(levl[x][y].typ) || - is_drawbridge_wall(x,y) >= 0) - ok = TRUE; - if(ok) { /* There is a drawbridge near */ - int tumblers, gears; - boolean matched[5]; + /* Check if there was the Stronghold drawbridge near + * and if the tune conforms to what we're waiting for. + */ + if (Is_stronghold(&u.uz)) { + exercise(A_WIS, TRUE); /* just for trying */ + if (!strcmp(buf, tune)) { + /* Search for the drawbridge */ + for (y = u.uy - 1; y <= u.uy + 1; y++) + for (x = u.ux - 1; x <= u.ux + 1; x++) + if (isok(x, y)) + if (find_drawbridge(&x, &y)) { + u.uevent.uheard_tune = + 2; /* tune now fully known */ + if (levl[x][y].typ == DRAWBRIDGE_DOWN) + close_drawbridge(x, y); + else + open_drawbridge(x, y); + return 1; + } + } else if (!Deaf) { + if (u.uevent.uheard_tune < 1) + u.uevent.uheard_tune = 1; + /* Okay, it wasn't the right tune, but perhaps + * we can give the player some hints like in the + * Mastermind game */ + ok = FALSE; + for (y = u.uy - 1; y <= u.uy + 1 && !ok; y++) + for (x = u.ux - 1; x <= u.ux + 1 && !ok; x++) + if (isok(x, y)) + if (IS_DRAWBRIDGE(levl[x][y].typ) + || is_drawbridge_wall(x, y) >= 0) + ok = TRUE; + if (ok) { /* There is a drawbridge near */ + int tumblers, gears; + boolean matched[5]; - tumblers = gears = 0; - for(x=0; x < 5; x++) - matched[x] = FALSE; + tumblers = gears = 0; + for (x = 0; x < 5; x++) + matched[x] = FALSE; - for(x=0; x < (int)strlen(buf); x++) - if(x < 5) { - if(buf[x] == tune[x]) { - gears++; - matched[x] = TRUE; - } else - for(y=0; y < 5; y++) - if(!matched[y] && - buf[x] == tune[y] && - buf[y] != tune[y]) { - tumblers++; - matched[y] = TRUE; - break; - } - } - if(tumblers) - if(gears) - You_hear("%d tumbler%s click and %d gear%s turn.", - tumblers, plur(tumblers), gears, plur(gears)); - else - You_hear("%d tumbler%s click.", - tumblers, plur(tumblers)); - else if(gears) { - You_hear("%d gear%s turn.", gears, plur(gears)); - /* could only get `gears == 5' by playing five - correct notes followed by excess; otherwise, - tune would have matched above */ - if (gears == 5) u.uevent.uheard_tune = 2; - } - } - } - } - return 1; + for (x = 0; x < (int) strlen(buf); x++) + if (x < 5) { + if (buf[x] == tune[x]) { + gears++; + matched[x] = TRUE; + } else + for (y = 0; y < 5; y++) + if (!matched[y] && buf[x] == tune[y] + && buf[y] != tune[y]) { + tumblers++; + matched[y] = TRUE; + break; + } + } + if (tumblers) + if (gears) + You_hear("%d tumbler%s click and %d gear%s turn.", + tumblers, plur(tumblers), gears, + plur(gears)); + else + You_hear("%d tumbler%s click.", tumblers, + plur(tumblers)); + else if (gears) { + You_hear("%d gear%s turn.", gears, plur(gears)); + /* could only get `gears == 5' by playing five + correct notes followed by excess; otherwise, + tune would have matched above */ + if (gears == 5) + u.uevent.uheard_tune = 2; + } + } + } + } + return 1; } else - return do_improvisation(instr); + return do_improvisation(instr); - nevermind: +nevermind: pline1(Never_mind); return 0; } @@ -712,15 +743,15 @@ atconsole() * difficult given the presence of virtual consoles and other modern * UNIX impedimenta... */ - char *termtype = nh_getenv("TERM"); + char *termtype = nh_getenv("TERM"); - return(!strcmp(termtype, "AT386") || !strcmp(termtype, "xterm")); + return (!strcmp(termtype, "AT386") || !strcmp(termtype, "xterm")); } STATIC_OVL void speaker(instr, buf) struct obj *instr; -char *buf; +char *buf; { /* * For this to work, you need to have installed the PD speaker-control @@ -728,113 +759,109 @@ char *buf; * posted to comp.sources.unix in Feb 1990. A copy should be included * with your nethack distribution. */ - int fd; + int fd; - if ((fd = open("/dev/speaker", 1)) != -1) - { - /* send a prefix to modify instrumental `timbre' */ - switch (instr->otyp) - { - case WOODEN_FLUTE: - case MAGIC_FLUTE: - (void) write(fd, ">ol", 1); /* up one octave & lock */ - break; - case TOOLED_HORN: - case FROST_HORN: - case FIRE_HORN: - (void) write(fd, "<otyp) { + case WOODEN_FLUTE: + case MAGIC_FLUTE: + (void) write(fd, ">ol", 1); /* up one octave & lock */ + break; + case TOOLED_HORN: + case FROST_HORN: + case FIRE_HORN: + (void) write(fd, "< #include #include -# else +#else #define KIOC ('K' << 8) #define KDMKTONE (KIOC | 8) -# endif +#endif #define noDEBUG -STATIC_OVL void tone(hz, ticks) +STATIC_OVL void +tone(hz, ticks) /* emit tone of frequency hz for given number of ticks */ unsigned int hz, ticks; { - ioctl(0,KDMKTONE,hz|((ticks*10)<<16)); -# ifdef DEBUG - printf("TONE: %6d %6d\n",hz,ticks * 10); -# endif + ioctl(0, KDMKTONE, hz | ((ticks * 10) << 16)); +#ifdef DEBUG + printf("TONE: %6d %6d\n", hz, ticks * 10); +#endif nap(ticks * 10); } -STATIC_OVL void rest(ticks) +STATIC_OVL void +rest(ticks) /* rest for given number of ticks */ -int ticks; +int ticks; { nap(ticks * 10); -# ifdef DEBUG - printf("REST: %6d\n",ticks * 10); -# endif +#ifdef DEBUG + printf("REST: %6d\n", ticks * 10); +#endif } - -#include "interp.c" /* from snd86unx.shr */ - +#include "interp.c" /* from snd86unx.shr */ STATIC_OVL void speaker(instr, buf) struct obj *instr; -char *buf; +char *buf; { /* emit a prefix to modify instrumental `timbre' */ playinit(); - switch (instr->otyp) - { - case WOODEN_FLUTE: - case MAGIC_FLUTE: - playstring(">ol", 1); /* up one octave & lock */ - break; - case TOOLED_HORN: - case FROST_HORN: - case FIRE_HORN: - playstring("<otyp) { + case WOODEN_FLUTE: + case MAGIC_FLUTE: + playstring(">ol", 1); /* up one octave & lock */ + break; + case TOOLED_HORN: + case FROST_HORN: + case FIRE_HORN: + playstring("< maxledgerno()) - ? maxledgerno() : ledger_no(dlev); - else - lev = 0; - first = bases[GEM_CLASS]; + if (dlev) + lev = (ledger_no(dlev) > maxledgerno()) ? maxledgerno() + : ledger_no(dlev); + else + lev = 0; + first = bases[GEM_CLASS]; - for(j = 0; j < 9-lev/3; j++) - objects[first+j].oc_prob = 0; - first += j; - if (first > LAST_GEM || objects[first].oc_class != GEM_CLASS || - OBJ_NAME(objects[first]) == (char *)0) { - raw_printf("Not enough gems? - first=%d j=%d LAST_GEM=%d", - first, j, LAST_GEM); - wait_synch(); - } - for (j = first; j <= LAST_GEM; j++) - objects[j].oc_prob = (171+j-first)/(LAST_GEM+1-first); + for (j = 0; j < 9 - lev / 3; j++) + objects[first + j].oc_prob = 0; + first += j; + if (first > LAST_GEM || objects[first].oc_class != GEM_CLASS + || OBJ_NAME(objects[first]) == (char *) 0) { + raw_printf("Not enough gems? - first=%d j=%d LAST_GEM=%d", first, j, + LAST_GEM); + wait_synch(); + } + for (j = first; j <= LAST_GEM; j++) + objects[j].oc_prob = (171 + j - first) / (LAST_GEM + 1 - first); } /* shuffle descriptions on objects o_low to o_high */ STATIC_OVL void shuffle(o_low, o_high, domaterial) - int o_low, o_high; - boolean domaterial; +int o_low, o_high; +boolean domaterial; { - int i, j, num_to_shuffle; - short sw; - int color; + int i, j, num_to_shuffle; + short sw; + int color; - for (num_to_shuffle = 0, j=o_low; j <= o_high; j++) - if (!objects[j].oc_name_known) num_to_shuffle++; - if (num_to_shuffle < 2) return; + for (num_to_shuffle = 0, j = o_low; j <= o_high; j++) + if (!objects[j].oc_name_known) + num_to_shuffle++; + if (num_to_shuffle < 2) + return; - for (j=o_low; j <= o_high; j++) { - if (objects[j].oc_name_known) continue; - do - i = j + rn2(o_high-j+1); - while (objects[i].oc_name_known); - sw = objects[j].oc_descr_idx; - objects[j].oc_descr_idx = objects[i].oc_descr_idx; - objects[i].oc_descr_idx = sw; - sw = objects[j].oc_tough; - objects[j].oc_tough = objects[i].oc_tough; - objects[i].oc_tough = sw; - color = objects[j].oc_color; - objects[j].oc_color = objects[i].oc_color; - objects[i].oc_color = color; + for (j = o_low; j <= o_high; j++) { + if (objects[j].oc_name_known) + continue; + do + i = j + rn2(o_high - j + 1); + while (objects[i].oc_name_known); + sw = objects[j].oc_descr_idx; + objects[j].oc_descr_idx = objects[i].oc_descr_idx; + objects[i].oc_descr_idx = sw; + sw = objects[j].oc_tough; + objects[j].oc_tough = objects[i].oc_tough; + objects[i].oc_tough = sw; + color = objects[j].oc_color; + objects[j].oc_color = objects[i].oc_color; + objects[i].oc_color = color; - /* shuffle material */ - if (domaterial) { - sw = objects[j].oc_material; - objects[j].oc_material = objects[i].oc_material; - objects[i].oc_material = sw; - } - } + /* shuffle material */ + if (domaterial) { + sw = objects[j].oc_material; + objects[j].oc_material = objects[i].oc_material; + objects[i].oc_material = sw; + } + } } void init_objects() { -register int i, first, last, sum; -register char oclass; + register int i, first, last, sum; + register char oclass; #ifdef TEXTCOLOR -# define COPY_OBJ_DESCR(o_dst,o_src) \ - o_dst.oc_descr_idx = o_src.oc_descr_idx,\ - o_dst.oc_color = o_src.oc_color +#define COPY_OBJ_DESCR(o_dst, o_src) \ + o_dst.oc_descr_idx = o_src.oc_descr_idx, o_dst.oc_color = o_src.oc_color #else -# define COPY_OBJ_DESCR(o_dst,o_src) o_dst.oc_descr_idx = o_src.oc_descr_idx +#define COPY_OBJ_DESCR(o_dst, o_src) o_dst.oc_descr_idx = o_src.oc_descr_idx #endif - /* bug fix to prevent "initialization error" abort on Intel Xenix. - * reported by mikew@semike - */ - for (i = 0; i < MAXOCLASSES; i++) - bases[i] = 0; - /* initialize object descriptions */ - for (i = 0; i < NUM_OBJECTS; i++) - objects[i].oc_name_idx = objects[i].oc_descr_idx = i; - /* init base; if probs given check that they add up to 1000, - otherwise compute probs */ - first = 0; - while( first < NUM_OBJECTS ) { - oclass = objects[first].oc_class; - last = first+1; - while (last < NUM_OBJECTS && objects[last].oc_class == oclass) last++; - bases[(int)oclass] = first; + /* bug fix to prevent "initialization error" abort on Intel Xenix. + * reported by mikew@semike + */ + for (i = 0; i < MAXOCLASSES; i++) + bases[i] = 0; + /* initialize object descriptions */ + for (i = 0; i < NUM_OBJECTS; i++) + objects[i].oc_name_idx = objects[i].oc_descr_idx = i; + /* init base; if probs given check that they add up to 1000, + otherwise compute probs */ + first = 0; + while (first < NUM_OBJECTS) { + oclass = objects[first].oc_class; + last = first + 1; + while (last < NUM_OBJECTS && objects[last].oc_class == oclass) + last++; + bases[(int) oclass] = first; - if (oclass == GEM_CLASS) { - setgemprobs((d_level *)0); + if (oclass == GEM_CLASS) { + setgemprobs((d_level *) 0); - if (rn2(2)) { /* change turquoise from green to blue? */ - COPY_OBJ_DESCR(objects[TURQUOISE],objects[SAPPHIRE]); - } - if (rn2(2)) { /* change aquamarine from green to blue? */ - COPY_OBJ_DESCR(objects[AQUAMARINE],objects[SAPPHIRE]); - } - switch (rn2(4)) { /* change fluorite from violet? */ - case 0: break; - case 1: /* blue */ - COPY_OBJ_DESCR(objects[FLUORITE],objects[SAPPHIRE]); - break; - case 2: /* white */ - COPY_OBJ_DESCR(objects[FLUORITE],objects[DIAMOND]); - break; - case 3: /* green */ - COPY_OBJ_DESCR(objects[FLUORITE],objects[EMERALD]); - break; - } - } - check: - sum = 0; - for(i = first; i < last; i++) sum += objects[i].oc_prob; - if(sum == 0) { - for(i = first; i < last; i++) - objects[i].oc_prob = (1000+i-first)/(last-first); - goto check; - } - if(sum != 1000) - error("init-prob error for class %d (%d%%)", oclass, sum); - first = last; - } - /* shuffle descriptions */ - shuffle_all(); + if (rn2(2)) { /* change turquoise from green to blue? */ + COPY_OBJ_DESCR(objects[TURQUOISE], objects[SAPPHIRE]); + } + if (rn2(2)) { /* change aquamarine from green to blue? */ + COPY_OBJ_DESCR(objects[AQUAMARINE], objects[SAPPHIRE]); + } + switch (rn2(4)) { /* change fluorite from violet? */ + case 0: + break; + case 1: /* blue */ + COPY_OBJ_DESCR(objects[FLUORITE], objects[SAPPHIRE]); + break; + case 2: /* white */ + COPY_OBJ_DESCR(objects[FLUORITE], objects[DIAMOND]); + break; + case 3: /* green */ + COPY_OBJ_DESCR(objects[FLUORITE], objects[EMERALD]); + break; + } + } + check: + sum = 0; + for (i = first; i < last; i++) + sum += objects[i].oc_prob; + if (sum == 0) { + for (i = first; i < last; i++) + objects[i].oc_prob = (1000 + i - first) / (last - first); + goto check; + } + if (sum != 1000) + error("init-prob error for class %d (%d%%)", oclass, sum); + first = last; + } + /* shuffle descriptions */ + shuffle_all(); #ifdef USE_TILES - shuffle_tiles(); + shuffle_tiles(); #endif } /* retrieve the range of objects that otyp shares descriptions with */ void obj_shuffle_range(otyp, lo_p, hi_p) -int otyp; /* input: representative item */ -int *lo_p, *hi_p; /* output: range that item belongs among */ +int otyp; /* input: representative item */ +int *lo_p, *hi_p; /* output: range that item belongs among */ { int i, ocls = objects[otyp].oc_class; @@ -190,42 +194,45 @@ int *lo_p, *hi_p; /* output: range that item belongs among */ switch (ocls) { case ARMOR_CLASS: - if (otyp >= HELMET && otyp <= HELM_OF_TELEPATHY) - *lo_p = HELMET, *hi_p = HELM_OF_TELEPATHY; - else if (otyp >= LEATHER_GLOVES && otyp <= GAUNTLETS_OF_DEXTERITY) - *lo_p = LEATHER_GLOVES, *hi_p = GAUNTLETS_OF_DEXTERITY; - else if (otyp >= CLOAK_OF_PROTECTION && otyp <= CLOAK_OF_DISPLACEMENT) - *lo_p = CLOAK_OF_PROTECTION, *hi_p = CLOAK_OF_DISPLACEMENT; - else if (otyp >= SPEED_BOOTS && otyp <= LEVITATION_BOOTS) - *lo_p = SPEED_BOOTS, *hi_p = LEVITATION_BOOTS; - break; + if (otyp >= HELMET && otyp <= HELM_OF_TELEPATHY) + *lo_p = HELMET, *hi_p = HELM_OF_TELEPATHY; + else if (otyp >= LEATHER_GLOVES && otyp <= GAUNTLETS_OF_DEXTERITY) + *lo_p = LEATHER_GLOVES, *hi_p = GAUNTLETS_OF_DEXTERITY; + else if (otyp >= CLOAK_OF_PROTECTION && otyp <= CLOAK_OF_DISPLACEMENT) + *lo_p = CLOAK_OF_PROTECTION, *hi_p = CLOAK_OF_DISPLACEMENT; + else if (otyp >= SPEED_BOOTS && otyp <= LEVITATION_BOOTS) + *lo_p = SPEED_BOOTS, *hi_p = LEVITATION_BOOTS; + break; case POTION_CLASS: - /* potion of water has the only fixed description */ - *lo_p = bases[POTION_CLASS]; - *hi_p = POT_WATER - 1; - break; + /* potion of water has the only fixed description */ + *lo_p = bases[POTION_CLASS]; + *hi_p = POT_WATER - 1; + break; case AMULET_CLASS: case SCROLL_CLASS: case SPBOOK_CLASS: - /* exclude non-magic types and also unique ones */ - *lo_p = bases[ocls]; - for (i = *lo_p; objects[i].oc_class == ocls; i++) - if (objects[i].oc_unique || !objects[i].oc_magic) break; - *hi_p = i - 1; - break; + /* exclude non-magic types and also unique ones */ + *lo_p = bases[ocls]; + for (i = *lo_p; objects[i].oc_class == ocls; i++) + if (objects[i].oc_unique || !objects[i].oc_magic) + break; + *hi_p = i - 1; + break; case RING_CLASS: case WAND_CLASS: case VENOM_CLASS: - /* entire class */ - *lo_p = bases[ocls]; - for (i = *lo_p; objects[i].oc_class == ocls; i++) continue; - *hi_p = i - 1; - break; + /* entire class */ + *lo_p = bases[ocls]; + for (i = *lo_p; objects[i].oc_class == ocls; i++) + continue; + *hi_p = i - 1; + break; } /* artifact checking might ask about item which isn't part of any range but fell within the classes that do have ranges specified above */ - if (otyp < *lo_p || otyp > *hi_p) *lo_p = *hi_p = otyp; + if (otyp < *lo_p || otyp > *hi_p) + *lo_p = *hi_p = otyp; return; } @@ -235,32 +242,24 @@ shuffle_all() { /* entire classes; obj_shuffle_range() handles their exceptions */ static char shuffle_classes[] = { - AMULET_CLASS, - POTION_CLASS, - RING_CLASS, - SCROLL_CLASS, - SPBOOK_CLASS, - WAND_CLASS, - VENOM_CLASS, + AMULET_CLASS, POTION_CLASS, RING_CLASS, SCROLL_CLASS, + SPBOOK_CLASS, WAND_CLASS, VENOM_CLASS, }; /* sub-class type ranges (one item from each group) */ static short shuffle_types[] = { - HELMET, - LEATHER_GLOVES, - CLOAK_OF_PROTECTION, - SPEED_BOOTS, + HELMET, LEATHER_GLOVES, CLOAK_OF_PROTECTION, SPEED_BOOTS, }; int first, last, idx; /* do whole classes (amulets, &c) */ for (idx = 0; idx < SIZE(shuffle_classes); idx++) { - obj_shuffle_range(bases[(int) shuffle_classes[idx]], &first, &last); - shuffle(first, last, TRUE); + obj_shuffle_range(bases[(int) shuffle_classes[idx]], &first, &last); + shuffle(first, last, TRUE); } /* do type ranges (helms, &c) */ for (idx = 0; idx < SIZE(shuffle_types); idx++) { - obj_shuffle_range(shuffle_types[idx], &first, &last); - shuffle(first, last, FALSE); + obj_shuffle_range(shuffle_types[idx], &first, &last); + shuffle(first, last, FALSE); } return; } @@ -273,67 +272,66 @@ find_skates() register const char *s; for (i = SPEED_BOOTS; i <= LEVITATION_BOOTS; i++) - if ((s = OBJ_DESCR(objects[i])) != 0 && !strcmp(s, "snow boots")) - return i; + if ((s = OBJ_DESCR(objects[i])) != 0 && !strcmp(s, "snow boots")) + return i; impossible("snow boots not found?"); - return -1; /* not 0, or caller would try again each move */ + return -1; /* not 0, or caller would try again each move */ } -void -oinit() /* level dependent initialization */ +void oinit() /* level dependent initialization */ { - setgemprobs(&u.uz); + setgemprobs(&u.uz); } void savenames(fd, mode) int fd, mode; { - register int i; - unsigned int len; + register int i; + unsigned int len; - if (perform_bwrite(mode)) { - bwrite(fd, (genericptr_t)bases, sizeof bases); - bwrite(fd, (genericptr_t)disco, sizeof disco); - bwrite(fd, (genericptr_t)objects, - sizeof(struct objclass) * NUM_OBJECTS); - } - /* as long as we use only one version of Hack we - need not save oc_name and oc_descr, but we must save - oc_uname for all objects */ - for (i = 0; i < NUM_OBJECTS; i++) - if (objects[i].oc_uname) { - if (perform_bwrite(mode)) { - len = strlen(objects[i].oc_uname)+1; - bwrite(fd, (genericptr_t)&len, sizeof len); - bwrite(fd, (genericptr_t)objects[i].oc_uname, len); - } - if (release_data(mode)) { - free((genericptr_t)objects[i].oc_uname); - objects[i].oc_uname = 0; - } - } + if (perform_bwrite(mode)) { + bwrite(fd, (genericptr_t) bases, sizeof bases); + bwrite(fd, (genericptr_t) disco, sizeof disco); + bwrite(fd, (genericptr_t) objects, + sizeof(struct objclass) * NUM_OBJECTS); + } + /* as long as we use only one version of Hack we + need not save oc_name and oc_descr, but we must save + oc_uname for all objects */ + for (i = 0; i < NUM_OBJECTS; i++) + if (objects[i].oc_uname) { + if (perform_bwrite(mode)) { + len = strlen(objects[i].oc_uname) + 1; + bwrite(fd, (genericptr_t) &len, sizeof len); + bwrite(fd, (genericptr_t) objects[i].oc_uname, len); + } + if (release_data(mode)) { + free((genericptr_t) objects[i].oc_uname); + objects[i].oc_uname = 0; + } + } } void restnames(fd) register int fd; { - register int i; - unsigned int len; + register int i; + unsigned int len; - mread(fd, (genericptr_t) bases, sizeof bases); - mread(fd, (genericptr_t) disco, sizeof disco); - mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); - for (i = 0; i < NUM_OBJECTS; i++) - if (objects[i].oc_uname) { - mread(fd, (genericptr_t) &len, sizeof len); - objects[i].oc_uname = (char *) alloc(len); - mread(fd, (genericptr_t)objects[i].oc_uname, len); - } + mread(fd, (genericptr_t) bases, sizeof bases); + mread(fd, (genericptr_t) disco, sizeof disco); + mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); + for (i = 0; i < NUM_OBJECTS; i++) + if (objects[i].oc_uname) { + mread(fd, (genericptr_t) &len, sizeof len); + objects[i].oc_uname = (char *) alloc(len); + mread(fd, (genericptr_t) objects[i].oc_uname, len); + } #ifdef USE_TILES - shuffle_tiles(); + shuffle_tiles(); #endif } @@ -344,21 +342,24 @@ boolean mark_as_known; boolean credit_hero; { if (!objects[oindx].oc_name_known) { - register int dindx, acls = objects[oindx].oc_class; + register int dindx, acls = objects[oindx].oc_class; - /* Loop thru disco[] 'til we find the target (which may have been - uname'd) or the next open slot; one or the other will be found - before we reach the next class... - */ - for (dindx = bases[acls]; disco[dindx] != 0; dindx++) - if (disco[dindx] == oindx) break; - disco[dindx] = oindx; + /* Loop thru disco[] 'til we find the target (which may have been + uname'd) or the next open slot; one or the other will be found + before we reach the next class... + */ + for (dindx = bases[acls]; disco[dindx] != 0; dindx++) + if (disco[dindx] == oindx) + break; + disco[dindx] = oindx; - if (mark_as_known) { - objects[oindx].oc_name_known = 1; - if (credit_hero) exercise(A_WIS, TRUE); - } - if (moves > 1L) update_inventory(); + if (mark_as_known) { + objects[oindx].oc_name_known = 1; + if (credit_hero) + exercise(A_WIS, TRUE); + } + if (moves > 1L) + update_inventory(); } } @@ -368,22 +369,24 @@ undiscover_object(oindx) register int oindx; { if (!objects[oindx].oc_name_known) { - register int dindx, acls = objects[oindx].oc_class; - register boolean found = FALSE; + register int dindx, acls = objects[oindx].oc_class; + register boolean found = FALSE; - /* find the object; shift those behind it forward one slot */ - for (dindx = bases[acls]; - dindx < NUM_OBJECTS && disco[dindx] != 0 - && objects[dindx].oc_class == acls; dindx++) - if (found) - disco[dindx-1] = disco[dindx]; - else if (disco[dindx] == oindx) - found = TRUE; + /* find the object; shift those behind it forward one slot */ + for (dindx = bases[acls]; dindx < NUM_OBJECTS && disco[dindx] != 0 + && objects[dindx].oc_class == acls; + dindx++) + if (found) + disco[dindx - 1] = disco[dindx]; + else if (disco[dindx] == oindx) + found = TRUE; - /* clear last slot */ - if (found) disco[dindx-1] = 0; - else impossible("named object not in disco"); - update_inventory(); + /* clear last slot */ + if (found) + disco[dindx - 1] = 0; + else + impossible("named object not in disco"); + update_inventory(); } } @@ -391,22 +394,20 @@ STATIC_OVL boolean interesting_to_discover(i) register int i; { - /* Pre-discovered objects are now printed with a '*' */ - return((boolean)(objects[i].oc_uname != (char *)0 || - (objects[i].oc_name_known && OBJ_DESCR(objects[i]) != (char *)0))); + /* Pre-discovered objects are now printed with a '*' */ + return ((boolean)(objects[i].oc_uname != (char *) 0 + || (objects[i].oc_name_known + && OBJ_DESCR(objects[i]) != (char *) 0))); } /* items that should stand out once they're known */ static short uniq_objs[] = { - AMULET_OF_YENDOR, - SPE_BOOK_OF_THE_DEAD, - CANDELABRUM_OF_INVOCATION, - BELL_OF_OPENING, + AMULET_OF_YENDOR, SPE_BOOK_OF_THE_DEAD, CANDELABRUM_OF_INVOCATION, + BELL_OF_OPENING, }; /* the '\' command - show discovered object types */ -int -dodiscovered() /* free after Robert Viduya */ +int dodiscovered() /* free after Robert Viduya */ { register int i, dis; int ct = 0; @@ -420,45 +421,47 @@ dodiscovered() /* free after Robert Viduya */ /* gather "unique objects" into a pseudo-class; note that they'll also be displayed individually within their regular class */ for (i = dis = 0; i < SIZE(uniq_objs); i++) - if (objects[uniq_objs[i]].oc_name_known) { - if (!dis++) - putstr(tmpwin, iflags.menu_headings, "Unique items"); - Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); - putstr(tmpwin, 0, buf); - ++ct; - } + if (objects[uniq_objs[i]].oc_name_known) { + if (!dis++) + putstr(tmpwin, iflags.menu_headings, "Unique items"); + Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); + putstr(tmpwin, 0, buf); + ++ct; + } /* display any known artifacts as another pseudo-class */ ct += disp_artifact_discoveries(tmpwin); /* several classes are omitted from packorder; one is of interest here */ Strcpy(classes, flags.inv_order); if (!index(classes, VENOM_CLASS)) { - s = eos(classes); - *s++ = VENOM_CLASS; - *s = '\0'; + s = eos(classes); + *s++ = VENOM_CLASS; + *s = '\0'; } for (s = classes; *s; s++) { - oclass = *s; - prev_class = oclass + 1; /* forced different from oclass */ - for (i = bases[(int)oclass]; - i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { - ct++; - if (oclass != prev_class) { - putstr(tmpwin, iflags.menu_headings, let_to_name(oclass, FALSE, FALSE)); - prev_class = oclass; - } - Sprintf(buf, "%s %s",(objects[dis].oc_pre_discovered ? "*" : " "), - obj_typename(dis)); - putstr(tmpwin, 0, buf); - } - } + oclass = *s; + prev_class = oclass + 1; /* forced different from oclass */ + for (i = bases[(int) oclass]; + i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { + if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + ct++; + if (oclass != prev_class) { + putstr(tmpwin, iflags.menu_headings, + let_to_name(oclass, FALSE, FALSE)); + prev_class = oclass; + } + Sprintf(buf, "%s %s", + (objects[dis].oc_pre_discovered ? "*" : " "), + obj_typename(dis)); + putstr(tmpwin, 0, buf); + } + } } if (ct == 0) { - You("haven't discovered anything yet..."); + You("haven't discovered anything yet..."); } else - display_nhwindow(tmpwin, TRUE); + display_nhwindow(tmpwin, TRUE); destroy_nhwindow(tmpwin); return 0; @@ -473,7 +476,8 @@ char *buf; char *s; Strcpy(buf, let_to_name(oclass, FALSE, FALSE)); - for (s = buf; *s; ++s) *s = lowc(*s); + for (s = buf; *s; ++s) + *s = lowc(*s); return buf; } @@ -481,12 +485,14 @@ char *buf; int doclassdisco() { - static NEARDATA const char - prompt[] = "View discoveries for which sort of objects?", - havent_discovered_any[] = "haven't discovered any %s yet.", - unique_items[] = "unique items", artifact_items[] = "artifacts"; - char *s, c, oclass, menulet, - allclasses[MAXOCLASSES], discosyms[2+MAXOCLASSES+1], buf[BUFSZ]; + static NEARDATA const char prompt[] = + "View discoveries for which sort of objects?", + havent_discovered_any[] = + "haven't discovered any %s yet.", + unique_items[] = "unique items", + artifact_items[] = "artifacts"; + char *s, c, oclass, menulet, allclasses[MAXOCLASSES], + discosyms[2 + MAXOCLASSES + 1], buf[BUFSZ]; int i, ct, dis, xtras; boolean traditional; winid tmpwin; @@ -494,102 +500,105 @@ doclassdisco() menu_item *pick_list = 0; discosyms[0] = '\0'; - traditional = (flags.menu_style == MENU_TRADITIONAL || - flags.menu_style == MENU_COMBINATION); + traditional = (flags.menu_style == MENU_TRADITIONAL + || flags.menu_style == MENU_COMBINATION); tmpwin = !traditional ? create_nhwindow(NHW_MENU) : WIN_ERR; any = zeroany; menulet = 'a'; /* check whether we've discovered any unique objects */ for (i = 0; i < SIZE(uniq_objs); i++) - if (objects[uniq_objs[i]].oc_name_known) { - Strcat(discosyms, "u"); - if (!traditional) { - any.a_int = 'u'; - add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, - unique_items, MENU_UNSELECTED); - } - break; - } + if (objects[uniq_objs[i]].oc_name_known) { + Strcat(discosyms, "u"); + if (!traditional) { + any.a_int = 'u'; + add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, + unique_items, MENU_UNSELECTED); + } + break; + } /* check whether we've discovered any artifacts */ if (disp_artifact_discoveries(WIN_ERR) > 0) { - Strcat(discosyms, "a"); - if (!traditional) { - any.a_int = 'a'; - add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, - artifact_items, MENU_UNSELECTED); - } + Strcat(discosyms, "a"); + if (!traditional) { + any.a_int = 'a'; + add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, + artifact_items, MENU_UNSELECTED); + } } /* collect classes with discoveries, in packorder ordering; several classes are omitted from packorder and one is of interest here */ Strcpy(allclasses, flags.inv_order); if (!index(allclasses, VENOM_CLASS)) - Sprintf(eos(allclasses), "%c", VENOM_CLASS); + Sprintf(eos(allclasses), "%c", VENOM_CLASS); /* construct discosyms[] */ for (s = allclasses; *s; ++s) { - oclass = *s; - c = def_oc_syms[(int)oclass].sym; - for (i = bases[(int)oclass]; - i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { - if (!index(discosyms, c)) { - Sprintf(eos(discosyms), "%c", c); - if (!traditional) { - any.a_int = c; - add_menu(tmpwin, NO_GLYPH, &any, - menulet++, c, ATR_NONE, - oclass_to_name(oclass, buf), MENU_UNSELECTED); - } - } - } + oclass = *s; + c = def_oc_syms[(int) oclass].sym; + for (i = bases[(int) oclass]; + i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) + if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if (!index(discosyms, c)) { + Sprintf(eos(discosyms), "%c", c); + if (!traditional) { + any.a_int = c; + add_menu(tmpwin, NO_GLYPH, &any, menulet++, c, + ATR_NONE, oclass_to_name(oclass, buf), + MENU_UNSELECTED); + } + } + } } /* there might not be anything for us to do... */ if (!discosyms[0]) { - You(havent_discovered_any, "items"); - if (tmpwin != WIN_ERR) destroy_nhwindow(tmpwin); - return 0; + You(havent_discovered_any, "items"); + if (tmpwin != WIN_ERR) + destroy_nhwindow(tmpwin); + return 0; } /* have player choose a class */ - c = '\0'; /* class not chosen yet */ + c = '\0'; /* class not chosen yet */ if (traditional) { - /* we'll prompt even if there's only one viable class; we add all - nonviable classes as unseen acceptable choices so player can ask - for discoveries of any class whether it has discoveries or not */ - for (s = allclasses, xtras = 0; *s; ++s) { - c = def_oc_syms[(int)*s].sym; - if (!index(discosyms, c)) { - if (!xtras++) Sprintf(eos(discosyms), "%c", '\033'); - Sprintf(eos(discosyms), "%c", c); - } - } - /* get the class (via its symbol character) */ - c = yn_function(prompt, discosyms, '\0'); - savech(c); - if (!c) - clear_nhwindow(WIN_MESSAGE); + /* we'll prompt even if there's only one viable class; we add all + nonviable classes as unseen acceptable choices so player can ask + for discoveries of any class whether it has discoveries or not */ + for (s = allclasses, xtras = 0; *s; ++s) { + c = def_oc_syms[(int) *s].sym; + if (!index(discosyms, c)) { + if (!xtras++) + Sprintf(eos(discosyms), "%c", '\033'); + Sprintf(eos(discosyms), "%c", c); + } + } + /* get the class (via its symbol character) */ + c = yn_function(prompt, discosyms, '\0'); + savech(c); + if (!c) + clear_nhwindow(WIN_MESSAGE); } else { - /* menustyle:full or menustyle:partial */ - if (!discosyms[1] && flags.menu_style == MENU_PARTIAL) { - /* only one class; menustyle:partial normally jumps past class - filtering straight to final menu so skip class filter here */ - c = discosyms[0]; - } else { - /* more than one choice, or menustyle:full which normally has - an intermediate class selection menu before the final menu */ - end_menu(tmpwin, prompt); - i = select_menu(tmpwin, PICK_ONE, &pick_list); - if (i > 0) { - c = pick_list[0].item.a_int; - free((genericptr_t) pick_list); - } /* else c stays 0 */ - } - destroy_nhwindow(tmpwin); + /* menustyle:full or menustyle:partial */ + if (!discosyms[1] && flags.menu_style == MENU_PARTIAL) { + /* only one class; menustyle:partial normally jumps past class + filtering straight to final menu so skip class filter here */ + c = discosyms[0]; + } else { + /* more than one choice, or menustyle:full which normally has + an intermediate class selection menu before the final menu */ + end_menu(tmpwin, prompt); + i = select_menu(tmpwin, PICK_ONE, &pick_list); + if (i > 0) { + c = pick_list[0].item.a_int; + free((genericptr_t) pick_list); + } /* else c stays 0 */ + } + destroy_nhwindow(tmpwin); } - if (!c) return 0; /* player declined to make a selection */ + if (!c) + return 0; /* player declined to make a selection */ /* * show discoveries for object class c @@ -598,39 +607,43 @@ doclassdisco() ct = 0; switch (c) { case 'u': - putstr(tmpwin, iflags.menu_headings, - upstart(strcpy(buf, unique_items))); - for (i = 0; i < SIZE(uniq_objs); i++) - if (objects[uniq_objs[i]].oc_name_known) { - Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); - putstr(tmpwin, 0, buf); - ++ct; - } - if (!ct) You(havent_discovered_any, unique_items); - break; + putstr(tmpwin, iflags.menu_headings, + upstart(strcpy(buf, unique_items))); + for (i = 0; i < SIZE(uniq_objs); i++) + if (objects[uniq_objs[i]].oc_name_known) { + Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); + putstr(tmpwin, 0, buf); + ++ct; + } + if (!ct) + You(havent_discovered_any, unique_items); + break; case 'a': - /* disp_artifact_discoveries() includes a header */ - ct = disp_artifact_discoveries(tmpwin); - if (!ct) You(havent_discovered_any, artifact_items); - break; + /* disp_artifact_discoveries() includes a header */ + ct = disp_artifact_discoveries(tmpwin); + if (!ct) + You(havent_discovered_any, artifact_items); + break; default: - oclass = def_char_to_objclass(c); - Sprintf(buf, "Discovered %s", let_to_name(oclass, FALSE, FALSE)); - putstr(tmpwin, iflags.menu_headings, buf); - for (i = bases[(int)oclass]; - i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { - Sprintf(buf, "%s %s", - objects[dis].oc_pre_discovered ? "*" : " ", - obj_typename(dis)); - putstr(tmpwin, 0, buf); - ++ct; - } - } - if (!ct) You(havent_discovered_any, oclass_to_name(oclass, buf)); - break; + oclass = def_char_to_objclass(c); + Sprintf(buf, "Discovered %s", let_to_name(oclass, FALSE, FALSE)); + putstr(tmpwin, iflags.menu_headings, buf); + for (i = bases[(int) oclass]; + i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) { + if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + Sprintf(buf, "%s %s", + objects[dis].oc_pre_discovered ? "*" : " ", + obj_typename(dis)); + putstr(tmpwin, 0, buf); + ++ct; + } + } + if (!ct) + You(havent_discovered_any, oclass_to_name(oclass, buf)); + break; } - if (ct) display_nhwindow(tmpwin, TRUE); + if (ct) + display_nhwindow(tmpwin, TRUE); destroy_nhwindow(tmpwin); return 0; } @@ -659,50 +672,53 @@ rename_disco() /* for each class, show discoveries in that class */ for (s = flags.inv_order; *s; s++) { - oclass = *s; - prev_class = oclass + 1; /* forced different from oclass */ - for (i = bases[(int)oclass]; - i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - dis = disco[i]; - if (!dis || !interesting_to_discover(dis)) continue; - ct++; - if (!objtyp_is_callable(dis)) continue; - mn++; + oclass = *s; + prev_class = oclass + 1; /* forced different from oclass */ + for (i = bases[(int) oclass]; + i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { + dis = disco[i]; + if (!dis || !interesting_to_discover(dis)) + continue; + ct++; + if (!objtyp_is_callable(dis)) + continue; + mn++; - if (oclass != prev_class) { - any.a_int = 0; - add_menu(tmpwin, NO_GLYPH, &any, ' ', iflags.menu_headings, - ATR_NONE, let_to_name(oclass, FALSE, FALSE), MENU_UNSELECTED); - prev_class = oclass; - } - any.a_int = dis; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - obj_typename(dis), MENU_UNSELECTED); - } + if (oclass != prev_class) { + any.a_int = 0; + add_menu(tmpwin, NO_GLYPH, &any, ' ', iflags.menu_headings, + ATR_NONE, let_to_name(oclass, FALSE, FALSE), + MENU_UNSELECTED); + prev_class = oclass; + } + any.a_int = dis; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + obj_typename(dis), MENU_UNSELECTED); + } } if (ct == 0) { - You("haven't discovered anything yet..."); + You("haven't discovered anything yet..."); } else if (mn == 0) { - pline("None of your discoveries can be assigned names..."); + pline("None of your discoveries can be assigned names..."); } else { - end_menu(tmpwin, "Pick an object type to name"); - dis = STRANGE_OBJECT; - sl = select_menu(tmpwin, PICK_ONE, &selected); - if (sl > 0) { - dis = selected[0].item.a_int; - free((genericptr_t)selected); - } - if (dis != STRANGE_OBJECT) { - struct obj odummy; + end_menu(tmpwin, "Pick an object type to name"); + dis = STRANGE_OBJECT; + sl = select_menu(tmpwin, PICK_ONE, &selected); + if (sl > 0) { + dis = selected[0].item.a_int; + free((genericptr_t) selected); + } + if (dis != STRANGE_OBJECT) { + struct obj odummy; - odummy = zeroobj; - odummy.otyp = dis; - odummy.oclass = objects[dis].oc_class; - odummy.quan = 1L; - odummy.known = !objects[dis].oc_uses_known; - odummy.dknown = 1; - docall(&odummy); - } + odummy = zeroobj; + odummy.otyp = dis; + odummy.oclass = objects[dis].oc_class; + odummy.quan = 1L; + odummy.known = !objects[dis].oc_uses_known; + odummy.dknown = 1; + docall(&odummy); + } } destroy_nhwindow(tmpwin); return; diff --git a/src/objects.c b/src/objects.c index d5ca4c3cd..32258c398 100644 --- a/src/objects.c +++ b/src/objects.c @@ -1,22 +1,23 @@ -/* NetHack 3.6 objects.c $NHDT-Date: 1428802519 2015/04/12 01:35:19 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ +/* NetHack 3.6 objects.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */ /* Copyright (c) Mike Threepoint, 1989. */ /* NetHack may be freely redistributed. See license for details. */ #ifndef OBJECTS_PASS_2_ /* first pass */ -struct monst { struct monst *dummy; }; /* lint: struct obj's union */ +struct monst { + struct monst *dummy; +}; /* lint: struct obj's union */ #include "config.h" #include "obj.h" #include "objclass.h" #include "prop.h" #include "skills.h" -#else /* !OBJECTS_PASS_2_ */ +#else /* !OBJECTS_PASS_2_ */ /* second pass */ #include "color.h" -# define COLOR_FIELD(X) X, -#endif /* !OBJECTS_PASS_2_ */ - +#define COLOR_FIELD(X) X, +#endif /* !OBJECTS_PASS_2_ */ /* objects have symbols: ) [ = " ( % ! ? + / $ * ` 0 _ . */ @@ -30,48 +31,59 @@ struct monst { struct monst *dummy; }; /* lint: struct obj's union */ #ifndef OBJECTS_PASS_2_ /* first pass -- object descriptive text */ -# define OBJ(name,desc) name,desc -# define OBJECT(obj,bits,prp,sym,prob,dly,wt,cost,sdam,ldam,oc1,oc2,nut,color) \ - {obj} +#define OBJ(name, desc) name, desc +#define OBJECT(obj, bits, prp, sym, prob, dly, wt, cost, sdam, ldam, oc1, \ + oc2, nut, color) \ + { \ + obj \ + } -NEARDATA struct objdescr obj_descr[] = { +NEARDATA struct objdescr + obj_descr[] = { #else /* second pass -- object definitions */ -# define BITS(nmkn,mrg,uskn,ctnr,mgc,chrg,uniq,nwsh,big,tuf,dir,sub,mtrl) \ - nmkn,mrg,uskn,0,mgc,chrg,uniq,nwsh,big,tuf,dir,mtrl,sub /* SCO ODT 1.1 cpp fodder */ -# define OBJECT(obj,bits,prp,sym,prob,dly,wt,cost,sdam,ldam,oc1,oc2,nut,color) \ - {0, 0, (char *)0, bits, prp, sym, dly, COLOR_FIELD(color) \ - prob, wt, cost, sdam, ldam, oc1, oc2, nut} -# ifndef lint -# define HARDGEM(n) (n >= 8) -# else -# define HARDGEM(n) (0) -# endif - -NEARDATA struct objclass objects[] = { +#define BITS(nmkn, mrg, uskn, ctnr, mgc, chrg, uniq, nwsh, big, tuf, dir, \ + sub, mtrl) \ + nmkn, mrg, uskn, 0, mgc, chrg, uniq, nwsh, big, tuf, dir, mtrl, \ + sub /* SCO ODT 1.1 cpp fodder */ +#define OBJECT(obj, bits, prp, sym, prob, dly, wt, cost, sdam, ldam, oc1, \ + oc2, nut, color) \ + { \ + 0, 0, (char *) 0, bits, prp, sym, dly, COLOR_FIELD(color) prob, wt, \ + cost, sdam, ldam, oc1, oc2, nut \ + } +#ifndef lint +#define HARDGEM(n) (n >= 8) +#else +#define HARDGEM(n) (0) #endif -/* dummy object[0] -- description [2nd arg] *must* be NULL */ - OBJECT(OBJ("strange object",(char *)0), BITS(1,0,0,0,0,0,0,0,0,0,0,P_NONE,0), - 0, ILLOBJ_CLASS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), + +NEARDATA struct objclass objects[] = + { +#endif + /* dummy object[0] -- description [2nd arg] *must* be NULL */ + OBJECT(OBJ("strange object", (char *) 0), + BITS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, 0), 0, + ILLOBJ_CLASS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), /* weapons ... */ -#define WEAPON(name,app,kn,mg,bi,prob,wt,cost,sdam,ldam,hitbon,typ,sub,metal,color) \ - OBJECT( \ - OBJ(name,app), BITS(kn,mg,1,0,0,1,0,0,bi,0,typ,sub,metal), 0, \ - WEAPON_CLASS, prob, 0, \ - wt, cost, sdam, ldam, hitbon, 0, wt, color ) -#define PROJECTILE(name,app,kn,prob,wt,cost,sdam,ldam,hitbon,metal,sub,color) \ - OBJECT( \ - OBJ(name,app), \ - BITS(kn,1,1,0,0,1,0,0,0,0,PIERCE,sub,metal), 0, \ - WEAPON_CLASS, prob, 0, \ - wt, cost, sdam, ldam, hitbon, 0, wt, color ) -#define BOW(name,app,kn,prob,wt,cost,hitbon,metal,sub,color) \ - OBJECT( \ - OBJ(name,app), BITS(kn,0,1,0,0,1,0,0,0,0,0,sub,metal), 0, \ - WEAPON_CLASS, prob, 0, \ - wt, cost, 2, 2, hitbon, 0, wt, color ) +#define WEAPON(name, app, kn, mg, bi, prob, wt, cost, sdam, ldam, hitbon, \ + typ, sub, metal, color) \ + OBJECT(OBJ(name, app), \ + BITS(kn, mg, 1, 0, 0, 1, 0, 0, bi, 0, typ, sub, metal), 0, \ + WEAPON_CLASS, prob, 0, wt, cost, sdam, ldam, hitbon, 0, wt, \ + color) +#define PROJECTILE(name, app, kn, prob, wt, cost, sdam, ldam, hitbon, metal, \ + sub, color) \ + OBJECT(OBJ(name, app), \ + BITS(kn, 1, 1, 0, 0, 1, 0, 0, 0, 0, PIERCE, sub, metal), 0, \ + WEAPON_CLASS, prob, 0, wt, cost, sdam, ldam, hitbon, 0, wt, \ + color) +#define BOW(name, app, kn, prob, wt, cost, hitbon, metal, sub, color) \ + OBJECT(OBJ(name, app), \ + BITS(kn, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, sub, metal), 0, \ + WEAPON_CLASS, prob, 0, wt, cost, 2, 2, hitbon, 0, wt, color) /* Note: for weapons that don't do an even die of damage (ex. 2-7 or 3-18) * the extra damage is added on in weapon.c, not here! */ @@ -80,188 +92,191 @@ NEARDATA struct objclass objects[] = { #define S SLASH #define B WHACK -/* missiles */ -PROJECTILE("arrow", (char *)0, - 1, 55, 1, 2, 6, 6, 0, IRON, -P_BOW, HI_METAL), -PROJECTILE("elven arrow", "runed arrow", - 0, 20, 1, 2, 7, 6, 0, WOOD, -P_BOW, HI_WOOD), -PROJECTILE("orcish arrow", "crude arrow", - 0, 20, 1, 2, 5, 6, 0, IRON, -P_BOW, CLR_BLACK), -PROJECTILE("silver arrow", (char *)0, - 1, 12, 1, 5, 6, 6, 0, SILVER, -P_BOW, HI_SILVER), -PROJECTILE("ya", "bamboo arrow", - 0, 15, 1, 4, 7, 7, 1, METAL, -P_BOW, HI_METAL), -PROJECTILE("crossbow bolt", (char *)0, - 1, 55, 1, 2, 4, 6, 0, IRON, -P_CROSSBOW, HI_METAL), + /* missiles */ + PROJECTILE("arrow", (char *) 0, 1, 55, 1, 2, 6, 6, 0, IRON, -P_BOW, + HI_METAL), + PROJECTILE("elven arrow", "runed arrow", 0, 20, 1, 2, 7, 6, 0, WOOD, + -P_BOW, HI_WOOD), + PROJECTILE("orcish arrow", "crude arrow", 0, 20, 1, 2, 5, 6, 0, IRON, + -P_BOW, CLR_BLACK), + PROJECTILE("silver arrow", (char *) 0, 1, 12, 1, 5, 6, 6, 0, + SILVER, -P_BOW, HI_SILVER), + PROJECTILE("ya", "bamboo arrow", 0, 15, 1, 4, 7, 7, 1, METAL, -P_BOW, + HI_METAL), + PROJECTILE("crossbow bolt", (char *) 0, 1, 55, 1, 2, 4, 6, 0, IRON, + -P_CROSSBOW, HI_METAL), -WEAPON("dart", (char *)0, - 1, 1, 0, 60, 1, 2, 3, 2, 0, P, -P_DART, IRON, HI_METAL), -WEAPON("shuriken", "throwing star", - 0, 1, 0, 35, 1, 5, 8, 6, 2, P, -P_SHURIKEN, IRON, HI_METAL), -WEAPON("boomerang", (char *)0, - 1, 1, 0, 15, 5, 20, 9, 9, 0, 0, -P_BOOMERANG, WOOD, HI_WOOD), + WEAPON("dart", (char *) 0, 1, 1, 0, 60, 1, 2, 3, 2, 0, P, -P_DART, + IRON, HI_METAL), + WEAPON("shuriken", "throwing star", 0, 1, 0, 35, 1, 5, 8, 6, 2, P, + -P_SHURIKEN, IRON, HI_METAL), + WEAPON("boomerang", (char *) 0, 1, 1, 0, 15, 5, 20, 9, 9, 0, 0, + -P_BOOMERANG, WOOD, HI_WOOD), -/* spears [note: javelin used to have a separate skill from spears, - because the latter are primarily stabbing weapons rather than - throwing ones; but for playability, they've been merged together - under spear skill and spears can now be thrown like javelins] */ -WEAPON("spear", (char *)0, - 1, 1, 0, 50, 30, 3, 6, 8, 0, P, P_SPEAR, IRON, HI_METAL), -WEAPON("elven spear", "runed spear", - 0, 1, 0, 10, 30, 3, 7, 8, 0, P, P_SPEAR, WOOD, HI_WOOD), -WEAPON("orcish spear", "crude spear", - 0, 1, 0, 13, 30, 3, 5, 8, 0, P, P_SPEAR, IRON, CLR_BLACK), -WEAPON("dwarvish spear", "stout spear", - 0, 1, 0, 12, 35, 3, 8, 8, 0, P, P_SPEAR, IRON, HI_METAL), -WEAPON("silver spear", (char *)0, - 1, 1, 0, 2, 36, 40, 6, 8, 0, P, P_SPEAR, SILVER, HI_SILVER), -WEAPON("javelin", "throwing spear", - 0, 1, 0, 10, 20, 3, 6, 6, 0, P, P_SPEAR, IRON, HI_METAL), + /* spears [note: javelin used to have a separate skill from spears, + because the latter are primarily stabbing weapons rather than + throwing ones; but for playability, they've been merged together + under spear skill and spears can now be thrown like javelins] */ + WEAPON("spear", (char *) 0, 1, 1, 0, 50, 30, 3, 6, 8, 0, P, P_SPEAR, + IRON, HI_METAL), + WEAPON("elven spear", "runed spear", 0, 1, 0, 10, 30, 3, 7, 8, 0, P, + P_SPEAR, WOOD, HI_WOOD), + WEAPON("orcish spear", "crude spear", 0, 1, 0, 13, 30, 3, 5, 8, 0, P, + P_SPEAR, IRON, CLR_BLACK), + WEAPON("dwarvish spear", "stout spear", 0, 1, 0, 12, 35, 3, 8, 8, 0, + P, P_SPEAR, IRON, HI_METAL), + WEAPON("silver spear", (char *) 0, 1, 1, 0, 2, 36, 40, 6, 8, 0, P, + P_SPEAR, SILVER, HI_SILVER), + WEAPON("javelin", "throwing spear", 0, 1, 0, 10, 20, 3, 6, 6, 0, P, + P_SPEAR, IRON, HI_METAL), -WEAPON("trident", (char *)0, - 1, 0, 0, 8, 25, 5, 6, 4, 0, P, P_TRIDENT, IRON, HI_METAL), - /* +1 small, +2d4 large */ + WEAPON("trident", (char *) 0, 1, 0, 0, 8, 25, 5, 6, 4, 0, P, + P_TRIDENT, IRON, HI_METAL), + /* +1 small, +2d4 large */ -/* blades */ -WEAPON("dagger", (char *)0, - 1, 1, 0, 30, 10, 4, 4, 3, 2, P, P_DAGGER, IRON, HI_METAL), -WEAPON("elven dagger", "runed dagger", - 0, 1, 0, 10, 10, 4, 5, 3, 2, P, P_DAGGER, WOOD, HI_WOOD), -WEAPON("orcish dagger", "crude dagger", - 0, 1, 0, 12, 10, 4, 3, 3, 2, P, P_DAGGER, IRON, CLR_BLACK), -WEAPON("silver dagger", (char *)0, - 1, 1, 0, 3, 12, 40, 4, 3, 2, P, P_DAGGER, SILVER, HI_SILVER), -WEAPON("athame", (char *)0, - 1, 1, 0, 0, 10, 4, 4, 3, 2, S, P_DAGGER, IRON, HI_METAL), -WEAPON("scalpel", (char *)0, - 1, 1, 0, 0, 5, 6, 3, 3, 2, S, P_KNIFE, METAL, HI_METAL), -WEAPON("knife", (char *)0, - 1, 1, 0, 20, 5, 4, 3, 2, 0, P|S, P_KNIFE, IRON, HI_METAL), -WEAPON("stiletto", (char *)0, - 1, 1, 0, 5, 5, 4, 3, 2, 0, P|S, P_KNIFE, IRON, HI_METAL), -WEAPON("worm tooth", (char *)0, - 1, 1, 0, 0, 20, 2, 2, 2, 0, 0, P_KNIFE, 0, CLR_WHITE), -WEAPON("crysknife", (char *)0, - 1, 1, 0, 0, 20,100, 10, 10, 3, P, P_KNIFE, MINERAL, CLR_WHITE), + /* blades */ + WEAPON("dagger", (char *) 0, 1, 1, 0, 30, 10, 4, 4, 3, 2, P, P_DAGGER, + IRON, HI_METAL), + WEAPON("elven dagger", "runed dagger", 0, 1, 0, 10, 10, 4, 5, 3, 2, P, + P_DAGGER, WOOD, HI_WOOD), + WEAPON("orcish dagger", "crude dagger", 0, 1, 0, 12, 10, 4, 3, 3, 2, + P, P_DAGGER, IRON, CLR_BLACK), + WEAPON("silver dagger", (char *) 0, 1, 1, 0, 3, 12, 40, 4, 3, 2, P, + P_DAGGER, SILVER, HI_SILVER), + WEAPON("athame", (char *) 0, 1, 1, 0, 0, 10, 4, 4, 3, 2, S, P_DAGGER, + IRON, HI_METAL), + WEAPON("scalpel", (char *) 0, 1, 1, 0, 0, 5, 6, 3, 3, 2, S, P_KNIFE, + METAL, HI_METAL), + WEAPON("knife", (char *) 0, 1, 1, 0, 20, 5, 4, 3, 2, 0, + P | S, P_KNIFE, IRON, HI_METAL), + WEAPON("stiletto", (char *) 0, 1, 1, 0, 5, 5, 4, 3, 2, 0, + P | S, P_KNIFE, IRON, HI_METAL), + WEAPON("worm tooth", (char *) 0, 1, 1, 0, 0, 20, 2, 2, 2, 0, 0, + P_KNIFE, 0, CLR_WHITE), + WEAPON("crysknife", (char *) 0, 1, 1, 0, 0, 20, 100, 10, 10, 3, P, + P_KNIFE, MINERAL, CLR_WHITE), -WEAPON("axe", (char *)0, - 1, 0, 0, 40, 60, 8, 6, 4, 0, S, P_AXE, IRON, HI_METAL), -WEAPON("battle-axe", "double-headed axe", - 0, 0, 1, 10,120, 40, 8, 6, 0, S, P_AXE, IRON, HI_METAL), - /* "double-bitted" ? */ + WEAPON("axe", (char *) 0, 1, 0, 0, 40, 60, 8, 6, 4, 0, S, P_AXE, IRON, + HI_METAL), + WEAPON("battle-axe", "double-headed axe", 0, 0, 1, 10, 120, 40, 8, 6, + 0, S, P_AXE, IRON, HI_METAL), + /* "double-bitted" ? */ -/* swords */ -WEAPON("short sword", (char *)0, - 1, 0, 0, 8, 30, 10, 6, 8, 0, P, P_SHORT_SWORD, IRON, HI_METAL), -WEAPON("elven short sword", "runed short sword", - 0, 0, 0, 2, 30, 10, 8, 8, 0, P, P_SHORT_SWORD, WOOD, HI_WOOD), -WEAPON("orcish short sword", "crude short sword", - 0, 0, 0, 3, 30, 10, 5, 8, 0, P, P_SHORT_SWORD, IRON, CLR_BLACK), -WEAPON("dwarvish short sword", "broad short sword", - 0, 0, 0, 2, 30, 10, 7, 8, 0, P, P_SHORT_SWORD, IRON, HI_METAL), -WEAPON("scimitar", "curved sword", - 0, 0, 0, 15, 40, 15, 8, 8, 0, S, P_SCIMITAR, IRON, HI_METAL), -WEAPON("silver saber", (char *)0, - 1, 0, 0, 6, 40, 75, 8, 8, 0, S, P_SABER, SILVER, HI_SILVER), -WEAPON("broadsword", (char *)0, - 1, 0, 0, 8, 70, 10, 4, 6, 0, S, P_BROAD_SWORD, IRON, HI_METAL), - /* +d4 small, +1 large */ -WEAPON("elven broadsword", "runed broadsword", - 0, 0, 0, 4, 70, 10, 6, 6, 0, S, P_BROAD_SWORD, WOOD, HI_WOOD), - /* +d4 small, +1 large */ -WEAPON("long sword", (char *)0, - 1, 0, 0, 50, 40, 15, 8, 12, 0, S, P_LONG_SWORD, IRON, HI_METAL), -WEAPON("two-handed sword", (char *)0, - 1, 0, 1, 22,150, 50, 12, 6, 0, S, P_TWO_HANDED_SWORD, IRON, HI_METAL), - /* +2d6 large */ -WEAPON("katana", "samurai sword", - 0, 0, 0, 4, 40, 80, 10, 12, 1, S, P_LONG_SWORD, IRON, HI_METAL), -/* special swords set up for artifacts */ -WEAPON("tsurugi", "long samurai sword", - 0, 0, 1, 0, 60,500, 16, 8, 2, S, P_TWO_HANDED_SWORD, METAL, HI_METAL), - /* +2d6 large */ -WEAPON("runesword", "runed broadsword", - 0, 0, 0, 0, 40,300, 4, 6, 0, S, P_BROAD_SWORD, IRON, CLR_BLACK), - /* +d4 small, +1 large */ - /* +5d2 +d8 from level drain */ + /* swords */ + WEAPON("short sword", (char *) 0, 1, 0, 0, 8, 30, 10, 6, 8, 0, P, + P_SHORT_SWORD, IRON, HI_METAL), + WEAPON("elven short sword", "runed short sword", 0, 0, 0, 2, + 30, 10, 8, 8, 0, P, P_SHORT_SWORD, WOOD, HI_WOOD), + WEAPON("orcish short sword", "crude short sword", 0, 0, 0, 3, + 30, 10, 5, 8, 0, P, P_SHORT_SWORD, IRON, CLR_BLACK), + WEAPON("dwarvish short sword", "broad short sword", 0, 0, 0, 2, + 30, 10, 7, 8, 0, P, P_SHORT_SWORD, IRON, HI_METAL), + WEAPON("scimitar", "curved sword", 0, 0, 0, 15, 40, 15, 8, 8, 0, S, + P_SCIMITAR, IRON, HI_METAL), + WEAPON("silver saber", (char *) 0, 1, 0, 0, 6, 40, 75, 8, 8, 0, S, + P_SABER, SILVER, HI_SILVER), + WEAPON("broadsword", (char *) 0, 1, 0, 0, 8, 70, 10, 4, 6, 0, S, + P_BROAD_SWORD, IRON, HI_METAL), + /* +d4 small, +1 large */ + WEAPON("elven broadsword", "runed broadsword", 0, 0, 0, 4, + 70, 10, 6, 6, 0, S, P_BROAD_SWORD, WOOD, HI_WOOD), + /* +d4 small, +1 large */ + WEAPON("long sword", (char *) 0, 1, 0, 0, 50, 40, 15, 8, 12, 0, S, + P_LONG_SWORD, IRON, HI_METAL), + WEAPON("two-handed sword", (char *) 0, 1, 0, 1, 22, 150, 50, 12, 6, 0, + S, P_TWO_HANDED_SWORD, IRON, HI_METAL), + /* +2d6 large */ + WEAPON("katana", "samurai sword", 0, 0, 0, 4, 40, 80, 10, 12, 1, S, + P_LONG_SWORD, IRON, HI_METAL), + /* special swords set up for artifacts */ + WEAPON("tsurugi", "long samurai sword", 0, 0, 1, 0, 60, 500, 16, 8, 2, + S, P_TWO_HANDED_SWORD, METAL, HI_METAL), + /* +2d6 large */ + WEAPON("runesword", "runed broadsword", 0, 0, 0, 0, 40, 300, 4, 6, 0, + S, P_BROAD_SWORD, IRON, CLR_BLACK), + /* +d4 small, +1 large */ + /* +5d2 +d8 from level drain */ -/* polearms */ -/* spear-type */ -WEAPON("partisan", "vulgar polearm", - 0, 0, 1, 5, 80, 10, 6, 6, 0, P, P_POLEARMS, IRON, HI_METAL), - /* +1 large */ -WEAPON("ranseur", "hilted polearm", - 0, 0, 1, 5, 50, 6, 4, 4, 0, P, P_POLEARMS, IRON, HI_METAL), - /* +d4 both */ -WEAPON("spetum", "forked polearm", - 0, 0, 1, 5, 50, 5, 6, 6, 0, P, P_POLEARMS, IRON, HI_METAL), - /* +1 small, +d6 large */ -WEAPON("glaive", "single-edged polearm", - 0, 0, 1, 8, 75, 6, 6, 10, 0, S, P_POLEARMS, IRON, HI_METAL), -WEAPON("lance", (char *)0, - 1, 0, 0, 4,180, 10, 6, 8, 0, P, P_LANCE, IRON, HI_METAL), -/* axe-type */ -WEAPON("halberd", "angled poleaxe", - 0, 0, 1, 8,150, 10, 10, 6, 0, P|S, P_POLEARMS, IRON, HI_METAL), - /* +1d6 large */ -WEAPON("bardiche", "long poleaxe", - 0, 0, 1, 4,120, 7, 4, 4, 0, S, P_POLEARMS, IRON, HI_METAL), - /* +1d4 small, +2d4 large */ -WEAPON("voulge", "pole cleaver", - 0, 0, 1, 4,125, 5, 4, 4, 0, S, P_POLEARMS, IRON, HI_METAL), - /* +d4 both */ -WEAPON("dwarvish mattock", "broad pick", - 0, 0, 1, 13,120, 50, 12, 8,-1, B, P_PICK_AXE, IRON, HI_METAL), + /* polearms */ + /* spear-type */ + WEAPON("partisan", "vulgar polearm", 0, 0, 1, 5, 80, 10, 6, 6, 0, P, + P_POLEARMS, IRON, HI_METAL), + /* +1 large */ + WEAPON("ranseur", "hilted polearm", 0, 0, 1, 5, 50, 6, 4, 4, 0, P, + P_POLEARMS, IRON, HI_METAL), + /* +d4 both */ + WEAPON("spetum", "forked polearm", 0, 0, 1, 5, 50, 5, 6, 6, 0, P, + P_POLEARMS, IRON, HI_METAL), + /* +1 small, +d6 large */ + WEAPON("glaive", "single-edged polearm", 0, 0, 1, 8, 75, 6, 6, + 10, 0, S, P_POLEARMS, IRON, HI_METAL), + WEAPON("lance", (char *) 0, 1, 0, 0, 4, 180, 10, 6, 8, 0, P, P_LANCE, + IRON, HI_METAL), + /* axe-type */ + WEAPON("halberd", "angled poleaxe", 0, 0, 1, 8, 150, 10, 10, 6, 0, + P | S, P_POLEARMS, IRON, HI_METAL), + /* +1d6 large */ + WEAPON("bardiche", "long poleaxe", 0, 0, 1, 4, 120, 7, 4, 4, 0, S, + P_POLEARMS, IRON, HI_METAL), + /* +1d4 small, +2d4 large */ + WEAPON("voulge", "pole cleaver", 0, 0, 1, 4, 125, 5, 4, 4, 0, S, + P_POLEARMS, IRON, HI_METAL), + /* +d4 both */ + WEAPON("dwarvish mattock", "broad pick", 0, 0, 1, 13, 120, + 50, 12, 8, -1, B, P_PICK_AXE, IRON, HI_METAL), -/* curved/hooked */ -WEAPON("fauchard", "pole sickle", - 0, 0, 1, 6, 60, 5, 6, 8, 0, P|S, P_POLEARMS, IRON, HI_METAL), -WEAPON("guisarme", "pruning hook", - 0, 0, 1, 6, 80, 5, 4, 8, 0, S, P_POLEARMS, IRON, HI_METAL), - /* +1d4 small */ -WEAPON("bill-guisarme", "hooked polearm", - 0, 0, 1, 4,120, 7, 4, 10, 0, P|S, P_POLEARMS, IRON, HI_METAL), - /* +1d4 small */ -/* other */ -WEAPON("lucern hammer", "pronged polearm", - 0, 0, 1, 5,150, 7, 4, 6, 0, B|P, P_POLEARMS, IRON, HI_METAL), - /* +1d4 small */ -WEAPON("bec de corbin", "beaked polearm", - 0, 0, 1, 4,100, 8, 8, 6, 0, B|P, P_POLEARMS, IRON, HI_METAL), + /* curved/hooked */ + WEAPON("fauchard", "pole sickle", 0, 0, 1, 6, 60, 5, 6, 8, 0, + P | S, P_POLEARMS, IRON, HI_METAL), + WEAPON("guisarme", "pruning hook", 0, 0, 1, 6, 80, 5, 4, 8, 0, S, + P_POLEARMS, IRON, HI_METAL), + /* +1d4 small */ + WEAPON("bill-guisarme", "hooked polearm", 0, 0, 1, 4, 120, 7, 4, + 10, 0, P | S, P_POLEARMS, IRON, HI_METAL), + /* +1d4 small */ + /* other */ + WEAPON("lucern hammer", "pronged polearm", 0, 0, 1, 5, 150, 7, 4, 6, + 0, B | P, P_POLEARMS, IRON, HI_METAL), + /* +1d4 small */ + WEAPON("bec de corbin", "beaked polearm", 0, 0, 1, 4, 100, 8, 8, 6, 0, + B | P, P_POLEARMS, IRON, HI_METAL), -/* bludgeons */ -WEAPON("mace", (char *)0, - 1, 0, 0, 40, 30, 5, 6, 6, 0, B, P_MACE, IRON, HI_METAL), - /* +1 small */ -WEAPON("morning star", (char *)0, - 1, 0, 0, 12,120, 10, 4, 6, 0, B, P_MORNING_STAR, IRON, HI_METAL), - /* +d4 small, +1 large */ -WEAPON("war hammer", (char *)0, - 1, 0, 0, 15, 50, 5, 4, 4, 0, B, P_HAMMER, IRON, HI_METAL), - /* +1 small */ -WEAPON("club", (char *)0, - 1, 0, 0, 12, 30, 3, 6, 3, 0, B, P_CLUB, WOOD, HI_WOOD), -WEAPON("rubber hose", (char *)0, - 1, 0, 0, 0, 20, 3, 4, 3, 0, B, P_WHIP, PLASTIC, CLR_BROWN), -WEAPON("quarterstaff", "staff", - 0, 0, 1, 11, 40, 5, 6, 6, 0, B, P_QUARTERSTAFF, WOOD, HI_WOOD), -/* two-piece */ -WEAPON("aklys", "thonged club", - 0, 0, 0, 8, 15, 4, 6, 3, 0, B, P_CLUB, IRON, HI_METAL), -WEAPON("flail", (char *)0, - 1, 0, 0, 40, 15, 4, 6, 4, 0, B, P_FLAIL, IRON, HI_METAL), - /* +1 small, +1d4 large */ -/* misc */ -WEAPON("bullwhip", (char *)0, - 1, 0, 0, 2, 20, 4, 2, 1, 0, 0, P_WHIP, LEATHER, CLR_BROWN), + /* bludgeons */ + WEAPON("mace", (char *) 0, 1, 0, 0, 40, 30, 5, 6, 6, 0, B, P_MACE, + IRON, HI_METAL), + /* +1 small */ + WEAPON("morning star", (char *) 0, 1, 0, 0, 12, 120, 10, 4, 6, 0, B, + P_MORNING_STAR, IRON, HI_METAL), + /* +d4 small, +1 large */ + WEAPON("war hammer", (char *) 0, 1, 0, 0, 15, 50, 5, 4, 4, 0, B, + P_HAMMER, IRON, HI_METAL), + /* +1 small */ + WEAPON("club", (char *) 0, 1, 0, 0, 12, 30, 3, 6, 3, 0, B, P_CLUB, + WOOD, HI_WOOD), + WEAPON("rubber hose", (char *) 0, 1, 0, 0, 0, 20, 3, 4, 3, 0, B, + P_WHIP, PLASTIC, CLR_BROWN), + WEAPON("quarterstaff", "staff", 0, 0, 1, 11, 40, 5, 6, 6, 0, B, + P_QUARTERSTAFF, WOOD, HI_WOOD), + /* two-piece */ + WEAPON("aklys", "thonged club", 0, 0, 0, 8, 15, 4, 6, 3, 0, B, P_CLUB, + IRON, HI_METAL), + WEAPON("flail", (char *) 0, 1, 0, 0, 40, 15, 4, 6, 4, 0, B, P_FLAIL, + IRON, HI_METAL), + /* +1 small, +1d4 large */ + /* misc */ + WEAPON("bullwhip", (char *) 0, 1, 0, 0, 2, 20, 4, 2, 1, 0, 0, P_WHIP, + LEATHER, CLR_BROWN), -/* bows */ -BOW("bow", (char *)0, 1, 24, 30, 60, 0, WOOD, P_BOW, HI_WOOD), -BOW("elven bow", "runed bow", 0, 12, 30, 60, 0, WOOD, P_BOW, HI_WOOD), -BOW("orcish bow", "crude bow", 0, 12, 30, 60, 0, WOOD, P_BOW, CLR_BLACK), -BOW("yumi", "long bow", 0, 0, 30, 60, 0, WOOD, P_BOW, HI_WOOD), -BOW("sling", (char *)0, 1, 40, 3, 20, 0, LEATHER, P_SLING, HI_LEATHER), -BOW("crossbow", (char *)0, 1, 45, 50, 40, 0, WOOD, P_CROSSBOW, HI_WOOD), + /* bows */ + BOW("bow", (char *) 0, 1, 24, 30, 60, 0, WOOD, P_BOW, HI_WOOD), + BOW("elven bow", "runed bow", 0, 12, 30, 60, 0, WOOD, P_BOW, HI_WOOD), + BOW("orcish bow", "crude bow", 0, 12, 30, 60, 0, WOOD, P_BOW, + CLR_BLACK), + BOW("yumi", "long bow", 0, 0, 30, 60, 0, WOOD, P_BOW, HI_WOOD), + BOW("sling", (char *) 0, 1, 40, 3, 20, 0, LEATHER, P_SLING, + HI_LEATHER), + BOW("crossbow", (char *) 0, 1, 45, 50, 40, 0, WOOD, P_CROSSBOW, + HI_WOOD), #undef P #undef S @@ -277,47 +292,56 @@ BOW("crossbow", (char *)0, 1, 45, 50, 40, 0, WOOD, P_CROSSBOW, HI_WOOD), * Only COPPER (including brass) corrodes. * Some creatures are vulnerable to SILVER. */ -#define ARMOR(name,desc,kn,mgc,blk,power,prob,delay,wt,cost,ac,can,sub,metal,c) \ - OBJECT( \ - OBJ(name,desc), BITS(kn,0,1,0,mgc,1,0,0,blk,0,0,sub,metal), power, \ - ARMOR_CLASS, prob, delay, wt, cost, \ - 0, 0, 10 - ac, can, wt, c ) -#define HELM(name,desc,kn,mgc,power,prob,delay,wt,cost,ac,can,metal,c) \ - ARMOR(name,desc,kn,mgc,0,power,prob,delay,wt,cost,ac,can,ARM_HELM,metal,c) -#define CLOAK(name,desc,kn,mgc,power,prob,delay,wt,cost,ac,can,metal,c) \ - ARMOR(name,desc,kn,mgc,0,power,prob,delay,wt,cost,ac,can,ARM_CLOAK,metal,c) -#define SHIELD(name,desc,kn,mgc,blk,power,prob,delay,wt,cost,ac,can,metal,c) \ - ARMOR(name,desc,kn,mgc,blk,power,prob,delay,wt,cost,ac,can,ARM_SHIELD,metal,c) -#define GLOVES(name,desc,kn,mgc,power,prob,delay,wt,cost,ac,can,metal,c) \ - ARMOR(name,desc,kn,mgc,0,power,prob,delay,wt,cost,ac,can,ARM_GLOVES,metal,c) -#define BOOTS(name,desc,kn,mgc,power,prob,delay,wt,cost,ac,can,metal,c) \ - ARMOR(name,desc,kn,mgc,0,power,prob,delay,wt,cost,ac,can,ARM_BOOTS,metal,c) +#define ARMOR(name, desc, kn, mgc, blk, power, prob, delay, wt, cost, ac, \ + can, sub, metal, c) \ + OBJECT(OBJ(name, desc), \ + BITS(kn, 0, 1, 0, mgc, 1, 0, 0, blk, 0, 0, sub, metal), power, \ + ARMOR_CLASS, prob, delay, wt, cost, 0, 0, 10 - ac, can, wt, c) +#define HELM(name, desc, kn, mgc, power, prob, delay, wt, cost, ac, can, \ + metal, c) \ + ARMOR(name, desc, kn, mgc, 0, power, prob, delay, wt, cost, ac, can, \ + ARM_HELM, metal, c) +#define CLOAK(name, desc, kn, mgc, power, prob, delay, wt, cost, ac, can, \ + metal, c) \ + ARMOR(name, desc, kn, mgc, 0, power, prob, delay, wt, cost, ac, can, \ + ARM_CLOAK, metal, c) +#define SHIELD(name, desc, kn, mgc, blk, power, prob, delay, wt, cost, ac, \ + can, metal, c) \ + ARMOR(name, desc, kn, mgc, blk, power, prob, delay, wt, cost, ac, can, \ + ARM_SHIELD, metal, c) +#define GLOVES(name, desc, kn, mgc, power, prob, delay, wt, cost, ac, can, \ + metal, c) \ + ARMOR(name, desc, kn, mgc, 0, power, prob, delay, wt, cost, ac, can, \ + ARM_GLOVES, metal, c) +#define BOOTS(name, desc, kn, mgc, power, prob, delay, wt, cost, ac, can, \ + metal, c) \ + ARMOR(name, desc, kn, mgc, 0, power, prob, delay, wt, cost, ac, can, \ + ARM_BOOTS, metal, c) -/* helmets */ -HELM("elven leather helm", "leather hat", - 0, 0, 0, 6, 1, 3, 8, 9, 0, LEATHER, HI_LEATHER), -HELM("orcish helm", "iron skull cap", - 0, 0, 0, 6, 1, 30, 10, 9, 0, IRON, CLR_BLACK), -HELM("dwarvish iron helm", "hard hat", - 0, 0, 0, 6, 1, 40, 20, 8, 0, IRON, HI_METAL), -HELM("fedora", (char *)0, - 1, 0, 0, 0, 0, 3, 1,10, 0, CLOTH, CLR_BROWN), -HELM("cornuthaum", "conical hat", - 0, 1, CLAIRVOYANT, - 3, 1, 4, 80,10, 1, CLOTH, CLR_BLUE), -HELM("dunce cap", "conical hat", - 0, 1, 0, 3, 1, 4, 1,10, 0, CLOTH, CLR_BLUE), -HELM("dented pot", (char *)0, - 1, 0, 0, 2, 0, 10, 8, 9, 0, IRON, CLR_BLACK), -/* With shuffled appearances... */ -HELM("helmet", "plumed helmet", - 0, 0, 0, 10, 1, 30, 10, 9, 0, IRON, HI_METAL), -HELM("helm of brilliance", "etched helmet", - 0, 1, 0, 6, 1, 50, 50, 9, 0, IRON, CLR_GREEN), -HELM("helm of opposite alignment", "crested helmet", - 0, 1, 0, 6, 1, 50, 50, 9, 0, IRON, HI_METAL), -HELM("helm of telepathy", "visored helmet", - 0, 1, TELEPAT, 2, 1, 50, 50, 9, 0, IRON, HI_METAL), + /* helmets */ + HELM("elven leather helm", "leather hat", 0, 0, 0, 6, 1, 3, 8, 9, 0, + LEATHER, HI_LEATHER), + HELM("orcish helm", "iron skull cap", 0, 0, 0, 6, 1, 30, 10, 9, 0, + IRON, CLR_BLACK), + HELM("dwarvish iron helm", "hard hat", 0, 0, 0, 6, 1, 40, 20, 8, 0, + IRON, HI_METAL), + HELM("fedora", (char *) 0, 1, 0, 0, 0, 0, 3, 1, 10, 0, CLOTH, + CLR_BROWN), + HELM("cornuthaum", "conical hat", 0, 1, CLAIRVOYANT, 3, 1, 4, + 80, 10, 1, CLOTH, CLR_BLUE), + HELM("dunce cap", "conical hat", 0, 1, 0, 3, 1, 4, 1, 10, 0, CLOTH, + CLR_BLUE), + HELM("dented pot", (char *) 0, 1, 0, 0, 2, 0, 10, 8, 9, 0, IRON, + CLR_BLACK), + /* With shuffled appearances... */ + HELM("helmet", "plumed helmet", 0, 0, 0, 10, 1, 30, 10, 9, 0, IRON, + HI_METAL), + HELM("helm of brilliance", "etched helmet", 0, 1, 0, 6, 1, 50, 50, 9, + 0, IRON, CLR_GREEN), + HELM("helm of opposite alignment", "crested helmet", 0, 1, 0, 6, 1, + 50, 50, 9, 0, IRON, HI_METAL), + HELM("helm of telepathy", "visored helmet", 0, 1, TELEPAT, 2, 1, + 50, 50, 9, 0, IRON, HI_METAL), /* suits of armor */ /* @@ -328,156 +352,164 @@ HELM("helm of telepathy", "visored helmet", * (2) That the order of the dragon scale mail and dragon scales is the * the same defined in monst.c. */ -#define DRGN_ARMR(name,mgc,power,cost,ac,color) \ - ARMOR(name,(char *)0,1,mgc,1,power,0,5,40,cost,ac,0,ARM_SUIT,DRAGON_HIDE,color) -/* 3.4.1: dragon scale mail reclassified as "magic" since magic is - needed to create them */ -DRGN_ARMR("gray dragon scale mail", 1, ANTIMAGIC, 1200, 1, CLR_GRAY), -DRGN_ARMR("silver dragon scale mail", 1, REFLECTING, 1200, 1, DRAGON_SILVER), -#if 0 /* DEFERRED */ +#define DRGN_ARMR(name, mgc, power, cost, ac, color) \ + ARMOR(name, (char *) 0, 1, mgc, 1, power, 0, 5, 40, cost, ac, 0, \ + ARM_SUIT, DRAGON_HIDE, color) + /* 3.4.1: dragon scale mail reclassified as "magic" since magic is + needed to create them */ + DRGN_ARMR("gray dragon scale mail", 1, ANTIMAGIC, 1200, 1, CLR_GRAY), + DRGN_ARMR("silver dragon scale mail", 1, REFLECTING, 1200, 1, + DRAGON_SILVER), +#if 0 /* DEFERRED */ DRGN_ARMR("shimmering dragon scale mail", 1, DISPLACED, 1200, 1, CLR_CYAN), #endif -DRGN_ARMR("red dragon scale mail", 1, FIRE_RES, 900, 1, CLR_RED), -DRGN_ARMR("white dragon scale mail", 1, COLD_RES, 900, 1, CLR_WHITE), -DRGN_ARMR("orange dragon scale mail", 1, SLEEP_RES, 900, 1, CLR_ORANGE), -DRGN_ARMR("black dragon scale mail", 1, DISINT_RES, 1200, 1, CLR_BLACK), -DRGN_ARMR("blue dragon scale mail", 1, SHOCK_RES, 900, 1, CLR_BLUE), -DRGN_ARMR("green dragon scale mail", 1, POISON_RES, 900, 1, CLR_GREEN), -DRGN_ARMR("yellow dragon scale mail", 1, ACID_RES, 900, 1, CLR_YELLOW), + DRGN_ARMR("red dragon scale mail", 1, FIRE_RES, 900, 1, CLR_RED), + DRGN_ARMR("white dragon scale mail", 1, COLD_RES, 900, 1, CLR_WHITE), + DRGN_ARMR("orange dragon scale mail", 1, SLEEP_RES, 900, 1, + CLR_ORANGE), + DRGN_ARMR("black dragon scale mail", 1, DISINT_RES, 1200, 1, + CLR_BLACK), + DRGN_ARMR("blue dragon scale mail", 1, SHOCK_RES, 900, 1, CLR_BLUE), + DRGN_ARMR("green dragon scale mail", 1, POISON_RES, 900, 1, + CLR_GREEN), + DRGN_ARMR("yellow dragon scale mail", 1, ACID_RES, 900, 1, + CLR_YELLOW), -/* For now, only dragons leave these. */ -/* 3.4.1: dragon scales left classified as "non-magic"; they confer - magical properties but are produced "naturally" */ -DRGN_ARMR("gray dragon scales", 0, ANTIMAGIC, 700, 7, CLR_GRAY), -DRGN_ARMR("silver dragon scales", 0, REFLECTING, 700, 7, DRAGON_SILVER), -#if 0 /* DEFERRED */ + /* For now, only dragons leave these. */ + /* 3.4.1: dragon scales left classified as "non-magic"; they confer + magical properties but are produced "naturally" */ + DRGN_ARMR("gray dragon scales", 0, ANTIMAGIC, 700, 7, CLR_GRAY), + DRGN_ARMR("silver dragon scales", 0, REFLECTING, 700, 7, + DRAGON_SILVER), +#if 0 /* DEFERRED */ DRGN_ARMR("shimmering dragon scales", 0, DISPLACED, 700, 7, CLR_CYAN), #endif -DRGN_ARMR("red dragon scales", 0, FIRE_RES, 500, 7, CLR_RED), -DRGN_ARMR("white dragon scales", 0, COLD_RES, 500, 7, CLR_WHITE), -DRGN_ARMR("orange dragon scales", 0, SLEEP_RES, 500, 7, CLR_ORANGE), -DRGN_ARMR("black dragon scales", 0, DISINT_RES, 700, 7, CLR_BLACK), -DRGN_ARMR("blue dragon scales", 0, SHOCK_RES, 500, 7, CLR_BLUE), -DRGN_ARMR("green dragon scales", 0, POISON_RES, 500, 7, CLR_GREEN), -DRGN_ARMR("yellow dragon scales", 0, ACID_RES, 500, 7, CLR_YELLOW), + DRGN_ARMR("red dragon scales", 0, FIRE_RES, 500, 7, CLR_RED), + DRGN_ARMR("white dragon scales", 0, COLD_RES, 500, 7, CLR_WHITE), + DRGN_ARMR("orange dragon scales", 0, SLEEP_RES, 500, 7, CLR_ORANGE), + DRGN_ARMR("black dragon scales", 0, DISINT_RES, 700, 7, CLR_BLACK), + DRGN_ARMR("blue dragon scales", 0, SHOCK_RES, 500, 7, CLR_BLUE), + DRGN_ARMR("green dragon scales", 0, POISON_RES, 500, 7, CLR_GREEN), + DRGN_ARMR("yellow dragon scales", 0, ACID_RES, 500, 7, CLR_YELLOW), #undef DRGN_ARMR -ARMOR("plate mail", (char *)0, - 1, 0, 1, 0, 44, 5, 450, 600, 3, 2, ARM_SUIT, IRON, HI_METAL), -ARMOR("crystal plate mail", (char *)0, - 1, 0, 1, 0, 10, 5, 450, 820, 3, 2, ARM_SUIT, GLASS, CLR_WHITE), -ARMOR("bronze plate mail", (char *)0, - 1, 0, 1, 0, 25, 5, 450, 400, 4, 1, ARM_SUIT, COPPER, HI_COPPER), -ARMOR("splint mail", (char *)0, - 1, 0, 1, 0, 62, 5, 400, 80, 4, 1, ARM_SUIT, IRON, HI_METAL), -ARMOR("banded mail", (char *)0, - 1, 0, 1, 0, 72, 5, 350, 90, 4, 1, ARM_SUIT, IRON, HI_METAL), -ARMOR("dwarvish mithril-coat", (char *)0, - 1, 0, 0, 0, 10, 1, 150, 240, 4, 2, ARM_SUIT, MITHRIL, HI_SILVER), -ARMOR("elven mithril-coat", (char *)0, - 1, 0, 0, 0, 15, 1, 150, 240, 5, 2, ARM_SUIT, MITHRIL, HI_SILVER), -ARMOR("chain mail", (char *)0, - 1, 0, 0, 0, 72, 5, 300, 75, 5, 1, ARM_SUIT, IRON, HI_METAL), -ARMOR("orcish chain mail", "crude chain mail", - 0, 0, 0, 0, 20, 5, 300, 75, 6, 1, ARM_SUIT, IRON, CLR_BLACK), -ARMOR("scale mail", (char *)0, - 1, 0, 0, 0, 72, 5, 250, 45, 6, 1, ARM_SUIT, IRON, HI_METAL), -ARMOR("studded leather armor", (char *)0, - 1, 0, 0, 0, 72, 3, 200, 15, 7, 1, ARM_SUIT, LEATHER, HI_LEATHER), -ARMOR("ring mail", (char *)0, - 1, 0, 0, 0, 72, 5, 250, 100, 7, 1, ARM_SUIT, IRON, HI_METAL), -ARMOR("orcish ring mail", "crude ring mail", - 0, 0, 0, 0, 20, 5, 250, 80, 8, 1, ARM_SUIT, IRON, CLR_BLACK), -ARMOR("leather armor", (char *)0, - 1, 0, 0, 0, 82, 3, 150, 5, 8, 1, ARM_SUIT, LEATHER, HI_LEATHER), -ARMOR("leather jacket", (char *)0, - 1, 0, 0, 0, 12, 0, 30, 10, 9, 0, ARM_SUIT, LEATHER, CLR_BLACK), + ARMOR("plate mail", (char *) 0, 1, 0, 1, 0, 44, 5, 450, 600, 3, + 2, ARM_SUIT, IRON, HI_METAL), + ARMOR("crystal plate mail", (char *) 0, 1, 0, 1, 0, 10, 5, 450, 820, + 3, 2, ARM_SUIT, GLASS, CLR_WHITE), + ARMOR("bronze plate mail", (char *) 0, 1, 0, 1, 0, 25, 5, 450, 400, 4, + 1, ARM_SUIT, COPPER, HI_COPPER), + ARMOR("splint mail", (char *) 0, 1, 0, 1, 0, 62, 5, 400, 80, 4, + 1, ARM_SUIT, IRON, HI_METAL), + ARMOR("banded mail", (char *) 0, 1, 0, 1, 0, 72, 5, 350, 90, 4, + 1, ARM_SUIT, IRON, HI_METAL), + ARMOR("dwarvish mithril-coat", (char *) 0, 1, 0, 0, 0, 10, 1, 150, + 240, 4, 2, ARM_SUIT, MITHRIL, HI_SILVER), + ARMOR("elven mithril-coat", (char *) 0, 1, 0, 0, 0, 15, 1, 150, 240, + 5, 2, ARM_SUIT, MITHRIL, HI_SILVER), + ARMOR("chain mail", (char *) 0, 1, 0, 0, 0, 72, 5, 300, 75, 5, + 1, ARM_SUIT, IRON, HI_METAL), + ARMOR("orcish chain mail", "crude chain mail", 0, 0, 0, 0, 20, 5, 300, + 75, 6, 1, ARM_SUIT, IRON, CLR_BLACK), + ARMOR("scale mail", (char *) 0, 1, 0, 0, 0, 72, 5, 250, 45, 6, + 1, ARM_SUIT, IRON, HI_METAL), + ARMOR("studded leather armor", (char *) 0, 1, 0, 0, 0, 72, 3, 200, + 15, 7, 1, ARM_SUIT, LEATHER, HI_LEATHER), + ARMOR("ring mail", (char *) 0, 1, 0, 0, 0, 72, 5, 250, 100, 7, + 1, ARM_SUIT, IRON, HI_METAL), + ARMOR("orcish ring mail", "crude ring mail", 0, 0, 0, 0, 20, 5, 250, + 80, 8, 1, ARM_SUIT, IRON, CLR_BLACK), + ARMOR("leather armor", (char *) 0, 1, 0, 0, 0, 82, 3, 150, 5, + 8, 1, ARM_SUIT, LEATHER, HI_LEATHER), + ARMOR("leather jacket", (char *) 0, 1, 0, 0, 0, 12, 0, 30, 10, 9, + 0, ARM_SUIT, LEATHER, CLR_BLACK), -/* shirts */ -ARMOR("Hawaiian shirt", (char *)0, - 1, 0, 0, 0, 8, 0, 5, 3, 10, 0, ARM_SHIRT, CLOTH, CLR_MAGENTA), -ARMOR("T-shirt", (char *)0, - 1, 0, 0, 0, 2, 0, 5, 2, 10, 0, ARM_SHIRT, CLOTH, CLR_WHITE), + /* shirts */ + ARMOR("Hawaiian shirt", (char *) 0, 1, 0, 0, 0, 8, 0, 5, 3, 10, 0, + ARM_SHIRT, CLOTH, CLR_MAGENTA), + ARMOR("T-shirt", (char *) 0, 1, 0, 0, 0, 2, 0, 5, 2, 10, 0, ARM_SHIRT, + CLOTH, CLR_WHITE), -/* cloaks */ -/* 'cope' is not a spelling mistake... leave it be */ -CLOAK("mummy wrapping", (char *)0, - 1, 0, 0, 0, 0, 3, 2, 10, 1, CLOTH, CLR_GRAY), -CLOAK("elven cloak", "faded pall", - 0, 1, STEALTH, 8, 0, 10, 60, 9, 1, CLOTH, CLR_BLACK), -CLOAK("orcish cloak", "coarse mantelet", - 0, 0, 0, 8, 0, 10, 40, 10, 1, CLOTH, CLR_BLACK), -CLOAK("dwarvish cloak", "hooded cloak", - 0, 0, 0, 8, 0, 10, 50, 10, 1, CLOTH, HI_CLOTH), -CLOAK("oilskin cloak", "slippery cloak", - 0, 0, 0, 8, 0, 10, 50, 9, 2, CLOTH, HI_CLOTH), -CLOAK("robe", (char *)0, - 1, 1, 0, 3, 0, 15, 50, 8, 2, CLOTH, CLR_RED), -CLOAK("alchemy smock", "apron", - 0, 1, POISON_RES, 9, 0, 10, 50, 9, 1, CLOTH, CLR_WHITE), -CLOAK("leather cloak", (char *)0, - 1, 0, 0, 8, 0, 15, 40, 9, 1, LEATHER, CLR_BROWN), -/* With shuffled appearances... */ -CLOAK("cloak of protection", "tattered cape", - 0, 1, PROTECTION, 9, 0, 10, 50, 7, 3, CLOTH, HI_CLOTH), -CLOAK("cloak of invisibility", "opera cloak", - 0, 1, INVIS, 10, 0, 10, 60, 9, 1, CLOTH, CLR_BRIGHT_MAGENTA), -CLOAK("cloak of magic resistance", "ornamental cope", - 0, 1, ANTIMAGIC, 2, 0, 10, 60, 9, 1, CLOTH, CLR_WHITE), -CLOAK("cloak of displacement", "piece of cloth", - 0, 1, DISPLACED, 10, 0, 10, 50, 9, 1, CLOTH, HI_CLOTH), + /* cloaks */ + /* 'cope' is not a spelling mistake... leave it be */ + CLOAK("mummy wrapping", (char *) 0, 1, 0, 0, 0, 0, 3, 2, 10, 1, CLOTH, + CLR_GRAY), + CLOAK("elven cloak", "faded pall", 0, 1, STEALTH, 8, 0, 10, 60, 9, + 1, CLOTH, CLR_BLACK), + CLOAK("orcish cloak", "coarse mantelet", 0, 0, 0, 8, 0, 10, 40, 10, 1, + CLOTH, CLR_BLACK), + CLOAK("dwarvish cloak", "hooded cloak", 0, 0, 0, 8, 0, 10, 50, 10, 1, + CLOTH, HI_CLOTH), + CLOAK("oilskin cloak", "slippery cloak", 0, 0, 0, 8, 0, 10, 50, 9, + 2, CLOTH, HI_CLOTH), + CLOAK("robe", (char *) 0, 1, 1, 0, 3, 0, 15, 50, 8, 2, CLOTH, + CLR_RED), + CLOAK("alchemy smock", "apron", 0, 1, POISON_RES, 9, 0, 10, 50, 9, + 1, CLOTH, CLR_WHITE), + CLOAK("leather cloak", (char *) 0, 1, 0, 0, 8, 0, 15, 40, 9, + 1, LEATHER, CLR_BROWN), + /* With shuffled appearances... */ + CLOAK("cloak of protection", "tattered cape", 0, 1, PROTECTION, 9, + 0, 10, 50, 7, 3, CLOTH, HI_CLOTH), + CLOAK("cloak of invisibility", "opera cloak", 0, 1, INVIS, 10, 0, + 10, 60, 9, 1, CLOTH, CLR_BRIGHT_MAGENTA), + CLOAK("cloak of magic resistance", "ornamental cope", 0, 1, ANTIMAGIC, + 2, 0, 10, 60, 9, 1, CLOTH, CLR_WHITE), + CLOAK("cloak of displacement", "piece of cloth", 0, 1, DISPLACED, + 10, 0, 10, 50, 9, 1, CLOTH, HI_CLOTH), -/* shields */ -SHIELD("small shield", (char *)0, - 1, 0, 0, 0, 6, 0, 30, 3, 9, 0, WOOD, HI_WOOD), -SHIELD("elven shield", "blue and green shield", - 0, 0, 0, 0, 2, 0, 40, 7, 8, 0, WOOD, CLR_GREEN), -SHIELD("Uruk-hai shield", "white-handed shield", - 0, 0, 0, 0, 2, 0, 50, 7, 9, 0, IRON, HI_METAL), -SHIELD("orcish shield", "red-eyed shield", - 0, 0, 0, 0, 2, 0, 50, 7, 9, 0, IRON, CLR_RED), -SHIELD("large shield", (char *)0, - 1, 0, 1, 0, 7, 0,100, 10, 8, 0, IRON, HI_METAL), -SHIELD("dwarvish roundshield", "large round shield", - 0, 0, 0, 0, 4, 0,100, 10, 8, 0, IRON, HI_METAL), -SHIELD("shield of reflection", "polished silver shield", - 0, 1, 0, REFLECTING, 3, 0, 50, 50, 8, 0, SILVER, HI_SILVER), + /* shields */ + SHIELD("small shield", (char *) 0, 1, 0, 0, 0, 6, 0, 30, 3, 9, 0, + WOOD, HI_WOOD), + SHIELD("elven shield", "blue and green shield", 0, 0, 0, 0, 2, 0, + 40, 7, 8, 0, WOOD, CLR_GREEN), + SHIELD("Uruk-hai shield", "white-handed shield", 0, 0, 0, 0, 2, 0, + 50, 7, 9, 0, IRON, HI_METAL), + SHIELD("orcish shield", "red-eyed shield", 0, 0, 0, 0, 2, 0, 50, 7, 9, + 0, IRON, CLR_RED), + SHIELD("large shield", (char *) 0, 1, 0, 1, 0, 7, 0, 100, 10, 8, 0, + IRON, HI_METAL), + SHIELD("dwarvish roundshield", "large round shield", 0, 0, 0, 0, 4, 0, + 100, 10, 8, 0, IRON, HI_METAL), + SHIELD("shield of reflection", "polished silver shield", 0, 1, 0, + REFLECTING, 3, 0, 50, 50, 8, 0, SILVER, HI_SILVER), -/* gloves */ -/* these have their color but not material shuffled, so the IRON must stay - * CLR_BROWN (== HI_LEATHER) - */ -GLOVES("leather gloves", "old gloves", - 0, 0, 0, 16, 1, 10, 8, 9, 0, LEATHER, HI_LEATHER), -GLOVES("gauntlets of fumbling", "padded gloves", - 0, 1, FUMBLING, 8, 1, 10, 50, 9, 0, LEATHER, HI_LEATHER), -GLOVES("gauntlets of power", "riding gloves", - 0, 1, 0, 8, 1, 30, 50, 9, 0, IRON, CLR_BROWN), -GLOVES("gauntlets of dexterity", "fencing gloves", - 0, 1, 0, 8, 1, 10, 50, 9, 0, LEATHER, HI_LEATHER), + /* gloves */ + /* these have their color but not material shuffled, so the IRON must + * stay + * CLR_BROWN (== HI_LEATHER) + */ + GLOVES("leather gloves", "old gloves", 0, 0, 0, 16, 1, 10, 8, 9, 0, + LEATHER, HI_LEATHER), + GLOVES("gauntlets of fumbling", "padded gloves", 0, 1, FUMBLING, 8, 1, + 10, 50, 9, 0, LEATHER, HI_LEATHER), + GLOVES("gauntlets of power", "riding gloves", 0, 1, 0, 8, 1, + 30, 50, 9, 0, IRON, CLR_BROWN), + GLOVES("gauntlets of dexterity", "fencing gloves", 0, 1, 0, 8, 1, + 10, 50, 9, 0, LEATHER, HI_LEATHER), -/* boots */ -BOOTS("low boots", "walking shoes", - 0, 0, 0, 25, 2, 10, 8, 9, 0, LEATHER, HI_LEATHER), -BOOTS("iron shoes", "hard shoes", - 0, 0, 0, 7, 2, 50, 16, 8, 0, IRON, HI_METAL), -BOOTS("high boots", "jackboots", - 0, 0, 0, 15, 2, 20, 12, 8, 0, LEATHER, HI_LEATHER), -/* With shuffled appearances... */ -BOOTS("speed boots", "combat boots", - 0, 1, FAST, 12, 2, 20, 50, 9, 0, LEATHER, HI_LEATHER), -BOOTS("water walking boots", "jungle boots", - 0, 1, WWALKING, 12, 2, 20, 50, 9, 0, LEATHER, HI_LEATHER), -BOOTS("jumping boots", "hiking boots", - 0, 1, JUMPING, 12, 2, 20, 50, 9, 0, LEATHER, HI_LEATHER), -BOOTS("elven boots", "mud boots", - 0, 1, STEALTH, 12, 2, 15, 8, 9, 0, LEATHER, HI_LEATHER), -BOOTS("kicking boots", "buckled boots", - 0, 1, 0, 12, 2, 15, 8, 9, 0, IRON, CLR_BROWN), -BOOTS("fumble boots", "riding boots", - 0, 1, FUMBLING, 12, 2, 20, 30, 9, 0, LEATHER, HI_LEATHER), -BOOTS("levitation boots", "snow boots", - 0, 1, LEVITATION,12, 2, 15, 30, 9, 0, LEATHER, HI_LEATHER), + /* boots */ + BOOTS("low boots", "walking shoes", 0, 0, 0, 25, 2, 10, 8, + 9, 0, LEATHER, HI_LEATHER), + BOOTS("iron shoes", "hard shoes", 0, 0, 0, 7, 2, 50, 16, 8, + 0, IRON, HI_METAL), + BOOTS("high boots", "jackboots", 0, 0, 0, 15, 2, 20, 12, 8, + 0, LEATHER, HI_LEATHER), + /* With shuffled appearances... */ + BOOTS("speed boots", "combat boots", 0, 1, FAST, 12, 2, 20, 50, 9, + 0, LEATHER, HI_LEATHER), + BOOTS("water walking boots", "jungle boots", 0, 1, WWALKING, 12, 2, + 20, 50, 9, 0, LEATHER, HI_LEATHER), + BOOTS("jumping boots", "hiking boots", 0, 1, JUMPING, 12, 2, + 20, 50, 9, 0, LEATHER, HI_LEATHER), + BOOTS("elven boots", "mud boots", 0, 1, STEALTH, 12, 2, 15, 8, + 9, 0, LEATHER, HI_LEATHER), + BOOTS("kicking boots", "buckled boots", 0, 1, 0, 12, 2, 15, 8, + 9, 0, IRON, CLR_BROWN), + BOOTS("fumble boots", "riding boots", 0, 1, FUMBLING, 12, 2, + 20, 30, 9, 0, LEATHER, HI_LEATHER), + BOOTS("levitation boots", "snow boots", 0, 1, LEVITATION, 12, 2, + 15, 30, 9, 0, LEATHER, HI_LEATHER), #undef HELM #undef CLOAK #undef SHIELD @@ -486,488 +518,603 @@ BOOTS("levitation boots", "snow boots", #undef ARMOR /* rings ... */ -#define RING(name,power,stone,cost,mgc,spec,mohs,metal,color) OBJECT( \ - OBJ(name,stone), \ - BITS(0,0,spec,0,mgc,spec,0,0,0,HARDGEM(mohs),0,P_NONE,metal), \ - power, RING_CLASS, 0, 0, 3, cost, 0, 0, 0, 0, 15, color ) -RING("adornment", ADORNED, "wooden", 100, 1, 1, 2, WOOD, HI_WOOD), -RING("gain strength", 0, "granite", 150, 1, 1, 7, MINERAL, HI_MINERAL), -RING("gain constitution", 0, "opal", 150, 1, 1, 7, MINERAL, HI_MINERAL), -RING("increase accuracy", 0, "clay", 150, 1, 1, 4, MINERAL, CLR_RED), -RING("increase damage", 0, "coral", 150, 1, 1, 4, MINERAL, CLR_ORANGE), -RING("protection", PROTECTION, "black onyx",100, 1, 1, 7, MINERAL, CLR_BLACK), -RING("regeneration", REGENERATION, "moonstone", - 200, 1, 0, 6, MINERAL, HI_MINERAL), -RING("searching", SEARCHING, "tiger eye", 200, 1, 0, 6, GEMSTONE, CLR_BROWN), -RING("stealth", STEALTH, "jade", 100, 1, 0, 6, GEMSTONE, CLR_GREEN), -RING("sustain ability", FIXED_ABIL, "bronze", - 100, 1, 0, 4, COPPER, HI_COPPER), -RING("levitation", LEVITATION, "agate", 200, 1, 0, 7, GEMSTONE, CLR_RED), -RING("hunger", HUNGER, "topaz", 100, 1, 0, 8, GEMSTONE, CLR_CYAN), -RING("aggravate monster", AGGRAVATE_MONSTER, "sapphire", - 150, 1, 0, 9, GEMSTONE, CLR_BLUE), -RING("conflict", CONFLICT, "ruby", 300, 1, 0, 9, GEMSTONE, CLR_RED), -RING("warning", WARNING, "diamond", 100, 1, 0,10, GEMSTONE, CLR_WHITE), -RING("poison resistance", POISON_RES, "pearl", - 150, 1, 0, 4, BONE, CLR_WHITE), -RING("fire resistance", FIRE_RES, "iron", 200, 1, 0, 5, IRON, HI_METAL), -RING("cold resistance", COLD_RES, "brass", 150, 1, 0, 4, COPPER, HI_COPPER), -RING("shock resistance", SHOCK_RES, "copper", - 150, 1, 0, 3, COPPER, HI_COPPER), -RING("free action", FREE_ACTION, "twisted", - 200, 1, 0, 6, IRON, HI_METAL), -RING("slow digestion", SLOW_DIGESTION, "steel", - 200, 1, 0, 8, IRON, HI_METAL), -RING("teleportation", TELEPORT, "silver", 200, 1, 0, 3, SILVER, HI_SILVER), -RING("teleport control", TELEPORT_CONTROL, "gold", - 300, 1, 0, 3, GOLD, HI_GOLD), -RING("polymorph", POLYMORPH, "ivory", 300, 1, 0, 4, BONE, CLR_WHITE), -RING("polymorph control", POLYMORPH_CONTROL, "emerald", - 300, 1, 0, 8, GEMSTONE, CLR_BRIGHT_GREEN), -RING("invisibility", INVIS, "wire", 150, 1, 0, 5, IRON, HI_METAL), -RING("see invisible", SEE_INVIS, "engagement", - 150, 1, 0, 5, IRON, HI_METAL), -RING("protection from shape changers", PROT_FROM_SHAPE_CHANGERS, "shiny", - 100, 1, 0, 5, IRON, CLR_BRIGHT_CYAN), +#define RING(name, power, stone, cost, mgc, spec, mohs, metal, color) \ + OBJECT(OBJ(name, stone), BITS(0, 0, spec, 0, mgc, spec, 0, 0, 0, \ + HARDGEM(mohs), 0, P_NONE, metal), \ + power, RING_CLASS, 0, 0, 3, cost, 0, 0, 0, 0, 15, color) + RING("adornment", ADORNED, "wooden", 100, 1, 1, 2, WOOD, HI_WOOD), + RING("gain strength", 0, "granite", 150, 1, 1, 7, MINERAL, + HI_MINERAL), + RING("gain constitution", 0, "opal", 150, 1, 1, 7, MINERAL, + HI_MINERAL), + RING("increase accuracy", 0, "clay", 150, 1, 1, 4, MINERAL, CLR_RED), + RING("increase damage", 0, "coral", 150, 1, 1, 4, MINERAL, + CLR_ORANGE), + RING("protection", PROTECTION, "black onyx", 100, 1, 1, 7, MINERAL, + CLR_BLACK), + RING("regeneration", REGENERATION, "moonstone", 200, 1, 0, 6, MINERAL, + HI_MINERAL), + RING("searching", SEARCHING, "tiger eye", 200, 1, 0, 6, GEMSTONE, + CLR_BROWN), + RING("stealth", STEALTH, "jade", 100, 1, 0, 6, GEMSTONE, CLR_GREEN), + RING("sustain ability", FIXED_ABIL, "bronze", 100, 1, 0, 4, COPPER, + HI_COPPER), + RING("levitation", LEVITATION, "agate", 200, 1, 0, 7, GEMSTONE, + CLR_RED), + RING("hunger", HUNGER, "topaz", 100, 1, 0, 8, GEMSTONE, CLR_CYAN), + RING("aggravate monster", AGGRAVATE_MONSTER, "sapphire", 150, 1, 0, 9, + GEMSTONE, CLR_BLUE), + RING("conflict", CONFLICT, "ruby", 300, 1, 0, 9, GEMSTONE, CLR_RED), + RING("warning", WARNING, "diamond", 100, 1, 0, 10, GEMSTONE, + CLR_WHITE), + RING("poison resistance", POISON_RES, "pearl", 150, 1, 0, 4, BONE, + CLR_WHITE), + RING("fire resistance", FIRE_RES, "iron", 200, 1, 0, 5, IRON, + HI_METAL), + RING("cold resistance", COLD_RES, "brass", 150, 1, 0, 4, COPPER, + HI_COPPER), + RING("shock resistance", SHOCK_RES, "copper", 150, 1, 0, 3, COPPER, + HI_COPPER), + RING("free action", FREE_ACTION, "twisted", 200, 1, 0, 6, IRON, + HI_METAL), + RING("slow digestion", SLOW_DIGESTION, "steel", 200, 1, 0, 8, IRON, + HI_METAL), + RING("teleportation", TELEPORT, "silver", 200, 1, 0, 3, SILVER, + HI_SILVER), + RING("teleport control", TELEPORT_CONTROL, "gold", 300, 1, 0, 3, GOLD, + HI_GOLD), + RING("polymorph", POLYMORPH, "ivory", 300, 1, 0, 4, BONE, CLR_WHITE), + RING("polymorph control", POLYMORPH_CONTROL, "emerald", 300, 1, 0, 8, + GEMSTONE, CLR_BRIGHT_GREEN), + RING("invisibility", INVIS, "wire", 150, 1, 0, 5, IRON, HI_METAL), + RING("see invisible", SEE_INVIS, "engagement", 150, 1, 0, 5, IRON, + HI_METAL), + RING("protection from shape changers", PROT_FROM_SHAPE_CHANGERS, + "shiny", 100, 1, 0, 5, IRON, CLR_BRIGHT_CYAN), #undef RING /* amulets ... - THE Amulet comes last because it is special */ -#define AMULET(name,desc,power,prob) OBJECT( \ - OBJ(name,desc), BITS(0,0,0,0,1,0,0,0,0,0,0,P_NONE,IRON), power, \ - AMULET_CLASS, prob, 0, 20, 150, 0, 0, 0, 0, 20, HI_METAL ) +#define AMULET(name, desc, power, prob) \ + OBJECT(OBJ(name, desc), \ + BITS(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, P_NONE, IRON), power, \ + AMULET_CLASS, prob, 0, 20, 150, 0, 0, 0, 0, 20, HI_METAL) -AMULET("amulet of ESP", "circular", TELEPAT, 175), -AMULET("amulet of life saving", "spherical", LIFESAVED, 75), -AMULET("amulet of strangulation", "oval", STRANGLED, 135), -AMULET("amulet of restful sleep", "triangular", SLEEPY, 135), -AMULET("amulet versus poison", "pyramidal", POISON_RES, 165), -AMULET("amulet of change", "square", 0, 130), - /* POLYMORPH */ -AMULET("amulet of unchanging", "concave", UNCHANGING, 45), -AMULET("amulet of reflection", "hexagonal", REFLECTING, 75), -AMULET("amulet of magical breathing", "octagonal", MAGICAL_BREATHING, 65), -OBJECT(OBJ("cheap plastic imitation of the Amulet of Yendor", - "Amulet of Yendor"), BITS(0,0,1,0,0,0,0,0,0,0,0,0,PLASTIC), 0, - AMULET_CLASS, 0, 0, 20, 0, 0, 0, 0, 0, 1, HI_METAL), -OBJECT(OBJ("Amulet of Yendor", /* note: description == name */ - "Amulet of Yendor"), BITS(0,0,1,0,1,0,1,1,0,0,0,0,MITHRIL), 0, - AMULET_CLASS, 0, 0, 20, 30000, 0, 0, 0, 0, 20, HI_METAL), + AMULET("amulet of ESP", "circular", TELEPAT, 175), + AMULET("amulet of life saving", "spherical", LIFESAVED, 75), + AMULET("amulet of strangulation", "oval", STRANGLED, 135), + AMULET("amulet of restful sleep", "triangular", SLEEPY, 135), + AMULET("amulet versus poison", "pyramidal", POISON_RES, 165), + AMULET("amulet of change", "square", 0, 130), + /* POLYMORPH */ + AMULET("amulet of unchanging", "concave", UNCHANGING, 45), + AMULET("amulet of reflection", "hexagonal", REFLECTING, 75), + AMULET("amulet of magical breathing", "octagonal", MAGICAL_BREATHING, + 65), + OBJECT(OBJ("cheap plastic imitation of the Amulet of Yendor", + "Amulet of Yendor"), + BITS(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, PLASTIC), 0, + AMULET_CLASS, 0, 0, 20, 0, 0, 0, 0, 0, 1, HI_METAL), + OBJECT(OBJ("Amulet of Yendor", /* note: description == name */ + "Amulet of Yendor"), + BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, MITHRIL), 0, + AMULET_CLASS, 0, 0, 20, 30000, 0, 0, 0, 0, 20, HI_METAL), #undef AMULET /* tools ... */ /* tools with weapon characteristics come last */ -#define TOOL(name,desc,kn,mrg,mgc,chg,prob,wt,cost,mat,color) \ - OBJECT( OBJ(name,desc), \ - BITS(kn,mrg,chg,0,mgc,chg,0,0,0,0,0,P_NONE,mat), \ - 0, TOOL_CLASS, prob, 0, \ - wt, cost, 0, 0, 0, 0, wt, color ) -#define CONTAINER(name,desc,kn,mgc,chg,prob,wt,cost,mat,color) \ - OBJECT( OBJ(name,desc), \ - BITS(kn,0,chg,1,mgc,chg,0,0,0,0,0,P_NONE,mat), \ - 0, TOOL_CLASS, prob, 0, \ - wt, cost, 0, 0, 0, 0, wt, color ) -#define WEPTOOL(name,desc,kn,mgc,bi,prob,wt,cost,sdam,ldam,hitbon,sub,mat,clr) \ - OBJECT( OBJ(name,desc), \ - BITS(kn,0,1,0,mgc,1,0,0,bi,0,hitbon,sub,mat), \ - 0, TOOL_CLASS, prob, 0, \ - wt, cost, sdam, ldam, hitbon, 0, wt, clr ) -/* containers */ -CONTAINER("large box", (char *)0, 1, 0, 0, 40,350, 8, WOOD, HI_WOOD), -CONTAINER("chest", (char *)0, 1, 0, 0, 35,600, 16, WOOD, HI_WOOD), -CONTAINER("ice box", (char *)0, 1, 0, 0, 5,900, 42, PLASTIC, CLR_WHITE), -CONTAINER("sack", "bag", 0, 0, 0, 35, 15, 2, CLOTH, HI_CLOTH), -CONTAINER("oilskin sack", "bag", 0, 0, 0, 5, 15, 100, CLOTH, HI_CLOTH), -CONTAINER("bag of holding", "bag", 0, 1, 0, 20, 15, 100, CLOTH, HI_CLOTH), -CONTAINER("bag of tricks", "bag", 0, 1, 1, 20, 15, 100, CLOTH, HI_CLOTH), +#define TOOL(name, desc, kn, mrg, mgc, chg, prob, wt, cost, mat, color) \ + OBJECT(OBJ(name, desc), \ + BITS(kn, mrg, chg, 0, mgc, chg, 0, 0, 0, 0, 0, P_NONE, mat), 0, \ + TOOL_CLASS, prob, 0, wt, cost, 0, 0, 0, 0, wt, color) +#define CONTAINER(name, desc, kn, mgc, chg, prob, wt, cost, mat, color) \ + OBJECT(OBJ(name, desc), \ + BITS(kn, 0, chg, 1, mgc, chg, 0, 0, 0, 0, 0, P_NONE, mat), 0, \ + TOOL_CLASS, prob, 0, wt, cost, 0, 0, 0, 0, wt, color) +#define WEPTOOL(name, desc, kn, mgc, bi, prob, wt, cost, sdam, ldam, hitbon, \ + sub, mat, clr) \ + OBJECT(OBJ(name, desc), \ + BITS(kn, 0, 1, 0, mgc, 1, 0, 0, bi, 0, hitbon, sub, mat), 0, \ + TOOL_CLASS, prob, 0, wt, cost, sdam, ldam, hitbon, 0, wt, clr) + /* containers */ + CONTAINER("large box", (char *) 0, 1, 0, 0, 40, 350, 8, WOOD, + HI_WOOD), + CONTAINER("chest", (char *) 0, 1, 0, 0, 35, 600, 16, WOOD, HI_WOOD), + CONTAINER("ice box", (char *) 0, 1, 0, 0, 5, 900, 42, PLASTIC, + CLR_WHITE), + CONTAINER("sack", "bag", 0, 0, 0, 35, 15, 2, CLOTH, HI_CLOTH), + CONTAINER("oilskin sack", "bag", 0, 0, 0, 5, 15, 100, CLOTH, + HI_CLOTH), + CONTAINER("bag of holding", "bag", 0, 1, 0, 20, 15, 100, CLOTH, + HI_CLOTH), + CONTAINER("bag of tricks", "bag", 0, 1, 1, 20, 15, 100, CLOTH, + HI_CLOTH), #undef CONTAINER -/* lock opening tools */ -TOOL("skeleton key", "key", 0, 0, 0, 0, 80, 3, 10, IRON, HI_METAL), -TOOL("lock pick", (char *)0, 1, 0, 0, 0, 60, 4, 20, IRON, HI_METAL), -TOOL("credit card", (char *)0, 1, 0, 0, 0, 15, 1, 10, PLASTIC, CLR_WHITE), -/* light sources */ -TOOL("tallow candle", "candle", 0, 1, 0, 0, 20, 2, 10, WAX, CLR_WHITE), -TOOL("wax candle", "candle", 0, 1, 0, 0, 5, 2, 20, WAX, CLR_WHITE), -TOOL("brass lantern", (char *)0,1, 0, 0, 0, 30, 30, 12, COPPER, CLR_YELLOW), -TOOL("oil lamp", "lamp", 0, 0, 0, 0, 45, 20, 10, COPPER, CLR_YELLOW), -TOOL("magic lamp", "lamp", 0, 0, 1, 0, 15, 20, 50, COPPER, CLR_YELLOW), -/* other tools */ -TOOL("expensive camera", (char *)0, - 1, 0, 0, 1, 15, 12, 200, PLASTIC, CLR_BLACK), -TOOL("mirror", "looking glass", 0, 0, 0, 0, 45, 13, 10, GLASS, HI_SILVER), -TOOL("crystal ball", "glass orb", - 0, 0, 1, 1, 15,150, 60, GLASS, HI_GLASS), -TOOL("lenses", (char *)0, 1, 0, 0, 0, 5, 3, 80, GLASS, HI_GLASS), -TOOL("blindfold", (char *)0, 1, 0, 0, 0, 50, 2, 20, CLOTH, CLR_BLACK), -TOOL("towel", (char *)0, 1, 0, 0, 0, 50, 2, 50, CLOTH, CLR_MAGENTA), -TOOL("saddle", (char *)0, 1, 0, 0, 0, 5,200, 150, LEATHER, HI_LEATHER), -TOOL("leash", (char *)0, 1, 0, 0, 0, 65, 12, 20, LEATHER, HI_LEATHER), -TOOL("stethoscope", (char *)0, 1, 0, 0, 0, 25, 4, 75, IRON, HI_METAL), -TOOL("tinning kit", (char *)0, 1, 0, 0, 1, 15,100, 30, IRON, HI_METAL), -TOOL("tin opener", (char *)0, 1, 0, 0, 0, 35, 4, 30, IRON, HI_METAL), -TOOL("can of grease", (char *)0,1, 0, 0, 1, 15, 15, 20, IRON, HI_METAL), -TOOL("figurine", (char *)0, 1, 0, 1, 0, 25, 50, 80, MINERAL, HI_MINERAL), -TOOL("magic marker", (char *)0, 1, 0, 1, 1, 15, 2, 50, PLASTIC, CLR_RED), -/* traps */ -TOOL("land mine",(char *)0, 1, 0, 0, 0, 0,300, 180, IRON, CLR_RED), -TOOL("beartrap", (char *)0, 1, 0, 0, 0, 0,200, 60, IRON, HI_METAL), -/* instruments */ -TOOL("tin whistle", "whistle", 0, 0, 0, 0, 100, 3, 10, METAL, HI_METAL), -TOOL("magic whistle", "whistle",0, 0, 1, 0, 30, 3, 10, METAL, HI_METAL), -/* "If tin whistles are made out of tin, what do they make foghorns out of?" */ -TOOL("wooden flute", "flute", 0, 0, 0, 0, 4, 5, 12, WOOD, HI_WOOD), -TOOL("magic flute", "flute", 0, 0, 1, 1, 2, 5, 36, WOOD, HI_WOOD), -TOOL("tooled horn", "horn", 0, 0, 0, 0, 5, 18, 15, BONE, CLR_WHITE), -TOOL("frost horn", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, CLR_WHITE), -TOOL("fire horn", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, CLR_WHITE), -TOOL("horn of plenty", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, CLR_WHITE), -TOOL("wooden harp", "harp", 0, 0, 0, 0, 4, 30, 50, WOOD, HI_WOOD), -TOOL("magic harp", "harp", 0, 0, 1, 1, 2, 30, 50, WOOD, HI_WOOD), -TOOL("bell", (char *)0, 1, 0, 0, 0, 2, 30, 50, COPPER, HI_COPPER), -TOOL("bugle", (char *)0, 1, 0, 0, 0, 4, 10, 15, COPPER, HI_COPPER), -TOOL("leather drum", "drum", 0, 0, 0, 0, 4, 25, 25, LEATHER, HI_LEATHER), -TOOL("drum of earthquake", "drum", - 0, 0, 1, 1, 2, 25, 25, LEATHER, HI_LEATHER), -/* tools useful as weapons */ -WEPTOOL("pick-axe", (char *)0, - 1, 0, 0, 20, 100, 50, 6, 3, WHACK, P_PICK_AXE, IRON, HI_METAL), -WEPTOOL("grappling hook", "iron hook", - 0, 0, 0, 5, 30, 50, 2, 6, WHACK, P_FLAIL, IRON, HI_METAL), -/* 3.4.1: unicorn horn left classified as "magic" */ -WEPTOOL("unicorn horn", (char *)0, - 1, 1, 1, 0, 20, 100, 12, 12, PIERCE, P_UNICORN_HORN, BONE, CLR_WHITE), + /* lock opening tools */ + TOOL("skeleton key", "key", 0, 0, 0, 0, 80, 3, 10, IRON, HI_METAL), + TOOL("lock pick", (char *) 0, 1, 0, 0, 0, 60, 4, 20, IRON, HI_METAL), + TOOL("credit card", (char *) 0, 1, 0, 0, 0, 15, 1, 10, PLASTIC, + CLR_WHITE), + /* light sources */ + TOOL("tallow candle", "candle", 0, 1, 0, 0, 20, 2, + 10, WAX, CLR_WHITE), + TOOL("wax candle", "candle", 0, 1, 0, 0, 5, 2, 20, WAX, CLR_WHITE), + TOOL("brass lantern", (char *) 0, 1, 0, 0, 0, 30, 30, 12, COPPER, + CLR_YELLOW), + TOOL("oil lamp", "lamp", 0, 0, 0, 0, 45, 20, 10, COPPER, CLR_YELLOW), + TOOL("magic lamp", "lamp", 0, 0, 1, 0, 15, 20, 50, COPPER, + CLR_YELLOW), + /* other tools */ + TOOL("expensive camera", (char *) 0, 1, 0, 0, 1, 15, 12, 200, PLASTIC, + CLR_BLACK), + TOOL("mirror", "looking glass", 0, 0, 0, 0, 45, 13, 10, GLASS, + HI_SILVER), + TOOL("crystal ball", "glass orb", 0, 0, 1, 1, 15, 150, 60, GLASS, + HI_GLASS), + TOOL("lenses", (char *) 0, 1, 0, 0, 0, 5, 3, 80, GLASS, HI_GLASS), + TOOL("blindfold", (char *) 0, 1, 0, 0, 0, 50, 2, 20, CLOTH, + CLR_BLACK), + TOOL("towel", (char *) 0, 1, 0, 0, 0, 50, 2, 50, CLOTH, CLR_MAGENTA), + TOOL("saddle", (char *) 0, 1, 0, 0, 0, 5, 200, 150, LEATHER, + HI_LEATHER), + TOOL("leash", (char *) 0, 1, 0, 0, 0, 65, 12, 20, LEATHER, + HI_LEATHER), + TOOL("stethoscope", (char *) 0, 1, 0, 0, 0, 25, 4, 75, IRON, + HI_METAL), + TOOL("tinning kit", (char *) 0, 1, 0, 0, 1, 15, 100, 30, IRON, + HI_METAL), + TOOL("tin opener", (char *) 0, 1, 0, 0, 0, 35, 4, 30, IRON, HI_METAL), + TOOL("can of grease", (char *) 0, 1, 0, 0, 1, 15, 15, 20, IRON, + HI_METAL), + TOOL("figurine", (char *) 0, 1, 0, 1, 0, 25, 50, 80, MINERAL, + HI_MINERAL), + TOOL("magic marker", (char *) 0, 1, 0, 1, 1, 15, 2, 50, PLASTIC, + CLR_RED), + /* traps */ + TOOL("land mine", (char *) 0, 1, 0, 0, 0, 0, 300, 180, IRON, CLR_RED), + TOOL("beartrap", (char *) 0, 1, 0, 0, 0, 0, 200, 60, IRON, HI_METAL), + /* instruments */ + TOOL("tin whistle", "whistle", 0, 0, 0, 0, 100, 3, 10, METAL, + HI_METAL), + TOOL("magic whistle", "whistle", 0, 0, 1, 0, 30, 3, 10, METAL, + HI_METAL), + /* "If tin whistles are made out of tin, what do they make foghorns + out of?" */ + TOOL("wooden flute", "flute", 0, 0, 0, 0, 4, 5, 12, WOOD, HI_WOOD), + TOOL("magic flute", "flute", 0, 0, 1, 1, 2, 5, 36, WOOD, HI_WOOD), + TOOL("tooled horn", "horn", 0, 0, 0, 0, 5, 18, 15, BONE, CLR_WHITE), + TOOL("frost horn", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, CLR_WHITE), + TOOL("fire horn", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, CLR_WHITE), + TOOL("horn of plenty", "horn", 0, 0, 1, 1, 2, 18, 50, BONE, + CLR_WHITE), + TOOL("wooden harp", "harp", 0, 0, 0, 0, 4, 30, 50, WOOD, HI_WOOD), + TOOL("magic harp", "harp", 0, 0, 1, 1, 2, 30, 50, WOOD, HI_WOOD), + TOOL("bell", (char *) 0, 1, 0, 0, 0, 2, 30, 50, COPPER, HI_COPPER), + TOOL("bugle", (char *) 0, 1, 0, 0, 0, 4, 10, 15, COPPER, HI_COPPER), + TOOL("leather drum", "drum", 0, 0, 0, 0, 4, 25, 25, LEATHER, + HI_LEATHER), + TOOL("drum of earthquake", "drum", 0, 0, 1, 1, 2, 25, 25, LEATHER, + HI_LEATHER), + /* tools useful as weapons */ + WEPTOOL("pick-axe", (char *) 0, 1, 0, 0, 20, 100, 50, 6, 3, WHACK, + P_PICK_AXE, IRON, HI_METAL), + WEPTOOL("grappling hook", "iron hook", 0, 0, 0, 5, 30, 50, 2, 6, + WHACK, P_FLAIL, IRON, HI_METAL), + /* 3.4.1: unicorn horn left classified as "magic" */ + WEPTOOL("unicorn horn", (char *) 0, 1, 1, 1, 0, 20, 100, + 12, 12, PIERCE, P_UNICORN_HORN, BONE, CLR_WHITE), -/* two special unique artifact "tools" */ -OBJECT(OBJ("Candelabrum of Invocation", "candelabrum"), - BITS(0,0,1,0,1,0,1,1,0,0,0,P_NONE,GOLD), 0, - TOOL_CLASS, 0, 0,10, 5000, 0, 0, 0, 0, 200, HI_GOLD), -OBJECT(OBJ("Bell of Opening", "silver bell"), - BITS(0,0,1,0,1,1,1,1,0,0,0,P_NONE,SILVER), 0, - TOOL_CLASS, 0, 0,10, 5000, 0, 0, 0, 0, 50, HI_SILVER), + /* two special unique artifact "tools" */ + OBJECT(OBJ("Candelabrum of Invocation", "candelabrum"), + BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, P_NONE, GOLD), 0, + TOOL_CLASS, 0, 0, 10, 5000, 0, 0, 0, 0, 200, HI_GOLD), + OBJECT(OBJ("Bell of Opening", "silver bell"), + BITS(0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, P_NONE, SILVER), 0, + TOOL_CLASS, 0, 0, 10, 5000, 0, 0, 0, 0, 50, HI_SILVER), #undef TOOL #undef WEPTOOL /* Comestibles ... */ -#define FOOD(name,prob,delay,wt,unk,tin,nutrition,color) OBJECT( \ - OBJ(name,(char *)0), BITS(1,1,unk,0,0,0,0,0,0,0,0,P_NONE,tin), 0, \ - FOOD_CLASS, prob, delay, \ - wt, nutrition/20 + 5, 0, 0, 0, 0, nutrition, color ) -/* all types of food (except tins & corpses) must have a delay of at least 1. */ -/* delay on corpses is computed and is weight dependant */ -/* dog eats foods 0-4 but prefers tripe rations above all others */ -/* fortune cookies can be read */ -/* carrots improve your vision */ -/* +0 tins contain monster meat */ -/* +1 tins (of spinach) make you stronger (like Popeye) */ -/* food CORPSE is a cadaver of some type */ -/* meatballs/sticks/rings are only created from objects via stone to flesh */ +#define FOOD(name, prob, delay, wt, unk, tin, nutrition, color) \ + OBJECT(OBJ(name, (char *) 0), \ + BITS(1, 1, unk, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, tin), 0, \ + FOOD_CLASS, prob, delay, wt, nutrition / 20 + 5, 0, 0, 0, 0, \ + nutrition, color) + /* all types of food (except tins & corpses) must have a delay of at + least 1. */ + /* delay on corpses is computed and is weight dependant */ + /* dog eats foods 0-4 but prefers tripe rations above all others */ + /* fortune cookies can be read */ + /* carrots improve your vision */ + /* +0 tins contain monster meat */ + /* +1 tins (of spinach) make you stronger (like Popeye) */ + /* food CORPSE is a cadaver of some type */ + /* meatballs/sticks/rings are only created from objects via stone to + flesh */ -/* meat */ -FOOD("tripe ration", 140, 2, 10, 0, FLESH, 200, CLR_BROWN), -FOOD("corpse", 0, 1, 0, 0, FLESH, 0, CLR_BROWN), -FOOD("egg", 85, 1, 1, 1, FLESH, 80, CLR_WHITE), -FOOD("meatball", 0, 1, 1, 0, FLESH, 5, CLR_BROWN), -FOOD("meat stick", 0, 1, 1, 0, FLESH, 5, CLR_BROWN), -FOOD("huge chunk of meat", 0,20,400, 0, FLESH,2000, CLR_BROWN), + /* meat */ + FOOD("tripe ration", 140, 2, 10, 0, FLESH, 200, CLR_BROWN), + FOOD("corpse", 0, 1, 0, 0, FLESH, 0, CLR_BROWN), + FOOD("egg", 85, 1, 1, 1, FLESH, 80, CLR_WHITE), + FOOD("meatball", 0, 1, 1, 0, FLESH, 5, CLR_BROWN), + FOOD("meat stick", 0, 1, 1, 0, FLESH, 5, CLR_BROWN), + FOOD("huge chunk of meat", 0, 20, 400, 0, FLESH, 2000, CLR_BROWN), -/* special case because it's not mergable */ -OBJECT(OBJ("meat ring", (char *)0), - BITS(1,0,0,0,0,0,0,0,0,0,0,0,FLESH), - 0, FOOD_CLASS, 0, 1, 5, 1, 0, 0, 0, 0, 5, CLR_BROWN), + /* special case because it's not mergable */ + OBJECT(OBJ("meat ring", (char *) 0), + BITS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FLESH), 0, FOOD_CLASS, + 0, 1, 5, 1, 0, 0, 0, 0, 5, CLR_BROWN), -/* pudding 'corpses' will turn into these and combine. - must be in same order as the pudding monsters */ -FOOD("glob of gray ooze", 0, 2, 20, 0, FLESH, 20, CLR_GRAY), -FOOD("glob of brown pudding", 0, 2, 20, 0, FLESH, 20, CLR_BROWN), -FOOD("glob of green slime", 0, 2, 20, 0, FLESH, 20, CLR_GREEN), -FOOD("glob of black pudding", 0, 2, 20, 0, FLESH, 20, CLR_BLACK), + /* pudding 'corpses' will turn into these and combine. + must be in same order as the pudding monsters */ + FOOD("glob of gray ooze", 0, 2, 20, 0, FLESH, 20, CLR_GRAY), + FOOD("glob of brown pudding", 0, 2, 20, 0, FLESH, 20, CLR_BROWN), + FOOD("glob of green slime", 0, 2, 20, 0, FLESH, 20, CLR_GREEN), + FOOD("glob of black pudding", 0, 2, 20, 0, FLESH, 20, CLR_BLACK), -/* fruits & veggies */ -FOOD("kelp frond", 0, 1, 1, 0, VEGGY, 30, CLR_GREEN), -FOOD("eucalyptus leaf", 3, 1, 1, 0, VEGGY, 30, CLR_GREEN), -FOOD("apple", 15, 1, 2, 0, VEGGY, 50, CLR_RED), -FOOD("orange", 10, 1, 2, 0, VEGGY, 80, CLR_ORANGE), -FOOD("pear", 10, 1, 2, 0, VEGGY, 50, CLR_BRIGHT_GREEN), -FOOD("melon", 10, 1, 5, 0, VEGGY, 100, CLR_BRIGHT_GREEN), -FOOD("banana", 10, 1, 2, 0, VEGGY, 80, CLR_YELLOW), -FOOD("carrot", 15, 1, 2, 0, VEGGY, 50, CLR_ORANGE), -FOOD("sprig of wolfsbane", 7, 1, 1, 0, VEGGY, 40, CLR_GREEN), -FOOD("clove of garlic", 7, 1, 1, 0, VEGGY, 40, CLR_WHITE), -FOOD("slime mold", 75, 1, 5, 0, VEGGY, 250, HI_ORGANIC), + /* fruits & veggies */ + FOOD("kelp frond", 0, 1, 1, 0, VEGGY, 30, CLR_GREEN), + FOOD("eucalyptus leaf", 3, 1, 1, 0, VEGGY, 30, CLR_GREEN), + FOOD("apple", 15, 1, 2, 0, VEGGY, 50, CLR_RED), + FOOD("orange", 10, 1, 2, 0, VEGGY, 80, CLR_ORANGE), + FOOD("pear", 10, 1, 2, 0, VEGGY, 50, CLR_BRIGHT_GREEN), + FOOD("melon", 10, 1, 5, 0, VEGGY, 100, CLR_BRIGHT_GREEN), + FOOD("banana", 10, 1, 2, 0, VEGGY, 80, CLR_YELLOW), + FOOD("carrot", 15, 1, 2, 0, VEGGY, 50, CLR_ORANGE), + FOOD("sprig of wolfsbane", 7, 1, 1, 0, VEGGY, 40, CLR_GREEN), + FOOD("clove of garlic", 7, 1, 1, 0, VEGGY, 40, CLR_WHITE), + FOOD("slime mold", 75, 1, 5, 0, VEGGY, 250, HI_ORGANIC), -/* people food */ -FOOD("lump of royal jelly", 0, 1, 2, 0, VEGGY, 200, CLR_YELLOW), -FOOD("cream pie", 25, 1, 10, 0, VEGGY, 100, CLR_WHITE), -FOOD("candy bar", 13, 1, 2, 0, VEGGY, 100, CLR_BROWN), -FOOD("fortune cookie", 55, 1, 1, 0, VEGGY, 40, CLR_YELLOW), -FOOD("pancake", 25, 2, 2, 0, VEGGY, 200, CLR_YELLOW), -FOOD("lembas wafer", 20, 2, 5, 0, VEGGY, 800, CLR_WHITE), -FOOD("cram ration", 20, 3, 15, 0, VEGGY, 600, HI_ORGANIC), -FOOD("food ration", 380, 5, 20, 0, VEGGY, 800, HI_ORGANIC), -FOOD("K-ration", 0, 1, 10, 0, VEGGY, 400, HI_ORGANIC), -FOOD("C-ration", 0, 1, 10, 0, VEGGY, 300, HI_ORGANIC), -FOOD("tin", 75, 0, 10, 1, METAL, 0, HI_METAL), + /* people food */ + FOOD("lump of royal jelly", 0, 1, 2, 0, VEGGY, 200, CLR_YELLOW), + FOOD("cream pie", 25, 1, 10, 0, VEGGY, 100, CLR_WHITE), + FOOD("candy bar", 13, 1, 2, 0, VEGGY, 100, CLR_BROWN), + FOOD("fortune cookie", 55, 1, 1, 0, VEGGY, 40, CLR_YELLOW), + FOOD("pancake", 25, 2, 2, 0, VEGGY, 200, CLR_YELLOW), + FOOD("lembas wafer", 20, 2, 5, 0, VEGGY, 800, CLR_WHITE), + FOOD("cram ration", 20, 3, 15, 0, VEGGY, 600, HI_ORGANIC), + FOOD("food ration", 380, 5, 20, 0, VEGGY, 800, HI_ORGANIC), + FOOD("K-ration", 0, 1, 10, 0, VEGGY, 400, HI_ORGANIC), + FOOD("C-ration", 0, 1, 10, 0, VEGGY, 300, HI_ORGANIC), + FOOD("tin", 75, 0, 10, 1, METAL, 0, HI_METAL), #undef FOOD /* potions ... */ -#define POTION(name,desc,mgc,power,prob,cost,color) OBJECT( \ - OBJ(name,desc), BITS(0,1,0,0,mgc,0,0,0,0,0,0,P_NONE,GLASS), power, \ - POTION_CLASS, prob, 0, 20, cost, 0, 0, 0, 0, 10, color ) -POTION("gain ability", "ruby", 1, 0, 42, 300, CLR_RED), -POTION("restore ability", "pink", 1, 0, 40, 100, CLR_BRIGHT_MAGENTA), -POTION("confusion", "orange", 1, CONFUSION, 42, 100, CLR_ORANGE), -POTION("blindness", "yellow", 1, BLINDED, 40, 150, CLR_YELLOW), -POTION("paralysis", "emerald", 1, 0, 42, 300, CLR_BRIGHT_GREEN), -POTION("speed", "dark green", 1, FAST, 42, 200, CLR_GREEN), -POTION("levitation", "cyan", 1, LEVITATION, 42, 200, CLR_CYAN), -POTION("hallucination", "sky blue", 1, HALLUC, 40, 100, CLR_CYAN), -POTION("invisibility", "brilliant blue",1, INVIS, 40, 150, CLR_BRIGHT_BLUE), -POTION("see invisible", "magenta", 1, SEE_INVIS, 42, 50, CLR_MAGENTA), -POTION("healing", "purple-red", 1, 0, 57, 100, CLR_MAGENTA), -POTION("extra healing", "puce", 1, 0, 47, 100, CLR_RED), -POTION("gain level", "milky", 1, 0, 20, 300, CLR_WHITE), -POTION("enlightenment", "swirly", 1, 0, 20, 200, CLR_BROWN), -POTION("monster detection", "bubbly", 1, 0, 40, 150, CLR_WHITE), -POTION("object detection", "smoky", 1, 0, 42, 150, CLR_GRAY), -POTION("gain energy", "cloudy", 1, 0, 42, 150, CLR_WHITE), -POTION("sleeping", "effervescent", 1, 0, 42, 100, CLR_GRAY), -POTION("full healing", "black", 1, 0, 10, 200, CLR_BLACK), -POTION("polymorph", "golden", 1, 0, 10, 200, CLR_YELLOW), -POTION("booze", "brown", 0, 0, 42, 50, CLR_BROWN), -POTION("sickness", "fizzy", 0, 0, 42, 50, CLR_CYAN), -POTION("fruit juice", "dark", 0, 0, 42, 50, CLR_BLACK), -POTION("acid", "white", 0, 0, 10, 250, CLR_WHITE), -POTION("oil", "murky", 0, 0, 30, 250, CLR_BROWN), -POTION("water", "clear", 0, 0, 92, 100, CLR_CYAN), +#define POTION(name, desc, mgc, power, prob, cost, color) \ + OBJECT(OBJ(name, desc), \ + BITS(0, 1, 0, 0, mgc, 0, 0, 0, 0, 0, 0, P_NONE, GLASS), power, \ + POTION_CLASS, prob, 0, 20, cost, 0, 0, 0, 0, 10, color) + POTION("gain ability", "ruby", 1, 0, 42, 300, CLR_RED), + POTION("restore ability", "pink", 1, 0, 40, 100, CLR_BRIGHT_MAGENTA), + POTION("confusion", "orange", 1, CONFUSION, 42, 100, CLR_ORANGE), + POTION("blindness", "yellow", 1, BLINDED, 40, 150, CLR_YELLOW), + POTION("paralysis", "emerald", 1, 0, 42, 300, CLR_BRIGHT_GREEN), + POTION("speed", "dark green", 1, FAST, 42, 200, CLR_GREEN), + POTION("levitation", "cyan", 1, LEVITATION, 42, 200, CLR_CYAN), + POTION("hallucination", "sky blue", 1, HALLUC, 40, 100, CLR_CYAN), + POTION("invisibility", "brilliant blue", 1, INVIS, 40, 150, + CLR_BRIGHT_BLUE), + POTION("see invisible", "magenta", 1, SEE_INVIS, 42, 50, CLR_MAGENTA), + POTION("healing", "purple-red", 1, 0, 57, 100, CLR_MAGENTA), + POTION("extra healing", "puce", 1, 0, 47, 100, CLR_RED), + POTION("gain level", "milky", 1, 0, 20, 300, CLR_WHITE), + POTION("enlightenment", "swirly", 1, 0, 20, 200, CLR_BROWN), + POTION("monster detection", "bubbly", 1, 0, 40, 150, CLR_WHITE), + POTION("object detection", "smoky", 1, 0, 42, 150, CLR_GRAY), + POTION("gain energy", "cloudy", 1, 0, 42, 150, CLR_WHITE), + POTION("sleeping", "effervescent", 1, 0, 42, 100, CLR_GRAY), + POTION("full healing", "black", 1, 0, 10, 200, CLR_BLACK), + POTION("polymorph", "golden", 1, 0, 10, 200, CLR_YELLOW), + POTION("booze", "brown", 0, 0, 42, 50, CLR_BROWN), + POTION("sickness", "fizzy", 0, 0, 42, 50, CLR_CYAN), + POTION("fruit juice", "dark", 0, 0, 42, 50, CLR_BLACK), + POTION("acid", "white", 0, 0, 10, 250, CLR_WHITE), + POTION("oil", "murky", 0, 0, 30, 250, CLR_BROWN), + POTION("water", "clear", 0, 0, 92, 100, CLR_CYAN), #undef POTION /* scrolls ... */ -#define SCROLL(name,text,mgc,prob,cost) OBJECT( \ - OBJ(name,text), BITS(0,1,0,0,mgc,0,0,0,0,0,0,P_NONE,PAPER), 0, \ - SCROLL_CLASS, prob, 0, 5, cost, 0, 0, 0, 0, 6, HI_PAPER ) - SCROLL("enchant armor", "ZELGO MER", 1, 63, 80), - SCROLL("destroy armor", "JUYED AWK YACC", 1, 45, 100), - SCROLL("confuse monster", "NR 9", 1, 53, 100), - SCROLL("scare monster", "XIXAXA XOXAXA XUXAXA", 1, 35, 100), - SCROLL("remove curse", "PRATYAVAYAH", 1, 65, 80), - SCROLL("enchant weapon", "DAIYEN FOOELS", 1, 80, 60), - SCROLL("create monster", "LEP GEX VEN ZEA", 1, 45, 200), - SCROLL("taming", "PRIRUTSENIE", 1, 15, 200), - SCROLL("genocide", "ELBIB YLOH", 1, 15, 300), - SCROLL("light", "VERR YED HORRE", 1, 90, 50), - SCROLL("teleportation", "VENZAR BORGAVVE", 1, 55, 100), - SCROLL("gold detection", "THARR", 1, 33, 100), - SCROLL("food detection", "YUM YUM", 1, 25, 100), - SCROLL("identify", "KERNOD WEL", 1, 180, 20), - SCROLL("magic mapping", "ELAM EBOW", 1, 45, 100), - SCROLL("amnesia", "DUAM XNAHT", 1, 35, 200), - SCROLL("fire", "ANDOVA BEGARIN", 1, 30, 100), - SCROLL("earth", "KIRJE", 1, 18, 200), - SCROLL("punishment", "VE FORBRYDERNE", 1, 15, 300), - SCROLL("charging", "HACKEM MUCHE", 1, 15, 300), - SCROLL("stinking cloud", "VELOX NEB", 1, 15, 300), - SCROLL((char *)0, "FOOBIE BLETCH", 1, 0, 100), - SCROLL((char *)0, "TEMOV", 1, 0, 100), - SCROLL((char *)0, "GARVEN DEH", 1, 0, 100), - SCROLL((char *)0, "READ ME", 1, 0, 100), - /* these must come last because they have special descriptions */ +#define SCROLL(name, text, mgc, prob, cost) \ + OBJECT(OBJ(name, text), \ + BITS(0, 1, 0, 0, mgc, 0, 0, 0, 0, 0, 0, P_NONE, PAPER), 0, \ + SCROLL_CLASS, prob, 0, 5, cost, 0, 0, 0, 0, 6, HI_PAPER) + SCROLL("enchant armor", "ZELGO MER", 1, 63, 80), + SCROLL("destroy armor", "JUYED AWK YACC", 1, 45, 100), + SCROLL("confuse monster", "NR 9", 1, 53, 100), + SCROLL("scare monster", "XIXAXA XOXAXA XUXAXA", 1, 35, 100), + SCROLL("remove curse", "PRATYAVAYAH", 1, 65, 80), + SCROLL("enchant weapon", "DAIYEN FOOELS", 1, 80, 60), + SCROLL("create monster", "LEP GEX VEN ZEA", 1, 45, 200), + SCROLL("taming", "PRIRUTSENIE", 1, 15, 200), + SCROLL("genocide", "ELBIB YLOH", 1, 15, 300), + SCROLL("light", "VERR YED HORRE", 1, 90, 50), + SCROLL("teleportation", "VENZAR BORGAVVE", 1, 55, 100), + SCROLL("gold detection", "THARR", 1, 33, 100), + SCROLL("food detection", "YUM YUM", 1, 25, 100), + SCROLL("identify", "KERNOD WEL", 1, 180, 20), + SCROLL("magic mapping", "ELAM EBOW", 1, 45, 100), + SCROLL("amnesia", "DUAM XNAHT", 1, 35, 200), + SCROLL("fire", "ANDOVA BEGARIN", 1, 30, 100), + SCROLL("earth", "KIRJE", 1, 18, 200), + SCROLL("punishment", "VE FORBRYDERNE", 1, 15, 300), + SCROLL("charging", "HACKEM MUCHE", 1, 15, 300), + SCROLL("stinking cloud", "VELOX NEB", 1, 15, 300), + SCROLL((char *) 0, "FOOBIE BLETCH", 1, 0, 100), + SCROLL((char *) 0, "TEMOV", 1, 0, 100), + SCROLL((char *) 0, "GARVEN DEH", 1, 0, 100), + SCROLL((char *) 0, "READ ME", 1, 0, 100), +/* these must come last because they have special descriptions */ #ifdef MAIL - SCROLL("mail", "stamped", 0, 0, 0), + SCROLL("mail", "stamped", 0, 0, 0), #endif - SCROLL("blank paper", "unlabeled", 0, 28, 60), + SCROLL("blank paper", "unlabeled", 0, 28, 60), #undef SCROLL /* spellbooks ... */ -#define SPELL(name,desc,sub,prob,delay,level,mgc,dir,color) OBJECT( \ - OBJ(name,desc), BITS(0,0,0,0,mgc,0,0,0,0,0,dir,sub,PAPER), 0, \ - SPBOOK_CLASS, prob, delay, \ - 50, level*100, 0, 0, 0, level, 20, color ) -SPELL("dig", "parchment", P_MATTER_SPELL, 20, 6, 5, 1, RAY, HI_PAPER), -SPELL("magic missile", "vellum", P_ATTACK_SPELL, 45, 2, 2, 1, RAY, HI_PAPER), -SPELL("fireball", "ragged", P_ATTACK_SPELL, 20, 4, 4, 1, RAY, HI_PAPER), -SPELL("cone of cold", "dog eared", P_ATTACK_SPELL, 10, 7, 4, 1, RAY, HI_PAPER), -SPELL("sleep", "mottled", P_ENCHANTMENT_SPELL, 50, 1, 1, 1, RAY, HI_PAPER), -SPELL("finger of death", "stained", P_ATTACK_SPELL, 5, 10, 7, 1, RAY, HI_PAPER), -SPELL("light", "cloth", P_DIVINATION_SPELL, 45, 1, 1, 1, NODIR, HI_CLOTH), -SPELL("detect monsters", "leathery", P_DIVINATION_SPELL, 43, 1, 1, 1, NODIR, HI_LEATHER), -SPELL("healing", "white", P_HEALING_SPELL, 40, 2, 1, 1, IMMEDIATE, CLR_WHITE), -SPELL("knock", "pink", P_MATTER_SPELL, 35, 1, 1, 1, IMMEDIATE, CLR_BRIGHT_MAGENTA), -SPELL("force bolt", "red", P_ATTACK_SPELL, 35, 2, 1, 1, IMMEDIATE, CLR_RED), -SPELL("confuse monster", "orange", P_ENCHANTMENT_SPELL, 30, 2, 2, 1, IMMEDIATE, CLR_ORANGE), -SPELL("cure blindness", "yellow", P_HEALING_SPELL, 25, 2, 2, 1, IMMEDIATE, CLR_YELLOW), -SPELL("drain life", "velvet", P_ATTACK_SPELL, 10, 2, 2, 1, IMMEDIATE, CLR_MAGENTA), -SPELL("slow monster", "light green", P_ENCHANTMENT_SPELL, 30, 2, 2, 1, IMMEDIATE, CLR_BRIGHT_GREEN), -SPELL("wizard lock", "dark green", P_MATTER_SPELL, 30, 3, 2, 1, IMMEDIATE, CLR_GREEN), -SPELL("create monster", "turquoise", P_CLERIC_SPELL, 35, 3, 2, 1, NODIR, CLR_BRIGHT_CYAN), -SPELL("detect food", "cyan", P_DIVINATION_SPELL, 30, 3, 2, 1, NODIR, CLR_CYAN), -SPELL("cause fear", "light blue", P_ENCHANTMENT_SPELL, 25, 3, 3, 1, NODIR, CLR_BRIGHT_BLUE), -SPELL("clairvoyance", "dark blue", P_DIVINATION_SPELL, 15, 3, 3, 1, NODIR, CLR_BLUE), -SPELL("cure sickness", "indigo", P_HEALING_SPELL, 32, 3, 3, 1, NODIR, CLR_BLUE), -SPELL("charm monster", "magenta", P_ENCHANTMENT_SPELL, 20, 3, 3, 1, IMMEDIATE, CLR_MAGENTA), -SPELL("haste self", "purple", P_ESCAPE_SPELL, 33, 4, 3, 1, NODIR, CLR_MAGENTA), -SPELL("detect unseen", "violet", P_DIVINATION_SPELL, 20, 4, 3, 1, NODIR, CLR_MAGENTA), -SPELL("levitation", "tan", P_ESCAPE_SPELL, 20, 4, 4, 1, NODIR, CLR_BROWN), -SPELL("extra healing", "plaid", P_HEALING_SPELL, 27, 5, 3, 1, IMMEDIATE, CLR_GREEN), -SPELL("restore ability", "light brown", P_HEALING_SPELL, 25, 5, 4, 1, NODIR, CLR_BROWN), -SPELL("invisibility", "dark brown", P_ESCAPE_SPELL, 25, 5, 4, 1, NODIR, CLR_BROWN), -SPELL("detect treasure", "gray", P_DIVINATION_SPELL, 20, 5, 4, 1, NODIR, CLR_GRAY), -SPELL("remove curse", "wrinkled", P_CLERIC_SPELL, 25, 5, 3, 1, NODIR, HI_PAPER), -SPELL("magic mapping", "dusty", P_DIVINATION_SPELL, 18, 7, 5, 1, NODIR, HI_PAPER), -SPELL("identify", "bronze", P_DIVINATION_SPELL, 20, 6, 3, 1, NODIR, HI_COPPER), -SPELL("turn undead", "copper", P_CLERIC_SPELL, 16, 8, 6, 1, IMMEDIATE, HI_COPPER), -SPELL("polymorph", "silver", P_MATTER_SPELL, 10, 8, 6, 1, IMMEDIATE, HI_SILVER), -SPELL("teleport away", "gold", P_ESCAPE_SPELL, 15, 6, 6, 1, IMMEDIATE, HI_GOLD), -SPELL("create familiar", "glittering", P_CLERIC_SPELL, 10, 7, 6, 1, NODIR, CLR_WHITE), -SPELL("cancellation", "shining", P_MATTER_SPELL, 15, 8, 7, 1, IMMEDIATE, CLR_WHITE), -SPELL("protection", "dull", P_CLERIC_SPELL, 18, 3, 1, 1, NODIR, HI_PAPER), -SPELL("jumping", "thin", P_ESCAPE_SPELL, 20, 3, 1, 1, IMMEDIATE, HI_PAPER), -SPELL("stone to flesh", "thick", P_HEALING_SPELL, 15, 1, 3, 1, IMMEDIATE, HI_PAPER), -#if 0 /* DEFERRED */ +#define SPELL(name, desc, sub, prob, delay, level, mgc, dir, color) \ + OBJECT(OBJ(name, desc), \ + BITS(0, 0, 0, 0, mgc, 0, 0, 0, 0, 0, dir, sub, PAPER), 0, \ + SPBOOK_CLASS, prob, delay, 50, level * 100, 0, 0, 0, level, 20, \ + color) + SPELL("dig", "parchment", P_MATTER_SPELL, 20, 6, 5, 1, RAY, HI_PAPER), + SPELL("magic missile", "vellum", P_ATTACK_SPELL, 45, 2, 2, 1, RAY, + HI_PAPER), + SPELL("fireball", "ragged", P_ATTACK_SPELL, 20, 4, 4, 1, RAY, + HI_PAPER), + SPELL("cone of cold", "dog eared", P_ATTACK_SPELL, 10, 7, 4, 1, RAY, + HI_PAPER), + SPELL("sleep", "mottled", P_ENCHANTMENT_SPELL, 50, 1, 1, 1, RAY, + HI_PAPER), + SPELL("finger of death", "stained", P_ATTACK_SPELL, 5, 10, 7, 1, RAY, + HI_PAPER), + SPELL("light", "cloth", P_DIVINATION_SPELL, 45, 1, 1, 1, NODIR, + HI_CLOTH), + SPELL("detect monsters", "leathery", P_DIVINATION_SPELL, 43, 1, 1, 1, + NODIR, HI_LEATHER), + SPELL("healing", "white", P_HEALING_SPELL, 40, 2, 1, 1, IMMEDIATE, + CLR_WHITE), + SPELL("knock", "pink", P_MATTER_SPELL, 35, 1, 1, 1, IMMEDIATE, + CLR_BRIGHT_MAGENTA), + SPELL("force bolt", "red", P_ATTACK_SPELL, 35, 2, 1, 1, IMMEDIATE, + CLR_RED), + SPELL("confuse monster", "orange", P_ENCHANTMENT_SPELL, 30, 2, 2, 1, + IMMEDIATE, CLR_ORANGE), + SPELL("cure blindness", "yellow", P_HEALING_SPELL, 25, 2, 2, 1, + IMMEDIATE, CLR_YELLOW), + SPELL("drain life", "velvet", P_ATTACK_SPELL, 10, 2, 2, 1, IMMEDIATE, + CLR_MAGENTA), + SPELL("slow monster", "light green", P_ENCHANTMENT_SPELL, 30, 2, 2, 1, + IMMEDIATE, CLR_BRIGHT_GREEN), + SPELL("wizard lock", "dark green", P_MATTER_SPELL, 30, 3, 2, 1, + IMMEDIATE, CLR_GREEN), + SPELL("create monster", "turquoise", P_CLERIC_SPELL, 35, 3, 2, 1, + NODIR, CLR_BRIGHT_CYAN), + SPELL("detect food", "cyan", P_DIVINATION_SPELL, 30, 3, 2, 1, NODIR, + CLR_CYAN), + SPELL("cause fear", "light blue", P_ENCHANTMENT_SPELL, 25, 3, 3, 1, + NODIR, CLR_BRIGHT_BLUE), + SPELL("clairvoyance", "dark blue", P_DIVINATION_SPELL, 15, 3, 3, 1, + NODIR, CLR_BLUE), + SPELL("cure sickness", "indigo", P_HEALING_SPELL, 32, 3, 3, 1, NODIR, + CLR_BLUE), + SPELL("charm monster", "magenta", P_ENCHANTMENT_SPELL, 20, 3, 3, 1, + IMMEDIATE, CLR_MAGENTA), + SPELL("haste self", "purple", P_ESCAPE_SPELL, 33, 4, 3, 1, NODIR, + CLR_MAGENTA), + SPELL("detect unseen", "violet", P_DIVINATION_SPELL, 20, 4, 3, 1, + NODIR, CLR_MAGENTA), + SPELL("levitation", "tan", P_ESCAPE_SPELL, 20, 4, 4, 1, NODIR, + CLR_BROWN), + SPELL("extra healing", "plaid", P_HEALING_SPELL, 27, 5, 3, 1, + IMMEDIATE, CLR_GREEN), + SPELL("restore ability", "light brown", P_HEALING_SPELL, 25, 5, 4, 1, + NODIR, CLR_BROWN), + SPELL("invisibility", "dark brown", P_ESCAPE_SPELL, 25, 5, 4, 1, + NODIR, CLR_BROWN), + SPELL("detect treasure", "gray", P_DIVINATION_SPELL, 20, 5, 4, 1, + NODIR, CLR_GRAY), + SPELL("remove curse", "wrinkled", P_CLERIC_SPELL, 25, 5, 3, 1, NODIR, + HI_PAPER), + SPELL("magic mapping", "dusty", P_DIVINATION_SPELL, 18, 7, 5, 1, + NODIR, HI_PAPER), + SPELL("identify", "bronze", P_DIVINATION_SPELL, 20, 6, 3, 1, NODIR, + HI_COPPER), + SPELL("turn undead", "copper", P_CLERIC_SPELL, 16, 8, 6, 1, IMMEDIATE, + HI_COPPER), + SPELL("polymorph", "silver", P_MATTER_SPELL, 10, 8, 6, 1, IMMEDIATE, + HI_SILVER), + SPELL("teleport away", "gold", P_ESCAPE_SPELL, 15, 6, 6, 1, IMMEDIATE, + HI_GOLD), + SPELL("create familiar", "glittering", P_CLERIC_SPELL, 10, 7, 6, 1, + NODIR, CLR_WHITE), + SPELL("cancellation", "shining", P_MATTER_SPELL, 15, 8, 7, 1, + IMMEDIATE, CLR_WHITE), + SPELL("protection", "dull", P_CLERIC_SPELL, 18, 3, 1, 1, NODIR, + HI_PAPER), + SPELL("jumping", "thin", P_ESCAPE_SPELL, 20, 3, 1, 1, IMMEDIATE, + HI_PAPER), + SPELL("stone to flesh", "thick", P_HEALING_SPELL, 15, 1, 3, 1, + IMMEDIATE, HI_PAPER), +#if 0 /* DEFERRED */ SPELL("flame sphere", "canvas", P_MATTER_SPELL, 20, 2, 1, 1, NODIR, CLR_BROWN), SPELL("freeze sphere", "hardcover", P_MATTER_SPELL, 20, 2, 1, 1, NODIR, CLR_BROWN), #endif -/* blank spellbook must come last because it retains its description */ -SPELL("blank paper", "plain", P_NONE, 18, 0, 0, 0, 0, HI_PAPER), -/* tribute book for 3.6 */ -OBJECT(OBJ("novel", "paperback"), BITS(0,0,1,0,0,0,0,1,0,0,0,P_NONE,HI_PAPER), 0, - SPBOOK_CLASS, 0, 0, 0, 20, 0, 0, 0, 1, 20, CLR_BRIGHT_BLUE), -/* a special, one of a kind, spellbook */ -OBJECT(OBJ("Book of the Dead", "papyrus"), BITS(0,0,1,0,1,0,1,1,0,0,0,P_NONE,PAPER), 0, - SPBOOK_CLASS, 0, 0,20, 10000, 0, 0, 0, 7, 20, HI_PAPER), + /* blank spellbook must come last because it retains its description + */ + SPELL("blank paper", "plain", P_NONE, 18, 0, 0, 0, 0, HI_PAPER), + /* tribute book for 3.6 */ + OBJECT(OBJ("novel", "paperback"), + BITS(0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, P_NONE, HI_PAPER), 0, + SPBOOK_CLASS, 0, 0, 0, 20, 0, 0, 0, 1, 20, CLR_BRIGHT_BLUE), + /* a special, one of a kind, spellbook */ + OBJECT(OBJ("Book of the Dead", "papyrus"), + BITS(0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, P_NONE, PAPER), 0, + SPBOOK_CLASS, 0, 0, 20, 10000, 0, 0, 0, 7, 20, HI_PAPER), #undef SPELL /* wands ... */ -#define WAND(name,typ,prob,cost,mgc,dir,metal,color) OBJECT( \ - OBJ(name,typ), BITS(0,0,1,0,mgc,1,0,0,0,0,dir,P_NONE,metal), 0, \ - WAND_CLASS, prob, 0, 7, cost, 0, 0, 0, 0, 30, color ) -WAND("light", "glass", 95, 100, 1, NODIR, GLASS, HI_GLASS), -WAND("secret door detection", "balsa", - 50, 150, 1, NODIR, WOOD, HI_WOOD), -WAND("enlightenment", "crystal", 15, 150, 1, NODIR, GLASS, HI_GLASS), -WAND("create monster", "maple", 45, 200, 1, NODIR, WOOD, HI_WOOD), -WAND("wishing", "pine", 5, 500, 1, NODIR, WOOD, HI_WOOD), -WAND("nothing", "oak", 25, 100, 0, IMMEDIATE, WOOD, HI_WOOD), -WAND("striking", "ebony", 75, 150, 1, IMMEDIATE, WOOD, HI_WOOD), -WAND("make invisible", "marble", 45, 150, 1, IMMEDIATE, MINERAL, HI_MINERAL), -WAND("slow monster", "tin", 50, 150, 1, IMMEDIATE, METAL, HI_METAL), -WAND("speed monster", "brass", 50, 150, 1, IMMEDIATE, COPPER, HI_COPPER), -WAND("undead turning", "copper", 50, 150, 1, IMMEDIATE, COPPER, HI_COPPER), -WAND("polymorph", "silver", 45, 200, 1, IMMEDIATE, SILVER, HI_SILVER), -WAND("cancellation", "platinum", 45, 200, 1, IMMEDIATE, PLATINUM, CLR_WHITE), -WAND("teleportation", "iridium", 45, 200, 1, IMMEDIATE, METAL, CLR_BRIGHT_CYAN), -WAND("opening", "zinc", 25, 150, 1, IMMEDIATE, METAL, HI_METAL), -WAND("locking", "aluminum", 25, 150, 1, IMMEDIATE, METAL, HI_METAL), -WAND("probing", "uranium", 30, 150, 1, IMMEDIATE, METAL, HI_METAL), -WAND("digging", "iron", 55, 150, 1, RAY, IRON, HI_METAL), -WAND("magic missile", "steel", 50, 150, 1, RAY, IRON, HI_METAL), -WAND("fire", "hexagonal",40, 175, 1, RAY, IRON, HI_METAL), -WAND("cold", "short", 40, 175, 1, RAY, IRON, HI_METAL), -WAND("sleep", "runed", 50, 175, 1, RAY, IRON, HI_METAL), -WAND("death", "long", 5, 500, 1, RAY, IRON, HI_METAL), -WAND("lightning", "curved", 40, 175, 1, RAY, IRON, HI_METAL), -WAND((char *)0, "forked", 0, 150, 1, 0, WOOD, HI_WOOD), -WAND((char *)0, "spiked", 0, 150, 1, 0, IRON, HI_METAL), -WAND((char *)0, "jeweled", 0, 150, 1, 0, IRON, HI_MINERAL), +#define WAND(name, typ, prob, cost, mgc, dir, metal, color) \ + OBJECT(OBJ(name, typ), \ + BITS(0, 0, 1, 0, mgc, 1, 0, 0, 0, 0, dir, P_NONE, metal), 0, \ + WAND_CLASS, prob, 0, 7, cost, 0, 0, 0, 0, 30, color) + WAND("light", "glass", 95, 100, 1, NODIR, GLASS, HI_GLASS), + WAND("secret door detection", "balsa", 50, 150, 1, NODIR, WOOD, + HI_WOOD), + WAND("enlightenment", "crystal", 15, 150, 1, NODIR, GLASS, HI_GLASS), + WAND("create monster", "maple", 45, 200, 1, NODIR, WOOD, HI_WOOD), + WAND("wishing", "pine", 5, 500, 1, NODIR, WOOD, HI_WOOD), + WAND("nothing", "oak", 25, 100, 0, IMMEDIATE, WOOD, HI_WOOD), + WAND("striking", "ebony", 75, 150, 1, IMMEDIATE, WOOD, HI_WOOD), + WAND("make invisible", "marble", 45, 150, 1, IMMEDIATE, MINERAL, + HI_MINERAL), + WAND("slow monster", "tin", 50, 150, 1, IMMEDIATE, METAL, HI_METAL), + WAND("speed monster", "brass", 50, 150, 1, IMMEDIATE, COPPER, + HI_COPPER), + WAND("undead turning", "copper", 50, 150, 1, IMMEDIATE, COPPER, + HI_COPPER), + WAND("polymorph", "silver", 45, 200, 1, IMMEDIATE, SILVER, HI_SILVER), + WAND("cancellation", "platinum", 45, 200, 1, IMMEDIATE, PLATINUM, + CLR_WHITE), + WAND("teleportation", "iridium", 45, 200, 1, IMMEDIATE, METAL, + CLR_BRIGHT_CYAN), + WAND("opening", "zinc", 25, 150, 1, IMMEDIATE, METAL, HI_METAL), + WAND("locking", "aluminum", 25, 150, 1, IMMEDIATE, METAL, HI_METAL), + WAND("probing", "uranium", 30, 150, 1, IMMEDIATE, METAL, HI_METAL), + WAND("digging", "iron", 55, 150, 1, RAY, IRON, HI_METAL), + WAND("magic missile", "steel", 50, 150, 1, RAY, IRON, HI_METAL), + WAND("fire", "hexagonal", 40, 175, 1, RAY, IRON, HI_METAL), + WAND("cold", "short", 40, 175, 1, RAY, IRON, HI_METAL), + WAND("sleep", "runed", 50, 175, 1, RAY, IRON, HI_METAL), + WAND("death", "long", 5, 500, 1, RAY, IRON, HI_METAL), + WAND("lightning", "curved", 40, 175, 1, RAY, IRON, HI_METAL), + WAND((char *) 0, "forked", 0, 150, 1, 0, WOOD, HI_WOOD), + WAND((char *) 0, "spiked", 0, 150, 1, 0, IRON, HI_METAL), + WAND((char *) 0, "jeweled", 0, 150, 1, 0, IRON, HI_MINERAL), #undef WAND /* coins ... - so far, gold is all there is */ -#define COIN(name,prob,metal,worth) OBJECT( \ - OBJ(name,(char *)0), BITS(0,1,0,0,0,0,0,0,0,0,0,P_NONE,metal), 0, \ - COIN_CLASS, prob, 0, 1, worth, 0, 0, 0, 0, 0, HI_GOLD ) - COIN("gold piece", 1000, GOLD,1), +#define COIN(name, prob, metal, worth) \ + OBJECT(OBJ(name, (char *) 0), \ + BITS(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, metal), 0, \ + COIN_CLASS, prob, 0, 1, worth, 0, 0, 0, 0, 0, HI_GOLD) + COIN("gold piece", 1000, GOLD, 1), #undef COIN /* gems ... - includes stones and rocks but not boulders */ -#define GEM(name,desc,prob,wt,gval,nutr,mohs,glass,color) OBJECT( \ - OBJ(name,desc), \ - BITS(0,1,0,0,0,0,0,0,0,HARDGEM(mohs),0,-P_SLING,glass), 0, \ - GEM_CLASS, prob, 0, 1, gval, 3, 3, 0, 0, nutr, color ) -#define ROCK(name,desc,kn,prob,wt,gval,sdam,ldam,mgc,nutr,mohs,glass,color) OBJECT( \ - OBJ(name,desc), \ - BITS(kn,1,0,0,mgc,0,0,0,0,HARDGEM(mohs),0,-P_SLING,glass), 0, \ - GEM_CLASS, prob, 0, wt, gval, sdam, ldam, 0, 0, nutr, color ) -GEM("dilithium crystal", "white", 2, 1, 4500, 15, 5, GEMSTONE, CLR_WHITE), -GEM("diamond", "white", 3, 1, 4000, 15, 10, GEMSTONE, CLR_WHITE), -GEM("ruby", "red", 4, 1, 3500, 15, 9, GEMSTONE, CLR_RED), -GEM("jacinth", "orange", 3, 1, 3250, 15, 9, GEMSTONE, CLR_ORANGE), -GEM("sapphire", "blue", 4, 1, 3000, 15, 9, GEMSTONE, CLR_BLUE), -GEM("black opal", "black", 3, 1, 2500, 15, 8, GEMSTONE, CLR_BLACK), -GEM("emerald", "green", 5, 1, 2500, 15, 8, GEMSTONE, CLR_GREEN), -GEM("turquoise", "green", 6, 1, 2000, 15, 6, GEMSTONE, CLR_GREEN), -GEM("citrine", "yellow", 4, 1, 1500, 15, 6, GEMSTONE, CLR_YELLOW), -GEM("aquamarine", "green", 6, 1, 1500, 15, 8, GEMSTONE, CLR_GREEN), -GEM("amber", "yellowish brown", 8, 1, 1000, 15, 2, GEMSTONE, CLR_BROWN), -GEM("topaz", "yellowish brown", 10, 1, 900, 15, 8, GEMSTONE, CLR_BROWN), -GEM("jet", "black", 6, 1, 850, 15, 7, GEMSTONE, CLR_BLACK), -GEM("opal", "white", 12, 1, 800, 15, 6, GEMSTONE, CLR_WHITE), -GEM("chrysoberyl", "yellow", 8, 1, 700, 15, 5, GEMSTONE, CLR_YELLOW), -GEM("garnet", "red", 12, 1, 700, 15, 7, GEMSTONE, CLR_RED), -GEM("amethyst", "violet", 14, 1, 600, 15, 7, GEMSTONE, CLR_MAGENTA), -GEM("jasper", "red", 15, 1, 500, 15, 7, GEMSTONE, CLR_RED), -GEM("fluorite", "violet", 15, 1, 400, 15, 4, GEMSTONE, CLR_MAGENTA), -GEM("obsidian", "black", 9, 1, 200, 15, 6, GEMSTONE, CLR_BLACK), -GEM("agate", "orange", 12, 1, 200, 15, 6, GEMSTONE, CLR_ORANGE), -GEM("jade", "green", 10, 1, 300, 15, 6, GEMSTONE, CLR_GREEN), -GEM("worthless piece of white glass", "white", 77, 1, 0, 6, 5, GLASS, CLR_WHITE), -GEM("worthless piece of blue glass", "blue", 77, 1, 0, 6, 5, GLASS, CLR_BLUE), -GEM("worthless piece of red glass", "red", 77, 1, 0, 6, 5, GLASS, CLR_RED), -GEM("worthless piece of yellowish brown glass", "yellowish brown", - 77, 1, 0, 6, 5, GLASS, CLR_BROWN), -GEM("worthless piece of orange glass", "orange", 76, 1, 0, 6, 5, GLASS, CLR_ORANGE), -GEM("worthless piece of yellow glass", "yellow", 77, 1, 0, 6, 5, GLASS, CLR_YELLOW), -GEM("worthless piece of black glass", "black", 76, 1, 0, 6, 5, GLASS, CLR_BLACK), -GEM("worthless piece of green glass", "green", 77, 1, 0, 6, 5, GLASS, CLR_GREEN), -GEM("worthless piece of violet glass", "violet", 77, 1, 0, 6, 5, GLASS, CLR_MAGENTA), +#define GEM(name, desc, prob, wt, gval, nutr, mohs, glass, color) \ + OBJECT(OBJ(name, desc), BITS(0, 1, 0, 0, 0, 0, 0, 0, 0, HARDGEM(mohs), \ + 0, -P_SLING, glass), \ + 0, GEM_CLASS, prob, 0, 1, gval, 3, 3, 0, 0, nutr, color) +#define ROCK(name, desc, kn, prob, wt, gval, sdam, ldam, mgc, nutr, mohs, \ + glass, color) \ + OBJECT(OBJ(name, desc), BITS(kn, 1, 0, 0, mgc, 0, 0, 0, 0, \ + HARDGEM(mohs), 0, -P_SLING, glass), \ + 0, GEM_CLASS, prob, 0, wt, gval, sdam, ldam, 0, 0, nutr, color) + GEM("dilithium crystal", "white", 2, 1, 4500, 15, 5, GEMSTONE, + CLR_WHITE), + GEM("diamond", "white", 3, 1, 4000, 15, 10, GEMSTONE, CLR_WHITE), + GEM("ruby", "red", 4, 1, 3500, 15, 9, GEMSTONE, CLR_RED), + GEM("jacinth", "orange", 3, 1, 3250, 15, 9, GEMSTONE, CLR_ORANGE), + GEM("sapphire", "blue", 4, 1, 3000, 15, 9, GEMSTONE, CLR_BLUE), + GEM("black opal", "black", 3, 1, 2500, 15, 8, GEMSTONE, CLR_BLACK), + GEM("emerald", "green", 5, 1, 2500, 15, 8, GEMSTONE, CLR_GREEN), + GEM("turquoise", "green", 6, 1, 2000, 15, 6, GEMSTONE, CLR_GREEN), + GEM("citrine", "yellow", 4, 1, 1500, 15, 6, GEMSTONE, CLR_YELLOW), + GEM("aquamarine", "green", 6, 1, 1500, 15, 8, GEMSTONE, CLR_GREEN), + GEM("amber", "yellowish brown", 8, 1, 1000, 15, 2, GEMSTONE, + CLR_BROWN), + GEM("topaz", "yellowish brown", 10, 1, 900, 15, 8, GEMSTONE, + CLR_BROWN), + GEM("jet", "black", 6, 1, 850, 15, 7, GEMSTONE, CLR_BLACK), + GEM("opal", "white", 12, 1, 800, 15, 6, GEMSTONE, CLR_WHITE), + GEM("chrysoberyl", "yellow", 8, 1, 700, 15, 5, GEMSTONE, CLR_YELLOW), + GEM("garnet", "red", 12, 1, 700, 15, 7, GEMSTONE, CLR_RED), + GEM("amethyst", "violet", 14, 1, 600, 15, 7, GEMSTONE, CLR_MAGENTA), + GEM("jasper", "red", 15, 1, 500, 15, 7, GEMSTONE, CLR_RED), + GEM("fluorite", "violet", 15, 1, 400, 15, 4, GEMSTONE, CLR_MAGENTA), + GEM("obsidian", "black", 9, 1, 200, 15, 6, GEMSTONE, CLR_BLACK), + GEM("agate", "orange", 12, 1, 200, 15, 6, GEMSTONE, CLR_ORANGE), + GEM("jade", "green", 10, 1, 300, 15, 6, GEMSTONE, CLR_GREEN), + GEM("worthless piece of white glass", "white", 77, 1, 0, 6, 5, GLASS, + CLR_WHITE), + GEM("worthless piece of blue glass", "blue", 77, 1, 0, 6, 5, GLASS, + CLR_BLUE), + GEM("worthless piece of red glass", "red", 77, 1, 0, 6, 5, GLASS, + CLR_RED), + GEM("worthless piece of yellowish brown glass", "yellowish brown", 77, + 1, 0, 6, 5, GLASS, CLR_BROWN), + GEM("worthless piece of orange glass", "orange", 76, 1, 0, 6, 5, + GLASS, CLR_ORANGE), + GEM("worthless piece of yellow glass", "yellow", 77, 1, 0, 6, 5, + GLASS, CLR_YELLOW), + GEM("worthless piece of black glass", "black", 76, 1, 0, 6, 5, GLASS, + CLR_BLACK), + GEM("worthless piece of green glass", "green", 77, 1, 0, 6, 5, GLASS, + CLR_GREEN), + GEM("worthless piece of violet glass", "violet", 77, 1, 0, 6, 5, + GLASS, CLR_MAGENTA), -/* Placement note: there is a wishable subrange for - * "gray stones" in the o_ranges[] array in objnam.c - * that is currently everything between luckstones and flint (inclusive). - */ -ROCK("luckstone", "gray", 0, 10, 10, 60, 3, 3, 1, 10, 7, MINERAL, CLR_GRAY), -ROCK("loadstone", "gray", 0, 10, 500, 1, 3, 3, 1, 10, 6, MINERAL, CLR_GRAY), -ROCK("touchstone", "gray", 0, 8, 10, 45, 3, 3, 1, 10, 6, MINERAL, CLR_GRAY), -ROCK("flint", "gray", 0, 10, 10, 1, 6, 6, 0, 10, 7, MINERAL, CLR_GRAY), -ROCK("rock", (char *)0, 1,100, 10, 0, 3, 3, 0, 10, 7, MINERAL, CLR_GRAY), + /* Placement note: there is a wishable subrange for + * "gray stones" in the o_ranges[] array in objnam.c + * that is currently everything between luckstones and flint + * (inclusive). + */ + ROCK("luckstone", "gray", 0, 10, 10, 60, 3, 3, 1, 10, 7, MINERAL, + CLR_GRAY), + ROCK("loadstone", "gray", 0, 10, 500, 1, 3, 3, 1, 10, 6, MINERAL, + CLR_GRAY), + ROCK("touchstone", "gray", 0, 8, 10, 45, 3, 3, 1, 10, 6, MINERAL, + CLR_GRAY), + ROCK("flint", "gray", 0, 10, 10, 1, 6, 6, 0, 10, 7, MINERAL, + CLR_GRAY), + ROCK("rock", (char *) 0, 1, 100, 10, 0, 3, 3, 0, 10, 7, MINERAL, + CLR_GRAY), #undef GEM #undef ROCK -/* miscellaneous ... */ -/* Note: boulders and rocks are not normally created at random; the - * probabilities only come into effect when you try to polymorph them. - * Boulders weigh more than MAX_CARR_CAP; statues use corpsenm to take - * on a specific type and may act as containers (both affect weight). - */ -OBJECT(OBJ("boulder",(char *)0), BITS(1,0,0,0,0,0,0,0,1,0,0,P_NONE,MINERAL), 0, - ROCK_CLASS, 100, 0, 6000, 0, 20, 20, 0, 0, 2000, HI_MINERAL), -OBJECT(OBJ("statue", (char *)0), BITS(1,0,0,1,0,0,0,0,0,0,0,P_NONE,MINERAL), 0, - ROCK_CLASS, 900, 0, 2500, 0, 20, 20, 0, 0, 2500, CLR_WHITE), + /* miscellaneous ... */ + /* Note: boulders and rocks are not normally created at random; the + * probabilities only come into effect when you try to polymorph them. + * Boulders weigh more than MAX_CARR_CAP; statues use corpsenm to take + * on a specific type and may act as containers (both affect weight). + */ + OBJECT(OBJ("boulder", (char *) 0), + BITS(1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, P_NONE, MINERAL), 0, + ROCK_CLASS, 100, 0, 6000, 0, 20, 20, 0, 0, 2000, HI_MINERAL), + OBJECT(OBJ("statue", (char *) 0), + BITS(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, P_NONE, MINERAL), 0, + ROCK_CLASS, 900, 0, 2500, 0, 20, 20, 0, 0, 2500, CLR_WHITE), -OBJECT(OBJ("heavy iron ball", (char *)0), BITS(1,0,0,0,0,0,0,0,0,0,WHACK,P_NONE,IRON), 0, - BALL_CLASS, 1000, 0, 480, 10, 25, 25, 0, 0, 200, HI_METAL), - /* +d4 when "very heavy" */ -OBJECT(OBJ("iron chain", (char *)0), BITS(1,0,0,0,0,0,0,0,0,0,WHACK,P_NONE,IRON), 0, - CHAIN_CLASS, 1000, 0, 120, 0, 4, 4, 0, 0, 200, HI_METAL), - /* +1 both l & s */ + OBJECT(OBJ("heavy iron ball", (char *) 0), + BITS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, WHACK, P_NONE, IRON), 0, + BALL_CLASS, 1000, 0, 480, 10, 25, 25, 0, 0, 200, HI_METAL), + /* +d4 when "very heavy" */ + OBJECT(OBJ("iron chain", (char *) 0), + BITS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, WHACK, P_NONE, IRON), 0, + CHAIN_CLASS, 1000, 0, 120, 0, 4, 4, 0, 0, 200, HI_METAL), + /* +1 both l & s */ -OBJECT(OBJ("blinding venom", "splash of venom"), - BITS(0,1,0,0,0,0,0,1,0,0,0,P_NONE,LIQUID), 0, - VENOM_CLASS, 500, 0, 1, 0, 0, 0, 0, 0, 0, HI_ORGANIC), -OBJECT(OBJ("acid venom", "splash of venom"), - BITS(0,1,0,0,0,0,0,1,0,0,0,P_NONE,LIQUID), 0, - VENOM_CLASS, 500, 0, 1, 0, 6, 6, 0, 0, 0, HI_ORGANIC), - /* +d6 small or large */ + OBJECT(OBJ("blinding venom", "splash of venom"), + BITS(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, P_NONE, LIQUID), 0, + VENOM_CLASS, 500, 0, 1, 0, 0, 0, 0, 0, 0, HI_ORGANIC), + OBJECT(OBJ("acid venom", "splash of venom"), + BITS(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, P_NONE, LIQUID), 0, + VENOM_CLASS, 500, 0, 1, 0, 6, 6, 0, 0, 0, HI_ORGANIC), + /* +d6 small or large */ -/* fencepost, the deadly Array Terminator -- name [1st arg] *must* be NULL */ - OBJECT(OBJ((char *)0,(char *)0), BITS(0,0,0,0,0,0,0,0,0,0,0,P_NONE,0), 0, - ILLOBJ_CLASS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) -}; /* objects[] */ + /* fencepost, the deadly Array Terminator -- name [1st arg] *must* be + NULL */ + OBJECT(OBJ((char *) 0, (char *) 0), + BITS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, P_NONE, 0), 0, + ILLOBJ_CLASS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + }; /* objects[] */ #ifndef OBJECTS_PASS_2_ /* perform recursive compilation for second structure */ -# undef OBJ -# undef OBJECT -# define OBJECTS_PASS_2_ +#undef OBJ +#undef OBJECT +#define OBJECTS_PASS_2_ #include "objects.c" void NDECL(objects_init); @@ -979,6 +1126,6 @@ objects_init() return; } -#endif /* !OBJECTS_PASS_2_ */ +#endif /* !OBJECTS_PASS_2_ */ /*objects.c*/ diff --git a/src/objnam.c b/src/objnam.c index 134796ba6..7b8709623 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1,76 +1,74 @@ -/* NetHack 3.6 objnam.c $NHDT-Date: 1429413519 2015/04/19 03:18:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.128 $ */ +/* NetHack 3.6 objnam.c $NHDT-Date: 1431192756 2015/05/09 17:32:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.131 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" /* "an uncursed greased partly eaten guardian naga hatchling [corpse]" */ -#define PREFIX 80 /* (56) */ +#define PREFIX 80 /* (56) */ #define SCHAR_LIM 127 #define NUMOBUF 12 -STATIC_DCL char *FDECL(strprepend,(char *,const char *)); +STATIC_DCL char *FDECL(strprepend, (char *, const char *)); STATIC_DCL short FDECL(rnd_otyp_by_wpnskill, (SCHAR_P)); -STATIC_DCL boolean FDECL(wishymatch, (const char *,const char *,BOOLEAN_P)); +STATIC_DCL boolean FDECL(wishymatch, (const char *, const char *, BOOLEAN_P)); STATIC_DCL char *NDECL(nextobuf); STATIC_DCL void FDECL(releaseobuf, (char *)); STATIC_DCL char *FDECL(minimal_xname, (struct obj *)); STATIC_DCL void FDECL(add_erosion_words, (struct obj *, char *)); -STATIC_DCL boolean FDECL(singplur_lookup, (char *,char *,BOOLEAN_P, - const char *const *)); +STATIC_DCL boolean +FDECL(singplur_lookup, (char *, char *, BOOLEAN_P, const char *const *)); STATIC_DCL char *FDECL(singplur_compound, (char *)); STATIC_DCL char *FDECL(xname_flags, (struct obj *, unsigned)); - struct Jitem { int item; const char *name; }; -#define BSTRCMPI(base,ptr,str) ((ptr) < base || strcmpi((ptr),str)) -#define BSTRNCMPI(base,ptr,str,num) ((ptr) < base || strncmpi((ptr),str,num)) -#define Strcasecpy(dst,src) (void)strcasecpy(dst,src) +#define BSTRCMPI(base, ptr, str) ((ptr) < base || strcmpi((ptr), str)) +#define BSTRNCMPI(base, ptr, str, num) \ + ((ptr) < base || strncmpi((ptr), str, num)) +#define Strcasecpy(dst, src) (void) strcasecpy(dst, src) /* true for gems/rocks that should have " stone" appended to their names */ -#define GemStone(typ) (typ == FLINT || \ - (objects[typ].oc_material == GEMSTONE && \ - (typ != DILITHIUM_CRYSTAL && typ != RUBY && \ - typ != DIAMOND && typ != SAPPHIRE && \ - typ != BLACK_OPAL && \ - typ != EMERALD && typ != OPAL))) +#define GemStone(typ) \ + (typ == FLINT \ + || (objects[typ].oc_material == GEMSTONE \ + && (typ != DILITHIUM_CRYSTAL && typ != RUBY && typ != DIAMOND \ + && typ != SAPPHIRE && typ != BLACK_OPAL && typ != EMERALD \ + && typ != OPAL))) -STATIC_OVL struct Jitem Japanese_items[] = { - { SHORT_SWORD, "wakizashi" }, - { BROADSWORD, "ninja-to" }, - { FLAIL, "nunchaku" }, - { GLAIVE, "naginata" }, - { LOCK_PICK, "osaku" }, - { WOODEN_HARP, "koto" }, - { KNIFE, "shito" }, - { PLATE_MAIL, "tanko" }, - { HELMET, "kabuto" }, - { LEATHER_GLOVES, "yugake" }, - { FOOD_RATION, "gunyoki" }, - { POT_BOOZE, "sake" }, - {0, "" } -}; +STATIC_OVL struct Jitem Japanese_items[] = { { SHORT_SWORD, "wakizashi" }, + { BROADSWORD, "ninja-to" }, + { FLAIL, "nunchaku" }, + { GLAIVE, "naginata" }, + { LOCK_PICK, "osaku" }, + { WOODEN_HARP, "koto" }, + { KNIFE, "shito" }, + { PLATE_MAIL, "tanko" }, + { HELMET, "kabuto" }, + { LEATHER_GLOVES, "yugake" }, + { FOOD_RATION, "gunyoki" }, + { POT_BOOZE, "sake" }, + { 0, "" } }; -STATIC_DCL const char *FDECL(Japanese_item_name,(int i)); +STATIC_DCL const char *FDECL(Japanese_item_name, (int i)); STATIC_OVL char * -strprepend(s,pref) +strprepend(s, pref) register char *s; register const char *pref; { - register int i = (int)strlen(pref); + register int i = (int) strlen(pref); - if(i > PREFIX) { + if (i > PREFIX) { impossible("PREFIX too short (for %d).", i); - return(s); + return (s); } s -= i; - (void) strncpy(s, pref, i); /* do not copy trailing 0 */ - return(s); + (void) strncpy(s, pref, i); /* do not copy trailing 0 */ + return (s); } /* manage a pool of BUFSZ buffers, so callers don't have to */ @@ -108,7 +106,7 @@ register int otyp; if (Role_if(PM_SAMURAI) && Japanese_item_name(otyp)) actualn = Japanese_item_name(otyp); - switch(ocl->oc_class) { + switch (ocl->oc_class) { case COIN_CLASS: Strcpy(buf, "coin"); break; @@ -128,46 +126,46 @@ register int otyp; Strcpy(buf, "ring"); break; case AMULET_CLASS: - if(nn) - Strcpy(buf,actualn); + if (nn) + Strcpy(buf, actualn); else - Strcpy(buf,"amulet"); - if(un) - Sprintf(eos(buf)," called %s",un); - if(dn) - Sprintf(eos(buf)," (%s)",dn); - return(buf); + Strcpy(buf, "amulet"); + if (un) + Sprintf(eos(buf), " called %s", un); + if (dn) + Sprintf(eos(buf), " (%s)", dn); + return (buf); default: - if(nn) { + if (nn) { Strcpy(buf, actualn); if (GemStone(otyp)) Strcat(buf, " stone"); - if(un) + if (un) Sprintf(eos(buf), " called %s", un); - if(dn) + if (dn) Sprintf(eos(buf), " (%s)", dn); } else { Strcpy(buf, dn ? dn : actualn); - if(ocl->oc_class == GEM_CLASS) - Strcat(buf, (ocl->oc_material == MINERAL) ? - " stone" : " gem"); - if(un) + if (ocl->oc_class == GEM_CLASS) + Strcat(buf, + (ocl->oc_material == MINERAL) ? " stone" : " gem"); + if (un) Sprintf(eos(buf), " called %s", un); } - return(buf); + return (buf); } /* here for ring/scroll/potion/wand */ - if(nn) { + if (nn) { if (ocl->oc_unique) - Strcpy(buf, actualn); /* avoid spellbook of Book of the Dead */ + Strcpy(buf, actualn); /* avoid spellbook of Book of the Dead */ else - Sprintf(eos(buf), " of %s", actualn); + Sprintf(eos(buf), " of %s", actualn); } - if(un) + if (un) Sprintf(eos(buf), " called %s", un); - if(dn) + if (dn) Sprintf(eos(buf), " (%s)", dn); - return(buf); + return (buf); } /* less verbose result than obj_typename(); either the actual name @@ -178,11 +176,11 @@ int otyp; { char *bufp, *pp, *save_uname = objects[otyp].oc_uname; - objects[otyp].oc_uname = 0; /* suppress any name given by user */ + objects[otyp].oc_uname = 0; /* suppress any name given by user */ bufp = obj_typename(otyp); objects[otyp].oc_uname = save_uname; if ((pp = strstri(bufp, " (")) != 0) - *pp = '\0'; /* strip the appended description */ + *pp = '\0'; /* strip the appended description */ return bufp; } @@ -190,14 +188,15 @@ boolean obj_is_pname(obj) register struct obj *obj; { - if (!obj->oartifact || !has_oname(obj)) return FALSE; + if (!obj->oartifact || !has_oname(obj)) + return FALSE; if (!program_state.gameover && !iflags.override_ID) { - if (not_fully_identified(obj)) return FALSE; + if (not_fully_identified(obj)) + return FALSE; } return TRUE; } - /* Give the name of an object seen at a distance. Unlike xname/doname, * we don't want to set dknown if it's not set already. The kludge used is * to temporarily set Blind so that xname() skips the dknown setting. This @@ -223,15 +222,15 @@ char *FDECL((*func), (OBJ_P)); ("slice of pizza" -> "pizza juice" rather than "slice of pizza juice") */ char * fruitname(juice) -boolean juice; /* whether or not to append " juice" to the name */ +boolean juice; /* whether or not to append " juice" to the name */ { char *buf = nextobuf(); const char *fruit_nam = strstri(pl_fruit, " of "); if (fruit_nam) - fruit_nam += 4; /* skip past " of " */ + fruit_nam += 4; /* skip past " of " */ else - fruit_nam = pl_fruit; /* use it as is */ + fruit_nam = pl_fruit; /* use it as is */ Sprintf(buf, "%s%s", makesingular(fruit_nam), juice ? " juice" : ""); return buf; @@ -247,7 +246,7 @@ struct obj *obj; char * xname_flags(obj, cxn_flags) register struct obj *obj; -unsigned cxn_flags; /* bitmask of CXN_xxx values */ +unsigned cxn_flags; /* bitmask of CXN_xxx values */ { register char *buf; register int typ = obj->otyp; @@ -256,10 +255,10 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ const char *actualn = OBJ_NAME(*ocl); const char *dn = OBJ_DESCR(*ocl); const char *un = ocl->oc_uname; - boolean pluralize = (obj->quan != 1L) && !(cxn_flags & CXN_SINGULAR); + boolean pluralize = (obj->quan != 1L) && !(cxn_flags & CXN_SINGULAR); boolean known, dknown, bknown; - buf = nextobuf() + PREFIX; /* leave room for "17 -3 " */ + buf = nextobuf() + PREFIX; /* leave room for "17 -3 " */ if (Role_if(PM_SAMURAI) && Japanese_item_name(typ)) actualn = Japanese_item_name(typ); @@ -270,9 +269,12 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ * printed for the object is tied to the combination of the two * and printing the wrong article gives away information. */ - if (!nn && ocl->oc_uses_known && ocl->oc_unique) obj->known = 0; - if (!Blind) obj->dknown = TRUE; - if (Role_if(PM_PRIEST)) obj->bknown = TRUE; + if (!nn && ocl->oc_uses_known && ocl->oc_unique) + obj->known = 0; + if (!Blind) + obj->dknown = TRUE; + if (Role_if(PM_PRIEST)) + obj->bknown = TRUE; if (iflags.override_ID) { known = dknown = bknown = TRUE; @@ -286,25 +288,24 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ if (obj_is_pname(obj)) goto nameit; switch (obj->oclass) { - case AMULET_CLASS: + case AMULET_CLASS: if (!dknown) Strcpy(buf, "amulet"); - else if (typ == AMULET_OF_YENDOR || - typ == FAKE_AMULET_OF_YENDOR) + else if (typ == AMULET_OF_YENDOR || typ == FAKE_AMULET_OF_YENDOR) /* each must be identified individually */ Strcpy(buf, known ? actualn : dn); else if (nn) Strcpy(buf, actualn); else if (un) - Sprintf(buf,"amulet called %s", un); + Sprintf(buf, "amulet called %s", un); else - Sprintf(buf,"%s amulet", dn); + Sprintf(buf, "%s amulet", dn); break; - case WEAPON_CLASS: + case WEAPON_CLASS: if (is_poisonable(obj) && obj->opoisoned) Strcpy(buf, "poisoned "); - case VENOM_CLASS: - case TOOL_CLASS: + case VENOM_CLASS: + case TOOL_CLASS: if (typ == LENSES) Strcpy(buf, "pair of "); @@ -322,51 +323,54 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ /* it whenever calling doname() or xname(). */ if (typ == FIGURINE && omndx != NON_PM) Sprintf(eos(buf), " of a%s %s", - index(vowels, *mons[omndx].mname) ? "n" : "", - mons[omndx].mname); + index(vowels, *mons[omndx].mname) ? "n" : "", + mons[omndx].mname); break; - case ARMOR_CLASS: + case ARMOR_CLASS: /* depends on order of the dragon scales objects */ if (typ >= GRAY_DRAGON_SCALES && typ <= YELLOW_DRAGON_SCALES) { Sprintf(buf, "set of %s", actualn); break; } - if(is_boots(obj) || is_gloves(obj)) Strcpy(buf,"pair of "); + if (is_boots(obj) || is_gloves(obj)) + Strcpy(buf, "pair of "); - if(obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD - && !dknown) { + if (obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD + && !dknown) { Strcpy(buf, "shield"); break; } - if(obj->otyp == SHIELD_OF_REFLECTION && !dknown) { + if (obj->otyp == SHIELD_OF_REFLECTION && !dknown) { Strcpy(buf, "smooth shield"); break; } - if(nn) Strcat(buf, actualn); - else if(un) { - if(is_boots(obj)) - Strcat(buf,"boots"); - else if(is_gloves(obj)) - Strcat(buf,"gloves"); - else if(is_cloak(obj)) - Strcpy(buf,"cloak"); - else if(is_helmet(obj)) - Strcpy(buf,"helmet"); - else if(is_shield(obj)) - Strcpy(buf,"shield"); + if (nn) + Strcat(buf, actualn); + else if (un) { + if (is_boots(obj)) + Strcat(buf, "boots"); + else if (is_gloves(obj)) + Strcat(buf, "gloves"); + else if (is_cloak(obj)) + Strcpy(buf, "cloak"); + else if (is_helmet(obj)) + Strcpy(buf, "helmet"); + else if (is_shield(obj)) + Strcpy(buf, "shield"); else - Strcpy(buf,"armor"); + Strcpy(buf, "armor"); Strcat(buf, " called "); Strcat(buf, un); - } else Strcat(buf, dn); + } else + Strcat(buf, dn); break; - case FOOD_CLASS: + case FOOD_CLASS: if (typ == SLIME_MOLD) { register struct fruit *f; - for(f=ffruit; f; f = f->nextf) { - if(f->fid == obj->spe) { + for (f = ffruit; f; f = f->nextf) { + if (f->fid == obj->spe) { Strcpy(buf, f->fname); break; } @@ -385,10 +389,11 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ } if (Is_pudding(obj)) { Sprintf(buf, "%s%s", - obj->owt < 100 ? "small " - : obj->owt > 500 ? "very large " - : obj->owt > 300 ? "large " - : "", actualn); + obj->owt < 100 + ? "small " + : obj->owt > 500 ? "very large " + : obj->owt > 300 ? "large " : "", + actualn); break; } @@ -396,37 +401,43 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ if (typ == TIN && known) tin_details(obj, omndx, buf); break; - case COIN_CLASS: - case CHAIN_CLASS: + case COIN_CLASS: + case CHAIN_CLASS: Strcpy(buf, actualn); break; - case ROCK_CLASS: + case ROCK_CLASS: if (typ == STATUE && omndx != NON_PM) Sprintf(buf, "%s%s of %s%s", - (Role_if(PM_ARCHEOLOGIST) && - (obj->spe & STATUE_HISTORIC)) ? "historic " : "", - actualn, - type_is_pname(&mons[omndx]) ? "" : - the_unique_pm(&mons[omndx]) ? "the " : - index(vowels, *mons[omndx].mname) ? "an " : "a ", - mons[omndx].mname); - else Strcpy(buf, actualn); + (Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) + ? "historic " + : "", + actualn, + type_is_pname(&mons[omndx]) + ? "" + : the_unique_pm(&mons[omndx]) + ? "the " + : index(vowels, *mons[omndx].mname) ? "an " + : "a ", + mons[omndx].mname); + else + Strcpy(buf, actualn); break; - case BALL_CLASS: + case BALL_CLASS: Sprintf(buf, "%sheavy iron ball", - (obj->owt > ocl->oc_weight) ? "very " : ""); + (obj->owt > ocl->oc_weight) ? "very " : ""); break; - case POTION_CLASS: + case POTION_CLASS: if (dknown && obj->odiluted) Strcpy(buf, "diluted "); - if(nn || un || !dknown) { + if (nn || un || !dknown) { Strcat(buf, "potion"); - if(!dknown) break; - if(nn) { + if (!dknown) + break; + if (nn) { Strcat(buf, " of "); - if (typ == POT_WATER && - bknown && (obj->blessed || obj->cursed)) { - Strcat(buf, obj->blessed ? "holy " : "unholy "); + if (typ == POT_WATER && bknown + && (obj->blessed || obj->cursed)) { + Strcat(buf, obj->blessed ? "holy " : "unholy "); } Strcat(buf, actualn); } else { @@ -440,11 +451,12 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ break; case SCROLL_CLASS: Strcpy(buf, "scroll"); - if(!dknown) break; - if(nn) { + if (!dknown) + break; + if (nn) { Strcat(buf, " of "); Strcat(buf, actualn); - } else if(un) { + } else if (un) { Strcat(buf, " called "); Strcat(buf, un); } else if (ocl->oc_magic) { @@ -456,28 +468,28 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ } break; case WAND_CLASS: - if(!dknown) + if (!dknown) Strcpy(buf, "wand"); - else if(nn) + else if (nn) Sprintf(buf, "wand of %s", actualn); - else if(un) + else if (un) Sprintf(buf, "wand called %s", un); else Sprintf(buf, "%s wand", dn); break; case SPBOOK_CLASS: - if (typ == SPE_NOVEL) { /* 3.6 tribute */ + if (typ == SPE_NOVEL) { /* 3.6 tribute */ if (!dknown) Strcpy(buf, "book"); - else if (nn) + else if (nn) Strcpy(buf, actualn); - else if (un) + else if (un) Sprintf(buf, "novel called %s", un); - else + else Sprintf(buf, "%s book", dn); break; - /* end of tribute */ - } else if (!dknown) { + /* end of tribute */ + } else if (!dknown) { Strcpy(buf, "spellbook"); } else if (nn) { if (typ != SPE_BOOK_OF_THE_DEAD) @@ -489,48 +501,51 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ Sprintf(buf, "%s spellbook", dn); break; case RING_CLASS: - if(!dknown) + if (!dknown) Strcpy(buf, "ring"); - else if(nn) + else if (nn) Sprintf(buf, "ring of %s", actualn); - else if(un) + else if (un) Sprintf(buf, "ring called %s", un); else Sprintf(buf, "%s ring", dn); break; - case GEM_CLASS: - { - const char *rock = - (ocl->oc_material == MINERAL) ? "stone" : "gem"; + case GEM_CLASS: { + const char *rock = (ocl->oc_material == MINERAL) ? "stone" : "gem"; if (!dknown) { Strcpy(buf, rock); } else if (!nn) { - if (un) Sprintf(buf,"%s called %s", rock, un); - else Sprintf(buf, "%s %s", dn, rock); + if (un) + Sprintf(buf, "%s called %s", rock, un); + else + Sprintf(buf, "%s %s", dn, rock); } else { Strcpy(buf, actualn); - if (GemStone(typ)) Strcat(buf, " stone"); + if (GemStone(typ)) + Strcat(buf, " stone"); } break; - } - default: - Sprintf(buf,"glorkum %d %d %d", obj->oclass, typ, obj->spe); } - if (pluralize) Strcpy(buf, makeplural(buf)); + default: + Sprintf(buf, "glorkum %d %d %d", obj->oclass, typ, obj->spe); + } + if (pluralize) + Strcpy(buf, makeplural(buf)); - if (obj->otyp == T_SHIRT && program_state.gameover) { - char tmpbuf[BUFSZ]; - Sprintf(eos(buf), " with text \"%s\"", tshirt_text(obj, tmpbuf)); - } + if (obj->otyp == T_SHIRT && program_state.gameover) { + char tmpbuf[BUFSZ]; + Sprintf(eos(buf), " with text \"%s\"", tshirt_text(obj, tmpbuf)); + } if (has_oname(obj) && dknown) { Strcat(buf, " named "); -nameit: + nameit: Strcat(buf, ONAME(obj)); } - if (!strncmpi(buf, "the ", 4)) buf += 4; - return(buf); + if (!strncmpi(buf, "the ", 4)) + buf += 4; + return (buf); } /* similar to simple_typename but minimal_xname operates on a particular @@ -553,7 +568,8 @@ struct obj *obj; objects[otyp].oc_uname = 0; /* suppress actual name if object's description is unknown */ saveobcls.oc_name_known = objects[otyp].oc_name_known; - if (!obj->dknown) objects[otyp].oc_name_known = 0; + if (!obj->dknown) + objects[otyp].oc_name_known = 0; /* caveat: this makes a lot of assumptions about which fields are required in order for xname() to yield a sensible result */ @@ -562,17 +578,21 @@ struct obj *obj; bareobj.oclass = obj->oclass; bareobj.dknown = obj->dknown; /* suppress known except for amulets (needed for fakes and real A-of-Y) */ - bareobj.known = (obj->oclass == AMULET_CLASS) ? obj->known : - /* default is "on" for types which don't use it */ - !objects[otyp].oc_uses_known; - bareobj.quan = 1L; /* don't want plural */ - bareobj.corpsenm = NON_PM; /* suppress statue and figurine details */ + bareobj.known = (obj->oclass == AMULET_CLASS) + ? obj->known + : + /* default is "on" for types which don't use it */ + !objects[otyp].oc_uses_known; + bareobj.quan = 1L; /* don't want plural */ + bareobj.corpsenm = NON_PM; /* suppress statue and figurine details */ /* but suppressing fruit details leads to "bad fruit #0" [perhaps we should force "slime mold" rather than use xname?] */ - if (obj->otyp == SLIME_MOLD) bareobj.spe = obj->spe; + if (obj->otyp == SLIME_MOLD) + bareobj.spe = obj->spe; - bufp = distant_name(&bareobj, xname); /* xname(&bareobj) */ - if (!strncmp(bufp, "uncursed ", 9)) bufp += 9; /* Role_if(PM_PRIEST) */ + bufp = distant_name(&bareobj, xname); /* xname(&bareobj) */ + if (!strncmp(bufp, "uncursed ", 9)) + bufp += 9; /* Role_if(PM_PRIEST) */ objects[otyp].oc_uname = saveobcls.oc_uname; objects[otyp].oc_name_known = saveobcls.oc_name_known; @@ -588,17 +608,16 @@ struct obj *obj; char *onm = xname(obj); if (m_shot.n > 1 && m_shot.o == obj->otyp) { - /* copy xname's result so that we can reuse its return buffer */ - Strcpy(tmpbuf, onm); - /* "the Nth arrow"; value will eventually be passed to an() or - The(), both of which correctly handle this "the " prefix */ - Sprintf(onm, "the %d%s %s", m_shot.i, ordin(m_shot.i), tmpbuf); + /* copy xname's result so that we can reuse its return buffer */ + Strcpy(tmpbuf, onm); + /* "the Nth arrow"; value will eventually be passed to an() or + The(), both of which correctly handle this "the " prefix */ + Sprintf(onm, "the %d%s %s", m_shot.i, ordin(m_shot.i), tmpbuf); } return onm; } - /* used for naming "the unique_item" instead of "a unique_item" */ boolean the_unique_obj(obj) @@ -606,12 +625,12 @@ register struct obj *obj; { boolean known = (obj->known || iflags.override_ID); if (!obj->dknown && !iflags.override_ID) - return FALSE; + return FALSE; else if (obj->otyp == FAKE_AMULET_OF_YENDOR && !known) - return TRUE; /* lie */ + return TRUE; /* lie */ else - return (boolean)(objects[obj->otyp].oc_unique && - (known || obj->otyp == AMULET_OF_YENDOR)); + return (boolean)(objects[obj->otyp].oc_unique + && (known || obj->otyp == AMULET_OF_YENDOR)); } /* should monster type be prefixed with "the"? (mostly used for corpses) */ @@ -623,7 +642,8 @@ struct permonst *ptr; /* even though monsters with personal names are unique, we want to describe them as "Name" rather than "the Name" */ - if (type_is_pname(ptr)) return FALSE; + if (type_is_pname(ptr)) + return FALSE; uniq = (ptr->geno & G_UNIQ) ? TRUE : FALSE; /* high priest is unique if it includes "of ", otherwise not @@ -638,7 +658,7 @@ struct permonst *ptr; } STATIC_OVL void -add_erosion_words(obj,prefix) +add_erosion_words(obj, prefix) struct obj *obj; char *prefix; { @@ -647,32 +667,42 @@ char *prefix; rknown = (iflags.override_ID == 0) ? obj->rknown : TRUE; - if (!is_damageable(obj) && !iscrys) return; + if (!is_damageable(obj) && !iscrys) + return; /* The only cases where any of these bits do double duty are for * rotted food and diluted potions, which are all not is_damageable(). */ if (obj->oeroded && !iscrys) { switch (obj->oeroded) { - case 2: Strcat(prefix, "very "); break; - case 3: Strcat(prefix, "thoroughly "); break; - } + case 2: + Strcat(prefix, "very "); + break; + case 3: + Strcat(prefix, "thoroughly "); + break; + } Strcat(prefix, is_rustprone(obj) ? "rusty " : "burnt "); } if (obj->oeroded2 && !iscrys) { switch (obj->oeroded2) { - case 2: Strcat(prefix, "very "); break; - case 3: Strcat(prefix, "thoroughly "); break; - } - Strcat(prefix, is_corrodeable(obj) ? "corroded " : - "rotted "); + case 2: + Strcat(prefix, "very "); + break; + case 3: + Strcat(prefix, "thoroughly "); + break; + } + Strcat(prefix, is_corrodeable(obj) ? "corroded " : "rotted "); } if (rknown && obj->oerodeproof) - Strcat(prefix, - iscrys ? "fixed " : - is_rustprone(obj) ? "rustproof " : - is_corrodeable(obj) ? "corrodeproof " : /* "stainless"? */ - is_flammable(obj) ? "fireproof " : ""); + Strcat(prefix, iscrys + ? "fixed " + : is_rustprone(obj) + ? "rustproof " + : is_corrodeable(obj) ? "corrodeproof " + : /* "stainless"? */ + is_flammable(obj) ? "fireproof " : ""); } char * @@ -683,15 +713,15 @@ register struct obj *obj; boolean known, cknown, bknown, lknown; int omndx = obj->corpsenm; char prefix[PREFIX]; - char tmpbuf[PREFIX+1]; + char tmpbuf[PREFIX + 1]; /* when we have to add something at the start of prefix instead of the * end (Strcat is used on the end) */ register char *bp = xname(obj); - if (iflags.override_ID) { - known = cknown = bknown = lknown = TRUE; - } else { + if (iflags.override_ID) { + known = cknown = bknown = lknown = TRUE; + } else { known = obj->known; cknown = obj->cknown; bknown = obj->bknown; @@ -709,7 +739,7 @@ register struct obj *obj; ispoisoned = TRUE; } - if(obj->quan != 1L) + if (obj->quan != 1L) Sprintf(prefix, "%ld ", obj->quan); else if (obj->otyp == CORPSE) /* skip article prefix for corpses [else corpse_xname() @@ -724,60 +754,63 @@ register struct obj *obj; /* "empty" goes at the beginning, but item count goes at the end */ if (cknown && - /* bag of tricks: include "empty" prefix if it's known to - be empty but its precise number of charges isn't known - (when that is known, suffix of "(n:0)" will be appended, - making the prefix be redundant; note that 'known' flag - isn't set when emptiness gets discovered because then - charging magic would yield known number of new charges) */ - (obj->otyp == BAG_OF_TRICKS ? (obj->spe == 0 && !obj->known) : - /* not bag of tricks: empty if container which has no contents */ - (Is_container(obj) || obj->otyp == STATUE) && !Has_contents(obj))) + /* bag of tricks: include "empty" prefix if it's known to + be empty but its precise number of charges isn't known + (when that is known, suffix of "(n:0)" will be appended, + making the prefix be redundant; note that 'known' flag + isn't set when emptiness gets discovered because then + charging magic would yield known number of new charges) */ + (obj->otyp == BAG_OF_TRICKS + ? (obj->spe == 0 && !obj->known) + : + /* not bag of tricks: empty if container which has no contents */ + (Is_container(obj) || obj->otyp == STATUE) + && !Has_contents(obj))) Strcat(prefix, "empty "); - if (bknown && - obj->oclass != COIN_CLASS && - (obj->otyp != POT_WATER || !objects[POT_WATER].oc_name_known - || (!obj->cursed && !obj->blessed))) { + if (bknown && obj->oclass != COIN_CLASS + && (obj->otyp != POT_WATER || !objects[POT_WATER].oc_name_known + || (!obj->cursed && !obj->blessed))) { /* allow 'blessed clear potion' if we don't know it's holy water; * always allow "uncursed potion of water" */ if (obj->cursed) - Strcat(prefix, "cursed "); + Strcat(prefix, "cursed "); else if (obj->blessed) - Strcat(prefix, "blessed "); - else if ((!known || !objects[obj->otyp].oc_charged || - (obj->oclass == ARMOR_CLASS || - obj->oclass == RING_CLASS)) - /* For most items with charges or +/-, if you know how many - * charges are left or what the +/- is, then you must have - * totally identified the item, so "uncursed" is unneccesary, - * because an identified object not described as "blessed" or - * "cursed" must be uncursed. - * - * If the charges or +/- is not known, "uncursed" must be - * printed to avoid ambiguity between an item whose curse - * status is unknown, and an item known to be uncursed. - */ + Strcat(prefix, "blessed "); + else if ((!known || !objects[obj->otyp].oc_charged + || (obj->oclass == ARMOR_CLASS + || obj->oclass == RING_CLASS)) +/* For most items with charges or +/-, if you know how many + * charges are left or what the +/- is, then you must have + * totally identified the item, so "uncursed" is unneccesary, + * because an identified object not described as "blessed" or + * "cursed" must be uncursed. + * + * If the charges or +/- is not known, "uncursed" must be + * printed to avoid ambiguity between an item whose curse + * status is unknown, and an item known to be uncursed. + */ #ifdef MAIL - && obj->otyp != SCR_MAIL + && obj->otyp != SCR_MAIL #endif - && obj->otyp != FAKE_AMULET_OF_YENDOR - && obj->otyp != AMULET_OF_YENDOR - && !Role_if(PM_PRIEST)) - Strcat(prefix, "uncursed "); + && obj->otyp != FAKE_AMULET_OF_YENDOR + && obj->otyp != AMULET_OF_YENDOR + && !Role_if(PM_PRIEST)) + Strcat(prefix, "uncursed "); } if (lknown && Is_box(obj)) { if (obj->obroken) Strcat(prefix, "unlockable "); else if (obj->olocked) - Strcat(prefix, "locked "); + Strcat(prefix, "locked "); else - Strcat(prefix, "unlocked "); + Strcat(prefix, "unlocked "); } - if (obj->greased) Strcat(prefix, "greased "); + if (obj->greased) + Strcat(prefix, "greased "); if (cknown && Has_contents(obj)) { /* we count all objects (obj->quantity); perhaps we should @@ -787,35 +820,35 @@ register struct obj *obj; when there are 2 scrolls plus 1000 gold pieces */ long itemcount = count_contents(obj, FALSE, TRUE, TRUE); - Sprintf(eos(bp), " containing %ld item%s", - itemcount, plur(itemcount)); + Sprintf(eos(bp), " containing %ld item%s", itemcount, + plur(itemcount)); } - switch(obj->oclass) { + switch (obj->oclass) { case AMULET_CLASS: - if(obj->owornmask & W_AMUL) + if (obj->owornmask & W_AMUL) Strcat(bp, " (being worn)"); break; case WEAPON_CLASS: - if(ispoisoned) + if (ispoisoned) Strcat(prefix, "poisoned "); -plus: + plus: add_erosion_words(obj, prefix); - if(known) { + if (known) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } break; case ARMOR_CLASS: - if(obj->owornmask & W_ARMOR) - Strcat(bp, (obj == uskin) ? " (embedded in your skin)" : - " (being worn)"); + if (obj->owornmask & W_ARMOR) + Strcat(bp, (obj == uskin) ? " (embedded in your skin)" + : " (being worn)"); goto plus; case TOOL_CLASS: /* weptools already get this done when we go to the +n code */ if (!is_weptool(obj)) add_erosion_words(obj, prefix); - if(obj->owornmask & (W_TOOL /* blindfold */ | W_SADDLE)) { + if (obj->owornmask & (W_TOOL /* blindfold */ | W_SADDLE)) { Strcat(bp, " (being worn)"); break; } @@ -830,27 +863,26 @@ plus: Strcpy(tmpbuf, "no"); else Sprintf(tmpbuf, "%d", obj->spe); - Sprintf(eos(bp), " (%s candle%s%s)", - tmpbuf, plur(obj->spe), - !obj->lamplit ? " attached" : ", lit"); + Sprintf(eos(bp), " (%s candle%s%s)", tmpbuf, plur(obj->spe), + !obj->lamplit ? " attached" : ", lit"); break; - } else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP || - obj->otyp == BRASS_LANTERN || Is_candle(obj)) { - if (Is_candle(obj) && - obj->age < 20L * (long)objects[obj->otyp].oc_cost) + } else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP + || obj->otyp == BRASS_LANTERN || Is_candle(obj)) { + if (Is_candle(obj) + && obj->age < 20L * (long) objects[obj->otyp].oc_cost) Strcat(prefix, "partly used "); - if(obj->lamplit) + if (obj->lamplit) Strcat(bp, " (lit)"); break; } - if(objects[obj->otyp].oc_charged) + if (objects[obj->otyp].oc_charged) goto charges; break; case WAND_CLASS: add_erosion_words(obj, prefix); -charges: - if(known) - Sprintf(eos(bp), " (%d:%d)", (int)obj->recharged, obj->spe); + charges: + if (known) + Sprintf(eos(bp), " (%d:%d)", (int) obj->recharged, obj->spe); break; case POTION_CLASS: if (obj->otyp == POT_OIL && obj->lamplit) @@ -858,14 +890,16 @@ charges: break; case RING_CLASS: add_erosion_words(obj, prefix); -ring: - if(obj->owornmask & W_RINGR) Strcat(bp, " (on right "); - if(obj->owornmask & W_RINGL) Strcat(bp, " (on left "); - if(obj->owornmask & W_RING) { + ring: + if (obj->owornmask & W_RINGR) + Strcat(bp, " (on right "); + if (obj->owornmask & W_RINGL) + Strcat(bp, " (on left "); + if (obj->owornmask & W_RING) { Strcat(bp, body_part(HAND)); Strcat(bp, ")"); } - if(known && objects[obj->otyp].oc_charged) { + if (known && objects[obj->otyp].oc_charged) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } @@ -875,68 +909,68 @@ ring: Strcat(prefix, "partly eaten "); if (obj->otyp == CORPSE) { Sprintf(prefix, "%s ", - corpse_xname(obj, prefix, - CXN_ARTICLE|CXN_NOCORPSE)); + corpse_xname(obj, prefix, CXN_ARTICLE | CXN_NOCORPSE)); } else if (obj->otyp == EGG) { -#if 0 /* corpses don't tell if they're stale either */ +#if 0 /* corpses don't tell if they're stale either */ if (known && stale_egg(obj)) Strcat(prefix, "stale "); #endif - if (omndx >= LOW_PM && (known || - (mvitals[omndx].mvflags & MV_KNOWS_EGG))) { - Strcat(prefix, mons[omndx].mname); - Strcat(prefix, " "); - if (obj->spe) - Strcat(bp, " (laid by you)"); + if (omndx >= LOW_PM + && (known || (mvitals[omndx].mvflags & MV_KNOWS_EGG))) { + Strcat(prefix, mons[omndx].mname); + Strcat(prefix, " "); + if (obj->spe) + Strcat(bp, " (laid by you)"); } } - if (obj->otyp == MEAT_RING) goto ring; + if (obj->otyp == MEAT_RING) + goto ring; break; case BALL_CLASS: case CHAIN_CLASS: add_erosion_words(obj, prefix); - if(obj->owornmask & W_BALL) + if (obj->owornmask & W_BALL) Strcat(bp, " (chained to you)"); - break; + break; } - if((obj->owornmask & W_WEP) && !mrg_to_wielded) { + if ((obj->owornmask & W_WEP) && !mrg_to_wielded) { if (obj->quan != 1L) { Strcat(bp, " (wielded)"); } else { const char *hand_s = body_part(HAND); - if (bimanual(obj)) hand_s = makeplural(hand_s); + if (bimanual(obj)) + hand_s = makeplural(hand_s); Sprintf(eos(bp), " (weapon in %s)", hand_s); } } - if(obj->owornmask & W_SWAPWEP) { + if (obj->owornmask & W_SWAPWEP) { if (u.twoweap) - Sprintf(eos(bp), " (wielded in other %s)", - body_part(HAND)); + Sprintf(eos(bp), " (wielded in other %s)", body_part(HAND)); else Strcat(bp, " (alternate weapon; not wielded)"); } - if(obj->owornmask & W_QUIVER){ - switch(obj->oclass){ + if (obj->owornmask & W_QUIVER) { + switch (obj->oclass) { case WEAPON_CLASS: - if(is_ammo(obj)){ - if(objects[obj->otyp].oc_skill == -P_BOW){ - /* Ammo for a bow */ + if (is_ammo(obj)) { + if (objects[obj->otyp].oc_skill == -P_BOW) { + /* Ammo for a bow */ Strcat(bp, " (in quiver)"); break; } else { - /* Ammo not for a bow */ + /* Ammo not for a bow */ Strcat(bp, " (in quiver pouch)"); break; } } else { - /* Weapons not considered ammo */ + /* Weapons not considered ammo */ Strcat(bp, " (at the ready)"); break; } - /* Small things and ammo not for a bow */ + /* Small things and ammo not for a bow */ case RING_CLASS: case AMULET_CLASS: case WAND_CLASS: @@ -944,25 +978,24 @@ ring: case GEM_CLASS: Strcat(bp, " (in quiver pouch)"); break; - default: /* odd things */ + default: /* odd things */ Strcat(bp, " (at the ready)"); } } if (!iflags.suppress_price && is_unpaid(obj)) { long quotedprice = unpaid_cost(obj, TRUE); - Sprintf(eos(bp), " (%s, %ld %s)", - obj->unpaid ? "unpaid" : "contents", - quotedprice, currency(quotedprice)); + Sprintf(eos(bp), " (%s, %ld %s)", obj->unpaid ? "unpaid" : "contents", + quotedprice, currency(quotedprice)); } - if (!strncmp(prefix, "a ", 2) && - index(vowels, *(prefix+2) ? *(prefix+2) : *bp) - && (*(prefix+2) || (strncmp(bp, "uranium", 7) - && strncmp(bp, "unicorn", 7) + if (!strncmp(prefix, "a ", 2) + && index(vowels, *(prefix + 2) ? *(prefix + 2) : *bp) + && (*(prefix + 2) + || (strncmp(bp, "uranium", 7) && strncmp(bp, "unicorn", 7) && strncmp(bp, "eucalyptus", 10)))) { Strcpy(tmpbuf, prefix); Strcpy(prefix, "an "); - Strcpy(prefix+3, tmpbuf+2); + Strcpy(prefix + 3, tmpbuf + 2); } /* show weight for items (debug tourist info) @@ -971,7 +1004,7 @@ ring: Sprintf(eos(bp), " (%d aum)", obj->owt); } bp = strprepend(bp, prefix); - return(bp); + return (bp); } /* used from invent.c */ @@ -980,7 +1013,8 @@ not_fully_identified(otmp) register struct obj *otmp; { /* gold doesn't have any interesting attributes [yet?] */ - if (otmp->oclass == COIN_CLASS) return FALSE; /* always fully ID'd */ + if (otmp->oclass == COIN_CLASS) + return FALSE; /* always fully ID'd */ /* check fundamental ID hallmarks first */ if (!otmp->known || !otmp->dknown || #ifdef MAIL @@ -989,108 +1023,111 @@ register struct obj *otmp; !otmp->bknown || #endif !objects[otmp->otyp].oc_name_known) - return TRUE; - if ((!otmp->cknown && (Is_container(otmp) || otmp->otyp == STATUE)) || - (!otmp->lknown && Is_box(otmp))) - return TRUE; + return TRUE; + if ((!otmp->cknown && (Is_container(otmp) || otmp->otyp == STATUE)) + || (!otmp->lknown && Is_box(otmp))) + return TRUE; if (otmp->oartifact && undiscovered_artifact(otmp->oartifact)) - return TRUE; + return TRUE; /* otmp->rknown is the only item of interest if we reach here */ - /* - * Note: if a revision ever allows scrolls to become fireproof or - * rings to become shockproof, this checking will need to be revised. - * `rknown' ID only matters if xname() will provide the info about it. - */ - if (otmp->rknown || (otmp->oclass != ARMOR_CLASS && - otmp->oclass != WEAPON_CLASS && - !is_weptool(otmp) && /* (redunant) */ - otmp->oclass != BALL_CLASS)) /* (useless) */ - return FALSE; - else /* lack of `rknown' only matters for vulnerable objects */ - return (boolean)(is_rustprone(otmp) || - is_corrodeable(otmp) || - is_flammable(otmp)); + /* + * Note: if a revision ever allows scrolls to become fireproof or + * rings to become shockproof, this checking will need to be revised. + * `rknown' ID only matters if xname() will provide the info about it. + */ + if (otmp->rknown + || (otmp->oclass != ARMOR_CLASS && otmp->oclass != WEAPON_CLASS + && !is_weptool(otmp) && /* (redunant) */ + otmp->oclass != BALL_CLASS)) /* (useless) */ + return FALSE; + else /* lack of `rknown' only matters for vulnerable objects */ + return (boolean)(is_rustprone(otmp) || is_corrodeable(otmp) + || is_flammable(otmp)); } char * corpse_xname(otmp, adjective, cxn_flags) struct obj *otmp; const char *adjective; -unsigned cxn_flags; /* bitmask of CXN_xxx values */ +unsigned cxn_flags; /* bitmask of CXN_xxx values */ { char *nambuf = nextobuf(); int omndx = otmp->corpsenm; boolean ignore_quan = (cxn_flags & CXN_SINGULAR) != 0, - /* suppress "the" from "the unique monster corpse" */ + /* suppress "the" from "the unique monster corpse" */ no_prefix = (cxn_flags & CXN_NO_PFX) != 0, - /* include "the" for "the woodchuck corpse */ + /* include "the" for "the woodchuck corpse */ the_prefix = (cxn_flags & CXN_PFX_THE) != 0, - /* include "an" for "an ogre corpse */ + /* include "an" for "an ogre corpse */ any_prefix = (cxn_flags & CXN_ARTICLE) != 0, - /* leave off suffix (do_name() appends "corpse" itself) */ - omit_corpse = (cxn_flags & CXN_NOCORPSE) != 0, - possessive = FALSE; + /* leave off suffix (do_name() appends "corpse" itself) */ + omit_corpse = (cxn_flags & CXN_NOCORPSE) != 0, possessive = FALSE; const char *mname; - if (omndx == NON_PM) { /* paranoia */ + if (omndx == NON_PM) { /* paranoia */ mname = "thing"; - /* [Possible enhancement: check whether corpse has monster traits - attached in order to use priestname() for priests and minions.] */ + /* [Possible enhancement: check whether corpse has monster traits + attached in order to use priestname() for priests and minions.] */ } else if (omndx == PM_ALIGNED_PRIEST) { /* avoid "aligned priest"; it just exposes internal details */ mname = "priest"; } else { mname = mons[omndx].mname; if (the_unique_pm(&mons[omndx]) || type_is_pname(&mons[omndx])) { - mname = s_suffix(mname); - possessive = TRUE; - /* don't precede personal name like "Medusa" with an article */ - if (type_is_pname(&mons[omndx])) - no_prefix = TRUE; - /* always precede non-personal unique monster name like - "Oracle" with "the" unless explicitly overridden */ - else if (the_unique_pm(&mons[omndx]) && !no_prefix) - the_prefix = TRUE; + mname = s_suffix(mname); + possessive = TRUE; + /* don't precede personal name like "Medusa" with an article */ + if (type_is_pname(&mons[omndx])) + no_prefix = TRUE; + /* always precede non-personal unique monster name like + "Oracle" with "the" unless explicitly overridden */ + else if (the_unique_pm(&mons[omndx]) && !no_prefix) + the_prefix = TRUE; } } - if (no_prefix) the_prefix = any_prefix = FALSE; - else if (the_prefix) any_prefix = FALSE; /* mutually exclusive */ + if (no_prefix) + the_prefix = any_prefix = FALSE; + else if (the_prefix) + any_prefix = FALSE; /* mutually exclusive */ *nambuf = '\0'; /* can't use the() the way we use an() below because any capitalized Name causes it to assume a personal name and return Name as-is; that's usually the behavior wanted, but here we need to force "the" to precede capitalized unique monsters (pnames are handled above) */ - if (the_prefix) Strcat(nambuf, "the "); + if (the_prefix) + Strcat(nambuf, "the "); if (!adjective || !*adjective) { /* normal case: newt corpse */ Strcat(nambuf, mname); } else { /* adjective positioning depends upon format of monster name */ - if (possessive) /* Medusa's cursed partly eaten corpse */ - Sprintf(eos(nambuf), "%s %s", mname, adjective); - else /* cursed partly eaten troll corpse */ - Sprintf(eos(nambuf), "%s %s", adjective, mname); + if (possessive) /* Medusa's cursed partly eaten corpse */ + Sprintf(eos(nambuf), "%s %s", mname, adjective); + else /* cursed partly eaten troll corpse */ + Sprintf(eos(nambuf), "%s %s", adjective, mname); /* in case adjective has a trailing space, squeeze it out */ mungspaces(nambuf); /* doname() might include a count in the adjective argument; if so, don't prepend an article */ - if (digit(*adjective)) any_prefix = FALSE; + if (digit(*adjective)) + any_prefix = FALSE; } if (!omit_corpse) { Strcat(nambuf, " corpse"); /* makeplural(nambuf) => append "s" to "corpse" */ if (otmp->quan > 1L && !ignore_quan) { - Strcat(nambuf, "s"); - any_prefix = FALSE; /* avoid "a newt corpses" */ + Strcat(nambuf, "s"); + any_prefix = FALSE; /* avoid "a newt corpses" */ } } /* it's safe to overwrite our nambuf after an() has copied its old value into another buffer */ - if (any_prefix) Strcpy(nambuf, an(nambuf)); + if (any_prefix) + Strcpy(nambuf, an(nambuf)); return nambuf; } @@ -1101,7 +1138,7 @@ cxname(obj) struct obj *obj; { if (obj->otyp == CORPSE) - return corpse_xname(obj, (const char *)0, CXN_NORMAL); + return corpse_xname(obj, (const char *) 0, CXN_NORMAL); return xname(obj); } @@ -1110,9 +1147,9 @@ char * cxname_singular(obj) struct obj *obj; { - if (obj->otyp == CORPSE) - return corpse_xname(obj, (const char *)0, CXN_SINGULAR); - return xname_flags(obj, CXN_SINGULAR); + if (obj->otyp == CORPSE) + return corpse_xname(obj, (const char *) 0, CXN_SINGULAR); + return xname_flags(obj, CXN_SINGULAR); } /* treat an object as fully ID'd when it might be used as reason for death */ @@ -1122,57 +1159,63 @@ struct obj *obj; { struct obj save_obj; unsigned save_ocknown; - char *buf, *save_ocuname, *save_oname = (char *)0; + char *buf, *save_ocuname, *save_oname = (char *) 0; /* bypass object twiddling for artifacts */ - if (obj->oartifact) return bare_artifactname(obj); + if (obj->oartifact) + return bare_artifactname(obj); /* remember original settings for core of the object; oextra structs other than oname don't matter here--since they aren't modified they don't need to be saved and restored */ save_obj = *obj; - if (has_oname(obj)) save_oname = ONAME(obj); + if (has_oname(obj)) + save_oname = ONAME(obj); /* killer name should be more specific than general xname; however, exact info like blessed/cursed and rustproof makes things be too verbose */ obj->known = obj->dknown = 1; obj->bknown = obj->rknown = obj->greased = 0; /* if character is a priest[ess], bknown will get toggled back on */ - if (obj->otyp != POT_WATER) obj->blessed = obj->cursed = 0; - else obj->bknown = 1; /* describe holy/unholy water as such */ + if (obj->otyp != POT_WATER) + obj->blessed = obj->cursed = 0; + else + obj->bknown = 1; /* describe holy/unholy water as such */ /* "killed by poisoned " would be misleading when poison is not the cause of death and "poisoned by poisoned " would be redundant when it is, so suppress "poisoned" prefix */ obj->opoisoned = 0; /* strip user-supplied name; artifacts keep theirs */ - if (!obj->oartifact && save_oname) ONAME(obj) = (char *)0; + if (!obj->oartifact && save_oname) + ONAME(obj) = (char *) 0; /* temporarily identify the type of object */ save_ocknown = objects[obj->otyp].oc_name_known; objects[obj->otyp].oc_name_known = 1; save_ocuname = objects[obj->otyp].oc_uname; - objects[obj->otyp].oc_uname = 0; /* avoid "foo called bar" */ + objects[obj->otyp].oc_uname = 0; /* avoid "foo called bar" */ /* format the object */ if (obj->otyp == CORPSE) { - buf = nextobuf(); - Strcpy(buf, corpse_xname(obj, (const char *)0, CXN_NORMAL)); + buf = nextobuf(); + Strcpy(buf, corpse_xname(obj, (const char *) 0, CXN_NORMAL)); } else if (obj->otyp == SLIME_MOLD) { - /* concession to "most unique deaths competition" in the annual - devnull tournament, suppress player supplied fruit names because - those can be used to fake other objects and dungeon features */ - buf = nextobuf(); - Sprintf(buf, "deadly slime mold%s", plur(obj->quan)); + /* concession to "most unique deaths competition" in the annual + devnull tournament, suppress player supplied fruit names because + those can be used to fake other objects and dungeon features */ + buf = nextobuf(); + Sprintf(buf, "deadly slime mold%s", plur(obj->quan)); } else { - buf = xname(obj); + buf = xname(obj); } /* apply an article if appropriate; caller should always use KILLED_BY */ if (obj->quan == 1L && !strstri(buf, "'s ") && !strstri(buf, "s' ")) - buf = (obj_is_pname(obj) || the_unique_obj(obj)) ? the(buf) : an(buf); + buf = (obj_is_pname(obj) || the_unique_obj(obj)) ? the(buf) : an(buf); objects[obj->otyp].oc_name_known = save_ocknown; objects[obj->otyp].oc_uname = save_ocuname; - *obj = save_obj; /* restore object's core settings */ - if (!obj->oartifact && save_oname) ONAME(obj) = save_oname; + *obj = save_obj; /* restore object's core settings */ + if (!obj->oartifact && save_oname) + ONAME(obj) = save_oname; return buf; } @@ -1181,54 +1224,56 @@ struct obj *obj; char * short_oname(obj, func, altfunc, lenlimit) struct obj *obj; -char *FDECL((*func), (OBJ_P)), /* main formatting routine */ - *FDECL((*altfunc), (OBJ_P)); /* alternate for shortest result */ +char *FDECL((*func), (OBJ_P)), /* main formatting routine */ + *FDECL((*altfunc), (OBJ_P)); /* alternate for shortest result */ unsigned lenlimit; { struct obj save_obj; - char unamebuf[12], onamebuf[12], - *save_oname, *save_uname, *outbuf; + char unamebuf[12], onamebuf[12], *save_oname, *save_uname, *outbuf; outbuf = (*func)(obj); - if ((unsigned)strlen(outbuf) <= lenlimit) return outbuf; + if ((unsigned) strlen(outbuf) <= lenlimit) + return outbuf; /* shorten called string to fairly small amount */ save_uname = objects[obj->otyp].oc_uname; if (save_uname && strlen(save_uname) >= sizeof unamebuf) { - (void) strncpy(unamebuf, save_uname, sizeof unamebuf - 4); - Strcpy(unamebuf + sizeof unamebuf - 4, "..."); - objects[obj->otyp].oc_uname = unamebuf; - releaseobuf(outbuf); - outbuf = (*func)(obj); - objects[obj->otyp].oc_uname = save_uname; /* restore called string */ - if ((unsigned)strlen(outbuf) <= lenlimit) return outbuf; + (void) strncpy(unamebuf, save_uname, sizeof unamebuf - 4); + Strcpy(unamebuf + sizeof unamebuf - 4, "..."); + objects[obj->otyp].oc_uname = unamebuf; + releaseobuf(outbuf); + outbuf = (*func)(obj); + objects[obj->otyp].oc_uname = save_uname; /* restore called string */ + if ((unsigned) strlen(outbuf) <= lenlimit) + return outbuf; } /* shorten named string to fairly small amount */ save_oname = has_oname(obj) ? ONAME(obj) : 0; if (save_oname && strlen(save_oname) >= sizeof onamebuf) { - (void) strncpy(onamebuf, save_oname, sizeof onamebuf - 4); - Strcpy(onamebuf + sizeof onamebuf - 4, "..."); - ONAME(obj) = onamebuf; - releaseobuf(outbuf); - outbuf = (*func)(obj); - ONAME(obj) = save_oname; /* restore named string */ - if ((unsigned)strlen(outbuf) <= lenlimit) return outbuf; + (void) strncpy(onamebuf, save_oname, sizeof onamebuf - 4); + Strcpy(onamebuf + sizeof onamebuf - 4, "..."); + ONAME(obj) = onamebuf; + releaseobuf(outbuf); + outbuf = (*func)(obj); + ONAME(obj) = save_oname; /* restore named string */ + if ((unsigned) strlen(outbuf) <= lenlimit) + return outbuf; } /* shorten both called and named strings; unamebuf and onamebuf have both already been populated */ - if (save_uname && strlen(save_uname) >= sizeof unamebuf && - save_oname && strlen(save_oname) >= sizeof onamebuf) { - objects[obj->otyp].oc_uname = unamebuf; - ONAME(obj) = onamebuf; - releaseobuf(outbuf); - outbuf = (*func)(obj); - if ((unsigned)strlen(outbuf) <= lenlimit) { - objects[obj->otyp].oc_uname = save_uname; - ONAME(obj) = save_oname; - return outbuf; - } + if (save_uname && strlen(save_uname) >= sizeof unamebuf && save_oname + && strlen(save_oname) >= sizeof onamebuf) { + objects[obj->otyp].oc_uname = unamebuf; + ONAME(obj) = onamebuf; + releaseobuf(outbuf); + outbuf = (*func)(obj); + if ((unsigned) strlen(outbuf) <= lenlimit) { + objects[obj->otyp].oc_uname = save_uname; + ONAME(obj) = save_oname; + return outbuf; + } } /* still long; strip several name-lengthening attributes; @@ -1238,16 +1283,18 @@ unsigned lenlimit; obj->oeroded = obj->oeroded2 = 0; releaseobuf(outbuf); outbuf = (*func)(obj); - if (altfunc && (unsigned)strlen(outbuf) > lenlimit) { - /* still long; use the alternate function (usually one of - the jackets around minimal_xname()) */ - releaseobuf(outbuf); - outbuf = (*altfunc)(obj); + if (altfunc && (unsigned) strlen(outbuf) > lenlimit) { + /* still long; use the alternate function (usually one of + the jackets around minimal_xname()) */ + releaseobuf(outbuf); + outbuf = (*altfunc)(obj); } /* restore the object */ *obj = save_obj; - if (save_oname) ONAME(obj) = save_oname; - if (save_uname) objects[obj->otyp].oc_uname = save_uname; + if (save_oname) + ONAME(obj) = save_oname; + if (save_uname) + objects[obj->otyp].oc_uname = save_uname; /* use whatever we've got, whether it's too long or not */ return outbuf; @@ -1265,7 +1312,8 @@ char *FDECL((*func), (OBJ_P)); char *nam; /* using xname for corpses does not give the monster type */ - if (otmp->otyp == CORPSE && func == xname) func = cxname; + if (otmp->otyp == CORPSE && func == xname) + func = cxname; savequan = otmp->quan; otmp->quan = 1L; @@ -1282,16 +1330,11 @@ register const char *str; buf[0] = '\0'; - if (strncmpi(str, "the ", 4) && - strcmp(str, "molten lava") && - strcmp(str, "iron bars") && - strcmp(str, "ice")) { - if (index(vowels, *str) && - strncmp(str, "one-", 4) && - strncmp(str, "useful", 6) && - strncmp(str, "unicorn", 7) && - strncmp(str, "uranium", 7) && - strncmp(str, "eucalyptus", 10)) + if (strncmpi(str, "the ", 4) && strcmp(str, "molten lava") + && strcmp(str, "iron bars") && strcmp(str, "ice")) { + if (index(vowels, *str) && strncmp(str, "one-", 4) + && strncmp(str, "useful", 6) && strncmp(str, "unicorn", 7) + && strncmp(str, "uranium", 7) && strncmp(str, "eucalyptus", 10)) Strcpy(buf, "an "); else Strcpy(buf, "a "); @@ -1323,7 +1366,7 @@ const char *str; if (!strncmpi(str, "the ", 4)) { buf[0] = lowc(*str); - Strcpy(&buf[1], str+1); + Strcpy(&buf[1], str + 1); return buf; } else if (*str < 'A' || *str > 'Z') { /* not a proper name, needs an article */ @@ -1334,22 +1377,24 @@ const char *str; int l; /* some objects have capitalized adjectives in their names */ - if(((tmp = rindex(str, ' ')) || (tmp = rindex(str, '-'))) && - (tmp[1] < 'A' || tmp[1] > 'Z')) - insert_the = TRUE; - else if (tmp && index(str, ' ') < tmp) { /* has spaces */ - /* it needs an article if the name contains "of" */ - tmp = strstri(str, " of "); - named = strstri(str, " named "); - called = strstri(str, " called "); - if (called && (!named || called < named)) named = called; + if (((tmp = rindex(str, ' ')) || (tmp = rindex(str, '-'))) + && (tmp[1] < 'A' || tmp[1] > 'Z')) + insert_the = TRUE; + else if (tmp && index(str, ' ') < tmp) { /* has spaces */ + /* it needs an article if the name contains "of" */ + tmp = strstri(str, " of "); + named = strstri(str, " named "); + called = strstri(str, " called "); + if (called && (!named || called < named)) + named = called; - if (tmp && (!named || tmp < named)) /* found an "of" */ - insert_the = TRUE; - /* stupid special case: lacks "of" but needs "the" */ - else if (!named && (l = strlen(str)) >= 31 && - !strcmp(&str[l - 31], "Platinum Yendorian Express Card")) - insert_the = TRUE; + if (tmp && (!named || tmp < named)) /* found an "of" */ + insert_the = TRUE; + /* stupid special case: lacks "of" but needs "the" */ + else if (!named && (l = strlen(str)) >= 31 + && !strcmp(&str[l - 31], + "Platinum Yendorian Express Card")) + insert_the = TRUE; } } if (insert_the) @@ -1372,28 +1417,28 @@ const char *str; /* returns "count cxname(otmp)" or just cxname(otmp) if count == 1 */ char * -aobjnam(otmp,verb) +aobjnam(otmp, verb) register struct obj *otmp; register const char *verb; { register char *bp = cxname(otmp); char prefix[PREFIX]; - if(otmp->quan != 1L) { + if (otmp->quan != 1L) { Sprintf(prefix, "%ld ", otmp->quan); bp = strprepend(bp, prefix); } - if(verb) { + if (verb) { Strcat(bp, " "); Strcat(bp, otense(otmp, verb)); } - return(bp); + return (bp); } /* combine yname and aobjnam eg "your count cxname(otmp)" */ char * -yobjnam(obj,verb) +yobjnam(obj, verb) struct obj *obj; const char *verb; { @@ -1401,8 +1446,8 @@ const char *verb; /* leave off "your" for most of your artifacts, but prepend * "your" for unique objects and "foo of bar" quest artifacts */ - if (!carried(obj) || !obj_is_pname(obj) || - obj->oartifact >= ART_ORB_OF_DETECTION) { + if (!carried(obj) || !obj_is_pname(obj) + || obj->oartifact >= ART_ORB_OF_DETECTION) { char *outbuf = shk_your(nextobuf(), obj); int space_left = BUFSZ - 1 - strlen(outbuf); @@ -1414,14 +1459,14 @@ const char *verb; /* combine Yname2 and aobjnam eg "Your count cxname(otmp)" */ char * -Yobjnam2(obj,verb) +Yobjnam2(obj, verb) struct obj *obj; const char *verb; { - register char *s = yobjnam(obj,verb); + register char *s = yobjnam(obj, verb); *s = highc(*s); - return(s); + return (s); } /* like aobjnam, but prepend "The", not count, and use xname */ @@ -1432,11 +1477,11 @@ register const char *verb; { char *bp = The(xname(otmp)); - if(verb) { + if (verb) { Strcat(bp, " "); Strcat(bp, otense(otmp, verb)); } - return(bp); + return (bp); } /* capitalized variant of doname() */ @@ -1447,7 +1492,7 @@ register struct obj *obj; register char *s = doname(obj); *s = highc(*s); - return(s); + return (s); } /* returns "[your ]xname(obj)" or "Foobar's xname(obj)" or "the xname(obj)" */ @@ -1459,8 +1504,8 @@ struct obj *obj; /* leave off "your" for most of your artifacts, but prepend * "your" for unique objects and "foo of bar" quest artifacts */ - if (!carried(obj) || !obj_is_pname(obj) || - obj->oartifact >= ART_ORB_OF_DETECTION) { + if (!carried(obj) || !obj_is_pname(obj) + || obj->oartifact >= ART_ORB_OF_DETECTION) { char *outbuf = shk_your(nextobuf(), obj); int space_left = BUFSZ - 1 - strlen(outbuf); @@ -1490,7 +1535,7 @@ ysimple_name(obj) struct obj *obj; { char *outbuf = nextobuf(); - char *s = shk_your(outbuf, obj); /* assert( s == outbuf ); */ + char *s = shk_your(outbuf, obj); /* assert( s == outbuf ); */ int space_left = BUFSZ - 1 - strlen(s); return strncat(s, minimal_xname(obj), space_left); @@ -1514,7 +1559,8 @@ struct obj *obj; { char *simpleoname = minimal_xname(obj); - if (obj->quan != 1L) simpleoname = makeplural(simpleoname); + if (obj->quan != 1L) + simpleoname = makeplural(simpleoname); return simpleoname; } @@ -1529,13 +1575,15 @@ struct obj *obj; /* prefix with "the" if a unique item, or a fake one imitating same, has been formatted with its actual name (we let typename() handle any `known' and `dknown' checking necessary) */ - if (otyp == FAKE_AMULET_OF_YENDOR) otyp = AMULET_OF_YENDOR; - if (objects[otyp].oc_unique && - !strcmp(simpleoname, OBJ_NAME(objects[otyp]))) + if (otyp == FAKE_AMULET_OF_YENDOR) + otyp = AMULET_OF_YENDOR; + if (objects[otyp].oc_unique + && !strcmp(simpleoname, OBJ_NAME(objects[otyp]))) return the(simpleoname); /* simpleoname is singular if quan==1, plural otherwise */ - if (obj->quan == 1L) simpleoname = an(simpleoname); + if (obj->quan == 1L) + simpleoname = an(simpleoname); return simpleoname; } @@ -1559,7 +1607,8 @@ struct obj *obj; if (obj->oartifact) { outbuf = nextobuf(); Strcpy(outbuf, artiname(obj->oartifact)); - if (!strncmp(outbuf, "The ", 4)) outbuf[0] = lowc(outbuf[0]); + if (!strncmp(outbuf, "The ", 4)) + outbuf[0] = lowc(outbuf[0]); } else { outbuf = xname(obj); } @@ -1567,17 +1616,16 @@ struct obj *obj; } static const char *wrp[] = { - "wand", "ring", "potion", "scroll", "gem", "amulet", - "spellbook", "spell book", + "wand", "ring", "potion", "scroll", "gem", + "amulet", "spellbook", "spell book", /* for non-specific wishes */ - "weapon", "armor", "tool", "food", "comestible", -}; -static const char wrpsym[] = { - WAND_CLASS, RING_CLASS, POTION_CLASS, SCROLL_CLASS, GEM_CLASS, - AMULET_CLASS, SPBOOK_CLASS, SPBOOK_CLASS, - WEAPON_CLASS, ARMOR_CLASS, TOOL_CLASS, FOOD_CLASS, - FOOD_CLASS + "weapon", "armor", "tool", "food", "comestible", }; +static const char wrpsym[] = { WAND_CLASS, RING_CLASS, POTION_CLASS, + SCROLL_CLASS, GEM_CLASS, AMULET_CLASS, + SPBOOK_CLASS, SPBOOK_CLASS, WEAPON_CLASS, + ARMOR_CLASS, TOOL_CLASS, FOOD_CLASS, + FOOD_CLASS }; /* return form of the verb (input plural) if xname(otmp) were the subject */ char * @@ -1593,7 +1641,7 @@ register const char *verb; * recomputing xname(otmp) at this time. */ if (!is_plural(otmp)) - return vtense((char *)0, verb); + return vtense((char *) 0, verb); buf = nextobuf(); Strcpy(buf, verb); @@ -1602,19 +1650,11 @@ register const char *verb; /* various singular words that vtense would otherwise categorize as plural; also used by makesingular() to catch some special cases */ -static const char * const special_subjs[] = { - "erinys", - "manes", /* this one is ambiguous */ - "Cyclops", - "Hippocrates", - "Pelias", - "aklys", - "amnesia", - "detect monsters", - "paralysis", - "shape changers", - "nemesis", - 0 +static const char *const special_subjs[] = { + "erinys", "manes", /* this one is ambiguous */ + "Cyclops", "Hippocrates", "Pelias", "aklys", + "amnesia", "detect monsters", "paralysis", "shape changers", + "nemesis", 0 /* note: "detect monsters" and "shape changers" are normally caught via "(s) of ", but they can be wished for using the shorter form, so we include them here @@ -1630,7 +1670,7 @@ register const char *verb; char *buf = nextobuf(), *bspot; int len, ltmp; const char *sp, *spot; - const char * const *spec; + const char *const *spec; /* * verb is given in plural (without trailing s). Return as input @@ -1643,73 +1683,75 @@ register const char *verb; * present tense form so we don't duplicate this code elsewhere. */ if (subj) { - if (!strncmpi(subj, "a ", 2) || !strncmpi(subj, "an ", 3)) - goto sing; - spot = (const char *)0; - for (sp = subj; (sp = index(sp, ' ')) != 0; ++sp) { - if (!strncmpi(sp, " of ", 4) || - !strncmpi(sp, " from ", 6) || - !strncmpi(sp, " called ", 8) || - !strncmpi(sp, " named ", 7) || - !strncmpi(sp, " labeled ", 9)) { - if (sp != subj) spot = sp - 1; - break; + if (!strncmpi(subj, "a ", 2) || !strncmpi(subj, "an ", 3)) + goto sing; + spot = (const char *) 0; + for (sp = subj; (sp = index(sp, ' ')) != 0; ++sp) { + if (!strncmpi(sp, " of ", 4) || !strncmpi(sp, " from ", 6) + || !strncmpi(sp, " called ", 8) || !strncmpi(sp, " named ", 7) + || !strncmpi(sp, " labeled ", 9)) { + if (sp != subj) + spot = sp - 1; + break; + } } - } - len = (int) strlen(subj); - if (!spot) spot = subj + len - 1; + len = (int) strlen(subj); + if (!spot) + spot = subj + len - 1; - /* - * plural: anything that ends in 's', but not '*us' or '*ss'. - * Guess at a few other special cases that makeplural creates. - */ - if ((lowc(*spot) == 's' && spot != subj && - !index("us", lowc(*(spot-1)))) || - !BSTRNCMPI(subj, spot-3, "eeth", 4) || - !BSTRNCMPI(subj, spot-3, "feet", 4) || - !BSTRNCMPI(subj, spot-1, "ia", 2) || - !BSTRNCMPI(subj, spot-1, "ae", 2)) { - /* check for special cases to avoid false matches */ - len = (int)(spot - subj) + 1; - for (spec = special_subjs; *spec; spec++) { - ltmp = strlen(*spec); - if (len == ltmp && !strncmpi(*spec, subj, len)) goto sing; - /* also check for - to catch things like "the invisible erinys" */ - if (len > ltmp && *(spot - ltmp) == ' ' && - !strncmpi(*spec, spot - ltmp + 1, ltmp)) goto sing; + /* + * plural: anything that ends in 's', but not '*us' or '*ss'. + * Guess at a few other special cases that makeplural creates. + */ + if ((lowc(*spot) == 's' && spot != subj + && !index("us", lowc(*(spot - 1)))) + || !BSTRNCMPI(subj, spot - 3, "eeth", 4) + || !BSTRNCMPI(subj, spot - 3, "feet", 4) + || !BSTRNCMPI(subj, spot - 1, "ia", 2) + || !BSTRNCMPI(subj, spot - 1, "ae", 2)) { + /* check for special cases to avoid false matches */ + len = (int) (spot - subj) + 1; + for (spec = special_subjs; *spec; spec++) { + ltmp = strlen(*spec); + if (len == ltmp && !strncmpi(*spec, subj, len)) + goto sing; + /* also check for + to catch things like "the invisible erinys" */ + if (len > ltmp && *(spot - ltmp) == ' ' + && !strncmpi(*spec, spot - ltmp + 1, ltmp)) + goto sing; + } + + return strcpy(buf, verb); } - - return strcpy(buf, verb); - } - /* - * 3rd person plural doesn't end in telltale 's'; - * 2nd person singular behaves as if plural. - */ - if (!strcmpi(subj, "they") || !strcmpi(subj, "you")) - return strcpy(buf, verb); + /* + * 3rd person plural doesn't end in telltale 's'; + * 2nd person singular behaves as if plural. + */ + if (!strcmpi(subj, "they") || !strcmpi(subj, "you")) + return strcpy(buf, verb); } - sing: +sing: Strcpy(buf, verb); - len = (int)strlen(buf); + len = (int) strlen(buf); bspot = buf + len - 1; if (!strcmpi(buf, "are")) { - Strcasecpy(buf, "is"); + Strcasecpy(buf, "is"); } else if (!strcmpi(buf, "have")) { - Strcasecpy(bspot-1, "s"); - } else if (index("zxs", lowc(*bspot)) || - (len >= 2 && lowc(*bspot) == 'h' && - index("cs", lowc(*(bspot-1)))) || - (len == 2 && lowc(*bspot) == 'o')) { - /* Ends in z, x, s, ch, sh; add an "es" */ - Strcasecpy(bspot+1, "es"); - } else if (lowc(*bspot) == 'y' && !index(vowels, lowc(*(bspot-1)))) { - /* like "y" case in makeplural */ - Strcasecpy(bspot, "ies"); + Strcasecpy(bspot - 1, "s"); + } else if (index("zxs", lowc(*bspot)) + || (len >= 2 && lowc(*bspot) == 'h' + && index("cs", lowc(*(bspot - 1)))) + || (len == 2 && lowc(*bspot) == 'o')) { + /* Ends in z, x, s, ch, sh; add an "es" */ + Strcasecpy(bspot + 1, "es"); + } else if (lowc(*bspot) == 'y' && !index(vowels, lowc(*(bspot - 1)))) { + /* like "y" case in makeplural */ + Strcasecpy(bspot, "ies"); } else { - Strcasecpy(bspot+1, "s"); + Strcasecpy(bspot + 1, "s"); } return buf; @@ -1723,20 +1765,21 @@ struct sing_plur { also some suffices which have very few--often one--matches or which aren't systematically reversible (knives, staves) */ static struct sing_plur one_off[] = { - { "child", "children" }, /* (for wise guys who give their food funny names) */ - { "cubus", "cubi" }, /* in-/suc-cubus */ - { "culus", "culi" }, /* homunculus */ + { "child", + "children" }, /* (for wise guys who give their food funny names) */ + { "cubus", "cubi" }, /* in-/suc-cubus */ + { "culus", "culi" }, /* homunculus */ { "djinni", "djinn" }, { "erinys", "erinyes" }, { "foot", "feet" }, { "fungus", "fungi" }, { "knife", "knives" }, - { "labrum", "labra" }, /* candelabrum */ + { "labrum", "labra" }, /* candelabrum */ { "louse", "lice" }, { "mouse", "mice" }, { "mumak", "mumakil" }, { "nemesis", "nemeses" }, - { "rtex", "rtices" }, /* vortex */ + { "rtex", "rtices" }, /* vortex */ { "tooth", "teeth" }, { "staff", "staves" }, { 0, 0 } @@ -1744,59 +1787,56 @@ static struct sing_plur one_off[] = { static const char *const as_is[] = { /* makesingular() leaves these plural due to how they're used */ - "boots", "shoes", - "gloves", "lenses", "scales", "eyes", - "gauntlets", - "iron bars", + "boots", "shoes", "gloves", "lenses", "scales", + "eyes", "gauntlets", "iron bars", /* both singular and plural are spelled the same */ - "deer", "fish", "tuna", "yaki", "-hai", - "krill", "manes", "ninja", "sheep", "ronin", "roshi", "shito", "tengu", - "ki-rin", "Nazgul", - "gunyoki", "piranha", "samurai", - "shuriken", - 0, + "deer", "fish", "tuna", "yaki", "-hai", + "krill", "manes", "ninja", "sheep", "ronin", + "roshi", "shito", "tengu", "ki-rin", "Nazgul", + "gunyoki", "piranha", "samurai", "shuriken", 0, /* Note: "fish" and "piranha" are collective plurals, suitable for "wiped out all ". For "3 ", they should be "fishes" and "piranhas" instead. We settle for collective variant instead of attempting to support both. */ }; -/* singularize/pluralize decisiions common to both makesingular & makeplural */ +/* singularize/pluralize decisiions common to both makesingular & makeplural + */ STATIC_OVL boolean singplur_lookup(basestr, endstring, to_plural, alt_as_is) -char *basestr, *endstring; /* base string, pointer to eos(string) */ -boolean to_plural; /* true => makeplural, false => makesingular */ -const char *const *alt_as_is; /* another set like as_is[] */ +char *basestr, *endstring; /* base string, pointer to eos(string) */ +boolean to_plural; /* true => makeplural, false => makesingular */ +const char *const *alt_as_is; /* another set like as_is[] */ { const struct sing_plur *sp; const char *same, *other, *const *as; int al; for (as = as_is; *as; ++as) { - al = (int)strlen(*as); + al = (int) strlen(*as); if (!BSTRCMPI(basestr, endstring - al, *as)) - return TRUE; + return TRUE; } if (alt_as_is) { for (as = alt_as_is; *as; ++as) { - al = (int)strlen(*as); - if (!BSTRCMPI(basestr, endstring - al, *as)) - return TRUE; + al = (int) strlen(*as); + if (!BSTRCMPI(basestr, endstring - al, *as)) + return TRUE; } } for (sp = one_off; sp->sing; sp++) { /* check whether endstring already matches */ same = to_plural ? sp->plur : sp->sing; - al = (int)strlen(same); + al = (int) strlen(same); if (!BSTRCMPI(basestr, endstring - al, same)) - return TRUE; /* use as-is */ + return TRUE; /* use as-is */ /* check whether it matches the inverse; if so, transform it */ other = to_plural ? sp->sing : sp->plur; - al = (int)strlen(other); + al = (int) strlen(other); if (!BSTRCMPI(basestr, endstring - al, other)) { - Strcasecpy(endstring - al, same); - return TRUE; /* one_off[] transformation */ + Strcasecpy(endstring - al, same); + return TRUE; /* one_off[] transformation */ } } return FALSE; @@ -1808,38 +1848,30 @@ singplur_compound(str) char *str; { /* if new entries are added, be sure to keep compound_start[] in sync */ - static const char *const compounds[] = { - " of ", - " labeled ", - " called ", - " named ", - " above", /* lurkers above */ - " versus ", - " from ", - " in ", - " on ", - " a la ", - " with", /* " with "? */ - " de ", - " d'", - " du ", - "-in-", - "-at-", - 0 - }, /* list of first characters for all compounds[] entries */ + static const char *const compounds[] = + { + " of ", " labeled ", " called ", + " named ", " above", /* lurkers above */ + " versus ", " from ", " in ", + " on ", " a la ", " with", /* " with "? */ + " de ", " d'", " du ", + "-in-", "-at-", 0 + }, /* list of first characters for all compounds[] entries */ compound_start[] = " -"; const char *const *cmpd; char *p; for (p = str; *p; ++p) { - /* substring starting at p can only match if *p is found - within compound_start[] */ - if (!index(compound_start, *p)) continue; + /* substring starting at p can only match if *p is found + within compound_start[] */ + if (!index(compound_start, *p)) + continue; - /* check current substring against all words in the compound[] list */ - for (cmpd = compounds; *cmpd; ++cmpd) - if (!strncmpi(p, *cmpd, (int)strlen(*cmpd))) return p; + /* check current substring against all words in the compound[] list */ + for (cmpd = compounds; *cmpd; ++cmpd) + if (!strncmpi(p, *cmpd, (int) strlen(*cmpd))) + return p; } /* wasn't recognized as a compound phrase */ return 0; @@ -1866,10 +1898,12 @@ const char *oldstr; { register char *spot; char lo_c, *str = nextobuf(); - const char *excess = (char *)0; + const char *excess = (char *) 0; int len; - if (oldstr) while (*oldstr == ' ') oldstr++; + if (oldstr) + while (*oldstr == ' ') + oldstr++; if (!oldstr || !*oldstr) { impossible("plural of null?"); Strcpy(str, "s"); @@ -1888,56 +1922,56 @@ const char *oldstr; /* look for "foo of bar" so that we can focus on "foo" */ if ((spot = singplur_compound(str)) != 0) { - excess = oldstr + (int)(spot - str); + excess = oldstr + (int) (spot - str); *spot = '\0'; } else spot = eos(str); spot--; - while (spot > str && *spot == ' ') spot--; /* Strip blanks from end */ - *(spot+1) = 0; + while (spot > str && *spot == ' ') + spot--; /* Strip blanks from end */ + *(spot + 1) = 0; /* Now spot is the last character of the string */ len = strlen(str); /* Single letters */ - if (len==1 || !letter(*spot)) { - Strcpy(spot+1, "'s"); + if (len == 1 || !letter(*spot)) { + Strcpy(spot + 1, "'s"); goto bottom; } /* dispense with some words which don't need pluralization */ { - static const char *const already_plural[] = { - "ae", /* algae, larvae, &c */ - "men", /* also catches women, watchmen */ - "matzot", - 0, - }; + static const char *const already_plural[] = { + "ae", /* algae, larvae, &c */ + "men", /* also catches women, watchmen */ + "matzot", 0, + }; - /* spot+1: synch up with makesingular's usage */ - if (singplur_lookup(str, spot + 1, TRUE, already_plural)) - goto bottom; + /* spot+1: synch up with makesingular's usage */ + if (singplur_lookup(str, spot + 1, TRUE, already_plural)) + goto bottom; - /* more of same, but not suitable for blanket loop checking */ - if ((len == 2 && !strcmpi(str, "ya")) || - (len >= 3 && !strcmpi(spot-2, " ya"))) - goto bottom; + /* more of same, but not suitable for blanket loop checking */ + if ((len == 2 && !strcmpi(str, "ya")) + || (len >= 3 && !strcmpi(spot - 2, " ya"))) + goto bottom; } /* man/men ("Wiped out all cavemen.") */ - if (len >= 3 && !strcmpi(spot-2, "man") && - /* exclude shamans and humans */ - (len < 6 || strcmpi(spot-5, "shaman")) && - (len < 5 || strcmpi(spot-4, "human"))) { - Strcasecpy(spot-1, "en"); + if (len >= 3 && !strcmpi(spot - 2, "man") && + /* exclude shamans and humans */ + (len < 6 || strcmpi(spot - 5, "shaman")) + && (len < 5 || strcmpi(spot - 4, "human"))) { + Strcasecpy(spot - 1, "en"); goto bottom; } if (lowc(*spot) == 'f') { /* (staff handled via one_off[]) */ - lo_c = lowc(*(spot-1)); - if (len >= 3 && !strcmpi(spot-2, "erf")) { + lo_c = lowc(*(spot - 1)); + if (len >= 3 && !strcmpi(spot - 2, "erf")) { /* avoid "nerf" -> "nerves", "serf" -> "serves" */ - ; /* fall through to default (append 's') */ + ; /* fall through to default (append 's') */ } else if (index("lr", lo_c) || index(vowels, lo_c)) { /* [aeioulr]f to [aeioulr]ves */ Strcasecpy(spot, "ves"); @@ -1945,41 +1979,41 @@ const char *oldstr; } } /* ium/ia (mycelia, baluchitheria) */ - if (len >= 3 && !strcmpi(spot-2, "ium")) { - Strcasecpy(spot-2, "ia"); + if (len >= 3 && !strcmpi(spot - 2, "ium")) { + Strcasecpy(spot - 2, "ia"); goto bottom; } /* algae, larvae, hyphae (another fungus part) */ - if ((len >= 4 && !strcmpi(spot-3, "alga")) || - (len >= 5 && (!strcmpi(spot-4, "hypha") || - !strcmpi(spot-4, "larva"))) || - (len >= 6 && !strcmpi(spot-5, "amoeba")) || - (len >= 8 && (!strcmpi(spot-7, "vertebra")))) { + if ((len >= 4 && !strcmpi(spot - 3, "alga")) + || (len >= 5 + && (!strcmpi(spot - 4, "hypha") || !strcmpi(spot - 4, "larva"))) + || (len >= 6 && !strcmpi(spot - 5, "amoeba")) + || (len >= 8 && (!strcmpi(spot - 7, "vertebra")))) { /* a to ae */ - Strcasecpy(spot+1, "e"); + Strcasecpy(spot + 1, "e"); goto bottom; } /* fungus/fungi, homunculus/homunculi, but buses, lotuses, wumpuses */ - if (len > 3 && !strcmpi(spot-1, "us") && - !((len >= 5 && !strcmpi(spot-4, "lotus")) || - (len >= 6 && !strcmpi(spot-5, "wumpus")))) { - Strcasecpy(spot-1, "i"); + if (len > 3 && !strcmpi(spot - 1, "us") + && !((len >= 5 && !strcmpi(spot - 4, "lotus")) + || (len >= 6 && !strcmpi(spot - 5, "wumpus")))) { + Strcasecpy(spot - 1, "i"); goto bottom; } /* sis/ses (nemesis) */ - if (len >= 3 && !strcmpi(spot-2, "sis")) { - Strcasecpy(spot-1, "es"); + if (len >= 3 && !strcmpi(spot - 2, "sis")) { + Strcasecpy(spot - 1, "es"); goto bottom; } /* matzoh/matzot, possible food name */ - if (len >= 6 && (!strcmpi(spot-5, "matzoh") || - !strcmpi(spot-5, "matzah"))) { - Strcasecpy(spot-1, "ot"); /* oh/ah -> ot */ + if (len >= 6 + && (!strcmpi(spot - 5, "matzoh") || !strcmpi(spot - 5, "matzah"))) { + Strcasecpy(spot - 1, "ot"); /* oh/ah -> ot */ goto bottom; } - if (len >= 5 && (!strcmpi(spot-4, "matzo") || - !strcmpi(spot-4, "matza"))) { - Strcasecpy(spot, "ot"); /* o/a -> ot */ + if (len >= 5 + && (!strcmpi(spot - 4, "matzo") || !strcmpi(spot - 4, "matza"))) { + Strcasecpy(spot, "ot"); /* o/a -> ot */ goto bottom; } @@ -1989,25 +2023,25 @@ const char *oldstr; lo_c = lowc(*spot); /* Ends in z, x, s, ch, sh; add an "es" */ - if (index("zxs", lo_c) || - (len >= 2 && lo_c == 'h' && index("cs", lowc(*(spot-1)))) || - /* Kludge to get "tomatoes" and "potatoes" right */ - (len >= 4 && !strcmpi(spot-2, "ato")) || - (len >= 5 && !strcmpi(spot-4, "dingo"))) { - Strcasecpy(spot+1, "es"); /* append es */ + if (index("zxs", lo_c) + || (len >= 2 && lo_c == 'h' && index("cs", lowc(*(spot - 1)))) || + /* Kludge to get "tomatoes" and "potatoes" right */ + (len >= 4 && !strcmpi(spot - 2, "ato")) + || (len >= 5 && !strcmpi(spot - 4, "dingo"))) { + Strcasecpy(spot + 1, "es"); /* append es */ goto bottom; } /* Ends in y preceded by consonant (note: also "qu") change to "ies" */ - if (lo_c == 'y' && - !index(vowels, lowc(*(spot-1)))) { - Strcasecpy(spot, "ies"); /* y -> ies */ + if (lo_c == 'y' && !index(vowels, lowc(*(spot - 1)))) { + Strcasecpy(spot, "ies"); /* y -> ies */ goto bottom; } /* Default: append an 's' */ - Strcasecpy(spot+1, "s"); + Strcasecpy(spot + 1, "s"); - bottom: - if (excess) Strcat(str, excess); +bottom: + if (excess) + Strcat(str, excess); return str; } @@ -2031,7 +2065,9 @@ const char *oldstr; const char *excess = 0; char *str = nextobuf(); - if (oldstr) while (*oldstr == ' ') oldstr++; + if (oldstr) + while (*oldstr == ' ') + oldstr++; if (!oldstr || !*oldstr) { impossible("singular of null?"); str[0] = '\0'; @@ -2042,7 +2078,7 @@ const char *oldstr; /* check for "foo of bar" so that we can focus on "foo" */ if ((p = singplur_compound(bp)) != 0) { - excess = oldstr + (int)(p - bp); + excess = oldstr + (int) (p - bp); *p = '\0'; } else p = eos(bp); @@ -2052,78 +2088,78 @@ const char *oldstr; goto bottom; /* remove -s or -es (boxes) or -ies (rubies) */ - if (p >= bp+1 && lowc(p[-1]) == 's') { - if (p >= bp+2 && lowc(p[-2]) == 'e') { - if (p >= bp+3 && lowc(p[-3]) == 'i') { /* "ies" */ - if (!BSTRCMPI(bp, p-7, "cookies") || - !BSTRCMPI(bp, p-4, "pies") || - !BSTRCMPI(bp, p-5, "mbies") || /* zombie */ - !BSTRCMPI(bp, p-5, "yries")) /* valkyrie */ + if (p >= bp + 1 && lowc(p[-1]) == 's') { + if (p >= bp + 2 && lowc(p[-2]) == 'e') { + if (p >= bp + 3 && lowc(p[-3]) == 'i') { /* "ies" */ + if (!BSTRCMPI(bp, p - 7, "cookies") + || !BSTRCMPI(bp, p - 4, "pies") + || !BSTRCMPI(bp, p - 5, "mbies") || /* zombie */ + !BSTRCMPI(bp, p - 5, "yries")) /* valkyrie */ goto mins; - Strcasecpy(p-3, "y"); /* ies -> y */ + Strcasecpy(p - 3, "y"); /* ies -> y */ goto bottom; } /* wolves, but f to ves isn't fully reversible */ - if (p-4 >= bp && (index("lr", lowc(*(p-4))) || - index(vowels, lowc(*(p-4)))) && - !BSTRCMPI(bp, p-3, "ves")) { - if (!BSTRCMPI(bp, p-6, "cloves") || - !BSTRCMPI(bp, p-6, "nerves")) goto mins; - Strcasecpy(p-3, "f"); /* ves -> f */ + if (p - 4 >= bp && (index("lr", lowc(*(p - 4))) + || index(vowels, lowc(*(p - 4)))) + && !BSTRCMPI(bp, p - 3, "ves")) { + if (!BSTRCMPI(bp, p - 6, "cloves") + || !BSTRCMPI(bp, p - 6, "nerves")) + goto mins; + Strcasecpy(p - 3, "f"); /* ves -> f */ goto bottom; } /* note: nurses, axes but boxes, wumpuses */ - if (!BSTRCMPI(bp, p-4, "eses") || - !BSTRCMPI(bp, p-4, "oxes") || /* boxes, foxes */ - !BSTRCMPI(bp, p-4, "nxes") || /* lynxes */ - !BSTRCMPI(bp, p-4, "ches") || - !BSTRCMPI(bp, p-4, "uses") || /* lotuses */ - !BSTRCMPI(bp, p-4, "sses") || /* priestesses */ - !BSTRCMPI(bp, p-5, "atoes") || /* tomatoes */ - !BSTRCMPI(bp, p-7, "dingoes") || - !BSTRCMPI(bp, p-7, "Aleaxes")) { - *(p-2) = '\0'; /* drop es */ + if (!BSTRCMPI(bp, p - 4, "eses") || !BSTRCMPI(bp, p - 4, "oxes") + || /* boxes, foxes */ + !BSTRCMPI(bp, p - 4, "nxes") || /* lynxes */ + !BSTRCMPI(bp, p - 4, "ches") || !BSTRCMPI(bp, p - 4, "uses") + || /* lotuses */ + !BSTRCMPI(bp, p - 4, "sses") || /* priestesses */ + !BSTRCMPI(bp, p - 5, "atoes") || /* tomatoes */ + !BSTRCMPI(bp, p - 7, "dingoes") + || !BSTRCMPI(bp, p - 7, "Aleaxes")) { + *(p - 2) = '\0'; /* drop es */ goto bottom; } /* else fall through to mins */ - /* ends in 's' but not 'es' */ - } else if (!BSTRCMPI(bp, p-2, "us")) { /* lotus, fungus... */ - if (BSTRCMPI(bp, p-6, "tengus") && /* but not these... */ - BSTRCMPI(bp, p-7, "hezrous")) - goto bottom; - } else if (!BSTRCMPI(bp, p-2, "ss") || - !BSTRCMPI(bp, p-5, " lens") || - (p-4 == bp && !strcmpi(p-4, "lens"))) { + /* ends in 's' but not 'es' */ + } else if (!BSTRCMPI(bp, p - 2, "us")) { /* lotus, fungus... */ + if (BSTRCMPI(bp, p - 6, "tengus") && /* but not these... */ + BSTRCMPI(bp, p - 7, "hezrous")) goto bottom; + } else if (!BSTRCMPI(bp, p - 2, "ss") || !BSTRCMPI(bp, p - 5, " lens") + || (p - 4 == bp && !strcmpi(p - 4, "lens"))) { + goto bottom; } mins: - *(p-1) = '\0'; /* drop s */ + *(p - 1) = '\0'; /* drop s */ - } else { /* input doesn't end in 's' */ + } else { /* input doesn't end in 's' */ - if (!BSTRCMPI(bp, p-3, "men")) { - Strcasecpy(p-2, "an"); + if (!BSTRCMPI(bp, p - 3, "men")) { + Strcasecpy(p - 2, "an"); goto bottom; } /* matzot -> matzo, algae -> alga */ - if (!BSTRCMPI(bp, p-6, "matzot") || - !BSTRCMPI(bp, p-2, "ae")) { - *(p-1) = '\0'; /* drop t/e */ + if (!BSTRCMPI(bp, p - 6, "matzot") || !BSTRCMPI(bp, p - 2, "ae")) { + *(p - 1) = '\0'; /* drop t/e */ goto bottom; } /* balactheria -> balactherium */ - if (p-4 >= bp && !strcmpi(p-2, "ia") && - index("lr", lowc(*(p-3))) && lowc(*(p-4)) == 'e') { - Strcasecpy(p-1, "um"); /* a -> um */ + if (p - 4 >= bp && !strcmpi(p - 2, "ia") + && index("lr", lowc(*(p - 3))) && lowc(*(p - 4)) == 'e') { + Strcasecpy(p - 1, "um"); /* a -> um */ } /* here we cannot find the plural suffix */ } - bottom: +bottom: /* if we stripped off a suffix (" of bar" from "foo of bar"), put it back now [strcat() isn't actually 100% safe here...] */ - if (excess) Strcat(bp, excess); + if (excess) + Strcat(bp, excess); return bp; } @@ -2131,16 +2167,17 @@ const char *oldstr; /* compare user string against object name string using fuzzy matching */ STATIC_OVL boolean wishymatch(u_str, o_str, retry_inverted) -const char *u_str; /* from user, so might be variant spelling */ -const char *o_str; /* from objects[], so is in canonical form */ -boolean retry_inverted; /* optional extra "of" handling */ +const char *u_str; /* from user, so might be variant spelling */ +const char *o_str; /* from objects[], so is in canonical form */ +boolean retry_inverted; /* optional extra "of" handling */ { - static NEARDATA const char - detect_SP[] = "detect ", SP_detection[] = " detection"; + static NEARDATA const char detect_SP[] = "detect ", + SP_detection[] = " detection"; char *p, buf[BUFSZ]; /* ignore spaces & hyphens and upper/lower case when comparing */ - if (fuzzymatch(u_str, o_str, " -", TRUE)) return TRUE; + if (fuzzymatch(u_str, o_str, " -", TRUE)) + return TRUE; if (retry_inverted) { const char *u_of, *o_of; @@ -2150,17 +2187,19 @@ boolean retry_inverted; /* optional extra "of" handling */ u_of = strstri(u_str, " of "); o_of = strstri(o_str, " of "); if (u_of && !o_of) { - Strcpy(buf, u_of + 4); - p = eos(strcat(buf, " ")); - while (u_str < u_of) *p++ = *u_str++; - *p = '\0'; - return fuzzymatch(buf, o_str, " -", TRUE); + Strcpy(buf, u_of + 4); + p = eos(strcat(buf, " ")); + while (u_str < u_of) + *p++ = *u_str++; + *p = '\0'; + return fuzzymatch(buf, o_str, " -", TRUE); } else if (o_of && !u_of) { - Strcpy(buf, o_of + 4); - p = eos(strcat(buf, " ")); - while (o_str < o_of) *p++ = *o_str++; - *p = '\0'; - return fuzzymatch(u_str, buf, " -", TRUE); + Strcpy(buf, o_of + 4); + p = eos(strcat(buf, " ")); + while (o_str < o_of) + *p++ = *o_str++; + *p = '\0'; + return fuzzymatch(u_str, buf, " -", TRUE); } } @@ -2169,50 +2208,51 @@ boolean retry_inverted; /* optional extra "of" handling */ order to get the "of" inversion handling] */ if (!strncmp(o_str, "dwarvish ", 9)) { if (!strncmpi(u_str, "dwarven ", 8)) - return fuzzymatch(u_str + 8, o_str + 9, " -", TRUE); + return fuzzymatch(u_str + 8, o_str + 9, " -", TRUE); } else if (!strncmp(o_str, "elven ", 6)) { if (!strncmpi(u_str, "elvish ", 7)) - return fuzzymatch(u_str + 7, o_str + 6, " -", TRUE); + return fuzzymatch(u_str + 7, o_str + 6, " -", TRUE); else if (!strncmpi(u_str, "elfin ", 6)) - return fuzzymatch(u_str + 6, o_str + 6, " -", TRUE); + return fuzzymatch(u_str + 6, o_str + 6, " -", TRUE); } else if (!strncmp(o_str, detect_SP, sizeof detect_SP - 1)) { /* check for "detect " vs " detection" */ - if ((p = strstri(u_str, SP_detection)) != 0 && - !*(p + sizeof SP_detection - 1)) { - /* convert " detection" into "detect " */ - *p = '\0'; - Strcat(strcpy(buf, detect_SP), u_str); - /* "detect monster" -> "detect monsters" */ - if (!strcmpi(u_str, "monster")) Strcat(buf, "s"); - *p = ' '; - return fuzzymatch(buf, o_str, " -", TRUE); + if ((p = strstri(u_str, SP_detection)) != 0 + && !*(p + sizeof SP_detection - 1)) { + /* convert " detection" into "detect " */ + *p = '\0'; + Strcat(strcpy(buf, detect_SP), u_str); + /* "detect monster" -> "detect monsters" */ + if (!strcmpi(u_str, "monster")) + Strcat(buf, "s"); + *p = ' '; + return fuzzymatch(buf, o_str, " -", TRUE); } } else if (strstri(o_str, SP_detection)) { /* and the inverse, " detection" vs "detect " */ if (!strncmpi(u_str, detect_SP, sizeof detect_SP - 1)) { - /* convert "detect s" into " detection" */ - p = makesingular(u_str + sizeof detect_SP - 1); - Strcat(strcpy(buf, p), SP_detection); - /* caller may be looping through objects[], so avoid - churning through all the obufs */ - releaseobuf(p); - return fuzzymatch(buf, o_str, " -", TRUE); + /* convert "detect s" into " detection" */ + p = makesingular(u_str + sizeof detect_SP - 1); + Strcat(strcpy(buf, p), SP_detection); + /* caller may be looping through objects[], so avoid + churning through all the obufs */ + releaseobuf(p); + return fuzzymatch(buf, o_str, " -", TRUE); } } else if (strstri(o_str, "ability")) { /* when presented with "foo of bar", make singular() used to singularize both foo & bar, but now only does so for foo */ /* catch "{potion(s),ring} of {gain,restore,sustain} abilities" */ - if ((p = strstri(u_str, "abilities")) != 0 && - !*(p + sizeof "abilities" - 1)) { - (void)strncpy(buf, u_str, (unsigned)(p - u_str)); - Strcpy(buf + (p - u_str), "ability"); - return fuzzymatch(buf, o_str, " -", TRUE); + if ((p = strstri(u_str, "abilities")) != 0 + && !*(p + sizeof "abilities" - 1)) { + (void) strncpy(buf, u_str, (unsigned) (p - u_str)); + Strcpy(buf + (p - u_str), "ability"); + return fuzzymatch(buf, o_str, " -", TRUE); } } else if (!strcmp(o_str, "aluminum")) { /* this special case doesn't really fit anywhere else... */ /* (note that " wand" will have been stripped off by now) */ if (!strcmpi(u_str, "aluminium")) - return fuzzymatch(u_str + 9, o_str + 8, " -", TRUE); + return fuzzymatch(u_str + 9, o_str + 8, " -", TRUE); } return FALSE; @@ -2220,32 +2260,32 @@ boolean retry_inverted; /* optional extra "of" handling */ struct o_range { const char *name, oclass; - int f_o_range, l_o_range; + int f_o_range, l_o_range; }; /* wishable subranges of objects */ STATIC_OVL NEARDATA const struct o_range o_ranges[] = { - { "bag", TOOL_CLASS, SACK, BAG_OF_TRICKS }, - { "lamp", TOOL_CLASS, OIL_LAMP, MAGIC_LAMP }, - { "candle", TOOL_CLASS, TALLOW_CANDLE, WAX_CANDLE }, - { "horn", TOOL_CLASS, TOOLED_HORN, HORN_OF_PLENTY }, - { "shield", ARMOR_CLASS, SMALL_SHIELD, SHIELD_OF_REFLECTION }, - { "hat", ARMOR_CLASS, FEDORA, DUNCE_CAP }, - { "helm", ARMOR_CLASS, ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY }, - { "gloves", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY }, - { "gauntlets", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY }, - { "boots", ARMOR_CLASS, LOW_BOOTS, LEVITATION_BOOTS }, - { "shoes", ARMOR_CLASS, LOW_BOOTS, IRON_SHOES }, - { "cloak", ARMOR_CLASS, MUMMY_WRAPPING, CLOAK_OF_DISPLACEMENT }, - { "shirt", ARMOR_CLASS, HAWAIIAN_SHIRT, T_SHIRT }, - { "dragon scales", - ARMOR_CLASS, GRAY_DRAGON_SCALES, YELLOW_DRAGON_SCALES }, - { "dragon scale mail", - ARMOR_CLASS, GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL }, - { "sword", WEAPON_CLASS, SHORT_SWORD, KATANA }, - { "venom", VENOM_CLASS, BLINDING_VENOM, ACID_VENOM }, - { "gray stone", GEM_CLASS, LUCKSTONE, FLINT }, - { "grey stone", GEM_CLASS, LUCKSTONE, FLINT }, + { "bag", TOOL_CLASS, SACK, BAG_OF_TRICKS }, + { "lamp", TOOL_CLASS, OIL_LAMP, MAGIC_LAMP }, + { "candle", TOOL_CLASS, TALLOW_CANDLE, WAX_CANDLE }, + { "horn", TOOL_CLASS, TOOLED_HORN, HORN_OF_PLENTY }, + { "shield", ARMOR_CLASS, SMALL_SHIELD, SHIELD_OF_REFLECTION }, + { "hat", ARMOR_CLASS, FEDORA, DUNCE_CAP }, + { "helm", ARMOR_CLASS, ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY }, + { "gloves", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY }, + { "gauntlets", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY }, + { "boots", ARMOR_CLASS, LOW_BOOTS, LEVITATION_BOOTS }, + { "shoes", ARMOR_CLASS, LOW_BOOTS, IRON_SHOES }, + { "cloak", ARMOR_CLASS, MUMMY_WRAPPING, CLOAK_OF_DISPLACEMENT }, + { "shirt", ARMOR_CLASS, HAWAIIAN_SHIRT, T_SHIRT }, + { "dragon scales", ARMOR_CLASS, GRAY_DRAGON_SCALES, + YELLOW_DRAGON_SCALES }, + { "dragon scale mail", ARMOR_CLASS, GRAY_DRAGON_SCALE_MAIL, + YELLOW_DRAGON_SCALE_MAIL }, + { "sword", WEAPON_CLASS, SHORT_SWORD, KATANA }, + { "venom", VENOM_CLASS, BLINDING_VENOM, ACID_VENOM }, + { "gray stone", GEM_CLASS, LUCKSTONE, FLINT }, + { "grey stone", GEM_CLASS, LUCKSTONE, FLINT }, }; /* alternate spellings; if the difference is only the presence or @@ -2279,30 +2319,32 @@ struct alt_spellings { { "grappling iron", GRAPPLING_HOOK }, { "grapnel", GRAPPLING_HOOK }, { "grapple", GRAPPLING_HOOK }, - { (const char *)0, 0 }, + { (const char *) 0, 0 }, }; short rnd_otyp_by_wpnskill(skill) schar skill; { - int i,n = 0; + int i, n = 0; short otyp; - for (i = bases[WEAPON_CLASS]; i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) - if (objects[i].oc_skill == skill) { - n++; - otyp = i; - } + for (i = bases[WEAPON_CLASS]; + i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) + if (objects[i].oc_skill == skill) { + n++; + otyp = i; + } if (n > 0) { - n = rn2(n); - for (i = bases[WEAPON_CLASS]; i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) - if (objects[i].oc_skill == skill) - if (--n < 0) return i; + n = rn2(n); + for (i = bases[WEAPON_CLASS]; + i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) + if (objects[i].oc_skill == skill) + if (--n < 0) + return i; } return STRANGE_OBJECT; } - /* * Return something wished for. Specifying a null pointer for * the user request string results in a random object. Otherwise, @@ -2344,13 +2386,11 @@ struct obj *no_wish; char oclass; char *un, *dn, *actualn; - const char *name=0; + const char *name = 0; - cnt = spe = spesgn = typ = very = rechrg = - blessed = uncursed = iscursed = - ispoisoned = isgreased = eroded = eroded2 = erodeproof = - halfeaten = islit = unlabeled = ishistoric = isdiluted = - trapped = 0; + cnt = spe = spesgn = typ = very = rechrg = blessed = uncursed = iscursed = + ispoisoned = isgreased = eroded = eroded2 = erodeproof = halfeaten = + islit = unlabeled = ishistoric = isdiluted = trapped = 0; tvariety = RANDOM_TIN; mntmp = NON_PM; #define UNDEFINED 0 @@ -2360,138 +2400,155 @@ struct obj *no_wish; oclass = 0; actualn = dn = un = 0; - if (!bp) goto any; + if (!bp) + goto any; /* first, remove extra whitespace they may have typed */ - (void)mungspaces(bp); + (void) mungspaces(bp); /* allow wishing for "nothing" to preserve wishless conduct... [now requires "wand of nothing" if that's what was really wanted] */ - if (!strcmpi(bp, "nothing") || !strcmpi(bp, "nil") || - !strcmpi(bp, "none")) return no_wish; + if (!strcmpi(bp, "nothing") || !strcmpi(bp, "nil") + || !strcmpi(bp, "none")) + return no_wish; /* save the [nearly] unmodified choice string */ Strcpy(fruitbuf, bp); - for(;;) { + for (;;) { register int l; - if (!bp || !*bp) goto any; - if (!strncmpi(bp, "an ", l=3) || - !strncmpi(bp, "a ", l=2)) { + if (!bp || !*bp) + goto any; + if (!strncmpi(bp, "an ", l = 3) || !strncmpi(bp, "a ", l = 2)) { cnt = 1; - } else if (!strncmpi(bp, "the ", l=4)) { - ; /* just increment `bp' by `l' below */ + } else if (!strncmpi(bp, "the ", l = 4)) { + ; /* just increment `bp' by `l' below */ } else if (!cnt && digit(*bp) && strcmp(bp, "0")) { cnt = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + while (digit(*bp)) + bp++; + while (*bp == ' ') + bp++; l = 0; } else if (*bp == '+' || *bp == '-') { spesgn = (*bp++ == '+') ? 1 : -1; spe = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + while (digit(*bp)) + bp++; + while (*bp == ' ') + bp++; l = 0; - } else if (!strncmpi(bp, "blessed ", l=8) || - !strncmpi(bp, "holy ", l=5)) { + } else if (!strncmpi(bp, "blessed ", l = 8) + || !strncmpi(bp, "holy ", l = 5)) { blessed = 1; - } else if (!strncmpi(bp, "cursed ", l=7) || - !strncmpi(bp, "unholy ", l=7)) { + } else if (!strncmpi(bp, "cursed ", l = 7) + || !strncmpi(bp, "unholy ", l = 7)) { iscursed = 1; - } else if (!strncmpi(bp, "uncursed ", l=9)) { + } else if (!strncmpi(bp, "uncursed ", l = 9)) { uncursed = 1; - } else if (!strncmpi(bp, "rustproof ", l=10) || - !strncmpi(bp, "erodeproof ", l=11) || - !strncmpi(bp, "corrodeproof ", l=13) || - !strncmpi(bp, "fixed ", l=6) || - !strncmpi(bp, "fireproof ", l=10) || - !strncmpi(bp, "rotproof ", l=9)) { + } else if (!strncmpi(bp, "rustproof ", l = 10) + || !strncmpi(bp, "erodeproof ", l = 11) + || !strncmpi(bp, "corrodeproof ", l = 13) + || !strncmpi(bp, "fixed ", l = 6) + || !strncmpi(bp, "fireproof ", l = 10) + || !strncmpi(bp, "rotproof ", l = 9)) { erodeproof = 1; - } else if (!strncmpi(bp,"lit ", l=4) || - !strncmpi(bp,"burning ", l=8)) { + } else if (!strncmpi(bp, "lit ", l = 4) + || !strncmpi(bp, "burning ", l = 8)) { islit = 1; - } else if (!strncmpi(bp,"unlit ", l=6) || - !strncmpi(bp,"extinguished ", l=13)) { + } else if (!strncmpi(bp, "unlit ", l = 6) + || !strncmpi(bp, "extinguished ", l = 13)) { islit = 0; - /* "unlabeled" and "blank" are synonymous */ - } else if (!strncmpi(bp,"unlabeled ", l=10) || - !strncmpi(bp,"unlabelled ", l=11) || - !strncmpi(bp,"blank ", l=6)) { + /* "unlabeled" and "blank" are synonymous */ + } else if (!strncmpi(bp, "unlabeled ", l = 10) + || !strncmpi(bp, "unlabelled ", l = 11) + || !strncmpi(bp, "blank ", l = 6)) { unlabeled = 1; - } else if(!strncmpi(bp, "poisoned ",l=9)) { - ispoisoned=1; - /* "trapped" recognized but not honored outside wizard mode */ - } else if(!strncmpi(bp, "trapped ",l=8)) { - trapped = 0; /* undo any previous "untrapped" */ - if (wizard) trapped = 1; - } else if(!strncmpi(bp, "untrapped ",l=10)) { - trapped = 2; /* not trapped */ - } else if(!strncmpi(bp, "greased ",l=8)) { - isgreased=1; - } else if (!strncmpi(bp, "very ", l=5)) { + } else if (!strncmpi(bp, "poisoned ", l = 9)) { + ispoisoned = 1; + /* "trapped" recognized but not honored outside wizard mode */ + } else if (!strncmpi(bp, "trapped ", l = 8)) { + trapped = 0; /* undo any previous "untrapped" */ + if (wizard) + trapped = 1; + } else if (!strncmpi(bp, "untrapped ", l = 10)) { + trapped = 2; /* not trapped */ + } else if (!strncmpi(bp, "greased ", l = 8)) { + isgreased = 1; + } else if (!strncmpi(bp, "very ", l = 5)) { /* very rusted very heavy iron ball */ very = 1; - } else if (!strncmpi(bp, "thoroughly ", l=11)) { + } else if (!strncmpi(bp, "thoroughly ", l = 11)) { very = 2; - } else if (!strncmpi(bp, "rusty ", l=6) || - !strncmpi(bp, "rusted ", l=7) || - !strncmpi(bp, "burnt ", l=6) || - !strncmpi(bp, "burned ", l=7)) { + } else if (!strncmpi(bp, "rusty ", l = 6) + || !strncmpi(bp, "rusted ", l = 7) + || !strncmpi(bp, "burnt ", l = 6) + || !strncmpi(bp, "burned ", l = 7)) { eroded = 1 + very; very = 0; - } else if (!strncmpi(bp, "corroded ", l=9) || - !strncmpi(bp, "rotted ", l=7)) { + } else if (!strncmpi(bp, "corroded ", l = 9) + || !strncmpi(bp, "rotted ", l = 7)) { eroded2 = 1 + very; very = 0; - } else if (!strncmpi(bp, "partly eaten ", l=13) || - !strncmpi(bp, "partially eaten ", l=16)) { + } else if (!strncmpi(bp, "partly eaten ", l = 13) + || !strncmpi(bp, "partially eaten ", l = 16)) { halfeaten = 1; - } else if (!strncmpi(bp, "historic ", l=9)) { + } else if (!strncmpi(bp, "historic ", l = 9)) { ishistoric = 1; - } else if (!strncmpi(bp, "diluted ", l=8)) { + } else if (!strncmpi(bp, "diluted ", l = 8)) { isdiluted = 1; - } else if(!strncmpi(bp, "empty ", l=6)) { + } else if (!strncmpi(bp, "empty ", l = 6)) { contents = EMPTY; - } else break; + } else + break; bp += l; } - if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */ + if (!cnt) + cnt = 1; /* %% what with "gems" etc. ? */ if (strlen(bp) > 1) { if ((p = rindex(bp, '(')) != 0) { - if (p > bp && p[-1] == ' ') p[-1] = 0; - else *p = 0; - p++; - if (!strcmpi(p, "lit)")) { - islit = 1; - } else { - spe = atoi(p); - while (digit(*p)) p++; - if (*p == ':') { + if (p > bp && p[-1] == ' ') + p[-1] = 0; + else + *p = 0; p++; - rechrg = spe; - spe = atoi(p); - while (digit(*p)) p++; - } - if (*p != ')') { - spe = rechrg = 0; + if (!strcmpi(p, "lit)")) { + islit = 1; } else { - spesgn = 1; - p++; - if (*p) Strcat(bp, p); + spe = atoi(p); + while (digit(*p)) + p++; + if (*p == ':') { + p++; + rechrg = spe; + spe = atoi(p); + while (digit(*p)) + p++; + } + if (*p != ')') { + spe = rechrg = 0; + } else { + spesgn = 1; + p++; + if (*p) + Strcat(bp, p); + } } } - } } -/* - otmp->spe is type schar; so we don't want spe to be any bigger or smaller. - also, spe should always be positive -- some cheaters may try to confuse - atoi() -*/ + /* + otmp->spe is type schar; so we don't want spe to be any bigger or + smaller. + also, spe should always be positive -- some cheaters may try to + confuse + atoi() + */ if (spe < 0) { - spesgn = -1; /* cheaters get what they deserve */ + spesgn = -1; /* cheaters get what they deserve */ spe = abs(spe); } if (spe > SCHAR_LIM) spe = SCHAR_LIM; - if (rechrg < 0 || rechrg > 7) rechrg = 7; /* recharge_limit */ + if (rechrg < 0 || rechrg > 7) + rechrg = 7; /* recharge_limit */ /* now we have the actual name, as delivered by xname, say green potions called whisky @@ -2504,26 +2561,26 @@ struct obj *no_wish; */ if ((p = strstri(bp, " named ")) != 0) { *p = 0; - name = p+7; + name = p + 7; } if ((p = strstri(bp, " called ")) != 0) { *p = 0; - un = p+8; + un = p + 8; /* "helmet called telepathy" is not "helmet" (a specific type) * "shield called reflection" is not "shield" (a general type) */ - for(i = 0; i < SIZE(o_ranges); i++) - if(!strcmpi(bp, o_ranges[i].name)) { - oclass = o_ranges[i].oclass; - goto srch; + for (i = 0; i < SIZE(o_ranges); i++) + if (!strcmpi(bp, o_ranges[i].name)) { + oclass = o_ranges[i].oclass; + goto srch; } } if ((p = strstri(bp, " labeled ")) != 0) { *p = 0; - dn = p+9; + dn = p + 9; } else if ((p = strstri(bp, " labelled ")) != 0) { *p = 0; - dn = p+10; + dn = p + 10; } if ((p = strstri(bp, " of spinach")) != 0) { *p = 0; @@ -2543,30 +2600,30 @@ struct obj *no_wish; -- boots, gloves, and lenses -- are also not mergable, so cnt is ignored anyway. */ - if(!strncmpi(bp, "pair of ",8)) { + if (!strncmpi(bp, "pair of ", 8)) { bp += 8; cnt *= 2; - } else if(cnt > 1 && !strncmpi(bp, "pairs of ",9)) { + } else if (cnt > 1 && !strncmpi(bp, "pairs of ", 9)) { bp += 9; cnt *= 2; - } else if (!strncmpi(bp, "set of ",7)) { + } else if (!strncmpi(bp, "set of ", 7)) { bp += 7; - } else if (!strncmpi(bp, "sets of ",8)) { + } else if (!strncmpi(bp, "sets of ", 8)) { bp += 8; } /* intercept pudding globs here; they're a valid wish target, * but we need them to not get treated like a corpse. - * - * also don't let player wish for multiple globs. + * + * also don't let player wish for multiple globs. */ - if ((p = strstri(bp, "glob of ")) != 0 - || (p = strstri(bp, "globs of ")) != 0) { - int globoffset = (*(p+4) == 's') ? 9 : 8; + if ((p = strstri(bp, "glob of ")) != 0 + || (p = strstri(bp, "globs of ")) != 0) { + int globoffset = (*(p + 4) == 's') ? 9 : 8; if ((mntmp = name_to_mon(p + globoffset)) >= PM_GRAY_OOZE - && mntmp <= PM_BLACK_PUDDING) { - mntmp = NON_PM; /* lie to ourselves */ - cnt = 0; /* force only one */ + && mntmp <= PM_BLACK_PUDDING) { + mntmp = NON_PM; /* lie to ourselves */ + cnt = 0; /* force only one */ } } else { /* @@ -2574,93 +2631,104 @@ struct obj *no_wish; * Don't check if it's a wand or spellbook. * (avoid "wand/finger of death" confusion). */ - if (!strstri(bp, "wand ") - && !strstri(bp, "spellbook ") + if (!strstri(bp, "wand ") && !strstri(bp, "spellbook ") && !strstri(bp, "finger ")) { - if (((p = strstri(bp, "tin of ")) != 0) && - (tmp = tin_variety_txt(p + 7, &tinv)) && - (mntmp = name_to_mon(p + 7 + tmp)) >= LOW_PM) { + if (((p = strstri(bp, "tin of ")) != 0) + && (tmp = tin_variety_txt(p + 7, &tinv)) + && (mntmp = name_to_mon(p + 7 + tmp)) >= LOW_PM) { *(p + 3) = 0; tvariety = tinv; } else if ((p = strstri(bp, " of ")) != 0 && (mntmp = name_to_mon(p + 4)) >= LOW_PM) - *p = 0; + *p = 0; } } /* Find corpse type w/o "of" (red dragon scale mail, yeti corpse) */ - if (strncmpi(bp, "samurai sword", 13)) /* not the "samurai" monster! */ - if (strncmpi(bp, "wizard lock", 11)) /* not the "wizard" monster! */ - if (strncmpi(bp, "ninja-to", 8)) /* not the "ninja" rank */ - if (strncmpi(bp, "master key", 10)) /* not the "master" rank */ - if (strncmpi(bp, "magenta", 7)) /* not the "mage" rank */ - if (mntmp < LOW_PM && strlen(bp) > 2 && - (mntmp = name_to_mon(bp)) >= LOW_PM) { - int mntmptoo, mntmplen; /* double check for rank title */ - char *obp = bp; - mntmptoo = title_to_mon(bp, (int *)0, &mntmplen); - bp += mntmp != mntmptoo ? (int)strlen(mons[mntmp].mname) : mntmplen; - if (*bp == ' ') bp++; - else if (!strncmpi(bp, "s ", 2)) bp += 2; - else if (!strncmpi(bp, "es ", 3)) bp += 3; - else if (!*bp && !actualn && !dn && !un && !oclass) { - /* no referent; they don't really mean a monster type */ - bp = obp; - mntmp = NON_PM; - } - } + if (strncmpi(bp, "samurai sword", 13)) /* not the "samurai" monster! */ + if (strncmpi(bp, "wizard lock", 11)) /* not the "wizard" monster! */ + if (strncmpi(bp, "ninja-to", 8)) /* not the "ninja" rank */ + if (strncmpi(bp, "master key", + 10)) /* not the "master" rank */ + if (strncmpi(bp, "magenta", 7)) /* not the "mage" rank */ + if (mntmp < LOW_PM && strlen(bp) > 2 + && (mntmp = name_to_mon(bp)) >= LOW_PM) { + int mntmptoo, + mntmplen; /* double check for rank title */ + char *obp = bp; + mntmptoo = title_to_mon(bp, (int *) 0, &mntmplen); + bp += mntmp != mntmptoo + ? (int) strlen(mons[mntmp].mname) + : mntmplen; + if (*bp == ' ') + bp++; + else if (!strncmpi(bp, "s ", 2)) + bp += 2; + else if (!strncmpi(bp, "es ", 3)) + bp += 3; + else if (!*bp && !actualn && !dn && !un + && !oclass) { + /* no referent; they don't really mean a + * monster type */ + bp = obp; + mntmp = NON_PM; + } + } /* first change to singular if necessary */ if (*bp) { char *sng = makesingular(bp); if (strcmp(bp, sng)) { - if (cnt == 1) cnt = 2; + if (cnt == 1) + cnt = 2; Strcpy(bp, sng); } } /* Alternate spellings (pick-ax, silver sabre, &c) */ { - struct alt_spellings *as = spellings; + struct alt_spellings *as = spellings; - while (as->sp) { - if (fuzzymatch(bp, as->sp, " -", TRUE)) { - typ = as->ob; - goto typfnd; + while (as->sp) { + if (fuzzymatch(bp, as->sp, " -", TRUE)) { + typ = as->ob; + goto typfnd; + } + as++; } - as++; - } - /* can't use spellings list for this one due to shuffling */ - if (!strncmpi(bp, "grey spell", 10)) - *(bp + 2) = 'a'; + /* can't use spellings list for this one due to shuffling */ + if (!strncmpi(bp, "grey spell", 10)) + *(bp + 2) = 'a'; - if ((p = strstri(bp, "armour")) != 0) { - /* skip past "armo", then copy remainer beyond "u" */ - p += 4; - while ((*p = *(p + 1)) != '\0') ++p; /* self terminating */ - } + if ((p = strstri(bp, "armour")) != 0) { + /* skip past "armo", then copy remainer beyond "u" */ + p += 4; + while ((*p = *(p + 1)) != '\0') + ++p; /* self terminating */ + } } /* dragon scales - assumes order of dragons */ - if(!strcmpi(bp, "scales") && - mntmp >= PM_GRAY_DRAGON && mntmp <= PM_YELLOW_DRAGON) { + if (!strcmpi(bp, "scales") && mntmp >= PM_GRAY_DRAGON + && mntmp <= PM_YELLOW_DRAGON) { typ = GRAY_DRAGON_SCALES + mntmp - PM_GRAY_DRAGON; - mntmp = NON_PM; /* no monster */ + mntmp = NON_PM; /* no monster */ goto typfnd; } p = eos(bp); - if(!BSTRCMPI(bp, p-10, "holy water")) { + if (!BSTRCMPI(bp, p - 10, "holy water")) { typ = POT_WATER; - if ((p-bp) >= 12 && *(p-12) == 'u') + if ((p - bp) >= 12 && *(p - 12) == 'u') iscursed = 1; /* unholy water */ - else blessed = 1; + else + blessed = 1; goto typfnd; } - if(unlabeled && !BSTRCMPI(bp, p-6, "scroll")) { + if (unlabeled && !BSTRCMPI(bp, p - 6, "scroll")) { typ = SCR_BLANK_PAPER; goto typfnd; } - if(unlabeled && !BSTRCMPI(bp, p-9, "spellbook")) { + if (unlabeled && !BSTRCMPI(bp, p - 9, "spellbook")) { typ = SPE_BLANK_PAPER; goto typfnd; } @@ -2670,11 +2738,13 @@ struct obj *no_wish; * gold/money concept. Maybe we want to add other monetary units as * well in the future. (TH) */ - if(!BSTRCMPI(bp, p-10, "gold piece") || !BSTRCMPI(bp, p-7, "zorkmid") || - !strcmpi(bp, "gold") || !strcmpi(bp, "money") || - !strcmpi(bp, "coin") || *bp == GOLD_SYM) { - if (cnt > 5000 && !wizard) cnt = 5000; - else if (cnt < 1) cnt = 1; + if (!BSTRCMPI(bp, p - 10, "gold piece") || !BSTRCMPI(bp, p - 7, "zorkmid") + || !strcmpi(bp, "gold") || !strcmpi(bp, "money") + || !strcmpi(bp, "coin") || *bp == GOLD_SYM) { + if (cnt > 5000 && !wizard) + cnt = 5000; + else if (cnt < 1) + cnt = 1; otmp = mksobj(GOLD_PIECE, FALSE, FALSE); otmp->quan = (long) cnt; otmp->owt = weight(otmp); @@ -2683,47 +2753,44 @@ struct obj *no_wish; } /* check for single character object class code ("/" for wand, &c) */ - if (strlen(bp) == 1 && - (i = def_char_to_objclass(*bp)) < MAXOCLASSES && - i > ILLOBJ_CLASS && (i != VENOM_CLASS || wizard)) { + if (strlen(bp) == 1 && (i = def_char_to_objclass(*bp)) < MAXOCLASSES + && i > ILLOBJ_CLASS && (i != VENOM_CLASS || wizard)) { oclass = i; goto any; } /* Search for class names: XXXXX potion, scroll of XXXXX. Avoid */ /* false hits on, e.g., rings for "ring mail". */ - if(strncmpi(bp, "enchant ", 8) && - strncmpi(bp, "destroy ", 8) && - strncmpi(bp, "detect food", 11) && - strncmpi(bp, "food detection", 14) && - strncmpi(bp, "ring mail", 9) && - strncmpi(bp, "studded leather armor", 21) && - strncmpi(bp, "leather armor", 13) && - strncmpi(bp, "tooled horn", 11) && - strncmpi(bp, "food ration", 11) && - strncmpi(bp, "meat ring", 9) - ) - for (i = 0; i < (int)(sizeof wrpsym); i++) { - register int j = strlen(wrp[i]); - if(!strncmpi(bp, wrp[i], j)){ - oclass = wrpsym[i]; - if(oclass != AMULET_CLASS) { - bp += j; - if(!strncmpi(bp, " of ", 4)) actualn = bp+4; - /* else if(*bp) ?? */ - } else - actualn = bp; - goto srch; + if (strncmpi(bp, "enchant ", 8) && strncmpi(bp, "destroy ", 8) + && strncmpi(bp, "detect food", 11) + && strncmpi(bp, "food detection", 14) && strncmpi(bp, "ring mail", 9) + && strncmpi(bp, "studded leather armor", 21) + && strncmpi(bp, "leather armor", 13) + && strncmpi(bp, "tooled horn", 11) && strncmpi(bp, "food ration", 11) + && strncmpi(bp, "meat ring", 9)) + for (i = 0; i < (int) (sizeof wrpsym); i++) { + register int j = strlen(wrp[i]); + if (!strncmpi(bp, wrp[i], j)) { + oclass = wrpsym[i]; + if (oclass != AMULET_CLASS) { + bp += j; + if (!strncmpi(bp, " of ", 4)) + actualn = bp + 4; + /* else if(*bp) ?? */ + } else + actualn = bp; + goto srch; + } + if (!BSTRCMPI(bp, p - j, wrp[i])) { + oclass = wrpsym[i]; + p -= j; + *p = 0; + if (p > bp && p[-1] == ' ') + p[-1] = 0; + actualn = dn = bp; + goto srch; + } } - if(!BSTRCMPI(bp, p-j, wrp[i])){ - oclass = wrpsym[i]; - p -= j; - *p = 0; - if(p > bp && p[-1] == ' ') p[-1] = 0; - actualn = dn = bp; - goto srch; - } - } /* Wishing in wizard mode can create traps and furniture. * Part I: distinguish between trap and object for the two @@ -2745,93 +2812,103 @@ struct obj *no_wish; boolean beartrap = (lowc(*bp) == 'b'); char *zp = bp + 4; /* skip "bear"/"land" */ - if (*zp == ' ') ++zp; /* embedded space is optional */ + if (*zp == ' ') + ++zp; /* embedded space is optional */ if (!strncmpi(zp, beartrap ? "trap" : "mine", 4)) { - zp += 4; - if (trapped == 2 || !strcmpi(zp, " object")) { - /* "untrapped " or " object" */ - typ = beartrap ? BEARTRAP : LAND_MINE; - goto typfnd; - } else if (trapped == 1 || *zp != '\0') { - /* "trapped " or " trap" (actually "*") */ - int idx = trap_to_defsym(beartrap ? BEAR_TRAP : LANDMINE); + zp += 4; + if (trapped == 2 || !strcmpi(zp, " object")) { + /* "untrapped " or " object" */ + typ = beartrap ? BEARTRAP : LAND_MINE; + goto typfnd; + } else if (trapped == 1 || *zp != '\0') { + /* "trapped " or " trap" (actually "*") */ + int idx = trap_to_defsym(beartrap ? BEAR_TRAP : LANDMINE); - /* use canonical trap spelling, skip object matching */ - Strcpy(bp, defsyms[idx].explanation); - goto wiztrap; - } - /* [no prefix or suffix; we're going to end up matching - the object name and getting a disarmed trap object] */ + /* use canonical trap spelling, skip object matching */ + Strcpy(bp, defsyms[idx].explanation); + goto wiztrap; + } + /* [no prefix or suffix; we're going to end up matching + the object name and getting a disarmed trap object] */ } } retry: /* "grey stone" check must be before general "stone" */ for (i = 0; i < SIZE(o_ranges); i++) - if(!strcmpi(bp, o_ranges[i].name)) { - typ = rnd_class(o_ranges[i].f_o_range, o_ranges[i].l_o_range); - goto typfnd; + if (!strcmpi(bp, o_ranges[i].name)) { + typ = rnd_class(o_ranges[i].f_o_range, o_ranges[i].l_o_range); + goto typfnd; } - if (!BSTRCMPI(bp, p-6, " stone")) { + if (!BSTRCMPI(bp, p - 6, " stone")) { p[-6] = 0; oclass = GEM_CLASS; dn = actualn = bp; goto srch; } else if (!strcmpi(bp, "looking glass")) { - ; /* avoid false hit on "* glass" */ - } else if (!BSTRCMPI(bp, p-6, " glass") || !strcmpi(bp, "glass")) { + ; /* avoid false hit on "* glass" */ + } else if (!BSTRCMPI(bp, p - 6, " glass") || !strcmpi(bp, "glass")) { register char *g = bp; - if (strstri(g, "broken")) return (struct obj *)0; - if (!strncmpi(g, "worthless ", 10)) g += 10; - if (!strncmpi(g, "piece of ", 9)) g += 9; - if (!strncmpi(g, "colored ", 8)) g += 8; - else if (!strncmpi(g, "coloured ", 9)) g += 9; - if (!strcmpi(g, "glass")) { /* choose random color */ + if (strstri(g, "broken")) + return (struct obj *) 0; + if (!strncmpi(g, "worthless ", 10)) + g += 10; + if (!strncmpi(g, "piece of ", 9)) + g += 9; + if (!strncmpi(g, "colored ", 8)) + g += 8; + else if (!strncmpi(g, "coloured ", 9)) + g += 9; + if (!strcmpi(g, "glass")) { /* choose random color */ /* 9 different kinds */ typ = LAST_GEM + rnd(9); - if (objects[typ].oc_class == GEM_CLASS) goto typfnd; - else typ = 0; /* somebody changed objects[]? punt */ - } else { /* try to construct canonical form */ + if (objects[typ].oc_class == GEM_CLASS) + goto typfnd; + else + typ = 0; /* somebody changed objects[]? punt */ + } else { /* try to construct canonical form */ char tbuf[BUFSZ]; Strcpy(tbuf, "worthless piece of "); - Strcat(tbuf, g); /* assume it starts with the color */ + Strcat(tbuf, g); /* assume it starts with the color */ Strcpy(bp, tbuf); } } actualn = bp; - if (!dn) dn = actualn; /* ex. "skull cap" */ + if (!dn) + dn = actualn; /* ex. "skull cap" */ srch: /* check real names of gems first */ - if(!oclass && actualn) { - for(i = bases[GEM_CLASS]; i <= LAST_GEM; i++) { - register const char *zn; + if (!oclass && actualn) { + for (i = bases[GEM_CLASS]; i <= LAST_GEM; i++) { + register const char *zn; - if((zn = OBJ_NAME(objects[i])) && !strcmpi(actualn, zn)) { - typ = i; - goto typfnd; - } + if ((zn = OBJ_NAME(objects[i])) && !strcmpi(actualn, zn)) { + typ = i; + goto typfnd; + } } } - i = oclass ? bases[(int)oclass] : 1; - while(i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass)){ + i = oclass ? bases[(int) oclass] : 1; + while (i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass)) { register const char *zn; - if (actualn && (zn = OBJ_NAME(objects[i])) != 0 && - wishymatch(actualn, zn, TRUE)) { + if (actualn && (zn = OBJ_NAME(objects[i])) != 0 + && wishymatch(actualn, zn, TRUE)) { typ = i; goto typfnd; } - if (dn && (zn = OBJ_DESCR(objects[i])) != 0 && - wishymatch(dn, zn, FALSE)) { + if (dn && (zn = OBJ_DESCR(objects[i])) != 0 + && wishymatch(dn, zn, FALSE)) { /* don't match extra descriptions (w/o real name) */ - if (!OBJ_NAME(objects[i])) return (struct obj *)0; + if (!OBJ_NAME(objects[i])) + return (struct obj *) 0; typ = i; goto typfnd; } - if (un && (zn = objects[i].oc_uname) != 0 && - wishymatch(un, zn, FALSE)) { + if (un && (zn = objects[i].oc_uname) != 0 + && wishymatch(un, zn, FALSE)) { typ = i; goto typfnd; } @@ -2839,7 +2916,7 @@ srch: } if (actualn) { struct Jitem *j = Japanese_items; - while(j->item) { + while (j->item) { if (actualn && !strcmpi(actualn, j->name)) { typ = j->item; goto typfnd; @@ -2874,112 +2951,122 @@ srch: cntf = 0; fp = fruitbuf; - for(;;) { - if (!fp || !*fp) break; - if (!strncmpi(fp, "an ", l=3) || - !strncmpi(fp, "a ", l=2)) { - cntf = 1; - } else if (!cntf && digit(*fp)) { - cntf = atoi(fp); - while(digit(*fp)) fp++; - while(*fp == ' ') fp++; - l = 0; - } else if (!strncmpi(fp, "blessed ", l=8)) { - blessedf = 1; - } else if (!strncmpi(fp, "cursed ", l=7)) { - iscursedf = 1; - } else if (!strncmpi(fp, "uncursed ", l=9)) { - uncursedf = 1; - } else if (!strncmpi(fp, "partly eaten ", l=13) || - !strncmpi(fp, "partially eaten ", l=16)) { - halfeatenf = 1; - } else break; - fp += l; + for (;;) { + if (!fp || !*fp) + break; + if (!strncmpi(fp, "an ", l = 3) || !strncmpi(fp, "a ", l = 2)) { + cntf = 1; + } else if (!cntf && digit(*fp)) { + cntf = atoi(fp); + while (digit(*fp)) + fp++; + while (*fp == ' ') + fp++; + l = 0; + } else if (!strncmpi(fp, "blessed ", l = 8)) { + blessedf = 1; + } else if (!strncmpi(fp, "cursed ", l = 7)) { + iscursedf = 1; + } else if (!strncmpi(fp, "uncursed ", l = 9)) { + uncursedf = 1; + } else if (!strncmpi(fp, "partly eaten ", l = 13) + || !strncmpi(fp, "partially eaten ", l = 16)) { + halfeatenf = 1; + } else + break; + fp += l; } - for(f=ffruit; f; f = f->nextf) { - /* match type: 0=none, 1=exact, 2=singular, 3=plural */ - int ftyp = 0; + for (f = ffruit; f; f = f->nextf) { + /* match type: 0=none, 1=exact, 2=singular, 3=plural */ + int ftyp = 0; - if (!strcmp(fp, f->fname)) ftyp = 1; - else if (!strcmp(fp, makesingular(f->fname))) ftyp = 2; - else if (!strcmp(fp, makeplural(f->fname))) ftyp = 3; - if (ftyp) { - typ = SLIME_MOLD; - blessed = blessedf; - iscursed = iscursedf; - uncursed = uncursedf; - halfeaten = halfeatenf; - /* adjust count if user explicitly asked for - singular amount (can't happen unless fruit - has been given an already pluralized name) - or for plural amount */ - if (ftyp == 2 && !cntf) cntf = 1; - else if (ftyp == 3 && !cntf) cntf = 2; - cnt = cntf; - ftype = f->fid; - goto typfnd; - } + if (!strcmp(fp, f->fname)) + ftyp = 1; + else if (!strcmp(fp, makesingular(f->fname))) + ftyp = 2; + else if (!strcmp(fp, makeplural(f->fname))) + ftyp = 3; + if (ftyp) { + typ = SLIME_MOLD; + blessed = blessedf; + iscursed = iscursedf; + uncursed = uncursedf; + halfeaten = halfeatenf; + /* adjust count if user explicitly asked for + singular amount (can't happen unless fruit + has been given an already pluralized name) + or for plural amount */ + if (ftyp == 2 && !cntf) + cntf = 1; + else if (ftyp == 3 && !cntf) + cntf = 2; + cnt = cntf; + ftype = f->fid; + goto typfnd; + } } } - if(!oclass && actualn) { + if (!oclass && actualn) { short objtyp; /* Perhaps it's an artifact specified by name, not type */ name = artifact_name(actualn, &objtyp); - if(name) { - typ = objtyp; - goto typfnd; + if (name) { + typ = objtyp; + goto typfnd; } } - /* Let wizards wish for traps and furniture. - * Must come after objects check so wizards can still wish for - * trap objects like beartraps. - * Disallow such topology tweaks for WIZKIT startup wishes. - */ +/* Let wizards wish for traps and furniture. + * Must come after objects check so wizards can still wish for + * trap objects like beartraps. + * Disallow such topology tweaks for WIZKIT startup wishes. + */ wiztrap: if (wizard && !program_state.wizkit_wishing) { struct rm *lev; int trap, x = u.ux, y = u.uy; - for (trap = NO_TRAP+1; trap < TRAPNUM; trap++) { + for (trap = NO_TRAP + 1; trap < TRAPNUM; trap++) { struct trap *t; const char *tname; tname = defsyms[trap_to_defsym(trap)].explanation; - if (strncmpi(tname, bp, strlen(tname))) continue; + if (strncmpi(tname, bp, strlen(tname))) + continue; /* found it; avoid stupid mistakes */ - if ((trap == TRAPDOOR || trap == HOLE) && - !Can_fall_thru(&u.uz)) trap = ROCKTRAP; + if ((trap == TRAPDOOR || trap == HOLE) && !Can_fall_thru(&u.uz)) + trap = ROCKTRAP; if ((t = maketrap(x, y, trap)) != 0) { trap = t->ttyp; tname = defsyms[trap_to_defsym(trap)].explanation; pline("%s%s.", An(tname), - (trap != MAGIC_PORTAL) ? "" : " to nowhere"); + (trap != MAGIC_PORTAL) ? "" : " to nowhere"); } else pline("Creation of %s failed.", an(tname)); - return(&zeroobj); + return (&zeroobj); } /* furniture and terrain */ lev = &levl[x][y]; p = eos(bp); - if (!BSTRCMPI(bp, p-8, "fountain")) { + if (!BSTRCMPI(bp, p - 8, "fountain")) { lev->typ = FOUNTAIN; level.flags.nfountains++; - if(!strncmpi(bp, "magic ", 6)) lev->blessedftn = 1; + if (!strncmpi(bp, "magic ", 6)) + lev->blessedftn = 1; pline("A %sfountain.", lev->blessedftn ? "magic " : ""); newsym(x, y); - return(&zeroobj); + return (&zeroobj); } - if (!BSTRCMPI(bp, p-6, "throne")) { + if (!BSTRCMPI(bp, p - 6, "throne")) { lev->typ = THRONE; pline("A throne."); newsym(x, y); - return(&zeroobj); + return (&zeroobj); } - if (!BSTRCMPI(bp, p-4, "sink")) { + if (!BSTRCMPI(bp, p - 4, "sink")) { lev->typ = SINK; level.flags.nsinks++; pline("A sink."); @@ -2987,8 +3074,8 @@ wiztrap: return &zeroobj; } /* ("water" matches "potion of water" rather than terrain) */ - if (!BSTRCMPI(bp, p-4, "pool") || !BSTRCMPI(bp, p-4, "moat")) { - lev->typ = !BSTRCMPI(bp, p-4, "pool") ? POOL : MOAT; + if (!BSTRCMPI(bp, p - 4, "pool") || !BSTRCMPI(bp, p - 4, "moat")) { + lev->typ = !BSTRCMPI(bp, p - 4, "pool") ? POOL : MOAT; del_engr_at(x, y); pline("A %s.", (lev->typ == POOL) ? "pool" : "moat"); /* Must manually make kelp! */ @@ -2996,45 +3083,46 @@ wiztrap: newsym(x, y); return &zeroobj; } - if (!BSTRCMPI(bp, p-4, "lava")) { /* also matches "molten lava" */ + if (!BSTRCMPI(bp, p - 4, "lava")) { /* also matches "molten lava" */ lev->typ = LAVAPOOL; del_engr_at(x, y); pline("A pool of molten lava."); - if (!(Levitation || Flying)) (void) lava_effects(); + if (!(Levitation || Flying)) + (void) lava_effects(); newsym(x, y); return &zeroobj; } - if (!BSTRCMPI(bp, p-5, "altar")) { + if (!BSTRCMPI(bp, p - 5, "altar")) { aligntyp al; lev->typ = ALTAR; - if(!strncmpi(bp, "chaotic ", 8)) - al = A_CHAOTIC; - else if(!strncmpi(bp, "neutral ", 8)) - al = A_NEUTRAL; - else if(!strncmpi(bp, "lawful ", 7)) - al = A_LAWFUL; - else if(!strncmpi(bp, "unaligned ", 10)) - al = A_NONE; + if (!strncmpi(bp, "chaotic ", 8)) + al = A_CHAOTIC; + else if (!strncmpi(bp, "neutral ", 8)) + al = A_NEUTRAL; + else if (!strncmpi(bp, "lawful ", 7)) + al = A_LAWFUL; + else if (!strncmpi(bp, "unaligned ", 10)) + al = A_NONE; else /* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */ - al = (!rn2(6)) ? A_NONE : rn2((int)A_LAWFUL+2) - 1; + al = (!rn2(6)) ? A_NONE : rn2((int) A_LAWFUL + 2) - 1; lev->altarmask = Align2amask(al); pline("%s altar.", An(align_str(al))); newsym(x, y); - return(&zeroobj); + return (&zeroobj); } - if (!BSTRCMPI(bp, p-5, "grave") || - !BSTRCMPI(bp, p-9, "headstone")) { - make_grave(x, y, (char *)0); - pline("%s.", IS_GRAVE(lev->typ) ? "A grave" : - "Can't place a grave here"); + if (!BSTRCMPI(bp, p - 5, "grave") + || !BSTRCMPI(bp, p - 9, "headstone")) { + make_grave(x, y, (char *) 0); + pline("%s.", IS_GRAVE(lev->typ) ? "A grave" + : "Can't place a grave here"); newsym(x, y); - return(&zeroobj); + return (&zeroobj); } - if (!BSTRCMPI(bp, p-4, "tree")) { + if (!BSTRCMPI(bp, p - 4, "tree")) { lev->typ = TREE; pline("A tree."); newsym(x, y); @@ -3042,7 +3130,7 @@ wiztrap: return &zeroobj; } - if (!BSTRCMPI(bp, p-4, "bars")) { + if (!BSTRCMPI(bp, p - 4, "bars")) { lev->typ = IRONBARS; pline("Iron bars."); newsym(x, y); @@ -3051,20 +3139,23 @@ wiztrap: } if (!oclass && !typ) { - if (!strncmpi(bp, "polearm", 7)) { - typ = rnd_otyp_by_wpnskill(P_POLEARMS); - goto typfnd; - } else if (!strncmpi(bp, "hammer", 6)) { - typ = rnd_otyp_by_wpnskill(P_HAMMER); - goto typfnd; - } + if (!strncmpi(bp, "polearm", 7)) { + typ = rnd_otyp_by_wpnskill(P_POLEARMS); + goto typfnd; + } else if (!strncmpi(bp, "hammer", 6)) { + typ = rnd_otyp_by_wpnskill(P_HAMMER); + goto typfnd; + } } - if(!oclass) return((struct obj *)0); + if (!oclass) + return ((struct obj *) 0); any: - if(!oclass) oclass = wrpsym[rn2((int)sizeof(wrpsym))]; + if (!oclass) + oclass = wrpsym[rn2((int) sizeof(wrpsym))]; typfnd: - if (typ) oclass = objects[typ].oc_class; + if (typ) + oclass = objects[typ].oc_class; /* handle some objects that are only allowed in wizard mode */ if (typ && !wizard) { @@ -3086,19 +3177,20 @@ typfnd: break; default: /* catch any other non-wishable objects (venom) */ - if (objects[typ].oc_nowish) return ((struct obj *)0); + if (objects[typ].oc_nowish) + return ((struct obj *) 0); break; } } - if (typ && wizard) { - if (typ == SPE_NOVEL) { - if (name && !lookup_novel(name, (int *)0)) { - pline("There's no novel by that name."); - return ((struct obj *)0); - } - } - } + if (typ && wizard) { + if (typ == SPE_NOVEL) { + if (name && !lookup_novel(name, (int *) 0)) { + pline("There's no novel by that name."); + return ((struct obj *) 0); + } + } + } /* * Create the object, then fine-tune it. @@ -3106,103 +3198,116 @@ typfnd: otmp = typ ? mksobj(typ, TRUE, FALSE) : mkobj(oclass, FALSE); typ = otmp->otyp, oclass = otmp->oclass; /* what we actually got */ - if (islit && - (typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN || - Is_candle(otmp) || typ == POT_OIL)) { - place_object(otmp, u.ux, u.uy); /* make it viable light source */ + if (islit && (typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN + || Is_candle(otmp) || typ == POT_OIL)) { + place_object(otmp, u.ux, u.uy); /* make it viable light source */ begin_burn(otmp, FALSE); - obj_extract_self(otmp); /* now release it for caller's use */ + obj_extract_self(otmp); /* now release it for caller's use */ } /* if player specified a reasonable count, maybe honor it */ - if (cnt > 0 && objects[typ].oc_merge && - (wizard || cnt < rnd(6) || - (cnt <= 7 && Is_candle(otmp)) || - (cnt <= 20 && - ((oclass == WEAPON_CLASS && is_ammo(otmp)) - || typ == ROCK || is_missile(otmp))))) + if (cnt > 0 && objects[typ].oc_merge + && (wizard || cnt < rnd(6) || (cnt <= 7 && Is_candle(otmp)) + || (cnt <= 20 && ((oclass == WEAPON_CLASS && is_ammo(otmp)) + || typ == ROCK || is_missile(otmp))))) otmp->quan = (long) cnt; - if (oclass == VENOM_CLASS) otmp->spe = 1; + if (oclass == VENOM_CLASS) + otmp->spe = 1; if (spesgn == 0) { spe = otmp->spe; } else if (wizard) { - ; /* no alteration to spe */ - } else if (oclass == ARMOR_CLASS || oclass == WEAPON_CLASS || - is_weptool(otmp) || - (oclass==RING_CLASS && objects[typ].oc_charged)) { - if(spe > rnd(5) && spe > otmp->spe) spe = 0; - if(spe > 2 && Luck < 0) spesgn = -1; + ; /* no alteration to spe */ + } else if (oclass == ARMOR_CLASS || oclass == WEAPON_CLASS + || is_weptool(otmp) + || (oclass == RING_CLASS && objects[typ].oc_charged)) { + if (spe > rnd(5) && spe > otmp->spe) + spe = 0; + if (spe > 2 && Luck < 0) + spesgn = -1; } else { if (oclass == WAND_CLASS) { - if (spe > 1 && spesgn == -1) spe = 1; + if (spe > 1 && spesgn == -1) + spe = 1; } else { - if (spe > 0 && spesgn == -1) spe = 0; + if (spe > 0 && spesgn == -1) + spe = 0; } - if (spe > otmp->spe) spe = otmp->spe; + if (spe > otmp->spe) + spe = otmp->spe; } - if (spesgn == -1) spe = -spe; + if (spesgn == -1) + spe = -spe; /* set otmp->spe. This may, or may not, use spe... */ switch (typ) { - case TIN: if (contents==EMPTY) { - otmp->corpsenm = NON_PM; - otmp->spe = 0; - } else if (contents==SPINACH) { - otmp->corpsenm = NON_PM; - otmp->spe = 1; - } - break; - case SLIME_MOLD: otmp->spe = ftype; - /* Fall through */ - case SKELETON_KEY: case CHEST: case LARGE_BOX: - case HEAVY_IRON_BALL: case IRON_CHAIN: case STATUE: - /* otmp->cobj already done in mksobj() */ - break; + case TIN: + if (contents == EMPTY) { + otmp->corpsenm = NON_PM; + otmp->spe = 0; + } else if (contents == SPINACH) { + otmp->corpsenm = NON_PM; + otmp->spe = 1; + } + break; + case SLIME_MOLD: + otmp->spe = ftype; + /* Fall through */ + case SKELETON_KEY: + case CHEST: + case LARGE_BOX: + case HEAVY_IRON_BALL: + case IRON_CHAIN: + case STATUE: + /* otmp->cobj already done in mksobj() */ + break; #ifdef MAIL - case SCR_MAIL: otmp->spe = 1; break; + case SCR_MAIL: + otmp->spe = 1; + break; #endif - case WAN_WISHING: - if (!wizard) { - otmp->spe = (rn2(10) ? -1 : 0); - break; - } - /* fall through, if wizard */ - default: otmp->spe = spe; + case WAN_WISHING: + if (!wizard) { + otmp->spe = (rn2(10) ? -1 : 0); + break; + } + /* fall through, if wizard */ + default: + otmp->spe = spe; } /* set otmp->corpsenm or dragon scale [mail] */ if (mntmp >= LOW_PM) { - if (mntmp == PM_LONG_WORM_TAIL) mntmp = PM_LONG_WORM; + if (mntmp == PM_LONG_WORM_TAIL) + mntmp = PM_LONG_WORM; switch (typ) { case TIN: otmp->spe = 0; /* No spinach */ if (dead_species(mntmp, FALSE)) { - otmp->corpsenm = NON_PM; /* it's empty */ - } else if (!(mons[mntmp].geno & G_UNIQ) && - !(mvitals[mntmp].mvflags & G_NOCORPSE) && - mons[mntmp].cnutrit != 0) { + otmp->corpsenm = NON_PM; /* it's empty */ + } else if (!(mons[mntmp].geno & G_UNIQ) + && !(mvitals[mntmp].mvflags & G_NOCORPSE) + && mons[mntmp].cnutrit != 0) { otmp->corpsenm = mntmp; } break; case CORPSE: - if (!(mons[mntmp].geno & G_UNIQ) && - !(mvitals[mntmp].mvflags & G_NOCORPSE)) { + if (!(mons[mntmp].geno & G_UNIQ) + && !(mvitals[mntmp].mvflags & G_NOCORPSE)) { if (mons[mntmp].msound == MS_GUARDIAN) - mntmp = genus(mntmp,1); + mntmp = genus(mntmp, 1); set_corpsenm(otmp, mntmp); } break; case FIGURINE: - if (!(mons[mntmp].geno & G_UNIQ) - && !is_human(&mons[mntmp]) + if (!(mons[mntmp].geno & G_UNIQ) && !is_human(&mons[mntmp]) #ifdef MAIL && mntmp != PM_MAIL_DAEMON #endif - ) + ) otmp->corpsenm = mntmp; break; case EGG: @@ -3210,18 +3315,17 @@ typfnd: /* this also sets hatch timer if appropriate */ set_corpsenm(otmp, mntmp); break; - case STATUE: otmp->corpsenm = mntmp; + case STATUE: + otmp->corpsenm = mntmp; if (Has_contents(otmp) && verysmall(&mons[mntmp])) - delete_contents(otmp); /* no spellbook */ + delete_contents(otmp); /* no spellbook */ otmp->spe = ishistoric ? STATUE_HISTORIC : 0; break; case SCALE_MAIL: /* Dragon mail - depends on the order of objects */ /* & dragons. */ - if (mntmp >= PM_GRAY_DRAGON && - mntmp <= PM_YELLOW_DRAGON) - otmp->otyp = GRAY_DRAGON_SCALE_MAIL + - mntmp - PM_GRAY_DRAGON; + if (mntmp >= PM_GRAY_DRAGON && mntmp <= PM_YELLOW_DRAGON) + otmp->otyp = GRAY_DRAGON_SCALE_MAIL + mntmp - PM_GRAY_DRAGON; break; } } @@ -3256,28 +3360,29 @@ typfnd: /* set otmp->recharged */ if (oclass == WAND_CLASS) { /* prevent wishing abuse */ - if (otmp->otyp == WAN_WISHING && !wizard) rechrg = 1; - otmp->recharged = (unsigned)rechrg; + if (otmp->otyp == WAN_WISHING && !wizard) + rechrg = 1; + otmp->recharged = (unsigned) rechrg; } /* set poisoned */ if (ispoisoned) { if (is_poisonable(otmp)) - otmp->opoisoned = (Luck >= 0); + otmp->opoisoned = (Luck >= 0); else if (oclass == FOOD_CLASS) - /* try to taint by making it as old as possible */ - otmp->age = 1L; + /* try to taint by making it as old as possible */ + otmp->age = 1L; } /* and [un]trapped */ if (trapped) { if (Is_box(otmp) || typ == TIN) - otmp->otrapped = (trapped == 1); + otmp->otrapped = (trapped == 1); } - if (isgreased) otmp->greased = 1; + if (isgreased) + otmp->greased = 1; - if (isdiluted && otmp->oclass == POTION_CLASS && - otmp->otyp != POT_WATER) + if (isdiluted && otmp->oclass == POTION_CLASS && otmp->otyp != POT_WATER) otmp->odiluted = 1; /* set tin variety */ @@ -3290,7 +3395,8 @@ typfnd: /* an artifact name might need capitalization fixing */ aname = artifact_name(name, &objtyp); - if (aname && objtyp == otmp->otyp) name = aname; + if (aname && objtyp == otmp->otyp) + name = aname; /* 3.6.0 tribute - fix up novel */ if (otmp->otyp == SPE_NOVEL) { @@ -3299,58 +3405,58 @@ typfnd: novelname = lookup_novel(name, &novidx); if (novelname) { - otmp->novelidx = novidx; - name = novelname; + otmp->novelidx = novidx; + name = novelname; } - } + } otmp = oname(otmp, name); if (otmp->oartifact) { otmp->quan = 1L; - u.uconduct.wisharti++; /* KMH, conduct */ + u.uconduct.wisharti++; /* KMH, conduct */ } } /* more wishing abuse: don't allow wishing for certain artifacts */ /* and make them pay; charge them for the wish anyway! */ - if ((is_quest_artifact(otmp) || - (otmp->oartifact && rn2(nartifact_exist()) > 1)) && - !wizard) { + if ((is_quest_artifact(otmp) + || (otmp->oartifact && rn2(nartifact_exist()) > 1)) && !wizard) { artifact_exists(otmp, safe_oname(otmp), FALSE); obfree(otmp, (struct obj *) 0); otmp = &zeroobj; pline("For a moment, you feel %s in your %s, but it disappears!", - something, - makeplural(body_part(HAND))); + something, makeplural(body_part(HAND))); } if (halfeaten && otmp->oclass == FOOD_CLASS) { if (otmp->otyp == CORPSE) otmp->oeaten = mons[otmp->corpsenm].cnutrit; - else otmp->oeaten = objects[otmp->otyp].oc_nutrition; + else + otmp->oeaten = objects[otmp->otyp].oc_nutrition; /* (do this adjustment before setting up object's weight) */ consume_oeaten(otmp, 1); } otmp->owt = weight(otmp); - if (very && otmp->otyp == HEAVY_IRON_BALL) otmp->owt += 160; + if (very && otmp->otyp == HEAVY_IRON_BALL) + otmp->owt += 160; - return(otmp); + return (otmp); } int -rnd_class(first,last) -int first,last; +rnd_class(first, last) +int first, last; { - int i, x, sum=0; + int i, x, sum = 0; if (first == last) return (first); - for(i=first; i<=last; i++) + for (i = first; i <= last; i++) sum += objects[i].oc_prob; if (!sum) /* all zero */ - return first + rn2(last-first+1); + return first + rn2(last - first + 1); x = rnd(sum); - for(i=first; i<=last; i++) + for (i = first; i <= last; i++) if (objects[i].oc_prob && (x -= objects[i].oc_prob) <= 0) return i; return 0; @@ -3362,12 +3468,12 @@ int i; { struct Jitem *j = Japanese_items; - while(j->item) { + while (j->item) { if (i == j->item) return j->name; j++; } - return (const char *)0; + return (const char *) 0; } const char * @@ -3377,15 +3483,15 @@ struct obj *suit; const char *suitnm, *esuitp; if (Is_dragon_mail(suit)) - return "dragon mail"; /* dragon scale mail */ + return "dragon mail"; /* dragon scale mail */ else if (Is_dragon_scales(suit)) return "dragon scales"; suitnm = OBJ_NAME(objects[suit->otyp]); - esuitp = eos((char *)suitnm); + esuitp = eos((char *) suitnm); if (strlen(suitnm) > 5 && !strcmp(esuitp - 5, " mail")) - return "mail"; /* most suits fall into this category */ + return "mail"; /* most suits fall into this category */ else if (strlen(suitnm) > 7 && !strcmp(esuitp - 7, " jacket")) - return "jacket"; /* leather jacket */ + return "jacket"; /* leather jacket */ /* suit is lame but armor is ambiguous and body armor is absurd */ return "suit"; } @@ -3395,17 +3501,18 @@ cloak_simple_name(cloak) struct obj *cloak; { if (cloak) { - switch (cloak->otyp) { - case ROBE: - return "robe"; - case MUMMY_WRAPPING: - return "wrapping"; - case ALCHEMY_SMOCK: - return (objects[cloak->otyp].oc_name_known && - cloak->dknown) ? "smock" : "apron"; - default: - break; - } + switch (cloak->otyp) { + case ROBE: + return "robe"; + case MUMMY_WRAPPING: + return "wrapping"; + case ALCHEMY_SMOCK: + return (objects[cloak->otyp].oc_name_known && cloak->dknown) + ? "smock" + : "apron"; + default: + break; + } } return "cloak"; } @@ -3434,9 +3541,11 @@ const char * mimic_obj_name(mtmp) struct monst *mtmp; { - if (mtmp->m_ap_type == M_AP_OBJECT && mtmp->mappearance != STRANGE_OBJECT) { + if (mtmp->m_ap_type == M_AP_OBJECT + && mtmp->mappearance != STRANGE_OBJECT) { int idx = objects[mtmp->mappearance].oc_descr_idx; - if (mtmp->mappearance == GOLD_PIECE) return "gold"; + if (mtmp->mappearance == GOLD_PIECE) + return "gold"; return obj_descr[idx].oc_name; } return "whatcha-may-callit"; @@ -3450,7 +3559,7 @@ struct monst *mtmp; */ char * safe_qbuf(qbuf, qprefix, qsuffix, obj, func, altfunc, lastR) -char *qbuf; /* output buffer */ +char *qbuf; /* output buffer */ const char *qprefix, *qsuffix; struct obj *obj; char *FDECL((*func), (OBJ_P)), *FDECL((*altfunc), (OBJ_P)); @@ -3459,9 +3568,9 @@ const char *lastR; char *bufp, *endp; /* convert size_t (or int for ancient systems) to ordinary unsigned */ unsigned len, lenlimit, - len_qpfx = (unsigned)(qprefix ? strlen(qprefix) : 0), - len_qsfx = (unsigned)(qsuffix ? strlen(qsuffix) : 0), - len_lastR = (unsigned)strlen(lastR); + len_qpfx = (unsigned) (qprefix ? strlen(qprefix) : 0), + len_qsfx = (unsigned) (qsuffix ? strlen(qsuffix) : 0), + len_lastR = (unsigned) strlen(lastR); lenlimit = QBUFSZ - 1; endp = qbuf + lenlimit; @@ -3469,56 +3578,56 @@ const char *lastR; the result of short_oname() to be shorter than the length of the last resort string, but we ignore that possibility here) */ if (len_qpfx > lenlimit) - impossible("safe_qbuf: prefix too long (%u characters).", - len_qpfx); + impossible("safe_qbuf: prefix too long (%u characters).", len_qpfx); else if (len_qpfx + len_qsfx > lenlimit) - impossible("safe_qbuf: suffix too long (%u + %u characters).", - len_qpfx, len_qsfx); + impossible("safe_qbuf: suffix too long (%u + %u characters).", + len_qpfx, len_qsfx); else if (len_qpfx + len_lastR + len_qsfx > lenlimit) - impossible("safe_qbuf: filler too long (%u + %u + %u characters).", - len_qpfx, len_lastR, len_qsfx); + impossible("safe_qbuf: filler too long (%u + %u + %u characters).", + len_qpfx, len_lastR, len_qsfx); /* the output buffer might be the same as the prefix if caller has already partially filled it */ if (qbuf == qprefix) { - /* prefix is already in the buffer */ - *endp = '\0'; + /* prefix is already in the buffer */ + *endp = '\0'; } else if (qprefix) { - /* put prefix into the buffer */ - (void)strncpy(qbuf, qprefix, lenlimit); - *endp = '\0'; + /* put prefix into the buffer */ + (void) strncpy(qbuf, qprefix, lenlimit); + *endp = '\0'; } else { - /* no prefix; output buffer starts out empty */ - qbuf[0] = '\0'; + /* no prefix; output buffer starts out empty */ + qbuf[0] = '\0'; } - len = (unsigned)strlen(qbuf); + len = (unsigned) strlen(qbuf); if (len + len_lastR + len_qsfx > lenlimit) { - /* too long; skip formatting, last resort output is truncated */ - if (len < lenlimit) { - (void)strncpy(&qbuf[len], lastR, lenlimit - len); - *endp = '\0'; - len = (unsigned)strlen(qbuf); - if (qsuffix && len < lenlimit) { - (void)strncpy(&qbuf[len], qsuffix, lenlimit - len); - *endp = '\0'; - /* len = (unsigned)strlen(qbuf); */ + /* too long; skip formatting, last resort output is truncated */ + if (len < lenlimit) { + (void) strncpy(&qbuf[len], lastR, lenlimit - len); + *endp = '\0'; + len = (unsigned) strlen(qbuf); + if (qsuffix && len < lenlimit) { + (void) strncpy(&qbuf[len], qsuffix, lenlimit - len); + *endp = '\0'; + /* len = (unsigned)strlen(qbuf); */ + } } - } } else { - /* suffix and last resort are guaranteed to fit */ - len += len_qsfx; /* include the pending suffix */ - /* format the object */ - bufp = short_oname(obj, func, altfunc, lenlimit - len); - if (len + strlen(bufp) <= lenlimit) - Strcat(qbuf, bufp); /* formatted name fits */ - else - Strcat(qbuf, lastR); /* use last resort */ - releaseobuf(bufp); + /* suffix and last resort are guaranteed to fit */ + len += len_qsfx; /* include the pending suffix */ + /* format the object */ + bufp = short_oname(obj, func, altfunc, lenlimit - len); + if (len + strlen(bufp) <= lenlimit) + Strcat(qbuf, bufp); /* formatted name fits */ + else + Strcat(qbuf, lastR); /* use last resort */ + releaseobuf(bufp); - if (qsuffix) Strcat(qbuf, qsuffix); + if (qsuffix) + Strcat(qbuf, qsuffix); } - /* assert( strlen(qbuf) < QBUFSZ ); */ + /* assert( strlen(qbuf) < QBUFSZ ); */ return qbuf; } diff --git a/src/options.c b/src/options.c index 82fc250c4..c98c3d2cd 100644 --- a/src/options.c +++ b/src/options.c @@ -1,17 +1,17 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1430441885 2015/05/01 00:58:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.191 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.197 $ */ /* NetHack 3.6 options.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.153 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ -#ifdef OPTION_LISTS_ONLY /* (AMIGA) external program for opt lists */ +#ifdef OPTION_LISTS_ONLY /* (AMIGA) external program for opt lists */ #include "config.h" #include "objclass.h" #include "flag.h" -NEARDATA struct flag flags; /* provide linkage */ +NEARDATA struct flag flags; /* provide linkage */ #ifdef SYSFLAGS -NEARDATA struct sysflag sysflags; /* provide linkage */ +NEARDATA struct sysflag sysflags; /* provide linkage */ #endif -NEARDATA struct instance_flags iflags; /* provide linkage */ +NEARDATA struct instance_flags iflags; /* provide linkage */ #define static #else #include "hack.h" @@ -28,11 +28,11 @@ NEARDATA struct instance_flags iflags; /* provide linkage */ #define PREFER_TILED FALSE #endif -#define MESSAGE_OPTION 1 -#define STATUS_OPTION 2 -#define MAP_OPTION 3 -#define MENU_OPTION 4 -#define TEXT_OPTION 5 +#define MESSAGE_OPTION 1 +#define STATUS_OPTION 2 +#define MAP_OPTION 3 +#define MENU_OPTION 4 +#define TEXT_OPTION 5 #define PILE_LIMIT_DFLT 5 @@ -46,373 +46,376 @@ NEARDATA struct instance_flags iflags; /* provide linkage */ * option (e.g. time and timed_delay) the shorter one must come first. */ -static struct Bool_Opt -{ - const char *name; - boolean *addr, initvalue; - int optflags; +static struct Bool_Opt { + const char *name; + boolean *addr, initvalue; + int optflags; } boolopt[] = { - {"acoustics", &flags.acoustics, TRUE, SET_IN_GAME}, + { "acoustics", &flags.acoustics, TRUE, SET_IN_GAME }, #if defined(SYSFLAGS) && defined(AMIGA) - /* Amiga altmeta causes Alt+key to be converted into Meta+key by - low level nethack code; on by default, can be toggled off if - Alt+key is needed for some ASCII chars on non-ASCII keyboard */ - {"altmeta", &sysflags.altmeta, TRUE, DISP_IN_GAME}, + /* Amiga altmeta causes Alt+key to be converted into Meta+key by + low level nethack code; on by default, can be toggled off if + Alt+key is needed for some ASCII chars on non-ASCII keyboard */ + { "altmeta", &sysflags.altmeta, TRUE, DISP_IN_GAME }, #else -# ifdef ALTMETA - /* non-Amiga altmeta causes nethack's top level command loop to treat - two character sequence "ESC c" as M-c, for terminals or emulators - which send "ESC c" when Alt+c is pressed; off by default, enabling - this can potentially make trouble if user types ESC when nethack - is honoring this conversion request (primarily after starting a - count prefix prior to a command and then deciding to cancel it) */ - {"altmeta", &iflags.altmeta, FALSE, SET_IN_GAME}, -# else - {"altmeta", (boolean *)0, TRUE, DISP_IN_GAME}, -# endif +#ifdef ALTMETA + /* non-Amiga altmeta causes nethack's top level command loop to treat + two character sequence "ESC c" as M-c, for terminals or emulators + which send "ESC c" when Alt+c is pressed; off by default, enabling + this can potentially make trouble if user types ESC when nethack + is honoring this conversion request (primarily after starting a + count prefix prior to a command and then deciding to cancel it) */ + { "altmeta", &iflags.altmeta, FALSE, SET_IN_GAME }, +#else + { "altmeta", (boolean *) 0, TRUE, DISP_IN_GAME }, #endif - {"ascii_map", &iflags.wc_ascii_map, !PREFER_TILED, SET_IN_GAME}, /*WC*/ +#endif + { "ascii_map", &iflags.wc_ascii_map, !PREFER_TILED, SET_IN_GAME }, /*WC*/ #if defined(SYSFLAGS) && defined(MFLOPPY) - {"asksavedisk", &sysflags.asksavedisk, FALSE, SET_IN_GAME}, + { "asksavedisk", &sysflags.asksavedisk, FALSE, SET_IN_GAME }, #else - {"asksavedisk", (boolean *)0, FALSE, SET_IN_FILE}, + { "asksavedisk", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"autodig", &flags.autodig, FALSE, SET_IN_GAME}, - {"autoopen", &flags.autoopen, TRUE, SET_IN_GAME}, - {"autopickup", &flags.pickup, TRUE, SET_IN_GAME}, - {"autoquiver", &flags.autoquiver, FALSE, SET_IN_GAME}, + { "autodig", &flags.autodig, FALSE, SET_IN_GAME }, + { "autoopen", &flags.autoopen, TRUE, SET_IN_GAME }, + { "autopickup", &flags.pickup, TRUE, SET_IN_GAME }, + { "autoquiver", &flags.autoquiver, FALSE, SET_IN_GAME }, #if defined(MICRO) && !defined(AMIGA) - {"BIOS", &iflags.BIOS, FALSE, SET_IN_FILE}, + { "BIOS", &iflags.BIOS, FALSE, SET_IN_FILE }, #else - {"BIOS", (boolean *)0, FALSE, SET_IN_FILE}, + { "BIOS", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"blind", &u.uroleplay.blind, FALSE, DISP_IN_GAME}, - {"bones", &flags.bones, TRUE, SET_IN_FILE}, + { "blind", &u.uroleplay.blind, FALSE, DISP_IN_GAME }, + { "bones", &flags.bones, TRUE, SET_IN_FILE }, #ifdef INSURANCE - {"checkpoint", &flags.ins_chkpt, TRUE, SET_IN_GAME}, + { "checkpoint", &flags.ins_chkpt, TRUE, SET_IN_GAME }, #else - {"checkpoint", (boolean *)0, FALSE, SET_IN_FILE}, + { "checkpoint", (boolean *) 0, FALSE, SET_IN_FILE }, #endif #ifdef MFLOPPY - {"checkspace", &iflags.checkspace, TRUE, SET_IN_GAME}, + { "checkspace", &iflags.checkspace, TRUE, SET_IN_GAME }, #else - {"checkspace", (boolean *)0, FALSE, SET_IN_FILE}, + { "checkspace", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"clicklook", &iflags.clicklook, FALSE, SET_IN_GAME}, - {"cmdassist", &iflags.cmdassist, TRUE, SET_IN_GAME}, -# if defined(MICRO) || defined(WIN32) - {"color", &iflags.wc_color,TRUE, SET_IN_GAME}, /*WC*/ -# else /* systems that support multiple terminals, many monochrome */ - {"color", &iflags.wc_color, FALSE, SET_IN_GAME}, /*WC*/ -# endif - {"confirm",&flags.confirm, TRUE, SET_IN_GAME}, - {"dark_room", &flags.dark_room, TRUE, SET_IN_GAME}, - {"eight_bit_tty", &iflags.wc_eight_bit_input, FALSE, SET_IN_GAME}, /*WC*/ + { "clicklook", &iflags.clicklook, FALSE, SET_IN_GAME }, + { "cmdassist", &iflags.cmdassist, TRUE, SET_IN_GAME }, +#if defined(MICRO) || defined(WIN32) + { "color", &iflags.wc_color, TRUE, SET_IN_GAME }, /*WC*/ +#else /* systems that support multiple terminals, many monochrome */ + { "color", &iflags.wc_color, FALSE, SET_IN_GAME }, /*WC*/ +#endif + { "confirm", &flags.confirm, TRUE, SET_IN_GAME }, + { "dark_room", &flags.dark_room, TRUE, SET_IN_GAME }, + { "eight_bit_tty", &iflags.wc_eight_bit_input, FALSE, + SET_IN_GAME }, /*WC*/ #ifdef TTY_GRAPHICS - {"extmenu", &iflags.extmenu, FALSE, SET_IN_GAME}, + { "extmenu", &iflags.extmenu, FALSE, SET_IN_GAME }, #else - {"extmenu", (boolean *)0, FALSE, SET_IN_FILE}, + { "extmenu", (boolean *) 0, FALSE, SET_IN_FILE }, #endif #ifdef OPT_DISPMAP - {"fast_map", &flags.fast_map, TRUE, SET_IN_GAME}, + { "fast_map", &flags.fast_map, TRUE, SET_IN_GAME }, #else - {"fast_map", (boolean *)0, TRUE, SET_IN_FILE}, + { "fast_map", (boolean *) 0, TRUE, SET_IN_FILE }, #endif - {"female", &flags.female, FALSE, DISP_IN_GAME}, - {"fixinv", &flags.invlet_constant, TRUE, SET_IN_GAME}, + { "female", &flags.female, FALSE, DISP_IN_GAME }, + { "fixinv", &flags.invlet_constant, TRUE, SET_IN_GAME }, #if defined(SYSFLAGS) && defined(AMIFLUSH) - {"flush", &sysflags.amiflush, FALSE, SET_IN_GAME}, + { "flush", &sysflags.amiflush, FALSE, SET_IN_GAME }, #else - {"flush", (boolean *)0, FALSE, SET_IN_FILE}, + { "flush", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"fullscreen", &iflags.wc2_fullscreen, FALSE, SET_IN_FILE}, - {"help", &flags.help, TRUE, SET_IN_GAME}, - {"hilite_pet", &iflags.wc_hilite_pet, FALSE, SET_IN_GAME}, /*WC*/ + { "fullscreen", &iflags.wc2_fullscreen, FALSE, SET_IN_FILE }, + { "help", &flags.help, TRUE, SET_IN_GAME }, + { "hilite_pet", &iflags.wc_hilite_pet, FALSE, SET_IN_GAME }, /*WC*/ #ifndef MAC - {"ignintr", &flags.ignintr, FALSE, SET_IN_GAME}, + { "ignintr", &flags.ignintr, FALSE, SET_IN_GAME }, #else - {"ignintr", (boolean *)0, FALSE, SET_IN_FILE}, + { "ignintr", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"large_font", &iflags.obsolete, FALSE, SET_IN_FILE}, /* OBSOLETE */ - {"legacy", &flags.legacy, TRUE, DISP_IN_GAME}, - {"lit_corridor", &flags.lit_corridor, FALSE, SET_IN_GAME}, - {"lootabc", &flags.lootabc, FALSE, SET_IN_GAME}, + { "large_font", &iflags.obsolete, FALSE, SET_IN_FILE }, /* OBSOLETE */ + { "legacy", &flags.legacy, TRUE, DISP_IN_GAME }, + { "lit_corridor", &flags.lit_corridor, FALSE, SET_IN_GAME }, + { "lootabc", &flags.lootabc, FALSE, SET_IN_GAME }, #ifdef MAIL - {"mail", &flags.biff, TRUE, SET_IN_GAME}, + { "mail", &flags.biff, TRUE, SET_IN_GAME }, #else - {"mail", (boolean *)0, TRUE, SET_IN_FILE}, + { "mail", (boolean *) 0, TRUE, SET_IN_FILE }, #endif - {"mention_walls", &iflags.mention_walls, FALSE, SET_IN_GAME}, - {"menucolors", &iflags.use_menu_color, FALSE, SET_IN_GAME}, - /* for menu debugging only*/ - {"menu_tab_sep", &iflags.menu_tab_sep, FALSE, SET_IN_GAME}, - {"menu_objsyms", &iflags.menu_head_objsym, FALSE, SET_IN_GAME}, - {"mouse_support", &iflags.wc_mouse_support, TRUE, DISP_IN_GAME}, /*WC*/ + { "mention_walls", &iflags.mention_walls, FALSE, SET_IN_GAME }, + { "menucolors", &iflags.use_menu_color, FALSE, SET_IN_GAME }, + /* for menu debugging only*/ + { "menu_tab_sep", &iflags.menu_tab_sep, FALSE, SET_IN_GAME }, + { "menu_objsyms", &iflags.menu_head_objsym, FALSE, SET_IN_GAME }, + { "mouse_support", &iflags.wc_mouse_support, TRUE, DISP_IN_GAME }, /*WC*/ #ifdef NEWS - {"news", &iflags.news, TRUE, DISP_IN_GAME}, + { "news", &iflags.news, TRUE, DISP_IN_GAME }, #else - {"news", (boolean *)0, FALSE, SET_IN_FILE}, + { "news", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"nudist", &u.uroleplay.nudist, FALSE, DISP_IN_GAME}, - {"null", &flags.null, TRUE, SET_IN_GAME}, + { "nudist", &u.uroleplay.nudist, FALSE, DISP_IN_GAME }, + { "null", &flags.null, TRUE, SET_IN_GAME }, #if defined(SYSFLAGS) && defined(MAC) - {"page_wait", &sysflags.page_wait, TRUE, SET_IN_GAME}, + { "page_wait", &sysflags.page_wait, TRUE, SET_IN_GAME }, #else - {"page_wait", (boolean *)0, FALSE, SET_IN_FILE}, + { "page_wait", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"perm_invent", &flags.perm_invent, FALSE, SET_IN_GAME}, - {"pickup_thrown", &flags.pickup_thrown, TRUE, SET_IN_GAME}, - {"popup_dialog", &iflags.wc_popup_dialog, FALSE, SET_IN_GAME}, /*WC*/ - {"preload_tiles", &iflags.wc_preload_tiles, TRUE, DISP_IN_GAME}, /*WC*/ - {"pushweapon", &flags.pushweapon, FALSE, SET_IN_GAME}, + { "perm_invent", &flags.perm_invent, FALSE, SET_IN_GAME }, + { "pickup_thrown", &flags.pickup_thrown, TRUE, SET_IN_GAME }, + { "popup_dialog", &iflags.wc_popup_dialog, FALSE, SET_IN_GAME }, /*WC*/ + { "preload_tiles", &iflags.wc_preload_tiles, TRUE, DISP_IN_GAME }, /*WC*/ + { "pushweapon", &flags.pushweapon, FALSE, SET_IN_GAME }, #if defined(MICRO) && !defined(AMIGA) - {"rawio", &iflags.rawio, FALSE, DISP_IN_GAME}, + { "rawio", &iflags.rawio, FALSE, DISP_IN_GAME }, #else - {"rawio", (boolean *)0, FALSE, SET_IN_FILE}, + { "rawio", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"rest_on_space", &flags.rest_on_space, FALSE, SET_IN_GAME}, + { "rest_on_space", &flags.rest_on_space, FALSE, SET_IN_GAME }, #ifdef RLECOMP - {"rlecomp", &iflags.rlecomp, -# if defined(COMPRESS) || defined(ZLIB_COMP) - FALSE, -# else - TRUE, -# endif - DISP_IN_GAME}, + { "rlecomp", &iflags.rlecomp, +#if defined(COMPRESS) || defined(ZLIB_COMP) + FALSE, +#else + TRUE, #endif - {"safe_pet", &flags.safe_dog, TRUE, SET_IN_GAME}, - {"sanity_check", &iflags.sanity_check, FALSE, SET_IN_GAME}, - {"selectsaved", &iflags.wc2_selectsaved, TRUE, DISP_IN_GAME}, /*WC*/ - {"showexp", &flags.showexp, FALSE, SET_IN_GAME}, - {"showrace", &flags.showrace, FALSE, SET_IN_GAME}, + DISP_IN_GAME }, +#endif + { "safe_pet", &flags.safe_dog, TRUE, SET_IN_GAME }, + { "sanity_check", &iflags.sanity_check, FALSE, SET_IN_GAME }, + { "selectsaved", &iflags.wc2_selectsaved, TRUE, DISP_IN_GAME }, /*WC*/ + { "showexp", &flags.showexp, FALSE, SET_IN_GAME }, + { "showrace", &flags.showrace, FALSE, SET_IN_GAME }, #ifdef SCORE_ON_BOTL - {"showscore", &flags.showscore, FALSE, SET_IN_GAME}, + { "showscore", &flags.showscore, FALSE, SET_IN_GAME }, #else - {"showscore", (boolean *)0, FALSE, SET_IN_FILE}, + { "showscore", (boolean *) 0, FALSE, SET_IN_FILE }, #endif - {"silent", &flags.silent, TRUE, SET_IN_GAME}, - {"softkeyboard", &iflags.wc2_softkeyboard, FALSE, SET_IN_FILE}, - {"sortpack", &flags.sortpack, TRUE, SET_IN_GAME}, - {"sparkle", &flags.sparkle, TRUE, SET_IN_GAME}, - {"splash_screen", &iflags.wc_splash_screen, TRUE, DISP_IN_GAME}, /*WC*/ - {"standout", &flags.standout, FALSE, SET_IN_GAME}, - {"tiled_map", &iflags.wc_tiled_map, PREFER_TILED, DISP_IN_GAME}, /*WC*/ - {"time", &flags.time, FALSE, SET_IN_GAME}, + { "silent", &flags.silent, TRUE, SET_IN_GAME }, + { "softkeyboard", &iflags.wc2_softkeyboard, FALSE, SET_IN_FILE }, + { "sortpack", &flags.sortpack, TRUE, SET_IN_GAME }, + { "sparkle", &flags.sparkle, TRUE, SET_IN_GAME }, + { "splash_screen", &iflags.wc_splash_screen, TRUE, DISP_IN_GAME }, /*WC*/ + { "standout", &flags.standout, FALSE, SET_IN_GAME }, + { "tiled_map", &iflags.wc_tiled_map, PREFER_TILED, DISP_IN_GAME }, /*WC*/ + { "time", &flags.time, FALSE, SET_IN_GAME }, #ifdef TIMED_DELAY - {"timed_delay", &flags.nap, TRUE, SET_IN_GAME}, + { "timed_delay", &flags.nap, TRUE, SET_IN_GAME }, #else - {"timed_delay", (boolean *)0, FALSE, SET_IN_GAME}, + { "timed_delay", (boolean *) 0, FALSE, SET_IN_GAME }, #endif - {"tombstone",&flags.tombstone, TRUE, SET_IN_GAME}, - {"toptenwin",&iflags.toptenwin, FALSE, SET_IN_GAME}, - {"travel", &flags.travelcmd, TRUE, SET_IN_GAME}, - {"use_darkgray", &iflags.wc2_darkgray, TRUE, SET_IN_FILE}, + { "tombstone", &flags.tombstone, TRUE, SET_IN_GAME }, + { "toptenwin", &iflags.toptenwin, FALSE, SET_IN_GAME }, + { "travel", &flags.travelcmd, TRUE, SET_IN_GAME }, + { "use_darkgray", &iflags.wc2_darkgray, TRUE, SET_IN_FILE }, #ifdef WIN32 - {"use_inverse", &iflags.wc_inverse, TRUE, SET_IN_GAME}, /*WC*/ + { "use_inverse", &iflags.wc_inverse, TRUE, SET_IN_GAME }, /*WC*/ #else - {"use_inverse", &iflags.wc_inverse, FALSE, SET_IN_GAME}, /*WC*/ + { "use_inverse", &iflags.wc_inverse, FALSE, SET_IN_GAME }, /*WC*/ #endif - {"verbose", &flags.verbose, TRUE, SET_IN_GAME}, - {"wraptext", &iflags.wc2_wraptext, FALSE, SET_IN_GAME}, + { "verbose", &flags.verbose, TRUE, SET_IN_GAME }, + { "wraptext", &iflags.wc2_wraptext, FALSE, SET_IN_GAME }, #ifdef ZEROCOMP - {"zerocomp", &iflags.zerocomp, -# if defined(COMPRESS) || defined(ZLIB_COMP) - FALSE, -# else - TRUE, -# endif - DISP_IN_GAME}, + { "zerocomp", &iflags.zerocomp, +#if defined(COMPRESS) || defined(ZLIB_COMP) + FALSE, +#else + TRUE, #endif - {(char *)0, (boolean *)0, FALSE, 0} + DISP_IN_GAME }, +#endif + { (char *) 0, (boolean *) 0, FALSE, 0 } }; /* compound options, for option_help() and external programs like Amiga * frontend */ -static struct Comp_Opt -{ - const char *name, *descr; - int size; /* for frontends and such allocating space -- - * usually allowed size of data in game, but - * occasionally maximum reasonable size for - * typing when game maintains information in - * a different format */ - int optflags; +static struct Comp_Opt { + const char *name, *descr; + int size; /* for frontends and such allocating space -- + * usually allowed size of data in game, but + * occasionally maximum reasonable size for + * typing when game maintains information in + * a different format */ + int optflags; } compopt[] = { - { "align", "your starting alignment (lawful, neutral, or chaotic)", - 8, DISP_IN_GAME }, - { "align_message", "message window alignment", 20, DISP_IN_GAME }, /*WC*/ - { "align_status", "status window alignment", 20, DISP_IN_GAME }, /*WC*/ - { "altkeyhandler", "alternate key handler", 20, DISP_IN_GAME }, + { "align", "your starting alignment (lawful, neutral, or chaotic)", 8, + DISP_IN_GAME }, + { "align_message", "message window alignment", 20, DISP_IN_GAME }, /*WC*/ + { "align_status", "status window alignment", 20, DISP_IN_GAME }, /*WC*/ + { "altkeyhandler", "alternate key handler", 20, DISP_IN_GAME }, #ifdef BACKWARD_COMPAT - { "boulder", "deprecated (use S_boulder in sym file instead)", - 1, SET_IN_FILE }, + { "boulder", "deprecated (use S_boulder in sym file instead)", 1, + SET_IN_FILE }, #endif - { "catname", "the name of your (first) cat (e.g., catname:Tabby)", - PL_PSIZ, DISP_IN_GAME }, - { "disclose", "the kinds of information to disclose at end of game", - sizeof(flags.end_disclose) * 2, - SET_IN_GAME }, - { "dogname", "the name of your (first) dog (e.g., dogname:Fang)", - PL_PSIZ, DISP_IN_GAME }, - { "dungeon", "the symbols to use in drawing the dungeon map", - MAXDCHARS+1, SET_IN_FILE }, - { "effects", "the symbols to use in drawing special effects", - MAXECHARS+1, SET_IN_FILE }, - { "font_map", "the font to use in the map window", 40, DISP_IN_GAME }, /*WC*/ - { "font_menu", "the font to use in menus", 40, DISP_IN_GAME }, /*WC*/ - { "font_message", "the font to use in the message window", - 40, DISP_IN_GAME }, /*WC*/ - { "font_size_map", "the size of the map font", 20, DISP_IN_GAME }, /*WC*/ - { "font_size_menu", "the size of the menu font", 20, DISP_IN_GAME }, /*WC*/ - { "font_size_message", "the size of the message font", 20, DISP_IN_GAME }, /*WC*/ - { "font_size_status", "the size of the status font", 20, DISP_IN_GAME }, /*WC*/ - { "font_size_text", "the size of the text font", 20, DISP_IN_GAME }, /*WC*/ - { "font_status", "the font to use in status window", 40, DISP_IN_GAME }, /*WC*/ - { "font_text", "the font to use in text windows", 40, DISP_IN_GAME }, /*WC*/ - { "fruit", "the name of a fruit you enjoy eating", - PL_FSIZ, SET_IN_GAME }, - { "gender", "your starting gender (male or female)", - 8, DISP_IN_GAME }, - { "horsename", "the name of your (first) horse (e.g., horsename:Silver)", - PL_PSIZ, DISP_IN_GAME }, - { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/ - { "menustyle", "user interface for object selection", - MENUTYPELEN, SET_IN_GAME }, - { "menu_deselect_all", "deselect all items in a menu", 4, SET_IN_FILE }, - { "menu_deselect_page", "deselect all items on this page of a menu", - 4, SET_IN_FILE }, - { "menu_first_page", "jump to the first page in a menu", - 4, SET_IN_FILE }, - { "menu_headings", "text attribute for menu headings", 9, SET_IN_GAME }, - { "menu_invert_all", "invert all items in a menu", 4, SET_IN_FILE }, - { "menu_invert_page", "invert all items on this page of a menu", - 4, SET_IN_FILE }, - { "menu_last_page", "jump to the last page in a menu", 4, SET_IN_FILE }, - { "menu_next_page", "goto the next menu page", 4, SET_IN_FILE }, - { "menu_previous_page", "goto the previous menu page", 4, SET_IN_FILE }, - { "menu_search", "search for a menu item", 4, SET_IN_FILE }, - { "menu_select_all", "select all items in a menu", 4, SET_IN_FILE }, - { "menu_select_page", "select all items on this page of a menu", - 4, SET_IN_FILE }, - { "monsters", "the symbols to use for monsters", - MAXMCLASSES, SET_IN_FILE }, - { "msghistory", "number of top line messages to save", - 5, DISP_IN_GAME }, -# ifdef TTY_GRAPHICS - {"msg_window", "the type of message window required",1, SET_IN_GAME}, -# else - {"msg_window", "the type of message window required", 1, SET_IN_FILE}, -# endif - { "name", "your character's name (e.g., name:Merlin-W)", - PL_NSIZ, DISP_IN_GAME }, - { "number_pad", "use the number pad for movement", 1, SET_IN_GAME}, - { "objects", "the symbols to use for objects", - MAXOCLASSES, SET_IN_FILE }, - { "packorder", "the inventory order of the items in your pack", - MAXOCLASSES, SET_IN_GAME }, + { "catname", "the name of your (first) cat (e.g., catname:Tabby)", + PL_PSIZ, DISP_IN_GAME }, + { "disclose", "the kinds of information to disclose at end of game", + sizeof(flags.end_disclose) * 2, SET_IN_GAME }, + { "dogname", "the name of your (first) dog (e.g., dogname:Fang)", PL_PSIZ, + DISP_IN_GAME }, + { "dungeon", "the symbols to use in drawing the dungeon map", + MAXDCHARS + 1, SET_IN_FILE }, + { "effects", "the symbols to use in drawing special effects", + MAXECHARS + 1, SET_IN_FILE }, + { "font_map", "the font to use in the map window", 40, + DISP_IN_GAME }, /*WC*/ + { "font_menu", "the font to use in menus", 40, DISP_IN_GAME }, /*WC*/ + { "font_message", "the font to use in the message window", 40, + DISP_IN_GAME }, /*WC*/ + { "font_size_map", "the size of the map font", 20, DISP_IN_GAME }, /*WC*/ + { "font_size_menu", "the size of the menu font", 20, + DISP_IN_GAME }, /*WC*/ + { "font_size_message", "the size of the message font", 20, + DISP_IN_GAME }, /*WC*/ + { "font_size_status", "the size of the status font", 20, + DISP_IN_GAME }, /*WC*/ + { "font_size_text", "the size of the text font", 20, + DISP_IN_GAME }, /*WC*/ + { "font_status", "the font to use in status window", 40, + DISP_IN_GAME }, /*WC*/ + { "font_text", "the font to use in text windows", 40, + DISP_IN_GAME }, /*WC*/ + { "fruit", "the name of a fruit you enjoy eating", PL_FSIZ, SET_IN_GAME }, + { "gender", "your starting gender (male or female)", 8, DISP_IN_GAME }, + { "horsename", "the name of your (first) horse (e.g., horsename:Silver)", + PL_PSIZ, DISP_IN_GAME }, + { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/ + { "menustyle", "user interface for object selection", MENUTYPELEN, + SET_IN_GAME }, + { "menu_deselect_all", "deselect all items in a menu", 4, SET_IN_FILE }, + { "menu_deselect_page", "deselect all items on this page of a menu", 4, + SET_IN_FILE }, + { "menu_first_page", "jump to the first page in a menu", 4, SET_IN_FILE }, + { "menu_headings", "text attribute for menu headings", 9, SET_IN_GAME }, + { "menu_invert_all", "invert all items in a menu", 4, SET_IN_FILE }, + { "menu_invert_page", "invert all items on this page of a menu", 4, + SET_IN_FILE }, + { "menu_last_page", "jump to the last page in a menu", 4, SET_IN_FILE }, + { "menu_next_page", "goto the next menu page", 4, SET_IN_FILE }, + { "menu_previous_page", "goto the previous menu page", 4, SET_IN_FILE }, + { "menu_search", "search for a menu item", 4, SET_IN_FILE }, + { "menu_select_all", "select all items in a menu", 4, SET_IN_FILE }, + { "menu_select_page", "select all items on this page of a menu", 4, + SET_IN_FILE }, + { "monsters", "the symbols to use for monsters", MAXMCLASSES, + SET_IN_FILE }, + { "msghistory", "number of top line messages to save", 5, DISP_IN_GAME }, +#ifdef TTY_GRAPHICS + { "msg_window", "the type of message window required", 1, SET_IN_GAME }, +#else + { "msg_window", "the type of message window required", 1, SET_IN_FILE }, +#endif + { "name", "your character's name (e.g., name:Merlin-W)", PL_NSIZ, + DISP_IN_GAME }, + { "number_pad", "use the number pad for movement", 1, SET_IN_GAME }, + { "objects", "the symbols to use for objects", MAXOCLASSES, SET_IN_FILE }, + { "packorder", "the inventory order of the items in your pack", + MAXOCLASSES, SET_IN_GAME }, #ifdef CHANGE_COLOR - { "palette", -# ifndef WIN32 - "palette (00c/880/-fff is blue/yellow/reverse white)", - 15 , SET_IN_GAME }, -# else - "palette (adjust an RGB color in palette (color-R-G-B)", - 15 , SET_IN_FILE }, -# endif -# if defined(MAC) - { "hicolor", "same as palette, only order is reversed", - 15, SET_IN_FILE }, -# endif + { "palette", +#ifndef WIN32 + "palette (00c/880/-fff is blue/yellow/reverse white)", 15, + SET_IN_GAME }, +#else + "palette (adjust an RGB color in palette (color-R-G-B)", 15, + SET_IN_FILE }, #endif - { "paranoid_confirmation", "extra prompting in certain situations", - 28, SET_IN_GAME }, - { "pettype", "your preferred initial pet type", 4, DISP_IN_GAME }, - { "pickup_burden", "maximum burden picked up before prompt", - 20, SET_IN_GAME }, - { "pickup_types", "types of objects to pick up automatically", - MAXOCLASSES, SET_IN_GAME }, - { "pile_limit", "threshold for \"there are many objects here\"", - 24, SET_IN_GAME }, - { "playmode", "normal play, non-scoring explore mode, or debug mode", - 8, DISP_IN_GAME }, - { "player_selection", "choose character via dialog or prompts", - 12, DISP_IN_GAME }, - { "race", "your starting race (e.g., Human, Elf)", - PL_CSIZ, DISP_IN_GAME }, - { "role", "your starting role (e.g., Barbarian, Valkyrie)", - PL_CSIZ, DISP_IN_GAME }, - { "runmode", "display frequency when `running' or `travelling'", - sizeof "teleport", SET_IN_GAME }, - { "scores", "the parts of the score list you wish to see", - 32, SET_IN_GAME }, - { "scroll_amount", "amount to scroll map when scroll_margin is reached", - 20, DISP_IN_GAME }, /*WC*/ - { "scroll_margin", "scroll map when this far from the edge", 20, DISP_IN_GAME }, /*WC*/ - { "sortloot", "sort object selection lists by description", 4, SET_IN_GAME }, -#ifdef MSDOS - { "soundcard", "type of sound card to use", 20, SET_IN_FILE }, +#if defined(MAC) + { "hicolor", "same as palette, only order is reversed", 15, SET_IN_FILE }, #endif - { "symset", "load a set of display symbols from the symbols file", 70, - SET_IN_GAME }, - { "roguesymset", "load a set of rogue display symbols from the symbols file", 70, - SET_IN_GAME }, - { "suppress_alert", "suppress alerts about version-specific features", - 8, SET_IN_GAME }, - { "tile_width", "width of tiles", 20, DISP_IN_GAME}, /*WC*/ - { "tile_height", "height of tiles", 20, DISP_IN_GAME}, /*WC*/ - { "tile_file", "name of tile file", 70, DISP_IN_GAME}, /*WC*/ - { "traps", "the symbols to use in drawing traps", - MAXTCHARS+1, SET_IN_FILE }, - { "vary_msgcount", "show more old messages at a time", 20, DISP_IN_GAME }, /*WC*/ +#endif + { "paranoid_confirmation", "extra prompting in certain situations", 28, + SET_IN_GAME }, + { "pettype", "your preferred initial pet type", 4, DISP_IN_GAME }, + { "pickup_burden", "maximum burden picked up before prompt", 20, + SET_IN_GAME }, + { "pickup_types", "types of objects to pick up automatically", + MAXOCLASSES, SET_IN_GAME }, + { "pile_limit", "threshold for \"there are many objects here\"", 24, + SET_IN_GAME }, + { "playmode", "normal play, non-scoring explore mode, or debug mode", 8, + DISP_IN_GAME }, + { "player_selection", "choose character via dialog or prompts", 12, + DISP_IN_GAME }, + { "race", "your starting race (e.g., Human, Elf)", PL_CSIZ, + DISP_IN_GAME }, + { "role", "your starting role (e.g., Barbarian, Valkyrie)", PL_CSIZ, + DISP_IN_GAME }, + { "runmode", "display frequency when `running' or `travelling'", + sizeof "teleport", SET_IN_GAME }, + { "scores", "the parts of the score list you wish to see", 32, + SET_IN_GAME }, + { "scroll_amount", "amount to scroll map when scroll_margin is reached", + 20, DISP_IN_GAME }, /*WC*/ + { "scroll_margin", "scroll map when this far from the edge", 20, + DISP_IN_GAME }, /*WC*/ + { "sortloot", "sort object selection lists by description", 4, + SET_IN_GAME }, #ifdef MSDOS - { "video", "method of video updating", 20, SET_IN_FILE }, + { "soundcard", "type of sound card to use", 20, SET_IN_FILE }, +#endif + { "symset", "load a set of display symbols from the symbols file", 70, + SET_IN_GAME }, + { "roguesymset", + "load a set of rogue display symbols from the symbols file", 70, + SET_IN_GAME }, + { "suppress_alert", "suppress alerts about version-specific features", 8, + SET_IN_GAME }, + { "tile_width", "width of tiles", 20, DISP_IN_GAME }, /*WC*/ + { "tile_height", "height of tiles", 20, DISP_IN_GAME }, /*WC*/ + { "tile_file", "name of tile file", 70, DISP_IN_GAME }, /*WC*/ + { "traps", "the symbols to use in drawing traps", MAXTCHARS + 1, + SET_IN_FILE }, + { "vary_msgcount", "show more old messages at a time", 20, + DISP_IN_GAME }, /*WC*/ +#ifdef MSDOS + { "video", "method of video updating", 20, SET_IN_FILE }, #endif #ifdef VIDEOSHADES - { "videocolors", "color mappings for internal screen routines", - 40, DISP_IN_GAME }, - { "videoshades", "gray shades to map to black/gray/white", - 32, DISP_IN_GAME }, + { "videocolors", "color mappings for internal screen routines", 40, + DISP_IN_GAME }, + { "videoshades", "gray shades to map to black/gray/white", 32, + DISP_IN_GAME }, #endif #ifdef WIN32 - {"subkeyvalue", "override keystroke value", 7, SET_IN_FILE}, + { "subkeyvalue", "override keystroke value", 7, SET_IN_FILE }, #endif - { "windowcolors", "the foreground/background colors of windows", /*WC*/ - 80, DISP_IN_GAME }, - { "windowtype", "windowing system to use", WINTYPELEN, DISP_IN_GAME }, + { "windowcolors", "the foreground/background colors of windows", /*WC*/ + 80, DISP_IN_GAME }, + { "windowtype", "windowing system to use", WINTYPELEN, DISP_IN_GAME }, #ifdef WINCHAIN - { "windowchain", "window processor to use", WINTYPELEN, SET_IN_SYS }, + { "windowchain", "window processor to use", WINTYPELEN, SET_IN_SYS }, #endif #ifdef BACKWARD_COMPAT - {"DECgraphics", "load DECGraphics display symbols", 70, SET_IN_FILE}, - {"IBMgraphics", "load IBMGraphics display symbols", 70, SET_IN_FILE}, -# ifdef MAC_GRAPHICS_ENV - {"Macgraphics", "load MACGraphics display symbols", 70, SET_IN_FILE}, -# endif + { "DECgraphics", "load DECGraphics display symbols", 70, SET_IN_FILE }, + { "IBMgraphics", "load IBMGraphics display symbols", 70, SET_IN_FILE }, +#ifdef MAC_GRAPHICS_ENV + { "Macgraphics", "load MACGraphics display symbols", 70, SET_IN_FILE }, #endif - { (char *)0, (char *)0, 0, 0 } +#endif + { (char *) 0, (char *) 0, 0, 0 } }; #ifdef OPTION_LISTS_ONLY #undef static -#else /* use rest of file */ +#else /* use rest of file */ extern struct symparse loadsyms[]; static boolean need_redraw; /* for doset() */ #if defined(TOS) && defined(TEXTCOLOR) -extern boolean colors_changed; /* in tos.c */ +extern boolean colors_changed; /* in tos.c */ #endif #ifdef VIDEOSHADES -extern char *shade[3]; /* in sys/msdos/video.c */ -extern char ttycolors[CLR_MAX]; /* in sys/msdos/video.c */ +extern char *shade[3]; /* in sys/msdos/video.c */ +extern char ttycolors[CLR_MAX]; /* in sys/msdos/video.c */ #endif static char def_inv_order[MAXOCLASSES] = { - COIN_CLASS, AMULET_CLASS, WEAPON_CLASS, ARMOR_CLASS, FOOD_CLASS, - SCROLL_CLASS, SPBOOK_CLASS, POTION_CLASS, RING_CLASS, WAND_CLASS, - TOOL_CLASS, GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0, + COIN_CLASS, AMULET_CLASS, WEAPON_CLASS, ARMOR_CLASS, FOOD_CLASS, + SCROLL_CLASS, SPBOOK_CLASS, POTION_CLASS, RING_CLASS, WAND_CLASS, + TOOL_CLASS, GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0, }; /* @@ -448,45 +451,45 @@ typedef struct { #define NUM_MENU_CMDS 11 static const menu_cmd_t default_menu_cmd_info[NUM_MENU_CMDS] = { -/* 0*/ { "menu_first_page", MENU_FIRST_PAGE }, - { "menu_last_page", MENU_LAST_PAGE }, - { "menu_next_page", MENU_NEXT_PAGE }, - { "menu_previous_page", MENU_PREVIOUS_PAGE }, - { "menu_select_all", MENU_SELECT_ALL }, -/* 5*/ { "menu_deselect_all", MENU_UNSELECT_ALL }, - { "menu_invert_all", MENU_INVERT_ALL }, - { "menu_select_page", MENU_SELECT_PAGE }, - { "menu_deselect_page", MENU_UNSELECT_PAGE }, - { "menu_invert_page", MENU_INVERT_PAGE }, -/*10*/ { "menu_search", MENU_SEARCH }, + /* 0*/ { "menu_first_page", MENU_FIRST_PAGE }, + { "menu_last_page", MENU_LAST_PAGE }, + { "menu_next_page", MENU_NEXT_PAGE }, + { "menu_previous_page", MENU_PREVIOUS_PAGE }, + { "menu_select_all", MENU_SELECT_ALL }, + /* 5*/ { "menu_deselect_all", MENU_UNSELECT_ALL }, + { "menu_invert_all", MENU_INVERT_ALL }, + { "menu_select_page", MENU_SELECT_PAGE }, + { "menu_deselect_page", MENU_UNSELECT_PAGE }, + { "menu_invert_page", MENU_INVERT_PAGE }, + /*10*/ { "menu_search", MENU_SEARCH }, }; /* * Allow the user to map incoming characters to various menu commands. * The accelerator list must be a valid C string. */ -#define MAX_MENU_MAPPED_CMDS 32 /* some number */ - char mapped_menu_cmds[MAX_MENU_MAPPED_CMDS+1]; /* exported */ -static char mapped_menu_op[MAX_MENU_MAPPED_CMDS+1]; +#define MAX_MENU_MAPPED_CMDS 32 /* some number */ +char mapped_menu_cmds[MAX_MENU_MAPPED_CMDS + 1]; /* exported */ +static char mapped_menu_op[MAX_MENU_MAPPED_CMDS + 1]; static short n_menu_mapped = 0; - static boolean initial, from_file; -STATIC_DCL void FDECL(doset_add_menu, (winid,const char *,int)); +STATIC_DCL void FDECL(doset_add_menu, (winid, const char *, int)); STATIC_DCL void FDECL(nmcpy, (char *, const char *, int)); STATIC_DCL void FDECL(escapes, (const char *, char *)); STATIC_DCL void FDECL(rejectoption, (const char *)); STATIC_DCL void FDECL(badoption, (const char *)); -STATIC_DCL char *FDECL(string_for_opt, (char *,BOOLEAN_P)); -STATIC_DCL char *FDECL(string_for_env_opt, (const char *, char *,BOOLEAN_P)); -STATIC_DCL void FDECL(bad_negation, (const char *,BOOLEAN_P)); +STATIC_DCL char *FDECL(string_for_opt, (char *, BOOLEAN_P)); +STATIC_DCL char *FDECL(string_for_env_opt, (const char *, char *, BOOLEAN_P)); +STATIC_DCL void FDECL(bad_negation, (const char *, BOOLEAN_P)); STATIC_DCL int FDECL(change_inv_order, (char *)); STATIC_DCL void FDECL(oc_to_str, (char *, char *)); STATIC_DCL int FDECL(feature_alert_opts, (char *, const char *)); STATIC_DCL const char *FDECL(get_compopt_value, (const char *, char *)); -STATIC_DCL boolean FDECL(special_handling, (const char *, BOOLEAN_P, BOOLEAN_P)); -STATIC_DCL void FDECL(warning_opts, (char *,const char *)); +STATIC_DCL boolean +FDECL(special_handling, (const char *, BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL void FDECL(warning_opts, (char *, const char *)); STATIC_DCL boolean FDECL(duplicate_opt_detection, (const char *, int)); STATIC_DCL void FDECL(complain_about_duplicate, (const char *, int)); @@ -496,7 +499,8 @@ STATIC_OVL boolean FDECL(is_wc_option, (const char *)); STATIC_OVL boolean FDECL(wc_supported, (const char *)); STATIC_OVL boolean FDECL(is_wc2_option, (const char *)); STATIC_OVL boolean FDECL(wc2_supported, (const char *)); -STATIC_DCL void FDECL(remove_autopickup_exception, (struct autopickup_exception *)); +STATIC_DCL void FDECL(remove_autopickup_exception, + (struct autopickup_exception *)); STATIC_OVL int FDECL(count_ape_maps, (int *, int *)); STATIC_DCL const char *FDECL(clr2colorname, (int)); STATIC_DCL const char *FDECL(attr2attrname, (int)); @@ -506,33 +510,30 @@ STATIC_DCL boolean FDECL(add_menu_coloring_parsed, (char *, int, int)); STATIC_DCL void FDECL(free_one_menu_coloring, (int)); STATIC_DCL int NDECL(count_menucolors); - void reglyph_darkroom() { - xchar x,y; + xchar x, y; for (x = 0; x < COLNO; x++) for (y = 0; y < ROWNO; y++) { - struct rm *lev = &levl[x][y]; - if (!flags.dark_room) { - if (lev->glyph == cmap_to_glyph(S_darkroom)) - lev->glyph = lev->waslit ? cmap_to_glyph(S_room) : cmap_to_glyph(S_stone); - } else { - if (lev->glyph == cmap_to_glyph(S_room) && - lev->seenv && - lev->waslit && !cansee(x,y)) - lev->glyph = cmap_to_glyph(S_darkroom); - else if (lev->glyph == cmap_to_glyph(S_stone) && - lev->typ == ROOM && - lev->seenv && - !cansee(x,y)) - lev->glyph = cmap_to_glyph(S_darkroom); - } - } + struct rm *lev = &levl[x][y]; + if (!flags.dark_room) { + if (lev->glyph == cmap_to_glyph(S_darkroom)) + lev->glyph = lev->waslit ? cmap_to_glyph(S_room) + : cmap_to_glyph(S_stone); + } else { + if (lev->glyph == cmap_to_glyph(S_room) && lev->seenv + && lev->waslit && !cansee(x, y)) + lev->glyph = cmap_to_glyph(S_darkroom); + else if (lev->glyph == cmap_to_glyph(S_stone) + && lev->typ == ROOM && lev->seenv && !cansee(x, y)) + lev->glyph = cmap_to_glyph(S_darkroom); + } + } if (flags.dark_room && iflags.use_color) - showsyms[S_darkroom]=showsyms[S_room]; + showsyms[S_darkroom] = showsyms[S_room]; else - showsyms[S_darkroom]=showsyms[S_stone]; + showsyms[S_darkroom] = showsyms[S_stone]; } /* check whether a user-supplied option string is a proper leading @@ -544,18 +545,20 @@ const char *user_string, *opt_name; int min_length; boolean val_allowed; { - int len = (int)strlen(user_string); + int len = (int) strlen(user_string); - if (val_allowed) { - const char *p = index(user_string, ':'), - *q = index(user_string, '='); + if (val_allowed) { + const char *p = index(user_string, ':'), *q = index(user_string, '='); - if (!p || (q && q < p)) p = q; - while (p && p > user_string && isspace((uchar)*(p-1))) p--; - if (p) len = (int)(p - user_string); - } + if (!p || (q && q < p)) + p = q; + while (p && p > user_string && isspace((uchar) * (p - 1))) + p--; + if (p) + len = (int) (p - user_string); + } - return (len >= min_length) && !strncmpi(opt_name, user_string, len); + return (len >= min_length) && !strncmpi(opt_name, user_string, len); } /* most environment variables will eventually be printed in an error @@ -569,201 +572,208 @@ char * nh_getenv(ev) const char *ev; { - char *getev = getenv(ev); + char *getev = getenv(ev); - if (getev && strlen(getev) <= (BUFSZ / 2)) - return getev; - else - return (char *)0; + if (getev && strlen(getev) <= (BUFSZ / 2)) + return getev; + else + return (char *) 0; } /* process options, possibly including SYSCF */ void initoptions() { - initoptions_init(); + initoptions_init(); #ifdef SYSCF - /* someday there may be other SYSCF alternatives besides text file */ -# ifdef SYSCF_FILE - /* If SYSCF_FILE is specified, it _must_ exist... */ - assure_syscf_file(); - /* ... and _must_ parse correctly. */ - if(!read_config_file(SYSCF_FILE, SET_IN_SYS)){ - raw_printf("Error(s) found in SYSCF_FILE, quitting."); - terminate(EXIT_FAILURE); - } -# endif +/* someday there may be other SYSCF alternatives besides text file */ +#ifdef SYSCF_FILE + /* If SYSCF_FILE is specified, it _must_ exist... */ + assure_syscf_file(); + /* ... and _must_ parse correctly. */ + if (!read_config_file(SYSCF_FILE, SET_IN_SYS)) { + raw_printf("Error(s) found in SYSCF_FILE, quitting."); + terminate(EXIT_FAILURE); + } #endif - initoptions_finish(); +#endif + initoptions_finish(); } void initoptions_init() { #if defined(UNIX) || defined(VMS) - char *opts; + char *opts; #endif - int i; + int i; - /* set up the command parsing */ - reset_commands(TRUE); /* init */ + /* set up the command parsing */ + reset_commands(TRUE); /* init */ - /* initialize the random number generator */ - setrandom(); + /* initialize the random number generator */ + setrandom(); - /* for detection of configfile options specified multiple times */ - iflags.opt_booldup = iflags.opt_compdup = (int *)0; + /* for detection of configfile options specified multiple times */ + iflags.opt_booldup = iflags.opt_compdup = (int *) 0; - for (i = 0; boolopt[i].name; i++) { - if (boolopt[i].addr) - *(boolopt[i].addr) = boolopt[i].initvalue; - } + for (i = 0; boolopt[i].name; i++) { + if (boolopt[i].addr) + *(boolopt[i].addr) = boolopt[i].initvalue; + } #if defined(COMPRESS) || defined(ZLIB_COMP) - set_savepref("externalcomp"); - set_restpref("externalcomp"); -# ifdef RLECOMP - set_savepref("!rlecomp"); - set_restpref("!rlecomp"); -# endif + set_savepref("externalcomp"); + set_restpref("externalcomp"); +#ifdef RLECOMP + set_savepref("!rlecomp"); + set_restpref("!rlecomp"); +#endif #else -# ifdef ZEROCOMP - set_savepref("zerocomp"); - set_restpref("zerocomp"); -# endif -# ifdef RLECOMP - set_savepref("rlecomp"); - set_restpref("rlecomp"); -# endif +#ifdef ZEROCOMP + set_savepref("zerocomp"); + set_restpref("zerocomp"); +#endif +#ifdef RLECOMP + set_savepref("rlecomp"); + set_restpref("rlecomp"); +#endif #endif #ifdef SYSFLAGS - Strcpy(sysflags.sysflagsid, "sysflags"); - sysflags.sysflagsid[9] = (char)sizeof(struct sysflag); + Strcpy(sysflags.sysflagsid, "sysflags"); + sysflags.sysflagsid[9] = (char) sizeof(struct sysflag); #endif - flags.end_own = FALSE; - flags.end_top = 3; - flags.end_around = 2; - flags.paranoia_bits = PARANOID_PRAY; /* old prayconfirm=TRUE */ - flags.pile_limit = PILE_LIMIT_DFLT; /* 5 */ - flags.runmode = RUN_LEAP; - iflags.msg_history = 20; + flags.end_own = FALSE; + flags.end_top = 3; + flags.end_around = 2; + flags.paranoia_bits = PARANOID_PRAY; /* old prayconfirm=TRUE */ + flags.pile_limit = PILE_LIMIT_DFLT; /* 5 */ + flags.runmode = RUN_LEAP; + iflags.msg_history = 20; #ifdef TTY_GRAPHICS - iflags.prevmsg_window = 's'; + iflags.prevmsg_window = 's'; #endif - iflags.menu_headings = ATR_INVERSE; + iflags.menu_headings = ATR_INVERSE; - /* hero's role, race, &c haven't been chosen yet */ - flags.initrole = flags.initrace = - flags.initgend = flags.initalign = ROLE_NONE; + /* hero's role, race, &c haven't been chosen yet */ + flags.initrole = flags.initrace = flags.initgend = flags.initalign = + ROLE_NONE; - /* Set the default monster and object class symbols. */ - init_symbols(); - for (i = 0; i < WARNCOUNT; i++) - warnsyms[i] = def_warnsyms[i].sym; - iflags.bouldersym = 0; + /* Set the default monster and object class symbols. */ + init_symbols(); + for (i = 0; i < WARNCOUNT; i++) + warnsyms[i] = def_warnsyms[i].sym; + iflags.bouldersym = 0; - iflags.travelcc.x = iflags.travelcc.y = -1; + iflags.travelcc.x = iflags.travelcc.y = -1; - /* assert( sizeof flags.inv_order == sizeof def_inv_order ); */ - (void)memcpy((genericptr_t)flags.inv_order, - (genericptr_t)def_inv_order, sizeof flags.inv_order); - flags.pickup_types[0] = '\0'; - flags.pickup_burden = MOD_ENCUMBER; - flags.sortloot = 'l'; /* sort only loot by default */ + /* assert( sizeof flags.inv_order == sizeof def_inv_order ); */ + (void) memcpy((genericptr_t) flags.inv_order, + (genericptr_t) def_inv_order, sizeof flags.inv_order); + flags.pickup_types[0] = '\0'; + flags.pickup_burden = MOD_ENCUMBER; + flags.sortloot = 'l'; /* sort only loot by default */ - for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) - flags.end_disclose[i] = DISCLOSE_PROMPT_DEFAULT_NO; - switch_symbols(FALSE); /* set default characters */ + for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) + flags.end_disclose[i] = DISCLOSE_PROMPT_DEFAULT_NO; + switch_symbols(FALSE); /* set default characters */ #if defined(UNIX) && defined(TTY_GRAPHICS) - /* - * Set defaults for some options depending on what we can - * detect about the environment's capabilities. - * This has to be done after the global initialization above - * and before reading user-specific initialization via - * config file/environment variable below. - */ - /* this detects the IBM-compatible console on most 386 boxes */ - if ((opts = nh_getenv("TERM")) && !strncmp(opts, "AT", 2)) { - if (!symset[PRIMARY].name) load_symset("IBMGraphics", PRIMARY); - if (!symset[ROGUESET].name) load_symset("RogueIBM", ROGUESET); - switch_symbols(TRUE); -# ifdef TEXTCOLOR - iflags.use_color = TRUE; -# endif - } + /* + * Set defaults for some options depending on what we can + * detect about the environment's capabilities. + * This has to be done after the global initialization above + * and before reading user-specific initialization via + * config file/environment variable below. + */ + /* this detects the IBM-compatible console on most 386 boxes */ + if ((opts = nh_getenv("TERM")) && !strncmp(opts, "AT", 2)) { + if (!symset[PRIMARY].name) + load_symset("IBMGraphics", PRIMARY); + if (!symset[ROGUESET].name) + load_symset("RogueIBM", ROGUESET); + switch_symbols(TRUE); +#ifdef TEXTCOLOR + iflags.use_color = TRUE; +#endif + } #endif /* UNIX && TTY_GRAPHICS */ #if defined(UNIX) || defined(VMS) -# ifdef TTY_GRAPHICS - /* detect whether a "vt" terminal can handle alternate charsets */ - if ((opts = nh_getenv("TERM")) && - !strncmpi(opts, "vt", 2) && AS && AE && - index(AS, '\016') && index(AE, '\017')) { - if (!symset[PRIMARY].name) load_symset("DECGraphics", PRIMARY); - switch_symbols(TRUE); - } -# endif +#ifdef TTY_GRAPHICS + /* detect whether a "vt" terminal can handle alternate charsets */ + if ((opts = nh_getenv("TERM")) && !strncmpi(opts, "vt", 2) && AS && AE + && index(AS, '\016') && index(AE, '\017')) { + if (!symset[PRIMARY].name) + load_symset("DECGraphics", PRIMARY); + switch_symbols(TRUE); + } +#endif #endif /* UNIX || VMS */ #ifdef MAC_GRAPHICS_ENV - if (!symset[PRIMARY].name) load_symset("MACGraphics", PRIMARY); - switch_symbols(TRUE); + if (!symset[PRIMARY].name) + load_symset("MACGraphics", PRIMARY); + switch_symbols(TRUE); #endif /* MAC_GRAPHICS_ENV */ - flags.menu_style = MENU_FULL; + flags.menu_style = MENU_FULL; - /* since this is done before init_objects(), do partial init here */ - objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD; - nmcpy(pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ); + /* since this is done before init_objects(), do partial init here */ + objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD; + nmcpy(pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ); } void initoptions_finish() { #ifndef MAC - char *opts = getenv("NETHACKOPTIONS"); - if (!opts) opts = getenv("HACKOPTIONS"); - if (opts) { - if (*opts == '/' || *opts == '\\' || *opts == '@') { - if (*opts == '@') opts++; /* @filename */ - /* looks like a filename */ - if (strlen(opts) < BUFSZ/2) - read_config_file(opts, SET_IN_FILE); - } else { - read_config_file((char *)0, SET_IN_FILE); - /* let the total length of options be long; - * parseoptions() will check each individually - */ - parseoptions(opts, TRUE, FALSE); - } - } else + char *opts = getenv("NETHACKOPTIONS"); + if (!opts) + opts = getenv("HACKOPTIONS"); + if (opts) { + if (*opts == '/' || *opts == '\\' || *opts == '@') { + if (*opts == '@') + opts++; /* @filename */ + /* looks like a filename */ + if (strlen(opts) < BUFSZ / 2) + read_config_file(opts, SET_IN_FILE); + } else { + read_config_file((char *) 0, SET_IN_FILE); + /* let the total length of options be long; + * parseoptions() will check each individually + */ + parseoptions(opts, TRUE, FALSE); + } + } else #endif - read_config_file((char *)0, SET_IN_FILE); + read_config_file((char *) 0, SET_IN_FILE); - (void)fruitadd(pl_fruit, (struct fruit *)0); - /* Remove "slime mold" from list of object names; this will */ - /* prevent it from being wished unless it's actually present */ - /* as a named (or default) fruit. Wishing for "fruit" will */ - /* result in the player's preferred fruit [better than "\033"]. */ - obj_descr[SLIME_MOLD].oc_name = "fruit"; + (void) fruitadd(pl_fruit, (struct fruit *) 0); + /* Remove "slime mold" from list of object names; this will */ + /* prevent it from being wished unless it's actually present */ + /* as a named (or default) fruit. Wishing for "fruit" will */ + /* result in the player's preferred fruit [better than "\033"]. */ + obj_descr[SLIME_MOLD].oc_name = "fruit"; - if (iflags.bouldersym) update_bouldersym(); + if (iflags.bouldersym) + update_bouldersym(); - reglyph_darkroom(); + reglyph_darkroom(); - return; + return; } STATIC_OVL void nmcpy(dest, src, maxlen) - char *dest; - const char *src; - int maxlen; +char *dest; +const char *src; +int maxlen; { - int count; + int count; - for(count = 1; count < maxlen; count++) { - if(*src == ',' || *src == '\0') break; /*exit on \0 terminator*/ - *dest++ = *src++; - } - *dest = 0; + for (count = 1; count < maxlen; count++) { + if (*src == ',' || *src == '\0') + break; /*exit on \0 terminator*/ + *dest++ = *src++; + } + *dest = 0; } /* @@ -784,61 +794,73 @@ nmcpy(dest, src, maxlen) */ STATIC_OVL void escapes(cp, tp) -const char *cp; +const char *cp; char *tp; { - static NEARDATA const char - oct[] = "01234567", dec[] = "0123456789", - hex[] = "00112233445566778899aAbBcCdDeEfF"; + static NEARDATA const char oct[] = "01234567", dec[] = "0123456789", + hex[] = "00112233445566778899aAbBcCdDeEfF"; const char *dp; int cval, meta, dcount; while (*cp) { - /* \M has to be followed by something to do meta conversion, - otherwise it will just be \M which ultimately yields 'M' */ - meta = (*cp == '\\' && (cp[1] == 'm' || cp[1] == 'M') && cp[2]); - if (meta) cp += 2; + /* \M has to be followed by something to do meta conversion, + otherwise it will just be \M which ultimately yields 'M' */ + meta = (*cp == '\\' && (cp[1] == 'm' || cp[1] == 'M') && cp[2]); + if (meta) + cp += 2; - cval = dcount = 0; /* for decimal, octal, hexadecimal cases */ - if ((*cp != '\\' && *cp != '^') || !cp[1]) { - /* simple character, or nothing left for \ or ^ to escape */ - cval = *cp++; - } else if (*cp == '^') { /* expand control-character syntax */ - cval = (*++cp & 0x1f); - ++cp; - /* remaining cases are all for backslash and we know cp[1] is not \0 */ - } else if (index(dec, cp[1])) { - ++cp; /* move past backslash to first digit */ - do { - cval = (cval * 10) + (*cp - '0'); - } while (*++cp && index(dec, *cp) && ++dcount < 3); - } else if ((cp[1] == 'o' || cp[1] == 'O') && - cp[2] && index(oct, cp[2])) { - cp += 2; /* move past backslash and 'O' */ - do { - cval = (cval * 8) + (*cp - '0'); - } while (*++cp && index(oct, *cp) && ++dcount < 3); - } else if ((cp[1] == 'x' || cp[1] == 'X') && - cp[2] && (dp = index(hex, cp[2])) != 0) { - cp += 2; /* move past backslash and 'X' */ - do { - cval = (cval * 16) + ((int)(dp - hex) / 2); - } while (*++cp && (dp = index(hex, *cp)) != 0 && ++dcount < 2); - } else { /* C-style character escapes */ - switch (*++cp) { - case '\\': cval = '\\'; break; - case 'n': cval = '\n'; break; - case 't': cval = '\t'; break; - case 'b': cval = '\b'; break; - case 'r': cval = '\r'; break; - default: cval = *cp; - } - ++cp; - } + cval = dcount = 0; /* for decimal, octal, hexadecimal cases */ + if ((*cp != '\\' && *cp != '^') || !cp[1]) { + /* simple character, or nothing left for \ or ^ to escape */ + cval = *cp++; + } else if (*cp == '^') { /* expand control-character syntax */ + cval = (*++cp & 0x1f); + ++cp; + /* remaining cases are all for backslash and we know cp[1] is not + * \0 */ + } else if (index(dec, cp[1])) { + ++cp; /* move past backslash to first digit */ + do { + cval = (cval * 10) + (*cp - '0'); + } while (*++cp && index(dec, *cp) && ++dcount < 3); + } else if ((cp[1] == 'o' || cp[1] == 'O') && cp[2] + && index(oct, cp[2])) { + cp += 2; /* move past backslash and 'O' */ + do { + cval = (cval * 8) + (*cp - '0'); + } while (*++cp && index(oct, *cp) && ++dcount < 3); + } else if ((cp[1] == 'x' || cp[1] == 'X') && cp[2] + && (dp = index(hex, cp[2])) != 0) { + cp += 2; /* move past backslash and 'X' */ + do { + cval = (cval * 16) + ((int) (dp - hex) / 2); + } while (*++cp && (dp = index(hex, *cp)) != 0 && ++dcount < 2); + } else { /* C-style character escapes */ + switch (*++cp) { + case '\\': + cval = '\\'; + break; + case 'n': + cval = '\n'; + break; + case 't': + cval = '\t'; + break; + case 'b': + cval = '\b'; + break; + case 'r': + cval = '\r'; + break; + default: + cval = *cp; + } + ++cp; + } - if (meta) - cval |= 0x80; - *tp++ = (char)cval; + if (meta) + cval |= 0x80; + *tp++ = (char) cval; } *tp = '\0'; } @@ -848,10 +870,10 @@ rejectoption(optname) const char *optname; { #ifdef MICRO - pline("\"%s\" settable only from %s.", optname, lastconfigfile); + pline("\"%s\" settable only from %s.", optname, lastconfigfile); #else - pline("%s can be set only from NETHACKOPTIONS or %s.", optname, - lastconfigfile); + pline("%s can be set only from NETHACKOPTIONS or %s.", optname, + lastconfigfile); #endif } @@ -859,23 +881,24 @@ STATIC_OVL void badoption(opts) const char *opts; { - if (!initial) { - if (!strncmp(opts, "h", 1) || !strncmp(opts, "?", 1)) - option_help(); - else - pline("Bad syntax: %s. Enter \"?g\" for help.", opts); - return; - } + if (!initial) { + if (!strncmp(opts, "h", 1) || !strncmp(opts, "?", 1)) + option_help(); + else + pline("Bad syntax: %s. Enter \"?g\" for help.", opts); + return; + } #ifdef MAC - else return; + else + return; #endif - if(from_file) - raw_printf("Bad syntax in OPTIONS in %s: %s.", lastconfigfile, opts); - else - raw_printf("Bad syntax in NETHACKOPTIONS: %s.", opts); + if (from_file) + raw_printf("Bad syntax in OPTIONS in %s: %s.", lastconfigfile, opts); + else + raw_printf("Bad syntax in NETHACKOPTIONS: %s.", opts); - wait_synch(); + wait_synch(); } STATIC_OVL char * @@ -883,17 +906,19 @@ string_for_opt(opts, val_optional) char *opts; boolean val_optional; { - char *colon, *equals; + char *colon, *equals; - colon = index(opts, ':'); - equals = index(opts, '='); - if (!colon || (equals && equals < colon)) colon = equals; + colon = index(opts, ':'); + equals = index(opts, '='); + if (!colon || (equals && equals < colon)) + colon = equals; - if (!colon || !*++colon) { - if (!val_optional) badoption(opts); - return (char *)0; - } - return colon; + if (!colon || !*++colon) { + if (!val_optional) + badoption(opts); + return (char *) 0; + } + return colon; } STATIC_OVL char * @@ -902,11 +927,11 @@ const char *optname; char *opts; boolean val_optional; { - if(!initial) { - rejectoption(optname); - return (char *)0; - } - return string_for_opt(opts, val_optional); + if (!initial) { + rejectoption(optname); + return (char *) 0; + } + return string_for_opt(opts, val_optional); } STATIC_OVL void @@ -914,9 +939,8 @@ bad_negation(optname, with_parameter) const char *optname; boolean with_parameter; { - pline_The("%s option may not %sbe negated.", - optname, - with_parameter ? "both have a value and " : ""); + pline_The("%s option may not %sbe negated.", optname, + with_parameter ? "both have a value and " : ""); } /* @@ -939,23 +963,23 @@ char *op; /* !!!! probably unnecessary with gold as normal inventory */ for (sp = op; *sp; sp++) { - oc_sym = def_char_to_objclass(*sp); - /* reject bad or duplicate entries */ - if (oc_sym == MAXOCLASSES || - oc_sym == RANDOM_CLASS || oc_sym == ILLOBJ_CLASS || - !index(flags.inv_order, oc_sym) || index(sp+1, *sp)) - return 0; - /* retain good ones */ - buf[num++] = (char) oc_sym; + oc_sym = def_char_to_objclass(*sp); + /* reject bad or duplicate entries */ + if (oc_sym == MAXOCLASSES || oc_sym == RANDOM_CLASS + || oc_sym == ILLOBJ_CLASS || !index(flags.inv_order, oc_sym) + || index(sp + 1, *sp)) + return 0; + /* retain good ones */ + buf[num++] = (char) oc_sym; } buf[num] = '\0'; /* fill in any omitted classes, using previous ordering */ for (sp = flags.inv_order; *sp; sp++) - if (!index(buf, *sp)) { - buf[num++] = *sp; - buf[num] = '\0'; /* explicitly terminate for next index() */ - } + if (!index(buf, *sp)) { + buf[num++] = *sp; + buf[num] = '\0'; /* explicitly terminate for next index() */ + } Strcpy(flags.inv_order, buf); return 1; @@ -966,29 +990,31 @@ warning_opts(opts, optype) register char *opts; const char *optype; { - uchar translate[MAXPCHARS+1]; - int length, i; + uchar translate[MAXPCHARS + 1]; + int length, i; - if (!(opts = string_for_env_opt(optype, opts, FALSE))) - return; - escapes(opts, opts); + if (!(opts = string_for_env_opt(optype, opts, FALSE))) + return; + escapes(opts, opts); - length = strlen(opts); - if (length > WARNCOUNT) length = WARNCOUNT; - /* match the form obtained from PC configuration files */ - for (i = 0; i < length; i++) - translate[i] = (((i < WARNCOUNT) && opts[i]) ? - (uchar) opts[i] : def_warnsyms[i].sym); - assign_warnings(translate); + length = strlen(opts); + if (length > WARNCOUNT) + length = WARNCOUNT; + /* match the form obtained from PC configuration files */ + for (i = 0; i < length; i++) + translate[i] = (((i < WARNCOUNT) && opts[i]) ? (uchar) opts[i] + : def_warnsyms[i].sym); + assign_warnings(translate); } void assign_warnings(graph_chars) register uchar *graph_chars; { - int i; - for (i = 0; i < WARNCOUNT; i++) - if (graph_chars[i]) warnsyms[i] = graph_chars[i]; + int i; + for (i = 0; i < WARNCOUNT; i++) + if (graph_chars[i]) + warnsyms[i] = graph_chars[i]; } STATIC_OVL int @@ -996,181 +1022,183 @@ feature_alert_opts(op, optn) char *op; const char *optn; { - char buf[BUFSZ]; - boolean rejectver = FALSE; - unsigned long fnv = get_feature_notice_ver(op); /* version.c */ - if (fnv == 0L) return 0; - if (fnv > get_current_feature_ver()) - rejectver = TRUE; - else - flags.suppress_alert = fnv; - if (rejectver) { - if (!initial) - You_cant("disable new feature alerts for future versions."); - else { - Sprintf(buf, - "\n%s=%s Invalid reference to a future version ignored", - optn, op); - badoption(buf); - } - return 0; - } - if (!initial) { - Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ, - FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH); - pline("Feature change alerts disabled for NetHack %s features and prior.", - buf); - } - return 1; + char buf[BUFSZ]; + boolean rejectver = FALSE; + unsigned long fnv = get_feature_notice_ver(op); /* version.c */ + if (fnv == 0L) + return 0; + if (fnv > get_current_feature_ver()) + rejectver = TRUE; + else + flags.suppress_alert = fnv; + if (rejectver) { + if (!initial) + You_cant("disable new feature alerts for future versions."); + else { + Sprintf(buf, + "\n%s=%s Invalid reference to a future version ignored", + optn, op); + badoption(buf); + } + return 0; + } + if (!initial) { + Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ, + FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH); + pline("Feature change alerts disabled for NetHack %s features and " + "prior.", + buf); + } + return 1; } void set_duplicate_opt_detection(on_or_off) int on_or_off; { - int k, *optptr; - if (on_or_off != 0) { - /*-- ON --*/ - if (iflags.opt_booldup) - impossible("iflags.opt_booldup already on (memory leak)"); - iflags.opt_booldup = (int *)alloc(SIZE(boolopt) * sizeof(int)); - optptr = iflags.opt_booldup; - for (k = 0; k < SIZE(boolopt); ++k) - *optptr++ = 0; + int k, *optptr; + if (on_or_off != 0) { + /*-- ON --*/ + if (iflags.opt_booldup) + impossible("iflags.opt_booldup already on (memory leak)"); + iflags.opt_booldup = (int *) alloc(SIZE(boolopt) * sizeof(int)); + optptr = iflags.opt_booldup; + for (k = 0; k < SIZE(boolopt); ++k) + *optptr++ = 0; - if (iflags.opt_compdup) - impossible("iflags.opt_compdup already on (memory leak)"); - iflags.opt_compdup = (int *)alloc(SIZE(compopt) * sizeof(int)); - optptr = iflags.opt_compdup; - for (k = 0; k < SIZE(compopt); ++k) - *optptr++ = 0; - } else { - /*-- OFF --*/ - if (iflags.opt_booldup) free((genericptr_t) iflags.opt_booldup); - iflags.opt_booldup = (int *)0; - if (iflags.opt_compdup) free((genericptr_t) iflags.opt_compdup); - iflags.opt_compdup = (int *)0; - } + if (iflags.opt_compdup) + impossible("iflags.opt_compdup already on (memory leak)"); + iflags.opt_compdup = (int *) alloc(SIZE(compopt) * sizeof(int)); + optptr = iflags.opt_compdup; + for (k = 0; k < SIZE(compopt); ++k) + *optptr++ = 0; + } else { + /*-- OFF --*/ + if (iflags.opt_booldup) + free((genericptr_t) iflags.opt_booldup); + iflags.opt_booldup = (int *) 0; + if (iflags.opt_compdup) + free((genericptr_t) iflags.opt_compdup); + iflags.opt_compdup = (int *) 0; + } } STATIC_OVL boolean duplicate_opt_detection(opts, iscompound) const char *opts; -int iscompound; /* 0 == boolean option, 1 == compound */ +int iscompound; /* 0 == boolean option, 1 == compound */ { - int i, *optptr; - if (!iscompound && iflags.opt_booldup && initial && from_file) { - for (i = 0; boolopt[i].name; i++) { - if (match_optname(opts, boolopt[i].name, 3, FALSE)) { - optptr = iflags.opt_booldup + i; - *optptr += 1; - if (*optptr > 1) return TRUE; - else return FALSE; - } - } - } else if (iscompound && iflags.opt_compdup && initial && from_file) { - for (i = 0; compopt[i].name; i++) { - if (match_optname(opts, compopt[i].name, - strlen(compopt[i].name), TRUE)) { - optptr = iflags.opt_compdup + i; - *optptr += 1; - if (*optptr > 1) return TRUE; - else return FALSE; - } - } - } - return FALSE; + int i, *optptr; + if (!iscompound && iflags.opt_booldup && initial && from_file) { + for (i = 0; boolopt[i].name; i++) { + if (match_optname(opts, boolopt[i].name, 3, FALSE)) { + optptr = iflags.opt_booldup + i; + *optptr += 1; + if (*optptr > 1) + return TRUE; + else + return FALSE; + } + } + } else if (iscompound && iflags.opt_compdup && initial && from_file) { + for (i = 0; compopt[i].name; i++) { + if (match_optname(opts, compopt[i].name, strlen(compopt[i].name), + TRUE)) { + optptr = iflags.opt_compdup + i; + *optptr += 1; + if (*optptr > 1) + return TRUE; + else + return FALSE; + } + } + } + return FALSE; } STATIC_OVL void complain_about_duplicate(opts, iscompound) const char *opts; -int iscompound; /* 0 == boolean option, 1 == compound */ +int iscompound; /* 0 == boolean option, 1 == compound */ { #if defined(MAC) - /* the Mac has trouble dealing with the output of messages while - * processing the config file. That should get fixed one day. - * For now just return. - */ - return; + /* the Mac has trouble dealing with the output of messages while + * processing the config file. That should get fixed one day. + * For now just return. + */ + return; #endif - raw_printf( - "\nWarning - %s option specified multiple times: %s.\n", - iscompound ? "compound" : "boolean", opts); - wait_synch(); - return; + raw_printf("\nWarning - %s option specified multiple times: %s.\n", + iscompound ? "compound" : "boolean", opts); + wait_synch(); + return; } /* paranoia[] - used by parseoptions() and special_handling() */ STATIC_VAR const struct paranoia_opts { - int flagmask; /* which paranoid option */ - const char *argname; /* primary name */ - int argMinLen; /* minimum number of letters to match */ - const char *synonym; /* alternate name (optional) */ - int synMinLen; - const char *explain; /* for interactive menu */ + int flagmask; /* which paranoid option */ + const char *argname; /* primary name */ + int argMinLen; /* minimum number of letters to match */ + const char *synonym; /* alternate name (optional) */ + int synMinLen; + const char *explain; /* for interactive menu */ } paranoia[] = { - /* there are some initial-letter conflicts: "a"ttack vs "a"ll, "attack" - takes precedence and "all" isn't present in the interactive menu, - and "d"ie vs "d"eath, synonyms for each other so doesn't matter; - (also "p"ray vs "P"aranoia, "pray" takes precedence since "Paranoia" - is just a synonym for "Confirm") */ - { PARANOID_CONFIRM, "Confirm", 1, "Paranoia", 2, - "for \"yes\" confirmations, require \"no\" to reject" }, - { PARANOID_QUIT, "quit", 1, "explore", 1, - "yes vs y to quit or to enter explore mode" }, - { PARANOID_DIE, "die", 1, "death", 2, - "yes vs y to die (explore mode or debug mode)" }, - { PARANOID_BONES, "bones", 1, 0, 0, - "yes vs y to save bones data when dying in debug mode" }, - { PARANOID_HIT, "attack", 1, "hit", 1, - "yes vs y to attack a peaceful monster" }, - { PARANOID_PRAY, "pray", 1, 0, 0, - "y to pray (supersedes old \"prayconfirm\" option)" }, - { PARANOID_REMOVE, "Remove", 1, "Takeoff", 1, - "always pick from inventory for Remove and Takeoff" }, - /* for config file parsing; interactive menu skips these */ - { 0, "none", 4, 0, 0, 0 }, /* require full word match */ - { ~0, "all", 3, 0, 0, 0 }, /* ditto */ + /* there are some initial-letter conflicts: "a"ttack vs "a"ll, "attack" + takes precedence and "all" isn't present in the interactive menu, + and "d"ie vs "d"eath, synonyms for each other so doesn't matter; + (also "p"ray vs "P"aranoia, "pray" takes precedence since "Paranoia" + is just a synonym for "Confirm") */ + { PARANOID_CONFIRM, "Confirm", 1, "Paranoia", 2, + "for \"yes\" confirmations, require \"no\" to reject" }, + { PARANOID_QUIT, "quit", 1, "explore", 1, + "yes vs y to quit or to enter explore mode" }, + { PARANOID_DIE, "die", 1, "death", 2, + "yes vs y to die (explore mode or debug mode)" }, + { PARANOID_BONES, "bones", 1, 0, 0, + "yes vs y to save bones data when dying in debug mode" }, + { PARANOID_HIT, "attack", 1, "hit", 1, + "yes vs y to attack a peaceful monster" }, + { PARANOID_PRAY, "pray", 1, 0, 0, + "y to pray (supersedes old \"prayconfirm\" option)" }, + { PARANOID_REMOVE, "Remove", 1, "Takeoff", 1, + "always pick from inventory for Remove and Takeoff" }, + /* for config file parsing; interactive menu skips these */ + { 0, "none", 4, 0, 0, 0 }, /* require full word match */ + { ~0, "all", 3, 0, 0, 0 }, /* ditto */ }; - extern struct menucoloring *menu_colorings; static const struct { - const char *name; - const int color; -} colornames[] = { - {"black", CLR_BLACK}, - {"red", CLR_RED}, - {"green", CLR_GREEN}, - {"brown", CLR_BROWN}, - {"blue", CLR_BLUE}, - {"magenta", CLR_MAGENTA}, - {"cyan", CLR_CYAN}, - {"gray", CLR_GRAY}, - {"grey", CLR_GRAY}, - {"orange", CLR_ORANGE}, - {"lightgreen", CLR_BRIGHT_GREEN}, - {"yellow", CLR_YELLOW}, - {"lightblue", CLR_BRIGHT_BLUE}, - {"lightmagenta", CLR_BRIGHT_MAGENTA}, - {"lightcyan", CLR_BRIGHT_CYAN}, - {"white", CLR_WHITE} -}; + const char *name; + const int color; +} colornames[] = { { "black", CLR_BLACK }, + { "red", CLR_RED }, + { "green", CLR_GREEN }, + { "brown", CLR_BROWN }, + { "blue", CLR_BLUE }, + { "magenta", CLR_MAGENTA }, + { "cyan", CLR_CYAN }, + { "gray", CLR_GRAY }, + { "grey", CLR_GRAY }, + { "orange", CLR_ORANGE }, + { "lightgreen", CLR_BRIGHT_GREEN }, + { "yellow", CLR_YELLOW }, + { "lightblue", CLR_BRIGHT_BLUE }, + { "lightmagenta", CLR_BRIGHT_MAGENTA }, + { "lightcyan", CLR_BRIGHT_CYAN }, + { "white", CLR_WHITE } }; static const struct { - const char *name; - const int attr; -} attrnames[] = { - {"none", ATR_NONE}, - {"bold", ATR_BOLD}, - {"dim", ATR_DIM}, - {"underline", ATR_ULINE}, - {"blink", ATR_BLINK}, - {"inverse", ATR_INVERSE} -}; + const char *name; + const int attr; +} attrnames[] = { { "none", ATR_NONE }, + { "bold", ATR_BOLD }, + { "dim", ATR_DIM }, + { "underline", ATR_ULINE }, + { "blink", ATR_BLINK }, + { "inverse", ATR_INVERSE } }; const char * clr2colorname(clr) @@ -1178,8 +1206,8 @@ int clr; { int i; for (i = 0; i < SIZE(colornames); i++) - if (colornames[i].color == clr) - return colornames[i].name; + if (colornames[i].color == clr) + return colornames[i].name; return NULL; } @@ -1189,8 +1217,8 @@ int attr; { int i; for (i = 0; i < SIZE(attrnames); i++) - if (attrnames[i].attr == attr) - return attrnames[i].name; + if (attrnames[i].attr == attr) + return attrnames[i].name; return NULL; } @@ -1200,23 +1228,25 @@ query_color() winid tmpwin; anything any; int i, pick_cnt; - menu_item *picks = (menu_item *)0; + menu_item *picks = (menu_item *) 0; tmpwin = create_nhwindow(NHW_MENU); start_menu(tmpwin); any = zeroany; for (i = 0; i < SIZE(colornames); i++) { - if (!strcmp(colornames[i].name, "grey")) continue; - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, colornames[i].name, MENU_UNSELECTED); + if (!strcmp(colornames[i].name, "grey")) + continue; + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, colornames[i].name, + MENU_UNSELECTED); } end_menu(tmpwin, "Pick a color"); pick_cnt = select_menu(tmpwin, PICK_ONE, &picks); destroy_nhwindow(tmpwin); if (pick_cnt > 0) { - i = colornames[picks->item.a_int - 1].color; - free((genericptr_t)picks); - return i; + i = colornames[picks->item.a_int - 1].color; + free((genericptr_t) picks); + return i; } return -1; } @@ -1228,23 +1258,23 @@ const char *prompt; winid tmpwin; anything any; int i, pick_cnt; - menu_item *picks = (menu_item *)0; + menu_item *picks = (menu_item *) 0; tmpwin = create_nhwindow(NHW_MENU); start_menu(tmpwin); any = zeroany; for (i = 0; i < SIZE(attrnames); i++) { - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - attrnames[i].attr, attrnames[i].name, MENU_UNSELECTED); + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, attrnames[i].attr, + attrnames[i].name, MENU_UNSELECTED); } end_menu(tmpwin, prompt ? prompt : "Pick an attribute"); pick_cnt = select_menu(tmpwin, PICK_ONE, &picks); destroy_nhwindow(tmpwin); if (pick_cnt > 0) { - i = attrnames[picks->item.a_int - 1].attr; - free((genericptr_t)picks); - return i; + i = attrnames[picks->item.a_int - 1].attr; + free((genericptr_t) picks); + return i; } return -1; } @@ -1255,25 +1285,26 @@ char *str; int c, a; { struct menucoloring *tmp; - if (!str) return FALSE; - tmp = (struct menucoloring *)alloc(sizeof(struct menucoloring)); + if (!str) + return FALSE; + tmp = (struct menucoloring *) alloc(sizeof(struct menucoloring)); tmp->match = regex_init(); if (!regex_compile(str, tmp->match)) { - static const char *re_error = "Menucolor regex error"; - if (!iflags.window_inited) - raw_printf("\n%s: %s\n", re_error, regex_error_desc(tmp->match)); - else - pline("%s: %s", re_error, regex_error_desc(tmp->match)); - wait_synch(); - free(tmp); - return FALSE; + static const char *re_error = "Menucolor regex error"; + if (!iflags.window_inited) + raw_printf("\n%s: %s\n", re_error, regex_error_desc(tmp->match)); + else + pline("%s: %s", re_error, regex_error_desc(tmp->match)); + wait_synch(); + free(tmp); + return FALSE; } else { - tmp->next = menu_colorings; - tmp->origstr = dupstr(str); - tmp->color = c; - tmp->attr = a; - menu_colorings = tmp; - return TRUE; + tmp->next = menu_colorings; + tmp->origstr = dupstr(str); + tmp->color = c; + tmp->attr = a; + menu_colorings = tmp; + return TRUE; } } @@ -1285,44 +1316,49 @@ char *str; int i, c = NO_COLOR, a = ATR_NONE; char *tmps, *cs = strchr(str, '='); - if (!cs || !str) return FALSE; + if (!cs || !str) + return FALSE; tmps = cs; tmps++; - while (*tmps && isspace((uchar)*tmps)) tmps++; + while (*tmps && isspace((uchar) *tmps)) + tmps++; for (i = 0; i < SIZE(colornames); i++) - if (strstri(tmps, colornames[i].name) == tmps) { - c = colornames[i].color; - break; - } - if ((i == SIZE(colornames)) && (*tmps >= '0' && *tmps <='9')) - c = atoi(tmps); + if (strstri(tmps, colornames[i].name) == tmps) { + c = colornames[i].color; + break; + } + if ((i == SIZE(colornames)) && (*tmps >= '0' && *tmps <= '9')) + c = atoi(tmps); - if (c > 15) return FALSE; + if (c > 15) + return FALSE; tmps = strchr(str, '&'); if (tmps) { - tmps++; - while (*tmps && isspace((uchar)*tmps)) tmps++; - for (i = 0; i < SIZE(attrnames); i++) - if (strstri(tmps, attrnames[i].name) == tmps) { - a = attrnames[i].attr; - break; - } - if ((i == SIZE(attrnames)) && (*tmps >= '0' && *tmps <='9')) - a = atoi(tmps); + tmps++; + while (*tmps && isspace((uchar) *tmps)) + tmps++; + for (i = 0; i < SIZE(attrnames); i++) + if (strstri(tmps, attrnames[i].name) == tmps) { + a = attrnames[i].attr; + break; + } + if ((i == SIZE(attrnames)) && (*tmps >= '0' && *tmps <= '9')) + a = atoi(tmps); } *cs = '\0'; tmps = str; if ((*tmps == '"') || (*tmps == '\'')) { - cs--; - while (isspace((uchar)*cs)) cs--; - if (*cs == *tmps) { - *cs = '\0'; - tmps++; - } + cs--; + while (isspace((uchar) *cs)) + cs--; + if (*cs == *tmps) { + *cs = '\0'; + tmps++; + } } return add_menu_coloring_parsed(tmps, c, a); @@ -1335,12 +1371,12 @@ int *color, *attr; { struct menucoloring *tmpmc; if (iflags.use_menu_color) - for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next) + for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next) if (regex_match(str, tmpmc->match)) { - *color = tmpmc->color; - *attr = tmpmc->attr; - return TRUE; - } + *color = tmpmc->color; + *attr = tmpmc->attr; + return TRUE; + } return FALSE; } @@ -1350,11 +1386,11 @@ free_menu_coloring() struct menucoloring *tmp = menu_colorings; while (tmp) { - struct menucoloring *tmp2 = tmp->next; + struct menucoloring *tmp2 = tmp->next; regex_free(tmp->match); - free(tmp->origstr); - free(tmp); - tmp = tmp2; + free(tmp->origstr); + free(tmp); + tmp = tmp2; } } @@ -1366,22 +1402,23 @@ int idx; /* 0 .. */ struct menucoloring *prev = NULL; while (tmp) { - if (idx == 0) { - struct menucoloring *next = tmp->next; - regex_free(tmp->match); - free(tmp->origstr); - free(tmp); - if (prev) prev->next = next; - else menu_colorings = next; - return; - } - idx--; - prev = tmp; - tmp = tmp->next; + if (idx == 0) { + struct menucoloring *next = tmp->next; + regex_free(tmp->match); + free(tmp->origstr); + free(tmp); + if (prev) + prev->next = next; + else + menu_colorings = next; + return; + } + idx--; + prev = tmp; + tmp = tmp->next; } } - int count_menucolors() { @@ -1389,8 +1426,8 @@ count_menucolors() struct menucoloring *tmp = menu_colorings; while (tmp) { - count++; - tmp = tmp->next; + count++; + tmp = tmp->next; } return count; } @@ -1400,1639 +1437,1752 @@ parseoptions(opts, tinitial, tfrom_file) register char *opts; boolean tinitial, tfrom_file; { - register char *op; - unsigned num; - boolean negated, duplicate; - int i; - const char *fullname; + register char *op; + unsigned num; + boolean negated, duplicate; + int i; + const char *fullname; - initial = tinitial; - from_file = tfrom_file; - if ((op = index(opts, ',')) != 0) { - *op++ = 0; - parseoptions(op, initial, from_file); - } - if (strlen(opts) > BUFSZ/2) { - badoption("option too long"); - return; - } + initial = tinitial; + from_file = tfrom_file; + if ((op = index(opts, ',')) != 0) { + *op++ = 0; + parseoptions(op, initial, from_file); + } + if (strlen(opts) > BUFSZ / 2) { + badoption("option too long"); + return; + } - /* strip leading and trailing white space */ - while (isspace((uchar)*opts)) opts++; - op = eos(opts); - while (--op >= opts && isspace((uchar)*op)) *op = '\0'; + /* strip leading and trailing white space */ + while (isspace((uchar) *opts)) + opts++; + op = eos(opts); + while (--op >= opts && isspace((uchar) *op)) + *op = '\0'; - if (!*opts) return; - negated = FALSE; - while ((*opts == '!') || !strncmpi(opts, "no", 2)) { - if (*opts == '!') opts++; else opts += 2; - negated = !negated; - } + if (!*opts) + return; + negated = FALSE; + while ((*opts == '!') || !strncmpi(opts, "no", 2)) { + if (*opts == '!') + opts++; + else + opts += 2; + negated = !negated; + } - /* variant spelling */ + /* variant spelling */ - if (match_optname(opts, "colour", 5, FALSE)) - Strcpy(opts, "color"); /* fortunately this isn't longer */ + if (match_optname(opts, "colour", 5, FALSE)) + Strcpy(opts, "color"); /* fortunately this isn't longer */ - /* special boolean options */ + /* special boolean options */ - if (match_optname(opts, "female", 3, FALSE)) { - if (duplicate_opt_detection(opts,0)) - complain_about_duplicate(opts,0); - if(!initial && flags.female == negated) - pline("That is not anatomically possible."); - else - flags.initgend = flags.female = !negated; - return; - } + if (match_optname(opts, "female", 3, FALSE)) { + if (duplicate_opt_detection(opts, 0)) + complain_about_duplicate(opts, 0); + if (!initial && flags.female == negated) + pline("That is not anatomically possible."); + else + flags.initgend = flags.female = !negated; + return; + } - if (match_optname(opts, "male", 4, FALSE)) { - if (duplicate_opt_detection(opts,0)) - complain_about_duplicate(opts,0); - if(!initial && flags.female != negated) - pline("That is not anatomically possible."); - else - flags.initgend = flags.female = negated; - return; - } + if (match_optname(opts, "male", 4, FALSE)) { + if (duplicate_opt_detection(opts, 0)) + complain_about_duplicate(opts, 0); + if (!initial && flags.female != negated) + pline("That is not anatomically possible."); + else + flags.initgend = flags.female = negated; + return; + } #if defined(MICRO) && !defined(AMIGA) - /* included for compatibility with old NetHack.cnf files */ - if (match_optname(opts, "IBM_", 4, FALSE)) { - iflags.BIOS = !negated; - return; - } + /* included for compatibility with old NetHack.cnf files */ + if (match_optname(opts, "IBM_", 4, FALSE)) { + iflags.BIOS = !negated; + return; + } #endif /* MICRO */ - /* compound options */ + /* compound options */ - /* This first batch can be duplicated if their values are negated */ + /* This first batch can be duplicated if their values are negated */ - /* align:string */ - fullname = "align"; - if (match_optname(opts, fullname, sizeof("align")-1, TRUE)) { - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - boolean val_negated = FALSE; - while ((*op == '!') || !strncmpi(op, "no", 2)) { - if (*op == '!') op++; else op += 2; - val_negated = !val_negated; - } - if (val_negated) { - if (!setrolefilter(op)) - badoption(opts); - } else { - if (duplicate_opt_detection(opts,1)) - complain_about_duplicate(opts,1); - if ((flags.initalign = str2align(op)) == ROLE_NONE) - badoption(opts); - } - } - return; - } + /* align:string */ + fullname = "align"; + if (match_optname(opts, fullname, sizeof("align") - 1, TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + boolean val_negated = FALSE; + while ((*op == '!') || !strncmpi(op, "no", 2)) { + if (*op == '!') + op++; + else + op += 2; + val_negated = !val_negated; + } + if (val_negated) { + if (!setrolefilter(op)) + badoption(opts); + } else { + if (duplicate_opt_detection(opts, 1)) + complain_about_duplicate(opts, 1); + if ((flags.initalign = str2align(op)) == ROLE_NONE) + badoption(opts); + } + } + return; + } - /* role:string or character:string */ - fullname = "role"; - if (match_optname(opts, fullname, 4, TRUE) || - match_optname(opts, (fullname = "character"), 4, TRUE)) { - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - boolean val_negated = FALSE; - while ((*op == '!') || !strncmpi(op, "no", 2)) { - if (*op == '!') op++; else op += 2; - val_negated = !val_negated; - } - if (val_negated) { - if (!setrolefilter(op)) - badoption(opts); - } else { - if (duplicate_opt_detection(opts,1)) - complain_about_duplicate(opts,1); - if ((flags.initrole = str2role(op)) == ROLE_NONE) - badoption(opts); - else /* Backwards compatibility */ - nmcpy(pl_character, op, PL_NSIZ); - } - } - return; - } + /* role:string or character:string */ + fullname = "role"; + if (match_optname(opts, fullname, 4, TRUE) + || match_optname(opts, (fullname = "character"), 4, TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + boolean val_negated = FALSE; + while ((*op == '!') || !strncmpi(op, "no", 2)) { + if (*op == '!') + op++; + else + op += 2; + val_negated = !val_negated; + } + if (val_negated) { + if (!setrolefilter(op)) + badoption(opts); + } else { + if (duplicate_opt_detection(opts, 1)) + complain_about_duplicate(opts, 1); + if ((flags.initrole = str2role(op)) == ROLE_NONE) + badoption(opts); + else /* Backwards compatibility */ + nmcpy(pl_character, op, PL_NSIZ); + } + } + return; + } - /* race:string */ - fullname = "race"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - boolean val_negated = FALSE; - while ((*op == '!') || !strncmpi(op, "no", 2)) { - if (*op == '!') op++; else op += 2; - val_negated = !val_negated; - } - if (val_negated) { - if (!setrolefilter(op)) - badoption(opts); - } else { - if (duplicate_opt_detection(opts,1)) - complain_about_duplicate(opts,1); - if ((flags.initrace = str2race(op)) == ROLE_NONE) - badoption(opts); - else /* Backwards compatibility */ - pl_race = *op; - } - } - return; - } + /* race:string */ + fullname = "race"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + boolean val_negated = FALSE; + while ((*op == '!') || !strncmpi(op, "no", 2)) { + if (*op == '!') + op++; + else + op += 2; + val_negated = !val_negated; + } + if (val_negated) { + if (!setrolefilter(op)) + badoption(opts); + } else { + if (duplicate_opt_detection(opts, 1)) + complain_about_duplicate(opts, 1); + if ((flags.initrace = str2race(op)) == ROLE_NONE) + badoption(opts); + else /* Backwards compatibility */ + pl_race = *op; + } + } + return; + } - /* gender:string */ - fullname = "gender"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - boolean val_negated = FALSE; - while ((*op == '!') || !strncmpi(op, "no", 2)) { - if (*op == '!') op++; else op += 2; - val_negated = !val_negated; - } - if (val_negated) { - if (!setrolefilter(op)) - badoption(opts); - } else { - if (duplicate_opt_detection(opts,1)) - complain_about_duplicate(opts,1); - if ((flags.initgend = str2gend(op)) == ROLE_NONE) - badoption(opts); - else - flags.female = flags.initgend; - } - } - return; - } + /* gender:string */ + fullname = "gender"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + boolean val_negated = FALSE; + while ((*op == '!') || !strncmpi(op, "no", 2)) { + if (*op == '!') + op++; + else + op += 2; + val_negated = !val_negated; + } + if (val_negated) { + if (!setrolefilter(op)) + badoption(opts); + } else { + if (duplicate_opt_detection(opts, 1)) + complain_about_duplicate(opts, 1); + if ((flags.initgend = str2gend(op)) == ROLE_NONE) + badoption(opts); + else + flags.female = flags.initgend; + } + } + return; + } - /* We always check for duplicates on the remaining compound options, - although individual option processing can choose to complain or not */ + /* We always check for duplicates on the remaining compound options, + although individual option processing can choose to complain or not */ - duplicate = duplicate_opt_detection(opts,1); /* 1 means check compounds */ + duplicate = + duplicate_opt_detection(opts, 1); /* 1 means check compounds */ - fullname = "pettype"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if ((op = string_for_env_opt(fullname, opts, negated)) != 0) { - if (negated) bad_negation(fullname, TRUE); - else switch (lowc(*op)) { - case 'd': /* dog */ - preferred_pet = 'd'; - break; - case 'c': /* cat */ - case 'f': /* feline */ - preferred_pet = 'c'; - break; - case 'h': /* horse */ - case 'q': /* quadruped */ - /* avoids giving "unrecognized type of pet" but - pet_type(dog.c) won't actually honor this */ - preferred_pet = 'h'; - break; - case 'n': /* no pet */ - preferred_pet = 'n'; - break; - case '*': /* random */ - preferred_pet = '\0'; - break; - default: - pline("Unrecognized pet type '%s'.", op); - break; - } - } else if (negated) preferred_pet = 'n'; - return; - } + fullname = "pettype"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if ((op = string_for_env_opt(fullname, opts, negated)) != 0) { + if (negated) + bad_negation(fullname, TRUE); + else + switch (lowc(*op)) { + case 'd': /* dog */ + preferred_pet = 'd'; + break; + case 'c': /* cat */ + case 'f': /* feline */ + preferred_pet = 'c'; + break; + case 'h': /* horse */ + case 'q': /* quadruped */ + /* avoids giving "unrecognized type of pet" but + pet_type(dog.c) won't actually honor this */ + preferred_pet = 'h'; + break; + case 'n': /* no pet */ + preferred_pet = 'n'; + break; + case '*': /* random */ + preferred_pet = '\0'; + break; + default: + pline("Unrecognized pet type '%s'.", op); + break; + } + } else if (negated) + preferred_pet = 'n'; + return; + } - fullname = "catname"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) - nmcpy(catname, op, PL_PSIZ); - sanitize_name(catname); - return; - } + fullname = "catname"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(catname, op, PL_PSIZ); + sanitize_name(catname); + return; + } - fullname = "dogname"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) - nmcpy(dogname, op, PL_PSIZ); - sanitize_name(dogname); - return; - } + fullname = "dogname"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(dogname, op, PL_PSIZ); + sanitize_name(dogname); + return; + } - fullname = "horsename"; - if (match_optname(opts, fullname, 5, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) - nmcpy(horsename, op, PL_PSIZ); - sanitize_name(horsename); - return; - } + fullname = "horsename"; + if (match_optname(opts, fullname, 5, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(horsename, op, PL_PSIZ); + sanitize_name(horsename); + return; + } - fullname = "number_pad"; - if (match_optname(opts, fullname, 10, TRUE)) { - boolean compat = (strlen(opts) <= 10); + fullname = "number_pad"; + if (match_optname(opts, fullname, 10, TRUE)) { + boolean compat = (strlen(opts) <= 10); - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, (compat || !initial)); - if (!op) { - if (compat || negated || initial) { - /* for backwards compatibility, "number_pad" without a - value is a synonym for number_pad:1 */ - iflags.num_pad = !negated; - iflags.num_pad_mode = 0; - } - } else if (negated) { - bad_negation("number_pad", TRUE); - return; - } else { - int mode = atoi(op); + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, (compat || !initial)); + if (!op) { + if (compat || negated || initial) { + /* for backwards compatibility, "number_pad" without a + value is a synonym for number_pad:1 */ + iflags.num_pad = !negated; + iflags.num_pad_mode = 0; + } + } else if (negated) { + bad_negation("number_pad", TRUE); + return; + } else { + int mode = atoi(op); - if (mode < -1 || mode > 4 || (mode == 0 && *op != '0')) { - badoption(opts); - return; - } else if (mode <= 0) { - iflags.num_pad = FALSE; - /* German keyboard; y and z keys swapped */ - iflags.num_pad_mode = (mode < 0); /* 0 or 1 */ - } else { /* mode > 0 */ - iflags.num_pad = TRUE; - iflags.num_pad_mode = 0; - /* PC Hack / MSDOS compatibility */ - if (mode == 2 || mode == 4) iflags.num_pad_mode |= 1; - /* phone keypad layout */ - if (mode == 3 || mode == 4) iflags.num_pad_mode |= 2; - } - } - reset_commands(FALSE); - number_pad(iflags.num_pad ? 1 : 0); - return; - } + if (mode < -1 || mode > 4 || (mode == 0 && *op != '0')) { + badoption(opts); + return; + } else if (mode <= 0) { + iflags.num_pad = FALSE; + /* German keyboard; y and z keys swapped */ + iflags.num_pad_mode = (mode < 0); /* 0 or 1 */ + } else { /* mode > 0 */ + iflags.num_pad = TRUE; + iflags.num_pad_mode = 0; + /* PC Hack / MSDOS compatibility */ + if (mode == 2 || mode == 4) + iflags.num_pad_mode |= 1; + /* phone keypad layout */ + if (mode == 3 || mode == 4) + iflags.num_pad_mode |= 2; + } + } + reset_commands(FALSE); + number_pad(iflags.num_pad ? 1 : 0); + return; + } - fullname = "roguesymset"; - if (match_optname(opts, fullname, 7, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_opt(opts, FALSE)) != 0) { - symset[ROGUESET].name = (char *)alloc(strlen(op) + 1); - Strcpy(symset[ROGUESET].name, op); - if (!read_sym_file(ROGUESET)) { - clear_symsetentry(ROGUESET, TRUE); - raw_printf("Unable to load symbol set \"%s\" from \"%s\".", - op, SYMBOLS); - wait_synch(); - } else { - if (!initial && Is_rogue_level(&u.uz)) - assign_graphics(ROGUESET); - need_redraw = TRUE; - } - } - return; - } + fullname = "roguesymset"; + if (match_optname(opts, fullname, 7, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_opt(opts, FALSE)) != 0) { + symset[ROGUESET].name = (char *) alloc(strlen(op) + 1); + Strcpy(symset[ROGUESET].name, op); + if (!read_sym_file(ROGUESET)) { + clear_symsetentry(ROGUESET, TRUE); + raw_printf("Unable to load symbol set \"%s\" from \"%s\".", + op, SYMBOLS); + wait_synch(); + } else { + if (!initial && Is_rogue_level(&u.uz)) + assign_graphics(ROGUESET); + need_redraw = TRUE; + } + } + return; + } - fullname = "symset"; - if (match_optname(opts, fullname, 6, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_opt(opts, FALSE)) != 0) { - symset[PRIMARY].name = (char *)alloc(strlen(op) + 1); - Strcpy(symset[PRIMARY].name, op); - if (!read_sym_file(PRIMARY)) { - clear_symsetentry(PRIMARY, TRUE); - raw_printf("Unable to load symbol set \"%s\" from \"%s\".", - op, SYMBOLS); - wait_synch(); - } else { - switch_symbols(TRUE); - need_redraw = TRUE; - } - } - return; - } + fullname = "symset"; + if (match_optname(opts, fullname, 6, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_opt(opts, FALSE)) != 0) { + symset[PRIMARY].name = (char *) alloc(strlen(op) + 1); + Strcpy(symset[PRIMARY].name, op); + if (!read_sym_file(PRIMARY)) { + clear_symsetentry(PRIMARY, TRUE); + raw_printf("Unable to load symbol set \"%s\" from \"%s\".", + op, SYMBOLS); + wait_synch(); + } else { + switch_symbols(TRUE); + need_redraw = TRUE; + } + } + return; + } - fullname = "runmode"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - flags.runmode = RUN_TPORT; - } else if ((op = string_for_opt(opts, FALSE)) != 0) { - if (!strncmpi(op, "teleport", strlen(op))) - flags.runmode = RUN_TPORT; - else if (!strncmpi(op, "run", strlen(op))) - flags.runmode = RUN_LEAP; - else if (!strncmpi(op, "walk", strlen(op))) - flags.runmode = RUN_STEP; - else if (!strncmpi(op, "crawl", strlen(op))) - flags.runmode = RUN_CRAWL; - else - badoption(opts); - } - return; - } + fullname = "runmode"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + flags.runmode = RUN_TPORT; + } else if ((op = string_for_opt(opts, FALSE)) != 0) { + if (!strncmpi(op, "teleport", strlen(op))) + flags.runmode = RUN_TPORT; + else if (!strncmpi(op, "run", strlen(op))) + flags.runmode = RUN_LEAP; + else if (!strncmpi(op, "walk", strlen(op))) + flags.runmode = RUN_STEP; + else if (!strncmpi(op, "crawl", strlen(op))) + flags.runmode = RUN_CRAWL; + else + badoption(opts); + } + return; + } - /* menucolor:"regex_string"=color */ - fullname = "menucolor"; - if (match_optname(opts, fullname, 9, TRUE)) { - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) - if (!add_menu_coloring(op)) - badoption(opts); - return; - } + /* menucolor:"regex_string"=color */ + fullname = "menucolor"; + if (match_optname(opts, fullname, 9, TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + if (!add_menu_coloring(op)) + badoption(opts); + return; + } - fullname = "msghistory"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_env_opt(fullname, opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.msg_history = negated ? 0 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } + fullname = "msghistory"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_env_opt(fullname, opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.msg_history = negated ? 0 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } - fullname="msg_window"; - /* msg_window:single, combo, full or reversed */ - if (match_optname(opts, fullname, 4, TRUE)) { - /* allow option to be silently ignored by non-tty ports */ + fullname = "msg_window"; + /* msg_window:single, combo, full or reversed */ + if (match_optname(opts, fullname, 4, TRUE)) { +/* allow option to be silently ignored by non-tty ports */ #ifdef TTY_GRAPHICS - int tmp; - if (duplicate) complain_about_duplicate(opts,1); - if (!(op = string_for_opt(opts, TRUE))) { - tmp = negated ? 's' : 'f'; - } else { - if (negated) { - bad_negation(fullname, TRUE); - return; - } - tmp = tolower(*op); - } - switch (tmp) { - case 's': /* single message history cycle (default if negated) */ - iflags.prevmsg_window = 's'; - break; - case 'c': /* combination: two singles, then full page reversed */ - iflags.prevmsg_window = 'c'; - break; - case 'f': /* full page (default if no opts) */ - iflags.prevmsg_window = 'f'; - break; - case 'r': /* full page (reversed) */ - iflags.prevmsg_window = 'r'; - break; - default: - badoption(opts); - } + int tmp; + if (duplicate) + complain_about_duplicate(opts, 1); + if (!(op = string_for_opt(opts, TRUE))) { + tmp = negated ? 's' : 'f'; + } else { + if (negated) { + bad_negation(fullname, TRUE); + return; + } + tmp = tolower(*op); + } + switch (tmp) { + case 's': /* single message history cycle (default if negated) */ + iflags.prevmsg_window = 's'; + break; + case 'c': /* combination: two singles, then full page reversed */ + iflags.prevmsg_window = 'c'; + break; + case 'f': /* full page (default if no opts) */ + iflags.prevmsg_window = 'f'; + break; + case 'r': /* full page (reversed) */ + iflags.prevmsg_window = 'r'; + break; + default: + badoption(opts); + } #endif - return; - } + return; + } - /* WINCAP - * setting font options */ - fullname = "font"; - if (!strncmpi(opts, fullname, 4)) { - int opttype = -1; - char *fontopts = opts + 4; + /* WINCAP + * setting font options */ + fullname = "font"; + if (!strncmpi(opts, fullname, 4)) { + int opttype = -1; + char *fontopts = opts + 4; - if (!strncmpi(fontopts, "map", 3) || - !strncmpi(fontopts, "_map", 4)) - opttype = MAP_OPTION; - else if (!strncmpi(fontopts, "message", 7) || - !strncmpi(fontopts, "_message", 8)) - opttype = MESSAGE_OPTION; - else if (!strncmpi(fontopts, "text", 4) || - !strncmpi(fontopts, "_text", 5)) - opttype = TEXT_OPTION; - else if (!strncmpi(fontopts, "menu", 4) || - !strncmpi(fontopts, "_menu", 5)) - opttype = MENU_OPTION; - else if (!strncmpi(fontopts, "status", 6) || - !strncmpi(fontopts, "_status", 7)) - opttype = STATUS_OPTION; - else if (!strncmpi(fontopts, "_size", 5)) { - if (!strncmpi(fontopts, "_size_map", 8)) - opttype = MAP_OPTION; - else if (!strncmpi(fontopts, "_size_message", 12)) - opttype = MESSAGE_OPTION; - else if (!strncmpi(fontopts, "_size_text", 9)) - opttype = TEXT_OPTION; - else if (!strncmpi(fontopts, "_size_menu", 9)) - opttype = MENU_OPTION; - else if (!strncmpi(fontopts, "_size_status", 11)) - opttype = STATUS_OPTION; - else { - badoption(opts); - return; - } - if (duplicate) complain_about_duplicate(opts,1); - if (opttype > 0 && !negated && - (op = string_for_opt(opts, FALSE)) != 0) { - switch(opttype) { - case MAP_OPTION: - iflags.wc_fontsiz_map = atoi(op); - break; - case MESSAGE_OPTION: - iflags.wc_fontsiz_message = atoi(op); - break; - case TEXT_OPTION: - iflags.wc_fontsiz_text = atoi(op); - break; - case MENU_OPTION: - iflags.wc_fontsiz_menu = atoi(op); - break; - case STATUS_OPTION: - iflags.wc_fontsiz_status = atoi(op); - break; - } - } - return; - } else { - badoption(opts); - } - if (opttype > 0 && - (op = string_for_opt(opts, FALSE)) != 0) { - wc_set_font_name(opttype, op); + if (!strncmpi(fontopts, "map", 3) || !strncmpi(fontopts, "_map", 4)) + opttype = MAP_OPTION; + else if (!strncmpi(fontopts, "message", 7) + || !strncmpi(fontopts, "_message", 8)) + opttype = MESSAGE_OPTION; + else if (!strncmpi(fontopts, "text", 4) + || !strncmpi(fontopts, "_text", 5)) + opttype = TEXT_OPTION; + else if (!strncmpi(fontopts, "menu", 4) + || !strncmpi(fontopts, "_menu", 5)) + opttype = MENU_OPTION; + else if (!strncmpi(fontopts, "status", 6) + || !strncmpi(fontopts, "_status", 7)) + opttype = STATUS_OPTION; + else if (!strncmpi(fontopts, "_size", 5)) { + if (!strncmpi(fontopts, "_size_map", 8)) + opttype = MAP_OPTION; + else if (!strncmpi(fontopts, "_size_message", 12)) + opttype = MESSAGE_OPTION; + else if (!strncmpi(fontopts, "_size_text", 9)) + opttype = TEXT_OPTION; + else if (!strncmpi(fontopts, "_size_menu", 9)) + opttype = MENU_OPTION; + else if (!strncmpi(fontopts, "_size_status", 11)) + opttype = STATUS_OPTION; + else { + badoption(opts); + return; + } + if (duplicate) + complain_about_duplicate(opts, 1); + if (opttype > 0 && !negated + && (op = string_for_opt(opts, FALSE)) != 0) { + switch (opttype) { + case MAP_OPTION: + iflags.wc_fontsiz_map = atoi(op); + break; + case MESSAGE_OPTION: + iflags.wc_fontsiz_message = atoi(op); + break; + case TEXT_OPTION: + iflags.wc_fontsiz_text = atoi(op); + break; + case MENU_OPTION: + iflags.wc_fontsiz_menu = atoi(op); + break; + case STATUS_OPTION: + iflags.wc_fontsiz_status = atoi(op); + break; + } + } + return; + } else { + badoption(opts); + } + if (opttype > 0 && (op = string_for_opt(opts, FALSE)) != 0) { + wc_set_font_name(opttype, op); #ifdef MAC - set_font_name (opttype, op); + set_font_name(opttype, op); #endif - return; - } else if (negated) bad_negation(fullname, TRUE); - return; - } + return; + } else if (negated) + bad_negation(fullname, TRUE); + return; + } #ifdef CHANGE_COLOR - if (match_optname(opts, "palette", 3, TRUE) -# ifdef MAC - || match_optname(opts, "hicolor", 3, TRUE) -# endif - ) { - int color_number, color_incr; + if (match_optname(opts, "palette", 3, TRUE) +#ifdef MAC + || match_optname(opts, "hicolor", 3, TRUE) +#endif + ) { + int color_number, color_incr; -# ifndef WIN32 - if (duplicate) complain_about_duplicate(opts,1); -# endif -# ifdef MAC - if (match_optname(opts, "hicolor", 3, TRUE)) { - if (negated) { - bad_negation("hicolor", FALSE); - return; - } - color_number = CLR_MAX + 4; /* HARDCODED inverse number */ - color_incr = -1; - } else { -# endif - if (negated) { - bad_negation("palette", FALSE); - return; - } - color_number = 0; - color_incr = 1; -# ifdef MAC - } -# endif +#ifndef WIN32 + if (duplicate) + complain_about_duplicate(opts, 1); +#endif +#ifdef MAC + if (match_optname(opts, "hicolor", 3, TRUE)) { + if (negated) { + bad_negation("hicolor", FALSE); + return; + } + color_number = CLR_MAX + 4; /* HARDCODED inverse number */ + color_incr = -1; + } else { +#endif + if (negated) { + bad_negation("palette", FALSE); + return; + } + color_number = 0; + color_incr = 1; +#ifdef MAC + } +#endif #ifdef WIN32 - op = string_for_opt(opts, TRUE); - if (!alternative_palette(op)) - badoption(opts); + op = string_for_opt(opts, TRUE); + if (!alternative_palette(op)) + badoption(opts); #else - if ((op = string_for_opt(opts, FALSE)) != (char *)0) { - char *pt = op; - int cnt, tmp, reverse; - long rgb; + if ((op = string_for_opt(opts, FALSE)) != (char *) 0) { + char *pt = op; + int cnt, tmp, reverse; + long rgb; - while (*pt && color_number >= 0) { - cnt = 3; - rgb = 0L; - if (*pt == '-') { - reverse = 1; - pt++; - } else { - reverse = 0; - } - while (cnt-- > 0) { - if (*pt && *pt != '/') { -# ifdef AMIGA - rgb <<= 4; -# else - rgb <<= 8; -# endif - tmp = *(pt++); - if (isalpha(tmp)) { - tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */ - } else { - tmp &= 0xf; /* Digits in ASCII too... */ - } -# ifndef AMIGA - /* Add an extra so we fill f -> ff and 0 -> 00 */ - rgb += tmp << 4; -# endif - rgb += tmp; - } - } - if (*pt == '/') { - pt++; - } - change_color(color_number, rgb, reverse); - color_number += color_incr; - } - } -# endif /* !WIN32 */ - if (!initial) { - need_redraw = TRUE; - } - return; - } + while (*pt && color_number >= 0) { + cnt = 3; + rgb = 0L; + if (*pt == '-') { + reverse = 1; + pt++; + } else { + reverse = 0; + } + while (cnt-- > 0) { + if (*pt && *pt != '/') { +#ifdef AMIGA + rgb <<= 4; +#else + rgb <<= 8; +#endif + tmp = *(pt++); + if (isalpha(tmp)) { + tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */ + } else { + tmp &= 0xf; /* Digits in ASCII too... */ + } +#ifndef AMIGA + /* Add an extra so we fill f -> ff and 0 -> 00 */ + rgb += tmp << 4; +#endif + rgb += tmp; + } + } + if (*pt == '/') { + pt++; + } + change_color(color_number, rgb, reverse); + color_number += color_incr; + } + } +#endif /* !WIN32 */ + if (!initial) { + need_redraw = TRUE; + } + return; + } #endif /* CHANGE_COLOR */ - if (match_optname(opts, "fruit", 2, TRUE)) { - struct fruit *forig = 0; + if (match_optname(opts, "fruit", 2, TRUE)) { + struct fruit *forig = 0; - char empty_str = '\0'; - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if (negated) { - if (op) { - bad_negation("fruit", TRUE); - return; - } - op = &empty_str; - goto goodfruit; - } - if (!op) return; - if (!initial) { - struct fruit *f; + char empty_str = '\0'; + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if (negated) { + if (op) { + bad_negation("fruit", TRUE); + return; + } + op = &empty_str; + goto goodfruit; + } + if (!op) + return; + if (!initial) { + struct fruit *f; - num = 0; - for(f=ffruit; f; f=f->nextf) { - if (!strcmp(op, f->fname)) - break; - num++; - } - if (!flags.made_fruit) { - for(forig=ffruit; forig; forig=forig->nextf) { - if (!strcmp(pl_fruit, forig->fname)) { - break; - } - } - } - if (!forig && num >= 100) { - pline("Doing that so many times isn't very fruitful."); - return; - } - } -goodfruit: - nmcpy(pl_fruit, op, PL_FSIZ); - sanitize_name(pl_fruit); - /* OBJ_NAME(objects[SLIME_MOLD]) won't work after initialization */ - if (!*pl_fruit) - nmcpy(pl_fruit, "slime mold", PL_FSIZ); - if (!initial) { - (void)fruitadd(pl_fruit, forig); - pline("Fruit is now \"%s\".", pl_fruit); - } - /* If initial, then initoptions is allowed to do it instead - * of here (initoptions always has to do it even if there's - * no fruit option at all. Also, we don't want people - * setting multiple fruits in their options.) - */ - return; - } + num = 0; + for (f = ffruit; f; f = f->nextf) { + if (!strcmp(op, f->fname)) + break; + num++; + } + if (!flags.made_fruit) { + for (forig = ffruit; forig; forig = forig->nextf) { + if (!strcmp(pl_fruit, forig->fname)) { + break; + } + } + } + if (!forig && num >= 100) { + pline("Doing that so many times isn't very fruitful."); + return; + } + } + goodfruit: + nmcpy(pl_fruit, op, PL_FSIZ); + sanitize_name(pl_fruit); + /* OBJ_NAME(objects[SLIME_MOLD]) won't work after initialization */ + if (!*pl_fruit) + nmcpy(pl_fruit, "slime mold", PL_FSIZ); + if (!initial) { + (void) fruitadd(pl_fruit, forig); + pline("Fruit is now \"%s\".", pl_fruit); + } + /* If initial, then initoptions is allowed to do it instead + * of here (initoptions always has to do it even if there's + * no fruit option at all. Also, we don't want people + * setting multiple fruits in their options.) + */ + return; + } - fullname = "warnings"; - if (match_optname(opts, fullname, 5, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else warning_opts(opts, fullname); - return; - } + fullname = "warnings"; + if (match_optname(opts, fullname, 5, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else + warning_opts(opts, fullname); + return; + } #ifdef BACKWARD_COMPAT - /* boulder:symbol */ - fullname = "boulder"; - if (match_optname(opts, fullname, 7, TRUE)) { - int clash = 0; - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } -/* if (!(opts = string_for_env_opt(fullname, opts, FALSE))) */ - if (!(opts = string_for_opt(opts, FALSE))) - return; - escapes(opts, opts); - if (def_char_to_monclass(opts[0]) != MAXMCLASSES) - clash = 1; - else if (opts[0] >= '1' && opts[0] <= '5') - clash = 2; - if (clash) { - /* symbol chosen matches a used monster or warning - symbol which is not good - reject it*/ - pline( - "Badoption - boulder symbol '%c' conflicts with a %s symbol.", - opts[0], (clash == 1) ? "monster" : "warning"); - } else { - /* - * Override the default boulder symbol. - */ - iflags.bouldersym = (uchar) opts[0]; - } - if (!initial) need_redraw = TRUE; - return; - } + /* boulder:symbol */ + fullname = "boulder"; + if (match_optname(opts, fullname, 7, TRUE)) { + int clash = 0; + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } + /* if (!(opts = string_for_env_opt(fullname, opts, FALSE))) + */ + if (!(opts = string_for_opt(opts, FALSE))) + return; + escapes(opts, opts); + if (def_char_to_monclass(opts[0]) != MAXMCLASSES) + clash = 1; + else if (opts[0] >= '1' && opts[0] <= '5') + clash = 2; + if (clash) { + /* symbol chosen matches a used monster or warning + symbol which is not good - reject it*/ + pline( + "Badoption - boulder symbol '%c' conflicts with a %s symbol.", + opts[0], (clash == 1) ? "monster" : "warning"); + } else { + /* + * Override the default boulder symbol. + */ + iflags.bouldersym = (uchar) opts[0]; + } + if (!initial) + need_redraw = TRUE; + return; + } #endif - /* name:string */ - fullname = "name"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) - nmcpy(plname, op, PL_NSIZ); - return; - } + /* name:string */ + fullname = "name"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(plname, op, PL_NSIZ); + return; + } - /* altkeyhandler:string */ - fullname = "altkeyhandler"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) bad_negation(fullname, FALSE); - else if ((op = string_for_opt(opts, negated))) { + /* altkeyhandler:string */ + fullname = "altkeyhandler"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_opt(opts, negated))) { #ifdef WIN32 - (void)strncpy(iflags.altkeyhandler, op, MAX_ALTKEYHANDLER - 5); - load_keyboard_handler(); + (void) strncpy(iflags.altkeyhandler, op, MAX_ALTKEYHANDLER - 5); + load_keyboard_handler(); #endif - } - return; - } + } + return; + } - /* WINCAP - * align_status:[left|top|right|bottom] */ - fullname = "align_status"; - if (match_optname(opts, fullname, sizeof("align_status")-1, TRUE)) { - op = string_for_opt(opts, negated); - if (op && !negated) { - if (!strncmpi (op, "left", sizeof("left")-1)) - iflags.wc_align_status = ALIGN_LEFT; - else if (!strncmpi (op, "top", sizeof("top")-1)) - iflags.wc_align_status = ALIGN_TOP; - else if (!strncmpi (op, "right", sizeof("right")-1)) - iflags.wc_align_status = ALIGN_RIGHT; - else if (!strncmpi (op, "bottom", sizeof("bottom")-1)) - iflags.wc_align_status = ALIGN_BOTTOM; - else - badoption(opts); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* WINCAP - * align_message:[left|top|right|bottom] */ - fullname = "align_message"; - if (match_optname(opts, fullname, sizeof("align_message")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if (op && !negated) { - if (!strncmpi (op, "left", sizeof("left")-1)) - iflags.wc_align_message = ALIGN_LEFT; - else if (!strncmpi (op, "top", sizeof("top")-1)) - iflags.wc_align_message = ALIGN_TOP; - else if (!strncmpi (op, "right", sizeof("right")-1)) - iflags.wc_align_message = ALIGN_RIGHT; - else if (!strncmpi (op, "bottom", sizeof("bottom")-1)) - iflags.wc_align_message = ALIGN_BOTTOM; - else - badoption(opts); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* the order to list the pack */ - fullname = "packorder"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } else if (!(op = string_for_opt(opts, FALSE))) return; + /* WINCAP + * align_status:[left|top|right|bottom] */ + fullname = "align_status"; + if (match_optname(opts, fullname, sizeof("align_status") - 1, TRUE)) { + op = string_for_opt(opts, negated); + if (op && !negated) { + if (!strncmpi(op, "left", sizeof("left") - 1)) + iflags.wc_align_status = ALIGN_LEFT; + else if (!strncmpi(op, "top", sizeof("top") - 1)) + iflags.wc_align_status = ALIGN_TOP; + else if (!strncmpi(op, "right", sizeof("right") - 1)) + iflags.wc_align_status = ALIGN_RIGHT; + else if (!strncmpi(op, "bottom", sizeof("bottom") - 1)) + iflags.wc_align_status = ALIGN_BOTTOM; + else + badoption(opts); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* WINCAP + * align_message:[left|top|right|bottom] */ + fullname = "align_message"; + if (match_optname(opts, fullname, sizeof("align_message") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if (op && !negated) { + if (!strncmpi(op, "left", sizeof("left") - 1)) + iflags.wc_align_message = ALIGN_LEFT; + else if (!strncmpi(op, "top", sizeof("top") - 1)) + iflags.wc_align_message = ALIGN_TOP; + else if (!strncmpi(op, "right", sizeof("right") - 1)) + iflags.wc_align_message = ALIGN_RIGHT; + else if (!strncmpi(op, "bottom", sizeof("bottom") - 1)) + iflags.wc_align_message = ALIGN_BOTTOM; + else + badoption(opts); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* the order to list the pack */ + fullname = "packorder"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(op = string_for_opt(opts, FALSE))) + return; - if (!change_inv_order(op)) - badoption(opts); - return; - } + if (!change_inv_order(op)) + badoption(opts); + return; + } - /* user can change required response for some prompts (quit, die, hit), - or add an extra prompt (pray, Remove) that isn't ordinarily there */ - fullname = "paranoid_confirmation"; - if (match_optname(opts, fullname, 8, TRUE)) { - /* at present we don't complain about duplicates for this - option, but we do throw away the old settings whenever - we process a new one [clearing old flags is essential - for handling default paranoid_confirm:pray sanely] */ - flags.paranoia_bits = 0; /* clear all */ - if (negated) { - flags.paranoia_bits = 0; /* [now redundant...] */ - } else if ((op = string_for_opt(opts, TRUE)) != 0) { - char *pp, buf[BUFSZ]; + /* user can change required response for some prompts (quit, die, hit), + or add an extra prompt (pray, Remove) that isn't ordinarily there */ + fullname = "paranoid_confirmation"; + if (match_optname(opts, fullname, 8, TRUE)) { + /* at present we don't complain about duplicates for this + option, but we do throw away the old settings whenever + we process a new one [clearing old flags is essential + for handling default paranoid_confirm:pray sanely] */ + flags.paranoia_bits = 0; /* clear all */ + if (negated) { + flags.paranoia_bits = 0; /* [now redundant...] */ + } else if ((op = string_for_opt(opts, TRUE)) != 0) { + char *pp, buf[BUFSZ]; - op = mungspaces(strcpy(buf, op)); - for (;;) { - /* We're looking to parse - "paranoid_confirm:whichone wheretwo whothree" - and "paranoid_confirm:" prefix has already - been stripped off by the time we get here */ - pp = index(op, ' '); - if (pp) *pp = '\0'; - /* we aren't matching option names but match_optname - does what we want once we've broken the space - delimited aggregate into separate tokens */ - for (i = 0; i < SIZE(paranoia); ++i) { - if (match_optname(op, paranoia[i].argname, - paranoia[i].argMinLen, FALSE) || - (paranoia[i].synonym && - match_optname(op, paranoia[i].synonym, - paranoia[i].synMinLen, FALSE))) { - if (paranoia[i].flagmask) - flags.paranoia_bits |= paranoia[i].flagmask; - else /* 0 == "none", so clear all */ - flags.paranoia_bits = 0; - break; - } - } - if (i == SIZE(paranoia)) { - /* didn't match anything, so arg is bad; - any flags already set will stay set */ - badoption(opts); - break; - } - /* move on to next token */ - if (pp) op = pp + 1; - else break; /* no next token */ - } /* for(;;) */ - } - return; - } + op = mungspaces(strcpy(buf, op)); + for (;;) { + /* We're looking to parse + "paranoid_confirm:whichone wheretwo whothree" + and "paranoid_confirm:" prefix has already + been stripped off by the time we get here */ + pp = index(op, ' '); + if (pp) + *pp = '\0'; + /* we aren't matching option names but match_optname + does what we want once we've broken the space + delimited aggregate into separate tokens */ + for (i = 0; i < SIZE(paranoia); ++i) { + if (match_optname(op, paranoia[i].argname, + paranoia[i].argMinLen, FALSE) + || (paranoia[i].synonym + && match_optname(op, paranoia[i].synonym, + paranoia[i].synMinLen, FALSE))) { + if (paranoia[i].flagmask) + flags.paranoia_bits |= paranoia[i].flagmask; + else /* 0 == "none", so clear all */ + flags.paranoia_bits = 0; + break; + } + } + if (i == SIZE(paranoia)) { + /* didn't match anything, so arg is bad; + any flags already set will stay set */ + badoption(opts); + break; + } + /* move on to next token */ + if (pp) + op = pp + 1; + else + break; /* no next token */ + } /* for(;;) */ + } + return; + } - /* accept deprecated boolean; superseded by paranoid_confirm:pray */ - fullname = "prayconfirm"; - if (match_optname(opts, fullname, 4, FALSE)) { - if (negated) - flags.paranoia_bits &= ~PARANOID_PRAY; - else - flags.paranoia_bits |= PARANOID_PRAY; - return; - } + /* accept deprecated boolean; superseded by paranoid_confirm:pray */ + fullname = "prayconfirm"; + if (match_optname(opts, fullname, 4, FALSE)) { + if (negated) + flags.paranoia_bits &= ~PARANOID_PRAY; + else + flags.paranoia_bits |= PARANOID_PRAY; + return; + } - /* maximum burden picked up before prompt (Warren Cheung) */ - fullname = "pickup_burden"; - if (match_optname(opts, fullname, 8, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - switch (tolower(*op)) { - /* Unencumbered */ - case 'u': - flags.pickup_burden = UNENCUMBERED; - break; - /* Burdened (slight encumbrance) */ - case 'b': - flags.pickup_burden = SLT_ENCUMBER; - break; - /* streSsed (moderate encumbrance) */ - case 's': - flags.pickup_burden = MOD_ENCUMBER; - break; - /* straiNed (heavy encumbrance) */ - case 'n': - flags.pickup_burden = HVY_ENCUMBER; - break; - /* OverTaxed (extreme encumbrance) */ - case 'o': - case 't': - flags.pickup_burden = EXT_ENCUMBER; - break; - /* overLoaded */ - case 'l': - flags.pickup_burden = OVERLOADED; - break; - default: - badoption(opts); - } - } - return; - } + /* maximum burden picked up before prompt (Warren Cheung) */ + fullname = "pickup_burden"; + if (match_optname(opts, fullname, 8, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + switch (tolower(*op)) { + /* Unencumbered */ + case 'u': + flags.pickup_burden = UNENCUMBERED; + break; + /* Burdened (slight encumbrance) */ + case 'b': + flags.pickup_burden = SLT_ENCUMBER; + break; + /* streSsed (moderate encumbrance) */ + case 's': + flags.pickup_burden = MOD_ENCUMBER; + break; + /* straiNed (heavy encumbrance) */ + case 'n': + flags.pickup_burden = HVY_ENCUMBER; + break; + /* OverTaxed (extreme encumbrance) */ + case 'o': + case 't': + flags.pickup_burden = EXT_ENCUMBER; + break; + /* overLoaded */ + case 'l': + flags.pickup_burden = OVERLOADED; + break; + default: + badoption(opts); + } + } + return; + } - /* types of objects to pick up automatically */ - if (match_optname(opts, "pickup_types", 8, TRUE)) { - char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], - qbuf[QBUFSZ], abuf[BUFSZ]; - int oc_sym; - boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu; + /* types of objects to pick up automatically */ + if (match_optname(opts, "pickup_types", 8, TRUE)) { + char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], qbuf[QBUFSZ], + abuf[BUFSZ]; + int oc_sym; + boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu; - if (duplicate) complain_about_duplicate(opts,1); - oc_to_str(flags.pickup_types, tbuf); - flags.pickup_types[0] = '\0'; /* all */ - op = string_for_opt(opts, (compat || !initial)); - if (!op) { - if (compat || negated || initial) { - /* for backwards compatibility, "pickup" without a - value is a synonym for autopickup of all types - (and during initialization, we can't prompt yet) */ - flags.pickup = !negated; - return; - } - oc_to_str(flags.inv_order, ocl); - use_menu = TRUE; - if (flags.menu_style == MENU_TRADITIONAL || - flags.menu_style == MENU_COMBINATION) { - use_menu = FALSE; - Sprintf(qbuf, "New pickup_types: [%s am] (%s)", - ocl, *tbuf ? tbuf : "all"); - getlin(qbuf, abuf); - op = mungspaces(abuf); - if (abuf[0] == '\0' || abuf[0] == '\033') - op = tbuf; /* restore */ - else if (abuf[0] == 'm') - use_menu = TRUE; - } - if (use_menu) { - (void) choose_classes_menu("Auto-Pickup what?", 1, - TRUE, ocl, tbuf); - op = tbuf; - } - } - if (negated) { - bad_negation("pickup_types", TRUE); - return; - } - while (*op == ' ') op++; - if (*op != 'a' && *op != 'A') { - num = 0; - while (*op) { - oc_sym = def_char_to_objclass(*op); - /* make sure all are valid obj symbols occuring once */ - if (oc_sym != MAXOCLASSES && - !index(flags.pickup_types, oc_sym)) { - flags.pickup_types[num] = (char)oc_sym; - flags.pickup_types[++num] = '\0'; - } else - badopt = TRUE; - op++; - } - if (badopt) badoption(opts); - } - return; - } + if (duplicate) + complain_about_duplicate(opts, 1); + oc_to_str(flags.pickup_types, tbuf); + flags.pickup_types[0] = '\0'; /* all */ + op = string_for_opt(opts, (compat || !initial)); + if (!op) { + if (compat || negated || initial) { + /* for backwards compatibility, "pickup" without a + value is a synonym for autopickup of all types + (and during initialization, we can't prompt yet) */ + flags.pickup = !negated; + return; + } + oc_to_str(flags.inv_order, ocl); + use_menu = TRUE; + if (flags.menu_style == MENU_TRADITIONAL + || flags.menu_style == MENU_COMBINATION) { + use_menu = FALSE; + Sprintf(qbuf, "New pickup_types: [%s am] (%s)", ocl, + *tbuf ? tbuf : "all"); + getlin(qbuf, abuf); + op = mungspaces(abuf); + if (abuf[0] == '\0' || abuf[0] == '\033') + op = tbuf; /* restore */ + else if (abuf[0] == 'm') + use_menu = TRUE; + } + if (use_menu) { + (void) choose_classes_menu("Auto-Pickup what?", 1, TRUE, ocl, + tbuf); + op = tbuf; + } + } + if (negated) { + bad_negation("pickup_types", TRUE); + return; + } + while (*op == ' ') + op++; + if (*op != 'a' && *op != 'A') { + num = 0; + while (*op) { + oc_sym = def_char_to_objclass(*op); + /* make sure all are valid obj symbols occuring once */ + if (oc_sym != MAXOCLASSES + && !index(flags.pickup_types, oc_sym)) { + flags.pickup_types[num] = (char) oc_sym; + flags.pickup_types[++num] = '\0'; + } else + badopt = TRUE; + op++; + } + if (badopt) + badoption(opts); + } + return; + } - /* pile limit: when walking over objects, number which triggers - "there are several/many objects here" instead of listing them */ - fullname = "pile_limit"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts, 1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) - flags.pile_limit = negated ? 0 : atoi(op); - else if (negated) - bad_negation(fullname, TRUE); - else /* !op */ - flags.pile_limit = PILE_LIMIT_DFLT; - /* sanity check */ - if (flags.pile_limit < 0) flags.pile_limit = PILE_LIMIT_DFLT; - return; - } + /* pile limit: when walking over objects, number which triggers + "there are several/many objects here" instead of listing them */ + fullname = "pile_limit"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) + flags.pile_limit = negated ? 0 : atoi(op); + else if (negated) + bad_negation(fullname, TRUE); + else /* !op */ + flags.pile_limit = PILE_LIMIT_DFLT; + /* sanity check */ + if (flags.pile_limit < 0) + flags.pile_limit = PILE_LIMIT_DFLT; + return; + } - /* play mode: normal, explore/discovery, or debug/wizard */ - fullname = "playmode"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts, 1); - if (negated) bad_negation(fullname, FALSE); - if (duplicate || negated) return; - op = string_for_opt(opts, TRUE); - if (!strncmpi(op, "normal", 6) || !strcmpi(op, "play")) { - wizard = discover = FALSE; - } else if (!strncmpi(op, "explore", 6) || - !strncmpi(op, "discovery", 6)) { - wizard = FALSE, discover = TRUE; - } else if (!strncmpi(op, "debug", 5) || - !strncmpi(op, "wizard", 6)) { - wizard = TRUE, discover = FALSE; - } else { - raw_printf("Invalid value for \"%s\":%s.", fullname, op); - } - return; - } + /* play mode: normal, explore/discovery, or debug/wizard */ + fullname = "playmode"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) + bad_negation(fullname, FALSE); + if (duplicate || negated) + return; + op = string_for_opt(opts, TRUE); + if (!strncmpi(op, "normal", 6) || !strcmpi(op, "play")) { + wizard = discover = FALSE; + } else if (!strncmpi(op, "explore", 6) + || !strncmpi(op, "discovery", 6)) { + wizard = FALSE, discover = TRUE; + } else if (!strncmpi(op, "debug", 5) || !strncmpi(op, "wizard", 6)) { + wizard = TRUE, discover = FALSE; + } else { + raw_printf("Invalid value for \"%s\":%s.", fullname, op); + } + return; + } - /* WINCAP - * player_selection: dialog | prompts */ - fullname = "player_selection"; - if (match_optname(opts, fullname, sizeof("player_selection")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if (op && !negated) { - if (!strncmpi(op, "dialog", sizeof("dialog")-1)) - iflags.wc_player_selection = VIA_DIALOG; - else if (!strncmpi(op, "prompt", sizeof("prompt")-1)) - iflags.wc_player_selection = VIA_PROMPTS; - else - badoption(opts); - } else if (negated) bad_negation(fullname, TRUE); - return; - } + /* WINCAP + * player_selection: dialog | prompts */ + fullname = "player_selection"; + if (match_optname(opts, fullname, sizeof("player_selection") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if (op && !negated) { + if (!strncmpi(op, "dialog", sizeof("dialog") - 1)) + iflags.wc_player_selection = VIA_DIALOG; + else if (!strncmpi(op, "prompt", sizeof("prompt") - 1)) + iflags.wc_player_selection = VIA_PROMPTS; + else + badoption(opts); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } - /* things to disclose at end of game */ - if (match_optname(opts, "disclose", 7, TRUE)) { - /* - * The order that the end_disclore options are stored: - * inventory, attribs, vanquished, genocided, - * conduct, overview. - * There is an array in flags: - * end_disclose[NUM_DISCLOSURE_OPT]; - * with option settings for the each of the following: - * iagvc [see disclosure_options in decl.c]: - * Legal setting values in that array are: - * DISCLOSE_PROMPT_DEFAULT_YES ask with default answer yes - * DISCLOSE_PROMPT_DEFAULT_NO ask with default answer no - * DISCLOSE_YES_WITHOUT_PROMPT always disclose and don't ask - * DISCLOSE_NO_WITHOUT_PROMPT never disclose and don't ask - * - * Those setting values can be used in the option - * string as a prefix to get the desired behaviour. - * - * For backward compatibility, no prefix is required, - * and the presence of a i,a,g,v, or c without a prefix - * sets the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT. - */ - boolean badopt = FALSE; - int idx, prefix_val; - - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, TRUE); - if (op && negated) { - bad_negation("disclose", TRUE); - return; - } - /* "disclose" without a value means "all with prompting" - and negated means "none without prompting" */ - if (!op || !strcmpi(op, "all") || !strcmpi(op, "none")) { - if (op && !strcmpi(op, "none")) negated = TRUE; - for (num = 0; num < NUM_DISCLOSURE_OPTIONS; num++) - flags.end_disclose[num] = negated ? - DISCLOSE_NO_WITHOUT_PROMPT : - DISCLOSE_PROMPT_DEFAULT_YES; - return; - } - - num = 0; - prefix_val = -1; - while (*op && num < sizeof flags.end_disclose - 1) { - static char valid_settings[] = { - DISCLOSE_PROMPT_DEFAULT_YES, - DISCLOSE_PROMPT_DEFAULT_NO, - DISCLOSE_YES_WITHOUT_PROMPT, - DISCLOSE_NO_WITHOUT_PROMPT, - '\0' - }; - register char c, *dop; + /* things to disclose at end of game */ + if (match_optname(opts, "disclose", 7, TRUE)) { + /* + * The order that the end_disclore options are stored: + * inventory, attribs, vanquished, genocided, + * conduct, overview. + * There is an array in flags: + * end_disclose[NUM_DISCLOSURE_OPT]; + * with option settings for the each of the following: + * iagvc [see disclosure_options in decl.c]: + * Legal setting values in that array are: + * DISCLOSE_PROMPT_DEFAULT_YES ask with default answer yes + * DISCLOSE_PROMPT_DEFAULT_NO ask with default answer no + * DISCLOSE_YES_WITHOUT_PROMPT always disclose and don't ask + * DISCLOSE_NO_WITHOUT_PROMPT never disclose and don't ask + * + * Those setting values can be used in the option + * string as a prefix to get the desired behaviour. + * + * For backward compatibility, no prefix is required, + * and the presence of a i,a,g,v, or c without a prefix + * sets the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT. + */ + boolean badopt = FALSE; + int idx, prefix_val; - c = lowc(*op); - if (c == 'k') c = 'v'; /* killed -> vanquished */ - if (c == 'd') c = 'o'; /* dungeon -> overview */ - dop = index(disclosure_options, c); - if (dop) { - idx = (int)(dop - disclosure_options); - if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) { - impossible("bad disclosure index %d %c", idx, c); - continue; - } - if (prefix_val != -1) { - flags.end_disclose[idx] = prefix_val; - prefix_val = -1; - } else - flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT; - } else if (index(valid_settings, c)) { - prefix_val = c; - } else if (c == ' ') { - ; /* do nothing */ - } else - badopt = TRUE; - op++; - } - if (badopt) badoption(opts); - return; - } + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, TRUE); + if (op && negated) { + bad_negation("disclose", TRUE); + return; + } + /* "disclose" without a value means "all with prompting" + and negated means "none without prompting" */ + if (!op || !strcmpi(op, "all") || !strcmpi(op, "none")) { + if (op && !strcmpi(op, "none")) + negated = TRUE; + for (num = 0; num < NUM_DISCLOSURE_OPTIONS; num++) + flags.end_disclose[num] = negated + ? DISCLOSE_NO_WITHOUT_PROMPT + : DISCLOSE_PROMPT_DEFAULT_YES; + return; + } - /* scores:5t[op] 5a[round] o[wn] */ - if (match_optname(opts, "scores", 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation("scores", FALSE); - return; - } - if (!(op = string_for_opt(opts, FALSE))) return; + num = 0; + prefix_val = -1; + while (*op && num < sizeof flags.end_disclose - 1) { + static char valid_settings[] = { + DISCLOSE_PROMPT_DEFAULT_YES, DISCLOSE_PROMPT_DEFAULT_NO, + DISCLOSE_YES_WITHOUT_PROMPT, DISCLOSE_NO_WITHOUT_PROMPT, '\0' + }; + register char c, *dop; - while (*op) { - int inum = 1; + c = lowc(*op); + if (c == 'k') + c = 'v'; /* killed -> vanquished */ + if (c == 'd') + c = 'o'; /* dungeon -> overview */ + dop = index(disclosure_options, c); + if (dop) { + idx = (int) (dop - disclosure_options); + if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) { + impossible("bad disclosure index %d %c", idx, c); + continue; + } + if (prefix_val != -1) { + flags.end_disclose[idx] = prefix_val; + prefix_val = -1; + } else + flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT; + } else if (index(valid_settings, c)) { + prefix_val = c; + } else if (c == ' ') { + ; /* do nothing */ + } else + badopt = TRUE; + op++; + } + if (badopt) + badoption(opts); + return; + } - if (digit(*op)) { - inum = atoi(op); - while (digit(*op)) op++; - } else if (*op == '!') { - negated = !negated; - op++; - } - while (*op == ' ') op++; + /* scores:5t[op] 5a[round] o[wn] */ + if (match_optname(opts, "scores", 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation("scores", FALSE); + return; + } + if (!(op = string_for_opt(opts, FALSE))) + return; - switch (*op) { - case 't': - case 'T': flags.end_top = inum; - break; - case 'a': - case 'A': flags.end_around = inum; - break; - case 'o': - case 'O': flags.end_own = !negated; - break; - default: badoption(opts); - return; - } - while (letter(*++op) || *op == ' ') continue; - if (*op == '/') op++; - } - return; - } + while (*op) { + int inum = 1; - fullname = "sortloot"; - if (match_optname(opts, fullname, 4, TRUE)) { - op = string_for_env_opt(fullname, opts, FALSE); - if (op) { - switch (tolower(*op)) { - case 'n': - case 'l': - case 'f': flags.sortloot = tolower(*op); - break; - default: badoption(opts); - return; - } - } - return; - } + if (digit(*op)) { + inum = atoi(op); + while (digit(*op)) + op++; + } else if (*op == '!') { + negated = !negated; + op++; + } + while (*op == ' ') + op++; - fullname = "suppress_alert"; - if (match_optname(opts, fullname, 4, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if (negated) bad_negation(fullname, FALSE); - else if (op) (void) feature_alert_opts(op,fullname); - return; - } + switch (*op) { + case 't': + case 'T': + flags.end_top = inum; + break; + case 'a': + case 'A': + flags.end_around = inum; + break; + case 'o': + case 'O': + flags.end_own = !negated; + break; + default: + badoption(opts); + return; + } + while (letter(*++op) || *op == ' ') + continue; + if (*op == '/') + op++; + } + return; + } + + fullname = "sortloot"; + if (match_optname(opts, fullname, 4, TRUE)) { + op = string_for_env_opt(fullname, opts, FALSE); + if (op) { + switch (tolower(*op)) { + case 'n': + case 'l': + case 'f': + flags.sortloot = tolower(*op); + break; + default: + badoption(opts); + return; + } + } + return; + } + + fullname = "suppress_alert"; + if (match_optname(opts, fullname, 4, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if (negated) + bad_negation(fullname, FALSE); + else if (op) + (void) feature_alert_opts(op, fullname); + return; + } #ifdef VIDEOSHADES - /* videocolors:string */ - fullname = "videocolors"; - if (match_optname(opts, fullname, 6, TRUE) || - match_optname(opts, "videocolours", 10, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } - else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { - return; - } - if (!assign_videocolors(opts)) - badoption(opts); - return; - } - /* videoshades:string */ - fullname = "videoshades"; - if (match_optname(opts, fullname, 6, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } - else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { - return; - } - if (!assign_videoshades(opts)) - badoption(opts); - return; - } + /* videocolors:string */ + fullname = "videocolors"; + if (match_optname(opts, fullname, 6, TRUE) + || match_optname(opts, "videocolours", 10, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { + return; + } + if (!assign_videocolors(opts)) + badoption(opts); + return; + } + /* videoshades:string */ + fullname = "videoshades"; + if (match_optname(opts, fullname, 6, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { + return; + } + if (!assign_videoshades(opts)) + badoption(opts); + return; + } #endif /* VIDEOSHADES */ #ifdef MSDOS -# ifdef NO_TERMS - /* video:string -- must be after longer tests */ - fullname = "video"; - if (match_optname(opts, fullname, 5, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } - else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { - return; - } - if (!assign_video(opts)) - badoption(opts); - return; - } -# endif /* NO_TERMS */ - /* soundcard:string -- careful not to match boolean 'sound' */ - fullname = "soundcard"; - if (match_optname(opts, fullname, 6, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } - else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { - return; - } - if (!assign_soundcard(opts)) - badoption(opts); - return; - } +#ifdef NO_TERMS + /* video:string -- must be after longer tests */ + fullname = "video"; + if (match_optname(opts, fullname, 5, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { + return; + } + if (!assign_video(opts)) + badoption(opts); + return; + } +#endif /* NO_TERMS */ + /* soundcard:string -- careful not to match boolean 'sound' */ + fullname = "soundcard"; + if (match_optname(opts, fullname, 6, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { + return; + } + if (!assign_soundcard(opts)) + badoption(opts); + return; + } #endif /* MSDOS */ - /* WINCAP - * map_mode:[tiles|ascii4x6|ascii6x8|ascii8x8|ascii16x8|ascii7x12|ascii8x12| - ascii16x12|ascii12x16|ascii10x18|fit_to_screen] */ - fullname = "map_mode"; - if (match_optname(opts, fullname, sizeof("map_mode")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if (op && !negated) { - if (!strncmpi (op, "tiles", sizeof("tiles")-1)) - iflags.wc_map_mode = MAP_MODE_TILES; - else if (!strncmpi (op, "ascii4x6", sizeof("ascii4x6")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII4x6; - else if (!strncmpi (op, "ascii6x8", sizeof("ascii6x8")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII6x8; - else if (!strncmpi (op, "ascii8x8", sizeof("ascii8x8")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII8x8; - else if (!strncmpi (op, "ascii16x8", sizeof("ascii16x8")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII16x8; - else if (!strncmpi (op, "ascii7x12", sizeof("ascii7x12")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII7x12; - else if (!strncmpi (op, "ascii8x12", sizeof("ascii8x12")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII8x12; - else if (!strncmpi (op, "ascii16x12", sizeof("ascii16x12")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII16x12; - else if (!strncmpi (op, "ascii12x16", sizeof("ascii12x16")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII12x16; - else if (!strncmpi (op, "ascii10x18", sizeof("ascii10x18")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII10x18; - else if (!strncmpi (op, "fit_to_screen", sizeof("fit_to_screen")-1)) - iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN; - else - badoption(opts); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* WINCAP - * scroll_amount:nn */ - fullname = "scroll_amount"; - if (match_optname(opts, fullname, sizeof("scroll_amount")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.wc_scroll_amount = negated ? 1 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* WINCAP - * scroll_margin:nn */ - fullname = "scroll_margin"; - if (match_optname(opts, fullname, sizeof("scroll_margin")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.wc_scroll_margin = negated ? 5 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - fullname = "subkeyvalue"; - if (match_optname(opts, fullname, 5, TRUE)) { - /* no duplicate complaint here */ - if (negated) bad_negation(fullname, FALSE); - else { + /* WINCAP + * + map_mode:[tiles|ascii4x6|ascii6x8|ascii8x8|ascii16x8|ascii7x12|ascii8x12| + ascii16x12|ascii12x16|ascii10x18|fit_to_screen] */ + fullname = "map_mode"; + if (match_optname(opts, fullname, sizeof("map_mode") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if (op && !negated) { + if (!strncmpi(op, "tiles", sizeof("tiles") - 1)) + iflags.wc_map_mode = MAP_MODE_TILES; + else if (!strncmpi(op, "ascii4x6", sizeof("ascii4x6") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII4x6; + else if (!strncmpi(op, "ascii6x8", sizeof("ascii6x8") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII6x8; + else if (!strncmpi(op, "ascii8x8", sizeof("ascii8x8") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII8x8; + else if (!strncmpi(op, "ascii16x8", sizeof("ascii16x8") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII16x8; + else if (!strncmpi(op, "ascii7x12", sizeof("ascii7x12") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII7x12; + else if (!strncmpi(op, "ascii8x12", sizeof("ascii8x12") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII8x12; + else if (!strncmpi(op, "ascii16x12", sizeof("ascii16x12") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII16x12; + else if (!strncmpi(op, "ascii12x16", sizeof("ascii12x16") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII12x16; + else if (!strncmpi(op, "ascii10x18", sizeof("ascii10x18") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII10x18; + else if (!strncmpi(op, "fit_to_screen", + sizeof("fit_to_screen") - 1)) + iflags.wc_map_mode = MAP_MODE_ASCII_FIT_TO_SCREEN; + else + badoption(opts); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* WINCAP + * scroll_amount:nn */ + fullname = "scroll_amount"; + if (match_optname(opts, fullname, sizeof("scroll_amount") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.wc_scroll_amount = negated ? 1 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* WINCAP + * scroll_margin:nn */ + fullname = "scroll_margin"; + if (match_optname(opts, fullname, sizeof("scroll_margin") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.wc_scroll_margin = negated ? 5 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + fullname = "subkeyvalue"; + if (match_optname(opts, fullname, 5, TRUE)) { + /* no duplicate complaint here */ + if (negated) + bad_negation(fullname, FALSE); + else { #if defined(WIN32) - op = string_for_opt(opts, 0); - map_subkeyvalue(op); + op = string_for_opt(opts, 0); + map_subkeyvalue(op); #endif - } - return; - } - /* WINCAP - * tile_width:nn */ - fullname = "tile_width"; - if (match_optname(opts, fullname, sizeof("tile_width")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.wc_tile_width = negated ? 0 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* WINCAP - * tile_file:name */ - fullname = "tile_file"; - if (match_optname(opts, fullname, sizeof("tile_file")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if ((op = string_for_opt(opts, FALSE)) != 0) { - if (iflags.wc_tile_file) free(iflags.wc_tile_file); - iflags.wc_tile_file = (char *)alloc(strlen(op) + 1); - Strcpy(iflags.wc_tile_file, op); - } - return; - } - /* WINCAP - * tile_height:nn */ - fullname = "tile_height"; - if (match_optname(opts, fullname, sizeof("tile_height")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.wc_tile_height = negated ? 0 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - /* WINCAP - * vary_msgcount:nn */ - fullname = "vary_msgcount"; - if (match_optname(opts, fullname, sizeof("vary_msgcount")-1, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, negated); - if ((negated && !op) || (!negated && op)) { - iflags.wc_vary_msgcount = negated ? 0 : atoi(op); - } else if (negated) bad_negation(fullname, TRUE); - return; - } - fullname = "windowtype"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - char buf[WINTYPELEN]; - nmcpy(buf, op, WINTYPELEN); - choose_windows(buf); - } - return; - } + } + return; + } + /* WINCAP + * tile_width:nn */ + fullname = "tile_width"; + if (match_optname(opts, fullname, sizeof("tile_width") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.wc_tile_width = negated ? 0 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* WINCAP + * tile_file:name */ + fullname = "tile_file"; + if (match_optname(opts, fullname, sizeof("tile_file") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if ((op = string_for_opt(opts, FALSE)) != 0) { + if (iflags.wc_tile_file) + free(iflags.wc_tile_file); + iflags.wc_tile_file = (char *) alloc(strlen(op) + 1); + Strcpy(iflags.wc_tile_file, op); + } + return; + } + /* WINCAP + * tile_height:nn */ + fullname = "tile_height"; + if (match_optname(opts, fullname, sizeof("tile_height") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.wc_tile_height = negated ? 0 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + /* WINCAP + * vary_msgcount:nn */ + fullname = "vary_msgcount"; + if (match_optname(opts, fullname, sizeof("vary_msgcount") - 1, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, negated); + if ((negated && !op) || (!negated && op)) { + iflags.wc_vary_msgcount = negated ? 0 : atoi(op); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } + fullname = "windowtype"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + char buf[WINTYPELEN]; + nmcpy(buf, op, WINTYPELEN); + choose_windows(buf); + } + return; + } #ifdef WINCHAIN - fullname = "windowchain"; - if (match_optname(opts, fullname, 3, TRUE)) { - if (negated) { - bad_negation(fullname, FALSE); - return; - } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { - char buf[WINTYPELEN]; - nmcpy(buf, op, WINTYPELEN); - addto_windowchain(buf); - } - return; - } + fullname = "windowchain"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { + char buf[WINTYPELEN]; + nmcpy(buf, op, WINTYPELEN); + addto_windowchain(buf); + } + return; + } #endif - /* WINCAP - * setting window colors - * syntax: windowcolors=menu foregrnd/backgrnd text foregrnd/backgrnd - */ - fullname = "windowcolors"; - if (match_optname(opts, fullname, 7, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if ((op = string_for_opt(opts, FALSE)) != 0) { - if (!wc_set_window_colors(op)) - badoption(opts); - } else if (negated) bad_negation(fullname, TRUE); - return; - } + /* WINCAP + * setting window colors + * syntax: windowcolors=menu foregrnd/backgrnd text foregrnd/backgrnd + */ + fullname = "windowcolors"; + if (match_optname(opts, fullname, 7, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if ((op = string_for_opt(opts, FALSE)) != 0) { + if (!wc_set_window_colors(op)) + badoption(opts); + } else if (negated) + bad_negation(fullname, TRUE); + return; + } - /* menustyle:traditional or combo or full or partial */ - if (match_optname(opts, "menustyle", 4, TRUE)) { - int tmp; - boolean val_required = (strlen(opts) > 5 && !negated); + /* menustyle:traditional or combo or full or partial */ + if (match_optname(opts, "menustyle", 4, TRUE)) { + int tmp; + boolean val_required = (strlen(opts) > 5 && !negated); - if (duplicate) complain_about_duplicate(opts,1); - if (!(op = string_for_opt(opts, !val_required))) { - if (val_required) return; /* string_for_opt gave feedback */ - tmp = negated ? 'n' : 'f'; - } else { - tmp = tolower(*op); - } - switch (tmp) { - case 'n': /* none */ - case 't': /* traditional */ - flags.menu_style = MENU_TRADITIONAL; - break; - case 'c': /* combo: trad.class sel+menu */ - flags.menu_style = MENU_COMBINATION; - break; - case 'p': /* partial: no class menu */ - flags.menu_style = MENU_PARTIAL; - break; - case 'f': /* full: class menu + menu */ - flags.menu_style = MENU_FULL; - break; - default: - badoption(opts); - } - return; - } + if (duplicate) + complain_about_duplicate(opts, 1); + if (!(op = string_for_opt(opts, !val_required))) { + if (val_required) + return; /* string_for_opt gave feedback */ + tmp = negated ? 'n' : 'f'; + } else { + tmp = tolower(*op); + } + switch (tmp) { + case 'n': /* none */ + case 't': /* traditional */ + flags.menu_style = MENU_TRADITIONAL; + break; + case 'c': /* combo: trad.class sel+menu */ + flags.menu_style = MENU_COMBINATION; + break; + case 'p': /* partial: no class menu */ + flags.menu_style = MENU_PARTIAL; + break; + case 'f': /* full: class menu + menu */ + flags.menu_style = MENU_FULL; + break; + default: + badoption(opts); + } + return; + } - fullname = "menu_headings"; - if (match_optname(opts, fullname, 12, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - if (negated) { - bad_negation(fullname, FALSE); - return; - } - else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { - return; - } - for (i = 0; i < SIZE(attrnames); i++) - if (!strcmpi(opts, attrnames[i].name)) { - iflags.menu_headings = attrnames[i].attr; - return; - } - badoption(opts); - return; - } + fullname = "menu_headings"; + if (match_optname(opts, fullname, 12, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + if (negated) { + bad_negation(fullname, FALSE); + return; + } else if (!(opts = string_for_env_opt(fullname, opts, FALSE))) { + return; + } + for (i = 0; i < SIZE(attrnames); i++) + if (!strcmpi(opts, attrnames[i].name)) { + iflags.menu_headings = attrnames[i].attr; + return; + } + badoption(opts); + return; + } - /* check for menu command mapping */ - for (i = 0; i < NUM_MENU_CMDS; i++) { - fullname = default_menu_cmd_info[i].name; - if (duplicate) complain_about_duplicate(opts,1); - if (match_optname(opts, fullname, (int)strlen(fullname), TRUE)) { - if (negated) - bad_negation(fullname, FALSE); - else if ((op = string_for_opt(opts, FALSE)) != 0) { - int j; - char c, op_buf[BUFSZ]; - boolean isbad = FALSE; + /* check for menu command mapping */ + for (i = 0; i < NUM_MENU_CMDS; i++) { + fullname = default_menu_cmd_info[i].name; + if (duplicate) + complain_about_duplicate(opts, 1); + if (match_optname(opts, fullname, (int) strlen(fullname), TRUE)) { + if (negated) + bad_negation(fullname, FALSE); + else if ((op = string_for_opt(opts, FALSE)) != 0) { + int j; + char c, op_buf[BUFSZ]; + boolean isbad = FALSE; - escapes(op, op_buf); - c = *op_buf; + escapes(op, op_buf); + c = *op_buf; - if (c == 0 || c == '\r' || c == '\n' || c == '\033' || - c == ' ' || digit(c) || (letter(c) && c != '@')) - isbad = TRUE; - else /* reject default object class symbols */ - for (j = 1; j < MAXOCLASSES; j++) - if (c == def_oc_syms[i].sym) { - isbad = TRUE; - break; - } + if (c == 0 || c == '\r' || c == '\n' || c == '\033' + || c == ' ' || digit(c) || (letter(c) && c != '@')) + isbad = TRUE; + else /* reject default object class symbols */ + for (j = 1; j < MAXOCLASSES; j++) + if (c == def_oc_syms[i].sym) { + isbad = TRUE; + break; + } - if (isbad) - badoption(opts); - else - add_menu_cmd_alias(c, default_menu_cmd_info[i].cmd); - } - return; - } - } + if (isbad) + badoption(opts); + else + add_menu_cmd_alias(c, default_menu_cmd_info[i].cmd); + } + return; + } + } #if defined(STATUS_VIA_WINDOWPORT) && defined(STATUS_HILITES) - /* hilite fields in status prompt */ - if (match_optname(opts, "hilite_status", 13, TRUE)) { - if (duplicate) complain_about_duplicate(opts,1); - op = string_for_opt(opts, TRUE); - if (op && negated) { - clear_status_hilites(); - return; - } else if (!op) { - /* a value is mandatory */ - badoption(opts); - return; - } - if (!set_status_hilites(op)) - badoption(opts); - return; - } + /* hilite fields in status prompt */ + if (match_optname(opts, "hilite_status", 13, TRUE)) { + if (duplicate) + complain_about_duplicate(opts, 1); + op = string_for_opt(opts, TRUE); + if (op && negated) { + clear_status_hilites(); + return; + } else if (!op) { + /* a value is mandatory */ + badoption(opts); + return; + } + if (!set_status_hilites(op)) + badoption(opts); + return; + } #endif #if defined(BACKWARD_COMPAT) - fullname = "DECgraphics"; - if (match_optname(opts, fullname, 3, TRUE)) { - boolean badflag = FALSE; - if (duplicate) complain_about_duplicate(opts,1); - if (!negated) { - /* There is no rogue level DECgraphics-specific set */ - if (symset[PRIMARY].name) - badflag = TRUE; - else { - symset[PRIMARY].name = (char *)alloc(strlen(fullname) + 1); - Strcpy(symset[PRIMARY].name, fullname); - if (!read_sym_file(PRIMARY)) { - badflag = TRUE; - clear_symsetentry(PRIMARY, TRUE); - } else switch_symbols(TRUE); - } - if (badflag) { - pline("Failure to load symbol set %s.", - fullname); - wait_synch(); - } - } - return; - } - fullname = "IBMgraphics"; - if (match_optname(opts, fullname, 3, TRUE)) { - const char *sym_name = fullname; - boolean badflag = FALSE; - if (duplicate) complain_about_duplicate(opts,1); - if (!negated) { - for (i = 0; i < NUM_GRAPHICS; ++i) { - if (symset[i].name) - badflag = TRUE; - else { - if (i == ROGUESET) sym_name = "RogueIBM"; - symset[i].name = (char *)alloc(strlen(sym_name) + 1); - Strcpy(symset[i].name, sym_name); - if (!read_sym_file(i)) { - badflag = TRUE; - clear_symsetentry(i, TRUE); - break; - } - } - } - if (badflag) { - pline("Failure to load symbol set %s.", - sym_name); - wait_synch(); - } else { - switch_symbols(TRUE); - if (!initial && Is_rogue_level(&u.uz)) - assign_graphics(ROGUESET); - } - } - return; - } + fullname = "DECgraphics"; + if (match_optname(opts, fullname, 3, TRUE)) { + boolean badflag = FALSE; + if (duplicate) + complain_about_duplicate(opts, 1); + if (!negated) { + /* There is no rogue level DECgraphics-specific set */ + if (symset[PRIMARY].name) + badflag = TRUE; + else { + symset[PRIMARY].name = (char *) alloc(strlen(fullname) + 1); + Strcpy(symset[PRIMARY].name, fullname); + if (!read_sym_file(PRIMARY)) { + badflag = TRUE; + clear_symsetentry(PRIMARY, TRUE); + } else + switch_symbols(TRUE); + } + if (badflag) { + pline("Failure to load symbol set %s.", fullname); + wait_synch(); + } + } + return; + } + fullname = "IBMgraphics"; + if (match_optname(opts, fullname, 3, TRUE)) { + const char *sym_name = fullname; + boolean badflag = FALSE; + if (duplicate) + complain_about_duplicate(opts, 1); + if (!negated) { + for (i = 0; i < NUM_GRAPHICS; ++i) { + if (symset[i].name) + badflag = TRUE; + else { + if (i == ROGUESET) + sym_name = "RogueIBM"; + symset[i].name = (char *) alloc(strlen(sym_name) + 1); + Strcpy(symset[i].name, sym_name); + if (!read_sym_file(i)) { + badflag = TRUE; + clear_symsetentry(i, TRUE); + break; + } + } + } + if (badflag) { + pline("Failure to load symbol set %s.", sym_name); + wait_synch(); + } else { + switch_symbols(TRUE); + if (!initial && Is_rogue_level(&u.uz)) + assign_graphics(ROGUESET); + } + } + return; + } #endif #ifdef MAC_GRAPHICS_ENV - fullname = "MACgraphics"; - if (match_optname(opts, fullname, 3, TRUE)) { - boolean badflag = FALSE; - if (duplicate) complain_about_duplicate(opts,1); - if (!negated) { - if (symset[PRIMARY]).name badflag = TRUE; - else { - symset[PRIMARY].name = (char *)alloc(strlen(fullname) + 1); - Strcpy(symset[PRIMARY].name, fullname); - if (!read_sym_file(PRIMARY)) { - badflag = TRUE; - clear_symsetentry(PRIMARY, TRUE); - } - } - if (badflag) { - pline("Failure to load symbol set %s.", - fullname); - wait_synch(); - } else { - switch_symbols(TRUE); - if (!initial && Is_rogue_level(&u.uz)) - assign_graphics(ROGUESET); - } - } - return; - } + fullname = "MACgraphics"; + if (match_optname(opts, fullname, 3, TRUE)) { + boolean badflag = FALSE; + if (duplicate) + complain_about_duplicate(opts, 1); + if (!negated) { + if (symset[PRIMARY]) + .name badflag = TRUE; + else { + symset[PRIMARY].name = (char *) alloc(strlen(fullname) + 1); + Strcpy(symset[PRIMARY].name, fullname); + if (!read_sym_file(PRIMARY)) { + badflag = TRUE; + clear_symsetentry(PRIMARY, TRUE); + } + } + if (badflag) { + pline("Failure to load symbol set %s.", fullname); + wait_synch(); + } else { + switch_symbols(TRUE); + if (!initial && Is_rogue_level(&u.uz)) + assign_graphics(ROGUESET); + } + } + return; + } #endif - /* OK, if we still haven't recognized the option, check the boolean - * options list - */ - for (i = 0; boolopt[i].name; i++) { - if (match_optname(opts, boolopt[i].name, 3, FALSE)) { + /* OK, if we still haven't recognized the option, check the boolean + * options list + */ + for (i = 0; boolopt[i].name; i++) { + if (match_optname(opts, boolopt[i].name, 3, FALSE)) { + /* options that don't exist */ + if (!boolopt[i].addr) { + if (!initial && !negated) + pline_The("\"%s\" option is not available.", + boolopt[i].name); + return; + } + /* options that must come from config file */ + if (!initial && (boolopt[i].optflags == SET_IN_FILE)) { + rejectoption(boolopt[i].name); + return; + } - /* options that don't exist */ - if (!boolopt[i].addr) { - if (!initial && !negated) - pline_The("\"%s\" option is not available.", - boolopt[i].name); - return; - } - /* options that must come from config file */ - if (!initial && (boolopt[i].optflags == SET_IN_FILE)) { - rejectoption(boolopt[i].name); - return; - } + *(boolopt[i].addr) = !negated; - *(boolopt[i].addr) = !negated; - - /* 0 means boolean opts */ - if (duplicate_opt_detection(boolopt[i].name, 0)) - complain_about_duplicate(boolopt[i].name,0); + /* 0 means boolean opts */ + if (duplicate_opt_detection(boolopt[i].name, 0)) + complain_about_duplicate(boolopt[i].name, 0); #ifdef RLECOMP - if ((boolopt[i].addr) == &iflags.rlecomp) { - if (*boolopt[i].addr) - set_savepref("rlecomp"); - else - set_savepref("!rlecomp"); - } + if ((boolopt[i].addr) == &iflags.rlecomp) { + if (*boolopt[i].addr) + set_savepref("rlecomp"); + else + set_savepref("!rlecomp"); + } #endif #ifdef ZEROCOMP - if ((boolopt[i].addr) == &iflags.zerocomp) { - if (*boolopt[i].addr) - set_savepref("zerocomp"); - else - set_savepref("externalcomp"); - } + if ((boolopt[i].addr) == &iflags.zerocomp) { + if (*boolopt[i].addr) + set_savepref("zerocomp"); + else + set_savepref("externalcomp"); + } #endif - /* only do processing below if setting with doset() */ - if (initial) return; + /* only do processing below if setting with doset() */ + if (initial) + return; - if ((boolopt[i].addr) == &flags.time - || (boolopt[i].addr) == &flags.showexp + if ((boolopt[i].addr) == &flags.time + || (boolopt[i].addr) == &flags.showexp #ifdef SCORE_ON_BOTL - || (boolopt[i].addr) == &flags.showscore + || (boolopt[i].addr) == &flags.showscore #endif - ) { + ) { #ifdef STATUS_VIA_WINDOWPORT - status_initialize(REASSESS_ONLY); + status_initialize(REASSESS_ONLY); #endif - context.botl = TRUE; - } - else if ((boolopt[i].addr) == &flags.invlet_constant) { - if (flags.invlet_constant) reassign(); - } - else if (((boolopt[i].addr) == &flags.lit_corridor) || - ((boolopt[i].addr) == &flags.dark_room)) { - /* - * All corridor squares seen via night vision or - * candles & lamps change. Update them by calling - * newsym() on them. Don't do this if we are - * initializing the options --- the vision system - * isn't set up yet. - */ - vision_recalc(2); /* shut down vision */ - vision_full_recalc = 1; /* delayed recalc */ - if (iflags.use_color) need_redraw = TRUE; /* darkroom refresh */ - } - else if ((boolopt[i].addr) == &iflags.use_inverse || - (boolopt[i].addr) == &flags.showrace || - (boolopt[i].addr) == &iflags.hilite_pet) { - need_redraw = TRUE; - } + context.botl = TRUE; + } else if ((boolopt[i].addr) == &flags.invlet_constant) { + if (flags.invlet_constant) + reassign(); + } else if (((boolopt[i].addr) == &flags.lit_corridor) + || ((boolopt[i].addr) == &flags.dark_room)) { + /* + * All corridor squares seen via night vision or + * candles & lamps change. Update them by calling + * newsym() on them. Don't do this if we are + * initializing the options --- the vision system + * isn't set up yet. + */ + vision_recalc(2); /* shut down vision */ + vision_full_recalc = 1; /* delayed recalc */ + if (iflags.use_color) + need_redraw = TRUE; /* darkroom refresh */ + } else if ((boolopt[i].addr) == &iflags.use_inverse + || (boolopt[i].addr) == &flags.showrace + || (boolopt[i].addr) == &iflags.hilite_pet) { + need_redraw = TRUE; + } #ifdef TEXTCOLOR - else if ((boolopt[i].addr) == &iflags.use_color) { - need_redraw = TRUE; -# ifdef TOS - if ((boolopt[i].addr) == &iflags.use_color - && iflags.BIOS) { - if (colors_changed) - restore_colors(); - else - set_colors(); - } -# endif - } + else if ((boolopt[i].addr) == &iflags.use_color) { + need_redraw = TRUE; +#ifdef TOS + if ((boolopt[i].addr) == &iflags.use_color && iflags.BIOS) { + if (colors_changed) + restore_colors(); + else + set_colors(); + } +#endif + } #endif - return; - } - } + return; + } + } - /* out of valid options */ - badoption(opts); + /* out of valid options */ + badoption(opts); } -static NEARDATA const char *menutype[] = { - "traditional", "combination", "partial", "full" -}; +static NEARDATA const char *menutype[] = { "traditional", "combination", + "partial", "full" }; -static NEARDATA const char *burdentype[] = { - "unencumbered", "burdened", "stressed", - "strained", "overtaxed", "overloaded" -}; +static NEARDATA const char *burdentype[] = { "unencumbered", "burdened", + "stressed", "strained", + "overtaxed", "overloaded" }; -static NEARDATA const char *runmodes[] = { - "teleport", "run", "walk", "crawl" -}; +static NEARDATA const char *runmodes[] = { "teleport", "run", "walk", + "crawl" }; -static NEARDATA const char *sortltype[] = { - "none", "loot", "full" -}; +static NEARDATA const char *sortltype[] = { "none", "loot", "full" }; /* * Convert the given string of object classes to a string of default object * symbols. */ STATIC_OVL void -oc_to_str(src,dest) - char *src, *dest; +oc_to_str(src, dest) +char *src, *dest; { int i; while ((i = (int) *src++) != 0) { - if (i < 0 || i >= MAXOCLASSES) - impossible("oc_to_str: illegal object class %d", i); - else - *dest++ = def_oc_syms[i].sym; + if (i < 0 || i >= MAXOCLASSES) + impossible("oc_to_str: illegal object class %d", i); + else + *dest++ = def_oc_syms[i].sym; } *dest = '\0'; } @@ -3043,16 +3193,16 @@ oc_to_str(src,dest) */ void add_menu_cmd_alias(from_ch, to_ch) - char from_ch, to_ch; +char from_ch, to_ch; { if (n_menu_mapped >= MAX_MENU_MAPPED_CMDS) - pline("out of menu map space."); + pline("out of menu map space."); else { - mapped_menu_cmds[n_menu_mapped] = from_ch; - mapped_menu_op[n_menu_mapped] = to_ch; - n_menu_mapped++; - mapped_menu_cmds[n_menu_mapped] = 0; - mapped_menu_op[n_menu_mapped] = 0; + mapped_menu_cmds[n_menu_mapped] = from_ch; + mapped_menu_op[n_menu_mapped] = to_ch; + n_menu_mapped++; + mapped_menu_cmds[n_menu_mapped] = 0; + mapped_menu_op[n_menu_mapped] = 0; } } @@ -3062,21 +3212,20 @@ add_menu_cmd_alias(from_ch, to_ch) */ char map_menu_cmd(ch) - char ch; +char ch; { char *found = index(mapped_menu_cmds, ch); if (found) { - int idx = (int)(found - mapped_menu_cmds); - ch = mapped_menu_op[idx]; + int idx = (int) (found - mapped_menu_cmds); + ch = mapped_menu_op[idx]; } return ch; } - #if defined(MICRO) || defined(MAC) || defined(WIN32) -# define OPTIONS_HEADING "OPTIONS" +#define OPTIONS_HEADING "OPTIONS" #else -# define OPTIONS_HEADING "NETHACKOPTIONS" +#define OPTIONS_HEADING "NETHACKOPTIONS" #endif static char fmtstr_doset_add_menu[] = "%s%-15s [%s] "; @@ -3084,39 +3233,41 @@ static char fmtstr_doset_add_menu_tab[] = "%s\t[%s]"; STATIC_OVL void doset_add_menu(win, option, indexoffset) - winid win; /* window to add to */ - const char *option; /* option name */ - int indexoffset; /* value to add to index in compopt[], or zero - if option cannot be changed */ +winid win; /* window to add to */ +const char *option; /* option name */ +int indexoffset; /* value to add to index in compopt[], or zero + if option cannot be changed */ { - const char *value = "unknown"; /* current value */ + const char *value = "unknown"; /* current value */ char buf[BUFSZ], buf2[BUFSZ]; anything any; int i; any = zeroany; if (indexoffset == 0) { - any.a_int = 0; - value = get_compopt_value(option, buf2); + any.a_int = 0; + value = get_compopt_value(option, buf2); } else { - for (i=0; compopt[i].name; i++) - if (strcmp(option, compopt[i].name) == 0) break; + for (i = 0; compopt[i].name; i++) + if (strcmp(option, compopt[i].name) == 0) + break; - if (compopt[i].name) { - any.a_int = i + 1 + indexoffset; - value = get_compopt_value(option, buf2); - } else { - /* We are trying to add an option not found in compopt[]. - This is almost certainly bad, but we'll let it through anyway - (with a zero value, so it can't be selected). */ - any.a_int = 0; - } + if (compopt[i].name) { + any.a_int = i + 1 + indexoffset; + value = get_compopt_value(option, buf2); + } else { + /* We are trying to add an option not found in compopt[]. + This is almost certainly bad, but we'll let it through anyway + (with a zero value, so it can't be selected). */ + any.a_int = 0; + } } /* " " replaces "a - " -- assumes menus follow that style */ if (!iflags.menu_tab_sep) - Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", option, value); + Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", option, + value); else - Sprintf(buf, fmtstr_doset_add_menu_tab, option, value); + Sprintf(buf, fmtstr_doset_add_menu_tab, option, value); add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); } @@ -3124,201 +3275,206 @@ doset_add_menu(win, option, indexoffset) int doset() { - char buf[BUFSZ], buf2[BUFSZ]; - int i, pass, boolcount, pick_cnt, pick_idx, opt_indx; - boolean *bool_p; - winid tmpwin; - anything any; - menu_item *pick_list; - int indexoffset, startpass, endpass; - boolean setinitial = FALSE, fromfile = FALSE; - int biggest_name = 0; + char buf[BUFSZ], buf2[BUFSZ]; + int i, pass, boolcount, pick_cnt, pick_idx, opt_indx; + boolean *bool_p; + winid tmpwin; + anything any; + menu_item *pick_list; + int indexoffset, startpass, endpass; + boolean setinitial = FALSE, fromfile = FALSE; + int biggest_name = 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); - any = zeroany; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - "Booleans (selecting will toggle value):", MENU_UNSELECTED); - any.a_int = 0; - /* first list any other non-modifiable booleans, then modifiable ones */ - for (pass = 0; pass <= 1; pass++) - for (i = 0; boolopt[i].name; i++) - if ((bool_p = boolopt[i].addr) != 0 && - ((boolopt[i].optflags == DISP_IN_GAME && pass == 0) || - (boolopt[i].optflags == SET_IN_GAME && pass == 1))) { - if (bool_p == &flags.female) continue; /* obsolete */ - if (bool_p == &iflags.sanity_check && !wizard) continue; - if (bool_p == &iflags.menu_tab_sep && !wizard) continue; - if (is_wc_option(boolopt[i].name) && - !wc_supported(boolopt[i].name)) continue; - if (is_wc2_option(boolopt[i].name) && - !wc2_supported(boolopt[i].name)) continue; - any.a_int = (pass == 0) ? 0 : i + 1; - if (!iflags.menu_tab_sep) - Sprintf(buf, "%s%-13s [%s]", - pass == 0 ? " " : "", - boolopt[i].name, *bool_p ? "true" : "false"); - else - Sprintf(buf, "%s\t[%s]", - boolopt[i].name, *bool_p ? "true" : "false"); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, buf, MENU_UNSELECTED); - } + any = zeroany; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + "Booleans (selecting will toggle value):", MENU_UNSELECTED); + any.a_int = 0; + /* first list any other non-modifiable booleans, then modifiable ones */ + for (pass = 0; pass <= 1; pass++) + for (i = 0; boolopt[i].name; i++) + if ((bool_p = boolopt[i].addr) != 0 + && ((boolopt[i].optflags == DISP_IN_GAME && pass == 0) + || (boolopt[i].optflags == SET_IN_GAME && pass == 1))) { + if (bool_p == &flags.female) + continue; /* obsolete */ + if (bool_p == &iflags.sanity_check && !wizard) + continue; + if (bool_p == &iflags.menu_tab_sep && !wizard) + continue; + if (is_wc_option(boolopt[i].name) + && !wc_supported(boolopt[i].name)) + continue; + if (is_wc2_option(boolopt[i].name) + && !wc2_supported(boolopt[i].name)) + continue; + any.a_int = (pass == 0) ? 0 : i + 1; + if (!iflags.menu_tab_sep) + Sprintf(buf, "%s%-13s [%s]", pass == 0 ? " " : "", + boolopt[i].name, *bool_p ? "true" : "false"); + else + Sprintf(buf, "%s\t[%s]", boolopt[i].name, + *bool_p ? "true" : "false"); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + } - boolcount = i; - indexoffset = boolcount; - any = zeroany; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - "Compounds (selecting will prompt for new value):", - MENU_UNSELECTED); + boolcount = i; + indexoffset = boolcount; + any = zeroany; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + "Compounds (selecting will prompt for new value):", + MENU_UNSELECTED); #ifdef notyet /* SYSCF */ -/* XXX I think this is still fragile. Fixing initial/from_file and/or changing - the SET_* etc to bitmaps will let me make this better. */ - if(wizard) - startpass = SET_IN_SYS; - else + /* XXX I think this is still fragile. Fixing initial/from_file and/or + changing + the SET_* etc to bitmaps will let me make this better. */ + if (wizard) + startpass = SET_IN_SYS; + else #endif - startpass = DISP_IN_GAME; - endpass = SET_IN_GAME; + startpass = DISP_IN_GAME; + endpass = SET_IN_GAME; - /* spin through the options to find the biggest name - and adjust the format string accordingly if needed */ - biggest_name = 0; - for (i = 0; compopt[i].name; i++) - if (compopt[i].optflags >= startpass && compopt[i].optflags <= endpass && - strlen(compopt[i].name) > (unsigned) biggest_name) - biggest_name = (int) strlen(compopt[i].name); - if (biggest_name > 30) biggest_name = 30; - if (!iflags.menu_tab_sep) - Sprintf(fmtstr_doset_add_menu, "%%s%%-%ds [%%s]", biggest_name); + /* spin through the options to find the biggest name + and adjust the format string accordingly if needed */ + biggest_name = 0; + for (i = 0; compopt[i].name; i++) + if (compopt[i].optflags >= startpass && compopt[i].optflags <= endpass + && strlen(compopt[i].name) > (unsigned) biggest_name) + biggest_name = (int) strlen(compopt[i].name); + if (biggest_name > 30) + biggest_name = 30; + if (!iflags.menu_tab_sep) + Sprintf(fmtstr_doset_add_menu, "%%s%%-%ds [%%s]", biggest_name); - /* deliberately put `playmode', `name', `role', `race', `gender' first - (also alignment if anything ever comes before it in compopt[]) */ - doset_add_menu(tmpwin, "playmode", 0); - doset_add_menu(tmpwin, "name", 0); - doset_add_menu(tmpwin, "role", 0); - doset_add_menu(tmpwin, "race", 0); - doset_add_menu(tmpwin, "gender", 0); + /* deliberately put `playmode', `name', `role', `race', `gender' first + (also alignment if anything ever comes before it in compopt[]) */ + doset_add_menu(tmpwin, "playmode", 0); + doset_add_menu(tmpwin, "name", 0); + doset_add_menu(tmpwin, "role", 0); + doset_add_menu(tmpwin, "race", 0); + doset_add_menu(tmpwin, "gender", 0); - for (pass = startpass; pass <= endpass; pass++) - for (i = 0; compopt[i].name; i++) - if (compopt[i].optflags == pass) { - if (!strcmp(compopt[i].name, "playmode") || - !strcmp(compopt[i].name, "name") || - !strcmp(compopt[i].name, "role") || - !strcmp(compopt[i].name, "race") || - !strcmp(compopt[i].name, "gender")) - continue; - else if (is_wc_option(compopt[i].name) && - !wc_supported(compopt[i].name)) - continue; - else if (is_wc2_option(compopt[i].name) && - !wc2_supported(compopt[i].name)) - continue; - else - doset_add_menu(tmpwin, compopt[i].name, - (pass == DISP_IN_GAME) ? 0 : indexoffset); - } - any.a_int = -3; - Sprintf(buf2, "(%d currently set)", count_menucolors()); - Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", - "menucolors", buf2); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); + for (pass = startpass; pass <= endpass; pass++) + for (i = 0; compopt[i].name; i++) + if (compopt[i].optflags == pass) { + if (!strcmp(compopt[i].name, "playmode") + || !strcmp(compopt[i].name, "name") + || !strcmp(compopt[i].name, "role") + || !strcmp(compopt[i].name, "race") + || !strcmp(compopt[i].name, "gender")) + continue; + else if (is_wc_option(compopt[i].name) + && !wc_supported(compopt[i].name)) + continue; + else if (is_wc2_option(compopt[i].name) + && !wc2_supported(compopt[i].name)) + continue; + else + doset_add_menu(tmpwin, compopt[i].name, + (pass == DISP_IN_GAME) ? 0 : indexoffset); + } + any.a_int = -3; + Sprintf(buf2, "(%d currently set)", count_menucolors()); + Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", "menucolors", + buf2); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); #ifdef STATUS_VIA_WINDOWPORT -# ifdef STATUS_HILITES - any.a_int = -2; - get_status_hilites(buf2, 60); - if (!iflags.menu_tab_sep) - Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", - "status_hilites", buf2); - else - Sprintf(buf, fmtstr_doset_add_menu_tab, "status_hilites", buf2); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); -# endif +#ifdef STATUS_HILITES + any.a_int = -2; + get_status_hilites(buf2, 60); + if (!iflags.menu_tab_sep) + Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ", + "status_hilites", buf2); + else + Sprintf(buf, fmtstr_doset_add_menu_tab, "status_hilites", buf2); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); #endif - any.a_int = -1; - Sprintf(buf, "autopickup exceptions (%d currently set)", - count_ape_maps((int *)0, (int *)0)); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); +#endif + any.a_int = -1; + Sprintf(buf, "autopickup exceptions (%d currently set)", + count_ape_maps((int *) 0, (int *) 0)); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED); #ifdef PREFIXES_IN_USE - any = zeroany; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - "Variable playground locations:", MENU_UNSELECTED); - for (i = 0; i < PREFIX_COUNT; i++) - doset_add_menu(tmpwin, fqn_prefix_names[i], 0); + any = zeroany; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + "Variable playground locations:", MENU_UNSELECTED); + for (i = 0; i < PREFIX_COUNT; i++) + doset_add_menu(tmpwin, fqn_prefix_names[i], 0); #endif - end_menu(tmpwin, "Set what options?"); - need_redraw = FALSE; - if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &pick_list)) > 0) { - /* - * Walk down the selection list and either invert the booleans - * or prompt for new values. In most cases, call parseoptions() - * to take care of options that require special attention, like - * redraws. - */ - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { - opt_indx = pick_list[pick_idx].item.a_int - 1; - if (opt_indx == -2) { /* -3 due to -1 offset for select_menu() */ - (void)special_handling("autopickup_exception", - setinitial, fromfile); - } else + end_menu(tmpwin, "Set what options?"); + need_redraw = FALSE; + if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &pick_list)) > 0) { + /* + * Walk down the selection list and either invert the booleans + * or prompt for new values. In most cases, call parseoptions() + * to take care of options that require special attention, like + * redraws. + */ + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { + opt_indx = pick_list[pick_idx].item.a_int - 1; + if (opt_indx == -2) { /* -3 due to -1 offset for select_menu() */ + (void) special_handling("autopickup_exception", setinitial, + fromfile); + } else #ifdef STATUS_VIA_WINDOWPORT -# ifdef STATUS_HILITES - if (opt_indx == -3) { /* -3 due to -1 offset for select_menu() */ - if (!status_hilite_menu()) - pline("Bad status hilite(s) specified."); - else { - if (wc2_supported("status_hilites")) - preference_update("status_hilites"); - } - } else -# endif +#ifdef STATUS_HILITES + if (opt_indx + == -3) { /* -3 due to -1 offset for select_menu() */ + if (!status_hilite_menu()) + pline("Bad status hilite(s) specified."); + else { + if (wc2_supported("status_hilites")) + preference_update("status_hilites"); + } + } else #endif - if (opt_indx == -4) { - (void)special_handling("menucolors", - setinitial, fromfile); - } else - if (opt_indx < boolcount) { - /* boolean option */ - Sprintf(buf, "%s%s", *boolopt[opt_indx].addr ? "!" : "", - boolopt[opt_indx].name); - parseoptions(buf, setinitial, fromfile); - if (wc_supported(boolopt[opt_indx].name) || - wc2_supported(boolopt[opt_indx].name)) - preference_update(boolopt[opt_indx].name); - } else { - /* compound option */ - opt_indx -= boolcount; +#endif + if (opt_indx == -4) { + (void) special_handling("menucolors", setinitial, fromfile); + } else if (opt_indx < boolcount) { + /* boolean option */ + Sprintf(buf, "%s%s", *boolopt[opt_indx].addr ? "!" : "", + boolopt[opt_indx].name); + parseoptions(buf, setinitial, fromfile); + if (wc_supported(boolopt[opt_indx].name) + || wc2_supported(boolopt[opt_indx].name)) + preference_update(boolopt[opt_indx].name); + } else { + /* compound option */ + opt_indx -= boolcount; - if (!special_handling(compopt[opt_indx].name, - setinitial, fromfile)) { - Sprintf(buf, "Set %s to what?", compopt[opt_indx].name); - getlin(buf, buf2); - if (buf2[0] == '\033') - continue; - Sprintf(buf, "%s:%s", compopt[opt_indx].name, buf2); - /* pass the buck */ - parseoptions(buf, setinitial, fromfile); - } - if (wc_supported(compopt[opt_indx].name) || - wc2_supported(compopt[opt_indx].name)) - preference_update(compopt[opt_indx].name); - } - } - free((genericptr_t)pick_list); - pick_list = (menu_item *)0; - } + if (!special_handling(compopt[opt_indx].name, setinitial, + fromfile)) { + Sprintf(buf, "Set %s to what?", compopt[opt_indx].name); + getlin(buf, buf2); + if (buf2[0] == '\033') + continue; + Sprintf(buf, "%s:%s", compopt[opt_indx].name, buf2); + /* pass the buck */ + parseoptions(buf, setinitial, fromfile); + } + if (wc_supported(compopt[opt_indx].name) + || wc2_supported(compopt[opt_indx].name)) + preference_update(compopt[opt_indx].name); + } + } + free((genericptr_t) pick_list); + pick_list = (menu_item *) 0; + } - destroy_nhwindow(tmpwin); - if (need_redraw) { - reglyph_darkroom(); - (void) doredraw(); - } - return 0; + destroy_nhwindow(tmpwin); + if (need_redraw) { + reglyph_darkroom(); + (void) doredraw(); + } + return 0; } int @@ -3326,59 +3482,61 @@ handle_add_list_remove(optname, numtotal) char *optname; int numtotal; { - winid tmpwin; - anything any; - int i, pick_cnt, pick_idx, opt_idx; - menu_item *pick_list = (menu_item *)0; - static const struct action { - char letr; - const char *desc; - } action_titles[] = { - { 'a', "add new %s" }, /* [0] */ - { 'l', "list %s" }, /* [1] */ - { 'r', "remove existing %s" }, /* [2] */ - { 'x', "exit this menu" }, /* [3] */ - }; + winid tmpwin; + anything any; + int i, pick_cnt, pick_idx, opt_idx; + menu_item *pick_list = (menu_item *) 0; + static const struct action { + char letr; + const char *desc; + } action_titles[] = { + { 'a', "add new %s" }, /* [0] */ + { 'l', "list %s" }, /* [1] */ + { 'r', "remove existing %s" }, /* [2] */ + { 'x', "exit this menu" }, /* [3] */ + }; - opt_idx = 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < SIZE(action_titles); i++) { - char tmpbuf[BUFSZ]; - any.a_int++; - /* omit list and remove if there aren't any yet */ - if (!numtotal && (i == 1 || i == 2)) continue; - Sprintf(tmpbuf, action_titles[i].desc, (i == 1) ? makeplural(optname) : optname); - add_menu(tmpwin, NO_GLYPH, &any, action_titles[i].letr, - 0, ATR_NONE, tmpbuf, -#if 0 /* this ought to work but doesn't... */ + opt_idx = 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < SIZE(action_titles); i++) { + char tmpbuf[BUFSZ]; + any.a_int++; + /* omit list and remove if there aren't any yet */ + if (!numtotal && (i == 1 || i == 2)) + continue; + Sprintf(tmpbuf, action_titles[i].desc, + (i == 1) ? makeplural(optname) : optname); + add_menu(tmpwin, NO_GLYPH, &any, action_titles[i].letr, 0, ATR_NONE, + tmpbuf, +#if 0 /* this ought to work but doesn't... */ (action_titles[i].letr == 'x') ? MENU_SELECTED : #endif - MENU_UNSELECTED); - } - end_menu(tmpwin, "Do what?"); - if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list)) > 0) { - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { - opt_idx = pick_list[pick_idx].item.a_int - 1; - } - free((genericptr_t)pick_list); - pick_list = (menu_item *)0; - } - destroy_nhwindow(tmpwin); + MENU_UNSELECTED); + } + end_menu(tmpwin, "Do what?"); + if ((pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list)) > 0) { + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { + opt_idx = pick_list[pick_idx].item.a_int - 1; + } + free((genericptr_t) pick_list); + pick_list = (menu_item *) 0; + } + destroy_nhwindow(tmpwin); - if (pick_cnt < 1) opt_idx = 3; /* none selected, exit menu */ - return opt_idx; + if (pick_cnt < 1) + opt_idx = 3; /* none selected, exit menu */ + return opt_idx; } - -struct symsetentry *symset_list = 0; /* files.c will populate this with - list of available sets */ +struct symsetentry *symset_list = 0; /* files.c will populate this with + list of available sets */ STATIC_OVL boolean special_handling(optname, setinitial, setfromfile) const char *optname; -boolean setinitial,setfromfile; +boolean setinitial, setfromfile; { winid tmpwin; anything any; @@ -3391,557 +3549,597 @@ boolean setinitial,setfromfile; * Also takes care of interactive autopickup_exception_handling changes. */ if (!strcmp("menustyle", optname)) { - const char *style_name; - menu_item *style_pick = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - for (i = 0; i < SIZE(menutype); i++) { - style_name = menutype[i]; - /* note: separate `style_name' variable used - to avoid an optimizer bug in VAX C V2.3 */ - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, *style_name, 0, - ATR_NONE, style_name, MENU_UNSELECTED); - } - end_menu(tmpwin, "Select menustyle:"); - if (select_menu(tmpwin, PICK_ONE, &style_pick) > 0) { - flags.menu_style = style_pick->item.a_int - 1; - free((genericptr_t)style_pick); - } - destroy_nhwindow(tmpwin); + const char *style_name; + menu_item *style_pick = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + for (i = 0; i < SIZE(menutype); i++) { + style_name = menutype[i]; + /* note: separate `style_name' variable used + to avoid an optimizer bug in VAX C V2.3 */ + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, *style_name, 0, ATR_NONE, + style_name, MENU_UNSELECTED); + } + end_menu(tmpwin, "Select menustyle:"); + if (select_menu(tmpwin, PICK_ONE, &style_pick) > 0) { + flags.menu_style = style_pick->item.a_int - 1; + free((genericptr_t) style_pick); + } + destroy_nhwindow(tmpwin); } else if (!strcmp("paranoid_confirmation", optname)) { - menu_item *paranoia_picks = (menu_item *)0; + menu_item *paranoia_picks = (menu_item *) 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; paranoia[i].flagmask != 0; ++i) { - if (paranoia[i].flagmask == PARANOID_BONES && !wizard) continue; - any.a_int = paranoia[i].flagmask; - add_menu(tmpwin, NO_GLYPH, &any, *paranoia[i].argname, 0, - ATR_NONE, paranoia[i].explain, - (flags.paranoia_bits & paranoia[i].flagmask) ? - MENU_SELECTED : MENU_UNSELECTED); - } - end_menu(tmpwin, "Actions requiring extra confirmation:"); - i = select_menu(tmpwin, PICK_ANY, ¶noia_picks); - if (i >= 0) { - /* player didn't cancel; we reset all the paranoia options - here even if there were no items picked, since user - could have toggled off preselected ones to end up with 0 */ - flags.paranoia_bits = 0; - if (i > 0) { - /* at least one item set, either preselected or newly picked */ - while (--i >= 0) - flags.paranoia_bits |= paranoia_picks[i].item.a_int; - free((genericptr_t)paranoia_picks); - } - } - destroy_nhwindow(tmpwin); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; paranoia[i].flagmask != 0; ++i) { + if (paranoia[i].flagmask == PARANOID_BONES && !wizard) + continue; + any.a_int = paranoia[i].flagmask; + add_menu(tmpwin, NO_GLYPH, &any, *paranoia[i].argname, 0, + ATR_NONE, paranoia[i].explain, + (flags.paranoia_bits & paranoia[i].flagmask) + ? MENU_SELECTED + : MENU_UNSELECTED); + } + end_menu(tmpwin, "Actions requiring extra confirmation:"); + i = select_menu(tmpwin, PICK_ANY, ¶noia_picks); + if (i >= 0) { + /* player didn't cancel; we reset all the paranoia options + here even if there were no items picked, since user + could have toggled off preselected ones to end up with 0 */ + flags.paranoia_bits = 0; + if (i > 0) { + /* at least one item set, either preselected or newly picked + */ + while (--i >= 0) + flags.paranoia_bits |= paranoia_picks[i].item.a_int; + free((genericptr_t) paranoia_picks); + } + } + destroy_nhwindow(tmpwin); } else if (!strcmp("pickup_burden", optname)) { - const char *burden_name, *burden_letters = "ubsntl"; - menu_item *burden_pick = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < SIZE(burdentype); i++) { - burden_name = burdentype[i]; - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, burden_letters[i], 0, - ATR_NONE, burden_name, MENU_UNSELECTED); - } - end_menu(tmpwin, "Select encumbrance level:"); - if (select_menu(tmpwin, PICK_ONE, &burden_pick) > 0) { - flags.pickup_burden = burden_pick->item.a_int - 1; - free((genericptr_t)burden_pick); - } - destroy_nhwindow(tmpwin); + const char *burden_name, *burden_letters = "ubsntl"; + menu_item *burden_pick = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < SIZE(burdentype); i++) { + burden_name = burdentype[i]; + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, burden_letters[i], 0, ATR_NONE, + burden_name, MENU_UNSELECTED); + } + end_menu(tmpwin, "Select encumbrance level:"); + if (select_menu(tmpwin, PICK_ONE, &burden_pick) > 0) { + flags.pickup_burden = burden_pick->item.a_int - 1; + free((genericptr_t) burden_pick); + } + destroy_nhwindow(tmpwin); } else if (!strcmp("pickup_types", optname)) { - /* parseoptions will prompt for the list of types */ - parseoptions(strcpy(buf, "pickup_types"), setinitial, setfromfile); + /* parseoptions will prompt for the list of types */ + parseoptions(strcpy(buf, "pickup_types"), setinitial, setfromfile); } else if (!strcmp("disclose", optname)) { - /* order of disclose_names[] must correspond to - disclosure_options in decl.c */ - static const char *disclosure_names[] = { - "inventory", "attributes", "vanquished", "genocides", - "conduct", "overview", - }; - int disc_cat[NUM_DISCLOSURE_OPTIONS]; - int pick_cnt, pick_idx, opt_idx; - menu_item *disclosure_pick = (menu_item *)0; + /* order of disclose_names[] must correspond to + disclosure_options in decl.c */ + static const char *disclosure_names[] = { + "inventory", "attributes", "vanquished", + "genocides", "conduct", "overview", + }; + int disc_cat[NUM_DISCLOSURE_OPTIONS]; + int pick_cnt, pick_idx, opt_idx; + menu_item *disclosure_pick = (menu_item *) 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { - Sprintf(buf, "%-12s[%c%c]", disclosure_names[i], - flags.end_disclose[i], disclosure_options[i]); - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, disclosure_options[i], 0, - ATR_NONE, buf, MENU_UNSELECTED); - disc_cat[i] = 0; - } - end_menu(tmpwin, "Change which disclosure options categories:"); - pick_cnt = select_menu(tmpwin, PICK_ANY, &disclosure_pick); - if (pick_cnt > 0) { - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { - opt_idx = disclosure_pick[pick_idx].item.a_int - 1; - disc_cat[opt_idx] = 1; - } - free((genericptr_t)disclosure_pick); - disclosure_pick = (menu_item *)0; - } - destroy_nhwindow(tmpwin); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { + Sprintf(buf, "%-12s[%c%c]", disclosure_names[i], + flags.end_disclose[i], disclosure_options[i]); + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, disclosure_options[i], 0, + ATR_NONE, buf, MENU_UNSELECTED); + disc_cat[i] = 0; + } + end_menu(tmpwin, "Change which disclosure options categories:"); + pick_cnt = select_menu(tmpwin, PICK_ANY, &disclosure_pick); + if (pick_cnt > 0) { + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) { + opt_idx = disclosure_pick[pick_idx].item.a_int - 1; + disc_cat[opt_idx] = 1; + } + free((genericptr_t) disclosure_pick); + disclosure_pick = (menu_item *) 0; + } + destroy_nhwindow(tmpwin); - for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { - if (disc_cat[i]) { - Sprintf(buf, "Disclosure options for %s:", - disclosure_names[i]); - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - /* 'y','n',and '+' work as alternate selectors; '-' doesn't */ - any.a_char = DISCLOSE_NO_WITHOUT_PROMPT; - add_menu(tmpwin, NO_GLYPH, &any, 'a', any.a_char, ATR_NONE, - "Never disclose, without prompting", MENU_UNSELECTED); - any.a_char = DISCLOSE_YES_WITHOUT_PROMPT; - add_menu(tmpwin, NO_GLYPH, &any, 'b', any.a_char, ATR_NONE, - "Always disclose, without prompting", - MENU_UNSELECTED); - any.a_char = DISCLOSE_PROMPT_DEFAULT_NO; - add_menu(tmpwin, NO_GLYPH, &any, 'c', any.a_char, ATR_NONE, - "Prompt, with default answer of \"No\"", - MENU_UNSELECTED); - any.a_char = DISCLOSE_PROMPT_DEFAULT_YES; - add_menu(tmpwin, NO_GLYPH, &any, 'd', any.a_char, ATR_NONE, - "Prompt, with default answer of \"Yes\"", - MENU_UNSELECTED); - end_menu(tmpwin, buf); - if (select_menu(tmpwin, PICK_ONE, &disclosure_pick) > 0) { - flags.end_disclose[i] = disclosure_pick->item.a_char; - free((genericptr_t)disclosure_pick); - } - destroy_nhwindow(tmpwin); - } - } + for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { + if (disc_cat[i]) { + Sprintf(buf, "Disclosure options for %s:", + disclosure_names[i]); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + /* 'y','n',and '+' work as alternate selectors; '-' doesn't */ + any.a_char = DISCLOSE_NO_WITHOUT_PROMPT; + add_menu(tmpwin, NO_GLYPH, &any, 'a', any.a_char, ATR_NONE, + "Never disclose, without prompting", + MENU_UNSELECTED); + any.a_char = DISCLOSE_YES_WITHOUT_PROMPT; + add_menu(tmpwin, NO_GLYPH, &any, 'b', any.a_char, ATR_NONE, + "Always disclose, without prompting", + MENU_UNSELECTED); + any.a_char = DISCLOSE_PROMPT_DEFAULT_NO; + add_menu(tmpwin, NO_GLYPH, &any, 'c', any.a_char, ATR_NONE, + "Prompt, with default answer of \"No\"", + MENU_UNSELECTED); + any.a_char = DISCLOSE_PROMPT_DEFAULT_YES; + add_menu(tmpwin, NO_GLYPH, &any, 'd', any.a_char, ATR_NONE, + "Prompt, with default answer of \"Yes\"", + MENU_UNSELECTED); + end_menu(tmpwin, buf); + if (select_menu(tmpwin, PICK_ONE, &disclosure_pick) > 0) { + flags.end_disclose[i] = disclosure_pick->item.a_char; + free((genericptr_t) disclosure_pick); + } + destroy_nhwindow(tmpwin); + } + } } else if (!strcmp("runmode", optname)) { - const char *mode_name; - menu_item *mode_pick = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < SIZE(runmodes); i++) { - mode_name = runmodes[i]; - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, *mode_name, 0, - ATR_NONE, mode_name, MENU_UNSELECTED); - } - end_menu(tmpwin, "Select run/travel display mode:"); - if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) { - flags.runmode = mode_pick->item.a_int - 1; - free((genericptr_t)mode_pick); - } - destroy_nhwindow(tmpwin); + const char *mode_name; + menu_item *mode_pick = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < SIZE(runmodes); i++) { + mode_name = runmodes[i]; + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, *mode_name, 0, ATR_NONE, + mode_name, MENU_UNSELECTED); + } + end_menu(tmpwin, "Select run/travel display mode:"); + if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) { + flags.runmode = mode_pick->item.a_int - 1; + free((genericptr_t) mode_pick); + } + destroy_nhwindow(tmpwin); } else if (!strcmp("msg_window", optname)) { #ifdef TTY_GRAPHICS - /* by Christian W. Cooper */ - menu_item *window_pick = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - any.a_char = 's'; - add_menu(tmpwin, NO_GLYPH, &any, 's', 0, - ATR_NONE, "single", MENU_UNSELECTED); - any.a_char = 'c'; - add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, - ATR_NONE, "combination", MENU_UNSELECTED); - any.a_char = 'f'; - add_menu(tmpwin, NO_GLYPH, &any, 'f', 0, - ATR_NONE, "full", MENU_UNSELECTED); - any.a_char = 'r'; - add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, - ATR_NONE, "reversed", MENU_UNSELECTED); - end_menu(tmpwin, "Select message history display type:"); - if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { - iflags.prevmsg_window = window_pick->item.a_char; - free((genericptr_t)window_pick); - } - destroy_nhwindow(tmpwin); + /* by Christian W. Cooper */ + menu_item *window_pick = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + any.a_char = 's'; + add_menu(tmpwin, NO_GLYPH, &any, 's', 0, ATR_NONE, "single", + MENU_UNSELECTED); + any.a_char = 'c'; + add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE, "combination", + MENU_UNSELECTED); + any.a_char = 'f'; + add_menu(tmpwin, NO_GLYPH, &any, 'f', 0, ATR_NONE, "full", + MENU_UNSELECTED); + any.a_char = 'r'; + add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "reversed", + MENU_UNSELECTED); + end_menu(tmpwin, "Select message history display type:"); + if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { + iflags.prevmsg_window = window_pick->item.a_char; + free((genericptr_t) window_pick); + } + destroy_nhwindow(tmpwin); #endif } else if (!strcmp("sortloot", optname)) { - const char *sortl_name; - menu_item *sortl_pick = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < SIZE(sortltype); i++) { - sortl_name = sortltype[i]; - any.a_char = *sortl_name; - add_menu(tmpwin, NO_GLYPH, &any, *sortl_name, 0, - ATR_NONE, sortl_name, MENU_UNSELECTED); - } - end_menu(tmpwin, "Select loot sorting type:"); - if (select_menu(tmpwin, PICK_ONE, &sortl_pick) > 0) { - flags.sortloot = sortl_pick->item.a_char; - free((genericptr_t)sortl_pick); - } - destroy_nhwindow(tmpwin); - } else if (!strcmp("align_message", optname) || - !strcmp("align_status", optname)) { - menu_item *window_pick = (menu_item *)0; - char abuf[BUFSZ]; - boolean msg = (*(optname+6) == 'm'); + const char *sortl_name; + menu_item *sortl_pick = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < SIZE(sortltype); i++) { + sortl_name = sortltype[i]; + any.a_char = *sortl_name; + add_menu(tmpwin, NO_GLYPH, &any, *sortl_name, 0, ATR_NONE, + sortl_name, MENU_UNSELECTED); + } + end_menu(tmpwin, "Select loot sorting type:"); + if (select_menu(tmpwin, PICK_ONE, &sortl_pick) > 0) { + flags.sortloot = sortl_pick->item.a_char; + free((genericptr_t) sortl_pick); + } + destroy_nhwindow(tmpwin); + } else if (!strcmp("align_message", optname) + || !strcmp("align_status", optname)) { + menu_item *window_pick = (menu_item *) 0; + char abuf[BUFSZ]; + boolean msg = (*(optname + 6) == 'm'); - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - any.a_int = ALIGN_TOP; - add_menu(tmpwin, NO_GLYPH, &any, 't', 0, - ATR_NONE, "top", MENU_UNSELECTED); - any.a_int = ALIGN_BOTTOM; - add_menu(tmpwin, NO_GLYPH, &any, 'b', 0, - ATR_NONE, "bottom", MENU_UNSELECTED); - any.a_int = ALIGN_LEFT; - add_menu(tmpwin, NO_GLYPH, &any, 'l', 0, - ATR_NONE, "left", MENU_UNSELECTED); - any.a_int = ALIGN_RIGHT; - add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, - ATR_NONE, "right", MENU_UNSELECTED); - Sprintf(abuf, "Select %s window placement relative to the map:", - msg ? "message" : "status"); - end_menu(tmpwin, abuf); - if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { - if (msg) iflags.wc_align_message = window_pick->item.a_int; - else iflags.wc_align_status = window_pick->item.a_int; - free((genericptr_t)window_pick); - } - destroy_nhwindow(tmpwin); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + any.a_int = ALIGN_TOP; + add_menu(tmpwin, NO_GLYPH, &any, 't', 0, ATR_NONE, "top", + MENU_UNSELECTED); + any.a_int = ALIGN_BOTTOM; + add_menu(tmpwin, NO_GLYPH, &any, 'b', 0, ATR_NONE, "bottom", + MENU_UNSELECTED); + any.a_int = ALIGN_LEFT; + add_menu(tmpwin, NO_GLYPH, &any, 'l', 0, ATR_NONE, "left", + MENU_UNSELECTED); + any.a_int = ALIGN_RIGHT; + add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "right", + MENU_UNSELECTED); + Sprintf(abuf, "Select %s window placement relative to the map:", + msg ? "message" : "status"); + end_menu(tmpwin, abuf); + if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { + if (msg) + iflags.wc_align_message = window_pick->item.a_int; + else + iflags.wc_align_status = window_pick->item.a_int; + free((genericptr_t) window_pick); + } + destroy_nhwindow(tmpwin); } else if (!strcmp("number_pad", optname)) { - static const char *npchoices[] = { - " 0 (off)", " 1 (on)", " 2 (on, MSDOS compatible)", - " 3 (on, phone-style digit layout)", - " 4 (on, phone-style layout, MSDOS compatible)", - "-1 (off, 'z' to move upper-left, 'y' to zap wands)" - }; - menu_item *mode_pick = (menu_item *)0; + static const char *npchoices[] = { + " 0 (off)", " 1 (on)", " 2 (on, MSDOS compatible)", + " 3 (on, phone-style digit layout)", + " 4 (on, phone-style layout, MSDOS compatible)", + "-1 (off, 'z' to move upper-left, 'y' to zap wands)" + }; + menu_item *mode_pick = (menu_item *) 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - for (i = 0; i < SIZE(npchoices); i++) { - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, 'a' + i, 0, - ATR_NONE, npchoices[i], MENU_UNSELECTED); - } - end_menu(tmpwin, "Select number_pad mode:"); - if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) { - switch (mode_pick->item.a_int - 1) { - case 0: iflags.num_pad = FALSE; iflags.num_pad_mode = 0; break; - case 1: iflags.num_pad = TRUE; iflags.num_pad_mode = 0; break; - case 2: iflags.num_pad = TRUE; iflags.num_pad_mode = 1; break; - case 3: iflags.num_pad = TRUE; iflags.num_pad_mode = 2; break; - case 4: iflags.num_pad = TRUE; iflags.num_pad_mode = 3; break; - /* last menu choice: number_pad == -1 */ - case 5: iflags.num_pad = FALSE; iflags.num_pad_mode = 1; break; - } - reset_commands(FALSE); - number_pad(iflags.num_pad ? 1 : 0); - free((genericptr_t)mode_pick); - } - destroy_nhwindow(tmpwin); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + for (i = 0; i < SIZE(npchoices); i++) { + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, 'a' + i, 0, ATR_NONE, + npchoices[i], MENU_UNSELECTED); + } + end_menu(tmpwin, "Select number_pad mode:"); + if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) { + switch (mode_pick->item.a_int - 1) { + case 0: + iflags.num_pad = FALSE; + iflags.num_pad_mode = 0; + break; + case 1: + iflags.num_pad = TRUE; + iflags.num_pad_mode = 0; + break; + case 2: + iflags.num_pad = TRUE; + iflags.num_pad_mode = 1; + break; + case 3: + iflags.num_pad = TRUE; + iflags.num_pad_mode = 2; + break; + case 4: + iflags.num_pad = TRUE; + iflags.num_pad_mode = 3; + break; + /* last menu choice: number_pad == -1 */ + case 5: + iflags.num_pad = FALSE; + iflags.num_pad_mode = 1; + break; + } + reset_commands(FALSE); + number_pad(iflags.num_pad ? 1 : 0); + free((genericptr_t) mode_pick); + } + destroy_nhwindow(tmpwin); } else if (!strcmp("menu_headings", optname)) { - int mhattr = query_attr("How to highlight menu headings:"); - if (mhattr != -1) iflags.menu_headings = mhattr; + int mhattr = query_attr("How to highlight menu headings:"); + if (mhattr != -1) + iflags.menu_headings = mhattr; } else if (!strcmp("menucolors", optname)) { - int opt_idx, nmc, mcclr, mcattr; - char mcbuf[BUFSZ]; -menucolors_again: - nmc = count_menucolors(); - opt_idx = handle_add_list_remove("menucolor", nmc); - if (opt_idx == 3) { - ; /* done--fall through to function exit */ - } else if (opt_idx == 0) { /* add new */ - getlin("What new menucolor pattern?", mcbuf); - if (*mcbuf == '\033' || !*mcbuf) goto menucolors_again; - mcclr = query_color(); - if (mcclr == -1) goto menucolors_again; - mcattr = query_attr(NULL); - if (mcattr == -1) goto menucolors_again; - if (!add_menu_coloring_parsed(mcbuf, mcclr, mcattr)) { - pline("Error adding the menu color."); - wait_synch(); - goto menucolors_again; - } - } else { /* list or remove */ - int pick_idx, pick_cnt; - int mc_idx; - menu_item *pick_list = (menu_item *)0; - struct menucoloring *tmp = menu_colorings; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - mc_idx = 0; - while (tmp) { - const char *sattr = attr2attrname(tmp->attr); - const char *sclr = clr2colorname(tmp->color); - any.a_int = (++mc_idx); - Sprintf(mcbuf, "\"%s\"=%s%s%s", tmp->origstr, sclr, - (tmp->attr != ATR_NONE) ? " & " : "", - (tmp->attr != ATR_NONE) ? sattr : ""); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, mcbuf, MENU_UNSELECTED); - tmp = tmp->next; - } - Sprintf(mcbuf, "%s menu colors", - (opt_idx == 1) ? "List of" : "Remove which"); - end_menu(tmpwin, mcbuf); - pick_cnt = select_menu(tmpwin, - (opt_idx == 1) ? PICK_NONE : PICK_ANY, - &pick_list); - if (pick_cnt > 0) { - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) - free_one_menu_coloring(pick_list[pick_idx].item.a_int - 1 - pick_idx); - } - free((genericptr_t)pick_list); - pick_list = (menu_item *)0; - destroy_nhwindow(tmpwin); - if (pick_cnt >= 0) goto menucolors_again; - } + int opt_idx, nmc, mcclr, mcattr; + char mcbuf[BUFSZ]; + menucolors_again: + nmc = count_menucolors(); + opt_idx = handle_add_list_remove("menucolor", nmc); + if (opt_idx == 3) { + ; /* done--fall through to function exit */ + } else if (opt_idx == 0) { /* add new */ + getlin("What new menucolor pattern?", mcbuf); + if (*mcbuf == '\033' || !*mcbuf) + goto menucolors_again; + mcclr = query_color(); + if (mcclr == -1) + goto menucolors_again; + mcattr = query_attr(NULL); + if (mcattr == -1) + goto menucolors_again; + if (!add_menu_coloring_parsed(mcbuf, mcclr, mcattr)) { + pline("Error adding the menu color."); + wait_synch(); + goto menucolors_again; + } + } else { /* list or remove */ + int pick_idx, pick_cnt; + int mc_idx; + menu_item *pick_list = (menu_item *) 0; + struct menucoloring *tmp = menu_colorings; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + mc_idx = 0; + while (tmp) { + const char *sattr = attr2attrname(tmp->attr); + const char *sclr = clr2colorname(tmp->color); + any.a_int = (++mc_idx); + Sprintf(mcbuf, "\"%s\"=%s%s%s", tmp->origstr, sclr, + (tmp->attr != ATR_NONE) ? " & " : "", + (tmp->attr != ATR_NONE) ? sattr : ""); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, mcbuf, + MENU_UNSELECTED); + tmp = tmp->next; + } + Sprintf(mcbuf, "%s menu colors", + (opt_idx == 1) ? "List of" : "Remove which"); + end_menu(tmpwin, mcbuf); + pick_cnt = select_menu( + tmpwin, (opt_idx == 1) ? PICK_NONE : PICK_ANY, &pick_list); + if (pick_cnt > 0) { + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) + free_one_menu_coloring(pick_list[pick_idx].item.a_int - 1 + - pick_idx); + } + free((genericptr_t) pick_list); + pick_list = (menu_item *) 0; + destroy_nhwindow(tmpwin); + if (pick_cnt >= 0) + goto menucolors_again; + } } else if (!strcmp("autopickup_exception", optname)) { - int opt_idx, pass, totalapes = 0, numapes[2] = {0,0}; - char apebuf[1+BUFSZ]; /* so &apebuf[1] is BUFSZ long for getlin() */ - struct autopickup_exception *ape; -ape_again: - totalapes = count_ape_maps(&numapes[AP_LEAVE], &numapes[AP_GRAB]); - opt_idx = handle_add_list_remove("autopickup exception", totalapes); - if (opt_idx == 3) { - ; /* done--fall through to function exit */ - } else if (opt_idx == 0) { /* add new */ - getlin("What new autopickup exception pattern?", &apebuf[1]); - mungspaces(&apebuf[1]); /* regularize whitespace */ - if (apebuf[1] == '\033') { - ; /* fall through to function exit */ - } else { - if (apebuf[1]) { - apebuf[0] = '\"'; - /* guarantee room for \" prefix and \"\0 suffix; - -2 is good enough for apebuf[] but -3 makes - sure the whole thing fits within normal BUFSZ */ - apebuf[sizeof apebuf - 3] = '\0'; - Strcat(apebuf, "\""); - add_autopickup_exception(apebuf); - } - goto ape_again; - } - } else { /* list or remove */ - int pick_idx, pick_cnt; - menu_item *pick_list = (menu_item *)0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { - if (numapes[pass] == 0) continue; - ape = iflags.autopickup_exceptions[pass]; - any = zeroany; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - (pass == 0) ? "Never pickup" : "Always pickup", - MENU_UNSELECTED); - for (i = 0; i < numapes[pass] && ape; i++) { - any.a_void = (opt_idx == 1) ? 0 : ape; - Sprintf(apebuf, "\"%s\"", ape->pattern); - add_menu(tmpwin, NO_GLYPH, &any, - 0, 0, ATR_NONE, apebuf, MENU_UNSELECTED); - ape = ape->next; - } - } - Sprintf(apebuf, "%s autopickup exceptions", - (opt_idx == 1) ? "List of" : "Remove which"); - end_menu(tmpwin, apebuf); - pick_cnt = select_menu(tmpwin, - (opt_idx == 1) ? PICK_NONE : PICK_ANY, - &pick_list); - if (pick_cnt > 0) { - for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) - remove_autopickup_exception( - (struct autopickup_exception *)pick_list[pick_idx].item.a_void); - } - free((genericptr_t)pick_list); - pick_list = (menu_item *)0; - destroy_nhwindow(tmpwin); - if (pick_cnt >= 0) goto ape_again; - } + int opt_idx, pass, totalapes = 0, numapes[2] = { 0, 0 }; + char apebuf[1 + BUFSZ]; /* so &apebuf[1] is BUFSZ long for getlin() */ + struct autopickup_exception *ape; + ape_again: + totalapes = count_ape_maps(&numapes[AP_LEAVE], &numapes[AP_GRAB]); + opt_idx = handle_add_list_remove("autopickup exception", totalapes); + if (opt_idx == 3) { + ; /* done--fall through to function exit */ + } else if (opt_idx == 0) { /* add new */ + getlin("What new autopickup exception pattern?", &apebuf[1]); + mungspaces(&apebuf[1]); /* regularize whitespace */ + if (apebuf[1] == '\033') { + ; /* fall through to function exit */ + } else { + if (apebuf[1]) { + apebuf[0] = '\"'; + /* guarantee room for \" prefix and \"\0 suffix; + -2 is good enough for apebuf[] but -3 makes + sure the whole thing fits within normal BUFSZ */ + apebuf[sizeof apebuf - 3] = '\0'; + Strcat(apebuf, "\""); + add_autopickup_exception(apebuf); + } + goto ape_again; + } + } else { /* list or remove */ + int pick_idx, pick_cnt; + menu_item *pick_list = (menu_item *) 0; + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { + if (numapes[pass] == 0) + continue; + ape = iflags.autopickup_exceptions[pass]; + any = zeroany; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + (pass == 0) ? "Never pickup" : "Always pickup", + MENU_UNSELECTED); + for (i = 0; i < numapes[pass] && ape; i++) { + any.a_void = (opt_idx == 1) ? 0 : ape; + Sprintf(apebuf, "\"%s\"", ape->pattern); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, apebuf, + MENU_UNSELECTED); + ape = ape->next; + } + } + Sprintf(apebuf, "%s autopickup exceptions", + (opt_idx == 1) ? "List of" : "Remove which"); + end_menu(tmpwin, apebuf); + pick_cnt = select_menu( + tmpwin, (opt_idx == 1) ? PICK_NONE : PICK_ANY, &pick_list); + if (pick_cnt > 0) { + for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) + remove_autopickup_exception( + (struct autopickup_exception *) pick_list[pick_idx] + .item.a_void); + } + free((genericptr_t) pick_list); + pick_list = (menu_item *) 0; + destroy_nhwindow(tmpwin); + if (pick_cnt >= 0) + goto ape_again; + } } else if (!strcmp("symset", optname) - || !strcmp("roguesymset", optname)) { - menu_item *symset_pick = (menu_item *)0; - boolean primaryflag = (*optname == 's'), - rogueflag = (*optname == 'r'), - ready_to_switch = FALSE, - nothing_to_do = FALSE; - int res; - char *symset_name, fmtstr[20]; - struct symsetentry *sl; - int setcount = 0; - int chosen = -2, which_set; - - if (rogueflag) which_set = ROGUESET; - else - which_set = PRIMARY; + || !strcmp("roguesymset", optname)) { + menu_item *symset_pick = (menu_item *) 0; + boolean primaryflag = (*optname == 's'), + rogueflag = (*optname == 'r'), ready_to_switch = FALSE, + nothing_to_do = FALSE; + int res; + char *symset_name, fmtstr[20]; + struct symsetentry *sl; + int setcount = 0; + int chosen = -2, which_set; - /* clear symset[].name as a flag to read_sym_file() to build list */ - symset_name = symset[which_set].name; - symset[which_set].name = (char *)0; - symset_list = (struct symsetentry *)0; + if (rogueflag) + which_set = ROGUESET; + else + which_set = PRIMARY; - res = read_sym_file(which_set); - if (res && symset_list) { - char symsetchoice[BUFSZ]; - int let = 'a', biggest = 0, thissize = 0; - sl = symset_list; - while (sl) { - /* check restrictions */ - if ((!rogueflag && sl->rogue) || - (!primaryflag && sl->primary)) { - sl = sl->next; - continue; - } - setcount++; - /* find biggest name */ - if (sl->name) thissize = strlen(sl->name); - if (thissize > biggest) biggest = thissize; - sl = sl->next; - } - if (!setcount) { - pline("There are no appropriate %ssymbol sets available.", - (rogueflag) ? "rogue level " : - (primaryflag) ? "primary " : - ""); - return TRUE; - } + /* clear symset[].name as a flag to read_sym_file() to build list */ + symset_name = symset[which_set].name; + symset[which_set].name = (char *) 0; + symset_list = (struct symsetentry *) 0; - Sprintf(fmtstr,"%%-%ds %%s", biggest + 5); - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any.a_int = 1; - add_menu(tmpwin, NO_GLYPH, &any, let++, 0, - ATR_NONE, "Default Symbols", MENU_UNSELECTED); + res = read_sym_file(which_set); + if (res && symset_list) { + char symsetchoice[BUFSZ]; + int let = 'a', biggest = 0, thissize = 0; + sl = symset_list; + while (sl) { + /* check restrictions */ + if ((!rogueflag && sl->rogue) + || (!primaryflag && sl->primary)) { + sl = sl->next; + continue; + } + setcount++; + /* find biggest name */ + if (sl->name) + thissize = strlen(sl->name); + if (thissize > biggest) + biggest = thissize; + sl = sl->next; + } + if (!setcount) { + pline("There are no appropriate %ssymbol sets available.", + (rogueflag) ? "rogue level " + : (primaryflag) ? "primary " : ""); + return TRUE; + } - sl = symset_list; - while (sl) { - /* check restrictions */ - if ((!rogueflag && sl->rogue) || - (!primaryflag && sl->primary)) { - sl = sl->next; - continue; - } - if (sl->name) { - any.a_int = sl->idx + 2; - Sprintf(symsetchoice, fmtstr, sl->name, - sl->desc ? sl->desc : ""); - add_menu(tmpwin, NO_GLYPH, &any, let, 0, - ATR_NONE, symsetchoice, MENU_UNSELECTED); - if (let == 'z') let = 'A'; - else let++; - } - sl = sl->next; - } - end_menu(tmpwin, "Select symbol set:"); - if (select_menu(tmpwin, PICK_ONE, &symset_pick) > 0) { - chosen = symset_pick->item.a_int - 2; - free((genericptr_t)symset_pick); - } - destroy_nhwindow(tmpwin); + Sprintf(fmtstr, "%%-%ds %%s", biggest + 5); + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any.a_int = 1; + add_menu(tmpwin, NO_GLYPH, &any, let++, 0, ATR_NONE, + "Default Symbols", MENU_UNSELECTED); - if (chosen > -1) { - /* chose an actual symset name from file */ - sl = symset_list; - while (sl) { - if (sl->idx == chosen) { - if (symset_name) { - free((genericptr_t)symset_name); - symset_name = (char *)0; - } - /* free the now stale attributes */ - clear_symsetentry(which_set, TRUE); + sl = symset_list; + while (sl) { + /* check restrictions */ + if ((!rogueflag && sl->rogue) + || (!primaryflag && sl->primary)) { + sl = sl->next; + continue; + } + if (sl->name) { + any.a_int = sl->idx + 2; + Sprintf(symsetchoice, fmtstr, sl->name, + sl->desc ? sl->desc : ""); + add_menu(tmpwin, NO_GLYPH, &any, let, 0, ATR_NONE, + symsetchoice, MENU_UNSELECTED); + if (let == 'z') + let = 'A'; + else + let++; + } + sl = sl->next; + } + end_menu(tmpwin, "Select symbol set:"); + if (select_menu(tmpwin, PICK_ONE, &symset_pick) > 0) { + chosen = symset_pick->item.a_int - 2; + free((genericptr_t) symset_pick); + } + destroy_nhwindow(tmpwin); - /* transfer only the name of the symbol set */ - symset[which_set].name = - (char *)alloc(strlen(sl->name)+1); - Strcpy(symset[which_set].name, sl->name); - ready_to_switch = TRUE; - break; - } - sl = sl->next; - } - } + if (chosen > -1) { + /* chose an actual symset name from file */ + sl = symset_list; + while (sl) { + if (sl->idx == chosen) { + if (symset_name) { + free((genericptr_t) symset_name); + symset_name = (char *) 0; + } + /* free the now stale attributes */ + clear_symsetentry(which_set, TRUE); - else if (chosen == -1) { - /* explicit selection of defaults */ - /* free the now stale symset attributes */ - if (symset_name) free ((genericptr_t)symset_name); - symset_name = (char *)0; - clear_symsetentry(which_set, TRUE); - } - else nothing_to_do = TRUE; - } else if (!res) { - /* The symbols file could not be accessed */ - pline("Unable to access \"%s\" file.", SYMBOLS); - return TRUE; - } else if (!symset_list) { - /* The symbols file was empty */ - pline("There were no symbol sets found in \"%s\".", - SYMBOLS); - return TRUE; - } + /* transfer only the name of the symbol set */ + symset[which_set].name = + (char *) alloc(strlen(sl->name) + 1); + Strcpy(symset[which_set].name, sl->name); + ready_to_switch = TRUE; + break; + } + sl = sl->next; + } + } - /* clean up */ - while (symset_list) { - sl = symset_list; - if (sl->name) free((genericptr_t)sl->name); - sl->name = (char *)0; + else if (chosen == -1) { + /* explicit selection of defaults */ + /* free the now stale symset attributes */ + if (symset_name) + free((genericptr_t) symset_name); + symset_name = (char *) 0; + clear_symsetentry(which_set, TRUE); + } else + nothing_to_do = TRUE; + } else if (!res) { + /* The symbols file could not be accessed */ + pline("Unable to access \"%s\" file.", SYMBOLS); + return TRUE; + } else if (!symset_list) { + /* The symbols file was empty */ + pline("There were no symbol sets found in \"%s\".", SYMBOLS); + return TRUE; + } - if (sl->desc) free((genericptr_t)sl->desc); - sl->desc = (char *)0; + /* clean up */ + while (symset_list) { + sl = symset_list; + if (sl->name) + free((genericptr_t) sl->name); + sl->name = (char *) 0; - symset_list = sl->next; - free((genericptr_t)sl); - } + if (sl->desc) + free((genericptr_t) sl->desc); + sl->desc = (char *) 0; - if (nothing_to_do) return TRUE; + symset_list = sl->next; + free((genericptr_t) sl); + } - if (!symset[which_set].name && symset_name) - symset[which_set].name = symset_name; + if (nothing_to_do) + return TRUE; - /* Set default symbols and clear the handling value */ - if(rogueflag) - init_r_symbols(); - else - init_l_symbols(); + if (!symset[which_set].name && symset_name) + symset[which_set].name = symset_name; - if (symset[which_set].name) { - if (read_sym_file(which_set)) - ready_to_switch = TRUE; - else { - clear_symsetentry(which_set, TRUE); - return TRUE; - } - } + /* Set default symbols and clear the handling value */ + if (rogueflag) + init_r_symbols(); + else + init_l_symbols(); - if (ready_to_switch) switch_symbols(TRUE); + if (symset[which_set].name) { + if (read_sym_file(which_set)) + ready_to_switch = TRUE; + else { + clear_symsetentry(which_set, TRUE); + return TRUE; + } + } - if (Is_rogue_level(&u.uz)) { - if (rogueflag) - assign_graphics(ROGUESET); - } else if (!rogueflag) assign_graphics(PRIMARY); - need_redraw = TRUE; - return TRUE; + if (ready_to_switch) + switch_symbols(TRUE); + + if (Is_rogue_level(&u.uz)) { + if (rogueflag) + assign_graphics(ROGUESET); + } else if (!rogueflag) + assign_graphics(PRIMARY); + need_redraw = TRUE; + return TRUE; } else { - /* didn't match any of the special options */ - return FALSE; + /* didn't match any of the special options */ + return FALSE; } return TRUE; } -#define rolestring(val,array,field) ((val >= 0) ? array[val].field : \ - (val == ROLE_RANDOM) ? randomrole : none) +#define rolestring(val, array, field) \ + ((val >= 0) ? array[val].field : (val == ROLE_RANDOM) ? randomrole : none) /* This is ugly. We have all the option names in the compopt[] array, but we need to look at each option individually to get the value. */ @@ -3950,364 +4148,415 @@ get_compopt_value(optname, buf) const char *optname; char *buf; { - char ocl[MAXOCLASSES+1]; - static const char none[] = "(none)", randomrole[] = "random", - to_be_done[] = "(to be done)", - defopt[] = "default", - defbrief[] = "def"; - int i; + char ocl[MAXOCLASSES + 1]; + static const char none[] = "(none)", randomrole[] = "random", + to_be_done[] = "(to be done)", defopt[] = "default", + defbrief[] = "def"; + int i; - buf[0] = '\0'; - if (!strcmp(optname,"align_message")) - Sprintf(buf, "%s", iflags.wc_align_message == ALIGN_TOP ? "top" : - iflags.wc_align_message == ALIGN_LEFT ? "left" : - iflags.wc_align_message == ALIGN_BOTTOM ? "bottom" : - iflags.wc_align_message == ALIGN_RIGHT ? "right" : - defopt); - else if (!strcmp(optname,"align_status")) - Sprintf(buf, "%s", iflags.wc_align_status == ALIGN_TOP ? "top" : - iflags.wc_align_status == ALIGN_LEFT ? "left" : - iflags.wc_align_status == ALIGN_BOTTOM ? "bottom" : - iflags.wc_align_status == ALIGN_RIGHT ? "right" : - defopt); - else if (!strcmp(optname,"align")) - Sprintf(buf, "%s", rolestring(flags.initalign, aligns, adj)); + buf[0] = '\0'; + if (!strcmp(optname, "align_message")) + Sprintf(buf, "%s", + iflags.wc_align_message == ALIGN_TOP + ? "top" + : iflags.wc_align_message == ALIGN_LEFT + ? "left" + : iflags.wc_align_message == ALIGN_BOTTOM + ? "bottom" + : iflags.wc_align_message == ALIGN_RIGHT + ? "right" + : defopt); + else if (!strcmp(optname, "align_status")) + Sprintf(buf, "%s", + iflags.wc_align_status == ALIGN_TOP + ? "top" + : iflags.wc_align_status == ALIGN_LEFT + ? "left" + : iflags.wc_align_status == ALIGN_BOTTOM + ? "bottom" + : iflags.wc_align_status == ALIGN_RIGHT + ? "right" + : defopt); + else if (!strcmp(optname, "align")) + Sprintf(buf, "%s", rolestring(flags.initalign, aligns, adj)); #ifdef WIN32 - else if (!strcmp(optname,"altkeyhandler")) - Sprintf(buf, "%s", iflags.altkeyhandler[0] ? - iflags.altkeyhandler : "default"); + else if (!strcmp(optname, "altkeyhandler")) + Sprintf(buf, "%s", + iflags.altkeyhandler[0] ? iflags.altkeyhandler : "default"); #endif #ifdef BACKWARD_COMPAT - else if (!strcmp(optname, "boulder")) - Sprintf(buf, "%c", iflags.bouldersym ? - iflags.bouldersym : - showsyms[(int)objects[BOULDER].oc_class + SYM_OFF_O]); + else if (!strcmp(optname, "boulder")) + Sprintf(buf, "%c", + iflags.bouldersym + ? iflags.bouldersym + : showsyms[(int) objects[BOULDER].oc_class + SYM_OFF_O]); #endif - else if (!strcmp(optname, "catname")) - Sprintf(buf, "%s", catname[0] ? catname : none); - else if (!strcmp(optname, "disclose")) - for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { - if (i) (void) strkitten(buf, ' '); - (void) strkitten(buf, flags.end_disclose[i]); - (void) strkitten(buf, disclosure_options[i]); - } - else if (!strcmp(optname, "dogname")) - Sprintf(buf, "%s", dogname[0] ? dogname : none); - else if (!strcmp(optname, "dungeon")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "effects")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "font_map")) - Sprintf(buf, "%s", iflags.wc_font_map ? iflags.wc_font_map : defopt); - else if (!strcmp(optname, "font_message")) - Sprintf(buf, "%s", iflags.wc_font_message ? iflags.wc_font_message : defopt); - else if (!strcmp(optname, "font_status")) - Sprintf(buf, "%s", iflags.wc_font_status ? iflags.wc_font_status : defopt); - else if (!strcmp(optname, "font_menu")) - Sprintf(buf, "%s", iflags.wc_font_menu ? iflags.wc_font_menu : defopt); - else if (!strcmp(optname, "font_text")) - Sprintf(buf, "%s", iflags.wc_font_text ? iflags.wc_font_text : defopt); - else if (!strcmp(optname, "font_size_map")) { - if (iflags.wc_fontsiz_map) Sprintf(buf, "%d", iflags.wc_fontsiz_map); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "font_size_message")) { - if (iflags.wc_fontsiz_message) Sprintf(buf, "%d", - iflags.wc_fontsiz_message); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "font_size_status")) { - if (iflags.wc_fontsiz_status) Sprintf(buf, "%d", iflags.wc_fontsiz_status); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "font_size_menu")) { - if (iflags.wc_fontsiz_menu) Sprintf(buf, "%d", iflags.wc_fontsiz_menu); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "font_size_text")) { - if (iflags.wc_fontsiz_text) Sprintf(buf, "%d",iflags.wc_fontsiz_text); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "fruit")) - Sprintf(buf, "%s", pl_fruit); - else if (!strcmp(optname, "gender")) - Sprintf(buf, "%s", rolestring(flags.initgend, genders, adj)); - else if (!strcmp(optname, "horsename")) - Sprintf(buf, "%s", horsename[0] ? horsename : none); - else if (!strcmp(optname, "map_mode")) - Sprintf(buf, "%s", - iflags.wc_map_mode == MAP_MODE_TILES ? "tiles" : - iflags.wc_map_mode == MAP_MODE_ASCII4x6 ? "ascii4x6" : - iflags.wc_map_mode == MAP_MODE_ASCII6x8 ? "ascii6x8" : - iflags.wc_map_mode == MAP_MODE_ASCII8x8 ? "ascii8x8" : - iflags.wc_map_mode == MAP_MODE_ASCII16x8 ? "ascii16x8" : - iflags.wc_map_mode == MAP_MODE_ASCII7x12 ? "ascii7x12" : - iflags.wc_map_mode == MAP_MODE_ASCII8x12 ? "ascii8x12" : - iflags.wc_map_mode == MAP_MODE_ASCII16x12 ? "ascii16x12" : - iflags.wc_map_mode == MAP_MODE_ASCII12x16 ? "ascii12x16" : - iflags.wc_map_mode == MAP_MODE_ASCII10x18 ? "ascii10x18" : - iflags.wc_map_mode == MAP_MODE_ASCII_FIT_TO_SCREEN ? - "fit_to_screen" : defopt); - else if (!strcmp(optname, "menustyle")) - Sprintf(buf, "%s", menutype[(int)flags.menu_style] ); - else if (!strcmp(optname, "menu_deselect_all")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_deselect_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_first_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_invert_all")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_headings")) { - Sprintf(buf, "%s", attr2attrname(iflags.menu_headings)); - } - else if (!strcmp(optname, "menu_invert_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_last_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_next_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_previous_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_search")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_select_all")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "menu_select_page")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "monsters")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "msghistory")) - Sprintf(buf, "%u", iflags.msg_history); + else if (!strcmp(optname, "catname")) + Sprintf(buf, "%s", catname[0] ? catname : none); + else if (!strcmp(optname, "disclose")) + for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { + if (i) + (void) strkitten(buf, ' '); + (void) strkitten(buf, flags.end_disclose[i]); + (void) strkitten(buf, disclosure_options[i]); + } + else if (!strcmp(optname, "dogname")) + Sprintf(buf, "%s", dogname[0] ? dogname : none); + else if (!strcmp(optname, "dungeon")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "effects")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "font_map")) + Sprintf(buf, "%s", iflags.wc_font_map ? iflags.wc_font_map : defopt); + else if (!strcmp(optname, "font_message")) + Sprintf(buf, "%s", + iflags.wc_font_message ? iflags.wc_font_message : defopt); + else if (!strcmp(optname, "font_status")) + Sprintf(buf, "%s", + iflags.wc_font_status ? iflags.wc_font_status : defopt); + else if (!strcmp(optname, "font_menu")) + Sprintf(buf, "%s", + iflags.wc_font_menu ? iflags.wc_font_menu : defopt); + else if (!strcmp(optname, "font_text")) + Sprintf(buf, "%s", + iflags.wc_font_text ? iflags.wc_font_text : defopt); + else if (!strcmp(optname, "font_size_map")) { + if (iflags.wc_fontsiz_map) + Sprintf(buf, "%d", iflags.wc_fontsiz_map); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "font_size_message")) { + if (iflags.wc_fontsiz_message) + Sprintf(buf, "%d", iflags.wc_fontsiz_message); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "font_size_status")) { + if (iflags.wc_fontsiz_status) + Sprintf(buf, "%d", iflags.wc_fontsiz_status); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "font_size_menu")) { + if (iflags.wc_fontsiz_menu) + Sprintf(buf, "%d", iflags.wc_fontsiz_menu); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "font_size_text")) { + if (iflags.wc_fontsiz_text) + Sprintf(buf, "%d", iflags.wc_fontsiz_text); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "fruit")) + Sprintf(buf, "%s", pl_fruit); + else if (!strcmp(optname, "gender")) + Sprintf(buf, "%s", rolestring(flags.initgend, genders, adj)); + else if (!strcmp(optname, "horsename")) + Sprintf(buf, "%s", horsename[0] ? horsename : none); + else if (!strcmp(optname, "map_mode")) + Sprintf( + buf, "%s", + iflags.wc_map_mode == MAP_MODE_TILES + ? "tiles" + : iflags.wc_map_mode == MAP_MODE_ASCII4x6 + ? "ascii4x6" + : iflags.wc_map_mode == MAP_MODE_ASCII6x8 + ? "ascii6x8" + : iflags.wc_map_mode == MAP_MODE_ASCII8x8 + ? "ascii8x8" + : iflags.wc_map_mode == MAP_MODE_ASCII16x8 + ? "ascii16x8" + : iflags.wc_map_mode + == MAP_MODE_ASCII7x12 + ? "ascii7x12" + : iflags.wc_map_mode + == MAP_MODE_ASCII8x12 + ? "ascii8x12" + : iflags.wc_map_mode + == MAP_MODE_ASCII16x12 + ? "ascii16x12" + : iflags.wc_map_mode + == MAP_MODE_ASCII12x16 + ? "ascii12x16" + : iflags.wc_map_mode + == MAP_MODE_ASCII10x18 + ? "asci" + "i10x" + "18" + : iflags.wc_map_mode + == MAP_MODE_ASCII_FIT_TO_SCREEN + ? "fit_to_screen" + : defopt); + else if (!strcmp(optname, "menustyle")) + Sprintf(buf, "%s", menutype[(int) flags.menu_style]); + else if (!strcmp(optname, "menu_deselect_all")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_deselect_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_first_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_invert_all")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_headings")) { + Sprintf(buf, "%s", attr2attrname(iflags.menu_headings)); + } else if (!strcmp(optname, "menu_invert_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_last_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_next_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_previous_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_search")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_select_all")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "menu_select_page")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "monsters")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "msghistory")) + Sprintf(buf, "%u", iflags.msg_history); #ifdef TTY_GRAPHICS - else if (!strcmp(optname, "msg_window")) - Sprintf(buf, "%s", (iflags.prevmsg_window=='s') ? "single" : - (iflags.prevmsg_window=='c') ? "combination" : - (iflags.prevmsg_window=='f') ? "full" : "reversed"); + else if (!strcmp(optname, "msg_window")) + Sprintf(buf, "%s", (iflags.prevmsg_window == 's') + ? "single" + : (iflags.prevmsg_window == 'c') + ? "combination" + : (iflags.prevmsg_window == 'f') + ? "full" + : "reversed"); #endif - else if (!strcmp(optname, "name")) - Sprintf(buf, "%s", plname); - else if (!strcmp(optname, "number_pad")) { - static const char *numpadmodes[] = { - "0=off", "1=on", - "2=on, MSDOS compatible", "3=on, phone-style layout", - "4=on, phone layout, MSDOS compatible", - "-1=off, y & z swapped", /*[5]*/ - }; - int indx = Cmd.num_pad ? - (Cmd.phone_layout ? (Cmd.pcHack_compat ? 4 : 3) : - (Cmd.pcHack_compat ? 2 : 1)) : - Cmd.swap_yz ? 5 : 0; + else if (!strcmp(optname, "name")) + Sprintf(buf, "%s", plname); + else if (!strcmp(optname, "number_pad")) { + static const char *numpadmodes[] = { + "0=off", "1=on", "2=on, MSDOS compatible", + "3=on, phone-style layout", + "4=on, phone layout, MSDOS compatible", + "-1=off, y & z swapped", /*[5]*/ + }; + int indx = Cmd.num_pad + ? (Cmd.phone_layout ? (Cmd.pcHack_compat ? 4 : 3) + : (Cmd.pcHack_compat ? 2 : 1)) + : Cmd.swap_yz ? 5 : 0; - Strcpy(buf, numpadmodes[indx]); - } else if (!strcmp(optname, "objects")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "packorder")) { - oc_to_str(flags.inv_order, ocl); - Sprintf(buf, "%s", ocl); - } + Strcpy(buf, numpadmodes[indx]); + } else if (!strcmp(optname, "objects")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "packorder")) { + oc_to_str(flags.inv_order, ocl); + Sprintf(buf, "%s", ocl); + } #ifdef CHANGE_COLOR - else if (!strcmp(optname, "palette")) - Sprintf(buf, "%s", get_color_string()); + else if (!strcmp(optname, "palette")) + Sprintf(buf, "%s", get_color_string()); #endif - else if (!strcmp(optname, "paranoid_confirmation")) { - char tmpbuf[QBUFSZ]; + else if (!strcmp(optname, "paranoid_confirmation")) { + char tmpbuf[QBUFSZ]; - tmpbuf[0] = '\0'; - if (ParanoidConfirm) Strcat(tmpbuf, " Confirm"); - if (ParanoidQuit) Strcat(tmpbuf, " quit"); - if (ParanoidDie) Strcat(tmpbuf, " die"); - if (ParanoidBones) Strcat(tmpbuf, " bones"); - if (ParanoidHit) Strcat(tmpbuf, " attack"); - if (ParanoidPray) Strcat(tmpbuf, " pray"); - if (ParanoidRemove) Strcat(tmpbuf, " Remove"); - Strcpy(buf, tmpbuf[0] ? &tmpbuf[1] : "none"); - } else if (!strcmp(optname, "pettype")) - Sprintf(buf, "%s", (preferred_pet == 'c') ? "cat" : - (preferred_pet == 'd') ? "dog" : - (preferred_pet == 'h') ? "horse" : - (preferred_pet == 'n') ? "none" : "random"); - else if (!strcmp(optname, "pickup_burden")) - Sprintf(buf, "%s", burdentype[flags.pickup_burden] ); - else if (!strcmp(optname, "pickup_types")) { - oc_to_str(flags.pickup_types, ocl); - Sprintf(buf, "%s", ocl[0] ? ocl : "all" ); - } - else if (!strcmp(optname, "pile_limit")) - Sprintf(buf, "%d", flags.pile_limit); - else if (!strcmp(optname, "playmode")) { - Strcpy(buf, - wizard ? "debug" : discover ? "explore" : "normal"); - } - else if (!strcmp(optname, "race")) - Sprintf(buf, "%s", rolestring(flags.initrace, races, noun)); - else if (!strcmp(optname, "roguesymset")) { - Sprintf(buf, "%s", - symset[ROGUESET].name ? - symset[ROGUESET].name : - "default"); - if (currentgraphics == ROGUESET && symset[ROGUESET].name) - Strcat(buf, ", active"); - } - else if (!strcmp(optname, "role")) - Sprintf(buf, "%s", rolestring(flags.initrole, roles, name.m)); - else if (!strcmp(optname, "runmode")) - Sprintf(buf, "%s", runmodes[flags.runmode]); - else if (!strcmp(optname, "scores")) { - Sprintf(buf, "%d top/%d around%s", flags.end_top, - flags.end_around, flags.end_own ? "/own" : ""); - } - else if (!strcmp(optname, "scroll_amount")) { - if (iflags.wc_scroll_amount) Sprintf(buf, "%d",iflags.wc_scroll_amount); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "scroll_margin")) { - if (iflags.wc_scroll_margin) Sprintf(buf, "%d",iflags.wc_scroll_margin); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "sortloot")) { - char *sortname = (char *)NULL; - for (i=0; i < SIZE(sortltype) && sortname==(char *)NULL; i++) { - if (flags.sortloot == sortltype[i][0]) - sortname = (char *)sortltype[i]; - } - if (sortname != (char *)NULL) - Sprintf(buf, "%s", sortname); - } - else if (!strcmp(optname, "player_selection")) - Sprintf(buf, "%s", iflags.wc_player_selection ? "prompts" : "dialog"); + tmpbuf[0] = '\0'; + if (ParanoidConfirm) + Strcat(tmpbuf, " Confirm"); + if (ParanoidQuit) + Strcat(tmpbuf, " quit"); + if (ParanoidDie) + Strcat(tmpbuf, " die"); + if (ParanoidBones) + Strcat(tmpbuf, " bones"); + if (ParanoidHit) + Strcat(tmpbuf, " attack"); + if (ParanoidPray) + Strcat(tmpbuf, " pray"); + if (ParanoidRemove) + Strcat(tmpbuf, " Remove"); + Strcpy(buf, tmpbuf[0] ? &tmpbuf[1] : "none"); + } else if (!strcmp(optname, "pettype")) + Sprintf(buf, "%s", + (preferred_pet == 'c') + ? "cat" + : (preferred_pet == 'd') + ? "dog" + : (preferred_pet == 'h') + ? "horse" + : (preferred_pet == 'n') ? "none" : "random"); + else if (!strcmp(optname, "pickup_burden")) + Sprintf(buf, "%s", burdentype[flags.pickup_burden]); + else if (!strcmp(optname, "pickup_types")) { + oc_to_str(flags.pickup_types, ocl); + Sprintf(buf, "%s", ocl[0] ? ocl : "all"); + } else if (!strcmp(optname, "pile_limit")) + Sprintf(buf, "%d", flags.pile_limit); + else if (!strcmp(optname, "playmode")) { + Strcpy(buf, wizard ? "debug" : discover ? "explore" : "normal"); + } else if (!strcmp(optname, "race")) + Sprintf(buf, "%s", rolestring(flags.initrace, races, noun)); + else if (!strcmp(optname, "roguesymset")) { + Sprintf(buf, "%s", + symset[ROGUESET].name ? symset[ROGUESET].name : "default"); + if (currentgraphics == ROGUESET && symset[ROGUESET].name) + Strcat(buf, ", active"); + } else if (!strcmp(optname, "role")) + Sprintf(buf, "%s", rolestring(flags.initrole, roles, name.m)); + else if (!strcmp(optname, "runmode")) + Sprintf(buf, "%s", runmodes[flags.runmode]); + else if (!strcmp(optname, "scores")) { + Sprintf(buf, "%d top/%d around%s", flags.end_top, flags.end_around, + flags.end_own ? "/own" : ""); + } else if (!strcmp(optname, "scroll_amount")) { + if (iflags.wc_scroll_amount) + Sprintf(buf, "%d", iflags.wc_scroll_amount); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "scroll_margin")) { + if (iflags.wc_scroll_margin) + Sprintf(buf, "%d", iflags.wc_scroll_margin); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "sortloot")) { + char *sortname = (char *) NULL; + for (i = 0; i < SIZE(sortltype) && sortname == (char *) NULL; i++) { + if (flags.sortloot == sortltype[i][0]) + sortname = (char *) sortltype[i]; + } + if (sortname != (char *) NULL) + Sprintf(buf, "%s", sortname); + } else if (!strcmp(optname, "player_selection")) + Sprintf(buf, "%s", iflags.wc_player_selection ? "prompts" : "dialog"); #ifdef MSDOS - else if (!strcmp(optname, "soundcard")) - Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "soundcard")) + Sprintf(buf, "%s", to_be_done); #endif - else if (!strcmp(optname, "suppress_alert")) { - if (flags.suppress_alert == 0L) - Strcpy(buf, none); - else - Sprintf(buf, "%lu.%lu.%lu", - FEATURE_NOTICE_VER_MAJ, - FEATURE_NOTICE_VER_MIN, - FEATURE_NOTICE_VER_PATCH); - } - else if (!strcmp(optname, "symset")) { - Sprintf(buf, "%s", - symset[PRIMARY].name ? - symset[PRIMARY].name : - "default"); - if (currentgraphics == PRIMARY && symset[PRIMARY].name) - Strcat(buf, ", active"); - } - else if (!strcmp(optname, "tile_file")) - Sprintf(buf, "%s", iflags.wc_tile_file ? iflags.wc_tile_file : defopt); - else if (!strcmp(optname, "tile_height")) { - if (iflags.wc_tile_height) Sprintf(buf, "%d",iflags.wc_tile_height); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "tile_width")) { - if (iflags.wc_tile_width) Sprintf(buf, "%d",iflags.wc_tile_width); - else Strcpy(buf, defopt); - } - else if (!strcmp(optname, "traps")) - Sprintf(buf, "%s", to_be_done); - else if (!strcmp(optname, "vary_msgcount")) { - if (iflags.wc_vary_msgcount) Sprintf(buf, "%d",iflags.wc_vary_msgcount); - else Strcpy(buf, defopt); - } + else if (!strcmp(optname, "suppress_alert")) { + if (flags.suppress_alert == 0L) + Strcpy(buf, none); + else + Sprintf(buf, "%lu.%lu.%lu", FEATURE_NOTICE_VER_MAJ, + FEATURE_NOTICE_VER_MIN, FEATURE_NOTICE_VER_PATCH); + } else if (!strcmp(optname, "symset")) { + Sprintf(buf, "%s", + symset[PRIMARY].name ? symset[PRIMARY].name : "default"); + if (currentgraphics == PRIMARY && symset[PRIMARY].name) + Strcat(buf, ", active"); + } else if (!strcmp(optname, "tile_file")) + Sprintf(buf, "%s", + iflags.wc_tile_file ? iflags.wc_tile_file : defopt); + else if (!strcmp(optname, "tile_height")) { + if (iflags.wc_tile_height) + Sprintf(buf, "%d", iflags.wc_tile_height); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "tile_width")) { + if (iflags.wc_tile_width) + Sprintf(buf, "%d", iflags.wc_tile_width); + else + Strcpy(buf, defopt); + } else if (!strcmp(optname, "traps")) + Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "vary_msgcount")) { + if (iflags.wc_vary_msgcount) + Sprintf(buf, "%d", iflags.wc_vary_msgcount); + else + Strcpy(buf, defopt); + } #ifdef MSDOS - else if (!strcmp(optname, "video")) - Sprintf(buf, "%s", to_be_done); + else if (!strcmp(optname, "video")) + Sprintf(buf, "%s", to_be_done); #endif #ifdef VIDEOSHADES - else if (!strcmp(optname, "videoshades")) - Sprintf(buf, "%s-%s-%s", shade[0],shade[1],shade[2]); - else if (!strcmp(optname, "videocolors")) - Sprintf(buf, "%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d", - ttycolors[CLR_RED], ttycolors[CLR_GREEN], - ttycolors[CLR_BROWN], ttycolors[CLR_BLUE], - ttycolors[CLR_MAGENTA], ttycolors[CLR_CYAN], - ttycolors[CLR_ORANGE], ttycolors[CLR_BRIGHT_GREEN], - ttycolors[CLR_YELLOW], ttycolors[CLR_BRIGHT_BLUE], - ttycolors[CLR_BRIGHT_MAGENTA], - ttycolors[CLR_BRIGHT_CYAN]); + else if (!strcmp(optname, "videoshades")) + Sprintf(buf, "%s-%s-%s", shade[0], shade[1], shade[2]); + else if (!strcmp(optname, "videocolors")) + Sprintf(buf, "%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d", + ttycolors[CLR_RED], ttycolors[CLR_GREEN], + ttycolors[CLR_BROWN], ttycolors[CLR_BLUE], + ttycolors[CLR_MAGENTA], ttycolors[CLR_CYAN], + ttycolors[CLR_ORANGE], ttycolors[CLR_BRIGHT_GREEN], + ttycolors[CLR_YELLOW], ttycolors[CLR_BRIGHT_BLUE], + ttycolors[CLR_BRIGHT_MAGENTA], ttycolors[CLR_BRIGHT_CYAN]); #endif /* VIDEOSHADES */ - else if (!strcmp(optname, "windowtype")) - Sprintf(buf, "%s", windowprocs.name); - else if (!strcmp(optname, "windowcolors")) - Sprintf(buf, "%s/%s %s/%s %s/%s %s/%s", - iflags.wc_foregrnd_menu ? iflags.wc_foregrnd_menu : defbrief, - iflags.wc_backgrnd_menu ? iflags.wc_backgrnd_menu : defbrief, - iflags.wc_foregrnd_message ? iflags.wc_foregrnd_message : defbrief, - iflags.wc_backgrnd_message ? iflags.wc_backgrnd_message : defbrief, - iflags.wc_foregrnd_status ? iflags.wc_foregrnd_status : defbrief, - iflags.wc_backgrnd_status ? iflags.wc_backgrnd_status : defbrief, - iflags.wc_foregrnd_text ? iflags.wc_foregrnd_text : defbrief, - iflags.wc_backgrnd_text ? iflags.wc_backgrnd_text : defbrief); + else if (!strcmp(optname, "windowtype")) + Sprintf(buf, "%s", windowprocs.name); + else if (!strcmp(optname, "windowcolors")) + Sprintf( + buf, "%s/%s %s/%s %s/%s %s/%s", + iflags.wc_foregrnd_menu ? iflags.wc_foregrnd_menu : defbrief, + iflags.wc_backgrnd_menu ? iflags.wc_backgrnd_menu : defbrief, + iflags.wc_foregrnd_message ? iflags.wc_foregrnd_message + : defbrief, + iflags.wc_backgrnd_message ? iflags.wc_backgrnd_message + : defbrief, + iflags.wc_foregrnd_status ? iflags.wc_foregrnd_status : defbrief, + iflags.wc_backgrnd_status ? iflags.wc_backgrnd_status : defbrief, + iflags.wc_foregrnd_text ? iflags.wc_foregrnd_text : defbrief, + iflags.wc_backgrnd_text ? iflags.wc_backgrnd_text : defbrief); #ifdef PREFIXES_IN_USE - else { - for (i = 0; i < PREFIX_COUNT; ++i) - if (!strcmp(optname, fqn_prefix_names[i]) && fqn_prefix[i]) - Sprintf(buf, "%s", fqn_prefix[i]); - } + else { + for (i = 0; i < PREFIX_COUNT; ++i) + if (!strcmp(optname, fqn_prefix_names[i]) && fqn_prefix[i]) + Sprintf(buf, "%s", fqn_prefix[i]); + } #endif - if (buf[0]) return buf; - else return "unknown"; + if (buf[0]) + return buf; + else + return "unknown"; } int dotogglepickup() { - char buf[BUFSZ], ocl[MAXOCLASSES+1]; + char buf[BUFSZ], ocl[MAXOCLASSES + 1]; - flags.pickup = !flags.pickup; - if (flags.pickup) { - oc_to_str(flags.pickup_types, ocl); - Sprintf(buf, "ON, for %s objects%s", ocl[0] ? ocl : "all", - (iflags.autopickup_exceptions[AP_LEAVE] || - iflags.autopickup_exceptions[AP_GRAB]) ? - ((count_ape_maps((int *)0, (int *)0) == 1) ? - ", with one exception" : ", with some exceptions") : - ""); - } else { - Strcpy(buf, "OFF"); - } - pline("Autopickup: %s.", buf); - return 0; + flags.pickup = !flags.pickup; + if (flags.pickup) { + oc_to_str(flags.pickup_types, ocl); + Sprintf(buf, "ON, for %s objects%s", ocl[0] ? ocl : "all", + (iflags.autopickup_exceptions[AP_LEAVE] + || iflags.autopickup_exceptions[AP_GRAB]) + ? ((count_ape_maps((int *) 0, (int *) 0) == 1) + ? ", with one exception" + : ", with some exceptions") + : ""); + } else { + Strcpy(buf, "OFF"); + } + pline("Autopickup: %s.", buf); + return 0; } int add_autopickup_exception(mapping) const char *mapping; { - struct autopickup_exception *ape, **apehead; - char text[256], *text2; - int textsize = 0; - boolean grab = FALSE; + struct autopickup_exception *ape, **apehead; + char text[256], *text2; + int textsize = 0; + boolean grab = FALSE; - if (sscanf(mapping, "\"%255[^\"]\"", text) == 1) { - text2 = &text[0]; - if (*text2 == '<') { /* force autopickup */ - grab = TRUE; - ++text2; - } else if (*text2 == '>') { /* default - Do not pickup */ - grab = FALSE; - ++text2; - } - textsize = strlen(text2); - apehead = (grab) ? &iflags.autopickup_exceptions[AP_GRAB] : - &iflags.autopickup_exceptions[AP_LEAVE]; - ape = (struct autopickup_exception *) - alloc(sizeof(struct autopickup_exception)); - ape->pattern = (char *) alloc(textsize+1); - Strcpy(ape->pattern, text2); - ape->grab = grab; - ape->next = *apehead; - *apehead = ape; - } else { - raw_print("syntax error in AUTOPICKUP_EXCEPTION"); - return 0; - } - return 1; + if (sscanf(mapping, "\"%255[^\"]\"", text) == 1) { + text2 = &text[0]; + if (*text2 == '<') { /* force autopickup */ + grab = TRUE; + ++text2; + } else if (*text2 == '>') { /* default - Do not pickup */ + grab = FALSE; + ++text2; + } + textsize = strlen(text2); + apehead = (grab) ? &iflags.autopickup_exceptions[AP_GRAB] + : &iflags.autopickup_exceptions[AP_LEAVE]; + ape = (struct autopickup_exception *) alloc( + sizeof(struct autopickup_exception)); + ape->pattern = (char *) alloc(textsize + 1); + Strcpy(ape->pattern, text2); + ape->grab = grab; + ape->next = *apehead; + *apehead = ape; + } else { + raw_print("syntax error in AUTOPICKUP_EXCEPTION"); + return 0; + } + return 1; } STATIC_OVL void @@ -4318,17 +4567,19 @@ struct autopickup_exception *whichape; int chain = whichape->grab ? AP_GRAB : AP_LEAVE; for (ape = iflags.autopickup_exceptions[chain]; ape;) { - if (ape == whichape) { - struct autopickup_exception *freeape = ape; - ape = ape->next; - if (prev) prev->next = ape; - else iflags.autopickup_exceptions[chain] = ape; - free(freeape->pattern); - free(freeape); - } else { - prev = ape; - ape = ape->next; - } + if (ape == whichape) { + struct autopickup_exception *freeape = ape; + ape = ape->next; + if (prev) + prev->next = ape; + else + iflags.autopickup_exceptions[chain] = ape; + free(freeape->pattern); + free(freeape); + } else { + prev = ape; + ape = ape->next; + } } } @@ -4336,35 +4587,37 @@ STATIC_OVL int count_ape_maps(leave, grab) int *leave, *grab; { - struct autopickup_exception *ape; - int pass, totalapes, numapes[2] = {0,0}; + struct autopickup_exception *ape; + int pass, totalapes, numapes[2] = { 0, 0 }; - for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { - ape = iflags.autopickup_exceptions[pass]; - while(ape) { - ape = ape->next; - numapes[pass]++; - } - } - totalapes = numapes[AP_LEAVE] + numapes[AP_GRAB]; - if (leave) *leave = numapes[AP_LEAVE]; - if (grab) *grab = numapes[AP_GRAB]; - return totalapes; + for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { + ape = iflags.autopickup_exceptions[pass]; + while (ape) { + ape = ape->next; + numapes[pass]++; + } + } + totalapes = numapes[AP_LEAVE] + numapes[AP_GRAB]; + if (leave) + *leave = numapes[AP_LEAVE]; + if (grab) + *grab = numapes[AP_GRAB]; + return totalapes; } void free_autopickup_exceptions() { - struct autopickup_exception *ape; - int pass; + struct autopickup_exception *ape; + int pass; - for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { - while((ape = iflags.autopickup_exceptions[pass]) != 0) { - free(ape->pattern); - iflags.autopickup_exceptions[pass] = ape->next; - free(ape); - } - } + for (pass = AP_LEAVE; pass <= AP_GRAB; ++pass) { + while ((ape = iflags.autopickup_exceptions[pass]) != 0) { + free(ape->pattern); + iflags.autopickup_exceptions[pass] = ape->next; + free(ape); + } + } } /* bundle some common usage into one easy-to-use routine */ @@ -4373,17 +4626,17 @@ load_symset(s, which_set) const char *s; int which_set; { - clear_symsetentry(which_set, TRUE); + clear_symsetentry(which_set, TRUE); - symset[which_set].name = (char *)alloc(strlen(s)+1); - Strcpy(symset[which_set].name,s); - if (read_sym_file(which_set)) - switch_symbols(TRUE); - else { - clear_symsetentry(which_set, TRUE); - return 0; - } - return 1; + symset[which_set].name = (char *) alloc(strlen(s) + 1); + Strcpy(symset[which_set].name, s); + if (read_sym_file(which_set)) + switch_symbols(TRUE); + else { + clear_symsetentry(which_set, TRUE); + return 0; + } + return 1; } /* Parse the value of a SYMBOLS line from a config file */ @@ -4391,93 +4644,95 @@ void parsesymbols(opts) register char *opts; { - int val; - char *op, *symname, *strval; - struct symparse *symp; + int val; + char *op, *symname, *strval; + struct symparse *symp; - if ((op = index(opts, ',')) != 0) { - *op++ = 0; - parsesymbols(op); - } + if ((op = index(opts, ',')) != 0) { + *op++ = 0; + parsesymbols(op); + } - /* S_sample:string */ - symname = opts; - strval = index(opts, ':'); - if (!strval) strval = index(opts, '='); - if (!strval) return; - *strval++ = '\0'; + /* S_sample:string */ + symname = opts; + strval = index(opts, ':'); + if (!strval) + strval = index(opts, '='); + if (!strval) + return; + *strval++ = '\0'; - /* strip leading and trailing white space from symname and strval */ - mungspaces(symname); - mungspaces(strval); + /* strip leading and trailing white space from symname and strval */ + mungspaces(symname); + mungspaces(strval); - symp = match_sym(symname); - if (!symp) return; + symp = match_sym(symname); + if (!symp) + return; - if (symp->range && symp->range != SYM_CONTROL) { - val = sym_val(strval); - update_l_symset(symp, val); - } + if (symp->range && symp->range != SYM_CONTROL) { + val = sym_val(strval); + update_l_symset(symp, val); + } } struct symparse * match_sym(buf) char *buf; { - size_t len = strlen(buf); - const char *p = index(buf, ':'), - *q = index(buf, '='); - struct symparse *sp = loadsyms; + size_t len = strlen(buf); + const char *p = index(buf, ':'), *q = index(buf, '='); + struct symparse *sp = loadsyms; - if (!p || (q && q < p)) p = q; - if (p) { - /* note: there will be at most one space before the '=' - because caller has condensed buf[] with mungspaces() */ - if (p > buf && p[-1] == ' ') p--; - len = (int)(p - buf); - } - while(sp->range) { - if ((len >= strlen(sp->name)) && !strncmpi(buf, sp->name, len)) - return sp; - sp++; - } - return (struct symparse *)0; + if (!p || (q && q < p)) + p = q; + if (p) { + /* note: there will be at most one space before the '=' + because caller has condensed buf[] with mungspaces() */ + if (p > buf && p[-1] == ' ') + p--; + len = (int) (p - buf); + } + while (sp->range) { + if ((len >= strlen(sp->name)) && !strncmpi(buf, sp->name, len)) + return sp; + sp++; + } + return (struct symparse *) 0; } -int sym_val(strval) +int +sym_val(strval) char *strval; { - char buf[QBUFSZ]; - buf[0] = '\0'; - escapes(strval, buf); - return (int)*buf; + char buf[QBUFSZ]; + buf[0] = '\0'; + escapes(strval, buf); + return (int) *buf; } /* data for option_help() */ static const char *opt_intro[] = { - "", - " NetHack Options Help:", - "", -#define CONFIG_SLOT 3 /* fill in next value at run-time */ - (char *)0, + "", " NetHack Options Help:", "", +#define CONFIG_SLOT 3 /* fill in next value at run-time */ + (char *) 0, #if !defined(MICRO) && !defined(MAC) - "or use `NETHACKOPTIONS=\"\"' in your environment", + "or use `NETHACKOPTIONS=\"\"' in your environment", #endif - "( is a list of options separated by commas)", + "( is a list of options separated by commas)", #ifdef VMS - "-- for example, $ DEFINE NETHACKOPTIONS \"noautopickup,fruit:kumquat\"", + "-- for example, $ DEFINE NETHACKOPTIONS \"noautopickup,fruit:kumquat\"", #endif - "or press \"O\" while playing and use the menu.", - "", - "Boolean options (which can be negated by prefixing them with '!' or \"no\"):", - (char *)0 + "or press \"O\" while playing and use the menu.", "", + "Boolean options (which can be negated by prefixing them with '!' or " + "\"no\"):", + (char *) 0 }; static const char *opt_epilog[] = { - "", - "Some of the options can be set only before the game is started; those", - "items will not be selectable in the 'O' command's menu.", - (char *)0 + "", + "Some of the options can be set only before the game is started; those", + "items will not be selectable in the 'O' command's menu.", (char *) 0 }; void @@ -4491,29 +4746,31 @@ option_help() Sprintf(buf, "Set options as OPTIONS= in %s", lastconfigfile); opt_intro[CONFIG_SLOT] = (const char *) buf; for (i = 0; opt_intro[i]; i++) - putstr(datawin, 0, opt_intro[i]); + putstr(datawin, 0, opt_intro[i]); /* Boolean options */ for (i = 0; boolopt[i].name; i++) { - if (boolopt[i].addr) { - if (boolopt[i].addr == &iflags.sanity_check && !wizard) continue; - if (boolopt[i].addr == &iflags.menu_tab_sep && !wizard) continue; - next_opt(datawin, boolopt[i].name); - } + if (boolopt[i].addr) { + if (boolopt[i].addr == &iflags.sanity_check && !wizard) + continue; + if (boolopt[i].addr == &iflags.menu_tab_sep && !wizard) + continue; + next_opt(datawin, boolopt[i].name); + } } next_opt(datawin, ""); /* Compound options */ putstr(datawin, 0, "Compound options:"); for (i = 0; compopt[i].name; i++) { - Sprintf(buf2, "`%s'", compopt[i].name); - Sprintf(buf, "%-20s - %s%c", buf2, compopt[i].descr, - compopt[i+1].name ? ',' : '.'); - putstr(datawin, 0, buf); + Sprintf(buf2, "`%s'", compopt[i].name); + Sprintf(buf, "%-20s - %s%c", buf2, compopt[i].descr, + compopt[i + 1].name ? ',' : '.'); + putstr(datawin, 0, buf); } for (i = 0; opt_epilog[i]; i++) - putstr(datawin, 0, opt_epilog[i]); + putstr(datawin, 0, opt_epilog[i]); display_nhwindow(datawin, FALSE); destroy_nhwindow(datawin); @@ -4529,33 +4786,34 @@ next_opt(datawin, str) winid datawin; const char *str; { - static char *buf = 0; - int i; - char *s; + static char *buf = 0; + int i; + char *s; - if (!buf) *(buf = (char *)alloc(BUFSZ)) = '\0'; + if (!buf) + *(buf = (char *) alloc(BUFSZ)) = '\0'; - if (!*str) { - s = eos(buf); - if (s > &buf[1] && s[-2] == ',') - Strcpy(s - 2, "."); /* replace last ", " */ - i = COLNO; /* (greater than COLNO - 2) */ - } else { - i = strlen(buf) + strlen(str) + 2; - } + if (!*str) { + s = eos(buf); + if (s > &buf[1] && s[-2] == ',') + Strcpy(s - 2, "."); /* replace last ", " */ + i = COLNO; /* (greater than COLNO - 2) */ + } else { + i = strlen(buf) + strlen(str) + 2; + } - if (i > COLNO - 2) { /* rule of thumb */ - putstr(datawin, 0, buf); - buf[0] = 0; - } - if (*str) { - Strcat(buf, str); - Strcat(buf, ", "); - } else { - putstr(datawin, 0, str); - free(buf), buf = 0; - } - return; + if (i > COLNO - 2) { /* rule of thumb */ + putstr(datawin, 0, buf); + buf[0] = 0; + } + if (*str) { + Strcat(buf, str); + Strcat(buf, ", "); + } else { + putstr(datawin, 0, str); + free(buf), buf = 0; + } + return; } /* Returns the fid of the fruit type; if that type already exists, it @@ -4569,108 +4827,109 @@ fruitadd(str, replace_fruit) char *str; struct fruit *replace_fruit; { - register int i; - register struct fruit *f; - int highest_fruit_id = 0; - char buf[PL_FSIZ], altname[PL_FSIZ]; - boolean user_specified = (str == pl_fruit); - /* if not user-specified, then it's a fruit name for a fruit on - * a bones level... - */ + register int i; + register struct fruit *f; + int highest_fruit_id = 0; + char buf[PL_FSIZ], altname[PL_FSIZ]; + boolean user_specified = (str == pl_fruit); + /* if not user-specified, then it's a fruit name for a fruit on + * a bones level... + */ - /* Note: every fruit has an id (kept in obj->spe) of at least 1; - * 0 is an error. - */ - if (user_specified) { - boolean found = FALSE, numeric = FALSE; + /* Note: every fruit has an id (kept in obj->spe) of at least 1; + * 0 is an error. + */ + if (user_specified) { + boolean found = FALSE, numeric = FALSE; - /* force fruit to be singular; this handling is not - needed--or wanted--for fruits from bones because - they already received it in their original game */ - nmcpy(pl_fruit, makesingular(str), PL_FSIZ); - /* assert( str == pl_fruit ); */ + /* force fruit to be singular; this handling is not + needed--or wanted--for fruits from bones because + they already received it in their original game */ + nmcpy(pl_fruit, makesingular(str), PL_FSIZ); + /* assert( str == pl_fruit ); */ - /* disallow naming after other foods (since it'd be impossible - * to tell the difference) - */ + /* disallow naming after other foods (since it'd be impossible + * to tell the difference) + */ - for (i = bases[FOOD_CLASS]; objects[i].oc_class == FOOD_CLASS; - i++) { - if (!strcmp(OBJ_NAME(objects[i]), pl_fruit)) { - found = TRUE; - break; - } - } - { - char *c; + for (i = bases[FOOD_CLASS]; objects[i].oc_class == FOOD_CLASS; i++) { + if (!strcmp(OBJ_NAME(objects[i]), pl_fruit)) { + found = TRUE; + break; + } + } + { + char *c; - c = pl_fruit; + c = pl_fruit; - for(c = pl_fruit; *c >= '0' && *c <= '9'; c++) - ; - if (isspace((uchar)*c) || *c == 0) numeric = TRUE; - } - if (found || numeric || - !strncmp(str, "cursed ", 7) || - !strncmp(str, "uncursed ", 9) || - !strncmp(str, "blessed ", 8) || - !strncmp(str, "partly eaten ", 13) || - (!strncmp(str, "tin of ", 7) && - (!strcmp(str+7, "spinach") || - name_to_mon(str+7) >= LOW_PM)) || - !strcmp(str, "empty tin") || - ((!strncmp(eos(str)-7," corpse",7) || - !strncmp(eos(str)-4, " egg",4)) && - name_to_mon(str) >= LOW_PM)) - { - Strcpy(buf, pl_fruit); - Strcpy(pl_fruit, "candied "); - nmcpy(pl_fruit+8, buf, PL_FSIZ-8); - } - *altname = '\0'; - /* This flag indicates that a fruit has been made since the - * last time the user set the fruit. If it hasn't, we can - * safely overwrite the current fruit, preventing the user from - * setting many fruits in a row and overflowing. - * Possible expansion: check for specific fruit IDs, not for - * any fruit. - */ - flags.made_fruit = FALSE; - if (replace_fruit) { - for(f=ffruit; f; f = f->nextf) { - if (f == replace_fruit) { - copynchars(f->fname, str, PL_FSIZ-1); - goto nonew; - } - } - } - } else { - /* not user_supplied, so assumed to be from bones */ - copynchars(altname, str, PL_FSIZ-1); - sanitize_name(altname); - flags.made_fruit = TRUE; /* for safety. Any fruit name added from a bones level should exist anyway. */ - } - for(f=ffruit; f; f = f->nextf) { - if(f->fid > highest_fruit_id) highest_fruit_id = f->fid; - if (!strncmp(str, f->fname, PL_FSIZ-1) || - (*altname && !strcmp(altname, f->fname))) - goto nonew; - } - /* if adding another fruit would overflow spe, use a random - fruit instead... we've got a lot to choose from. - current_fruit remains as is. */ - if (highest_fruit_id >= 127) return rnd(127); + for (c = pl_fruit; *c >= '0' && *c <= '9'; c++) + ; + if (isspace((uchar) *c) || *c == 0) + numeric = TRUE; + } + if (found || numeric || !strncmp(str, "cursed ", 7) + || !strncmp(str, "uncursed ", 9) || !strncmp(str, "blessed ", 8) + || !strncmp(str, "partly eaten ", 13) + || (!strncmp(str, "tin of ", 7) + && (!strcmp(str + 7, "spinach") + || name_to_mon(str + 7) >= LOW_PM)) + || !strcmp(str, "empty tin") + || ((!strncmp(eos(str) - 7, " corpse", 7) + || !strncmp(eos(str) - 4, " egg", 4)) + && name_to_mon(str) >= LOW_PM)) { + Strcpy(buf, pl_fruit); + Strcpy(pl_fruit, "candied "); + nmcpy(pl_fruit + 8, buf, PL_FSIZ - 8); + } + *altname = '\0'; + /* This flag indicates that a fruit has been made since the + * last time the user set the fruit. If it hasn't, we can + * safely overwrite the current fruit, preventing the user from + * setting many fruits in a row and overflowing. + * Possible expansion: check for specific fruit IDs, not for + * any fruit. + */ + flags.made_fruit = FALSE; + if (replace_fruit) { + for (f = ffruit; f; f = f->nextf) { + if (f == replace_fruit) { + copynchars(f->fname, str, PL_FSIZ - 1); + goto nonew; + } + } + } + } else { + /* not user_supplied, so assumed to be from bones */ + copynchars(altname, str, PL_FSIZ - 1); + sanitize_name(altname); + flags.made_fruit = TRUE; /* for safety. Any fruit name added from a + bones level should exist anyway. */ + } + for (f = ffruit; f; f = f->nextf) { + if (f->fid > highest_fruit_id) + highest_fruit_id = f->fid; + if (!strncmp(str, f->fname, PL_FSIZ - 1) + || (*altname && !strcmp(altname, f->fname))) + goto nonew; + } + /* if adding another fruit would overflow spe, use a random + fruit instead... we've got a lot to choose from. + current_fruit remains as is. */ + if (highest_fruit_id >= 127) + return rnd(127); - f = newfruit(); - copynchars(f->fname, *altname ? altname : str, PL_FSIZ-1); - f->fid = ++highest_fruit_id; - /* we used to go out of our way to add it at the end of the list, - but the order is arbitrary so use simpler insertion at start */ - f->nextf = ffruit; - ffruit = f; - nonew: - if (user_specified) context.current_fruit = f->fid; - return f->fid; + f = newfruit(); + copynchars(f->fname, *altname ? altname : str, PL_FSIZ - 1); + f->fid = ++highest_fruit_id; + /* we used to go out of our way to add it at the end of the list, + but the order is arbitrary so use simpler insertion at start */ + f->nextf = ffruit; + ffruit = f; +nonew: + if (user_specified) + context.current_fruit = f->fid; + return f->fid; } /* @@ -4704,7 +4963,7 @@ boolean way; char *class_list; char *class_select; { - menu_item *pick_list = (menu_item *)0; + menu_item *pick_list = (menu_item *) 0; winid win; anything any; char buf[BUFSZ]; @@ -4712,114 +4971,111 @@ char *class_select; int ret; int next_accelerator, accelerator; - if (class_list == (char *)0 || class_select == (char *)0) return 0; + if (class_list == (char *) 0 || class_select == (char *) 0) + return 0; accelerator = 0; next_accelerator = 'a'; any = zeroany; win = create_nhwindow(NHW_MENU); start_menu(win); while (*class_list) { - const char *text; - boolean selected; + const char *text; + boolean selected; - text = (char *)0; - selected = FALSE; - switch (category) { - case 0: - text = def_monsyms[def_char_to_monclass(*class_list)].explain; - accelerator = *class_list; - Sprintf(buf, "%s", text); - break; - case 1: - text = def_oc_syms[def_char_to_objclass(*class_list)].explain; - accelerator = next_accelerator; - Sprintf(buf, "%c %s", *class_list, text); - break; - default: - impossible("choose_classes_menu: invalid category %d", - category); - } - if (way && *class_select) { /* Selections there already */ - if (index(class_select, *class_list)) { - selected = TRUE; - } - } - any.a_int = *class_list; - add_menu(win, NO_GLYPH, &any, accelerator, - category ? *class_list : 0, - ATR_NONE, buf, selected); - ++class_list; - if (category > 0) { - ++next_accelerator; - if (next_accelerator == ('z' + 1)) next_accelerator = 'A'; - if (next_accelerator == ('Z' + 1)) break; - } + text = (char *) 0; + selected = FALSE; + switch (category) { + case 0: + text = def_monsyms[def_char_to_monclass(*class_list)].explain; + accelerator = *class_list; + Sprintf(buf, "%s", text); + break; + case 1: + text = def_oc_syms[def_char_to_objclass(*class_list)].explain; + accelerator = next_accelerator; + Sprintf(buf, "%c %s", *class_list, text); + break; + default: + impossible("choose_classes_menu: invalid category %d", category); + } + if (way && *class_select) { /* Selections there already */ + if (index(class_select, *class_list)) { + selected = TRUE; + } + } + any.a_int = *class_list; + add_menu(win, NO_GLYPH, &any, accelerator, category ? *class_list : 0, + ATR_NONE, buf, selected); + ++class_list; + if (category > 0) { + ++next_accelerator; + if (next_accelerator == ('z' + 1)) + next_accelerator = 'A'; + if (next_accelerator == ('Z' + 1)) + break; + } } end_menu(win, prompt); n = select_menu(win, way ? PICK_ANY : PICK_ONE, &pick_list); destroy_nhwindow(win); if (n > 0) { - for (i = 0; i < n; ++i) - *class_select++ = (char)pick_list[i].item.a_int; - free((genericptr_t)pick_list); - ret = n; + for (i = 0; i < n; ++i) + *class_select++ = (char) pick_list[i].item.a_int; + free((genericptr_t) pick_list); + ret = n; } else if (n == -1) { - class_select = eos(class_select); - ret = -1; + class_select = eos(class_select); + ret = -1; } else - ret = 0; + ret = 0; *class_select = '\0'; return ret; } -struct wc_Opt wc_options[] = { - {"ascii_map", WC_ASCII_MAP}, - {"color", WC_COLOR}, - {"eight_bit_tty", WC_EIGHT_BIT_IN}, - {"hilite_pet", WC_HILITE_PET}, - {"popup_dialog", WC_POPUP_DIALOG}, - {"player_selection", WC_PLAYER_SELECTION}, - {"preload_tiles", WC_PRELOAD_TILES}, - {"tiled_map", WC_TILED_MAP}, - {"tile_file", WC_TILE_FILE}, - {"tile_width", WC_TILE_WIDTH}, - {"tile_height", WC_TILE_HEIGHT}, - {"use_inverse", WC_INVERSE}, - {"align_message", WC_ALIGN_MESSAGE}, - {"align_status", WC_ALIGN_STATUS}, - {"font_map", WC_FONT_MAP}, - {"font_menu", WC_FONT_MENU}, - {"font_message",WC_FONT_MESSAGE}, +struct wc_Opt wc_options[] = { { "ascii_map", WC_ASCII_MAP }, + { "color", WC_COLOR }, + { "eight_bit_tty", WC_EIGHT_BIT_IN }, + { "hilite_pet", WC_HILITE_PET }, + { "popup_dialog", WC_POPUP_DIALOG }, + { "player_selection", WC_PLAYER_SELECTION }, + { "preload_tiles", WC_PRELOAD_TILES }, + { "tiled_map", WC_TILED_MAP }, + { "tile_file", WC_TILE_FILE }, + { "tile_width", WC_TILE_WIDTH }, + { "tile_height", WC_TILE_HEIGHT }, + { "use_inverse", WC_INVERSE }, + { "align_message", WC_ALIGN_MESSAGE }, + { "align_status", WC_ALIGN_STATUS }, + { "font_map", WC_FONT_MAP }, + { "font_menu", WC_FONT_MENU }, + { "font_message", WC_FONT_MESSAGE }, #if 0 {"perm_invent",WC_PERM_INVENT}, #endif - {"font_size_map", WC_FONTSIZ_MAP}, - {"font_size_menu", WC_FONTSIZ_MENU}, - {"font_size_message", WC_FONTSIZ_MESSAGE}, - {"font_size_status", WC_FONTSIZ_STATUS}, - {"font_size_text", WC_FONTSIZ_TEXT}, - {"font_status", WC_FONT_STATUS}, - {"font_text", WC_FONT_TEXT}, - {"map_mode", WC_MAP_MODE}, - {"scroll_amount", WC_SCROLL_AMOUNT}, - {"scroll_margin", WC_SCROLL_MARGIN}, - {"splash_screen", WC_SPLASH_SCREEN}, - {"vary_msgcount",WC_VARY_MSGCOUNT}, - {"windowcolors", WC_WINDOWCOLORS}, - {"mouse_support", WC_MOUSE_SUPPORT}, - {(char *)0, 0L} -}; + { "font_size_map", WC_FONTSIZ_MAP }, + { "font_size_menu", WC_FONTSIZ_MENU }, + { "font_size_message", WC_FONTSIZ_MESSAGE }, + { "font_size_status", WC_FONTSIZ_STATUS }, + { "font_size_text", WC_FONTSIZ_TEXT }, + { "font_status", WC_FONT_STATUS }, + { "font_text", WC_FONT_TEXT }, + { "map_mode", WC_MAP_MODE }, + { "scroll_amount", WC_SCROLL_AMOUNT }, + { "scroll_margin", WC_SCROLL_MARGIN }, + { "splash_screen", WC_SPLASH_SCREEN }, + { "vary_msgcount", WC_VARY_MSGCOUNT }, + { "windowcolors", WC_WINDOWCOLORS }, + { "mouse_support", WC_MOUSE_SUPPORT }, + { (char *) 0, 0L } }; -struct wc_Opt wc2_options[] = { - {"fullscreen", WC2_FULLSCREEN}, - {"softkeyboard", WC2_SOFTKEYBOARD}, - {"wraptext", WC2_WRAPTEXT}, - {"use_darkgray", WC2_DARKGRAY}, +struct wc_Opt wc2_options[] = { { "fullscreen", WC2_FULLSCREEN }, + { "softkeyboard", WC2_SOFTKEYBOARD }, + { "wraptext", WC2_WRAPTEXT }, + { "use_darkgray", WC2_DARKGRAY }, #ifdef STATUS_VIA_WINDOWPORT - {"hilite_status", WC2_HILITE_STATUS}, + { "hilite_status", WC2_HILITE_STATUS }, #endif - {(char *)0, 0L} -}; + { (char *) 0, 0L } }; /* * If a port wants to change or ensure that the SET_IN_SYS, @@ -4833,24 +5089,23 @@ set_option_mod_status(optnam, status) const char *optnam; int status; { - int k; - if ( SET__IS_VALUE_VALID(status) ) { - impossible("set_option_mod_status: status out of range %d.", - status); - return; - } - for (k = 0; boolopt[k].name; k++) { - if (!strncmpi(boolopt[k].name, optnam, strlen(optnam))) { - boolopt[k].optflags = status; - return; - } - } - for (k = 0; compopt[k].name; k++) { - if (!strncmpi(compopt[k].name, optnam, strlen(optnam))) { - compopt[k].optflags = status; - return; - } - } + int k; + if (SET__IS_VALUE_VALID(status)) { + impossible("set_option_mod_status: status out of range %d.", status); + return; + } + for (k = 0; boolopt[k].name; k++) { + if (!strncmpi(boolopt[k].name, optnam, strlen(optnam))) { + boolopt[k].optflags = status; + return; + } + } + for (k = 0; compopt[k].name; k++) { + if (!strncmpi(compopt[k].name, optnam, strlen(optnam))) { + compopt[k].optflags = status; + return; + } + } } /* @@ -4859,62 +5114,64 @@ int status; * the appropriate bits for each option that you * are setting in the optmask argument * prior to calling. - * example: set_wc_option_mod_status(WC_COLOR|WC_SCROLL_MARGIN, SET_IN_GAME); + * example: set_wc_option_mod_status(WC_COLOR|WC_SCROLL_MARGIN, + * SET_IN_GAME); */ void set_wc_option_mod_status(optmask, status) unsigned long optmask; int status; { - int k = 0; - if ( SET__IS_VALUE_VALID(status) ) { - impossible("set_wc_option_mod_status: status out of range %d.", - status); - return; - } - while (wc_options[k].wc_name) { - if (optmask & wc_options[k].wc_bit) { - set_option_mod_status(wc_options[k].wc_name, status); - } - k++; - } + int k = 0; + if (SET__IS_VALUE_VALID(status)) { + impossible("set_wc_option_mod_status: status out of range %d.", + status); + return; + } + while (wc_options[k].wc_name) { + if (optmask & wc_options[k].wc_bit) { + set_option_mod_status(wc_options[k].wc_name, status); + } + k++; + } } STATIC_OVL boolean is_wc_option(optnam) const char *optnam; { - int k = 0; - while (wc_options[k].wc_name) { - if (strcmp(wc_options[k].wc_name, optnam) == 0) - return TRUE; - k++; - } - return FALSE; + int k = 0; + while (wc_options[k].wc_name) { + if (strcmp(wc_options[k].wc_name, optnam) == 0) + return TRUE; + k++; + } + return FALSE; } STATIC_OVL boolean wc_supported(optnam) const char *optnam; { - int k = 0; - while (wc_options[k].wc_name) { - if (!strcmp(wc_options[k].wc_name, optnam) && - (windowprocs.wincap & wc_options[k].wc_bit)) - return TRUE; - k++; - } - return FALSE; + int k = 0; + while (wc_options[k].wc_name) { + if (!strcmp(wc_options[k].wc_name, optnam) + && (windowprocs.wincap & wc_options[k].wc_bit)) + return TRUE; + k++; + } + return FALSE; } - /* * You can set several wc2_options in one call to * set_wc2_option_mod_status() by setting * the appropriate bits for each option that you * are setting in the optmask argument * prior to calling. - * example: set_wc2_option_mod_status(WC2_FULLSCREEN|WC2_SOFTKEYBOARD|WC2_WRAPTEXT, SET_IN_FILE); + * example: + * set_wc2_option_mod_status(WC2_FULLSCREEN|WC2_SOFTKEYBOARD|WC2_WRAPTEXT, + * SET_IN_FILE); */ void @@ -4922,163 +5179,180 @@ set_wc2_option_mod_status(optmask, status) unsigned long optmask; int status; { - int k = 0; - if ( SET__IS_VALUE_VALID(status) ) { - impossible("set_wc2_option_mod_status: status out of range %d.", - status); - return; - } - while (wc2_options[k].wc_name) { - if (optmask & wc2_options[k].wc_bit) { - set_option_mod_status(wc2_options[k].wc_name, status); - } - k++; - } + int k = 0; + if (SET__IS_VALUE_VALID(status)) { + impossible("set_wc2_option_mod_status: status out of range %d.", + status); + return; + } + while (wc2_options[k].wc_name) { + if (optmask & wc2_options[k].wc_bit) { + set_option_mod_status(wc2_options[k].wc_name, status); + } + k++; + } } STATIC_OVL boolean is_wc2_option(optnam) const char *optnam; { - int k = 0; - while (wc2_options[k].wc_name) { - if (strcmp(wc2_options[k].wc_name, optnam) == 0) - return TRUE; - k++; - } - return FALSE; + int k = 0; + while (wc2_options[k].wc_name) { + if (strcmp(wc2_options[k].wc_name, optnam) == 0) + return TRUE; + k++; + } + return FALSE; } STATIC_OVL boolean wc2_supported(optnam) const char *optnam; { - int k = 0; - while (wc2_options[k].wc_name) { - if (!strcmp(wc2_options[k].wc_name, optnam) && - (windowprocs.wincap2 & wc2_options[k].wc_bit)) - return TRUE; - k++; - } - return FALSE; + int k = 0; + while (wc2_options[k].wc_name) { + if (!strcmp(wc2_options[k].wc_name, optnam) + && (windowprocs.wincap2 & wc2_options[k].wc_bit)) + return TRUE; + k++; + } + return FALSE; } - STATIC_OVL void wc_set_font_name(opttype, fontname) int opttype; char *fontname; { - char **fn = (char **)0; - if (!fontname) return; - switch(opttype) { - case MAP_OPTION: - fn = &iflags.wc_font_map; - break; - case MESSAGE_OPTION: - fn = &iflags.wc_font_message; - break; - case TEXT_OPTION: - fn = &iflags.wc_font_text; - break; - case MENU_OPTION: - fn = &iflags.wc_font_menu; - break; - case STATUS_OPTION: - fn = &iflags.wc_font_status; - break; - default: - return; - } - if (fn) { - if (*fn) free(*fn); - *fn = (char *)alloc(strlen(fontname) + 1); - Strcpy(*fn, fontname); - } - return; + char **fn = (char **) 0; + if (!fontname) + return; + switch (opttype) { + case MAP_OPTION: + fn = &iflags.wc_font_map; + break; + case MESSAGE_OPTION: + fn = &iflags.wc_font_message; + break; + case TEXT_OPTION: + fn = &iflags.wc_font_text; + break; + case MENU_OPTION: + fn = &iflags.wc_font_menu; + break; + case STATUS_OPTION: + fn = &iflags.wc_font_status; + break; + default: + return; + } + if (fn) { + if (*fn) + free(*fn); + *fn = (char *) alloc(strlen(fontname) + 1); + Strcpy(*fn, fontname); + } + return; } STATIC_OVL int wc_set_window_colors(op) char *op; { - /* syntax: - * menu white/black message green/yellow status white/blue text white/black - */ + /* syntax: + * menu white/black message green/yellow status white/blue text + * white/black + */ - int j; - char buf[BUFSZ]; - char *wn, *tfg, *tbg, *newop; - static const char *wnames[] = { "menu", "message", "status", "text" }; - static const char *shortnames[] = { "mnu", "msg", "sts", "txt" }; - static char **fgp[] = { - &iflags.wc_foregrnd_menu, - &iflags.wc_foregrnd_message, - &iflags.wc_foregrnd_status, - &iflags.wc_foregrnd_text - }; - static char **bgp[] = { - &iflags.wc_backgrnd_menu, - &iflags.wc_backgrnd_message, - &iflags.wc_backgrnd_status, - &iflags.wc_backgrnd_text - }; + int j; + char buf[BUFSZ]; + char *wn, *tfg, *tbg, *newop; + static const char *wnames[] = { "menu", "message", "status", "text" }; + static const char *shortnames[] = { "mnu", "msg", "sts", "txt" }; + static char **fgp[] = { &iflags.wc_foregrnd_menu, + &iflags.wc_foregrnd_message, + &iflags.wc_foregrnd_status, + &iflags.wc_foregrnd_text }; + static char **bgp[] = { &iflags.wc_backgrnd_menu, + &iflags.wc_backgrnd_message, + &iflags.wc_backgrnd_status, + &iflags.wc_backgrnd_text }; - Strcpy(buf, op); - newop = mungspaces(buf); - while (newop && *newop) { + Strcpy(buf, op); + newop = mungspaces(buf); + while (newop && *newop) { + wn = tfg = tbg = (char *) 0; - wn = tfg = tbg = (char *)0; + /* until first non-space in case there's leading spaces - before + * colorname*/ + if (*newop == ' ') + newop++; + if (*newop) + wn = newop; + else + return 0; - /* until first non-space in case there's leading spaces - before colorname*/ - if (*newop == ' ') newop++; - if (*newop) wn = newop; - else return 0; + /* until first space - colorname*/ + while (*newop && *newop != ' ') + newop++; + if (*newop) + *newop = '\0'; + else + return 0; + newop++; - /* until first space - colorname*/ - while (*newop && *newop != ' ') newop++; - if (*newop) *newop = '\0'; - else return 0; - newop++; + /* until first non-space - before foreground*/ + if (*newop == ' ') + newop++; + if (*newop) + tfg = newop; + else + return 0; - /* until first non-space - before foreground*/ - if (*newop == ' ') newop++; - if (*newop) tfg = newop; - else return 0; + /* until slash - foreground */ + while (*newop && *newop != '/') + newop++; + if (*newop) + *newop = '\0'; + else + return 0; + newop++; - /* until slash - foreground */ - while (*newop && *newop != '/') newop++; - if (*newop) *newop = '\0'; - else return 0; - newop++; + /* until first non-space (in case there's leading space after slash) - + * before background */ + if (*newop == ' ') + newop++; + if (*newop) + tbg = newop; + else + return 0; - /* until first non-space (in case there's leading space after slash) - before background */ - if (*newop == ' ') newop++; - if (*newop) tbg = newop; - else return 0; + /* until first space - background */ + while (*newop && *newop != ' ') + newop++; + if (*newop) + *newop++ = '\0'; - /* until first space - background */ - while (*newop && *newop != ' ') newop++; - if (*newop) *newop++ = '\0'; - - for (j = 0; j < 4; ++j) { - if (!strcmpi(wn, wnames[j]) || - !strcmpi(wn, shortnames[j])) { - if (tfg && !strstri(tfg, " ")) { - if (*fgp[j]) free(*fgp[j]); - *fgp[j] = (char *)alloc(strlen(tfg) + 1); - Strcpy(*fgp[j], tfg); - } - if (tbg && !strstri(tbg, " ")) { - if (*bgp[j]) free(*bgp[j]); - *bgp[j] = (char *)alloc(strlen(tbg) + 1); - Strcpy(*bgp[j], tbg); - } - break; - } - } - } - return 1; + for (j = 0; j < 4; ++j) { + if (!strcmpi(wn, wnames[j]) || !strcmpi(wn, shortnames[j])) { + if (tfg && !strstri(tfg, " ")) { + if (*fgp[j]) + free(*fgp[j]); + *fgp[j] = (char *) alloc(strlen(tfg) + 1); + Strcpy(*fgp[j], tfg); + } + if (tbg && !strstri(tbg, " ")) { + if (*bgp[j]) + free(*bgp[j]); + *bgp[j] = (char *) alloc(strlen(tbg) + 1); + Strcpy(*bgp[j], tbg); + } + break; + } + } + } + return 1; } /* set up for wizard mode if player or save file has requested to it; @@ -5089,17 +5363,17 @@ void set_playmode() { if (wizard) { - if (authorize_wizard_mode()) - Strcpy(plname, "wizard"); - else - wizard = FALSE; /* not allowed or not available */ - /* force explore mode if we didn't make it into wizard mode */ - discover = !wizard; - iflags.deferred_X = FALSE; + if (authorize_wizard_mode()) + Strcpy(plname, "wizard"); + else + wizard = FALSE; /* not allowed or not available */ + /* force explore mode if we didn't make it into wizard mode */ + discover = !wizard; + iflags.deferred_X = FALSE; } /* don't need to do anything special for explore mode or normal play */ } -#endif /* OPTION_LISTS_ONLY */ +#endif /* OPTION_LISTS_ONLY */ /*options.c*/ diff --git a/src/pager.c b/src/pager.c index f5c4b2ee1..3cdc063a9 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pager.c $NHDT-Date: 1429916796 2015/04/24 23:06:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.66 $ */ +/* NetHack 3.6 pager.c $NHDT-Date: 1431192756 2015/05/09 17:32:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.71 $ */ /* NetHack 3.6 pager.c $Date: 2012/01/15 09:27:06 $ $Revision: 1.41 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,9 +11,9 @@ STATIC_DCL boolean FDECL(is_swallow_sym, (int)); STATIC_DCL int FDECL(append_str, (char *, const char *)); -STATIC_DCL struct permonst * FDECL(lookat, (int, int, char *, char *)); +STATIC_DCL struct permonst *FDECL(lookat, (int, int, char *, char *)); STATIC_DCL void FDECL(checkfile, - (char *,struct permonst *,BOOLEAN_P,BOOLEAN_P)); + (char *, struct permonst *, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL boolean FDECL(help_menu, (int *)); #ifdef PORT_HELP extern void NDECL(port_help); @@ -26,7 +26,8 @@ int c; { int i; for (i = S_sw_tl; i <= S_sw_br; i++) - if ((int)showsyms[i] == c) return TRUE; + if ((int) showsyms[i] == c) + return TRUE; return FALSE; } @@ -37,12 +38,13 @@ int c; */ STATIC_OVL int append_str(buf, new_str) - char *buf; - const char *new_str; +char *buf; +const char *new_str; { - int space_left; /* space remaining in buf */ + int space_left; /* space remaining in buf */ - if (strstri(buf, new_str)) return 0; + if (strstri(buf, new_str)) + return 0; space_left = BUFSZ - strlen(buf) - 1; (void) strncat(buf, " or ", space_left); @@ -55,19 +57,19 @@ char * self_lookat(outbuf) char *outbuf; { - char race[QBUFSZ]; + char race[QBUFSZ]; - /* include race with role unless polymorphed */ - race[0] = '\0'; - if (!Upolyd) - Sprintf(race, "%s ", urace.adj); - Sprintf(outbuf, "%s%s%s called %s", - /* being blinded may hide invisibility from self */ - (Invis && (senseself() || !Blind)) ? "invisible " : "", - race, mons[u.umonnum].mname, plname); - if (u.usteed) - Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed)); - return outbuf; + /* include race with role unless polymorphed */ + race[0] = '\0'; + if (!Upolyd) + Sprintf(race, "%s ", urace.adj); + Sprintf(outbuf, "%s%s%s called %s", + /* being blinded may hide invisibility from self */ + (Invis && (senseself() || !Blind)) ? "invisible " : "", race, + mons[u.umonnum].mname, plname); + if (u.usteed) + Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed)); + return outbuf; } /* @@ -76,206 +78,227 @@ char *outbuf; */ STATIC_OVL struct permonst * lookat(x, y, buf, monbuf) - int x, y; - char *buf, *monbuf; +int x, y; +char *buf, *monbuf; { register struct monst *mtmp = (struct monst *) 0; struct permonst *pm = (struct permonst *) 0; int glyph; buf[0] = monbuf[0] = 0; - glyph = glyph_at(x,y); + glyph = glyph_at(x, y); if (u.ux == x && u.uy == y && canspotself()) { - /* fill in buf[] */ - (void)self_lookat(buf); + /* fill in buf[] */ + (void) self_lookat(buf); - /* file lookup can't distinguish between "gnomish wizard" monster - and correspondingly named player character, always picking the - former; force it to find the general "wizard" entry instead */ - if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd) - pm = &mons[PM_WIZARD]; + /* file lookup can't distinguish between "gnomish wizard" monster + and correspondingly named player character, always picking the + former; force it to find the general "wizard" entry instead */ + if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd) + pm = &mons[PM_WIZARD]; - /* When you see yourself normally, no explanation is appended - (even if you could also see yourself via other means). - Sensing self while blind or swallowed is treated as if it - were by normal vision (cf canseeself()). */ - if ((Invisible || u.uundetected) && !Blind && !u.uswallow) { - unsigned how = 0; + /* When you see yourself normally, no explanation is appended + (even if you could also see yourself via other means). + Sensing self while blind or swallowed is treated as if it + were by normal vision (cf canseeself()). */ + if ((Invisible || u.uundetected) && !Blind && !u.uswallow) { + unsigned how = 0; - if (Infravision) how |= 1; - if (Unblind_telepat) how |= 2; - if (Detect_monsters) how |= 4; + if (Infravision) + how |= 1; + if (Unblind_telepat) + how |= 2; + if (Detect_monsters) + how |= 4; - if (how) - Sprintf(eos(buf), " [seen: %s%s%s%s%s]", - (how & 1) ? "infravision" : "", - /* add comma if telep and infrav */ - ((how & 3) > 2) ? ", " : "", - (how & 2) ? "telepathy" : "", - /* add comma if detect and (infrav or telep or both) */ - ((how & 7) > 4) ? ", " : "", - (how & 4) ? "monster detection" : ""); - } + if (how) + Sprintf( + eos(buf), " [seen: %s%s%s%s%s]", + (how & 1) ? "infravision" : "", + /* add comma if telep and infrav */ + ((how & 3) > 2) ? ", " : "", (how & 2) ? "telepathy" : "", + /* add comma if detect and (infrav or telep or both) */ + ((how & 7) > 4) ? ", " : "", + (how & 4) ? "monster detection" : ""); + } } else if (u.uswallow) { - /* all locations when swallowed other than the hero are the monster */ - Sprintf(buf, "interior of %s", - Blind ? "a monster" : a_monnam(u.ustuck)); - pm = u.ustuck->data; + /* all locations when swallowed other than the hero are the monster */ + Sprintf(buf, "interior of %s", + Blind ? "a monster" : a_monnam(u.ustuck)); + pm = u.ustuck->data; } else if (glyph_is_monster(glyph)) { - bhitpos.x = x; - bhitpos.y = y; - mtmp = m_at(x,y); - if (mtmp) { - char *name, monnambuf[BUFSZ]; - unsigned how_seen; - boolean accurate = !Hallucination; + bhitpos.x = x; + bhitpos.y = y; + mtmp = m_at(x, y); + if (mtmp) { + char *name, monnambuf[BUFSZ]; + unsigned how_seen; + boolean accurate = !Hallucination; - if (mtmp->data == &mons[PM_COYOTE] && accurate) - name = coyotename(mtmp, monnambuf); - else - name = distant_monnam(mtmp, ARTICLE_NONE, monnambuf); + if (mtmp->data == &mons[PM_COYOTE] && accurate) + name = coyotename(mtmp, monnambuf); + else + name = distant_monnam(mtmp, ARTICLE_NONE, monnambuf); - pm = mtmp->data; - Sprintf(buf, "%s%s%s", - (mtmp->mx != x || mtmp->my != y) ? - ((mtmp->isshk && accurate) - ? "tail of " : "tail of a ") : "", - (mtmp->mtame && accurate) ? "tame " : - (mtmp->mpeaceful && accurate) ? "peaceful " : "", - name); - if (u.ustuck == mtmp) - Strcat(buf, (Upolyd && sticks(youmonst.data)) ? - ", being held" : ", holding you"); - if (mtmp->mleashed) - Strcat(buf, ", leashed to you"); + pm = mtmp->data; + Sprintf( + buf, "%s%s%s", + (mtmp->mx != x || mtmp->my != y) + ? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ") + : "", + (mtmp->mtame && accurate) + ? "tame " + : (mtmp->mpeaceful && accurate) ? "peaceful " : "", + name); + if (u.ustuck == mtmp) + Strcat(buf, (Upolyd && sticks(youmonst.data)) + ? ", being held" + : ", holding you"); + if (mtmp->mleashed) + Strcat(buf, ", leashed to you"); - if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) { - struct trap *t = t_at(mtmp->mx, mtmp->my); - int tt = t ? t->ttyp : NO_TRAP; + if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) { + struct trap *t = t_at(mtmp->mx, mtmp->my); + int tt = t ? t->ttyp : NO_TRAP; - /* newsym lets you know of the trap, so mention it here */ - if (tt == BEAR_TRAP || tt == PIT || - tt == SPIKED_PIT || tt == WEB) - Sprintf(eos(buf), ", trapped in %s", - an(defsyms[trap_to_defsym(tt)].explanation)); - } + /* newsym lets you know of the trap, so mention it here */ + if (tt == BEAR_TRAP || tt == PIT || tt == SPIKED_PIT + || tt == WEB) + Sprintf(eos(buf), ", trapped in %s", + an(defsyms[trap_to_defsym(tt)].explanation)); + } - how_seen = howmonseen(mtmp); - if (how_seen && how_seen != MONSEEN_NORMAL) { - if (how_seen & MONSEEN_NORMAL) { - Strcat(monbuf, "normal vision"); - how_seen &= ~MONSEEN_NORMAL; - /* how_seen can't be 0 yet... */ - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_SEEINVIS) { - Strcat(monbuf, "see invisible"); - how_seen &= ~MONSEEN_SEEINVIS; - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_INFRAVIS) { - Strcat(monbuf, "infravision"); - how_seen &= ~MONSEEN_INFRAVIS; - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_TELEPAT) { - Strcat(monbuf, "telepathy"); - how_seen &= ~MONSEEN_TELEPAT; - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_XRAYVIS) { - /* Eyes of the Overworld */ - Strcat(monbuf, "astral vision"); - how_seen &= ~MONSEEN_XRAYVIS; - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_DETECT) { - Strcat(monbuf, "monster detection"); - how_seen &= ~MONSEEN_DETECT; - if (how_seen) Strcat(monbuf, ", "); - } - if (how_seen & MONSEEN_WARNMON) { - if (Hallucination) - Strcat(monbuf, "paranoid delusion"); - else - Sprintf(eos(monbuf), "warned of %s", - makeplural(mtmp->data->mname)); - how_seen &= ~MONSEEN_WARNMON; - if (how_seen) Strcat(monbuf, ", "); - } - /* should have used up all the how_seen bits by now */ - if (how_seen) { - impossible("lookat: unknown method of seeing monster"); - Sprintf(eos(monbuf), "(%u)", how_seen); - } - } /* seen by something other than normal vision */ - } /* mtmp */ + how_seen = howmonseen(mtmp); + if (how_seen && how_seen != MONSEEN_NORMAL) { + if (how_seen & MONSEEN_NORMAL) { + Strcat(monbuf, "normal vision"); + how_seen &= ~MONSEEN_NORMAL; + /* how_seen can't be 0 yet... */ + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_SEEINVIS) { + Strcat(monbuf, "see invisible"); + how_seen &= ~MONSEEN_SEEINVIS; + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_INFRAVIS) { + Strcat(monbuf, "infravision"); + how_seen &= ~MONSEEN_INFRAVIS; + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_TELEPAT) { + Strcat(monbuf, "telepathy"); + how_seen &= ~MONSEEN_TELEPAT; + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_XRAYVIS) { + /* Eyes of the Overworld */ + Strcat(monbuf, "astral vision"); + how_seen &= ~MONSEEN_XRAYVIS; + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_DETECT) { + Strcat(monbuf, "monster detection"); + how_seen &= ~MONSEEN_DETECT; + if (how_seen) + Strcat(monbuf, ", "); + } + if (how_seen & MONSEEN_WARNMON) { + if (Hallucination) + Strcat(monbuf, "paranoid delusion"); + else + Sprintf(eos(monbuf), "warned of %s", + makeplural(mtmp->data->mname)); + how_seen &= ~MONSEEN_WARNMON; + if (how_seen) + Strcat(monbuf, ", "); + } + /* should have used up all the how_seen bits by now */ + if (how_seen) { + impossible("lookat: unknown method of seeing monster"); + Sprintf(eos(monbuf), "(%u)", how_seen); + } + } /* seen by something other than normal vision */ + } /* mtmp */ } else if (glyph_is_object(glyph)) { - int glyphotyp = glyph_to_obj(glyph); - struct obj *otmp = vobj_at(x,y); + int glyphotyp = glyph_to_obj(glyph); + struct obj *otmp = vobj_at(x, y); - /* there might be a mimic here posing as an object */ - mtmp = m_at(x, y); - if (mtmp && mtmp->m_ap_type == M_AP_OBJECT && - mtmp->mappearance == (unsigned)glyphotyp) otmp = 0; - else mtmp = 0; + /* there might be a mimic here posing as an object */ + mtmp = m_at(x, y); + if (mtmp && mtmp->m_ap_type == M_AP_OBJECT + && mtmp->mappearance == (unsigned) glyphotyp) + otmp = 0; + else + mtmp = 0; - if (!otmp || otmp->otyp != glyphotyp) { - if (glyphotyp != STRANGE_OBJECT) { - otmp = mksobj(glyphotyp, FALSE, FALSE); - if (otmp->oclass == COIN_CLASS) - otmp->quan = 2L; /* to force pluralization */ - else if (otmp->otyp == SLIME_MOLD) - otmp->spe = context.current_fruit; /* give it a type */ - if (mtmp && has_mcorpsenm(mtmp)) /* mimic as corpse/statue */ - otmp->corpsenm = MCORPSENM(mtmp); - Strcpy(buf, distant_name(otmp, xname)); - dealloc_obj(otmp); - } - } else - Strcpy(buf, distant_name(otmp, xname)); + if (!otmp || otmp->otyp != glyphotyp) { + if (glyphotyp != STRANGE_OBJECT) { + otmp = mksobj(glyphotyp, FALSE, FALSE); + if (otmp->oclass == COIN_CLASS) + otmp->quan = 2L; /* to force pluralization */ + else if (otmp->otyp == SLIME_MOLD) + otmp->spe = context.current_fruit; /* give it a type */ + if (mtmp && has_mcorpsenm(mtmp)) /* mimic as corpse/statue */ + otmp->corpsenm = MCORPSENM(mtmp); + Strcpy(buf, distant_name(otmp, xname)); + dealloc_obj(otmp); + } + } else + Strcpy(buf, distant_name(otmp, xname)); - if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) - Strcat(buf, " embedded in stone"); - else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR) - Strcat(buf, " embedded in a wall"); - else if (closed_door(x,y)) - Strcat(buf, " embedded in a door"); - else if (is_pool(x,y)) - Strcat(buf, " in water"); - else if (is_lava(x,y)) - Strcat(buf, " in molten lava"); /* [can this ever happen?] */ + if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) + Strcat(buf, " embedded in stone"); + else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR) + Strcat(buf, " embedded in a wall"); + else if (closed_door(x, y)) + Strcat(buf, " embedded in a door"); + else if (is_pool(x, y)) + Strcat(buf, " in water"); + else if (is_lava(x, y)) + Strcat(buf, " in molten lava"); /* [can this ever happen?] */ } else if (glyph_is_trap(glyph)) { - int tnum = what_trap(glyph_to_trap(glyph)); - Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation); - } else if(!glyph_is_cmap(glyph)) { - Strcpy(buf,"unexplored area"); - } else switch(glyph_to_cmap(glyph)) { - case S_altar: - Sprintf(buf, "%s %saltar", - /* like endgame high priests, endgame high altars - are only recognizable when immediately adjacent */ - (Is_astralevel(&u.uz) && distu(x, y) > 2) ? "aligned" : - align_str(Amask2align(levl[x][y].altarmask & ~AM_SHRINE)), - ((levl[x][y].altarmask & AM_SHRINE) && - (Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) ? "high " : ""); - break; - case S_ndoor: - if (is_drawbridge_wall(x, y) >= 0) - Strcpy(buf,"open drawbridge portcullis"); - else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN) - Strcpy(buf,"broken door"); - else - Strcpy(buf,"doorway"); - break; - case S_cloud: - Strcpy(buf, Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud"); - break; - default: - Strcpy(buf,defsyms[glyph_to_cmap(glyph)].explanation); - break; - } + int tnum = what_trap(glyph_to_trap(glyph)); + Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation); + } else if (!glyph_is_cmap(glyph)) { + Strcpy(buf, "unexplored area"); + } else + switch (glyph_to_cmap(glyph)) { + case S_altar: + Sprintf(buf, "%s %saltar", + /* like endgame high priests, endgame high altars + are only recognizable when immediately adjacent */ + (Is_astralevel(&u.uz) && distu(x, y) > 2) + ? "aligned" + : align_str( + Amask2align(levl[x][y].altarmask & ~AM_SHRINE)), + ((levl[x][y].altarmask & AM_SHRINE) + && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) + ? "high " + : ""); + break; + case S_ndoor: + if (is_drawbridge_wall(x, y) >= 0) + Strcpy(buf, "open drawbridge portcullis"); + else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN) + Strcpy(buf, "broken door"); + else + Strcpy(buf, "doorway"); + break; + case S_cloud: + Strcpy(buf, + Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud"); + break; + default: + Strcpy(buf, defsyms[glyph_to_cmap(glyph)].explanation); + break; + } return ((pm && !Hallucination) ? pm : (struct permonst *) 0); } @@ -292,9 +315,9 @@ lookat(x, y, buf, monbuf) */ STATIC_OVL void checkfile(inp, pm, user_typed_name, without_asking) - char *inp; - struct permonst *pm; - boolean user_typed_name, without_asking; +char *inp; +struct permonst *pm; +boolean user_typed_name, without_asking; { dlb *fp; char buf[BUFSZ], newstr[BUFSZ]; @@ -306,16 +329,16 @@ checkfile(inp, pm, user_typed_name, without_asking) fp = dlb_fopen(DATAFILE, "r"); if (!fp) { - pline("Cannot open data file!"); - return; + pline("Cannot open data file!"); + return; } /* * If someone passed us garbage, prevent fault. */ if (!inp || (inp && strlen(inp) > (BUFSZ - 1))) { - pline("bad do_look buffer passed!"); - return; + pline("bad do_look buffer passed!"); + return; } /* To prevent the need for entries in data.base like *ngel to account @@ -323,124 +346,136 @@ checkfile(inp, pm, user_typed_name, without_asking) * user_typed_name and picked name. */ if (pm != (struct permonst *) 0 && !user_typed_name) - dbase_str = strcpy(newstr, pm->mname); - else dbase_str = strcpy(newstr, inp); + dbase_str = strcpy(newstr, pm->mname); + else + dbase_str = strcpy(newstr, inp); (void) lcase(dbase_str); if (!strncmp(dbase_str, "interior of ", 12)) - dbase_str += 12; + dbase_str += 12; if (!strncmp(dbase_str, "a ", 2)) - dbase_str += 2; + dbase_str += 2; else if (!strncmp(dbase_str, "an ", 3)) - dbase_str += 3; + dbase_str += 3; else if (!strncmp(dbase_str, "the ", 4)) - dbase_str += 4; + dbase_str += 4; if (!strncmp(dbase_str, "tame ", 5)) - dbase_str += 5; + dbase_str += 5; else if (!strncmp(dbase_str, "peaceful ", 9)) - dbase_str += 9; + dbase_str += 9; if (!strncmp(dbase_str, "invisible ", 10)) - dbase_str += 10; + dbase_str += 10; if (!strncmp(dbase_str, "saddled ", 8)) - dbase_str += 8; + dbase_str += 8; if (!strncmp(dbase_str, "statue of ", 10)) - dbase_str[6] = '\0'; + dbase_str[6] = '\0'; else if (!strncmp(dbase_str, "figurine of ", 12)) - dbase_str[8] = '\0'; + dbase_str[8] = '\0'; /* Make sure the name is non-empty. */ if (*dbase_str) { - /* adjust the input to remove "named " and convert to lower case */ - char *alt = 0; /* alternate description */ + /* adjust the input to remove "named " and convert to lower case */ + char *alt = 0; /* alternate description */ - if ((ep = strstri(dbase_str, " named ")) != 0) - alt = ep + 7; - else - ep = strstri(dbase_str, " called "); - if (!ep) ep = strstri(dbase_str, ", "); - if (ep && ep > dbase_str) *ep = '\0'; + if ((ep = strstri(dbase_str, " named ")) != 0) + alt = ep + 7; + else + ep = strstri(dbase_str, " called "); + if (!ep) + ep = strstri(dbase_str, ", "); + if (ep && ep > dbase_str) + *ep = '\0'; - /* - * If the object is named, then the name is the alternate description; - * otherwise, the result of makesingular() applied to the name is. This - * isn't strictly optimal, but named objects of interest to the user - * will usually be found under their name, rather than under their - * object type, so looking for a singular form is pointless. - */ - if (!alt) - alt = makesingular(dbase_str); + /* + * If the object is named, then the name is the alternate description; + * otherwise, the result of makesingular() applied to the name is. + * This + * isn't strictly optimal, but named objects of interest to the user + * will usually be found under their name, rather than under their + * object type, so looking for a singular form is pointless. + */ + if (!alt) + alt = makesingular(dbase_str); - /* skip first record; read second */ - txt_offset = 0L; - if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) { - impossible("can't read 'data' file"); - (void) dlb_fclose(fp); - return; - } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset == 0L) - goto bad_data_file; + /* skip first record; read second */ + txt_offset = 0L; + if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) { + impossible("can't read 'data' file"); + (void) dlb_fclose(fp); + return; + } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset == 0L) + goto bad_data_file; - /* look for the appropriate entry */ - while (dlb_fgets(buf,BUFSZ,fp)) { - if (*buf == '.') break; /* we passed last entry without success */ + /* look for the appropriate entry */ + while (dlb_fgets(buf, BUFSZ, fp)) { + if (*buf == '.') + break; /* we passed last entry without success */ - if (digit(*buf)) { - /* a number indicates the end of current entry */ - skipping_entry = FALSE; - } else if (!skipping_entry) { - if (!(ep = index(buf, '\n'))) goto bad_data_file; - *ep = 0; - /* if we match a key that begins with "~", skip this entry */ - chk_skip = (*buf == '~') ? 1 : 0; - if (pmatch(&buf[chk_skip], dbase_str) || - (alt && pmatch(&buf[chk_skip], alt))) { - if (chk_skip) { - skipping_entry = TRUE; - continue; - } else { - found_in_file = TRUE; - break; - } - } - } - } + if (digit(*buf)) { + /* a number indicates the end of current entry */ + skipping_entry = FALSE; + } else if (!skipping_entry) { + if (!(ep = index(buf, '\n'))) + goto bad_data_file; + *ep = 0; + /* if we match a key that begins with "~", skip this entry */ + chk_skip = (*buf == '~') ? 1 : 0; + if (pmatch(&buf[chk_skip], dbase_str) + || (alt && pmatch(&buf[chk_skip], alt))) { + if (chk_skip) { + skipping_entry = TRUE; + continue; + } else { + found_in_file = TRUE; + break; + } + } + } + } } - if(found_in_file) { - long entry_offset; - int entry_count; - int i; + if (found_in_file) { + long entry_offset; + int entry_count; + int i; - /* skip over other possible matches for the info */ - do { - if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file; - } while (!digit(*buf)); - if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) { - bad_data_file: - impossible("'data' file in wrong format or corrupted"); - /* window will exist if we came here from below via 'goto' */ - if (datawin != WIN_ERR) destroy_nhwindow(datawin); - (void) dlb_fclose(fp); - return; - } + /* skip over other possible matches for the info */ + do { + if (!dlb_fgets(buf, BUFSZ, fp)) + goto bad_data_file; + } while (!digit(*buf)); + if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) { + bad_data_file: + impossible("'data' file in wrong format or corrupted"); + /* window will exist if we came here from below via 'goto' */ + if (datawin != WIN_ERR) + destroy_nhwindow(datawin); + (void) dlb_fclose(fp); + return; + } - if (user_typed_name || without_asking || yn("More info?") == 'y') { - if (dlb_fseek(fp, (long)txt_offset + entry_offset, SEEK_SET) < 0) { - pline("? Seek error on 'data' file!"); - (void) dlb_fclose(fp); - return; - } - datawin = create_nhwindow(NHW_MENU); - for (i = 0; i < entry_count; i++) { - if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file; - if ((ep = index(buf, '\n')) != 0) *ep = 0; - if (index(buf+1, '\t') != 0) (void) tabexpand(buf+1); - putstr(datawin, 0, buf+1); - } - display_nhwindow(datawin, FALSE); - destroy_nhwindow(datawin); - } + if (user_typed_name || without_asking || yn("More info?") == 'y') { + if (dlb_fseek(fp, (long) txt_offset + entry_offset, SEEK_SET) + < 0) { + pline("? Seek error on 'data' file!"); + (void) dlb_fclose(fp); + return; + } + datawin = create_nhwindow(NHW_MENU); + for (i = 0; i < entry_count; i++) { + if (!dlb_fgets(buf, BUFSZ, fp)) + goto bad_data_file; + if ((ep = index(buf, '\n')) != 0) + *ep = 0; + if (index(buf + 1, '\t') != 0) + (void) tabexpand(buf + 1); + putstr(datawin, 0, buf + 1); + } + display_nhwindow(datawin, FALSE); + destroy_nhwindow(datawin); + } } else if (user_typed_name) - pline("I don't have any information on those things."); + pline("I don't have any information on those things."); (void) dlb_fclose(fp); } @@ -455,9 +490,9 @@ const char **firstmatch; { boolean need_to_look = FALSE; int glyph; - static char look_buf[BUFSZ]; + static char look_buf[BUFSZ]; char prefix[BUFSZ]; - int found = 0; /* count of matching syms found */ + int found = 0; /* count of matching syms found */ int i; int skipped_venom = 0; boolean hit_trap; @@ -465,19 +500,19 @@ const char **firstmatch; static const char *mon_interior = "the interior of a monster"; if (looked) { - int oc; - unsigned os; + int oc; + unsigned os; - glyph = glyph_at(cc.x,cc.y); + glyph = glyph_at(cc.x, cc.y); - /* Convert the glyph at the selected position to a symbol. */ - (void) mapglyph(glyph, &sym, &oc, &os, cc.x, cc.y); + /* Convert the glyph at the selected position to a symbol. */ + (void) mapglyph(glyph, &sym, &oc, &os, cc.x, cc.y); } if (looked) - Sprintf(prefix, "%s ", encglyph(glyph)); + Sprintf(prefix, "%s ", encglyph(glyph)); else - Sprintf(prefix, "%c ", sym); + Sprintf(prefix, "%c ", sym); /* * Check all the possibilities, saving all explanations in a buffer. @@ -486,28 +521,26 @@ const char **firstmatch; /* Check for monsters */ for (i = 0; i < MAXMCLASSES; i++) { - if (sym == ((looked) ? - showsyms[i + SYM_OFF_M] : def_monsyms[i].sym) && - def_monsyms[i].explain) { - need_to_look = TRUE; - if (!found) { - Sprintf(out_str, "%s%s", - prefix, an(def_monsyms[i].explain)); - *firstmatch = def_monsyms[i].explain; - found++; - } else { - found += append_str(out_str, an(def_monsyms[i].explain)); - } - } + if (sym == ((looked) ? showsyms[i + SYM_OFF_M] : def_monsyms[i].sym) + && def_monsyms[i].explain) { + need_to_look = TRUE; + if (!found) { + Sprintf(out_str, "%s%s", prefix, an(def_monsyms[i].explain)); + *firstmatch = def_monsyms[i].explain; + found++; + } else { + found += append_str(out_str, an(def_monsyms[i].explain)); + } + } } /* handle '@' as a special case if it refers to you and you're playing a character which isn't normally displayed by that symbol; firstmatch is assumed to already be set for '@' */ - if (((looked) ? - (sym == showsyms[S_HUMAN + SYM_OFF_M] && cc.x == u.ux && cc.y == u.uy) : - (sym == def_monsyms[S_HUMAN].sym && !flags.showrace)) && - !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd) - found += append_str(out_str, "you"); /* tack on "or you" */ + if (((looked) ? (sym == showsyms[S_HUMAN + SYM_OFF_M] && cc.x == u.ux + && cc.y == u.uy) + : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace)) + && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd) + found += append_str(out_str, "you"); /* tack on "or you" */ /* * Special case: if identifying from the screen, and we're swallowed, @@ -515,46 +548,42 @@ const char **firstmatch; * "the interior of a monster". */ if (u.uswallow && (looked) && is_swallow_sym(sym)) { - if (!found) { - Sprintf(out_str, "%s%s", - prefix, mon_interior); - *firstmatch = mon_interior; - } else { - found += append_str(out_str, mon_interior); - } - need_to_look = TRUE; + if (!found) { + Sprintf(out_str, "%s%s", prefix, mon_interior); + *firstmatch = mon_interior; + } else { + found += append_str(out_str, mon_interior); + } + need_to_look = TRUE; } /* Now check for objects */ for (i = 1; i < MAXOCLASSES; i++) { - if (sym == ((looked) ? - showsyms[i + SYM_OFF_O] : def_oc_syms[i].sym)) { - need_to_look = TRUE; - if ((looked) && i == VENOM_CLASS) { - skipped_venom++; - continue; - } - if (!found) { - Sprintf(out_str, "%s%s", - prefix, an(def_oc_syms[i].explain)); - *firstmatch = def_oc_syms[i].explain; - found++; - } else { - found += append_str(out_str, an(def_oc_syms[i].explain)); - } - } + if (sym + == ((looked) ? showsyms[i + SYM_OFF_O] : def_oc_syms[i].sym)) { + need_to_look = TRUE; + if ((looked) && i == VENOM_CLASS) { + skipped_venom++; + continue; + } + if (!found) { + Sprintf(out_str, "%s%s", prefix, an(def_oc_syms[i].explain)); + *firstmatch = def_oc_syms[i].explain; + found++; + } else { + found += append_str(out_str, an(def_oc_syms[i].explain)); + } + } } if (sym == DEF_INVISIBLE) { - if (!found) { - Sprintf(out_str, "%s%s", - prefix, - an(invisexplain)); - *firstmatch = invisexplain; - found++; - } else { - found += append_str(out_str, an(invisexplain)); - } + if (!found) { + Sprintf(out_str, "%s%s", prefix, an(invisexplain)); + *firstmatch = invisexplain; + found++; + } else { + found += append_str(out_str, an(invisexplain)); + } } #define is_cmap_trap(i) ((i) >= S_arrow_trap && (i) <= S_polymorph_trap) @@ -562,83 +591,80 @@ const char **firstmatch; /* Now check for graphics symbols */ for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) { - x_str = defsyms[i].explanation; - if (sym == ((looked) ? - showsyms[i] : defsyms[i].sym) && *x_str) { - /* avoid "an air", "a water", "a floor of a room", "a dark part of a room" */ - int article = ((i == S_room)||(i == S_darkroom)) ? 2 : /* 2=>"the" */ - !(strcmp(x_str, "air") == 0 || /* 1=>"an" */ - strcmp(x_str, "water") == 0); /* 0=>(none)*/ + x_str = defsyms[i].explanation; + if (sym == ((looked) ? showsyms[i] : defsyms[i].sym) && *x_str) { + /* avoid "an air", "a water", "a floor of a room", "a dark part of + * a room" */ + int article = + ((i == S_room) || (i == S_darkroom)) ? 2 : /* 2=>"the" */ + !(strcmp(x_str, "air") == 0 || /* 1=>"an" */ + strcmp(x_str, "water") == 0); /* 0=>(none)*/ - if (!found) { - if (is_cmap_trap(i)) { - Sprintf(out_str, "%sa trap", prefix); - hit_trap = TRUE; - } else { - Sprintf(out_str, "%s%s", - prefix, - article == 2 ? the(x_str) : - article == 1 ? an(x_str) : x_str); - } - *firstmatch = x_str; - found++; - } else if (!u.uswallow && !(hit_trap && is_cmap_trap(i)) && - !(found >= 3 && is_cmap_drawbridge(i))) { - found += append_str(out_str, - article == 2 ? the(x_str) : - article == 1 ? an(x_str) : x_str); - if (is_cmap_trap(i)) hit_trap = TRUE; - } + if (!found) { + if (is_cmap_trap(i)) { + Sprintf(out_str, "%sa trap", prefix); + hit_trap = TRUE; + } else { + Sprintf(out_str, "%s%s", prefix, + article == 2 ? the(x_str) + : article == 1 ? an(x_str) : x_str); + } + *firstmatch = x_str; + found++; + } else if (!u.uswallow && !(hit_trap && is_cmap_trap(i)) + && !(found >= 3 && is_cmap_drawbridge(i))) { + found += append_str( + out_str, article == 2 ? the(x_str) + : article == 1 ? an(x_str) : x_str); + if (is_cmap_trap(i)) + hit_trap = TRUE; + } - if (i == S_altar || is_cmap_trap(i)) - need_to_look = TRUE; - } + if (i == S_altar || is_cmap_trap(i)) + need_to_look = TRUE; + } } /* Now check for warning symbols */ for (i = 1; i < WARNCOUNT; i++) { - x_str = def_warnsyms[i].explanation; - if (sym == ((looked) ? - warnsyms[i] : def_warnsyms[i].sym)) { - if (!found) { - Sprintf(out_str, "%s%s", - prefix, def_warnsyms[i].explanation); - *firstmatch = def_warnsyms[i].explanation; - found++; - } else { - found += append_str(out_str, def_warnsyms[i].explanation); - } - /* Kludge: warning trumps boulders on the display. - Reveal the boulder too or player can get confused */ - if ((looked) && sobj_at(BOULDER, cc.x, cc.y)) - Strcat(out_str, " co-located with a boulder"); - break; /* out of for loop*/ - } + x_str = def_warnsyms[i].explanation; + if (sym == ((looked) ? warnsyms[i] : def_warnsyms[i].sym)) { + if (!found) { + Sprintf(out_str, "%s%s", prefix, def_warnsyms[i].explanation); + *firstmatch = def_warnsyms[i].explanation; + found++; + } else { + found += append_str(out_str, def_warnsyms[i].explanation); + } + /* Kludge: warning trumps boulders on the display. + Reveal the boulder too or player can get confused */ + if ((looked) && sobj_at(BOULDER, cc.x, cc.y)) + Strcat(out_str, " co-located with a boulder"); + break; /* out of for loop*/ + } } /* if we ignored venom and list turned out to be short, put it back */ if (skipped_venom && found < 2) { - x_str = def_oc_syms[VENOM_CLASS].explain; - if (!found) { - Sprintf(out_str, "%s%s", - prefix, an(x_str)); - *firstmatch = x_str; - found++; - } else { - found += append_str(out_str, an(x_str)); - } + x_str = def_oc_syms[VENOM_CLASS].explain; + if (!found) { + Sprintf(out_str, "%s%s", prefix, an(x_str)); + *firstmatch = x_str; + found++; + } else { + found += append_str(out_str, an(x_str)); + } } /* handle optional boulder symbol as a special case */ if (iflags.bouldersym && sym == iflags.bouldersym) { - if (!found) { - *firstmatch = "boulder"; - Sprintf(out_str, "%s%s", - prefix, an(*firstmatch)); - found++; - } else { - found += append_str(out_str, "boulder"); - } + if (!found) { + *firstmatch = "boulder"; + Sprintf(out_str, "%s%s", prefix, an(*firstmatch)); + found++; + } else { + found += append_str(out_str, "boulder"); + } } /* @@ -646,127 +672,135 @@ const char **firstmatch; * an ambiguous explanation by something more detailed. */ if (looked) { - if (found > 1 || need_to_look) { - char monbuf[BUFSZ]; - char temp_buf[BUFSZ]; + if (found > 1 || need_to_look) { + char monbuf[BUFSZ]; + char temp_buf[BUFSZ]; - (void) lookat(cc.x, cc.y, look_buf, monbuf); - *firstmatch = look_buf; - if (*(*firstmatch)) { - Sprintf(temp_buf, " (%s)", *firstmatch); - (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1); - found = 1; /* we have something to look up */ - } - if (monbuf[0]) { - Sprintf(temp_buf, " [seen: %s]", monbuf); - (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1); - } - } + (void) lookat(cc.x, cc.y, look_buf, monbuf); + *firstmatch = look_buf; + if (*(*firstmatch)) { + Sprintf(temp_buf, " (%s)", *firstmatch); + (void) strncat(out_str, temp_buf, + BUFSZ - strlen(out_str) - 1); + found = 1; /* we have something to look up */ + } + if (monbuf[0]) { + Sprintf(temp_buf, " [seen: %s]", monbuf); + (void) strncat(out_str, temp_buf, + BUFSZ - strlen(out_str) - 1); + } + } } return found; } - /* getpos() return values */ -#define LOOK_TRADITIONAL 0 /* '.' -- ask about "more info?" */ -#define LOOK_QUICK 1 /* ',' -- skip "more info?" */ -#define LOOK_ONCE 2 /* ';' -- skip and stop looping */ -#define LOOK_VERBOSE 3 /* ':' -- show more info w/o asking */ +#define LOOK_TRADITIONAL 0 /* '.' -- ask about "more info?" */ +#define LOOK_QUICK 1 /* ',' -- skip "more info?" */ +#define LOOK_ONCE 2 /* ';' -- skip and stop looping */ +#define LOOK_VERBOSE 3 /* ':' -- show more info w/o asking */ /* also used by getpos hack in do_name.c */ const char what_is_an_unknown_object[] = "an unknown object"; int do_look(mode, click_cc) - int mode; - coord *click_cc; +int mode; +coord *click_cc; { - boolean quick = (mode == 1); /* use cursor && don't search for "more info" */ + boolean quick = + (mode == 1); /* use cursor && don't search for "more info" */ boolean clicklook = (mode == 2); /* right mouse-click method */ - char out_str[BUFSZ]; + char out_str[BUFSZ]; const char *firstmatch = 0; struct permonst *pm = 0; - int i = '\0', ans = 0; - int sym; /* typed symbol or converted glyph */ - int found; /* count of matching syms found */ - coord cc; /* screen pos of unknown glyph */ - boolean save_verbose; /* saved value of flags.verbose */ - boolean from_screen; /* question from the screen */ + int i = '\0', ans = 0; + int sym; /* typed symbol or converted glyph */ + int found; /* count of matching syms found */ + coord cc; /* screen pos of unknown glyph */ + boolean save_verbose; /* saved value of flags.verbose */ + boolean from_screen; /* question from the screen */ if (!clicklook) { - if (quick) { - from_screen = TRUE; /* yes, we want to use the cursor */ - i = 'y'; + if (quick) { + from_screen = TRUE; /* yes, we want to use the cursor */ + i = 'y'; } - if (i != 'y') { - menu_item *pick_list = (menu_item *)0; - winid win; - anything any; - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; any.a_char ='a'; - /* 'y' and 'n' to keep backwards compat with previous versions */ - add_menu(win, NO_GLYPH, &any, 'a', 'y', ATR_NONE, "something on the map", MENU_UNSELECTED); - any.a_void = 0; any.a_char ='b'; - add_menu(win, NO_GLYPH, &any, 'b', 0, ATR_NONE, "something you're carrying", MENU_UNSELECTED); - any.a_void = 0; any.a_char ='c'; - add_menu(win, NO_GLYPH, &any, 'c', 'n', ATR_NONE, "something else", MENU_UNSELECTED); - end_menu(win, "What do you want to look at:"); - if (select_menu(win, PICK_ONE, &pick_list) > 0) { - i = pick_list->item.a_char; - free((genericptr_t)pick_list); - } - destroy_nhwindow(win); - } + if (i != 'y') { + menu_item *pick_list = (menu_item *) 0; + winid win; + anything any; + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; + any.a_char = 'a'; + /* 'y' and 'n' to keep backwards compat with previous versions */ + add_menu(win, NO_GLYPH, &any, 'a', 'y', ATR_NONE, + "something on the map", MENU_UNSELECTED); + any.a_void = 0; + any.a_char = 'b'; + add_menu(win, NO_GLYPH, &any, 'b', 0, ATR_NONE, + "something you're carrying", MENU_UNSELECTED); + any.a_void = 0; + any.a_char = 'c'; + add_menu(win, NO_GLYPH, &any, 'c', 'n', ATR_NONE, + "something else", MENU_UNSELECTED); + end_menu(win, "What do you want to look at:"); + if (select_menu(win, PICK_ONE, &pick_list) > 0) { + i = pick_list->item.a_char; + free((genericptr_t) pick_list); + } + destroy_nhwindow(win); + } - switch (i) { - default: - case 'q': return 0; - case 'y': - case 'a': - from_screen = TRUE; - sym = 0; - cc.x = u.ux; - cc.y = u.uy; - break; - case 'b': - { - char invlet; - struct obj *invobj; + switch (i) { + default: + case 'q': + return 0; + case 'y': + case 'a': + from_screen = TRUE; + sym = 0; + cc.x = u.ux; + cc.y = u.uy; + break; + case 'b': { + char invlet; + struct obj *invobj; - invlet = display_inventory(NULL, TRUE); - if (!invlet || invlet == '\033') return 0; - *out_str = '\0'; - for (invobj = invent; invobj; invobj = invobj->nobj) - if (invobj->invlet == invlet) { - strcpy(out_str, singular(invobj, xname)); - break; - } - if (*out_str) - checkfile(out_str, pm, TRUE, TRUE); - return 0; - } - break; - case 'c': - from_screen = FALSE; - getlin("Specify what? (type the word)", out_str); - if (out_str[0] == '\0' || out_str[0] == '\033') - return 0; + invlet = display_inventory(NULL, TRUE); + if (!invlet || invlet == '\033') + return 0; + *out_str = '\0'; + for (invobj = invent; invobj; invobj = invobj->nobj) + if (invobj->invlet == invlet) { + strcpy(out_str, singular(invobj, xname)); + break; + } + if (*out_str) + checkfile(out_str, pm, TRUE, TRUE); + return 0; + } break; + case 'c': + from_screen = FALSE; + getlin("Specify what? (type the word)", out_str); + if (out_str[0] == '\0' || out_str[0] == '\033') + return 0; - if (out_str[1]) { /* user typed in a complete string */ - checkfile(out_str, pm, TRUE, TRUE); - return 0; - } - sym = out_str[0]; - break; - } - } else { /* clicklook */ - cc.x = click_cc->x; - cc.y = click_cc->y; - sym = 0; - from_screen = FALSE; + if (out_str[1]) { /* user typed in a complete string */ + checkfile(out_str, pm, TRUE, TRUE); + return 0; + } + sym = out_str[0]; + break; + } + } else { /* clicklook */ + cc.x = click_cc->x; + cc.y = click_cc->y; + sym = 0; + from_screen = FALSE; } /* Save the verbose flag, we change it later. */ @@ -776,46 +810,49 @@ do_look(mode, click_cc) * The user typed one letter, or we're identifying from the screen. */ do { - /* Reset some variables. */ - pm = (struct permonst *)0; - found = 0; - out_str[0] = '\0'; + /* Reset some variables. */ + pm = (struct permonst *) 0; + found = 0; + out_str[0] = '\0'; - if (from_screen || clicklook) { - if (from_screen) { - if (flags.verbose) - pline("Please move the cursor to %s.", - what_is_an_unknown_object); - else - pline("Pick an object."); + if (from_screen || clicklook) { + if (from_screen) { + if (flags.verbose) + pline("Please move the cursor to %s.", + what_is_an_unknown_object); + else + pline("Pick an object."); - ans = getpos(&cc, quick, what_is_an_unknown_object); - if (ans < 0 || cc.x < 0) { - flags.verbose = save_verbose; - return 0; /* done */ - } - flags.verbose = FALSE; /* only print long question once */ - } - } + ans = getpos(&cc, quick, what_is_an_unknown_object); + if (ans < 0 || cc.x < 0) { + flags.verbose = save_verbose; + return 0; /* done */ + } + flags.verbose = FALSE; /* only print long question once */ + } + } - found = do_screen_description(cc, (from_screen||clicklook), sym, out_str, &firstmatch); + found = do_screen_description(cc, (from_screen || clicklook), sym, + out_str, &firstmatch); - /* Finally, print out our explanation. */ - if (found) { + /* Finally, print out our explanation. */ + if (found) { + /* Used putmixed() because there may be an encoded glyph present + */ + putmixed(WIN_MESSAGE, 0, out_str); - /* Used putmixed() because there may be an encoded glyph present */ - putmixed(WIN_MESSAGE, 0, out_str); - - /* check the data file for information about this thing */ - if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE && - (ans == LOOK_VERBOSE || (flags.help && !quick)) && !clicklook) { - char temp_buf[BUFSZ]; - Strcpy(temp_buf, firstmatch); - checkfile(temp_buf, pm, FALSE, (boolean)(ans == LOOK_VERBOSE)); - } - } else { - pline("I've never heard of such things."); - } + /* check the data file for information about this thing */ + if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE + && (ans == LOOK_VERBOSE || (flags.help && !quick)) + && !clicklook) { + char temp_buf[BUFSZ]; + Strcpy(temp_buf, firstmatch); + checkfile(temp_buf, pm, FALSE, + (boolean)(ans == LOOK_VERBOSE)); + } + } else { + pline("I've never heard of such things."); + } } while (from_screen && !quick && ans != LOOK_ONCE && !clicklook); @@ -827,47 +864,53 @@ do_look(mode, click_cc) int dowhatis() { - return do_look(0,(coord *)0); + return do_look(0, (coord *) 0); } /* the ';' command */ int doquickwhatis() { - return do_look(1,(coord *)0); + return do_look(1, (coord *) 0); } /* the '^' command */ int doidtrap() { - register struct trap *trap; - int x, y, tt; + register struct trap *trap; + int x, y, tt; - if (!getdir("^")) return 0; - x = u.ux + u.dx; - y = u.uy + u.dy; - for (trap = ftrap; trap; trap = trap->ntrap) - if (trap->tx == x && trap->ty == y) { - if (!trap->tseen) break; - tt = trap->ttyp; - if (u.dz) { - if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE) : - tt == ROCKTRAP) break; - } - tt = what_trap(tt); - pline("That is %s%s%s.", - an(defsyms[trap_to_defsym(tt)].explanation), - !trap->madeby_u ? "" : (tt == WEB) ? " woven" : - /* trap doors & spiked pits can't be made by - player, and should be considered at least - as much "set" as "dug" anyway */ - (tt == HOLE || tt == PIT) ? " dug" : " set", - !trap->madeby_u ? "" : " by you"); - return 0; - } - pline("I can't see a trap there."); - return 0; + if (!getdir("^")) + return 0; + x = u.ux + u.dx; + y = u.uy + u.dy; + for (trap = ftrap; trap; trap = trap->ntrap) + if (trap->tx == x && trap->ty == y) { + if (!trap->tseen) + break; + tt = trap->ttyp; + if (u.dz) { + if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE) + : tt == ROCKTRAP) + break; + } + tt = what_trap(tt); + pline( + "That is %s%s%s.", + an(defsyms[trap_to_defsym(tt)].explanation), + !trap->madeby_u + ? "" + : (tt == WEB) ? " woven" : + /* trap doors & spiked pits can't be made by + player, and should be considered at least + as much "set" as "dug" anyway */ + (tt == HOLE || tt == PIT) ? " dug" : " set", + !trap->madeby_u ? "" : " by you"); + return 0; + } + pline("I can't see a trap there."); + return 0; } char * @@ -875,201 +918,225 @@ dowhatdoes_core(q, cbuf) char q; char *cbuf; { - dlb *fp; - char bufr[BUFSZ]; - register char *buf = &bufr[6], *ep, ctrl, meta; + dlb *fp; + char bufr[BUFSZ]; + register char *buf = &bufr[6], *ep, ctrl, meta; - fp = dlb_fopen(CMDHELPFILE, "r"); - if (!fp) { - pline("Cannot open data file!"); - return 0; - } + fp = dlb_fopen(CMDHELPFILE, "r"); + if (!fp) { + pline("Cannot open data file!"); + return 0; + } - ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0); - meta = ((0x80 & q) ? (0x7f & q) : 0); - while(dlb_fgets(buf,BUFSZ-6,fp)) { - if ((ctrl && *buf=='^' && *(buf+1)==ctrl) || - (meta && *buf=='M' && *(buf+1)=='-' && *(buf+2)==meta) || - *buf==q) { - ep = index(buf, '\n'); - if(ep) *ep = 0; - if (ctrl && buf[2] == '\t'){ - buf = bufr + 1; - (void) strncpy(buf, "^? ", 8); - buf[1] = ctrl; - } else if (meta && buf[3] == '\t'){ - buf = bufr + 2; - (void) strncpy(buf, "M-? ", 8); - buf[2] = meta; - } else if(buf[1] == '\t'){ - buf = bufr; - buf[0] = q; - (void) strncpy(buf+1, " ", 7); - } - (void) dlb_fclose(fp); - Strcpy(cbuf, buf); - return cbuf; - } - } - (void) dlb_fclose(fp); - return (char *)0; + ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0); + meta = ((0x80 & q) ? (0x7f & q) : 0); + while (dlb_fgets(buf, BUFSZ - 6, fp)) { + if ((ctrl && *buf == '^' && *(buf + 1) == ctrl) + || (meta && *buf == 'M' && *(buf + 1) == '-' + && *(buf + 2) == meta) || *buf == q) { + ep = index(buf, '\n'); + if (ep) + *ep = 0; + if (ctrl && buf[2] == '\t') { + buf = bufr + 1; + (void) strncpy(buf, "^? ", 8); + buf[1] = ctrl; + } else if (meta && buf[3] == '\t') { + buf = bufr + 2; + (void) strncpy(buf, "M-? ", 8); + buf[2] = meta; + } else if (buf[1] == '\t') { + buf = bufr; + buf[0] = q; + (void) strncpy(buf + 1, " ", 7); + } + (void) dlb_fclose(fp); + Strcpy(cbuf, buf); + return cbuf; + } + } + (void) dlb_fclose(fp); + return (char *) 0; } int dowhatdoes() { - char bufr[BUFSZ]; - char q, *reslt; + char bufr[BUFSZ]; + char q, *reslt; #if defined(UNIX) || defined(VMS) - introff(); + introff(); #endif - q = yn_function("What command?", (char *)0, '\0'); + q = yn_function("What command?", (char *) 0, '\0'); #if defined(UNIX) || defined(VMS) - intron(); + intron(); #endif - reslt = dowhatdoes_core(q, bufr); - if (reslt) - pline1(reslt); - else - pline("I've never heard of such commands."); - return 0; + reslt = dowhatdoes_core(q, bufr); + if (reslt) + pline1(reslt); + else + pline("I've never heard of such commands."); + return 0; } void docontact() { - winid cwin = create_nhwindow(NHW_TEXT); - char buf[BUFSZ]; - if(sysopt.support){ -/*XXX overflow possibilities*/ - Sprintf(buf, "To contact local support, %s", sysopt.support); - putstr(cwin, 0, buf); - putstr(cwin, 0, ""); - } else if(sysopt.wizards){ - char *tmp = build_english_list(sysopt.wizards); - Sprintf(buf, "To contact local support, contact %s.", tmp); - free(tmp); - putstr(cwin, 0, buf); - putstr(cwin, 0, ""); - } - putstr(cwin, 0, "To contact the NetHack development team directly,"); -/*XXX overflow possibilities*/ - Sprintf(buf, "see the Contact form on our website or email %s", - DEVTEAM_EMAIL); - putstr(cwin, 0, buf); - putstr(cwin, 0, ""); - putstr(cwin, 0, "For more information on NetHack, or to report a bug,"); - Sprintf(buf, "visit our website %s", DEVTEAM_URL); - putstr(cwin, 0, buf); - display_nhwindow(cwin, FALSE); - destroy_nhwindow(cwin); + winid cwin = create_nhwindow(NHW_TEXT); + char buf[BUFSZ]; + if (sysopt.support) { + /*XXX overflow possibilities*/ + Sprintf(buf, "To contact local support, %s", sysopt.support); + putstr(cwin, 0, buf); + putstr(cwin, 0, ""); + } else if (sysopt.wizards) { + char *tmp = build_english_list(sysopt.wizards); + Sprintf(buf, "To contact local support, contact %s.", tmp); + free(tmp); + putstr(cwin, 0, buf); + putstr(cwin, 0, ""); + } + putstr(cwin, 0, "To contact the NetHack development team directly,"); + /*XXX overflow possibilities*/ + Sprintf(buf, "see the Contact form on our website or email %s", + DEVTEAM_EMAIL); + putstr(cwin, 0, buf); + putstr(cwin, 0, ""); + putstr(cwin, 0, "For more information on NetHack, or to report a bug,"); + Sprintf(buf, "visit our website %s", DEVTEAM_URL); + putstr(cwin, 0, buf); + display_nhwindow(cwin, FALSE); + destroy_nhwindow(cwin); } /* data for help_menu() */ static const char *help_menu_items[] = { -/* 0*/ "About NetHack (version information).", -/* 1*/ "Long description of the game and commands.", -/* 2*/ "List of game commands.", -/* 3*/ "Concise history of NetHack.", -/* 4*/ "Info on a character in the game display.", -/* 5*/ "Info on what a given key does.", -/* 6*/ "List of game options.", -/* 7*/ "Longer explanation of game options.", -/* 8*/ "List of extended commands.", -/* 9*/ "The NetHack license.", -/* 10*/ "Support information.", + /* 0*/ "About NetHack (version information).", + /* 1*/ "Long description of the game and commands.", + /* 2*/ "List of game commands.", + /* 3*/ "Concise history of NetHack.", + /* 4*/ "Info on a character in the game display.", + /* 5*/ "Info on what a given key does.", + /* 6*/ "List of game options.", + /* 7*/ "Longer explanation of game options.", + /* 8*/ "List of extended commands.", + /* 9*/ "The NetHack license.", + /* 10*/ "Support information.", #ifdef PORT_HELP - "%s-specific help and commands.", + "%s-specific help and commands.", #define PORT_HELP_ID 100 #define WIZHLP_SLOT 12 #else #define WIZHLP_SLOT 11 #endif - "List of wizard-mode commands.", - "", - (char *)0 + "List of wizard-mode commands.", "", (char *) 0 }; STATIC_OVL boolean help_menu(sel) - int *sel; +int *sel; { - winid tmpwin = create_nhwindow(NHW_MENU); + winid tmpwin = create_nhwindow(NHW_MENU); #ifdef PORT_HELP - char helpbuf[QBUFSZ]; + char helpbuf[QBUFSZ]; #endif - int i, n; - menu_item *selected; - anything any; + int i, n; + menu_item *selected; + anything any; - any = zeroany; /* zero all bits */ - start_menu(tmpwin); - if (!wizard) help_menu_items[WIZHLP_SLOT] = "", - help_menu_items[WIZHLP_SLOT+1] = (char *)0; - for (i = 0; help_menu_items[i]; i++) + any = zeroany; /* zero all bits */ + start_menu(tmpwin); + if (!wizard) + help_menu_items[WIZHLP_SLOT] = "", + help_menu_items[WIZHLP_SLOT + 1] = (char *) 0; + for (i = 0; help_menu_items[i]; i++) #ifdef PORT_HELP - /* port-specific line has a %s in it for the PORT_ID */ - if (help_menu_items[i][0] == '%') { - Sprintf(helpbuf, help_menu_items[i], PORT_ID); - any.a_int = PORT_HELP_ID + 1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, - helpbuf, MENU_UNSELECTED); - } else + /* port-specific line has a %s in it for the PORT_ID */ + if (help_menu_items[i][0] == '%') { + Sprintf(helpbuf, help_menu_items[i], PORT_ID); + any.a_int = PORT_HELP_ID + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, helpbuf, + MENU_UNSELECTED); + } else #endif - { - any.a_int = (*help_menu_items[i]) ? i+1 : 0; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, help_menu_items[i], MENU_UNSELECTED); - } - end_menu(tmpwin, "Select one item:"); - n = select_menu(tmpwin, PICK_ONE, &selected); - destroy_nhwindow(tmpwin); - if (n > 0) { - *sel = selected[0].item.a_int - 1; - free((genericptr_t)selected); - return TRUE; - } - return FALSE; + { + any.a_int = (*help_menu_items[i]) ? i + 1 : 0; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + help_menu_items[i], MENU_UNSELECTED); + } + end_menu(tmpwin, "Select one item:"); + n = select_menu(tmpwin, PICK_ONE, &selected); + destroy_nhwindow(tmpwin); + if (n > 0) { + *sel = selected[0].item.a_int - 1; + free((genericptr_t) selected); + return TRUE; + } + return FALSE; } /* the '?' command */ int dohelp() { - int sel = 0; + int sel = 0; - if (help_menu(&sel)) { - switch (sel) { - case 0: (void) doextversion(); break; - case 1: display_file(HELP, TRUE); break; - case 2: display_file(SHELP, TRUE); break; - case 3: (void) dohistory(); break; - case 4: (void) dowhatis(); break; - case 5: (void) dowhatdoes(); break; - case 6: option_help(); break; - case 7: display_file(OPTIONFILE, TRUE); break; - case 8: (void) doextlist(); break; - case 9: display_file(LICENSE, TRUE); break; - case 10: (void) docontact(); break; + if (help_menu(&sel)) { + switch (sel) { + case 0: + (void) doextversion(); + break; + case 1: + display_file(HELP, TRUE); + break; + case 2: + display_file(SHELP, TRUE); + break; + case 3: + (void) dohistory(); + break; + case 4: + (void) dowhatis(); + break; + case 5: + (void) dowhatdoes(); + break; + case 6: + option_help(); + break; + case 7: + display_file(OPTIONFILE, TRUE); + break; + case 8: + (void) doextlist(); + break; + case 9: + display_file(LICENSE, TRUE); + break; + case 10: + (void) docontact(); + break; #ifdef PORT_HELP - case PORT_HELP_ID: port_help(); break; + case PORT_HELP_ID: + port_help(); + break; #endif - default: - /* handle slot 11 or 12 */ - display_file(DEBUGHELP, TRUE); - break; - } - } - return 0; + default: + /* handle slot 11 or 12 */ + display_file(DEBUGHELP, TRUE); + break; + } + } + return 0; } /* the 'V' command; also a choice for '?' */ int dohistory() { - display_file(HISTORY, TRUE); - return 0; + display_file(HISTORY, TRUE); + return 0; } /*pager.c*/ diff --git a/src/pickup.c b/src/pickup.c index 568e940a1..eb8f9dc6d 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pickup.c $NHDT-Date: 1430122768 2015/04/27 08:19:28 $ $NHDT-Branch: master $:$NHDT-Revision: 1.150 $ */ +/* NetHack 3.6 pickup.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.153 $ */ /* NetHack 3.6 pickup.c $Date: 2012/02/16 03:01:38 $ $Revision: 1.123 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,58 +9,61 @@ #include "hack.h" -#define CONTAINED_SYM '>' /* from invent.c */ +#define CONTAINED_SYM '>' /* from invent.c */ -STATIC_DCL void FDECL(simple_look, (struct obj *,BOOLEAN_P)); -STATIC_DCL boolean FDECL(query_classes, (char *,boolean *,boolean *, - const char *,struct obj *,BOOLEAN_P,int *)); -STATIC_DCL boolean FDECL(fatal_corpse_mistake, (struct obj *,BOOLEAN_P)); +STATIC_DCL void FDECL(simple_look, (struct obj *, BOOLEAN_P)); +STATIC_DCL boolean +FDECL(query_classes, (char *, boolean *, boolean *, const char *, + struct obj *, BOOLEAN_P, int *)); +STATIC_DCL boolean FDECL(fatal_corpse_mistake, (struct obj *, BOOLEAN_P)); STATIC_DCL void FDECL(check_here, (BOOLEAN_P)); STATIC_DCL boolean FDECL(n_or_more, (struct obj *)); STATIC_DCL boolean FDECL(all_but_uchain, (struct obj *)); #if 0 /* not used */ STATIC_DCL boolean FDECL(allow_cat_no_uchain, (struct obj *)); #endif -STATIC_DCL int FDECL(autopick, (struct obj*, int, menu_item **)); -STATIC_DCL int FDECL(count_categories, (struct obj *,int)); -STATIC_DCL long FDECL(carry_count, - (struct obj *,struct obj *,long,BOOLEAN_P,int *,int *)); -STATIC_DCL int FDECL(lift_object, (struct obj *,struct obj *,long *,BOOLEAN_P)); -STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *,int)); -STATIC_PTR int FDECL(in_container,(struct obj *)); -STATIC_PTR int FDECL(out_container,(struct obj *)); -STATIC_DCL long FDECL(mbag_item_gone, (int,struct obj *)); +STATIC_DCL int FDECL(autopick, (struct obj *, int, menu_item **)); +STATIC_DCL int FDECL(count_categories, (struct obj *, int)); +STATIC_DCL long FDECL(carry_count, (struct obj *, struct obj *, long, + BOOLEAN_P, int *, int *)); +STATIC_DCL int FDECL(lift_object, + (struct obj *, struct obj *, long *, BOOLEAN_P)); +STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *, int)); +STATIC_PTR int FDECL(in_container, (struct obj *)); +STATIC_PTR int FDECL(out_container, (struct obj *)); +STATIC_DCL long FDECL(mbag_item_gone, (int, struct obj *)); STATIC_DCL void FDECL(observe_quantum_cat, (struct obj *)); STATIC_DCL void NDECL(explain_container_prompt); STATIC_DCL int FDECL(traditional_loot, (BOOLEAN_P)); -STATIC_DCL int FDECL(menu_loot, (int,BOOLEAN_P)); -STATIC_DCL char FDECL(in_or_out_menu, (const char *,struct obj *, - BOOLEAN_P,BOOLEAN_P,BOOLEAN_P)); +STATIC_DCL int FDECL(menu_loot, (int, BOOLEAN_P)); +STATIC_DCL char FDECL(in_or_out_menu, (const char *, struct obj *, BOOLEAN_P, + BOOLEAN_P, BOOLEAN_P)); STATIC_DCL int FDECL(container_at, (int, int, BOOLEAN_P)); -STATIC_DCL boolean FDECL(able_to_loot, (int,int,BOOLEAN_P)); +STATIC_DCL boolean FDECL(able_to_loot, (int, int, BOOLEAN_P)); STATIC_DCL boolean NDECL(reverse_loot); STATIC_DCL boolean FDECL(mon_beside, (int, int)); STATIC_DCL void FDECL(tipcontainer, (struct obj *)); /* define for query_objlist() and autopickup() */ #define FOLLOW(curr, flags) \ - (((flags) & BY_NEXTHERE) ? (curr)->nexthere : (curr)->nobj) + (((flags) &BY_NEXTHERE) ? (curr)->nexthere : (curr)->nobj) /* * How much the weight of the given container will change when the given * object is removed from it. This calculation must match the one used * by weight() in mkobj.c. */ -#define DELTA_CWT(cont,obj) \ - ((cont)->cursed ? (obj)->owt * 2 : \ - (cont)->blessed ? ((obj)->owt + 3) / 4 : ((obj)->owt + 1) / 2) -#define GOLD_WT(n) (((n) + 50L) / 100L) +#define DELTA_CWT(cont, obj) \ + ((cont)->cursed ? (obj)->owt * 2 : (cont)->blessed \ + ? ((obj)->owt + 3) / 4 \ + : ((obj)->owt + 1) / 2) +#define GOLD_WT(n) (((n) + 50L) / 100L) /* if you can figure this out, give yourself a hearty pat on the back... */ -#define GOLD_CAPACITY(w,n) (((w) * -100L) - ((n) + 50L) - 1L) +#define GOLD_CAPACITY(w, n) (((w) * -100L) - ((n) + 50L) - 1L) /* A variable set in use_container(), to be used by the callback routines */ /* in_container() and out_container() from askchain() and use_container(). */ -/* Also used by menu_loot() and container_gone(). */ +/* Also used by menu_loot() and container_gone(). */ static NEARDATA struct obj *current_container; #define Icebox (current_container->otyp == ICE_BOX) @@ -73,27 +76,27 @@ static const char overloadmsg[] = "You have extreme difficulty lifting"; /* much simpler version of the look-here code; used by query_classes() */ STATIC_OVL void simple_look(otmp, here) -struct obj *otmp; /* list of objects */ -boolean here; /* flag for type of obj list linkage */ +struct obj *otmp; /* list of objects */ +boolean here; /* flag for type of obj list linkage */ { - /* Neither of the first two cases is expected to happen, since - * we're only called after multiple classes of objects have been - * detected, hence multiple objects must be present. - */ - if (!otmp) { - impossible("simple_look(null)"); - } else if (!(here ? otmp->nexthere : otmp->nobj)) { - pline1(doname(otmp)); - } else { - winid tmpwin = create_nhwindow(NHW_MENU); - putstr(tmpwin, 0, ""); - do { - putstr(tmpwin, 0, doname(otmp)); - otmp = here ? otmp->nexthere : otmp->nobj; - } while (otmp); - display_nhwindow(tmpwin, TRUE); - destroy_nhwindow(tmpwin); - } + /* Neither of the first two cases is expected to happen, since + * we're only called after multiple classes of objects have been + * detected, hence multiple objects must be present. + */ + if (!otmp) { + impossible("simple_look(null)"); + } else if (!(here ? otmp->nexthere : otmp->nobj)) { + pline1(doname(otmp)); + } else { + winid tmpwin = create_nhwindow(NHW_MENU); + putstr(tmpwin, 0, ""); + do { + putstr(tmpwin, 0, doname(otmp)); + otmp = here ? otmp->nexthere : otmp->nobj; + } while (otmp); + display_nhwindow(tmpwin, TRUE); + destroy_nhwindow(tmpwin); + } } int @@ -101,23 +104,23 @@ collect_obj_classes(ilets, otmp, here, filter, itemcount) char ilets[]; register struct obj *otmp; boolean here; -boolean FDECL((*filter),(OBJ_P)); +boolean FDECL((*filter), (OBJ_P)); int *itemcount; { - register int iletct = 0; - register char c; + register int iletct = 0; + register char c; - *itemcount = 0; - ilets[iletct] = '\0'; /* terminate ilets so that index() will work */ - while (otmp) { - c = def_oc_syms[(int)otmp->oclass].sym; - if (!index(ilets, c) && (!filter || (*filter)(otmp))) - ilets[iletct++] = c, ilets[iletct] = '\0'; - *itemcount += 1; - otmp = here ? otmp->nexthere : otmp->nobj; - } + *itemcount = 0; + ilets[iletct] = '\0'; /* terminate ilets so that index() will work */ + while (otmp) { + c = def_oc_syms[(int) otmp->oclass].sym; + if (!index(ilets, c) && (!filter || (*filter)(otmp))) + ilets[iletct++] = c, ilets[iletct] = '\0'; + *itemcount += 1; + otmp = here ? otmp->nexthere : otmp->nobj; + } - return iletct; + return iletct; } /* @@ -133,8 +136,8 @@ int *itemcount; * (ie, treated as if it had just been "?a"). */ STATIC_OVL boolean -query_classes(oclasses, one_at_a_time, everything, action, objs, - here, menu_on_demand) +query_classes(oclasses, one_at_a_time, everything, action, objs, here, + menu_on_demand) char oclasses[]; boolean *one_at_a_time, *everything; const char *action; @@ -142,97 +145,102 @@ struct obj *objs; boolean here; int *menu_on_demand; { - char ilets[20], inbuf[BUFSZ]; - int iletct, oclassct; - boolean not_everything; - char qbuf[QBUFSZ]; - boolean m_seen; - int itemcount; + char ilets[20], inbuf[BUFSZ]; + int iletct, oclassct; + boolean not_everything; + char qbuf[QBUFSZ]; + boolean m_seen; + int itemcount; - oclasses[oclassct = 0] = '\0'; - *one_at_a_time = *everything = m_seen = FALSE; - iletct = collect_obj_classes(ilets, objs, here, - (boolean FDECL((*),(OBJ_P))) 0, &itemcount); - if (iletct == 0) { - return FALSE; - } else if (iletct == 1) { - oclasses[0] = def_char_to_objclass(ilets[0]); - oclasses[1] = '\0'; - if (itemcount && menu_on_demand) { - ilets[iletct++] = 'm'; - *menu_on_demand = 0; - ilets[iletct] = '\0'; - } - } else { /* more than one choice available */ - const char *where = 0; - register char sym, oc_of_sym, *p; - /* additional choices */ - ilets[iletct++] = ' '; - ilets[iletct++] = 'a'; - ilets[iletct++] = 'A'; - ilets[iletct++] = (objs == invent ? 'i' : ':'); - if (menu_on_demand) { - ilets[iletct++] = 'm'; - *menu_on_demand = 0; - } - ilets[iletct] = '\0'; -ask_again: - oclasses[oclassct = 0] = '\0'; - *one_at_a_time = *everything = FALSE; - not_everything = FALSE; - Sprintf(qbuf,"What kinds of thing do you want to %s? [%s]", - action, ilets); - getlin(qbuf,inbuf); - if (*inbuf == '\033') return FALSE; + oclasses[oclassct = 0] = '\0'; + *one_at_a_time = *everything = m_seen = FALSE; + iletct = collect_obj_classes(ilets, objs, here, + (boolean FDECL((*), (OBJ_P))) 0, &itemcount); + if (iletct == 0) { + return FALSE; + } else if (iletct == 1) { + oclasses[0] = def_char_to_objclass(ilets[0]); + oclasses[1] = '\0'; + if (itemcount && menu_on_demand) { + ilets[iletct++] = 'm'; + *menu_on_demand = 0; + ilets[iletct] = '\0'; + } + } else { /* more than one choice available */ + const char *where = 0; + register char sym, oc_of_sym, *p; + /* additional choices */ + ilets[iletct++] = ' '; + ilets[iletct++] = 'a'; + ilets[iletct++] = 'A'; + ilets[iletct++] = (objs == invent ? 'i' : ':'); + if (menu_on_demand) { + ilets[iletct++] = 'm'; + *menu_on_demand = 0; + } + ilets[iletct] = '\0'; + ask_again: + oclasses[oclassct = 0] = '\0'; + *one_at_a_time = *everything = FALSE; + not_everything = FALSE; + Sprintf(qbuf, "What kinds of thing do you want to %s? [%s]", action, + ilets); + getlin(qbuf, inbuf); + if (*inbuf == '\033') + return FALSE; - for (p = inbuf; (sym = *p++); ) { - /* new A function (selective all) added by GAN 01/09/87 */ - if (sym == ' ') continue; - else if (sym == 'A') *one_at_a_time = TRUE; - else if (sym == 'a') *everything = TRUE; - else if (sym == ':') { - simple_look(objs, here); /* dumb if objs==invent */ - /* if we just scanned the contents of a container - then mark it as having known contents */ - if (objs->where == OBJ_CONTAINED) - objs->ocontainer->cknown = 1; - goto ask_again; - } else if (sym == 'i') { - (void) display_inventory((char *)0, TRUE); - goto ask_again; - } else if (sym == 'm') { - m_seen = TRUE; - } else { - oc_of_sym = def_char_to_objclass(sym); - if (index(ilets,sym)) { - add_valid_menu_class(oc_of_sym); - oclasses[oclassct++] = oc_of_sym; - oclasses[oclassct] = '\0'; - } else { - if (!where) - where = !strcmp(action,"pick up") ? "here" : - !strcmp(action,"take out") ? - "inside" : ""; - if (*where) - There("are no %c's %s.", sym, where); - else - You("have no %c's.", sym); - not_everything = TRUE; - } - } - } - if (m_seen && menu_on_demand) { - *menu_on_demand = (*everything || !oclassct) ? -2 : -3; - return FALSE; - } - if (!oclassct && (!*everything || not_everything)) { - /* didn't pick anything, - or tried to pick something that's not present */ - *one_at_a_time = TRUE; /* force 'A' */ - *everything = FALSE; /* inhibit 'a' */ - } - } - return TRUE; + for (p = inbuf; (sym = *p++);) { + /* new A function (selective all) added by GAN 01/09/87 */ + if (sym == ' ') + continue; + else if (sym == 'A') + *one_at_a_time = TRUE; + else if (sym == 'a') + *everything = TRUE; + else if (sym == ':') { + simple_look(objs, here); /* dumb if objs==invent */ + /* if we just scanned the contents of a container + then mark it as having known contents */ + if (objs->where == OBJ_CONTAINED) + objs->ocontainer->cknown = 1; + goto ask_again; + } else if (sym == 'i') { + (void) display_inventory((char *) 0, TRUE); + goto ask_again; + } else if (sym == 'm') { + m_seen = TRUE; + } else { + oc_of_sym = def_char_to_objclass(sym); + if (index(ilets, sym)) { + add_valid_menu_class(oc_of_sym); + oclasses[oclassct++] = oc_of_sym; + oclasses[oclassct] = '\0'; + } else { + if (!where) + where = + !strcmp(action, "pick up") + ? "here" + : !strcmp(action, "take out") ? "inside" : ""; + if (*where) + There("are no %c's %s.", sym, where); + else + You("have no %c's.", sym); + not_everything = TRUE; + } + } + } + if (m_seen && menu_on_demand) { + *menu_on_demand = (*everything || !oclassct) ? -2 : -3; + return FALSE; + } + if (!oclassct && (!*everything || not_everything)) { + /* didn't pick anything, + or tried to pick something that's not present */ + *one_at_a_time = TRUE; /* force 'A' */ + *everything = FALSE; /* inhibit 'a' */ + } + } + return TRUE; } /* check whether hero is bare-handedly touching a cockatrice corpse */ @@ -241,17 +249,17 @@ fatal_corpse_mistake(obj, remotely) struct obj *obj; boolean remotely; { - if (uarmg || remotely || obj->otyp != CORPSE || - !touch_petrifies(&mons[obj->corpsenm]) || Stone_resistance) - return FALSE; + if (uarmg || remotely || obj->otyp != CORPSE + || !touch_petrifies(&mons[obj->corpsenm]) || Stone_resistance) + return FALSE; if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { - display_nhwindow(WIN_MESSAGE, FALSE); /* --More-- */ - return FALSE; + display_nhwindow(WIN_MESSAGE, FALSE); /* --More-- */ + return FALSE; } pline("Touching %s is a fatal mistake.", - corpse_xname(obj, (const char *)0, CXN_SINGULAR|CXN_ARTICLE)); + corpse_xname(obj, (const char *) 0, CXN_SINGULAR | CXN_ARTICLE)); instapetrify(killer_xname(obj)); return TRUE; } @@ -263,11 +271,11 @@ struct obj *obj; boolean remotely; { if (!obj || obj->otyp != CORPSE || !is_rider(&mons[obj->corpsenm])) - return FALSE; + return FALSE; pline("At your %s, the corpse suddenly moves...", - remotely ? "attempted acquisition" : "touch"); - (void)revive_corpse(obj); + remotely ? "attempted acquisition" : "touch"); + (void) revive_corpse(obj); exercise(A_WIS, FALSE); return TRUE; } @@ -277,23 +285,24 @@ STATIC_OVL void check_here(picked_some) boolean picked_some; { - register struct obj *obj; - register int ct = 0; + register struct obj *obj; + register int ct = 0; - /* count the objects here */ - for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere) { - if (obj != uchain) - ct++; - } + /* count the objects here */ + for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere) { + if (obj != uchain) + ct++; + } - /* If there are objects here, take a look. */ - if (ct) { - if (context.run) nomul(0); - flush_screen(1); - (void) look_here(ct, picked_some); - } else { - read_engr_at(u.ux,u.uy); - } + /* If there are objects here, take a look. */ + if (ct) { + if (context.run) + nomul(0); + flush_screen(1); + (void) look_here(ct, picked_some); + } else { + read_engr_at(u.ux, u.uy); + } } /* Value set by query_objlist() for n_or_more(). */ @@ -304,7 +313,8 @@ STATIC_OVL boolean n_or_more(obj) struct obj *obj; { - if (obj == uchain) return FALSE; + if (obj == uchain) + return FALSE; return (obj->quan >= val_for_n_or_more); } @@ -317,22 +327,30 @@ void add_valid_menu_class(c) int c; { - static int vmc_count = 0; + static int vmc_count = 0; - if (c == 0) { /* reset */ - vmc_count = 0; - class_filter = bucx_filter = shop_filter = FALSE; - } else { - valid_menu_classes[vmc_count++] = (char)c; - /* categorize the new class */ - switch (c) { - case 'B': case 'U': case 'C': /*FALLTHRU*/ - case 'X': bucx_filter = TRUE; break; - case 'u': shop_filter = TRUE; break; - default: class_filter = TRUE; break; - } - } - valid_menu_classes[vmc_count] = '\0'; + if (c == 0) { /* reset */ + vmc_count = 0; + class_filter = bucx_filter = shop_filter = FALSE; + } else { + valid_menu_classes[vmc_count++] = (char) c; + /* categorize the new class */ + switch (c) { + case 'B': + case 'U': + case 'C': /*FALLTHRU*/ + case 'X': + bucx_filter = TRUE; + break; + case 'u': + shop_filter = TRUE; + break; + default: + class_filter = TRUE; + break; + } + } + valid_menu_classes[vmc_count] = '\0'; } /* query_objlist callback: return TRUE if not uchain */ @@ -358,9 +376,10 @@ struct obj *obj; { /* unpaid and BUC checks don't apply to coins */ if (obj->oclass == COIN_CLASS) - return index(valid_menu_classes, COIN_CLASS) ? TRUE : FALSE; + return index(valid_menu_classes, COIN_CLASS) ? TRUE : FALSE; - if (Role_if(PM_PRIEST)) obj->bknown = TRUE; + if (Role_if(PM_PRIEST)) + obj->bknown = TRUE; /* * There are three types of filters possible and the first and * third can have more than one entry: @@ -379,21 +398,21 @@ struct obj *obj; */ /* if class is expected but obj's class is not in the list, reject */ if (class_filter && !index(valid_menu_classes, obj->oclass)) - return FALSE; + return FALSE; /* if unpaid is expected and obj isn't unpaid, reject (treat a container holding any unpaid object as unpaid even if isn't unpaid itself) */ if (shop_filter && !obj->unpaid - && !(Has_contents(obj) && count_unpaid(obj) > 0)) - return FALSE; + && !(Has_contents(obj) && count_unpaid(obj) > 0)) + return FALSE; /* check for particular bless/curse state */ if (bucx_filter) { - /* first categorize this object's bless/curse state */ - char bucx = !obj->bknown ? 'X' - : obj->blessed ? 'B' : obj->cursed ? 'C' : 'U'; + /* first categorize this object's bless/curse state */ + char bucx = + !obj->bknown ? 'X' : obj->blessed ? 'B' : obj->cursed ? 'C' : 'U'; - /* if its category is not in the list, reject */ - if (!index(valid_menu_classes, bucx)) - return FALSE; + /* if its category is not in the list, reject */ + if (!index(valid_menu_classes, bucx)) + return FALSE; } /* obj didn't fail any of the filter checks, so accept */ return TRUE; @@ -419,9 +438,9 @@ boolean is_worn_by_type(otmp) register struct obj *otmp; { - return((boolean)(!!(otmp->owornmask & - (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_WEP | W_SWAPWEP | W_QUIVER))) - && (index(valid_menu_classes, otmp->oclass) != (char *)0)); + return ((boolean)(!!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL + | W_WEP | W_SWAPWEP | W_QUIVER))) + && (index(valid_menu_classes, otmp->oclass) != (char *) 0)); } /* @@ -438,229 +457,243 @@ register struct obj *otmp; */ int pickup(what) -int what; /* should be a long */ +int what; /* should be a long */ { - int i, n, res, count, n_tried = 0, n_picked = 0; - menu_item *pick_list = (menu_item *) 0; - boolean autopickup = what > 0; - struct obj *objchain; - int traverse_how; + int i, n, res, count, n_tried = 0, n_picked = 0; + menu_item *pick_list = (menu_item *) 0; + boolean autopickup = what > 0; + struct obj *objchain; + int traverse_how; - /* we might have arrived here while fainted or sleeping, via - random teleport or levitation timeout; if so, skip check_here - and read_engr_at in addition to bypassing autopickup itself - [probably ought to check whether hero is using a cockatrice - corpse for a pillow here... (also at initial faint/sleep)] */ - if (autopickup && multi < 0 && unconscious()) return 0; + /* we might have arrived here while fainted or sleeping, via + random teleport or levitation timeout; if so, skip check_here + and read_engr_at in addition to bypassing autopickup itself + [probably ought to check whether hero is using a cockatrice + corpse for a pillow here... (also at initial faint/sleep)] */ + if (autopickup && multi < 0 && unconscious()) + return 0; - if (what < 0) /* pick N of something */ - count = -what; - else /* pick anything */ - count = 0; + if (what < 0) /* pick N of something */ + count = -what; + else /* pick anything */ + count = 0; - if (!u.uswallow) { - struct trap *ttmp = t_at(u.ux, u.uy); - /* no auto-pick if no-pick move, nothing there, or in a pool */ - if (autopickup && (context.nopick || !OBJ_AT(u.ux, u.uy) || - (is_pool(u.ux, u.uy) && !Underwater) || is_lava(u.ux, u.uy))) { - read_engr_at(u.ux, u.uy); - return (0); - } + if (!u.uswallow) { + struct trap *ttmp = t_at(u.ux, u.uy); + /* no auto-pick if no-pick move, nothing there, or in a pool */ + if (autopickup && (context.nopick || !OBJ_AT(u.ux, u.uy) + || (is_pool(u.ux, u.uy) && !Underwater) + || is_lava(u.ux, u.uy))) { + read_engr_at(u.ux, u.uy); + return (0); + } - /* no pickup if levitating & not on air or water level */ - if (!can_reach_floor(TRUE)) { - if ((multi && !context.run) || - (autopickup && !flags.pickup) || - (ttmp && uteetering_at_seen_pit(ttmp))) - read_engr_at(u.ux, u.uy); - return (0); - } - /* multi && !context.run means they are in the middle of some other - * action, or possibly paralyzed, sleeping, etc.... and they just - * teleported onto the object. They shouldn't pick it up. - */ - if ((multi && !context.run) || (autopickup && !flags.pickup)) { - check_here(FALSE); - return (0); - } - if (notake(youmonst.data)) { - if (!autopickup) - You("are physically incapable of picking anything up."); - else - check_here(FALSE); - return (0); - } + /* no pickup if levitating & not on air or water level */ + if (!can_reach_floor(TRUE)) { + if ((multi && !context.run) || (autopickup && !flags.pickup) + || (ttmp && uteetering_at_seen_pit(ttmp))) + read_engr_at(u.ux, u.uy); + return (0); + } + /* multi && !context.run means they are in the middle of some other + * action, or possibly paralyzed, sleeping, etc.... and they just + * teleported onto the object. They shouldn't pick it up. + */ + if ((multi && !context.run) || (autopickup && !flags.pickup)) { + check_here(FALSE); + return (0); + } + if (notake(youmonst.data)) { + if (!autopickup) + You("are physically incapable of picking anything up."); + else + check_here(FALSE); + return (0); + } - /* if there's anything here, stop running */ - if (OBJ_AT(u.ux,u.uy) && context.run && context.run != 8 && !context.nopick) nomul(0); - } + /* if there's anything here, stop running */ + if (OBJ_AT(u.ux, u.uy) && context.run && context.run != 8 + && !context.nopick) + nomul(0); + } - add_valid_menu_class(0); /* reset */ - if (!u.uswallow) { - objchain = level.objects[u.ux][u.uy]; - traverse_how = BY_NEXTHERE; - } else { - objchain = u.ustuck->minvent; - traverse_how = 0; /* nobj */ - } - /* - * Start the actual pickup process. This is split into two main - * sections, the newer menu and the older "traditional" methods. - * Automatic pickup has been split into its own menu-style routine - * to make things less confusing. - */ - if (autopickup) { - n = autopick(objchain, traverse_how, &pick_list); - goto menu_pickup; - } + add_valid_menu_class(0); /* reset */ + if (!u.uswallow) { + objchain = level.objects[u.ux][u.uy]; + traverse_how = BY_NEXTHERE; + } else { + objchain = u.ustuck->minvent; + traverse_how = 0; /* nobj */ + } + /* + * Start the actual pickup process. This is split into two main + * sections, the newer menu and the older "traditional" methods. + * Automatic pickup has been split into its own menu-style routine + * to make things less confusing. + */ + if (autopickup) { + n = autopick(objchain, traverse_how, &pick_list); + goto menu_pickup; + } - if (flags.menu_style != MENU_TRADITIONAL || iflags.menu_requested) { + if (flags.menu_style != MENU_TRADITIONAL || iflags.menu_requested) { + /* use menus exclusively */ + if (count) { /* looking for N of something */ + char buf[QBUFSZ]; + Sprintf(buf, "Pick %d of what?", count); + val_for_n_or_more = count; /* set up callback selector */ + n = query_objlist(buf, objchain, traverse_how | AUTOSELECT_SINGLE + | INVORDER_SORT, + &pick_list, PICK_ONE, n_or_more); + /* correct counts, if any given */ + for (i = 0; i < n; i++) + pick_list[i].count = count; + } else { + n = query_objlist("Pick up what?", objchain, + traverse_how | AUTOSELECT_SINGLE | INVORDER_SORT + | FEEL_COCKATRICE, + &pick_list, PICK_ANY, all_but_uchain); + } + menu_pickup: + n_tried = n; + for (n_picked = i = 0; i < n; i++) { + res = pickup_object(pick_list[i].item.a_obj, pick_list[i].count, + FALSE); + if (res < 0) + break; /* can't continue */ + n_picked += res; + } + if (pick_list) + free((genericptr_t) pick_list); - /* use menus exclusively */ - if (count) { /* looking for N of something */ - char buf[QBUFSZ]; - Sprintf(buf, "Pick %d of what?", count); - val_for_n_or_more = count; /* set up callback selector */ - n = query_objlist(buf, objchain, - traverse_how|AUTOSELECT_SINGLE|INVORDER_SORT, - &pick_list, PICK_ONE, n_or_more); - /* correct counts, if any given */ - for (i = 0; i < n; i++) - pick_list[i].count = count; - } else { - n = query_objlist("Pick up what?", objchain, - traverse_how|AUTOSELECT_SINGLE|INVORDER_SORT|FEEL_COCKATRICE, - &pick_list, PICK_ANY, all_but_uchain); - } -menu_pickup: - n_tried = n; - for (n_picked = i = 0 ; i < n; i++) { - res = pickup_object(pick_list[i].item.a_obj,pick_list[i].count, - FALSE); - if (res < 0) break; /* can't continue */ - n_picked += res; - } - if (pick_list) free((genericptr_t)pick_list); + } else { + /* old style interface */ + int ct = 0; + long lcount; + boolean all_of_a_type, selective; + char oclasses[MAXOCLASSES]; + struct obj *obj, *obj2; - } else { - /* old style interface */ - int ct = 0; - long lcount; - boolean all_of_a_type, selective; - char oclasses[MAXOCLASSES]; - struct obj *obj, *obj2; + oclasses[0] = '\0'; /* types to consider (empty for all) */ + all_of_a_type = TRUE; /* take all of considered types */ + selective = FALSE; /* ask for each item */ - oclasses[0] = '\0'; /* types to consider (empty for all) */ - all_of_a_type = TRUE; /* take all of considered types */ - selective = FALSE; /* ask for each item */ + /* check for more than one object */ + for (obj = objchain; obj; + obj = (traverse_how == BY_NEXTHERE) ? obj->nexthere : obj->nobj) + ct++; - /* check for more than one object */ - for (obj = objchain; - obj; obj = (traverse_how == BY_NEXTHERE) ? obj->nexthere : obj->nobj) - ct++; + if (ct == 1 && count) { + /* if only one thing, then pick it */ + obj = objchain; + lcount = min(obj->quan, (long) count); + n_tried++; + if (pickup_object(obj, lcount, FALSE) > 0) + n_picked++; /* picked something */ + goto end_query; - if (ct == 1 && count) { - /* if only one thing, then pick it */ - obj = objchain; - lcount = min(obj->quan, (long)count); - n_tried++; - if (pickup_object(obj, lcount, FALSE) > 0) - n_picked++; /* picked something */ - goto end_query; + } else if (ct >= 2) { + int via_menu = 0; - } else if (ct >= 2) { - int via_menu = 0; + There("are %s objects here.", (ct <= 10) ? "several" : "many"); + if (!query_classes(oclasses, &selective, &all_of_a_type, + "pick up", objchain, + traverse_how == BY_NEXTHERE, &via_menu)) { + if (!via_menu) + return (0); + n = query_objlist( + "Pick up what?", objchain, + traverse_how | (selective ? 0 : INVORDER_SORT), + &pick_list, PICK_ANY, + via_menu == -2 ? allow_all : allow_category); + goto menu_pickup; + } + } - There("are %s objects here.", - (ct <= 10) ? "several" : "many"); - if (!query_classes(oclasses, &selective, &all_of_a_type, - "pick up", objchain, - traverse_how == BY_NEXTHERE, - &via_menu)) { - if (!via_menu) return (0); - n = query_objlist("Pick up what?", - objchain, - traverse_how|(selective ? 0 : INVORDER_SORT), - &pick_list, PICK_ANY, - via_menu == -2 ? allow_all : allow_category); - goto menu_pickup; - } - } + for (obj = objchain; obj; obj = obj2) { + if (traverse_how == BY_NEXTHERE) + obj2 = obj->nexthere; /* perhaps obj will be picked up */ + else + obj2 = obj->nobj; + lcount = -1L; - for (obj = objchain; obj; obj = obj2) { - if (traverse_how == BY_NEXTHERE) - obj2 = obj->nexthere; /* perhaps obj will be picked up */ - else - obj2 = obj->nobj; - lcount = -1L; + if (!selective && oclasses[0] && !index(oclasses, obj->oclass)) + continue; - if (!selective && oclasses[0] && !index(oclasses,obj->oclass)) - continue; + if (!all_of_a_type) { + char qbuf[BUFSZ]; - if (!all_of_a_type) { - char qbuf[BUFSZ]; + (void) safe_qbuf(qbuf, "Pick up ", "?", obj, doname, + ansimpleoname, something); + switch ((obj->quan < 2L) ? ynaq(qbuf) : ynNaq(qbuf)) { + case 'q': + goto end_query; /* out 2 levels */ + case 'n': + continue; + case 'a': + all_of_a_type = TRUE; + if (selective) { + selective = FALSE; + oclasses[0] = obj->oclass; + oclasses[1] = '\0'; + } + break; + case '#': /* count was entered */ + if (!yn_number) + continue; /* 0 count => No */ + lcount = (long) yn_number; + if (lcount > obj->quan) + lcount = obj->quan; + /* fall thru */ + default: /* 'y' */ + break; + } + } + if (lcount == -1L) + lcount = obj->quan; - (void)safe_qbuf(qbuf, "Pick up ", "?", - obj, doname, ansimpleoname, something); - switch ((obj->quan < 2L) ? ynaq(qbuf) : ynNaq(qbuf)) { - case 'q': goto end_query; /* out 2 levels */ - case 'n': continue; - case 'a': - all_of_a_type = TRUE; - if (selective) { - selective = FALSE; - oclasses[0] = obj->oclass; - oclasses[1] = '\0'; - } - break; - case '#': /* count was entered */ - if (!yn_number) continue; /* 0 count => No */ - lcount = (long) yn_number; - if (lcount > obj->quan) lcount = obj->quan; - /* fall thru */ - default: /* 'y' */ - break; - } - } - if (lcount == -1L) lcount = obj->quan; + n_tried++; + if ((res = pickup_object(obj, lcount, FALSE)) < 0) + break; + n_picked += res; + } + end_query: + ; /* semicolon needed by brain-damaged compilers */ + } - n_tried++; - if ((res = pickup_object(obj, lcount, FALSE)) < 0) break; - n_picked += res; - } -end_query: - ; /* semicolon needed by brain-damaged compilers */ - } + if (!u.uswallow) { + if (hides_under(youmonst.data)) + (void) hideunder(&youmonst); - if (!u.uswallow) { - if (hides_under(youmonst.data)) (void) hideunder(&youmonst); + /* position may need updating (invisible hero) */ + if (n_picked) + newsym(u.ux, u.uy); - /* position may need updating (invisible hero) */ - if (n_picked) newsym(u.ux,u.uy); - - /* check if there's anything else here after auto-pickup is done */ - if (autopickup) check_here(n_picked > 0); - } - return (n_tried > 0); + /* check if there's anything else here after auto-pickup is done */ + if (autopickup) + check_here(n_picked > 0); + } + return (n_tried > 0); } boolean is_autopickup_exception(obj, grab) struct obj *obj; -boolean grab; /* forced pickup, rather than forced leave behind? */ +boolean grab; /* forced pickup, rather than forced leave behind? */ { - /* - * Does the text description of this match an exception? - */ - char *objdesc = makesingular(doname(obj)); - struct autopickup_exception *ape = (grab) ? - iflags.autopickup_exceptions[AP_GRAB] : - iflags.autopickup_exceptions[AP_LEAVE]; - while (ape) { - if (pmatch(ape->pattern, objdesc)) return TRUE; - ape = ape->next; - } - return FALSE; + /* + * Does the text description of this match an exception? + */ + char *objdesc = makesingular(doname(obj)); + struct autopickup_exception *ape = + (grab) ? iflags.autopickup_exceptions[AP_GRAB] + : iflags.autopickup_exceptions[AP_LEAVE]; + while (ape) { + if (pmatch(ape->pattern, objdesc)) + return TRUE; + ape = ape->next; + } + return FALSE; } /* @@ -672,47 +705,53 @@ boolean grab; /* forced pickup, rather than forced leave behind? */ */ STATIC_OVL int autopick(olist, follow, pick_list) -struct obj *olist; /* the object list */ -int follow; /* how to follow the object list */ -menu_item **pick_list; /* list of objects and counts to pick up */ +struct obj *olist; /* the object list */ +int follow; /* how to follow the object list */ +menu_item **pick_list; /* list of objects and counts to pick up */ { - menu_item *pi; /* pick item */ - struct obj *curr; - int n; - boolean pickit; - const char *otypes = flags.pickup_types; + menu_item *pi; /* pick item */ + struct obj *curr; + int n; + boolean pickit; + const char *otypes = flags.pickup_types; - /* first count the number of eligible items */ - for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) { - pickit = (!*otypes || index(otypes, curr->oclass)); - /* check for "always pick up */ - if (!pickit) pickit = is_autopickup_exception(curr, TRUE); - /* then for "never pick up */ - if (pickit) pickit = !is_autopickup_exception(curr, FALSE); - /* pickup_thrown overrides pickup_types and exceptions */ - if (!pickit) pickit = (flags.pickup_thrown && curr->was_thrown); - /* finally, do we count this object? */ - if (pickit) ++n; - } + /* first count the number of eligible items */ + for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) { + pickit = (!*otypes || index(otypes, curr->oclass)); + /* check for "always pick up */ + if (!pickit) + pickit = is_autopickup_exception(curr, TRUE); + /* then for "never pick up */ + if (pickit) + pickit = !is_autopickup_exception(curr, FALSE); + /* pickup_thrown overrides pickup_types and exceptions */ + if (!pickit) + pickit = (flags.pickup_thrown && curr->was_thrown); + /* finally, do we count this object? */ + if (pickit) + ++n; + } - if (n) { - *pick_list = pi = (menu_item *) alloc(sizeof(menu_item) * n); - for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) { - pickit = (!*otypes || index(otypes, curr->oclass)); - if (!pickit) pickit = is_autopickup_exception(curr, TRUE); - if (pickit) pickit = !is_autopickup_exception(curr, FALSE); - if (!pickit) pickit = (flags.pickup_thrown && curr->was_thrown); - if (pickit) { - pi[n].item.a_obj = curr; - pi[n].count = curr->quan; - n++; - } - } - } - return n; + if (n) { + *pick_list = pi = (menu_item *) alloc(sizeof(menu_item) * n); + for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) { + pickit = (!*otypes || index(otypes, curr->oclass)); + if (!pickit) + pickit = is_autopickup_exception(curr, TRUE); + if (pickit) + pickit = !is_autopickup_exception(curr, FALSE); + if (!pickit) + pickit = (flags.pickup_thrown && curr->was_thrown); + if (pickit) { + pi[n].item.a_obj = curr; + pi[n].count = curr->quan; + n++; + } + } + } + return n; } - /* * Put up a menu using the given object list. Only those objects on the * list that meet the approval of the allow function are displayed. Return @@ -733,156 +772,159 @@ menu_item **pick_list; /* list of objects and counts to pick up */ */ int query_objlist(qstr, olist, qflags, pick_list, how, allow) -const char *qstr; /* query string */ -struct obj *olist; /* the list to pick from */ -int qflags; /* options to control the query */ -menu_item **pick_list; /* return list of items picked */ -int how; /* type of query */ -boolean FDECL((*allow), (OBJ_P));/* allow function */ +const char *qstr; /* query string */ +struct obj *olist; /* the list to pick from */ +int qflags; /* options to control the query */ +menu_item **pick_list; /* return list of items picked */ +int how; /* type of query */ +boolean FDECL((*allow), (OBJ_P)); /* allow function */ { - int i, n, actualn; - winid win; - struct obj *curr, *last, fake_hero_object; - struct obj **oarray; - char *pack; - anything any; - boolean printed_type_name, - sorted = (qflags & INVORDER_SORT) != 0, - engulfer = (qflags & INCLUDE_HERO) != 0; + int i, n, actualn; + winid win; + struct obj *curr, *last, fake_hero_object; + struct obj **oarray; + char *pack; + anything any; + boolean printed_type_name, sorted = (qflags & INVORDER_SORT) != 0, + engulfer = (qflags & INCLUDE_HERO) != 0; - *pick_list = (menu_item *) 0; - if (!olist && !engulfer) return 0; + *pick_list = (menu_item *) 0; + if (!olist && !engulfer) + return 0; - /* count the number of items allowed */ - for (n = 0, last = 0, curr = olist; curr; curr = FOLLOW(curr, qflags)) - if ((*allow)(curr)) { - last = curr; - n++; - } - actualn = n; - if (engulfer) { - ++n; - /* don't autoselect swallowed hero if it's the only choice */ - qflags &= ~AUTOSELECT_SINGLE; - } + /* count the number of items allowed */ + for (n = 0, last = 0, curr = olist; curr; curr = FOLLOW(curr, qflags)) + if ((*allow)(curr)) { + last = curr; + n++; + } + actualn = n; + if (engulfer) { + ++n; + /* don't autoselect swallowed hero if it's the only choice */ + qflags &= ~AUTOSELECT_SINGLE; + } - if (n == 0) /* nothing to pick here */ - return (qflags & SIGNAL_NOMENU) ? -1 : 0; + if (n == 0) /* nothing to pick here */ + return (qflags & SIGNAL_NOMENU) ? -1 : 0; - if (n == 1 && (qflags & AUTOSELECT_SINGLE)) { - *pick_list = (menu_item *) alloc(sizeof(menu_item)); - (*pick_list)->item.a_obj = last; - (*pick_list)->count = last->quan; - return 1; - } + if (n == 1 && (qflags & AUTOSELECT_SINGLE)) { + *pick_list = (menu_item *) alloc(sizeof(menu_item)); + (*pick_list)->item.a_obj = last; + (*pick_list)->count = last->quan; + return 1; + } - oarray = objarr_init(actualn); - /* Add objects to the array */ - i = 0; - for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { - if ((*allow)(curr)) { - objarr_set(curr, i++, oarray, (flags.sortloot == 'f' || - (flags.sortloot == 'l' && !(qflags & USE_INVLET)))); - } - } + oarray = objarr_init(actualn); + /* Add objects to the array */ + i = 0; + for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { + if ((*allow)(curr)) { + objarr_set(curr, i++, oarray, (flags.sortloot == 'f' + || (flags.sortloot == 'l' + && !(qflags & USE_INVLET)))); + } + } - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; - /* - * Run through the list and add the objects to the menu. If - * INVORDER_SORT is set, we'll run through the list once for - * each type so we can group them. The allow function will only - * be called once per object in the list. - */ - pack = flags.inv_order; - do { - printed_type_name = FALSE; - for (i = 0; i < actualn; i++) { - curr = oarray[i]; - if ((qflags & FEEL_COCKATRICE) && curr->otyp == CORPSE && - will_feel_cockatrice(curr, FALSE)) { - destroy_nhwindow(win); /* stop the menu and revert */ - (void) look_here(0, FALSE); - return 0; - } - if ((!sorted || curr->oclass == *pack) && (*allow)(curr)) { + /* + * Run through the list and add the objects to the menu. If + * INVORDER_SORT is set, we'll run through the list once for + * each type so we can group them. The allow function will only + * be called once per object in the list. + */ + pack = flags.inv_order; + do { + printed_type_name = FALSE; + for (i = 0; i < actualn; i++) { + curr = oarray[i]; + if ((qflags & FEEL_COCKATRICE) && curr->otyp == CORPSE + && will_feel_cockatrice(curr, FALSE)) { + destroy_nhwindow(win); /* stop the menu and revert */ + (void) look_here(0, FALSE); + return 0; + } + if ((!sorted || curr->oclass == *pack) && (*allow)(curr)) { + /* if sorting, print type name (once only) */ + if (sorted && !printed_type_name) { + any = zeroany; + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + let_to_name(*pack, FALSE, + (how != PICK_NONE) + && iflags.menu_head_objsym), + MENU_UNSELECTED); + printed_type_name = TRUE; + } - /* if sorting, print type name (once only) */ - if (sorted && !printed_type_name) { - any = zeroany; - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - let_to_name(*pack, FALSE, - (how != PICK_NONE) && iflags.menu_head_objsym), - MENU_UNSELECTED); - printed_type_name = TRUE; - } + any.a_obj = curr; + add_menu(win, obj_to_glyph(curr), &any, + (qflags & USE_INVLET) ? curr->invlet : 0, + def_oc_syms[(int) objects[curr->otyp].oc_class].sym, + ATR_NONE, doname(curr), MENU_UNSELECTED); + } + } + pack++; + } while (sorted && *pack); + free(oarray); - any.a_obj = curr; - add_menu(win, obj_to_glyph(curr), &any, - (qflags & USE_INVLET) ? curr->invlet : 0, - def_oc_syms[(int)objects[curr->otyp].oc_class].sym, - ATR_NONE, doname(curr), MENU_UNSELECTED); - } - } - pack++; - } while (sorted && *pack); - free(oarray); + if (engulfer) { + char buf[BUFSZ]; - if (engulfer) { - char buf[BUFSZ]; + any = zeroany; + if (sorted && n > 1) { + Sprintf(buf, "%s Creatures", + is_animal(u.ustuck->data) ? "Swallowed" : "Engulfed"); + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, + MENU_UNSELECTED); + } + fake_hero_object = zeroobj; + fake_hero_object.quan = 1L; /* not strictly necessary... */ + any.a_obj = &fake_hero_object; + add_menu(win, mon_to_glyph(&youmonst), &any, + /* fake inventory letter, no group accelerator */ + CONTAINED_SYM, 0, ATR_NONE, an(self_lookat(buf)), + MENU_UNSELECTED); + } - any = zeroany; - if (sorted && n > 1) { - Sprintf(buf, "%s Creatures", - is_animal(u.ustuck->data) ? "Swallowed" : "Engulfed"); - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - buf, MENU_UNSELECTED); - } - fake_hero_object = zeroobj; - fake_hero_object.quan = 1L; /* not strictly necessary... */ - any.a_obj = &fake_hero_object; - add_menu(win, mon_to_glyph(&youmonst), &any, - /* fake inventory letter, no group accelerator */ - CONTAINED_SYM, 0, - ATR_NONE, an(self_lookat(buf)), MENU_UNSELECTED); - } + end_menu(win, qstr); + n = select_menu(win, how, pick_list); + destroy_nhwindow(win); - end_menu(win, qstr); - n = select_menu(win, how, pick_list); - destroy_nhwindow(win); + if (n > 0) { + menu_item *mi; + int k; - if (n > 0) { - menu_item *mi; - int k; - - /* fix up counts: -1 means no count used => pick all; - if fake_hero_object was picked, discard that choice */ - for (i = k = 0, mi = *pick_list; i < n; i++, mi++) { - if (mi->item.a_obj == &fake_hero_object) continue; - if (mi->count == -1L || mi->count > mi->item.a_obj->quan) - mi->count = mi->item.a_obj->quan; - if (k < i) (*pick_list)[k] = *mi; - ++k; - } - if (!k) { - /* fake_hero was only choice so discard whole list */ - free((genericptr_t) *pick_list); - *pick_list = 0; - n = 0; - } else if (k < n) { - /* other stuff plus fake_hero; last slot is now unused */ - (*pick_list)[k].item = zeroany; - (*pick_list)[k].count = 0L; - n = k; - } - } else if (n < 0) { - /* -1 is used for SIGNAL_NOMENU, so callers don't expect it - to indicate that the player declined to make a choice */ - n = (qflags & SIGNAL_ESCAPE) ? -2 : 0; - } - return n; + /* fix up counts: -1 means no count used => pick all; + if fake_hero_object was picked, discard that choice */ + for (i = k = 0, mi = *pick_list; i < n; i++, mi++) { + if (mi->item.a_obj == &fake_hero_object) + continue; + if (mi->count == -1L || mi->count > mi->item.a_obj->quan) + mi->count = mi->item.a_obj->quan; + if (k < i) + (*pick_list)[k] = *mi; + ++k; + } + if (!k) { + /* fake_hero was only choice so discard whole list */ + free((genericptr_t) *pick_list); + *pick_list = 0; + n = 0; + } else if (k < n) { + /* other stuff plus fake_hero; last slot is now unused */ + (*pick_list)[k].item = zeroany; + (*pick_list)[k].count = 0L; + n = k; + } + } else if (n < 0) { + /* -1 is used for SIGNAL_NOMENU, so callers don't expect it + to indicate that the player declined to make a choice */ + n = (qflags & SIGNAL_ESCAPE) ? -2 : 0; + } + return n; } /* @@ -891,165 +933,169 @@ boolean FDECL((*allow), (OBJ_P));/* allow function */ */ int query_category(qstr, olist, qflags, pick_list, how) -const char *qstr; /* query string */ -struct obj *olist; /* the list to pick from */ -int qflags; /* behaviour modification flags */ -menu_item **pick_list; /* return list of items picked */ -int how; /* type of query */ +const char *qstr; /* query string */ +struct obj *olist; /* the list to pick from */ +int qflags; /* behaviour modification flags */ +menu_item **pick_list; /* return list of items picked */ +int how; /* type of query */ { - int n; - winid win; - struct obj *curr; - char *pack; - anything any; - boolean collected_type_name; - char invlet; - int ccount; - boolean do_unpaid = FALSE; - boolean do_blessed = FALSE, do_cursed = FALSE, do_uncursed = FALSE, - do_buc_unknown = FALSE; - int num_buc_types = 0; + int n; + winid win; + struct obj *curr; + char *pack; + anything any; + boolean collected_type_name; + char invlet; + int ccount; + boolean do_unpaid = FALSE; + boolean do_blessed = FALSE, do_cursed = FALSE, do_uncursed = FALSE, + do_buc_unknown = FALSE; + int num_buc_types = 0; - *pick_list = (menu_item *) 0; - if (!olist) return 0; - if ((qflags & UNPAID_TYPES) && count_unpaid(olist)) do_unpaid = TRUE; - if ((qflags & BUC_BLESSED) && count_buc(olist, BUC_BLESSED)) { - do_blessed = TRUE; - num_buc_types++; - } - if ((qflags & BUC_CURSED) && count_buc(olist, BUC_CURSED)) { - do_cursed = TRUE; - num_buc_types++; - } - if ((qflags & BUC_UNCURSED) && count_buc(olist, BUC_UNCURSED)) { - do_uncursed = TRUE; - num_buc_types++; - } - if ((qflags & BUC_UNKNOWN) && count_buc(olist, BUC_UNKNOWN)) { - do_buc_unknown = TRUE; - num_buc_types++; - } + *pick_list = (menu_item *) 0; + if (!olist) + return 0; + if ((qflags & UNPAID_TYPES) && count_unpaid(olist)) + do_unpaid = TRUE; + if ((qflags & BUC_BLESSED) && count_buc(olist, BUC_BLESSED)) { + do_blessed = TRUE; + num_buc_types++; + } + if ((qflags & BUC_CURSED) && count_buc(olist, BUC_CURSED)) { + do_cursed = TRUE; + num_buc_types++; + } + if ((qflags & BUC_UNCURSED) && count_buc(olist, BUC_UNCURSED)) { + do_uncursed = TRUE; + num_buc_types++; + } + if ((qflags & BUC_UNKNOWN) && count_buc(olist, BUC_UNKNOWN)) { + do_buc_unknown = TRUE; + num_buc_types++; + } - ccount = count_categories(olist, qflags); - /* no point in actually showing a menu for a single category */ - if (ccount == 1 && !do_unpaid && num_buc_types <= 1 && !(qflags & BILLED_TYPES)) { - for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { - if ((qflags & WORN_TYPES) && - !(curr->owornmask & (W_ARMOR|W_RING|W_AMUL|W_TOOL|W_WEP|W_SWAPWEP|W_QUIVER))) - continue; - break; - } - if (curr) { - *pick_list = (menu_item *) alloc(sizeof(menu_item)); - (*pick_list)->item.a_int = curr->oclass; - return 1; - } else { - debugpline0("query_category: no single object match"); - } - return 0; - } + ccount = count_categories(olist, qflags); + /* no point in actually showing a menu for a single category */ + if (ccount == 1 && !do_unpaid && num_buc_types <= 1 + && !(qflags & BILLED_TYPES)) { + for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { + if ((qflags & WORN_TYPES) + && !(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL + | W_WEP | W_SWAPWEP | W_QUIVER))) + continue; + break; + } + if (curr) { + *pick_list = (menu_item *) alloc(sizeof(menu_item)); + (*pick_list)->item.a_int = curr->oclass; + return 1; + } else { + debugpline0("query_category: no single object match"); + } + return 0; + } - win = create_nhwindow(NHW_MENU); - start_menu(win); - pack = flags.inv_order; - if ((qflags & ALL_TYPES) && (ccount > 1)) { - invlet = 'a'; - any = zeroany; - any.a_int = ALL_TYPES_SELECTED; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - (qflags & WORN_TYPES) ? "All worn types" : "All types", - MENU_UNSELECTED); - invlet = 'b'; - } else - invlet = 'a'; - do { - collected_type_name = FALSE; - for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { - if (curr->oclass == *pack) { - if ((qflags & WORN_TYPES) && - !(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | - W_WEP | W_SWAPWEP | W_QUIVER))) - continue; - if (!collected_type_name) { - any = zeroany; - any.a_int = curr->oclass; - add_menu(win, NO_GLYPH, &any, invlet++, - def_oc_syms[(int)objects[curr->otyp].oc_class].sym, - ATR_NONE, - let_to_name(*pack, FALSE, - (how != PICK_NONE) && iflags.menu_head_objsym), - MENU_UNSELECTED); - collected_type_name = TRUE; - } - } - } - pack++; - if (invlet >= 'u') { - impossible("query_category: too many categories"); - return 0; - } - } while (*pack); - /* unpaid items if there are any */ - if (do_unpaid) { - invlet = 'u'; - any = zeroany; - any.a_int = 'u'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Unpaid items", MENU_UNSELECTED); - } - /* billed items: checked by caller, so always include if BILLED_TYPES */ - if (qflags & BILLED_TYPES) { - invlet = 'x'; - any = zeroany; - any.a_int = 'x'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Unpaid items already used up", MENU_UNSELECTED); - } - if (qflags & CHOOSE_ALL) { - invlet = 'A'; - any = zeroany; - any.a_int = 'A'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - (qflags & WORN_TYPES) ? - "Auto-select every item being worn" : - "Auto-select every item", MENU_UNSELECTED); - } - /* items with b/u/c/unknown if there are any */ - if (do_blessed) { - invlet = 'B'; - any = zeroany; - any.a_int = 'B'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Items known to be Blessed", MENU_UNSELECTED); - } - if (do_cursed) { - invlet = 'C'; - any = zeroany; - any.a_int = 'C'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Items known to be Cursed", MENU_UNSELECTED); - } - if (do_uncursed) { - invlet = 'U'; - any = zeroany; - any.a_int = 'U'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Items known to be Uncursed", MENU_UNSELECTED); - } - if (do_buc_unknown) { - invlet = 'X'; - any = zeroany; - any.a_int = 'X'; - add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, - "Items of unknown B/C/U status", - MENU_UNSELECTED); - } - end_menu(win, qstr); - n = select_menu(win, how, pick_list); - destroy_nhwindow(win); - if (n < 0) - n = 0; /* caller's don't expect -1 */ - return n; + win = create_nhwindow(NHW_MENU); + start_menu(win); + pack = flags.inv_order; + if ((qflags & ALL_TYPES) && (ccount > 1)) { + invlet = 'a'; + any = zeroany; + any.a_int = ALL_TYPES_SELECTED; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + (qflags & WORN_TYPES) ? "All worn types" : "All types", + MENU_UNSELECTED); + invlet = 'b'; + } else + invlet = 'a'; + do { + collected_type_name = FALSE; + for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { + if (curr->oclass == *pack) { + if ((qflags & WORN_TYPES) + && !(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL + | W_WEP | W_SWAPWEP | W_QUIVER))) + continue; + if (!collected_type_name) { + any = zeroany; + any.a_int = curr->oclass; + add_menu( + win, NO_GLYPH, &any, invlet++, + def_oc_syms[(int) objects[curr->otyp].oc_class].sym, + ATR_NONE, let_to_name(*pack, FALSE, + (how != PICK_NONE) + && iflags.menu_head_objsym), + MENU_UNSELECTED); + collected_type_name = TRUE; + } + } + } + pack++; + if (invlet >= 'u') { + impossible("query_category: too many categories"); + return 0; + } + } while (*pack); + /* unpaid items if there are any */ + if (do_unpaid) { + invlet = 'u'; + any = zeroany; + any.a_int = 'u'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, "Unpaid items", + MENU_UNSELECTED); + } + /* billed items: checked by caller, so always include if BILLED_TYPES */ + if (qflags & BILLED_TYPES) { + invlet = 'x'; + any = zeroany; + any.a_int = 'x'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + "Unpaid items already used up", MENU_UNSELECTED); + } + if (qflags & CHOOSE_ALL) { + invlet = 'A'; + any = zeroany; + any.a_int = 'A'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + (qflags & WORN_TYPES) ? "Auto-select every item being worn" + : "Auto-select every item", + MENU_UNSELECTED); + } + /* items with b/u/c/unknown if there are any */ + if (do_blessed) { + invlet = 'B'; + any = zeroany; + any.a_int = 'B'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + "Items known to be Blessed", MENU_UNSELECTED); + } + if (do_cursed) { + invlet = 'C'; + any = zeroany; + any.a_int = 'C'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + "Items known to be Cursed", MENU_UNSELECTED); + } + if (do_uncursed) { + invlet = 'U'; + any = zeroany; + any.a_int = 'U'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + "Items known to be Uncursed", MENU_UNSELECTED); + } + if (do_buc_unknown) { + invlet = 'X'; + any = zeroany; + any.a_int = 'X'; + add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE, + "Items of unknown B/C/U status", MENU_UNSELECTED); + } + end_menu(win, qstr); + n = select_menu(win, how, pick_list); + destroy_nhwindow(win); + if (n < 0) + n = 0; /* caller's don't expect -1 */ + return n; } STATIC_OVL int @@ -1057,41 +1103,41 @@ count_categories(olist, qflags) struct obj *olist; int qflags; { - char *pack; - boolean counted_category; - int ccount = 0; - struct obj *curr; + char *pack; + boolean counted_category; + int ccount = 0; + struct obj *curr; - pack = flags.inv_order; - do { - counted_category = FALSE; - for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { - if (curr->oclass == *pack) { - if ((qflags & WORN_TYPES) && - !(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | - W_WEP | W_SWAPWEP | W_QUIVER))) - continue; - if (!counted_category) { - ccount++; - counted_category = TRUE; - } - } - } - pack++; - } while (*pack); - return ccount; + pack = flags.inv_order; + do { + counted_category = FALSE; + for (curr = olist; curr; curr = FOLLOW(curr, qflags)) { + if (curr->oclass == *pack) { + if ((qflags & WORN_TYPES) + && !(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL + | W_WEP | W_SWAPWEP | W_QUIVER))) + continue; + if (!counted_category) { + ccount++; + counted_category = TRUE; + } + } + } + pack++; + } while (*pack); + return ccount; } /* could we carry `obj'? if not, could we carry some of it/them? */ STATIC_OVL long carry_count(obj, container, count, telekinesis, wt_before, wt_after) -struct obj *obj, *container; /* object to pick up, bag it's coming out of */ +struct obj *obj, *container; /* object to pick up, bag it's coming out of */ long count; boolean telekinesis; int *wt_before, *wt_after; { boolean adjust_wt = container && carried(container), - is_gold = obj->oclass == COIN_CLASS; + is_gold = obj->oclass == COIN_CLASS; int wt, iw, ow, oow; long qq, savequan, umoney; unsigned saveowt; @@ -1104,192 +1150,207 @@ int *wt_before, *wt_after; iw = max_capacity(); if (count != savequan) { - obj->quan = count; - obj->owt = (unsigned)weight(obj); + obj->quan = count; + obj->owt = (unsigned) weight(obj); } - wt = iw + (int)obj->owt; + wt = iw + (int) obj->owt; if (adjust_wt) - wt -= (container->otyp == BAG_OF_HOLDING) ? - (int)DELTA_CWT(container, obj) : (int)obj->owt; + wt -= (container->otyp == BAG_OF_HOLDING) + ? (int) DELTA_CWT(container, obj) + : (int) obj->owt; /* This will go with silver+copper & new gold weight */ - if (is_gold) /* merged gold might affect cumulative weight */ - wt -= (GOLD_WT(umoney) + GOLD_WT(count) - GOLD_WT(umoney + count)); + if (is_gold) /* merged gold might affect cumulative weight */ + wt -= (GOLD_WT(umoney) + GOLD_WT(count) - GOLD_WT(umoney + count)); if (count != savequan) { - obj->quan = savequan; - obj->owt = saveowt; + obj->quan = savequan; + obj->owt = saveowt; } *wt_before = iw; - *wt_after = wt; + *wt_after = wt; if (wt < 0) - return count; + return count; /* see how many we can lift */ if (is_gold) { - iw -= (int)GOLD_WT(umoney); - if (!adjust_wt) { - qq = GOLD_CAPACITY((long)iw, umoney); - } else { - oow = 0; - qq = 50L - (umoney % 100L) - 1L; - if (qq < 0L) qq += 100L; - for ( ; qq <= count; qq += 100L) { - obj->quan = qq; - obj->owt = (unsigned)GOLD_WT(qq); - ow = (int)GOLD_WT(umoney + qq); - ow -= (container->otyp == BAG_OF_HOLDING) ? - (int)DELTA_CWT(container, obj) : (int)obj->owt; - if (iw + ow >= 0) break; - oow = ow; - } - iw -= oow; - qq -= 100L; - } - if (qq < 0L) qq = 0L; - else if (qq > count) qq = count; - wt = iw + (int)GOLD_WT(umoney + qq); + iw -= (int) GOLD_WT(umoney); + if (!adjust_wt) { + qq = GOLD_CAPACITY((long) iw, umoney); + } else { + oow = 0; + qq = 50L - (umoney % 100L) - 1L; + if (qq < 0L) + qq += 100L; + for (; qq <= count; qq += 100L) { + obj->quan = qq; + obj->owt = (unsigned) GOLD_WT(qq); + ow = (int) GOLD_WT(umoney + qq); + ow -= (container->otyp == BAG_OF_HOLDING) + ? (int) DELTA_CWT(container, obj) + : (int) obj->owt; + if (iw + ow >= 0) + break; + oow = ow; + } + iw -= oow; + qq -= 100L; + } + if (qq < 0L) + qq = 0L; + else if (qq > count) + qq = count; + wt = iw + (int) GOLD_WT(umoney + qq); } else if (count > 1 || count < obj->quan) { - /* - * Ugh. Calc num to lift by changing the quan of of the - * object and calling weight. - * - * This works for containers only because containers - * don't merge. -dean - */ - for (qq = 1L; qq <= count; qq++) { - obj->quan = qq; - obj->owt = (unsigned)(ow = weight(obj)); - if (adjust_wt) - ow -= (container->otyp == BAG_OF_HOLDING) ? - (int)DELTA_CWT(container, obj) : (int)obj->owt; - if (iw + ow >= 0) - break; - wt = iw + ow; - } - --qq; + /* + * Ugh. Calc num to lift by changing the quan of of the + * object and calling weight. + * + * This works for containers only because containers + * don't merge. -dean + */ + for (qq = 1L; qq <= count; qq++) { + obj->quan = qq; + obj->owt = (unsigned) (ow = weight(obj)); + if (adjust_wt) + ow -= (container->otyp == BAG_OF_HOLDING) + ? (int) DELTA_CWT(container, obj) + : (int) obj->owt; + if (iw + ow >= 0) + break; + wt = iw + ow; + } + --qq; } else { - /* there's only one, and we can't lift it */ - qq = 0L; + /* there's only one, and we can't lift it */ + qq = 0L; } obj->quan = savequan; obj->owt = saveowt; if (qq < count) { - /* some message will be given */ - Strcpy(obj_nambuf, doname(obj)); - if (container) { - Sprintf(where, "in %s", the(xname(container))); - verb = "carry"; - } else { - Strcpy(where, "lying here"); - verb = telekinesis ? "acquire" : "lift"; - } + /* some message will be given */ + Strcpy(obj_nambuf, doname(obj)); + if (container) { + Sprintf(where, "in %s", the(xname(container))); + verb = "carry"; + } else { + Strcpy(where, "lying here"); + verb = telekinesis ? "acquire" : "lift"; + } } else { - /* lint supppression */ - *obj_nambuf = *where = '\0'; - verb = ""; + /* lint supppression */ + *obj_nambuf = *where = '\0'; + verb = ""; } /* we can carry qq of them */ if (qq > 0) { - if (qq < count) - You("can only %s %s of the %s %s.", - verb, (qq == 1L) ? "one" : "some", obj_nambuf, where); - *wt_after = wt; - return qq; + if (qq < count) + You("can only %s %s of the %s %s.", verb, + (qq == 1L) ? "one" : "some", obj_nambuf, where); + *wt_after = wt; + return qq; } - if (!container) Strcpy(where, "here"); /* slightly shorter form */ + if (!container) + Strcpy(where, "here"); /* slightly shorter form */ if (invent || umoney) { - prefx1 = "you cannot "; - prefx2 = ""; - suffx = " any more"; + prefx1 = "you cannot "; + prefx2 = ""; + suffx = " any more"; } else { - prefx1 = (obj->quan == 1L) ? "it " : "even one "; - prefx2 = "is too heavy for you to "; - suffx = ""; + prefx1 = (obj->quan == 1L) ? "it " : "even one "; + prefx2 = "is too heavy for you to "; + suffx = ""; } - There("%s %s %s, but %s%s%s%s.", - otense(obj, "are"), obj_nambuf, where, - prefx1, prefx2, verb, suffx); + There("%s %s %s, but %s%s%s%s.", otense(obj, "are"), obj_nambuf, where, + prefx1, prefx2, verb, suffx); - /* *wt_after = iw; */ + /* *wt_after = iw; */ return 0L; } /* determine whether character is able and player is willing to carry `obj' */ STATIC_OVL -int +int lift_object(obj, container, cnt_p, telekinesis) -struct obj *obj, *container; /* object to pick up, bag it's coming out of */ +struct obj *obj, *container; /* object to pick up, bag it's coming out of */ long *cnt_p; boolean telekinesis; { int result, old_wt, new_wt, prev_encumbr, next_encumbr; if (obj->otyp == BOULDER && Sokoban) { - You("cannot get your %s around this %s.", - body_part(HAND), xname(obj)); - return -1; + You("cannot get your %s around this %s.", body_part(HAND), + xname(obj)); + return -1; } /* override weight consideration for loadstone picked up by anybody and for boulder picked up by hero poly'd into a giant; override availability of open inventory slot iff not already carrying one */ - if (obj->otyp == LOADSTONE || - (obj->otyp == BOULDER && throws_rocks(youmonst.data))) { - if (inv_cnt(FALSE) < 52 || !carrying(obj->otyp) || - merge_choice(invent, obj)) - return 1; /* lift regardless of current situation */ - /* if we reach here, we're out of slots and already have at least - one of these, so treat this one more like a normal item */ - You("are carrying too much stuff to pick up %s %s.", - (obj->quan == 1L) ? "another" : "more", simpleonames(obj)); - return -1; + if (obj->otyp == LOADSTONE + || (obj->otyp == BOULDER && throws_rocks(youmonst.data))) { + if (inv_cnt(FALSE) < 52 || !carrying(obj->otyp) + || merge_choice(invent, obj)) + return 1; /* lift regardless of current situation */ + /* if we reach here, we're out of slots and already have at least + one of these, so treat this one more like a normal item */ + You("are carrying too much stuff to pick up %s %s.", + (obj->quan == 1L) ? "another" : "more", simpleonames(obj)); + return -1; } - *cnt_p = carry_count(obj, container, *cnt_p, telekinesis, &old_wt, &new_wt); + *cnt_p = + carry_count(obj, container, *cnt_p, telekinesis, &old_wt, &new_wt); if (*cnt_p < 1L) { - result = -1; /* nothing lifted */ + result = -1; /* nothing lifted */ } else if (obj->oclass != COIN_CLASS && - /* [exception for gold coins will have to change - if silver/copper ones ever get implemented] */ - inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) { - Your("knapsack cannot accommodate any more items."); - result = -1; /* nothing lifted */ + /* [exception for gold coins will have to change + if silver/copper ones ever get implemented] */ + inv_cnt(FALSE) >= 52 && !merge_choice(invent, obj)) { + Your("knapsack cannot accommodate any more items."); + result = -1; /* nothing lifted */ } else { - result = 1; - prev_encumbr = near_capacity(); - if (prev_encumbr < flags.pickup_burden) - prev_encumbr = flags.pickup_burden; - next_encumbr = calc_capacity(new_wt - old_wt); - if (next_encumbr > prev_encumbr) { - if (telekinesis) { - result = 0; /* don't lift */ - } else { - char qbuf[BUFSZ]; - long savequan = obj->quan; + result = 1; + prev_encumbr = near_capacity(); + if (prev_encumbr < flags.pickup_burden) + prev_encumbr = flags.pickup_burden; + next_encumbr = calc_capacity(new_wt - old_wt); + if (next_encumbr > prev_encumbr) { + if (telekinesis) { + result = 0; /* don't lift */ + } else { + char qbuf[BUFSZ]; + long savequan = obj->quan; - obj->quan = *cnt_p; - Strcpy(qbuf, - (next_encumbr > HVY_ENCUMBER) ? overloadmsg : - (next_encumbr > MOD_ENCUMBER) ? nearloadmsg : - moderateloadmsg); - if (container) (void) strsubst(qbuf,"lifting","removing"); - Strcat(qbuf, " "); - (void)safe_qbuf(qbuf, qbuf, ". Continue?", - obj, doname, ansimpleoname, something); - obj->quan = savequan; - switch (ynq(qbuf)) { - case 'q': result = -1; break; - case 'n': result = 0; break; - default: break; /* 'y' => result == 1 */ - } - clear_nhwindow(WIN_MESSAGE); - } - } + obj->quan = *cnt_p; + Strcpy(qbuf, (next_encumbr > HVY_ENCUMBER) + ? overloadmsg + : (next_encumbr > MOD_ENCUMBER) + ? nearloadmsg + : moderateloadmsg); + if (container) + (void) strsubst(qbuf, "lifting", "removing"); + Strcat(qbuf, " "); + (void) safe_qbuf(qbuf, qbuf, ". Continue?", obj, doname, + ansimpleoname, something); + obj->quan = savequan; + switch (ynq(qbuf)) { + case 'q': + result = -1; + break; + case 'n': + result = 0; + break; + default: + break; /* 'y' => result == 1 */ + } + clear_nhwindow(WIN_MESSAGE); + } + } } if (obj->otyp == SCR_SCARE_MONSTER && result <= 0 && !container) - obj->spe = 0; + obj->spe = 0; return result; } @@ -1302,62 +1363,64 @@ int pickup_object(obj, count, telekinesis) struct obj *obj; long count; -boolean telekinesis; /* not picking it up directly by hand */ +boolean telekinesis; /* not picking it up directly by hand */ { - int res, nearload; + int res, nearload; - if (obj->quan < count) { - impossible("pickup_object: count %ld > quan %ld?", - count, obj->quan); - return 0; - } + if (obj->quan < count) { + impossible("pickup_object: count %ld > quan %ld?", count, obj->quan); + return 0; + } - /* In case of auto-pickup, where we haven't had a chance - to look at it yet; affects docall(SCR_SCARE_MONSTER). */ - if (!Blind) - obj->dknown = 1; + /* In case of auto-pickup, where we haven't had a chance + to look at it yet; affects docall(SCR_SCARE_MONSTER). */ + if (!Blind) + obj->dknown = 1; - if (obj == uchain) { /* do not pick up attached chain */ - return 0; - } else if (obj->oartifact && !touch_artifact(obj,&youmonst)) { - return 0; - } else if (obj->otyp == CORPSE) { - if (fatal_corpse_mistake(obj, telekinesis) || - rider_corpse_revival(obj, telekinesis)) - return -1; - } else if (obj->otyp == SCR_SCARE_MONSTER) { - if (obj->blessed) obj->blessed = 0; - else if (!obj->spe && !obj->cursed) obj->spe = 1; - else { - pline_The("scroll%s %s to dust as you %s %s up.", - plur(obj->quan), otense(obj, "turn"), - telekinesis ? "raise" : "pick", - (obj->quan == 1L) ? "it" : "them"); - if (!(objects[SCR_SCARE_MONSTER].oc_name_known) && - !(objects[SCR_SCARE_MONSTER].oc_uname)) - docall(obj); - useupf(obj, obj->quan); - return 1; /* tried to pick something up and failed, but - don't want to terminate pickup loop yet */ - } - } + if (obj == uchain) { /* do not pick up attached chain */ + return 0; + } else if (obj->oartifact && !touch_artifact(obj, &youmonst)) { + return 0; + } else if (obj->otyp == CORPSE) { + if (fatal_corpse_mistake(obj, telekinesis) + || rider_corpse_revival(obj, telekinesis)) + return -1; + } else if (obj->otyp == SCR_SCARE_MONSTER) { + if (obj->blessed) + obj->blessed = 0; + else if (!obj->spe && !obj->cursed) + obj->spe = 1; + else { + pline_The("scroll%s %s to dust as you %s %s up.", plur(obj->quan), + otense(obj, "turn"), telekinesis ? "raise" : "pick", + (obj->quan == 1L) ? "it" : "them"); + if (!(objects[SCR_SCARE_MONSTER].oc_name_known) + && !(objects[SCR_SCARE_MONSTER].oc_uname)) + docall(obj); + useupf(obj, obj->quan); + return 1; /* tried to pick something up and failed, but + don't want to terminate pickup loop yet */ + } + } - if ((res = lift_object(obj, (struct obj *)0, &count, telekinesis)) <= 0) - return res; + if ((res = lift_object(obj, (struct obj *) 0, &count, telekinesis)) <= 0) + return res; - /* Whats left of the special case for gold :-) */ - if (obj->oclass == COIN_CLASS) context.botl = 1; - if (obj->quan != count && obj->otyp != LOADSTONE) - obj = splitobj(obj, count); + /* Whats left of the special case for gold :-) */ + if (obj->oclass == COIN_CLASS) + context.botl = 1; + if (obj->quan != count && obj->otyp != LOADSTONE) + obj = splitobj(obj, count); - obj = pick_obj(obj); + obj = pick_obj(obj); - if (uwep && uwep == obj) mrg_to_wielded = TRUE; - nearload = near_capacity(); - prinv(nearload == SLT_ENCUMBER ? moderateloadmsg : (char *) 0, - obj, count); - mrg_to_wielded = FALSE; - return 1; + if (uwep && uwep == obj) + mrg_to_wielded = TRUE; + nearload = near_capacity(); + prinv(nearload == SLT_ENCUMBER ? moderateloadmsg : (char *) 0, obj, + count); + mrg_to_wielded = FALSE; + return 1; } /* @@ -1370,26 +1433,26 @@ struct obj * pick_obj(otmp) struct obj *otmp; { - obj_extract_self(otmp); - if (!u.uswallow && otmp != uball && costly_spot(otmp->ox, otmp->oy)) { - char saveushops[5], fakeshop[2]; + obj_extract_self(otmp); + if (!u.uswallow && otmp != uball && costly_spot(otmp->ox, otmp->oy)) { + char saveushops[5], fakeshop[2]; - /* addtobill cares about your location rather than the object's; - usually they'll be the same, but not when using telekinesis - (if ever implemented) or a grappling hook */ - Strcpy(saveushops, u.ushops); - fakeshop[0] = *in_rooms(otmp->ox, otmp->oy, SHOPBASE); - fakeshop[1] = '\0'; - Strcpy(u.ushops, fakeshop); - /* sets obj->unpaid if necessary */ - addtobill(otmp, TRUE, FALSE, FALSE); - Strcpy(u.ushops, saveushops); - /* if you're outside the shop, make shk notice */ - if (!index(u.ushops, *fakeshop)) - remote_burglary(otmp->ox, otmp->oy); - } - newsym(otmp->ox, otmp->oy); - return addinv(otmp); /* might merge it with other objects */ + /* addtobill cares about your location rather than the object's; + usually they'll be the same, but not when using telekinesis + (if ever implemented) or a grappling hook */ + Strcpy(saveushops, u.ushops); + fakeshop[0] = *in_rooms(otmp->ox, otmp->oy, SHOPBASE); + fakeshop[1] = '\0'; + Strcpy(u.ushops, fakeshop); + /* sets obj->unpaid if necessary */ + addtobill(otmp, TRUE, FALSE, FALSE); + Strcpy(u.ushops, saveushops); + /* if you're outside the shop, make shk notice */ + if (!index(u.ushops, *fakeshop)) + remote_burglary(otmp->ox, otmp->oy); + } + newsym(otmp->ox, otmp->oy); + return addinv(otmp); /* might merge it with other objects */ } /* @@ -1402,33 +1465,41 @@ encumber_msg() static int oldcap = UNENCUMBERED; int newcap = near_capacity(); - if(oldcap < newcap) { - switch(newcap) { - case 1: Your("movements are slowed slightly because of your load."); - break; - case 2: You("rebalance your load. Movement is difficult."); - break; - case 3: You("%s under your heavy load. Movement is very hard.", - stagger(youmonst.data, "stagger")); - break; - default: You("%s move a handspan with this load!", - newcap == 4 ? "can barely" : "can't even"); - break; - } - context.botl = 1; - } else if(oldcap > newcap) { - switch(newcap) { - case 0: Your("movements are now unencumbered."); - break; - case 1: Your("movements are only slowed slightly by your load."); - break; - case 2: You("rebalance your load. Movement is still difficult."); - break; - case 3: You("%s under your load. Movement is still very hard.", - stagger(youmonst.data, "stagger")); - break; - } - context.botl = 1; + if (oldcap < newcap) { + switch (newcap) { + case 1: + Your("movements are slowed slightly because of your load."); + break; + case 2: + You("rebalance your load. Movement is difficult."); + break; + case 3: + You("%s under your heavy load. Movement is very hard.", + stagger(youmonst.data, "stagger")); + break; + default: + You("%s move a handspan with this load!", + newcap == 4 ? "can barely" : "can't even"); + break; + } + context.botl = 1; + } else if (oldcap > newcap) { + switch (newcap) { + case 0: + Your("movements are now unencumbered."); + break; + case 1: + Your("movements are only slowed slightly by your load."); + break; + case 2: + You("rebalance your load. Movement is still difficult."); + break; + case 3: + You("%s under your load. Movement is still very hard.", + stagger(youmonst.data, "stagger")); + break; + } + context.botl = 1; } oldcap = newcap; @@ -1438,66 +1509,66 @@ encumber_msg() /* Is there a container at x,y. Optional: return count of containers at x,y */ STATIC_OVL int container_at(x, y, countem) -int x,y; +int x, y; boolean countem; { - struct obj *cobj, *nobj; - int container_count = 0; - - for(cobj = level.objects[x][y]; cobj; cobj = nobj) { - nobj = cobj->nexthere; - if(Is_container(cobj)) { - container_count++; - if (!countem) break; - } - } - return container_count; + struct obj *cobj, *nobj; + int container_count = 0; + + for (cobj = level.objects[x][y]; cobj; cobj = nobj) { + nobj = cobj->nexthere; + if (Is_container(cobj)) { + container_count++; + if (!countem) + break; + } + } + return container_count; } STATIC_OVL boolean able_to_loot(x, y, looting) int x, y; -boolean looting; /* loot vs tip */ +boolean looting; /* loot vs tip */ { - const char *verb = looting ? "loot" : "tip"; + const char *verb = looting ? "loot" : "tip"; - if (!can_reach_floor(TRUE)) { - if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) - rider_cant_reach(); /* not skilled enough to reach */ - else - cant_reach_floor(x, y, FALSE, TRUE); - return FALSE; - } else if ((is_pool(x, y) && (looting || !Underwater)) || - is_lava(x, y)) { - /* at present, can't loot in water even when Underwater; - can tip underwater, but not when over--or stuck in--lava */ - You("cannot %s things that are deep in the %s.", - verb, is_lava(x, y) ? "lava" : "water"); - return FALSE; - } else if (nolimbs(youmonst.data)) { - pline("Without limbs, you cannot %s anything.", verb); - return FALSE; - } else if (looting && !freehand()) { - pline("Without a free %s, you cannot loot anything.", - body_part(HAND)); - return FALSE; - } - return TRUE; + if (!can_reach_floor(TRUE)) { + if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) + rider_cant_reach(); /* not skilled enough to reach */ + else + cant_reach_floor(x, y, FALSE, TRUE); + return FALSE; + } else if ((is_pool(x, y) && (looting || !Underwater)) || is_lava(x, y)) { + /* at present, can't loot in water even when Underwater; + can tip underwater, but not when over--or stuck in--lava */ + You("cannot %s things that are deep in the %s.", verb, + is_lava(x, y) ? "lava" : "water"); + return FALSE; + } else if (nolimbs(youmonst.data)) { + pline("Without limbs, you cannot %s anything.", verb); + return FALSE; + } else if (looting && !freehand()) { + pline("Without a free %s, you cannot loot anything.", + body_part(HAND)); + return FALSE; + } + return TRUE; } STATIC_OVL boolean -mon_beside(x,y) +mon_beside(x, y) int x, y; { - int i,j,nx,ny; - for(i = -1; i <= 1; i++) - for(j = -1; j <= 1; j++) { - nx = x + i; - ny = y + j; - if(isok(nx, ny) && MON_AT(nx, ny)) - return TRUE; - } - return FALSE; + int i, j, nx, ny; + for (i = -1; i <= 1; i++) + for (j = -1; j <= 1; j++) { + nx = x + i; + ny = y + j; + if (isok(nx, ny) && MON_AT(nx, ny)) + return TRUE; + } + return FALSE; } int @@ -1505,33 +1576,32 @@ do_loot_cont(cobjp) struct obj **cobjp; { struct obj *cobj = *cobjp; - if (!cobj) return 0; + if (!cobj) + return 0; if (cobj->olocked) { - pline("%s locked.", cobj->lknown ? "It is" : - "Hmmm, it turns out to be"); - cobj->lknown = 1; - return 0; + pline("%s locked.", + cobj->lknown ? "It is" : "Hmmm, it turns out to be"); + cobj->lknown = 1; + return 0; } cobj->lknown = 1; if (cobj->otyp == BAG_OF_TRICKS) { - int tmp; - You("carefully open the bag..."); - pline("It develops a huge set of teeth and bites you!"); - tmp = rnd(10); - losehp(Maybe_Half_Phys(tmp), "carnivorous bag", KILLED_BY_AN); - makeknown(BAG_OF_TRICKS); - return 1; + int tmp; + You("carefully open the bag..."); + pline("It develops a huge set of teeth and bites you!"); + tmp = rnd(10); + losehp(Maybe_Half_Phys(tmp), "carnivorous bag", KILLED_BY_AN); + makeknown(BAG_OF_TRICKS); + return 1; } - You("%sopen %s...", - (!cobj->cknown || !cobj->lknown) ? "carefully " : "", - the(xname(cobj))); + You("%sopen %s...", (!cobj->cknown || !cobj->lknown) ? "carefully " : "", + the(xname(cobj))); return use_container(cobjp, 0); } -int -doloot() /* loot a container on the floor or loot saddle from mon. */ +int doloot() /* loot a container on the floor or loot saddle from mon. */ { struct obj *cobj, *nobj; register int c = -1; @@ -1545,130 +1615,145 @@ doloot() /* loot a container on the floor or loot saddle from mon. */ boolean prev_loot = FALSE; int num_conts; - if (check_capacity((char *)0)) { - /* "Can't do that while carrying so much stuff." */ - return 0; + if (check_capacity((char *) 0)) { + /* "Can't do that while carrying so much stuff." */ + return 0; } if (nohands(youmonst.data)) { - You("have no hands!"); /* not `body_part(HAND)' */ - return 0; + You("have no hands!"); /* not `body_part(HAND)' */ + return 0; } if (Confusion) { - if (rn2(6) && reverse_loot()) return 1; - if (rn2(2)) { - pline("Being confused, you find nothing to loot."); - return 1; /* costs a turn */ - } /* else fallthrough to normal looting */ + if (rn2(6) && reverse_loot()) + return 1; + if (rn2(2)) { + pline("Being confused, you find nothing to loot."); + return 1; /* costs a turn */ + } /* else fallthrough to normal looting */ } - cc.x = u.ux; cc.y = u.uy; + cc.x = u.ux; + cc.y = u.uy; lootcont: if ((num_conts = container_at(cc.x, cc.y, TRUE)) > 0) { - boolean anyfound = FALSE; + boolean anyfound = FALSE; - if (!able_to_loot(cc.x, cc.y, TRUE)) return 0; + if (!able_to_loot(cc.x, cc.y, TRUE)) + return 0; - if (num_conts > 1) { - /* use a menu to loot many containers */ - int n, i; - winid win; - anything any; - menu_item *pick_list = NULL; + if (num_conts > 1) { + /* use a menu to loot many containers */ + int n, i; + winid win; + anything any; + menu_item *pick_list = NULL; - any.a_void = 0; - win = create_nhwindow(NHW_MENU); - start_menu(win); + any.a_void = 0; + win = create_nhwindow(NHW_MENU); + start_menu(win); - for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = cobj->nexthere) - if (Is_container(cobj)) { - any.a_obj = cobj; - add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, doname(cobj), MENU_UNSELECTED); - } - end_menu(win, "Loot which containers?"); - n = select_menu(win, PICK_ANY, &pick_list); - destroy_nhwindow(win); + for (cobj = level.objects[cc.x][cc.y]; cobj; + cobj = cobj->nexthere) + if (Is_container(cobj)) { + any.a_obj = cobj; + add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, + doname(cobj), MENU_UNSELECTED); + } + end_menu(win, "Loot which containers?"); + n = select_menu(win, PICK_ANY, &pick_list); + destroy_nhwindow(win); - if (n > 0) { - for (i = 0; i < n; i++) { - timepassed |= do_loot_cont(&pick_list[i].item.a_obj); - if (multi < 0 || !pick_list[i].item.a_obj) { - free((genericptr_t) pick_list); - return 1; - } - } - } - if (pick_list) free((genericptr_t) pick_list); - if (n != 0) c = 'y'; - } else { - for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) { - nobj = cobj->nexthere; + if (n > 0) { + for (i = 0; i < n; i++) { + timepassed |= do_loot_cont(&pick_list[i].item.a_obj); + if (multi < 0 || !pick_list[i].item.a_obj) { + free((genericptr_t) pick_list); + return 1; + } + } + } + if (pick_list) + free((genericptr_t) pick_list); + if (n != 0) + c = 'y'; + } else { + for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) { + nobj = cobj->nexthere; - if (Is_container(cobj)) { - c = ynq(safe_qbuf(qbuf, "There is ", " here, loot it?", - cobj, doname, ansimpleoname, "a container")); - if (c == 'q') return (timepassed); - if (c == 'n') continue; - anyfound = TRUE; + if (Is_container(cobj)) { + c = ynq(safe_qbuf(qbuf, "There is ", " here, loot it?", + cobj, doname, ansimpleoname, + "a container")); + if (c == 'q') + return (timepassed); + if (c == 'n') + continue; + anyfound = TRUE; - timepassed |= do_loot_cont(&cobj); - /* might have triggered chest trap or magic bag explosion */ - if (multi < 0 || !cobj) return 1; - } - } - if (anyfound) c = 'y'; - } + timepassed |= do_loot_cont(&cobj); + /* might have triggered chest trap or magic bag explosion + */ + if (multi < 0 || !cobj) + return 1; + } + } + if (anyfound) + c = 'y'; + } } else if (IS_GRAVE(levl[cc.x][cc.y].typ)) { - You("need to dig up the grave to effectively loot it..."); + You("need to dig up the grave to effectively loot it..."); } /* * 3.3.1 introduced directional looting for some things. */ if (c != 'y' && mon_beside(u.ux, u.uy)) { - if (!get_adjacent_loc("Loot in what direction?", - "Invalid loot location", - u.ux, u.uy, &cc)) return 0; - if (cc.x == u.ux && cc.y == u.uy) { - underfoot = TRUE; - if (container_at(cc.x, cc.y, FALSE)) - goto lootcont; - } else - underfoot = FALSE; - if (u.dz < 0) { - You("%s to loot on the %s.", dont_find_anything, - ceiling(cc.x, cc.y)); - timepassed = 1; - return timepassed; - } - mtmp = m_at(cc.x, cc.y); - if (mtmp) timepassed = loot_mon(mtmp, &prev_inquiry, &prev_loot); - /* always use a turn when choosing a direction is impaired, - even if you've successfully targetted a saddled creature - and then answered "no" to the "remove its saddle?" prompt */ - if (Confusion || Stunned) timepassed = 1; + if (!get_adjacent_loc("Loot in what direction?", + "Invalid loot location", u.ux, u.uy, &cc)) + return 0; + if (cc.x == u.ux && cc.y == u.uy) { + underfoot = TRUE; + if (container_at(cc.x, cc.y, FALSE)) + goto lootcont; + } else + underfoot = FALSE; + if (u.dz < 0) { + You("%s to loot on the %s.", dont_find_anything, + ceiling(cc.x, cc.y)); + timepassed = 1; + return timepassed; + } + mtmp = m_at(cc.x, cc.y); + if (mtmp) + timepassed = loot_mon(mtmp, &prev_inquiry, &prev_loot); + /* always use a turn when choosing a direction is impaired, + even if you've successfully targetted a saddled creature + and then answered "no" to the "remove its saddle?" prompt */ + if (Confusion || Stunned) + timepassed = 1; - /* Preserve pre-3.3.1 behaviour for containers. - * Adjust this if-block to allow container looting - * from one square away to change that in the future. - */ - if (!underfoot) { - if (container_at(cc.x, cc.y, FALSE)) { - if (mtmp) { - You_cant("loot anything %sthere with %s in the way.", - prev_inquiry ? "else " : "", mon_nam(mtmp)); - return timepassed; - } else { - You("have to be at a container to loot it."); - } - } else { - You("%s %sthere to loot.", dont_find_anything, - (prev_inquiry || prev_loot) ? "else " : ""); - return timepassed; - } - } + /* Preserve pre-3.3.1 behaviour for containers. + * Adjust this if-block to allow container looting + * from one square away to change that in the future. + */ + if (!underfoot) { + if (container_at(cc.x, cc.y, FALSE)) { + if (mtmp) { + You_cant("loot anything %sthere with %s in the way.", + prev_inquiry ? "else " : "", mon_nam(mtmp)); + return timepassed; + } else { + You("have to be at a container to loot it."); + } + } else { + You("%s %sthere to loot.", dont_find_anything, + (prev_inquiry || prev_loot) ? "else " : ""); + return timepassed; + } + } } else if (c != 'y' && c != 'n') { - You("%s %s to loot.", dont_find_anything, - underfoot ? "here" : "there"); + You("%s %s to loot.", dont_find_anything, + underfoot ? "here" : "there"); } return (timepassed); } @@ -1683,59 +1768,66 @@ reverse_loot() int n, x = u.ux, y = u.uy; if (!rn2(3)) { - /* n objects: 1/(n+1) chance per object plus 1/(n+1) to fall off end */ - for (n = inv_cnt(TRUE), otmp = invent; otmp; --n, otmp = otmp->nobj) - if (!rn2(n + 1)) { - prinv("You find old loot:", otmp, 0L); - return TRUE; - } - return FALSE; + /* n objects: 1/(n+1) chance per object plus 1/(n+1) to fall off end + */ + for (n = inv_cnt(TRUE), otmp = invent; otmp; --n, otmp = otmp->nobj) + if (!rn2(n + 1)) { + prinv("You find old loot:", otmp, 0L); + return TRUE; + } + return FALSE; } /* find a money object to mess with */ for (goldob = invent; goldob; goldob = goldob->nobj) - if (goldob->oclass == COIN_CLASS) { - contribution = ((long)rnd(5) * goldob->quan + 4L) / 5L; - if (contribution < goldob->quan) - goldob = splitobj(goldob, contribution); - break; - } - if (!goldob) return FALSE; + if (goldob->oclass == COIN_CLASS) { + contribution = ((long) rnd(5) * goldob->quan + 4L) / 5L; + if (contribution < goldob->quan) + goldob = splitobj(goldob, contribution); + break; + } + if (!goldob) + return FALSE; if (!IS_THRONE(levl[x][y].typ)) { - dropx(goldob); - /* the dropped gold might have fallen to lower level */ - if (g_at(x, y)) pline("Ok, now there is loot here."); + dropx(goldob); + /* the dropped gold might have fallen to lower level */ + if (g_at(x, y)) + pline("Ok, now there is loot here."); } else { - /* find original coffers chest if present, otherwise use nearest one */ - otmp = 0; - for (coffers = fobj; coffers; coffers = coffers->nobj) - if (coffers->otyp == CHEST) { - if (coffers->spe == 2) break; /* a throne room chest */ - if (!otmp || - distu(coffers->ox, coffers->oy) < distu(otmp->ox, otmp->oy)) - otmp = coffers; /* remember closest ordinary chest */ - } - if (!coffers) coffers = otmp; + /* find original coffers chest if present, otherwise use nearest one + */ + otmp = 0; + for (coffers = fobj; coffers; coffers = coffers->nobj) + if (coffers->otyp == CHEST) { + if (coffers->spe == 2) + break; /* a throne room chest */ + if (!otmp + || distu(coffers->ox, coffers->oy) + < distu(otmp->ox, otmp->oy)) + otmp = coffers; /* remember closest ordinary chest */ + } + if (!coffers) + coffers = otmp; - if (coffers) { - verbalize("Thank you for your contribution to reduce the debt."); - freeinv(goldob); - (void)add_to_container(coffers, goldob); - coffers->owt = weight(coffers); - coffers->cknown = 0; - if (!coffers->olocked) { - boxdummy = zeroobj, boxdummy.otyp = SPE_WIZARD_LOCK; - (void)boxlock(coffers, &boxdummy); - } - } else if ((mon = makemon(courtmon(), x, y, NO_MM_FLAGS)) != 0) { - freeinv(goldob); - add_to_minv(mon, goldob); - pline("The exchequer accepts your contribution."); - } else { - You("drop %s.", doname(goldob)); - dropx(goldob); - } + if (coffers) { + verbalize("Thank you for your contribution to reduce the debt."); + freeinv(goldob); + (void) add_to_container(coffers, goldob); + coffers->owt = weight(coffers); + coffers->cknown = 0; + if (!coffers->olocked) { + boxdummy = zeroobj, boxdummy.otyp = SPE_WIZARD_LOCK; + (void) boxlock(coffers, &boxdummy); + } + } else if ((mon = makemon(courtmon(), x, y, NO_MM_FLAGS)) != 0) { + freeinv(goldob); + add_to_minv(mon, goldob); + pline("The exchequer accepts your contribution."); + } else { + You("drop %s.", doname(goldob)); + dropx(goldob); + } } return TRUE; } @@ -1753,45 +1845,50 @@ boolean *prev_loot; struct obj *otmp; char qbuf[QBUFSZ]; - /* 3.3.1 introduced the ability to remove saddle from a steed */ - /* *passed_info is set to TRUE if a loot query was given. */ - /* *prev_loot is set to TRUE if something was actually acquired in here. */ + /* 3.3.1 introduced the ability to remove saddle from a steed */ + /* *passed_info is set to TRUE if a loot query was given. */ + /* *prev_loot is set to TRUE if something was actually acquired in here. + */ if (mtmp && mtmp != u.usteed && (otmp = which_armor(mtmp, W_SADDLE))) { - long unwornmask; - if (passed_info) *passed_info = 1; - Sprintf(qbuf, "Do you want to remove the saddle from %s?", - x_monnam(mtmp, ARTICLE_THE, (char *)0, SUPPRESS_SADDLE, FALSE)); - if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { - if (nolimbs(youmonst.data)) { - You_cant("do that without limbs."); /* not body_part(HAND) */ - return (0); - } - if (otmp->cursed) { - You("can't. The saddle seems to be stuck to %s.", - x_monnam(mtmp, ARTICLE_THE, (char *)0, - SUPPRESS_SADDLE, FALSE)); - - /* the attempt costs you time */ - return (1); - } - obj_extract_self(otmp); - if ((unwornmask = otmp->owornmask) != 0L) { - mtmp->misc_worn_check &= ~unwornmask; - otmp->owornmask = 0L; - update_mon_intrinsics(mtmp, otmp, FALSE, FALSE); - } - otmp = hold_another_object(otmp, "You drop %s!", doname(otmp), - (const char *)0); - timepassed = rnd(3); - if (prev_loot) *prev_loot = TRUE; - } else if (c == 'q') { - return (0); - } + long unwornmask; + if (passed_info) + *passed_info = 1; + Sprintf( + qbuf, "Do you want to remove the saddle from %s?", + x_monnam(mtmp, ARTICLE_THE, (char *) 0, SUPPRESS_SADDLE, FALSE)); + if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') { + if (nolimbs(youmonst.data)) { + You_cant("do that without limbs."); /* not body_part(HAND) */ + return (0); + } + if (otmp->cursed) { + You("can't. The saddle seems to be stuck to %s.", + x_monnam(mtmp, ARTICLE_THE, (char *) 0, SUPPRESS_SADDLE, + FALSE)); + + /* the attempt costs you time */ + return (1); + } + obj_extract_self(otmp); + if ((unwornmask = otmp->owornmask) != 0L) { + mtmp->misc_worn_check &= ~unwornmask; + otmp->owornmask = 0L; + update_mon_intrinsics(mtmp, otmp, FALSE, FALSE); + } + otmp = hold_another_object(otmp, "You drop %s!", doname(otmp), + (const char *) 0); + timepassed = rnd(3); + if (prev_loot) + *prev_loot = TRUE; + } else if (c == 'q') { + return (0); + } } - /* 3.4.0 introduced the ability to pick things up from within swallower's stomach */ + /* 3.4.0 introduced the ability to pick things up from within swallower's + * stomach */ if (u.uswallow) { - int count = passed_info ? *passed_info : 0; - timepassed = pickup(count); + int count = passed_info ? *passed_info : 0; + timepassed = pickup(count); } return timepassed; } @@ -1802,23 +1899,24 @@ boolean *prev_loot; */ STATIC_OVL boolean mbag_explodes(obj, depthin) - struct obj *obj; - int depthin; +struct obj *obj; +int depthin; { /* these won't cause an explosion when they're empty */ - if ((obj->otyp == WAN_CANCELLATION || obj->otyp == BAG_OF_TRICKS) && - obj->spe <= 0) - return FALSE; + if ((obj->otyp == WAN_CANCELLATION || obj->otyp == BAG_OF_TRICKS) + && obj->spe <= 0) + return FALSE; /* odds: 1/1, 2/2, 3/4, 4/8, 5/16, 6/32, 7/64, 8/128, 9/128, 10/128,... */ - if ((Is_mbag(obj) || obj->otyp == WAN_CANCELLATION) && - (rn2(1 << (depthin > 7 ? 7 : depthin)) <= depthin)) - return TRUE; + if ((Is_mbag(obj) || obj->otyp == WAN_CANCELLATION) + && (rn2(1 << (depthin > 7 ? 7 : depthin)) <= depthin)) + return TRUE; else if (Has_contents(obj)) { - struct obj *otmp; + struct obj *otmp; - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) - if (mbag_explodes(otmp, depthin+1)) return TRUE; + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) + if (mbag_explodes(otmp, depthin + 1)) + return TRUE; } return FALSE; } @@ -1828,143 +1926,147 @@ STATIC_PTR int in_container(obj) register struct obj *obj; { - boolean floor_container = !carried(current_container); - boolean was_unpaid = FALSE; - char buf[BUFSZ]; + boolean floor_container = !carried(current_container); + boolean was_unpaid = FALSE; + char buf[BUFSZ]; - if (!current_container) { - impossible(" no current_container?"); - return 0; - } else if (obj == uball || obj == uchain) { - You("must be kidding."); - return 0; - } else if (obj == current_container) { - pline("That would be an interesting topological exercise."); - return 0; - } else if (obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) { - Norep("You cannot %s %s you are wearing.", - Icebox ? "refrigerate" : "stash", something); - return 0; - } else if ((obj->otyp == LOADSTONE) && obj->cursed) { - obj->bknown = 1; - pline_The("stone%s won't leave your person.", plur(obj->quan)); - return 0; - } else if (obj->otyp == AMULET_OF_YENDOR || - obj->otyp == CANDELABRUM_OF_INVOCATION || - obj->otyp == BELL_OF_OPENING || - obj->otyp == SPE_BOOK_OF_THE_DEAD) { - /* Prohibit Amulets in containers; if you allow it, monsters can't - * steal them. It also becomes a pain to check to see if someone - * has the Amulet. Ditto for the Candelabrum, the Bell and the Book. - */ - pline("%s cannot be confined in such trappings.", The(xname(obj))); - return 0; - } else if (obj->otyp == LEASH && obj->leashmon != 0) { - pline("%s attached to your pet.", Tobjnam(obj, "are")); - return 0; - } else if (obj == uwep) { - if (welded(obj)) { - weldmsg(obj); - return 0; - } - setuwep((struct obj *) 0); - if (uwep) return 0; /* unwielded, died, rewielded */ - } else if (obj == uswapwep) { - setuswapwep((struct obj *) 0); - if (uswapwep) return 0; /* unwielded, died, rewielded */ - } else if (obj == uquiver) { - setuqwep((struct obj *) 0); - if (uquiver) return 0; /* unwielded, died, rewielded */ - } + if (!current_container) { + impossible(" no current_container?"); + return 0; + } else if (obj == uball || obj == uchain) { + You("must be kidding."); + return 0; + } else if (obj == current_container) { + pline("That would be an interesting topological exercise."); + return 0; + } else if (obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) { + Norep("You cannot %s %s you are wearing.", + Icebox ? "refrigerate" : "stash", something); + return 0; + } else if ((obj->otyp == LOADSTONE) && obj->cursed) { + obj->bknown = 1; + pline_The("stone%s won't leave your person.", plur(obj->quan)); + return 0; + } else if (obj->otyp == AMULET_OF_YENDOR + || obj->otyp == CANDELABRUM_OF_INVOCATION + || obj->otyp == BELL_OF_OPENING + || obj->otyp == SPE_BOOK_OF_THE_DEAD) { + /* Prohibit Amulets in containers; if you allow it, monsters can't + * steal them. It also becomes a pain to check to see if someone + * has the Amulet. Ditto for the Candelabrum, the Bell and the Book. + */ + pline("%s cannot be confined in such trappings.", The(xname(obj))); + return 0; + } else if (obj->otyp == LEASH && obj->leashmon != 0) { + pline("%s attached to your pet.", Tobjnam(obj, "are")); + return 0; + } else if (obj == uwep) { + if (welded(obj)) { + weldmsg(obj); + return 0; + } + setuwep((struct obj *) 0); + if (uwep) + return 0; /* unwielded, died, rewielded */ + } else if (obj == uswapwep) { + setuswapwep((struct obj *) 0); + if (uswapwep) + return 0; /* unwielded, died, rewielded */ + } else if (obj == uquiver) { + setuqwep((struct obj *) 0); + if (uquiver) + return 0; /* unwielded, died, rewielded */ + } - if (fatal_corpse_mistake(obj, FALSE)) return -1; + if (fatal_corpse_mistake(obj, FALSE)) + return -1; - /* boxes, boulders, and big statues can't fit into any container */ - if (obj->otyp == ICE_BOX || Is_box(obj) || obj->otyp == BOULDER || - (obj->otyp == STATUE && bigmonst(&mons[obj->corpsenm]))) { - /* - * xname() uses a static result array. Save obj's name - * before current_container's name is computed. Don't - * use the result of strcpy() within You() --- the order - * of evaluation of the parameters is undefined. - */ - Strcpy(buf, the(xname(obj))); - You("cannot fit %s into %s.", buf, - the(xname(current_container))); - return 0; - } + /* boxes, boulders, and big statues can't fit into any container */ + if (obj->otyp == ICE_BOX || Is_box(obj) || obj->otyp == BOULDER + || (obj->otyp == STATUE && bigmonst(&mons[obj->corpsenm]))) { + /* + * xname() uses a static result array. Save obj's name + * before current_container's name is computed. Don't + * use the result of strcpy() within You() --- the order + * of evaluation of the parameters is undefined. + */ + Strcpy(buf, the(xname(obj))); + You("cannot fit %s into %s.", buf, the(xname(current_container))); + return 0; + } - freeinv(obj); + freeinv(obj); - if (obj_is_burning(obj)) /* this used to be part of freeinv() */ - (void) snuff_lit(obj); + if (obj_is_burning(obj)) /* this used to be part of freeinv() */ + (void) snuff_lit(obj); - if (floor_container && costly_spot(u.ux, u.uy)) { - if (current_container->no_charge && !obj->unpaid) { - /* don't sell when putting the item into your own container */ - obj->no_charge = 1; - } else if (obj->oclass != COIN_CLASS) { - /* sellobj() will take an unpaid item off the shop bill - * note: coins are handled later */ - was_unpaid = obj->unpaid ? TRUE : FALSE; - sellobj_state(SELL_DELIBERATE); - sellobj(obj, u.ux, u.uy); - sellobj_state(SELL_NORMAL); - } - } - if (Icebox && !age_is_relative(obj)) { - obj->age = monstermoves - obj->age; /* actual age */ - /* stop any corpse timeouts when frozen */ - if (obj->otyp == CORPSE && obj->timed) { - long rot_alarm = stop_timer(ROT_CORPSE, obj_to_any(obj)); - (void) stop_timer(REVIVE_MON, obj_to_any(obj)); - /* mark a non-reviving corpse as such */ - if (rot_alarm) obj->norevive = 1; - } - } else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) { - /* explicitly mention what item is triggering the explosion */ - pline( - "As you put %s inside, you are blasted by a magical explosion!", - doname(obj)); - /* did not actually insert obj yet */ - if (was_unpaid) addtobill(obj, FALSE, FALSE, TRUE); - obfree(obj, (struct obj *)0); - delete_contents(current_container); - if (!floor_container) - useup(current_container); - else if (obj_here(current_container, u.ux, u.uy)) - useupf(current_container, current_container->quan); - else - panic("in_container: bag not found."); + if (floor_container && costly_spot(u.ux, u.uy)) { + if (current_container->no_charge && !obj->unpaid) { + /* don't sell when putting the item into your own container */ + obj->no_charge = 1; + } else if (obj->oclass != COIN_CLASS) { + /* sellobj() will take an unpaid item off the shop bill + * note: coins are handled later */ + was_unpaid = obj->unpaid ? TRUE : FALSE; + sellobj_state(SELL_DELIBERATE); + sellobj(obj, u.ux, u.uy); + sellobj_state(SELL_NORMAL); + } + } + if (Icebox && !age_is_relative(obj)) { + obj->age = monstermoves - obj->age; /* actual age */ + /* stop any corpse timeouts when frozen */ + if (obj->otyp == CORPSE && obj->timed) { + long rot_alarm = stop_timer(ROT_CORPSE, obj_to_any(obj)); + (void) stop_timer(REVIVE_MON, obj_to_any(obj)); + /* mark a non-reviving corpse as such */ + if (rot_alarm) + obj->norevive = 1; + } + } else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) { + /* explicitly mention what item is triggering the explosion */ + pline("As you put %s inside, you are blasted by a magical explosion!", + doname(obj)); + /* did not actually insert obj yet */ + if (was_unpaid) + addtobill(obj, FALSE, FALSE, TRUE); + obfree(obj, (struct obj *) 0); + delete_contents(current_container); + if (!floor_container) + useup(current_container); + else if (obj_here(current_container, u.ux, u.uy)) + useupf(current_container, current_container->quan); + else + panic("in_container: bag not found."); - losehp(d(6,6),"magical explosion", KILLED_BY_AN); - current_container = 0; /* baggone = TRUE; */ - } + losehp(d(6, 6), "magical explosion", KILLED_BY_AN); + current_container = 0; /* baggone = TRUE; */ + } - if (current_container) { - Strcpy(buf, the(xname(current_container))); - You("put %s into %s.", doname(obj), buf); + if (current_container) { + Strcpy(buf, the(xname(current_container))); + You("put %s into %s.", doname(obj), buf); - /* gold in container always needs to be added to credit */ - if (floor_container && obj->oclass == COIN_CLASS) - sellobj(obj, current_container->ox, current_container->oy); - (void) add_to_container(current_container, obj); - current_container->owt = weight(current_container); - } - /* gold needs this, and freeinv() many lines above may cause - * the encumbrance to disappear from the status, so just always - * update status immediately. - */ - bot(); + /* gold in container always needs to be added to credit */ + if (floor_container && obj->oclass == COIN_CLASS) + sellobj(obj, current_container->ox, current_container->oy); + (void) add_to_container(current_container, obj); + current_container->owt = weight(current_container); + } + /* gold needs this, and freeinv() many lines above may cause + * the encumbrance to disappear from the status, so just always + * update status immediately. + */ + bot(); - return(current_container ? 1 : -1); + return (current_container ? 1 : -1); } int ck_bag(obj) struct obj *obj; { - return current_container && obj != current_container; + return current_container && obj != current_container; } /* Returns: -1 to stop, 1 item was removed, 0 item was not removed. */ @@ -1972,60 +2074,63 @@ STATIC_PTR int out_container(obj) register struct obj *obj; { - register struct obj *otmp; - boolean is_gold = (obj->oclass == COIN_CLASS); - int res, loadlev; - long count; + register struct obj *otmp; + boolean is_gold = (obj->oclass == COIN_CLASS); + int res, loadlev; + long count; - if (!current_container) { - impossible(" no current_container?"); - return -1; - } else if (is_gold) { - obj->owt = weight(obj); - } + if (!current_container) { + impossible(" no current_container?"); + return -1; + } else if (is_gold) { + obj->owt = weight(obj); + } - if(obj->oartifact && !touch_artifact(obj,&youmonst)) return 0; + if (obj->oartifact && !touch_artifact(obj, &youmonst)) + return 0; - if (fatal_corpse_mistake(obj, FALSE)) return -1; + if (fatal_corpse_mistake(obj, FALSE)) + return -1; - count = obj->quan; - if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0) - return res; + count = obj->quan; + if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0) + return res; - if (obj->quan != count && obj->otyp != LOADSTONE) - obj = splitobj(obj, count); + if (obj->quan != count && obj->otyp != LOADSTONE) + obj = splitobj(obj, count); - /* Remove the object from the list. */ - obj_extract_self(obj); - current_container->owt = weight(current_container); + /* Remove the object from the list. */ + obj_extract_self(obj); + current_container->owt = weight(current_container); - if (Icebox && !age_is_relative(obj)) { - obj->age = monstermoves - obj->age; /* actual age */ - if (obj->otyp == CORPSE) - start_corpse_timeout(obj); - } - /* simulated point of time */ + if (Icebox && !age_is_relative(obj)) { + obj->age = monstermoves - obj->age; /* actual age */ + if (obj->otyp == CORPSE) + start_corpse_timeout(obj); + } + /* simulated point of time */ - if(!obj->unpaid && !carried(current_container) && - costly_spot(current_container->ox, current_container->oy)) { - obj->ox = current_container->ox; - obj->oy = current_container->oy; - addtobill(obj, FALSE, FALSE, FALSE); - } - if (is_pick(obj)) pick_pick(obj); /* shopkeeper feedback */ + if (!obj->unpaid && !carried(current_container) + && costly_spot(current_container->ox, current_container->oy)) { + obj->ox = current_container->ox; + obj->oy = current_container->oy; + addtobill(obj, FALSE, FALSE, FALSE); + } + if (is_pick(obj)) + pick_pick(obj); /* shopkeeper feedback */ - otmp = addinv(obj); - loadlev = near_capacity(); - prinv(loadlev ? - (loadlev < MOD_ENCUMBER ? - "You have a little trouble removing" : - "You have much trouble removing") : (char *)0, - otmp, count); + otmp = addinv(obj); + loadlev = near_capacity(); + prinv(loadlev + ? (loadlev < MOD_ENCUMBER ? "You have a little trouble removing" + : "You have much trouble removing") + : (char *) 0, + otmp, count); - if (is_gold) { - bot(); /* update character's gold piece count immediately */ - } - return 1; + if (is_gold) { + bot(); /* update character's gold piece count immediately */ + } + return 1; } /* an object inside a cursed bag of holding is being destroyed */ @@ -2038,14 +2143,14 @@ struct obj *item; long loss = 0L; if (item->dknown) - pline("%s %s vanished!", Doname2(item), otense(item, "have")); + pline("%s %s vanished!", Doname2(item), otense(item, "have")); else - You("%s %s disappear!", Blind ? "notice" : "see", doname(item)); + You("%s %s disappear!", Blind ? "notice" : "see", doname(item)); if (*u.ushops && (shkp = shop_keeper(*u.ushops)) != 0) { - if (held ? (boolean) item->unpaid : costly_spot(u.ux, u.uy)) - loss = stolen_value(item, u.ux, u.uy, - (boolean)shkp->mpeaceful, TRUE); + if (held ? (boolean) item->unpaid : costly_spot(u.ux, u.uy)) + loss = stolen_value(item, u.ux, u.uy, (boolean) shkp->mpeaceful, + TRUE); } obfree(item, (struct obj *) 0); return loss; @@ -2060,33 +2165,34 @@ struct obj *box; struct monst *livecat; xchar ox, oy; - box->spe = 0; /* box->owt will be updated below */ + box->spe = 0; /* box->owt will be updated below */ if (get_obj_location(box, &ox, &oy, 0)) - box->ox = ox, box->oy = oy; /* in case it's being carried */ + box->ox = ox, box->oy = oy; /* in case it's being carried */ /* this isn't really right, since any form of observation (telepathic or monster/object/food detection) ought to force the determination of alive vs dead state; but basing it just on opening the box is much simpler to cope with */ - livecat = rn2(2) ? makemon(&mons[PM_HOUSECAT], - box->ox, box->oy, NO_MINVENT) : 0; + livecat = rn2(2) + ? makemon(&mons[PM_HOUSECAT], box->ox, box->oy, NO_MINVENT) + : 0; if (livecat) { - livecat->mpeaceful = 1; - set_malign(livecat); - if (!canspotmon(livecat)) - You("think %s brushed your %s.", something, body_part(FOOT)); - else - pline("%s inside the box is still alive!", Monnam(livecat)); - (void) christen_monst(livecat, sc); + livecat->mpeaceful = 1; + set_malign(livecat); + if (!canspotmon(livecat)) + You("think %s brushed your %s.", something, body_part(FOOT)); + else + pline("%s inside the box is still alive!", Monnam(livecat)); + (void) christen_monst(livecat, sc); } else { - deadcat = mk_named_object(CORPSE, &mons[PM_HOUSECAT], - box->ox, box->oy, sc); - if (deadcat) { - obj_extract_self(deadcat); - (void) add_to_container(box, deadcat); - } - pline_The("%s inside the box is dead!", - Hallucination ? rndmonnam(NULL) : "housecat"); + deadcat = + mk_named_object(CORPSE, &mons[PM_HOUSECAT], box->ox, box->oy, sc); + if (deadcat) { + obj_extract_self(deadcat); + (void) add_to_container(box, deadcat); + } + pline_The("%s inside the box is dead!", + Hallucination ? rndmonnam(NULL) : "housecat"); } box->owt = weight(box); return; @@ -2100,34 +2206,30 @@ container_gone(fn) int FDECL((*fn), (OBJ_P)); { /* result is only meaningful while use_container() is executing */ - return ((fn == in_container || fn == out_container) && !current_container); + return ((fn == in_container || fn == out_container) + && !current_container); } STATIC_OVL void explain_container_prompt() { - static const char * const explaintext[] = { - "Container actions:", - "", - " : -- Look: examine contents", - " o -- Out: take things out", - " i -- In: put things in", - " b -- Both: first take things out, then put things in", - " r -- Reversed: put things in, then take things out", - " s -- Stash: put one item in", - " q -- Quit: do nothing", - " ? -- Help: display this text.", - "", - 0 + static const char *const explaintext[] = { + "Container actions:", "", " : -- Look: examine contents", + " o -- Out: take things out", " i -- In: put things in", + " b -- Both: first take things out, then put things in", + " r -- Reversed: put things in, then take things out", + " s -- Stash: put one item in", " q -- Quit: do nothing", + " ? -- Help: display this text.", "", 0 }; - const char * const *txtpp; + const char *const *txtpp; winid win; /* "Do what with ? [:oibrsq or ?] (q)" */ if ((win = create_nhwindow(NHW_TEXT)) != WIN_ERR) { - for (txtpp = explaintext; *txtpp; ++txtpp) putstr(win, 0, *txtpp); - display_nhwindow(win, FALSE); - destroy_nhwindow(win); + for (txtpp = explaintext; *txtpp; ++txtpp) + putstr(win, 0, *txtpp); + display_nhwindow(win, FALSE); + destroy_nhwindow(win); } } @@ -2135,11 +2237,11 @@ boolean u_handsy() { if (nohands(youmonst.data)) { - You("have no hands!"); /* not `body_part(HAND)' */ - return FALSE; + You("have no hands!"); /* not `body_part(HAND)' */ + return FALSE; } else if (!freehand()) { - You("have no free %s.", body_part(HAND)); - return FALSE; + You("have no free %s.", body_part(HAND)); + return FALSE; } return TRUE; } @@ -2151,224 +2253,231 @@ use_container(objp, held) struct obj **objp; int held; { - struct obj *curr, *otmp, *obj = *objp; - boolean quantum_cat, cursed_mbag, - loot_out, loot_in, loot_in_first, stash_one, - inokay, outokay, outmaybe; - char c, emptymsg[BUFSZ], - qbuf[QBUFSZ], pbuf[QBUFSZ], xbuf[QBUFSZ]; - int used = 0; + struct obj *curr, *otmp, *obj = *objp; + boolean quantum_cat, cursed_mbag, loot_out, loot_in, loot_in_first, + stash_one, inokay, outokay, outmaybe; + char c, emptymsg[BUFSZ], qbuf[QBUFSZ], pbuf[QBUFSZ], xbuf[QBUFSZ]; + int used = 0; - emptymsg[0] = '\0'; + emptymsg[0] = '\0'; - if (!u_handsy()) return 0; + if (!u_handsy()) + return 0; - if (obj->olocked) { - pline("%s locked.", Tobjnam(obj, "are")); - if (held) You("must put it down to unlock."); - obj->lknown = 1; - return 0; - } else if (obj->otrapped) { - if (held) You("open %s...", the(xname(obj))); - obj->lknown = 1; - (void) chest_trap(obj, HAND, FALSE); - /* even if the trap fails, you've used up this turn */ - if (multi >= 0) { /* in case we didn't become paralyzed */ - nomul(-1); - multi_reason = "opening a container"; - nomovemsg = ""; - } - return 1; - } - obj->lknown = 1; + if (obj->olocked) { + pline("%s locked.", Tobjnam(obj, "are")); + if (held) + You("must put it down to unlock."); + obj->lknown = 1; + return 0; + } else if (obj->otrapped) { + if (held) + You("open %s...", the(xname(obj))); + obj->lknown = 1; + (void) chest_trap(obj, HAND, FALSE); + /* even if the trap fails, you've used up this turn */ + if (multi >= 0) { /* in case we didn't become paralyzed */ + nomul(-1); + multi_reason = "opening a container"; + nomovemsg = ""; + } + return 1; + } + obj->lknown = 1; - current_container = obj; /* for use by in/out_container */ - /* from here on out, all early returns go through containerdone */ + current_container = obj; /* for use by in/out_container */ + /* from here on out, all early returns go through containerdone */ - /* check for Schroedinger's Cat */ - quantum_cat = SchroedingersBox(current_container); - if (quantum_cat) { - observe_quantum_cat(current_container); - used = 1; - } - /* sometimes toss objects if a cursed magic bag */ - cursed_mbag = (Is_mbag(current_container) && - current_container->cursed && - Has_contents(current_container)); - if (cursed_mbag) { - long loss = 0L; + /* check for Schroedinger's Cat */ + quantum_cat = SchroedingersBox(current_container); + if (quantum_cat) { + observe_quantum_cat(current_container); + used = 1; + } + /* sometimes toss objects if a cursed magic bag */ + cursed_mbag = (Is_mbag(current_container) && current_container->cursed + && Has_contents(current_container)); + if (cursed_mbag) { + long loss = 0L; - for (curr = current_container->cobj; curr; curr = otmp) { - otmp = curr->nobj; - if (!rn2(13)) { - obj_extract_self(curr); - loss += mbag_item_gone(held, curr); - used = 1; - } - } - if (loss) - You("owe %ld %s for lost merchandise.", loss, currency(loss)); - current_container->owt = weight(current_container); - } - inokay = (invent != 0 && - !(invent == current_container && !current_container->nobj)); - outokay = Has_contents(current_container); - if (!outokay) /* preformat the empty-container message */ - Sprintf(emptymsg, "%s is %sempty.", - Ysimple_name2(current_container), - (quantum_cat || cursed_mbag) ? "now " : ""); + for (curr = current_container->cobj; curr; curr = otmp) { + otmp = curr->nobj; + if (!rn2(13)) { + obj_extract_self(curr); + loss += mbag_item_gone(held, curr); + used = 1; + } + } + if (loss) + You("owe %ld %s for lost merchandise.", loss, currency(loss)); + current_container->owt = weight(current_container); + } + inokay = (invent != 0 + && !(invent == current_container && !current_container->nobj)); + outokay = Has_contents(current_container); + if (!outokay) /* preformat the empty-container message */ + Sprintf(emptymsg, "%s is %sempty.", Ysimple_name2(current_container), + (quantum_cat || cursed_mbag) ? "now " : ""); - /* - * What-to-do prompt's list of possible actions: - * always include the look-inside choice (':'); - * include the take-out choice ('o') if container - * has anything in it or if player doesn't yet know - * that it's empty (latter can change on subsequent - * iterations if player picks ':' response); - * include the put-in choices ('i','s') if hero - * carries any inventory (including gold); - * include do-both when 'o' is available, even if - * inventory is empty--taking out could alter that; - * include do-both-reversed when 'i' is available, - * even if container is empty--for similar reason; - * always include the quit choice ('q'). - * include the help choice (" or ?") if `cmdassist' - * run-time option is set; - * (Player can pick any of (o,i,b,r,s,?) even when - * they're not listed among the available actions.) - * - * Do what with ? [:oibrsq or ?] (q) - * or - * is empty. Do what with it? [:irsq or ?] - */ - for (;;) { /* repeats if '?' or ":' gets chosen */ - outmaybe = (outokay || !current_container->cknown); - if (!outmaybe) - (void)safe_qbuf(qbuf, (char *)0, - " is empty. Do what with it?", - current_container, - Yname2, Ysimple_name2, "This"); - else - (void)safe_qbuf(qbuf, "Do what with ", "?", - current_container, yname, ysimple_name, "it"); - /* ask player about what to do with this container */ - if (flags.menu_style == MENU_FULL) { - if (!inokay && !outmaybe) { - /* nothing to take out, nothing to put in; - trying to do both will yield proper feedback */ - c = 'b'; - } else { - c = in_or_out_menu(qbuf, current_container, - outmaybe, inokay, (used != 0)); - } - } else { /* TRADITIONAL, COMBINATION, or PARTIAL */ - xbuf[0] = '\0'; /* list of extra acceptable responses */ - Strcpy(pbuf, ":"); /* look inside */ - Strcat(outmaybe ? pbuf : xbuf, "o"); /* take out */ - Strcat(inokay ? pbuf : xbuf, "i"); /* put in */ - Strcat(outmaybe ? pbuf : xbuf, "b"); /* both */ - Strcat(inokay ? pbuf : xbuf, "rs"); /* reversed, stash */ - Strcat(pbuf, "q"); /* quit */ - if (iflags.cmdassist) Strcat(pbuf, " or ?"); /* help */ - else Strcat(xbuf, "?"); - if (*xbuf) Strcat(strcat(pbuf, "\033"), xbuf); - c = yn_function(qbuf, pbuf, 'q'); - } /* FULL vs other modes */ + /* + * What-to-do prompt's list of possible actions: + * always include the look-inside choice (':'); + * include the take-out choice ('o') if container + * has anything in it or if player doesn't yet know + * that it's empty (latter can change on subsequent + * iterations if player picks ':' response); + * include the put-in choices ('i','s') if hero + * carries any inventory (including gold); + * include do-both when 'o' is available, even if + * inventory is empty--taking out could alter that; + * include do-both-reversed when 'i' is available, + * even if container is empty--for similar reason; + * always include the quit choice ('q'). + * include the help choice (" or ?") if `cmdassist' + * run-time option is set; + * (Player can pick any of (o,i,b,r,s,?) even when + * they're not listed among the available actions.) + * + * Do what with ? [:oibrsq or ?] (q) + * or + * is empty. Do what with it? [:irsq or ?] + */ + for (;;) { /* repeats if '?' or ":' gets chosen */ + outmaybe = (outokay || !current_container->cknown); + if (!outmaybe) + (void) safe_qbuf(qbuf, (char *) 0, " is empty. Do what with it?", + current_container, Yname2, Ysimple_name2, + "This"); + else + (void) safe_qbuf(qbuf, "Do what with ", "?", current_container, + yname, ysimple_name, "it"); + /* ask player about what to do with this container */ + if (flags.menu_style == MENU_FULL) { + if (!inokay && !outmaybe) { + /* nothing to take out, nothing to put in; + trying to do both will yield proper feedback */ + c = 'b'; + } else { + c = in_or_out_menu(qbuf, current_container, outmaybe, inokay, + (used != 0)); + } + } else { /* TRADITIONAL, COMBINATION, or PARTIAL */ + xbuf[0] = '\0'; /* list of extra acceptable responses */ + Strcpy(pbuf, ":"); /* look inside */ + Strcat(outmaybe ? pbuf : xbuf, "o"); /* take out */ + Strcat(inokay ? pbuf : xbuf, "i"); /* put in */ + Strcat(outmaybe ? pbuf : xbuf, "b"); /* both */ + Strcat(inokay ? pbuf : xbuf, "rs"); /* reversed, stash */ + Strcat(pbuf, "q"); /* quit */ + if (iflags.cmdassist) + Strcat(pbuf, " or ?"); /* help */ + else + Strcat(xbuf, "?"); + if (*xbuf) + Strcat(strcat(pbuf, "\033"), xbuf); + c = yn_function(qbuf, pbuf, 'q'); + } /* FULL vs other modes */ - if (c == '?') { - explain_container_prompt(); - } else if (c == ':') { /* note: will set obj->cknown */ - if (!current_container->cknown) used = 1; /* gaining info */ - container_contents(current_container, FALSE, FALSE, TRUE); - } else - break; - } /* loop until something other than '?' or ':' is picked */ + if (c == '?') { + explain_container_prompt(); + } else if (c == ':') { /* note: will set obj->cknown */ + if (!current_container->cknown) + used = 1; /* gaining info */ + container_contents(current_container, FALSE, FALSE, TRUE); + } else + break; + } /* loop until something other than '?' or ':' is picked */ - if (c == 'q') /* [not strictly needed; falling through works] */ - goto containerdone; - loot_out = (c == 'o' || c == 'b' || c == 'r'); - loot_in = (c == 'i' || c == 'b' || c == 'r'); - loot_in_first = (c == 'r'); /* both, reversed */ - stash_one = (c == 's'); + if (c == 'q') /* [not strictly needed; falling through works] */ + goto containerdone; + loot_out = (c == 'o' || c == 'b' || c == 'r'); + loot_in = (c == 'i' || c == 'b' || c == 'r'); + loot_in_first = (c == 'r'); /* both, reversed */ + stash_one = (c == 's'); - /* out-only or out before in */ - if (loot_out && !loot_in_first) { - if (!Has_contents(current_container)) { - pline1(emptymsg); /* is empty. */ - if (!current_container->cknown) used = 1; - current_container->cknown = 1; - } else { - add_valid_menu_class(0); /* reset */ - if (flags.menu_style == MENU_TRADITIONAL) - used |= traditional_loot(FALSE); - else - used |= (menu_loot(0, FALSE) > 0); - } - } + /* out-only or out before in */ + if (loot_out && !loot_in_first) { + if (!Has_contents(current_container)) { + pline1(emptymsg); /* is empty. */ + if (!current_container->cknown) + used = 1; + current_container->cknown = 1; + } else { + add_valid_menu_class(0); /* reset */ + if (flags.menu_style == MENU_TRADITIONAL) + used |= traditional_loot(FALSE); + else + used |= (menu_loot(0, FALSE) > 0); + } + } - if ((loot_in || stash_one) && - (!invent || (invent == current_container && !invent->nobj))) { - You("don't have anything%s to %s.", - invent ? " else" : "", stash_one ? "stash" : "put in"); - loot_in = stash_one = FALSE; - } + if ((loot_in || stash_one) + && (!invent || (invent == current_container && !invent->nobj))) { + You("don't have anything%s to %s.", invent ? " else" : "", + stash_one ? "stash" : "put in"); + loot_in = stash_one = FALSE; + } - /* - * Gone: being nice about only selecting food if we know we are - * putting things in an ice chest. - */ - if (loot_in) { - add_valid_menu_class(0); /* reset */ - if (flags.menu_style == MENU_TRADITIONAL) - used |= traditional_loot(TRUE); - else - used |= (menu_loot(0, TRUE) > 0); - } else if (stash_one) { - /* put one item into container */ - if ((otmp = getobj(stashable, "stash")) != 0) { - if (in_container(otmp)) { - used = 1; - } else { - /* couldn't put selected item into container for some - reason; might need to undo splitobj() */ - for (curr = invent; curr; curr = curr->nobj) - if (curr->nobj == otmp) break; - if (curr && curr->invlet == otmp->invlet) - (void)merged(&curr, &otmp); - } - } - } - /* putting something in might have triggered magic bag explosion */ - if (!current_container) loot_out = FALSE; + /* + * Gone: being nice about only selecting food if we know we are + * putting things in an ice chest. + */ + if (loot_in) { + add_valid_menu_class(0); /* reset */ + if (flags.menu_style == MENU_TRADITIONAL) + used |= traditional_loot(TRUE); + else + used |= (menu_loot(0, TRUE) > 0); + } else if (stash_one) { + /* put one item into container */ + if ((otmp = getobj(stashable, "stash")) != 0) { + if (in_container(otmp)) { + used = 1; + } else { + /* couldn't put selected item into container for some + reason; might need to undo splitobj() */ + for (curr = invent; curr; curr = curr->nobj) + if (curr->nobj == otmp) + break; + if (curr && curr->invlet == otmp->invlet) + (void) merged(&curr, &otmp); + } + } + } + /* putting something in might have triggered magic bag explosion */ + if (!current_container) + loot_out = FALSE; - /* out after in */ - if (loot_out && loot_in_first) { - if (!Has_contents(current_container)) { - pline1(emptymsg); /* is empty. */ - if (!current_container->cknown) used = 1; - current_container->cknown = 1; - } else { - add_valid_menu_class(0); /* reset */ - if (flags.menu_style == MENU_TRADITIONAL) - used |= traditional_loot(FALSE); - else - used |= (menu_loot(0, FALSE) > 0); - } - } + /* out after in */ + if (loot_out && loot_in_first) { + if (!Has_contents(current_container)) { + pline1(emptymsg); /* is empty. */ + if (!current_container->cknown) + used = 1; + current_container->cknown = 1; + } else { + add_valid_menu_class(0); /* reset */ + if (flags.menu_style == MENU_TRADITIONAL) + used |= traditional_loot(FALSE); + else + used |= (menu_loot(0, FALSE) > 0); + } + } - containerdone: - if (used) { - /* Not completely correct; if we put something in without knowing - whatever was already inside, now we suddenly do. That can't - be helped unless we want to track things item by item and then - deal with containers whose contents are "partly known". */ - if (current_container) current_container->cknown = 1; - update_inventory(); - } +containerdone: + if (used) { + /* Not completely correct; if we put something in without knowing + whatever was already inside, now we suddenly do. That can't + be helped unless we want to track things item by item and then + deal with containers whose contents are "partly known". */ + if (current_container) + current_container->cknown = 1; + update_inventory(); + } - *objp = current_container; /* might have become null */ - current_container = 0; /* avoid hanging on to stale pointer */ - return used; + *objp = current_container; /* might have become null */ + current_container = 0; /* avoid hanging on to stale pointer */ + return used; } /* loot current_container (take things out or put things in), by prompting */ @@ -2376,34 +2485,32 @@ STATIC_OVL int traditional_loot(put_in) boolean put_in; { - int FDECL((*actionfunc), (OBJ_P)), - FDECL((*checkfunc), (OBJ_P)); + int FDECL((*actionfunc), (OBJ_P)), FDECL((*checkfunc), (OBJ_P)); struct obj **objlist; - char selection[MAXOCLASSES+1]; + char selection[MAXOCLASSES + 1]; const char *action; boolean one_by_one, allflag; int used = 0, menu_on_request = 0; if (put_in) { - action = "put in"; - objlist = &invent; - actionfunc = in_container; - checkfunc = ck_bag; + action = "put in"; + objlist = &invent; + actionfunc = in_container; + checkfunc = ck_bag; } else { - action = "take out"; - objlist = &(current_container->cobj); - actionfunc = out_container; - checkfunc = (int FDECL((*), (OBJ_P)))0; + action = "take out"; + objlist = &(current_container->cobj); + actionfunc = out_container; + checkfunc = (int FDECL((*), (OBJ_P))) 0; } - if (query_classes(selection, &one_by_one, &allflag, - action, *objlist, FALSE, - &menu_on_request)) { - if (askchain(objlist, (one_by_one ? (char *)0 : selection), - allflag, actionfunc, checkfunc, 0, action)) - used = 1; + if (query_classes(selection, &one_by_one, &allflag, action, *objlist, + FALSE, &menu_on_request)) { + if (askchain(objlist, (one_by_one ? (char *) 0 : selection), allflag, + actionfunc, checkfunc, 0, action)) + used = 1; } else if (menu_on_request < 0) { - used = (menu_loot(menu_on_request, put_in) > 0); + used = (menu_loot(menu_on_request, put_in) > 0); } return used; } @@ -2424,65 +2531,70 @@ boolean put_in; long count; if (retry) { - all_categories = (retry == -2); + all_categories = (retry == -2); } else if (flags.menu_style == MENU_FULL) { - all_categories = FALSE; - Sprintf(buf, "%s what type of objects?", action); - mflags = put_in ? ALL_TYPES | BUC_ALLBKNOWN | BUC_UNKNOWN : - ALL_TYPES | CHOOSE_ALL | BUC_ALLBKNOWN | BUC_UNKNOWN; - n = query_category(buf, put_in ? invent : current_container->cobj, - mflags, &pick_list, PICK_ANY); - if (!n) return 0; - for (i = 0; i < n; i++) { - if (pick_list[i].item.a_int == 'A') - loot_everything = TRUE; - else if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) - all_categories = TRUE; - else - add_valid_menu_class(pick_list[i].item.a_int); - } - free((genericptr_t) pick_list); + all_categories = FALSE; + Sprintf(buf, "%s what type of objects?", action); + mflags = put_in + ? ALL_TYPES | BUC_ALLBKNOWN | BUC_UNKNOWN + : ALL_TYPES | CHOOSE_ALL | BUC_ALLBKNOWN | BUC_UNKNOWN; + n = query_category(buf, put_in ? invent : current_container->cobj, + mflags, &pick_list, PICK_ANY); + if (!n) + return 0; + for (i = 0; i < n; i++) { + if (pick_list[i].item.a_int == 'A') + loot_everything = TRUE; + else if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) + all_categories = TRUE; + else + add_valid_menu_class(pick_list[i].item.a_int); + } + free((genericptr_t) pick_list); } if (loot_everything) { - current_container->cknown = 1; - for (otmp = current_container->cobj; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - res = out_container(otmp); - if (res < 0) break; - } + current_container->cknown = 1; + for (otmp = current_container->cobj; otmp; otmp = otmp2) { + otmp2 = otmp->nobj; + res = out_container(otmp); + if (res < 0) + break; + } } else { - mflags = INVORDER_SORT; - if (put_in && flags.invlet_constant) mflags |= USE_INVLET; - if (!put_in) current_container->cknown = 1; - Sprintf(buf, "%s what?", action); - n = query_objlist(buf, put_in ? invent : current_container->cobj, - mflags, &pick_list, PICK_ANY, - all_categories ? allow_all : allow_category); - if (n) { - n_looted = n; - for (i = 0; i < n; i++) { - otmp = pick_list[i].item.a_obj; - count = pick_list[i].count; - if (count > 0 && count < otmp->quan) { - otmp = splitobj(otmp, count); - /* special split case also handled by askchain() */ - } - res = put_in ? in_container(otmp) : out_container(otmp); - if (res < 0) { - if (!current_container) { - /* otmp caused current_container to explode; - both are now gone */ - otmp = 0; /* and break loop */ - } else if (otmp && otmp != pick_list[i].item.a_obj) { - /* split occurred, merge again */ - (void) merged(&pick_list[i].item.a_obj, &otmp); - } - break; - } - } - free((genericptr_t)pick_list); - } + mflags = INVORDER_SORT; + if (put_in && flags.invlet_constant) + mflags |= USE_INVLET; + if (!put_in) + current_container->cknown = 1; + Sprintf(buf, "%s what?", action); + n = query_objlist(buf, put_in ? invent : current_container->cobj, + mflags, &pick_list, PICK_ANY, + all_categories ? allow_all : allow_category); + if (n) { + n_looted = n; + for (i = 0; i < n; i++) { + otmp = pick_list[i].item.a_obj; + count = pick_list[i].count; + if (count > 0 && count < otmp->quan) { + otmp = splitobj(otmp, count); + /* special split case also handled by askchain() */ + } + res = put_in ? in_container(otmp) : out_container(otmp); + if (res < 0) { + if (!current_container) { + /* otmp caused current_container to explode; + both are now gone */ + otmp = 0; /* and break loop */ + } else if (otmp && otmp != pick_list[i].item.a_obj) { + /* split occurred, merge again */ + (void) merged(&pick_list[i].item.a_obj, &otmp); + } + break; + } + } + free((genericptr_t) pick_list); + } } return n_looted; } @@ -2494,8 +2606,7 @@ struct obj *obj; boolean outokay, inokay, alreadyused; { /* underscore is not a choice; it's used to skip element [0] */ - static const char lootchars[] = "_:oibrsq", - abc_chars[] = "_:abcdeq"; + static const char lootchars[] = "_:oibrsq", abc_chars[] = "_:abcdeq"; winid win; anything any; menu_item *pick_list; @@ -2507,53 +2618,53 @@ boolean outokay, inokay, alreadyused; win = create_nhwindow(NHW_MENU); start_menu(win); - any.a_int = 1; /* ':' */ + any.a_int = 1; /* ':' */ Sprintf(buf, "Look inside %s", thesimpleoname(obj)); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, buf, + MENU_UNSELECTED); if (outokay) { - any.a_int = 2; /* 'o' */ - Sprintf(buf, "take %s out", something); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); + any.a_int = 2; /* 'o' */ + Sprintf(buf, "take %s out", something); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, + buf, MENU_UNSELECTED); } if (inokay) { - any.a_int = 3; /* 'i' */ - Sprintf(buf, "put %s in", something); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); + any.a_int = 3; /* 'i' */ + Sprintf(buf, "put %s in", something); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, + buf, MENU_UNSELECTED); } if (outokay) { - any.a_int = 4; /* 'b' */ - Sprintf(buf, "%stake out, then put in", inokay ? "both; " : ""); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); + any.a_int = 4; /* 'b' */ + Sprintf(buf, "%stake out, then put in", inokay ? "both; " : ""); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, + buf, MENU_UNSELECTED); } if (inokay) { - any.a_int = 5; /* 'r' */ - Sprintf(buf, "%sput in, then take out", - outokay ? "both reversed; " : ""); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); - any.a_int = 6; /* 's' */ - Sprintf(buf, "stash one item into %s", thesimpleoname(obj)); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_UNSELECTED); + any.a_int = 5; /* 'r' */ + Sprintf(buf, "%sput in, then take out", + outokay ? "both reversed; " : ""); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, + buf, MENU_UNSELECTED); + any.a_int = 6; /* 's' */ + Sprintf(buf, "stash one item into %s", thesimpleoname(obj)); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, + buf, MENU_UNSELECTED); } - any.a_int = 7; /* 'q' */ + any.a_int = 7; /* 'q' */ Strcpy(buf, alreadyused ? "done" : "do nothing"); - add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, - buf, MENU_SELECTED); + add_menu(win, NO_GLYPH, &any, menuselector[any.a_int], 0, ATR_NONE, buf, + MENU_SELECTED); end_menu(win, prompt); n = select_menu(win, PICK_ONE, &pick_list); destroy_nhwindow(win); if (n > 0) { - n = pick_list[0].item.a_int; - free((genericptr_t) pick_list); - return lootchars[n]; /* :,o,i,b,r,s,q */ + n = pick_list[0].item.a_int; + free((genericptr_t) pick_list); + return lootchars[n]; /* :,o,i,b,r,s,q */ } - return 'q'; /* quit */ + return 'q'; /* quit */ } static const char tippables[] = { ALL_CLASSES, TOOL_CLASS, 0 }; @@ -2578,206 +2689,213 @@ dotip() /* check floor container(s) first; at most one will be accessed */ if ((boxes = container_at(cc.x, cc.y, TRUE)) > 0) { - if (flags.verbose) - pline("There %s here.", - (boxes > 1) ? "are containers" : "is a container"); - Sprintf(buf, "You can't tip %s while carrying so much.", - !flags.verbose ? "a container" : (boxes > 1) ? "one" : "it"); - if (!check_capacity(buf) && able_to_loot(cc.x, cc.y, FALSE)) { - for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) { - nobj = cobj->nexthere; - if (!Is_container(cobj)) continue; + if (flags.verbose) + pline("There %s here.", + (boxes > 1) ? "are containers" : "is a container"); + Sprintf(buf, "You can't tip %s while carrying so much.", + !flags.verbose ? "a container" : (boxes > 1) ? "one" : "it"); + if (!check_capacity(buf) && able_to_loot(cc.x, cc.y, FALSE)) { + for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) { + nobj = cobj->nexthere; + if (!Is_container(cobj)) + continue; - c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?", - cobj, doname, ansimpleoname, "container")); - if (c == 'q') return 0; - if (c == 'n') continue; - - tipcontainer(cobj); - return 1; - } /* next cobj */ - } + c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?", cobj, + doname, ansimpleoname, "container")); + if (c == 'q') + return 0; + if (c == 'n') + continue; + + tipcontainer(cobj); + return 1; + } /* next cobj */ + } } /* either no floor container(s) or couldn't tip one or didn't tip any */ cobj = getobj(tippables, "tip"); - if (!cobj) return 0; + if (!cobj) + return 0; /* normal case */ if (Is_container(cobj) || cobj->otyp == HORN_OF_PLENTY) { - tipcontainer(cobj); - return 1; + tipcontainer(cobj); + return 1; } /* assorted other cases */ if (Is_candle(cobj) && cobj->lamplit) { - /* note "wax" even for tallow candles to avoid giving away info */ - spillage = "wax"; - } else if ((cobj->otyp == POT_OIL && cobj->lamplit) || - (cobj->otyp == OIL_LAMP && cobj->age != 0L) || - (cobj->otyp == MAGIC_LAMP && cobj->spe != 0)) { - spillage = "oil"; - /* todo: reduce potion's remaining burn timer or oil lamp's fuel */ + /* note "wax" even for tallow candles to avoid giving away info */ + spillage = "wax"; + } else if ((cobj->otyp == POT_OIL && cobj->lamplit) + || (cobj->otyp == OIL_LAMP && cobj->age != 0L) + || (cobj->otyp == MAGIC_LAMP && cobj->spe != 0)) { + spillage = "oil"; + /* todo: reduce potion's remaining burn timer or oil lamp's fuel */ } else if (cobj->otyp == CAN_OF_GREASE && cobj->spe > 0) { - /* charged consumed below */ - spillage = "grease"; - } else if (cobj->otyp == FOOD_RATION || - cobj->otyp == CRAM_RATION || - cobj->otyp == LEMBAS_WAFER) { - spillage = "crumbs"; + /* charged consumed below */ + spillage = "grease"; + } else if (cobj->otyp == FOOD_RATION || cobj->otyp == CRAM_RATION + || cobj->otyp == LEMBAS_WAFER) { + spillage = "crumbs"; } else if (cobj->oclass == VENOM_CLASS) { - spillage = "venom"; + spillage = "venom"; } if (spillage) { - buf[0] = '\0'; - if (is_pool(u.ux, u.uy)) - Sprintf(buf, " and gradually %s", vtense(spillage, "dissipate")); - else if (is_lava(u.ux, u.uy)) - Sprintf(buf, " and immediately %s away", vtense(spillage, "burn")); - pline("Some %s %s onto the %s%s.", - spillage, vtense(spillage, "spill"), - surface(u.ux, u.uy), buf); - /* shop usage message comes after the spill message */ - if (cobj->otyp == CAN_OF_GREASE && cobj->spe > 0) { - consume_obj_charge(cobj, TRUE); - } - /* something [useless] happened */ - return 1; + buf[0] = '\0'; + if (is_pool(u.ux, u.uy)) + Sprintf(buf, " and gradually %s", vtense(spillage, "dissipate")); + else if (is_lava(u.ux, u.uy)) + Sprintf(buf, " and immediately %s away", + vtense(spillage, "burn")); + pline("Some %s %s onto the %s%s.", spillage, + vtense(spillage, "spill"), surface(u.ux, u.uy), buf); + /* shop usage message comes after the spill message */ + if (cobj->otyp == CAN_OF_GREASE && cobj->spe > 0) { + consume_obj_charge(cobj, TRUE); + } + /* something [useless] happened */ + return 1; } /* anything not covered yet */ - if (cobj->oclass == POTION_CLASS) /* can't pour potions... */ - pline_The("%s %s securely sealed.", xname(cobj), otense(cobj, "are")); + if (cobj->oclass == POTION_CLASS) /* can't pour potions... */ + pline_The("%s %s securely sealed.", xname(cobj), otense(cobj, "are")); else if (cobj->otyp == STATUE) - pline("Nothing interesting happens."); + pline("Nothing interesting happens."); else - pline1(nothing_happens); + pline1(nothing_happens); return 0; } STATIC_OVL void tipcontainer(box) -struct obj *box; /* or bag */ +struct obj *box; /* or bag */ { xchar ox = u.ux, oy = u.uy; /* #tip only works at hero's location */ boolean empty_it = FALSE, - /* Shop handling: can't rely on the container's own unpaid - or no_charge status because contents might differ with it. - A carried container's contents will be flagged as unpaid - or not, as appropriate, and need no special handling here. - Items owned by the hero get sold to the shop without - confirmation as with other uncontrolled drops. A floor - container's contents will be marked no_charge if owned by - hero, otherwise they're owned by the shop. By passing - the contents through shop billing, they end up getting - treated the same as in the carried case. We do so one - item at a time instead of doing whole container at once - to reduce the chance of exhausting shk's billing capacity. */ - maybeshopgoods = !carried(box) && costly_spot(ox, oy); + /* Shop handling: can't rely on the container's own unpaid + or no_charge status because contents might differ with it. + A carried container's contents will be flagged as unpaid + or not, as appropriate, and need no special handling here. + Items owned by the hero get sold to the shop without + confirmation as with other uncontrolled drops. A floor + container's contents will be marked no_charge if owned by + hero, otherwise they're owned by the shop. By passing + the contents through shop billing, they end up getting + treated the same as in the carried case. We do so one + item at a time instead of doing whole container at once + to reduce the chance of exhausting shk's billing capacity. */ + maybeshopgoods = !carried(box) && costly_spot(ox, oy); /* caveat: this assumes that cknown, lknown, olocked, and otrapped fields haven't been overloaded to mean something special for the non-standard "container" horn of plenty */ box->lknown = 1; if (box->olocked) { - pline("It's locked."); + pline("It's locked."); } else if (box->otrapped) { - /* we're not reaching inside but we're still handling it... */ - (void) chest_trap(box, HAND, FALSE); - /* even if the trap fails, you've used up this turn */ - if (multi >= 0) { /* in case we didn't become paralyzed */ - nomul(-1); - multi_reason = "tipping a container"; - nomovemsg = ""; - } + /* we're not reaching inside but we're still handling it... */ + (void) chest_trap(box, HAND, FALSE); + /* even if the trap fails, you've used up this turn */ + if (multi >= 0) { /* in case we didn't become paralyzed */ + nomul(-1); + multi_reason = "tipping a container"; + nomovemsg = ""; + } } else if (box->otyp == BAG_OF_TRICKS || box->otyp == HORN_OF_PLENTY) { - boolean bag = box->otyp == BAG_OF_TRICKS; - int old_spe = box->spe, seen = 0; + boolean bag = box->otyp == BAG_OF_TRICKS; + int old_spe = box->spe, seen = 0; - if (maybeshopgoods && !box->no_charge) - addtobill(box, FALSE, FALSE, TRUE); - /* apply this bag/horn until empty or monster/object creation fails - (if the latter occurs, force the former...) */ - do { - if (!(bag ? bagotricks(box, TRUE, &seen) : hornoplenty(box, TRUE))) - break; - } while (box->spe > 0); + if (maybeshopgoods && !box->no_charge) + addtobill(box, FALSE, FALSE, TRUE); + /* apply this bag/horn until empty or monster/object creation fails + (if the latter occurs, force the former...) */ + do { + if (!(bag ? bagotricks(box, TRUE, &seen) + : hornoplenty(box, TRUE))) + break; + } while (box->spe > 0); - if (box->spe < old_spe) { - if (bag) pline((seen == 0) ? "Nothing seems to happen." : - (seen == 1) ? "A monster appears." : - "Monsters appear!"); - /* check_unpaid wants to see a non-zero charge count */ - box->spe = old_spe; - check_unpaid_usage(box, TRUE); - box->spe = 0; /* empty */ - box->cknown = 1; - } - if (maybeshopgoods && !box->no_charge) - subfrombill(box, shop_keeper(*in_rooms(ox, oy, SHOPBASE))); + if (box->spe < old_spe) { + if (bag) + pline((seen == 0) ? "Nothing seems to happen." + : (seen == 1) ? "A monster appears." + : "Monsters appear!"); + /* check_unpaid wants to see a non-zero charge count */ + box->spe = old_spe; + check_unpaid_usage(box, TRUE); + box->spe = 0; /* empty */ + box->cknown = 1; + } + if (maybeshopgoods && !box->no_charge) + subfrombill(box, shop_keeper(*in_rooms(ox, oy, SHOPBASE))); } else if (SchroedingersBox(box)) { - char yourbuf[BUFSZ]; + char yourbuf[BUFSZ]; - observe_quantum_cat(box); - if (!Has_contents(box)) /* evidently a live cat came out */ - /* container type of "large box" is inferred */ - pline("%sbox is now empty.", Shk_Your(yourbuf, box)); - else /* holds cat corpse or other random stuff */ - empty_it = TRUE; - box->cknown = 1; + observe_quantum_cat(box); + if (!Has_contents(box)) /* evidently a live cat came out */ + /* container type of "large box" is inferred */ + pline("%sbox is now empty.", Shk_Your(yourbuf, box)); + else /* holds cat corpse or other random stuff */ + empty_it = TRUE; + box->cknown = 1; } else if (!Has_contents(box)) { - box->cknown = 1; - pline("It's empty."); + box->cknown = 1; + pline("It's empty."); } else { - empty_it = TRUE; + empty_it = TRUE; } if (empty_it) { - struct obj *otmp, *nobj; - boolean verbose = FALSE, - highdrop = !can_reach_floor(TRUE), - altarizing = IS_ALTAR(levl[ox][oy].typ), - cursed_mbag = (Is_mbag(box) && box->cursed); - int held = carried(box); - long loss = 0L; + struct obj *otmp, *nobj; + boolean verbose = FALSE, highdrop = !can_reach_floor(TRUE), + altarizing = IS_ALTAR(levl[ox][oy].typ), + cursed_mbag = (Is_mbag(box) && box->cursed); + int held = carried(box); + long loss = 0L; - if (u.uswallow) highdrop = altarizing = FALSE; - box->cknown = 1; - pline("%s out%c", - box->cobj->nobj ? "Objects spill" : "An object spills", - !(highdrop || altarizing) ? ':' : '.'); - for (otmp = box->cobj; otmp; otmp = nobj) { - nobj = otmp->nobj; - obj_extract_self(otmp); - if (cursed_mbag && !rn2(13)) { - loss += mbag_item_gone(held, otmp); - /* abbreviated drop format is no longer appropriate */ - verbose = TRUE; - continue; - } + if (u.uswallow) + highdrop = altarizing = FALSE; + box->cknown = 1; + pline("%s out%c", + box->cobj->nobj ? "Objects spill" : "An object spills", + !(highdrop || altarizing) ? ':' : '.'); + for (otmp = box->cobj; otmp; otmp = nobj) { + nobj = otmp->nobj; + obj_extract_self(otmp); + if (cursed_mbag && !rn2(13)) { + loss += mbag_item_gone(held, otmp); + /* abbreviated drop format is no longer appropriate */ + verbose = TRUE; + continue; + } - if (maybeshopgoods) { - addtobill(otmp, FALSE, FALSE, TRUE); - iflags.suppress_price++; /* doname formatting */ - } + if (maybeshopgoods) { + addtobill(otmp, FALSE, FALSE, TRUE); + iflags.suppress_price++; /* doname formatting */ + } - if (highdrop) { - /* might break or fall down stairs; handles altars itself */ - hitfloor(otmp); - } else { - if (altarizing) - doaltarobj(otmp); - else if (verbose) - pline("%s %s to the %s.", Doname2(otmp), - otense(otmp, "drop"), surface(ox, oy)); - else - pline("%s%c", doname(otmp), nobj ? ',' : '.'); - dropy(otmp); - } - if (maybeshopgoods) iflags.suppress_price--; /* reset */ - } - if (loss) /* magic bag lost some shop goods */ - You("owe %ld %s for lost merchandise.", loss, currency(loss)); - box->owt = weight(box); /* mbag_item_gone() doesn't update this */ - if (held) (void)encumber_msg(); + if (highdrop) { + /* might break or fall down stairs; handles altars itself */ + hitfloor(otmp); + } else { + if (altarizing) + doaltarobj(otmp); + else if (verbose) + pline("%s %s to the %s.", Doname2(otmp), + otense(otmp, "drop"), surface(ox, oy)); + else + pline("%s%c", doname(otmp), nobj ? ',' : '.'); + dropy(otmp); + } + if (maybeshopgoods) + iflags.suppress_price--; /* reset */ + } + if (loss) /* magic bag lost some shop goods */ + You("owe %ld %s for lost merchandise.", loss, currency(loss)); + box->owt = weight(box); /* mbag_item_gone() doesn't update this */ + if (held) + (void) encumber_msg(); } } diff --git a/src/pline.c b/src/pline.c index 347ab2770..74e431184 100644 --- a/src/pline.c +++ b/src/pline.c @@ -1,9 +1,10 @@ -/* NetHack 3.6 pline.c $NHDT-Date: 1429666920 2015/04/22 01:42:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.37 $ */ +/* NetHack 3.6 pline.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.40 $ */ /* NetHack 3.6 pline.c $Date: 2013/02/09 01:33:37 $ $Revision: 1.30 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ -#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */ +#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers \ + */ #include "hack.h" static boolean no_repeat = FALSE; @@ -18,84 +19,93 @@ static char *FDECL(You_buf, (int)); #if defined(USE_STDARG) || defined(USE_VARARGS) static void FDECL(vpline, (const char *, va_list)); -void -pline VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, char *); - vpline(line, VA_ARGS); - VA_END(); +void pline +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, char *); + vpline(line, VA_ARGS); + VA_END(); } -# ifdef USE_STDARG +#ifdef USE_STDARG static void -vpline(const char *line, va_list the_args) { -# else +vpline(const char *line, va_list the_args) +{ +#else static void -vpline(line, the_args) const char *line; va_list the_args; { -# endif +vpline(line, the_args) +const char *line; +va_list the_args; +{ +#endif -#else /* USE_STDARG | USE_VARARG */ +#else /* USE_STDARG | USE_VARARG */ #define vpline pline -void -pline VA_DECL(const char *, line) -#endif /* USE_STDARG | USE_VARARG */ +void pline +VA_DECL(const char *, line) +#endif /* USE_STDARG | USE_VARARG */ - char pbuf[3*BUFSZ]; - int ln; -/* Do NOT use VA_START and VA_END in here... see above */ + char pbuf[3 * BUFSZ]; + int ln; + /* Do NOT use VA_START and VA_END in here... see above */ - if (!line || !*line) return; + if (!line || !*line) + return; #ifdef HANGUPHANDLING - if (program_state.done_hup) return; + if (program_state.done_hup) + return; #endif - if (program_state.wizkit_wishing) return; + if (program_state.wizkit_wishing) + return; - if (index(line, '%')) { - Vsprintf(pbuf,line,VA_ARGS); - line = pbuf; - } - if ((ln = (int)strlen(line)) > BUFSZ-1) { - if (line != pbuf) /* no '%' was present */ - (void)strncpy(pbuf, line, BUFSZ-1); /* caveat: unterminated */ - /* truncate, preserving the final 3 characters: - "___ extremely long text" -> "___ extremely l...ext" - (this may be suboptimal if overflow is less than 3) */ - (void)strncpy(pbuf + BUFSZ-1 - 6, "...", 3); - /* avoid strncpy; buffers could overlap if excess is small */ - pbuf[BUFSZ-1 - 3] = line[ln - 3]; - pbuf[BUFSZ-1 - 2] = line[ln - 2]; - pbuf[BUFSZ-1 - 1] = line[ln - 1]; - pbuf[BUFSZ-1] = '\0'; - line = pbuf; - } - if (!iflags.window_inited) { - raw_print(line); - iflags.last_msg = PLNMSG_UNKNOWN; - return; - } + if (index(line, '%')) { + Vsprintf(pbuf, line, VA_ARGS); + line = pbuf; + } + if ((ln = (int) strlen(line)) > BUFSZ - 1) { + if (line != pbuf) /* no '%' was present */ + (void) strncpy(pbuf, line, BUFSZ - 1); /* caveat: unterminated */ + /* truncate, preserving the final 3 characters: + "___ extremely long text" -> "___ extremely l...ext" + (this may be suboptimal if overflow is less than 3) */ + (void) strncpy(pbuf + BUFSZ - 1 - 6, "...", 3); + /* avoid strncpy; buffers could overlap if excess is small */ + pbuf[BUFSZ - 1 - 3] = line[ln - 3]; + pbuf[BUFSZ - 1 - 2] = line[ln - 2]; + pbuf[BUFSZ - 1 - 1] = line[ln - 1]; + pbuf[BUFSZ - 1] = '\0'; + line = pbuf; + } + if (!iflags.window_inited) { + raw_print(line); + iflags.last_msg = PLNMSG_UNKNOWN; + return; + } #ifndef MAC - if (no_repeat && !strcmp(line, toplines)) - return; + if (no_repeat && !strcmp(line, toplines)) + return; #endif /* MAC */ - if (vision_full_recalc) vision_recalc(0); - if (u.ux) flush_screen(1); /* %% */ - putstr(WIN_MESSAGE, 0, line); - /* this gets cleared after every pline message */ - iflags.last_msg = PLNMSG_UNKNOWN; + if (vision_full_recalc) + vision_recalc(0); + if (u.ux) + flush_screen(1); /* %% */ + putstr(WIN_MESSAGE, 0, line); + /* this gets cleared after every pline message */ + iflags.last_msg = PLNMSG_UNKNOWN; } /*VARARGS1*/ -void -Norep VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, const char *); - no_repeat = TRUE; - vpline(line, VA_ARGS); - no_repeat = FALSE; - VA_END(); - return; +void Norep +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, const char *); + no_repeat = TRUE; + vpline(line, VA_ARGS); + no_repeat = FALSE; + VA_END(); + return; } /* work buffer for You(), &c and verbalize() */ @@ -106,126 +116,128 @@ static char * You_buf(siz) int siz; { - if (siz > you_buf_siz) { - if (you_buf) free((genericptr_t) you_buf); - you_buf_siz = siz + 10; - you_buf = (char *) alloc((unsigned) you_buf_siz); - } - return you_buf; + if (siz > you_buf_siz) { + if (you_buf) + free((genericptr_t) you_buf); + you_buf_siz = siz + 10; + you_buf = (char *) alloc((unsigned) you_buf_siz); + } + return you_buf; } void free_youbuf() { - if (you_buf) free((genericptr_t) you_buf), you_buf = (char *)0; - you_buf_siz = 0; + if (you_buf) + free((genericptr_t) you_buf), you_buf = (char *) 0; + you_buf_siz = 0; } /* `prefix' must be a string literal, not a pointer */ -#define YouPrefix(pointer,prefix,text) \ - Strcpy((pointer = You_buf((int)(strlen(text) + sizeof prefix))), prefix) +#define YouPrefix(pointer, prefix, text) \ + Strcpy((pointer = You_buf((int) (strlen(text) + sizeof prefix))), prefix) -#define YouMessage(pointer,prefix,text) \ - strcat((YouPrefix(pointer, prefix, text), pointer), text) +#define YouMessage(pointer, prefix, text) \ + strcat((YouPrefix(pointer, prefix, text), pointer), text) /*VARARGS1*/ -void -You VA_DECL(const char *, line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - vpline(YouMessage(tmp, "You ", line), VA_ARGS); - VA_END(); +void You +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + vpline(YouMessage(tmp, "You ", line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -Your VA_DECL(const char *,line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - vpline(YouMessage(tmp, "Your ", line), VA_ARGS); - VA_END(); +void Your +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + vpline(YouMessage(tmp, "Your ", line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -You_feel VA_DECL(const char *,line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - if (Unaware) - YouPrefix(tmp, "You dream that you feel ", line); - else - YouPrefix(tmp, "You feel ", line); - vpline(strcat(tmp, line), VA_ARGS); - VA_END(); -} - - -/*VARARGS1*/ -void -You_cant VA_DECL(const char *,line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - vpline(YouMessage(tmp, "You can't ", line), VA_ARGS); - VA_END(); +void You_feel +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + if (Unaware) + YouPrefix(tmp, "You dream that you feel ", line); + else + YouPrefix(tmp, "You feel ", line); + vpline(strcat(tmp, line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -pline_The VA_DECL(const char *,line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - vpline(YouMessage(tmp, "The ", line), VA_ARGS); - VA_END(); +void You_cant +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + vpline(YouMessage(tmp, "You can't ", line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -There VA_DECL(const char *,line) - char *tmp; - VA_START(line); - VA_INIT(line, const char *); - vpline(YouMessage(tmp, "There ", line), VA_ARGS); - VA_END(); +void pline_The +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + vpline(YouMessage(tmp, "The ", line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -You_hear VA_DECL(const char *,line) - char *tmp; - - if (Deaf || !flags.acoustics) return; - VA_START(line); - VA_INIT(line, const char *); - if (Underwater) - YouPrefix(tmp, "You barely hear ", line); - else if (Unaware) - YouPrefix(tmp, "You dream that you hear ", line); - else - YouPrefix(tmp, "You hear ", line); - vpline(strcat(tmp, line), VA_ARGS); - VA_END(); +void There +VA_DECL(const char *, line) + char *tmp; + VA_START(line); + VA_INIT(line, const char *); + vpline(YouMessage(tmp, "There ", line), VA_ARGS); + VA_END(); } /*VARARGS1*/ -void -You_see VA_DECL(const char *,line) - char *tmp; +void You_hear +VA_DECL(const char *, line) + char *tmp; - VA_START(line); - VA_INIT(line, const char *); - if (Unaware) - YouPrefix(tmp, "You dream that you see ", line); - else if (Blind) /* caller should have caught this... */ - YouPrefix(tmp, "You sense ", line); - else - YouPrefix(tmp, "You see ", line); - vpline(strcat(tmp, line), VA_ARGS); - VA_END(); + if (Deaf || !flags.acoustics) + return; + VA_START(line); + VA_INIT(line, const char *); + if (Underwater) + YouPrefix(tmp, "You barely hear ", line); + else if (Unaware) + YouPrefix(tmp, "You dream that you hear ", line); + else + YouPrefix(tmp, "You hear ", line); + vpline(strcat(tmp, line), VA_ARGS); + VA_END(); +} + +/*VARARGS1*/ +void You_see +VA_DECL(const char *, line) + char *tmp; + + VA_START(line); + VA_INIT(line, const char *); + if (Unaware) + YouPrefix(tmp, "You dream that you see ", line); + else if (Blind) /* caller should have caught this... */ + YouPrefix(tmp, "You sense ", line); + else + YouPrefix(tmp, "You see ", line); + vpline(strcat(tmp, line), VA_ARGS); + VA_END(); } /* Print a message inside double-quotes. @@ -233,18 +245,18 @@ You_see VA_DECL(const char *,line) * Gods can speak directly to you in spite of deafness. */ /*VARARGS1*/ -void -verbalize VA_DECL(const char *,line) - char *tmp; +void verbalize +VA_DECL(const char *, line) + char *tmp; - VA_START(line); - VA_INIT(line, const char *); - tmp = You_buf((int)strlen(line) + sizeof "\"\""); - Strcpy(tmp, "\""); - Strcat(tmp, line); - Strcat(tmp, "\""); - vpline(tmp, VA_ARGS); - VA_END(); + VA_START(line); + VA_INIT(line, const char *); + tmp = You_buf((int) strlen(line) + sizeof "\"\""); + Strcpy(tmp, "\""); + Strcat(tmp, line); + Strcat(tmp, "\""); + vpline(tmp, VA_ARGS); + VA_END(); } /*VARARGS1*/ @@ -253,75 +265,83 @@ verbalize VA_DECL(const char *,line) */ #if defined(USE_STDARG) || defined(USE_VARARGS) -static void FDECL(vraw_printf,(const char *,va_list)); +static void FDECL(vraw_printf, (const char *, va_list)); -void -raw_printf VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, char *); - vraw_printf(line, VA_ARGS); - VA_END(); +void raw_printf +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, char *); + vraw_printf(line, VA_ARGS); + VA_END(); } -# ifdef USE_STDARG +#ifdef USE_STDARG static void -vraw_printf(const char *line, va_list the_args) { -# else +vraw_printf(const char *line, va_list the_args) +{ +#else static void -vraw_printf(line, the_args) const char *line; va_list the_args; { -# endif - -#else /* USE_STDARG | USE_VARARG */ - -void -raw_printf VA_DECL(const char *, line) +vraw_printf(line, the_args) +const char *line; +va_list the_args; +{ #endif - char pbuf[3*BUFSZ]; - int ln; -/* Do NOT use VA_START and VA_END in here... see above */ +#else /* USE_STDARG | USE_VARARG */ - if (index(line, '%')) { - Vsprintf(pbuf,line,VA_ARGS); - line = pbuf; - } - if ((ln = (int)strlen(line)) > BUFSZ-1) { - if (line != pbuf) line = strncpy(pbuf, line, BUFSZ-1); - /* unlike pline, we don't futz around to keep last few chars */ - pbuf[BUFSZ-1] = '\0'; /* terminate strncpy or truncate vsprintf */ - } - raw_print(line); +void raw_printf +VA_DECL(const char *, line) +#endif + + char pbuf[3 * BUFSZ]; + int ln; + /* Do NOT use VA_START and VA_END in here... see above */ + + if (index(line, '%')) { + Vsprintf(pbuf, line, VA_ARGS); + line = pbuf; + } + if ((ln = (int) strlen(line)) > BUFSZ - 1) { + if (line != pbuf) + line = strncpy(pbuf, line, BUFSZ - 1); + /* unlike pline, we don't futz around to keep last few chars */ + pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */ + } + raw_print(line); } - /*VARARGS1*/ -void -impossible VA_DECL(const char *, s) - char pbuf[2*BUFSZ]; - VA_START(s); - VA_INIT(s, const char *); - if (program_state.in_impossible) - panic("impossible called impossible"); +void impossible +VA_DECL(const char *, s) + char pbuf[2 * BUFSZ]; + VA_START(s); + VA_INIT(s, const char *); + if (program_state.in_impossible) + panic("impossible called impossible"); - program_state.in_impossible = 1; - Vsprintf(pbuf, s, VA_ARGS); - pbuf[BUFSZ-1] = '\0'; /* sanity */ - paniclog("impossible", pbuf); - pline("%s", pbuf); - pline("Program in disorder - perhaps you'd better #quit."); - program_state.in_impossible = 0; - VA_END(); + program_state.in_impossible = 1; + Vsprintf(pbuf, s, VA_ARGS); + pbuf[BUFSZ - 1] = '\0'; /* sanity */ + paniclog("impossible", pbuf); + pline("%s", pbuf); + pline("Program in disorder - perhaps you'd better #quit."); + program_state.in_impossible = 0; + VA_END(); } const char * align_str(alignment) - aligntyp alignment; +aligntyp alignment; { - switch ((int)alignment) { - case A_CHAOTIC: return "chaotic"; - case A_NEUTRAL: return "neutral"; - case A_LAWFUL: return "lawful"; - case A_NONE: return "unaligned"; + switch ((int) alignment) { + case A_CHAOTIC: + return "chaotic"; + case A_NEUTRAL: + return "neutral"; + case A_LAWFUL: + return "lawful"; + case A_NONE: + return "unaligned"; } return "unknown"; } @@ -330,171 +350,194 @@ void mstatusline(mtmp) register struct monst *mtmp; { - aligntyp alignment = mon_aligntyp(mtmp); - char info[BUFSZ], monnambuf[BUFSZ]; + aligntyp alignment = mon_aligntyp(mtmp); + char info[BUFSZ], monnambuf[BUFSZ]; - info[0] = 0; - if (mtmp->mtame) { Strcat(info, ", tame"); - if (wizard) { - Sprintf(eos(info), " (%d", mtmp->mtame); - if (!mtmp->isminion) - Sprintf(eos(info), "; hungry %ld; apport %d", - EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport); - Strcat(info, ")"); - } - } - else if (mtmp->mpeaceful) Strcat(info, ", peaceful"); - if (mtmp->cham >= LOW_PM && mtmp->data != &mons[mtmp->cham]) - /* don't reveal the innate form (chameleon, vampire, &c), - just expose the fact that this current form isn't it */ - Strcat(info, ", shapechanger"); - /* pets eating mimic corpses mimic while eating, so this comes first */ - if (mtmp->meating) Strcat(info, ", eating"); - /* a stethoscope exposes mimic before getting here so this - won't be relevant for it, but wand of probing doesn't */ - if (mtmp->m_ap_type) - Sprintf(eos(info), ", mimicking %s", - (mtmp->m_ap_type == M_AP_FURNITURE) ? - an(defsyms[mtmp->mappearance].explanation) : - (mtmp->m_ap_type == M_AP_OBJECT) ? - ((mtmp->mappearance == GOLD_PIECE) ? "gold" : - an(simple_typename(mtmp->mappearance))) : - (mtmp->m_ap_type == M_AP_MONSTER) ? - an(mons[mtmp->mappearance].mname) : - something); /* impossible... */ - if (mtmp->mcan) Strcat(info, ", cancelled"); - if (mtmp->mconf) Strcat(info, ", confused"); - if (mtmp->mblinded || !mtmp->mcansee) - Strcat(info, ", blind"); - if (mtmp->mstun) Strcat(info, ", stunned"); - if (mtmp->msleeping) Strcat(info, ", asleep"); -#if 0 /* unfortunately mfrozen covers temporary sleep and being busy - (donning armor, for instance) as well as paralysis */ + info[0] = 0; + if (mtmp->mtame) { + Strcat(info, ", tame"); + if (wizard) { + Sprintf(eos(info), " (%d", mtmp->mtame); + if (!mtmp->isminion) + Sprintf(eos(info), "; hungry %ld; apport %d", + EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport); + Strcat(info, ")"); + } + } else if (mtmp->mpeaceful) + Strcat(info, ", peaceful"); + if (mtmp->cham >= LOW_PM && mtmp->data != &mons[mtmp->cham]) + /* don't reveal the innate form (chameleon, vampire, &c), + just expose the fact that this current form isn't it */ + Strcat(info, ", shapechanger"); + /* pets eating mimic corpses mimic while eating, so this comes first */ + if (mtmp->meating) + Strcat(info, ", eating"); + /* a stethoscope exposes mimic before getting here so this + won't be relevant for it, but wand of probing doesn't */ + if (mtmp->m_ap_type) + Sprintf(eos(info), ", mimicking %s", + (mtmp->m_ap_type == M_AP_FURNITURE) + ? an(defsyms[mtmp->mappearance].explanation) + : (mtmp->m_ap_type == M_AP_OBJECT) + ? ((mtmp->mappearance == GOLD_PIECE) + ? "gold" + : an(simple_typename(mtmp->mappearance))) + : (mtmp->m_ap_type == M_AP_MONSTER) + ? an(mons[mtmp->mappearance].mname) + : something); /* impossible... */ + if (mtmp->mcan) + Strcat(info, ", cancelled"); + if (mtmp->mconf) + Strcat(info, ", confused"); + if (mtmp->mblinded || !mtmp->mcansee) + Strcat(info, ", blind"); + if (mtmp->mstun) + Strcat(info, ", stunned"); + if (mtmp->msleeping) + Strcat(info, ", asleep"); +#if 0 /* unfortunately mfrozen covers temporary sleep and being busy \ + (donning armor, for instance) as well as paralysis */ else if (mtmp->mfrozen) Strcat(info, ", paralyzed"); #else - else if (mtmp->mfrozen || !mtmp->mcanmove) - Strcat(info, ", can't move"); + else if (mtmp->mfrozen || !mtmp->mcanmove) + Strcat(info, ", can't move"); #endif - /* [arbitrary reason why it isn't moving] */ - else if (mtmp->mstrategy & STRAT_WAITMASK) - Strcat(info, ", meditating"); - if (mtmp->mflee) Strcat(info, ", scared"); - if (mtmp->mtrapped) Strcat(info, ", trapped"); - if (mtmp->mspeed) Strcat(info, - mtmp->mspeed == MFAST ? ", fast" : - mtmp->mspeed == MSLOW ? ", slow" : - ", ???? speed"); - if (mtmp->mundetected) Strcat(info, ", concealed"); - if (mtmp->minvis) Strcat(info, ", invisible"); - if (mtmp == u.ustuck) Strcat(info, - sticks(youmonst.data) ? ", held by you" : - !u.uswallow ? ", holding you" : - attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_DGST) ? - ", digesting you" : - is_animal(u.ustuck->data) ? ", swallowing you" : - ", engulfing you"); - if (mtmp == u.usteed) Strcat(info, ", carrying you"); + /* [arbitrary reason why it isn't moving] */ + else if (mtmp->mstrategy & STRAT_WAITMASK) + Strcat(info, ", meditating"); + if (mtmp->mflee) + Strcat(info, ", scared"); + if (mtmp->mtrapped) + Strcat(info, ", trapped"); + if (mtmp->mspeed) + Strcat(info, mtmp->mspeed == MFAST ? ", fast" : mtmp->mspeed == MSLOW + ? ", slow" + : ", ???? speed"); + if (mtmp->mundetected) + Strcat(info, ", concealed"); + if (mtmp->minvis) + Strcat(info, ", invisible"); + if (mtmp == u.ustuck) + Strcat(info, sticks(youmonst.data) + ? ", held by you" + : !u.uswallow ? ", holding you" + : attacktype_fordmg(u.ustuck->data, + AT_ENGL, AD_DGST) + ? ", digesting you" + : is_animal(u.ustuck->data) + ? ", swallowing you" + : ", engulfing you"); + if (mtmp == u.usteed) + Strcat(info, ", carrying you"); - /* avoid "Status of the invisible newt ..., invisible" */ - /* and unlike a normal mon_nam, use "saddled" even if it has a name */ - Strcpy(monnambuf, x_monnam(mtmp, ARTICLE_THE, (char *)0, - (SUPPRESS_IT|SUPPRESS_INVISIBLE), FALSE)); + /* avoid "Status of the invisible newt ..., invisible" */ + /* and unlike a normal mon_nam, use "saddled" even if it has a name */ + Strcpy(monnambuf, x_monnam(mtmp, ARTICLE_THE, (char *) 0, + (SUPPRESS_IT | SUPPRESS_INVISIBLE), FALSE)); - pline("Status of %s (%s): Level %d HP %d(%d) AC %d%s.", - monnambuf, - align_str(alignment), - mtmp->m_lev, - mtmp->mhp, - mtmp->mhpmax, - find_mac(mtmp), - info); + pline("Status of %s (%s): Level %d HP %d(%d) AC %d%s.", monnambuf, + align_str(alignment), mtmp->m_lev, mtmp->mhp, mtmp->mhpmax, + find_mac(mtmp), info); } void ustatusline() { - char info[BUFSZ]; + char info[BUFSZ]; - info[0] = '\0'; - if (Sick) { - Strcat(info, ", dying from"); - if (u.usick_type & SICK_VOMITABLE) - Strcat(info, " food poisoning"); - if (u.usick_type & SICK_NONVOMITABLE) { - if (u.usick_type & SICK_VOMITABLE) - Strcat(info, " and"); - Strcat(info, " illness"); - } - } - if (Stoned) Strcat(info, ", solidifying"); - if (Slimed) Strcat(info, ", becoming slimy"); - if (Strangled) Strcat(info, ", being strangled"); - if (Vomiting) Strcat(info, ", nauseated"); /* !"nauseous" */ - if (Confusion) Strcat(info, ", confused"); - if (Blind) { - Strcat(info, ", blind"); - if (u.ucreamed) { - if ((long)u.ucreamed < Blinded || Blindfolded - || !haseyes(youmonst.data)) - Strcat(info, ", cover"); - Strcat(info, "ed by sticky goop"); - } /* note: "goop" == "glop"; variation is intentional */ - } - if (Stunned) Strcat(info, ", stunned"); - if (!u.usteed && Wounded_legs) { - const char *what = body_part(LEG); - if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES) - what = makeplural(what); - Sprintf(eos(info), ", injured %s", what); - } - if (Glib) Sprintf(eos(info), ", slippery %s", - makeplural(body_part(HAND))); - if (u.utrap) Strcat(info, ", trapped"); - if (Fast) Strcat(info, Very_fast ? - ", very fast" : ", fast"); - if (u.uundetected) Strcat(info, ", concealed"); - if (Invis) Strcat(info, ", invisible"); - if (u.ustuck) { - if (sticks(youmonst.data)) - Strcat(info, ", holding "); - else - Strcat(info, ", held by "); - Strcat(info, mon_nam(u.ustuck)); - } + info[0] = '\0'; + if (Sick) { + Strcat(info, ", dying from"); + if (u.usick_type & SICK_VOMITABLE) + Strcat(info, " food poisoning"); + if (u.usick_type & SICK_NONVOMITABLE) { + if (u.usick_type & SICK_VOMITABLE) + Strcat(info, " and"); + Strcat(info, " illness"); + } + } + if (Stoned) + Strcat(info, ", solidifying"); + if (Slimed) + Strcat(info, ", becoming slimy"); + if (Strangled) + Strcat(info, ", being strangled"); + if (Vomiting) + Strcat(info, ", nauseated"); /* !"nauseous" */ + if (Confusion) + Strcat(info, ", confused"); + if (Blind) { + Strcat(info, ", blind"); + if (u.ucreamed) { + if ((long) u.ucreamed < Blinded || Blindfolded + || !haseyes(youmonst.data)) + Strcat(info, ", cover"); + Strcat(info, "ed by sticky goop"); + } /* note: "goop" == "glop"; variation is intentional */ + } + if (Stunned) + Strcat(info, ", stunned"); + if (!u.usteed && Wounded_legs) { + const char *what = body_part(LEG); + if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES) + what = makeplural(what); + Sprintf(eos(info), ", injured %s", what); + } + if (Glib) + Sprintf(eos(info), ", slippery %s", makeplural(body_part(HAND))); + if (u.utrap) + Strcat(info, ", trapped"); + if (Fast) + Strcat(info, Very_fast ? ", very fast" : ", fast"); + if (u.uundetected) + Strcat(info, ", concealed"); + if (Invis) + Strcat(info, ", invisible"); + if (u.ustuck) { + if (sticks(youmonst.data)) + Strcat(info, ", holding "); + else + Strcat(info, ", held by "); + Strcat(info, mon_nam(u.ustuck)); + } - pline("Status of %s (%s%s): Level %d HP %d(%d) AC %d%s.", - plname, - (u.ualign.record >= 20) ? "piously " : - (u.ualign.record > 13) ? "devoutly " : - (u.ualign.record > 8) ? "fervently " : - (u.ualign.record > 3) ? "stridently " : - (u.ualign.record == 3) ? "" : - (u.ualign.record >= 1) ? "haltingly " : - (u.ualign.record == 0) ? "nominally " : - "insufficiently ", - align_str(u.ualign.type), - Upolyd ? mons[u.umonnum].mlevel : u.ulevel, - Upolyd ? u.mh : u.uhp, - Upolyd ? u.mhmax : u.uhpmax, - u.uac, - info); + pline("Status of %s (%s%s): Level %d HP %d(%d) AC %d%s.", plname, + (u.ualign.record >= 20) + ? "piously " + : (u.ualign.record > 13) + ? "devoutly " + : (u.ualign.record > 8) + ? "fervently " + : (u.ualign.record > 3) + ? "stridently " + : (u.ualign.record == 3) + ? "" + : (u.ualign.record >= 1) + ? "haltingly " + : (u.ualign.record == 0) + ? "nominally " + : "insufficiently ", + align_str(u.ualign.type), + Upolyd ? mons[u.umonnum].mlevel : u.ulevel, Upolyd ? u.mh : u.uhp, + Upolyd ? u.mhmax : u.uhpmax, u.uac, info); } void self_invis_message() { - pline("%s %s.", - Hallucination ? "Far out, man! You" : "Gee! All of a sudden, you", - See_invisible ? "can see right through yourself" : - "can't see yourself"); + pline("%s %s.", + Hallucination ? "Far out, man! You" : "Gee! All of a sudden, you", + See_invisible ? "can see right through yourself" + : "can't see yourself"); } void pudding_merge_message(otmp, otmp2) -struct obj* otmp; -struct obj* otmp2; +struct obj *otmp; +struct obj *otmp2; { - boolean visible = cansee(otmp->ox, otmp->oy) || cansee(otmp2->ox, otmp2->oy); + boolean visible = + cansee(otmp->ox, otmp->oy) || cansee(otmp2->ox, otmp2->oy); boolean onfloor = otmp->where == OBJ_FLOOR || otmp2->where == OBJ_FLOOR; boolean inpack = carried(otmp) || carried(otmp2); @@ -506,16 +549,16 @@ struct obj* otmp2; } else if (inpack) { Your("pack reaches out and grabs something!"); } - /* even though we can see where they should be, + /* even though we can see where they should be, * they'll be out of our view (minvent or container) * so don't actually show anything */ } else if (onfloor || inpack) { pline("The %s coalesce%s.", makeplural(obj_typename(otmp->otyp)), - inpack ? " inside your pack" : ""); + inpack ? " inside your pack" : ""); } } else { You_hear("a faint sloshing sound."); } } - + /*pline.c*/ diff --git a/src/polyself.c b/src/polyself.c index 0694ea9e9..0083a9c07 100644 --- a/src/polyself.c +++ b/src/polyself.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 polyself.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 polyself.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.98 $ */ /* NetHack 3.6 polyself.c $Date: 2013/03/16 01:44:28 $ $Revision: 1.88 $ */ /* Copyright (C) 1987, 1988, 1989 by Ken Arromdee */ /* NetHack may be freely redistributed. See license for details. */ @@ -23,16 +23,16 @@ #include "hack.h" STATIC_DCL void FDECL(check_strangling, (BOOLEAN_P)); -STATIC_DCL void FDECL(polyman, (const char *,const char *)); +STATIC_DCL void FDECL(polyman, (const char *, const char *)); STATIC_DCL void NDECL(break_armor); -STATIC_DCL void FDECL(drop_weapon,(int)); +STATIC_DCL void FDECL(drop_weapon, (int)); STATIC_DCL void NDECL(uunstick); -STATIC_DCL int FDECL(armor_to_dragon,(int)); +STATIC_DCL int FDECL(armor_to_dragon, (int)); STATIC_DCL void NDECL(newman); -STATIC_DCL boolean FDECL(polysense,(struct permonst *)); +STATIC_DCL boolean FDECL(polysense, (struct permonst *)); STATIC_VAR const char no_longer_petrify_resistant[] = - "No longer petrify-resistant, you"; + "No longer petrify-resistant, you"; /* controls whether taking on new form or becoming new man can also change sex (ought to be an arg to polymon() and newman() instead) */ @@ -42,60 +42,64 @@ STATIC_VAR int sex_change_ok = 0; void set_uasmon() { - struct permonst *mdat = &mons[u.umonnum]; + struct permonst *mdat = &mons[u.umonnum]; - set_mon_data(&youmonst, mdat, 0); + set_mon_data(&youmonst, mdat, 0); -#define PROPSET(PropIndx, ON) do { \ - if (ON) u.uprops[PropIndx].intrinsic |= FROMFORM; \ - else u.uprops[PropIndx].intrinsic &= ~FROMFORM; } while (0) +#define PROPSET(PropIndx, ON) \ + do { \ + if (ON) \ + u.uprops[PropIndx].intrinsic |= FROMFORM; \ + else \ + u.uprops[PropIndx].intrinsic &= ~FROMFORM; \ + } while (0) - PROPSET(FIRE_RES, resists_fire(&youmonst)); - PROPSET(COLD_RES, resists_cold(&youmonst)); - PROPSET(SLEEP_RES, resists_sleep(&youmonst)); - PROPSET(DISINT_RES, resists_disint(&youmonst)); - PROPSET(SHOCK_RES, resists_elec(&youmonst)); - PROPSET(POISON_RES, resists_poison(&youmonst)); - PROPSET(ACID_RES, resists_acid(&youmonst)); - PROPSET(STONE_RES, resists_ston(&youmonst)); + PROPSET(FIRE_RES, resists_fire(&youmonst)); + PROPSET(COLD_RES, resists_cold(&youmonst)); + PROPSET(SLEEP_RES, resists_sleep(&youmonst)); + PROPSET(DISINT_RES, resists_disint(&youmonst)); + PROPSET(SHOCK_RES, resists_elec(&youmonst)); + PROPSET(POISON_RES, resists_poison(&youmonst)); + PROPSET(ACID_RES, resists_acid(&youmonst)); + PROPSET(STONE_RES, resists_ston(&youmonst)); { - /* resists_drli() takes wielded weapon into account; suppress it */ - struct obj *save_uwep = uwep; + /* resists_drli() takes wielded weapon into account; suppress it */ + struct obj *save_uwep = uwep; - uwep = 0; - PROPSET(DRAIN_RES, resists_drli(&youmonst)); - uwep = save_uwep; + uwep = 0; + PROPSET(DRAIN_RES, resists_drli(&youmonst)); + uwep = save_uwep; } - /* resists_magm() takes wielded, worn, and carried equipment into - into account; cheat and duplicate its monster-specific part */ - PROPSET(ANTIMAGIC, (dmgtype(mdat, AD_MAGM) || - mdat == &mons[PM_BABY_GRAY_DRAGON] || - dmgtype(mdat, AD_RBRE))); - PROPSET(SICK_RES, (mdat->mlet == S_FUNGUS || mdat == &mons[PM_GHOUL])); + /* resists_magm() takes wielded, worn, and carried equipment into + into account; cheat and duplicate its monster-specific part */ + PROPSET(ANTIMAGIC, + (dmgtype(mdat, AD_MAGM) || mdat == &mons[PM_BABY_GRAY_DRAGON] + || dmgtype(mdat, AD_RBRE))); + PROPSET(SICK_RES, (mdat->mlet == S_FUNGUS || mdat == &mons[PM_GHOUL])); - PROPSET(STUNNED, (mdat == &mons[PM_STALKER] || is_bat(mdat))); - PROPSET(HALLUC_RES, dmgtype(mdat, AD_HALU)); - PROPSET(SEE_INVIS, perceives(mdat)); - PROPSET(TELEPAT, telepathic(mdat)); - PROPSET(INFRAVISION, infravision(mdat)); - PROPSET(INVIS, pm_invisible(mdat)); - PROPSET(TELEPORT, can_teleport(mdat)); - PROPSET(TELEPORT_CONTROL, control_teleport(mdat)); - PROPSET(LEVITATION, is_floater(mdat)); - PROPSET(FLYING, is_flyer(mdat)); - PROPSET(SWIMMING, is_swimmer(mdat)); - /* [don't touch MAGICAL_BREATHING here; both Amphibious and Breathless - key off of it but include different monster forms...] */ - PROPSET(PASSES_WALLS, passes_walls(mdat)); - PROPSET(REGENERATION, regenerates(mdat)); - PROPSET(REFLECTING, (mdat == &mons[PM_SILVER_DRAGON])); + PROPSET(STUNNED, (mdat == &mons[PM_STALKER] || is_bat(mdat))); + PROPSET(HALLUC_RES, dmgtype(mdat, AD_HALU)); + PROPSET(SEE_INVIS, perceives(mdat)); + PROPSET(TELEPAT, telepathic(mdat)); + PROPSET(INFRAVISION, infravision(mdat)); + PROPSET(INVIS, pm_invisible(mdat)); + PROPSET(TELEPORT, can_teleport(mdat)); + PROPSET(TELEPORT_CONTROL, control_teleport(mdat)); + PROPSET(LEVITATION, is_floater(mdat)); + PROPSET(FLYING, is_flyer(mdat)); + PROPSET(SWIMMING, is_swimmer(mdat)); + /* [don't touch MAGICAL_BREATHING here; both Amphibious and Breathless + key off of it but include different monster forms...] */ + PROPSET(PASSES_WALLS, passes_walls(mdat)); + PROPSET(REGENERATION, regenerates(mdat)); + PROPSET(REFLECTING, (mdat == &mons[PM_SILVER_DRAGON])); - float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ + float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ #undef PROPSET #ifdef STATUS_VIA_WINDOWPORT - status_initialize(REASSESS_ONLY); + status_initialize(REASSESS_ONLY); #endif } @@ -103,12 +107,12 @@ set_uasmon() void float_vs_flight() { - /* floating overrides flight; normally float_up() and float_down() - handle this, but sometimes they're skipped */ - if (HLevitation || ELevitation) - BFlying |= I_SPECIAL; - else - BFlying &= ~I_SPECIAL; + /* floating overrides flight; normally float_up() and float_down() + handle this, but sometimes they're skipped */ + if (HLevitation || ELevitation) + BFlying |= I_SPECIAL; + else + BFlying &= ~I_SPECIAL; } /* for changing into form that's immune to strangulation */ @@ -116,22 +120,22 @@ STATIC_OVL void check_strangling(on) boolean on; { - if (on) { /* on -- maybe resume strangling */ - /* when Strangled is already set, polymorphing from one - vulnerable form into another causes the counter to be reset */ - if (uamul && uamul->otyp == AMULET_OF_STRANGULATION && - can_be_strangled(&youmonst)) { - Your("%s %s your %s!", simpleonames(uamul), - Strangled ? "still constricts" : "begins constricting", - body_part(NECK)); /* "throat" */ - Strangled = 6L; - makeknown(AMULET_OF_STRANGULATION); - } - } else { /* off -- maybe block strangling */ - if (Strangled && !can_be_strangled(&youmonst)) { - Strangled = 0L; - You("are no longer being strangled."); - } + if (on) { /* on -- maybe resume strangling */ + /* when Strangled is already set, polymorphing from one + vulnerable form into another causes the counter to be reset */ + if (uamul && uamul->otyp == AMULET_OF_STRANGULATION + && can_be_strangled(&youmonst)) { + Your("%s %s your %s!", simpleonames(uamul), + Strangled ? "still constricts" : "begins constricting", + body_part(NECK)); /* "throat" */ + Strangled = 6L; + makeknown(AMULET_OF_STRANGULATION); + } + } else { /* off -- maybe block strangling */ + if (Strangled && !can_be_strangled(&youmonst)) { + Strangled = 0L; + You("are no longer being strangled."); + } } } @@ -140,661 +144,695 @@ STATIC_OVL void polyman(fmt, arg) const char *fmt, *arg; { - boolean sticky = sticks(youmonst.data) && u.ustuck && !u.uswallow, - was_mimicking = (youmonst.m_ap_type == M_AP_OBJECT); - boolean was_blind = !!Blind; + boolean sticky = sticks(youmonst.data) && u.ustuck && !u.uswallow, + was_mimicking = (youmonst.m_ap_type == M_AP_OBJECT); + boolean was_blind = !!Blind; - if (Upolyd) { - u.acurr = u.macurr; /* restore old attribs */ - u.amax = u.mamax; - u.umonnum = u.umonster; - flags.female = u.mfemale; - } - set_uasmon(); + if (Upolyd) { + u.acurr = u.macurr; /* restore old attribs */ + u.amax = u.mamax; + u.umonnum = u.umonster; + flags.female = u.mfemale; + } + set_uasmon(); - u.mh = u.mhmax = 0; - u.mtimedone = 0; - skinback(FALSE); - u.uundetected = 0; + u.mh = u.mhmax = 0; + u.mtimedone = 0; + skinback(FALSE); + u.uundetected = 0; - if (sticky) uunstick(); - find_ac(); - if (was_mimicking) { - if (multi < 0) unmul(""); - youmonst.m_ap_type = M_AP_NOTHING; - } + if (sticky) + uunstick(); + find_ac(); + if (was_mimicking) { + if (multi < 0) + unmul(""); + youmonst.m_ap_type = M_AP_NOTHING; + } - newsym(u.ux,u.uy); + newsym(u.ux, u.uy); - You(fmt, arg); - /* check whether player foolishly genocided self while poly'd */ - if ((mvitals[urole.malenum].mvflags & G_GENOD) || - (urole.femalenum != NON_PM && - (mvitals[urole.femalenum].mvflags & G_GENOD)) || - (mvitals[urace.malenum].mvflags & G_GENOD) || - (urace.femalenum != NON_PM && - (mvitals[urace.femalenum].mvflags & G_GENOD))) { - /* intervening activity might have clobbered genocide info */ - struct kinfo *kptr = find_delayed_killer(POLYMORPH); + You(fmt, arg); + /* check whether player foolishly genocided self while poly'd */ + if ((mvitals[urole.malenum].mvflags & G_GENOD) + || (urole.femalenum != NON_PM + && (mvitals[urole.femalenum].mvflags & G_GENOD)) + || (mvitals[urace.malenum].mvflags & G_GENOD) + || (urace.femalenum != NON_PM + && (mvitals[urace.femalenum].mvflags & G_GENOD))) { + /* intervening activity might have clobbered genocide info */ + struct kinfo *kptr = find_delayed_killer(POLYMORPH); - if (kptr != (struct kinfo*) 0 && kptr->name[0]) { - killer.format = kptr->format; - Strcpy(killer.name, kptr->name); - } else { - killer.format = KILLED_BY; - Strcpy(killer.name, "self-genocide"); - } - dealloc_killer(kptr); - done(GENOCIDED); - } + if (kptr != (struct kinfo *) 0 && kptr->name[0]) { + killer.format = kptr->format; + Strcpy(killer.name, kptr->name); + } else { + killer.format = KILLED_BY; + Strcpy(killer.name, "self-genocide"); + } + dealloc_killer(kptr); + done(GENOCIDED); + } - if (u.twoweap && !could_twoweap(youmonst.data)) - untwoweapon(); + if (u.twoweap && !could_twoweap(youmonst.data)) + untwoweapon(); - if (u.utraptype == TT_PIT && u.utrap) { - u.utrap = rn1(6,2); /* time to escape resets */ - } - if (was_blind && !Blind) { /* reverting from eyeless */ - Blinded = 1L; - make_blinded(0L, TRUE); /* remove blindness */ - } - check_strangling(TRUE); + if (u.utraptype == TT_PIT && u.utrap) { + u.utrap = rn1(6, 2); /* time to escape resets */ + } + if (was_blind && !Blind) { /* reverting from eyeless */ + Blinded = 1L; + make_blinded(0L, TRUE); /* remove blindness */ + } + check_strangling(TRUE); - if(!Levitation && !u.ustuck && is_pool_or_lava(u.ux,u.uy)) - spoteffects(TRUE); + if (!Levitation && !u.ustuck && is_pool_or_lava(u.ux, u.uy)) + spoteffects(TRUE); - see_monsters(); + see_monsters(); } void change_sex() { - /* setting u.umonster for caveman/cavewoman or priest/priestess - swap unintentionally makes `Upolyd' appear to be true */ - boolean already_polyd = (boolean) Upolyd; + /* setting u.umonster for caveman/cavewoman or priest/priestess + swap unintentionally makes `Upolyd' appear to be true */ + boolean already_polyd = (boolean) Upolyd; - /* Some monsters are always of one sex and their sex can't be changed */ - /* succubi/incubi can change, but are handled below */ - /* !already_polyd check necessary because is_male() and is_female() - are true if the player is a priest/priestess */ - if (!already_polyd || (!is_male(youmonst.data) && !is_female(youmonst.data) && !is_neuter(youmonst.data))) - flags.female = !flags.female; - if (already_polyd) /* poly'd: also change saved sex */ - u.mfemale = !u.mfemale; - max_rank_sz(); /* [this appears to be superfluous] */ - if ((already_polyd ? u.mfemale : flags.female) && urole.name.f) - Strcpy(pl_character, urole.name.f); - else - Strcpy(pl_character, urole.name.m); - u.umonster = ((already_polyd ? u.mfemale : flags.female) && urole.femalenum != NON_PM) ? - urole.femalenum : urole.malenum; - if (!already_polyd) { - u.umonnum = u.umonster; - } else if (u.umonnum == PM_SUCCUBUS || u.umonnum == PM_INCUBUS) { - flags.female = !flags.female; - /* change monster type to match new sex */ - u.umonnum = (u.umonnum == PM_SUCCUBUS) ? PM_INCUBUS : PM_SUCCUBUS; - set_uasmon(); - } + /* Some monsters are always of one sex and their sex can't be changed */ + /* succubi/incubi can change, but are handled below */ + /* !already_polyd check necessary because is_male() and is_female() + are true if the player is a priest/priestess */ + if (!already_polyd + || (!is_male(youmonst.data) && !is_female(youmonst.data) + && !is_neuter(youmonst.data))) + flags.female = !flags.female; + if (already_polyd) /* poly'd: also change saved sex */ + u.mfemale = !u.mfemale; + max_rank_sz(); /* [this appears to be superfluous] */ + if ((already_polyd ? u.mfemale : flags.female) && urole.name.f) + Strcpy(pl_character, urole.name.f); + else + Strcpy(pl_character, urole.name.m); + u.umonster = ((already_polyd ? u.mfemale : flags.female) + && urole.femalenum != NON_PM) + ? urole.femalenum + : urole.malenum; + if (!already_polyd) { + u.umonnum = u.umonster; + } else if (u.umonnum == PM_SUCCUBUS || u.umonnum == PM_INCUBUS) { + flags.female = !flags.female; + /* change monster type to match new sex */ + u.umonnum = (u.umonnum == PM_SUCCUBUS) ? PM_INCUBUS : PM_SUCCUBUS; + set_uasmon(); + } } STATIC_OVL void newman() { - int i, oldlvl, newlvl, hpmax, enmax; + int i, oldlvl, newlvl, hpmax, enmax; - oldlvl = u.ulevel; - newlvl = oldlvl + rn1(5, -2); /* new = old + {-2,-1,0,+1,+2} */ - if (newlvl > 127 || newlvl < 1) { /* level went below 0? */ - goto dead; /* old level is still intact (in case of lifesaving) */ - } - if (newlvl > MAXULEV) newlvl = MAXULEV; - /* If your level goes down, your peak level goes down by - the same amount so that you can't simply use blessed - full healing to undo the decrease. But if your level - goes up, your peak level does *not* undergo the same - adjustment; you might end up losing out on the chance - to regain some levels previously lost to other causes. */ - if (newlvl < oldlvl) u.ulevelmax -= (oldlvl - newlvl); - if (u.ulevelmax < newlvl) u.ulevelmax = newlvl; - u.ulevel = newlvl; + oldlvl = u.ulevel; + newlvl = oldlvl + rn1(5, -2); /* new = old + {-2,-1,0,+1,+2} */ + if (newlvl > 127 || newlvl < 1) { /* level went below 0? */ + goto dead; /* old level is still intact (in case of lifesaving) */ + } + if (newlvl > MAXULEV) + newlvl = MAXULEV; + /* If your level goes down, your peak level goes down by + the same amount so that you can't simply use blessed + full healing to undo the decrease. But if your level + goes up, your peak level does *not* undergo the same + adjustment; you might end up losing out on the chance + to regain some levels previously lost to other causes. */ + if (newlvl < oldlvl) + u.ulevelmax -= (oldlvl - newlvl); + if (u.ulevelmax < newlvl) + u.ulevelmax = newlvl; + u.ulevel = newlvl; - if (sex_change_ok && !rn2(10)) change_sex(); + if (sex_change_ok && !rn2(10)) + change_sex(); - adjabil(oldlvl, (int)u.ulevel); - reset_rndmonst(NON_PM); /* new monster generation criteria */ + adjabil(oldlvl, (int) u.ulevel); + reset_rndmonst(NON_PM); /* new monster generation criteria */ - /* random experience points for the new experience level */ - u.uexp = rndexp(FALSE); + /* random experience points for the new experience level */ + u.uexp = rndexp(FALSE); - /* set up new attribute points (particularly Con) */ - redist_attr(); + /* set up new attribute points (particularly Con) */ + redist_attr(); - /* - * New hit points: - * remove level-gain based HP from any extra HP accumulated - * (the "extra" might actually be negative); - * modify the extra, retaining {80%, 90%, 100%, or 110%}; - * add in newly generated set of level-gain HP. - * (This used to calculate new HP in direct proportion to old HP, - * but that was subject to abuse: accumulate a large amount of - * extra HP, drain level down to 1, then polyself to level 2 or 3 - * [lifesaving capability needed to handle level 0 and -1 cases] - * and the extra got multiplied by 2 or 3. Repeat the level - * drain and polyself steps until out of lifesaving capability.) - */ - hpmax = u.uhpmax; - for (i = 0; i < oldlvl; i++) hpmax -= (int)u.uhpinc[i]; - /* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */ - hpmax = rounddiv((long)hpmax * (long)rn1(4, 8), 10); - for (i = 0; (u.ulevel = i) < newlvl; i++) hpmax += newhp(); - if (hpmax < u.ulevel) hpmax = u.ulevel; /* min of 1 HP per level */ - /* retain same proportion for current HP; u.uhp * hpmax / u.uhpmax */ - u.uhp = rounddiv((long)u.uhp * (long)hpmax, u.uhpmax); - u.uhpmax = hpmax; - /* - * Do the same for spell power. - */ - enmax = u.uenmax; - for (i = 0; i < oldlvl; i++) enmax -= (int)u.ueninc[i]; - enmax = rounddiv((long)enmax * (long)rn1(4, 8), 10); - for (i = 0; (u.ulevel = i) < newlvl; i++) enmax += newpw(); - if (enmax < u.ulevel) enmax = u.ulevel; - u.uen = rounddiv((long)u.uen * (long)enmax, ((u.uenmax < 1) ? 1 : u.uenmax)); - u.uenmax = enmax; - /* [should alignment record be tweaked too?] */ + /* + * New hit points: + * remove level-gain based HP from any extra HP accumulated + * (the "extra" might actually be negative); + * modify the extra, retaining {80%, 90%, 100%, or 110%}; + * add in newly generated set of level-gain HP. + * (This used to calculate new HP in direct proportion to old HP, + * but that was subject to abuse: accumulate a large amount of + * extra HP, drain level down to 1, then polyself to level 2 or 3 + * [lifesaving capability needed to handle level 0 and -1 cases] + * and the extra got multiplied by 2 or 3. Repeat the level + * drain and polyself steps until out of lifesaving capability.) + */ + hpmax = u.uhpmax; + for (i = 0; i < oldlvl; i++) + hpmax -= (int) u.uhpinc[i]; + /* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */ + hpmax = rounddiv((long) hpmax * (long) rn1(4, 8), 10); + for (i = 0; (u.ulevel = i) < newlvl; i++) + hpmax += newhp(); + if (hpmax < u.ulevel) + hpmax = u.ulevel; /* min of 1 HP per level */ + /* retain same proportion for current HP; u.uhp * hpmax / u.uhpmax */ + u.uhp = rounddiv((long) u.uhp * (long) hpmax, u.uhpmax); + u.uhpmax = hpmax; + /* + * Do the same for spell power. + */ + enmax = u.uenmax; + for (i = 0; i < oldlvl; i++) + enmax -= (int) u.ueninc[i]; + enmax = rounddiv((long) enmax * (long) rn1(4, 8), 10); + for (i = 0; (u.ulevel = i) < newlvl; i++) + enmax += newpw(); + if (enmax < u.ulevel) + enmax = u.ulevel; + u.uen = rounddiv((long) u.uen * (long) enmax, + ((u.uenmax < 1) ? 1 : u.uenmax)); + u.uenmax = enmax; + /* [should alignment record be tweaked too?] */ - u.uhunger = rn1(500,500); - if (Sick) make_sick(0L, (char *) 0, FALSE, SICK_ALL); - if (Stoned) make_stoned(0L, (char *)0, 0, (char *)0); - if (u.uhp <= 0) { - if (Polymorph_control) { /* even when Stunned || Unaware */ - if (u.uhp <= 0) u.uhp = 1; - } else { -dead: /* we come directly here if their experience level went to 0 or less */ - Your("new form doesn't seem healthy enough to survive."); - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "unsuccessful polymorph"); - done(DIED); - newuhs(FALSE); - (void) polysense(youmonst.data); - return; /* lifesaved */ - } - } - newuhs(FALSE); - polyman("feel like a new %s!", - /* use saved gender we're about to revert to, not current */ - (u.mfemale && urace.individual.f) ? urace.individual.f : - (urace.individual.m) ? urace.individual.m : urace.noun); - if (Slimed) { - Your("body transforms, but there is still slime on you."); - make_slimed(10L, (const char*) 0); - } + u.uhunger = rn1(500, 500); + if (Sick) + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + if (Stoned) + make_stoned(0L, (char *) 0, 0, (char *) 0); + if (u.uhp <= 0) { + if (Polymorph_control) { /* even when Stunned || Unaware */ + if (u.uhp <= 0) + u.uhp = 1; + } else { + dead: /* we come directly here if their experience level went to 0 or + less */ + Your("new form doesn't seem healthy enough to survive."); + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "unsuccessful polymorph"); + done(DIED); + newuhs(FALSE); + (void) polysense(youmonst.data); + return; /* lifesaved */ + } + } + newuhs(FALSE); + polyman("feel like a new %s!", + /* use saved gender we're about to revert to, not current */ + (u.mfemale && urace.individual.f) + ? urace.individual.f + : (urace.individual.m) ? urace.individual.m : urace.noun); + if (Slimed) { + Your("body transforms, but there is still slime on you."); + make_slimed(10L, (const char *) 0); + } - (void) polysense(youmonst.data); - context.botl = 1; - see_monsters(); - (void) encumber_msg(); + (void) polysense(youmonst.data); + context.botl = 1; + see_monsters(); + (void) encumber_msg(); - retouch_equipment(2); - if (!uarmg) selftouch(no_longer_petrify_resistant); + retouch_equipment(2); + if (!uarmg) + selftouch(no_longer_petrify_resistant); } void polyself(psflags) -int psflags; +int psflags; { - char buf[BUFSZ]; - int old_light, new_light, mntmp, class, tryct; - boolean forcecontrol = (psflags == 1), - monsterpoly = (psflags == 2), - draconian = (uarm && Is_dragon_armor(uarm)), - iswere = (u.ulycn >= LOW_PM), - isvamp = is_vampire(youmonst.data), - controllable_poly = Polymorph_control && !(Stunned || Unaware); + char buf[BUFSZ]; + int old_light, new_light, mntmp, class, tryct; + boolean forcecontrol = (psflags == 1), monsterpoly = (psflags == 2), + draconian = (uarm && Is_dragon_armor(uarm)), + iswere = (u.ulycn >= LOW_PM), isvamp = is_vampire(youmonst.data), + controllable_poly = Polymorph_control && !(Stunned || Unaware); - if (Unchanging) { - pline("You fail to transform!"); - return; - } - /* being Stunned|Unaware doesn't negate this aspect of Poly_control */ - if (!Polymorph_control && !forcecontrol && - !draconian && !iswere && !isvamp) { - if (rn2(20) > ACURR(A_CON)) { - You1(shudder_for_moment); - losehp(rnd(30), "system shock", KILLED_BY_AN); - exercise(A_CON, FALSE); - return; - } - } - old_light = emits_light(youmonst.data); - mntmp = NON_PM; + if (Unchanging) { + pline("You fail to transform!"); + return; + } + /* being Stunned|Unaware doesn't negate this aspect of Poly_control */ + if (!Polymorph_control && !forcecontrol && !draconian && !iswere + && !isvamp) { + if (rn2(20) > ACURR(A_CON)) { + You1(shudder_for_moment); + losehp(rnd(30), "system shock", KILLED_BY_AN); + exercise(A_CON, FALSE); + return; + } + } + old_light = emits_light(youmonst.data); + mntmp = NON_PM; - if (monsterpoly && isvamp) - goto do_vampyr; + if (monsterpoly && isvamp) + goto do_vampyr; - if (controllable_poly || forcecontrol) { - tryct = 5; - do { - mntmp = NON_PM; - getlin("Become what kind of monster? [type the name]", - buf); - (void) mungspaces(buf); - if (*buf == '\033') { - /* user is cancelling controlled poly */ - if (forcecontrol) { /* wizard mode #polyself */ - pline1(Never_mind); - return; - } - Strcpy(buf, "*"); /* resort to random */ - } - if (!strcmp(buf, "*") || !strcmp(buf, "random")) { - /* explicitly requesting random result */ - tryct = 0; /* will skip thats_enough_tries */ - continue; /* end do-while(--tryct > 0) loop */ - } - class = 0; - mntmp = name_to_mon(buf); - if (mntmp < LOW_PM) { - by_class: - class = name_to_monclass(buf, &mntmp); - if (class && mntmp == NON_PM) - mntmp = mkclass_poly(class); - } - if (mntmp < LOW_PM) { - if (!class) - pline("I've never heard of such monsters."); - else - You_cant("polymorph into any of those."); - } else if (iswere && (were_beastie(mntmp) == u.ulycn || - mntmp == counter_were(u.ulycn) || - (Upolyd && mntmp == PM_HUMAN))) { - goto do_shift; - /* Note: humans are illegal as monsters, but an - * illegal monster forces newman(), which is what we - * want if they specified a human.... */ - } else if (!polyok(&mons[mntmp]) && - !(mntmp == PM_HUMAN || - your_race(&mons[mntmp]) || - mntmp == urole.malenum || - mntmp == urole.femalenum)) { - const char *pm_name; + if (controllable_poly || forcecontrol) { + tryct = 5; + do { + mntmp = NON_PM; + getlin("Become what kind of monster? [type the name]", buf); + (void) mungspaces(buf); + if (*buf == '\033') { + /* user is cancelling controlled poly */ + if (forcecontrol) { /* wizard mode #polyself */ + pline1(Never_mind); + return; + } + Strcpy(buf, "*"); /* resort to random */ + } + if (!strcmp(buf, "*") || !strcmp(buf, "random")) { + /* explicitly requesting random result */ + tryct = 0; /* will skip thats_enough_tries */ + continue; /* end do-while(--tryct > 0) loop */ + } + class = 0; + mntmp = name_to_mon(buf); + if (mntmp < LOW_PM) { + by_class: + class = name_to_monclass(buf, &mntmp); + if (class && mntmp == NON_PM) + mntmp = mkclass_poly(class); + } + if (mntmp < LOW_PM) { + if (!class) + pline("I've never heard of such monsters."); + else + You_cant("polymorph into any of those."); + } else if (iswere && (were_beastie(mntmp) == u.ulycn + || mntmp == counter_were(u.ulycn) + || (Upolyd && mntmp == PM_HUMAN))) { + goto do_shift; + /* Note: humans are illegal as monsters, but an + * illegal monster forces newman(), which is what we + * want if they specified a human.... */ + } else if (!polyok(&mons[mntmp]) + && !(mntmp == PM_HUMAN || your_race(&mons[mntmp]) + || mntmp == urole.malenum + || mntmp == urole.femalenum)) { + const char *pm_name; - /* mkclass_ploy() can pick a !polyok() - candidate; if so, usually try again */ - if (class) { - if (rn2(3) || --tryct > 0) goto by_class; - /* no retries left; put one back on counter - so that end of loop decrement will yield - 0 and trigger thats_enough_tries message */ - ++tryct; - } - pm_name = mons[mntmp].mname; - if (the_unique_pm(&mons[mntmp])) - pm_name = the(pm_name); - else if (!type_is_pname(&mons[mntmp])) - pm_name = an(pm_name); - You_cant("polymorph into %s.", pm_name); - } else break; - } while (--tryct > 0); - if (!tryct) pline1(thats_enough_tries); - /* allow skin merging, even when polymorph is controlled */ - if (draconian && (tryct <= 0 || - mntmp == armor_to_dragon(uarm->otyp))) - goto do_merge; - if (isvamp && (tryct <= 0 || mntmp == PM_WOLF || - mntmp == PM_FOG_CLOUD || is_bat(&mons[mntmp]))) - goto do_vampyr; - } else if (draconian || iswere || isvamp) { - /* special changes that don't require polyok() */ - if (draconian) { - do_merge: - mntmp = armor_to_dragon(uarm->otyp); - if (!(mvitals[mntmp].mvflags & G_GENOD)) { - /* allow G_EXTINCT */ - if (Is_dragon_scales(uarm)) { - /* dragon scales remain intact as uskin */ - You("merge with your scaly armor."); - } else { /* dragon scale mail */ - /* d.scale mail first reverts to scales */ - char *p, *dsmail; + /* mkclass_ploy() can pick a !polyok() + candidate; if so, usually try again */ + if (class) { + if (rn2(3) || --tryct > 0) + goto by_class; + /* no retries left; put one back on counter + so that end of loop decrement will yield + 0 and trigger thats_enough_tries message */ + ++tryct; + } + pm_name = mons[mntmp].mname; + if (the_unique_pm(&mons[mntmp])) + pm_name = the(pm_name); + else if (!type_is_pname(&mons[mntmp])) + pm_name = an(pm_name); + You_cant("polymorph into %s.", pm_name); + } else + break; + } while (--tryct > 0); + if (!tryct) + pline1(thats_enough_tries); + /* allow skin merging, even when polymorph is controlled */ + if (draconian && (tryct <= 0 || mntmp == armor_to_dragon(uarm->otyp))) + goto do_merge; + if (isvamp && (tryct <= 0 || mntmp == PM_WOLF || mntmp == PM_FOG_CLOUD + || is_bat(&mons[mntmp]))) + goto do_vampyr; + } else if (draconian || iswere || isvamp) { + /* special changes that don't require polyok() */ + if (draconian) { + do_merge: + mntmp = armor_to_dragon(uarm->otyp); + if (!(mvitals[mntmp].mvflags & G_GENOD)) { + /* allow G_EXTINCT */ + if (Is_dragon_scales(uarm)) { + /* dragon scales remain intact as uskin */ + You("merge with your scaly armor."); + } else { /* dragon scale mail */ + /* d.scale mail first reverts to scales */ + char *p, *dsmail; - /* similar to noarmor(invent.c), - shorten to " scale mail" */ - dsmail = strcpy(buf, simpleonames(uarm)); - if ((p = strstri(dsmail, " dragon ")) != 0) - while ((p[1] = p[8]) != '\0') ++p; - /* tricky phrasing; dragon scale mail - is singular, dragon scales are plural */ - Your( - "%s reverts to scales as you merge with them.", - dsmail); - /* uarm->spe enchantment remains unchanged; - re-converting scales to mail poses risk - of evaporation due to over enchanting */ - uarm->otyp += GRAY_DRAGON_SCALES - - GRAY_DRAGON_SCALE_MAIL; - uarm->dknown = 1; - context.botl = 1; /* AC is changing */ - } - uskin = uarm; - uarm = (struct obj *)0; - /* save/restore hack */ - uskin->owornmask |= I_SPECIAL; - update_inventory(); - } - } else if (iswere) { - do_shift: - if (Upolyd && were_beastie(mntmp) != u.ulycn) - mntmp = PM_HUMAN; /* Illegal; force newman() */ - else - mntmp = u.ulycn; - } else if (isvamp) { - do_vampyr: - if (mntmp < LOW_PM || (mons[mntmp].geno & G_UNIQ)) - mntmp = (youmonst.data != &mons[PM_VAMPIRE] && - !rn2(10)) ? PM_WOLF : - !rn2(4) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT; - if (controllable_poly) { - Sprintf(buf, "Become %s?", - an(mons[mntmp].mname)); - if (yn(buf) != 'y') return; - } - } - /* if polymon fails, "you feel" message has been given - so don't follow up with another polymon or newman; - sex_change_ok left disabled here */ - if (mntmp == PM_HUMAN) - newman(); /* werecritter */ - else - (void)polymon(mntmp); - goto made_change; /* maybe not, but this is right anyway */ - } + /* similar to noarmor(invent.c), + shorten to " scale mail" */ + dsmail = strcpy(buf, simpleonames(uarm)); + if ((p = strstri(dsmail, " dragon ")) != 0) + while ((p[1] = p[8]) != '\0') + ++p; + /* tricky phrasing; dragon scale mail + is singular, dragon scales are plural */ + Your("%s reverts to scales as you merge with them.", + dsmail); + /* uarm->spe enchantment remains unchanged; + re-converting scales to mail poses risk + of evaporation due to over enchanting */ + uarm->otyp += GRAY_DRAGON_SCALES - GRAY_DRAGON_SCALE_MAIL; + uarm->dknown = 1; + context.botl = 1; /* AC is changing */ + } + uskin = uarm; + uarm = (struct obj *) 0; + /* save/restore hack */ + uskin->owornmask |= I_SPECIAL; + update_inventory(); + } + } else if (iswere) { + do_shift: + if (Upolyd && were_beastie(mntmp) != u.ulycn) + mntmp = PM_HUMAN; /* Illegal; force newman() */ + else + mntmp = u.ulycn; + } else if (isvamp) { + do_vampyr: + if (mntmp < LOW_PM || (mons[mntmp].geno & G_UNIQ)) + mntmp = (youmonst.data != &mons[PM_VAMPIRE] && !rn2(10)) + ? PM_WOLF + : !rn2(4) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT; + if (controllable_poly) { + Sprintf(buf, "Become %s?", an(mons[mntmp].mname)); + if (yn(buf) != 'y') + return; + } + } + /* if polymon fails, "you feel" message has been given + so don't follow up with another polymon or newman; + sex_change_ok left disabled here */ + if (mntmp == PM_HUMAN) + newman(); /* werecritter */ + else + (void) polymon(mntmp); + goto made_change; /* maybe not, but this is right anyway */ + } - if (mntmp < LOW_PM) { - tryct = 200; - do { - /* randomly pick an "ordinary" monster */ - mntmp = rn1(SPECIAL_PM - LOW_PM, LOW_PM); - if (polyok(&mons[mntmp]) && - !is_placeholder(&mons[mntmp])) break; - } while (--tryct > 0); - } + if (mntmp < LOW_PM) { + tryct = 200; + do { + /* randomly pick an "ordinary" monster */ + mntmp = rn1(SPECIAL_PM - LOW_PM, LOW_PM); + if (polyok(&mons[mntmp]) && !is_placeholder(&mons[mntmp])) + break; + } while (--tryct > 0); + } - /* The below polyok() fails either if everything is genocided, or if - * we deliberately chose something illegal to force newman(). - */ - sex_change_ok++; - if (!polyok(&mons[mntmp]) || - (!forcecontrol && !rn2(5)) || your_race(&mons[mntmp])) { - newman(); - } else { - (void)polymon(mntmp); - } - sex_change_ok--; /* reset */ + /* The below polyok() fails either if everything is genocided, or if + * we deliberately chose something illegal to force newman(). + */ + sex_change_ok++; + if (!polyok(&mons[mntmp]) || (!forcecontrol && !rn2(5)) + || your_race(&mons[mntmp])) { + newman(); + } else { + (void) polymon(mntmp); + } + sex_change_ok--; /* reset */ - made_change: - new_light = emits_light(youmonst.data); - if (old_light != new_light) { - if (old_light) - del_light_source(LS_MONSTER, monst_to_any(&youmonst)); - if (new_light == 1) ++new_light; /* otherwise it's undetectable */ - if (new_light) - new_light_source(u.ux, u.uy, new_light, - LS_MONSTER, monst_to_any(&youmonst)); - } +made_change: + new_light = emits_light(youmonst.data); + if (old_light != new_light) { + if (old_light) + del_light_source(LS_MONSTER, monst_to_any(&youmonst)); + if (new_light == 1) + ++new_light; /* otherwise it's undetectable */ + if (new_light) + new_light_source(u.ux, u.uy, new_light, LS_MONSTER, + monst_to_any(&youmonst)); + } } /* (try to) make a mntmp monster out of the player */ -int -polymon(mntmp) /* returns 1 if polymorph successful */ -int mntmp; +int polymon(mntmp) /* returns 1 if polymorph successful */ +int mntmp; { - boolean sticky = sticks(youmonst.data) && u.ustuck && !u.uswallow, - was_blind = !!Blind, dochange = FALSE; - int mlvl; + boolean sticky = sticks(youmonst.data) && u.ustuck && !u.uswallow, + was_blind = !!Blind, dochange = FALSE; + int mlvl; - if (mvitals[mntmp].mvflags & G_GENOD) { /* allow G_EXTINCT */ - You_feel("rather %s-ish.",mons[mntmp].mname); - exercise(A_WIS, TRUE); - return(0); - } + if (mvitals[mntmp].mvflags & G_GENOD) { /* allow G_EXTINCT */ + You_feel("rather %s-ish.", mons[mntmp].mname); + exercise(A_WIS, TRUE); + return (0); + } - /* KMH, conduct */ - u.uconduct.polyselfs++; + /* KMH, conduct */ + u.uconduct.polyselfs++; - /* exercise used to be at the very end but only Wis was affected - there since the polymorph was always in effect by then */ - exercise(A_CON, FALSE); - exercise(A_WIS, TRUE); + /* exercise used to be at the very end but only Wis was affected + there since the polymorph was always in effect by then */ + exercise(A_CON, FALSE); + exercise(A_WIS, TRUE); - if (!Upolyd) { - /* Human to monster; save human stats */ - u.macurr = u.acurr; - u.mamax = u.amax; - u.mfemale = flags.female; - } else { - /* Monster to monster; restore human stats, to be - * immediately changed to provide stats for the new monster - */ - u.acurr = u.macurr; - u.amax = u.mamax; - flags.female = u.mfemale; - } + if (!Upolyd) { + /* Human to monster; save human stats */ + u.macurr = u.acurr; + u.mamax = u.amax; + u.mfemale = flags.female; + } else { + /* Monster to monster; restore human stats, to be + * immediately changed to provide stats for the new monster + */ + u.acurr = u.macurr; + u.amax = u.mamax; + flags.female = u.mfemale; + } - /* if stuck mimicking gold, stop immediately */ - if (multi < 0 && youmonst.m_ap_type == M_AP_OBJECT && - youmonst.data->mlet != S_MIMIC) - unmul(""); - /* if becoming a non-mimic, stop mimicking anything */ - if (mons[mntmp].mlet != S_MIMIC) { - /* as in polyman() */ - youmonst.m_ap_type = M_AP_NOTHING; - } - if (is_male(&mons[mntmp])) { - if(flags.female) dochange = TRUE; - } else if (is_female(&mons[mntmp])) { - if(!flags.female) dochange = TRUE; - } else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) { - if (sex_change_ok && !rn2(10)) dochange = TRUE; - } - if (dochange) { - flags.female = !flags.female; - You("%s %s%s!", - (u.umonnum != mntmp) ? "turn into a" : "feel like a new", - (is_male(&mons[mntmp]) || is_female(&mons[mntmp])) ? "" : - flags.female ? "female " : "male ", - mons[mntmp].mname); - } else { - if (u.umonnum != mntmp) - You("turn into %s!", an(mons[mntmp].mname)); - else - You_feel("like a new %s!", mons[mntmp].mname); - } - if (Stoned && poly_when_stoned(&mons[mntmp])) { - /* poly_when_stoned already checked stone golem genocide */ - mntmp = PM_STONE_GOLEM; - make_stoned(0L, "You turn to stone!", 0, (char *)0); - } + /* if stuck mimicking gold, stop immediately */ + if (multi < 0 && youmonst.m_ap_type == M_AP_OBJECT + && youmonst.data->mlet != S_MIMIC) + unmul(""); + /* if becoming a non-mimic, stop mimicking anything */ + if (mons[mntmp].mlet != S_MIMIC) { + /* as in polyman() */ + youmonst.m_ap_type = M_AP_NOTHING; + } + if (is_male(&mons[mntmp])) { + if (flags.female) + dochange = TRUE; + } else if (is_female(&mons[mntmp])) { + if (!flags.female) + dochange = TRUE; + } else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) { + if (sex_change_ok && !rn2(10)) + dochange = TRUE; + } + if (dochange) { + flags.female = !flags.female; + You("%s %s%s!", + (u.umonnum != mntmp) ? "turn into a" : "feel like a new", + (is_male(&mons[mntmp]) || is_female(&mons[mntmp])) + ? "" + : flags.female ? "female " : "male ", + mons[mntmp].mname); + } else { + if (u.umonnum != mntmp) + You("turn into %s!", an(mons[mntmp].mname)); + else + You_feel("like a new %s!", mons[mntmp].mname); + } + if (Stoned && poly_when_stoned(&mons[mntmp])) { + /* poly_when_stoned already checked stone golem genocide */ + mntmp = PM_STONE_GOLEM; + make_stoned(0L, "You turn to stone!", 0, (char *) 0); + } - u.mtimedone = rn1(500, 500); - u.umonnum = mntmp; - set_uasmon(); + u.mtimedone = rn1(500, 500); + u.umonnum = mntmp; + set_uasmon(); - /* New stats for monster, to last only as long as polymorphed. - * Currently only strength gets changed. - */ - if(strongmonst(&mons[mntmp])) ABASE(A_STR) = AMAX(A_STR) = STR18(100); + /* New stats for monster, to last only as long as polymorphed. + * Currently only strength gets changed. + */ + if (strongmonst(&mons[mntmp])) + ABASE(A_STR) = AMAX(A_STR) = STR18(100); - if (Stone_resistance && Stoned) { /* parnes@eniac.seas.upenn.edu */ - make_stoned(0L, "You no longer seem to be petrifying.", - 0, (char *)0); - } - if (Sick_resistance && Sick) { - make_sick(0L, (char *) 0, FALSE, SICK_ALL); - You("no longer feel sick."); - } - if (Slimed) { - if (flaming(youmonst.data)) { - make_slimed(0L, "The slime burns away!"); - } else if (mntmp == PM_GREEN_SLIME) { - /* do it silently */ - make_slimed(0L, (char*) 0); - } - } - check_strangling(FALSE); /* maybe stop strangling */ - if (nohands(youmonst.data)) Glib = 0; + if (Stone_resistance && Stoned) { /* parnes@eniac.seas.upenn.edu */ + make_stoned(0L, "You no longer seem to be petrifying.", 0, + (char *) 0); + } + if (Sick_resistance && Sick) { + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + You("no longer feel sick."); + } + if (Slimed) { + if (flaming(youmonst.data)) { + make_slimed(0L, "The slime burns away!"); + } else if (mntmp == PM_GREEN_SLIME) { + /* do it silently */ + make_slimed(0L, (char *) 0); + } + } + check_strangling(FALSE); /* maybe stop strangling */ + if (nohands(youmonst.data)) + Glib = 0; - /* - mlvl = adj_lev(&mons[mntmp]); - * We can't do the above, since there's no such thing as an - * "experience level of you as a monster" for a polymorphed character. - */ - mlvl = (int)mons[mntmp].mlevel; - if (youmonst.data->mlet == S_DRAGON && mntmp >= PM_GRAY_DRAGON) { - u.mhmax = In_endgame(&u.uz) ? (8*mlvl) : (4*mlvl + d(mlvl,4)); - } else if (is_golem(youmonst.data)) { - u.mhmax = golemhp(mntmp); - } else { - if (!mlvl) u.mhmax = rnd(4); - else u.mhmax = d(mlvl, 8); - if (is_home_elemental(&mons[mntmp])) u.mhmax *= 3; - } - u.mh = u.mhmax; + /* + mlvl = adj_lev(&mons[mntmp]); + * We can't do the above, since there's no such thing as an + * "experience level of you as a monster" for a polymorphed character. + */ + mlvl = (int) mons[mntmp].mlevel; + if (youmonst.data->mlet == S_DRAGON && mntmp >= PM_GRAY_DRAGON) { + u.mhmax = In_endgame(&u.uz) ? (8 * mlvl) : (4 * mlvl + d(mlvl, 4)); + } else if (is_golem(youmonst.data)) { + u.mhmax = golemhp(mntmp); + } else { + if (!mlvl) + u.mhmax = rnd(4); + else + u.mhmax = d(mlvl, 8); + if (is_home_elemental(&mons[mntmp])) + u.mhmax *= 3; + } + u.mh = u.mhmax; - if (u.ulevel < mlvl) { - /* Low level characters can't become high level monsters for long */ + if (u.ulevel < mlvl) { +/* Low level characters can't become high level monsters for long */ #ifdef DUMB - /* DRS/NS 2.2.6 messes up -- Peter Kendell */ - int mtd = u.mtimedone, ulv = u.ulevel; + /* DRS/NS 2.2.6 messes up -- Peter Kendell */ + int mtd = u.mtimedone, ulv = u.ulevel; - u.mtimedone = mtd * ulv / mlvl; + u.mtimedone = mtd * ulv / mlvl; #else - u.mtimedone = u.mtimedone * u.ulevel / mlvl; + u.mtimedone = u.mtimedone * u.ulevel / mlvl; #endif - } + } - if (uskin && mntmp != armor_to_dragon(uskin->otyp)) - skinback(FALSE); - break_armor(); - drop_weapon(1); - (void) hideunder(&youmonst); + if (uskin && mntmp != armor_to_dragon(uskin->otyp)) + skinback(FALSE); + break_armor(); + drop_weapon(1); + (void) hideunder(&youmonst); - if (u.utraptype == TT_PIT && u.utrap) { - u.utrap = rn1(6,2); /* time to escape resets */ - } - if (was_blind && !Blind) { /* previous form was eyeless */ - Blinded = 1L; - make_blinded(0L, TRUE); /* remove blindness */ - } - newsym(u.ux,u.uy); /* Change symbol */ + if (u.utraptype == TT_PIT && u.utrap) { + u.utrap = rn1(6, 2); /* time to escape resets */ + } + if (was_blind && !Blind) { /* previous form was eyeless */ + Blinded = 1L; + make_blinded(0L, TRUE); /* remove blindness */ + } + newsym(u.ux, u.uy); /* Change symbol */ - if (!sticky && !u.uswallow && u.ustuck && sticks(youmonst.data)) u.ustuck = 0; - else if (sticky && !sticks(youmonst.data)) uunstick(); - if (u.usteed) { - if (touch_petrifies(u.usteed->data) && - !Stone_resistance && rnl(3)) { - char buf[BUFSZ]; + if (!sticky && !u.uswallow && u.ustuck && sticks(youmonst.data)) + u.ustuck = 0; + else if (sticky && !sticks(youmonst.data)) + uunstick(); + if (u.usteed) { + if (touch_petrifies(u.usteed->data) && !Stone_resistance && rnl(3)) { + char buf[BUFSZ]; - pline("%s touch %s.", no_longer_petrify_resistant, - mon_nam(u.usteed)); - Sprintf(buf, "riding %s", an(u.usteed->data->mname)); - instapetrify(buf); - } - if (!can_ride(u.usteed)) dismount_steed(DISMOUNT_POLY); - } + pline("%s touch %s.", no_longer_petrify_resistant, + mon_nam(u.usteed)); + Sprintf(buf, "riding %s", an(u.usteed->data->mname)); + instapetrify(buf); + } + if (!can_ride(u.usteed)) + dismount_steed(DISMOUNT_POLY); + } - if (flags.verbose) { - static const char use_thec[] = "Use the command #%s to %s."; - static const char monsterc[] = "monster"; + if (flags.verbose) { + static const char use_thec[] = "Use the command #%s to %s."; + static const char monsterc[] = "monster"; - if (can_breathe(youmonst.data)) - pline(use_thec,monsterc,"use your breath weapon"); - if (attacktype(youmonst.data, AT_SPIT)) - pline(use_thec,monsterc,"spit venom"); - if (youmonst.data->mlet == S_NYMPH) - pline(use_thec,monsterc,"remove an iron ball"); - if (attacktype(youmonst.data, AT_GAZE)) - pline(use_thec,monsterc,"gaze at monsters"); - if (is_hider(youmonst.data)) - pline(use_thec,monsterc,"hide"); - if (is_were(youmonst.data)) - pline(use_thec,monsterc,"summon help"); - if (webmaker(youmonst.data)) - pline(use_thec,monsterc,"spin a web"); - if (u.umonnum == PM_GREMLIN) - pline(use_thec,monsterc,"multiply in a fountain"); - if (is_unicorn(youmonst.data)) - pline(use_thec,monsterc,"use your horn"); - if (is_mind_flayer(youmonst.data)) - pline(use_thec,monsterc,"emit a mental blast"); - if (youmonst.data->msound == MS_SHRIEK) /* worthless, actually */ - pline(use_thec,monsterc,"shriek"); - if (is_vampire(youmonst.data)) - pline(use_thec,monsterc,"change shape"); + if (can_breathe(youmonst.data)) + pline(use_thec, monsterc, "use your breath weapon"); + if (attacktype(youmonst.data, AT_SPIT)) + pline(use_thec, monsterc, "spit venom"); + if (youmonst.data->mlet == S_NYMPH) + pline(use_thec, monsterc, "remove an iron ball"); + if (attacktype(youmonst.data, AT_GAZE)) + pline(use_thec, monsterc, "gaze at monsters"); + if (is_hider(youmonst.data)) + pline(use_thec, monsterc, "hide"); + if (is_were(youmonst.data)) + pline(use_thec, monsterc, "summon help"); + if (webmaker(youmonst.data)) + pline(use_thec, monsterc, "spin a web"); + if (u.umonnum == PM_GREMLIN) + pline(use_thec, monsterc, "multiply in a fountain"); + if (is_unicorn(youmonst.data)) + pline(use_thec, monsterc, "use your horn"); + if (is_mind_flayer(youmonst.data)) + pline(use_thec, monsterc, "emit a mental blast"); + if (youmonst.data->msound == MS_SHRIEK) /* worthless, actually */ + pline(use_thec, monsterc, "shriek"); + if (is_vampire(youmonst.data)) + pline(use_thec, monsterc, "change shape"); - if (lays_eggs(youmonst.data) && flags.female) - pline(use_thec,"sit","lay an egg"); - } - /* you now know what an egg of your type looks like */ - if (lays_eggs(youmonst.data)) { - learn_egg_type(u.umonnum); - /* make queen bees recognize killer bee eggs */ - learn_egg_type(egg_type_from_parent(u.umonnum, TRUE)); - } - find_ac(); - if((!Levitation && !u.ustuck && !Flying && - is_pool_or_lava(u.ux,u.uy)) || - (Underwater && !Swimming)) - spoteffects(TRUE); - if (Passes_walls && u.utrap && - (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL)) { - u.utrap = 0; - if (u.utraptype == TT_INFLOOR) - pline_The("rock seems to no longer trap you."); - else { - pline_The("buried ball is no longer bound to you."); - buried_ball_to_freedom(); - } - } else if (likes_lava(youmonst.data) && u.utrap && u.utraptype == TT_LAVA) { - u.utrap = 0; - pline_The("lava now feels soothing."); - } - if (amorphous(youmonst.data) || is_whirly(youmonst.data) || unsolid(youmonst.data)) { - if (Punished) { - You("slip out of the iron chain."); - unpunish(); - } else if (u.utrap && u.utraptype == TT_BURIEDBALL) { - You("slip free of the buried ball and chain."); - buried_ball_to_freedom(); - } - } - if (u.utrap && (u.utraptype == TT_WEB || u.utraptype == TT_BEARTRAP) && - (amorphous(youmonst.data) || is_whirly(youmonst.data) || unsolid(youmonst.data) || - (youmonst.data->msize <= MZ_SMALL && u.utraptype == TT_BEARTRAP))) { - You("are no longer stuck in the %s.", - u.utraptype == TT_WEB ? "web" : "bear trap"); - /* probably should burn webs too if PM_FIRE_ELEMENTAL */ - u.utrap = 0; - } - if (webmaker(youmonst.data) && u.utrap && u.utraptype == TT_WEB) { - You("orient yourself on the web."); - u.utrap = 0; - } - check_strangling(TRUE); /* maybe start strangling */ - (void) polysense(youmonst.data); + if (lays_eggs(youmonst.data) && flags.female) + pline(use_thec, "sit", "lay an egg"); + } + /* you now know what an egg of your type looks like */ + if (lays_eggs(youmonst.data)) { + learn_egg_type(u.umonnum); + /* make queen bees recognize killer bee eggs */ + learn_egg_type(egg_type_from_parent(u.umonnum, TRUE)); + } + find_ac(); + if ((!Levitation && !u.ustuck && !Flying && is_pool_or_lava(u.ux, u.uy)) + || (Underwater && !Swimming)) + spoteffects(TRUE); + if (Passes_walls && u.utrap + && (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL)) { + u.utrap = 0; + if (u.utraptype == TT_INFLOOR) + pline_The("rock seems to no longer trap you."); + else { + pline_The("buried ball is no longer bound to you."); + buried_ball_to_freedom(); + } + } else if (likes_lava(youmonst.data) && u.utrap + && u.utraptype == TT_LAVA) { + u.utrap = 0; + pline_The("lava now feels soothing."); + } + if (amorphous(youmonst.data) || is_whirly(youmonst.data) + || unsolid(youmonst.data)) { + if (Punished) { + You("slip out of the iron chain."); + unpunish(); + } else if (u.utrap && u.utraptype == TT_BURIEDBALL) { + You("slip free of the buried ball and chain."); + buried_ball_to_freedom(); + } + } + if (u.utrap && (u.utraptype == TT_WEB || u.utraptype == TT_BEARTRAP) + && (amorphous(youmonst.data) || is_whirly(youmonst.data) + || unsolid(youmonst.data) || (youmonst.data->msize <= MZ_SMALL + && u.utraptype == TT_BEARTRAP))) { + You("are no longer stuck in the %s.", + u.utraptype == TT_WEB ? "web" : "bear trap"); + /* probably should burn webs too if PM_FIRE_ELEMENTAL */ + u.utrap = 0; + } + if (webmaker(youmonst.data) && u.utrap && u.utraptype == TT_WEB) { + You("orient yourself on the web."); + u.utrap = 0; + } + check_strangling(TRUE); /* maybe start strangling */ + (void) polysense(youmonst.data); - context.botl = 1; - vision_full_recalc = 1; - see_monsters(); - (void) encumber_msg(); + context.botl = 1; + vision_full_recalc = 1; + see_monsters(); + (void) encumber_msg(); - retouch_equipment(2); - /* this might trigger a recursize call to polymon() [stone golem - wielding cockatrice corpse and hit by stone-to-flesh, becomes - flesh golem above, now gets transformed back into stone golem] */ - if (!uarmg) selftouch(no_longer_petrify_resistant); - return(1); + retouch_equipment(2); + /* this might trigger a recursize call to polymon() [stone golem + wielding cockatrice corpse and hit by stone-to-flesh, becomes + flesh golem above, now gets transformed back into stone golem] */ + if (!uarmg) + selftouch(no_longer_petrify_resistant); + return (1); } STATIC_OVL void @@ -803,101 +841,110 @@ break_armor() register 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); - } + 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 (((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)) { - char hornbuf[BUFSZ]; + if ((otmp = uarmh) != 0) { + if (is_flimsy(otmp) && !donning(otmp)) { + char hornbuf[BUFSZ]; - /* Future possiblities: This could damage/destroy helmet */ - Sprintf(hornbuf, "horn%s", plur(num_horns(youmonst.data))); - Your("%s %s through %s.", - hornbuf, vtense(hornbuf, "pierce"), yname(otmp)); - } else { - if (donning(otmp)) cancel_don(); - Your("%s falls to the %s!", - helm_simple_name(otmp), surface(u.ux, u.uy)); - (void) Helmet_off(); - dropx(otmp); - } - } + /* Future possiblities: This could damage/destroy helmet */ + Sprintf(hornbuf, "horn%s", plur(num_horns(youmonst.data))); + Your("%s %s through %s.", hornbuf, vtense(hornbuf, "pierce"), + yname(otmp)); + } else { + if (donning(otmp)) + cancel_don(); + Your("%s falls to the %s!", helm_simple_name(otmp), + 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("%s falls to the %s!", - helm_simple_name(otmp), surface(u.ux, u.uy)); - (void) Helmet_off(); - dropx(otmp); - } + 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("%s falls to the %s!", helm_simple_name(otmp), + 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); - } + 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); + } } } @@ -910,549 +957,563 @@ int alone; boolean candropwep, candropswapwep; if (uwep) { - /* !alone check below is currently superfluous but in the - * future it might not be so if there are monsters which cannot - * wear gloves but can wield weapons - */ - if (!alone || cantwield(youmonst.data)) { - candropwep = canletgo(uwep, ""); - candropswapwep = !u.twoweap || canletgo(uswapwep, ""); - if (alone) { - what = (candropwep && candropswapwep) ? "drop" : "release"; - which = is_sword(uwep) ? "sword" : weapon_descr(uwep); - if (u.twoweap) { - whichtoo = is_sword(uswapwep) ? "sword" : - weapon_descr(uswapwep); - if (strcmp(which, whichtoo)) which = "weapon"; - } - if (uwep->quan != 1L || u.twoweap) which = makeplural(which); + /* !alone check below is currently superfluous but in the + * future it might not be so if there are monsters which cannot + * wear gloves but can wield weapons + */ + if (!alone || cantwield(youmonst.data)) { + candropwep = canletgo(uwep, ""); + candropswapwep = !u.twoweap || canletgo(uswapwep, ""); + if (alone) { + what = (candropwep && candropswapwep) ? "drop" : "release"; + which = is_sword(uwep) ? "sword" : weapon_descr(uwep); + if (u.twoweap) { + whichtoo = + is_sword(uswapwep) ? "sword" : weapon_descr(uswapwep); + if (strcmp(which, whichtoo)) + which = "weapon"; + } + if (uwep->quan != 1L || u.twoweap) + which = makeplural(which); - You("find you must %s %s %s!", what, - the_your[!!strncmp(which, "corpse", 6)], which); - } - if (u.twoweap) { - otmp = uswapwep; - uswapwepgone(); - if (candropswapwep) dropx(otmp); - } - otmp = uwep; - uwepgone(); - if (candropwep) dropx(otmp); - update_inventory(); - } else if (!could_twoweap(youmonst.data)) { - untwoweapon(); - } + You("find you must %s %s %s!", what, + the_your[!!strncmp(which, "corpse", 6)], which); + } + if (u.twoweap) { + otmp = uswapwep; + uswapwepgone(); + if (candropswapwep) + dropx(otmp); + } + otmp = uwep; + uwepgone(); + if (candropwep) + dropx(otmp); + update_inventory(); + } else if (!could_twoweap(youmonst.data)) { + untwoweapon(); + } } } void rehumanize() { - /* You can't revert back while unchanging */ - if (Unchanging && (u.mh < 1)) { - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "killed while stuck in creature form"); - done(DIED); - } + /* You can't revert back while unchanging */ + if (Unchanging && (u.mh < 1)) { + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "killed while stuck in creature form"); + done(DIED); + } - if (emits_light(youmonst.data)) - del_light_source(LS_MONSTER, monst_to_any(&youmonst)); - polyman("return to %s form!", urace.adj); + if (emits_light(youmonst.data)) + del_light_source(LS_MONSTER, monst_to_any(&youmonst)); + polyman("return to %s form!", urace.adj); - if (u.uhp < 1) { - /* can only happen if some bit of code reduces u.uhp - instead of u.mh while poly'd */ - Your("old form was not healthy enough to survive."); - Sprintf(killer.name, "reverting to unhealthy %s form", urace.adj); - killer.format = KILLED_BY; - done(DIED); - } - nomul(0); + if (u.uhp < 1) { + /* can only happen if some bit of code reduces u.uhp + instead of u.mh while poly'd */ + Your("old form was not healthy enough to survive."); + Sprintf(killer.name, "reverting to unhealthy %s form", urace.adj); + killer.format = KILLED_BY; + done(DIED); + } + nomul(0); - context.botl = 1; - vision_full_recalc = 1; - (void) encumber_msg(); + context.botl = 1; + vision_full_recalc = 1; + (void) encumber_msg(); - retouch_equipment(2); - if (!uarmg) selftouch(no_longer_petrify_resistant); + retouch_equipment(2); + if (!uarmg) + selftouch(no_longer_petrify_resistant); } int dobreathe() { - struct attack *mattk; + struct attack *mattk; - if (Strangled) { - You_cant("breathe. Sorry."); - return(0); - } - if (u.uen < 15) { - You("don't have enough energy to breathe!"); - return(0); - } - u.uen -= 15; - context.botl = 1; + if (Strangled) { + You_cant("breathe. Sorry."); + return (0); + } + if (u.uen < 15) { + You("don't have enough energy to breathe!"); + return (0); + } + u.uen -= 15; + context.botl = 1; - if (!getdir((char *)0)) return(0); + if (!getdir((char *) 0)) + return (0); - mattk = attacktype_fordmg(youmonst.data, AT_BREA, AD_ANY); - if (!mattk) - impossible("bad breath attack?"); /* mouthwash needed... */ - else if (!u.dx && !u.dy && !u.dz) - ubreatheu(mattk); - else - buzz((int) (20 + mattk->adtyp-1), (int)mattk->damn, - u.ux, u.uy, u.dx, u.dy); - return(1); + mattk = attacktype_fordmg(youmonst.data, AT_BREA, AD_ANY); + if (!mattk) + impossible("bad breath attack?"); /* mouthwash needed... */ + else if (!u.dx && !u.dy && !u.dz) + ubreatheu(mattk); + else + buzz((int) (20 + mattk->adtyp - 1), (int) mattk->damn, u.ux, u.uy, + u.dx, u.dy); + return (1); } int dospit() { - struct obj *otmp; - struct attack *mattk; + struct obj *otmp; + struct attack *mattk; - if (!getdir((char *)0)) return(0); - mattk = attacktype_fordmg(youmonst.data, AT_SPIT, AD_ANY); - if (!mattk) { - impossible("bad spit attack?"); - } else { - switch (mattk->adtyp) { - case AD_BLND: - case AD_DRST: - otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); - break; - default: - impossible("bad attack type in dospit"); - /* fall through */ - case AD_ACID: - otmp = mksobj(ACID_VENOM, TRUE, FALSE); - break; - } - otmp->spe = 1; /* to indicate it's yours */ - throwit(otmp, 0L, FALSE); - } - return(1); + if (!getdir((char *) 0)) + return (0); + mattk = attacktype_fordmg(youmonst.data, AT_SPIT, AD_ANY); + if (!mattk) { + impossible("bad spit attack?"); + } else { + switch (mattk->adtyp) { + case AD_BLND: + case AD_DRST: + otmp = mksobj(BLINDING_VENOM, TRUE, FALSE); + break; + default: + impossible("bad attack type in dospit"); + /* fall through */ + case AD_ACID: + otmp = mksobj(ACID_VENOM, TRUE, FALSE); + break; + } + otmp->spe = 1; /* to indicate it's yours */ + throwit(otmp, 0L, FALSE); + } + return (1); } int doremove() { - if (!Punished) { - if (u.utrap && u.utraptype == TT_BURIEDBALL) { - pline_The("ball and chain are buried firmly in the %s.", - surface(u.ux, u.uy)); - return(0); - } - You("are not chained to anything!"); - return(0); - } - unpunish(); - return(1); + if (!Punished) { + if (u.utrap && u.utraptype == TT_BURIEDBALL) { + pline_The("ball and chain are buried firmly in the %s.", + surface(u.ux, u.uy)); + return (0); + } + You("are not chained to anything!"); + return (0); + } + unpunish(); + return (1); } int dospinweb() { - register struct trap *ttmp = t_at(u.ux,u.uy); + register struct trap *ttmp = t_at(u.ux, u.uy); - if (Levitation || Is_airlevel(&u.uz) - || Underwater || Is_waterlevel(&u.uz)) { - You("must be on the ground to spin a web."); - return(0); - } - if (u.uswallow) { - You("release web fluid inside %s.", mon_nam(u.ustuck)); - if (is_animal(u.ustuck->data)) { - expels(u.ustuck, u.ustuck->data, TRUE); - return(0); - } - if (is_whirly(u.ustuck->data)) { - int i; + if (Levitation || Is_airlevel(&u.uz) || Underwater + || Is_waterlevel(&u.uz)) { + You("must be on the ground to spin a web."); + return (0); + } + if (u.uswallow) { + You("release web fluid inside %s.", mon_nam(u.ustuck)); + if (is_animal(u.ustuck->data)) { + expels(u.ustuck, u.ustuck->data, TRUE); + return (0); + } + if (is_whirly(u.ustuck->data)) { + int i; - for (i = 0; i < NATTK; i++) - if (u.ustuck->data->mattk[i].aatyp == AT_ENGL) - break; - if (i == NATTK) - impossible("Swallower has no engulfing attack?"); - else { - char sweep[30]; + for (i = 0; i < NATTK; i++) + if (u.ustuck->data->mattk[i].aatyp == AT_ENGL) + break; + if (i == NATTK) + impossible("Swallower has no engulfing attack?"); + else { + char sweep[30]; - sweep[0] = '\0'; - switch(u.ustuck->data->mattk[i].adtyp) { - case AD_FIRE: - Strcpy(sweep, "ignites and "); - break; - case AD_ELEC: - Strcpy(sweep, "fries and "); - break; - case AD_COLD: - Strcpy(sweep, - "freezes, shatters and "); - break; - } - pline_The("web %sis swept away!", sweep); - } - return(0); - } /* default: a nasty jelly-like creature */ - pline_The("web dissolves into %s.", mon_nam(u.ustuck)); - return(0); - } - if (u.utrap) { - You("cannot spin webs while stuck in a trap."); - return(0); - } - exercise(A_DEX, TRUE); - if (ttmp) switch (ttmp->ttyp) { - case PIT: - case SPIKED_PIT: You("spin a web, covering up the pit."); - deltrap(ttmp); - bury_objs(u.ux, u.uy); - newsym(u.ux, u.uy); - return(1); - case SQKY_BOARD: pline_The("squeaky board is muffled."); - deltrap(ttmp); - newsym(u.ux, u.uy); - return(1); - case TELEP_TRAP: - case LEVEL_TELEP: - case MAGIC_PORTAL: - Your("webbing vanishes!"); - return(0); - case WEB: You("make the web thicker."); - return(1); - case HOLE: - case TRAPDOOR: - You("web over the %s.", - (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole"); - deltrap(ttmp); - newsym(u.ux, u.uy); - return 1; - case ROLLING_BOULDER_TRAP: - You("spin a web, jamming the trigger."); - deltrap(ttmp); - newsym(u.ux, u.uy); - return(1); - case ARROW_TRAP: - case DART_TRAP: - case BEAR_TRAP: - case ROCKTRAP: - case FIRE_TRAP: - case LANDMINE: - case SLP_GAS_TRAP: - case RUST_TRAP: - case MAGIC_TRAP: - case ANTI_MAGIC: - case POLY_TRAP: - You("have triggered a trap!"); - dotrap(ttmp, 0); - return(1); - default: - impossible("Webbing over trap type %d?", ttmp->ttyp); - return(0); - } - else if (On_stairs(u.ux, u.uy)) { - /* cop out: don't let them hide the stairs */ - Your("web fails to impede access to the %s.", - (levl[u.ux][u.uy].typ == STAIRS) ? "stairs" : "ladder"); - return(1); - - } - ttmp = maketrap(u.ux, u.uy, WEB); - if (ttmp) { - ttmp->madeby_u = 1; - feeltrap(ttmp); - } - return(1); + sweep[0] = '\0'; + switch (u.ustuck->data->mattk[i].adtyp) { + case AD_FIRE: + Strcpy(sweep, "ignites and "); + break; + case AD_ELEC: + Strcpy(sweep, "fries and "); + break; + case AD_COLD: + Strcpy(sweep, "freezes, shatters and "); + break; + } + pline_The("web %sis swept away!", sweep); + } + return (0); + } /* default: a nasty jelly-like creature */ + pline_The("web dissolves into %s.", mon_nam(u.ustuck)); + return (0); + } + if (u.utrap) { + You("cannot spin webs while stuck in a trap."); + return (0); + } + exercise(A_DEX, TRUE); + if (ttmp) + switch (ttmp->ttyp) { + case PIT: + case SPIKED_PIT: + You("spin a web, covering up the pit."); + deltrap(ttmp); + bury_objs(u.ux, u.uy); + newsym(u.ux, u.uy); + return (1); + case SQKY_BOARD: + pline_The("squeaky board is muffled."); + deltrap(ttmp); + newsym(u.ux, u.uy); + return (1); + case TELEP_TRAP: + case LEVEL_TELEP: + case MAGIC_PORTAL: + Your("webbing vanishes!"); + return (0); + case WEB: + You("make the web thicker."); + return (1); + case HOLE: + case TRAPDOOR: + You("web over the %s.", + (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole"); + deltrap(ttmp); + newsym(u.ux, u.uy); + return 1; + case ROLLING_BOULDER_TRAP: + You("spin a web, jamming the trigger."); + deltrap(ttmp); + newsym(u.ux, u.uy); + return (1); + case ARROW_TRAP: + case DART_TRAP: + case BEAR_TRAP: + case ROCKTRAP: + case FIRE_TRAP: + case LANDMINE: + case SLP_GAS_TRAP: + case RUST_TRAP: + case MAGIC_TRAP: + case ANTI_MAGIC: + case POLY_TRAP: + You("have triggered a trap!"); + dotrap(ttmp, 0); + return (1); + default: + impossible("Webbing over trap type %d?", ttmp->ttyp); + return (0); + } + else if (On_stairs(u.ux, u.uy)) { + /* cop out: don't let them hide the stairs */ + Your("web fails to impede access to the %s.", + (levl[u.ux][u.uy].typ == STAIRS) ? "stairs" : "ladder"); + return (1); + } + ttmp = maketrap(u.ux, u.uy, WEB); + if (ttmp) { + ttmp->madeby_u = 1; + feeltrap(ttmp); + } + return (1); } int dosummon() { - int placeholder; - if (u.uen < 10) { - You("lack the energy to send forth a call for help!"); - return(0); - } - u.uen -= 10; - context.botl = 1; + int placeholder; + if (u.uen < 10) { + You("lack the energy to send forth a call for help!"); + return (0); + } + u.uen -= 10; + context.botl = 1; - You("call upon your brethren for help!"); - exercise(A_WIS, TRUE); - if (!were_summon(youmonst.data, TRUE, &placeholder, (char *)0)) - pline("But none arrive."); - return(1); + You("call upon your brethren for help!"); + exercise(A_WIS, TRUE); + if (!were_summon(youmonst.data, TRUE, &placeholder, (char *) 0)) + pline("But none arrive."); + return (1); } int dogaze() { - register struct monst *mtmp; - int looked = 0; - char qbuf[QBUFSZ]; - int i; - uchar adtyp = 0; + register struct monst *mtmp; + int looked = 0; + char qbuf[QBUFSZ]; + int i; + uchar adtyp = 0; - for (i = 0; i < NATTK; i++) { - if(youmonst.data->mattk[i].aatyp == AT_GAZE) { - adtyp = youmonst.data->mattk[i].adtyp; - break; - } - } - if (adtyp != AD_CONF && adtyp != AD_FIRE) { - impossible("gaze attack %d?", adtyp); - return 0; - } + for (i = 0; i < NATTK; i++) { + if (youmonst.data->mattk[i].aatyp == AT_GAZE) { + adtyp = youmonst.data->mattk[i].adtyp; + break; + } + } + if (adtyp != AD_CONF && adtyp != AD_FIRE) { + impossible("gaze attack %d?", adtyp); + return 0; + } - if (Blind) { - You_cant("see anything to gaze at."); - return 0; - } else if (Hallucination) { - You_cant("gaze at anything you can see."); - return 0; - } - if (u.uen < 15) { - You("lack the energy to use your special gaze!"); - return(0); - } - u.uen -= 15; - context.botl = 1; + if (Blind) { + You_cant("see anything to gaze at."); + return 0; + } else if (Hallucination) { + You_cant("gaze at anything you can see."); + return 0; + } + if (u.uen < 15) { + You("lack the energy to use your special gaze!"); + return (0); + } + u.uen -= 15; + context.botl = 1; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) { - looked++; - if (Invis && !perceives(mtmp->data)) - pline("%s seems not to notice your gaze.", Monnam(mtmp)); - else if (mtmp->minvis && !See_invisible) - You_cant("see where to gaze at %s.", Monnam(mtmp)); - else if (mtmp->m_ap_type == M_AP_FURNITURE - || mtmp->m_ap_type == M_AP_OBJECT) { - looked--; - continue; - } else if (flags.safe_dog && mtmp->mtame && !Confusion) { - You("avoid gazing at %s.", y_monnam(mtmp)); - } else { - if (flags.confirm && mtmp->mpeaceful && !Confusion) { - Sprintf(qbuf, "Really %s %s?", - (adtyp == AD_CONF) ? "confuse" : "attack", - mon_nam(mtmp)); - if (yn(qbuf) != 'y') continue; - setmangry(mtmp); - } - if (!mtmp->mcanmove || mtmp->mstun || mtmp->msleeping || - !mtmp->mcansee || !haseyes(mtmp->data)) { - looked--; - continue; - } - /* No reflection check for consistency with when a monster - * gazes at *you*--only medusa gaze gets reflected then. - */ - if (adtyp == AD_CONF) { - if (!mtmp->mconf) - Your("gaze confuses %s!", mon_nam(mtmp)); - else - pline("%s is getting more and more confused.", - Monnam(mtmp)); - mtmp->mconf = 1; - } else if (adtyp == AD_FIRE) { - int dmg = d(2,6), lev = (int)u.ulevel; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) { + looked++; + if (Invis && !perceives(mtmp->data)) + pline("%s seems not to notice your gaze.", Monnam(mtmp)); + else if (mtmp->minvis && !See_invisible) + You_cant("see where to gaze at %s.", Monnam(mtmp)); + else if (mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT) { + looked--; + continue; + } else if (flags.safe_dog && mtmp->mtame && !Confusion) { + You("avoid gazing at %s.", y_monnam(mtmp)); + } else { + if (flags.confirm && mtmp->mpeaceful && !Confusion) { + Sprintf(qbuf, "Really %s %s?", + (adtyp == AD_CONF) ? "confuse" : "attack", + mon_nam(mtmp)); + if (yn(qbuf) != 'y') + continue; + setmangry(mtmp); + } + if (!mtmp->mcanmove || mtmp->mstun || mtmp->msleeping + || !mtmp->mcansee || !haseyes(mtmp->data)) { + looked--; + continue; + } + /* No reflection check for consistency with when a monster + * gazes at *you*--only medusa gaze gets reflected then. + */ + if (adtyp == AD_CONF) { + if (!mtmp->mconf) + Your("gaze confuses %s!", mon_nam(mtmp)); + else + pline("%s is getting more and more confused.", + Monnam(mtmp)); + mtmp->mconf = 1; + } else if (adtyp == AD_FIRE) { + int dmg = d(2, 6), lev = (int) u.ulevel; - You("attack %s with a fiery gaze!", mon_nam(mtmp)); - if (resists_fire(mtmp)) { - pline_The("fire doesn't burn %s!", mon_nam(mtmp)); - dmg = 0; - } - if (lev > rn2(20)) - (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); - if (lev > rn2(20)) - (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); - if (lev > rn2(25)) - (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); - if (dmg) mtmp->mhp -= dmg; - if (mtmp->mhp <= 0) killed(mtmp); - } - /* For consistency with passive() in uhitm.c, this only - * affects you if the monster is still alive. - */ - if (DEADMONSTER(mtmp)) continue; + You("attack %s with a fiery gaze!", mon_nam(mtmp)); + if (resists_fire(mtmp)) { + pline_The("fire doesn't burn %s!", mon_nam(mtmp)); + dmg = 0; + } + if (lev > rn2(20)) + (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); + if (lev > rn2(20)) + (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); + if (lev > rn2(25)) + (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); + if (dmg) + mtmp->mhp -= dmg; + if (mtmp->mhp <= 0) + killed(mtmp); + } + /* For consistency with passive() in uhitm.c, this only + * affects you if the monster is still alive. + */ + if (DEADMONSTER(mtmp)) + continue; - if (mtmp->data == &mons[PM_FLOATING_EYE] && !mtmp->mcan) { - if (!Free_action) { - You("are frozen by %s gaze!", - s_suffix(mon_nam(mtmp))); - nomul((u.ulevel > 6 || rn2(4)) ? - -d((int)mtmp->m_lev+1, - (int)mtmp->data->mattk[0].damd) - : -200); - multi_reason = "frozen by a monster's gaze"; - nomovemsg = 0; - return 1; - } else - You("stiffen momentarily under %s gaze.", - s_suffix(mon_nam(mtmp))); - } - /* Technically this one shouldn't affect you at all because - * the Medusa gaze is an active monster attack that only - * works on the monster's turn, but for it to *not* have an - * effect would be too weird. - */ - if (mtmp->data == &mons[PM_MEDUSA] && !mtmp->mcan) { - pline( - "Gazing at the awake %s is not a very good idea.", - l_monnam(mtmp)); - /* as if gazing at a sleeping anything is fruitful... */ - You("turn to stone..."); - killer.format = KILLED_BY; - Strcpy(killer.name, - "deliberately meeting Medusa's gaze"); - done(STONING); - } - } - } - } - if (!looked) You("gaze at no place in particular."); - return 1; + if (mtmp->data == &mons[PM_FLOATING_EYE] && !mtmp->mcan) { + if (!Free_action) { + You("are frozen by %s gaze!", + s_suffix(mon_nam(mtmp))); + nomul((u.ulevel > 6 || rn2(4)) + ? -d((int) mtmp->m_lev + 1, + (int) mtmp->data->mattk[0].damd) + : -200); + multi_reason = "frozen by a monster's gaze"; + nomovemsg = 0; + return 1; + } else + You("stiffen momentarily under %s gaze.", + s_suffix(mon_nam(mtmp))); + } + /* Technically this one shouldn't affect you at all because + * the Medusa gaze is an active monster attack that only + * works on the monster's turn, but for it to *not* have an + * effect would be too weird. + */ + if (mtmp->data == &mons[PM_MEDUSA] && !mtmp->mcan) { + pline("Gazing at the awake %s is not a very good idea.", + l_monnam(mtmp)); + /* as if gazing at a sleeping anything is fruitful... */ + You("turn to stone..."); + killer.format = KILLED_BY; + Strcpy(killer.name, "deliberately meeting Medusa's gaze"); + done(STONING); + } + } + } + } + if (!looked) + You("gaze at no place in particular."); + return 1; } int dohide() { - boolean ismimic = youmonst.data->mlet == S_MIMIC, - on_ceiling = is_clinger(youmonst.data) || Flying; + boolean ismimic = youmonst.data->mlet == S_MIMIC, + on_ceiling = is_clinger(youmonst.data) || Flying; - /* can't hide while being held (or holding) or while trapped - (except for floor hiders [trapper or mimic] in pits) */ - if (u.ustuck || (u.utrap && (u.utraptype != TT_PIT || on_ceiling))) { - You_cant("hide while you're %s.", - !u.ustuck ? "trapped" : - !sticks(youmonst.data) ? "being held" : - humanoid(u.ustuck->data) ? "holding someone" : - "holding that creature"); - if (u.uundetected || - (ismimic && youmonst.m_ap_type != M_AP_NOTHING)) { - u.uundetected = 0; - youmonst.m_ap_type = M_AP_NOTHING; - newsym(u.ux, u.uy); - } - return 0; - } - /* note: the eel and hides_under cases are hypothetical; - such critters aren't offered the option of hiding via #monster */ - if (youmonst.data->mlet == S_EEL && !is_pool(u.ux, u.uy)) { - if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)) - The("fountain is not deep enough to hide in."); - else - There("is no water to hide in here."); - u.uundetected = 0; - return 0; - } - if (hides_under(youmonst.data) && !level.objects[u.ux][u.uy]) { - There("is nothing to hide under here."); - u.uundetected = 0; - return 0; - } - /* Planes of Air and Water */ - if (on_ceiling && !has_ceiling(&u.uz)) { - There("is nowhere to hide above you."); - u.uundetected = 0; - return 0; - } - if ((is_hider(youmonst.data) && !Flying) && /* floor hider */ - (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))) { - There("is nowhere to hide beneath you."); - u.uundetected = 0; - return 0; - } - /* TODO? inhibit floor hiding at furniture locations, or - else make youhiding() give smarter messages at such spots */ + /* can't hide while being held (or holding) or while trapped + (except for floor hiders [trapper or mimic] in pits) */ + if (u.ustuck || (u.utrap && (u.utraptype != TT_PIT || on_ceiling))) { + You_cant("hide while you're %s.", + !u.ustuck ? "trapped" : !sticks(youmonst.data) + ? "being held" + : humanoid(u.ustuck->data) + ? "holding someone" + : "holding that creature"); + if (u.uundetected + || (ismimic && youmonst.m_ap_type != M_AP_NOTHING)) { + u.uundetected = 0; + youmonst.m_ap_type = M_AP_NOTHING; + newsym(u.ux, u.uy); + } + return 0; + } + /* note: the eel and hides_under cases are hypothetical; + such critters aren't offered the option of hiding via #monster */ + if (youmonst.data->mlet == S_EEL && !is_pool(u.ux, u.uy)) { + if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)) + The("fountain is not deep enough to hide in."); + else + There("is no water to hide in here."); + u.uundetected = 0; + return 0; + } + if (hides_under(youmonst.data) && !level.objects[u.ux][u.uy]) { + There("is nothing to hide under here."); + u.uundetected = 0; + return 0; + } + /* Planes of Air and Water */ + if (on_ceiling && !has_ceiling(&u.uz)) { + There("is nowhere to hide above you."); + u.uundetected = 0; + return 0; + } + if ((is_hider(youmonst.data) && !Flying) && /* floor hider */ + (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))) { + There("is nowhere to hide beneath you."); + u.uundetected = 0; + return 0; + } + /* TODO? inhibit floor hiding at furniture locations, or + else make youhiding() give smarter messages at such spots */ - if (u.uundetected || (ismimic && youmonst.m_ap_type != M_AP_NOTHING)) { - youhiding(FALSE, 1); /* "you are already hiding" */ - return 0; - } + if (u.uundetected || (ismimic && youmonst.m_ap_type != M_AP_NOTHING)) { + youhiding(FALSE, 1); /* "you are already hiding" */ + return 0; + } - if (ismimic) { - /* should bring up a dialog "what would you like to imitate?" */ - youmonst.m_ap_type = M_AP_OBJECT; - youmonst.mappearance = STRANGE_OBJECT; - } else - u.uundetected = 1; - newsym(u.ux, u.uy); - youhiding(FALSE, 0); /* "you are now hiding" */ - return 1; + if (ismimic) { + /* should bring up a dialog "what would you like to imitate?" */ + youmonst.m_ap_type = M_AP_OBJECT; + youmonst.mappearance = STRANGE_OBJECT; + } else + u.uundetected = 1; + newsym(u.ux, u.uy); + youhiding(FALSE, 0); /* "you are now hiding" */ + return 1; } int dopoly() { - struct permonst *savedat = youmonst.data; - if (is_vampire(youmonst.data)) { - polyself(2); - if (savedat != youmonst.data) { - You("transform into %s.", an(youmonst.data->mname)); - newsym(u.ux,u.uy); - } - } - return(1); + struct permonst *savedat = youmonst.data; + if (is_vampire(youmonst.data)) { + polyself(2); + if (savedat != youmonst.data) { + You("transform into %s.", an(youmonst.data->mname)); + newsym(u.ux, u.uy); + } + } + return (1); } int domindblast() { - struct monst *mtmp, *nmon; + struct monst *mtmp, *nmon; - if (u.uen < 10) { - You("concentrate but lack the energy to maintain doing so."); - return(0); - } - u.uen -= 10; - context.botl = 1; + if (u.uen < 10) { + You("concentrate but lack the energy to maintain doing so."); + return (0); + } + u.uen -= 10; + context.botl = 1; - You("concentrate."); - pline("A wave of psychic energy pours out."); - for(mtmp=fmon; mtmp; mtmp = nmon) { - int u_sen; + You("concentrate."); + pline("A wave of psychic energy pours out."); + for (mtmp = fmon; mtmp; mtmp = nmon) { + int u_sen; - nmon = mtmp->nmon; - if (DEADMONSTER(mtmp)) - continue; - if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM) - continue; - if(mtmp->mpeaceful) - continue; - u_sen = telepathic(mtmp->data) && !mtmp->mcansee; - if (u_sen || (telepathic(mtmp->data) && rn2(2)) || !rn2(10)) { - You("lock in on %s %s.", s_suffix(mon_nam(mtmp)), - u_sen ? "telepathy" : - telepathic(mtmp->data) ? "latent telepathy" : - "mind"); - mtmp->mhp -= rnd(15); - if (mtmp->mhp <= 0) - killed(mtmp); - } - } - return 1; + nmon = mtmp->nmon; + if (DEADMONSTER(mtmp)) + continue; + if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM) + continue; + if (mtmp->mpeaceful) + continue; + u_sen = telepathic(mtmp->data) && !mtmp->mcansee; + if (u_sen || (telepathic(mtmp->data) && rn2(2)) || !rn2(10)) { + You("lock in on %s %s.", s_suffix(mon_nam(mtmp)), + u_sen ? "telepathy" + : telepathic(mtmp->data) ? "latent telepathy" : "mind"); + mtmp->mhp -= rnd(15); + if (mtmp->mhp <= 0) + killed(mtmp); + } + } + return 1; } STATIC_OVL void uunstick() { - pline("%s is no longer in your clutches.", Monnam(u.ustuck)); - u.ustuck = 0; + pline("%s is no longer in your clutches.", Monnam(u.ustuck)); + u.ustuck = 0; } void skinback(silently) boolean silently; { - if (uskin) { - if (!silently) Your("skin returns to its original form."); - uarm = uskin; - uskin = (struct obj *)0; - /* undo save/restore hack */ - uarm->owornmask &= ~I_SPECIAL; - } + if (uskin) { + if (!silently) + Your("skin returns to its original form."); + uarm = uskin; + uskin = (struct obj *) 0; + /* undo save/restore hack */ + uarm->owornmask &= ~I_SPECIAL; + } } const char * @@ -1460,208 +1521,232 @@ mbodypart(mon, part) struct monst *mon; int part; { - static NEARDATA const char - *humanoid_parts[] = { "arm", "eye", "face", "finger", - "fingertip", "foot", "hand", "handed", "head", "leg", - "light headed", "neck", "spine", "toe", "hair", - "blood", "lung", "nose", "stomach"}, - *jelly_parts[] = { "pseudopod", "dark spot", "front", - "pseudopod extension", "pseudopod extremity", - "pseudopod root", "grasp", "grasped", "cerebral area", - "lower pseudopod", "viscous", "middle", "surface", - "pseudopod extremity", "ripples", "juices", - "surface", "sensor", "stomach" }, - *animal_parts[] = { "forelimb", "eye", "face", "foreclaw", "claw tip", - "rear claw", "foreclaw", "clawed", "head", "rear limb", - "light headed", "neck", "spine", "rear claw tip", - "fur", "blood", "lung", "nose", "stomach" }, - *bird_parts[] = { "wing", "eye", "face", "wing", "wing tip", - "foot", "wing", "winged", "head", "leg", - "light headed", "neck", "spine", "toe", - "feathers", "blood", "lung", "bill", "stomach" }, - *horse_parts[] = { "foreleg", "eye", "face", "forehoof", "hoof tip", - "rear hoof", "forehoof", "hooved", "head", "rear leg", - "light headed", "neck", "backbone", "rear hoof tip", - "mane", "blood", "lung", "nose", "stomach"}, - *sphere_parts[] = { "appendage", "optic nerve", "body", "tentacle", - "tentacle tip", "lower appendage", "tentacle", "tentacled", - "body", "lower tentacle", "rotational", "equator", "body", - "lower tentacle tip", "cilia", "life force", "retina", - "olfactory nerve", "interior" }, - *fungus_parts[] = { "mycelium", "visual area", "front", "hypha", - "hypha", "root", "strand", "stranded", "cap area", - "rhizome", "sporulated", "stalk", "root", "rhizome tip", - "spores", "juices", "gill", "gill", "interior" }, - *vortex_parts[] = { "region", "eye", "front", "minor current", - "minor current", "lower current", "swirl", "swirled", - "central core", "lower current", "addled", "center", - "currents", "edge", "currents", "life force", - "center", "leading edge", "interior" }, - *snake_parts[] = { "vestigial limb", "eye", "face", "large scale", - "large scale tip", "rear region", "scale gap", "scale gapped", - "head", "rear region", "light headed", "neck", "length", - "rear scale", "scales", "blood", "lung", "forked tongue", "stomach" }, - *worm_parts[] = { "anterior segment", "light sensitive cell", "clitellum", "setae", - "setae", "posterior segment", "segment", "segmented", - "anterior segment", "posterior", "over stretched", "clitellum", "length", - "posterior setae", "setae", "blood", "skin", "prostomium", "stomach" }, - *fish_parts[] = { "fin", "eye", "premaxillary", "pelvic axillary", - "pelvic fin", "anal fin", "pectoral fin", "finned", "head", "peduncle", - "played out", "gills", "dorsal fin", "caudal fin", - "scales", "blood", "gill", "nostril", "stomach" }; - /* claw attacks are overloaded in mons[]; most humanoids with - such attacks should still reference hands rather than claws */ - static const char not_claws[] = { - S_HUMAN, S_MUMMY, S_ZOMBIE, S_ANGEL, - S_NYMPH, S_LEPRECHAUN, S_QUANTMECH, S_VAMPIRE, - S_ORC, S_GIANT, /* quest nemeses */ - '\0' /* string terminator; assert( S_xxx != 0 ); */ - }; - struct permonst *mptr = mon->data; + static NEARDATA const char + *humanoid_parts[] = { "arm", "eye", "face", "finger", + "fingertip", "foot", "hand", "handed", + "head", "leg", "light headed", "neck", + "spine", "toe", "hair", "blood", + "lung", "nose", "stomach" }, + *jelly_parts[] = { "pseudopod", "dark spot", "front", + "pseudopod extension", "pseudopod extremity", + "pseudopod root", "grasp", "grasped", + "cerebral area", "lower pseudopod", "viscous", + "middle", "surface", "pseudopod extremity", + "ripples", "juices", "surface", "sensor", + "stomach" }, + *animal_parts[] = { "forelimb", "eye", "face", + "foreclaw", "claw tip", "rear claw", + "foreclaw", "clawed", "head", + "rear limb", "light headed", "neck", + "spine", "rear claw tip", "fur", + "blood", "lung", "nose", + "stomach" }, + *bird_parts[] = { "wing", "eye", "face", "wing", + "wing tip", "foot", "wing", "winged", + "head", "leg", "light headed", "neck", + "spine", "toe", "feathers", "blood", + "lung", "bill", "stomach" }, + *horse_parts[] = { "foreleg", "eye", "face", + "forehoof", "hoof tip", "rear hoof", + "forehoof", "hooved", "head", + "rear leg", "light headed", "neck", + "backbone", "rear hoof tip", "mane", + "blood", "lung", "nose", + "stomach" }, + *sphere_parts[] = { "appendage", "optic nerve", "body", "tentacle", + "tentacle tip", "lower appendage", "tentacle", + "tentacled", "body", "lower tentacle", + "rotational", "equator", "body", + "lower tentacle tip", "cilia", "life force", + "retina", "olfactory nerve", "interior" }, + *fungus_parts[] = { "mycelium", "visual area", "front", + "hypha", "hypha", "root", + "strand", "stranded", "cap area", + "rhizome", "sporulated", "stalk", + "root", "rhizome tip", "spores", + "juices", "gill", "gill", + "interior" }, + *vortex_parts[] = { "region", "eye", "front", + "minor current", "minor current", "lower current", + "swirl", "swirled", "central core", + "lower current", "addled", "center", + "currents", "edge", "currents", + "life force", "center", "leading edge", + "interior" }, + *snake_parts[] = { "vestigial limb", "eye", "face", "large scale", + "large scale tip", "rear region", "scale gap", + "scale gapped", "head", "rear region", + "light headed", "neck", "length", "rear scale", + "scales", "blood", "lung", "forked tongue", + "stomach" }, + *worm_parts[] = { "anterior segment", "light sensitive cell", + "clitellum", "setae", "setae", "posterior segment", + "segment", "segmented", "anterior segment", + "posterior", "over stretched", "clitellum", + "length", "posterior setae", "setae", "blood", + "skin", "prostomium", "stomach" }, + *fish_parts[] = { "fin", "eye", "premaxillary", "pelvic axillary", + "pelvic fin", "anal fin", "pectoral fin", "finned", + "head", "peduncle", "played out", "gills", + "dorsal fin", "caudal fin", "scales", "blood", + "gill", "nostril", "stomach" }; + /* claw attacks are overloaded in mons[]; most humanoids with + such attacks should still reference hands rather than claws */ + static const char not_claws[] = { + S_HUMAN, S_MUMMY, S_ZOMBIE, S_ANGEL, S_NYMPH, S_LEPRECHAUN, + S_QUANTMECH, S_VAMPIRE, S_ORC, S_GIANT, /* quest nemeses */ + '\0' /* string terminator; assert( S_xxx != 0 ); */ + }; + struct permonst *mptr = mon->data; - if (part == HAND || part == HANDED) { /* some special cases */ - if (mptr->mlet == S_DOG || mptr->mlet == S_FELINE || - mptr->mlet == S_YETI) - return part == HAND ? "paw" : "pawed"; - if (humanoid(mptr) && attacktype(mptr, AT_CLAW) && - !index(not_claws, mptr->mlet) && - mptr != &mons[PM_STONE_GOLEM] && - mptr != &mons[PM_INCUBUS] && mptr != &mons[PM_SUCCUBUS]) - return part == HAND ? "claw" : "clawed"; - } - if ((mptr == &mons[PM_MUMAK] || mptr == &mons[PM_MASTODON]) && - part == NOSE) - return "trunk"; - if (mptr == &mons[PM_SHARK] && part == HAIR) - return "skin"; /* sharks don't have scales */ - if ((mptr == &mons[PM_JELLYFISH] || mptr == &mons[PM_KRAKEN]) && - (part == ARM || part == FINGER || - part == HAND || part == FOOT || part == TOE)) - return "tentacle"; - if (mptr == &mons[PM_FLOATING_EYE] && part == EYE) - return "cornea"; - if (humanoid(mptr) && - (part == ARM || part == FINGER || part == FINGERTIP || - part == HAND || part == HANDED)) - return humanoid_parts[part]; - if (mptr == &mons[PM_RAVEN]) - return bird_parts[part]; - if (mptr->mlet == S_CENTAUR || mptr->mlet == S_UNICORN || - (mptr == &mons[PM_ROTHE] && part != HAIR)) - return horse_parts[part]; - if (mptr->mlet == S_LIGHT) { - if (part == HANDED) return "rayed"; - else if (part == ARM || part == FINGER || - part == FINGERTIP || part == HAND) return "ray"; - else return "beam"; - } - if (mptr == &mons[PM_STALKER] && part == HEAD) - return "head"; - if (mptr->mlet == S_EEL && mptr != &mons[PM_JELLYFISH]) - return fish_parts[part]; - if (mptr->mlet == S_WORM) - return worm_parts[part]; - if (slithy(mptr) || (mptr->mlet == S_DRAGON && part == HAIR)) - return snake_parts[part]; - if (mptr->mlet == S_EYE) - return sphere_parts[part]; - if (mptr->mlet == S_JELLY || mptr->mlet == S_PUDDING || - mptr->mlet == S_BLOB || mptr == &mons[PM_JELLYFISH]) - return jelly_parts[part]; - if (mptr->mlet == S_VORTEX || mptr->mlet == S_ELEMENTAL) - return vortex_parts[part]; - if (mptr->mlet == S_FUNGUS) - return fungus_parts[part]; - if (humanoid(mptr)) - return humanoid_parts[part]; - return animal_parts[part]; + if (part == HAND || part == HANDED) { /* some special cases */ + if (mptr->mlet == S_DOG || mptr->mlet == S_FELINE + || mptr->mlet == S_YETI) + return part == HAND ? "paw" : "pawed"; + if (humanoid(mptr) && attacktype(mptr, AT_CLAW) + && !index(not_claws, mptr->mlet) && mptr != &mons[PM_STONE_GOLEM] + && mptr != &mons[PM_INCUBUS] && mptr != &mons[PM_SUCCUBUS]) + return part == HAND ? "claw" : "clawed"; + } + if ((mptr == &mons[PM_MUMAK] || mptr == &mons[PM_MASTODON]) + && part == NOSE) + return "trunk"; + if (mptr == &mons[PM_SHARK] && part == HAIR) + return "skin"; /* sharks don't have scales */ + if ((mptr == &mons[PM_JELLYFISH] || mptr == &mons[PM_KRAKEN]) + && (part == ARM || part == FINGER || part == HAND || part == FOOT + || part == TOE)) + return "tentacle"; + if (mptr == &mons[PM_FLOATING_EYE] && part == EYE) + return "cornea"; + if (humanoid(mptr) && (part == ARM || part == FINGER || part == FINGERTIP + || part == HAND || part == HANDED)) + return humanoid_parts[part]; + if (mptr == &mons[PM_RAVEN]) + return bird_parts[part]; + if (mptr->mlet == S_CENTAUR || mptr->mlet == S_UNICORN + || (mptr == &mons[PM_ROTHE] && part != HAIR)) + return horse_parts[part]; + if (mptr->mlet == S_LIGHT) { + if (part == HANDED) + return "rayed"; + else if (part == ARM || part == FINGER || part == FINGERTIP + || part == HAND) + return "ray"; + else + return "beam"; + } + if (mptr == &mons[PM_STALKER] && part == HEAD) + return "head"; + if (mptr->mlet == S_EEL && mptr != &mons[PM_JELLYFISH]) + return fish_parts[part]; + if (mptr->mlet == S_WORM) + return worm_parts[part]; + if (slithy(mptr) || (mptr->mlet == S_DRAGON && part == HAIR)) + return snake_parts[part]; + if (mptr->mlet == S_EYE) + return sphere_parts[part]; + if (mptr->mlet == S_JELLY || mptr->mlet == S_PUDDING + || mptr->mlet == S_BLOB || mptr == &mons[PM_JELLYFISH]) + return jelly_parts[part]; + if (mptr->mlet == S_VORTEX || mptr->mlet == S_ELEMENTAL) + return vortex_parts[part]; + if (mptr->mlet == S_FUNGUS) + return fungus_parts[part]; + if (humanoid(mptr)) + return humanoid_parts[part]; + return animal_parts[part]; } const char * body_part(part) int part; { - return mbodypart(&youmonst, part); + return mbodypart(&youmonst, part); } int poly_gender() { -/* Returns gender of polymorphed player; 0/1=same meaning as flags.female, - * 2=none. - */ - if (is_neuter(youmonst.data) || !humanoid(youmonst.data)) return 2; - return flags.female; + /* Returns gender of polymorphed player; 0/1=same meaning as flags.female, + * 2=none. + */ + if (is_neuter(youmonst.data) || !humanoid(youmonst.data)) + return 2; + return flags.female; } void ugolemeffects(damtype, dam) int damtype, dam; { - int heal = 0; - /* We won't bother with "slow"/"haste" since players do not - * have a monster-specific slow/haste so there is no way to - * restore the old velocity once they are back to human. - */ - if (u.umonnum != PM_FLESH_GOLEM && u.umonnum != PM_IRON_GOLEM) - return; - switch (damtype) { - case AD_ELEC: if (u.umonnum == PM_FLESH_GOLEM) - heal = dam / 6; /* Approx 1 per die */ - break; - case AD_FIRE: if (u.umonnum == PM_IRON_GOLEM) - heal = dam; - break; - } - if (heal && (u.mh < u.mhmax)) { - u.mh += heal; - if (u.mh > u.mhmax) u.mh = u.mhmax; - context.botl = 1; - pline("Strangely, you feel better than before."); - exercise(A_STR, TRUE); - } + int heal = 0; + /* We won't bother with "slow"/"haste" since players do not + * have a monster-specific slow/haste so there is no way to + * restore the old velocity once they are back to human. + */ + if (u.umonnum != PM_FLESH_GOLEM && u.umonnum != PM_IRON_GOLEM) + return; + switch (damtype) { + case AD_ELEC: + if (u.umonnum == PM_FLESH_GOLEM) + heal = dam / 6; /* Approx 1 per die */ + break; + case AD_FIRE: + if (u.umonnum == PM_IRON_GOLEM) + heal = dam; + break; + } + if (heal && (u.mh < u.mhmax)) { + u.mh += heal; + if (u.mh > u.mhmax) + u.mh = u.mhmax; + context.botl = 1; + pline("Strangely, you feel better than before."); + exercise(A_STR, TRUE); + } } STATIC_OVL int armor_to_dragon(atyp) int atyp; { - switch(atyp) { - case GRAY_DRAGON_SCALE_MAIL: - case GRAY_DRAGON_SCALES: - return PM_GRAY_DRAGON; - case SILVER_DRAGON_SCALE_MAIL: - case SILVER_DRAGON_SCALES: - return PM_SILVER_DRAGON; -#if 0 /* DEFERRED */ + switch (atyp) { + case GRAY_DRAGON_SCALE_MAIL: + case GRAY_DRAGON_SCALES: + return PM_GRAY_DRAGON; + case SILVER_DRAGON_SCALE_MAIL: + case SILVER_DRAGON_SCALES: + return PM_SILVER_DRAGON; +#if 0 /* DEFERRED */ case SHIMMERING_DRAGON_SCALE_MAIL: case SHIMMERING_DRAGON_SCALES: return PM_SHIMMERING_DRAGON; #endif - case RED_DRAGON_SCALE_MAIL: - case RED_DRAGON_SCALES: - return PM_RED_DRAGON; - case ORANGE_DRAGON_SCALE_MAIL: - case ORANGE_DRAGON_SCALES: - return PM_ORANGE_DRAGON; - case WHITE_DRAGON_SCALE_MAIL: - case WHITE_DRAGON_SCALES: - return PM_WHITE_DRAGON; - case BLACK_DRAGON_SCALE_MAIL: - case BLACK_DRAGON_SCALES: - return PM_BLACK_DRAGON; - case BLUE_DRAGON_SCALE_MAIL: - case BLUE_DRAGON_SCALES: - return PM_BLUE_DRAGON; - case GREEN_DRAGON_SCALE_MAIL: - case GREEN_DRAGON_SCALES: - return PM_GREEN_DRAGON; - case YELLOW_DRAGON_SCALE_MAIL: - case YELLOW_DRAGON_SCALES: - return PM_YELLOW_DRAGON; - default: - return -1; - } + case RED_DRAGON_SCALE_MAIL: + case RED_DRAGON_SCALES: + return PM_RED_DRAGON; + case ORANGE_DRAGON_SCALE_MAIL: + case ORANGE_DRAGON_SCALES: + return PM_ORANGE_DRAGON; + case WHITE_DRAGON_SCALE_MAIL: + case WHITE_DRAGON_SCALES: + return PM_WHITE_DRAGON; + case BLACK_DRAGON_SCALE_MAIL: + case BLACK_DRAGON_SCALES: + return PM_BLACK_DRAGON; + case BLUE_DRAGON_SCALE_MAIL: + case BLUE_DRAGON_SCALES: + return PM_BLUE_DRAGON; + case GREEN_DRAGON_SCALE_MAIL: + case GREEN_DRAGON_SCALES: + return PM_GREEN_DRAGON; + case YELLOW_DRAGON_SCALE_MAIL: + case YELLOW_DRAGON_SCALES: + return PM_YELLOW_DRAGON; + default: + return -1; + } } /* @@ -1671,31 +1756,31 @@ static boolean polysense(mptr) struct permonst *mptr; { - short warnidx = 0; - context.warntype.speciesidx = 0; - context.warntype.species = 0; - context.warntype.polyd = 0; + short warnidx = 0; + context.warntype.speciesidx = 0; + context.warntype.species = 0; + context.warntype.polyd = 0; - switch (monsndx(mptr)) { - case PM_PURPLE_WORM: - warnidx = PM_SHRIEKER; - break; - case PM_VAMPIRE: - case PM_VAMPIRE_LORD: - context.warntype.polyd = M2_HUMAN | M2_ELF; - HWarn_of_mon |= FROMRACE; - return TRUE; - } - if (warnidx) { - context.warntype.speciesidx = warnidx; - context.warntype.species = &mons[warnidx]; - HWarn_of_mon |= FROMRACE; - return TRUE; - } - context.warntype.speciesidx = 0; - context.warntype.species = 0; - HWarn_of_mon &= ~FROMRACE; - return FALSE; + switch (monsndx(mptr)) { + case PM_PURPLE_WORM: + warnidx = PM_SHRIEKER; + break; + case PM_VAMPIRE: + case PM_VAMPIRE_LORD: + context.warntype.polyd = M2_HUMAN | M2_ELF; + HWarn_of_mon |= FROMRACE; + return TRUE; + } + if (warnidx) { + context.warntype.speciesidx = warnidx; + context.warntype.species = &mons[warnidx]; + HWarn_of_mon |= FROMRACE; + return TRUE; + } + context.warntype.speciesidx = 0; + context.warntype.species = 0; + HWarn_of_mon &= ~FROMRACE; + return FALSE; } /*polyself.c*/ diff --git a/src/potion.c b/src/potion.c index 0c5a42841..b680cf4f4 100644 --- a/src/potion.c +++ b/src/potion.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 potion.c $NHDT-Date: 1428972597 2015/04/14 00:49:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.111 $ */ +/* NetHack 3.6 potion.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.114 $ */ /* NetHack 3.6 potion.c $Date: 2013/11/05 00:57:55 $ $Revision: 1.91 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,19 +11,21 @@ static NEARDATA int nothing, unkn; static NEARDATA const char beverages[] = { POTION_CLASS, 0 }; STATIC_DCL long FDECL(itimeout, (long)); -STATIC_DCL long FDECL(itimeout_incr, (long,int)); +STATIC_DCL long FDECL(itimeout_incr, (long, int)); STATIC_DCL void NDECL(ghost_from_bottle); -STATIC_DCL boolean FDECL(H2Opotion_dip, (struct obj *,struct obj *, - BOOLEAN_P,const char *)); -STATIC_DCL short FDECL(mixtype, (struct obj *,struct obj *)); +STATIC_DCL boolean +FDECL(H2Opotion_dip, (struct obj *, struct obj *, BOOLEAN_P, const char *)); +STATIC_DCL short FDECL(mixtype, (struct obj *, struct obj *)); /* force `val' to be within valid range for intrinsic timeout value */ STATIC_OVL long itimeout(val) long val; { - if (val >= TIMEOUT) val = TIMEOUT; - else if (val < 1) val = 0; + if (val >= TIMEOUT) + val = TIMEOUT; + else if (val < 1) + val = 0; return val; } @@ -34,7 +36,7 @@ itimeout_incr(old, incr) long old; int incr; { - return itimeout((old & TIMEOUT) + (long)incr); + return itimeout((old & TIMEOUT) + (long) incr); } /* set the timeout field of intrinsic `which' */ @@ -56,95 +58,101 @@ int incr; } void -make_confused(xtime,talk) +make_confused(xtime, talk) long xtime; boolean talk; { - long old = HConfusion; + long old = HConfusion; - if (Unaware) talk = FALSE; + if (Unaware) + talk = FALSE; - if (!xtime && old) { - if (talk) - You_feel("less %s now.", - Hallucination ? "trippy" : "confused"); - } - if ((xtime && !old) || (!xtime && old)) context.botl = TRUE; + if (!xtime && old) { + if (talk) + You_feel("less %s now.", Hallucination ? "trippy" : "confused"); + } + if ((xtime && !old) || (!xtime && old)) + context.botl = TRUE; - set_itimeout(&HConfusion, xtime); + set_itimeout(&HConfusion, xtime); } void -make_stunned(xtime,talk) +make_stunned(xtime, talk) long xtime; boolean talk; { - long old = HStun; + long old = HStun; - if (Unaware) talk = FALSE; + if (Unaware) + talk = FALSE; - if (!xtime && old) { - if (talk) - You_feel("%s now.", - Hallucination ? "less wobbly" : "a bit steadier"); - } - if (xtime && !old) { - if (talk) { - if (u.usteed) - You("wobble in the saddle."); - else - You("%s...", stagger(youmonst.data, "stagger")); - } - } - if ((!xtime && old) || (xtime && !old)) context.botl = TRUE; + if (!xtime && old) { + if (talk) + You_feel("%s now.", + Hallucination ? "less wobbly" : "a bit steadier"); + } + if (xtime && !old) { + if (talk) { + if (u.usteed) + You("wobble in the saddle."); + else + You("%s...", stagger(youmonst.data, "stagger")); + } + } + if ((!xtime && old) || (xtime && !old)) + context.botl = TRUE; - set_itimeout(&HStun, xtime); + set_itimeout(&HStun, xtime); } void make_sick(xtime, cause, talk, type) long xtime; -const char *cause; /* sickness cause */ +const char *cause; /* sickness cause */ boolean talk; int type; { - long old = Sick; + long old = Sick; #if 0 if (Unaware) talk = FALSE; #endif - if (xtime > 0L) { - if (Sick_resistance) return; - if (!old) { - /* newly sick */ - You_feel("deathly sick."); - } else { - /* already sick */ - if (talk) You_feel("%s worse.", - xtime <= Sick/2L ? "much" : "even"); - } - set_itimeout(&Sick, xtime); - u.usick_type |= type; - context.botl = TRUE; - } else if (old && (type & u.usick_type)) { - /* was sick, now not */ - u.usick_type &= ~type; - if (u.usick_type) { /* only partly cured */ - if (talk) You_feel("somewhat better."); - set_itimeout(&Sick, Sick * 2); /* approximation */ - } else { - if (talk) You_feel("cured. What a relief!"); - Sick = 0L; /* set_itimeout(&Sick, 0L) */ - } - context.botl = TRUE; - } + if (xtime > 0L) { + if (Sick_resistance) + return; + if (!old) { + /* newly sick */ + You_feel("deathly sick."); + } else { + /* already sick */ + if (talk) + You_feel("%s worse.", xtime <= Sick / 2L ? "much" : "even"); + } + set_itimeout(&Sick, xtime); + u.usick_type |= type; + context.botl = TRUE; + } else if (old && (type & u.usick_type)) { + /* was sick, now not */ + u.usick_type &= ~type; + if (u.usick_type) { /* only partly cured */ + if (talk) + You_feel("somewhat better."); + set_itimeout(&Sick, Sick * 2); /* approximation */ + } else { + if (talk) + You_feel("cured. What a relief!"); + Sick = 0L; /* set_itimeout(&Sick, 0L) */ + } + context.botl = TRUE; + } - if (Sick) { - exercise(A_CON, FALSE); - delayed_killer(SICK, KILLED_BY_AN, cause); - } else - dealloc_killer(find_delayed_killer(SICK)); + if (Sick) { + exercise(A_CON, FALSE); + delayed_killer(SICK, KILLED_BY_AN, cause); + } else + dealloc_killer(find_delayed_killer(SICK)); } void @@ -152,18 +160,20 @@ make_slimed(xtime, msg) long xtime; const char *msg; { - long old = Slimed; + long old = Slimed; #if 0 if (Unaware) msg = 0; #endif - if ((!xtime && old) || (xtime && !old)) { - if (msg) pline1(msg); - context.botl = 1; - } - set_itimeout(&Slimed, xtime); - if (!Slimed) dealloc_killer(find_delayed_killer(SLIMED)); + if ((!xtime && old) || (xtime && !old)) { + if (msg) + pline1(msg); + context.botl = 1; + } + set_itimeout(&Slimed, xtime); + if (!Slimed) + dealloc_killer(find_delayed_killer(SLIMED)); } /* start or stop petrification */ @@ -174,19 +184,22 @@ const char *msg; int killedby; const char *killername; { - long old = Stoned; + long old = Stoned; #if 0 if (Unaware) msg = 0; #endif - if ((!xtime && old) || (xtime && !old)) { - if (msg) pline1(msg); - /* context.botl = 1; --- Stoned is not a status line item */ - } - set_itimeout(&Stoned, xtime); - if (!Stoned) dealloc_killer(find_delayed_killer(STONED)); - else if (!old) delayed_killer(STONED, killedby, killername); + if ((!xtime && old) || (xtime && !old)) { + if (msg) + pline1(msg); + /* context.botl = 1; --- Stoned is not a status line item */ + } + set_itimeout(&Stoned, xtime); + if (!Stoned) + dealloc_killer(find_delayed_killer(STONED)); + else if (!old) + delayed_killer(STONED, killedby, killername); } void @@ -194,14 +207,16 @@ make_vomiting(xtime, talk) long xtime; boolean talk; { - long old = Vomiting; + long old = Vomiting; - if (Unaware) talk = FALSE; + if (Unaware) + talk = FALSE; - if(!xtime && old) - if(talk) You_feel("much less nauseated now."); + if (!xtime && old) + if (talk) + You_feel("much less nauseated now."); - set_itimeout(&Vomiting, xtime); + set_itimeout(&Vomiting, xtime); } static const char vismsg[] = "vision seems to %s for a moment but is %s now."; @@ -212,171 +227,182 @@ make_blinded(xtime, talk) long xtime; boolean talk; { - long old = Blinded; - boolean u_could_see, can_see_now; - const char *eyes; + long old = Blinded; + boolean u_could_see, can_see_now; + const char *eyes; - /* we need to probe ahead in case the Eyes of the Overworld - are or will be overriding blindness */ - u_could_see = !Blind; - Blinded = xtime ? 1L : 0L; - can_see_now = !Blind; - Blinded = old; /* restore */ + /* we need to probe ahead in case the Eyes of the Overworld + are or will be overriding blindness */ + u_could_see = !Blind; + Blinded = xtime ? 1L : 0L; + can_see_now = !Blind; + Blinded = old; /* restore */ - if (Unaware) talk = FALSE; + if (Unaware) + talk = FALSE; - if (can_see_now && !u_could_see) { /* regaining sight */ - if (talk) { - if (Hallucination) - pline("Far out! Everything is all cosmic again!"); - else - You("can see again."); - } - } else if (old && !xtime) { - /* clearing temporary blindness without toggling blindness */ - if (talk) { - if (!haseyes(youmonst.data)) { - strange_feeling((struct obj *)0, (char *)0); - } else if (Blindfolded) { - eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) eyes = makeplural(eyes); - Your(eyemsg, eyes, vtense(eyes, "itch")); - } else { /* Eyes of the Overworld */ - Your(vismsg, "brighten", - Hallucination ? "sadder" : "normal"); - } - } - } + if (can_see_now && !u_could_see) { /* regaining sight */ + if (talk) { + if (Hallucination) + pline("Far out! Everything is all cosmic again!"); + else + You("can see again."); + } + } else if (old && !xtime) { + /* clearing temporary blindness without toggling blindness */ + if (talk) { + if (!haseyes(youmonst.data)) { + strange_feeling((struct obj *) 0, (char *) 0); + } else if (Blindfolded) { + eyes = body_part(EYE); + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your(eyemsg, eyes, vtense(eyes, "itch")); + } else { /* Eyes of the Overworld */ + Your(vismsg, "brighten", Hallucination ? "sadder" : "normal"); + } + } + } - if (u_could_see && !can_see_now) { /* losing sight */ - if (talk) { - if (Hallucination) - pline("Oh, bummer! Everything is dark! Help!"); - else - pline("A cloud of darkness falls upon you."); - } - /* Before the hero goes blind, set the ball&chain variables. */ - if (Punished) set_bc(0); - } else if (!old && xtime) { - /* setting temporary blindness without toggling blindness */ - if (talk) { - if (!haseyes(youmonst.data)) { - strange_feeling((struct obj *)0, (char *)0); - } else if (Blindfolded) { - eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) eyes = makeplural(eyes); - Your(eyemsg, eyes, vtense(eyes, "twitch")); - } else { /* Eyes of the Overworld */ - Your(vismsg, "dim", - Hallucination ? "happier" : "normal"); - } - } - } + if (u_could_see && !can_see_now) { /* losing sight */ + if (talk) { + if (Hallucination) + pline("Oh, bummer! Everything is dark! Help!"); + else + pline("A cloud of darkness falls upon you."); + } + /* Before the hero goes blind, set the ball&chain variables. */ + if (Punished) + set_bc(0); + } else if (!old && xtime) { + /* setting temporary blindness without toggling blindness */ + if (talk) { + if (!haseyes(youmonst.data)) { + strange_feeling((struct obj *) 0, (char *) 0); + } else if (Blindfolded) { + eyes = body_part(EYE); + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your(eyemsg, eyes, vtense(eyes, "twitch")); + } else { /* Eyes of the Overworld */ + Your(vismsg, "dim", Hallucination ? "happier" : "normal"); + } + } + } - set_itimeout(&Blinded, xtime); + set_itimeout(&Blinded, xtime); - if (u_could_see ^ can_see_now) { /* one or the other but not both */ - context.botl = 1; - vision_full_recalc = 1; /* blindness just got toggled */ - /* this vision recalculation used to be deferred until - moveloop(), but that made it possible for vision - irregularities to occur (cited case was force bolt - hitting adjacent potion of blindness and then a - secret door; hero was blinded by vapors but then - got the message "a door appears in the wall") */ - vision_recalc(0); - if (Blind_telepat || Infravision) see_monsters(); + if (u_could_see ^ can_see_now) { /* one or the other but not both */ + context.botl = 1; + vision_full_recalc = 1; /* blindness just got toggled */ + /* this vision recalculation used to be deferred until + moveloop(), but that made it possible for vision + irregularities to occur (cited case was force bolt + hitting adjacent potion of blindness and then a + secret door; hero was blinded by vapors but then + got the message "a door appears in the wall") */ + vision_recalc(0); + if (Blind_telepat || Infravision) + see_monsters(); - /* update dknown flag for inventory picked up while blind */ - if (can_see_now) learn_unseen_invent(); - } + /* update dknown flag for inventory picked up while blind */ + if (can_see_now) + learn_unseen_invent(); + } } boolean make_hallucinated(xtime, talk, mask) -long xtime; /* nonzero if this is an attempt to turn on hallucination */ +long xtime; /* nonzero if this is an attempt to turn on hallucination */ boolean talk; -long mask; /* nonzero if resistance status should change by mask */ +long mask; /* nonzero if resistance status should change by mask */ { - long old = HHallucination; - boolean changed = 0; - const char *message, *verb; + long old = HHallucination; + boolean changed = 0; + const char *message, *verb; - if (Unaware) talk = FALSE; + if (Unaware) + talk = FALSE; - message = (!xtime) ? "Everything %s SO boring now." : - "Oh wow! Everything %s so cosmic!"; - verb = (!Blind) ? "looks" : "feels"; + message = (!xtime) ? "Everything %s SO boring now." + : "Oh wow! Everything %s so cosmic!"; + verb = (!Blind) ? "looks" : "feels"; - if (mask) { - if (HHallucination) changed = TRUE; + if (mask) { + if (HHallucination) + changed = TRUE; - if (!xtime) EHalluc_resistance |= mask; - else EHalluc_resistance &= ~mask; - } else { - if (!EHalluc_resistance && (!!HHallucination != !!xtime)) - changed = TRUE; - set_itimeout(&HHallucination, xtime); + if (!xtime) + EHalluc_resistance |= mask; + else + EHalluc_resistance &= ~mask; + } else { + if (!EHalluc_resistance && (!!HHallucination != !!xtime)) + changed = TRUE; + set_itimeout(&HHallucination, xtime); - /* clearing temporary hallucination without toggling vision */ - if (!changed && !HHallucination && old && talk) { - if (!haseyes(youmonst.data)) { - strange_feeling((struct obj *)0, (char *)0); - } else if (Blind) { - const char *eyes = body_part(EYE); + /* clearing temporary hallucination without toggling vision */ + if (!changed && !HHallucination && old && talk) { + if (!haseyes(youmonst.data)) { + strange_feeling((struct obj *) 0, (char *) 0); + } else if (Blind) { + const char *eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) eyes = makeplural(eyes); - Your(eyemsg, eyes, vtense(eyes, "itch")); - } else { /* Grayswandir */ - Your(vismsg, "flatten", "normal"); - } - } - } + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your(eyemsg, eyes, vtense(eyes, "itch")); + } else { /* Grayswandir */ + Your(vismsg, "flatten", "normal"); + } + } + } - if (changed) { - /* in case we're mimicking an orange (hallucinatory form - of mimicking gold) update the mimicking's-over message */ - if (!Hallucination) eatmupdate(); + if (changed) { + /* in case we're mimicking an orange (hallucinatory form + of mimicking gold) update the mimicking's-over message */ + if (!Hallucination) + eatmupdate(); - if (u.uswallow) { - swallowed(0); /* redraw swallow display */ - } else { - /* The see_* routines should be called *before* the pline. */ - see_monsters(); - see_objects(); - see_traps(); - } + if (u.uswallow) { + swallowed(0); /* redraw swallow display */ + } else { + /* The see_* routines should be called *before* the pline. */ + see_monsters(); + see_objects(); + see_traps(); + } - /* for perm_inv and anything similar - (eg. Qt windowport's equipped items display) */ - update_inventory(); + /* for perm_inv and anything similar + (eg. Qt windowport's equipped items display) */ + update_inventory(); - context.botl = 1; - if (talk) pline(message, verb); - } - return changed; + context.botl = 1; + if (talk) + pline(message, verb); + } + return changed; } STATIC_OVL void ghost_from_bottle() { - struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS); + struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS); - if (!mtmp) { - pline("This bottle turns out to be empty."); - return; - } - if (Blind) { - pline("As you open the bottle, %s emerges.", something); - return; - } - pline("As you open the bottle, an enormous %s emerges!", - Hallucination ? rndmonnam(NULL) : (const char *)"ghost"); - if(flags.verbose) - You("are frightened to death, and unable to move."); - nomul(-3); - multi_reason = "being frightened to death"; - nomovemsg = "You regain your composure."; + if (!mtmp) { + pline("This bottle turns out to be empty."); + return; + } + if (Blind) { + pline("As you open the bottle, %s emerges.", something); + return; + } + pline("As you open the bottle, an enormous %s emerges!", + Hallucination ? rndmonnam(NULL) : (const char *) "ghost"); + if (flags.verbose) + You("are frightened to death, and unable to move."); + nomul(-3); + multi_reason = "being frightened to death"; + nomovemsg = "You regain your composure."; } /* "Quaffing is like drinking, except you spill more." -- Terry Pratchett @@ -384,667 +410,682 @@ ghost_from_bottle() int dodrink() { - register struct obj *otmp; - const char *potion_descr; + register struct obj *otmp; + const char *potion_descr; - if (Strangled) { - pline("If you can't breathe air, how can you drink liquid?"); - return 0; - } - /* Is there a fountain to drink from here? */ - if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) && - /* not as low as floor level but similar restrictions apply */ - can_reach_floor(FALSE)) { - if(yn("Drink from the fountain?") == 'y') { - drinkfountain(); - return 1; - } - } - /* Or a kitchen sink? */ - if (IS_SINK(levl[u.ux][u.uy].typ) && - /* not as low as floor level but similar restrictions apply */ - can_reach_floor(FALSE)) { - if (yn("Drink from the sink?") == 'y') { - drinksink(); - return 1; - } - } + if (Strangled) { + pline("If you can't breathe air, how can you drink liquid?"); + return 0; + } + /* Is there a fountain to drink from here? */ + if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) && + /* not as low as floor level but similar restrictions apply */ + can_reach_floor(FALSE)) { + if (yn("Drink from the fountain?") == 'y') { + drinkfountain(); + return 1; + } + } + /* Or a kitchen sink? */ + if (IS_SINK(levl[u.ux][u.uy].typ) && + /* not as low as floor level but similar restrictions apply */ + can_reach_floor(FALSE)) { + if (yn("Drink from the sink?") == 'y') { + drinksink(); + return 1; + } + } - /* Or are you surrounded by water? */ - if (Underwater && !u.uswallow) { - if (yn("Drink the water around you?") == 'y') { - pline("Do you know what lives in this water?"); - return 1; - } - } + /* Or are you surrounded by water? */ + if (Underwater && !u.uswallow) { + if (yn("Drink the water around you?") == 'y') { + pline("Do you know what lives in this water?"); + return 1; + } + } - otmp = getobj(beverages, "drink"); - if(!otmp) return(0); + otmp = getobj(beverages, "drink"); + if (!otmp) + return (0); - /* quan > 1 used to be left to useup(), but we need to force - the current potion to be unworn, and don't want to do - that for the entire stack when starting with more than 1. - [Drinking a wielded potion of polymorph can trigger a shape - change which causes hero's weapon to be dropped. In 3.4.x, - that led to an "object lost" panic since subsequent useup() - was no longer dealing with an inventory item. Unwearing - the current potion is intended to keep it in inventory.] */ - if (otmp->quan > 1L) { - otmp = splitobj(otmp, 1L); - otmp->owornmask = 0L; /* rest of original stuck unaffected */ - } else if (otmp->owornmask) { - remove_worn_item(otmp, FALSE); - } - otmp->in_use = TRUE; /* you've opened the stopper */ + /* quan > 1 used to be left to useup(), but we need to force + the current potion to be unworn, and don't want to do + that for the entire stack when starting with more than 1. + [Drinking a wielded potion of polymorph can trigger a shape + change which causes hero's weapon to be dropped. In 3.4.x, + that led to an "object lost" panic since subsequent useup() + was no longer dealing with an inventory item. Unwearing + the current potion is intended to keep it in inventory.] */ + if (otmp->quan > 1L) { + otmp = splitobj(otmp, 1L); + otmp->owornmask = 0L; /* rest of original stuck unaffected */ + } else if (otmp->owornmask) { + remove_worn_item(otmp, FALSE); + } + otmp->in_use = TRUE; /* you've opened the stopper */ - potion_descr = OBJ_DESCR(objects[otmp->otyp]); - if (potion_descr) { - if (!strcmp(potion_descr, "milky") && - !(mvitals[PM_GHOST].mvflags & G_GONE) && - !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { - ghost_from_bottle(); - useup(otmp); - return(1); - } else if (!strcmp(potion_descr, "smoky") && - !(mvitals[PM_DJINNI].mvflags & G_GONE) && - !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { - djinni_from_bottle(otmp); - useup(otmp); - return(1); - } - } - return dopotion(otmp); + potion_descr = OBJ_DESCR(objects[otmp->otyp]); + if (potion_descr) { + if (!strcmp(potion_descr, "milky") + && !(mvitals[PM_GHOST].mvflags & G_GONE) + && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { + ghost_from_bottle(); + useup(otmp); + return (1); + } else if (!strcmp(potion_descr, "smoky") + && !(mvitals[PM_DJINNI].mvflags & G_GONE) + && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { + djinni_from_bottle(otmp); + useup(otmp); + return (1); + } + } + return dopotion(otmp); } int dopotion(otmp) register struct obj *otmp; { - int retval; + int retval; - otmp->in_use = TRUE; - nothing = unkn = 0; - if((retval = peffects(otmp)) >= 0) return(retval); + otmp->in_use = TRUE; + nothing = unkn = 0; + if ((retval = peffects(otmp)) >= 0) + return (retval); - if(nothing) { - unkn++; - You("have a %s feeling for a moment, then it passes.", - Hallucination ? "normal" : "peculiar"); - } - if(otmp->dknown && !objects[otmp->otyp].oc_name_known) { - if(!unkn) { - makeknown(otmp->otyp); - more_experienced(0,10); - } else if(!objects[otmp->otyp].oc_uname) - docall(otmp); - } - useup(otmp); - return(1); + if (nothing) { + unkn++; + You("have a %s feeling for a moment, then it passes.", + Hallucination ? "normal" : "peculiar"); + } + if (otmp->dknown && !objects[otmp->otyp].oc_name_known) { + if (!unkn) { + makeknown(otmp->otyp); + more_experienced(0, 10); + } else if (!objects[otmp->otyp].oc_uname) + docall(otmp); + } + useup(otmp); + return (1); } int peffects(otmp) - register struct obj *otmp; +register struct obj *otmp; { - register int i, ii, lim; + register int i, ii, lim; - switch(otmp->otyp){ - case POT_RESTORE_ABILITY: - case SPE_RESTORE_ABILITY: - unkn++; - if(otmp->cursed) { - pline("Ulch! This makes you feel mediocre!"); - break; - } else { - /* unlike unicorn horn, overrides Fixed_abil */ - pline("Wow! This makes you feel %s!", - (otmp->blessed) ? - (unfixable_trouble_count(FALSE) ? "better" : "great") - : "good"); - i = rn2(A_MAX); /* start at a random point */ - for (ii = 0; ii < A_MAX; ii++) { - lim = AMAX(i); - if (i == A_STR && u.uhs >= 3) --lim; /* WEAK */ - if (ABASE(i) < lim) { - ABASE(i) = lim; - context.botl = 1; - /* only first found if not blessed */ - if (!otmp->blessed) break; - } - if(++i >= A_MAX) i = 0; - } - } - break; - case POT_HALLUCINATION: - if (Hallucination || Halluc_resistance) nothing++; - (void) make_hallucinated(itimeout_incr(HHallucination, - rn1(200, 600 - 300 * bcsign(otmp))), - TRUE, 0L); - break; - case POT_WATER: - if(!otmp->blessed && !otmp->cursed) { - pline("This tastes like water."); - u.uhunger += rnd(10); - newuhs(FALSE); - break; - } - unkn++; - if(is_undead(youmonst.data) || is_demon(youmonst.data) || - u.ualign.type == A_CHAOTIC) { - if(otmp->blessed) { - pline("This burns like acid!"); - exercise(A_CON, FALSE); - if (u.ulycn >= LOW_PM) { - Your("affinity to %s disappears!", - makeplural(mons[u.ulycn].mname)); - if (youmonst.data == &mons[u.ulycn]) - you_unwere(FALSE); - u.ulycn = NON_PM; /* cure lycanthropy */ - } - losehp(Maybe_Half_Phys(d(2,6)), - "potion of holy water", KILLED_BY_AN); - } else if(otmp->cursed) { - You_feel("quite proud of yourself."); - healup(d(2,6),0,0,0); - if (u.ulycn >= LOW_PM && !Upolyd) you_were(); - exercise(A_CON, TRUE); - } - } else { - if(otmp->blessed) { - You_feel("full of awe."); - make_sick(0L, (char *) 0, TRUE, SICK_ALL); - exercise(A_WIS, TRUE); - exercise(A_CON, TRUE); - if (u.ulycn >= LOW_PM) - you_unwere(TRUE); /* "Purified" */ - /* make_confused(0L,TRUE); */ - } else { - if(u.ualign.type == A_LAWFUL) { - pline("This burns like acid!"); - losehp(Maybe_Half_Phys(d(2,6)), - "potion of unholy water", - KILLED_BY_AN); - } else - You_feel("full of dread."); - if (u.ulycn >= LOW_PM && !Upolyd) you_were(); - exercise(A_CON, FALSE); - } - } - break; - case POT_BOOZE: - unkn++; - pline("Ooph! This tastes like %s%s!", - otmp->odiluted ? "watered down " : "", - Hallucination ? "dandelion wine" : "liquid fire"); - if (!otmp->blessed) - make_confused(itimeout_incr(HConfusion, d(3,8)), FALSE); - /* the whiskey makes us feel better */ - if (!otmp->odiluted) healup(1, 0, FALSE, FALSE); - u.uhunger += 10 * (2 + bcsign(otmp)); - newuhs(FALSE); - exercise(A_WIS, FALSE); - if(otmp->cursed) { - You("pass out."); - multi = -rnd(15); - nomovemsg = "You awake with a headache."; - } - break; - case POT_ENLIGHTENMENT: - if(otmp->cursed) { - unkn++; - You("have an uneasy feeling..."); - exercise(A_WIS, FALSE); - } else { - if (otmp->blessed) { - (void) adjattrib(A_INT, 1, FALSE); - (void) adjattrib(A_WIS, 1, FALSE); - } - You_feel("self-knowledgeable..."); - display_nhwindow(WIN_MESSAGE, FALSE); - enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); - pline_The("feeling subsides."); - exercise(A_WIS, TRUE); - } - break; - case SPE_INVISIBILITY: - /* spell cannot penetrate mummy wrapping */ - if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { - You_feel("rather itchy under %s.", yname(uarmc)); - break; - } - /* FALLTHRU */ - case POT_INVISIBILITY: - if (Invis || Blind || BInvis) { - nothing++; - } else { - self_invis_message(); - } - if (otmp->blessed) HInvis |= FROMOUTSIDE; - else incr_itimeout(&HInvis, rn1(15,31)); - newsym(u.ux,u.uy); /* update position */ - if(otmp->cursed) { - pline("For some reason, you feel your presence is known."); - aggravate(); - } - break; - case POT_SEE_INVISIBLE: - /* tastes like fruit juice in Rogue */ - case POT_FRUIT_JUICE: - { - int msg = Invisible && !Blind; + switch (otmp->otyp) { + case POT_RESTORE_ABILITY: + case SPE_RESTORE_ABILITY: + unkn++; + if (otmp->cursed) { + pline("Ulch! This makes you feel mediocre!"); + break; + } else { + /* unlike unicorn horn, overrides Fixed_abil */ + pline("Wow! This makes you feel %s!", + (otmp->blessed) + ? (unfixable_trouble_count(FALSE) ? "better" : "great") + : "good"); + i = rn2(A_MAX); /* start at a random point */ + for (ii = 0; ii < A_MAX; ii++) { + lim = AMAX(i); + if (i == A_STR && u.uhs >= 3) + --lim; /* WEAK */ + if (ABASE(i) < lim) { + ABASE(i) = lim; + context.botl = 1; + /* only first found if not blessed */ + if (!otmp->blessed) + break; + } + if (++i >= A_MAX) + i = 0; + } + } + break; + case POT_HALLUCINATION: + if (Hallucination || Halluc_resistance) + nothing++; + (void) make_hallucinated( + itimeout_incr(HHallucination, rn1(200, 600 - 300 * bcsign(otmp))), + TRUE, 0L); + break; + case POT_WATER: + if (!otmp->blessed && !otmp->cursed) { + pline("This tastes like water."); + u.uhunger += rnd(10); + newuhs(FALSE); + break; + } + unkn++; + if (is_undead(youmonst.data) || is_demon(youmonst.data) + || u.ualign.type == A_CHAOTIC) { + if (otmp->blessed) { + pline("This burns like acid!"); + exercise(A_CON, FALSE); + if (u.ulycn >= LOW_PM) { + Your("affinity to %s disappears!", + makeplural(mons[u.ulycn].mname)); + if (youmonst.data == &mons[u.ulycn]) + you_unwere(FALSE); + u.ulycn = NON_PM; /* cure lycanthropy */ + } + losehp(Maybe_Half_Phys(d(2, 6)), "potion of holy water", + KILLED_BY_AN); + } else if (otmp->cursed) { + You_feel("quite proud of yourself."); + healup(d(2, 6), 0, 0, 0); + if (u.ulycn >= LOW_PM && !Upolyd) + you_were(); + exercise(A_CON, TRUE); + } + } else { + if (otmp->blessed) { + You_feel("full of awe."); + make_sick(0L, (char *) 0, TRUE, SICK_ALL); + exercise(A_WIS, TRUE); + exercise(A_CON, TRUE); + if (u.ulycn >= LOW_PM) + you_unwere(TRUE); /* "Purified" */ + /* make_confused(0L,TRUE); */ + } else { + if (u.ualign.type == A_LAWFUL) { + pline("This burns like acid!"); + losehp(Maybe_Half_Phys(d(2, 6)), "potion of unholy water", + KILLED_BY_AN); + } else + You_feel("full of dread."); + if (u.ulycn >= LOW_PM && !Upolyd) + you_were(); + exercise(A_CON, FALSE); + } + } + break; + case POT_BOOZE: + unkn++; + pline("Ooph! This tastes like %s%s!", + otmp->odiluted ? "watered down " : "", + Hallucination ? "dandelion wine" : "liquid fire"); + if (!otmp->blessed) + make_confused(itimeout_incr(HConfusion, d(3, 8)), FALSE); + /* the whiskey makes us feel better */ + if (!otmp->odiluted) + healup(1, 0, FALSE, FALSE); + u.uhunger += 10 * (2 + bcsign(otmp)); + newuhs(FALSE); + exercise(A_WIS, FALSE); + if (otmp->cursed) { + You("pass out."); + multi = -rnd(15); + nomovemsg = "You awake with a headache."; + } + break; + case POT_ENLIGHTENMENT: + if (otmp->cursed) { + unkn++; + You("have an uneasy feeling..."); + exercise(A_WIS, FALSE); + } else { + if (otmp->blessed) { + (void) adjattrib(A_INT, 1, FALSE); + (void) adjattrib(A_WIS, 1, FALSE); + } + You_feel("self-knowledgeable..."); + display_nhwindow(WIN_MESSAGE, FALSE); + enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); + pline_The("feeling subsides."); + exercise(A_WIS, TRUE); + } + break; + case SPE_INVISIBILITY: + /* spell cannot penetrate mummy wrapping */ + if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { + You_feel("rather itchy under %s.", yname(uarmc)); + break; + } + /* FALLTHRU */ + case POT_INVISIBILITY: + if (Invis || Blind || BInvis) { + nothing++; + } else { + self_invis_message(); + } + if (otmp->blessed) + HInvis |= FROMOUTSIDE; + else + incr_itimeout(&HInvis, rn1(15, 31)); + newsym(u.ux, u.uy); /* update position */ + if (otmp->cursed) { + pline("For some reason, you feel your presence is known."); + aggravate(); + } + break; + case POT_SEE_INVISIBLE: + /* tastes like fruit juice in Rogue */ + case POT_FRUIT_JUICE: { + int msg = Invisible && !Blind; - unkn++; - if (otmp->cursed) - pline("Yecch! This tastes %s.", - Hallucination ? "overripe" : "rotten"); - else - pline(Hallucination ? - "This tastes like 10%% real %s%s all-natural beverage." : - "This tastes like %s%s.", - otmp->odiluted ? "reconstituted " : "", - fruitname(TRUE)); - if (otmp->otyp == POT_FRUIT_JUICE) { - u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp)); - newuhs(FALSE); - break; - } - if (!otmp->cursed) { - /* Tell them they can see again immediately, which - * will help them identify the potion... - */ - make_blinded(0L,TRUE); - } - if (otmp->blessed) - HSee_invisible |= FROMOUTSIDE; - else - incr_itimeout(&HSee_invisible, rn1(100,750)); - set_mimic_blocking(); /* do special mimic handling */ - see_monsters(); /* see invisible monsters */ - newsym(u.ux,u.uy); /* see yourself! */ - if (msg && !Blind) { /* Blind possible if polymorphed */ - You("can see through yourself, but you are visible!"); - unkn--; - } - break; - } - case POT_PARALYSIS: - if (Free_action) - You("stiffen momentarily."); - else { - if (Levitation || Is_airlevel(&u.uz)||Is_waterlevel(&u.uz)) - You("are motionlessly suspended."); - else if (u.usteed) - You("are frozen in place!"); - else - Your("%s are frozen to the %s!", - makeplural(body_part(FOOT)), surface(u.ux, u.uy)); - nomul(-(rn1(10, 25 - 12*bcsign(otmp)))); - multi_reason = "frozen by a potion"; - nomovemsg = You_can_move_again; - exercise(A_DEX, FALSE); - } - break; - case POT_SLEEPING: - if(Sleep_resistance || Free_action) - You("yawn."); - else { - You("suddenly fall asleep!"); - fall_asleep(-rn1(10, 25 - 12*bcsign(otmp)), TRUE); - } - break; - case POT_MONSTER_DETECTION: - case SPE_DETECT_MONSTERS: - if (otmp->blessed) { - int x, y; + unkn++; + if (otmp->cursed) + pline("Yecch! This tastes %s.", + Hallucination ? "overripe" : "rotten"); + else + pline( + Hallucination + ? "This tastes like 10%% real %s%s all-natural beverage." + : "This tastes like %s%s.", + otmp->odiluted ? "reconstituted " : "", fruitname(TRUE)); + if (otmp->otyp == POT_FRUIT_JUICE) { + u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp)); + newuhs(FALSE); + break; + } + if (!otmp->cursed) { + /* Tell them they can see again immediately, which + * will help them identify the potion... + */ + make_blinded(0L, TRUE); + } + if (otmp->blessed) + HSee_invisible |= FROMOUTSIDE; + else + incr_itimeout(&HSee_invisible, rn1(100, 750)); + set_mimic_blocking(); /* do special mimic handling */ + see_monsters(); /* see invisible monsters */ + newsym(u.ux, u.uy); /* see yourself! */ + if (msg && !Blind) { /* Blind possible if polymorphed */ + You("can see through yourself, but you are visible!"); + unkn--; + } + break; + } + case POT_PARALYSIS: + if (Free_action) + You("stiffen momentarily."); + else { + if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) + You("are motionlessly suspended."); + else if (u.usteed) + You("are frozen in place!"); + else + Your("%s are frozen to the %s!", makeplural(body_part(FOOT)), + surface(u.ux, u.uy)); + nomul(-(rn1(10, 25 - 12 * bcsign(otmp)))); + multi_reason = "frozen by a potion"; + nomovemsg = You_can_move_again; + exercise(A_DEX, FALSE); + } + break; + case POT_SLEEPING: + if (Sleep_resistance || Free_action) + You("yawn."); + else { + You("suddenly fall asleep!"); + fall_asleep(-rn1(10, 25 - 12 * bcsign(otmp)), TRUE); + } + break; + case POT_MONSTER_DETECTION: + case SPE_DETECT_MONSTERS: + if (otmp->blessed) { + int x, y; - if (Detect_monsters) nothing++; - unkn++; - /* after a while, repeated uses become less effective */ - if ((HDetect_monsters & TIMEOUT) >= 300L) - i = 1; - else - i = rn1(40,21); - incr_itimeout(&HDetect_monsters, i); - for (x = 1; x < COLNO; x++) { - for (y = 0; y < ROWNO; y++) { - if (levl[x][y].glyph == GLYPH_INVISIBLE) { - unmap_object(x, y); - newsym(x,y); - } - if (MON_AT(x,y)) unkn = 0; - } - } - see_monsters(); - if (unkn) You_feel("lonely."); - break; - } - if (monster_detect(otmp, 0)) - return(1); /* nothing detected */ - exercise(A_WIS, TRUE); - break; - case POT_OBJECT_DETECTION: - case SPE_DETECT_TREASURE: - if (object_detect(otmp, 0)) - return(1); /* nothing detected */ - exercise(A_WIS, TRUE); - break; - case POT_SICKNESS: - pline("Yecch! This stuff tastes like poison."); - if (otmp->blessed) { - pline("(But in fact it was mildly stale %s.)", - fruitname(TRUE)); - if (!Role_if(PM_HEALER)) { - /* NB: blessed otmp->fromsink is not possible */ - losehp(1, "mildly contaminated potion", KILLED_BY_AN); - } - } else { - if(Poison_resistance) - pline( - "(But in fact it was biologically contaminated %s.)", - fruitname(TRUE)); - if (Role_if(PM_HEALER)) - pline("Fortunately, you have been immunized."); - else { - char contaminant[BUFSZ]; - int typ = rn2(A_MAX); + if (Detect_monsters) + nothing++; + unkn++; + /* after a while, repeated uses become less effective */ + if ((HDetect_monsters & TIMEOUT) >= 300L) + i = 1; + else + i = rn1(40, 21); + incr_itimeout(&HDetect_monsters, i); + for (x = 1; x < COLNO; x++) { + for (y = 0; y < ROWNO; y++) { + if (levl[x][y].glyph == GLYPH_INVISIBLE) { + unmap_object(x, y); + newsym(x, y); + } + if (MON_AT(x, y)) + unkn = 0; + } + } + see_monsters(); + if (unkn) + You_feel("lonely."); + break; + } + if (monster_detect(otmp, 0)) + return (1); /* nothing detected */ + exercise(A_WIS, TRUE); + break; + case POT_OBJECT_DETECTION: + case SPE_DETECT_TREASURE: + if (object_detect(otmp, 0)) + return (1); /* nothing detected */ + exercise(A_WIS, TRUE); + break; + case POT_SICKNESS: + pline("Yecch! This stuff tastes like poison."); + if (otmp->blessed) { + pline("(But in fact it was mildly stale %s.)", fruitname(TRUE)); + if (!Role_if(PM_HEALER)) { + /* NB: blessed otmp->fromsink is not possible */ + losehp(1, "mildly contaminated potion", KILLED_BY_AN); + } + } else { + if (Poison_resistance) + pline("(But in fact it was biologically contaminated %s.)", + fruitname(TRUE)); + if (Role_if(PM_HEALER)) + pline("Fortunately, you have been immunized."); + else { + char contaminant[BUFSZ]; + int typ = rn2(A_MAX); - Sprintf(contaminant, "%s%s", - (Poison_resistance) ? "mildly " : "", - (otmp->fromsink) ? "contaminated tap water" : - "contaminated potion"); - if (!Fixed_abil) { - poisontell(typ, FALSE); - (void) adjattrib(typ, - Poison_resistance ? -1 : -rn1(4,3), - 1); - } - if(!Poison_resistance) { - if (otmp->fromsink) - losehp(rnd(10)+5*!!(otmp->cursed), - contaminant, KILLED_BY); - else - losehp(rnd(10)+5*!!(otmp->cursed), - contaminant, KILLED_BY_AN); - } else { - /* rnd loss is so that unblessed poorer than blessed */ - losehp(1 + rn2(2), contaminant, - (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN); - } - exercise(A_CON, FALSE); - } - } - if(Hallucination) { - You("are shocked back to your senses!"); - (void) make_hallucinated(0L,FALSE,0L); - } - break; - case POT_CONFUSION: - if(!Confusion) - if (Hallucination) { - pline("What a trippy feeling!"); - unkn++; - } else - pline("Huh, What? Where am I?"); - else nothing++; - make_confused(itimeout_incr(HConfusion, - rn1(7, 16 - 8 * bcsign(otmp))), - FALSE); - break; - case POT_GAIN_ABILITY: - if(otmp->cursed) { - pline("Ulch! That potion tasted foul!"); - unkn++; - } else if (Fixed_abil) { - nothing++; - } else { /* If blessed, increase all; if not, try up to */ - int itmp; /* 6 times to find one which can be increased. */ - i = -1; /* increment to 0 */ - for (ii = A_MAX; ii > 0; ii--) { - i = (otmp->blessed ? i + 1 : rn2(A_MAX)); - /* only give "your X is already as high as it can get" - message on last attempt (except blessed potions) */ - itmp = (otmp->blessed || ii == 1) ? 0 : -1; - if (adjattrib(i, 1, itmp) && !otmp->blessed) - break; - } - } - break; - case POT_SPEED: - if(Wounded_legs && !otmp->cursed && !u.usteed) { - /* heal_legs() would heal steeds legs */ - heal_legs(); - unkn++; - break; - } /* and fall through */ - case SPE_HASTE_SELF: - if(!Very_fast) /* wwf@doe.carleton.ca */ - You("are suddenly moving %sfaster.", - Fast ? "" : "much "); - else { - Your("%s get new energy.", - makeplural(body_part(LEG))); - unkn++; - } - exercise(A_DEX, TRUE); - incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp))); - break; - case POT_BLINDNESS: - if(Blind) nothing++; - make_blinded(itimeout_incr(Blinded, - rn1(200, 250 - 125 * bcsign(otmp))), - (boolean)!Blind); - break; - case POT_GAIN_LEVEL: - if (otmp->cursed) { - unkn++; - /* they went up a level */ - if((ledger_no(&u.uz) == 1 && u.uhave.amulet) || - Can_rise_up(u.ux, u.uy, &u.uz)) { - const char *riseup ="rise up, through the %s!"; - if(ledger_no(&u.uz) == 1) { - You(riseup, ceiling(u.ux,u.uy)); - goto_level(&earth_level, FALSE, FALSE, FALSE); - } else { - register int newlev = depth(&u.uz)-1; - d_level newlevel; + Sprintf(contaminant, "%s%s", + (Poison_resistance) ? "mildly " : "", + (otmp->fromsink) ? "contaminated tap water" + : "contaminated potion"); + if (!Fixed_abil) { + poisontell(typ, FALSE); + (void) adjattrib(typ, Poison_resistance ? -1 : -rn1(4, 3), + 1); + } + if (!Poison_resistance) { + if (otmp->fromsink) + losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant, + KILLED_BY); + else + losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant, + KILLED_BY_AN); + } else { + /* rnd loss is so that unblessed poorer than blessed */ + losehp(1 + rn2(2), contaminant, + (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN); + } + exercise(A_CON, FALSE); + } + } + if (Hallucination) { + You("are shocked back to your senses!"); + (void) make_hallucinated(0L, FALSE, 0L); + } + break; + case POT_CONFUSION: + if (!Confusion) + if (Hallucination) { + pline("What a trippy feeling!"); + unkn++; + } else + pline("Huh, What? Where am I?"); + else + nothing++; + make_confused( + itimeout_incr(HConfusion, rn1(7, 16 - 8 * bcsign(otmp))), FALSE); + break; + case POT_GAIN_ABILITY: + if (otmp->cursed) { + pline("Ulch! That potion tasted foul!"); + unkn++; + } else if (Fixed_abil) { + nothing++; + } else { /* If blessed, increase all; if not, try up to */ + int itmp; /* 6 times to find one which can be increased. */ + i = -1; /* increment to 0 */ + for (ii = A_MAX; ii > 0; ii--) { + i = (otmp->blessed ? i + 1 : rn2(A_MAX)); + /* only give "your X is already as high as it can get" + message on last attempt (except blessed potions) */ + itmp = (otmp->blessed || ii == 1) ? 0 : -1; + if (adjattrib(i, 1, itmp) && !otmp->blessed) + break; + } + } + break; + case POT_SPEED: + if (Wounded_legs && !otmp->cursed && !u.usteed) { + /* heal_legs() would heal steeds legs */ + heal_legs(); + unkn++; + break; + } /* and fall through */ + case SPE_HASTE_SELF: + if (!Very_fast) /* wwf@doe.carleton.ca */ + You("are suddenly moving %sfaster.", Fast ? "" : "much "); + else { + Your("%s get new energy.", makeplural(body_part(LEG))); + unkn++; + } + exercise(A_DEX, TRUE); + incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp))); + break; + case POT_BLINDNESS: + if (Blind) + nothing++; + make_blinded( + itimeout_incr(Blinded, rn1(200, 250 - 125 * bcsign(otmp))), + (boolean) !Blind); + break; + case POT_GAIN_LEVEL: + if (otmp->cursed) { + unkn++; + /* they went up a level */ + if ((ledger_no(&u.uz) == 1 && u.uhave.amulet) + || Can_rise_up(u.ux, u.uy, &u.uz)) { + const char *riseup = "rise up, through the %s!"; + if (ledger_no(&u.uz) == 1) { + You(riseup, ceiling(u.ux, u.uy)); + goto_level(&earth_level, FALSE, FALSE, FALSE); + } else { + register int newlev = depth(&u.uz) - 1; + d_level newlevel; - get_level(&newlevel, newlev); - if(on_level(&newlevel, &u.uz)) { - pline("It tasted bad."); - break; - } else You(riseup, ceiling(u.ux,u.uy)); - goto_level(&newlevel, FALSE, FALSE, FALSE); - } - } - else You("have an uneasy feeling."); - break; - } - pluslvl(FALSE); - if (otmp->blessed) - /* blessed potions place you at a random spot in the - * middle of the new level instead of the low point - */ - u.uexp = rndexp(TRUE); - break; - case POT_HEALING: - You_feel("better."); - healup(d(6 + 2 * bcsign(otmp), 4), - !otmp->cursed ? 1 : 0, !!otmp->blessed, !otmp->cursed); - exercise(A_CON, TRUE); - break; - case POT_EXTRA_HEALING: - You_feel("much better."); - healup(d(6 + 2 * bcsign(otmp), 8), - otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, - !otmp->cursed, TRUE); - (void) make_hallucinated(0L,TRUE,0L); - exercise(A_CON, TRUE); - exercise(A_STR, TRUE); - break; - case POT_FULL_HEALING: - You_feel("completely healed."); - healup(400, 4+4*bcsign(otmp), !otmp->cursed, TRUE); - /* Restore one lost level if blessed */ - if (otmp->blessed && u.ulevel < u.ulevelmax) { - /* when multiple levels have been lost, drinking - multiple potions will only get half of them back */ - u.ulevelmax -= 1; - pluslvl(FALSE); - } - (void) make_hallucinated(0L,TRUE,0L); - exercise(A_STR, TRUE); - exercise(A_CON, TRUE); - break; - case POT_LEVITATION: - case SPE_LEVITATION: - if (otmp->cursed) HLevitation &= ~I_SPECIAL; - if (!Levitation && !BLevitation) { - /* kludge to ensure proper operation of float_up() */ - set_itimeout(&HLevitation, 1L); - float_up(); - /* reverse kludge */ - set_itimeout(&HLevitation, 0L); - if (otmp->cursed) { - if ((u.ux == xupstair && u.uy == yupstair) || - (sstairs.up && u.ux == sstairs.sx && - u.uy == sstairs.sy) || - (xupladder && u.ux == xupladder && - u.uy == yupladder)) { - (void) doup(); - } else if (has_ceiling(&u.uz)) { - int dmg = uarmh ? 1 : rnd(10); + get_level(&newlevel, newlev); + if (on_level(&newlevel, &u.uz)) { + pline("It tasted bad."); + break; + } else + You(riseup, ceiling(u.ux, u.uy)); + goto_level(&newlevel, FALSE, FALSE, FALSE); + } + } else + You("have an uneasy feeling."); + break; + } + pluslvl(FALSE); + if (otmp->blessed) + /* blessed potions place you at a random spot in the + * middle of the new level instead of the low point + */ + u.uexp = rndexp(TRUE); + break; + case POT_HEALING: + You_feel("better."); + healup(d(6 + 2 * bcsign(otmp), 4), !otmp->cursed ? 1 : 0, + !!otmp->blessed, !otmp->cursed); + exercise(A_CON, TRUE); + break; + case POT_EXTRA_HEALING: + You_feel("much better."); + healup(d(6 + 2 * bcsign(otmp), 8), + otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, !otmp->cursed, + TRUE); + (void) make_hallucinated(0L, TRUE, 0L); + exercise(A_CON, TRUE); + exercise(A_STR, TRUE); + break; + case POT_FULL_HEALING: + You_feel("completely healed."); + healup(400, 4 + 4 * bcsign(otmp), !otmp->cursed, TRUE); + /* Restore one lost level if blessed */ + if (otmp->blessed && u.ulevel < u.ulevelmax) { + /* when multiple levels have been lost, drinking + multiple potions will only get half of them back */ + u.ulevelmax -= 1; + pluslvl(FALSE); + } + (void) make_hallucinated(0L, TRUE, 0L); + exercise(A_STR, TRUE); + exercise(A_CON, TRUE); + break; + case POT_LEVITATION: + case SPE_LEVITATION: + if (otmp->cursed) + HLevitation &= ~I_SPECIAL; + if (!Levitation && !BLevitation) { + /* kludge to ensure proper operation of float_up() */ + set_itimeout(&HLevitation, 1L); + float_up(); + /* reverse kludge */ + set_itimeout(&HLevitation, 0L); + if (otmp->cursed) { + if ((u.ux == xupstair && u.uy == yupstair) + || (sstairs.up && u.ux == sstairs.sx + && u.uy == sstairs.sy) + || (xupladder && u.ux == xupladder + && u.uy == yupladder)) { + (void) doup(); + } else if (has_ceiling(&u.uz)) { + int dmg = uarmh ? 1 : rnd(10); - You("hit your %s on the %s.", - body_part(HEAD), ceiling(u.ux,u.uy)); - losehp(Maybe_Half_Phys(dmg), - "colliding with the ceiling", KILLED_BY); - } - } /*cursed*/ - } else - nothing++; - if (otmp->blessed) { - incr_itimeout(&HLevitation, rn1(50,250)); - HLevitation |= I_SPECIAL; - } else - incr_itimeout(&HLevitation, rn1(140,10)); - if (Levitation) spoteffects(FALSE); /* for sinks */ - float_vs_flight(); - break; - case POT_GAIN_ENERGY: /* M. Stephenson */ - { register int num; - if(otmp->cursed) - You_feel("lackluster."); - else - pline("Magical energies course through your body."); - num = rnd(5) + 5 * otmp->blessed + 1; - u.uenmax += (otmp->cursed) ? -num : num; - u.uen += (otmp->cursed) ? -num : num; - if(u.uenmax <= 0) u.uenmax = 0; - if(u.uen <= 0) u.uen = 0; - context.botl = 1; - exercise(A_WIS, TRUE); - } - break; - case POT_OIL: /* P. Winner */ - { - boolean good_for_you = FALSE; + You("hit your %s on the %s.", body_part(HEAD), + ceiling(u.ux, u.uy)); + losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling", + KILLED_BY); + } + } /*cursed*/ + } else + nothing++; + if (otmp->blessed) { + incr_itimeout(&HLevitation, rn1(50, 250)); + HLevitation |= I_SPECIAL; + } else + incr_itimeout(&HLevitation, rn1(140, 10)); + if (Levitation) + spoteffects(FALSE); /* for sinks */ + float_vs_flight(); + break; + case POT_GAIN_ENERGY: /* M. Stephenson */ + { + register int num; + if (otmp->cursed) + You_feel("lackluster."); + else + pline("Magical energies course through your body."); + num = rnd(5) + 5 * otmp->blessed + 1; + u.uenmax += (otmp->cursed) ? -num : num; + u.uen += (otmp->cursed) ? -num : num; + if (u.uenmax <= 0) + u.uenmax = 0; + if (u.uen <= 0) + u.uen = 0; + context.botl = 1; + exercise(A_WIS, TRUE); + } break; + case POT_OIL: /* P. Winner */ + { + boolean good_for_you = FALSE; - if (otmp->lamplit) { - if (likes_fire(youmonst.data)) { - pline("Ahh, a refreshing drink."); - good_for_you = TRUE; - } else { - You("burn your %s.", body_part(FACE)); - /* fire damage */ - losehp(d(Fire_resistance ? 1 : 3, 4), - "burning potion of oil", KILLED_BY_AN); - } - } else if(otmp->cursed) - pline("This tastes like castor oil."); - else - pline("That was smooth!"); - exercise(A_WIS, good_for_you); - } - break; - case POT_ACID: - if (Acid_resistance) - /* Not necessarily a creature who _likes_ acid */ - pline("This tastes %s.", Hallucination ? "tangy" : "sour"); - else { - int dmg; - pline("This burns%s!", otmp->blessed ? " a little" : - otmp->cursed ? " a lot" : " like acid"); - dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8); - losehp(Maybe_Half_Phys(dmg), - "potion of acid", KILLED_BY_AN); - exercise(A_CON, FALSE); - } - if (Stoned) fix_petrification(); - unkn++; /* holy/unholy water can burn like acid too */ - break; - case POT_POLYMORPH: - You_feel("a little %s.", Hallucination ? "normal" : "strange"); - if (!Unchanging) polyself(0); - break; - default: - impossible("What a funny potion! (%u)", otmp->otyp); - return(0); - } - return(-1); + if (otmp->lamplit) { + if (likes_fire(youmonst.data)) { + pline("Ahh, a refreshing drink."); + good_for_you = TRUE; + } else { + You("burn your %s.", body_part(FACE)); + /* fire damage */ + losehp(d(Fire_resistance ? 1 : 3, 4), "burning potion of oil", + KILLED_BY_AN); + } + } else if (otmp->cursed) + pline("This tastes like castor oil."); + else + pline("That was smooth!"); + exercise(A_WIS, good_for_you); + } break; + case POT_ACID: + if (Acid_resistance) + /* Not necessarily a creature who _likes_ acid */ + pline("This tastes %s.", Hallucination ? "tangy" : "sour"); + else { + int dmg; + pline("This burns%s!", + otmp->blessed ? " a little" : otmp->cursed ? " a lot" + : " like acid"); + dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8); + losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN); + exercise(A_CON, FALSE); + } + if (Stoned) + fix_petrification(); + unkn++; /* holy/unholy water can burn like acid too */ + break; + case POT_POLYMORPH: + You_feel("a little %s.", Hallucination ? "normal" : "strange"); + if (!Unchanging) + polyself(0); + break; + default: + impossible("What a funny potion! (%u)", otmp->otyp); + return (0); + } + return (-1); } void healup(nhp, nxtra, curesick, cureblind) - int nhp, nxtra; - register boolean curesick, cureblind; +int nhp, nxtra; +register boolean curesick, cureblind; { - if (nhp) { - if (Upolyd) { - u.mh += nhp; - if (u.mh > u.mhmax) u.mh = (u.mhmax += nxtra); - } else { - u.uhp += nhp; - if(u.uhp > u.uhpmax) u.uhp = (u.uhpmax += nxtra); - } - } - if (cureblind) make_blinded(0L, TRUE); - if (curesick) { - make_vomiting(0L, TRUE); - make_sick(0L, (char *)0, TRUE, SICK_ALL); - } - context.botl = 1; - return; + if (nhp) { + if (Upolyd) { + u.mh += nhp; + if (u.mh > u.mhmax) + u.mh = (u.mhmax += nxtra); + } else { + u.uhp += nhp; + if (u.uhp > u.uhpmax) + u.uhp = (u.uhpmax += nxtra); + } + } + if (cureblind) + make_blinded(0L, TRUE); + if (curesick) { + make_vomiting(0L, TRUE); + make_sick(0L, (char *) 0, TRUE, SICK_ALL); + } + context.botl = 1; + return; } void -strange_feeling(obj,txt) +strange_feeling(obj, txt) register struct obj *obj; register const char *txt; { - if (flags.beginner || !txt) - You("have a %s feeling for a moment, then it passes.", - Hallucination ? "normal" : "strange"); - else - pline1(txt); + if (flags.beginner || !txt) + You("have a %s feeling for a moment, then it passes.", + Hallucination ? "normal" : "strange"); + else + pline1(txt); - if(!obj) /* e.g., crystal ball finds no traps */ - return; + if (!obj) /* e.g., crystal ball finds no traps */ + return; - if(obj->dknown && !objects[obj->otyp].oc_name_known && - !objects[obj->otyp].oc_uname) - docall(obj); - useup(obj); + if (obj->dknown && !objects[obj->otyp].oc_name_known + && !objects[obj->otyp].oc_uname) + docall(obj); + useup(obj); } -const char *bottlenames[] = { - "bottle", "phial", "flagon", "carafe", "flask", "jar", "vial" -}; - +const char *bottlenames[] = { "bottle", "phial", "flagon", "carafe", + "flask", "jar", "vial" }; const char * bottlename() { - return bottlenames[rn2(SIZE(bottlenames))]; + return bottlenames[rn2(SIZE(bottlenames))]; } /* handle item dipped into water potion or steed saddle splashed by same */ @@ -1052,75 +1093,76 @@ STATIC_OVL boolean H2Opotion_dip(potion, targobj, useeit, objphrase) struct obj *potion, *targobj; boolean useeit; -const char *objphrase; /* "Your widget glows" or "Steed's saddle glows" */ +const char *objphrase; /* "Your widget glows" or "Steed's saddle glows" */ { void FDECL((*func), (OBJ_P)) = 0; const char *glowcolor = 0; #define COST_alter (-2) -#define COST_none (-1) +#define COST_none (-1) int costchange = COST_none; boolean altfmt = FALSE, res = FALSE; - if (!potion || potion->otyp != POT_WATER) return FALSE; + if (!potion || potion->otyp != POT_WATER) + return FALSE; if (potion->blessed) { - if (targobj->cursed) { - func = uncurse; - glowcolor = NH_AMBER; - costchange = COST_UNCURS; - } else if (!targobj->blessed) { - func = bless; - glowcolor = NH_LIGHT_BLUE; - costchange = COST_alter; - altfmt = TRUE; /* "with a aura" */ - } + if (targobj->cursed) { + func = uncurse; + glowcolor = NH_AMBER; + costchange = COST_UNCURS; + } else if (!targobj->blessed) { + func = bless; + glowcolor = NH_LIGHT_BLUE; + costchange = COST_alter; + altfmt = TRUE; /* "with a aura" */ + } } else if (potion->cursed) { - if (targobj->blessed) { - func = unbless; - glowcolor = "brown"; - costchange = COST_UNBLSS; - } else if (!targobj->cursed) { - func = curse; - glowcolor = NH_BLACK; - costchange = COST_alter; - altfmt = TRUE; - } + if (targobj->blessed) { + func = unbless; + glowcolor = "brown"; + costchange = COST_UNBLSS; + } else if (!targobj->cursed) { + func = curse; + glowcolor = NH_BLACK; + costchange = COST_alter; + altfmt = TRUE; + } } else { - /* dipping into uncursed water; carried() check skips steed saddle */ - if (carried(targobj)) { - if (water_damage(targobj, 0, TRUE) != ER_NOTHING) - res = TRUE; - } + /* dipping into uncursed water; carried() check skips steed saddle */ + if (carried(targobj)) { + if (water_damage(targobj, 0, TRUE) != ER_NOTHING) + res = TRUE; + } } if (func) { - /* give feedback before altering the target object; - this used to set obj->bknown even when not seeing - the effect; now hero has to see the glow, and bknown - is cleared instead of set if perception is distorted */ - if (useeit) { - glowcolor = hcolor(glowcolor); - if (altfmt) - pline("%s with %s aura.", objphrase, an(glowcolor)); - else - pline("%s %s.", objphrase, glowcolor); - iflags.last_msg = PLNMSG_OBJ_GLOWS; - targobj->bknown = !Hallucination; - } - /* potions of water are the only shop goods whose price depends - on their curse/bless state */ - if (targobj->unpaid && targobj->otyp == POT_WATER) { - if (costchange == COST_alter) - /* added blessing or cursing; update shop - bill to reflect item's new higher price */ - alter_cost(targobj, 0L); - else if (costchange != COST_none) - /* removed blessing or cursing; you - degraded it, now you'll have to buy it... */ - costly_alteration(targobj, costchange); - } - /* finally, change curse/bless state */ - (*func)(targobj); - res = TRUE; + /* give feedback before altering the target object; + this used to set obj->bknown even when not seeing + the effect; now hero has to see the glow, and bknown + is cleared instead of set if perception is distorted */ + if (useeit) { + glowcolor = hcolor(glowcolor); + if (altfmt) + pline("%s with %s aura.", objphrase, an(glowcolor)); + else + pline("%s %s.", objphrase, glowcolor); + iflags.last_msg = PLNMSG_OBJ_GLOWS; + targobj->bknown = !Hallucination; + } + /* potions of water are the only shop goods whose price depends + on their curse/bless state */ + if (targobj->unpaid && targobj->otyp == POT_WATER) { + if (costchange == COST_alter) + /* added blessing or cursing; update shop + bill to reflect item's new higher price */ + alter_cost(targobj, 0L); + else if (costchange != COST_none) + /* removed blessing or cursing; you + degraded it, now you'll have to buy it... */ + costly_alteration(targobj, costchange); + } + /* finally, change curse/bless state */ + (*func)(targobj); + res = TRUE; } return res; } @@ -1131,260 +1173,268 @@ register struct monst *mon; register struct obj *obj; boolean your_fault; { - register const char *botlnam = bottlename(); - boolean isyou = (mon == &youmonst); - int distance; - struct obj *saddle = (struct obj *)0; - boolean hit_saddle = FALSE; - - if(isyou) { - distance = 0; - pline_The("%s crashes on your %s and breaks into shards.", - botlnam, body_part(HEAD)); - losehp(Maybe_Half_Phys(rnd(2)), "thrown potion", KILLED_BY_AN); - } else { - /* sometimes it hits the saddle */ - if(((mon->misc_worn_check & W_SADDLE) && - (saddle = which_armor(mon, W_SADDLE))) && - (!rn2(10) || - (obj->otyp == POT_WATER && - ((rnl(10) > 7 && obj->cursed) || - (rnl(10) < 4 && obj->blessed) || !rn2(3))))) - hit_saddle = TRUE; - distance = distu(mon->mx,mon->my); - if (!cansee(mon->mx,mon->my)) pline("Crash!"); - else { - char *mnam = mon_nam(mon); - char buf[BUFSZ]; - - if(hit_saddle && saddle) { - Sprintf(buf, "%s saddle", s_suffix(x_monnam(mon, - ARTICLE_THE, (char *)0, - (SUPPRESS_IT|SUPPRESS_SADDLE), FALSE))); - } else if(has_head(mon->data)) { - Sprintf(buf, "%s %s", - s_suffix(mnam), - (notonhead ? "body" : "head")); - } else { - Strcpy(buf, mnam); - } - pline_The("%s crashes on %s and breaks into shards.", - botlnam, buf); - } - if(rn2(5) && mon->mhp > 1 && !hit_saddle) - mon->mhp--; - } - - /* oil doesn't instantly evaporate; Neither does a saddle hit */ - if (obj->otyp != POT_OIL && !hit_saddle && cansee(mon->mx,mon->my)) - pline("%s.", Tobjnam(obj, "evaporate")); + register const char *botlnam = bottlename(); + boolean isyou = (mon == &youmonst); + int distance; + struct obj *saddle = (struct obj *) 0; + boolean hit_saddle = FALSE; if (isyou) { - switch (obj->otyp) { - case POT_OIL: - if (obj->lamplit) - explode_oil(obj, u.ux, u.uy); - break; - case POT_POLYMORPH: - You_feel("a little %s.", Hallucination ? "normal" : "strange"); - if (!Unchanging && !Antimagic) polyself(0); - break; - case POT_ACID: - if (!Acid_resistance) { - int dmg; - pline("This burns%s!", obj->blessed ? " a little" : - obj->cursed ? " a lot" : ""); - dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); - losehp(Maybe_Half_Phys(dmg), - "potion of acid", KILLED_BY_AN); - } - break; - } - } else if (hit_saddle && saddle) { - char *mnam, buf[BUFSZ], saddle_glows[BUFSZ]; - boolean affected = FALSE; - boolean useeit = !Blind && canseemon(mon) && cansee(mon->mx,mon->my); - - mnam = x_monnam(mon, ARTICLE_THE, (char *)0, - (SUPPRESS_IT|SUPPRESS_SADDLE), FALSE); - Sprintf(buf, "%s", upstart(s_suffix(mnam))); - - switch (obj->otyp) { - case POT_WATER: - Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow")); - affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows); - break; - case POT_POLYMORPH: - /* Do we allow the saddle to polymorph? */ - break; - } - if (useeit && !affected) - pline("%s %s wet.", buf, aobjnam(saddle, "get")); + distance = 0; + pline_The("%s crashes on your %s and breaks into shards.", botlnam, + body_part(HEAD)); + losehp(Maybe_Half_Phys(rnd(2)), "thrown potion", KILLED_BY_AN); } else { - boolean angermon = TRUE; + /* sometimes it hits the saddle */ + if (((mon->misc_worn_check & W_SADDLE) + && (saddle = which_armor(mon, W_SADDLE))) + && (!rn2(10) + || (obj->otyp == POT_WATER + && ((rnl(10) > 7 && obj->cursed) + || (rnl(10) < 4 && obj->blessed) || !rn2(3))))) + hit_saddle = TRUE; + distance = distu(mon->mx, mon->my); + if (!cansee(mon->mx, mon->my)) + pline("Crash!"); + else { + char *mnam = mon_nam(mon); + char buf[BUFSZ]; - if (!your_fault) angermon = FALSE; - switch (obj->otyp) { - case POT_HEALING: - case POT_EXTRA_HEALING: - case POT_FULL_HEALING: - if (mon->data == &mons[PM_PESTILENCE]) goto do_illness; - /*FALLTHRU*/ - case POT_RESTORE_ABILITY: - case POT_GAIN_ABILITY: - do_healing: - angermon = FALSE; - if(mon->mhp < mon->mhpmax) { - mon->mhp = mon->mhpmax; - if (canseemon(mon)) - pline("%s looks sound and hale again.", Monnam(mon)); - } - break; - case POT_SICKNESS: - if (mon->data == &mons[PM_PESTILENCE]) goto do_healing; - if (dmgtype(mon->data, AD_DISE) || - dmgtype(mon->data, AD_PEST) || /* won't happen, see prior goto */ - resists_poison(mon)) { - if (canseemon(mon)) - pline("%s looks unharmed.", Monnam(mon)); - break; - } - do_illness: - if((mon->mhpmax > 3) && !resist(mon, POTION_CLASS, 0, NOTELL)) - mon->mhpmax /= 2; - if((mon->mhp > 2) && !resist(mon, POTION_CLASS, 0, NOTELL)) - mon->mhp /= 2; - if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax; - if (canseemon(mon)) - pline("%s looks rather ill.", Monnam(mon)); - break; - case POT_CONFUSION: - case POT_BOOZE: - if(!resist(mon, POTION_CLASS, 0, NOTELL)) mon->mconf = TRUE; - break; - case POT_INVISIBILITY: - angermon = FALSE; - mon_set_minvis(mon); - break; - case POT_SLEEPING: - /* wakeup() doesn't rouse victims of temporary sleep */ - if (sleep_monst(mon, rnd(12), POTION_CLASS)) { - pline("%s falls asleep.", Monnam(mon)); - slept_monst(mon); - } - break; - case POT_PARALYSIS: - if (mon->mcanmove) { - /* really should be rnd(5) for consistency with players - * breathing potions, but... - */ - paralyze_monst(mon, rnd(25)); - } - break; - case POT_SPEED: - angermon = FALSE; - mon_adjust_speed(mon, 1, obj); - break; - case POT_BLINDNESS: - if(haseyes(mon->data)) { - register int btmp = 64 + rn2(32) + - rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL); - btmp += mon->mblinded; - mon->mblinded = min(btmp,127); - mon->mcansee = 0; - } - break; - case POT_WATER: - if (is_undead(mon->data) || is_demon(mon->data) || - is_were(mon->data) || is_vampshifter(mon)) { - if (obj->blessed) { - pline("%s %s in pain!", Monnam(mon), - is_silent(mon->data) ? "writhes" : "shrieks"); - if (!is_silent(mon->data)) - wake_nearto(mon->mx, mon->my, - mon->data->mlevel * 10); - mon->mhp -= d(2,6); - /* should only be by you */ - if (mon->mhp < 1) killed(mon); - else if (is_were(mon->data) && !is_human(mon->data)) - new_were(mon); /* revert to human */ - } else if (obj->cursed) { - angermon = FALSE; - if (canseemon(mon)) - pline("%s looks healthier.", Monnam(mon)); - mon->mhp += d(2,6); - if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax; - if (is_were(mon->data) && is_human(mon->data) && - !Protection_from_shape_changers) - new_were(mon); /* transform into beast */ - } - } else if(mon->data == &mons[PM_GREMLIN]) { - angermon = FALSE; - (void)split_mon(mon, (struct monst *)0); - } else if(mon->data == &mons[PM_IRON_GOLEM]) { - if (canseemon(mon)) - pline("%s rusts.", Monnam(mon)); - mon->mhp -= d(1,6); - /* should only be by you */ - if (mon->mhp < 1) killed(mon); - } - break; - case POT_OIL: - if (obj->lamplit) - explode_oil(obj, mon->mx, mon->my); - break; - case POT_ACID: - if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) { - pline("%s %s in pain!", Monnam(mon), - is_silent(mon->data) ? "writhes" : "shrieks"); - if (!is_silent(mon->data)) - wake_nearto(mon->mx, mon->my, - mon->data->mlevel * 10); - mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); - if (mon->mhp < 1) { - if (your_fault) - killed(mon); - else - monkilled(mon, "", AD_ACID); - } - } - break; - case POT_POLYMORPH: - (void) bhitm(mon, obj); - break; -/* - case POT_GAIN_LEVEL: - case POT_LEVITATION: - case POT_FRUIT_JUICE: - case POT_MONSTER_DETECTION: - case POT_OBJECT_DETECTION: - break; -*/ - } - if (angermon) - wakeup(mon); - else - mon->msleeping = 0; + if (hit_saddle && saddle) { + Sprintf(buf, "%s saddle", + s_suffix(x_monnam(mon, ARTICLE_THE, (char *) 0, + (SUPPRESS_IT | SUPPRESS_SADDLE), + FALSE))); + } else if (has_head(mon->data)) { + Sprintf(buf, "%s %s", s_suffix(mnam), + (notonhead ? "body" : "head")); + } else { + Strcpy(buf, mnam); + } + pline_The("%s crashes on %s and breaks into shards.", botlnam, + buf); + } + if (rn2(5) && mon->mhp > 1 && !hit_saddle) + mon->mhp--; } - /* Note: potionbreathe() does its own docall() */ - if ((distance==0 || ((distance < 3) && rn2(5))) && - (!breathless(youmonst.data) || haseyes(youmonst.data))) - potionbreathe(obj); - else if (obj->dknown && !objects[obj->otyp].oc_name_known && - !objects[obj->otyp].oc_uname && cansee(mon->mx,mon->my)) - docall(obj); - if(*u.ushops && obj->unpaid) { - struct monst *shkp = - shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); + /* oil doesn't instantly evaporate; Neither does a saddle hit */ + if (obj->otyp != POT_OIL && !hit_saddle && cansee(mon->mx, mon->my)) + pline("%s.", Tobjnam(obj, "evaporate")); - if (shkp) - (void)stolen_value(obj, u.ux, u.uy, - (boolean)shkp->mpeaceful, FALSE); - else - obj->unpaid = 0; - } - obfree(obj, (struct obj *)0); + if (isyou) { + switch (obj->otyp) { + case POT_OIL: + if (obj->lamplit) + explode_oil(obj, u.ux, u.uy); + break; + case POT_POLYMORPH: + You_feel("a little %s.", Hallucination ? "normal" : "strange"); + if (!Unchanging && !Antimagic) + polyself(0); + break; + case POT_ACID: + if (!Acid_resistance) { + int dmg; + pline("This burns%s!", obj->blessed + ? " a little" + : obj->cursed ? " a lot" : ""); + dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); + losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN); + } + break; + } + } else if (hit_saddle && saddle) { + char *mnam, buf[BUFSZ], saddle_glows[BUFSZ]; + boolean affected = FALSE; + boolean useeit = !Blind && canseemon(mon) && cansee(mon->mx, mon->my); + + mnam = x_monnam(mon, ARTICLE_THE, (char *) 0, + (SUPPRESS_IT | SUPPRESS_SADDLE), FALSE); + Sprintf(buf, "%s", upstart(s_suffix(mnam))); + + switch (obj->otyp) { + case POT_WATER: + Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow")); + affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows); + break; + case POT_POLYMORPH: + /* Do we allow the saddle to polymorph? */ + break; + } + if (useeit && !affected) + pline("%s %s wet.", buf, aobjnam(saddle, "get")); + } else { + boolean angermon = TRUE; + + if (!your_fault) + angermon = FALSE; + switch (obj->otyp) { + case POT_HEALING: + case POT_EXTRA_HEALING: + case POT_FULL_HEALING: + if (mon->data == &mons[PM_PESTILENCE]) + goto do_illness; + /*FALLTHRU*/ + case POT_RESTORE_ABILITY: + case POT_GAIN_ABILITY: + do_healing: + angermon = FALSE; + if (mon->mhp < mon->mhpmax) { + mon->mhp = mon->mhpmax; + if (canseemon(mon)) + pline("%s looks sound and hale again.", Monnam(mon)); + } + break; + case POT_SICKNESS: + if (mon->data == &mons[PM_PESTILENCE]) + goto do_healing; + if (dmgtype(mon->data, AD_DISE) || dmgtype(mon->data, AD_PEST) + || /* won't happen, see prior goto */ + resists_poison(mon)) { + if (canseemon(mon)) + pline("%s looks unharmed.", Monnam(mon)); + break; + } + do_illness: + if ((mon->mhpmax > 3) && !resist(mon, POTION_CLASS, 0, NOTELL)) + mon->mhpmax /= 2; + if ((mon->mhp > 2) && !resist(mon, POTION_CLASS, 0, NOTELL)) + mon->mhp /= 2; + if (mon->mhp > mon->mhpmax) + mon->mhp = mon->mhpmax; + if (canseemon(mon)) + pline("%s looks rather ill.", Monnam(mon)); + break; + case POT_CONFUSION: + case POT_BOOZE: + if (!resist(mon, POTION_CLASS, 0, NOTELL)) + mon->mconf = TRUE; + break; + case POT_INVISIBILITY: + angermon = FALSE; + mon_set_minvis(mon); + break; + case POT_SLEEPING: + /* wakeup() doesn't rouse victims of temporary sleep */ + if (sleep_monst(mon, rnd(12), POTION_CLASS)) { + pline("%s falls asleep.", Monnam(mon)); + slept_monst(mon); + } + break; + case POT_PARALYSIS: + if (mon->mcanmove) { + /* really should be rnd(5) for consistency with players + * breathing potions, but... + */ + paralyze_monst(mon, rnd(25)); + } + break; + case POT_SPEED: + angermon = FALSE; + mon_adjust_speed(mon, 1, obj); + break; + case POT_BLINDNESS: + if (haseyes(mon->data)) { + register int btmp = + 64 + rn2(32) + + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL); + btmp += mon->mblinded; + mon->mblinded = min(btmp, 127); + mon->mcansee = 0; + } + break; + case POT_WATER: + if (is_undead(mon->data) || is_demon(mon->data) + || is_were(mon->data) || is_vampshifter(mon)) { + if (obj->blessed) { + pline("%s %s in pain!", Monnam(mon), + is_silent(mon->data) ? "writhes" : "shrieks"); + if (!is_silent(mon->data)) + wake_nearto(mon->mx, mon->my, mon->data->mlevel * 10); + mon->mhp -= d(2, 6); + /* should only be by you */ + if (mon->mhp < 1) + killed(mon); + else if (is_were(mon->data) && !is_human(mon->data)) + new_were(mon); /* revert to human */ + } else if (obj->cursed) { + angermon = FALSE; + if (canseemon(mon)) + pline("%s looks healthier.", Monnam(mon)); + mon->mhp += d(2, 6); + if (mon->mhp > mon->mhpmax) + mon->mhp = mon->mhpmax; + if (is_were(mon->data) && is_human(mon->data) + && !Protection_from_shape_changers) + new_were(mon); /* transform into beast */ + } + } else if (mon->data == &mons[PM_GREMLIN]) { + angermon = FALSE; + (void) split_mon(mon, (struct monst *) 0); + } else if (mon->data == &mons[PM_IRON_GOLEM]) { + if (canseemon(mon)) + pline("%s rusts.", Monnam(mon)); + mon->mhp -= d(1, 6); + /* should only be by you */ + if (mon->mhp < 1) + killed(mon); + } + break; + case POT_OIL: + if (obj->lamplit) + explode_oil(obj, mon->mx, mon->my); + break; + case POT_ACID: + if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) { + pline("%s %s in pain!", Monnam(mon), + is_silent(mon->data) ? "writhes" : "shrieks"); + if (!is_silent(mon->data)) + wake_nearto(mon->mx, mon->my, mon->data->mlevel * 10); + mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); + if (mon->mhp < 1) { + if (your_fault) + killed(mon); + else + monkilled(mon, "", AD_ACID); + } + } + break; + case POT_POLYMORPH: + (void) bhitm(mon, obj); + break; + /* + case POT_GAIN_LEVEL: + case POT_LEVITATION: + case POT_FRUIT_JUICE: + case POT_MONSTER_DETECTION: + case POT_OBJECT_DETECTION: + break; + */ + } + if (angermon) + wakeup(mon); + else + mon->msleeping = 0; + } + + /* Note: potionbreathe() does its own docall() */ + if ((distance == 0 || ((distance < 3) && rn2(5))) + && (!breathless(youmonst.data) || haseyes(youmonst.data))) + potionbreathe(obj); + else if (obj->dknown && !objects[obj->otyp].oc_name_known + && !objects[obj->otyp].oc_uname && cansee(mon->mx, mon->my)) + docall(obj); + if (*u.ushops && obj->unpaid) { + struct monst *shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); + + if (shkp) + (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful, + FALSE); + else + obj->unpaid = 0; + } + obfree(obj, (struct obj *) 0); } /* vapors are inhaled or get in your eyes */ @@ -1392,143 +1442,160 @@ void potionbreathe(obj) register struct obj *obj; { - register int i, ii, isdone, kn = 0; + register int i, ii, isdone, kn = 0; - switch(obj->otyp) { - case POT_RESTORE_ABILITY: - case POT_GAIN_ABILITY: - if(obj->cursed) { - if (!breathless(youmonst.data)) - pline("Ulch! That potion smells terrible!"); - else if (haseyes(youmonst.data)) { - const char *eyes = body_part(EYE); + switch (obj->otyp) { + case POT_RESTORE_ABILITY: + case POT_GAIN_ABILITY: + if (obj->cursed) { + if (!breathless(youmonst.data)) + pline("Ulch! That potion smells terrible!"); + else if (haseyes(youmonst.data)) { + const char *eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) - eyes = makeplural(eyes); - Your("%s %s!", eyes, vtense(eyes, "sting")); - } - break; - } else { - i = rn2(A_MAX); /* start at a random point */ - for(isdone = ii = 0; !isdone && ii < A_MAX; ii++) { - if(ABASE(i) < AMAX(i)) { - ABASE(i)++; - /* only first found if not blessed */ - isdone = !(obj->blessed); - context.botl = 1; - } - if(++i >= A_MAX) i = 0; - } - } - break; - case POT_FULL_HEALING: - if (Upolyd && u.mh < u.mhmax) u.mh++, context.botl = 1; - if (u.uhp < u.uhpmax) u.uhp++, context.botl = 1; - /*FALL THROUGH*/ - case POT_EXTRA_HEALING: - if (Upolyd && u.mh < u.mhmax) u.mh++, context.botl = 1; - if (u.uhp < u.uhpmax) u.uhp++, context.botl = 1; - /*FALL THROUGH*/ - case POT_HEALING: - if (Upolyd && u.mh < u.mhmax) u.mh++, context.botl = 1; - if (u.uhp < u.uhpmax) u.uhp++, context.botl = 1; - exercise(A_CON, TRUE); - break; - case POT_SICKNESS: - if (!Role_if(PM_HEALER)) { - if (Upolyd) { - if (u.mh <= 5) u.mh = 1; else u.mh -= 5; - } else { - if (u.uhp <= 5) u.uhp = 1; else u.uhp -= 5; - } - context.botl = 1; - exercise(A_CON, FALSE); - } - break; - case POT_HALLUCINATION: - You("have a momentary vision."); - break; - case POT_CONFUSION: - case POT_BOOZE: - if(!Confusion) - You_feel("somewhat dizzy."); - make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE); - break; - case POT_INVISIBILITY: - if (!Blind && !Invis) { - kn++; - pline("For an instant you %s!", - See_invisible ? "could see right through yourself" - : "couldn't see yourself"); - } - break; - case POT_PARALYSIS: - kn++; - if (!Free_action) { - pline("%s seems to be holding you.", Something); - nomul(-rnd(5)); - multi_reason = "frozen by a potion"; - nomovemsg = You_can_move_again; - exercise(A_DEX, FALSE); - } else You("stiffen momentarily."); - break; - case POT_SLEEPING: - kn++; - if (!Free_action && !Sleep_resistance) { - You_feel("rather tired."); - nomul(-rnd(5)); - multi_reason = "sleeping off a magical draught"; - nomovemsg = You_can_move_again; - exercise(A_DEX, FALSE); - } else You("yawn."); - break; - case POT_SPEED: - if (!Fast) Your("knees seem more flexible now."); - incr_itimeout(&HFast, rnd(5)); - exercise(A_DEX, TRUE); - break; - case POT_BLINDNESS: - if (!Blind && !Unaware) { - kn++; - pline("It suddenly gets dark."); - } - make_blinded(itimeout_incr(Blinded, rnd(5)), FALSE); - if (!Blind && !Unaware) Your1(vision_clears); - break; - case POT_WATER: - if(u.umonnum == PM_GREMLIN) { - (void)split_mon(&youmonst, (struct monst *)0); - } else if (u.ulycn >= LOW_PM) { - /* vapor from [un]holy water will trigger - transformation but won't cure lycanthropy */ - if (obj->blessed && youmonst.data == &mons[u.ulycn]) - you_unwere(FALSE); - else if (obj->cursed && !Upolyd) - you_were(); - } - break; - case POT_ACID: - case POT_POLYMORPH: - exercise(A_CON, FALSE); - break; -/* - case POT_GAIN_LEVEL: - case POT_LEVITATION: - case POT_FRUIT_JUICE: - case POT_MONSTER_DETECTION: - case POT_OBJECT_DETECTION: - case POT_OIL: - break; -*/ - } - /* note: no obfree() */ - if (obj->dknown) { - if (kn) - makeknown(obj->otyp); - else if (!objects[obj->otyp].oc_name_known && - !objects[obj->otyp].oc_uname) - docall(obj); - } + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your("%s %s!", eyes, vtense(eyes, "sting")); + } + break; + } else { + i = rn2(A_MAX); /* start at a random point */ + for (isdone = ii = 0; !isdone && ii < A_MAX; ii++) { + if (ABASE(i) < AMAX(i)) { + ABASE(i)++; + /* only first found if not blessed */ + isdone = !(obj->blessed); + context.botl = 1; + } + if (++i >= A_MAX) + i = 0; + } + } + break; + case POT_FULL_HEALING: + if (Upolyd && u.mh < u.mhmax) + u.mh++, context.botl = 1; + if (u.uhp < u.uhpmax) + u.uhp++, context.botl = 1; + /*FALL THROUGH*/ + case POT_EXTRA_HEALING: + if (Upolyd && u.mh < u.mhmax) + u.mh++, context.botl = 1; + if (u.uhp < u.uhpmax) + u.uhp++, context.botl = 1; + /*FALL THROUGH*/ + case POT_HEALING: + if (Upolyd && u.mh < u.mhmax) + u.mh++, context.botl = 1; + if (u.uhp < u.uhpmax) + u.uhp++, context.botl = 1; + exercise(A_CON, TRUE); + break; + case POT_SICKNESS: + if (!Role_if(PM_HEALER)) { + if (Upolyd) { + if (u.mh <= 5) + u.mh = 1; + else + u.mh -= 5; + } else { + if (u.uhp <= 5) + u.uhp = 1; + else + u.uhp -= 5; + } + context.botl = 1; + exercise(A_CON, FALSE); + } + break; + case POT_HALLUCINATION: + You("have a momentary vision."); + break; + case POT_CONFUSION: + case POT_BOOZE: + if (!Confusion) + You_feel("somewhat dizzy."); + make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE); + break; + case POT_INVISIBILITY: + if (!Blind && !Invis) { + kn++; + pline("For an instant you %s!", + See_invisible ? "could see right through yourself" + : "couldn't see yourself"); + } + break; + case POT_PARALYSIS: + kn++; + if (!Free_action) { + pline("%s seems to be holding you.", Something); + nomul(-rnd(5)); + multi_reason = "frozen by a potion"; + nomovemsg = You_can_move_again; + exercise(A_DEX, FALSE); + } else + You("stiffen momentarily."); + break; + case POT_SLEEPING: + kn++; + if (!Free_action && !Sleep_resistance) { + You_feel("rather tired."); + nomul(-rnd(5)); + multi_reason = "sleeping off a magical draught"; + nomovemsg = You_can_move_again; + exercise(A_DEX, FALSE); + } else + You("yawn."); + break; + case POT_SPEED: + if (!Fast) + Your("knees seem more flexible now."); + incr_itimeout(&HFast, rnd(5)); + exercise(A_DEX, TRUE); + break; + case POT_BLINDNESS: + if (!Blind && !Unaware) { + kn++; + pline("It suddenly gets dark."); + } + make_blinded(itimeout_incr(Blinded, rnd(5)), FALSE); + if (!Blind && !Unaware) + Your1(vision_clears); + break; + case POT_WATER: + if (u.umonnum == PM_GREMLIN) { + (void) split_mon(&youmonst, (struct monst *) 0); + } else if (u.ulycn >= LOW_PM) { + /* vapor from [un]holy water will trigger + transformation but won't cure lycanthropy */ + if (obj->blessed && youmonst.data == &mons[u.ulycn]) + you_unwere(FALSE); + else if (obj->cursed && !Upolyd) + you_were(); + } + break; + case POT_ACID: + case POT_POLYMORPH: + exercise(A_CON, FALSE); + break; + /* + case POT_GAIN_LEVEL: + case POT_LEVITATION: + case POT_FRUIT_JUICE: + case POT_MONSTER_DETECTION: + case POT_OBJECT_DETECTION: + case POT_OIL: + break; + */ + } + /* note: no obfree() */ + if (obj->dknown) { + if (kn) + makeknown(obj->otyp); + else if (!objects[obj->otyp].oc_name_known + && !objects[obj->otyp].oc_uname) + docall(obj); + } } STATIC_OVL short @@ -1536,459 +1603,462 @@ mixtype(o1, o2) register struct obj *o1, *o2; /* returns the potion type when o1 is dipped in o2 */ { - /* cut down on the number of cases below */ - if (o1->oclass == POTION_CLASS && - (o2->otyp == POT_GAIN_LEVEL || - o2->otyp == POT_GAIN_ENERGY || - o2->otyp == POT_HEALING || - o2->otyp == POT_EXTRA_HEALING || - o2->otyp == POT_FULL_HEALING || - o2->otyp == POT_ENLIGHTENMENT || - o2->otyp == POT_FRUIT_JUICE)) { - struct obj *swp; + /* cut down on the number of cases below */ + if (o1->oclass == POTION_CLASS + && (o2->otyp == POT_GAIN_LEVEL || o2->otyp == POT_GAIN_ENERGY + || o2->otyp == POT_HEALING || o2->otyp == POT_EXTRA_HEALING + || o2->otyp == POT_FULL_HEALING || o2->otyp == POT_ENLIGHTENMENT + || o2->otyp == POT_FRUIT_JUICE)) { + struct obj *swp; - swp = o1; o1 = o2; o2 = swp; - } + swp = o1; + o1 = o2; + o2 = swp; + } - switch (o1->otyp) { - case POT_HEALING: - switch (o2->otyp) { - case POT_SPEED: - case POT_GAIN_LEVEL: - case POT_GAIN_ENERGY: - return POT_EXTRA_HEALING; - } - case POT_EXTRA_HEALING: - switch (o2->otyp) { - case POT_GAIN_LEVEL: - case POT_GAIN_ENERGY: - return POT_FULL_HEALING; - } - case POT_FULL_HEALING: - switch (o2->otyp) { - case POT_GAIN_LEVEL: - case POT_GAIN_ENERGY: - return POT_GAIN_ABILITY; - } - case UNICORN_HORN: - switch (o2->otyp) { - case POT_SICKNESS: - return POT_FRUIT_JUICE; - case POT_HALLUCINATION: - case POT_BLINDNESS: - case POT_CONFUSION: - return POT_WATER; - } - break; - case AMETHYST: /* "a-methyst" == "not intoxicated" */ - if (o2->otyp == POT_BOOZE) - return POT_FRUIT_JUICE; - break; - case POT_GAIN_LEVEL: - case POT_GAIN_ENERGY: - switch (o2->otyp) { - case POT_CONFUSION: - return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT); - case POT_HEALING: - return POT_EXTRA_HEALING; - case POT_EXTRA_HEALING: - return POT_FULL_HEALING; - case POT_FULL_HEALING: - return POT_GAIN_ABILITY; - case POT_FRUIT_JUICE: - return POT_SEE_INVISIBLE; - case POT_BOOZE: - return POT_HALLUCINATION; - } - break; - case POT_FRUIT_JUICE: - switch (o2->otyp) { - case POT_SICKNESS: - return POT_SICKNESS; - case POT_SPEED: - return POT_BOOZE; - case POT_GAIN_LEVEL: - case POT_GAIN_ENERGY: - return POT_SEE_INVISIBLE; - } - break; - case POT_ENLIGHTENMENT: - switch (o2->otyp) { - case POT_LEVITATION: - if (rn2(3)) return POT_GAIN_LEVEL; - break; - case POT_FRUIT_JUICE: - return POT_BOOZE; - case POT_BOOZE: - return POT_CONFUSION; - } - break; - } + switch (o1->otyp) { + case POT_HEALING: + switch (o2->otyp) { + case POT_SPEED: + case POT_GAIN_LEVEL: + case POT_GAIN_ENERGY: + return POT_EXTRA_HEALING; + } + case POT_EXTRA_HEALING: + switch (o2->otyp) { + case POT_GAIN_LEVEL: + case POT_GAIN_ENERGY: + return POT_FULL_HEALING; + } + case POT_FULL_HEALING: + switch (o2->otyp) { + case POT_GAIN_LEVEL: + case POT_GAIN_ENERGY: + return POT_GAIN_ABILITY; + } + case UNICORN_HORN: + switch (o2->otyp) { + case POT_SICKNESS: + return POT_FRUIT_JUICE; + case POT_HALLUCINATION: + case POT_BLINDNESS: + case POT_CONFUSION: + return POT_WATER; + } + break; + case AMETHYST: /* "a-methyst" == "not intoxicated" */ + if (o2->otyp == POT_BOOZE) + return POT_FRUIT_JUICE; + break; + case POT_GAIN_LEVEL: + case POT_GAIN_ENERGY: + switch (o2->otyp) { + case POT_CONFUSION: + return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT); + case POT_HEALING: + return POT_EXTRA_HEALING; + case POT_EXTRA_HEALING: + return POT_FULL_HEALING; + case POT_FULL_HEALING: + return POT_GAIN_ABILITY; + case POT_FRUIT_JUICE: + return POT_SEE_INVISIBLE; + case POT_BOOZE: + return POT_HALLUCINATION; + } + break; + case POT_FRUIT_JUICE: + switch (o2->otyp) { + case POT_SICKNESS: + return POT_SICKNESS; + case POT_SPEED: + return POT_BOOZE; + case POT_GAIN_LEVEL: + case POT_GAIN_ENERGY: + return POT_SEE_INVISIBLE; + } + break; + case POT_ENLIGHTENMENT: + switch (o2->otyp) { + case POT_LEVITATION: + if (rn2(3)) + return POT_GAIN_LEVEL; + break; + case POT_FRUIT_JUICE: + return POT_BOOZE; + case POT_BOOZE: + return POT_CONFUSION; + } + break; + } - return 0; + return 0; } int dodip() { - register struct obj *potion, *obj; - struct obj *singlepotion; - uchar here; - char allowall[2]; - short mixture; - char qbuf[QBUFSZ], qtoo[QBUFSZ]; + register struct obj *potion, *obj; + struct obj *singlepotion; + uchar here; + char allowall[2]; + short mixture; + char qbuf[QBUFSZ], qtoo[QBUFSZ]; - allowall[0] = ALL_CLASSES; allowall[1] = '\0'; - if(!(obj = getobj(allowall, "dip"))) - return(0); - if (inaccessible_equipment(obj, "dip", FALSE)) return 0; + allowall[0] = ALL_CLASSES; + allowall[1] = '\0'; + if (!(obj = getobj(allowall, "dip"))) + return (0); + if (inaccessible_equipment(obj, "dip", FALSE)) + return 0; - Sprintf(qbuf, "dip %s into", thesimpleoname(obj)); - here = levl[u.ux][u.uy].typ; - /* Is there a fountain to dip into here? */ - if (IS_FOUNTAIN(here)) { - /* "Dip into the fountain?" */ - Sprintf(qtoo, "%s the fountain?", qbuf); - if (yn(upstart(qtoo)) == 'y') { - dipfountain(obj); - return(1); - } - } else if (is_pool(u.ux,u.uy)) { - const char *pooltype = waterbody_name(u.ux,u.uy); + Sprintf(qbuf, "dip %s into", thesimpleoname(obj)); + here = levl[u.ux][u.uy].typ; + /* Is there a fountain to dip into here? */ + if (IS_FOUNTAIN(here)) { + /* "Dip into the fountain?" */ + Sprintf(qtoo, "%s the fountain?", qbuf); + if (yn(upstart(qtoo)) == 'y') { + dipfountain(obj); + return (1); + } + } else if (is_pool(u.ux, u.uy)) { + const char *pooltype = waterbody_name(u.ux, u.uy); - /* "Dip into the {pool, moat, &c}?" */ - Sprintf(qtoo, "%s the %s?", qbuf, pooltype); - if (yn(upstart(qtoo)) == 'y') { - if (Levitation) { - floating_above(pooltype); - } else if (u.usteed && !is_swimmer(u.usteed->data) && - P_SKILL(P_RIDING) < P_BASIC) { - rider_cant_reach(); /* not skilled enough to reach */ - } else { - if (obj->otyp == POT_ACID) obj->in_use = 1; - if (water_damage(obj, 0, TRUE) != ER_DESTROYED && obj->in_use) - useup(obj); - } - return 1; - } - } + /* "Dip into the {pool, moat, &c}?" */ + Sprintf(qtoo, "%s the %s?", qbuf, pooltype); + if (yn(upstart(qtoo)) == 'y') { + if (Levitation) { + floating_above(pooltype); + } else if (u.usteed && !is_swimmer(u.usteed->data) + && P_SKILL(P_RIDING) < P_BASIC) { + rider_cant_reach(); /* not skilled enough to reach */ + } else { + if (obj->otyp == POT_ACID) + obj->in_use = 1; + if (water_damage(obj, 0, TRUE) != ER_DESTROYED && obj->in_use) + useup(obj); + } + return 1; + } + } - /* "What do you want to dip into?" */ - potion = getobj(beverages, qbuf); /* "dip into" */ - if (!potion) return 0; - if (potion == obj && potion->quan == 1L) { - pline("That is a potion bottle, not a Klein bottle!"); - return 0; - } - potion->in_use = TRUE; /* assume it will be used up */ - if(potion->otyp == POT_WATER) { - boolean useeit = !Blind || (obj == ublindf && Blindfolded_only); - const char *obj_glows = Yobjnam2(obj, "glow"); + /* "What do you want to dip into?" */ + potion = getobj(beverages, qbuf); /* "dip into" */ + if (!potion) + return 0; + if (potion == obj && potion->quan == 1L) { + pline("That is a potion bottle, not a Klein bottle!"); + return 0; + } + potion->in_use = TRUE; /* assume it will be used up */ + if (potion->otyp == POT_WATER) { + boolean useeit = !Blind || (obj == ublindf && Blindfolded_only); + const char *obj_glows = Yobjnam2(obj, "glow"); - if (H2Opotion_dip(potion, obj, useeit, obj_glows)) - goto poof; - } else if (obj->otyp == POT_POLYMORPH || - potion->otyp == POT_POLYMORPH) { - /* some objects can't be polymorphed */ - if (obj->otyp == potion->otyp || /* both POT_POLY */ - obj->otyp == WAN_POLYMORPH || - obj->otyp == SPE_POLYMORPH || - obj == uball || obj == uskin || - obj_resists(obj->otyp == POT_POLYMORPH ? - potion : obj, 5, 95)) { - pline1(nothing_happens); - } else { - boolean was_wep, was_swapwep, was_quiver; - short save_otyp = obj->otyp; - /* KMH, conduct */ - u.uconduct.polypiles++; + if (H2Opotion_dip(potion, obj, useeit, obj_glows)) + goto poof; + } else if (obj->otyp == POT_POLYMORPH || potion->otyp == POT_POLYMORPH) { + /* some objects can't be polymorphed */ + if (obj->otyp == potion->otyp || /* both POT_POLY */ + obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH + || obj == uball || obj == uskin + || obj_resists(obj->otyp == POT_POLYMORPH ? potion : obj, 5, + 95)) { + pline1(nothing_happens); + } else { + boolean was_wep, was_swapwep, was_quiver; + short save_otyp = obj->otyp; + /* KMH, conduct */ + u.uconduct.polypiles++; - was_wep = (obj == uwep); - was_swapwep = (obj == uswapwep); - was_quiver = (obj == uquiver); + was_wep = (obj == uwep); + was_swapwep = (obj == uswapwep); + was_quiver = (obj == uquiver); - obj = poly_obj(obj, STRANGE_OBJECT); + obj = poly_obj(obj, STRANGE_OBJECT); - if (was_wep) setuwep(obj); - else if (was_swapwep) setuswapwep(obj); - else if (was_quiver) setuqwep(obj); + if (was_wep) + setuwep(obj); + else if (was_swapwep) + setuswapwep(obj); + else if (was_quiver) + setuqwep(obj); - if (obj->otyp != save_otyp) { - makeknown(POT_POLYMORPH); - useup(potion); - prinv((char *)0, obj, 0L); - return 1; - } else { - pline("Nothing seems to happen."); - goto poof; - } - } - potion->in_use = FALSE; /* didn't go poof */ - return(1); - } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) { - long amt = obj->quan; + if (obj->otyp != save_otyp) { + makeknown(POT_POLYMORPH); + useup(potion); + prinv((char *) 0, obj, 0L); + return 1; + } else { + pline("Nothing seems to happen."); + goto poof; + } + } + potion->in_use = FALSE; /* didn't go poof */ + return (1); + } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) { + long amt = obj->quan; - Strcpy(qbuf, "The"); - if (amt > (objects[potion->otyp].oc_magic ? 2L : 9L)) { - /* trying to dip multiple potions will usually affect only a - subset; pick an amount between 2 and min(N,9), inclusive */ - amt -= 1L; - do { - amt = (long)rnd((int)amt); - } while (amt >= 9L); - amt += 1L; - if (amt < obj->quan) { - obj = splitobj(obj, amt); - Sprintf(qbuf, "%ld of the", obj->quan); - } - } - /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */ - pline("%s %s %s with %s%s...", qbuf, - simpleonames(obj), otense(obj, "mix"), - (potion->quan > 1L) ? "one of " : "", - thesimpleoname(potion)); - /* Mixing potions is dangerous... - KMH, balance patch -- acid is particularly unstable */ - if (obj->cursed || obj->otyp == POT_ACID || !rn2(10)) { - /* it would be better to use up the whole stack in advance - of the message, but we can't because we need to keep it - around for potionbreathe() [and we can't set obj->in_use - to 'amt' because that's not implemented] */ - obj->in_use = 1; - pline("BOOM! They explode!"); - wake_nearto(u.ux, u.uy, (BOLT_LIM+1)*(BOLT_LIM+1)); - exercise(A_STR, FALSE); - if (!breathless(youmonst.data) || haseyes(youmonst.data)) - potionbreathe(obj); - useupall(obj); - useup(potion); - losehp((int)(amt + rnd(9)), /* not physical damage */ - "alchemic blast", KILLED_BY_AN); - return 1; - } + Strcpy(qbuf, "The"); + if (amt > (objects[potion->otyp].oc_magic ? 2L : 9L)) { + /* trying to dip multiple potions will usually affect only a + subset; pick an amount between 2 and min(N,9), inclusive */ + amt -= 1L; + do { + amt = (long) rnd((int) amt); + } while (amt >= 9L); + amt += 1L; + if (amt < obj->quan) { + obj = splitobj(obj, amt); + Sprintf(qbuf, "%ld of the", obj->quan); + } + } + /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */ + pline("%s %s %s with %s%s...", qbuf, simpleonames(obj), + otense(obj, "mix"), (potion->quan > 1L) ? "one of " : "", + thesimpleoname(potion)); + /* Mixing potions is dangerous... + KMH, balance patch -- acid is particularly unstable */ + if (obj->cursed || obj->otyp == POT_ACID || !rn2(10)) { + /* it would be better to use up the whole stack in advance + of the message, but we can't because we need to keep it + around for potionbreathe() [and we can't set obj->in_use + to 'amt' because that's not implemented] */ + obj->in_use = 1; + pline("BOOM! They explode!"); + wake_nearto(u.ux, u.uy, (BOLT_LIM + 1) * (BOLT_LIM + 1)); + exercise(A_STR, FALSE); + if (!breathless(youmonst.data) || haseyes(youmonst.data)) + potionbreathe(obj); + useupall(obj); + useup(potion); + losehp((int) (amt + rnd(9)), /* not physical damage */ + "alchemic blast", KILLED_BY_AN); + return 1; + } - obj->blessed = obj->cursed = obj->bknown = 0; - if (Blind || Hallucination) obj->dknown = 0; + obj->blessed = obj->cursed = obj->bknown = 0; + if (Blind || Hallucination) + obj->dknown = 0; - if ((mixture = mixtype(obj, potion)) != 0) { - obj->otyp = mixture; - } else { - switch (obj->odiluted ? 1 : rnd(8)) { - case 1: - obj->otyp = POT_WATER; - break; - case 2: - case 3: - obj->otyp = POT_SICKNESS; - break; - case 4: - { - struct obj *otmp = mkobj(POTION_CLASS, FALSE); + if ((mixture = mixtype(obj, potion)) != 0) { + obj->otyp = mixture; + } else { + switch (obj->odiluted ? 1 : rnd(8)) { + case 1: + obj->otyp = POT_WATER; + break; + case 2: + case 3: + obj->otyp = POT_SICKNESS; + break; + case 4: { + struct obj *otmp = mkobj(POTION_CLASS, FALSE); - obj->otyp = otmp->otyp; - obfree(otmp, (struct obj *)0); - } - break; - default: - useupall(obj); - useup(potion); - if (!Blind) - pline_The("mixture glows brightly and evaporates."); - return 1; - } - } - obj->odiluted = (obj->otyp != POT_WATER); + obj->otyp = otmp->otyp; + obfree(otmp, (struct obj *) 0); + } break; + default: + useupall(obj); + useup(potion); + if (!Blind) + pline_The("mixture glows brightly and evaporates."); + return 1; + } + } + obj->odiluted = (obj->otyp != POT_WATER); - if (obj->otyp == POT_WATER && !Hallucination) { - pline_The("mixture bubbles%s.", Blind ? "" : ", then clears"); - } else if (!Blind) { - pline_The("mixture looks %s.", - hcolor(OBJ_DESCR(objects[obj->otyp]))); - } + if (obj->otyp == POT_WATER && !Hallucination) { + pline_The("mixture bubbles%s.", Blind ? "" : ", then clears"); + } else if (!Blind) { + pline_The("mixture looks %s.", + hcolor(OBJ_DESCR(objects[obj->otyp]))); + } - useup(potion); - /* this is required when 'obj' was split off from a bigger stack, - so that 'obj' will now be assigned its own inventory slot; - it has a side-effect of merging 'obj' into another compatible - stack if there is one, so we do it even when no split has - been made in order to get the merge result for both cases; - as a consequence, mixing while Fumbling drops the mixture */ - freeinv(obj); - (void) hold_another_object(obj, "You drop %s!", doname(obj), - (const char *)0); - return 1; - } + useup(potion); + /* this is required when 'obj' was split off from a bigger stack, + so that 'obj' will now be assigned its own inventory slot; + it has a side-effect of merging 'obj' into another compatible + stack if there is one, so we do it even when no split has + been made in order to get the merge result for both cases; + as a consequence, mixing while Fumbling drops the mixture */ + freeinv(obj); + (void) hold_another_object(obj, "You drop %s!", doname(obj), + (const char *) 0); + return 1; + } - if(potion->otyp == POT_ACID && obj->otyp == CORPSE && - obj->corpsenm == PM_LICHEN && !Blind) { - pline("%s %s %s around the edges.", The(cxname(obj)), - otense(obj, "turn"), potion->odiluted ? - hcolor(NH_ORANGE) : hcolor(NH_RED)); - potion->in_use = FALSE; /* didn't go poof */ - return(1); - } + if (potion->otyp == POT_ACID && obj->otyp == CORPSE + && obj->corpsenm == PM_LICHEN && !Blind) { + pline("%s %s %s around the edges.", The(cxname(obj)), + otense(obj, "turn"), + potion->odiluted ? hcolor(NH_ORANGE) : hcolor(NH_RED)); + potion->in_use = FALSE; /* didn't go poof */ + return (1); + } - if(is_poisonable(obj)) { - if(potion->otyp == POT_SICKNESS && !obj->opoisoned) { - char buf[BUFSZ]; - if (potion->quan > 1L) - Sprintf(buf, "One of %s", the(xname(potion))); - else - Strcpy(buf, The(xname(potion))); - pline("%s forms a coating on %s.", - buf, the(xname(obj))); - obj->opoisoned = TRUE; - goto poof; - } else if(obj->opoisoned && - (potion->otyp == POT_HEALING || - potion->otyp == POT_EXTRA_HEALING || - potion->otyp == POT_FULL_HEALING)) { - pline("A coating wears off %s.", the(xname(obj))); - obj->opoisoned = 0; - goto poof; - } - } + if (is_poisonable(obj)) { + if (potion->otyp == POT_SICKNESS && !obj->opoisoned) { + char buf[BUFSZ]; + if (potion->quan > 1L) + Sprintf(buf, "One of %s", the(xname(potion))); + else + Strcpy(buf, The(xname(potion))); + pline("%s forms a coating on %s.", buf, the(xname(obj))); + obj->opoisoned = TRUE; + goto poof; + } else if (obj->opoisoned && (potion->otyp == POT_HEALING + || potion->otyp == POT_EXTRA_HEALING + || potion->otyp == POT_FULL_HEALING)) { + pline("A coating wears off %s.", the(xname(obj))); + obj->opoisoned = 0; + goto poof; + } + } - if (potion->otyp == POT_ACID) { - if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING) - goto poof; - } + if (potion->otyp == POT_ACID) { + if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING) + goto poof; + } - if (potion->otyp == POT_OIL) { - boolean wisx = FALSE; - if (potion->lamplit) { /* burning */ - fire_damage(obj, TRUE, u.ux, u.uy); - } else if (potion->cursed) { - pline_The("potion spills and covers your %s with oil.", - makeplural(body_part(FINGER))); - incr_itimeout(&Glib, d(2,10)); - } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) { - /* the following cases apply only to weapons */ - goto more_dips; - /* Oil removes rust and corrosion, but doesn't unburn. - * Arrows, etc are classed as metallic due to arrowhead - * material, but dipping in oil shouldn't repair them. - */ - } else if ((!is_rustprone(obj) && !is_corrodeable(obj)) || - is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) { - /* uses up potion, doesn't set obj->greased */ - pline("%s %s with an oily sheen.", - Yname2(obj), otense(obj, "gleam")); - } else { - pline("%s %s less %s.", - Yname2(obj), otense(obj, "are"), - (obj->oeroded && obj->oeroded2) ? "corroded and rusty" : - obj->oeroded ? "rusty" : "corroded"); - if (obj->oeroded > 0) obj->oeroded--; - if (obj->oeroded2 > 0) obj->oeroded2--; - wisx = TRUE; - } - exercise(A_WIS, wisx); - makeknown(potion->otyp); - useup(potion); - return 1; - } - more_dips: + if (potion->otyp == POT_OIL) { + boolean wisx = FALSE; + if (potion->lamplit) { /* burning */ + fire_damage(obj, TRUE, u.ux, u.uy); + } else if (potion->cursed) { + pline_The("potion spills and covers your %s with oil.", + makeplural(body_part(FINGER))); + incr_itimeout(&Glib, d(2, 10)); + } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) { + /* the following cases apply only to weapons */ + goto more_dips; + /* Oil removes rust and corrosion, but doesn't unburn. + * Arrows, etc are classed as metallic due to arrowhead + * material, but dipping in oil shouldn't repair them. + */ + } else if ((!is_rustprone(obj) && !is_corrodeable(obj)) + || is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) { + /* uses up potion, doesn't set obj->greased */ + pline("%s %s with an oily sheen.", Yname2(obj), + otense(obj, "gleam")); + } else { + pline("%s %s less %s.", Yname2(obj), otense(obj, "are"), + (obj->oeroded && obj->oeroded2) + ? "corroded and rusty" + : obj->oeroded ? "rusty" : "corroded"); + if (obj->oeroded > 0) + obj->oeroded--; + if (obj->oeroded2 > 0) + obj->oeroded2--; + wisx = TRUE; + } + exercise(A_WIS, wisx); + makeknown(potion->otyp); + useup(potion); + return 1; + } +more_dips: - /* Allow filling of MAGIC_LAMPs to prevent identification by player */ - if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) && - (potion->otyp == POT_OIL)) { - /* Turn off engine before fueling, turn off fuel too :-) */ - if (obj->lamplit || potion->lamplit) { - useup(potion); - explode(u.ux, u.uy, 11, d(6,6), 0, EXPL_FIERY); - exercise(A_WIS, FALSE); - return 1; - } - /* Adding oil to an empty magic lamp renders it into an oil lamp */ - if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) { - obj->otyp = OIL_LAMP; - obj->age = 0; - } - if (obj->age > 1000L) { - pline("%s %s full.", Yname2(obj), otense(obj, "are")); - potion->in_use = FALSE; /* didn't go poof */ - } else { - You("fill %s with oil.", yname(obj)); - check_unpaid(potion); /* Yendorian Fuel Tax */ - obj->age += 2*potion->age; /* burns more efficiently */ - if (obj->age > 1500L) obj->age = 1500L; - useup(potion); - exercise(A_WIS, TRUE); - } - makeknown(POT_OIL); - obj->spe = 1; - update_inventory(); - return 1; - } + /* Allow filling of MAGIC_LAMPs to prevent identification by player */ + if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) + && (potion->otyp == POT_OIL)) { + /* Turn off engine before fueling, turn off fuel too :-) */ + if (obj->lamplit || potion->lamplit) { + useup(potion); + explode(u.ux, u.uy, 11, d(6, 6), 0, EXPL_FIERY); + exercise(A_WIS, FALSE); + return 1; + } + /* Adding oil to an empty magic lamp renders it into an oil lamp */ + if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) { + obj->otyp = OIL_LAMP; + obj->age = 0; + } + if (obj->age > 1000L) { + pline("%s %s full.", Yname2(obj), otense(obj, "are")); + potion->in_use = FALSE; /* didn't go poof */ + } else { + You("fill %s with oil.", yname(obj)); + check_unpaid(potion); /* Yendorian Fuel Tax */ + obj->age += 2 * potion->age; /* burns more efficiently */ + if (obj->age > 1500L) + obj->age = 1500L; + useup(potion); + exercise(A_WIS, TRUE); + } + makeknown(POT_OIL); + obj->spe = 1; + update_inventory(); + return 1; + } - potion->in_use = FALSE; /* didn't go poof */ - if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST) && - (mixture = mixtype(obj, potion)) != 0) { - char oldbuf[BUFSZ], newbuf[BUFSZ]; - short old_otyp = potion->otyp; - boolean old_dknown = FALSE; - boolean more_than_one = potion->quan > 1L; + potion->in_use = FALSE; /* didn't go poof */ + if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST) + && (mixture = mixtype(obj, potion)) != 0) { + char oldbuf[BUFSZ], newbuf[BUFSZ]; + short old_otyp = potion->otyp; + boolean old_dknown = FALSE; + boolean more_than_one = potion->quan > 1L; - oldbuf[0] = '\0'; - if (potion->dknown) { - old_dknown = TRUE; - Sprintf(oldbuf, "%s ", - hcolor(OBJ_DESCR(objects[potion->otyp]))); - } - /* with multiple merged potions, split off one and - just clear it */ - if (potion->quan > 1L) { - singlepotion = splitobj(potion, 1L); - } else singlepotion = potion; + oldbuf[0] = '\0'; + if (potion->dknown) { + old_dknown = TRUE; + Sprintf(oldbuf, "%s ", hcolor(OBJ_DESCR(objects[potion->otyp]))); + } + /* with multiple merged potions, split off one and + just clear it */ + if (potion->quan > 1L) { + singlepotion = splitobj(potion, 1L); + } else + singlepotion = potion; - costly_alteration(singlepotion, COST_NUTRLZ); - singlepotion->otyp = mixture; - singlepotion->blessed = 0; - if (mixture == POT_WATER) - singlepotion->cursed = singlepotion->odiluted = 0; - else - singlepotion->cursed = obj->cursed; /* odiluted left as-is */ - singlepotion->bknown = FALSE; - if (Blind) { - singlepotion->dknown = FALSE; - } else { - singlepotion->dknown = !Hallucination; - if (mixture == POT_WATER && singlepotion->dknown) - Sprintf(newbuf, "clears"); - else - Sprintf(newbuf, "turns %s", - hcolor(OBJ_DESCR(objects[mixture]))); - pline_The("%spotion%s %s.", oldbuf, - more_than_one ? " that you dipped into" : "", - newbuf); - if(!objects[old_otyp].oc_uname && - !objects[old_otyp].oc_name_known && old_dknown) { - struct obj fakeobj; - fakeobj = zeroobj; - fakeobj.dknown = 1; - fakeobj.otyp = old_otyp; - fakeobj.oclass = POTION_CLASS; - docall(&fakeobj); - } - } - obj_extract_self(singlepotion); - singlepotion = hold_another_object(singlepotion, - "You juggle and drop %s!", - doname(singlepotion), (const char *)0); - update_inventory(); - return(1); - } + costly_alteration(singlepotion, COST_NUTRLZ); + singlepotion->otyp = mixture; + singlepotion->blessed = 0; + if (mixture == POT_WATER) + singlepotion->cursed = singlepotion->odiluted = 0; + else + singlepotion->cursed = obj->cursed; /* odiluted left as-is */ + singlepotion->bknown = FALSE; + if (Blind) { + singlepotion->dknown = FALSE; + } else { + singlepotion->dknown = !Hallucination; + if (mixture == POT_WATER && singlepotion->dknown) + Sprintf(newbuf, "clears"); + else + Sprintf(newbuf, "turns %s", + hcolor(OBJ_DESCR(objects[mixture]))); + pline_The("%spotion%s %s.", oldbuf, + more_than_one ? " that you dipped into" : "", newbuf); + if (!objects[old_otyp].oc_uname + && !objects[old_otyp].oc_name_known && old_dknown) { + struct obj fakeobj; + fakeobj = zeroobj; + fakeobj.dknown = 1; + fakeobj.otyp = old_otyp; + fakeobj.oclass = POTION_CLASS; + docall(&fakeobj); + } + } + obj_extract_self(singlepotion); + singlepotion = + hold_another_object(singlepotion, "You juggle and drop %s!", + doname(singlepotion), (const char *) 0); + update_inventory(); + return (1); + } - pline("Interesting..."); - return(1); + pline("Interesting..."); + return (1); - poof: - if (!objects[potion->otyp].oc_name_known && - !objects[potion->otyp].oc_uname) - docall(potion); - useup(potion); - return 1; +poof: + if (!objects[potion->otyp].oc_name_known + && !objects[potion->otyp].oc_uname) + docall(potion); + useup(potion); + return 1; } /* *monp grants a wish and then leaves the game */ @@ -1997,13 +2067,12 @@ mongrantswish(monp) struct monst **monp; { struct monst *mon = *monp; - int mx = mon->mx, my = mon->my, - glyph = glyph_at(mx, my); - + int mx = mon->mx, my = mon->my, glyph = glyph_at(mx, my); + /* remove the monster first in case wish proves to be fatal (blasted by artifact), to keep it out of resulting bones file */ - mongone(mon); - *monp = 0; /* inform caller that monster is gone */ + mongone(mon); + *monp = 0; /* inform caller that monster is gone */ /* hide that removal from player--map is visible during wish prompt */ tmp_at(DISP_ALWAYS, glyph); tmp_at(mx, my); @@ -2017,83 +2086,92 @@ void djinni_from_bottle(obj) register struct obj *obj; { - struct monst *mtmp; - int chance; + struct monst *mtmp; + int chance; - if(!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, NO_MM_FLAGS))){ - pline("It turns out to be empty."); - return; - } + if (!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, NO_MM_FLAGS))) { + pline("It turns out to be empty."); + return; + } - if (!Blind) { - pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp)); - pline("%s speaks.", Monnam(mtmp)); - } else { - You("smell acrid fumes."); - pline("%s speaks.", Something); - } + if (!Blind) { + pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp)); + pline("%s speaks.", Monnam(mtmp)); + } else { + You("smell acrid fumes."); + pline("%s speaks.", Something); + } - chance = rn2(5); - if (obj->blessed) chance = (chance == 4) ? rnd(4) : 0; - else if (obj->cursed) chance = (chance == 0) ? rn2(4) : 4; - /* 0,1,2,3,4: b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */ + chance = rn2(5); + if (obj->blessed) + chance = (chance == 4) ? rnd(4) : 0; + else if (obj->cursed) + chance = (chance == 0) ? rn2(4) : 4; + /* 0,1,2,3,4: b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */ - switch (chance) { - case 0 : verbalize("I am in your debt. I will grant one wish!"); - /* give a wish and discard the monster (mtmp set to null) */ - mongrantswish(&mtmp); - break; - case 1 : verbalize("Thank you for freeing me!"); - (void) tamedog(mtmp, (struct obj *)0); - break; - case 2 : verbalize("You freed me!"); - mtmp->mpeaceful = TRUE; - set_malign(mtmp); - break; - case 3 : verbalize("It is about time!"); - if (canspotmon(mtmp)) pline("%s vanishes.", Monnam(mtmp)); - mongone(mtmp); - break; - default: verbalize("You disturbed me, fool!"); - mtmp->mpeaceful = FALSE; - set_malign(mtmp); - break; - } + switch (chance) { + case 0: + verbalize("I am in your debt. I will grant one wish!"); + /* give a wish and discard the monster (mtmp set to null) */ + mongrantswish(&mtmp); + break; + case 1: + verbalize("Thank you for freeing me!"); + (void) tamedog(mtmp, (struct obj *) 0); + break; + case 2: + verbalize("You freed me!"); + mtmp->mpeaceful = TRUE; + set_malign(mtmp); + break; + case 3: + verbalize("It is about time!"); + if (canspotmon(mtmp)) + pline("%s vanishes.", Monnam(mtmp)); + mongone(mtmp); + break; + default: + verbalize("You disturbed me, fool!"); + mtmp->mpeaceful = FALSE; + set_malign(mtmp); + break; + } } /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger); hit points are cut in half (odd HP stays with original) */ struct monst * split_mon(mon, mtmp) -struct monst *mon, /* monster being split */ - *mtmp; /* optional attacker whose heat triggered it */ +struct monst *mon, /* monster being split */ + *mtmp; /* optional attacker whose heat triggered it */ { - struct monst *mtmp2; - char reason[BUFSZ]; + struct monst *mtmp2; + char reason[BUFSZ]; - reason[0] = '\0'; - if (mtmp) Sprintf(reason, " from %s heat", - (mtmp == &youmonst) ? the_your[1] : - (const char *)s_suffix(mon_nam(mtmp))); + reason[0] = '\0'; + if (mtmp) + Sprintf(reason, " from %s heat", + (mtmp == &youmonst) ? the_your[1] + : (const char *) s_suffix(mon_nam(mtmp))); - if (mon == &youmonst) { - mtmp2 = cloneu(); - if (mtmp2) { - mtmp2->mhpmax = u.mhmax / 2; - u.mhmax -= mtmp2->mhpmax; - context.botl = 1; - You("multiply%s!", reason); - } - } else { - mtmp2 = clone_mon(mon, 0, 0); - if (mtmp2) { - mtmp2->mhpmax = mon->mhpmax / 2; - mon->mhpmax -= mtmp2->mhpmax; - if (canspotmon(mon)) - pline("%s multiplies%s!", Monnam(mon), reason); - } - } - return mtmp2; + if (mon == &youmonst) { + mtmp2 = cloneu(); + if (mtmp2) { + mtmp2->mhpmax = u.mhmax / 2; + u.mhmax -= mtmp2->mhpmax; + context.botl = 1; + You("multiply%s!", reason); + } + } else { + mtmp2 = clone_mon(mon, 0, 0); + if (mtmp2) { + mtmp2->mhpmax = mon->mhpmax / 2; + mon->mhpmax -= mtmp2->mhpmax; + if (canspotmon(mon)) + pline("%s multiplies%s!", Monnam(mon), reason); + } + } + return mtmp2; } /*potion.c*/ diff --git a/src/pray.c b/src/pray.c index 8ae9ef20d..482188c2e 100644 --- a/src/pray.c +++ b/src/pray.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pray.c $NHDT-Date: 1427670643 2015/03/29 23:10:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.69 $ */ +/* NetHack 3.6 pray.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.80 $ */ /* NetHack 3.6 pray.c $Date: 2012/05/07 01:44:38 $ $Revision: 1.62 $ */ /* Copyright (c) Benson I. Margulies, Mike Stephenson, Steve Linhart, 1989. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,22 +8,22 @@ STATIC_PTR int NDECL(prayer_done); STATIC_DCL struct obj *NDECL(worst_cursed_item); STATIC_DCL int NDECL(in_trouble); -STATIC_DCL void FDECL(fix_worst_trouble,(int)); -STATIC_DCL void FDECL(angrygods,(ALIGNTYP_P)); +STATIC_DCL void FDECL(fix_worst_trouble, (int)); +STATIC_DCL void FDECL(angrygods, (ALIGNTYP_P)); STATIC_DCL void FDECL(at_your_feet, (const char *)); STATIC_DCL void NDECL(gcrownu); -STATIC_DCL void FDECL(pleased,(ALIGNTYP_P)); -STATIC_DCL void FDECL(godvoice,(ALIGNTYP_P,const char*)); -STATIC_DCL void FDECL(god_zaps_you,(ALIGNTYP_P)); -STATIC_DCL void FDECL(fry_by_god,(ALIGNTYP_P,BOOLEAN_P)); -STATIC_DCL void FDECL(gods_angry,(ALIGNTYP_P)); -STATIC_DCL void FDECL(gods_upset,(ALIGNTYP_P)); -STATIC_DCL void FDECL(consume_offering,(struct obj *)); -STATIC_DCL boolean FDECL(water_prayer,(BOOLEAN_P)); -STATIC_DCL boolean FDECL(blocked_boulder,(int,int)); +STATIC_DCL void FDECL(pleased, (ALIGNTYP_P)); +STATIC_DCL void FDECL(godvoice, (ALIGNTYP_P, const char *)); +STATIC_DCL void FDECL(god_zaps_you, (ALIGNTYP_P)); +STATIC_DCL void FDECL(fry_by_god, (ALIGNTYP_P, BOOLEAN_P)); +STATIC_DCL void FDECL(gods_angry, (ALIGNTYP_P)); +STATIC_DCL void FDECL(gods_upset, (ALIGNTYP_P)); +STATIC_DCL void FDECL(consume_offering, (struct obj *)); +STATIC_DCL boolean FDECL(water_prayer, (BOOLEAN_P)); +STATIC_DCL boolean FDECL(blocked_boulder, (int, int)); /* simplify a few tests */ -#define Cursed_obj(obj,typ) ((obj) && (obj)->otyp == (typ) && (obj)->cursed) +#define Cursed_obj(obj, typ) ((obj) && (obj)->otyp == (typ) && (obj)->cursed) /* * Logic behind deities and altars and such: @@ -42,13 +42,10 @@ STATIC_DCL boolean FDECL(blocked_boulder,(int,int)); * responsible for the theft of the Amulet from Marduk, the Creator. * Moloch is unaligned. */ -static const char *Moloch = "Moloch"; +static const char *Moloch = "Moloch"; static const char *godvoices[] = { - "booms out", - "thunders", - "rings out", - "booms", + "booms out", "thunders", "rings out", "booms", }; /* values calculated when prayer starts, and used when completed */ @@ -68,32 +65,32 @@ static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */ * order to have the values be meaningful. */ -#define TROUBLE_STONED 14 -#define TROUBLE_SLIMED 13 -#define TROUBLE_STRANGLED 12 -#define TROUBLE_LAVA 11 -#define TROUBLE_SICK 10 -#define TROUBLE_STARVING 9 -#define TROUBLE_REGION 8 /* stinking cloud */ -#define TROUBLE_HIT 7 -#define TROUBLE_LYCANTHROPE 6 -#define TROUBLE_COLLAPSING 5 -#define TROUBLE_STUCK_IN_WALL 4 -#define TROUBLE_CURSED_LEVITATION 3 -#define TROUBLE_UNUSEABLE_HANDS 2 -#define TROUBLE_CURSED_BLINDFOLD 1 +#define TROUBLE_STONED 14 +#define TROUBLE_SLIMED 13 +#define TROUBLE_STRANGLED 12 +#define TROUBLE_LAVA 11 +#define TROUBLE_SICK 10 +#define TROUBLE_STARVING 9 +#define TROUBLE_REGION 8 /* stinking cloud */ +#define TROUBLE_HIT 7 +#define TROUBLE_LYCANTHROPE 6 +#define TROUBLE_COLLAPSING 5 +#define TROUBLE_STUCK_IN_WALL 4 +#define TROUBLE_CURSED_LEVITATION 3 +#define TROUBLE_UNUSEABLE_HANDS 2 +#define TROUBLE_CURSED_BLINDFOLD 1 -#define TROUBLE_PUNISHED (-1) -#define TROUBLE_FUMBLING (-2) -#define TROUBLE_CURSED_ITEMS (-3) -#define TROUBLE_SADDLE (-4) -#define TROUBLE_BLIND (-5) -#define TROUBLE_POISONED (-6) -#define TROUBLE_WOUNDED_LEGS (-7) -#define TROUBLE_HUNGRY (-8) -#define TROUBLE_STUNNED (-9) -#define TROUBLE_CONFUSED (-10) -#define TROUBLE_HALLUCINATION (-11) +#define TROUBLE_PUNISHED (-1) +#define TROUBLE_FUMBLING (-2) +#define TROUBLE_CURSED_ITEMS (-3) +#define TROUBLE_SADDLE (-4) +#define TROUBLE_BLIND (-5) +#define TROUBLE_POISONED (-6) +#define TROUBLE_WOUNDED_LEGS (-7) +#define TROUBLE_HUNGRY (-8) +#define TROUBLE_STUNNED (-9) +#define TROUBLE_CONFUSED (-10) +#define TROUBLE_HALLUCINATION (-11) /* We could force rehumanize of polyselfed people, but we can't tell unintentional shape changes from the other kind. Oh well. @@ -111,33 +108,48 @@ but that's really hard. */ #define ugod_is_angry() (u.ualign.record < 0) -#define on_altar() IS_ALTAR(levl[u.ux][u.uy].typ) -#define on_shrine() ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0) -#define a_align(x,y) ((aligntyp)Amask2align(levl[x][y].altarmask & AM_MASK)) +#define on_altar() IS_ALTAR(levl[u.ux][u.uy].typ) +#define on_shrine() ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0) +#define a_align(x, y) ((aligntyp) Amask2align(levl[x][y].altarmask & AM_MASK)) /* criticially low hit points if hp <= 5 or hp <= maxhp/N for some N */ boolean critically_low_hp(only_if_injured) -boolean only_if_injured; /* determines whether maxhp <= 5 matters */ +boolean only_if_injured; /* determines whether maxhp <= 5 matters */ { - int divisor, hplim, - curhp = Upolyd ? u.mh : u.uhp, - maxhp = Upolyd ? u.mhmax : u.uhpmax; + int divisor, hplim, curhp = Upolyd ? u.mh : u.uhp, + maxhp = Upolyd ? u.mhmax : u.uhpmax; - if (only_if_injured && !(curhp < maxhp)) return FALSE; + if (only_if_injured && !(curhp < maxhp)) + return FALSE; /* if maxhp is extremely high, use lower threshold for the division test (golden glow cuts off at 11+5*lvl, nurse interaction at 25*lvl; this ought to use monster hit dice--and a smaller multiplier--rather than ulevel when polymorphed, but polyself doesn't maintain that) */ hplim = 15 * u.ulevel; - if (maxhp > hplim) maxhp = hplim; + if (maxhp > hplim) + maxhp = hplim; /* 7 used to be the unconditional divisor */ - switch (xlev_to_rank(u.ulevel)) { /* maps 1..30 into 0..8 */ - case 0: case 1: divisor = 5; break; /* explvl 1 to 5 */ - case 2: case 3: divisor = 6; break; /* explvl 6 to 13 */ - case 4: case 5: divisor = 7; break; /* explvl 14 to 21 */ - case 6: case 7: divisor = 8; break; /* explvl 22 to 29 */ - default: divisor = 9; break; /* explvl 30+ */ + switch (xlev_to_rank(u.ulevel)) { /* maps 1..30 into 0..8 */ + case 0: + case 1: + divisor = 5; + break; /* explvl 1 to 5 */ + case 2: + case 3: + divisor = 6; + break; /* explvl 6 to 13 */ + case 4: + case 5: + divisor = 7; + break; /* explvl 14 to 21 */ + case 6: + case 7: + divisor = 8; + break; /* explvl 22 to 29 */ + default: + divisor = 9; + break; /* explvl 30+ */ } /* 5 is a magic number in TROUBLE_HIT handling below */ return (curhp <= 5 || curhp * divisor <= maxhp); @@ -146,74 +158,96 @@ boolean only_if_injured; /* determines whether maxhp <= 5 matters */ STATIC_OVL int in_trouble() { - struct obj *otmp; - int i, j, count=0; + struct obj *otmp; + int i, j, count = 0; - /* - * major troubles - */ - if(Stoned) return(TROUBLE_STONED); - if(Slimed) return(TROUBLE_SLIMED); - if(Strangled) return(TROUBLE_STRANGLED); - if(u.utrap && u.utraptype == TT_LAVA) return(TROUBLE_LAVA); - if(Sick) return(TROUBLE_SICK); - if(u.uhs >= WEAK) return(TROUBLE_STARVING); - if (region_danger()) return TROUBLE_REGION; - if (critically_low_hp(FALSE)) return TROUBLE_HIT; - if(u.ulycn >= LOW_PM) return(TROUBLE_LYCANTHROPE); - if(near_capacity() >= EXT_ENCUMBER && AMAX(A_STR)-ABASE(A_STR) > 3) - return(TROUBLE_COLLAPSING); + /* + * major troubles + */ + if (Stoned) + return (TROUBLE_STONED); + if (Slimed) + return (TROUBLE_SLIMED); + if (Strangled) + return (TROUBLE_STRANGLED); + if (u.utrap && u.utraptype == TT_LAVA) + return (TROUBLE_LAVA); + if (Sick) + return (TROUBLE_SICK); + if (u.uhs >= WEAK) + return (TROUBLE_STARVING); + if (region_danger()) + return TROUBLE_REGION; + if (critically_low_hp(FALSE)) + return TROUBLE_HIT; + if (u.ulycn >= LOW_PM) + return (TROUBLE_LYCANTHROPE); + if (near_capacity() >= EXT_ENCUMBER && AMAX(A_STR) - ABASE(A_STR) > 3) + return (TROUBLE_COLLAPSING); - for (i= -1; i<=1; i++) for(j= -1; j<=1; j++) { - if (!i && !j) continue; - if (!isok(u.ux+i, u.uy+j) || IS_ROCK(levl[u.ux+i][u.uy+j].typ) - || (blocked_boulder(i,j) && !throws_rocks(youmonst.data))) - count++; - } - if (count == 8 && !Passes_walls) - return(TROUBLE_STUCK_IN_WALL); + for (i = -1; i <= 1; i++) + for (j = -1; j <= 1; j++) { + if (!i && !j) + continue; + if (!isok(u.ux + i, u.uy + j) + || IS_ROCK(levl[u.ux + i][u.uy + j].typ) + || (blocked_boulder(i, j) && !throws_rocks(youmonst.data))) + count++; + } + if (count == 8 && !Passes_walls) + return (TROUBLE_STUCK_IN_WALL); - if (Cursed_obj(uarmf, LEVITATION_BOOTS) || - stuck_ring(uleft, RIN_LEVITATION) || - stuck_ring(uright, RIN_LEVITATION)) - return(TROUBLE_CURSED_LEVITATION); - if (nohands(youmonst.data) || !freehand()) { - /* for bag/box access [cf use_container()]... - make sure it's a case that we know how to handle; - otherwise "fix all troubles" would get stuck in a loop */ - if (welded(uwep)) return TROUBLE_UNUSEABLE_HANDS; - if (Upolyd && nohands(youmonst.data) && (!Unchanging || - ((otmp = unchanger()) != 0 && otmp->cursed))) - return TROUBLE_UNUSEABLE_HANDS; - } - if(Blindfolded && ublindf->cursed) return(TROUBLE_CURSED_BLINDFOLD); + if (Cursed_obj(uarmf, LEVITATION_BOOTS) + || stuck_ring(uleft, RIN_LEVITATION) + || stuck_ring(uright, RIN_LEVITATION)) + return (TROUBLE_CURSED_LEVITATION); + if (nohands(youmonst.data) || !freehand()) { + /* for bag/box access [cf use_container()]... + make sure it's a case that we know how to handle; + otherwise "fix all troubles" would get stuck in a loop */ + if (welded(uwep)) + return TROUBLE_UNUSEABLE_HANDS; + if (Upolyd && nohands(youmonst.data) + && (!Unchanging || ((otmp = unchanger()) != 0 && otmp->cursed))) + return TROUBLE_UNUSEABLE_HANDS; + } + if (Blindfolded && ublindf->cursed) + return (TROUBLE_CURSED_BLINDFOLD); - /* - * minor troubles - */ - if (Punished || (u.utrap && u.utraptype == TT_BURIEDBALL)) - return(TROUBLE_PUNISHED); - if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING) || - Cursed_obj(uarmf, FUMBLE_BOOTS)) - return TROUBLE_FUMBLING; - if (worst_cursed_item()) return TROUBLE_CURSED_ITEMS; - if (u.usteed) { /* can't voluntarily dismount from a cursed saddle */ - otmp = which_armor(u.usteed, W_SADDLE); - if (Cursed_obj(otmp, SADDLE)) return TROUBLE_SADDLE; - } + /* + * minor troubles + */ + if (Punished || (u.utrap && u.utraptype == TT_BURIEDBALL)) + return (TROUBLE_PUNISHED); + if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING) + || Cursed_obj(uarmf, FUMBLE_BOOTS)) + return TROUBLE_FUMBLING; + if (worst_cursed_item()) + return TROUBLE_CURSED_ITEMS; + if (u.usteed) { /* can't voluntarily dismount from a cursed saddle */ + otmp = which_armor(u.usteed, W_SADDLE); + if (Cursed_obj(otmp, SADDLE)) + return TROUBLE_SADDLE; + } - if (Blinded > 1 && haseyes(youmonst.data) && - (!u.uswallow || - !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))) - return(TROUBLE_BLIND); - for(i=0; i= HUNGRY) return TROUBLE_HUNGRY; - if (HStun & TIMEOUT) return TROUBLE_STUNNED; - if (HConfusion & TIMEOUT) return TROUBLE_CONFUSED; - if (HHallucination & TIMEOUT) return TROUBLE_HALLUCINATION; - return(0); + if (Blinded > 1 && haseyes(youmonst.data) + && (!u.uswallow + || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))) + return (TROUBLE_BLIND); + for (i = 0; i < A_MAX; i++) + if (ABASE(i) < AMAX(i)) + return (TROUBLE_POISONED); + if (Wounded_legs && !u.usteed) + return (TROUBLE_WOUNDED_LEGS); + if (u.uhs >= HUNGRY) + return TROUBLE_HUNGRY; + if (HStun & TIMEOUT) + return TROUBLE_STUNNED; + if (HConfusion & TIMEOUT) + return TROUBLE_CONFUSED; + if (HHallucination & TIMEOUT) + return TROUBLE_HALLUCINATION; + return (0); } /* select an item for TROUBLE_CURSED_ITEMS */ @@ -224,51 +258,53 @@ worst_cursed_item() /* if strained or worse, check for loadstone first */ if (near_capacity() >= HVY_ENCUMBER) { - for (otmp = invent; otmp; otmp = otmp->nobj) - if (Cursed_obj(otmp, LOADSTONE)) return otmp; + for (otmp = invent; otmp; otmp = otmp->nobj) + if (Cursed_obj(otmp, LOADSTONE)) + return otmp; } /* weapon takes precedence if it is interfering with taking off a ring or putting on a shield */ - if (welded(uwep) && (uright || bimanual(uwep))) { /* weapon */ - otmp = uwep; - /* gloves come next, due to rings */ - } else if (uarmg && uarmg->cursed) { /* gloves */ - otmp = uarmg; - /* then shield due to two handed weapons and spells */ - } else if (uarms && uarms->cursed) { /* shield */ - otmp = uarms; - /* then cloak due to body armor */ - } else if (uarmc && uarmc->cursed) { /* cloak */ - otmp = uarmc; - } else if (uarm && uarm->cursed) { /* suit */ - otmp = uarm; - } else if (uarmh && uarmh->cursed) { /* helmet */ - otmp = uarmh; - } else if (uarmf && uarmf->cursed) { /* boots */ - otmp = uarmf; - } else if (uarmu && uarmu->cursed) { /* shirt */ - otmp = uarmu; - } else if (uamul && uamul->cursed) { /* amulet */ - otmp = uamul; - } else if (uleft && uleft->cursed) { /* left ring */ - otmp = uleft; - } else if (uright && uright->cursed) { /* right ring */ - otmp = uright; - } else if (ublindf && ublindf->cursed) { /* eyewear */ - otmp = ublindf; /* must be non-blinding lenses */ - /* if weapon wasn't handled above, do it now */ - } else if (welded(uwep)) { /* weapon */ - otmp = uwep; - /* active secondary weapon even though it isn't welded */ + if (welded(uwep) && (uright || bimanual(uwep))) { /* weapon */ + otmp = uwep; + /* gloves come next, due to rings */ + } else if (uarmg && uarmg->cursed) { /* gloves */ + otmp = uarmg; + /* then shield due to two handed weapons and spells */ + } else if (uarms && uarms->cursed) { /* shield */ + otmp = uarms; + /* then cloak due to body armor */ + } else if (uarmc && uarmc->cursed) { /* cloak */ + otmp = uarmc; + } else if (uarm && uarm->cursed) { /* suit */ + otmp = uarm; + } else if (uarmh && uarmh->cursed) { /* helmet */ + otmp = uarmh; + } else if (uarmf && uarmf->cursed) { /* boots */ + otmp = uarmf; + } else if (uarmu && uarmu->cursed) { /* shirt */ + otmp = uarmu; + } else if (uamul && uamul->cursed) { /* amulet */ + otmp = uamul; + } else if (uleft && uleft->cursed) { /* left ring */ + otmp = uleft; + } else if (uright && uright->cursed) { /* right ring */ + otmp = uright; + } else if (ublindf && ublindf->cursed) { /* eyewear */ + otmp = ublindf; /* must be non-blinding lenses */ + /* if weapon wasn't handled above, do it now */ + } else if (welded(uwep)) { /* weapon */ + otmp = uwep; + /* active secondary weapon even though it isn't welded */ } else if (uswapwep && uswapwep->cursed && u.twoweap) { - otmp = uswapwep; - /* all worn items ought to be handled by now */ + otmp = uswapwep; + /* all worn items ought to be handled by now */ } else { - for (otmp = invent; otmp; otmp = otmp->nobj) { - if (!otmp->cursed) continue; - if (otmp->otyp == LOADSTONE || confers_luck(otmp)) - break; - } + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (!otmp->cursed) + continue; + if (otmp->otyp == LOADSTONE || confers_luck(otmp)) + break; + } } return otmp; } @@ -277,208 +313,217 @@ STATIC_OVL void fix_worst_trouble(trouble) register int trouble; { - int i; - struct obj *otmp = 0; - const char *what = (const char *)0; - static NEARDATA const char leftglow[] = "Your left ring softly glows", - rightglow[] = "Your right ring softly glows"; + int i; + struct obj *otmp = 0; + const char *what = (const char *) 0; + static NEARDATA const char leftglow[] = "Your left ring softly glows", + rightglow[] = "Your right ring softly glows"; - switch (trouble) { - case TROUBLE_STONED: - make_stoned(0L, "You feel more limber.", 0, (char *)0); - break; - case TROUBLE_SLIMED: - make_slimed(0L, "The slime disappears."); - break; - case TROUBLE_STRANGLED: - if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) { - Your("amulet vanishes!"); - useup(uamul); - } - You("can breathe again."); - Strangled = 0; - context.botl = 1; - break; - case TROUBLE_LAVA: - You("are back on solid ground."); - /* teleport should always succeed, but if not, - * just untrap them. - */ - if(!safe_teleds(FALSE)) - u.utrap = 0; - break; - case TROUBLE_STARVING: - losestr(-1); - /* fall into... */ - case TROUBLE_HUNGRY: - Your("%s feels content.", body_part(STOMACH)); - init_uhunger(); - context.botl = 1; - break; - case TROUBLE_SICK: - You_feel("better."); - make_sick(0L, (char *) 0, FALSE, SICK_ALL); - break; - case TROUBLE_REGION: - /* stinking cloud, with hero vulnerable to HP loss */ - region_safety(); - break; - case TROUBLE_HIT: - /* "fix all troubles" will keep trying if hero has - 5 or less hit points, so make sure they're always - boosted to be more than that */ - You_feel("much better."); - if (Upolyd) { - u.mhmax += rnd(5); - if (u.mhmax <= 5) u.mhmax = 5+1; - u.mh = u.mhmax; - } - if (u.uhpmax < u.ulevel * 5 + 11) u.uhpmax += rnd(5); - if (u.uhpmax <= 5) u.uhpmax = 5+1; - u.uhp = u.uhpmax; - context.botl = 1; - break; - case TROUBLE_COLLAPSING: - /* override Fixed_abil; uncurse that if feasible */ - You_feel("%sstronger.", - (AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : ""); - ABASE(A_STR) = AMAX(A_STR); - context.botl = 1; - if (Fixed_abil) { - if ((otmp = stuck_ring(uleft, - RIN_SUSTAIN_ABILITY)) != 0) { - if (otmp == uleft) what = leftglow; - } else if ((otmp = stuck_ring(uright, - RIN_SUSTAIN_ABILITY)) != 0) { - if (otmp == uright) what = rightglow; - } - if (otmp) goto decurse; - } - break; - case TROUBLE_STUCK_IN_WALL: - Your("surroundings change."); - /* no control, but works on no-teleport levels */ - (void) safe_teleds(FALSE); - break; - case TROUBLE_CURSED_LEVITATION: - if (Cursed_obj(uarmf, LEVITATION_BOOTS)) { - otmp = uarmf; - } else if ((otmp = stuck_ring(uleft,RIN_LEVITATION)) !=0) { - if (otmp == uleft) what = leftglow; - } else if ((otmp = stuck_ring(uright,RIN_LEVITATION))!=0) { - if (otmp == uright) what = rightglow; - } - goto decurse; - case TROUBLE_UNUSEABLE_HANDS: - if (welded(uwep)) { - otmp = uwep; - goto decurse; - } - if (Upolyd && nohands(youmonst.data)) { - if (!Unchanging) { - Your("shape becomes uncertain."); - rehumanize(); /* "You return to {normal} form." */ - } else if ((otmp = unchanger()) != 0 && otmp->cursed) { - /* otmp is an amulet of unchanging */ - goto decurse; - } - } - if (nohands(youmonst.data) || !freehand()) - impossible("fix_worst_trouble: couldn't cure hands."); - break; - case TROUBLE_CURSED_BLINDFOLD: - otmp = ublindf; - goto decurse; - case TROUBLE_LYCANTHROPE: - you_unwere(TRUE); - break; - /* - */ - case TROUBLE_PUNISHED: - Your("chain disappears."); - if(u.utrap && u.utraptype == TT_BURIEDBALL) - buried_ball_to_freedom(); - else - unpunish(); - break; - case TROUBLE_FUMBLING: - if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING)) - otmp = uarmg; - else if (Cursed_obj(uarmf, FUMBLE_BOOTS)) - otmp = uarmf; - goto decurse; - /*NOTREACHED*/ - break; - case TROUBLE_CURSED_ITEMS: - otmp = worst_cursed_item(); - if (otmp == uright) what = rightglow; - else if (otmp == uleft) what = leftglow; -decurse: - if (!otmp) { - impossible("fix_worst_trouble: nothing to uncurse."); - return; - } - if (!Blind || (otmp == ublindf && Blindfolded_only)) { - pline("%s %s.", what ? what : - (const char *)Yobjnam2(otmp, "softly glow"), - hcolor(NH_AMBER)); - iflags.last_msg = PLNMSG_OBJ_GLOWS; - otmp->bknown = TRUE; - } - uncurse(otmp); - update_inventory(); - break; - case TROUBLE_POISONED: - /* override Fixed_abil; ignore items which confer that */ - if (Hallucination) - pline("There's a tiger in your tank."); - else - You_feel("in good health again."); - for (i = 0; i < A_MAX; i++) { - if(ABASE(i) < AMAX(i)) { - ABASE(i) = AMAX(i); - context.botl = 1; - } - } - (void) encumber_msg(); - break; - case TROUBLE_BLIND: - { - const char *eyes = body_part(EYE); + switch (trouble) { + case TROUBLE_STONED: + make_stoned(0L, "You feel more limber.", 0, (char *) 0); + break; + case TROUBLE_SLIMED: + make_slimed(0L, "The slime disappears."); + break; + case TROUBLE_STRANGLED: + if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) { + Your("amulet vanishes!"); + useup(uamul); + } + You("can breathe again."); + Strangled = 0; + context.botl = 1; + break; + case TROUBLE_LAVA: + You("are back on solid ground."); + /* teleport should always succeed, but if not, + * just untrap them. + */ + if (!safe_teleds(FALSE)) + u.utrap = 0; + break; + case TROUBLE_STARVING: + losestr(-1); + /* fall into... */ + case TROUBLE_HUNGRY: + Your("%s feels content.", body_part(STOMACH)); + init_uhunger(); + context.botl = 1; + break; + case TROUBLE_SICK: + You_feel("better."); + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + break; + case TROUBLE_REGION: + /* stinking cloud, with hero vulnerable to HP loss */ + region_safety(); + break; + case TROUBLE_HIT: + /* "fix all troubles" will keep trying if hero has + 5 or less hit points, so make sure they're always + boosted to be more than that */ + You_feel("much better."); + if (Upolyd) { + u.mhmax += rnd(5); + if (u.mhmax <= 5) + u.mhmax = 5 + 1; + u.mh = u.mhmax; + } + if (u.uhpmax < u.ulevel * 5 + 11) + u.uhpmax += rnd(5); + if (u.uhpmax <= 5) + u.uhpmax = 5 + 1; + u.uhp = u.uhpmax; + context.botl = 1; + break; + case TROUBLE_COLLAPSING: + /* override Fixed_abil; uncurse that if feasible */ + You_feel("%sstronger.", + (AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : ""); + ABASE(A_STR) = AMAX(A_STR); + context.botl = 1; + if (Fixed_abil) { + if ((otmp = stuck_ring(uleft, RIN_SUSTAIN_ABILITY)) != 0) { + if (otmp == uleft) + what = leftglow; + } else if ((otmp = stuck_ring(uright, RIN_SUSTAIN_ABILITY)) + != 0) { + if (otmp == uright) + what = rightglow; + } + if (otmp) + goto decurse; + } + break; + case TROUBLE_STUCK_IN_WALL: + Your("surroundings change."); + /* no control, but works on no-teleport levels */ + (void) safe_teleds(FALSE); + break; + case TROUBLE_CURSED_LEVITATION: + if (Cursed_obj(uarmf, LEVITATION_BOOTS)) { + otmp = uarmf; + } else if ((otmp = stuck_ring(uleft, RIN_LEVITATION)) != 0) { + if (otmp == uleft) + what = leftglow; + } else if ((otmp = stuck_ring(uright, RIN_LEVITATION)) != 0) { + if (otmp == uright) + what = rightglow; + } + goto decurse; + case TROUBLE_UNUSEABLE_HANDS: + if (welded(uwep)) { + otmp = uwep; + goto decurse; + } + if (Upolyd && nohands(youmonst.data)) { + if (!Unchanging) { + Your("shape becomes uncertain."); + rehumanize(); /* "You return to {normal} form." */ + } else if ((otmp = unchanger()) != 0 && otmp->cursed) { + /* otmp is an amulet of unchanging */ + goto decurse; + } + } + if (nohands(youmonst.data) || !freehand()) + impossible("fix_worst_trouble: couldn't cure hands."); + break; + case TROUBLE_CURSED_BLINDFOLD: + otmp = ublindf; + goto decurse; + case TROUBLE_LYCANTHROPE: + you_unwere(TRUE); + break; + /* + */ + case TROUBLE_PUNISHED: + Your("chain disappears."); + if (u.utrap && u.utraptype == TT_BURIEDBALL) + buried_ball_to_freedom(); + else + unpunish(); + break; + case TROUBLE_FUMBLING: + if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING)) + otmp = uarmg; + else if (Cursed_obj(uarmf, FUMBLE_BOOTS)) + otmp = uarmf; + goto decurse; + /*NOTREACHED*/ + break; + case TROUBLE_CURSED_ITEMS: + otmp = worst_cursed_item(); + if (otmp == uright) + what = rightglow; + else if (otmp == uleft) + what = leftglow; + decurse: + if (!otmp) { + impossible("fix_worst_trouble: nothing to uncurse."); + return; + } + if (!Blind || (otmp == ublindf && Blindfolded_only)) { + pline("%s %s.", + what ? what : (const char *) Yobjnam2(otmp, "softly glow"), + hcolor(NH_AMBER)); + iflags.last_msg = PLNMSG_OBJ_GLOWS; + otmp->bknown = TRUE; + } + uncurse(otmp); + update_inventory(); + break; + case TROUBLE_POISONED: + /* override Fixed_abil; ignore items which confer that */ + if (Hallucination) + pline("There's a tiger in your tank."); + else + You_feel("in good health again."); + for (i = 0; i < A_MAX; i++) { + if (ABASE(i) < AMAX(i)) { + ABASE(i) = AMAX(i); + context.botl = 1; + } + } + (void) encumber_msg(); + break; + case TROUBLE_BLIND: { + const char *eyes = body_part(EYE); - if (eyecount(youmonst.data) != 1) eyes = makeplural(eyes); - Your("%s %s better.", eyes, vtense(eyes, "feel")); - u.ucreamed = 0; - make_blinded(0L,FALSE); - break; - } - case TROUBLE_WOUNDED_LEGS: - heal_legs(); - break; - case TROUBLE_STUNNED: - make_stunned(0L,TRUE); - break; - case TROUBLE_CONFUSED: - make_confused(0L,TRUE); - break; - case TROUBLE_HALLUCINATION: - pline ("Looks like you are back in Kansas."); - (void) make_hallucinated(0L,FALSE,0L); - break; - case TROUBLE_SADDLE: - otmp = which_armor(u.usteed, W_SADDLE); - if (!Blind) { - pline("%s %s.", Yobjnam2(otmp, "softly glow"), - hcolor(NH_AMBER)); - otmp->bknown = TRUE; - } - uncurse(otmp); - break; - } + if (eyecount(youmonst.data) != 1) + eyes = makeplural(eyes); + Your("%s %s better.", eyes, vtense(eyes, "feel")); + u.ucreamed = 0; + make_blinded(0L, FALSE); + break; + } + case TROUBLE_WOUNDED_LEGS: + heal_legs(); + break; + case TROUBLE_STUNNED: + make_stunned(0L, TRUE); + break; + case TROUBLE_CONFUSED: + make_confused(0L, TRUE); + break; + case TROUBLE_HALLUCINATION: + pline("Looks like you are back in Kansas."); + (void) make_hallucinated(0L, FALSE, 0L); + break; + case TROUBLE_SADDLE: + otmp = which_armor(u.usteed, W_SADDLE); + if (!Blind) { + pline("%s %s.", Yobjnam2(otmp, "softly glow"), hcolor(NH_AMBER)); + otmp->bknown = TRUE; + } + uncurse(otmp); + break; + } } /* "I am sometimes shocked by... the nuns who never take a bath without - * wearing a bathrobe all the time. When asked why, since no man can see them, + * wearing a bathrobe all the time. When asked why, since no man can see + * them, * they reply 'Oh, but you forget the good God'. Apparently they conceive of * the Deity as a Peeping Tom, whose omnipotence enables Him to see through * bathroom walls, but who is foiled by bathrobes." --Bertrand Russell, 1943 @@ -488,73 +533,74 @@ STATIC_OVL void god_zaps_you(resp_god) aligntyp resp_god; { - if (u.uswallow) { - pline("Suddenly a bolt of lightning comes down at you from the heavens!"); - pline("It strikes %s!", mon_nam(u.ustuck)); - if (!resists_elec(u.ustuck)) { - pline("%s fries to a crisp!", Monnam(u.ustuck)); - /* Yup, you get experience. It takes guts to successfully - * pull off this trick on your god, anyway. - */ - xkilled(u.ustuck, 0); - } else - pline("%s seems unaffected.", Monnam(u.ustuck)); - } else { - pline("Suddenly, a bolt of lightning strikes you!"); - if (Reflecting) { - shieldeff(u.ux, u.uy); - if (Blind) - pline("For some reason you're unaffected."); - else - (void) ureflects("%s reflects from your %s.", "It"); - } else if (Shock_resistance) { - shieldeff(u.ux, u.uy); - pline("It seems not to affect you."); - } else - fry_by_god(resp_god, FALSE); - } + if (u.uswallow) { + pline("Suddenly a bolt of lightning comes down at you from the " + "heavens!"); + pline("It strikes %s!", mon_nam(u.ustuck)); + if (!resists_elec(u.ustuck)) { + pline("%s fries to a crisp!", Monnam(u.ustuck)); + /* Yup, you get experience. It takes guts to successfully + * pull off this trick on your god, anyway. + */ + xkilled(u.ustuck, 0); + } else + pline("%s seems unaffected.", Monnam(u.ustuck)); + } else { + pline("Suddenly, a bolt of lightning strikes you!"); + if (Reflecting) { + shieldeff(u.ux, u.uy); + if (Blind) + pline("For some reason you're unaffected."); + else + (void) ureflects("%s reflects from your %s.", "It"); + } else if (Shock_resistance) { + shieldeff(u.ux, u.uy); + pline("It seems not to affect you."); + } else + fry_by_god(resp_god, FALSE); + } - pline("%s is not deterred...", align_gname(resp_god)); - if (u.uswallow) { - pline("A wide-angle disintegration beam aimed at you hits %s!", - mon_nam(u.ustuck)); - if (!resists_disint(u.ustuck)) { - pline("%s disintegrates into a pile of dust!", - Monnam(u.ustuck)); - xkilled(u.ustuck, 2); /* no corpse */ - } else - pline("%s seems unaffected.", Monnam(u.ustuck)); - } else { - pline("A wide-angle disintegration beam hits you!"); + pline("%s is not deterred...", align_gname(resp_god)); + if (u.uswallow) { + pline("A wide-angle disintegration beam aimed at you hits %s!", + mon_nam(u.ustuck)); + if (!resists_disint(u.ustuck)) { + pline("%s disintegrates into a pile of dust!", Monnam(u.ustuck)); + xkilled(u.ustuck, 2); /* no corpse */ + } else + pline("%s seems unaffected.", Monnam(u.ustuck)); + } else { + pline("A wide-angle disintegration beam hits you!"); - /* disintegrate shield and body armor before disintegrating - * the impudent mortal, like black dragon breath -3. - */ - if (uarms && !(EReflecting & W_ARMS) && - !(EDisint_resistance & W_ARMS)) - (void) destroy_arm(uarms); - if (uarmc && !(EReflecting & W_ARMC) && - !(EDisint_resistance & W_ARMC)) - (void) destroy_arm(uarmc); - if (uarm && !(EReflecting & W_ARM) && - !(EDisint_resistance & W_ARM) && !uarmc) - (void) destroy_arm(uarm); - if (uarmu && !uarm && !uarmc) (void) destroy_arm(uarmu); - if (!Disint_resistance) - fry_by_god(resp_god, TRUE); - else { - You("bask in its %s glow for a minute...", NH_BLACK); - godvoice(resp_god, "I believe it not!"); - } - if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) { - /* one more try for high altars */ - verbalize("Thou cannot escape my wrath, mortal!"); - summon_minion(resp_god, FALSE); - summon_minion(resp_god, FALSE); - summon_minion(resp_god, FALSE); - verbalize("Destroy %s, my servants!", uhim()); - } - } + /* disintegrate shield and body armor before disintegrating + * the impudent mortal, like black dragon breath -3. + */ + if (uarms && !(EReflecting & W_ARMS) + && !(EDisint_resistance & W_ARMS)) + (void) destroy_arm(uarms); + if (uarmc && !(EReflecting & W_ARMC) + && !(EDisint_resistance & W_ARMC)) + (void) destroy_arm(uarmc); + if (uarm && !(EReflecting & W_ARM) && !(EDisint_resistance & W_ARM) + && !uarmc) + (void) destroy_arm(uarm); + if (uarmu && !uarm && !uarmc) + (void) destroy_arm(uarmu); + if (!Disint_resistance) + fry_by_god(resp_god, TRUE); + else { + You("bask in its %s glow for a minute...", NH_BLACK); + godvoice(resp_god, "I believe it not!"); + } + if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) { + /* one more try for high altars */ + verbalize("Thou cannot escape my wrath, mortal!"); + summon_minion(resp_god, FALSE); + summon_minion(resp_god, FALSE); + summon_minion(resp_god, FALSE); + verbalize("Destroy %s, my servants!", uhim()); + } + } } STATIC_OVL void @@ -562,96 +608,104 @@ fry_by_god(resp_god, via_disintegration) aligntyp resp_god; boolean via_disintegration; { - You("%s!", !via_disintegration ? "fry to a crisp" : - "disintegrate into a pile of dust"); - killer.format = KILLED_BY; - Sprintf(killer.name, "the wrath of %s", align_gname(resp_god)); - done(DIED); + You("%s!", !via_disintegration ? "fry to a crisp" + : "disintegrate into a pile of dust"); + killer.format = KILLED_BY; + Sprintf(killer.name, "the wrath of %s", align_gname(resp_god)); + done(DIED); } STATIC_OVL void angrygods(resp_god) aligntyp resp_god; { - register int maxanger; + register int maxanger; - if(Inhell) resp_god = A_NONE; - u.ublessed = 0; + if (Inhell) + resp_god = A_NONE; + u.ublessed = 0; - /* changed from tmp = u.ugangr + abs (u.uluck) -- rph */ - /* added test for alignment diff -dlc */ - if(resp_god != u.ualign.type) - maxanger = u.ualign.record/2 + (Luck > 0 ? -Luck/3 : -Luck); - else - maxanger = 3*u.ugangr + - ((Luck > 0 || u.ualign.record >= STRIDENT) ? -Luck/3 : -Luck); - if (maxanger < 1) maxanger = 1; /* possible if bad align & good luck */ - else if (maxanger > 15) maxanger = 15; /* be reasonable */ + /* changed from tmp = u.ugangr + abs (u.uluck) -- rph */ + /* added test for alignment diff -dlc */ + if (resp_god != u.ualign.type) + maxanger = u.ualign.record / 2 + (Luck > 0 ? -Luck / 3 : -Luck); + else + maxanger = + 3 * u.ugangr + + ((Luck > 0 || u.ualign.record >= STRIDENT) ? -Luck / 3 : -Luck); + if (maxanger < 1) + maxanger = 1; /* possible if bad align & good luck */ + else if (maxanger > 15) + maxanger = 15; /* be reasonable */ - switch (rn2(maxanger)) { - case 0: - case 1: You_feel("that %s is %s.", align_gname(resp_god), - Hallucination ? "bummed" : "displeased"); - break; - case 2: - case 3: - godvoice(resp_god,(char *)0); - pline("\"Thou %s, %s.\"", - (ugod_is_angry() && resp_god == u.ualign.type) - ? "hast strayed from the path" : - "art arrogant", - youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); - verbalize("Thou must relearn thy lessons!"); - (void) adjattrib(A_WIS, -1, FALSE); - losexp((char *)0); - break; - case 6: if (!Punished) { - gods_angry(resp_god); - punish((struct obj *)0); - break; - } /* else fall thru */ - case 4: - case 5: gods_angry(resp_god); - if (!Blind && !Antimagic) - pline("%s glow surrounds you.", - An(hcolor(NH_BLACK))); - rndcurse(); - break; - case 7: - case 8: godvoice(resp_god,(char *)0); - verbalize("Thou durst %s me?", - (on_altar() && - (a_align(u.ux,u.uy) != resp_god)) ? - "scorn":"call upon"); - pline("\"Then die, %s!\"", - youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); - summon_minion(resp_god, FALSE); - break; + switch (rn2(maxanger)) { + case 0: + case 1: + You_feel("that %s is %s.", align_gname(resp_god), + Hallucination ? "bummed" : "displeased"); + break; + case 2: + case 3: + godvoice(resp_god, (char *) 0); + pline("\"Thou %s, %s.\"", + (ugod_is_angry() && resp_god == u.ualign.type) + ? "hast strayed from the path" + : "art arrogant", + youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); + verbalize("Thou must relearn thy lessons!"); + (void) adjattrib(A_WIS, -1, FALSE); + losexp((char *) 0); + break; + case 6: + if (!Punished) { + gods_angry(resp_god); + punish((struct obj *) 0); + break; + } /* else fall thru */ + case 4: + case 5: + gods_angry(resp_god); + if (!Blind && !Antimagic) + pline("%s glow surrounds you.", An(hcolor(NH_BLACK))); + rndcurse(); + break; + case 7: + case 8: + godvoice(resp_god, (char *) 0); + verbalize("Thou durst %s me?", + (on_altar() && (a_align(u.ux, u.uy) != resp_god)) + ? "scorn" + : "call upon"); + pline("\"Then die, %s!\"", + youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); + summon_minion(resp_god, FALSE); + break; - default: gods_angry(resp_god); - god_zaps_you(resp_god); - break; - } - u.ublesscnt = rnz(300); - return; + default: + gods_angry(resp_god); + god_zaps_you(resp_god); + break; + } + u.ublesscnt = rnz(300); + return; } /* helper to print "str appears at your feet", or appropriate */ static void at_your_feet(str) - const char *str; +const char *str; { - if (Blind) str = Something; - if (u.uswallow) { - /* barrier between you and the floor */ - pline("%s %s into %s %s.", str, vtense(str, "drop"), - s_suffix(mon_nam(u.ustuck)), mbodypart(u.ustuck, STOMACH)); - } else { - pline("%s %s %s your %s!", str, - Blind ? "lands" : vtense(str, "appear"), - Levitation ? "beneath" : "at", - makeplural(body_part(FOOT))); - } + if (Blind) + str = Something; + if (u.uswallow) { + /* barrier between you and the floor */ + pline("%s %s into %s %s.", str, vtense(str, "drop"), + s_suffix(mon_nam(u.ustuck)), mbodypart(u.ustuck, STOMACH)); + } else { + pline("%s %s %s your %s!", str, + Blind ? "lands" : vtense(str, "appear"), + Levitation ? "beneath" : "at", makeplural(body_part(FOOT))); + } } STATIC_OVL void @@ -669,134 +723,138 @@ gcrownu() HShock_resistance |= FROMOUTSIDE; HSleep_resistance |= FROMOUTSIDE; HPoison_resistance |= FROMOUTSIDE; - godvoice(u.ualign.type, (char *)0); + godvoice(u.ualign.type, (char *) 0); obj = ok_wep(uwep) ? uwep : 0; - already_exists = in_hand = FALSE; /* lint suppression */ + already_exists = in_hand = FALSE; /* lint suppression */ switch (u.ualign.type) { case A_LAWFUL: - u.uevent.uhand_of_elbereth = 1; - verbalize("I crown thee... The Hand of Elbereth!"); - break; + u.uevent.uhand_of_elbereth = 1; + verbalize("I crown thee... The Hand of Elbereth!"); + break; case A_NEUTRAL: - u.uevent.uhand_of_elbereth = 2; - in_hand = (uwep && uwep->oartifact == ART_VORPAL_BLADE); - already_exists = exist_artifact(LONG_SWORD, artiname(ART_VORPAL_BLADE)); - verbalize("Thou shalt be my Envoy of Balance!"); - break; + u.uevent.uhand_of_elbereth = 2; + in_hand = (uwep && uwep->oartifact == ART_VORPAL_BLADE); + already_exists = + exist_artifact(LONG_SWORD, artiname(ART_VORPAL_BLADE)); + verbalize("Thou shalt be my Envoy of Balance!"); + break; case A_CHAOTIC: - u.uevent.uhand_of_elbereth = 3; - in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER); - already_exists = exist_artifact(RUNESWORD, artiname(ART_STORMBRINGER)); - verbalize("Thou art chosen to %s for My Glory!", - already_exists && !in_hand ? "take lives" : "steal souls"); - break; + u.uevent.uhand_of_elbereth = 3; + in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER); + already_exists = + exist_artifact(RUNESWORD, artiname(ART_STORMBRINGER)); + verbalize("Thou art chosen to %s for My Glory!", + already_exists && !in_hand ? "take lives" : "steal souls"); + break; } class_gift = STRANGE_OBJECT; /* 3.3.[01] had this in the A_NEUTRAL case below, preventing chaotic wizards from receiving a spellbook */ - if (Role_if(PM_WIZARD) && - (!uwep || (uwep->oartifact != ART_VORPAL_BLADE && - uwep->oartifact != ART_STORMBRINGER)) && - !carrying(SPE_FINGER_OF_DEATH)) { - class_gift = SPE_FINGER_OF_DEATH; - make_splbk: - obj = mksobj(class_gift, TRUE, FALSE); - bless(obj); - obj->bknown = TRUE; - at_your_feet("A spellbook"); - dropy(obj); - u.ugifts++; - /* when getting a new book for known spell, enhance - currently wielded weapon rather than the book */ - for (sp_no = 0; sp_no < MAXSPELL; sp_no++) - if (spl_book[sp_no].sp_id == class_gift) { - if (ok_wep(uwep)) obj = uwep; /* to be blessed,&c */ - break; - } - } else if (Role_if(PM_MONK) && - (!uwep || !uwep->oartifact) && - !carrying(SPE_RESTORE_ABILITY)) { - /* monks rarely wield a weapon */ - class_gift = SPE_RESTORE_ABILITY; - goto make_splbk; + if (Role_if(PM_WIZARD) + && (!uwep || (uwep->oartifact != ART_VORPAL_BLADE + && uwep->oartifact != ART_STORMBRINGER)) + && !carrying(SPE_FINGER_OF_DEATH)) { + class_gift = SPE_FINGER_OF_DEATH; + make_splbk: + obj = mksobj(class_gift, TRUE, FALSE); + bless(obj); + obj->bknown = TRUE; + at_your_feet("A spellbook"); + dropy(obj); + u.ugifts++; + /* when getting a new book for known spell, enhance + currently wielded weapon rather than the book */ + for (sp_no = 0; sp_no < MAXSPELL; sp_no++) + if (spl_book[sp_no].sp_id == class_gift) { + if (ok_wep(uwep)) + obj = uwep; /* to be blessed,&c */ + break; + } + } else if (Role_if(PM_MONK) && (!uwep || !uwep->oartifact) + && !carrying(SPE_RESTORE_ABILITY)) { + /* monks rarely wield a weapon */ + class_gift = SPE_RESTORE_ABILITY; + goto make_splbk; } switch (u.ualign.type) { case A_LAWFUL: - if (class_gift != STRANGE_OBJECT) { - ; /* already got bonus above */ - } else if (obj && obj->otyp == LONG_SWORD && !obj->oartifact) { - if (!Blind) Your("sword shines brightly for a moment."); - obj = oname(obj, artiname(ART_EXCALIBUR)); - if (obj && obj->oartifact == ART_EXCALIBUR) u.ugifts++; - } - /* acquire Excalibur's skill regardless of weapon or gift */ - unrestrict_weapon_skill(P_LONG_SWORD); - if (obj && obj->oartifact == ART_EXCALIBUR) - discover_artifact(ART_EXCALIBUR); - break; + if (class_gift != STRANGE_OBJECT) { + ; /* already got bonus above */ + } else if (obj && obj->otyp == LONG_SWORD && !obj->oartifact) { + if (!Blind) + Your("sword shines brightly for a moment."); + obj = oname(obj, artiname(ART_EXCALIBUR)); + if (obj && obj->oartifact == ART_EXCALIBUR) + u.ugifts++; + } + /* acquire Excalibur's skill regardless of weapon or gift */ + unrestrict_weapon_skill(P_LONG_SWORD); + if (obj && obj->oartifact == ART_EXCALIBUR) + discover_artifact(ART_EXCALIBUR); + break; case A_NEUTRAL: - if (class_gift != STRANGE_OBJECT) { - ; /* already got bonus above */ - } else if (in_hand) { - Your("%s goes snicker-snack!", xname(obj)); - obj->dknown = TRUE; - } else if (!already_exists) { - obj = mksobj(LONG_SWORD, FALSE, FALSE); - obj = oname(obj, artiname(ART_VORPAL_BLADE)); - obj->spe = 1; - at_your_feet("A sword"); - dropy(obj); - u.ugifts++; - } - /* acquire Vorpal Blade's skill regardless of weapon or gift */ - unrestrict_weapon_skill(P_LONG_SWORD); - if (obj && obj->oartifact == ART_VORPAL_BLADE) - discover_artifact(ART_VORPAL_BLADE); - break; - case A_CHAOTIC: - { - char swordbuf[BUFSZ]; + if (class_gift != STRANGE_OBJECT) { + ; /* already got bonus above */ + } else if (in_hand) { + Your("%s goes snicker-snack!", xname(obj)); + obj->dknown = TRUE; + } else if (!already_exists) { + obj = mksobj(LONG_SWORD, FALSE, FALSE); + obj = oname(obj, artiname(ART_VORPAL_BLADE)); + obj->spe = 1; + at_your_feet("A sword"); + dropy(obj); + u.ugifts++; + } + /* acquire Vorpal Blade's skill regardless of weapon or gift */ + unrestrict_weapon_skill(P_LONG_SWORD); + if (obj && obj->oartifact == ART_VORPAL_BLADE) + discover_artifact(ART_VORPAL_BLADE); + break; + case A_CHAOTIC: { + char swordbuf[BUFSZ]; - Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK)); - if (class_gift != STRANGE_OBJECT) { - ; /* already got bonus above */ - } else if (in_hand) { - Your("%s hums ominously!", swordbuf); - obj->dknown = TRUE; - } else if (!already_exists) { - obj = mksobj(RUNESWORD, FALSE, FALSE); - obj = oname(obj, artiname(ART_STORMBRINGER)); - obj->spe = 1; - at_your_feet(An(swordbuf)); - dropy(obj); - u.ugifts++; - } - /* acquire Stormbringer's skill regardless of weapon or gift */ - unrestrict_weapon_skill(P_BROAD_SWORD); - if (obj && obj->oartifact == ART_STORMBRINGER) - discover_artifact(ART_STORMBRINGER); - break; - } + Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK)); + if (class_gift != STRANGE_OBJECT) { + ; /* already got bonus above */ + } else if (in_hand) { + Your("%s hums ominously!", swordbuf); + obj->dknown = TRUE; + } else if (!already_exists) { + obj = mksobj(RUNESWORD, FALSE, FALSE); + obj = oname(obj, artiname(ART_STORMBRINGER)); + obj->spe = 1; + at_your_feet(An(swordbuf)); + dropy(obj); + u.ugifts++; + } + /* acquire Stormbringer's skill regardless of weapon or gift */ + unrestrict_weapon_skill(P_BROAD_SWORD); + if (obj && obj->oartifact == ART_STORMBRINGER) + discover_artifact(ART_STORMBRINGER); + break; + } default: - obj = 0; /* lint */ - break; + obj = 0; /* lint */ + break; } /* enhance weapon regardless of alignment or artifact status */ if (ok_wep(obj)) { - bless(obj); - obj->oeroded = obj->oeroded2 = 0; - obj->oerodeproof = TRUE; - obj->bknown = obj->rknown = TRUE; - if (obj->spe < 1) obj->spe = 1; - /* acquire skill in this weapon */ - unrestrict_weapon_skill(weapon_type(obj)); + bless(obj); + obj->oeroded = obj->oeroded2 = 0; + obj->oerodeproof = TRUE; + obj->bknown = obj->rknown = TRUE; + if (obj->spe < 1) + obj->spe = 1; + /* acquire skill in this weapon */ + unrestrict_weapon_skill(weapon_type(obj)); } else if (class_gift == STRANGE_OBJECT) { - /* opportunity knocked, but there was nobody home... */ - You_feel("unworthy."); + /* opportunity knocked, but there was nobody home... */ + You_feel("unworthy."); } update_inventory(); @@ -808,264 +866,292 @@ gcrownu() STATIC_OVL void pleased(g_align) - aligntyp g_align; +aligntyp g_align; { - /* don't use p_trouble, worst trouble may get fixed while praying */ - int trouble = in_trouble(); /* what's your worst difficulty? */ - int pat_on_head = 0, kick_on_butt; + /* don't use p_trouble, worst trouble may get fixed while praying */ + int trouble = in_trouble(); /* what's your worst difficulty? */ + int pat_on_head = 0, kick_on_butt; - You_feel("that %s is %s.", align_gname(g_align), - u.ualign.record >= DEVOUT ? - Hallucination ? "pleased as punch" : "well-pleased" : - u.ualign.record >= STRIDENT ? - Hallucination ? "ticklish" : "pleased" : - Hallucination ? "full" : "satisfied"); + You_feel("that %s is %s.", align_gname(g_align), + u.ualign.record >= DEVOUT + ? Hallucination ? "pleased as punch" : "well-pleased" + : u.ualign.record >= STRIDENT + ? Hallucination ? "ticklish" : "pleased" + : Hallucination ? "full" : "satisfied"); - /* not your deity */ - if (on_altar() && p_aligntyp != u.ualign.type) { - adjalign(-1); - return; - } else if (u.ualign.record < 2 && trouble <= 0) adjalign(1); + /* not your deity */ + if (on_altar() && p_aligntyp != u.ualign.type) { + adjalign(-1); + return; + } else if (u.ualign.record < 2 && trouble <= 0) + adjalign(1); - /* depending on your luck & align level, the god you prayed to will: - - fix your worst problem if it's major. - - fix all your major problems. - - fix your worst problem if it's minor. - - fix all of your problems. - - do you a gratuitous favor. + /* depending on your luck & align level, the god you prayed to will: + - fix your worst problem if it's major. + - fix all your major problems. + - fix your worst problem if it's minor. + - fix all of your problems. + - do you a gratuitous favor. - if you make it to the the last category, you roll randomly again - to see what they do for you. + if you make it to the the last category, you roll randomly again + to see what they do for you. - If your luck is at least 0, then you are guaranteed rescued - from your worst major problem. */ + If your luck is at least 0, then you are guaranteed rescued + from your worst major problem. */ - if (!trouble && u.ualign.record >= DEVOUT) { - /* if hero was in trouble, but got better, no special favor */ - if (p_trouble == 0) pat_on_head = 1; - } else { - int action, prayer_luck; + if (!trouble && u.ualign.record >= DEVOUT) { + /* if hero was in trouble, but got better, no special favor */ + if (p_trouble == 0) + pat_on_head = 1; + } else { + int action, prayer_luck; - /* Negative luck is normally impossible here (can_pray() forces - prayer failure in that situation), but it's possible for - Luck to drop during the period of prayer occupation and - become negative by the time we get here. [Reported case - was lawful character whose stinking cloud caused a delayed - killing of a peaceful human, triggering the "murderer" - penalty while successful prayer was in progress. It could - also happen due to inconvenient timing on Friday 13th, but - the magnitude there (-1) isn't big enough to cause trouble.] - We don't bother remembering start-of-prayer luck, just make - sure it's at least -1 so that Luck+2 is big enough to avoid - a divide by zero crash when generating a random number. */ - prayer_luck = max(Luck, -1); /* => (prayer_luck + 2 > 0) */ - action = rn1(prayer_luck + (on_altar() ? 3 + on_shrine() : 2), 1); - if (!on_altar()) action = min(action, 3); - if (u.ualign.record < STRIDENT) - action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0; + /* Negative luck is normally impossible here (can_pray() forces + prayer failure in that situation), but it's possible for + Luck to drop during the period of prayer occupation and + become negative by the time we get here. [Reported case + was lawful character whose stinking cloud caused a delayed + killing of a peaceful human, triggering the "murderer" + penalty while successful prayer was in progress. It could + also happen due to inconvenient timing on Friday 13th, but + the magnitude there (-1) isn't big enough to cause trouble.] + We don't bother remembering start-of-prayer luck, just make + sure it's at least -1 so that Luck+2 is big enough to avoid + a divide by zero crash when generating a random number. */ + prayer_luck = max(Luck, -1); /* => (prayer_luck + 2 > 0) */ + action = rn1(prayer_luck + (on_altar() ? 3 + on_shrine() : 2), 1); + if (!on_altar()) + action = min(action, 3); + if (u.ualign.record < STRIDENT) + action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0; - switch(min(action,5)) { - case 5: pat_on_head = 1; - case 4: do fix_worst_trouble(trouble); - while ((trouble = in_trouble()) != 0); - break; + switch (min(action, 5)) { + case 5: + pat_on_head = 1; + case 4: + do + fix_worst_trouble(trouble); + while ((trouble = in_trouble()) != 0); + break; - case 3: fix_worst_trouble(trouble); - case 2: while ((trouble = in_trouble()) > 0) - fix_worst_trouble(trouble); - break; + case 3: + fix_worst_trouble(trouble); + case 2: + while ((trouble = in_trouble()) > 0) + fix_worst_trouble(trouble); + break; - case 1: if (trouble > 0) fix_worst_trouble(trouble); - case 0: break; /* your god blows you off, too bad */ - } - } + case 1: + if (trouble > 0) + fix_worst_trouble(trouble); + case 0: + break; /* your god blows you off, too bad */ + } + } /* note: can't get pat_on_head unless all troubles have just been fixed or there were no troubles to begin with; hallucination won't be in effect so special handling for it is superfluous */ - if(pat_on_head) - switch(rn2((Luck + 6)>>1)) { - case 0: break; - case 1: - if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS || - is_weptool(uwep))) { - char repair_buf[BUFSZ]; + if (pat_on_head) + switch (rn2((Luck + 6) >> 1)) { + case 0: + break; + case 1: + if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS + || is_weptool(uwep))) { + char repair_buf[BUFSZ]; - *repair_buf = '\0'; - if (uwep->oeroded || uwep->oeroded2) - Sprintf(repair_buf, " and %s now as good as new", - otense(uwep, "are")); + *repair_buf = '\0'; + if (uwep->oeroded || uwep->oeroded2) + Sprintf(repair_buf, " and %s now as good as new", + otense(uwep, "are")); - if (uwep->cursed) { - if (!Blind) { - pline("%s %s%s.", Yobjnam2(uwep, "softly glow"), - hcolor(NH_AMBER), repair_buf); - iflags.last_msg = PLNMSG_OBJ_GLOWS; - } else - You_feel("the power of %s over %s.", - u_gname(), yname(uwep)); - uncurse(uwep); - uwep->bknown = TRUE; - *repair_buf = '\0'; - } else if (!uwep->blessed) { - if (!Blind) { - pline("%s with %s aura%s.", - Yobjnam2(uwep, "softly glow"), - an(hcolor(NH_LIGHT_BLUE)), repair_buf); - iflags.last_msg = PLNMSG_OBJ_GLOWS; - } else - You_feel("the blessing of %s over %s.", - u_gname(), yname(uwep)); - bless(uwep); - uwep->bknown = TRUE; - *repair_buf = '\0'; - } + if (uwep->cursed) { + if (!Blind) { + pline("%s %s%s.", Yobjnam2(uwep, "softly glow"), + hcolor(NH_AMBER), repair_buf); + iflags.last_msg = PLNMSG_OBJ_GLOWS; + } else + You_feel("the power of %s over %s.", u_gname(), + yname(uwep)); + uncurse(uwep); + uwep->bknown = TRUE; + *repair_buf = '\0'; + } else if (!uwep->blessed) { + if (!Blind) { + pline("%s with %s aura%s.", + Yobjnam2(uwep, "softly glow"), + an(hcolor(NH_LIGHT_BLUE)), repair_buf); + iflags.last_msg = PLNMSG_OBJ_GLOWS; + } else + You_feel("the blessing of %s over %s.", u_gname(), + yname(uwep)); + bless(uwep); + uwep->bknown = TRUE; + *repair_buf = '\0'; + } - /* fix any rust/burn/rot damage, but don't protect - against future damage */ - if (uwep->oeroded || uwep->oeroded2) { - uwep->oeroded = uwep->oeroded2 = 0; - /* only give this message if we didn't just bless - or uncurse (which has already given a message) */ - if (*repair_buf) - pline("%s as good as new!", - Yobjnam2(uwep, Blind ? "feel" : "look")); - } - update_inventory(); - } - break; - case 3: - /* takes 2 hints to get the music to enter the stronghold; - skip if you've solved it via mastermind or destroyed the - drawbridge (both set uopened_dbridge) or if you've already - travelled past the Valley of the Dead (gehennom_entered) */ - if (!u.uevent.uopened_dbridge && !u.uevent.gehennom_entered) { - if (u.uevent.uheard_tune < 1) { - godvoice(g_align,(char *)0); - verbalize("Hark, %s!", - youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); - verbalize( - "To enter the castle, thou must play the right tune!"); - u.uevent.uheard_tune++; - break; - } else if (u.uevent.uheard_tune < 2) { - You_hear("a divine music..."); - pline("It sounds like: \"%s\".", tune); - u.uevent.uheard_tune++; - break; - } - } - /* Otherwise, falls into next case */ - case 2: - if (!Blind) - You("are surrounded by %s glow.", an(hcolor(NH_GOLDEN))); - /* if any levels have been lost (and not yet regained), - treat this effect like blessed full healing */ - if (u.ulevel < u.ulevelmax) { - u.ulevelmax -= 1; /* see potion.c */ - pluslvl(FALSE); - } else { - u.uhpmax += 5; - if (Upolyd) u.mhmax += 5; - } - u.uhp = u.uhpmax; - if (Upolyd) u.mh = u.mhmax; - ABASE(A_STR) = AMAX(A_STR); - if (u.uhunger < 900) init_uhunger(); - if (u.uluck < 0) u.uluck = 0; - make_blinded(0L,TRUE); - context.botl = 1; - break; - case 4: { - register struct obj *otmp; - int any = 0; + /* fix any rust/burn/rot damage, but don't protect + against future damage */ + if (uwep->oeroded || uwep->oeroded2) { + uwep->oeroded = uwep->oeroded2 = 0; + /* only give this message if we didn't just bless + or uncurse (which has already given a message) */ + if (*repair_buf) + pline("%s as good as new!", + Yobjnam2(uwep, Blind ? "feel" : "look")); + } + update_inventory(); + } + break; + case 3: + /* takes 2 hints to get the music to enter the stronghold; + skip if you've solved it via mastermind or destroyed the + drawbridge (both set uopened_dbridge) or if you've already + travelled past the Valley of the Dead (gehennom_entered) */ + if (!u.uevent.uopened_dbridge && !u.uevent.gehennom_entered) { + if (u.uevent.uheard_tune < 1) { + godvoice(g_align, (char *) 0); + verbalize("Hark, %s!", youmonst.data->mlet == S_HUMAN + ? "mortal" + : "creature"); + verbalize("To enter the castle, thou must play the right " + "tune!"); + u.uevent.uheard_tune++; + break; + } else if (u.uevent.uheard_tune < 2) { + You_hear("a divine music..."); + pline("It sounds like: \"%s\".", tune); + u.uevent.uheard_tune++; + break; + } + } + /* Otherwise, falls into next case */ + case 2: + if (!Blind) + You("are surrounded by %s glow.", an(hcolor(NH_GOLDEN))); + /* if any levels have been lost (and not yet regained), + treat this effect like blessed full healing */ + if (u.ulevel < u.ulevelmax) { + u.ulevelmax -= 1; /* see potion.c */ + pluslvl(FALSE); + } else { + u.uhpmax += 5; + if (Upolyd) + u.mhmax += 5; + } + u.uhp = u.uhpmax; + if (Upolyd) + u.mh = u.mhmax; + ABASE(A_STR) = AMAX(A_STR); + if (u.uhunger < 900) + init_uhunger(); + if (u.uluck < 0) + u.uluck = 0; + make_blinded(0L, TRUE); + context.botl = 1; + break; + case 4: { + register struct obj *otmp; + int any = 0; - if (Blind) - You_feel("the power of %s.", u_gname()); - else You("are surrounded by %s aura.", - an(hcolor(NH_LIGHT_BLUE))); - for(otmp=invent; otmp; otmp=otmp->nobj) { - if (otmp->cursed) { - if (!Blind) { - pline("%s %s.", Yobjnam2(otmp, "softly glow"), - hcolor(NH_AMBER)); - iflags.last_msg = PLNMSG_OBJ_GLOWS; - otmp->bknown = TRUE; - ++any; - } - uncurse(otmp); - } - } - if (any) update_inventory(); - break; - } - case 5: { - static NEARDATA const char - msg[] = "\"and thus I grant thee the gift of %s!\""; + if (Blind) + You_feel("the power of %s.", u_gname()); + else + You("are surrounded by %s aura.", an(hcolor(NH_LIGHT_BLUE))); + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->cursed) { + if (!Blind) { + pline("%s %s.", Yobjnam2(otmp, "softly glow"), + hcolor(NH_AMBER)); + iflags.last_msg = PLNMSG_OBJ_GLOWS; + otmp->bknown = TRUE; + ++any; + } + uncurse(otmp); + } + } + if (any) + update_inventory(); + break; + } + case 5: { + static NEARDATA const char msg[] = + "\"and thus I grant thee the gift of %s!\""; - godvoice(u.ualign.type, "Thou hast pleased me with thy progress,"); - if (!(HTelepat & INTRINSIC)) { - HTelepat |= FROMOUTSIDE; - pline(msg, "Telepathy"); - if (Blind) see_monsters(); - } else if (!(HFast & INTRINSIC)) { - HFast |= FROMOUTSIDE; - pline(msg, "Speed"); - } else if (!(HStealth & INTRINSIC)) { - HStealth |= FROMOUTSIDE; - pline(msg, "Stealth"); - } else { - if (!(HProtection & INTRINSIC)) { - HProtection |= FROMOUTSIDE; - if (!u.ublessed) u.ublessed = rn1(3, 2); - } else u.ublessed++; - pline(msg, "my protection"); - } - verbalize("Use it wisely in my name!"); - break; - } - case 7: - case 8: - if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) { - gcrownu(); - break; - } /* else FALLTHRU */ - case 6: { - struct obj *otmp; - int sp_no, trycnt = u.ulevel + 1; + godvoice(u.ualign.type, + "Thou hast pleased me with thy progress,"); + if (!(HTelepat & INTRINSIC)) { + HTelepat |= FROMOUTSIDE; + pline(msg, "Telepathy"); + if (Blind) + see_monsters(); + } else if (!(HFast & INTRINSIC)) { + HFast |= FROMOUTSIDE; + pline(msg, "Speed"); + } else if (!(HStealth & INTRINSIC)) { + HStealth |= FROMOUTSIDE; + pline(msg, "Stealth"); + } else { + if (!(HProtection & INTRINSIC)) { + HProtection |= FROMOUTSIDE; + if (!u.ublessed) + u.ublessed = rn1(3, 2); + } else + u.ublessed++; + pline(msg, "my protection"); + } + verbalize("Use it wisely in my name!"); + break; + } + case 7: + case 8: + if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) { + gcrownu(); + break; + } /* else FALLTHRU */ + case 6: { + struct obj *otmp; + int sp_no, trycnt = u.ulevel + 1; - /* not yet known spells given preference over already known ones */ - /* Also, try to grant a spell for which there is a skill slot */ - otmp = mkobj(SPBOOK_CLASS, TRUE); - while (--trycnt > 0) { - if (otmp->otyp != SPE_BLANK_PAPER) { - for (sp_no = 0; sp_no < MAXSPELL; sp_no++) - if (spl_book[sp_no].sp_id == otmp->otyp) break; - if (sp_no == MAXSPELL && - !P_RESTRICTED(spell_skilltype(otmp->otyp))) - break; /* usable, but not yet known */ - } else { - if (!objects[SPE_BLANK_PAPER].oc_name_known || - carrying(MAGIC_MARKER)) break; - } - otmp->otyp = rnd_class(bases[SPBOOK_CLASS], SPE_BLANK_PAPER); - } - bless(otmp); - at_your_feet("A spellbook"); - place_object(otmp, u.ux, u.uy); - newsym(u.ux, u.uy); - break; - } - default: impossible("Confused deity!"); - break; - } + /* not yet known spells given preference over already known ones + */ + /* Also, try to grant a spell for which there is a skill slot */ + otmp = mkobj(SPBOOK_CLASS, TRUE); + while (--trycnt > 0) { + if (otmp->otyp != SPE_BLANK_PAPER) { + for (sp_no = 0; sp_no < MAXSPELL; sp_no++) + if (spl_book[sp_no].sp_id == otmp->otyp) + break; + if (sp_no == MAXSPELL + && !P_RESTRICTED(spell_skilltype(otmp->otyp))) + break; /* usable, but not yet known */ + } else { + if (!objects[SPE_BLANK_PAPER].oc_name_known + || carrying(MAGIC_MARKER)) + break; + } + otmp->otyp = rnd_class(bases[SPBOOK_CLASS], SPE_BLANK_PAPER); + } + bless(otmp); + at_your_feet("A spellbook"); + place_object(otmp, u.ux, u.uy); + newsym(u.ux, u.uy); + break; + } + default: + impossible("Confused deity!"); + break; + } - u.ublesscnt = rnz(350); - kick_on_butt = u.uevent.udemigod ? 1 : 0; - if (u.uevent.uhand_of_elbereth) kick_on_butt++; - if (kick_on_butt) u.ublesscnt += kick_on_butt * rnz(1000); + u.ublesscnt = rnz(350); + kick_on_butt = u.uevent.udemigod ? 1 : 0; + if (u.uevent.uhand_of_elbereth) + kick_on_butt++; + if (kick_on_butt) + u.ublesscnt += kick_on_butt * rnz(1000); - return; + return; } /* either blesses or curses water on the altar, @@ -1073,51 +1159,51 @@ pleased(g_align) */ STATIC_OVL boolean water_prayer(bless_water) - boolean bless_water; +boolean bless_water; { - register struct obj* otmp; + register struct obj *otmp; register long changed = 0; boolean other = FALSE, bc_known = !(Blind || Hallucination); - for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { - /* turn water into (un)holy water */ - if (otmp->otyp == POT_WATER && - (bless_water ? !otmp->blessed : !otmp->cursed)) { - otmp->blessed = bless_water; - otmp->cursed = !bless_water; - otmp->bknown = bc_known; - changed += otmp->quan; - } else if(otmp->oclass == POTION_CLASS) - other = TRUE; + for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { + /* turn water into (un)holy water */ + if (otmp->otyp == POT_WATER + && (bless_water ? !otmp->blessed : !otmp->cursed)) { + otmp->blessed = bless_water; + otmp->cursed = !bless_water; + otmp->bknown = bc_known; + changed += otmp->quan; + } else if (otmp->oclass == POTION_CLASS) + other = TRUE; } - if(!Blind && changed) { - pline("%s potion%s on the altar glow%s %s for a moment.", - ((other && changed > 1L) ? "Some of the" : - (other ? "One of the" : "The")), - ((other || changed > 1L) ? "s" : ""), (changed > 1L ? "" : "s"), - (bless_water ? hcolor(NH_LIGHT_BLUE) : hcolor(NH_BLACK))); + if (!Blind && changed) { + pline("%s potion%s on the altar glow%s %s for a moment.", + ((other && changed > 1L) ? "Some of the" + : (other ? "One of the" : "The")), + ((other || changed > 1L) ? "s" : ""), (changed > 1L ? "" : "s"), + (bless_water ? hcolor(NH_LIGHT_BLUE) : hcolor(NH_BLACK))); } - return((boolean)(changed > 0L)); + return ((boolean)(changed > 0L)); } STATIC_OVL void godvoice(g_align, words) - aligntyp g_align; - const char *words; +aligntyp g_align; +const char *words; { const char *quot = ""; - if(words) - quot = "\""; + if (words) + quot = "\""; else - words = ""; + words = ""; pline_The("voice of %s %s: %s%s%s", align_gname(g_align), - godvoices[rn2(SIZE(godvoices))], quot, words, quot); + godvoices[rn2(SIZE(godvoices))], quot, words, quot); } STATIC_OVL void gods_angry(g_align) - aligntyp g_align; +aligntyp g_align; { godvoice(g_align, "Thou hast angered me."); } @@ -1125,11 +1211,13 @@ gods_angry(g_align) /* The g_align god is upset with you. */ STATIC_OVL void gods_upset(g_align) - aligntyp g_align; +aligntyp g_align; { - if(g_align == u.ualign.type) u.ugangr++; - else if(u.ugangr) u.ugangr--; - angrygods(g_align); + if (g_align == u.ualign.type) + u.ugangr++; + else if (u.ugangr) + u.ugangr--; + angrygods(g_align); } STATIC_OVL void @@ -1137,23 +1225,27 @@ consume_offering(otmp) register struct obj *otmp; { if (Hallucination) - switch (rn2(3)) { - case 0: - Your("sacrifice sprouts wings and a propeller and roars away!"); - break; - case 1: - Your("sacrifice puffs up, swelling bigger and bigger, and pops!"); - break; - case 2: - Your("sacrifice collapses into a cloud of dancing particles and fades away!"); - break; - } + switch (rn2(3)) { + case 0: + Your("sacrifice sprouts wings and a propeller and roars away!"); + break; + case 1: + Your("sacrifice puffs up, swelling bigger and bigger, and pops!"); + break; + case 2: + Your("sacrifice collapses into a cloud of dancing particles and " + "fades away!"); + break; + } else if (Blind && u.ualign.type == A_LAWFUL) - Your("sacrifice disappears!"); - else Your("sacrifice is consumed in a %s!", - u.ualign.type == A_LAWFUL ? "flash of light" : "burst of flame"); - if (carried(otmp)) useup(otmp); - else useupf(otmp, 1L); + Your("sacrifice disappears!"); + else + Your("sacrifice is consumed in a %s!", + u.ualign.type == A_LAWFUL ? "flash of light" : "burst of flame"); + if (carried(otmp)) + useup(otmp); + else + useupf(otmp, 1L); exercise(A_WIS, TRUE); } @@ -1161,462 +1253,509 @@ int dosacrifice() { static NEARDATA const char cloud_of_smoke[] = - "A cloud of %s smoke surrounds you..."; + "A cloud of %s smoke surrounds you..."; register struct obj *otmp; int value = 0, pm; boolean highaltar; - aligntyp altaralign = a_align(u.ux,u.uy); + aligntyp altaralign = a_align(u.ux, u.uy); if (!on_altar() || u.uswallow) { - You("are not standing on an altar."); - return 0; + You("are not standing on an altar."); + return 0; } - highaltar = ((Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) && - (levl[u.ux][u.uy].altarmask & AM_SHRINE)); + highaltar = ((Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) + && (levl[u.ux][u.uy].altarmask & AM_SHRINE)); otmp = floorfood("sacrifice", 1); - if (!otmp) return 0; - /* - Was based on nutritional value and aging behavior (< 50 moves). - Sacrificing a food ration got you max luck instantly, making the - gods as easy to please as an angry dog! + if (!otmp) + return 0; +/* + Was based on nutritional value and aging behavior (< 50 moves). + Sacrificing a food ration got you max luck instantly, making the + gods as easy to please as an angry dog! - Now only accepts corpses, based on the game's evaluation of their - toughness. Human and pet sacrifice, as well as sacrificing unicorns - of your alignment, is strongly discouraged. - */ + Now only accepts corpses, based on the game's evaluation of their + toughness. Human and pet sacrifice, as well as sacrificing unicorns + of your alignment, is strongly discouraged. + */ #define MAXVALUE 24 /* Highest corpse value (besides Wiz) */ if (otmp->otyp == CORPSE) { - register struct permonst *ptr = &mons[otmp->corpsenm]; - struct monst *mtmp; - extern const int monstr[]; + register struct permonst *ptr = &mons[otmp->corpsenm]; + struct monst *mtmp; + extern const int monstr[]; - /* KMH, conduct */ - u.uconduct.gnostic++; + /* KMH, conduct */ + u.uconduct.gnostic++; - /* you're handling this corpse, even if it was killed upon the altar */ - feel_cockatrice(otmp, TRUE); - if (rider_corpse_revival(otmp, FALSE)) return 1; + /* you're handling this corpse, even if it was killed upon the altar + */ + feel_cockatrice(otmp, TRUE); + if (rider_corpse_revival(otmp, FALSE)) + return 1; - if (otmp->corpsenm == PM_ACID_BLOB - || (monstermoves <= peek_at_iced_corpse_age(otmp) + 50)) { - value = monstr[otmp->corpsenm] + 1; - if (otmp->oeaten) - value = eaten_stat(value, otmp); - } + if (otmp->corpsenm == PM_ACID_BLOB + || (monstermoves <= peek_at_iced_corpse_age(otmp) + 50)) { + value = monstr[otmp->corpsenm] + 1; + if (otmp->oeaten) + value = eaten_stat(value, otmp); + } - if (your_race(ptr)) { - if (is_demon(youmonst.data)) { - You("find the idea very satisfying."); - exercise(A_WIS, TRUE); - } else if (u.ualign.type != A_CHAOTIC) { - pline("You'll regret this infamous offense!"); - exercise(A_WIS, FALSE); - } + if (your_race(ptr)) { + if (is_demon(youmonst.data)) { + You("find the idea very satisfying."); + exercise(A_WIS, TRUE); + } else if (u.ualign.type != A_CHAOTIC) { + pline("You'll regret this infamous offense!"); + exercise(A_WIS, FALSE); + } - if (highaltar && - (altaralign != A_CHAOTIC || u.ualign.type != A_CHAOTIC)) { - goto desecrate_high_altar; - } else if (altaralign != A_CHAOTIC && altaralign != A_NONE) { - /* curse the lawful/neutral altar */ - pline_The("altar is stained with %s blood.", urace.adj); - levl[u.ux][u.uy].altarmask = AM_CHAOTIC; - angry_priest(); - } else { - struct monst *dmon; - const char *demonless_msg; + if (highaltar + && (altaralign != A_CHAOTIC || u.ualign.type != A_CHAOTIC)) { + goto desecrate_high_altar; + } else if (altaralign != A_CHAOTIC && altaralign != A_NONE) { + /* curse the lawful/neutral altar */ + pline_The("altar is stained with %s blood.", urace.adj); + levl[u.ux][u.uy].altarmask = AM_CHAOTIC; + angry_priest(); + } else { + struct monst *dmon; + const char *demonless_msg; - /* Human sacrifice on a chaotic or unaligned altar */ - /* is equivalent to demon summoning */ - if (altaralign == A_CHAOTIC && u.ualign.type != A_CHAOTIC) { - pline( - "The blood floods the altar, which vanishes in %s cloud!", - an(hcolor(NH_BLACK))); - levl[u.ux][u.uy].typ = ROOM; - levl[u.ux][u.uy].altarmask = 0; - newsym(u.ux, u.uy); - angry_priest(); - demonless_msg = "cloud dissipates"; - } else { - /* either you're chaotic or altar is Moloch's or both */ - pline_The("blood covers the altar!"); - change_luck(altaralign == A_NONE ? -2 : 2); - demonless_msg = "blood coagulates"; - } - if ((pm = dlord(altaralign)) != NON_PM && - (dmon = makemon(&mons[pm], u.ux, u.uy, NO_MM_FLAGS)) != 0) { - char dbuf[BUFSZ]; + /* Human sacrifice on a chaotic or unaligned altar */ + /* is equivalent to demon summoning */ + if (altaralign == A_CHAOTIC && u.ualign.type != A_CHAOTIC) { + pline("The blood floods the altar, which vanishes in %s " + "cloud!", + an(hcolor(NH_BLACK))); + levl[u.ux][u.uy].typ = ROOM; + levl[u.ux][u.uy].altarmask = 0; + newsym(u.ux, u.uy); + angry_priest(); + demonless_msg = "cloud dissipates"; + } else { + /* either you're chaotic or altar is Moloch's or both */ + pline_The("blood covers the altar!"); + change_luck(altaralign == A_NONE ? -2 : 2); + demonless_msg = "blood coagulates"; + } + if ((pm = dlord(altaralign)) != NON_PM + && (dmon = makemon(&mons[pm], u.ux, u.uy, NO_MM_FLAGS)) + != 0) { + char dbuf[BUFSZ]; - Strcpy(dbuf, a_monnam(dmon)); - if (!strcmpi(dbuf, "it")) - Strcpy(dbuf, "something dreadful"); - else - dmon->mstrategy &= ~STRAT_APPEARMSG; - You("have summoned %s!", dbuf); - if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp)) - dmon->mpeaceful = TRUE; - You("are terrified, and unable to move."); - nomul(-3); - multi_reason = "being terrified of a demon"; - nomovemsg = 0; - } else pline_The("%s.", demonless_msg); - } + Strcpy(dbuf, a_monnam(dmon)); + if (!strcmpi(dbuf, "it")) + Strcpy(dbuf, "something dreadful"); + else + dmon->mstrategy &= ~STRAT_APPEARMSG; + You("have summoned %s!", dbuf); + if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp)) + dmon->mpeaceful = TRUE; + You("are terrified, and unable to move."); + nomul(-3); + multi_reason = "being terrified of a demon"; + nomovemsg = 0; + } else + pline_The("%s.", demonless_msg); + } - if (u.ualign.type != A_CHAOTIC) { - adjalign(-5); - u.ugangr += 3; - (void) adjattrib(A_WIS, -1, TRUE); - if (!Inhell) angrygods(u.ualign.type); - change_luck(-5); - } else adjalign(5); - if (carried(otmp)) useup(otmp); - else useupf(otmp, 1L); - return(1); - } else if (has_omonst(otmp) - && ((mtmp = get_mtraits(otmp, FALSE)) != (struct monst *)0) - && mtmp->mtame) { - /* mtmp is a temporary pointer to a tame monster's attributes, - * not a real monster */ - pline("So this is how you repay loyalty?"); - adjalign(-3); - value = -1; - HAggravate_monster |= FROMOUTSIDE; - } else if (is_undead(ptr)) { /* Not demons--no demon corpses */ - if (u.ualign.type != A_CHAOTIC) - value += 1; - } else if (is_unicorn(ptr)) { - int unicalign = sgn(ptr->maligntyp); + if (u.ualign.type != A_CHAOTIC) { + adjalign(-5); + u.ugangr += 3; + (void) adjattrib(A_WIS, -1, TRUE); + if (!Inhell) + angrygods(u.ualign.type); + change_luck(-5); + } else + adjalign(5); + if (carried(otmp)) + useup(otmp); + else + useupf(otmp, 1L); + return (1); + } else if (has_omonst(otmp) && ((mtmp = get_mtraits(otmp, FALSE)) + != (struct monst *) 0) + && mtmp->mtame) { + /* mtmp is a temporary pointer to a tame monster's attributes, + * not a real monster */ + pline("So this is how you repay loyalty?"); + adjalign(-3); + value = -1; + HAggravate_monster |= FROMOUTSIDE; + } else if (is_undead(ptr)) { /* Not demons--no demon corpses */ + if (u.ualign.type != A_CHAOTIC) + value += 1; + } else if (is_unicorn(ptr)) { + int unicalign = sgn(ptr->maligntyp); - /* If same as altar, always a very bad action. */ - if (unicalign == altaralign) { - pline("Such an action is an insult to %s!", - (unicalign == A_CHAOTIC) - ? "chaos" : unicalign ? "law" : "balance"); - (void) adjattrib(A_WIS, -1, TRUE); - value = -5; - } else if (u.ualign.type == altaralign) { - /* If different from altar, and altar is same as yours, */ - /* it's a very good action */ - if (u.ualign.record < ALIGNLIM) - You_feel("appropriately %s.", align_str(u.ualign.type)); - else You_feel("you are thoroughly on the right path."); - adjalign(5); - value += 3; - } else - /* If sacrificing unicorn of your alignment to altar not of */ - /* your alignment, your god gets angry and it's a conversion */ - if (unicalign == u.ualign.type) { - u.ualign.record = -1; - value = 1; - } else value += 3; - } + /* If same as altar, always a very bad action. */ + if (unicalign == altaralign) { + pline("Such an action is an insult to %s!", + (unicalign == A_CHAOTIC) ? "chaos" : unicalign + ? "law" + : "balance"); + (void) adjattrib(A_WIS, -1, TRUE); + value = -5; + } else if (u.ualign.type == altaralign) { + /* If different from altar, and altar is same as yours, */ + /* it's a very good action */ + if (u.ualign.record < ALIGNLIM) + You_feel("appropriately %s.", align_str(u.ualign.type)); + else + You_feel("you are thoroughly on the right path."); + adjalign(5); + value += 3; + } else + /* If sacrificing unicorn of your alignment to altar not of */ + /* your alignment, your god gets angry and it's a conversion + */ + if (unicalign == u.ualign.type) { + u.ualign.record = -1; + value = 1; + } else + value += 3; + } } /* corpse */ if (otmp->otyp == AMULET_OF_YENDOR) { - if (!highaltar) { - too_soon: - if (altaralign == A_NONE && Inhell) - /* hero has left Moloch's Sanctum so is in the process - of getting away with the Amulet (outside of Gehennom, - fall through to the "ashamed" feedback) */ - gods_upset(A_NONE); - else - You_feel("%s.", Hallucination ? "homesick" : - /* headed towards celestial disgrace */ - (altaralign != u.ualign.type) ? "ashamed" : - /* on track; give a big hint */ - "an urge to return to the surface"); - return 1; - } else { - /* The final Test. Did you win? */ - if(uamul == otmp) Amulet_off(); - u.uevent.ascended = 1; - if(carried(otmp)) useup(otmp); /* well, it's gone now */ - else useupf(otmp, 1L); - You("offer the Amulet of Yendor to %s...", a_gname()); - if (altaralign == A_NONE) { - /* Moloch's high altar */ - if (u.ualign.record > -99) u.ualign.record = -99; - /*[apparently shrug/snarl can be sensed without being seen]*/ - pline("%s shrugs and retains dominion over %s,", - Moloch, u_gname()); - pline("then mercilessly snuffs out your life."); - Sprintf(killer.name, "%s indifference", s_suffix(Moloch)); - killer.format = KILLED_BY; - done(DIED); - /* life-saved (or declined to die in wizard/explore mode) */ - pline("%s snarls and tries again...", Moloch); - fry_by_god(A_NONE, TRUE); /* wrath of Moloch */ - /* declined to die in wizard or explore mode */ - pline(cloud_of_smoke, hcolor(NH_BLACK)); - done(ESCAPED); - } else if (u.ualign.type != altaralign) { - /* And the opposing team picks you up and - carries you off on their shoulders */ - adjalign(-99); - pline("%s accepts your gift, and gains dominion over %s...", - a_gname(), u_gname()); - pline("%s is enraged...", u_gname()); - pline("Fortunately, %s permits you to live...", a_gname()); - pline(cloud_of_smoke, hcolor(NH_ORANGE)); - done(ESCAPED); - } else { /* super big win */ - adjalign(10); - u.uachieve.ascended = 1; -pline("An invisible choir sings, and you are bathed in radiance..."); - godvoice(altaralign, "Congratulations, mortal!"); - display_nhwindow(WIN_MESSAGE, FALSE); -verbalize("In return for thy service, I grant thee the gift of Immortality!"); - You("ascend to the status of Demigod%s...", - flags.female ? "dess" : ""); - done(ASCENDED); - } - } + if (!highaltar) { + too_soon: + if (altaralign == A_NONE && Inhell) + /* hero has left Moloch's Sanctum so is in the process + of getting away with the Amulet (outside of Gehennom, + fall through to the "ashamed" feedback) */ + gods_upset(A_NONE); + else + You_feel("%s.", + Hallucination ? "homesick" : + /* headed towards celestial disgrace */ + (altaralign != u.ualign.type) + ? "ashamed" + : + /* on track; give a big hint */ + "an urge to return to the surface"); + return 1; + } else { + /* The final Test. Did you win? */ + if (uamul == otmp) + Amulet_off(); + u.uevent.ascended = 1; + if (carried(otmp)) + useup(otmp); /* well, it's gone now */ + else + useupf(otmp, 1L); + You("offer the Amulet of Yendor to %s...", a_gname()); + if (altaralign == A_NONE) { + /* Moloch's high altar */ + if (u.ualign.record > -99) + u.ualign.record = -99; + /*[apparently shrug/snarl can be sensed without being seen]*/ + pline("%s shrugs and retains dominion over %s,", Moloch, + u_gname()); + pline("then mercilessly snuffs out your life."); + Sprintf(killer.name, "%s indifference", s_suffix(Moloch)); + killer.format = KILLED_BY; + done(DIED); + /* life-saved (or declined to die in wizard/explore mode) */ + pline("%s snarls and tries again...", Moloch); + fry_by_god(A_NONE, TRUE); /* wrath of Moloch */ + /* declined to die in wizard or explore mode */ + pline(cloud_of_smoke, hcolor(NH_BLACK)); + done(ESCAPED); + } else if (u.ualign.type != altaralign) { + /* And the opposing team picks you up and + carries you off on their shoulders */ + adjalign(-99); + pline("%s accepts your gift, and gains dominion over %s...", + a_gname(), u_gname()); + pline("%s is enraged...", u_gname()); + pline("Fortunately, %s permits you to live...", a_gname()); + pline(cloud_of_smoke, hcolor(NH_ORANGE)); + done(ESCAPED); + } else { /* super big win */ + adjalign(10); + u.uachieve.ascended = 1; + pline("An invisible choir sings, and you are bathed in " + "radiance..."); + godvoice(altaralign, "Congratulations, mortal!"); + display_nhwindow(WIN_MESSAGE, FALSE); + verbalize("In return for thy service, I grant thee the gift " + "of Immortality!"); + You("ascend to the status of Demigod%s...", + flags.female ? "dess" : ""); + done(ASCENDED); + } + } } /* real Amulet */ if (otmp->otyp == FAKE_AMULET_OF_YENDOR) { - if (!highaltar && !otmp->known) goto too_soon; - You_hear("a nearby thunderclap."); - if (!otmp->known) { - You("realize you have made a %s.", - Hallucination ? "boo-boo" : "mistake"); - otmp->known = TRUE; - change_luck(-1); - return 1; - } else { - /* don't you dare try to fool the gods */ - if (Deaf) pline("Oh, no."); /* didn't hear thunderclap */ - change_luck(-3); - adjalign(-1); - u.ugangr += 3; - value = -3; - } + if (!highaltar && !otmp->known) + goto too_soon; + You_hear("a nearby thunderclap."); + if (!otmp->known) { + You("realize you have made a %s.", + Hallucination ? "boo-boo" : "mistake"); + otmp->known = TRUE; + change_luck(-1); + return 1; + } else { + /* don't you dare try to fool the gods */ + if (Deaf) + pline("Oh, no."); /* didn't hear thunderclap */ + change_luck(-3); + adjalign(-1); + u.ugangr += 3; + value = -3; + } } /* fake Amulet */ if (value == 0) { - pline1(nothing_happens); - return (1); + pline1(nothing_happens); + return (1); } if (altaralign != u.ualign.type && highaltar) { - desecrate_high_altar: - /* - * REAL BAD NEWS!!! High altars cannot be converted. Even an attempt - * gets the god who owns it truely pissed off. - */ - You_feel("the air around you grow charged..."); - pline("Suddenly, you realize that %s has noticed you...", a_gname()); - godvoice(altaralign, "So, mortal! You dare desecrate my High Temple!"); - /* Throw everything we have at the player */ - god_zaps_you(altaralign); - } else if (value < 0) { /* I don't think the gods are gonna like this... */ - gods_upset(altaralign); + desecrate_high_altar: + /* + * REAL BAD NEWS!!! High altars cannot be converted. Even an attempt + * gets the god who owns it truely pissed off. + */ + You_feel("the air around you grow charged..."); + pline("Suddenly, you realize that %s has noticed you...", a_gname()); + godvoice(altaralign, + "So, mortal! You dare desecrate my High Temple!"); + /* Throw everything we have at the player */ + god_zaps_you(altaralign); + } else if (value + < 0) { /* I don't think the gods are gonna like this... */ + gods_upset(altaralign); } else { - int saved_anger = u.ugangr; - int saved_cnt = u.ublesscnt; - int saved_luck = u.uluck; + int saved_anger = u.ugangr; + int saved_cnt = u.ublesscnt; + int saved_luck = u.uluck; - /* Sacrificing at an altar of a different alignment */ - if (u.ualign.type != altaralign) { - /* Is this a conversion ? */ - /* An unaligned altar in Gehennom will always elicit rejection. */ - if (ugod_is_angry() || (altaralign == A_NONE && Inhell)) { - if(u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL] && - altaralign != A_NONE) { - You("have a strong feeling that %s is angry...", u_gname()); - consume_offering(otmp); - pline("%s accepts your allegiance.", a_gname()); + /* Sacrificing at an altar of a different alignment */ + if (u.ualign.type != altaralign) { + /* Is this a conversion ? */ + /* An unaligned altar in Gehennom will always elicit rejection. */ + if (ugod_is_angry() || (altaralign == A_NONE && Inhell)) { + if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL] + && altaralign != A_NONE) { + You("have a strong feeling that %s is angry...", + u_gname()); + consume_offering(otmp); + pline("%s accepts your allegiance.", a_gname()); - uchangealign(altaralign, 0); - /* Beware, Conversion is costly */ - change_luck(-3); - u.ublesscnt += 300; - } else { - u.ugangr += 3; - adjalign(-5); - pline("%s rejects your sacrifice!", a_gname()); - godvoice(altaralign, "Suffer, infidel!"); - change_luck(-5); - (void) adjattrib(A_WIS, -2, TRUE); - if (!Inhell) angrygods(u.ualign.type); - } - return(1); - } else { - consume_offering(otmp); - You("sense a conflict between %s and %s.", - u_gname(), a_gname()); - if (rn2(8 + u.ulevel) > 5) { - struct monst *pri; - You_feel("the power of %s increase.", u_gname()); - exercise(A_WIS, TRUE); - change_luck(1); - /* Yes, this is supposed to be &=, not |= */ - levl[u.ux][u.uy].altarmask &= AM_SHRINE; - /* the following accommodates stupid compilers */ - levl[u.ux][u.uy].altarmask = - levl[u.ux][u.uy].altarmask | (Align2amask(u.ualign.type)); - if (!Blind) - pline_The("altar glows %s.", - hcolor( - u.ualign.type == A_LAWFUL ? NH_WHITE : - u.ualign.type ? NH_BLACK : (const char *)"gray")); + uchangealign(altaralign, 0); + /* Beware, Conversion is costly */ + change_luck(-3); + u.ublesscnt += 300; + } else { + u.ugangr += 3; + adjalign(-5); + pline("%s rejects your sacrifice!", a_gname()); + godvoice(altaralign, "Suffer, infidel!"); + change_luck(-5); + (void) adjattrib(A_WIS, -2, TRUE); + if (!Inhell) + angrygods(u.ualign.type); + } + return (1); + } else { + consume_offering(otmp); + You("sense a conflict between %s and %s.", u_gname(), + a_gname()); + if (rn2(8 + u.ulevel) > 5) { + struct monst *pri; + You_feel("the power of %s increase.", u_gname()); + exercise(A_WIS, TRUE); + change_luck(1); + /* Yes, this is supposed to be &=, not |= */ + levl[u.ux][u.uy].altarmask &= AM_SHRINE; + /* the following accommodates stupid compilers */ + levl[u.ux][u.uy].altarmask = + levl[u.ux][u.uy].altarmask + | (Align2amask(u.ualign.type)); + if (!Blind) + pline_The("altar glows %s.", + hcolor(u.ualign.type == A_LAWFUL + ? NH_WHITE + : u.ualign.type + ? NH_BLACK + : (const char *) "gray")); - if (rnl(u.ulevel) > 6 && u.ualign.record > 0 && - rnd(u.ualign.record) > (3*ALIGNLIM)/4) - summon_minion(altaralign, TRUE); - /* anger priest; test handles bones files */ - if((pri = findpriest(temple_occupied(u.urooms))) && - !p_coaligned(pri)) - angry_priest(); - } else { - pline("Unluckily, you feel the power of %s decrease.", - u_gname()); - change_luck(-1); - exercise(A_WIS, FALSE); - if (rnl(u.ulevel) > 6 && u.ualign.record > 0 && - rnd(u.ualign.record) > (7*ALIGNLIM)/8) - summon_minion(altaralign, TRUE); - } - return(1); - } - } + if (rnl(u.ulevel) > 6 && u.ualign.record > 0 + && rnd(u.ualign.record) > (3 * ALIGNLIM) / 4) + summon_minion(altaralign, TRUE); + /* anger priest; test handles bones files */ + if ((pri = findpriest(temple_occupied(u.urooms))) + && !p_coaligned(pri)) + angry_priest(); + } else { + pline("Unluckily, you feel the power of %s decrease.", + u_gname()); + change_luck(-1); + exercise(A_WIS, FALSE); + if (rnl(u.ulevel) > 6 && u.ualign.record > 0 + && rnd(u.ualign.record) > (7 * ALIGNLIM) / 8) + summon_minion(altaralign, TRUE); + } + return (1); + } + } - consume_offering(otmp); - /* OK, you get brownie points. */ - if(u.ugangr) { - u.ugangr -= - ((value * (u.ualign.type == A_CHAOTIC ? 2 : 3)) / MAXVALUE); - if(u.ugangr < 0) u.ugangr = 0; - if(u.ugangr != saved_anger) { - if (u.ugangr) { - pline("%s seems %s.", u_gname(), - Hallucination ? "groovy" : "slightly mollified"); + consume_offering(otmp); + /* OK, you get brownie points. */ + if (u.ugangr) { + u.ugangr -= + ((value * (u.ualign.type == A_CHAOTIC ? 2 : 3)) / MAXVALUE); + if (u.ugangr < 0) + u.ugangr = 0; + if (u.ugangr != saved_anger) { + if (u.ugangr) { + pline("%s seems %s.", u_gname(), + Hallucination ? "groovy" : "slightly mollified"); - if ((int)u.uluck < 0) change_luck(1); - } else { - pline("%s seems %s.", u_gname(), Hallucination ? - "cosmic (not a new fact)" : "mollified"); + if ((int) u.uluck < 0) + change_luck(1); + } else { + pline("%s seems %s.", u_gname(), + Hallucination ? "cosmic (not a new fact)" + : "mollified"); - if ((int)u.uluck < 0) u.uluck = 0; - } - } else { /* not satisfied yet */ - if (Hallucination) - pline_The("gods seem tall."); - else You("have a feeling of inadequacy."); - } - } else if(ugod_is_angry()) { - if(value > MAXVALUE) value = MAXVALUE; - if(value > -u.ualign.record) value = -u.ualign.record; - adjalign(value); - You_feel("partially absolved."); - } else if (u.ublesscnt > 0) { - u.ublesscnt -= - ((value * (u.ualign.type == A_CHAOTIC ? 500 : 300)) / MAXVALUE); - if(u.ublesscnt < 0) u.ublesscnt = 0; - if(u.ublesscnt != saved_cnt) { - if (u.ublesscnt) { - if (Hallucination) - You("realize that the gods are not like you and I."); - else - You("have a hopeful feeling."); - if ((int)u.uluck < 0) change_luck(1); - } else { - if (Hallucination) - pline("Overall, there is a smell of fried onions."); - else - You("have a feeling of reconciliation."); - if ((int)u.uluck < 0) u.uluck = 0; - } - } - } else { - int nartifacts = nartifact_exist(); + if ((int) u.uluck < 0) + u.uluck = 0; + } + } else { /* not satisfied yet */ + if (Hallucination) + pline_The("gods seem tall."); + else + You("have a feeling of inadequacy."); + } + } else if (ugod_is_angry()) { + if (value > MAXVALUE) + value = MAXVALUE; + if (value > -u.ualign.record) + value = -u.ualign.record; + adjalign(value); + You_feel("partially absolved."); + } else if (u.ublesscnt > 0) { + u.ublesscnt -= ((value * (u.ualign.type == A_CHAOTIC ? 500 : 300)) + / MAXVALUE); + if (u.ublesscnt < 0) + u.ublesscnt = 0; + if (u.ublesscnt != saved_cnt) { + if (u.ublesscnt) { + if (Hallucination) + You("realize that the gods are not like you and I."); + else + You("have a hopeful feeling."); + if ((int) u.uluck < 0) + change_luck(1); + } else { + if (Hallucination) + pline("Overall, there is a smell of fried onions."); + else + You("have a feeling of reconciliation."); + if ((int) u.uluck < 0) + u.uluck = 0; + } + } + } else { + int nartifacts = nartifact_exist(); - /* you were already in pretty good standing */ - /* The player can gain an artifact */ - /* The chance goes down as the number of artifacts goes up */ - if (u.ulevel > 2 && u.uluck >= 0 && - !rn2(10 + (2 * u.ugifts * nartifacts))) { - otmp = mk_artifact((struct obj *)0, a_align(u.ux,u.uy)); - if (otmp) { - if (otmp->spe < 0) otmp->spe = 0; - if (otmp->cursed) uncurse(otmp); - otmp->oerodeproof = TRUE; - at_your_feet("An object"); - dropy(otmp); - godvoice(u.ualign.type, "Use my gift wisely!"); - u.ugifts++; - u.ublesscnt = rnz(300 + (50 * nartifacts)); - exercise(A_WIS, TRUE); - /* make sure we can use this weapon */ - unrestrict_weapon_skill(weapon_type(otmp)); - if (!Hallucination && !Blind) { - otmp->dknown = 1; - makeknown(otmp->otyp); - discover_artifact(otmp->oartifact); - } - return(1); - } - } - change_luck((value * LUCKMAX) / (MAXVALUE * 2)); - if ((int)u.uluck < 0) u.uluck = 0; - if (u.uluck != saved_luck) { - if (Blind) - You("think %s brushed your %s.",something, body_part(FOOT)); - else You(Hallucination ? - "see crabgrass at your %s. A funny thing in a dungeon." : - "glimpse a four-leaf clover at your %s.", - makeplural(body_part(FOOT))); - } - } + /* you were already in pretty good standing */ + /* The player can gain an artifact */ + /* The chance goes down as the number of artifacts goes up */ + if (u.ulevel > 2 && u.uluck >= 0 + && !rn2(10 + (2 * u.ugifts * nartifacts))) { + otmp = mk_artifact((struct obj *) 0, a_align(u.ux, u.uy)); + if (otmp) { + if (otmp->spe < 0) + otmp->spe = 0; + if (otmp->cursed) + uncurse(otmp); + otmp->oerodeproof = TRUE; + at_your_feet("An object"); + dropy(otmp); + godvoice(u.ualign.type, "Use my gift wisely!"); + u.ugifts++; + u.ublesscnt = rnz(300 + (50 * nartifacts)); + exercise(A_WIS, TRUE); + /* make sure we can use this weapon */ + unrestrict_weapon_skill(weapon_type(otmp)); + if (!Hallucination && !Blind) { + otmp->dknown = 1; + makeknown(otmp->otyp); + discover_artifact(otmp->oartifact); + } + return (1); + } + } + change_luck((value * LUCKMAX) / (MAXVALUE * 2)); + if ((int) u.uluck < 0) + u.uluck = 0; + if (u.uluck != saved_luck) { + if (Blind) + You("think %s brushed your %s.", something, + body_part(FOOT)); + else + You(Hallucination + ? "see crabgrass at your %s. A funny thing in a " + "dungeon." + : "glimpse a four-leaf clover at your %s.", + makeplural(body_part(FOOT))); + } + } } - return(1); + return (1); } - /* determine prayer results in advance; also used for enlightenment */ boolean can_pray(praying) -boolean praying; /* false means no messages should be given */ +boolean praying; /* false means no messages should be given */ { int alignment; - p_aligntyp = on_altar() ? a_align(u.ux,u.uy) : u.ualign.type; + p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type; p_trouble = in_trouble(); if (is_demon(youmonst.data) && (p_aligntyp != A_CHAOTIC)) { - if (praying) - pline_The("very idea of praying to a %s god is repugnant to you.", - p_aligntyp ? "lawful" : "neutral"); - return FALSE; + if (praying) + pline_The("very idea of praying to a %s god is repugnant to you.", + p_aligntyp ? "lawful" : "neutral"); + return FALSE; } if (praying) - You("begin praying to %s.", align_gname(p_aligntyp)); + You("begin praying to %s.", align_gname(p_aligntyp)); if (u.ualign.type && u.ualign.type == -p_aligntyp) - alignment = -u.ualign.record; /* Opposite alignment altar */ + alignment = -u.ualign.record; /* Opposite alignment altar */ else if (u.ualign.type != p_aligntyp) - alignment = u.ualign.record / 2; /* Different alignment altar */ - else alignment = u.ualign.record; + alignment = u.ualign.record / 2; /* Different alignment altar */ + else + alignment = u.ualign.record; - if ((p_trouble > 0) ? (u.ublesscnt > 200) : /* big trouble */ - (p_trouble < 0) ? (u.ublesscnt > 100) : /* minor difficulties */ - (u.ublesscnt > 0)) /* not in trouble */ - p_type = 0; /* too soon... */ - else if ((int)Luck < 0 || u.ugangr || alignment < 0) - p_type = 1; /* too naughty... */ + if ((p_trouble > 0) ? (u.ublesscnt > 200) : /* big trouble */ + (p_trouble < 0) ? (u.ublesscnt > 100) : /* minor difficulties */ + (u.ublesscnt > 0)) /* not in trouble */ + p_type = 0; /* too soon... */ + else if ((int) Luck < 0 || u.ugangr || alignment < 0) + p_type = 1; /* too naughty... */ else /* alignment >= 0 */ { - if(on_altar() && u.ualign.type != p_aligntyp) - p_type = 2; - else - p_type = 3; + if (on_altar() && u.ualign.type != p_aligntyp) + p_type = 2; + else + p_type = 3; } - if (is_undead(youmonst.data) && !Inhell && - (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10)))) - p_type = -1; + if (is_undead(youmonst.data) && !Inhell + && (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10)))) + p_type = -1; /* Note: when !praying, the random factor for neutrals makes the return value a non-deterministic approximation for enlightenment. This case should be uncommon enough to live with... */ @@ -1629,208 +1768,214 @@ dopray() { /* Confirm accidental slips of Alt-P */ if (ParanoidPray && yn("Are you sure you want to pray?") != 'y') - return 0; + return 0; u.uconduct.gnostic++; /* set up p_type and p_alignment */ - if (!can_pray(TRUE)) return 0; + if (!can_pray(TRUE)) + return 0; if (wizard && p_type >= 0) { - if (yn("Force the gods to be pleased?") == 'y') { - u.ublesscnt = 0; - if (u.uluck < 0) u.uluck = 0; - if (u.ualign.record <= 0) u.ualign.record = 1; - u.ugangr = 0; - if(p_type < 2) p_type = 3; - } + if (yn("Force the gods to be pleased?") == 'y') { + u.ublesscnt = 0; + if (u.uluck < 0) + u.uluck = 0; + if (u.ualign.record <= 0) + u.ualign.record = 1; + u.ugangr = 0; + if (p_type < 2) + p_type = 3; + } } nomul(-3); multi_reason = "praying"; nomovemsg = "You finish your prayer."; afternmv = prayer_done; - if(p_type == 3 && !Inhell) { - /* if you've been true to your god you can't die while you pray */ - if (!Blind) - You("are surrounded by a shimmering light."); - u.uinvulnerable = TRUE; + if (p_type == 3 && !Inhell) { + /* if you've been true to your god you can't die while you pray */ + if (!Blind) + You("are surrounded by a shimmering light."); + u.uinvulnerable = TRUE; } - return(1); + return (1); } -STATIC_PTR int -prayer_done() /* M. Stephenson (1.0.3b) */ +STATIC_PTR int prayer_done() /* M. Stephenson (1.0.3b) */ { aligntyp alignment = p_aligntyp; u.uinvulnerable = FALSE; - if(p_type == -1) { - godvoice(alignment, - alignment == A_LAWFUL ? - "Vile creature, thou durst call upon me?" : - "Walk no more, perversion of nature!"); - You_feel("like you are falling apart."); - /* KMH -- Gods have mastery over unchanging */ - rehumanize(); - /* no Half_physical_damage adjustment here */ - losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN); - exercise(A_CON, FALSE); - return(1); + if (p_type == -1) { + godvoice(alignment, alignment == A_LAWFUL + ? "Vile creature, thou durst call upon me?" + : "Walk no more, perversion of nature!"); + You_feel("like you are falling apart."); + /* KMH -- Gods have mastery over unchanging */ + rehumanize(); + /* no Half_physical_damage adjustment here */ + losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN); + exercise(A_CON, FALSE); + return (1); } if (Inhell) { - pline("Since you are in Gehennom, %s won't help you.", - align_gname(alignment)); - /* haltingly aligned is least likely to anger */ - if (u.ualign.record <= 0 || rnl(u.ualign.record)) - angrygods(u.ualign.type); - return(0); + pline("Since you are in Gehennom, %s won't help you.", + align_gname(alignment)); + /* haltingly aligned is least likely to anger */ + if (u.ualign.record <= 0 || rnl(u.ualign.record)) + angrygods(u.ualign.type); + return (0); } if (p_type == 0) { - if(on_altar() && u.ualign.type != alignment) - (void) water_prayer(FALSE); - u.ublesscnt += rnz(250); - change_luck(-3); - gods_upset(u.ualign.type); - } else if(p_type == 1) { - if(on_altar() && u.ualign.type != alignment) - (void) water_prayer(FALSE); - angrygods(u.ualign.type); /* naughty */ - } else if(p_type == 2) { - if(water_prayer(FALSE)) { - /* attempted water prayer on a non-coaligned altar */ - u.ublesscnt += rnz(250); - change_luck(-3); - gods_upset(u.ualign.type); - } else pleased(alignment); + if (on_altar() && u.ualign.type != alignment) + (void) water_prayer(FALSE); + u.ublesscnt += rnz(250); + change_luck(-3); + gods_upset(u.ualign.type); + } else if (p_type == 1) { + if (on_altar() && u.ualign.type != alignment) + (void) water_prayer(FALSE); + angrygods(u.ualign.type); /* naughty */ + } else if (p_type == 2) { + if (water_prayer(FALSE)) { + /* attempted water prayer on a non-coaligned altar */ + u.ublesscnt += rnz(250); + change_luck(-3); + gods_upset(u.ualign.type); + } else + pleased(alignment); } else { - /* coaligned */ - if(on_altar()) - (void) water_prayer(TRUE); - pleased(alignment); /* nice */ + /* coaligned */ + if (on_altar()) + (void) water_prayer(TRUE); + pleased(alignment); /* nice */ } - return(1); + return (1); } int doturn() -{ /* Knights & Priest(esse)s only please */ +{ /* Knights & Priest(esse)s only please */ - struct monst *mtmp, *mtmp2; - int once, range, xlev; + struct monst *mtmp, *mtmp2; + int once, range, xlev; - if (!Role_if(PM_PRIEST) && !Role_if(PM_KNIGHT)) { - /* Try to use turn undead spell. */ - if (objects[SPE_TURN_UNDEAD].oc_name_known) { - register int sp_no; - for (sp_no = 0; sp_no < MAXSPELL && - spl_book[sp_no].sp_id != NO_SPELL && - spl_book[sp_no].sp_id != SPE_TURN_UNDEAD; sp_no++); + if (!Role_if(PM_PRIEST) && !Role_if(PM_KNIGHT)) { + /* Try to use turn undead spell. */ + if (objects[SPE_TURN_UNDEAD].oc_name_known) { + register int sp_no; + for (sp_no = 0; + sp_no < MAXSPELL && spl_book[sp_no].sp_id != NO_SPELL + && spl_book[sp_no].sp_id != SPE_TURN_UNDEAD; + sp_no++) + ; - if (sp_no < MAXSPELL && - spl_book[sp_no].sp_id == SPE_TURN_UNDEAD) - return spelleffects(sp_no, TRUE); - } + if (sp_no < MAXSPELL && spl_book[sp_no].sp_id == SPE_TURN_UNDEAD) + return spelleffects(sp_no, TRUE); + } - You("don't know how to turn undead!"); - return(0); - } - u.uconduct.gnostic++; + You("don't know how to turn undead!"); + return (0); + } + u.uconduct.gnostic++; - if ((u.ualign.type != A_CHAOTIC && - (is_demon(youmonst.data) || is_undead(youmonst.data))) || - u.ugangr > 6 /* "Die, mortal!" */) { + if ((u.ualign.type != A_CHAOTIC + && (is_demon(youmonst.data) || is_undead(youmonst.data))) + || u.ugangr > 6 /* "Die, mortal!" */) { + pline("For some reason, %s seems to ignore you.", u_gname()); + aggravate(); + exercise(A_WIS, FALSE); + return (0); + } - pline("For some reason, %s seems to ignore you.", u_gname()); - aggravate(); - exercise(A_WIS, FALSE); - return(0); - } + if (Inhell) { + pline("Since you are in Gehennom, %s won't help you.", u_gname()); + aggravate(); + return (0); + } + pline("Calling upon %s, you chant an arcane formula.", u_gname()); + exercise(A_WIS, TRUE); - if (Inhell) { - pline("Since you are in Gehennom, %s won't help you.", u_gname()); - aggravate(); - return(0); - } - pline("Calling upon %s, you chant an arcane formula.", u_gname()); - exercise(A_WIS, TRUE); + /* note: does not perform unturn_dead() on victims' inventories */ + range = BOLT_LIM + (u.ulevel / 5); /* 5 to 11 */ + range *= range; + once = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; - /* note: does not perform unturn_dead() on victims' inventories */ - range = BOLT_LIM + (u.ulevel / 5); /* 5 to 11 */ - range *= range; - once = 0; - for(mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; + if (DEADMONSTER(mtmp)) + continue; + if (!cansee(mtmp->mx, mtmp->my) || distu(mtmp->mx, mtmp->my) > range) + continue; - if (DEADMONSTER(mtmp)) continue; - if (!cansee(mtmp->mx,mtmp->my) || - distu(mtmp->mx,mtmp->my) > range) continue; - - if (!mtmp->mpeaceful && (is_undead(mtmp->data) || - is_vampshifter(mtmp) || - (is_demon(mtmp->data) && (u.ulevel > (MAXULEV/2))))) { - - mtmp->msleeping = 0; - if (Confusion) { - if (!once++) - pline("Unfortunately, your voice falters."); - mtmp->mflee = 0; - mtmp->mfrozen = 0; - mtmp->mcanmove = 1; - } else if (!resist(mtmp, '\0', 0, TELL)) { - xlev = 6; - switch (mtmp->data->mlet) { - /* this is intentional, lichs are tougher - than zombies. */ - case S_LICH: xlev += 2; /*FALLTHRU*/ - case S_GHOST: xlev += 2; /*FALLTHRU*/ - case S_VAMPIRE: xlev += 2; /*FALLTHRU*/ - case S_WRAITH: xlev += 2; /*FALLTHRU*/ - case S_MUMMY: xlev += 2; /*FALLTHRU*/ - case S_ZOMBIE: - if (u.ulevel >= xlev && - !resist(mtmp, '\0', 0, NOTELL)) { - if (u.ualign.type == A_CHAOTIC) { - mtmp->mpeaceful = 1; - set_malign(mtmp); - } else { /* damn them */ - killed(mtmp); - } - break; - } /* else flee */ - /*FALLTHRU*/ - default: - monflee(mtmp, 0, FALSE, TRUE); - break; - } - } - } - } - nomul(-5); - multi_reason = "trying to turn the monsters"; - nomovemsg = You_can_move_again; - return(1); + if (!mtmp->mpeaceful + && (is_undead(mtmp->data) || is_vampshifter(mtmp) + || (is_demon(mtmp->data) && (u.ulevel > (MAXULEV / 2))))) { + mtmp->msleeping = 0; + if (Confusion) { + if (!once++) + pline("Unfortunately, your voice falters."); + mtmp->mflee = 0; + mtmp->mfrozen = 0; + mtmp->mcanmove = 1; + } else if (!resist(mtmp, '\0', 0, TELL)) { + xlev = 6; + switch (mtmp->data->mlet) { + /* this is intentional, lichs are tougher + than zombies. */ + case S_LICH: + xlev += 2; /*FALLTHRU*/ + case S_GHOST: + xlev += 2; /*FALLTHRU*/ + case S_VAMPIRE: + xlev += 2; /*FALLTHRU*/ + case S_WRAITH: + xlev += 2; /*FALLTHRU*/ + case S_MUMMY: + xlev += 2; /*FALLTHRU*/ + case S_ZOMBIE: + if (u.ulevel >= xlev && !resist(mtmp, '\0', 0, NOTELL)) { + if (u.ualign.type == A_CHAOTIC) { + mtmp->mpeaceful = 1; + set_malign(mtmp); + } else { /* damn them */ + killed(mtmp); + } + break; + } /* else flee */ + /*FALLTHRU*/ + default: + monflee(mtmp, 0, FALSE, TRUE); + break; + } + } + } + } + nomul(-5); + multi_reason = "trying to turn the monsters"; + nomovemsg = You_can_move_again; + return (1); } const char * a_gname() { - return(a_gname_at(u.ux, u.uy)); + return (a_gname_at(u.ux, u.uy)); } -const char * -a_gname_at(x,y) /* returns the name of an altar's deity */ +const char *a_gname_at(x, y) /* returns the name of an altar's deity */ xchar x, y; { - if(!IS_ALTAR(levl[x][y].typ)) return((char *)0); + if (!IS_ALTAR(levl[x][y].typ)) + return ((char *) 0); - return align_gname(a_align(x,y)); + return align_gname(a_align(x, y)); } -const char * -u_gname() /* returns the name of the player's deity */ +const char *u_gname() /* returns the name of the player's deity */ { return align_gname(u.ualign.type); } @@ -1842,32 +1987,43 @@ aligntyp alignment; const char *gnam; switch (alignment) { - case A_NONE: gnam = Moloch; break; - case A_LAWFUL: gnam = urole.lgod; break; - case A_NEUTRAL: gnam = urole.ngod; break; - case A_CHAOTIC: gnam = urole.cgod; break; - default: impossible("unknown alignment."); - gnam = "someone"; break; + case A_NONE: + gnam = Moloch; + break; + case A_LAWFUL: + gnam = urole.lgod; + break; + case A_NEUTRAL: + gnam = urole.ngod; + break; + case A_CHAOTIC: + gnam = urole.cgod; + break; + default: + impossible("unknown alignment."); + gnam = "someone"; + break; } - if (*gnam == '_') ++gnam; + if (*gnam == '_') + ++gnam; return gnam; } static const char *hallu_gods[] = { - "the Flying Spaghetti Monster", /* Church of the FSM */ - "Eris", /* Discordianism */ - "the Martians", /* every science fiction ever */ - "Xom", /* Crawl */ - "AnDoR dRaKoN", /* ADOM */ - "the Central Bank of Yendor", /* economics */ - "Tooth Fairy", /* real world(?) */ - "Om", /* Discworld */ - "Yawgmoth", /* Magic: the Gathering */ - "Morgoth", /* LoTR */ - "Cthulhu", /* Lovecraft */ - "the Ori", /* Stargate */ - "destiny", /* why not? */ - "your Friend the Computer", /* Paranoia */ + "the Flying Spaghetti Monster", /* Church of the FSM */ + "Eris", /* Discordianism */ + "the Martians", /* every science fiction ever */ + "Xom", /* Crawl */ + "AnDoR dRaKoN", /* ADOM */ + "the Central Bank of Yendor", /* economics */ + "Tooth Fairy", /* real world(?) */ + "Om", /* Discworld */ + "Yawgmoth", /* Magic: the Gathering */ + "Morgoth", /* LoTR */ + "Cthulhu", /* Lovecraft */ + "the Ori", /* Stargate */ + "destiny", /* why not? */ + "your Friend the Computer", /* Paranoia */ }; /* hallucination handling for priest/minion names: select a random god @@ -1928,12 +2084,21 @@ aligntyp alignment; const char *gnam, *result = "god"; switch (alignment) { - case A_LAWFUL: gnam = urole.lgod; break; - case A_NEUTRAL: gnam = urole.ngod; break; - case A_CHAOTIC: gnam = urole.cgod; break; - default: gnam = 0; break; + case A_LAWFUL: + gnam = urole.lgod; + break; + case A_NEUTRAL: + gnam = urole.ngod; + break; + case A_CHAOTIC: + gnam = urole.cgod; + break; + default: + gnam = 0; + break; } - if (gnam && *gnam == '_') result = "goddess"; + if (gnam && *gnam == '_') + result = "goddess"; return result; } @@ -1941,45 +2106,48 @@ void altar_wrath(x, y) register int x, y; { - aligntyp altaralign = a_align(x,y); + aligntyp altaralign = a_align(x, y); - if(!strcmp(align_gname(altaralign), u_gname())) { - godvoice(altaralign, "How darest thou desecrate my altar!"); - (void) adjattrib(A_WIS, -1, FALSE); + if (!strcmp(align_gname(altaralign), u_gname())) { + godvoice(altaralign, "How darest thou desecrate my altar!"); + (void) adjattrib(A_WIS, -1, FALSE); } else { - pline("A voice (could it be %s?) whispers:", - align_gname(altaralign)); - verbalize("Thou shalt pay, infidel!"); - change_luck(-1); + pline("A voice (could it be %s?) whispers:", align_gname(altaralign)); + verbalize("Thou shalt pay, infidel!"); + change_luck(-1); } } /* assumes isok() at one space away, but not necessarily at two */ STATIC_OVL boolean -blocked_boulder(dx,dy) -int dx,dy; +blocked_boulder(dx, dy) +int dx, dy; { register struct obj *otmp; long count = 0L; - for(otmp = level.objects[u.ux+dx][u.uy+dy]; otmp; otmp = otmp->nexthere) { - if(otmp->otyp == BOULDER) - count += otmp->quan; + for (otmp = level.objects[u.ux + dx][u.uy + dy]; otmp; + otmp = otmp->nexthere) { + if (otmp->otyp == BOULDER) + count += otmp->quan; } - switch(count) { - case 0: return FALSE; /* no boulders--not blocked */ - case 1: break; /* possibly blocked depending on if it's pushable */ - default: return TRUE; /* >1 boulder--blocked after they push the top - one; don't force them to push it first to find out */ + switch (count) { + case 0: + return FALSE; /* no boulders--not blocked */ + case 1: + break; /* possibly blocked depending on if it's pushable */ + default: + return TRUE; /* >1 boulder--blocked after they push the top + one; don't force them to push it first to find out */ } - if (!isok(u.ux+2*dx, u.uy+2*dy)) - return TRUE; - if (IS_ROCK(levl[u.ux+2*dx][u.uy+2*dy].typ)) - return TRUE; - if (sobj_at(BOULDER, u.ux+2*dx, u.uy+2*dy)) - return TRUE; + if (!isok(u.ux + 2 * dx, u.uy + 2 * dy)) + return TRUE; + if (IS_ROCK(levl[u.ux + 2 * dx][u.uy + 2 * dy].typ)) + return TRUE; + if (sobj_at(BOULDER, u.ux + 2 * dx, u.uy + 2 * dy)) + return TRUE; return FALSE; } diff --git a/src/priest.c b/src/priest.c index 75cb4e93d..bed3c30be 100644 --- a/src/priest.c +++ b/src/priest.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 priest.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 priest.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.36 $ */ /* NetHack 3.6 priest.c $Date: 2012/02/16 02:40:24 $ $Revision: 1.27 $ */ /* Copyright (c) Izchak Miller, Steve Linhart, 1989. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,32 +7,33 @@ #include "mfndpos.h" /* these match the categorizations shown by enlightenment */ -#define ALGN_SINNED (-4) /* worse than strayed (-1..-3) */ -#define ALGN_PIOUS 14 /* better than fervent (9..13) */ +#define ALGN_SINNED (-4) /* worse than strayed (-1..-3) */ +#define ALGN_PIOUS 14 /* better than fervent (9..13) */ -STATIC_DCL boolean FDECL(histemple_at,(struct monst *,XCHAR_P,XCHAR_P)); -STATIC_DCL boolean FDECL(has_shrine,(struct monst *)); +STATIC_DCL boolean FDECL(histemple_at, (struct monst *, XCHAR_P, XCHAR_P)); +STATIC_DCL boolean FDECL(has_shrine, (struct monst *)); void newepri(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) mtmp->mextra = newmextra(); - if (!EPRI(mtmp)) { - EPRI(mtmp) = (struct epri *)alloc(sizeof(struct epri)); - (void) memset((genericptr_t) EPRI(mtmp), 0, sizeof(struct epri)); - } + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + if (!EPRI(mtmp)) { + EPRI(mtmp) = (struct epri *) alloc(sizeof(struct epri)); + (void) memset((genericptr_t) EPRI(mtmp), 0, sizeof(struct epri)); + } } void free_epri(mtmp) struct monst *mtmp; { - if (mtmp->mextra && EPRI(mtmp)) { - free((genericptr_t) EPRI(mtmp)); - EPRI(mtmp) = (struct epri *)0; - } - mtmp->ispriest = 0; + if (mtmp->mextra && EPRI(mtmp)) { + free((genericptr_t) EPRI(mtmp)); + EPRI(mtmp) = (struct epri *) 0; + } + mtmp->ispriest = 0; } /* @@ -40,102 +41,109 @@ struct monst *mtmp; * Valid returns are 1: moved 0: didn't -1: let m_move do it -2: died. */ int -move_special(mtmp,in_his_shop,appr,uondoor,avoid,omx,omy,gx,gy) +move_special(mtmp, in_his_shop, appr, uondoor, avoid, omx, omy, gx, gy) register struct monst *mtmp; boolean in_his_shop; schar appr; -boolean uondoor,avoid; -register xchar omx,omy,gx,gy; +boolean uondoor, avoid; +register xchar omx, omy, gx, gy; { - register xchar nx,ny,nix,niy; - register schar i; - schar chcnt,cnt; - coord poss[9]; - long info[9]; - long allowflags; - struct obj *ib = (struct obj *)0; + register xchar nx, ny, nix, niy; + register schar i; + schar chcnt, cnt; + coord poss[9]; + long info[9]; + long allowflags; + struct obj *ib = (struct obj *) 0; - if(omx == gx && omy == gy) - return(0); - if(mtmp->mconf) { - avoid = FALSE; - appr = 0; - } + if (omx == gx && omy == gy) + return (0); + if (mtmp->mconf) { + avoid = FALSE; + appr = 0; + } - nix = omx; - niy = omy; - if (mtmp->isshk) allowflags = ALLOW_SSM; - else allowflags = ALLOW_SSM | ALLOW_SANCT; - if (passes_walls(mtmp->data)) allowflags |= (ALLOW_ROCK|ALLOW_WALL); - if (throws_rocks(mtmp->data)) allowflags |= ALLOW_ROCK; - if (tunnels(mtmp->data)) allowflags |= ALLOW_DIG; - if (!nohands(mtmp->data) && !verysmall(mtmp->data)) { - allowflags |= OPENDOOR; - if (m_carrying(mtmp, SKELETON_KEY)) allowflags |= BUSTDOOR; - } - if (is_giant(mtmp->data)) allowflags |= BUSTDOOR; - cnt = mfndpos(mtmp, poss, info, allowflags); + nix = omx; + niy = omy; + if (mtmp->isshk) + allowflags = ALLOW_SSM; + else + allowflags = ALLOW_SSM | ALLOW_SANCT; + if (passes_walls(mtmp->data)) + allowflags |= (ALLOW_ROCK | ALLOW_WALL); + if (throws_rocks(mtmp->data)) + allowflags |= ALLOW_ROCK; + if (tunnels(mtmp->data)) + allowflags |= ALLOW_DIG; + if (!nohands(mtmp->data) && !verysmall(mtmp->data)) { + allowflags |= OPENDOOR; + if (m_carrying(mtmp, SKELETON_KEY)) + allowflags |= BUSTDOOR; + } + if (is_giant(mtmp->data)) + allowflags |= BUSTDOOR; + cnt = mfndpos(mtmp, poss, info, allowflags); - if(mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */ - for(i=0; iisshk && avoid && uondoor) { /* perhaps we cannot avoid him */ + for (i = 0; i < cnt; i++) + if (!(info[i] & NOTONL)) + goto pick_move; + avoid = FALSE; + } -#define GDIST(x,y) (dist2(x,y,gx,gy)) +#define GDIST(x, y) (dist2(x, y, gx, gy)) pick_move: - chcnt = 0; - for(i=0; iisshk && - (!in_his_shop || ESHK(mtmp)->following))) { - if(avoid && (info[i] & NOTONL)) - continue; - if((!appr && !rn2(++chcnt)) || - (appr && GDIST(nx,ny) < GDIST(nix,niy))) { - nix = nx; - niy = ny; - } - } - } - if(mtmp->ispriest && avoid && - nix == omx && niy == omy && onlineu(omx,omy)) { - /* might as well move closer as long it's going to stay - * lined up */ - avoid = FALSE; - goto pick_move; - } + chcnt = 0; + for (i = 0; i < cnt; i++) { + nx = poss[i].x; + ny = poss[i].y; + if (IS_ROOM(levl[nx][ny].typ) + || (mtmp->isshk && (!in_his_shop || ESHK(mtmp)->following))) { + if (avoid && (info[i] & NOTONL)) + continue; + if ((!appr && !rn2(++chcnt)) + || (appr && GDIST(nx, ny) < GDIST(nix, niy))) { + nix = nx; + niy = ny; + } + } + } + if (mtmp->ispriest && avoid && nix == omx && niy == omy + && onlineu(omx, omy)) { + /* might as well move closer as long it's going to stay + * lined up */ + avoid = FALSE; + goto pick_move; + } - if(nix != omx || niy != omy) { - remove_monster(omx, omy); - place_monster(mtmp, nix, niy); - newsym(nix,niy); - if (mtmp->isshk && !in_his_shop && inhishop(mtmp)) - check_special_room(FALSE); - if(ib) { - if (cansee(mtmp->mx,mtmp->my)) - pline("%s picks up %s.", Monnam(mtmp), - distant_name(ib,doname)); - obj_extract_self(ib); - (void) mpickobj(mtmp, ib); - } - return(1); - } - return(0); + if (nix != omx || niy != omy) { + remove_monster(omx, omy); + place_monster(mtmp, nix, niy); + newsym(nix, niy); + if (mtmp->isshk && !in_his_shop && inhishop(mtmp)) + check_special_room(FALSE); + if (ib) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s picks up %s.", Monnam(mtmp), + distant_name(ib, doname)); + obj_extract_self(ib); + (void) mpickobj(mtmp, ib); + } + return (1); + } + return (0); } char temple_occupied(array) register char *array; { - register char *ptr; + register char *ptr; - for (ptr = array; *ptr; ptr++) - if (rooms[*ptr - ROOMOFFSET].rtype == TEMPLE) - return(*ptr); - return('\0'); + for (ptr = array; *ptr; ptr++) + if (rooms[*ptr - ROOMOFFSET].rtype == TEMPLE) + return (*ptr); + return ('\0'); } STATIC_OVL boolean @@ -143,20 +151,22 @@ histemple_at(priest, x, y) register struct monst *priest; register xchar x, y; { - return((boolean)((EPRI(priest)->shroom == *in_rooms(x, y, TEMPLE)) && - on_level(&(EPRI(priest)->shrlevel), &u.uz))); + return ((boolean)((EPRI(priest)->shroom == *in_rooms(x, y, TEMPLE)) + && on_level(&(EPRI(priest)->shrlevel), &u.uz))); } boolean inhistemple(priest) struct monst *priest; { - /* make sure we have a priest */ - if (!priest || !priest->ispriest) return FALSE; - /* priest must be on right level and in right room */ - if (!histemple_at(priest, priest->mx, priest->my)) return FALSE; - /* temple room must still contain properly aligned altar */ - return has_shrine(priest); + /* make sure we have a priest */ + if (!priest || !priest->ispriest) + return FALSE; + /* priest must be on right level and in right room */ + if (!histemple_at(priest, priest->mx, priest->my)) + return FALSE; + /* temple room must still contain properly aligned altar */ + return has_shrine(priest); } /* @@ -166,91 +176,93 @@ int pri_move(priest) register struct monst *priest; { - register xchar gx,gy,omx,omy; - schar temple; - boolean avoid = TRUE; + register xchar gx, gy, omx, omy; + schar temple; + boolean avoid = TRUE; - omx = priest->mx; - omy = priest->my; + omx = priest->mx; + omy = priest->my; - if(!histemple_at(priest, omx, omy)) return(-1); + if (!histemple_at(priest, omx, omy)) + return (-1); - temple = EPRI(priest)->shroom; + temple = EPRI(priest)->shroom; - gx = EPRI(priest)->shrpos.x; - gy = EPRI(priest)->shrpos.y; + gx = EPRI(priest)->shrpos.x; + gy = EPRI(priest)->shrpos.y; - gx += rn1(3,-1); /* mill around the altar */ - gy += rn1(3,-1); + gx += rn1(3, -1); /* mill around the altar */ + gy += rn1(3, -1); - if(!priest->mpeaceful || - (Conflict && !resist(priest, RING_CLASS, 0, 0))) { - if(monnear(priest, u.ux, u.uy)) { - if(Displaced) - Your("displaced image doesn't fool %s!", - mon_nam(priest)); - (void) mattacku(priest); - return(0); - } else if(index(u.urooms, temple)) { - /* chase player if inside temple & can see him */ - if(priest->mcansee && m_canseeu(priest)) { - gx = u.ux; - gy = u.uy; - } - avoid = FALSE; - } - } else if(Invis) avoid = FALSE; + if (!priest->mpeaceful + || (Conflict && !resist(priest, RING_CLASS, 0, 0))) { + if (monnear(priest, u.ux, u.uy)) { + if (Displaced) + Your("displaced image doesn't fool %s!", mon_nam(priest)); + (void) mattacku(priest); + return (0); + } else if (index(u.urooms, temple)) { + /* chase player if inside temple & can see him */ + if (priest->mcansee && m_canseeu(priest)) { + gx = u.ux; + gy = u.uy; + } + avoid = FALSE; + } + } else if (Invis) + avoid = FALSE; - return(move_special(priest,FALSE,TRUE,FALSE,avoid,omx,omy,gx,gy)); + return ( + move_special(priest, FALSE, TRUE, FALSE, avoid, omx, omy, gx, gy)); } /* exclusively for mktemple() */ void priestini(lvl, sroom, sx, sy, sanctum) -d_level *lvl; +d_level *lvl; struct mkroom *sroom; int sx, sy; -boolean sanctum; /* is it the seat of the high priest? */ +boolean sanctum; /* is it the seat of the high priest? */ { - struct monst *priest; - struct obj *otmp; - int cnt; + struct monst *priest; + struct obj *otmp; + int cnt; - if(MON_AT(sx+1, sy)) - (void) rloc(m_at(sx+1, sy), FALSE); /* insurance */ + if (MON_AT(sx + 1, sy)) + (void) rloc(m_at(sx + 1, sy), FALSE); /* insurance */ - priest = makemon(&mons[sanctum ? PM_HIGH_PRIEST : PM_ALIGNED_PRIEST], - sx + 1, sy, MM_EPRI); - if (priest) { - EPRI(priest)->shroom = (schar)((sroom - rooms) + ROOMOFFSET); - EPRI(priest)->shralign = Amask2align(levl[sx][sy].altarmask); - EPRI(priest)->shrpos.x = sx; - EPRI(priest)->shrpos.y = sy; - assign_level(&(EPRI(priest)->shrlevel), lvl); - priest->mtrapseen = ~0; /* traps are known */ - priest->mpeaceful = 1; - priest->ispriest = 1; - priest->isminion = 0; - priest->msleeping = 0; - set_malign(priest); /* mpeaceful may have changed */ + priest = makemon(&mons[sanctum ? PM_HIGH_PRIEST : PM_ALIGNED_PRIEST], + sx + 1, sy, MM_EPRI); + if (priest) { + EPRI(priest)->shroom = (schar)((sroom - rooms) + ROOMOFFSET); + EPRI(priest)->shralign = Amask2align(levl[sx][sy].altarmask); + EPRI(priest)->shrpos.x = sx; + EPRI(priest)->shrpos.y = sy; + assign_level(&(EPRI(priest)->shrlevel), lvl); + priest->mtrapseen = ~0; /* traps are known */ + priest->mpeaceful = 1; + priest->ispriest = 1; + priest->isminion = 0; + priest->msleeping = 0; + set_malign(priest); /* mpeaceful may have changed */ - /* now his/her goodies... */ - if(sanctum && EPRI(priest)->shralign == A_NONE && - on_level(&sanctum_level, &u.uz)) { - (void) mongets(priest, AMULET_OF_YENDOR); - } - /* 2 to 4 spellbooks */ - for (cnt = rn1(3,2); cnt > 0; --cnt) { - (void) mpickobj(priest, mkobj(SPBOOK_CLASS, FALSE)); - } - /* robe [via makemon()] */ - if (rn2(2) && (otmp = which_armor(priest, W_ARMC)) != 0) { - if (p_coaligned(priest)) - uncurse(otmp); - else - curse(otmp); - } - } + /* now his/her goodies... */ + if (sanctum && EPRI(priest)->shralign == A_NONE + && on_level(&sanctum_level, &u.uz)) { + (void) mongets(priest, AMULET_OF_YENDOR); + } + /* 2 to 4 spellbooks */ + for (cnt = rn1(3, 2); cnt > 0; --cnt) { + (void) mpickobj(priest, mkobj(SPBOOK_CLASS, FALSE)); + } + /* robe [via makemon()] */ + if (rn2(2) && (otmp = which_armor(priest, W_ARMC)) != 0) { + if (p_coaligned(priest)) + uncurse(otmp); + else + curse(otmp); + } + } } /* get a monster's alignment type without caller needing EPRI & EMIN */ @@ -258,11 +270,12 @@ aligntyp mon_aligntyp(mon) struct monst *mon; { - aligntyp algn = mon->ispriest ? EPRI(mon)->shralign : - mon->isminion ? EMIN(mon)->min_align : - mon->data->maligntyp; + aligntyp algn = mon->ispriest ? EPRI(mon)->shralign + : mon->isminion ? EMIN(mon)->min_align + : mon->data->maligntyp; - if (algn == A_NONE) return A_NONE; /* negative but differs from chaotic */ + if (algn == A_NONE) + return A_NONE; /* negative but differs from chaotic */ return (algn > 0) ? A_LAWFUL : (algn < 0) ? A_CHAOTIC : A_NEUTRAL; } @@ -279,47 +292,49 @@ struct monst *mon; char * priestname(mon, pname) register struct monst *mon; -char *pname; /* caller-supplied output buffer */ +char *pname; /* caller-supplied output buffer */ { boolean do_hallu = Hallucination, - aligned_priest = mon->data == &mons[PM_ALIGNED_PRIEST], - high_priest = mon->data == &mons[PM_HIGH_PRIEST]; + aligned_priest = mon->data == &mons[PM_ALIGNED_PRIEST], + high_priest = mon->data == &mons[PM_HIGH_PRIEST]; char whatcode = '\0'; const char *what = do_hallu ? rndmonnam(&whatcode) : mon->data->mname; - if (!mon->ispriest && !mon->isminion) /* should never happen... */ - return strcpy(pname, what); /* caller must be confused */ + if (!mon->ispriest && !mon->isminion) /* should never happen... */ + return strcpy(pname, what); /* caller must be confused */ *pname = '\0'; - if (!do_hallu || !bogon_is_pname(whatcode)) Strcat(pname, "the "); - if (mon->minvis) Strcat(pname, "invisible "); + if (!do_hallu || !bogon_is_pname(whatcode)) + Strcat(pname, "the "); + if (mon->minvis) + Strcat(pname, "invisible "); if (mon->isminion && EMIN(mon)->renegade) - Strcat(pname, "renegade "); + Strcat(pname, "renegade "); - if (mon->ispriest || aligned_priest) { /* high_priest implies ispriest */ - if (!aligned_priest && !high_priest) { - ; /* polymorphed priest; use ``what'' as is */ - } else { - if (high_priest) - Strcat(pname, "high "); - if (Hallucination) - what = "poohbah"; - else if (mon->female) - what = "priestess"; - else - what = "priest"; - } + if (mon->ispriest || aligned_priest) { /* high_priest implies ispriest */ + if (!aligned_priest && !high_priest) { + ; /* polymorphed priest; use ``what'' as is */ + } else { + if (high_priest) + Strcat(pname, "high "); + if (Hallucination) + what = "poohbah"; + else if (mon->female) + what = "priestess"; + else + what = "priest"; + } } else { - if (mon->mtame && !strcmpi(what, "Angel")) - Strcat(pname, "guardian "); + if (mon->mtame && !strcmpi(what, "Angel")) + Strcat(pname, "guardian "); } Strcat(pname, what); /* same as distant_monnam(), more or less... */ - if (do_hallu || !high_priest || !Is_astralevel(&u.uz) || - distu(mon->mx, mon->my) <= 2 || program_state.gameover) { - Strcat(pname, " of "); - Strcat(pname, halu_gname(mon_aligntyp(mon))); + if (do_hallu || !high_priest || !Is_astralevel(&u.uz) + || distu(mon->mx, mon->my) <= 2 || program_state.gameover) { + Strcat(pname, " of "); + Strcat(pname, halu_gname(mon_aligntyp(mon))); } return pname; } @@ -328,37 +343,40 @@ boolean p_coaligned(priest) struct monst *priest; { - return((boolean)(u.ualign.type == ((int)EPRI(priest)->shralign))); + return ((boolean)(u.ualign.type == ((int) EPRI(priest)->shralign))); } STATIC_OVL boolean has_shrine(pri) struct monst *pri; { - struct rm *lev; - struct epri *epri_p; + struct rm *lev; + struct epri *epri_p; - if (!pri || !pri->ispriest) return FALSE; - epri_p = EPRI(pri); - lev = &levl[epri_p->shrpos.x][epri_p->shrpos.y]; - if (!IS_ALTAR(lev->typ) || !(lev->altarmask & AM_SHRINE)) return FALSE; - return (boolean)(epri_p->shralign == - (Amask2align(lev->altarmask & ~AM_SHRINE))); + if (!pri || !pri->ispriest) + return FALSE; + epri_p = EPRI(pri); + lev = &levl[epri_p->shrpos.x][epri_p->shrpos.y]; + if (!IS_ALTAR(lev->typ) || !(lev->altarmask & AM_SHRINE)) + return FALSE; + return (boolean)(epri_p->shralign + == (Amask2align(lev->altarmask & ~AM_SHRINE))); } struct monst * findpriest(roomno) char roomno; { - register struct monst *mtmp; + register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if(mtmp->ispriest && (EPRI(mtmp)->shroom == roomno) && - histemple_at(mtmp,mtmp->mx,mtmp->my)) - return(mtmp); - } - return (struct monst *)0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->ispriest && (EPRI(mtmp)->shroom == roomno) + && histemple_at(mtmp, mtmp->mx, mtmp->my)) + return (mtmp); + } + return (struct monst *) 0; } /* called from check_special_room() when the player enters the temple room */ @@ -374,110 +392,121 @@ int roomno; char buf[BUFSZ]; /* don't do anything if hero is already in the room */ - if (temple_occupied(u.urooms0)) return; + if (temple_occupied(u.urooms0)) + return; - if ((priest = findpriest((char)roomno)) != 0) { - /* tended */ + if ((priest = findpriest((char) roomno)) != 0) { + /* tended */ - epri_p = EPRI(priest); - shrined = has_shrine(priest); - sanctum = (priest->data == &mons[PM_HIGH_PRIEST] && - (Is_sanctum(&u.uz) || In_endgame(&u.uz))); - can_speak = (priest->mcanmove && !priest->msleeping); - if (can_speak && !Deaf && moves >= epri_p->intone_time) { - unsigned save_priest = priest->ispriest; + epri_p = EPRI(priest); + shrined = has_shrine(priest); + sanctum = (priest->data == &mons[PM_HIGH_PRIEST] + && (Is_sanctum(&u.uz) || In_endgame(&u.uz))); + can_speak = (priest->mcanmove && !priest->msleeping); + if (can_speak && !Deaf && moves >= epri_p->intone_time) { + unsigned save_priest = priest->ispriest; - /* don't reveal the altar's owner upon temple entry in - the endgame; for the Sanctum, the next message names - Moloch so suppress the "of Moloch" for him here too */ - if (sanctum && !Hallucination) priest->ispriest = 0; - pline("%s intones:", - canseemon(priest) ? Monnam(priest) : "A nearby voice"); - priest->ispriest = save_priest; - epri_p->intone_time = moves + (long)d(10, 500); /* ~2505 */ - /* make sure that we don't suppress entry message when - we've just given its "priest intones" introduction */ - epri_p->enter_time = 0L; - } - msg1 = msg2 = 0; - if (sanctum && Is_sanctum(&u.uz)) { - if (priest->mpeaceful) { - /* first time inside */ - msg1 = "Infidel, you have entered Moloch's Sanctum!"; - msg2 = "Be gone!"; - priest->mpeaceful = 0; - /* became angry voluntarily; no penalty for attacking him */ - set_malign(priest); - } else { - /* repeat visit, or attacked priest before entering */ - msg1 = "You desecrate this place by your presence!"; - } - } else if (moves >= epri_p->enter_time) { - Sprintf(buf, "Pilgrim, you enter a %s place!", - !shrined ? "desecrated" : "sacred"); - msg1 = buf; - } - if (msg1 && can_speak && !Deaf) { - verbalize1(msg1); - if (msg2) verbalize1(msg2); - epri_p->enter_time = moves + (long)d(10, 100); /* ~505 */ - } - if (!sanctum) { - if (!shrined || !p_coaligned(priest) || - u.ualign.record <= ALGN_SINNED) { - msg1 = "have a%s forbidding feeling..."; - msg2 = (!shrined || !p_coaligned(priest)) ? "" : " strange"; - this_time = &epri_p->hostile_time; - other_time = &epri_p->peaceful_time; - } else { - msg1 = "experience %s sense of peace."; - msg2 = (u.ualign.record >= ALGN_PIOUS) ? "a" : "an unusual"; - this_time = &epri_p->peaceful_time; - other_time = &epri_p->hostile_time; - } - /* give message if we haven't seen it recently or - if alignment update has caused it to switch from - forbidding to sense-of-peace or vice versa */ - if (moves >= *this_time || *other_time >= *this_time) { - You(msg1, msg2); - *this_time = moves + (long)d(10, 20); /* ~55 */ - /* avoid being tricked by the RNG: switch might have just - happened and previous random threshold could be larger */ - if (*this_time <= *other_time) *other_time = *this_time - 1L; - } - } - /* recognize the Valley of the Dead and Moloch's Sanctum - once hero has encountered the temple priest on those levels */ - mapseen_temple(priest); + /* don't reveal the altar's owner upon temple entry in + the endgame; for the Sanctum, the next message names + Moloch so suppress the "of Moloch" for him here too */ + if (sanctum && !Hallucination) + priest->ispriest = 0; + pline("%s intones:", + canseemon(priest) ? Monnam(priest) : "A nearby voice"); + priest->ispriest = save_priest; + epri_p->intone_time = moves + (long) d(10, 500); /* ~2505 */ + /* make sure that we don't suppress entry message when + we've just given its "priest intones" introduction */ + epri_p->enter_time = 0L; + } + msg1 = msg2 = 0; + if (sanctum && Is_sanctum(&u.uz)) { + if (priest->mpeaceful) { + /* first time inside */ + msg1 = "Infidel, you have entered Moloch's Sanctum!"; + msg2 = "Be gone!"; + priest->mpeaceful = 0; + /* became angry voluntarily; no penalty for attacking him */ + set_malign(priest); + } else { + /* repeat visit, or attacked priest before entering */ + msg1 = "You desecrate this place by your presence!"; + } + } else if (moves >= epri_p->enter_time) { + Sprintf(buf, "Pilgrim, you enter a %s place!", + !shrined ? "desecrated" : "sacred"); + msg1 = buf; + } + if (msg1 && can_speak && !Deaf) { + verbalize1(msg1); + if (msg2) + verbalize1(msg2); + epri_p->enter_time = moves + (long) d(10, 100); /* ~505 */ + } + if (!sanctum) { + if (!shrined || !p_coaligned(priest) + || u.ualign.record <= ALGN_SINNED) { + msg1 = "have a%s forbidding feeling..."; + msg2 = (!shrined || !p_coaligned(priest)) ? "" : " strange"; + this_time = &epri_p->hostile_time; + other_time = &epri_p->peaceful_time; + } else { + msg1 = "experience %s sense of peace."; + msg2 = (u.ualign.record >= ALGN_PIOUS) ? "a" : "an unusual"; + this_time = &epri_p->peaceful_time; + other_time = &epri_p->hostile_time; + } + /* give message if we haven't seen it recently or + if alignment update has caused it to switch from + forbidding to sense-of-peace or vice versa */ + if (moves >= *this_time || *other_time >= *this_time) { + You(msg1, msg2); + *this_time = moves + (long) d(10, 20); /* ~55 */ + /* avoid being tricked by the RNG: switch might have just + happened and previous random threshold could be larger */ + if (*this_time <= *other_time) + *other_time = *this_time - 1L; + } + } + /* recognize the Valley of the Dead and Moloch's Sanctum + once hero has encountered the temple priest on those levels */ + mapseen_temple(priest); } else { - /* untended */ + /* untended */ - switch (rn2(4)) { - case 0: You("have an eerie feeling..."); break; - case 1: You_feel("like you are being watched."); break; - case 2: pline("A shiver runs down your %s.", - body_part(SPINE)); break; - default: break; /* no message; unfortunately there's no - EPRI(priest)->eerie_time available to - make sure we give one the first time */ - } - if (!rn2(5) && - (mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS)) != 0) { - /* [TODO: alter this (at a minimum, by switching from - an exclamation to a simple declaration) if hero has - already killed enough ghosts.] */ - if (canspotmon(mtmp)) - pline("An enormous ghost appears next to you!"); - else - You("sense a presence close by!"); - mtmp->mpeaceful = 0; - set_malign(mtmp); - if (flags.verbose) - You("are frightened to death, and unable to move."); - nomul(-3); - multi_reason = "being terrified of a demon"; - nomovemsg = "You regain your composure."; - } + switch (rn2(4)) { + case 0: + You("have an eerie feeling..."); + break; + case 1: + You_feel("like you are being watched."); + break; + case 2: + pline("A shiver runs down your %s.", body_part(SPINE)); + break; + default: + break; /* no message; unfortunately there's no + EPRI(priest)->eerie_time available to + make sure we give one the first time */ + } + if (!rn2(5) + && (mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS)) + != 0) { + /* [TODO: alter this (at a minimum, by switching from + an exclamation to a simple declaration) if hero has + already killed enough ghosts.] */ + if (canspotmon(mtmp)) + pline("An enormous ghost appears next to you!"); + else + You("sense a presence close by!"); + mtmp->mpeaceful = 0; + set_malign(mtmp); + if (flags.verbose) + You("are frightened to death, and unable to move."); + nomul(-3); + multi_reason = "being terrified of a demon"; + nomovemsg = "You regain your composure."; + } } } @@ -490,119 +519,123 @@ struct monst *priest; struct epri *epri_p = priest->ispriest ? EPRI(priest) : 0; if (!epri_p) { - impossible("attempting to manipulate shrine data for non-priest?"); - return; + impossible("attempting to manipulate shrine data for non-priest?"); + return; } - epri_p->intone_time = epri_p->enter_time = - epri_p->peaceful_time = epri_p->hostile_time = 0L; + epri_p->intone_time = epri_p->enter_time = epri_p->peaceful_time = + epri_p->hostile_time = 0L; } void priest_talk(priest) register struct monst *priest; { - boolean coaligned = p_coaligned(priest); - boolean strayed = (u.ualign.record < 0); + boolean coaligned = p_coaligned(priest); + boolean strayed = (u.ualign.record < 0); - /* KMH, conduct */ - u.uconduct.gnostic++; + /* KMH, conduct */ + u.uconduct.gnostic++; - if(priest->mflee || (!priest->ispriest && coaligned && strayed)) { - pline("%s doesn't want anything to do with you!", - Monnam(priest)); - priest->mpeaceful = 0; - return; - } + if (priest->mflee || (!priest->ispriest && coaligned && strayed)) { + pline("%s doesn't want anything to do with you!", Monnam(priest)); + priest->mpeaceful = 0; + return; + } - /* priests don't chat unless peaceful and in their own temple */ - if(!histemple_at(priest,priest->mx,priest->my) || - !priest->mpeaceful || !priest->mcanmove || priest->msleeping) { - static const char *cranky_msg[3] = { - "Thou wouldst have words, eh? I'll give thee a word or two!", - "Talk? Here is what I have to say!", - "Pilgrim, I would speak no longer with thee." - }; + /* priests don't chat unless peaceful and in their own temple */ + if (!histemple_at(priest, priest->mx, priest->my) || !priest->mpeaceful + || !priest->mcanmove || priest->msleeping) { + static const char *cranky_msg[3] = { + "Thou wouldst have words, eh? I'll give thee a word or two!", + "Talk? Here is what I have to say!", + "Pilgrim, I would speak no longer with thee." + }; - if(!priest->mcanmove || priest->msleeping) { - pline("%s breaks out of %s reverie!", - Monnam(priest), mhis(priest)); - priest->mfrozen = priest->msleeping = 0; - priest->mcanmove = 1; - } - priest->mpeaceful = 0; - verbalize1(cranky_msg[rn2(3)]); - return; - } + if (!priest->mcanmove || priest->msleeping) { + pline("%s breaks out of %s reverie!", Monnam(priest), + mhis(priest)); + priest->mfrozen = priest->msleeping = 0; + priest->mcanmove = 1; + } + priest->mpeaceful = 0; + verbalize1(cranky_msg[rn2(3)]); + return; + } - /* you desecrated the temple and now you want to chat? */ - if(priest->mpeaceful && *in_rooms(priest->mx, priest->my, TEMPLE) && - !has_shrine(priest)) { - verbalize("Begone! Thou desecratest this holy place with thy presence."); - priest->mpeaceful = 0; - return; - } - if(!money_cnt(invent)) { - if(coaligned && !strayed) { - long pmoney = money_cnt(priest->minvent); - if (pmoney > 0L) { - /* Note: two bits is actually 25 cents. Hmm. */ - pline("%s gives you %s for an ale.", Monnam(priest), - (pmoney == 1L) ? "one bit" : "two bits"); - money2u(priest, pmoney > 1L ? 2 : 1); - } else - pline("%s preaches the virtues of poverty.", Monnam(priest)); - exercise(A_WIS, TRUE); - } else - pline("%s is not interested.", Monnam(priest)); - return; - } else { - long offer; + /* you desecrated the temple and now you want to chat? */ + if (priest->mpeaceful && *in_rooms(priest->mx, priest->my, TEMPLE) + && !has_shrine(priest)) { + verbalize( + "Begone! Thou desecratest this holy place with thy presence."); + priest->mpeaceful = 0; + return; + } + if (!money_cnt(invent)) { + if (coaligned && !strayed) { + long pmoney = money_cnt(priest->minvent); + if (pmoney > 0L) { + /* Note: two bits is actually 25 cents. Hmm. */ + pline("%s gives you %s for an ale.", Monnam(priest), + (pmoney == 1L) ? "one bit" : "two bits"); + money2u(priest, pmoney > 1L ? 2 : 1); + } else + pline("%s preaches the virtues of poverty.", Monnam(priest)); + exercise(A_WIS, TRUE); + } else + pline("%s is not interested.", Monnam(priest)); + return; + } else { + long offer; - pline("%s asks you for a contribution for the temple.", - Monnam(priest)); - if((offer = bribe(priest)) == 0) { - verbalize("Thou shalt regret thine action!"); - if(coaligned) adjalign(-1); - } else if(offer < (u.ulevel * 200)) { - if(money_cnt(invent) > (offer * 2L)) verbalize("Cheapskate."); - else { - verbalize("I thank thee for thy contribution."); - /* give player some token */ - exercise(A_WIS, TRUE); - } - } else if(offer < (u.ulevel * 400)) { - verbalize("Thou art indeed a pious individual."); - if(money_cnt(invent) < (offer * 2L)) { - if (coaligned && u.ualign.record <= ALGN_SINNED) - adjalign(1); - verbalize("I bestow upon thee a blessing."); - incr_itimeout(&HClairvoyant, rn1(500,500)); - } - } else if(offer < (u.ulevel * 600) && - /* u.ublessed is only active when Protection is - enabled via something other than worn gear - (theft by gremlin clears the intrinsic but not - its former magnitude, making it recoverable) */ - (!(HProtection & INTRINSIC) || - (u.ublessed < 20 && - (u.ublessed < 9 || !rn2(u.ublessed))))) { - verbalize("Thy devotion has been rewarded."); - if (!(HProtection & INTRINSIC)) { - HProtection |= FROMOUTSIDE; - if (!u.ublessed) u.ublessed = rn1(3, 2); - } else u.ublessed++; - } else { - verbalize("Thy selfless generosity is deeply appreciated."); - if(money_cnt(invent) < (offer * 2L) && coaligned) { - if(strayed && (moves - u.ucleansed) > 5000L) { - u.ualign.record = 0; /* cleanse thee */ - u.ucleansed = moves; - } else { - adjalign(2); - } - } - } - } + pline("%s asks you for a contribution for the temple.", + Monnam(priest)); + if ((offer = bribe(priest)) == 0) { + verbalize("Thou shalt regret thine action!"); + if (coaligned) + adjalign(-1); + } else if (offer < (u.ulevel * 200)) { + if (money_cnt(invent) > (offer * 2L)) + verbalize("Cheapskate."); + else { + verbalize("I thank thee for thy contribution."); + /* give player some token */ + exercise(A_WIS, TRUE); + } + } else if (offer < (u.ulevel * 400)) { + verbalize("Thou art indeed a pious individual."); + if (money_cnt(invent) < (offer * 2L)) { + if (coaligned && u.ualign.record <= ALGN_SINNED) + adjalign(1); + verbalize("I bestow upon thee a blessing."); + incr_itimeout(&HClairvoyant, rn1(500, 500)); + } + } else if (offer < (u.ulevel * 600) && + /* u.ublessed is only active when Protection is + enabled via something other than worn gear + (theft by gremlin clears the intrinsic but not + its former magnitude, making it recoverable) */ + (!(HProtection & INTRINSIC) + || (u.ublessed < 20 + && (u.ublessed < 9 || !rn2(u.ublessed))))) { + verbalize("Thy devotion has been rewarded."); + if (!(HProtection & INTRINSIC)) { + HProtection |= FROMOUTSIDE; + if (!u.ublessed) + u.ublessed = rn1(3, 2); + } else + u.ublessed++; + } else { + verbalize("Thy selfless generosity is deeply appreciated."); + if (money_cnt(invent) < (offer * 2L) && coaligned) { + if (strayed && (moves - u.ucleansed) > 5000L) { + u.ualign.record = 0; /* cleanse thee */ + u.ucleansed = moves; + } else { + adjalign(2); + } + } + } + } } struct monst * @@ -612,162 +645,179 @@ aligntyp alignment; xchar x, y; boolean peaceful; { - register struct monst *roamer; - register boolean coaligned = (u.ualign.type == alignment); + register struct monst *roamer; + register boolean coaligned = (u.ualign.type == alignment); -#if 0 /* this was due to permonst's pxlth field which is now gone */ +#if 0 /* this was due to permonst's pxlth field which is now gone */ if (ptr != &mons[PM_ALIGNED_PRIEST] && ptr != &mons[PM_ANGEL]) return((struct monst *)0); #endif - if (MON_AT(x, y)) (void) rloc(m_at(x, y), FALSE); /* insurance */ + if (MON_AT(x, y)) + (void) rloc(m_at(x, y), FALSE); /* insurance */ - if (!(roamer = makemon(ptr, x, y, MM_ADJACENTOK|MM_EMIN))) - return((struct monst *)0); + if (!(roamer = makemon(ptr, x, y, MM_ADJACENTOK | MM_EMIN))) + return ((struct monst *) 0); - EMIN(roamer)->min_align = alignment; - EMIN(roamer)->renegade = (coaligned && !peaceful); - roamer->ispriest = 0; - roamer->isminion = 1; - roamer->mtrapseen = ~0; /* traps are known */ - roamer->mpeaceful = peaceful; - roamer->msleeping = 0; - set_malign(roamer); /* peaceful may have changed */ + EMIN(roamer)->min_align = alignment; + EMIN(roamer)->renegade = (coaligned && !peaceful); + roamer->ispriest = 0; + roamer->isminion = 1; + roamer->mtrapseen = ~0; /* traps are known */ + roamer->mpeaceful = peaceful; + roamer->msleeping = 0; + set_malign(roamer); /* peaceful may have changed */ - /* MORE TO COME */ - return(roamer); + /* MORE TO COME */ + return (roamer); } void reset_hostility(roamer) register struct monst *roamer; { - if (!roamer->isminion) return; - if (roamer->data != &mons[PM_ALIGNED_PRIEST] && - roamer->data != &mons[PM_ANGEL]) return; + if (!roamer->isminion) + return; + if (roamer->data != &mons[PM_ALIGNED_PRIEST] + && roamer->data != &mons[PM_ANGEL]) + return; - if (EMIN(roamer)->min_align != u.ualign.type) { - roamer->mpeaceful = roamer->mtame = 0; - set_malign(roamer); - } - newsym(roamer->mx, roamer->my); + if (EMIN(roamer)->min_align != u.ualign.type) { + roamer->mpeaceful = roamer->mtame = 0; + set_malign(roamer); + } + newsym(roamer->mx, roamer->my); } boolean in_your_sanctuary(mon, x, y) -struct monst *mon; /* if non-null, overrides */ +struct monst *mon; /* if non-null, overrides */ xchar x, y; { - register char roomno; - register struct monst *priest; + register char roomno; + register struct monst *priest; - if (mon) { - if (is_minion(mon->data) || is_rider(mon->data)) return FALSE; - x = mon->mx, y = mon->my; - } - if (u.ualign.record <= ALGN_SINNED) /* sinned or worse */ - return FALSE; - if ((roomno = temple_occupied(u.urooms)) == 0 || - roomno != *in_rooms(x, y, TEMPLE)) - return FALSE; - if ((priest = findpriest(roomno)) == 0) - return FALSE; - return (boolean)(has_shrine(priest) && - p_coaligned(priest) && - priest->mpeaceful); + if (mon) { + if (is_minion(mon->data) || is_rider(mon->data)) + return FALSE; + x = mon->mx, y = mon->my; + } + if (u.ualign.record <= ALGN_SINNED) /* sinned or worse */ + return FALSE; + if ((roomno = temple_occupied(u.urooms)) == 0 + || roomno != *in_rooms(x, y, TEMPLE)) + return FALSE; + if ((priest = findpriest(roomno)) == 0) + return FALSE; + return (boolean)(has_shrine(priest) && p_coaligned(priest) + && priest->mpeaceful); } -void -ghod_hitsu(priest) /* when attacking "priest" in his temple */ +void ghod_hitsu(priest) /* when attacking "priest" in his temple */ struct monst *priest; { - int x, y, ax, ay, roomno = (int)temple_occupied(u.urooms); - struct mkroom *troom; + int x, y, ax, ay, roomno = (int) temple_occupied(u.urooms); + struct mkroom *troom; - if (!roomno || !has_shrine(priest)) - return; + if (!roomno || !has_shrine(priest)) + return; - ax = x = EPRI(priest)->shrpos.x; - ay = y = EPRI(priest)->shrpos.y; - troom = &rooms[roomno - ROOMOFFSET]; + ax = x = EPRI(priest)->shrpos.x; + ay = y = EPRI(priest)->shrpos.y; + troom = &rooms[roomno - ROOMOFFSET]; - if ((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y, 1)) { - if(IS_DOOR(levl[u.ux][u.uy].typ)) { - if(u.ux == troom->lx - 1) { - x = troom->hx; - y = u.uy; - } else if(u.ux == troom->hx + 1) { - x = troom->lx; - y = u.uy; - } else if(u.uy == troom->ly - 1) { - x = u.ux; - y = troom->hy; - } else if(u.uy == troom->hy + 1) { - x = u.ux; - y = troom->ly; - } - } else { - switch(rn2(4)) { - case 0: x = u.ux; y = troom->ly; break; - case 1: x = u.ux; y = troom->hy; break; - case 2: x = troom->lx; y = u.uy; break; - default: x = troom->hx; y = u.uy; break; - } - } - if (!linedup(u.ux, u.uy, x, y, 1)) return; - } + if ((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y, 1)) { + if (IS_DOOR(levl[u.ux][u.uy].typ)) { + if (u.ux == troom->lx - 1) { + x = troom->hx; + y = u.uy; + } else if (u.ux == troom->hx + 1) { + x = troom->lx; + y = u.uy; + } else if (u.uy == troom->ly - 1) { + x = u.ux; + y = troom->hy; + } else if (u.uy == troom->hy + 1) { + x = u.ux; + y = troom->ly; + } + } else { + switch (rn2(4)) { + case 0: + x = u.ux; + y = troom->ly; + break; + case 1: + x = u.ux; + y = troom->hy; + break; + case 2: + x = troom->lx; + y = u.uy; + break; + default: + x = troom->hx; + y = u.uy; + break; + } + } + if (!linedup(u.ux, u.uy, x, y, 1)) + return; + } - switch(rn2(3)) { - case 0: - pline("%s roars in anger: \"Thou shalt suffer!\"", - a_gname_at(ax, ay)); - break; - case 1: - pline("%s voice booms: \"How darest thou harm my servant!\"", - s_suffix(a_gname_at(ax, ay))); - break; - default: - pline("%s roars: \"Thou dost profane my shrine!\"", - a_gname_at(ax, ay)); - break; - } + switch (rn2(3)) { + case 0: + pline("%s roars in anger: \"Thou shalt suffer!\"", + a_gname_at(ax, ay)); + break; + case 1: + pline("%s voice booms: \"How darest thou harm my servant!\"", + s_suffix(a_gname_at(ax, ay))); + break; + default: + pline("%s roars: \"Thou dost profane my shrine!\"", + a_gname_at(ax, ay)); + break; + } - buzz(-10-(AD_ELEC-1), 6, x, y, sgn(tbx), sgn(tby)); /* bolt of lightning */ - exercise(A_WIS, FALSE); + buzz(-10 - (AD_ELEC - 1), 6, x, y, sgn(tbx), + sgn(tby)); /* bolt of lightning */ + exercise(A_WIS, FALSE); } void angry_priest() { - register struct monst *priest; - struct rm *lev; + register struct monst *priest; + struct rm *lev; - if ((priest = findpriest(temple_occupied(u.urooms))) != 0) { - struct epri *eprip = EPRI(priest); + if ((priest = findpriest(temple_occupied(u.urooms))) != 0) { + struct epri *eprip = EPRI(priest); - wakeup(priest); - /* - * If the altar has been destroyed or converted, let the - * priest run loose. - * (When it's just a conversion and there happens to be - * a fresh corpse nearby, the priest ought to have an - * opportunity to try converting it back; maybe someday...) - */ - lev = &levl[eprip->shrpos.x][eprip->shrpos.y]; - if (!IS_ALTAR(lev->typ) || - ((aligntyp)Amask2align(lev->altarmask & AM_MASK) != - eprip->shralign)) { - if (!EMIN(priest)) newemin(priest); - priest->ispriest = 0; /* now a roaming minion */ - priest->isminion = 1; - EMIN(priest)->min_align = eprip->shralign; - EMIN(priest)->renegade = FALSE; - /* discard priest's memory of his former shrine; - if we ever implement the re-conversion mentioned - above, this will need to be removed */ - free_epri(priest); - } - } + wakeup(priest); + /* + * If the altar has been destroyed or converted, let the + * priest run loose. + * (When it's just a conversion and there happens to be + * a fresh corpse nearby, the priest ought to have an + * opportunity to try converting it back; maybe someday...) + */ + lev = &levl[eprip->shrpos.x][eprip->shrpos.y]; + if (!IS_ALTAR(lev->typ) + || ((aligntyp) Amask2align(lev->altarmask & AM_MASK) + != eprip->shralign)) { + if (!EMIN(priest)) + newemin(priest); + priest->ispriest = 0; /* now a roaming minion */ + priest->isminion = 1; + EMIN(priest)->min_align = eprip->shralign; + EMIN(priest)->renegade = FALSE; + /* discard priest's memory of his former shrine; + if we ever implement the re-conversion mentioned + above, this will need to be removed */ + free_epri(priest); + } + } } /* @@ -781,9 +831,10 @@ clearpriests() struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->ispriest && !on_level(&(EPRI(mtmp)->shrlevel), &u.uz)) - mongone(mtmp); + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->ispriest && !on_level(&(EPRI(mtmp)->shrlevel), &u.uz)) + mongone(mtmp); } } @@ -793,9 +844,9 @@ restpriest(mtmp, ghostly) register struct monst *mtmp; boolean ghostly; { - if(u.uz.dlevel) { - if (ghostly) - assign_level(&(EPRI(mtmp)->shrlevel), &u.uz); + if (u.uz.dlevel) { + if (ghostly) + assign_level(&(EPRI(mtmp)->shrlevel), &u.uz); } } diff --git a/src/quest.c b/src/quest.c index 4ee088c1e..dfa7b2bd2 100644 --- a/src/quest.c +++ b/src/quest.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 quest.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 quest.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ /* NetHack 3.6 quest.c $Date: 2009/05/06 10:47:33 $ $Revision: 1.10 $ */ /* SCCS Id: @(#)quest.c 3.5 2006/08/05 */ /* Copyright 1991, M. Stephenson */ @@ -11,8 +11,8 @@ #include "quest.h" #include "qtext.h" -#define Not_firsttime (on_level(&u.uz0, &u.uz)) -#define Qstat(x) (quest_status.x) +#define Not_firsttime (on_level(&u.uz0, &u.uz)) +#define Qstat(x) (quest_status.x) STATIC_DCL void NDECL(on_start); STATIC_DCL void NDECL(on_locate); @@ -25,101 +25,110 @@ STATIC_DCL void NDECL(chat_with_nemesis); STATIC_DCL void NDECL(chat_with_guardian); STATIC_DCL void FDECL(prisoner_speaks, (struct monst *)); - STATIC_OVL void on_start() { - if(!Qstat(first_start)) { - qt_pager(QT_FIRSTTIME); - Qstat(first_start) = TRUE; - } else if((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) { - if(Qstat(not_ready) <= 2) qt_pager(QT_NEXTTIME); - else qt_pager(QT_OTHERTIME); - } + if (!Qstat(first_start)) { + qt_pager(QT_FIRSTTIME); + Qstat(first_start) = TRUE; + } else if ((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) { + if (Qstat(not_ready) <= 2) + qt_pager(QT_NEXTTIME); + else + qt_pager(QT_OTHERTIME); + } } STATIC_OVL void on_locate() { - /* the locate messages are phrased in a manner such that they only - make sense when arriving on the level from above */ - boolean from_above = (u.uz0.dlevel < u.uz.dlevel); + /* the locate messages are phrased in a manner such that they only + make sense when arriving on the level from above */ + boolean from_above = (u.uz0.dlevel < u.uz.dlevel); - if (Qstat(killed_nemesis)) { - return; - } else if (!Qstat(first_locate)) { - if (from_above) qt_pager(QT_FIRSTLOCATE); - /* if we've arrived from below this will be a lie, but there won't - be any point in delivering the message upon a return visit from - above later since the level has now been seen */ - Qstat(first_locate) = TRUE; - } else { - if (from_above) qt_pager(QT_NEXTLOCATE); - } + if (Qstat(killed_nemesis)) { + return; + } else if (!Qstat(first_locate)) { + if (from_above) + qt_pager(QT_FIRSTLOCATE); + /* if we've arrived from below this will be a lie, but there won't + be any point in delivering the message upon a return visit from + above later since the level has now been seen */ + Qstat(first_locate) = TRUE; + } else { + if (from_above) + qt_pager(QT_NEXTLOCATE); + } } STATIC_OVL void on_goal() { - if (Qstat(killed_nemesis)) { - return; - } else if (!Qstat(made_goal)) { - qt_pager(QT_FIRSTGOAL); - Qstat(made_goal) = 1; - } else { - qt_pager(QT_NEXTGOAL); - if(Qstat(made_goal) < 7) Qstat(made_goal)++; - } + if (Qstat(killed_nemesis)) { + return; + } else if (!Qstat(made_goal)) { + qt_pager(QT_FIRSTGOAL); + Qstat(made_goal) = 1; + } else { + qt_pager(QT_NEXTGOAL); + if (Qstat(made_goal) < 7) + Qstat(made_goal)++; + } } void onquest() { - if(u.uevent.qcompleted || Not_firsttime) return; - if(!Is_special(&u.uz)) return; + if (u.uevent.qcompleted || Not_firsttime) + return; + if (!Is_special(&u.uz)) + return; - if(Is_qstart(&u.uz)) on_start(); - else if(Is_qlocate(&u.uz)) on_locate(); - else if(Is_nemesis(&u.uz)) on_goal(); - return; + if (Is_qstart(&u.uz)) + on_start(); + else if (Is_qlocate(&u.uz)) + on_locate(); + else if (Is_nemesis(&u.uz)) + on_goal(); + return; } void nemdead() { - if(!Qstat(killed_nemesis)) { - Qstat(killed_nemesis) = TRUE; - qt_pager(QT_KILLEDNEM); - } + if (!Qstat(killed_nemesis)) { + Qstat(killed_nemesis) = TRUE; + qt_pager(QT_KILLEDNEM); + } } void artitouch(obj) struct obj *obj; { - if(!Qstat(touched_artifact)) { - /* in case we haven't seen the item yet (ie, currently blinded), - this quest message describes it by name so mark it as seen */ - obj->dknown = 1; - /* only give this message once */ - Qstat(touched_artifact) = TRUE; - qt_pager(QT_GOTIT); - exercise(A_WIS, TRUE); - } + if (!Qstat(touched_artifact)) { + /* in case we haven't seen the item yet (ie, currently blinded), + this quest message describes it by name so mark it as seen */ + obj->dknown = 1; + /* only give this message once */ + Qstat(touched_artifact) = TRUE; + qt_pager(QT_GOTIT); + exercise(A_WIS, TRUE); + } } /* external hook for do.c (level change check) */ boolean ok_to_quest() { - return((boolean)((Qstat(got_quest) || Qstat(got_thanks))) - && (is_pure(FALSE) > 0)); + return ((boolean)((Qstat(got_quest) || Qstat(got_thanks))) + && (is_pure(FALSE) > 0)); } STATIC_OVL boolean not_capable() { - return((boolean)(u.ulevel < MIN_QUEST_LEVEL)); + return ((boolean)(u.ulevel < MIN_QUEST_LEVEL)); } STATIC_OVL int @@ -130,22 +139,23 @@ boolean talk; aligntyp original_alignment = u.ualignbase[A_ORIGINAL]; if (wizard && talk) { - if (u.ualign.type != original_alignment) { - You("are currently %s instead of %s.", - align_str(u.ualign.type), align_str(original_alignment)); - } else if (u.ualignbase[A_CURRENT] != original_alignment) { - You("have converted."); - } else if (u.ualign.record < MIN_QUEST_ALIGN) { - You("are currently %d and require %d.", - u.ualign.record, MIN_QUEST_ALIGN); - if (yn_function("adjust?", (char *)0, 'y') == 'y') - u.ualign.record = MIN_QUEST_ALIGN; - } + if (u.ualign.type != original_alignment) { + You("are currently %s instead of %s.", align_str(u.ualign.type), + align_str(original_alignment)); + } else if (u.ualignbase[A_CURRENT] != original_alignment) { + You("have converted."); + } else if (u.ualign.record < MIN_QUEST_ALIGN) { + You("are currently %d and require %d.", u.ualign.record, + MIN_QUEST_ALIGN); + if (yn_function("adjust?", (char *) 0, 'y') == 'y') + u.ualign.record = MIN_QUEST_ALIGN; + } } - purity = (u.ualign.record >= MIN_QUEST_ALIGN && - u.ualign.type == original_alignment && - u.ualignbase[A_CURRENT] == original_alignment) ? 1 : - (u.ualignbase[A_CURRENT] != original_alignment) ? -1 : 0; + purity = (u.ualign.record >= MIN_QUEST_ALIGN + && u.ualign.type == original_alignment + && u.ualignbase[A_CURRENT] == original_alignment) + ? 1 + : (u.ualignbase[A_CURRENT] != original_alignment) ? -1 : 0; return purity; } @@ -166,21 +176,24 @@ boolean seal; br = dungeon_branch("The Quest"); dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1; - portal_flag = u.uevent.qexpelled ? 0 : /* returned via artifact? */ - !seal ? 1 : -1; - schedule_goto(dest, FALSE, FALSE, portal_flag, (char *)0, (char *)0); - if (seal) { /* remove the portal to the quest - sealing it off */ - int reexpelled = u.uevent.qexpelled; - u.uevent.qexpelled = 1; - remdun_mapseen(quest_dnum); - /* Delete the near portal now; the far (main dungeon side) - portal will be deleted as part of arrival on that level. - If monster movement is in progress, any who haven't moved - yet will now miss out on a chance to wander through it... */ - for (t = ftrap; t; t = t->ntrap) - if (t->ttyp == MAGIC_PORTAL) break; - if (t) deltrap(t); /* (display might be briefly out of sync) */ - else if (!reexpelled) impossible("quest portal already gone?"); + portal_flag = u.uevent.qexpelled ? 0 : /* returned via artifact? */ + !seal ? 1 : -1; + schedule_goto(dest, FALSE, FALSE, portal_flag, (char *) 0, (char *) 0); + if (seal) { /* remove the portal to the quest - sealing it off */ + int reexpelled = u.uevent.qexpelled; + u.uevent.qexpelled = 1; + remdun_mapseen(quest_dnum); + /* Delete the near portal now; the far (main dungeon side) + portal will be deleted as part of arrival on that level. + If monster movement is in progress, any who haven't moved + yet will now miss out on a chance to wander through it... */ + for (t = ftrap; t; t = t->ntrap) + if (t->ttyp == MAGIC_PORTAL) + break; + if (t) + deltrap(t); /* (display might be briefly out of sync) */ + else if (!reexpelled) + impossible("quest portal already gone?"); } } @@ -191,213 +204,236 @@ boolean seal; and using the magic portal to return to the dungeon. */ void finish_quest(obj) -struct obj *obj; /* quest artifact; possibly null if carrying Amulet */ +struct obj *obj; /* quest artifact; possibly null if carrying Amulet */ { - struct obj *otmp; + struct obj *otmp; - if (u.uhave.amulet) { /* unlikely but not impossible */ - qt_pager(QT_HASAMULET); - /* leader IDs the real amulet but ignores any fakes */ - if ((otmp = carrying(AMULET_OF_YENDOR)) != 0) - fully_identify_obj(otmp); - } else { - qt_pager(!Qstat(got_thanks) ? QT_OFFEREDIT : QT_OFFEREDIT2); - /* should have obtained bell during quest; - if not, suggest returning for it now */ - if ((otmp = carrying(BELL_OF_OPENING)) == 0) - com_pager(5); - } - Qstat(got_thanks) = TRUE; + if (u.uhave.amulet) { /* unlikely but not impossible */ + qt_pager(QT_HASAMULET); + /* leader IDs the real amulet but ignores any fakes */ + if ((otmp = carrying(AMULET_OF_YENDOR)) != 0) + fully_identify_obj(otmp); + } else { + qt_pager(!Qstat(got_thanks) ? QT_OFFEREDIT : QT_OFFEREDIT2); + /* should have obtained bell during quest; + if not, suggest returning for it now */ + if ((otmp = carrying(BELL_OF_OPENING)) == 0) + com_pager(5); + } + Qstat(got_thanks) = TRUE; - if (obj) { - u.uevent.qcompleted = 1; /* you did it! */ - /* behave as if leader imparts sufficient info about the - quest artifact */ - fully_identify_obj(obj); - update_inventory(); - } + if (obj) { + u.uevent.qcompleted = 1; /* you did it! */ + /* behave as if leader imparts sufficient info about the + quest artifact */ + fully_identify_obj(obj); + update_inventory(); + } } STATIC_OVL void chat_with_leader() { -/* Rule 0: Cheater checks. */ - if(u.uhave.questart && !Qstat(met_nemesis)) - Qstat(cheater) = TRUE; + /* Rule 0: Cheater checks. */ + if (u.uhave.questart && !Qstat(met_nemesis)) + Qstat(cheater) = TRUE; -/* It is possible for you to get the amulet without completing - * the quest. If so, try to induce the player to quest. - */ - if(Qstat(got_thanks)) { -/* Rule 1: You've gone back with/without the amulet. */ - if(u.uhave.amulet) finish_quest((struct obj *)0); + /* It is possible for you to get the amulet without completing + * the quest. If so, try to induce the player to quest. + */ + if (Qstat(got_thanks)) { + /* Rule 1: You've gone back with/without the amulet. */ + if (u.uhave.amulet) + finish_quest((struct obj *) 0); -/* Rule 2: You've gone back before going for the amulet. */ - else qt_pager(QT_POSTHANKS); - } + /* Rule 2: You've gone back before going for the amulet. */ + else + qt_pager(QT_POSTHANKS); + } -/* Rule 3: You've got the artifact and are back to return it. */ - else if(u.uhave.questart) { - struct obj *otmp; + /* Rule 3: You've got the artifact and are back to return it. */ + else if (u.uhave.questart) { + struct obj *otmp; - for (otmp = invent; otmp; otmp = otmp->nobj) - if (is_quest_artifact(otmp)) break; + for (otmp = invent; otmp; otmp = otmp->nobj) + if (is_quest_artifact(otmp)) + break; - finish_quest(otmp); + finish_quest(otmp); -/* Rule 4: You haven't got the artifact yet. */ - } else if(Qstat(got_quest)) { - qt_pager(rn1(10, QT_ENCOURAGE)); + /* Rule 4: You haven't got the artifact yet. */ + } else if (Qstat(got_quest)) { + qt_pager(rn1(10, QT_ENCOURAGE)); -/* Rule 5: You aren't yet acceptable - or are you? */ - } else { - if(!Qstat(met_leader)) { - qt_pager(QT_FIRSTLEADER); - Qstat(met_leader) = TRUE; - Qstat(not_ready) = 0; - } else qt_pager(QT_NEXTLEADER); - /* the quest leader might have passed through the portal into - the regular dungeon; none of the remaining make sense there */ - if (!on_level(&u.uz, &qstart_level)) return; + /* Rule 5: You aren't yet acceptable - or are you? */ + } else { + if (!Qstat(met_leader)) { + qt_pager(QT_FIRSTLEADER); + Qstat(met_leader) = TRUE; + Qstat(not_ready) = 0; + } else + qt_pager(QT_NEXTLEADER); + /* the quest leader might have passed through the portal into + the regular dungeon; none of the remaining make sense there */ + if (!on_level(&u.uz, &qstart_level)) + return; - if(not_capable()) { - qt_pager(QT_BADLEVEL); - exercise(A_WIS, TRUE); - expulsion(FALSE); - } else if(is_pure(TRUE) < 0) { - com_pager(QT_BANISHED); - expulsion(TRUE); - } else if(is_pure(TRUE) == 0) { - qt_pager(QT_BADALIGN); - if(Qstat(not_ready) == MAX_QUEST_TRIES) { - qt_pager(QT_LASTLEADER); - expulsion(TRUE); - } else { - Qstat(not_ready)++; - exercise(A_WIS, TRUE); - expulsion(FALSE); - } - } else { /* You are worthy! */ - qt_pager(QT_ASSIGNQUEST); - exercise(A_WIS, TRUE); - Qstat(got_quest) = TRUE; - } - } + if (not_capable()) { + qt_pager(QT_BADLEVEL); + exercise(A_WIS, TRUE); + expulsion(FALSE); + } else if (is_pure(TRUE) < 0) { + com_pager(QT_BANISHED); + expulsion(TRUE); + } else if (is_pure(TRUE) == 0) { + qt_pager(QT_BADALIGN); + if (Qstat(not_ready) == MAX_QUEST_TRIES) { + qt_pager(QT_LASTLEADER); + expulsion(TRUE); + } else { + Qstat(not_ready)++; + exercise(A_WIS, TRUE); + expulsion(FALSE); + } + } else { /* You are worthy! */ + qt_pager(QT_ASSIGNQUEST); + exercise(A_WIS, TRUE); + Qstat(got_quest) = TRUE; + } + } } void leader_speaks(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - /* maybe you attacked leader? */ - if(!mtmp->mpeaceful) { - Qstat(pissed_off) = TRUE; - mtmp->mstrategy &= ~STRAT_WAITMASK; /* end the inaction */ - } - /* the quest leader might have passed through the portal into the - regular dungeon; if so, mustn't perform "backwards expulsion" */ - if (!on_level(&u.uz, &qstart_level)) return; + /* maybe you attacked leader? */ + if (!mtmp->mpeaceful) { + Qstat(pissed_off) = TRUE; + mtmp->mstrategy &= ~STRAT_WAITMASK; /* end the inaction */ + } + /* the quest leader might have passed through the portal into the + regular dungeon; if so, mustn't perform "backwards expulsion" */ + if (!on_level(&u.uz, &qstart_level)) + return; - if(Qstat(pissed_off)) { - qt_pager(QT_LASTLEADER); - expulsion(TRUE); - } else chat_with_leader(); + if (Qstat(pissed_off)) { + qt_pager(QT_LASTLEADER); + expulsion(TRUE); + } else + chat_with_leader(); } STATIC_OVL void chat_with_nemesis() { -/* The nemesis will do most of the talking, but... */ - qt_pager(rn1(10, QT_DISCOURAGE)); - if(!Qstat(met_nemesis)) Qstat(met_nemesis++); + /* The nemesis will do most of the talking, but... */ + qt_pager(rn1(10, QT_DISCOURAGE)); + if (!Qstat(met_nemesis)) + Qstat(met_nemesis++); } void nemesis_speaks() { - if(!Qstat(in_battle)) { - if(u.uhave.questart) qt_pager(QT_NEMWANTSIT); - else if(Qstat(made_goal) == 1 || !Qstat(met_nemesis)) - qt_pager(QT_FIRSTNEMESIS); - else if(Qstat(made_goal) < 4) qt_pager(QT_NEXTNEMESIS); - else if(Qstat(made_goal) < 7) qt_pager(QT_OTHERNEMESIS); - else if(!rn2(5)) qt_pager(rn1(10, QT_DISCOURAGE)); - if(Qstat(made_goal) < 7) Qstat(made_goal)++; - Qstat(met_nemesis) = TRUE; - } else /* he will spit out random maledictions */ - if(!rn2(5)) qt_pager(rn1(10, QT_DISCOURAGE)); + if (!Qstat(in_battle)) { + if (u.uhave.questart) + qt_pager(QT_NEMWANTSIT); + else if (Qstat(made_goal) == 1 || !Qstat(met_nemesis)) + qt_pager(QT_FIRSTNEMESIS); + else if (Qstat(made_goal) < 4) + qt_pager(QT_NEXTNEMESIS); + else if (Qstat(made_goal) < 7) + qt_pager(QT_OTHERNEMESIS); + else if (!rn2(5)) + qt_pager(rn1(10, QT_DISCOURAGE)); + if (Qstat(made_goal) < 7) + Qstat(made_goal)++; + Qstat(met_nemesis) = TRUE; + } else /* he will spit out random maledictions */ + if (!rn2(5)) + qt_pager(rn1(10, QT_DISCOURAGE)); } STATIC_OVL void chat_with_guardian() { -/* These guys/gals really don't have much to say... */ - if (u.uhave.questart && Qstat(killed_nemesis)) - qt_pager(rn1(5, QT_GUARDTALK2)); - else - qt_pager(rn1(5, QT_GUARDTALK)); + /* These guys/gals really don't have much to say... */ + if (u.uhave.questart && Qstat(killed_nemesis)) + qt_pager(rn1(5, QT_GUARDTALK2)); + else + qt_pager(rn1(5, QT_GUARDTALK)); } STATIC_OVL void -prisoner_speaks (mtmp) - register struct monst *mtmp; +prisoner_speaks(mtmp) +register struct monst *mtmp; { - if (mtmp->data == &mons[PM_PRISONER] && - (mtmp->mstrategy & STRAT_WAITMASK)) { - /* Awaken the prisoner */ - if (canseemon(mtmp)) - pline("%s speaks:", Monnam(mtmp)); - verbalize("I'm finally free!"); - mtmp->mstrategy &= ~STRAT_WAITMASK; - mtmp->mpeaceful = 1; + if (mtmp->data == &mons[PM_PRISONER] + && (mtmp->mstrategy & STRAT_WAITMASK)) { + /* Awaken the prisoner */ + if (canseemon(mtmp)) + pline("%s speaks:", Monnam(mtmp)); + verbalize("I'm finally free!"); + mtmp->mstrategy &= ~STRAT_WAITMASK; + mtmp->mpeaceful = 1; - /* Your god is happy... */ - adjalign(3); + /* Your god is happy... */ + adjalign(3); - /* ...But the guards are not */ - (void) angry_guards(FALSE); - } - return; + /* ...But the guards are not */ + (void) angry_guards(FALSE); + } + return; } void quest_chat(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { if (mtmp->m_id == Qstat(leader_m_id)) { - chat_with_leader(); - return; + chat_with_leader(); + return; + } + switch (mtmp->data->msound) { + case MS_NEMESIS: + chat_with_nemesis(); + break; + case MS_GUARDIAN: + chat_with_guardian(); + break; + default: + impossible("quest_chat: Unknown quest character %s.", mon_nam(mtmp)); } - switch(mtmp->data->msound) { - case MS_NEMESIS: chat_with_nemesis(); break; - case MS_GUARDIAN: chat_with_guardian(); break; - default: impossible("quest_chat: Unknown quest character %s.", - mon_nam(mtmp)); - } } void quest_talk(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { if (mtmp->m_id == Qstat(leader_m_id)) { - leader_speaks(mtmp); - return; + leader_speaks(mtmp); + return; + } + switch (mtmp->data->msound) { + case MS_NEMESIS: + nemesis_speaks(); + break; + case MS_DJINNI: + prisoner_speaks(mtmp); + break; + default: + break; } - switch(mtmp->data->msound) { - case MS_NEMESIS: nemesis_speaks(); break; - case MS_DJINNI: prisoner_speaks(mtmp); break; - default: break; - } } void quest_stat_check(mtmp) - struct monst *mtmp; +struct monst *mtmp; { - if(mtmp->data->msound == MS_NEMESIS) - Qstat(in_battle) = (mtmp->mcanmove && !mtmp->msleeping && - monnear(mtmp, u.ux, u.uy)); + if (mtmp->data->msound == MS_NEMESIS) + Qstat(in_battle) = + (mtmp->mcanmove && !mtmp->msleeping && monnear(mtmp, u.ux, u.uy)); } /*quest.c*/ diff --git a/src/questpgr.c b/src/questpgr.c index ffd5d552d..734679bd2 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 questpgr.c $NHDT-Date: 1426465439 2015/03/16 00:23:59 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.18 $ */ +/* NetHack 3.6 questpgr.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.28 $ */ /* NetHack 3.6 questpgr.c $Date: 2012/02/02 09:18:14 $ $Revision: 1.14 $ */ /* Copyright 1991, M. Stephenson */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,7 +10,7 @@ #include "qtext.h" -#define QTEXT_FILE "quest.dat" +#define QTEXT_FILE "quest.dat" #ifdef TTY_GRAPHICS #include "wintty.h" @@ -19,218 +19,218 @@ /* from sp_lev.c, for deliver_splev_message() */ extern char *lev_message; -static void FDECL(Fread, (genericptr_t,int,int,dlb *)); -STATIC_DCL struct qtmsg * FDECL(construct_qtlist, (long)); -STATIC_DCL const char * NDECL(intermed); -STATIC_DCL const char * NDECL(neminame); -STATIC_DCL const char * NDECL(guardname); -STATIC_DCL const char * NDECL(homebase); -STATIC_DCL void FDECL(qtext_pronoun, (CHAR_P,CHAR_P)); -STATIC_DCL struct qtmsg * FDECL(msg_in, (struct qtmsg *,int)); +static void FDECL(Fread, (genericptr_t, int, int, dlb *)); +STATIC_DCL struct qtmsg *FDECL(construct_qtlist, (long)); +STATIC_DCL const char *NDECL(intermed); +STATIC_DCL const char *NDECL(neminame); +STATIC_DCL const char *NDECL(guardname); +STATIC_DCL const char *NDECL(homebase); +STATIC_DCL void FDECL(qtext_pronoun, (CHAR_P, CHAR_P)); +STATIC_DCL struct qtmsg *FDECL(msg_in, (struct qtmsg *, int)); STATIC_DCL void FDECL(convert_arg, (CHAR_P)); STATIC_DCL void NDECL(convert_line); STATIC_DCL void FDECL(deliver_by_pline, (struct qtmsg *)); -STATIC_DCL void FDECL(deliver_by_window, (struct qtmsg *,int)); +STATIC_DCL void FDECL(deliver_by_window, (struct qtmsg *, int)); STATIC_DCL boolean FDECL(skip_pager, (BOOLEAN_P)); static char in_line[QTEXT_IN_SIZ], out_line[QTEXT_OUTSIZ], cvt_buf[64]; -static struct qtlists qt_list; -static dlb *msg_file; +static struct qtlists qt_list; +static dlb *msg_file; /* used by ldrname() and neminame(), then copied into cvt_buf */ -static char nambuf[sizeof cvt_buf]; +static char nambuf[sizeof cvt_buf]; #ifdef DEBUG static void NDECL(dump_qtlist); static void -dump_qtlist() /* dump the character msg list to check appearance */ +dump_qtlist() /* dump the character msg list to check appearance */ { - struct qtmsg *msg; + struct qtmsg *msg; - if (!explicitdebug(__FILE__)) return; + if (!explicitdebug(__FILE__)) + return; - for (msg = qt_list.chrole; msg->msgnum > 0; msg++) { - pline("msgnum %d: delivery %c", - msg->msgnum, msg->delivery); + for (msg = qt_list.chrole; msg->msgnum > 0; msg++) { + pline("msgnum %d: delivery %c", msg->msgnum, msg->delivery); #ifdef TTY_GRAPHICS - more(); + more(); #endif - (void) dlb_fseek(msg_file, msg->offset, SEEK_SET); - deliver_by_window(msg, NHW_TEXT); - } + (void) dlb_fseek(msg_file, msg->offset, SEEK_SET); + deliver_by_window(msg, NHW_TEXT); + } } #else static void -dump_qtlist() { } +dump_qtlist() +{ +} #endif /* !DEBUG */ static void Fread(ptr, size, nitems, stream) -genericptr_t ptr; -int size, nitems; -dlb *stream; +genericptr_t ptr; +int size, nitems; +dlb *stream; { - int cnt; + int cnt; - if ((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) { - - panic("PREMATURE EOF ON QUEST TEXT FILE! Expected %d bytes, got %d", - (size * nitems), (size * cnt)); - } + if ((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) { + panic("PREMATURE EOF ON QUEST TEXT FILE! Expected %d bytes, got %d", + (size * nitems), (size * cnt)); + } } STATIC_OVL struct qtmsg * construct_qtlist(hdr_offset) -long hdr_offset; +long hdr_offset; { - struct qtmsg *msg_list; - int n_msgs; + struct qtmsg *msg_list; + int n_msgs; - (void) dlb_fseek(msg_file, hdr_offset, SEEK_SET); - Fread(&n_msgs, sizeof(int), 1, msg_file); - msg_list = (struct qtmsg *) - alloc((unsigned)(n_msgs+1)*sizeof(struct qtmsg)); + (void) dlb_fseek(msg_file, hdr_offset, SEEK_SET); + Fread(&n_msgs, sizeof(int), 1, msg_file); + msg_list = (struct qtmsg *) alloc((unsigned) (n_msgs + 1) + * sizeof(struct qtmsg)); - /* - * Load up the list. - */ - Fread((genericptr_t)msg_list, n_msgs*sizeof(struct qtmsg), 1, msg_file); + /* + * Load up the list. + */ + Fread((genericptr_t) msg_list, n_msgs * sizeof(struct qtmsg), 1, + msg_file); - msg_list[n_msgs].msgnum = -1; - return(msg_list); + msg_list[n_msgs].msgnum = -1; + return (msg_list); } void load_qtlist() { + int n_classes, i; + char qt_classes[N_HDR][LEN_HDR]; + long qt_offsets[N_HDR]; - int n_classes, i; - char qt_classes[N_HDR][LEN_HDR]; - long qt_offsets[N_HDR]; + msg_file = dlb_fopen(QTEXT_FILE, RDBMODE); + if (!msg_file) + panic("CANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE); - msg_file = dlb_fopen(QTEXT_FILE, RDBMODE); - if (!msg_file) - panic("CANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE); + /* + * Read in the number of classes, then the ID's & offsets for + * each header. + */ - /* - * Read in the number of classes, then the ID's & offsets for - * each header. - */ + Fread(&n_classes, sizeof(int), 1, msg_file); + Fread(&qt_classes[0][0], sizeof(char) * LEN_HDR, n_classes, msg_file); + Fread(qt_offsets, sizeof(long), n_classes, msg_file); - Fread(&n_classes, sizeof(int), 1, msg_file); - Fread(&qt_classes[0][0], sizeof(char)*LEN_HDR, n_classes, msg_file); - Fread(qt_offsets, sizeof(long), n_classes, msg_file); + /* + * Now construct the message lists for quick reference later + * on when we are actually paging the messages out. + */ - /* - * Now construct the message lists for quick reference later - * on when we are actually paging the messages out. - */ + qt_list.common = qt_list.chrole = (struct qtmsg *) 0; - qt_list.common = qt_list.chrole = (struct qtmsg *)0; - - for (i = 0; i < n_classes; i++) { - if (!strncmp(COMMON_ID, qt_classes[i], LEN_HDR)) - qt_list.common = construct_qtlist(qt_offsets[i]); - else if (!strncmp(urole.filecode, qt_classes[i], LEN_HDR)) - qt_list.chrole = construct_qtlist(qt_offsets[i]); -#if 0 /* UNUSED but available */ + for (i = 0; i < n_classes; i++) { + if (!strncmp(COMMON_ID, qt_classes[i], LEN_HDR)) + qt_list.common = construct_qtlist(qt_offsets[i]); + else if (!strncmp(urole.filecode, qt_classes[i], LEN_HDR)) + qt_list.chrole = construct_qtlist(qt_offsets[i]); +#if 0 /* UNUSED but available */ else if (!strncmp(urace.filecode, qt_classes[i], LEN_HDR)) qt_list.chrace = construct_qtlist(qt_offsets[i]); #endif - } + } - if (!qt_list.common || !qt_list.chrole) - impossible("load_qtlist: cannot load quest text."); - dump_qtlist(); - return; /* no ***DON'T*** close the msg_file */ + if (!qt_list.common || !qt_list.chrole) + impossible("load_qtlist: cannot load quest text."); + dump_qtlist(); + return; /* no ***DON'T*** close the msg_file */ } /* called at program exit */ void unload_qtlist() { - if (msg_file) - (void) dlb_fclose(msg_file), msg_file = 0; - if (qt_list.common) - free((genericptr_t) qt_list.common), qt_list.common = 0; - if (qt_list.chrole) - free((genericptr_t) qt_list.chrole), qt_list.chrole = 0; - return; + if (msg_file) + (void) dlb_fclose(msg_file), msg_file = 0; + if (qt_list.common) + free((genericptr_t) qt_list.common), qt_list.common = 0; + if (qt_list.chrole) + free((genericptr_t) qt_list.chrole), qt_list.chrole = 0; + return; } short quest_info(typ) int typ; { - switch (typ) { - case 0: return (urole.questarti); - case MS_LEADER: return (urole.ldrnum); - case MS_NEMESIS: return (urole.neminum); - case MS_GUARDIAN: return (urole.guardnum); - default: impossible("quest_info(%d)", typ); - } - return 0; + switch (typ) { + case 0: + return (urole.questarti); + case MS_LEADER: + return (urole.ldrnum); + case MS_NEMESIS: + return (urole.neminum); + case MS_GUARDIAN: + return (urole.guardnum); + default: + impossible("quest_info(%d)", typ); + } + return 0; } -const char * -ldrname() /* return your role leader's name */ +const char *ldrname() /* return your role leader's name */ { - int i = urole.ldrnum; + int i = urole.ldrnum; - Sprintf(nambuf, "%s%s", - type_is_pname(&mons[i]) ? "" : "the ", - mons[i].mname); - return nambuf; + Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", + mons[i].mname); + return nambuf; } -STATIC_OVL const char * -intermed() /* return your intermediate target string */ +STATIC_OVL const char *intermed() /* return your intermediate target string */ { - return (urole.intermed); + return (urole.intermed); } boolean is_quest_artifact(otmp) struct obj *otmp; { - return((boolean)(otmp->oartifact == urole.questarti)); + return ((boolean)(otmp->oartifact == urole.questarti)); +} + +STATIC_OVL const char *neminame() /* return your role nemesis' name */ +{ + int i = urole.neminum; + + Sprintf(nambuf, "%s%s", type_is_pname(&mons[i]) ? "" : "the ", + mons[i].mname); + return nambuf; } STATIC_OVL const char * -neminame() /* return your role nemesis' name */ +guardname() /* return your role leader's guard monster name */ { - int i = urole.neminum; + int i = urole.guardnum; - Sprintf(nambuf, "%s%s", - type_is_pname(&mons[i]) ? "" : "the ", - mons[i].mname); - return nambuf; + return (mons[i].mname); } -STATIC_OVL const char * -guardname() /* return your role leader's guard monster name */ +STATIC_OVL const char *homebase() /* return your role leader's location */ { - int i = urole.guardnum; - - return(mons[i].mname); -} - -STATIC_OVL const char * -homebase() /* return your role leader's location */ -{ - return(urole.homebase); + return (urole.homebase); } /* replace deity, leader, nemesis, or artifact name with pronoun; overwrites cvt_buf[] */ STATIC_OVL void qtext_pronoun(who, which) -char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ - which; /* 'h'|'H'|'i'|'I'|'j'|'J' */ +char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ + which; /* 'h'|'H'|'i'|'I'|'j'|'J' */ { const char *pnoun; int g; - char lwhich = lowc(which); /* H,I,J -> h,i,j */ + char lwhich = lowc(which); /* H,I,J -> h,i,j */ /* * Invalid subject (not d,l,n,o) yields neuter, singular result. @@ -240,202 +240,237 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */ * and makesingular() understands how to handle "the foos of bar". */ if (who == 'o' && strcmpi(cvt_buf, makesingular(cvt_buf))) { - pnoun = (lwhich == 'h') ? "they" : - (lwhich == 'i') ? "them" : - (lwhich == 'j') ? "their" : "?"; + pnoun = + (lwhich == 'h') ? "they" : (lwhich == 'i') + ? "them" + : (lwhich == 'j') ? "their" : "?"; } else { - g = (who == 'd') ? quest_status.godgend : - (who == 'l') ? quest_status.ldrgend : - (who == 'n') ? quest_status.nemgend : 2; /* default to neuter */ - pnoun = (lwhich == 'h') ? genders[g].he : - (lwhich == 'i') ? genders[g].him : - (lwhich == 'j') ? genders[g].his : "?"; + g = (who == 'd') + ? quest_status.godgend + : (who == 'l') ? quest_status.ldrgend + : (who == 'n') ? quest_status.nemgend + : 2; /* default to neuter */ + pnoun = (lwhich == 'h') ? genders[g].he : (lwhich == 'i') + ? genders[g].him + : (lwhich == 'j') + ? genders[g].his + : "?"; } Strcpy(cvt_buf, pnoun); /* capitalize for H,I,J */ - if (lwhich != which) cvt_buf[0] = highc(cvt_buf[0]); + if (lwhich != which) + cvt_buf[0] = highc(cvt_buf[0]); return; } STATIC_OVL struct qtmsg * msg_in(qtm_list, msgnum) struct qtmsg *qtm_list; -int msgnum; +int msgnum; { - struct qtmsg *qt_msg; + struct qtmsg *qt_msg; - for (qt_msg = qtm_list; qt_msg->msgnum > 0; qt_msg++) - if (qt_msg->msgnum == msgnum) return(qt_msg); + for (qt_msg = qtm_list; qt_msg->msgnum > 0; qt_msg++) + if (qt_msg->msgnum == msgnum) + return (qt_msg); - return((struct qtmsg *)0); + return ((struct qtmsg *) 0); } STATIC_OVL void convert_arg(c) char c; { - register const char *str; + register const char *str; - switch (c) { + switch (c) { + case 'p': + str = plname; + break; + case 'c': + str = (flags.female && urole.name.f) ? urole.name.f : urole.name.m; + break; + case 'r': + str = rank_of(u.ulevel, Role_switch, flags.female); + break; + case 'R': + str = rank_of(MIN_QUEST_LEVEL, Role_switch, flags.female); + break; + case 's': + str = (flags.female) ? "sister" : "brother"; + break; + case 'S': + str = (flags.female) ? "daughter" : "son"; + break; + case 'l': + str = ldrname(); + break; + case 'i': + str = intermed(); + break; + case 'O': + case 'o': + str = the(artiname(urole.questarti)); + if (c == 'O') { + /* shorten "the Foo of Bar" to "the Foo" + (buffer returned by the() is modifiable) */ + char *p = strstri(str, " of "); - case 'p': str = plname; - break; - case 'c': str = (flags.female && urole.name.f) ? - urole.name.f : urole.name.m; - break; - case 'r': str = rank_of(u.ulevel, Role_switch, flags.female); - break; - case 'R': str = rank_of(MIN_QUEST_LEVEL, Role_switch, - flags.female); - break; - case 's': str = (flags.female) ? "sister" : "brother"; - break; - case 'S': str = (flags.female) ? "daughter" : "son"; - break; - case 'l': str = ldrname(); - break; - case 'i': str = intermed(); - break; - case 'O': - case 'o': str = the(artiname(urole.questarti)); - if (c == 'O') { - /* shorten "the Foo of Bar" to "the Foo" - (buffer returned by the() is modifiable) */ - char *p = strstri(str, " of "); - - if (p) *p = '\0'; - } - break; - case 'n': str = neminame(); - break; - case 'g': str = guardname(); - break; - case 'G': str = align_gtitle(u.ualignbase[A_ORIGINAL]); - break; - case 'H': str = homebase(); - break; - case 'a': str = align_str(u.ualignbase[A_ORIGINAL]); - break; - case 'A': str = align_str(u.ualign.type); - break; - case 'd': str = align_gname(u.ualignbase[A_ORIGINAL]); - break; - case 'D': str = align_gname(A_LAWFUL); - break; - case 'C': str = "chaotic"; - break; - case 'N': str = "neutral"; - break; - case 'L': str = "lawful"; - break; - case 'x': str = Blind ? "sense" : "see"; - break; - case 'Z': str = dungeons[0].dname; - break; - case '%': str = "%"; - break; - default: str = ""; - break; - } - Strcpy(cvt_buf, str); + if (p) + *p = '\0'; + } + break; + case 'n': + str = neminame(); + break; + case 'g': + str = guardname(); + break; + case 'G': + str = align_gtitle(u.ualignbase[A_ORIGINAL]); + break; + case 'H': + str = homebase(); + break; + case 'a': + str = align_str(u.ualignbase[A_ORIGINAL]); + break; + case 'A': + str = align_str(u.ualign.type); + break; + case 'd': + str = align_gname(u.ualignbase[A_ORIGINAL]); + break; + case 'D': + str = align_gname(A_LAWFUL); + break; + case 'C': + str = "chaotic"; + break; + case 'N': + str = "neutral"; + break; + case 'L': + str = "lawful"; + break; + case 'x': + str = Blind ? "sense" : "see"; + break; + case 'Z': + str = dungeons[0].dname; + break; + case '%': + str = "%"; + break; + default: + str = ""; + break; + } + Strcpy(cvt_buf, str); } STATIC_OVL void convert_line() { - char *c, *cc; - char xbuf[BUFSZ]; + char *c, *cc; + char xbuf[BUFSZ]; - cc = out_line; - for (c = xcrypt(in_line, xbuf); *c; c++) { + cc = out_line; + for (c = xcrypt(in_line, xbuf); *c; c++) { + *cc = 0; + switch (*c) { + case '\r': + case '\n': + *(++cc) = 0; + return; - *cc = 0; - switch(*c) { + case '%': + if (*(c + 1)) { + convert_arg(*(++c)); + switch (*(++c)) { + /* insert "a"/"an" prefix */ + case 'A': + Strcat(cc, An(cvt_buf)); + cc += strlen(cc); + continue; /* for */ + case 'a': + Strcat(cc, an(cvt_buf)); + cc += strlen(cc); + continue; /* for */ - case '\r': - case '\n': - *(++cc) = 0; - return; + /* capitalize */ + case 'C': + cvt_buf[0] = highc(cvt_buf[0]); + break; - case '%': - if (*(c+1)) { - convert_arg(*(++c)); - switch (*(++c)) { + /* replace name with pronoun; + valid for %d, %l, %n, and %o */ + case 'h': /* he/she */ + case 'H': /* He/She */ + case 'i': /* him/her */ + case 'I': + case 'j': /* his/her */ + case 'J': + if (index("dlno", lowc(*(c - 1)))) + qtext_pronoun(*(c - 1), *c); + else + --c; /* default action */ + break; - /* insert "a"/"an" prefix */ - case 'A': Strcat(cc, An(cvt_buf)); - cc += strlen(cc); - continue; /* for */ - case 'a': Strcat(cc, an(cvt_buf)); - cc += strlen(cc); - continue; /* for */ + /* pluralize */ + case 'P': + cvt_buf[0] = highc(cvt_buf[0]); + case 'p': + Strcpy(cvt_buf, makeplural(cvt_buf)); + break; - /* capitalize */ - case 'C': cvt_buf[0] = highc(cvt_buf[0]); - break; + /* append possessive suffix */ + case 'S': + cvt_buf[0] = highc(cvt_buf[0]); + case 's': + Strcpy(cvt_buf, s_suffix(cvt_buf)); + break; - /* replace name with pronoun; - valid for %d, %l, %n, and %o */ - case 'h': /* he/she */ - case 'H': /* He/She */ - case 'i': /* him/her */ - case 'I': - case 'j': /* his/her */ - case 'J': if (index("dlno", lowc(*(c - 1)))) - qtext_pronoun(*(c - 1), *c); - else - --c; /* default action */ - break; + /* strip any "the" prefix */ + case 't': + if (!strncmpi(cvt_buf, "the ", 4)) { + Strcat(cc, &cvt_buf[4]); + cc += strlen(cc); + continue; /* for */ + } + break; - /* pluralize */ - case 'P': cvt_buf[0] = highc(cvt_buf[0]); - case 'p': Strcpy(cvt_buf, makeplural(cvt_buf)); - break; + default: + --c; /* undo switch increment */ + break; + } + Strcat(cc, cvt_buf); + cc += strlen(cvt_buf); + break; + } /* else fall through */ - /* append possessive suffix */ - case 'S': cvt_buf[0] = highc(cvt_buf[0]); - case 's': Strcpy(cvt_buf, s_suffix(cvt_buf)); - break; - - /* strip any "the" prefix */ - case 't': if (!strncmpi(cvt_buf, "the ", 4)) { - Strcat(cc, &cvt_buf[4]); - cc += strlen(cc); - continue; /* for */ - } - break; - - default: --c; /* undo switch increment */ - break; - } - Strcat(cc, cvt_buf); - cc += strlen(cvt_buf); - break; - } /* else fall through */ - - default: - *cc++ = *c; - break; - } - } - if (cc >= out_line + sizeof out_line) - panic("convert_line: overflow"); - *cc = 0; - return; + default: + *cc++ = *c; + break; + } + } + if (cc >= out_line + sizeof out_line) + panic("convert_line: overflow"); + *cc = 0; + return; } STATIC_OVL void deliver_by_pline(qt_msg) struct qtmsg *qt_msg; { - long size; - - for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { - (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); - convert_line(); - pline1(out_line); - } + long size; + for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) { + (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); + convert_line(); + pline1(out_line); + } } STATIC_OVL void @@ -443,97 +478,104 @@ deliver_by_window(qt_msg, how) struct qtmsg *qt_msg; int how; { - long size; - winid datawin = create_nhwindow(how); + long size; + winid datawin = create_nhwindow(how); - for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { - (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); - convert_line(); - putstr(datawin, 0, out_line); - } - display_nhwindow(datawin, TRUE); - destroy_nhwindow(datawin); + for (size = 0; size < qt_msg->size; size += (long) strlen(in_line)) { + (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); + convert_line(); + putstr(datawin, 0, out_line); + } + display_nhwindow(datawin, TRUE); + destroy_nhwindow(datawin); - /* block messages delivered by window aren't kept in message history - but can have a one-line summary which is put there for ^P recall */ - if (qt_msg->summary_size) { - (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); - convert_line(); - putmsghistory(out_line, FALSE); - } + /* block messages delivered by window aren't kept in message history + but can have a one-line summary which is put there for ^P recall */ + if (qt_msg->summary_size) { + (void) dlb_fgets(in_line, QTEXT_IN_SIZ, msg_file); + convert_line(); + putmsghistory(out_line, FALSE); + } } boolean skip_pager(common) boolean common; { - /* WIZKIT: suppress plot feedback if starting with quest artifact */ - if (program_state.wizkit_wishing) return TRUE; - if (!(common ? qt_list.common : qt_list.chrole)) { - panic("%s: no %s quest text data available", - common ? "com_pager" : "qt_pager", - common ? "common" : "role-specific"); - /*NOTREACHED*/ - return TRUE; - } - return FALSE; + /* WIZKIT: suppress plot feedback if starting with quest artifact */ + if (program_state.wizkit_wishing) + return TRUE; + if (!(common ? qt_list.common : qt_list.chrole)) { + panic("%s: no %s quest text data available", + common ? "com_pager" : "qt_pager", + common ? "common" : "role-specific"); + /*NOTREACHED*/ + return TRUE; + } + return FALSE; } void com_pager(msgnum) -int msgnum; +int msgnum; { - struct qtmsg *qt_msg; + struct qtmsg *qt_msg; - if (skip_pager(TRUE)) return; + if (skip_pager(TRUE)) + return; - if (!(qt_msg = msg_in(qt_list.common, msgnum))) { - impossible("com_pager: message %d not found.", msgnum); - return; - } + if (!(qt_msg = msg_in(qt_list.common, msgnum))) { + impossible("com_pager: message %d not found.", msgnum); + return; + } - (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); - if (qt_msg->delivery == 'p') deliver_by_pline(qt_msg); - else if (msgnum == 1) deliver_by_window(qt_msg, NHW_MENU); - else deliver_by_window(qt_msg, NHW_TEXT); - return; + (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); + if (qt_msg->delivery == 'p') + deliver_by_pline(qt_msg); + else if (msgnum == 1) + deliver_by_window(qt_msg, NHW_MENU); + else + deliver_by_window(qt_msg, NHW_TEXT); + return; } void qt_pager(msgnum) -int msgnum; +int msgnum; { - struct qtmsg *qt_msg; + struct qtmsg *qt_msg; - if (skip_pager(FALSE)) return; + if (skip_pager(FALSE)) + return; - if (!(qt_msg = msg_in(qt_list.chrole, msgnum))) { - impossible("qt_pager: message %d not found.", msgnum); - return; - } + if (!(qt_msg = msg_in(qt_list.chrole, msgnum))) { + impossible("qt_pager: message %d not found.", msgnum); + return; + } - (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); - if (qt_msg->delivery == 'p' && strcmp(windowprocs.name, "X11")) - deliver_by_pline(qt_msg); - else deliver_by_window(qt_msg, NHW_TEXT); - return; + (void) dlb_fseek(msg_file, qt_msg->offset, SEEK_SET); + if (qt_msg->delivery == 'p' && strcmp(windowprocs.name, "X11")) + deliver_by_pline(qt_msg); + else + deliver_by_window(qt_msg, NHW_TEXT); + return; } struct permonst * qt_montype() { - int qpm; + int qpm; - if (rn2(5)) { - qpm = urole.enemy1num; - if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD)) - return (&mons[qpm]); - return (mkclass(urole.enemy1sym, 0)); - } - qpm = urole.enemy2num; - if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD)) - return (&mons[qpm]); - return (mkclass(urole.enemy2sym, 0)); + if (rn2(5)) { + qpm = urole.enemy1num; + if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD)) + return (&mons[qpm]); + return (mkclass(urole.enemy1sym, 0)); + } + qpm = urole.enemy2num; + if (qpm != NON_PM && rn2(5) && !(mvitals[qpm].mvflags & G_GENOD)) + return (&mons[qpm]); + return (mkclass(urole.enemy2sym, 0)); } /* special levels can include a custom arrival message; display it */ @@ -544,23 +586,24 @@ deliver_splev_message() /* there's no provision for delivering via window instead of pline */ if (lev_message) { - /* lev_message can span multiple lines using embedded newline chars; - any segments too long to fit within in_line[] will be truncated */ - for (str = lev_message; *str; str = nl + 1) { - /* copying will stop at newline if one is present */ - copynchars(in_line, str, (int)(sizeof in_line) - 1); + /* lev_message can span multiple lines using embedded newline chars; + any segments too long to fit within in_line[] will be truncated */ + for (str = lev_message; *str; str = nl + 1) { + /* copying will stop at newline if one is present */ + copynchars(in_line, str, (int) (sizeof in_line) - 1); - /* convert_line() expects encrypted input; - it reads from in_line[] and writes to out_line[] */ - (void)xcrypt(in_line, in_line); - convert_line(); - pline1(out_line); + /* convert_line() expects encrypted input; + it reads from in_line[] and writes to out_line[] */ + (void) xcrypt(in_line, in_line); + convert_line(); + pline1(out_line); - if ((nl = index(str, '\n')) == 0) break; /* done if no newline */ - } + if ((nl = index(str, '\n')) == 0) + break; /* done if no newline */ + } - free((genericptr_t)lev_message); - lev_message = 0; + free((genericptr_t) lev_message); + lev_message = 0; } } diff --git a/src/read.c b/src/read.c index 1bfd1d102..63062d9d2 100644 --- a/src/read.c +++ b/src/read.c @@ -1,46 +1,46 @@ -/* NetHack 3.6 read.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 read.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.111 $ */ /* NetHack 3.6 read.c $Date: 2012/04/06 08:35:00 $ $Revision: 1.78 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -#define Your_Own_Role(mndx) \ - ((mndx) == urole.malenum || \ - (urole.femalenum != NON_PM && (mndx) == urole.femalenum)) -#define Your_Own_Race(mndx) \ - ((mndx) == urace.malenum || \ - (urace.femalenum != NON_PM && (mndx) == urace.femalenum)) +#define Your_Own_Role(mndx) \ + ((mndx) == urole.malenum \ + || (urole.femalenum != NON_PM && (mndx) == urole.femalenum)) +#define Your_Own_Race(mndx) \ + ((mndx) == urace.malenum \ + || (urace.femalenum != NON_PM && (mndx) == urace.femalenum)) -boolean known; +boolean known; -static NEARDATA const char readable[] = - { ALL_CLASSES, SCROLL_CLASS, SPBOOK_CLASS, 0 }; +static NEARDATA const char readable[] = { ALL_CLASSES, SCROLL_CLASS, + SPBOOK_CLASS, 0 }; static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; STATIC_DCL boolean FDECL(learnscrolltyp, (SHORT_P)); STATIC_DCL void NDECL(do_class_genocide); -STATIC_DCL void FDECL(stripspe,(struct obj *)); -STATIC_DCL void FDECL(p_glow1,(struct obj *)); -STATIC_DCL void FDECL(p_glow2,(struct obj *,const char *)); -STATIC_DCL void FDECL(randomize,(int *, int)); +STATIC_DCL void FDECL(stripspe, (struct obj *)); +STATIC_DCL void FDECL(p_glow1, (struct obj *)); +STATIC_DCL void FDECL(p_glow2, (struct obj *, const char *)); +STATIC_DCL void FDECL(randomize, (int *, int)); STATIC_DCL void FDECL(forget_single_object, (int)); STATIC_DCL void FDECL(forget, (int)); -STATIC_DCL int FDECL(maybe_tame, (struct monst *,struct obj *)); +STATIC_DCL int FDECL(maybe_tame, (struct monst *, struct obj *)); STATIC_DCL boolean FDECL(is_valid_stinking_cloud_pos, (int, int, BOOLEAN_P)); STATIC_DCL void FDECL(display_stinking_cloud_positions, (int)); -STATIC_PTR void FDECL(set_lit, (int,int,genericptr_t)); +STATIC_PTR void FDECL(set_lit, (int, int, genericptr_t)); STATIC_OVL boolean learnscrolltyp(scrolltyp) short scrolltyp; { if (!objects[scrolltyp].oc_name_known) { - makeknown(scrolltyp); - more_experienced(0, 10); - return TRUE; + makeknown(scrolltyp); + more_experienced(0, 10); + return TRUE; } else - return FALSE; + return FALSE; } /* also called from teleport.c for scroll of teleportation */ @@ -51,7 +51,7 @@ struct obj *sobj; /* it's implied that sobj->dknown is set; we couldn't be reading this scroll otherwise */ if (sobj->oclass != SPBOOK_CLASS) - (void) learnscrolltyp(sobj->otyp); + (void) learnscrolltyp(sobj->otyp); } char * @@ -61,9 +61,8 @@ char *buf; { int erosion = greatest_erosion(otmp); if (erosion) - wipeout_text(buf, - (int)(strlen(buf) * erosion / (2*MAX_ERODE)), - otmp->o_id ^ (unsigned)ubirthday); + wipeout_text(buf, (int) (strlen(buf) * erosion / (2 * MAX_ERODE)), + otmp->o_id ^ (unsigned) ubirthday); return buf; } @@ -72,72 +71,53 @@ tshirt_text(tshirt, buf) struct obj *tshirt; char *buf; { - static const char *shirt_msgs[] = { /* Scott Bigham */ - "I explored the Dungeons of Doom and all I got was this lousy T-shirt!", - "Is that Mjollnir in your pocket or are you just happy to see me?", - "It's not the size of your sword, it's how #enhance'd you are with it.", - "Madame Elvira's House O' Succubi Lifetime Customer", - "Madame Elvira's House O' Succubi Employee of the Month", - "Ludios Vault Guards Do It In Small, Dark Rooms", - "Yendor Military Soldiers Do It In Large Groups", - "I survived Yendor Military Boot Camp", - "Ludios Accounting School Intra-Mural Lacrosse Team", - "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest", - "Hey, black dragon! Disintegrate THIS!", - "I'm With Stupid -->", - "Don't blame me, I voted for Izchak!", - "Don't Panic", /* HHGTTG */ - "Furinkan High School Athletic Dept.", /* Ranma 1/2 */ - "Hel-LOOO, Nurse!", /* Animaniacs */ - "=^.^=", - "100% goblin hair - do not wash", - "Aberzombie and Fitch", - "cK -- Cockatrice touches the Kop", - "Don't ask me, I only adventure here", - "Down with pants!", - "d, your dog or a killer?", - "FREE PUG AND NEWT!", - "Go team ant!", - "Got newt?", - "Hello, my darlings!", /* Charlie Drake */ - "Hey! Nymphs! Steal This T-Shirt!", - "I <3 Dungeon of Doom", - "I <3 Maud", - "I am a Valkyrie. If you see me running, try to keep up.", - "I am not a pack rat - I am a collector", - "I bounced off a rubber tree", /* Monkey Island */ - "Plunder Island Brimstone Beach Club", /* Monkey Island */ - "If you can read this, I can hit you with my polearm", - "I'm confused!", - "I scored with the princess", - "I want to live forever or die in the attempt.", - "Lichen Park", - "LOST IN THOUGHT - please send search party", - "Meat is Mordor", - "Minetown Better Business Bureau", - "Minetown Watch", - "Ms. Palm's House of Negotiable Affection -- A Very Reputable House Of Disrepute", - "Protection Racketeer", - "Real men love Crom", - "Somebody stole my Mojo!", - "The Hellhound Gang", - "The Werewolves", - "They Might Be Storm Giants", - "Weapons don't kill people, I kill people", - "White Zombie", - "You're killing me!", - "Anhur State University - Home of the Fighting Fire Ants!", - "FREE HUGS", - "Serial Ascender", - "Real men are valkyries", - "Young Men's Cavedigging Association", - "Occupy Fort Ludios", - "I couldn't afford this T-shirt so I stole it!", - "Mind flayers suck", - "I'm not wearing any pants", - "Down with the living!", - "Pudding farmer", - "Vegetarian", + static const char *shirt_msgs[] = { + /* Scott Bigham */ + "I explored the Dungeons of Doom and all I got was this lousy " + "T-shirt!", + "Is that Mjollnir in your pocket or are you just happy to see me?", + "It's not the size of your sword, it's how #enhance'd you are with " + "it.", + "Madame Elvira's House O' Succubi Lifetime Customer", + "Madame Elvira's House O' Succubi Employee of the Month", + "Ludios Vault Guards Do It In Small, Dark Rooms", + "Yendor Military Soldiers Do It In Large Groups", + "I survived Yendor Military Boot Camp", + "Ludios Accounting School Intra-Mural Lacrosse Team", + "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest", + "Hey, black dragon! Disintegrate THIS!", "I'm With Stupid -->", + "Don't blame me, I voted for Izchak!", "Don't Panic", /* HHGTTG */ + "Furinkan High School Athletic Dept.", /* Ranma 1/2 */ + "Hel-LOOO, Nurse!", /* Animaniacs */ + "=^.^=", "100% goblin hair - do not wash", "Aberzombie and Fitch", + "cK -- Cockatrice touches the Kop", + "Don't ask me, I only adventure here", "Down with pants!", + "d, your dog or a killer?", "FREE PUG AND NEWT!", "Go team ant!", + "Got newt?", "Hello, my darlings!", /* Charlie Drake */ + "Hey! Nymphs! Steal This T-Shirt!", "I <3 Dungeon of Doom", + "I <3 Maud", + "I am a Valkyrie. If you see me running, try to keep up.", + "I am not a pack rat - I am a collector", + "I bounced off a rubber tree", /* Monkey Island */ + "Plunder Island Brimstone Beach Club", /* Monkey Island */ + "If you can read this, I can hit you with my polearm", + "I'm confused!", "I scored with the princess", + "I want to live forever or die in the attempt.", "Lichen Park", + "LOST IN THOUGHT - please send search party", "Meat is Mordor", + "Minetown Better Business Bureau", "Minetown Watch", + "Ms. Palm's House of Negotiable Affection -- A Very Reputable House " + "Of Disrepute", + "Protection Racketeer", "Real men love Crom", + "Somebody stole my Mojo!", "The Hellhound Gang", "The Werewolves", + "They Might Be Storm Giants", + "Weapons don't kill people, I kill people", "White Zombie", + "You're killing me!", + "Anhur State University - Home of the Fighting Fire Ants!", + "FREE HUGS", "Serial Ascender", "Real men are valkyries", + "Young Men's Cavedigging Association", "Occupy Fort Ludios", + "I couldn't afford this T-shirt so I stole it!", "Mind flayers suck", + "I'm not wearing any pants", "Down with the living!", + "Pudding farmer", "Vegetarian", }; Strcpy(buf, shirt_msgs[tshirt->o_id % SIZE(shirt_msgs)]); return erode_obj_text(tshirt, buf); @@ -149,15 +129,12 @@ struct obj *apron; char *buf; { static const char *apron_msgs[] = { - "Kiss the cook", - "I'm making SCIENCE!", - "Don't mess with the chef", - "Don't make me poison you", - "Gehennom's Kitchen", - "Rat: The other white meat", - "If you can't stand the heat, get out of Gehennom!", - "If we weren't meant to eat animals, why are they made out of meat?", - "If you don't like the food, I'll stab you", + "Kiss the cook", "I'm making SCIENCE!", "Don't mess with the chef", + "Don't make me poison you", "Gehennom's Kitchen", + "Rat: The other white meat", + "If you can't stand the heat, get out of Gehennom!", + "If we weren't meant to eat animals, why are they made out of meat?", + "If you don't like the food, I'll stab you", }; Strcpy(buf, apron_msgs[apron->o_id % SIZE(apron_msgs)]); return erode_obj_text(apron, buf); @@ -166,238 +143,237 @@ char *buf; int doread() { - register struct obj *scroll; - boolean confused, nodisappear; + register struct obj *scroll; + boolean confused, nodisappear; - known = FALSE; - if(check_capacity((char *)0)) return (0); - scroll = getobj(readable, "read"); - if(!scroll) return(0); + known = FALSE; + if (check_capacity((char *) 0)) + return (0); + scroll = getobj(readable, "read"); + if (!scroll) + return (0); - /* outrumor has its own blindness check */ - if(scroll->otyp == FORTUNE_COOKIE) { - if(flags.verbose) - You("break up the cookie and throw away the pieces."); - outrumor(bcsign(scroll), BY_COOKIE); - if (!Blind) u.uconduct.literate++; - useup(scroll); - return(1); - } else if (scroll->otyp == T_SHIRT || - scroll->otyp == ALCHEMY_SMOCK) { - char buf[BUFSZ]; - if (Blind) { - You_cant("feel any Braille writing."); - return 0; - } - /* can't read shirt worn under suit (under cloak is ok though) */ - if (scroll->otyp == T_SHIRT && uarm && scroll == uarmu) { - pline("%s shirt is obscured by %s%s.", - scroll->unpaid ? "That" : "Your", - shk_your(buf, uarm), suit_simple_name(uarm)); - return 0; - } - u.uconduct.literate++; - if(flags.verbose) - pline("It reads:"); - pline("\"%s\"", (scroll->otyp == T_SHIRT) - ? tshirt_text(scroll, buf) - : apron_text(scroll, buf)); - return 1; - } else if (scroll->otyp == CREDIT_CARD) { - static const char *card_msgs[] = { - "Leprechaun Gold Tru$t - Shamrock Card", - "Magic Memory Vault Charge Card", - "Larn National Bank", /* Larn */ - "First Bank of Omega", /* Omega */ - "Bank of Zork - Frobozz Magic Card", /* Zork */ - "Ankh-Morpork Merchant's Guild Barter Card", - "Ankh-Morpork Thieves' Guild Unlimited Transaction Card", - "Ransmannsby Moneylenders Association", - "Bank of Gehennom - 99% Interest Card", - "Yendorian Express - Copper Card", - "Yendorian Express - Silver Card", - "Yendorian Express - Gold Card", - "Yendorian Express - Mithril Card", - "Yendorian Express - Platinum Card", /* must be last */ - }; - if (Blind) { - You("feel the embossed numbers:"); - } else { - if(flags.verbose) - pline("It reads:"); - pline("\"%s\"", scroll->oartifact ? card_msgs[SIZE(card_msgs)-1] - : card_msgs[scroll->o_id % (SIZE(card_msgs)-1)]); - } - /* Make a credit card number */ - pline("\"%d0%d %d%d1 0%d%d0\"", ((scroll->o_id % 89)+10), (scroll->o_id % 4), - (((scroll->o_id * 499) % 899999) + 100000), (scroll->o_id % 10), - (!(scroll->o_id % 3)), ((scroll->o_id * 7) % 10)); + /* outrumor has its own blindness check */ + if (scroll->otyp == FORTUNE_COOKIE) { + if (flags.verbose) + You("break up the cookie and throw away the pieces."); + outrumor(bcsign(scroll), BY_COOKIE); + if (!Blind) u.uconduct.literate++; - return 1; - } else if (scroll->otyp == CAN_OF_GREASE) { - pline("This %s has no label.", singular(scroll, xname)); + useup(scroll); + return (1); + } else if (scroll->otyp == T_SHIRT || scroll->otyp == ALCHEMY_SMOCK) { + char buf[BUFSZ]; + if (Blind) { + You_cant("feel any Braille writing."); return 0; - } else if (scroll->otyp == MAGIC_MARKER) { - if (Blind) { - You_cant("feel any Braille writing."); - return 0; - } - if (flags.verbose) - pline("It reads:"); - pline("\"Magic Marker(TM) Red Ink Marker Pen. Water Soluble.\""); - u.uconduct.literate++; - return 1; - } else if (scroll->oclass == COIN_CLASS) { - if (Blind) - You("feel the embossed words:"); - else if (flags.verbose) - You("read:"); - pline("\"1 Zorkmid. 857 GUE. In Frobs We Trust.\""); - u.uconduct.literate++; - return 1; - } else if (scroll->oartifact == ART_ORB_OF_FATE) { - if (Blind) - You("feel the engraved signature:"); - else pline("It is signed:"); - pline("\"Odin.\""); - u.uconduct.literate++; - return 1; - } else if (scroll->otyp == CANDY_BAR) { - static const char *wrapper_msgs[] = { - "Apollo", /* Lost */ - "Moon Crunchy", /* South Park */ - "Snacky Cake", - "Chocolate Nuggie", - "The Small Bar", - "Crispy Yum Yum", - "Nilla Crunchie", - "Berry Bar", - "Choco Nummer", - "Om-nom", /* Cat Macro */ - "Fruity Oaty", /* Serenity */ - "Wonka Bar" /* Charlie and the Chocolate Factory */ - }; - if (Blind) { - You_cant("feel any Braille writing."); - return 0; - } - pline("The wrapper reads: \"%s\"", wrapper_msgs[scroll->o_id % SIZE(wrapper_msgs)]); - u.uconduct.literate++; - return 1; - } else if (scroll->oclass != SCROLL_CLASS - && scroll->oclass != SPBOOK_CLASS) { - pline(silly_thing_to, "read"); - return(0); - } else if (Blind && (scroll->otyp != SPE_BOOK_OF_THE_DEAD)) { - const char *what = 0; - if (scroll->oclass == SPBOOK_CLASS) - what = "mystic runes"; - else if (!scroll->dknown) - what = "formula on the scroll"; - if (what) { - pline("Being blind, you cannot read the %s.", what); - return(0); - } - } + } + /* can't read shirt worn under suit (under cloak is ok though) */ + if (scroll->otyp == T_SHIRT && uarm && scroll == uarmu) { + pline("%s shirt is obscured by %s%s.", + scroll->unpaid ? "That" : "Your", shk_your(buf, uarm), + suit_simple_name(uarm)); + return 0; + } + u.uconduct.literate++; + if (flags.verbose) + pline("It reads:"); + pline("\"%s\"", (scroll->otyp == T_SHIRT) ? tshirt_text(scroll, buf) + : apron_text(scroll, buf)); + return 1; + } else if (scroll->otyp == CREDIT_CARD) { + static const char *card_msgs[] = { + "Leprechaun Gold Tru$t - Shamrock Card", + "Magic Memory Vault Charge Card", "Larn National Bank", /* Larn */ + "First Bank of Omega", /* Omega */ + "Bank of Zork - Frobozz Magic Card", /* Zork */ + "Ankh-Morpork Merchant's Guild Barter Card", + "Ankh-Morpork Thieves' Guild Unlimited Transaction Card", + "Ransmannsby Moneylenders Association", + "Bank of Gehennom - 99% Interest Card", + "Yendorian Express - Copper Card", + "Yendorian Express - Silver Card", + "Yendorian Express - Gold Card", + "Yendorian Express - Mithril Card", + "Yendorian Express - Platinum Card", /* must be last */ + }; + if (Blind) { + You("feel the embossed numbers:"); + } else { + if (flags.verbose) + pline("It reads:"); + pline("\"%s\"", + scroll->oartifact + ? card_msgs[SIZE(card_msgs) - 1] + : card_msgs[scroll->o_id % (SIZE(card_msgs) - 1)]); + } + /* Make a credit card number */ + pline("\"%d0%d %d%d1 0%d%d0\"", ((scroll->o_id % 89) + 10), + (scroll->o_id % 4), (((scroll->o_id * 499) % 899999) + 100000), + (scroll->o_id % 10), (!(scroll->o_id % 3)), + ((scroll->o_id * 7) % 10)); + u.uconduct.literate++; + return 1; + } else if (scroll->otyp == CAN_OF_GREASE) { + pline("This %s has no label.", singular(scroll, xname)); + return 0; + } else if (scroll->otyp == MAGIC_MARKER) { + if (Blind) { + You_cant("feel any Braille writing."); + return 0; + } + if (flags.verbose) + pline("It reads:"); + pline("\"Magic Marker(TM) Red Ink Marker Pen. Water Soluble.\""); + u.uconduct.literate++; + return 1; + } else if (scroll->oclass == COIN_CLASS) { + if (Blind) + You("feel the embossed words:"); + else if (flags.verbose) + You("read:"); + pline("\"1 Zorkmid. 857 GUE. In Frobs We Trust.\""); + u.uconduct.literate++; + return 1; + } else if (scroll->oartifact == ART_ORB_OF_FATE) { + if (Blind) + You("feel the engraved signature:"); + else + pline("It is signed:"); + pline("\"Odin.\""); + u.uconduct.literate++; + return 1; + } else if (scroll->otyp == CANDY_BAR) { + static const char *wrapper_msgs[] = { + "Apollo", /* Lost */ + "Moon Crunchy", /* South Park */ + "Snacky Cake", "Chocolate Nuggie", "The Small Bar", + "Crispy Yum Yum", "Nilla Crunchie", "Berry Bar", + "Choco Nummer", "Om-nom", /* Cat Macro */ + "Fruity Oaty", /* Serenity */ + "Wonka Bar" /* Charlie and the Chocolate Factory */ + }; + if (Blind) { + You_cant("feel any Braille writing."); + return 0; + } + pline("The wrapper reads: \"%s\"", + wrapper_msgs[scroll->o_id % SIZE(wrapper_msgs)]); + u.uconduct.literate++; + return 1; + } else if (scroll->oclass != SCROLL_CLASS + && scroll->oclass != SPBOOK_CLASS) { + pline(silly_thing_to, "read"); + return (0); + } else if (Blind && (scroll->otyp != SPE_BOOK_OF_THE_DEAD)) { + const char *what = 0; + if (scroll->oclass == SPBOOK_CLASS) + what = "mystic runes"; + else if (!scroll->dknown) + what = "formula on the scroll"; + if (what) { + pline("Being blind, you cannot read the %s.", what); + return (0); + } + } - confused = (Confusion != 0); + confused = (Confusion != 0); #ifdef MAIL - if (scroll->otyp == SCR_MAIL) { - confused = FALSE; /* override */ - /* reading mail is a convenience for the player and takes - place outside the game, so shouldn't affect gameplay; - on the other hand, it starts by explicitly making the - hero actively read something, which is pretty hard - to simply ignore; as a compromise, if the player has - maintained illiterate conduct so far, and this mail - scroll didn't come from bones, ask for confirmation */ - if (!u.uconduct.literate) { - if (!scroll->spe && - yn("Reading mail will violate \"illiterate\" conduct. Read anyway?") - != 'y') return 0; - } - } + if (scroll->otyp == SCR_MAIL) { + confused = FALSE; /* override */ + /* reading mail is a convenience for the player and takes + place outside the game, so shouldn't affect gameplay; + on the other hand, it starts by explicitly making the + hero actively read something, which is pretty hard + to simply ignore; as a compromise, if the player has + maintained illiterate conduct so far, and this mail + scroll didn't come from bones, ask for confirmation */ + if (!u.uconduct.literate) { + if (!scroll->spe && yn("Reading mail will violate \"illiterate\" " + "conduct. Read anyway?") != 'y') + return 0; + } + } #endif - /* Actions required to win the game aren't counted towards conduct */ - /* Novel conduct is handled in read_tribute so exclude it too*/ - if (scroll->otyp != SPE_BOOK_OF_THE_DEAD && - scroll->otyp != SPE_BLANK_PAPER && - scroll->otyp != SCR_BLANK_PAPER && - scroll->otyp != SPE_NOVEL) - u.uconduct.literate++; + /* Actions required to win the game aren't counted towards conduct */ + /* Novel conduct is handled in read_tribute so exclude it too*/ + if (scroll->otyp != SPE_BOOK_OF_THE_DEAD + && scroll->otyp != SPE_BLANK_PAPER && scroll->otyp != SCR_BLANK_PAPER + && scroll->otyp != SPE_NOVEL) + u.uconduct.literate++; - if(scroll->oclass == SPBOOK_CLASS) { - return(study_book(scroll)); - } - scroll->in_use = TRUE; /* scroll, not spellbook, now being read */ - if (scroll->otyp != SCR_BLANK_PAPER) { - /* a few scroll feedback messages describe something happening - to the scroll itself, so avoid "it disappears" for those */ - nodisappear = (scroll->otyp == SCR_FIRE || - (scroll->otyp == SCR_REMOVE_CURSE && scroll->cursed)); - if (Blind) - pline(nodisappear ? "You %s the formula on the scroll." : - "As you %s the formula on it, the scroll disappears.", - is_silent(youmonst.data) ? "cogitate" : "pronounce"); - else - pline(nodisappear ? "You read the scroll." : - "As you read the scroll, it disappears."); - if (confused) { - if (Hallucination) - pline("Being so trippy, you screw up..."); - else - pline("Being confused, you %s the magic words...", - is_silent(youmonst.data) ? "misunderstand" : - "mispronounce"); - } - } - if(!seffects(scroll)) { - if(!objects[scroll->otyp].oc_name_known) { - if (known) - learnscroll(scroll); - else if (!objects[scroll->otyp].oc_uname) - docall(scroll); - } - scroll->in_use = FALSE; - if(scroll->otyp != SCR_BLANK_PAPER) - useup(scroll); - } - return(1); + if (scroll->oclass == SPBOOK_CLASS) { + return (study_book(scroll)); + } + scroll->in_use = TRUE; /* scroll, not spellbook, now being read */ + if (scroll->otyp != SCR_BLANK_PAPER) { + /* a few scroll feedback messages describe something happening + to the scroll itself, so avoid "it disappears" for those */ + nodisappear = + (scroll->otyp == SCR_FIRE + || (scroll->otyp == SCR_REMOVE_CURSE && scroll->cursed)); + if (Blind) + pline(nodisappear + ? "You %s the formula on the scroll." + : "As you %s the formula on it, the scroll disappears.", + is_silent(youmonst.data) ? "cogitate" : "pronounce"); + else + pline(nodisappear ? "You read the scroll." + : "As you read the scroll, it disappears."); + if (confused) { + if (Hallucination) + pline("Being so trippy, you screw up..."); + else + pline("Being confused, you %s the magic words...", + is_silent(youmonst.data) ? "misunderstand" + : "mispronounce"); + } + } + if (!seffects(scroll)) { + if (!objects[scroll->otyp].oc_name_known) { + if (known) + learnscroll(scroll); + else if (!objects[scroll->otyp].oc_uname) + docall(scroll); + } + scroll->in_use = FALSE; + if (scroll->otyp != SCR_BLANK_PAPER) + useup(scroll); + } + return (1); } STATIC_OVL void stripspe(obj) register struct obj *obj; { - if (obj->blessed || obj->spe <= 0) { - pline1(nothing_happens); - } else { - /* order matters: message, shop handling, actual transformation */ - pline("%s briefly.", Yobjnam2(obj, "vibrate")); - costly_alteration(obj, COST_UNCHRG); - obj->spe = 0; - if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN) - obj->age = 0; - } + if (obj->blessed || obj->spe <= 0) { + pline1(nothing_happens); + } else { + /* order matters: message, shop handling, actual transformation */ + pline("%s briefly.", Yobjnam2(obj, "vibrate")); + costly_alteration(obj, COST_UNCHRG); + obj->spe = 0; + if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN) + obj->age = 0; + } } STATIC_OVL void p_glow1(otmp) -register struct obj *otmp; +register struct obj *otmp; { - pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow")); + pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow")); } STATIC_OVL void -p_glow2(otmp,color) -register struct obj *otmp; +p_glow2(otmp, color) +register struct obj *otmp; register const char *color; { - pline("%s%s%s for a moment.", - Yobjnam2(otmp, Blind ? "vibrate" : "glow"), - Blind ? "" : " ", - Blind ? "" : hcolor(color)); + pline("%s%s%s for a moment.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"), + Blind ? "" : " ", Blind ? "" : hcolor(color)); } /* Is the object chargeable? For purposes of inventory display; it is */ @@ -406,17 +382,19 @@ boolean is_chargeable(obj) struct obj *obj; { - if (obj->oclass == WAND_CLASS) return TRUE; - /* known && !oc_name_known is possible after amnesia/mind flayer */ - if (obj->oclass == RING_CLASS) - return (boolean)(objects[obj->otyp].oc_charged && - (obj->known || - (obj->dknown && objects[obj->otyp].oc_name_known))); - if (is_weptool(obj)) /* specific check before general tools */ - return FALSE; - if (obj->oclass == TOOL_CLASS) - return (boolean)(objects[obj->otyp].oc_charged); - return FALSE; /* why are weapons/armor considered charged anyway? */ + if (obj->oclass == WAND_CLASS) + return TRUE; + /* known && !oc_name_known is possible after amnesia/mind flayer */ + if (obj->oclass == RING_CLASS) + return (boolean)( + objects[obj->otyp].oc_charged + && (obj->known + || (obj->dknown && objects[obj->otyp].oc_name_known))); + if (is_weptool(obj)) /* specific check before general tools */ + return FALSE; + if (obj->oclass == TOOL_CLASS) + return (boolean)(objects[obj->otyp].oc_charged); + return FALSE; /* why are weapons/armor considered charged anyway? */ } /* @@ -428,242 +406,266 @@ recharge(obj, curse_bless) struct obj *obj; int curse_bless; { - register int n; - boolean is_cursed, is_blessed; + register int n; + boolean is_cursed, is_blessed; - is_cursed = curse_bless < 0; - is_blessed = curse_bless > 0; + is_cursed = curse_bless < 0; + is_blessed = curse_bless > 0; - if (obj->oclass == WAND_CLASS) { - int lim = (obj->otyp == WAN_WISHING) ? 3 : - (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15; + if (obj->oclass == WAND_CLASS) { + int lim = (obj->otyp == WAN_WISHING) + ? 3 + : (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15; - /* undo any prior cancellation, even when is_cursed */ - if (obj->spe == -1) obj->spe = 0; + /* undo any prior cancellation, even when is_cursed */ + if (obj->spe == -1) + obj->spe = 0; - /* - * Recharging might cause wands to explode. - * v = number of previous recharges - * v = percentage chance to explode on this attempt - * v = cumulative odds for exploding - * 0 : 0 0 - * 1 : 0.29 0.29 - * 2 : 2.33 2.62 - * 3 : 7.87 10.28 - * 4 : 18.66 27.02 - * 5 : 36.44 53.62 - * 6 : 62.97 82.83 - * 7 : 100 100 - */ - n = (int)obj->recharged; - if (n > 0 && (obj->otyp == WAN_WISHING || - (n * n * n > rn2(7*7*7)))) { /* recharge_limit */ - wand_explode(obj, rnd(lim)); - return; - } - /* didn't explode, so increment the recharge count */ - obj->recharged = (unsigned)(n + 1); + /* + * Recharging might cause wands to explode. + * v = number of previous recharges + * v = percentage chance to explode on this attempt + * v = cumulative odds for exploding + * 0 : 0 0 + * 1 : 0.29 0.29 + * 2 : 2.33 2.62 + * 3 : 7.87 10.28 + * 4 : 18.66 27.02 + * 5 : 36.44 53.62 + * 6 : 62.97 82.83 + * 7 : 100 100 + */ + n = (int) obj->recharged; + if (n > 0 && (obj->otyp == WAN_WISHING + || (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */ + wand_explode(obj, rnd(lim)); + return; + } + /* didn't explode, so increment the recharge count */ + obj->recharged = (unsigned) (n + 1); - /* now handle the actual recharging */ - if (is_cursed) { - stripspe(obj); - } else { - n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5); - if (!is_blessed) n = rnd(n); + /* now handle the actual recharging */ + if (is_cursed) { + stripspe(obj); + } else { + n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5); + if (!is_blessed) + n = rnd(n); - if (obj->spe < n) obj->spe = n; - else obj->spe++; - if (obj->otyp == WAN_WISHING && obj->spe > 3) { - wand_explode(obj, 1); - return; - } - if (obj->spe >= lim) p_glow2(obj, NH_BLUE); - else p_glow1(obj); -#if 0 /*[shop price doesn't vary by charge count]*/ + if (obj->spe < n) + obj->spe = n; + else + obj->spe++; + if (obj->otyp == WAN_WISHING && obj->spe > 3) { + wand_explode(obj, 1); + return; + } + if (obj->spe >= lim) + p_glow2(obj, NH_BLUE); + else + p_glow1(obj); +#if 0 /*[shop price doesn't vary by charge count]*/ /* update shop bill to reflect new higher price */ if (obj->unpaid) alter_cost(obj, 0L); #endif - } + } - } else if (obj->oclass == RING_CLASS && - objects[obj->otyp].oc_charged) { - /* charging does not affect ring's curse/bless status */ - int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1; - boolean is_on = (obj == uleft || obj == uright); + } else if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged) { + /* charging does not affect ring's curse/bless status */ + int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1; + boolean is_on = (obj == uleft || obj == uright); - /* destruction depends on current state, not adjustment */ - if (obj->spe > rn2(7) || obj->spe <= -5) { - pline("%s momentarily, then %s!", - Yobjnam2(obj, "pulsate"), otense(obj,"explode")); - if (is_on) Ring_gone(obj); - s = rnd(3 * abs(obj->spe)); /* amount of damage */ - useup(obj); - losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN); - } else { - long mask = is_on ? (obj == uleft ? LEFT_RING : - RIGHT_RING) : 0L; - pline("%s spins %sclockwise for a moment.", - Yname2(obj), s < 0 ? "counter" : ""); - if (s < 0) costly_alteration(obj, COST_DECHNT); - /* cause attributes and/or properties to be updated */ - if (is_on) Ring_off(obj); - obj->spe += s; /* update the ring while it's off */ - if (is_on) setworn(obj, mask), Ring_on(obj); - /* oartifact: if a touch-sensitive artifact ring is - ever created the above will need to be revised */ - /* update shop bill to reflect new higher price */ - if (s > 0 && obj->unpaid) alter_cost(obj, 0L); - } + /* destruction depends on current state, not adjustment */ + if (obj->spe > rn2(7) || obj->spe <= -5) { + pline("%s momentarily, then %s!", Yobjnam2(obj, "pulsate"), + otense(obj, "explode")); + if (is_on) + Ring_gone(obj); + s = rnd(3 * abs(obj->spe)); /* amount of damage */ + useup(obj); + losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN); + } else { + long mask = is_on ? (obj == uleft ? LEFT_RING : RIGHT_RING) : 0L; + pline("%s spins %sclockwise for a moment.", Yname2(obj), + s < 0 ? "counter" : ""); + if (s < 0) + costly_alteration(obj, COST_DECHNT); + /* cause attributes and/or properties to be updated */ + if (is_on) + Ring_off(obj); + obj->spe += s; /* update the ring while it's off */ + if (is_on) + setworn(obj, mask), Ring_on(obj); + /* oartifact: if a touch-sensitive artifact ring is + ever created the above will need to be revised */ + /* update shop bill to reflect new higher price */ + if (s > 0 && obj->unpaid) + alter_cost(obj, 0L); + } - } else if (obj->oclass == TOOL_CLASS) { - int rechrg = (int)obj->recharged; + } else if (obj->oclass == TOOL_CLASS) { + int rechrg = (int) obj->recharged; - if (objects[obj->otyp].oc_charged) { - /* tools don't have a limit, but the counter used does */ - if (rechrg < 7) /* recharge_limit */ - obj->recharged++; - } - switch(obj->otyp) { - case BELL_OF_OPENING: - if (is_cursed) stripspe(obj); - else if (is_blessed) obj->spe += rnd(3); - else obj->spe += 1; - if (obj->spe > 5) obj->spe = 5; - break; - case MAGIC_MARKER: - case TINNING_KIT: - case EXPENSIVE_CAMERA: - if (is_cursed) stripspe(obj); - else if (rechrg && obj->otyp == MAGIC_MARKER) { /* previously recharged */ - obj->recharged = 1; /* override increment done above */ - if (obj->spe < 3) - Your("marker seems permanently dried out."); - else - pline1(nothing_happens); - } else if (is_blessed) { - n = rn1(16,15); /* 15..30 */ - if (obj->spe + n <= 50) - obj->spe = 50; - else if (obj->spe + n <= 75) - obj->spe = 75; - else { - int chrg = (int)obj->spe; - if ((chrg + n) > 127) - obj->spe = 127; - else - obj->spe += n; - } - p_glow2(obj, NH_BLUE); - } else { - n = rn1(11,10); /* 10..20 */ - if (obj->spe + n <= 50) - obj->spe = 50; - else { - int chrg = (int)obj->spe; - if ((chrg + n) > 127) - obj->spe = 127; - else - obj->spe += n; - } - p_glow2(obj, NH_WHITE); - } - break; - case OIL_LAMP: - case BRASS_LANTERN: - if (is_cursed) { - stripspe(obj); - if (obj->lamplit) { - if (!Blind) - pline("%s out!", Tobjnam(obj, "go")); - end_burn(obj, TRUE); - } - } else if (is_blessed) { - obj->spe = 1; - obj->age = 1500; - p_glow2(obj, NH_BLUE); - } else { - obj->spe = 1; - obj->age += 750; - if (obj->age > 1500) obj->age = 1500; - p_glow1(obj); - } - break; - case CRYSTAL_BALL: - if (is_cursed) stripspe(obj); - else if (is_blessed) { - obj->spe = 6; - p_glow2(obj, NH_BLUE); - } else { - if (obj->spe < 5) { - obj->spe++; - p_glow1(obj); - } else pline1(nothing_happens); - } - break; - case HORN_OF_PLENTY: - case BAG_OF_TRICKS: - case CAN_OF_GREASE: - if (is_cursed) stripspe(obj); - else if (is_blessed) { - if (obj->spe <= 10) - obj->spe += rn1(10, 6); - else obj->spe += rn1(5, 6); - if (obj->spe > 50) obj->spe = 50; - p_glow2(obj, NH_BLUE); - } else { - obj->spe += rnd(5); - if (obj->spe > 50) obj->spe = 50; - p_glow1(obj); - } - break; - case MAGIC_FLUTE: - case MAGIC_HARP: - case FROST_HORN: - case FIRE_HORN: - case DRUM_OF_EARTHQUAKE: - if (is_cursed) { - stripspe(obj); - } else if (is_blessed) { - obj->spe += d(2,4); - if (obj->spe > 20) obj->spe = 20; - p_glow2(obj, NH_BLUE); - } else { - obj->spe += rnd(4); - if (obj->spe > 20) obj->spe = 20; - p_glow1(obj); - } - break; - default: - goto not_chargable; - /*NOTREACHED*/ - break; - } /* switch */ + if (objects[obj->otyp].oc_charged) { + /* tools don't have a limit, but the counter used does */ + if (rechrg < 7) /* recharge_limit */ + obj->recharged++; + } + switch (obj->otyp) { + case BELL_OF_OPENING: + if (is_cursed) + stripspe(obj); + else if (is_blessed) + obj->spe += rnd(3); + else + obj->spe += 1; + if (obj->spe > 5) + obj->spe = 5; + break; + case MAGIC_MARKER: + case TINNING_KIT: + case EXPENSIVE_CAMERA: + if (is_cursed) + stripspe(obj); + else if (rechrg + && obj->otyp + == MAGIC_MARKER) { /* previously recharged */ + obj->recharged = 1; /* override increment done above */ + if (obj->spe < 3) + Your("marker seems permanently dried out."); + else + pline1(nothing_happens); + } else if (is_blessed) { + n = rn1(16, 15); /* 15..30 */ + if (obj->spe + n <= 50) + obj->spe = 50; + else if (obj->spe + n <= 75) + obj->spe = 75; + else { + int chrg = (int) obj->spe; + if ((chrg + n) > 127) + obj->spe = 127; + else + obj->spe += n; + } + p_glow2(obj, NH_BLUE); + } else { + n = rn1(11, 10); /* 10..20 */ + if (obj->spe + n <= 50) + obj->spe = 50; + else { + int chrg = (int) obj->spe; + if ((chrg + n) > 127) + obj->spe = 127; + else + obj->spe += n; + } + p_glow2(obj, NH_WHITE); + } + break; + case OIL_LAMP: + case BRASS_LANTERN: + if (is_cursed) { + stripspe(obj); + if (obj->lamplit) { + if (!Blind) + pline("%s out!", Tobjnam(obj, "go")); + end_burn(obj, TRUE); + } + } else if (is_blessed) { + obj->spe = 1; + obj->age = 1500; + p_glow2(obj, NH_BLUE); + } else { + obj->spe = 1; + obj->age += 750; + if (obj->age > 1500) + obj->age = 1500; + p_glow1(obj); + } + break; + case CRYSTAL_BALL: + if (is_cursed) + stripspe(obj); + else if (is_blessed) { + obj->spe = 6; + p_glow2(obj, NH_BLUE); + } else { + if (obj->spe < 5) { + obj->spe++; + p_glow1(obj); + } else + pline1(nothing_happens); + } + break; + case HORN_OF_PLENTY: + case BAG_OF_TRICKS: + case CAN_OF_GREASE: + if (is_cursed) + stripspe(obj); + else if (is_blessed) { + if (obj->spe <= 10) + obj->spe += rn1(10, 6); + else + obj->spe += rn1(5, 6); + if (obj->spe > 50) + obj->spe = 50; + p_glow2(obj, NH_BLUE); + } else { + obj->spe += rnd(5); + if (obj->spe > 50) + obj->spe = 50; + p_glow1(obj); + } + break; + case MAGIC_FLUTE: + case MAGIC_HARP: + case FROST_HORN: + case FIRE_HORN: + case DRUM_OF_EARTHQUAKE: + if (is_cursed) { + stripspe(obj); + } else if (is_blessed) { + obj->spe += d(2, 4); + if (obj->spe > 20) + obj->spe = 20; + p_glow2(obj, NH_BLUE); + } else { + obj->spe += rnd(4); + if (obj->spe > 20) + obj->spe = 20; + p_glow1(obj); + } + break; + default: + goto not_chargable; + /*NOTREACHED*/ + break; + } /* switch */ - } else { - not_chargable: - You("have a feeling of loss."); - } + } else { + not_chargable: + You("have a feeling of loss."); + } } - /* Forget known information about this object class. */ STATIC_OVL void forget_single_object(obj_id) - int obj_id; +int obj_id; { - objects[obj_id].oc_name_known = 0; - objects[obj_id].oc_pre_discovered = 0; /* a discovery when relearned */ - if (objects[obj_id].oc_uname) { - free((genericptr_t)objects[obj_id].oc_uname); - objects[obj_id].oc_uname = 0; - } - undiscover_object(obj_id); /* after clearing oc_name_known */ + objects[obj_id].oc_name_known = 0; + objects[obj_id].oc_pre_discovered = 0; /* a discovery when relearned */ + if (objects[obj_id].oc_uname) { + free((genericptr_t) objects[obj_id].oc_uname); + objects[obj_id].oc_uname = 0; + } + undiscover_object(obj_id); /* after clearing oc_name_known */ - /* clear & free object names from matching inventory items too? */ + /* clear & free object names from matching inventory items too? */ } - -#if 0 /* here if anyone wants it.... */ +#if 0 /* here if anyone wants it.... */ /* Forget everything known about a particular object class. */ STATIC_OVL void forget_objclass(oclass) @@ -677,83 +679,83 @@ forget_objclass(oclass) } #endif - /* randomize the given list of numbers 0 <= i < count */ STATIC_OVL void randomize(indices, count) - int *indices; - int count; +int *indices; +int count; { - int i, iswap, temp; + int i, iswap, temp; - for (i = count - 1; i > 0; i--) { - if ((iswap = rn2(i + 1)) == i) continue; - temp = indices[i]; - indices[i] = indices[iswap]; - indices[iswap] = temp; - } + for (i = count - 1; i > 0; i--) { + if ((iswap = rn2(i + 1)) == i) + continue; + temp = indices[i]; + indices[i] = indices[iswap]; + indices[iswap] = temp; + } } - /* Forget % of known objects. */ void forget_objects(percent) - int percent; +int percent; { - int i, count; - int indices[NUM_OBJECTS]; + int i, count; + int indices[NUM_OBJECTS]; - if (percent == 0) return; - if (percent <= 0 || percent > 100) { - impossible("forget_objects: bad percent %d", percent); - return; - } + if (percent == 0) + return; + if (percent <= 0 || percent > 100) { + impossible("forget_objects: bad percent %d", percent); + return; + } - for (count = 0, i = 1; i < NUM_OBJECTS; i++) - if (OBJ_DESCR(objects[i]) && - (objects[i].oc_name_known || objects[i].oc_uname)) - indices[count++] = i; + for (count = 0, i = 1; i < NUM_OBJECTS; i++) + if (OBJ_DESCR(objects[i]) + && (objects[i].oc_name_known || objects[i].oc_uname)) + indices[count++] = i; - randomize(indices, count); + randomize(indices, count); - /* forget first % of randomized indices */ - count = ((count * percent) + rn2(100)) / 100; - for (i = 0; i < count; i++) - forget_single_object(indices[i]); + /* forget first % of randomized indices */ + count = ((count * percent) + rn2(100)) / 100; + for (i = 0; i < count; i++) + forget_single_object(indices[i]); } - /* Forget some or all of map (depends on parameters). */ void forget_map(howmuch) - int howmuch; +int howmuch; { - register int zx, zy; + register int zx, zy; - if (Sokoban) - return; + if (Sokoban) + return; - known = TRUE; - for(zx = 0; zx < COLNO; zx++) for(zy = 0; zy < ROWNO; zy++) - if (howmuch & ALL_MAP || rn2(7)) { - /* Zonk all memory of this location. */ - levl[zx][zy].seenv = 0; - levl[zx][zy].waslit = 0; - levl[zx][zy].glyph = cmap_to_glyph(S_stone); - lastseentyp[zx][zy] = STONE; - } + known = TRUE; + for (zx = 0; zx < COLNO; zx++) + for (zy = 0; zy < ROWNO; zy++) + if (howmuch & ALL_MAP || rn2(7)) { + /* Zonk all memory of this location. */ + levl[zx][zy].seenv = 0; + levl[zx][zy].waslit = 0; + levl[zx][zy].glyph = cmap_to_glyph(S_stone); + lastseentyp[zx][zy] = STONE; + } } /* Forget all traps on the level. */ void forget_traps() { - register struct trap *trap; + register struct trap *trap; - /* forget all traps (except the one the hero is in :-) */ - for (trap = ftrap; trap; trap = trap->ntrap) - if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE)) - trap->tseen = 0; + /* forget all traps (except the one the hero is in :-) */ + for (trap = ftrap; trap; trap = trap->ntrap) + if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE)) + trap->tseen = 0; } /* @@ -762,47 +764,49 @@ forget_traps() */ void forget_levels(percent) - int percent; +int percent; { - int i, count; - xchar maxl, this_lev; - int indices[MAXLINFO]; + int i, count; + xchar maxl, this_lev; + int indices[MAXLINFO]; - if (percent == 0) return; + if (percent == 0) + return; - if (percent <= 0 || percent > 100) { - impossible("forget_levels: bad percent %d", percent); - return; - } + if (percent <= 0 || percent > 100) { + impossible("forget_levels: bad percent %d", percent); + return; + } - this_lev = ledger_no(&u.uz); - maxl = maxledgerno(); + this_lev = ledger_no(&u.uz); + maxl = maxledgerno(); - /* count & save indices of non-forgotten visited levels */ - /* Sokoban levels are pre-mapped for the player, and should stay - * so, or they become nearly impossible to solve. But try to - * shift the forgetting elsewhere by fiddling with percent - * instead of forgetting fewer levels. - */ - for (count = 0, i = 0; i <= maxl; i++) - if ((level_info[i].flags & VISITED) && - !(level_info[i].flags & FORGOTTEN) && i != this_lev) { - if (ledger_to_dnum(i) == sokoban_dnum) - percent += 2; - else - indices[count++] = i; - } - - if (percent > 100) percent = 100; + /* count & save indices of non-forgotten visited levels */ + /* Sokoban levels are pre-mapped for the player, and should stay + * so, or they become nearly impossible to solve. But try to + * shift the forgetting elsewhere by fiddling with percent + * instead of forgetting fewer levels. + */ + for (count = 0, i = 0; i <= maxl; i++) + if ((level_info[i].flags & VISITED) + && !(level_info[i].flags & FORGOTTEN) && i != this_lev) { + if (ledger_to_dnum(i) == sokoban_dnum) + percent += 2; + else + indices[count++] = i; + } - randomize(indices, count); + if (percent > 100) + percent = 100; - /* forget first % of randomized indices */ - count = ((count * percent) + 50) / 100; - for (i = 0; i < count; i++) { - level_info[indices[i]].flags |= FORGOTTEN; - forget_mapseen(indices[i]); - } + randomize(indices, count); + + /* forget first % of randomized indices */ + count = ((count * percent) + 50) / 100; + for (i = 0; i < count; i++) { + level_info[indices[i]].flags |= FORGOTTEN; + forget_mapseen(indices[i]); + } } /* @@ -822,30 +826,33 @@ STATIC_OVL void forget(howmuch) int howmuch; { + if (Punished) + u.bc_felt = 0; /* forget felt ball&chain */ - if (Punished) u.bc_felt = 0; /* forget felt ball&chain */ + forget_map(howmuch); + forget_traps(); - forget_map(howmuch); - forget_traps(); + /* 1 in 3 chance of forgetting some levels */ + if (!rn2(3)) + forget_levels(rn2(25)); - /* 1 in 3 chance of forgetting some levels */ - if (!rn2(3)) forget_levels(rn2(25)); + /* 1 in 3 chance of forgeting some objects */ + if (!rn2(3)) + forget_objects(rn2(25)); - /* 1 in 3 chance of forgeting some objects */ - if (!rn2(3)) forget_objects(rn2(25)); - - if (howmuch & ALL_SPELLS) losespells(); - /* - * Make sure that what was seen is restored correctly. To do this, - * we need to go blind for an instant --- turn off the display, - * then restart it. All this work is needed to correctly handle - * walls which are stone on one side and wall on the other. Turning - * off the seen bits above will make the wall revert to stone, but - * there are cases where we don't want this to happen. The easiest - * thing to do is to run it through the vision system again, which - * is always correct. - */ - docrt(); /* this correctly will reset vision */ + if (howmuch & ALL_SPELLS) + losespells(); + /* + * Make sure that what was seen is restored correctly. To do this, + * we need to go blind for an instant --- turn off the display, + * then restart it. All this work is needed to correctly handle + * walls which are stone on one side and wall on the other. Turning + * off the seen bits above will make the wall revert to stone, but + * there are cases where we don't want this to happen. The easiest + * thing to do is to run it through the vision system again, which + * is always correct. + */ + docrt(); /* this correctly will reset vision */ } /* monster is hit by scroll of taming's effect */ @@ -854,53 +861,55 @@ maybe_tame(mtmp, sobj) struct monst *mtmp; struct obj *sobj; { - int was_tame = mtmp->mtame; - unsigned was_peaceful = mtmp->mpeaceful; + int was_tame = mtmp->mtame; + unsigned was_peaceful = mtmp->mpeaceful; - if (sobj->cursed) { - setmangry(mtmp); - if (was_peaceful && !mtmp->mpeaceful) return -1; - } else { - if (mtmp->isshk) - make_happy_shk(mtmp, FALSE); - else if (!resist(mtmp, sobj->oclass, 0, NOTELL)) - (void) tamedog(mtmp, (struct obj *) 0); - if ((!was_peaceful && mtmp->mpeaceful) || - (!was_tame && mtmp->mtame)) return 1; - } - return 0; + if (sobj->cursed) { + setmangry(mtmp); + if (was_peaceful && !mtmp->mpeaceful) + return -1; + } else { + if (mtmp->isshk) + make_happy_shk(mtmp, FALSE); + else if (!resist(mtmp, sobj->oclass, 0, NOTELL)) + (void) tamedog(mtmp, (struct obj *) 0); + if ((!was_peaceful && mtmp->mpeaceful) || (!was_tame && mtmp->mtame)) + return 1; + } + return 0; } boolean -is_valid_stinking_cloud_pos(x,y, showmsg) -int x,y; +is_valid_stinking_cloud_pos(x, y, showmsg) +int x, y; boolean showmsg; { if (!cansee(x, y) || !ACCESSIBLE(levl[x][y].typ) || distu(x, y) >= 32) { - if (showmsg) You("smell rotten eggs."); - return FALSE; + if (showmsg) + You("smell rotten eggs."); + return FALSE; } return TRUE; } void display_stinking_cloud_positions(state) - int state; +int state; { if (state == 0) { - tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); + tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); } else if (state == 1) { - int x,y, dx, dy; - int dist = 6; - for (dx = -dist; dx <= dist; dx++) - for (dy = -dist; dy <= dist; dy++) { - x = u.ux + dx; - y = u.uy + dy; - if (isok(x,y) && is_valid_stinking_cloud_pos(x,y, FALSE)) - tmp_at(x,y); - } + int x, y, dx, dy; + int dist = 6; + for (dx = -dist; dx <= dist; dx++) + for (dy = -dist; dy <= dist; dy++) { + x = u.ux + dx; + y = u.uy + dy; + if (isok(x, y) && is_valid_stinking_cloud_pos(x, y, FALSE)) + tmp_at(x, y); + } } else { - tmp_at(DISP_END, 0); + tmp_at(DISP_END, 0); } } @@ -910,679 +919,685 @@ int seffects(sobj) struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */ { - int cval, otyp = sobj->otyp; - boolean confused = (Confusion != 0), - sblessed = sobj->blessed, scursed = sobj->cursed, - already_known, old_erodeproof, new_erodeproof; - struct obj *otmp; + int cval, otyp = sobj->otyp; + boolean confused = (Confusion != 0), sblessed = sobj->blessed, + scursed = sobj->cursed, already_known, old_erodeproof, + new_erodeproof; + struct obj *otmp; - if (objects[otyp].oc_magic) - exercise(A_WIS, TRUE); /* just for trying */ - already_known = (sobj->oclass == SPBOOK_CLASS || /* spell */ - objects[otyp].oc_name_known); + if (objects[otyp].oc_magic) + exercise(A_WIS, TRUE); /* just for trying */ + already_known = (sobj->oclass == SPBOOK_CLASS || /* spell */ + objects[otyp].oc_name_known); - switch (otyp) { + switch (otyp) { #ifdef MAIL - case SCR_MAIL: - known = TRUE; - if (sobj->spe) - pline( - "This seems to be junk mail addressed to the finder of the Eye of Larn."); - /* note to the puzzled: the game Larn actually sends you junk - * mail if you win! - */ - else readmail(sobj); - break; + case SCR_MAIL: + known = TRUE; + if (sobj->spe) + pline("This seems to be junk mail addressed to the finder of the " + "Eye of Larn."); + /* note to the puzzled: the game Larn actually sends you junk + * mail if you win! + */ + else + readmail(sobj); + break; #endif - case SCR_ENCHANT_ARMOR: - { - register schar s; - boolean special_armor; - boolean same_color; + case SCR_ENCHANT_ARMOR: { + register schar s; + boolean special_armor; + boolean same_color; - otmp = some_armor(&youmonst); - if(!otmp) { - strange_feeling(sobj, - !Blind ? "Your skin glows then fades." : - "Your skin feels warm for a moment."); - sobj = 0; /* useup() in strange_feeling() */ - exercise(A_CON, !scursed); - exercise(A_STR, !scursed); - break; - } - if(confused) { - old_erodeproof = (otmp->oerodeproof != 0); - new_erodeproof = !scursed; - otmp->oerodeproof = 0; /* for messages */ - if(Blind) { - otmp->rknown = FALSE; - pline("%s warm for a moment.", - Yobjnam2(otmp, "feel")); - } else { - otmp->rknown = TRUE; - pline("%s covered by a %s %s %s!", - Yobjnam2(otmp, "are"), - scursed ? "mottled" : "shimmering", - hcolor(scursed ? NH_BLACK : NH_GOLDEN), - scursed ? "glow" : - (is_shield(otmp) ? "layer" : "shield")); - } - if (new_erodeproof && - (otmp->oeroded || otmp->oeroded2)) { - otmp->oeroded = otmp->oeroded2 = 0; - pline("%s as good as new!", - Yobjnam2(otmp, Blind ? "feel" : "look")); - } - if (old_erodeproof && !new_erodeproof) { - /* restore old_erodeproof before shop charges */ - otmp->oerodeproof = 1; - costly_alteration(otmp, COST_DEGRD); - } - otmp->oerodeproof = new_erodeproof ? 1 : 0; - break; - } - /* elven armor vibrates warningly when enchanted beyond a limit */ - special_armor = is_elven_armor(otmp) || - (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM); - if (scursed) - same_color = - (otmp->otyp == BLACK_DRAGON_SCALE_MAIL || - otmp->otyp == BLACK_DRAGON_SCALES); - else - same_color = - (otmp->otyp == SILVER_DRAGON_SCALE_MAIL || - otmp->otyp == SILVER_DRAGON_SCALES || - otmp->otyp == SHIELD_OF_REFLECTION); - if (Blind) same_color = FALSE; + otmp = some_armor(&youmonst); + if (!otmp) { + strange_feeling(sobj, !Blind + ? "Your skin glows then fades." + : "Your skin feels warm for a moment."); + sobj = 0; /* useup() in strange_feeling() */ + exercise(A_CON, !scursed); + exercise(A_STR, !scursed); + break; + } + if (confused) { + old_erodeproof = (otmp->oerodeproof != 0); + new_erodeproof = !scursed; + otmp->oerodeproof = 0; /* for messages */ + if (Blind) { + otmp->rknown = FALSE; + pline("%s warm for a moment.", Yobjnam2(otmp, "feel")); + } else { + otmp->rknown = TRUE; + pline("%s covered by a %s %s %s!", Yobjnam2(otmp, "are"), + scursed ? "mottled" : "shimmering", + hcolor(scursed ? NH_BLACK : NH_GOLDEN), + scursed ? "glow" + : (is_shield(otmp) ? "layer" : "shield")); + } + if (new_erodeproof && (otmp->oeroded || otmp->oeroded2)) { + otmp->oeroded = otmp->oeroded2 = 0; + pline("%s as good as new!", + Yobjnam2(otmp, Blind ? "feel" : "look")); + } + if (old_erodeproof && !new_erodeproof) { + /* restore old_erodeproof before shop charges */ + otmp->oerodeproof = 1; + costly_alteration(otmp, COST_DEGRD); + } + otmp->oerodeproof = new_erodeproof ? 1 : 0; + break; + } + /* elven armor vibrates warningly when enchanted beyond a limit */ + special_armor = is_elven_armor(otmp) + || (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM); + if (scursed) + same_color = (otmp->otyp == BLACK_DRAGON_SCALE_MAIL + || otmp->otyp == BLACK_DRAGON_SCALES); + else + same_color = (otmp->otyp == SILVER_DRAGON_SCALE_MAIL + || otmp->otyp == SILVER_DRAGON_SCALES + || otmp->otyp == SHIELD_OF_REFLECTION); + if (Blind) + same_color = FALSE; - /* KMH -- catch underflow */ - s = scursed ? -otmp->spe : otmp->spe; - if (s > (special_armor ? 5 : 3) && rn2(s)) { - otmp->in_use = TRUE; - pline("%s violently %s%s%s for a while, then %s.", - Yname2(otmp), - otense(otmp, Blind ? "vibrate" : "glow"), - (!Blind && !same_color) ? " " : "", - (Blind || same_color) ? "" : - hcolor(scursed ? NH_BLACK : NH_SILVER), - otense(otmp, "evaporate")); - remove_worn_item(otmp, FALSE); - useup(otmp); - break; - } - s = scursed ? -1 : - otmp->spe >= 9 ? (rn2(otmp->spe) == 0) : - sblessed ? rnd(3 - otmp->spe / 3) : 1; - if (s >= 0 && Is_dragon_scales(otmp)) { - /* dragon scales get turned into dragon scale mail */ - pline("%s merges and hardens!", Yname2(otmp)); - setworn((struct obj *)0, W_ARM); - /* assumes same order */ - otmp->otyp += GRAY_DRAGON_SCALE_MAIL - - GRAY_DRAGON_SCALES; - if (sblessed) { - otmp->spe++; - if (!otmp->blessed) bless(otmp); - } else if (otmp->cursed) - uncurse(otmp); - otmp->known = 1; - setworn(otmp, W_ARM); - if (otmp->unpaid) alter_cost(otmp, 0L); /* shop bill */ - break; - } - pline("%s %s%s%s%s for a %s.", - Yname2(otmp), - s == 0 ? "violently " : "", - otense(otmp, Blind ? "vibrate" : "glow"), - (!Blind && !same_color) ? " " : "", - (Blind || same_color) ? "" : - hcolor(scursed ? NH_BLACK : NH_SILVER), - (s * s > 1) ? "while" : "moment"); - /* [this cost handling will need updating if shop pricing is - ever changed to care about curse/bless status of armor] */ - if (s < 0) costly_alteration(otmp, COST_DECHNT); - if (scursed && !otmp->cursed) curse(otmp); - else if (sblessed && !otmp->blessed) bless(otmp); - if (s) { - otmp->spe += s; - adj_abon(otmp, s); - known = otmp->known; - /* update shop bill to reflect new higher price */ - if (s > 0 && otmp->unpaid) alter_cost(otmp, 0L); - } + /* KMH -- catch underflow */ + s = scursed ? -otmp->spe : otmp->spe; + if (s > (special_armor ? 5 : 3) && rn2(s)) { + otmp->in_use = TRUE; + pline("%s violently %s%s%s for a while, then %s.", Yname2(otmp), + otense(otmp, Blind ? "vibrate" : "glow"), + (!Blind && !same_color) ? " " : "", + (Blind || same_color) ? "" : hcolor(scursed ? NH_BLACK + : NH_SILVER), + otense(otmp, "evaporate")); + remove_worn_item(otmp, FALSE); + useup(otmp); + break; + } + s = scursed ? -1 : otmp->spe >= 9 + ? (rn2(otmp->spe) == 0) + : sblessed ? rnd(3 - otmp->spe / 3) : 1; + if (s >= 0 && Is_dragon_scales(otmp)) { + /* dragon scales get turned into dragon scale mail */ + pline("%s merges and hardens!", Yname2(otmp)); + setworn((struct obj *) 0, W_ARM); + /* assumes same order */ + otmp->otyp += GRAY_DRAGON_SCALE_MAIL - GRAY_DRAGON_SCALES; + if (sblessed) { + otmp->spe++; + if (!otmp->blessed) + bless(otmp); + } else if (otmp->cursed) + uncurse(otmp); + otmp->known = 1; + setworn(otmp, W_ARM); + if (otmp->unpaid) + alter_cost(otmp, 0L); /* shop bill */ + break; + } + pline("%s %s%s%s%s for a %s.", Yname2(otmp), + s == 0 ? "violently " : "", + otense(otmp, Blind ? "vibrate" : "glow"), + (!Blind && !same_color) ? " " : "", + (Blind || same_color) ? "" + : hcolor(scursed ? NH_BLACK : NH_SILVER), + (s * s > 1) ? "while" : "moment"); + /* [this cost handling will need updating if shop pricing is + ever changed to care about curse/bless status of armor] */ + if (s < 0) + costly_alteration(otmp, COST_DECHNT); + if (scursed && !otmp->cursed) + curse(otmp); + else if (sblessed && !otmp->blessed) + bless(otmp); + if (s) { + otmp->spe += s; + adj_abon(otmp, s); + known = otmp->known; + /* update shop bill to reflect new higher price */ + if (s > 0 && otmp->unpaid) + alter_cost(otmp, 0L); + } - if ((otmp->spe > (special_armor ? 5 : 3)) && - (special_armor || !rn2(7))) - pline("%s %s.", - Yobjnam2(otmp, "suddenly vibrate"), - Blind ? "again" : "unexpectedly"); - break; - } - case SCR_DESTROY_ARMOR: - { - otmp = some_armor(&youmonst); - if (confused) { - if (!otmp) { - strange_feeling(sobj,"Your bones itch."); - sobj = 0; /* useup() in strange_feeling() */ - exercise(A_STR, FALSE); - exercise(A_CON, FALSE); - break; - } - old_erodeproof = (otmp->oerodeproof != 0); - new_erodeproof = scursed; - otmp->oerodeproof = 0; /* for messages */ - p_glow2(otmp, NH_PURPLE); - if (old_erodeproof && !new_erodeproof) { - /* restore old_erodeproof before shop charges */ - otmp->oerodeproof = 1; - costly_alteration(otmp, COST_DEGRD); - } - otmp->oerodeproof = new_erodeproof ? 1 : 0; - break; - } - if (!scursed || !otmp || !otmp->cursed) { - if (!destroy_arm(otmp)) { - strange_feeling(sobj,"Your skin itches."); - sobj = 0; /* useup() in strange_feeling() */ - exercise(A_STR, FALSE); - exercise(A_CON, FALSE); - break; - } else - known = TRUE; - } else { /* armor and scroll both cursed */ - pline("%s.", Yobjnam2(otmp, "vibrate")); - if (otmp->spe >= -6) { - otmp->spe += -1; - adj_abon(otmp, -1); - } - make_stunned((HStun & TIMEOUT) + (long)rn1(10, 10), TRUE); - } - } - break; - case SCR_CONFUSE_MONSTER: - case SPE_CONFUSE_MONSTER: - if (youmonst.data->mlet != S_HUMAN || scursed) { - if (!HConfusion) You_feel("confused."); - make_confused(HConfusion + rnd(100),FALSE); - } else if (confused) { - if (!sblessed) { - Your("%s begin to %s%s.", - makeplural(body_part(HAND)), - Blind ? "tingle" : "glow ", - Blind ? "" : hcolor(NH_PURPLE)); - make_confused(HConfusion + rnd(100),FALSE); - } else { - pline("A %s%s surrounds your %s.", - Blind ? "" : hcolor(NH_RED), - Blind ? "faint buzz" : " glow", - body_part(HEAD)); - make_confused(0L,TRUE); - } - } else { - if (!sblessed) { - Your("%s%s %s%s.", - makeplural(body_part(HAND)), - Blind ? "" : " begin to glow", - Blind ? (const char *)"tingle" : hcolor(NH_RED), - u.umconf ? " even more" : ""); - u.umconf++; - } else { - if (Blind) - Your("%s tingle %s sharply.", - makeplural(body_part(HAND)), - u.umconf ? "even more" : "very"); - else - Your("%s glow a%s brilliant %s.", - makeplural(body_part(HAND)), - u.umconf ? "n even more" : "", - hcolor(NH_RED)); - /* after a while, repeated uses become less effective */ - if (u.umconf >= 40) - u.umconf++; - else - u.umconf += rn1(8, 2); - } - } - break; - case SCR_SCARE_MONSTER: - case SPE_CAUSE_FEAR: - { - register int ct = 0; - register struct monst *mtmp; + if ((otmp->spe > (special_armor ? 5 : 3)) + && (special_armor || !rn2(7))) + pline("%s %s.", Yobjnam2(otmp, "suddenly vibrate"), + Blind ? "again" : "unexpectedly"); + break; + } + case SCR_DESTROY_ARMOR: { + otmp = some_armor(&youmonst); + if (confused) { + if (!otmp) { + strange_feeling(sobj, "Your bones itch."); + sobj = 0; /* useup() in strange_feeling() */ + exercise(A_STR, FALSE); + exercise(A_CON, FALSE); + break; + } + old_erodeproof = (otmp->oerodeproof != 0); + new_erodeproof = scursed; + otmp->oerodeproof = 0; /* for messages */ + p_glow2(otmp, NH_PURPLE); + if (old_erodeproof && !new_erodeproof) { + /* restore old_erodeproof before shop charges */ + otmp->oerodeproof = 1; + costly_alteration(otmp, COST_DEGRD); + } + otmp->oerodeproof = new_erodeproof ? 1 : 0; + break; + } + if (!scursed || !otmp || !otmp->cursed) { + if (!destroy_arm(otmp)) { + strange_feeling(sobj, "Your skin itches."); + sobj = 0; /* useup() in strange_feeling() */ + exercise(A_STR, FALSE); + exercise(A_CON, FALSE); + break; + } else + known = TRUE; + } else { /* armor and scroll both cursed */ + pline("%s.", Yobjnam2(otmp, "vibrate")); + if (otmp->spe >= -6) { + otmp->spe += -1; + adj_abon(otmp, -1); + } + make_stunned((HStun & TIMEOUT) + (long) rn1(10, 10), TRUE); + } + } break; + case SCR_CONFUSE_MONSTER: + case SPE_CONFUSE_MONSTER: + if (youmonst.data->mlet != S_HUMAN || scursed) { + if (!HConfusion) + You_feel("confused."); + make_confused(HConfusion + rnd(100), FALSE); + } else if (confused) { + if (!sblessed) { + Your("%s begin to %s%s.", makeplural(body_part(HAND)), + Blind ? "tingle" : "glow ", + Blind ? "" : hcolor(NH_PURPLE)); + make_confused(HConfusion + rnd(100), FALSE); + } else { + pline("A %s%s surrounds your %s.", + Blind ? "" : hcolor(NH_RED), + Blind ? "faint buzz" : " glow", body_part(HEAD)); + make_confused(0L, TRUE); + } + } else { + if (!sblessed) { + Your("%s%s %s%s.", makeplural(body_part(HAND)), + Blind ? "" : " begin to glow", + Blind ? (const char *) "tingle" : hcolor(NH_RED), + u.umconf ? " even more" : ""); + u.umconf++; + } else { + if (Blind) + Your("%s tingle %s sharply.", makeplural(body_part(HAND)), + u.umconf ? "even more" : "very"); + else + Your("%s glow a%s brilliant %s.", + makeplural(body_part(HAND)), + u.umconf ? "n even more" : "", hcolor(NH_RED)); + /* after a while, repeated uses become less effective */ + if (u.umconf >= 40) + u.umconf++; + else + u.umconf += rn1(8, 2); + } + } + break; + case SCR_SCARE_MONSTER: + case SPE_CAUSE_FEAR: { + register int ct = 0; + register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if(cansee(mtmp->mx,mtmp->my)) { - if (confused || scursed) { - mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0; - mtmp->mcanmove = 1; - } else - if (! resist(mtmp, sobj->oclass, 0, NOTELL)) - monflee(mtmp, 0, FALSE, FALSE); - if(!mtmp->mtame) ct++; /* pets don't laugh at you */ - } - } - if (otyp == SCR_SCARE_MONSTER || !ct) - You_hear("%s %s.", - (confused || scursed) ? "sad wailing" : - "maniacal laughter", - !ct ? "in the distance" : "close by"); - break; - } - case SCR_BLANK_PAPER: - if (Blind) - You("don't remember there being any magic words on this scroll."); - else - pline("This scroll seems to be blank."); - known = TRUE; - break; - case SCR_REMOVE_CURSE: - case SPE_REMOVE_CURSE: - { - register struct obj *obj; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (cansee(mtmp->mx, mtmp->my)) { + if (confused || scursed) { + mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0; + mtmp->mcanmove = 1; + } else if (!resist(mtmp, sobj->oclass, 0, NOTELL)) + monflee(mtmp, 0, FALSE, FALSE); + if (!mtmp->mtame) + ct++; /* pets don't laugh at you */ + } + } + if (otyp == SCR_SCARE_MONSTER || !ct) + You_hear("%s %s.", (confused || scursed) ? "sad wailing" + : "maniacal laughter", + !ct ? "in the distance" : "close by"); + break; + } + case SCR_BLANK_PAPER: + if (Blind) + You("don't remember there being any magic words on this scroll."); + else + pline("This scroll seems to be blank."); + known = TRUE; + break; + case SCR_REMOVE_CURSE: + case SPE_REMOVE_CURSE: { + register struct obj *obj; - You_feel(!Hallucination ? - (!confused ? - "like someone is helping you." : - "like you need some help.") : - (!confused ? - "in touch with the Universal Oneness." : - "the power of the Force against you!")); + You_feel(!Hallucination + ? (!confused ? "like someone is helping you." + : "like you need some help.") + : (!confused ? "in touch with the Universal Oneness." + : "the power of the Force against you!")); - if (scursed) { - pline_The("scroll disintegrates."); - } else { - for (obj = invent; obj; obj = obj->nobj) { - long wornmask; - /* gold isn't subject to cursing and blessing */ - if (obj->oclass == COIN_CLASS) continue; - wornmask = (obj->owornmask & ~(W_BALL|W_ART|W_ARTI)); - if (wornmask && !sblessed) { - /* handle a couple of special cases; we don't - allow auxiliary weapon slots to be used to - artificially increase number of worn items */ - if (obj == uswapwep) { - if (!u.twoweap) wornmask = 0L; - } else if (obj == uquiver) { - if (obj->oclass == WEAPON_CLASS) { - /* mergeable weapon test covers ammo, - missiles, spears, daggers & knives */ - if (!objects[obj->otyp].oc_merge) - wornmask = 0L; - } else if (obj->oclass == GEM_CLASS) { - /* possibly ought to check whether - alternate weapon is a sling... */ - if (!uslinging()) wornmask = 0L; - } else { - /* weptools don't merge and aren't - reasonable quivered weapons */ - wornmask = 0L; - } - } - } - if (sblessed || wornmask || - obj->otyp == LOADSTONE || - (obj->otyp == LEASH && obj->leashmon)) { - /* water price varies by curse/bless status */ - boolean shop_h2o = (obj->unpaid && - obj->otyp == POT_WATER); + if (scursed) { + pline_The("scroll disintegrates."); + } else { + for (obj = invent; obj; obj = obj->nobj) { + long wornmask; + /* gold isn't subject to cursing and blessing */ + if (obj->oclass == COIN_CLASS) + continue; + wornmask = (obj->owornmask & ~(W_BALL | W_ART | W_ARTI)); + if (wornmask && !sblessed) { + /* handle a couple of special cases; we don't + allow auxiliary weapon slots to be used to + artificially increase number of worn items */ + if (obj == uswapwep) { + if (!u.twoweap) + wornmask = 0L; + } else if (obj == uquiver) { + if (obj->oclass == WEAPON_CLASS) { + /* mergeable weapon test covers ammo, + missiles, spears, daggers & knives */ + if (!objects[obj->otyp].oc_merge) + wornmask = 0L; + } else if (obj->oclass == GEM_CLASS) { + /* possibly ought to check whether + alternate weapon is a sling... */ + if (!uslinging()) + wornmask = 0L; + } else { + /* weptools don't merge and aren't + reasonable quivered weapons */ + wornmask = 0L; + } + } + } + if (sblessed || wornmask || obj->otyp == LOADSTONE + || (obj->otyp == LEASH && obj->leashmon)) { + /* water price varies by curse/bless status */ + boolean shop_h2o = + (obj->unpaid && obj->otyp == POT_WATER); - if (confused) { - blessorcurse(obj, 2); - /* lose knowledge of this object's curse/bless - state (even if it didn't actually change) */ - obj->bknown = 0; - /* blessorcurse() only affects uncursed items - so no need to worry about price of water - going down (hence no costly_alteration) */ - if (shop_h2o && (obj->cursed || obj->blessed)) - alter_cost(obj, 0L); /* price goes up */ - } else if (obj->cursed) { - if (shop_h2o) - costly_alteration(obj, COST_UNCURS); - uncurse(obj); - } - } - } - } - if(Punished && !confused) unpunish(); - if(u.utrap && u.utraptype == TT_BURIEDBALL) { - buried_ball_to_freedom(); - pline_The("clasp on your %s vanishes.", - body_part(LEG)); - } - update_inventory(); - break; - } - case SCR_CREATE_MONSTER: - case SPE_CREATE_MONSTER: - if (create_critters(1 + ((confused || scursed) ? 12 : 0) + - ((sblessed || rn2(73)) ? 0 : rnd(4)), - confused ? &mons[PM_ACID_BLOB] : (struct permonst *)0,FALSE)) - known = TRUE; - /* no need to flush monsters; we ask for identification only if the - * monsters are not visible - */ - break; - case SCR_ENCHANT_WEAPON: - if (confused && uwep && - (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))) { - old_erodeproof = (uwep->oerodeproof != 0); - new_erodeproof = !scursed; - uwep->oerodeproof = 0; /* for messages */ - if (Blind) { - uwep->rknown = FALSE; - Your("weapon feels warm for a moment."); - } else { - uwep->rknown = TRUE; - pline("%s covered by a %s %s %s!", - Yobjnam2(uwep, "are"), - scursed ? "mottled" : "shimmering", - hcolor(scursed ? NH_PURPLE : NH_GOLDEN), - scursed ? "glow" : "shield"); - } - if (uwep->oerodeproof && (uwep->oeroded || uwep->oeroded2)) { - uwep->oeroded = uwep->oeroded2 = 0; - pline("%s as good as new!", - Yobjnam2(uwep, Blind ? "feel" : "look")); - } - if (old_erodeproof && !new_erodeproof) { - /* restore old_erodeproof before shop charges */ - uwep->oerodeproof = 1; - costly_alteration(uwep, COST_DEGRD); - } - uwep->oerodeproof = new_erodeproof ? 1 : 0; - break; - } - if (!chwepon(sobj, - scursed ? -1 : !uwep ? 1 : - (uwep->spe >= 9) ? !rn2(uwep->spe) : - sblessed ? rnd(3 - uwep->spe / 3) : 1)) - sobj = 0; /* nothing enchanted: strange_feeling -> useup */ - break; - case SCR_TAMING: - case SPE_CHARM_MONSTER: - { - int candidates, res, results, vis_results; + if (confused) { + blessorcurse(obj, 2); + /* lose knowledge of this object's curse/bless + state (even if it didn't actually change) */ + obj->bknown = 0; + /* blessorcurse() only affects uncursed items + so no need to worry about price of water + going down (hence no costly_alteration) */ + if (shop_h2o && (obj->cursed || obj->blessed)) + alter_cost(obj, 0L); /* price goes up */ + } else if (obj->cursed) { + if (shop_h2o) + costly_alteration(obj, COST_UNCURS); + uncurse(obj); + } + } + } + } + if (Punished && !confused) + unpunish(); + if (u.utrap && u.utraptype == TT_BURIEDBALL) { + buried_ball_to_freedom(); + pline_The("clasp on your %s vanishes.", body_part(LEG)); + } + update_inventory(); + break; + } + case SCR_CREATE_MONSTER: + case SPE_CREATE_MONSTER: + if (create_critters(1 + ((confused || scursed) ? 12 : 0) + + ((sblessed || rn2(73)) ? 0 : rnd(4)), + confused ? &mons[PM_ACID_BLOB] + : (struct permonst *) 0, + FALSE)) + known = TRUE; + /* no need to flush monsters; we ask for identification only if the + * monsters are not visible + */ + break; + case SCR_ENCHANT_WEAPON: + if (confused && uwep + && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))) { + old_erodeproof = (uwep->oerodeproof != 0); + new_erodeproof = !scursed; + uwep->oerodeproof = 0; /* for messages */ + if (Blind) { + uwep->rknown = FALSE; + Your("weapon feels warm for a moment."); + } else { + uwep->rknown = TRUE; + pline("%s covered by a %s %s %s!", Yobjnam2(uwep, "are"), + scursed ? "mottled" : "shimmering", + hcolor(scursed ? NH_PURPLE : NH_GOLDEN), + scursed ? "glow" : "shield"); + } + if (uwep->oerodeproof && (uwep->oeroded || uwep->oeroded2)) { + uwep->oeroded = uwep->oeroded2 = 0; + pline("%s as good as new!", + Yobjnam2(uwep, Blind ? "feel" : "look")); + } + if (old_erodeproof && !new_erodeproof) { + /* restore old_erodeproof before shop charges */ + uwep->oerodeproof = 1; + costly_alteration(uwep, COST_DEGRD); + } + uwep->oerodeproof = new_erodeproof ? 1 : 0; + break; + } + if (!chwepon(sobj, + scursed + ? -1 + : !uwep ? 1 : (uwep->spe >= 9) + ? !rn2(uwep->spe) + : sblessed ? rnd(3 - uwep->spe / 3) + : 1)) + sobj = 0; /* nothing enchanted: strange_feeling -> useup */ + break; + case SCR_TAMING: + case SPE_CHARM_MONSTER: { + int candidates, res, results, vis_results; - if (u.uswallow) { - candidates = 1; - results = vis_results = maybe_tame(u.ustuck, sobj); - } else { - int i, j, bd = confused ? 5 : 1; - struct monst *mtmp; + if (u.uswallow) { + candidates = 1; + results = vis_results = maybe_tame(u.ustuck, sobj); + } else { + int i, j, bd = confused ? 5 : 1; + struct monst *mtmp; - /* note: maybe_tame() can return either positive or - negative values, but not both for the same scroll */ - candidates = results = vis_results = 0; - for (i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++) { - if (!isok(u.ux + i, u.uy + j)) continue; - if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0 - || (!i && !j && (mtmp = u.usteed) != 0)) { - ++candidates; - res = maybe_tame(mtmp, sobj); - results += res; - if (canspotmon(mtmp)) vis_results += res; - } - } - } - if (!results) { - pline("Nothing interesting %s.", - !candidates ? "happens" : "seems to happen"); - } else { - pline_The("neighborhood %s %sfriendlier.", - vis_results ? "is" : "seems", - (results < 0) ? "un" : ""); - if (vis_results > 0) known = TRUE; - } - } - break; - case SCR_GENOCIDE: - if (!already_known) - You("have found a scroll of genocide!"); - known = TRUE; - if (sblessed) do_class_genocide(); - else do_genocide(!scursed | (2 * !!Confusion)); - break; - case SCR_LIGHT: - if (!confused || rn2(5)) { - if(!Blind) known = TRUE; - litroom(!confused && !scursed, sobj); - if (!confused && !scursed) { - if (lightdamage(sobj, TRUE, 5)) known = TRUE; - } - } else { - /* could be scroll of create monster, don't set known ...*/ - (void) create_critters(1, !scursed ? - &mons[PM_YELLOW_LIGHT] : - &mons[PM_BLACK_LIGHT], TRUE); - if(!objects[sobj->otyp].oc_uname) - docall(sobj); - } - break; - case SCR_TELEPORTATION: - if (confused || scursed) { - level_tele(); - } else { - known = scrolltele(sobj); - } - break; - case SCR_GOLD_DETECTION: - if ((confused || scursed) ? trap_detect(sobj) : - gold_detect(sobj)) - sobj = 0; /* failure: strange_feeling() -> useup() */ - break; - case SCR_FOOD_DETECTION: - case SPE_DETECT_FOOD: - if (food_detect(sobj)) - sobj = 0; /* nothing detected: strange_feeling -> useup */ - break; - case SCR_IDENTIFY: - /* known = TRUE; -- handled inline here */ - /* use up the scroll first, before makeknown() performs a - perm_invent update; also simplifies empty invent check */ - useup(sobj); - sobj = 0; /* it's gone */ - if (confused) - You("identify this as an identify scroll."); - else if (!already_known || !invent) - /* force feedback now if invent became - empty after using up this scroll */ - pline("This is an identify scroll."); - if (!already_known) - (void) learnscrolltyp(SCR_IDENTIFY); - /*FALLTHRU*/ - case SPE_IDENTIFY: - cval = 1; - if (sblessed || (!scursed && !rn2(5))) { - cval = rn2(5); - /* note: if cval==0, identify all items */ - if (cval == 1 && sblessed && Luck > 0) ++cval; - } - if (invent && !confused) { - identify_pack(cval, !already_known); - } else if (otyp == SPE_IDENTIFY) { - /* when casting a spell we know we're not confused, - so inventory must be empty (another message has - already been given above if reading a scroll) */ - pline("You're not carrying anything to be identified."); - } - break; - case SCR_CHARGING: - if (confused) { - if (scursed) { - You_feel("discharged."); - u.uen = 0; - } else { - You_feel("charged up!"); - if (u.uen < u.uenmax) - u.uen = u.uenmax; - else - u.uen = (u.uenmax += d(5,4)); - } - context.botl = 1; - break; - } - /* known = TRUE; -- handled inline here */ - if (!already_known) { - pline("This is a charging scroll."); - learnscroll(sobj); - } - /* use it up now to prevent it from showing in the - getobj picklist because the "disappears" message - was already delivered */ - useup(sobj); - sobj = 0; /* it's gone */ - otmp = getobj(all_count, "charge"); - if (otmp) recharge(otmp, scursed ? -1 : sblessed ? 1 : 0); - break; - case SCR_MAGIC_MAPPING: - if (level.flags.nommap) { - Your("mind is filled with crazy lines!"); - if (Hallucination) - pline("Wow! Modern art."); - else - Your("%s spins in bewilderment.", body_part(HEAD)); - make_confused(HConfusion + rnd(30), FALSE); - break; - } - if (sblessed) { - register int x, y; + /* note: maybe_tame() can return either positive or + negative values, but not both for the same scroll */ + candidates = results = vis_results = 0; + for (i = -bd; i <= bd; i++) + for (j = -bd; j <= bd; j++) { + if (!isok(u.ux + i, u.uy + j)) + continue; + if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0 + || (!i && !j && (mtmp = u.usteed) != 0)) { + ++candidates; + res = maybe_tame(mtmp, sobj); + results += res; + if (canspotmon(mtmp)) + vis_results += res; + } + } + } + if (!results) { + pline("Nothing interesting %s.", + !candidates ? "happens" : "seems to happen"); + } else { + pline_The("neighborhood %s %sfriendlier.", + vis_results ? "is" : "seems", + (results < 0) ? "un" : ""); + if (vis_results > 0) + known = TRUE; + } + } break; + case SCR_GENOCIDE: + if (!already_known) + You("have found a scroll of genocide!"); + known = TRUE; + if (sblessed) + do_class_genocide(); + else + do_genocide(!scursed | (2 * !!Confusion)); + break; + case SCR_LIGHT: + if (!confused || rn2(5)) { + if (!Blind) + known = TRUE; + litroom(!confused && !scursed, sobj); + if (!confused && !scursed) { + if (lightdamage(sobj, TRUE, 5)) + known = TRUE; + } + } else { + /* could be scroll of create monster, don't set known ...*/ + (void) create_critters(1, !scursed ? &mons[PM_YELLOW_LIGHT] + : &mons[PM_BLACK_LIGHT], + TRUE); + if (!objects[sobj->otyp].oc_uname) + docall(sobj); + } + break; + case SCR_TELEPORTATION: + if (confused || scursed) { + level_tele(); + } else { + known = scrolltele(sobj); + } + break; + case SCR_GOLD_DETECTION: + if ((confused || scursed) ? trap_detect(sobj) : gold_detect(sobj)) + sobj = 0; /* failure: strange_feeling() -> useup() */ + break; + case SCR_FOOD_DETECTION: + case SPE_DETECT_FOOD: + if (food_detect(sobj)) + sobj = 0; /* nothing detected: strange_feeling -> useup */ + break; + case SCR_IDENTIFY: + /* known = TRUE; -- handled inline here */ + /* use up the scroll first, before makeknown() performs a + perm_invent update; also simplifies empty invent check */ + useup(sobj); + sobj = 0; /* it's gone */ + if (confused) + You("identify this as an identify scroll."); + else if (!already_known || !invent) + /* force feedback now if invent became + empty after using up this scroll */ + pline("This is an identify scroll."); + if (!already_known) + (void) learnscrolltyp(SCR_IDENTIFY); + /*FALLTHRU*/ + case SPE_IDENTIFY: + cval = 1; + if (sblessed || (!scursed && !rn2(5))) { + cval = rn2(5); + /* note: if cval==0, identify all items */ + if (cval == 1 && sblessed && Luck > 0) + ++cval; + } + if (invent && !confused) { + identify_pack(cval, !already_known); + } else if (otyp == SPE_IDENTIFY) { + /* when casting a spell we know we're not confused, + so inventory must be empty (another message has + already been given above if reading a scroll) */ + pline("You're not carrying anything to be identified."); + } + break; + case SCR_CHARGING: + if (confused) { + if (scursed) { + You_feel("discharged."); + u.uen = 0; + } else { + You_feel("charged up!"); + if (u.uen < u.uenmax) + u.uen = u.uenmax; + else + u.uen = (u.uenmax += d(5, 4)); + } + context.botl = 1; + break; + } + /* known = TRUE; -- handled inline here */ + if (!already_known) { + pline("This is a charging scroll."); + learnscroll(sobj); + } + /* use it up now to prevent it from showing in the + getobj picklist because the "disappears" message + was already delivered */ + useup(sobj); + sobj = 0; /* it's gone */ + otmp = getobj(all_count, "charge"); + if (otmp) + recharge(otmp, scursed ? -1 : sblessed ? 1 : 0); + break; + case SCR_MAGIC_MAPPING: + if (level.flags.nommap) { + Your("mind is filled with crazy lines!"); + if (Hallucination) + pline("Wow! Modern art."); + else + Your("%s spins in bewilderment.", body_part(HEAD)); + make_confused(HConfusion + rnd(30), FALSE); + break; + } + if (sblessed) { + register int x, y; - for (x = 1; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (levl[x][y].typ == SDOOR) - cvt_sdoor_to_door(&levl[x][y]); - /* do_mapping() already reveals secret passages */ - } - known = TRUE; - case SPE_MAGIC_MAPPING: - if (level.flags.nommap) { - Your("%s spins as %s blocks the spell!", body_part(HEAD), something); - make_confused(HConfusion + rnd(30), FALSE); - break; - } - pline("A map coalesces in your mind!"); - cval = (scursed && !confused); - if(cval) HConfusion = 1; /* to screw up map */ - do_mapping(); - if(cval) { - HConfusion = 0; /* restore */ - pline("Unfortunately, you can't grasp the details."); - } - break; - case SCR_AMNESIA: - known = TRUE; - forget((!sblessed ? ALL_SPELLS : 0) | - (!confused || scursed ? ALL_MAP : 0)); - if (Hallucination) /* Ommmmmm! */ - Your("mind releases itself from mundane concerns."); - else if (!strncmpi(plname, "Maud", 4)) - pline("As your mind turns inward on itself, you forget everything else."); - else if (rn2(2)) - pline("Who was that Maud person anyway?"); - else - pline("Thinking of Maud you forget everything else."); - exercise(A_WIS, FALSE); - break; - case SCR_FIRE: - cval = bcsign(sobj); - useup(sobj); - sobj = 0; /* it's gone */ - if (!already_known) - (void) learnscrolltyp(SCR_FIRE); - if(confused) { - if(Fire_resistance) { - shieldeff(u.ux, u.uy); - if(!Blind) - pline("Oh, look, what a pretty fire in your %s.", - makeplural(body_part(HAND))); - else You_feel("a pleasant warmth in your %s.", - makeplural(body_part(HAND))); - } else { - pline_The("scroll catches fire and you burn your %s.", - makeplural(body_part(HAND))); - losehp(1, "scroll of fire", KILLED_BY_AN); - } - break; - } - if (Underwater) { - pline_The("water around you vaporizes violently!"); - } else { - pline_The("scroll erupts in a tower of flame!"); - iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */ - burn_away_slime(); - } - explode(u.ux, u.uy, 11, (2*(rn1(3, 3) + 2 * cval) + 1)/3, - SCROLL_CLASS, EXPL_FIERY); - break; - case SCR_EARTH: - /* TODO: handle steeds */ - if (!Is_rogue_level(&u.uz) + for (x = 1; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + if (levl[x][y].typ == SDOOR) + cvt_sdoor_to_door(&levl[x][y]); + /* do_mapping() already reveals secret passages */ + } + known = TRUE; + case SPE_MAGIC_MAPPING: + if (level.flags.nommap) { + Your("%s spins as %s blocks the spell!", body_part(HEAD), + something); + make_confused(HConfusion + rnd(30), FALSE); + break; + } + pline("A map coalesces in your mind!"); + cval = (scursed && !confused); + if (cval) + HConfusion = 1; /* to screw up map */ + do_mapping(); + if (cval) { + HConfusion = 0; /* restore */ + pline("Unfortunately, you can't grasp the details."); + } + break; + case SCR_AMNESIA: + known = TRUE; + forget((!sblessed ? ALL_SPELLS : 0) + | (!confused || scursed ? ALL_MAP : 0)); + if (Hallucination) /* Ommmmmm! */ + Your("mind releases itself from mundane concerns."); + else if (!strncmpi(plname, "Maud", 4)) + pline("As your mind turns inward on itself, you forget " + "everything else."); + else if (rn2(2)) + pline("Who was that Maud person anyway?"); + else + pline("Thinking of Maud you forget everything else."); + exercise(A_WIS, FALSE); + break; + case SCR_FIRE: + cval = bcsign(sobj); + useup(sobj); + sobj = 0; /* it's gone */ + if (!already_known) + (void) learnscrolltyp(SCR_FIRE); + if (confused) { + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + if (!Blind) + pline("Oh, look, what a pretty fire in your %s.", + makeplural(body_part(HAND))); + else + You_feel("a pleasant warmth in your %s.", + makeplural(body_part(HAND))); + } else { + pline_The("scroll catches fire and you burn your %s.", + makeplural(body_part(HAND))); + losehp(1, "scroll of fire", KILLED_BY_AN); + } + break; + } + if (Underwater) { + pline_The("water around you vaporizes violently!"); + } else { + pline_The("scroll erupts in a tower of flame!"); + iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */ + burn_away_slime(); + } + explode(u.ux, u.uy, 11, (2 * (rn1(3, 3) + 2 * cval) + 1) / 3, + SCROLL_CLASS, EXPL_FIERY); + break; + case SCR_EARTH: + /* TODO: handle steeds */ + if (!Is_rogue_level(&u.uz) && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { - register int x, y; - int nboulders = 0; + register int x, y; + int nboulders = 0; - /* Identify the scroll */ - pline_The("%s rumbles %s you!", ceiling(u.ux,u.uy), - sblessed ? "around" : "above"); - known = 1; - sokoban_guilt(); + /* Identify the scroll */ + pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy), + sblessed ? "around" : "above"); + known = 1; + sokoban_guilt(); - /* Loop through the surrounding squares */ - if (!scursed) for (x = u.ux-1; x <= u.ux+1; x++) { - for (y = u.uy-1; y <= u.uy+1; y++) { + /* Loop through the surrounding squares */ + if (!scursed) + for (x = u.ux - 1; x <= u.ux + 1; x++) { + for (y = u.uy - 1; y <= u.uy + 1; y++) { + /* Is this a suitable spot? */ + if (isok(x, y) && !closed_door(x, y) + && !IS_ROCK(levl[x][y].typ) + && !IS_AIR(levl[x][y].typ) + && (x != u.ux || y != u.uy)) { + nboulders += + drop_boulder_on_monster(x, y, confused, TRUE); + } + } + } + /* Attack the player */ + if (!sblessed) { + drop_boulder_on_player(confused, !scursed, TRUE, FALSE); + } else if (!nboulders) + pline("But nothing else happens."); + } + break; + case SCR_PUNISHMENT: + known = TRUE; + if (confused || sblessed) { + You_feel("guilty."); + break; + } + punish(sobj); + break; + case SCR_STINKING_CLOUD: { + coord cc; - /* Is this a suitable spot? */ - if (isok(x, y) && !closed_door(x, y) && - !IS_ROCK(levl[x][y].typ) && - !IS_AIR(levl[x][y].typ) && - (x != u.ux || y != u.uy)) { - nboulders += drop_boulder_on_monster(x, y, confused, TRUE); - } - } - } - /* Attack the player */ - if (!sblessed) { - drop_boulder_on_player(confused, !scursed, TRUE, FALSE); - } else if (!nboulders) pline("But nothing else happens."); - } - break; - case SCR_PUNISHMENT: - known = TRUE; - if (confused || sblessed) { - You_feel("guilty."); - break; - } - punish(sobj); - break; - case SCR_STINKING_CLOUD: - { - coord cc; - - if (!already_known) - You("have found a scroll of stinking cloud!"); - known = TRUE; - pline("Where do you want to center the %scloud?", - already_known ? "stinking " : ""); - cc.x = u.ux; - cc.y = u.uy; - getpos_sethilite(display_stinking_cloud_positions); - if (getpos(&cc, TRUE, "the desired position") < 0) { - pline1(Never_mind); - break; - } - if (!is_valid_stinking_cloud_pos(cc.x, cc.y, TRUE)) - break; - (void) create_gas_cloud(cc.x, cc.y, 3+bcsign(sobj), - 8+4*bcsign(sobj)); - break; - } - default: - impossible("What weird effect is this? (%u)", otyp); - } - return sobj ? 0 : 1; + if (!already_known) + You("have found a scroll of stinking cloud!"); + known = TRUE; + pline("Where do you want to center the %scloud?", + already_known ? "stinking " : ""); + cc.x = u.ux; + cc.y = u.uy; + getpos_sethilite(display_stinking_cloud_positions); + if (getpos(&cc, TRUE, "the desired position") < 0) { + pline1(Never_mind); + break; + } + if (!is_valid_stinking_cloud_pos(cc.x, cc.y, TRUE)) + break; + (void) create_gas_cloud(cc.x, cc.y, 3 + bcsign(sobj), + 8 + 4 * bcsign(sobj)); + break; + } + default: + impossible("What weird effect is this? (%u)", otyp); + } + return sobj ? 0 : 1; } void @@ -1597,42 +1612,43 @@ boolean skip_uswallow; /* hit monster if swallowed */ if (u.uswallow && !skip_uswallow) { - drop_boulder_on_monster(u.ux, u.uy, confused, byu); - return; + drop_boulder_on_monster(u.ux, u.uy, confused, byu); + return; } otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE); - if (!otmp2) return; - otmp2->quan = confused ? rn1(5,2) : 1; + if (!otmp2) + return; + otmp2->quan = confused ? rn1(5, 2) : 1; otmp2->owt = weight(otmp2); - if (!amorphous(youmonst.data) && !Passes_walls && - !noncorporeal(youmonst.data) && !unsolid(youmonst.data)) { - You("are hit by %s!", doname(otmp2)); - dmg = dmgval(otmp2, &youmonst) * otmp2->quan; - if (uarmh && helmet_protects) { - if(is_metallic(uarmh)) { - pline("Fortunately, you are wearing a hard helmet."); - if (dmg > 2) dmg = 2; - } else if (flags.verbose) { - pline("%s does not protect you.", - Yname2(uarmh)); - } - } + if (!amorphous(youmonst.data) && !Passes_walls + && !noncorporeal(youmonst.data) && !unsolid(youmonst.data)) { + You("are hit by %s!", doname(otmp2)); + dmg = dmgval(otmp2, &youmonst) * otmp2->quan; + if (uarmh && helmet_protects) { + if (is_metallic(uarmh)) { + pline("Fortunately, you are wearing a hard helmet."); + if (dmg > 2) + dmg = 2; + } else if (flags.verbose) { + pline("%s does not protect you.", Yname2(uarmh)); + } + } } else - dmg = 0; + dmg = 0; /* Must be before the losehp(), for bones files */ if (!flooreffects(otmp2, u.ux, u.uy, "fall")) { - place_object(otmp2, u.ux, u.uy); - stackobj(otmp2); - newsym(u.ux, u.uy); + place_object(otmp2, u.ux, u.uy); + stackobj(otmp2); + newsym(u.ux, u.uy); } - if (dmg) losehp(Maybe_Half_Phys(dmg), "scroll of earth", - KILLED_BY_AN); + if (dmg) + losehp(Maybe_Half_Phys(dmg), "scroll of earth", KILLED_BY_AN); } boolean -drop_boulder_on_monster(x,y, confused, byu) -int x,y; +drop_boulder_on_monster(x, y, confused, byu) +int x, y; boolean confused; boolean byu; { @@ -1641,65 +1657,63 @@ boolean byu; /* Make the object(s) */ otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE); - if (!otmp2) return FALSE; /* Shouldn't happen */ - otmp2->quan = confused ? rn1(5,2) : 1; + if (!otmp2) + return FALSE; /* Shouldn't happen */ + otmp2->quan = confused ? rn1(5, 2) : 1; otmp2->owt = weight(otmp2); /* Find the monster here (won't be player) */ mtmp = m_at(x, y); - if (mtmp && !amorphous(mtmp->data) && - !passes_walls(mtmp->data) && - !noncorporeal(mtmp->data) && - !unsolid(mtmp->data)) { - struct obj *helmet = which_armor(mtmp, W_ARMH); - int mdmg; + if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data) + && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) { + struct obj *helmet = which_armor(mtmp, W_ARMH); + int mdmg; - if (cansee(mtmp->mx, mtmp->my)) { - pline("%s is hit by %s!", Monnam(mtmp), - doname(otmp2)); - if (mtmp->minvis && !canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); - } else if (u.uswallow && mtmp == u.ustuck) - You_hear("something hit %s %s over your %s!", - s_suffix(mon_nam(mtmp)), - mbodypart(mtmp, STOMACH), - body_part(HEAD)); + if (cansee(mtmp->mx, mtmp->my)) { + pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2)); + if (mtmp->minvis && !canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + } else if (u.uswallow && mtmp == u.ustuck) + You_hear("something hit %s %s over your %s!", + s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH), + body_part(HEAD)); - mdmg = dmgval(otmp2, mtmp) * otmp2->quan; - if (helmet) { - if(is_metallic(helmet)) { - if (canspotmon(mtmp)) - pline("Fortunately, %s is wearing a hard helmet.", mon_nam(mtmp)); - else if (!Deaf) - You_hear("a clanging sound."); - if (mdmg > 2) mdmg = 2; - } else { - if (canspotmon(mtmp)) - pline("%s's %s does not protect %s.", - Monnam(mtmp), xname(helmet), - mhim(mtmp)); - } - } - mtmp->mhp -= mdmg; - if (mtmp->mhp <= 0) { - if (byu) - xkilled(mtmp, 1); - else { - pline("%s is killed.", Monnam(mtmp)); - mondied(mtmp); - } - } + mdmg = dmgval(otmp2, mtmp) * otmp2->quan; + if (helmet) { + if (is_metallic(helmet)) { + if (canspotmon(mtmp)) + pline("Fortunately, %s is wearing a hard helmet.", + mon_nam(mtmp)); + else if (!Deaf) + You_hear("a clanging sound."); + if (mdmg > 2) + mdmg = 2; + } else { + if (canspotmon(mtmp)) + pline("%s's %s does not protect %s.", Monnam(mtmp), + xname(helmet), mhim(mtmp)); + } + } + mtmp->mhp -= mdmg; + if (mtmp->mhp <= 0) { + if (byu) + xkilled(mtmp, 1); + else { + pline("%s is killed.", Monnam(mtmp)); + mondied(mtmp); + } + } } else if (u.uswallow && mtmp == u.ustuck) { - obfree(otmp2, (struct obj *)0); - /* fall through to player */ - drop_boulder_on_player(confused, TRUE, FALSE, TRUE); - return 1; + obfree(otmp2, (struct obj *) 0); + /* fall through to player */ + drop_boulder_on_player(confused, TRUE, FALSE, TRUE); + return 1; } /* Drop the rock/boulder to the floor */ if (!flooreffects(otmp2, x, y, "fall")) { - place_object(otmp2, x, y); - stackobj(otmp2); - newsym(x, y); /* map the rock */ + place_object(otmp2, x, y); + stackobj(otmp2); + newsym(x, y); /* map the rock */ } return TRUE; } @@ -1708,37 +1722,44 @@ boolean byu; void wand_explode(obj, chg) struct obj *obj; -int chg; /* recharging */ +int chg; /* recharging */ { const char *expl = !chg ? "suddenly" : "vibrates violently and"; int dmg, n, k; /* number of damage dice */ - if (!chg) chg = 2; /* zap/engrave adjustment */ + if (!chg) + chg = 2; /* zap/engrave adjustment */ n = obj->spe + chg; - if (n < 2) n = 2; /* arbitrary minimum */ + if (n < 2) + n = 2; /* arbitrary minimum */ /* size of damage dice */ switch (obj->otyp) { case WAN_WISHING: - k = 12; break; + k = 12; + break; case WAN_CANCELLATION: case WAN_DEATH: case WAN_POLYMORPH: case WAN_UNDEAD_TURNING: - k = 10; break; + k = 10; + break; case WAN_COLD: case WAN_FIRE: case WAN_LIGHTNING: case WAN_MAGIC_MISSILE: - k = 8; break; + k = 8; + break; case WAN_NOTHING: - k = 4; break; + k = 4; + break; default: - k = 6; break; + k = 6; + break; } /* inflict damage and destroy the wand */ dmg = d(n, k); - obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */ + obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */ pline("%s %s explodes!", Yname2(obj), expl); losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN); useup(obj); @@ -1758,268 +1779,278 @@ STATIC_VAR struct litmon *gremlins = 0; * Low-level lit-field update routine. */ STATIC_PTR void -set_lit(x,y,val) +set_lit(x, y, val) int x, y; genericptr_t val; { - struct monst *mtmp; - struct litmon *gremlin; + struct monst *mtmp; + struct litmon *gremlin; - if (val) { - levl[x][y].lit = 1; - if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) { - gremlin = (struct litmon *)alloc(sizeof *gremlin); - gremlin->mon = mtmp; - gremlin->nxt = gremlins; - gremlins = gremlin; - } - } else { - levl[x][y].lit = 0; - snuff_light_source(x, y); - } + if (val) { + levl[x][y].lit = 1; + if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) { + gremlin = (struct litmon *) alloc(sizeof *gremlin); + gremlin->mon = mtmp; + gremlin->nxt = gremlins; + gremlins = gremlin; + } + } else { + levl[x][y].lit = 0; + snuff_light_source(x, y); + } } void -litroom(on,obj) +litroom(on, obj) register boolean on; struct obj *obj; { - char is_lit; /* value is irrelevant; we use its address - as a `not null' flag for set_lit() */ + char is_lit; /* value is irrelevant; we use its address + as a `not null' flag for set_lit() */ - /* first produce the text (provided you're not blind) */ - if(!on) { - register struct obj *otmp; + /* first produce the text (provided you're not blind) */ + if (!on) { + register struct obj *otmp; - if (!Blind) { - if(u.uswallow) { - pline("It seems even darker in here than before."); - return; - } - if (uwep && artifact_light(uwep) && uwep->lamplit) - pline("Suddenly, the only light left comes from %s!", - the(xname(uwep))); - else - You("are surrounded by darkness!"); - } + if (!Blind) { + if (u.uswallow) { + pline("It seems even darker in here than before."); + return; + } + if (uwep && artifact_light(uwep) && uwep->lamplit) + pline("Suddenly, the only light left comes from %s!", + the(xname(uwep))); + else + You("are surrounded by darkness!"); + } - /* the magic douses lamps, et al, too */ - for(otmp = invent; otmp; otmp = otmp->nobj) - if (otmp->lamplit) - (void) snuff_lit(otmp); - if (Blind) goto do_it; - } else { - if (Blind) goto do_it; - if(u.uswallow){ - if (is_animal(u.ustuck->data)) - pline("%s %s is lit.", - s_suffix(Monnam(u.ustuck)), - mbodypart(u.ustuck, STOMACH)); - else - if (is_whirly(u.ustuck->data)) - pline("%s shines briefly.", - Monnam(u.ustuck)); - else - pline("%s glistens.", Monnam(u.ustuck)); - return; - } - pline("A lit field surrounds you!"); - } + /* the magic douses lamps, et al, too */ + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->lamplit) + (void) snuff_lit(otmp); + if (Blind) + goto do_it; + } else { + if (Blind) + goto do_it; + if (u.uswallow) { + if (is_animal(u.ustuck->data)) + pline("%s %s is lit.", s_suffix(Monnam(u.ustuck)), + mbodypart(u.ustuck, STOMACH)); + else if (is_whirly(u.ustuck->data)) + pline("%s shines briefly.", Monnam(u.ustuck)); + else + pline("%s glistens.", Monnam(u.ustuck)); + return; + } + pline("A lit field surrounds you!"); + } do_it: - /* No-op in water - can only see the adjacent squares and that's it! */ - if (Underwater || Is_waterlevel(&u.uz)) return; - /* - * If we are darkening the room and the hero is punished but not - * blind, then we have to pick up and replace the ball and chain so - * that we don't remember them if they are out of sight. - */ - if (Punished && !on && !Blind) - move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); + /* No-op in water - can only see the adjacent squares and that's it! */ + if (Underwater || Is_waterlevel(&u.uz)) + return; + /* + * If we are darkening the room and the hero is punished but not + * blind, then we have to pick up and replace the ball and chain so + * that we don't remember them if they are out of sight. + */ + if (Punished && !on && !Blind) + move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); - if (Is_rogue_level(&u.uz)) { - /* Can't use do_clear_area because MAX_RADIUS is too small */ - /* rogue lighting must light the entire room */ - int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; - int rx, ry; - if(rnum >= 0) { - for(rx = rooms[rnum].lx-1; rx <= rooms[rnum].hx+1; rx++) - for(ry = rooms[rnum].ly-1; ry <= rooms[rnum].hy+1; ry++) - set_lit(rx, ry, - (genericptr_t)(on ? &is_lit : (char *)0)); - rooms[rnum].rlit = on; - } - /* hallways remain dark on the rogue level */ - } else - do_clear_area(u.ux,u.uy, - (obj && obj->oclass==SCROLL_CLASS && obj->blessed) ? 9 : 5, - set_lit, (genericptr_t)(on ? &is_lit : (char *)0)); + if (Is_rogue_level(&u.uz)) { + /* Can't use do_clear_area because MAX_RADIUS is too small */ + /* rogue lighting must light the entire room */ + int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; + int rx, ry; + if (rnum >= 0) { + for (rx = rooms[rnum].lx - 1; rx <= rooms[rnum].hx + 1; rx++) + for (ry = rooms[rnum].ly - 1; ry <= rooms[rnum].hy + 1; ry++) + set_lit(rx, ry, + (genericptr_t)(on ? &is_lit : (char *) 0)); + rooms[rnum].rlit = on; + } + /* hallways remain dark on the rogue level */ + } else + do_clear_area( + u.ux, u.uy, + (obj && obj->oclass == SCROLL_CLASS && obj->blessed) ? 9 : 5, + set_lit, (genericptr_t)(on ? &is_lit : (char *) 0)); - /* - * If we are not blind, then force a redraw on all positions in sight - * by temporarily blinding the hero. The vision recalculation will - * correctly update all previously seen positions *and* correctly - * set the waslit bit [could be messed up from above]. - */ - if (!Blind) { - vision_recalc(2); + /* + * If we are not blind, then force a redraw on all positions in sight + * by temporarily blinding the hero. The vision recalculation will + * correctly update all previously seen positions *and* correctly + * set the waslit bit [could be messed up from above]. + */ + if (!Blind) { + vision_recalc(2); - /* replace ball&chain */ - if (Punished && !on) - move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); - } + /* replace ball&chain */ + if (Punished && !on) + move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); + } - vision_full_recalc = 1; /* delayed vision recalculation */ - if (gremlins) { - struct litmon *gremlin; + vision_full_recalc = 1; /* delayed vision recalculation */ + if (gremlins) { + struct litmon *gremlin; - /* can't delay vision recalc after all */ - vision_recalc(0); - /* after vision has been updated, monsters who are affected - when hit by light can now be hit by it */ - do { - gremlin = gremlins; - gremlins = gremlin->nxt; - light_hits_gremlin(gremlin->mon, rnd(5)); - free((genericptr_t)gremlin); - } while (gremlins); - } + /* can't delay vision recalc after all */ + vision_recalc(0); + /* after vision has been updated, monsters who are affected + when hit by light can now be hit by it */ + do { + gremlin = gremlins; + gremlins = gremlin->nxt; + light_hits_gremlin(gremlin->mon, rnd(5)); + free((genericptr_t) gremlin); + } while (gremlins); + } } STATIC_OVL void do_class_genocide() { - int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0; - char buf[BUFSZ]; - boolean gameover = FALSE; /* true iff killed self */ + int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0; + char buf[BUFSZ]; + boolean gameover = FALSE; /* true iff killed self */ - for(j=0; ; j++) { - if (j >= 5) { - pline1(thats_enough_tries); - return; - } - do { - getlin("What class of monsters do you wish to genocide?", - buf); - (void)mungspaces(buf); - } while (!*buf); - /* choosing "none" preserves genocideless conduct */ - if (*buf == '\033' || !strcmpi(buf, "none") || - !strcmpi(buf, "nothing")) return; + for (j = 0;; j++) { + if (j >= 5) { + pline1(thats_enough_tries); + return; + } + do { + getlin("What class of monsters do you wish to genocide?", buf); + (void) mungspaces(buf); + } while (!*buf); + /* choosing "none" preserves genocideless conduct */ + if (*buf == '\033' || !strcmpi(buf, "none") + || !strcmpi(buf, "nothing")) + return; - class = name_to_monclass(buf, (int *)0); - if (class == 0 && (i = name_to_mon(buf)) != NON_PM) - class = mons[i].mlet; - immunecnt = gonecnt = goodcnt = 0; - for (i = LOW_PM; i < NUMMONS; i++) { - if (mons[i].mlet == class) { - if (!(mons[i].geno & G_GENO)) immunecnt++; - else if(mvitals[i].mvflags & G_GENOD) gonecnt++; - else goodcnt++; - } - } - if (!goodcnt && class != mons[urole.malenum].mlet && - class != mons[urace.malenum].mlet) { - if (gonecnt) - pline("All such monsters are already nonexistent."); - else if (immunecnt || class == S_invisible) - You("aren't permitted to genocide such monsters."); - else - if (wizard && buf[0] == '*') { - register struct monst *mtmp, *mtmp2; + class = name_to_monclass(buf, (int *) 0); + if (class == 0 && (i = name_to_mon(buf)) != NON_PM) + class = mons[i].mlet; + immunecnt = gonecnt = goodcnt = 0; + for (i = LOW_PM; i < NUMMONS; i++) { + if (mons[i].mlet == class) { + if (!(mons[i].geno & G_GENO)) + immunecnt++; + else if (mvitals[i].mvflags & G_GENOD) + gonecnt++; + else + goodcnt++; + } + } + if (!goodcnt && class != mons[urole.malenum].mlet + && class != mons[urace.malenum].mlet) { + if (gonecnt) + pline("All such monsters are already nonexistent."); + else if (immunecnt || class == S_invisible) + You("aren't permitted to genocide such monsters."); + else if (wizard && buf[0] == '*') { + register struct monst *mtmp, *mtmp2; - gonecnt = 0; - for (mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if (DEADMONSTER(mtmp)) continue; - mongone(mtmp); - gonecnt++; - } - pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt)); - return; - } else - pline("That %s does not represent any monster.", - strlen(buf) == 1 ? "symbol" : "response"); - continue; - } + gonecnt = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (DEADMONSTER(mtmp)) + continue; + mongone(mtmp); + gonecnt++; + } + pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt)); + return; + } else + pline("That %s does not represent any monster.", + strlen(buf) == 1 ? "symbol" : "response"); + continue; + } - for (i = LOW_PM; i < NUMMONS; i++) { - if(mons[i].mlet == class) { - char nam[BUFSZ]; + for (i = LOW_PM; i < NUMMONS; i++) { + if (mons[i].mlet == class) { + char nam[BUFSZ]; - Strcpy(nam, makeplural(mons[i].mname)); - /* Although "genus" is Latin for race, the hero benefits - * from both race and role; thus genocide affects either. - */ - if (Your_Own_Role(i) || Your_Own_Race(i) || - ((mons[i].geno & G_GENO) - && !(mvitals[i].mvflags & G_GENOD))) { - /* This check must be first since player monsters might - * have G_GENOD or !G_GENO. - */ - mvitals[i].mvflags |= (G_GENOD|G_NOCORPSE); - reset_rndmonst(i); - kill_genocided_monsters(); - update_inventory(); /* eggs & tins */ - pline("Wiped out all %s.", nam); - if (Upolyd && i == u.umonnum) { - u.mh = -1; - if (Unchanging) { - if (!feel_dead++) You("die."); - /* finish genociding this class of - monsters before ultimately dying */ - gameover = TRUE; - } else - rehumanize(); - } - /* Self-genocide if it matches either your race - or role. Assumption: male and female forms - share same monster class. */ - if (i == urole.malenum || i == urace.malenum) { - u.uhp = -1; - if (Upolyd) { - if (!feel_dead++) You_feel("dead inside."); - } else { - if (!feel_dead++) You("die."); - gameover = TRUE; - } - } - } else if (mvitals[i].mvflags & G_GENOD) { - if (!gameover) - pline("All %s are already nonexistent.", nam); - } else if (!gameover) { - /* suppress feedback about quest beings except - for those applicable to our own role */ - if ((mons[i].msound != MS_LEADER || - quest_info(MS_LEADER) == i) - && (mons[i].msound != MS_NEMESIS || - quest_info(MS_NEMESIS) == i) - && (mons[i].msound != MS_GUARDIAN || - quest_info(MS_GUARDIAN) == i) - /* non-leader/nemesis/guardian role-specific monster */ - && (i != PM_NINJA || /* nuisance */ - Role_if(PM_SAMURAI))) { - boolean named, uniq; + Strcpy(nam, makeplural(mons[i].mname)); + /* Although "genus" is Latin for race, the hero benefits + * from both race and role; thus genocide affects either. + */ + if (Your_Own_Role(i) || Your_Own_Race(i) + || ((mons[i].geno & G_GENO) + && !(mvitals[i].mvflags & G_GENOD))) { + /* This check must be first since player monsters might + * have G_GENOD or !G_GENO. + */ + mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE); + reset_rndmonst(i); + kill_genocided_monsters(); + update_inventory(); /* eggs & tins */ + pline("Wiped out all %s.", nam); + if (Upolyd && i == u.umonnum) { + u.mh = -1; + if (Unchanging) { + if (!feel_dead++) + You("die."); + /* finish genociding this class of + monsters before ultimately dying */ + gameover = TRUE; + } else + rehumanize(); + } + /* Self-genocide if it matches either your race + or role. Assumption: male and female forms + share same monster class. */ + if (i == urole.malenum || i == urace.malenum) { + u.uhp = -1; + if (Upolyd) { + if (!feel_dead++) + You_feel("dead inside."); + } else { + if (!feel_dead++) + You("die."); + gameover = TRUE; + } + } + } else if (mvitals[i].mvflags & G_GENOD) { + if (!gameover) + pline("All %s are already nonexistent.", nam); + } else if (!gameover) { + /* suppress feedback about quest beings except + for those applicable to our own role */ + if ((mons[i].msound != MS_LEADER + || quest_info(MS_LEADER) == i) + && (mons[i].msound != MS_NEMESIS + || quest_info(MS_NEMESIS) == i) + && (mons[i].msound != MS_GUARDIAN + || quest_info(MS_GUARDIAN) == i) + /* non-leader/nemesis/guardian role-specific monster + */ + && (i != PM_NINJA || /* nuisance */ + Role_if(PM_SAMURAI))) { + boolean named, uniq; - named = type_is_pname(&mons[i]) ? TRUE : FALSE; - uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE; - /* one special case */ - if (i == PM_HIGH_PRIEST) uniq = FALSE; + named = type_is_pname(&mons[i]) ? TRUE : FALSE; + uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE; + /* one special case */ + if (i == PM_HIGH_PRIEST) + uniq = FALSE; - You("aren't permitted to genocide %s%s.", - (uniq && !named) ? "the " : "", - (uniq || named) ? mons[i].mname : nam); - } - } - } - } - if (gameover || u.uhp == -1) { - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "scroll of genocide"); - if (gameover) done(GENOCIDED); - } - return; - } + You("aren't permitted to genocide %s%s.", + (uniq && !named) ? "the " : "", + (uniq || named) ? mons[i].mname : nam); + } + } + } + } + if (gameover || u.uhp == -1) { + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "scroll of genocide"); + if (gameover) + done(GENOCIDED); + } + return; + } } #define REALLY 1 @@ -2033,201 +2064,211 @@ int how; /* 3 = forced genocide of player */ /* 5 (4 | 1) = normal genocide from throne */ { - char buf[BUFSZ]; - register int i, killplayer = 0; - register int mndx; - register struct permonst *ptr; - const char *which; + char buf[BUFSZ]; + register int i, killplayer = 0; + register int mndx; + register struct permonst *ptr; + const char *which; - if (how & PLAYER) { - mndx = u.umonster; /* non-polymorphed mon num */ - ptr = &mons[mndx]; - Strcpy(buf, ptr->mname); - killplayer++; - } else { - for(i = 0; ; i++) { - if(i >= 5) { - pline1(thats_enough_tries); - return; - } - getlin("What monster do you want to genocide? [type the name]", - buf); - (void)mungspaces(buf); - /* choosing "none" preserves genocideless conduct */ - if (!strcmpi(buf, "none") || !strcmpi(buf, "nothing")) { - /* ... but no free pass if cursed */ - if (!(how & REALLY)) { - ptr = rndmonst(); - if (!ptr) return; /* no message, like normal case */ - mndx = monsndx(ptr); - break; /* remaining checks don't apply */ - } else return; - } + if (how & PLAYER) { + mndx = u.umonster; /* non-polymorphed mon num */ + ptr = &mons[mndx]; + Strcpy(buf, ptr->mname); + killplayer++; + } else { + for (i = 0;; i++) { + if (i >= 5) { + pline1(thats_enough_tries); + return; + } + getlin("What monster do you want to genocide? [type the name]", + buf); + (void) mungspaces(buf); + /* choosing "none" preserves genocideless conduct */ + if (!strcmpi(buf, "none") || !strcmpi(buf, "nothing")) { + /* ... but no free pass if cursed */ + if (!(how & REALLY)) { + ptr = rndmonst(); + if (!ptr) + return; /* no message, like normal case */ + mndx = monsndx(ptr); + break; /* remaining checks don't apply */ + } else + return; + } - mndx = name_to_mon(buf); - if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) { - pline("Such creatures %s exist in this world.", - (mndx == NON_PM) ? "do not" : "no longer"); - continue; - } - ptr = &mons[mndx]; - /* Although "genus" is Latin for race, the hero benefits - * from both race and role; thus genocide affects either. - */ - if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) { - killplayer++; - break; - } - if (is_human(ptr)) adjalign(-sgn(u.ualign.type)); - if (is_demon(ptr)) adjalign(sgn(u.ualign.type)); + mndx = name_to_mon(buf); + if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) { + pline("Such creatures %s exist in this world.", + (mndx == NON_PM) ? "do not" : "no longer"); + continue; + } + ptr = &mons[mndx]; + /* Although "genus" is Latin for race, the hero benefits + * from both race and role; thus genocide affects either. + */ + if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) { + killplayer++; + break; + } + if (is_human(ptr)) + adjalign(-sgn(u.ualign.type)); + if (is_demon(ptr)) + adjalign(sgn(u.ualign.type)); - if(!(ptr->geno & G_GENO)) { - if(!Deaf) { - /* fixme: unconditional "caverns" will be silly in some circumstances */ - if(flags.verbose) - pline("A thunderous voice booms through the caverns:"); - verbalize("No, mortal! That will not be done."); - } - continue; - } - /* KMH -- Unchanging prevents rehumanization */ - if (Unchanging && ptr == youmonst.data) - killplayer++; - break; - } - } + if (!(ptr->geno & G_GENO)) { + if (!Deaf) { + /* fixme: unconditional "caverns" will be silly in some + * circumstances */ + if (flags.verbose) + pline( + "A thunderous voice booms through the caverns:"); + verbalize("No, mortal! That will not be done."); + } + continue; + } + /* KMH -- Unchanging prevents rehumanization */ + if (Unchanging && ptr == youmonst.data) + killplayer++; + break; + } + } - which = "all "; - if (Hallucination) { - if (Upolyd) - Strcpy(buf,youmonst.data->mname); - else { - Strcpy(buf, (flags.female && urole.name.f) ? - urole.name.f : urole.name.m); - buf[0] = lowc(buf[0]); - } - } else { - Strcpy(buf, ptr->mname); /* make sure we have standard singular */ - if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST]) - which = !type_is_pname(ptr) ? "the " : ""; - } - if (how & REALLY) { - /* setting no-corpse affects wishing and random tin generation */ - mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE); - pline("Wiped out %s%s.", which, - (*which != 'a') ? buf : makeplural(buf)); + which = "all "; + if (Hallucination) { + if (Upolyd) + Strcpy(buf, youmonst.data->mname); + else { + Strcpy(buf, (flags.female && urole.name.f) ? urole.name.f + : urole.name.m); + buf[0] = lowc(buf[0]); + } + } else { + Strcpy(buf, ptr->mname); /* make sure we have standard singular */ + if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST]) + which = !type_is_pname(ptr) ? "the " : ""; + } + if (how & REALLY) { + /* setting no-corpse affects wishing and random tin generation */ + mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE); + pline("Wiped out %s%s.", which, + (*which != 'a') ? buf : makeplural(buf)); - if (killplayer) { - /* might need to wipe out dual role */ - if (urole.femalenum != NON_PM && mndx == urole.malenum) - mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); - if (urole.femalenum != NON_PM && mndx == urole.femalenum) - mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE); - if (urace.femalenum != NON_PM && mndx == urace.malenum) - mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); - if (urace.femalenum != NON_PM && mndx == urace.femalenum) - mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE); + if (killplayer) { + /* might need to wipe out dual role */ + if (urole.femalenum != NON_PM && mndx == urole.malenum) + mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); + if (urole.femalenum != NON_PM && mndx == urole.femalenum) + mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE); + if (urace.femalenum != NON_PM && mndx == urace.malenum) + mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); + if (urace.femalenum != NON_PM && mndx == urace.femalenum) + mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE); - u.uhp = -1; - if (how & PLAYER) { - killer.format = KILLED_BY; - Strcpy(killer.name, "genocidal confusion"); - } else if (how & ONTHRONE) { - /* player selected while on a throne */ - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "imperious order"); - } else { /* selected player deliberately, not confused */ - killer.format = KILLED_BY_AN; - Strcpy(killer.name, "scroll of genocide"); - } + u.uhp = -1; + if (how & PLAYER) { + killer.format = KILLED_BY; + Strcpy(killer.name, "genocidal confusion"); + } else if (how & ONTHRONE) { + /* player selected while on a throne */ + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "imperious order"); + } else { /* selected player deliberately, not confused */ + killer.format = KILLED_BY_AN; + Strcpy(killer.name, "scroll of genocide"); + } - /* Polymorphed characters will die as soon as they're rehumanized. */ - /* KMH -- Unchanging prevents rehumanization */ - if (Upolyd && ptr != youmonst.data) { - delayed_killer(POLYMORPH, killer.format, killer.name); - You_feel("dead inside."); - } else - done(GENOCIDED); - } else if (ptr == youmonst.data) { - rehumanize(); - } - reset_rndmonst(mndx); - kill_genocided_monsters(); - update_inventory(); /* in case identified eggs were affected */ - } else { - int cnt = 0, census = monster_census(FALSE); + /* Polymorphed characters will die as soon as they're rehumanized. + */ + /* KMH -- Unchanging prevents rehumanization */ + if (Upolyd && ptr != youmonst.data) { + delayed_killer(POLYMORPH, killer.format, killer.name); + You_feel("dead inside."); + } else + done(GENOCIDED); + } else if (ptr == youmonst.data) { + rehumanize(); + } + reset_rndmonst(mndx); + kill_genocided_monsters(); + update_inventory(); /* in case identified eggs were affected */ + } else { + int cnt = 0, census = monster_census(FALSE); - if (!(mons[mndx].geno & G_UNIQ) && - !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT))) - for (i = rn1(3, 4); i > 0; i--) { - if (!makemon(ptr, u.ux, u.uy, NO_MINVENT)) - break; /* couldn't make one */ - ++cnt; - if (mvitals[mndx].mvflags & G_EXTINCT) - break; /* just made last one */ - } - if (cnt) { - /* accumulated 'cnt' doesn't take groups into account; - assume bringing in new mon(s) didn't remove any old ones */ - cnt = monster_census(FALSE) - census; - pline("Sent in %s%s.", (cnt > 1) ? "some " : "", - (cnt > 1) ? makeplural(buf) : an(buf)); - } else - pline1(nothing_happens); - } + if (!(mons[mndx].geno & G_UNIQ) + && !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT))) + for (i = rn1(3, 4); i > 0; i--) { + if (!makemon(ptr, u.ux, u.uy, NO_MINVENT)) + break; /* couldn't make one */ + ++cnt; + if (mvitals[mndx].mvflags & G_EXTINCT) + break; /* just made last one */ + } + if (cnt) { + /* accumulated 'cnt' doesn't take groups into account; + assume bringing in new mon(s) didn't remove any old ones */ + cnt = monster_census(FALSE) - census; + pline("Sent in %s%s.", (cnt > 1) ? "some " : "", + (cnt > 1) ? makeplural(buf) : an(buf)); + } else + pline1(nothing_happens); + } } void punish(sobj) -register struct obj *sobj; +register struct obj *sobj; { - struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL) ? - sobj : (struct obj *)0; - /* KMH -- Punishment is still okay when you are riding */ - if (!reuse_ball) You("are being punished for your misbehavior!"); - if(Punished){ - Your("iron ball gets heavier."); - uball->owt += 160 * (1 + sobj->cursed); - return; - } - if (amorphous(youmonst.data) || is_whirly(youmonst.data) || unsolid(youmonst.data)) { - if (!reuse_ball) { - pline("A ball and chain appears, then falls away."); - dropy(mkobj(BALL_CLASS, TRUE)); - } else { - dropy(reuse_ball); - } - return; - } - setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN); - if (!reuse_ball) - setworn(mkobj(BALL_CLASS, TRUE), W_BALL); - else - setworn(reuse_ball, W_BALL); - uball->spe = 1; /* special ball (see save) */ + struct obj *reuse_ball = + (sobj && sobj->otyp == HEAVY_IRON_BALL) ? sobj : (struct obj *) 0; + /* KMH -- Punishment is still okay when you are riding */ + if (!reuse_ball) + You("are being punished for your misbehavior!"); + if (Punished) { + Your("iron ball gets heavier."); + uball->owt += 160 * (1 + sobj->cursed); + return; + } + if (amorphous(youmonst.data) || is_whirly(youmonst.data) + || unsolid(youmonst.data)) { + if (!reuse_ball) { + pline("A ball and chain appears, then falls away."); + dropy(mkobj(BALL_CLASS, TRUE)); + } else { + dropy(reuse_ball); + } + return; + } + setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN); + if (!reuse_ball) + setworn(mkobj(BALL_CLASS, TRUE), W_BALL); + else + setworn(reuse_ball, W_BALL); + uball->spe = 1; /* special ball (see save) */ - /* - * Place ball & chain if not swallowed. If swallowed, the ball & - * chain variables will be set at the next call to placebc(). - */ - if (!u.uswallow) { - placebc(); - if (Blind) set_bc(1); /* set up ball and chain variables */ - newsym(u.ux,u.uy); /* see ball&chain if can't see self */ - } + /* + * Place ball & chain if not swallowed. If swallowed, the ball & + * chain variables will be set at the next call to placebc(). + */ + if (!u.uswallow) { + placebc(); + if (Blind) + set_bc(1); /* set up ball and chain variables */ + newsym(u.ux, u.uy); /* see ball&chain if can't see self */ + } } void unpunish() -{ /* remove the ball and chain */ - struct obj *savechain = uchain; +{ /* remove the ball and chain */ + struct obj *savechain = uchain; - obj_extract_self(uchain); - newsym(uchain->ox,uchain->oy); - setworn((struct obj *)0, W_CHAIN); - dealloc_obj(savechain); - uball->spe = 0; - setworn((struct obj *)0, W_BALL); + obj_extract_self(uchain); + newsym(uchain->ox, uchain->oy); + setworn((struct obj *) 0, W_CHAIN); + dealloc_obj(savechain); + uball->spe = 0; + setworn((struct obj *) 0, W_BALL); } /* some creatures have special data structures that only make sense in their @@ -2240,23 +2281,23 @@ int *mtype; boolean revival; struct obj *from_obj; { - /* SHOPKEEPERS can be revived now */ - if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival) || - *mtype == PM_HIGH_PRIEST || *mtype == PM_ALIGNED_PRIEST || - *mtype == PM_ANGEL) { - *mtype = PM_HUMAN_ZOMBIE; - return TRUE; - } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */ - *mtype = PM_LONG_WORM; - return TRUE; - } else if (unique_corpstat(&mons[*mtype]) && - (!from_obj || !has_omonst(from_obj))) { - /* unique corpses (from bones or wizard mode wish) or - statues (bones or any wish) end up as shapechangers */ - *mtype = PM_DOPPELGANGER; - return TRUE; - } - return FALSE; + /* SHOPKEEPERS can be revived now */ + if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival) + || *mtype == PM_HIGH_PRIEST || *mtype == PM_ALIGNED_PRIEST + || *mtype == PM_ANGEL) { + *mtype = PM_HUMAN_ZOMBIE; + return TRUE; + } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */ + *mtype = PM_LONG_WORM; + return TRUE; + } else if (unique_corpstat(&mons[*mtype]) + && (!from_obj || !has_omonst(from_obj))) { + /* unique corpses (from bones or wizard mode wish) or + statues (bones or any wish) end up as shapechangers */ + *mtype = PM_DOPPELGANGER; + return TRUE; + } + return FALSE; } /* @@ -2269,94 +2310,97 @@ struct obj *from_obj; boolean create_particular() { - char buf[BUFSZ], *bufp, monclass; - int which, tryct, i, firstchoice = NON_PM; - struct permonst *whichpm = NULL; - struct monst *mtmp; - boolean madeany = FALSE; - boolean maketame, makepeaceful, makehostile; - boolean randmonst = FALSE; + char buf[BUFSZ], *bufp, monclass; + int which, tryct, i, firstchoice = NON_PM; + struct permonst *whichpm = NULL; + struct monst *mtmp; + boolean madeany = FALSE; + boolean maketame, makepeaceful, makehostile; + boolean randmonst = FALSE; - tryct = 5; - do { - monclass = MAXMCLASSES; - which = urole.malenum; /* an arbitrary index into mons[] */ - maketame = makepeaceful = makehostile = FALSE; - getlin("Create what kind of monster? [type the name or symbol]", - buf); - bufp = mungspaces(buf); - if (*bufp == '\033') return FALSE; - /* allow the initial disposition to be specified */ - if (!strncmpi(bufp, "tame ", 5)) { - bufp += 5; - maketame = TRUE; - } else if (!strncmpi(bufp, "peaceful ", 9)) { - bufp += 9; - makepeaceful = TRUE; - } else if (!strncmpi(bufp, "hostile ", 8)) { - bufp += 8; - makehostile = TRUE; - } - /* decide whether a valid monster was chosen */ - if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) { - randmonst = TRUE; - break; - } - which = name_to_mon(bufp); - if (which >= LOW_PM) break; /* got one */ - monclass = name_to_monclass(bufp, &which); - if (which >= LOW_PM) { - monclass = MAXMCLASSES; /* matters below */ - break; - } else if (monclass > 0) { - which = urole.malenum; /* reset from NON_PM */ - break; - } - /* no good; try again... */ - pline("I've never heard of such monsters."); - } while (--tryct > 0); + tryct = 5; + do { + monclass = MAXMCLASSES; + which = urole.malenum; /* an arbitrary index into mons[] */ + maketame = makepeaceful = makehostile = FALSE; + getlin("Create what kind of monster? [type the name or symbol]", buf); + bufp = mungspaces(buf); + if (*bufp == '\033') + return FALSE; + /* allow the initial disposition to be specified */ + if (!strncmpi(bufp, "tame ", 5)) { + bufp += 5; + maketame = TRUE; + } else if (!strncmpi(bufp, "peaceful ", 9)) { + bufp += 9; + makepeaceful = TRUE; + } else if (!strncmpi(bufp, "hostile ", 8)) { + bufp += 8; + makehostile = TRUE; + } + /* decide whether a valid monster was chosen */ + if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) { + randmonst = TRUE; + break; + } + which = name_to_mon(bufp); + if (which >= LOW_PM) + break; /* got one */ + monclass = name_to_monclass(bufp, &which); + if (which >= LOW_PM) { + monclass = MAXMCLASSES; /* matters below */ + break; + } else if (monclass > 0) { + which = urole.malenum; /* reset from NON_PM */ + break; + } + /* no good; try again... */ + pline("I've never heard of such monsters."); + } while (--tryct > 0); - if (!tryct) { - pline1(thats_enough_tries); - } else { - if (!randmonst) { + if (!tryct) { + pline1(thats_enough_tries); + } else { + if (!randmonst) { firstchoice = which; - if (cant_revive(&which, FALSE, (struct obj *)0)) { + if (cant_revive(&which, FALSE, (struct obj *) 0)) { /* wizard mode can override handling of special monsters */ Sprintf(buf, "Creating %s instead; force %s?", - mons[which].mname, mons[firstchoice].mname); - if (yn(buf) == 'y') which = firstchoice; + mons[which].mname, mons[firstchoice].mname); + if (yn(buf) == 'y') + which = firstchoice; } whichpm = &mons[which]; - } - for (i = 0; i <= multi; i++) { - if (monclass != MAXMCLASSES) - whichpm = mkclass(monclass, 0); - else if (randmonst) - whichpm = rndmonst(); - mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS); - if (!mtmp) { - /* quit trying if creation failed and is going to repeat */ - if (monclass == MAXMCLASSES && !randmonst) break; - /* otherwise try again */ - continue; - } - if (maketame) { - (void) tamedog(mtmp, (struct obj *) 0); - } else if (makepeaceful || makehostile) { - mtmp->mtame = 0; /* sanity precaution */ - mtmp->mpeaceful = makepeaceful ? 1 : 0; - set_malign(mtmp); - } - madeany = TRUE; - /* in case we got a doppelganger instead of what was asked - for, make it start out looking like what was asked for */ - if (mtmp->cham != NON_PM && firstchoice != NON_PM && - mtmp->cham != firstchoice) - (void)newcham(mtmp, &mons[firstchoice], FALSE, FALSE); - } - } - return madeany; + } + for (i = 0; i <= multi; i++) { + if (monclass != MAXMCLASSES) + whichpm = mkclass(monclass, 0); + else if (randmonst) + whichpm = rndmonst(); + mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS); + if (!mtmp) { + /* quit trying if creation failed and is going to repeat */ + if (monclass == MAXMCLASSES && !randmonst) + break; + /* otherwise try again */ + continue; + } + if (maketame) { + (void) tamedog(mtmp, (struct obj *) 0); + } else if (makepeaceful || makehostile) { + mtmp->mtame = 0; /* sanity precaution */ + mtmp->mpeaceful = makepeaceful ? 1 : 0; + set_malign(mtmp); + } + madeany = TRUE; + /* in case we got a doppelganger instead of what was asked + for, make it start out looking like what was asked for */ + if (mtmp->cham != NON_PM && firstchoice != NON_PM + && mtmp->cham != firstchoice) + (void) newcham(mtmp, &mons[firstchoice], FALSE, FALSE); + } + } + return madeany; } /*read.c*/ diff --git a/src/rect.c b/src/rect.c index c863e5b4b..3824783d2 100644 --- a/src/rect.c +++ b/src/rect.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 rect.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 rect.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 rect.c $Date: 2009/05/06 10:47:37 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)rect.c 3.5 1990/02/22 */ /* Copyright (c) 1990 by Jean-Christophe Collet */ @@ -8,18 +8,18 @@ int FDECL(get_rect_ind, (NhRect *)); -STATIC_DCL boolean FDECL(intersect, (NhRect *,NhRect *,NhRect *)); +STATIC_DCL boolean FDECL(intersect, (NhRect *, NhRect *, NhRect *)); - /* - * In this file, we will handle the various rectangle functions we - * need for room generation. - */ +/* + * In this file, we will handle the various rectangle functions we + * need for room generation. + */ -#define MAXRECT 50 -#define XLIM 4 -#define YLIM 3 +#define MAXRECT 50 +#define XLIM 4 +#define YLIM 3 -static NhRect rect[MAXRECT+1]; +static NhRect rect[MAXRECT + 1]; static int rect_cnt; /* @@ -30,10 +30,10 @@ static int rect_cnt; void init_rect() { - rect_cnt = 1; - rect[0].lx = rect[0].ly = 0; - rect[0].hx = COLNO - 1; - rect[0].hy = ROWNO - 1; + rect_cnt = 1; + rect[0].lx = rect[0].ly = 0; + rect[0].hx = COLNO - 1; + rect[0].hy = ROWNO - 1; } /* @@ -45,17 +45,19 @@ int get_rect_ind(r) NhRect *r; { - register NhRect *rectp; - register int lx, ly, hx, hy; - register int i; + register NhRect *rectp; + register int lx, ly, hx, hy; + register int i; - lx = r->lx; ly = r->ly; - hx = r->hx; hy = r->hy; - for (i=0,rectp = &rect[0];ilx && ly == rectp->ly && - hx == rectp->hx && hy == rectp->hy) - return i; - return -1; + lx = r->lx; + ly = r->ly; + hx = r->hx; + hy = r->hy; + for (i = 0, rectp = &rect[0]; i < rect_cnt; i++, rectp++) + if (lx == rectp->lx && ly == rectp->ly && hx == rectp->hx + && hy == rectp->hy) + return i; + return -1; } /* @@ -66,17 +68,19 @@ NhRect * get_rect(r) NhRect *r; { - register NhRect *rectp; - register int lx, ly, hx, hy; - register int i; + register NhRect *rectp; + register int lx, ly, hx, hy; + register int i; - lx = r->lx; ly = r->ly; - hx = r->hx; hy = r->hy; - for (i=0,rectp = &rect[0];i= rectp->lx && ly >= rectp->ly && - hx <= rectp->hx && hy <= rectp->hy) - return rectp; - return 0; + lx = r->lx; + ly = r->ly; + hx = r->hx; + hy = r->hy; + for (i = 0, rectp = &rect[0]; i < rect_cnt; i++, rectp++) + if (lx >= rectp->lx && ly >= rectp->ly && hx <= rectp->hx + && hy <= rectp->hy) + return rectp; + return 0; } /* @@ -86,7 +90,7 @@ NhRect *r; NhRect * rnd_rect() { - return rect_cnt > 0 ? &rect[rn2(rect_cnt)] : 0; + return rect_cnt > 0 ? &rect[rn2(rect_cnt)] : 0; } /* @@ -99,18 +103,18 @@ STATIC_OVL boolean intersect(r1, r2, r3) NhRect *r1, *r2, *r3; { - if (r2->lx > r1->hx || r2->ly > r1->hy || - r2->hx < r1->lx || r2->hy < r1->ly) - return FALSE; + if (r2->lx > r1->hx || r2->ly > r1->hy || r2->hx < r1->lx + || r2->hy < r1->ly) + return FALSE; - r3->lx = (r2->lx > r1->lx ? r2->lx : r1->lx); - r3->ly = (r2->ly > r1->ly ? r2->ly : r1->ly); - r3->hx = (r2->hx > r1->hx ? r1->hx : r2->hx); - r3->hy = (r2->hy > r1->hy ? r1->hy : r2->hy); + r3->lx = (r2->lx > r1->lx ? r2->lx : r1->lx); + r3->ly = (r2->ly > r1->ly ? r2->ly : r1->ly); + r3->hx = (r2->hx > r1->hx ? r1->hx : r2->hx); + r3->hy = (r2->hy > r1->hy ? r1->hy : r2->hy); - if (r3->lx > r3->hx || r3->ly > r3->hy) - return FALSE; - return TRUE; + if (r3->lx > r3->hx || r3->ly > r3->hy) + return FALSE; + return TRUE; } /* @@ -121,11 +125,11 @@ void remove_rect(r) NhRect *r; { - int ind; + int ind; - ind = get_rect_ind(r); - if ( ind >=0 ) - rect[ind] = rect[--rect_cnt]; + ind = get_rect_ind(r); + if (ind >= 0) + rect[ind] = rect[--rect_cnt]; } /* @@ -136,15 +140,16 @@ void add_rect(r) NhRect *r; { - if (rect_cnt >= MAXRECT) { - if (wizard) pline("MAXRECT may be too small."); - return; - } - /* Check that this NhRect is not included in another one */ - if (get_rect(r)) - return; - rect[rect_cnt] = *r; - rect_cnt++; + if (rect_cnt >= MAXRECT) { + if (wizard) + pline("MAXRECT may be too small."); + return; + } + /* Check that this NhRect is not included in another one */ + if (get_rect(r)) + return; + rect[rect_cnt] = *r; + rect_cnt++; } /* @@ -158,37 +163,39 @@ void split_rects(r1, r2) NhRect *r1, *r2; { - NhRect r, old_r; - int i; + NhRect r, old_r; + int i; - old_r = *r1; - remove_rect(r1); + old_r = *r1; + remove_rect(r1); - /* Walk down since rect_cnt & rect[] will change... */ - for (i=rect_cnt-1; i>=0; i--) - if (intersect(&rect[i], r2, &r)) - split_rects(&rect[i], &r); - - if (r2->ly - old_r.ly-1 > (old_r.hy < ROWNO - 1 ? 2*YLIM : YLIM+1)+4) { - r = old_r; - r.hy = r2->ly - 2; - add_rect(&r); - } - if (r2->lx - old_r.lx-1 > (old_r.hx < COLNO - 1 ? 2*XLIM : XLIM+1)+4) { - r = old_r; - r.hx = r2->lx - 2; - add_rect(&r); - } - if (old_r.hy - r2->hy-1 > (old_r.ly > 0 ? 2*YLIM : YLIM+1)+4) { - r = old_r; - r.ly = r2->hy + 2; - add_rect(&r); - } - if (old_r.hx - r2->hx-1 > (old_r.lx > 0 ? 2*XLIM : XLIM+1)+4) { - r = old_r; - r.lx = r2->hx + 2; - add_rect(&r); - } + /* Walk down since rect_cnt & rect[] will change... */ + for (i = rect_cnt - 1; i >= 0; i--) + if (intersect(&rect[i], r2, &r)) + split_rects(&rect[i], &r); + + if (r2->ly - old_r.ly - 1 + > (old_r.hy < ROWNO - 1 ? 2 * YLIM : YLIM + 1) + 4) { + r = old_r; + r.hy = r2->ly - 2; + add_rect(&r); + } + if (r2->lx - old_r.lx - 1 + > (old_r.hx < COLNO - 1 ? 2 * XLIM : XLIM + 1) + 4) { + r = old_r; + r.hx = r2->lx - 2; + add_rect(&r); + } + if (old_r.hy - r2->hy - 1 > (old_r.ly > 0 ? 2 * YLIM : YLIM + 1) + 4) { + r = old_r; + r.ly = r2->hy + 2; + add_rect(&r); + } + if (old_r.hx - r2->hx - 1 > (old_r.lx > 0 ? 2 * XLIM : XLIM + 1) + 4) { + r = old_r; + r.lx = r2->hx + 2; + add_rect(&r); + } } /*rect.c*/ diff --git a/src/region.c b/src/region.c index 7844e7709..5840dcbd5 100644 --- a/src/region.c +++ b/src/region.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 region.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 region.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */ /* NetHack 3.6 region.c $Date: 2012/05/07 01:44:38 $ $Revision: 1.26 $ */ /* Copyright (c) 1996 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -18,15 +18,15 @@ static int max_regions = 0; #define NO_CALLBACK (-1) -boolean FDECL(inside_gas_cloud, (genericptr,genericptr)); -boolean FDECL(expire_gas_cloud, (genericptr,genericptr)); -boolean FDECL(inside_rect, (NhRect *,int,int)); -boolean FDECL(inside_region, (NhRegion *,int,int)); -NhRegion *FDECL(create_region, (NhRect *,int)); -void FDECL(add_rect_to_reg, (NhRegion *,NhRect *)); -void FDECL(add_mon_to_reg, (NhRegion *,struct monst *)); -void FDECL(remove_mon_from_reg, (NhRegion *,struct monst *)); -boolean FDECL(mon_in_region, (NhRegion *,struct monst *)); +boolean FDECL(inside_gas_cloud, (genericptr, genericptr)); +boolean FDECL(expire_gas_cloud, (genericptr, genericptr)); +boolean FDECL(inside_rect, (NhRect *, int, int)); +boolean FDECL(inside_region, (NhRegion *, int, int)); +NhRegion *FDECL(create_region, (NhRect *, int)); +void FDECL(add_rect_to_reg, (NhRegion *, NhRect *)); +void FDECL(add_mon_to_reg, (NhRegion *, struct monst *)); +void FDECL(remove_mon_from_reg, (NhRegion *, struct monst *)); +boolean FDECL(mon_in_region, (NhRegion *, struct monst *)); #if 0 NhRegion *FDECL(clone_region, (NhRegion *)); @@ -72,11 +72,11 @@ int x, y; { int i; - if (reg == (NhRegion *)0 || !inside_rect(&(reg->bounding_box), x, y)) - return FALSE; + if (reg == (NhRegion *) 0 || !inside_rect(&(reg->bounding_box), x, y)) + return FALSE; for (i = 0; i < reg->nrects; i++) - if (inside_rect(&(reg->rects[i]), x, y)) - return TRUE; + if (inside_rect(&(reg->rects[i]), x, y)) + return TRUE; return FALSE; } @@ -91,36 +91,36 @@ int nrect; int i; NhRegion *reg; - reg = (NhRegion *) alloc(sizeof (NhRegion)); + reg = (NhRegion *) alloc(sizeof(NhRegion)); /* Determines bounding box */ if (nrect > 0) { - reg->bounding_box = rects[0]; + reg->bounding_box = rects[0]; } else { - reg->bounding_box.lx = 99; - reg->bounding_box.ly = 99; - reg->bounding_box.hx = 0; - reg->bounding_box.hy = 0; + reg->bounding_box.lx = 99; + reg->bounding_box.ly = 99; + reg->bounding_box.hx = 0; + reg->bounding_box.hy = 0; } reg->nrects = nrect; - reg->rects = nrect > 0 ? - (NhRect *)alloc((sizeof (NhRect)) * nrect) : (NhRect *)0; + reg->rects = + nrect > 0 ? (NhRect *) alloc((sizeof(NhRect)) * nrect) : (NhRect *) 0; for (i = 0; i < nrect; i++) { - if (rects[i].lx < reg->bounding_box.lx) - reg->bounding_box.lx = rects[i].lx; - if (rects[i].ly < reg->bounding_box.ly) - reg->bounding_box.ly = rects[i].ly; - if (rects[i].hx > reg->bounding_box.hx) - reg->bounding_box.hx = rects[i].hx; - if (rects[i].hy > reg->bounding_box.hy) - reg->bounding_box.hy = rects[i].hy; - reg->rects[i] = rects[i]; + if (rects[i].lx < reg->bounding_box.lx) + reg->bounding_box.lx = rects[i].lx; + if (rects[i].ly < reg->bounding_box.ly) + reg->bounding_box.ly = rects[i].ly; + if (rects[i].hx > reg->bounding_box.hx) + reg->bounding_box.hx = rects[i].hx; + if (rects[i].hy > reg->bounding_box.hy) + reg->bounding_box.hy = rects[i].hy; + reg->rects[i] = rects[i]; } - reg->ttl = -1L; /* Defaults */ + reg->ttl = -1L; /* Defaults */ reg->attach_2_u = FALSE; reg->attach_2_m = 0; /* reg->attach_2_o = NULL; */ - reg->enter_msg = (const char *)0; - reg->leave_msg = (const char *)0; + reg->enter_msg = (const char *) 0; + reg->leave_msg = (const char *) 0; reg->expire_f = NO_CALLBACK; reg->enter_f = NO_CALLBACK; reg->can_enter_f = NO_CALLBACK; @@ -131,7 +131,7 @@ int nrect; clear_heros_fault(reg); reg->n_monst = 0; reg->max_monst = 0; - reg->monsters = (unsigned int *)0; + reg->monsters = (unsigned int *) 0; reg->arg = zeroany; return reg; } @@ -146,24 +146,24 @@ NhRect *rect; { NhRect *tmp_rect; - tmp_rect = (NhRect *) alloc(sizeof (NhRect) * (reg->nrects + 1)); + tmp_rect = (NhRect *) alloc(sizeof(NhRect) * (reg->nrects + 1)); if (reg->nrects > 0) { - (void) memcpy((genericptr_t) tmp_rect, (genericptr_t) reg->rects, - (sizeof (NhRect) * reg->nrects)); - free((genericptr_t) reg->rects); + (void) memcpy((genericptr_t) tmp_rect, (genericptr_t) reg->rects, + (sizeof(NhRect) * reg->nrects)); + free((genericptr_t) reg->rects); } tmp_rect[reg->nrects] = *rect; reg->nrects++; reg->rects = tmp_rect; /* Update bounding box if needed */ if (reg->bounding_box.lx > rect->lx) - reg->bounding_box.lx = rect->lx; + reg->bounding_box.lx = rect->lx; if (reg->bounding_box.ly > rect->ly) - reg->bounding_box.ly = rect->ly; + reg->bounding_box.ly = rect->ly; if (reg->bounding_box.hx < rect->hx) - reg->bounding_box.hx = rect->hx; + reg->bounding_box.hx = rect->hx; if (reg->bounding_box.hy < rect->hy) - reg->bounding_box.hy = rect->hy; + reg->bounding_box.hy = rect->hy; } /* @@ -178,15 +178,15 @@ struct monst *mon; unsigned *tmp_m; if (reg->max_monst <= reg->n_monst) { - tmp_m = (unsigned *) - alloc(sizeof (unsigned) * (reg->max_monst + MONST_INC)); - if (reg->max_monst > 0) { - for (i = 0; i < reg->max_monst; i++) - tmp_m[i] = reg->monsters[i]; - free((genericptr_t) reg->monsters); - } - reg->monsters = tmp_m; - reg->max_monst += MONST_INC; + tmp_m = (unsigned *) alloc(sizeof(unsigned) + * (reg->max_monst + MONST_INC)); + if (reg->max_monst > 0) { + for (i = 0; i < reg->max_monst; i++) + tmp_m[i] = reg->monsters[i]; + free((genericptr_t) reg->monsters); + } + reg->monsters = tmp_m; + reg->max_monst += MONST_INC; } reg->monsters[reg->n_monst++] = mon->m_id; } @@ -202,11 +202,11 @@ struct monst *mon; register int i; for (i = 0; i < reg->n_monst; i++) - if (reg->monsters[i] == mon->m_id) { - reg->n_monst--; - reg->monsters[i] = reg->monsters[reg->n_monst]; - return; - } + if (reg->monsters[i] == mon->m_id) { + reg->n_monst--; + reg->monsters[i] = reg->monsters[reg->n_monst]; + return; + } } /* @@ -222,8 +222,8 @@ struct monst *mon; int i; for (i = 0; i < reg->n_monst; i++) - if (reg->monsters[i] == mon->m_id) - return TRUE; + if (reg->monsters[i] == mon->m_id) + return TRUE; return FALSE; } @@ -261,7 +261,7 @@ NhRegion *reg; return ret_reg; } -#endif /*0*/ +#endif /*0*/ /* * Free mem from region. @@ -271,15 +271,15 @@ free_region(reg) NhRegion *reg; { if (reg) { - if (reg->rects) - free((genericptr_t) reg->rects); - if (reg->monsters) - free((genericptr_t) reg->monsters); - if (reg->enter_msg) - free((genericptr_t) reg->enter_msg); - if (reg->leave_msg) - free((genericptr_t) reg->leave_msg); - free((genericptr_t) reg); + if (reg->rects) + free((genericptr_t) reg->rects); + if (reg->monsters) + free((genericptr_t) reg->monsters); + if (reg->enter_msg) + free((genericptr_t) reg->enter_msg); + if (reg->leave_msg) + free((genericptr_t) reg->leave_msg); + free((genericptr_t) reg); } } @@ -295,33 +295,34 @@ NhRegion *reg; int i, j; if (max_regions <= n_regions) { - tmp_reg = regions; - regions = (NhRegion **)alloc(sizeof (NhRegion *) * (max_regions + 10)); - if (max_regions > 0) { - (void) memcpy((genericptr_t) regions, (genericptr_t) tmp_reg, - max_regions * sizeof (NhRegion *)); - free((genericptr_t) tmp_reg); - } - max_regions += 10; + tmp_reg = regions; + regions = + (NhRegion **) alloc(sizeof(NhRegion *) * (max_regions + 10)); + if (max_regions > 0) { + (void) memcpy((genericptr_t) regions, (genericptr_t) tmp_reg, + max_regions * sizeof(NhRegion *)); + free((genericptr_t) tmp_reg); + } + max_regions += 10; } regions[n_regions] = reg; n_regions++; /* Check for monsters inside the region */ for (i = reg->bounding_box.lx; i <= reg->bounding_box.hx; i++) - for (j = reg->bounding_box.ly; j <= reg->bounding_box.hy; j++) { - /* Some regions can cross the level boundaries */ - if (!isok(i,j)) - continue; - if (MON_AT(i, j) && inside_region(reg, i, j)) - add_mon_to_reg(reg, level.monsters[i][j]); - if (reg->visible && cansee(i, j)) - newsym(i, j); - } + for (j = reg->bounding_box.ly; j <= reg->bounding_box.hy; j++) { + /* Some regions can cross the level boundaries */ + if (!isok(i, j)) + continue; + if (MON_AT(i, j) && inside_region(reg, i, j)) + add_mon_to_reg(reg, level.monsters[i][j]); + if (reg->visible && cansee(i, j)) + newsym(i, j); + } /* Check for player now... */ - if (inside_region(reg, u.ux, u.uy)) - set_hero_inside(reg); + if (inside_region(reg, u.ux, u.uy)) + set_hero_inside(reg); else - clear_hero_inside(reg); + clear_hero_inside(reg); } /* @@ -334,18 +335,18 @@ NhRegion *reg; register int i, x, y; for (i = 0; i < n_regions; i++) - if (regions[i] == reg) - break; + if (regions[i] == reg) + break; if (i == n_regions) - return; + return; /* Update screen if necessary */ - reg->ttl = -2L; /* for visible_region_at */ + reg->ttl = -2L; /* for visible_region_at */ if (reg->visible) - for (x = reg->bounding_box.lx; x <= reg->bounding_box.hx; x++) - for (y = reg->bounding_box.ly; y <= reg->bounding_box.hy; y++) - if (isok(x,y) && inside_region(reg, x, y) && cansee(x, y)) - newsym(x, y); + for (x = reg->bounding_box.lx; x <= reg->bounding_box.hx; x++) + for (y = reg->bounding_box.ly; y <= reg->bounding_box.hy; y++) + if (isok(x, y) && inside_region(reg, x, y) && cansee(x, y)) + newsym(x, y); free_region(reg); regions[i] = regions[n_regions - 1]; @@ -363,12 +364,12 @@ clear_regions() register int i; for (i = 0; i < n_regions; i++) - free_region(regions[i]); + free_region(regions[i]); n_regions = 0; if (max_regions > 0) - free((genericptr_t) regions); + free((genericptr_t) regions); max_regions = 0; - regions = (NhRegion **)0; + regions = (NhRegion **) 0; } /* @@ -385,37 +386,38 @@ run_regions() /* End of life ? */ /* Do it backward because the array will be modified */ for (i = n_regions - 1; i >= 0; i--) { - if (regions[i]->ttl == 0L) { - if ((f_indx = regions[i]->expire_f) == NO_CALLBACK || - (*callbacks[f_indx])(regions[i], (genericptr_t) 0)) - remove_region(regions[i]); - } + if (regions[i]->ttl == 0L) { + if ((f_indx = regions[i]->expire_f) == NO_CALLBACK + || (*callbacks[f_indx])(regions[i], (genericptr_t) 0)) + remove_region(regions[i]); + } } /* Process remaining regions */ for (i = 0; i < n_regions; i++) { - /* Make the region age */ - if (regions[i]->ttl > 0L) - regions[i]->ttl--; - /* Check if player is inside region */ - f_indx = regions[i]->inside_f; - if (f_indx != NO_CALLBACK && hero_inside(regions[i])) - (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); - /* Check if any monster is inside region */ - if (f_indx != NO_CALLBACK) { - for (j = 0; j < regions[i]->n_monst; j++) { - struct monst *mtmp = find_mid(regions[i]->monsters[j], FM_FMON); + /* Make the region age */ + if (regions[i]->ttl > 0L) + regions[i]->ttl--; + /* Check if player is inside region */ + f_indx = regions[i]->inside_f; + if (f_indx != NO_CALLBACK && hero_inside(regions[i])) + (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); + /* Check if any monster is inside region */ + if (f_indx != NO_CALLBACK) { + for (j = 0; j < regions[i]->n_monst; j++) { + struct monst *mtmp = + find_mid(regions[i]->monsters[j], FM_FMON); - if (!mtmp || mtmp->mhp <= 0 || - (*callbacks[f_indx])(regions[i], mtmp)) { - /* The monster died, remove it from list */ - k = (regions[i]->n_monst -= 1); - regions[i]->monsters[j] = regions[i]->monsters[k]; - regions[i]->monsters[k] = 0; - --j; /* current slot has been reused; recheck it next */ - } - } - } + if (!mtmp || mtmp->mhp <= 0 + || (*callbacks[f_indx])(regions[i], mtmp)) { + /* The monster died, remove it from list */ + k = (regions[i]->n_monst -= 1); + regions[i]->monsters[j] = regions[i]->monsters[k]; + regions[i]->monsters[k] = 0; + --j; /* current slot has been reused; recheck it next */ + } + } + } } } @@ -424,49 +426,46 @@ run_regions() */ boolean in_out_region(x, y) -xchar - x, y; +xchar x, y; { int i, f_indx; /* First check if we can do the move */ for (i = 0; i < n_regions; i++) { - if (inside_region(regions[i], x, y) - && !hero_inside(regions[i]) && !regions[i]->attach_2_u) { - if ((f_indx = regions[i]->can_enter_f) != NO_CALLBACK) - if (!(*callbacks[f_indx])(regions[i], (genericptr_t) 0)) - return FALSE; - } else - if (hero_inside(regions[i]) - && !inside_region(regions[i], x, y) - && !regions[i]->attach_2_u) { - if ((f_indx = regions[i]->can_leave_f) != NO_CALLBACK) - if (!(*callbacks[f_indx])(regions[i], (genericptr_t) 0)) - return FALSE; - } + if (inside_region(regions[i], x, y) && !hero_inside(regions[i]) + && !regions[i]->attach_2_u) { + if ((f_indx = regions[i]->can_enter_f) != NO_CALLBACK) + if (!(*callbacks[f_indx])(regions[i], (genericptr_t) 0)) + return FALSE; + } else if (hero_inside(regions[i]) && !inside_region(regions[i], x, y) + && !regions[i]->attach_2_u) { + if ((f_indx = regions[i]->can_leave_f) != NO_CALLBACK) + if (!(*callbacks[f_indx])(regions[i], (genericptr_t) 0)) + return FALSE; + } } /* Callbacks for the regions we do leave */ for (i = 0; i < n_regions; i++) - if (hero_inside(regions[i]) && - !regions[i]->attach_2_u && !inside_region(regions[i], x, y)) { - clear_hero_inside(regions[i]); - if (regions[i]->leave_msg != (const char *)0) - pline1(regions[i]->leave_msg); - if ((f_indx = regions[i]->leave_f) != NO_CALLBACK) - (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); - } + if (hero_inside(regions[i]) && !regions[i]->attach_2_u + && !inside_region(regions[i], x, y)) { + clear_hero_inside(regions[i]); + if (regions[i]->leave_msg != (const char *) 0) + pline1(regions[i]->leave_msg); + if ((f_indx = regions[i]->leave_f) != NO_CALLBACK) + (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); + } /* Callbacks for the regions we do enter */ for (i = 0; i < n_regions; i++) - if (!hero_inside(regions[i]) && - !regions[i]->attach_2_u && inside_region(regions[i], x, y)) { - set_hero_inside(regions[i]); - if (regions[i]->enter_msg != (const char *)0) - pline1(regions[i]->enter_msg); - if ((f_indx = regions[i]->enter_f) != NO_CALLBACK) - (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); - } + if (!hero_inside(regions[i]) && !regions[i]->attach_2_u + && inside_region(regions[i], x, y)) { + set_hero_inside(regions[i]); + if (regions[i]->enter_msg != (const char *) 0) + pline1(regions[i]->enter_msg); + if ((f_indx = regions[i]->enter_f) != NO_CALLBACK) + (void) (*callbacks[f_indx])(regions[i], (genericptr_t) 0); + } return TRUE; } @@ -482,39 +481,38 @@ xchar x, y; /* First check if we can do the move */ for (i = 0; i < n_regions; i++) { - if (inside_region(regions[i], x, y) && - !mon_in_region(regions[i], mon) && - regions[i]->attach_2_m != mon->m_id) { - if ((f_indx = regions[i]->can_enter_f) != NO_CALLBACK) - if (!(*callbacks[f_indx])(regions[i], mon)) - return FALSE; - } else if (mon_in_region(regions[i], mon) && - !inside_region(regions[i], x, y) && - regions[i]->attach_2_m != mon->m_id) { - if ((f_indx = regions[i]->can_leave_f) != NO_CALLBACK) - if (!(*callbacks[f_indx])(regions[i], mon)) - return FALSE; - } + if (inside_region(regions[i], x, y) && !mon_in_region(regions[i], mon) + && regions[i]->attach_2_m != mon->m_id) { + if ((f_indx = regions[i]->can_enter_f) != NO_CALLBACK) + if (!(*callbacks[f_indx])(regions[i], mon)) + return FALSE; + } else if (mon_in_region(regions[i], mon) + && !inside_region(regions[i], x, y) + && regions[i]->attach_2_m != mon->m_id) { + if ((f_indx = regions[i]->can_leave_f) != NO_CALLBACK) + if (!(*callbacks[f_indx])(regions[i], mon)) + return FALSE; + } } /* Callbacks for the regions we do leave */ for (i = 0; i < n_regions; i++) - if (mon_in_region(regions[i], mon) && - regions[i]->attach_2_m != mon->m_id && - !inside_region(regions[i], x, y)) { - remove_mon_from_reg(regions[i], mon); - if ((f_indx = regions[i]->leave_f) != NO_CALLBACK) - (void) (*callbacks[f_indx])(regions[i], mon); - } + if (mon_in_region(regions[i], mon) + && regions[i]->attach_2_m != mon->m_id + && !inside_region(regions[i], x, y)) { + remove_mon_from_reg(regions[i], mon); + if ((f_indx = regions[i]->leave_f) != NO_CALLBACK) + (void) (*callbacks[f_indx])(regions[i], mon); + } /* Callbacks for the regions we do enter */ for (i = 0; i < n_regions; i++) - if (!hero_inside(regions[i]) && - !regions[i]->attach_2_u && inside_region(regions[i], x, y)) { - add_mon_to_reg(regions[i], mon); - if ((f_indx = regions[i]->enter_f) != NO_CALLBACK) - (void) (*callbacks[f_indx])(regions[i], mon); - } + if (!hero_inside(regions[i]) && !regions[i]->attach_2_u + && inside_region(regions[i], x, y)) { + add_mon_to_reg(regions[i], mon); + if ((f_indx = regions[i]->enter_f) != NO_CALLBACK) + (void) (*callbacks[f_indx])(regions[i], mon); + } return TRUE; } @@ -527,10 +525,10 @@ update_player_regions() register int i; for (i = 0; i < n_regions; i++) - if (!regions[i]->attach_2_u && inside_region(regions[i], u.ux, u.uy)) - set_hero_inside(regions[i]); - else - clear_hero_inside(regions[i]); + if (!regions[i]->attach_2_u && inside_region(regions[i], u.ux, u.uy)) + set_hero_inside(regions[i]); + else + clear_hero_inside(regions[i]); } /* @@ -543,13 +541,13 @@ struct monst *mon; register int i; for (i = 0; i < n_regions; i++) { - if (inside_region(regions[i], mon->mx, mon->my)) { - if (!mon_in_region(regions[i], mon)) - add_mon_to_reg(regions[i], mon); - } else { - if (mon_in_region(regions[i], mon)) - remove_mon_from_reg(regions[i], mon); - } + if (inside_region(regions[i], mon->mx, mon->my)) { + if (!mon_in_region(regions[i], mon)) + add_mon_to_reg(regions[i], mon); + } else { + if (mon_in_region(regions[i], mon)) + remove_mon_from_reg(regions[i], mon); + } } } @@ -588,7 +586,7 @@ struct monst *mon; remove_mon_from_reg(regions[i], mon); } -#endif /*0*/ +#endif /*0*/ /* * Check if a spot is under a visible region (eg: gas cloud). @@ -601,9 +599,9 @@ xchar x, y; register int i; for (i = 0; i < n_regions; i++) - if (inside_region(regions[i], x, y) && regions[i]->visible && - regions[i]->ttl != -2L) - return regions[i]; + if (inside_region(regions[i], x, y) && regions[i]->visible + && regions[i]->ttl != -2L) + return regions[i]; return (NhRegion *) 0; } @@ -626,48 +624,52 @@ int mode; int i, j; unsigned n; - if (!perform_bwrite(mode)) goto skip_lots; + if (!perform_bwrite(mode)) + goto skip_lots; - bwrite(fd, (genericptr_t) &moves, sizeof (moves)); /* timestamp */ - bwrite(fd, (genericptr_t) &n_regions, sizeof (n_regions)); + bwrite(fd, (genericptr_t) &moves, sizeof(moves)); /* timestamp */ + bwrite(fd, (genericptr_t) &n_regions, sizeof(n_regions)); for (i = 0; i < n_regions; i++) { - bwrite(fd, (genericptr_t) ®ions[i]->bounding_box, sizeof (NhRect)); - bwrite(fd, (genericptr_t) ®ions[i]->nrects, sizeof (short)); - for (j = 0; j < regions[i]->nrects; j++) - bwrite(fd, (genericptr_t) ®ions[i]->rects[j], sizeof (NhRect)); - bwrite(fd, (genericptr_t) ®ions[i]->attach_2_u, sizeof (boolean)); - n = 0; - bwrite(fd, (genericptr_t) ®ions[i]->attach_2_m, sizeof (unsigned)); - n = regions[i]->enter_msg != (const char *)0 ? - strlen(regions[i]->enter_msg) : 0; - bwrite(fd, (genericptr_t) &n, sizeof n); - if (n > 0) - bwrite(fd, (genericptr_t) regions[i]->enter_msg, n); - n = regions[i]->leave_msg != (const char *)0 ? - strlen(regions[i]->leave_msg) : 0; - bwrite(fd, (genericptr_t) &n, sizeof n); - if (n > 0) - bwrite(fd, (genericptr_t) regions[i]->leave_msg, n); - bwrite(fd, (genericptr_t) ®ions[i]->ttl, sizeof (long)); - bwrite(fd, (genericptr_t) ®ions[i]->expire_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->can_enter_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->enter_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->can_leave_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->leave_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->inside_f, sizeof (short)); - bwrite(fd, (genericptr_t) ®ions[i]->player_flags, sizeof (unsigned int)); - bwrite(fd, (genericptr_t) ®ions[i]->n_monst, sizeof (short)); - for (j = 0; j < regions[i]->n_monst; j++) - bwrite(fd, (genericptr_t) ®ions[i]->monsters[j], - sizeof (unsigned)); - bwrite(fd, (genericptr_t) ®ions[i]->visible, sizeof (boolean)); - bwrite(fd, (genericptr_t) ®ions[i]->glyph, sizeof (int)); - bwrite(fd, (genericptr_t) ®ions[i]->arg, sizeof (anything)); + bwrite(fd, (genericptr_t) ®ions[i]->bounding_box, sizeof(NhRect)); + bwrite(fd, (genericptr_t) ®ions[i]->nrects, sizeof(short)); + for (j = 0; j < regions[i]->nrects; j++) + bwrite(fd, (genericptr_t) ®ions[i]->rects[j], sizeof(NhRect)); + bwrite(fd, (genericptr_t) ®ions[i]->attach_2_u, sizeof(boolean)); + n = 0; + bwrite(fd, (genericptr_t) ®ions[i]->attach_2_m, sizeof(unsigned)); + n = regions[i]->enter_msg != (const char *) 0 + ? strlen(regions[i]->enter_msg) + : 0; + bwrite(fd, (genericptr_t) &n, sizeof n); + if (n > 0) + bwrite(fd, (genericptr_t) regions[i]->enter_msg, n); + n = regions[i]->leave_msg != (const char *) 0 + ? strlen(regions[i]->leave_msg) + : 0; + bwrite(fd, (genericptr_t) &n, sizeof n); + if (n > 0) + bwrite(fd, (genericptr_t) regions[i]->leave_msg, n); + bwrite(fd, (genericptr_t) ®ions[i]->ttl, sizeof(long)); + bwrite(fd, (genericptr_t) ®ions[i]->expire_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->can_enter_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->enter_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->can_leave_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->leave_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->inside_f, sizeof(short)); + bwrite(fd, (genericptr_t) ®ions[i]->player_flags, + sizeof(unsigned int)); + bwrite(fd, (genericptr_t) ®ions[i]->n_monst, sizeof(short)); + for (j = 0; j < regions[i]->n_monst; j++) + bwrite(fd, (genericptr_t) ®ions[i]->monsters[j], + sizeof(unsigned)); + bwrite(fd, (genericptr_t) ®ions[i]->visible, sizeof(boolean)); + bwrite(fd, (genericptr_t) ®ions[i]->glyph, sizeof(int)); + bwrite(fd, (genericptr_t) ®ions[i]->arg, sizeof(anything)); } skip_lots: if (release_data(mode)) - clear_regions(); + clear_regions(); } void @@ -680,82 +682,85 @@ boolean ghostly; /* If a bones file restore */ long tmstamp; char *msg_buf; - clear_regions(); /* Just for security */ - mread(fd, (genericptr_t) &tmstamp, sizeof (tmstamp)); - if (ghostly) tmstamp = 0; - else tmstamp = (moves - tmstamp); - mread(fd, (genericptr_t) &n_regions, sizeof (n_regions)); + clear_regions(); /* Just for security */ + mread(fd, (genericptr_t) &tmstamp, sizeof(tmstamp)); + if (ghostly) + tmstamp = 0; + else + tmstamp = (moves - tmstamp); + mread(fd, (genericptr_t) &n_regions, sizeof(n_regions)); max_regions = n_regions; if (n_regions > 0) - regions = (NhRegion **) alloc(sizeof (NhRegion *) * n_regions); + regions = (NhRegion **) alloc(sizeof(NhRegion *) * n_regions); for (i = 0; i < n_regions; i++) { - regions[i] = (NhRegion *) alloc(sizeof (NhRegion)); - mread(fd, (genericptr_t) ®ions[i]->bounding_box, sizeof (NhRect)); - mread(fd, (genericptr_t) ®ions[i]->nrects, sizeof (short)); + regions[i] = (NhRegion *) alloc(sizeof(NhRegion)); + mread(fd, (genericptr_t) ®ions[i]->bounding_box, sizeof(NhRect)); + mread(fd, (genericptr_t) ®ions[i]->nrects, sizeof(short)); - if (regions[i]->nrects > 0) - regions[i]->rects = (NhRect *) - alloc(sizeof (NhRect) * regions[i]->nrects); - for (j = 0; j < regions[i]->nrects; j++) - mread(fd, (genericptr_t) ®ions[i]->rects[j], sizeof (NhRect)); - mread(fd, (genericptr_t) ®ions[i]->attach_2_u, sizeof (boolean)); - mread(fd, (genericptr_t) ®ions[i]->attach_2_m, sizeof (unsigned)); + if (regions[i]->nrects > 0) + regions[i]->rects = + (NhRect *) alloc(sizeof(NhRect) * regions[i]->nrects); + for (j = 0; j < regions[i]->nrects; j++) + mread(fd, (genericptr_t) ®ions[i]->rects[j], sizeof(NhRect)); + mread(fd, (genericptr_t) ®ions[i]->attach_2_u, sizeof(boolean)); + mread(fd, (genericptr_t) ®ions[i]->attach_2_m, sizeof(unsigned)); - mread(fd, (genericptr_t) &n, sizeof n); - if (n > 0) { - msg_buf = (char *) alloc(n + 1); - mread(fd, (genericptr_t) msg_buf, n); - msg_buf[n] = '\0'; - regions[i]->enter_msg = (const char *) msg_buf; - } else - regions[i]->enter_msg = (const char *)0; + mread(fd, (genericptr_t) &n, sizeof n); + if (n > 0) { + msg_buf = (char *) alloc(n + 1); + mread(fd, (genericptr_t) msg_buf, n); + msg_buf[n] = '\0'; + regions[i]->enter_msg = (const char *) msg_buf; + } else + regions[i]->enter_msg = (const char *) 0; - mread(fd, (genericptr_t) &n, sizeof n); - if (n > 0) { - msg_buf = (char *) alloc(n + 1); - mread(fd, (genericptr_t) msg_buf, n); - msg_buf[n] = '\0'; - regions[i]->leave_msg = (const char *) msg_buf; - } else - regions[i]->leave_msg = (const char *)0; + mread(fd, (genericptr_t) &n, sizeof n); + if (n > 0) { + msg_buf = (char *) alloc(n + 1); + mread(fd, (genericptr_t) msg_buf, n); + msg_buf[n] = '\0'; + regions[i]->leave_msg = (const char *) msg_buf; + } else + regions[i]->leave_msg = (const char *) 0; - mread(fd, (genericptr_t) ®ions[i]->ttl, sizeof (long)); - /* check for expired region */ - if (regions[i]->ttl >= 0L) - regions[i]->ttl = - (regions[i]->ttl > tmstamp) ? regions[i]->ttl - tmstamp : 0L; - mread(fd, (genericptr_t) ®ions[i]->expire_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->can_enter_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->enter_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->can_leave_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->leave_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->inside_f, sizeof (short)); - mread(fd, (genericptr_t) ®ions[i]->player_flags, sizeof (unsigned int)); - if (ghostly) { /* settings pertained to old player */ - clear_hero_inside(regions[i]); - clear_heros_fault(regions[i]); - } - mread(fd, (genericptr_t) ®ions[i]->n_monst, sizeof (short)); - if (regions[i]->n_monst > 0) - regions[i]->monsters = - (unsigned *) alloc(sizeof (unsigned) * regions[i]->n_monst); - else - regions[i]->monsters = (unsigned int *)0; - regions[i]->max_monst = regions[i]->n_monst; - for (j = 0; j < regions[i]->n_monst; j++) - mread(fd, (genericptr_t) ®ions[i]->monsters[j], - sizeof (unsigned)); - mread(fd, (genericptr_t) ®ions[i]->visible, sizeof (boolean)); - mread(fd, (genericptr_t) ®ions[i]->glyph, sizeof (int)); - mread(fd, (genericptr_t) ®ions[i]->arg, sizeof (anything)); + mread(fd, (genericptr_t) ®ions[i]->ttl, sizeof(long)); + /* check for expired region */ + if (regions[i]->ttl >= 0L) + regions[i]->ttl = + (regions[i]->ttl > tmstamp) ? regions[i]->ttl - tmstamp : 0L; + mread(fd, (genericptr_t) ®ions[i]->expire_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->can_enter_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->enter_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->can_leave_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->leave_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->inside_f, sizeof(short)); + mread(fd, (genericptr_t) ®ions[i]->player_flags, + sizeof(unsigned int)); + if (ghostly) { /* settings pertained to old player */ + clear_hero_inside(regions[i]); + clear_heros_fault(regions[i]); + } + mread(fd, (genericptr_t) ®ions[i]->n_monst, sizeof(short)); + if (regions[i]->n_monst > 0) + regions[i]->monsters = + (unsigned *) alloc(sizeof(unsigned) * regions[i]->n_monst); + else + regions[i]->monsters = (unsigned int *) 0; + regions[i]->max_monst = regions[i]->n_monst; + for (j = 0; j < regions[i]->n_monst; j++) + mread(fd, (genericptr_t) ®ions[i]->monsters[j], + sizeof(unsigned)); + mread(fd, (genericptr_t) ®ions[i]->visible, sizeof(boolean)); + mread(fd, (genericptr_t) ®ions[i]->glyph, sizeof(int)); + mread(fd, (genericptr_t) ®ions[i]->arg, sizeof(anything)); } /* remove expired regions, do not trigger the expire_f callback (yet!); also update monster lists if this data is coming from a bones file */ for (i = n_regions - 1; i >= 0; i--) - if (regions[i]->ttl == 0L) - remove_region(regions[i]); - else if (ghostly && regions[i]->n_monst > 0) - reset_region_mids(regions[i]); + if (regions[i]->ttl == 0L) + remove_region(regions[i]); + else if (ghostly && regions[i]->n_monst > 0) + reset_region_mids(regions[i]); } /* update monster IDs for region being loaded from bones; `ghostly' implied */ @@ -767,13 +772,13 @@ NhRegion *reg; unsigned *mid_list = reg->monsters; while (i < n) - if (!lookup_id_mapping(mid_list[i], &mid_list[i])) { - /* shrink list to remove missing monster; order doesn't matter */ - mid_list[i] = mid_list[--n]; - } else { - /* move on to next monster */ - ++i; - } + if (!lookup_id_mapping(mid_list[i], &mid_list[i])) { + /* shrink list to remove missing monster; order doesn't matter */ + mid_list[i] = mid_list[--n]; + } else { + /* move on to next monster */ + ++i; + } reg->n_monst = n; return; } @@ -872,7 +877,7 @@ long ttl; return ff; } -#endif /*0*/ +#endif /*0*/ /*--------------------------------------------------------------* * * @@ -898,13 +903,13 @@ genericptr_t p2 UNUSED; /* If it was a thick cloud, it dissipates a little first */ if (damage >= 5) { - damage /= 2; /* It dissipates, let's do less damage */ - reg->arg = zeroany; - reg->arg.a_int = damage; - reg->ttl = 2L; /* Here's the trick : reset ttl */ - return FALSE; /* THEN return FALSE, means "still there" */ + damage /= 2; /* It dissipates, let's do less damage */ + reg->arg = zeroany; + reg->arg.a_int = damage; + reg->ttl = 2L; /* Here's the trick : reset ttl */ + return FALSE; /* THEN return FALSE, means "still there" */ } - return TRUE; /* OK, it's gone, you can free it! */ + return TRUE; /* OK, it's gone, you can free it! */ } boolean @@ -918,51 +923,52 @@ genericptr_t p2; reg = (NhRegion *) p1; dam = reg->arg.a_int; - if (p2 == (genericptr_t)0) { /* This means *YOU* Bozo! */ - if (u.uinvulnerable || nonliving(youmonst.data) || Breathless) - return FALSE; - if (!Blind) { - Your("%s sting.", makeplural(body_part(EYE))); - make_blinded(1L, FALSE); - } - if (!Poison_resistance) { - pline("%s is burning your %s!", - Something, makeplural(body_part(LUNG))); - You("cough and spit blood!"); - losehp(Maybe_Half_Phys(rnd(dam) + 5), "gas cloud", KILLED_BY_AN); - return FALSE; - } else { - You("cough!"); - return FALSE; - } - } else { /* A monster is inside the cloud */ - mtmp = (struct monst *) p2; + if (p2 == (genericptr_t) 0) { /* This means *YOU* Bozo! */ + if (u.uinvulnerable || nonliving(youmonst.data) || Breathless) + return FALSE; + if (!Blind) { + Your("%s sting.", makeplural(body_part(EYE))); + make_blinded(1L, FALSE); + } + if (!Poison_resistance) { + pline("%s is burning your %s!", Something, + makeplural(body_part(LUNG))); + You("cough and spit blood!"); + losehp(Maybe_Half_Phys(rnd(dam) + 5), "gas cloud", KILLED_BY_AN); + return FALSE; + } else { + You("cough!"); + return FALSE; + } + } else { /* A monster is inside the cloud */ + mtmp = (struct monst *) p2; - /* Non living and non breathing monsters are not concerned */ - if (!(nonliving(mtmp->data) || is_vampshifter(mtmp)) - && !breathless(mtmp->data)) { - if (cansee(mtmp->mx, mtmp->my)) - pline("%s coughs!", Monnam(mtmp)); - if (heros_fault(reg)) setmangry(mtmp); - if (haseyes(mtmp->data) && mtmp->mcansee) { - mtmp->mblinded = 1; - mtmp->mcansee = 0; - } - if (resists_poison(mtmp)) - return FALSE; - mtmp->mhp -= rnd(dam) + 5; - if (mtmp->mhp <= 0) { - if (heros_fault(reg)) - killed(mtmp); - else - monkilled(mtmp, "gas cloud", AD_DRST); - if (mtmp->mhp <= 0) { /* not lifesaved */ - return TRUE; - } - } - } + /* Non living and non breathing monsters are not concerned */ + if (!(nonliving(mtmp->data) || is_vampshifter(mtmp)) + && !breathless(mtmp->data)) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s coughs!", Monnam(mtmp)); + if (heros_fault(reg)) + setmangry(mtmp); + if (haseyes(mtmp->data) && mtmp->mcansee) { + mtmp->mblinded = 1; + mtmp->mcansee = 0; + } + if (resists_poison(mtmp)) + return FALSE; + mtmp->mhp -= rnd(dam) + 5; + if (mtmp->mhp <= 0) { + if (heros_fault(reg)) + killed(mtmp); + else + monkilled(mtmp, "gas cloud", AD_DRST); + if (mtmp->mhp <= 0) { /* not lifesaved */ + return TRUE; + } + } + } } - return FALSE; /* Monster is still alive */ + return FALSE; /* Monster is still alive */ } NhRegion * @@ -982,15 +988,15 @@ int damage; tmprect.ly = y - (radius - 1); tmprect.hy = y + (radius - 1); for (i = 0; i < nrect; i++) { - add_rect_to_reg(cloud, &tmprect); - tmprect.lx--; - tmprect.hx++; - tmprect.ly++; - tmprect.hy--; + add_rect_to_reg(cloud, &tmprect); + tmprect.lx--; + tmprect.hx++; + tmprect.ly++; + tmprect.hy--; } - cloud->ttl = rn1(3,4); + cloud->ttl = rn1(3, 4); if (!in_mklev && !context.mon_moving) - set_heros_fault(cloud); /* assume player has created it */ + set_heros_fault(cloud); /* assume player has created it */ cloud->inside_f = INSIDE_GAS_CLOUD; cloud->expire_f = EXPIRE_GAS_CLOUD; cloud->arg = zeroany; @@ -1008,18 +1014,21 @@ region_danger() int i, f_indx, n = 0; for (i = 0; i < n_regions; i++) { - /* only care about regions that hero is in */ - if (!hero_inside(regions[i])) continue; - f_indx = regions[i]->inside_f; - /* the only type of region we understand is gas_cloud */ - if (f_indx == INSIDE_GAS_CLOUD) { - /* completely harmless if you don't need to breathe */ - if (nonliving(youmonst.data) || Breathless) continue; - /* minor inconvenience if you're posion resistant; - not harmful enough to be a prayer-level trouble */ - if (Poison_resistance) continue; - ++n; - } + /* only care about regions that hero is in */ + if (!hero_inside(regions[i])) + continue; + f_indx = regions[i]->inside_f; + /* the only type of region we understand is gas_cloud */ + if (f_indx == INSIDE_GAS_CLOUD) { + /* completely harmless if you don't need to breathe */ + if (nonliving(youmonst.data) || Breathless) + continue; + /* minor inconvenience if you're posion resistant; + not harmful enough to be a prayer-level trouble */ + if (Poison_resistance) + continue; + ++n; + } } return n ? TRUE : FALSE; } @@ -1033,27 +1042,30 @@ region_safety() int i, f_indx, n = 0; for (i = 0; i < n_regions; i++) { - /* only care about regions that hero is in */ - if (!hero_inside(regions[i])) continue; - f_indx = regions[i]->inside_f; - /* the only type of region we understand is gas_cloud */ - if (f_indx == INSIDE_GAS_CLOUD) { - if (!n++ && regions[i]->ttl >= 0) r = regions[i]; - } + /* only care about regions that hero is in */ + if (!hero_inside(regions[i])) + continue; + f_indx = regions[i]->inside_f; + /* the only type of region we understand is gas_cloud */ + if (f_indx == INSIDE_GAS_CLOUD) { + if (!n++ && regions[i]->ttl >= 0) + r = regions[i]; + } } if (n > 1 || (n == 1 && !r)) { - /* multiple overlapping cloud regions or non-expiring one */ - safe_teleds(FALSE); + /* multiple overlapping cloud regions or non-expiring one */ + safe_teleds(FALSE); } else if (r) { - remove_region(r); - pline_The("gas cloud enveloping you dissipates."); + remove_region(r); + pline_The("gas cloud enveloping you dissipates."); } else { - /* cloud dissipated on its own, so nothing needs to be done */ - pline_The("gas cloud has dissipated."); + /* cloud dissipated on its own, so nothing needs to be done */ + pline_The("gas cloud has dissipated."); } /* maybe cure blindness too */ - if ((Blinded & TIMEOUT) == 1L) make_blinded(0L, TRUE); + if ((Blinded & TIMEOUT) == 1L) + make_blinded(0L, TRUE); } /*region.c*/ diff --git a/src/restore.c b/src/restore.c index 89a9c51c0..daf04e0be 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 restore.c $NHDT-Date: 1429757270 2015/04/23 02:47:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.93 $ */ +/* NetHack 3.6 restore.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.97 $ */ /* NetHack 3.6 restore.c $Date: 2012/02/16 02:40:24 $ $Revision: 1.71 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,57 +8,52 @@ #include "tcap.h" /* for TERMLIB and ASCIIGRAPH */ #if defined(MICRO) -extern int dotcnt; /* shared with save */ -extern int dotrow; /* shared with save */ +extern int dotcnt; /* shared with save */ +extern int dotrow; /* shared with save */ #endif #ifdef USE_TILES -extern void FDECL(substitute_tiles, (d_level *)); /* from tile.c */ +extern void FDECL(substitute_tiles, (d_level *)); /* from tile.c */ #endif #ifdef ZEROCOMP STATIC_DCL void NDECL(zerocomp_minit); -STATIC_DCL void FDECL(zerocomp_mread, (int,genericptr_t,unsigned int)); +STATIC_DCL void FDECL(zerocomp_mread, (int, genericptr_t, unsigned int)); STATIC_DCL int NDECL(zerocomp_mgetc); #endif STATIC_DCL void NDECL(def_minit); -STATIC_DCL void FDECL(def_mread, (int,genericptr_t,unsigned int)); +STATIC_DCL void FDECL(def_mread, (int, genericptr_t, unsigned int)); STATIC_DCL void NDECL(find_lev_obj); STATIC_DCL void FDECL(restlevchn, (int)); -STATIC_DCL void FDECL(restdamage, (int,BOOLEAN_P)); +STATIC_DCL void FDECL(restdamage, (int, BOOLEAN_P)); STATIC_DCL void FDECL(restobj, (int, struct obj *)); -STATIC_DCL struct obj *FDECL(restobjchn, (int,BOOLEAN_P,BOOLEAN_P)); +STATIC_DCL struct obj *FDECL(restobjchn, (int, BOOLEAN_P, BOOLEAN_P)); STATIC_OVL void FDECL(restmon, (int, struct monst *)); -STATIC_DCL struct monst *FDECL(restmonchn, (int,BOOLEAN_P)); +STATIC_DCL struct monst *FDECL(restmonchn, (int, BOOLEAN_P)); STATIC_DCL struct fruit *FDECL(loadfruitchn, (int)); STATIC_DCL void FDECL(freefruitchn, (struct fruit *)); STATIC_DCL void FDECL(ghostfruit, (struct obj *)); -STATIC_DCL boolean FDECL(restgamestate, (int, unsigned int *, unsigned int *)); +STATIC_DCL boolean +FDECL(restgamestate, (int, unsigned int *, unsigned int *)); STATIC_DCL void FDECL(restlevelstate, (unsigned int, unsigned int)); -STATIC_DCL int FDECL(restlevelfile, (int,XCHAR_P)); +STATIC_DCL int FDECL(restlevelfile, (int, XCHAR_P)); STATIC_OVL void FDECL(restore_msghistory, (int)); STATIC_DCL void FDECL(reset_oattached_mids, (BOOLEAN_P)); -STATIC_DCL void FDECL(rest_levl, (int,BOOLEAN_P)); +STATIC_DCL void FDECL(rest_levl, (int, BOOLEAN_P)); static struct restore_procs { - const char *name; - int mread_flags; - void NDECL((*restore_minit)); - void FDECL((*restore_mread), (int,genericptr_t,unsigned int)); - void FDECL((*restore_bclose), (int)); + const char *name; + int mread_flags; + void NDECL((*restore_minit)); + void FDECL((*restore_mread), (int, genericptr_t, unsigned int)); + void FDECL((*restore_bclose), (int)); } restoreprocs = { #if !defined(ZEROCOMP) || (defined(COMPRESS) || defined(ZLIB_COMP)) - "externalcomp", 0, - def_minit, - def_mread, - def_bclose, + "externalcomp", 0, def_minit, def_mread, def_bclose, #else - "zerocomp", 0, - zerocomp_minit, - zerocomp_mread, - zerocomp_bclose, + "zerocomp", 0, zerocomp_minit, zerocomp_mread, zerocomp_bclose, #endif }; @@ -70,8 +65,8 @@ static struct restore_procs { struct bucket { struct bucket *next; struct { - unsigned gid; /* ghost ID */ - unsigned nid; /* new ID */ + unsigned gid; /* ghost ID */ + unsigned nid; /* new ID */ } map[N_PER_BUCKET]; }; @@ -81,9 +76,8 @@ STATIC_DCL void FDECL(add_id_mapping, (unsigned, unsigned)); static int n_ids_mapped = 0; static struct bucket *id_map = 0; - #ifdef AMII_GRAPHICS -void FDECL( amii_setpens, (int) ); /* use colors from save file */ +void FDECL(amii_setpens, (int)); /* use colors from save file */ extern int amii_numcolors; #endif @@ -99,31 +93,32 @@ static NEARDATA long omoves; STATIC_OVL void find_lev_obj() { - register struct obj *fobjtmp = (struct obj *)0; - register struct obj *otmp; - int x,y; + register struct obj *fobjtmp = (struct obj *) 0; + register struct obj *otmp; + int x, y; - for(x=0; xnobj; - otmp->nobj = fobjtmp; - otmp->where = OBJ_FREE; - fobjtmp = otmp; - } - /* fobj should now be empty */ + /* + * Reverse the entire fobj chain, which is necessary so that we can + * place the objects in the proper order. Make all obj in chain + * OBJ_FREE so place_object will work correctly. + */ + while ((otmp = fobj) != 0) { + fobj = otmp->nobj; + otmp->nobj = fobjtmp; + otmp->where = OBJ_FREE; + fobjtmp = otmp; + } + /* fobj should now be empty */ - /* Set level.objects (as well as reversing the chain back again) */ - while ((otmp = fobjtmp) != 0) { - fobjtmp = otmp->nobj; - place_object(otmp, otmp->ox, otmp->oy); - } + /* Set level.objects (as well as reversing the chain back again) */ + while ((otmp = fobjtmp) != 0) { + fobjtmp = otmp->nobj; + place_object(otmp, otmp->ox, otmp->oy); + } } /* Things that were marked "in_use" when the game was saved (ex. via the @@ -133,38 +128,39 @@ void inven_inuse(quietly) boolean quietly; { - register struct obj *otmp, *otmp2; + register struct obj *otmp, *otmp2; - for (otmp = invent; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (otmp->in_use) { - if (!quietly) pline("Finishing off %s...", xname(otmp)); - useup(otmp); - } - } + for (otmp = invent; otmp; otmp = otmp2) { + otmp2 = otmp->nobj; + if (otmp->in_use) { + if (!quietly) + pline("Finishing off %s...", xname(otmp)); + useup(otmp); + } + } } STATIC_OVL void restlevchn(fd) register int fd; { - int cnt; - s_level *tmplev, *x; + int cnt; + s_level *tmplev, *x; - sp_levchn = (s_level *) 0; - mread(fd, (genericptr_t) &cnt, sizeof(int)); - for(; cnt > 0; cnt--) { - - tmplev = (s_level *)alloc(sizeof(s_level)); - mread(fd, (genericptr_t) tmplev, sizeof(s_level)); - if(!sp_levchn) sp_levchn = tmplev; - else { - - for(x = sp_levchn; x->next; x = x->next); - x->next = tmplev; - } - tmplev->next = (s_level *)0; - } + sp_levchn = (s_level *) 0; + mread(fd, (genericptr_t) &cnt, sizeof(int)); + for (; cnt > 0; cnt--) { + tmplev = (s_level *) alloc(sizeof(s_level)); + mread(fd, (genericptr_t) tmplev, sizeof(s_level)); + if (!sp_levchn) + sp_levchn = tmplev; + else { + for (x = sp_levchn; x->next; x = x->next) + ; + x->next = tmplev; + } + tmplev->next = (s_level *) 0; + } } STATIC_OVL void @@ -172,42 +168,42 @@ restdamage(fd, ghostly) int fd; boolean ghostly; { - int counter; - struct damage *tmp_dam; + int counter; + struct damage *tmp_dam; - mread(fd, (genericptr_t) &counter, sizeof(counter)); - if (!counter) - return; - tmp_dam = (struct damage *)alloc(sizeof(struct damage)); - while (--counter >= 0) { - char damaged_shops[5], *shp = (char *)0; + mread(fd, (genericptr_t) &counter, sizeof(counter)); + if (!counter) + return; + tmp_dam = (struct damage *) alloc(sizeof(struct damage)); + while (--counter >= 0) { + char damaged_shops[5], *shp = (char *) 0; - mread(fd, (genericptr_t) tmp_dam, sizeof(*tmp_dam)); - if (ghostly) - tmp_dam->when += (monstermoves - omoves); - Strcpy(damaged_shops, - in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); - if (u.uz.dlevel) { - /* when restoring, there are two passes over the current - * level. the first time, u.uz isn't set, so neither is - * shop_keeper(). just wait and process the damage on - * the second pass. - */ - for (shp = damaged_shops; *shp; shp++) { - struct monst *shkp = shop_keeper(*shp); + mread(fd, (genericptr_t) tmp_dam, sizeof(*tmp_dam)); + if (ghostly) + tmp_dam->when += (monstermoves - omoves); + Strcpy(damaged_shops, + in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); + if (u.uz.dlevel) { + /* when restoring, there are two passes over the current + * level. the first time, u.uz isn't set, so neither is + * shop_keeper(). just wait and process the damage on + * the second pass. + */ + for (shp = damaged_shops; *shp; shp++) { + struct monst *shkp = shop_keeper(*shp); - if (shkp && inhishop(shkp) && - repair_damage(shkp, tmp_dam, TRUE)) - break; - } - } - if (!shp || !*shp) { - tmp_dam->next = level.damagelist; - level.damagelist = tmp_dam; - tmp_dam = (struct damage *)alloc(sizeof(*tmp_dam)); - } - } - free((genericptr_t)tmp_dam); + if (shkp && inhishop(shkp) + && repair_damage(shkp, tmp_dam, TRUE)) + break; + } + } + if (!shp || !*shp) { + tmp_dam->next = level.damagelist; + level.damagelist = tmp_dam; + tmp_dam = (struct damage *) alloc(sizeof(*tmp_dam)); + } + } + free((genericptr_t) tmp_dam); } /* restore one object */ @@ -216,53 +212,53 @@ restobj(fd, otmp) int fd; struct obj *otmp; { - int buflen; + int buflen; - mread(fd, (genericptr_t) otmp, sizeof(struct obj)); + mread(fd, (genericptr_t) otmp, sizeof(struct obj)); - /* next object pointers are invalid; otmp->cobj needs to be left - as is--being non-null is key to restoring container contents */ - otmp->nobj = otmp->nexthere = (struct obj *)0; - /* non-null oextra needs to be reconstructed */ - if (otmp->oextra) { - otmp->oextra = newoextra(); + /* next object pointers are invalid; otmp->cobj needs to be left + as is--being non-null is key to restoring container contents */ + otmp->nobj = otmp->nexthere = (struct obj *) 0; + /* non-null oextra needs to be reconstructed */ + if (otmp->oextra) { + otmp->oextra = newoextra(); - /* oname - object's name */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { /* includes terminating '\0' */ - new_oname(otmp, buflen); - mread(fd, (genericptr_t) ONAME(otmp), buflen); - } - /* omonst - corpse or statue might retain full monster details */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { - newomonst(otmp); - /* this is actually a monst struct, so we - can just defer to restmon() here */ - restmon(fd, OMONST(otmp)); - } - /* omid - monster id number, connecting corpse to ghost */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { - newomid(otmp); - mread(fd, (genericptr_t) OMID(otmp), buflen); - } - /* olong - temporary gold */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { - newolong(otmp); - mread(fd, (genericptr_t) OLONG(otmp), buflen); - } - /* omailcmd - feedback mechanism for scroll of mail */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { - char *omailcmd = (char *)alloc(buflen); + /* oname - object's name */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { /* includes terminating '\0' */ + new_oname(otmp, buflen); + mread(fd, (genericptr_t) ONAME(otmp), buflen); + } + /* omonst - corpse or statue might retain full monster details */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newomonst(otmp); + /* this is actually a monst struct, so we + can just defer to restmon() here */ + restmon(fd, OMONST(otmp)); + } + /* omid - monster id number, connecting corpse to ghost */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newomid(otmp); + mread(fd, (genericptr_t) OMID(otmp), buflen); + } + /* olong - temporary gold */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newolong(otmp); + mread(fd, (genericptr_t) OLONG(otmp), buflen); + } + /* omailcmd - feedback mechanism for scroll of mail */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + char *omailcmd = (char *) alloc(buflen); - mread(fd, (genericptr_t) omailcmd, buflen); - new_omailcmd(otmp, omailcmd); - free((genericptr_t)omailcmd); - } - } + mread(fd, (genericptr_t) omailcmd, buflen); + new_omailcmd(otmp, omailcmd); + free((genericptr_t) omailcmd); + } + } } STATIC_OVL struct obj * @@ -270,58 +266,63 @@ restobjchn(fd, ghostly, frozen) register int fd; boolean ghostly, frozen; { - register struct obj *otmp, *otmp2 = 0; - register struct obj *first = (struct obj *)0; - int buflen; + register struct obj *otmp, *otmp2 = 0; + register struct obj *first = (struct obj *) 0; + int buflen; - while(1) { - mread(fd, (genericptr_t) &buflen, sizeof buflen); - if(buflen == -1) break; + while (1) { + mread(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen == -1) + break; - otmp = newobj(); - restobj(fd, otmp); - if(!first) first = otmp; - else otmp2->nobj = otmp; + otmp = newobj(); + restobj(fd, otmp); + if (!first) + first = otmp; + else + otmp2->nobj = otmp; - if (ghostly) { - unsigned nid = context.ident++; - add_id_mapping(otmp->o_id, nid); - otmp->o_id = nid; - } - if (ghostly && otmp->otyp == SLIME_MOLD) ghostfruit(otmp); - /* Ghost levels get object age shifted from old player's clock - * to new player's clock. Assumption: new player arrived - * immediately after old player died. - */ - if (ghostly && !frozen && !age_is_relative(otmp)) - otmp->age = monstermoves - omoves + otmp->age; + if (ghostly) { + unsigned nid = context.ident++; + add_id_mapping(otmp->o_id, nid); + otmp->o_id = nid; + } + if (ghostly && otmp->otyp == SLIME_MOLD) + ghostfruit(otmp); + /* Ghost levels get object age shifted from old player's clock + * to new player's clock. Assumption: new player arrived + * immediately after old player died. + */ + if (ghostly && !frozen && !age_is_relative(otmp)) + otmp->age = monstermoves - omoves + otmp->age; - /* get contents of a container or statue */ - if (Has_contents(otmp)) { - struct obj *otmp3; - otmp->cobj = restobjchn(fd, ghostly, Is_IceBox(otmp)); - /* restore container back pointers */ - for (otmp3 = otmp->cobj; otmp3; otmp3 = otmp3->nobj) - otmp3->ocontainer = otmp; - } - if (otmp->bypass) otmp->bypass = 0; - if (!ghostly) { - /* fix the pointers */ - if (otmp->o_id == context.victual.o_id) - context.victual.piece = otmp; - if (otmp->o_id == context.tin.o_id) - context.tin.tin = otmp; - if (otmp->o_id == context.spbook.o_id) - context.spbook.book = otmp; - } - otmp2 = otmp; - } - if(first && otmp2->nobj){ - impossible("Restobjchn: error reading objchn."); - otmp2->nobj = 0; - } + /* get contents of a container or statue */ + if (Has_contents(otmp)) { + struct obj *otmp3; + otmp->cobj = restobjchn(fd, ghostly, Is_IceBox(otmp)); + /* restore container back pointers */ + for (otmp3 = otmp->cobj; otmp3; otmp3 = otmp3->nobj) + otmp3->ocontainer = otmp; + } + if (otmp->bypass) + otmp->bypass = 0; + if (!ghostly) { + /* fix the pointers */ + if (otmp->o_id == context.victual.o_id) + context.victual.piece = otmp; + if (otmp->o_id == context.tin.o_id) + context.tin.tin = otmp; + if (otmp->o_id == context.spbook.o_id) + context.spbook.book = otmp; + } + otmp2 = otmp; + } + if (first && otmp2->nobj) { + impossible("Restobjchn: error reading objchn."); + otmp2->nobj = 0; + } - return(first); + return (first); } /* restore one monster */ @@ -330,57 +331,56 @@ restmon(fd, mtmp) int fd; struct monst *mtmp; { - int buflen; + int buflen; - mread(fd, (genericptr_t) mtmp, sizeof(struct monst)); + mread(fd, (genericptr_t) mtmp, sizeof(struct monst)); - /* next monster pointer is invalid */ - mtmp->nmon = (struct monst *)0; - /* non-null mextra needs to be reconstructed */ - if (mtmp->mextra) { - mtmp->mextra = newmextra(); + /* next monster pointer is invalid */ + mtmp->nmon = (struct monst *) 0; + /* non-null mextra needs to be reconstructed */ + if (mtmp->mextra) { + mtmp->mextra = newmextra(); - /* mname - monster's name */ - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if (buflen > 0) { /* includes terminating '\0' */ - new_mname(mtmp, buflen); - mread(fd, (genericptr_t) MNAME(mtmp), buflen); - } - /* egd - vault guard */ - mread(fd, (genericptr_t) &buflen, sizeof (buflen)); - if (buflen > 0) { - newegd(mtmp); - mread(fd, (genericptr_t) EGD(mtmp), sizeof (struct egd)); - } - /* epri - temple priest */ - mread(fd, (genericptr_t) &buflen, sizeof (buflen)); - if (buflen > 0) { - newepri(mtmp); - mread(fd, (genericptr_t) EPRI(mtmp), sizeof (struct epri)); - } - /* eshk - shopkeeper */ - mread(fd, (genericptr_t) &buflen, sizeof (buflen)); - if (buflen > 0) { - neweshk(mtmp); - mread(fd, (genericptr_t) ESHK(mtmp), sizeof (struct eshk)); - } - /* emin - minion */ - mread(fd, (genericptr_t) &buflen, sizeof (buflen)); - if (buflen > 0) { - newemin(mtmp); - mread(fd, (genericptr_t) EMIN(mtmp), sizeof (struct emin)); - } - /* edog - pet */ - mread(fd, (genericptr_t) &buflen, sizeof (buflen)); - if (buflen > 0) { - newedog(mtmp); - mread(fd, (genericptr_t) EDOG(mtmp), sizeof (struct edog)); - } - /* mcorpsenm - obj->corpsenm for mimic posing as corpse or - statue (inline int rather than pointer to something) */ - mread(fd, (genericptr_t) &MCORPSENM(mtmp), - sizeof MCORPSENM(mtmp)); - } /* mextra */ + /* mname - monster's name */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { /* includes terminating '\0' */ + new_mname(mtmp, buflen); + mread(fd, (genericptr_t) MNAME(mtmp), buflen); + } + /* egd - vault guard */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newegd(mtmp); + mread(fd, (genericptr_t) EGD(mtmp), sizeof(struct egd)); + } + /* epri - temple priest */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newepri(mtmp); + mread(fd, (genericptr_t) EPRI(mtmp), sizeof(struct epri)); + } + /* eshk - shopkeeper */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + neweshk(mtmp); + mread(fd, (genericptr_t) ESHK(mtmp), sizeof(struct eshk)); + } + /* emin - minion */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newemin(mtmp); + mread(fd, (genericptr_t) EMIN(mtmp), sizeof(struct emin)); + } + /* edog - pet */ + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen > 0) { + newedog(mtmp); + mread(fd, (genericptr_t) EDOG(mtmp), sizeof(struct edog)); + } + /* mcorpsenm - obj->corpsenm for mimic posing as corpse or + statue (inline int rather than pointer to something) */ + mread(fd, (genericptr_t) &MCORPSENM(mtmp), sizeof MCORPSENM(mtmp)); + } /* mextra */ } STATIC_OVL struct monst * @@ -388,112 +388,120 @@ restmonchn(fd, ghostly) register int fd; boolean ghostly; { - register struct monst *mtmp, *mtmp2 = 0; - register struct monst *first = (struct monst *)0; - int offset, buflen; + register struct monst *mtmp, *mtmp2 = 0; + register struct monst *first = (struct monst *) 0; + int offset, buflen; - while(1) { - mread(fd, (genericptr_t) &buflen, sizeof(buflen)); - if(buflen == -1) break; + while (1) { + mread(fd, (genericptr_t) &buflen, sizeof(buflen)); + if (buflen == -1) + break; - mtmp = newmonst(); - restmon(fd, mtmp); - if(!first) first = mtmp; - else mtmp2->nmon = mtmp; + mtmp = newmonst(); + restmon(fd, mtmp); + if (!first) + first = mtmp; + else + mtmp2->nmon = mtmp; - if (ghostly) { - unsigned nid = context.ident++; - add_id_mapping(mtmp->m_id, nid); - mtmp->m_id = nid; - } - offset = mtmp->mnum; - mtmp->data = &mons[offset]; - if (ghostly) { - int mndx = monsndx(mtmp->data); - if (propagate(mndx, TRUE, ghostly) == 0) { - /* cookie to trigger purge in getbones() */ - mtmp->mhpmax = DEFUNCT_MONSTER; - } - } - if(mtmp->minvent) { - struct obj *obj; - mtmp->minvent = restobjchn(fd, ghostly, FALSE); - /* restore monster back pointer */ - for (obj = mtmp->minvent; obj; obj = obj->nobj) - obj->ocarry = mtmp; - } - if (mtmp->mw) { - struct obj *obj; + if (ghostly) { + unsigned nid = context.ident++; + add_id_mapping(mtmp->m_id, nid); + mtmp->m_id = nid; + } + offset = mtmp->mnum; + mtmp->data = &mons[offset]; + if (ghostly) { + int mndx = monsndx(mtmp->data); + if (propagate(mndx, TRUE, ghostly) == 0) { + /* cookie to trigger purge in getbones() */ + mtmp->mhpmax = DEFUNCT_MONSTER; + } + } + if (mtmp->minvent) { + struct obj *obj; + mtmp->minvent = restobjchn(fd, ghostly, FALSE); + /* restore monster back pointer */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) + obj->ocarry = mtmp; + } + if (mtmp->mw) { + struct obj *obj; - for(obj = mtmp->minvent; obj; obj = obj->nobj) - if (obj->owornmask & W_WEP) break; - if (obj) mtmp->mw = obj; - else { - MON_NOWEP(mtmp); - impossible("bad monster weapon restore"); - } - } + for (obj = mtmp->minvent; obj; obj = obj->nobj) + if (obj->owornmask & W_WEP) + break; + if (obj) + mtmp->mw = obj; + else { + MON_NOWEP(mtmp); + impossible("bad monster weapon restore"); + } + } - if (mtmp->isshk) restshk(mtmp, ghostly); - if (mtmp->ispriest) restpriest(mtmp, ghostly); + if (mtmp->isshk) + restshk(mtmp, ghostly); + if (mtmp->ispriest) + restpriest(mtmp, ghostly); - if (!ghostly) { - if (mtmp->m_id == context.polearm.m_id) - context.polearm.hitmon = mtmp; - } - mtmp2 = mtmp; - } - if(first && mtmp2->nmon){ - impossible("Restmonchn: error reading monchn."); - mtmp2->nmon = 0; - } - return(first); + if (!ghostly) { + if (mtmp->m_id == context.polearm.m_id) + context.polearm.hitmon = mtmp; + } + mtmp2 = mtmp; + } + if (first && mtmp2->nmon) { + impossible("Restmonchn: error reading monchn."); + mtmp2->nmon = 0; + } + return (first); } STATIC_OVL struct fruit * loadfruitchn(fd) int fd; { - register struct fruit *flist, *fnext; + register struct fruit *flist, *fnext; - flist = 0; - while (fnext = newfruit(), - mread(fd, (genericptr_t)fnext, sizeof *fnext), - fnext->fid != 0) { - fnext->nextf = flist; - flist = fnext; - } - dealloc_fruit(fnext); - return flist; + flist = 0; + while (fnext = newfruit(), mread(fd, (genericptr_t) fnext, sizeof *fnext), + fnext->fid != 0) { + fnext->nextf = flist; + flist = fnext; + } + dealloc_fruit(fnext); + return flist; } STATIC_OVL void freefruitchn(flist) register struct fruit *flist; { - register struct fruit *fnext; + register struct fruit *fnext; - while (flist) { - fnext = flist->nextf; - dealloc_fruit(flist); - flist = fnext; - } + while (flist) { + fnext = flist->nextf; + dealloc_fruit(flist); + flist = fnext; + } } STATIC_OVL void ghostfruit(otmp) register struct obj *otmp; { - register struct fruit *oldf; + register struct fruit *oldf; - for (oldf = oldfruit; oldf; oldf = oldf->nextf) - if (oldf->fid == otmp->spe) break; + for (oldf = oldfruit; oldf; oldf = oldf->nextf) + if (oldf->fid == otmp->spe) + break; - if (!oldf) impossible("no old fruit?"); - else otmp->spe = fruitadd(oldf->fname, (struct fruit *)0); + if (!oldf) + impossible("no old fruit?"); + else + otmp->spe = fruitadd(oldf->fname, (struct fruit *) 0); } - #ifdef SYSCF #define SYSOPT_CHECK_SAVE_UID sysopt.check_save_uid #else @@ -506,161 +514,161 @@ restgamestate(fd, stuckid, steedid) register int fd; unsigned int *stuckid, *steedid; { - struct flag newgameflags; + struct flag newgameflags; #ifdef SYSFLAGS - struct sysflag newgamesysflags; + struct sysflag newgamesysflags; #endif - struct obj *otmp, *tmp_bc; - char timebuf[15]; - unsigned long uid; + struct obj *otmp, *tmp_bc; + char timebuf[15]; + unsigned long uid; - mread(fd, (genericptr_t) &uid, sizeof uid); - if (SYSOPT_CHECK_SAVE_UID && uid != (unsigned long)getuid()) { /* strange ... */ - /* for wizard mode, issue a reminder; for others, treat it - as an attempt to cheat and refuse to restore this file */ - pline("Saved game was not yours."); - if (!wizard) - return FALSE; - } - mread(fd, (genericptr_t) &context, sizeof(struct context_info)); - if (context.warntype.speciesidx) - context.warntype.species = &mons[context.warntype.speciesidx]; + mread(fd, (genericptr_t) &uid, sizeof uid); + if (SYSOPT_CHECK_SAVE_UID + && uid != (unsigned long) getuid()) { /* strange ... */ + /* for wizard mode, issue a reminder; for others, treat it + as an attempt to cheat and refuse to restore this file */ + pline("Saved game was not yours."); + if (!wizard) + return FALSE; + } + mread(fd, (genericptr_t) &context, sizeof(struct context_info)); + if (context.warntype.speciesidx) + context.warntype.species = &mons[context.warntype.speciesidx]; - /* we want to be able to revert to command line/environment/config - file option values instead of keeping old save file option values - if partial restore fails and we resort to starting a new game */ - newgameflags = flags; - mread(fd, (genericptr_t) &flags, sizeof(struct flag)); - /* wizard and discover are actually flags.debug and flags.explore; - player might be overriding the save file values for them; - in the discover case, we don't want to set that for a normal - game until after the save file has been removed */ - iflags.deferred_X = (newgameflags.explore && !discover); - if (newgameflags.debug) { - /* authorized by startup code; wizard mode exists and is allowed */ - wizard = TRUE, discover = iflags.deferred_X = FALSE; - } else if (wizard) { - /* specified by save file; check authorization now */ - set_playmode(); - } + /* we want to be able to revert to command line/environment/config + file option values instead of keeping old save file option values + if partial restore fails and we resort to starting a new game */ + newgameflags = flags; + mread(fd, (genericptr_t) &flags, sizeof(struct flag)); + /* wizard and discover are actually flags.debug and flags.explore; + player might be overriding the save file values for them; + in the discover case, we don't want to set that for a normal + game until after the save file has been removed */ + iflags.deferred_X = (newgameflags.explore && !discover); + if (newgameflags.debug) { + /* authorized by startup code; wizard mode exists and is allowed */ + wizard = TRUE, discover = iflags.deferred_X = FALSE; + } else if (wizard) { + /* specified by save file; check authorization now */ + set_playmode(); + } #ifdef SYSFLAGS - newgamesysflags = sysflags; - mread(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); + newgamesysflags = sysflags; + mread(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); #endif - role_init(); /* Reset the initial role, race, gender, and alignment */ + role_init(); /* Reset the initial role, race, gender, and alignment */ #ifdef AMII_GRAPHICS - amii_setpens(amii_numcolors); /* use colors from save file */ + amii_setpens(amii_numcolors); /* use colors from save file */ #endif - mread(fd, (genericptr_t) &u, sizeof(struct you)); + mread(fd, (genericptr_t) &u, sizeof(struct you)); -#define ReadTimebuf(foo) mread(fd, (genericptr_t) timebuf, 14); \ - timebuf[14] = '\0'; \ +#define ReadTimebuf(foo) \ + mread(fd, (genericptr_t) timebuf, 14); \ + timebuf[14] = '\0'; \ foo = time_from_yyyymmddhhmmss(timebuf); - ReadTimebuf(ubirthday); - mread(fd, &urealtime.realtime, sizeof(urealtime.realtime)); - ReadTimebuf(urealtime.restored); + ReadTimebuf(ubirthday); + mread(fd, &urealtime.realtime, sizeof(urealtime.realtime)); + ReadTimebuf(urealtime.restored); #if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *)&urealtime.restored); + (void) time((long *) &urealtime.restored); #else - (void) time(&urealtime.restored); + (void) time(&urealtime.restored); #endif - - set_uasmon(); + set_uasmon(); #ifdef CLIPPING - cliparound(u.ux, u.uy); + cliparound(u.ux, u.uy); #endif - if(u.uhp <= 0 && (!Upolyd || u.mh <= 0)) { - u.ux = u.uy = 0; /* affects pline() [hence You()] */ - You("were not healthy enough to survive restoration."); - /* wiz1_level.dlevel is used by mklev.c to see if lots of stuff is - * uninitialized, so we only have to set it and not the other stuff. - */ - wiz1_level.dlevel = 0; - u.uz.dnum = 0; - u.uz.dlevel = 1; - /* revert to pre-restore option settings */ - iflags.deferred_X = FALSE; - flags = newgameflags; + if (u.uhp <= 0 && (!Upolyd || u.mh <= 0)) { + u.ux = u.uy = 0; /* affects pline() [hence You()] */ + You("were not healthy enough to survive restoration."); + /* wiz1_level.dlevel is used by mklev.c to see if lots of stuff is + * uninitialized, so we only have to set it and not the other stuff. + */ + wiz1_level.dlevel = 0; + u.uz.dnum = 0; + u.uz.dlevel = 1; + /* revert to pre-restore option settings */ + iflags.deferred_X = FALSE; + flags = newgameflags; #ifdef SYSFLAGS - sysflags = newgamesysflags; + sysflags = newgamesysflags; #endif - return(FALSE); - } - /* in case hangup save occurred in midst of level change */ - assign_level(&u.uz0, &u.uz); + return (FALSE); + } + /* in case hangup save occurred in midst of level change */ + assign_level(&u.uz0, &u.uz); - /* this stuff comes after potential aborted restore attempts */ - restore_killers(fd); - restore_timers(fd, RANGE_GLOBAL, FALSE, 0L); - restore_light_sources(fd); - invent = restobjchn(fd, FALSE, FALSE); - /* tmp_bc only gets set here if the ball & chain were orphaned - because you were swallowed; otherwise they will be on the floor - or in your inventory */ - tmp_bc = restobjchn(fd, FALSE, FALSE); - if (tmp_bc) { - for(otmp = tmp_bc; otmp; otmp = otmp->nobj) { - if(otmp->owornmask) - setworn(otmp, otmp->owornmask); - } - if (!uball || !uchain) - impossible("restgamestate: lost ball & chain"); - } + /* this stuff comes after potential aborted restore attempts */ + restore_killers(fd); + restore_timers(fd, RANGE_GLOBAL, FALSE, 0L); + restore_light_sources(fd); + invent = restobjchn(fd, FALSE, FALSE); + /* tmp_bc only gets set here if the ball & chain were orphaned + because you were swallowed; otherwise they will be on the floor + or in your inventory */ + tmp_bc = restobjchn(fd, FALSE, FALSE); + if (tmp_bc) { + for (otmp = tmp_bc; otmp; otmp = otmp->nobj) { + if (otmp->owornmask) + setworn(otmp, otmp->owornmask); + } + if (!uball || !uchain) + impossible("restgamestate: lost ball & chain"); + } - migrating_objs = restobjchn(fd, FALSE, FALSE); - migrating_mons = restmonchn(fd, FALSE); - mread(fd, (genericptr_t) mvitals, sizeof(mvitals)); + migrating_objs = restobjchn(fd, FALSE, FALSE); + migrating_mons = restmonchn(fd, FALSE); + mread(fd, (genericptr_t) mvitals, sizeof(mvitals)); - /* - * There are some things after this that can have unintended display - * side-effects too early in the game. - * Disable see_monsters() here, re-enable it at the top of moveloop() - */ - defer_see_monsters = TRUE; + /* + * There are some things after this that can have unintended display + * side-effects too early in the game. + * Disable see_monsters() here, re-enable it at the top of moveloop() + */ + defer_see_monsters = TRUE; - /* this comes after inventory has been loaded */ - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->owornmask) - setworn(otmp, otmp->owornmask); - /* reset weapon so that player will get a reminder about "bashing" - during next fight when bare-handed or wielding an unconventional - item; for pick-axe, we aren't able to distinguish between having - applied or wielded it, so be conservative and assume the former */ - otmp = uwep; /* `uwep' usually init'd by setworn() in loop above */ - uwep = 0; /* clear it and have setuwep() reinit */ - setuwep(otmp); /* (don't need any null check here) */ - if (!uwep || uwep->otyp == PICK_AXE || uwep->otyp == GRAPPLING_HOOK) - unweapon = TRUE; + /* this comes after inventory has been loaded */ + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->owornmask) + setworn(otmp, otmp->owornmask); + /* reset weapon so that player will get a reminder about "bashing" + during next fight when bare-handed or wielding an unconventional + item; for pick-axe, we aren't able to distinguish between having + applied or wielded it, so be conservative and assume the former */ + otmp = uwep; /* `uwep' usually init'd by setworn() in loop above */ + uwep = 0; /* clear it and have setuwep() reinit */ + setuwep(otmp); /* (don't need any null check here) */ + if (!uwep || uwep->otyp == PICK_AXE || uwep->otyp == GRAPPLING_HOOK) + unweapon = TRUE; - restore_dungeon(fd); - restlevchn(fd); - mread(fd, (genericptr_t) &moves, sizeof moves); - mread(fd, (genericptr_t) &monstermoves, sizeof monstermoves); - mread(fd, (genericptr_t) &quest_status, sizeof(struct q_score)); - mread(fd, (genericptr_t) spl_book, - sizeof(struct spell) * (MAXSPELL + 1)); - restore_artifacts(fd); - restore_oracles(fd); - if (u.ustuck) - mread(fd, (genericptr_t) stuckid, sizeof (*stuckid)); - if (u.usteed) - mread(fd, (genericptr_t) steedid, sizeof (*steedid)); - mread(fd, (genericptr_t) pl_character, sizeof pl_character); + restore_dungeon(fd); + restlevchn(fd); + mread(fd, (genericptr_t) &moves, sizeof moves); + mread(fd, (genericptr_t) &monstermoves, sizeof monstermoves); + mread(fd, (genericptr_t) &quest_status, sizeof(struct q_score)); + mread(fd, (genericptr_t) spl_book, sizeof(struct spell) * (MAXSPELL + 1)); + restore_artifacts(fd); + restore_oracles(fd); + if (u.ustuck) + mread(fd, (genericptr_t) stuckid, sizeof(*stuckid)); + if (u.usteed) + mread(fd, (genericptr_t) steedid, sizeof(*steedid)); + mread(fd, (genericptr_t) pl_character, sizeof pl_character); - mread(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); - freefruitchn(ffruit); /* clean up fruit(s) made by initoptions() */ - ffruit = loadfruitchn(fd); + mread(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); + freefruitchn(ffruit); /* clean up fruit(s) made by initoptions() */ + ffruit = loadfruitchn(fd); - restnames(fd); - restore_waterlevel(fd); - restore_msghistory(fd); - /* must come after all mons & objs are restored */ - relink_timers(FALSE); - relink_light_sources(FALSE); - return(TRUE); + restnames(fd); + restore_waterlevel(fd); + restore_msghistory(fd); + /* must come after all mons & objs are restored */ + relink_timers(FALSE); + relink_light_sources(FALSE); + return (TRUE); } /* update game state pointers to those valid for the current level (so we @@ -670,222 +678,226 @@ STATIC_OVL void restlevelstate(stuckid, steedid) unsigned int stuckid, steedid; { - register struct monst *mtmp; + register struct monst *mtmp; - if (stuckid) { - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (mtmp->m_id == stuckid) break; - if (!mtmp) panic("Cannot find the monster ustuck."); - u.ustuck = mtmp; - } - if (steedid) { - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if (mtmp->m_id == steedid) break; - if (!mtmp) panic("Cannot find the monster usteed."); - u.usteed = mtmp; - remove_monster(mtmp->mx, mtmp->my); - } + if (stuckid) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (mtmp->m_id == stuckid) + break; + if (!mtmp) + panic("Cannot find the monster ustuck."); + u.ustuck = mtmp; + } + if (steedid) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (mtmp->m_id == steedid) + break; + if (!mtmp) + panic("Cannot find the monster usteed."); + u.usteed = mtmp; + remove_monster(mtmp->mx, mtmp->my); + } } -/*ARGSUSED*/ /* fd used in MFLOPPY only */ -STATIC_OVL int -restlevelfile(fd, ltmp) -register int fd; +/*ARGSUSED*/ /* fd used in MFLOPPY only */ +STATIC_OVL int restlevelfile(fd, ltmp) register int fd; xchar ltmp; -#if defined(macintosh) && (defined(__SC__) || defined(__MRC__)) && !defined(MFLOPPY) -# pragma unused(fd) +#if defined(macintosh) && (defined(__SC__) || defined(__MRC__)) \ + && !defined(MFLOPPY) +#pragma unused(fd) #endif { - register int nfd; - char whynot[BUFSZ]; + register int nfd; + char whynot[BUFSZ]; - nfd = create_levelfile(ltmp, whynot); - if (nfd < 0) { - /* BUG: should suppress any attempt to write a panic - save file if file creation is now failing... */ - panic("restlevelfile: %s", whynot); - } + nfd = create_levelfile(ltmp, whynot); + if (nfd < 0) { + /* BUG: should suppress any attempt to write a panic + save file if file creation is now failing... */ + panic("restlevelfile: %s", whynot); + } #ifdef MFLOPPY - if (!savelev(nfd, ltmp, COUNT_SAVE)) { + if (!savelev(nfd, ltmp, COUNT_SAVE)) { + /* The savelev can't proceed because the size required + * is greater than the available disk space. + */ + pline("Not enough space on `%s' to restore your game.", levels); - /* The savelev can't proceed because the size required - * is greater than the available disk space. - */ - pline("Not enough space on `%s' to restore your game.", - levels); + /* Remove levels and bones that may have been created. + */ + (void) nhclose(nfd); +#ifdef AMIGA + clearlocks(); +#else + eraseall(levels, alllevels); + eraseall(levels, allbones); - /* Remove levels and bones that may have been created. - */ - (void) nhclose(nfd); -# ifdef AMIGA - clearlocks(); -# else - eraseall(levels, alllevels); - eraseall(levels, allbones); - - /* Perhaps the person would like to play without a - * RAMdisk. - */ - if (ramdisk) { - /* PlaywoRAMdisk may not return, but if it does - * it is certain that ramdisk will be 0. - */ - playwoRAMdisk(); - /* Rewind save file and try again */ - (void) lseek(fd, (off_t)0, 0); - (void) validate(fd, (char *)0); /* skip version etc */ - return dorecover(fd); /* 0 or 1 */ - } else { -# endif - pline("Be seeing you..."); - terminate(EXIT_SUCCESS); -# ifndef AMIGA - } -# endif - } + /* Perhaps the person would like to play without a + * RAMdisk. + */ + if (ramdisk) { + /* PlaywoRAMdisk may not return, but if it does + * it is certain that ramdisk will be 0. + */ + playwoRAMdisk(); + /* Rewind save file and try again */ + (void) lseek(fd, (off_t) 0, 0); + (void) validate(fd, (char *) 0); /* skip version etc */ + return dorecover(fd); /* 0 or 1 */ + } else { #endif - bufon(nfd); - savelev(nfd, ltmp, WRITE_SAVE | FREE_SAVE); - bclose(nfd); - return(2); + pline("Be seeing you..."); + terminate(EXIT_SUCCESS); +#ifndef AMIGA + } +#endif +} +#endif +bufon(nfd); +savelev(nfd, ltmp, WRITE_SAVE | FREE_SAVE); +bclose(nfd); +return (2); } int dorecover(fd) register int fd; { - unsigned int stuckid = 0, steedid = 0; /* not a register */ - xchar ltmp; - int rtmp; - struct obj *otmp; + unsigned int stuckid = 0, steedid = 0; /* not a register */ + xchar ltmp; + int rtmp; + struct obj *otmp; - restoring = TRUE; - get_plname_from_file(fd, plname); - getlev(fd, 0, (xchar)0, FALSE); - if (!restgamestate(fd, &stuckid, &steedid)) { - display_nhwindow(WIN_MESSAGE, TRUE); - savelev(-1, 0, FREE_SAVE); /* discard current level */ - (void) nhclose(fd); - (void) delete_savefile(); - restoring = FALSE; - return(0); - } - restlevelstate(stuckid, steedid); + restoring = TRUE; + get_plname_from_file(fd, plname); + getlev(fd, 0, (xchar) 0, FALSE); + if (!restgamestate(fd, &stuckid, &steedid)) { + display_nhwindow(WIN_MESSAGE, TRUE); + savelev(-1, 0, FREE_SAVE); /* discard current level */ + (void) nhclose(fd); + (void) delete_savefile(); + restoring = FALSE; + return (0); + } + restlevelstate(stuckid, steedid); #ifdef INSURANCE - savestateinlock(); + savestateinlock(); #endif - rtmp = restlevelfile(fd, ledger_no(&u.uz)); - if (rtmp < 2) return(rtmp); /* dorecover called recursively */ + rtmp = restlevelfile(fd, ledger_no(&u.uz)); + if (rtmp < 2) + return (rtmp); /* dorecover called recursively */ - /* these pointers won't be valid while we're processing the - * other levels, but they'll be reset again by restlevelstate() - * afterwards, and in the meantime at least u.usteed may mislead - * place_monster() on other levels - */ - u.ustuck = (struct monst *)0; - u.usteed = (struct monst *)0; + /* these pointers won't be valid while we're processing the + * other levels, but they'll be reset again by restlevelstate() + * afterwards, and in the meantime at least u.usteed may mislead + * place_monster() on other levels + */ + u.ustuck = (struct monst *) 0; + u.usteed = (struct monst *) 0; #ifdef MICRO -# ifdef AMII_GRAPHICS - { - extern struct window_procs amii_procs; - if(windowprocs.win_init_nhwindows== amii_procs.win_init_nhwindows){ - extern winid WIN_BASE; - clear_nhwindow(WIN_BASE); /* hack until there's a hook for this */ - } - } -# else - clear_nhwindow(WIN_MAP); -# endif - clear_nhwindow(WIN_MESSAGE); - You("return to level %d in %s%s.", - depth(&u.uz), dungeons[u.uz.dnum].dname, - flags.debug ? " while in debug mode" : - flags.explore ? " while in explore mode" : ""); - curs(WIN_MAP, 1, 1); - dotcnt = 0; - dotrow = 2; - if (strncmpi("X11", windowprocs.name, 3)) - putstr(WIN_MAP, 0, "Restoring:"); +#ifdef AMII_GRAPHICS + { + extern struct window_procs amii_procs; + if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) { + extern winid WIN_BASE; + clear_nhwindow(WIN_BASE); /* hack until there's a hook for this */ + } + } +#else + clear_nhwindow(WIN_MAP); #endif - restoreprocs.mread_flags = 1; /* return despite error */ - while(1) { - mread(fd, (genericptr_t) <mp, sizeof ltmp); - if (restoreprocs.mread_flags == -1) - break; - getlev(fd, 0, ltmp, FALSE); + clear_nhwindow(WIN_MESSAGE); + You("return to level %d in %s%s.", depth(&u.uz), + dungeons[u.uz.dnum].dname, + flags.debug ? " while in debug mode" + : flags.explore ? " while in explore mode" : ""); + curs(WIN_MAP, 1, 1); + dotcnt = 0; + dotrow = 2; + if (strncmpi("X11", windowprocs.name, 3)) + putstr(WIN_MAP, 0, "Restoring:"); +#endif + restoreprocs.mread_flags = 1; /* return despite error */ + while (1) { + mread(fd, (genericptr_t) <mp, sizeof ltmp); + if (restoreprocs.mread_flags == -1) + break; + getlev(fd, 0, ltmp, FALSE); #ifdef MICRO - curs(WIN_MAP, 1+dotcnt++, dotrow); - if (dotcnt >= (COLNO - 1)) { - dotrow++; - dotcnt = 0; - } - if (strncmpi("X11", windowprocs.name, 3)){ - putstr(WIN_MAP, 0, "."); - } - mark_synch(); + curs(WIN_MAP, 1 + dotcnt++, dotrow); + if (dotcnt >= (COLNO - 1)) { + dotrow++; + dotcnt = 0; + } + if (strncmpi("X11", windowprocs.name, 3)) { + putstr(WIN_MAP, 0, "."); + } + mark_synch(); #endif - rtmp = restlevelfile(fd, ltmp); - if (rtmp < 2) return(rtmp); /* dorecover called recursively */ - } - restoreprocs.mread_flags = 0; + rtmp = restlevelfile(fd, ltmp); + if (rtmp < 2) + return (rtmp); /* dorecover called recursively */ + } + restoreprocs.mread_flags = 0; #ifdef BSD - (void) lseek(fd, 0L, 0); + (void) lseek(fd, 0L, 0); #else - (void) lseek(fd, (off_t)0, 0); + (void) lseek(fd, (off_t) 0, 0); #endif - (void) validate(fd, (char *)0); /* skip version and savefile info */ - get_plname_from_file(fd, plname); + (void) validate(fd, (char *) 0); /* skip version and savefile info */ + get_plname_from_file(fd, plname); - getlev(fd, 0, (xchar)0, FALSE); - (void) nhclose(fd); + getlev(fd, 0, (xchar) 0, FALSE); + (void) nhclose(fd); - /* Now set the restore settings to match the - * settings used by the save file output routines - */ - reset_restpref(); + /* Now set the restore settings to match the + * settings used by the save file output routines + */ + reset_restpref(); - restlevelstate(stuckid, steedid); - program_state.something_worth_saving = 1; /* useful data now exists */ + restlevelstate(stuckid, steedid); + program_state.something_worth_saving = 1; /* useful data now exists */ - if (!wizard && !discover) - (void) delete_savefile(); - if (Is_rogue_level(&u.uz)) assign_graphics(ROGUESET); + if (!wizard && !discover) + (void) delete_savefile(); + if (Is_rogue_level(&u.uz)) + assign_graphics(ROGUESET); #ifdef USE_TILES - substitute_tiles(&u.uz); + substitute_tiles(&u.uz); #endif #ifdef MFLOPPY - gameDiskPrompt(); + gameDiskPrompt(); #endif - max_rank_sz(); /* to recompute mrank_sz (botl.c) */ - /* take care of iron ball & chain */ - for(otmp = fobj; otmp; otmp = otmp->nobj) - if(otmp->owornmask) - setworn(otmp, otmp->owornmask); + max_rank_sz(); /* to recompute mrank_sz (botl.c) */ + /* take care of iron ball & chain */ + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otmp->owornmask) + setworn(otmp, otmp->owornmask); - /* in_use processing must be after: - * + The inventory has been read so that freeinv() works. - * + The current level has been restored so billing information - * is available. - */ - inven_inuse(FALSE); + /* in_use processing must be after: + * + The inventory has been read so that freeinv() works. + * + The current level has been restored so billing information + * is available. + */ + inven_inuse(FALSE); - load_qtlist(); /* re-load the quest text info */ - /* Set up the vision internals, after levl[] data is loaded */ - /* but before docrt(). */ - vision_reset(); - vision_full_recalc = 1; /* recompute vision (not saved) */ + load_qtlist(); /* re-load the quest text info */ + /* Set up the vision internals, after levl[] data is loaded */ + /* but before docrt(). */ + vision_reset(); + vision_full_recalc = 1; /* recompute vision (not saved) */ - run_timers(); /* expire all timers that have gone off while away */ - docrt(); - restoring = FALSE; - clear_nhwindow(WIN_MESSAGE); + run_timers(); /* expire all timers that have gone off while away */ + docrt(); + restoring = FALSE; + clear_nhwindow(WIN_MESSAGE); - /* Success! */ - welcome(FALSE); - check_special_room(FALSE); - return(1); + /* Success! */ + welcome(FALSE); + check_special_room(FALSE); + return (1); } void @@ -896,17 +908,17 @@ struct cemetery **cemeteryaddr; struct cemetery *bonesinfo, **bonesaddr; int flag; - mread(fd, (genericptr_t)&flag, sizeof flag); + mread(fd, (genericptr_t) &flag, sizeof flag); if (flag == 0) { - bonesaddr = cemeteryaddr; - do { - bonesinfo = (struct cemetery *)alloc(sizeof *bonesinfo); - mread(fd, (genericptr_t)bonesinfo, sizeof *bonesinfo); - *bonesaddr = bonesinfo; - bonesaddr = &(*bonesaddr)->next; - } while (*bonesaddr); + bonesaddr = cemeteryaddr; + do { + bonesinfo = (struct cemetery *) alloc(sizeof *bonesinfo); + mread(fd, (genericptr_t) bonesinfo, sizeof *bonesinfo); + *bonesaddr = bonesinfo; + bonesaddr = &(*bonesaddr)->next; + } while (*bonesaddr); } else { - *cemeteryaddr = 0; + *cemeteryaddr = 0; } } @@ -917,44 +929,46 @@ int fd; boolean rlecomp; { #ifdef RLECOMP - short i, j; - uchar len; - struct rm r; + short i, j; + uchar len; + struct rm r; - if (rlecomp) { -# if defined(MAC) - /* Suppress warning about used before set */ - (void) memset((genericptr_t) &r, 0, sizeof(r)); -# endif - i = 0; j = 0; len = 0; - while(i < ROWNO) { - while(j < COLNO) { - if(len > 0) { - levl[j][i] = r; - len -= 1; - j += 1; - } else { - mread(fd, (genericptr_t)&len, sizeof(uchar)); - mread(fd, (genericptr_t)&r, sizeof(struct rm)); - } - } - j = 0; - i += 1; - } - } else + if (rlecomp) { +#if defined(MAC) + /* Suppress warning about used before set */ + (void) memset((genericptr_t) &r, 0, sizeof(r)); +#endif + i = 0; + j = 0; + len = 0; + while (i < ROWNO) { + while (j < COLNO) { + if (len > 0) { + levl[j][i] = r; + len -= 1; + j += 1; + } else { + mread(fd, (genericptr_t) &len, sizeof(uchar)); + mread(fd, (genericptr_t) &r, sizeof(struct rm)); + } + } + j = 0; + i += 1; + } + } else #endif /* RLECOMP */ - mread(fd, (genericptr_t) levl, sizeof(levl)); + mread(fd, (genericptr_t) levl, sizeof(levl)); } void trickery(reason) char *reason; { - pline("Strange, this map is not as I remember it."); - pline("Somebody is trying some trickery here..."); - pline("This game is void."); - Strcpy(killer.name, reason ? reason : ""); - done(TRICKED); + pline("Strange, this map is not as I remember it."); + pline("Somebody is trying some trickery here..."); + pline("This game is void."); + Strcpy(killer.name, reason ? reason : ""); + done(TRICKED); } void @@ -963,178 +977,187 @@ int fd, pid; xchar lev; boolean ghostly; { - register struct trap *trap; - register struct monst *mtmp; - long elapsed; - branch *br; - int hpid; - xchar dlvl; - int x, y; + register struct trap *trap; + register struct monst *mtmp; + long elapsed; + branch *br; + int hpid; + xchar dlvl; + int x, y; #ifdef TOS - short tlev; + short tlev; #endif - if (ghostly) - clear_id_mapping(); + if (ghostly) + clear_id_mapping(); #if defined(MSDOS) || defined(OS2) - setmode(fd, O_BINARY); + setmode(fd, O_BINARY); #endif - /* Load the old fruit info. We have to do it first, so the - * information is available when restoring the objects. - */ - if (ghostly) oldfruit = loadfruitchn(fd); + /* Load the old fruit info. We have to do it first, so the + * information is available when restoring the objects. + */ + if (ghostly) + oldfruit = loadfruitchn(fd); - /* First some sanity checks */ - mread(fd, (genericptr_t) &hpid, sizeof(hpid)); + /* First some sanity checks */ + mread(fd, (genericptr_t) &hpid, sizeof(hpid)); /* CHECK: This may prevent restoration */ #ifdef TOS - mread(fd, (genericptr_t) &tlev, sizeof(tlev)); - dlvl=tlev&0x00ff; + mread(fd, (genericptr_t) &tlev, sizeof(tlev)); + dlvl = tlev & 0x00ff; #else - mread(fd, (genericptr_t) &dlvl, sizeof(dlvl)); + mread(fd, (genericptr_t) &dlvl, sizeof(dlvl)); #endif - if ((pid && pid != hpid) || (lev && dlvl != lev)) { - char trickbuf[BUFSZ]; + if ((pid && pid != hpid) || (lev && dlvl != lev)) { + char trickbuf[BUFSZ]; - if (pid && pid != hpid) - Sprintf(trickbuf, "PID (%d) doesn't match saved PID (%d)!", - hpid, pid); - else - Sprintf(trickbuf, "This is level %d, not %d!", dlvl, lev); - if (wizard) pline1(trickbuf); - trickery(trickbuf); - } - restcemetery(fd, &level.bonesinfo); - rest_levl(fd, (boolean)((sfrestinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP)); - mread(fd, (genericptr_t)lastseentyp, sizeof(lastseentyp)); - mread(fd, (genericptr_t)&omoves, sizeof(omoves)); - elapsed = monstermoves - omoves; - mread(fd, (genericptr_t)&upstair, sizeof(stairway)); - mread(fd, (genericptr_t)&dnstair, sizeof(stairway)); - mread(fd, (genericptr_t)&upladder, sizeof(stairway)); - mread(fd, (genericptr_t)&dnladder, sizeof(stairway)); - mread(fd, (genericptr_t)&sstairs, sizeof(stairway)); - mread(fd, (genericptr_t)&updest, sizeof(dest_area)); - mread(fd, (genericptr_t)&dndest, sizeof(dest_area)); - mread(fd, (genericptr_t)&level.flags, sizeof(level.flags)); - mread(fd, (genericptr_t)doors, sizeof(doors)); - rest_rooms(fd); /* No joke :-) */ - if (nroom) - doorindex = rooms[nroom - 1].fdoor + rooms[nroom - 1].doorct; - else - doorindex = 0; + if (pid && pid != hpid) + Sprintf(trickbuf, "PID (%d) doesn't match saved PID (%d)!", hpid, + pid); + else + Sprintf(trickbuf, "This is level %d, not %d!", dlvl, lev); + if (wizard) + pline1(trickbuf); + trickery(trickbuf); + } + restcemetery(fd, &level.bonesinfo); + rest_levl(fd, + (boolean)((sfrestinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP)); + mread(fd, (genericptr_t) lastseentyp, sizeof(lastseentyp)); + mread(fd, (genericptr_t) &omoves, sizeof(omoves)); + elapsed = monstermoves - omoves; + mread(fd, (genericptr_t) &upstair, sizeof(stairway)); + mread(fd, (genericptr_t) &dnstair, sizeof(stairway)); + mread(fd, (genericptr_t) &upladder, sizeof(stairway)); + mread(fd, (genericptr_t) &dnladder, sizeof(stairway)); + mread(fd, (genericptr_t) &sstairs, sizeof(stairway)); + mread(fd, (genericptr_t) &updest, sizeof(dest_area)); + mread(fd, (genericptr_t) &dndest, sizeof(dest_area)); + mread(fd, (genericptr_t) &level.flags, sizeof(level.flags)); + mread(fd, (genericptr_t) doors, sizeof(doors)); + rest_rooms(fd); /* No joke :-) */ + if (nroom) + doorindex = rooms[nroom - 1].fdoor + rooms[nroom - 1].doorct; + else + doorindex = 0; - restore_timers(fd, RANGE_LEVEL, ghostly, elapsed); - restore_light_sources(fd); - fmon = restmonchn(fd, ghostly); + restore_timers(fd, RANGE_LEVEL, ghostly, elapsed); + restore_light_sources(fd); + fmon = restmonchn(fd, ghostly); - rest_worm(fd); /* restore worm information */ - ftrap = 0; - while (trap = newtrap(), - mread(fd, (genericptr_t)trap, sizeof(struct trap)), - trap->tx != 0) { /* need "!= 0" to work around DICE 3.0 bug */ - trap->ntrap = ftrap; - ftrap = trap; - } - dealloc_trap(trap); - fobj = restobjchn(fd, ghostly, FALSE); - find_lev_obj(); - /* restobjchn()'s `frozen' argument probably ought to be a callback - routine so that we can check for objects being buried under ice */ - level.buriedobjlist = restobjchn(fd, ghostly, FALSE); - billobjs = restobjchn(fd, ghostly, FALSE); - rest_engravings(fd); + rest_worm(fd); /* restore worm information */ + ftrap = 0; + while (trap = newtrap(), + mread(fd, (genericptr_t) trap, sizeof(struct trap)), + trap->tx != 0) { /* need "!= 0" to work around DICE 3.0 bug */ + trap->ntrap = ftrap; + ftrap = trap; + } + dealloc_trap(trap); + fobj = restobjchn(fd, ghostly, FALSE); + find_lev_obj(); + /* restobjchn()'s `frozen' argument probably ought to be a callback + routine so that we can check for objects being buried under ice */ + level.buriedobjlist = restobjchn(fd, ghostly, FALSE); + billobjs = restobjchn(fd, ghostly, FALSE); + rest_engravings(fd); - /* reset level.monsters for new level */ - for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - level.monsters[x][y] = (struct monst *) 0; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (mtmp->isshk) set_residency(mtmp, FALSE); - place_monster(mtmp, mtmp->mx, mtmp->my); - if (mtmp->wormno) place_wsegs(mtmp); + /* reset level.monsters for new level */ + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + level.monsters[x][y] = (struct monst *) 0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (mtmp->isshk) + set_residency(mtmp, FALSE); + place_monster(mtmp, mtmp->mx, mtmp->my); + if (mtmp->wormno) + place_wsegs(mtmp); - /* regenerate monsters while on another level */ - if (!u.uz.dlevel) continue; - if (ghostly) { - /* reset peaceful/malign relative to new character; - shopkeepers will reset based on name */ - if (!mtmp->isshk) - mtmp->mpeaceful = (is_unicorn(mtmp->data) && - sgn(u.ualign.type) == sgn(mtmp->data->maligntyp)) ? - TRUE : peace_minded(mtmp->data); - set_malign(mtmp); - } else if (elapsed > 0L) { - mon_catchup_elapsed_time(mtmp, elapsed); - } - /* update shape-changers in case protection against - them is different now than when the level was saved */ - restore_cham(mtmp); - /* give hiders a chance to hide before their next move */ - if (ghostly || elapsed > (long)rnd(10)) hide_monst(mtmp); - } + /* regenerate monsters while on another level */ + if (!u.uz.dlevel) + continue; + if (ghostly) { + /* reset peaceful/malign relative to new character; + shopkeepers will reset based on name */ + if (!mtmp->isshk) + mtmp->mpeaceful = + (is_unicorn(mtmp->data) + && sgn(u.ualign.type) == sgn(mtmp->data->maligntyp)) + ? TRUE + : peace_minded(mtmp->data); + set_malign(mtmp); + } else if (elapsed > 0L) { + mon_catchup_elapsed_time(mtmp, elapsed); + } + /* update shape-changers in case protection against + them is different now than when the level was saved */ + restore_cham(mtmp); + /* give hiders a chance to hide before their next move */ + if (ghostly || elapsed > (long) rnd(10)) + hide_monst(mtmp); + } - restdamage(fd, ghostly); - rest_regions(fd, ghostly); - if (ghostly) { - /* Now get rid of all the temp fruits... */ - freefruitchn(oldfruit), oldfruit = 0; + restdamage(fd, ghostly); + rest_regions(fd, ghostly); + if (ghostly) { + /* Now get rid of all the temp fruits... */ + freefruitchn(oldfruit), oldfruit = 0; - if (lev > ledger_no(&medusa_level) && - lev < ledger_no(&stronghold_level) && xdnstair == 0) { - coord cc; + if (lev > ledger_no(&medusa_level) + && lev < ledger_no(&stronghold_level) && xdnstair == 0) { + coord cc; - mazexy(&cc); - xdnstair = cc.x; - ydnstair = cc.y; - levl[cc.x][cc.y].typ = STAIRS; - } + mazexy(&cc); + xdnstair = cc.x; + ydnstair = cc.y; + levl[cc.x][cc.y].typ = STAIRS; + } - br = Is_branchlev(&u.uz); - if (br && u.uz.dlevel == 1) { - d_level ltmp; + br = Is_branchlev(&u.uz); + if (br && u.uz.dlevel == 1) { + d_level ltmp; - if (on_level(&u.uz, &br->end1)) - assign_level(<mp, &br->end2); - else - assign_level(<mp, &br->end1); + if (on_level(&u.uz, &br->end1)) + assign_level(<mp, &br->end2); + else + assign_level(<mp, &br->end1); - switch(br->type) { - case BR_STAIR: - case BR_NO_END1: - case BR_NO_END2: /* OK to assign to sstairs if it's not used */ - assign_level(&sstairs.tolev, <mp); - break; - case BR_PORTAL: /* max of 1 portal per level */ - { - register struct trap *ttmp; - for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) - if (ttmp->ttyp == MAGIC_PORTAL) - break; - if (!ttmp) panic("getlev: need portal but none found"); - assign_level(&ttmp->dst, <mp); - } - break; - } - } else if (!br) { - /* Remove any dangling portals. */ - register struct trap *ttmp; - for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) - if (ttmp->ttyp == MAGIC_PORTAL) { - deltrap(ttmp); - break; /* max of 1 portal/level */ - } - } - } + switch (br->type) { + case BR_STAIR: + case BR_NO_END1: + case BR_NO_END2: /* OK to assign to sstairs if it's not used */ + assign_level(&sstairs.tolev, <mp); + break; + case BR_PORTAL: /* max of 1 portal per level */ + { + register struct trap *ttmp; + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) + if (ttmp->ttyp == MAGIC_PORTAL) + break; + if (!ttmp) + panic("getlev: need portal but none found"); + assign_level(&ttmp->dst, <mp); + } break; + } + } else if (!br) { + /* Remove any dangling portals. */ + register struct trap *ttmp; + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) + if (ttmp->ttyp == MAGIC_PORTAL) { + deltrap(ttmp); + break; /* max of 1 portal/level */ + } + } + } - /* must come after all mons & objs are restored */ - relink_timers(ghostly); - relink_light_sources(ghostly); - reset_oattached_mids(ghostly); + /* must come after all mons & objs are restored */ + relink_timers(ghostly); + relink_light_sources(ghostly); + reset_oattached_mids(ghostly); - if (ghostly) - clear_id_mapping(); + if (ghostly) + clear_id_mapping(); } void @@ -1142,31 +1165,33 @@ get_plname_from_file(fd, plbuf) int fd; char *plbuf; { - int pltmpsiz = 0; - (void) read(fd, (genericptr_t) &pltmpsiz, sizeof(pltmpsiz)); - (void) read(fd, (genericptr_t) plbuf, pltmpsiz); - return; + int pltmpsiz = 0; + (void) read(fd, (genericptr_t) &pltmpsiz, sizeof(pltmpsiz)); + (void) read(fd, (genericptr_t) plbuf, pltmpsiz); + return; } STATIC_OVL void restore_msghistory(fd) register int fd; { - int msgsize, msgcount = 0; - char msg[BUFSZ]; + int msgsize, msgcount = 0; + char msg[BUFSZ]; - while(1) { - mread(fd, (genericptr_t) &msgsize, sizeof(msgsize)); - if(msgsize == -1) break; - if (msgsize > (BUFSZ - 1)) - panic("restore_msghistory: msg too big (%d)", msgsize); - mread(fd, (genericptr_t)msg, msgsize); - msg[msgsize] = '\0'; - putmsghistory(msg, TRUE); - ++msgcount; - } - if (msgcount) putmsghistory((char *)0, TRUE); - debugpline1("Read %d messages from savefile.", msgcount); + while (1) { + mread(fd, (genericptr_t) &msgsize, sizeof(msgsize)); + if (msgsize == -1) + break; + if (msgsize > (BUFSZ - 1)) + panic("restore_msghistory: msg too big (%d)", msgsize); + mread(fd, (genericptr_t) msg, msgsize); + msg[msgsize] = '\0'; + putmsghistory(msg, TRUE); + ++msgcount; + } + if (msgcount) + putmsghistory((char *) 0, TRUE); + debugpline1("Read %d messages from savefile.", msgcount); } /* Clear all structures for object and monster ID mapping. */ @@ -1176,8 +1201,8 @@ clear_id_mapping() struct bucket *curr; while ((curr = id_map) != 0) { - id_map = curr->next; - free((genericptr_t) curr); + id_map = curr->next; + free((genericptr_t) curr); } n_ids_mapped = 0; } @@ -1185,7 +1210,7 @@ clear_id_mapping() /* Add a mapping to the ID map. */ STATIC_OVL void add_id_mapping(gid, nid) - unsigned gid, nid; +unsigned gid, nid; { int idx; @@ -1193,9 +1218,9 @@ add_id_mapping(gid, nid) /* idx is zero on first time through, as well as when a new bucket is */ /* needed */ if (idx == 0) { - struct bucket *gnu = (struct bucket *) alloc(sizeof(struct bucket)); - gnu->next = id_map; - id_map = gnu; + struct bucket *gnu = (struct bucket *) alloc(sizeof(struct bucket)); + gnu->next = id_map; + id_map = gnu; } id_map->map[idx].gid = gid; @@ -1210,26 +1235,27 @@ add_id_mapping(gid, nid) */ boolean lookup_id_mapping(gid, nidp) - unsigned gid, *nidp; +unsigned gid, *nidp; { int i; struct bucket *curr; if (n_ids_mapped) - for (curr = id_map; curr; curr = curr->next) { - /* first bucket might not be totally full */ - if (curr == id_map) { - i = n_ids_mapped % N_PER_BUCKET; - if (i == 0) i = N_PER_BUCKET; - } else - i = N_PER_BUCKET; + for (curr = id_map; curr; curr = curr->next) { + /* first bucket might not be totally full */ + if (curr == id_map) { + i = n_ids_mapped % N_PER_BUCKET; + if (i == 0) + i = N_PER_BUCKET; + } else + i = N_PER_BUCKET; - while (--i >= 0) - if (gid == curr->map[i].gid) { - *nidp = curr->map[i].nid; - return TRUE; - } - } + while (--i >= 0) + if (gid == curr->map[i].gid) { + *nidp = curr->map[i].nid; + return TRUE; + } + } return FALSE; } @@ -1241,85 +1267,88 @@ boolean ghostly; struct obj *otmp; unsigned oldid, nid; for (otmp = fobj; otmp; otmp = otmp->nobj) { - if (ghostly && has_omonst(otmp)) { - struct monst *mtmp = OMONST(otmp); + if (ghostly && has_omonst(otmp)) { + struct monst *mtmp = OMONST(otmp); - mtmp->m_id = 0; - mtmp->mpeaceful = mtmp->mtame = 0; /* pet's owner died! */ - } - if (ghostly && has_omid(otmp)) { - (void) memcpy((genericptr_t)&oldid, (genericptr_t)OMID(otmp), - sizeof(oldid)); - if (lookup_id_mapping(oldid, &nid)) - (void) memcpy((genericptr_t)OMID(otmp), (genericptr_t)&nid, - sizeof(nid)); - else - free_omid(otmp); - - } + mtmp->m_id = 0; + mtmp->mpeaceful = mtmp->mtame = 0; /* pet's owner died! */ + } + if (ghostly && has_omid(otmp)) { + (void) memcpy((genericptr_t) &oldid, (genericptr_t) OMID(otmp), + sizeof(oldid)); + if (lookup_id_mapping(oldid, &nid)) + (void) memcpy((genericptr_t) OMID(otmp), (genericptr_t) &nid, + sizeof(nid)); + else + free_omid(otmp); + } } } #ifdef SELECTSAVED /* put up a menu listing each character from this player's saved games */ int -restore_menu(bannerwin) /* returns 1: use plname[], 0: new game, -1: quit */ +restore_menu(bannerwin) /* returns 1: use plname[], 0: new game, -1: quit */ winid bannerwin; /* if not WIN_ERR, clear window and show copyright in menu */ { winid tmpwin; anything any; char **saved; - menu_item *chosen_game = (menu_item *)0; - int k, clet, ch = 0; /* ch: 0 => new game */ + menu_item *chosen_game = (menu_item *) 0; + int k, clet, ch = 0; /* ch: 0 => new game */ *plname = '\0'; - saved = get_saved_games(); /* array of character names */ + saved = get_saved_games(); /* array of character names */ if (saved && *saved) { - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; /* no selection */ - if (bannerwin != WIN_ERR) { - /* for tty; erase copyright notice and redo it in the menu */ - clear_nhwindow(bannerwin); - /* COPYRIGHT_BANNER_[ABCD] */ - for (k = 1; k <= 4; ++k) - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, copyright_banner_line(k), MENU_UNSELECTED); - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, "", MENU_UNSELECTED); - } - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, "Select one of your saved games", MENU_UNSELECTED); - for (k = 0; saved[k]; ++k) { - any.a_int = k + 1; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, - ATR_NONE, saved[k], MENU_UNSELECTED); - } - clet = (k <= 'n' - 'a') ? 'n' : 0; /* new game */ - any.a_int = -1; /* not >= 0 */ - add_menu(tmpwin, NO_GLYPH, &any, clet, 0, - ATR_NONE, "Start a new character", MENU_UNSELECTED); - clet = (k + 1 <= 'q' - 'a') ? 'q' : 0; /* quit */ - any.a_int = -2; - add_menu(tmpwin, NO_GLYPH, &any, clet, 0, - ATR_NONE, "Never mind (quit)", MENU_SELECTED); - /* no prompt on end_menu, as we've done our own at the top */ - end_menu(tmpwin, (char *)0); - if (select_menu(tmpwin, PICK_ONE, &chosen_game) > 0) { - ch = chosen_game->item.a_int; - if (ch > 0) Strcpy(plname, saved[ch - 1]); - else if (ch < 0) ++ch; /* -1 -> 0 (new game), -2 -> -1 (quit) */ - free((genericptr_t)chosen_game); - } else { - ch = -1; /* quit menu without making a selection => quit */ - } - destroy_nhwindow(tmpwin); - if (bannerwin != WIN_ERR) { - /* for tty; clear the menu away and put subset of copyright back */ - clear_nhwindow(bannerwin); - /* COPYRIGHT_BANNER_A, preceding "Who are you?" prompt */ - if (ch == 0) putstr(bannerwin, 0, copyright_banner_line(1)); - } + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; /* no selection */ + if (bannerwin != WIN_ERR) { + /* for tty; erase copyright notice and redo it in the menu */ + clear_nhwindow(bannerwin); + /* COPYRIGHT_BANNER_[ABCD] */ + for (k = 1; k <= 4; ++k) + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + copyright_banner_line(k), MENU_UNSELECTED); + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", + MENU_UNSELECTED); + } + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, + "Select one of your saved games", MENU_UNSELECTED); + for (k = 0; saved[k]; ++k) { + any.a_int = k + 1; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, saved[k], + MENU_UNSELECTED); + } + clet = (k <= 'n' - 'a') ? 'n' : 0; /* new game */ + any.a_int = -1; /* not >= 0 */ + add_menu(tmpwin, NO_GLYPH, &any, clet, 0, ATR_NONE, + "Start a new character", MENU_UNSELECTED); + clet = (k + 1 <= 'q' - 'a') ? 'q' : 0; /* quit */ + any.a_int = -2; + add_menu(tmpwin, NO_GLYPH, &any, clet, 0, ATR_NONE, + "Never mind (quit)", MENU_SELECTED); + /* no prompt on end_menu, as we've done our own at the top */ + end_menu(tmpwin, (char *) 0); + if (select_menu(tmpwin, PICK_ONE, &chosen_game) > 0) { + ch = chosen_game->item.a_int; + if (ch > 0) + Strcpy(plname, saved[ch - 1]); + else if (ch < 0) + ++ch; /* -1 -> 0 (new game), -2 -> -1 (quit) */ + free((genericptr_t) chosen_game); + } else { + ch = -1; /* quit menu without making a selection => quit */ + } + destroy_nhwindow(tmpwin); + if (bannerwin != WIN_ERR) { + /* for tty; clear the menu away and put subset of copyright back + */ + clear_nhwindow(bannerwin); + /* COPYRIGHT_BANNER_A, preceding "Who are you?" prompt */ + if (ch == 0) + putstr(bannerwin, 0, copyright_banner_line(1)); + } } free_saved_games(saved); return (ch > 0) ? 1 : ch; @@ -1360,58 +1389,66 @@ const char *name; unsigned long compatible; boolean verbose = name ? TRUE : FALSE, reslt = FALSE; - if (!(reslt = uptodate(fd, name))) return 1; + if (!(reslt = uptodate(fd, name))) + return 1; rlen = read(fd, (genericptr_t) &sfi, sizeof sfi); - minit(); /* ZEROCOMP */ + minit(); /* ZEROCOMP */ if (rlen == 0) { - if (verbose) { - pline("File \"%s\" is empty during save file feature check?", name); - wait_synch(); - } - return -1; + if (verbose) { + pline("File \"%s\" is empty during save file feature check?", + name); + wait_synch(); + } + return -1; } compatible = (sfi.sfi1 & sfcap.sfi1); if ((sfi.sfi1 & SFI1_ZEROCOMP) == SFI1_ZEROCOMP) { - if ((compatible & SFI1_ZEROCOMP) != SFI1_ZEROCOMP) { - if (verbose) { - pline("File \"%s\" has incompatible ZEROCOMP compression.", name); - wait_synch(); - } - return 2; - } else if ((sfrestinfo.sfi1 & SFI1_ZEROCOMP) != SFI1_ZEROCOMP) { - set_restpref("zerocomp"); - } + if ((compatible & SFI1_ZEROCOMP) != SFI1_ZEROCOMP) { + if (verbose) { + pline("File \"%s\" has incompatible ZEROCOMP compression.", + name); + wait_synch(); + } + return 2; + } else if ((sfrestinfo.sfi1 & SFI1_ZEROCOMP) != SFI1_ZEROCOMP) { + set_restpref("zerocomp"); + } } if ((sfi.sfi1 & SFI1_EXTERNALCOMP) == SFI1_EXTERNALCOMP) { - if ((compatible & SFI1_EXTERNALCOMP) != SFI1_EXTERNALCOMP) { - if (verbose) { - pline("File \"%s\" lacks required internal compression.", name); - wait_synch(); - } - return 2; - } else if ((sfrestinfo.sfi1 & SFI1_EXTERNALCOMP) != SFI1_EXTERNALCOMP) { - set_restpref("externalcomp"); - } + if ((compatible & SFI1_EXTERNALCOMP) != SFI1_EXTERNALCOMP) { + if (verbose) { + pline("File \"%s\" lacks required internal compression.", + name); + wait_synch(); + } + return 2; + } else if ((sfrestinfo.sfi1 & SFI1_EXTERNALCOMP) + != SFI1_EXTERNALCOMP) { + set_restpref("externalcomp"); + } } - /* RLECOMP check must be last, after ZEROCOMP or INTERNALCOMP adjustments */ + /* RLECOMP check must be last, after ZEROCOMP or INTERNALCOMP adjustments + */ if ((sfi.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP) { - if ((compatible & SFI1_RLECOMP) != SFI1_RLECOMP) { - if (verbose) { - pline("File \"%s\" has incompatible run-length compression.", name); - wait_synch(); - } - return 2; - } else if ((sfrestinfo.sfi1 & SFI1_RLECOMP) != SFI1_RLECOMP) { - set_restpref("rlecomp"); + if ((compatible & SFI1_RLECOMP) != SFI1_RLECOMP) { + if (verbose) { + pline("File \"%s\" has incompatible run-length compression.", + name); + wait_synch(); + } + return 2; + } else if ((sfrestinfo.sfi1 & SFI1_RLECOMP) != SFI1_RLECOMP) { + set_restpref("rlecomp"); } } /* savefile does not have RLECOMP level location compression, so adjust */ - else set_restpref("!rlecomp"); + else + set_restpref("!rlecomp"); return 0; } @@ -1420,53 +1457,53 @@ void reset_restpref() { #ifdef ZEROCOMP - if (iflags.zerocomp) - set_restpref("zerocomp"); - else + if (iflags.zerocomp) + set_restpref("zerocomp"); + else #endif - set_restpref("externalcomp"); + set_restpref("externalcomp"); #ifdef RLECOMP - if (iflags.rlecomp) - set_restpref("rlecomp"); - else + if (iflags.rlecomp) + set_restpref("rlecomp"); + else #endif - set_restpref("!rlecomp"); + set_restpref("!rlecomp"); } void set_restpref(suitename) const char *suitename; { - if (!strcmpi(suitename, "externalcomp")) { - restoreprocs.name = "externalcomp"; - restoreprocs.restore_mread = def_mread; - restoreprocs.restore_minit = def_minit; - sfrestinfo.sfi1 |= SFI1_EXTERNALCOMP; - sfrestinfo.sfi1 &= ~SFI1_ZEROCOMP; - def_minit(); - } - if (!strcmpi(suitename, "!rlecomp")) { - sfrestinfo.sfi1 &= ~SFI1_RLECOMP; - } + if (!strcmpi(suitename, "externalcomp")) { + restoreprocs.name = "externalcomp"; + restoreprocs.restore_mread = def_mread; + restoreprocs.restore_minit = def_minit; + sfrestinfo.sfi1 |= SFI1_EXTERNALCOMP; + sfrestinfo.sfi1 &= ~SFI1_ZEROCOMP; + def_minit(); + } + if (!strcmpi(suitename, "!rlecomp")) { + sfrestinfo.sfi1 &= ~SFI1_RLECOMP; + } #ifdef ZEROCOMP - if (!strcmpi(suitename, "zerocomp")) { - restoreprocs.name = "zerocomp"; - restoreprocs.restore_mread = zerocomp_mread; - restoreprocs.restore_minit = zerocomp_minit; - sfrestinfo.sfi1 |= SFI1_ZEROCOMP; - sfrestinfo.sfi1 &= ~SFI1_EXTERNALCOMP; - zerocomp_minit(); - } + if (!strcmpi(suitename, "zerocomp")) { + restoreprocs.name = "zerocomp"; + restoreprocs.restore_mread = zerocomp_mread; + restoreprocs.restore_minit = zerocomp_minit; + sfrestinfo.sfi1 |= SFI1_ZEROCOMP; + sfrestinfo.sfi1 &= ~SFI1_EXTERNALCOMP; + zerocomp_minit(); + } #endif #ifdef RLECOMP - if (!strcmpi(suitename, "rlecomp")) { - sfrestinfo.sfi1 |= SFI1_RLECOMP; - } + if (!strcmpi(suitename, "rlecomp")) { + sfrestinfo.sfi1 |= SFI1_RLECOMP; + } #endif } #ifdef ZEROCOMP -#define RLESC '\0' /* Leading character for run of RLESC's */ +#define RLESC '\0' /* Leading character for run of RLESC's */ #ifndef ZEROCOMP_BUFSIZ #define ZEROCOMP_BUFSIZ BUFSZ @@ -1481,14 +1518,14 @@ STATIC_OVL int zerocomp_mgetc() { if (inbufp >= inbufsz) { - inbufsz = read(mreadfd, (genericptr_t)inbuf, sizeof inbuf); - if (!inbufsz) { - if (inbufp > sizeof inbuf) - error("EOF on file #%d.\n", mreadfd); - inbufp = 1 + sizeof inbuf; /* exactly one warning :-) */ - return -1; - } - inbufp = 0; + inbufsz = read(mreadfd, (genericptr_t) inbuf, sizeof inbuf); + if (!inbufsz) { + if (inbufp > sizeof inbuf) + error("EOF on file #%d.\n", mreadfd); + inbufp = 1 + sizeof inbuf; /* exactly one warning :-) */ + return -1; + } + inbufp = 0; } return inbuf[inbufp++]; } @@ -1508,23 +1545,24 @@ genericptr_t buf; register unsigned len; { /*register int readlen = 0;*/ - if (fd < 0) error("Restore error; mread attempting to read file %d.", fd); + if (fd < 0) + error("Restore error; mread attempting to read file %d.", fd); mreadfd = fd; while (len--) { - if (inrunlength > 0) { - inrunlength--; - *(*((char **)&buf))++ = '\0'; - } else { - register short ch = zerocomp_mgetc(); - if (ch < 0) { - restoreprocs.mread_flags = -1; - return; - } - if ((*(*(char **)&buf)++ = (char)ch) == RLESC) { - inrunlength = zerocomp_mgetc(); - } - } - /*readlen++;*/ + if (inrunlength > 0) { + inrunlength--; + *(*((char **) &buf))++ = '\0'; + } else { + register short ch = zerocomp_mgetc(); + if (ch < 0) { + restoreprocs.mread_flags = -1; + return; + } + if ((*(*(char **) &buf)++ = (char) ch) == RLESC) { + inrunlength = zerocomp_mgetc(); + } + } + /*readlen++;*/ } } #endif /* ZEROCOMP */ @@ -1541,28 +1579,28 @@ register int fd; register genericptr_t buf; register unsigned int len; { - register int rlen; + register int rlen; #if defined(BSD) || defined(ULTRIX) - rlen = read(fd, buf, (int) len); - if(rlen != len){ + rlen = read(fd, buf, (int) len); + if (rlen != len) { #else /* e.g. SYSV, __TURBOC__ */ - rlen = read(fd, buf, (unsigned) len); - if((unsigned)rlen != len){ + rlen = read(fd, buf, (unsigned) len); + if ((unsigned) rlen != len) { #endif - if (restoreprocs.mread_flags == 1) { /* means "return anyway" */ - restoreprocs.mread_flags = -1; - return; - } else { - pline("Read %d instead of %u bytes.", rlen, len); - if(restoring) { - (void) nhclose(fd); - (void) delete_savefile(); - error("Error restoring old game."); - } - panic("Error reading level file."); - } - } + if (restoreprocs.mread_flags == 1) { /* means "return anyway" */ + restoreprocs.mread_flags = -1; + return; + } else { + pline("Read %d instead of %u bytes.", rlen, len); + if (restoring) { + (void) nhclose(fd); + (void) delete_savefile(); + error("Error restoring old game."); + } + panic("Error reading level file."); + } + } } /*restore.c*/ diff --git a/src/rip.c b/src/rip.c index 2fbea961f..204d1ab85 100644 --- a/src/rip.c +++ b/src/rip.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 rip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 rip.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ /* NetHack 3.6 rip.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.11 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,13 +7,14 @@ STATIC_DCL void FDECL(center, (int, char *)); -#if defined(TTY_GRAPHICS) || defined(X11_GRAPHICS) || defined(GEM_GRAPHICS) || defined(MSWIN_GRAPHICS) -# define TEXT_TOMBSTONE +#if defined(TTY_GRAPHICS) || defined(X11_GRAPHICS) || defined(GEM_GRAPHICS) \ + || defined(MSWIN_GRAPHICS) +#define TEXT_TOMBSTONE #endif #if defined(mac) || defined(__BEOS__) || defined(WIN32_GRAPHICS) -# ifndef TEXT_TOMBSTONE -# define TEXT_TOMBSTONE -# endif +#ifndef TEXT_TOMBSTONE +#define TEXT_TOMBSTONE +#endif #endif #ifdef TEXT_TOMBSTONE @@ -21,53 +22,54 @@ STATIC_DCL void FDECL(center, (int, char *)); #ifndef NH320_DEDICATION /* A normal tombstone for end of game display. */ static const char *rip_txt[] = { -" ----------", -" / \\", -" / REST \\", -" / IN \\", -" / PEACE \\", -" / \\", -" | |", /* Name of player */ -" | |", /* Amount of $ */ -" | |", /* Type of death */ -" | |", /* . */ -" | |", /* . */ -" | |", /* . */ -" | 1001 |", /* Real year of death */ -" *| * * * | *", -" _________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", -0 + " ----------", + " / \\", + " / REST \\", + " / IN \\", + " / PEACE \\", + " / \\", + " | |", /* Name of player */ + " | |", /* Amount of $ */ + " | |", /* Type of death */ + " | |", /* . */ + " | |", /* . */ + " | |", /* . */ + " | 1001 |", /* Real year of death */ + " *| * * * | *", + " _________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", 0 }; -#define STONE_LINE_CENT 28 /* char[] element of center of stone face */ -#else /* NH320_DEDICATION */ +#define STONE_LINE_CENT 28 /* char[] element of center of stone face */ +#else /* NH320_DEDICATION */ /* NetHack 3.2.x displayed a dual tombstone as a tribute to Izchak. */ static const char *rip_txt[] = { -" ---------- ----------", -" / \\ / \\", -" / REST \\ / This \\", -" / IN \\ / release of \\", -" / PEACE \\ / NetHack is \\", -" / \\ / dedicated to \\", -" | | | the memory of |", -" | | | |", -" | | | Izchak Miller |", -" | | | 1935 - 1994 |", -" | | | |", -" | | | Ascended |", -" | 1001 | | |", -" * | * * * | * * | * * * | *", -" _____)/\\|\\__//(\\/(/\\)/\\//\\/|_)________)/|\\\\_/_/(\\/(/\\)/\\/\\/|_)____", -0 + " ---------- ----------", + " / \\ / \\", + " / REST \\ / This \\", + " / IN \\ / release of \\", + " / PEACE \\ / NetHack is \\", + " / \\ / dedicated to \\", + " | | | the memory of |", + " | | | |", + " | | | Izchak Miller |", + " | | | 1935 - 1994 |", + " | | | |", + " | | | Ascended |", + " | 1001 | | |", + " * | * * * | * * | * * * | *", + " _____)/\\|\\__//(\\/(/\\)/\\//\\/|_)________)/|\\\\_/_/(\\/(/\\)/\\/\\/" + "|_)____", + 0 }; -#define STONE_LINE_CENT 19 /* char[] element of center of stone face */ -#endif /* NH320_DEDICATION */ -#define STONE_LINE_LEN 16 /* # chars that fit on one line - * (note 1 ' ' border) - */ -#define NAME_LINE 6 /* *char[] line # for player name */ -#define GOLD_LINE 7 /* *char[] line # for amount of gold */ -#define DEATH_LINE 8 /* *char[] line # for death description */ -#define YEAR_LINE 12 /* *char[] line # for year */ +#define STONE_LINE_CENT 19 /* char[] element of center of stone face */ +#endif /* NH320_DEDICATION */ +#define STONE_LINE_LEN \ + 16 /* # chars that fit on one line \ + * (note 1 ' ' border) \ + */ +#define NAME_LINE 6 /* *char[] line # for player name */ +#define GOLD_LINE 7 /* *char[] line # for amount of gold */ +#define DEATH_LINE 8 /* *char[] line # for death description */ +#define YEAR_LINE 12 /* *char[] line # for year */ static char **rip; @@ -76,83 +78,85 @@ center(line, text) int line; char *text; { - register char *ip,*op; - ip = text; - op = &rip[line][STONE_LINE_CENT - ((strlen(text)+1)>>1)]; - while(*ip) *op++ = *ip++; + register char *ip, *op; + ip = text; + op = &rip[line][STONE_LINE_CENT - ((strlen(text) + 1) >> 1)]; + while (*ip) + *op++ = *ip++; } - void genl_outrip(tmpwin, how, when) winid tmpwin; int how; time_t when; { - register char **dp; - register char *dpx; - char buf[BUFSZ]; - long year; - register int x; - int line; + register char **dp; + register char *dpx; + char buf[BUFSZ]; + long year; + register int x; + int line; - rip = dp = (char **) alloc(sizeof(rip_txt)); - for (x = 0; rip_txt[x]; ++x) - dp[x] = dupstr(rip_txt[x]); - dp[x] = (char *)0; + rip = dp = (char **) alloc(sizeof(rip_txt)); + for (x = 0; rip_txt[x]; ++x) + dp[x] = dupstr(rip_txt[x]); + dp[x] = (char *) 0; - /* Put name on stone */ - Sprintf(buf, "%s", plname); - buf[STONE_LINE_LEN] = 0; - center(NAME_LINE, buf); + /* Put name on stone */ + Sprintf(buf, "%s", plname); + buf[STONE_LINE_LEN] = 0; + center(NAME_LINE, buf); - /* Put $ on stone */ - Sprintf(buf, "%ld Au", done_money); - buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */ - center(GOLD_LINE, buf); + /* Put $ on stone */ + Sprintf(buf, "%ld Au", done_money); + buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */ + center(GOLD_LINE, buf); - /* Put together death description */ - formatkiller(buf, sizeof buf, how); + /* Put together death description */ + formatkiller(buf, sizeof buf, how); - /* Put death type on stone */ - for (line=DEATH_LINE, dpx = buf; line STONE_LINE_LEN) { - for(i = STONE_LINE_LEN; - ((i0 > STONE_LINE_LEN) && i); i--) - if(dpx[i] == ' ') i0 = i; - if(!i) i0 = STONE_LINE_LEN; - } - tmpchar = dpx[i0]; - dpx[i0] = 0; - center(line, dpx); - if (tmpchar != ' ') { - dpx[i0] = tmpchar; - dpx= &dpx[i0]; - } else dpx= &dpx[i0+1]; - } + if ((i0 = strlen(dpx)) > STONE_LINE_LEN) { + for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--) + if (dpx[i] == ' ') + i0 = i; + if (!i) + i0 = STONE_LINE_LEN; + } + tmpchar = dpx[i0]; + dpx[i0] = 0; + center(line, dpx); + if (tmpchar != ' ') { + dpx[i0] = tmpchar; + dpx = &dpx[i0]; + } else + dpx = &dpx[i0 + 1]; + } - /* Put year on stone */ - year = yyyymmdd(when) / 10000L; - Sprintf(buf, "%4ld", year); - center(YEAR_LINE, buf); + /* Put year on stone */ + year = yyyymmdd(when) / 10000L; + Sprintf(buf, "%4ld", year); + center(YEAR_LINE, buf); - putstr(tmpwin, 0, ""); - for(; *dp; dp++) - putstr(tmpwin, 0, *dp); + putstr(tmpwin, 0, ""); + for (; *dp; dp++) + putstr(tmpwin, 0, *dp); - putstr(tmpwin, 0, ""); - putstr(tmpwin, 0, ""); + putstr(tmpwin, 0, ""); + putstr(tmpwin, 0, ""); - for (x = 0; rip_txt[x]; x++) { - free((genericptr_t)rip[x]); - } - free((genericptr_t)rip); - rip = 0; + for (x = 0; rip_txt[x]; x++) { + free((genericptr_t) rip[x]); + } + free((genericptr_t) rip); + rip = 0; } -#endif /* TEXT_TOMBSTONE */ +#endif /* TEXT_TOMBSTONE */ /*rip.c*/ diff --git a/src/rnd.c b/src/rnd.c index a64a59482..b97f568b0 100644 --- a/src/rnd.c +++ b/src/rnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 rnd.c $NHDT-Date: 1426465440 2015/03/16 00:24:00 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.8 $ */ +/* NetHack 3.6 rnd.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 rnd.c $Date: 2009/05/06 10:47:41 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)rnd.c 3.5 2004/08/27 */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,126 +6,125 @@ #include "hack.h" /* "Rand()"s definition is determined by [OS]conf.h */ -#if defined(LINT) && defined(UNIX) /* rand() is long... */ +#if defined(LINT) && defined(UNIX) /* rand() is long... */ extern int NDECL(rand); -#define RND(x) (rand() % x) +#define RND(x) (rand() % x) #else /* LINT */ -# if defined(UNIX) || defined(RANDOM) -#define RND(x) (int)(Rand() % (long)(x)) -# else +#if defined(UNIX) || defined(RANDOM) +#define RND(x) (int)(Rand() % (long) (x)) +#else /* Good luck: the bottom order bits are cyclic. */ -#define RND(x) (int)((Rand()>>3) % (x)) -# endif +#define RND(x) (int)((Rand() >> 3) % (x)) +#endif #endif /* LINT */ -int -rn2(x) /* 0 <= rn2(x) < x */ +int rn2(x) /* 0 <= rn2(x) < x */ register int x; { #ifdef BETA - if (x <= 0) { - debugpline1("rn2(%d) attempted", x); - return(0); - } - x = RND(x); - return(x); + if (x <= 0) { + debugpline1("rn2(%d) attempted", x); + return (0); + } + x = RND(x); + return (x); #else - return(RND(x)); + return (RND(x)); #endif } -int -rnl(x) /* 0 <= rnl(x) < x; sometimes subtracting Luck */ -register int x; /* good luck approaches 0, bad luck approaches (x-1) */ +int rnl(x) /* 0 <= rnl(x) < x; sometimes subtracting Luck */ +register int x; /* good luck approaches 0, bad luck approaches (x-1) */ { - register int i, adjustment; + register int i, adjustment; #ifdef BETA - if (x <= 0) { - debugpline1("rnl(%d) attempted", x); - return(0); - } + if (x <= 0) { + debugpline1("rnl(%d) attempted", x); + return (0); + } #endif - adjustment = Luck; - if (x <= 15) { - /* for small ranges, use Luck/3 (rounded away from 0); - also guard against architecture-specific differences - of integer division involving negative values */ - adjustment = (abs(adjustment) + 1) / 3 * sgn(adjustment); - /* - * 11..13 -> 4 - * 8..10 -> 3 - * 5.. 7 -> 2 - * 2.. 4 -> 1 - * -1,0,1 -> 0 (no adjustment) - * -4..-2 -> -1 - * -7..-5 -> -2 - * -10..-8 -> -3 - * -13..-11-> -4 - */ - } + adjustment = Luck; + if (x <= 15) { + /* for small ranges, use Luck/3 (rounded away from 0); + also guard against architecture-specific differences + of integer division involving negative values */ + adjustment = (abs(adjustment) + 1) / 3 * sgn(adjustment); + /* + * 11..13 -> 4 + * 8..10 -> 3 + * 5.. 7 -> 2 + * 2.. 4 -> 1 + * -1,0,1 -> 0 (no adjustment) + * -4..-2 -> -1 + * -7..-5 -> -2 + * -10..-8 -> -3 + * -13..-11-> -4 + */ + } - i = RND(x); - if (adjustment && rn2(37 + abs(adjustment))) { - i -= adjustment; - if (i < 0) i = 0; - else if (i >= x) i = x-1; - } - return i; + i = RND(x); + if (adjustment && rn2(37 + abs(adjustment))) { + i -= adjustment; + if (i < 0) + i = 0; + else if (i >= x) + i = x - 1; + } + return i; } -int -rnd(x) /* 1 <= rnd(x) <= x */ +int rnd(x) /* 1 <= rnd(x) <= x */ register int x; { #ifdef BETA - if (x <= 0) { - debugpline1("rnd(%d) attempted", x); - return(1); - } - x = RND(x)+1; - return(x); + if (x <= 0) { + debugpline1("rnd(%d) attempted", x); + return (1); + } + x = RND(x) + 1; + return (x); #else - return(RND(x)+1); + return (RND(x) + 1); #endif } -int -d(n,x) /* n <= d(n,x) <= (n*x) */ +int d(n, x) /* n <= d(n,x) <= (n*x) */ register int n, x; { - register int tmp = n; + register int tmp = n; #ifdef BETA - if (x < 0 || n < 0 || (x == 0 && n != 0)) { - debugpline2("d(%d,%d) attempted", n, x); - return(1); - } + if (x < 0 || n < 0 || (x == 0 && n != 0)) { + debugpline2("d(%d,%d) attempted", n, x); + return (1); + } #endif - while(n--) tmp += RND(x); - return(tmp); /* Alea iacta est. -- J.C. */ + while (n--) + tmp += RND(x); + return (tmp); /* Alea iacta est. -- J.C. */ } int rne(x) register int x; { - register int tmp, utmp; + register int tmp, utmp; - utmp = (u.ulevel < 15) ? 5 : u.ulevel/3; - tmp = 1; - while (tmp < utmp && !rn2(x)) - tmp++; - return tmp; + utmp = (u.ulevel < 15) ? 5 : u.ulevel / 3; + tmp = 1; + while (tmp < utmp && !rn2(x)) + tmp++; + return tmp; - /* was: - * tmp = 1; - * while(!rn2(x)) tmp++; - * return(min(tmp,(u.ulevel < 15) ? 5 : u.ulevel/3)); - * which is clearer but less efficient and stands a vanishingly - * small chance of overflowing tmp - */ + /* was: + * tmp = 1; + * while(!rn2(x)) tmp++; + * return(min(tmp,(u.ulevel < 15) ? 5 : u.ulevel/3)); + * which is clearer but less efficient and stands a vanishingly + * small chance of overflowing tmp + */ } int @@ -133,17 +132,22 @@ rnz(i) int i; { #ifdef LINT - int x = i; - int tmp = 1000; + int x = i; + int tmp = 1000; #else - register long x = i; - register long tmp = 1000; + register long x = i; + register long tmp = 1000; #endif - tmp += rn2(1000); - tmp *= rne(4); - if (rn2(2)) { x *= tmp; x /= 1000; } - else { x *= 1000; x /= tmp; } - return((int)x); + tmp += rn2(1000); + tmp *= rne(4); + if (rn2(2)) { + x *= tmp; + x /= 1000; + } else { + x *= 1000; + x /= tmp; + } + return ((int) x); } /*rnd.c*/ diff --git a/src/role.c b/src/role.c index 295b301c2..2cd4faf3d 100644 --- a/src/role.c +++ b/src/role.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 role.c $NHDT-Date: 1426558928 2015/03/17 02:22:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */ +/* NetHack 3.6 role.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */ /* NetHack 3.6 role.c $Date: 2012/02/16 03:01:38 $ $Revision: 1.18 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985-1999. */ /* NetHack may be freely redistributed. See license for details. */ @@ -25,217 +25,360 @@ * God names use a leading underscore to flag goddesses. */ const struct Role roles[] = { -{ {"Archeologist", 0}, { - {"Digger", 0}, - {"Field Worker",0}, - {"Investigator",0}, - {"Exhumer", 0}, - {"Excavator", 0}, - {"Spelunker", 0}, - {"Speleologist",0}, - {"Collector", 0}, - {"Curator", 0} }, - "Quetzalcoatl", "Camaxtli", "Huhetotl", /* Central American */ - "Arc", "the College of Archeology", "the Tomb of the Toltec Kings", - PM_ARCHEOLOGIST, NON_PM, NON_PM, - PM_LORD_CARNARVON, PM_STUDENT, PM_MINION_OF_HUHETOTL, - NON_PM, PM_HUMAN_MUMMY, S_SNAKE, S_MUMMY, - ART_ORB_OF_DETECTION, - MH_HUMAN|MH_DWARF|MH_GNOME | ROLE_MALE|ROLE_FEMALE | - ROLE_LAWFUL|ROLE_NEUTRAL, - /* Str Int Wis Dex Con Cha */ - { 7, 10, 10, 7, 7, 7 }, - { 20, 20, 20, 10, 20, 10 }, - /* Init Lower Higher */ - { 11, 0, 0, 8, 1, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },14, /* Energy */ - 10, 5, 0, 2, 10, A_INT, SPE_MAGIC_MAPPING, -4 -}, -{ {"Barbarian", 0}, { - {"Plunderer", "Plunderess"}, - {"Pillager", 0}, - {"Bandit", 0}, - {"Brigand", 0}, - {"Raider", 0}, - {"Reaver", 0}, - {"Slayer", 0}, - {"Chieftain", "Chieftainess"}, - {"Conqueror", "Conqueress"} }, - "Mitra", "Crom", "Set", /* Hyborian */ - "Bar", "the Camp of the Duali Tribe", "the Duali Oasis", - PM_BARBARIAN, NON_PM, NON_PM, - PM_PELIAS, PM_CHIEFTAIN, PM_THOTH_AMON, - PM_OGRE, PM_TROLL, S_OGRE, S_TROLL, - ART_HEART_OF_AHRIMAN, - MH_HUMAN|MH_ORC | ROLE_MALE|ROLE_FEMALE | - ROLE_NEUTRAL|ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 16, 7, 7, 15, 16, 6 }, - { 30, 6, 7, 20, 30, 7 }, - /* Init Lower Higher */ - { 14, 0, 0,10, 2, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },10, /* Energy */ - 10, 14, 0, 0, 8, A_INT, SPE_HASTE_SELF, -4 -}, -{ {"Caveman", "Cavewoman"}, { - {"Troglodyte", 0}, - {"Aborigine", 0}, - {"Wanderer", 0}, - {"Vagrant", 0}, - {"Wayfarer", 0}, - {"Roamer", 0}, - {"Nomad", 0}, - {"Rover", 0}, - {"Pioneer", 0} }, - "Anu", "_Ishtar", "Anshar", /* Babylonian */ - "Cav", "the Caves of the Ancestors", "the Dragon's Lair", - PM_CAVEMAN, PM_CAVEWOMAN, PM_LITTLE_DOG, - PM_SHAMAN_KARNOV, PM_NEANDERTHAL, PM_CHROMATIC_DRAGON, - PM_BUGBEAR, PM_HILL_GIANT, S_HUMANOID, S_GIANT, - ART_SCEPTRE_OF_MIGHT, - MH_HUMAN|MH_DWARF|MH_GNOME | ROLE_MALE|ROLE_FEMALE | - ROLE_LAWFUL|ROLE_NEUTRAL, - /* Str Int Wis Dex Con Cha */ - { 10, 7, 7, 7, 8, 6 }, - { 30, 6, 7, 20, 30, 7 }, - /* Init Lower Higher */ - { 14, 0, 0, 8, 2, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },10, /* Energy */ - 0, 12, 0, 1, 8, A_INT, SPE_DIG, -4 -}, -{ {"Healer", 0}, { - {"Rhizotomist", 0}, - {"Empiric", 0}, - {"Embalmer", 0}, - {"Dresser", 0}, - {"Medicus ossium", "Medica ossium"}, - {"Herbalist", 0}, - {"Magister", "Magistra"}, - {"Physician", 0}, - {"Chirurgeon", 0} }, - "_Athena", "Hermes", "Poseidon", /* Greek */ - "Hea", "the Temple of Epidaurus", "the Temple of Coeus", - PM_HEALER, NON_PM, NON_PM, - PM_HIPPOCRATES, PM_ATTENDANT, PM_CYCLOPS, - PM_GIANT_RAT, PM_SNAKE, S_RODENT, S_YETI, - ART_STAFF_OF_AESCULAPIUS, - MH_HUMAN|MH_GNOME | ROLE_MALE|ROLE_FEMALE | ROLE_NEUTRAL, - /* Str Int Wis Dex Con Cha */ - { 7, 7, 13, 7, 11, 16 }, - { 15, 20, 20, 15, 25, 5 }, - /* Init Lower Higher */ - { 11, 0, 0, 8, 1, 0 }, /* Hit points */ - { 1, 4, 0, 1, 0, 2 },20, /* Energy */ - 10, 3,-3, 2, 10, A_WIS, SPE_CURE_SICKNESS, -4 -}, -{ {"Knight", 0}, { - {"Gallant", 0}, - {"Esquire", 0}, - {"Bachelor", 0}, - {"Sergeant", 0}, - {"Knight", 0}, - {"Banneret", 0}, - {"Chevalier", "Chevaliere"}, - {"Seignieur", "Dame"}, - {"Paladin", 0} }, - "Lugh", "_Brigit", "Manannan Mac Lir", /* Celtic */ - "Kni", "Camelot Castle", "the Isle of Glass", - PM_KNIGHT, NON_PM, PM_PONY, - PM_KING_ARTHUR, PM_PAGE, PM_IXOTH, - PM_QUASIT, PM_OCHRE_JELLY, S_IMP, S_JELLY, - ART_MAGIC_MIRROR_OF_MERLIN, - MH_HUMAN | ROLE_MALE|ROLE_FEMALE | ROLE_LAWFUL, - /* Str Int Wis Dex Con Cha */ - { 13, 7, 14, 8, 10, 17 }, - { 30, 15, 15, 10, 20, 10 }, - /* Init Lower Higher */ - { 14, 0, 0, 8, 2, 0 }, /* Hit points */ - { 1, 4, 0, 1, 0, 2 },10, /* Energy */ - 10, 8,-2, 0, 9, A_WIS, SPE_TURN_UNDEAD, -4 -}, -{ {"Monk", 0}, { - {"Candidate", 0}, - {"Novice", 0}, - {"Initiate", 0}, - {"Student of Stones", 0}, - {"Student of Waters", 0}, - {"Student of Metals", 0}, - {"Student of Winds", 0}, - {"Student of Fire", 0}, - {"Master", 0} }, - "Shan Lai Ching", "Chih Sung-tzu", "Huan Ti", /* Chinese */ - "Mon", "the Monastery of Chan-Sune", - "the Monastery of the Earth-Lord", - PM_MONK, NON_PM, NON_PM, - PM_GRAND_MASTER, PM_ABBOT, PM_MASTER_KAEN, - PM_EARTH_ELEMENTAL, PM_XORN, S_ELEMENTAL, S_XORN, - ART_EYES_OF_THE_OVERWORLD, - MH_HUMAN | ROLE_MALE|ROLE_FEMALE | - ROLE_LAWFUL|ROLE_NEUTRAL|ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 10, 7, 8, 8, 7, 7 }, - { 25, 10, 20, 20, 15, 10 }, - /* Init Lower Higher */ - { 12, 0, 0, 8, 1, 0 }, /* Hit points */ - { 2, 2, 0, 2, 0, 2 },10, /* Energy */ - 10, 8,-2, 2, 20, A_WIS, SPE_RESTORE_ABILITY, -4 -}, -{ {"Priest", "Priestess"}, { - {"Aspirant", 0}, - {"Acolyte", 0}, - {"Adept", 0}, - {"Priest", "Priestess"}, - {"Curate", 0}, - {"Canon", "Canoness"}, - {"Lama", 0}, - {"Patriarch", "Matriarch"}, - {"High Priest", "High Priestess"} }, - 0, 0, 0, /* chosen randomly from among the other roles */ - "Pri", "the Great Temple", "the Temple of Nalzok", - PM_PRIEST, PM_PRIESTESS, NON_PM, - PM_ARCH_PRIEST, PM_ACOLYTE, PM_NALZOK, - PM_HUMAN_ZOMBIE, PM_WRAITH, S_ZOMBIE, S_WRAITH, - ART_MITRE_OF_HOLINESS, - MH_HUMAN|MH_ELF | ROLE_MALE|ROLE_FEMALE | - ROLE_LAWFUL|ROLE_NEUTRAL|ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 7, 7, 10, 7, 7, 7 }, - { 15, 10, 30, 15, 20, 10 }, - /* Init Lower Higher */ - { 12, 0, 0, 8, 1, 0 }, /* Hit points */ - { 4, 3, 0, 2, 0, 2 },10, /* Energy */ - 0, 3,-2, 2, 10, A_WIS, SPE_REMOVE_CURSE, -4 -}, - /* Note: Rogue precedes Ranger so that use of `-R' on the command line - retains its traditional meaning. */ -{ {"Rogue", 0}, { - {"Footpad", 0}, - {"Cutpurse", 0}, - {"Rogue", 0}, - {"Pilferer", 0}, - {"Robber", 0}, - {"Burglar", 0}, - {"Filcher", 0}, - {"Magsman", "Magswoman"}, - {"Thief", 0} }, - "Issek", "Mog", "Kos", /* Nehwon */ - "Rog", "the Thieves' Guild Hall", "the Assassins' Guild Hall", - PM_ROGUE, NON_PM, NON_PM, - PM_MASTER_OF_THIEVES, PM_THUG, PM_MASTER_ASSASSIN, - PM_LEPRECHAUN, PM_GUARDIAN_NAGA, S_NYMPH, S_NAGA, - ART_MASTER_KEY_OF_THIEVERY, - MH_HUMAN|MH_ORC | ROLE_MALE|ROLE_FEMALE | - ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 7, 7, 7, 10, 7, 6 }, - { 20, 10, 10, 30, 20, 10 }, - /* Init Lower Higher */ - { 10, 0, 0, 8, 1, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },11, /* Energy */ - 10, 8, 0, 1, 9, A_INT, SPE_DETECT_TREASURE, -4 -}, -{ {"Ranger", 0}, { -#if 0 /* OBSOLETE */ + { { "Archeologist", 0 }, + { { "Digger", 0 }, + { "Field Worker", 0 }, + { "Investigator", 0 }, + { "Exhumer", 0 }, + { "Excavator", 0 }, + { "Spelunker", 0 }, + { "Speleologist", 0 }, + { "Collector", 0 }, + { "Curator", 0 } }, + "Quetzalcoatl", + "Camaxtli", + "Huhetotl", /* Central American */ + "Arc", + "the College of Archeology", + "the Tomb of the Toltec Kings", + PM_ARCHEOLOGIST, + NON_PM, + NON_PM, + PM_LORD_CARNARVON, + PM_STUDENT, + PM_MINION_OF_HUHETOTL, + NON_PM, + PM_HUMAN_MUMMY, + S_SNAKE, + S_MUMMY, + ART_ORB_OF_DETECTION, + MH_HUMAN | MH_DWARF | MH_GNOME | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL + | ROLE_NEUTRAL, + /* Str Int Wis Dex Con Cha */ + { 7, 10, 10, 7, 7, 7 }, + { 20, 20, 20, 10, 20, 10 }, + /* Init Lower Higher */ + { 11, 0, 0, 8, 1, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 14, /* Energy */ + 10, + 5, + 0, + 2, + 10, + A_INT, + SPE_MAGIC_MAPPING, + -4 }, + { { "Barbarian", 0 }, + { { "Plunderer", "Plunderess" }, + { "Pillager", 0 }, + { "Bandit", 0 }, + { "Brigand", 0 }, + { "Raider", 0 }, + { "Reaver", 0 }, + { "Slayer", 0 }, + { "Chieftain", "Chieftainess" }, + { "Conqueror", "Conqueress" } }, + "Mitra", + "Crom", + "Set", /* Hyborian */ + "Bar", + "the Camp of the Duali Tribe", + "the Duali Oasis", + PM_BARBARIAN, + NON_PM, + NON_PM, + PM_PELIAS, + PM_CHIEFTAIN, + PM_THOTH_AMON, + PM_OGRE, + PM_TROLL, + S_OGRE, + S_TROLL, + ART_HEART_OF_AHRIMAN, + MH_HUMAN | MH_ORC | ROLE_MALE | ROLE_FEMALE | ROLE_NEUTRAL + | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 16, 7, 7, 15, 16, 6 }, + { 30, 6, 7, 20, 30, 7 }, + /* Init Lower Higher */ + { 14, 0, 0, 10, 2, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 10, /* Energy */ + 10, + 14, + 0, + 0, + 8, + A_INT, + SPE_HASTE_SELF, + -4 }, + { { "Caveman", "Cavewoman" }, + { { "Troglodyte", 0 }, + { "Aborigine", 0 }, + { "Wanderer", 0 }, + { "Vagrant", 0 }, + { "Wayfarer", 0 }, + { "Roamer", 0 }, + { "Nomad", 0 }, + { "Rover", 0 }, + { "Pioneer", 0 } }, + "Anu", + "_Ishtar", + "Anshar", /* Babylonian */ + "Cav", + "the Caves of the Ancestors", + "the Dragon's Lair", + PM_CAVEMAN, + PM_CAVEWOMAN, + PM_LITTLE_DOG, + PM_SHAMAN_KARNOV, + PM_NEANDERTHAL, + PM_CHROMATIC_DRAGON, + PM_BUGBEAR, + PM_HILL_GIANT, + S_HUMANOID, + S_GIANT, + ART_SCEPTRE_OF_MIGHT, + MH_HUMAN | MH_DWARF | MH_GNOME | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL + | ROLE_NEUTRAL, + /* Str Int Wis Dex Con Cha */ + { 10, 7, 7, 7, 8, 6 }, + { 30, 6, 7, 20, 30, 7 }, + /* Init Lower Higher */ + { 14, 0, 0, 8, 2, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 10, /* Energy */ + 0, + 12, + 0, + 1, + 8, + A_INT, + SPE_DIG, + -4 }, + { { "Healer", 0 }, + { { "Rhizotomist", 0 }, + { "Empiric", 0 }, + { "Embalmer", 0 }, + { "Dresser", 0 }, + { "Medicus ossium", "Medica ossium" }, + { "Herbalist", 0 }, + { "Magister", "Magistra" }, + { "Physician", 0 }, + { "Chirurgeon", 0 } }, + "_Athena", + "Hermes", + "Poseidon", /* Greek */ + "Hea", + "the Temple of Epidaurus", + "the Temple of Coeus", + PM_HEALER, + NON_PM, + NON_PM, + PM_HIPPOCRATES, + PM_ATTENDANT, + PM_CYCLOPS, + PM_GIANT_RAT, + PM_SNAKE, + S_RODENT, + S_YETI, + ART_STAFF_OF_AESCULAPIUS, + MH_HUMAN | MH_GNOME | ROLE_MALE | ROLE_FEMALE | ROLE_NEUTRAL, + /* Str Int Wis Dex Con Cha */ + { 7, 7, 13, 7, 11, 16 }, + { 15, 20, 20, 15, 25, 5 }, + /* Init Lower Higher */ + { 11, 0, 0, 8, 1, 0 }, /* Hit points */ + { 1, 4, 0, 1, 0, 2 }, + 20, /* Energy */ + 10, + 3, + -3, + 2, + 10, + A_WIS, + SPE_CURE_SICKNESS, + -4 }, + { { "Knight", 0 }, + { { "Gallant", 0 }, + { "Esquire", 0 }, + { "Bachelor", 0 }, + { "Sergeant", 0 }, + { "Knight", 0 }, + { "Banneret", 0 }, + { "Chevalier", "Chevaliere" }, + { "Seignieur", "Dame" }, + { "Paladin", 0 } }, + "Lugh", + "_Brigit", + "Manannan Mac Lir", /* Celtic */ + "Kni", + "Camelot Castle", + "the Isle of Glass", + PM_KNIGHT, + NON_PM, + PM_PONY, + PM_KING_ARTHUR, + PM_PAGE, + PM_IXOTH, + PM_QUASIT, + PM_OCHRE_JELLY, + S_IMP, + S_JELLY, + ART_MAGIC_MIRROR_OF_MERLIN, + MH_HUMAN | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL, + /* Str Int Wis Dex Con Cha */ + { 13, 7, 14, 8, 10, 17 }, + { 30, 15, 15, 10, 20, 10 }, + /* Init Lower Higher */ + { 14, 0, 0, 8, 2, 0 }, /* Hit points */ + { 1, 4, 0, 1, 0, 2 }, + 10, /* Energy */ + 10, + 8, + -2, + 0, + 9, + A_WIS, + SPE_TURN_UNDEAD, + -4 }, + { { "Monk", 0 }, + { { "Candidate", 0 }, + { "Novice", 0 }, + { "Initiate", 0 }, + { "Student of Stones", 0 }, + { "Student of Waters", 0 }, + { "Student of Metals", 0 }, + { "Student of Winds", 0 }, + { "Student of Fire", 0 }, + { "Master", 0 } }, + "Shan Lai Ching", + "Chih Sung-tzu", + "Huan Ti", /* Chinese */ + "Mon", + "the Monastery of Chan-Sune", + "the Monastery of the Earth-Lord", + PM_MONK, + NON_PM, + NON_PM, + PM_GRAND_MASTER, + PM_ABBOT, + PM_MASTER_KAEN, + PM_EARTH_ELEMENTAL, + PM_XORN, + S_ELEMENTAL, + S_XORN, + ART_EYES_OF_THE_OVERWORLD, + MH_HUMAN | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL | ROLE_NEUTRAL + | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 10, 7, 8, 8, 7, 7 }, + { 25, 10, 20, 20, 15, 10 }, + /* Init Lower Higher */ + { 12, 0, 0, 8, 1, 0 }, /* Hit points */ + { 2, 2, 0, 2, 0, 2 }, + 10, /* Energy */ + 10, + 8, + -2, + 2, + 20, + A_WIS, + SPE_RESTORE_ABILITY, + -4 }, + { { "Priest", "Priestess" }, + { { "Aspirant", 0 }, + { "Acolyte", 0 }, + { "Adept", 0 }, + { "Priest", "Priestess" }, + { "Curate", 0 }, + { "Canon", "Canoness" }, + { "Lama", 0 }, + { "Patriarch", "Matriarch" }, + { "High Priest", "High Priestess" } }, + 0, + 0, + 0, /* chosen randomly from among the other roles */ + "Pri", + "the Great Temple", + "the Temple of Nalzok", + PM_PRIEST, + PM_PRIESTESS, + NON_PM, + PM_ARCH_PRIEST, + PM_ACOLYTE, + PM_NALZOK, + PM_HUMAN_ZOMBIE, + PM_WRAITH, + S_ZOMBIE, + S_WRAITH, + ART_MITRE_OF_HOLINESS, + MH_HUMAN | MH_ELF | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL | ROLE_NEUTRAL + | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 7, 7, 10, 7, 7, 7 }, + { 15, 10, 30, 15, 20, 10 }, + /* Init Lower Higher */ + { 12, 0, 0, 8, 1, 0 }, /* Hit points */ + { 4, 3, 0, 2, 0, 2 }, + 10, /* Energy */ + 0, + 3, + -2, + 2, + 10, + A_WIS, + SPE_REMOVE_CURSE, + -4 }, + /* Note: Rogue precedes Ranger so that use of `-R' on the command line + retains its traditional meaning. */ + { { "Rogue", 0 }, + { { "Footpad", 0 }, + { "Cutpurse", 0 }, + { "Rogue", 0 }, + { "Pilferer", 0 }, + { "Robber", 0 }, + { "Burglar", 0 }, + { "Filcher", 0 }, + { "Magsman", "Magswoman" }, + { "Thief", 0 } }, + "Issek", + "Mog", + "Kos", /* Nehwon */ + "Rog", + "the Thieves' Guild Hall", + "the Assassins' Guild Hall", + PM_ROGUE, + NON_PM, + NON_PM, + PM_MASTER_OF_THIEVES, + PM_THUG, + PM_MASTER_ASSASSIN, + PM_LEPRECHAUN, + PM_GUARDIAN_NAGA, + S_NYMPH, + S_NAGA, + ART_MASTER_KEY_OF_THIEVERY, + MH_HUMAN | MH_ORC | ROLE_MALE | ROLE_FEMALE | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 7, 7, 7, 10, 7, 6 }, + { 20, 10, 10, 30, 20, 10 }, + /* Init Lower Higher */ + { 10, 0, 0, 8, 1, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 11, /* Energy */ + 10, + 8, + 0, + 1, + 9, + A_INT, + SPE_DETECT_TREASURE, + -4 }, + { { "Ranger", 0 }, + { +#if 0 /* OBSOLETE */ {"Edhel", "Elleth"}, {"Edhel", "Elleth"}, /* elf-maid */ {"Ohtar", "Ohtie"}, /* warrior */ @@ -249,513 +392,678 @@ const struct Role roles[] = { {"Elentar", "Elentari"}, /* Star-king, -queen (Q.) */ "Solonor Thelandira", "Aerdrie Faenya", "Lolth", /* Elven */ #endif - {"Tenderfoot", 0}, - {"Lookout", 0}, - {"Trailblazer", 0}, - {"Reconnoiterer", "Reconnoiteress"}, - {"Scout", 0}, - {"Arbalester", 0}, /* One skilled at crossbows */ - {"Archer", 0}, - {"Sharpshooter", 0}, - {"Marksman", "Markswoman"} }, - "Mercury", "_Venus", "Mars", /* Roman/planets */ - "Ran", "Orion's camp", "the cave of the wumpus", - PM_RANGER, NON_PM, PM_LITTLE_DOG /* Orion & canis major */, - PM_ORION, PM_HUNTER, PM_SCORPIUS, - PM_FOREST_CENTAUR, PM_SCORPION, S_CENTAUR, S_SPIDER, - ART_LONGBOW_OF_DIANA, - MH_HUMAN|MH_ELF|MH_GNOME|MH_ORC | ROLE_MALE|ROLE_FEMALE | - ROLE_NEUTRAL|ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 13, 13, 13, 9, 13, 7 }, - { 30, 10, 10, 20, 20, 10 }, - /* Init Lower Higher */ - { 13, 0, 0, 6, 1, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },12, /* Energy */ - 10, 9, 2, 1, 10, A_INT, SPE_INVISIBILITY, -4 -}, -{ {"Samurai", 0}, { - {"Hatamoto", 0}, /* Banner Knight */ - {"Ronin", 0}, /* no allegiance */ - {"Ninja", "Kunoichi"}, /* secret society */ - {"Joshu", 0}, /* heads a castle */ - {"Ryoshu", 0}, /* has a territory */ - {"Kokushu", 0}, /* heads a province */ - {"Daimyo", 0}, /* a samurai lord */ - {"Kuge", 0}, /* Noble of the Court */ - {"Shogun", 0} },/* supreme commander, warlord */ - "_Amaterasu Omikami", "Raijin", "Susanowo", /* Japanese */ - "Sam", "the Castle of the Taro Clan", "the Shogun's Castle", - PM_SAMURAI, NON_PM, PM_LITTLE_DOG, - PM_LORD_SATO, PM_ROSHI, PM_ASHIKAGA_TAKAUJI, - PM_WOLF, PM_STALKER, S_DOG, S_ELEMENTAL, - ART_TSURUGI_OF_MURAMASA, - MH_HUMAN | ROLE_MALE|ROLE_FEMALE | ROLE_LAWFUL, - /* Str Int Wis Dex Con Cha */ - { 10, 8, 7, 10, 17, 6 }, - { 30, 10, 8, 30, 14, 8 }, - /* Init Lower Higher */ - { 13, 0, 0, 8, 1, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },11, /* Energy */ - 10, 10, 0, 0, 8, A_INT, SPE_CLAIRVOYANCE, -4 -}, -{ {"Tourist", 0}, { - {"Rambler", 0}, - {"Sightseer", 0}, - {"Excursionist",0}, - {"Peregrinator","Peregrinatrix"}, - {"Traveler", 0}, - {"Journeyer", 0}, - {"Voyager", 0}, - {"Explorer", 0}, - {"Adventurer", 0} }, - "Blind Io", "_The Lady", "Offler", /* Discworld */ - "Tou", "Ankh-Morpork", "the Thieves' Guild Hall", - PM_TOURIST, NON_PM, NON_PM, - PM_TWOFLOWER, PM_GUIDE, PM_MASTER_OF_THIEVES, - PM_GIANT_SPIDER, PM_FOREST_CENTAUR, S_SPIDER, S_CENTAUR, - ART_YENDORIAN_EXPRESS_CARD, - MH_HUMAN | ROLE_MALE|ROLE_FEMALE | ROLE_NEUTRAL, - /* Str Int Wis Dex Con Cha */ - { 7, 10, 6, 7, 7, 10 }, - { 15, 10, 10, 15, 30, 20 }, - /* Init Lower Higher */ - { 8, 0, 0, 8, 0, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },14, /* Energy */ - 0, 5, 1, 2, 10, A_INT, SPE_CHARM_MONSTER, -4 -}, -{ {"Valkyrie", 0}, { - {"Stripling", 0}, - {"Skirmisher", 0}, - {"Fighter", 0}, - {"Man-at-arms", "Woman-at-arms"}, - {"Warrior", 0}, - {"Swashbuckler",0}, - {"Hero", "Heroine"}, - {"Champion", 0}, - {"Lord", "Lady"} }, - "Tyr", "Odin", "Loki", /* Norse */ - "Val", "the Shrine of Destiny", "the cave of Surtur", - PM_VALKYRIE, NON_PM, NON_PM /*PM_WINTER_WOLF_CUB*/, - PM_NORN, PM_WARRIOR, PM_LORD_SURTUR, - PM_FIRE_ANT, PM_FIRE_GIANT, S_ANT, S_GIANT, - ART_ORB_OF_FATE, - MH_HUMAN|MH_DWARF | ROLE_FEMALE | ROLE_LAWFUL|ROLE_NEUTRAL, - /* Str Int Wis Dex Con Cha */ - { 10, 7, 7, 7, 10, 7 }, - { 30, 6, 7, 20, 30, 7 }, - /* Init Lower Higher */ - { 14, 0, 0, 8, 2, 0 }, /* Hit points */ - { 1, 0, 0, 1, 0, 1 },10, /* Energy */ - 0, 10,-2, 0, 9, A_WIS, SPE_CONE_OF_COLD, -4 -}, -{ {"Wizard", 0}, { - {"Evoker", 0}, - {"Conjurer", 0}, - {"Thaumaturge", 0}, - {"Magician", 0}, - {"Enchanter", "Enchantress"}, - {"Sorcerer", "Sorceress"}, - {"Necromancer", 0}, - {"Wizard", 0}, - {"Mage", 0} }, - "Ptah", "Thoth", "Anhur", /* Egyptian */ - "Wiz", "the Lonely Tower", "the Tower of Darkness", - PM_WIZARD, NON_PM, PM_KITTEN, - PM_NEFERET_THE_GREEN, PM_APPRENTICE, PM_DARK_ONE, - PM_VAMPIRE_BAT, PM_XORN, S_BAT, S_WRAITH, - ART_EYE_OF_THE_AETHIOPICA, - MH_HUMAN|MH_ELF|MH_GNOME|MH_ORC | ROLE_MALE|ROLE_FEMALE | - ROLE_NEUTRAL|ROLE_CHAOTIC, - /* Str Int Wis Dex Con Cha */ - { 7, 10, 7, 7, 7, 7 }, - { 10, 30, 10, 20, 20, 10 }, - /* Init Lower Higher */ - { 10, 0, 0, 8, 1, 0 }, /* Hit points */ - { 4, 3, 0, 2, 0, 3 },12, /* Energy */ - 0, 1, 0, 3, 10, A_INT, SPE_MAGIC_MISSILE, -4 -}, -/* Array terminator */ -{{0, 0}} + { "Tenderfoot", 0 }, + { "Lookout", 0 }, + { "Trailblazer", 0 }, + { "Reconnoiterer", "Reconnoiteress" }, + { "Scout", 0 }, + { "Arbalester", 0 }, /* One skilled at crossbows */ + { "Archer", 0 }, + { "Sharpshooter", 0 }, + { "Marksman", "Markswoman" } }, + "Mercury", + "_Venus", + "Mars", /* Roman/planets */ + "Ran", + "Orion's camp", + "the cave of the wumpus", + PM_RANGER, + NON_PM, + PM_LITTLE_DOG /* Orion & canis major */, + PM_ORION, + PM_HUNTER, + PM_SCORPIUS, + PM_FOREST_CENTAUR, + PM_SCORPION, + S_CENTAUR, + S_SPIDER, + ART_LONGBOW_OF_DIANA, + MH_HUMAN | MH_ELF | MH_GNOME | MH_ORC | ROLE_MALE | ROLE_FEMALE + | ROLE_NEUTRAL | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 13, 13, 13, 9, 13, 7 }, + { 30, 10, 10, 20, 20, 10 }, + /* Init Lower Higher */ + { 13, 0, 0, 6, 1, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 12, /* Energy */ + 10, + 9, + 2, + 1, + 10, + A_INT, + SPE_INVISIBILITY, + -4 }, + { { "Samurai", 0 }, + { { "Hatamoto", 0 }, /* Banner Knight */ + { "Ronin", 0 }, /* no allegiance */ + { "Ninja", "Kunoichi" }, /* secret society */ + { "Joshu", 0 }, /* heads a castle */ + { "Ryoshu", 0 }, /* has a territory */ + { "Kokushu", 0 }, /* heads a province */ + { "Daimyo", 0 }, /* a samurai lord */ + { "Kuge", 0 }, /* Noble of the Court */ + { "Shogun", 0 } }, /* supreme commander, warlord */ + "_Amaterasu Omikami", + "Raijin", + "Susanowo", /* Japanese */ + "Sam", + "the Castle of the Taro Clan", + "the Shogun's Castle", + PM_SAMURAI, + NON_PM, + PM_LITTLE_DOG, + PM_LORD_SATO, + PM_ROSHI, + PM_ASHIKAGA_TAKAUJI, + PM_WOLF, + PM_STALKER, + S_DOG, + S_ELEMENTAL, + ART_TSURUGI_OF_MURAMASA, + MH_HUMAN | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL, + /* Str Int Wis Dex Con Cha */ + { 10, 8, 7, 10, 17, 6 }, + { 30, 10, 8, 30, 14, 8 }, + /* Init Lower Higher */ + { 13, 0, 0, 8, 1, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 11, /* Energy */ + 10, + 10, + 0, + 0, + 8, + A_INT, + SPE_CLAIRVOYANCE, + -4 }, + { { "Tourist", 0 }, + { { "Rambler", 0 }, + { "Sightseer", 0 }, + { "Excursionist", 0 }, + { "Peregrinator", "Peregrinatrix" }, + { "Traveler", 0 }, + { "Journeyer", 0 }, + { "Voyager", 0 }, + { "Explorer", 0 }, + { "Adventurer", 0 } }, + "Blind Io", + "_The Lady", + "Offler", /* Discworld */ + "Tou", + "Ankh-Morpork", + "the Thieves' Guild Hall", + PM_TOURIST, + NON_PM, + NON_PM, + PM_TWOFLOWER, + PM_GUIDE, + PM_MASTER_OF_THIEVES, + PM_GIANT_SPIDER, + PM_FOREST_CENTAUR, + S_SPIDER, + S_CENTAUR, + ART_YENDORIAN_EXPRESS_CARD, + MH_HUMAN | ROLE_MALE | ROLE_FEMALE | ROLE_NEUTRAL, + /* Str Int Wis Dex Con Cha */ + { 7, 10, 6, 7, 7, 10 }, + { 15, 10, 10, 15, 30, 20 }, + /* Init Lower Higher */ + { 8, 0, 0, 8, 0, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 14, /* Energy */ + 0, + 5, + 1, + 2, + 10, + A_INT, + SPE_CHARM_MONSTER, + -4 }, + { { "Valkyrie", 0 }, + { { "Stripling", 0 }, + { "Skirmisher", 0 }, + { "Fighter", 0 }, + { "Man-at-arms", "Woman-at-arms" }, + { "Warrior", 0 }, + { "Swashbuckler", 0 }, + { "Hero", "Heroine" }, + { "Champion", 0 }, + { "Lord", "Lady" } }, + "Tyr", + "Odin", + "Loki", /* Norse */ + "Val", + "the Shrine of Destiny", + "the cave of Surtur", + PM_VALKYRIE, + NON_PM, + NON_PM /*PM_WINTER_WOLF_CUB*/, + PM_NORN, + PM_WARRIOR, + PM_LORD_SURTUR, + PM_FIRE_ANT, + PM_FIRE_GIANT, + S_ANT, + S_GIANT, + ART_ORB_OF_FATE, + MH_HUMAN | MH_DWARF | ROLE_FEMALE | ROLE_LAWFUL | ROLE_NEUTRAL, + /* Str Int Wis Dex Con Cha */ + { 10, 7, 7, 7, 10, 7 }, + { 30, 6, 7, 20, 30, 7 }, + /* Init Lower Higher */ + { 14, 0, 0, 8, 2, 0 }, /* Hit points */ + { 1, 0, 0, 1, 0, 1 }, + 10, /* Energy */ + 0, + 10, + -2, + 0, + 9, + A_WIS, + SPE_CONE_OF_COLD, + -4 }, + { { "Wizard", 0 }, + { { "Evoker", 0 }, + { "Conjurer", 0 }, + { "Thaumaturge", 0 }, + { "Magician", 0 }, + { "Enchanter", "Enchantress" }, + { "Sorcerer", "Sorceress" }, + { "Necromancer", 0 }, + { "Wizard", 0 }, + { "Mage", 0 } }, + "Ptah", + "Thoth", + "Anhur", /* Egyptian */ + "Wiz", + "the Lonely Tower", + "the Tower of Darkness", + PM_WIZARD, + NON_PM, + PM_KITTEN, + PM_NEFERET_THE_GREEN, + PM_APPRENTICE, + PM_DARK_ONE, + PM_VAMPIRE_BAT, + PM_XORN, + S_BAT, + S_WRAITH, + ART_EYE_OF_THE_AETHIOPICA, + MH_HUMAN | MH_ELF | MH_GNOME | MH_ORC | ROLE_MALE | ROLE_FEMALE + | ROLE_NEUTRAL | ROLE_CHAOTIC, + /* Str Int Wis Dex Con Cha */ + { 7, 10, 7, 7, 7, 7 }, + { 10, 30, 10, 20, 20, 10 }, + /* Init Lower Higher */ + { 10, 0, 0, 8, 1, 0 }, /* Hit points */ + { 4, 3, 0, 2, 0, 3 }, + 12, /* Energy */ + 0, + 1, + 0, + 3, + 10, + A_INT, + SPE_MAGIC_MISSILE, + -4 }, + /* Array terminator */ + { { 0, 0 } } }; - /* The player's role, created at runtime from initial * choices. This may be munged in role_init(). */ -struct Role urole = -{ {"Undefined", 0}, { {0, 0}, {0, 0}, {0, 0}, - {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} }, - "L", "N", "C", "Xxx", "home", "locate", - NON_PM, NON_PM, NON_PM, NON_PM, NON_PM, NON_PM, - NON_PM, NON_PM, 0, 0, 0, 0, - /* Str Int Wis Dex Con Cha */ - { 7, 7, 7, 7, 7, 7 }, - { 20, 15, 15, 20, 20, 10 }, - /* Init Lower Higher */ - { 10, 0, 0, 8, 1, 0 }, /* Hit points */ - { 2, 0, 0, 2, 0, 3 },14, /* Energy */ - 0, 10, 0, 0, 4, A_INT, 0, -3 -}; - - +struct Role urole = { { "Undefined", 0 }, + { { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + "L", + "N", + "C", + "Xxx", + "home", + "locate", + NON_PM, + NON_PM, + NON_PM, + NON_PM, + NON_PM, + NON_PM, + NON_PM, + NON_PM, + 0, + 0, + 0, + 0, + /* Str Int Wis Dex Con Cha */ + { 7, 7, 7, 7, 7, 7 }, + { 20, 15, 15, 20, 20, 10 }, + /* Init Lower Higher */ + { 10, 0, 0, 8, 1, 0 }, /* Hit points */ + { 2, 0, 0, 2, 0, 3 }, + 14, /* Energy */ + 0, + 10, + 0, + 0, + 4, + A_INT, + 0, + -3 }; /* Table of all races */ const struct Race races[] = { -{ "human", "human", "humanity", "Hum", - {"man", "woman"}, - PM_HUMAN, NON_PM, PM_HUMAN_MUMMY, PM_HUMAN_ZOMBIE, - MH_HUMAN | ROLE_MALE|ROLE_FEMALE | - ROLE_LAWFUL|ROLE_NEUTRAL|ROLE_CHAOTIC, - MH_HUMAN, 0, MH_GNOME|MH_ORC, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - { STR18(100), 18, 18, 18, 18, 18 }, - /* Init Lower Higher */ - { 2, 0, 0, 2, 1, 0 }, /* Hit points */ - { 1, 0, 2, 0, 2, 0 } /* Energy */ -}, -{ "elf", "elven", "elvenkind", "Elf", - {0, 0}, - PM_ELF, NON_PM, PM_ELF_MUMMY, PM_ELF_ZOMBIE, - MH_ELF | ROLE_MALE|ROLE_FEMALE | ROLE_CHAOTIC, - MH_ELF, MH_ELF, MH_ORC, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - { 18, 20, 20, 18, 16, 18 }, - /* Init Lower Higher */ - { 1, 0, 0, 1, 1, 0 }, /* Hit points */ - { 2, 0, 3, 0, 3, 0 } /* Energy */ -}, -{ "dwarf", "dwarven", "dwarvenkind", "Dwa", - {0, 0}, - PM_DWARF, NON_PM, PM_DWARF_MUMMY, PM_DWARF_ZOMBIE, - MH_DWARF | ROLE_MALE|ROLE_FEMALE | ROLE_LAWFUL, - MH_DWARF, MH_DWARF|MH_GNOME, MH_ORC, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - { STR18(100), 16, 16, 20, 20, 16 }, - /* Init Lower Higher */ - { 4, 0, 0, 3, 2, 0 }, /* Hit points */ - { 0, 0, 0, 0, 0, 0 } /* Energy */ -}, -{ "gnome", "gnomish", "gnomehood", "Gno", - {0, 0}, - PM_GNOME, NON_PM, PM_GNOME_MUMMY, PM_GNOME_ZOMBIE, - MH_GNOME | ROLE_MALE|ROLE_FEMALE | ROLE_NEUTRAL, - MH_GNOME, MH_DWARF|MH_GNOME, MH_HUMAN, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - {STR18(50),19, 18, 18, 18, 18 }, - /* Init Lower Higher */ - { 1, 0, 0, 1, 0, 0 }, /* Hit points */ - { 2, 0, 2, 0, 2, 0 } /* Energy */ -}, -{ "orc", "orcish", "orcdom", "Orc", - {0, 0}, - PM_ORC, NON_PM, PM_ORC_MUMMY, PM_ORC_ZOMBIE, - MH_ORC | ROLE_MALE|ROLE_FEMALE | ROLE_CHAOTIC, - MH_ORC, 0, MH_HUMAN|MH_ELF|MH_DWARF, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - {STR18(50),16, 16, 18, 18, 16 }, - /* Init Lower Higher */ - { 1, 0, 0, 1, 0, 0 }, /* Hit points */ - { 1, 0, 1, 0, 1, 0 } /* Energy */ -}, -/* Array terminator */ -{ 0, 0, 0, 0 }}; - + { + "human", + "human", + "humanity", + "Hum", + { "man", "woman" }, + PM_HUMAN, + NON_PM, + PM_HUMAN_MUMMY, + PM_HUMAN_ZOMBIE, + MH_HUMAN | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL | ROLE_NEUTRAL + | ROLE_CHAOTIC, + MH_HUMAN, + 0, + MH_GNOME | MH_ORC, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { STR18(100), 18, 18, 18, 18, 18 }, + /* Init Lower Higher */ + { 2, 0, 0, 2, 1, 0 }, /* Hit points */ + { 1, 0, 2, 0, 2, 0 } /* Energy */ + }, + { + "elf", + "elven", + "elvenkind", + "Elf", + { 0, 0 }, + PM_ELF, + NON_PM, + PM_ELF_MUMMY, + PM_ELF_ZOMBIE, + MH_ELF | ROLE_MALE | ROLE_FEMALE | ROLE_CHAOTIC, + MH_ELF, + MH_ELF, + MH_ORC, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { 18, 20, 20, 18, 16, 18 }, + /* Init Lower Higher */ + { 1, 0, 0, 1, 1, 0 }, /* Hit points */ + { 2, 0, 3, 0, 3, 0 } /* Energy */ + }, + { + "dwarf", + "dwarven", + "dwarvenkind", + "Dwa", + { 0, 0 }, + PM_DWARF, + NON_PM, + PM_DWARF_MUMMY, + PM_DWARF_ZOMBIE, + MH_DWARF | ROLE_MALE | ROLE_FEMALE | ROLE_LAWFUL, + MH_DWARF, + MH_DWARF | MH_GNOME, + MH_ORC, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { STR18(100), 16, 16, 20, 20, 16 }, + /* Init Lower Higher */ + { 4, 0, 0, 3, 2, 0 }, /* Hit points */ + { 0, 0, 0, 0, 0, 0 } /* Energy */ + }, + { + "gnome", + "gnomish", + "gnomehood", + "Gno", + { 0, 0 }, + PM_GNOME, + NON_PM, + PM_GNOME_MUMMY, + PM_GNOME_ZOMBIE, + MH_GNOME | ROLE_MALE | ROLE_FEMALE | ROLE_NEUTRAL, + MH_GNOME, + MH_DWARF | MH_GNOME, + MH_HUMAN, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { STR18(50), 19, 18, 18, 18, 18 }, + /* Init Lower Higher */ + { 1, 0, 0, 1, 0, 0 }, /* Hit points */ + { 2, 0, 2, 0, 2, 0 } /* Energy */ + }, + { + "orc", + "orcish", + "orcdom", + "Orc", + { 0, 0 }, + PM_ORC, + NON_PM, + PM_ORC_MUMMY, + PM_ORC_ZOMBIE, + MH_ORC | ROLE_MALE | ROLE_FEMALE | ROLE_CHAOTIC, + MH_ORC, + 0, + MH_HUMAN | MH_ELF | MH_DWARF, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { STR18(50), 16, 16, 18, 18, 16 }, + /* Init Lower Higher */ + { 1, 0, 0, 1, 0, 0 }, /* Hit points */ + { 1, 0, 1, 0, 1, 0 } /* Energy */ + }, + /* Array terminator */ + { 0, 0, 0, 0 } +}; /* The player's race, created at runtime from initial * choices. This may be munged in role_init(). */ -struct Race urace = -{ "something", "undefined", "something", "Xxx", - {0, 0}, - NON_PM, NON_PM, NON_PM, NON_PM, - 0, 0, 0, 0, - /* Str Int Wis Dex Con Cha */ - { 3, 3, 3, 3, 3, 3 }, - { STR18(100), 18, 18, 18, 18, 18 }, - /* Init Lower Higher */ - { 2, 0, 0, 2, 1, 0 }, /* Hit points */ - { 1, 0, 2, 0, 2, 0 } /* Energy */ +struct Race urace = { + "something", + "undefined", + "something", + "Xxx", + { 0, 0 }, + NON_PM, + NON_PM, + NON_PM, + NON_PM, + 0, + 0, + 0, + 0, + /* Str Int Wis Dex Con Cha */ + { 3, 3, 3, 3, 3, 3 }, + { STR18(100), 18, 18, 18, 18, 18 }, + /* Init Lower Higher */ + { 2, 0, 0, 2, 1, 0 }, /* Hit points */ + { 1, 0, 2, 0, 2, 0 } /* Energy */ }; - /* Table of all genders */ const struct Gender genders[] = { - {"male", "he", "him", "his", "Mal", ROLE_MALE}, - {"female", "she", "her", "her", "Fem", ROLE_FEMALE}, - {"neuter", "it", "it", "its", "Ntr", ROLE_NEUTER} + { "male", "he", "him", "his", "Mal", ROLE_MALE }, + { "female", "she", "her", "her", "Fem", ROLE_FEMALE }, + { "neuter", "it", "it", "its", "Ntr", ROLE_NEUTER } }; - /* Table of all alignments */ const struct Align aligns[] = { - {"law", "lawful", "Law", ROLE_LAWFUL, A_LAWFUL}, - {"balance", "neutral", "Neu", ROLE_NEUTRAL, A_NEUTRAL}, - {"chaos", "chaotic", "Cha", ROLE_CHAOTIC, A_CHAOTIC}, - {"evil", "unaligned", "Una", 0, A_NONE} + { "law", "lawful", "Law", ROLE_LAWFUL, A_LAWFUL }, + { "balance", "neutral", "Neu", ROLE_NEUTRAL, A_NEUTRAL }, + { "chaos", "chaotic", "Cha", ROLE_CHAOTIC, A_CHAOTIC }, + { "evil", "unaligned", "Una", 0, A_NONE } }; /* Filters */ static struct { - boolean roles[SIZE(roles)]; - short mask; + boolean roles[SIZE(roles)]; + short mask; } filter; -STATIC_DCL char * FDECL(promptsep, (char *, int)); +STATIC_DCL char *FDECL(promptsep, (char *, int)); STATIC_DCL int FDECL(role_gendercount, (int)); STATIC_DCL int FDECL(race_alignmentcount, (int)); /* used by str2XXX() */ static char NEARDATA randomstr[] = "random"; - boolean validrole(rolenum) - int rolenum; +int rolenum; { - return (rolenum >= 0 && rolenum < SIZE(roles)-1); + return (rolenum >= 0 && rolenum < SIZE(roles) - 1); } - int randrole() { - return (rn2(SIZE(roles)-1)); + return (rn2(SIZE(roles) - 1)); } - int str2role(str) - const char *str; +const char *str; { - int i, len; + int i, len; - /* Is str valid? */ - if (!str || !str[0]) - return ROLE_NONE; + /* Is str valid? */ + if (!str || !str[0]) + return ROLE_NONE; - /* Match as much of str as is provided */ - len = strlen(str); - for (i = 0; roles[i].name.m; i++) { - /* Does it match the male name? */ - if (!strncmpi(str, roles[i].name.m, len)) - return i; - /* Or the female name? */ - if (roles[i].name.f && !strncmpi(str, roles[i].name.f, len)) - return i; - /* Or the filecode? */ - if (!strcmpi(str, roles[i].filecode)) - return i; - } + /* Match as much of str as is provided */ + len = strlen(str); + for (i = 0; roles[i].name.m; i++) { + /* Does it match the male name? */ + if (!strncmpi(str, roles[i].name.m, len)) + return i; + /* Or the female name? */ + if (roles[i].name.f && !strncmpi(str, roles[i].name.f, len)) + return i; + /* Or the filecode? */ + if (!strcmpi(str, roles[i].filecode)) + return i; + } - if ((len == 1 && (*str == '*' || *str == '@')) || - !strncmpi(str, randomstr, len)) - return ROLE_RANDOM; + if ((len == 1 && (*str == '*' || *str == '@')) + || !strncmpi(str, randomstr, len)) + return ROLE_RANDOM; - /* Couldn't find anything appropriate */ - return ROLE_NONE; + /* Couldn't find anything appropriate */ + return ROLE_NONE; } - boolean validrace(rolenum, racenum) - int rolenum, racenum; +int rolenum, racenum; { - /* Assumes validrole */ - return (racenum >= 0 && racenum < SIZE(races)-1 && - (roles[rolenum].allow & races[racenum].allow & ROLE_RACEMASK)); + /* Assumes validrole */ + return (racenum >= 0 && racenum < SIZE(races) - 1 + && (roles[rolenum].allow & races[racenum].allow & ROLE_RACEMASK)); } - int randrace(rolenum) - int rolenum; +int rolenum; { - int i, n = 0; + int i, n = 0; - /* Count the number of valid races */ - for (i = 0; races[i].noun; i++) - if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) - n++; + /* Count the number of valid races */ + for (i = 0; races[i].noun; i++) + if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) + n++; - /* Pick a random race */ - /* Use a factor of 100 in case of bad random number generators */ - if (n) n = rn2(n*100)/100; - for (i = 0; races[i].noun; i++) - if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) { - if (n) n--; - else return (i); - } + /* Pick a random race */ + /* Use a factor of 100 in case of bad random number generators */ + if (n) + n = rn2(n * 100) / 100; + for (i = 0; races[i].noun; i++) + if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) { + if (n) + n--; + else + return (i); + } - /* This role has no permitted races? */ - return (rn2(SIZE(races)-1)); + /* This role has no permitted races? */ + return (rn2(SIZE(races) - 1)); } - int str2race(str) - const char *str; +const char *str; { - int i, len; + int i, len; - /* Is str valid? */ - if (!str || !str[0]) - return ROLE_NONE; + /* Is str valid? */ + if (!str || !str[0]) + return ROLE_NONE; - /* Match as much of str as is provided */ - len = strlen(str); - for (i = 0; races[i].noun; i++) { - /* Does it match the noun? */ - if (!strncmpi(str, races[i].noun, len)) - return i; - /* Or the filecode? */ - if (!strcmpi(str, races[i].filecode)) - return i; - } + /* Match as much of str as is provided */ + len = strlen(str); + for (i = 0; races[i].noun; i++) { + /* Does it match the noun? */ + if (!strncmpi(str, races[i].noun, len)) + return i; + /* Or the filecode? */ + if (!strcmpi(str, races[i].filecode)) + return i; + } - if ((len == 1 && (*str == '*' || *str == '@')) || - !strncmpi(str, randomstr, len)) - return ROLE_RANDOM; + if ((len == 1 && (*str == '*' || *str == '@')) + || !strncmpi(str, randomstr, len)) + return ROLE_RANDOM; - /* Couldn't find anything appropriate */ - return ROLE_NONE; + /* Couldn't find anything appropriate */ + return ROLE_NONE; } - boolean validgend(rolenum, racenum, gendnum) - int rolenum, racenum, gendnum; +int rolenum, racenum, gendnum; { - /* Assumes validrole and validrace */ - return (gendnum >= 0 && gendnum < ROLE_GENDERS && - (roles[rolenum].allow & races[racenum].allow & - genders[gendnum].allow & ROLE_GENDMASK)); + /* Assumes validrole and validrace */ + return (gendnum >= 0 && gendnum < ROLE_GENDERS + && (roles[rolenum].allow & races[racenum].allow + & genders[gendnum].allow & ROLE_GENDMASK)); } - int randgend(rolenum, racenum) - int rolenum, racenum; +int rolenum, racenum; { - int i, n = 0; + int i, n = 0; - /* Count the number of valid genders */ - for (i = 0; i < ROLE_GENDERS; i++) - if (roles[rolenum].allow & races[racenum].allow & - genders[i].allow & ROLE_GENDMASK) - n++; + /* Count the number of valid genders */ + for (i = 0; i < ROLE_GENDERS; i++) + if (roles[rolenum].allow & races[racenum].allow & genders[i].allow + & ROLE_GENDMASK) + n++; - /* Pick a random gender */ - if (n) n = rn2(n); - for (i = 0; i < ROLE_GENDERS; i++) - if (roles[rolenum].allow & races[racenum].allow & - genders[i].allow & ROLE_GENDMASK) { - if (n) n--; - else return (i); - } + /* Pick a random gender */ + if (n) + n = rn2(n); + for (i = 0; i < ROLE_GENDERS; i++) + if (roles[rolenum].allow & races[racenum].allow & genders[i].allow + & ROLE_GENDMASK) { + if (n) + n--; + else + return (i); + } - /* This role/race has no permitted genders? */ - return (rn2(ROLE_GENDERS)); + /* This role/race has no permitted genders? */ + return (rn2(ROLE_GENDERS)); } - int str2gend(str) - char *str; +char *str; { - int i, len; + int i, len; - /* Is str valid? */ - if (!str || !str[0]) - return ROLE_NONE; + /* Is str valid? */ + if (!str || !str[0]) + return ROLE_NONE; - /* Match as much of str as is provided */ - len = strlen(str); - for (i = 0; i < ROLE_GENDERS; i++) { - /* Does it match the adjective? */ - if (!strncmpi(str, genders[i].adj, len)) - return i; - /* Or the filecode? */ - if (!strcmpi(str, genders[i].filecode)) - return i; - } - if ((len == 1 && (*str == '*' || *str == '@')) || - !strncmpi(str, randomstr, len)) - return ROLE_RANDOM; + /* Match as much of str as is provided */ + len = strlen(str); + for (i = 0; i < ROLE_GENDERS; i++) { + /* Does it match the adjective? */ + if (!strncmpi(str, genders[i].adj, len)) + return i; + /* Or the filecode? */ + if (!strcmpi(str, genders[i].filecode)) + return i; + } + if ((len == 1 && (*str == '*' || *str == '@')) + || !strncmpi(str, randomstr, len)) + return ROLE_RANDOM; - /* Couldn't find anything appropriate */ - return ROLE_NONE; + /* Couldn't find anything appropriate */ + return ROLE_NONE; } - boolean validalign(rolenum, racenum, alignnum) - int rolenum, racenum, alignnum; +int rolenum, racenum, alignnum; { - /* Assumes validrole and validrace */ - return (alignnum >= 0 && alignnum < ROLE_ALIGNS && - (roles[rolenum].allow & races[racenum].allow & - aligns[alignnum].allow & ROLE_ALIGNMASK)); + /* Assumes validrole and validrace */ + return (alignnum >= 0 && alignnum < ROLE_ALIGNS + && (roles[rolenum].allow & races[racenum].allow + & aligns[alignnum].allow & ROLE_ALIGNMASK)); } - int randalign(rolenum, racenum) - int rolenum, racenum; +int rolenum, racenum; { - int i, n = 0; + int i, n = 0; - /* Count the number of valid alignments */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (roles[rolenum].allow & races[racenum].allow & - aligns[i].allow & ROLE_ALIGNMASK) - n++; + /* Count the number of valid alignments */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (roles[rolenum].allow & races[racenum].allow & aligns[i].allow + & ROLE_ALIGNMASK) + n++; - /* Pick a random alignment */ - if (n) n = rn2(n); - for (i = 0; i < ROLE_ALIGNS; i++) - if (roles[rolenum].allow & races[racenum].allow & - aligns[i].allow & ROLE_ALIGNMASK) { - if (n) n--; - else return (i); - } + /* Pick a random alignment */ + if (n) + n = rn2(n); + for (i = 0; i < ROLE_ALIGNS; i++) + if (roles[rolenum].allow & races[racenum].allow & aligns[i].allow + & ROLE_ALIGNMASK) { + if (n) + n--; + else + return (i); + } - /* This role/race has no permitted alignments? */ - return (rn2(ROLE_ALIGNS)); + /* This role/race has no permitted alignments? */ + return (rn2(ROLE_ALIGNS)); } - int str2align(str) - char *str; +char *str; { - int i, len; + int i, len; - /* Is str valid? */ - if (!str || !str[0]) - return ROLE_NONE; + /* Is str valid? */ + if (!str || !str[0]) + return ROLE_NONE; - /* Match as much of str as is provided */ - len = strlen(str); - for (i = 0; i < ROLE_ALIGNS; i++) { - /* Does it match the adjective? */ - if (!strncmpi(str, aligns[i].adj, len)) - return i; - /* Or the filecode? */ - if (!strcmpi(str, aligns[i].filecode)) - return i; - } - if ((len == 1 && (*str == '*' || *str == '@')) || - !strncmpi(str, randomstr, len)) - return ROLE_RANDOM; + /* Match as much of str as is provided */ + len = strlen(str); + for (i = 0; i < ROLE_ALIGNS; i++) { + /* Does it match the adjective? */ + if (!strncmpi(str, aligns[i].adj, len)) + return i; + /* Or the filecode? */ + if (!strcmpi(str, aligns[i].filecode)) + return i; + } + if ((len == 1 && (*str == '*' || *str == '@')) + || !strncmpi(str, randomstr, len)) + return ROLE_RANDOM; - /* Couldn't find anything appropriate */ - return ROLE_NONE; + /* Couldn't find anything appropriate */ + return ROLE_NONE; } /* is rolenum compatible with any racenum/gendnum/alignnum constraints? */ @@ -766,35 +1074,35 @@ int rolenum, racenum, gendnum, alignnum; int i; short allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1) { - allow = roles[rolenum].allow; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_RACEMASK)) - return FALSE; - if (gendnum >= 0 && gendnum < ROLE_GENDERS && - !(allow & genders[gendnum].allow & ROLE_GENDMASK)) - return FALSE; - if (alignnum >= 0 && alignnum < ROLE_ALIGNS && - !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) - return FALSE; - if (filter.roles[rolenum]) - return FALSE; - return TRUE; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1) { + allow = roles[rolenum].allow; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_RACEMASK)) + return FALSE; + if (gendnum >= 0 && gendnum < ROLE_GENDERS + && !(allow & genders[gendnum].allow & ROLE_GENDMASK)) + return FALSE; + if (alignnum >= 0 && alignnum < ROLE_ALIGNS + && !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) + return FALSE; + if (filter.roles[rolenum]) + return FALSE; + return TRUE; } else { - for (i = 0; i < SIZE(roles)-1; i++) { - allow = roles[i].allow; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_RACEMASK)) - continue; - if (gendnum >= 0 && gendnum < ROLE_GENDERS && - !(allow & genders[gendnum].allow & ROLE_GENDMASK)) - continue; - if (alignnum >= 0 && alignnum < ROLE_ALIGNS && - !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) - continue; - return TRUE; - } - return FALSE; + for (i = 0; i < SIZE(roles) - 1; i++) { + allow = roles[i].allow; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_RACEMASK)) + continue; + if (gendnum >= 0 && gendnum < ROLE_GENDERS + && !(allow & genders[gendnum].allow & ROLE_GENDMASK)) + continue; + if (alignnum >= 0 && alignnum < ROLE_ALIGNS + && !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) + continue; + return TRUE; + } + return FALSE; } } @@ -808,20 +1116,20 @@ int racenum, gendnum, alignnum, pickhow; int i; int roles_ok = 0; - for (i = 0; i < SIZE(roles)-1; i++) { - if (ok_role(i, racenum, gendnum, alignnum)) - roles_ok++; + for (i = 0; i < SIZE(roles) - 1; i++) { + if (ok_role(i, racenum, gendnum, alignnum)) + roles_ok++; } if (roles_ok == 0 || (roles_ok > 1 && pickhow == PICK_RIGID)) - return ROLE_NONE; + return ROLE_NONE; roles_ok = rn2(roles_ok); - for (i = 0; i < SIZE(roles)-1; i++) { - if (ok_role(i, racenum, gendnum, alignnum)) { - if (roles_ok == 0) - return i; - else - roles_ok--; - } + for (i = 0; i < SIZE(roles) - 1; i++) { + if (ok_role(i, racenum, gendnum, alignnum)) { + if (roles_ok == 0) + return i; + else + roles_ok--; + } } return ROLE_NONE; } @@ -834,35 +1142,35 @@ int rolenum, racenum, gendnum, alignnum; int i; short allow; - if (racenum >= 0 && racenum < SIZE(races)-1) { - allow = races[racenum].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_RACEMASK)) - return FALSE; - if (gendnum >= 0 && gendnum < ROLE_GENDERS && - !(allow & genders[gendnum].allow & ROLE_GENDMASK)) - return FALSE; - if (alignnum >= 0 && alignnum < ROLE_ALIGNS && - !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) - return FALSE; - if (filter.mask & races[racenum].selfmask) - return FALSE; - return TRUE; + if (racenum >= 0 && racenum < SIZE(races) - 1) { + allow = races[racenum].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_RACEMASK)) + return FALSE; + if (gendnum >= 0 && gendnum < ROLE_GENDERS + && !(allow & genders[gendnum].allow & ROLE_GENDMASK)) + return FALSE; + if (alignnum >= 0 && alignnum < ROLE_ALIGNS + && !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) + return FALSE; + if (filter.mask & races[racenum].selfmask) + return FALSE; + return TRUE; } else { - for (i = 0; i < SIZE(races)-1; i++) { - allow = races[i].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_RACEMASK)) - continue; - if (gendnum >= 0 && gendnum < ROLE_GENDERS && - !(allow & genders[gendnum].allow & ROLE_GENDMASK)) - continue; - if (alignnum >= 0 && alignnum < ROLE_ALIGNS && - !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) - continue; - return TRUE; - } - return FALSE; + for (i = 0; i < SIZE(races) - 1; i++) { + allow = races[i].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_RACEMASK)) + continue; + if (gendnum >= 0 && gendnum < ROLE_GENDERS + && !(allow & genders[gendnum].allow & ROLE_GENDMASK)) + continue; + if (alignnum >= 0 && alignnum < ROLE_ALIGNS + && !(allow & aligns[alignnum].allow & ROLE_ALIGNMASK)) + continue; + return TRUE; + } + return FALSE; } } @@ -876,20 +1184,20 @@ int rolenum, gendnum, alignnum, pickhow; int i; int races_ok = 0; - for (i = 0; i < SIZE(races)-1; i++) { - if (ok_race(rolenum, i, gendnum, alignnum)) - races_ok++; + for (i = 0; i < SIZE(races) - 1; i++) { + if (ok_race(rolenum, i, gendnum, alignnum)) + races_ok++; } if (races_ok == 0 || (races_ok > 1 && pickhow == PICK_RIGID)) - return ROLE_NONE; + return ROLE_NONE; races_ok = rn2(races_ok); - for (i = 0; i < SIZE(races)-1; i++) { - if (ok_race(rolenum, i, gendnum, alignnum)) { - if (races_ok == 0) - return i; - else - races_ok--; - } + for (i = 0; i < SIZE(races) - 1; i++) { + if (ok_race(rolenum, i, gendnum, alignnum)) { + if (races_ok == 0) + return i; + else + races_ok--; + } } return ROLE_NONE; } @@ -905,28 +1213,28 @@ int alignnum UNUSED; short allow; if (gendnum >= 0 && gendnum < ROLE_GENDERS) { - allow = genders[gendnum].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_GENDMASK)) - return FALSE; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_GENDMASK)) - return FALSE; - if (filter.mask & genders[gendnum].allow) - return FALSE; - return TRUE; + allow = genders[gendnum].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_GENDMASK)) + return FALSE; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_GENDMASK)) + return FALSE; + if (filter.mask & genders[gendnum].allow) + return FALSE; + return TRUE; } else { - for (i = 0; i < ROLE_GENDERS; i++) { - allow = genders[i].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_GENDMASK)) - continue; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_GENDMASK)) - continue; - return TRUE; - } - return FALSE; + for (i = 0; i < ROLE_GENDERS; i++) { + allow = genders[i].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_GENDMASK)) + continue; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_GENDMASK)) + continue; + return TRUE; + } + return FALSE; } } @@ -942,19 +1250,19 @@ int rolenum, racenum, alignnum, pickhow; int gends_ok = 0; for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(rolenum, racenum, i, alignnum)) - gends_ok++; + if (ok_gend(rolenum, racenum, i, alignnum)) + gends_ok++; } if (gends_ok == 0 || (gends_ok > 1 && pickhow == PICK_RIGID)) - return ROLE_NONE; + return ROLE_NONE; gends_ok = rn2(gends_ok); for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(rolenum, racenum, i, alignnum)) { - if (gends_ok == 0) - return i; - else - gends_ok--; - } + if (ok_gend(rolenum, racenum, i, alignnum)) { + if (gends_ok == 0) + return i; + else + gends_ok--; + } } return ROLE_NONE; } @@ -971,32 +1279,33 @@ int alignnum; short allow; if (alignnum >= 0 && alignnum < ROLE_ALIGNS) { - allow = aligns[alignnum].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_ALIGNMASK)) - return FALSE; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_ALIGNMASK)) - return FALSE; - if (filter.mask & aligns[alignnum].allow) - return FALSE; - return TRUE; + allow = aligns[alignnum].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_ALIGNMASK)) + return FALSE; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_ALIGNMASK)) + return FALSE; + if (filter.mask & aligns[alignnum].allow) + return FALSE; + return TRUE; } else { - for (i = 0; i < ROLE_ALIGNS; i++) { - allow = aligns[i].allow; - if (rolenum >= 0 && rolenum < SIZE(roles)-1 && - !(allow & roles[rolenum].allow & ROLE_ALIGNMASK)) - continue; - if (racenum >= 0 && racenum < SIZE(races)-1 && - !(allow & races[racenum].allow & ROLE_ALIGNMASK)) - continue; - return TRUE; - } - return FALSE; + for (i = 0; i < ROLE_ALIGNS; i++) { + allow = aligns[i].allow; + if (rolenum >= 0 && rolenum < SIZE(roles) - 1 + && !(allow & roles[rolenum].allow & ROLE_ALIGNMASK)) + continue; + if (racenum >= 0 && racenum < SIZE(races) - 1 + && !(allow & races[racenum].allow & ROLE_ALIGNMASK)) + continue; + return TRUE; + } + return FALSE; } } -/* pick a random alignment subject to any rolenum/racenum/gendnum constraints */ +/* pick a random alignment subject to any rolenum/racenum/gendnum constraints + */ /* alignment and gender are not comparable (and also not constrainable) */ /* If pickhow == PICK_RIGID an alignment is returned only if there is */ /* a single possibility */ @@ -1008,19 +1317,19 @@ int rolenum, racenum, gendnum, pickhow; int aligns_ok = 0; for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(rolenum, racenum, gendnum, i)) - aligns_ok++; + if (ok_align(rolenum, racenum, gendnum, i)) + aligns_ok++; } if (aligns_ok == 0 || (aligns_ok > 1 && pickhow == PICK_RIGID)) - return ROLE_NONE; + return ROLE_NONE; aligns_ok = rn2(aligns_ok); for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(rolenum, racenum, gendnum, i)) { - if (aligns_ok == 0) - return i; - else - aligns_ok--; - } + if (ok_align(rolenum, racenum, gendnum, i)) { + if (aligns_ok == 0) + return i; + else + aligns_ok--; + } } return ROLE_NONE; } @@ -1037,25 +1346,25 @@ rigid_role_checks() * */ if (flags.initrole == ROLE_RANDOM) { - /* If the role was explicitly specified as ROLE_RANDOM - * via -uXXXX-@ then choose the role in here to narrow down - * later choices. Pick a random role in this case. - */ - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) - flags.initrole = randrole(); + /* If the role was explicitly specified as ROLE_RANDOM + * via -uXXXX-@ then choose the role in here to narrow down + * later choices. Pick a random role in this case. + */ + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) + flags.initrole = randrole(); } if (flags.initrole != ROLE_NONE) { - if (flags.initrace == ROLE_NONE) - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RIGID); - if (flags.initalign == ROLE_NONE) - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RIGID); - if (flags.initgend == ROLE_NONE) - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RIGID); + if (flags.initrace == ROLE_NONE) + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RIGID); + if (flags.initalign == ROLE_NONE) + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RIGID); + if (flags.initgend == ROLE_NONE) + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RIGID); } } @@ -1063,27 +1372,27 @@ boolean setrolefilter(bufp) char *bufp; { - int i; - boolean reslt = TRUE; + int i; + boolean reslt = TRUE; - if ((i=str2role(bufp)) != ROLE_NONE && i != ROLE_RANDOM) - filter.roles[i] = TRUE; - else if ((i=str2race(bufp)) != ROLE_NONE && i != ROLE_RANDOM) - filter.mask |= races[i].selfmask; - else if ((i=str2gend(bufp)) != ROLE_NONE && i != ROLE_RANDOM) - filter.mask |= genders[i].allow; - else if ((i=str2align(bufp)) != ROLE_NONE && i != ROLE_RANDOM) - filter.mask |= aligns[i].allow; - else - reslt = FALSE; - return reslt; + if ((i = str2role(bufp)) != ROLE_NONE && i != ROLE_RANDOM) + filter.roles[i] = TRUE; + else if ((i = str2race(bufp)) != ROLE_NONE && i != ROLE_RANDOM) + filter.mask |= races[i].selfmask; + else if ((i = str2gend(bufp)) != ROLE_NONE && i != ROLE_RANDOM) + filter.mask |= genders[i].allow; + else if ((i = str2align(bufp)) != ROLE_NONE && i != ROLE_RANDOM) + filter.mask |= aligns[i].allow; + else + reslt = FALSE; + return reslt; } -#define BP_ALIGN 0 -#define BP_GEND 1 -#define BP_RACE 2 -#define BP_ROLE 3 -#define NUM_BP 4 +#define BP_ALIGN 0 +#define BP_GEND 1 +#define BP_RACE 2 +#define BP_ROLE 3 +#define NUM_BP 4 STATIC_VAR char pa[NUM_BP], post_attribs; @@ -1092,178 +1401,198 @@ promptsep(buf, num_post_attribs) char *buf; int num_post_attribs; { - const char *conjuct = "and "; - if (num_post_attribs > 1 - && post_attribs < num_post_attribs && post_attribs > 1) - Strcat(buf, ","); - Strcat(buf, " "); - --post_attribs; - if (!post_attribs && num_post_attribs > 1) Strcat(buf, conjuct); - return buf; + const char *conjuct = "and "; + if (num_post_attribs > 1 && post_attribs < num_post_attribs + && post_attribs > 1) + Strcat(buf, ","); + Strcat(buf, " "); + --post_attribs; + if (!post_attribs && num_post_attribs > 1) + Strcat(buf, conjuct); + return buf; } STATIC_OVL int role_gendercount(rolenum) int rolenum; { - int gendcount = 0; - if (validrole(rolenum)) { - if (roles[rolenum].allow & ROLE_MALE) ++gendcount; - if (roles[rolenum].allow & ROLE_FEMALE) ++gendcount; - if (roles[rolenum].allow & ROLE_NEUTER) ++gendcount; - } - return gendcount; + int gendcount = 0; + if (validrole(rolenum)) { + if (roles[rolenum].allow & ROLE_MALE) + ++gendcount; + if (roles[rolenum].allow & ROLE_FEMALE) + ++gendcount; + if (roles[rolenum].allow & ROLE_NEUTER) + ++gendcount; + } + return gendcount; } STATIC_OVL int race_alignmentcount(racenum) int racenum; { - int aligncount = 0; - if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) { - if (races[racenum].allow & ROLE_CHAOTIC) ++aligncount; - if (races[racenum].allow & ROLE_LAWFUL) ++aligncount; - if (races[racenum].allow & ROLE_NEUTRAL) ++aligncount; - } - return aligncount; + int aligncount = 0; + if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) { + if (races[racenum].allow & ROLE_CHAOTIC) + ++aligncount; + if (races[racenum].allow & ROLE_LAWFUL) + ++aligncount; + if (races[racenum].allow & ROLE_NEUTRAL) + ++aligncount; + } + return aligncount; } char * -root_plselection_prompt(suppliedbuf, buflen, rolenum, racenum, gendnum, alignnum) +root_plselection_prompt(suppliedbuf, buflen, rolenum, racenum, gendnum, + alignnum) char *suppliedbuf; int buflen, rolenum, racenum, gendnum, alignnum; { - int k, gendercount = 0, aligncount = 0; - char buf[BUFSZ]; - static char err_ret[] = " character's"; - boolean donefirst = FALSE; + int k, gendercount = 0, aligncount = 0; + char buf[BUFSZ]; + static char err_ret[] = " character's"; + boolean donefirst = FALSE; - if (!suppliedbuf || buflen < 1) return err_ret; + if (!suppliedbuf || buflen < 1) + return err_ret; - /* initialize these static variables each time this is called */ - post_attribs = 0; - for (k=0; k < NUM_BP; ++k) - pa[k] = 0; - buf[0] = '\0'; - *suppliedbuf = '\0'; - - /* How many alignments are allowed for the desired race? */ - if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) - aligncount = race_alignmentcount(racenum); + /* initialize these static variables each time this is called */ + post_attribs = 0; + for (k = 0; k < NUM_BP; ++k) + pa[k] = 0; + buf[0] = '\0'; + *suppliedbuf = '\0'; - if (alignnum != ROLE_NONE && alignnum != ROLE_RANDOM && - ok_align(rolenum, racenum, gendnum, alignnum)) { - /* if race specified, and multiple choice of alignments for it */ - if ((racenum >= 0) && (aligncount > 1)) { - if (donefirst) Strcat(buf, " "); - Strcat(buf, aligns[alignnum].adj); - donefirst = TRUE; - } else { - if (donefirst) Strcat(buf, " "); - Strcat(buf, aligns[alignnum].adj); - donefirst = TRUE; - } - } else { - /* in case we got here by failing the ok_align() test */ - if (alignnum != ROLE_RANDOM) alignnum = ROLE_NONE; - /* if alignment not specified, but race is specified - and only one choice of alignment for that race then - don't include it in the later list */ - if ((((racenum != ROLE_NONE && racenum != ROLE_RANDOM) && - ok_race(rolenum, racenum, gendnum, alignnum)) - && (aligncount > 1)) - || (racenum == ROLE_NONE || racenum == ROLE_RANDOM)) { - pa[BP_ALIGN] = 1; - post_attribs++; - } - } - /* */ + /* How many alignments are allowed for the desired race? */ + if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) + aligncount = race_alignmentcount(racenum); - /* How many genders are allowed for the desired role? */ - if (validrole(rolenum)) - gendercount = role_gendercount(rolenum); + if (alignnum != ROLE_NONE && alignnum != ROLE_RANDOM + && ok_align(rolenum, racenum, gendnum, alignnum)) { + /* if race specified, and multiple choice of alignments for it */ + if ((racenum >= 0) && (aligncount > 1)) { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, aligns[alignnum].adj); + donefirst = TRUE; + } else { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, aligns[alignnum].adj); + donefirst = TRUE; + } + } else { + /* in case we got here by failing the ok_align() test */ + if (alignnum != ROLE_RANDOM) + alignnum = ROLE_NONE; + /* if alignment not specified, but race is specified + and only one choice of alignment for that race then + don't include it in the later list */ + if ((((racenum != ROLE_NONE && racenum != ROLE_RANDOM) + && ok_race(rolenum, racenum, gendnum, alignnum)) + && (aligncount > 1)) + || (racenum == ROLE_NONE || racenum == ROLE_RANDOM)) { + pa[BP_ALIGN] = 1; + post_attribs++; + } + } + /* */ - if (gendnum != ROLE_NONE && gendnum != ROLE_RANDOM) { - if (validrole(rolenum)) { - /* if role specified, and multiple choice of genders for it, - and name of role itself does not distinguish gender */ - if ((rolenum != ROLE_NONE) && (gendercount > 1) - && !roles[rolenum].name.f) { - if (donefirst) Strcat(buf, " "); - Strcat(buf, genders[gendnum].adj); - donefirst = TRUE; - } - } else { - if (donefirst) Strcat(buf, " "); - Strcat(buf, genders[gendnum].adj); - donefirst = TRUE; - } - } else { - /* if gender not specified, but role is specified - and only one choice of gender then - don't include it in the later list */ - if ((validrole(rolenum) && (gendercount > 1)) || !validrole(rolenum)) { - pa[BP_GEND] = 1; - post_attribs++; - } - } - /* */ + /* How many genders are allowed for the desired role? */ + if (validrole(rolenum)) + gendercount = role_gendercount(rolenum); - if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) { - if (validrole(rolenum) && ok_race(rolenum, racenum, gendnum, alignnum)) { - if (donefirst) Strcat(buf, " "); - Strcat(buf, (rolenum == ROLE_NONE) ? - races[racenum].noun : - races[racenum].adj); - donefirst = TRUE; - } else if (!validrole(rolenum)) { - if (donefirst) Strcat(buf, " "); - Strcat(buf, races[racenum].noun); - donefirst = TRUE; - } else { - pa[BP_RACE] = 1; - post_attribs++; - } - } else { - pa[BP_RACE] = 1; - post_attribs++; - } - /* || */ + if (gendnum != ROLE_NONE && gendnum != ROLE_RANDOM) { + if (validrole(rolenum)) { + /* if role specified, and multiple choice of genders for it, + and name of role itself does not distinguish gender */ + if ((rolenum != ROLE_NONE) && (gendercount > 1) + && !roles[rolenum].name.f) { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, genders[gendnum].adj); + donefirst = TRUE; + } + } else { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, genders[gendnum].adj); + donefirst = TRUE; + } + } else { + /* if gender not specified, but role is specified + and only one choice of gender then + don't include it in the later list */ + if ((validrole(rolenum) && (gendercount > 1)) + || !validrole(rolenum)) { + pa[BP_GEND] = 1; + post_attribs++; + } + } + /* */ - if (validrole(rolenum)) { - if (donefirst) Strcat(buf, " "); - if (gendnum != ROLE_NONE) { - if (gendnum == 1 && roles[rolenum].name.f) - Strcat(buf, roles[rolenum].name.f); - else - Strcat(buf, roles[rolenum].name.m); - } else { - if (roles[rolenum].name.f) { - Strcat(buf, roles[rolenum].name.m); - Strcat(buf, "/"); - Strcat(buf, roles[rolenum].name.f); - } else - Strcat(buf, roles[rolenum].name.m); - } - donefirst = TRUE; - } else if (rolenum == ROLE_NONE) { - pa[BP_ROLE] = 1; - post_attribs++; - } - - if ((racenum == ROLE_NONE || racenum == ROLE_RANDOM) && !validrole(rolenum)) { - if (donefirst) Strcat(buf, " "); - Strcat(buf, "character"); - donefirst = TRUE; - } - /* || - * || - */ - if (buflen > (int) (strlen(buf) + 1)) { - Strcpy(suppliedbuf, buf); - return suppliedbuf; - } else - return err_ret; + if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) { + if (validrole(rolenum) + && ok_race(rolenum, racenum, gendnum, alignnum)) { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, (rolenum == ROLE_NONE) ? races[racenum].noun + : races[racenum].adj); + donefirst = TRUE; + } else if (!validrole(rolenum)) { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, races[racenum].noun); + donefirst = TRUE; + } else { + pa[BP_RACE] = 1; + post_attribs++; + } + } else { + pa[BP_RACE] = 1; + post_attribs++; + } + /* || */ + + if (validrole(rolenum)) { + if (donefirst) + Strcat(buf, " "); + if (gendnum != ROLE_NONE) { + if (gendnum == 1 && roles[rolenum].name.f) + Strcat(buf, roles[rolenum].name.f); + else + Strcat(buf, roles[rolenum].name.m); + } else { + if (roles[rolenum].name.f) { + Strcat(buf, roles[rolenum].name.m); + Strcat(buf, "/"); + Strcat(buf, roles[rolenum].name.f); + } else + Strcat(buf, roles[rolenum].name.m); + } + donefirst = TRUE; + } else if (rolenum == ROLE_NONE) { + pa[BP_ROLE] = 1; + post_attribs++; + } + + if ((racenum == ROLE_NONE || racenum == ROLE_RANDOM) + && !validrole(rolenum)) { + if (donefirst) + Strcat(buf, " "); + Strcat(buf, "character"); + donefirst = TRUE; + } + /* || + * || + */ + if (buflen > (int) (strlen(buf) + 1)) { + Strcpy(suppliedbuf, buf); + return suppliedbuf; + } else + return err_ret; } char * @@ -1271,53 +1600,54 @@ build_plselection_prompt(buf, buflen, rolenum, racenum, gendnum, alignnum) char *buf; int buflen, rolenum, racenum, gendnum, alignnum; { - const char *defprompt = "Shall I pick a character for you? [ynaq] "; - int num_post_attribs = 0; - char tmpbuf[BUFSZ]; + const char *defprompt = "Shall I pick a character for you? [ynaq] "; + int num_post_attribs = 0; + char tmpbuf[BUFSZ]; - if (buflen < QBUFSZ) - return (char *)defprompt; + if (buflen < QBUFSZ) + return (char *) defprompt; - Strcpy(tmpbuf, "Shall I pick "); - if (racenum != ROLE_NONE || validrole(rolenum)) - Strcat(tmpbuf, "your "); - else { - Strcat(tmpbuf, "a "); - } - /* */ + Strcpy(tmpbuf, "Shall I pick "); + if (racenum != ROLE_NONE || validrole(rolenum)) + Strcat(tmpbuf, "your "); + else { + Strcat(tmpbuf, "a "); + } + /* */ - (void) root_plselection_prompt(eos(tmpbuf), buflen - strlen(tmpbuf), - rolenum, racenum, gendnum, alignnum); - Sprintf(buf, "%s", s_suffix(tmpbuf)); + (void) root_plselection_prompt(eos(tmpbuf), buflen - strlen(tmpbuf), + rolenum, racenum, gendnum, alignnum); + Sprintf(buf, "%s", s_suffix(tmpbuf)); - /* buf should now be: - * < your lawful female gnomish cavewoman's> || - * || - * - * Now append the post attributes to it - */ + /* buf should now be: + * < your lawful female gnomish cavewoman's> || + * || + * + * Now append the post attributes to it + */ - num_post_attribs = post_attribs; - if (post_attribs) { - if (pa[BP_RACE]) { - (void) promptsep(eos(buf), num_post_attribs); - Strcat(buf, "race"); - } - if (pa[BP_ROLE]) { - (void) promptsep(eos(buf), num_post_attribs); - Strcat(buf, "role"); - } - if (pa[BP_GEND]) { - (void) promptsep(eos(buf), num_post_attribs); - Strcat(buf, "gender"); - } - if (pa[BP_ALIGN]) { - (void) promptsep(eos(buf), num_post_attribs); - Strcat(buf, "alignment"); - } - } - Strcat(buf, " for you? [ynaq] "); - return buf; + num_post_attribs = post_attribs; + if (post_attribs) { + if (pa[BP_RACE]) { + (void) promptsep(eos(buf), num_post_attribs); + Strcat(buf, "race"); + } + if (pa[BP_ROLE]) { + (void) promptsep(eos(buf), num_post_attribs); + Strcat(buf, "role"); + } + if (pa[BP_GEND]) { + (void) promptsep(eos(buf), num_post_attribs); + Strcat(buf, "gender"); + } + if (pa[BP_ALIGN]) { + (void) promptsep(eos(buf), num_post_attribs); + Strcat(buf, "alignment"); + } + } + Strcat(buf, " for you? [ynaq] "); + return buf; } #undef BP_ALIGN @@ -1334,44 +1664,46 @@ plnamesuffix() #ifdef GENERIC_USERNAMES { - /* some generic user names will be ignored in favor of prompting */ - const char *uptr = GENERIC_USERNAMES; + /* some generic user names will be ignored in favor of prompting */ + const char *uptr = GENERIC_USERNAMES; - i = (int)strlen(plname); - if ((sptr = strstri(uptr, plname)) != 0 - && (sptr == uptr || sptr[-1] == ' ') - && (sptr[i] == ' ' || sptr[i] == '\0')) - *plname = '\0'; /* call askname() */ + i = (int) strlen(plname); + if ((sptr = strstri(uptr, plname)) != 0 + && (sptr == uptr || sptr[-1] == ' ') + && (sptr[i] == ' ' || sptr[i] == '\0')) + *plname = '\0'; /* call askname() */ } #endif do { - if (!*plname) askname(); /* fill plname[] if necessary */ + if (!*plname) + askname(); /* fill plname[] if necessary */ - /* Look for tokens delimited by '-' */ - if ((eptr = index(plname, '-')) != (char *) 0) - *eptr++ = '\0'; - while (eptr) { - /* Isolate the next token */ - sptr = eptr; - if ((eptr = index(sptr, '-')) != (char *)0) - *eptr++ = '\0'; + /* Look for tokens delimited by '-' */ + if ((eptr = index(plname, '-')) != (char *) 0) + *eptr++ = '\0'; + while (eptr) { + /* Isolate the next token */ + sptr = eptr; + if ((eptr = index(sptr, '-')) != (char *) 0) + *eptr++ = '\0'; - /* Try to match it to something */ - if ((i = str2role(sptr)) != ROLE_NONE) - flags.initrole = i; - else if ((i = str2race(sptr)) != ROLE_NONE) - flags.initrace = i; - else if ((i = str2gend(sptr)) != ROLE_NONE) - flags.initgend = i; - else if ((i = str2align(sptr)) != ROLE_NONE) - flags.initalign = i; - } + /* Try to match it to something */ + if ((i = str2role(sptr)) != ROLE_NONE) + flags.initrole = i; + else if ((i = str2race(sptr)) != ROLE_NONE) + flags.initrace = i; + else if ((i = str2gend(sptr)) != ROLE_NONE) + flags.initgend = i; + else if ((i = str2align(sptr)) != ROLE_NONE) + flags.initalign = i; + } } while (!*plname); /* commas in the plname confuse the record file, convert to spaces */ for (sptr = plname; *sptr; sptr++) { - if (*sptr == ',') *sptr = ' '; + if (*sptr == ',') + *sptr = ' '; } } @@ -1382,10 +1714,9 @@ role_selection_prolog(which, where) int which; winid where; { - static const char NEARDATA - choosing[] = " choosing now", - not_yet[] = " not yet specified", - rand_choice[] = " random"; + static const char NEARDATA choosing[] = " choosing now", + not_yet[] = " not yet specified", + rand_choice[] = " random"; char buf[BUFSZ]; int r, c, g, a, allowmask; @@ -1394,31 +1725,31 @@ winid where; g = flags.initgend; a = flags.initalign; if (r >= 0) { - allowmask = roles[r].allow; - if ((allowmask & ROLE_RACEMASK) == MH_HUMAN) - c = 0; /* races[human] */ - else if (c >= 0 && !(allowmask & ROLE_RACEMASK & races[c].allow)) - c = ROLE_RANDOM; - if ((allowmask & ROLE_GENDMASK) == ROLE_MALE) - g = 0; /* role forces male (hypothetical) */ - else if ((allowmask & ROLE_GENDMASK) == ROLE_FEMALE) - g = 1; /* role forces female (valkyrie) */ - if ((allowmask & ROLE_ALIGNMASK) == AM_LAWFUL) - a = 0; /* aligns[lawful] */ - else if ((allowmask & ROLE_ALIGNMASK) == AM_NEUTRAL) - a = 1; /* aligns[neutral] */ - else if ((allowmask & ROLE_ALIGNMASK) == AM_CHAOTIC) - a = 2; /* alings[chaotic] */ + allowmask = roles[r].allow; + if ((allowmask & ROLE_RACEMASK) == MH_HUMAN) + c = 0; /* races[human] */ + else if (c >= 0 && !(allowmask & ROLE_RACEMASK & races[c].allow)) + c = ROLE_RANDOM; + if ((allowmask & ROLE_GENDMASK) == ROLE_MALE) + g = 0; /* role forces male (hypothetical) */ + else if ((allowmask & ROLE_GENDMASK) == ROLE_FEMALE) + g = 1; /* role forces female (valkyrie) */ + if ((allowmask & ROLE_ALIGNMASK) == AM_LAWFUL) + a = 0; /* aligns[lawful] */ + else if ((allowmask & ROLE_ALIGNMASK) == AM_NEUTRAL) + a = 1; /* aligns[neutral] */ + else if ((allowmask & ROLE_ALIGNMASK) == AM_CHAOTIC) + a = 2; /* alings[chaotic] */ } if (c >= 0) { - allowmask = races[c].allow; - if ((allowmask & ROLE_ALIGNMASK) == AM_LAWFUL) - a = 0; /* aligns[lawful] */ - else if ((allowmask & ROLE_ALIGNMASK) == AM_NEUTRAL) - a = 1; /* aligns[neutral] */ - else if ((allowmask & ROLE_ALIGNMASK) == AM_CHAOTIC) - a = 2; /* alings[chaotic] */ - /* [c never forces gender] */ + allowmask = races[c].allow; + if ((allowmask & ROLE_ALIGNMASK) == AM_LAWFUL) + a = 0; /* aligns[lawful] */ + else if ((allowmask & ROLE_ALIGNMASK) == AM_NEUTRAL) + a = 1; /* aligns[neutral] */ + else if ((allowmask & ROLE_ALIGNMASK) == AM_CHAOTIC) + a = 2; /* alings[chaotic] */ + /* [c never forces gender] */ } /* [g and a don't constrain anything sufficiently to narrow something done to a single choice] */ @@ -1427,29 +1758,41 @@ winid where; Strcat(buf, (which == RS_NAME) ? choosing : !*plname ? not_yet : plname); putstr(where, 0, buf); Sprintf(buf, "%12s ", "role:"); - Strcat(buf, (which == RS_ROLE) ? choosing : (r == ROLE_NONE) ? not_yet : - (r == ROLE_RANDOM) ? rand_choice : roles[r].name.m); + Strcat(buf, (which == RS_ROLE) ? choosing : (r == ROLE_NONE) + ? not_yet + : (r == ROLE_RANDOM) + ? rand_choice + : roles[r].name.m); if (r >= 0 && roles[r].name.f) { - /* distinct female name [caveman/cavewoman, priest/priestess] */ - if (g == 1) - /* female specified; replace male role name with female one */ - Sprintf(index(buf, ':'), ": %s", roles[r].name.f); - else if (g < 0) - /* gender unspecified; append slash and female role name */ - Sprintf(eos(buf), "/%s", roles[r].name.f); + /* distinct female name [caveman/cavewoman, priest/priestess] */ + if (g == 1) + /* female specified; replace male role name with female one */ + Sprintf(index(buf, ':'), ": %s", roles[r].name.f); + else if (g < 0) + /* gender unspecified; append slash and female role name */ + Sprintf(eos(buf), "/%s", roles[r].name.f); } putstr(where, 0, buf); Sprintf(buf, "%12s ", "race:"); - Strcat(buf, (which == RS_RACE) ? choosing : (c == ROLE_NONE) ? not_yet : - (c == ROLE_RANDOM) ? rand_choice : races[c].noun); + Strcat(buf, (which == RS_RACE) ? choosing : (c == ROLE_NONE) + ? not_yet + : (c == ROLE_RANDOM) + ? rand_choice + : races[c].noun); putstr(where, 0, buf); Sprintf(buf, "%12s ", "gender:"); - Strcat(buf, (which == RS_GENDER) ? choosing : (g == ROLE_NONE) ? not_yet : - (g == ROLE_RANDOM) ? rand_choice : genders[g].adj); + Strcat(buf, (which == RS_GENDER) ? choosing : (g == ROLE_NONE) + ? not_yet + : (g == ROLE_RANDOM) + ? rand_choice + : genders[g].adj); putstr(where, 0, buf); Sprintf(buf, "%12s ", "alignment:"); - Strcat(buf, (which == RS_ALGNMNT) ? choosing : (a == ROLE_NONE) ? not_yet : - (a == ROLE_RANDOM) ? rand_choice : aligns[a].adj); + Strcat(buf, (which == RS_ALGNMNT) ? choosing : (a == ROLE_NONE) + ? not_yet + : (a == ROLE_RANDOM) + ? rand_choice + : aligns[a].adj); putstr(where, 0, buf); } @@ -1460,11 +1803,11 @@ int which; winid where; { static NEARDATA const char RS_menu_let[] = { - '=', /* name */ - '?', /* role */ - '/', /* race */ - '\"', /* gender */ - '[', /* alignment */ + '=', /* name */ + '?', /* role */ + '/', /* race */ + '\"', /* gender */ + '[', /* alignment */ }; anything any; char buf[BUFSZ]; @@ -1475,93 +1818,96 @@ winid where; c = flags.initrace; switch (which) { case RS_NAME: - what = "name"; - break; + what = "name"; + break; case RS_ROLE: - what = "role"; - f = r; - /* nothing contrains role to a single choice */ - break; + what = "role"; + f = r; + /* nothing contrains role to a single choice */ + break; case RS_RACE: - what = "race"; - f = flags.initrace; - c = ROLE_NONE; /* override player's setting */ - if (r >= 0) { - allowmask = roles[r].allow & ROLE_RACEMASK; - if (allowmask == MH_HUMAN) - c = 0; /* races[human] */ - if (c >= 0) { - constrainer = "role"; - forcedvalue = races[c].noun; - } - } - break; + what = "race"; + f = flags.initrace; + c = ROLE_NONE; /* override player's setting */ + if (r >= 0) { + allowmask = roles[r].allow & ROLE_RACEMASK; + if (allowmask == MH_HUMAN) + c = 0; /* races[human] */ + if (c >= 0) { + constrainer = "role"; + forcedvalue = races[c].noun; + } + } + break; case RS_GENDER: - what = "gender"; - f = flags.initgend; - g = ROLE_NONE; - if (r >= 0) { - allowmask = roles[r].allow & ROLE_GENDMASK; - if (allowmask == ROLE_MALE) - g = 0; /* genders[male] */ - else if (allowmask == ROLE_FEMALE) - g = 1; /* genders[female] */ - if (g >= 0) { - constrainer = "role"; - forcedvalue = genders[g].adj; - } - } - break; + what = "gender"; + f = flags.initgend; + g = ROLE_NONE; + if (r >= 0) { + allowmask = roles[r].allow & ROLE_GENDMASK; + if (allowmask == ROLE_MALE) + g = 0; /* genders[male] */ + else if (allowmask == ROLE_FEMALE) + g = 1; /* genders[female] */ + if (g >= 0) { + constrainer = "role"; + forcedvalue = genders[g].adj; + } + } + break; case RS_ALGNMNT: - what = "alignment"; - f = flags.initalign; - a = ROLE_NONE; - if (r >= 0) { - allowmask = roles[r].allow & ROLE_ALIGNMASK; - if (allowmask == AM_LAWFUL) - a = 0; /* aligns[lawful] */ - else if (allowmask == AM_NEUTRAL) - a = 1; /* aligns[neutral] */ - else if (allowmask == AM_CHAOTIC) - a = 2; /* aligns[chaotic] */ - if (a >= 0) constrainer = "role"; - } - if (c >= 0 && !constrainer) { - allowmask = races[c].allow & ROLE_ALIGNMASK; - if (allowmask == AM_LAWFUL) - a = 0; /* aligns[lawful] */ - else if (allowmask == AM_NEUTRAL) - a = 1; /* aligns[neutral] */ - else if (allowmask == AM_CHAOTIC) - a = 2; /* aligns[chaotic] */ - if (a >= 0) constrainer = "race"; - } - if (a >= 0) forcedvalue = aligns[a].adj; - break; + what = "alignment"; + f = flags.initalign; + a = ROLE_NONE; + if (r >= 0) { + allowmask = roles[r].allow & ROLE_ALIGNMASK; + if (allowmask == AM_LAWFUL) + a = 0; /* aligns[lawful] */ + else if (allowmask == AM_NEUTRAL) + a = 1; /* aligns[neutral] */ + else if (allowmask == AM_CHAOTIC) + a = 2; /* aligns[chaotic] */ + if (a >= 0) + constrainer = "role"; + } + if (c >= 0 && !constrainer) { + allowmask = races[c].allow & ROLE_ALIGNMASK; + if (allowmask == AM_LAWFUL) + a = 0; /* aligns[lawful] */ + else if (allowmask == AM_NEUTRAL) + a = 1; /* aligns[neutral] */ + else if (allowmask == AM_CHAOTIC) + a = 2; /* aligns[chaotic] */ + if (a >= 0) + constrainer = "race"; + } + if (a >= 0) + forcedvalue = aligns[a].adj; + break; } - any = zeroany; /* zero out all bits */ + any = zeroany; /* zero out all bits */ if (constrainer) { - any.a_int = 0; - /* use four spaces of padding to fake a grayed out menu choice */ - Sprintf(buf, "%4s%s forces %s", "", constrainer, forcedvalue); - add_menu(where, NO_GLYPH, &any, ' ', - 0, ATR_NONE, buf, MENU_UNSELECTED); + any.a_int = 0; + /* use four spaces of padding to fake a grayed out menu choice */ + Sprintf(buf, "%4s%s forces %s", "", constrainer, forcedvalue); + add_menu(where, NO_GLYPH, &any, ' ', 0, ATR_NONE, buf, + MENU_UNSELECTED); } else if (what) { - any.a_int = RS_menu_arg(which); - Sprintf(buf, "Pick%s %s first", (f >= 0) ? " another" : "", what); - add_menu(where, NO_GLYPH, &any, RS_menu_let[which], - 0, ATR_NONE, buf, MENU_UNSELECTED); + any.a_int = RS_menu_arg(which); + Sprintf(buf, "Pick%s %s first", (f >= 0) ? " another" : "", what); + add_menu(where, NO_GLYPH, &any, RS_menu_let[which], 0, ATR_NONE, buf, + MENU_UNSELECTED); } else if (which == ROLE_RANDOM) { - any.a_int = ROLE_RANDOM; - add_menu(where, NO_GLYPH, &any, '*', - 0, ATR_NONE, "Random", MENU_UNSELECTED); + any.a_int = ROLE_RANDOM; + add_menu(where, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); } else if (which == ROLE_NONE) { - any.a_int = ROLE_NONE; - add_menu(where, NO_GLYPH, &any, 'q', - 0, ATR_NONE, "Quit", MENU_UNSELECTED); + any.a_int = ROLE_NONE; + add_menu(where, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); } else { - impossible("role_menu_extra: bad arg (%d)", which); + impossible("role_menu_extra: bad arg (%d)", which); } } @@ -1584,159 +1930,166 @@ winid where; void role_init() { - int alignmnt; - struct permonst *pm; + int alignmnt; + struct permonst *pm; - /* Strip the role letter out of the player name. - * This is included for backwards compatibility. - */ - plnamesuffix(); + /* Strip the role letter out of the player name. + * This is included for backwards compatibility. + */ + plnamesuffix(); - /* Check for a valid role. Try flags.initrole first. */ - if (!validrole(flags.initrole)) { - /* Try the player letter second */ - if ((flags.initrole = str2role(pl_character)) < 0) - /* None specified; pick a random role */ - flags.initrole = randrole(); - } + /* Check for a valid role. Try flags.initrole first. */ + if (!validrole(flags.initrole)) { + /* Try the player letter second */ + if ((flags.initrole = str2role(pl_character)) < 0) + /* None specified; pick a random role */ + flags.initrole = randrole(); + } - /* We now have a valid role index. Copy the role name back. */ - /* This should become OBSOLETE */ - Strcpy(pl_character, roles[flags.initrole].name.m); - pl_character[PL_CSIZ-1] = '\0'; + /* We now have a valid role index. Copy the role name back. */ + /* This should become OBSOLETE */ + Strcpy(pl_character, roles[flags.initrole].name.m); + pl_character[PL_CSIZ - 1] = '\0'; - /* Check for a valid race */ - if (!validrace(flags.initrole, flags.initrace)) - flags.initrace = randrace(flags.initrole); + /* Check for a valid race */ + if (!validrace(flags.initrole, flags.initrace)) + flags.initrace = randrace(flags.initrole); - /* Check for a valid gender. If new game, check both initgend - * and female. On restore, assume flags.female is correct. */ - if (flags.pantheon == -1) { /* new game */ - if (!validgend(flags.initrole, flags.initrace, flags.female)) - flags.female = !flags.female; - } - if (!validgend(flags.initrole, flags.initrace, flags.initgend)) - /* Note that there is no way to check for an unspecified gender. */ - flags.initgend = flags.female; + /* Check for a valid gender. If new game, check both initgend + * and female. On restore, assume flags.female is correct. */ + if (flags.pantheon == -1) { /* new game */ + if (!validgend(flags.initrole, flags.initrace, flags.female)) + flags.female = !flags.female; + } + if (!validgend(flags.initrole, flags.initrace, flags.initgend)) + /* Note that there is no way to check for an unspecified gender. */ + flags.initgend = flags.female; - /* Check for a valid alignment */ - if (!validalign(flags.initrole, flags.initrace, flags.initalign)) - /* Pick a random alignment */ - flags.initalign = randalign(flags.initrole, flags.initrace); - alignmnt = aligns[flags.initalign].value; + /* Check for a valid alignment */ + if (!validalign(flags.initrole, flags.initrace, flags.initalign)) + /* Pick a random alignment */ + flags.initalign = randalign(flags.initrole, flags.initrace); + alignmnt = aligns[flags.initalign].value; - /* Initialize urole and urace */ - urole = roles[flags.initrole]; - urace = races[flags.initrace]; + /* Initialize urole and urace */ + urole = roles[flags.initrole]; + urace = races[flags.initrace]; - /* Fix up the quest leader */ - if (urole.ldrnum != NON_PM) { - pm = &mons[urole.ldrnum]; - pm->msound = MS_LEADER; - pm->mflags2 |= (M2_PEACEFUL); - pm->mflags3 |= M3_CLOSE; - pm->maligntyp = alignmnt * 3; - /* if gender is random, we choose it now instead of waiting - until the leader monster is created */ - quest_status.ldrgend = is_neuter(pm) ? 2 : is_female(pm) ? 1 : - is_male(pm) ? 0 : (rn2(100) < 50); - } + /* Fix up the quest leader */ + if (urole.ldrnum != NON_PM) { + pm = &mons[urole.ldrnum]; + pm->msound = MS_LEADER; + pm->mflags2 |= (M2_PEACEFUL); + pm->mflags3 |= M3_CLOSE; + pm->maligntyp = alignmnt * 3; + /* if gender is random, we choose it now instead of waiting + until the leader monster is created */ + quest_status.ldrgend = + is_neuter(pm) ? 2 : is_female(pm) ? 1 : is_male(pm) + ? 0 + : (rn2(100) < 50); + } - /* Fix up the quest guardians */ - if (urole.guardnum != NON_PM) { - pm = &mons[urole.guardnum]; - pm->mflags2 |= (M2_PEACEFUL); - pm->maligntyp = alignmnt * 3; - } + /* Fix up the quest guardians */ + if (urole.guardnum != NON_PM) { + pm = &mons[urole.guardnum]; + pm->mflags2 |= (M2_PEACEFUL); + pm->maligntyp = alignmnt * 3; + } - /* Fix up the quest nemesis */ - if (urole.neminum != NON_PM) { - pm = &mons[urole.neminum]; - pm->msound = MS_NEMESIS; - pm->mflags2 &= ~(M2_PEACEFUL); - pm->mflags2 |= (M2_NASTY|M2_STALK|M2_HOSTILE); - pm->mflags3 &= ~(M3_CLOSE); - pm->mflags3 |= M3_WANTSARTI | M3_WAITFORU; - /* if gender is random, we choose it now instead of waiting - until the nemesis monster is created */ - quest_status.nemgend = is_neuter(pm) ? 2 : is_female(pm) ? 1 : - is_male(pm) ? 0 : (rn2(100) < 50); - } + /* Fix up the quest nemesis */ + if (urole.neminum != NON_PM) { + pm = &mons[urole.neminum]; + pm->msound = MS_NEMESIS; + pm->mflags2 &= ~(M2_PEACEFUL); + pm->mflags2 |= (M2_NASTY | M2_STALK | M2_HOSTILE); + pm->mflags3 &= ~(M3_CLOSE); + pm->mflags3 |= M3_WANTSARTI | M3_WAITFORU; + /* if gender is random, we choose it now instead of waiting + until the nemesis monster is created */ + quest_status.nemgend = + is_neuter(pm) ? 2 : is_female(pm) ? 1 : is_male(pm) + ? 0 + : (rn2(100) < 50); + } - /* Fix up the god names */ - if (flags.pantheon == -1) { /* new game */ - flags.pantheon = flags.initrole; /* use own gods */ - while (!roles[flags.pantheon].lgod) /* unless they're missing */ - flags.pantheon = randrole(); - } - if (!urole.lgod) { - urole.lgod = roles[flags.pantheon].lgod; - urole.ngod = roles[flags.pantheon].ngod; - urole.cgod = roles[flags.pantheon].cgod; - } - /* 0 or 1; no gods are neuter, nor is gender randomized */ - quest_status.godgend = !strcmpi(align_gtitle(alignmnt), "goddess"); + /* Fix up the god names */ + if (flags.pantheon == -1) { /* new game */ + flags.pantheon = flags.initrole; /* use own gods */ + while (!roles[flags.pantheon].lgod) /* unless they're missing */ + flags.pantheon = randrole(); + } + if (!urole.lgod) { + urole.lgod = roles[flags.pantheon].lgod; + urole.ngod = roles[flags.pantheon].ngod; + urole.cgod = roles[flags.pantheon].cgod; + } + /* 0 or 1; no gods are neuter, nor is gender randomized */ + quest_status.godgend = !strcmpi(align_gtitle(alignmnt), "goddess"); - /* Fix up infravision */ - if (mons[urace.malenum].mflags3 & M3_INFRAVISION) { - /* although an infravision intrinsic is possible, infravision - * is purely a property of the physical race. This means that we - * must put the infravision flag in the player's current race - * (either that or have separate permonst entries for - * elven/non-elven members of each class). The side effect is that - * all NPCs of that class will have (probably bogus) infravision, - * but since infravision has no effect for NPCs anyway we can - * ignore this. - */ - mons[urole.malenum].mflags3 |= M3_INFRAVISION; - if (urole.femalenum != NON_PM) - mons[urole.femalenum].mflags3 |= M3_INFRAVISION; - } + /* Fix up infravision */ + if (mons[urace.malenum].mflags3 & M3_INFRAVISION) { + /* although an infravision intrinsic is possible, infravision + * is purely a property of the physical race. This means that we + * must put the infravision flag in the player's current race + * (either that or have separate permonst entries for + * elven/non-elven members of each class). The side effect is that + * all NPCs of that class will have (probably bogus) infravision, + * but since infravision has no effect for NPCs anyway we can + * ignore this. + */ + mons[urole.malenum].mflags3 |= M3_INFRAVISION; + if (urole.femalenum != NON_PM) + mons[urole.femalenum].mflags3 |= M3_INFRAVISION; + } - /* Artifacts are fixed in hack_artifacts() */ + /* Artifacts are fixed in hack_artifacts() */ - /* Success! */ - return; + /* Success! */ + return; } const char * Hello(mtmp) struct monst *mtmp; { - switch (Role_switch) { - case PM_KNIGHT: - return ("Salutations"); /* Olde English */ - case PM_SAMURAI: - return (mtmp && mtmp->data == &mons[PM_SHOPKEEPER] ? - "Irasshaimase" : "Konnichi wa"); /* Japanese */ - case PM_TOURIST: - return ("Aloha"); /* Hawaiian */ - case PM_VALKYRIE: - return ( + switch (Role_switch) { + case PM_KNIGHT: + return ("Salutations"); /* Olde English */ + case PM_SAMURAI: + return (mtmp && mtmp->data == &mons[PM_SHOPKEEPER] + ? "Irasshaimase" + : "Konnichi wa"); /* Japanese */ + case PM_TOURIST: + return ("Aloha"); /* Hawaiian */ + case PM_VALKYRIE: + return ( #ifdef MAIL - mtmp && mtmp->data == &mons[PM_MAIL_DAEMON] ? "Hallo" : + mtmp && mtmp->data == &mons[PM_MAIL_DAEMON] + ? "Hallo" + : #endif - "Velkommen"); /* Norse */ - default: - return ("Hello"); - } + "Velkommen"); /* Norse */ + default: + return ("Hello"); + } } const char * Goodbye() { - switch (Role_switch) { - case PM_KNIGHT: - return ("Fare thee well"); /* Olde English */ - case PM_SAMURAI: - return ("Sayonara"); /* Japanese */ - case PM_TOURIST: - return ("Aloha"); /* Hawaiian */ - case PM_VALKYRIE: - return ("Farvel"); /* Norse */ - default: - return ("Goodbye"); - } + switch (Role_switch) { + case PM_KNIGHT: + return ("Fare thee well"); /* Olde English */ + case PM_SAMURAI: + return ("Sayonara"); /* Japanese */ + case PM_TOURIST: + return ("Aloha"); /* Hawaiian */ + case PM_VALKYRIE: + return ("Farvel"); /* Norse */ + default: + return ("Goodbye"); + } } /* role.c */ diff --git a/src/rumors.c b/src/rumors.c index 6ec453649..03686e06b 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 rumors.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 rumors.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */ /* NetHack 3.6 rumors.c $Date: 2012/05/11 22:36:33 $ $Revision: 1.17 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -51,7 +51,7 @@ static unsigned long true_rumor_start, false_rumor_start; /* rumor end offsets are signed because they're compared with [dlb_]ftell() */ static long true_rumor_end, false_rumor_end; /* oracles are handled differently from rumors... */ -static int oracle_flg = 0; /* -1=>don't use, 0=>need init, 1=>init done */ +static int oracle_flg = 0; /* -1=>don't use, 0=>need init, 1=>init done */ static unsigned oracle_cnt = 0; static unsigned long *oracle_loc = 0; @@ -59,26 +59,26 @@ STATIC_OVL void init_rumors(fp) dlb *fp; { - static const char rumors_header[] = "%d,%ld,%lx;%d,%ld,%lx;0,0,%lx\n"; - int true_count, false_count; /* in file but not used here */ - unsigned long eof_offset; - char line[BUFSZ]; + static const char rumors_header[] = "%d,%ld,%lx;%d,%ld,%lx;0,0,%lx\n"; + int true_count, false_count; /* in file but not used here */ + unsigned long eof_offset; + char line[BUFSZ]; - (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment */ - (void) dlb_fgets(line, sizeof line, fp); - if (sscanf(line, rumors_header, - &true_count, &true_rumor_size, &true_rumor_start, - &false_count, &false_rumor_size, &false_rumor_start, - &eof_offset) == 7 && - true_rumor_size > 0L && false_rumor_size > 0L) { - true_rumor_end = (long)true_rumor_start + true_rumor_size; - /* assert( true_rumor_end == false_rumor_start ); */ - false_rumor_end = (long)false_rumor_start + false_rumor_size; - /* assert( false_rumor_end == eof_offset ); */ - } else { - true_rumor_size = -1L; /* init failed */ - (void) dlb_fclose(fp); - } + (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment */ + (void) dlb_fgets(line, sizeof line, fp); + if (sscanf(line, rumors_header, &true_count, &true_rumor_size, + &true_rumor_start, &false_count, &false_rumor_size, + &false_rumor_start, &eof_offset) == 7 + && true_rumor_size > 0L + && false_rumor_size > 0L) { + true_rumor_end = (long) true_rumor_start + true_rumor_size; + /* assert( true_rumor_end == false_rumor_start ); */ + false_rumor_end = (long) false_rumor_start + false_rumor_size; + /* assert( false_rumor_end == eof_offset ); */ + } else { + true_rumor_size = -1L; /* init failed */ + (void) dlb_fclose(fp); + } } /* exclude_cookie is a hack used because we sometimes want to get rumors in a @@ -90,86 +90,90 @@ char * getrumor(truth, rumor_buf, exclude_cookie) int truth; /* 1=true, -1=false, 0=either */ char *rumor_buf; -boolean exclude_cookie; +boolean exclude_cookie; { - dlb *rumors; - long tidbit, beginning; - char *endp, line[BUFSZ], xbuf[BUFSZ]; + dlb *rumors; + long tidbit, beginning; + char *endp, line[BUFSZ], xbuf[BUFSZ]; - rumor_buf[0] = '\0'; - if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ - return rumor_buf; + rumor_buf[0] = '\0'; + if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ + return rumor_buf; - rumors = dlb_fopen(RUMORFILE, "r"); + rumors = dlb_fopen(RUMORFILE, "r"); - if (rumors) { - int count = 0; - int adjtruth; + if (rumors) { + int count = 0; + int adjtruth; - do { - rumor_buf[0] = '\0'; - if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ - init_rumors(rumors); - if (true_rumor_size < 0L) { /* init failed */ - Sprintf(rumor_buf, "Error reading \"%.80s\".", - RUMORFILE); - return rumor_buf; - } - } - /* - * input: 1 0 -1 - * rn2 \ +1 2=T 1=T 0=F - * adj./ +0 1=T 0=F -1=F - */ - switch (adjtruth = truth + rn2(2)) { - case 2: /*(might let a bogus input arg sneak thru)*/ - case 1: beginning = (long)true_rumor_start; - tidbit = Rand() % true_rumor_size; - break; - case 0: /* once here, 0 => false rather than "either"*/ - case -1: beginning = (long)false_rumor_start; - tidbit = Rand() % false_rumor_size; - break; - default: - impossible("strange truth value for rumor"); - return strcpy(rumor_buf, "Oops..."); - } - (void) dlb_fseek(rumors, beginning + tidbit, SEEK_SET); - (void) dlb_fgets(line, sizeof line, rumors); - if (!dlb_fgets(line, sizeof line, rumors) || - (adjtruth > 0 && dlb_ftell(rumors) > true_rumor_end)) { - /* reached end of rumors -- go back to beginning */ - (void) dlb_fseek(rumors, beginning, SEEK_SET); - (void) dlb_fgets(line, sizeof line, rumors); - } - if ((endp = index(line, '\n')) != 0) *endp = 0; - Strcat(rumor_buf, xcrypt(line, xbuf)); - } while (count++ < 50 && exclude_cookie && - (strstri(rumor_buf, "fortune") || strstri(rumor_buf, "pity"))); - (void) dlb_fclose(rumors); - if (count >= 50) - impossible("Can't find non-cookie rumor?"); - else if (!in_mklev) /* avoid exercizing wisdom for graffiti */ - exercise(A_WIS, (adjtruth > 0)); - } else { - pline("Can't open rumors file!"); - true_rumor_size = -1; /* don't try to open it again */ - } + do { + rumor_buf[0] = '\0'; + if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ + init_rumors(rumors); + if (true_rumor_size < 0L) { /* init failed */ + Sprintf(rumor_buf, "Error reading \"%.80s\".", RUMORFILE); + return rumor_buf; + } + } + /* + * input: 1 0 -1 + * rn2 \ +1 2=T 1=T 0=F + * adj./ +0 1=T 0=F -1=F + */ + switch (adjtruth = truth + rn2(2)) { + case 2: /*(might let a bogus input arg sneak thru)*/ + case 1: + beginning = (long) true_rumor_start; + tidbit = Rand() % true_rumor_size; + break; + case 0: /* once here, 0 => false rather than "either"*/ + case -1: + beginning = (long) false_rumor_start; + tidbit = Rand() % false_rumor_size; + break; + default: + impossible("strange truth value for rumor"); + return strcpy(rumor_buf, "Oops..."); + } + (void) dlb_fseek(rumors, beginning + tidbit, SEEK_SET); + (void) dlb_fgets(line, sizeof line, rumors); + if (!dlb_fgets(line, sizeof line, rumors) + || (adjtruth > 0 && dlb_ftell(rumors) > true_rumor_end)) { + /* reached end of rumors -- go back to beginning */ + (void) dlb_fseek(rumors, beginning, SEEK_SET); + (void) dlb_fgets(line, sizeof line, rumors); + } + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Strcat(rumor_buf, xcrypt(line, xbuf)); + } while ( + count++ < 50 && exclude_cookie + && (strstri(rumor_buf, "fortune") || strstri(rumor_buf, "pity"))); + (void) dlb_fclose(rumors); + if (count >= 50) + impossible("Can't find non-cookie rumor?"); + else if (!in_mklev) /* avoid exercizing wisdom for graffiti */ + exercise(A_WIS, (adjtruth > 0)); + } else { + pline("Can't open rumors file!"); + true_rumor_size = -1; /* don't try to open it again */ + } /* this is safe either way, so do it always since we can't get the definition * out of makedefs.c */ #define PAD_RUMORS_TO #ifdef PAD_RUMORS_TO - /* remove padding */ - { - char *x = eos(rumor_buf) - 1; + /* remove padding */ + { + char *x = eos(rumor_buf) - 1; - while(x > rumor_buf && *x=='_') x--; - *++x = '\n'; - *x = '\0'; - } + while (x > rumor_buf && *x == '_') + x--; + *++x = '\n'; + *x = '\0'; + } #endif - return rumor_buf; + return rumor_buf; } /* @@ -178,95 +182,101 @@ boolean exclude_cookie; void rumor_check() { - dlb *rumors; - winid tmpwin; - char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ]; + dlb *rumors; + winid tmpwin; + char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ]; - if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */ - no_rumors: - pline("rumors not accessible."); - return; - } + if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */ + no_rumors: + pline("rumors not accessible."); + return; + } - rumors = dlb_fopen(RUMORFILE, "r"); + rumors = dlb_fopen(RUMORFILE, "r"); - if (rumors) { - long ftell_rumor_start = 0L; + if (rumors) { + long ftell_rumor_start = 0L; - rumor_buf[0] = '\0'; - if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ - init_rumors(rumors); - if (true_rumor_size < 0L) goto no_rumors; /* init failed */ - } - tmpwin = create_nhwindow(NHW_TEXT); + rumor_buf[0] = '\0'; + if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ + init_rumors(rumors); + if (true_rumor_size < 0L) + goto no_rumors; /* init failed */ + } + tmpwin = create_nhwindow(NHW_TEXT); - /* - * reveal the values. - */ + /* + * reveal the values. + */ - Sprintf(rumor_buf, - "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long)true_rumor_start, true_rumor_start, - true_rumor_end, (unsigned long)true_rumor_end, - true_rumor_size, (unsigned long)true_rumor_size); - putstr(tmpwin, 0, rumor_buf); - - Sprintf(rumor_buf, - "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long)false_rumor_start, false_rumor_start, - false_rumor_end, (unsigned long)false_rumor_end, - false_rumor_size, (unsigned long)false_rumor_size); - putstr(tmpwin, 0, rumor_buf); - - /* - * check the first rumor (start of true rumors) by - * skipping the first two lines. - * - * Then seek to the start of the false rumors (based on - * the value read in rumors, and display it. - */ - rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long)true_rumor_start, SEEK_SET); - ftell_rumor_start = dlb_ftell(rumors); - (void) dlb_fgets(line, sizeof line, rumors); - if ((endp = index(line, '\n')) != 0) *endp = 0; - Sprintf(rumor_buf, "T %06ld %s", ftell_rumor_start, - xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - /* find last true rumor */ - while (dlb_fgets(line, sizeof line, rumors) && - dlb_ftell(rumors) < true_rumor_end) - continue; - if ((endp = index(line, '\n')) != 0) *endp = 0; - Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); + Sprintf( + rumor_buf, + "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", + (long) true_rumor_start, true_rumor_start, true_rumor_end, + (unsigned long) true_rumor_end, true_rumor_size, + (unsigned long) true_rumor_size); + putstr(tmpwin, 0, rumor_buf); - rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long)false_rumor_start, SEEK_SET); - ftell_rumor_start = dlb_ftell(rumors); - (void) dlb_fgets(line, sizeof line, rumors); - if ((endp = index(line, '\n')) != 0) *endp = 0; - Sprintf(rumor_buf, "F %06ld %s", ftell_rumor_start, - xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - /* find last false rumor */ - while (dlb_fgets(line, sizeof line, rumors) && - dlb_ftell(rumors) < false_rumor_end) - continue; - if ((endp = index(line, '\n')) != 0) *endp = 0; - Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); + Sprintf( + rumor_buf, + "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", + (long) false_rumor_start, false_rumor_start, false_rumor_end, + (unsigned long) false_rumor_end, false_rumor_size, + (unsigned long) false_rumor_size); + putstr(tmpwin, 0, rumor_buf); - (void) dlb_fclose(rumors); - display_nhwindow(tmpwin, TRUE); - destroy_nhwindow(tmpwin); - } else { - impossible("Can't open rumors file!"); - true_rumor_size = -1; /* don't try to open it again */ - } + /* + * check the first rumor (start of true rumors) by + * skipping the first two lines. + * + * Then seek to the start of the false rumors (based on + * the value read in rumors, and display it. + */ + rumor_buf[0] = '\0'; + (void) dlb_fseek(rumors, (long) true_rumor_start, SEEK_SET); + ftell_rumor_start = dlb_ftell(rumors); + (void) dlb_fgets(line, sizeof line, rumors); + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Sprintf(rumor_buf, "T %06ld %s", ftell_rumor_start, + xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + /* find last true rumor */ + while (dlb_fgets(line, sizeof line, rumors) + && dlb_ftell(rumors) < true_rumor_end) + continue; + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + + rumor_buf[0] = '\0'; + (void) dlb_fseek(rumors, (long) false_rumor_start, SEEK_SET); + ftell_rumor_start = dlb_ftell(rumors); + (void) dlb_fgets(line, sizeof line, rumors); + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Sprintf(rumor_buf, "F %06ld %s", ftell_rumor_start, + xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + /* find last false rumor */ + while (dlb_fgets(line, sizeof line, rumors) + && dlb_ftell(rumors) < false_rumor_end) + continue; + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + + (void) dlb_fclose(rumors); + display_nhwindow(tmpwin, TRUE); + destroy_nhwindow(tmpwin); + } else { + impossible("Can't open rumors file!"); + true_rumor_size = -1; /* don't try to open it again */ + } } - /* Gets a random line of text from file 'fname', and returns it. */ char * get_rnd_text(fname, buf) @@ -280,126 +290,129 @@ char *buf; fh = dlb_fopen(fname, "r"); if (fh) { - /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents? */ - long sizetxt = 0, starttxt = 0, endtxt = 0, tidbit = 0; - char *endp, line[BUFSZ], xbuf[BUFSZ]; - (void) dlb_fgets(line, sizeof line, fh); /* skip "don't edit" comment */ + /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents? + */ + long sizetxt = 0, starttxt = 0, endtxt = 0, tidbit = 0; + char *endp, line[BUFSZ], xbuf[BUFSZ]; + (void) dlb_fgets(line, sizeof line, + fh); /* skip "don't edit" comment */ - (void) dlb_fseek(fh, 0L, SEEK_CUR); - starttxt = dlb_ftell(fh); - (void) dlb_fseek(fh, 0L, SEEK_END); - endtxt = dlb_ftell(fh); - sizetxt = endtxt - starttxt; - tidbit = Rand() % sizetxt; + (void) dlb_fseek(fh, 0L, SEEK_CUR); + starttxt = dlb_ftell(fh); + (void) dlb_fseek(fh, 0L, SEEK_END); + endtxt = dlb_ftell(fh); + sizetxt = endtxt - starttxt; + tidbit = Rand() % sizetxt; - (void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET); - (void) dlb_fgets(line, sizeof line, fh); - if (!dlb_fgets(line, sizeof line, fh)) { - (void) dlb_fseek(fh, starttxt, SEEK_SET); - (void) dlb_fgets(line, sizeof line, fh); - } - if ((endp = index(line, '\n')) != 0) *endp = 0; - Strcat(buf, xcrypt(line, xbuf)); - (void) dlb_fclose(fh); - } else impossible("Can't open file %s!", fname); + (void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET); + (void) dlb_fgets(line, sizeof line, fh); + if (!dlb_fgets(line, sizeof line, fh)) { + (void) dlb_fseek(fh, starttxt, SEEK_SET); + (void) dlb_fgets(line, sizeof line, fh); + } + if ((endp = index(line, '\n')) != 0) + *endp = 0; + Strcat(buf, xcrypt(line, xbuf)); + (void) dlb_fclose(fh); + } else + impossible("Can't open file %s!", fname); return buf; } - void outrumor(truth, mechanism) int truth; /* 1=true, -1=false, 0=either */ int mechanism; { - static const char fortune_msg[] = - "This cookie has a scrap of paper inside."; - const char *line; - char buf[BUFSZ]; - boolean reading = (mechanism == BY_COOKIE || - mechanism == BY_PAPER); + static const char fortune_msg[] = + "This cookie has a scrap of paper inside."; + const char *line; + char buf[BUFSZ]; + boolean reading = (mechanism == BY_COOKIE || mechanism == BY_PAPER); - if (reading) { - /* deal with various things that prevent reading */ - if (is_fainted() && mechanism == BY_COOKIE) - return; - else if (Blind) { - if (mechanism == BY_COOKIE) - pline(fortune_msg); - pline("What a pity that you cannot read it!"); - return; - } - } - line = getrumor(truth, buf, reading ? FALSE : TRUE); - if (!*line) - line = "NetHack rumors file closed for renovation."; - switch (mechanism) { - case BY_ORACLE: - /* Oracle delivers the rumor */ - pline("True to her word, the Oracle %ssays: ", - (!rn2(4) ? "offhandedly " : (!rn2(3) ? "casually " : - (rn2(2) ? "nonchalantly " : "")))); - verbalize1(line); - /* [WIS exercized by getrumor()] */ - return; - case BY_COOKIE: - pline(fortune_msg); - /* FALLTHRU */ - case BY_PAPER: - pline("It reads:"); - break; - } - pline1(line); + if (reading) { + /* deal with various things that prevent reading */ + if (is_fainted() && mechanism == BY_COOKIE) + return; + else if (Blind) { + if (mechanism == BY_COOKIE) + pline(fortune_msg); + pline("What a pity that you cannot read it!"); + return; + } + } + line = getrumor(truth, buf, reading ? FALSE : TRUE); + if (!*line) + line = "NetHack rumors file closed for renovation."; + switch (mechanism) { + case BY_ORACLE: + /* Oracle delivers the rumor */ + pline("True to her word, the Oracle %ssays: ", + (!rn2(4) ? "offhandedly " + : (!rn2(3) ? "casually " + : (rn2(2) ? "nonchalantly " : "")))); + verbalize1(line); + /* [WIS exercized by getrumor()] */ + return; + case BY_COOKIE: + pline(fortune_msg); + /* FALLTHRU */ + case BY_PAPER: + pline("It reads:"); + break; + } + pline1(line); } STATIC_OVL void init_oracles(fp) dlb *fp; { - register int i; - char line[BUFSZ]; - int cnt = 0; + register int i; + char line[BUFSZ]; + int cnt = 0; - /* this assumes we're only called once */ - (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment*/ - (void) dlb_fgets(line, sizeof line, fp); - if (sscanf(line, "%5d\n", &cnt) == 1 && cnt > 0) { - oracle_cnt = (unsigned) cnt; - oracle_loc = (unsigned long *)alloc((unsigned)cnt * sizeof (long)); - for (i = 0; i < cnt; i++) { - (void) dlb_fgets(line, sizeof line, fp); - (void) sscanf(line, "%5lx\n", &oracle_loc[i]); - } - } - return; + /* this assumes we're only called once */ + (void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment*/ + (void) dlb_fgets(line, sizeof line, fp); + if (sscanf(line, "%5d\n", &cnt) == 1 && cnt > 0) { + oracle_cnt = (unsigned) cnt; + oracle_loc = (unsigned long *) alloc((unsigned) cnt * sizeof(long)); + for (i = 0; i < cnt; i++) { + (void) dlb_fgets(line, sizeof line, fp); + (void) sscanf(line, "%5lx\n", &oracle_loc[i]); + } + } + return; } void save_oracles(fd, mode) int fd, mode; { - if (perform_bwrite(mode)) { - bwrite(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); - if (oracle_cnt) - bwrite(fd, (genericptr_t)oracle_loc, oracle_cnt*sizeof (long)); - } - if (release_data(mode)) { - if (oracle_cnt) { - free((genericptr_t)oracle_loc); - oracle_loc = 0, oracle_cnt = 0, oracle_flg = 0; - } - } + if (perform_bwrite(mode)) { + bwrite(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); + if (oracle_cnt) + bwrite(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long)); + } + if (release_data(mode)) { + if (oracle_cnt) { + free((genericptr_t) oracle_loc); + oracle_loc = 0, oracle_cnt = 0, oracle_flg = 0; + } + } } void restore_oracles(fd) int fd; { - mread(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); - if (oracle_cnt) { - oracle_loc = (unsigned long *)alloc(oracle_cnt * sizeof (long)); - mread(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof (long)); - oracle_flg = 1; /* no need to call init_oracles() */ - } + mread(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt); + if (oracle_cnt) { + oracle_loc = (unsigned long *) alloc(oracle_cnt * sizeof(long)); + mread(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long)); + oracle_flg = 1; /* no need to call init_oracles() */ + } } void @@ -407,126 +420,130 @@ outoracle(special, delphi) boolean special; boolean delphi; { - char line[COLNO]; - char *endp; - dlb *oracles; - int oracle_idx; - char xbuf[BUFSZ]; + char line[COLNO]; + char *endp; + dlb *oracles; + int oracle_idx; + char xbuf[BUFSZ]; - if(oracle_flg < 0 || /* couldn't open ORACLEFILE */ - (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ - return; + if (oracle_flg < 0 || /* couldn't open ORACLEFILE */ + (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ + return; - oracles = dlb_fopen(ORACLEFILE, "r"); + oracles = dlb_fopen(ORACLEFILE, "r"); - if (oracles) { - winid tmpwin; - if (oracle_flg == 0) { /* if this is the first outoracle() */ - init_oracles(oracles); - oracle_flg = 1; - if (oracle_cnt == 0) return; - } - /* oracle_loc[0] is the special oracle; */ - /* oracle_loc[1..oracle_cnt-1] are normal ones */ - if (oracle_cnt <= 1 && !special) return; /*(shouldn't happen)*/ - oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1); - (void) dlb_fseek(oracles, (long)oracle_loc[oracle_idx], - SEEK_SET); - if (!special) /* move offset of very last one into this slot */ - oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt]; + if (oracles) { + winid tmpwin; + if (oracle_flg == 0) { /* if this is the first outoracle() */ + init_oracles(oracles); + oracle_flg = 1; + if (oracle_cnt == 0) + return; + } + /* oracle_loc[0] is the special oracle; */ + /* oracle_loc[1..oracle_cnt-1] are normal ones */ + if (oracle_cnt <= 1 && !special) + return; /*(shouldn't happen)*/ + oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1); + (void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET); + if (!special) /* move offset of very last one into this slot */ + oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt]; - tmpwin = create_nhwindow(NHW_TEXT); - if (delphi) - putstr(tmpwin, 0, special ? - "The Oracle scornfully takes all your money and says:" : - "The Oracle meditates for a moment and then intones:"); - else - putstr(tmpwin, 0, "The message reads:"); - putstr(tmpwin, 0, ""); + tmpwin = create_nhwindow(NHW_TEXT); + if (delphi) + putstr( + tmpwin, 0, + special + ? "The Oracle scornfully takes all your money and says:" + : "The Oracle meditates for a moment and then intones:"); + else + putstr(tmpwin, 0, "The message reads:"); + putstr(tmpwin, 0, ""); - while(dlb_fgets(line, COLNO, oracles) && strcmp(line,"---\n")) { - if ((endp = index(line, '\n')) != 0) *endp = 0; - putstr(tmpwin, 0, xcrypt(line, xbuf)); - } - display_nhwindow(tmpwin, TRUE); - destroy_nhwindow(tmpwin); - (void) dlb_fclose(oracles); - } else { - pline("Can't open oracles file!"); - oracle_flg = -1; /* don't try to open it again */ - } + while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) { + if ((endp = index(line, '\n')) != 0) + *endp = 0; + putstr(tmpwin, 0, xcrypt(line, xbuf)); + } + display_nhwindow(tmpwin, TRUE); + destroy_nhwindow(tmpwin); + (void) dlb_fclose(oracles); + } else { + pline("Can't open oracles file!"); + oracle_flg = -1; /* don't try to open it again */ + } } int doconsult(oracl) register struct monst *oracl; { - long umoney; - int u_pay, minor_cost = 50, major_cost = 500 + 50 * u.ulevel; - int add_xpts; - char qbuf[QBUFSZ]; + long umoney; + int u_pay, minor_cost = 50, major_cost = 500 + 50 * u.ulevel; + int add_xpts; + char qbuf[QBUFSZ]; - multi = 0; - umoney = money_cnt(invent); + multi = 0; + umoney = money_cnt(invent); - if (!oracl) { - There("is no one here to consult."); - return 0; - } else if (!oracl->mpeaceful) { - pline("%s is in no mood for consultations.", Monnam(oracl)); - return 0; - } else if (!umoney) { - You("have no money."); - return 0; - } + if (!oracl) { + There("is no one here to consult."); + return 0; + } else if (!oracl->mpeaceful) { + pline("%s is in no mood for consultations.", Monnam(oracl)); + return 0; + } else if (!umoney) { + You("have no money."); + return 0; + } - Sprintf(qbuf, - "\"Wilt thou settle for a minor consultation?\" (%d %s)", - minor_cost, currency((long)minor_cost)); - switch (ynq(qbuf)) { - default: - case 'q': - return 0; - case 'y': - if (umoney < (long)minor_cost) { - You("don't even have enough money for that!"); - return 0; - } - u_pay = minor_cost; - break; - case 'n': - if (umoney <= (long)minor_cost || /* don't even ask */ - (oracle_cnt == 1 || oracle_flg < 0)) return 0; - Sprintf(qbuf, - "\"Then dost thou desire a major one?\" (%d %s)", - major_cost, currency((long)major_cost)); - if (yn(qbuf) != 'y') return 0; - u_pay = (umoney < (long)major_cost) ? (int)umoney : major_cost; - break; - } - money2mon(oracl, (long)u_pay); - context.botl = 1; - add_xpts = 0; /* first oracle of each type gives experience points */ - if (u_pay == minor_cost) { - outrumor(1, BY_ORACLE); - if (!u.uevent.minor_oracle) - add_xpts = u_pay / (u.uevent.major_oracle ? 25 : 10); - /* 5 pts if very 1st, or 2 pts if major already done */ - u.uevent.minor_oracle = TRUE; - } else { - boolean cheapskate = u_pay < major_cost; - outoracle(cheapskate, TRUE); - if (!cheapskate && !u.uevent.major_oracle) - add_xpts = u_pay / (u.uevent.minor_oracle ? 25 : 10); - /* ~100 pts if very 1st, ~40 pts if minor already done */ - u.uevent.major_oracle = TRUE; - exercise(A_WIS, !cheapskate); - } - if (add_xpts) { - more_experienced(add_xpts, u_pay/50); - newexplevel(); - } - return 1; + Sprintf(qbuf, "\"Wilt thou settle for a minor consultation?\" (%d %s)", + minor_cost, currency((long) minor_cost)); + switch (ynq(qbuf)) { + default: + case 'q': + return 0; + case 'y': + if (umoney < (long) minor_cost) { + You("don't even have enough money for that!"); + return 0; + } + u_pay = minor_cost; + break; + case 'n': + if (umoney <= (long) minor_cost || /* don't even ask */ + (oracle_cnt == 1 || oracle_flg < 0)) + return 0; + Sprintf(qbuf, "\"Then dost thou desire a major one?\" (%d %s)", + major_cost, currency((long) major_cost)); + if (yn(qbuf) != 'y') + return 0; + u_pay = (umoney < (long) major_cost) ? (int) umoney : major_cost; + break; + } + money2mon(oracl, (long) u_pay); + context.botl = 1; + add_xpts = 0; /* first oracle of each type gives experience points */ + if (u_pay == minor_cost) { + outrumor(1, BY_ORACLE); + if (!u.uevent.minor_oracle) + add_xpts = u_pay / (u.uevent.major_oracle ? 25 : 10); + /* 5 pts if very 1st, or 2 pts if major already done */ + u.uevent.minor_oracle = TRUE; + } else { + boolean cheapskate = u_pay < major_cost; + outoracle(cheapskate, TRUE); + if (!cheapskate && !u.uevent.major_oracle) + add_xpts = u_pay / (u.uevent.minor_oracle ? 25 : 10); + /* ~100 pts if very 1st, ~40 pts if minor already done */ + u.uevent.major_oracle = TRUE; + exercise(A_WIS, !cheapskate); + } + if (add_xpts) { + more_experienced(add_xpts, u_pay / 50); + newexplevel(); + } + return 1; } /*rumors.c*/ diff --git a/src/save.c b/src/save.c index 37e192a3b..b50d94fb4 100644 --- a/src/save.c +++ b/src/save.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 save.c $NHDT-Date: 1429757271 2015/04/23 02:47:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.82 $ */ +/* NetHack 3.6 save.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.86 $ */ /* NetHack 3.6 save.c $Date: 2012/02/16 02:40:24 $ $Revision: 1.53 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -19,65 +19,56 @@ static int count_only; #endif #ifdef MICRO -int dotcnt, dotrow; /* also used in restore */ +int dotcnt, dotrow; /* also used in restore */ #endif -STATIC_DCL void FDECL(savelevchn, (int,int)); -STATIC_DCL void FDECL(savedamage, (int,int)); -STATIC_DCL void FDECL(saveobj, (int,struct obj *)); -STATIC_DCL void FDECL(saveobjchn, (int,struct obj *,int)); -STATIC_DCL void FDECL(savemon, (int,struct monst *)); -STATIC_DCL void FDECL(savemonchn, (int,struct monst *,int)); -STATIC_DCL void FDECL(savetrapchn, (int,struct trap *,int)); -STATIC_DCL void FDECL(savegamestate, (int,int)); -STATIC_OVL void FDECL(save_msghistory, (int,int)); +STATIC_DCL void FDECL(savelevchn, (int, int)); +STATIC_DCL void FDECL(savedamage, (int, int)); +STATIC_DCL void FDECL(saveobj, (int, struct obj *)); +STATIC_DCL void FDECL(saveobjchn, (int, struct obj *, int)); +STATIC_DCL void FDECL(savemon, (int, struct monst *)); +STATIC_DCL void FDECL(savemonchn, (int, struct monst *, int)); +STATIC_DCL void FDECL(savetrapchn, (int, struct trap *, int)); +STATIC_DCL void FDECL(savegamestate, (int, int)); +STATIC_OVL void FDECL(save_msghistory, (int, int)); #ifdef MFLOPPY -STATIC_DCL void FDECL(savelev0, (int,XCHAR_P,int)); +STATIC_DCL void FDECL(savelev0, (int, XCHAR_P, int)); STATIC_DCL boolean NDECL(swapout_oldest); -STATIC_DCL void FDECL(copyfile, (char *,char *)); +STATIC_DCL void FDECL(copyfile, (char *, char *)); #endif /* MFLOPPY */ STATIC_DCL void FDECL(savelevl, (int fd, BOOLEAN_P)); STATIC_DCL void FDECL(def_bufon, (int)); STATIC_DCL void FDECL(def_bufoff, (int)); STATIC_DCL void FDECL(def_bflush, (int)); -STATIC_DCL void FDECL(def_bwrite, (int,genericptr_t,unsigned int)); +STATIC_DCL void FDECL(def_bwrite, (int, genericptr_t, unsigned int)); #ifdef ZEROCOMP STATIC_DCL void FDECL(zerocomp_bufon, (int)); STATIC_DCL void FDECL(zerocomp_bufoff, (int)); STATIC_DCL void FDECL(zerocomp_bflush, (int)); -STATIC_DCL void FDECL(zerocomp_bwrite, (int,genericptr_t,unsigned int)); +STATIC_DCL void FDECL(zerocomp_bwrite, (int, genericptr_t, unsigned int)); STATIC_DCL void FDECL(zerocomp_bputc, (int)); #endif static struct save_procs { - const char *name; - void FDECL((*save_bufon), (int)); - void FDECL((*save_bufoff), (int)); - void FDECL((*save_bflush), (int)); - void FDECL((*save_bwrite), (int,genericptr_t,unsigned int)); - void FDECL((*save_bclose), (int)); + const char *name; + void FDECL((*save_bufon), (int)); + void FDECL((*save_bufoff), (int)); + void FDECL((*save_bflush), (int)); + void FDECL((*save_bwrite), (int, genericptr_t, unsigned int)); + void FDECL((*save_bclose), (int)); } saveprocs = { #if !defined(ZEROCOMP) || (defined(COMPRESS) || defined(ZLIB_COMP)) - "externalcomp", - def_bufon, - def_bufoff, - def_bflush, - def_bwrite, - def_bclose, + "externalcomp", def_bufon, def_bufoff, def_bflush, def_bwrite, def_bclose, #else - "zerocomp", - zerocomp_bufon, - zerocomp_bufoff, - zerocomp_bflush, - zerocomp_bwrite, - zerocomp_bclose, + "zerocomp", zerocomp_bufon, zerocomp_bufoff, + zerocomp_bflush, zerocomp_bwrite, zerocomp_bclose, #endif }; static long nulls[sizeof(struct trap) + sizeof(struct fruit)]; #if defined(UNIX) || defined(VMS) || defined(__EMX__) || defined(WIN32) -#define HUP if (!program_state.done_hup) +#define HUP if (!program_state.done_hup) #else #define HUP #endif @@ -88,259 +79,269 @@ static unsigned ustuck_id = 0, usteed_id = 0; int dosave() { - clear_nhwindow(WIN_MESSAGE); - if(yn("Really save?") == 'n') { - clear_nhwindow(WIN_MESSAGE); - if(multi > 0) nomul(0); - } else { - clear_nhwindow(WIN_MESSAGE); - pline("Saving..."); + clear_nhwindow(WIN_MESSAGE); + if (yn("Really save?") == 'n') { + clear_nhwindow(WIN_MESSAGE); + if (multi > 0) + nomul(0); + } else { + clear_nhwindow(WIN_MESSAGE); + pline("Saving..."); #if defined(UNIX) || defined(VMS) || defined(__EMX__) - program_state.done_hup = 0; + program_state.done_hup = 0; #endif - if(dosave0()) { - u.uhp = -1; /* universal game's over indicator */ - /* make sure they see the Saving message */ - display_nhwindow(WIN_MESSAGE, TRUE); - exit_nhwindows("Be seeing you..."); - terminate(EXIT_SUCCESS); - } else (void)doredraw(); - } - return 0; + if (dosave0()) { + u.uhp = -1; /* universal game's over indicator */ + /* make sure they see the Saving message */ + display_nhwindow(WIN_MESSAGE, TRUE); + exit_nhwindows("Be seeing you..."); + terminate(EXIT_SUCCESS); + } else + (void) doredraw(); + } + return 0; } /* returns 1 if save successful */ int dosave0() { - const char *fq_save; - register int fd, ofd; - xchar ltmp; - d_level uz_save; - char whynot[BUFSZ]; + const char *fq_save; + register int fd, ofd; + xchar ltmp; + d_level uz_save; + char whynot[BUFSZ]; - /* we may get here via hangup signal, in which case we want to fix up - a few of things before saving so that they won't be restored in - an improper state; these will be no-ops for normal save sequence */ - u.uinvulnerable = 0; - if (iflags.save_uinwater) u.uinwater = 1, iflags.save_uinwater = 0; - if (iflags.save_uburied) u.uburied = 1, iflags.save_uburied = 0; + /* we may get here via hangup signal, in which case we want to fix up + a few of things before saving so that they won't be restored in + an improper state; these will be no-ops for normal save sequence */ + u.uinvulnerable = 0; + if (iflags.save_uinwater) + u.uinwater = 1, iflags.save_uinwater = 0; + if (iflags.save_uburied) + u.uburied = 1, iflags.save_uburied = 0; - if (!program_state.something_worth_saving || !SAVEF[0]) - return 0; - fq_save = fqname(SAVEF, SAVEPREFIX, 1); /* level files take 0 */ + if (!program_state.something_worth_saving || !SAVEF[0]) + return 0; + fq_save = fqname(SAVEF, SAVEPREFIX, 1); /* level files take 0 */ #if defined(UNIX) || defined(VMS) - sethanguphandler((void FDECL((*),(int)))SIG_IGN); + sethanguphandler((void FDECL((*), (int) )) SIG_IGN); #endif #ifndef NO_SIGNAL - (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); #endif #if defined(MICRO) && defined(MFLOPPY) - if (!saveDiskPrompt(0)) return 0; + if (!saveDiskPrompt(0)) + return 0; #endif - HUP if (iflags.window_inited) { - nh_uncompress(fq_save); - fd = open_savefile(); - if (fd > 0) { - (void) nhclose(fd); - clear_nhwindow(WIN_MESSAGE); - There("seems to be an old save file."); - if (yn("Overwrite the old file?") == 'n') { - nh_compress(fq_save); - return 0; - } - } - } + HUP if (iflags.window_inited) + { + nh_uncompress(fq_save); + fd = open_savefile(); + if (fd > 0) { + (void) nhclose(fd); + clear_nhwindow(WIN_MESSAGE); + There("seems to be an old save file."); + if (yn("Overwrite the old file?") == 'n') { + nh_compress(fq_save); + return 0; + } + } + } - HUP mark_synch(); /* flush any buffered screen output */ + HUP mark_synch(); /* flush any buffered screen output */ - fd = create_savefile(); - if(fd < 0) { - HUP pline("Cannot open save file."); - (void) delete_savefile(); /* ab@unido */ - return(0); - } + fd = create_savefile(); + if (fd < 0) { + HUP pline("Cannot open save file."); + (void) delete_savefile(); /* ab@unido */ + return (0); + } - vision_recalc(2); /* shut down vision to prevent problems - in the event of an impossible() call */ - - /* undo date-dependent luck adjustments made at startup time */ - if(flags.moonphase == FULL_MOON) /* ut-sally!fletcher */ - change_luck(-1); /* and unido!ab */ - if(flags.friday13) - change_luck(1); - if(iflags.window_inited) - HUP clear_nhwindow(WIN_MESSAGE); + vision_recalc(2); /* shut down vision to prevent problems + in the event of an impossible() call */ + + /* undo date-dependent luck adjustments made at startup time */ + if (flags.moonphase == FULL_MOON) /* ut-sally!fletcher */ + change_luck(-1); /* and unido!ab */ + if (flags.friday13) + change_luck(1); + if (iflags.window_inited) + HUP clear_nhwindow(WIN_MESSAGE); #ifdef MICRO - dotcnt = 0; - dotrow = 2; - curs(WIN_MAP, 1, 1); - if (strncmpi("X11", windowprocs.name, 3)) - putstr(WIN_MAP, 0, "Saving:"); + dotcnt = 0; + dotrow = 2; + curs(WIN_MAP, 1, 1); + if (strncmpi("X11", windowprocs.name, 3)) + putstr(WIN_MAP, 0, "Saving:"); #endif #ifdef MFLOPPY - /* make sure there is enough disk space */ - if (iflags.checkspace) { - long fds, needed; + /* make sure there is enough disk space */ + if (iflags.checkspace) { + long fds, needed; - savelev(fd, ledger_no(&u.uz), COUNT_SAVE); - savegamestate(fd, COUNT_SAVE); - needed = bytes_counted; + savelev(fd, ledger_no(&u.uz), COUNT_SAVE); + savegamestate(fd, COUNT_SAVE); + needed = bytes_counted; - for (ltmp = 1; ltmp <= maxledgerno(); ltmp++) - if (ltmp != ledger_no(&u.uz) && level_info[ltmp].where) - needed += level_info[ltmp].size + (sizeof ltmp); - fds = freediskspace(fq_save); - if (needed > fds) { - HUP { - There("is insufficient space on SAVE disk."); - pline("Require %ld bytes but only have %ld.", needed, fds); - } - flushout(); - (void) nhclose(fd); - (void) delete_savefile(); - return 0; - } + for (ltmp = 1; ltmp <= maxledgerno(); ltmp++) + if (ltmp != ledger_no(&u.uz) && level_info[ltmp].where) + needed += level_info[ltmp].size + (sizeof ltmp); + fds = freediskspace(fq_save); + if (needed > fds) { + HUP + { + There("is insufficient space on SAVE disk."); + pline("Require %ld bytes but only have %ld.", needed, fds); + } + flushout(); + (void) nhclose(fd); + (void) delete_savefile(); + return 0; + } - co_false(); - } + co_false(); + } #endif /* MFLOPPY */ - store_version(fd); - store_savefileinfo(fd); - store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); - savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); - savegamestate(fd, WRITE_SAVE | FREE_SAVE); + store_version(fd); + store_savefileinfo(fd); + store_plname_in_file(fd); + ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + usteed_id = (u.usteed ? u.usteed->m_id : 0); + savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); + savegamestate(fd, WRITE_SAVE | FREE_SAVE); - /* While copying level files around, zero out u.uz to keep - * parts of the restore code from completely initializing all - * in-core data structures, since all we're doing is copying. - * This also avoids at least one nasty core dump. - */ - uz_save = u.uz; - u.uz.dnum = u.uz.dlevel = 0; - /* these pointers are no longer valid, and at least u.usteed - * may mislead place_monster() on other levels - */ - u.ustuck = (struct monst *)0; - u.usteed = (struct monst *)0; + /* While copying level files around, zero out u.uz to keep + * parts of the restore code from completely initializing all + * in-core data structures, since all we're doing is copying. + * This also avoids at least one nasty core dump. + */ + uz_save = u.uz; + u.uz.dnum = u.uz.dlevel = 0; + /* these pointers are no longer valid, and at least u.usteed + * may mislead place_monster() on other levels + */ + u.ustuck = (struct monst *) 0; + u.usteed = (struct monst *) 0; - for(ltmp = (xchar)1; ltmp <= maxledgerno(); ltmp++) { - if (ltmp == ledger_no(&uz_save)) continue; - if (!(level_info[ltmp].flags & LFILE_EXISTS)) continue; + for (ltmp = (xchar) 1; ltmp <= maxledgerno(); ltmp++) { + if (ltmp == ledger_no(&uz_save)) + continue; + if (!(level_info[ltmp].flags & LFILE_EXISTS)) + continue; #ifdef MICRO - curs(WIN_MAP, 1 + dotcnt++, dotrow); - if (dotcnt >= (COLNO - 1)) { - dotrow++; - dotcnt = 0; - } - if (strncmpi("X11", windowprocs.name, 3)){ - putstr(WIN_MAP, 0, "."); - } - mark_synch(); + curs(WIN_MAP, 1 + dotcnt++, dotrow); + if (dotcnt >= (COLNO - 1)) { + dotrow++; + dotcnt = 0; + } + if (strncmpi("X11", windowprocs.name, 3)) { + putstr(WIN_MAP, 0, "."); + } + mark_synch(); #endif - ofd = open_levelfile(ltmp, whynot); - if (ofd < 0) { - HUP pline1(whynot); - (void) nhclose(fd); - (void) delete_savefile(); - HUP Strcpy(killer.name, whynot); - HUP done(TRICKED); - return(0); - } - minit(); /* ZEROCOMP */ - getlev(ofd, hackpid, ltmp, FALSE); - (void) nhclose(ofd); - bwrite(fd, (genericptr_t) <mp, sizeof ltmp); /* level number*/ - savelev(fd, ltmp, WRITE_SAVE | FREE_SAVE); /* actual level*/ - delete_levelfile(ltmp); - } - bclose(fd); + ofd = open_levelfile(ltmp, whynot); + if (ofd < 0) { + HUP pline1(whynot); + (void) nhclose(fd); + (void) delete_savefile(); + HUP Strcpy(killer.name, whynot); + HUP done(TRICKED); + return (0); + } + minit(); /* ZEROCOMP */ + getlev(ofd, hackpid, ltmp, FALSE); + (void) nhclose(ofd); + bwrite(fd, (genericptr_t) <mp, sizeof ltmp); /* level number*/ + savelev(fd, ltmp, WRITE_SAVE | FREE_SAVE); /* actual level*/ + delete_levelfile(ltmp); + } + bclose(fd); - u.uz = uz_save; + u.uz = uz_save; - /* get rid of current level --jgm */ - delete_levelfile(ledger_no(&u.uz)); - delete_levelfile(0); - nh_compress(fq_save); - /* this should probably come sooner... */ - program_state.something_worth_saving = 0; - return(1); + /* get rid of current level --jgm */ + delete_levelfile(ledger_no(&u.uz)); + delete_levelfile(0); + nh_compress(fq_save); + /* this should probably come sooner... */ + program_state.something_worth_saving = 0; + return (1); } STATIC_OVL void savegamestate(fd, mode) register int fd, mode; { - unsigned long uid; + unsigned long uid; #ifdef MFLOPPY - count_only = (mode & COUNT_SAVE); + count_only = (mode & COUNT_SAVE); #endif - uid = (unsigned long)getuid(); - bwrite(fd, (genericptr_t) &uid, sizeof uid); - bwrite(fd, (genericptr_t) &context, sizeof(struct context_info)); - bwrite(fd, (genericptr_t) &flags, sizeof(struct flag)); + uid = (unsigned long) getuid(); + bwrite(fd, (genericptr_t) &uid, sizeof uid); + bwrite(fd, (genericptr_t) &context, sizeof(struct context_info)); + bwrite(fd, (genericptr_t) &flags, sizeof(struct flag)); #ifdef SYSFLAGS - bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); + bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); #endif - urealtime.realtime += (long)(getnow() - urealtime.restored); - bwrite(fd, (genericptr_t) &u, sizeof(struct you)); - bwrite(fd, yyyymmddhhmmss(ubirthday), 14); - bwrite(fd, (genericptr_t) &urealtime.realtime, sizeof(urealtime.realtime)); - bwrite(fd, yyyymmddhhmmss(urealtime.restored), 14); - save_killers(fd, mode); + urealtime.realtime += (long) (getnow() - urealtime.restored); + bwrite(fd, (genericptr_t) &u, sizeof(struct you)); + bwrite(fd, yyyymmddhhmmss(ubirthday), 14); + bwrite(fd, (genericptr_t) &urealtime.realtime, + sizeof(urealtime.realtime)); + bwrite(fd, yyyymmddhhmmss(urealtime.restored), 14); + save_killers(fd, mode); - /* must come before migrating_objs and migrating_mons are freed */ - save_timers(fd, mode, RANGE_GLOBAL); - save_light_sources(fd, mode, RANGE_GLOBAL); + /* must come before migrating_objs and migrating_mons are freed */ + save_timers(fd, mode, RANGE_GLOBAL); + save_light_sources(fd, mode, RANGE_GLOBAL); - saveobjchn(fd, invent, mode); - if (BALL_IN_MON) { - /* prevent loss of ball & chain when swallowed */ - uball->nobj = uchain; - uchain->nobj = (struct obj *)0; - saveobjchn(fd, uball, mode); - } else { - saveobjchn(fd, (struct obj *)0, mode); - } + saveobjchn(fd, invent, mode); + if (BALL_IN_MON) { + /* prevent loss of ball & chain when swallowed */ + uball->nobj = uchain; + uchain->nobj = (struct obj *) 0; + saveobjchn(fd, uball, mode); + } else { + saveobjchn(fd, (struct obj *) 0, mode); + } - saveobjchn(fd, migrating_objs, mode); - savemonchn(fd, migrating_mons, mode); - if (release_data(mode)) { - invent = 0; - migrating_objs = 0; - migrating_mons = 0; - } - bwrite(fd, (genericptr_t) mvitals, sizeof(mvitals)); + saveobjchn(fd, migrating_objs, mode); + savemonchn(fd, migrating_mons, mode); + if (release_data(mode)) { + invent = 0; + migrating_objs = 0; + migrating_mons = 0; + } + bwrite(fd, (genericptr_t) mvitals, sizeof(mvitals)); - save_dungeon(fd, (boolean)!!perform_bwrite(mode), - (boolean)!!release_data(mode)); - savelevchn(fd, mode); - bwrite(fd, (genericptr_t) &moves, sizeof moves); - bwrite(fd, (genericptr_t) &monstermoves, sizeof monstermoves); - bwrite(fd, (genericptr_t) &quest_status, sizeof(struct q_score)); - bwrite(fd, (genericptr_t) spl_book, - sizeof(struct spell) * (MAXSPELL + 1)); - save_artifacts(fd); - save_oracles(fd, mode); - if(ustuck_id) - bwrite(fd, (genericptr_t) &ustuck_id, sizeof ustuck_id); - if(usteed_id) - bwrite(fd, (genericptr_t) &usteed_id, sizeof usteed_id); - bwrite(fd, (genericptr_t) pl_character, sizeof pl_character); - bwrite(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); - savefruitchn(fd, mode); - savenames(fd, mode); - save_waterlevel(fd, mode); - save_msghistory(fd, mode); - bflush(fd); + save_dungeon(fd, (boolean) !!perform_bwrite(mode), + (boolean) !!release_data(mode)); + savelevchn(fd, mode); + bwrite(fd, (genericptr_t) &moves, sizeof moves); + bwrite(fd, (genericptr_t) &monstermoves, sizeof monstermoves); + bwrite(fd, (genericptr_t) &quest_status, sizeof(struct q_score)); + bwrite(fd, (genericptr_t) spl_book, + sizeof(struct spell) * (MAXSPELL + 1)); + save_artifacts(fd); + save_oracles(fd, mode); + if (ustuck_id) + bwrite(fd, (genericptr_t) &ustuck_id, sizeof ustuck_id); + if (usteed_id) + bwrite(fd, (genericptr_t) &usteed_id, sizeof usteed_id); + bwrite(fd, (genericptr_t) pl_character, sizeof pl_character); + bwrite(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); + savefruitchn(fd, mode); + savenames(fd, mode); + save_waterlevel(fd, mode); + save_msghistory(fd, mode); + bflush(fd); } boolean @@ -349,11 +350,11 @@ int fd; char *whynot; { if (fd < 0) { - pline1(whynot); - pline("Probably someone removed it."); - Strcpy(killer.name, whynot); - done(TRICKED); - return TRUE; + pline1(whynot); + pline("Probably someone removed it."); + Strcpy(killer.name, whynot); + done(TRICKED); + return TRUE; } return FALSE; } @@ -362,66 +363,66 @@ char *whynot; void savestateinlock() { - int fd, hpid; - static boolean havestate = TRUE; - char whynot[BUFSZ]; + int fd, hpid; + static boolean havestate = TRUE; + char whynot[BUFSZ]; - /* When checkpointing is on, the full state needs to be written - * on each checkpoint. When checkpointing is off, only the pid - * needs to be in the level.0 file, so it does not need to be - * constantly rewritten. When checkpointing is turned off during - * a game, however, the file has to be rewritten once to truncate - * it and avoid restoring from outdated information. - * - * Restricting havestate to this routine means that an additional - * noop pid rewriting will take place on the first "checkpoint" after - * the game is started or restored, if checkpointing is off. - */ - if (flags.ins_chkpt || havestate) { - /* save the rest of the current game state in the lock file, - * following the original int pid, the current level number, - * and the current savefile name, which should not be subject - * to any internal compression schemes since they must be - * readable by an external utility - */ - fd = open_levelfile(0, whynot); - if (tricked_fileremoved(fd, whynot)) return; + /* When checkpointing is on, the full state needs to be written + * on each checkpoint. When checkpointing is off, only the pid + * needs to be in the level.0 file, so it does not need to be + * constantly rewritten. When checkpointing is turned off during + * a game, however, the file has to be rewritten once to truncate + * it and avoid restoring from outdated information. + * + * Restricting havestate to this routine means that an additional + * noop pid rewriting will take place on the first "checkpoint" after + * the game is started or restored, if checkpointing is off. + */ + if (flags.ins_chkpt || havestate) { + /* save the rest of the current game state in the lock file, + * following the original int pid, the current level number, + * and the current savefile name, which should not be subject + * to any internal compression schemes since they must be + * readable by an external utility + */ + fd = open_levelfile(0, whynot); + if (tricked_fileremoved(fd, whynot)) + return; - (void) read(fd, (genericptr_t) &hpid, sizeof(hpid)); - if (hackpid != hpid) { - Sprintf(whynot, - "Level #0 pid (%d) doesn't match ours (%d)!", - hpid, hackpid); - pline1(whynot); - Strcpy(killer.name, whynot); - done(TRICKED); - } - (void) nhclose(fd); + (void) read(fd, (genericptr_t) &hpid, sizeof(hpid)); + if (hackpid != hpid) { + Sprintf(whynot, "Level #0 pid (%d) doesn't match ours (%d)!", + hpid, hackpid); + pline1(whynot); + Strcpy(killer.name, whynot); + done(TRICKED); + } + (void) nhclose(fd); - fd = create_levelfile(0, whynot); - if (fd < 0) { - pline1(whynot); - Strcpy(killer.name, whynot); - done(TRICKED); - return; - } - (void) write(fd, (genericptr_t) &hackpid, sizeof(hackpid)); - if (flags.ins_chkpt) { - int currlev = ledger_no(&u.uz); + fd = create_levelfile(0, whynot); + if (fd < 0) { + pline1(whynot); + Strcpy(killer.name, whynot); + done(TRICKED); + return; + } + (void) write(fd, (genericptr_t) &hackpid, sizeof(hackpid)); + if (flags.ins_chkpt) { + int currlev = ledger_no(&u.uz); - (void) write(fd, (genericptr_t) &currlev, sizeof(currlev)); - save_savefile_name(fd); - store_version(fd); - store_savefileinfo(fd); - store_plname_in_file(fd); + (void) write(fd, (genericptr_t) &currlev, sizeof(currlev)); + save_savefile_name(fd); + store_version(fd); + store_savefileinfo(fd); + store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); - savegamestate(fd, WRITE_SAVE); - } - bclose(fd); - } - havestate = flags.ins_chkpt; + ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + usteed_id = (u.usteed ? u.usteed->m_id : 0); + savegamestate(fd, WRITE_SAVE); + } + bclose(fd); + } + havestate = flags.ins_chkpt; } #endif @@ -432,109 +433,115 @@ int fd; xchar lev; int mode; { - if (mode & COUNT_SAVE) { - bytes_counted = 0; - savelev0(fd, lev, COUNT_SAVE); - /* probably bytes_counted will be filled in again by an - * immediately following WRITE_SAVE anyway, but we'll - * leave it out of checkspace just in case */ - if (iflags.checkspace) { - while (bytes_counted > freediskspace(levels)) - if (!swapout_oldest()) - return FALSE; - } - } - if (mode & (WRITE_SAVE | FREE_SAVE)) { - bytes_counted = 0; - savelev0(fd, lev, mode); - } - if (mode != FREE_SAVE) { - level_info[lev].where = ACTIVE; - level_info[lev].time = moves; - level_info[lev].size = bytes_counted; - } - return TRUE; + if (mode & COUNT_SAVE) { + bytes_counted = 0; + savelev0(fd, lev, COUNT_SAVE); + /* probably bytes_counted will be filled in again by an + * immediately following WRITE_SAVE anyway, but we'll + * leave it out of checkspace just in case */ + if (iflags.checkspace) { + while (bytes_counted > freediskspace(levels)) + if (!swapout_oldest()) + return FALSE; + } + } + if (mode & (WRITE_SAVE | FREE_SAVE)) { + bytes_counted = 0; + savelev0(fd, lev, mode); + } + if (mode != FREE_SAVE) { + level_info[lev].where = ACTIVE; + level_info[lev].time = moves; + level_info[lev].size = bytes_counted; + } + return TRUE; } STATIC_OVL void -savelev0(fd,lev,mode) +savelev0(fd, lev, mode) #else void -savelev(fd,lev,mode) +savelev(fd, lev, mode) #endif int fd; xchar lev; int mode; { #ifdef TOS - short tlev; + short tlev; #endif - /* if we're tearing down the current level without saving anything - (which happens upon entrance to the endgame or after an aborted - restore attempt) then we don't want to do any actual I/O */ - if (mode == FREE_SAVE) goto skip_lots; + /* if we're tearing down the current level without saving anything + (which happens upon entrance to the endgame or after an aborted + restore attempt) then we don't want to do any actual I/O */ + if (mode == FREE_SAVE) + goto skip_lots; - /* purge any dead monsters (necessary if we're starting - a panic save rather than a normal one, or sometimes - when changing levels without taking time -- e.g. - create statue trap then immediately level teleport) */ - if (iflags.purge_monsters) dmonsfree(); + /* purge any dead monsters (necessary if we're starting + a panic save rather than a normal one, or sometimes + when changing levels without taking time -- e.g. + create statue trap then immediately level teleport) */ + if (iflags.purge_monsters) + dmonsfree(); - if(fd < 0) panic("Save on bad file!"); /* impossible */ + if (fd < 0) + panic("Save on bad file!"); /* impossible */ #ifdef MFLOPPY - count_only = (mode & COUNT_SAVE); + count_only = (mode & COUNT_SAVE); #endif - if (lev >= 0 && lev <= maxledgerno()) - level_info[lev].flags |= VISITED; - bwrite(fd,(genericptr_t) &hackpid,sizeof(hackpid)); + if (lev >= 0 && lev <= maxledgerno()) + level_info[lev].flags |= VISITED; + bwrite(fd, (genericptr_t) &hackpid, sizeof(hackpid)); #ifdef TOS - tlev=lev; tlev &= 0x00ff; - bwrite(fd,(genericptr_t) &tlev,sizeof(tlev)); + tlev = lev; + tlev &= 0x00ff; + bwrite(fd, (genericptr_t) &tlev, sizeof(tlev)); #else - bwrite(fd,(genericptr_t) &lev,sizeof(lev)); + bwrite(fd, (genericptr_t) &lev, sizeof(lev)); #endif - savecemetery(fd, mode, &level.bonesinfo); - savelevl(fd, (boolean)((sfsaveinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP)); - bwrite(fd,(genericptr_t) lastseentyp,sizeof(lastseentyp)); - bwrite(fd,(genericptr_t) &monstermoves,sizeof(monstermoves)); - bwrite(fd,(genericptr_t) &upstair,sizeof(stairway)); - bwrite(fd,(genericptr_t) &dnstair,sizeof(stairway)); - bwrite(fd,(genericptr_t) &upladder,sizeof(stairway)); - bwrite(fd,(genericptr_t) &dnladder,sizeof(stairway)); - bwrite(fd,(genericptr_t) &sstairs,sizeof(stairway)); - bwrite(fd,(genericptr_t) &updest,sizeof(dest_area)); - bwrite(fd,(genericptr_t) &dndest,sizeof(dest_area)); - bwrite(fd,(genericptr_t) &level.flags,sizeof(level.flags)); - bwrite(fd, (genericptr_t) doors, sizeof(doors)); - save_rooms(fd); /* no dynamic memory to reclaim */ + savecemetery(fd, mode, &level.bonesinfo); + savelevl(fd, (boolean)((sfsaveinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP)); + bwrite(fd, (genericptr_t) lastseentyp, sizeof(lastseentyp)); + bwrite(fd, (genericptr_t) &monstermoves, sizeof(monstermoves)); + bwrite(fd, (genericptr_t) &upstair, sizeof(stairway)); + bwrite(fd, (genericptr_t) &dnstair, sizeof(stairway)); + bwrite(fd, (genericptr_t) &upladder, sizeof(stairway)); + bwrite(fd, (genericptr_t) &dnladder, sizeof(stairway)); + bwrite(fd, (genericptr_t) &sstairs, sizeof(stairway)); + bwrite(fd, (genericptr_t) &updest, sizeof(dest_area)); + bwrite(fd, (genericptr_t) &dndest, sizeof(dest_area)); + bwrite(fd, (genericptr_t) &level.flags, sizeof(level.flags)); + bwrite(fd, (genericptr_t) doors, sizeof(doors)); + save_rooms(fd); /* no dynamic memory to reclaim */ - /* from here on out, saving also involves allocated memory cleanup */ - skip_lots: - /* this comes before the map, so need cleanup here if we skipped */ - if (mode == FREE_SAVE) savecemetery(fd, mode, &level.bonesinfo); - /* must be saved before mons, objs, and buried objs */ - save_timers(fd, mode, RANGE_LEVEL); - save_light_sources(fd, mode, RANGE_LEVEL); +/* from here on out, saving also involves allocated memory cleanup */ +skip_lots: + /* this comes before the map, so need cleanup here if we skipped */ + if (mode == FREE_SAVE) + savecemetery(fd, mode, &level.bonesinfo); + /* must be saved before mons, objs, and buried objs */ + save_timers(fd, mode, RANGE_LEVEL); + save_light_sources(fd, mode, RANGE_LEVEL); - savemonchn(fd, fmon, mode); - save_worm(fd, mode); /* save worm information */ - savetrapchn(fd, ftrap, mode); - saveobjchn(fd, fobj, mode); - saveobjchn(fd, level.buriedobjlist, mode); - saveobjchn(fd, billobjs, mode); - if (release_data(mode)) { - fmon = 0; - ftrap = 0; - fobj = 0; - level.buriedobjlist = 0; - billobjs = 0; - /* level.bonesinfo = 0; -- handled by savecemetery() */ - } - save_engravings(fd, mode); - savedamage(fd, mode); - save_regions(fd, mode); - if (mode != FREE_SAVE) bflush(fd); + savemonchn(fd, fmon, mode); + save_worm(fd, mode); /* save worm information */ + savetrapchn(fd, ftrap, mode); + saveobjchn(fd, fobj, mode); + saveobjchn(fd, level.buriedobjlist, mode); + saveobjchn(fd, billobjs, mode); + if (release_data(mode)) { + fmon = 0; + ftrap = 0; + fobj = 0; + level.buriedobjlist = 0; + billobjs = 0; + /* level.bonesinfo = 0; -- handled by savecemetery() */ + } + save_engravings(fd, mode); + savedamage(fd, mode); + save_regions(fd, mode); + if (mode != FREE_SAVE) + bflush(fd); } STATIC_OVL void @@ -543,54 +550,51 @@ int fd; boolean rlecomp; { #ifdef RLECOMP - struct rm *prm, *rgrm; - int x, y; - uchar match; + struct rm *prm, *rgrm; + int x, y; + uchar match; - if (rlecomp) { - /* perform run-length encoding of rm structs */ + if (rlecomp) { + /* perform run-length encoding of rm structs */ - rgrm = &levl[0][0]; /* start matching at first rm */ - match = 0; + rgrm = &levl[0][0]; /* start matching at first rm */ + match = 0; - for (y = 0; y < ROWNO; y++) { - for (x = 0; x < COLNO; x++) { - prm = &levl[x][y]; - if (prm->glyph == rgrm->glyph - && prm->typ == rgrm->typ - && prm->seenv == rgrm->seenv - && prm->horizontal == rgrm->horizontal - && prm->flags == rgrm->flags - && prm->lit == rgrm->lit - && prm->waslit == rgrm->waslit - && prm->roomno == rgrm->roomno - && prm->edge == rgrm->edge - && prm->candig == rgrm->candig) { - match++; - if (match > 254) { - match = 254; /* undo this match */ - goto writeout; - } - } else { - /* the run has been broken, - * write out run-length encoding */ - writeout: - bwrite(fd, (genericptr_t)&match, sizeof(uchar)); - bwrite(fd, (genericptr_t)rgrm, sizeof(struct rm)); - /* start encoding again. we have at least 1 rm - * in the next run, viz. this one. */ - match = 1; - rgrm = prm; - } - } - } - if (match > 0) { - bwrite(fd, (genericptr_t)&match, sizeof(uchar)); - bwrite(fd, (genericptr_t)rgrm, sizeof(struct rm)); - } - } else + for (y = 0; y < ROWNO; y++) { + for (x = 0; x < COLNO; x++) { + prm = &levl[x][y]; + if (prm->glyph == rgrm->glyph && prm->typ == rgrm->typ + && prm->seenv == rgrm->seenv + && prm->horizontal == rgrm->horizontal + && prm->flags == rgrm->flags && prm->lit == rgrm->lit + && prm->waslit == rgrm->waslit + && prm->roomno == rgrm->roomno && prm->edge == rgrm->edge + && prm->candig == rgrm->candig) { + match++; + if (match > 254) { + match = 254; /* undo this match */ + goto writeout; + } + } else { + /* the run has been broken, + * write out run-length encoding */ + writeout: + bwrite(fd, (genericptr_t) &match, sizeof(uchar)); + bwrite(fd, (genericptr_t) rgrm, sizeof(struct rm)); + /* start encoding again. we have at least 1 rm + * in the next run, viz. this one. */ + match = 1; + rgrm = prm; + } + } + } + if (match > 0) { + bwrite(fd, (genericptr_t) &match, sizeof(uchar)); + bwrite(fd, (genericptr_t) rgrm, sizeof(struct rm)); + } + } else #endif /* RLECOMP */ - bwrite(fd,(genericptr_t) levl,sizeof(levl)); + bwrite(fd, (genericptr_t) levl, sizeof(levl)); } /*ARGSUSED*/ @@ -611,8 +615,7 @@ int fd; return; } -void -bflush(fd) /* flush run and buffer */ +void bflush(fd) /* flush run and buffer */ register int fd; { (*saveprocs.save_bflush)(fd); @@ -643,15 +646,15 @@ static boolean buffering = FALSE; STATIC_OVL void def_bufon(fd) - int fd; +int fd; { #ifdef UNIX - if(bw_fd != fd) { - if(bw_fd >= 0) - panic("double buffering unexpected"); - bw_fd = fd; - if((bw_FILE = fdopen(fd, "w")) == 0) - panic("buffering of file %d failed", fd); + if (bw_fd != fd) { + if (bw_fd >= 0) + panic("double buffering unexpected"); + bw_fd = fd; + if ((bw_FILE = fdopen(fd, "w")) == 0) + panic("buffering of file %d failed", fd); } #endif buffering = TRUE; @@ -667,70 +670,71 @@ int fd; STATIC_OVL void def_bflush(fd) - int fd; +int fd; { #ifdef UNIX - if(fd == bw_fd) { - if(fflush(bw_FILE) == EOF) - panic("flush of savefile failed!"); + if (fd == bw_fd) { + if (fflush(bw_FILE) == EOF) + panic("flush of savefile failed!"); } #endif return; } STATIC_OVL void -def_bwrite(fd,loc,num) +def_bwrite(fd, loc, num) register int fd; register genericptr_t loc; register unsigned num; { - boolean failed; + boolean failed; #ifdef MFLOPPY - bytes_counted += num; - if (count_only) return; + bytes_counted += num; + if (count_only) + return; #endif #ifdef UNIX - if (buffering) { - if(fd != bw_fd) - panic("unbuffered write to fd %d (!= %d)", fd, bw_fd); + if (buffering) { + if (fd != bw_fd) + panic("unbuffered write to fd %d (!= %d)", fd, bw_fd); - failed = (fwrite(loc, (int)num, 1, bw_FILE) != 1); - } else + failed = (fwrite(loc, (int) num, 1, bw_FILE) != 1); + } else #endif /* UNIX */ - { + { /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */ #if defined(BSD) || defined(ULTRIX) || defined(WIN32) || defined(_MSC_VER) - failed = ((long)write(fd, loc, (int)num) != (long)num); + failed = ((long) write(fd, loc, (int) num) != (long) num); #else /* e.g. SYSV, __TURBOC__ */ - failed = ((long)write(fd, loc, num) != (long)num); + failed = ((long) write(fd, loc, num) != (long) num); #endif - } + } - if (failed) { + if (failed) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) - terminate(EXIT_FAILURE); - else + if (program_state.done_hup) + terminate(EXIT_FAILURE); + else #endif - panic("cannot write %u bytes to file #%d", num, fd); - } + panic("cannot write %u bytes to file #%d", num, fd); + } } void def_bclose(fd) - int fd; +int fd; { bufoff(fd); #ifdef UNIX if (fd == bw_fd) { - (void) fclose(bw_FILE); - bw_fd = -1; - bw_FILE = 0; + (void) fclose(bw_FILE); + bw_fd = -1; + bw_FILE = 0; } else #endif - (void) nhclose(fd); + (void) nhclose(fd); return; } @@ -743,11 +747,11 @@ def_bclose(fd) * file is written out. */ -#define RLESC '\0' /* Leading character for run of LRESC's */ +#define RLESC '\0' /* Leading character for run of LRESC's */ #define flushoutrun(ln) (zerocomp_bputc(RLESC), zerocomp_bputc(ln), ln = -1) #ifndef ZEROCOMP_BUFSIZ -# define ZEROCOMP_BUFSIZ BUFSZ +#define ZEROCOMP_BUFSIZ BUFSZ #endif static NEARDATA unsigned char outbuf[ZEROCOMP_BUFSIZ]; static NEARDATA unsigned short outbufp = 0; @@ -767,18 +771,18 @@ int c; #ifdef MFLOPPY bytes_counted++; if (count_only) - return; + return; #endif if (outbufp >= sizeof outbuf) { - (void) write(bwritefd, outbuf, sizeof outbuf); - outbufp = 0; + (void) write(bwritefd, outbuf, sizeof outbuf); + outbufp = 0; } - outbuf[outbufp++] = (unsigned char)c; + outbuf[outbufp++] = (unsigned char) c; } /*ARGSUSED*/ -void -STATIC_OVL zerocomp_bufon(fd) +void STATIC_OVL +zerocomp_bufon(fd) int fd; { compressing = TRUE; @@ -791,36 +795,36 @@ zerocomp_bufoff(fd) int fd; { if (outbufp) { - outbufp = 0; - panic("closing file with buffered data still unwritten"); + outbufp = 0; + panic("closing file with buffered data still unwritten"); } outrunlength = -1; compressing = FALSE; return; } -STATIC_OVL void -zerocomp_bflush(fd) /* flush run and buffer */ +STATIC_OVL void zerocomp_bflush(fd) /* flush run and buffer */ register int fd; { bwritefd = fd; - if (outrunlength >= 0) { /* flush run */ - flushoutrun(outrunlength); + if (outrunlength >= 0) { /* flush run */ + flushoutrun(outrunlength); } #ifdef MFLOPPY - if (count_only) outbufp = 0; + if (count_only) + outbufp = 0; #endif if (outbufp) { - if (write(fd, outbuf, outbufp) != outbufp) { + if (write(fd, outbuf, outbufp) != outbufp) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) - terminate(EXIT_FAILURE); - else + if (program_state.done_hup) + terminate(EXIT_FAILURE); + else #endif - zerocomp_bclose(fd); /* panic (outbufp != 0) */ - } - outbufp = 0; + zerocomp_bclose(fd); /* panic (outbufp != 0) */ + } + outbufp = 0; } } @@ -830,35 +834,36 @@ int fd; genericptr_t loc; register unsigned num; { - register unsigned char *bp = (unsigned char *)loc; + register unsigned char *bp = (unsigned char *) loc; if (!compressing) { #ifdef MFLOPPY - bytes_counted += num; - if (count_only) return; + bytes_counted += num; + if (count_only) + return; #endif - if ((unsigned) write(fd, loc, num) != num) { + if ((unsigned) write(fd, loc, num) != num) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) - terminate(EXIT_FAILURE); - else + if (program_state.done_hup) + terminate(EXIT_FAILURE); + else #endif - panic("cannot write %u bytes to file #%d", num, fd); - } + panic("cannot write %u bytes to file #%d", num, fd); + } } else { - bwritefd = fd; - for (; num; num--, bp++) { - if (*bp == RLESC) { /* One more char in run */ - if (++outrunlength == 0xFF) { - flushoutrun(outrunlength); - } - } else { /* end of run */ - if (outrunlength >= 0) { /* flush run */ - flushoutrun(outrunlength); - } - zerocomp_bputc(*bp); - } - } + bwritefd = fd; + for (; num; num--, bp++) { + if (*bp == RLESC) { /* One more char in run */ + if (++outrunlength == 0xFF) { + flushoutrun(outrunlength); + } + } else { /* end of run */ + if (outrunlength >= 0) { /* flush run */ + flushoutrun(outrunlength); + } + zerocomp_bputc(*bp); + } + } } } @@ -876,22 +881,23 @@ STATIC_OVL void savelevchn(fd, mode) register int fd, mode; { - s_level *tmplev, *tmplev2; - int cnt = 0; + s_level *tmplev, *tmplev2; + int cnt = 0; - for (tmplev = sp_levchn; tmplev; tmplev = tmplev->next) cnt++; - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) &cnt, sizeof(int)); + for (tmplev = sp_levchn; tmplev; tmplev = tmplev->next) + cnt++; + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) &cnt, sizeof(int)); - for (tmplev = sp_levchn; tmplev; tmplev = tmplev2) { - tmplev2 = tmplev->next; - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) tmplev, sizeof(s_level)); - if (release_data(mode)) - free((genericptr_t) tmplev); - } - if (release_data(mode)) - sp_levchn = 0; + for (tmplev = sp_levchn; tmplev; tmplev = tmplev2) { + tmplev2 = tmplev->next; + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) tmplev, sizeof(s_level)); + if (release_data(mode)) + free((genericptr_t) tmplev); + } + if (release_data(mode)) + sp_levchn = 0; } /* used when saving a level and also when saving dungeon overview data */ @@ -906,42 +912,42 @@ struct cemetery **cemeteryaddr; flag = *cemeteryaddr ? 0 : -1; if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t)&flag, sizeof flag); + bwrite(fd, (genericptr_t) &flag, sizeof flag); nextbones = *cemeteryaddr; while ((thisbones = nextbones) != 0) { - nextbones = thisbones->next; - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t)thisbones, sizeof *thisbones); - if (release_data(mode)) - free((genericptr_t)thisbones); + nextbones = thisbones->next; + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) thisbones, sizeof *thisbones); + if (release_data(mode)) + free((genericptr_t) thisbones); } if (release_data(mode)) - *cemeteryaddr = 0; + *cemeteryaddr = 0; } STATIC_OVL void savedamage(fd, mode) register int fd, mode; { - register struct damage *damageptr, *tmp_dam; - unsigned int xl = 0; + register struct damage *damageptr, *tmp_dam; + unsigned int xl = 0; - damageptr = level.damagelist; - for (tmp_dam = damageptr; tmp_dam; tmp_dam = tmp_dam->next) - xl++; - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) &xl, sizeof(xl)); + damageptr = level.damagelist; + for (tmp_dam = damageptr; tmp_dam; tmp_dam = tmp_dam->next) + xl++; + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) &xl, sizeof(xl)); - while (xl--) { - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) damageptr, sizeof(*damageptr)); - tmp_dam = damageptr; - damageptr = damageptr->next; - if (release_data(mode)) - free((genericptr_t)tmp_dam); - } - if (release_data(mode)) - level.damagelist = 0; + while (xl--) { + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) damageptr, sizeof(*damageptr)); + tmp_dam = damageptr; + damageptr = damageptr->next; + if (release_data(mode)) + free((genericptr_t) tmp_dam); + } + if (release_data(mode)) + level.damagelist = 0; } STATIC_OVL void @@ -949,40 +955,50 @@ saveobj(fd, otmp) int fd; struct obj *otmp; { - int buflen, zerobuf = 0; + int buflen, zerobuf = 0; - buflen = sizeof(struct obj); - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - bwrite(fd, (genericptr_t) otmp, buflen); - if (otmp->oextra) { - if (ONAME(otmp)) buflen = strlen(ONAME(otmp)) + 1; - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof buflen); - if (buflen > 0) - bwrite(fd, (genericptr_t) ONAME(otmp), buflen); + buflen = sizeof(struct obj); + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + bwrite(fd, (genericptr_t) otmp, buflen); + if (otmp->oextra) { + if (ONAME(otmp)) + buflen = strlen(ONAME(otmp)) + 1; + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen > 0) + bwrite(fd, (genericptr_t) ONAME(otmp), buflen); - /* defer to savemon() for this one */ - if (OMONST(otmp)) savemon(fd, OMONST(otmp)); - else bwrite(fd, (genericptr_t) &zerobuf, sizeof zerobuf); + /* defer to savemon() for this one */ + if (OMONST(otmp)) + savemon(fd, OMONST(otmp)); + else + bwrite(fd, (genericptr_t) &zerobuf, sizeof zerobuf); - if (OMID(otmp)) buflen = sizeof(unsigned); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof buflen); - if (buflen > 0) - bwrite(fd, (genericptr_t) OMID(otmp), buflen); + if (OMID(otmp)) + buflen = sizeof(unsigned); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen > 0) + bwrite(fd, (genericptr_t) OMID(otmp), buflen); - if (OLONG(otmp)) buflen = sizeof(long); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof buflen); - if (buflen > 0) - bwrite(fd, (genericptr_t) OLONG(otmp), buflen); + if (OLONG(otmp)) + buflen = sizeof(long); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen > 0) + bwrite(fd, (genericptr_t) OLONG(otmp), buflen); - if (OMAILCMD(otmp)) buflen = strlen(OMAILCMD(otmp)) + 1; - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof buflen); - if (buflen > 0) - bwrite(fd, (genericptr_t) OMAILCMD(otmp), buflen); - } + if (OMAILCMD(otmp)) + buflen = strlen(OMAILCMD(otmp)) + 1; + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen > 0) + bwrite(fd, (genericptr_t) OMAILCMD(otmp), buflen); + } } STATIC_OVL void @@ -990,55 +1006,57 @@ saveobjchn(fd, otmp, mode) register int fd, mode; register struct obj *otmp; { - register struct obj *otmp2; - int minusone = -1; + register struct obj *otmp2; + int minusone = -1; - while(otmp) { - otmp2 = otmp->nobj; - if (perform_bwrite(mode)) { - saveobj(fd, otmp); - } - if (Has_contents(otmp)) - saveobjchn(fd,otmp->cobj,mode); - if (release_data(mode)) { -/* if (otmp->oclass == FOOD_CLASS) food_disappears(otmp); */ - /* - * If these are on the floor, the discarding could - * be because of a game save, or we could just be changing levels. - * Always invalidate the pointer, but ensure that we have - * the o_id in order to restore the pointer on reload. - */ - if (otmp == context.victual.piece) { - /* Store the o_id of the victual if mismatched */ - if (context.victual.o_id != otmp->o_id) - context.victual.o_id = otmp->o_id; - /* invalidate the pointer; on reload it will get restored */ - context.victual.piece = (struct obj *)0; - } - if (otmp == context.tin.tin) { - /* Store the o_id of your tin */ - if (context.tin.o_id != otmp->o_id) - context.tin.o_id = otmp->o_id; - /* invalidate the pointer; on reload it will get restored */ - context.tin.tin = (struct obj *)0; - } -/* if (otmp->oclass == SPBOOK_CLASS) book_disappears(otmp); */ - if (otmp == context.spbook.book) { - /* Store the o_id of your spellbook */ - if (context.spbook.o_id != otmp->o_id) - context.spbook.o_id = otmp->o_id; - /* invalidate the pointer; on reload it will get restored */ - context.spbook.book = (struct obj *)0; - } - otmp->where = OBJ_FREE; /* set to free so dealloc will work */ - otmp->timed = 0; /* not timed any more */ - otmp->lamplit = 0; /* caller handled lights */ - dealloc_obj(otmp); - } - otmp = otmp2; - } - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) &minusone, sizeof(int)); + while (otmp) { + otmp2 = otmp->nobj; + if (perform_bwrite(mode)) { + saveobj(fd, otmp); + } + if (Has_contents(otmp)) + saveobjchn(fd, otmp->cobj, mode); + if (release_data(mode)) { + /* if (otmp->oclass == FOOD_CLASS) food_disappears(otmp); + */ + /* + * If these are on the floor, the discarding could + * be because of a game save, or we could just be changing levels. + * Always invalidate the pointer, but ensure that we have + * the o_id in order to restore the pointer on reload. + */ + if (otmp == context.victual.piece) { + /* Store the o_id of the victual if mismatched */ + if (context.victual.o_id != otmp->o_id) + context.victual.o_id = otmp->o_id; + /* invalidate the pointer; on reload it will get restored */ + context.victual.piece = (struct obj *) 0; + } + if (otmp == context.tin.tin) { + /* Store the o_id of your tin */ + if (context.tin.o_id != otmp->o_id) + context.tin.o_id = otmp->o_id; + /* invalidate the pointer; on reload it will get restored */ + context.tin.tin = (struct obj *) 0; + } + /* if (otmp->oclass == SPBOOK_CLASS) book_disappears(otmp); + */ + if (otmp == context.spbook.book) { + /* Store the o_id of your spellbook */ + if (context.spbook.o_id != otmp->o_id) + context.spbook.o_id = otmp->o_id; + /* invalidate the pointer; on reload it will get restored */ + context.spbook.book = (struct obj *) 0; + } + otmp->where = OBJ_FREE; /* set to free so dealloc will work */ + otmp->timed = 0; /* not timed any more */ + otmp->lamplit = 0; /* caller handled lights */ + dealloc_obj(otmp); + } + otmp = otmp2; + } + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) &minusone, sizeof(int)); } STATIC_OVL void @@ -1046,53 +1064,64 @@ savemon(fd, mtmp) int fd; struct monst *mtmp; { - int buflen; + int buflen; - buflen = sizeof(struct monst); - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - bwrite(fd, (genericptr_t) mtmp, buflen); - if (mtmp->mextra) { - if (MNAME(mtmp)) buflen = strlen(MNAME(mtmp)) + 1; - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof buflen); - if (buflen > 0) - bwrite(fd, (genericptr_t) MNAME(mtmp), buflen); + buflen = sizeof(struct monst); + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + bwrite(fd, (genericptr_t) mtmp, buflen); + if (mtmp->mextra) { + if (MNAME(mtmp)) + buflen = strlen(MNAME(mtmp)) + 1; + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof buflen); + if (buflen > 0) + bwrite(fd, (genericptr_t) MNAME(mtmp), buflen); - if (EGD(mtmp)) buflen = sizeof(struct egd); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - if (buflen > 0) - bwrite(fd, (genericptr_t) EGD(mtmp), buflen); + if (EGD(mtmp)) + buflen = sizeof(struct egd); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + if (buflen > 0) + bwrite(fd, (genericptr_t) EGD(mtmp), buflen); - if (EPRI(mtmp)) buflen = sizeof(struct epri); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - if (buflen > 0) - bwrite(fd, (genericptr_t) EPRI(mtmp), buflen); + if (EPRI(mtmp)) + buflen = sizeof(struct epri); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + if (buflen > 0) + bwrite(fd, (genericptr_t) EPRI(mtmp), buflen); - if (ESHK(mtmp)) buflen = sizeof(struct eshk); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - if (buflen > 0) - bwrite(fd, (genericptr_t) ESHK(mtmp), buflen); + if (ESHK(mtmp)) + buflen = sizeof(struct eshk); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + if (buflen > 0) + bwrite(fd, (genericptr_t) ESHK(mtmp), buflen); - if (EMIN(mtmp)) buflen = sizeof(struct emin); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - if (buflen > 0) - bwrite(fd, (genericptr_t) EMIN(mtmp), buflen); + if (EMIN(mtmp)) + buflen = sizeof(struct emin); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + if (buflen > 0) + bwrite(fd, (genericptr_t) EMIN(mtmp), buflen); - if (EDOG(mtmp)) buflen = sizeof(struct edog); - else buflen = 0; - bwrite(fd, (genericptr_t) &buflen, sizeof(int)); - if (buflen > 0) - bwrite(fd, (genericptr_t) EDOG(mtmp), buflen); + if (EDOG(mtmp)) + buflen = sizeof(struct edog); + else + buflen = 0; + bwrite(fd, (genericptr_t) &buflen, sizeof(int)); + if (buflen > 0) + bwrite(fd, (genericptr_t) EDOG(mtmp), buflen); - /* mcorpsenm is inline int rather than pointer to something, - so doesn't need to be preceded by a length field */ - bwrite(fd, (genericptr_t) &MCORPSENM(mtmp), - sizeof MCORPSENM(mtmp)); - } + /* mcorpsenm is inline int rather than pointer to something, + so doesn't need to be preceded by a length field */ + bwrite(fd, (genericptr_t) &MCORPSENM(mtmp), sizeof MCORPSENM(mtmp)); + } } STATIC_OVL void @@ -1100,29 +1129,30 @@ savemonchn(fd, mtmp, mode) register int fd, mode; register struct monst *mtmp; { - register struct monst *mtmp2; - int minusone = -1; + register struct monst *mtmp2; + int minusone = -1; - while (mtmp) { - mtmp2 = mtmp->nmon; - if (perform_bwrite(mode)) { - mtmp->mnum = monsndx(mtmp->data); - if (mtmp->ispriest) forget_temple_entry(mtmp); /* EPRI() */ - savemon(fd, mtmp); - } - if (mtmp->minvent) - saveobjchn(fd,mtmp->minvent,mode); - if (release_data(mode)) { - if (mtmp == context.polearm.hitmon) { - context.polearm.m_id = mtmp->m_id; - context.polearm.hitmon = NULL; - } - dealloc_monst(mtmp); - } - mtmp = mtmp2; - } - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) &minusone, sizeof(int)); + while (mtmp) { + mtmp2 = mtmp->nmon; + if (perform_bwrite(mode)) { + mtmp->mnum = monsndx(mtmp->data); + if (mtmp->ispriest) + forget_temple_entry(mtmp); /* EPRI() */ + savemon(fd, mtmp); + } + if (mtmp->minvent) + saveobjchn(fd, mtmp->minvent, mode); + if (release_data(mode)) { + if (mtmp == context.polearm.hitmon) { + context.polearm.m_id = mtmp->m_id; + context.polearm.hitmon = NULL; + } + dealloc_monst(mtmp); + } + mtmp = mtmp2; + } + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) &minusone, sizeof(int)); } STATIC_OVL void @@ -1130,18 +1160,18 @@ savetrapchn(fd, trap, mode) register int fd, mode; register struct trap *trap; { - register struct trap *trap2; + register struct trap *trap2; - while (trap) { - trap2 = trap->ntrap; - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t) trap, sizeof(struct trap)); - if (release_data(mode)) - dealloc_trap(trap); - trap = trap2; - } - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t)nulls, sizeof(struct trap)); + while (trap) { + trap2 = trap->ntrap; + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) trap, sizeof(struct trap)); + if (release_data(mode)) + dealloc_trap(trap); + trap = trap2; + } + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) nulls, sizeof(struct trap)); } /* save all the fruit names and ID's; this is used only in saving whole games @@ -1153,203 +1183,210 @@ void savefruitchn(fd, mode) register int fd, mode; { - register struct fruit *f2, *f1; + register struct fruit *f2, *f1; - f1 = ffruit; - while (f1) { - f2 = f1->nextf; - if (f1->fid >= 0 && perform_bwrite(mode)) - bwrite(fd, (genericptr_t) f1, sizeof(struct fruit)); - if (release_data(mode)) - dealloc_fruit(f1); - f1 = f2; - } - if (perform_bwrite(mode)) - bwrite(fd, (genericptr_t)nulls, sizeof(struct fruit)); - if (release_data(mode)) - ffruit = 0; + f1 = ffruit; + while (f1) { + f2 = f1->nextf; + if (f1->fid >= 0 && perform_bwrite(mode)) + bwrite(fd, (genericptr_t) f1, sizeof(struct fruit)); + if (release_data(mode)) + dealloc_fruit(f1); + f1 = f2; + } + if (perform_bwrite(mode)) + bwrite(fd, (genericptr_t) nulls, sizeof(struct fruit)); + if (release_data(mode)) + ffruit = 0; } void store_plname_in_file(fd) int fd; { - int plsiztmp = PL_NSIZ; - bufoff(fd); - /* bwrite() before bufon() uses plain write() */ - bwrite(fd, (genericptr_t) &plsiztmp, sizeof(plsiztmp)); - bwrite(fd, (genericptr_t) plname, plsiztmp); - bufon(fd); - return; + int plsiztmp = PL_NSIZ; + bufoff(fd); + /* bwrite() before bufon() uses plain write() */ + bwrite(fd, (genericptr_t) &plsiztmp, sizeof(plsiztmp)); + bwrite(fd, (genericptr_t) plname, plsiztmp); + bufon(fd); + return; } STATIC_OVL void save_msghistory(fd, mode) int fd, mode; { - char *msg; - int msgcount = 0, msglen; - int minusone = -1; - boolean init = TRUE; + char *msg; + int msgcount = 0, msglen; + int minusone = -1; + boolean init = TRUE; - if (perform_bwrite(mode)) { - /* ask window port for each message in sequence */ - while ((msg = getmsghistory(init)) != 0) { - init = FALSE; - msglen = strlen(msg); - /* sanity: truncate if necessary (shouldn't happen); - no need to modify msg[] since terminator isn't written */ - if (msglen > BUFSZ - 1) msglen = BUFSZ - 1; - bwrite(fd, (genericptr_t)&msglen, sizeof(msglen)); - bwrite(fd, (genericptr_t)msg, msglen); - ++msgcount; - } - bwrite(fd, (genericptr_t) &minusone, sizeof(int)); - } - debugpline1("Stored %d messages into savefile.", msgcount); - /* note: we don't attempt to handle release_data() here */ + if (perform_bwrite(mode)) { + /* ask window port for each message in sequence */ + while ((msg = getmsghistory(init)) != 0) { + init = FALSE; + msglen = strlen(msg); + /* sanity: truncate if necessary (shouldn't happen); + no need to modify msg[] since terminator isn't written */ + if (msglen > BUFSZ - 1) + msglen = BUFSZ - 1; + bwrite(fd, (genericptr_t) &msglen, sizeof(msglen)); + bwrite(fd, (genericptr_t) msg, msglen); + ++msgcount; + } + bwrite(fd, (genericptr_t) &minusone, sizeof(int)); + } + debugpline1("Stored %d messages into savefile.", msgcount); + /* note: we don't attempt to handle release_data() here */ } void store_savefileinfo(fd) int fd; { - /* sfcap (decl.c) describes the savefile feature capabilities - * that are supported by this port/platform build. - * - * sfsaveinfo (decl.c) describes the savefile info that actually - * gets written into the savefile, and is used to determine the - * save file being written. + /* sfcap (decl.c) describes the savefile feature capabilities + * that are supported by this port/platform build. + * + * sfsaveinfo (decl.c) describes the savefile info that actually + * gets written into the savefile, and is used to determine the + * save file being written. - * sfrestinfo (decl.c) describes the savefile info that is - * being used to read the information from an existing savefile. - * - */ + * sfrestinfo (decl.c) describes the savefile info that is + * being used to read the information from an existing savefile. + * + */ - bufoff(fd); - /* bwrite() before bufon() uses plain write() */ - bwrite(fd,(genericptr_t)&sfsaveinfo, (unsigned)(sizeof sfsaveinfo)); - bufon(fd); - return; + bufoff(fd); + /* bwrite() before bufon() uses plain write() */ + bwrite(fd, (genericptr_t) &sfsaveinfo, (unsigned) (sizeof sfsaveinfo)); + bufon(fd); + return; } void set_savepref(suitename) const char *suitename; { - if (!strcmpi(suitename, "externalcomp")) { - saveprocs.name = "externalcomp"; - saveprocs.save_bufon = def_bufon; - saveprocs.save_bufoff = def_bufoff; - saveprocs.save_bflush = def_bflush; - saveprocs.save_bwrite = def_bwrite; - saveprocs.save_bclose = def_bclose; - sfsaveinfo.sfi1 |= SFI1_EXTERNALCOMP; - sfsaveinfo.sfi1 &= ~SFI1_ZEROCOMP; - } - if (!strcmpi(suitename, "!rlecomp")) { - sfsaveinfo.sfi1 &= ~SFI1_RLECOMP; - } + if (!strcmpi(suitename, "externalcomp")) { + saveprocs.name = "externalcomp"; + saveprocs.save_bufon = def_bufon; + saveprocs.save_bufoff = def_bufoff; + saveprocs.save_bflush = def_bflush; + saveprocs.save_bwrite = def_bwrite; + saveprocs.save_bclose = def_bclose; + sfsaveinfo.sfi1 |= SFI1_EXTERNALCOMP; + sfsaveinfo.sfi1 &= ~SFI1_ZEROCOMP; + } + if (!strcmpi(suitename, "!rlecomp")) { + sfsaveinfo.sfi1 &= ~SFI1_RLECOMP; + } #ifdef ZEROCOMP - if (!strcmpi(suitename, "zerocomp")) { - saveprocs.name = "zerocomp"; - saveprocs.save_bufon = zerocomp_bufon; - saveprocs.save_bufoff = zerocomp_bufoff; - saveprocs.save_bflush = zerocomp_bflush; - saveprocs.save_bwrite = zerocomp_bwrite; - saveprocs.save_bclose = zerocomp_bclose; - sfsaveinfo.sfi1 |= SFI1_ZEROCOMP; - sfsaveinfo.sfi1 &= ~SFI1_EXTERNALCOMP; - } + if (!strcmpi(suitename, "zerocomp")) { + saveprocs.name = "zerocomp"; + saveprocs.save_bufon = zerocomp_bufon; + saveprocs.save_bufoff = zerocomp_bufoff; + saveprocs.save_bflush = zerocomp_bflush; + saveprocs.save_bwrite = zerocomp_bwrite; + saveprocs.save_bclose = zerocomp_bclose; + sfsaveinfo.sfi1 |= SFI1_ZEROCOMP; + sfsaveinfo.sfi1 &= ~SFI1_EXTERNALCOMP; + } #endif #ifdef RLECOMP - if (!strcmpi(suitename, "rlecomp")) { - sfsaveinfo.sfi1 |= SFI1_RLECOMP; - } + if (!strcmpi(suitename, "rlecomp")) { + sfsaveinfo.sfi1 |= SFI1_RLECOMP; + } #endif } - + /* also called by prscore(); this probably belongs in dungeon.c... */ void free_dungeons() { #ifdef FREE_ALL_MEMORY - savelevchn(0, FREE_SAVE); - save_dungeon(0, FALSE, TRUE); + savelevchn(0, FREE_SAVE); + save_dungeon(0, FALSE, TRUE); #endif - return; + return; } void freedynamicdata() { - unload_qtlist(); - free_menu_coloring(); - free_invbuf(); /* let_to_name (invent.c) */ - free_youbuf(); /* You_buf,&c (pline.c) */ - tmp_at(DISP_FREEMEM, 0); /* temporary display effects */ + unload_qtlist(); + free_menu_coloring(); + free_invbuf(); /* let_to_name (invent.c) */ + free_youbuf(); /* You_buf,&c (pline.c) */ + tmp_at(DISP_FREEMEM, 0); /* temporary display effects */ #ifdef FREE_ALL_MEMORY -# define freeobjchn(X) (saveobjchn(0, X, FREE_SAVE), X = 0) -# define freemonchn(X) (savemonchn(0, X, FREE_SAVE), X = 0) -# define freetrapchn(X) (savetrapchn(0, X, FREE_SAVE), X = 0) -# define freefruitchn() savefruitchn(0, FREE_SAVE) -# define freenames() savenames(0, FREE_SAVE) -# define free_killers() save_killers(0, FREE_SAVE) -# define free_oracles() save_oracles(0, FREE_SAVE) -# define free_waterlevel() save_waterlevel(0, FREE_SAVE) -# define free_worm() save_worm(0, FREE_SAVE) -# define free_timers(R) save_timers(0, FREE_SAVE, R) -# define free_light_sources(R) save_light_sources(0, FREE_SAVE, R); -# define free_engravings() save_engravings(0, FREE_SAVE) -# define freedamage() savedamage(0, FREE_SAVE) -# define free_animals() mon_animal_list(FALSE) +#define freeobjchn(X) (saveobjchn(0, X, FREE_SAVE), X = 0) +#define freemonchn(X) (savemonchn(0, X, FREE_SAVE), X = 0) +#define freetrapchn(X) (savetrapchn(0, X, FREE_SAVE), X = 0) +#define freefruitchn() savefruitchn(0, FREE_SAVE) +#define freenames() savenames(0, FREE_SAVE) +#define free_killers() save_killers(0, FREE_SAVE) +#define free_oracles() save_oracles(0, FREE_SAVE) +#define free_waterlevel() save_waterlevel(0, FREE_SAVE) +#define free_worm() save_worm(0, FREE_SAVE) +#define free_timers(R) save_timers(0, FREE_SAVE, R) +#define free_light_sources(R) save_light_sources(0, FREE_SAVE, R); +#define free_engravings() save_engravings(0, FREE_SAVE) +#define freedamage() savedamage(0, FREE_SAVE) +#define free_animals() mon_animal_list(FALSE) - /* move-specific data */ - dmonsfree(); /* release dead monsters */ + /* move-specific data */ + dmonsfree(); /* release dead monsters */ - /* level-specific data */ - free_timers(RANGE_LEVEL); - free_light_sources(RANGE_LEVEL); + /* level-specific data */ + free_timers(RANGE_LEVEL); + free_light_sources(RANGE_LEVEL); clear_regions(); - freemonchn(fmon); - free_worm(); /* release worm segment information */ - freetrapchn(ftrap); - freeobjchn(fobj); - freeobjchn(level.buriedobjlist); - freeobjchn(billobjs); - free_engravings(); - freedamage(); + freemonchn(fmon); + free_worm(); /* release worm segment information */ + freetrapchn(ftrap); + freeobjchn(fobj); + freeobjchn(level.buriedobjlist); + freeobjchn(billobjs); + free_engravings(); + freedamage(); - /* game-state data */ - free_killers(); - free_timers(RANGE_GLOBAL); - free_light_sources(RANGE_GLOBAL); - freeobjchn(invent); - freeobjchn(migrating_objs); - freemonchn(migrating_mons); - freemonchn(mydogs); /* ascension or dungeon escape */ - /* freelevchn(); [folded into free_dungeons()] */ - free_animals(); - free_oracles(); - freefruitchn(); - freenames(); - free_waterlevel(); - free_dungeons(); + /* game-state data */ + free_killers(); + free_timers(RANGE_GLOBAL); + free_light_sources(RANGE_GLOBAL); + freeobjchn(invent); + freeobjchn(migrating_objs); + freemonchn(migrating_mons); + freemonchn(mydogs); /* ascension or dungeon escape */ + /* freelevchn(); [folded into free_dungeons()] */ + free_animals(); + free_oracles(); + freefruitchn(); + freenames(); + free_waterlevel(); + free_dungeons(); - /* some pointers in iflags */ - if (iflags.wc_font_map) free(iflags.wc_font_map); - if (iflags.wc_font_message) free(iflags.wc_font_message); - if (iflags.wc_font_text) free(iflags.wc_font_text); - if (iflags.wc_font_menu) free(iflags.wc_font_menu); - if (iflags.wc_font_status) free(iflags.wc_font_status); - if (iflags.wc_tile_file) free(iflags.wc_tile_file); - free_autopickup_exceptions(); -#endif /* FREE_ALL_MEMORY */ + /* some pointers in iflags */ + if (iflags.wc_font_map) + free(iflags.wc_font_map); + if (iflags.wc_font_message) + free(iflags.wc_font_message); + if (iflags.wc_font_text) + free(iflags.wc_font_text); + if (iflags.wc_font_menu) + free(iflags.wc_font_menu); + if (iflags.wc_font_status) + free(iflags.wc_font_status); + if (iflags.wc_tile_file) + free(iflags.wc_tile_file); + free_autopickup_exceptions(); +#endif /* FREE_ALL_MEMORY */ #ifdef STATUS_VIA_WINDOWPORT - status_finish(); + status_finish(); #endif - sysopt_release(); /* SYSCF strings */ - return; + sysopt_release(); /* SYSCF strings */ + return; } #ifdef MFLOPPY @@ -1357,87 +1394,88 @@ boolean swapin_file(lev) int lev; { - char to[PATHLEN], from[PATHLEN]; + char to[PATHLEN], from[PATHLEN]; - Sprintf(from, "%s%s", permbones, alllevels); - Sprintf(to, "%s%s", levels, alllevels); - set_levelfile_name(from, lev); - set_levelfile_name(to, lev); - if (iflags.checkspace) { - while (level_info[lev].size > freediskspace(to)) - if (!swapout_oldest()) - return FALSE; - } - if (wizard) { - pline("Swapping in `%s'.", from); - wait_synch(); - } - copyfile(from, to); - (void) unlink(from); - level_info[lev].where = ACTIVE; - return TRUE; + Sprintf(from, "%s%s", permbones, alllevels); + Sprintf(to, "%s%s", levels, alllevels); + set_levelfile_name(from, lev); + set_levelfile_name(to, lev); + if (iflags.checkspace) { + while (level_info[lev].size > freediskspace(to)) + if (!swapout_oldest()) + return FALSE; + } + if (wizard) { + pline("Swapping in `%s'.", from); + wait_synch(); + } + copyfile(from, to); + (void) unlink(from); + level_info[lev].where = ACTIVE; + return TRUE; } STATIC_OVL boolean -swapout_oldest() { - char to[PATHLEN], from[PATHLEN]; - int i, oldest; - long oldtime; +swapout_oldest() +{ + char to[PATHLEN], from[PATHLEN]; + int i, oldest; + long oldtime; - if (!ramdisk) - return FALSE; - for (i = 1, oldtime = 0, oldest = 0; i <= maxledgerno(); i++) - if (level_info[i].where == ACTIVE - && (!oldtime || level_info[i].time < oldtime)) { - oldest = i; - oldtime = level_info[i].time; - } - if (!oldest) - return FALSE; - Sprintf(from, "%s%s", levels, alllevels); - Sprintf(to, "%s%s", permbones, alllevels); - set_levelfile_name(from, oldest); - set_levelfile_name(to, oldest); - if (wizard) { - pline("Swapping out `%s'.", from); - wait_synch(); - } - copyfile(from, to); - (void) unlink(from); - level_info[oldest].where = SWAPPED; - return TRUE; + if (!ramdisk) + return FALSE; + for (i = 1, oldtime = 0, oldest = 0; i <= maxledgerno(); i++) + if (level_info[i].where == ACTIVE + && (!oldtime || level_info[i].time < oldtime)) { + oldest = i; + oldtime = level_info[i].time; + } + if (!oldest) + return FALSE; + Sprintf(from, "%s%s", levels, alllevels); + Sprintf(to, "%s%s", permbones, alllevels); + set_levelfile_name(from, oldest); + set_levelfile_name(to, oldest); + if (wizard) { + pline("Swapping out `%s'.", from); + wait_synch(); + } + copyfile(from, to); + (void) unlink(from); + level_info[oldest].where = SWAPPED; + return TRUE; } STATIC_OVL void copyfile(from, to) char *from, *to; { -# ifdef TOS +#ifdef TOS - if (_copyfile(from, to)) - panic("Can't copy %s to %s", from, to); -# else - char buf[BUFSIZ]; /* this is system interaction, therefore - * BUFSIZ instead of NetHack's BUFSZ */ - int nfrom, nto, fdfrom, fdto; + if (_copyfile(from, to)) + panic("Can't copy %s to %s", from, to); +#else + char buf[BUFSIZ]; /* this is system interaction, therefore + * BUFSIZ instead of NetHack's BUFSZ */ + int nfrom, nto, fdfrom, fdto; - if ((fdfrom = open(from, O_RDONLY | O_BINARY, FCMASK)) < 0) - panic("Can't copy from %s !?", from); - if ((fdto = open(to, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK)) < 0) - panic("Can't copy to %s", to); - do { - nfrom = read(fdfrom, buf, BUFSIZ); - nto = write(fdto, buf, nfrom); - if (nto != nfrom) - panic("Copyfile failed!"); - } while (nfrom == BUFSIZ); - (void) nhclose(fdfrom); - (void) nhclose(fdto); -# endif /* TOS */ + if ((fdfrom = open(from, O_RDONLY | O_BINARY, FCMASK)) < 0) + panic("Can't copy from %s !?", from); + if ((fdto = open(to, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK)) + < 0) + panic("Can't copy to %s", to); + do { + nfrom = read(fdfrom, buf, BUFSIZ); + nto = write(fdto, buf, nfrom); + if (nto != nfrom) + panic("Copyfile failed!"); + } while (nfrom == BUFSIZ); + (void) nhclose(fdfrom); + (void) nhclose(fdto); +#endif /* TOS */ } -void -co_false() /* see comment in bones.c */ +void co_false() /* see comment in bones.c */ { count_only = FALSE; return; diff --git a/src/shk.c b/src/shk.c index 825788250..7d038bec9 100644 --- a/src/shk.c +++ b/src/shk.c @@ -1,30 +1,31 @@ -/* NetHack 3.6 shk.c $NHDT-Date: 1426465441 2015/03/16 00:24:01 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.96 $ */ +/* NetHack 3.6 shk.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.108 $ */ /* NetHack 3.6 shk.c $Date: 2012/07/03 22:54:49 $ $Revision: 1.91 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -#define PAY_SOME 2 -#define PAY_BUY 1 -#define PAY_CANT 0 /* too poor */ -#define PAY_SKIP (-1) +#define PAY_SOME 2 +#define PAY_BUY 1 +#define PAY_CANT 0 /* too poor */ +#define PAY_SKIP (-1) #define PAY_BROKE (-2) STATIC_DCL void FDECL(makekops, (coord *)); -STATIC_DCL void FDECL(call_kops, (struct monst *,BOOLEAN_P)); +STATIC_DCL void FDECL(call_kops, (struct monst *, BOOLEAN_P)); STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P)); -#define NOTANGRY(mon) ((mon)->mpeaceful) -#define ANGRY(mon) (!NOTANGRY(mon)) -#define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE) +#define NOTANGRY(mon) ((mon)->mpeaceful) +#define ANGRY(mon) (!NOTANGRY(mon)) +#define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE) -#define muteshk(shkp) ((shkp)->msleeping || !(shkp)->mcanmove || \ - (shkp)->data->msound <= MS_ANIMAL) +#define muteshk(shkp) \ + ((shkp)->msleeping || !(shkp)->mcanmove \ + || (shkp)->data->msound <= MS_ANIMAL) -extern const struct shclass shtypes[]; /* defined in shknam.c */ +extern const struct shclass shtypes[]; /* defined in shknam.c */ -STATIC_VAR NEARDATA long int followmsg; /* last time of follow message */ +STATIC_VAR NEARDATA long int followmsg; /* last time of follow message */ STATIC_VAR const char and_its_contents[] = " and its contents"; STATIC_VAR const char the_contents_of[] = "the contents of "; @@ -32,51 +33,54 @@ STATIC_DCL void FDECL(append_honorific, (char *)); STATIC_DCL void FDECL(setpaid, (struct monst *)); STATIC_DCL long FDECL(addupbill, (struct monst *)); STATIC_DCL void FDECL(pacify_shk, (struct monst *)); -STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *, BOOLEAN_P)); +STATIC_DCL struct bill_x *FDECL(onbill, + (struct obj *, struct monst *, BOOLEAN_P)); STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P)); STATIC_DCL long FDECL(shop_debt, (struct eshk *)); -STATIC_DCL char *FDECL(shk_owns, (char *,struct obj *)); -STATIC_DCL char *FDECL(mon_owns, (char *,struct obj *)); -STATIC_DCL void FDECL(clear_unpaid,(struct obj *)); +STATIC_DCL char *FDECL(shk_owns, (char *, struct obj *)); +STATIC_DCL char *FDECL(mon_owns, (char *, struct obj *)); +STATIC_DCL void FDECL(clear_unpaid, (struct obj *)); STATIC_DCL long FDECL(check_credit, (long, struct monst *)); STATIC_DCL void FDECL(pay, (long, struct monst *)); STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *)); STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *)); STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long)); -STATIC_DCL long FDECL(cost_per_charge, (struct monst *,struct obj *,BOOLEAN_P)); +STATIC_DCL long FDECL(cost_per_charge, + (struct monst *, struct obj *, BOOLEAN_P)); STATIC_DCL long FDECL(cheapest_item, (struct monst *)); STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *, - struct obj **, int, BOOLEAN_P)); -STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *, long, - BOOLEAN_P)); -STATIC_DCL long FDECL(getprice, (struct obj *,BOOLEAN_P)); -STATIC_DCL void FDECL(shk_names_obj, - (struct monst *,struct obj *,const char *,long,const char *)); + struct obj **, int, BOOLEAN_P)); +STATIC_DCL long FDECL(stolen_container, + (struct obj *, struct monst *, long, BOOLEAN_P)); +STATIC_DCL long FDECL(getprice, (struct obj *, BOOLEAN_P)); +STATIC_DCL void FDECL(shk_names_obj, (struct monst *, struct obj *, + const char *, long, const char *)); STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *)); -STATIC_DCL boolean FDECL(inherits, (struct monst *,int,int)); +STATIC_DCL boolean FDECL(inherits, (struct monst *, int, int)); STATIC_DCL void FDECL(set_repo_loc, (struct monst *)); STATIC_DCL boolean NDECL(angry_shk_exists); STATIC_DCL void FDECL(rile_shk, (struct monst *)); -STATIC_DCL void FDECL(rouse_shk, (struct monst *,BOOLEAN_P)); +STATIC_DCL void FDECL(rouse_shk, (struct monst *, BOOLEAN_P)); STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P)); STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *)); -STATIC_DCL void FDECL(add_one_tobill, (struct obj *,BOOLEAN_P,struct monst *)); -STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *, - BOOLEAN_P)); +STATIC_DCL void FDECL(add_one_tobill, + (struct obj *, BOOLEAN_P, struct monst *)); +STATIC_DCL void FDECL(dropped_container, + (struct obj *, struct monst *, BOOLEAN_P)); STATIC_DCL void FDECL(add_to_billobjs, (struct obj *)); -STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P, - struct monst *)); +STATIC_DCL void FDECL(bill_box_content, + (struct obj *, BOOLEAN_P, BOOLEAN_P, struct monst *)); STATIC_DCL boolean FDECL(rob_shop, (struct monst *)); STATIC_DCL void FDECL(deserted_shop, (char *)); -STATIC_DCL boolean FDECL(special_stock, (struct obj *, struct monst *, BOOLEAN_P)); +STATIC_DCL boolean +FDECL(special_stock, (struct obj *, struct monst *, BOOLEAN_P)); STATIC_DCL const char *FDECL(cad, (BOOLEAN_P)); /* - invariants: obj->unpaid iff onbill(obj) [unless bp->useup] - obj->quan <= bp->bquan + invariants: obj->unpaid iff onbill(obj) [unless bp->useup] + obj->quan <= bp->bquan */ - /* Transfer money from inventory to monster when paying shopkeepers, priests, oracle, succubus, & other demons. @@ -98,25 +102,24 @@ long amount; struct obj *ygold = findgold(invent); if (amount <= 0) { - impossible("%s payment in money2mon!", amount ? "negative" : "zero"); - return 0L; + impossible("%s payment in money2mon!", amount ? "negative" : "zero"); + return 0L; } if (!ygold || ygold->quan < amount) { - impossible("Paying without %s money?", ygold ? "enough" : ""); - return 0L; + impossible("Paying without %s money?", ygold ? "enough" : ""); + return 0L; } if (ygold->quan > amount) - ygold = splitobj(ygold, amount); + ygold = splitobj(ygold, amount); else if (ygold->owornmask) - remove_worn_item(ygold, FALSE); /* quiver */ + remove_worn_item(ygold, FALSE); /* quiver */ freeinv(ygold); add_to_minv(mon, ygold); context.botl = 1; return amount; } - /* Transfer money from monster to inventory. Used when the shopkeeper pay for items, and when @@ -130,24 +133,25 @@ long amount; struct obj *mongold = findgold(mon->minvent); if (amount <= 0) { - impossible("%s payment in money2u!", amount ? "negative" : "zero"); - return; + impossible("%s payment in money2u!", amount ? "negative" : "zero"); + return; } if (!mongold || mongold->quan < amount) { - impossible("%s paying without %s money?", a_monnam(mon), - mongold ? "enough" : ""); - return; + impossible("%s paying without %s money?", a_monnam(mon), + mongold ? "enough" : ""); + return; } - if (mongold->quan > amount) mongold = splitobj(mongold, amount); + if (mongold->quan > amount) + mongold = splitobj(mongold, amount); obj_extract_self(mongold); if (!merge_choice(invent, mongold) && inv_cnt(FALSE) >= 52) { - You("have no room for the money!"); - dropy(mongold); + You("have no room for the money!"); + dropy(mongold); } else { - addinv(mongold); - context.botl = 1; + addinv(mongold); + context.botl = 1; } } @@ -156,54 +160,60 @@ next_shkp(shkp, withbill) register struct monst *shkp; register boolean withbill; { - for (; shkp; shkp = shkp->nmon) { - if (DEADMONSTER(shkp)) continue; - if (shkp->isshk && (ESHK(shkp)->billct || !withbill)) break; - } + for (; shkp; shkp = shkp->nmon) { + if (DEADMONSTER(shkp)) + continue; + if (shkp->isshk && (ESHK(shkp)->billct || !withbill)) + break; + } - if (shkp) { - if (NOTANGRY(shkp)) { - if (ESHK(shkp)->surcharge) pacify_shk(shkp); - } else { - if (!ESHK(shkp)->surcharge) rile_shk(shkp); - } - } - return(shkp); + if (shkp) { + if (NOTANGRY(shkp)) { + if (ESHK(shkp)->surcharge) + pacify_shk(shkp); + } else { + if (!ESHK(shkp)->surcharge) + rile_shk(shkp); + } + } + return (shkp); } -void -shkgone(mtmp) /* called in mon.c */ +void shkgone(mtmp) /* called in mon.c */ struct monst *mtmp; { - struct eshk *eshk = ESHK(mtmp); - struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET]; - struct obj *otmp; - char *p; - int sx, sy; + struct eshk *eshk = ESHK(mtmp); + struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET]; + struct obj *otmp; + char *p; + int sx, sy; - /* [BUG: some of this should be done on the shop level */ - /* even when the shk dies on a different level.] */ - if (on_level(&eshk->shoplevel, &u.uz)) { - remove_damage(mtmp, TRUE); - sroom->resident = (struct monst *)0; - if (!search_special(ANY_SHOP)) - level.flags.has_shop = 0; + /* [BUG: some of this should be done on the shop level */ + /* even when the shk dies on a different level.] */ + if (on_level(&eshk->shoplevel, &u.uz)) { + remove_damage(mtmp, TRUE); + sroom->resident = (struct monst *) 0; + if (!search_special(ANY_SHOP)) + level.flags.has_shop = 0; - /* items on shop floor revert to ordinary objects */ - for (sx = sroom->lx; sx <= sroom->hx; sx++) - for (sy = sroom->ly; sy <= sroom->hy; sy++) - for (otmp = level.objects[sx][sy]; otmp; otmp = otmp->nexthere) - otmp->no_charge = 0; + /* items on shop floor revert to ordinary objects */ + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) + for (otmp = level.objects[sx][sy]; otmp; + otmp = otmp->nexthere) + otmp->no_charge = 0; - /* Make sure bill is set only when the - dead shk is the resident shk. */ - if ((p = index(u.ushops, eshk->shoproom)) != 0) { - setpaid(mtmp); - eshk->bill_p = (struct bill_x *)0; - /* remove eshk->shoproom from u.ushops */ - do { *p = *(p + 1); } while (*++p); - } - } + /* Make sure bill is set only when the + dead shk is the resident shk. */ + if ((p = index(u.ushops, eshk->shoproom)) != 0) { + setpaid(mtmp); + eshk->bill_p = (struct bill_x *) 0; + /* remove eshk->shoproom from u.ushops */ + do { + *p = *(p + 1); + } while (*++p); + } + } } void @@ -211,19 +221,19 @@ set_residency(shkp, zero_out) register struct monst *shkp; register boolean zero_out; { - if (on_level(&(ESHK(shkp)->shoplevel), &u.uz)) - rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident = - (zero_out)? (struct monst *)0 : shkp; + if (on_level(&(ESHK(shkp)->shoplevel), &u.uz)) + rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident = + (zero_out) ? (struct monst *) 0 : shkp; } void -replshk(mtmp,mtmp2) +replshk(mtmp, mtmp2) register struct monst *mtmp, *mtmp2; { - rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2; - if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) { - ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]); - } + rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2; + if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) { + ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]); + } } /* do shopkeeper specific structure munging -dlc */ @@ -233,17 +243,17 @@ struct monst *shkp; boolean ghostly; { if (u.uz.dlevel) { - struct eshk *eshkp = ESHK(shkp); + struct eshk *eshkp = ESHK(shkp); - if (eshkp->bill_p != (struct bill_x *) -1000) - eshkp->bill_p = &eshkp->bill[0]; - /* shoplevel can change as dungeons move around */ - /* savebones guarantees that non-homed shk's will be gone */ - if (ghostly) { - assign_level(&eshkp->shoplevel, &u.uz); - if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ)) - pacify_shk(shkp); - } + if (eshkp->bill_p != (struct bill_x *) -1000) + eshkp->bill_p = &eshkp->bill[0]; + /* shoplevel can change as dungeons move around */ + /* savebones guarantees that non-homed shk's will be gone */ + if (ghostly) { + assign_level(&eshkp->shoplevel, &u.uz); + if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ)) + pacify_shk(shkp); + } } } @@ -253,9 +263,10 @@ clear_unpaid(list) register struct obj *list; { while (list) { - if (Has_contents(list)) clear_unpaid(list->cobj); - list->unpaid = 0; - list = list->nobj; + if (Has_contents(list)) + clear_unpaid(list->cobj); + list->unpaid = 0; + list = list->nobj; } } @@ -264,47 +275,49 @@ STATIC_OVL void setpaid(shkp) register struct monst *shkp; { - register struct obj *obj; - register struct monst *mtmp; + register struct obj *obj; + register struct monst *mtmp; - /* FIXME: object handling should be limited to - items which are on this particular shk's bill */ + /* FIXME: object handling should be limited to + items which are on this particular shk's bill */ - clear_unpaid(invent); - clear_unpaid(fobj); - clear_unpaid(level.buriedobjlist); - if (thrownobj) thrownobj->unpaid = 0; - if (kickedobj) kickedobj->unpaid = 0; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - clear_unpaid(mtmp->minvent); - for(mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) - clear_unpaid(mtmp->minvent); + clear_unpaid(invent); + clear_unpaid(fobj); + clear_unpaid(level.buriedobjlist); + if (thrownobj) + thrownobj->unpaid = 0; + if (kickedobj) + kickedobj->unpaid = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + clear_unpaid(mtmp->minvent); + for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) + clear_unpaid(mtmp->minvent); - while ((obj = billobjs) != 0) { - obj_extract_self(obj); - dealloc_obj(obj); - } - if(shkp) { - ESHK(shkp)->billct = 0; - ESHK(shkp)->credit = 0L; - ESHK(shkp)->debit = 0L; - ESHK(shkp)->loan = 0L; - } + while ((obj = billobjs) != 0) { + obj_extract_self(obj); + dealloc_obj(obj); + } + if (shkp) { + ESHK(shkp)->billct = 0; + ESHK(shkp)->credit = 0L; + ESHK(shkp)->debit = 0L; + ESHK(shkp)->loan = 0L; + } } STATIC_OVL long addupbill(shkp) register struct monst *shkp; { - register int ct = ESHK(shkp)->billct; - register struct bill_x *bp = ESHK(shkp)->bill_p; - register long total = 0L; + register int ct = ESHK(shkp)->billct; + register struct bill_x *bp = ESHK(shkp)->bill_p; + register long total = 0L; - while(ct--){ - total += bp->price * bp->bquan; - bp++; - } - return(total); + while (ct--) { + total += bp->price * bp->bquan; + bp++; + } + return (total); } STATIC_OVL void @@ -312,50 +325,52 @@ call_kops(shkp, nearshop) register struct monst *shkp; register boolean nearshop; { - /* Keystone Kops srt@ucla */ - register boolean nokops; + /* Keystone Kops srt@ucla */ + register boolean nokops; - if(!shkp) return; + if (!shkp) + return; - if (!Deaf) - pline("An alarm sounds!"); + if (!Deaf) + pline("An alarm sounds!"); - nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE) && - (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE) && - (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE) && - (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE)); + nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE) + && (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE) + && (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE) + && (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE)); - if(!angry_guards(!!Deaf) && nokops) { - if(flags.verbose && !Deaf) - pline("But no one seems to respond to it."); - return; - } + if (!angry_guards(!!Deaf) && nokops) { + if (flags.verbose && !Deaf) + pline("But no one seems to respond to it."); + return; + } - if(nokops) return; + if (nokops) + return; - { - coord mm; + { + coord mm; - if (nearshop) { - /* Create swarm around you, if you merely "stepped out" */ - if (flags.verbose) - pline_The("Keystone Kops appear!"); - mm.x = u.ux; - mm.y = u.uy; - makekops(&mm); - return; - } - if (flags.verbose) - pline_The("Keystone Kops are after you!"); - /* Create swarm near down staircase (hinders return to level) */ - mm.x = xdnstair; - mm.y = ydnstair; - makekops(&mm); - /* Create swarm near shopkeeper (hinders return to shop) */ - mm.x = shkp->mx; - mm.y = shkp->my; - makekops(&mm); - } + if (nearshop) { + /* Create swarm around you, if you merely "stepped out" */ + if (flags.verbose) + pline_The("Keystone Kops appear!"); + mm.x = u.ux; + mm.y = u.uy; + makekops(&mm); + return; + } + if (flags.verbose) + pline_The("Keystone Kops are after you!"); + /* Create swarm near down staircase (hinders return to level) */ + mm.x = xdnstair; + mm.y = ydnstair; + makekops(&mm); + /* Create swarm near shopkeeper (hinders return to shop) */ + mm.x = shkp->mx; + mm.y = shkp->my; + makekops(&mm); + } } /* x,y is strictly inside shop */ @@ -363,13 +378,13 @@ char inside_shop(x, y) register xchar x, y; { - register char rno; + register char rno; - rno = levl[x][y].roomno; - if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno-ROOMOFFSET)) - return(NO_ROOM); - else - return(rno); + rno = levl[x][y].roomno; + if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno - ROOMOFFSET)) + return (NO_ROOM); + else + return (rno); } void @@ -377,43 +392,41 @@ u_left_shop(leavestring, newlev) char *leavestring; boolean newlev; { - struct monst *shkp; - struct eshk *eshkp; + struct monst *shkp; + struct eshk *eshkp; - /* - * IF player - * ((didn't leave outright) AND - * ((he is now strictly-inside the shop) OR - * (he wasn't strictly-inside last turn anyway))) - * THEN (there's nothing to do, so just return) - */ - if(!*leavestring && - (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge)) - return; + /* + * IF player + * ((didn't leave outright) AND + * ((he is now strictly-inside the shop) OR + * (he wasn't strictly-inside last turn anyway))) + * THEN (there's nothing to do, so just return) + */ + if (!*leavestring && (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge)) + return; - shkp = shop_keeper(*u.ushops0); - if (!shkp || !inhishop(shkp)) - return; /* shk died, teleported, changed levels... */ + shkp = shop_keeper(*u.ushops0); + if (!shkp || !inhishop(shkp)) + return; /* shk died, teleported, changed levels... */ - eshkp = ESHK(shkp); - if (!eshkp->billct && !eshkp->debit) /* bill is settled */ - return; + eshkp = ESHK(shkp); + if (!eshkp->billct && !eshkp->debit) /* bill is settled */ + return; - if (!*leavestring && !muteshk(shkp)) { - /* - * Player just stepped onto shop-boundary (known from above logic). - * Try to intimidate him into paying his bill - */ - verbalize(NOTANGRY(shkp) ? - "%s! Please pay before leaving." : - "%s! Don't you leave without paying!", - plname); - return; - } + if (!*leavestring && !muteshk(shkp)) { + /* + * Player just stepped onto shop-boundary (known from above logic). + * Try to intimidate him into paying his bill + */ + verbalize(NOTANGRY(shkp) ? "%s! Please pay before leaving." + : "%s! Don't you leave without paying!", + plname); + return; + } - if (rob_shop(shkp)) { - call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge)); - } + if (rob_shop(shkp)) { + call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge)); + } } /* robbery from outside the shop via telekinesis or grappling hook */ @@ -421,55 +434,55 @@ void remote_burglary(x, y) xchar x, y; { - struct monst *shkp; - struct eshk *eshkp; + struct monst *shkp; + struct eshk *eshkp; - shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); - if (!shkp || !inhishop(shkp)) - return; /* shk died, teleported, changed levels... */ + shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); + if (!shkp || !inhishop(shkp)) + return; /* shk died, teleported, changed levels... */ - eshkp = ESHK(shkp); - if (!eshkp->billct && !eshkp->debit) /* bill is settled */ - return; + eshkp = ESHK(shkp); + if (!eshkp->billct && !eshkp->debit) /* bill is settled */ + return; - if (rob_shop(shkp)) { - /*[might want to set 2nd arg based on distance from shop doorway]*/ - call_kops(shkp, FALSE); - } + if (rob_shop(shkp)) { + /*[might want to set 2nd arg based on distance from shop doorway]*/ + call_kops(shkp, FALSE); + } } -/* shop merchandise has been taken; pay for it with any credit available; +/* shop merchandise has been taken; pay for it with any credit available; return false if the debt is fully covered by credit, true otherwise */ STATIC_OVL boolean rob_shop(shkp) struct monst *shkp; { - struct eshk *eshkp; - long total; + struct eshk *eshkp; + long total; - eshkp = ESHK(shkp); - rouse_shk(shkp, TRUE); - total = (addupbill(shkp) + eshkp->debit); - if (eshkp->credit >= total) { - Your("credit of %ld %s is used to cover your shopping bill.", - eshkp->credit, currency(eshkp->credit)); - total = 0L; /* credit gets cleared by setpaid() */ - } else { - You("escaped the shop without paying!"); - total -= eshkp->credit; - } - setpaid(shkp); - if (!total) return FALSE; + eshkp = ESHK(shkp); + rouse_shk(shkp, TRUE); + total = (addupbill(shkp) + eshkp->debit); + if (eshkp->credit >= total) { + Your("credit of %ld %s is used to cover your shopping bill.", + eshkp->credit, currency(eshkp->credit)); + total = 0L; /* credit gets cleared by setpaid() */ + } else { + You("escaped the shop without paying!"); + total -= eshkp->credit; + } + setpaid(shkp); + if (!total) + return FALSE; - /* by this point, we know an actual robbery has taken place */ - eshkp->robbed += total; - You("stole %ld %s worth of merchandise.", - total, currency(total)); - if (!Role_if(PM_ROGUE)) /* stealing is unlawful */ - adjalign(-sgn(u.ualign.type)); + /* by this point, we know an actual robbery has taken place */ + eshkp->robbed += total; + You("stole %ld %s worth of merchandise.", total, currency(total)); + if (!Role_if(PM_ROGUE)) /* stealing is unlawful */ + adjalign(-sgn(u.ualign.type)); - hot_pursuit(shkp); - return TRUE; + hot_pursuit(shkp); + return TRUE; } /* give a message when entering an untended shop (caller has verified that) */ @@ -482,139 +495,138 @@ deserted_shop(enterstring) int x, y, m = 0, n = 0; for (x = r->lx; x <= r->hx; ++x) - for (y = r->ly; y <= r->hy; ++y) { - if (x == u.ux && y == u.uy) continue; - if ((mtmp = m_at(x, y)) != 0) { - ++n; - if (sensemon(mtmp) || - ((mtmp->m_ap_type == M_AP_NOTHING || - mtmp->m_ap_type == M_AP_MONSTER) && - canseemon(mtmp))) - ++m; - } - } + for (y = r->ly; y <= r->hy; ++y) { + if (x == u.ux && y == u.uy) + continue; + if ((mtmp = m_at(x, y)) != 0) { + ++n; + if (sensemon(mtmp) || ((mtmp->m_ap_type == M_AP_NOTHING + || mtmp->m_ap_type == M_AP_MONSTER) + && canseemon(mtmp))) + ++m; + } + } if (Blind && !(Blind_telepat || Detect_monsters)) - ++n; /* force feedback to be less specific */ + ++n; /* force feedback to be less specific */ - pline("This shop %s %s.", - (m < n) ? "seems to be" : "is", - !n ? "deserted" : "untended"); + pline("This shop %s %s.", (m < n) ? "seems to be" : "is", + !n ? "deserted" : "untended"); } void u_entered_shop(enterstring) char *enterstring; { + register int rt; + register struct monst *shkp; + register struct eshk *eshkp; + static char empty_shops[5]; - register int rt; - register struct monst *shkp; - register struct eshk *eshkp; - static char empty_shops[5]; + if (!*enterstring) + return; - if(!*enterstring) - return; + if (!(shkp = shop_keeper(*enterstring))) { + if (!index(empty_shops, *enterstring) + && in_rooms(u.ux, u.uy, SHOPBASE) + != in_rooms(u.ux0, u.uy0, SHOPBASE)) + deserted_shop(enterstring); + Strcpy(empty_shops, u.ushops); + u.ushops[0] = '\0'; + return; + } - if(!(shkp = shop_keeper(*enterstring))) { - if (!index(empty_shops, *enterstring) && - in_rooms(u.ux, u.uy, SHOPBASE) != - in_rooms(u.ux0, u.uy0, SHOPBASE)) - deserted_shop(enterstring); - Strcpy(empty_shops, u.ushops); - u.ushops[0] = '\0'; - return; - } + eshkp = ESHK(shkp); - eshkp = ESHK(shkp); + if (!inhishop(shkp)) { + /* dump core when referenced */ + eshkp->bill_p = (struct bill_x *) -1000; + if (!index(empty_shops, *enterstring)) + deserted_shop(enterstring); + Strcpy(empty_shops, u.ushops); + u.ushops[0] = '\0'; + return; + } - if (!inhishop(shkp)) { - /* dump core when referenced */ - eshkp->bill_p = (struct bill_x *) -1000; - if (!index(empty_shops, *enterstring)) - deserted_shop(enterstring); - Strcpy(empty_shops, u.ushops); - u.ushops[0] = '\0'; - return; - } + eshkp->bill_p = &(eshkp->bill[0]); - eshkp->bill_p = &(eshkp->bill[0]); + if ((!eshkp->visitct || *eshkp->customer) + && strncmpi(eshkp->customer, plname, PL_NSIZ)) { + /* You seem to be new here */ + eshkp->visitct = 0; + eshkp->following = 0; + (void) strncpy(eshkp->customer, plname, PL_NSIZ); + pacify_shk(shkp); + } - if ((!eshkp->visitct || *eshkp->customer) && - strncmpi(eshkp->customer, plname, PL_NSIZ)) { - /* You seem to be new here */ - eshkp->visitct = 0; - eshkp->following = 0; - (void) strncpy(eshkp->customer,plname,PL_NSIZ); - pacify_shk(shkp); - } + if (muteshk(shkp) || eshkp->following) + return; /* no dialog */ - if (muteshk(shkp) || eshkp->following) - return; /* no dialog */ + if (Invis) { + pline("%s senses your presence.", shkname(shkp)); + verbalize("Invisible customers are not welcome!"); + return; + } - if (Invis) { - pline("%s senses your presence.", shkname(shkp)); - verbalize("Invisible customers are not welcome!"); - return; - } + rt = rooms[*enterstring - ROOMOFFSET].rtype; - rt = rooms[*enterstring - ROOMOFFSET].rtype; + if (ANGRY(shkp)) { + verbalize("So, %s, you dare return to %s %s?!", plname, + s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name); + } else if (eshkp->robbed) { + pline("%s mutters imprecations against shoplifters.", shkname(shkp)); + } else { + verbalize("%s, %s! Welcome%s to %s %s!", Hello(shkp), plname, + eshkp->visitct++ ? " again" : "", s_suffix(shkname(shkp)), + shtypes[rt - SHOPBASE].name); + } + /* can't do anything about blocking if teleported in */ + if (!inside_shop(u.ux, u.uy)) { + boolean should_block; + int cnt; + const char *tool; + struct obj *pick = carrying(PICK_AXE), + *mattock = carrying(DWARVISH_MATTOCK); - if (ANGRY(shkp)) { - verbalize("So, %s, you dare return to %s %s?!", - plname, - s_suffix(shkname(shkp)), - shtypes[rt - SHOPBASE].name); - } else if (eshkp->robbed) { - pline("%s mutters imprecations against shoplifters.", shkname(shkp)); - } else { - verbalize("%s, %s! Welcome%s to %s %s!", - Hello(shkp), plname, - eshkp->visitct++ ? " again" : "", - s_suffix(shkname(shkp)), - shtypes[rt - SHOPBASE].name); - } - /* can't do anything about blocking if teleported in */ - if (!inside_shop(u.ux, u.uy)) { - boolean should_block; - int cnt; - const char *tool; - struct obj *pick = carrying(PICK_AXE), - *mattock = carrying(DWARVISH_MATTOCK); - - if (pick || mattock) { - cnt = 1; /* so far */ - if (pick && mattock) { /* carrying both types */ - tool = "digging tool"; - cnt = 2; /* `more than 1' is all that matters */ - } else if (pick) { - tool = "pick-axe"; - /* hack: `pick' already points somewhere into inventory */ - while ((pick = pick->nobj) != 0) - if (pick->otyp == PICK_AXE) ++cnt; - } else { /* assert(mattock != 0) */ - tool = "mattock"; - while ((mattock = mattock->nobj) != 0) - if (mattock->otyp == DWARVISH_MATTOCK) ++cnt; - /* [ALI] Shopkeeper identifies mattock(s) */ - if (!Blind) makeknown(DWARVISH_MATTOCK); - } - verbalize(NOTANGRY(shkp) ? - "Will you please leave your %s%s outside?" : - "Leave the %s%s outside.", - tool, plur(cnt)); - should_block = TRUE; - } else if (u.usteed) { - verbalize(NOTANGRY(shkp) ? - "Will you please leave %s outside?" : - "Leave %s outside.", y_monnam(u.usteed)); + if (pick || mattock) { + cnt = 1; /* so far */ + if (pick && mattock) { /* carrying both types */ + tool = "digging tool"; + cnt = 2; /* `more than 1' is all that matters */ + } else if (pick) { + tool = "pick-axe"; + /* hack: `pick' already points somewhere into inventory */ + while ((pick = pick->nobj) != 0) + if (pick->otyp == PICK_AXE) + ++cnt; + } else { /* assert(mattock != 0) */ + tool = "mattock"; + while ((mattock = mattock->nobj) != 0) + if (mattock->otyp == DWARVISH_MATTOCK) + ++cnt; + /* [ALI] Shopkeeper identifies mattock(s) */ + if (!Blind) + makeknown(DWARVISH_MATTOCK); + } + verbalize(NOTANGRY(shkp) + ? "Will you please leave your %s%s outside?" + : "Leave the %s%s outside.", + tool, plur(cnt)); should_block = TRUE; - } else { - should_block = (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) || - sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))); - } - if (should_block) (void) dochug(shkp); /* shk gets extra move */ - } - return; + } else if (u.usteed) { + verbalize(NOTANGRY(shkp) ? "Will you please leave %s outside?" + : "Leave %s outside.", + y_monnam(u.usteed)); + should_block = TRUE; + } else { + should_block = + (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) + || sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))); + } + if (should_block) + (void) dochug(shkp); /* shk gets extra move */ + } + return; } /* called when removing a pick-axe or mattock from a container */ @@ -622,20 +634,21 @@ void pick_pick(obj) struct obj *obj; { - struct monst *shkp; + struct monst *shkp; - if (obj->unpaid || !is_pick(obj)) return; - shkp = shop_keeper(*u.ushops); - if (shkp && inhishop(shkp) && !muteshk(shkp)) { - static NEARDATA long pickmovetime = 0L; + if (obj->unpaid || !is_pick(obj)) + return; + shkp = shop_keeper(*u.ushops); + if (shkp && inhishop(shkp) && !muteshk(shkp)) { + static NEARDATA long pickmovetime = 0L; - /* if you bring a sack of N picks into a shop to sell, - don't repeat this N times when they're taken out */ - if (moves != pickmovetime) - verbalize("You sneaky %s! Get out of here with that pick!", - cad(FALSE)); - pickmovetime = moves; - } + /* if you bring a sack of N picks into a shop to sell, + don't repeat this N times when they're taken out */ + if (moves != pickmovetime) + verbalize("You sneaky %s! Get out of here with that pick!", + cad(FALSE)); + pickmovetime = moves; + } } /* @@ -647,26 +660,30 @@ boolean same_price(obj1, obj2) struct obj *obj1, *obj2; { - register struct monst *shkp1, *shkp2; - register struct bill_x *bp1 = 0, *bp2 = 0; - register boolean are_mergable = FALSE; + register struct monst *shkp1, *shkp2; + register struct bill_x *bp1 = 0, *bp2 = 0; + register boolean are_mergable = FALSE; - /* look up the first object by finding shk whose bill it's on */ - for (shkp1 = next_shkp(fmon, TRUE); shkp1; - shkp1 = next_shkp(shkp1->nmon, TRUE)) - if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0) break; - /* second object is probably owned by same shk; if not, look harder */ - if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) { - shkp2 = shkp1; - } else { - for (shkp2 = next_shkp(fmon, TRUE); shkp2; - shkp2 = next_shkp(shkp2->nmon, TRUE)) - if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0) break; - } + /* look up the first object by finding shk whose bill it's on */ + for (shkp1 = next_shkp(fmon, TRUE); shkp1; + shkp1 = next_shkp(shkp1->nmon, TRUE)) + if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0) + break; + /* second object is probably owned by same shk; if not, look harder */ + if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) { + shkp2 = shkp1; + } else { + for (shkp2 = next_shkp(fmon, TRUE); shkp2; + shkp2 = next_shkp(shkp2->nmon, TRUE)) + if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0) + break; + } - if (!bp1 || !bp2) impossible("same_price: object wasn't on any bill!"); - else are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price); - return are_mergable; + if (!bp1 || !bp2) + impossible("same_price: object wasn't on any bill!"); + else + are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price); + return are_mergable; } /* @@ -679,87 +696,89 @@ STATIC_OVL long shop_debt(eshkp) struct eshk *eshkp; { - struct bill_x *bp; - int ct; - long debt = eshkp->debit; + struct bill_x *bp; + int ct; + long debt = eshkp->debit; - for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--) - debt += bp->price * bp->bquan; - return debt; + for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--) + debt += bp->price * bp->bquan; + return debt; } /* called in response to the `$' command */ void shopper_financial_report() { - struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy)); - struct eshk *eshkp; - long amt; - int pass; + struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy)); + struct eshk *eshkp; + long amt; + int pass; - if (this_shkp && - !(ESHK(this_shkp)->credit || shop_debt(ESHK(this_shkp)))) { - You("have no credit or debt in here."); - this_shkp = 0; /* skip first pass */ - } + if (this_shkp + && !(ESHK(this_shkp)->credit || shop_debt(ESHK(this_shkp)))) { + You("have no credit or debt in here."); + this_shkp = 0; /* skip first pass */ + } - /* pass 0: report for the shop we're currently in, if any; - pass 1: report for all other shops on this level. */ - for (pass = this_shkp ? 0 : 1; pass <= 1; pass++) - for (shkp = next_shkp(fmon, FALSE); - shkp; shkp = next_shkp(shkp->nmon, FALSE)) { - if ((shkp != this_shkp) ^ pass) continue; - eshkp = ESHK(shkp); - if ((amt = eshkp->credit) != 0) - You("have %ld %s credit at %s %s.", - amt, currency(amt), s_suffix(shkname(shkp)), - shtypes[eshkp->shoptype - SHOPBASE].name); - else if (shkp == this_shkp) - You("have no credit in here."); - if ((amt = shop_debt(eshkp)) != 0) - You("owe %s %ld %s.", - shkname(shkp), amt, currency(amt)); - else if (shkp == this_shkp) - You("don't owe any money here."); - } + /* pass 0: report for the shop we're currently in, if any; + pass 1: report for all other shops on this level. */ + for (pass = this_shkp ? 0 : 1; pass <= 1; pass++) + for (shkp = next_shkp(fmon, FALSE); shkp; + shkp = next_shkp(shkp->nmon, FALSE)) { + if ((shkp != this_shkp) ^ pass) + continue; + eshkp = ESHK(shkp); + if ((amt = eshkp->credit) != 0) + You("have %ld %s credit at %s %s.", amt, currency(amt), + s_suffix(shkname(shkp)), + shtypes[eshkp->shoptype - SHOPBASE].name); + else if (shkp == this_shkp) + You("have no credit in here."); + if ((amt = shop_debt(eshkp)) != 0) + You("owe %s %ld %s.", shkname(shkp), amt, currency(amt)); + else if (shkp == this_shkp) + You("don't owe any money here."); + } } int inhishop(mtmp) register struct monst *mtmp; { - return(index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), - ESHK(mtmp)->shoproom) && - on_level(&(ESHK(mtmp)->shoplevel), &u.uz)); + return ( + index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), ESHK(mtmp)->shoproom) + && on_level(&(ESHK(mtmp)->shoplevel), &u.uz)); } struct monst * shop_keeper(rmno) register char rmno; { - struct monst *shkp = rmno >= ROOMOFFSET ? - rooms[rmno - ROOMOFFSET].resident : 0; + struct monst *shkp = + rmno >= ROOMOFFSET ? rooms[rmno - ROOMOFFSET].resident : 0; - if (shkp) { - if (NOTANGRY(shkp)) { - if (ESHK(shkp)->surcharge) pacify_shk(shkp); - } else { - if (!ESHK(shkp)->surcharge) rile_shk(shkp); - } - } - return shkp; + if (shkp) { + if (NOTANGRY(shkp)) { + if (ESHK(shkp)->surcharge) + pacify_shk(shkp); + } else { + if (!ESHK(shkp)->surcharge) + rile_shk(shkp); + } + } + return shkp; } boolean tended_shop(sroom) register struct mkroom *sroom; { - register struct monst *mtmp = sroom->resident; + register struct monst *mtmp = sroom->resident; - if (!mtmp) - return(FALSE); - else - return((boolean)(inhishop(mtmp))); + if (!mtmp) + return (FALSE); + else + return ((boolean)(inhishop(mtmp))); } STATIC_OVL struct bill_x * @@ -768,18 +787,21 @@ register struct obj *obj; register struct monst *shkp; register boolean silent; { - if (shkp) { - register struct bill_x *bp = ESHK(shkp)->bill_p; - register int ct = ESHK(shkp)->billct; + if (shkp) { + register struct bill_x *bp = ESHK(shkp)->bill_p; + register int ct = ESHK(shkp)->billct; - while (--ct >= 0) - if (bp->bo_id == obj->o_id) { - if (!obj->unpaid) pline("onbill: paid obj on bill?"); - return bp; - } else bp++; - } - if(obj->unpaid & !silent) pline("onbill: unpaid obj not on bill?"); - return (struct bill_x *)0; + while (--ct >= 0) + if (bp->bo_id == obj->o_id) { + if (!obj->unpaid) + pline("onbill: paid obj on bill?"); + return bp; + } else + bp++; + } + if (obj->unpaid & !silent) + pline("onbill: unpaid obj not on bill?"); + return (struct bill_x *) 0; } /* check whether an object or any of its contents belongs to a shop */ @@ -787,7 +809,7 @@ boolean is_unpaid(obj) struct obj *obj; { - return (obj->unpaid || (Has_contents(obj) && count_unpaid(obj->cobj))); + return (obj->unpaid || (Has_contents(obj) && count_unpaid(obj->cobj))); } /* Delete the contents of the given object. */ @@ -795,12 +817,12 @@ void delete_contents(obj) register struct obj *obj; { - register struct obj *curr; + register struct obj *curr; - while ((curr = obj->cobj) != 0) { - obj_extract_self(curr); - obfree(curr, (struct obj *)0); - } + while ((curr = obj->cobj) != 0) { + obj_extract_self(curr); + obfree(curr, (struct obj *) 0); + } } /* called with two args on merge */ @@ -808,67 +830,73 @@ void obfree(obj, merge) register struct obj *obj, *merge; { - register struct bill_x *bp; - register struct bill_x *bpm; - register struct monst *shkp; + register struct bill_x *bp; + register struct bill_x *bpm; + register struct monst *shkp; - if (obj->otyp == LEASH && obj->leashmon) o_unleash(obj); - if (obj->oclass == FOOD_CLASS) food_disappears(obj); - if (obj->oclass == SPBOOK_CLASS) book_disappears(obj); - if (Has_contents(obj)) delete_contents(obj); + if (obj->otyp == LEASH && obj->leashmon) + o_unleash(obj); + if (obj->oclass == FOOD_CLASS) + food_disappears(obj); + if (obj->oclass == SPBOOK_CLASS) + book_disappears(obj); + if (Has_contents(obj)) + delete_contents(obj); - shkp = 0; - if (obj->unpaid) { - /* look for a shopkeeper who owns this object */ - for (shkp = next_shkp(fmon, TRUE); shkp; - shkp = next_shkp(shkp->nmon, TRUE)) - if (onbill(obj, shkp, TRUE)) break; - } - /* sanity check, more or less */ - if (!shkp) shkp = shop_keeper(*u.ushops); - /* - * Note: `shkp = shop_keeper(*u.ushops)' used to be - * unconditional. But obfree() is used all over - * the place, so making its behavior be dependent - * upon player location doesn't make much sense. - */ + shkp = 0; + if (obj->unpaid) { + /* look for a shopkeeper who owns this object */ + for (shkp = next_shkp(fmon, TRUE); shkp; + shkp = next_shkp(shkp->nmon, TRUE)) + if (onbill(obj, shkp, TRUE)) + break; + } + /* sanity check, more or less */ + if (!shkp) + shkp = shop_keeper(*u.ushops); + /* + * Note: `shkp = shop_keeper(*u.ushops)' used to be + * unconditional. But obfree() is used all over + * the place, so making its behavior be dependent + * upon player location doesn't make much sense. + */ - if ((bp = onbill(obj, shkp, FALSE)) != 0) { - if(!merge){ - bp->useup = 1; - obj->unpaid = 0; /* only for doinvbill */ - add_to_billobjs(obj); - return; - } - bpm = onbill(merge, shkp, FALSE); - if(!bpm){ - /* this used to be a rename */ - impossible("obfree: not on bill??"); - return; - } else { - /* this was a merger */ - bpm->bquan += bp->bquan; - ESHK(shkp)->billct--; + if ((bp = onbill(obj, shkp, FALSE)) != 0) { + if (!merge) { + bp->useup = 1; + obj->unpaid = 0; /* only for doinvbill */ + add_to_billobjs(obj); + return; + } + bpm = onbill(merge, shkp, FALSE); + if (!bpm) { + /* this used to be a rename */ + impossible("obfree: not on bill??"); + return; + } else { + /* this was a merger */ + bpm->bquan += bp->bquan; + ESHK(shkp)->billct--; #ifdef DUMB - { - /* DRS/NS 2.2.6 messes up -- Peter Kendell */ - int indx = ESHK(shkp)->billct; - *bp = ESHK(shkp)->bill_p[indx]; - } + { + /* DRS/NS 2.2.6 messes up -- Peter Kendell */ + int indx = ESHK(shkp)->billct; + *bp = ESHK(shkp)->bill_p[indx]; + } #else - *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; + *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; #endif - } - } - if (obj->owornmask) { - impossible("obfree: deleting worn obj (%d: %ld)", - obj->otyp, obj->owornmask); - /* unfortunately at this point we don't know whether worn mask - applied to hero or a monster or perhaps something bogus, so - can't call remove_worn_item() to get _off() side-effects */ - setnotworn(obj); - } - dealloc_obj(obj); + } + } + if (obj->owornmask) { + impossible("obfree: deleting worn obj (%d: %ld)", obj->otyp, + obj->owornmask); + /* unfortunately at this point we don't know whether worn mask + applied to hero or a monster or perhaps something bogus, so + can't call remove_worn_item() to get _off() side-effects */ + setnotworn(obj); + } + dealloc_obj(obj); } STATIC_OVL long @@ -876,37 +904,41 @@ check_credit(tmp, shkp) long tmp; register struct monst *shkp; { - long credit = ESHK(shkp)->credit; + long credit = ESHK(shkp)->credit; - if(credit == 0L) return(tmp); - if(credit >= tmp) { - pline_The("price is deducted from your credit."); - ESHK(shkp)->credit -=tmp; - tmp = 0L; - } else { - pline_The("price is partially covered by your credit."); - ESHK(shkp)->credit = 0L; - tmp -= credit; - } - return(tmp); + if (credit == 0L) + return (tmp); + if (credit >= tmp) { + pline_The("price is deducted from your credit."); + ESHK(shkp)->credit -= tmp; + tmp = 0L; + } else { + pline_The("price is partially covered by your credit."); + ESHK(shkp)->credit = 0L; + tmp -= credit; + } + return (tmp); } STATIC_OVL void -pay(tmp,shkp) +pay(tmp, shkp) long tmp; register struct monst *shkp; { - long robbed = ESHK(shkp)->robbed; - long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp)); + long robbed = ESHK(shkp)->robbed; + long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp)); - if (balance > 0) money2mon(shkp, balance); - else if (balance < 0) money2u(shkp, -balance); - context.botl = 1; - if(robbed) { - robbed -= tmp; - if(robbed < 0) robbed = 0L; - ESHK(shkp)->robbed = robbed; - } + if (balance > 0) + money2mon(shkp, balance); + else if (balance < 0) + money2u(shkp, -balance); + context.botl = 1; + if (robbed) { + robbed -= tmp; + if (robbed < 0) + robbed = 0L; + ESHK(shkp)->robbed = robbed; + } } /* return shkp to home position */ @@ -915,26 +947,27 @@ home_shk(shkp, killkops) register struct monst *shkp; register boolean killkops; { - register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y; + register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y; - (void) mnearto(shkp, x, y, TRUE); - level.flags.has_shop = 1; - if (killkops) { - kops_gone(TRUE); - pacify_guards(); - } - after_shk_move(shkp); + (void) mnearto(shkp, x, y, TRUE); + level.flags.has_shop = 1; + if (killkops) { + kops_gone(TRUE); + pacify_guards(); + } + after_shk_move(shkp); } STATIC_OVL boolean angry_shk_exists() { - register struct monst *shkp; + register struct monst *shkp; - for (shkp = next_shkp(fmon, FALSE); - shkp; shkp = next_shkp(shkp->nmon, FALSE)) - if (ANGRY(shkp)) return(TRUE); - return(FALSE); + for (shkp = next_shkp(fmon, FALSE); shkp; + shkp = next_shkp(shkp->nmon, FALSE)) + if (ANGRY(shkp)) + return (TRUE); + return (FALSE); } /* remove previously applied surcharge from all billed items */ @@ -942,18 +975,18 @@ STATIC_OVL void pacify_shk(shkp) register struct monst *shkp; { - NOTANGRY(shkp) = TRUE; /* make peaceful */ - if (ESHK(shkp)->surcharge) { - register struct bill_x *bp = ESHK(shkp)->bill_p; - register int ct = ESHK(shkp)->billct; + NOTANGRY(shkp) = TRUE; /* make peaceful */ + if (ESHK(shkp)->surcharge) { + register struct bill_x *bp = ESHK(shkp)->bill_p; + register int ct = ESHK(shkp)->billct; - ESHK(shkp)->surcharge = FALSE; - while (ct-- > 0) { - register long reduction = (bp->price + 3L) / 4L; - bp->price -= reduction; /* undo 33% increase */ - bp++; - } - } + ESHK(shkp)->surcharge = FALSE; + while (ct-- > 0) { + register long reduction = (bp->price + 3L) / 4L; + bp->price -= reduction; /* undo 33% increase */ + bp++; + } + } } /* add aggravation surcharge to all billed items */ @@ -961,18 +994,18 @@ STATIC_OVL void rile_shk(shkp) register struct monst *shkp; { - NOTANGRY(shkp) = FALSE; /* make angry */ - if (!ESHK(shkp)->surcharge) { - register struct bill_x *bp = ESHK(shkp)->bill_p; - register int ct = ESHK(shkp)->billct; + NOTANGRY(shkp) = FALSE; /* make angry */ + if (!ESHK(shkp)->surcharge) { + register struct bill_x *bp = ESHK(shkp)->bill_p; + register int ct = ESHK(shkp)->billct; - ESHK(shkp)->surcharge = TRUE; - while (ct-- > 0) { - register long surcharge = (bp->price + 2L) / 3L; - bp->price += surcharge; - bp++; - } - } + ESHK(shkp)->surcharge = TRUE; + while (ct-- > 0) { + register long surcharge = (bp->price + 2L) / 3L; + bp->price += surcharge; + bp++; + } + } } /* wakeup and/or unparalyze shopkeeper */ @@ -981,15 +1014,15 @@ rouse_shk(shkp, verbosely) struct monst *shkp; boolean verbosely; { - if (!shkp->mcanmove || shkp->msleeping) { - /* greed induced recovery... */ - if (verbosely && canspotmon(shkp)) - pline("%s %s.", Monnam(shkp), - shkp->msleeping ? "wakes up" : "can move again"); - shkp->msleeping = 0; - shkp->mfrozen = 0; - shkp->mcanmove = 1; - } + if (!shkp->mcanmove || shkp->msleeping) { + /* greed induced recovery... */ + if (verbosely && canspotmon(shkp)) + pline("%s %s.", Monnam(shkp), + shkp->msleeping ? "wakes up" : "can move again"); + shkp->msleeping = 0; + shkp->mfrozen = 0; + shkp->mcanmove = 1; + } } void @@ -997,41 +1030,43 @@ make_happy_shk(shkp, silentkops) register struct monst *shkp; register boolean silentkops; { - boolean wasmad = ANGRY(shkp); - struct eshk *eshkp = ESHK(shkp); + boolean wasmad = ANGRY(shkp); + struct eshk *eshkp = ESHK(shkp); - pacify_shk(shkp); - eshkp->following = 0; - eshkp->robbed = 0L; - if (!Role_if(PM_ROGUE)) - adjalign(sgn(u.ualign.type)); - if(!inhishop(shkp)) { - char shk_nam[BUFSZ]; - boolean vanished = canseemon(shkp); + pacify_shk(shkp); + eshkp->following = 0; + eshkp->robbed = 0L; + if (!Role_if(PM_ROGUE)) + adjalign(sgn(u.ualign.type)); + if (!inhishop(shkp)) { + char shk_nam[BUFSZ]; + boolean vanished = canseemon(shkp); - Strcpy(shk_nam, mon_nam(shkp)); - if (on_level(&eshkp->shoplevel, &u.uz)) { - home_shk(shkp, FALSE); - /* didn't disappear if shk can still be seen */ - if (canseemon(shkp)) vanished = FALSE; - } else { - /* if sensed, does disappear regardless whether seen */ - if (sensemon(shkp)) vanished = TRUE; - /* can't act as porter for the Amulet, even if shk - happens to be going farther down rather than up */ - mdrop_special_objs(shkp); - /* arrive near shop's door */ - migrate_to_level(shkp, ledger_no(&eshkp->shoplevel), - MIGR_APPROX_XY, &eshkp->shd); - /* dismiss kops on that level when shk arrives */ - eshkp->dismiss_kops = TRUE; - } - if (vanished) - pline("Satisfied, %s suddenly disappears!", shk_nam); - } else if(wasmad) - pline("%s calms down.", Monnam(shkp)); + Strcpy(shk_nam, mon_nam(shkp)); + if (on_level(&eshkp->shoplevel, &u.uz)) { + home_shk(shkp, FALSE); + /* didn't disappear if shk can still be seen */ + if (canseemon(shkp)) + vanished = FALSE; + } else { + /* if sensed, does disappear regardless whether seen */ + if (sensemon(shkp)) + vanished = TRUE; + /* can't act as porter for the Amulet, even if shk + happens to be going farther down rather than up */ + mdrop_special_objs(shkp); + /* arrive near shop's door */ + migrate_to_level(shkp, ledger_no(&eshkp->shoplevel), + MIGR_APPROX_XY, &eshkp->shd); + /* dismiss kops on that level when shk arrives */ + eshkp->dismiss_kops = TRUE; + } + if (vanished) + pline("Satisfied, %s suddenly disappears!", shk_nam); + } else if (wasmad) + pline("%s calms down.", Monnam(shkp)); - make_happy_shoppers(silentkops); + make_happy_shoppers(silentkops); } /* called by make_happy_shk() and also by losedogs() for migrating shk */ @@ -1039,21 +1074,22 @@ void make_happy_shoppers(silentkops) boolean silentkops; { - if (!angry_shk_exists()) { - kops_gone(silentkops); - pacify_guards(); - } + if (!angry_shk_exists()) { + kops_gone(silentkops); + pacify_guards(); + } } void hot_pursuit(shkp) register struct monst *shkp; { - if(!shkp->isshk) return; + if (!shkp->isshk) + return; - rile_shk(shkp); - (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ); - ESHK(shkp)->following = 1; + rile_shk(shkp); + (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ); + ESHK(shkp)->following = 1; } /* used when the shkp is teleported or falls (ox == 0) out of his shop, @@ -1064,368 +1100,372 @@ register struct monst *shkp; void make_angry_shk(shkp, ox, oy) register struct monst *shkp; -register xchar ox,oy; +register xchar ox, oy; { - xchar sx, sy; - struct eshk *eshkp = ESHK(shkp); + xchar sx, sy; + struct eshk *eshkp = ESHK(shkp); - /* all pending shop transactions are now "past due" */ - if (eshkp->billct || eshkp->debit || eshkp->loan || eshkp->credit) { - eshkp->robbed += (addupbill(shkp) + eshkp->debit + eshkp->loan); - eshkp->robbed -= eshkp->credit; - if (eshkp->robbed < 0L) eshkp->robbed = 0L; - /* billct, debit, loan, and credit will be cleared by setpaid */ - setpaid(shkp); - } + /* all pending shop transactions are now "past due" */ + if (eshkp->billct || eshkp->debit || eshkp->loan || eshkp->credit) { + eshkp->robbed += (addupbill(shkp) + eshkp->debit + eshkp->loan); + eshkp->robbed -= eshkp->credit; + if (eshkp->robbed < 0L) + eshkp->robbed = 0L; + /* billct, debit, loan, and credit will be cleared by setpaid */ + setpaid(shkp); + } - /* If you just used a wand of teleportation to send the shk away, you - might not be able to see her any more. Monnam would yield "it", - which makes this message look pretty silly, so temporarily restore - her original location during the call to Monnam. */ - sx = shkp->mx, sy = shkp->my; - if (isok(ox, oy) && cansee(ox, oy) && !cansee(sx, sy)) - shkp->mx = ox, shkp->my = oy; - pline("%s %s!", Monnam(shkp), - !ANGRY(shkp) ? "gets angry" : "is furious"); - shkp->mx = sx, shkp->my = sy; - hot_pursuit(shkp); + /* If you just used a wand of teleportation to send the shk away, you + might not be able to see her any more. Monnam would yield "it", + which makes this message look pretty silly, so temporarily restore + her original location during the call to Monnam. */ + sx = shkp->mx, sy = shkp->my; + if (isok(ox, oy) && cansee(ox, oy) && !cansee(sx, sy)) + shkp->mx = ox, shkp->my = oy; + pline("%s %s!", Monnam(shkp), !ANGRY(shkp) ? "gets angry" : "is furious"); + shkp->mx = sx, shkp->my = sy; + hot_pursuit(shkp); } STATIC_VAR const char no_money[] = "Moreover, you%s have no money."; STATIC_VAR const char not_enough_money[] = - "Besides, you don't have enough to interest %s."; + "Besides, you don't have enough to interest %s."; STATIC_OVL long -cheapest_item(shkp) /* delivers the cheapest item on the list */ +cheapest_item(shkp) /* delivers the cheapest item on the list */ register struct monst *shkp; { - register int ct = ESHK(shkp)->billct; - register struct bill_x *bp = ESHK(shkp)->bill_p; - register long gmin = (bp->price * bp->bquan); + register int ct = ESHK(shkp)->billct; + register struct bill_x *bp = ESHK(shkp)->bill_p; + register long gmin = (bp->price * bp->bquan); - while(ct--){ - if(bp->price * bp->bquan < gmin) - gmin = bp->price * bp->bquan; - bp++; - } - return(gmin); + while (ct--) { + if (bp->price * bp->bquan < gmin) + gmin = bp->price * bp->bquan; + bp++; + } + return (gmin); } int dopay() { - register struct eshk *eshkp; - register struct monst *shkp; - struct monst *nxtm, *resident; - long ltmp; - long umoney; - int pass, tmp, sk = 0, seensk = 0; - boolean paid = FALSE, stashed_gold = (hidden_gold() > 0L); + register struct eshk *eshkp; + register struct monst *shkp; + struct monst *nxtm, *resident; + long ltmp; + long umoney; + int pass, tmp, sk = 0, seensk = 0; + boolean paid = FALSE, stashed_gold = (hidden_gold() > 0L); - multi = 0; + multi = 0; - /* find how many shk's there are, how many are in */ - /* sight, and are you in a shop room with one. */ - nxtm = resident = 0; - for (shkp = next_shkp(fmon, FALSE); - shkp; shkp = next_shkp(shkp->nmon, FALSE)) { - sk++; - if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2) nxtm = shkp; - if (canspotmon(shkp)) seensk++; - if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom)) - resident = shkp; - } + /* find how many shk's there are, how many are in */ + /* sight, and are you in a shop room with one. */ + nxtm = resident = 0; + for (shkp = next_shkp(fmon, FALSE); shkp; + shkp = next_shkp(shkp->nmon, FALSE)) { + sk++; + if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2) + nxtm = shkp; + if (canspotmon(shkp)) + seensk++; + if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom)) + resident = shkp; + } - if (nxtm) { /* Player should always appease an */ - shkp = nxtm; /* irate shk standing next to them. */ - goto proceed; - } + if (nxtm) { /* Player should always appease an */ + shkp = nxtm; /* irate shk standing next to them. */ + goto proceed; + } - if ((!sk && (!Blind || Blind_telepat)) || (!Blind && !seensk)) { - There("appears to be no shopkeeper here to receive your payment."); - return(0); - } + if ((!sk && (!Blind || Blind_telepat)) || (!Blind && !seensk)) { + There("appears to be no shopkeeper here to receive your payment."); + return (0); + } - if(!seensk) { - You_cant("see..."); - return(0); - } + if (!seensk) { + You_cant("see..."); + return (0); + } - /* the usual case. allow paying at a distance when */ - /* inside a tended shop. should we change that? */ - if(sk == 1 && resident) { - shkp = resident; - goto proceed; - } + /* the usual case. allow paying at a distance when */ + /* inside a tended shop. should we change that? */ + if (sk == 1 && resident) { + shkp = resident; + goto proceed; + } - if (seensk == 1) { - for (shkp = next_shkp(fmon, FALSE); - shkp; shkp = next_shkp(shkp->nmon, FALSE)) - if (canspotmon(shkp)) break; - if (shkp != resident && distu(shkp->mx, shkp->my) > 2) { - pline("%s is not near enough to receive your payment.", - Monnam(shkp)); - return(0); - } - } else { - struct monst *mtmp; - coord cc; - int cx, cy; + if (seensk == 1) { + for (shkp = next_shkp(fmon, FALSE); shkp; + shkp = next_shkp(shkp->nmon, FALSE)) + if (canspotmon(shkp)) + break; + if (shkp != resident && distu(shkp->mx, shkp->my) > 2) { + pline("%s is not near enough to receive your payment.", + Monnam(shkp)); + return (0); + } + } else { + struct monst *mtmp; + coord cc; + int cx, cy; - pline("Pay whom?"); - cc.x = u.ux; - cc.y = u.uy; - if (getpos(&cc, TRUE, "the creature you want to pay") < 0) - return 0; /* player pressed ESC */ - cx = cc.x; - cy = cc.y; - if(cx < 0) { - pline("Try again..."); - return(0); - } - if(u.ux == cx && u.uy == cy) { - You("are generous to yourself."); - return(0); - } - mtmp = m_at(cx, cy); - if(!mtmp) { - There("is no one there to receive your payment."); - return(0); - } - if(!mtmp->isshk) { - pline("%s is not interested in your payment.", - Monnam(mtmp)); - return(0); - } - if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) { - pline("%s is too far to receive your payment.", - Monnam(mtmp)); - return(0); - } - shkp = mtmp; - } + pline("Pay whom?"); + cc.x = u.ux; + cc.y = u.uy; + if (getpos(&cc, TRUE, "the creature you want to pay") < 0) + return 0; /* player pressed ESC */ + cx = cc.x; + cy = cc.y; + if (cx < 0) { + pline("Try again..."); + return (0); + } + if (u.ux == cx && u.uy == cy) { + You("are generous to yourself."); + return (0); + } + mtmp = m_at(cx, cy); + if (!mtmp) { + There("is no one there to receive your payment."); + return (0); + } + if (!mtmp->isshk) { + pline("%s is not interested in your payment.", Monnam(mtmp)); + return (0); + } + if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) { + pline("%s is too far to receive your payment.", Monnam(mtmp)); + return (0); + } + shkp = mtmp; + } - if(!shkp) { - debugpline0("dopay: null shkp."); - return(0); - } + if (!shkp) { + debugpline0("dopay: null shkp."); + return (0); + } proceed: - eshkp = ESHK(shkp); - ltmp = eshkp->robbed; + eshkp = ESHK(shkp); + ltmp = eshkp->robbed; - /* wake sleeping shk when someone who owes money offers payment */ - if (ltmp || eshkp->billct || eshkp->debit) - rouse_shk(shkp, TRUE); + /* wake sleeping shk when someone who owes money offers payment */ + if (ltmp || eshkp->billct || eshkp->debit) + rouse_shk(shkp, TRUE); - if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */ - pline("%s %s.", Monnam(shkp), - rn2(2) ? "seems to be napping" : "doesn't respond"); - return 0; - } + if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */ + pline("%s %s.", Monnam(shkp), + rn2(2) ? "seems to be napping" : "doesn't respond"); + return 0; + } - if(shkp != resident && NOTANGRY(shkp)) { - umoney = money_cnt(invent); - if(!ltmp) - You("do not owe %s anything.", mon_nam(shkp)); - else if(!umoney) { - You("%shave no money.", stashed_gold ? "seem to " : ""); - if(stashed_gold) - pline("But you have some gold stashed away."); - } else { - if(umoney > ltmp) { - You("give %s the %ld gold piece%s %s asked for.", - shkname(shkp), ltmp, plur(ltmp), mhe(shkp)); - pay(ltmp, shkp); - } else { - You("give %s all your%s gold.", shkname(shkp), - stashed_gold ? " openly kept" : ""); - pay(umoney, shkp); - if (stashed_gold) pline("But you have hidden gold!"); - } - if((umoney < ltmp/2L) || (umoney < ltmp && stashed_gold)) - pline("Unfortunately, %s doesn't look satisfied.", - mhe(shkp)); - else - make_happy_shk(shkp, FALSE); - } - return(1); - } + if (shkp != resident && NOTANGRY(shkp)) { + umoney = money_cnt(invent); + if (!ltmp) + You("do not owe %s anything.", mon_nam(shkp)); + else if (!umoney) { + You("%shave no money.", stashed_gold ? "seem to " : ""); + if (stashed_gold) + pline("But you have some gold stashed away."); + } else { + if (umoney > ltmp) { + You("give %s the %ld gold piece%s %s asked for.", + shkname(shkp), ltmp, plur(ltmp), mhe(shkp)); + pay(ltmp, shkp); + } else { + You("give %s all your%s gold.", shkname(shkp), + stashed_gold ? " openly kept" : ""); + pay(umoney, shkp); + if (stashed_gold) + pline("But you have hidden gold!"); + } + if ((umoney < ltmp / 2L) || (umoney < ltmp && stashed_gold)) + pline("Unfortunately, %s doesn't look satisfied.", mhe(shkp)); + else + make_happy_shk(shkp, FALSE); + } + return (1); + } - /* ltmp is still eshkp->robbed here */ - if (!eshkp->billct && !eshkp->debit) { - umoney = money_cnt(invent); - if(!ltmp && NOTANGRY(shkp)) { - You("do not owe %s anything.", shkname(shkp)); - if (!umoney) - pline(no_money, stashed_gold ? " seem to" : ""); - } else if(ltmp) { - pline("%s is after blood, not money!", shkname(shkp)); - if(umoney < ltmp/2L || - (umoney < ltmp && stashed_gold)) { - if (!umoney) - pline(no_money, stashed_gold ? " seem to" : ""); - else pline(not_enough_money, mhim(shkp)); - return(1); - } - pline("But since %s shop has been robbed recently,", - mhis(shkp)); - pline("you %scompensate %s for %s losses.", - (umoney < ltmp) ? "partially " : "", - shkname(shkp), mhis(shkp)); - pay(umoney < ltmp ? umoney : ltmp, shkp); - make_happy_shk(shkp, FALSE); - } else { - /* shopkeeper is angry, but has not been robbed -- - * door broken, attacked, etc. */ - pline("%s is after your hide, not your money!", - Monnam(shkp)); - if(umoney < 1000L) { - if (!umoney) - pline(no_money, stashed_gold ? " seem to" : ""); - else pline(not_enough_money, mhim(shkp)); - return(1); - } - You("try to appease %s by giving %s 1000 gold pieces.", - x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE), - mhim(shkp)); - pay(1000L,shkp); - if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3)) - make_happy_shk(shkp, FALSE); - else - pline("But %s is as angry as ever.", shkname(shkp)); - } - return(1); - } - if(shkp != resident) { - impossible("dopay: not to shopkeeper?"); - if(resident) setpaid(resident); - return(0); - } - /* pay debt, if any, first */ - if(eshkp->debit) { - long dtmp = eshkp->debit; - long loan = eshkp->loan; - char sbuf[BUFSZ]; - umoney = money_cnt(invent); - Sprintf(sbuf, "You owe %s %ld %s ", - shkname(shkp), dtmp, currency(dtmp)); - if(loan) { - if(loan == dtmp) - Strcat(sbuf, "you picked up in the store."); - else Strcat(sbuf, - "for gold picked up and the use of merchandise."); - } else Strcat(sbuf, "for the use of merchandise."); - pline1(sbuf); - if (umoney + eshkp->credit < dtmp) { - pline("But you don't%s have enough gold%s.", - stashed_gold ? " seem to" : "", - eshkp->credit ? " or credit" : ""); - return(1); - } else { - if (eshkp->credit >= dtmp) { - eshkp->credit -= dtmp; - eshkp->debit = 0L; - eshkp->loan = 0L; - Your("debt is covered by your credit."); - } else if (!eshkp->credit) { - money2mon(shkp, dtmp); - eshkp->debit = 0L; - eshkp->loan = 0L; - You("pay that debt."); - context.botl = 1; - } else { - dtmp -= eshkp->credit; - eshkp->credit = 0L; - money2mon(shkp, dtmp); - eshkp->debit = 0L; - eshkp->loan = 0L; - pline("That debt is partially offset by your credit."); - You("pay the remainder."); - context.botl = 1; - } - paid = TRUE; - } - } - /* now check items on bill */ - if (eshkp->billct) { - register boolean itemize; - int iprompt; - umoney = money_cnt(invent); - if (!umoney && !eshkp->credit) { - You("%shave no money or credit%s.", - stashed_gold ? "seem to " : "", - paid ? " left" : ""); - return(0); - } - if ((umoney + eshkp->credit) < cheapest_item(shkp)) { - You("don't have enough money to buy%s the item%s you picked.", - eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct)); - if(stashed_gold) - pline("Maybe you have some gold stashed away?"); - return(0); - } + /* ltmp is still eshkp->robbed here */ + if (!eshkp->billct && !eshkp->debit) { + umoney = money_cnt(invent); + if (!ltmp && NOTANGRY(shkp)) { + You("do not owe %s anything.", shkname(shkp)); + if (!umoney) + pline(no_money, stashed_gold ? " seem to" : ""); + } else if (ltmp) { + pline("%s is after blood, not money!", shkname(shkp)); + if (umoney < ltmp / 2L || (umoney < ltmp && stashed_gold)) { + if (!umoney) + pline(no_money, stashed_gold ? " seem to" : ""); + else + pline(not_enough_money, mhim(shkp)); + return (1); + } + pline("But since %s shop has been robbed recently,", mhis(shkp)); + pline("you %scompensate %s for %s losses.", + (umoney < ltmp) ? "partially " : "", shkname(shkp), + mhis(shkp)); + pay(umoney < ltmp ? umoney : ltmp, shkp); + make_happy_shk(shkp, FALSE); + } else { + /* shopkeeper is angry, but has not been robbed -- + * door broken, attacked, etc. */ + pline("%s is after your hide, not your money!", Monnam(shkp)); + if (umoney < 1000L) { + if (!umoney) + pline(no_money, stashed_gold ? " seem to" : ""); + else + pline(not_enough_money, mhim(shkp)); + return (1); + } + You("try to appease %s by giving %s 1000 gold pieces.", + x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE), mhim(shkp)); + pay(1000L, shkp); + if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3)) + make_happy_shk(shkp, FALSE); + else + pline("But %s is as angry as ever.", shkname(shkp)); + } + return (1); + } + if (shkp != resident) { + impossible("dopay: not to shopkeeper?"); + if (resident) + setpaid(resident); + return (0); + } + /* pay debt, if any, first */ + if (eshkp->debit) { + long dtmp = eshkp->debit; + long loan = eshkp->loan; + char sbuf[BUFSZ]; + umoney = money_cnt(invent); + Sprintf(sbuf, "You owe %s %ld %s ", shkname(shkp), dtmp, + currency(dtmp)); + if (loan) { + if (loan == dtmp) + Strcat(sbuf, "you picked up in the store."); + else + Strcat(sbuf, + "for gold picked up and the use of merchandise."); + } else + Strcat(sbuf, "for the use of merchandise."); + pline1(sbuf); + if (umoney + eshkp->credit < dtmp) { + pline("But you don't%s have enough gold%s.", + stashed_gold ? " seem to" : "", + eshkp->credit ? " or credit" : ""); + return (1); + } else { + if (eshkp->credit >= dtmp) { + eshkp->credit -= dtmp; + eshkp->debit = 0L; + eshkp->loan = 0L; + Your("debt is covered by your credit."); + } else if (!eshkp->credit) { + money2mon(shkp, dtmp); + eshkp->debit = 0L; + eshkp->loan = 0L; + You("pay that debt."); + context.botl = 1; + } else { + dtmp -= eshkp->credit; + eshkp->credit = 0L; + money2mon(shkp, dtmp); + eshkp->debit = 0L; + eshkp->loan = 0L; + pline("That debt is partially offset by your credit."); + You("pay the remainder."); + context.botl = 1; + } + paid = TRUE; + } + } + /* now check items on bill */ + if (eshkp->billct) { + register boolean itemize; + int iprompt; + umoney = money_cnt(invent); + if (!umoney && !eshkp->credit) { + You("%shave no money or credit%s.", + stashed_gold ? "seem to " : "", paid ? " left" : ""); + return (0); + } + if ((umoney + eshkp->credit) < cheapest_item(shkp)) { + You("don't have enough money to buy%s the item%s you picked.", + eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct)); + if (stashed_gold) + pline("Maybe you have some gold stashed away?"); + return (0); + } - /* this isn't quite right; it itemizes without asking if the - * single item on the bill is partly used up and partly unpaid */ - iprompt = (eshkp->billct > 1 ? ynq("Itemized billing?") : 'y'); - itemize = (iprompt == 'y'); - if (iprompt == 'q') goto thanks; + /* this isn't quite right; it itemizes without asking if the + * single item on the bill is partly used up and partly unpaid */ + iprompt = (eshkp->billct > 1 ? ynq("Itemized billing?") : 'y'); + itemize = (iprompt == 'y'); + if (iprompt == 'q') + goto thanks; - for (pass = 0; pass <= 1; pass++) { - tmp = 0; - while (tmp < eshkp->billct) { - struct obj *otmp; - register struct bill_x *bp = &(eshkp->bill_p[tmp]); + for (pass = 0; pass <= 1; pass++) { + tmp = 0; + while (tmp < eshkp->billct) { + struct obj *otmp; + register struct bill_x *bp = &(eshkp->bill_p[tmp]); - /* find the object on one of the lists */ - if ((otmp = bp_to_obj(bp)) != 0) { - /* if completely used up, object quantity is stale; - restoring it to its original value here avoids - making the partly-used-up code more complicated */ - if (bp->useup) otmp->quan = bp->bquan; - } else { - impossible("Shopkeeper administration out of order."); - setpaid(shkp); /* be nice to the player */ - return 1; - } - if (pass == bp->useup && otmp->quan == bp->bquan) { - /* pay for used-up items on first pass and others - * on second, so player will be stuck in the store - * less often; things which are partly used up - * are processed on both passes */ - tmp++; - } else { - switch (dopayobj(shkp, bp, &otmp, pass, itemize)) { - case PAY_CANT: - return 1; /*break*/ - case PAY_BROKE: - paid = TRUE; - goto thanks; /*break*/ - case PAY_SKIP: - tmp++; - continue; /*break*/ - case PAY_SOME: - paid = TRUE; - if (itemize) bot(); - continue; /*break*/ - case PAY_BUY: - paid = TRUE; - break; - } - if (itemize) bot(); - *bp = eshkp->bill_p[--eshkp->billct]; - } - } - } - thanks: - if (!itemize) - update_inventory(); /* Done in dopayobj() if itemize. */ - } - if (!ANGRY(shkp) && paid && !muteshk(shkp)) - verbalize("Thank you for shopping in %s %s!", - s_suffix(shkname(shkp)), - shtypes[eshkp->shoptype - SHOPBASE].name); - return(1); + /* find the object on one of the lists */ + if ((otmp = bp_to_obj(bp)) != 0) { + /* if completely used up, object quantity is stale; + restoring it to its original value here avoids + making the partly-used-up code more complicated */ + if (bp->useup) + otmp->quan = bp->bquan; + } else { + impossible("Shopkeeper administration out of order."); + setpaid(shkp); /* be nice to the player */ + return 1; + } + if (pass == bp->useup && otmp->quan == bp->bquan) { + /* pay for used-up items on first pass and others + * on second, so player will be stuck in the store + * less often; things which are partly used up + * are processed on both passes */ + tmp++; + } else { + switch (dopayobj(shkp, bp, &otmp, pass, itemize)) { + case PAY_CANT: + return 1; /*break*/ + case PAY_BROKE: + paid = TRUE; + goto thanks; /*break*/ + case PAY_SKIP: + tmp++; + continue; /*break*/ + case PAY_SOME: + paid = TRUE; + if (itemize) + bot(); + continue; /*break*/ + case PAY_BUY: + paid = TRUE; + break; + } + if (itemize) + bot(); + *bp = eshkp->bill_p[--eshkp->billct]; + } + } + } + thanks: + if (!itemize) + update_inventory(); /* Done in dopayobj() if itemize. */ + } + if (!ANGRY(shkp) && paid && !muteshk(shkp)) + verbalize("Thank you for shopping in %s %s!", s_suffix(shkname(shkp)), + shtypes[eshkp->shoptype - SHOPBASE].name); + return (1); } /* return 2 if used-up portion paid */ @@ -1438,103 +1478,103 @@ dopayobj(shkp, bp, obj_p, which, itemize) register struct monst *shkp; register struct bill_x *bp; struct obj **obj_p; -int which; /* 0 => used-up item, 1 => other (unpaid or lost) */ +int which; /* 0 => used-up item, 1 => other (unpaid or lost) */ boolean itemize; { - register struct obj *obj = *obj_p; - long ltmp, quan, save_quan; - long umoney = money_cnt(invent); - int buy; - boolean stashed_gold = (hidden_gold() > 0L), - consumed = (which == 0); + register struct obj *obj = *obj_p; + long ltmp, quan, save_quan; + long umoney = money_cnt(invent); + int buy; + boolean stashed_gold = (hidden_gold() > 0L), consumed = (which == 0); - if(!obj->unpaid && !bp->useup){ - impossible("Paid object on bill??"); - return PAY_BUY; - } - if(itemize && umoney + ESHK(shkp)->credit == 0L){ - You("%shave no money or credit left.", - stashed_gold ? "seem to " : ""); - return PAY_BROKE; - } - /* we may need to temporarily adjust the object, if part of the - original quantity has been used up but part remains unpaid */ - save_quan = obj->quan; - if (consumed) { - /* either completely used up (simple), or split needed */ - quan = bp->bquan; - if (quan > obj->quan) /* difference is amount used up */ - quan -= obj->quan; - } else { - /* dealing with ordinary unpaid item */ - quan = obj->quan; - } - obj->quan = quan; /* to be used by doname() */ - obj->unpaid = 0; /* ditto */ - iflags.suppress_price++; /* affects containers */ - ltmp = bp->price * quan; - buy = PAY_BUY; /* flag; if changed then return early */ + if (!obj->unpaid && !bp->useup) { + impossible("Paid object on bill??"); + return PAY_BUY; + } + if (itemize && umoney + ESHK(shkp)->credit == 0L) { + You("%shave no money or credit left.", + stashed_gold ? "seem to " : ""); + return PAY_BROKE; + } + /* we may need to temporarily adjust the object, if part of the + original quantity has been used up but part remains unpaid */ + save_quan = obj->quan; + if (consumed) { + /* either completely used up (simple), or split needed */ + quan = bp->bquan; + if (quan > obj->quan) /* difference is amount used up */ + quan -= obj->quan; + } else { + /* dealing with ordinary unpaid item */ + quan = obj->quan; + } + obj->quan = quan; /* to be used by doname() */ + obj->unpaid = 0; /* ditto */ + iflags.suppress_price++; /* affects containers */ + ltmp = bp->price * quan; + buy = PAY_BUY; /* flag; if changed then return early */ - if (itemize) { - char qbuf[BUFSZ], qsfx[BUFSZ]; + if (itemize) { + char qbuf[BUFSZ], qsfx[BUFSZ]; - Sprintf(qsfx, " for %ld %s. Pay?", ltmp, currency(ltmp)); - (void)safe_qbuf(qbuf, (char *)0, qsfx, - obj, (quan == 1L) ? Doname2 : doname, - ansimpleoname, (quan == 1L) ? "that" : "those"); - if (yn(qbuf) == 'n') { - buy = PAY_SKIP; /* don't want to buy */ - } else if (quan < bp->bquan && !consumed) { /* partly used goods */ - obj->quan = bp->bquan - save_quan; /* used up amount */ - verbalize("%s for the other %s before buying %s.", - ANGRY(shkp) ? "Pay" : "Please pay", - simpleonames(obj), /* short name suffices */ - save_quan > 1L ? "these" : "this one"); - buy = PAY_SKIP; /* shk won't sell */ - } - } - if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) { - You("don't%s have gold%s enough to pay for %s.", - stashed_gold ? " seem to" : "", - (ESHK(shkp)->credit > 0L) ? " or credit" : "", - thesimpleoname(obj)); - buy = itemize ? PAY_SKIP : PAY_CANT; - } + Sprintf(qsfx, " for %ld %s. Pay?", ltmp, currency(ltmp)); + (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj, + (quan == 1L) ? Doname2 : doname, ansimpleoname, + (quan == 1L) ? "that" : "those"); + if (yn(qbuf) == 'n') { + buy = PAY_SKIP; /* don't want to buy */ + } else if (quan < bp->bquan && !consumed) { /* partly used goods */ + obj->quan = bp->bquan - save_quan; /* used up amount */ + verbalize("%s for the other %s before buying %s.", + ANGRY(shkp) ? "Pay" : "Please pay", + simpleonames(obj), /* short name suffices */ + save_quan > 1L ? "these" : "this one"); + buy = PAY_SKIP; /* shk won't sell */ + } + } + if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) { + You("don't%s have gold%s enough to pay for %s.", + stashed_gold ? " seem to" : "", + (ESHK(shkp)->credit > 0L) ? " or credit" : "", + thesimpleoname(obj)); + buy = itemize ? PAY_SKIP : PAY_CANT; + } - if (buy != PAY_BUY) { - /* restore unpaid object to original state */ - obj->quan = save_quan; - obj->unpaid = 1; - iflags.suppress_price--; - return buy; - } + if (buy != PAY_BUY) { + /* restore unpaid object to original state */ + obj->quan = save_quan; + obj->unpaid = 1; + iflags.suppress_price--; + return buy; + } - pay(ltmp, shkp); - shk_names_obj(shkp, obj, consumed ? - "paid for %s at a cost of %ld gold piece%s.%s" : - "bought %s for %ld gold piece%s.%s", ltmp, ""); - obj->quan = save_quan; /* restore original count */ - /* quan => amount just bought, save_quan => remaining unpaid count */ - if (consumed) { - if (quan != bp->bquan) { - /* eliminate used-up portion; remainder is still unpaid */ - bp->bquan = obj->quan; - obj->unpaid = 1; - bp->useup = 0; - buy = PAY_SOME; - } else { /* completely used-up, so get rid of it */ - obj_extract_self(obj); - /* assert( obj == *obj_p ); */ - dealloc_obj(obj); - *obj_p = 0; /* destroy pointer to freed object */ - } - } else if (itemize) - update_inventory(); /* Done just once in dopay() if !itemize. */ - iflags.suppress_price--; - return buy; + pay(ltmp, shkp); + shk_names_obj(shkp, obj, + consumed ? "paid for %s at a cost of %ld gold piece%s.%s" + : "bought %s for %ld gold piece%s.%s", + ltmp, ""); + obj->quan = save_quan; /* restore original count */ + /* quan => amount just bought, save_quan => remaining unpaid count */ + if (consumed) { + if (quan != bp->bquan) { + /* eliminate used-up portion; remainder is still unpaid */ + bp->bquan = obj->quan; + obj->unpaid = 1; + bp->useup = 0; + buy = PAY_SOME; + } else { /* completely used-up, so get rid of it */ + obj_extract_self(obj); + /* assert( obj == *obj_p ); */ + dealloc_obj(obj); + *obj_p = 0; /* destroy pointer to freed object */ + } + } else if (itemize) + update_inventory(); /* Done just once in dopay() if !itemize. */ + iflags.suppress_price--; + return buy; } -static struct repo { /* repossession context */ +static struct repo { /* repossession context */ struct monst *shopkeeper; coord location; } repo; @@ -1542,83 +1582,87 @@ static struct repo { /* repossession context */ /* routine called after dying (or quitting) */ boolean paybill(croaked) -int croaked; /* -1: escaped dungeon; 0: quit; 1: died */ +int croaked; /* -1: escaped dungeon; 0: quit; 1: died */ { - struct monst *mtmp, *mtmp2, *firstshk, - *resident, *creditor, *hostile, *localshk; - struct eshk *eshkp; - boolean taken = FALSE, local; - int numsk = 0; + struct monst *mtmp, *mtmp2, *firstshk, *resident, *creditor, *hostile, + *localshk; + struct eshk *eshkp; + boolean taken = FALSE, local; + int numsk = 0; - /* if we escaped from the dungeon, shopkeepers can't reach us; - shops don't occur on level 1, but this could happen if hero - level teleports out of the dungeon and manages not to die */ - if (croaked < 0) return FALSE; - /* [should probably also return false when dead hero has been - petrified since shk shouldn't be able to grab inventory - which has been shut inside a statue] */ + /* if we escaped from the dungeon, shopkeepers can't reach us; + shops don't occur on level 1, but this could happen if hero + level teleports out of the dungeon and manages not to die */ + if (croaked < 0) + return FALSE; + /* [should probably also return false when dead hero has been + petrified since shk shouldn't be able to grab inventory + which has been shut inside a statue] */ - /* this is where inventory will end up if any shk takes it */ - repo.location.x = repo.location.y = 0; - repo.shopkeeper = 0; + /* this is where inventory will end up if any shk takes it */ + repo.location.x = repo.location.y = 0; + repo.shopkeeper = 0; - /* - * Scan all shopkeepres on the level, to prioritize them: - * 1) keeper of shop hero is inside and who is owed money, - * 2) keeper of shop hero is inside who isn't owed any money, - * 3) other shk who is owed money, 4) other shk who is angry, - * 5) any shk local to this level, and if none is found, - * 6) first shk on monster list (last resort; unlikely, since - * any nonlocal shk will probably be in the owed category - * and almost certainly be in the angry category). - */ - resident = creditor = hostile = localshk = (struct monst *)0; - for (mtmp = next_shkp(fmon, FALSE); - mtmp; mtmp = next_shkp(mtmp2, FALSE)) { - mtmp2 = mtmp->nmon; - eshkp = ESHK(mtmp); - local = on_level(&eshkp->shoplevel, &u.uz); - if (local && index(u.ushops, eshkp->shoproom)) { - /* inside this shk's shop [there might be more than one - resident shk if hero is standing in a breech of a shared - wall, so give priority to one who's also owed money] */ - if (!resident || - eshkp->billct || eshkp->debit || eshkp->robbed) - resident = mtmp; - } else if (eshkp->billct || eshkp->debit || eshkp->robbed) { - /* owe this shopkeeper money (might also owe others) */ - if (!creditor) creditor = mtmp; - } else if (eshkp->following || ANGRY(mtmp)) { - /* this shopkeeper is antagonistic (others might be too) */ - if (!hostile) hostile = mtmp; - } else if (local) { - /* this shopkeeper's shop is on current level */ - if (!localshk) localshk = mtmp; - } - } + /* + * Scan all shopkeepres on the level, to prioritize them: + * 1) keeper of shop hero is inside and who is owed money, + * 2) keeper of shop hero is inside who isn't owed any money, + * 3) other shk who is owed money, 4) other shk who is angry, + * 5) any shk local to this level, and if none is found, + * 6) first shk on monster list (last resort; unlikely, since + * any nonlocal shk will probably be in the owed category + * and almost certainly be in the angry category). + */ + resident = creditor = hostile = localshk = (struct monst *) 0; + for (mtmp = next_shkp(fmon, FALSE); mtmp; + mtmp = next_shkp(mtmp2, FALSE)) { + mtmp2 = mtmp->nmon; + eshkp = ESHK(mtmp); + local = on_level(&eshkp->shoplevel, &u.uz); + if (local && index(u.ushops, eshkp->shoproom)) { + /* inside this shk's shop [there might be more than one + resident shk if hero is standing in a breech of a shared + wall, so give priority to one who's also owed money] */ + if (!resident || eshkp->billct || eshkp->debit || eshkp->robbed) + resident = mtmp; + } else if (eshkp->billct || eshkp->debit || eshkp->robbed) { + /* owe this shopkeeper money (might also owe others) */ + if (!creditor) + creditor = mtmp; + } else if (eshkp->following || ANGRY(mtmp)) { + /* this shopkeeper is antagonistic (others might be too) */ + if (!hostile) + hostile = mtmp; + } else if (local) { + /* this shopkeeper's shop is on current level */ + if (!localshk) + localshk = mtmp; + } + } - /* give highest priority shopkeeper first crack */ - firstshk = resident ? resident : creditor ? creditor : - hostile ? hostile : localshk; - if (firstshk) { - numsk++; - taken = inherits(firstshk, numsk, croaked); - } + /* give highest priority shopkeeper first crack */ + firstshk = resident ? resident : creditor ? creditor : hostile ? hostile + : localshk; + if (firstshk) { + numsk++; + taken = inherits(firstshk, numsk, croaked); + } - /* now handle the rest */ - for (mtmp = next_shkp(fmon, FALSE); - mtmp; mtmp = next_shkp(mtmp2, FALSE)) { - mtmp2 = mtmp->nmon; - eshkp = ESHK(mtmp); - local = on_level(&eshkp->shoplevel, &u.uz); - if (mtmp != firstshk) { - numsk++; - taken |= inherits(mtmp, numsk, croaked); - } - /* for bones: we don't want a shopless shk around */ - if (!local) mongone(mtmp); - } - return taken; + /* now handle the rest */ + for (mtmp = next_shkp(fmon, FALSE); mtmp; + mtmp = next_shkp(mtmp2, FALSE)) { + mtmp2 = mtmp->nmon; + eshkp = ESHK(mtmp); + local = on_level(&eshkp->shoplevel, &u.uz); + if (mtmp != firstshk) { + numsk++; + taken |= inherits(mtmp, numsk, croaked); + } + /* for bones: we don't want a shopless shk around */ + if (!local) + mongone(mtmp); + } + return taken; } STATIC_OVL boolean @@ -1627,149 +1671,148 @@ struct monst *shkp; int numsk; int croaked; { - long loss = 0L; - long umoney; - struct eshk *eshkp = ESHK(shkp); - boolean take = FALSE, taken = FALSE; - unsigned save_minvis = shkp->minvis; - int roomno = *u.ushops; - char takes[BUFSZ]; + long loss = 0L; + long umoney; + struct eshk *eshkp = ESHK(shkp); + boolean take = FALSE, taken = FALSE; + unsigned save_minvis = shkp->minvis; + int roomno = *u.ushops; + char takes[BUFSZ]; - shkp->minvis = 0; - /* the simplifying principle is that first-come */ - /* already took everything you had. */ - if (numsk > 1) { - if (cansee(shkp->mx, shkp->my) && croaked) { - takes[0] = '\0'; - if (has_head(shkp->data) && !rn2(2)) - Sprintf(takes, ", shakes %s %s,", - mhis(shkp), mbodypart(shkp, HEAD)); - pline("%s %slooks at your corpse%s and %s.", - Monnam(shkp), (!shkp->mcanmove || shkp->msleeping) ? - "wakes up, " : "", - takes, !inhishop(shkp) ? "disappears" : "sighs"); - } - rouse_shk(shkp, FALSE); /* wake shk for bones */ - taken = (roomno == eshkp->shoproom); - goto skip; - } + shkp->minvis = 0; + /* the simplifying principle is that first-come */ + /* already took everything you had. */ + if (numsk > 1) { + if (cansee(shkp->mx, shkp->my) && croaked) { + takes[0] = '\0'; + if (has_head(shkp->data) && !rn2(2)) + Sprintf(takes, ", shakes %s %s,", mhis(shkp), + mbodypart(shkp, HEAD)); + pline("%s %slooks at your corpse%s and %s.", Monnam(shkp), + (!shkp->mcanmove || shkp->msleeping) ? "wakes up, " : "", + takes, !inhishop(shkp) ? "disappears" : "sighs"); + } + rouse_shk(shkp, FALSE); /* wake shk for bones */ + taken = (roomno == eshkp->shoproom); + goto skip; + } - /* get one case out of the way: you die in the shop, the */ - /* shopkeeper is peaceful, nothing stolen, nothing owed. */ - if(roomno == eshkp->shoproom && inhishop(shkp) && - !eshkp->billct && !eshkp->robbed && !eshkp->debit && - NOTANGRY(shkp) && !eshkp->following) { - taken = (invent != 0); - if (taken) - pline("%s gratefully inherits all your possessions.", - shkname(shkp)); - set_repo_loc(shkp); - goto clear; - } + /* get one case out of the way: you die in the shop, the */ + /* shopkeeper is peaceful, nothing stolen, nothing owed. */ + if (roomno == eshkp->shoproom && inhishop(shkp) && !eshkp->billct + && !eshkp->robbed && !eshkp->debit && NOTANGRY(shkp) + && !eshkp->following) { + taken = (invent != 0); + if (taken) + pline("%s gratefully inherits all your possessions.", + shkname(shkp)); + set_repo_loc(shkp); + goto clear; + } - if (eshkp->billct || eshkp->debit || eshkp->robbed) { - if (roomno == eshkp->shoproom && inhishop(shkp)) - loss = addupbill(shkp) + eshkp->debit; - if (loss < eshkp->robbed) loss = eshkp->robbed; - take = TRUE; - } + if (eshkp->billct || eshkp->debit || eshkp->robbed) { + if (roomno == eshkp->shoproom && inhishop(shkp)) + loss = addupbill(shkp) + eshkp->debit; + if (loss < eshkp->robbed) + loss = eshkp->robbed; + take = TRUE; + } - if (eshkp->following || ANGRY(shkp) || take) { - if (!invent) goto skip; - umoney = money_cnt(invent); - takes[0] = '\0'; - if (!shkp->mcanmove || shkp->msleeping) - Strcat(takes, "wakes up and "); - if (distu(shkp->mx, shkp->my) > 2) - Strcat(takes, "comes and "); - Strcat(takes, "takes"); + if (eshkp->following || ANGRY(shkp) || take) { + if (!invent) + goto skip; + umoney = money_cnt(invent); + takes[0] = '\0'; + if (!shkp->mcanmove || shkp->msleeping) + Strcat(takes, "wakes up and "); + if (distu(shkp->mx, shkp->my) > 2) + Strcat(takes, "comes and "); + Strcat(takes, "takes"); - if (loss > umoney || !loss || roomno == eshkp->shoproom) { - eshkp->robbed -= umoney; - if (eshkp->robbed < 0L) eshkp->robbed = 0L; - if (umoney > 0) money2mon(shkp, umoney); - context.botl = 1; - pline("%s %s all your possessions.", - shkname(shkp), takes); - taken = TRUE; - /* where to put player's invent (after disclosure) */ - set_repo_loc(shkp); - } else { - money2mon(shkp, loss); - context.botl = 1; - pline("%s %s the %ld %s %sowed %s.", - Monnam(shkp), takes, - loss, currency(loss), - strncmp(eshkp->customer, plname, PL_NSIZ) ? - "" : "you ", - shkp->female ? "her" : "him"); - /* shopkeeper has now been paid in full */ - pacify_shk(shkp); - eshkp->following = 0; - eshkp->robbed = 0L; - } -skip: - /* in case we create bones */ - rouse_shk(shkp, FALSE); /* wake up */ - if (!inhishop(shkp)) - home_shk(shkp, FALSE); - } + if (loss > umoney || !loss || roomno == eshkp->shoproom) { + eshkp->robbed -= umoney; + if (eshkp->robbed < 0L) + eshkp->robbed = 0L; + if (umoney > 0) + money2mon(shkp, umoney); + context.botl = 1; + pline("%s %s all your possessions.", shkname(shkp), takes); + taken = TRUE; + /* where to put player's invent (after disclosure) */ + set_repo_loc(shkp); + } else { + money2mon(shkp, loss); + context.botl = 1; + pline("%s %s the %ld %s %sowed %s.", Monnam(shkp), takes, loss, + currency(loss), + strncmp(eshkp->customer, plname, PL_NSIZ) ? "" : "you ", + shkp->female ? "her" : "him"); + /* shopkeeper has now been paid in full */ + pacify_shk(shkp); + eshkp->following = 0; + eshkp->robbed = 0L; + } + skip: + /* in case we create bones */ + rouse_shk(shkp, FALSE); /* wake up */ + if (!inhishop(shkp)) + home_shk(shkp, FALSE); + } clear: - shkp->minvis = save_minvis; - setpaid(shkp); - return(taken); + shkp->minvis = save_minvis; + setpaid(shkp); + return (taken); } STATIC_OVL void set_repo_loc(shkp) struct monst *shkp; { - register xchar ox, oy; - struct eshk *eshkp = ESHK(shkp); + register xchar ox, oy; + struct eshk *eshkp = ESHK(shkp); - /* if you're not in this shk's shop room, or if you're in its doorway - or entry spot, then your gear gets dumped all the way inside */ - if (*u.ushops != eshkp->shoproom || - IS_DOOR(levl[u.ux][u.uy].typ) || - (u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) { - /* shk.x,shk.y is the position immediately in - * front of the door -- move in one more space - */ - ox = eshkp->shk.x; - oy = eshkp->shk.y; - ox += sgn(ox - eshkp->shd.x); - oy += sgn(oy - eshkp->shd.y); - } else { /* already inside this shk's shop */ - ox = u.ux; - oy = u.uy; - } - /* finish_paybill will deposit invent here */ - repo.location.x = ox; - repo.location.y = oy; - repo.shopkeeper = shkp; + /* if you're not in this shk's shop room, or if you're in its doorway + or entry spot, then your gear gets dumped all the way inside */ + if (*u.ushops != eshkp->shoproom || IS_DOOR(levl[u.ux][u.uy].typ) + || (u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) { + /* shk.x,shk.y is the position immediately in + * front of the door -- move in one more space + */ + ox = eshkp->shk.x; + oy = eshkp->shk.y; + ox += sgn(ox - eshkp->shd.x); + oy += sgn(oy - eshkp->shd.y); + } else { /* already inside this shk's shop */ + ox = u.ux; + oy = u.uy; + } + /* finish_paybill will deposit invent here */ + repo.location.x = ox; + repo.location.y = oy; + repo.shopkeeper = shkp; } /* called at game exit, after inventory disclosure but before making bones */ void finish_paybill() { - struct monst *shkp = repo.shopkeeper; - int ox = repo.location.x, - oy = repo.location.y; + struct monst *shkp = repo.shopkeeper; + int ox = repo.location.x, oy = repo.location.y; -#if 0 /* don't bother */ +#if 0 /* don't bother */ if (ox == 0 && oy == 0) impossible("finish_paybill: no location"); #endif - /* normally done by savebones(), but that's too late in this case */ - unleash_all(); - /* if hero has any gold left, take it into shopkeeper's possession */ - if (shkp) { - long umoney = money_cnt(invent); + /* normally done by savebones(), but that's too late in this case */ + unleash_all(); + /* if hero has any gold left, take it into shopkeeper's possession */ + if (shkp) { + long umoney = money_cnt(invent); - if (umoney) money2mon(shkp, umoney); - } - /* transfer rest of the character's inventory to the shop floor */ - drop_upon_death((struct monst *)0, (struct obj *)0, ox, oy); + if (umoney) + money2mon(shkp, umoney); + } + /* transfer rest of the character's inventory to the shop floor */ + drop_upon_death((struct monst *) 0, (struct obj *) 0, ox, oy); } /* find obj on one of the lists */ @@ -1777,14 +1820,14 @@ STATIC_OVL struct obj * bp_to_obj(bp) register struct bill_x *bp; { - register struct obj *obj; - register unsigned int id = bp->bo_id; + register struct obj *obj; + register unsigned int id = bp->bo_id; - if(bp->useup) - obj = o_on(id, billobjs); - else - obj = find_oid(id); - return obj; + if (bp->useup) + obj = o_on(id, billobjs); + else + obj = find_oid(id); + return obj; } /* @@ -1796,123 +1839,139 @@ struct obj * find_oid(id) unsigned id; { - struct obj *obj; - struct monst *mon, *mmtmp[3]; - int i; + struct obj *obj; + struct monst *mon, *mmtmp[3]; + int i; - /* first check various obj lists directly */ - if ((obj = o_on(id, invent)) != 0) return obj; - if ((obj = o_on(id, fobj)) != 0) return obj; - if ((obj = o_on(id, level.buriedobjlist)) != 0) return obj; - if ((obj = o_on(id, migrating_objs)) != 0) return obj; + /* first check various obj lists directly */ + if ((obj = o_on(id, invent)) != 0) + return obj; + if ((obj = o_on(id, fobj)) != 0) + return obj; + if ((obj = o_on(id, level.buriedobjlist)) != 0) + return obj; + if ((obj = o_on(id, migrating_objs)) != 0) + return obj; - /* not found yet; check inventory for members of various monst lists */ - mmtmp[0] = fmon; - mmtmp[1] = migrating_mons; - mmtmp[2] = mydogs; /* for use during level changes */ - for (i = 0; i < 3; i++) - for (mon = mmtmp[i]; mon; mon = mon->nmon) - if ((obj = o_on(id, mon->minvent)) != 0) return obj; + /* not found yet; check inventory for members of various monst lists */ + mmtmp[0] = fmon; + mmtmp[1] = migrating_mons; + mmtmp[2] = mydogs; /* for use during level changes */ + for (i = 0; i < 3; i++) + for (mon = mmtmp[i]; mon; mon = mon->nmon) + if ((obj = o_on(id, mon->minvent)) != 0) + return obj; - /* not found at all */ - return (struct obj *)0; + /* not found at all */ + return (struct obj *) 0; } /* calculate the value that the shk will charge for [one of] an object */ STATIC_OVL long get_cost(obj, shkp) register struct obj *obj; -register struct monst *shkp; /* if angry, impose a surcharge */ +register struct monst *shkp; /* if angry, impose a surcharge */ { - long tmp = getprice(obj, FALSE), - /* used to perform a single calculation even when multiple - adjustments (unID'd, dunce/tourist, charisma) are made */ - multiplier = 1L, divisor = 1L; + long tmp = getprice(obj, FALSE), + /* used to perform a single calculation even when multiple + adjustments (unID'd, dunce/tourist, charisma) are made */ + multiplier = 1L, divisor = 1L; - if (!tmp) tmp = 5L; - /* shopkeeper may notice if the player isn't very knowledgeable - - especially when gem prices are concerned */ - if (!obj->dknown || !objects[obj->otyp].oc_name_known) { - if (obj->oclass == GEM_CLASS && - objects[obj->otyp].oc_material == GLASS) { - int i; - /* get a value that's 'random' from game to game, but the - same within the same game */ - boolean pseudorand = - (((int)ubirthday % obj->otyp) >= obj->otyp/2); + if (!tmp) + tmp = 5L; + /* shopkeeper may notice if the player isn't very knowledgeable - + especially when gem prices are concerned */ + if (!obj->dknown || !objects[obj->otyp].oc_name_known) { + if (obj->oclass == GEM_CLASS + && objects[obj->otyp].oc_material == GLASS) { + int i; + /* get a value that's 'random' from game to game, but the + same within the same game */ + boolean pseudorand = + (((int) ubirthday % obj->otyp) >= obj->otyp / 2); - /* all gems are priced high - real or not */ - switch(obj->otyp - LAST_GEM) { - case 1: /* white */ - i = pseudorand ? DIAMOND : OPAL; - break; - case 2: /* blue */ - i = pseudorand ? SAPPHIRE : AQUAMARINE; - break; - case 3: /* red */ - i = pseudorand ? RUBY : JASPER; - break; - case 4: /* yellowish brown */ - i = pseudorand ? AMBER : TOPAZ; - break; - case 5: /* orange */ - i = pseudorand ? JACINTH : AGATE; - break; - case 6: /* yellow */ - i = pseudorand ? CITRINE : CHRYSOBERYL; - break; - case 7: /* black */ - i = pseudorand ? BLACK_OPAL : JET; - break; - case 8: /* green */ - i = pseudorand ? EMERALD : JADE; - break; - case 9: /* violet */ - i = pseudorand ? AMETHYST : FLUORITE; - break; - default: impossible("bad glass gem %d?", obj->otyp); - i = STRANGE_OBJECT; - break; - } - tmp = (long) objects[i].oc_cost; - } else if (!(obj->o_id % 4)) { - /* unid'd, arbitrarily impose surcharge: tmp *= 4/3 */ - multiplier *= 4L; - divisor *= 3L; - } - } - if (uarmh && uarmh->otyp == DUNCE_CAP) - multiplier *= 4L, divisor *= 3L; - else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2)) || - (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ - multiplier *= 4L, divisor *= 3L; + /* all gems are priced high - real or not */ + switch (obj->otyp - LAST_GEM) { + case 1: /* white */ + i = pseudorand ? DIAMOND : OPAL; + break; + case 2: /* blue */ + i = pseudorand ? SAPPHIRE : AQUAMARINE; + break; + case 3: /* red */ + i = pseudorand ? RUBY : JASPER; + break; + case 4: /* yellowish brown */ + i = pseudorand ? AMBER : TOPAZ; + break; + case 5: /* orange */ + i = pseudorand ? JACINTH : AGATE; + break; + case 6: /* yellow */ + i = pseudorand ? CITRINE : CHRYSOBERYL; + break; + case 7: /* black */ + i = pseudorand ? BLACK_OPAL : JET; + break; + case 8: /* green */ + i = pseudorand ? EMERALD : JADE; + break; + case 9: /* violet */ + i = pseudorand ? AMETHYST : FLUORITE; + break; + default: + impossible("bad glass gem %d?", obj->otyp); + i = STRANGE_OBJECT; + break; + } + tmp = (long) objects[i].oc_cost; + } else if (!(obj->o_id % 4)) { + /* unid'd, arbitrarily impose surcharge: tmp *= 4/3 */ + multiplier *= 4L; + divisor *= 3L; + } + } + if (uarmh && uarmh->otyp == DUNCE_CAP) + multiplier *= 4L, divisor *= 3L; + else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2)) + || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ + multiplier *= 4L, divisor *= 3L; - if (ACURR(A_CHA) > 18) divisor *= 2L; - else if (ACURR(A_CHA) == 18) multiplier *= 2L, divisor *= 3L; - else if (ACURR(A_CHA) >= 16) multiplier *= 3L, divisor *= 4L; - else if (ACURR(A_CHA) <= 5) multiplier *= 2L; - else if (ACURR(A_CHA) <= 7) multiplier *= 3L, divisor *= 2L; - else if (ACURR(A_CHA) <= 10) multiplier *= 4L, divisor *= 3L; + if (ACURR(A_CHA) > 18) + divisor *= 2L; + else if (ACURR(A_CHA) == 18) + multiplier *= 2L, divisor *= 3L; + else if (ACURR(A_CHA) >= 16) + multiplier *= 3L, divisor *= 4L; + else if (ACURR(A_CHA) <= 5) + multiplier *= 2L; + else if (ACURR(A_CHA) <= 7) + multiplier *= 3L, divisor *= 2L; + else if (ACURR(A_CHA) <= 10) + multiplier *= 4L, divisor *= 3L; - /* tmp = (tmp * multiplier) / divisor [with roundoff tweak] */ - tmp *= multiplier; - if (divisor > 1L) { - /* tmp = (((tmp * 10) / divisor) + 5) / 10 */ - tmp *= 10L; - tmp /= divisor; - tmp += 5L; - tmp /= 10L; - } + /* tmp = (tmp * multiplier) / divisor [with roundoff tweak] */ + tmp *= multiplier; + if (divisor > 1L) { + /* tmp = (((tmp * 10) / divisor) + 5) / 10 */ + tmp *= 10L; + tmp /= divisor; + tmp += 5L; + tmp /= 10L; + } - if (tmp <= 0L) tmp = 1L; - /* the artifact prices in artilist[] are also used as a score bonus; - inflate their shop price here without affecting score calculation */ - if (obj->oartifact) tmp *= 4L; + if (tmp <= 0L) + tmp = 1L; + /* the artifact prices in artilist[] are also used as a score bonus; + inflate their shop price here without affecting score calculation */ + if (obj->oartifact) + tmp *= 4L; - /* anger surcharge should match rile_shk's, so we do it separately - from the multiplier/divisor calculation */ - if (shkp && ESHK(shkp)->surcharge) tmp += (tmp + 2L) / 3L; - return tmp; + /* anger surcharge should match rile_shk's, so we do it separately + from the multiplier/divisor calculation */ + if (shkp && ESHK(shkp)->surcharge) + tmp += (tmp + 2L) / 3L; + return tmp; } /* returns the price of a container's content. the price @@ -1927,45 +1986,46 @@ long price; boolean usell; boolean unpaid_only; { - register struct obj *otmp; + register struct obj *otmp; - /* price of contained objects; "top" container handled by caller */ - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if (otmp->oclass == COIN_CLASS) continue; + /* price of contained objects; "top" container handled by caller */ + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; - if (usell) { - if (saleable(shkp, otmp) && - !otmp->unpaid && otmp->oclass != BALL_CLASS && - !(otmp->oclass == FOOD_CLASS && otmp->oeaten) && - !(Is_candle(otmp) && otmp->age < - 20L * (long)objects[otmp->otyp].oc_cost)) - price += set_cost(otmp, shkp); - } else if (!otmp->no_charge && (otmp->unpaid || !unpaid_only)) { - price += get_cost(otmp, shkp) * otmp->quan; - } + if (usell) { + if (saleable(shkp, otmp) && !otmp->unpaid + && otmp->oclass != BALL_CLASS + && !(otmp->oclass == FOOD_CLASS && otmp->oeaten) + && !(Is_candle(otmp) + && otmp->age < 20L * (long) objects[otmp->otyp].oc_cost)) + price += set_cost(otmp, shkp); + } else if (!otmp->no_charge && (otmp->unpaid || !unpaid_only)) { + price += get_cost(otmp, shkp) * otmp->quan; + } - if (Has_contents(otmp)) - price = contained_cost(otmp, shkp, price, usell, unpaid_only); - } + if (Has_contents(otmp)) + price = contained_cost(otmp, shkp, price, usell, unpaid_only); + } - return(price); + return (price); } long contained_gold(obj) register struct obj *obj; { - register struct obj *otmp; - register long value = 0L; + register struct obj *otmp; + register long value = 0L; - /* accumulate contained gold */ - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) - if (otmp->oclass == COIN_CLASS) - value += otmp->quan; - else if (Has_contents(otmp)) - value += contained_gold(otmp); + /* accumulate contained gold */ + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) + if (otmp->oclass == COIN_CLASS) + value += otmp->quan; + else if (Has_contents(otmp)) + value += contained_gold(otmp); - return(value); + return (value); } STATIC_OVL void @@ -1974,36 +2034,38 @@ register struct obj *obj; register struct monst *shkp; register boolean sale; { - register struct obj *otmp; + register struct obj *otmp; - /* the "top" container is treated in the calling fn */ - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if (otmp->oclass == COIN_CLASS) continue; + /* the "top" container is treated in the calling fn */ + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; - if (!otmp->unpaid && !(sale && saleable(shkp, otmp))) - otmp->no_charge = 1; + if (!otmp->unpaid && !(sale && saleable(shkp, otmp))) + otmp->no_charge = 1; - if (Has_contents(otmp)) - dropped_container(otmp, shkp, sale); - } + if (Has_contents(otmp)) + dropped_container(otmp, shkp, sale); + } } void picked_container(obj) register struct obj *obj; { - register struct obj *otmp; + register struct obj *otmp; - /* the "top" container is treated in the calling fn */ - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if (otmp->oclass == COIN_CLASS) continue; + /* the "top" container is treated in the calling fn */ + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; - if (otmp->no_charge) - otmp->no_charge = 0; + if (otmp->no_charge) + otmp->no_charge = 0; - if (Has_contents(otmp)) - picked_container(otmp); - } + if (Has_contents(otmp)) + picked_container(otmp); + } } STATIC_OVL boolean @@ -2012,27 +2074,26 @@ struct obj *obj; struct monst *shkp; boolean quietly; { - /* for unique situations */ - if (ESHK(shkp)->shoptype == CANDLESHOP && - obj->otyp == CANDELABRUM_OF_INVOCATION) { - if (!quietly) { - if (is_izchak(shkp, TRUE) && !u.uevent.invoked) { - verbalize("No thanks, I'd hang onto that if I were you."); - if (obj->spe < 7) - verbalize( - "You'll need %d%s candle%s to go along with it.", - (7 - obj->spe), - (obj->spe > 0) ? " more" : "", - plur(7 - obj->spe)); - /* [what if hero is already carrying enough candles? - should Izchak explain how to attach them instead] */ - } else { - verbalize("I won't stock that. Take it out of here!"); - } - } - return TRUE; - } - return FALSE; + /* for unique situations */ + if (ESHK(shkp)->shoptype == CANDLESHOP + && obj->otyp == CANDELABRUM_OF_INVOCATION) { + if (!quietly) { + if (is_izchak(shkp, TRUE) && !u.uevent.invoked) { + verbalize("No thanks, I'd hang onto that if I were you."); + if (obj->spe < 7) + verbalize( + "You'll need %d%s candle%s to go along with it.", + (7 - obj->spe), (obj->spe > 0) ? " more" : "", + plur(7 - obj->spe)); + /* [what if hero is already carrying enough candles? + should Izchak explain how to attach them instead] */ + } else { + verbalize("I won't stock that. Take it out of here!"); + } + } + return TRUE; + } + return FALSE; } /* calculate how much the shk will pay when buying [all of] an object */ @@ -2041,46 +2102,46 @@ set_cost(obj, shkp) register struct obj *obj; register struct monst *shkp; { - long tmp = getprice(obj, TRUE) * obj->quan, - multiplier = 1L, divisor = 1L; + long tmp = getprice(obj, TRUE) * obj->quan, multiplier = 1L, divisor = 1L; - if (uarmh && uarmh->otyp == DUNCE_CAP) - divisor *= 3L; - else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2)) || - (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ - divisor *= 3L; - else - divisor *= 2L; + if (uarmh && uarmh->otyp == DUNCE_CAP) + divisor *= 3L; + else if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV / 2)) + || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ + divisor *= 3L; + else + divisor *= 2L; - /* shopkeeper may notice if the player isn't very knowledgeable - - especially when gem prices are concerned */ - if (!obj->dknown || !objects[obj->otyp].oc_name_known) { - if (obj->oclass == GEM_CLASS) { - /* different shop keepers give different prices */ - if (objects[obj->otyp].oc_material == GEMSTONE || - objects[obj->otyp].oc_material == GLASS) { - tmp = (obj->otyp % (6 - shkp->m_id % 3)); - tmp = (tmp + 3) * obj->quan; - } - } else if (tmp > 1L && !rn2(4)) - multiplier *= 3L, divisor *= 4L; - } + /* shopkeeper may notice if the player isn't very knowledgeable - + especially when gem prices are concerned */ + if (!obj->dknown || !objects[obj->otyp].oc_name_known) { + if (obj->oclass == GEM_CLASS) { + /* different shop keepers give different prices */ + if (objects[obj->otyp].oc_material == GEMSTONE + || objects[obj->otyp].oc_material == GLASS) { + tmp = (obj->otyp % (6 - shkp->m_id % 3)); + tmp = (tmp + 3) * obj->quan; + } + } else if (tmp > 1L && !rn2(4)) + multiplier *= 3L, divisor *= 4L; + } - if (tmp >= 1L) { - /* [see get_cost()] */ - tmp *= multiplier; - if (divisor > 1L) { - tmp *= 10L; - tmp /= divisor; - tmp += 5L; - tmp /= 10L; - } - /* avoid adjusting nonzero to zero */ - if (tmp < 1L) tmp = 1L; - } + if (tmp >= 1L) { + /* [see get_cost()] */ + tmp *= multiplier; + if (divisor > 1L) { + tmp *= 10L; + tmp /= divisor; + tmp += 5L; + tmp /= 10L; + } + /* avoid adjusting nonzero to zero */ + if (tmp < 1L) + tmp = 1L; + } - /* (no adjustment for angry shk here) */ - return tmp; + /* (no adjustment for angry shk here) */ + return tmp; } /* called when an item's value has been enhanced; if it happens to be @@ -2089,56 +2150,58 @@ register struct monst *shkp; void alter_cost(obj, amt) struct obj *obj; -long amt; /* if 0, use regular shop pricing, otherwise force amount; - if negative, use abs(amt) even if it's less than old cost */ +long amt; /* if 0, use regular shop pricing, otherwise force amount; + if negative, use abs(amt) even if it's less than old cost */ { struct bill_x *bp = 0; struct monst *shkp; long new_price; for (shkp = next_shkp(fmon, TRUE); shkp; shkp = next_shkp(shkp, TRUE)) - if ((bp = onbill(obj, shkp, TRUE)) != 0) { - new_price = !amt ? get_cost(obj, shkp) : (amt < 0L) ? -amt : amt; - if (new_price > bp->price || amt < 0L) { - bp->price = new_price; - update_inventory(); - } - break; /* done */ - } + if ((bp = onbill(obj, shkp, TRUE)) != 0) { + new_price = !amt ? get_cost(obj, shkp) : (amt < 0L) ? -amt : amt; + if (new_price > bp->price || amt < 0L) { + bp->price = new_price; + update_inventory(); + } + break; /* done */ + } return; } /* called from doinv(invent.c) for inventory of unpaid objects */ long unpaid_cost(unp_obj, include_contents) -struct obj *unp_obj; /* known to be unpaid or contain unpaid */ +struct obj *unp_obj; /* known to be unpaid or contain unpaid */ boolean include_contents; { - struct bill_x *bp = (struct bill_x *)0; - struct monst *shkp; - long amt = 0L; - xchar ox, oy; + struct bill_x *bp = (struct bill_x *) 0; + struct monst *shkp; + long amt = 0L; + xchar ox, oy; - if (!get_obj_location(unp_obj, &ox, &oy, BURIED_TOO|CONTAINED_TOO)) - ox = u.ux, oy = u.uy; /* (shouldn't happen) */ - if ((shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) != 0) { - bp = onbill(unp_obj, shkp, TRUE); - } else { - /* didn't find shk? try searching bills */ - for (shkp = next_shkp(fmon, TRUE); shkp; - shkp = next_shkp(shkp->nmon, TRUE)) - if ((bp = onbill(unp_obj, shkp, TRUE)) != 0) break; - } + if (!get_obj_location(unp_obj, &ox, &oy, BURIED_TOO | CONTAINED_TOO)) + ox = u.ux, oy = u.uy; /* (shouldn't happen) */ + if ((shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) != 0) { + bp = onbill(unp_obj, shkp, TRUE); + } else { + /* didn't find shk? try searching bills */ + for (shkp = next_shkp(fmon, TRUE); shkp; + shkp = next_shkp(shkp->nmon, TRUE)) + if ((bp = onbill(unp_obj, shkp, TRUE)) != 0) + break; + } - /* onbill() gave no message if unexpected problem occurred */ - if (!shkp || (unp_obj->unpaid && !bp)) { - impossible("unpaid_cost: object wasn't on any bill."); - } else { - if (bp) amt = unp_obj->quan * bp->price; - if (include_contents && Has_contents(unp_obj)) - amt = contained_cost(unp_obj, shkp, amt, FALSE, TRUE); - } - return amt; + /* onbill() gave no message if unexpected problem occurred */ + if (!shkp || (unp_obj->unpaid && !bp)) { + impossible("unpaid_cost: object wasn't on any bill."); + } else { + if (bp) + amt = unp_obj->quan * bp->price; + if (include_contents && Has_contents(unp_obj)) + amt = contained_cost(unp_obj, shkp, amt, FALSE, TRUE); + } + return amt; } STATIC_OVL void @@ -2147,40 +2210,41 @@ struct obj *obj; boolean dummy; struct monst *shkp; { - struct eshk *eshkp; - struct bill_x *bp; - int bct; + struct eshk *eshkp; + struct bill_x *bp; + int bct; - if (!billable(&shkp, obj, *u.ushops, TRUE)) return; - eshkp = ESHK(shkp); + if (!billable(&shkp, obj, *u.ushops, TRUE)) + return; + eshkp = ESHK(shkp); - if (eshkp->billct == BILLSZ) { - You("got that for free!"); - return; - } + if (eshkp->billct == BILLSZ) { + You("got that for free!"); + return; + } - bct = eshkp->billct; - bp = &(eshkp->bill_p[bct]); - bp->bo_id = obj->o_id; - bp->bquan = obj->quan; - if(dummy) { /* a dummy object must be inserted into */ - bp->useup = 1; /* the billobjs chain here. crucial for */ - add_to_billobjs(obj); /* eating floorfood in shop. see eat.c */ - } else - bp->useup = 0; - bp->price = get_cost(obj, shkp); - eshkp->billct++; - obj->unpaid = 1; + bct = eshkp->billct; + bp = &(eshkp->bill_p[bct]); + bp->bo_id = obj->o_id; + bp->bquan = obj->quan; + if (dummy) { /* a dummy object must be inserted into */ + bp->useup = 1; /* the billobjs chain here. crucial for */ + add_to_billobjs(obj); /* eating floorfood in shop. see eat.c */ + } else + bp->useup = 0; + bp->price = get_cost(obj, shkp); + eshkp->billct++; + obj->unpaid = 1; } STATIC_OVL void add_to_billobjs(obj) - struct obj *obj; +struct obj *obj; { if (obj->where != OBJ_FREE) - panic("add_to_billobjs: obj not free"); + panic("add_to_billobjs: obj not free"); if (obj->timed) - obj_stop_timers(obj); + obj_stop_timers(obj); obj->nobj = billobjs; billobjs = obj; @@ -2194,18 +2258,18 @@ register struct obj *obj; register boolean ininv, dummy; register struct monst *shkp; { - register struct obj *otmp; + register struct obj *otmp; - for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if (otmp->oclass == COIN_CLASS) continue; - - /* the "top" box is added in addtobill() */ - if (!otmp->no_charge) - add_one_tobill(otmp, dummy, shkp); - if (Has_contents(otmp)) - bill_box_content(otmp, ininv, dummy, shkp); - } + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; + /* the "top" box is added in addtobill() */ + if (!otmp->no_charge) + add_one_tobill(otmp, dummy, shkp); + if (Has_contents(otmp)) + bill_box_content(otmp, ininv, dummy, shkp); + } } /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */ @@ -2213,41 +2277,41 @@ STATIC_OVL void shk_names_obj(shkp, obj, fmt, amt, arg) struct monst *shkp; struct obj *obj; -const char *fmt; /* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */ +const char *fmt; /* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */ long amt; const char *arg; { - char *obj_name, fmtbuf[BUFSZ]; - boolean was_unknown = !obj->dknown; + char *obj_name, fmtbuf[BUFSZ]; + boolean was_unknown = !obj->dknown; - obj->dknown = TRUE; - /* Use real name for ordinary weapons/armor, and spell-less - * scrolls/books (that is, blank and mail), but only if the - * object is within the shk's area of interest/expertise. - */ - if (!objects[obj->otyp].oc_magic && saleable(shkp, obj) && - (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS || - obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS || - obj->otyp == MIRROR)) { - was_unknown |= !objects[obj->otyp].oc_name_known; - makeknown(obj->otyp); - } - obj_name = doname(obj); - /* Use an alternate message when extra information is being provided */ - if (was_unknown) { - Sprintf(fmtbuf, "%%s; you %s", fmt); - obj_name[0] = highc(obj_name[0]); - pline(fmtbuf, obj_name, (obj->quan > 1L) ? "them" : "it", - amt, plur(amt), arg); - } else { - You(fmt, obj_name, amt, plur(amt), arg); - } + obj->dknown = TRUE; + /* Use real name for ordinary weapons/armor, and spell-less + * scrolls/books (that is, blank and mail), but only if the + * object is within the shk's area of interest/expertise. + */ + if (!objects[obj->otyp].oc_magic && saleable(shkp, obj) + && (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS + || obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS + || obj->otyp == MIRROR)) { + was_unknown |= !objects[obj->otyp].oc_name_known; + makeknown(obj->otyp); + } + obj_name = doname(obj); + /* Use an alternate message when extra information is being provided */ + if (was_unknown) { + Sprintf(fmtbuf, "%%s; you %s", fmt); + obj_name[0] = highc(obj_name[0]); + pline(fmtbuf, obj_name, (obj->quan > 1L) ? "them" : "it", amt, + plur(amt), arg); + } else { + You(fmt, obj_name, amt, plur(amt), arg); + } } /* decide whether a shopkeeper thinks an item belongs to her */ boolean billable(shkpp, obj, roomno, reset_nocharge) -struct monst **shkpp; /* in: non-null if shk has been validated; out: shk */ +struct monst **shkpp; /* in: non-null if shk has been validated; out: shk */ struct obj *obj; char roomno; boolean reset_nocharge; @@ -2256,26 +2320,29 @@ boolean reset_nocharge; /* if caller hasn't supplied a shopkeeper, look one up now */ if (!shkp) { - if (!roomno) return FALSE; - shkp = shop_keeper(roomno); - if (!shkp || !inhishop(shkp)) return FALSE; - *shkpp = shkp; + if (!roomno) + return FALSE; + shkp = shop_keeper(roomno); + if (!shkp || !inhishop(shkp)) + return FALSE; + *shkpp = shkp; } /* perhaps we threw it away earlier */ - if (onbill(obj, shkp, FALSE) || - (obj->oclass == FOOD_CLASS && obj->oeaten)) - return FALSE; + if (onbill(obj, shkp, FALSE) + || (obj->oclass == FOOD_CLASS && obj->oeaten)) + return FALSE; /* outer container might be marked no_charge but still have contents which should be charged for; clear no_charge when picking things up */ if (obj->no_charge) { - if (!Has_contents(obj) || - (contained_gold(obj) == 0L && - contained_cost(obj, shkp, 0L, FALSE, !reset_nocharge) == 0L)) - shkp = 0; /* not billable */ - if (reset_nocharge && !shkp && obj->oclass != COIN_CLASS) { - obj->no_charge = 0; - if (Has_contents(obj)) picked_container(obj); /* clear no_charge */ - } + if (!Has_contents(obj) || (contained_gold(obj) == 0L + && contained_cost(obj, shkp, 0L, FALSE, + !reset_nocharge) == 0L)) + shkp = 0; /* not billable */ + if (reset_nocharge && !shkp && obj->oclass != COIN_CLASS) { + obj->no_charge = 0; + if (Has_contents(obj)) + picked_container(obj); /* clear no_charge */ + } } return shkp ? TRUE : FALSE; } @@ -2285,98 +2352,99 @@ addtobill(obj, ininv, dummy, silent) struct obj *obj; boolean ininv, dummy, silent; { - struct monst *shkp = 0; - long ltmp, cltmp, gltmp; - int contentscount; - boolean container; + struct monst *shkp = 0; + long ltmp, cltmp, gltmp; + int contentscount; + boolean container; - if (!billable(&shkp, obj, *u.ushops, TRUE)) - return; + if (!billable(&shkp, obj, *u.ushops, TRUE)) + return; - if (obj->oclass == COIN_CLASS) { - costly_gold(obj->ox, obj->oy, obj->quan); - return; - } else if (ESHK(shkp)->billct == BILLSZ) { - if (!silent) You("got that for free!"); - return; - } + if (obj->oclass == COIN_CLASS) { + costly_gold(obj->ox, obj->oy, obj->quan); + return; + } else if (ESHK(shkp)->billct == BILLSZ) { + if (!silent) + You("got that for free!"); + return; + } - ltmp = cltmp = gltmp = 0L; - container = Has_contents(obj); + ltmp = cltmp = gltmp = 0L; + container = Has_contents(obj); - if(!obj->no_charge) - ltmp = get_cost(obj, shkp); + if (!obj->no_charge) + ltmp = get_cost(obj, shkp); - if (obj->no_charge && !container) { - obj->no_charge = 0; - return; - } + if (obj->no_charge && !container) { + obj->no_charge = 0; + return; + } - if(container) { - cltmp = contained_cost(obj, shkp, cltmp, FALSE, FALSE); - gltmp = contained_gold(obj); + if (container) { + cltmp = contained_cost(obj, shkp, cltmp, FALSE, FALSE); + gltmp = contained_gold(obj); - if(ltmp) add_one_tobill(obj, dummy, shkp); - if(cltmp) bill_box_content(obj, ininv, dummy, shkp); - picked_container(obj); /* reset contained obj->no_charge */ + if (ltmp) + add_one_tobill(obj, dummy, shkp); + if (cltmp) + bill_box_content(obj, ininv, dummy, shkp); + picked_container(obj); /* reset contained obj->no_charge */ - ltmp += cltmp; + ltmp += cltmp; - if(gltmp) { - costly_gold(obj->ox, obj->oy, gltmp); - if(!ltmp) return; - } + if (gltmp) { + costly_gold(obj->ox, obj->oy, gltmp); + if (!ltmp) + return; + } - if(obj->no_charge) - obj->no_charge = 0; - contentscount = count_unpaid(obj->cobj); - } else { /* !container */ - add_one_tobill(obj, dummy, shkp); - contentscount = 0; - } + if (obj->no_charge) + obj->no_charge = 0; + contentscount = count_unpaid(obj->cobj); + } else { /* !container */ + add_one_tobill(obj, dummy, shkp); + contentscount = 0; + } - if (!muteshk(shkp) && !silent) { - char buf[BUFSZ]; + if (!muteshk(shkp) && !silent) { + char buf[BUFSZ]; - if(!ltmp) { - pline("%s has no interest in %s.", Monnam(shkp), - the(xname(obj))); - return; - } - if (!ininv) { - pline("%s will cost you %ld %s%s.", - The(xname(obj)), ltmp, currency(ltmp), - (obj->quan > 1L) ? " each" : ""); - } else { - long save_quan = obj->quan; + if (!ltmp) { + pline("%s has no interest in %s.", Monnam(shkp), the(xname(obj))); + return; + } + if (!ininv) { + pline("%s will cost you %ld %s%s.", The(xname(obj)), ltmp, + currency(ltmp), (obj->quan > 1L) ? " each" : ""); + } else { + long save_quan = obj->quan; - Strcpy(buf, "\"For you, "); - if (ANGRY(shkp)) { - Strcat(buf, "scum;"); - } else { - append_honorific(buf); - Strcat(buf, "; only"); - } - obj->quan = 1L; /* fool xname() into giving singular */ - pline("%s %ld %s %s %s%s.\"", buf, ltmp, currency(ltmp), - (save_quan > 1L) ? "per" : - (contentscount && !obj->unpaid) ? - "for the contents of this" : "for this", - xname(obj), (contentscount && obj->unpaid) ? - and_its_contents : ""); - obj->quan = save_quan; - } - } else if(!silent) { - if (ltmp) pline_The("list price of %s%s%s is %ld %s%s.", - (contentscount && !obj->unpaid) ? - the_contents_of : "", - the(xname(obj)), - (contentscount && obj->unpaid) ? - and_its_contents : "", - ltmp, currency(ltmp), - (obj->quan > 1L) ? " each" : ""); - else pline("%s does not notice.", Monnam(shkp)); - } + Strcpy(buf, "\"For you, "); + if (ANGRY(shkp)) { + Strcat(buf, "scum;"); + } else { + append_honorific(buf); + Strcat(buf, "; only"); + } + obj->quan = 1L; /* fool xname() into giving singular */ + pline("%s %ld %s %s %s%s.\"", buf, ltmp, currency(ltmp), + (save_quan > 1L) ? "per" : (contentscount && !obj->unpaid) + ? "for the contents of this" + : "for this", + xname(obj), + (contentscount && obj->unpaid) ? and_its_contents : ""); + obj->quan = save_quan; + } + } else if (!silent) { + if (ltmp) + pline_The("list price of %s%s%s is %ld %s%s.", + (contentscount && !obj->unpaid) ? the_contents_of : "", + the(xname(obj)), + (contentscount && obj->unpaid) ? and_its_contents : "", + ltmp, currency(ltmp), (obj->quan > 1L) ? " each" : ""); + else + pline("%s does not notice.", Monnam(shkp)); + } } void @@ -2385,56 +2453,57 @@ char *buf; { /* (chooses among [0]..[3] normally; [1]..[4] after the Wizard has been killed or invocation ritual performed) */ - static const char * const honored[] = { - "good", "honored", "most gracious", "esteemed", - "most renowned and sacred" - }; + static const char *const honored[] = { "good", "honored", "most gracious", + "esteemed", + "most renowned and sacred" }; Strcat(buf, honored[rn2(SIZE(honored) - 1) + u.uevent.udemigod]); if (is_vampire(youmonst.data)) - Strcat(buf, (flags.female) ? " dark lady" : " dark lord"); + Strcat(buf, (flags.female) ? " dark lady" : " dark lord"); else if (is_elf(youmonst.data)) - Strcat(buf,(flags.female) ? " hiril" : " hir"); + Strcat(buf, (flags.female) ? " hiril" : " hir"); else - Strcat(buf, !is_human(youmonst.data) ? " creature" : - (flags.female) ? " lady" : " sir"); + Strcat(buf, !is_human(youmonst.data) ? " creature" : (flags.female) + ? " lady" + : " sir"); } void splitbill(obj, otmp) register struct obj *obj, *otmp; { - /* otmp has been split off from obj */ - register struct bill_x *bp; - register long tmp; - register struct monst *shkp = shop_keeper(*u.ushops); + /* otmp has been split off from obj */ + register struct bill_x *bp; + register long tmp; + register struct monst *shkp = shop_keeper(*u.ushops); - if(!shkp || !inhishop(shkp)) { - impossible("splitbill: no resident shopkeeper??"); - return; - } - bp = onbill(obj, shkp, FALSE); - if(!bp) { - impossible("splitbill: not on bill?"); - return; - } - if(bp->bquan < otmp->quan) { - impossible("Negative quantity on bill??"); - } - if(bp->bquan == otmp->quan) { - impossible("Zero quantity on bill??"); - } - bp->bquan -= otmp->quan; + if (!shkp || !inhishop(shkp)) { + impossible("splitbill: no resident shopkeeper??"); + return; + } + bp = onbill(obj, shkp, FALSE); + if (!bp) { + impossible("splitbill: not on bill?"); + return; + } + if (bp->bquan < otmp->quan) { + impossible("Negative quantity on bill??"); + } + if (bp->bquan == otmp->quan) { + impossible("Zero quantity on bill??"); + } + bp->bquan -= otmp->quan; - if(ESHK(shkp)->billct == BILLSZ) otmp->unpaid = 0; - else { - tmp = bp->price; - bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]); - bp->bo_id = otmp->o_id; - bp->bquan = otmp->quan; - bp->useup = 0; - bp->price = tmp; - ESHK(shkp)->billct++; - } + if (ESHK(shkp)->billct == BILLSZ) + otmp->unpaid = 0; + else { + tmp = bp->price; + bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]); + bp->bo_id = otmp->o_id; + bp->bquan = otmp->quan; + bp->useup = 0; + bp->price = tmp; + ESHK(shkp)->billct++; + } } STATIC_OVL void @@ -2442,39 +2511,39 @@ sub_one_frombill(obj, shkp) register struct obj *obj; register struct monst *shkp; { - register struct bill_x *bp; + register struct bill_x *bp; - if((bp = onbill(obj, shkp, FALSE)) != 0) { - register struct obj *otmp; + if ((bp = onbill(obj, shkp, FALSE)) != 0) { + register struct obj *otmp; - obj->unpaid = 0; - if(bp->bquan > obj->quan){ - otmp = newobj(); - *otmp = *obj; - otmp->oextra = (struct oextra *)0; - bp->bo_id = otmp->o_id = context.ident++; - otmp->where = OBJ_FREE; - otmp->quan = (bp->bquan -= obj->quan); - otmp->owt = 0; /* superfluous */ - bp->useup = 1; - add_to_billobjs(otmp); - return; - } - ESHK(shkp)->billct--; + obj->unpaid = 0; + if (bp->bquan > obj->quan) { + otmp = newobj(); + *otmp = *obj; + otmp->oextra = (struct oextra *) 0; + bp->bo_id = otmp->o_id = context.ident++; + otmp->where = OBJ_FREE; + otmp->quan = (bp->bquan -= obj->quan); + otmp->owt = 0; /* superfluous */ + bp->useup = 1; + add_to_billobjs(otmp); + return; + } + ESHK(shkp)->billct--; #ifdef DUMB - { - /* DRS/NS 2.2.6 messes up -- Peter Kendell */ - int indx = ESHK(shkp)->billct; - *bp = ESHK(shkp)->bill_p[indx]; - } + { + /* DRS/NS 2.2.6 messes up -- Peter Kendell */ + int indx = ESHK(shkp)->billct; + *bp = ESHK(shkp)->bill_p[indx]; + } #else - *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; + *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; #endif - return; - } else if (obj->unpaid) { - impossible("sub_one_frombill: unpaid object not on bill"); - obj->unpaid = 0; - } + return; + } else if (obj->unpaid) { + impossible("sub_one_frombill: unpaid object not on bill"); + obj->unpaid = 0; + } } /* recursive check of unpaid objects within nested containers. */ @@ -2483,19 +2552,20 @@ subfrombill(obj, shkp) register struct obj *obj; register struct monst *shkp; { - register struct obj *otmp; + register struct obj *otmp; - sub_one_frombill(obj, shkp); + sub_one_frombill(obj, shkp); - if (Has_contents(obj)) - for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if(otmp->oclass == COIN_CLASS) continue; + if (Has_contents(obj)) + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; - if (Has_contents(otmp)) - subfrombill(otmp, shkp); - else - sub_one_frombill(otmp, shkp); - } + if (Has_contents(otmp)) + subfrombill(otmp, shkp); + else + sub_one_frombill(otmp, shkp); + } } STATIC_OVL long @@ -2505,35 +2575,37 @@ struct monst *shkp; long price; boolean ininv; { - struct obj *otmp; - struct bill_x *bp; - long billamt; + struct obj *otmp; + struct bill_x *bp; + long billamt; - /* the price of contained objects; caller handles top container */ - for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { - if (otmp->oclass == COIN_CLASS) continue; - billamt = 0L; - if (!billable(&shkp, otmp, ESHK(shkp)->shoproom, TRUE)) { - /* billable() returns false for objects already on bill */ - if ((bp = onbill(otmp, shkp, FALSE)) == 0) continue; - /* this assumes that we're being called by stolen_value() - (or by a recursive call to self on behalf of it) where - the cost of this object is about to be added to shop - debt in place of having it remain on the current bill */ - billamt = bp->bquan * bp->price; - sub_one_frombill(otmp, shkp); /* avoid double billing */ - } + /* the price of contained objects; caller handles top container */ + for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { + if (otmp->oclass == COIN_CLASS) + continue; + billamt = 0L; + if (!billable(&shkp, otmp, ESHK(shkp)->shoproom, TRUE)) { + /* billable() returns false for objects already on bill */ + if ((bp = onbill(otmp, shkp, FALSE)) == 0) + continue; + /* this assumes that we're being called by stolen_value() + (or by a recursive call to self on behalf of it) where + the cost of this object is about to be added to shop + debt in place of having it remain on the current bill */ + billamt = bp->bquan * bp->price; + sub_one_frombill(otmp, shkp); /* avoid double billing */ + } - if (billamt) - price += billamt; - else if (ininv ? otmp->unpaid : !otmp->no_charge) - price += otmp->quan * get_cost(otmp, shkp); + if (billamt) + price += billamt; + else if (ininv ? otmp->unpaid : !otmp->no_charge) + price += otmp->quan * get_cost(otmp, shkp); - if (Has_contents(otmp)) - price = stolen_container(otmp, shkp, price, ininv); - } + if (Has_contents(otmp)) + price = stolen_container(otmp, shkp, price, ininv); + } - return(price); + return (price); } long @@ -2542,87 +2614,90 @@ struct obj *obj; xchar x, y; boolean peaceful, silent; { - long value = 0L, gvalue = 0L, billamt = 0L; - char roomno = *in_rooms(x, y, SHOPBASE); - struct bill_x *bp; - struct monst *shkp = 0; + long value = 0L, gvalue = 0L, billamt = 0L; + char roomno = *in_rooms(x, y, SHOPBASE); + struct bill_x *bp; + struct monst *shkp = 0; - if (!billable(&shkp, obj, roomno, FALSE)) { - /* things already on the bill yield a not-billable result, so - we need to check bill before deciding that shk doesn't care */ - if ((bp = onbill(obj, shkp, FALSE)) == 0) return 0L; - /* shk does care; take obj off bill to avoid double billing */ - billamt = bp->bquan * bp->price; - sub_one_frombill(obj, shkp); - } + if (!billable(&shkp, obj, roomno, FALSE)) { + /* things already on the bill yield a not-billable result, so + we need to check bill before deciding that shk doesn't care */ + if ((bp = onbill(obj, shkp, FALSE)) == 0) + return 0L; + /* shk does care; take obj off bill to avoid double billing */ + billamt = bp->bquan * bp->price; + sub_one_frombill(obj, shkp); + } - if(obj->oclass == COIN_CLASS) { - gvalue += obj->quan; - } else { - if (billamt) - value += billamt; - else if (!obj->no_charge) - value += obj->quan * get_cost(obj, shkp); + if (obj->oclass == COIN_CLASS) { + gvalue += obj->quan; + } else { + if (billamt) + value += billamt; + else if (!obj->no_charge) + value += obj->quan * get_cost(obj, shkp); - if (Has_contents(obj)) { - boolean ininv = (obj->where == OBJ_INVENT || - obj->where == OBJ_FREE); + if (Has_contents(obj)) { + boolean ininv = + (obj->where == OBJ_INVENT || obj->where == OBJ_FREE); - value += stolen_container(obj, shkp, 0L, ininv); - if(!ininv) gvalue += contained_gold(obj); - } - } + value += stolen_container(obj, shkp, 0L, ininv); + if (!ininv) + gvalue += contained_gold(obj); + } + } - if(gvalue + value == 0L) return(0L); + if (gvalue + value == 0L) + return (0L); - value += gvalue; + value += gvalue; - if(peaceful) { - boolean credit_use = !!ESHK(shkp)->credit; - value = check_credit(value, shkp); - /* 'peaceful' affects general treatment, but doesn't affect - * the fact that other code expects that all charges after the - * shopkeeper is angry are included in robbed, not debit */ - if (ANGRY(shkp)) - ESHK(shkp)->robbed += value; - else - ESHK(shkp)->debit += value; + if (peaceful) { + boolean credit_use = !!ESHK(shkp)->credit; + value = check_credit(value, shkp); + /* 'peaceful' affects general treatment, but doesn't affect + * the fact that other code expects that all charges after the + * shopkeeper is angry are included in robbed, not debit */ + if (ANGRY(shkp)) + ESHK(shkp)->robbed += value; + else + ESHK(shkp)->debit += value; - if(!silent) { - const char *still = ""; + if (!silent) { + const char *still = ""; - if (credit_use) { - if (ESHK(shkp)->credit) { - You("have %ld %s credit remaining.", - ESHK(shkp)->credit, currency(ESHK(shkp)->credit)); - return value; - } else if (!value) { - You("have no credit remaining."); - return 0; - } - still = "still "; - } - if(obj->oclass == COIN_CLASS) - You("%sowe %s %ld %s!", still, - mon_nam(shkp), value, currency(value)); - else - You("%sowe %s %ld %s for %s!", still, - mon_nam(shkp), value, currency(value), - obj->quan > 1L ? "them" : "it"); - } - } else { - ESHK(shkp)->robbed += value; + if (credit_use) { + if (ESHK(shkp)->credit) { + You("have %ld %s credit remaining.", ESHK(shkp)->credit, + currency(ESHK(shkp)->credit)); + return value; + } else if (!value) { + You("have no credit remaining."); + return 0; + } + still = "still "; + } + if (obj->oclass == COIN_CLASS) + You("%sowe %s %ld %s!", still, mon_nam(shkp), value, + currency(value)); + else + You("%sowe %s %ld %s for %s!", still, mon_nam(shkp), value, + currency(value), obj->quan > 1L ? "them" : "it"); + } + } else { + ESHK(shkp)->robbed += value; - if(!silent) { - if(cansee(shkp->mx, shkp->my)) { - Norep("%s booms: \"%s, you are a thief!\"", - Monnam(shkp), plname); - } else Norep("You hear a scream, \"Thief!\""); - } - hot_pursuit(shkp); - (void) angry_guards(FALSE); - } - return(value); + if (!silent) { + if (cansee(shkp->mx, shkp->my)) { + Norep("%s booms: \"%s, you are a thief!\"", Monnam(shkp), + plname); + } else + Norep("You hear a scream, \"Thief!\""); + } + hot_pursuit(shkp); + (void) angry_guards(FALSE); + } + return (value); } /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */ @@ -2636,15 +2711,15 @@ void sellobj_state(deliberate) int deliberate; { - /* If we're deliberately dropping something, there's no automatic - response to the shopkeeper's "want to sell" query; however, if we - accidentally drop anything, the shk will buy it/them without asking. - This retains the old pre-query risk that slippery fingers while in - shops entailed: you drop it, you've lost it. - */ - sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a'; - sell_how = deliberate; - auto_credit = FALSE; + /* If we're deliberately dropping something, there's no automatic + response to the shopkeeper's "want to sell" query; however, if we + accidentally drop anything, the shk will buy it/them without asking. + This retains the old pre-query risk that slippery fingers while in + shops entailed: you drop it, you've lost it. + */ + sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a'; + sell_how = deliberate; + auto_credit = FALSE; } void @@ -2652,367 +2727,393 @@ sellobj(obj, x, y) register struct obj *obj; xchar x, y; { - register struct monst *shkp; - register struct eshk *eshkp; - long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer, shkmoney; - boolean saleitem, cgold = FALSE, container = Has_contents(obj); - boolean isgold = (obj->oclass == COIN_CLASS); - boolean only_partially_your_contents = FALSE; + register struct monst *shkp; + register struct eshk *eshkp; + long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer, shkmoney; + boolean saleitem, cgold = FALSE, container = Has_contents(obj); + boolean isgold = (obj->oclass == COIN_CLASS); + boolean only_partially_your_contents = FALSE; - if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || - !inhishop(shkp)) return; - if(!costly_spot(x, y)) return; - if(!*u.ushops) return; + if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) + return; + if (!costly_spot(x, y)) + return; + if (!*u.ushops) + return; - if(obj->unpaid && !container && !isgold) { - sub_one_frombill(obj, shkp); - return; - } - if(container) { - /* find the price of content before subfrombill */ - cltmp = contained_cost(obj, shkp, cltmp, TRUE, FALSE); - /* find the value of contained gold */ - gltmp += contained_gold(obj); - cgold = (gltmp > 0L); - } + if (obj->unpaid && !container && !isgold) { + sub_one_frombill(obj, shkp); + return; + } + if (container) { + /* find the price of content before subfrombill */ + cltmp = contained_cost(obj, shkp, cltmp, TRUE, FALSE); + /* find the value of contained gold */ + gltmp += contained_gold(obj); + cgold = (gltmp > 0L); + } - saleitem = saleable(shkp, obj); - if(!isgold && !obj->unpaid && saleitem) - ltmp = set_cost(obj, shkp); + saleitem = saleable(shkp, obj); + if (!isgold && !obj->unpaid && saleitem) + ltmp = set_cost(obj, shkp); - offer = ltmp + cltmp; + offer = ltmp + cltmp; - /* get one case out of the way: nothing to sell, and no gold */ - if (!isgold && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) { - boolean unpaid = is_unpaid(obj); + /* get one case out of the way: nothing to sell, and no gold */ + if (!isgold && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) { + boolean unpaid = is_unpaid(obj); - if(container) { - dropped_container(obj, shkp, FALSE); - if(!obj->unpaid && !saleitem) - obj->no_charge = 1; - if (unpaid) - subfrombill(obj, shkp); - } else obj->no_charge = 1; + if (container) { + dropped_container(obj, shkp, FALSE); + if (!obj->unpaid && !saleitem) + obj->no_charge = 1; + if (unpaid) + subfrombill(obj, shkp); + } else + obj->no_charge = 1; - if(!unpaid && (sell_how != SELL_DONTSELL) && - !special_stock(obj, shkp, FALSE)) - pline("%s seems uninterested.", Monnam(shkp)); - return; - } + if (!unpaid && (sell_how != SELL_DONTSELL) + && !special_stock(obj, shkp, FALSE)) + pline("%s seems uninterested.", Monnam(shkp)); + return; + } - /* you dropped something of your own - probably want to sell it */ - rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */ - eshkp = ESHK(shkp); + /* you dropped something of your own - probably want to sell it */ + rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */ + eshkp = ESHK(shkp); - if (ANGRY(shkp)) { /* they become shop-objects, no pay */ - if (!muteshk(shkp)) - verbalize("Thank you, scum!"); - subfrombill(obj, shkp); - return; - } + if (ANGRY(shkp)) { /* they become shop-objects, no pay */ + if (!muteshk(shkp)) + verbalize("Thank you, scum!"); + subfrombill(obj, shkp); + return; + } - if(eshkp->robbed) { /* shkp is not angry? */ - if(isgold) offer = obj->quan; - else if(cgold) offer += cgold; - if((eshkp->robbed -= offer < 0L)) - eshkp->robbed = 0L; - if (offer && !muteshk(shkp)) - verbalize( - "Thank you for your contribution to restock this recently plundered shop."); - subfrombill(obj, shkp); - return; - } + if (eshkp->robbed) { /* shkp is not angry? */ + if (isgold) + offer = obj->quan; + else if (cgold) + offer += cgold; + if ((eshkp->robbed -= offer < 0L)) + eshkp->robbed = 0L; + if (offer && !muteshk(shkp)) + verbalize("Thank you for your contribution to restock this " + "recently plundered shop."); + subfrombill(obj, shkp); + return; + } - if(isgold || cgold) { - if(!cgold) gltmp = obj->quan; + if (isgold || cgold) { + if (!cgold) + gltmp = obj->quan; - if(eshkp->debit >= gltmp) { - if(eshkp->loan) { /* you carry shop's gold */ - if(eshkp->loan >= gltmp) - eshkp->loan -= gltmp; - else eshkp->loan = 0L; - } - eshkp->debit -= gltmp; - Your("debt is %spaid off.", - eshkp->debit ? "partially " : ""); - } else { - long delta = gltmp - eshkp->debit; + if (eshkp->debit >= gltmp) { + if (eshkp->loan) { /* you carry shop's gold */ + if (eshkp->loan >= gltmp) + eshkp->loan -= gltmp; + else + eshkp->loan = 0L; + } + eshkp->debit -= gltmp; + Your("debt is %spaid off.", eshkp->debit ? "partially " : ""); + } else { + long delta = gltmp - eshkp->debit; - eshkp->credit += delta; - if(eshkp->debit) { - eshkp->debit = 0L; - eshkp->loan = 0L; - Your("debt is paid off."); - } - if (eshkp->credit == delta) - You("have established %ld %s credit.", - delta, currency(delta)); - else - pline("%ld %s added to your credit; total is now %ld %s.", - delta, currency(delta), - eshkp->credit, currency(eshkp->credit)); - } + eshkp->credit += delta; + if (eshkp->debit) { + eshkp->debit = 0L; + eshkp->loan = 0L; + Your("debt is paid off."); + } + if (eshkp->credit == delta) + You("have established %ld %s credit.", delta, + currency(delta)); + else + pline("%ld %s added to your credit; total is now %ld %s.", + delta, currency(delta), eshkp->credit, + currency(eshkp->credit)); + } - if (!offer) { - if(!isgold) { - if (container) - dropped_container(obj, shkp, FALSE); - if (!obj->unpaid && !saleitem) obj->no_charge = 1; - subfrombill(obj, shkp); - } - return; - } - } + if (!offer) { + if (!isgold) { + if (container) + dropped_container(obj, shkp, FALSE); + if (!obj->unpaid && !saleitem) + obj->no_charge = 1; + subfrombill(obj, shkp); + } + return; + } + } - if((!saleitem && !(container && cltmp > 0L)) - || eshkp->billct == BILLSZ - || obj->oclass == BALL_CLASS - || obj->oclass == CHAIN_CLASS || offer == 0L - || (obj->oclass == FOOD_CLASS && obj->oeaten) - || (Is_candle(obj) && - obj->age < 20L * (long)objects[obj->otyp].oc_cost)) { - pline("%s seems uninterested%s.", Monnam(shkp), - cgold ? " in the rest" : ""); - if (container) - dropped_container(obj, shkp, FALSE); - obj->no_charge = 1; - return; - } - - shkmoney = money_cnt(shkp->minvent); - if (!shkmoney) { - char c, qbuf[BUFSZ]; - long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L); + if ((!saleitem && !(container && cltmp > 0L)) || eshkp->billct == BILLSZ + || obj->oclass == BALL_CLASS || obj->oclass == CHAIN_CLASS + || offer == 0L || (obj->oclass == FOOD_CLASS && obj->oeaten) + || (Is_candle(obj) + && obj->age < 20L * (long) objects[obj->otyp].oc_cost)) { + pline("%s seems uninterested%s.", Monnam(shkp), + cgold ? " in the rest" : ""); + if (container) + dropped_container(obj, shkp, FALSE); + obj->no_charge = 1; + return; + } - if (sell_how == SELL_NORMAL || auto_credit) { - c = sell_response = 'y'; - } else if (sell_response != 'n') { - pline("%s cannot pay you at present.", shkname(shkp)); - Sprintf(qbuf, "Will you accept %ld %s in credit for ", - tmpcr, currency(tmpcr)); - c = ynaq(safe_qbuf(qbuf, qbuf, "?", - obj, doname, thesimpleoname, - (obj->quan == 1L) ? "that" : "those")); - if (c == 'a') { - c = 'y'; - auto_credit = TRUE; - } - } else /* previously specified "quit" */ - c = 'n'; + shkmoney = money_cnt(shkp->minvent); + if (!shkmoney) { + char c, qbuf[BUFSZ]; + long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L); - if (c == 'y') { - shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ? - "traded %s for %ld zorkmid%s in %scredit." : - "relinquish %s and acquire %ld zorkmid%s in %scredit.", - tmpcr, - (eshkp->credit > 0L) ? "additional " : ""); - eshkp->credit += tmpcr; - subfrombill(obj, shkp); - } else { - if (c == 'q') sell_response = 'n'; - if (container) - dropped_container(obj, shkp, FALSE); - if (!obj->unpaid) obj->no_charge = 1; - subfrombill(obj, shkp); - } - } else { - char qbuf[BUFSZ], qsfx[BUFSZ]; - boolean short_funds = (offer > shkmoney), one; + if (sell_how == SELL_NORMAL || auto_credit) { + c = sell_response = 'y'; + } else if (sell_response != 'n') { + pline("%s cannot pay you at present.", shkname(shkp)); + Sprintf(qbuf, "Will you accept %ld %s in credit for ", tmpcr, + currency(tmpcr)); + c = ynaq(safe_qbuf(qbuf, qbuf, "?", obj, doname, thesimpleoname, + (obj->quan == 1L) ? "that" : "those")); + if (c == 'a') { + c = 'y'; + auto_credit = TRUE; + } + } else /* previously specified "quit" */ + c = 'n'; - if (short_funds) offer = shkmoney; - if (!sell_response) { - long yourc = 0L, shksc; + if (c == 'y') { + shk_names_obj( + shkp, obj, + (sell_how != SELL_NORMAL) + ? "traded %s for %ld zorkmid%s in %scredit." + : "relinquish %s and acquire %ld zorkmid%s in %scredit.", + tmpcr, (eshkp->credit > 0L) ? "additional " : ""); + eshkp->credit += tmpcr; + subfrombill(obj, shkp); + } else { + if (c == 'q') + sell_response = 'n'; + if (container) + dropped_container(obj, shkp, FALSE); + if (!obj->unpaid) + obj->no_charge = 1; + subfrombill(obj, shkp); + } + } else { + char qbuf[BUFSZ], qsfx[BUFSZ]; + boolean short_funds = (offer > shkmoney), one; - if (container) { - /* number of items owned by shk */ - shksc = count_contents(obj, TRUE, TRUE, FALSE); - /* number of items owned by you (total - shksc) */ - yourc = count_contents(obj, TRUE, TRUE, TRUE) - shksc; - only_partially_your_contents = shksc && yourc; - } - /* - " offers * for ..." query formatting. - Normal item(s): - "... your . Sell it?" - "... your . Sell them?" - A container is either owned by the hero, or already - owned by the shk (!ltmp), or the shk isn't interested - in buying it (also !ltmp). It's either empty (!cltmp) - or it has contents owned by the hero or it has some - contents owned by the hero and others by the shk. - (The case where it has contents already entirely owned - by the shk is treated the same was if it were empty - since the hero isn't selling any of those contents.) - Your container: - "... your . Sell it?" - "... your and its contents. Sell them?" - "... your and item inside. Sell them?" - "... your and items inside. Sell them?" - Shk's container: - "... your item in the . Sell it?" - "... your items in the . Sell them?" - */ - Sprintf(qbuf, "%s offers%s %ld gold piece%s for %s%s ", - shkname(shkp), short_funds ? " only" : "", - offer, plur(offer), - (cltmp && !ltmp) ? - ((yourc == 1L) ? "your item in " : - "your items in ") : "", - obj->unpaid ? "the" : "your"); - one = obj->unpaid ? (yourc == 1L) : - (obj->quan == 1L && !cltmp); - Sprintf(qsfx, "%s. Sell %s?", - (cltmp && ltmp) ? (only_partially_your_contents ? - ((yourc == 1L) ? " and item inside" : - " and items inside") : - and_its_contents) : "", - one ? "it" : "them"); - (void)safe_qbuf(qbuf, qbuf, qsfx, - obj, xname, simpleonames, - one ? "that" : "those"); - } else qbuf[0] = '\0'; /* just to pacify lint */ + if (short_funds) + offer = shkmoney; + if (!sell_response) { + long yourc = 0L, shksc; - switch (sell_response ? sell_response : ynaq(qbuf)) { - case 'q': sell_response = 'n'; - case 'n': if (container) - dropped_container(obj, shkp, FALSE); - if (!obj->unpaid) obj->no_charge = 1; - subfrombill(obj, shkp); - break; - case 'a': sell_response = 'y'; - case 'y': if (container) - dropped_container(obj, shkp, TRUE); - if (!obj->unpaid && !saleitem) obj->no_charge = 1; - subfrombill(obj, shkp); - pay(-offer, shkp); - shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ? - (!ltmp && cltmp && only_partially_your_contents) ? - "sold some items inside %s for %ld gold piece%s.%s" : - "sold %s for %ld gold piece%s.%s" : - "relinquish %s and receive %ld gold piece%s in compensation.%s", - offer, ""); - break; - default: impossible("invalid sell response"); - } - } + if (container) { + /* number of items owned by shk */ + shksc = count_contents(obj, TRUE, TRUE, FALSE); + /* number of items owned by you (total - shksc) */ + yourc = count_contents(obj, TRUE, TRUE, TRUE) - shksc; + only_partially_your_contents = shksc && yourc; + } + /* + " offers * for ..." query formatting. + Normal item(s): + "... your . Sell it?" + "... your . Sell them?" + A container is either owned by the hero, or already + owned by the shk (!ltmp), or the shk isn't interested + in buying it (also !ltmp). It's either empty (!cltmp) + or it has contents owned by the hero or it has some + contents owned by the hero and others by the shk. + (The case where it has contents already entirely owned + by the shk is treated the same was if it were empty + since the hero isn't selling any of those contents.) + Your container: + "... your . Sell it?" + "... your and its contents. Sell them?" + "... your and item inside. Sell them?" + "... your and items inside. Sell them?" + Shk's container: + "... your item in the . Sell it?" + "... your items in the . Sell them?" + */ + Sprintf(qbuf, "%s offers%s %ld gold piece%s for %s%s ", + shkname(shkp), short_funds ? " only" : "", offer, + plur(offer), + (cltmp && !ltmp) + ? ((yourc == 1L) ? "your item in " : "your items in ") + : "", + obj->unpaid ? "the" : "your"); + one = obj->unpaid ? (yourc == 1L) : (obj->quan == 1L && !cltmp); + Sprintf(qsfx, "%s. Sell %s?", + (cltmp && ltmp) + ? (only_partially_your_contents + ? ((yourc == 1L) ? " and item inside" + : " and items inside") + : and_its_contents) + : "", + one ? "it" : "them"); + (void) safe_qbuf(qbuf, qbuf, qsfx, obj, xname, simpleonames, + one ? "that" : "those"); + } else + qbuf[0] = '\0'; /* just to pacify lint */ + + switch (sell_response ? sell_response : ynaq(qbuf)) { + case 'q': + sell_response = 'n'; + case 'n': + if (container) + dropped_container(obj, shkp, FALSE); + if (!obj->unpaid) + obj->no_charge = 1; + subfrombill(obj, shkp); + break; + case 'a': + sell_response = 'y'; + case 'y': + if (container) + dropped_container(obj, shkp, TRUE); + if (!obj->unpaid && !saleitem) + obj->no_charge = 1; + subfrombill(obj, shkp); + pay(-offer, shkp); + shk_names_obj( + shkp, obj, + (sell_how != SELL_NORMAL) + ? (!ltmp && cltmp && only_partially_your_contents) + ? "sold some items inside %s for %ld gold " + "piece%s.%s" + : "sold %s for %ld gold piece%s.%s" + : "relinquish %s and receive %ld gold piece%s in " + "compensation.%s", + offer, ""); + break; + default: + impossible("invalid sell response"); + } + } } int doinvbill(mode) -int mode; /* 0: deliver count 1: paged */ +int mode; /* 0: deliver count 1: paged */ { -#ifdef __SASC - void sasc_bug(struct obj *, unsigned); +#ifdef __SASC + void sasc_bug(struct obj *, unsigned); #endif - struct monst *shkp; - struct eshk *eshkp; - struct bill_x *bp, *end_bp; - struct obj *obj; - long totused; - char *buf_p; - winid datawin; + struct monst *shkp; + struct eshk *eshkp; + struct bill_x *bp, *end_bp; + struct obj *obj; + long totused; + char *buf_p; + winid datawin; - shkp = shop_keeper(*u.ushops); - if (!shkp || !inhishop(shkp)) { - if (mode != 0) impossible("doinvbill: no shopkeeper?"); - return 0; - } - eshkp = ESHK(shkp); + shkp = shop_keeper(*u.ushops); + if (!shkp || !inhishop(shkp)) { + if (mode != 0) + impossible("doinvbill: no shopkeeper?"); + return 0; + } + eshkp = ESHK(shkp); - if (mode == 0) { - /* count expended items, so that the `I' command can decide - whether to include 'x' in its prompt string */ - int cnt = !eshkp->debit ? 0 : 1; + if (mode == 0) { + /* count expended items, so that the `I' command can decide + whether to include 'x' in its prompt string */ + int cnt = !eshkp->debit ? 0 : 1; - for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; - bp < end_bp; bp++) - if (bp->useup || - ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan)) - cnt++; - return cnt; - } + for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; + bp < end_bp; bp++) + if (bp->useup + || ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan)) + cnt++; + return cnt; + } - datawin = create_nhwindow(NHW_MENU); - putstr(datawin, 0, "Unpaid articles already used up:"); - putstr(datawin, 0, ""); + datawin = create_nhwindow(NHW_MENU); + putstr(datawin, 0, "Unpaid articles already used up:"); + putstr(datawin, 0, ""); - totused = 0L; - for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; - bp < end_bp; bp++) { - obj = bp_to_obj(bp); - if(!obj) { - impossible("Bad shopkeeper administration."); - goto quit; - } - if(bp->useup || bp->bquan > obj->quan) { - long oquan, uquan, thisused; + totused = 0L; + for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; + bp < end_bp; bp++) { + obj = bp_to_obj(bp); + if (!obj) { + impossible("Bad shopkeeper administration."); + goto quit; + } + if (bp->useup || bp->bquan > obj->quan) { + long oquan, uquan, thisused; - oquan = obj->quan; - uquan = (bp->useup ? bp->bquan : bp->bquan - oquan); - thisused = bp->price * uquan; - totused += thisused; - iflags.suppress_price++; /* suppress "(unpaid)" suffix */ - /* Why 'x'? To match `I x', more or less. */ - buf_p = xprname(obj, (char *)0, 'x', FALSE, thisused, uquan); - iflags.suppress_price--; - putstr(datawin, 0, buf_p); - } - } - if (eshkp->debit) { - /* additional shop debt which has no itemization available */ - if (totused) putstr(datawin, 0, ""); - totused += eshkp->debit; - buf_p = xprname((struct obj *)0, - "usage charges and/or other fees", - GOLD_SYM, FALSE, eshkp->debit, 0L); - putstr(datawin, 0, buf_p); - } - buf_p = xprname((struct obj *)0, "Total:", '*', FALSE, totused, 0L); - putstr(datawin, 0, ""); - putstr(datawin, 0, buf_p); - display_nhwindow(datawin, FALSE); - quit: - destroy_nhwindow(datawin); - return(0); + oquan = obj->quan; + uquan = (bp->useup ? bp->bquan : bp->bquan - oquan); + thisused = bp->price * uquan; + totused += thisused; + iflags.suppress_price++; /* suppress "(unpaid)" suffix */ + /* Why 'x'? To match `I x', more or less. */ + buf_p = xprname(obj, (char *) 0, 'x', FALSE, thisused, uquan); + iflags.suppress_price--; + putstr(datawin, 0, buf_p); + } + } + if (eshkp->debit) { + /* additional shop debt which has no itemization available */ + if (totused) + putstr(datawin, 0, ""); + totused += eshkp->debit; + buf_p = xprname((struct obj *) 0, "usage charges and/or other fees", + GOLD_SYM, FALSE, eshkp->debit, 0L); + putstr(datawin, 0, buf_p); + } + buf_p = xprname((struct obj *) 0, "Total:", '*', FALSE, totused, 0L); + putstr(datawin, 0, ""); + putstr(datawin, 0, buf_p); + display_nhwindow(datawin, FALSE); +quit: + destroy_nhwindow(datawin); + return (0); } -#define HUNGRY 2 +#define HUNGRY 2 STATIC_OVL long getprice(obj, shk_buying) register struct obj *obj; boolean shk_buying; { - register long tmp = (long) objects[obj->otyp].oc_cost; + register long tmp = (long) objects[obj->otyp].oc_cost; - if (obj->oartifact) { - tmp = arti_cost(obj); - if (shk_buying) tmp /= 4; - } - switch(obj->oclass) { - case FOOD_CLASS: - /* simpler hunger check, (2-4)*cost */ - if (u.uhs >= HUNGRY && !shk_buying) tmp *= (long) u.uhs; - if (obj->oeaten) tmp = 0L; - break; - case WAND_CLASS: - if (obj->spe == -1) tmp = 0L; - break; - case POTION_CLASS: - if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed) - tmp = 0L; - break; - case ARMOR_CLASS: - case WEAPON_CLASS: - if (obj->spe > 0) tmp += 10L * (long) obj->spe; - break; - case TOOL_CLASS: - if (Is_candle(obj) && - obj->age < 20L * (long)objects[obj->otyp].oc_cost) - tmp /= 2L; - break; - } - return tmp; + if (obj->oartifact) { + tmp = arti_cost(obj); + if (shk_buying) + tmp /= 4; + } + switch (obj->oclass) { + case FOOD_CLASS: + /* simpler hunger check, (2-4)*cost */ + if (u.uhs >= HUNGRY && !shk_buying) + tmp *= (long) u.uhs; + if (obj->oeaten) + tmp = 0L; + break; + case WAND_CLASS: + if (obj->spe == -1) + tmp = 0L; + break; + case POTION_CLASS: + if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed) + tmp = 0L; + break; + case ARMOR_CLASS: + case WEAPON_CLASS: + if (obj->spe > 0) + tmp += 10L * (long) obj->spe; + break; + case TOOL_CLASS: + if (Is_candle(obj) + && obj->age < 20L * (long) objects[obj->otyp].oc_cost) + tmp /= 2L; + break; + } + return tmp; } /* shk catches thrown pick-axe */ @@ -3021,33 +3122,32 @@ shkcatch(obj, x, y) register struct obj *obj; register xchar x, y; { - register struct monst *shkp; + register struct monst *shkp; - if (!(shkp = shop_keeper(inside_shop(x, y))) || - !inhishop(shkp)) return(0); + if (!(shkp = shop_keeper(inside_shop(x, y))) || !inhishop(shkp)) + return (0); - if (shkp->mcanmove && !shkp->msleeping && - (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy)) && - dist2(shkp->mx, shkp->my, x, y) < 3 && - /* if it is the shk's pos, you hit and anger him */ - (shkp->mx != x || shkp->my != y)) { - if (mnearto(shkp, x, y, TRUE) && !muteshk(shkp)) - verbalize("Out of my way, scum!"); - if (cansee(x, y)) { - pline("%s nimbly%s catches %s.", - Monnam(shkp), - (x == shkp->mx && y == shkp->my) ? "" : " reaches over and", - the(xname(obj))); - if (!canspotmon(shkp)) - map_invisible(x, y); - delay_output(); - mark_synch(); - } - subfrombill(obj, shkp); - (void) mpickobj(shkp, obj); - return shkp; - } - return (struct monst *)0; + if (shkp->mcanmove && !shkp->msleeping + && (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy)) + && dist2(shkp->mx, shkp->my, x, y) < 3 && + /* if it is the shk's pos, you hit and anger him */ + (shkp->mx != x || shkp->my != y)) { + if (mnearto(shkp, x, y, TRUE) && !muteshk(shkp)) + verbalize("Out of my way, scum!"); + if (cansee(x, y)) { + pline("%s nimbly%s catches %s.", Monnam(shkp), + (x == shkp->mx && y == shkp->my) ? "" : " reaches over and", + the(xname(obj))); + if (!canspotmon(shkp)) + map_invisible(x, y); + delay_output(); + mark_synch(); + } + subfrombill(obj, shkp); + (void) mpickobj(shkp, obj); + return shkp; + } + return (struct monst *) 0; } void @@ -3055,35 +3155,36 @@ add_damage(x, y, cost) register xchar x, y; long cost; { - struct damage *tmp_dam; - char *shops; + struct damage *tmp_dam; + char *shops; - if (IS_DOOR(levl[x][y].typ)) { - struct monst *mtmp; + if (IS_DOOR(levl[x][y].typ)) { + struct monst *mtmp; - /* Don't schedule for repair unless it's a real shop entrance */ - for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++) - if ((mtmp = shop_keeper(*shops)) != 0 && - x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y) - break; - if (!*shops) return; - } - for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) - if (tmp_dam->place.x == x && tmp_dam->place.y == y) { - tmp_dam->cost += cost; - return; - } - tmp_dam = (struct damage *)alloc((unsigned)sizeof(struct damage)); - tmp_dam->when = monstermoves; - tmp_dam->place.x = x; - tmp_dam->place.y = y; - tmp_dam->cost = cost; - tmp_dam->typ = levl[x][y].typ; - tmp_dam->next = level.damagelist; - level.damagelist = tmp_dam; - /* If player saw damage, display as a wall forever */ - if (cansee(x, y)) - levl[x][y].seenv = SVALL; + /* Don't schedule for repair unless it's a real shop entrance */ + for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++) + if ((mtmp = shop_keeper(*shops)) != 0 && x == ESHK(mtmp)->shd.x + && y == ESHK(mtmp)->shd.y) + break; + if (!*shops) + return; + } + for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) + if (tmp_dam->place.x == x && tmp_dam->place.y == y) { + tmp_dam->cost += cost; + return; + } + tmp_dam = (struct damage *) alloc((unsigned) sizeof(struct damage)); + tmp_dam->when = monstermoves; + tmp_dam->place.x = x; + tmp_dam->place.y = y; + tmp_dam->cost = cost; + tmp_dam->typ = levl[x][y].typ; + tmp_dam->next = level.damagelist; + level.damagelist = tmp_dam; + /* If player saw damage, display as a wall forever */ + if (cansee(x, y)) + levl[x][y].seenv = SVALL; } /* @@ -3100,117 +3201,117 @@ remove_damage(shkp, croaked) struct monst *shkp; boolean croaked; { - struct damage *tmp_dam, *tmp2_dam; - boolean did_repair = FALSE, saw_door = FALSE, - saw_floor = FALSE, stop_picking = FALSE, - doorway_trap = FALSE; - int saw_walls = 0, saw_untrap = 0; - char trapmsg[BUFSZ]; + struct damage *tmp_dam, *tmp2_dam; + boolean did_repair = FALSE, saw_door = FALSE, saw_floor = FALSE, + stop_picking = FALSE, doorway_trap = FALSE; + int saw_walls = 0, saw_untrap = 0; + char trapmsg[BUFSZ]; - tmp_dam = level.damagelist; - tmp2_dam = 0; - while (tmp_dam) { - register xchar x = tmp_dam->place.x, y = tmp_dam->place.y; - char shops[5]; - int disposition; - unsigned old_doormask = 0; + tmp_dam = level.damagelist; + tmp2_dam = 0; + while (tmp_dam) { + register xchar x = tmp_dam->place.x, y = tmp_dam->place.y; + char shops[5]; + int disposition; + unsigned old_doormask = 0; - disposition = 0; - Strcpy(shops, in_rooms(x, y, SHOPBASE)); - if (index(shops, ESHK(shkp)->shoproom)) { - if (IS_DOOR(levl[x][y].typ)) old_doormask = levl[x][y].doormask; + disposition = 0; + Strcpy(shops, in_rooms(x, y, SHOPBASE)); + if (index(shops, ESHK(shkp)->shoproom)) { + if (IS_DOOR(levl[x][y].typ)) + old_doormask = levl[x][y].doormask; - if (croaked) - disposition = (shops[1])? 0 : 1; - else if (stop_picking) - disposition = repair_damage(shkp, tmp_dam, FALSE); - else { - /* Defer the stop_occupation() until after repair msgs */ - if (closed_door(x, y)) - stop_picking = picking_at(x, y); - disposition = repair_damage(shkp, tmp_dam, FALSE); - if (!disposition) - stop_picking = FALSE; - } - } + if (croaked) + disposition = (shops[1]) ? 0 : 1; + else if (stop_picking) + disposition = repair_damage(shkp, tmp_dam, FALSE); + else { + /* Defer the stop_occupation() until after repair msgs */ + if (closed_door(x, y)) + stop_picking = picking_at(x, y); + disposition = repair_damage(shkp, tmp_dam, FALSE); + if (!disposition) + stop_picking = FALSE; + } + } - if (!disposition) { - tmp2_dam = tmp_dam; - tmp_dam = tmp_dam->next; - continue; - } + if (!disposition) { + tmp2_dam = tmp_dam; + tmp_dam = tmp_dam->next; + continue; + } - if (disposition > 1) { - did_repair = TRUE; - if (cansee(x, y)) { - if (IS_WALL(levl[x][y].typ)) { - saw_walls++; - } else if (IS_DOOR(levl[x][y].typ) && - /* an existing door here implies trap removal */ - !(old_doormask & (D_ISOPEN|D_CLOSED))) { - saw_door = TRUE; - } else if (disposition == 3) { /* untrapped */ - saw_untrap++; - if (IS_DOOR(levl[x][y].typ)) doorway_trap = TRUE; - } else { - saw_floor = TRUE; - } - } - } + if (disposition > 1) { + did_repair = TRUE; + if (cansee(x, y)) { + if (IS_WALL(levl[x][y].typ)) { + saw_walls++; + } else if (IS_DOOR(levl[x][y].typ) && + /* an existing door here implies trap removal */ + !(old_doormask & (D_ISOPEN | D_CLOSED))) { + saw_door = TRUE; + } else if (disposition == 3) { /* untrapped */ + saw_untrap++; + if (IS_DOOR(levl[x][y].typ)) + doorway_trap = TRUE; + } else { + saw_floor = TRUE; + } + } + } - tmp_dam = tmp_dam->next; - if (!tmp2_dam) { - free((genericptr_t)level.damagelist); - level.damagelist = tmp_dam; - } else { - free((genericptr_t)tmp2_dam->next); - tmp2_dam->next = tmp_dam; - } - } - if (!did_repair) - return; + tmp_dam = tmp_dam->next; + if (!tmp2_dam) { + free((genericptr_t) level.damagelist); + level.damagelist = tmp_dam; + } else { + free((genericptr_t) tmp2_dam->next); + tmp2_dam->next = tmp_dam; + } + } + if (!did_repair) + return; - if (saw_untrap) { - Sprintf(trapmsg, "%s trap%s", - (saw_untrap > 3) ? "several" : - (saw_untrap > 1) ? "some" : "a", - plur(saw_untrap)); - Sprintf(eos(trapmsg), " %s", vtense(trapmsg, "are")); - Sprintf(eos(trapmsg), " removed from the %s", - (doorway_trap && saw_untrap == 1) ? "doorway" : "floor"); - } else - trapmsg[0] = '\0'; /* not just lint suppression... */ + if (saw_untrap) { + Sprintf(trapmsg, "%s trap%s", + (saw_untrap > 3) ? "several" : (saw_untrap > 1) ? "some" + : "a", + plur(saw_untrap)); + Sprintf(eos(trapmsg), " %s", vtense(trapmsg, "are")); + Sprintf(eos(trapmsg), " removed from the %s", + (doorway_trap && saw_untrap == 1) ? "doorway" : "floor"); + } else + trapmsg[0] = '\0'; /* not just lint suppression... */ - if (saw_walls) { - char wallbuf[BUFSZ]; + if (saw_walls) { + char wallbuf[BUFSZ]; - Sprintf(wallbuf, "section%s", plur(saw_walls)); - pline("Suddenly, %s %s of wall %s up!", - (saw_walls == 1) ? "a" : (saw_walls <= 3) ? - "some" : "several", - wallbuf, vtense(wallbuf, "close")); + Sprintf(wallbuf, "section%s", plur(saw_walls)); + pline("Suddenly, %s %s of wall %s up!", + (saw_walls == 1) ? "a" : (saw_walls <= 3) ? "some" : "several", + wallbuf, vtense(wallbuf, "close")); - if (saw_door) - pline_The("shop door reappears!"); - if (saw_floor) - pline_The("floor is repaired!"); - if (saw_untrap) - pline("%s!", upstart(trapmsg)); - } else { - if (saw_door || saw_floor || saw_untrap) - pline("Suddenly, %s%s%s%s%s!", - saw_door ? "the shop door reappears" : "", - (saw_door && saw_floor) ? " and " : "", - saw_floor ? "the floor damage is gone" : "", - ((saw_door || saw_floor) && *trapmsg) ? " and " : "", - trapmsg); - else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom) - You_feel("more claustrophobic than before."); - else if (!Deaf && !rn2(10)) - Norep("The dungeon acoustics noticeably change."); - } - if (stop_picking) - stop_occupation(); + if (saw_door) + pline_The("shop door reappears!"); + if (saw_floor) + pline_The("floor is repaired!"); + if (saw_untrap) + pline("%s!", upstart(trapmsg)); + } else { + if (saw_door || saw_floor || saw_untrap) + pline("Suddenly, %s%s%s%s%s!", + saw_door ? "the shop door reappears" : "", + (saw_door && saw_floor) ? " and " : "", + saw_floor ? "the floor damage is gone" : "", + ((saw_door || saw_floor) && *trapmsg) ? " and " : "", + trapmsg); + else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom) + You_feel("more claustrophobic than before."); + else if (!Deaf && !rn2(10)) + Norep("The dungeon acoustics noticeably change."); + } + if (stop_picking) + stop_occupation(); } /* @@ -3221,125 +3322,126 @@ int repair_damage(shkp, tmp_dam, catchup) register struct monst *shkp; register struct damage *tmp_dam; -boolean catchup; /* restoring a level */ +boolean catchup; /* restoring a level */ { - register xchar x, y, i; - xchar litter[9]; - register struct monst *mtmp; - register struct obj *otmp; - register struct trap *ttmp; + register xchar x, y, i; + xchar litter[9]; + register struct monst *mtmp; + register struct obj *otmp; + register struct trap *ttmp; - if ((monstermoves - tmp_dam->when) < REPAIR_DELAY) - return(0); - if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following) - return(0); - x = tmp_dam->place.x; - y = tmp_dam->place.y; - if (!IS_ROOM(tmp_dam->typ)) { - if (x == u.ux && y == u.uy) - if (!Passes_walls) - return(0); - if (x == shkp->mx && y == shkp->my) - return(0); - if ((mtmp = m_at(x, y)) && (!passes_walls(mtmp->data))) - return(0); - } - if ((ttmp = t_at(x, y)) != 0) { - if (x == u.ux && y == u.uy) - if (!Passes_walls) - return(0); - if (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP) { - /* convert to an object */ - otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE : - BEARTRAP, TRUE, FALSE); - otmp->quan= 1L; - otmp->owt = weight(otmp); - (void) mpickobj(shkp, otmp); - } - deltrap(ttmp); - if (IS_DOOR(tmp_dam->typ) && - !(levl[x][y].doormask & D_ISOPEN)) { - levl[x][y].doormask = D_CLOSED; - block_point(x, y); - } else if (IS_WALL(tmp_dam->typ)) { - levl[x][y].typ = tmp_dam->typ; - block_point(x, y); - } - newsym(x, y); - return(3); - } - if (IS_ROOM(tmp_dam->typ)) { - /* No messages, because player already filled trap door */ - return(1); - } - if ((tmp_dam->typ == levl[x][y].typ) && - (!IS_DOOR(tmp_dam->typ) || (levl[x][y].doormask > D_BROKEN))) - /* No messages if player already replaced shop door */ - return(1); - levl[x][y].typ = tmp_dam->typ; - (void) memset((genericptr_t)litter, 0, sizeof(litter)); - if ((otmp = level.objects[x][y]) != 0) { - /* Scatter objects haphazardly into the shop */ + if ((monstermoves - tmp_dam->when) < REPAIR_DELAY) + return (0); + if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following) + return (0); + x = tmp_dam->place.x; + y = tmp_dam->place.y; + if (!IS_ROOM(tmp_dam->typ)) { + if (x == u.ux && y == u.uy) + if (!Passes_walls) + return (0); + if (x == shkp->mx && y == shkp->my) + return (0); + if ((mtmp = m_at(x, y)) && (!passes_walls(mtmp->data))) + return (0); + } + if ((ttmp = t_at(x, y)) != 0) { + if (x == u.ux && y == u.uy) + if (!Passes_walls) + return (0); + if (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP) { + /* convert to an object */ + otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP, + TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + (void) mpickobj(shkp, otmp); + } + deltrap(ttmp); + if (IS_DOOR(tmp_dam->typ) && !(levl[x][y].doormask & D_ISOPEN)) { + levl[x][y].doormask = D_CLOSED; + block_point(x, y); + } else if (IS_WALL(tmp_dam->typ)) { + levl[x][y].typ = tmp_dam->typ; + block_point(x, y); + } + newsym(x, y); + return (3); + } + if (IS_ROOM(tmp_dam->typ)) { + /* No messages, because player already filled trap door */ + return (1); + } + if ((tmp_dam->typ == levl[x][y].typ) + && (!IS_DOOR(tmp_dam->typ) || (levl[x][y].doormask > D_BROKEN))) + /* No messages if player already replaced shop door */ + return (1); + levl[x][y].typ = tmp_dam->typ; + (void) memset((genericptr_t) litter, 0, sizeof(litter)); + if ((otmp = level.objects[x][y]) != 0) { +/* Scatter objects haphazardly into the shop */ #define NEED_UPDATE 1 -#define OPEN 2 -#define INSHOP 4 -#define horiz(i) ((i%3)-1) -#define vert(i) ((i/3)-1) - for (i = 0; i < 9; i++) { - if ((i == 4) || (!ZAP_POS(levl[x+horiz(i)][y+vert(i)].typ))) - continue; - litter[i] = OPEN; - if (inside_shop(x+horiz(i), - y+vert(i)) == ESHK(shkp)->shoproom) - litter[i] |= INSHOP; - } - if (Punished && !u.uswallow && - ((uchain->ox == x && uchain->oy == y) || - (uball->ox == x && uball->oy == y))) { - /* - * Either the ball or chain is in the repair location. - * - * Take the easy way out and put ball&chain under hero. - */ - if (!muteshk(shkp)) - verbalize("Get your junk out of my wall!"); - unplacebc(); /* pick 'em up */ - placebc(); /* put 'em down */ - } - while ((otmp = level.objects[x][y]) != 0) - /* Don't mess w/ boulders -- just merge into wall */ - if ((otmp->otyp == BOULDER) || (otmp->otyp == ROCK)) { - obj_extract_self(otmp); - obfree(otmp, (struct obj *)0); - } else { - while (!(litter[i = rn2(9)] & INSHOP)); - remove_object(otmp); - place_object(otmp, x+horiz(i), y+vert(i)); - litter[i] |= NEED_UPDATE; - } - } - if (catchup) return 1; /* repair occurred while off level */ +#define OPEN 2 +#define INSHOP 4 +#define horiz(i) ((i % 3) - 1) +#define vert(i) ((i / 3) - 1) + for (i = 0; i < 9; i++) { + if ((i == 4) || (!ZAP_POS(levl[x + horiz(i)][y + vert(i)].typ))) + continue; + litter[i] = OPEN; + if (inside_shop(x + horiz(i), y + vert(i)) + == ESHK(shkp)->shoproom) + litter[i] |= INSHOP; + } + if (Punished && !u.uswallow + && ((uchain->ox == x && uchain->oy == y) + || (uball->ox == x && uball->oy == y))) { + /* + * Either the ball or chain is in the repair location. + * + * Take the easy way out and put ball&chain under hero. + */ + if (!muteshk(shkp)) + verbalize("Get your junk out of my wall!"); + unplacebc(); /* pick 'em up */ + placebc(); /* put 'em down */ + } + while ((otmp = level.objects[x][y]) != 0) + /* Don't mess w/ boulders -- just merge into wall */ + if ((otmp->otyp == BOULDER) || (otmp->otyp == ROCK)) { + obj_extract_self(otmp); + obfree(otmp, (struct obj *) 0); + } else { + while (!(litter[i = rn2(9)] & INSHOP)) + ; + remove_object(otmp); + place_object(otmp, x + horiz(i), y + vert(i)); + litter[i] |= NEED_UPDATE; + } + } + if (catchup) + return 1; /* repair occurred while off level */ - block_point(x, y); - if(IS_DOOR(tmp_dam->typ)) { - levl[x][y].doormask = D_CLOSED; /* arbitrary */ - newsym(x, y); - } else { - /* don't set doormask - it is (hopefully) the same as it was */ - /* if not, perhaps save it with the damage array... */ + block_point(x, y); + if (IS_DOOR(tmp_dam->typ)) { + levl[x][y].doormask = D_CLOSED; /* arbitrary */ + newsym(x, y); + } else { + /* don't set doormask - it is (hopefully) the same as it was */ + /* if not, perhaps save it with the damage array... */ - if (IS_WALL(tmp_dam->typ) && cansee(x, y)) { - /* Player sees actual repair process, so they KNOW it's a wall */ - levl[x][y].seenv = SVALL; - newsym(x, y); - } - /* Mark this wall as "repaired". There currently is no code */ - /* to do anything about repaired walls, so don't do it. */ - } - for (i = 0; i < 9; i++) - if (litter[i] & NEED_UPDATE) - newsym(x+horiz(i), y+vert(i)); - return(2); + if (IS_WALL(tmp_dam->typ) && cansee(x, y)) { + /* Player sees actual repair process, so they KNOW it's a wall */ + levl[x][y].seenv = SVALL; + newsym(x, y); + } + /* Mark this wall as "repaired". There currently is no code */ + /* to do anything about repaired walls, so don't do it. */ + } + for (i = 0; i < 9; i++) + if (litter[i] & NEED_UPDATE) + newsym(x + horiz(i), y + vert(i)); + return (2); #undef NEED_UPDATE #undef OPEN #undef INSHOP @@ -3354,122 +3456,124 @@ int shk_move(shkp) register struct monst *shkp; { - register xchar gx,gy,omx,omy; - register int udist; - register schar appr; - register struct eshk *eshkp = ESHK(shkp); - int z; - boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv; + register xchar gx, gy, omx, omy; + register int udist; + register schar appr; + register struct eshk *eshkp = ESHK(shkp); + int z; + boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv; - omx = shkp->mx; - omy = shkp->my; + omx = shkp->mx; + omy = shkp->my; - if (inhishop(shkp)) - remove_damage(shkp, FALSE); + if (inhishop(shkp)) + remove_damage(shkp, FALSE); - if((udist = distu(omx,omy)) < 3 && - (shkp->data != &mons[PM_GRID_BUG] || (omx==u.ux || omy==u.uy))) { - if(ANGRY(shkp) || - (Conflict && !resist(shkp, RING_CLASS, 0, 0))) { - if(Displaced) - Your("displaced image doesn't fool %s!", - mon_nam(shkp)); - (void) mattacku(shkp); - return(0); - } - if(eshkp->following) { - if(strncmp(eshkp->customer, plname, PL_NSIZ)) { - if (!muteshk(shkp)) - verbalize("%s, %s! I was looking for %s.", - Hello(shkp), plname, eshkp->customer); - eshkp->following = 0; - return(0); - } - if(moves > followmsg+4) { - if (!muteshk(shkp)) - verbalize("%s, %s! Didn't you forget to pay?", - Hello(shkp), plname); - followmsg = moves; - if (!rn2(9)) { - pline("%s doesn't like customers who don't pay.", - Monnam(shkp)); - rile_shk(shkp); - } - } - if(udist < 2) - return(0); - } - } + if ((udist = distu(omx, omy)) < 3 && (shkp->data != &mons[PM_GRID_BUG] + || (omx == u.ux || omy == u.uy))) { + if (ANGRY(shkp) || (Conflict && !resist(shkp, RING_CLASS, 0, 0))) { + if (Displaced) + Your("displaced image doesn't fool %s!", mon_nam(shkp)); + (void) mattacku(shkp); + return (0); + } + if (eshkp->following) { + if (strncmp(eshkp->customer, plname, PL_NSIZ)) { + if (!muteshk(shkp)) + verbalize("%s, %s! I was looking for %s.", Hello(shkp), + plname, eshkp->customer); + eshkp->following = 0; + return (0); + } + if (moves > followmsg + 4) { + if (!muteshk(shkp)) + verbalize("%s, %s! Didn't you forget to pay?", + Hello(shkp), plname); + followmsg = moves; + if (!rn2(9)) { + pline("%s doesn't like customers who don't pay.", + Monnam(shkp)); + rile_shk(shkp); + } + } + if (udist < 2) + return (0); + } + } - appr = 1; - gx = eshkp->shk.x; - gy = eshkp->shk.y; - satdoor = (gx == omx && gy == omy); - if(eshkp->following || ((z = holetime()) >= 0 && z*z <= udist)){ - /* [This distance check used to apply regardless of - whether the shk was following, but that resulted in - m_move() sometimes taking the shk out of the shop if - the player had fenced him in with boulders or traps. - Such voluntary abandonment left unpaid objects in - invent, triggering billing impossibilities on the - next level once the character fell through the hole.] */ - if (udist > 4 && eshkp->following && !eshkp->billct) - return(-1); /* leave it to m_move */ - gx = u.ux; - gy = u.uy; - } else if(ANGRY(shkp)) { - /* Move towards the hero if the shopkeeper can see him. */ - if(shkp->mcansee && m_canseeu(shkp)) { - gx = u.ux; - gy = u.uy; - } - avoid = FALSE; - } else { -#define GDIST(x,y) (dist2(x,y,gx,gy)) - if (Invis || u.usteed) { - avoid = FALSE; - } else { - uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y); - if(uondoor) { - badinv = (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) || - (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) || - sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)))); - if(satdoor && badinv) - return(0); - avoid = !badinv; - } else { - avoid = (*u.ushops && distu(gx,gy) > 8); - badinv = FALSE; - } + appr = 1; + gx = eshkp->shk.x; + gy = eshkp->shk.y; + satdoor = (gx == omx && gy == omy); + if (eshkp->following || ((z = holetime()) >= 0 && z * z <= udist)) { + /* [This distance check used to apply regardless of + whether the shk was following, but that resulted in + m_move() sometimes taking the shk out of the shop if + the player had fenced him in with boulders or traps. + Such voluntary abandonment left unpaid objects in + invent, triggering billing impossibilities on the + next level once the character fell through the hole.] */ + if (udist > 4 && eshkp->following && !eshkp->billct) + return (-1); /* leave it to m_move */ + gx = u.ux; + gy = u.uy; + } else if (ANGRY(shkp)) { + /* Move towards the hero if the shopkeeper can see him. */ + if (shkp->mcansee && m_canseeu(shkp)) { + gx = u.ux; + gy = u.uy; + } + avoid = FALSE; + } else { +#define GDIST(x, y) (dist2(x, y, gx, gy)) + if (Invis || u.usteed) { + avoid = FALSE; + } else { + uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y); + if (uondoor) { + badinv = + (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) + || (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) + || sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)))); + if (satdoor && badinv) + return (0); + avoid = !badinv; + } else { + avoid = (*u.ushops && distu(gx, gy) > 8); + badinv = FALSE; + } - if(((!eshkp->robbed && !eshkp->billct && !eshkp->debit) - || avoid) && GDIST(omx,omy) < 3) { - if (!badinv && !onlineu(omx,omy)) - return(0); - if(satdoor) - appr = gx = gy = 0; - } - } - } + if (((!eshkp->robbed && !eshkp->billct && !eshkp->debit) || avoid) + && GDIST(omx, omy) < 3) { + if (!badinv && !onlineu(omx, omy)) + return (0); + if (satdoor) + appr = gx = gy = 0; + } + } + } - z = move_special(shkp,inhishop(shkp),appr,uondoor,avoid,omx,omy,gx,gy); - if (z > 0) after_shk_move(shkp); + z = move_special(shkp, inhishop(shkp), appr, uondoor, avoid, omx, omy, gx, + gy); + if (z > 0) + after_shk_move(shkp); - return z; + return z; } -/* called after shopkeeper moves, in case the move causes re-entry into shop */ +/* called after shopkeeper moves, in case the move causes re-entry into shop + */ void after_shk_move(shkp) struct monst *shkp; { - struct eshk *eshkp = ESHK(shkp); + struct eshk *eshkp = ESHK(shkp); - if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) { - /* reset bill_p, need to re-calc player's occupancy too */ - eshkp->bill_p = &eshkp->bill[0]; - check_special_room(FALSE); - } + if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) { + /* reset bill_p, need to re-calc player's occupancy too */ + eshkp->bill_p = &eshkp->bill[0]; + check_special_room(FALSE); + } } /* for use in levl_follower (mondata.c) */ @@ -3477,7 +3581,7 @@ boolean is_fshk(mtmp) register struct monst *mtmp; { - return((boolean)(mtmp->isshk && ESHK(mtmp)->following)); + return ((boolean)(mtmp->isshk && ESHK(mtmp)->following)); } /* You are digging in the shop. */ @@ -3489,45 +3593,46 @@ register int fall; int lang; const char *grabs = "grabs"; - if(!shkp) return; + if (!shkp) + return; /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */ lang = 0; if (shkp->msleeping || !shkp->mcanmove || is_silent(shkp->data)) - ; /* lang stays 0 */ + ; /* lang stays 0 */ else if (shkp->data->msound <= MS_ANIMAL) - lang = 1; + lang = 1; else if (shkp->data->msound >= MS_HUMANOID) - lang = 2; + lang = 2; - if(!inhishop(shkp)) { - if (Role_if(PM_KNIGHT)) { - You_feel("like a common thief."); - adjalign(-sgn(u.ualign.type)); - } - return; + if (!inhishop(shkp)) { + if (Role_if(PM_KNIGHT)) { + You_feel("like a common thief."); + adjalign(-sgn(u.ualign.type)); + } + return; } - if(!fall) { - if (lang == 2) { - if(u.utraptype == TT_PIT) - verbalize( - "Be careful, %s, or you might fall through the floor.", - flags.female ? "madam" : "sir"); - else - verbalize("%s, do not damage the floor here!", - flags.female ? "Madam" : "Sir"); - } - if (Role_if(PM_KNIGHT)) { - You_feel("like a common thief."); - adjalign(-sgn(u.ualign.type)); - } - } else if(!um_dist(shkp->mx, shkp->my, 5) && - !shkp->msleeping && shkp->mcanmove && - (ESHK(shkp)->billct || ESHK(shkp)->debit)) { - register struct obj *obj, *obj2; - if (nolimbs(shkp->data)) { - grabs = "knocks off"; + if (!fall) { + if (lang == 2) { + if (u.utraptype == TT_PIT) + verbalize( + "Be careful, %s, or you might fall through the floor.", + flags.female ? "madam" : "sir"); + else + verbalize("%s, do not damage the floor here!", + flags.female ? "Madam" : "Sir"); + } + if (Role_if(PM_KNIGHT)) { + You_feel("like a common thief."); + adjalign(-sgn(u.ualign.type)); + } + } else if (!um_dist(shkp->mx, shkp->my, 5) && !shkp->msleeping + && shkp->mcanmove + && (ESHK(shkp)->billct || ESHK(shkp)->debit)) { + register struct obj *obj, *obj2; + if (nolimbs(shkp->data)) { + grabs = "knocks off"; #if 0 /* This is what should happen, but for balance * reasons, it isn't currently. @@ -3538,36 +3643,37 @@ register int fall; rile_shk(shkp); return; #endif - } - if (distu(shkp->mx, shkp->my) > 2) { - mnexto(shkp); - /* for some reason the shopkeeper can't come next to you */ - if (distu(shkp->mx, shkp->my) > 2) { - if (lang == 2) - pline("%s curses you in anger and frustration!", - shkname(shkp)); - else if (lang == 1) - growl(shkp); - rile_shk(shkp); - return; - } else - pline("%s %s, and %s your backpack!", - shkname(shkp), - makeplural(locomotion(shkp->data,"leap")), grabs); - } else - pline("%s %s your backpack!", shkname(shkp), grabs); + } + if (distu(shkp->mx, shkp->my) > 2) { + mnexto(shkp); + /* for some reason the shopkeeper can't come next to you */ + if (distu(shkp->mx, shkp->my) > 2) { + if (lang == 2) + pline("%s curses you in anger and frustration!", + shkname(shkp)); + else if (lang == 1) + growl(shkp); + rile_shk(shkp); + return; + } else + pline("%s %s, and %s your backpack!", shkname(shkp), + makeplural(locomotion(shkp->data, "leap")), grabs); + } else + pline("%s %s your backpack!", shkname(shkp), grabs); - for(obj = invent; obj; obj = obj2) { - obj2 = obj->nobj; - if ((obj->owornmask & ~(W_SWAPWEP|W_QUIVER)) != 0 || - (obj == uswapwep && u.twoweap) || - (obj->otyp == LEASH && obj->leashmon)) continue; - if (obj == current_wand) continue; - setnotworn(obj); - freeinv(obj); - subfrombill(obj, shkp); - (void) add_to_minv(shkp, obj); /* may free obj */ - } + for (obj = invent; obj; obj = obj2) { + obj2 = obj->nobj; + if ((obj->owornmask & ~(W_SWAPWEP | W_QUIVER)) != 0 + || (obj == uswapwep && u.twoweap) + || (obj->otyp == LEASH && obj->leashmon)) + continue; + if (obj == current_wand) + continue; + setnotworn(obj); + freeinv(obj); + subfrombill(obj, shkp); + (void) add_to_minv(shkp, obj); /* may free obj */ + } } } @@ -3575,25 +3681,26 @@ STATIC_OVL void makekops(mm) coord *mm; { - static const short k_mndx[4] = { - PM_KEYSTONE_KOP, PM_KOP_SERGEANT, PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN - }; - int k_cnt[4], cnt, mndx, k; + static const short k_mndx[4] = { PM_KEYSTONE_KOP, PM_KOP_SERGEANT, + PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN }; + int k_cnt[4], cnt, mndx, k; - k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5); - k_cnt[1] = (cnt / 3) + 1; /* at least one sarge */ - k_cnt[2] = (cnt / 6); /* maybe a lieutenant */ - k_cnt[3] = (cnt / 9); /* and maybe a kaptain */ + k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5); + k_cnt[1] = (cnt / 3) + 1; /* at least one sarge */ + k_cnt[2] = (cnt / 6); /* maybe a lieutenant */ + k_cnt[3] = (cnt / 9); /* and maybe a kaptain */ - for (k = 0; k < 4; k++) { - if ((cnt = k_cnt[k]) == 0) break; - mndx = k_mndx[k]; - if (mvitals[mndx].mvflags & G_GONE) continue; + for (k = 0; k < 4; k++) { + if ((cnt = k_cnt[k]) == 0) + break; + mndx = k_mndx[k]; + if (mvitals[mndx].mvflags & G_GONE) + continue; - while (cnt--) - if (enexto(mm, mm->x, mm->y, &mons[mndx])) - (void) makemon(&mons[mndx], mm->x, mm->y, NO_MM_FLAGS); - } + while (cnt--) + if (enexto(mm, mm->x, mm->y, &mons[mndx])) + (void) makemon(&mons[mndx], mm->x, mm->y, NO_MM_FLAGS); + } } void @@ -3601,161 +3708,162 @@ pay_for_damage(dmgstr, cant_mollify) const char *dmgstr; boolean cant_mollify; { - register struct monst *shkp = (struct monst *)0; - char shops_affected[5]; - register boolean uinshp = (*u.ushops != '\0'); - char qbuf[80]; - register xchar x, y; - boolean dugwall = !strcmp(dmgstr, "dig into") || /* wand */ - !strcmp(dmgstr, "damage"); /* pick-axe */ - boolean animal, pursue; - struct damage *tmp_dam, *appear_here = 0; - /* any number >= (80*80)+(24*24) would do, actually */ - long cost_of_damage = 0L; - unsigned int nearest_shk = 7000, nearest_damage = 7000; - int picks = 0; + register struct monst *shkp = (struct monst *) 0; + char shops_affected[5]; + register boolean uinshp = (*u.ushops != '\0'); + char qbuf[80]; + register xchar x, y; + boolean dugwall = !strcmp(dmgstr, "dig into") || /* wand */ + !strcmp(dmgstr, "damage"); /* pick-axe */ + boolean animal, pursue; + struct damage *tmp_dam, *appear_here = 0; + /* any number >= (80*80)+(24*24) would do, actually */ + long cost_of_damage = 0L; + unsigned int nearest_shk = 7000, nearest_damage = 7000; + int picks = 0; - for (tmp_dam = level.damagelist; - (tmp_dam && (tmp_dam->when == monstermoves)); - tmp_dam = tmp_dam->next) { - char *shp; + for (tmp_dam = level.damagelist; + (tmp_dam && (tmp_dam->when == monstermoves)); + tmp_dam = tmp_dam->next) { + char *shp; - if (!tmp_dam->cost) - continue; - cost_of_damage += tmp_dam->cost; - Strcpy(shops_affected, - in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); - for (shp = shops_affected; *shp; shp++) { - struct monst *tmp_shk; - unsigned int shk_distance; + if (!tmp_dam->cost) + continue; + cost_of_damage += tmp_dam->cost; + Strcpy(shops_affected, + in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); + for (shp = shops_affected; *shp; shp++) { + struct monst *tmp_shk; + unsigned int shk_distance; - if (!(tmp_shk = shop_keeper(*shp))) - continue; - if (tmp_shk == shkp) { - unsigned int damage_distance = - distu(tmp_dam->place.x, tmp_dam->place.y); + if (!(tmp_shk = shop_keeper(*shp))) + continue; + if (tmp_shk == shkp) { + unsigned int damage_distance = + distu(tmp_dam->place.x, tmp_dam->place.y); - if (damage_distance < nearest_damage) { - nearest_damage = damage_distance; - appear_here = tmp_dam; - } - continue; - } - if (!inhishop(tmp_shk)) - continue; - shk_distance = distu(tmp_shk->mx, tmp_shk->my); - if (shk_distance > nearest_shk) - continue; - if ((shk_distance == nearest_shk) && picks) { - if (rn2(++picks)) - continue; - } else - picks = 1; - shkp = tmp_shk; - nearest_shk = shk_distance; - appear_here = tmp_dam; - nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y); - } - } + if (damage_distance < nearest_damage) { + nearest_damage = damage_distance; + appear_here = tmp_dam; + } + continue; + } + if (!inhishop(tmp_shk)) + continue; + shk_distance = distu(tmp_shk->mx, tmp_shk->my); + if (shk_distance > nearest_shk) + continue; + if ((shk_distance == nearest_shk) && picks) { + if (rn2(++picks)) + continue; + } else + picks = 1; + shkp = tmp_shk; + nearest_shk = shk_distance; + appear_here = tmp_dam; + nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y); + } + } - if (!cost_of_damage || !shkp) - return; + if (!cost_of_damage || !shkp) + return; - animal = (shkp->data->msound <= MS_ANIMAL); - pursue = FALSE; - x = appear_here->place.x; - y = appear_here->place.y; + animal = (shkp->data->msound <= MS_ANIMAL); + pursue = FALSE; + x = appear_here->place.x; + y = appear_here->place.y; - /* not the best introduction to the shk... */ - (void) strncpy(ESHK(shkp)->customer,plname,PL_NSIZ); + /* not the best introduction to the shk... */ + (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ); - /* if the shk is already on the war path, be sure it's all out */ - if(ANGRY(shkp) || ESHK(shkp)->following) { - hot_pursuit(shkp); - return; - } + /* if the shk is already on the war path, be sure it's all out */ + if (ANGRY(shkp) || ESHK(shkp)->following) { + hot_pursuit(shkp); + return; + } - /* if the shk is not in their shop.. */ - if(!*in_rooms(shkp->mx,shkp->my,SHOPBASE)) { - if(!cansee(shkp->mx, shkp->my)) - return; - pursue = TRUE; - goto getcad; - } + /* if the shk is not in their shop.. */ + if (!*in_rooms(shkp->mx, shkp->my, SHOPBASE)) { + if (!cansee(shkp->mx, shkp->my)) + return; + pursue = TRUE; + goto getcad; + } - if(uinshp) { - if(um_dist(shkp->mx, shkp->my, 1) && - !um_dist(shkp->mx, shkp->my, 3)) { - pline("%s leaps towards you!", shkname(shkp)); - mnexto(shkp); - } - pursue = um_dist(shkp->mx, shkp->my, 1); - if (pursue) goto getcad; - } else { - /* - * Make shkp show up at the door. Effect: If there is a monster - * in the doorway, have the hero hear the shopkeeper yell a bit, - * pause, then have the shopkeeper appear at the door, having - * yanked the hapless critter out of the way. - */ - if (MON_AT(x, y)) { - if (!Deaf && !animal) { - You_hear("an angry voice:"); - verbalize("Out of my way, scum!"); - wait_synch(); + if (uinshp) { + if (um_dist(shkp->mx, shkp->my, 1) + && !um_dist(shkp->mx, shkp->my, 3)) { + pline("%s leaps towards you!", shkname(shkp)); + mnexto(shkp); + } + pursue = um_dist(shkp->mx, shkp->my, 1); + if (pursue) + goto getcad; + } else { + /* + * Make shkp show up at the door. Effect: If there is a monster + * in the doorway, have the hero hear the shopkeeper yell a bit, + * pause, then have the shopkeeper appear at the door, having + * yanked the hapless critter out of the way. + */ + if (MON_AT(x, y)) { + if (!Deaf && !animal) { + You_hear("an angry voice:"); + verbalize("Out of my way, scum!"); + wait_synch(); #if defined(UNIX) || defined(VMS) -# if defined(SYSV) || defined(ULTRIX) || defined(VMS) - (void) -# endif - sleep(1); +#if defined(SYSV) || defined(ULTRIX) || defined(VMS) + (void) #endif - } else { - growl(shkp); - } - } - (void) mnearto(shkp, x, y, TRUE); - } + sleep(1); +#endif + } else { + growl(shkp); + } + } + (void) mnearto(shkp, x, y, TRUE); + } - if((um_dist(x, y, 1) && !uinshp) || cant_mollify || - (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage - || !rn2(50)) { - getcad: - if (muteshk(shkp)) { - if (animal && shkp->mcanmove && !shkp->msleeping) - yelp(shkp); - } else if (pursue || uinshp || !um_dist(x, y, 1)) { - verbalize("How dare you %s my %s?", dmgstr, - dugwall ? "shop" : "door"); - } else { - pline("%s shouts:", shkname(shkp)); - verbalize("Who dared %s my %s?", dmgstr, - dugwall ? "shop" : "door"); - } - hot_pursuit(shkp); - return; - } + if ((um_dist(x, y, 1) && !uinshp) || cant_mollify + || (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage + || !rn2(50)) { + getcad: + if (muteshk(shkp)) { + if (animal && shkp->mcanmove && !shkp->msleeping) + yelp(shkp); + } else if (pursue || uinshp || !um_dist(x, y, 1)) { + verbalize("How dare you %s my %s?", dmgstr, + dugwall ? "shop" : "door"); + } else { + pline("%s shouts:", shkname(shkp)); + verbalize("Who dared %s my %s?", dmgstr, + dugwall ? "shop" : "door"); + } + hot_pursuit(shkp); + return; + } - if (Invis) Your("invisibility does not fool %s!", shkname(shkp)); - Sprintf(qbuf,"%sYou did %ld %s worth of damage!%s Pay?", - !animal ? cad(TRUE) : "", cost_of_damage, - currency(cost_of_damage), !animal ? "\"" : ""); - if(yn(qbuf) != 'n') { - cost_of_damage = check_credit(cost_of_damage, shkp); - money2mon(shkp, cost_of_damage); - context.botl = 1; - pline("Mollified, %s accepts your restitution.", - shkname(shkp)); - /* move shk back to his home loc */ - home_shk(shkp, FALSE); - pacify_shk(shkp); - } else { - if (!animal) - verbalize("Oh, yes! You'll pay!"); - else - growl(shkp); - hot_pursuit(shkp); - adjalign(-sgn(u.ualign.type)); - } + if (Invis) + Your("invisibility does not fool %s!", shkname(shkp)); + Sprintf(qbuf, "%sYou did %ld %s worth of damage!%s Pay?", + !animal ? cad(TRUE) : "", cost_of_damage, + currency(cost_of_damage), !animal ? "\"" : ""); + if (yn(qbuf) != 'n') { + cost_of_damage = check_credit(cost_of_damage, shkp); + money2mon(shkp, cost_of_damage); + context.botl = 1; + pline("Mollified, %s accepts your restitution.", shkname(shkp)); + /* move shk back to his home loc */ + home_shk(shkp, FALSE); + pacify_shk(shkp); + } else { + if (!animal) + verbalize("Oh, yes! You'll pay!"); + else + growl(shkp); + hot_pursuit(shkp); + adjalign(-sgn(u.ualign.type)); + } } /* called in dokick.c when we kick an object that might be in a store */ @@ -3763,15 +3871,17 @@ boolean costly_spot(x, y) register xchar x, y; { - register struct monst *shkp; + register struct monst *shkp; - if (!level.flags.has_shop) return FALSE; - shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); - if(!shkp || !inhishop(shkp)) return(FALSE); + if (!level.flags.has_shop) + return FALSE; + shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); + if (!shkp || !inhishop(shkp)) + return (FALSE); - return((boolean)(inside_shop(x, y) && - !(x == ESHK(shkp)->shk.x && - y == ESHK(shkp)->shk.y))); + return ( + (boolean)(inside_shop(x, y) + && !(x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y))); } /* called by dotalk(sounds.c) when #chatting; returns obj if location @@ -3783,16 +3893,17 @@ register xchar x, y; register struct obj *otmp; register struct monst *shkp; - if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) - return(struct obj *)0; + if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) + return (struct obj *) 0; for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (otmp->oclass != COIN_CLASS) - break; + if (otmp->oclass != COIN_CLASS) + break; /* note: otmp might have ->no_charge set, but that's ok */ - return (otmp && costly_spot(x, y) && NOTANGRY(shkp) - && shkp->mcanmove && !shkp->msleeping) - ? otmp : (struct obj *)0; + return (otmp && costly_spot(x, y) && NOTANGRY(shkp) && shkp->mcanmove + && !shkp->msleeping) + ? otmp + : (struct obj *) 0; } /* give price quotes for all objects linked to this one (ie, on this spot) */ @@ -3812,38 +3923,40 @@ register struct obj *first_obj; putstr(tmpwin, 0, "Fine goods for sale:"); putstr(tmpwin, 0, ""); for (otmp = first_obj; otmp; otmp = otmp->nexthere) { - if (otmp->oclass == COIN_CLASS) continue; - cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L : - get_cost(otmp, (struct monst *)0); - contentsonly = !cost; - if (Has_contents(otmp)) - cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE); - if (!cost) { - Strcpy(price, "no charge"); - contentsonly = FALSE; - } else { - Sprintf(price, "%ld %s%s", cost, currency(cost), - (otmp->quan) > 1L ? " each" : ""); - } - Sprintf(buf, "%s%s, %s", - contentsonly ? the_contents_of : "", doname(otmp), price); - putstr(tmpwin, 0, buf), cnt++; + if (otmp->oclass == COIN_CLASS) + continue; + cost = (otmp->no_charge || otmp == uball || otmp == uchain) + ? 0L + : get_cost(otmp, (struct monst *) 0); + contentsonly = !cost; + if (Has_contents(otmp)) + cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE); + if (!cost) { + Strcpy(price, "no charge"); + contentsonly = FALSE; + } else { + Sprintf(price, "%ld %s%s", cost, currency(cost), + (otmp->quan) > 1L ? " each" : ""); + } + Sprintf(buf, "%s%s, %s", contentsonly ? the_contents_of : "", + doname(otmp), price); + putstr(tmpwin, 0, buf), cnt++; } if (cnt > 1) { - display_nhwindow(tmpwin, TRUE); + display_nhwindow(tmpwin, TRUE); } else if (cnt == 1) { - if (!cost) { - /* ", no charge" */ - pline("%s!", upstart(buf)); /* buf still contains the string */ - } else { - /* print cost in slightly different format, so can't reuse buf; - cost and contentsonly are already set up */ - Sprintf(buf, "%s%s", - contentsonly ? the_contents_of : "", doname(first_obj)); - pline("%s, price %ld %s%s%s", upstart(buf), - cost, currency(cost), (first_obj->quan > 1L) ? " each" : "", - contentsonly ? "." : shk_embellish(first_obj, cost)); - } + if (!cost) { + /* ", no charge" */ + pline("%s!", upstart(buf)); /* buf still contains the string */ + } else { + /* print cost in slightly different format, so can't reuse buf; + cost and contentsonly are already set up */ + Sprintf(buf, "%s%s", contentsonly ? the_contents_of : "", + doname(first_obj)); + pline("%s, price %ld %s%s%s", upstart(buf), cost, currency(cost), + (first_obj->quan > 1L) ? " each" : "", + contentsonly ? "." : shk_embellish(first_obj, cost)); + } } destroy_nhwindow(tmpwin); } @@ -3854,32 +3967,41 @@ register struct obj *itm; long cost; { if (!rn2(3)) { - register int o, choice = rn2(5); - if (choice == 0) choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3); - switch (choice) { - case 4: - if (cost < 10L) break; else o = itm->oclass; - if (o == FOOD_CLASS) return ", gourmets' delight!"; - if (objects[itm->otyp].oc_name_known - ? objects[itm->otyp].oc_magic - : (o == AMULET_CLASS || o == RING_CLASS || - o == WAND_CLASS || o == POTION_CLASS || - o == SCROLL_CLASS || o == SPBOOK_CLASS)) - return ", painstakingly developed!"; - return ", superb craftsmanship!"; - case 3: return ", finest quality."; - case 2: return ", an excellent choice."; - case 1: return ", a real bargain."; - default: break; - } + register int o, choice = rn2(5); + if (choice == 0) + choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3); + switch (choice) { + case 4: + if (cost < 10L) + break; + else + o = itm->oclass; + if (o == FOOD_CLASS) + return ", gourmets' delight!"; + if (objects[itm->otyp].oc_name_known + ? objects[itm->otyp].oc_magic + : (o == AMULET_CLASS || o == RING_CLASS || o == WAND_CLASS + || o == POTION_CLASS || o == SCROLL_CLASS + || o == SPBOOK_CLASS)) + return ", painstakingly developed!"; + return ", superb craftsmanship!"; + case 3: + return ", finest quality."; + case 2: + return ", an excellent choice."; + case 1: + return ", a real bargain."; + default: + break; + } } else if (itm->oartifact) { - return ", one of a kind!"; + return ", one of a kind!"; } return "."; } /* First 4 supplied by Ronen and Tamar, remainder by development team */ -const char *Izchak_speaks[]={ +const char *Izchak_speaks[] = { "%s says: 'These shopping malls give me a headache.'", "%s says: 'Slow down. Think clearly.'", "%s says: 'You need to take things one at a time.'", @@ -3895,75 +4017,74 @@ void shk_chat(shkp) struct monst *shkp; { - struct eshk *eshk; - long shkmoney; - if (!shkp->isshk) { - /* The monster type is shopkeeper, but this monster is - not actually a shk, which could happen if someone - wishes for a shopkeeper statue and then animates it. - (Note: shkname() would be "" in a case like this.) */ - pline("%s asks whether you've seen any untended shops recently.", - Monnam(shkp)); - /* [Perhaps we ought to check whether this conversation - is taking place inside an untended shop, but a shopless - shk can probably be expected to be rather disoriented.] */ - return; - } + struct eshk *eshk; + long shkmoney; + if (!shkp->isshk) { + /* The monster type is shopkeeper, but this monster is + not actually a shk, which could happen if someone + wishes for a shopkeeper statue and then animates it. + (Note: shkname() would be "" in a case like this.) */ + pline("%s asks whether you've seen any untended shops recently.", + Monnam(shkp)); + /* [Perhaps we ought to check whether this conversation + is taking place inside an untended shop, but a shopless + shk can probably be expected to be rather disoriented.] */ + return; + } - eshk = ESHK(shkp); - if (ANGRY(shkp)) - pline("%s mentions how much %s dislikes %s customers.", - shkname(shkp), mhe(shkp), - eshk->robbed ? "non-paying" : "rude"); - else if (eshk->following) { - if (strncmp(eshk->customer, plname, PL_NSIZ)) { - verbalize("%s %s! I was looking for %s.", - Hello(shkp), plname, eshk->customer); - eshk->following = 0; - } else { - verbalize("%s %s! Didn't you forget to pay?", - Hello(shkp), plname); - } - } else if (eshk->billct) { - register long total = addupbill(shkp) + eshk->debit; - pline("%s says that your bill comes to %ld %s.", - shkname(shkp), total, currency(total)); - } else if (eshk->debit) - pline("%s reminds you that you owe %s %ld %s.", - shkname(shkp), mhim(shkp), - eshk->debit, currency(eshk->debit)); - else if (eshk->credit) - pline("%s encourages you to use your %ld %s of credit.", - shkname(shkp), eshk->credit, currency(eshk->credit)); - else if (eshk->robbed) - pline("%s complains about a recent robbery.", shkname(shkp)); - else if ((shkmoney = money_cnt(shkp->minvent)) < 50) - pline("%s complains that business is bad.", shkname(shkp)); - else if (shkmoney > 4000) - pline("%s says that business is good.", shkname(shkp)); - else if (is_izchak(shkp, FALSE)) - pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))],shkname(shkp)); - else - pline("%s talks about the problem of shoplifters.",shkname(shkp)); + eshk = ESHK(shkp); + if (ANGRY(shkp)) + pline("%s mentions how much %s dislikes %s customers.", shkname(shkp), + mhe(shkp), eshk->robbed ? "non-paying" : "rude"); + else if (eshk->following) { + if (strncmp(eshk->customer, plname, PL_NSIZ)) { + verbalize("%s %s! I was looking for %s.", Hello(shkp), plname, + eshk->customer); + eshk->following = 0; + } else { + verbalize("%s %s! Didn't you forget to pay?", Hello(shkp), + plname); + } + } else if (eshk->billct) { + register long total = addupbill(shkp) + eshk->debit; + pline("%s says that your bill comes to %ld %s.", shkname(shkp), total, + currency(total)); + } else if (eshk->debit) + pline("%s reminds you that you owe %s %ld %s.", shkname(shkp), + mhim(shkp), eshk->debit, currency(eshk->debit)); + else if (eshk->credit) + pline("%s encourages you to use your %ld %s of credit.", + shkname(shkp), eshk->credit, currency(eshk->credit)); + else if (eshk->robbed) + pline("%s complains about a recent robbery.", shkname(shkp)); + else if ((shkmoney = money_cnt(shkp->minvent)) < 50) + pline("%s complains that business is bad.", shkname(shkp)); + else if (shkmoney > 4000) + pline("%s says that business is good.", shkname(shkp)); + else if (is_izchak(shkp, FALSE)) + pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))], shkname(shkp)); + else + pline("%s talks about the problem of shoplifters.", shkname(shkp)); } STATIC_OVL void kops_gone(silent) register boolean silent; { - register int cnt = 0; - register struct monst *mtmp, *mtmp2; + register int cnt = 0; + register struct monst *mtmp, *mtmp2; - for (mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; - if (mtmp->data->mlet == S_KOP) { - if (canspotmon(mtmp)) cnt++; - mongone(mtmp); - } - } - if (cnt && !silent) - pline_The("Kop%s (disappointed) vanish%s into thin air.", - plur(cnt), cnt == 1 ? "es" : ""); + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; + if (mtmp->data->mlet == S_KOP) { + if (canspotmon(mtmp)) + cnt++; + mongone(mtmp); + } + } + if (cnt && !silent) + pline_The("Kop%s (disappointed) vanish%s into thin air.", plur(cnt), + cnt == 1 ? "es" : ""); } STATIC_OVL long @@ -3972,50 +4093,53 @@ struct monst *shkp; struct obj *otmp; boolean altusage; /* some items have an "alternate" use with different cost */ { - long tmp = 0L; + long tmp = 0L; - if(!shkp || !inhishop(shkp)) return(0L); /* insurance */ - tmp = get_cost(otmp, shkp); + if (!shkp || !inhishop(shkp)) + return (0L); /* insurance */ + tmp = get_cost(otmp, shkp); - /* The idea is to make the exhaustive use of */ - /* an unpaid item more expensive than buying */ - /* it outright. */ - if(otmp->otyp == MAGIC_LAMP) { /* 1 */ - /* normal use (ie, as light source) of a magic lamp never - degrades its value, but not charging anything would make - identifcation too easy; charge an amount comparable to - what is charged for an ordinary lamp (don't bother with - angry shk surchage) */ - if (!altusage) tmp = (long) objects[OIL_LAMP].oc_cost; - else tmp += tmp / 3L; /* djinni is being released */ - } else if(otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */ - /* no way to determine in advance */ - /* how many charges will be wasted. */ - /* so, arbitrarily, one half of the */ - /* price per use. */ - tmp /= 2L; - } else if(otmp->otyp == BAG_OF_TRICKS || /* 1 - 20 */ - otmp->otyp == HORN_OF_PLENTY) { - /* altusage: emptying of all the contents at once */ - if (!altusage) tmp /= 5L; - } else if(otmp->otyp == CRYSTAL_BALL || /* 1 - 5 */ - otmp->otyp == OIL_LAMP || /* 1 - 10 */ - otmp->otyp == BRASS_LANTERN || - (otmp->otyp >= MAGIC_FLUTE && - otmp->otyp <= DRUM_OF_EARTHQUAKE) || /* 5 - 9 */ - otmp->oclass == WAND_CLASS) { /* 3 - 11 */ - if (otmp->spe > 1) tmp /= 4L; - } else if (otmp->oclass == SPBOOK_CLASS) { - tmp -= tmp / 5L; - } else if (otmp->otyp == CAN_OF_GREASE - || otmp->otyp == TINNING_KIT - || otmp->otyp == EXPENSIVE_CAMERA - ) { - tmp /= 10L; - } else if (otmp->otyp == POT_OIL) { - tmp /= 5L; - } - return(tmp); + /* The idea is to make the exhaustive use of */ + /* an unpaid item more expensive than buying */ + /* it outright. */ + if (otmp->otyp == MAGIC_LAMP) { /* 1 */ + /* normal use (ie, as light source) of a magic lamp never + degrades its value, but not charging anything would make + identifcation too easy; charge an amount comparable to + what is charged for an ordinary lamp (don't bother with + angry shk surchage) */ + if (!altusage) + tmp = (long) objects[OIL_LAMP].oc_cost; + else + tmp += tmp / 3L; /* djinni is being released */ + } else if (otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */ + /* no way to determine in advance */ + /* how many charges will be wasted. */ + /* so, arbitrarily, one half of the */ + /* price per use. */ + tmp /= 2L; + } else if (otmp->otyp == BAG_OF_TRICKS || /* 1 - 20 */ + otmp->otyp == HORN_OF_PLENTY) { + /* altusage: emptying of all the contents at once */ + if (!altusage) + tmp /= 5L; + } else if (otmp->otyp == CRYSTAL_BALL || /* 1 - 5 */ + otmp->otyp == OIL_LAMP || /* 1 - 10 */ + otmp->otyp == BRASS_LANTERN + || (otmp->otyp >= MAGIC_FLUTE + && otmp->otyp <= DRUM_OF_EARTHQUAKE) || /* 5 - 9 */ + otmp->oclass == WAND_CLASS) { /* 3 - 11 */ + if (otmp->spe > 1) + tmp /= 4L; + } else if (otmp->oclass == SPBOOK_CLASS) { + tmp -= tmp / 5L; + } else if (otmp->otyp == CAN_OF_GREASE || otmp->otyp == TINNING_KIT + || otmp->otyp == EXPENSIVE_CAMERA) { + tmp /= 10L; + } else if (otmp->otyp == POT_OIL) { + tmp /= 5L; + } + return (tmp); } /* Charge the player for partial use of an unpaid object. @@ -4028,43 +4152,47 @@ check_unpaid_usage(otmp, altusage) struct obj *otmp; boolean altusage; { - struct monst *shkp; - const char *fmt, *arg1, *arg2; - char buf[BUFSZ]; - long tmp; + struct monst *shkp; + const char *fmt, *arg1, *arg2; + char buf[BUFSZ]; + long tmp; - if (!otmp->unpaid || !*u.ushops || - (otmp->spe <= 0 && objects[otmp->otyp].oc_charged)) - return; - if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp)) - return; - if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L) - return; + if (!otmp->unpaid || !*u.ushops + || (otmp->spe <= 0 && objects[otmp->otyp].oc_charged)) + return; + if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp)) + return; + if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L) + return; - arg1 = arg2 = ""; - if (otmp->oclass == SPBOOK_CLASS) { - fmt = "%sYou owe%s %ld %s."; - Sprintf(buf, "This is no free library, %s! ", cad(FALSE)); - arg1 = rn2(2) ? buf : ""; - arg2 = ESHK(shkp)->debit > 0L ? " an additional" : ""; - } else if (otmp->otyp == POT_OIL) { - fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax)."; - } else if (altusage && - (otmp->otyp == BAG_OF_TRICKS || otmp->otyp == HORN_OF_PLENTY)) { - fmt = "%s%sEmptying that will cost you %ld %s."; - if (!rn2(3)) arg1 = "Whoa! "; - if (!rn2(3)) arg1 = "Watch it! "; - } else { - fmt = "%s%sUsage fee, %ld %s."; - if (!rn2(3)) arg1 = "Hey! "; - if (!rn2(3)) arg2 = "Ahem. "; - } + arg1 = arg2 = ""; + if (otmp->oclass == SPBOOK_CLASS) { + fmt = "%sYou owe%s %ld %s."; + Sprintf(buf, "This is no free library, %s! ", cad(FALSE)); + arg1 = rn2(2) ? buf : ""; + arg2 = ESHK(shkp)->debit > 0L ? " an additional" : ""; + } else if (otmp->otyp == POT_OIL) { + fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax)."; + } else if (altusage && (otmp->otyp == BAG_OF_TRICKS + || otmp->otyp == HORN_OF_PLENTY)) { + fmt = "%s%sEmptying that will cost you %ld %s."; + if (!rn2(3)) + arg1 = "Whoa! "; + if (!rn2(3)) + arg1 = "Watch it! "; + } else { + fmt = "%s%sUsage fee, %ld %s."; + if (!rn2(3)) + arg1 = "Hey! "; + if (!rn2(3)) + arg2 = "Ahem. "; + } - if (!muteshk(shkp)) { - verbalize(fmt, arg1, arg2, tmp, currency(tmp)); - exercise(A_WIS, TRUE); /* you just got info */ - } - ESHK(shkp)->debit += tmp; + if (!muteshk(shkp)) { + verbalize(fmt, arg1, arg2, tmp, currency(tmp)); + exercise(A_WIS, TRUE); /* you just got info */ + } + ESHK(shkp)->debit += tmp; } /* for using charges of unpaid objects "used in the normal manner" */ @@ -4072,7 +4200,7 @@ void check_unpaid(otmp) struct obj *otmp; { - check_unpaid_usage(otmp, FALSE); /* normal item use */ + check_unpaid_usage(otmp, FALSE); /* normal item use */ } void @@ -4080,103 +4208,106 @@ costly_gold(x, y, amount) register xchar x, y; register long amount; { - register long delta; - register struct monst *shkp; - register struct eshk *eshkp; + register long delta; + register struct monst *shkp; + register struct eshk *eshkp; - if(!costly_spot(x, y)) return; - /* shkp now guaranteed to exist by costly_spot() */ - shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); + if (!costly_spot(x, y)) + return; + /* shkp now guaranteed to exist by costly_spot() */ + shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); - eshkp = ESHK(shkp); - if(eshkp->credit >= amount) { - if(eshkp->credit > amount) - Your("credit is reduced by %ld %s.", - amount, currency(amount)); - else Your("credit is erased."); - eshkp->credit -= amount; - } else { - delta = amount - eshkp->credit; - if(eshkp->credit) - Your("credit is erased."); - if(eshkp->debit) - Your("debt increases by %ld %s.", - delta, currency(delta)); - else You("owe %s %ld %s.", - shkname(shkp), delta, currency(delta)); - eshkp->debit += delta; - eshkp->loan += delta; - eshkp->credit = 0L; - } + eshkp = ESHK(shkp); + if (eshkp->credit >= amount) { + if (eshkp->credit > amount) + Your("credit is reduced by %ld %s.", amount, currency(amount)); + else + Your("credit is erased."); + eshkp->credit -= amount; + } else { + delta = amount - eshkp->credit; + if (eshkp->credit) + Your("credit is erased."); + if (eshkp->debit) + Your("debt increases by %ld %s.", delta, currency(delta)); + else + You("owe %s %ld %s.", shkname(shkp), delta, currency(delta)); + eshkp->debit += delta; + eshkp->loan += delta; + eshkp->credit = 0L; + } } /* used in domove to block diagonal shop-exit */ /* x,y should always be a door */ boolean -block_door(x,y) +block_door(x, y) register xchar x, y; { - register int roomno = *in_rooms(x, y, SHOPBASE); - register struct monst *shkp; + register int roomno = *in_rooms(x, y, SHOPBASE); + register struct monst *shkp; - if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); - if(!IS_DOOR(levl[x][y].typ)) return(FALSE); - if(roomno != *u.ushops) return(FALSE); + if (roomno < 0 || !IS_SHOP(roomno)) + return (FALSE); + if (!IS_DOOR(levl[x][y].typ)) + return (FALSE); + if (roomno != *u.ushops) + return (FALSE); - if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) - return(FALSE); + if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp)) + return (FALSE); - if(shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y - /* Actually, the shk should be made to block _any_ - * door, including a door the player digs, if the - * shk is within a 'jumping' distance. - */ - && ESHK(shkp)->shd.x == x && ESHK(shkp)->shd.y == y - && shkp->mcanmove && !shkp->msleeping - && (ESHK(shkp)->debit || ESHK(shkp)->billct || - ESHK(shkp)->robbed)) { - pline("%s%s blocks your way!", shkname(shkp), - Invis ? " senses your motion and" : ""); - return(TRUE); - } - return(FALSE); + if (shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y + /* Actually, the shk should be made to block _any_ + * door, including a door the player digs, if the + * shk is within a 'jumping' distance. + */ + && ESHK(shkp)->shd.x == x + && ESHK(shkp)->shd.y == y + && shkp->mcanmove && !shkp->msleeping + && (ESHK(shkp)->debit || ESHK(shkp)->billct || ESHK(shkp)->robbed)) { + pline("%s%s blocks your way!", shkname(shkp), + Invis ? " senses your motion and" : ""); + return (TRUE); + } + return (FALSE); } /* used in domove to block diagonal shop-entry */ /* u.ux, u.uy should always be a door */ boolean -block_entry(x,y) +block_entry(x, y) register xchar x, y; { - register xchar sx, sy; - register int roomno; - register struct monst *shkp; + register xchar sx, sy; + register int roomno; + register struct monst *shkp; - if(!(IS_DOOR(levl[u.ux][u.uy].typ) && - levl[u.ux][u.uy].doormask == D_BROKEN)) return(FALSE); + if (!(IS_DOOR(levl[u.ux][u.uy].typ) + && levl[u.ux][u.uy].doormask == D_BROKEN)) + return (FALSE); - roomno = *in_rooms(x, y, SHOPBASE); - if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); - if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) - return(FALSE); + roomno = *in_rooms(x, y, SHOPBASE); + if (roomno < 0 || !IS_SHOP(roomno)) + return (FALSE); + if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp)) + return (FALSE); - if(ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy) - return(FALSE); + if (ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy) + return (FALSE); - sx = ESHK(shkp)->shk.x; - sy = ESHK(shkp)->shk.y; + sx = ESHK(shkp)->shk.x; + sy = ESHK(shkp)->shk.y; - if(shkp->mx == sx && shkp->my == sy - && shkp->mcanmove && !shkp->msleeping - && (x == sx-1 || x == sx+1 || y == sy-1 || y == sy+1) - && (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) - || u.usteed - )) { - pline("%s%s blocks your way!", shkname(shkp), - Invis ? " senses your motion and" : ""); - return(TRUE); - } - return(FALSE); + if (shkp->mx == sx && shkp->my == sy && shkp->mcanmove && !shkp->msleeping + && (x == sx - 1 || x == sx + 1 || y == sy - 1 || y == sy + 1) + && (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) + || u.usteed)) { + pline("%s%s blocks your way!", shkname(shkp), + Invis ? " senses your motion and" : ""); + return (TRUE); + } + return (FALSE); } /* "your " or "Foobar's " (note the trailing space) */ @@ -4185,9 +4316,9 @@ shk_your(buf, obj) char *buf; struct obj *obj; { - if (!shk_owns(buf, obj) && !mon_owns(buf, obj)) - Strcpy(buf, the_your[carried(obj) ? 1 : 0]); - return strcat(buf, " "); + if (!shk_owns(buf, obj) && !mon_owns(buf, obj)) + Strcpy(buf, the_your[carried(obj) ? 1 : 0]); + return strcat(buf, " "); } char * @@ -4195,9 +4326,9 @@ Shk_Your(buf, obj) char *buf; struct obj *obj; { - (void) shk_your(buf, obj); - *buf = highc(*buf); - return buf; + (void) shk_your(buf, obj); + *buf = highc(*buf); + return buf; } STATIC_OVL char * @@ -4205,16 +4336,16 @@ shk_owns(buf, obj) char *buf; struct obj *obj; { - struct monst *shkp; - xchar x, y; + struct monst *shkp; + xchar x, y; - if (get_obj_location(obj, &x, &y, 0) && - (obj->unpaid || - (obj->where==OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) { - shkp = shop_keeper(inside_shop(x, y)); - return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : the_your[0]); - } - return (char *)0; + if (get_obj_location(obj, &x, &y, 0) + && (obj->unpaid || (obj->where == OBJ_FLOOR && !obj->no_charge + && costly_spot(x, y)))) { + shkp = shop_keeper(inside_shop(x, y)); + return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : the_your[0]); + } + return (char *) 0; } STATIC_OVL char * @@ -4222,41 +4353,52 @@ mon_owns(buf, obj) char *buf; struct obj *obj; { - if (obj->where == OBJ_MINVENT) - return strcpy(buf, s_suffix(y_monnam(obj->ocarry))); - return (char *)0; + if (obj->where == OBJ_MINVENT) + return strcpy(buf, s_suffix(y_monnam(obj->ocarry))); + return (char *) 0; } STATIC_OVL const char * cad(altusage) -boolean altusage; /* used as a verbalized exclamation: \"Cad! ...\" */ +boolean altusage; /* used as a verbalized exclamation: \"Cad! ...\" */ { const char *res = 0; switch (is_demon(youmonst.data) ? 3 : poly_gender()) { - case 0: res = "cad"; break; - case 1: res = "minx"; break; - case 2: res = "beast"; break; - case 3: res = "fiend"; break; - default: impossible("cad: unknown gender"); - res = "thing"; break; + case 0: + res = "cad"; + break; + case 1: + res = "minx"; + break; + case 2: + res = "beast"; + break; + case 3: + res = "fiend"; + break; + default: + impossible("cad: unknown gender"); + res = "thing"; + break; } if (altusage) { - char *cadbuf = mon_nam(&youmonst); /* snag an output buffer */ + char *cadbuf = mon_nam(&youmonst); /* snag an output buffer */ - /* alternate usage adds a leading double quote and trailing - exclamation point plus sentence separating spaces */ - Sprintf(cadbuf, "\"%s! ", res); - cadbuf[1] = highc(cadbuf[1]); - res = cadbuf; + /* alternate usage adds a leading double quote and trailing + exclamation point plus sentence separating spaces */ + Sprintf(cadbuf, "\"%s! ", res); + cadbuf[1] = highc(cadbuf[1]); + res = cadbuf; } return res; } #ifdef __SASC void -sasc_bug(struct obj *op, unsigned x){ - op->unpaid=x; +sasc_bug(struct obj *op, unsigned x) +{ + op->unpaid = x; } #endif diff --git a/src/shknam.c b/src/shknam.c index 1f24f1513..906d17696 100644 --- a/src/shknam.c +++ b/src/shknam.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 shknam.c $NHDT-Date: 1428207608 2015/04/05 04:20:08 $ $NHDT-Branch: nhmall-booktribute $:$NHDT-Revision: 1.32 $ */ +/* NetHack 3.6 shknam.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.35 $ */ /* NetHack 3.6 shknam.c $Date: 2011/04/15 01:55:42 $ $Revision: 1.24 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,14 +7,15 @@ #include "hack.h" -STATIC_DCL boolean FDECL(veggy_item, (struct obj *obj,int)); +STATIC_DCL boolean FDECL(veggy_item, (struct obj * obj, int)); STATIC_DCL int NDECL(shkveg); -STATIC_DCL void FDECL(mkveggy_at, (int,int)); -STATIC_DCL void FDECL(mkshobj_at, (const struct shclass *,int,int,BOOLEAN_P)); -STATIC_DCL void FDECL(nameshk, (struct monst *,const char * const *)); -STATIC_DCL int FDECL(shkinit, (const struct shclass *,struct mkroom *)); +STATIC_DCL void FDECL(mkveggy_at, (int, int)); +STATIC_DCL void FDECL(mkshobj_at, + (const struct shclass *, int, int, BOOLEAN_P)); +STATIC_DCL void FDECL(nameshk, (struct monst *, const char *const *)); +STATIC_DCL int FDECL(shkinit, (const struct shclass *, struct mkroom *)); -#define VEGETARIAN_CLASS (MAXOCLASSES+1) +#define VEGETARIAN_CLASS (MAXOCLASSES + 1) /* * Name prefix codes: @@ -27,104 +28,98 @@ STATIC_DCL int FDECL(shkinit, (const struct shclass *,struct mkroom *)); * Personal names do not receive the honorific prefix "Mr." or "Ms.". */ -static const char * const shkliquors[] = { +static const char *const shkliquors[] = { /* Ukraine */ "Njezjin", "Tsjernigof", "Ossipewsk", "Gorlowka", /* Belarus */ "Gomel", /* N. Russia */ - "Konosja", "Weliki Oestjoeg", "Syktywkar", "Sablja", - "Narodnaja", "Kyzyl", + "Konosja", "Weliki Oestjoeg", "Syktywkar", "Sablja", "Narodnaja", "Kyzyl", /* Silezie */ - "Walbrzych", "Swidnica", "Klodzko", "Raciborz", "Gliwice", - "Brzeg", "Krnov", "Hradec Kralove", + "Walbrzych", "Swidnica", "Klodzko", "Raciborz", "Gliwice", "Brzeg", + "Krnov", "Hradec Kralove", /* Schweiz */ - "Leuk", "Brig", "Brienz", "Thun", "Sarnen", "Burglen", "Elm", - "Flims", "Vals", "Schuls", "Zum Loch", - 0 + "Leuk", "Brig", "Brienz", "Thun", "Sarnen", "Burglen", "Elm", "Flims", + "Vals", "Schuls", "Zum Loch", 0 }; -static const char * const shkbooks[] = { +static const char *const shkbooks[] = { /* Eire */ - "Skibbereen", "Kanturk", "Rath Luirc", "Ennistymon", "Lahinch", - "Kinnegad", "Lugnaquillia", "Enniscorthy", "Gweebarra", - "Kittamagh", "Nenagh", "Sneem", "Ballingeary", "Kilgarvan", - "Cahersiveen", "Glenbeigh", "Kilmihil", "Kiltamagh", - "Droichead Atha", "Inniscrone", "Clonegal", "Lisnaskea", - "Culdaff", "Dunfanaghy", "Inishbofin", "Kesh", - 0 + "Skibbereen", "Kanturk", "Rath Luirc", "Ennistymon", + "Lahinch", "Kinnegad", "Lugnaquillia", "Enniscorthy", + "Gweebarra", "Kittamagh", "Nenagh", "Sneem", + "Ballingeary", "Kilgarvan", "Cahersiveen", "Glenbeigh", + "Kilmihil", "Kiltamagh", "Droichead Atha", "Inniscrone", + "Clonegal", "Lisnaskea", "Culdaff", "Dunfanaghy", + "Inishbofin", "Kesh", 0 }; -static const char * const shkarmors[] = { +static const char *const shkarmors[] = { /* Turquie */ - "Demirci", "Kalecik", "Boyabai", "Yildizeli", "Gaziantep", - "Siirt", "Akhalataki", "Tirebolu", "Aksaray", "Ermenak", - "Iskenderun", "Kadirli", "Siverek", "Pervari", "Malasgirt", - "Bayburt", "Ayancik", "Zonguldak", "Balya", "Tefenni", - "Artvin", "Kars", "Makharadze", "Malazgirt", "Midyat", - "Birecik", "Kirikkale", "Alaca", "Polatli", "Nallihan", + "Demirci", "Kalecik", "Boyabai", "Yildizeli", "Gaziantep", + "Siirt", "Akhalataki", "Tirebolu", "Aksaray", "Ermenak", + "Iskenderun", "Kadirli", "Siverek", "Pervari", "Malasgirt", + "Bayburt", "Ayancik", "Zonguldak", "Balya", "Tefenni", + "Artvin", "Kars", "Makharadze", "Malazgirt", "Midyat", + "Birecik", "Kirikkale", "Alaca", "Polatli", "Nallihan", 0 }; -static const char * const shkwands[] = { +static const char *const shkwands[] = { /* Wales */ - "Yr Wyddgrug", "Trallwng", "Mallwyd", "Pontarfynach", - "Rhaeader", "Llandrindod", "Llanfair-ym-muallt", - "Y-Fenni", "Maesteg", "Rhydaman", "Beddgelert", - "Curig", "Llanrwst", "Llanerchymedd", "Caergybi", + "Yr Wyddgrug", "Trallwng", "Mallwyd", "Pontarfynach", "Rhaeader", + "Llandrindod", "Llanfair-ym-muallt", "Y-Fenni", "Maesteg", "Rhydaman", + "Beddgelert", "Curig", "Llanrwst", "Llanerchymedd", "Caergybi", /* Scotland */ - "Nairn", "Turriff", "Inverurie", "Braemar", "Lochnagar", - "Kerloch", "Beinn a Ghlo", "Drumnadrochit", "Morven", - "Uist", "Storr", "Sgurr na Ciche", "Cannich", "Gairloch", - "Kyleakin", "Dunvegan", - 0 + "Nairn", "Turriff", "Inverurie", "Braemar", "Lochnagar", "Kerloch", + "Beinn a Ghlo", "Drumnadrochit", "Morven", "Uist", "Storr", + "Sgurr na Ciche", "Cannich", "Gairloch", "Kyleakin", "Dunvegan", 0 }; -static const char * const shkrings[] = { +static const char *const shkrings[] = { /* Hollandse familienamen */ - "Feyfer", "Flugi", "Gheel", "Havic", "Haynin", "Hoboken", - "Imbyze", "Juyn", "Kinsky", "Massis", "Matray", "Moy", - "Olycan", "Sadelin", "Svaving", "Tapper", "Terwen", "Wirix", - "Ypey", + "Feyfer", "Flugi", "Gheel", "Havic", "Haynin", + "Hoboken", "Imbyze", "Juyn", "Kinsky", "Massis", + "Matray", "Moy", "Olycan", "Sadelin", "Svaving", + "Tapper", "Terwen", "Wirix", "Ypey", /* Skandinaviske navne */ - "Rastegaisa", "Varjag Njarga", "Kautekeino", "Abisko", - "Enontekis", "Rovaniemi", "Avasaksa", "Haparanda", - "Lulea", "Gellivare", "Oeloe", "Kajaani", "Fauske", - 0 + "Rastegaisa", "Varjag Njarga", "Kautekeino", "Abisko", "Enontekis", + "Rovaniemi", "Avasaksa", "Haparanda", "Lulea", "Gellivare", + "Oeloe", "Kajaani", "Fauske", 0 }; -static const char * const shkfoods[] = { +static const char *const shkfoods[] = { /* Indonesia */ - "Djasinga", "Tjibarusa", "Tjiwidej", "Pengalengan", - "Bandjar", "Parbalingga", "Bojolali", "Sarangan", - "Ngebel", "Djombang", "Ardjawinangun", "Berbek", - "Papar", "Baliga", "Tjisolok", "Siboga", "Banjoewangi", - "Trenggalek", "Karangkobar", "Njalindoeng", "Pasawahan", - "Pameunpeuk", "Patjitan", "Kediri", "Pemboeang", "Tringanoe", - "Makin", "Tipor", "Semai", "Berhala", "Tegal", "Samoe", + "Djasinga", "Tjibarusa", "Tjiwidej", "Pengalengan", + "Bandjar", "Parbalingga", "Bojolali", "Sarangan", + "Ngebel", "Djombang", "Ardjawinangun", "Berbek", + "Papar", "Baliga", "Tjisolok", "Siboga", + "Banjoewangi", "Trenggalek", "Karangkobar", "Njalindoeng", + "Pasawahan", "Pameunpeuk", "Patjitan", "Kediri", + "Pemboeang", "Tringanoe", "Makin", "Tipor", + "Semai", "Berhala", "Tegal", "Samoe", 0 }; -static const char * const shkweapons[] = { +static const char *const shkweapons[] = { /* Perigord */ - "Voulgezac", "Rouffiac", "Lerignac", "Touverac", "Guizengeard", - "Melac", "Neuvicq", "Vanzac", "Picq", "Urignac", "Corignac", - "Fleac", "Lonzac", "Vergt", "Queyssac", "Liorac", "Echourgnac", - "Cazelon", "Eypau", "Carignan", "Monbazillac", "Jonzac", - "Pons", "Jumilhac", "Fenouilledes", "Laguiolet", "Saujon", - "Eymoutiers", "Eygurande", "Eauze", "Labouheyre", - 0 + "Voulgezac", "Rouffiac", "Lerignac", "Touverac", "Guizengeard", + "Melac", "Neuvicq", "Vanzac", "Picq", "Urignac", + "Corignac", "Fleac", "Lonzac", "Vergt", "Queyssac", + "Liorac", "Echourgnac", "Cazelon", "Eypau", "Carignan", + "Monbazillac", "Jonzac", "Pons", "Jumilhac", "Fenouilledes", + "Laguiolet", "Saujon", "Eymoutiers", "Eygurande", "Eauze", + "Labouheyre", 0 }; -static const char * const shktools[] = { +static const char *const shktools[] = { /* Spmi */ "Ymla", "Eed-morra", "Cubask", "Nieb", "Bnowr Falr", "Telloc Cyaj", "Sperc", "Noskcirdneh", "Yawolloh", "Hyeghu", "Niskal", "Trahnil", - "Htargcm", "Enrobwem", "Kachzi Rellim", "Regien", "Donmyar", - "Yelpur", "Nosnehpets", "Stewe", "Renrut", "-Zlaw", "Nosalnef", - "Rewuorb", "Rellenk", "Yad", "Cire Htims", "Y-crad", "Nenilukah", - "Corsh", "Aned", "Niknar", "Lapu", "Lechaim", "Rebrol-nek", - "AlliWar Wickson", "Oguhmk", + "Htargcm", "Enrobwem", "Kachzi Rellim", "Regien", "Donmyar", "Yelpur", + "Nosnehpets", "Stewe", "Renrut", "-Zlaw", "Nosalnef", "Rewuorb", + "Rellenk", "Yad", "Cire Htims", "Y-crad", "Nenilukah", "Corsh", "Aned", + "Niknar", "Lapu", "Lechaim", "Rebrol-nek", "AlliWar Wickson", "Oguhmk", #ifdef OVERLAY "Erreip", "Nehpets", "Mron", "Snivek", "Kahztiy", #endif @@ -132,12 +127,12 @@ static const char * const shktools[] = { "Lexa", "Niod", #endif #ifdef MAC - "Nhoj-lee", "Evad\'kh", "Ettaw-noj", "Tsew-mot", "Ydna-s", - "Yao-hang", "Tonbar", "Kivenhoug", "Llardom", + "Nhoj-lee", "Evad\'kh", "Ettaw-noj", "Tsew-mot", "Ydna-s", "Yao-hang", + "Tonbar", "Kivenhoug", "Llardom", #endif #ifdef AMIGA - "Falo", "Nosid-da\'r", "Ekim-p", "Noslo", "Yl-rednow", - "Mured-oog", "Ivrajimsal", + "Falo", "Nosid-da\'r", "Ekim-p", "Noslo", "Yl-rednow", "Mured-oog", + "Ivrajimsal", #endif #ifdef TOS "Nivram", @@ -151,53 +146,48 @@ static const char * const shktools[] = { 0 }; -static const char * const shklight[] = { +static const char *const shklight[] = { /* Romania */ "Zarnesti", "Slanic", "Nehoiasu", "Ludus", "Sighisoara", "Nisipitu", "Razboieni", "Bicaz", "Dorohoi", "Vaslui", "Fetesti", "Tirgu Neamt", "Babadag", "Zimnicea", "Zlatna", "Jiu", "Eforie", "Mamaia", /* Bulgaria */ - "Silistra", "Tulovo", "Panagyuritshte", "Smolyan", "Kirklareli", - "Pernik", "Lom", "Haskovo", "Dobrinishte", "Varvara", "Oryahovo", - "Troyan", "Lovech", "Sliven", - 0 + "Silistra", "Tulovo", "Panagyuritshte", "Smolyan", "Kirklareli", "Pernik", + "Lom", "Haskovo", "Dobrinishte", "Varvara", "Oryahovo", "Troyan", + "Lovech", "Sliven", 0 }; -static const char * const shkgeneral[] = { +static const char *const shkgeneral[] = { /* Suriname */ - "Hebiwerie", "Possogroenoe", "Asidonhopo", "Manlobbi", - "Adjama", "Pakka Pakka", "Kabalebo", "Wonotobo", - "Akalapi", "Sipaliwini", + "Hebiwerie", "Possogroenoe", "Asidonhopo", "Manlobbi", + "Adjama", "Pakka Pakka", "Kabalebo", "Wonotobo", + "Akalapi", "Sipaliwini", /* Greenland */ - "Annootok", "Upernavik", "Angmagssalik", + "Annootok", "Upernavik", "Angmagssalik", /* N. Canada */ - "Aklavik", "Inuvik", "Tuktoyaktuk", - "Chicoutimi", "Ouiatchouane", "Chibougamau", - "Matagami", "Kipawa", "Kinojevis", - "Abitibi", "Maganasipi", + "Aklavik", "Inuvik", "Tuktoyaktuk", "Chicoutimi", + "Ouiatchouane", "Chibougamau", "Matagami", "Kipawa", + "Kinojevis", "Abitibi", "Maganasipi", /* Iceland */ - "Akureyri", "Kopasker", "Budereyri", "Akranes", "Bordeyri", - "Holmavik", - 0 + "Akureyri", "Kopasker", "Budereyri", "Akranes", + "Bordeyri", "Holmavik", 0 }; -static const char * const shkhealthfoods[] = { +static const char *const shkhealthfoods[] = { /* Tibet */ - "Ga'er", "Zhangmu", "Rikaze", "Jiangji", - "Changdu", "Linzhi", "Shigatse", "Gyantse", - "Ganden", "Tsurphu", "Lhasa", "Tsedong", - "Drepung", + "Ga'er", "Zhangmu", "Rikaze", "Jiangji", "Changdu", + "Linzhi", "Shigatse", "Gyantse", "Ganden", "Tsurphu", + "Lhasa", "Tsedong", "Drepung", /* Hippie names */ - "=Azura", "=Blaze", "=Breanna", "=Breezy", - "=Dharma", "=Feather", "=Jasmine", "=Luna", - "=Melody", "=Moonjava", "=Petal", "=Rhiannon", - "=Starla", "=Tranquilla", "=Windsong", "=Zennia", - "=Zoe", "=Zora", - 0 + "=Azura", "=Blaze", "=Breanna", "=Breezy", "=Dharma", + "=Feather", "=Jasmine", "=Luna", "=Melody", "=Moonjava", + "=Petal", "=Rhiannon", "=Starla", "=Tranquilla", "=Windsong", + "=Zennia", "=Zoe", "=Zora", 0 }; /* - * To add new shop types, all that is necessary is to edit the shtypes[] array. + * To add new shop types, all that is necessary is to edit the shtypes[] + * array. * See mkroom.h for the structure definition. Typically, you'll have to lower * some or all of the probability fields in old entries to free up some * percentage for the new type. @@ -213,51 +203,146 @@ static const char * const shkhealthfoods[] = { */ const struct shclass shtypes[] = { - {"general store", RANDOM_CLASS, 42, D_SHOP, - {{100, RANDOM_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkgeneral}, - {"used armor dealership", ARMOR_CLASS, 14, D_SHOP, - {{90, ARMOR_CLASS}, {10, WEAPON_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkarmors}, - {"second-hand bookstore", SCROLL_CLASS, 10, D_SHOP, - {{90, SCROLL_CLASS}, {10, SPBOOK_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkbooks}, - {"liquor emporium", POTION_CLASS, 10, D_SHOP, - {{100, POTION_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkliquors}, - {"antique weapons outlet", WEAPON_CLASS, 5, D_SHOP, - {{90, WEAPON_CLASS}, {10, ARMOR_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkweapons}, - {"delicatessen", FOOD_CLASS, 5, D_SHOP, - {{83, FOOD_CLASS}, {5, -POT_FRUIT_JUICE}, {4, -POT_BOOZE}, - {5, -POT_WATER}, {3, -ICE_BOX}, {0, 0}}, - shkfoods}, - {"jewelers", RING_CLASS, 3, D_SHOP, - {{85, RING_CLASS}, {10, GEM_CLASS}, {5, AMULET_CLASS}, - {0, 0}, {0, 0}, {0, 0}}, - shkrings}, - {"quality apparel and accessories", WAND_CLASS, 3, D_SHOP, - {{90, WAND_CLASS}, {5, -LEATHER_GLOVES}, {5, -ELVEN_CLOAK}, {0, 0}}, - shkwands}, - {"hardware store", TOOL_CLASS, 3, D_SHOP, - {{100, TOOL_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shktools}, - {"rare books", SPBOOK_CLASS, 3, D_SHOP, - {{90, SPBOOK_CLASS}, {10, SCROLL_CLASS}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, - shkbooks}, - {"health food store", FOOD_CLASS, 2, D_SHOP, - {{70, VEGETARIAN_CLASS}, {20, -POT_FRUIT_JUICE}, {4, -POT_HEALING}, - {3, -POT_FULL_HEALING}, {2, -SCR_FOOD_DETECTION}, {1, -LUMP_OF_ROYAL_JELLY}}, - shkhealthfoods}, - /* Shops below this point are "unique". That is they must all have a - * probability of zero. They are only created via the special level - * loader. - */ - {"lighting store", TOOL_CLASS, 0, D_SHOP, - {{30, -WAX_CANDLE}, {48, -TALLOW_CANDLE}, {5, -BRASS_LANTERN}, - {9, -OIL_LAMP}, {3, -MAGIC_LAMP}, {5, -POT_OIL}}, - shklight}, - {(char *)0, 0, 0, 0, {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, 0} + { "general store", + RANDOM_CLASS, + 42, + D_SHOP, + { { 100, RANDOM_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkgeneral }, + { "used armor dealership", + ARMOR_CLASS, + 14, + D_SHOP, + { { 90, ARMOR_CLASS }, + { 10, WEAPON_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkarmors }, + { "second-hand bookstore", + SCROLL_CLASS, + 10, + D_SHOP, + { { 90, SCROLL_CLASS }, + { 10, SPBOOK_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkbooks }, + { "liquor emporium", + POTION_CLASS, + 10, + D_SHOP, + { { 100, POTION_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkliquors }, + { "antique weapons outlet", + WEAPON_CLASS, + 5, + D_SHOP, + { { 90, WEAPON_CLASS }, + { 10, ARMOR_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkweapons }, + { "delicatessen", + FOOD_CLASS, + 5, + D_SHOP, + { { 83, FOOD_CLASS }, + { 5, -POT_FRUIT_JUICE }, + { 4, -POT_BOOZE }, + { 5, -POT_WATER }, + { 3, -ICE_BOX }, + { 0, 0 } }, + shkfoods }, + { "jewelers", + RING_CLASS, + 3, + D_SHOP, + { { 85, RING_CLASS }, + { 10, GEM_CLASS }, + { 5, AMULET_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkrings }, + { "quality apparel and accessories", + WAND_CLASS, + 3, + D_SHOP, + { { 90, WAND_CLASS }, + { 5, -LEATHER_GLOVES }, + { 5, -ELVEN_CLOAK }, + { 0, 0 } }, + shkwands }, + { "hardware store", + TOOL_CLASS, + 3, + D_SHOP, + { { 100, TOOL_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shktools }, + { "rare books", + SPBOOK_CLASS, + 3, + D_SHOP, + { { 90, SPBOOK_CLASS }, + { 10, SCROLL_CLASS }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 } }, + shkbooks }, + { "health food store", + FOOD_CLASS, + 2, + D_SHOP, + { { 70, VEGETARIAN_CLASS }, + { 20, -POT_FRUIT_JUICE }, + { 4, -POT_HEALING }, + { 3, -POT_FULL_HEALING }, + { 2, -SCR_FOOD_DETECTION }, + { 1, -LUMP_OF_ROYAL_JELLY } }, + shkhealthfoods }, + /* Shops below this point are "unique". That is they must all have a + * probability of zero. They are only created via the special level + * loader. + */ + { "lighting store", + TOOL_CLASS, + 0, + D_SHOP, + { { 30, -WAX_CANDLE }, + { 48, -TALLOW_CANDLE }, + { 5, -BRASS_LANTERN }, + { 9, -OIL_LAMP }, + { 3, -MAGIC_LAMP }, + { 5, -POT_OIL } }, + shklight }, + { (char *) 0, + 0, + 0, + 0, + { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }, + 0 } }; #if 0 @@ -286,29 +371,29 @@ init_shop_selection() STATIC_OVL boolean veggy_item(obj, otyp) struct obj *obj; -int otyp; /* used iff obj is null */ +int otyp; /* used iff obj is null */ { int corpsenm; char oclass; if (obj) { - /* actual object; will check tin content and corpse species */ - otyp = (int) obj->otyp; - oclass = obj->oclass; - corpsenm = obj->corpsenm; + /* actual object; will check tin content and corpse species */ + otyp = (int) obj->otyp; + oclass = obj->oclass; + corpsenm = obj->corpsenm; } else { - /* just a type; caller will have to handle tins and corpses */ - oclass = objects[otyp].oc_class; - corpsenm = PM_LICHEN; /* veggy standin */ + /* just a type; caller will have to handle tins and corpses */ + oclass = objects[otyp].oc_class; + corpsenm = PM_LICHEN; /* veggy standin */ } if (oclass == FOOD_CLASS) { - if (objects[otyp].oc_material == VEGGY || otyp == EGG) - return TRUE; - if (otyp == TIN && corpsenm == NON_PM) /* implies obj is non-null */ - return (obj->spe == 1); /* 0 = empty, 1 = spinach */ - if (otyp == TIN || otyp == CORPSE) - return (corpsenm >= LOW_PM && vegetarian(&mons[corpsenm])); + if (objects[otyp].oc_material == VEGGY || otyp == EGG) + return TRUE; + if (otyp == TIN && corpsenm == NON_PM) /* implies obj is non-null */ + return (obj->spe == 1); /* 0 = empty, 1 = spinach */ + if (otyp == TIN || otyp == CORPSE) + return (corpsenm >= LOW_PM && vegetarian(&mons[corpsenm])); } return FALSE; } @@ -316,32 +401,34 @@ int otyp; /* used iff obj is null */ STATIC_OVL int shkveg() { - int i, j, maxprob, prob; - char oclass = FOOD_CLASS; - int ok[NUM_OBJECTS]; + int i, j, maxprob, prob; + char oclass = FOOD_CLASS; + int ok[NUM_OBJECTS]; - j = maxprob = 0; - for (i = bases[(int)oclass]; i < NUM_OBJECTS; ++i) { - if (objects[i].oc_class != oclass) break; + j = maxprob = 0; + for (i = bases[(int) oclass]; i < NUM_OBJECTS; ++i) { + if (objects[i].oc_class != oclass) + break; - if (veggy_item((struct obj *)0, i)) { - ok[j++] = i; - maxprob += objects[i].oc_prob; - } - } - if (maxprob < 1) panic("shkveg no veggy objects"); - prob = rnd(maxprob); + if (veggy_item((struct obj *) 0, i)) { + ok[j++] = i; + maxprob += objects[i].oc_prob; + } + } + if (maxprob < 1) + panic("shkveg no veggy objects"); + prob = rnd(maxprob); - j = 0; - i = ok[0]; - while((prob -= objects[i].oc_prob) > 0) { - j++; - i = ok[j]; - } + j = 0; + i = ok[0]; + while ((prob -= objects[i].oc_prob) > 0) { + j++; + i = ok[j]; + } - if(objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) - panic("shkveg probtype error, oclass=%d i=%d", (int) oclass, i); - return i; + if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) + panic("shkveg probtype error, oclass=%d i=%d", (int) oclass, i); + return i; } /* make a random item for health food store */ @@ -352,7 +439,7 @@ int sx, sy; struct obj *obj = mksobj_at(shkveg(), sx, sy, TRUE, TRUE); if (obj && obj->otyp == TIN) - set_tin_variety(obj, HEALTHY_TIN); + set_tin_variety(obj, HEALTHY_TIN); return; } @@ -363,210 +450,227 @@ const struct shclass *shp; int sx, sy; boolean mkspecl; { - struct monst *mtmp; - int atype; - struct permonst *ptr; + struct monst *mtmp; + int atype; + struct permonst *ptr; - /* 3.6.0 tribute */ - if (mkspecl && (!strcmp(shp->name, "rare books") || - !strcmp(shp->name, "second-hand bookstore"))) { - struct obj *novel=mksobj_at(SPE_NOVEL, sx, sy, FALSE, FALSE); - if (novel) context.tribute.bookstock = TRUE; - return; - } - - if (rn2(100) < depth(&u.uz) && - !MON_AT(sx, sy) && (ptr = mkclass(S_MIMIC,0)) && - (mtmp = makemon(ptr,sx,sy,NO_MM_FLAGS)) != 0) { - /* note: makemon will set the mimic symbol to a shop item */ - if (rn2(10) >= depth(&u.uz)) { - mtmp->m_ap_type = M_AP_OBJECT; - mtmp->mappearance = STRANGE_OBJECT; - } - } else { - atype = get_shop_item((int)(shp - shtypes)); - if (atype == VEGETARIAN_CLASS) - mkveggy_at(sx, sy); - else if (atype < 0) - (void) mksobj_at(-atype, sx, sy, TRUE, TRUE); - else - (void) mkobj_at(atype, sx, sy, TRUE); - } + /* 3.6.0 tribute */ + if (mkspecl && (!strcmp(shp->name, "rare books") + || !strcmp(shp->name, "second-hand bookstore"))) { + struct obj *novel = mksobj_at(SPE_NOVEL, sx, sy, FALSE, FALSE); + if (novel) + context.tribute.bookstock = TRUE; + return; + } + + if (rn2(100) < depth(&u.uz) && !MON_AT(sx, sy) + && (ptr = mkclass(S_MIMIC, 0)) + && (mtmp = makemon(ptr, sx, sy, NO_MM_FLAGS)) != 0) { + /* note: makemon will set the mimic symbol to a shop item */ + if (rn2(10) >= depth(&u.uz)) { + mtmp->m_ap_type = M_AP_OBJECT; + mtmp->mappearance = STRANGE_OBJECT; + } + } else { + atype = get_shop_item((int) (shp - shtypes)); + if (atype == VEGETARIAN_CLASS) + mkveggy_at(sx, sy); + else if (atype < 0) + (void) mksobj_at(-atype, sx, sy, TRUE, TRUE); + else + (void) mkobj_at(atype, sx, sy, TRUE); + } } /* extract a shopkeeper name for the given shop type */ STATIC_OVL void nameshk(shk, nlp) struct monst *shk; -const char * const *nlp; +const char *const *nlp; { - int i, trycnt, names_avail; - const char *shname = 0; - struct monst *mtmp; - int name_wanted; - s_level *sptr; + int i, trycnt, names_avail; + const char *shname = 0; + struct monst *mtmp; + int name_wanted; + s_level *sptr; - if (nlp == shkfoods && In_mines(&u.uz) && Role_if(PM_MONK) - && (sptr = Is_special(&u.uz)) != 0 && sptr->flags.town) { - /* special-case override for minetown food store for monks */ - nlp = shkhealthfoods; - } + if (nlp == shkfoods && In_mines(&u.uz) && Role_if(PM_MONK) + && (sptr = Is_special(&u.uz)) != 0 && sptr->flags.town) { + /* special-case override for minetown food store for monks */ + nlp = shkhealthfoods; + } - if (nlp == shklight && In_mines(&u.uz) - && (sptr = Is_special(&u.uz)) != 0 && sptr->flags.town) { - /* special-case minetown lighting shk */ - shname = "+Izchak"; - shk->female = FALSE; - } else { - /* We want variation from game to game, without needing the save - and restore support which would be necessary for randomization; - try not to make too many assumptions about time_t's internals; - use ledger_no rather than depth to keep mine town distinct. */ - int nseed = (int)((long)ubirthday / 257L); + if (nlp == shklight && In_mines(&u.uz) && (sptr = Is_special(&u.uz)) != 0 + && sptr->flags.town) { + /* special-case minetown lighting shk */ + shname = "+Izchak"; + shk->female = FALSE; + } else { + /* We want variation from game to game, without needing the save + and restore support which would be necessary for randomization; + try not to make too many assumptions about time_t's internals; + use ledger_no rather than depth to keep mine town distinct. */ + int nseed = (int) ((long) ubirthday / 257L); - name_wanted = ledger_no(&u.uz) + (nseed % 13) - (nseed % 5); - if (name_wanted < 0) name_wanted += (13 + 5); - shk->female = name_wanted & 1; + name_wanted = ledger_no(&u.uz) + (nseed % 13) - (nseed % 5); + if (name_wanted < 0) + name_wanted += (13 + 5); + shk->female = name_wanted & 1; - for (names_avail = 0; nlp[names_avail]; names_avail++) - continue; + for (names_avail = 0; nlp[names_avail]; names_avail++) + continue; - for (trycnt = 0; trycnt < 50; trycnt++) { - if (nlp == shktools) { - shname = shktools[rn2(names_avail)]; - shk->female = 0; /* reversed below for '_' prefix */ - } else if (name_wanted < names_avail) { - shname = nlp[name_wanted]; - } else if ((i = rn2(names_avail)) != 0) { - shname = nlp[i - 1]; - } else if (nlp != shkgeneral) { - nlp = shkgeneral; /* try general names */ - for (names_avail = 0; nlp[names_avail]; names_avail++) - continue; - continue; /* next `trycnt' iteration */ - } else { - shname = shk->female ? "-Lucrezia" : "+Dirk"; - } - if (*shname == '_' || *shname == '-') shk->female = 1; - else if (*shname == '|' || *shname == '+') shk->female = 0; + for (trycnt = 0; trycnt < 50; trycnt++) { + if (nlp == shktools) { + shname = shktools[rn2(names_avail)]; + shk->female = 0; /* reversed below for '_' prefix */ + } else if (name_wanted < names_avail) { + shname = nlp[name_wanted]; + } else if ((i = rn2(names_avail)) != 0) { + shname = nlp[i - 1]; + } else if (nlp != shkgeneral) { + nlp = shkgeneral; /* try general names */ + for (names_avail = 0; nlp[names_avail]; names_avail++) + continue; + continue; /* next `trycnt' iteration */ + } else { + shname = shk->female ? "-Lucrezia" : "+Dirk"; + } + if (*shname == '_' || *shname == '-') + shk->female = 1; + else if (*shname == '|' || *shname == '+') + shk->female = 0; - /* is name already in use on this level? */ - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp) || (mtmp == shk) || !mtmp->isshk) continue; - if (strcmp(ESHK(mtmp)->shknam, shname)) continue; - break; - } - if (!mtmp) break; /* new name */ - } - } - (void) strncpy(ESHK(shk)->shknam, shname, PL_NSIZ); - ESHK(shk)->shknam[PL_NSIZ-1] = 0; + /* is name already in use on this level? */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp) || (mtmp == shk) || !mtmp->isshk) + continue; + if (strcmp(ESHK(mtmp)->shknam, shname)) + continue; + break; + } + if (!mtmp) + break; /* new name */ + } + } + (void) strncpy(ESHK(shk)->shknam, shname, PL_NSIZ); + ESHK(shk)->shknam[PL_NSIZ - 1] = 0; } void neweshk(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) - mtmp->mextra = newmextra(); - if (!ESHK(mtmp)) - ESHK(mtmp) = (struct eshk *)alloc(sizeof(struct eshk)); - (void) memset((genericptr_t)ESHK(mtmp), 0, sizeof (struct eshk)); - ESHK(mtmp)->bill_p = (struct bill_x *)0; + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + if (!ESHK(mtmp)) + ESHK(mtmp) = (struct eshk *) alloc(sizeof(struct eshk)); + (void) memset((genericptr_t) ESHK(mtmp), 0, sizeof(struct eshk)); + ESHK(mtmp)->bill_p = (struct bill_x *) 0; } void free_eshk(mtmp) struct monst *mtmp; { - if (mtmp->mextra && ESHK(mtmp)) { - free((genericptr_t) ESHK(mtmp)); - ESHK(mtmp) = (struct eshk *)0; - } - mtmp->isshk = 0; + if (mtmp->mextra && ESHK(mtmp)) { + free((genericptr_t) ESHK(mtmp)); + ESHK(mtmp) = (struct eshk *) 0; + } + mtmp->isshk = 0; } -STATIC_OVL int -shkinit(shp, sroom) /* create a new shopkeeper in the given room */ -const struct shclass *shp; -struct mkroom *sroom; +STATIC_OVL int shkinit(shp, + sroom) /* create a new shopkeeper in the given room */ +const struct shclass *shp; +struct mkroom *sroom; { - register int sh, sx, sy; - struct monst *shk; - struct eshk *eshkp; + register int sh, sx, sy; + struct monst *shk; + struct eshk *eshkp; - /* place the shopkeeper in the given room */ - sh = sroom->fdoor; - sx = doors[sh].x; - sy = doors[sh].y; + /* place the shopkeeper in the given room */ + sh = sroom->fdoor; + sx = doors[sh].x; + sy = doors[sh].y; - /* check that the shopkeeper placement is sane */ - if(sroom->irregular) { - int rmno = (int)((sroom - rooms) + ROOMOFFSET); - if (isok(sx-1,sy) && !levl[sx-1][sy].edge && - (int) levl[sx-1][sy].roomno == rmno) sx--; - else if (isok(sx+1,sy) && !levl[sx+1][sy].edge && - (int) levl[sx+1][sy].roomno == rmno) sx++; - else if (isok(sx,sy-1) && !levl[sx][sy-1].edge && - (int) levl[sx][sy-1].roomno == rmno) sy--; - else if (isok(sx,sy+1) && !levl[sx][sy+1].edge && - (int) levl[sx][sy+1].roomno == rmno) sx++; - else goto shk_failed; - } - else if(sx == sroom->lx-1) sx++; - else if(sx == sroom->hx+1) sx--; - else if(sy == sroom->ly-1) sy++; - else if(sy == sroom->hy+1) sy--; else { - shk_failed: + /* check that the shopkeeper placement is sane */ + if (sroom->irregular) { + int rmno = (int) ((sroom - rooms) + ROOMOFFSET); + if (isok(sx - 1, sy) && !levl[sx - 1][sy].edge + && (int) levl[sx - 1][sy].roomno == rmno) + sx--; + else if (isok(sx + 1, sy) && !levl[sx + 1][sy].edge + && (int) levl[sx + 1][sy].roomno == rmno) + sx++; + else if (isok(sx, sy - 1) && !levl[sx][sy - 1].edge + && (int) levl[sx][sy - 1].roomno == rmno) + sy--; + else if (isok(sx, sy + 1) && !levl[sx][sy + 1].edge + && (int) levl[sx][sy + 1].roomno == rmno) + sx++; + else + goto shk_failed; + } else if (sx == sroom->lx - 1) + sx++; + else if (sx == sroom->hx + 1) + sx--; + else if (sy == sroom->ly - 1) + sy++; + else if (sy == sroom->hy + 1) + sy--; + else { + shk_failed: #ifdef DEBUG - /* Said to happen sometimes, but I have never seen it. */ - /* Supposedly fixed by fdoor change in mklev.c */ - if(wizard) { - register int j = sroom->doorct; + /* Said to happen sometimes, but I have never seen it. */ + /* Supposedly fixed by fdoor change in mklev.c */ + if (wizard) { + register int j = sroom->doorct; - pline("Where is shopdoor?"); - pline("Room at (%d,%d),(%d,%d).", - sroom->lx, sroom->ly, sroom->hx, sroom->hy); - pline("doormax=%d doorct=%d fdoor=%d", - doorindex, sroom->doorct, sh); - while(j--) { - pline("door [%d,%d]", doors[sh].x, doors[sh].y); - sh++; - } - display_nhwindow(WIN_MESSAGE, FALSE); - } + pline("Where is shopdoor?"); + pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, sroom->hx, + sroom->hy); + pline("doormax=%d doorct=%d fdoor=%d", doorindex, sroom->doorct, + sh); + while (j--) { + pline("door [%d,%d]", doors[sh].x, doors[sh].y); + sh++; + } + display_nhwindow(WIN_MESSAGE, FALSE); + } #endif - return(-1); - } + return (-1); + } - if(MON_AT(sx, sy)) (void) rloc(m_at(sx, sy), FALSE); /* insurance */ + if (MON_AT(sx, sy)) + (void) rloc(m_at(sx, sy), FALSE); /* insurance */ - /* now initialize the shopkeeper monster structure */ - if(!(shk = makemon(&mons[PM_SHOPKEEPER], sx, sy, MM_ESHK))) - return(-1); - eshkp = ESHK(shk); /* makemon(...,MM_ESHK) allocates this */ - shk->isshk = shk->mpeaceful = 1; - set_malign(shk); - shk->msleeping = 0; - shk->mtrapseen = ~0; /* we know all the traps already */ - eshkp->shoproom = (schar)((sroom - rooms) + ROOMOFFSET); - sroom->resident = shk; - eshkp->shoptype = sroom->rtype; - assign_level(&eshkp->shoplevel, &u.uz); - eshkp->shd = doors[sh]; - eshkp->shk.x = sx; - eshkp->shk.y = sy; - eshkp->robbed = eshkp->credit = eshkp->debit = eshkp->loan = 0L; - eshkp->following = eshkp->surcharge = eshkp->dismiss_kops = FALSE; - eshkp->billct = eshkp->visitct = 0; - eshkp->bill_p = (struct bill_x *)0; - eshkp->customer[0] = '\0'; - mkmonmoney(shk, 1000L + 30L*(long)rnd(100)); /* initial capital */ - if (shp->shknms == shkrings) - (void) mongets(shk, TOUCHSTONE); - nameshk(shk, shp->shknms); + /* now initialize the shopkeeper monster structure */ + if (!(shk = makemon(&mons[PM_SHOPKEEPER], sx, sy, MM_ESHK))) + return (-1); + eshkp = ESHK(shk); /* makemon(...,MM_ESHK) allocates this */ + shk->isshk = shk->mpeaceful = 1; + set_malign(shk); + shk->msleeping = 0; + shk->mtrapseen = ~0; /* we know all the traps already */ + eshkp->shoproom = (schar)((sroom - rooms) + ROOMOFFSET); + sroom->resident = shk; + eshkp->shoptype = sroom->rtype; + assign_level(&eshkp->shoplevel, &u.uz); + eshkp->shd = doors[sh]; + eshkp->shk.x = sx; + eshkp->shk.y = sy; + eshkp->robbed = eshkp->credit = eshkp->debit = eshkp->loan = 0L; + eshkp->following = eshkp->surcharge = eshkp->dismiss_kops = FALSE; + eshkp->billct = eshkp->visitct = 0; + eshkp->bill_p = (struct bill_x *) 0; + eshkp->customer[0] = '\0'; + mkmonmoney(shk, 1000L + 30L * (long) rnd(100)); /* initial capital */ + if (shp->shknms == shkrings) + (void) mongets(shk, TOUCHSTONE); + nameshk(shk, shp->shknms); - return(sh); + return (sh); } /* stock a newly-created room with objects */ @@ -584,76 +688,81 @@ register struct mkroom *sroom; int sx, sy, sh; int stockcount = 0, specialspot = 0; char buf[BUFSZ]; - int rmno = (int)((sroom - rooms) + ROOMOFFSET); + int rmno = (int) ((sroom - rooms) + ROOMOFFSET); const struct shclass *shp = &shtypes[shp_indx]; /* first, try to place a shopkeeper in the room */ if ((sh = shkinit(shp, sroom)) < 0) - return; + return; /* make sure no doorways without doors, and no */ /* trapped doors, in shops. */ sx = doors[sroom->fdoor].x; sy = doors[sroom->fdoor].y; - if(levl[sx][sy].doormask == D_NODOOR) { - levl[sx][sy].doormask = D_ISOPEN; - newsym(sx,sy); + if (levl[sx][sy].doormask == D_NODOOR) { + levl[sx][sy].doormask = D_ISOPEN; + newsym(sx, sy); } - if(levl[sx][sy].typ == SDOOR) { - cvt_sdoor_to_door(&levl[sx][sy]); /* .typ = DOOR */ - newsym(sx,sy); + if (levl[sx][sy].typ == SDOOR) { + cvt_sdoor_to_door(&levl[sx][sy]); /* .typ = DOOR */ + newsym(sx, sy); } - if(levl[sx][sy].doormask & D_TRAPPED) - levl[sx][sy].doormask = D_LOCKED; + if (levl[sx][sy].doormask & D_TRAPPED) + levl[sx][sy].doormask = D_LOCKED; - if(levl[sx][sy].doormask == D_LOCKED) { - register int m = sx, n = sy; + if (levl[sx][sy].doormask == D_LOCKED) { + register int m = sx, n = sy; - if(inside_shop(sx+1,sy)) m--; - else if(inside_shop(sx-1,sy)) m++; - if(inside_shop(sx,sy+1)) n--; - else if(inside_shop(sx,sy-1)) n++; - Sprintf(buf, "Closed for inventory"); - make_engr_at(m, n, buf, 0L, DUST); + if (inside_shop(sx + 1, sy)) + m--; + else if (inside_shop(sx - 1, sy)) + m++; + if (inside_shop(sx, sy + 1)) + n--; + else if (inside_shop(sx, sy - 1)) + n++; + Sprintf(buf, "Closed for inventory"); + make_engr_at(m, n, buf, 0L, DUST); } if (context.tribute.enabled && !context.tribute.bookstock) { - /* - * Out of the number of spots where we're actually - * going to put stuff, randomly single out one in particular. - */ - for (sx = sroom->lx; sx <= sroom->hx; sx++) - for (sy = sroom->ly; sy <= sroom->hy; sy++) { - if (sroom->irregular) { - if (levl[sx][sy].edge || (int)levl[sx][sy].roomno != rmno || - distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1) - continue; - } - else if ((sx == sroom->lx && doors[sh].x == sx - 1) || - (sx == sroom->hx && doors[sh].x == sx + 1) || - (sy == sroom->ly && doors[sh].y == sy - 1) || - (sy == sroom->hy && doors[sh].y == sy + 1)) continue; - stockcount++; - } - specialspot = rnd(stockcount); - stockcount = 0; + /* + * Out of the number of spots where we're actually + * going to put stuff, randomly single out one in particular. + */ + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) { + if (sroom->irregular) { + if (levl[sx][sy].edge || (int) levl[sx][sy].roomno != rmno + || distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1) + continue; + } else if ((sx == sroom->lx && doors[sh].x == sx - 1) + || (sx == sroom->hx && doors[sh].x == sx + 1) + || (sy == sroom->ly && doors[sh].y == sy - 1) + || (sy == sroom->hy && doors[sh].y == sy + 1)) + continue; + stockcount++; + } + specialspot = rnd(stockcount); + stockcount = 0; } - - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++) { - if(sroom->irregular) { - if (levl[sx][sy].edge || (int) levl[sx][sy].roomno != rmno || - distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1) - continue; - } else if((sx == sroom->lx && doors[sh].x == sx-1) || - (sx == sroom->hx && doors[sh].x == sx+1) || - (sy == sroom->ly && doors[sh].y == sy-1) || - (sy == sroom->hy && doors[sh].y == sy+1)) continue; - stockcount++; - mkshobj_at(shp, sx, sy, ((stockcount) && (stockcount == specialspot))); - } + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) { + if (sroom->irregular) { + if (levl[sx][sy].edge || (int) levl[sx][sy].roomno != rmno + || distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1) + continue; + } else if ((sx == sroom->lx && doors[sh].x == sx - 1) + || (sx == sroom->hx && doors[sh].x == sx + 1) + || (sy == sroom->ly && doors[sh].y == sy - 1) + || (sy == sroom->hy && doors[sh].y == sy + 1)) + continue; + stockcount++; + mkshobj_at(shp, sx, sy, + ((stockcount) && (stockcount == specialspot))); + } /* * Special monster placements (if any) should go here: that way, @@ -673,15 +782,16 @@ struct obj *obj; const struct shclass *shp = &shtypes[shp_indx]; if (shp->symb == RANDOM_CLASS) - return TRUE; + return TRUE; for (i = 0; i < SIZE(shtypes[0].iprobs) && shp->iprobs[i].iprob; i++) { - /* pseudo-class needs special handling */ - if (shp->iprobs[i].itype == VEGETARIAN_CLASS) { - if (veggy_item(obj, 0)) return TRUE; - } else if ((shp->iprobs[i].itype < 0) ? - shp->iprobs[i].itype == - obj->otyp : - shp->iprobs[i].itype == obj->oclass) - return TRUE; + /* pseudo-class needs special handling */ + if (shp->iprobs[i].itype == VEGETARIAN_CLASS) { + if (veggy_item(obj, 0)) + return TRUE; + } else if ((shp->iprobs[i].itype < 0) + ? shp->iprobs[i].itype == -obj->otyp + : shp->iprobs[i].itype == obj->oclass) + return TRUE; } /* not found */ return FALSE; @@ -692,14 +802,14 @@ int get_shop_item(type) int type; { - const struct shclass *shp = shtypes+type; - register int i,j; + const struct shclass *shp = shtypes + type; + register int i, j; - /* select an appropriate object type at random */ - for(j = rnd(100), i = 0; (j -= shp->iprobs[i].iprob) > 0; i++) - continue; + /* select an appropriate object type at random */ + for (j = rnd(100), i = 0; (j -= shp->iprobs[i].iprob) > 0; i++) + continue; - return shp->iprobs[i].itype; + return shp->iprobs[i].itype; } const char * @@ -709,23 +819,27 @@ struct monst *mtmp; const char *shknm = ESHK(mtmp)->shknam; if (Hallucination && !program_state.gameover) { - const char * const *nlp; - int num; + const char *const *nlp; + int num; - /* count the number of non-unique shop types; - pick one randomly, ignoring shop generation probabilities; - pick a name at random from that shop type's list */ - for (num = 0; num < SIZE(shtypes); num++) - if (shtypes[num].prob == 0) break; - if (num > 0) { - nlp = shtypes[rn2(num)].shknms; - for (num = 0; nlp[num]; num++) continue; - if (num > 0) shknm = nlp[rn2(num)]; - } + /* count the number of non-unique shop types; + pick one randomly, ignoring shop generation probabilities; + pick a name at random from that shop type's list */ + for (num = 0; num < SIZE(shtypes); num++) + if (shtypes[num].prob == 0) + break; + if (num > 0) { + nlp = shtypes[rn2(num)].shknms; + for (num = 0; nlp[num]; num++) + continue; + if (num > 0) + shknm = nlp[rn2(num)]; + } } /* strip prefix if present */ - if (!letter(*shknm)) ++shknm; + if (!letter(*shknm)) + ++shknm; return shknm; } @@ -745,13 +859,17 @@ boolean override_hallucination; { const char *shknm; - if (Hallucination && !override_hallucination) return FALSE; - if (!shkp->isshk) return FALSE; + if (Hallucination && !override_hallucination) + return FALSE; + if (!shkp->isshk) + return FALSE; /* outside of town, Izchak becomes just an ordinary shopkeeper */ - if (!in_town(shkp->mx, shkp->my)) return FALSE; + if (!in_town(shkp->mx, shkp->my)) + return FALSE; shknm = ESHK(shkp)->shknam; /* skip "+" prefix */ - if (!letter(*shknm)) ++shknm; + if (!letter(*shknm)) + ++shknm; return !strcmp(shknm, "Izchak"); } diff --git a/src/sit.c b/src/sit.c index e523d2a70..2f4ba1206 100644 --- a/src/sit.c +++ b/src/sit.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sit.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 sit.c $NHDT-Date: 1431192756 2015/05/09 17:32:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.48 $ */ /* NetHack 3.6 sit.c $Date: 2012/02/06 04:17:25 $ $Revision: 1.31 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,429 +9,448 @@ void take_gold() { - struct obj *otmp, *nobj; - int lost_money = 0; - for (otmp = invent; otmp; otmp = nobj) { - nobj = otmp->nobj; - if (otmp->oclass == COIN_CLASS) { - lost_money = 1; - remove_worn_item(otmp, FALSE); - delobj(otmp); - } - } - if (!lost_money) { - You_feel("a strange sensation."); - } else { - You("notice you have no money!"); - context.botl = 1; - } + struct obj *otmp, *nobj; + int lost_money = 0; + for (otmp = invent; otmp; otmp = nobj) { + nobj = otmp->nobj; + if (otmp->oclass == COIN_CLASS) { + lost_money = 1; + remove_worn_item(otmp, FALSE); + delobj(otmp); + } + } + if (!lost_money) { + You_feel("a strange sensation."); + } else { + You("notice you have no money!"); + context.botl = 1; + } } int dosit() { - static const char sit_message[] = "sit on the %s."; - register struct trap *trap = t_at(u.ux,u.uy); - register int typ = levl[u.ux][u.uy].typ; + static const char sit_message[] = "sit on the %s."; + register struct trap *trap = t_at(u.ux, u.uy); + register int typ = levl[u.ux][u.uy].typ; - if (u.usteed) { - You("are already sitting on %s.", mon_nam(u.usteed)); - return (0); - } - if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) - u.uundetected = 0; /* no longer on the ceiling */ + if (u.usteed) { + You("are already sitting on %s.", mon_nam(u.usteed)); + return (0); + } + if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) + u.uundetected = 0; /* no longer on the ceiling */ - if (!can_reach_floor(FALSE)) { - if (u.uswallow) - There("are no seats in here!"); - else if (Levitation) - You("tumble in place."); - else - You("are sitting on air."); - return 0; - } else if (u.ustuck && !sticks(youmonst.data)) { - /* holding monster is next to hero rather than beneath, but - hero is in no condition to actually sit at has/her own spot */ - if (humanoid(u.ustuck->data)) - pline("%s won't offer %s lap.", - Monnam(u.ustuck), mhis(u.ustuck)); - else - pline("%s has no lap.", Monnam(u.ustuck)); - return 0; - } else if (is_pool(u.ux, u.uy) && !Underwater) { /* water walking */ - goto in_water; - } + if (!can_reach_floor(FALSE)) { + if (u.uswallow) + There("are no seats in here!"); + else if (Levitation) + You("tumble in place."); + else + You("are sitting on air."); + return 0; + } else if (u.ustuck && !sticks(youmonst.data)) { + /* holding monster is next to hero rather than beneath, but + hero is in no condition to actually sit at has/her own spot */ + if (humanoid(u.ustuck->data)) + pline("%s won't offer %s lap.", Monnam(u.ustuck), mhis(u.ustuck)); + else + pline("%s has no lap.", Monnam(u.ustuck)); + return 0; + } else if (is_pool(u.ux, u.uy) && !Underwater) { /* water walking */ + goto in_water; + } - if (OBJ_AT(u.ux, u.uy) && - /* ensure we're not standing on the precipice */ - !uteetering_at_seen_pit(trap)) { - register struct obj *obj; + if (OBJ_AT(u.ux, u.uy) && + /* ensure we're not standing on the precipice */ + !uteetering_at_seen_pit(trap)) { + register struct obj *obj; - obj = level.objects[u.ux][u.uy]; - if (youmonst.data->mlet == S_DRAGON && obj->oclass == COIN_CLASS) { - You("coil up around your %shoard.", - (obj->quan + money_cnt(invent) < u.ulevel*1000) ? "meager " : ""); - } else { - You("sit on %s.", the(xname(obj))); - if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH)) - pline("It's not very comfortable..."); - } - } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) { - if (u.utrap) { - exercise(A_WIS, FALSE); /* you're getting stuck longer */ - if (u.utraptype == TT_BEARTRAP) { - You_cant("sit down with your %s in the bear trap.", - body_part(FOOT)); - u.utrap++; - } else if (u.utraptype == TT_PIT) { - if (trap && trap->ttyp == SPIKED_PIT) { - You("sit down on a spike. Ouch!"); - losehp(Half_physical_damage ? rn2(2) : 1, - "sitting on an iron spike", KILLED_BY); - exercise(A_STR, FALSE); - } else - You("sit down in the pit."); - u.utrap += rn2(5); - } else if (u.utraptype == TT_WEB) { - You("sit in the spider web and get entangled further!"); - u.utrap += rn1(10, 5); - } else if (u.utraptype == TT_LAVA) { - /* Must have fire resistance or they'd be dead already */ - You("sit in the lava!"); - if (Slimed) burn_away_slime(); - u.utrap += rnd(4); - losehp(d(2,10), "sitting in lava", KILLED_BY); /* lava damage */ - } else if (u.utraptype == TT_INFLOOR || - u.utraptype == TT_BURIEDBALL) { - You_cant("maneuver to sit!"); - u.utrap++; - } - } else { - You("sit down."); - dotrap(trap, 0); - } - } else if(Underwater || Is_waterlevel(&u.uz)) { - if (Is_waterlevel(&u.uz)) - There("are no cushions floating nearby."); - else - You("sit down on the muddy bottom."); - } else if(is_pool(u.ux, u.uy)) { - in_water: - You("sit in the water."); - if (!rn2(10) && uarm) - (void) water_damage(uarm, "armor", TRUE); - if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS) - (void) water_damage(uarm, "armor", TRUE); - } else if(IS_SINK(typ)) { - You(sit_message, defsyms[S_sink].explanation); - Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside"); - } else if(IS_ALTAR(typ)) { - You(sit_message, defsyms[S_altar].explanation); - altar_wrath(u.ux, u.uy); - } else if(IS_GRAVE(typ)) { - You(sit_message, defsyms[S_grave].explanation); - } else if(typ == STAIRS) { - You(sit_message, "stairs"); - } else if(typ == LADDER) { - You(sit_message, "ladder"); - } else if (is_lava(u.ux, u.uy)) { - /* must be WWalking */ - You(sit_message, "lava"); - burn_away_slime(); - if (likes_lava(youmonst.data)) { - pline_The("lava feels warm."); - return 1; - } - pline_The("lava burns you!"); - losehp(d((Fire_resistance ? 2 : 10), 10), /* lava damage */ - "sitting on lava", KILLED_BY); - } else if (is_ice(u.ux, u.uy)) { - You(sit_message, defsyms[S_ice].explanation); - if (!Cold_resistance) pline_The("ice feels cold."); - } else if (typ == DRAWBRIDGE_DOWN) { - You(sit_message, "drawbridge"); - } else if(IS_THRONE(typ)) { - You(sit_message, defsyms[S_throne].explanation); - if (rnd(6) > 4) { - switch (rnd(13)) { - case 1: - (void) adjattrib(rn2(A_MAX), -rn1(4,3), FALSE); - losehp(rnd(10), "cursed throne", KILLED_BY_AN); - break; - case 2: - (void) adjattrib(rn2(A_MAX), 1, FALSE); - break; - case 3: - pline("A%s electric shock shoots through your body!", - (Shock_resistance) ? "n" : " massive"); - losehp(Shock_resistance ? rnd(6) : rnd(30), - "electric chair", KILLED_BY_AN); - exercise(A_CON, FALSE); - break; - case 4: - You_feel("much, much better!"); - if (Upolyd) { - if (u.mh >= (u.mhmax - 5)) u.mhmax += 4; - u.mh = u.mhmax; - } - if(u.uhp >= (u.uhpmax - 5)) u.uhpmax += 4; - u.uhp = u.uhpmax; - make_blinded(0L,TRUE); - make_sick(0L, (char *) 0, FALSE, SICK_ALL); - heal_legs(); - context.botl = 1; - break; - case 5: - take_gold(); - break; - case 6: - if(u.uluck + rn2(5) < 0) { - You_feel("your luck is changing."); - change_luck(1); - } else makewish(); - break; - case 7: - { - register int cnt = rnd(10); + obj = level.objects[u.ux][u.uy]; + if (youmonst.data->mlet == S_DRAGON && obj->oclass == COIN_CLASS) { + You("coil up around your %shoard.", + (obj->quan + money_cnt(invent) < u.ulevel * 1000) ? "meager " + : ""); + } else { + You("sit on %s.", the(xname(obj))); + if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH)) + pline("It's not very comfortable..."); + } + } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) { + if (u.utrap) { + exercise(A_WIS, FALSE); /* you're getting stuck longer */ + if (u.utraptype == TT_BEARTRAP) { + You_cant("sit down with your %s in the bear trap.", + body_part(FOOT)); + u.utrap++; + } else if (u.utraptype == TT_PIT) { + if (trap && trap->ttyp == SPIKED_PIT) { + You("sit down on a spike. Ouch!"); + losehp(Half_physical_damage ? rn2(2) : 1, + "sitting on an iron spike", KILLED_BY); + exercise(A_STR, FALSE); + } else + You("sit down in the pit."); + u.utrap += rn2(5); + } else if (u.utraptype == TT_WEB) { + You("sit in the spider web and get entangled further!"); + u.utrap += rn1(10, 5); + } else if (u.utraptype == TT_LAVA) { + /* Must have fire resistance or they'd be dead already */ + You("sit in the lava!"); + if (Slimed) + burn_away_slime(); + u.utrap += rnd(4); + losehp(d(2, 10), "sitting in lava", + KILLED_BY); /* lava damage */ + } else if (u.utraptype == TT_INFLOOR + || u.utraptype == TT_BURIEDBALL) { + You_cant("maneuver to sit!"); + u.utrap++; + } + } else { + You("sit down."); + dotrap(trap, 0); + } + } else if (Underwater || Is_waterlevel(&u.uz)) { + if (Is_waterlevel(&u.uz)) + There("are no cushions floating nearby."); + else + You("sit down on the muddy bottom."); + } else if (is_pool(u.ux, u.uy)) { + in_water: + You("sit in the water."); + if (!rn2(10) && uarm) + (void) water_damage(uarm, "armor", TRUE); + if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS) + (void) water_damage(uarm, "armor", TRUE); + } else if (IS_SINK(typ)) { + You(sit_message, defsyms[S_sink].explanation); + Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside"); + } else if (IS_ALTAR(typ)) { + You(sit_message, defsyms[S_altar].explanation); + altar_wrath(u.ux, u.uy); + } else if (IS_GRAVE(typ)) { + You(sit_message, defsyms[S_grave].explanation); + } else if (typ == STAIRS) { + You(sit_message, "stairs"); + } else if (typ == LADDER) { + You(sit_message, "ladder"); + } else if (is_lava(u.ux, u.uy)) { + /* must be WWalking */ + You(sit_message, "lava"); + burn_away_slime(); + if (likes_lava(youmonst.data)) { + pline_The("lava feels warm."); + return 1; + } + pline_The("lava burns you!"); + losehp(d((Fire_resistance ? 2 : 10), 10), /* lava damage */ + "sitting on lava", KILLED_BY); + } else if (is_ice(u.ux, u.uy)) { + You(sit_message, defsyms[S_ice].explanation); + if (!Cold_resistance) + pline_The("ice feels cold."); + } else if (typ == DRAWBRIDGE_DOWN) { + You(sit_message, "drawbridge"); + } else if (IS_THRONE(typ)) { + You(sit_message, defsyms[S_throne].explanation); + if (rnd(6) > 4) { + switch (rnd(13)) { + case 1: + (void) adjattrib(rn2(A_MAX), -rn1(4, 3), FALSE); + losehp(rnd(10), "cursed throne", KILLED_BY_AN); + break; + case 2: + (void) adjattrib(rn2(A_MAX), 1, FALSE); + break; + case 3: + pline("A%s electric shock shoots through your body!", + (Shock_resistance) ? "n" : " massive"); + losehp(Shock_resistance ? rnd(6) : rnd(30), "electric chair", + KILLED_BY_AN); + exercise(A_CON, FALSE); + break; + case 4: + You_feel("much, much better!"); + if (Upolyd) { + if (u.mh >= (u.mhmax - 5)) + u.mhmax += 4; + u.mh = u.mhmax; + } + if (u.uhp >= (u.uhpmax - 5)) + u.uhpmax += 4; + u.uhp = u.uhpmax; + make_blinded(0L, TRUE); + make_sick(0L, (char *) 0, FALSE, SICK_ALL); + heal_legs(); + context.botl = 1; + break; + case 5: + take_gold(); + break; + case 6: + if (u.uluck + rn2(5) < 0) { + You_feel("your luck is changing."); + change_luck(1); + } else + makewish(); + break; + case 7: { + register int cnt = rnd(10); - /* Magical voice not affected by deafness */ - pline("A voice echoes:"); - verbalize("Thy audience hath been summoned, %s!", - flags.female ? "Dame" : "Sire"); - while(cnt--) - (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS); - break; - } - case 8: - /* Magical voice not affected by deafness */ - pline("A voice echoes:"); - verbalize("By thine Imperious order, %s...", - flags.female ? "Dame" : "Sire"); - do_genocide(5); /* REALLY|ONTHRONE, see do_genocide() */ - break; - case 9: - /* Magical voice not affected by deafness */ - pline("A voice echoes:"); - verbalize("A curse upon thee for sitting upon this most holy throne!"); - if (Luck > 0) { - make_blinded(Blinded + rn1(100,250),TRUE); - } else rndcurse(); - break; - case 10: - if (Luck < 0 || (HSee_invisible & INTRINSIC)) { - if (level.flags.nommap) { - pline("A terrible drone fills your head!"); - make_confused((HConfusion & TIMEOUT) + - (long)rnd(30), FALSE); - } else { - pline("An image forms in your mind."); - do_mapping(); - } - } else { - Your("vision becomes clear."); - HSee_invisible |= FROMOUTSIDE; - newsym(u.ux, u.uy); - } - break; - case 11: - if (Luck < 0) { - You_feel("threatened."); - aggravate(); - } else { + /* Magical voice not affected by deafness */ + pline("A voice echoes:"); + verbalize("Thy audience hath been summoned, %s!", + flags.female ? "Dame" : "Sire"); + while (cnt--) + (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS); + break; + } + case 8: + /* Magical voice not affected by deafness */ + pline("A voice echoes:"); + verbalize("By thine Imperious order, %s...", + flags.female ? "Dame" : "Sire"); + do_genocide(5); /* REALLY|ONTHRONE, see do_genocide() */ + break; + case 9: + /* Magical voice not affected by deafness */ + pline("A voice echoes:"); + verbalize("A curse upon thee for sitting upon this most holy " + "throne!"); + if (Luck > 0) { + make_blinded(Blinded + rn1(100, 250), TRUE); + } else + rndcurse(); + break; + case 10: + if (Luck < 0 || (HSee_invisible & INTRINSIC)) { + if (level.flags.nommap) { + pline("A terrible drone fills your head!"); + make_confused((HConfusion & TIMEOUT) + (long) rnd(30), + FALSE); + } else { + pline("An image forms in your mind."); + do_mapping(); + } + } else { + Your("vision becomes clear."); + HSee_invisible |= FROMOUTSIDE; + newsym(u.ux, u.uy); + } + break; + case 11: + if (Luck < 0) { + You_feel("threatened."); + aggravate(); + } else { + You_feel("a wrenching sensation."); + tele(); /* teleport him */ + } + break; + case 12: + You("are granted an insight!"); + if (invent) { + /* rn2(5) agrees w/seffects() */ + identify_pack(rn2(5), FALSE); + } + break; + case 13: + Your("mind turns into a pretzel!"); + make_confused((HConfusion & TIMEOUT) + (long) rn1(7, 16), + FALSE); + break; + default: + impossible("throne effect"); + break; + } + } else { + if (is_prince(youmonst.data)) + You_feel("very comfortable here."); + else + You_feel("somehow out of place..."); + } - You_feel("a wrenching sensation."); - tele(); /* teleport him */ - } - break; - case 12: - You("are granted an insight!"); - if (invent) { - /* rn2(5) agrees w/seffects() */ - identify_pack(rn2(5), FALSE); - } - break; - case 13: - Your("mind turns into a pretzel!"); - make_confused((HConfusion & TIMEOUT) + (long)rn1(7,16), - FALSE); - break; - default: impossible("throne effect"); - break; - } - } else { - if (is_prince(youmonst.data)) - You_feel("very comfortable here."); - else - You_feel("somehow out of place..."); - } + if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) { + /* may have teleported */ + levl[u.ux][u.uy].typ = ROOM; + pline_The("throne vanishes in a puff of logic."); + newsym(u.ux, u.uy); + } + } else if (lays_eggs(youmonst.data)) { + struct obj *uegg; - if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) { - /* may have teleported */ - levl[u.ux][u.uy].typ = ROOM; - pline_The("throne vanishes in a puff of logic."); - newsym(u.ux,u.uy); - } - } else if (lays_eggs(youmonst.data)) { - struct obj *uegg; + if (!flags.female) { + pline(Hallucination ? "You may think you are a platypus but a " + "male still can't lay eggs!" + : "Males can't lay eggs!"); + return 0; + } else if (u.uhunger < (int) objects[EGG].oc_nutrition) { + You("don't have enough energy to lay an egg."); + return 0; + } - if (!flags.female) { - pline(Hallucination ? - "You may think you are a platypus but a male still can't lay eggs!" : - "Males can't lay eggs!"); - return 0; - } else if (u.uhunger < (int)objects[EGG].oc_nutrition) { - You("don't have enough energy to lay an egg."); - return 0; - } - - uegg = mksobj(EGG, FALSE, FALSE); - uegg->spe = 1; - uegg->quan = 1L; - uegg->owt = weight(uegg); - /* this sets hatch timers if appropriate */ - set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE)); - uegg->known = uegg->dknown = 1; - You("lay an egg."); - dropy(uegg); - stackobj(uegg); - morehungry((int)objects[EGG].oc_nutrition); - } else { - pline("Having fun sitting on the %s?", surface(u.ux,u.uy)); - } - return(1); + uegg = mksobj(EGG, FALSE, FALSE); + uegg->spe = 1; + uegg->quan = 1L; + uegg->owt = weight(uegg); + /* this sets hatch timers if appropriate */ + set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE)); + uegg->known = uegg->dknown = 1; + You("lay an egg."); + dropy(uegg); + stackobj(uegg); + morehungry((int) objects[EGG].oc_nutrition); + } else { + pline("Having fun sitting on the %s?", surface(u.ux, u.uy)); + } + return (1); } -void -rndcurse() /* curse a few inventory items at random! */ +void rndcurse() /* curse a few inventory items at random! */ { - int nobj = 0; - int cnt, onum; - struct obj *otmp; - static const char mal_aura[] = "feel a malignant aura surround %s."; + int nobj = 0; + int cnt, onum; + struct obj *otmp; + static const char mal_aura[] = "feel a malignant aura surround %s."; - if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { - You(mal_aura, "the magic-absorbing blade"); - return; - } + if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { + You(mal_aura, "the magic-absorbing blade"); + return; + } - if(Antimagic) { - shieldeff(u.ux, u.uy); - You(mal_aura, "you"); - } + if (Antimagic) { + shieldeff(u.ux, u.uy); + You(mal_aura, "you"); + } - for (otmp = invent; otmp; otmp = otmp->nobj) { - /* gold isn't subject to being cursed or blessed */ - if (otmp->oclass == COIN_CLASS) continue; - nobj++; - } - if (nobj) { - for (cnt = rnd(6/((!!Antimagic) + (!!Half_spell_damage) + 1)); - cnt > 0; cnt--) { - onum = rnd(nobj); - for (otmp = invent; otmp; otmp = otmp->nobj) { - /* as above */ - if (otmp->oclass == COIN_CLASS) continue; - if (--onum == 0) break; /* found the target */ - } - /* the !otmp case should never happen; picking an already - cursed item happens--avoid "resists" message in that case */ - if (!otmp || otmp->cursed) continue; /* next target */ + for (otmp = invent; otmp; otmp = otmp->nobj) { + /* gold isn't subject to being cursed or blessed */ + if (otmp->oclass == COIN_CLASS) + continue; + nobj++; + } + if (nobj) { + for (cnt = rnd(6 / ((!!Antimagic) + (!!Half_spell_damage) + 1)); + cnt > 0; cnt--) { + onum = rnd(nobj); + for (otmp = invent; otmp; otmp = otmp->nobj) { + /* as above */ + if (otmp->oclass == COIN_CLASS) + continue; + if (--onum == 0) + break; /* found the target */ + } + /* the !otmp case should never happen; picking an already + cursed item happens--avoid "resists" message in that case */ + if (!otmp || otmp->cursed) + continue; /* next target */ - if(otmp->oartifact && spec_ability(otmp, SPFX_INTEL) && - rn2(10) < 8) { - pline("%s!", Tobjnam(otmp, "resist")); - continue; - } + if (otmp->oartifact && spec_ability(otmp, SPFX_INTEL) + && rn2(10) < 8) { + pline("%s!", Tobjnam(otmp, "resist")); + continue; + } - if(otmp->blessed) - unbless(otmp); - else - curse(otmp); - } - update_inventory(); - } + if (otmp->blessed) + unbless(otmp); + else + curse(otmp); + } + update_inventory(); + } - /* treat steed's saddle as extended part of hero's inventory */ - if (u.usteed && !rn2(4) && - (otmp = which_armor(u.usteed, W_SADDLE)) != 0 && - !otmp->cursed) { /* skip if already cursed */ - if (otmp->blessed) - unbless(otmp); - else - curse(otmp); - if (!Blind) { - pline("%s %s.", - Yobjnam2(otmp, "glow"), - hcolor(otmp->cursed ? NH_BLACK : (const char *)"brown")); - otmp->bknown = TRUE; - } - } + /* treat steed's saddle as extended part of hero's inventory */ + if (u.usteed && !rn2(4) && (otmp = which_armor(u.usteed, W_SADDLE)) != 0 + && !otmp->cursed) { /* skip if already cursed */ + if (otmp->blessed) + unbless(otmp); + else + curse(otmp); + if (!Blind) { + pline("%s %s.", Yobjnam2(otmp, "glow"), + hcolor(otmp->cursed ? NH_BLACK : (const char *) "brown")); + otmp->bknown = TRUE; + } + } } -void -attrcurse() /* remove a random INTRINSIC ability */ +void attrcurse() /* remove a random INTRINSIC ability */ { - switch(rnd(11)) { - case 1 : if (HFire_resistance & INTRINSIC) { - HFire_resistance &= ~INTRINSIC; - You_feel("warmer."); - break; - } - case 2 : if (HTeleportation & INTRINSIC) { - HTeleportation &= ~INTRINSIC; - You_feel("less jumpy."); - break; - } - case 3 : if (HPoison_resistance & INTRINSIC) { - HPoison_resistance &= ~INTRINSIC; - You_feel("a little sick!"); - break; - } - case 4 : if (HTelepat & INTRINSIC) { - HTelepat &= ~INTRINSIC; - if (Blind && !Blind_telepat) - see_monsters(); /* Can't sense mons anymore! */ - Your("senses fail!"); - break; - } - case 5 : if (HCold_resistance & INTRINSIC) { - HCold_resistance &= ~INTRINSIC; - You_feel("cooler."); - break; - } - case 6 : if (HInvis & INTRINSIC) { - HInvis &= ~INTRINSIC; - You_feel("paranoid."); - break; - } - case 7 : if (HSee_invisible & INTRINSIC) { - HSee_invisible &= ~INTRINSIC; - You("%s!", Hallucination ? "tawt you taw a puttie tat" - : "thought you saw something"); - break; - } - case 8 : if (HFast & INTRINSIC) { - HFast &= ~INTRINSIC; - You_feel("slower."); - break; - } - case 9 : if (HStealth & INTRINSIC) { - HStealth &= ~INTRINSIC; - You_feel("clumsy."); - break; - } - case 10: if (HProtection & INTRINSIC) { - HProtection &= ~INTRINSIC; - You_feel("vulnerable."); - break; - } - case 11: if (HAggravate_monster & INTRINSIC) { - HAggravate_monster &= ~INTRINSIC; - You_feel("less attractive."); - break; - } - default: break; - } + switch (rnd(11)) { + case 1: + if (HFire_resistance & INTRINSIC) { + HFire_resistance &= ~INTRINSIC; + You_feel("warmer."); + break; + } + case 2: + if (HTeleportation & INTRINSIC) { + HTeleportation &= ~INTRINSIC; + You_feel("less jumpy."); + break; + } + case 3: + if (HPoison_resistance & INTRINSIC) { + HPoison_resistance &= ~INTRINSIC; + You_feel("a little sick!"); + break; + } + case 4: + if (HTelepat & INTRINSIC) { + HTelepat &= ~INTRINSIC; + if (Blind && !Blind_telepat) + see_monsters(); /* Can't sense mons anymore! */ + Your("senses fail!"); + break; + } + case 5: + if (HCold_resistance & INTRINSIC) { + HCold_resistance &= ~INTRINSIC; + You_feel("cooler."); + break; + } + case 6: + if (HInvis & INTRINSIC) { + HInvis &= ~INTRINSIC; + You_feel("paranoid."); + break; + } + case 7: + if (HSee_invisible & INTRINSIC) { + HSee_invisible &= ~INTRINSIC; + You("%s!", Hallucination ? "tawt you taw a puttie tat" + : "thought you saw something"); + break; + } + case 8: + if (HFast & INTRINSIC) { + HFast &= ~INTRINSIC; + You_feel("slower."); + break; + } + case 9: + if (HStealth & INTRINSIC) { + HStealth &= ~INTRINSIC; + You_feel("clumsy."); + break; + } + case 10: + if (HProtection & INTRINSIC) { + HProtection &= ~INTRINSIC; + You_feel("vulnerable."); + break; + } + case 11: + if (HAggravate_monster & INTRINSIC) { + HAggravate_monster &= ~INTRINSIC; + You_feel("less attractive."); + break; + } + default: + break; + } } /*sit.c*/ diff --git a/src/sounds.c b/src/sounds.c index 1924c7b2c..ba8b518c4 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sounds.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 sounds.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.60 $ */ /* NetHack 3.6 sounds.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.39 $ */ /* Copyright (c) 1989 Janet Walz, Mike Threepoint */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,16 +6,16 @@ #include "hack.h" #ifdef USER_SOUNDS -# ifdef USER_SOUNDS_REGEX +#ifdef USER_SOUNDS_REGEX #include #include -# endif +#endif #endif STATIC_DCL boolean FDECL(mon_is_gecko, (struct monst *)); -STATIC_DCL int FDECL(domonnoise,(struct monst *)); +STATIC_DCL int FDECL(domonnoise, (struct monst *)); STATIC_DCL int NDECL(dochat); -STATIC_DCL int FDECL(mon_in_room, (struct monst *,int)); +STATIC_DCL int FDECL(mon_in_room, (struct monst *, int)); /* this easily could be a macro, but it might overtax dumb compilers */ STATIC_OVL int @@ -38,319 +38,321 @@ dosounds() #endif struct monst *mtmp; - if (Deaf || !flags.acoustics || u.uswallow || Underwater) return; + if (Deaf || !flags.acoustics || u.uswallow || Underwater) + return; hallu = Hallucination ? 1 : 0; if (level.flags.nfountains && !rn2(400)) { - static const char * const fountain_msg[4] = { - "bubbling water.", - "water falling on coins.", - "the splashing of a naiad.", - "a soda fountain!", - }; - You_hear1(fountain_msg[rn2(3)+hallu]); + static const char *const fountain_msg[4] = { + "bubbling water.", "water falling on coins.", + "the splashing of a naiad.", "a soda fountain!", + }; + You_hear1(fountain_msg[rn2(3) + hallu]); } if (level.flags.nsinks && !rn2(300)) { - static const char * const sink_msg[3] = { - "a slow drip.", - "a gurgling noise.", - "dishes being washed!", - }; - You_hear1(sink_msg[rn2(2)+hallu]); + static const char *const sink_msg[3] = { + "a slow drip.", "a gurgling noise.", "dishes being washed!", + }; + You_hear1(sink_msg[rn2(2) + hallu]); } if (level.flags.has_court && !rn2(200)) { - static const char * const throne_msg[4] = { - "the tones of courtly conversation.", - "a sceptre pounded in judgment.", - "Someone shouts \"Off with %s head!\"", - "Queen Beruthiel's cats!", - }; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((mtmp->msleeping || - is_lord(mtmp->data) || is_prince(mtmp->data)) && - !is_animal(mtmp->data) && - mon_in_room(mtmp, COURT)) { - /* finding one is enough, at least for now */ - int which = rn2(3)+hallu; + static const char *const throne_msg[4] = { + "the tones of courtly conversation.", + "a sceptre pounded in judgment.", + "Someone shouts \"Off with %s head!\"", "Queen Beruthiel's cats!", + }; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((mtmp->msleeping || is_lord(mtmp->data) + || is_prince(mtmp->data)) && !is_animal(mtmp->data) + && mon_in_room(mtmp, COURT)) { + /* finding one is enough, at least for now */ + int which = rn2(3) + hallu; - if (which != 2) You_hear1(throne_msg[which]); - else pline(throne_msg[2], uhis()); - return; - } - } + if (which != 2) + You_hear1(throne_msg[which]); + else + pline(throne_msg[2], uhis()); + return; + } + } } if (level.flags.has_swamp && !rn2(200)) { - static const char * const swamp_msg[3] = { - "hear mosquitoes!", - "smell marsh gas!", /* so it's a smell...*/ - "hear Donald Duck!", - }; - You1(swamp_msg[rn2(2)+hallu]); - return; + static const char *const swamp_msg[3] = { + "hear mosquitoes!", "smell marsh gas!", /* so it's a smell...*/ + "hear Donald Duck!", + }; + You1(swamp_msg[rn2(2) + hallu]); + return; } if (level.flags.has_vault && !rn2(200)) { - if (!(sroom = search_special(VAULT))) { - /* strange ... */ - level.flags.has_vault = 0; - return; - } - if(gd_sound()) - switch (rn2(2)+hallu) { - case 1: { - boolean gold_in_vault = FALSE; + if (!(sroom = search_special(VAULT))) { + /* strange ... */ + level.flags.has_vault = 0; + return; + } + if (gd_sound()) + switch (rn2(2) + hallu) { + case 1: { + boolean gold_in_vault = FALSE; - for (vx = sroom->lx;vx <= sroom->hx; vx++) - for (vy = sroom->ly; vy <= sroom->hy; vy++) - if (g_at(vx, vy)) - gold_in_vault = TRUE; + for (vx = sroom->lx; vx <= sroom->hx; vx++) + for (vy = sroom->ly; vy <= sroom->hy; vy++) + if (g_at(vx, vy)) + gold_in_vault = TRUE; #if defined(AMIGA) && defined(AZTEC_C_WORKAROUND) - /* Bug in aztec assembler here. Workaround below */ - xx = ROOM_INDEX(sroom) + ROOMOFFSET; - xx = (xx != vault_occupied(u.urooms)); - if(xx) + /* Bug in aztec assembler here. Workaround below */ + xx = ROOM_INDEX(sroom) + ROOMOFFSET; + xx = (xx != vault_occupied(u.urooms)); + if (xx) #else - if (vault_occupied(u.urooms) != - (ROOM_INDEX(sroom) + ROOMOFFSET)) + if (vault_occupied(u.urooms) + != (ROOM_INDEX(sroom) + ROOMOFFSET)) #endif /* AZTEC_C_WORKAROUND */ - { - if (gold_in_vault) - You_hear(!hallu ? "someone counting money." : - "the quarterback calling the play."); - else - You_hear("someone searching."); - break; - } - /* fall into... (yes, even for hallucination) */ - } - case 0: - You_hear("the footsteps of a guard on patrol."); - break; - case 2: - You_hear("Ebenezer Scrooge!"); - break; - } - return; + { + if (gold_in_vault) + You_hear(!hallu + ? "someone counting money." + : "the quarterback calling the play."); + else + You_hear("someone searching."); + break; + } + /* fall into... (yes, even for hallucination) */ + } + case 0: + You_hear("the footsteps of a guard on patrol."); + break; + case 2: + You_hear("Ebenezer Scrooge!"); + break; + } + return; } if (level.flags.has_beehive && !rn2(200)) { - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((mtmp->data->mlet == S_ANT && is_flyer(mtmp->data)) && - mon_in_room(mtmp, BEEHIVE)) { - switch (rn2(2)+hallu) { - case 0: - You_hear("a low buzzing."); - break; - case 1: - You_hear("an angry drone."); - break; - case 2: - You_hear("bees in your %sbonnet!", - uarmh ? "" : "(nonexistent) "); - break; - } - return; - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((mtmp->data->mlet == S_ANT && is_flyer(mtmp->data)) + && mon_in_room(mtmp, BEEHIVE)) { + switch (rn2(2) + hallu) { + case 0: + You_hear("a low buzzing."); + break; + case 1: + You_hear("an angry drone."); + break; + case 2: + You_hear("bees in your %sbonnet!", + uarmh ? "" : "(nonexistent) "); + break; + } + return; + } + } } if (level.flags.has_morgue && !rn2(200)) { - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((is_undead(mtmp->data) || is_vampshifter(mtmp)) && - mon_in_room(mtmp, MORGUE)) { - const char *hair = body_part(HAIR); /* hair/fur/scales */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((is_undead(mtmp->data) || is_vampshifter(mtmp)) + && mon_in_room(mtmp, MORGUE)) { + const char *hair = body_part(HAIR); /* hair/fur/scales */ - switch (rn2(2)+hallu) { - case 0: - You("suddenly realize it is unnaturally quiet."); - break; - case 1: - pline_The("%s on the back of your %s %s up.", - hair, body_part(NECK), vtense(hair, "stand")); - break; - case 2: - pline_The("%s on your %s %s to stand up.", - hair, body_part(HEAD), vtense(hair, "seem")); - break; - } - return; - } - } + switch (rn2(2) + hallu) { + case 0: + You("suddenly realize it is unnaturally quiet."); + break; + case 1: + pline_The("%s on the back of your %s %s up.", hair, + body_part(NECK), vtense(hair, "stand")); + break; + case 2: + pline_The("%s on your %s %s to stand up.", hair, + body_part(HEAD), vtense(hair, "seem")); + break; + } + return; + } + } } if (level.flags.has_barracks && !rn2(200)) { - static const char * const barracks_msg[4] = { - "blades being honed.", - "loud snoring.", - "dice being thrown.", - "General MacArthur!", - }; - int count = 0; + static const char *const barracks_msg[4] = { + "blades being honed.", "loud snoring.", "dice being thrown.", + "General MacArthur!", + }; + int count = 0; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (is_mercenary(mtmp->data) && -#if 0 /* don't bother excluding these */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (is_mercenary(mtmp->data) && +#if 0 /* don't bother excluding these */ !strstri(mtmp->data->mname, "watch") && !strstri(mtmp->data->mname, "guard") && #endif - mon_in_room(mtmp, BARRACKS) && - /* sleeping implies not-yet-disturbed (usually) */ - (mtmp->msleeping || ++count > 5)) { - You_hear1(barracks_msg[rn2(3)+hallu]); - return; - } - } + mon_in_room(mtmp, BARRACKS) && + /* sleeping implies not-yet-disturbed (usually) */ + (mtmp->msleeping || ++count > 5)) { + You_hear1(barracks_msg[rn2(3) + hallu]); + return; + } + } } if (level.flags.has_zoo && !rn2(200)) { - static const char * const zoo_msg[3] = { - "a sound reminiscent of an elephant stepping on a peanut.", - "a sound reminiscent of a seal barking.", - "Doctor Dolittle!", - }; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if ((mtmp->msleeping || is_animal(mtmp->data)) && - mon_in_room(mtmp, ZOO)) { - You_hear1(zoo_msg[rn2(2)+hallu]); - return; - } - } + static const char *const zoo_msg[3] = { + "a sound reminiscent of an elephant stepping on a peanut.", + "a sound reminiscent of a seal barking.", "Doctor Dolittle!", + }; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if ((mtmp->msleeping || is_animal(mtmp->data)) + && mon_in_room(mtmp, ZOO)) { + You_hear1(zoo_msg[rn2(2) + hallu]); + return; + } + } } if (level.flags.has_shop && !rn2(200)) { - if (!(sroom = search_special(ANY_SHOP))) { - /* strange... */ - level.flags.has_shop = 0; - return; - } - if (tended_shop(sroom) && - !index(u.ushops, (int)(ROOM_INDEX(sroom) + ROOMOFFSET))) { - static const char * const shop_msg[3] = { - "someone cursing shoplifters.", - "the chime of a cash register.", - "Neiman and Marcus arguing!", - }; - You_hear1(shop_msg[rn2(2)+hallu]); - } - return; + if (!(sroom = search_special(ANY_SHOP))) { + /* strange... */ + level.flags.has_shop = 0; + return; + } + if (tended_shop(sroom) + && !index(u.ushops, (int) (ROOM_INDEX(sroom) + ROOMOFFSET))) { + static const char *const shop_msg[3] = { + "someone cursing shoplifters.", + "the chime of a cash register.", "Neiman and Marcus arguing!", + }; + You_hear1(shop_msg[rn2(2) + hallu]); + } + return; } - if (level.flags.has_temple && !rn2(200) && - !(Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) { - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->ispriest && inhistemple(mtmp) && - /* priest must be active */ - mtmp->mcanmove && !mtmp->msleeping && - /* hero must be outside this temple */ - temple_occupied(u.urooms) != EPRI(mtmp)->shroom) - break; - } - if (mtmp) { - /* Generic temple messages; no attempt to match topic or tone - to the pantheon involved, let alone to the specific deity. - These are assumed to be coming from the attending priest; - asterisk means that the priest must be capable of speech; - pound sign (octathorpe,&c--don't go there) means that the - priest and the altar must not be directly visible (we don't - care if telepathy or extended detection reveals that the - priest is not currently standing on the altar; he's mobile). */ - static const char * const temple_msg[] = { - "*someone praising %s.", - "*someone beseeching %s.", - "#an animal carcass being offered in sacrifice.", - "*a strident plea for donations.", - }; - const char *msg; - int trycount = 0, - ax = EPRI(mtmp)->shrpos.x, ay = EPRI(mtmp)->shrpos.y; - boolean speechless = (mtmp->data->msound <= MS_ANIMAL), - in_sight = canseemon(mtmp) || cansee(ax, ay); + if (level.flags.has_temple && !rn2(200) + && !(Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->ispriest && inhistemple(mtmp) && + /* priest must be active */ + mtmp->mcanmove && !mtmp->msleeping && + /* hero must be outside this temple */ + temple_occupied(u.urooms) != EPRI(mtmp)->shroom) + break; + } + if (mtmp) { + /* Generic temple messages; no attempt to match topic or tone + to the pantheon involved, let alone to the specific deity. + These are assumed to be coming from the attending priest; + asterisk means that the priest must be capable of speech; + pound sign (octathorpe,&c--don't go there) means that the + priest and the altar must not be directly visible (we don't + care if telepathy or extended detection reveals that the + priest is not currently standing on the altar; he's mobile). */ + static const char *const temple_msg[] = { + "*someone praising %s.", "*someone beseeching %s.", + "#an animal carcass being offered in sacrifice.", + "*a strident plea for donations.", + }; + const char *msg; + int trycount = 0, ax = EPRI(mtmp)->shrpos.x, + ay = EPRI(mtmp)->shrpos.y; + boolean speechless = (mtmp->data->msound <= MS_ANIMAL), + in_sight = canseemon(mtmp) || cansee(ax, ay); - do { - msg = temple_msg[rn2(SIZE(temple_msg) - 1 + hallu)]; - if (index(msg, '*') && speechless) continue; - if (index(msg, '#') && in_sight) continue; - break; /* msg is acceptable */ - } while (++trycount < 50); - while (!letter(*msg)) ++msg; /* skip control flags */ - if (index(msg, '%')) - You_hear(msg, halu_gname(EPRI(mtmp)->shralign)); - else - You_hear1(msg); - return; - } + do { + msg = temple_msg[rn2(SIZE(temple_msg) - 1 + hallu)]; + if (index(msg, '*') && speechless) + continue; + if (index(msg, '#') && in_sight) + continue; + break; /* msg is acceptable */ + } while (++trycount < 50); + while (!letter(*msg)) + ++msg; /* skip control flags */ + if (index(msg, '%')) + You_hear(msg, halu_gname(EPRI(mtmp)->shralign)); + else + You_hear1(msg); + return; + } } if (Is_oracle_level(&u.uz) && !rn2(400)) { - /* make sure the Oracle is still here */ - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->data == &mons[PM_ORACLE]) - break; - } - /* and don't produce silly effects when she's clearly visible */ - if (mtmp && (hallu || !canseemon(mtmp))) { - static const char * const ora_msg[5] = { - "a strange wind.", /* Jupiter at Dodona */ - "convulsive ravings.", /* Apollo at Delphi */ - "snoring snakes.", /* AEsculapius at Epidaurus */ - "someone say \"No more woodchucks!\"", - "a loud ZOT!" /* both rec.humor.oracle */ - }; - You_hear1(ora_msg[rn2(3)+hallu*2]); - } - return; + /* make sure the Oracle is still here */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->data == &mons[PM_ORACLE]) + break; + } + /* and don't produce silly effects when she's clearly visible */ + if (mtmp && (hallu || !canseemon(mtmp))) { + static const char *const ora_msg[5] = { + "a strange wind.", /* Jupiter at Dodona */ + "convulsive ravings.", /* Apollo at Delphi */ + "snoring snakes.", /* AEsculapius at Epidaurus */ + "someone say \"No more woodchucks!\"", + "a loud ZOT!" /* both rec.humor.oracle */ + }; + You_hear1(ora_msg[rn2(3) + hallu * 2]); + } + return; } } -static const char * const h_sounds[] = { - "beep", "boing", "sing", "belche", "creak", "cough", "rattle", - "ululate", "pop", "jingle", "sniffle", "tinkle", "eep", - "clatter", "hum", "sizzle", "twitter", "wheeze", "rustle", - "honk", "lisp", "yodel", "coo", "burp", "moo", "boom", - "murmur", "oink", "quack", "rumble", "twang", "bellow", - "toot", "gargle", "hoot", "warble" +static const char *const h_sounds[] = { + "beep", "boing", "sing", "belche", "creak", "cough", + "rattle", "ululate", "pop", "jingle", "sniffle", "tinkle", + "eep", "clatter", "hum", "sizzle", "twitter", "wheeze", + "rustle", "honk", "lisp", "yodel", "coo", "burp", + "moo", "boom", "murmur", "oink", "quack", "rumble", + "twang", "bellow", "toot", "gargle", "hoot", "warble" }; const char * growl_sound(mtmp) register struct monst *mtmp; { - const char *ret; + const char *ret; - switch (mtmp->data->msound) { - case MS_MEW: - case MS_HISS: - ret = "hiss"; - break; - case MS_BARK: - case MS_GROWL: - ret = "growl"; - break; - case MS_ROAR: - ret = "roar"; - break; - case MS_BUZZ: - ret = "buzz"; - break; - case MS_SQEEK: - ret = "squeal"; - break; - case MS_SQAWK: - ret = "screech"; - break; - case MS_NEIGH: - ret = "neigh"; - break; - case MS_WAIL: - ret = "wail"; - break; - case MS_SILENT: - ret = "commotion"; - break; - default: - ret = "scream"; - } - return ret; + switch (mtmp->data->msound) { + case MS_MEW: + case MS_HISS: + ret = "hiss"; + break; + case MS_BARK: + case MS_GROWL: + ret = "growl"; + break; + case MS_ROAR: + ret = "roar"; + break; + case MS_BUZZ: + ret = "buzz"; + break; + case MS_SQEEK: + ret = "squeal"; + break; + case MS_SQAWK: + ret = "screech"; + break; + case MS_NEIGH: + ret = "neigh"; + break; + case MS_WAIL: + ret = "wail"; + break; + case MS_SILENT: + ret = "commotion"; + break; + default: + ret = "scream"; + } + return ret; } /* the sounds of a seriously abused pet, including player attacking it */ @@ -361,17 +363,18 @@ register struct monst *mtmp; register const char *growl_verb = 0; if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound) - return; + return; /* presumably nearness and soundok checks have already been made */ if (Hallucination) - growl_verb = h_sounds[rn2(SIZE(h_sounds))]; + growl_verb = h_sounds[rn2(SIZE(h_sounds))]; else - growl_verb = growl_sound(mtmp); + growl_verb = growl_sound(mtmp); if (growl_verb) { - pline("%s %s!", Monnam(mtmp), vtense((char *)0, growl_verb)); - if(context.run) nomul(0); - wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 18); + pline("%s %s!", Monnam(mtmp), vtense((char *) 0, growl_verb)); + if (context.run) + nomul(0); + wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 18); } } @@ -383,36 +386,38 @@ register struct monst *mtmp; register const char *yelp_verb = 0; if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound) - return; + return; /* presumably nearness and soundok checks have already been made */ if (Hallucination) - yelp_verb = h_sounds[rn2(SIZE(h_sounds))]; - else switch (mtmp->data->msound) { - case MS_MEW: - yelp_verb = "yowl"; - break; - case MS_BARK: - case MS_GROWL: - yelp_verb = "yelp"; - break; - case MS_ROAR: - yelp_verb = "snarl"; - break; - case MS_SQEEK: - yelp_verb = "squeal"; - break; - case MS_SQAWK: - yelp_verb = "screak"; - break; - case MS_WAIL: - yelp_verb = "wail"; - break; - } + yelp_verb = h_sounds[rn2(SIZE(h_sounds))]; + else + switch (mtmp->data->msound) { + case MS_MEW: + yelp_verb = "yowl"; + break; + case MS_BARK: + case MS_GROWL: + yelp_verb = "yelp"; + break; + case MS_ROAR: + yelp_verb = "snarl"; + break; + case MS_SQEEK: + yelp_verb = "squeal"; + break; + case MS_SQAWK: + yelp_verb = "screak"; + break; + case MS_WAIL: + yelp_verb = "wail"; + break; + } if (yelp_verb) { - pline("%s %s!", Monnam(mtmp), vtense((char *)0, yelp_verb)); - if(context.run) nomul(0); - wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 12); + pline("%s %s!", Monnam(mtmp), vtense((char *) 0, yelp_verb)); + if (context.run) + nomul(0); + wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 12); } } @@ -424,27 +429,29 @@ register struct monst *mtmp; register const char *whimper_verb = 0; if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound) - return; + return; /* presumably nearness and soundok checks have already been made */ if (Hallucination) - whimper_verb = h_sounds[rn2(SIZE(h_sounds))]; - else switch (mtmp->data->msound) { - case MS_MEW: - case MS_GROWL: - whimper_verb = "whimper"; - break; - case MS_BARK: - whimper_verb = "whine"; - break; - case MS_SQEEK: - whimper_verb = "squeal"; - break; - } + whimper_verb = h_sounds[rn2(SIZE(h_sounds))]; + else + switch (mtmp->data->msound) { + case MS_MEW: + case MS_GROWL: + whimper_verb = "whimper"; + break; + case MS_BARK: + whimper_verb = "whine"; + break; + case MS_SQEEK: + whimper_verb = "squeal"; + break; + } if (whimper_verb) { - pline("%s %s.", Monnam(mtmp), vtense((char *)0, whimper_verb)); - if(context.run) nomul(0); - wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 6); + pline("%s %s.", Monnam(mtmp), vtense((char *) 0, whimper_verb)); + if (context.run) + nomul(0); + wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 6); } } @@ -453,17 +460,17 @@ void beg(mtmp) register struct monst *mtmp; { - if (mtmp->msleeping || !mtmp->mcanmove || - !(carnivorous(mtmp->data) || herbivorous(mtmp->data))) - return; + if (mtmp->msleeping || !mtmp->mcanmove + || !(carnivorous(mtmp->data) || herbivorous(mtmp->data))) + return; /* presumably nearness and soundok checks have already been made */ if (!is_silent(mtmp->data) && mtmp->data->msound <= MS_ANIMAL) - (void) domonnoise(mtmp); + (void) domonnoise(mtmp); else if (mtmp->data->msound >= MS_HUMANOID) { - if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); - verbalize("I'm hungry."); + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + verbalize("I'm hungry."); } } @@ -475,12 +482,14 @@ struct monst *mon; int glyph; /* return True if it is actually a gecko */ - if (mon->data == &mons[PM_GECKO]) return TRUE; + if (mon->data == &mons[PM_GECKO]) + return TRUE; /* return False if it is a long worm; we might be chatting to its tail (not strictly needed; long worms are MS_SILENT so won't get here) */ - if (mon->data == &mons[PM_LONG_WORM]) return FALSE; + if (mon->data == &mons[PM_LONG_WORM]) + return FALSE; /* result depends upon whether map spot shows a gecko, which will - be due to hallucination or to mimickery since mon isn't one */ + be due to hallucination or to mimickery since mon isn't one */ glyph = glyph_at(mon->mx, mon->my); return (boolean)(glyph_to_mon(glyph) == PM_GECKO); } @@ -490,435 +499,444 @@ domonnoise(mtmp) register struct monst *mtmp; { char verbuf[BUFSZ]; - register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */ - *verbl_msg = 0, /* verbalize() */ - *verbl_msg_mcan = 0; /* verbalize() if cancelled */ + register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */ + *verbl_msg = 0, /* verbalize() */ + *verbl_msg_mcan = 0; /* verbalize() if cancelled */ struct permonst *ptr = mtmp->data; int msound = ptr->msound; /* presumably nearness and sleep checks have already been made */ - if (Deaf) return(0); - if (is_silent(ptr)) return(0); + if (Deaf) + return (0); + if (is_silent(ptr)) + return (0); /* leader might be poly'd; if he can still speak, give leader speach */ if (mtmp->m_id == quest_status.leader_m_id && msound > MS_ANIMAL) - msound = MS_LEADER; + msound = MS_LEADER; /* make sure it's your role's quest quardian; adjust if not */ else if (msound == MS_GUARDIAN && ptr != &mons[urole.guardnum]) - msound = mons[genus(monsndx(ptr), 1)].msound; + msound = mons[genus(monsndx(ptr), 1)].msound; /* some normally non-speaking types can/will speak if hero is similar */ - else if (msound == MS_ORC && /* note: MS_ORC is same as MS_GRUNT */ - (same_race(ptr, youmonst.data) || /* current form, */ - same_race(ptr, &mons[Race_switch]))) /* unpoly'd form */ - msound = MS_HUMANOID; + else if (msound == MS_ORC && /* note: MS_ORC is same as MS_GRUNT */ + (same_race(ptr, youmonst.data) || /* current form, */ + same_race(ptr, &mons[Race_switch]))) /* unpoly'd form */ + msound = MS_HUMANOID; /* silliness, with slight chance to interfere with shopping */ else if (Hallucination && mon_is_gecko(mtmp)) - msound = MS_SELL; + msound = MS_SELL; /* be sure to do this before talking; the monster might teleport away, in * which case we want to check its pre-teleport position */ if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); + map_invisible(mtmp->mx, mtmp->my); switch (msound) { - case MS_ORACLE: - return doconsult(mtmp); - case MS_PRIEST: - priest_talk(mtmp); - break; - case MS_LEADER: - case MS_NEMESIS: - case MS_GUARDIAN: - quest_chat(mtmp); - break; - case MS_SELL: /* pitch, pay, total */ - if (!Hallucination || (mtmp->isshk && !rn2(2))) { - shk_chat(mtmp); - } else { - /* approximation of GEICO's advertising slogan (it actually - concludes with "save you 15% or more on car insurance.") */ - Sprintf(verbuf, "15 minutes could save you 15 %s.", - currency(15L)); /* "zorkmids" */ - verbl_msg = verbuf; - } - break; - case MS_VAMPIRE: - { - /* vampire messages are varied by tameness, peacefulness, and time of night */ - boolean isnight = night(); - boolean kindred = (Upolyd && (u.umonnum == PM_VAMPIRE || - u.umonnum == PM_VAMPIRE_LORD)); - boolean nightchild = (Upolyd && (u.umonnum == PM_WOLF || - u.umonnum == PM_WINTER_WOLF || - u.umonnum == PM_WINTER_WOLF_CUB)); - const char *racenoun = (flags.female && urace.individual.f) ? - urace.individual.f : (urace.individual.m) ? - urace.individual.m : urace.noun; + case MS_ORACLE: + return doconsult(mtmp); + case MS_PRIEST: + priest_talk(mtmp); + break; + case MS_LEADER: + case MS_NEMESIS: + case MS_GUARDIAN: + quest_chat(mtmp); + break; + case MS_SELL: /* pitch, pay, total */ + if (!Hallucination || (mtmp->isshk && !rn2(2))) { + shk_chat(mtmp); + } else { + /* approximation of GEICO's advertising slogan (it actually + concludes with "save you 15% or more on car insurance.") */ + Sprintf(verbuf, "15 minutes could save you 15 %s.", + currency(15L)); /* "zorkmids" */ + verbl_msg = verbuf; + } + break; + case MS_VAMPIRE: { + /* vampire messages are varied by tameness, peacefulness, and time of + * night */ + boolean isnight = night(); + boolean kindred = (Upolyd && (u.umonnum == PM_VAMPIRE + || u.umonnum == PM_VAMPIRE_LORD)); + boolean nightchild = + (Upolyd && (u.umonnum == PM_WOLF || u.umonnum == PM_WINTER_WOLF + || u.umonnum == PM_WINTER_WOLF_CUB)); + const char *racenoun = + (flags.female && urace.individual.f) + ? urace.individual.f + : (urace.individual.m) ? urace.individual.m : urace.noun; - if (mtmp->mtame) { - if (kindred) { - Sprintf(verbuf, "Good %s to you Master%s", - isnight ? "evening" : "day", - isnight ? "!" : ". Why do we not rest?"); - verbl_msg = verbuf; - } else { - Sprintf(verbuf,"%s%s", - nightchild ? "Child of the night, " : "", - midnight() ? - "I can stand this craving no longer!" : - isnight ? - "I beg you, help me satisfy this growing craving!" : - "I find myself growing a little weary."); - verbl_msg = verbuf; - } - } else if (mtmp->mpeaceful) { - if (kindred && isnight) { - Sprintf(verbuf, "Good feeding %s!", - flags.female ? "sister" : "brother"); - verbl_msg = verbuf; - } else if (nightchild && isnight) { - Sprintf(verbuf, - "How nice to hear you, child of the night!"); - verbl_msg = verbuf; - } else - verbl_msg = "I only drink... potions."; - } else { - int vampindex; - static const char * const vampmsg[] = { - /* These first two (0 and 1) are specially handled below */ - "I vant to suck your %s!", - "I vill come after %s without regret!", - /* other famous vampire quotes can follow here if desired */ - }; - if (kindred) - verbl_msg = "This is my hunting ground that you dare to prowl!"; - else if (youmonst.data == &mons[PM_SILVER_DRAGON] || - youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) { - /* Silver dragons are silver in color, not made of silver */ - Sprintf(verbuf, "%s! Your silver sheen does not frighten me!", - youmonst.data == &mons[PM_SILVER_DRAGON] ? - "Fool" : "Young Fool"); - verbl_msg = verbuf; - } else { - vampindex = rn2(SIZE(vampmsg)); - if (vampindex == 0) { - Sprintf(verbuf, vampmsg[vampindex], body_part(BLOOD)); - verbl_msg = verbuf; - } else if (vampindex == 1) { - Sprintf(verbuf, vampmsg[vampindex], - Upolyd ? an(mons[u.umonnum].mname) : an(racenoun)); - verbl_msg = verbuf; - } else - verbl_msg = vampmsg[vampindex]; - } - } - } - break; - case MS_WERE: - if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) { - pline("%s throws back %s head and lets out a blood curdling %s!", - Monnam(mtmp), mhis(mtmp), - ptr == &mons[PM_HUMAN_WERERAT] ? "shriek" : "howl"); - wake_nearto(mtmp->mx, mtmp->my, 11*11); - } else - pline_msg = - "whispers inaudibly. All you can make out is \"moon\"."; - break; - case MS_BARK: - if (flags.moonphase == FULL_MOON && night()) { - pline_msg = "howls."; - } else if (mtmp->mpeaceful) { - if (mtmp->mtame && - (mtmp->mconf || mtmp->mflee || mtmp->mtrapped || - moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5)) - pline_msg = "whines."; - else if (mtmp->mtame && EDOG(mtmp)->hungrytime > moves + 1000) - pline_msg = "yips."; - else { - if (mtmp->data != &mons[PM_DINGO]) /* dingos do not actually bark */ - pline_msg = "barks."; - } - } else { - pline_msg = "growls."; - } - break; - case MS_MEW: - if (mtmp->mtame) { - if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped || - mtmp->mtame < 5) - pline_msg = "yowls."; - else if (moves > EDOG(mtmp)->hungrytime) - pline_msg = "meows."; - else if (EDOG(mtmp)->hungrytime > moves + 1000) - pline_msg = "purrs."; - else - pline_msg = "mews."; - break; - } /* else FALLTHRU */ - case MS_GROWL: - pline_msg = mtmp->mpeaceful ? "snarls." : "growls!"; - break; - case MS_ROAR: - pline_msg = mtmp->mpeaceful ? "snarls." : "roars!"; - break; - case MS_SQEEK: - pline_msg = "squeaks."; - break; - case MS_SQAWK: - if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful) - verbl_msg = "Nevermore!"; - else - pline_msg = "squawks."; - break; - case MS_HISS: - if (!mtmp->mpeaceful) - pline_msg = "hisses!"; - else return 0; /* no sound */ - break; - case MS_BUZZ: - pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily."; - break; - case MS_GRUNT: - pline_msg = "grunts."; - break; - case MS_NEIGH: - if (mtmp->mtame < 5) - pline_msg = "neighs."; - else if (moves > EDOG(mtmp)->hungrytime) - pline_msg = "whinnies."; - else - pline_msg = "whickers."; - break; - case MS_WAIL: - pline_msg = "wails mournfully."; - break; - case MS_GURGLE: - pline_msg = "gurgles."; - break; - case MS_BURBLE: - pline_msg = "burbles."; - break; - case MS_SHRIEK: - pline_msg = "shrieks."; - aggravate(); - break; - case MS_IMITATE: - pline_msg = "imitates you."; - break; - case MS_BONES: - pline("%s rattles noisily.", Monnam(mtmp)); - You("freeze for a moment."); - nomul(-2); - multi_reason = "scared by rattling"; - nomovemsg = 0; - break; - case MS_LAUGH: - { - static const char * const laugh_msg[4] = { - "giggles.", "chuckles.", "snickers.", "laughs.", - }; - pline_msg = laugh_msg[rn2(4)]; - } - break; - case MS_MUMBLE: - pline_msg = "mumbles incomprehensibly."; - break; - case MS_DJINNI: - if (mtmp->mtame) { - verbl_msg = "Sorry, I'm all out of wishes."; - } else if (mtmp->mpeaceful) { - if (ptr == &mons[PM_WATER_DEMON]) - pline_msg = "gurgles."; - else - verbl_msg = "I'm free!"; - } else { - if (ptr != &mons[PM_PRISONER]) - verbl_msg = "This will teach you not to disturb me!"; + if (mtmp->mtame) { + if (kindred) { + Sprintf(verbuf, "Good %s to you Master%s", + isnight ? "evening" : "day", + isnight ? "!" : ". Why do we not rest?"); + verbl_msg = verbuf; + } else { + Sprintf( + verbuf, "%s%s", nightchild ? "Child of the night, " : "", + midnight() + ? "I can stand this craving no longer!" + : isnight ? "I beg you, help me satisfy this growing " + "craving!" + : "I find myself growing a little weary."); + verbl_msg = verbuf; + } + } else if (mtmp->mpeaceful) { + if (kindred && isnight) { + Sprintf(verbuf, "Good feeding %s!", + flags.female ? "sister" : "brother"); + verbl_msg = verbuf; + } else if (nightchild && isnight) { + Sprintf(verbuf, "How nice to hear you, child of the night!"); + verbl_msg = verbuf; + } else + verbl_msg = "I only drink... potions."; + } else { + int vampindex; + static const char *const vampmsg[] = { + /* These first two (0 and 1) are specially handled below */ + "I vant to suck your %s!", + "I vill come after %s without regret!", + /* other famous vampire quotes can follow here if desired */ + }; + if (kindred) + verbl_msg = + "This is my hunting ground that you dare to prowl!"; + else if (youmonst.data == &mons[PM_SILVER_DRAGON] + || youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) { + /* Silver dragons are silver in color, not made of silver */ + Sprintf(verbuf, "%s! Your silver sheen does not frighten me!", + youmonst.data == &mons[PM_SILVER_DRAGON] + ? "Fool" + : "Young Fool"); + verbl_msg = verbuf; + } else { + vampindex = rn2(SIZE(vampmsg)); + if (vampindex == 0) { + Sprintf(verbuf, vampmsg[vampindex], body_part(BLOOD)); + verbl_msg = verbuf; + } else if (vampindex == 1) { + Sprintf(verbuf, vampmsg[vampindex], + Upolyd ? an(mons[u.umonnum].mname) + : an(racenoun)); + verbl_msg = verbuf; + } else + verbl_msg = vampmsg[vampindex]; + } + } + } break; + case MS_WERE: + if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) { + pline("%s throws back %s head and lets out a blood curdling %s!", + Monnam(mtmp), mhis(mtmp), + ptr == &mons[PM_HUMAN_WERERAT] ? "shriek" : "howl"); + wake_nearto(mtmp->mx, mtmp->my, 11 * 11); + } else + pline_msg = + "whispers inaudibly. All you can make out is \"moon\"."; + break; + case MS_BARK: + if (flags.moonphase == FULL_MOON && night()) { + pline_msg = "howls."; + } else if (mtmp->mpeaceful) { + if (mtmp->mtame + && (mtmp->mconf || mtmp->mflee || mtmp->mtrapped + || moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5)) + pline_msg = "whines."; + else if (mtmp->mtame && EDOG(mtmp)->hungrytime > moves + 1000) + pline_msg = "yips."; + else { + if (mtmp->data + != &mons[PM_DINGO]) /* dingos do not actually bark */ + pline_msg = "barks."; + } + } else { + pline_msg = "growls."; + } + break; + case MS_MEW: + if (mtmp->mtame) { + if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped + || mtmp->mtame < 5) + pline_msg = "yowls."; + else if (moves > EDOG(mtmp)->hungrytime) + pline_msg = "meows."; + else if (EDOG(mtmp)->hungrytime > moves + 1000) + pline_msg = "purrs."; + else + pline_msg = "mews."; + break; + } /* else FALLTHRU */ + case MS_GROWL: + pline_msg = mtmp->mpeaceful ? "snarls." : "growls!"; + break; + case MS_ROAR: + pline_msg = mtmp->mpeaceful ? "snarls." : "roars!"; + break; + case MS_SQEEK: + pline_msg = "squeaks."; + break; + case MS_SQAWK: + if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful) + verbl_msg = "Nevermore!"; + else + pline_msg = "squawks."; + break; + case MS_HISS: + if (!mtmp->mpeaceful) + pline_msg = "hisses!"; + else + return 0; /* no sound */ + break; + case MS_BUZZ: + pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily."; + break; + case MS_GRUNT: + pline_msg = "grunts."; + break; + case MS_NEIGH: + if (mtmp->mtame < 5) + pline_msg = "neighs."; + else if (moves > EDOG(mtmp)->hungrytime) + pline_msg = "whinnies."; + else + pline_msg = "whickers."; + break; + case MS_WAIL: + pline_msg = "wails mournfully."; + break; + case MS_GURGLE: + pline_msg = "gurgles."; + break; + case MS_BURBLE: + pline_msg = "burbles."; + break; + case MS_SHRIEK: + pline_msg = "shrieks."; + aggravate(); + break; + case MS_IMITATE: + pline_msg = "imitates you."; + break; + case MS_BONES: + pline("%s rattles noisily.", Monnam(mtmp)); + You("freeze for a moment."); + nomul(-2); + multi_reason = "scared by rattling"; + nomovemsg = 0; + break; + case MS_LAUGH: { + static const char *const laugh_msg[4] = { + "giggles.", "chuckles.", "snickers.", "laughs.", + }; + pline_msg = laugh_msg[rn2(4)]; + } break; + case MS_MUMBLE: + pline_msg = "mumbles incomprehensibly."; + break; + case MS_DJINNI: + if (mtmp->mtame) { + verbl_msg = "Sorry, I'm all out of wishes."; + } else if (mtmp->mpeaceful) { + if (ptr == &mons[PM_WATER_DEMON]) + pline_msg = "gurgles."; + else + verbl_msg = "I'm free!"; + } else { + if (ptr != &mons[PM_PRISONER]) + verbl_msg = "This will teach you not to disturb me!"; #if 0 else verbl_msg = "??????????"; #endif - } - break; - case MS_BOAST: /* giants */ - if (!mtmp->mpeaceful) { - switch (rn2(4)) { - case 0: pline("%s boasts about %s gem collection.", - Monnam(mtmp), mhis(mtmp)); - break; - case 1: pline_msg = "complains about a diet of mutton."; - break; - default: pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws."; - wake_nearto(mtmp->mx, mtmp->my, 7*7); - break; - } - break; - } - /* else FALLTHRU */ - case MS_HUMANOID: - if (!mtmp->mpeaceful) { - if (In_endgame(&u.uz) && is_mplayer(ptr)) - mplayer_talk(mtmp); - else - pline_msg = "threatens you."; - break; - } - /* Generic peaceful humanoid behaviour. */ - if (mtmp->mflee) - pline_msg = "wants nothing to do with you."; - else if (mtmp->mhp < mtmp->mhpmax/4) - pline_msg = "moans."; - else if (mtmp->mconf || mtmp->mstun) - verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?"; - else if (!mtmp->mcansee) - verbl_msg = "I can't see!"; - else if (mtmp->mtrapped) { - struct trap *t = t_at(mtmp->mx, mtmp->my); + } + break; + case MS_BOAST: /* giants */ + if (!mtmp->mpeaceful) { + switch (rn2(4)) { + case 0: + pline("%s boasts about %s gem collection.", Monnam(mtmp), + mhis(mtmp)); + break; + case 1: + pline_msg = "complains about a diet of mutton."; + break; + default: + pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws."; + wake_nearto(mtmp->mx, mtmp->my, 7 * 7); + break; + } + break; + } + /* else FALLTHRU */ + case MS_HUMANOID: + if (!mtmp->mpeaceful) { + if (In_endgame(&u.uz) && is_mplayer(ptr)) + mplayer_talk(mtmp); + else + pline_msg = "threatens you."; + break; + } + /* Generic peaceful humanoid behaviour. */ + if (mtmp->mflee) + pline_msg = "wants nothing to do with you."; + else if (mtmp->mhp < mtmp->mhpmax / 4) + pline_msg = "moans."; + else if (mtmp->mconf || mtmp->mstun) + verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?"; + else if (!mtmp->mcansee) + verbl_msg = "I can't see!"; + else if (mtmp->mtrapped) { + struct trap *t = t_at(mtmp->mx, mtmp->my); - if (t) t->tseen = 1; - verbl_msg = "I'm trapped!"; - } else if (mtmp->mhp < mtmp->mhpmax/2) - pline_msg = "asks for a potion of healing."; - else if (mtmp->mtame && !mtmp->isminion && - moves > EDOG(mtmp)->hungrytime) - verbl_msg = "I'm hungry."; - /* Specific monsters' interests */ - else if (is_elf(ptr)) - pline_msg = "curses orcs."; - else if (is_dwarf(ptr)) - pline_msg = "talks about mining."; - else if (likes_magic(ptr)) - pline_msg = "talks about spellcraft."; - else if (ptr->mlet == S_CENTAUR) - pline_msg = "discusses hunting."; - else switch (monsndx(ptr)) { - case PM_HOBBIT: - pline_msg = (mtmp->mhpmax - mtmp->mhp >= 10) ? - "complains about unpleasant dungeon conditions." - : "asks you about the One Ring."; - break; - case PM_ARCHEOLOGIST: - pline_msg = "describes a recent article in \"Spelunker Today\" magazine."; - break; - case PM_TOURIST: - verbl_msg = "Aloha."; - break; - default: - pline_msg = "discusses dungeon exploration."; - break; - } - break; - case MS_SEDUCE: - { - int swval; - if (SYSOPT_SEDUCE) { - if (ptr->mlet != S_NYMPH && - could_seduce(mtmp, &youmonst, (struct attack *)0) == 1) { - (void) doseduce(mtmp); - break; - } - swval = ((poly_gender() != (int) mtmp->female) ? rn2(3) : 0); - } else - swval = ((poly_gender() == 0) ? rn2(3) : 0); - switch(swval){ - case 2: - verbl_msg = "Hello, sailor."; - break; - case 1: - pline_msg = "comes on to you."; - break; - default: - pline_msg = "cajoles you."; - } - } - break; - case MS_ARREST: - if (mtmp->mpeaceful) - verbalize("Just the facts, %s.", - flags.female ? "Ma'am" : "Sir"); - else { - static const char * const arrest_msg[3] = { - "Anything you say can be used against you.", - "You're under arrest!", - "Stop in the name of the Law!", - }; - verbl_msg = arrest_msg[rn2(3)]; - } - break; - case MS_BRIBE: - if (mtmp->mpeaceful && !mtmp->mtame) { - (void) demon_talk(mtmp); - break; - } - /* fall through */ - case MS_CUSS: - if (!mtmp->mpeaceful) - cuss(mtmp); - else if (is_lminion(mtmp)) - verbl_msg = "It's not too late."; - else - verbl_msg = "We're all doomed."; - break; - case MS_SPELL: - /* deliberately vague, since it's not actually casting any spell */ - pline_msg = "seems to mutter a cantrip."; - break; - case MS_NURSE: - verbl_msg_mcan = "I hate this job!"; - if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))) - verbl_msg = "Put that weapon away before you hurt someone!"; - else if (uarmc || uarm || uarmh || uarms || uarmg || uarmf) - verbl_msg = Role_if(PM_HEALER) ? - "Doc, I can't help you unless you cooperate." : - "Please undress so I can examine you."; - else if (uarmu) - verbl_msg = "Take off your shirt, please."; - else verbl_msg = "Relax, this won't hurt a bit."; - break; - case MS_GUARD: - if (money_cnt(invent)) - verbl_msg = "Please drop that gold and follow me."; - else - verbl_msg = "Please follow me."; - break; - case MS_SOLDIER: - { - static const char * const soldier_foe_msg[3] = { - "Resistance is useless!", - "You're dog meat!", - "Surrender!", - }, * const soldier_pax_msg[3] = { - "What lousy pay we're getting here!", - "The food's not fit for Orcs!", - "My feet hurt, I've been on them all day!", - }; - verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)] - : soldier_foe_msg[rn2(3)]; - } - break; - case MS_RIDER: - if (ptr == &mons[PM_DEATH] && !rn2(10)) - pline_msg = "is busy reading a copy of Sandman #8."; - else verbl_msg = "Who do you think you are, War?"; - break; + if (t) + t->tseen = 1; + verbl_msg = "I'm trapped!"; + } else if (mtmp->mhp < mtmp->mhpmax / 2) + pline_msg = "asks for a potion of healing."; + else if (mtmp->mtame && !mtmp->isminion + && moves > EDOG(mtmp)->hungrytime) + verbl_msg = "I'm hungry."; + /* Specific monsters' interests */ + else if (is_elf(ptr)) + pline_msg = "curses orcs."; + else if (is_dwarf(ptr)) + pline_msg = "talks about mining."; + else if (likes_magic(ptr)) + pline_msg = "talks about spellcraft."; + else if (ptr->mlet == S_CENTAUR) + pline_msg = "discusses hunting."; + else + switch (monsndx(ptr)) { + case PM_HOBBIT: + pline_msg = + (mtmp->mhpmax - mtmp->mhp >= 10) + ? "complains about unpleasant dungeon conditions." + : "asks you about the One Ring."; + break; + case PM_ARCHEOLOGIST: + pline_msg = "describes a recent article in \"Spelunker " + "Today\" magazine."; + break; + case PM_TOURIST: + verbl_msg = "Aloha."; + break; + default: + pline_msg = "discusses dungeon exploration."; + break; + } + break; + case MS_SEDUCE: { + int swval; + if (SYSOPT_SEDUCE) { + if (ptr->mlet != S_NYMPH + && could_seduce(mtmp, &youmonst, (struct attack *) 0) == 1) { + (void) doseduce(mtmp); + break; + } + swval = ((poly_gender() != (int) mtmp->female) ? rn2(3) : 0); + } else + swval = ((poly_gender() == 0) ? rn2(3) : 0); + switch (swval) { + case 2: + verbl_msg = "Hello, sailor."; + break; + case 1: + pline_msg = "comes on to you."; + break; + default: + pline_msg = "cajoles you."; + } + } break; + case MS_ARREST: + if (mtmp->mpeaceful) + verbalize("Just the facts, %s.", flags.female ? "Ma'am" : "Sir"); + else { + static const char *const arrest_msg[3] = { + "Anything you say can be used against you.", + "You're under arrest!", "Stop in the name of the Law!", + }; + verbl_msg = arrest_msg[rn2(3)]; + } + break; + case MS_BRIBE: + if (mtmp->mpeaceful && !mtmp->mtame) { + (void) demon_talk(mtmp); + break; + } + /* fall through */ + case MS_CUSS: + if (!mtmp->mpeaceful) + cuss(mtmp); + else if (is_lminion(mtmp)) + verbl_msg = "It's not too late."; + else + verbl_msg = "We're all doomed."; + break; + case MS_SPELL: + /* deliberately vague, since it's not actually casting any spell */ + pline_msg = "seems to mutter a cantrip."; + break; + case MS_NURSE: + verbl_msg_mcan = "I hate this job!"; + if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))) + verbl_msg = "Put that weapon away before you hurt someone!"; + else if (uarmc || uarm || uarmh || uarms || uarmg || uarmf) + verbl_msg = Role_if(PM_HEALER) + ? "Doc, I can't help you unless you cooperate." + : "Please undress so I can examine you."; + else if (uarmu) + verbl_msg = "Take off your shirt, please."; + else + verbl_msg = "Relax, this won't hurt a bit."; + break; + case MS_GUARD: + if (money_cnt(invent)) + verbl_msg = "Please drop that gold and follow me."; + else + verbl_msg = "Please follow me."; + break; + case MS_SOLDIER: { + static const char + *const soldier_foe_msg[3] = + { + "Resistance is useless!", "You're dog meat!", "Surrender!", + }, + *const soldier_pax_msg[3] = { + "What lousy pay we're getting here!", + "The food's not fit for Orcs!", + "My feet hurt, I've been on them all day!", + }; + verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)] + : soldier_foe_msg[rn2(3)]; + } break; + case MS_RIDER: + if (ptr == &mons[PM_DEATH] && !rn2(10)) + pline_msg = "is busy reading a copy of Sandman #8."; + else + verbl_msg = "Who do you think you are, War?"; + break; } - if (pline_msg) pline("%s %s", Monnam(mtmp), pline_msg); - else if (mtmp->mcan && verbl_msg_mcan) verbalize1(verbl_msg_mcan); + if (pline_msg) + pline("%s %s", Monnam(mtmp), pline_msg); + else if (mtmp->mcan && verbl_msg_mcan) + verbalize1(verbl_msg_mcan); else if (verbl_msg) { - if (ptr == &mons[PM_DEATH]) { /* Death talks in CAPITAL LETTERS */ - char tmpbuf[BUFSZ]; - Sprintf(tmpbuf, "%s", verbl_msg); - verbalize1(ucase(tmpbuf)); - } else { - verbalize1(verbl_msg); - } + if (ptr == &mons[PM_DEATH]) { /* Death talks in CAPITAL LETTERS */ + char tmpbuf[BUFSZ]; + Sprintf(tmpbuf, "%s", verbl_msg); + verbalize1(ucase(tmpbuf)); + } else { + verbalize1(verbl_msg); + } } - return(1); + return (1); } - int dotalk() { @@ -932,119 +950,121 @@ STATIC_OVL int dochat() { register struct monst *mtmp; - register int tx,ty; + register int tx, ty; struct obj *otmp; if (is_silent(youmonst.data)) { - pline("As %s, you cannot speak.", an(youmonst.data->mname)); - return(0); + pline("As %s, you cannot speak.", an(youmonst.data->mname)); + return (0); } if (Strangled) { - You_cant("speak. You're choking!"); - return(0); + You_cant("speak. You're choking!"); + return (0); } if (u.uswallow) { - pline("They won't hear you out there."); - return(0); + pline("They won't hear you out there."); + return (0); } if (Underwater) { - Your("speech is unintelligible underwater."); - return(0); + Your("speech is unintelligible underwater."); + return (0); } if (Deaf) { - pline("How can you hold a conversation when you cannot hear?"); - return(0); + pline("How can you hold a conversation when you cannot hear?"); + return (0); } - if (!Blind && (otmp = shop_object(u.ux, u.uy)) != (struct obj *)0) { - /* standing on something in a shop and chatting causes the shopkeeper - to describe the price(s). This can inhibit other chatting inside - a shop, but that shouldn't matter much. shop_object() returns an - object iff inside a shop and the shopkeeper is present and willing - (not angry) and able (not asleep) to speak and the position contains - any objects other than just gold. - */ - price_quote(otmp); - return(1); + if (!Blind && (otmp = shop_object(u.ux, u.uy)) != (struct obj *) 0) { + /* standing on something in a shop and chatting causes the shopkeeper + to describe the price(s). This can inhibit other chatting inside + a shop, but that shouldn't matter much. shop_object() returns an + object iff inside a shop and the shopkeeper is present and willing + (not angry) and able (not asleep) to speak and the position + contains + any objects other than just gold. + */ + price_quote(otmp); + return (1); } if (!getdir("Talk to whom? (in what direction)")) { - /* decided not to chat */ - return(0); + /* decided not to chat */ + return (0); } if (u.usteed && u.dz > 0) { if (!u.usteed->mcanmove || u.usteed->msleeping) { pline("%s seems not to notice you.", Monnam(u.usteed)); - return(1); + return (1); } else return (domonnoise(u.usteed)); } if (u.dz) { - pline("They won't hear you %s there.", u.dz < 0 ? "up" : "down"); - return(0); + pline("They won't hear you %s there.", u.dz < 0 ? "up" : "down"); + return (0); } if (u.dx == 0 && u.dy == 0) { -/* - * Let's not include this. It raises all sorts of questions: can you wear - * 2 helmets, 2 amulets, 3 pairs of gloves or 6 rings as a marilith, - * etc... --KAA - if (u.umonnum == PM_ETTIN) { - You("discover that your other head makes boring conversation."); - return(1); - } -*/ - pline("Talking to yourself is a bad habit for a dungeoneer."); - return(0); + /* + * Let's not include this. It raises all sorts of questions: can you + wear + * 2 helmets, 2 amulets, 3 pairs of gloves or 6 rings as a marilith, + * etc... --KAA + if (u.umonnum == PM_ETTIN) { + You("discover that your other head makes boring + conversation."); + return(1); + } + */ + pline("Talking to yourself is a bad habit for a dungeoneer."); + return (0); } - tx = u.ux+u.dx; ty = u.uy+u.dy; + tx = u.ux + u.dx; + ty = u.uy + u.dy; - if (!isok(tx,ty)) return (0); + if (!isok(tx, ty)) + return (0); mtmp = m_at(tx, ty); - if ((!mtmp || mtmp->mundetected) && - (otmp = vobj_at(tx, ty)) && otmp->otyp == STATUE) { - - /* Talking to a statue */ + if ((!mtmp || mtmp->mundetected) && (otmp = vobj_at(tx, ty)) + && otmp->otyp == STATUE) { + /* Talking to a statue */ - if (!Blind) { - if (Hallucination) { - /* if you're hallucinating, you can't tell it's a statue */ - pline_The("%s seems not to notice you.", rndmonnam(NULL)); - } - else { - pline_The("statue seems not to notice you."); - } - } - return(0); + if (!Blind) { + if (Hallucination) { + /* if you're hallucinating, you can't tell it's a statue */ + pline_The("%s seems not to notice you.", rndmonnam(NULL)); + } else { + pline_The("statue seems not to notice you."); + } + } + return (0); } - if (!mtmp || mtmp->mundetected || - mtmp->m_ap_type == M_AP_FURNITURE || - mtmp->m_ap_type == M_AP_OBJECT) - return(0); + if (!mtmp || mtmp->mundetected || mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT) + return (0); /* sleeping monsters won't talk, except priests (who wake up) */ if ((!mtmp->mcanmove || mtmp->msleeping) && !mtmp->ispriest) { - /* If it is unseen, the player can't tell the difference between - not noticing him and just not existing, so skip the message. */ - if (canspotmon(mtmp)) - pline("%s seems not to notice you.", Monnam(mtmp)); - return(0); + /* If it is unseen, the player can't tell the difference between + not noticing him and just not existing, so skip the message. */ + if (canspotmon(mtmp)) + pline("%s seems not to notice you.", Monnam(mtmp)); + return (0); } /* if this monster is waiting for something, prod it into action */ mtmp->mstrategy &= ~STRAT_WAITMASK; if (mtmp->mtame && mtmp->meating) { - if (!canspotmon(mtmp)) - map_invisible(mtmp->mx, mtmp->my); - pline("%s is eating noisily.", Monnam(mtmp)); - return (0); + if (!canspotmon(mtmp)) + map_invisible(mtmp->mx, mtmp->my); + pline("%s is eating noisily.", Monnam(mtmp)); + return (0); } return domonnoise(mtmp); @@ -1052,101 +1072,101 @@ dochat() #ifdef USER_SOUNDS -extern void FDECL(play_usersound, (const char*, int)); +extern void FDECL(play_usersound, (const char *, int)); typedef struct audio_mapping_rec { #ifdef USER_SOUNDS_REGEX - struct re_pattern_buffer regex; + struct re_pattern_buffer regex; #else - char *pattern; + char *pattern; #endif - char *filename; - int volume; - struct audio_mapping_rec *next; + char *filename; + int volume; + struct audio_mapping_rec *next; } audio_mapping; static audio_mapping *soundmap = 0; -char* sounddir = "."; +char *sounddir = "."; /* adds a sound file mapping, returns 0 on failure, 1 on success */ int add_sound_mapping(mapping) const char *mapping; { - char text[256]; - char filename[256]; - char filespec[256]; - int volume; + char text[256]; + char filename[256]; + char filespec[256]; + int volume; - if (sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d", - text, filename, &volume) == 3) { - const char *err; - audio_mapping *new_map; + if (sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d", text, + filename, &volume) == 3) { + const char *err; + audio_mapping *new_map; - if (strlen(sounddir) + strlen(filename) > 254) { - raw_print("sound file name too long"); - return 0; - } - Sprintf(filespec, "%s/%s", sounddir, filename); + if (strlen(sounddir) + strlen(filename) > 254) { + raw_print("sound file name too long"); + return 0; + } + Sprintf(filespec, "%s/%s", sounddir, filename); - if (can_read_file(filespec)) { - new_map = (audio_mapping *)alloc(sizeof(audio_mapping)); + if (can_read_file(filespec)) { + new_map = (audio_mapping *) alloc(sizeof(audio_mapping)); #ifdef USER_SOUNDS_REGEX - new_map->regex.translate = 0; - new_map->regex.fastmap = 0; - new_map->regex.buffer = 0; - new_map->regex.allocated = 0; - new_map->regex.regs_allocated = REGS_FIXED; + new_map->regex.translate = 0; + new_map->regex.fastmap = 0; + new_map->regex.buffer = 0; + new_map->regex.allocated = 0; + new_map->regex.regs_allocated = REGS_FIXED; #else - new_map->pattern = dupstr(text); + new_map->pattern = dupstr(text); #endif - new_map->filename = dupstr(filespec); - new_map->volume = volume; - new_map->next = soundmap; + new_map->filename = dupstr(filespec); + new_map->volume = volume; + new_map->next = soundmap; #ifdef USER_SOUNDS_REGEX - err = re_compile_pattern(text, strlen(text), &new_map->regex); + err = re_compile_pattern(text, strlen(text), &new_map->regex); #else - err = 0; + err = 0; #endif - if (err) { - raw_print(err); - free(new_map->filename); - free(new_map); - return 0; - } else { - soundmap = new_map; - } - } else { - Sprintf(text, "cannot read %.243s", filespec); - raw_print(text); - return 0; - } - } else { - raw_print("syntax error in SOUND"); - return 0; - } + if (err) { + raw_print(err); + free(new_map->filename); + free(new_map); + return 0; + } else { + soundmap = new_map; + } + } else { + Sprintf(text, "cannot read %.243s", filespec); + raw_print(text); + return 0; + } + } else { + raw_print("syntax error in SOUND"); + return 0; + } - return 1; + return 1; } void play_sound_for_message(msg) -const char* msg; +const char *msg; { - audio_mapping* cursor = soundmap; + audio_mapping *cursor = soundmap; - while (cursor) { + while (cursor) { #ifdef USER_SOUNDS_REGEX - if (re_search(&cursor->regex, msg, strlen(msg), 0, 9999, 0) >= 0) { + if (re_search(&cursor->regex, msg, strlen(msg), 0, 9999, 0) >= 0) { #else - if (pmatch(cursor->pattern, msg)) { + if (pmatch(cursor->pattern, msg)) { #endif - play_usersound(cursor->filename, cursor->volume); - } - cursor = cursor->next; - } + play_usersound(cursor->filename, cursor->volume); + } + cursor = cursor->next; + } } #endif /* USER_SOUNDS */ diff --git a/src/sp_lev.c b/src/sp_lev.c index aea32a636..6a3c64313 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sp_lev.c $NHDT-Date: 1429755531 2015/04/23 02:18:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.50 $ */ +/* NetHack 3.6 sp_lev.c $NHDT-Date: 1431192758 2015/05/09 17:32:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.55 $ */ /* NetHack 3.6 sp_lev.c $Date: 2011/01/05 01:28:36 $ $Revision: 1.23 $ */ /* Copyright (c) 1989 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,7 +17,7 @@ #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable:4244) +#pragma warning(disable : 4244) #endif typedef void (*select_iter_func)(int, int, genericptr_t); @@ -25,53 +25,60 @@ typedef void (*select_iter_func)(int, int, genericptr_t); extern void FDECL(mkmap, (lev_init *)); STATIC_DCL void FDECL(get_room_loc, (schar *, schar *, struct mkroom *)); -STATIC_DCL void FDECL(get_free_room_loc, (schar *, schar *, struct mkroom *, packed_coord)); +STATIC_DCL void FDECL(get_free_room_loc, + (schar *, schar *, struct mkroom *, packed_coord)); STATIC_DCL void FDECL(create_trap, (trap *, struct mkroom *)); STATIC_DCL int FDECL(noncoalignment, (ALIGNTYP_P)); -STATIC_DCL boolean FDECL(m_bad_boulder_spot, (int,int)); +STATIC_DCL boolean FDECL(m_bad_boulder_spot, (int, int)); STATIC_DCL void FDECL(create_monster, (monster *, struct mkroom *)); STATIC_DCL void FDECL(create_object, (object *, struct mkroom *)); STATIC_DCL void FDECL(create_altar, (altar *, struct mkroom *)); -STATIC_DCL boolean FDECL(search_door, (struct mkroom *, xchar *, xchar *, - XCHAR_P, int)); +STATIC_DCL boolean +FDECL(search_door, (struct mkroom *, xchar *, xchar *, XCHAR_P, int)); STATIC_DCL void NDECL(fix_stair_rooms); STATIC_DCL void FDECL(create_corridor, (corridor *)); STATIC_DCL void NDECL(count_features); -STATIC_DCL boolean FDECL(create_subroom, (struct mkroom *, XCHAR_P, XCHAR_P, - XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P)); +STATIC_DCL boolean +FDECL(create_subroom, (struct mkroom *, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, + XCHAR_P, XCHAR_P)); long FDECL(opvar_array_length, (struct sp_coder *)); STATIC_DCL void NDECL(solidify_map); STATIC_DCL void FDECL(splev_stack_init, (struct splevstack *)); STATIC_DCL void FDECL(splev_stack_done, (struct splevstack *)); -STATIC_DCL void FDECL(splev_stack_push, (struct splevstack *, struct opvar *)); -STATIC_DCL struct opvar * FDECL(splev_stack_pop, (struct splevstack *)); -STATIC_DCL struct splevstack * FDECL(splev_stack_reverse, (struct splevstack *)); -STATIC_DCL struct opvar * FDECL(opvar_new_str, (char *)); -STATIC_DCL struct opvar * FDECL(opvar_new_int, (long)); -STATIC_DCL struct opvar * FDECL(opvar_new_coord, (int, int)); +STATIC_DCL void FDECL(splev_stack_push, + (struct splevstack *, struct opvar *)); +STATIC_DCL struct opvar *FDECL(splev_stack_pop, (struct splevstack *)); +STATIC_DCL struct splevstack *FDECL(splev_stack_reverse, + (struct splevstack *)); +STATIC_DCL struct opvar *FDECL(opvar_new_str, (char *)); +STATIC_DCL struct opvar *FDECL(opvar_new_int, (long)); +STATIC_DCL struct opvar *FDECL(opvar_new_coord, (int, int)); #if 0 STATIC_DCL struct opvar * FDECL(opvar_new_region, (int,int, int,int)); #endif /*0*/ STATIC_DCL void FDECL(opvar_free_x, (struct opvar *)); -STATIC_DCL struct opvar * FDECL(opvar_clone, (struct opvar *)); -STATIC_DCL struct opvar * FDECL(opvar_var_conversion, (struct sp_coder *, struct opvar *)); -STATIC_DCL struct splev_var * FDECL(opvar_var_defined, (struct sp_coder *, char *)); -STATIC_DCL struct opvar * FDECL(splev_stack_getdat, (struct sp_coder *, XCHAR_P)); -STATIC_DCL struct opvar * FDECL(splev_stack_getdat_any, (struct sp_coder *)); +STATIC_DCL struct opvar *FDECL(opvar_clone, (struct opvar *)); +STATIC_DCL struct opvar *FDECL(opvar_var_conversion, + (struct sp_coder *, struct opvar *)); +STATIC_DCL struct splev_var *FDECL(opvar_var_defined, + (struct sp_coder *, char *)); +STATIC_DCL struct opvar *FDECL(splev_stack_getdat, + (struct sp_coder *, XCHAR_P)); +STATIC_DCL struct opvar *FDECL(splev_stack_getdat_any, (struct sp_coder *)); STATIC_DCL void FDECL(variable_list_del, (struct splev_var *)); -STATIC_DCL void FDECL(lvlfill_maze_grid, (int,int, int,int, SCHAR_P)); +STATIC_DCL void FDECL(lvlfill_maze_grid, (int, int, int, int, SCHAR_P)); STATIC_DCL void FDECL(lvlfill_solid, (SCHAR_P, SCHAR_P)); STATIC_DCL void NDECL(remove_boundary_syms); -STATIC_DCL void FDECL(maybe_add_door, (int,int, struct mkroom *)); +STATIC_DCL void FDECL(maybe_add_door, (int, int, struct mkroom *)); STATIC_DCL void NDECL(link_doors_rooms); STATIC_DCL void NDECL(fill_rooms); STATIC_DCL unpacked_coord FDECL(get_unpacked_coord, (long, int)); STATIC_DCL void FDECL(replace_terrain, (replaceterrain *, struct mkroom *)); -STATIC_DCL void FDECL(wallify_map, (int,int, int,int)); +STATIC_DCL void FDECL(wallify_map, (int, int, int, int)); STATIC_DCL void FDECL(splev_initlev, (lev_init *)); -STATIC_DCL struct sp_frame * FDECL(frame_new, (long)); +STATIC_DCL struct sp_frame *FDECL(frame_new, (long)); STATIC_DCL void FDECL(frame_del, (struct sp_frame *)); STATIC_DCL void FDECL(spo_frame_push, (struct sp_coder *)); STATIC_DCL void FDECL(spo_frame_pop, (struct sp_coder *)); @@ -96,25 +103,35 @@ STATIC_DCL void FDECL(spo_altar, (struct sp_coder *)); STATIC_DCL void FDECL(spo_trap, (struct sp_coder *)); STATIC_DCL void FDECL(spo_gold, (struct sp_coder *)); STATIC_DCL void FDECL(spo_corridor, (struct sp_coder *)); -STATIC_DCL struct opvar * FDECL(selection_opvar, (char *)); -STATIC_DCL xchar FDECL(selection_getpoint, (int,int, struct opvar *)); -STATIC_DCL void FDECL(selection_setpoint, (int,int, struct opvar *, XCHAR_P)); -STATIC_DCL struct opvar * FDECL(selection_not, (struct opvar *)); -STATIC_DCL struct opvar * FDECL(selection_logical_oper, (struct opvar *, struct opvar *, CHAR_P)); -STATIC_DCL struct opvar * FDECL(selection_filter_mapchar, (struct opvar *, struct opvar *)); +STATIC_DCL struct opvar *FDECL(selection_opvar, (char *)); +STATIC_DCL xchar FDECL(selection_getpoint, (int, int, struct opvar *)); +STATIC_DCL void FDECL(selection_setpoint, + (int, int, struct opvar *, XCHAR_P)); +STATIC_DCL struct opvar *FDECL(selection_not, (struct opvar *)); +STATIC_DCL struct opvar *FDECL(selection_logical_oper, + (struct opvar *, struct opvar *, CHAR_P)); +STATIC_DCL struct opvar *FDECL(selection_filter_mapchar, + (struct opvar *, struct opvar *)); STATIC_DCL void FDECL(selection_filter_percent, (struct opvar *, int)); STATIC_DCL int FDECL(selection_rndcoord, (struct opvar *, schar *, schar *)); STATIC_DCL void FDECL(selection_do_grow, (struct opvar *, int)); -STATIC_DCL void FDECL(selection_floodfill, (struct opvar *, int,int)); -STATIC_DCL void FDECL(selection_do_ellipse, (struct opvar *, int,int, int,int, int)); -STATIC_DCL long FDECL(line_dist_coord, (long,long, long,long, long,long)); -STATIC_DCL void FDECL(selection_do_gradient, (struct opvar *, long,long, long,long, long,long,long,long)); -STATIC_DCL void FDECL(selection_do_line, (SCHAR_P,SCHAR_P, SCHAR_P,SCHAR_P, struct opvar *)); -STATIC_DCL void FDECL(selection_do_randline, (SCHAR_P,SCHAR_P, SCHAR_P,SCHAR_P, SCHAR_P,SCHAR_P, struct opvar *)); -STATIC_DCL void FDECL(selection_iterate, (struct opvar *, select_iter_func, genericptr_t)); -STATIC_DCL void FDECL(sel_set_ter, (int,int, genericptr_t)); -STATIC_DCL void FDECL(sel_set_feature, (int,int, genericptr_t)); -STATIC_DCL void FDECL(sel_set_door, (int,int, genericptr_t)); +STATIC_DCL void FDECL(selection_floodfill, (struct opvar *, int, int)); +STATIC_DCL void FDECL(selection_do_ellipse, + (struct opvar *, int, int, int, int, int)); +STATIC_DCL long FDECL(line_dist_coord, (long, long, long, long, long, long)); +STATIC_DCL void FDECL(selection_do_gradient, + (struct opvar *, long, long, long, long, long, long, + long, long)); +STATIC_DCL void FDECL(selection_do_line, + (SCHAR_P, SCHAR_P, SCHAR_P, SCHAR_P, struct opvar *)); +STATIC_DCL void FDECL(selection_do_randline, + (SCHAR_P, SCHAR_P, SCHAR_P, SCHAR_P, SCHAR_P, SCHAR_P, + struct opvar *)); +STATIC_DCL void FDECL(selection_iterate, + (struct opvar *, select_iter_func, genericptr_t)); +STATIC_DCL void FDECL(sel_set_ter, (int, int, genericptr_t)); +STATIC_DCL void FDECL(sel_set_feature, (int, int, genericptr_t)); +STATIC_DCL void FDECL(sel_set_door, (int, int, genericptr_t)); STATIC_DCL void FDECL(spo_door, (struct sp_coder *)); STATIC_DCL void FDECL(spo_feature, (struct sp_coder *)); STATIC_DCL void FDECL(spo_terrain, (struct sp_coder *)); @@ -125,7 +142,7 @@ STATIC_DCL void FDECL(spo_drawbridge, (struct sp_coder *)); STATIC_DCL void FDECL(spo_mazewalk, (struct sp_coder *)); STATIC_DCL void FDECL(spo_wall_property, (struct sp_coder *)); STATIC_DCL void FDECL(spo_room_door, (struct sp_coder *)); -STATIC_DCL void FDECL(sel_set_wallify, (int,int, genericptr_t)); +STATIC_DCL void FDECL(sel_set_wallify, (int, int, genericptr_t)); STATIC_DCL void FDECL(spo_wallify, (struct sp_coder *)); STATIC_DCL void FDECL(spo_map, (struct sp_coder *)); STATIC_DCL void FDECL(spo_jmp, (struct sp_coder *, sp_lev *)); @@ -133,25 +150,27 @@ STATIC_DCL void FDECL(spo_conditional_jump, (struct sp_coder *, sp_lev *)); STATIC_DCL void FDECL(spo_var_init, (struct sp_coder *)); STATIC_DCL void FDECL(spo_shuffle_array, (struct sp_coder *)); -#define LEFT 1 -#define H_LEFT 2 -#define CENTER 3 -#define H_RIGHT 4 -#define RIGHT 5 +#define LEFT 1 +#define H_LEFT 2 +#define CENTER 3 +#define H_RIGHT 4 +#define RIGHT 5 -#define TOP 1 -#define BOTTOM 5 +#define TOP 1 +#define BOTTOM 5 -#define sq(x) ((x)*(x)) +#define sq(x) ((x) * (x)) -#define XLIM 4 -#define YLIM 3 +#define XLIM 4 +#define YLIM 3 -#define Fread (void)dlb_fread -#define Fgetc (schar)dlb_fgetc -#define New(type) (type *) alloc(sizeof(type)) -#define NewTab(type, size) (type **) alloc(sizeof(type *) * (unsigned)size) -#define Free(ptr) if(ptr) free((genericptr_t) (ptr)) +#define Fread (void) dlb_fread +#define Fgetc (schar) dlb_fgetc +#define New(type) (type *) alloc(sizeof(type)) +#define NewTab(type, size) (type **) alloc(sizeof(type *) * (unsigned) size) +#define Free(ptr) \ + if (ptr) \ + free((genericptr_t)(ptr)) extern struct engr *head_engr; @@ -160,19 +179,20 @@ extern int min_rx, max_rx, min_ry, max_ry; /* from mkmap.c */ /* positions touched by level elements explicitly defined in the des-file */ static char SpLev_Map[COLNO][ROWNO]; -static aligntyp ralign[3] = { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }; +static aligntyp ralign[3] = { AM_CHAOTIC, AM_NEUTRAL, AM_LAWFUL }; static NEARDATA xchar xstart, ystart; static NEARDATA char xsize, ysize; -STATIC_DCL void FDECL(set_wall_property, (XCHAR_P,XCHAR_P,XCHAR_P,XCHAR_P,int)); +STATIC_DCL void FDECL(set_wall_property, + (XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P, int)); STATIC_DCL int NDECL(rnddoor); STATIC_DCL int NDECL(rndtrap); -STATIC_DCL void FDECL(get_location, (schar *,schar *,int, struct mkroom *)); +STATIC_DCL void FDECL(get_location, (schar *, schar *, int, struct mkroom *)); STATIC_DCL void FDECL(light_region, (region *)); -STATIC_DCL void FDECL(maze1xy, (coord *,int)); +STATIC_DCL void FDECL(maze1xy, (coord *, int)); STATIC_DCL boolean FDECL(sp_level_loader, (dlb *, sp_lev *)); STATIC_DCL void FDECL(create_door, (room_door *, struct mkroom *)); -struct mkroom * FDECL(build_room, (room *, struct mkroom *)); +struct mkroom *FDECL(build_room, (room *, struct mkroom *)); char *lev_message = 0; lev_region *lregions = 0; @@ -192,73 +212,79 @@ solidify_map() { xchar x, y; for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (IS_STWALL(levl[x][y].typ) && !SpLev_Map[x][y]) - levl[x][y].wall_info |= (W_NONDIGGABLE|W_NONPASSWALL); + for (y = 0; y < ROWNO; y++) + if (IS_STWALL(levl[x][y].typ) && !SpLev_Map[x][y]) + levl[x][y].wall_info |= (W_NONDIGGABLE | W_NONPASSWALL); } void splev_stack_init(st) - struct splevstack *st; +struct splevstack *st; { if (st) { - st->depth = 0; - st->depth_alloc = SPLEV_STACK_RESERVE; - st->stackdata = (struct opvar **)alloc(st->depth_alloc * sizeof(struct opvar *)); + st->depth = 0; + st->depth_alloc = SPLEV_STACK_RESERVE; + st->stackdata = + (struct opvar **) alloc(st->depth_alloc * sizeof(struct opvar *)); } } void splev_stack_done(st) - struct splevstack *st; +struct splevstack *st; { if (st) { - int i; + int i; - if (st->stackdata && st->depth) - for (i = 0; i < st->depth; i++) { - switch (st->stackdata[i]->spovartyp) { - default: - case SPOVAR_NULL: - case SPOVAR_COORD: - case SPOVAR_REGION: - case SPOVAR_MAPCHAR: - case SPOVAR_MONST: - case SPOVAR_OBJ: - case SPOVAR_INT: - break; - case SPOVAR_VARIABLE: - case SPOVAR_STRING: - case SPOVAR_SEL: - if (st->stackdata[i]->vardata.str) Free(st->stackdata[i]->vardata.str); - st->stackdata[i]->vardata.str = NULL; - break; - } - Free(st->stackdata[i]); - st->stackdata[i] = NULL; - } + if (st->stackdata && st->depth) + for (i = 0; i < st->depth; i++) { + switch (st->stackdata[i]->spovartyp) { + default: + case SPOVAR_NULL: + case SPOVAR_COORD: + case SPOVAR_REGION: + case SPOVAR_MAPCHAR: + case SPOVAR_MONST: + case SPOVAR_OBJ: + case SPOVAR_INT: + break; + case SPOVAR_VARIABLE: + case SPOVAR_STRING: + case SPOVAR_SEL: + if (st->stackdata[i]->vardata.str) + Free(st->stackdata[i]->vardata.str); + st->stackdata[i]->vardata.str = NULL; + break; + } + Free(st->stackdata[i]); + st->stackdata[i] = NULL; + } - Free(st->stackdata); - st->stackdata = NULL; - st->depth = st->depth_alloc = 0; - Free(st); + Free(st->stackdata); + st->stackdata = NULL; + st->depth = st->depth_alloc = 0; + Free(st); } } void splev_stack_push(st, v) - struct splevstack *st; - struct opvar *v; +struct splevstack *st; +struct opvar *v; { - if (!st || !v) return; - if (!st->stackdata) panic("splev_stack_push: no stackdata allocated?"); + if (!st || !v) + return; + if (!st->stackdata) + panic("splev_stack_push: no stackdata allocated?"); if (st->depth >= st->depth_alloc) { - struct opvar **tmp = (struct opvar **)alloc((st->depth_alloc + SPLEV_STACK_RESERVE) * sizeof(struct opvar *)); - (void)memcpy(tmp, st->stackdata, st->depth_alloc * sizeof(struct opvar *)); - Free(st->stackdata); - st->stackdata = tmp; - st->depth_alloc += SPLEV_STACK_RESERVE; + struct opvar **tmp = (struct opvar **) alloc( + (st->depth_alloc + SPLEV_STACK_RESERVE) * sizeof(struct opvar *)); + (void) memcpy(tmp, st->stackdata, + st->depth_alloc * sizeof(struct opvar *)); + Free(st->stackdata); + st->stackdata = tmp; + st->depth_alloc += SPLEV_STACK_RESERVE; } st->stackdata[st->depth] = v; @@ -267,33 +293,38 @@ splev_stack_push(st, v) struct opvar * splev_stack_pop(st) - struct splevstack *st; +struct splevstack *st; { struct opvar *ret = NULL; - if (!st) return ret; - if (!st->stackdata) panic("splev_stack_pop: no stackdata allocated?"); + if (!st) + return ret; + if (!st->stackdata) + panic("splev_stack_pop: no stackdata allocated?"); if (st->depth) { - st->depth--; - ret = st->stackdata[st->depth]; - st->stackdata[st->depth] = NULL; - return ret; - } else impossible("splev_stack_pop: empty stack?"); + st->depth--; + ret = st->stackdata[st->depth]; + st->stackdata[st->depth] = NULL; + return ret; + } else + impossible("splev_stack_pop: empty stack?"); return ret; } struct splevstack * splev_stack_reverse(st) - struct splevstack *st; +struct splevstack *st; { long i; struct opvar *tmp; - if (!st) return NULL; - if (!st->stackdata) panic("splev_stack_reverse: no stackdata allocated?"); + if (!st) + return NULL; + if (!st->stackdata) + panic("splev_stack_reverse: no stackdata allocated?"); for (i = 0; i < (st->depth / 2); i++) { - tmp = st->stackdata[i]; - st->stackdata[i] = st->stackdata[st->depth - i - 1]; - st->stackdata[st->depth - i - 1] = tmp; + tmp = st->stackdata[i]; + st->stackdata[i] = st->stackdata[st->depth - i - 1]; + st->stackdata[st->depth - i - 1] = tmp; } return st; } @@ -306,32 +337,32 @@ splev_stack_reverse(st) #define OV_pop_c(x) (x = splev_stack_getdat(coder, SPOVAR_COORD)) #define OV_pop_r(x) (x = splev_stack_getdat(coder, SPOVAR_REGION)) #define OV_pop_s(x) (x = splev_stack_getdat(coder, SPOVAR_STRING)) -#define OV_pop(x) (x = splev_stack_getdat_any(coder)) -#define OV_pop_typ(x,typ) (x = splev_stack_getdat(coder, typ)) - +#define OV_pop(x) (x = splev_stack_getdat_any(coder)) +#define OV_pop_typ(x, typ) (x = splev_stack_getdat(coder, typ)) struct opvar * opvar_new_str(s) - char *s; +char *s; { - struct opvar *tmpov = (struct opvar *)alloc(sizeof(struct opvar)); + struct opvar *tmpov = (struct opvar *) alloc(sizeof(struct opvar)); tmpov->spovartyp = SPOVAR_STRING; if (s) { - int len = strlen(s); - tmpov->vardata.str = (char *)alloc(len + 1); - (void)memcpy((genericptr_t)tmpov->vardata.str, (genericptr_t)s, len); - tmpov->vardata.str[len] = '\0'; + int len = strlen(s); + tmpov->vardata.str = (char *) alloc(len + 1); + (void) memcpy((genericptr_t) tmpov->vardata.str, (genericptr_t) s, + len); + tmpov->vardata.str[len] = '\0'; } else - tmpov->vardata.str = NULL; + tmpov->vardata.str = NULL; return tmpov; } struct opvar * opvar_new_int(i) - long i; +long i; { - struct opvar *tmpov = (struct opvar *)alloc(sizeof(struct opvar)); + struct opvar *tmpov = (struct opvar *) alloc(sizeof(struct opvar)); tmpov->spovartyp = SPOVAR_INT; tmpov->vardata.l = i; @@ -339,13 +370,13 @@ opvar_new_int(i) } struct opvar * -opvar_new_coord(x,y) - int x,y; +opvar_new_coord(x, y) +int x, y; { - struct opvar *tmpov = (struct opvar *)alloc(sizeof(struct opvar)); + struct opvar *tmpov = (struct opvar *) alloc(sizeof(struct opvar)); tmpov->spovartyp = SPOVAR_COORD; - tmpov->vardata.l = SP_COORD_PACK(x,y); + tmpov->vardata.l = SP_COORD_PACK(x, y); return tmpov; } @@ -364,9 +395,10 @@ opvar_new_region(x1,y1,x2,y2) void opvar_free_x(ov) - struct opvar *ov; +struct opvar *ov; { - if (!ov) return; + if (!ov) + return; switch (ov->spovartyp) { case SPOVAR_COORD: case SPOVAR_REGION: @@ -374,13 +406,14 @@ opvar_free_x(ov) case SPOVAR_MONST: case SPOVAR_OBJ: case SPOVAR_INT: - break; + break; case SPOVAR_VARIABLE: case SPOVAR_STRING: case SPOVAR_SEL: - Free(ov->vardata.str); - break; - default: impossible("Unknown opvar value type (%i)!", ov->spovartyp); + Free(ov->vardata.str); + break; + default: + impossible("Unknown opvar value type (%i)!", ov->spovartyp); } Free(ov); } @@ -389,16 +422,24 @@ opvar_free_x(ov) #ifdef __BORLANDC__ #define __FUNCTION__ __FUNC__ #endif -#define opvar_free(ov) { if (ov) { opvar_free_x(ov); ov = NULL; } else impossible("opvar_free(), %s", __FUNCTION__); } +#define opvar_free(ov) \ + { \ + if (ov) { \ + opvar_free_x(ov); \ + ov = NULL; \ + } else \ + impossible("opvar_free(), %s", __FUNCTION__); \ + } struct opvar * opvar_clone(ov) - struct opvar *ov; +struct opvar *ov; { struct opvar *tmpov; - if (!ov) panic("no opvar to clone"); - tmpov = (struct opvar *)alloc(sizeof(struct opvar)); + if (!ov) + panic("no opvar to clone"); + tmpov = (struct opvar *) alloc(sizeof(struct opvar)); tmpov->spovartyp = ov->spovartyp; switch (ov->spovartyp) { case SPOVAR_COORD: @@ -407,174 +448,186 @@ opvar_clone(ov) case SPOVAR_MONST: case SPOVAR_OBJ: case SPOVAR_INT: - tmpov->vardata.l = ov->vardata.l; - break; + tmpov->vardata.l = ov->vardata.l; + break; case SPOVAR_VARIABLE: case SPOVAR_STRING: case SPOVAR_SEL: - tmpov->vardata.str = dupstr(ov->vardata.str); - break; - default: impossible("Unknown push value type (%i)!", ov->spovartyp); + tmpov->vardata.str = dupstr(ov->vardata.str); + break; + default: + impossible("Unknown push value type (%i)!", ov->spovartyp); } return tmpov; } - struct opvar * opvar_var_conversion(coder, ov) - struct sp_coder *coder; - struct opvar *ov; +struct sp_coder *coder; +struct opvar *ov; { struct splev_var *tmp; struct opvar *tmpov; struct opvar *array_idx = NULL; - if (!coder || !ov) return NULL; - if (ov->spovartyp != SPOVAR_VARIABLE) return ov; + if (!coder || !ov) + return NULL; + if (ov->spovartyp != SPOVAR_VARIABLE) + return ov; tmp = coder->frame->variables; while (tmp) { - if (!strcmp(tmp->name, OV_s(ov))) { - if ((tmp->svtyp & SPOVAR_ARRAY)) { - array_idx = opvar_var_conversion(coder, splev_stack_pop(coder->stack)); - if (!array_idx || OV_typ(array_idx) != SPOVAR_INT) - panic("array idx not an int"); - if (tmp->array_len < 1) panic("array len < 1"); - OV_i(array_idx) = (OV_i(array_idx) % tmp->array_len); - tmpov = opvar_clone(tmp->data.arrayvalues[OV_i(array_idx)]); - return tmpov; - } else { - tmpov = opvar_clone(tmp->data.value); - return tmpov; - } - } - tmp = tmp->next; + if (!strcmp(tmp->name, OV_s(ov))) { + if ((tmp->svtyp & SPOVAR_ARRAY)) { + array_idx = opvar_var_conversion( + coder, splev_stack_pop(coder->stack)); + if (!array_idx || OV_typ(array_idx) != SPOVAR_INT) + panic("array idx not an int"); + if (tmp->array_len < 1) + panic("array len < 1"); + OV_i(array_idx) = (OV_i(array_idx) % tmp->array_len); + tmpov = opvar_clone(tmp->data.arrayvalues[OV_i(array_idx)]); + return tmpov; + } else { + tmpov = opvar_clone(tmp->data.value); + return tmpov; + } + } + tmp = tmp->next; } return NULL; } struct splev_var * opvar_var_defined(coder, name) - struct sp_coder *coder; - char *name; +struct sp_coder *coder; +char *name; { struct splev_var *tmp; - if (!coder) return NULL; + if (!coder) + return NULL; tmp = coder->frame->variables; while (tmp) { - if (!strcmp(tmp->name, name)) return tmp; - tmp = tmp->next; + if (!strcmp(tmp->name, name)) + return tmp; + tmp = tmp->next; } return NULL; } struct opvar * splev_stack_getdat(coder, typ) - struct sp_coder *coder; - xchar typ; +struct sp_coder *coder; +xchar typ; { if (coder && coder->stack) { - struct opvar *tmp = splev_stack_pop(coder->stack); - if (!tmp) panic("no value type %i in stack.", typ); - if (tmp->spovartyp == SPOVAR_VARIABLE) - tmp = opvar_var_conversion(coder, tmp); - if (tmp->spovartyp == typ) - return tmp; + struct opvar *tmp = splev_stack_pop(coder->stack); + if (!tmp) + panic("no value type %i in stack.", typ); + if (tmp->spovartyp == SPOVAR_VARIABLE) + tmp = opvar_var_conversion(coder, tmp); + if (tmp->spovartyp == typ) + return tmp; } return NULL; } struct opvar * splev_stack_getdat_any(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (coder && coder->stack) { - struct opvar *tmp = splev_stack_pop(coder->stack); - if (tmp && tmp->spovartyp == SPOVAR_VARIABLE) - tmp = opvar_var_conversion(coder, tmp); - return tmp; + struct opvar *tmp = splev_stack_pop(coder->stack); + if (tmp && tmp->spovartyp == SPOVAR_VARIABLE) + tmp = opvar_var_conversion(coder, tmp); + return tmp; } return NULL; } - - void variable_list_del(varlist) - struct splev_var *varlist; +struct splev_var *varlist; { struct splev_var *tmp = varlist; - if (!tmp) return; + if (!tmp) + return; while (tmp) { - Free(tmp->name); - if ((tmp->svtyp & SPOVAR_ARRAY)) { - long idx = tmp->array_len; - while (idx-- > 0) { - opvar_free(tmp->data.arrayvalues[idx]); - }; - Free(tmp->data.arrayvalues); - } else { - opvar_free(tmp->data.value); - } - tmp = varlist->next; - Free(varlist); - varlist = tmp; + Free(tmp->name); + if ((tmp->svtyp & SPOVAR_ARRAY)) { + long idx = tmp->array_len; + while (idx-- > 0) { + opvar_free(tmp->data.arrayvalues[idx]); + }; + Free(tmp->data.arrayvalues); + } else { + opvar_free(tmp->data.value); + } + tmp = varlist->next; + Free(varlist); + varlist = tmp; } } void -lvlfill_maze_grid(x1,y1,x2,y2,filling) -int x1,y1,x2,y2; +lvlfill_maze_grid(x1, y1, x2, y2, filling) +int x1, y1, x2, y2; schar filling; { - int x,y; + int x, y; - for (x = x1; x <= x2; x++) - for (y = y1; y <= y2; y++) { + for (x = x1; x <= x2; x++) + for (y = y1; y <= y2; y++) { if (level.flags.corrmaze) - levl[x][y].typ = STONE; + levl[x][y].typ = STONE; else levl[x][y].typ = (y < 2 || ((x % 2) && (y % 2))) ? STONE : filling; - } + } } void -lvlfill_solid(filling,lit) +lvlfill_solid(filling, lit) schar filling; schar lit; { - int x,y; - for (x = 2; x <= x_maze_max; x++) - for (y = 0; y <= y_maze_max; y++) { - SET_TYPLIT(x,y,filling,lit); - } + int x, y; + for (x = 2; x <= x_maze_max; x++) + for (y = 0; y <= y_maze_max; y++) { + SET_TYPLIT(x, y, filling, lit); + } } - /* * Make walls of the area (x1, y1, x2, y2) non diggable/non passwall-able */ STATIC_OVL void -set_wall_property(x1,y1,x2,y2, prop) +set_wall_property(x1, y1, x2, y2, prop) xchar x1, y1, x2, y2; int prop; { - register xchar x, y; + register xchar x, y; - for(y = max(y1,0); y <= min(y2, ROWNO-1); y++) - for(x = max(x1,0); x <= min(x2,COLNO-1); x++) - if(IS_STWALL(levl[x][y].typ) || IS_TREE(levl[x][y].typ)) - levl[x][y].wall_info |= prop; + for (y = max(y1, 0); y <= min(y2, ROWNO - 1); y++) + for (x = max(x1, 0); x <= min(x2, COLNO - 1); x++) + if (IS_STWALL(levl[x][y].typ) || IS_TREE(levl[x][y].typ)) + levl[x][y].wall_info |= prop; } STATIC_OVL void shuffle_alignments() { - int i; + int i; aligntyp atmp; /* shuffle 3 alignments */ - i = rn2(3); atmp=ralign[2]; ralign[2]=ralign[i]; ralign[i]=atmp; - if (rn2(2)) { atmp=ralign[1]; ralign[1]=ralign[0]; ralign[0]=atmp; } + i = rn2(3); + atmp = ralign[2]; + ralign[2] = ralign[i]; + ralign[i] = atmp; + if (rn2(2)) { + atmp = ralign[1]; + ralign[1] = ralign[0]; + ralign[0] = atmp; + } } /* @@ -583,16 +636,16 @@ shuffle_alignments() STATIC_OVL void count_features() { - xchar x,y; + xchar x, y; level.flags.nfountains = level.flags.nsinks = 0; for (y = 0; y < ROWNO; y++) - for (x = 0; x < COLNO; x++) { - int typ = levl[x][y].typ; - if (typ == FOUNTAIN) - level.flags.nfountains++; - else if (typ == SINK) - level.flags.nsinks++; - } + for (x = 0; x < COLNO; x++) { + int typ = levl[x][y].typ; + if (typ == FOUNTAIN) + level.flags.nfountains++; + else if (typ == SINK) + level.flags.nsinks++; + } } void @@ -603,47 +656,46 @@ remove_boundary_syms() * are laid out. CROSSWALLS are used to specify "invisible" * boundaries where DOOR syms look bad or aren't desirable. */ - xchar x,y; + xchar x, y; boolean has_bounds = FALSE; - for (x = 0; x < COLNO-1; x++) - for (y = 0; y < ROWNO-1; y++) - if (levl[x][y].typ == CROSSWALL) { - has_bounds = TRUE; - break; - } + for (x = 0; x < COLNO - 1; x++) + for (y = 0; y < ROWNO - 1; y++) + if (levl[x][y].typ == CROSSWALL) { + has_bounds = TRUE; + break; + } if (has_bounds) { - for(x = 0; x < x_maze_max; x++) - for(y = 0; y < y_maze_max; y++) - if ((levl[x][y].typ == CROSSWALL) && SpLev_Map[x][y]) - levl[x][y].typ = ROOM; + for (x = 0; x < x_maze_max; x++) + for (y = 0; y < y_maze_max; y++) + if ((levl[x][y].typ == CROSSWALL) && SpLev_Map[x][y]) + levl[x][y].typ = ROOM; } } - void -maybe_add_door(x,y, droom) -int x,y; +maybe_add_door(x, y, droom) +int x, y; struct mkroom *droom; { - if (droom->hx >= 0 && doorindex < DOORMAX && inside_room(droom, x,y)) - add_door(x, y, droom); + if (droom->hx >= 0 && doorindex < DOORMAX && inside_room(droom, x, y)) + add_door(x, y, droom); } void link_doors_rooms() { - int x,y; + int x, y; int tmpi, m; for (y = 0; y < ROWNO; y++) - for (x = 0; x < COLNO; x++) - if (IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR) { - for (tmpi = 0; tmpi < nroom; tmpi++) { - maybe_add_door(x,y, &rooms[tmpi]); - for (m = 0; m < rooms[tmpi].nsubrooms; m++) { - maybe_add_door(x,y, rooms[tmpi].sbrooms[m]); - } - } - } + for (x = 0; x < COLNO; x++) + if (IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR) { + for (tmpi = 0; tmpi < nroom; tmpi++) { + maybe_add_door(x, y, &rooms[tmpi]); + for (m = 0; m < rooms[tmpi].nsubrooms; m++) { + maybe_add_door(x, y, rooms[tmpi].sbrooms[m]); + } + } + } } void @@ -651,12 +703,12 @@ fill_rooms() { int tmpi; for (tmpi = 0; tmpi < nroom; tmpi++) { - int m; - if (rooms[tmpi].needfill) - fill_room(&rooms[tmpi], (rooms[tmpi].needfill == 2)); - for (m = 0; m < rooms[tmpi].nsubrooms; m++) - if (rooms[tmpi].sbrooms[m]->needfill) - fill_room(rooms[tmpi].sbrooms[m], FALSE); + int m; + if (rooms[tmpi].needfill) + fill_room(&rooms[tmpi], (rooms[tmpi].needfill == 2)); + for (m = 0; m < rooms[tmpi].nsubrooms; m++) + if (rooms[tmpi].sbrooms[m]->needfill) + fill_room(rooms[tmpi].sbrooms[m], FALSE); } } @@ -666,9 +718,9 @@ fill_rooms() STATIC_OVL int rnddoor() { - int i = 1 << rn2(5); - i >>= 1; - return i; + int i = 1 << rn2(5); + i >>= 1; + return i; } /* @@ -677,25 +729,32 @@ rnddoor() STATIC_OVL int rndtrap() { - int rtrap; + int rtrap; - do { - rtrap = rnd(TRAPNUM-1); - switch (rtrap) { - case HOLE: /* no random holes on special levels */ - case MAGIC_PORTAL: rtrap = NO_TRAP; - break; - case TRAPDOOR: if (!Can_dig_down(&u.uz)) rtrap = NO_TRAP; - break; - case LEVEL_TELEP: - case TELEP_TRAP: if (level.flags.noteleport) rtrap = NO_TRAP; - break; - case ROLLING_BOULDER_TRAP: - case ROCKTRAP: if (In_endgame(&u.uz)) rtrap = NO_TRAP; - break; - } - } while (rtrap == NO_TRAP); - return rtrap; + do { + rtrap = rnd(TRAPNUM - 1); + switch (rtrap) { + case HOLE: /* no random holes on special levels */ + case MAGIC_PORTAL: + rtrap = NO_TRAP; + break; + case TRAPDOOR: + if (!Can_dig_down(&u.uz)) + rtrap = NO_TRAP; + break; + case LEVEL_TELEP: + case TELEP_TRAP: + if (level.flags.noteleport) + rtrap = NO_TRAP; + break; + case ROLLING_BOULDER_TRAP: + case ROCKTRAP: + if (In_endgame(&u.uz)) + rtrap = NO_TRAP; + break; + } + } while (rtrap == NO_TRAP); + return rtrap; } /* @@ -713,63 +772,67 @@ schar *x, *y; int humidity; struct mkroom *croom; { - int cpt = 0; - int mx, my, sx, sy; + int cpt = 0; + int mx, my, sx, sy; - if (croom) { - mx = croom->lx; - my = croom->ly; - sx = croom->hx - mx + 1; - sy = croom->hy - my + 1; - } else { - mx = xstart; - my = ystart; - sx = xsize; - sy = ysize; - } + if (croom) { + mx = croom->lx; + my = croom->ly; + sx = croom->hx - mx + 1; + sy = croom->hy - my + 1; + } else { + mx = xstart; + my = ystart; + sx = xsize; + sy = ysize; + } - if (*x >= 0) { /* normal locations */ - *x += mx; - *y += my; - } else { /* random location */ - do { - if (croom) { /* handle irregular areas */ - coord tmpc; - somexy(croom, &tmpc); - *x = tmpc.x; - *y = tmpc.y; - } else { - *x = mx + rn2((int)sx); - *y = my + rn2((int)sy); - } - if (is_ok_location(*x,*y,humidity)) break; - } while (++cpt < 100); - if (cpt >= 100) { - register int xx, yy; - /* last try */ - for (xx = 0; xx < sx; xx++) - for (yy = 0; yy < sy; yy++) { - *x = mx + xx; - *y = my + yy; - if (is_ok_location(*x,*y,humidity)) goto found_it; - } - if (!(humidity & NO_LOC_WARN)) { - impossible("get_location: can't find a place!"); - } else { - *x = *y = -1; - } - } - } -found_it:; + if (*x >= 0) { /* normal locations */ + *x += mx; + *y += my; + } else { /* random location */ + do { + if (croom) { /* handle irregular areas */ + coord tmpc; + somexy(croom, &tmpc); + *x = tmpc.x; + *y = tmpc.y; + } else { + *x = mx + rn2((int) sx); + *y = my + rn2((int) sy); + } + if (is_ok_location(*x, *y, humidity)) + break; + } while (++cpt < 100); + if (cpt >= 100) { + register int xx, yy; + /* last try */ + for (xx = 0; xx < sx; xx++) + for (yy = 0; yy < sy; yy++) { + *x = mx + xx; + *y = my + yy; + if (is_ok_location(*x, *y, humidity)) + goto found_it; + } + if (!(humidity & NO_LOC_WARN)) { + impossible("get_location: can't find a place!"); + } else { + *x = *y = -1; + } + } + } +found_it: + ; - if (!(humidity & ANY_LOC) && !isok(*x,*y)) { - if (!(humidity & NO_LOC_WARN)) { - /*warning("get_location: (%d,%d) out of bounds", *x, *y);*/ - *x = x_maze_max; *y = y_maze_max; - } else { - *x = *y = -1; - } - } + if (!(humidity & ANY_LOC) && !isok(*x, *y)) { + if (!(humidity & NO_LOC_WARN)) { + /*warning("get_location: (%d,%d) out of bounds", *x, *y);*/ + *x = x_maze_max; + *y = y_maze_max; + } else { + *x = *y = -1; + } + } } STATIC_OVL boolean @@ -777,44 +840,49 @@ is_ok_location(x, y, humidity) register schar x, y; register int humidity; { - register int typ; + register int typ; - if (Is_waterlevel(&u.uz)) return TRUE; /* accept any spot */ + if (Is_waterlevel(&u.uz)) + return TRUE; /* accept any spot */ - /* TODO: Should perhaps check if wall is diggable/passwall? */ - if (humidity & ANY_LOC) return TRUE; + /* TODO: Should perhaps check if wall is diggable/passwall? */ + if (humidity & ANY_LOC) + return TRUE; - if ((humidity & SOLID) && IS_ROCK(levl[x][y].typ)) return TRUE; + if ((humidity & SOLID) && IS_ROCK(levl[x][y].typ)) + return TRUE; - if (humidity & DRY) { - typ = levl[x][y].typ; - if (typ == ROOM || typ == AIR || - typ == CLOUD || typ == ICE || typ == CORR) - return TRUE; - } - if ((humidity & WET) && is_pool(x,y)) return TRUE; - if ((humidity & HOT) && is_lava(x,y)) return TRUE; - return FALSE; + if (humidity & DRY) { + typ = levl[x][y].typ; + if (typ == ROOM || typ == AIR || typ == CLOUD || typ == ICE + || typ == CORR) + return TRUE; + } + if ((humidity & WET) && is_pool(x, y)) + return TRUE; + if ((humidity & HOT) && is_lava(x, y)) + return TRUE; + return FALSE; } - unpacked_coord get_unpacked_coord(loc, defhumidity) - long loc; - int defhumidity; +long loc; +int defhumidity; { static unpacked_coord c; if (loc & SP_COORD_IS_RANDOM) { - c.x = c.y = -1; - c.is_random = 1; - c.getloc_flags = (loc & ~SP_COORD_IS_RANDOM); - if (!c.getloc_flags) c.getloc_flags = defhumidity; + c.x = c.y = -1; + c.is_random = 1; + c.getloc_flags = (loc & ~SP_COORD_IS_RANDOM); + if (!c.getloc_flags) + c.getloc_flags = defhumidity; } else { - c.is_random = 0; - c.getloc_flags = defhumidity; - c.x = SP_COORD_X(loc); - c.y = SP_COORD_Y(loc); + c.is_random = 0; + c.getloc_flags = defhumidity; + c.x = SP_COORD_X(loc); + c.y = SP_COORD_Y(loc); } return c; } @@ -830,9 +898,10 @@ long crd; c = get_unpacked_coord(crd, humidity); *x = c.x; *y = c.y; - get_location(x, y, c.getloc_flags | (c.is_random ? NO_LOC_WARN : 0), croom); + get_location(x, y, c.getloc_flags | (c.is_random ? NO_LOC_WARN : 0), + croom); if (*x == -1 && *y == -1 && c.is_random) - get_location(x,y, humidity, croom); + get_location(x, y, humidity, croom); } /* @@ -841,26 +910,26 @@ long crd; */ STATIC_OVL void -get_room_loc(x,y, croom) -schar *x, *y; -struct mkroom *croom; +get_room_loc(x, y, croom) +schar *x, *y; +struct mkroom *croom; { - coord c; + coord c; - if (*x <0 && *y <0) { - if (somexy(croom, &c)) { - *x = c.x; - *y = c.y; - } else - panic("get_room_loc : can't find a place!"); - } else { - if (*x < 0) - *x = rn2(croom->hx - croom->lx + 1); - if (*y < 0) - *y = rn2(croom->hy - croom->ly + 1); - *x += croom->lx; - *y += croom->ly; - } + if (*x < 0 && *y < 0) { + if (somexy(croom, &c)) { + *x = c.x; + *y = c.y; + } else + panic("get_room_loc : can't find a place!"); + } else { + if (*x < 0) + *x = rn2(croom->hx - croom->lx + 1); + if (*y < 0) + *y = rn2(croom->hy - croom->ly + 1); + *x += croom->lx; + *y += croom->ly; + } } /* @@ -869,25 +938,25 @@ struct mkroom *croom; */ STATIC_OVL void -get_free_room_loc(x,y, croom, pos) -schar *x, *y; -struct mkroom *croom; -packed_coord pos; +get_free_room_loc(x, y, croom, pos) +schar *x, *y; +struct mkroom *croom; +packed_coord pos; { - schar try_x, try_y; - register int trycnt = 0; + schar try_x, try_y; + register int trycnt = 0; - get_location_coord(&try_x, &try_y, DRY, croom, pos); - if (levl[try_x][try_y].typ != ROOM) { - do { - try_x = *x, try_y = *y; - get_room_loc(&try_x, &try_y, croom); - } while (levl[try_x][try_y].typ != ROOM && ++trycnt <= 100); + get_location_coord(&try_x, &try_y, DRY, croom, pos); + if (levl[try_x][try_y].typ != ROOM) { + do { + try_x = *x, try_y = *y; + get_room_loc(&try_x, &try_y, croom); + } while (levl[try_x][try_y].typ != ROOM && ++trycnt <= 100); - if (trycnt > 100) - panic("get_free_room_loc: can't find a place!"); - } - *x = try_x, *y = try_y; + if (trycnt > 100) + panic("get_free_room_loc: can't find a place!"); + } + *x = try_x, *y = try_y; } boolean @@ -895,47 +964,57 @@ check_room(lowx, ddx, lowy, ddy, vault) xchar *lowx, *ddx, *lowy, *ddy; boolean vault; { - register int x,y,hix = *lowx + *ddx, hiy = *lowy + *ddy; - register struct rm *lev; - int xlim, ylim, ymax; + register int x, y, hix = *lowx + *ddx, hiy = *lowy + *ddy; + register struct rm *lev; + int xlim, ylim, ymax; - xlim = XLIM + (vault ? 1 : 0); - ylim = YLIM + (vault ? 1 : 0); + xlim = XLIM + (vault ? 1 : 0); + ylim = YLIM + (vault ? 1 : 0); - if (*lowx < 3) *lowx = 3; - if (*lowy < 2) *lowy = 2; - if (hix > COLNO-3) hix = COLNO-3; - if (hiy > ROWNO-3) hiy = ROWNO-3; + if (*lowx < 3) + *lowx = 3; + if (*lowy < 2) + *lowy = 2; + if (hix > COLNO - 3) + hix = COLNO - 3; + if (hiy > ROWNO - 3) + hiy = ROWNO - 3; chk: - if (hix <= *lowx || hiy <= *lowy) return FALSE; + if (hix <= *lowx || hiy <= *lowy) + return FALSE; - /* check area around room (and make room smaller if necessary) */ - for (x = *lowx - xlim; x<= hix + xlim; x++) { - if(x <= 0 || x >= COLNO) continue; - y = *lowy - ylim; ymax = hiy + ylim; - if(y < 0) y = 0; - if(ymax >= ROWNO) ymax = (ROWNO-1); - lev = &levl[x][y]; - for (; y <= ymax; y++) { - if (lev++->typ) { - if (!vault) - debugpline2("strange area [%d,%d] in check_room.", x, y); - if (!rn2(3)) return FALSE; - if (x < *lowx) - *lowx = x + xlim + 1; - else - hix = x - xlim - 1; - if (y < *lowy) - *lowy = y + ylim + 1; - else - hiy = y - ylim - 1; - goto chk; - } - } - } - *ddx = hix - *lowx; - *ddy = hiy - *lowy; - return TRUE; + /* check area around room (and make room smaller if necessary) */ + for (x = *lowx - xlim; x <= hix + xlim; x++) { + if (x <= 0 || x >= COLNO) + continue; + y = *lowy - ylim; + ymax = hiy + ylim; + if (y < 0) + y = 0; + if (ymax >= ROWNO) + ymax = (ROWNO - 1); + lev = &levl[x][y]; + for (; y <= ymax; y++) { + if (lev++->typ) { + if (!vault) + debugpline2("strange area [%d,%d] in check_room.", x, y); + if (!rn2(3)) + return FALSE; + if (x < *lowx) + *lowx = x + xlim + 1; + else + hix = x - xlim - 1; + if (y < *lowy) + *lowy = y + ylim + 1; + else + hiy = y - ylim - 1; + goto chk; + } + } + } + *ddx = hix - *lowx; + *ddy = hiy - *lowy; + return TRUE; } /* @@ -944,166 +1023,171 @@ chk: */ boolean -create_room(x,y,w,h,xal,yal,rtype,rlit) -xchar x,y; -xchar w,h; -xchar xal,yal; -xchar rtype, rlit; +create_room(x, y, w, h, xal, yal, rtype, rlit) +xchar x, y; +xchar w, h; +xchar xal, yal; +xchar rtype, rlit; { - xchar xabs, yabs; - int wtmp, htmp, xaltmp, yaltmp, xtmp, ytmp; - NhRect *r1 = 0, r2; - int trycnt = 0; - boolean vault = FALSE; - int xlim = XLIM, ylim = YLIM; + xchar xabs, yabs; + int wtmp, htmp, xaltmp, yaltmp, xtmp, ytmp; + NhRect *r1 = 0, r2; + int trycnt = 0; + boolean vault = FALSE; + int xlim = XLIM, ylim = YLIM; - if (rtype == -1) /* Is the type random ? */ - rtype = OROOM; + if (rtype == -1) /* Is the type random ? */ + rtype = OROOM; - if (rtype == VAULT) { - vault = TRUE; - xlim++; - ylim++; - } + if (rtype == VAULT) { + vault = TRUE; + xlim++; + ylim++; + } - /* on low levels the room is lit (usually) */ - /* some other rooms may require lighting */ + /* on low levels the room is lit (usually) */ + /* some other rooms may require lighting */ - /* is light state random ? */ - if (rlit == -1) - rlit = (rnd(1+abs(depth(&u.uz))) < 11 && rn2(77)) ? TRUE : FALSE; + /* is light state random ? */ + if (rlit == -1) + rlit = (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? TRUE : FALSE; - /* - * Here we will try to create a room. If some parameters are - * random we are willing to make several try before we give - * it up. - */ - do { - xchar xborder, yborder; - wtmp = w; htmp = h; - xtmp = x; ytmp = y; - xaltmp = xal; yaltmp = yal; + /* + * Here we will try to create a room. If some parameters are + * random we are willing to make several try before we give + * it up. + */ + do { + xchar xborder, yborder; + wtmp = w; + htmp = h; + xtmp = x; + ytmp = y; + xaltmp = xal; + yaltmp = yal; - /* First case : a totally random room */ + /* First case : a totally random room */ - if((xtmp < 0 && ytmp <0 && wtmp < 0 && xaltmp < 0 && - yaltmp < 0) || vault) { - xchar hx, hy, lx, ly, dx, dy; - r1 = rnd_rect(); /* Get a random rectangle */ + if ((xtmp < 0 && ytmp < 0 && wtmp < 0 && xaltmp < 0 && yaltmp < 0) + || vault) { + xchar hx, hy, lx, ly, dx, dy; + r1 = rnd_rect(); /* Get a random rectangle */ - if (!r1) { /* No more free rectangles ! */ - debugpline0("No more rects..."); - return FALSE; - } - hx = r1->hx; - hy = r1->hy; - lx = r1->lx; - ly = r1->ly; - if (vault) - dx = dy = 1; - else { - dx = 2 + rn2((hx-lx > 28) ? 12 : 8); - dy = 2 + rn2(4); - if(dx*dy > 50) - dy = 50/dx; - } - xborder = (lx > 0 && hx < COLNO -1) ? 2*xlim : xlim+1; - yborder = (ly > 0 && hy < ROWNO -1) ? 2*ylim : ylim+1; - if(hx-lx < dx + 3 + xborder || - hy-ly < dy + 3 + yborder) { - r1 = 0; - continue; - } - xabs = lx + (lx > 0 ? xlim : 3) - + rn2(hx - (lx>0?lx : 3) - dx - xborder + 1); - yabs = ly + (ly > 0 ? ylim : 2) - + rn2(hy - (ly>0?ly : 2) - dy - yborder + 1); - if (ly == 0 && hy >= (ROWNO-1) && - (!nroom || !rn2(nroom)) && (yabs+dy > ROWNO/2)) { - yabs = rn1(3, 2); - if(nroom < 4 && dy>1) dy--; - } - if (!check_room(&xabs, &dx, &yabs, &dy, vault)) { - r1 = 0; - continue; - } - wtmp = dx+1; - htmp = dy+1; - r2.lx = xabs-1; r2.ly = yabs-1; - r2.hx = xabs + wtmp; - r2.hy = yabs + htmp; - } else { /* Only some parameters are random */ - int rndpos = 0; - if (xtmp < 0 && ytmp < 0) { /* Position is RANDOM */ - xtmp = rnd(5); - ytmp = rnd(5); - rndpos = 1; - } - if (wtmp < 0 || htmp < 0) { /* Size is RANDOM */ - wtmp = rn1(15, 3); - htmp = rn1(8, 2); - } - if (xaltmp == -1) /* Horizontal alignment is RANDOM */ - xaltmp = rnd(3); - if (yaltmp == -1) /* Vertical alignment is RANDOM */ - yaltmp = rnd(3); + if (!r1) { /* No more free rectangles ! */ + debugpline0("No more rects..."); + return FALSE; + } + hx = r1->hx; + hy = r1->hy; + lx = r1->lx; + ly = r1->ly; + if (vault) + dx = dy = 1; + else { + dx = 2 + rn2((hx - lx > 28) ? 12 : 8); + dy = 2 + rn2(4); + if (dx * dy > 50) + dy = 50 / dx; + } + xborder = (lx > 0 && hx < COLNO - 1) ? 2 * xlim : xlim + 1; + yborder = (ly > 0 && hy < ROWNO - 1) ? 2 * ylim : ylim + 1; + if (hx - lx < dx + 3 + xborder || hy - ly < dy + 3 + yborder) { + r1 = 0; + continue; + } + xabs = lx + (lx > 0 ? xlim : 3) + + rn2(hx - (lx > 0 ? lx : 3) - dx - xborder + 1); + yabs = ly + (ly > 0 ? ylim : 2) + + rn2(hy - (ly > 0 ? ly : 2) - dy - yborder + 1); + if (ly == 0 && hy >= (ROWNO - 1) && (!nroom || !rn2(nroom)) + && (yabs + dy > ROWNO / 2)) { + yabs = rn1(3, 2); + if (nroom < 4 && dy > 1) + dy--; + } + if (!check_room(&xabs, &dx, &yabs, &dy, vault)) { + r1 = 0; + continue; + } + wtmp = dx + 1; + htmp = dy + 1; + r2.lx = xabs - 1; + r2.ly = yabs - 1; + r2.hx = xabs + wtmp; + r2.hy = yabs + htmp; + } else { /* Only some parameters are random */ + int rndpos = 0; + if (xtmp < 0 && ytmp < 0) { /* Position is RANDOM */ + xtmp = rnd(5); + ytmp = rnd(5); + rndpos = 1; + } + if (wtmp < 0 || htmp < 0) { /* Size is RANDOM */ + wtmp = rn1(15, 3); + htmp = rn1(8, 2); + } + if (xaltmp == -1) /* Horizontal alignment is RANDOM */ + xaltmp = rnd(3); + if (yaltmp == -1) /* Vertical alignment is RANDOM */ + yaltmp = rnd(3); - /* Try to generate real (absolute) coordinates here! */ + /* Try to generate real (absolute) coordinates here! */ - xabs = (((xtmp-1) * COLNO) / 5) + 1; - yabs = (((ytmp-1) * ROWNO) / 5) + 1; - switch (xaltmp) { - case LEFT: - break; - case RIGHT: - xabs += (COLNO / 5) - wtmp; - break; - case CENTER: - xabs += ((COLNO / 5) - wtmp) / 2; - break; - } - switch (yaltmp) { - case TOP: - break; - case BOTTOM: - yabs += (ROWNO / 5) - htmp; - break; - case CENTER: - yabs += ((ROWNO / 5) - htmp) / 2; - break; - } + xabs = (((xtmp - 1) * COLNO) / 5) + 1; + yabs = (((ytmp - 1) * ROWNO) / 5) + 1; + switch (xaltmp) { + case LEFT: + break; + case RIGHT: + xabs += (COLNO / 5) - wtmp; + break; + case CENTER: + xabs += ((COLNO / 5) - wtmp) / 2; + break; + } + switch (yaltmp) { + case TOP: + break; + case BOTTOM: + yabs += (ROWNO / 5) - htmp; + break; + case CENTER: + yabs += ((ROWNO / 5) - htmp) / 2; + break; + } - if (xabs + wtmp - 1 > COLNO - 2) - xabs = COLNO - wtmp - 3; - if (xabs < 2) - xabs = 2; - if (yabs + htmp - 1> ROWNO - 2) - yabs = ROWNO - htmp - 3; - if (yabs < 2) - yabs = 2; + if (xabs + wtmp - 1 > COLNO - 2) + xabs = COLNO - wtmp - 3; + if (xabs < 2) + xabs = 2; + if (yabs + htmp - 1 > ROWNO - 2) + yabs = ROWNO - htmp - 3; + if (yabs < 2) + yabs = 2; - /* Try to find a rectangle that fit our room ! */ + /* Try to find a rectangle that fit our room ! */ - r2.lx = xabs-1; r2.ly = yabs-1; - r2.hx = xabs + wtmp + rndpos; - r2.hy = yabs + htmp + rndpos; - r1 = get_rect(&r2); - } - } while (++trycnt <= 100 && !r1); - if (!r1) { /* creation of room failed ? */ - return FALSE; - } - split_rects(r1, &r2); + r2.lx = xabs - 1; + r2.ly = yabs - 1; + r2.hx = xabs + wtmp + rndpos; + r2.hy = yabs + htmp + rndpos; + r1 = get_rect(&r2); + } + } while (++trycnt <= 100 && !r1); + if (!r1) { /* creation of room failed ? */ + return FALSE; + } + split_rects(r1, &r2); - if (!vault) { - smeq[nroom] = nroom; - add_room(xabs, yabs, xabs+wtmp-1, yabs+htmp-1, - rlit, rtype, FALSE); - } else { - rooms[nroom].lx = xabs; - rooms[nroom].ly = yabs; - } - return TRUE; + if (!vault) { + smeq[nroom] = nroom; + add_room(xabs, yabs, xabs + wtmp - 1, yabs + htmp - 1, rlit, rtype, + FALSE); + } else { + rooms[nroom].lx = xabs; + rooms[nroom].ly = yabs; + } + return TRUE; } /* @@ -1112,47 +1196,46 @@ xchar rtype, rlit; */ STATIC_OVL boolean -create_subroom(proom, x, y, w, h, rtype, rlit) +create_subroom(proom, x, y, w, h, rtype, rlit) struct mkroom *proom; -xchar x,y; -xchar w,h; +xchar x, y; +xchar w, h; xchar rtype, rlit; { - xchar width, height; + xchar width, height; - width = proom->hx - proom->lx + 1; - height = proom->hy - proom->ly + 1; + width = proom->hx - proom->lx + 1; + height = proom->hy - proom->ly + 1; - /* There is a minimum size for the parent room */ - if (width < 4 || height < 4) - return FALSE; + /* There is a minimum size for the parent room */ + if (width < 4 || height < 4) + return FALSE; - /* Check for random position, size, etc... */ + /* Check for random position, size, etc... */ - if (w == -1) - w = rnd(width - 3); - if (h == -1) - h = rnd(height - 3); - if (x == -1) - x = rnd(width - w - 1) - 1; - if (y == -1) - y = rnd(height - h - 1) - 1; - if (x == 1) - x = 0; - if (y == 1) - y = 0; - if ((x + w + 1) == width) - x++; - if ((y + h + 1) == height) - y++; - if (rtype == -1) - rtype = OROOM; - if (rlit == -1) - rlit = (rnd(1+abs(depth(&u.uz))) < 11 && rn2(77)) ? TRUE : FALSE; - add_subroom(proom, proom->lx + x, proom->ly + y, - proom->lx + x + w - 1, proom->ly + y + h - 1, - rlit, rtype, FALSE); - return TRUE; + if (w == -1) + w = rnd(width - 3); + if (h == -1) + h = rnd(height - 3); + if (x == -1) + x = rnd(width - w - 1) - 1; + if (y == -1) + y = rnd(height - h - 1) - 1; + if (x == 1) + x = 0; + if (y == 1) + y = 0; + if ((x + w + 1) == width) + x++; + if ((y + h + 1) == height) + y++; + if (rtype == -1) + rtype = OROOM; + if (rlit == -1) + rlit = (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? TRUE : FALSE; + add_subroom(proom, proom->lx + x, proom->ly + y, proom->lx + x + w - 1, + proom->ly + y + h - 1, rlit, rtype, FALSE); + return TRUE; } /* @@ -1165,86 +1248,102 @@ create_door(dd, broom) room_door *dd; struct mkroom *broom; { - int x = 0, y = 0; - int trycnt = 0, wtry = 0; + int x = 0, y = 0; + int trycnt = 0, wtry = 0; - if (dd->secret == -1) - dd->secret = rn2(2); + if (dd->secret == -1) + dd->secret = rn2(2); - if (dd->mask == -1) { - /* is it a locked door, closed, or a doorway? */ - if (!dd->secret) { - if(!rn2(3)) { - if(!rn2(5)) - dd->mask = D_ISOPEN; - else if(!rn2(6)) - dd->mask = D_LOCKED; - else - dd->mask = D_CLOSED; - if (dd->mask != D_ISOPEN && !rn2(25)) - dd->mask |= D_TRAPPED; - } else - dd->mask = D_NODOOR; - } else { - if(!rn2(5)) dd->mask = D_LOCKED; - else dd->mask = D_CLOSED; + if (dd->mask == -1) { + /* is it a locked door, closed, or a doorway? */ + if (!dd->secret) { + if (!rn2(3)) { + if (!rn2(5)) + dd->mask = D_ISOPEN; + else if (!rn2(6)) + dd->mask = D_LOCKED; + else + dd->mask = D_CLOSED; + if (dd->mask != D_ISOPEN && !rn2(25)) + dd->mask |= D_TRAPPED; + } else + dd->mask = D_NODOOR; + } else { + if (!rn2(5)) + dd->mask = D_LOCKED; + else + dd->mask = D_CLOSED; - if(!rn2(20)) dd->mask |= D_TRAPPED; - } - } + if (!rn2(20)) + dd->mask |= D_TRAPPED; + } + } - do { - register int dwall, dpos; + do { + register int dwall, dpos; - dwall = dd->wall; - if (dwall == -1) /* The wall is RANDOM */ - dwall = 1 << rn2(4); + dwall = dd->wall; + if (dwall == -1) /* The wall is RANDOM */ + dwall = 1 << rn2(4); - dpos = dd->pos; + dpos = dd->pos; - /* Convert wall and pos into an absolute coordinate! */ - wtry = rn2(4); - switch (wtry) { - case 0: - if (!(dwall & W_NORTH)) goto redoloop; - y = broom->ly - 1; - x = broom->lx + ((dpos == -1) ? rn2(1+(broom->hx - broom->lx)) : dpos); - if (IS_ROCK(levl[x][y-1].typ)) goto redoloop; - goto outdirloop; - case 1: - if (!(dwall & W_SOUTH)) goto redoloop; - y = broom->hy + 1; - x = broom->lx + ((dpos == -1) ? rn2(1+(broom->hx - broom->lx)) : dpos); - if (IS_ROCK(levl[x][y+1].typ)) goto redoloop; - goto outdirloop; - case 2: - if (!(dwall & W_WEST)) goto redoloop; - x = broom->lx - 1; - y = broom->ly + ((dpos == -1) ? rn2(1+(broom->hy - broom->ly)) : dpos); - if (IS_ROCK(levl[x-1][y].typ)) goto redoloop; - goto outdirloop; - case 3: - if (!(dwall & W_EAST)) goto redoloop; - x = broom->hx + 1; - y = broom->ly + ((dpos == -1) ? rn2(1+(broom->hy - broom->ly)) : dpos); - if (IS_ROCK(levl[x+1][y].typ)) goto redoloop; - goto outdirloop; - default: - x = y = 0; - panic("create_door: No wall for door!"); - goto outdirloop; - } -outdirloop: - if (okdoor(x,y)) - break; -redoloop: ; - } while (++trycnt <= 100); - if (trycnt > 100) { - impossible("create_door: Can't find a proper place!"); - return; - } - levl[x][y].typ = (dd->secret ? SDOOR : DOOR); - levl[x][y].doormask = dd->mask; + /* Convert wall and pos into an absolute coordinate! */ + wtry = rn2(4); + switch (wtry) { + case 0: + if (!(dwall & W_NORTH)) + goto redoloop; + y = broom->ly - 1; + x = broom->lx + + ((dpos == -1) ? rn2(1 + (broom->hx - broom->lx)) : dpos); + if (IS_ROCK(levl[x][y - 1].typ)) + goto redoloop; + goto outdirloop; + case 1: + if (!(dwall & W_SOUTH)) + goto redoloop; + y = broom->hy + 1; + x = broom->lx + + ((dpos == -1) ? rn2(1 + (broom->hx - broom->lx)) : dpos); + if (IS_ROCK(levl[x][y + 1].typ)) + goto redoloop; + goto outdirloop; + case 2: + if (!(dwall & W_WEST)) + goto redoloop; + x = broom->lx - 1; + y = broom->ly + + ((dpos == -1) ? rn2(1 + (broom->hy - broom->ly)) : dpos); + if (IS_ROCK(levl[x - 1][y].typ)) + goto redoloop; + goto outdirloop; + case 3: + if (!(dwall & W_EAST)) + goto redoloop; + x = broom->hx + 1; + y = broom->ly + + ((dpos == -1) ? rn2(1 + (broom->hy - broom->ly)) : dpos); + if (IS_ROCK(levl[x + 1][y].typ)) + goto redoloop; + goto outdirloop; + default: + x = y = 0; + panic("create_door: No wall for door!"); + goto outdirloop; + } + outdirloop: + if (okdoor(x, y)) + break; + redoloop: + ; + } while (++trycnt <= 100); + if (trycnt > 100) { + impossible("create_door: Can't find a proper place!"); + return; + } + levl[x][y].typ = (dd->secret ? SDOOR : DOOR); + levl[x][y].doormask = dd->mask; } /* @@ -1252,36 +1351,44 @@ redoloop: ; */ void create_secret_door(croom, walls) - struct mkroom *croom; - xchar walls; /* any of W_NORTH | W_SOUTH | W_EAST | W_WEST (or W_ANY) */ +struct mkroom *croom; +xchar walls; /* any of W_NORTH | W_SOUTH | W_EAST | W_WEST (or W_ANY) */ { xchar sx, sy; /* location of the secret door */ int count; - for(count = 0; count < 100; count++) { - sx = rn1(croom->hx - croom->lx + 1, croom->lx); - sy = rn1(croom->hy - croom->ly + 1, croom->ly); + for (count = 0; count < 100; count++) { + sx = rn1(croom->hx - croom->lx + 1, croom->lx); + sy = rn1(croom->hy - croom->ly + 1, croom->ly); - switch(rn2(4)) { - case 0: /* top */ - if(!(walls & W_NORTH)) continue; - sy = croom->ly-1; break; - case 1: /* bottom */ - if(!(walls & W_SOUTH)) continue; - sy = croom->hy+1; break; - case 2: /* left */ - if(!(walls & W_EAST)) continue; - sx = croom->lx-1; break; - case 3: /* right */ - if(!(walls & W_WEST)) continue; - sx = croom->hx+1; break; - } + switch (rn2(4)) { + case 0: /* top */ + if (!(walls & W_NORTH)) + continue; + sy = croom->ly - 1; + break; + case 1: /* bottom */ + if (!(walls & W_SOUTH)) + continue; + sy = croom->hy + 1; + break; + case 2: /* left */ + if (!(walls & W_EAST)) + continue; + sx = croom->lx - 1; + break; + case 3: /* right */ + if (!(walls & W_WEST)) + continue; + sx = croom->hx + 1; + break; + } - if(okdoor(sx,sy)) { - levl[sx][sy].typ = SDOOR; - levl[sx][sy].doormask = D_CLOSED; - return; - } + if (okdoor(sx, sy)) { + levl[sx][sy].typ = SDOOR; + levl[sx][sy].doormask = D_CLOSED; + return; + } } impossible("couldn't create secret door on any walls 0x%x", walls); @@ -1292,27 +1399,29 @@ create_secret_door(croom, walls) */ STATIC_OVL void -create_trap(t,croom) -trap *t; -struct mkroom *croom; +create_trap(t, croom) +trap *t; +struct mkroom *croom; { - schar x,y; - coord tm; + schar x, y; + coord tm; if (croom) - get_free_room_loc(&x, &y, croom, t->coord); + get_free_room_loc(&x, &y, croom, t->coord); else { - int trycnt = 0; - do { - get_location_coord(&x, &y, DRY, croom, t->coord); - } while ((levl[x][y].typ == STAIRS || levl[x][y].typ == LADDER) && ++trycnt <= 100); - if (trycnt > 100) return; + int trycnt = 0; + do { + get_location_coord(&x, &y, DRY, croom, t->coord); + } while ((levl[x][y].typ == STAIRS || levl[x][y].typ == LADDER) + && ++trycnt <= 100); + if (trycnt > 100) + return; } - tm.x = x; - tm.y = y; + tm.x = x; + tm.y = y; - mktrap(t->type, 1, (struct mkroom*) 0, &tm); + mktrap(t->type, 1, (struct mkroom *) 0, &tm); } /* @@ -1323,12 +1432,12 @@ STATIC_OVL int noncoalignment(alignment) aligntyp alignment; { - int k; + int k; - k = rn2(2); - if (!alignment) - return(k ? -1 : 1); - return(k ? -alignment : 0); + k = rn2(2); + if (!alignment) + return (k ? -1 : 1); + return (k ? -alignment : 0); } /* attempt to screen out locations where a mimic-as-boulder shouldn't occur */ @@ -1339,22 +1448,24 @@ int x, y; struct rm *lev; /* avoid trap locations */ - if (t_at(x, y)) return TRUE; + if (t_at(x, y)) + return TRUE; /* try to avoid locations which already have a boulder (this won't actually work; we get called before objects have been placed...) */ - if (sobj_at(BOULDER, x, y)) return TRUE; + if (sobj_at(BOULDER, x, y)) + return TRUE; /* avoid closed doors */ lev = &levl[x][y]; if (IS_DOOR(lev->typ) && (lev->doormask & (D_CLOSED | D_LOCKED)) != 0) - return TRUE; + return TRUE; /* spot is ok */ return FALSE; } STATIC_OVL void -create_monster(m,croom) -monster *m; -struct mkroom *croom; +create_monster(m, croom) +monster *m; +struct mkroom *croom; { struct monst *mtmp; schar x, y; @@ -1364,217 +1475,228 @@ struct mkroom *croom; struct permonst *pm; unsigned g_mvflags; + if (m->class >= 0) + class = (char) def_char_to_monclass((char) m->class); + else + class = 0; - if (m->class >= 0) - class = (char) def_char_to_monclass((char)m->class); - else - class = 0; + if (class == MAXMCLASSES) + panic("create_monster: unknown monster class '%c'", m->class); - if (class == MAXMCLASSES) - panic("create_monster: unknown monster class '%c'", m->class); + amask = + (m->align == AM_SPLEV_CO) + ? Align2amask(u.ualignbase[A_ORIGINAL]) + : (m->align == AM_SPLEV_NONCO) + ? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) + : (m->align <= -(MAX_REGISTERS + 1)) + ? induced_align(80) + : (m->align < 0 ? ralign[-m->align - 1] : m->align); - amask = (m->align == AM_SPLEV_CO) ? - Align2amask(u.ualignbase[A_ORIGINAL]) : - (m->align == AM_SPLEV_NONCO) ? - Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) : - (m->align <= -(MAX_REGISTERS+1)) ? induced_align(80) : - (m->align < 0 ? ralign[-m->align-1] : m->align); + if (!class) + pm = (struct permonst *) 0; + else if (m->id != NON_PM) { + pm = &mons[m->id]; + g_mvflags = (unsigned) mvitals[monsndx(pm)].mvflags; + if ((pm->geno & G_UNIQ) && (g_mvflags & G_EXTINCT)) + return; + else if (g_mvflags & G_GONE) /* genocided or extinct */ + pm = (struct permonst *) 0; /* make random monster */ + } else { + pm = mkclass(class, G_NOGEN); + /* if we can't get a specific monster type (pm == 0) then the + class has been genocided, so settle for a random monster */ + } + if (In_mines(&u.uz) && pm && your_race(pm) + && (Race_if(PM_DWARF) || Race_if(PM_GNOME)) && rn2(3)) + pm = (struct permonst *) 0; - if (!class) - pm = (struct permonst *) 0; - else if (m->id != NON_PM) { - pm = &mons[m->id]; - g_mvflags = (unsigned) mvitals[monsndx(pm)].mvflags; - if ((pm->geno & G_UNIQ) && (g_mvflags & G_EXTINCT)) - return; - else if (g_mvflags & G_GONE) /* genocided or extinct */ - pm = (struct permonst *) 0; /* make random monster */ - } else { - pm = mkclass(class,G_NOGEN); - /* if we can't get a specific monster type (pm == 0) then the - class has been genocided, so settle for a random monster */ - } - if (In_mines(&u.uz) && pm && your_race(pm) && - (Race_if(PM_DWARF) || Race_if(PM_GNOME)) && rn2(3)) - pm = (struct permonst *) 0; + if (pm) { + int loc = DRY; + if (pm->mlet == S_EEL || amphibious(pm) || is_swimmer(pm)) + loc = WET; + if (is_flyer(pm) || is_floater(pm)) + loc |= (HOT | WET); + if (passes_walls(pm) || noncorporeal(pm)) + loc |= SOLID; + if (flaming(pm)) + loc |= HOT; + /* If water-liking monster, first try is without DRY */ + get_location_coord(&x, &y, loc | NO_LOC_WARN, croom, m->coord); + if (x == -1 && y == -1) { + loc |= DRY; + get_location_coord(&x, &y, loc, croom, m->coord); + } + } else { + get_location_coord(&x, &y, DRY, croom, m->coord); + } - if (pm) { - int loc = DRY; - if (pm->mlet == S_EEL || amphibious(pm) || is_swimmer(pm)) loc = WET; - if (is_flyer(pm) || is_floater(pm)) loc |= (HOT | WET); - if (passes_walls(pm) || noncorporeal(pm)) loc |= SOLID; - if (flaming(pm)) loc |= HOT; - /* If water-liking monster, first try is without DRY */ - get_location_coord(&x, &y, loc|NO_LOC_WARN, croom, m->coord); - if (x == -1 && y == -1) { - loc |= DRY; - get_location_coord(&x, &y, loc, croom, m->coord); - } - } else { - get_location_coord(&x, &y, DRY, croom, m->coord); - } + /* try to find a close place if someone else is already there */ + if (MON_AT(x, y) && enexto(&cc, x, y, pm)) + x = cc.x, y = cc.y; - /* try to find a close place if someone else is already there */ - if (MON_AT(x,y) && enexto(&cc, x, y, pm)) - x = cc.x, y = cc.y; + if (m->align != -(MAX_REGISTERS + 2)) + mtmp = mk_roamer(pm, Amask2align(amask), x, y, m->peaceful); + else if (PM_ARCHEOLOGIST <= m->id && m->id <= PM_WIZARD) + mtmp = mk_mplayer(pm, x, y, FALSE); + else + mtmp = makemon(pm, x, y, NO_MM_FLAGS); - if(m->align != -(MAX_REGISTERS+2)) - mtmp = mk_roamer(pm, Amask2align(amask), x, y, m->peaceful); - else if(PM_ARCHEOLOGIST <= m->id && m->id <= PM_WIZARD) - mtmp = mk_mplayer(pm, x, y, FALSE); - else mtmp = makemon(pm, x, y, NO_MM_FLAGS); + if (mtmp) { + x = mtmp->mx, y = mtmp->my; /* sanity precaution */ + m->x = x, m->y = y; + /* handle specific attributes for some special monsters */ + if (m->name.str) + mtmp = christen_monst(mtmp, m->name.str); - if (mtmp) { - x = mtmp->mx, y = mtmp->my; /* sanity precaution */ - m->x = x, m->y = y; - /* handle specific attributes for some special monsters */ - if (m->name.str) mtmp = christen_monst(mtmp, m->name.str); + /* + * This is currently hardwired for mimics only. It should + * eventually be expanded. + */ + if (m->appear_as.str + && ((mtmp->data->mlet == S_MIMIC) || mtmp->cham)) { + int i; - /* - * This is currently hardwired for mimics only. It should - * eventually be expanded. - */ - if (m->appear_as.str && ((mtmp->data->mlet == S_MIMIC) || mtmp->cham)) { - int i; + switch (m->appear) { + case M_AP_NOTHING: + impossible("create_monster: mon has an appearance, \"%s\", " + "but no type", + m->appear_as.str); + break; - switch (m->appear) { - case M_AP_NOTHING: - impossible( - "create_monster: mon has an appearance, \"%s\", but no type", - m->appear_as.str); - break; + case M_AP_FURNITURE: + for (i = 0; i < MAXPCHARS; i++) + if (!strcmp(defsyms[i].explanation, m->appear_as.str)) + break; + if (i == MAXPCHARS) { + impossible("create_monster: can't find feature \"%s\"", + m->appear_as.str); + } else { + mtmp->m_ap_type = M_AP_FURNITURE; + mtmp->mappearance = i; + } + break; - case M_AP_FURNITURE: - for (i = 0; i < MAXPCHARS; i++) - if (!strcmp(defsyms[i].explanation, - m->appear_as.str)) - break; - if (i == MAXPCHARS) { - impossible( - "create_monster: can't find feature \"%s\"", - m->appear_as.str); - } else { - mtmp->m_ap_type = M_AP_FURNITURE; - mtmp->mappearance = i; - } - break; + case M_AP_OBJECT: + for (i = 0; i < NUM_OBJECTS; i++) + if (OBJ_NAME(objects[i]) + && !strcmp(OBJ_NAME(objects[i]), m->appear_as.str)) + break; + if (i == NUM_OBJECTS) { + impossible("create_monster: can't find object \"%s\"", + m->appear_as.str); + } else { + mtmp->m_ap_type = M_AP_OBJECT; + mtmp->mappearance = i; + /* try to avoid placing mimic boulder on a trap */ + if (i == BOULDER && m->x < 0 + && m_bad_boulder_spot(x, y)) { + int retrylimit = 10; - case M_AP_OBJECT: - for (i = 0; i < NUM_OBJECTS; i++) - if (OBJ_NAME(objects[i]) && - !strcmp(OBJ_NAME(objects[i]),m->appear_as.str)) - break; - if (i == NUM_OBJECTS) { - impossible( - "create_monster: can't find object \"%s\"", - m->appear_as.str); - } else { - mtmp->m_ap_type = M_AP_OBJECT; - mtmp->mappearance = i; - /* try to avoid placing mimic boulder on a trap */ - if (i == BOULDER && m->x < 0 && - m_bad_boulder_spot(x, y)) { - int retrylimit = 10; + remove_monster(x, y); + do { + x = m->x; + y = m->y; + get_location(&x, &y, DRY, croom); + if (MON_AT(x, y) && enexto(&cc, x, y, pm)) + x = cc.x, y = cc.y; + } while (m_bad_boulder_spot(x, y) + && --retrylimit > 0); + place_monster(mtmp, x, y); + /* if we didn't find a good spot + then mimic something else */ + if (!retrylimit) + set_mimic_sym(mtmp); + } + } + break; - remove_monster(x, y); - do { - x = m->x; - y = m->y; - get_location(&x, &y, DRY, croom); - if (MON_AT(x,y) && enexto(&cc, x, y, pm)) - x = cc.x, y = cc.y; - } while (m_bad_boulder_spot(x, y) && - --retrylimit > 0); - place_monster(mtmp, x, y); - /* if we didn't find a good spot - then mimic something else */ - if (!retrylimit) set_mimic_sym(mtmp); - } - } - break; + case M_AP_MONSTER: { + int mndx; + if (!strcmpi(m->appear_as.str, "random")) + mndx = select_newcham_form(mtmp); + else + mndx = name_to_mon(m->appear_as.str); + if ((mndx != NON_PM) && (&mons[mndx] != mtmp->data)) { + struct permonst *mdat = &mons[mndx]; + struct permonst *olddata = mtmp->data; - case M_AP_MONSTER: - { - int mndx; - if (!strcmpi(m->appear_as.str, "random")) - mndx = select_newcham_form(mtmp); - else - mndx = name_to_mon(m->appear_as.str); - if ((mndx != NON_PM) && (&mons[mndx] != mtmp->data)) { - struct permonst *mdat = &mons[mndx]; - struct permonst *olddata = mtmp->data; + mgender_from_permonst(mtmp, mdat); + set_mon_data(mtmp, mdat, 0); + if (emits_light(olddata) != emits_light(mtmp->data)) { + /* used to give light, now doesn't, or vice versa, + or light's range has changed */ + if (emits_light(olddata)) + del_light_source(LS_MONSTER, (genericptr_t) mtmp); + if (emits_light(mtmp->data)) + new_light_source(mtmp->mx, mtmp->my, + emits_light(mtmp->data), + LS_MONSTER, (genericptr_t) mtmp); + } + if (!mtmp->perminvis || pm_invisible(olddata)) + mtmp->perminvis = pm_invisible(mdat); + } + } break; + default: + impossible("create_monster: unimplemented mon appear type " + "[%d,\"%s\"]", + m->appear, m->appear_as.str); + break; + } + if (does_block(x, y, &levl[x][y])) + block_point(x, y); + } - mgender_from_permonst(mtmp, mdat); - set_mon_data(mtmp, mdat, 0); - if (emits_light(olddata) != emits_light(mtmp->data)) { - /* used to give light, now doesn't, or vice versa, - or light's range has changed */ - if (emits_light(olddata)) - del_light_source(LS_MONSTER, (genericptr_t)mtmp); - if (emits_light(mtmp->data)) - new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data), - LS_MONSTER, (genericptr_t)mtmp); - } - if (!mtmp->perminvis || pm_invisible(olddata)) - mtmp->perminvis = pm_invisible(mdat); - } - } - break; - default: - impossible( - "create_monster: unimplemented mon appear type [%d,\"%s\"]", - m->appear, m->appear_as.str); - break; - } - if (does_block(x, y, &levl[x][y])) - block_point(x, y); - } - - if (m->peaceful >= 0) { - mtmp->mpeaceful = m->peaceful; - /* changed mpeaceful again; have to reset malign */ - set_malign(mtmp); - } - if (m->asleep >= 0) { + if (m->peaceful >= 0) { + mtmp->mpeaceful = m->peaceful; + /* changed mpeaceful again; have to reset malign */ + set_malign(mtmp); + } + if (m->asleep >= 0) { #ifdef UNIXPC - /* optimizer bug strikes again */ - if (m->asleep) - mtmp->msleeping = 1; - else - mtmp->msleeping = 0; + /* optimizer bug strikes again */ + if (m->asleep) + mtmp->msleeping = 1; + else + mtmp->msleeping = 0; #else - mtmp->msleeping = m->asleep; + mtmp->msleeping = m->asleep; #endif - } - if (m->seentraps) mtmp->mtrapseen = m->seentraps; - if (m->female) mtmp->female = 1; - if (m->cancelled) mtmp->mcan = 1; - if (m->revived) mtmp->mrevived = 1; - if (m->avenge) mtmp->mavenge = 1; - if (m->stunned) mtmp->mstun = 1; - if (m->confused) mtmp->mconf = 1; - if (m->invis) { - mtmp->minvis = mtmp->perminvis = 1; - } - if (m->blinded) { - mtmp->mcansee = 0; - mtmp->mblinded = (m->blinded % 127); - } - if (m->paralyzed) { - mtmp->mcanmove = 0; - mtmp->mfrozen = (m->paralyzed % 127); - } - if (m->fleeing) { - mtmp->mflee = 1; - mtmp->mfleetim = (m->fleeing % 127); - } - - if (m->has_invent) { - discard_minvent(mtmp); - invent_carrying_monster = mtmp; - } - } + } + if (m->seentraps) + mtmp->mtrapseen = m->seentraps; + if (m->female) + mtmp->female = 1; + if (m->cancelled) + mtmp->mcan = 1; + if (m->revived) + mtmp->mrevived = 1; + if (m->avenge) + mtmp->mavenge = 1; + if (m->stunned) + mtmp->mstun = 1; + if (m->confused) + mtmp->mconf = 1; + if (m->invis) { + mtmp->minvis = mtmp->perminvis = 1; + } + if (m->blinded) { + mtmp->mcansee = 0; + mtmp->mblinded = (m->blinded % 127); + } + if (m->paralyzed) { + mtmp->mcanmove = 0; + mtmp->mfrozen = (m->paralyzed % 127); + } + if (m->fleeing) { + mtmp->mflee = 1; + mtmp->mfleetim = (m->fleeing % 127); + } + if (m->has_invent) { + discard_minvent(mtmp); + invent_carrying_monster = mtmp; + } + } } /* @@ -1582,211 +1704,225 @@ struct mkroom *croom; */ STATIC_OVL void -create_object(o,croom) -object *o; -struct mkroom *croom; +create_object(o, croom) +object *o; +struct mkroom *croom; { struct obj *otmp; schar x, y; char c; - boolean named; /* has a name been supplied in level description? */ + boolean named; /* has a name been supplied in level description? */ - named = o->name.str ? TRUE : FALSE; + named = o->name.str ? TRUE : FALSE; - get_location_coord(&x, &y, DRY, croom, o->coord); + get_location_coord(&x, &y, DRY, croom, o->coord); - if (o->class >= 0) - c = o->class; - else - c = 0; + if (o->class >= 0) + c = o->class; + else + c = 0; - if (!c) - otmp = mkobj_at(RANDOM_CLASS, x, y, !named); - else if (o->id != -1) - otmp = mksobj_at(o->id, x, y, TRUE, !named); - else { - /* - * The special levels are compiled with the default "text" object - * class characters. We must convert them to the internal format. - */ - char oclass = (char) def_char_to_objclass(c); + if (!c) + otmp = mkobj_at(RANDOM_CLASS, x, y, !named); + else if (o->id != -1) + otmp = mksobj_at(o->id, x, y, TRUE, !named); + else { + /* + * The special levels are compiled with the default "text" object + * class characters. We must convert them to the internal format. + */ + char oclass = (char) def_char_to_objclass(c); - if (oclass == MAXOCLASSES) - panic("create_object: unexpected object class '%c'",c); + if (oclass == MAXOCLASSES) + panic("create_object: unexpected object class '%c'", c); - /* KMH -- Create piles of gold properly */ - if (oclass == COIN_CLASS) - otmp = mkgold(0L, x, y); - else - otmp = mkobj_at(oclass, x, y, !named); - } + /* KMH -- Create piles of gold properly */ + if (oclass == COIN_CLASS) + otmp = mkgold(0L, x, y); + else + otmp = mkobj_at(oclass, x, y, !named); + } - if (o->spe != -127) /* That means NOT RANDOM! */ - otmp->spe = (schar)o->spe; + if (o->spe != -127) /* That means NOT RANDOM! */ + otmp->spe = (schar) o->spe; - switch (o->curse_state) { - case 1: bless(otmp); break; /* BLESSED */ - case 2: unbless(otmp); uncurse(otmp); break; /* uncursed */ - case 3: curse(otmp); break; /* CURSED */ - default: break; /* Otherwise it's random and we're happy - * with what mkobj gave us! */ - } + switch (o->curse_state) { + case 1: + bless(otmp); + break; /* BLESSED */ + case 2: + unbless(otmp); + uncurse(otmp); + break; /* uncursed */ + case 3: + curse(otmp); + break; /* CURSED */ + default: + break; /* Otherwise it's random and we're happy + * with what mkobj gave us! */ + } - /* corpsenm is "empty" if -1, random if -2, otherwise specific */ - if (o->corpsenm != NON_PM) { - if (o->corpsenm == NON_PM - 1) - set_corpsenm(otmp, rndmonnum()); - else set_corpsenm(otmp, o->corpsenm); - } - /* set_corpsenm() took care of egg hatch and corpse timers */ + /* corpsenm is "empty" if -1, random if -2, otherwise specific */ + if (o->corpsenm != NON_PM) { + if (o->corpsenm == NON_PM - 1) + set_corpsenm(otmp, rndmonnum()); + else + set_corpsenm(otmp, o->corpsenm); + } + /* set_corpsenm() took care of egg hatch and corpse timers */ - if (named) - otmp = oname(otmp, o->name.str); + if (named) + otmp = oname(otmp, o->name.str); - if (o->eroded) { - if (o->eroded < 0) otmp->oerodeproof = 1; - else { - otmp->oeroded = (o->eroded % 4); - otmp->oeroded2 = ((o->eroded >> 2) % 4); - } - } - if (o->recharged) otmp->recharged = (o->recharged % 8); - if (o->locked) otmp->olocked = 1; - else if (o->broken) { - otmp->obroken = 1; - otmp->olocked = 0; /* obj generation may set */ - } - if (o->trapped) otmp->otrapped = 1; - if (o->greased) otmp->greased = 1; + if (o->eroded) { + if (o->eroded < 0) + otmp->oerodeproof = 1; + else { + otmp->oeroded = (o->eroded % 4); + otmp->oeroded2 = ((o->eroded >> 2) % 4); + } + } + if (o->recharged) + otmp->recharged = (o->recharged % 8); + if (o->locked) + otmp->olocked = 1; + else if (o->broken) { + otmp->obroken = 1; + otmp->olocked = 0; /* obj generation may set */ + } + if (o->trapped) + otmp->otrapped = 1; + if (o->greased) + otmp->greased = 1; #ifdef INVISIBLE_OBJECTS - if (o->invis) otmp->oinvis = 1; + if (o->invis) + otmp->oinvis = 1; #endif - if ((o->quan > 0) && objects[otmp->otyp].oc_merge) { - otmp->quan = o->quan; - otmp->owt = weight(otmp); - } + if ((o->quan > 0) && objects[otmp->otyp].oc_merge) { + otmp->quan = o->quan; + otmp->owt = weight(otmp); + } - /* contents */ - if (o->containment & SP_OBJ_CONTENT) { - if (!container_idx) { - if (!invent_carrying_monster) { - /*impossible("create_object: no container");*/ - /* don't complain, the monster may be gone legally - (eg. unique demon already generated) - TODO: In the case of unique demon lords, they should - get their inventories even when they get generated - outside the des-file. Maybe another data file that - determines what inventories monsters get by default? - */ - } else { - int ci; - struct obj *objcheck = otmp; - int inuse = -1; + /* contents */ + if (o->containment & SP_OBJ_CONTENT) { + if (!container_idx) { + if (!invent_carrying_monster) { + /*impossible("create_object: no container");*/ + /* don't complain, the monster may be gone legally + (eg. unique demon already generated) + TODO: In the case of unique demon lords, they should + get their inventories even when they get generated + outside the des-file. Maybe another data file that + determines what inventories monsters get by default? + */ + } else { + int ci; + struct obj *objcheck = otmp; + int inuse = -1; - for (ci = 0; ci < container_idx; ci++) - if (container_obj[ci] == objcheck) - inuse = ci; - remove_object(otmp); - if (mpickobj(invent_carrying_monster, otmp)) { - if (inuse > -1) { - impossible( - "container given to monster was merged or deallocated."); - for (ci = inuse; ci < container_idx - 1; ci++) - container_obj[ci] = container_obj[ci + 1]; - container_obj[container_idx] = NULL; - container_idx--; - } - /* we lost track of it. */ - return; - } - } - } else { - remove_object(otmp); - if (container_obj[container_idx-1]) - (void) add_to_container(container_obj[container_idx-1], otmp); - else { - obj_extract_self(otmp); - obfree(otmp, NULL); - return; - } - } - } - /* container */ - if (o->containment & SP_OBJ_CONTAINER) { - delete_contents(otmp); - if (container_idx < MAX_CONTAINMENT) { - container_obj[container_idx] = otmp; - container_idx++; - } else impossible("create_object: too deeply nested containers."); - } - - /* Medusa level special case: statues are petrified monsters, so they - * are not stone-resistant and have monster inventory. They also lack - * other contents, but that can be specified as an empty container. - */ - if (o->id == STATUE && Is_medusa_level(&u.uz) && - o->corpsenm == NON_PM) { - struct monst *was; - struct obj *obj; - int wastyp; - int i = 0; /* prevent endless loop in case makemon always fails */ - - /* Named random statues are of player types, and aren't stone- - * resistant (if they were, we'd have to reset the name as well as - * setting corpsenm). - */ - for (wastyp = otmp->corpsenm; i < 1000 ; i++, wastyp = rndmonnum()) { - /* makemon without rndmonst() might create a group */ - was = makemon(&mons[wastyp], 0, 0, MM_NOCOUNTBIRTH); - if (was) { - if (!resists_ston(was)) { - (void) propagate(wastyp, TRUE, FALSE); - break; - } - mongone(was); - was = NULL; - } - } - if (was) { - set_corpsenm(otmp, wastyp); - while(was->minvent) { - obj = was->minvent; - obj->owornmask = 0; - obj_extract_self(obj); - (void) add_to_container(otmp, obj); - } - otmp->owt = weight(otmp); - mongone(was); - } - } - - /* Nasty hack here: try to determine if this is the Mines or Sokoban - * "prize" and then set record_achieve_special (maps to corpsenm) - * for the object. That field will later be checked to find out if - * the player obtained the prize. */ - if(otmp->otyp == LUCKSTONE && Is_mineend_level(&u.uz)) { - otmp->record_achieve_special = 1; - } else if((otmp->otyp == AMULET_OF_REFLECTION || - otmp->otyp == BAG_OF_HOLDING) && - Is_sokoend_level(&u.uz)) { - otmp->record_achieve_special = 1; + for (ci = 0; ci < container_idx; ci++) + if (container_obj[ci] == objcheck) + inuse = ci; + remove_object(otmp); + if (mpickobj(invent_carrying_monster, otmp)) { + if (inuse > -1) { + impossible("container given to monster was merged or " + "deallocated."); + for (ci = inuse; ci < container_idx - 1; ci++) + container_obj[ci] = container_obj[ci + 1]; + container_obj[container_idx] = NULL; + container_idx--; + } + /* we lost track of it. */ + return; + } + } + } else { + remove_object(otmp); + if (container_obj[container_idx - 1]) + (void) add_to_container(container_obj[container_idx - 1], + otmp); + else { + obj_extract_self(otmp); + obfree(otmp, NULL); + return; + } } + } + /* container */ + if (o->containment & SP_OBJ_CONTAINER) { + delete_contents(otmp); + if (container_idx < MAX_CONTAINMENT) { + container_obj[container_idx] = otmp; + container_idx++; + } else + impossible("create_object: too deeply nested containers."); + } - stackobj(otmp); + /* Medusa level special case: statues are petrified monsters, so they + * are not stone-resistant and have monster inventory. They also lack + * other contents, but that can be specified as an empty container. + */ + if (o->id == STATUE && Is_medusa_level(&u.uz) && o->corpsenm == NON_PM) { + struct monst *was; + struct obj *obj; + int wastyp; + int i = 0; /* prevent endless loop in case makemon always fails */ - if (o->lit) { - begin_burn(otmp, FALSE); - } + /* Named random statues are of player types, and aren't stone- + * resistant (if they were, we'd have to reset the name as well as + * setting corpsenm). + */ + for (wastyp = otmp->corpsenm; i < 1000; i++, wastyp = rndmonnum()) { + /* makemon without rndmonst() might create a group */ + was = makemon(&mons[wastyp], 0, 0, MM_NOCOUNTBIRTH); + if (was) { + if (!resists_ston(was)) { + (void) propagate(wastyp, TRUE, FALSE); + break; + } + mongone(was); + was = NULL; + } + } + if (was) { + set_corpsenm(otmp, wastyp); + while (was->minvent) { + obj = was->minvent; + obj->owornmask = 0; + obj_extract_self(obj); + (void) add_to_container(otmp, obj); + } + otmp->owt = weight(otmp); + mongone(was); + } + } - if (o->buried) { - boolean dealloced; - (void) bury_an_obj(otmp, &dealloced); - if (dealloced && container_idx) { - container_obj[container_idx-1] = NULL; - } - } + /* Nasty hack here: try to determine if this is the Mines or Sokoban + * "prize" and then set record_achieve_special (maps to corpsenm) + * for the object. That field will later be checked to find out if + * the player obtained the prize. */ + if (otmp->otyp == LUCKSTONE && Is_mineend_level(&u.uz)) { + otmp->record_achieve_special = 1; + } else if ((otmp->otyp == AMULET_OF_REFLECTION + || otmp->otyp == BAG_OF_HOLDING) && Is_sokoend_level(&u.uz)) { + otmp->record_achieve_special = 1; + } + stackobj(otmp); + + if (o->lit) { + begin_burn(otmp, FALSE); + } + + if (o->buried) { + boolean dealloced; + (void) bury_an_obj(otmp, &dealloced); + if (dealloced && container_idx) { + container_obj[container_idx - 1] = NULL; + } + } } /* @@ -1795,61 +1931,64 @@ struct mkroom *croom; STATIC_OVL void create_altar(a, croom) - altar *a; - struct mkroom *croom; +altar *a; +struct mkroom *croom; { - schar sproom,x,y; - aligntyp amask; - boolean croom_is_temple = TRUE; - int oldtyp; + schar sproom, x, y; + aligntyp amask; + boolean croom_is_temple = TRUE; + int oldtyp; - if (croom) { - get_free_room_loc(&x, &y, croom, a->coord); - if (croom->rtype != TEMPLE) - croom_is_temple = FALSE; - } else { - get_location_coord(&x, &y, DRY, croom, a->coord); - if ((sproom = (schar) *in_rooms(x, y, TEMPLE)) != 0) - croom = &rooms[sproom - ROOMOFFSET]; - else - croom_is_temple = FALSE; - } + if (croom) { + get_free_room_loc(&x, &y, croom, a->coord); + if (croom->rtype != TEMPLE) + croom_is_temple = FALSE; + } else { + get_location_coord(&x, &y, DRY, croom, a->coord); + if ((sproom = (schar) *in_rooms(x, y, TEMPLE)) != 0) + croom = &rooms[sproom - ROOMOFFSET]; + else + croom_is_temple = FALSE; + } - /* check for existing features */ - oldtyp = levl[x][y].typ; - if (oldtyp == STAIRS || oldtyp == LADDER) - return; + /* check for existing features */ + oldtyp = levl[x][y].typ; + if (oldtyp == STAIRS || oldtyp == LADDER) + return; - /* Is the alignment random ? - * If so, it's an 80% chance that the altar will be co-aligned. - * - * The alignment is encoded as amask values instead of alignment - * values to avoid conflicting with the rest of the encoding, - * shared by many other parts of the special level code. - */ + /* Is the alignment random ? + * If so, it's an 80% chance that the altar will be co-aligned. + * + * The alignment is encoded as amask values instead of alignment + * values to avoid conflicting with the rest of the encoding, + * shared by many other parts of the special level code. + */ - amask = (a->align == AM_SPLEV_CO) ? - Align2amask(u.ualignbase[A_ORIGINAL]) : - (a->align == AM_SPLEV_NONCO) ? - Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) : - (a->align == -(MAX_REGISTERS+1)) ? induced_align(80) : - (a->align < 0 ? ralign[-a->align-1] : a->align); + amask = + (a->align == AM_SPLEV_CO) + ? Align2amask(u.ualignbase[A_ORIGINAL]) + : (a->align == AM_SPLEV_NONCO) + ? Align2amask(noncoalignment(u.ualignbase[A_ORIGINAL])) + : (a->align == -(MAX_REGISTERS + 1)) + ? induced_align(80) + : (a->align < 0 ? ralign[-a->align - 1] : a->align); - levl[x][y].typ = ALTAR; - levl[x][y].altarmask = amask; + levl[x][y].typ = ALTAR; + levl[x][y].altarmask = amask; - if (a->shrine < 0) a->shrine = rn2(2); /* handle random case */ + if (a->shrine < 0) + a->shrine = rn2(2); /* handle random case */ - if (!croom_is_temple || !a->shrine) return; + if (!croom_is_temple || !a->shrine) + return; - if (a->shrine) { /* Is it a shrine or sanctum? */ - priestini(&u.uz, croom, x, y, (a->shrine > 1)); - levl[x][y].altarmask |= AM_SHRINE; - level.flags.has_temple = TRUE; - } + if (a->shrine) { /* Is it a shrine or sanctum? */ + priestini(&u.uz, croom, x, y, (a->shrine > 1)); + levl[x][y].altarmask |= AM_SHRINE; + level.flags.has_temple = TRUE; + } } - void replace_terrain(terr, croom) replaceterrain *terr; @@ -1857,73 +1996,80 @@ struct mkroom *croom; { schar x, y, x1, y1, x2, y2; - if (terr->toter >= MAX_TYPE) return; + if (terr->toter >= MAX_TYPE) + return; - x1 = terr->x1; y1 = terr->y1; + x1 = terr->x1; + y1 = terr->y1; get_location(&x1, &y1, ANY_LOC, croom); - x2 = terr->x2; y2 = terr->y2; + x2 = terr->x2; + y2 = terr->y2; get_location(&x2, &y2, ANY_LOC, croom); - for (x = max(x1,0); x <= min(x2,COLNO-1); x++) - for (y = max(y1,0); y <= min(y2,ROWNO-1); y++) - if ((levl[x][y].typ == terr->fromter) && (rn2(100) < terr->chance)) { - SET_TYPLIT(x,y, terr->toter, terr->tolit); - } + for (x = max(x1, 0); x <= min(x2, COLNO - 1); x++) + for (y = max(y1, 0); y <= min(y2, ROWNO - 1); y++) + if ((levl[x][y].typ == terr->fromter) + && (rn2(100) < terr->chance)) { + SET_TYPLIT(x, y, terr->toter, terr->tolit); + } } - /* * Search for a door in a room on a specified wall. */ STATIC_OVL boolean -search_door(croom,x,y,wall,cnt) +search_door(croom, x, y, wall, cnt) struct mkroom *croom; xchar *x, *y; xchar wall; int cnt; { - int dx, dy; - int xx,yy; + int dx, dy; + int xx, yy; - switch(wall) { - case W_NORTH: - dy = 0; dx = 1; - xx = croom->lx; - yy = croom->hy + 1; - break; - case W_SOUTH: - dy = 0; dx = 1; - xx = croom->lx; - yy = croom->ly - 1; - break; - case W_EAST: - dy = 1; dx = 0; - xx = croom->hx + 1; - yy = croom->ly; - break; - case W_WEST: - dy = 1; dx = 0; - xx = croom->lx - 1; - yy = croom->ly; - break; - default: - dx = dy = xx = yy = 0; - panic("search_door: Bad wall!"); - break; - } - while (xx <= croom->hx+1 && yy <= croom->hy+1) { - if (IS_DOOR(levl[xx][yy].typ) || levl[xx][yy].typ == SDOOR) { - *x = xx; - *y = yy; - if (cnt-- <= 0) - return TRUE; - } - xx += dx; - yy += dy; - } - return FALSE; + switch (wall) { + case W_NORTH: + dy = 0; + dx = 1; + xx = croom->lx; + yy = croom->hy + 1; + break; + case W_SOUTH: + dy = 0; + dx = 1; + xx = croom->lx; + yy = croom->ly - 1; + break; + case W_EAST: + dy = 1; + dx = 0; + xx = croom->hx + 1; + yy = croom->ly; + break; + case W_WEST: + dy = 1; + dx = 0; + xx = croom->lx - 1; + yy = croom->ly; + break; + default: + dx = dy = xx = yy = 0; + panic("search_door: Bad wall!"); + break; + } + while (xx <= croom->hx + 1 && yy <= croom->hy + 1) { + if (IS_DOOR(levl[xx][yy].typ) || levl[xx][yy].typ == SDOOR) { + *x = xx; + *y = yy; + if (cnt-- <= 0) + return TRUE; + } + xx += dx; + yy += dy; + } + return FALSE; } /* @@ -1931,103 +2077,107 @@ int cnt; */ boolean -dig_corridor(org,dest,nxcor,ftyp,btyp) +dig_corridor(org, dest, nxcor, ftyp, btyp) coord *org, *dest; boolean nxcor; schar ftyp, btyp; { - register int dx=0, dy=0, dix, diy, cct; - register struct rm *crm; - register int tx, ty, xx, yy; + register int dx = 0, dy = 0, dix, diy, cct; + register struct rm *crm; + register int tx, ty, xx, yy; - xx = org->x; yy = org->y; - tx = dest->x; ty = dest->y; - if (xx <= 0 || yy <= 0 || tx <= 0 || ty <= 0 || - xx > COLNO-1 || tx > COLNO-1 || - yy > ROWNO-1 || ty > ROWNO-1) { - debugpline4("dig_corridor: bad coords <%d,%d> <%d,%d>.", - xx, yy, tx, ty); - return FALSE; - } - if (tx > xx) dx = 1; - else if (ty > yy) dy = 1; - else if (tx < xx) dx = -1; - else dy = -1; + xx = org->x; + yy = org->y; + tx = dest->x; + ty = dest->y; + if (xx <= 0 || yy <= 0 || tx <= 0 || ty <= 0 || xx > COLNO - 1 + || tx > COLNO - 1 || yy > ROWNO - 1 || ty > ROWNO - 1) { + debugpline4("dig_corridor: bad coords <%d,%d> <%d,%d>.", xx, yy, tx, + ty); + return FALSE; + } + if (tx > xx) + dx = 1; + else if (ty > yy) + dy = 1; + else if (tx < xx) + dx = -1; + else + dy = -1; - xx -= dx; - yy -= dy; - cct = 0; - while(xx != tx || yy != ty) { - /* loop: dig corridor at [xx,yy] and find new [xx,yy] */ - if(cct++ > 500 || (nxcor && !rn2(35))) - return FALSE; + xx -= dx; + yy -= dy; + cct = 0; + while (xx != tx || yy != ty) { + /* loop: dig corridor at [xx,yy] and find new [xx,yy] */ + if (cct++ > 500 || (nxcor && !rn2(35))) + return FALSE; - xx += dx; - yy += dy; + xx += dx; + yy += dy; - if(xx >= COLNO-1 || xx <= 0 || yy <= 0 || yy >= ROWNO-1) - return FALSE; /* impossible */ + if (xx >= COLNO - 1 || xx <= 0 || yy <= 0 || yy >= ROWNO - 1) + return FALSE; /* impossible */ - crm = &levl[xx][yy]; - if(crm->typ == btyp) { - if(ftyp != CORR || rn2(100)) { - crm->typ = ftyp; - if(nxcor && !rn2(50)) - (void) mksobj_at(BOULDER, xx, yy, TRUE, FALSE); - } else { - crm->typ = SCORR; - } - } else - if(crm->typ != ftyp && crm->typ != SCORR) { - /* strange ... */ - return FALSE; - } + crm = &levl[xx][yy]; + if (crm->typ == btyp) { + if (ftyp != CORR || rn2(100)) { + crm->typ = ftyp; + if (nxcor && !rn2(50)) + (void) mksobj_at(BOULDER, xx, yy, TRUE, FALSE); + } else { + crm->typ = SCORR; + } + } else if (crm->typ != ftyp && crm->typ != SCORR) { + /* strange ... */ + return FALSE; + } - /* find next corridor position */ - dix = abs(xx-tx); - diy = abs(yy-ty); + /* find next corridor position */ + dix = abs(xx - tx); + diy = abs(yy - ty); - /* do we have to change direction ? */ - if(dy && dix > diy) { - register int ddx = (xx > tx) ? -1 : 1; + /* do we have to change direction ? */ + if (dy && dix > diy) { + register int ddx = (xx > tx) ? -1 : 1; - crm = &levl[xx+ddx][yy]; - if(crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) { - dx = ddx; - dy = 0; - continue; - } - } else if(dx && diy > dix) { - register int ddy = (yy > ty) ? -1 : 1; + crm = &levl[xx + ddx][yy]; + if (crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) { + dx = ddx; + dy = 0; + continue; + } + } else if (dx && diy > dix) { + register int ddy = (yy > ty) ? -1 : 1; - crm = &levl[xx][yy+ddy]; - if(crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) { - dy = ddy; - dx = 0; - continue; - } - } + crm = &levl[xx][yy + ddy]; + if (crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) { + dy = ddy; + dx = 0; + continue; + } + } - /* continue straight on? */ - crm = &levl[xx+dx][yy+dy]; - if(crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) - continue; + /* continue straight on? */ + crm = &levl[xx + dx][yy + dy]; + if (crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) + continue; - /* no, what must we do now?? */ - if(dx) { - dx = 0; - dy = (ty < yy) ? -1 : 1; - } else { - dy = 0; - dx = (tx < xx) ? -1 : 1; - } - crm = &levl[xx+dx][yy+dy]; - if(crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) - continue; - dy = -dy; - dx = -dx; - } - return TRUE; + /* no, what must we do now?? */ + if (dx) { + dx = 0; + dy = (ty < yy) ? -1 : 1; + } else { + dy = 0; + dx = (tx < xx) ? -1 : 1; + } + crm = &levl[xx + dx][yy + dy]; + if (crm->typ == btyp || crm->typ == ftyp || crm->typ == SCORR) + continue; + dy = -dy; + dx = -dx; + } + return TRUE; } /* @@ -2042,33 +2192,35 @@ fix_stair_rooms() int i; struct mkroom *croom; - if(xdnstair && - !((dnstairs_room->lx <= xdnstair && xdnstair <= dnstairs_room->hx) && - (dnstairs_room->ly <= ydnstair && ydnstair <= dnstairs_room->hy))) { - for(i=0; i < nroom; i++) { - croom = &rooms[i]; - if((croom->lx <= xdnstair && xdnstair <= croom->hx) && - (croom->ly <= ydnstair && ydnstair <= croom->hy)) { - dnstairs_room = croom; - break; - } - } - if(i == nroom) - panic("Couldn't find dnstair room in fix_stair_rooms!"); + if (xdnstair + && !((dnstairs_room->lx <= xdnstair && xdnstair <= dnstairs_room->hx) + && (dnstairs_room->ly <= ydnstair + && ydnstair <= dnstairs_room->hy))) { + for (i = 0; i < nroom; i++) { + croom = &rooms[i]; + if ((croom->lx <= xdnstair && xdnstair <= croom->hx) + && (croom->ly <= ydnstair && ydnstair <= croom->hy)) { + dnstairs_room = croom; + break; + } + } + if (i == nroom) + panic("Couldn't find dnstair room in fix_stair_rooms!"); } - if(xupstair && - !((upstairs_room->lx <= xupstair && xupstair <= upstairs_room->hx) && - (upstairs_room->ly <= yupstair && yupstair <= upstairs_room->hy))) { - for(i=0; i < nroom; i++) { - croom = &rooms[i]; - if((croom->lx <= xupstair && xupstair <= croom->hx) && - (croom->ly <= yupstair && yupstair <= croom->hy)) { - upstairs_room = croom; - break; - } - } - if(i == nroom) - panic("Couldn't find upstair room in fix_stair_rooms!"); + if (xupstair + && !((upstairs_room->lx <= xupstair && xupstair <= upstairs_room->hx) + && (upstairs_room->ly <= yupstair + && yupstair <= upstairs_room->hy))) { + for (i = 0; i < nroom; i++) { + croom = &rooms[i]; + if ((croom->lx <= xupstair && xupstair <= croom->hx) + && (croom->ly <= yupstair && yupstair <= croom->hy)) { + upstairs_room = croom; + break; + } + } + if (i == nroom) + panic("Couldn't find upstair room in fix_stair_rooms!"); } } @@ -2080,41 +2232,56 @@ fix_stair_rooms() STATIC_OVL void create_corridor(c) -corridor *c; +corridor *c; { - coord org, dest; + coord org, dest; - if (c->src.room == -1) { - fix_stair_rooms(); - makecorridors(); /*makecorridors(c->src.door);*/ - return; - } + if (c->src.room == -1) { + fix_stair_rooms(); + makecorridors(); /*makecorridors(c->src.door);*/ + return; + } - if( !search_door(&rooms[c->src.room], &org.x, &org.y, c->src.wall, - c->src.door)) - return; + if (!search_door(&rooms[c->src.room], &org.x, &org.y, c->src.wall, + c->src.door)) + return; - if (c->dest.room != -1) { - if(!search_door(&rooms[c->dest.room], &dest.x, &dest.y, - c->dest.wall, c->dest.door)) - return; - switch(c->src.wall) { - case W_NORTH: org.y--; break; - case W_SOUTH: org.y++; break; - case W_WEST: org.x--; break; - case W_EAST: org.x++; break; - } - switch(c->dest.wall) { - case W_NORTH: dest.y--; break; - case W_SOUTH: dest.y++; break; - case W_WEST: dest.x--; break; - case W_EAST: dest.x++; break; - } - (void) dig_corridor(&org, &dest, FALSE, CORR, STONE); - } + if (c->dest.room != -1) { + if (!search_door(&rooms[c->dest.room], &dest.x, &dest.y, c->dest.wall, + c->dest.door)) + return; + switch (c->src.wall) { + case W_NORTH: + org.y--; + break; + case W_SOUTH: + org.y++; + break; + case W_WEST: + org.x--; + break; + case W_EAST: + org.x++; + break; + } + switch (c->dest.wall) { + case W_NORTH: + dest.y--; + break; + case W_SOUTH: + dest.y++; + break; + case W_WEST: + dest.x--; + break; + case W_EAST: + dest.x++; + break; + } + (void) dig_corridor(&org, &dest, FALSE, CORR, STONE); + } } - /* * Fill a room (shop, zoo, etc...) with appropriate stuff. */ @@ -2124,93 +2291,92 @@ fill_room(croom, prefilled) struct mkroom *croom; boolean prefilled; { - if (!croom || croom->rtype == OROOM) - return; + if (!croom || croom->rtype == OROOM) + return; - if (!prefilled) { - int x,y; + if (!prefilled) { + int x, y; - /* Shop ? */ - if (croom->rtype >= SHOPBASE) { - stock_room(croom->rtype - SHOPBASE, croom); - level.flags.has_shop = TRUE; - return; - } + /* Shop ? */ + if (croom->rtype >= SHOPBASE) { + stock_room(croom->rtype - SHOPBASE, croom); + level.flags.has_shop = TRUE; + return; + } - switch (croom->rtype) { - case VAULT: - for (x=croom->lx;x<=croom->hx;x++) - for (y=croom->ly;y<=croom->hy;y++) - (void) mkgold((long)rn1(abs(depth(&u.uz))*100, 51), x, y); - break; - case COURT: - case ZOO: - case BEEHIVE: - case MORGUE: - case BARRACKS: - fill_zoo(croom); - break; - } - } - switch (croom->rtype) { - case VAULT: - level.flags.has_vault = TRUE; - break; - case ZOO: - level.flags.has_zoo = TRUE; - break; - case COURT: - level.flags.has_court = TRUE; - break; - case MORGUE: - level.flags.has_morgue = TRUE; - break; - case BEEHIVE: - level.flags.has_beehive = TRUE; - break; - case BARRACKS: - level.flags.has_barracks = TRUE; - break; - case TEMPLE: - level.flags.has_temple = TRUE; - break; - case SWAMP: - level.flags.has_swamp = TRUE; - break; - } + switch (croom->rtype) { + case VAULT: + for (x = croom->lx; x <= croom->hx; x++) + for (y = croom->ly; y <= croom->hy; y++) + (void) mkgold((long) rn1(abs(depth(&u.uz)) * 100, 51), x, + y); + break; + case COURT: + case ZOO: + case BEEHIVE: + case MORGUE: + case BARRACKS: + fill_zoo(croom); + break; + } + } + switch (croom->rtype) { + case VAULT: + level.flags.has_vault = TRUE; + break; + case ZOO: + level.flags.has_zoo = TRUE; + break; + case COURT: + level.flags.has_court = TRUE; + break; + case MORGUE: + level.flags.has_morgue = TRUE; + break; + case BEEHIVE: + level.flags.has_beehive = TRUE; + break; + case BARRACKS: + level.flags.has_barracks = TRUE; + break; + case TEMPLE: + level.flags.has_temple = TRUE; + break; + case SWAMP: + level.flags.has_swamp = TRUE; + break; + } } - struct mkroom * build_room(r, mkr) room *r; struct mkroom *mkr; { - boolean okroom; - struct mkroom *aroom; - xchar rtype = (!r->chance || rn2(100) < r->chance) ? r->rtype : OROOM; + boolean okroom; + struct mkroom *aroom; + xchar rtype = (!r->chance || rn2(100) < r->chance) ? r->rtype : OROOM; - if(mkr) { - aroom = &subrooms[nsubroom]; - okroom = create_subroom(mkr, r->x, r->y, r->w, r->h, - rtype, r->rlit); - } else { - aroom = &rooms[nroom]; - okroom = create_room(r->x, r->y, r->w, r->h, r->xalign, - r->yalign, rtype, r->rlit); - } + if (mkr) { + aroom = &subrooms[nsubroom]; + okroom = create_subroom(mkr, r->x, r->y, r->w, r->h, rtype, r->rlit); + } else { + aroom = &rooms[nroom]; + okroom = create_room(r->x, r->y, r->w, r->h, r->xalign, r->yalign, + rtype, r->rlit); + } - if (okroom) { + if (okroom) { #ifdef SPECIALIZATION - topologize(aroom,FALSE); /* set roomno */ + topologize(aroom, FALSE); /* set roomno */ #else - topologize(aroom); /* set roomno */ + topologize(aroom); /* set roomno */ #endif - aroom->needfill = r->filled; - aroom->needjoining = r->joined; - return aroom; - } - return (struct mkroom *)0; + aroom->needfill = r->filled; + aroom->needjoining = r->joined; + return aroom; + } + return (struct mkroom *) 0; } /* @@ -2218,7 +2384,7 @@ struct mkroom *mkr; */ STATIC_OVL void light_region(tmpregion) - region *tmpregion; +region *tmpregion; { register boolean litstate = tmpregion->rlit ? 1 : 0; register int hiy = tmpregion->y2; @@ -2227,46 +2393,47 @@ light_region(tmpregion) int lowy = tmpregion->y1; int lowx = tmpregion->x1, hix = tmpregion->x2; - if(litstate) { - /* adjust region size for walls, but only if lighted */ - lowx = max(lowx-1,1); - hix = min(hix+1,COLNO-1); - lowy = max(lowy-1,0); - hiy = min(hiy+1, ROWNO-1); + if (litstate) { + /* adjust region size for walls, but only if lighted */ + lowx = max(lowx - 1, 1); + hix = min(hix + 1, COLNO - 1); + lowy = max(lowy - 1, 0); + hiy = min(hiy + 1, ROWNO - 1); } - for(x = lowx; x <= hix; x++) { - lev = &levl[x][lowy]; - for(y = lowy; y <= hiy; y++) { - if (lev->typ != LAVAPOOL) /* this overrides normal lighting */ - lev->lit = litstate; - lev++; - } + for (x = lowx; x <= hix; x++) { + lev = &levl[x][lowy]; + for (y = lowy; y <= hiy; y++) { + if (lev->typ != LAVAPOOL) /* this overrides normal lighting */ + lev->lit = litstate; + lev++; + } } } void -wallify_map(x1,y1,x2,y2) -int x1,y1,x2,y2; +wallify_map(x1, y1, x2, y2) +int x1, y1, x2, y2; { - int x, y, xx, yy, lo_xx, lo_yy, hi_xx, hi_yy; + int x, y, xx, yy, lo_xx, lo_yy, hi_xx, hi_yy; - for (y = y1; y <= y2; y++) { - lo_yy = (y > 0) ? y - 1 : 0; - hi_yy = (y < y2) ? y + 1 : y2; - for (x = x1; x <= x2; x++) { - if (levl[x][y].typ != STONE) continue; - lo_xx = (x > 0) ? x - 1 : 0; - hi_xx = (x < x2) ? x + 1 : x2; - for (yy = lo_yy; yy <= hi_yy; yy++) - for (xx = lo_xx; xx <= hi_xx; xx++) - if (IS_ROOM(levl[xx][yy].typ) || - levl[xx][yy].typ == CROSSWALL) { - levl[x][y].typ = (yy != y) ? HWALL : VWALL; - yy = hi_yy; /* end `yy' loop */ - break; /* end `xx' loop */ - } - } - } + for (y = y1; y <= y2; y++) { + lo_yy = (y > 0) ? y - 1 : 0; + hi_yy = (y < y2) ? y + 1 : y2; + for (x = x1; x <= x2; x++) { + if (levl[x][y].typ != STONE) + continue; + lo_xx = (x > 0) ? x - 1 : 0; + hi_xx = (x < x2) ? x + 1 : x2; + for (yy = lo_yy; yy <= hi_yy; yy++) + for (xx = lo_xx; xx <= hi_xx; xx++) + if (IS_ROOM(levl[xx][yy].typ) + || levl[xx][yy].typ == CROSSWALL) { + levl[x][y].typ = (yy != y) ? HWALL : VWALL; + yy = hi_yy; /* end `yy' loop */ + break; /* end `xx' loop */ + } + } + } } /* @@ -2281,19 +2448,20 @@ maze1xy(m, humidity) coord *m; int humidity; { - register int x, y, tryct = 2000; - /* tryct: normally it won't take more than ten or so tries due - to the circumstances under which we'll be called, but the - `humidity' screening might drastically change the chances */ + register int x, y, tryct = 2000; + /* tryct: normally it won't take more than ten or so tries due + to the circumstances under which we'll be called, but the + `humidity' screening might drastically change the chances */ - do { - x = rn1(x_maze_max - 3, 3); - y = rn1(y_maze_max - 3, 3); - if (--tryct < 0) break; /* give up */ - } while (!(x % 2) || !(y % 2) || SpLev_Map[x][y] || - !is_ok_location((schar)x, (schar)y, humidity)); + do { + x = rn1(x_maze_max - 3, 3); + y = rn1(y_maze_max - 3, 3); + if (--tryct < 0) + break; /* give up */ + } while (!(x % 2) || !(y % 2) || SpLev_Map[x][y] + || !is_ok_location((schar) x, (schar) y, humidity)); - m->x = (xchar)x, m->y = (xchar)y; + m->x = (xchar) x, m->y = (xchar) y; } /* @@ -2307,50 +2475,51 @@ STATIC_OVL void fill_empty_maze() { int mapcountmax, mapcount, mapfact; - xchar x,y; + xchar x, y; coord mm; mapcountmax = mapcount = (x_maze_max - 2) * (y_maze_max - 2); mapcountmax = mapcountmax / 2; - for(x = 2; x < x_maze_max; x++) - for(y = 0; y < y_maze_max; y++) - if(SpLev_Map[x][y]) mapcount--; + for (x = 2; x < x_maze_max; x++) + for (y = 0; y < y_maze_max; y++) + if (SpLev_Map[x][y]) + mapcount--; if ((mapcount > (int) (mapcountmax / 10))) { - mapfact = (int) ((mapcount * 100L) / mapcountmax); - for(x = rnd((int) (20 * mapfact) / 100); x; x--) { - maze1xy(&mm, DRY); - (void) mkobj_at(rn2(2) ? GEM_CLASS : RANDOM_CLASS, - mm.x, mm.y, TRUE); - } - for(x = rnd((int) (12 * mapfact) / 100); x; x--) { - maze1xy(&mm, DRY); - (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE); - } - for (x = rn2(2); x; x--) { - maze1xy(&mm, DRY); - (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS); - } - for(x = rnd((int) (12 * mapfact) / 100); x; x--) { - maze1xy(&mm, DRY); - (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS); - } - for(x = rn2((int) (15 * mapfact) / 100); x; x--) { - maze1xy(&mm, DRY); - (void) mkgold(0L,mm.x,mm.y); - } - for(x = rn2((int) (15 * mapfact) / 100); x; x--) { - int trytrap; + mapfact = (int) ((mapcount * 100L) / mapcountmax); + for (x = rnd((int) (20 * mapfact) / 100); x; x--) { + maze1xy(&mm, DRY); + (void) mkobj_at(rn2(2) ? GEM_CLASS : RANDOM_CLASS, mm.x, mm.y, + TRUE); + } + for (x = rnd((int) (12 * mapfact) / 100); x; x--) { + maze1xy(&mm, DRY); + (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE); + } + for (x = rn2(2); x; x--) { + maze1xy(&mm, DRY); + (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS); + } + for (x = rnd((int) (12 * mapfact) / 100); x; x--) { + maze1xy(&mm, DRY); + (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS); + } + for (x = rn2((int) (15 * mapfact) / 100); x; x--) { + maze1xy(&mm, DRY); + (void) mkgold(0L, mm.x, mm.y); + } + for (x = rn2((int) (15 * mapfact) / 100); x; x--) { + int trytrap; - maze1xy(&mm, DRY); - trytrap = rndtrap(); - if (sobj_at(BOULDER, mm.x, mm.y)) - while (trytrap == PIT || trytrap == SPIKED_PIT || - trytrap == TRAPDOOR || trytrap == HOLE) - trytrap = rndtrap(); - (void) maketrap(mm.x, mm.y, trytrap); - } + maze1xy(&mm, DRY); + trytrap = rndtrap(); + if (sobj_at(BOULDER, mm.x, mm.y)) + while (trytrap == PIT || trytrap == SPIKED_PIT + || trytrap == TRAPDOOR || trytrap == HOLE) + trytrap = rndtrap(); + (void) maketrap(mm.x, mm.y, trytrap); + } } } @@ -2366,65 +2535,66 @@ sp_lev *lvl; struct opvar *opdat; int opcode; - Fread((genericptr_t)&(lvl->n_opcodes), 1, sizeof(lvl->n_opcodes), fd); - lvl->opcodes = (_opcode *)alloc(sizeof(_opcode) * (lvl->n_opcodes)); + Fread((genericptr_t) & (lvl->n_opcodes), 1, sizeof(lvl->n_opcodes), fd); + lvl->opcodes = (_opcode *) alloc(sizeof(_opcode) * (lvl->n_opcodes)); while (n_opcode < lvl->n_opcodes) { + Fread((genericptr_t) &lvl->opcodes[n_opcode].opcode, 1, + sizeof(lvl->opcodes[n_opcode].opcode), fd); + opcode = lvl->opcodes[n_opcode].opcode; - Fread((genericptr_t) &lvl->opcodes[n_opcode].opcode, 1, - sizeof(lvl->opcodes[n_opcode].opcode), fd); - opcode = lvl->opcodes[n_opcode].opcode; + opdat = NULL; - opdat = NULL; + if (opcode < SPO_NULL || opcode >= MAX_SP_OPCODES) + panic("sp_level_loader: impossible opcode %i.", opcode); - if (opcode < SPO_NULL || opcode >= MAX_SP_OPCODES) - panic("sp_level_loader: impossible opcode %i.", opcode); + if (opcode == SPO_PUSH) { + int nsize; + struct opvar *ov = (struct opvar *) alloc(sizeof(struct opvar)); - if (opcode == SPO_PUSH) { - int nsize; - struct opvar *ov = (struct opvar *)alloc(sizeof(struct opvar)); + opdat = ov; + ov->spovartyp = SPO_NULL; + ov->vardata.l = 0; + Fread((genericptr_t) & (ov->spovartyp), 1, sizeof(ov->spovartyp), + fd); - opdat = ov; - ov->spovartyp = SPO_NULL; - ov->vardata.l = 0; - Fread((genericptr_t)&(ov->spovartyp), 1, sizeof(ov->spovartyp), fd); + switch (ov->spovartyp) { + case SPOVAR_NULL: + break; + case SPOVAR_COORD: + case SPOVAR_REGION: + case SPOVAR_MAPCHAR: + case SPOVAR_MONST: + case SPOVAR_OBJ: + case SPOVAR_INT: + Fread((genericptr_t) & (ov->vardata.l), 1, + sizeof(ov->vardata.l), fd); + break; + case SPOVAR_VARIABLE: + case SPOVAR_STRING: + case SPOVAR_SEL: { + char *opd; + Fread((genericptr_t) &nsize, 1, sizeof(nsize), fd); + opd = (char *) alloc(nsize + 1); - switch (ov->spovartyp) { - case SPOVAR_NULL: break; - case SPOVAR_COORD: - case SPOVAR_REGION: - case SPOVAR_MAPCHAR: - case SPOVAR_MONST: - case SPOVAR_OBJ: - case SPOVAR_INT: - Fread((genericptr_t)&(ov->vardata.l), 1, sizeof(ov->vardata.l), fd); - break; - case SPOVAR_VARIABLE: - case SPOVAR_STRING: - case SPOVAR_SEL: - { - char *opd; - Fread((genericptr_t) &nsize, 1, sizeof(nsize), fd); - opd = (char *)alloc(nsize + 1); + if (nsize) + Fread(opd, 1, nsize, fd); + opd[nsize] = 0; + ov->vardata.str = opd; + } break; + default: + panic("sp_level_loader: unknown opvar type %i", + ov->spovartyp); + } + } - if (nsize) Fread(opd, 1, nsize, fd); - opd[nsize] = 0; - ov->vardata.str = opd; - } - break; - default: - panic("sp_level_loader: unknown opvar type %i", ov->spovartyp); - } - } - - lvl->opcodes[n_opcode].opdat = opdat; - n_opcode++; + lvl->opcodes[n_opcode].opdat = opdat; + n_opcode++; } /*while*/ return TRUE; } - /* Frees the memory allocated for special level creation structs */ STATIC_OVL boolean sp_level_free(lvl) @@ -2433,14 +2603,15 @@ sp_lev *lvl; long n_opcode = 0; while (n_opcode < lvl->n_opcodes) { - int opcode = lvl->opcodes[n_opcode].opcode; - struct opvar *opdat = lvl->opcodes[n_opcode].opdat; + int opcode = lvl->opcodes[n_opcode].opcode; + struct opvar *opdat = lvl->opcodes[n_opcode].opdat; - if (opcode < SPO_NULL || opcode >= MAX_SP_OPCODES) - panic("sp_level_free: unknown opcode %i", opcode); + if (opcode < SPO_NULL || opcode >= MAX_SP_OPCODES) + panic("sp_level_free: unknown opcode %i", opcode); - if (opdat) opvar_free(opdat); - n_opcode++; + if (opdat) + opvar_free(opdat); + n_opcode++; } Free(lvl->opcodes); lvl->opcodes = NULL; @@ -2452,62 +2623,70 @@ splev_initlev(linit) lev_init *linit; { switch (linit->init_style) { - default: impossible("Unrecognized level init style."); break; - case LVLINIT_NONE: break; + default: + impossible("Unrecognized level init style."); + break; + case LVLINIT_NONE: + break; case LVLINIT_SOLIDFILL: - if (linit->lit == -1) linit->lit = rn2(2); - lvlfill_solid(linit->filling, linit->lit); - break; + if (linit->lit == -1) + linit->lit = rn2(2); + lvlfill_solid(linit->filling, linit->lit); + break; case LVLINIT_MAZEGRID: - lvlfill_maze_grid(2,0, x_maze_max,y_maze_max, linit->filling); - break; + lvlfill_maze_grid(2, 0, x_maze_max, y_maze_max, linit->filling); + break; #ifdef REINCARNATION case LVLINIT_ROGUE: - makeroguerooms(); - break; + makeroguerooms(); + break; #endif case LVLINIT_MINES: - if (linit->lit == -1) linit->lit = rn2(2); - if (linit->filling > -1) lvlfill_solid(linit->filling, 0); - linit->icedpools = icedpools; - mkmap(linit); - break; + if (linit->lit == -1) + linit->lit = rn2(2); + if (linit->filling > -1) + lvlfill_solid(linit->filling, 0); + linit->icedpools = icedpools; + mkmap(linit); + break; } } struct sp_frame * frame_new(execptr) - long execptr; +long execptr; { - struct sp_frame *frame = (struct sp_frame *)alloc(sizeof(struct sp_frame)); + struct sp_frame *frame = + (struct sp_frame *) alloc(sizeof(struct sp_frame)); frame->next = NULL; frame->variables = NULL; frame->n_opcode = execptr; - frame->stack = (struct splevstack *)alloc(sizeof(struct splevstack)); + frame->stack = (struct splevstack *) alloc(sizeof(struct splevstack)); splev_stack_init(frame->stack); return frame; } void frame_del(frame) - struct sp_frame *frame; +struct sp_frame *frame; { - if (!frame) return; + if (!frame) + return; if (frame->stack) { - splev_stack_done(frame->stack); - frame->stack = NULL; + splev_stack_done(frame->stack); + frame->stack = NULL; } if (frame->variables) { - variable_list_del(frame->variables); - frame->variables = NULL; + variable_list_del(frame->variables); + frame->variables = NULL; } Free(frame); } void spo_frame_push(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct sp_frame *tmpframe = frame_new(coder->frame->n_opcode); tmpframe->next = coder->frame; @@ -2516,38 +2695,41 @@ spo_frame_push(coder) void spo_frame_pop(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (coder->frame && coder->frame->next) { - struct sp_frame *tmpframe = coder->frame->next; - frame_del(coder->frame); - coder->frame = tmpframe; - coder->stack = coder->frame->stack; + struct sp_frame *tmpframe = coder->frame->next; + frame_del(coder->frame); + coder->frame = tmpframe; + coder->stack = coder->frame->stack; } } long sp_code_jmpaddr(curpos, jmpaddr) - long curpos, jmpaddr; +long curpos, jmpaddr; { return (curpos + jmpaddr); } void spo_call(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *addr; struct opvar *params; struct sp_frame *tmpframe; - if (!OV_pop_i(addr) || !OV_pop_i(params)) return; - if (OV_i(params) < 0) return; + if (!OV_pop_i(addr) || !OV_pop_i(params)) + return; + if (OV_i(params) < 0) + return; - tmpframe = frame_new(sp_code_jmpaddr(coder->frame->n_opcode, OV_i(addr)-1)); + tmpframe = + frame_new(sp_code_jmpaddr(coder->frame->n_opcode, OV_i(addr) - 1)); while (OV_i(params)-- > 0) { - splev_stack_push(tmpframe->stack, splev_stack_getdat_any(coder)); + splev_stack_push(tmpframe->stack, splev_stack_getdat_any(coder)); } splev_stack_reverse(tmpframe->stack); @@ -2561,23 +2743,27 @@ spo_call(coder) void spo_return(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *params; - if (!coder->frame || !coder->frame->next) panic("return: no frame."); - if (!OV_pop_i(params)) return; - if (OV_i(params) < 0) return; + if (!coder->frame || !coder->frame->next) + panic("return: no frame."); + if (!OV_pop_i(params)) + return; + if (OV_i(params) < 0) + return; while (OV_i(params)-- > 0) { - splev_stack_push(coder->frame->next->stack, splev_stack_pop(coder->stack)); + splev_stack_push(coder->frame->next->stack, + splev_stack_pop(coder->stack)); } /* pop the frame */ if (coder->frame->next) { - struct sp_frame *tmpframe = coder->frame->next; - frame_del(coder->frame); - coder->frame = tmpframe; - coder->stack = coder->frame->stack; + struct sp_frame *tmpframe = coder->frame->next; + frame_del(coder->frame); + coder->frame = tmpframe; + coder->stack = coder->frame->stack; } opvar_free(params); @@ -2586,45 +2772,48 @@ spo_return(coder) /*ARGUSED*/ void spo_end_moninvent(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (invent_carrying_monster) - m_dowear(invent_carrying_monster, TRUE); + m_dowear(invent_carrying_monster, TRUE); invent_carrying_monster = NULL; } /*ARGUSED*/ void spo_pop_container(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (container_idx > 0) { - container_idx--; - container_obj[container_idx] = NULL; + container_idx--; + container_obj[container_idx] = NULL; } } - void spo_message(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *op; char *msg, *levmsg; int old_n, n; - if (!OV_pop_s(op)) return; + if (!OV_pop_s(op)) + return; msg = OV_s(op); - if (!msg) return; + if (!msg) + return; - old_n = lev_message ? (strlen(lev_message)+1) : 0; + old_n = lev_message ? (strlen(lev_message) + 1) : 0; n = strlen(msg); - levmsg = (char *) alloc(old_n+n+1); - if (old_n) levmsg[old_n-1] = '\n'; + levmsg = (char *) alloc(old_n + n + 1); + if (old_n) + levmsg[old_n - 1] = '\n'; if (lev_message) - (void) memcpy((genericptr_t)levmsg, (genericptr_t)lev_message, old_n-1); - (void) memcpy((genericptr_t)&levmsg[old_n], msg, n); - levmsg[old_n+n] = '\0'; + (void) memcpy((genericptr_t) levmsg, (genericptr_t) lev_message, + old_n - 1); + (void) memcpy((genericptr_t) &levmsg[old_n], msg, n); + levmsg[old_n + n] = '\0'; Free(lev_message); lev_message = levmsg; opvar_free(op); @@ -2632,7 +2821,7 @@ spo_message(coder) void spo_monster(coder) - struct sp_coder *coder; +struct sp_coder *coder; { int nparams = 0; @@ -2642,10 +2831,10 @@ spo_monster(coder) tmpmons.peaceful = -1; tmpmons.asleep = -1; - tmpmons.name.str = (char *)0; + tmpmons.name.str = (char *) 0; tmpmons.appear = 0; - tmpmons.appear_as.str = (char *)0; - tmpmons.align = - MAX_REGISTERS - 2; + tmpmons.appear_as.str = (char *) 0; + tmpmons.align = -MAX_REGISTERS - 2; tmpmons.female = 0; tmpmons.invis = 0; tmpmons.cancelled = 0; @@ -2659,104 +2848,104 @@ spo_monster(coder) tmpmons.seentraps = 0; tmpmons.has_invent = 0; - if (!OV_pop_i(has_inv)) return; + if (!OV_pop_i(has_inv)) + return; - if (!OV_pop_i(varparam)) return; + if (!OV_pop_i(varparam)) + return; - while ((nparams++ < (SP_M_V_END+1)) && - (OV_typ(varparam) == SPOVAR_INT) && - (OV_i(varparam) >= 0) && - (OV_i(varparam) < SP_M_V_END)) { - struct opvar *parm = NULL; - OV_pop(parm); - switch (OV_i(varparam)) { - case SP_M_V_NAME: - if ((OV_typ(parm) == SPOVAR_STRING) && - !tmpmons.name.str) - tmpmons.name.str = dupstr(OV_s(parm)); - break; - case SP_M_V_APPEAR: - if ((OV_typ(parm) == SPOVAR_INT) && - !tmpmons.appear_as.str) { - tmpmons.appear = OV_i(parm); - opvar_free(parm); - OV_pop(parm); - tmpmons.appear_as.str = dupstr(OV_s(parm)); - } - break; - case SP_M_V_ASLEEP: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.asleep = OV_i(parm); - break; - case SP_M_V_ALIGN: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.align = OV_i(parm); - break; - case SP_M_V_PEACEFUL: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.peaceful = OV_i(parm); - break; - case SP_M_V_FEMALE: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.female = OV_i(parm); - break; - case SP_M_V_INVIS: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.invis = OV_i(parm); - break; - case SP_M_V_CANCELLED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.cancelled = OV_i(parm); - break; - case SP_M_V_REVIVED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.revived = OV_i(parm); - break; - case SP_M_V_AVENGE: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.avenge = OV_i(parm); - break; - case SP_M_V_FLEEING: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.fleeing = OV_i(parm); - break; - case SP_M_V_BLINDED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.blinded = OV_i(parm); - break; - case SP_M_V_PARALYZED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.paralyzed = OV_i(parm); - break; - case SP_M_V_STUNNED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.stunned = OV_i(parm); - break; - case SP_M_V_CONFUSED: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.confused = OV_i(parm); - break; - case SP_M_V_SEENTRAPS: - if (OV_typ(parm) == SPOVAR_INT) - tmpmons.seentraps = OV_i(parm); - break; - case SP_M_V_END: - nparams = SP_M_V_END+1; - break; - default: - impossible("MONSTER with unknown variable param type!"); - break; - } - opvar_free(parm); - if (OV_i(varparam) != SP_M_V_END) { - opvar_free(varparam); - OV_pop(varparam); - } + while ((nparams++ < (SP_M_V_END + 1)) && (OV_typ(varparam) == SPOVAR_INT) + && (OV_i(varparam) >= 0) && (OV_i(varparam) < SP_M_V_END)) { + struct opvar *parm = NULL; + OV_pop(parm); + switch (OV_i(varparam)) { + case SP_M_V_NAME: + if ((OV_typ(parm) == SPOVAR_STRING) && !tmpmons.name.str) + tmpmons.name.str = dupstr(OV_s(parm)); + break; + case SP_M_V_APPEAR: + if ((OV_typ(parm) == SPOVAR_INT) && !tmpmons.appear_as.str) { + tmpmons.appear = OV_i(parm); + opvar_free(parm); + OV_pop(parm); + tmpmons.appear_as.str = dupstr(OV_s(parm)); + } + break; + case SP_M_V_ASLEEP: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.asleep = OV_i(parm); + break; + case SP_M_V_ALIGN: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.align = OV_i(parm); + break; + case SP_M_V_PEACEFUL: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.peaceful = OV_i(parm); + break; + case SP_M_V_FEMALE: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.female = OV_i(parm); + break; + case SP_M_V_INVIS: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.invis = OV_i(parm); + break; + case SP_M_V_CANCELLED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.cancelled = OV_i(parm); + break; + case SP_M_V_REVIVED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.revived = OV_i(parm); + break; + case SP_M_V_AVENGE: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.avenge = OV_i(parm); + break; + case SP_M_V_FLEEING: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.fleeing = OV_i(parm); + break; + case SP_M_V_BLINDED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.blinded = OV_i(parm); + break; + case SP_M_V_PARALYZED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.paralyzed = OV_i(parm); + break; + case SP_M_V_STUNNED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.stunned = OV_i(parm); + break; + case SP_M_V_CONFUSED: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.confused = OV_i(parm); + break; + case SP_M_V_SEENTRAPS: + if (OV_typ(parm) == SPOVAR_INT) + tmpmons.seentraps = OV_i(parm); + break; + case SP_M_V_END: + nparams = SP_M_V_END + 1; + break; + default: + impossible("MONSTER with unknown variable param type!"); + break; + } + opvar_free(parm); + if (OV_i(varparam) != SP_M_V_END) { + opvar_free(varparam); + OV_pop(varparam); + } } - if (!OV_pop_c(mcoord)) panic("no monster coord?"); + if (!OV_pop_c(mcoord)) + panic("no monster coord?"); - if (!OV_pop_typ(id, SPOVAR_MONST)) panic("no mon type"); + if (!OV_pop_typ(id, SPOVAR_MONST)) + panic("no mon type"); tmpmons.id = SP_MONST_PM(OV_i(id)); tmpmons.class = SP_MONST_CLASS(OV_i(id)); @@ -2776,7 +2965,7 @@ spo_monster(coder) void spo_object(coder) - struct sp_coder *coder; +struct sp_coder *coder; { int nparams = 0; long quancnt; @@ -2789,7 +2978,7 @@ spo_object(coder) tmpobj.spe = -127; tmpobj.curse_state = -1; tmpobj.corpsenm = NON_PM; - tmpobj.name.str = (char *)0; + tmpobj.name.str = (char *) 0; tmpobj.quan = -1; tmpobj.buried = 0; tmpobj.lit = 0; @@ -2802,109 +2991,109 @@ spo_object(coder) tmpobj.broken = 0; tmpobj.coord = SP_COORD_PACK_RANDOM(0); - if (!OV_pop_i(containment)) return; + if (!OV_pop_i(containment)) + return; - if (!OV_pop_i(varparam)) return; + if (!OV_pop_i(varparam)) + return; - while ((nparams++ < (SP_O_V_END+1)) && - (OV_typ(varparam) == SPOVAR_INT) && - (OV_i(varparam) >= 0) && - (OV_i(varparam) < SP_O_V_END)) { - struct opvar *parm; - OV_pop(parm); - switch (OV_i(varparam)) { - case SP_O_V_NAME: - if ((OV_typ(parm) == SPOVAR_STRING) && - !tmpobj.name.str) - tmpobj.name.str = dupstr(OV_s(parm)); - break; - case SP_O_V_CORPSENM: - if (OV_typ(parm) == SPOVAR_MONST) { - char monclass = SP_MONST_CLASS(OV_i(parm)); - int monid = SP_MONST_PM(OV_i(parm)); - if (monid >= 0 && monid < NUMMONS) { - tmpobj.corpsenm = monid; - break; /* we're done! */ - } else { - struct permonst *pm = (struct permonst *)0; - if (def_char_to_monclass(monclass) != MAXMCLASSES) { - pm = mkclass(def_char_to_monclass(monclass), G_NOGEN); - } else { - pm = rndmonst(); - } - if (pm) - tmpobj.corpsenm = monsndx(pm); - } - } - break; - case SP_O_V_CURSE: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.curse_state = OV_i(parm); - break; - case SP_O_V_SPE: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.spe = OV_i(parm); - break; - case SP_O_V_QUAN: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.quan = OV_i(parm); - break; - case SP_O_V_BURIED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.buried = OV_i(parm); - break; - case SP_O_V_LIT: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.lit = OV_i(parm); - break; - case SP_O_V_ERODED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.eroded = OV_i(parm); - break; - case SP_O_V_LOCKED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.locked = OV_i(parm); - break; - case SP_O_V_TRAPPED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.trapped = OV_i(parm); - break; - case SP_O_V_RECHARGED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.recharged = OV_i(parm); - break; - case SP_O_V_INVIS: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.invis = OV_i(parm); - break; - case SP_O_V_GREASED: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.greased = OV_i(parm); - break; - case SP_O_V_BROKEN: - if (OV_typ(parm) == SPOVAR_INT) - tmpobj.broken = OV_i(parm); - break; - case SP_O_V_COORD: - if (OV_typ(parm) != SPOVAR_COORD) - panic("no coord for obj?"); - tmpobj.coord = OV_i(parm); - break; - case SP_O_V_END: - nparams = SP_O_V_END+1; - break; - default: - impossible("OBJECT with unknown variable param type!"); - break; - } - opvar_free(parm); - if (OV_i(varparam) != SP_O_V_END) { - opvar_free(varparam); - OV_pop(varparam); - } + while ((nparams++ < (SP_O_V_END + 1)) && (OV_typ(varparam) == SPOVAR_INT) + && (OV_i(varparam) >= 0) && (OV_i(varparam) < SP_O_V_END)) { + struct opvar *parm; + OV_pop(parm); + switch (OV_i(varparam)) { + case SP_O_V_NAME: + if ((OV_typ(parm) == SPOVAR_STRING) && !tmpobj.name.str) + tmpobj.name.str = dupstr(OV_s(parm)); + break; + case SP_O_V_CORPSENM: + if (OV_typ(parm) == SPOVAR_MONST) { + char monclass = SP_MONST_CLASS(OV_i(parm)); + int monid = SP_MONST_PM(OV_i(parm)); + if (monid >= 0 && monid < NUMMONS) { + tmpobj.corpsenm = monid; + break; /* we're done! */ + } else { + struct permonst *pm = (struct permonst *) 0; + if (def_char_to_monclass(monclass) != MAXMCLASSES) { + pm = mkclass(def_char_to_monclass(monclass), G_NOGEN); + } else { + pm = rndmonst(); + } + if (pm) + tmpobj.corpsenm = monsndx(pm); + } + } + break; + case SP_O_V_CURSE: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.curse_state = OV_i(parm); + break; + case SP_O_V_SPE: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.spe = OV_i(parm); + break; + case SP_O_V_QUAN: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.quan = OV_i(parm); + break; + case SP_O_V_BURIED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.buried = OV_i(parm); + break; + case SP_O_V_LIT: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.lit = OV_i(parm); + break; + case SP_O_V_ERODED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.eroded = OV_i(parm); + break; + case SP_O_V_LOCKED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.locked = OV_i(parm); + break; + case SP_O_V_TRAPPED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.trapped = OV_i(parm); + break; + case SP_O_V_RECHARGED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.recharged = OV_i(parm); + break; + case SP_O_V_INVIS: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.invis = OV_i(parm); + break; + case SP_O_V_GREASED: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.greased = OV_i(parm); + break; + case SP_O_V_BROKEN: + if (OV_typ(parm) == SPOVAR_INT) + tmpobj.broken = OV_i(parm); + break; + case SP_O_V_COORD: + if (OV_typ(parm) != SPOVAR_COORD) + panic("no coord for obj?"); + tmpobj.coord = OV_i(parm); + break; + case SP_O_V_END: + nparams = SP_O_V_END + 1; + break; + default: + impossible("OBJECT with unknown variable param type!"); + break; + } + opvar_free(parm); + if (OV_i(varparam) != SP_O_V_END) { + opvar_free(varparam); + OV_pop(varparam); + } } - if (!OV_pop_typ(id, SPOVAR_OBJ)) panic("no obj type"); + if (!OV_pop_typ(id, SPOVAR_OBJ)) + panic("no obj type"); tmpobj.id = SP_OBJ_TYP(OV_i(id)); tmpobj.class = SP_OBJ_CLASS(OV_i(id)); @@ -2913,11 +3102,10 @@ spo_object(coder) quancnt = (tmpobj.id > STRANGE_OBJECT) ? tmpobj.quan : 0; do { - create_object(&tmpobj, coder->croom); - quancnt--; - } while ((quancnt > 0) && - ((tmpobj.id > STRANGE_OBJECT) && - !objects[tmpobj.id].oc_merge)); + create_object(&tmpobj, coder->croom); + quancnt--; + } while ((quancnt > 0) && ((tmpobj.id > STRANGE_OBJECT) + && !objects[tmpobj.id].oc_merge)); Free(tmpobj.name.str); @@ -2928,45 +3116,55 @@ spo_object(coder) void spo_level_flags(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *flagdata; long lflags; - if (!OV_pop_i(flagdata)) return; + if (!OV_pop_i(flagdata)) + return; lflags = OV_i(flagdata); - if (lflags & NOTELEPORT) level.flags.noteleport = 1; - if (lflags & HARDFLOOR) level.flags.hardfloor = 1; - if (lflags & NOMMAP) level.flags.nommap = 1; - if (lflags & SHORTSIGHTED) level.flags.shortsighted = 1; - if (lflags & ARBOREAL) level.flags.arboreal = 1; - if (lflags & MAZELEVEL) level.flags.is_maze_lev = 1; - if (lflags & PREMAPPED) coder->premapped = TRUE; - if (lflags & SHROUD) level.flags.hero_memory = 0; - if (lflags & GRAVEYARD) level.flags.graveyard = 1; - if (lflags & ICEDPOOLS) icedpools = TRUE; - if (lflags & SOLIDIFY) coder->solidify = TRUE; - if (lflags & CORRMAZE) level.flags.corrmaze = TRUE; + if (lflags & NOTELEPORT) + level.flags.noteleport = 1; + if (lflags & HARDFLOOR) + level.flags.hardfloor = 1; + if (lflags & NOMMAP) + level.flags.nommap = 1; + if (lflags & SHORTSIGHTED) + level.flags.shortsighted = 1; + if (lflags & ARBOREAL) + level.flags.arboreal = 1; + if (lflags & MAZELEVEL) + level.flags.is_maze_lev = 1; + if (lflags & PREMAPPED) + coder->premapped = TRUE; + if (lflags & SHROUD) + level.flags.hero_memory = 0; + if (lflags & GRAVEYARD) + level.flags.graveyard = 1; + if (lflags & ICEDPOOLS) + icedpools = TRUE; + if (lflags & SOLIDIFY) + coder->solidify = TRUE; + if (lflags & CORRMAZE) + level.flags.corrmaze = TRUE; opvar_free(flagdata); } void spo_initlevel(coder) - struct sp_coder *coder; +struct sp_coder *coder; { lev_init init_lev; - struct opvar *init_style, *fg, *bg, *smoothed, *joined, *lit, *walled, *filling; + struct opvar *init_style, *fg, *bg, *smoothed, *joined, *lit, *walled, + *filling; - if (!OV_pop_i(fg) || - !OV_pop_i(bg) || - !OV_pop_i(smoothed) || - !OV_pop_i(joined) || - !OV_pop_i(lit) || - !OV_pop_i(walled) || - !OV_pop_i(filling) || - !OV_pop_i(init_style)) return; + if (!OV_pop_i(fg) || !OV_pop_i(bg) || !OV_pop_i(smoothed) + || !OV_pop_i(joined) || !OV_pop_i(lit) || !OV_pop_i(walled) + || !OV_pop_i(filling) || !OV_pop_i(init_style)) + return; splev_init_present = TRUE; @@ -2995,14 +3193,13 @@ spo_initlevel(coder) void spo_engraving(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *etyp, *txt, *ecoord; - xchar x,y; + xchar x, y; - if (!OV_pop_i(etyp) || - !OV_pop_s(txt) || - !OV_pop_c(ecoord)) return; + if (!OV_pop_i(etyp) || !OV_pop_s(txt) || !OV_pop_c(ecoord)) + return; get_location_coord(&x, &y, DRY, coder->croom, OV_i(ecoord)); make_engr_at(x, y, OV_s(txt), 0L, OV_i(etyp)); @@ -3014,16 +3211,16 @@ spo_engraving(coder) void spo_mineralize(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *kelp_pool, *kelp_moat, *gold_prob, *gem_prob; - if (!OV_pop_i(gem_prob) || - !OV_pop_i(gold_prob) || - !OV_pop_i(kelp_moat) || - !OV_pop_i(kelp_pool)) return; + if (!OV_pop_i(gem_prob) || !OV_pop_i(gold_prob) || !OV_pop_i(kelp_moat) + || !OV_pop_i(kelp_pool)) + return; - mineralize(OV_i(kelp_pool), OV_i(kelp_moat), OV_i(gold_prob), OV_i(gem_prob), TRUE); + mineralize(OV_i(kelp_pool), OV_i(kelp_moat), OV_i(gold_prob), + OV_i(gem_prob), TRUE); opvar_free(gem_prob); opvar_free(gold_prob); @@ -3033,105 +3230,100 @@ spo_mineralize(coder) void spo_room(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (coder->n_subroom > MAX_NESTED_ROOMS) { - panic("Too deeply nested rooms?!"); + panic("Too deeply nested rooms?!"); } else { - struct opvar *rflags, *h, *w, *yalign, *xalign, - *y, *x, *rlit, *chance, *rtype; + struct opvar *rflags, *h, *w, *yalign, *xalign, *y, *x, *rlit, + *chance, *rtype; - room tmproom; - struct mkroom *tmpcr; + room tmproom; + struct mkroom *tmpcr; - if (!OV_pop_i(h) || - !OV_pop_i(w) || - !OV_pop_i(y) || - !OV_pop_i(x) || - !OV_pop_i(yalign) || - !OV_pop_i(xalign) || - !OV_pop_i(rflags) || - !OV_pop_i(rlit) || - !OV_pop_i(chance) || - !OV_pop_i(rtype)) return; + if (!OV_pop_i(h) || !OV_pop_i(w) || !OV_pop_i(y) || !OV_pop_i(x) + || !OV_pop_i(yalign) || !OV_pop_i(xalign) || !OV_pop_i(rflags) + || !OV_pop_i(rlit) || !OV_pop_i(chance) || !OV_pop_i(rtype)) + return; + tmproom.x = OV_i(x); + tmproom.y = OV_i(y); + tmproom.w = OV_i(w); + tmproom.h = OV_i(h); + tmproom.xalign = OV_i(xalign); + tmproom.yalign = OV_i(yalign); + tmproom.rtype = OV_i(rtype); + tmproom.chance = OV_i(chance); + tmproom.rlit = OV_i(rlit); + tmproom.filled = (OV_i(rflags) & (1 << 0)); + /*tmproom.irregular = (OV_i(rflags) & (1 << 1));*/ + tmproom.joined = !(OV_i(rflags) & (1 << 2)); - tmproom.x = OV_i(x); - tmproom.y = OV_i(y); - tmproom.w = OV_i(w); - tmproom.h = OV_i(h); - tmproom.xalign = OV_i(xalign); - tmproom.yalign = OV_i(yalign); - tmproom.rtype = OV_i(rtype); - tmproom.chance = OV_i(chance); - tmproom.rlit = OV_i(rlit); - tmproom.filled = (OV_i(rflags) & (1 << 0)); - /*tmproom.irregular = (OV_i(rflags) & (1 << 1));*/ - tmproom.joined = !(OV_i(rflags) & (1 << 2)); + opvar_free(x); + opvar_free(y); + opvar_free(w); + opvar_free(h); + opvar_free(xalign); + opvar_free(yalign); + opvar_free(rtype); + opvar_free(chance); + opvar_free(rlit); + opvar_free(rflags); - opvar_free(x); - opvar_free(y); - opvar_free(w); - opvar_free(h); - opvar_free(xalign); - opvar_free(yalign); - opvar_free(rtype); - opvar_free(chance); - opvar_free(rlit); - opvar_free(rflags); - - if (!coder->failed_room[coder->n_subroom-1]) { - tmpcr = build_room(&tmproom, coder->croom); - if (tmpcr) { - coder->tmproomlist[coder->n_subroom] = tmpcr; - coder->failed_room[coder->n_subroom] = FALSE; - coder->n_subroom++; - return; - } - } /* failed to create parent room, so fail this too */ + if (!coder->failed_room[coder->n_subroom - 1]) { + tmpcr = build_room(&tmproom, coder->croom); + if (tmpcr) { + coder->tmproomlist[coder->n_subroom] = tmpcr; + coder->failed_room[coder->n_subroom] = FALSE; + coder->n_subroom++; + return; + } + } /* failed to create parent room, so fail this too */ } - coder->tmproomlist[coder->n_subroom] = (struct mkroom *)0; + coder->tmproomlist[coder->n_subroom] = (struct mkroom *) 0; coder->failed_room[coder->n_subroom] = TRUE; coder->n_subroom++; } void spo_endroom(coder) - struct sp_coder *coder; +struct sp_coder *coder; { if (coder->n_subroom > 1) { - coder->n_subroom--; - coder->tmproomlist[coder->n_subroom] = NULL; - coder->failed_room[coder->n_subroom] = TRUE; + coder->n_subroom--; + coder->tmproomlist[coder->n_subroom] = NULL; + coder->failed_room[coder->n_subroom] = TRUE; } else { - /* no subroom, get out of top-level room */ - /* Need to ensure xstart/ystart/xsize/ysize have something sensible, - in case there's some stuff to be created outside the outermost room, - and there's no MAP. - */ - if(xsize <= 1 && ysize <= 1) { - xstart = 1; - ystart = 0; - xsize = COLNO-1; - ysize = ROWNO; - } + /* no subroom, get out of top-level room */ + /* Need to ensure xstart/ystart/xsize/ysize have something sensible, + in case there's some stuff to be created outside the outermost + room, + and there's no MAP. + */ + if (xsize <= 1 && ysize <= 1) { + xstart = 1; + ystart = 0; + xsize = COLNO - 1; + ysize = ROWNO; + } } } void spo_stair(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - xchar x,y; + xchar x, y; struct opvar *up, *scoord; struct trap *badtrap; - if (!OV_pop_i(up) || - !OV_pop_c(scoord)) return; + if (!OV_pop_i(up) || !OV_pop_c(scoord)) + return; get_location_coord(&x, &y, DRY, coder->croom, OV_i(scoord)); - if ((badtrap = t_at(x,y)) != 0) deltrap(badtrap); - mkstairs(x, y, (char)OV_i(up), coder->croom); + if ((badtrap = t_at(x, y)) != 0) + deltrap(badtrap); + mkstairs(x, y, (char) OV_i(up), coder->croom); SpLev_Map[x][y] = 1; opvar_free(scoord); @@ -3140,24 +3332,26 @@ spo_stair(coder) void spo_ladder(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - xchar x,y; + xchar x, y; struct opvar *up, *lcoord; - if (!OV_pop_i(up) || - !OV_pop_c(lcoord)) return; + if (!OV_pop_i(up) || !OV_pop_c(lcoord)) + return; get_location_coord(&x, &y, DRY, coder->croom, OV_i(lcoord)); levl[x][y].typ = LADDER; SpLev_Map[x][y] = 1; if (OV_i(up)) { - xupladder = x; yupladder = y; - levl[x][y].ladder = LA_UP; + xupladder = x; + yupladder = y; + levl[x][y].ladder = LA_UP; } else { - xdnladder = x; ydnladder = y; - levl[x][y].ladder = LA_DOWN; + xdnladder = x; + ydnladder = y; + levl[x][y].ladder = LA_DOWN; } opvar_free(lcoord); opvar_free(up); @@ -3165,23 +3359,28 @@ spo_ladder(coder) void spo_grave(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *gcoord, *typ, *txt; - schar x,y; - if (!OV_pop_i(typ) || - !OV_pop_s(txt) || - !OV_pop_c(gcoord)) return; + schar x, y; + if (!OV_pop_i(typ) || !OV_pop_s(txt) || !OV_pop_c(gcoord)) + return; get_location_coord(&x, &y, DRY, coder->croom, OV_i(gcoord)); if (isok(x, y) && !t_at(x, y)) { - levl[x][y].typ = GRAVE; - switch (OV_i(typ)) { - case 2: make_grave(x, y, OV_s(txt)); break; - case 1: make_grave(x, y, NULL); break; - default: del_engr_at(x, y); break; - } + levl[x][y].typ = GRAVE; + switch (OV_i(typ)) { + case 2: + make_grave(x, y, OV_s(txt)); + break; + case 1: + make_grave(x, y, NULL); + break; + default: + del_engr_at(x, y); + break; + } } opvar_free(gcoord); @@ -3191,14 +3390,13 @@ spo_grave(coder) void spo_altar(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *al, *shrine, *acoord; altar tmpaltar; - if (!OV_pop_i(al) || - !OV_pop_i(shrine) || - !OV_pop_c(acoord)) return; + if (!OV_pop_i(al) || !OV_pop_i(shrine) || !OV_pop_c(acoord)) + return; tmpaltar.coord = OV_i(acoord); tmpaltar.align = OV_i(al); @@ -3213,14 +3411,14 @@ spo_altar(coder) void spo_trap(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *type; struct opvar *tcoord; trap tmptrap; - if (!OV_pop_i(type) || - !OV_pop_c(tcoord)) return; + if (!OV_pop_i(type) || !OV_pop_c(tcoord)) + return; tmptrap.coord = OV_i(tcoord); tmptrap.type = OV_i(type); @@ -3232,35 +3430,33 @@ spo_trap(coder) void spo_gold(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *gcoord, *amt; - schar x,y; + schar x, y; long amount; - if (!OV_pop_c(gcoord) || !OV_pop_i(amt)) return; + if (!OV_pop_c(gcoord) || !OV_pop_i(amt)) + return; amount = OV_i(amt); get_location_coord(&x, &y, DRY, coder->croom, OV_i(gcoord)); - if (amount == -1) amount = rnd(200); - mkgold(amount, x,y); + if (amount == -1) + amount = rnd(200); + mkgold(amount, x, y); opvar_free(gcoord); opvar_free(amt); } void spo_corridor(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - struct opvar *deswall, *desdoor, *desroom, - *srcwall, *srcdoor, *srcroom; + struct opvar *deswall, *desdoor, *desroom, *srcwall, *srcdoor, *srcroom; corridor tc; - if (!OV_pop_i(deswall) || - !OV_pop_i(desdoor) || - !OV_pop_i(desroom) || - !OV_pop_i(srcwall) || - !OV_pop_i(srcdoor) || - !OV_pop_i(srcroom)) return; + if (!OV_pop_i(deswall) || !OV_pop_i(desdoor) || !OV_pop_i(desroom) + || !OV_pop_i(srcwall) || !OV_pop_i(srcdoor) || !OV_pop_i(srcroom)) + return; tc.src.room = OV_i(srcroom); tc.src.door = OV_i(srcdoor); @@ -3279,159 +3475,175 @@ spo_corridor(coder) opvar_free(srcroom); } - struct opvar * selection_opvar(nbuf) - char *nbuf; +char *nbuf; { struct opvar *ov; - char buf[(COLNO*ROWNO)+1]; + char buf[(COLNO * ROWNO) + 1]; if (!nbuf) { - (void) memset(buf, 1, sizeof(buf)); - buf[(COLNO*ROWNO)] = '\0'; - ov = opvar_new_str(buf); + (void) memset(buf, 1, sizeof(buf)); + buf[(COLNO * ROWNO)] = '\0'; + ov = opvar_new_str(buf); } else { - ov = opvar_new_str(nbuf); + ov = opvar_new_str(nbuf); } ov->spovartyp = SPOVAR_SEL; return ov; } xchar -selection_getpoint(x,y,ov) - int x,y; - struct opvar *ov; +selection_getpoint(x, y, ov) +int x, y; +struct opvar *ov; { - if (!ov || ov->spovartyp != SPOVAR_SEL) return 0; - if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) return 0; + if (!ov || ov->spovartyp != SPOVAR_SEL) + return 0; + if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) + return 0; - return (ov->vardata.str[COLNO*y + x] - 1); + return (ov->vardata.str[COLNO * y + x] - 1); } void -selection_setpoint(x,y,ov, c) - int x,y; - struct opvar *ov; - xchar c; +selection_setpoint(x, y, ov, c) +int x, y; +struct opvar *ov; +xchar c; { - if (!ov || ov->spovartyp != SPOVAR_SEL) return; - if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) return; + if (!ov || ov->spovartyp != SPOVAR_SEL) + return; + if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO) + return; - ov->vardata.str[COLNO*y + x] = (char)(c + 1); + ov->vardata.str[COLNO * y + x] = (char) (c + 1); } struct opvar * selection_not(s) - struct opvar *s; +struct opvar *s; { struct opvar *ov; - int x,y; + int x, y; ov = selection_opvar(NULL); - if (!ov) return NULL; + if (!ov) + return NULL; for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (!selection_getpoint(x,y,s)) - selection_setpoint(x,y,ov,1); + for (y = 0; y < ROWNO; y++) + if (!selection_getpoint(x, y, s)) + selection_setpoint(x, y, ov, 1); return ov; } struct opvar * selection_logical_oper(s1, s2, oper) - struct opvar *s1, *s2; - char oper; +struct opvar *s1, *s2; +char oper; { struct opvar *ov; - int x,y; + int x, y; ov = selection_opvar(NULL); - if (!ov) return NULL; + if (!ov) + return NULL; for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) { - switch (oper) { - default: - case '|': - if (selection_getpoint(x,y,s1) || selection_getpoint(x,y,s2)) - selection_setpoint(x,y,ov,1); - break; - case '&': - if (selection_getpoint(x,y,s1) && selection_getpoint(x,y,s2)) - selection_setpoint(x,y,ov,1); - break; - } - } + for (y = 0; y < ROWNO; y++) { + switch (oper) { + default: + case '|': + if (selection_getpoint(x, y, s1) + || selection_getpoint(x, y, s2)) + selection_setpoint(x, y, ov, 1); + break; + case '&': + if (selection_getpoint(x, y, s1) + && selection_getpoint(x, y, s2)) + selection_setpoint(x, y, ov, 1); + break; + } + } return ov; } struct opvar * selection_filter_mapchar(ov, mc) - struct opvar *ov; - struct opvar *mc; +struct opvar *ov; +struct opvar *mc; { - int x,y; + int x, y; schar mapc; xchar lit; struct opvar *ret = selection_opvar(NULL); - if (!ov || !mc || !ret) return NULL; + if (!ov || !mc || !ret) + return NULL; mapc = SP_MAPCHAR_TYP(OV_i(mc)); lit = SP_MAPCHAR_LIT(OV_i(mc)); for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (selection_getpoint(x,y,ov) && (levl[x][y].typ == mapc)) { - switch (lit) { - default: - case -2: selection_setpoint(x,y,ret, 1); break; - case -1: selection_setpoint(x,y,ret, rn2(2)); break; - case 0: - case 1: if (levl[x][y].lit == lit) selection_setpoint(x,y,ret, 1); break; - } - } + for (y = 0; y < ROWNO; y++) + if (selection_getpoint(x, y, ov) && (levl[x][y].typ == mapc)) { + switch (lit) { + default: + case -2: + selection_setpoint(x, y, ret, 1); + break; + case -1: + selection_setpoint(x, y, ret, rn2(2)); + break; + case 0: + case 1: + if (levl[x][y].lit == lit) + selection_setpoint(x, y, ret, 1); + break; + } + } return ret; } - void selection_filter_percent(ov, percent) - struct opvar *ov; - int percent; +struct opvar *ov; +int percent; { - int x,y; - if (!ov) return; + int x, y; + if (!ov) + return; for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (selection_getpoint(x,y,ov) && (rn2(100) >= percent)) - selection_setpoint(x,y,ov,0); + for (y = 0; y < ROWNO; y++) + if (selection_getpoint(x, y, ov) && (rn2(100) >= percent)) + selection_setpoint(x, y, ov, 0); } int -selection_rndcoord(ov, x,y) - struct opvar *ov; - schar *x, *y; +selection_rndcoord(ov, x, y) +struct opvar *ov; +schar *x, *y; { int idx = 0; int c; - int dx,dy; + int dx, dy; for (dx = 0; dx < COLNO; dx++) - for (dy = 0; dy < ROWNO; dy++) - if (isok(dx,dy) && selection_getpoint(dx,dy,ov)) idx++; + for (dy = 0; dy < ROWNO; dy++) + if (isok(dx, dy) && selection_getpoint(dx, dy, ov)) + idx++; if (idx) { - c = rn2(idx); - for (dx = 0; dx < COLNO; dx++) - for (dy = 0; dy < ROWNO; dy++) - if (isok(dx,dy) && selection_getpoint(dx,dy, ov)) { - if (!c) { - *x = dx; - *y = dy; - return 1; - } - c--; - } + c = rn2(idx); + for (dx = 0; dx < COLNO; dx++) + for (dy = 0; dy < ROWNO; dy++) + if (isok(dx, dy) && selection_getpoint(dx, dy, ov)) { + if (!c) { + *x = dx; + *y = dy; + return 1; + } + c--; + } } *x = *y = -1; return 0; @@ -3439,61 +3651,97 @@ selection_rndcoord(ov, x,y) void selection_do_grow(ov, dir) - struct opvar *ov; - int dir; +struct opvar *ov; +int dir; { - int x,y, c; + int x, y, c; char tmp[COLNO][ROWNO]; - if (ov->spovartyp != SPOVAR_SEL) return; - if (!ov) return; + if (ov->spovartyp != SPOVAR_SEL) + return; + if (!ov) + return; (void) memset(tmp, 0, sizeof(tmp)); for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) { - c = 0; - if ((dir & W_WEST) && (x > 0) && (selection_getpoint(x-1,y, ov))) c++; - if ((dir & (W_WEST|W_NORTH)) && (x > 0) && (y > 0) && (selection_getpoint(x-1,y-1, ov))) c++; - if ((dir & W_NORTH) && (y > 0) && (selection_getpoint(x,y-1, ov))) c++; - if ((dir & (W_NORTH|W_EAST)) && (y > 0) && (x < COLNO-1) && (selection_getpoint(x+1,y-1, ov))) c++; - if ((dir & W_EAST) && (x < COLNO-1) && (selection_getpoint(x+1,y, ov))) c++; - if ((dir & (W_EAST|W_SOUTH)) && (x < COLNO-1) && (y < ROWNO-1) && (selection_getpoint(x+1,y+1, ov))) c++; - if ((dir & W_SOUTH) && (y < ROWNO-1) && (selection_getpoint(x,y+1, ov))) c++; - if ((dir & (W_SOUTH|W_WEST)) && (y < ROWNO-1) && (x > 0) && (selection_getpoint(x-1,y+1, ov))) c++; - if (c) tmp[x][y] = 1; - } + for (y = 0; y < ROWNO; y++) { + c = 0; + if ((dir & W_WEST) && (x > 0) + && (selection_getpoint(x - 1, y, ov))) + c++; + if ((dir & (W_WEST | W_NORTH)) && (x > 0) && (y > 0) + && (selection_getpoint(x - 1, y - 1, ov))) + c++; + if ((dir & W_NORTH) && (y > 0) + && (selection_getpoint(x, y - 1, ov))) + c++; + if ((dir & (W_NORTH | W_EAST)) && (y > 0) && (x < COLNO - 1) + && (selection_getpoint(x + 1, y - 1, ov))) + c++; + if ((dir & W_EAST) && (x < COLNO - 1) + && (selection_getpoint(x + 1, y, ov))) + c++; + if ((dir & (W_EAST | W_SOUTH)) && (x < COLNO - 1) + && (y < ROWNO - 1) && (selection_getpoint(x + 1, y + 1, ov))) + c++; + if ((dir & W_SOUTH) && (y < ROWNO - 1) + && (selection_getpoint(x, y + 1, ov))) + c++; + if ((dir & (W_SOUTH | W_WEST)) && (y < ROWNO - 1) && (x > 0) + && (selection_getpoint(x - 1, y + 1, ov))) + c++; + if (c) + tmp[x][y] = 1; + } for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (tmp[x][y]) selection_setpoint(x,y,ov,1); + for (y = 0; y < ROWNO; y++) + if (tmp[x][y]) + selection_setpoint(x, y, ov, 1); } void -selection_floodfill(ov, x,y) - struct opvar *ov; - int x,y; +selection_floodfill(ov, x, y) +struct opvar *ov; +int x, y; { struct opvar *tmp = selection_opvar(NULL); -#define SEL_FLOOD_STACK (COLNO*ROWNO) -#define SEL_FLOOD(nx,ny) {if (idx 0); #undef SEL_FLOOD #undef SEL_FLOOD_STACK @@ -3502,313 +3750,333 @@ selection_floodfill(ov, x,y) /* McIlroy's Ellipse Algorithm */ void -selection_do_ellipse(ov, xc,yc, a,b, filled) - struct opvar *ov; - int xc,yc,a,b,filled; -{ /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */ +selection_do_ellipse(ov, xc, yc, a, b, filled) +struct opvar *ov; +int xc, yc, a, b, filled; +{ /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */ int x = 0, y = b; - long a2 = (long)a*a, b2 = (long)b*b; - long crit1 = -(a2/4 + a%2 + b2); - long crit2 = -(b2/4 + b%2 + a2); - long crit3 = -(b2/4 + b%2); - long t = -a2*y; /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */ - long dxt = 2*b2*x, dyt = -2*a2*y; - long d2xt = 2*b2, d2yt = 2*a2; + long a2 = (long) a * a, b2 = (long) b * b; + long crit1 = -(a2 / 4 + a % 2 + b2); + long crit2 = -(b2 / 4 + b % 2 + a2); + long crit3 = -(b2 / 4 + b % 2); + long t = -a2 * y; /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */ + long dxt = 2 * b2 * x, dyt = -2 * a2 * y; + long d2xt = 2 * b2, d2yt = 2 * a2; long width = 1; long i; - if (!ov) return; + if (!ov) + return; filled = !filled; if (!filled) { - while (y>=0 && x<=a) { - selection_setpoint(xc+x, yc+y, ov, 1); - if (x!=0 || y!=0) - selection_setpoint(xc-x, yc-y, ov, 1); - if (x!=0 && y!=0) { - selection_setpoint(xc+x, yc-y, ov, 1); - selection_setpoint(xc-x, yc+y, ov, 1); - } - if (t + b2*x <= crit1 || /* e(x+1,y-1/2) <= 0 */ - t + a2*y <= crit3) { /* e(x+1/2,y) <= 0 */ - x++; dxt += d2xt; t += dxt; - } else if (t - a2*y > crit2) { /* e(x+1/2,y-1) > 0 */ - y--; dyt += d2yt; t += dyt; - } else { - x++; dxt += d2xt; t += dxt; - y--; dyt += d2yt; t += dyt; - } - } + while (y >= 0 && x <= a) { + selection_setpoint(xc + x, yc + y, ov, 1); + if (x != 0 || y != 0) + selection_setpoint(xc - x, yc - y, ov, 1); + if (x != 0 && y != 0) { + selection_setpoint(xc + x, yc - y, ov, 1); + selection_setpoint(xc - x, yc + y, ov, 1); + } + if (t + b2 * x <= crit1 || /* e(x+1,y-1/2) <= 0 */ + t + a2 * y <= crit3) { /* e(x+1/2,y) <= 0 */ + x++; + dxt += d2xt; + t += dxt; + } else if (t - a2 * y > crit2) { /* e(x+1/2,y-1) > 0 */ + y--; + dyt += d2yt; + t += dyt; + } else { + x++; + dxt += d2xt; + t += dxt; + y--; + dyt += d2yt; + t += dyt; + } + } } else { - while (y>=0 && x<=a) { - if (t + b2*x <= crit1 || /* e(x+1,y-1/2) <= 0 */ - t + a2*y <= crit3) { /* e(x+1/2,y) <= 0 */ - x++; dxt += d2xt; t += dxt; - width += 2; - } else if (t - a2*y > crit2) { /* e(x+1/2,y-1) > 0 */ - for (i = 0; i < width; i++) selection_setpoint(xc-x+i, yc-y, ov, 1); - if (y!=0) - for (i = 0; i < width; i++) selection_setpoint(xc-x+i, yc+y, ov, 1); - y--; dyt += d2yt; t += dyt; - } else { - for (i = 0; i < width; i++) selection_setpoint(xc-x+i, yc-y, ov, 1); - if (y!=0) - for (i = 0; i < width; i++) selection_setpoint(xc-x+i, yc+y, ov, 1); - x++; dxt += d2xt; t += dxt; - y--; dyt += d2yt; t += dyt; - width += 2; - } - } + while (y >= 0 && x <= a) { + if (t + b2 * x <= crit1 || /* e(x+1,y-1/2) <= 0 */ + t + a2 * y <= crit3) { /* e(x+1/2,y) <= 0 */ + x++; + dxt += d2xt; + t += dxt; + width += 2; + } else if (t - a2 * y > crit2) { /* e(x+1/2,y-1) > 0 */ + for (i = 0; i < width; i++) + selection_setpoint(xc - x + i, yc - y, ov, 1); + if (y != 0) + for (i = 0; i < width; i++) + selection_setpoint(xc - x + i, yc + y, ov, 1); + y--; + dyt += d2yt; + t += dyt; + } else { + for (i = 0; i < width; i++) + selection_setpoint(xc - x + i, yc - y, ov, 1); + if (y != 0) + for (i = 0; i < width; i++) + selection_setpoint(xc - x + i, yc + y, ov, 1); + x++; + dxt += d2xt; + t += dxt; + y--; + dyt += d2yt; + t += dyt; + width += 2; + } + } } } /* distance from line segment (x1,y1, x2,y2) to point (x3,y3) */ long -line_dist_coord(x1,y1, x2,y2, x3,y3) - long x1,y1,x2,y2,x3,y3; +line_dist_coord(x1, y1, x2, y2, x3, y3) +long x1, y1, x2, y2, x3, y3; { - long px = x2-x1; - long py = y2-y1; - long s = px*px + py*py; + long px = x2 - x1; + long py = y2 - y1; + long s = px * px + py * py; long x, y, dx, dy, dist = 0; float lu = 0; - if (x1 == x2 && y1 == y2) return isqrt(dist2(x1,y1, x3,y3)); + if (x1 == x2 && y1 == y2) + return isqrt(dist2(x1, y1, x3, y3)); - lu = ((x3 - x1) * px + (y3 - y1) * py) / (float)s; - if (lu > 1) lu = 1; - else if (lu < 0) lu = 0; + lu = ((x3 - x1) * px + (y3 - y1) * py) / (float) s; + if (lu > 1) + lu = 1; + else if (lu < 0) + lu = 0; x = x1 + lu * px; y = y1 + lu * py; dx = x - x3; dy = y - y3; - dist = isqrt(dx*dx + dy*dy); + dist = isqrt(dx * dx + dy * dy); return dist; } void -selection_do_gradient(ov, x,y, x2,y2, gtyp, mind, maxd, limit) - struct opvar *ov; - long x, y, x2,y2, gtyp, mind, maxd, limit; +selection_do_gradient(ov, x, y, x2, y2, gtyp, mind, maxd, limit) +struct opvar *ov; +long x, y, x2, y2, gtyp, mind, maxd, limit; { - long dx,dy, dofs; + long dx, dy, dofs; if (mind > maxd) { - long tmp = mind; - mind = maxd; - maxd = tmp; + long tmp = mind; + mind = maxd; + maxd = tmp; } dofs = maxd - mind; - if (dofs < 1) dofs = 1; + if (dofs < 1) + dofs = 1; switch (gtyp) { default: - case SEL_GRADIENT_RADIAL: - { - for (dx = 0; dx < COLNO; dx++) - for (dy = 0; dy < ROWNO; dy++) { - long d0 = line_dist_coord(x,y, x2,y2, dx,dy); - if (d0 >= mind && (!limit || d0 <= maxd)) { - if (d0 - mind > rn2(dofs)) - selection_setpoint(dx,dy, ov, 1); - } - } - } - break; - case SEL_GRADIENT_SQUARE: - { - for (dx = 0; dx < COLNO; dx++) - for (dy = 0; dy < ROWNO; dy++) { - long d1 = line_dist_coord(x,y, x2,y2, x,dy); - long d2 = line_dist_coord(x,y, x2,y2, dx,y); - long d3 = line_dist_coord(x,y, x2,y2, x2,dy); - long d4 = line_dist_coord(x,y, x2,y2, dx,y2); - long d5 = line_dist_coord(x,y, x2,y2, dx,dy); - long d0 = min(d5, min(max(d1, d2), max(d3, d4))); + case SEL_GRADIENT_RADIAL: { + for (dx = 0; dx < COLNO; dx++) + for (dy = 0; dy < ROWNO; dy++) { + long d0 = line_dist_coord(x, y, x2, y2, dx, dy); + if (d0 >= mind && (!limit || d0 <= maxd)) { + if (d0 - mind > rn2(dofs)) + selection_setpoint(dx, dy, ov, 1); + } + } + } break; + case SEL_GRADIENT_SQUARE: { + for (dx = 0; dx < COLNO; dx++) + for (dy = 0; dy < ROWNO; dy++) { + long d1 = line_dist_coord(x, y, x2, y2, x, dy); + long d2 = line_dist_coord(x, y, x2, y2, dx, y); + long d3 = line_dist_coord(x, y, x2, y2, x2, dy); + long d4 = line_dist_coord(x, y, x2, y2, dx, y2); + long d5 = line_dist_coord(x, y, x2, y2, dx, dy); + long d0 = min(d5, min(max(d1, d2), max(d3, d4))); - if (d0 >= mind && (!limit || d0 <= maxd)) { - if (d0 - mind > rn2(dofs)) - selection_setpoint(dx,dy, ov, 1); - } - } - } - break; + if (d0 >= mind && (!limit || d0 <= maxd)) { + if (d0 - mind > rn2(dofs)) + selection_setpoint(dx, dy, ov, 1); + } + } + } break; } } -void -selection_do_line(x1,y1,x2,y2, ov) /* bresenham line algo */ - schar x1,y1,x2,y2; - struct opvar *ov; +void selection_do_line(x1, y1, x2, y2, ov) /* bresenham line algo */ +schar x1, y1, x2, y2; +struct opvar *ov; { int d0, dx, dy, ai, bi, xi, yi; if (x1 < x2) { - xi = 1; - dx = x2 - x1; + xi = 1; + dx = x2 - x1; } else { - xi = - 1; - dx = x1 - x2; + xi = -1; + dx = x1 - x2; } if (y1 < y2) { - yi = 1; - dy = y2 - y1; + yi = 1; + dy = y2 - y1; } else { - yi = - 1; - dy = y1 - y2; + yi = -1; + dy = y1 - y2; } - selection_setpoint(x1,y1, ov, 1); + selection_setpoint(x1, y1, ov, 1); if (dx > dy) { - ai = (dy - dx) * 2; - bi = dy * 2; - d0 = bi - dx; - do { - if (d0 >= 0) { - y1 += yi; - d0 += ai; - } else d0 += bi; - x1 += xi; - selection_setpoint(x1,y1, ov, 1); - } while (x1 != x2); + ai = (dy - dx) * 2; + bi = dy * 2; + d0 = bi - dx; + do { + if (d0 >= 0) { + y1 += yi; + d0 += ai; + } else + d0 += bi; + x1 += xi; + selection_setpoint(x1, y1, ov, 1); + } while (x1 != x2); } else { - ai = (dx - dy) * 2; - bi = dx * 2; - d0 = bi - dy; - do { - if (d0 >= 0) { - x1 += xi; - d0 += ai; - } else d0 += bi; - y1 += yi; - selection_setpoint(x1,y1, ov, 1); - } while (y1 != y2); + ai = (dx - dy) * 2; + bi = dx * 2; + d0 = bi - dy; + do { + if (d0 >= 0) { + x1 += xi; + d0 += ai; + } else + d0 += bi; + y1 += yi; + selection_setpoint(x1, y1, ov, 1); + } while (y1 != y2); } } void -selection_do_randline(x1,y1,x2,y2,rough, rec, ov) - schar x1,y1,x2,y2,rough,rec; - struct opvar *ov; +selection_do_randline(x1, y1, x2, y2, rough, rec, ov) +schar x1, y1, x2, y2, rough, rec; +struct opvar *ov; { int mx, my; int dx, dy; if (rec < 1) { - return; + return; } if ((x2 == x1) && (y2 == y1)) { - selection_setpoint(x1,y1, ov, 1); - return; + selection_setpoint(x1, y1, ov, 1); + return; } - if (rough > max(abs(x2-x1), abs(y2-y1))) - rough = max(abs(x2-x1), abs(y2-y1)); + if (rough > max(abs(x2 - x1), abs(y2 - y1))) + rough = max(abs(x2 - x1), abs(y2 - y1)); if (rough < 2) { - mx = ((x1 + x2) / 2); - my = ((y1 + y2) / 2); + mx = ((x1 + x2) / 2); + my = ((y1 + y2) / 2); } else { - do { - dx = (rand() % rough) - (rough / 2); - dy = (rand() % rough) - (rough / 2); - mx = ((x1 + x2) / 2) + dx; - my = ((y1 + y2) / 2) + dy; - } while ((mx > COLNO-1 || mx < 0 || my < 0 || my > ROWNO-1)); + do { + dx = (rand() % rough) - (rough / 2); + dy = (rand() % rough) - (rough / 2); + mx = ((x1 + x2) / 2) + dx; + my = ((y1 + y2) / 2) + dy; + } while ((mx > COLNO - 1 || mx < 0 || my < 0 || my > ROWNO - 1)); } - selection_setpoint(mx,my, ov, 1); + selection_setpoint(mx, my, ov, 1); rough = (rough * 2) / 3; rec--; - selection_do_randline(x1,y1,mx,my, rough, rec, ov); - selection_do_randline(mx,my,x2,y2, rough, rec, ov); + selection_do_randline(x1, y1, mx, my, rough, rec, ov); + selection_do_randline(mx, my, x2, y2, rough, rec, ov); } - void selection_iterate(ov, func, arg) - struct opvar *ov; - select_iter_func func; - genericptr_t arg; +struct opvar *ov; +select_iter_func func; +genericptr_t arg; { - int x,y; + int x, y; /* yes, this is very naive, but it's not _that_ expensive. */ for (x = 0; x < COLNO; x++) - for (y = 0; y < ROWNO; y++) - if (selection_getpoint(x,y, ov)) (*func)(x,y, arg); + for (y = 0; y < ROWNO; y++) + if (selection_getpoint(x, y, ov)) + (*func)(x, y, arg); } void -sel_set_ter(x,y,arg) - int x,y; - genericptr_t arg; +sel_set_ter(x, y, arg) +int x, y; +genericptr_t arg; { terrain terr; - terr = (*(terrain *)arg); - SET_TYPLIT(x,y, terr.ter, terr.tlit); + terr = (*(terrain *) arg); + SET_TYPLIT(x, y, terr.ter, terr.tlit); /* handle doors and secret doors */ if (levl[x][y].typ == SDOOR || IS_DOOR(levl[x][y].typ)) { - if(levl[x][y].typ == SDOOR) - levl[x][y].doormask = D_CLOSED; - if (x && (IS_WALL(levl[x-1][y].typ) || - levl[x-1][y].horizontal)) - levl[x][y].horizontal = 1; + if (levl[x][y].typ == SDOOR) + levl[x][y].doormask = D_CLOSED; + if (x && (IS_WALL(levl[x - 1][y].typ) || levl[x - 1][y].horizontal)) + levl[x][y].horizontal = 1; } } void -sel_set_feature(x,y,arg) - int x,y; - genericptr_t arg; +sel_set_feature(x, y, arg) +int x, y; +genericptr_t arg; { - if (IS_FURNITURE(levl[x][y].typ)) return; - levl[x][y].typ = (*(int *)arg); + if (IS_FURNITURE(levl[x][y].typ)) + return; + levl[x][y].typ = (*(int *) arg); } void -sel_set_door(dx,dy,arg) - int dx,dy; - genericptr_t arg; +sel_set_door(dx, dy, arg) +int dx, dy; +genericptr_t arg; { - xchar typ = (*(xchar *)arg); + xchar typ = (*(xchar *) arg); xchar x = dx; xchar y = dy; if (!IS_DOOR(levl[x][y].typ) && levl[x][y].typ != SDOOR) - levl[x][y].typ = (typ & D_SECRET) ? SDOOR : DOOR; + levl[x][y].typ = (typ & D_SECRET) ? SDOOR : DOOR; if (typ & D_SECRET) { - typ &= ~D_SECRET; - if (typ < D_CLOSED) - typ = D_CLOSED; + typ &= ~D_SECRET; + if (typ < D_CLOSED) + typ = D_CLOSED; } levl[x][y].doormask = typ; SpLev_Map[x][y] = 1; } - - void spo_door(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *msk, *sel; xchar typ; - if (!OV_pop_i(msk) || - !OV_pop_typ(sel, SPOVAR_SEL)) return; + if (!OV_pop_i(msk) || !OV_pop_typ(sel, SPOVAR_SEL)) + return; - typ = OV_i(msk) == -1 ? rnddoor() : (xchar)OV_i(msk); + typ = OV_i(msk) == -1 ? rnddoor() : (xchar) OV_i(msk); - selection_iterate(sel, sel_set_door, (genericptr_t)&typ); + selection_iterate(sel, sel_set_door, (genericptr_t) &typ); opvar_free(sel); opvar_free(msk); @@ -3816,36 +4084,45 @@ spo_door(coder) void spo_feature(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *sel; int typ; - if (!OV_pop_typ(sel, SPOVAR_SEL)) return; + if (!OV_pop_typ(sel, SPOVAR_SEL)) + return; switch (coder->opcode) { - default: impossible("spo_feature called with wrong opcode %i.", coder->opcode); break; - case SPO_FOUNTAIN: typ = FOUNTAIN; break; - case SPO_SINK: typ = SINK; break; - case SPO_POOL: typ = POOL; break; + default: + impossible("spo_feature called with wrong opcode %i.", coder->opcode); + break; + case SPO_FOUNTAIN: + typ = FOUNTAIN; + break; + case SPO_SINK: + typ = SINK; + break; + case SPO_POOL: + typ = POOL; + break; } - selection_iterate(sel, sel_set_feature, (genericptr_t)&typ); + selection_iterate(sel, sel_set_feature, (genericptr_t) &typ); opvar_free(sel); } void spo_terrain(coder) - struct sp_coder *coder; +struct sp_coder *coder; { terrain tmpterrain; struct opvar *ter, *sel; - if (!OV_pop_typ(ter, SPOVAR_MAPCHAR) || - !OV_pop_typ(sel, SPOVAR_SEL)) return; + if (!OV_pop_typ(ter, SPOVAR_MAPCHAR) || !OV_pop_typ(sel, SPOVAR_SEL)) + return; tmpterrain.ter = SP_MAPCHAR_TYP(OV_i(ter)); tmpterrain.tlit = SP_MAPCHAR_LIT(OV_i(ter)); - selection_iterate(sel, sel_set_ter, (genericptr_t)&tmpterrain); + selection_iterate(sel, sel_set_ter, (genericptr_t) &tmpterrain); opvar_free(ter); opvar_free(sel); @@ -3853,15 +4130,14 @@ spo_terrain(coder) void spo_replace_terrain(coder) - struct sp_coder *coder; +struct sp_coder *coder; { replaceterrain rt; - struct opvar *reg,*from_ter,*to_ter,*chance; + struct opvar *reg, *from_ter, *to_ter, *chance; - if (!OV_pop_i(chance) || - !OV_pop_typ(to_ter, SPOVAR_MAPCHAR) || - !OV_pop_typ(from_ter, SPOVAR_MAPCHAR) || - !OV_pop_r(reg)) return; + if (!OV_pop_i(chance) || !OV_pop_typ(to_ter, SPOVAR_MAPCHAR) + || !OV_pop_typ(from_ter, SPOVAR_MAPCHAR) || !OV_pop_r(reg)) + return; rt.chance = OV_i(chance); rt.tolit = SP_MAPCHAR_LIT(OV_i(to_ter)); @@ -3883,29 +4159,21 @@ spo_replace_terrain(coder) void spo_levregion(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - struct opvar *rname, *padding, *rtype, - *del_islev, *dy2, *dx2, *dy1, *dx1, - *in_islev, *iy2, *ix2, *iy1, *ix1; + struct opvar *rname, *padding, *rtype, *del_islev, *dy2, *dx2, *dy1, *dx1, + *in_islev, *iy2, *ix2, *iy1, *ix1; lev_region *tmplregion; - if (!OV_pop_s(rname) || - !OV_pop_i(padding) || - !OV_pop_i(rtype) || - !OV_pop_i(del_islev) || - !OV_pop_i(dy2) || - !OV_pop_i(dx2) || - !OV_pop_i(dy1) || - !OV_pop_i(dx1) || - !OV_pop_i(in_islev) || - !OV_pop_i(iy2) || - !OV_pop_i(ix2) || - !OV_pop_i(iy1) || - !OV_pop_i(ix1)) return; + if (!OV_pop_s(rname) || !OV_pop_i(padding) || !OV_pop_i(rtype) + || !OV_pop_i(del_islev) || !OV_pop_i(dy2) || !OV_pop_i(dx2) + || !OV_pop_i(dy1) || !OV_pop_i(dx1) || !OV_pop_i(in_islev) + || !OV_pop_i(iy2) || !OV_pop_i(ix2) || !OV_pop_i(iy1) + || !OV_pop_i(ix1)) + return; - tmplregion = (lev_region *)alloc(sizeof(lev_region)); + tmplregion = (lev_region *) alloc(sizeof(lev_region)); tmplregion->inarea.x1 = OV_i(ix1); tmplregion->inarea.y1 = OV_i(iy1); @@ -3923,33 +4191,34 @@ spo_levregion(coder) tmplregion->padding = OV_i(padding); tmplregion->rname.str = dupstr(OV_s(rname)); - if(!tmplregion->in_islev) { - get_location(&tmplregion->inarea.x1, &tmplregion->inarea.y1, - ANY_LOC, (struct mkroom *)0); - get_location(&tmplregion->inarea.x2, &tmplregion->inarea.y2, - ANY_LOC, (struct mkroom *)0); + if (!tmplregion->in_islev) { + get_location(&tmplregion->inarea.x1, &tmplregion->inarea.y1, ANY_LOC, + (struct mkroom *) 0); + get_location(&tmplregion->inarea.x2, &tmplregion->inarea.y2, ANY_LOC, + (struct mkroom *) 0); } - if(!tmplregion->del_islev) { - get_location(&tmplregion->delarea.x1, &tmplregion->delarea.y1, - ANY_LOC, (struct mkroom *)0); - get_location(&tmplregion->delarea.x2, &tmplregion->delarea.y2, - ANY_LOC, (struct mkroom *)0); + if (!tmplregion->del_islev) { + get_location(&tmplregion->delarea.x1, &tmplregion->delarea.y1, + ANY_LOC, (struct mkroom *) 0); + get_location(&tmplregion->delarea.x2, &tmplregion->delarea.y2, + ANY_LOC, (struct mkroom *) 0); } - if(num_lregions) { - /* realloc the lregion space to add the new one */ - lev_region *newl = (lev_region *) alloc(sizeof(lev_region) * - (unsigned)(1+num_lregions)); - (void) memcpy((genericptr_t)(newl), (genericptr_t)lregions, - sizeof(lev_region) * num_lregions); - Free(lregions); - num_lregions++; - lregions = newl; + if (num_lregions) { + /* realloc the lregion space to add the new one */ + lev_region *newl = (lev_region *) alloc( + sizeof(lev_region) * (unsigned) (1 + num_lregions)); + (void) memcpy((genericptr_t)(newl), (genericptr_t) lregions, + sizeof(lev_region) * num_lregions); + Free(lregions); + num_lregions++; + lregions = newl; } else { - num_lregions = 1; - lregions = (lev_region *) alloc(sizeof(lev_region)); + num_lregions = 1; + lregions = (lev_region *) alloc(sizeof(lev_region)); } - (void) memcpy(&lregions[num_lregions-1], tmplregion, sizeof(lev_region)); + (void) memcpy(&lregions[num_lregions - 1], tmplregion, + sizeof(lev_region)); opvar_free(dx1); opvar_free(dy1); @@ -3970,100 +4239,95 @@ spo_levregion(coder) void spo_region(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *rtype, *rlit, *rflags, *area; - xchar dx1,dy1,dx2,dy2; + xchar dx1, dy1, dx2, dy2; register struct mkroom *troom; boolean prefilled, room_not_needed, irregular, joined; - if (!OV_pop_i(rflags) || - !OV_pop_i(rtype) || - !OV_pop_i(rlit) || - !OV_pop_r(area)) return; + if (!OV_pop_i(rflags) || !OV_pop_i(rtype) || !OV_pop_i(rlit) + || !OV_pop_r(area)) + return; prefilled = !(OV_i(rflags) & (1 << 0)); irregular = (OV_i(rflags) & (1 << 1)); joined = !(OV_i(rflags) & (1 << 2)); - if(OV_i(rtype) > MAXRTYPE) { - OV_i(rtype) -= MAXRTYPE+1; - prefilled = TRUE; + if (OV_i(rtype) > MAXRTYPE) { + OV_i(rtype) -= MAXRTYPE + 1; + prefilled = TRUE; } else - prefilled = FALSE; + prefilled = FALSE; - if(OV_i(rlit) < 0) - OV_i(rlit) = (rnd(1+abs(depth(&u.uz))) < 11 && rn2(77)) - ? TRUE : FALSE; + if (OV_i(rlit) < 0) + OV_i(rlit) = + (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? TRUE : FALSE; dx1 = SP_REGION_X1(OV_i(area)); dy1 = SP_REGION_Y1(OV_i(area)); dx2 = SP_REGION_X2(OV_i(area)); dy2 = SP_REGION_Y2(OV_i(area)); - get_location(&dx1, &dy1, ANY_LOC, (struct mkroom *)0); - get_location(&dx2, &dy2, ANY_LOC, (struct mkroom *)0); + get_location(&dx1, &dy1, ANY_LOC, (struct mkroom *) 0); + get_location(&dx2, &dy2, ANY_LOC, (struct mkroom *) 0); /* for an ordinary room, `prefilled' is a flag to force an actual room to be created (such rooms are used to control placement of migrating monster arrivals) */ - room_not_needed = (OV_i(rtype) == OROOM && - !irregular && !prefilled); + room_not_needed = (OV_i(rtype) == OROOM && !irregular && !prefilled); if (room_not_needed || nroom >= MAXNROFROOMS) { - region tmpregion; - if (!room_not_needed) - impossible("Too many rooms on new level!"); - tmpregion.rlit = OV_i(rlit); - tmpregion.x1 = dx1; - tmpregion.y1 = dy1; - tmpregion.x2 = dx2; - tmpregion.y2 = dy2; - light_region(&tmpregion); + region tmpregion; + if (!room_not_needed) + impossible("Too many rooms on new level!"); + tmpregion.rlit = OV_i(rlit); + tmpregion.x1 = dx1; + tmpregion.y1 = dy1; + tmpregion.x2 = dx2; + tmpregion.y2 = dy2; + light_region(&tmpregion); - opvar_free(area); - opvar_free(rflags); - opvar_free(rlit); - opvar_free(rtype); + opvar_free(area); + opvar_free(rflags); + opvar_free(rlit); + opvar_free(rtype); - return; + return; } troom = &rooms[nroom]; /* mark rooms that must be filled, but do it later */ if (OV_i(rtype) != OROOM) - troom->needfill = (prefilled ? 2 : 1); + troom->needfill = (prefilled ? 2 : 1); troom->needjoining = joined; if (irregular) { - min_rx = max_rx = dx1; - min_ry = max_ry = dy1; - smeq[nroom] = nroom; - flood_fill_rm(dx1, dy1, nroom+ROOMOFFSET, - OV_i(rlit), TRUE); - add_room(min_rx, min_ry, max_rx, max_ry, - FALSE, OV_i(rtype), TRUE); - troom->rlit = OV_i(rlit); - troom->irregular = TRUE; + min_rx = max_rx = dx1; + min_ry = max_ry = dy1; + smeq[nroom] = nroom; + flood_fill_rm(dx1, dy1, nroom + ROOMOFFSET, OV_i(rlit), TRUE); + add_room(min_rx, min_ry, max_rx, max_ry, FALSE, OV_i(rtype), TRUE); + troom->rlit = OV_i(rlit); + troom->irregular = TRUE; } else { - add_room(dx1, dy1, dx2, dy2, - OV_i(rlit), OV_i(rtype), TRUE); + add_room(dx1, dy1, dx2, dy2, OV_i(rlit), OV_i(rtype), TRUE); #ifdef SPECIALIZATION - topologize(troom,FALSE); /* set roomno */ + topologize(troom, FALSE); /* set roomno */ #else - topologize(troom); /* set roomno */ + topologize(troom); /* set roomno */ #endif } if (!room_not_needed) { - if (coder->n_subroom > 1) - impossible("region as subroom"); - else { - coder->tmproomlist[coder->n_subroom] = troom; - coder->failed_room[coder->n_subroom] = FALSE; - coder->n_subroom++; - } + if (coder->n_subroom > 1) + impossible("region as subroom"); + else { + coder->tmproomlist[coder->n_subroom] = troom; + coder->failed_room[coder->n_subroom] = FALSE; + coder->n_subroom++; + } } opvar_free(area); @@ -4074,18 +4338,17 @@ spo_region(coder) void spo_drawbridge(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - xchar x,y; + xchar x, y; struct opvar *dir, *db_open, *dcoord; - if (!OV_pop_i(dir) || - !OV_pop_i(db_open) || - !OV_pop_c(dcoord)) return; + if (!OV_pop_i(dir) || !OV_pop_i(db_open) || !OV_pop_c(dcoord)) + return; - get_location_coord(&x, &y, DRY|WET|HOT, coder->croom, OV_i(dcoord)); + get_location_coord(&x, &y, DRY | WET | HOT, coder->croom, OV_i(dcoord)); if (!create_drawbridge(x, y, OV_i(dir), OV_i(db_open))) - impossible("Cannot create drawbridge."); + impossible("Cannot create drawbridge."); SpLev_Map[x][y] = 1; opvar_free(dcoord); @@ -4095,39 +4358,47 @@ spo_drawbridge(coder) void spo_mazewalk(coder) - struct sp_coder *coder; +struct sp_coder *coder; { - xchar x,y; - struct opvar *ftyp, *fstocked,*fdir, *mcoord; + xchar x, y; + struct opvar *ftyp, *fstocked, *fdir, *mcoord; int dir; - if (!OV_pop_i(ftyp) || - !OV_pop_i(fstocked) || - !OV_pop_i(fdir) || - !OV_pop_c(mcoord)) return; + if (!OV_pop_i(ftyp) || !OV_pop_i(fstocked) || !OV_pop_i(fdir) + || !OV_pop_c(mcoord)) + return; dir = OV_i(fdir); get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(mcoord)); - if (!isok(x,y)) return; + if (!isok(x, y)) + return; if (OV_i(ftyp) < 1) { - OV_i(ftyp) = level.flags.corrmaze ? CORR : ROOM; + OV_i(ftyp) = level.flags.corrmaze ? CORR : ROOM; } /* don't use move() - it doesn't use W_NORTH, etc. */ switch (dir) { - case W_NORTH: --y; break; - case W_SOUTH: y++; break; - case W_EAST: x++; break; - case W_WEST: --x; break; + case W_NORTH: + --y; + break; + case W_SOUTH: + y++; + break; + case W_EAST: + x++; + break; + case W_WEST: + --x; + break; default: - impossible("sp_level_coder: Bad MAZEWALK direction"); + impossible("sp_level_coder: Bad MAZEWALK direction"); } - if(!IS_DOOR(levl[x][y].typ)) { - levl[x][y].typ = OV_i(ftyp); - levl[x][y].flags = 0; + if (!IS_DOOR(levl[x][y].typ)) { + levl[x][y].typ = OV_i(ftyp); + levl[x][y].flags = 0; } /* @@ -4135,26 +4406,27 @@ spo_mazewalk(coder) * walkfrom() is odd. But we must also take into account * what direction was chosen. */ - if(!(x % 2)) { - if (dir == W_EAST) - x++; - else - x--; + if (!(x % 2)) { + if (dir == W_EAST) + x++; + else + x--; - /* no need for IS_DOOR check; out of map bounds */ - levl[x][y].typ = OV_i(ftyp); - levl[x][y].flags = 0; + /* no need for IS_DOOR check; out of map bounds */ + levl[x][y].typ = OV_i(ftyp); + levl[x][y].flags = 0; } if (!(y % 2)) { - if (dir == W_SOUTH) - y++; - else - y--; + if (dir == W_SOUTH) + y++; + else + y--; } walkfrom(x, y, OV_i(ftyp)); - if (OV_i(fstocked)) fill_empty_maze(); + if (OV_i(fstocked)) + fill_empty_maze(); opvar_free(mcoord); opvar_free(fdir); @@ -4164,21 +4436,23 @@ spo_mazewalk(coder) void spo_wall_property(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *r; - xchar dx1,dy1,dx2,dy2; - int wprop = (coder->opcode == SPO_NON_DIGGABLE) ? W_NONDIGGABLE : W_NONPASSWALL; + xchar dx1, dy1, dx2, dy2; + int wprop = + (coder->opcode == SPO_NON_DIGGABLE) ? W_NONDIGGABLE : W_NONPASSWALL; - if (!OV_pop_r(r)) return; + if (!OV_pop_r(r)) + return; dx1 = SP_REGION_X1(OV_i(r)); dy1 = SP_REGION_Y1(OV_i(r)); dx2 = SP_REGION_X2(OV_i(r)); dy2 = SP_REGION_Y2(OV_i(r)); - get_location(&dx1, &dy1, ANY_LOC, (struct mkroom *)0); - get_location(&dx2, &dy2, ANY_LOC, (struct mkroom *)0); + get_location(&dx1, &dy1, ANY_LOC, (struct mkroom *) 0); + get_location(&dx2, &dy2, ANY_LOC, (struct mkroom *) 0); set_wall_property(dx1, dy1, dx2, dy2, wprop); @@ -4187,16 +4461,14 @@ spo_wall_property(coder) void spo_room_door(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *wall, *secret, *mask, *pos; room_door tmpd; - if (!OV_pop_i(wall) || - !OV_pop_i(secret) || - !OV_pop_i(mask) || - !OV_pop_i(pos) || - !coder->croom) return; + if (!OV_pop_i(wall) || !OV_pop_i(secret) || !OV_pop_i(mask) + || !OV_pop_i(pos) || !coder->croom) + return; tmpd.secret = OV_i(secret); tmpd.mask = OV_i(mask); @@ -4213,48 +4485,46 @@ spo_room_door(coder) /*ARGSUSED*/ void -sel_set_wallify(x,y,arg) - int x, y; - genericptr_t arg; +sel_set_wallify(x, y, arg) +int x, y; +genericptr_t arg; { - wallify_map(x,y, x,y); + wallify_map(x, y, x, y); } void spo_wallify(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *typ, *r; - int dx1,dy1,dx2,dy2; - if (!OV_pop_i(typ)) return; + int dx1, dy1, dx2, dy2; + if (!OV_pop_i(typ)) + return; switch (OV_i(typ)) { default: - case 0: - { - if (!OV_pop_r(r)) return; - dx1 = (xchar)SP_REGION_X1(OV_i(r)); - dy1 = (xchar)SP_REGION_Y1(OV_i(r)); - dx2 = (xchar)SP_REGION_X2(OV_i(r)); - dy2 = (xchar)SP_REGION_Y2(OV_i(r)); - wallify_map(dx1 < 0 ? xstart : dx1, - dy1 < 0 ? ystart : dy1, - dx2 < 0 ? xstart+xsize : dx2, - dy2 < 0 ? ystart+ysize : dy2); - } - break; - case 1: - { - if (!OV_pop_typ(r, SPOVAR_SEL)) return; - selection_iterate(r, sel_set_wallify, NULL); - } - break; + case 0: { + if (!OV_pop_r(r)) + return; + dx1 = (xchar) SP_REGION_X1(OV_i(r)); + dy1 = (xchar) SP_REGION_Y1(OV_i(r)); + dx2 = (xchar) SP_REGION_X2(OV_i(r)); + dy2 = (xchar) SP_REGION_Y2(OV_i(r)); + wallify_map(dx1 < 0 ? xstart : dx1, dy1 < 0 ? ystart : dy1, + dx2 < 0 ? xstart + xsize : dx2, + dy2 < 0 ? ystart + ysize : dy2); + } break; + case 1: { + if (!OV_pop_typ(r, SPOVAR_SEL)) + return; + selection_iterate(r, sel_set_wallify, NULL); + } break; } opvar_free(r); } void spo_map(coder) - struct sp_coder *coder; +struct sp_coder *coder; { mazepart tmpmazepart; struct opvar *mpxs, *mpys, *mpmap, *mpa, *mpkeepr, *mpzalign; @@ -4262,12 +4532,9 @@ spo_map(coder) xchar tmpxstart, tmpystart, tmpxsize, tmpysize; unpacked_coord upc; - if (!OV_pop_i(mpxs) || - !OV_pop_i(mpys) || - !OV_pop_s(mpmap) || - !OV_pop_i(mpkeepr) || - !OV_pop_i(mpzalign) || - !OV_pop_c(mpa)) return; + if (!OV_pop_i(mpxs) || !OV_pop_i(mpys) || !OV_pop_s(mpmap) + || !OV_pop_i(mpkeepr) || !OV_pop_i(mpzalign) || !OV_pop_c(mpa)) + return; tmpmazepart.xsize = OV_i(mpxs); tmpmazepart.ysize = OV_i(mpys); @@ -4277,8 +4544,10 @@ spo_map(coder) tmpmazepart.halign = upc.x; tmpmazepart.valign = upc.y; - tmpxsize = xsize; tmpysize = ysize; - tmpxstart = xstart; tmpystart = ystart; + tmpxsize = xsize; + tmpysize = ysize; + tmpxstart = xstart; + tmpystart = ystart; halign = tmpmazepart.halign; valign = tmpmazepart.valign; @@ -4287,93 +4556,118 @@ spo_map(coder) switch (tmpmazepart.zaligntyp) { default: case 0: - break; + break; case 1: - switch((int) halign) { - case LEFT: xstart = splev_init_present ? 1 : 3; break; - case H_LEFT: xstart = 2+((x_maze_max-2-xsize)/4); break; - case CENTER: xstart = 2+((x_maze_max-2-xsize)/2); break; - case H_RIGHT: xstart = 2+((x_maze_max-2-xsize)*3/4); break; - case RIGHT: xstart = x_maze_max-xsize-1; break; - } - switch((int) valign) { - case TOP: ystart = 3; break; - case CENTER: ystart = 2+((y_maze_max-2-ysize)/2); break; - case BOTTOM: ystart = y_maze_max-ysize-1; break; - } - if (!(xstart % 2)) xstart++; - if (!(ystart % 2)) ystart++; - break; + switch ((int) halign) { + case LEFT: + xstart = splev_init_present ? 1 : 3; + break; + case H_LEFT: + xstart = 2 + ((x_maze_max - 2 - xsize) / 4); + break; + case CENTER: + xstart = 2 + ((x_maze_max - 2 - xsize) / 2); + break; + case H_RIGHT: + xstart = 2 + ((x_maze_max - 2 - xsize) * 3 / 4); + break; + case RIGHT: + xstart = x_maze_max - xsize - 1; + break; + } + switch ((int) valign) { + case TOP: + ystart = 3; + break; + case CENTER: + ystart = 2 + ((y_maze_max - 2 - ysize) / 2); + break; + case BOTTOM: + ystart = y_maze_max - ysize - 1; + break; + } + if (!(xstart % 2)) + xstart++; + if (!(ystart % 2)) + ystart++; + break; case 2: - if (!coder->croom) { - xstart = 1; - ystart = 0; - xsize = COLNO-1-tmpmazepart.xsize; - ysize = ROWNO-tmpmazepart.ysize; - } - get_location_coord(&halign, &valign, ANY_LOC, coder->croom, OV_i(mpa)); - xsize = tmpmazepart.xsize; - ysize = tmpmazepart.ysize; - xstart = halign; - ystart = valign; - break; + if (!coder->croom) { + xstart = 1; + ystart = 0; + xsize = COLNO - 1 - tmpmazepart.xsize; + ysize = ROWNO - tmpmazepart.ysize; + } + get_location_coord(&halign, &valign, ANY_LOC, coder->croom, + OV_i(mpa)); + xsize = tmpmazepart.xsize; + ysize = tmpmazepart.ysize; + xstart = halign; + ystart = valign; + break; } if ((ystart < 0) || (ystart + ysize > ROWNO)) { - /* try to move the start a bit */ - ystart += (ystart > 0) ? -2 : 2; - if(ysize == ROWNO) ystart = 0; - if(ystart < 0 || ystart + ysize > ROWNO) - panic("reading special level with ysize too large"); + /* try to move the start a bit */ + ystart += (ystart > 0) ? -2 : 2; + if (ysize == ROWNO) + ystart = 0; + if (ystart < 0 || ystart + ysize > ROWNO) + panic("reading special level with ysize too large"); } if (xsize <= 1 && ysize <= 1) { - xstart = 1; - ystart = 0; - xsize = COLNO-1; - ysize = ROWNO; + xstart = 1; + ystart = 0; + xsize = COLNO - 1; + ysize = ROWNO; } else { - xchar x,y; - /* Load the map */ - for(y = ystart; y < ystart+ysize; y++) - for(x = xstart; x < xstart+xsize; x++) { - xchar mptyp = (mpmap->vardata.str[(y-ystart) * xsize + (x-xstart)] - 1); - if (mptyp >= MAX_TYPE) continue; - levl[x][y].typ = mptyp; - levl[x][y].lit = FALSE; - /* clear out levl: load_common_data may set them */ - levl[x][y].flags = 0; - levl[x][y].horizontal = 0; - levl[x][y].roomno = 0; - levl[x][y].edge = 0; - SpLev_Map[x][y] = 1; - /* - * Set secret doors to closed (why not trapped too?). Set - * the horizontal bit. - */ - if (levl[x][y].typ == SDOOR || IS_DOOR(levl[x][y].typ)) { - if(levl[x][y].typ == SDOOR) - levl[x][y].doormask = D_CLOSED; - /* - * If there is a wall to the left that connects to a - * (secret) door, then it is horizontal. This does - * not allow (secret) doors to be corners of rooms. - */ - if (x != xstart && (IS_WALL(levl[x-1][y].typ) || - levl[x-1][y].horizontal)) - levl[x][y].horizontal = 1; - } else if(levl[x][y].typ == HWALL || - levl[x][y].typ == IRONBARS) - levl[x][y].horizontal = 1; - else if(levl[x][y].typ == LAVAPOOL) - levl[x][y].lit = 1; - else if (splev_init_present && levl[x][y].typ == ICE) - levl[x][y].icedpool = icedpools ? ICED_POOL : ICED_MOAT; - } - if (coder->lvl_is_joined) - remove_rooms(xstart, ystart, xstart+xsize, ystart+ysize); + xchar x, y; + /* Load the map */ + for (y = ystart; y < ystart + ysize; y++) + for (x = xstart; x < xstart + xsize; x++) { + xchar mptyp = + (mpmap->vardata.str[(y - ystart) * xsize + (x - xstart)] + - 1); + if (mptyp >= MAX_TYPE) + continue; + levl[x][y].typ = mptyp; + levl[x][y].lit = FALSE; + /* clear out levl: load_common_data may set them */ + levl[x][y].flags = 0; + levl[x][y].horizontal = 0; + levl[x][y].roomno = 0; + levl[x][y].edge = 0; + SpLev_Map[x][y] = 1; + /* + * Set secret doors to closed (why not trapped too?). Set + * the horizontal bit. + */ + if (levl[x][y].typ == SDOOR || IS_DOOR(levl[x][y].typ)) { + if (levl[x][y].typ == SDOOR) + levl[x][y].doormask = D_CLOSED; + /* + * If there is a wall to the left that connects to a + * (secret) door, then it is horizontal. This does + * not allow (secret) doors to be corners of rooms. + */ + if (x != xstart && (IS_WALL(levl[x - 1][y].typ) + || levl[x - 1][y].horizontal)) + levl[x][y].horizontal = 1; + } else if (levl[x][y].typ == HWALL + || levl[x][y].typ == IRONBARS) + levl[x][y].horizontal = 1; + else if (levl[x][y].typ == LAVAPOOL) + levl[x][y].lit = 1; + else if (splev_init_present && levl[x][y].typ == ICE) + levl[x][y].icedpool = icedpools ? ICED_POOL : ICED_MOAT; + } + if (coder->lvl_is_joined) + remove_rooms(xstart, ystart, xstart + xsize, ystart + ysize); } if (!OV_i(mpkeepr)) { - xstart = tmpxstart; ystart = tmpystart; - xsize = tmpxsize; ysize = tmpysize; + xstart = tmpxstart; + ystart = tmpystart; + xsize = tmpxsize; + ysize = tmpysize; } opvar_free(mpxs); @@ -4386,55 +4680,68 @@ spo_map(coder) void spo_jmp(coder, lvl) - struct sp_coder *coder; - sp_lev *lvl; +struct sp_coder *coder; +sp_lev *lvl; { struct opvar *tmpa; long a; - if (!OV_pop_i(tmpa)) return; + if (!OV_pop_i(tmpa)) + return; a = sp_code_jmpaddr(coder->frame->n_opcode, (OV_i(tmpa) - 1)); - if ((a >= 0) && (a < lvl->n_opcodes) && - (a != coder->frame->n_opcode)) - coder->frame->n_opcode = a; + if ((a >= 0) && (a < lvl->n_opcodes) && (a != coder->frame->n_opcode)) + coder->frame->n_opcode = a; opvar_free(tmpa); } void -spo_conditional_jump(coder,lvl) - struct sp_coder *coder; - sp_lev *lvl; +spo_conditional_jump(coder, lvl) +struct sp_coder *coder; +sp_lev *lvl; { struct opvar *oa, *oc; - long a,c; + long a, c; int test = 0; - if (!OV_pop_i(oa) || !OV_pop_i(oc)) return; + if (!OV_pop_i(oa) || !OV_pop_i(oc)) + return; a = sp_code_jmpaddr(coder->frame->n_opcode, (OV_i(oa) - 1)); c = OV_i(oc); switch (coder->opcode) { - default: impossible("spo_conditional_jump: illegal opcode"); break; - case SPO_JL: test = (c & SP_CPUFLAG_LT); break; - case SPO_JLE: test = (c & (SP_CPUFLAG_LT|SP_CPUFLAG_EQ)); break; - case SPO_JG: test = (c & SP_CPUFLAG_GT); break; - case SPO_JGE: test = (c & (SP_CPUFLAG_GT|SP_CPUFLAG_EQ)); break; - case SPO_JE: test = (c & SP_CPUFLAG_EQ); break; - case SPO_JNE: test = (c & ~SP_CPUFLAG_EQ); break; + default: + impossible("spo_conditional_jump: illegal opcode"); + break; + case SPO_JL: + test = (c & SP_CPUFLAG_LT); + break; + case SPO_JLE: + test = (c & (SP_CPUFLAG_LT | SP_CPUFLAG_EQ)); + break; + case SPO_JG: + test = (c & SP_CPUFLAG_GT); + break; + case SPO_JGE: + test = (c & (SP_CPUFLAG_GT | SP_CPUFLAG_EQ)); + break; + case SPO_JE: + test = (c & SP_CPUFLAG_EQ); + break; + case SPO_JNE: + test = (c & ~SP_CPUFLAG_EQ); + break; } - if ((test) && (a >= 0) && - (a < lvl->n_opcodes) && - (a != coder->frame->n_opcode)) - coder->frame->n_opcode = a; + if ((test) && (a >= 0) && (a < lvl->n_opcodes) + && (a != coder->frame->n_opcode)) + coder->frame->n_opcode = a; opvar_free(oa); opvar_free(oc); } - void spo_var_init(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *vname; struct opvar *arraylen; @@ -4447,118 +4754,128 @@ spo_var_init(coder) OV_pop_i(arraylen); if (!vname || !arraylen) - panic("no values for SPO_VAR_INIT"); + panic("no values for SPO_VAR_INIT"); tmpvar = opvar_var_defined(coder, OV_s(vname)); if (tmpvar) { - /* variable redefinition */ - if (OV_i(arraylen) < 0) { - /* copy variable */ - if (tmpvar->array_len) { - idx = tmpvar->array_len; - while (idx-- > 0) { - opvar_free(tmpvar->data.arrayvalues[idx]); - } - Free(tmpvar->data.arrayvalues); - } else { - opvar_free(tmpvar->data.value); - } - tmpvar->data.arrayvalues = NULL; - goto copy_variable; - } else if (OV_i(arraylen)) { - /* redefined array */ - idx = tmpvar->array_len; - while (idx-- > 0) { - opvar_free(tmpvar->data.arrayvalues[idx]); - } - Free(tmpvar->data.arrayvalues); - tmpvar->data.arrayvalues = NULL; - goto create_new_array; - } else { - /* redefined single value */ - OV_pop(vvalue); - if (tmpvar->svtyp != vvalue->spovartyp) panic("redefining variable as different type"); - opvar_free(tmpvar->data.value); - tmpvar->data.value = vvalue; - tmpvar->array_len = 0; - } + /* variable redefinition */ + if (OV_i(arraylen) < 0) { + /* copy variable */ + if (tmpvar->array_len) { + idx = tmpvar->array_len; + while (idx-- > 0) { + opvar_free(tmpvar->data.arrayvalues[idx]); + } + Free(tmpvar->data.arrayvalues); + } else { + opvar_free(tmpvar->data.value); + } + tmpvar->data.arrayvalues = NULL; + goto copy_variable; + } else if (OV_i(arraylen)) { + /* redefined array */ + idx = tmpvar->array_len; + while (idx-- > 0) { + opvar_free(tmpvar->data.arrayvalues[idx]); + } + Free(tmpvar->data.arrayvalues); + tmpvar->data.arrayvalues = NULL; + goto create_new_array; + } else { + /* redefined single value */ + OV_pop(vvalue); + if (tmpvar->svtyp != vvalue->spovartyp) + panic("redefining variable as different type"); + opvar_free(tmpvar->data.value); + tmpvar->data.value = vvalue; + tmpvar->array_len = 0; + } } else { - /* new variable definition */ - tmpvar = (struct splev_var *)alloc(sizeof(struct splev_var)); - tmpvar->next = coder->frame->variables; - tmpvar->name = dupstr(OV_s(vname)); - coder->frame->variables = tmpvar; + /* new variable definition */ + tmpvar = (struct splev_var *) alloc(sizeof(struct splev_var)); + tmpvar->next = coder->frame->variables; + tmpvar->name = dupstr(OV_s(vname)); + coder->frame->variables = tmpvar; - if (OV_i(arraylen) < 0) { - /* copy variable */ -copy_variable: - OV_pop(vvalue); - tmp2 = opvar_var_defined(coder, OV_s(vvalue)); - if (!tmp2) panic("no copyable var"); - tmpvar->svtyp = tmp2->svtyp; - tmpvar->array_len = tmp2->array_len; - if (tmpvar->array_len) { - idx = tmpvar->array_len; - tmpvar->data.arrayvalues = (struct opvar **)alloc(sizeof(struct opvar *) * idx); - while (idx-- > 0) { - tmpvar->data.arrayvalues[idx] = opvar_clone(tmp2->data.arrayvalues[idx]); - } - } else { - tmpvar->data.value = opvar_clone(tmp2->data.value); - } - opvar_free(vvalue); - } else if (OV_i(arraylen)) { - /* new array */ -create_new_array: - idx = OV_i(arraylen); - tmpvar->array_len = idx; - tmpvar->data.arrayvalues = (struct opvar **)alloc(sizeof(struct opvar *) * idx); - while (idx-- > 0) { - OV_pop(vvalue); - if (!vvalue) panic("no value for arrayvariable"); - tmpvar->data.arrayvalues[idx] = vvalue; - } - tmpvar->svtyp = SPOVAR_ARRAY; - } else { - /* new single value */ - OV_pop(vvalue); - if (!vvalue) panic("no value for variable"); - tmpvar->svtyp = OV_typ(vvalue); - tmpvar->data.value = vvalue; - tmpvar->array_len = 0; - } + if (OV_i(arraylen) < 0) { + /* copy variable */ + copy_variable: + OV_pop(vvalue); + tmp2 = opvar_var_defined(coder, OV_s(vvalue)); + if (!tmp2) + panic("no copyable var"); + tmpvar->svtyp = tmp2->svtyp; + tmpvar->array_len = tmp2->array_len; + if (tmpvar->array_len) { + idx = tmpvar->array_len; + tmpvar->data.arrayvalues = + (struct opvar **) alloc(sizeof(struct opvar *) * idx); + while (idx-- > 0) { + tmpvar->data.arrayvalues[idx] = + opvar_clone(tmp2->data.arrayvalues[idx]); + } + } else { + tmpvar->data.value = opvar_clone(tmp2->data.value); + } + opvar_free(vvalue); + } else if (OV_i(arraylen)) { + /* new array */ + create_new_array: + idx = OV_i(arraylen); + tmpvar->array_len = idx; + tmpvar->data.arrayvalues = + (struct opvar **) alloc(sizeof(struct opvar *) * idx); + while (idx-- > 0) { + OV_pop(vvalue); + if (!vvalue) + panic("no value for arrayvariable"); + tmpvar->data.arrayvalues[idx] = vvalue; + } + tmpvar->svtyp = SPOVAR_ARRAY; + } else { + /* new single value */ + OV_pop(vvalue); + if (!vvalue) + panic("no value for variable"); + tmpvar->svtyp = OV_typ(vvalue); + tmpvar->data.value = vvalue; + tmpvar->array_len = 0; + } } opvar_free(vname); opvar_free(arraylen); } - long opvar_array_length(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *vname; struct splev_var *tmp; long len = 0; - if (!coder) return 0; + if (!coder) + return 0; vname = splev_stack_pop(coder->stack); - if (!vname) return 0; - if (vname->spovartyp != SPOVAR_VARIABLE) goto pass; + if (!vname) + return 0; + if (vname->spovartyp != SPOVAR_VARIABLE) + goto pass; tmp = coder->frame->variables; while (tmp) { - if (!strcmp(tmp->name, OV_s(vname))) { - if ((tmp->svtyp & SPOVAR_ARRAY)) { - len = tmp->array_len; - if (len < 1) len = 0; - } - goto pass; - } - tmp = tmp->next; + if (!strcmp(tmp->name, OV_s(vname))) { + if ((tmp->svtyp & SPOVAR_ARRAY)) { + len = tmp->array_len; + if (len < 1) + len = 0; + } + goto pass; + } + tmp = tmp->next; } pass: @@ -4566,35 +4883,34 @@ pass: return len; } - void spo_shuffle_array(coder) - struct sp_coder *coder; +struct sp_coder *coder; { struct opvar *vname; struct splev_var *tmp; struct opvar *tmp2; - long i,j; + long i, j; - if (!OV_pop_s(vname)) return; + if (!OV_pop_s(vname)) + return; tmp = opvar_var_defined(coder, OV_s(vname)); if (!tmp || (tmp->array_len < 1)) { - opvar_free(vname); - return; + opvar_free(vname); + return; } for (i = tmp->array_len - 1; i > 0; i--) { - if ((j = rn2(i + 1)) == i) continue; - tmp2 = tmp->data.arrayvalues[j]; - tmp->data.arrayvalues[j] = tmp->data.arrayvalues[i]; - tmp->data.arrayvalues[i] = tmp2; + if ((j = rn2(i + 1)) == i) + continue; + tmp2 = tmp->data.arrayvalues[j]; + tmp->data.arrayvalues[j] = tmp->data.arrayvalues[i]; + tmp->data.arrayvalues[i] = tmp2; } opvar_free(vname); } - - /* Special level coder, creates the special level from the sp_lev codes. * Does not free the allocated memory. */ @@ -4603,10 +4919,11 @@ sp_level_coder(lvl) sp_lev *lvl; { unsigned long exec_opcodes = 0; - int tmpi; + int tmpi; long room_stack = 0; unsigned long max_execution = SPCODER_MAX_RUNTIME; - struct sp_coder *coder = (struct sp_coder *)alloc(sizeof(struct sp_coder)); + struct sp_coder *coder = + (struct sp_coder *) alloc(sizeof(struct sp_coder)); coder->frame = frame_new(0); coder->stack = NULL; @@ -4621,532 +4938,604 @@ sp_lev *lvl; icedpools = FALSE; if (wizard) { - char *met = nh_getenv("SPCODER_MAX_RUNTIME"); - if (met && met[0] == '1') max_execution = (1<<30) - 1; + char *met = nh_getenv("SPCODER_MAX_RUNTIME"); + if (met && met[0] == '1') + max_execution = (1 << 30) - 1; } for (tmpi = 0; tmpi <= MAX_NESTED_ROOMS; tmpi++) { - coder->tmproomlist[tmpi] = (struct mkroom *)0; - coder->failed_room[tmpi] = FALSE; + coder->tmproomlist[tmpi] = (struct mkroom *) 0; + coder->failed_room[tmpi] = FALSE; } shuffle_alignments(); - for (tmpi = 0; tmpi < MAX_CONTAINMENT; tmpi++) container_obj[tmpi] = NULL; + for (tmpi = 0; tmpi < MAX_CONTAINMENT; tmpi++) + container_obj[tmpi] = NULL; container_idx = 0; invent_carrying_monster = NULL; - (void) memset((genericptr_t)&SpLev_Map[0][0], 0, sizeof SpLev_Map); + (void) memset((genericptr_t) &SpLev_Map[0][0], 0, sizeof SpLev_Map); level.flags.is_maze_lev = 0; xstart = 1; ystart = 0; - xsize = COLNO-1; + xsize = COLNO - 1; ysize = ROWNO; while (coder->frame->n_opcode < lvl->n_opcodes && !coder->exit_script) { - coder->opcode = lvl->opcodes[coder->frame->n_opcode].opcode; - coder->opdat = lvl->opcodes[coder->frame->n_opcode].opdat; + coder->opcode = lvl->opcodes[coder->frame->n_opcode].opcode; + coder->opdat = lvl->opcodes[coder->frame->n_opcode].opdat; - coder->stack = coder->frame->stack; + coder->stack = coder->frame->stack; - if (exec_opcodes++ > max_execution) { - impossible("Level script is taking too much time, stopping."); - coder->exit_script = TRUE; - } + if (exec_opcodes++ > max_execution) { + impossible("Level script is taking too much time, stopping."); + coder->exit_script = TRUE; + } - if (coder->failed_room[coder->n_subroom-1] && - coder->opcode != SPO_ENDROOM && - coder->opcode != SPO_ROOM && - coder->opcode != SPO_SUBROOM) goto next_opcode; + if (coder->failed_room[coder->n_subroom - 1] + && coder->opcode != SPO_ENDROOM && coder->opcode != SPO_ROOM + && coder->opcode != SPO_SUBROOM) + goto next_opcode; - coder->croom = coder->tmproomlist[coder->n_subroom-1]; + coder->croom = coder->tmproomlist[coder->n_subroom - 1]; - switch (coder->opcode) { - case SPO_NULL: break; - case SPO_EXIT: coder->exit_script = TRUE; break; - case SPO_FRAME_PUSH: spo_frame_push(coder); break; - case SPO_FRAME_POP: spo_frame_pop(coder); break; - case SPO_CALL: spo_call(coder); break; - case SPO_RETURN: spo_return(coder); break; - case SPO_END_MONINVENT: spo_end_moninvent(coder); break; - case SPO_POP_CONTAINER: spo_pop_container(coder); break; - case SPO_POP: - { - struct opvar *ov = splev_stack_pop(coder->stack); - opvar_free(ov); - } - break; - case SPO_PUSH: splev_stack_push(coder->stack, opvar_clone(coder->opdat)); break; - case SPO_MESSAGE: spo_message(coder); break; - case SPO_MONSTER: spo_monster(coder); break; - case SPO_OBJECT: spo_object(coder); break; - case SPO_LEVEL_FLAGS: spo_level_flags(coder); break; - case SPO_INITLEVEL: spo_initlevel(coder); break; - case SPO_ENGRAVING: spo_engraving(coder); break; - case SPO_MINERALIZE: spo_mineralize(coder); break; - case SPO_SUBROOM: - case SPO_ROOM: - if (!coder->failed_room[coder->n_subroom-1]) { - spo_room(coder); - } else room_stack++; - break; - case SPO_ENDROOM: - if (coder->failed_room[coder->n_subroom-1]) { - if (!room_stack) - spo_endroom(coder); - else - room_stack--; - } else { - spo_endroom(coder); - } - break; - case SPO_DOOR: spo_door(coder); break; - case SPO_STAIR: spo_stair(coder); break; - case SPO_LADDER: spo_ladder(coder); break; - case SPO_GRAVE: spo_grave(coder); break; - case SPO_ALTAR: spo_altar(coder); break; - case SPO_SINK: - case SPO_POOL: - case SPO_FOUNTAIN: spo_feature(coder); break; - case SPO_TRAP: spo_trap(coder); break; - case SPO_GOLD: spo_gold(coder); break; - case SPO_CORRIDOR: spo_corridor(coder); break; - case SPO_TERRAIN: spo_terrain(coder); break; - case SPO_REPLACETERRAIN: spo_replace_terrain(coder); break; - case SPO_LEVREGION: spo_levregion(coder); break; - case SPO_REGION: spo_region(coder); break; - case SPO_DRAWBRIDGE: spo_drawbridge(coder); break; - case SPO_MAZEWALK: spo_mazewalk(coder); break; - case SPO_NON_PASSWALL: - case SPO_NON_DIGGABLE: spo_wall_property(coder); break; - case SPO_ROOM_DOOR: spo_room_door(coder); break; - case SPO_WALLIFY: spo_wallify(coder); break; - case SPO_COPY: - { - struct opvar *a = splev_stack_pop(coder->stack); - splev_stack_push(coder->stack, opvar_clone(a)); - splev_stack_push(coder->stack, opvar_clone(a)); - opvar_free(a); - } - break; - case SPO_DEC: - { - struct opvar *a; - if (!OV_pop_i(a)) break; - OV_i(a)--; - splev_stack_push(coder->stack, a); - } - break; - case SPO_INC: - { - struct opvar *a; - if (!OV_pop_i(a)) break; - OV_i(a)++; - splev_stack_push(coder->stack, a); - } - break; - case SPO_MATH_SIGN: - { - struct opvar *a; - if (!OV_pop_i(a)) break; - OV_i(a) = ((OV_i(a) < 0) ? -1 : ((OV_i(a) > 0) ? 1 : 0)); - splev_stack_push(coder->stack, a); - } - break; - case SPO_MATH_ADD: - { - struct opvar *a, *b; - if (!OV_pop(b) || !OV_pop(a)) break; - if (OV_typ(b) == OV_typ(a)) { - if (OV_typ(a) == SPOVAR_INT) { - OV_i(a) = OV_i(a) + OV_i(b); - splev_stack_push(coder->stack, a); - opvar_free(b); - } else if (OV_typ(a) == SPOVAR_STRING) { - struct opvar *c; - char *tmpbuf = (char *)alloc(strlen(OV_s(a)) + strlen(OV_s(b)) + 1); - (void) sprintf(tmpbuf, "%s%s", OV_s(a), OV_s(b)); - c = opvar_new_str(tmpbuf); - splev_stack_push(coder->stack, c); - opvar_free(a); - opvar_free(b); - Free(tmpbuf); - } else { - splev_stack_push(coder->stack, a); - opvar_free(b); - impossible("adding weird types"); - } - } else { - splev_stack_push(coder->stack, a); - opvar_free(b); - impossible("adding different types"); - } - } - break; - case SPO_MATH_SUB: - { - struct opvar *a, *b; - if (!OV_pop_i(b) || !OV_pop_i(a)) break; - OV_i(a) = OV_i(a) - OV_i(b); - splev_stack_push(coder->stack, a); - opvar_free(b); - } - break; - case SPO_MATH_MUL: - { - struct opvar *a, *b; - if (!OV_pop_i(b) || !OV_pop_i(a)) break; - OV_i(a) = OV_i(a) * OV_i(b); - splev_stack_push(coder->stack, a); - opvar_free(b); - } - break; - case SPO_MATH_DIV: - { - struct opvar *a, *b; - if (!OV_pop_i(b) || !OV_pop_i(a)) break; - if (OV_i(b) >= 1) { - OV_i(a) = OV_i(a) / OV_i(b); - } else { - OV_i(a) = 0; - } - splev_stack_push(coder->stack, a); - opvar_free(b); - } - break; - case SPO_MATH_MOD: - { - struct opvar *a, *b; - if (!OV_pop_i(b) || !OV_pop_i(a)) break; - if (OV_i(b) > 0) { - OV_i(a) = OV_i(a) % OV_i(b); - } else { - OV_i(a) = 0; - } - splev_stack_push(coder->stack, a); - opvar_free(b); - } - break; - case SPO_CMP: - { - struct opvar *a; - struct opvar *b; - struct opvar *c; - long val = 0; + switch (coder->opcode) { + case SPO_NULL: + break; + case SPO_EXIT: + coder->exit_script = TRUE; + break; + case SPO_FRAME_PUSH: + spo_frame_push(coder); + break; + case SPO_FRAME_POP: + spo_frame_pop(coder); + break; + case SPO_CALL: + spo_call(coder); + break; + case SPO_RETURN: + spo_return(coder); + break; + case SPO_END_MONINVENT: + spo_end_moninvent(coder); + break; + case SPO_POP_CONTAINER: + spo_pop_container(coder); + break; + case SPO_POP: { + struct opvar *ov = splev_stack_pop(coder->stack); + opvar_free(ov); + } break; + case SPO_PUSH: + splev_stack_push(coder->stack, opvar_clone(coder->opdat)); + break; + case SPO_MESSAGE: + spo_message(coder); + break; + case SPO_MONSTER: + spo_monster(coder); + break; + case SPO_OBJECT: + spo_object(coder); + break; + case SPO_LEVEL_FLAGS: + spo_level_flags(coder); + break; + case SPO_INITLEVEL: + spo_initlevel(coder); + break; + case SPO_ENGRAVING: + spo_engraving(coder); + break; + case SPO_MINERALIZE: + spo_mineralize(coder); + break; + case SPO_SUBROOM: + case SPO_ROOM: + if (!coder->failed_room[coder->n_subroom - 1]) { + spo_room(coder); + } else + room_stack++; + break; + case SPO_ENDROOM: + if (coder->failed_room[coder->n_subroom - 1]) { + if (!room_stack) + spo_endroom(coder); + else + room_stack--; + } else { + spo_endroom(coder); + } + break; + case SPO_DOOR: + spo_door(coder); + break; + case SPO_STAIR: + spo_stair(coder); + break; + case SPO_LADDER: + spo_ladder(coder); + break; + case SPO_GRAVE: + spo_grave(coder); + break; + case SPO_ALTAR: + spo_altar(coder); + break; + case SPO_SINK: + case SPO_POOL: + case SPO_FOUNTAIN: + spo_feature(coder); + break; + case SPO_TRAP: + spo_trap(coder); + break; + case SPO_GOLD: + spo_gold(coder); + break; + case SPO_CORRIDOR: + spo_corridor(coder); + break; + case SPO_TERRAIN: + spo_terrain(coder); + break; + case SPO_REPLACETERRAIN: + spo_replace_terrain(coder); + break; + case SPO_LEVREGION: + spo_levregion(coder); + break; + case SPO_REGION: + spo_region(coder); + break; + case SPO_DRAWBRIDGE: + spo_drawbridge(coder); + break; + case SPO_MAZEWALK: + spo_mazewalk(coder); + break; + case SPO_NON_PASSWALL: + case SPO_NON_DIGGABLE: + spo_wall_property(coder); + break; + case SPO_ROOM_DOOR: + spo_room_door(coder); + break; + case SPO_WALLIFY: + spo_wallify(coder); + break; + case SPO_COPY: { + struct opvar *a = splev_stack_pop(coder->stack); + splev_stack_push(coder->stack, opvar_clone(a)); + splev_stack_push(coder->stack, opvar_clone(a)); + opvar_free(a); + } break; + case SPO_DEC: { + struct opvar *a; + if (!OV_pop_i(a)) + break; + OV_i(a)--; + splev_stack_push(coder->stack, a); + } break; + case SPO_INC: { + struct opvar *a; + if (!OV_pop_i(a)) + break; + OV_i(a)++; + splev_stack_push(coder->stack, a); + } break; + case SPO_MATH_SIGN: { + struct opvar *a; + if (!OV_pop_i(a)) + break; + OV_i(a) = ((OV_i(a) < 0) ? -1 : ((OV_i(a) > 0) ? 1 : 0)); + splev_stack_push(coder->stack, a); + } break; + case SPO_MATH_ADD: { + struct opvar *a, *b; + if (!OV_pop(b) || !OV_pop(a)) + break; + if (OV_typ(b) == OV_typ(a)) { + if (OV_typ(a) == SPOVAR_INT) { + OV_i(a) = OV_i(a) + OV_i(b); + splev_stack_push(coder->stack, a); + opvar_free(b); + } else if (OV_typ(a) == SPOVAR_STRING) { + struct opvar *c; + char *tmpbuf = + (char *) alloc(strlen(OV_s(a)) + strlen(OV_s(b)) + 1); + (void) sprintf(tmpbuf, "%s%s", OV_s(a), OV_s(b)); + c = opvar_new_str(tmpbuf); + splev_stack_push(coder->stack, c); + opvar_free(a); + opvar_free(b); + Free(tmpbuf); + } else { + splev_stack_push(coder->stack, a); + opvar_free(b); + impossible("adding weird types"); + } + } else { + splev_stack_push(coder->stack, a); + opvar_free(b); + impossible("adding different types"); + } + } break; + case SPO_MATH_SUB: { + struct opvar *a, *b; + if (!OV_pop_i(b) || !OV_pop_i(a)) + break; + OV_i(a) = OV_i(a) - OV_i(b); + splev_stack_push(coder->stack, a); + opvar_free(b); + } break; + case SPO_MATH_MUL: { + struct opvar *a, *b; + if (!OV_pop_i(b) || !OV_pop_i(a)) + break; + OV_i(a) = OV_i(a) * OV_i(b); + splev_stack_push(coder->stack, a); + opvar_free(b); + } break; + case SPO_MATH_DIV: { + struct opvar *a, *b; + if (!OV_pop_i(b) || !OV_pop_i(a)) + break; + if (OV_i(b) >= 1) { + OV_i(a) = OV_i(a) / OV_i(b); + } else { + OV_i(a) = 0; + } + splev_stack_push(coder->stack, a); + opvar_free(b); + } break; + case SPO_MATH_MOD: { + struct opvar *a, *b; + if (!OV_pop_i(b) || !OV_pop_i(a)) + break; + if (OV_i(b) > 0) { + OV_i(a) = OV_i(a) % OV_i(b); + } else { + OV_i(a) = 0; + } + splev_stack_push(coder->stack, a); + opvar_free(b); + } break; + case SPO_CMP: { + struct opvar *a; + struct opvar *b; + struct opvar *c; + long val = 0; - OV_pop(b); - OV_pop(a); + OV_pop(b); + OV_pop(a); - if (!a || !b) { - impossible("spo_cmp: no values in stack"); - break; - } + if (!a || !b) { + impossible("spo_cmp: no values in stack"); + break; + } - if (OV_typ(a) != OV_typ(b)) { - impossible("spo_cmp: trying to compare differing datatypes"); - break; - } + if (OV_typ(a) != OV_typ(b)) { + impossible("spo_cmp: trying to compare differing datatypes"); + break; + } - switch (OV_typ(a)) { - case SPOVAR_COORD: - case SPOVAR_REGION: - case SPOVAR_MAPCHAR: - case SPOVAR_MONST: - case SPOVAR_OBJ: - case SPOVAR_INT: - if (OV_i(b) > OV_i(a)) val |= SP_CPUFLAG_LT; - if (OV_i(b) < OV_i(a)) val |= SP_CPUFLAG_GT; - if (OV_i(b) == OV_i(a)) val |= SP_CPUFLAG_EQ; - c = opvar_new_int(val); - break; - case SPOVAR_STRING: - c = opvar_new_int(((!strcmp(OV_s(b), OV_s(a))) ? SP_CPUFLAG_EQ : 0)); - break; - default: - c = opvar_new_int(0); - break; - } - splev_stack_push(coder->stack, c); - opvar_free(a); - opvar_free(b); - } - break; + switch (OV_typ(a)) { + case SPOVAR_COORD: + case SPOVAR_REGION: + case SPOVAR_MAPCHAR: + case SPOVAR_MONST: + case SPOVAR_OBJ: + case SPOVAR_INT: + if (OV_i(b) > OV_i(a)) + val |= SP_CPUFLAG_LT; + if (OV_i(b) < OV_i(a)) + val |= SP_CPUFLAG_GT; + if (OV_i(b) == OV_i(a)) + val |= SP_CPUFLAG_EQ; + c = opvar_new_int(val); + break; + case SPOVAR_STRING: + c = opvar_new_int( + ((!strcmp(OV_s(b), OV_s(a))) ? SP_CPUFLAG_EQ : 0)); + break; + default: + c = opvar_new_int(0); + break; + } + splev_stack_push(coder->stack, c); + opvar_free(a); + opvar_free(b); + } break; case SPO_JMP: - spo_jmp(coder, lvl); break; + spo_jmp(coder, lvl); + break; case SPO_JL: case SPO_JLE: case SPO_JG: case SPO_JGE: case SPO_JE: case SPO_JNE: - spo_conditional_jump(coder, lvl); break; - case SPO_RN2: - { - struct opvar *tmpv; - struct opvar *t; - if (!OV_pop_i(tmpv)) break; - t = opvar_new_int((OV_i(tmpv) > 1) ? rn2(OV_i(tmpv)) : 0); - splev_stack_push(coder->stack, t); - opvar_free(tmpv); - } - break; - case SPO_DICE: - { - struct opvar *a, *b, *t; - if (!OV_pop_i(b) || !OV_pop_i(a)) break; - if (OV_i(b) < 1) OV_i(b) = 1; - if (OV_i(a) < 1) OV_i(a) = 1; - t = opvar_new_int(d(OV_i(a), OV_i(b))); - splev_stack_push(coder->stack, t); - opvar_free(a); - opvar_free(b); - } - break; - case SPO_MAP: - spo_map(coder); break; - case SPO_VAR_INIT: - spo_var_init(coder); break; - case SPO_SHUFFLE_ARRAY: - spo_shuffle_array(coder); break; - case SPO_SEL_ADD: /* actually, logical or */ - { - struct opvar *sel1, *sel2, *pt; - if (!OV_pop_typ(sel1, SPOVAR_SEL)) panic("no sel1 for add"); - if (!OV_pop_typ(sel2, SPOVAR_SEL)) panic("no sel2 for add"); - pt = selection_logical_oper(sel1, sel2, '|'); - opvar_free(sel1); - opvar_free(sel2); - splev_stack_push(coder->stack, pt); - } - break; - case SPO_SEL_COMPLEMENT: - { - struct opvar *sel, *pt; - if (!OV_pop_typ(sel, SPOVAR_SEL)) panic("no sel for not"); - pt = selection_not(sel); - opvar_free(sel); - splev_stack_push(coder->stack, pt); - } - break; - case SPO_SEL_FILTER: /* sorta like logical and */ - { - struct opvar *filtertype; - if (!OV_pop_i(filtertype)) panic("no sel filter type"); - switch (OV_i(filtertype)) { - case SPOFILTER_PERCENT: - { - struct opvar *tmp1, *sel; - if (!OV_pop_i(tmp1)) panic("no sel filter percent"); - if (!OV_pop_typ(sel, SPOVAR_SEL)) panic("no sel filter"); - selection_filter_percent(sel, OV_i(tmp1)); - splev_stack_push(coder->stack, sel); - opvar_free(tmp1); - } - break; - case SPOFILTER_SELECTION: /* logical and */ - { - struct opvar *pt, *sel1, *sel2; - if (!OV_pop_typ(sel1, SPOVAR_SEL)) panic("no sel filter sel1"); - if (!OV_pop_typ(sel2, SPOVAR_SEL)) panic("no sel filter sel2"); - pt = selection_logical_oper(sel1, sel2, '&'); - splev_stack_push(coder->stack, pt); - opvar_free(sel1); - opvar_free(sel2); - } - break; - case SPOFILTER_MAPCHAR: - { - struct opvar *pt, *tmp1, *sel; - if (!OV_pop_typ(sel, SPOVAR_SEL)) panic("no sel filter"); - if (!OV_pop_typ(tmp1, SPOVAR_MAPCHAR)) panic("no sel filter mapchar"); - pt = selection_filter_mapchar(sel, tmp1); - splev_stack_push(coder->stack, pt); - opvar_free(tmp1); - opvar_free(sel); - } - break; - default: panic("unknown sel filter type"); - } - opvar_free(filtertype); - } - break; - case SPO_SEL_POINT: - { - struct opvar *tmp; - struct opvar *pt = selection_opvar(NULL); - schar x,y; - if (!OV_pop_c(tmp)) panic("no ter sel coord"); - get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(tmp)); - selection_setpoint(x,y, pt, 1); - splev_stack_push(coder->stack, pt); - opvar_free(tmp); - } - break; - case SPO_SEL_RECT: - case SPO_SEL_FILLRECT: - { - struct opvar *tmp, *pt = selection_opvar(NULL); - schar x,y,x1,y1,x2,y2; - if (!OV_pop_r(tmp)) panic("no ter sel region"); - x1 = min(SP_REGION_X1(OV_i(tmp)), SP_REGION_X2(OV_i(tmp))); - y1 = min(SP_REGION_Y1(OV_i(tmp)), SP_REGION_Y2(OV_i(tmp))); - x2 = max(SP_REGION_X1(OV_i(tmp)), SP_REGION_X2(OV_i(tmp))); - y2 = max(SP_REGION_Y1(OV_i(tmp)), SP_REGION_Y2(OV_i(tmp))); - get_location(&x1, &y1, ANY_LOC, coder->croom); - get_location(&x2, &y2, ANY_LOC, coder->croom); - x1 = (x1 < 0) ? 0 : x1; - y1 = (y1 < 0) ? 0 : y1; - x2 = (x2 >= COLNO) ? COLNO-1 : x2; - y2 = (y2 >= ROWNO) ? ROWNO-1 : y2; - if (coder->opcode == SPO_SEL_RECT) { - for (x = x1; x <= x2; x++) { - selection_setpoint(x,y1, pt, 1); - selection_setpoint(x,y2, pt, 1); - } - for (y = y1; y <= y2; y++) { - selection_setpoint(x1,y, pt, 1); - selection_setpoint(x2,y, pt, 1); - } - } else { - for (x = x1; x <= x2; x++) - for (y = y1; y <= y2; y++) - selection_setpoint(x,y, pt, 1); - } - splev_stack_push(coder->stack, pt); - opvar_free(tmp); - } - break; - case SPO_SEL_LINE: - { - struct opvar *tmp = NULL, *tmp2 = NULL, *pt = selection_opvar(NULL); - schar x1,y1,x2,y2; - if (!OV_pop_c(tmp)) panic("no ter sel linecoord1"); - if (!OV_pop_c(tmp2)) panic("no ter sel linecoord2"); - get_location_coord(&x1, &y1, ANY_LOC, coder->croom, OV_i(tmp)); - get_location_coord(&x2, &y2, ANY_LOC, coder->croom, OV_i(tmp2)); - x1 = (x1 < 0) ? 0 : x1; - y1 = (y1 < 0) ? 0 : y1; - x2 = (x2 >= COLNO) ? COLNO-1 : x2; - y2 = (y2 >= ROWNO) ? ROWNO-1 : y2; - selection_do_line(x1,y1,x2,y2, pt); - splev_stack_push(coder->stack, pt); - opvar_free(tmp); - opvar_free(tmp2); - } - break; - case SPO_SEL_RNDLINE: - { - struct opvar *tmp = NULL, *tmp2 = NULL, *tmp3, *pt = selection_opvar(NULL); - schar x1,y1,x2,y2; - if (!OV_pop_i(tmp3)) panic("no ter sel randline1"); - if (!OV_pop_c(tmp)) panic("no ter sel randline2"); - if (!OV_pop_c(tmp2)) panic("no ter sel randline3"); - get_location_coord(&x1, &y1, ANY_LOC, coder->croom, OV_i(tmp)); - get_location_coord(&x2, &y2, ANY_LOC, coder->croom, OV_i(tmp2)); - x1 = (x1 < 0) ? 0 : x1; - y1 = (y1 < 0) ? 0 : y1; - x2 = (x2 >= COLNO) ? COLNO-1 : x2; - y2 = (y2 >= ROWNO) ? ROWNO-1 : y2; - selection_do_randline(x1,y1,x2,y2, OV_i(tmp3), 12, pt); - splev_stack_push(coder->stack, pt); - opvar_free(tmp); - opvar_free(tmp2); - opvar_free(tmp3); - } - break; - case SPO_SEL_GROW: - { - struct opvar *dirs, *pt; - if (!OV_pop_i(dirs)) panic("no dirs for grow"); - if (!OV_pop_typ(pt, SPOVAR_SEL)) panic("no selection for grow"); - selection_do_grow(pt, OV_i(dirs)); - splev_stack_push(coder->stack, pt); - opvar_free(dirs); - } - break; - case SPO_SEL_FLOOD: - { - struct opvar *tmp; - schar x,y; - if (!OV_pop_c(tmp)) panic("no ter sel flood coord"); - get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(tmp)); - if (isok(x,y)) { - struct opvar *pt = selection_opvar(NULL); - selection_floodfill(pt, x,y); - splev_stack_push(coder->stack, pt); - } - opvar_free(tmp); - } - break; - case SPO_SEL_RNDCOORD: - { - struct opvar *pt; - schar x,y; - if (!OV_pop_typ(pt, SPOVAR_SEL)) panic("no selection for rndcoord"); - if (selection_rndcoord(pt, &x, &y)) { - x -= xstart; - y -= ystart; - } - splev_stack_push(coder->stack, opvar_new_coord(x,y)); - opvar_free(pt); - } - break; - case SPO_SEL_ELLIPSE: - { - struct opvar *filled, *xaxis, *yaxis, *pt; - struct opvar *sel = selection_opvar(NULL); - schar x,y; - if (!OV_pop_i(filled)) panic("no filled for ellipse"); - if (!OV_pop_i(yaxis)) panic("no yaxis for ellipse"); - if (!OV_pop_i(xaxis)) panic("no xaxis for ellipse"); - if (!OV_pop_c(pt)) panic("no pt for ellipse"); - get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(pt)); - selection_do_ellipse(sel, x,y, OV_i(xaxis), OV_i(yaxis), OV_i(filled)); - splev_stack_push(coder->stack, sel); - opvar_free(filled); - opvar_free(yaxis); - opvar_free(xaxis); - opvar_free(pt); - } - break; - case SPO_SEL_GRADIENT: - { - struct opvar *gtyp, *glim, *mind, *maxd, *gcoord, *coord2; - struct opvar *sel; - schar x,y, x2,y2; - if (!OV_pop_i(gtyp)) panic("no gtyp for grad"); - if (!OV_pop_i(glim)) panic("no glim for grad"); - if (!OV_pop_c(coord2)) panic("no coord2 for grad"); - if (!OV_pop_c(gcoord)) panic("no coord for grad"); - if (!OV_pop_i(maxd)) panic("no maxd for grad"); - if (!OV_pop_i(mind)) panic("no mind for grad"); - get_location_coord(&x, &y, ANY_LOC, coder->croom, - OV_i(gcoord)); - get_location_coord(&x2, &y2, ANY_LOC, coder->croom, - OV_i(coord2)); + spo_conditional_jump(coder, lvl); + break; + case SPO_RN2: { + struct opvar *tmpv; + struct opvar *t; + if (!OV_pop_i(tmpv)) + break; + t = opvar_new_int((OV_i(tmpv) > 1) ? rn2(OV_i(tmpv)) : 0); + splev_stack_push(coder->stack, t); + opvar_free(tmpv); + } break; + case SPO_DICE: { + struct opvar *a, *b, *t; + if (!OV_pop_i(b) || !OV_pop_i(a)) + break; + if (OV_i(b) < 1) + OV_i(b) = 1; + if (OV_i(a) < 1) + OV_i(a) = 1; + t = opvar_new_int(d(OV_i(a), OV_i(b))); + splev_stack_push(coder->stack, t); + opvar_free(a); + opvar_free(b); + } break; + case SPO_MAP: + spo_map(coder); + break; + case SPO_VAR_INIT: + spo_var_init(coder); + break; + case SPO_SHUFFLE_ARRAY: + spo_shuffle_array(coder); + break; + case SPO_SEL_ADD: /* actually, logical or */ + { + struct opvar *sel1, *sel2, *pt; + if (!OV_pop_typ(sel1, SPOVAR_SEL)) + panic("no sel1 for add"); + if (!OV_pop_typ(sel2, SPOVAR_SEL)) + panic("no sel2 for add"); + pt = selection_logical_oper(sel1, sel2, '|'); + opvar_free(sel1); + opvar_free(sel2); + splev_stack_push(coder->stack, pt); + } break; + case SPO_SEL_COMPLEMENT: { + struct opvar *sel, *pt; + if (!OV_pop_typ(sel, SPOVAR_SEL)) + panic("no sel for not"); + pt = selection_not(sel); + opvar_free(sel); + splev_stack_push(coder->stack, pt); + } break; + case SPO_SEL_FILTER: /* sorta like logical and */ + { + struct opvar *filtertype; + if (!OV_pop_i(filtertype)) + panic("no sel filter type"); + switch (OV_i(filtertype)) { + case SPOFILTER_PERCENT: { + struct opvar *tmp1, *sel; + if (!OV_pop_i(tmp1)) + panic("no sel filter percent"); + if (!OV_pop_typ(sel, SPOVAR_SEL)) + panic("no sel filter"); + selection_filter_percent(sel, OV_i(tmp1)); + splev_stack_push(coder->stack, sel); + opvar_free(tmp1); + } break; + case SPOFILTER_SELECTION: /* logical and */ + { + struct opvar *pt, *sel1, *sel2; + if (!OV_pop_typ(sel1, SPOVAR_SEL)) + panic("no sel filter sel1"); + if (!OV_pop_typ(sel2, SPOVAR_SEL)) + panic("no sel filter sel2"); + pt = selection_logical_oper(sel1, sel2, '&'); + splev_stack_push(coder->stack, pt); + opvar_free(sel1); + opvar_free(sel2); + } break; + case SPOFILTER_MAPCHAR: { + struct opvar *pt, *tmp1, *sel; + if (!OV_pop_typ(sel, SPOVAR_SEL)) + panic("no sel filter"); + if (!OV_pop_typ(tmp1, SPOVAR_MAPCHAR)) + panic("no sel filter mapchar"); + pt = selection_filter_mapchar(sel, tmp1); + splev_stack_push(coder->stack, pt); + opvar_free(tmp1); + opvar_free(sel); + } break; + default: + panic("unknown sel filter type"); + } + opvar_free(filtertype); + } break; + case SPO_SEL_POINT: { + struct opvar *tmp; + struct opvar *pt = selection_opvar(NULL); + schar x, y; + if (!OV_pop_c(tmp)) + panic("no ter sel coord"); + get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(tmp)); + selection_setpoint(x, y, pt, 1); + splev_stack_push(coder->stack, pt); + opvar_free(tmp); + } break; + case SPO_SEL_RECT: + case SPO_SEL_FILLRECT: { + struct opvar *tmp, *pt = selection_opvar(NULL); + schar x, y, x1, y1, x2, y2; + if (!OV_pop_r(tmp)) + panic("no ter sel region"); + x1 = min(SP_REGION_X1(OV_i(tmp)), SP_REGION_X2(OV_i(tmp))); + y1 = min(SP_REGION_Y1(OV_i(tmp)), SP_REGION_Y2(OV_i(tmp))); + x2 = max(SP_REGION_X1(OV_i(tmp)), SP_REGION_X2(OV_i(tmp))); + y2 = max(SP_REGION_Y1(OV_i(tmp)), SP_REGION_Y2(OV_i(tmp))); + get_location(&x1, &y1, ANY_LOC, coder->croom); + get_location(&x2, &y2, ANY_LOC, coder->croom); + x1 = (x1 < 0) ? 0 : x1; + y1 = (y1 < 0) ? 0 : y1; + x2 = (x2 >= COLNO) ? COLNO - 1 : x2; + y2 = (y2 >= ROWNO) ? ROWNO - 1 : y2; + if (coder->opcode == SPO_SEL_RECT) { + for (x = x1; x <= x2; x++) { + selection_setpoint(x, y1, pt, 1); + selection_setpoint(x, y2, pt, 1); + } + for (y = y1; y <= y2; y++) { + selection_setpoint(x1, y, pt, 1); + selection_setpoint(x2, y, pt, 1); + } + } else { + for (x = x1; x <= x2; x++) + for (y = y1; y <= y2; y++) + selection_setpoint(x, y, pt, 1); + } + splev_stack_push(coder->stack, pt); + opvar_free(tmp); + } break; + case SPO_SEL_LINE: { + struct opvar *tmp = NULL, *tmp2 = NULL, + *pt = selection_opvar(NULL); + schar x1, y1, x2, y2; + if (!OV_pop_c(tmp)) + panic("no ter sel linecoord1"); + if (!OV_pop_c(tmp2)) + panic("no ter sel linecoord2"); + get_location_coord(&x1, &y1, ANY_LOC, coder->croom, OV_i(tmp)); + get_location_coord(&x2, &y2, ANY_LOC, coder->croom, OV_i(tmp2)); + x1 = (x1 < 0) ? 0 : x1; + y1 = (y1 < 0) ? 0 : y1; + x2 = (x2 >= COLNO) ? COLNO - 1 : x2; + y2 = (y2 >= ROWNO) ? ROWNO - 1 : y2; + selection_do_line(x1, y1, x2, y2, pt); + splev_stack_push(coder->stack, pt); + opvar_free(tmp); + opvar_free(tmp2); + } break; + case SPO_SEL_RNDLINE: { + struct opvar *tmp = NULL, *tmp2 = NULL, *tmp3, + *pt = selection_opvar(NULL); + schar x1, y1, x2, y2; + if (!OV_pop_i(tmp3)) + panic("no ter sel randline1"); + if (!OV_pop_c(tmp)) + panic("no ter sel randline2"); + if (!OV_pop_c(tmp2)) + panic("no ter sel randline3"); + get_location_coord(&x1, &y1, ANY_LOC, coder->croom, OV_i(tmp)); + get_location_coord(&x2, &y2, ANY_LOC, coder->croom, OV_i(tmp2)); + x1 = (x1 < 0) ? 0 : x1; + y1 = (y1 < 0) ? 0 : y1; + x2 = (x2 >= COLNO) ? COLNO - 1 : x2; + y2 = (y2 >= ROWNO) ? ROWNO - 1 : y2; + selection_do_randline(x1, y1, x2, y2, OV_i(tmp3), 12, pt); + splev_stack_push(coder->stack, pt); + opvar_free(tmp); + opvar_free(tmp2); + opvar_free(tmp3); + } break; + case SPO_SEL_GROW: { + struct opvar *dirs, *pt; + if (!OV_pop_i(dirs)) + panic("no dirs for grow"); + if (!OV_pop_typ(pt, SPOVAR_SEL)) + panic("no selection for grow"); + selection_do_grow(pt, OV_i(dirs)); + splev_stack_push(coder->stack, pt); + opvar_free(dirs); + } break; + case SPO_SEL_FLOOD: { + struct opvar *tmp; + schar x, y; + if (!OV_pop_c(tmp)) + panic("no ter sel flood coord"); + get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(tmp)); + if (isok(x, y)) { + struct opvar *pt = selection_opvar(NULL); + selection_floodfill(pt, x, y); + splev_stack_push(coder->stack, pt); + } + opvar_free(tmp); + } break; + case SPO_SEL_RNDCOORD: { + struct opvar *pt; + schar x, y; + if (!OV_pop_typ(pt, SPOVAR_SEL)) + panic("no selection for rndcoord"); + if (selection_rndcoord(pt, &x, &y)) { + x -= xstart; + y -= ystart; + } + splev_stack_push(coder->stack, opvar_new_coord(x, y)); + opvar_free(pt); + } break; + case SPO_SEL_ELLIPSE: { + struct opvar *filled, *xaxis, *yaxis, *pt; + struct opvar *sel = selection_opvar(NULL); + schar x, y; + if (!OV_pop_i(filled)) + panic("no filled for ellipse"); + if (!OV_pop_i(yaxis)) + panic("no yaxis for ellipse"); + if (!OV_pop_i(xaxis)) + panic("no xaxis for ellipse"); + if (!OV_pop_c(pt)) + panic("no pt for ellipse"); + get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(pt)); + selection_do_ellipse(sel, x, y, OV_i(xaxis), OV_i(yaxis), + OV_i(filled)); + splev_stack_push(coder->stack, sel); + opvar_free(filled); + opvar_free(yaxis); + opvar_free(xaxis); + opvar_free(pt); + } break; + case SPO_SEL_GRADIENT: { + struct opvar *gtyp, *glim, *mind, *maxd, *gcoord, *coord2; + struct opvar *sel; + schar x, y, x2, y2; + if (!OV_pop_i(gtyp)) + panic("no gtyp for grad"); + if (!OV_pop_i(glim)) + panic("no glim for grad"); + if (!OV_pop_c(coord2)) + panic("no coord2 for grad"); + if (!OV_pop_c(gcoord)) + panic("no coord for grad"); + if (!OV_pop_i(maxd)) + panic("no maxd for grad"); + if (!OV_pop_i(mind)) + panic("no mind for grad"); + get_location_coord(&x, &y, ANY_LOC, coder->croom, OV_i(gcoord)); + get_location_coord(&x2, &y2, ANY_LOC, coder->croom, OV_i(coord2)); - sel = selection_opvar(NULL); - selection_do_gradient(sel, x,y, x2,y2, OV_i(gtyp), - OV_i(mind), OV_i(maxd), OV_i(glim)); - splev_stack_push(coder->stack, sel); + sel = selection_opvar(NULL); + selection_do_gradient(sel, x, y, x2, y2, OV_i(gtyp), OV_i(mind), + OV_i(maxd), OV_i(glim)); + splev_stack_push(coder->stack, sel); - opvar_free(gtyp); - opvar_free(glim); - opvar_free(gcoord); - opvar_free(coord2); - opvar_free(maxd); - opvar_free(mind); - } - break; - default: - panic("sp_level_coder: Unknown opcode %i", coder->opcode); - } + opvar_free(gtyp); + opvar_free(glim); + opvar_free(gcoord); + opvar_free(coord2); + opvar_free(maxd); + opvar_free(mind); + } break; + default: + panic("sp_level_coder: Unknown opcode %i", coder->opcode); + } -next_opcode: - coder->frame->n_opcode++; + next_opcode: + coder->frame->n_opcode++; } /*while*/ link_doors_rooms(); @@ -5159,20 +5548,22 @@ next_opcode: * purpose. */ if (!level.flags.corrmaze) - wallification(1, 0, COLNO-1, ROWNO-1); + wallification(1, 0, COLNO - 1, ROWNO - 1); count_features(); - if (coder->premapped) sokoban_detect(); - if (coder->solidify) solidify_map(); + if (coder->premapped) + sokoban_detect(); + if (coder->solidify) + solidify_map(); if (coder->frame) { - struct sp_frame *tmpframe; - do { - tmpframe = coder->frame->next; - frame_del(coder->frame); - coder->frame = tmpframe; - } while (coder->frame); + struct sp_frame *tmpframe; + do { + tmpframe = coder->frame->next; + frame_del(coder->frame); + coder->frame = tmpframe; + } while (coder->frame); } return TRUE; @@ -5186,30 +5577,31 @@ boolean load_special(name) const char *name; { - dlb *fd; - sp_lev *lvl = NULL; - boolean result = FALSE; - struct version_info vers_info; + dlb *fd; + sp_lev *lvl = NULL; + boolean result = FALSE; + struct version_info vers_info; - fd = dlb_fopen(name, RDBMODE); - if (!fd) return FALSE; - Fread((genericptr_t) &vers_info, sizeof vers_info, 1, fd); - if (!check_version(&vers_info, name, TRUE)) { - (void)dlb_fclose(fd); - goto give_up; - } - lvl = (sp_lev *)alloc(sizeof(sp_lev)); - result = sp_level_loader(fd, lvl); - (void)dlb_fclose(fd); - if (result) result = sp_level_coder(lvl); - sp_level_free(lvl); - Free(lvl); + fd = dlb_fopen(name, RDBMODE); + if (!fd) + return FALSE; + Fread((genericptr_t) &vers_info, sizeof vers_info, 1, fd); + if (!check_version(&vers_info, name, TRUE)) { + (void) dlb_fclose(fd); + goto give_up; + } + lvl = (sp_lev *) alloc(sizeof(sp_lev)); + result = sp_level_loader(fd, lvl); + (void) dlb_fclose(fd); + if (result) + result = sp_level_coder(lvl); + sp_level_free(lvl); + Free(lvl); - give_up: - return result; +give_up: + return result; } - #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/src/spell.c b/src/spell.c index e68a49b79..71f4ff332 100644 --- a/src/spell.c +++ b/src/spell.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 spell.c $NHDT-Date: 1429513494 2015/04/20 07:04:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.57 $ */ +/* NetHack 3.6 spell.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.61 $ */ /* NetHack 3.6 spell.c $Date: 2011/12/29 22:01:25 $ $Revision: 1.44 $ */ /* Copyright (c) M. Stephenson 1988 */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,7 +8,7 @@ /* spellmenu arguments; 0 thru n-1 used as spl_book[] index when swapping */ #define SPELLMENU_CAST (-2) #define SPELLMENU_VIEW (-1) -#define SPELLMENU_SORT (MAXSPELL) /* special menu entry */ +#define SPELLMENU_SORT (MAXSPELL) /* special menu entry */ /* spell retention period, in turns; at 10% of this value, player becomes eligible to reread the spellbook and regain 100% retention (the threshold @@ -19,25 +19,26 @@ initialization; spell memory is decremented at the end of each turn, including the turn on which the spellbook is read; without the extra increment, the hero used to get cheated out of 1 turn of retention */ -#define incrnknow(spell,x) (spl_book[spell].sp_know = KEEN + (x)) +#define incrnknow(spell, x) (spl_book[spell].sp_know = KEEN + (x)) -#define spellev(spell) spl_book[spell].sp_lev -#define spellname(spell) OBJ_NAME(objects[spellid(spell)]) -#define spellet(spell) \ - ((char)((spell < 26) ? ('a' + spell) : ('A' + spell - 26))) +#define spellev(spell) spl_book[spell].sp_lev +#define spellname(spell) OBJ_NAME(objects[spellid(spell)]) +#define spellet(spell) \ + ((char) ((spell < 26) ? ('a' + spell) : ('A' + spell - 26))) STATIC_DCL int FDECL(spell_let_to_idx, (CHAR_P)); -STATIC_DCL boolean FDECL(cursed_book, (struct obj *bp)); +STATIC_DCL boolean FDECL(cursed_book, (struct obj * bp)); STATIC_DCL boolean FDECL(confused_book, (struct obj *)); STATIC_DCL void FDECL(deadbook, (struct obj *)); STATIC_PTR int NDECL(learn); STATIC_DCL boolean FDECL(getspell, (int *)); -STATIC_PTR int FDECL(CFDECLSPEC spell_cmp,(const genericptr,const genericptr)); +STATIC_PTR int FDECL(CFDECLSPEC spell_cmp, + (const genericptr, const genericptr)); STATIC_DCL void NDECL(sortspells); STATIC_DCL boolean NDECL(spellsortmenu); -STATIC_DCL boolean FDECL(dospellmenu, (const char *,int,int *)); +STATIC_DCL boolean FDECL(dospellmenu, (const char *, int, int *)); STATIC_DCL int FDECL(percent_success, (int)); -STATIC_DCL char *FDECL(spellretention, (int,char *)); +STATIC_DCL char *FDECL(spellretention, (int, char *)); STATIC_DCL int NDECL(throwspell); STATIC_DCL void NDECL(cast_protection); STATIC_DCL void FDECL(spell_backfire, (int)); @@ -49,7 +50,8 @@ STATIC_DCL const char *FDECL(spelltypemnemonic, (int)); * Reasoning: * spelbase, spelheal: * Arc are aware of magic through historical research - * Bar abhor magic (Conan finds it "interferes with his animal instincts") + * Bar abhor magic (Conan finds it "interferes with his animal + *instincts") * Cav are ignorant to magic * Hea are very aware of healing magic through medical research * Kni are moderately aware of healing from Paladin training @@ -107,69 +109,70 @@ char ilet; int indx; indx = ilet - 'a'; - if (indx >= 0 && indx < 26) return indx; + if (indx >= 0 && indx < 26) + return indx; indx = ilet - 'A'; - if (indx >= 0 && indx < 26) return indx + 26; + if (indx >= 0 && indx < 26) + return indx + 26; return -1; } /* TRUE: book should be destroyed by caller */ STATIC_OVL boolean cursed_book(bp) - struct obj *bp; +struct obj *bp; { - int lev = objects[bp->otyp].oc_level; - int dmg = 0; + int lev = objects[bp->otyp].oc_level; + int dmg = 0; - switch(rn2(lev)) { - case 0: - You_feel("a wrenching sensation."); - tele(); /* teleport him */ - break; - case 1: - You_feel("threatened."); - aggravate(); - break; - case 2: - make_blinded(Blinded + rn1(100,250),TRUE); - break; - case 3: - take_gold(); - break; - case 4: - pline("These runes were just too much to comprehend."); - make_confused(HConfusion + rn1(7,16),FALSE); - break; - case 5: - pline_The("book was coated with contact poison!"); - if (uarmg) { - erode_obj(uarmg, "gloves", ERODE_CORRODE, - EF_GREASE | EF_VERBOSE); - break; - } - /* temp disable in_use; death should not destroy the book */ - bp->in_use = FALSE; - losestr(Poison_resistance ? rn1(2,1) : rn1(4,3)); - losehp(rnd(Poison_resistance ? 6 : 10), - "contact-poisoned spellbook", KILLED_BY_AN); - bp->in_use = TRUE; - break; - case 6: - if(Antimagic) { - shieldeff(u.ux, u.uy); - pline_The("book %s, but you are unharmed!", explodes); - } else { - pline("As you read the book, it %s in your %s!", - explodes, body_part(FACE)); - dmg = 2*rnd(10)+5; - losehp(Maybe_Half_Phys(dmg), "exploding rune", KILLED_BY_AN); - } - return TRUE; - default: - rndcurse(); - break; - } - return FALSE; + switch (rn2(lev)) { + case 0: + You_feel("a wrenching sensation."); + tele(); /* teleport him */ + break; + case 1: + You_feel("threatened."); + aggravate(); + break; + case 2: + make_blinded(Blinded + rn1(100, 250), TRUE); + break; + case 3: + take_gold(); + break; + case 4: + pline("These runes were just too much to comprehend."); + make_confused(HConfusion + rn1(7, 16), FALSE); + break; + case 5: + pline_The("book was coated with contact poison!"); + if (uarmg) { + erode_obj(uarmg, "gloves", ERODE_CORRODE, EF_GREASE | EF_VERBOSE); + break; + } + /* temp disable in_use; death should not destroy the book */ + bp->in_use = FALSE; + losestr(Poison_resistance ? rn1(2, 1) : rn1(4, 3)); + losehp(rnd(Poison_resistance ? 6 : 10), "contact-poisoned spellbook", + KILLED_BY_AN); + bp->in_use = TRUE; + break; + case 6: + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline_The("book %s, but you are unharmed!", explodes); + } else { + pline("As you read the book, it %s in your %s!", explodes, + body_part(FACE)); + dmg = 2 * rnd(10) + 5; + losehp(Maybe_Half_Phys(dmg), "exploding rune", KILLED_BY_AN); + } + return TRUE; + default: + rndcurse(); + break; + } + return FALSE; } /* study while confused: returns TRUE if the book is destroyed */ @@ -177,24 +180,24 @@ STATIC_OVL boolean confused_book(spellbook) struct obj *spellbook; { - boolean gone = FALSE; + boolean gone = FALSE; - if (!rn2(3) && spellbook->otyp != SPE_BOOK_OF_THE_DEAD) { - spellbook->in_use = TRUE; /* in case called from learn */ - pline( - "Being confused you have difficulties in controlling your actions."); - display_nhwindow(WIN_MESSAGE, FALSE); - You("accidentally tear the spellbook to pieces."); - if (!objects[spellbook->otyp].oc_name_known && - !objects[spellbook->otyp].oc_uname) - docall(spellbook); - useup(spellbook); - gone = TRUE; - } else { - You("find yourself reading the %s line over and over again.", - spellbook == context.spbook.book ? "next" : "first"); - } - return gone; + if (!rn2(3) && spellbook->otyp != SPE_BOOK_OF_THE_DEAD) { + spellbook->in_use = TRUE; /* in case called from learn */ + pline("Being confused you have difficulties in controlling your " + "actions."); + display_nhwindow(WIN_MESSAGE, FALSE); + You("accidentally tear the spellbook to pieces."); + if (!objects[spellbook->otyp].oc_name_known + && !objects[spellbook->otyp].oc_uname) + docall(spellbook); + useup(spellbook); + gone = TRUE; + } else { + You("find yourself reading the %s line over and over again.", + spellbook == context.spbook.book ? "next" : "first"); + } + return gone; } /* special effects for The Book of the Dead */ @@ -209,104 +212,114 @@ struct obj *book2; makeknown(SPE_BOOK_OF_THE_DEAD); /* KMH -- Need ->known to avoid "_a_ Book of the Dead" */ book2->known = 1; - if(invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) { - register struct obj *otmp; - register boolean arti1_primed = FALSE, arti2_primed = FALSE, - arti_cursed = FALSE; + if (invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) { + register struct obj *otmp; + register boolean arti1_primed = FALSE, arti2_primed = FALSE, + arti_cursed = FALSE; - if(book2->cursed) { - pline_The("runes appear scrambled. You can't read them!"); - return; - } + if (book2->cursed) { + pline_The("runes appear scrambled. You can't read them!"); + return; + } - if(!u.uhave.bell || !u.uhave.menorah) { - pline("A chill runs down your %s.", body_part(SPINE)); - if(!u.uhave.bell) You_hear("a faint chime..."); - if(!u.uhave.menorah) pline("Vlad's doppelganger is amused."); - return; - } + if (!u.uhave.bell || !u.uhave.menorah) { + pline("A chill runs down your %s.", body_part(SPINE)); + if (!u.uhave.bell) + You_hear("a faint chime..."); + if (!u.uhave.menorah) + pline("Vlad's doppelganger is amused."); + return; + } - for(otmp = invent; otmp; otmp = otmp->nobj) { - if(otmp->otyp == CANDELABRUM_OF_INVOCATION && - otmp->spe == 7 && otmp->lamplit) { - if(!otmp->cursed) arti1_primed = TRUE; - else arti_cursed = TRUE; - } - if(otmp->otyp == BELL_OF_OPENING && - (moves - otmp->age) < 5L) { /* you rang it recently */ - if(!otmp->cursed) arti2_primed = TRUE; - else arti_cursed = TRUE; - } - } + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->otyp == CANDELABRUM_OF_INVOCATION && otmp->spe == 7 + && otmp->lamplit) { + if (!otmp->cursed) + arti1_primed = TRUE; + else + arti_cursed = TRUE; + } + if (otmp->otyp == BELL_OF_OPENING + && (moves - otmp->age) < 5L) { /* you rang it recently */ + if (!otmp->cursed) + arti2_primed = TRUE; + else + arti_cursed = TRUE; + } + } - if(arti_cursed) { - pline_The("invocation fails!"); - pline("At least one of your artifacts is cursed..."); - } else if(arti1_primed && arti2_primed) { - unsigned soon = (unsigned) d(2,6); /* time til next intervene() */ + if (arti_cursed) { + pline_The("invocation fails!"); + pline("At least one of your artifacts is cursed..."); + } else if (arti1_primed && arti2_primed) { + unsigned soon = + (unsigned) d(2, 6); /* time til next intervene() */ - /* successful invocation */ - mkinvokearea(); - u.uevent.invoked = 1; - /* in case you haven't killed the Wizard yet, behave as if - you just did */ - u.uevent.udemigod = 1; /* wizdead() */ - if (!u.udg_cnt || u.udg_cnt > soon) u.udg_cnt = soon; - } else { /* at least one artifact not prepared properly */ - You("have a feeling that %s is amiss...", something); - goto raise_dead; - } - return; + /* successful invocation */ + mkinvokearea(); + u.uevent.invoked = 1; + /* in case you haven't killed the Wizard yet, behave as if + you just did */ + u.uevent.udemigod = 1; /* wizdead() */ + if (!u.udg_cnt || u.udg_cnt > soon) + u.udg_cnt = soon; + } else { /* at least one artifact not prepared properly */ + You("have a feeling that %s is amiss...", something); + goto raise_dead; + } + return; } /* when not an invocation situation */ if (book2->cursed) { -raise_dead: + raise_dead: - You("raised the dead!"); - /* first maybe place a dangerous adversary */ - if (!rn2(3) && ((mtmp = makemon(&mons[PM_MASTER_LICH], - u.ux, u.uy, NO_MINVENT)) != 0 || - (mtmp = makemon(&mons[PM_NALFESHNEE], - u.ux, u.uy, NO_MINVENT)) != 0)) { - mtmp->mpeaceful = 0; - set_malign(mtmp); - } - /* next handle the affect on things you're carrying */ - (void) unturn_dead(&youmonst); - /* last place some monsters around you */ - mm.x = u.ux; - mm.y = u.uy; - mkundead(&mm, TRUE, NO_MINVENT); - } else if(book2->blessed) { - for(mtmp = fmon; mtmp; mtmp = mtmp2) { - mtmp2 = mtmp->nmon; /* tamedog() changes chain */ - if (DEADMONSTER(mtmp)) continue; + You("raised the dead!"); + /* first maybe place a dangerous adversary */ + if (!rn2(3) && ((mtmp = makemon(&mons[PM_MASTER_LICH], u.ux, u.uy, + NO_MINVENT)) != 0 + || (mtmp = makemon(&mons[PM_NALFESHNEE], u.ux, u.uy, + NO_MINVENT)) != 0)) { + mtmp->mpeaceful = 0; + set_malign(mtmp); + } + /* next handle the affect on things you're carrying */ + (void) unturn_dead(&youmonst); + /* last place some monsters around you */ + mm.x = u.ux; + mm.y = u.uy; + mkundead(&mm, TRUE, NO_MINVENT); + } else if (book2->blessed) { + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + mtmp2 = mtmp->nmon; /* tamedog() changes chain */ + if (DEADMONSTER(mtmp)) + continue; - if ((is_undead(mtmp->data) || is_vampshifter(mtmp)) && - cansee(mtmp->mx, mtmp->my)) { - mtmp->mpeaceful = TRUE; - if(sgn(mtmp->data->maligntyp) == sgn(u.ualign.type) - && distu(mtmp->mx, mtmp->my) < 4) - if (mtmp->mtame) { - if (mtmp->mtame < 20) - mtmp->mtame++; - } else - (void) tamedog(mtmp, (struct obj *)0); - else monflee(mtmp, 0, FALSE, TRUE); - } - } + if ((is_undead(mtmp->data) || is_vampshifter(mtmp)) + && cansee(mtmp->mx, mtmp->my)) { + mtmp->mpeaceful = TRUE; + if (sgn(mtmp->data->maligntyp) == sgn(u.ualign.type) + && distu(mtmp->mx, mtmp->my) < 4) + if (mtmp->mtame) { + if (mtmp->mtame < 20) + mtmp->mtame++; + } else + (void) tamedog(mtmp, (struct obj *) 0); + else + monflee(mtmp, 0, FALSE, TRUE); + } + } } else { - switch(rn2(3)) { - case 0: - Your("ancestors are annoyed with you!"); - break; - case 1: - pline_The("headstones in the cemetery begin to move!"); - break; - default: - pline("Oh my! Your name appears in the book!"); - } + switch (rn2(3)) { + case 0: + Your("ancestors are annoyed with you!"); + break; + case 1: + pline_The("headstones in the cemetery begin to move!"); + break; + default: + pline("Oh my! Your name appears in the book!"); + } } return; } @@ -314,251 +327,257 @@ raise_dead: STATIC_PTR int learn(VOID_ARGS) { - int i; - short booktype; - char splname[BUFSZ]; - boolean costly = TRUE; - struct obj *book = context.spbook.book; + int i; + short booktype; + char splname[BUFSZ]; + boolean costly = TRUE; + struct obj *book = context.spbook.book; - /* JDS: lenses give 50% faster reading; 33% smaller read time */ - if (context.spbook.delay && ublindf && ublindf->otyp == LENSES && rn2(2)) - context.spbook.delay++; - if (Confusion) { /* became confused while learning */ - (void) confused_book(book); - context.spbook.book = 0; /* no longer studying */ - context.spbook.o_id = 0; - nomul(context.spbook.delay); /* remaining delay is uninterrupted */ - multi_reason = "reading a book"; - nomovemsg = 0; - context.spbook.delay = 0; - return(0); - } - if (context.spbook.delay) { /* not if (context.spbook.delay++), so at end delay == 0 */ - context.spbook.delay++; - return(1); /* still busy */ - } - exercise(A_WIS, TRUE); /* you're studying. */ - booktype = book->otyp; - if(booktype == SPE_BOOK_OF_THE_DEAD) { - deadbook(book); - return(0); - } + /* JDS: lenses give 50% faster reading; 33% smaller read time */ + if (context.spbook.delay && ublindf && ublindf->otyp == LENSES && rn2(2)) + context.spbook.delay++; + if (Confusion) { /* became confused while learning */ + (void) confused_book(book); + context.spbook.book = 0; /* no longer studying */ + context.spbook.o_id = 0; + nomul(context.spbook.delay); /* remaining delay is uninterrupted */ + multi_reason = "reading a book"; + nomovemsg = 0; + context.spbook.delay = 0; + return (0); + } + if (context + .spbook.delay) { /* not if (context.spbook.delay++), so at end + delay == 0 */ + context.spbook.delay++; + return (1); /* still busy */ + } + exercise(A_WIS, TRUE); /* you're studying. */ + booktype = book->otyp; + if (booktype == SPE_BOOK_OF_THE_DEAD) { + deadbook(book); + return (0); + } - Sprintf(splname, objects[booktype].oc_name_known ? - "\"%s\"" : "the \"%s\" spell", - OBJ_NAME(objects[booktype])); - for (i = 0; i < MAXSPELL; i++) - if (spellid(i) == booktype || spellid(i) == NO_SPELL) break; + Sprintf(splname, + objects[booktype].oc_name_known ? "\"%s\"" : "the \"%s\" spell", + OBJ_NAME(objects[booktype])); + for (i = 0; i < MAXSPELL; i++) + if (spellid(i) == booktype || spellid(i) == NO_SPELL) + break; - if (i == MAXSPELL) { - impossible("Too many spells memorized!"); - } else if (spellid(i) == booktype) { - /* normal book can be read and re-read a total of 4 times */ - if (book->spestudied > MAX_SPELL_STUDY) { - pline("This spellbook is too faint to be read any more."); - book->otyp = booktype = SPE_BLANK_PAPER; - /* reset spestudied as if polymorph had taken place */ - book->spestudied = rn2(book->spestudied); - } else if (spellknow(i) > KEEN / 10) { - You("know %s quite well already.", splname); - costly = FALSE; - } else { /* spellknow(i) <= KEEN/10 */ - Your("knowledge of %s is %s.", splname, - spellknow(i) ? "keener" : "restored"); - incrnknow(i, 1); - book->spestudied++; - exercise(A_WIS,TRUE); /* extra study */ - } - /* make book become known even when spell is already - known, in case amnesia made you forget the book */ - makeknown((int)booktype); - } else { /* (spellid(i) == NO_SPELL) */ - /* for a normal book, spestudied will be zero, but for - a polymorphed one, spestudied will be non-zero and - one less reading is available than when re-learning */ - if (book->spestudied >= MAX_SPELL_STUDY) { - /* pre-used due to being the product of polymorph */ - pline("This spellbook is too faint to read even once."); - book->otyp = booktype = SPE_BLANK_PAPER; - /* reset spestudied as if polymorph had taken place */ - book->spestudied = rn2(book->spestudied); - } else { - spl_book[i].sp_id = booktype; - spl_book[i].sp_lev = objects[booktype].oc_level; - incrnknow(i, 1); - book->spestudied++; - You(i > 0 ? "add %s to your repertoire." : "learn %s.", - splname); - } - makeknown((int)booktype); - } + if (i == MAXSPELL) { + impossible("Too many spells memorized!"); + } else if (spellid(i) == booktype) { + /* normal book can be read and re-read a total of 4 times */ + if (book->spestudied > MAX_SPELL_STUDY) { + pline("This spellbook is too faint to be read any more."); + book->otyp = booktype = SPE_BLANK_PAPER; + /* reset spestudied as if polymorph had taken place */ + book->spestudied = rn2(book->spestudied); + } else if (spellknow(i) > KEEN / 10) { + You("know %s quite well already.", splname); + costly = FALSE; + } else { /* spellknow(i) <= KEEN/10 */ + Your("knowledge of %s is %s.", splname, + spellknow(i) ? "keener" : "restored"); + incrnknow(i, 1); + book->spestudied++; + exercise(A_WIS, TRUE); /* extra study */ + } + /* make book become known even when spell is already + known, in case amnesia made you forget the book */ + makeknown((int) booktype); + } else { /* (spellid(i) == NO_SPELL) */ + /* for a normal book, spestudied will be zero, but for + a polymorphed one, spestudied will be non-zero and + one less reading is available than when re-learning */ + if (book->spestudied >= MAX_SPELL_STUDY) { + /* pre-used due to being the product of polymorph */ + pline("This spellbook is too faint to read even once."); + book->otyp = booktype = SPE_BLANK_PAPER; + /* reset spestudied as if polymorph had taken place */ + book->spestudied = rn2(book->spestudied); + } else { + spl_book[i].sp_id = booktype; + spl_book[i].sp_lev = objects[booktype].oc_level; + incrnknow(i, 1); + book->spestudied++; + You(i > 0 ? "add %s to your repertoire." : "learn %s.", splname); + } + makeknown((int) booktype); + } - if (book->cursed) { /* maybe a demon cursed it */ - if (cursed_book(book)) { - useup(book); - context.spbook.book = 0; - context.spbook.o_id = 0; - return 0; - } - } - if (costly) check_unpaid(book); - context.spbook.book = 0; - context.spbook.o_id = 0; - return(0); + if (book->cursed) { /* maybe a demon cursed it */ + if (cursed_book(book)) { + useup(book); + context.spbook.book = 0; + context.spbook.o_id = 0; + return 0; + } + } + if (costly) + check_unpaid(book); + context.spbook.book = 0; + context.spbook.o_id = 0; + return (0); } int study_book(spellbook) register struct obj *spellbook; { - int booktype = spellbook->otyp; - boolean confused = (Confusion != 0); - boolean too_hard = FALSE; + int booktype = spellbook->otyp; + boolean confused = (Confusion != 0); + boolean too_hard = FALSE; - /* attempting to read dull book may make hero fall asleep */ - if (!confused && booktype != SPE_BLANK_PAPER && - !strcmp(OBJ_DESCR(objects[booktype]), "dull")) { - const char *eyes; - int dullbook = rnd(25) - ACURR(A_WIS); + /* attempting to read dull book may make hero fall asleep */ + if (!confused && booktype != SPE_BLANK_PAPER + && !strcmp(OBJ_DESCR(objects[booktype]), "dull")) { + const char *eyes; + int dullbook = rnd(25) - ACURR(A_WIS); - /* adjust chance if hero stayed awake, got interrupted, retries */ - if (context.spbook.delay && spellbook == context.spbook.book) - dullbook -= rnd(objects[booktype].oc_level); + /* adjust chance if hero stayed awake, got interrupted, retries */ + if (context.spbook.delay && spellbook == context.spbook.book) + dullbook -= rnd(objects[booktype].oc_level); - if (dullbook > 0) { - eyes = body_part(EYE); - if (eyecount(youmonst.data) > 1) eyes = makeplural(eyes); - pline("This book is so dull that you can't keep your %s open.", - eyes); - dullbook += rnd(2 * objects[booktype].oc_level); - fall_asleep(-dullbook, TRUE); - return 1; - } - } + if (dullbook > 0) { + eyes = body_part(EYE); + if (eyecount(youmonst.data) > 1) + eyes = makeplural(eyes); + pline("This book is so dull that you can't keep your %s open.", + eyes); + dullbook += rnd(2 * objects[booktype].oc_level); + fall_asleep(-dullbook, TRUE); + return 1; + } + } - if (context.spbook.delay && !confused && spellbook == context.spbook.book && - /* handle the sequence: start reading, get interrupted, - have context.spbook.book become erased somehow, resume reading it */ - booktype != SPE_BLANK_PAPER) { - You("continue your efforts to %s.", (booktype == SPE_NOVEL) ? - "read the novel" : "memorize the spell"); - } else { - /* KMH -- Simplified this code */ - if (booktype == SPE_BLANK_PAPER) { - pline("This spellbook is all blank."); - makeknown(booktype); - return(1); - } + if (context.spbook.delay && !confused && spellbook == context.spbook.book + && + /* handle the sequence: start reading, get interrupted, + have context.spbook.book become erased somehow, resume reading it + */ + booktype != SPE_BLANK_PAPER) { + You("continue your efforts to %s.", (booktype == SPE_NOVEL) + ? "read the novel" + : "memorize the spell"); + } else { + /* KMH -- Simplified this code */ + if (booktype == SPE_BLANK_PAPER) { + pline("This spellbook is all blank."); + makeknown(booktype); + return (1); + } - /* 3.6.0 tribute */ - if (booktype == SPE_NOVEL) { - /* Obtain current Terry Pratchett book title */ - const char *tribtitle = noveltitle(&spellbook->novelidx); - if (read_tribute("books", tribtitle, 0)) { - u.uconduct.literate++; - check_unpaid(spellbook); - if (!u.uevent.read_tribute) { - /* give bonus of 20 xp and 4*20+0 pts */ - more_experienced(20, 0); - newexplevel(); - u.uevent.read_tribute = 1; /* only once */ - } - } - return(1); - } + /* 3.6.0 tribute */ + if (booktype == SPE_NOVEL) { + /* Obtain current Terry Pratchett book title */ + const char *tribtitle = noveltitle(&spellbook->novelidx); + if (read_tribute("books", tribtitle, 0)) { + u.uconduct.literate++; + check_unpaid(spellbook); + if (!u.uevent.read_tribute) { + /* give bonus of 20 xp and 4*20+0 pts */ + more_experienced(20, 0); + newexplevel(); + u.uevent.read_tribute = 1; /* only once */ + } + } + return (1); + } - switch (objects[booktype].oc_level) { - case 1: - case 2: - context.spbook.delay = -objects[booktype].oc_delay; - break; - case 3: - case 4: - context.spbook.delay = -(objects[booktype].oc_level - 1) * - objects[booktype].oc_delay; - break; - case 5: - case 6: - context.spbook.delay = -objects[booktype].oc_level * - objects[booktype].oc_delay; - break; - case 7: - context.spbook.delay = -8 * objects[booktype].oc_delay; - break; - default: - impossible("Unknown spellbook level %d, book %d;", - objects[booktype].oc_level, booktype); - return 0; - } + switch (objects[booktype].oc_level) { + case 1: + case 2: + context.spbook.delay = -objects[booktype].oc_delay; + break; + case 3: + case 4: + context.spbook.delay = -(objects[booktype].oc_level - 1) + * objects[booktype].oc_delay; + break; + case 5: + case 6: + context.spbook.delay = + -objects[booktype].oc_level * objects[booktype].oc_delay; + break; + case 7: + context.spbook.delay = -8 * objects[booktype].oc_delay; + break; + default: + impossible("Unknown spellbook level %d, book %d;", + objects[booktype].oc_level, booktype); + return 0; + } - /* Books are often wiser than their readers (Rus.) */ - spellbook->in_use = TRUE; - if (!spellbook->blessed && - spellbook->otyp != SPE_BOOK_OF_THE_DEAD) { - if (spellbook->cursed) { - too_hard = TRUE; - } else { - /* uncursed - chance to fail */ - int read_ability = ACURR(A_INT) + 4 + u.ulevel/2 - - 2*objects[booktype].oc_level - + ((ublindf && ublindf->otyp == LENSES) ? 2 : 0); - /* only wizards know if a spell is too difficult */ - if (Role_if(PM_WIZARD) && read_ability < 20 && - !confused) { - char qbuf[QBUFSZ]; - Sprintf(qbuf, - "This spellbook is %sdifficult to comprehend. Continue?", - (read_ability < 12 ? "very " : "")); - if (yn(qbuf) != 'y') { - spellbook->in_use = FALSE; - return(1); - } - } - /* its up to random luck now */ - if (rnd(20) > read_ability) { - too_hard = TRUE; - } - } - } + /* Books are often wiser than their readers (Rus.) */ + spellbook->in_use = TRUE; + if (!spellbook->blessed && spellbook->otyp != SPE_BOOK_OF_THE_DEAD) { + if (spellbook->cursed) { + too_hard = TRUE; + } else { + /* uncursed - chance to fail */ + int read_ability = + ACURR(A_INT) + 4 + u.ulevel / 2 + - 2 * objects[booktype].oc_level + + ((ublindf && ublindf->otyp == LENSES) ? 2 : 0); + /* only wizards know if a spell is too difficult */ + if (Role_if(PM_WIZARD) && read_ability < 20 && !confused) { + char qbuf[QBUFSZ]; + Sprintf(qbuf, "This spellbook is %sdifficult to " + "comprehend. Continue?", + (read_ability < 12 ? "very " : "")); + if (yn(qbuf) != 'y') { + spellbook->in_use = FALSE; + return (1); + } + } + /* its up to random luck now */ + if (rnd(20) > read_ability) { + too_hard = TRUE; + } + } + } - if (too_hard) { - boolean gone = cursed_book(spellbook); + if (too_hard) { + boolean gone = cursed_book(spellbook); - nomul(context.spbook.delay); /* study time */ - multi_reason = "reading a book"; - nomovemsg = 0; - context.spbook.delay = 0; - if(gone || !rn2(3)) { - if (!gone) pline_The("spellbook crumbles to dust!"); - if (!objects[spellbook->otyp].oc_name_known && - !objects[spellbook->otyp].oc_uname) - docall(spellbook); - useup(spellbook); - } else - spellbook->in_use = FALSE; - return(1); - } else if (confused) { - if (!confused_book(spellbook)) { - spellbook->in_use = FALSE; - } - nomul(context.spbook.delay); - multi_reason = "reading a book"; - nomovemsg = 0; - context.spbook.delay = 0; - return(1); - } - spellbook->in_use = FALSE; + nomul(context.spbook.delay); /* study time */ + multi_reason = "reading a book"; + nomovemsg = 0; + context.spbook.delay = 0; + if (gone || !rn2(3)) { + if (!gone) + pline_The("spellbook crumbles to dust!"); + if (!objects[spellbook->otyp].oc_name_known + && !objects[spellbook->otyp].oc_uname) + docall(spellbook); + useup(spellbook); + } else + spellbook->in_use = FALSE; + return (1); + } else if (confused) { + if (!confused_book(spellbook)) { + spellbook->in_use = FALSE; + } + nomul(context.spbook.delay); + multi_reason = "reading a book"; + nomovemsg = 0; + context.spbook.delay = 0; + return (1); + } + spellbook->in_use = FALSE; - You("begin to %s the runes.", - spellbook->otyp == SPE_BOOK_OF_THE_DEAD ? "recite" : - "memorize"); - } + You("begin to %s the runes.", + spellbook->otyp == SPE_BOOK_OF_THE_DEAD ? "recite" : "memorize"); + } - context.spbook.book = spellbook; - if (context.spbook.book) - context.spbook.o_id = context.spbook.book->o_id; - set_occupation(learn, "studying", 0); - return(1); + context.spbook.book = spellbook; + if (context.spbook.book) + context.spbook.o_id = context.spbook.book->o_id; + set_occupation(learn, "studying", 0); + return (1); } /* a spellbook has been destroyed or the character has changed levels; @@ -567,10 +586,10 @@ void book_disappears(obj) struct obj *obj; { - if (obj == context.spbook.book) { - context.spbook.book = (struct obj *)0; - context.spbook.o_id = 0; - } + if (obj == context.spbook.book) { + context.spbook.book = (struct obj *) 0; + context.spbook.o_id = 0; + } } /* renaming an object usually results in it having a different address; @@ -580,28 +599,28 @@ void book_substitution(old_obj, new_obj) struct obj *old_obj, *new_obj; { - if (old_obj == context.spbook.book) { - context.spbook.book = new_obj; - if (context.spbook.book) - context.spbook.o_id = context.spbook.book->o_id; - } + if (old_obj == context.spbook.book) { + context.spbook.book = new_obj; + if (context.spbook.book) + context.spbook.o_id = context.spbook.book->o_id; + } } /* called from moveloop() */ void age_spells() { - int i; - /* - * The time relative to the hero (a pass through move - * loop) causes all spell knowledge to be decremented. - * The hero's speed, rest status, conscious status etc. - * does not alter the loss of memory. - */ - for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) - if (spellknow(i)) - decrnknow(i); - return; + int i; + /* + * The time relative to the hero (a pass through move + * loop) causes all spell knowledge to be decremented. + * The hero's speed, rest status, conscious status etc. + * does not alter the loss of memory. + */ + for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) + if (spellknow(i)) + decrnknow(i); + return; } /* @@ -610,159 +629,169 @@ age_spells() */ STATIC_OVL boolean getspell(spell_no) - int *spell_no; +int *spell_no; { - int nspells, idx; - char ilet, lets[BUFSZ], qbuf[QBUFSZ]; + int nspells, idx; + char ilet, lets[BUFSZ], qbuf[QBUFSZ]; - if (spellid(0) == NO_SPELL) { - You("don't know any spells right now."); - return FALSE; - } - if (flags.menu_style == MENU_TRADITIONAL) { - /* we know there is at least 1 known spell */ - for (nspells = 1; nspells < MAXSPELL - && spellid(nspells) != NO_SPELL; nspells++) - continue; + if (spellid(0) == NO_SPELL) { + You("don't know any spells right now."); + return FALSE; + } + if (flags.menu_style == MENU_TRADITIONAL) { + /* we know there is at least 1 known spell */ + for (nspells = 1; nspells < MAXSPELL && spellid(nspells) != NO_SPELL; + nspells++) + continue; - if (nspells == 1) Strcpy(lets, "a"); - else if (nspells < 27) Sprintf(lets, "a-%c", 'a' + nspells - 1); - else if (nspells == 27) Sprintf(lets, "a-zA"); - /* this assumes that there are at most 52 spells... */ - else Sprintf(lets, "a-zA-%c", 'A' + nspells - 27); + if (nspells == 1) + Strcpy(lets, "a"); + else if (nspells < 27) + Sprintf(lets, "a-%c", 'a' + nspells - 1); + else if (nspells == 27) + Sprintf(lets, "a-zA"); + /* this assumes that there are at most 52 spells... */ + else + Sprintf(lets, "a-zA-%c", 'A' + nspells - 27); - for (;;) { - Sprintf(qbuf, "Cast which spell? [%s *?]", lets); - ilet = yn_function(qbuf, (char *)0, '\0'); - if (ilet == '*' || ilet == '?') - break; /* use menu mode */ - if (index(quitchars, ilet)) - return FALSE; + for (;;) { + Sprintf(qbuf, "Cast which spell? [%s *?]", lets); + ilet = yn_function(qbuf, (char *) 0, '\0'); + if (ilet == '*' || ilet == '?') + break; /* use menu mode */ + if (index(quitchars, ilet)) + return FALSE; - idx = spell_let_to_idx(ilet); - if (idx < 0 || idx >= nspells) { - You("don't know that spell."); - continue; /* ask again */ - } - *spell_no = idx; - return TRUE; - } - } - return dospellmenu("Choose which spell to cast", - SPELLMENU_CAST, spell_no); + idx = spell_let_to_idx(ilet); + if (idx < 0 || idx >= nspells) { + You("don't know that spell."); + continue; /* ask again */ + } + *spell_no = idx; + return TRUE; + } + } + return dospellmenu("Choose which spell to cast", SPELLMENU_CAST, + spell_no); } /* the 'Z' command -- cast a spell */ int docast() { - int spell_no; + int spell_no; - if (getspell(&spell_no)) - return spelleffects(spell_no, FALSE); - return 0; + if (getspell(&spell_no)) + return spelleffects(spell_no, FALSE); + return 0; } STATIC_OVL const char * spelltypemnemonic(skill) int skill; { - switch (skill) { - case P_ATTACK_SPELL: - return "attack"; - case P_HEALING_SPELL: - return "healing"; - case P_DIVINATION_SPELL: - return "divination"; - case P_ENCHANTMENT_SPELL: - return "enchantment"; - case P_CLERIC_SPELL: - return "clerical"; - case P_ESCAPE_SPELL: - return "escape"; - case P_MATTER_SPELL: - return "matter"; - default: - impossible("Unknown spell skill, %d;", skill); - return ""; - } + switch (skill) { + case P_ATTACK_SPELL: + return "attack"; + case P_HEALING_SPELL: + return "healing"; + case P_DIVINATION_SPELL: + return "divination"; + case P_ENCHANTMENT_SPELL: + return "enchantment"; + case P_CLERIC_SPELL: + return "clerical"; + case P_ESCAPE_SPELL: + return "escape"; + case P_MATTER_SPELL: + return "matter"; + default: + impossible("Unknown spell skill, %d;", skill); + return ""; + } } int spell_skilltype(booktype) int booktype; { - return (objects[booktype].oc_skill); + return (objects[booktype].oc_skill); } STATIC_OVL void cast_protection() { - int loglev = 0; - int l = u.ulevel; - int natac = u.uac - u.uspellprot; - int gain; + int loglev = 0; + int l = u.ulevel; + int natac = u.uac - u.uspellprot; + int gain; - /* loglev=log2(u.ulevel)+1 (1..5) */ - while (l) { - loglev++; - l /= 2; - } + /* loglev=log2(u.ulevel)+1 (1..5) */ + while (l) { + loglev++; + l /= 2; + } - /* The more u.uspellprot you already have, the less you get, - * and the better your natural ac, the less you get. - * - * LEVEL AC SPELLPROT from sucessive SPE_PROTECTION casts - * 1 10 0, 1, 2, 3, 4 - * 1 0 0, 1, 2, 3 - * 1 -10 0, 1, 2 - * 2-3 10 0, 2, 4, 5, 6, 7, 8 - * 2-3 0 0, 2, 4, 5, 6 - * 2-3 -10 0, 2, 3, 4 - * 4-7 10 0, 3, 6, 8, 9, 10, 11, 12 - * 4-7 0 0, 3, 5, 7, 8, 9 - * 4-7 -10 0, 3, 5, 6 - * 7-15 -10 0, 3, 5, 6 - * 8-15 10 0, 4, 7, 10, 12, 13, 14, 15, 16 - * 8-15 0 0, 4, 7, 9, 10, 11, 12 - * 8-15 -10 0, 4, 6, 7, 8 - * 16-30 10 0, 5, 9, 12, 14, 16, 17, 18, 19, 20 - * 16-30 0 0, 5, 9, 11, 13, 14, 15 - * 16-30 -10 0, 5, 8, 9, 10 - */ - gain = loglev - (int)u.uspellprot / (4 - min(3,(10 - natac)/10)); + /* The more u.uspellprot you already have, the less you get, + * and the better your natural ac, the less you get. + * + * LEVEL AC SPELLPROT from sucessive SPE_PROTECTION casts + * 1 10 0, 1, 2, 3, 4 + * 1 0 0, 1, 2, 3 + * 1 -10 0, 1, 2 + * 2-3 10 0, 2, 4, 5, 6, 7, 8 + * 2-3 0 0, 2, 4, 5, 6 + * 2-3 -10 0, 2, 3, 4 + * 4-7 10 0, 3, 6, 8, 9, 10, 11, 12 + * 4-7 0 0, 3, 5, 7, 8, 9 + * 4-7 -10 0, 3, 5, 6 + * 7-15 -10 0, 3, 5, 6 + * 8-15 10 0, 4, 7, 10, 12, 13, 14, 15, 16 + * 8-15 0 0, 4, 7, 9, 10, 11, 12 + * 8-15 -10 0, 4, 6, 7, 8 + * 16-30 10 0, 5, 9, 12, 14, 16, 17, 18, 19, 20 + * 16-30 0 0, 5, 9, 11, 13, 14, 15 + * 16-30 -10 0, 5, 8, 9, 10 + */ + gain = loglev - (int) u.uspellprot / (4 - min(3, (10 - natac) / 10)); - if (gain > 0) { - if (!Blind) { - int rmtyp; - const char *hgolden = hcolor(NH_GOLDEN), *atmosphere; + if (gain > 0) { + if (!Blind) { + int rmtyp; + const char *hgolden = hcolor(NH_GOLDEN), *atmosphere; - if (u.uspellprot) { - pline_The("%s haze around you becomes more dense.", - hgolden); - } else { - rmtyp = levl[u.ux][u.uy].typ; - atmosphere = u.uswallow ? - ((u.ustuck->data == &mons[PM_FOG_CLOUD]) ? "mist" : - is_whirly(u.ustuck->data) ? "maelstrom" : - is_animal(u.ustuck->data) ? "maw" : "ooze") : - u.uinwater ? "water" : - (rmtyp == CLOUD) ? "cloud" : - IS_TREE(rmtyp) ? "vegitation" : - IS_STWALL(rmtyp) ? "stone" : "air"; - pline_The("%s around you begins to shimmer with %s haze.", - atmosphere, an(hgolden)); - } - } - u.uspellprot += gain; - u.uspmtime = - P_SKILL(spell_skilltype(SPE_PROTECTION)) == P_EXPERT ? 20 : 10; - if (!u.usptime) - u.usptime = u.uspmtime; - find_ac(); - } else { - Your("skin feels warm for a moment."); - } + if (u.uspellprot) { + pline_The("%s haze around you becomes more dense.", hgolden); + } else { + rmtyp = levl[u.ux][u.uy].typ; + atmosphere = + u.uswallow + ? ((u.ustuck->data == &mons[PM_FOG_CLOUD]) + ? "mist" + : is_whirly(u.ustuck->data) + ? "maelstrom" + : is_animal(u.ustuck->data) ? "maw" + : "ooze") + : u.uinwater ? "water" : (rmtyp == CLOUD) + ? "cloud" + : IS_TREE(rmtyp) + ? "vegitation" + : IS_STWALL(rmtyp) + ? "stone" + : "air"; + pline_The("%s around you begins to shimmer with %s haze.", + atmosphere, an(hgolden)); + } + } + u.uspellprot += gain; + u.uspmtime = + P_SKILL(spell_skilltype(SPE_PROTECTION)) == P_EXPERT ? 20 : 10; + if (!u.usptime) + u.usptime = u.uspmtime; + find_ac(); + } else { + Your("skin feels warm for a moment."); + } } /* attempting to cast a forgotten spell will cause disorientation */ @@ -770,26 +799,30 @@ STATIC_OVL void spell_backfire(spell) int spell; { - long duration = (long)((spellev(spell) + 1) * 3); /* 6..24 */ + long duration = (long) ((spellev(spell) + 1) * 3); /* 6..24 */ /* prior to 3.4.1, the only effect was confusion; it still predominates */ switch (rn2(10)) { case 0: case 1: case 2: - case 3: make_confused(duration, FALSE); /* 40% */ - break; + case 3: + make_confused(duration, FALSE); /* 40% */ + break; case 4: case 5: - case 6: make_confused(2L * duration / 3L, FALSE); /* 30% */ - make_stunned(duration / 3L, FALSE); - break; + case 6: + make_confused(2L * duration / 3L, FALSE); /* 30% */ + make_stunned(duration / 3L, FALSE); + break; case 7: - case 8: make_stunned(2L * duration / 3L, FALSE); /* 20% */ - make_confused(duration / 3L, FALSE); - break; - case 9: make_stunned(duration, FALSE); /* 10% */ - break; + case 8: + make_stunned(2L * duration / 3L, FALSE); /* 20% */ + make_confused(duration / 3L, FALSE); + break; + case 9: + make_stunned(duration, FALSE); /* 10% */ + break; } return; } @@ -799,297 +832,322 @@ spelleffects(spell, atme) int spell; boolean atme; { - int energy, damage, chance, n, intell; - int skill, role_skill; - boolean confused = (Confusion != 0); - boolean physical_damage = FALSE; - struct obj *pseudo; - coord cc; + int energy, damage, chance, n, intell; + int skill, role_skill; + boolean confused = (Confusion != 0); + boolean physical_damage = FALSE; + struct obj *pseudo; + coord cc; - /* - * Spell casting no longer affects knowledge of the spell. A - * decrement of spell knowledge is done every turn. - */ - if (spellknow(spell) <= 0) { - Your("knowledge of this spell is twisted."); - pline("It invokes nightmarish images in your mind..."); - spell_backfire(spell); - return(0); - } else if (spellknow(spell) <= KEEN / 200) { /* 100 turns left */ - You("strain to recall the spell."); - } else if (spellknow(spell) <= KEEN / 40) { /* 500 turns left */ - You("have difficulty remembering the spell."); - } else if (spellknow(spell) <= KEEN / 20) { /* 1000 turns left */ - Your("knowledge of this spell is growing faint."); - } else if (spellknow(spell) <= KEEN / 10) { /* 2000 turns left */ - Your("recall of this spell is gradually fading."); - } - energy = (spellev(spell) * 5); /* 5 <= energy <= 35 */ + /* + * Spell casting no longer affects knowledge of the spell. A + * decrement of spell knowledge is done every turn. + */ + if (spellknow(spell) <= 0) { + Your("knowledge of this spell is twisted."); + pline("It invokes nightmarish images in your mind..."); + spell_backfire(spell); + return (0); + } else if (spellknow(spell) <= KEEN / 200) { /* 100 turns left */ + You("strain to recall the spell."); + } else if (spellknow(spell) <= KEEN / 40) { /* 500 turns left */ + You("have difficulty remembering the spell."); + } else if (spellknow(spell) <= KEEN / 20) { /* 1000 turns left */ + Your("knowledge of this spell is growing faint."); + } else if (spellknow(spell) <= KEEN / 10) { /* 2000 turns left */ + Your("recall of this spell is gradually fading."); + } + energy = (spellev(spell) * 5); /* 5 <= energy <= 35 */ - if (u.uhunger <= 10 && spellid(spell) != SPE_DETECT_FOOD) { - You("are too hungry to cast that spell."); - return(0); - } else if (ACURR(A_STR) < 4 && spellid(spell) != SPE_RESTORE_ABILITY) { - You("lack the strength to cast spells."); - return(0); - } else if(check_capacity( - "Your concentration falters while carrying so much stuff.")) { - return (1); - } else if (!freehand()) { - Your("arms are not free to cast!"); - return (0); - } + if (u.uhunger <= 10 && spellid(spell) != SPE_DETECT_FOOD) { + You("are too hungry to cast that spell."); + return (0); + } else if (ACURR(A_STR) < 4 && spellid(spell) != SPE_RESTORE_ABILITY) { + You("lack the strength to cast spells."); + return (0); + } else if (check_capacity("Your concentration falters while carrying so " + "much stuff.")) { + return (1); + } else if (!freehand()) { + Your("arms are not free to cast!"); + return (0); + } - if (u.uhave.amulet) { - You_feel("the amulet draining your energy away."); - energy += rnd(2*energy); - } - if(energy > u.uen) { - You("don't have enough energy to cast that spell."); - return(0); - } else { - if (spellid(spell) != SPE_DETECT_FOOD) { - int hungr = energy * 2; + if (u.uhave.amulet) { + You_feel("the amulet draining your energy away."); + energy += rnd(2 * energy); + } + if (energy > u.uen) { + You("don't have enough energy to cast that spell."); + return (0); + } else { + if (spellid(spell) != SPE_DETECT_FOOD) { + int hungr = energy * 2; - /* If hero is a wizard, their current intelligence - * (bonuses + temporary + current) - * affects hunger reduction in casting a spell. - * 1. int = 17-18 no reduction - * 2. int = 16 1/4 hungr - * 3. int = 15 1/2 hungr - * 4. int = 1-14 normal reduction - * The reason for this is: - * a) Intelligence affects the amount of exertion - * in thinking. - * b) Wizards have spent their life at magic and - * understand quite well how to cast spells. - */ - intell = acurr(A_INT); - if (!Role_if(PM_WIZARD)) intell = 10; - switch (intell) { - case 25: case 24: case 23: case 22: - case 21: case 20: case 19: case 18: - case 17: hungr = 0; break; - case 16: hungr /= 4; break; - case 15: hungr /= 2; break; - } - /* don't put player (quite) into fainting from - * casting a spell, particularly since they might - * not even be hungry at the beginning; however, - * this is low enough that they must eat before - * casting anything else except detect food - */ - if (hungr > u.uhunger-3) - hungr = u.uhunger-3; - morehungry(hungr); - } - } + /* If hero is a wizard, their current intelligence + * (bonuses + temporary + current) + * affects hunger reduction in casting a spell. + * 1. int = 17-18 no reduction + * 2. int = 16 1/4 hungr + * 3. int = 15 1/2 hungr + * 4. int = 1-14 normal reduction + * The reason for this is: + * a) Intelligence affects the amount of exertion + * in thinking. + * b) Wizards have spent their life at magic and + * understand quite well how to cast spells. + */ + intell = acurr(A_INT); + if (!Role_if(PM_WIZARD)) + intell = 10; + switch (intell) { + case 25: + case 24: + case 23: + case 22: + case 21: + case 20: + case 19: + case 18: + case 17: + hungr = 0; + break; + case 16: + hungr /= 4; + break; + case 15: + hungr /= 2; + break; + } + /* don't put player (quite) into fainting from + * casting a spell, particularly since they might + * not even be hungry at the beginning; however, + * this is low enough that they must eat before + * casting anything else except detect food + */ + if (hungr > u.uhunger - 3) + hungr = u.uhunger - 3; + morehungry(hungr); + } + } - chance = percent_success(spell); - if (confused || (rnd(100) > chance)) { - You("fail to cast the spell correctly."); - u.uen -= energy / 2; - context.botl = 1; - return(1); - } + chance = percent_success(spell); + if (confused || (rnd(100) > chance)) { + You("fail to cast the spell correctly."); + u.uen -= energy / 2; + context.botl = 1; + return (1); + } - u.uen -= energy; - context.botl = 1; - exercise(A_WIS, TRUE); - /* pseudo is a temporary "false" object containing the spell stats */ - pseudo = mksobj(spellid(spell), FALSE, FALSE); - pseudo->blessed = pseudo->cursed = 0; - pseudo->quan = 20L; /* do not let useup get it */ - /* - * Find the skill the hero has in a spell type category. - * See spell_skilltype for categories. - */ - skill = spell_skilltype(pseudo->otyp); - role_skill = P_SKILL(skill); + u.uen -= energy; + context.botl = 1; + exercise(A_WIS, TRUE); + /* pseudo is a temporary "false" object containing the spell stats */ + pseudo = mksobj(spellid(spell), FALSE, FALSE); + pseudo->blessed = pseudo->cursed = 0; + pseudo->quan = 20L; /* do not let useup get it */ + /* + * Find the skill the hero has in a spell type category. + * See spell_skilltype for categories. + */ + skill = spell_skilltype(pseudo->otyp); + role_skill = P_SKILL(skill); - switch(pseudo->otyp) { - /* - * At first spells act as expected. As the hero increases in skill - * with the appropriate spell type, some spells increase in their - * effects, e.g. more damage, further distance, and so on, without - * additional cost to the spellcaster. - */ - case SPE_FIREBALL: - case SPE_CONE_OF_COLD: - if (role_skill >= P_SKILLED) { - if (throwspell()) { - cc.x=u.dx;cc.y=u.dy; - n=rnd(8)+1; - while(n--) { - if(!u.dx && !u.dy && !u.dz) { - if ((damage = zapyourself(pseudo, TRUE)) != 0) { - char buf[BUFSZ]; - Sprintf(buf, "zapped %sself with a spell", uhim()); - losehp(damage, buf, NO_KILLER_PREFIX); - } - } else { - explode(u.dx, u.dy, - pseudo->otyp - SPE_MAGIC_MISSILE + 10, - spell_damage_bonus(u.ulevel / 2 + 1), 0, - (pseudo->otyp == SPE_CONE_OF_COLD) ? - EXPL_FROSTY : EXPL_FIERY); - } - u.dx = cc.x+rnd(3)-2; u.dy = cc.y+rnd(3)-2; - if (!isok(u.dx,u.dy) || !cansee(u.dx,u.dy) || - IS_STWALL(levl[u.dx][u.dy].typ) || u.uswallow) { - /* Spell is reflected back to center */ - u.dx = cc.x; - u.dy = cc.y; - } - } - } - break; - } /* else fall through... */ + switch (pseudo->otyp) { + /* + * At first spells act as expected. As the hero increases in skill + * with the appropriate spell type, some spells increase in their + * effects, e.g. more damage, further distance, and so on, without + * additional cost to the spellcaster. + */ + case SPE_FIREBALL: + case SPE_CONE_OF_COLD: + if (role_skill >= P_SKILLED) { + if (throwspell()) { + cc.x = u.dx; + cc.y = u.dy; + n = rnd(8) + 1; + while (n--) { + if (!u.dx && !u.dy && !u.dz) { + if ((damage = zapyourself(pseudo, TRUE)) != 0) { + char buf[BUFSZ]; + Sprintf(buf, "zapped %sself with a spell", + uhim()); + losehp(damage, buf, NO_KILLER_PREFIX); + } + } else { + explode( + u.dx, u.dy, pseudo->otyp - SPE_MAGIC_MISSILE + 10, + spell_damage_bonus(u.ulevel / 2 + 1), 0, + (pseudo->otyp == SPE_CONE_OF_COLD) ? EXPL_FROSTY + : EXPL_FIERY); + } + u.dx = cc.x + rnd(3) - 2; + u.dy = cc.y + rnd(3) - 2; + if (!isok(u.dx, u.dy) || !cansee(u.dx, u.dy) + || IS_STWALL(levl[u.dx][u.dy].typ) || u.uswallow) { + /* Spell is reflected back to center */ + u.dx = cc.x; + u.dy = cc.y; + } + } + } + break; + } /* else fall through... */ - /* these spells are all duplicates of wand effects */ - case SPE_FORCE_BOLT: - physical_damage = TRUE; - /* fall through */ - case SPE_SLEEP: - case SPE_MAGIC_MISSILE: - case SPE_KNOCK: - case SPE_SLOW_MONSTER: - case SPE_WIZARD_LOCK: - case SPE_DIG: - case SPE_TURN_UNDEAD: - case SPE_POLYMORPH: - case SPE_TELEPORT_AWAY: - case SPE_CANCELLATION: - case SPE_FINGER_OF_DEATH: - case SPE_LIGHT: - case SPE_DETECT_UNSEEN: - case SPE_HEALING: - case SPE_EXTRA_HEALING: - case SPE_DRAIN_LIFE: - case SPE_STONE_TO_FLESH: - if (!(objects[pseudo->otyp].oc_dir == NODIR)) { - if (atme) u.dx = u.dy = u.dz = 0; - else if (!getdir((char *)0)) { - /* getdir cancelled, re-use previous direction */ - pline_The("magical energy is released!"); - } - if(!u.dx && !u.dy && !u.dz) { - if ((damage = zapyourself(pseudo, TRUE)) != 0) { - char buf[BUFSZ]; - Sprintf(buf, "zapped %sself with a spell", uhim()); - if (physical_damage) damage = Maybe_Half_Phys(damage); - losehp(damage, buf, NO_KILLER_PREFIX); - } - } else weffects(pseudo); - } else weffects(pseudo); - update_inventory(); /* spell may modify inventory */ - break; + /* these spells are all duplicates of wand effects */ + case SPE_FORCE_BOLT: + physical_damage = TRUE; + /* fall through */ + case SPE_SLEEP: + case SPE_MAGIC_MISSILE: + case SPE_KNOCK: + case SPE_SLOW_MONSTER: + case SPE_WIZARD_LOCK: + case SPE_DIG: + case SPE_TURN_UNDEAD: + case SPE_POLYMORPH: + case SPE_TELEPORT_AWAY: + case SPE_CANCELLATION: + case SPE_FINGER_OF_DEATH: + case SPE_LIGHT: + case SPE_DETECT_UNSEEN: + case SPE_HEALING: + case SPE_EXTRA_HEALING: + case SPE_DRAIN_LIFE: + case SPE_STONE_TO_FLESH: + if (!(objects[pseudo->otyp].oc_dir == NODIR)) { + if (atme) + u.dx = u.dy = u.dz = 0; + else if (!getdir((char *) 0)) { + /* getdir cancelled, re-use previous direction */ + pline_The("magical energy is released!"); + } + if (!u.dx && !u.dy && !u.dz) { + if ((damage = zapyourself(pseudo, TRUE)) != 0) { + char buf[BUFSZ]; + Sprintf(buf, "zapped %sself with a spell", uhim()); + if (physical_damage) + damage = Maybe_Half_Phys(damage); + losehp(damage, buf, NO_KILLER_PREFIX); + } + } else + weffects(pseudo); + } else + weffects(pseudo); + update_inventory(); /* spell may modify inventory */ + break; - /* these are all duplicates of scroll effects */ - case SPE_REMOVE_CURSE: - case SPE_CONFUSE_MONSTER: - case SPE_DETECT_FOOD: - case SPE_CAUSE_FEAR: - case SPE_IDENTIFY: - /* high skill yields effect equivalent to blessed scroll */ - if (role_skill >= P_SKILLED) pseudo->blessed = 1; - /* fall through */ - case SPE_CHARM_MONSTER: - case SPE_MAGIC_MAPPING: - case SPE_CREATE_MONSTER: - (void) seffects(pseudo); - break; + /* these are all duplicates of scroll effects */ + case SPE_REMOVE_CURSE: + case SPE_CONFUSE_MONSTER: + case SPE_DETECT_FOOD: + case SPE_CAUSE_FEAR: + case SPE_IDENTIFY: + /* high skill yields effect equivalent to blessed scroll */ + if (role_skill >= P_SKILLED) + pseudo->blessed = 1; + /* fall through */ + case SPE_CHARM_MONSTER: + case SPE_MAGIC_MAPPING: + case SPE_CREATE_MONSTER: + (void) seffects(pseudo); + break; - /* these are all duplicates of potion effects */ - case SPE_HASTE_SELF: - case SPE_DETECT_TREASURE: - case SPE_DETECT_MONSTERS: - case SPE_LEVITATION: - case SPE_RESTORE_ABILITY: - /* high skill yields effect equivalent to blessed potion */ - if (role_skill >= P_SKILLED) pseudo->blessed = 1; - /* fall through */ - case SPE_INVISIBILITY: - (void) peffects(pseudo); - break; + /* these are all duplicates of potion effects */ + case SPE_HASTE_SELF: + case SPE_DETECT_TREASURE: + case SPE_DETECT_MONSTERS: + case SPE_LEVITATION: + case SPE_RESTORE_ABILITY: + /* high skill yields effect equivalent to blessed potion */ + if (role_skill >= P_SKILLED) + pseudo->blessed = 1; + /* fall through */ + case SPE_INVISIBILITY: + (void) peffects(pseudo); + break; - case SPE_CURE_BLINDNESS: - healup(0, 0, FALSE, TRUE); - break; - case SPE_CURE_SICKNESS: - if (Sick) You("are no longer ill."); - if (Slimed) make_slimed(0L, "The slime disappears!"); - healup(0, 0, TRUE, FALSE); - break; - case SPE_CREATE_FAMILIAR: - (void) make_familiar((struct obj *)0, u.ux, u.uy, FALSE); - break; - case SPE_CLAIRVOYANCE: - if (!BClairvoyant) - do_vicinity_map(); - /* at present, only one thing blocks clairvoyance */ - else if (uarmh && uarmh->otyp == CORNUTHAUM) - You("sense a pointy hat on top of your %s.", - body_part(HEAD)); - break; - case SPE_PROTECTION: - cast_protection(); - break; - case SPE_JUMPING: - if (!jump(max(role_skill,1))) - pline1(nothing_happens); - break; - default: - impossible("Unknown spell %d attempted.", spell); - obfree(pseudo, (struct obj *)0); - return(0); - } + case SPE_CURE_BLINDNESS: + healup(0, 0, FALSE, TRUE); + break; + case SPE_CURE_SICKNESS: + if (Sick) + You("are no longer ill."); + if (Slimed) + make_slimed(0L, "The slime disappears!"); + healup(0, 0, TRUE, FALSE); + break; + case SPE_CREATE_FAMILIAR: + (void) make_familiar((struct obj *) 0, u.ux, u.uy, FALSE); + break; + case SPE_CLAIRVOYANCE: + if (!BClairvoyant) + do_vicinity_map(); + /* at present, only one thing blocks clairvoyance */ + else if (uarmh && uarmh->otyp == CORNUTHAUM) + You("sense a pointy hat on top of your %s.", body_part(HEAD)); + break; + case SPE_PROTECTION: + cast_protection(); + break; + case SPE_JUMPING: + if (!jump(max(role_skill, 1))) + pline1(nothing_happens); + break; + default: + impossible("Unknown spell %d attempted.", spell); + obfree(pseudo, (struct obj *) 0); + return (0); + } - /* gain skill for successful cast */ - use_skill(skill, spellev(spell)); + /* gain skill for successful cast */ + use_skill(skill, spellev(spell)); - obfree(pseudo, (struct obj *)0); /* now, get rid of it */ - return(1); + obfree(pseudo, (struct obj *) 0); /* now, get rid of it */ + return (1); } /* Choose location where spell takes effect. */ STATIC_OVL int throwspell() { - coord cc; - struct monst *mtmp; + coord cc; + struct monst *mtmp; - if (u.uinwater) { - pline("You're joking! In this weather?"); return 0; - } else if (Is_waterlevel(&u.uz)) { - You("had better wait for the sun to come out."); return 0; - } + if (u.uinwater) { + pline("You're joking! In this weather?"); + return 0; + } else if (Is_waterlevel(&u.uz)) { + You("had better wait for the sun to come out."); + return 0; + } - pline("Where do you want to cast the spell?"); - cc.x = u.ux; - cc.y = u.uy; - if (getpos(&cc, TRUE, "the desired position") < 0) - return 0; /* user pressed ESC */ - /* The number of moves from hero to where the spell drops.*/ - if (distmin(u.ux, u.uy, cc.x, cc.y) > 10) { - pline_The("spell dissipates over the distance!"); - return 0; - } else if (u.uswallow) { - pline_The("spell is cut short!"); - exercise(A_WIS, FALSE); /* What were you THINKING! */ - u.dx = 0; - u.dy = 0; - return 1; - } else if ((!cansee(cc.x, cc.y) && - (!(mtmp = m_at(cc.x, cc.y)) || !canspotmon(mtmp))) || - IS_STWALL(levl[cc.x][cc.y].typ)) { - Your("mind fails to lock onto that location!"); - return 0; - } + pline("Where do you want to cast the spell?"); + cc.x = u.ux; + cc.y = u.uy; + if (getpos(&cc, TRUE, "the desired position") < 0) + return 0; /* user pressed ESC */ + /* The number of moves from hero to where the spell drops.*/ + if (distmin(u.ux, u.uy, cc.x, cc.y) > 10) { + pline_The("spell dissipates over the distance!"); + return 0; + } else if (u.uswallow) { + pline_The("spell is cut short!"); + exercise(A_WIS, FALSE); /* What were you THINKING! */ + u.dx = 0; + u.dy = 0; + return 1; + } else if ((!cansee(cc.x, cc.y) + && (!(mtmp = m_at(cc.x, cc.y)) || !canspotmon(mtmp))) + || IS_STWALL(levl[cc.x][cc.y].typ)) { + Your("mind fails to lock onto that location!"); + return 0; + } - u.dx = cc.x; - u.dy = cc.y; - return 1; + u.dx = cc.x; + u.dy = cc.y; + return 1; } /* forget a random selection of known spells due to amnesia; @@ -1105,18 +1163,20 @@ losespells() context.spbook.o_id = 0; /* count the number of known spells */ for (n = 0; n < MAXSPELL; ++n) - if (spellid(n) == NO_SPELL) break; + if (spellid(n) == NO_SPELL) + break; /* lose anywhere from zero to all known spells; if confused, use the worse of two die rolls */ nzap = rn2(n + 1); if (Confusion) { - i = rn2(n + 1); - if (i > nzap) nzap = i; + i = rn2(n + 1); + if (i > nzap) + nzap = i; } /* good Luck might ameliorate spell loss */ if (nzap > 1 && !rnl(7)) - nzap = rnd(nzap); + nzap = rnd(nzap); /* * Forget 'nzap' out of 'n' known spells by setting their memory @@ -1141,22 +1201,22 @@ losespells() * the first lost spell would end up with new letter assigned.) */ for (i = 0; nzap > 0; ++i) { - /* when nzap is small relative to the number of spells left, - the chance to lose spell [i] is small; as the number of - remaining candidates shrinks, the chance per candidate - gets bigger; overall, exactly nzap entries are affected */ - if (rn2(n - i) < nzap) { - /* lose access to spell [i] */ - spellknow(i) = 0; + /* when nzap is small relative to the number of spells left, + the chance to lose spell [i] is small; as the number of + remaining candidates shrinks, the chance per candidate + gets bigger; overall, exactly nzap entries are affected */ + if (rn2(n - i) < nzap) { + /* lose access to spell [i] */ + spellknow(i) = 0; #if 0 /* also forget its book */ forget_single_object(spellid(i)); #endif - /* and abuse wisdom */ - exercise(A_WIS, FALSE); - /* there's now one less spell slated to be forgotten */ - --nzap; - } + /* and abuse wisdom */ + exercise(A_WIS, FALSE); + /* there's now one less spell slated to be forgotten */ + --nzap; + } } } @@ -1173,28 +1233,28 @@ losespells() * appended to the end of the list? */ static const char *spl_sortchoices[] = { - "by casting letter", -#define SORTBY_LETTER 0 - "alphabetically", -#define SORTBY_ALPHA 1 - "by level, low to high", -#define SORTBY_LVL_LO 2 - "by level, high to low", -#define SORTBY_LVL_HI 3 - "by skill group, alphabetized within each group", -#define SORTBY_SKL_AL 4 - "by skill group, low to high level within group", -#define SORTBY_SKL_LO 5 - "by skill group, high to low level within group", -#define SORTBY_SKL_HI 6 - "maintain current ordering", -#define SORTBY_CURRENT 7 - /* a menu choice rather than a sort choice */ - "reassign casting letters to retain current order", -#define SORTRETAINORDER 8 + "by casting letter", +#define SORTBY_LETTER 0 + "alphabetically", +#define SORTBY_ALPHA 1 + "by level, low to high", +#define SORTBY_LVL_LO 2 + "by level, high to low", +#define SORTBY_LVL_HI 3 + "by skill group, alphabetized within each group", +#define SORTBY_SKL_AL 4 + "by skill group, low to high level within group", +#define SORTBY_SKL_LO 5 + "by skill group, high to low level within group", +#define SORTBY_SKL_HI 6 + "maintain current ordering", +#define SORTBY_CURRENT 7 + /* a menu choice rather than a sort choice */ + "reassign casting letters to retain current order", +#define SORTRETAINORDER 8 }; -static int spl_sortmode = 0; /* index into spl_sortchoices[] */ -static int *spl_orderindx = 0; /* array of spl_book[] indices */ +static int spl_sortmode = 0; /* index into spl_sortchoices[] */ +static int *spl_orderindx = 0; /* array of spl_book[] indices */ /* qsort callback routine */ STATIC_PTR int CFDECLSPEC @@ -1210,40 +1270,47 @@ const genericptr vptr2; * levl? = spell level; * skil? = skill group aka spell class; */ - int indx1 = *(int *)vptr1, indx2 = *(int *)vptr2, - otyp1 = spl_book[indx1].sp_id, otyp2 = spl_book[indx2].sp_id, - levl1 = objects[otyp1].oc_level, levl2 = objects[otyp2].oc_level, - skil1 = objects[otyp1].oc_skill, skil2 = objects[otyp2].oc_skill; + int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2, + otyp1 = spl_book[indx1].sp_id, otyp2 = spl_book[indx2].sp_id, + levl1 = objects[otyp1].oc_level, levl2 = objects[otyp2].oc_level, + skil1 = objects[otyp1].oc_skill, skil2 = objects[otyp2].oc_skill; switch (spl_sortmode) { case SORTBY_LETTER: - return indx1 - indx2; + return indx1 - indx2; case SORTBY_ALPHA: - break; + break; case SORTBY_LVL_LO: - if (levl1 != levl2) return levl1 - levl2; - break; + if (levl1 != levl2) + return levl1 - levl2; + break; case SORTBY_LVL_HI: - if (levl1 != levl2) return levl2 - levl1; - break; + if (levl1 != levl2) + return levl2 - levl1; + break; case SORTBY_SKL_AL: - if (skil1 != skil2) return skil1 - skil2; - break; + if (skil1 != skil2) + return skil1 - skil2; + break; case SORTBY_SKL_LO: - if (skil1 != skil2) return skil1 - skil2; - if (levl1 != levl2) return levl1 - levl2; - break; + if (skil1 != skil2) + return skil1 - skil2; + if (levl1 != levl2) + return levl1 - levl2; + break; case SORTBY_SKL_HI: - if (skil1 != skil2) return skil1 - skil2; - if (levl1 != levl2) return levl2 - levl1; - break; + if (skil1 != skil2) + return skil1 - skil2; + if (levl1 != levl2) + return levl2 - levl1; + break; case SORTBY_CURRENT: default: - return (vptr1 < vptr2) ? -1 : (vptr1 > vptr2); /* keep current order */ + return (vptr1 < vptr2) ? -1 + : (vptr1 > vptr2); /* keep current order */ } /* tie-breaker for most sorts--alphabetical by spell name */ - return strcmpi(OBJ_NAME(objects[otyp1]), - OBJ_NAME(objects[otyp2])); + return strcmpi(OBJ_NAME(objects[otyp1]), OBJ_NAME(objects[otyp2])); } /* sort the index used for display order of the "view known spells" @@ -1259,35 +1326,40 @@ sortspells() int n; #endif - if (spl_sortmode == SORTBY_CURRENT) return; - for (n = 0; n < MAXSPELL && spellid(n) != NO_SPELL; ++n) continue; - if (n < 2) return; /* not enough entries to need sorting */ + if (spl_sortmode == SORTBY_CURRENT) + return; + for (n = 0; n < MAXSPELL && spellid(n) != NO_SPELL; ++n) + continue; + if (n < 2) + return; /* not enough entries to need sorting */ if (!spl_orderindx) { - /* we haven't done any sorting yet; list is in casting order */ - if (spl_sortmode == SORTBY_LETTER || /* default */ - spl_sortmode == SORTRETAINORDER) return; - /* allocate enough for full spellbook rather than just N spells */ - spl_orderindx = (int *)alloc(MAXSPELL * sizeof (int)); - for (i = 0; i < MAXSPELL; i++) spl_orderindx[i] = i; + /* we haven't done any sorting yet; list is in casting order */ + if (spl_sortmode == SORTBY_LETTER || /* default */ + spl_sortmode == SORTRETAINORDER) + return; + /* allocate enough for full spellbook rather than just N spells */ + spl_orderindx = (int *) alloc(MAXSPELL * sizeof(int)); + for (i = 0; i < MAXSPELL; i++) + spl_orderindx[i] = i; } if (spl_sortmode == SORTRETAINORDER) { - struct spell tmp_book[MAXSPELL]; + struct spell tmp_book[MAXSPELL]; - /* sort spl_book[] rather than spl_orderindx[]; - this also updates the index to reflect the new ordering (we - could just free it since that ordering becomes the default) */ - for (i = 0; i < MAXSPELL; i++) - tmp_book[i] = spl_book[spl_orderindx[i]]; - for (i = 0; i < MAXSPELL; i++) - spl_book[i] = tmp_book[i], spl_orderindx[i] = i; - spl_sortmode = SORTBY_LETTER; /* reset */ - return; + /* sort spl_book[] rather than spl_orderindx[]; + this also updates the index to reflect the new ordering (we + could just free it since that ordering becomes the default) */ + for (i = 0; i < MAXSPELL; i++) + tmp_book[i] = spl_book[spl_orderindx[i]]; + for (i = 0; i < MAXSPELL; i++) + spl_book[i] = tmp_book[i], spl_orderindx[i] = i; + spl_sortmode = SORTBY_LETTER; /* reset */ + return; } /* usual case, sort the index rather than the spells themselves */ - qsort((genericptr_t)spl_orderindx, n, sizeof *spl_orderindx, spell_cmp); + qsort((genericptr_t) spl_orderindx, n, sizeof *spl_orderindx, spell_cmp); return; } @@ -1303,34 +1375,34 @@ spellsortmenu() tmpwin = create_nhwindow(NHW_MENU); start_menu(tmpwin); - any = zeroany; /* zero out all bits */ + any = zeroany; /* zero out all bits */ for (i = 0; i < SIZE(spl_sortchoices); i++) { - if (i == SORTRETAINORDER) { - let = 'z'; /* assumes fewer than 26 sort choices... */ - /* separate final choice from others with a blank line */ - any.a_int = 0; - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", - MENU_UNSELECTED); - } else { - let = 'a' + i; - } - any.a_int = i + 1; - add_menu(tmpwin, NO_GLYPH, &any, let, 0, ATR_NONE, spl_sortchoices[i], - (i == spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); + if (i == SORTRETAINORDER) { + let = 'z'; /* assumes fewer than 26 sort choices... */ + /* separate final choice from others with a blank line */ + any.a_int = 0; + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", + MENU_UNSELECTED); + } else { + let = 'a' + i; + } + any.a_int = i + 1; + add_menu(tmpwin, NO_GLYPH, &any, let, 0, ATR_NONE, spl_sortchoices[i], + (i == spl_sortmode) ? MENU_SELECTED : MENU_UNSELECTED); } end_menu(tmpwin, "View known spells list sorted"); n = select_menu(tmpwin, PICK_ONE, &selected); destroy_nhwindow(tmpwin); if (n > 0) { - choice = selected[0].item.a_int - 1; - /* skip preselected entry if we have more than one item chosen */ - if (n > 1 && choice == spl_sortmode) - choice = selected[1].item.a_int - 1; - free((genericptr_t)selected); - spl_sortmode = choice; - return TRUE; + choice = selected[0].item.a_int - 1; + /* skip preselected entry if we have more than one item chosen */ + if (n > 1 && choice == spl_sortmode) + choice = selected[1].item.a_int - 1; + free((genericptr_t) selected); + spl_sortmode = choice; + return TRUE; } return FALSE; } @@ -1339,223 +1411,233 @@ spellsortmenu() int dovspell() { - char qbuf[QBUFSZ]; - int splnum, othnum; - struct spell spl_tmp; + char qbuf[QBUFSZ]; + int splnum, othnum; + struct spell spl_tmp; - if (spellid(0) == NO_SPELL) { - You("don't know any spells right now."); - } else { - while (dospellmenu("Currently known spells", - SPELLMENU_VIEW, &splnum)) { - if (splnum == SPELLMENU_SORT) { - if (spellsortmenu()) sortspells(); - } else { - Sprintf(qbuf, "Reordering spells; swap '%c' with", - spellet(splnum)); - if (!dospellmenu(qbuf, splnum, &othnum)) break; + if (spellid(0) == NO_SPELL) { + You("don't know any spells right now."); + } else { + while ( + dospellmenu("Currently known spells", SPELLMENU_VIEW, &splnum)) { + if (splnum == SPELLMENU_SORT) { + if (spellsortmenu()) + sortspells(); + } else { + Sprintf(qbuf, "Reordering spells; swap '%c' with", + spellet(splnum)); + if (!dospellmenu(qbuf, splnum, &othnum)) + break; - spl_tmp = spl_book[splnum]; - spl_book[splnum] = spl_book[othnum]; - spl_book[othnum] = spl_tmp; - } - } - } - if (spl_orderindx) { - free((genericptr_t)spl_orderindx); - spl_orderindx = 0; - } - spl_sortmode = SORTBY_LETTER; /* 0 */ - return 0; + spl_tmp = spl_book[splnum]; + spl_book[splnum] = spl_book[othnum]; + spl_book[othnum] = spl_tmp; + } + } + } + if (spl_orderindx) { + free((genericptr_t) spl_orderindx); + spl_orderindx = 0; + } + spl_sortmode = SORTBY_LETTER; /* 0 */ + return 0; } STATIC_OVL boolean dospellmenu(prompt, splaction, spell_no) const char *prompt; -int splaction; /* SPELLMENU_CAST, SPELLMENU_VIEW, or spl_book[] index */ +int splaction; /* SPELLMENU_CAST, SPELLMENU_VIEW, or spl_book[] index */ int *spell_no; { - winid tmpwin; - int i, n, how, splnum; - char buf[BUFSZ], retentionbuf[24]; - const char *fmt; - menu_item *selected; - anything any; + winid tmpwin; + int i, n, how, splnum; + char buf[BUFSZ], retentionbuf[24]; + const char *fmt; + menu_item *selected; + anything any; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; /* zero out all bits */ + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; /* zero out all bits */ - /* - * The correct spacing of the columns when not using - * tab separation depends on the following: - * (1) that the font is monospaced, and - * (2) that selection letters are pre-pended to the - * given string and are of the form "a - ". - */ - if (!iflags.menu_tab_sep) { - Sprintf(buf, "%-20s Level %-12s Fail Retention", - " Name", "Category"); - fmt = "%-20s %2d %-12s %3d%% %9s"; - } else { - Sprintf(buf, "Name\tLevel\tCategory\tFail\tRetention"); - fmt = "%s\t%-d\t%s\t%-d%%\t%s"; - } - add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, MENU_UNSELECTED); - for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) { - splnum = !spl_orderindx ? i : spl_orderindx[i]; - Sprintf(buf, fmt, - spellname(splnum), spellev(splnum), - spelltypemnemonic(spell_skilltype(spellid(splnum))), - 100 - percent_success(splnum), - spellretention(splnum, retentionbuf)); + /* + * The correct spacing of the columns when not using + * tab separation depends on the following: + * (1) that the font is monospaced, and + * (2) that selection letters are pre-pended to the + * given string and are of the form "a - ". + */ + if (!iflags.menu_tab_sep) { + Sprintf(buf, "%-20s Level %-12s Fail Retention", " Name", + "Category"); + fmt = "%-20s %2d %-12s %3d%% %9s"; + } else { + Sprintf(buf, "Name\tLevel\tCategory\tFail\tRetention"); + fmt = "%s\t%-d\t%s\t%-d%%\t%s"; + } + add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, + MENU_UNSELECTED); + for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) { + splnum = !spl_orderindx ? i : spl_orderindx[i]; + Sprintf(buf, fmt, spellname(splnum), spellev(splnum), + spelltypemnemonic(spell_skilltype(spellid(splnum))), + 100 - percent_success(splnum), + spellretention(splnum, retentionbuf)); - any.a_int = splnum + 1; /* must be non-zero */ - add_menu(tmpwin, NO_GLYPH, &any, - spellet(splnum), 0, ATR_NONE, buf, - (splnum == splaction) ? MENU_SELECTED : MENU_UNSELECTED); - } - how = PICK_ONE; - if (splaction == SPELLMENU_VIEW) { - if (spellid(1) == NO_SPELL) { - /* only one spell => nothing to swap with */ - how = PICK_NONE; - } else { - /* more than 1 spell, add an extra menu entry */ - any.a_int = SPELLMENU_SORT + 1; - add_menu(tmpwin, NO_GLYPH, &any, '+', 0, ATR_NONE, - "[sort spells]", MENU_UNSELECTED); - } - } - end_menu(tmpwin, prompt); + any.a_int = splnum + 1; /* must be non-zero */ + add_menu(tmpwin, NO_GLYPH, &any, spellet(splnum), 0, ATR_NONE, buf, + (splnum == splaction) ? MENU_SELECTED : MENU_UNSELECTED); + } + how = PICK_ONE; + if (splaction == SPELLMENU_VIEW) { + if (spellid(1) == NO_SPELL) { + /* only one spell => nothing to swap with */ + how = PICK_NONE; + } else { + /* more than 1 spell, add an extra menu entry */ + any.a_int = SPELLMENU_SORT + 1; + add_menu(tmpwin, NO_GLYPH, &any, '+', 0, ATR_NONE, + "[sort spells]", MENU_UNSELECTED); + } + } + end_menu(tmpwin, prompt); - n = select_menu(tmpwin, how, &selected); - destroy_nhwindow(tmpwin); - if (n > 0) { - *spell_no = selected[0].item.a_int - 1; - /* menu selection for `PICK_ONE' does not - de-select any preselected entry */ - if (n > 1 && *spell_no == splaction) - *spell_no = selected[1].item.a_int - 1; - free((genericptr_t)selected); - /* default selection of preselected spell means that - user chose not to swap it with anything */ - if (*spell_no == splaction) return FALSE; - return TRUE; - } else if (splaction >= 0) { - /* explicit de-selection of preselected spell means that - user is still swapping but not for the current spell */ - *spell_no = splaction; - return TRUE; - } - return FALSE; + n = select_menu(tmpwin, how, &selected); + destroy_nhwindow(tmpwin); + if (n > 0) { + *spell_no = selected[0].item.a_int - 1; + /* menu selection for `PICK_ONE' does not + de-select any preselected entry */ + if (n > 1 && *spell_no == splaction) + *spell_no = selected[1].item.a_int - 1; + free((genericptr_t) selected); + /* default selection of preselected spell means that + user chose not to swap it with anything */ + if (*spell_no == splaction) + return FALSE; + return TRUE; + } else if (splaction >= 0) { + /* explicit de-selection of preselected spell means that + user is still swapping but not for the current spell */ + *spell_no = splaction; + return TRUE; + } + return FALSE; } STATIC_OVL int percent_success(spell) int spell; { - /* Intrinsic and learned ability are combined to calculate - * the probability of player's success at cast a given spell. - */ - int chance, splcaster, special, statused; - int difficulty; - int skill; + /* Intrinsic and learned ability are combined to calculate + * the probability of player's success at cast a given spell. + */ + int chance, splcaster, special, statused; + int difficulty; + int skill; - /* Calculate intrinsic ability (splcaster) */ + /* Calculate intrinsic ability (splcaster) */ - splcaster = urole.spelbase; - special = urole.spelheal; - statused = ACURR(urole.spelstat); + splcaster = urole.spelbase; + special = urole.spelheal; + statused = ACURR(urole.spelstat); - if (uarm && is_metallic(uarm)) - splcaster += (uarmc && uarmc->otyp == ROBE) ? - urole.spelarmr/2 : urole.spelarmr; - else if (uarmc && uarmc->otyp == ROBE) - splcaster -= urole.spelarmr; - if (uarms) splcaster += urole.spelshld; + if (uarm && is_metallic(uarm)) + splcaster += (uarmc && uarmc->otyp == ROBE) ? urole.spelarmr / 2 + : urole.spelarmr; + else if (uarmc && uarmc->otyp == ROBE) + splcaster -= urole.spelarmr; + if (uarms) + splcaster += urole.spelshld; - if (uarmh && is_metallic(uarmh) && uarmh->otyp != HELM_OF_BRILLIANCE) - splcaster += uarmhbon; - if (uarmg && is_metallic(uarmg)) splcaster += uarmgbon; - if (uarmf && is_metallic(uarmf)) splcaster += uarmfbon; + if (uarmh && is_metallic(uarmh) && uarmh->otyp != HELM_OF_BRILLIANCE) + splcaster += uarmhbon; + if (uarmg && is_metallic(uarmg)) + splcaster += uarmgbon; + if (uarmf && is_metallic(uarmf)) + splcaster += uarmfbon; - if (spellid(spell) == urole.spelspec) - splcaster += urole.spelsbon; + if (spellid(spell) == urole.spelspec) + splcaster += urole.spelsbon; + /* `healing spell' bonus */ + if (spellid(spell) == SPE_HEALING || spellid(spell) == SPE_EXTRA_HEALING + || spellid(spell) == SPE_CURE_BLINDNESS + || spellid(spell) == SPE_CURE_SICKNESS + || spellid(spell) == SPE_RESTORE_ABILITY + || spellid(spell) == SPE_REMOVE_CURSE) + splcaster += special; - /* `healing spell' bonus */ - if (spellid(spell) == SPE_HEALING || - spellid(spell) == SPE_EXTRA_HEALING || - spellid(spell) == SPE_CURE_BLINDNESS || - spellid(spell) == SPE_CURE_SICKNESS || - spellid(spell) == SPE_RESTORE_ABILITY || - spellid(spell) == SPE_REMOVE_CURSE) splcaster += special; + if (splcaster > 20) + splcaster = 20; - if (splcaster > 20) splcaster = 20; + /* Calculate learned ability */ - /* Calculate learned ability */ + /* Players basic likelihood of being able to cast any spell + * is based of their `magic' statistic. (Int or Wis) + */ + chance = 11 * statused / 2; - /* Players basic likelihood of being able to cast any spell - * is based of their `magic' statistic. (Int or Wis) - */ - chance = 11 * statused / 2; + /* + * High level spells are harder. Easier for higher level casters. + * The difficulty is based on the hero's level and their skill level + * in that spell type. + */ + skill = P_SKILL(spell_skilltype(spellid(spell))); + skill = max(skill, P_UNSKILLED) - 1; /* unskilled => 0 */ + difficulty = + (spellev(spell) - 1) * 4 - ((skill * 6) + (u.ulevel / 3) + 1); - /* - * High level spells are harder. Easier for higher level casters. - * The difficulty is based on the hero's level and their skill level - * in that spell type. - */ - skill = P_SKILL(spell_skilltype(spellid(spell))); - skill = max(skill,P_UNSKILLED) - 1; /* unskilled => 0 */ - difficulty= (spellev(spell)-1) * 4 - ((skill * 6) + (u.ulevel/3) + 1); + if (difficulty > 0) { + /* Player is too low level or unskilled. */ + chance -= isqrt(900 * difficulty + 2000); + } else { + /* Player is above level. Learning continues, but the + * law of diminishing returns sets in quickly for + * low-level spells. That is, a player quickly gains + * no advantage for raising level. + */ + int learning = 15 * -difficulty / spellev(spell); + chance += learning > 20 ? 20 : learning; + } - if (difficulty > 0) { - /* Player is too low level or unskilled. */ - chance -= isqrt(900 * difficulty + 2000); - } else { - /* Player is above level. Learning continues, but the - * law of diminishing returns sets in quickly for - * low-level spells. That is, a player quickly gains - * no advantage for raising level. - */ - int learning = 15 * -difficulty / spellev(spell); - chance += learning > 20 ? 20 : learning; - } + /* Clamp the chance: >18 stat and advanced learning only help + * to a limit, while chances below "hopeless" only raise the + * specter of overflowing 16-bit ints (and permit wearing a + * shield to raise the chances :-). + */ + if (chance < 0) + chance = 0; + if (chance > 120) + chance = 120; - /* Clamp the chance: >18 stat and advanced learning only help - * to a limit, while chances below "hopeless" only raise the - * specter of overflowing 16-bit ints (and permit wearing a - * shield to raise the chances :-). - */ - if (chance < 0) chance = 0; - if (chance > 120) chance = 120; + /* Wearing anything but a light shield makes it very awkward + * to cast a spell. The penalty is not quite so bad for the + * player's role-specific spell. + */ + if (uarms && weight(uarms) > (int) objects[SMALL_SHIELD].oc_weight) { + if (spellid(spell) == urole.spelspec) { + chance /= 2; + } else { + chance /= 4; + } + } - /* Wearing anything but a light shield makes it very awkward - * to cast a spell. The penalty is not quite so bad for the - * player's role-specific spell. - */ - if (uarms && weight(uarms) > (int) objects[SMALL_SHIELD].oc_weight) { - if (spellid(spell) == urole.spelspec) { - chance /= 2; - } else { - chance /= 4; - } - } + /* Finally, chance (based on player intell/wisdom and level) is + * combined with ability (based on player intrinsics and + * encumbrances). No matter how intelligent/wise and advanced + * a player is, intrinsics and encumbrance can prevent casting; + * and no matter how able, learning is always required. + */ + chance = chance * (20 - splcaster) / 15 - splcaster; - /* Finally, chance (based on player intell/wisdom and level) is - * combined with ability (based on player intrinsics and - * encumbrances). No matter how intelligent/wise and advanced - * a player is, intrinsics and encumbrance can prevent casting; - * and no matter how able, learning is always required. - */ - chance = chance * (20-splcaster) / 15 - splcaster; + /* Clamp to percentile */ + if (chance > 100) + chance = 100; + if (chance < 0) + chance = 0; - /* Clamp to percentile */ - if (chance > 100) chance = 100; - if (chance < 0) chance = 0; - - return chance; + return chance; } STATIC_OVL char * @@ -1563,43 +1645,45 @@ spellretention(idx, outbuf) int idx; char *outbuf; { - long turnsleft, percent, accuracy; - int skill; + long turnsleft, percent, accuracy; + int skill; - skill = P_SKILL(spell_skilltype(spellid(idx))); - skill = max(skill, P_UNSKILLED); /* restricted same as unskilled */ - turnsleft = spellknow(idx); - *outbuf = '\0'; /* lint suppression */ + skill = P_SKILL(spell_skilltype(spellid(idx))); + skill = max(skill, P_UNSKILLED); /* restricted same as unskilled */ + turnsleft = spellknow(idx); + *outbuf = '\0'; /* lint suppression */ - if (turnsleft < 1L) { - /* spell has expired; hero can't successfully cast it anymore */ - Strcpy(outbuf, "(gone)"); - } else if (turnsleft >= (long)KEEN) { - /* full retention, first turn or immediately after reading book */ - Strcpy(outbuf, "100%"); - } else { - /* - * Retention is displayed as a range of percentages of - * amount of time left until memory of the spell expires; - * the precision of the range depends upon hero's skill - * in this spell. - * expert: 2% intervals; 1-2, 3-4, ..., 99-100; - * skilled: 5% intervals; 1-5, 6-10, ..., 95-100; - * basic: 10% intervals; 1-10, 11-20, ..., 91-100; - * unskilled: 25% intervals; 1-25, 26-50, 51-75, 76-100. - * - * At the low end of each range, a value of N% really means - * (N-1)%+1 through N%; so 1% is "greater than 0, at most 200". - * KEEN is a multiple of 100; KEEN/100 loses no precision. - */ - percent = (turnsleft - 1L) / ((long)KEEN / 100L) + 1L; - accuracy = (skill == P_EXPERT) ? 2L : (skill == P_SKILLED) ? 5L : - (skill == P_BASIC) ? 10L : 25L; - /* round up to the high end of this range */ - percent = accuracy * ((percent - 1L) / accuracy + 1L); - Sprintf(outbuf, "%ld%%-%ld%%", percent - accuracy + 1L, percent); - } - return outbuf; + if (turnsleft < 1L) { + /* spell has expired; hero can't successfully cast it anymore */ + Strcpy(outbuf, "(gone)"); + } else if (turnsleft >= (long) KEEN) { + /* full retention, first turn or immediately after reading book */ + Strcpy(outbuf, "100%"); + } else { + /* + * Retention is displayed as a range of percentages of + * amount of time left until memory of the spell expires; + * the precision of the range depends upon hero's skill + * in this spell. + * expert: 2% intervals; 1-2, 3-4, ..., 99-100; + * skilled: 5% intervals; 1-5, 6-10, ..., 95-100; + * basic: 10% intervals; 1-10, 11-20, ..., 91-100; + * unskilled: 25% intervals; 1-25, 26-50, 51-75, 76-100. + * + * At the low end of each range, a value of N% really means + * (N-1)%+1 through N%; so 1% is "greater than 0, at most 200". + * KEEN is a multiple of 100; KEEN/100 loses no precision. + */ + percent = (turnsleft - 1L) / ((long) KEEN / 100L) + 1L; + accuracy = + (skill == P_EXPERT) ? 2L : (skill == P_SKILLED) + ? 5L + : (skill == P_BASIC) ? 10L : 25L; + /* round up to the high end of this range */ + percent = accuracy * ((percent - 1L) / accuracy + 1L); + Sprintf(outbuf, "%ld%%-%ld%%", percent - accuracy + 1L, percent); + } + return outbuf; } /* Learn a spell during creation of the initial inventory */ @@ -1607,22 +1691,23 @@ void initialspell(obj) struct obj *obj; { - int i, otyp = obj->otyp; + int i, otyp = obj->otyp; - for (i = 0; i < MAXSPELL; i++) - if (spellid(i) == NO_SPELL || spellid(i) == otyp) break; + for (i = 0; i < MAXSPELL; i++) + if (spellid(i) == NO_SPELL || spellid(i) == otyp) + break; - if (i == MAXSPELL) { - impossible("Too many spells memorized!"); - } else if (spellid(i) != NO_SPELL) { - /* initial inventory shouldn't contain duplicate spellbooks */ - impossible("Spell %s already known.", OBJ_NAME(objects[otyp])); - } else { - spl_book[i].sp_id = otyp; - spl_book[i].sp_lev = objects[otyp].oc_level; - incrnknow(i, 0); - } - return; + if (i == MAXSPELL) { + impossible("Too many spells memorized!"); + } else if (spellid(i) != NO_SPELL) { + /* initial inventory shouldn't contain duplicate spellbooks */ + impossible("Spell %s already known.", OBJ_NAME(objects[otyp])); + } else { + spl_book[i].sp_id = otyp; + spl_book[i].sp_lev = objects[otyp].oc_level; + incrnknow(i, 0); + } + return; } /*spell.c*/ diff --git a/src/steal.c b/src/steal.c index 4228c0a18..eb251ba92 100644 --- a/src/steal.c +++ b/src/steal.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 steal.c $NHDT-Date: 1430528463 2015/05/02 01:01:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.53 $ */ +/* NetHack 3.6 steal.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.57 $ */ /* NetHack 3.6 steal.c $Date: 2012/02/05 04:26:48 $ $Revision: 1.41 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -13,41 +13,47 @@ STATIC_OVL const char * equipname(otmp) register struct obj *otmp; { - return ((otmp == uarmu) ? "shirt" : - (otmp == uarmf) ? "boots" : - (otmp == uarms) ? "shield" : - (otmp == uarmg) ? "gloves" : - (otmp == uarmc) ? cloak_simple_name(otmp) : - (otmp == uarmh) ? helm_simple_name(otmp) : - "armor"); + return ((otmp == uarmu) + ? "shirt" + : (otmp == uarmf) + ? "boots" + : (otmp == uarms) + ? "shield" + : (otmp == uarmg) + ? "gloves" + : (otmp == uarmc) + ? cloak_simple_name(otmp) + : (otmp == uarmh) + ? helm_simple_name(otmp) + : "armor"); } -long /* actually returns something that fits in an int */ -somegold(lmoney) +long /* actually returns something that fits in an int */ + somegold(lmoney) long lmoney; { -#ifdef LINT /* long conv. ok */ +#ifdef LINT /* long conv. ok */ int igold = 0; #else - int igold = (lmoney >= (long)LARGEST_INT) ? LARGEST_INT : (int)lmoney; + int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney; #endif if (igold < 50) - ; /* all gold */ + ; /* all gold */ else if (igold < 100) - igold = rn1(igold - 25 + 1, 25); + igold = rn1(igold - 25 + 1, 25); else if (igold < 500) - igold = rn1(igold - 50 + 1, 50); + igold = rn1(igold - 50 + 1, 50); else if (igold < 1000) - igold = rn1(igold - 100 + 1, 100); + igold = rn1(igold - 100 + 1, 100); else if (igold < 5000) - igold = rn1(igold - 500 + 1, 500); + igold = rn1(igold - 500 + 1, 500); else if (igold < 10000) - igold = rn1(igold - 1000 + 1, 1000); + igold = rn1(igold - 1000 + 1, 1000); else - igold = rn1(igold - 5000 + 1, 5000); + igold = rn1(igold - 5000 + 1, 5000); - return (long)igold; + return (long) igold; } /* @@ -62,103 +68,112 @@ struct obj * findgold(chain) register struct obj *chain; { - while (chain && chain->otyp != GOLD_PIECE) chain = chain->nobj; - return chain; + while (chain && chain->otyp != GOLD_PIECE) + chain = chain->nobj; + return chain; } -/* +/* Steal gold coins only. Leprechauns don't care for lesser coins. */ void stealgold(mtmp) register struct monst *mtmp; { - register struct obj *fgold = g_at(u.ux, u.uy); - register struct obj *ygold; - register long tmp; - struct monst *who; - const char *whose, *what; + register struct obj *fgold = g_at(u.ux, u.uy); + register struct obj *ygold; + register long tmp; + struct monst *who; + const char *whose, *what; - /* skip lesser coins on the floor */ - while (fgold && fgold->otyp != GOLD_PIECE) fgold = fgold->nexthere; + /* skip lesser coins on the floor */ + while (fgold && fgold->otyp != GOLD_PIECE) + fgold = fgold->nexthere; - /* Do you have real gold? */ - ygold = findgold(invent); + /* Do you have real gold? */ + ygold = findgold(invent); - if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) { - obj_extract_self(fgold); - add_to_minv(mtmp, fgold); - newsym(u.ux, u.uy); - if (u.usteed) { - who = u.usteed; - whose = s_suffix(y_monnam(who)); - what = makeplural(mbodypart(who, FOOT)); - } else { - who = &youmonst; - whose = "your"; - what = makeplural(body_part(FOOT)); - } - /* [ avoid "between your rear regions" :-] */ - if (slithy(who->data)) what = "coils"; - /* reduce "rear hooves/claws" to "hooves/claws" */ - if (!strncmp(what, "rear ", 5)) what += 5; - pline("%s quickly snatches some gold from %s %s %s!", - Monnam(mtmp), - (Levitation || Flying) ? "beneath" : "between", - whose, what); - if(!ygold || !rn2(5)) { - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - monflee(mtmp, 0, FALSE, FALSE); - } - } else if(ygold) { - const int gold_price = objects[GOLD_PIECE].oc_cost; - tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price; - tmp = min(tmp, ygold->quan); - if (tmp < ygold->quan) ygold = splitobj(ygold, tmp); - else setnotworn(ygold); - freeinv(ygold); - add_to_minv(mtmp, ygold); - Your("purse feels lighter."); - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - monflee(mtmp, 0, FALSE, FALSE); - context.botl = 1; - } + if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) { + obj_extract_self(fgold); + add_to_minv(mtmp, fgold); + newsym(u.ux, u.uy); + if (u.usteed) { + who = u.usteed; + whose = s_suffix(y_monnam(who)); + what = makeplural(mbodypart(who, FOOT)); + } else { + who = &youmonst; + whose = "your"; + what = makeplural(body_part(FOOT)); + } + /* [ avoid "between your rear regions" :-] */ + if (slithy(who->data)) + what = "coils"; + /* reduce "rear hooves/claws" to "hooves/claws" */ + if (!strncmp(what, "rear ", 5)) + what += 5; + pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp), + (Levitation || Flying) ? "beneath" : "between", whose, what); + if (!ygold || !rn2(5)) { + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + monflee(mtmp, 0, FALSE, FALSE); + } + } else if (ygold) { + const int gold_price = objects[GOLD_PIECE].oc_cost; + tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price; + tmp = min(tmp, ygold->quan); + if (tmp < ygold->quan) + ygold = splitobj(ygold, tmp); + else + setnotworn(ygold); + freeinv(ygold); + add_to_minv(mtmp, ygold); + Your("purse feels lighter."); + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + monflee(mtmp, 0, FALSE, FALSE); + context.botl = 1; + } } /* steal armor after you finish taking it off */ -unsigned int stealoid; /* object to be stolen */ -unsigned int stealmid; /* monster doing the stealing */ +unsigned int stealoid; /* object to be stolen */ +unsigned int stealmid; /* monster doing the stealing */ STATIC_PTR int stealarm(VOID_ARGS) { - register struct monst *mtmp; - register struct obj *otmp; + register struct monst *mtmp; + register struct obj *otmp; - for(otmp = invent; otmp; otmp = otmp->nobj) { - if(otmp->o_id == stealoid) { - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if(mtmp->m_id == stealmid) { - if(DEADMONSTER(mtmp)) impossible("stealarm(): dead monster stealing"); - if(!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */ - goto botm; - if(otmp->unpaid) - subfrombill(otmp, shop_keeper(*u.ushops)); - freeinv(otmp); - pline("%s steals %s!", Monnam(mtmp), doname(otmp)); - (void) mpickobj(mtmp,otmp); /* may free otmp */ - /* Implies seduction, "you gladly hand over ..." - so we don't set mavenge bit here. */ - monflee(mtmp, 0, FALSE, FALSE); - if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE); - break; - } - } - break; - } - } -botm: stealoid = 0; - return 0; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->o_id == stealoid) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (mtmp->m_id == stealmid) { + if (DEADMONSTER(mtmp)) + impossible("stealarm(): dead monster stealing"); + if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */ + goto botm; + if (otmp->unpaid) + subfrombill(otmp, shop_keeper(*u.ushops)); + freeinv(otmp); + pline("%s steals %s!", Monnam(mtmp), doname(otmp)); + (void) mpickobj(mtmp, otmp); /* may free otmp */ + /* Implies seduction, "you gladly hand over ..." + so we don't set mavenge bit here. */ + monflee(mtmp, 0, FALSE, FALSE); + if (!tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); + break; + } + } + break; + } + } +botm: + stealoid = 0; + return 0; } /* An object you're wearing has been taken off by a monster (theft or @@ -166,48 +181,57 @@ botm: stealoid = 0; void remove_worn_item(obj, unchain_ball) struct obj *obj; -boolean unchain_ball; /* whether to unpunish or just unwield */ +boolean unchain_ball; /* whether to unpunish or just unwield */ { - if (donning(obj)) - cancel_don(); - if (!obj->owornmask) - return; + 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) (void) Armor_off(); - else if (obj == uarmc) (void) Cloak_off(); - else if (obj == uarmf) (void) Boots_off(); - else if (obj == uarmg) (void) Gloves_off(); - else if (obj == uarmh) (void) Helmet_off(); - else if (obj == uarms) (void) Shield_off(); - else if (obj == uarmu) (void) Shirt_off(); - /* catchall -- should never happen */ - else setworn((struct obj *)0, 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_ARMOR) { + if (obj == uskin) { + impossible("Removing embedded scales?"); + skinback(TRUE); /* uarm = uskin; uskin = 0; */ + } + if (obj == uarm) + (void) Armor_off(); + else if (obj == uarmc) + (void) Cloak_off(); + else if (obj == uarmf) + (void) Boots_off(); + else if (obj == uarmg) + (void) Gloves_off(); + else if (obj == uarmh) + (void) Helmet_off(); + else if (obj == uarms) + (void) Shield_off(); + else if (obj == uarmu) + (void) Shirt_off(); + /* catchall -- should never happen */ + else + setworn((struct obj *) 0, 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); - } + if (obj->owornmask & (W_BALL | W_CHAIN)) { + if (unchain_ball) + unpunish(); + } else if (obj->owornmask) { + /* catchall */ + setnotworn(obj); + } } /* Returns 1 when something was stolen (or at least, when N should flee now) @@ -220,212 +244,234 @@ steal(mtmp, objnambuf) struct monst *mtmp; char *objnambuf; { - struct obj *otmp; - int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0; - boolean monkey_business, /* true iff an animal is doing the thievery */ - was_doffing; + struct obj *otmp; + int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0; + boolean monkey_business, /* true iff an animal is doing the thievery */ + was_doffing; - if (objnambuf) *objnambuf = '\0'; - /* the following is true if successful on first of two attacks. */ - if(!monnear(mtmp, u.ux, u.uy)) return(0); + if (objnambuf) + *objnambuf = '\0'; + /* the following is true if successful on first of two attacks. */ + if (!monnear(mtmp, u.ux, u.uy)) + return (0); - /* food being eaten might already be used up but will not have - been removed from inventory yet; we don't want to steal that, - so this will cause it to be removed now */ - if (occupation) (void) maybe_finished_meal(FALSE); + /* food being eaten might already be used up but will not have + been removed from inventory yet; we don't want to steal that, + so this will cause it to be removed now */ + if (occupation) + (void) maybe_finished_meal(FALSE); - if (!invent || (inv_cnt(FALSE) == 1 && uskin)) { -nothing_to_steal: - /* Not even a thousand men in armor can strip a naked man. */ - if(Blind) - pline("Somebody tries to rob you, but finds nothing to steal."); - else - pline("%s tries to rob you, but there is nothing to steal!", - Monnam(mtmp)); - return(1); /* let her flee */ - } + if (!invent || (inv_cnt(FALSE) == 1 && uskin)) { + nothing_to_steal: + /* Not even a thousand men in armor can strip a naked man. */ + if (Blind) + pline("Somebody tries to rob you, but finds nothing to steal."); + else + pline("%s tries to rob you, but there is nothing to steal!", + Monnam(mtmp)); + return (1); /* let her flee */ + } - monkey_business = is_animal(mtmp->data); - if (monkey_business || uarmg) { - ; /* skip ring special cases */ - } else if (Adornment & LEFT_RING) { - otmp = uleft; - goto gotobj; - } else if (Adornment & RIGHT_RING) { - otmp = uright; - goto gotobj; - } + monkey_business = is_animal(mtmp->data); + if (monkey_business || uarmg) { + ; /* skip ring special cases */ + } else if (Adornment & LEFT_RING) { + otmp = uleft; + goto gotobj; + } else if (Adornment & RIGHT_RING) { + otmp = uright; + goto gotobj; + } - retry: - tmp = 0; - for(otmp = invent; otmp; otmp = otmp->nobj) - if ((!uarm || otmp != uarmc) && otmp != uskin && otmp->oclass != COIN_CLASS) - tmp += ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1); - if (!tmp) goto nothing_to_steal; - tmp = rn2(tmp); - for(otmp = invent; otmp; otmp = otmp->nobj) - if ((!uarm || otmp != uarmc) && otmp != uskin && otmp->oclass != COIN_CLASS) - if((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1)) < 0) +retry: + tmp = 0; + for (otmp = invent; otmp; otmp = otmp->nobj) + if ((!uarm || otmp != uarmc) && otmp != uskin + && otmp->oclass != COIN_CLASS) + tmp += ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) + ? 5 + : 1); + if (!tmp) + goto nothing_to_steal; + tmp = rn2(tmp); + for (otmp = invent; otmp; otmp = otmp->nobj) + if ((!uarm || otmp != uarmc) && otmp != uskin + && otmp->oclass != COIN_CLASS) + if ((tmp -= + ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) + ? 5 + : 1)) < 0) break; - if(!otmp) { - impossible("Steal fails!"); - return(0); - } - /* can't steal ring(s) while wearing gloves */ - if ((otmp == uleft || otmp == uright) && uarmg) otmp = uarmg; - /* can't steal gloves while wielding - so steal the wielded item. */ - if (otmp == uarmg && uwep) otmp = uwep; - /* can't steal armor while wearing cloak - so steal the cloak. */ - else if(otmp == uarm && uarmc) otmp = uarmc; - /* can't steal shirt while wearing cloak or suit */ - else if(otmp == uarmu && uarmc) otmp = uarmc; - else if(otmp == uarmu && uarm) otmp = uarm; + if (!otmp) { + impossible("Steal fails!"); + return (0); + } + /* can't steal ring(s) while wearing gloves */ + if ((otmp == uleft || otmp == uright) && uarmg) + otmp = uarmg; + /* can't steal gloves while wielding - so steal the wielded item. */ + if (otmp == uarmg && uwep) + otmp = uwep; + /* can't steal armor while wearing cloak - so steal the cloak. */ + else if (otmp == uarm && uarmc) + otmp = uarmc; + /* can't steal shirt while wearing cloak or suit */ + else if (otmp == uarmu && uarmc) + otmp = uarmc; + else if (otmp == uarmu && uarm) + otmp = uarm; gotobj: - if(otmp->o_id == stealoid) return(0); + if (otmp->o_id == stealoid) + return (0); - if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) { - if (!retrycnt++) goto retry; - goto cant_take; - } - /* animals can't overcome curse stickiness nor unlock chains */ - if (monkey_business) { - boolean ostuck; - /* is the player prevented from voluntarily giving up this item? - (ignores loadstones; the !can_carry() check will catch those) */ - if (otmp == uball) - ostuck = TRUE; /* effectively worn; curse is implicit */ - else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) - ostuck = FALSE; /* not really worn; curse doesn't matter */ - else - ostuck = ((otmp->cursed && otmp->owornmask) || - /* nymphs can steal rings from under - cursed weapon but animals can't */ - (otmp == uright && welded(uwep)) || - (otmp == uleft && welded(uwep) && bimanual(uwep))); + if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) { + if (!retrycnt++) + goto retry; + goto cant_take; + } + /* animals can't overcome curse stickiness nor unlock chains */ + if (monkey_business) { + boolean ostuck; + /* is the player prevented from voluntarily giving up this item? + (ignores loadstones; the !can_carry() check will catch those) */ + if (otmp == uball) + ostuck = TRUE; /* effectively worn; curse is implicit */ + else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) + ostuck = FALSE; /* not really worn; curse doesn't matter */ + else + ostuck = ((otmp->cursed && otmp->owornmask) || + /* nymphs can steal rings from under + cursed weapon but animals can't */ + (otmp == uright && welded(uwep)) + || (otmp == uleft && welded(uwep) && bimanual(uwep))); - if (ostuck || !can_carry(mtmp, otmp)) { - static const char * const how[] = { "steal","snatch","grab","take" }; - cant_take: - pline("%s tries to %s %s%s but gives up.", - Monnam(mtmp), how[rn2(SIZE(how))], - (otmp->owornmask & W_ARMOR) ? "your " : "", - (otmp->owornmask & W_ARMOR) ? equipname(otmp) : - yname(otmp)); - /* the fewer items you have, the less likely the thief - is going to stick around to try again (0) instead of - running away (1) */ - return !rn2(inv_cnt(FALSE) / 5 + 2); - } - } + if (ostuck || !can_carry(mtmp, otmp)) { + static const char *const how[] = { "steal", "snatch", "grab", + "take" }; + cant_take: + pline("%s tries to %s %s%s but gives up.", Monnam(mtmp), + how[rn2(SIZE(how))], + (otmp->owornmask & W_ARMOR) ? "your " : "", + (otmp->owornmask & W_ARMOR) ? equipname(otmp) + : yname(otmp)); + /* the fewer items you have, the less likely the thief + is going to stick around to try again (0) instead of + running away (1) */ + return !rn2(inv_cnt(FALSE) / 5 + 2); + } + } - if (otmp->otyp == LEASH && otmp->leashmon) { - if (monkey_business && otmp->cursed) goto cant_take; - o_unleash(otmp); - } + if (otmp->otyp == LEASH && otmp->leashmon) { + if (monkey_business && otmp->cursed) + goto cant_take; + o_unleash(otmp); + } - was_doffing = doffing(otmp); - /* stop donning/doffing now so that afternmv won't be clobbered - below; stop_occupation doesn't handle donning/doffing */ - olddelay = stop_donning(otmp); - /* you're going to notice the theft... */ - stop_occupation(); + was_doffing = doffing(otmp); + /* stop donning/doffing now so that afternmv won't be clobbered + below; stop_occupation doesn't handle donning/doffing */ + olddelay = stop_donning(otmp); + /* you're going to notice the theft... */ + stop_occupation(); - if((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))){ - switch(otmp->oclass) { - case TOOL_CLASS: - case AMULET_CLASS: - case RING_CLASS: - case FOOD_CLASS: /* meat ring */ - remove_worn_item(otmp, TRUE); - break; - case ARMOR_CLASS: - armordelay = objects[otmp->otyp].oc_delay; - if (olddelay > 0 && olddelay < armordelay) - armordelay = olddelay; - if (monkey_business) { - /* animals usually don't have enough patience - to take off items which require extra time */ - if (armordelay >= 1 && !olddelay && rn2(10)) - goto cant_take; - remove_worn_item(otmp, TRUE); - break; - } else { - int curssv = otmp->cursed; - int slowly; - boolean seen = canspotmon(mtmp); + if ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))) { + switch (otmp->oclass) { + case TOOL_CLASS: + case AMULET_CLASS: + case RING_CLASS: + case FOOD_CLASS: /* meat ring */ + remove_worn_item(otmp, TRUE); + break; + case ARMOR_CLASS: + armordelay = objects[otmp->otyp].oc_delay; + if (olddelay > 0 && olddelay < armordelay) + armordelay = olddelay; + if (monkey_business) { + /* animals usually don't have enough patience + to take off items which require extra time */ + if (armordelay >= 1 && !olddelay && rn2(10)) + goto cant_take; + remove_worn_item(otmp, TRUE); + break; + } else { + int curssv = otmp->cursed; + int slowly; + boolean seen = canspotmon(mtmp); - otmp->cursed = 0; - /* can't charm you without first waking you */ - if (Unaware) unmul((char *)0); - slowly = (armordelay >= 1 || multi < 0); - if(flags.female) - pline("%s charms you. You gladly %s your %s.", - !seen ? "She" : Monnam(mtmp), - curssv ? "let her take" : - !slowly ? "hand over" : - was_doffing ? "continue removing" : - "start removing", - equipname(otmp)); - else - pline("%s seduces you and %s off your %s.", - !seen ? "She" : Adjmonnam(mtmp, "beautiful"), - curssv ? "helps you to take" : - !slowly ? "you take" : - was_doffing ? "you continue taking" : - "you start taking", - equipname(otmp)); - named++; - /* the following is to set multi for later on */ - nomul(-armordelay); - multi_reason = "taking off clothes"; - nomovemsg = 0; - remove_worn_item(otmp, TRUE); - otmp->cursed = curssv; - if(multi < 0) { - /* - multi = 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. [%d]", - otmp->oclass); - } - } - else if (otmp->owornmask) - remove_worn_item(otmp, TRUE); + otmp->cursed = 0; + /* can't charm you without first waking you */ + if (Unaware) + unmul((char *) 0); + slowly = (armordelay >= 1 || multi < 0); + if (flags.female) + pline("%s charms you. You gladly %s your %s.", + !seen ? "She" : Monnam(mtmp), + curssv ? "let her take" + : !slowly ? "hand over" + : was_doffing ? "continue removing" + : "start removing", + equipname(otmp)); + else + pline("%s seduces you and %s off your %s.", + !seen ? "She" : Adjmonnam(mtmp, "beautiful"), + curssv + ? "helps you to take" + : !slowly ? "you take" + : was_doffing ? "you continue taking" + : "you start taking", + equipname(otmp)); + named++; + /* the following is to set multi for later on */ + nomul(-armordelay); + multi_reason = "taking off clothes"; + nomovemsg = 0; + remove_worn_item(otmp, TRUE); + otmp->cursed = curssv; + if (multi < 0) { + /* + multi = 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. [%d]", + otmp->oclass); + } + } else if (otmp->owornmask) + remove_worn_item(otmp, TRUE); - /* do this before removing it from inventory */ - if (objnambuf) Strcpy(objnambuf, yname(otmp)); - /* set mavenge bit so knights won't suffer an - * alignment penalty during retaliation; - */ - mtmp->mavenge = 1; + /* do this before removing it from inventory */ + if (objnambuf) + Strcpy(objnambuf, yname(otmp)); + /* set mavenge bit so knights won't suffer an + * alignment penalty during retaliation; + */ + mtmp->mavenge = 1; - if(otmp->unpaid) - subfrombill(otmp, shop_keeper(*u.ushops)); - freeinv(otmp); - pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp)); - could_petrify = (otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm])); - (void) mpickobj(mtmp,otmp); /* may free otmp */ - if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) { - minstapetrify(mtmp, TRUE); - return -1; - } - return((multi < 0) ? 0 : 1); + if (otmp->unpaid) + subfrombill(otmp, shop_keeper(*u.ushops)); + freeinv(otmp); + pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp)); + could_petrify = + (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])); + (void) mpickobj(mtmp, otmp); /* may free otmp */ + if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) { + minstapetrify(mtmp, TRUE); + return -1; + } + return ((multi < 0) ? 0 : 1); } /* Returns 1 if otmp is free'd, 0 otherwise. */ int -mpickobj(mtmp,otmp) +mpickobj(mtmp, otmp) register struct monst *mtmp; register struct obj *otmp; { @@ -434,29 +480,32 @@ register struct obj *otmp; /* if monster is acquiring a thrown or kicked object, the throwing or kicking code shouldn't continue to track and place it */ - if (otmp == thrownobj) thrownobj = 0; - else if (otmp == kickedobj) kickedobj = 0; + if (otmp == thrownobj) + thrownobj = 0; + else if (otmp == kickedobj) + kickedobj = 0; /* don't want hidden light source inside the monster; assumes that engulfers won't have external inventories; whirly monsters cause the light to be extinguished rather than letting it shine thru */ - if (otmp->lamplit && /* hack to avoid function calls for most objs */ - obj_sheds_light(otmp) && - attacktype(mtmp->data, AT_ENGL)) { - /* this is probably a burning object that you dropped or threw */ - if (u.uswallow && mtmp == u.ustuck && !Blind) - pline("%s out.", Tobjnam(otmp, "go")); - snuff_otmp = TRUE; + if (otmp->lamplit && /* hack to avoid function calls for most objs */ + obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) { + /* this is probably a burning object that you dropped or threw */ + if (u.uswallow && mtmp == u.ustuck && !Blind) + pline("%s out.", Tobjnam(otmp, "go")); + snuff_otmp = TRUE; } /* for hero owned object on shop floor, mtmp is taking possession and if it's eventually dropped in a shop, shk will claim it */ - if (!mtmp->mtame) otmp->no_charge = 0; + if (!mtmp->mtame) + otmp->no_charge = 0; /* Must do carrying effects on object prior to add_to_minv() */ carry_obj_effects(otmp); /* add_to_minv() might free otmp [if merged with something else], so we have to call it after doing the object checks */ freed_otmp = add_to_minv(mtmp, otmp); /* and we had to defer this until object is in mtmp's inventory */ - if (snuff_otmp) snuff_light_source(mtmp->mx, mtmp->my); + if (snuff_otmp) + snuff_light_source(mtmp->mx, mtmp->my); return freed_otmp; } @@ -464,45 +513,48 @@ void stealamulet(mtmp) struct monst *mtmp; { - struct obj *otmp = (struct obj *)0; - int real=0, fake=0; + struct obj *otmp = (struct obj *) 0; + int real = 0, fake = 0; /* select the artifact to steal */ - if(u.uhave.amulet) { - real = AMULET_OF_YENDOR; - fake = FAKE_AMULET_OF_YENDOR; - } else if(u.uhave.questart) { - for(otmp = invent; otmp; otmp = otmp->nobj) - if(is_quest_artifact(otmp)) break; - if (!otmp) return; /* should we panic instead? */ - } else if(u.uhave.bell) { - real = BELL_OF_OPENING; - fake = BELL; - } else if(u.uhave.book) { - real = SPE_BOOK_OF_THE_DEAD; - } else if(u.uhave.menorah) { - real = CANDELABRUM_OF_INVOCATION; - } else return; /* you have nothing of special interest */ + if (u.uhave.amulet) { + real = AMULET_OF_YENDOR; + fake = FAKE_AMULET_OF_YENDOR; + } else if (u.uhave.questart) { + for (otmp = invent; otmp; otmp = otmp->nobj) + if (is_quest_artifact(otmp)) + break; + if (!otmp) + return; /* should we panic instead? */ + } else if (u.uhave.bell) { + real = BELL_OF_OPENING; + fake = BELL; + } else if (u.uhave.book) { + real = SPE_BOOK_OF_THE_DEAD; + } else if (u.uhave.menorah) { + real = CANDELABRUM_OF_INVOCATION; + } else + return; /* you have nothing of special interest */ if (!otmp) { - /* If we get here, real and fake have been set up. */ - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == real || (otmp->otyp == fake && !mtmp->iswiz)) - break; + /* If we get here, real and fake have been set up. */ + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == real || (otmp->otyp == fake && !mtmp->iswiz)) + break; } if (otmp) { /* we have something to snatch */ - if (otmp->owornmask) - remove_worn_item(otmp, TRUE); - if(otmp->unpaid) - subfrombill(otmp, shop_keeper(*u.ushops)); - freeinv(otmp); - /* mpickobj wont merge otmp because none of the above things - to steal are mergable */ - (void) mpickobj(mtmp,otmp); /* may merge and free otmp */ - pline("%s stole %s!", Monnam(mtmp), doname(otmp)); - if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) - (void) rloc(mtmp, FALSE); + if (otmp->owornmask) + remove_worn_item(otmp, TRUE); + if (otmp->unpaid) + subfrombill(otmp, shop_keeper(*u.ushops)); + freeinv(otmp); + /* mpickobj wont merge otmp because none of the above things + to steal are mergable */ + (void) mpickobj(mtmp, otmp); /* may merge and free otmp */ + pline("%s stole %s!", Monnam(mtmp), doname(otmp)); + if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) + (void) rloc(mtmp, FALSE); } } @@ -512,35 +564,39 @@ void maybe_absorb_item(mon, obj, ochance, achance) struct monst *mon; struct obj *obj; -int ochance, achance; /* percent chance for ordinary item, artifact */ +int ochance, achance; /* percent chance for ordinary item, artifact */ { - if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS || - obj_resists(obj, 100 - ochance, 100 - achance) || - !touch_artifact(obj, mon)) - return; + if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS + || obj_resists(obj, 100 - ochance, 100 - achance) + || !touch_artifact(obj, mon)) + return; if (carried(obj)) { - if (obj->owornmask) remove_worn_item(obj, TRUE); - if (obj->unpaid) subfrombill(obj, shop_keeper(*u.ushops)); - if (cansee(mon->mx, mon->my)) { - const char *MonName = Monnam(mon); + if (obj->owornmask) + remove_worn_item(obj, TRUE); + if (obj->unpaid) + subfrombill(obj, shop_keeper(*u.ushops)); + if (cansee(mon->mx, mon->my)) { + const char *MonName = Monnam(mon); - /* mon might be invisible; avoid "It pulls ... and absorbs it!" */ - if (!strcmp(MonName, "It")) MonName = "Something"; - pline("%s pulls %s away from you and absorbs %s!", - MonName, yname(obj), (obj->quan > 1L) ? "them" : "it"); - } else { - const char *hand_s = body_part(HAND); + /* mon might be invisible; avoid "It pulls ... and absorbs it!" */ + if (!strcmp(MonName, "It")) + MonName = "Something"; + pline("%s pulls %s away from you and absorbs %s!", MonName, + yname(obj), (obj->quan > 1L) ? "them" : "it"); + } else { + const char *hand_s = body_part(HAND); - if (bimanual(obj)) hand_s = makeplural(hand_s); - pline("%s %s pulled from your %s!", - upstart(yname(obj)), otense(obj, "are"), hand_s); - } - freeinv(obj); + if (bimanual(obj)) + hand_s = makeplural(hand_s); + pline("%s %s pulled from your %s!", upstart(yname(obj)), + otense(obj, "are"), hand_s); + } + freeinv(obj); } else { - /* not carried; presumeably thrown or kicked */ - if (canspotmon(mon)) - pline("%s absorbs %s!", Monnam(mon), yname(obj)); + /* not carried; presumeably thrown or kicked */ + if (canspotmon(mon)) + pline("%s absorbs %s!", Monnam(mon), yname(obj)); } /* add to mon's inventory */ (void) mpickobj(mon, obj); @@ -557,32 +613,36 @@ boolean verbosely; boolean update_mon = FALSE; if (obj->owornmask) { - /* perform worn item handling if the monster is still alive */ - if (mon->mhp > 0) { - mon->misc_worn_check &= ~obj->owornmask; - update_mon = TRUE; - /* don't charge for an owned saddle on dead steed (provided - that the hero is within the same shop at the time) */ - } else if (mon->mtame && (obj->owornmask & W_SADDLE) && - !obj->unpaid && costly_spot(omx, omy) && - /* being at a costly_spot guarantees lev->roomno is not 0 */ - index(in_rooms(u.ux, u.uy, SHOPBASE), levl[omx][omy].roomno)) { - obj->no_charge = 1; - } - /* this should be done even if the monster has died */ - if (obj->owornmask & W_WEP) setmnotwielded(mon, obj); - obj->owornmask = 0L; + /* perform worn item handling if the monster is still alive */ + if (mon->mhp > 0) { + mon->misc_worn_check &= ~obj->owornmask; + update_mon = TRUE; + /* don't charge for an owned saddle on dead steed (provided + that the hero is within the same shop at the time) */ + } else if (mon->mtame && (obj->owornmask & W_SADDLE) && !obj->unpaid + && costly_spot(omx, omy) && + /* being at a costly_spot guarantees lev->roomno is not 0 + */ + index(in_rooms(u.ux, u.uy, SHOPBASE), + levl[omx][omy].roomno)) { + obj->no_charge = 1; + } + /* this should be done even if the monster has died */ + if (obj->owornmask & W_WEP) + setmnotwielded(mon, obj); + obj->owornmask = 0L; } - /* obj_no_longer_held(obj); -- done by place_object */ + /* obj_no_longer_held(obj); -- done by place_object */ if (verbosely && cansee(omx, omy)) - pline("%s drops %s.", Monnam(mon), distant_name(obj, doname)); + pline("%s drops %s.", Monnam(mon), distant_name(obj, doname)); if (!flooreffects(obj, omx, omy, "fall")) { - place_object(obj, omx, omy); - stackobj(obj); + place_object(obj, omx, omy); + stackobj(obj); } /* do this last, after placing obj on floor; removing steed's saddle throws rider, possibly inflicting fatal damage and producing bones */ - if (update_mon) update_mon_intrinsics(mon, obj, FALSE, TRUE); + if (update_mon) + update_mon_intrinsics(mon, obj, FALSE, TRUE); } /* some monsters bypass the normal rules for moving between levels or @@ -595,13 +655,13 @@ struct monst *mon; struct obj *obj, *otmp; for (obj = mon->minvent; obj; obj = otmp) { - otmp = obj->nobj; - /* the Amulet, invocation tools, and Rider corpses resist even when - artifacts and ordinary objects are given 0% resistance chance */ - if (obj_resists(obj, 0, 0)) { - obj_extract_self(obj); - mdrop_obj(mon, obj, FALSE); - } + otmp = obj->nobj; + /* the Amulet, invocation tools, and Rider corpses resist even when + artifacts and ordinary objects are given 0% resistance chance */ + if (obj_resists(obj, 0, 0)) { + obj_extract_self(obj); + mdrop_obj(mon, obj, FALSE); + } } } @@ -610,28 +670,26 @@ void relobj(mtmp, show, is_pet) struct monst *mtmp; int show; -boolean is_pet; /* If true, pet should keep wielded/worn items */ +boolean is_pet; /* If true, pet should keep wielded/worn items */ { - struct obj *otmp; - int omx = mtmp->mx, omy = mtmp->my; + struct obj *otmp; + int omx = mtmp->mx, omy = mtmp->my; - /* vault guard's gold goes away rather than be dropped... */ - if (mtmp->isgd && - (otmp = findgold(mtmp->minvent)) != 0 - ) { - if (canspotmon(mtmp)) - pline("%s gold %s.", s_suffix(Monnam(mtmp)), - canseemon(mtmp) ? "vanishes" : "seems to vanish"); - obfree(otmp, (struct obj *)0); - } /* isgd && has gold */ + /* vault guard's gold goes away rather than be dropped... */ + if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) { + if (canspotmon(mtmp)) + pline("%s gold %s.", s_suffix(Monnam(mtmp)), + canseemon(mtmp) ? "vanishes" : "seems to vanish"); + obfree(otmp, (struct obj *) 0); + } /* isgd && has gold */ - while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) { - obj_extract_self(otmp); - mdrop_obj(mtmp, otmp, is_pet && flags.verbose); - } + while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) { + obj_extract_self(otmp); + mdrop_obj(mtmp, otmp, is_pet && flags.verbose); + } - if (show && cansee(omx, omy)) - newsym(omx, omy); + if (show && cansee(omx, omy)) + newsym(omx, omy); } /*steal.c*/ diff --git a/src/steed.c b/src/steed.c index 5a6a53741..56c6f18eb 100644 --- a/src/steed.c +++ b/src/steed.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 steed.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 steed.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */ /* NetHack 3.6 steed.c $Date: 2012/01/04 18:52:36 $ $Revision: 1.36 $ */ /* Copyright (c) Kevin Hugo, 1998-1999. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,9 +6,9 @@ #include "hack.h" /* Monsters that might be ridden */ -static NEARDATA const char steeds[] = { - S_QUADRUPED, S_UNICORN, S_ANGEL, S_CENTAUR, S_DRAGON, S_JABBERWOCK, '\0' -}; +static NEARDATA const char steeds[] = { S_QUADRUPED, S_UNICORN, S_ANGEL, + S_CENTAUR, S_DRAGON, S_JABBERWOCK, + '\0' }; STATIC_DCL boolean FDECL(landing_spot, (coord *, int, int)); STATIC_DCL void FDECL(maybewakesteed, (struct monst *)); @@ -17,7 +17,7 @@ STATIC_DCL void FDECL(maybewakesteed, (struct monst *)); void rider_cant_reach() { - You("aren't skilled enough to reach from %s.", y_monnam(u.usteed)); + You("aren't skilled enough to reach from %s.", y_monnam(u.usteed)); } /*** Putting the saddle on ***/ @@ -25,382 +25,380 @@ rider_cant_reach() /* Can this monster wear a saddle? */ boolean can_saddle(mtmp) - struct monst *mtmp; +struct monst *mtmp; { - struct permonst *ptr = mtmp->data; + struct permonst *ptr = mtmp->data; - return (index(steeds, ptr->mlet) && (ptr->msize >= MZ_MEDIUM) && - (!humanoid(ptr) || ptr->mlet == S_CENTAUR) && - !amorphous(ptr) && !noncorporeal(ptr) && - !is_whirly(ptr) && !unsolid(ptr)); + return (index(steeds, ptr->mlet) && (ptr->msize >= MZ_MEDIUM) + && (!humanoid(ptr) || ptr->mlet == S_CENTAUR) && !amorphous(ptr) + && !noncorporeal(ptr) && !is_whirly(ptr) && !unsolid(ptr)); } - int use_saddle(otmp) - struct obj *otmp; +struct obj *otmp; { - struct monst *mtmp; - struct permonst *ptr; - int chance; - const char *s; + struct monst *mtmp; + struct permonst *ptr; + int chance; + const char *s; + if (!u_handsy()) + return 0; - if (!u_handsy()) return 0; + /* Select an animal */ + if (u.uswallow || Underwater || !getdir((char *) 0)) { + pline1(Never_mind); + return 0; + } + if (!u.dx && !u.dy) { + pline("Saddle yourself? Very funny..."); + return 0; + } + if (!isok(u.ux + u.dx, u.uy + u.dy) + || !(mtmp = m_at(u.ux + u.dx, u.uy + u.dy)) || !canspotmon(mtmp)) { + pline("I see nobody there."); + return 1; + } - /* Select an animal */ - if (u.uswallow || Underwater || !getdir((char *)0)) { - pline1(Never_mind); - return 0; - } - if (!u.dx && !u.dy) { - pline("Saddle yourself? Very funny..."); - return 0; - } - if (!isok(u.ux+u.dx, u.uy+u.dy) || - !(mtmp = m_at(u.ux+u.dx, u.uy+u.dy)) || - !canspotmon(mtmp)) { - pline("I see nobody there."); - return 1; - } + /* Is this a valid monster? */ + if (mtmp->misc_worn_check & W_SADDLE || which_armor(mtmp, W_SADDLE)) { + pline("%s doesn't need another one.", Monnam(mtmp)); + return 1; + } + ptr = mtmp->data; + if (touch_petrifies(ptr) && !uarmg && !Stone_resistance) { + char kbuf[BUFSZ]; - /* Is this a valid monster? */ - if (mtmp->misc_worn_check & W_SADDLE || - which_armor(mtmp, W_SADDLE)) { - pline("%s doesn't need another one.", Monnam(mtmp)); - return 1; - } - ptr = mtmp->data; - if (touch_petrifies(ptr) && !uarmg && !Stone_resistance) { - char kbuf[BUFSZ]; + You("touch %s.", mon_nam(mtmp)); + if (!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) { + Sprintf(kbuf, "attempting to saddle %s", an(mtmp->data->mname)); + instapetrify(kbuf); + } + } + if (ptr == &mons[PM_INCUBUS] || ptr == &mons[PM_SUCCUBUS]) { + pline("Shame on you!"); + exercise(A_WIS, FALSE); + return 1; + } + if (mtmp->isminion || mtmp->isshk || mtmp->ispriest || mtmp->isgd + || mtmp->iswiz) { + pline("I think %s would mind.", mon_nam(mtmp)); + return 1; + } + if (!can_saddle(mtmp)) { + You_cant("saddle such a creature."); + return 1; + } - You("touch %s.", mon_nam(mtmp)); - if (!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) { - Sprintf(kbuf, "attempting to saddle %s", an(mtmp->data->mname)); - instapetrify(kbuf); - } - } - if (ptr == &mons[PM_INCUBUS] || ptr == &mons[PM_SUCCUBUS]) { - pline("Shame on you!"); - exercise(A_WIS, FALSE); - return 1; - } - if (mtmp->isminion || mtmp->isshk || mtmp->ispriest || - mtmp->isgd || mtmp->iswiz) { - pline("I think %s would mind.", mon_nam(mtmp)); - return 1; - } - if (!can_saddle(mtmp)) { - You_cant("saddle such a creature."); - return 1; - } + /* Calculate your chance */ + chance = ACURR(A_DEX) + ACURR(A_CHA) / 2 + 2 * mtmp->mtame; + chance += u.ulevel * (mtmp->mtame ? 20 : 5); + if (!mtmp->mtame) + chance -= 10 * mtmp->m_lev; + if (Role_if(PM_KNIGHT)) + chance += 20; + switch (P_SKILL(P_RIDING)) { + case P_ISRESTRICTED: + case P_UNSKILLED: + default: + chance -= 20; + break; + case P_BASIC: + break; + case P_SKILLED: + chance += 15; + break; + case P_EXPERT: + chance += 30; + break; + } + if (Confusion || Fumbling || Glib) + chance -= 20; + else if (uarmg && (s = OBJ_DESCR(objects[uarmg->otyp])) != (char *) 0 + && !strncmp(s, "riding ", 7)) + /* Bonus for wearing "riding" (but not fumbling) gloves */ + chance += 10; + else if (uarmf && (s = OBJ_DESCR(objects[uarmf->otyp])) != (char *) 0 + && !strncmp(s, "riding ", 7)) + /* ... or for "riding boots" */ + chance += 10; + if (otmp->cursed) + chance -= 50; - /* Calculate your chance */ - chance = ACURR(A_DEX) + ACURR(A_CHA)/2 + 2*mtmp->mtame; - chance += u.ulevel * (mtmp->mtame ? 20 : 5); - if (!mtmp->mtame) chance -= 10*mtmp->m_lev; - if (Role_if(PM_KNIGHT)) - chance += 20; - switch (P_SKILL(P_RIDING)) { - case P_ISRESTRICTED: - case P_UNSKILLED: - default: - chance -= 20; break; - case P_BASIC: - break; - case P_SKILLED: - chance += 15; break; - case P_EXPERT: - chance += 30; break; - } - if (Confusion || Fumbling || Glib) - chance -= 20; - else if (uarmg && - (s = OBJ_DESCR(objects[uarmg->otyp])) != (char *)0 && - !strncmp(s, "riding ", 7)) - /* Bonus for wearing "riding" (but not fumbling) gloves */ - chance += 10; - else if (uarmf && - (s = OBJ_DESCR(objects[uarmf->otyp])) != (char *)0 && - !strncmp(s, "riding ", 7)) - /* ... or for "riding boots" */ - chance += 10; - if (otmp->cursed) - chance -= 50; + /* [intended] steed becomes alert if possible */ + maybewakesteed(mtmp); - /* [intended] steed becomes alert if possible */ - maybewakesteed(mtmp); - - /* Make the attempt */ - if (rn2(100) < chance) { - You("put the saddle on %s.", mon_nam(mtmp)); - if (otmp->owornmask) remove_worn_item(otmp, FALSE); - freeinv(otmp); - /* mpickobj may free otmp it if merges, but we have already - checked for a saddle above, so no merger should happen */ - (void) mpickobj(mtmp, otmp); - mtmp->misc_worn_check |= W_SADDLE; - otmp->owornmask = W_SADDLE; - otmp->leashmon = mtmp->m_id; - update_mon_intrinsics(mtmp, otmp, TRUE, FALSE); - } else - pline("%s resists!", Monnam(mtmp)); - return 1; + /* Make the attempt */ + if (rn2(100) < chance) { + You("put the saddle on %s.", mon_nam(mtmp)); + if (otmp->owornmask) + remove_worn_item(otmp, FALSE); + freeinv(otmp); + /* mpickobj may free otmp it if merges, but we have already + checked for a saddle above, so no merger should happen */ + (void) mpickobj(mtmp, otmp); + mtmp->misc_worn_check |= W_SADDLE; + otmp->owornmask = W_SADDLE; + otmp->leashmon = mtmp->m_id; + update_mon_intrinsics(mtmp, otmp, TRUE, FALSE); + } else + pline("%s resists!", Monnam(mtmp)); + return 1; } - /*** Riding the monster ***/ /* Can we ride this monster? Caller should also check can_saddle() */ boolean can_ride(mtmp) - struct monst *mtmp; +struct monst *mtmp; { - return (mtmp->mtame && humanoid(youmonst.data) && - !verysmall(youmonst.data) && !bigmonst(youmonst.data) && - (!Underwater || is_swimmer(mtmp->data))); + return (mtmp->mtame && humanoid(youmonst.data) + && !verysmall(youmonst.data) && !bigmonst(youmonst.data) + && (!Underwater || is_swimmer(mtmp->data))); } - int doride() { - boolean forcemount = FALSE; + boolean forcemount = FALSE; - if (u.usteed) { - dismount_steed(DISMOUNT_BYCHOICE); - } else if (getdir((char *)0) && isok(u.ux+u.dx, u.uy+u.dy)) { - if (wizard && yn("Force the mount to succeed?") == 'y') - forcemount = TRUE; - return (mount_steed(m_at(u.ux+u.dx, u.uy+u.dy), forcemount)); - } else { - return 0; - } - return 1; + if (u.usteed) { + dismount_steed(DISMOUNT_BYCHOICE); + } else if (getdir((char *) 0) && isok(u.ux + u.dx, u.uy + u.dy)) { + if (wizard && yn("Force the mount to succeed?") == 'y') + forcemount = TRUE; + return (mount_steed(m_at(u.ux + u.dx, u.uy + u.dy), forcemount)); + } else { + return 0; + } + return 1; } - /* Start riding, with the given monster */ boolean mount_steed(mtmp, force) - struct monst *mtmp; /* The animal */ - boolean force; /* Quietly force this animal */ +struct monst *mtmp; /* The animal */ +boolean force; /* Quietly force this animal */ { - struct obj *otmp; - char buf[BUFSZ]; - struct permonst *ptr; + struct obj *otmp; + char buf[BUFSZ]; + struct permonst *ptr; - /* Sanity checks */ - if (u.usteed) { - You("are already riding %s.", mon_nam(u.usteed)); - return (FALSE); - } + /* Sanity checks */ + if (u.usteed) { + You("are already riding %s.", mon_nam(u.usteed)); + return (FALSE); + } - /* Is the player in the right form? */ - if (Hallucination && !force) { - pline("Maybe you should find a designated driver."); - return (FALSE); - } - /* While riding Wounded_legs refers to the steed's, - * not the hero's legs. - * That opens up a potential abuse where the player - * can mount a steed, then dismount immediately to - * heal leg damage, because leg damage is always - * healed upon dismount (Wounded_legs context switch). - * By preventing a hero with Wounded_legs from - * mounting a steed, the potential for abuse is - * reduced. However, dismounting still immediately - * heals the steed's wounded legs. [In 3.4.3 and - * earlier, that unintentionally made the hero's - * temporary 1 point Dex loss become permanent.] - */ - if (Wounded_legs) { - Your("%s are in no shape for riding.", makeplural(body_part(LEG))); - if (force && wizard && yn("Heal your legs?") == 'y') - HWounded_legs = EWounded_legs = 0; - else - return (FALSE); - } + /* Is the player in the right form? */ + if (Hallucination && !force) { + pline("Maybe you should find a designated driver."); + return (FALSE); + } + /* While riding Wounded_legs refers to the steed's, + * not the hero's legs. + * That opens up a potential abuse where the player + * can mount a steed, then dismount immediately to + * heal leg damage, because leg damage is always + * healed upon dismount (Wounded_legs context switch). + * By preventing a hero with Wounded_legs from + * mounting a steed, the potential for abuse is + * reduced. However, dismounting still immediately + * heals the steed's wounded legs. [In 3.4.3 and + * earlier, that unintentionally made the hero's + * temporary 1 point Dex loss become permanent.] + */ + if (Wounded_legs) { + Your("%s are in no shape for riding.", makeplural(body_part(LEG))); + if (force && wizard && yn("Heal your legs?") == 'y') + HWounded_legs = EWounded_legs = 0; + else + return (FALSE); + } - if (Upolyd && (!humanoid(youmonst.data) || verysmall(youmonst.data) || - bigmonst(youmonst.data) || slithy(youmonst.data))) { - You("won't fit on a saddle."); - return (FALSE); - } - if(!force && (near_capacity() > SLT_ENCUMBER)) { - You_cant("do that while carrying so much stuff."); - return (FALSE); - } + if (Upolyd && (!humanoid(youmonst.data) || verysmall(youmonst.data) + || bigmonst(youmonst.data) || slithy(youmonst.data))) { + You("won't fit on a saddle."); + return (FALSE); + } + if (!force && (near_capacity() > SLT_ENCUMBER)) { + You_cant("do that while carrying so much stuff."); + return (FALSE); + } - /* Can the player reach and see the monster? */ - if (!mtmp || (!force && ((Blind && !Blind_telepat) || - mtmp->mundetected || - mtmp->m_ap_type == M_AP_FURNITURE || - mtmp->m_ap_type == M_AP_OBJECT))) { - pline("I see nobody there."); - return (FALSE); - } - if (u.uswallow || u.ustuck || u.utrap || Punished || - !test_move(u.ux, u.uy, mtmp->mx-u.ux, mtmp->my-u.uy, TEST_MOVE)) { - if (Punished || !(u.uswallow || u.ustuck || u.utrap)) - You("are unable to swing your %s over.", body_part(LEG)); - else - You("are stuck here for now."); - return (FALSE); - } + /* Can the player reach and see the monster? */ + if (!mtmp || (!force && ((Blind && !Blind_telepat) || mtmp->mundetected + || mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT))) { + pline("I see nobody there."); + return (FALSE); + } + if (u.uswallow || u.ustuck || u.utrap || Punished + || !test_move(u.ux, u.uy, mtmp->mx - u.ux, mtmp->my - u.uy, + TEST_MOVE)) { + if (Punished || !(u.uswallow || u.ustuck || u.utrap)) + You("are unable to swing your %s over.", body_part(LEG)); + else + You("are stuck here for now."); + return (FALSE); + } - /* Is this a valid monster? */ - otmp = which_armor(mtmp, W_SADDLE); - if (!otmp) { - pline("%s is not saddled.", Monnam(mtmp)); - return (FALSE); - } - ptr = mtmp->data; - if (touch_petrifies(ptr) && !Stone_resistance) { - char kbuf[BUFSZ]; + /* Is this a valid monster? */ + otmp = which_armor(mtmp, W_SADDLE); + if (!otmp) { + pline("%s is not saddled.", Monnam(mtmp)); + return (FALSE); + } + ptr = mtmp->data; + if (touch_petrifies(ptr) && !Stone_resistance) { + char kbuf[BUFSZ]; - You("touch %s.", mon_nam(mtmp)); - Sprintf(kbuf, "attempting to ride %s", an(mtmp->data->mname)); - instapetrify(kbuf); - } - if (!mtmp->mtame || mtmp->isminion) { - pline("I think %s would mind.", mon_nam(mtmp)); - return (FALSE); - } - if (mtmp->mtrapped) { - struct trap *t = t_at(mtmp->mx, mtmp->my); + You("touch %s.", mon_nam(mtmp)); + Sprintf(kbuf, "attempting to ride %s", an(mtmp->data->mname)); + instapetrify(kbuf); + } + if (!mtmp->mtame || mtmp->isminion) { + pline("I think %s would mind.", mon_nam(mtmp)); + return (FALSE); + } + if (mtmp->mtrapped) { + struct trap *t = t_at(mtmp->mx, mtmp->my); - You_cant("mount %s while %s's trapped in %s.", - mon_nam(mtmp), mhe(mtmp), - an(defsyms[trap_to_defsym(t->ttyp)].explanation)); - return (FALSE); - } + You_cant("mount %s while %s's trapped in %s.", mon_nam(mtmp), + mhe(mtmp), an(defsyms[trap_to_defsym(t->ttyp)].explanation)); + return (FALSE); + } - if (!force && !Role_if(PM_KNIGHT) && !(--mtmp->mtame)) { - /* no longer tame */ - newsym(mtmp->mx, mtmp->my); - pline("%s resists%s!", Monnam(mtmp), - mtmp->mleashed ? " and its leash comes off" : ""); - if (mtmp->mleashed) m_unleash(mtmp, FALSE); - return (FALSE); - } - if (!force && Underwater && !is_swimmer(ptr)) { - You_cant("ride that creature while under water."); - return (FALSE); - } - if (!can_saddle(mtmp) || !can_ride(mtmp)) { - You_cant("ride such a creature."); - return (0); - } + if (!force && !Role_if(PM_KNIGHT) && !(--mtmp->mtame)) { + /* no longer tame */ + newsym(mtmp->mx, mtmp->my); + pline("%s resists%s!", Monnam(mtmp), + mtmp->mleashed ? " and its leash comes off" : ""); + if (mtmp->mleashed) + m_unleash(mtmp, FALSE); + return (FALSE); + } + if (!force && Underwater && !is_swimmer(ptr)) { + You_cant("ride that creature while under water."); + return (FALSE); + } + if (!can_saddle(mtmp) || !can_ride(mtmp)) { + You_cant("ride such a creature."); + return (0); + } - /* Is the player impaired? */ - if (!force && !is_floater(ptr) && !is_flyer(ptr) && - Levitation && !Lev_at_will) { - You("cannot reach %s.", mon_nam(mtmp)); - return (FALSE); - } - if (!force && uarm && is_metallic(uarm) && - greatest_erosion(uarm)) { - Your("%s armor is too stiff to be able to mount %s.", - uarm->oeroded ? "rusty" : "corroded", - mon_nam(mtmp)); - return (FALSE); - } - if (!force && (Confusion || Fumbling || Glib || Wounded_legs || - otmp->cursed || (u.ulevel+mtmp->mtame < rnd(MAXULEV/2+5)))) { - if (Levitation) { - pline("%s slips away from you.", Monnam(mtmp)); - return FALSE; - } - You("slip while trying to get on %s.", mon_nam(mtmp)); + /* Is the player impaired? */ + if (!force && !is_floater(ptr) && !is_flyer(ptr) && Levitation + && !Lev_at_will) { + You("cannot reach %s.", mon_nam(mtmp)); + return (FALSE); + } + if (!force && uarm && is_metallic(uarm) && greatest_erosion(uarm)) { + Your("%s armor is too stiff to be able to mount %s.", + uarm->oeroded ? "rusty" : "corroded", mon_nam(mtmp)); + return (FALSE); + } + if (!force + && (Confusion || Fumbling || Glib || Wounded_legs || otmp->cursed + || (u.ulevel + mtmp->mtame < rnd(MAXULEV / 2 + 5)))) { + if (Levitation) { + pline("%s slips away from you.", Monnam(mtmp)); + return FALSE; + } + You("slip while trying to get on %s.", mon_nam(mtmp)); - Sprintf(buf, "slipped while mounting %s", - /* "a saddled mumak" or "a saddled pony called Dobbin" */ - x_monnam(mtmp, ARTICLE_A, (char *)0, - SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_HALLUCINATION, - TRUE)); - losehp(Maybe_Half_Phys(rn1(5,10)), buf, NO_KILLER_PREFIX); - return (FALSE); - } + Sprintf(buf, "slipped while mounting %s", + /* "a saddled mumak" or "a saddled pony called Dobbin" */ + x_monnam(mtmp, ARTICLE_A, (char *) 0, + SUPPRESS_IT | SUPPRESS_INVISIBLE + | SUPPRESS_HALLUCINATION, + TRUE)); + losehp(Maybe_Half_Phys(rn1(5, 10)), buf, NO_KILLER_PREFIX); + return (FALSE); + } - /* Success */ - maybewakesteed(mtmp); - if (!force) { - if (Levitation && !is_floater(ptr) && !is_flyer(ptr)) - /* Must have Lev_at_will at this point */ - pline("%s magically floats up!", Monnam(mtmp)); - You("mount %s.", mon_nam(mtmp)); - } - /* setuwep handles polearms differently when you're mounted */ - if (uwep && is_pole(uwep)) unweapon = FALSE; - u.usteed = mtmp; - remove_monster(mtmp->mx, mtmp->my); - teleds(mtmp->mx, mtmp->my, TRUE); - return (TRUE); + /* Success */ + maybewakesteed(mtmp); + if (!force) { + if (Levitation && !is_floater(ptr) && !is_flyer(ptr)) + /* Must have Lev_at_will at this point */ + pline("%s magically floats up!", Monnam(mtmp)); + You("mount %s.", mon_nam(mtmp)); + } + /* setuwep handles polearms differently when you're mounted */ + if (uwep && is_pole(uwep)) + unweapon = FALSE; + u.usteed = mtmp; + remove_monster(mtmp->mx, mtmp->my); + teleds(mtmp->mx, mtmp->my, TRUE); + return (TRUE); } - /* You and your steed have moved */ void exercise_steed() { - if (!u.usteed) - return; + if (!u.usteed) + return; - /* It takes many turns of riding to exercise skill */ - if (u.urideturns++ >= 100) { - u.urideturns = 0; - use_skill(P_RIDING, 1); - } - return; + /* It takes many turns of riding to exercise skill */ + if (u.urideturns++ >= 100) { + u.urideturns = 0; + use_skill(P_RIDING, 1); + } + return; } - /* The player kicks or whips the steed */ void kick_steed() { - char He[4]; - if (!u.usteed) - return; + char He[4]; + if (!u.usteed) + return; - /* [ALI] Various effects of kicking sleeping/paralyzed steeds */ - if (u.usteed->msleeping || !u.usteed->mcanmove) { - /* We assume a message has just been output of the form - * "You kick ." - */ - Strcpy(He, mhe(u.usteed)); - *He = highc(*He); - if ((u.usteed->mcanmove || u.usteed->mfrozen) && !rn2(2)) { - if (u.usteed->mcanmove) - u.usteed->msleeping = 0; - else if (u.usteed->mfrozen > 2) - u.usteed->mfrozen -= 2; - else { - u.usteed->mfrozen = 0; - u.usteed->mcanmove = 1; - } - if (u.usteed->msleeping || !u.usteed->mcanmove) - pline("%s stirs.", He); - else - pline("%s rouses %sself!", He, mhim(u.usteed)); - } else - pline("%s does not respond.", He); - return; - } + /* [ALI] Various effects of kicking sleeping/paralyzed steeds */ + if (u.usteed->msleeping || !u.usteed->mcanmove) { + /* We assume a message has just been output of the form + * "You kick ." + */ + Strcpy(He, mhe(u.usteed)); + *He = highc(*He); + if ((u.usteed->mcanmove || u.usteed->mfrozen) && !rn2(2)) { + if (u.usteed->mcanmove) + u.usteed->msleeping = 0; + else if (u.usteed->mfrozen > 2) + u.usteed->mfrozen -= 2; + else { + u.usteed->mfrozen = 0; + u.usteed->mcanmove = 1; + } + if (u.usteed->msleeping || !u.usteed->mcanmove) + pline("%s stirs.", He); + else + pline("%s rouses %sself!", He, mhim(u.usteed)); + } else + pline("%s does not respond.", He); + return; + } - /* Make the steed less tame and check if it resists */ - if (u.usteed->mtame) u.usteed->mtame--; - if (!u.usteed->mtame && u.usteed->mleashed) m_unleash(u.usteed, TRUE); - if (!u.usteed->mtame || (u.ulevel+u.usteed->mtame < rnd(MAXULEV/2+5))) { - newsym(u.usteed->mx, u.usteed->my); - dismount_steed(DISMOUNT_THROWN); - return; - } + /* Make the steed less tame and check if it resists */ + if (u.usteed->mtame) + u.usteed->mtame--; + if (!u.usteed->mtame && u.usteed->mleashed) + m_unleash(u.usteed, TRUE); + if (!u.usteed->mtame + || (u.ulevel + u.usteed->mtame < rnd(MAXULEV / 2 + 5))) { + newsym(u.usteed->mx, u.usteed->my); + dismount_steed(DISMOUNT_THROWN); + return; + } - pline("%s gallops!", Monnam(u.usteed)); - u.ugallop += rn1(20, 30); - return; + pline("%s gallops!", Monnam(u.usteed)); + u.ugallop += rn1(20, 30); + return; } /* @@ -412,7 +410,7 @@ kick_steed() */ STATIC_OVL boolean landing_spot(spot, reason, forceit) -coord *spot; /* landing position (we fill it in) */ +coord *spot; /* landing position (we fill it in) */ int reason; int forceit; { @@ -421,33 +419,35 @@ int forceit; struct trap *t; /* avoid known traps (i == 0) and boulders, but allow them as a backup */ - if (reason != DISMOUNT_BYCHOICE || Stunned || Confusion || Fumbling) i = 1; + if (reason != DISMOUNT_BYCHOICE || Stunned || Confusion || Fumbling) + i = 1; for (; !found && i < 2; ++i) { - for (x = u.ux-1; x <= u.ux+1; x++) - for (y = u.uy-1; y <= u.uy+1; y++) { - if (!isok(x, y) || (x == u.ux && y == u.uy)) continue; + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (!isok(x, y) || (x == u.ux && y == u.uy)) + continue; - if (accessible(x, y) && !MON_AT(x,y)) { - distance = distu(x,y); - if (min_distance < 0 || distance < min_distance || - (distance == min_distance && rn2(2))) { - if (i > 0 || (((t = t_at(x, y)) == 0 || !t->tseen) && - (!sobj_at(BOULDER, x, y) || - throws_rocks(youmonst.data)))) { - spot->x = x; - spot->y = y; - min_distance = distance; - found = TRUE; - } - } - } - } + if (accessible(x, y) && !MON_AT(x, y)) { + distance = distu(x, y); + if (min_distance < 0 || distance < min_distance + || (distance == min_distance && rn2(2))) { + if (i > 0 || (((t = t_at(x, y)) == 0 || !t->tseen) + && (!sobj_at(BOULDER, x, y) + || throws_rocks(youmonst.data)))) { + spot->x = x; + spot->y = y; + min_distance = distance; + found = TRUE; + } + } + } + } } /* If we didn't find a good spot and forceit is on, try enexto(). */ - if (forceit && min_distance < 0 && - !enexto(spot, u.ux, u.uy, youmonst.data)) - return FALSE; + if (forceit && min_distance < 0 + && !enexto(spot, u.ux, u.uy, youmonst.data)) + return FALSE; return found; } @@ -455,167 +455,171 @@ int forceit; /* Stop riding the current steed */ void dismount_steed(reason) - int reason; /* Player was thrown off etc. */ +int reason; /* Player was thrown off etc. */ { - struct monst *mtmp; - struct obj *otmp; - coord cc; - const char *verb = "fall"; - boolean repair_leg_damage = (Wounded_legs != 0L); - unsigned save_utrap = u.utrap; - boolean have_spot = landing_spot(&cc,reason,0); - - mtmp = u.usteed; /* make a copy of steed pointer */ - /* Sanity check */ - if (!mtmp) /* Just return silently */ - return; + struct monst *mtmp; + struct obj *otmp; + coord cc; + const char *verb = "fall"; + boolean repair_leg_damage = (Wounded_legs != 0L); + unsigned save_utrap = u.utrap; + boolean have_spot = landing_spot(&cc, reason, 0); - /* Check the reason for dismounting */ - otmp = which_armor(mtmp, W_SADDLE); - switch (reason) { - case DISMOUNT_THROWN: - verb = "are thrown"; - case DISMOUNT_FELL: - You("%s off of %s!", verb, mon_nam(mtmp)); - if (!have_spot) have_spot = landing_spot(&cc,reason,1); - losehp(Maybe_Half_Phys(rn1(10,10)), "riding accident", KILLED_BY_AN); - set_wounded_legs(BOTH_SIDES, (int)HWounded_legs + rn1(5,5)); - repair_leg_damage = FALSE; - break; - case DISMOUNT_POLY: - You("can no longer ride %s.", mon_nam(u.usteed)); - if (!have_spot) have_spot = landing_spot(&cc,reason,1); - break; - case DISMOUNT_ENGULFED: - /* caller displays message */ - break; - case DISMOUNT_BONES: - /* hero has just died... */ - break; - case DISMOUNT_GENERIC: - /* no messages, just make it so */ - break; - case DISMOUNT_BYCHOICE: - default: - if (otmp && otmp->cursed) { - You("can't. The saddle %s cursed.", - otmp->bknown ? "is" : "seems to be"); - otmp->bknown = TRUE; - return; - } - if (!have_spot) { - You("can't. There isn't anywhere for you to stand."); - return; - } - if (!has_mname(mtmp)) { - pline("You've been through the dungeon on %s with no name.", - an(mtmp->data->mname)); - if (Hallucination) - pline("It felt good to get out of the rain."); - } else - You("dismount %s.", mon_nam(mtmp)); - } - /* While riding, Wounded_legs refers to the steed's legs; - after dismounting, it reverts to the hero's legs. */ - if (repair_leg_damage) { - /* [TODO: make heal_legs() take a parameter to handle this] */ - in_steed_dismounting = TRUE; - heal_legs(); - in_steed_dismounting = FALSE; - } + mtmp = u.usteed; /* make a copy of steed pointer */ + /* Sanity check */ + if (!mtmp) /* Just return silently */ + return; - /* Release the steed and saddle */ - u.usteed = 0; - u.ugallop = 0L; + /* Check the reason for dismounting */ + otmp = which_armor(mtmp, W_SADDLE); + switch (reason) { + case DISMOUNT_THROWN: + verb = "are thrown"; + case DISMOUNT_FELL: + You("%s off of %s!", verb, mon_nam(mtmp)); + if (!have_spot) + have_spot = landing_spot(&cc, reason, 1); + losehp(Maybe_Half_Phys(rn1(10, 10)), "riding accident", KILLED_BY_AN); + set_wounded_legs(BOTH_SIDES, (int) HWounded_legs + rn1(5, 5)); + repair_leg_damage = FALSE; + break; + case DISMOUNT_POLY: + You("can no longer ride %s.", mon_nam(u.usteed)); + if (!have_spot) + have_spot = landing_spot(&cc, reason, 1); + break; + case DISMOUNT_ENGULFED: + /* caller displays message */ + break; + case DISMOUNT_BONES: + /* hero has just died... */ + break; + case DISMOUNT_GENERIC: + /* no messages, just make it so */ + break; + case DISMOUNT_BYCHOICE: + default: + if (otmp && otmp->cursed) { + You("can't. The saddle %s cursed.", + otmp->bknown ? "is" : "seems to be"); + otmp->bknown = TRUE; + return; + } + if (!have_spot) { + You("can't. There isn't anywhere for you to stand."); + return; + } + if (!has_mname(mtmp)) { + pline("You've been through the dungeon on %s with no name.", + an(mtmp->data->mname)); + if (Hallucination) + pline("It felt good to get out of the rain."); + } else + You("dismount %s.", mon_nam(mtmp)); + } + /* While riding, Wounded_legs refers to the steed's legs; + after dismounting, it reverts to the hero's legs. */ + if (repair_leg_damage) { + /* [TODO: make heal_legs() take a parameter to handle this] */ + in_steed_dismounting = TRUE; + heal_legs(); + in_steed_dismounting = FALSE; + } - /* Set player and steed's position. Try moving the player first - unless we're in the midst of creating a bones file. */ - if (reason == DISMOUNT_BONES) { - /* move the steed to an adjacent square */ - if (enexto(&cc, u.ux, u.uy, mtmp->data)) - rloc_to(mtmp, cc.x, cc.y); - else /* evidently no room nearby; move steed elsewhere */ - (void) rloc(mtmp, FALSE); - return; - } - if (mtmp->mhp > 0) { - place_monster(mtmp, u.ux, u.uy); - if (!u.uswallow && !u.ustuck && have_spot) { - struct permonst *mdat = mtmp->data; + /* Release the steed and saddle */ + u.usteed = 0; + u.ugallop = 0L; - /* The steed may drop into water/lava */ - if (!is_flyer(mdat) && !is_floater(mdat) && !is_clinger(mdat)) { - if (is_pool(u.ux, u.uy)) { - if (!Underwater) - pline("%s falls into the %s!", Monnam(mtmp), - surface(u.ux, u.uy)); - if (!is_swimmer(mdat) && !amphibious(mdat)) { - killed(mtmp); - adjalign(-1); - } - } else if (is_lava(u.ux, u.uy)) { - pline("%s is pulled into the lava!", Monnam(mtmp)); - if (!likes_lava(mdat)) { - killed(mtmp); - adjalign(-1); - } - } - } - /* Steed dismounting consists of two steps: being moved to another - * square, and descending to the floor. We have functions to do - * each of these activities, but they're normally called - * individually and include an attempt to look at or pick up the - * objects on the floor: - * teleds() --> spoteffects() --> pickup() - * float_down() --> pickup() - * We use this kludge to make sure there is only one such attempt. - * - * Clearly this is not the best way to do it. A full fix would - * involve having these functions not call pickup() at all, instead - * calling them first and calling pickup() afterwards. But it - * would take a lot of work to keep this change from having any - * unforseen side effects (for instance, you would no longer be - * able to walk onto a square with a hole, and autopickup before - * falling into the hole). - */ - /* [ALI] No need to move the player if the steed died. */ - if (mtmp->mhp > 0) { - /* Keep steed here, move the player to cc; - * teleds() clears u.utrap - */ - in_steed_dismounting = TRUE; - teleds(cc.x, cc.y, TRUE); - in_steed_dismounting = FALSE; + /* Set player and steed's position. Try moving the player first + unless we're in the midst of creating a bones file. */ + if (reason == DISMOUNT_BONES) { + /* move the steed to an adjacent square */ + if (enexto(&cc, u.ux, u.uy, mtmp->data)) + rloc_to(mtmp, cc.x, cc.y); + else /* evidently no room nearby; move steed elsewhere */ + (void) rloc(mtmp, FALSE); + return; + } + if (mtmp->mhp > 0) { + place_monster(mtmp, u.ux, u.uy); + if (!u.uswallow && !u.ustuck && have_spot) { + struct permonst *mdat = mtmp->data; - /* Put your steed in your trap */ - if (save_utrap) - (void) mintrap(mtmp); - } - /* Couldn't... try placing the steed */ - } else if (enexto(&cc, u.ux, u.uy, mtmp->data)) { - /* Keep player here, move the steed to cc */ - rloc_to(mtmp, cc.x, cc.y); - /* Player stays put */ - /* Otherwise, kill the steed */ - } else { - killed(mtmp); - adjalign(-1); - } - } + /* The steed may drop into water/lava */ + if (!is_flyer(mdat) && !is_floater(mdat) && !is_clinger(mdat)) { + if (is_pool(u.ux, u.uy)) { + if (!Underwater) + pline("%s falls into the %s!", Monnam(mtmp), + surface(u.ux, u.uy)); + if (!is_swimmer(mdat) && !amphibious(mdat)) { + killed(mtmp); + adjalign(-1); + } + } else if (is_lava(u.ux, u.uy)) { + pline("%s is pulled into the lava!", Monnam(mtmp)); + if (!likes_lava(mdat)) { + killed(mtmp); + adjalign(-1); + } + } + } + /* Steed dismounting consists of two steps: being moved to another + * square, and descending to the floor. We have functions to do + * each of these activities, but they're normally called + * individually and include an attempt to look at or pick up the + * objects on the floor: + * teleds() --> spoteffects() --> pickup() + * float_down() --> pickup() + * We use this kludge to make sure there is only one such attempt. + * + * Clearly this is not the best way to do it. A full fix would + * involve having these functions not call pickup() at all, + * instead + * calling them first and calling pickup() afterwards. But it + * would take a lot of work to keep this change from having any + * unforseen side effects (for instance, you would no longer be + * able to walk onto a square with a hole, and autopickup before + * falling into the hole). + */ + /* [ALI] No need to move the player if the steed died. */ + if (mtmp->mhp > 0) { + /* Keep steed here, move the player to cc; + * teleds() clears u.utrap + */ + in_steed_dismounting = TRUE; + teleds(cc.x, cc.y, TRUE); + in_steed_dismounting = FALSE; - /* Return the player to the floor */ - if (reason != DISMOUNT_ENGULFED) { - in_steed_dismounting = TRUE; - (void) float_down(0L, W_SADDLE); - in_steed_dismounting = FALSE; - context.botl = 1; - (void)encumber_msg(); - vision_full_recalc = 1; - } else - context.botl = 1; - /* polearms behave differently when not mounted */ - if (uwep && is_pole(uwep)) unweapon = TRUE; - return; + /* Put your steed in your trap */ + if (save_utrap) + (void) mintrap(mtmp); + } + /* Couldn't... try placing the steed */ + } else if (enexto(&cc, u.ux, u.uy, mtmp->data)) { + /* Keep player here, move the steed to cc */ + rloc_to(mtmp, cc.x, cc.y); + /* Player stays put */ + /* Otherwise, kill the steed */ + } else { + killed(mtmp); + adjalign(-1); + } + } + + /* Return the player to the floor */ + if (reason != DISMOUNT_ENGULFED) { + in_steed_dismounting = TRUE; + (void) float_down(0L, W_SADDLE); + in_steed_dismounting = FALSE; + context.botl = 1; + (void) encumber_msg(); + vision_full_recalc = 1; + } else + context.botl = 1; + /* polearms behave differently when not mounted */ + if (uwep && is_pole(uwep)) + unweapon = TRUE; + return; } /* when attempting to saddle or mount a sleeping steed, try to wake it up @@ -629,18 +633,18 @@ struct monst *steed; steed->msleeping = 0; if (frozen) { - frozen = (frozen + 1) / 2; /* half */ - /* might break out of timed sleep or paralysis */ - if (!rn2(frozen)) { - steed->mfrozen = 0; - steed->mcanmove = 1; - } else { - /* didn't awake, but remaining duration is halved */ - steed->mfrozen = frozen; - } + frozen = (frozen + 1) / 2; /* half */ + /* might break out of timed sleep or paralysis */ + if (!rn2(frozen)) { + steed->mfrozen = 0; + steed->mcanmove = 1; + } else { + /* didn't awake, but remaining duration is halved */ + steed->mfrozen = frozen; + } } if (wasimmobile && !steed->msleeping && steed->mcanmove) - pline("%s wakes up.", Monnam(steed)); + pline("%s wakes up.", Monnam(steed)); /* regardless of waking, terminate any meal in progress */ finish_meating(steed); } @@ -654,16 +658,16 @@ boolean checkfeeding; struct monst *steed = u.usteed; if (steed) { - /* check whether steed can move */ - if (steed->msleeping || !steed->mcanmove) { - pline("%s won't move!", upstart(y_monnam(steed))); - return TRUE; - } - /* optionally check whether steed is in the midst of a meal */ - if (checkfeeding && steed->meating) { - pline("%s is still eating.", upstart(y_monnam(steed))); - return TRUE; - } + /* check whether steed can move */ + if (steed->msleeping || !steed->mcanmove) { + pline("%s won't move!", upstart(y_monnam(steed))); + return TRUE; + } + /* optionally check whether steed is in the midst of a meal */ + if (checkfeeding && steed->meating) { + pline("%s is still eating.", upstart(y_monnam(steed))); + return TRUE; + } } return FALSE; } @@ -674,11 +678,11 @@ struct monst *mon; int x, y; { if (mon == u.usteed || - /* special case is for convoluted vault guard handling */ - (DEADMONSTER(mon) && !(mon->isgd && x == 0 && y == 0))) { - impossible("placing %s onto map?", - (mon == u.usteed) ? "steed" : "defunct monster"); - return; + /* special case is for convoluted vault guard handling */ + (DEADMONSTER(mon) && !(mon->isgd && x == 0 && y == 0))) { + impossible("placing %s onto map?", + (mon == u.usteed) ? "steed" : "defunct monster"); + return; } mon->mx = x, mon->my = y; level.monsters[x][y] = mon; diff --git a/src/sys.c b/src/sys.c index 7142309a7..241021951 100644 --- a/src/sys.c +++ b/src/sys.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sys.c $NHDT-Date: 1426544797 2015/03/16 22:26:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */ +/* NetHack 3.6 sys.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */ /* NetHack 3.6 sys.c $Date: 2012/03/10 02:22:07 $ $Revision: 1.12 $ */ /* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -19,75 +19,78 @@ struct sysopt sysopt; void sys_early_init() { - sysopt.support = NULL; - sysopt.recover = NULL; + sysopt.support = NULL; + sysopt.recover = NULL; #ifdef SYSCF - sysopt.wizards = NULL; + sysopt.wizards = NULL; #else - sysopt.wizards = dupstr(WIZARD_NAME); + sysopt.wizards = dupstr(WIZARD_NAME); #endif #if defined(SYSCF) || !defined(DEBUGFILES) - sysopt.debugfiles = NULL; + sysopt.debugfiles = NULL; #else - sysopt.debugfiles = dupstr(DEBUGFILES); + sysopt.debugfiles = dupstr(DEBUGFILES); #endif - sysopt.env_dbgfl = 0; /* haven't checked getenv("DEBUGFILES") yet */ - sysopt.shellers = NULL; - sysopt.explorers = NULL; - sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */ + sysopt.env_dbgfl = 0; /* haven't checked getenv("DEBUGFILES") yet */ + sysopt.shellers = NULL; + sysopt.explorers = NULL; + sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */ - /* record file */ - sysopt.persmax = PERSMAX; - sysopt.entrymax = ENTRYMAX; - sysopt.pointsmin = POINTSMIN; - sysopt.pers_is_uid = PERS_IS_UID; - sysopt.tt_oname_maxrank = 10; + /* record file */ + sysopt.persmax = PERSMAX; + sysopt.entrymax = ENTRYMAX; + sysopt.pointsmin = POINTSMIN; + sysopt.pers_is_uid = PERS_IS_UID; + sysopt.tt_oname_maxrank = 10; - /* sanity checks */ - if(PERSMAX<1) sysopt.persmax = 1; - if(ENTRYMAX<10) sysopt.entrymax = 10; - if(POINTSMIN<1) sysopt.pointsmin = 1; - if(PERS_IS_UID != 0 && PERS_IS_UID != 1) - panic("config error: PERS_IS_UID must be either 0 or 1"); + /* sanity checks */ + if (PERSMAX < 1) + sysopt.persmax = 1; + if (ENTRYMAX < 10) + sysopt.entrymax = 10; + if (POINTSMIN < 1) + sysopt.pointsmin = 1; + if (PERS_IS_UID != 0 && PERS_IS_UID != 1) + panic("config error: PERS_IS_UID must be either 0 or 1"); #ifdef PANICTRACE - /* panic options */ - sysopt.gdbpath = dupstr(GDBPATH); - sysopt.greppath = dupstr(GREPPATH); -# ifdef BETA - sysopt.panictrace_gdb = 1; -# ifdef PANICTRACE_LIBC - sysopt.panictrace_libc = 2; -# endif -# else - sysopt.panictrace_gdb = 0; -# ifdef PANICTRACE_LIBC - sysopt.panictrace_libc = 0; -# endif -# endif + /* panic options */ + sysopt.gdbpath = dupstr(GDBPATH); + sysopt.greppath = dupstr(GREPPATH); +#ifdef BETA + sysopt.panictrace_gdb = 1; +#ifdef PANICTRACE_LIBC + sysopt.panictrace_libc = 2; +#endif +#else + sysopt.panictrace_gdb = 0; +#ifdef PANICTRACE_LIBC + sysopt.panictrace_libc = 0; +#endif +#endif #endif - sysopt.check_save_uid = 1; - sysopt.seduce = 1; /* if it's compiled in, default to on */ - sysopt_seduce_set(sysopt.seduce); + sysopt.check_save_uid = 1; + sysopt.seduce = 1; /* if it's compiled in, default to on */ + sysopt_seduce_set(sysopt.seduce); } void sysopt_release() { - if (sysopt.support) - free(sysopt.support), sysopt.support = NULL; - if (sysopt.recover) - free(sysopt.recover), sysopt.recover = NULL; - if (sysopt.wizards) - free(sysopt.wizards), sysopt.wizards = NULL; - if (sysopt.debugfiles) - free(sysopt.debugfiles), sysopt.debugfiles = NULL; + if (sysopt.support) + free(sysopt.support), sysopt.support = NULL; + if (sysopt.recover) + free(sysopt.recover), sysopt.recover = NULL; + if (sysopt.wizards) + free(sysopt.wizards), sysopt.wizards = NULL; + if (sysopt.debugfiles) + free(sysopt.debugfiles), sysopt.debugfiles = NULL; #ifdef PANICTRACE - if (sysopt.gdbpath) - free(sysopt.gdbpath), sysopt.gdbpath = NULL; - if (sysopt.greppath) - free (sysopt.greppath), sysopt.greppath = NULL; + if (sysopt.gdbpath) + free(sysopt.gdbpath), sysopt.gdbpath = NULL; + if (sysopt.greppath) + free(sysopt.greppath), sysopt.greppath = NULL; #endif } @@ -96,12 +99,12 @@ extern struct attack sa_no[NATTK]; void sysopt_seduce_set(val) - int val; +int val; { - struct attack *setval = val ? sa_yes : sa_no; - int x; - for(x=0; xmx - * != x || mtmp->my != y, we'd miss the case where we're called - * to place the worm segment and the worm's head is at x,y. - */ - if (mtmp2 && (mtmp2 != mtmp || mtmp->wormno)) - return FALSE; + /* Be careful with long worms. A monster may be placed back in + * its own location. Normally, if m_at() returns the same monster + * that we're trying to place, the monster is being placed in its + * own location. However, that is not correct for worm segments, + * because all the segments of the worm return the same m_at(). + * Actually we overdo the check a little bit--a worm can't be placed + * in its own location, period. If we just checked for mtmp->mx + * != x || mtmp->my != y, we'd miss the case where we're called + * to place the worm segment and the worm's head is at x,y. + */ + if (mtmp2 && (mtmp2 != mtmp || mtmp->wormno)) + return FALSE; - mdat = mtmp->data; - if (is_pool(x,y) && !ignorewater) { - if (mtmp == &youmonst) - return (Levitation || Flying || Wwalking || - Swimming || Amphibious); - else - return (is_floater(mdat) || is_flyer(mdat) || - is_swimmer(mdat) || is_clinger(mdat)); - } else if (mdat->mlet == S_EEL && rn2(13) && !ignorewater) { - return FALSE; - } else if (is_lava(x,y)) { - if (mtmp == &youmonst) - return (Levitation || Flying || - (Fire_resistance && Wwalking && - uarmf && uarmf->oerodeproof) || - (Upolyd && likes_lava(youmonst.data))); - else - return (is_floater(mdat) || is_flyer(mdat) || - likes_lava(mdat)); - } - if (passes_walls(mdat) && may_passwall(x,y)) return TRUE; - if (amorphous(mdat) && closed_door(x,y)) return TRUE; - } - if (!accessible(x, y)) { - if (!(is_pool(x,y) && ignorewater)) return FALSE; - } + mdat = mtmp->data; + if (is_pool(x, y) && !ignorewater) { + if (mtmp == &youmonst) + return (Levitation || Flying || Wwalking || Swimming + || Amphibious); + else + return (is_floater(mdat) || is_flyer(mdat) || is_swimmer(mdat) + || is_clinger(mdat)); + } else if (mdat->mlet == S_EEL && rn2(13) && !ignorewater) { + return FALSE; + } else if (is_lava(x, y)) { + if (mtmp == &youmonst) + return (Levitation || Flying + || (Fire_resistance && Wwalking && uarmf + && uarmf->oerodeproof) + || (Upolyd && likes_lava(youmonst.data))); + else + return (is_floater(mdat) || is_flyer(mdat) + || likes_lava(mdat)); + } + if (passes_walls(mdat) && may_passwall(x, y)) + return TRUE; + if (amorphous(mdat) && closed_door(x, y)) + return TRUE; + } + if (!accessible(x, y)) { + if (!(is_pool(x, y) && ignorewater)) + return FALSE; + } - if (sobj_at(BOULDER, x, y) && (!mdat || !throws_rocks(mdat))) - return FALSE; - return TRUE; + if (sobj_at(BOULDER, x, y) && (!mdat || !throws_rocks(mdat))) + return FALSE; + return TRUE; } /* @@ -104,7 +108,7 @@ coord *cc; register xchar xx, yy; struct permonst *mdat; { - return enexto_core(cc, xx, yy, mdat, 0); + return enexto_core(cc, xx, yy, mdat, 0); } boolean @@ -118,14 +122,14 @@ unsigned entflags; coord good[MAX_GOOD], *good_ptr; int x, y, range, i; int xmin, xmax, ymin, ymax; - struct monst fakemon; /* dummy monster */ + struct monst fakemon; /* dummy monster */ if (!mdat) { - debugpline0("enexto() called with null mdat"); - /* default to player's original monster type */ - mdat = &mons[u.umonster]; + debugpline0("enexto() called with null mdat"); + /* default to player's original monster type */ + mdat = &mons[u.umonster]; } - fakemon.data = mdat; /* set up for goodpos */ + fakemon.data = mdat; /* set up for goodpos */ good_ptr = good; range = 1; /* @@ -133,47 +137,52 @@ unsigned entflags; * radius range. Stop when we find at least one valid position. */ do { - xmin = max(1, xx-range); - xmax = min(COLNO-1, xx+range); - ymin = max(0, yy-range); - ymax = min(ROWNO-1, yy+range); + xmin = max(1, xx - range); + xmax = min(COLNO - 1, xx + range); + ymin = max(0, yy - range); + ymax = min(ROWNO - 1, yy + range); - for (x = xmin; x <= xmax; x++) - if (goodpos(x, ymin, &fakemon, entflags)) { - good_ptr->x = x; - good_ptr->y = ymin ; - /* beware of accessing beyond segment boundaries.. */ - if (good_ptr++ == &good[MAX_GOOD-1]) goto full; - } - for (x = xmin; x <= xmax; x++) - if (goodpos(x, ymax, &fakemon, entflags)) { - good_ptr->x = x; - good_ptr->y = ymax ; - /* beware of accessing beyond segment boundaries.. */ - if (good_ptr++ == &good[MAX_GOOD-1]) goto full; - } - for (y = ymin+1; y < ymax; y++) - if (goodpos(xmin, y, &fakemon, entflags)) { - good_ptr->x = xmin; - good_ptr-> y = y ; - /* beware of accessing beyond segment boundaries.. */ - if (good_ptr++ == &good[MAX_GOOD-1]) goto full; - } - for (y = ymin+1; y < ymax; y++) - if (goodpos(xmax, y, &fakemon, entflags)) { - good_ptr->x = xmax; - good_ptr->y = y ; - /* beware of accessing beyond segment boundaries.. */ - if (good_ptr++ == &good[MAX_GOOD-1]) goto full; - } - range++; + for (x = xmin; x <= xmax; x++) + if (goodpos(x, ymin, &fakemon, entflags)) { + good_ptr->x = x; + good_ptr->y = ymin; + /* beware of accessing beyond segment boundaries.. */ + if (good_ptr++ == &good[MAX_GOOD - 1]) + goto full; + } + for (x = xmin; x <= xmax; x++) + if (goodpos(x, ymax, &fakemon, entflags)) { + good_ptr->x = x; + good_ptr->y = ymax; + /* beware of accessing beyond segment boundaries.. */ + if (good_ptr++ == &good[MAX_GOOD - 1]) + goto full; + } + for (y = ymin + 1; y < ymax; y++) + if (goodpos(xmin, y, &fakemon, entflags)) { + good_ptr->x = xmin; + good_ptr->y = y; + /* beware of accessing beyond segment boundaries.. */ + if (good_ptr++ == &good[MAX_GOOD - 1]) + goto full; + } + for (y = ymin + 1; y < ymax; y++) + if (goodpos(xmax, y, &fakemon, entflags)) { + good_ptr->x = xmax; + good_ptr->y = y; + /* beware of accessing beyond segment boundaries.. */ + if (good_ptr++ == &good[MAX_GOOD - 1]) + goto full; + } + range++; - /* return if we've grown too big (nothing is valid) */ - if (range > ROWNO && range > COLNO) return FALSE; + /* return if we've grown too big (nothing is valid) */ + if (range > ROWNO && range > COLNO) + return FALSE; } while (good_ptr == good); full: - i = rn2((int)(good_ptr - good)); + i = rn2((int) (good_ptr - good)); cc->x = good[i].x; cc->y = good[i].y; return TRUE; @@ -188,33 +197,33 @@ STATIC_OVL boolean tele_jump_ok(x1, y1, x2, y2) int x1, y1, x2, y2; { - if (dndest.nlx > 0) { - /* if inside a restricted region, can't teleport outside */ - if (within_bounded_area(x1, y1, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy) && - !within_bounded_area(x2, y2, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy)) - return FALSE; - /* and if outside, can't teleport inside */ - if (!within_bounded_area(x1, y1, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy) && - within_bounded_area(x2, y2, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy)) - return FALSE; - } - if (updest.nlx > 0) { /* ditto */ - if (within_bounded_area(x1, y1, updest.nlx, updest.nly, - updest.nhx, updest.nhy) && - !within_bounded_area(x2, y2, updest.nlx, updest.nly, - updest.nhx, updest.nhy)) - return FALSE; - if (!within_bounded_area(x1, y1, updest.nlx, updest.nly, - updest.nhx, updest.nhy) && - within_bounded_area(x2, y2, updest.nlx, updest.nly, - updest.nhx, updest.nhy)) - return FALSE; - } - return TRUE; + if (dndest.nlx > 0) { + /* if inside a restricted region, can't teleport outside */ + if (within_bounded_area(x1, y1, dndest.nlx, dndest.nly, dndest.nhx, + dndest.nhy) + && !within_bounded_area(x2, y2, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy)) + return FALSE; + /* and if outside, can't teleport inside */ + if (!within_bounded_area(x1, y1, dndest.nlx, dndest.nly, dndest.nhx, + dndest.nhy) + && within_bounded_area(x2, y2, dndest.nlx, dndest.nly, dndest.nhx, + dndest.nhy)) + return FALSE; + } + if (updest.nlx > 0) { /* ditto */ + if (within_bounded_area(x1, y1, updest.nlx, updest.nly, updest.nhx, + updest.nhy) + && !within_bounded_area(x2, y2, updest.nlx, updest.nly, + updest.nhx, updest.nhy)) + return FALSE; + if (!within_bounded_area(x1, y1, updest.nlx, updest.nly, updest.nhx, + updest.nhy) + && within_bounded_area(x2, y2, updest.nlx, updest.nly, updest.nhx, + updest.nhy)) + return FALSE; + } + return TRUE; } STATIC_OVL boolean @@ -222,149 +231,153 @@ teleok(x, y, trapok) register int x, y; boolean trapok; { - if (!trapok && t_at(x, y)) return FALSE; - if (!goodpos(x, y, &youmonst, 0)) return FALSE; - if (!tele_jump_ok(u.ux, u.uy, x, y)) return FALSE; - if (!in_out_region(x, y)) return FALSE; - return TRUE; + if (!trapok && t_at(x, y)) + return FALSE; + if (!goodpos(x, y, &youmonst, 0)) + return FALSE; + if (!tele_jump_ok(u.ux, u.uy, x, y)) + return FALSE; + if (!in_out_region(x, y)) + return FALSE; + return TRUE; } void teleds(nux, nuy, allow_drag) -register int nux,nuy; +register int nux, nuy; boolean allow_drag; { - boolean ball_active, ball_still_in_range; + boolean ball_active, ball_still_in_range; - if (u.utraptype == TT_BURIEDBALL) { - /* unearth it */ - buried_ball_to_punishment(); - } - ball_active = (Punished && uball->where != OBJ_FREE), - ball_still_in_range = FALSE; + if (u.utraptype == TT_BURIEDBALL) { + /* unearth it */ + buried_ball_to_punishment(); + } + ball_active = (Punished && uball->where != OBJ_FREE), + ball_still_in_range = FALSE; - /* If they have to move the ball, then drag if allow_drag is true; - * otherwise they are teleporting, so unplacebc(). - * If they don't have to move the ball, then always "drag" whether or - * not allow_drag is true, because we are calling that function, not - * to drag, but to move the chain. *However* there are some dumb - * special cases: - * 0 0 - * _X move east -----> X_ - * @ @ - * These are permissible if teleporting, but not if dragging. As a - * result, drag_ball() needs to know about allow_drag and might end - * up dragging the ball anyway. Also, drag_ball() might find that - * dragging the ball is completely impossible (ball in range but there's - * rock in the way), in which case it teleports the ball on its own. - */ - if (ball_active) { - if (!carried(uball) && distmin(nux, nuy, uball->ox, uball->oy) <= 2) - ball_still_in_range = TRUE; /* don't have to move the ball */ - else { - /* have to move the ball */ - if (!allow_drag || distmin(u.ux, u.uy, nux, nuy) > 1) { - /* we should not have dist > 1 and allow_drag at the same - * time, but just in case, we must then revert to teleport. - */ - allow_drag = FALSE; - unplacebc(); - } - } - } - u.utrap = 0; - u.ustuck = 0; - u.ux0 = u.ux; - u.uy0 = u.uy; + /* If they have to move the ball, then drag if allow_drag is true; + * otherwise they are teleporting, so unplacebc(). + * If they don't have to move the ball, then always "drag" whether or + * not allow_drag is true, because we are calling that function, not + * to drag, but to move the chain. *However* there are some dumb + * special cases: + * 0 0 + * _X move east -----> X_ + * @ @ + * These are permissible if teleporting, but not if dragging. As a + * result, drag_ball() needs to know about allow_drag and might end + * up dragging the ball anyway. Also, drag_ball() might find that + * dragging the ball is completely impossible (ball in range but there's + * rock in the way), in which case it teleports the ball on its own. + */ + if (ball_active) { + if (!carried(uball) && distmin(nux, nuy, uball->ox, uball->oy) <= 2) + ball_still_in_range = TRUE; /* don't have to move the ball */ + else { + /* have to move the ball */ + if (!allow_drag || distmin(u.ux, u.uy, nux, nuy) > 1) { + /* we should not have dist > 1 and allow_drag at the same + * time, but just in case, we must then revert to teleport. + */ + allow_drag = FALSE; + unplacebc(); + } + } + } + u.utrap = 0; + u.ustuck = 0; + u.ux0 = u.ux; + u.uy0 = u.uy; - if (!hideunder(&youmonst) && youmonst.data->mlet == S_MIMIC) { - /* mimics stop being unnoticed */ - youmonst.m_ap_type = M_AP_NOTHING; - } + if (!hideunder(&youmonst) && youmonst.data->mlet == S_MIMIC) { + /* mimics stop being unnoticed */ + youmonst.m_ap_type = M_AP_NOTHING; + } - if (u.uswallow) { - u.uswldtim = u.uswallow = 0; - if (Punished && !ball_active) { - /* ensure ball placement, like unstuck */ - ball_active = TRUE; - allow_drag = FALSE; - } - docrt(); - } - if (ball_active) { - if (ball_still_in_range || allow_drag) { - int bc_control; - xchar ballx, bally, chainx, chainy; - boolean cause_delay; + if (u.uswallow) { + u.uswldtim = u.uswallow = 0; + if (Punished && !ball_active) { + /* ensure ball placement, like unstuck */ + ball_active = TRUE; + allow_drag = FALSE; + } + docrt(); + } + if (ball_active) { + if (ball_still_in_range || allow_drag) { + int bc_control; + xchar ballx, bally, chainx, chainy; + boolean cause_delay; - if (drag_ball(nux, nuy, &bc_control, &ballx, &bally, - &chainx, &chainy, &cause_delay, allow_drag)) - move_bc(0, bc_control, ballx, bally, chainx, chainy); - } - } - /* must set u.ux, u.uy after drag_ball(), which may need to know - the old position if allow_drag is true... */ - u_on_newpos(nux, nuy); /* set u., usteed->; cliparound() */ - fill_pit(u.ux0, u.uy0); - if (ball_active) { - if (!ball_still_in_range && !allow_drag) - placebc(); - } - initrack(); /* teleports mess up tracking monsters without this */ - update_player_regions(); - /* - * Make sure the hero disappears from the old location. This will - * not happen if she is teleported within sight of her previous - * location. Force a full vision recalculation because the hero - * is now in a new location. - */ - newsym(u.ux0,u.uy0); - see_monsters(); - vision_full_recalc = 1; - nomul(0); - vision_recalc(0); /* vision before effects */ - if (telescroll) { - /* when teleporting by scroll, we need to handle discovery - now before getting feedback about any objects at our - destination since we might land on another such scroll */ - if (distu(u.ux0, u.uy0) >= 16 || !couldsee(u.ux0, u.uy0)) - learnscroll(telescroll); - else - telescroll = 0; /* no discovery by scrolltele()'s caller */ - } - spoteffects(TRUE); - invocation_message(); + if (drag_ball(nux, nuy, &bc_control, &ballx, &bally, &chainx, + &chainy, &cause_delay, allow_drag)) + move_bc(0, bc_control, ballx, bally, chainx, chainy); + } + } + /* must set u.ux, u.uy after drag_ball(), which may need to know + the old position if allow_drag is true... */ + u_on_newpos(nux, nuy); /* set u., usteed->; cliparound() */ + fill_pit(u.ux0, u.uy0); + if (ball_active) { + if (!ball_still_in_range && !allow_drag) + placebc(); + } + initrack(); /* teleports mess up tracking monsters without this */ + update_player_regions(); + /* + * Make sure the hero disappears from the old location. This will + * not happen if she is teleported within sight of her previous + * location. Force a full vision recalculation because the hero + * is now in a new location. + */ + newsym(u.ux0, u.uy0); + see_monsters(); + vision_full_recalc = 1; + nomul(0); + vision_recalc(0); /* vision before effects */ + if (telescroll) { + /* when teleporting by scroll, we need to handle discovery + now before getting feedback about any objects at our + destination since we might land on another such scroll */ + if (distu(u.ux0, u.uy0) >= 16 || !couldsee(u.ux0, u.uy0)) + learnscroll(telescroll); + else + telescroll = 0; /* no discovery by scrolltele()'s caller */ + } + spoteffects(TRUE); + invocation_message(); } boolean safe_teleds(allow_drag) boolean allow_drag; { - register int nux, nuy, tcnt = 0; + register int nux, nuy, tcnt = 0; - do { - nux = rnd(COLNO-1); - nuy = rn2(ROWNO); - } while (!teleok(nux, nuy, (boolean)(tcnt > 200)) && ++tcnt <= 400); + do { + nux = rnd(COLNO - 1); + nuy = rn2(ROWNO); + } while (!teleok(nux, nuy, (boolean)(tcnt > 200)) && ++tcnt <= 400); - if (tcnt <= 400) { - teleds(nux, nuy, allow_drag); - return TRUE; - } else - return FALSE; + if (tcnt <= 400) { + teleds(nux, nuy, allow_drag); + return TRUE; + } else + return FALSE; } STATIC_OVL void vault_tele() { - register struct mkroom *croom = search_special(VAULT); - coord c; + register struct mkroom *croom = search_special(VAULT); + coord c; - if (croom && somexy(croom, &c) && teleok(c.x,c.y,FALSE)) { - teleds(c.x,c.y,FALSE); - return; - } - tele(); + if (croom && somexy(croom, &c) && teleok(c.x, c.y, FALSE)) { + teleds(c.x, c.y, FALSE); + return; + } + tele(); } boolean @@ -372,35 +385,35 @@ teleport_pet(mtmp, force_it) register struct monst *mtmp; boolean force_it; { - register struct obj *otmp; + register struct obj *otmp; - if (mtmp == u.usteed) - return (FALSE); + if (mtmp == u.usteed) + return (FALSE); - if (mtmp->mleashed) { - otmp = get_mleash(mtmp); - if (!otmp) { - impossible("%s is leashed, without a leash.", Monnam(mtmp)); - goto release_it; - } - if (otmp->cursed && !force_it) { - yelp(mtmp); - return FALSE; - } else { - Your("leash goes slack."); - release_it: - m_unleash(mtmp, FALSE); - return TRUE; - } - } - return TRUE; + if (mtmp->mleashed) { + otmp = get_mleash(mtmp); + if (!otmp) { + impossible("%s is leashed, without a leash.", Monnam(mtmp)); + goto release_it; + } + if (otmp->cursed && !force_it) { + yelp(mtmp); + return FALSE; + } else { + Your("leash goes slack."); + release_it: + m_unleash(mtmp, FALSE); + return TRUE; + } + } + return TRUE; } /* teleport the hero via some method other than scroll of teleport */ void tele() { - (void)scrolltele((struct obj *)0); + (void) scrolltele((struct obj *) 0); } /* teleport the hero; return true if scroll of teleportation should become @@ -411,519 +424,538 @@ boolean scrolltele(scroll) struct obj *scroll; { - coord cc; - boolean result = FALSE; /* don't learn scroll */ + coord cc; + boolean result = FALSE; /* don't learn scroll */ - /* Disable teleportation in stronghold && Vlad's Tower */ - if (level.flags.noteleport) { - if (!wizard) { - pline("A mysterious force prevents you from teleporting!"); - return TRUE; - } - } + /* Disable teleportation in stronghold && Vlad's Tower */ + if (level.flags.noteleport) { + if (!wizard) { + pline("A mysterious force prevents you from teleporting!"); + return TRUE; + } + } - /* don't show trap if "Sorry..." */ - if (!Blinded) make_blinded(0L,FALSE); + /* don't show trap if "Sorry..." */ + if (!Blinded) + make_blinded(0L, FALSE); - if ((u.uhave.amulet || On_W_tower_level(&u.uz)) && !rn2(3)) { - You_feel("disoriented for a moment."); - if (wizard && yn("Override?") != 'y') - return FALSE; - } - if ((Teleport_control && !Stunned) - || wizard - ) { - if (unconscious()) { - pline("Being unconscious, you cannot control your teleport."); - } else { - char whobuf[BUFSZ]; + if ((u.uhave.amulet || On_W_tower_level(&u.uz)) && !rn2(3)) { + You_feel("disoriented for a moment."); + if (wizard && yn("Override?") != 'y') + return FALSE; + } + if ((Teleport_control && !Stunned) || wizard) { + if (unconscious()) { + pline("Being unconscious, you cannot control your teleport."); + } else { + char whobuf[BUFSZ]; - Strcpy(whobuf, "you"); - if (u.usteed) - Sprintf(eos(whobuf), " and %s", mon_nam(u.usteed)); - pline("To what position do %s want to be teleported?", - whobuf); - cc.x = u.ux; - cc.y = u.uy; - if (getpos(&cc, TRUE, "the desired position") < 0) - return TRUE; /* abort */ - /* possible extensions: introduce a small error if - magic power is low; allow transfer to solid rock */ - if (teleok(cc.x, cc.y, FALSE)) { - /* for scroll, discover it regardless of destination */ - if (scroll) learnscroll(scroll); - teleds(cc.x, cc.y, FALSE); - return TRUE; - } - pline("Sorry..."); - result = TRUE; - } - } else if (scroll && scroll->blessed) { - /* (this used to be handled in seffects()) */ - if (yn("Do you wish to teleport?") == 'n') return TRUE; - result = TRUE; - } + Strcpy(whobuf, "you"); + if (u.usteed) + Sprintf(eos(whobuf), " and %s", mon_nam(u.usteed)); + pline("To what position do %s want to be teleported?", whobuf); + cc.x = u.ux; + cc.y = u.uy; + if (getpos(&cc, TRUE, "the desired position") < 0) + return TRUE; /* abort */ + /* possible extensions: introduce a small error if + magic power is low; allow transfer to solid rock */ + if (teleok(cc.x, cc.y, FALSE)) { + /* for scroll, discover it regardless of destination */ + if (scroll) + learnscroll(scroll); + teleds(cc.x, cc.y, FALSE); + return TRUE; + } + pline("Sorry..."); + result = TRUE; + } + } else if (scroll && scroll->blessed) { + /* (this used to be handled in seffects()) */ + if (yn("Do you wish to teleport?") == 'n') + return TRUE; + result = TRUE; + } - telescroll = scroll; - (void) safe_teleds(FALSE); - /* teleds() will leave telescroll intact iff random destination - is far enough away for scroll discovery to be warranted */ - if (telescroll) result = TRUE; - telescroll = 0; /* reset */ - return result; + telescroll = scroll; + (void) safe_teleds(FALSE); + /* teleds() will leave telescroll intact iff random destination + is far enough away for scroll discovery to be warranted */ + if (telescroll) + result = TRUE; + telescroll = 0; /* reset */ + return result; } int dotele() { - struct trap *trap; + struct trap *trap; - trap = t_at(u.ux, u.uy); - if (trap && (!trap->tseen || trap->ttyp != TELEP_TRAP)) - trap = 0; + trap = t_at(u.ux, u.uy); + if (trap && (!trap->tseen || trap->ttyp != TELEP_TRAP)) + trap = 0; - if (trap) { - if (trap->once) { - pline("This is a vault teleport, usable once only."); - if (yn("Jump in?") == 'n') - trap = 0; - else { - deltrap(trap); - newsym(u.ux, u.uy); - } - } - if (trap) - You("%s onto the teleportation trap.", - locomotion(youmonst.data, "jump")); - } - if (!trap) { - boolean castit = FALSE; - register int sp_no = 0, energy = 0; + if (trap) { + if (trap->once) { + pline("This is a vault teleport, usable once only."); + if (yn("Jump in?") == 'n') + trap = 0; + else { + deltrap(trap); + newsym(u.ux, u.uy); + } + } + if (trap) + You("%s onto the teleportation trap.", + locomotion(youmonst.data, "jump")); + } + if (!trap) { + boolean castit = FALSE; + register int sp_no = 0, energy = 0; - if (!Teleportation || (u.ulevel < (Role_if(PM_WIZARD) ? 8 : 12) - && !can_teleport(youmonst.data))) { - /* Try to use teleport away spell. */ - if (objects[SPE_TELEPORT_AWAY].oc_name_known && !Confusion) - for (sp_no = 0; sp_no < MAXSPELL; sp_no++) - if (spl_book[sp_no].sp_id == SPE_TELEPORT_AWAY) { - castit = TRUE; - break; - } - if (!wizard) { - if (!castit) { - if (!Teleportation) - You("don't know that spell."); - else You("are not able to teleport at will."); - return(0); - } - } - } + if (!Teleportation || (u.ulevel < (Role_if(PM_WIZARD) ? 8 : 12) + && !can_teleport(youmonst.data))) { + /* Try to use teleport away spell. */ + if (objects[SPE_TELEPORT_AWAY].oc_name_known && !Confusion) + for (sp_no = 0; sp_no < MAXSPELL; sp_no++) + if (spl_book[sp_no].sp_id == SPE_TELEPORT_AWAY) { + castit = TRUE; + break; + } + if (!wizard) { + if (!castit) { + if (!Teleportation) + You("don't know that spell."); + else + You("are not able to teleport at will."); + return (0); + } + } + } - if (u.uhunger <= 100 || ACURR(A_STR) < 6) { - if (!wizard) { - You("lack the strength %s.", - castit ? "for a teleport spell" : "to teleport"); - return 1; - } - } + if (u.uhunger <= 100 || ACURR(A_STR) < 6) { + if (!wizard) { + You("lack the strength %s.", + castit ? "for a teleport spell" : "to teleport"); + return 1; + } + } - energy = objects[SPE_TELEPORT_AWAY].oc_level * 7 / 2 - 2; - if (u.uen <= energy) { - if (wizard) - energy = u.uen; - else { - You("lack the energy %s.", - castit ? "for a teleport spell" : "to teleport"); - return 1; - } - } + energy = objects[SPE_TELEPORT_AWAY].oc_level * 7 / 2 - 2; + if (u.uen <= energy) { + if (wizard) + energy = u.uen; + else { + You("lack the energy %s.", + castit ? "for a teleport spell" : "to teleport"); + return 1; + } + } - if (check_capacity( - "Your concentration falters from carrying so much.")) - return 1; + if (check_capacity( + "Your concentration falters from carrying so much.")) + return 1; - if (castit) { - exercise(A_WIS, TRUE); - if (spelleffects(sp_no, TRUE)) - return(1); - else if (!wizard) - return(0); - } else { - u.uen -= energy; - context.botl = 1; - } - } + if (castit) { + exercise(A_WIS, TRUE); + if (spelleffects(sp_no, TRUE)) + return (1); + else if (!wizard) + return (0); + } else { + u.uen -= energy; + context.botl = 1; + } + } - if (next_to_u()) { - if (trap && trap->once) vault_tele(); - else tele(); - (void) next_to_u(); - } else { - You1(shudder_for_moment); - return(0); - } - if (!trap) morehungry(100); - return(1); + if (next_to_u()) { + if (trap && trap->once) + vault_tele(); + else + tele(); + (void) next_to_u(); + } else { + You1(shudder_for_moment); + return (0); + } + if (!trap) + morehungry(100); + return (1); } - void level_tele() { - register int newlev; - d_level newlevel; - const char *escape_by_flying = 0; /* when surviving dest of -N */ - char buf[BUFSZ]; - boolean force_dest = FALSE; + register int newlev; + d_level newlevel; + const char *escape_by_flying = 0; /* when surviving dest of -N */ + char buf[BUFSZ]; + boolean force_dest = FALSE; - if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz)) - && !wizard) { - You_feel("very disoriented for a moment."); - return; - } - if ((Teleport_control && !Stunned) || wizard) { - char qbuf[BUFSZ]; - int trycnt = 0; + if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz)) + && !wizard) { + You_feel("very disoriented for a moment."); + return; + } + if ((Teleport_control && !Stunned) || wizard) { + char qbuf[BUFSZ]; + int trycnt = 0; - Strcpy(qbuf, "To what level do you want to teleport?"); - do { - if (++trycnt == 2) { - if (wizard) Strcat(qbuf, " [type a number or ? for a menu]"); - else Strcat(qbuf, " [type a number]"); - } - getlin(qbuf, buf); - if (!strcmp(buf,"\033")) { /* cancelled */ - if (Confusion && rnl(5)) { - pline("Oops..."); - goto random_levtport; - } - return; - } else if (!strcmp(buf,"*")) { - goto random_levtport; - } else if (Confusion && rnl(5)) { - pline("Oops..."); - goto random_levtport; - } - if (wizard && !strcmp(buf,"?")) { - schar destlev = 0; - xchar destdnum = 0; + Strcpy(qbuf, "To what level do you want to teleport?"); + do { + if (++trycnt == 2) { + if (wizard) + Strcat(qbuf, " [type a number or ? for a menu]"); + else + Strcat(qbuf, " [type a number]"); + } + getlin(qbuf, buf); + if (!strcmp(buf, "\033")) { /* cancelled */ + if (Confusion && rnl(5)) { + pline("Oops..."); + goto random_levtport; + } + return; + } else if (!strcmp(buf, "*")) { + goto random_levtport; + } else if (Confusion && rnl(5)) { + pline("Oops..."); + goto random_levtport; + } + if (wizard && !strcmp(buf, "?")) { + schar destlev = 0; + xchar destdnum = 0; - newlev = (int)print_dungeon(TRUE, &destlev, &destdnum); - if (!newlev) return; + newlev = (int) print_dungeon(TRUE, &destlev, &destdnum); + if (!newlev) + return; - newlevel.dnum = destdnum; - newlevel.dlevel = destlev; - if (In_endgame(&newlevel) && !In_endgame(&u.uz)) { - struct obj *amu; + newlevel.dnum = destdnum; + newlevel.dlevel = destlev; + if (In_endgame(&newlevel) && !In_endgame(&u.uz)) { + struct obj *amu; - if (!u.uhave.amulet && - (amu = mksobj(AMULET_OF_YENDOR, TRUE, FALSE)) != 0) { - /* ordinarily we'd use hold_another_object() - for something like this, but we don't want - fumbling or already full pack to interfere */ - amu = addinv(amu); - prinv("Endgame prerequisite:", amu, 0L); - } - } - force_dest = TRUE; - } else if ((newlev = lev_by_name(buf)) == 0) newlev = atoi(buf); - } while (!newlev && !digit(buf[0]) && - (buf[0] != '-' || !digit(buf[1])) && - trycnt < 10); + if (!u.uhave.amulet + && (amu = mksobj(AMULET_OF_YENDOR, TRUE, FALSE)) + != 0) { + /* ordinarily we'd use hold_another_object() + for something like this, but we don't want + fumbling or already full pack to interfere */ + amu = addinv(amu); + prinv("Endgame prerequisite:", amu, 0L); + } + } + force_dest = TRUE; + } else if ((newlev = lev_by_name(buf)) == 0) + newlev = atoi(buf); + } while (!newlev && !digit(buf[0]) + && (buf[0] != '-' || !digit(buf[1])) && trycnt < 10); - /* no dungeon escape via this route */ - if (newlev == 0) { - if (trycnt >= 10) - goto random_levtport; - if (ynq("Go to Nowhere. Are you sure?") != 'y') return; - You("%s in agony as your body begins to warp...", - is_silent(youmonst.data) ? "writhe" : "scream"); - display_nhwindow(WIN_MESSAGE, FALSE); - You("cease to exist."); - if (invent) Your("possessions land on the %s with a thud.", - surface(u.ux, u.uy)); - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "committed suicide"); - done(DIED); - pline("An energized cloud of dust begins to coalesce."); - Your("body rematerializes%s.", invent ? - ", and you gather up all your possessions" : ""); - return; - } + /* no dungeon escape via this route */ + if (newlev == 0) { + if (trycnt >= 10) + goto random_levtport; + if (ynq("Go to Nowhere. Are you sure?") != 'y') + return; + You("%s in agony as your body begins to warp...", + is_silent(youmonst.data) ? "writhe" : "scream"); + display_nhwindow(WIN_MESSAGE, FALSE); + You("cease to exist."); + if (invent) + Your("possessions land on the %s with a thud.", + surface(u.ux, u.uy)); + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "committed suicide"); + done(DIED); + pline("An energized cloud of dust begins to coalesce."); + Your("body rematerializes%s.", + invent ? ", and you gather up all your possessions" : ""); + return; + } - /* if in Knox and the requested level > 0, stay put. - * we let negative values requests fall into the "heaven" loop. - */ - if (Is_knox(&u.uz) && newlev > 0 && !force_dest) { - You1(shudder_for_moment); - return; - } - /* if in Quest, the player sees "Home 1", etc., on the status - * line, instead of the logical depth of the level. controlled - * level teleport request is likely to be relativized to the - * status line, and consequently it should be incremented to - * the value of the logical depth of the target level. - * - * we let negative values requests fall into the "heaven" loop. - */ - if (In_quest(&u.uz) && newlev > 0) - newlev = newlev + dungeons[u.uz.dnum].depth_start - 1; - } else { /* involuntary level tele */ - random_levtport: - newlev = random_teleport_level(); - if (newlev == depth(&u.uz)) { - You1(shudder_for_moment); - return; - } - } + /* if in Knox and the requested level > 0, stay put. + * we let negative values requests fall into the "heaven" loop. + */ + if (Is_knox(&u.uz) && newlev > 0 && !force_dest) { + You1(shudder_for_moment); + return; + } + /* if in Quest, the player sees "Home 1", etc., on the status + * line, instead of the logical depth of the level. controlled + * level teleport request is likely to be relativized to the + * status line, and consequently it should be incremented to + * the value of the logical depth of the target level. + * + * we let negative values requests fall into the "heaven" loop. + */ + if (In_quest(&u.uz) && newlev > 0) + newlev = newlev + dungeons[u.uz.dnum].depth_start - 1; + } else { /* involuntary level tele */ + random_levtport: + newlev = random_teleport_level(); + if (newlev == depth(&u.uz)) { + You1(shudder_for_moment); + return; + } + } - if (u.utrap && u.utraptype == TT_BURIEDBALL) - buried_ball_to_punishment(); + if (u.utrap && u.utraptype == TT_BURIEDBALL) + buried_ball_to_punishment(); - if (!next_to_u() && !force_dest) { - You1(shudder_for_moment); - return; - } - if (In_endgame(&u.uz)) { /* must already be wizard */ - int llimit = dunlevs_in_dungeon(&u.uz); + if (!next_to_u() && !force_dest) { + You1(shudder_for_moment); + return; + } + if (In_endgame(&u.uz)) { /* must already be wizard */ + int llimit = dunlevs_in_dungeon(&u.uz); - if (newlev >= 0 || newlev <= -llimit) { - You_cant("get there from here."); - return; - } - newlevel.dnum = u.uz.dnum; - newlevel.dlevel = llimit + newlev; - schedule_goto(&newlevel, FALSE, FALSE, 0, (char *)0, (char *)0); - return; - } + if (newlev >= 0 || newlev <= -llimit) { + You_cant("get there from here."); + return; + } + newlevel.dnum = u.uz.dnum; + newlevel.dlevel = llimit + newlev; + schedule_goto(&newlevel, FALSE, FALSE, 0, (char *) 0, (char *) 0); + return; + } - killer.name[0] = 0; /* still alive, so far... */ + killer.name[0] = 0; /* still alive, so far... */ - if (newlev < 0 && !force_dest) { - if (*u.ushops0) { - /* take unpaid inventory items off of shop bills */ - in_mklev = TRUE; /* suppress map update */ - u_left_shop(u.ushops0, TRUE); - /* you're now effectively out of the shop */ - *u.ushops0 = *u.ushops = '\0'; - in_mklev = FALSE; - } - if (newlev <= -10) { - You("arrive in heaven."); - verbalize("Thou art early, but we'll admit thee."); - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "went to heaven prematurely"); - } else if (newlev == -9) { - You_feel("deliriously happy. "); - pline("(In fact, you're on Cloud 9!) "); - display_nhwindow(WIN_MESSAGE, FALSE); - } else - You("are now high above the clouds..."); + if (newlev < 0 && !force_dest) { + if (*u.ushops0) { + /* take unpaid inventory items off of shop bills */ + in_mklev = TRUE; /* suppress map update */ + u_left_shop(u.ushops0, TRUE); + /* you're now effectively out of the shop */ + *u.ushops0 = *u.ushops = '\0'; + in_mklev = FALSE; + } + if (newlev <= -10) { + You("arrive in heaven."); + verbalize("Thou art early, but we'll admit thee."); + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "went to heaven prematurely"); + } else if (newlev == -9) { + You_feel("deliriously happy. "); + pline("(In fact, you're on Cloud 9!) "); + display_nhwindow(WIN_MESSAGE, FALSE); + } else + You("are now high above the clouds..."); - if (killer.name[0]) { - ; /* arrival in heaven is pending */ - } else if (Levitation) { - escape_by_flying = "float gently down to earth"; - } else if (Flying) { - escape_by_flying = "fly down to the ground"; - } else { - pline("Unfortunately, you don't know how to fly."); - You("plummet a few thousand feet to your death."); - Sprintf(killer.name, - "teleported out of the dungeon and fell to %s death", - uhis()); - killer.format = NO_KILLER_PREFIX; - } - } + if (killer.name[0]) { + ; /* arrival in heaven is pending */ + } else if (Levitation) { + escape_by_flying = "float gently down to earth"; + } else if (Flying) { + escape_by_flying = "fly down to the ground"; + } else { + pline("Unfortunately, you don't know how to fly."); + You("plummet a few thousand feet to your death."); + Sprintf(killer.name, + "teleported out of the dungeon and fell to %s death", + uhis()); + killer.format = NO_KILLER_PREFIX; + } + } - if (killer.name[0]) { /* the chosen destination was not survivable */ - d_level lsav; + if (killer.name[0]) { /* the chosen destination was not survivable */ + d_level lsav; - /* set specific death location; this also suppresses bones */ - lsav = u.uz; /* save current level, see below */ - u.uz.dnum = 0; /* main dungeon */ - u.uz.dlevel = (newlev <= -10) ? -10 : 0; /* heaven or surface */ - done(DIED); - /* can only get here via life-saving (or declining to die in - explore|debug mode); the hero has now left the dungeon... */ - escape_by_flying = "find yourself back on the surface"; - u.uz = lsav; /* restore u.uz so escape code works */ - } + /* set specific death location; this also suppresses bones */ + lsav = u.uz; /* save current level, see below */ + u.uz.dnum = 0; /* main dungeon */ + u.uz.dlevel = (newlev <= -10) ? -10 : 0; /* heaven or surface */ + done(DIED); + /* can only get here via life-saving (or declining to die in + explore|debug mode); the hero has now left the dungeon... */ + escape_by_flying = "find yourself back on the surface"; + u.uz = lsav; /* restore u.uz so escape code works */ + } - /* calls done(ESCAPED) if newlevel==0 */ - if (escape_by_flying) { - You("%s.", escape_by_flying); - newlevel.dnum = 0; /* specify main dungeon */ - newlevel.dlevel = 0; /* escape the dungeon */ - /* [dlevel used to be set to 1, but it doesn't make sense to - teleport out of the dungeon and float or fly down to the - surface but then actually arrive back inside the dungeon] */ - } else if (u.uz.dnum == medusa_level.dnum && - newlev >= dungeons[u.uz.dnum].depth_start + - dunlevs_in_dungeon(&u.uz)) { - if (!(wizard && force_dest)) - find_hell(&newlevel); - } else { - /* if invocation did not yet occur, teleporting into - * the last level of Gehennom is forbidden. - */ - if (!wizard && Inhell && !u.uevent.invoked && - newlev >= (dungeons[u.uz.dnum].depth_start + - dunlevs_in_dungeon(&u.uz) - 1)) { - newlev = dungeons[u.uz.dnum].depth_start + - dunlevs_in_dungeon(&u.uz) - 2; - pline("Sorry..."); - } - /* no teleporting out of quest dungeon */ - if (In_quest(&u.uz) && newlev < depth(&qstart_level)) - newlev = depth(&qstart_level); - /* the player thinks of levels purely in logical terms, so - * we must translate newlev to a number relative to the - * current dungeon. - */ - if (!(wizard && force_dest)) - get_level(&newlevel, newlev); - } - schedule_goto(&newlevel, FALSE, FALSE, 0, (char *)0, (char *)0); - /* in case player just read a scroll and is about to be asked to - call it something, we can't defer until the end of the turn */ - if (u.utotype && !context.mon_moving) deferred_goto(); + /* calls done(ESCAPED) if newlevel==0 */ + if (escape_by_flying) { + You("%s.", escape_by_flying); + newlevel.dnum = 0; /* specify main dungeon */ + newlevel.dlevel = 0; /* escape the dungeon */ + /* [dlevel used to be set to 1, but it doesn't make sense to + teleport out of the dungeon and float or fly down to the + surface but then actually arrive back inside the dungeon] */ + } else if (u.uz.dnum == medusa_level.dnum + && newlev >= dungeons[u.uz.dnum].depth_start + + dunlevs_in_dungeon(&u.uz)) { + if (!(wizard && force_dest)) + find_hell(&newlevel); + } else { + /* if invocation did not yet occur, teleporting into + * the last level of Gehennom is forbidden. + */ + if (!wizard && Inhell && !u.uevent.invoked + && newlev >= (dungeons[u.uz.dnum].depth_start + + dunlevs_in_dungeon(&u.uz) - 1)) { + newlev = dungeons[u.uz.dnum].depth_start + + dunlevs_in_dungeon(&u.uz) - 2; + pline("Sorry..."); + } + /* no teleporting out of quest dungeon */ + if (In_quest(&u.uz) && newlev < depth(&qstart_level)) + newlev = depth(&qstart_level); + /* the player thinks of levels purely in logical terms, so + * we must translate newlev to a number relative to the + * current dungeon. + */ + if (!(wizard && force_dest)) + get_level(&newlevel, newlev); + } + schedule_goto(&newlevel, FALSE, FALSE, 0, (char *) 0, (char *) 0); + /* in case player just read a scroll and is about to be asked to + call it something, we can't defer until the end of the turn */ + if (u.utotype && !context.mon_moving) + deferred_goto(); } void domagicportal(ttmp) register struct trap *ttmp; { - struct d_level target_level; + struct d_level target_level; - if (u.utrap && u.utraptype == TT_BURIEDBALL) - buried_ball_to_punishment(); + if (u.utrap && u.utraptype == TT_BURIEDBALL) + buried_ball_to_punishment(); - if (!next_to_u()) { - You1(shudder_for_moment); - return; - } + if (!next_to_u()) { + You1(shudder_for_moment); + return; + } - /* if landed from another portal, do nothing */ - /* problem: level teleport landing escapes the check */ - if (!on_level(&u.uz, &u.uz0)) return; + /* if landed from another portal, do nothing */ + /* problem: level teleport landing escapes the check */ + if (!on_level(&u.uz, &u.uz0)) + return; - You("activated a magic portal!"); + You("activated a magic portal!"); - /* prevent the poor shnook, whose amulet was stolen while in - * the endgame, from accidently triggering the portal to the - * next level, and thus losing the game - */ - if (In_endgame(&u.uz) && !u.uhave.amulet) { - You_feel("dizzy for a moment, but nothing happens..."); - return; - } + /* prevent the poor shnook, whose amulet was stolen while in + * the endgame, from accidently triggering the portal to the + * next level, and thus losing the game + */ + if (In_endgame(&u.uz) && !u.uhave.amulet) { + You_feel("dizzy for a moment, but nothing happens..."); + return; + } - target_level = ttmp->dst; - schedule_goto(&target_level, FALSE, FALSE, 1, - "You feel dizzy for a moment, but the sensation passes.", - (char *)0); + target_level = ttmp->dst; + schedule_goto(&target_level, FALSE, FALSE, 1, + "You feel dizzy for a moment, but the sensation passes.", + (char *) 0); } void tele_trap(trap) struct trap *trap; { - if (In_endgame(&u.uz) || Antimagic) { - if (Antimagic) - shieldeff(u.ux, u.uy); - You_feel("a wrenching sensation."); - } else if (!next_to_u()) { - You1(shudder_for_moment); - } else if (trap->once) { - deltrap(trap); - newsym(u.ux,u.uy); /* get rid of trap symbol */ - vault_tele(); - } else - tele(); + if (In_endgame(&u.uz) || Antimagic) { + if (Antimagic) + shieldeff(u.ux, u.uy); + You_feel("a wrenching sensation."); + } else if (!next_to_u()) { + You1(shudder_for_moment); + } else if (trap->once) { + deltrap(trap); + newsym(u.ux, u.uy); /* get rid of trap symbol */ + vault_tele(); + } else + tele(); } void level_tele_trap(trap) struct trap *trap; { - You("%s onto a level teleport trap!", - Levitation ? (const char *)"float" : - locomotion(youmonst.data, "step")); - if (Antimagic) { - shieldeff(u.ux, u.uy); - } - if (Antimagic || In_endgame(&u.uz)) { - You_feel("a wrenching sensation."); - return; - } - if (!Blind) - You("are momentarily blinded by a flash of light."); - else - You("are momentarily disoriented."); - deltrap(trap); - newsym(u.ux,u.uy); /* get rid of trap symbol */ - level_tele(); + You("%s onto a level teleport trap!", + Levitation ? (const char *) "float" + : locomotion(youmonst.data, "step")); + if (Antimagic) { + shieldeff(u.ux, u.uy); + } + if (Antimagic || In_endgame(&u.uz)) { + You_feel("a wrenching sensation."); + return; + } + if (!Blind) + You("are momentarily blinded by a flash of light."); + else + You("are momentarily disoriented."); + deltrap(trap); + newsym(u.ux, u.uy); /* get rid of trap symbol */ + level_tele(); } /* check whether monster can arrive at location via Tport (or fall) */ STATIC_OVL boolean rloc_pos_ok(x, y, mtmp) -register int x, y; /* coordinates of candidate location */ +register int x, y; /* coordinates of candidate location */ struct monst *mtmp; { - register int xx, yy; + register int xx, yy; - if (!goodpos(x, y, mtmp, 0)) return FALSE; - /* - * Check for restricted areas present in some special levels. - * - * `xx' is current column; if 0, then `yy' will contain flag bits - * rather than row: bit #0 set => moving upwards; bit #1 set => - * inside the Wizard's tower. - */ - xx = mtmp->mx; - yy = mtmp->my; - if (!xx) { - /* no current location (migrating monster arrival) */ - if (dndest.nlx && On_W_tower_level(&u.uz)) - return ((yy & 2) != 0) ^ /* inside xor not within */ - !within_bounded_area(x, y, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy); - if (updest.lx && (yy & 1) != 0) /* moving up */ - return (within_bounded_area(x, y, updest.lx, updest.ly, - updest.hx, updest.hy) && - (!updest.nlx || - !within_bounded_area(x, y, updest.nlx, updest.nly, - updest.nhx, updest.nhy))); - if (dndest.lx && (yy & 1) == 0) /* moving down */ - return (within_bounded_area(x, y, dndest.lx, dndest.ly, - dndest.hx, dndest.hy) && - (!dndest.nlx || - !within_bounded_area(x, y, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy))); - } else { - /* [try to] prevent a shopkeeper or temple priest from being - sent out of his room (caller might resort to goodpos() if - we report failure here, so this isn't full prevention) */ - if (mtmp->isshk && inhishop(mtmp)) { - if (levl[x][y].roomno != ESHK(mtmp)->shoproom) return FALSE; - } else if (mtmp->ispriest && inhistemple(mtmp)) { - if (levl[x][y].roomno != EPRI(mtmp)->shroom) return FALSE; - } - /* current location is */ - if (!tele_jump_ok(xx, yy, x, y)) return FALSE; - } - /* is ok */ - return TRUE; + if (!goodpos(x, y, mtmp, 0)) + return FALSE; + /* + * Check for restricted areas present in some special levels. + * + * `xx' is current column; if 0, then `yy' will contain flag bits + * rather than row: bit #0 set => moving upwards; bit #1 set => + * inside the Wizard's tower. + */ + xx = mtmp->mx; + yy = mtmp->my; + if (!xx) { + /* no current location (migrating monster arrival) */ + if (dndest.nlx && On_W_tower_level(&u.uz)) + return ((yy & 2) != 0) + ^ /* inside xor not within */ + !within_bounded_area(x, y, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy); + if (updest.lx && (yy & 1) != 0) /* moving up */ + return (within_bounded_area(x, y, updest.lx, updest.ly, updest.hx, + updest.hy) + && (!updest.nlx + || !within_bounded_area(x, y, updest.nlx, updest.nly, + updest.nhx, updest.nhy))); + if (dndest.lx && (yy & 1) == 0) /* moving down */ + return (within_bounded_area(x, y, dndest.lx, dndest.ly, dndest.hx, + dndest.hy) + && (!dndest.nlx + || !within_bounded_area(x, y, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy))); + } else { + /* [try to] prevent a shopkeeper or temple priest from being + sent out of his room (caller might resort to goodpos() if + we report failure here, so this isn't full prevention) */ + if (mtmp->isshk && inhishop(mtmp)) { + if (levl[x][y].roomno != ESHK(mtmp)->shoproom) + return FALSE; + } else if (mtmp->ispriest && inhistemple(mtmp)) { + if (levl[x][y].roomno != EPRI(mtmp)->shroom) + return FALSE; + } + /* current location is */ + if (!tele_jump_ok(xx, yy, x, y)) + return FALSE; + } + /* is ok */ + return TRUE; } /* * rloc_to() * * Pulls a monster from its current position and places a monster at - * a new x and y. If oldx is 0, then the monster was not in the levels.monsters - * array. However, if oldx is 0, oldy may still have a value because mtmp is a + * a new x and y. If oldx is 0, then the monster was not in the + * levels.monsters + * array. However, if oldx is 0, oldy may still have a value because mtmp is + * a * migrating_mon. Worm tails are always placed randomly around the head of * the worm. */ @@ -932,123 +964,124 @@ rloc_to(mtmp, x, y) struct monst *mtmp; register int x, y; { - register int oldx = mtmp->mx, oldy = mtmp->my; - boolean resident_shk = mtmp->isshk && inhishop(mtmp); + register int oldx = mtmp->mx, oldy = mtmp->my; + boolean resident_shk = mtmp->isshk && inhishop(mtmp); - if (x == mtmp->mx && y == mtmp->my) /* that was easy */ - return; + if (x == mtmp->mx && y == mtmp->my) /* that was easy */ + return; - if (oldx) { /* "pick up" monster */ - if (mtmp->wormno) - remove_worm(mtmp); - else { - remove_monster(oldx, oldy); - newsym(oldx, oldy); /* update old location */ - } - } + if (oldx) { /* "pick up" monster */ + if (mtmp->wormno) + remove_worm(mtmp); + else { + remove_monster(oldx, oldy); + newsym(oldx, oldy); /* update old location */ + } + } - place_monster(mtmp, x, y); /* put monster down */ - update_monster_region(mtmp); + place_monster(mtmp, x, y); /* put monster down */ + update_monster_region(mtmp); - if (mtmp->wormno) /* now put down tail */ - place_worm_tail_randomly(mtmp, x, y); + if (mtmp->wormno) /* now put down tail */ + place_worm_tail_randomly(mtmp, x, y); - if (u.ustuck == mtmp) { - if (u.uswallow) { - u.ux = x; - u.uy = y; - docrt(); - } else u.ustuck = 0; - } + if (u.ustuck == mtmp) { + if (u.uswallow) { + u.ux = x; + u.uy = y; + docrt(); + } else + u.ustuck = 0; + } - newsym(x, y); /* update new location */ - set_apparxy(mtmp); /* orient monster */ + newsym(x, y); /* update new location */ + set_apparxy(mtmp); /* orient monster */ - /* shopkeepers will only teleport if you zap them with a wand of - teleportation or if they've been transformed into a jumpy monster; - the latter only happens if you've attacked them with polymorph */ - if (resident_shk && !inhishop(mtmp)) make_angry_shk(mtmp, oldx, oldy); + /* shopkeepers will only teleport if you zap them with a wand of + teleportation or if they've been transformed into a jumpy monster; + the latter only happens if you've attacked them with polymorph */ + if (resident_shk && !inhishop(mtmp)) + make_angry_shk(mtmp, oldx, oldy); } /* place a monster at a random location, typically due to teleport */ /* return TRUE if successful, FALSE if not */ boolean rloc(mtmp, suppress_impossible) -struct monst *mtmp; /* mx==0 implies migrating monster arrival */ +struct monst *mtmp; /* mx==0 implies migrating monster arrival */ boolean suppress_impossible; { - register int x, y, trycount; + register int x, y, trycount; - if (mtmp == u.usteed) { - tele(); - return TRUE; - } + if (mtmp == u.usteed) { + tele(); + return TRUE; + } - if (mtmp->iswiz && mtmp->mx) { /* Wizard, not just arriving */ - if (!In_W_tower(u.ux, u.uy, &u.uz)) - x = xupstair, y = yupstair; - else if (!xdnladder) /* bottom level of tower */ - x = xupladder, y = yupladder; - else - x = xdnladder, y = ydnladder; - /* if the wiz teleports away to heal, try the up staircase, - to block the player's escaping before he's healed - (deliberately use `goodpos' rather than `rloc_pos_ok' here) */ - if (goodpos(x, y, mtmp, 0)) - goto found_xy; - } + if (mtmp->iswiz && mtmp->mx) { /* Wizard, not just arriving */ + if (!In_W_tower(u.ux, u.uy, &u.uz)) + x = xupstair, y = yupstair; + else if (!xdnladder) /* bottom level of tower */ + x = xupladder, y = yupladder; + else + x = xdnladder, y = ydnladder; + /* if the wiz teleports away to heal, try the up staircase, + to block the player's escaping before he's healed + (deliberately use `goodpos' rather than `rloc_pos_ok' here) */ + if (goodpos(x, y, mtmp, 0)) + goto found_xy; + } - trycount = 0; - do { - x = rn1(COLNO-3,2); - y = rn2(ROWNO); - if ((trycount < 500) ? rloc_pos_ok(x, y, mtmp) - : goodpos(x, y, mtmp, 0)) - goto found_xy; - } while (++trycount < 1000); + trycount = 0; + do { + x = rn1(COLNO - 3, 2); + y = rn2(ROWNO); + if ((trycount < 500) ? rloc_pos_ok(x, y, mtmp) + : goodpos(x, y, mtmp, 0)) + goto found_xy; + } while (++trycount < 1000); - /* last ditch attempt to find a good place */ - for (x = 2; x < COLNO - 1; x++) - for (y = 0; y < ROWNO; y++) - if (goodpos(x, y, mtmp, 0)) - goto found_xy; + /* last ditch attempt to find a good place */ + for (x = 2; x < COLNO - 1; x++) + for (y = 0; y < ROWNO; y++) + if (goodpos(x, y, mtmp, 0)) + goto found_xy; - /* level either full of monsters or somehow faulty */ - if (!suppress_impossible) - impossible("rloc(): couldn't relocate monster"); - return FALSE; + /* level either full of monsters or somehow faulty */ + if (!suppress_impossible) + impossible("rloc(): couldn't relocate monster"); + return FALSE; - found_xy: - rloc_to(mtmp, x, y); - return TRUE; +found_xy: + rloc_to(mtmp, x, y); + return TRUE; } STATIC_OVL void mvault_tele(mtmp) struct monst *mtmp; { - register struct mkroom *croom = search_special(VAULT); - coord c; + register struct mkroom *croom = search_special(VAULT); + coord c; - if (croom && somexy(croom, &c) && - goodpos(c.x, c.y, mtmp, 0)) { - rloc_to(mtmp, c.x, c.y); - return; - } - (void) rloc(mtmp, FALSE); + if (croom && somexy(croom, &c) && goodpos(c.x, c.y, mtmp, 0)) { + rloc_to(mtmp, c.x, c.y); + return; + } + (void) rloc(mtmp, FALSE); } boolean tele_restrict(mon) struct monst *mon; { - if (level.flags.noteleport) { - if (canseemon(mon)) - pline("A mysterious force prevents %s from teleporting!", - mon_nam(mon)); - return TRUE; - } - return FALSE; + if (level.flags.noteleport) { + if (canseemon(mon)) + pline("A mysterious force prevents %s from teleporting!", + mon_nam(mon)); + return TRUE; + } + return FALSE; } void @@ -1057,28 +1090,31 @@ struct monst *mtmp; struct trap *trap; int in_sight; { - char *monname; + char *monname; - if (tele_restrict(mtmp)) return; - if (teleport_pet(mtmp, FALSE)) { - /* save name with pre-movement visibility */ - monname = Monnam(mtmp); + if (tele_restrict(mtmp)) + return; + if (teleport_pet(mtmp, FALSE)) { + /* save name with pre-movement visibility */ + monname = Monnam(mtmp); - /* Note: don't remove the trap if a vault. Other- - * wise the monster will be stuck there, since - * the guard isn't going to come for it... - */ - if (trap->once) mvault_tele(mtmp); - else (void) rloc(mtmp, FALSE); + /* Note: don't remove the trap if a vault. Other- + * wise the monster will be stuck there, since + * the guard isn't going to come for it... + */ + if (trap->once) + mvault_tele(mtmp); + else + (void) rloc(mtmp, FALSE); - if (in_sight) { - if (canseemon(mtmp)) - pline("%s seems disoriented.", monname); - else - pline("%s suddenly disappears!", monname); - seetrap(trap); - } - } + if (in_sight) { + if (canseemon(mtmp)) + pline("%s seems disoriented.", monname); + else + pline("%s suddenly disappears!", monname); + seetrap(trap); + } + } } /* return 0 if still on level, 3 if not */ @@ -1089,192 +1125,195 @@ struct trap *trap; boolean force_it; int in_sight; { - int tt = trap->ttyp; - struct permonst *mptr = mtmp->data; + int tt = trap->ttyp; + struct permonst *mptr = mtmp->data; - if (mtmp == u.ustuck) /* probably a vortex */ - return 0; /* temporary? kludge */ - if (teleport_pet(mtmp, force_it)) { - d_level tolevel; - int migrate_typ = MIGR_RANDOM; + if (mtmp == u.ustuck) /* probably a vortex */ + return 0; /* temporary? kludge */ + if (teleport_pet(mtmp, force_it)) { + d_level tolevel; + int migrate_typ = MIGR_RANDOM; - if ((tt == HOLE || tt == TRAPDOOR)) { - if (Is_stronghold(&u.uz)) { - assign_level(&tolevel, &valley_level); - } else if (Is_botlevel(&u.uz)) { - if (in_sight && trap->tseen) - pline("%s avoids the %s.", Monnam(mtmp), - (tt == HOLE) ? "hole" : "trap"); - return 0; - } else { - get_level(&tolevel, depth(&u.uz) + 1); - } - } else if (tt == MAGIC_PORTAL) { - if (In_endgame(&u.uz) && - (mon_has_amulet(mtmp) || is_home_elemental(mptr))) { - if (in_sight && mptr->mlet != S_ELEMENTAL) { - pline("%s seems to shimmer for a moment.", - Monnam(mtmp)); - seetrap(trap); - } - return 0; - } else { - assign_level(&tolevel, &trap->dst); - migrate_typ = MIGR_PORTAL; - } - } else { /* (tt == LEVEL_TELEP) */ - int nlev; + if ((tt == HOLE || tt == TRAPDOOR)) { + if (Is_stronghold(&u.uz)) { + assign_level(&tolevel, &valley_level); + } else if (Is_botlevel(&u.uz)) { + if (in_sight && trap->tseen) + pline("%s avoids the %s.", Monnam(mtmp), + (tt == HOLE) ? "hole" : "trap"); + return 0; + } else { + get_level(&tolevel, depth(&u.uz) + 1); + } + } else if (tt == MAGIC_PORTAL) { + if (In_endgame(&u.uz) + && (mon_has_amulet(mtmp) || is_home_elemental(mptr))) { + if (in_sight && mptr->mlet != S_ELEMENTAL) { + pline("%s seems to shimmer for a moment.", Monnam(mtmp)); + seetrap(trap); + } + return 0; + } else { + assign_level(&tolevel, &trap->dst); + migrate_typ = MIGR_PORTAL; + } + } else { /* (tt == LEVEL_TELEP) */ + int nlev; - if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { - if (in_sight) - pline("%s seems very disoriented for a moment.", - Monnam(mtmp)); - return 0; - } - nlev = random_teleport_level(); - if (nlev == depth(&u.uz)) { - if (in_sight) - pline("%s shudders for a moment.", Monnam(mtmp)); - return 0; - } - get_level(&tolevel, nlev); - } + if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { + if (in_sight) + pline("%s seems very disoriented for a moment.", + Monnam(mtmp)); + return 0; + } + nlev = random_teleport_level(); + if (nlev == depth(&u.uz)) { + if (in_sight) + pline("%s shudders for a moment.", Monnam(mtmp)); + return 0; + } + get_level(&tolevel, nlev); + } - if (in_sight) { - pline("Suddenly, %s disappears out of sight.", mon_nam(mtmp)); - seetrap(trap); - } - migrate_to_level(mtmp, ledger_no(&tolevel), - migrate_typ, (coord *)0); - return 3; /* no longer on this level */ - } - return 0; + if (in_sight) { + pline("Suddenly, %s disappears out of sight.", mon_nam(mtmp)); + seetrap(trap); + } + migrate_to_level(mtmp, ledger_no(&tolevel), migrate_typ, (coord *) 0); + return 3; /* no longer on this level */ + } + return 0; } - -/* place object randomly, returns FALSE if it's gone (eg broken) as a result */ +/* place object randomly, returns FALSE if it's gone (eg broken) as a result + */ boolean rloco(obj) register struct obj *obj; { - register xchar tx, ty, otx, oty; - boolean restricted_fall; - int try_limit = 4000; + register xchar tx, ty, otx, oty; + boolean restricted_fall; + int try_limit = 4000; - if (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm])) { - if (revive_corpse(obj)) return FALSE; - } + if (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm])) { + if (revive_corpse(obj)) + return FALSE; + } - obj_extract_self(obj); - otx = obj->ox; - oty = obj->oy; - restricted_fall = (otx == 0 && dndest.lx); - do { - tx = rn1(COLNO-3,2); - ty = rn2(ROWNO); - if (!--try_limit) break; - } while (!goodpos(tx, ty, (struct monst *)0, 0) || - (restricted_fall && - (!within_bounded_area(tx, ty, dndest.lx, dndest.ly, - dndest.hx, dndest.hy) || - (dndest.nlx && - within_bounded_area(tx, ty, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy)))) || - /* on the Wizard Tower levels, objects inside should - stay inside and objects outside should stay outside */ - (dndest.nlx && On_W_tower_level(&u.uz) && - within_bounded_area(tx, ty, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy) != - within_bounded_area(otx, oty, dndest.nlx, dndest.nly, - dndest.nhx, dndest.nhy))); + obj_extract_self(obj); + otx = obj->ox; + oty = obj->oy; + restricted_fall = (otx == 0 && dndest.lx); + do { + tx = rn1(COLNO - 3, 2); + ty = rn2(ROWNO); + if (!--try_limit) + break; + } while (!goodpos(tx, ty, (struct monst *) 0, 0) + || (restricted_fall + && (!within_bounded_area(tx, ty, dndest.lx, dndest.ly, + dndest.hx, dndest.hy) + || (dndest.nlx && within_bounded_area( + tx, ty, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy)))) || + /* on the Wizard Tower levels, objects inside should + stay inside and objects outside should stay outside */ + (dndest.nlx && On_W_tower_level(&u.uz) + && within_bounded_area(tx, ty, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy) + != within_bounded_area(otx, oty, dndest.nlx, dndest.nly, + dndest.nhx, dndest.nhy))); - if (flooreffects(obj, tx, ty, "fall")) { - return FALSE; - } else if (otx == 0 && oty == 0) { - ; /* fell through a trap door; no update of old loc needed */ - } else { - if (costly_spot(otx, oty) - && (!costly_spot(tx, ty) || - !index(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) { - if (costly_spot(u.ux, u.uy) && - index(u.urooms, *in_rooms(otx, oty, 0))) - addtobill(obj, FALSE, FALSE, FALSE); - else (void)stolen_value(obj, otx, oty, FALSE, FALSE); - } - newsym(otx, oty); /* update old location */ - } - place_object(obj, tx, ty); - newsym(tx, ty); - return TRUE; + if (flooreffects(obj, tx, ty, "fall")) { + return FALSE; + } else if (otx == 0 && oty == 0) { + ; /* fell through a trap door; no update of old loc needed */ + } else { + if (costly_spot(otx, oty) + && (!costly_spot(tx, ty) + || !index(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) { + if (costly_spot(u.ux, u.uy) + && index(u.urooms, *in_rooms(otx, oty, 0))) + addtobill(obj, FALSE, FALSE, FALSE); + else + (void) stolen_value(obj, otx, oty, FALSE, FALSE); + } + newsym(otx, oty); /* update old location */ + } + place_object(obj, tx, ty); + newsym(tx, ty); + return TRUE; } /* Returns an absolute depth */ int random_teleport_level() { - int nlev, max_depth, min_depth, - cur_depth = (int)depth(&u.uz); + int nlev, max_depth, min_depth, cur_depth = (int) depth(&u.uz); - /* [the endgame case can only occur in wizard mode] */ - if (!rn2(5) || Is_knox(&u.uz) || In_endgame(&u.uz)) - return cur_depth; + /* [the endgame case can only occur in wizard mode] */ + if (!rn2(5) || Is_knox(&u.uz) || In_endgame(&u.uz)) + return cur_depth; - /* What I really want to do is as follows: - * -- If in a dungeon that goes down, the new level is to be restricted - * to [top of parent, bottom of current dungeon] - * -- If in a dungeon that goes up, the new level is to be restricted - * to [top of current dungeon, bottom of parent] - * -- If in a quest dungeon or similar dungeon entered by portals, - * the new level is to be restricted to [top of current dungeon, - * bottom of current dungeon] - * The current behavior is not as sophisticated as that ideal, but is - * still better what we used to do, which was like this for players - * but different for monsters for no obvious reason. Currently, we - * must explicitly check for special dungeons. We check for Knox - * above; endgame is handled in the caller due to its different - * message ("disoriented"). - * --KAA - * 3.4.2: explicitly handle quest here too, to fix the problem of - * monsters sometimes level teleporting out of it into main dungeon. - * Also prevent monsters reaching the Sanctum prior to invocation. - */ - if (In_quest(&u.uz)) { - int bottom = dunlevs_in_dungeon(&u.uz), - qlocate_depth = qlocate_level.dlevel; + /* What I really want to do is as follows: + * -- If in a dungeon that goes down, the new level is to be restricted + * to [top of parent, bottom of current dungeon] + * -- If in a dungeon that goes up, the new level is to be restricted + * to [top of current dungeon, bottom of parent] + * -- If in a quest dungeon or similar dungeon entered by portals, + * the new level is to be restricted to [top of current dungeon, + * bottom of current dungeon] + * The current behavior is not as sophisticated as that ideal, but is + * still better what we used to do, which was like this for players + * but different for monsters for no obvious reason. Currently, we + * must explicitly check for special dungeons. We check for Knox + * above; endgame is handled in the caller due to its different + * message ("disoriented"). + * --KAA + * 3.4.2: explicitly handle quest here too, to fix the problem of + * monsters sometimes level teleporting out of it into main dungeon. + * Also prevent monsters reaching the Sanctum prior to invocation. + */ + if (In_quest(&u.uz)) { + int bottom = dunlevs_in_dungeon(&u.uz), + qlocate_depth = qlocate_level.dlevel; - /* if hero hasn't reached the middle locate level yet, - no one can randomly teleport past it */ - if (dunlev_reached(&u.uz) < qlocate_depth) - bottom = qlocate_depth; - min_depth = dungeons[u.uz.dnum].depth_start; - max_depth = bottom + (dungeons[u.uz.dnum].depth_start - 1); - } else { - min_depth = 1; - max_depth = dunlevs_in_dungeon(&u.uz) + - (dungeons[u.uz.dnum].depth_start - 1); - /* can't reach Sanctum if the invocation hasn't been performed */ - if (Inhell && !u.uevent.invoked) max_depth -= 1; - } + /* if hero hasn't reached the middle locate level yet, + no one can randomly teleport past it */ + if (dunlev_reached(&u.uz) < qlocate_depth) + bottom = qlocate_depth; + min_depth = dungeons[u.uz.dnum].depth_start; + max_depth = bottom + (dungeons[u.uz.dnum].depth_start - 1); + } else { + min_depth = 1; + max_depth = + dunlevs_in_dungeon(&u.uz) + (dungeons[u.uz.dnum].depth_start - 1); + /* can't reach Sanctum if the invocation hasn't been performed */ + if (Inhell && !u.uevent.invoked) + max_depth -= 1; + } - /* Get a random value relative to the current dungeon */ - /* Range is 1 to current+3, current not counting */ - nlev = rn2(cur_depth + 3 - min_depth) + min_depth; - if (nlev >= cur_depth) nlev++; + /* Get a random value relative to the current dungeon */ + /* Range is 1 to current+3, current not counting */ + nlev = rn2(cur_depth + 3 - min_depth) + min_depth; + if (nlev >= cur_depth) + nlev++; - if (nlev > max_depth) { - nlev = max_depth; - /* teleport up if already on bottom */ - if (Is_botlevel(&u.uz)) nlev -= rnd(3); - } - if (nlev < min_depth) { - nlev = min_depth; - if (nlev == cur_depth) { - nlev += rnd(3); - if (nlev > max_depth) - nlev = max_depth; - } - } - return nlev; + if (nlev > max_depth) { + nlev = max_depth; + /* teleport up if already on bottom */ + if (Is_botlevel(&u.uz)) + nlev -= rnd(3); + } + if (nlev < min_depth) { + nlev = min_depth; + if (nlev == cur_depth) { + nlev += rnd(3); + if (nlev > max_depth) + nlev = max_depth; + } + } + return nlev; } /* you teleport a monster (via wand, spell, or poly'd q.mechanic attack); @@ -1284,23 +1323,23 @@ u_teleport_mon(mtmp, give_feedback) struct monst *mtmp; boolean give_feedback; { - coord cc; + coord cc; - if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { - if (give_feedback) - pline("%s resists your magic!", Monnam(mtmp)); - return FALSE; - } else if (level.flags.noteleport && u.uswallow && mtmp == u.ustuck) { - if (give_feedback) - You("are no longer inside %s!", mon_nam(mtmp)); - unstuck(mtmp); - (void) rloc(mtmp, FALSE); - } else if (is_rider(mtmp->data) && rn2(13) && - enexto(&cc, u.ux, u.uy, mtmp->data)) - rloc_to(mtmp, cc.x, cc.y); - else - (void) rloc(mtmp, FALSE); - return TRUE; + if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { + if (give_feedback) + pline("%s resists your magic!", Monnam(mtmp)); + return FALSE; + } else if (level.flags.noteleport && u.uswallow && mtmp == u.ustuck) { + if (give_feedback) + You("are no longer inside %s!", mon_nam(mtmp)); + unstuck(mtmp); + (void) rloc(mtmp, FALSE); + } else if (is_rider(mtmp->data) && rn2(13) + && enexto(&cc, u.ux, u.uy, mtmp->data)) + rloc_to(mtmp, cc.x, cc.y); + else + (void) rloc(mtmp, FALSE); + return TRUE; } /*teleport.c*/ diff --git a/src/timeout.c b/src/timeout.c index a3bfd2a86..32df5f12c 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1,10 +1,10 @@ -/* NetHack 3.6 timeout.c $NHDT-Date: 1430754548 2015/05/04 15:49:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.55 $ */ +/* NetHack 3.6 timeout.c $NHDT-Date: 1431192760 2015/05/09 17:32:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.58 $ */ /* NetHack 3.6 timeout.c $Date: 2012/04/16 00:57:37 $ $Revision: 1.48 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -#include "lev.h" /* for checking save modes */ +#include "lev.h" /* for checking save modes */ STATIC_DCL void NDECL(stoned_dialogue); STATIC_DCL void NDECL(vomiting_dialogue); @@ -13,395 +13,422 @@ STATIC_DCL void NDECL(slime_dialogue); STATIC_DCL void NDECL(slip_or_trip); STATIC_DCL void FDECL(see_lamp_flicker, (struct obj *, const char *)); STATIC_DCL void FDECL(lantern_message, (struct obj *)); -STATIC_DCL void FDECL(cleanup_burn, (ANY_P *,long)); +STATIC_DCL void FDECL(cleanup_burn, (ANY_P *, long)); /* He is being petrified - dialogue by inmet!tower */ -static NEARDATA const char * const stoned_texts[] = { - "You are slowing down.", /* 5 */ - "Your limbs are stiffening.", /* 4 */ - "Your limbs have turned to stone.", /* 3 */ - "You have turned to stone.", /* 2 */ - "You are a statue." /* 1 */ +static NEARDATA const char *const stoned_texts[] = { + "You are slowing down.", /* 5 */ + "Your limbs are stiffening.", /* 4 */ + "Your limbs have turned to stone.", /* 3 */ + "You have turned to stone.", /* 2 */ + "You are a statue." /* 1 */ }; STATIC_OVL void stoned_dialogue() { - register long i = (Stoned & TIMEOUT); + register long i = (Stoned & TIMEOUT); - if (i > 0L && i <= SIZE(stoned_texts)) { - char buf[BUFSZ]; + if (i > 0L && i <= SIZE(stoned_texts)) { + char buf[BUFSZ]; - Strcpy(buf, stoned_texts[SIZE(stoned_texts) - i]); - if (nolimbs(youmonst.data) && strstri(buf, "limbs")) - (void) strsubst(buf, "limbs", "extremities"); - pline1(buf); - } - switch ((int) i) { - case 5: /* slowing down */ - HFast = 0L; - if (multi > 0) nomul(0); - break; - case 4: /* limbs stiffening */ - /* just one move left to save oneself so quit fiddling around; - don't stop attempt to eat tin--might be lizard or acidic */ - if (!Popeye(STONED)) stop_occupation(); - if (multi > 0) nomul(0); - break; - case 3: /* limbs turned to stone */ - stop_occupation(); - nomul(-3); /* can't move anymore */ - multi_reason = "getting stoned"; - nomovemsg = You_can_move_again; /* not unconscious */ - break; - default: - break; - } - exercise(A_DEX, FALSE); + Strcpy(buf, stoned_texts[SIZE(stoned_texts) - i]); + if (nolimbs(youmonst.data) && strstri(buf, "limbs")) + (void) strsubst(buf, "limbs", "extremities"); + pline1(buf); + } + switch ((int) i) { + case 5: /* slowing down */ + HFast = 0L; + if (multi > 0) + nomul(0); + break; + case 4: /* limbs stiffening */ + /* just one move left to save oneself so quit fiddling around; + don't stop attempt to eat tin--might be lizard or acidic */ + if (!Popeye(STONED)) + stop_occupation(); + if (multi > 0) + nomul(0); + break; + case 3: /* limbs turned to stone */ + stop_occupation(); + nomul(-3); /* can't move anymore */ + multi_reason = "getting stoned"; + nomovemsg = You_can_move_again; /* not unconscious */ + break; + default: + break; + } + exercise(A_DEX, FALSE); } /* He is getting sicker and sicker prior to vomiting */ -static NEARDATA const char * const vomiting_texts[] = { - "are feeling mildly nauseated.", /* 14 */ - "feel slightly confused.", /* 11 */ - "can't seem to think straight.", /* 8 */ - "feel incredibly sick.", /* 5 */ - "suddenly vomit!" /* 2 */ +static NEARDATA const char *const vomiting_texts[] = { + "are feeling mildly nauseated.", /* 14 */ + "feel slightly confused.", /* 11 */ + "can't seem to think straight.", /* 8 */ + "feel incredibly sick.", /* 5 */ + "suddenly vomit!" /* 2 */ }; STATIC_OVL void vomiting_dialogue() { - const char *txt = 0; - long v = (Vomiting & TIMEOUT); + const char *txt = 0; + long v = (Vomiting & TIMEOUT); - /* note: nhtimeout() hasn't decremented timed properties for the - current turn yet, so we use Vomiting-1 here */ - switch ((int)(v - 1L)) { - case 14: txt = vomiting_texts[0]; break; - case 11: txt = vomiting_texts[1]; break; - case 6: - make_stunned((HStun & TIMEOUT) + (long)d(2,4), FALSE); - if (!Popeye(VOMITING)) stop_occupation(); - /*FALLTHRU*/ - case 9: - make_confused((HConfusion & TIMEOUT) + (long)d(2,4), FALSE); - if (multi > 0) nomul(0); - break; - case 8: txt = vomiting_texts[2]; break; - case 5: txt = vomiting_texts[3]; break; - case 2: txt = vomiting_texts[4]; - if (cantvomit(youmonst.data)) txt = "gag uncontrolably."; - break; - case 0: - stop_occupation(); - if (!cantvomit(youmonst.data)) morehungry(20); - vomit(); - break; - default: break; - } - if (txt) You1(txt); - exercise(A_CON, FALSE); + /* note: nhtimeout() hasn't decremented timed properties for the + current turn yet, so we use Vomiting-1 here */ + switch ((int) (v - 1L)) { + case 14: + txt = vomiting_texts[0]; + break; + case 11: + txt = vomiting_texts[1]; + break; + case 6: + make_stunned((HStun & TIMEOUT) + (long) d(2, 4), FALSE); + if (!Popeye(VOMITING)) + stop_occupation(); + /*FALLTHRU*/ + case 9: + make_confused((HConfusion & TIMEOUT) + (long) d(2, 4), FALSE); + if (multi > 0) + nomul(0); + break; + case 8: + txt = vomiting_texts[2]; + break; + case 5: + txt = vomiting_texts[3]; + break; + case 2: + txt = vomiting_texts[4]; + if (cantvomit(youmonst.data)) + txt = "gag uncontrolably."; + break; + case 0: + stop_occupation(); + if (!cantvomit(youmonst.data)) + morehungry(20); + vomit(); + break; + default: + break; + } + if (txt) + You1(txt); + exercise(A_CON, FALSE); } -static NEARDATA const char * const choke_texts[] = { - "You find it hard to breathe.", - "You're gasping for air.", - "You can no longer breathe.", - "You're turning %s.", - "You suffocate." +static NEARDATA const char *const choke_texts[] = { + "You find it hard to breathe.", "You're gasping for air.", + "You can no longer breathe.", "You're turning %s.", "You suffocate." }; -static NEARDATA const char * const choke_texts2[] = { - "Your %s is becoming constricted.", - "Your blood is having trouble reaching your brain.", - "The pressure on your %s increases.", - "Your consciousness is fading.", - "You suffocate." +static NEARDATA const char *const choke_texts2[] = { + "Your %s is becoming constricted.", + "Your blood is having trouble reaching your brain.", + "The pressure on your %s increases.", "Your consciousness is fading.", + "You suffocate." }; STATIC_OVL void choke_dialogue() { - register long i = (Strangled & TIMEOUT); + register long i = (Strangled & TIMEOUT); - if(i > 0 && i <= SIZE(choke_texts)) { - if (Breathless || !rn2(50)) - pline(choke_texts2[SIZE(choke_texts2) - i], body_part(NECK)); - else { - const char *str = choke_texts[SIZE(choke_texts)-i]; + if (i > 0 && i <= SIZE(choke_texts)) { + if (Breathless || !rn2(50)) + pline(choke_texts2[SIZE(choke_texts2) - i], body_part(NECK)); + else { + const char *str = choke_texts[SIZE(choke_texts) - i]; - if (index(str, '%')) - pline(str, hcolor(NH_BLUE)); - else - pline1(str); - } - } - exercise(A_STR, FALSE); + if (index(str, '%')) + pline(str, hcolor(NH_BLUE)); + else + pline1(str); + } + } + exercise(A_STR, FALSE); } -static NEARDATA const char * const slime_texts[] = { - "You are turning a little %s.", /* 5 */ - "Your limbs are getting oozy.", /* 4 */ - "Your skin begins to peel away.", /* 3 */ - "You are turning into %s.", /* 2 */ - "You have become %s." /* 1 */ +static NEARDATA const char *const slime_texts[] = { + "You are turning a little %s.", /* 5 */ + "Your limbs are getting oozy.", /* 4 */ + "Your skin begins to peel away.", /* 3 */ + "You are turning into %s.", /* 2 */ + "You have become %s." /* 1 */ }; STATIC_OVL void slime_dialogue() { - register long i = (Slimed & TIMEOUT) / 2L; + register long i = (Slimed & TIMEOUT) / 2L; - if (((Slimed & TIMEOUT) % 2L) && i >= 0L && i < SIZE(slime_texts)) { - char buf[BUFSZ]; + if (((Slimed & TIMEOUT) % 2L) && i >= 0L && i < SIZE(slime_texts)) { + char buf[BUFSZ]; - Strcpy(buf, slime_texts[SIZE(slime_texts) - i - 1L]); - if (nolimbs(youmonst.data) && strstri(buf, "limbs")) - (void) strsubst(buf, "limbs", "extremities"); + Strcpy(buf, slime_texts[SIZE(slime_texts) - i - 1L]); + if (nolimbs(youmonst.data) && strstri(buf, "limbs")) + (void) strsubst(buf, "limbs", "extremities"); - if (index(buf, '%')) { - if (i == 4L) { /* "you are turning green" */ - if (!Blind) /* [what if you're already green?] */ - pline(buf, hcolor(NH_GREEN)); - } else - pline(buf, an(Hallucination ? rndmonnam(NULL) : "green slime")); - } else - pline1(buf); - } - if (i == 3L) { /* limbs becoming oozy */ - HFast = 0L; /* lose intrinsic speed */ - if (!Popeye(SLIMED)) stop_occupation(); - if (multi > 0) nomul(0); - } - exercise(A_DEX, FALSE); + if (index(buf, '%')) { + if (i == 4L) { /* "you are turning green" */ + if (!Blind) /* [what if you're already green?] */ + pline(buf, hcolor(NH_GREEN)); + } else + pline(buf, + an(Hallucination ? rndmonnam(NULL) : "green slime")); + } else + pline1(buf); + } + if (i == 3L) { /* limbs becoming oozy */ + HFast = 0L; /* lose intrinsic speed */ + if (!Popeye(SLIMED)) + stop_occupation(); + if (multi > 0) + nomul(0); + } + exercise(A_DEX, FALSE); } void burn_away_slime() { - if (Slimed) { - make_slimed(0L, "The slime that covers you is burned away!"); - } + if (Slimed) { + make_slimed(0L, "The slime that covers you is burned away!"); + } } - void nh_timeout() { - register struct prop *upp; - struct kinfo *kptr; - int sleeptime; - int m_idx; - int baseluck = (flags.moonphase == FULL_MOON) ? 1 : 0; + register struct prop *upp; + struct kinfo *kptr; + int sleeptime; + int m_idx; + int baseluck = (flags.moonphase == FULL_MOON) ? 1 : 0; - if (flags.friday13) baseluck -= 1; + if (flags.friday13) + baseluck -= 1; - if (u.uluck != baseluck && - moves % (u.uhave.amulet || u.ugangr ? 300 : 600) == 0) { - /* Cursed luckstones stop bad luck from timing out; blessed luckstones - * stop good luck from timing out; normal luckstones stop both; - * neither is stopped if you don't have a luckstone. - * Luck is based at 0 usually, +1 if a full moon and -1 on Friday 13th - */ - register int time_luck = stone_luck(FALSE); - boolean nostone = !carrying(LUCKSTONE) && !stone_luck(TRUE); + if (u.uluck != baseluck + && moves % (u.uhave.amulet || u.ugangr ? 300 : 600) == 0) { + /* Cursed luckstones stop bad luck from timing out; blessed luckstones + * stop good luck from timing out; normal luckstones stop both; + * neither is stopped if you don't have a luckstone. + * Luck is based at 0 usually, +1 if a full moon and -1 on Friday 13th + */ + register int time_luck = stone_luck(FALSE); + boolean nostone = !carrying(LUCKSTONE) && !stone_luck(TRUE); - if(u.uluck > baseluck && (nostone || time_luck < 0)) - u.uluck--; - else if(u.uluck < baseluck && (nostone || time_luck > 0)) - u.uluck++; - } - if(u.uinvulnerable) return; /* things past this point could kill you */ - if(Stoned) stoned_dialogue(); - if(Slimed) slime_dialogue(); - if(Vomiting) vomiting_dialogue(); - if(Strangled) choke_dialogue(); - if(u.mtimedone && !--u.mtimedone) { - if (Unchanging) - u.mtimedone = rnd(100*youmonst.data->mlevel + 1); - else - rehumanize(); - } - if(u.ucreamed) u.ucreamed--; + if (u.uluck > baseluck && (nostone || time_luck < 0)) + u.uluck--; + else if (u.uluck < baseluck && (nostone || time_luck > 0)) + u.uluck++; + } + if (u.uinvulnerable) + return; /* things past this point could kill you */ + if (Stoned) + stoned_dialogue(); + if (Slimed) + slime_dialogue(); + if (Vomiting) + vomiting_dialogue(); + if (Strangled) + choke_dialogue(); + if (u.mtimedone && !--u.mtimedone) { + if (Unchanging) + u.mtimedone = rnd(100 * youmonst.data->mlevel + 1); + else + rehumanize(); + } + if (u.ucreamed) + u.ucreamed--; - /* Dissipate spell-based protection. */ - if (u.usptime) { - if (--u.usptime == 0 && u.uspellprot) { - u.usptime = u.uspmtime; - u.uspellprot--; - find_ac(); - if (!Blind) - Norep("The %s haze around you %s.", hcolor(NH_GOLDEN), - u.uspellprot ? "becomes less dense" : "disappears"); - } - } + /* Dissipate spell-based protection. */ + if (u.usptime) { + if (--u.usptime == 0 && u.uspellprot) { + u.usptime = u.uspmtime; + u.uspellprot--; + find_ac(); + if (!Blind) + Norep("The %s haze around you %s.", hcolor(NH_GOLDEN), + u.uspellprot ? "becomes less dense" : "disappears"); + } + } - if (u.ugallop) { - if (--u.ugallop == 0L && u.usteed) - pline("%s stops galloping.", Monnam(u.usteed)); - } + if (u.ugallop) { + if (--u.ugallop == 0L && u.usteed) + pline("%s stops galloping.", Monnam(u.usteed)); + } - for(upp = u.uprops; upp < u.uprops+SIZE(u.uprops); upp++) - if((upp->intrinsic & TIMEOUT) && !(--upp->intrinsic & TIMEOUT)) { - kptr = find_delayed_killer((int)(upp - u.uprops)); - switch(upp - u.uprops){ - case STONED: - if (kptr && kptr->name[0]) { - killer.format = kptr->format; - Strcpy(killer.name, kptr->name); - } else { - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "killed by petrification"); - } - dealloc_killer(kptr); - /* (unlike sliming, you aren't changing form here) */ - done(STONING); - break; - case SLIMED: - if (kptr && kptr->name[0]) { - killer.format = kptr->format; - Strcpy(killer.name, kptr->name); - } else { - killer.format = NO_KILLER_PREFIX; - Strcpy(killer.name, "turned into green slime"); - } - dealloc_killer(kptr); - /* involuntarily break "never changed form" conduct */ - u.uconduct.polyselfs++; - done(TURNED_SLIME); - break; - case VOMITING: - make_vomiting(0L, TRUE); - break; - case SICK: - You("die from your illness."); - if (kptr && kptr->name[0]) { - killer.format = kptr->format; - Strcpy(killer.name, kptr->name); - } else { - killer.format = KILLED_BY_AN; - killer.name[0] = 0; /* take the default */ - } - dealloc_killer(kptr); + for (upp = u.uprops; upp < u.uprops + SIZE(u.uprops); upp++) + if ((upp->intrinsic & TIMEOUT) && !(--upp->intrinsic & TIMEOUT)) { + kptr = find_delayed_killer((int) (upp - u.uprops)); + switch (upp - u.uprops) { + case STONED: + if (kptr && kptr->name[0]) { + killer.format = kptr->format; + Strcpy(killer.name, kptr->name); + } else { + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "killed by petrification"); + } + dealloc_killer(kptr); + /* (unlike sliming, you aren't changing form here) */ + done(STONING); + break; + case SLIMED: + if (kptr && kptr->name[0]) { + killer.format = kptr->format; + Strcpy(killer.name, kptr->name); + } else { + killer.format = NO_KILLER_PREFIX; + Strcpy(killer.name, "turned into green slime"); + } + dealloc_killer(kptr); + /* involuntarily break "never changed form" conduct */ + u.uconduct.polyselfs++; + done(TURNED_SLIME); + break; + case VOMITING: + make_vomiting(0L, TRUE); + break; + case SICK: + You("die from your illness."); + if (kptr && kptr->name[0]) { + killer.format = kptr->format; + Strcpy(killer.name, kptr->name); + } else { + killer.format = KILLED_BY_AN; + killer.name[0] = 0; /* take the default */ + } + dealloc_killer(kptr); - if ((m_idx = name_to_mon(killer.name)) >= LOW_PM) { - if (type_is_pname(&mons[m_idx])) { - killer.format = KILLED_BY; - } else if (mons[m_idx].geno & G_UNIQ) { - Strcpy(killer.name, the(killer.name)); - killer.format = KILLED_BY; - } - } - u.usick_type = 0; - done(POISONING); - break; - case FAST: - if (!Very_fast) - You_feel("yourself slowing down%s.", - Fast ? " a bit" : ""); - break; - case CONFUSION: - /* So make_confused works properly */ - set_itimeout(&HConfusion, 1L); - make_confused(0L, TRUE); - if (!Confusion) stop_occupation(); - break; - case STUNNED: - set_itimeout(&HStun, 1L); - make_stunned(0L, TRUE); - if (!Stunned) stop_occupation(); - break; - case BLINDED: - set_itimeout(&Blinded, 1L); - make_blinded(0L, TRUE); - if (!Blind) stop_occupation(); - break; - case DEAF: - if (!Deaf) { - You("can hear again."); - stop_occupation(); - } - break; - case INVIS: - newsym(u.ux,u.uy); - if (!Invis && !BInvis && !Blind) { - You(!See_invisible ? - "are no longer invisible." : - "can no longer see through yourself."); - stop_occupation(); - } - break; - case SEE_INVIS: - set_mimic_blocking(); /* do special mimic handling */ - see_monsters(); /* make invis mons appear */ - newsym(u.ux,u.uy); /* make self appear */ - stop_occupation(); - break; - case WOUNDED_LEGS: - heal_legs(); - stop_occupation(); - break; - case HALLUC: - set_itimeout(&HHallucination, 1L); - (void) make_hallucinated(0L, TRUE, 0L); - if (!Hallucination) stop_occupation(); - break; - case SLEEPY: - if (unconscious() || Sleep_resistance) { - incr_itimeout(&HSleepy, rnd(100)); - } else if (Sleepy) { - You("fall asleep."); - sleeptime = rnd(20); - fall_asleep(-sleeptime, TRUE); - incr_itimeout(&HSleepy, sleeptime + rnd(100)); - } - break; - case LEVITATION: - (void) float_down(I_SPECIAL|TIMEOUT, 0L); - break; - case STRANGLED: - killer.format = KILLED_BY; - Strcpy(killer.name, - (u.uburied) ? "suffocation" : "strangulation"); - done(DIED); - /* must be declining to die in explore|wizard mode; - treat like being cured of strangulation by prayer */ - if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) { - Your("amulet vanishes!"); - useup(uamul); - } - break; - case FUMBLING: - /* call this only when a move took place. */ - /* otherwise handle fumbling msgs locally. */ - if (u.umoved && !Levitation) { - slip_or_trip(); - nomul(-2); - multi_reason = "fumbling"; - nomovemsg = ""; - /* The more you are carrying the more likely you - * are to make noise when you fumble. Adjustments - * to this number must be thoroughly play tested. - */ - if ((inv_weight() > -500)) { - You("make a lot of noise!"); - wake_nearby(); - } - } - /* from outside means slippery ice; don't reset - counter if that's the only fumble reason */ - HFumbling &= ~FROMOUTSIDE; - if (Fumbling) - incr_itimeout(&HFumbling, rnd(20)); - break; - case DETECT_MONSTERS: - see_monsters(); - break; - } - } + if ((m_idx = name_to_mon(killer.name)) >= LOW_PM) { + if (type_is_pname(&mons[m_idx])) { + killer.format = KILLED_BY; + } else if (mons[m_idx].geno & G_UNIQ) { + Strcpy(killer.name, the(killer.name)); + killer.format = KILLED_BY; + } + } + u.usick_type = 0; + done(POISONING); + break; + case FAST: + if (!Very_fast) + You_feel("yourself slowing down%s.", + Fast ? " a bit" : ""); + break; + case CONFUSION: + /* So make_confused works properly */ + set_itimeout(&HConfusion, 1L); + make_confused(0L, TRUE); + if (!Confusion) + stop_occupation(); + break; + case STUNNED: + set_itimeout(&HStun, 1L); + make_stunned(0L, TRUE); + if (!Stunned) + stop_occupation(); + break; + case BLINDED: + set_itimeout(&Blinded, 1L); + make_blinded(0L, TRUE); + if (!Blind) + stop_occupation(); + break; + case DEAF: + if (!Deaf) { + You("can hear again."); + stop_occupation(); + } + break; + case INVIS: + newsym(u.ux, u.uy); + if (!Invis && !BInvis && !Blind) { + You(!See_invisible + ? "are no longer invisible." + : "can no longer see through yourself."); + stop_occupation(); + } + break; + case SEE_INVIS: + set_mimic_blocking(); /* do special mimic handling */ + see_monsters(); /* make invis mons appear */ + newsym(u.ux, u.uy); /* make self appear */ + stop_occupation(); + break; + case WOUNDED_LEGS: + heal_legs(); + stop_occupation(); + break; + case HALLUC: + set_itimeout(&HHallucination, 1L); + (void) make_hallucinated(0L, TRUE, 0L); + if (!Hallucination) + stop_occupation(); + break; + case SLEEPY: + if (unconscious() || Sleep_resistance) { + incr_itimeout(&HSleepy, rnd(100)); + } else if (Sleepy) { + You("fall asleep."); + sleeptime = rnd(20); + fall_asleep(-sleeptime, TRUE); + incr_itimeout(&HSleepy, sleeptime + rnd(100)); + } + break; + case LEVITATION: + (void) float_down(I_SPECIAL | TIMEOUT, 0L); + break; + case STRANGLED: + killer.format = KILLED_BY; + Strcpy(killer.name, + (u.uburied) ? "suffocation" : "strangulation"); + done(DIED); + /* must be declining to die in explore|wizard mode; + treat like being cured of strangulation by prayer */ + if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) { + Your("amulet vanishes!"); + useup(uamul); + } + break; + case FUMBLING: + /* call this only when a move took place. */ + /* otherwise handle fumbling msgs locally. */ + if (u.umoved && !Levitation) { + slip_or_trip(); + nomul(-2); + multi_reason = "fumbling"; + nomovemsg = ""; + /* The more you are carrying the more likely you + * are to make noise when you fumble. Adjustments + * to this number must be thoroughly play tested. + */ + if ((inv_weight() > -500)) { + You("make a lot of noise!"); + wake_nearby(); + } + } + /* from outside means slippery ice; don't reset + counter if that's the only fumble reason */ + HFumbling &= ~FROMOUTSIDE; + if (Fumbling) + incr_itimeout(&HFumbling, rnd(20)); + break; + case DETECT_MONSTERS: + see_monsters(); + break; + } + } - run_timers(); + run_timers(); } void @@ -409,19 +436,19 @@ fall_asleep(how_long, wakeup_msg) int how_long; boolean wakeup_msg; { - stop_occupation(); - nomul(how_long); - multi_reason = "sleeping"; - /* generally don't notice sounds while sleeping */ - if (wakeup_msg && multi == how_long) { - /* caller can follow with a direct call to Hear_again() if - there's a need to override this when wakeup_msg is true */ - incr_itimeout(&HDeaf, how_long); - afternmv = Hear_again; /* this won't give any messages */ - } - /* early wakeup from combat won't be possible until next monster turn */ - u.usleep = monstermoves; - nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again; + stop_occupation(); + nomul(how_long); + multi_reason = "sleeping"; + /* generally don't notice sounds while sleeping */ + if (wakeup_msg && multi == how_long) { + /* caller can follow with a direct call to Hear_again() if + there's a need to override this when wakeup_msg is true */ + incr_itimeout(&HDeaf, how_long); + afternmv = Hear_again; /* this won't give any messages */ + } + /* early wakeup from combat won't be possible until next monster turn */ + u.usleep = monstermoves; + nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again; } /* Attach an egg hatch timeout to the given egg. @@ -433,29 +460,28 @@ attach_egg_hatch_timeout(egg, when) struct obj *egg; long when; { - int i; + int i; - /* stop previous timer, if any */ - (void) stop_timer(HATCH_EGG, obj_to_any(egg)); + /* stop previous timer, if any */ + (void) stop_timer(HATCH_EGG, obj_to_any(egg)); - /* - * Decide if and when to hatch the egg. The old hatch_it() code tried - * once a turn from age 151 to 200 (inclusive), hatching if it rolled - * a number x, 1<=x<=age, where x>150. This yields a chance of - * hatching > 99.9993%. Mimic that here. - */ - if (!when) { - for (i = (MAX_EGG_HATCH_TIME-50)+1; i <= MAX_EGG_HATCH_TIME; i++) - if (rnd(i) > 150) { - /* egg will hatch */ - when = (long)i; - break; - } - } - if (when) { - (void) start_timer(when, TIMER_OBJECT, - HATCH_EGG, obj_to_any(egg)); - } + /* + * Decide if and when to hatch the egg. The old hatch_it() code tried + * once a turn from age 151 to 200 (inclusive), hatching if it rolled + * a number x, 1<=x<=age, where x>150. This yields a chance of + * hatching > 99.9993%. Mimic that here. + */ + if (!when) { + for (i = (MAX_EGG_HATCH_TIME - 50) + 1; i <= MAX_EGG_HATCH_TIME; i++) + if (rnd(i) > 150) { + /* egg will hatch */ + when = (long) i; + break; + } + } + if (when) { + (void) start_timer(when, TIMER_OBJECT, HATCH_EGG, obj_to_any(egg)); + } } /* prevent an egg from ever hatching */ @@ -463,8 +489,8 @@ void kill_egg(egg) struct obj *egg; { - /* stop previous timer, if any */ - (void) stop_timer(HATCH_EGG, obj_to_any(egg)); + /* stop previous timer, if any */ + (void) stop_timer(HATCH_EGG, obj_to_any(egg)); } /* timer callback routine: hatch the given egg */ @@ -473,53 +499,55 @@ hatch_egg(arg, timeout) anything *arg; long timeout; { - struct obj *egg; - struct monst *mon, *mon2; - coord cc; - xchar x, y; - boolean yours, silent, knows_egg = FALSE; - boolean cansee_hatchspot = FALSE; - int i, mnum, hatchcount = 0; + struct obj *egg; + struct monst *mon, *mon2; + coord cc; + xchar x, y; + boolean yours, silent, knows_egg = FALSE; + boolean cansee_hatchspot = FALSE; + int i, mnum, hatchcount = 0; - egg = arg->a_obj; - /* sterilized while waiting */ - if (egg->corpsenm == NON_PM) return; + egg = arg->a_obj; + /* sterilized while waiting */ + if (egg->corpsenm == NON_PM) + return; - mon = mon2 = (struct monst *)0; - mnum = big_to_little(egg->corpsenm); - /* The identity of one's father is learned, not innate */ - yours = (egg->spe || (!flags.female && carried(egg) && !rn2(2))); - silent = (timeout != monstermoves); /* hatched while away */ + mon = mon2 = (struct monst *) 0; + mnum = big_to_little(egg->corpsenm); + /* The identity of one's father is learned, not innate */ + yours = (egg->spe || (!flags.female && carried(egg) && !rn2(2))); + silent = (timeout != monstermoves); /* hatched while away */ - /* only can hatch when in INVENT, FLOOR, MINVENT */ - if (get_obj_location(egg, &x, &y, 0)) { - hatchcount = rnd((int)egg->quan); - cansee_hatchspot = cansee(x, y) && !silent; - if (!(mons[mnum].geno & G_UNIQ) && - !(mvitals[mnum].mvflags & (G_GENOD | G_EXTINCT))) { - for (i = hatchcount; i > 0; i--) { - if (!enexto(&cc, x, y, &mons[mnum]) || - !(mon = makemon(&mons[mnum], cc.x, cc.y, NO_MINVENT))) - break; - /* tame if your own egg hatches while you're on the - same dungeon level, or any dragon egg which hatches - while it's in your inventory */ - if ((yours && !silent) || - (carried(egg) && mon->data->mlet == S_DRAGON)) { - if (tamedog(mon, (struct obj *)0)) { - if (carried(egg) && mon->data->mlet != S_DRAGON) - mon->mtame = 20; - } - } - if (mvitals[mnum].mvflags & G_EXTINCT) - break; /* just made last one */ - mon2 = mon; /* in case makemon() fails on 2nd egg */ - } - if (!mon) mon = mon2; - hatchcount -= i; - egg->quan -= (long)hatchcount; - } - } + /* only can hatch when in INVENT, FLOOR, MINVENT */ + if (get_obj_location(egg, &x, &y, 0)) { + hatchcount = rnd((int) egg->quan); + cansee_hatchspot = cansee(x, y) && !silent; + if (!(mons[mnum].geno & G_UNIQ) + && !(mvitals[mnum].mvflags & (G_GENOD | G_EXTINCT))) { + for (i = hatchcount; i > 0; i--) { + if (!enexto(&cc, x, y, &mons[mnum]) + || !(mon = makemon(&mons[mnum], cc.x, cc.y, NO_MINVENT))) + break; + /* tame if your own egg hatches while you're on the + same dungeon level, or any dragon egg which hatches + while it's in your inventory */ + if ((yours && !silent) + || (carried(egg) && mon->data->mlet == S_DRAGON)) { + if (tamedog(mon, (struct obj *) 0)) { + if (carried(egg) && mon->data->mlet != S_DRAGON) + mon->mtame = 20; + } + } + if (mvitals[mnum].mvflags & G_EXTINCT) + break; /* just made last one */ + mon2 = mon; /* in case makemon() fails on 2nd egg */ + } + if (!mon) + mon = mon2; + hatchcount -= i; + egg->quan -= (long) hatchcount; + } + } #if 0 /* * We could possibly hatch while migrating, but the code isn't @@ -547,90 +575,87 @@ long timeout; } #endif - if (mon) { - char monnambuf[BUFSZ], carriedby[BUFSZ]; - boolean siblings = (hatchcount > 1), redraw = FALSE; + if (mon) { + char monnambuf[BUFSZ], carriedby[BUFSZ]; + boolean siblings = (hatchcount > 1), redraw = FALSE; - if (cansee_hatchspot) { - Sprintf(monnambuf, "%s%s", - siblings ? "some " : "", - siblings ? - makeplural(m_monnam(mon)) : an(m_monnam(mon))); - /* we don't learn the egg type here because learning - an egg type requires either seeing the egg hatch - or being familiar with the egg already, - as well as being able to see the resulting - monster, checked below - */ - } - switch (egg->where) { - case OBJ_INVENT: - knows_egg = TRUE; /* true even if you are blind */ - if (!cansee_hatchspot) - You_feel("%s %s from your pack!", something, - locomotion(mon->data, "drop")); - else - You_see("%s %s out of your pack!", - monnambuf, locomotion(mon->data, "drop")); - if (yours) { - pline("%s cries sound like \"%s%s\"", - siblings ? "Their" : "Its", - flags.female ? "mommy" : "daddy", - egg->spe ? "." : "?"); - } else if (mon->data->mlet == S_DRAGON && !Deaf) { - verbalize("Gleep!"); /* Mything eggs :-) */ - } - break; + if (cansee_hatchspot) { + Sprintf(monnambuf, "%s%s", siblings ? "some " : "", + siblings ? makeplural(m_monnam(mon)) : an(m_monnam(mon))); + /* we don't learn the egg type here because learning + an egg type requires either seeing the egg hatch + or being familiar with the egg already, + as well as being able to see the resulting + monster, checked below + */ + } + switch (egg->where) { + case OBJ_INVENT: + knows_egg = TRUE; /* true even if you are blind */ + if (!cansee_hatchspot) + You_feel("%s %s from your pack!", something, + locomotion(mon->data, "drop")); + else + You_see("%s %s out of your pack!", monnambuf, + locomotion(mon->data, "drop")); + if (yours) { + pline("%s cries sound like \"%s%s\"", + siblings ? "Their" : "Its", + flags.female ? "mommy" : "daddy", egg->spe ? "." : "?"); + } else if (mon->data->mlet == S_DRAGON && !Deaf) { + verbalize("Gleep!"); /* Mything eggs :-) */ + } + break; - case OBJ_FLOOR: - if (cansee_hatchspot) { - knows_egg = TRUE; - You_see("%s hatch.", monnambuf); - redraw = TRUE; /* update egg's map location */ - } - break; + case OBJ_FLOOR: + if (cansee_hatchspot) { + knows_egg = TRUE; + You_see("%s hatch.", monnambuf); + redraw = TRUE; /* update egg's map location */ + } + break; - case OBJ_MINVENT: - if (cansee_hatchspot) { - /* egg carring monster might be invisible */ - if (canseemon(egg->ocarry)) { - Sprintf(carriedby, "%s pack", - s_suffix(a_monnam(egg->ocarry))); - knows_egg = TRUE; - } - else if (is_pool(mon->mx, mon->my)) - Strcpy(carriedby, "empty water"); - else - Strcpy(carriedby, "thin air"); - You_see("%s %s out of %s!", monnambuf, - locomotion(mon->data, "drop"), carriedby); - } - break; + case OBJ_MINVENT: + if (cansee_hatchspot) { + /* egg carring monster might be invisible */ + if (canseemon(egg->ocarry)) { + Sprintf(carriedby, "%s pack", + s_suffix(a_monnam(egg->ocarry))); + knows_egg = TRUE; + } else if (is_pool(mon->mx, mon->my)) + Strcpy(carriedby, "empty water"); + else + Strcpy(carriedby, "thin air"); + You_see("%s %s out of %s!", monnambuf, + locomotion(mon->data, "drop"), carriedby); + } + break; #if 0 case OBJ_MIGRATING: break; #endif - default: - impossible("egg hatched where? (%d)", (int)egg->where); - break; - } + default: + impossible("egg hatched where? (%d)", (int) egg->where); + break; + } - if (cansee_hatchspot && knows_egg) - learn_egg_type(mnum); + if (cansee_hatchspot && knows_egg) + learn_egg_type(mnum); - if (egg->quan > 0) { - /* still some eggs left */ - /* Instead of ordinary egg timeout use a short one */ - attach_egg_hatch_timeout(egg, (long)rnd(12)); - } else if (carried(egg)) { - useup(egg); - } else { - /* free egg here because we use it above */ - obj_extract_self(egg); - obfree(egg, (struct obj *)0); - } - if (redraw) newsym(x, y); - } + if (egg->quan > 0) { + /* still some eggs left */ + /* Instead of ordinary egg timeout use a short one */ + attach_egg_hatch_timeout(egg, (long) rnd(12)); + } else if (carried(egg)) { + useup(egg); + } else { + /* free egg here because we use it above */ + obj_extract_self(egg); + obfree(egg, (struct obj *) 0); + } + if (redraw) + newsym(x, y); + } } /* Learn to recognize eggs of the given type. */ @@ -638,11 +663,11 @@ void learn_egg_type(mnum) int mnum; { - /* baby monsters hatch from grown-up eggs */ - mnum = little_to_big(mnum); - mvitals[mnum].mvflags |= MV_KNOWS_EGG; - /* we might have just learned about other eggs being carried */ - update_inventory(); + /* baby monsters hatch from grown-up eggs */ + mnum = little_to_big(mnum); + mvitals[mnum].mvflags |= MV_KNOWS_EGG; + /* we might have just learned about other eggs being carried */ + update_inventory(); } /* Attach a fig_transform timeout to the given figurine. */ @@ -650,103 +675,110 @@ void attach_fig_transform_timeout(figurine) struct obj *figurine; { - int i; + int i; - /* stop previous timer, if any */ - (void) stop_timer(FIG_TRANSFORM, obj_to_any(figurine)); + /* stop previous timer, if any */ + (void) stop_timer(FIG_TRANSFORM, obj_to_any(figurine)); - /* - * Decide when to transform the figurine. - */ - i = rnd(9000) + 200; - /* figurine will transform */ - (void) start_timer((long)i, TIMER_OBJECT, - FIG_TRANSFORM, obj_to_any(figurine)); + /* + * Decide when to transform the figurine. + */ + i = rnd(9000) + 200; + /* figurine will transform */ + (void) start_timer((long) i, TIMER_OBJECT, FIG_TRANSFORM, + obj_to_any(figurine)); } /* give a fumble message */ STATIC_OVL void slip_or_trip() { - struct obj *otmp = vobj_at(u.ux, u.uy); - const char *what; - char buf[BUFSZ]; - boolean on_foot = TRUE; - if (u.usteed) on_foot = FALSE; + struct obj *otmp = vobj_at(u.ux, u.uy); + const char *what; + char buf[BUFSZ]; + boolean on_foot = TRUE; + if (u.usteed) + on_foot = FALSE; - if (otmp && on_foot && !u.uinwater && is_pool(u.ux, u.uy)) otmp = 0; + if (otmp && on_foot && !u.uinwater && is_pool(u.ux, u.uy)) + otmp = 0; - if (otmp && on_foot) { /* trip over something in particular */ - /* - If there is only one item, it will have just been named - during the move, so refer to by via pronoun; otherwise, - if the top item has been or can be seen, refer to it by - name; if not, look for rocks to trip over; trip over - anonymous "something" if there aren't any rocks. - */ - what = (iflags.last_msg == PLNMSG_ONE_ITEM_HERE) ? - ((otmp->quan == 1L) ? "it" : Hallucination ? "they" : "them") : - (otmp->dknown || !Blind) ? doname(otmp) : - ((otmp = sobj_at(ROCK, u.ux, u.uy)) == 0 ? something : - (otmp->quan == 1L ? "a rock" : "some rocks")); - if (Hallucination) { - what = strcpy(buf, what); - buf[0] = highc(buf[0]); - pline("Egads! %s bite%s your %s!", - what, (!otmp || otmp->quan == 1L) ? "s" : "", - body_part(FOOT)); - } else { - You("trip over %s.", what); - } - if (!uarmf && otmp->otyp == CORPSE && - touch_petrifies(&mons[otmp->corpsenm]) && !Stone_resistance) { - Sprintf(killer.name, "tripping over %s corpse", - an(mons[otmp->corpsenm].mname)); - instapetrify(killer.name); - } - } else if (rn2(3) && is_ice(u.ux, u.uy)) { - pline("%s %s%s on the ice.", - u.usteed ? upstart(x_monnam(u.usteed, - (has_mname(u.usteed)) ? ARTICLE_NONE : ARTICLE_THE, - (char *)0, SUPPRESS_SADDLE, FALSE)) : - "You", rn2(2) ? "slip" : "slide", on_foot ? "" : "s"); - } else { - if (on_foot) { - switch (rn2(4)) { - case 1: - You("trip over your own %s.", Hallucination ? - "elbow" : makeplural(body_part(FOOT))); - break; - case 2: - You("slip %s.", Hallucination ? - "on a banana peel" : "and nearly fall"); - break; - case 3: - You("flounder."); - break; - default: - You("stumble."); - break; - } - } - else { - switch (rn2(4)) { - case 1: - Your("%s slip out of the stirrups.", makeplural(body_part(FOOT))); - break; - case 2: - You("let go of the reins."); - break; - case 3: - You("bang into the saddle-horn."); - break; - default: - You("slide to one side of the saddle."); - break; - } - dismount_steed(DISMOUNT_FELL); - } - } + if (otmp && on_foot) { /* trip over something in particular */ + /* + If there is only one item, it will have just been named + during the move, so refer to by via pronoun; otherwise, + if the top item has been or can be seen, refer to it by + name; if not, look for rocks to trip over; trip over + anonymous "something" if there aren't any rocks. + */ + what = + (iflags.last_msg == PLNMSG_ONE_ITEM_HERE) + ? ((otmp->quan == 1L) ? "it" : Hallucination ? "they" + : "them") + : (otmp->dknown || !Blind) + ? doname(otmp) + : ((otmp = sobj_at(ROCK, u.ux, u.uy)) == 0 + ? something + : (otmp->quan == 1L ? "a rock" : "some rocks")); + if (Hallucination) { + what = strcpy(buf, what); + buf[0] = highc(buf[0]); + pline("Egads! %s bite%s your %s!", what, + (!otmp || otmp->quan == 1L) ? "s" : "", body_part(FOOT)); + } else { + You("trip over %s.", what); + } + if (!uarmf && otmp->otyp == CORPSE + && touch_petrifies(&mons[otmp->corpsenm]) && !Stone_resistance) { + Sprintf(killer.name, "tripping over %s corpse", + an(mons[otmp->corpsenm].mname)); + instapetrify(killer.name); + } + } else if (rn2(3) && is_ice(u.ux, u.uy)) { + pline("%s %s%s on the ice.", + u.usteed ? upstart(x_monnam(u.usteed, + (has_mname(u.usteed)) ? ARTICLE_NONE + : ARTICLE_THE, + (char *) 0, SUPPRESS_SADDLE, FALSE)) + : "You", + rn2(2) ? "slip" : "slide", on_foot ? "" : "s"); + } else { + if (on_foot) { + switch (rn2(4)) { + case 1: + You("trip over your own %s.", + Hallucination ? "elbow" : makeplural(body_part(FOOT))); + break; + case 2: + You("slip %s.", + Hallucination ? "on a banana peel" : "and nearly fall"); + break; + case 3: + You("flounder."); + break; + default: + You("stumble."); + break; + } + } else { + switch (rn2(4)) { + case 1: + Your("%s slip out of the stirrups.", + makeplural(body_part(FOOT))); + break; + case 2: + You("let go of the reins."); + break; + case 3: + You("bang into the saddle-horn."); + break; + default: + You("slide to one side of the saddle."); + break; + } + dismount_steed(DISMOUNT_FELL); + } + } } /* Print a lamp flicker message with tailer. */ @@ -755,15 +787,15 @@ see_lamp_flicker(obj, tailer) struct obj *obj; const char *tailer; { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%s flickers%s.", Yname2(obj), tailer); - break; - case OBJ_FLOOR: - You_see("%s flicker%s.", an(xname(obj)), tailer); - break; - } + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%s flickers%s.", Yname2(obj), tailer); + break; + case OBJ_FLOOR: + You_see("%s flicker%s.", an(xname(obj)), tailer); + break; + } } /* Print a dimming message for brass lanterns. */ @@ -771,21 +803,20 @@ STATIC_OVL void lantern_message(obj) struct obj *obj; { - /* from adventure */ - switch (obj->where) { - case OBJ_INVENT: - Your("lantern is getting dim."); - if (Hallucination) - pline("Batteries have not been invented yet."); - break; - case OBJ_FLOOR: - You_see("a lantern getting dim."); - break; - case OBJ_MINVENT: - pline("%s lantern is getting dim.", - s_suffix(Monnam(obj->ocarry))); - break; - } + /* from adventure */ + switch (obj->where) { + case OBJ_INVENT: + Your("lantern is getting dim."); + if (Hallucination) + pline("Batteries have not been invented yet."); + break; + case OBJ_FLOOR: + You_see("a lantern getting dim."); + break; + case OBJ_MINVENT: + pline("%s lantern is getting dim.", s_suffix(Monnam(obj->ocarry))); + break; + } } /* @@ -797,280 +828,268 @@ burn_object(arg, timeout) anything *arg; long timeout; { - struct obj *obj = arg->a_obj; - boolean canseeit, many, menorah, need_newsym; - xchar x, y; - char whose[BUFSZ]; + struct obj *obj = arg->a_obj; + boolean canseeit, many, menorah, need_newsym; + xchar x, y; + char whose[BUFSZ]; - menorah = obj->otyp == CANDELABRUM_OF_INVOCATION; - many = menorah ? obj->spe > 1 : obj->quan > 1L; + menorah = obj->otyp == CANDELABRUM_OF_INVOCATION; + many = menorah ? obj->spe > 1 : obj->quan > 1L; - /* timeout while away */ - if (timeout != monstermoves) { - long how_long = monstermoves - timeout; + /* timeout while away */ + if (timeout != monstermoves) { + long how_long = monstermoves - timeout; - if (how_long >= obj->age) { - obj->age = 0; - end_burn(obj, FALSE); + if (how_long >= obj->age) { + obj->age = 0; + end_burn(obj, FALSE); - if (menorah) { - obj->spe = 0; /* no more candles */ - } else if (Is_candle(obj) || obj->otyp == POT_OIL) { - /* get rid of candles and burning oil potions; - we know this object isn't carried by hero, - nor is it migrating */ - obj_extract_self(obj); - obfree(obj, (struct obj *)0); - obj = (struct obj *) 0; - } + if (menorah) { + obj->spe = 0; /* no more candles */ + } else if (Is_candle(obj) || obj->otyp == POT_OIL) { + /* get rid of candles and burning oil potions; + we know this object isn't carried by hero, + nor is it migrating */ + obj_extract_self(obj); + obfree(obj, (struct obj *) 0); + obj = (struct obj *) 0; + } - } else { - obj->age -= how_long; - begin_burn(obj, TRUE); - } - return; - } + } else { + obj->age -= how_long; + begin_burn(obj, TRUE); + } + return; + } - /* only interested in INVENT, FLOOR, and MINVENT */ - if (get_obj_location(obj, &x, &y, 0)) { - canseeit = !Blind && cansee(x, y); - /* set `whose[]' to be "Your " or "Fred's " or "The goblin's " */ - (void) Shk_Your(whose, obj); - } else { - canseeit = FALSE; - } - need_newsym = FALSE; + /* only interested in INVENT, FLOOR, and MINVENT */ + if (get_obj_location(obj, &x, &y, 0)) { + canseeit = !Blind && cansee(x, y); + /* set `whose[]' to be "Your " or "Fred's " or "The goblin's " */ + (void) Shk_Your(whose, obj); + } else { + canseeit = FALSE; + } + need_newsym = FALSE; - /* obj->age is the age remaining at this point. */ - switch (obj->otyp) { - case POT_OIL: - /* this should only be called when we run out */ - if (canseeit) { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%spotion of oil has burnt away.", - whose); - break; - case OBJ_FLOOR: - You_see("a burning potion of oil go out."); - need_newsym = TRUE; - break; - } - } - end_burn(obj, FALSE); /* turn off light source */ - if (carried(obj)) { - useupall(obj); - } else { - /* clear migrating obj's destination code before obfree - to avoid false complaint of deleting worn item */ - if (obj->where == OBJ_MIGRATING) obj->owornmask = 0L; - obj_extract_self(obj); - obfree(obj, (struct obj *)0); - } - obj = (struct obj *) 0; - break; + /* obj->age is the age remaining at this point. */ + switch (obj->otyp) { + case POT_OIL: + /* this should only be called when we run out */ + if (canseeit) { + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%spotion of oil has burnt away.", whose); + break; + case OBJ_FLOOR: + You_see("a burning potion of oil go out."); + need_newsym = TRUE; + break; + } + } + end_burn(obj, FALSE); /* turn off light source */ + if (carried(obj)) { + useupall(obj); + } else { + /* clear migrating obj's destination code before obfree + to avoid false complaint of deleting worn item */ + if (obj->where == OBJ_MIGRATING) + obj->owornmask = 0L; + obj_extract_self(obj); + obfree(obj, (struct obj *) 0); + } + obj = (struct obj *) 0; + break; - case BRASS_LANTERN: - case OIL_LAMP: - switch((int)obj->age) { - case 150: - case 100: - case 50: - if (canseeit) { - if (obj->otyp == BRASS_LANTERN) - lantern_message(obj); - else - see_lamp_flicker(obj, - obj->age == 50L ? " considerably" : ""); - } - break; + case BRASS_LANTERN: + case OIL_LAMP: + switch ((int) obj->age) { + case 150: + case 100: + case 50: + if (canseeit) { + if (obj->otyp == BRASS_LANTERN) + lantern_message(obj); + else + see_lamp_flicker(obj, + obj->age == 50L ? " considerably" : ""); + } + break; - case 25: - if (canseeit) { - if (obj->otyp == BRASS_LANTERN) - lantern_message(obj); - else { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%s seems about to go out.", - Yname2(obj)); - break; - case OBJ_FLOOR: - You_see("%s about to go out.", - an(xname(obj))); - break; - } - } - } - break; + case 25: + if (canseeit) { + if (obj->otyp == BRASS_LANTERN) + lantern_message(obj); + else { + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%s seems about to go out.", Yname2(obj)); + break; + case OBJ_FLOOR: + You_see("%s about to go out.", an(xname(obj))); + break; + } + } + } + break; - case 0: - /* even if blind you'll know if holding it */ - if (canseeit || obj->where == OBJ_INVENT) { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - if (obj->otyp == BRASS_LANTERN) - pline("%slantern has run out of power.", - whose); - else - pline("%s has gone out.", Yname2(obj)); - break; - case OBJ_FLOOR: - if (obj->otyp == BRASS_LANTERN) - You_see("a lantern run out of power."); - else - You_see("%s go out.", an(xname(obj))); - break; - } - } - end_burn(obj, FALSE); - break; + case 0: + /* even if blind you'll know if holding it */ + if (canseeit || obj->where == OBJ_INVENT) { + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + if (obj->otyp == BRASS_LANTERN) + pline("%slantern has run out of power.", whose); + else + pline("%s has gone out.", Yname2(obj)); + break; + case OBJ_FLOOR: + if (obj->otyp == BRASS_LANTERN) + You_see("a lantern run out of power."); + else + You_see("%s go out.", an(xname(obj))); + break; + } + } + end_burn(obj, FALSE); + break; - default: - /* - * Someone added fuel to the lamp while it was - * lit. Just fall through and let begin burn - * handle the new age. - */ - break; - } + default: + /* + * Someone added fuel to the lamp while it was + * lit. Just fall through and let begin burn + * handle the new age. + */ + break; + } - if (obj->age) - begin_burn(obj, TRUE); + if (obj->age) + begin_burn(obj, TRUE); - break; + break; - case CANDELABRUM_OF_INVOCATION: - case TALLOW_CANDLE: - case WAX_CANDLE: - switch (obj->age) { - case 75: - if (canseeit) - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%s%scandle%s getting short.", - whose, - menorah ? "candelabrum's " : "", - many ? "s are" : " is"); - break; - case OBJ_FLOOR: - You_see("%scandle%s getting short.", - menorah ? "a candelabrum's " : - many ? "some " : "a ", - many ? "s" : ""); - break; - } - break; + case CANDELABRUM_OF_INVOCATION: + case TALLOW_CANDLE: + case WAX_CANDLE: + switch (obj->age) { + case 75: + if (canseeit) + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%s%scandle%s getting short.", whose, + menorah ? "candelabrum's " : "", + many ? "s are" : " is"); + break; + case OBJ_FLOOR: + You_see("%scandle%s getting short.", + menorah ? "a candelabrum's " : many ? "some " + : "a ", + many ? "s" : ""); + break; + } + break; - case 15: - if (canseeit) - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline( - "%s%scandle%s flame%s flicker%s low!", - whose, - menorah ? "candelabrum's " : "", - many ? "s'" : "'s", - many ? "s" : "", - many ? "" : "s"); - break; - case OBJ_FLOOR: - You_see("%scandle%s flame%s flicker low!", - menorah ? "a candelabrum's " : - many ? "some " : "a ", - many ? "s'" : "'s", - many ? "s" : ""); - break; - } - break; + case 15: + if (canseeit) + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%s%scandle%s flame%s flicker%s low!", whose, + menorah ? "candelabrum's " : "", many ? "s'" : "'s", + many ? "s" : "", many ? "" : "s"); + break; + case OBJ_FLOOR: + You_see("%scandle%s flame%s flicker low!", + menorah ? "a candelabrum's " : many ? "some " + : "a ", + many ? "s'" : "'s", many ? "s" : ""); + break; + } + break; - case 0: - /* we know even if blind and in our inventory */ - if (canseeit || obj->where == OBJ_INVENT) { - if (menorah) { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%scandelabrum's flame%s.", - whose, many ? "s die" : " dies"); - break; - case OBJ_FLOOR: - You_see("a candelabrum's flame%s die.", - many ? "s" : ""); - break; - } - } else { - switch (obj->where) { - case OBJ_INVENT: - case OBJ_MINVENT: - pline("%s %s consumed!", - Yname2(obj), - many ? "are" : "is"); - break; - case OBJ_FLOOR: - /* - You see some wax candles consumed! - You see a wax candle consumed! - */ - You_see("%s%s consumed!", - many ? "some " : "", - many ? xname(obj) : an(xname(obj))); - need_newsym = TRUE; - break; - } + case 0: + /* we know even if blind and in our inventory */ + if (canseeit || obj->where == OBJ_INVENT) { + if (menorah) { + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%scandelabrum's flame%s.", whose, + many ? "s die" : " dies"); + break; + case OBJ_FLOOR: + You_see("a candelabrum's flame%s die.", + many ? "s" : ""); + break; + } + } else { + switch (obj->where) { + case OBJ_INVENT: + case OBJ_MINVENT: + pline("%s %s consumed!", Yname2(obj), + many ? "are" : "is"); + break; + case OBJ_FLOOR: + /* + You see some wax candles consumed! + You see a wax candle consumed! + */ + You_see("%s%s consumed!", many ? "some " : "", + many ? xname(obj) : an(xname(obj))); + need_newsym = TRUE; + break; + } - /* post message */ - pline(Hallucination ? - (many ? "They shriek!" : - "It shrieks!") : - Blind ? "" : - (many ? "Their flames die." : - "Its flame dies.")); - } - } - end_burn(obj, FALSE); + /* post message */ + pline(Hallucination + ? (many ? "They shriek!" : "It shrieks!") + : Blind ? "" : (many ? "Their flames die." + : "Its flame dies.")); + } + } + end_burn(obj, FALSE); - if (menorah) { - obj->spe = 0; - } else { - if (carried(obj)) { - useupall(obj); - } else { - /* clear migrating obj's destination code - so obfree won't think this item is worn */ - if (obj->where == OBJ_MIGRATING) - obj->owornmask = 0L; - obj_extract_self(obj); - obfree(obj, (struct obj *)0); - } - obj = (struct obj *) 0; - } - break; + if (menorah) { + obj->spe = 0; + } else { + if (carried(obj)) { + useupall(obj); + } else { + /* clear migrating obj's destination code + so obfree won't think this item is worn */ + if (obj->where == OBJ_MIGRATING) + obj->owornmask = 0L; + obj_extract_self(obj); + obfree(obj, (struct obj *) 0); + } + obj = (struct obj *) 0; + } + break; - default: - /* - * Someone added fuel (candles) to the menorah while - * it was lit. Just fall through and let begin burn - * handle the new age. - */ - break; - } + default: + /* + * Someone added fuel (candles) to the menorah while + * it was lit. Just fall through and let begin burn + * handle the new age. + */ + break; + } - if (obj && obj->age) - begin_burn(obj, TRUE); + if (obj && obj->age) + begin_burn(obj, TRUE); - break; + break; - default: - impossible("burn_object: unexpeced obj %s", xname(obj)); - break; - } - if (need_newsym) newsym(x, y); + default: + impossible("burn_object: unexpeced obj %s", xname(obj)); + break; + } + if (need_newsym) + newsym(x, y); } /* @@ -1106,91 +1125,90 @@ long timeout; */ void begin_burn(obj, already_lit) - struct obj *obj; - boolean already_lit; +struct obj *obj; +boolean already_lit; { - int radius = 3; - long turns = 0; - boolean do_timer = TRUE; + int radius = 3; + long turns = 0; + boolean do_timer = TRUE; - if (obj->age == 0 && obj->otyp != MAGIC_LAMP && !artifact_light(obj)) - return; + if (obj->age == 0 && obj->otyp != MAGIC_LAMP && !artifact_light(obj)) + return; - switch (obj->otyp) { - case MAGIC_LAMP: - obj->lamplit = 1; - do_timer = FALSE; - break; + switch (obj->otyp) { + case MAGIC_LAMP: + obj->lamplit = 1; + do_timer = FALSE; + break; - case POT_OIL: - turns = obj->age; - radius = 1; /* very dim light */ - break; + case POT_OIL: + turns = obj->age; + radius = 1; /* very dim light */ + break; - case BRASS_LANTERN: - case OIL_LAMP: - /* magic times are 150, 100, 50, 25, and 0 */ - if (obj->age > 150L) - turns = obj->age - 150L; - else if (obj->age > 100L) - turns = obj->age - 100L; - else if (obj->age > 50L) - turns = obj->age - 50L; - else if (obj->age > 25L) - turns = obj->age - 25L; - else - turns = obj->age; - break; + case BRASS_LANTERN: + case OIL_LAMP: + /* magic times are 150, 100, 50, 25, and 0 */ + if (obj->age > 150L) + turns = obj->age - 150L; + else if (obj->age > 100L) + turns = obj->age - 100L; + else if (obj->age > 50L) + turns = obj->age - 50L; + else if (obj->age > 25L) + turns = obj->age - 25L; + else + turns = obj->age; + break; - case CANDELABRUM_OF_INVOCATION: - case TALLOW_CANDLE: - case WAX_CANDLE: - /* magic times are 75, 15, and 0 */ - if (obj->age > 75L) - turns = obj->age - 75L; - else if (obj->age > 15L) - turns = obj->age - 15L; - else - turns = obj->age; - radius = candle_light_range(obj); - break; + case CANDELABRUM_OF_INVOCATION: + case TALLOW_CANDLE: + case WAX_CANDLE: + /* magic times are 75, 15, and 0 */ + if (obj->age > 75L) + turns = obj->age - 75L; + else if (obj->age > 15L) + turns = obj->age - 15L; + else + turns = obj->age; + radius = candle_light_range(obj); + break; - default: - /* [ALI] Support artifact light sources */ - if (artifact_light(obj)) { - obj->lamplit = 1; - do_timer = FALSE; - radius = arti_light_radius(obj); - } else { - impossible("begin burn: unexpected %s", xname(obj)); - turns = obj->age; - } - break; - } + default: + /* [ALI] Support artifact light sources */ + if (artifact_light(obj)) { + obj->lamplit = 1; + do_timer = FALSE; + radius = arti_light_radius(obj); + } else { + impossible("begin burn: unexpected %s", xname(obj)); + turns = obj->age; + } + break; + } - if (do_timer) { - if (start_timer(turns, TIMER_OBJECT, - BURN_OBJECT, obj_to_any(obj))) { - obj->lamplit = 1; - obj->age -= turns; - if (carried(obj) && !already_lit) - update_inventory(); - } else { - obj->lamplit = 0; - } - } else { - if (carried(obj) && !already_lit) - update_inventory(); - } + if (do_timer) { + if (start_timer(turns, TIMER_OBJECT, BURN_OBJECT, obj_to_any(obj))) { + obj->lamplit = 1; + obj->age -= turns; + if (carried(obj) && !already_lit) + update_inventory(); + } else { + obj->lamplit = 0; + } + } else { + if (carried(obj) && !already_lit) + update_inventory(); + } - if (obj->lamplit && !already_lit) { - xchar x, y; + if (obj->lamplit && !already_lit) { + xchar x, y; - if (get_obj_location(obj, &x, &y, CONTAINED_TOO|BURIED_TOO)) - new_light_source(x, y, radius, LS_OBJECT, obj_to_any(obj)); - else - impossible("begin_burn: can't get obj position"); - } + if (get_obj_location(obj, &x, &y, CONTAINED_TOO | BURIED_TOO)) + new_light_source(x, y, radius, LS_OBJECT, obj_to_any(obj)); + else + impossible("begin_burn: can't get obj position"); + } } /* @@ -1199,25 +1217,25 @@ begin_burn(obj, already_lit) */ void end_burn(obj, timer_attached) - struct obj *obj; - boolean timer_attached; +struct obj *obj; +boolean timer_attached; { - if (!obj->lamplit) { - impossible("end_burn: obj %s not lit", xname(obj)); - return; - } + if (!obj->lamplit) { + impossible("end_burn: obj %s not lit", xname(obj)); + return; + } - if (obj->otyp == MAGIC_LAMP || artifact_light(obj)) - timer_attached = FALSE; + if (obj->otyp == MAGIC_LAMP || artifact_light(obj)) + timer_attached = FALSE; - if (!timer_attached) { - /* [DS] Cleanup explicitly, since timer cleanup won't happen */ - del_light_source(LS_OBJECT, obj_to_any(obj)); - obj->lamplit = 0; - if (obj->where == OBJ_INVENT) - update_inventory(); - } else if (!stop_timer(BURN_OBJECT, obj_to_any(obj))) - impossible("end_burn: obj %s not timed!", xname(obj)); + if (!timer_attached) { + /* [DS] Cleanup explicitly, since timer cleanup won't happen */ + del_light_source(LS_OBJECT, obj_to_any(obj)); + obj->lamplit = 0; + if (obj->where == OBJ_INVENT) + update_inventory(); + } else if (!stop_timer(BURN_OBJECT, obj_to_any(obj))) + impossible("end_burn: obj %s not timed!", xname(obj)); } /* @@ -1225,13 +1243,13 @@ end_burn(obj, timer_attached) */ static void cleanup_burn(arg, expire_time) - anything *arg; - long expire_time; +anything *arg; +long expire_time; { struct obj *obj = arg->a_obj; if (!obj->lamplit) { - impossible("cleanup_burn: obj %s not lit", xname(obj)); - return; + impossible("cleanup_burn: obj %s not lit", xname(obj)); + return; } del_light_source(LS_OBJECT, obj_to_any(obj)); @@ -1242,7 +1260,7 @@ cleanup_burn(arg, expire_time) obj->lamplit = 0; if (obj->where == OBJ_INVENT) - update_inventory(); + update_inventory(); } void @@ -1254,42 +1272,43 @@ do_storms() int count; /* no lightning if not the air level or too often, even then */ - if(!Is_airlevel(&u.uz) || rn2(8)) - return; + if (!Is_airlevel(&u.uz) || rn2(8)) + return; /* the number of strikes is 8-log2(nstrike) */ - for(nstrike = rnd(64); nstrike <= 64; nstrike *= 2) { - count = 0; - do { - x = rnd(COLNO-1); - y = rn2(ROWNO); - } while (++count < 100 && levl[x][y].typ != CLOUD); + for (nstrike = rnd(64); nstrike <= 64; nstrike *= 2) { + count = 0; + do { + x = rnd(COLNO - 1); + y = rn2(ROWNO); + } while (++count < 100 && levl[x][y].typ != CLOUD); - if(count < 100) { - dirx = rn2(3) - 1; - diry = rn2(3) - 1; - if(dirx != 0 || diry != 0) - buzz(-15, /* "monster" LIGHTNING spell */ - 8, x, y, dirx, diry); - } + if (count < 100) { + dirx = rn2(3) - 1; + diry = rn2(3) - 1; + if (dirx != 0 || diry != 0) + buzz(-15, /* "monster" LIGHTNING spell */ + 8, x, y, dirx, diry); + } } - if(levl[u.ux][u.uy].typ == CLOUD) { - /* Inside a cloud during a thunder storm is deafening. */ - /* Even if already deaf, we sense the thunder's vibrations. */ - pline("Kaboom!!! Boom!! Boom!!"); - incr_itimeout(&HDeaf, rn1(20,30)); - if(!u.uinvulnerable) { - stop_occupation(); - nomul(-3); - multi_reason = "hiding from thunderstorm"; - nomovemsg = 0; - } + if (levl[u.ux][u.uy].typ == CLOUD) { + /* Inside a cloud during a thunder storm is deafening. */ + /* Even if already deaf, we sense the thunder's vibrations. */ + pline("Kaboom!!! Boom!! Boom!!"); + incr_itimeout(&HDeaf, rn1(20, 30)); + if (!u.uinvulnerable) { + stop_occupation(); + nomul(-3); + multi_reason = "hiding from thunderstorm"; + nomovemsg = 0; + } } else - You_hear("a rumbling noise."); + You_hear("a rumbling noise."); } -/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- + */ /* * Generic Timeout Functions. * @@ -1351,15 +1370,15 @@ do_storms() STATIC_DCL const char *FDECL(kind_name, (SHORT_P)); STATIC_DCL void FDECL(print_queue, (winid, timer_element *)); STATIC_DCL void FDECL(insert_timer, (timer_element *)); -STATIC_DCL timer_element *FDECL(remove_timer, (timer_element **, SHORT_P, - ANY_P *)); +STATIC_DCL timer_element *FDECL(remove_timer, + (timer_element **, SHORT_P, ANY_P *)); STATIC_DCL void FDECL(write_timer, (int, timer_element *)); STATIC_DCL boolean FDECL(mon_is_local, (struct monst *)); STATIC_DCL boolean FDECL(timer_is_local, (timer_element *)); STATIC_DCL int FDECL(maybe_write_timer, (int, int, BOOLEAN_P)); /* ordered timer list */ -static timer_element *timer_base; /* "active" */ +static timer_element *timer_base; /* "active" */ static unsigned long timer_id = 1; /* If defined, then include names when printing out the timer queue */ @@ -1369,63 +1388,72 @@ typedef struct { timeout_proc f, cleanup; #ifdef VERBOSE_TIMER const char *name; -# define TTAB(a, b, c) {a,b,c} +#define TTAB(a, b, c) \ + { \ + a, b, c \ + } #else -# define TTAB(a, b, c) {a,b} +#define TTAB(a, b, c) \ + { \ + a, b \ + } #endif } ttable; /* table of timeout functions */ static const ttable timeout_funcs[NUM_TIME_FUNCS] = { - TTAB(rot_organic, (timeout_proc)0, "rot_organic"), - TTAB(rot_corpse, (timeout_proc)0, "rot_corpse"), - TTAB(revive_mon, (timeout_proc)0, "revive_mon"), - TTAB(burn_object, cleanup_burn, "burn_object"), - TTAB(hatch_egg, (timeout_proc)0, "hatch_egg"), - TTAB(fig_transform, (timeout_proc)0, "fig_transform"), - TTAB(melt_ice_away, (timeout_proc)0, "melt_ice_away") + TTAB(rot_organic, (timeout_proc) 0, "rot_organic"), + TTAB(rot_corpse, (timeout_proc) 0, "rot_corpse"), + TTAB(revive_mon, (timeout_proc) 0, "revive_mon"), + TTAB(burn_object, cleanup_burn, "burn_object"), + TTAB(hatch_egg, (timeout_proc) 0, "hatch_egg"), + TTAB(fig_transform, (timeout_proc) 0, "fig_transform"), + TTAB(melt_ice_away, (timeout_proc) 0, "melt_ice_away") }; #undef TTAB STATIC_OVL const char * kind_name(kind) - short kind; +short kind; { switch (kind) { - case TIMER_LEVEL: return "level"; - case TIMER_GLOBAL: return "global"; - case TIMER_OBJECT: return "object"; - case TIMER_MONSTER: return "monster"; + case TIMER_LEVEL: + return "level"; + case TIMER_GLOBAL: + return "global"; + case TIMER_OBJECT: + return "object"; + case TIMER_MONSTER: + return "monster"; } return "unknown"; } STATIC_OVL void print_queue(win, base) - winid win; - timer_element *base; +winid win; +timer_element *base; { timer_element *curr; char buf[BUFSZ]; if (!base) { - putstr(win, 0, ""); + putstr(win, 0, ""); } else { - putstr(win, 0, "timeout id kind call"); - for (curr = base; curr; curr = curr->next) { + putstr(win, 0, "timeout id kind call"); + for (curr = base; curr; curr = curr->next) { #ifdef VERBOSE_TIMER - Sprintf(buf, " %4ld %4ld %-6s %s(%s)", - curr->timeout, curr->tid, kind_name(curr->kind), - timeout_funcs[curr->func_index].name, - fmt_ptr((genericptr_t)curr->arg.a_void)); + Sprintf(buf, " %4ld %4ld %-6s %s(%s)", curr->timeout, + curr->tid, kind_name(curr->kind), + timeout_funcs[curr->func_index].name, + fmt_ptr((genericptr_t) curr->arg.a_void)); #else - Sprintf(buf, " %4ld %4ld %-6s #%d(%s)", - curr->timeout, curr->tid, kind_name(curr->kind), - curr->func_index, - fmt_ptr((genericptr_t)curr->arg.a_void)); + Sprintf(buf, " %4ld %4ld %-6s #%d(%s)", curr->timeout, + curr->tid, kind_name(curr->kind), curr->func_index, + fmt_ptr((genericptr_t) curr->arg.a_void)); #endif - putstr(win, 0, buf); - } + putstr(win, 0, buf); + } } } @@ -1435,8 +1463,9 @@ wiz_timeout_queue() winid win; char buf[BUFSZ]; - win = create_nhwindow(NHW_MENU); /* corner text window */ - if (win == WIN_ERR) return 0; + win = create_nhwindow(NHW_MENU); /* corner text window */ + if (win == WIN_ERR) + return 0; Sprintf(buf, "Current time = %ld.", monstermoves); putstr(win, 0, buf); @@ -1458,13 +1487,13 @@ timer_sanity_check() /* this should be much more complete */ for (curr = timer_base; curr; curr = curr->next) - if (curr->kind == TIMER_OBJECT) { - struct obj *obj = curr->arg.a_obj; - if (obj->timed == 0) { - pline("timer sanity: untimed obj %s, timer %ld", - fmt_ptr((genericptr_t)obj), curr->tid); - } - } + if (curr->kind == TIMER_OBJECT) { + struct obj *obj = curr->arg.a_obj; + if (obj->timed == 0) { + pline("timer sanity: untimed obj %s, timer %ld", + fmt_ptr((genericptr_t) obj), curr->tid); + } + } } /* @@ -1482,16 +1511,16 @@ run_timers() * is in the future. */ while (timer_base && timer_base->timeout <= monstermoves) { - curr = timer_base; - timer_base = curr->next; + curr = timer_base; + timer_base = curr->next; - if (curr->kind == TIMER_OBJECT) (curr->arg.a_obj)->timed--; - (*timeout_funcs[curr->func_index].f)(&curr->arg, curr->timeout); - free((genericptr_t) curr); + if (curr->kind == TIMER_OBJECT) + (curr->arg.a_obj)->timed--; + (*timeout_funcs[curr->func_index].f)(&curr->arg, curr->timeout); + free((genericptr_t) curr); } } - /* * Start a timer. Return TRUE if successful. */ @@ -1505,7 +1534,7 @@ anything *arg; timer_element *gnu; if (func_index < 0 || func_index >= NUM_TIME_FUNCS) - panic("start_timer"); + panic("start_timer"); gnu = (timer_element *) alloc(sizeof(timer_element)); gnu->next = 0; @@ -1517,14 +1546,13 @@ anything *arg; gnu->arg = *arg; insert_timer(gnu); - if (kind == TIMER_OBJECT) /* increment object's timed count */ - (arg->a_obj)->timed++; + if (kind == TIMER_OBJECT) /* increment object's timed count */ + (arg->a_obj)->timed++; /* should check for duplicates and fail if any */ return TRUE; } - /* * Remove the timer from the current list and free it up. Return the time * remaining until it would have gone off, 0 if not found. @@ -1540,13 +1568,13 @@ anything *arg; doomed = remove_timer(&timer_base, func_index, arg); if (doomed) { - timeout = doomed->timeout; - if (doomed->kind == TIMER_OBJECT) - (arg->a_obj)->timed--; - if (timeout_funcs[doomed->func_index].cleanup) - (*timeout_funcs[doomed->func_index].cleanup)(arg, timeout); - free((genericptr_t) doomed); - return (timeout - monstermoves); + timeout = doomed->timeout; + if (doomed->kind == TIMER_OBJECT) + (arg->a_obj)->timed--; + if (timeout_funcs[doomed->func_index].cleanup) + (*timeout_funcs[doomed->func_index].cleanup)(arg, timeout); + free((genericptr_t) doomed); + return (timeout - monstermoves); } return 0L; } @@ -1556,84 +1584,81 @@ anything *arg; */ long peek_timer(type, arg) - short type; - anything *arg; +short type; +anything *arg; { timer_element *curr; for (curr = timer_base; curr; curr = curr->next) { - if (curr->func_index == type && curr->arg.a_void == arg->a_void) - return curr->timeout; + if (curr->func_index == type && curr->arg.a_void == arg->a_void) + return curr->timeout; } return 0L; } - /* * Move all object timers from src to dest, leaving src untimed. */ void obj_move_timers(src, dest) - struct obj *src, *dest; +struct obj *src, *dest; { int count; timer_element *curr; for (count = 0, curr = timer_base; curr; curr = curr->next) - if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { - curr->arg.a_obj = dest; - dest->timed++; - count++; - } + if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { + curr->arg.a_obj = dest; + dest->timed++; + count++; + } if (count != src->timed) - panic("obj_move_timers"); + panic("obj_move_timers"); src->timed = 0; } - /* * Find all object timers and duplicate them for the new object "dest". */ void obj_split_timers(src, dest) - struct obj *src, *dest; +struct obj *src, *dest; { - timer_element *curr, *next_timer=0; + timer_element *curr, *next_timer = 0; for (curr = timer_base; curr; curr = next_timer) { - next_timer = curr->next; /* things may be inserted */ - if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { - (void) start_timer(curr->timeout-monstermoves, TIMER_OBJECT, - curr->func_index, obj_to_any(dest)); - } + next_timer = curr->next; /* things may be inserted */ + if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == src) { + (void) start_timer(curr->timeout - monstermoves, TIMER_OBJECT, + curr->func_index, obj_to_any(dest)); + } } } - /* * Stop all timers attached to this object. We can get away with this because * all object pointers are unique. */ void obj_stop_timers(obj) - struct obj *obj; +struct obj *obj; { - timer_element *curr, *prev, *next_timer=0; + timer_element *curr, *prev, *next_timer = 0; for (prev = 0, curr = timer_base; curr; curr = next_timer) { - next_timer = curr->next; - if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == obj) { - if (prev) - prev->next = curr->next; - else - timer_base = curr->next; - if (timeout_funcs[curr->func_index].cleanup) - (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, - curr->timeout); - free((genericptr_t) curr); - } else { - prev = curr; - } + next_timer = curr->next; + if (curr->kind == TIMER_OBJECT && curr->arg.a_obj == obj) { + if (prev) + prev->next = curr->next; + else + timer_base = curr->next; + if (timeout_funcs[curr->func_index].cleanup) + (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, + curr->timeout); + free((genericptr_t) curr); + } else { + prev = curr; + } } obj->timed = 0; } @@ -1643,42 +1668,41 @@ obj_stop_timers(obj) */ boolean obj_has_timer(object, timer_type) - struct obj *object; - short timer_type; +struct obj *object; +short timer_type; { long timeout = peek_timer(timer_type, obj_to_any(object)); return (boolean)(timeout != 0L); } - /* * Stop all timers of index func_index at this spot. - * + * */ void -spot_stop_timers(x,y,func_index) -xchar x,y; +spot_stop_timers(x, y, func_index) +xchar x, y; short func_index; { - timer_element *curr, *prev, *next_timer=0; - long where = (((long)x << 16) | ((long)y)); + timer_element *curr, *prev, *next_timer = 0; + long where = (((long) x << 16) | ((long) y)); for (prev = 0, curr = timer_base; curr; curr = next_timer) { - next_timer = curr->next; - if (curr->kind == TIMER_LEVEL && - curr->func_index == func_index && curr->arg.a_long == where) { - if (prev) - prev->next = curr->next; - else - timer_base = curr->next; - if (timeout_funcs[curr->func_index].cleanup) - (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, - curr->timeout); - free((genericptr_t) curr); - } else { - prev = curr; - } + next_timer = curr->next; + if (curr->kind == TIMER_LEVEL && curr->func_index == func_index + && curr->arg.a_long == where) { + if (prev) + prev->next = curr->next; + else + timer_base = curr->next; + if (timeout_funcs[curr->func_index].cleanup) + (*timeout_funcs[curr->func_index].cleanup)(&curr->arg, + curr->timeout); + free((genericptr_t) curr); + } else { + prev = curr; + } } } @@ -1687,48 +1711,48 @@ short func_index; * Returns 0L if no such timer. */ long -spot_time_expires(x,y,func_index) -xchar x,y; +spot_time_expires(x, y, func_index) +xchar x, y; short func_index; { timer_element *curr; - long where = (((long)x << 16) | ((long)y)); + long where = (((long) x << 16) | ((long) y)); for (curr = timer_base; curr; curr = curr->next) { - if (curr->kind == TIMER_LEVEL && - curr->func_index == func_index && curr->arg.a_long == where) - return curr->timeout; + if (curr->kind == TIMER_LEVEL && curr->func_index == func_index + && curr->arg.a_long == where) + return curr->timeout; } return 0L; } long -spot_time_left(x,y,func_index) -xchar x,y; +spot_time_left(x, y, func_index) +xchar x, y; short func_index; { - long expires = spot_time_expires(x,y,func_index); + long expires = spot_time_expires(x, y, func_index); return (expires > 0L) ? expires - monstermoves : 0L; } /* Insert timer into the global queue */ STATIC_OVL void insert_timer(gnu) - timer_element *gnu; +timer_element *gnu; { timer_element *curr, *prev; for (prev = 0, curr = timer_base; curr; prev = curr, curr = curr->next) - if (curr->timeout >= gnu->timeout) break; + if (curr->timeout >= gnu->timeout) + break; gnu->next = curr; if (prev) - prev->next = gnu; + prev->next = gnu; else - timer_base = gnu; + timer_base = gnu; } - STATIC_OVL timer_element * remove_timer(base, func_index, arg) timer_element **base; @@ -1738,92 +1762,94 @@ anything *arg; timer_element *prev, *curr; for (prev = 0, curr = *base; curr; prev = curr, curr = curr->next) - if (curr->func_index == func_index && curr->arg.a_void == arg->a_void) break; + if (curr->func_index == func_index && curr->arg.a_void == arg->a_void) + break; if (curr) { - if (prev) - prev->next = curr->next; - else - *base = curr->next; + if (prev) + prev->next = curr->next; + else + *base = curr->next; } return curr; } - STATIC_OVL void write_timer(fd, timer) - int fd; - timer_element *timer; +int fd; +timer_element *timer; { anything arg_save; arg_save = zeroany; switch (timer->kind) { - case TIMER_GLOBAL: - case TIMER_LEVEL: - /* assume no pointers in arg */ - bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); - break; + case TIMER_GLOBAL: + case TIMER_LEVEL: + /* assume no pointers in arg */ + bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); + break; - case TIMER_OBJECT: - if (timer->needs_fixup) - bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); - else { - /* replace object pointer with id */ - arg_save.a_obj = timer->arg.a_obj; - timer->arg = zeroany; - timer->arg.a_uint = (arg_save.a_obj)->o_id; - timer->needs_fixup = 1; - bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); - timer->arg.a_obj = arg_save.a_obj; - timer->needs_fixup = 0; - } - break; + case TIMER_OBJECT: + if (timer->needs_fixup) + bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); + else { + /* replace object pointer with id */ + arg_save.a_obj = timer->arg.a_obj; + timer->arg = zeroany; + timer->arg.a_uint = (arg_save.a_obj)->o_id; + timer->needs_fixup = 1; + bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); + timer->arg.a_obj = arg_save.a_obj; + timer->needs_fixup = 0; + } + break; - case TIMER_MONSTER: - if (timer->needs_fixup) - bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); - else { - /* replace monster pointer with id */ - arg_save.a_monst = timer->arg.a_monst; - timer->arg = zeroany; - timer->arg.a_uint = (arg_save.a_monst)->m_id; - timer->needs_fixup = 1; - bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); - timer->arg.a_monst = arg_save.a_monst; - timer->needs_fixup = 0; - } - break; + case TIMER_MONSTER: + if (timer->needs_fixup) + bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); + else { + /* replace monster pointer with id */ + arg_save.a_monst = timer->arg.a_monst; + timer->arg = zeroany; + timer->arg.a_uint = (arg_save.a_monst)->m_id; + timer->needs_fixup = 1; + bwrite(fd, (genericptr_t) timer, sizeof(timer_element)); + timer->arg.a_monst = arg_save.a_monst; + timer->needs_fixup = 0; + } + break; - default: - panic("write_timer"); - break; + default: + panic("write_timer"); + break; } } - /* * Return TRUE if the object will stay on the level when the level is * saved. */ boolean obj_is_local(obj) - struct obj *obj; +struct obj *obj; { switch (obj->where) { - case OBJ_INVENT: - case OBJ_MIGRATING: return FALSE; - case OBJ_FLOOR: - case OBJ_BURIED: return TRUE; - case OBJ_CONTAINED: return obj_is_local(obj->ocontainer); - case OBJ_MINVENT: return mon_is_local(obj->ocarry); + case OBJ_INVENT: + case OBJ_MIGRATING: + return FALSE; + case OBJ_FLOOR: + case OBJ_BURIED: + return TRUE; + case OBJ_CONTAINED: + return obj_is_local(obj->ocontainer); + case OBJ_MINVENT: + return mon_is_local(obj->ocarry); } panic("obj_is_local"); return FALSE; } - /* * Return TRUE if the given monster will stay on the level when the * level is saved. @@ -1835,69 +1861,73 @@ struct monst *mon; struct monst *curr; for (curr = migrating_mons; curr; curr = curr->nmon) - if (curr == mon) return FALSE; + if (curr == mon) + return FALSE; /* `mydogs' is used during level changes, never saved and restored */ for (curr = mydogs; curr; curr = curr->nmon) - if (curr == mon) return FALSE; + if (curr == mon) + return FALSE; return TRUE; } - /* * Return TRUE if the timer is attached to something that will stay on the * level when the level is saved. */ STATIC_OVL boolean timer_is_local(timer) - timer_element *timer; +timer_element *timer; { switch (timer->kind) { - case TIMER_LEVEL: return TRUE; - case TIMER_GLOBAL: return FALSE; - case TIMER_OBJECT: return obj_is_local(timer->arg.a_obj); - case TIMER_MONSTER: return mon_is_local(timer->arg.a_monst); + case TIMER_LEVEL: + return TRUE; + case TIMER_GLOBAL: + return FALSE; + case TIMER_OBJECT: + return obj_is_local(timer->arg.a_obj); + case TIMER_MONSTER: + return mon_is_local(timer->arg.a_monst); } panic("timer_is_local"); return FALSE; } - /* * Part of the save routine. Count up the number of timers that would * be written. If write_it is true, actually write the timer. */ STATIC_OVL int maybe_write_timer(fd, range, write_it) - int fd, range; - boolean write_it; +int fd, range; +boolean write_it; { int count = 0; timer_element *curr; for (curr = timer_base; curr; curr = curr->next) { - if (range == RANGE_GLOBAL) { - /* global timers */ + if (range == RANGE_GLOBAL) { + /* global timers */ - if (!timer_is_local(curr)) { - count++; - if (write_it) write_timer(fd, curr); - } + if (!timer_is_local(curr)) { + count++; + if (write_it) + write_timer(fd, curr); + } - } else { - /* local timers */ + } else { + /* local timers */ - if (timer_is_local(curr)) { - count++; - if (write_it) write_timer(fd, curr); - } - - } + if (timer_is_local(curr)) { + count++; + if (write_it) + write_timer(fd, curr); + } + } } return count; } - /* * Save part of the timer list. The parameter 'range' specifies either * global or level timers to save. The timer ID is saved with the global @@ -1913,91 +1943,90 @@ maybe_write_timer(fd, range, write_it) */ void save_timers(fd, mode, range) - int fd, mode, range; +int fd, mode, range; { - timer_element *curr, *prev, *next_timer=0; + timer_element *curr, *prev, *next_timer = 0; int count; if (perform_bwrite(mode)) { - if (range == RANGE_GLOBAL) - bwrite(fd, (genericptr_t) &timer_id, sizeof(timer_id)); + if (range == RANGE_GLOBAL) + bwrite(fd, (genericptr_t) &timer_id, sizeof(timer_id)); - count = maybe_write_timer(fd, range, FALSE); - bwrite(fd, (genericptr_t) &count, sizeof count); - (void) maybe_write_timer(fd, range, TRUE); + count = maybe_write_timer(fd, range, FALSE); + bwrite(fd, (genericptr_t) &count, sizeof count); + (void) maybe_write_timer(fd, range, TRUE); } if (release_data(mode)) { - for (prev = 0, curr = timer_base; curr; curr = next_timer) { - next_timer = curr->next; /* in case curr is removed */ + for (prev = 0, curr = timer_base; curr; curr = next_timer) { + next_timer = curr->next; /* in case curr is removed */ - if ( !(!!(range == RANGE_LEVEL) ^ !!timer_is_local(curr)) ) { - if (prev) - prev->next = curr->next; - else - timer_base = curr->next; - free((genericptr_t) curr); - /* prev stays the same */ - } else { - prev = curr; - } - } + if (!(!!(range == RANGE_LEVEL) ^ !!timer_is_local(curr))) { + if (prev) + prev->next = curr->next; + else + timer_base = curr->next; + free((genericptr_t) curr); + /* prev stays the same */ + } else { + prev = curr; + } + } } } - /* * Pull in the structures from disk, but don't recalculate the object and * monster pointers. */ void restore_timers(fd, range, ghostly, adjust) - int fd, range; - boolean ghostly; /* restoring from a ghost level */ - long adjust; /* how much to adjust timeout */ +int fd, range; +boolean ghostly; /* restoring from a ghost level */ +long adjust; /* how much to adjust timeout */ { int count; timer_element *curr; if (range == RANGE_GLOBAL) - mread(fd, (genericptr_t) &timer_id, sizeof timer_id); + mread(fd, (genericptr_t) &timer_id, sizeof timer_id); /* restore elements */ mread(fd, (genericptr_t) &count, sizeof count); while (count-- > 0) { - curr = (timer_element *) alloc(sizeof(timer_element)); - mread(fd, (genericptr_t) curr, sizeof(timer_element)); - if (ghostly) - curr->timeout += adjust; - insert_timer(curr); + curr = (timer_element *) alloc(sizeof(timer_element)); + mread(fd, (genericptr_t) curr, sizeof(timer_element)); + if (ghostly) + curr->timeout += adjust; + insert_timer(curr); } } - /* reset all timers that are marked for reseting */ void relink_timers(ghostly) - boolean ghostly; +boolean ghostly; { timer_element *curr; unsigned nid; for (curr = timer_base; curr; curr = curr->next) { - if (curr->needs_fixup) { - if (curr->kind == TIMER_OBJECT) { - if (ghostly) { - if (!lookup_id_mapping(curr->arg.a_uint, &nid)) - panic("relink_timers 1"); - } else - nid = curr->arg.a_uint; - curr->arg.a_obj = find_oid(nid); - if (!curr->arg.a_obj) panic("cant find o_id %d", nid); - curr->needs_fixup = 0; - } else if (curr->kind == TIMER_MONSTER) { - panic("relink_timers: no monster timer implemented"); - } else - panic("relink_timers 2"); - } + if (curr->needs_fixup) { + if (curr->kind == TIMER_OBJECT) { + if (ghostly) { + if (!lookup_id_mapping(curr->arg.a_uint, &nid)) + panic("relink_timers 1"); + } else + nid = curr->arg.a_uint; + curr->arg.a_obj = find_oid(nid); + if (!curr->arg.a_obj) + panic("cant find o_id %d", nid); + curr->needs_fixup = 0; + } else if (curr->kind == TIMER_MONSTER) { + panic("relink_timers: no monster timer implemented"); + } else + panic("relink_timers 2"); + } } } diff --git a/src/topten.c b/src/topten.c index 4a8ec94b9..06eabb7e2 100644 --- a/src/topten.c +++ b/src/topten.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 topten.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 topten.c $NHDT-Date: 1431192766 2015/05/09 17:32:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ /* NetHack 3.6 topten.c $Date: 2012/01/24 04:26:15 $ $Revision: 1.23 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,9 +12,9 @@ #endif #ifdef VMS - /* We don't want to rewrite the whole file, because that entails */ - /* creating a new version which requires that the old one be deletable. */ -# define UPDATE_RECORD_IN_PLACE +/* We don't want to rewrite the whole file, because that entails */ +/* creating a new version which requires that the old one be deletable. */ +#define UPDATE_RECORD_IN_PLACE #endif /* @@ -30,55 +30,54 @@ static long final_fpos; #define done_stopprint program_state.stopprint #define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry)) -#define dealloc_ttentry(ttent) free((genericptr_t) (ttent)) -#define NAMSZ 10 -#define DTHSZ 100 -#define ROLESZ 3 +#define dealloc_ttentry(ttent) free((genericptr_t)(ttent)) +#define NAMSZ 10 +#define DTHSZ 100 +#define ROLESZ 3 struct toptenentry { - struct toptenentry *tt_next; + struct toptenentry *tt_next; #ifdef UPDATE_RECORD_IN_PLACE - long fpos; + long fpos; #endif - long points; - int deathdnum, deathlev; - int maxlvl, hp, maxhp, deaths; - int ver_major, ver_minor, patchlevel; - long deathdate, birthdate; - int uid; - char plrole[ROLESZ+1]; - char plrace[ROLESZ+1]; - char plgend[ROLESZ+1]; - char plalign[ROLESZ+1]; - char name[NAMSZ+1]; - char death[DTHSZ+1]; -} *tt_head; + long points; + int deathdnum, deathlev; + int maxlvl, hp, maxhp, deaths; + int ver_major, ver_minor, patchlevel; + long deathdate, birthdate; + int uid; + char plrole[ROLESZ + 1]; + char plrace[ROLESZ + 1]; + char plgend[ROLESZ + 1]; + char plalign[ROLESZ + 1]; + char name[NAMSZ + 1]; + char death[DTHSZ + 1]; +} * tt_head; /* size big enough to read in all the string fields at once; includes room for separating space or trailing newline plus string terminator */ -#define SCANBUFSZ (4*(ROLESZ+1)+(NAMSZ+1)+(DTHSZ+1)+1) +#define SCANBUFSZ (4 * (ROLESZ + 1) + (NAMSZ + 1) + (DTHSZ + 1) + 1) STATIC_DCL void FDECL(topten_print, (const char *)); STATIC_DCL void FDECL(topten_print_bold, (const char *)); STATIC_DCL xchar FDECL(observable_depth, (d_level *)); STATIC_DCL void NDECL(outheader); -STATIC_DCL void FDECL(outentry, (int,struct toptenentry *,BOOLEAN_P)); +STATIC_DCL void FDECL(outentry, (int, struct toptenentry *, BOOLEAN_P)); STATIC_DCL void FDECL(discardexcess, (FILE *)); -STATIC_DCL void FDECL(readentry, (FILE *,struct toptenentry *)); -STATIC_DCL void FDECL(writeentry, (FILE *,struct toptenentry *)); -STATIC_DCL void FDECL(writexlentry, (FILE*, struct toptenentry *)); +STATIC_DCL void FDECL(readentry, (FILE *, struct toptenentry *)); +STATIC_DCL void FDECL(writeentry, (FILE *, struct toptenentry *)); +STATIC_DCL void FDECL(writexlentry, (FILE *, struct toptenentry *)); STATIC_DCL long NDECL(encodexlogflags); STATIC_DCL long NDECL(encodeconduct); STATIC_DCL long NDECL(encodeachieve); STATIC_DCL void FDECL(free_ttlist, (struct toptenentry *)); -STATIC_DCL int FDECL(classmon, (char *,BOOLEAN_P)); -STATIC_DCL int FDECL(score_wanted, - (BOOLEAN_P, int,struct toptenentry *,int,const char **,int)); +STATIC_DCL int FDECL(classmon, (char *, BOOLEAN_P)); +STATIC_DCL int FDECL(score_wanted, (BOOLEAN_P, int, struct toptenentry *, int, + const char **, int)); #ifdef NO_SCAN_BRACK -STATIC_DCL void FDECL(nsb_mung_line,(char*)); -STATIC_DCL void FDECL(nsb_unmung_line,(char*)); +STATIC_DCL void FDECL(nsb_mung_line, (char *)); +STATIC_DCL void FDECL(nsb_unmung_line, (char *)); #endif - static winid toptenwin = WIN_ERR; /* "killed by",&c ["an"] 'killer.name' */ @@ -88,15 +87,15 @@ char *buf; unsigned siz; int how; { - static NEARDATA const char * const killed_by_prefix[] = { - /* DIED, CHOKING, POISONING, STARVING, */ - "killed by ", "choked on ", "poisoned by ", "died of ", - /* DROWNING, BURNING, DISSOLVED, CRUSHING, */ - "drowned in ", "burned by ", "dissolved in ", "crushed to death by ", - /* STONING, TURNED_SLIME, GENOCIDED, */ - "petrified by ", "turned to slime by ", "killed by ", - /* PANICKED, TRICKED, QUIT, ESCAPED, ASCENDED */ - "", "", "", "", "" + static NEARDATA const char *const killed_by_prefix[] = { + /* DIED, CHOKING, POISONING, STARVING, */ + "killed by ", "choked on ", "poisoned by ", "died of ", + /* DROWNING, BURNING, DISSOLVED, CRUSHING, */ + "drowned in ", "burned by ", "dissolved in ", "crushed to death by ", + /* STONING, TURNED_SLIME, GENOCIDED, */ + "petrified by ", "turned to slime by ", "killed by ", + /* PANICKED, TRICKED, QUIT, ESCAPED, ASCENDED */ + "", "", "", "", "" }; unsigned l; char *kname = killer.name; @@ -104,18 +103,18 @@ int how; buf[0] = '\0'; /* so strncat() can find the end */ switch (killer.format) { default: - impossible("bad killer format? (%d)", killer.format); - /*FALLTHRU*/ + impossible("bad killer format? (%d)", killer.format); + /*FALLTHRU*/ case NO_KILLER_PREFIX: - break; + break; case KILLED_BY_AN: - kname = an(kname); - /*FALLTHRU*/ + kname = an(kname); + /*FALLTHRU*/ case KILLED_BY: - (void) strncat(buf, killed_by_prefix[how], siz - 1); - l = strlen(buf); - buf += l, siz -= l; - break; + (void) strncat(buf, killed_by_prefix[how], siz - 1); + l = strlen(buf); + buf += l, siz -= l; + break; } /* we're writing into buf[0] (after possibly advancing buf) rather than appending, but strncat() appends a terminator and strncpy() doesn't */ @@ -126,28 +125,28 @@ STATIC_OVL void topten_print(x) const char *x; { - if (toptenwin == WIN_ERR) - raw_print(x); - else - putstr(toptenwin, ATR_NONE, x); + if (toptenwin == WIN_ERR) + raw_print(x); + else + putstr(toptenwin, ATR_NONE, x); } STATIC_OVL void topten_print_bold(x) const char *x; { - if (toptenwin == WIN_ERR) - raw_print_bold(x); - else - putstr(toptenwin, ATR_BOLD, x); + if (toptenwin == WIN_ERR) + raw_print_bold(x); + else + putstr(toptenwin, ATR_BOLD, x); } STATIC_OVL xchar observable_depth(lev) d_level *lev; { -#if 0 /* if we ever randomize the order of the elemental planes, we - must use a constant external representation in the record file */ +#if 0 /* if we ever randomize the order of the elemental planes, we \ + must use a constant external representation in the record file */ if (In_endgame(lev)) { if (Is_astralevel(lev)) return -5; else if (Is_waterlevel(lev)) return -4; @@ -157,7 +156,7 @@ d_level *lev; else return 0; /* ? */ } else #endif - return depth(lev); + return depth(lev); } /* throw away characters until current record has been entirely consumed */ @@ -165,185 +164,167 @@ STATIC_OVL void discardexcess(rfile) FILE *rfile; { - int c; + int c; - do { - c = fgetc(rfile); - } while (c != '\n' && c != EOF); + do { + c = fgetc(rfile); + } while (c != '\n' && c != EOF); } STATIC_OVL void -readentry(rfile,tt) +readentry(rfile, tt) FILE *rfile; struct toptenentry *tt; { - char inbuf[SCANBUFSZ], - s1[SCANBUFSZ], s2[SCANBUFSZ], s3[SCANBUFSZ], - s4[SCANBUFSZ], s5[SCANBUFSZ], s6[SCANBUFSZ]; + char inbuf[SCANBUFSZ], s1[SCANBUFSZ], s2[SCANBUFSZ], s3[SCANBUFSZ], + s4[SCANBUFSZ], s5[SCANBUFSZ], s6[SCANBUFSZ]; #ifdef NO_SCAN_BRACK /* Version_ Pts DgnLevs_ Hp___ Died__Born id */ - static const char fmt[] = "%d %d %d %ld %d %d %d %d %d %d %ld %ld %d%*c"; - static const char fmt32[] = "%c%c %s %s%*c"; - static const char fmt33[] = "%s %s %s %s %s %s%*c"; + static const char fmt[] = "%d %d %d %ld %d %d %d %d %d %d %ld %ld %d%*c"; + static const char fmt32[] = "%c%c %s %s%*c"; + static const char fmt33[] = "%s %s %s %s %s %s%*c"; #else - static const char fmt[] = "%d.%d.%d %ld %d %d %d %d %d %d %ld %ld %d "; - static const char fmt32[] = "%c%c %[^,],%[^\n]%*c"; - static const char fmt33[] = "%s %s %s %s %[^,],%[^\n]%*c"; + static const char fmt[] = "%d.%d.%d %ld %d %d %d %d %d %d %ld %ld %d "; + static const char fmt32[] = "%c%c %[^,],%[^\n]%*c"; + static const char fmt33[] = "%s %s %s %s %[^,],%[^\n]%*c"; #endif #ifdef UPDATE_RECORD_IN_PLACE - /* note: input below must read the record's terminating newline */ - final_fpos = tt->fpos = ftell(rfile); + /* note: input below must read the record's terminating newline */ + final_fpos = tt->fpos = ftell(rfile); #endif #define TTFIELDS 13 - if(fscanf(rfile, fmt, - &tt->ver_major, &tt->ver_minor, &tt->patchlevel, - &tt->points, &tt->deathdnum, &tt->deathlev, - &tt->maxlvl, &tt->hp, &tt->maxhp, &tt->deaths, - &tt->deathdate, &tt->birthdate, - &tt->uid) != TTFIELDS) { + if (fscanf(rfile, fmt, &tt->ver_major, &tt->ver_minor, &tt->patchlevel, + &tt->points, &tt->deathdnum, &tt->deathlev, &tt->maxlvl, + &tt->hp, &tt->maxhp, &tt->deaths, &tt->deathdate, + &tt->birthdate, &tt->uid) != TTFIELDS) { #undef TTFIELDS - tt->points = 0; - discardexcess(rfile); - } else { - /* load remainder of record into a local buffer; - this imposes an implicit length limit of SCANBUFSZ - on every string field extracted from the buffer */ - if (!fgets(inbuf, sizeof inbuf, rfile)) { - /* sscanf will fail and tt->points will be set to 0 */ - *inbuf = '\0'; - } else if (!index(inbuf, '\n')) { - Strcpy(&inbuf[sizeof inbuf - 2], "\n"); - discardexcess(rfile); - } - /* Check for backwards compatibility */ - if (tt->ver_major < 3 || - (tt->ver_major == 3 && tt->ver_minor < 3)) { - int i; + tt->points = 0; + discardexcess(rfile); + } else { + /* load remainder of record into a local buffer; + this imposes an implicit length limit of SCANBUFSZ + on every string field extracted from the buffer */ + if (!fgets(inbuf, sizeof inbuf, rfile)) { + /* sscanf will fail and tt->points will be set to 0 */ + *inbuf = '\0'; + } else if (!index(inbuf, '\n')) { + Strcpy(&inbuf[sizeof inbuf - 2], "\n"); + discardexcess(rfile); + } + /* Check for backwards compatibility */ + if (tt->ver_major < 3 || (tt->ver_major == 3 && tt->ver_minor < 3)) { + int i; - if (sscanf(inbuf, fmt32, - tt->plrole, tt->plgend, s1, s2) == 4) { - tt->plrole[1] = tt->plgend[1] = '\0'; /* read via %c */ - copynchars(tt->name, s1, (int)(sizeof tt->name) - 1); - copynchars(tt->death, s2, (int)(sizeof tt->death) - 1); - } else - tt->points = 0; - tt->plrole[1] = '\0'; - if ((i = str2role(tt->plrole)) >= 0) - Strcpy(tt->plrole, roles[i].filecode); - Strcpy(tt->plrace, "?"); - Strcpy(tt->plgend, (tt->plgend[0] == 'M') ? "Mal" : "Fem"); - Strcpy(tt->plalign, "?"); - } else if (sscanf(inbuf, fmt33, s1, s2, s3, s4, s5, s6) == 6) { - copynchars(tt->plrole, s1, (int)(sizeof tt->plrole) - 1); - copynchars(tt->plrace, s2, (int)(sizeof tt->plrace) - 1); - copynchars(tt->plgend, s3, (int)(sizeof tt->plgend) - 1); - copynchars(tt->plalign, s4, (int)(sizeof tt->plalign) - 1); - copynchars(tt->name, s5, (int)(sizeof tt->name) - 1); - copynchars(tt->death, s6, (int)(sizeof tt->death) - 1); - } else - tt->points = 0; + if (sscanf(inbuf, fmt32, tt->plrole, tt->plgend, s1, s2) == 4) { + tt->plrole[1] = tt->plgend[1] = '\0'; /* read via %c */ + copynchars(tt->name, s1, (int) (sizeof tt->name) - 1); + copynchars(tt->death, s2, (int) (sizeof tt->death) - 1); + } else + tt->points = 0; + tt->plrole[1] = '\0'; + if ((i = str2role(tt->plrole)) >= 0) + Strcpy(tt->plrole, roles[i].filecode); + Strcpy(tt->plrace, "?"); + Strcpy(tt->plgend, (tt->plgend[0] == 'M') ? "Mal" : "Fem"); + Strcpy(tt->plalign, "?"); + } else if (sscanf(inbuf, fmt33, s1, s2, s3, s4, s5, s6) == 6) { + copynchars(tt->plrole, s1, (int) (sizeof tt->plrole) - 1); + copynchars(tt->plrace, s2, (int) (sizeof tt->plrace) - 1); + copynchars(tt->plgend, s3, (int) (sizeof tt->plgend) - 1); + copynchars(tt->plalign, s4, (int) (sizeof tt->plalign) - 1); + copynchars(tt->name, s5, (int) (sizeof tt->name) - 1); + copynchars(tt->death, s6, (int) (sizeof tt->death) - 1); + } else + tt->points = 0; #ifdef NO_SCAN_BRACK - if(tt->points > 0) { - nsb_unmung_line(tt->name); - nsb_unmung_line(tt->death); - } + if (tt->points > 0) { + nsb_unmung_line(tt->name); + nsb_unmung_line(tt->death); + } #endif - } + } - /* check old score entries for Y2K problem and fix whenever found */ - if (tt->points > 0) { - if (tt->birthdate < 19000000L) tt->birthdate += 19000000L; - if (tt->deathdate < 19000000L) tt->deathdate += 19000000L; - } + /* check old score entries for Y2K problem and fix whenever found */ + if (tt->points > 0) { + if (tt->birthdate < 19000000L) + tt->birthdate += 19000000L; + if (tt->deathdate < 19000000L) + tt->deathdate += 19000000L; + } } STATIC_OVL void -writeentry(rfile,tt) +writeentry(rfile, tt) FILE *rfile; struct toptenentry *tt; { - static const char fmt32[] = "%c%c "; /* role,gender */ - static const char fmt33[] = "%s %s %s %s "; /* role,race,gndr,algn */ + static const char fmt32[] = "%c%c "; /* role,gender */ + static const char fmt33[] = "%s %s %s %s "; /* role,race,gndr,algn */ #ifndef NO_SCAN_BRACK - static const char fmt0[] = "%d.%d.%d %ld %d %d %d %d %d %d %ld %ld %d "; - static const char fmtX[] = "%s,%s\n"; -#else /* NO_SCAN_BRACK */ - static const char fmt0[] = "%d %d %d %ld %d %d %d %d %d %d %ld %ld %d "; - static const char fmtX[] = "%s %s\n"; + static const char fmt0[] = "%d.%d.%d %ld %d %d %d %d %d %d %ld %ld %d "; + static const char fmtX[] = "%s,%s\n"; +#else /* NO_SCAN_BRACK */ + static const char fmt0[] = "%d %d %d %ld %d %d %d %d %d %d %ld %ld %d "; + static const char fmtX[] = "%s %s\n"; - nsb_mung_line(tt->name); - nsb_mung_line(tt->death); + nsb_mung_line(tt->name); + nsb_mung_line(tt->death); #endif - (void)fprintf(rfile, fmt0, - tt->ver_major, tt->ver_minor, tt->patchlevel, - tt->points, tt->deathdnum, tt->deathlev, - tt->maxlvl, tt->hp, tt->maxhp, tt->deaths, - tt->deathdate, tt->birthdate, tt->uid); - if (tt->ver_major < 3 || - (tt->ver_major == 3 && tt->ver_minor < 3)) - (void)fprintf(rfile, fmt32, tt->plrole[0], tt->plgend[0]); - else - (void)fprintf(rfile, fmt33, - tt->plrole, tt->plrace, tt->plgend, tt->plalign); - (void)fprintf(rfile, fmtX, - onlyspace(tt->name) ? "_" : tt->name, tt->death); + (void) fprintf(rfile, fmt0, tt->ver_major, tt->ver_minor, tt->patchlevel, + tt->points, tt->deathdnum, tt->deathlev, tt->maxlvl, + tt->hp, tt->maxhp, tt->deaths, tt->deathdate, + tt->birthdate, tt->uid); + if (tt->ver_major < 3 || (tt->ver_major == 3 && tt->ver_minor < 3)) + (void) fprintf(rfile, fmt32, tt->plrole[0], tt->plgend[0]); + else + (void) fprintf(rfile, fmt33, tt->plrole, tt->plrace, tt->plgend, + tt->plalign); + (void) fprintf(rfile, fmtX, onlyspace(tt->name) ? "_" : tt->name, + tt->death); #ifdef NO_SCAN_BRACK - nsb_unmung_line(tt->name); - nsb_unmung_line(tt->death); + nsb_unmung_line(tt->name); + nsb_unmung_line(tt->death); #endif } /* as tab is never used in eg. plname or death, no need to mangle those. */ STATIC_OVL void -writexlentry(rfile,tt) +writexlentry(rfile, tt) FILE *rfile; struct toptenentry *tt; { -#define Fprintf (void)fprintf -#define XLOG_SEP '\t' /* xlogfile field separator. */ +#define Fprintf (void) fprintf +#define XLOG_SEP '\t' /* xlogfile field separator. */ char buf[BUFSZ]; - Sprintf(buf, "version=%d.%d.%d", - tt->ver_major, tt->ver_minor, tt->patchlevel); - Sprintf(eos(buf), "%cpoints=%ld%cdeathdnum=%d%cdeathlev=%d", - XLOG_SEP, tt->points, - XLOG_SEP, tt->deathdnum, - XLOG_SEP, tt->deathlev); - Sprintf(eos(buf), "%cmaxlvl=%d%chp=%d%cmaxhp=%d", - XLOG_SEP, tt->maxlvl, - XLOG_SEP, tt->hp, - XLOG_SEP, tt->maxhp); + Sprintf(buf, "version=%d.%d.%d", tt->ver_major, tt->ver_minor, + tt->patchlevel); + Sprintf(eos(buf), "%cpoints=%ld%cdeathdnum=%d%cdeathlev=%d", XLOG_SEP, + tt->points, XLOG_SEP, tt->deathdnum, XLOG_SEP, tt->deathlev); + Sprintf(eos(buf), "%cmaxlvl=%d%chp=%d%cmaxhp=%d", XLOG_SEP, tt->maxlvl, + XLOG_SEP, tt->hp, XLOG_SEP, tt->maxhp); Sprintf(eos(buf), "%cdeaths=%d%cdeathdate=%ld%cbirthdate=%ld%cuid=%d", - XLOG_SEP, tt->deaths, - XLOG_SEP, tt->deathdate, - XLOG_SEP, tt->birthdate, - XLOG_SEP, tt->uid); + XLOG_SEP, tt->deaths, XLOG_SEP, tt->deathdate, XLOG_SEP, + tt->birthdate, XLOG_SEP, tt->uid); Fprintf(rfile, "%s", buf); - Sprintf(buf, "%crole=%s%crace=%s%cgender=%s%calign=%s", - XLOG_SEP, tt->plrole, - XLOG_SEP, tt->plrace, - XLOG_SEP, tt->plgend, - XLOG_SEP, tt->plalign); + Sprintf(buf, "%crole=%s%crace=%s%cgender=%s%calign=%s", XLOG_SEP, + tt->plrole, XLOG_SEP, tt->plrace, XLOG_SEP, tt->plgend, XLOG_SEP, + tt->plalign); Fprintf(rfile, "%s%cname=%s%cdeath=%s", - buf, /* (already includes separator) */ - XLOG_SEP, plname, - XLOG_SEP, tt->death); - Fprintf(rfile, "%cconduct=0x%lx%cturns=%ld%cachieve=0x%lx", - XLOG_SEP, encodeconduct(), - XLOG_SEP, moves, - XLOG_SEP, encodeachieve()); - Fprintf(rfile, "%crealtime=%ld%cstarttime=%ld%cendtime=%ld", - XLOG_SEP, (long)urealtime.realtime, - XLOG_SEP, (long)ubirthday, - XLOG_SEP, (long)urealtime.endtime); - Fprintf(rfile, "%cgender0=%s%calign0=%s", - XLOG_SEP, genders[flags.initgend].filecode, - XLOG_SEP, aligns[1 - u.ualignbase[A_ORIGINAL]].filecode); - Fprintf(rfile, "%cflags=0x%lx", - XLOG_SEP, encodexlogflags()); + buf, /* (already includes separator) */ + XLOG_SEP, plname, XLOG_SEP, tt->death); + Fprintf(rfile, "%cconduct=0x%lx%cturns=%ld%cachieve=0x%lx", XLOG_SEP, + encodeconduct(), XLOG_SEP, moves, XLOG_SEP, encodeachieve()); + Fprintf(rfile, "%crealtime=%ld%cstarttime=%ld%cendtime=%ld", XLOG_SEP, + (long) urealtime.realtime, XLOG_SEP, (long) ubirthday, XLOG_SEP, + (long) urealtime.endtime); + Fprintf(rfile, "%cgender0=%s%calign0=%s", XLOG_SEP, + genders[flags.initgend].filecode, XLOG_SEP, + aligns[1 - u.ualignbase[A_ORIGINAL]].filecode); + Fprintf(rfile, "%cflags=0x%lx", XLOG_SEP, encodexlogflags()); Fprintf(rfile, "\n"); #undef XLOG_SEP } @@ -353,9 +334,12 @@ encodexlogflags() { long e = 0L; - if (wizard) e |= 1L << 0; - if (discover) e |= 1L << 1; - if (!u.uroleplay.numbones) e |= 1L << 2; + if (wizard) + e |= 1L << 0; + if (discover) + e |= 1L << 1; + if (!u.uroleplay.numbones) + e |= 1L << 2; return e; } @@ -365,18 +349,30 @@ encodeconduct() { long e = 0L; - if(!u.uconduct.food) e |= 1L << 0; - if(!u.uconduct.unvegan) e |= 1L << 1; - if(!u.uconduct.unvegetarian) e |= 1L << 2; - if(!u.uconduct.gnostic) e |= 1L << 3; - if(!u.uconduct.weaphit) e |= 1L << 4; - if(!u.uconduct.killer) e |= 1L << 5; - if(!u.uconduct.literate) e |= 1L << 6; - if(!u.uconduct.polypiles) e |= 1L << 7; - if(!u.uconduct.polyselfs) e |= 1L << 8; - if(!u.uconduct.wishes) e |= 1L << 9; - if(!u.uconduct.wisharti) e |= 1L << 10; - if(!num_genocides()) e |= 1L << 11; + if (!u.uconduct.food) + e |= 1L << 0; + if (!u.uconduct.unvegan) + e |= 1L << 1; + if (!u.uconduct.unvegetarian) + e |= 1L << 2; + if (!u.uconduct.gnostic) + e |= 1L << 3; + if (!u.uconduct.weaphit) + e |= 1L << 4; + if (!u.uconduct.killer) + e |= 1L << 5; + if (!u.uconduct.literate) + e |= 1L << 6; + if (!u.uconduct.polypiles) + e |= 1L << 7; + if (!u.uconduct.polyselfs) + e |= 1L << 8; + if (!u.uconduct.wishes) + e |= 1L << 9; + if (!u.uconduct.wisharti) + e |= 1L << 10; + if (!num_genocides()) + e |= 1L << 11; return e; } @@ -386,38 +382,50 @@ encodeachieve() { long r = 0L; - if(u.uachieve.bell) r |= 1L << 0; - if(u.uachieve.enter_gehennom) r |= 1L << 1; - if(u.uachieve.menorah) r |= 1L << 2; - if(u.uachieve.book) r |= 1L << 3; - if(u.uevent.invoked) r |= 1L << 4; - if(u.uachieve.amulet) r |= 1L << 5; - if(In_endgame(&u.uz)) r |= 1L << 6; - if(Is_astralevel(&u.uz)) r |= 1L << 7; - if(u.uachieve.ascended) r |= 1L << 8; - if(u.uachieve.mines_luckstone) r |= 1L << 9; - if(u.uachieve.finish_sokoban) r |= 1L << 10; - if(u.uachieve.killed_medusa) r |= 1L << 11; - if(u.uroleplay.blind) r |= 1L << 12; - if(u.uroleplay.nudist) r |= 1L << 13; + if (u.uachieve.bell) + r |= 1L << 0; + if (u.uachieve.enter_gehennom) + r |= 1L << 1; + if (u.uachieve.menorah) + r |= 1L << 2; + if (u.uachieve.book) + r |= 1L << 3; + if (u.uevent.invoked) + r |= 1L << 4; + if (u.uachieve.amulet) + r |= 1L << 5; + if (In_endgame(&u.uz)) + r |= 1L << 6; + if (Is_astralevel(&u.uz)) + r |= 1L << 7; + if (u.uachieve.ascended) + r |= 1L << 8; + if (u.uachieve.mines_luckstone) + r |= 1L << 9; + if (u.uachieve.finish_sokoban) + r |= 1L << 10; + if (u.uachieve.killed_medusa) + r |= 1L << 11; + if (u.uroleplay.blind) + r |= 1L << 12; + if (u.uroleplay.nudist) + r |= 1L << 13; return r; } - - STATIC_OVL void free_ttlist(tt) struct toptenentry *tt; { - struct toptenentry *ttnext; + struct toptenentry *ttnext; - while (tt->points > 0) { - ttnext = tt->tt_next; - dealloc_ttentry(tt); - tt = ttnext; - } - dealloc_ttentry(tt); + while (tt->points > 0) { + ttnext = tt->tt_next; + dealloc_ttentry(tt); + tt = ttnext; + } + dealloc_ttentry(tt); } void @@ -425,19 +433,19 @@ topten(how, when) int how; time_t when; { - int uid = getuid(); - int rank, rank0 = -1, rank1 = 0; - int occ_cnt = sysopt.persmax; - register struct toptenentry *t0, *tprev; - struct toptenentry *t1; - FILE *rfile; - register int flg = 0; - boolean t0_used; + int uid = getuid(); + int rank, rank0 = -1, rank1 = 0; + int occ_cnt = sysopt.persmax; + register struct toptenentry *t0, *tprev; + struct toptenentry *t1; + FILE *rfile; + register int flg = 0; + boolean t0_used; #ifdef LOGFILE - FILE *lfile; + FILE *lfile; #endif /* LOGFILE */ #ifdef XLOGFILE - FILE *xlfile; + FILE *xlfile; #endif /* XLOGFILE */ /* Under DICE 3.0, this crashes the system consistently, apparently due to @@ -445,282 +453,292 @@ time_t when; * topten support entirely - at least then the game exits cleanly. --AC */ #ifdef _DCC - return; + return; #endif -/* If we are in the midst of a panic, cut out topten entirely. - * topten uses alloc() several times, which will lead to - * problems if the panic was the result of an alloc() failure. - */ - if (program_state.panicking) - return; + /* If we are in the midst of a panic, cut out topten entirely. + * topten uses alloc() several times, which will lead to + * problems if the panic was the result of an alloc() failure. + */ + if (program_state.panicking) + return; - if (iflags.toptenwin) { - toptenwin = create_nhwindow(NHW_TEXT); - } + if (iflags.toptenwin) { + toptenwin = create_nhwindow(NHW_TEXT); + } #if defined(UNIX) || defined(VMS) || defined(__EMX__) -#define HUP if (!program_state.done_hup) +#define HUP if (!program_state.done_hup) #else #define HUP #endif #ifdef TOS - restore_colors(); /* make sure the screen is black on white */ + restore_colors(); /* make sure the screen is black on white */ #endif - /* create a new 'topten' entry */ - t0_used = FALSE; - t0 = newttentry(); - /* deepest_lev_reached() is in terms of depth(), and reporting the - * deepest level reached in the dungeon death occurred in doesn't - * seem right, so we have to report the death level in depth() terms - * as well (which also seems reasonable since that's all the player - * sees on the screen anyway) - */ - t0->ver_major = VERSION_MAJOR; - t0->ver_minor = VERSION_MINOR; - t0->patchlevel = PATCHLEVEL; - t0->points = u.urexp; - t0->deathdnum = u.uz.dnum; - t0->deathlev = observable_depth(&u.uz); - t0->maxlvl = deepest_lev_reached(TRUE); - t0->hp = u.uhp; - t0->maxhp = u.uhpmax; - t0->deaths = u.umortality; - t0->uid = uid; - copynchars(t0->plrole, urole.filecode, ROLESZ); - copynchars(t0->plrace, urace.filecode, ROLESZ); - copynchars(t0->plgend, genders[flags.female].filecode, ROLESZ); - copynchars(t0->plalign, aligns[1 - u.ualign.type].filecode, ROLESZ); - copynchars(t0->name, plname, NAMSZ); - formatkiller(t0->death, sizeof t0->death, how); - t0->birthdate = yyyymmdd(ubirthday); - t0->deathdate = yyyymmdd(when); - t0->tt_next = 0; - urealtime.endtime = when; + /* create a new 'topten' entry */ + t0_used = FALSE; + t0 = newttentry(); + /* deepest_lev_reached() is in terms of depth(), and reporting the + * deepest level reached in the dungeon death occurred in doesn't + * seem right, so we have to report the death level in depth() terms + * as well (which also seems reasonable since that's all the player + * sees on the screen anyway) + */ + t0->ver_major = VERSION_MAJOR; + t0->ver_minor = VERSION_MINOR; + t0->patchlevel = PATCHLEVEL; + t0->points = u.urexp; + t0->deathdnum = u.uz.dnum; + t0->deathlev = observable_depth(&u.uz); + t0->maxlvl = deepest_lev_reached(TRUE); + t0->hp = u.uhp; + t0->maxhp = u.uhpmax; + t0->deaths = u.umortality; + t0->uid = uid; + copynchars(t0->plrole, urole.filecode, ROLESZ); + copynchars(t0->plrace, urace.filecode, ROLESZ); + copynchars(t0->plgend, genders[flags.female].filecode, ROLESZ); + copynchars(t0->plalign, aligns[1 - u.ualign.type].filecode, ROLESZ); + copynchars(t0->name, plname, NAMSZ); + formatkiller(t0->death, sizeof t0->death, how); + t0->birthdate = yyyymmdd(ubirthday); + t0->deathdate = yyyymmdd(when); + t0->tt_next = 0; + urealtime.endtime = when; #ifdef UPDATE_RECORD_IN_PLACE - t0->fpos = -1L; + t0->fpos = -1L; #endif -#ifdef LOGFILE /* used for debugging (who dies of what, where) */ - if (lock_file(LOGFILE, SCOREPREFIX, 10)) { - if(!(lfile = fopen_datafile(LOGFILE, "a", SCOREPREFIX))) { - HUP raw_print("Cannot open log file!"); - } else { - writeentry(lfile, t0); - (void) fclose(lfile); - } - unlock_file(LOGFILE); - } +#ifdef LOGFILE /* used for debugging (who dies of what, where) */ + if (lock_file(LOGFILE, SCOREPREFIX, 10)) { + if (!(lfile = fopen_datafile(LOGFILE, "a", SCOREPREFIX))) { + HUP raw_print("Cannot open log file!"); + } else { + writeentry(lfile, t0); + (void) fclose(lfile); + } + unlock_file(LOGFILE); + } #endif /* LOGFILE */ #ifdef XLOGFILE - if (lock_file(XLOGFILE, SCOREPREFIX, 10)) { - if(!(xlfile = fopen_datafile(XLOGFILE, "a", SCOREPREFIX))) { - HUP raw_print("Cannot open extended log file!"); - } else { - writexlentry(xlfile, t0); - (void) fclose(xlfile); - } - unlock_file(XLOGFILE); - } + if (lock_file(XLOGFILE, SCOREPREFIX, 10)) { + if (!(xlfile = fopen_datafile(XLOGFILE, "a", SCOREPREFIX))) { + HUP raw_print("Cannot open extended log file!"); + } else { + writexlentry(xlfile, t0); + (void) fclose(xlfile); + } + unlock_file(XLOGFILE); + } #endif /* XLOGFILE */ - if (wizard || discover) { - if (how != PANICKED) HUP { - char pbuf[BUFSZ]; - topten_print(""); - Sprintf(pbuf, - "Since you were in %s mode, the score list will not be checked.", - wizard ? "wizard" : "discover"); - topten_print(pbuf); - } - goto showwin; - } + if (wizard || discover) { + if (how != PANICKED) + HUP + { + char pbuf[BUFSZ]; + topten_print(""); + Sprintf(pbuf, "Since you were in %s mode, the score list " + "will not be checked.", + wizard ? "wizard" : "discover"); + topten_print(pbuf); + } + goto showwin; + } - if (!lock_file(RECORD, SCOREPREFIX, 60)) - goto destroywin; + if (!lock_file(RECORD, SCOREPREFIX, 60)) + goto destroywin; #ifdef UPDATE_RECORD_IN_PLACE - rfile = fopen_datafile(RECORD, "r+", SCOREPREFIX); + rfile = fopen_datafile(RECORD, "r+", SCOREPREFIX); #else - rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); #endif - if (!rfile) { - HUP raw_print("Cannot open record file!"); - unlock_file(RECORD); - goto destroywin; - } + if (!rfile) { + HUP raw_print("Cannot open record file!"); + unlock_file(RECORD); + goto destroywin; + } - HUP topten_print(""); + HUP topten_print(""); - /* assure minimum number of points */ - if(t0->points < sysopt.pointsmin) t0->points = 0; + /* assure minimum number of points */ + if (t0->points < sysopt.pointsmin) + t0->points = 0; - t1 = tt_head = newttentry(); - tprev = 0; - /* rank0: -1 undefined, 0 not_on_list, n n_th on list */ - for(rank = 1; ; ) { - readentry(rfile, t1); - if (t1->points < sysopt.pointsmin) t1->points = 0; - if(rank0 < 0 && t1->points < t0->points) { - rank0 = rank++; - if(tprev == 0) - tt_head = t0; - else - tprev->tt_next = t0; - t0->tt_next = t1; + t1 = tt_head = newttentry(); + tprev = 0; + /* rank0: -1 undefined, 0 not_on_list, n n_th on list */ + for (rank = 1;;) { + readentry(rfile, t1); + if (t1->points < sysopt.pointsmin) + t1->points = 0; + if (rank0 < 0 && t1->points < t0->points) { + rank0 = rank++; + if (tprev == 0) + tt_head = t0; + else + tprev->tt_next = t0; + t0->tt_next = t1; #ifdef UPDATE_RECORD_IN_PLACE - t0->fpos = t1->fpos; /* insert here */ + t0->fpos = t1->fpos; /* insert here */ #endif - t0_used = TRUE; - occ_cnt--; - flg++; /* ask for a rewrite */ - } else tprev = t1; + t0_used = TRUE; + occ_cnt--; + flg++; /* ask for a rewrite */ + } else + tprev = t1; - if(t1->points == 0) break; - if( - (sysopt.pers_is_uid - ? t1->uid == t0->uid - : strncmp(t1->name, t0->name, NAMSZ) == 0 - ) && - !strncmp(t1->plrole, t0->plrole, ROLESZ) && - --occ_cnt <= 0) { - if(rank0 < 0) { - rank0 = 0; - rank1 = rank; - HUP { - char pbuf[BUFSZ]; - Sprintf(pbuf, - "You didn't beat your previous score of %ld points.", - t1->points); - topten_print(pbuf); - topten_print(""); - } - } - if(occ_cnt < 0) { - flg++; - continue; - } - } - if(rank <= sysopt.entrymax) { - t1->tt_next = newttentry(); - t1 = t1->tt_next; - rank++; - } - if(rank > sysopt.entrymax) { - t1->points = 0; - break; - } - } - if(flg) { /* rewrite record file */ + if (t1->points == 0) + break; + if ((sysopt.pers_is_uid ? t1->uid == t0->uid + : strncmp(t1->name, t0->name, NAMSZ) == 0) + && !strncmp(t1->plrole, t0->plrole, ROLESZ) && --occ_cnt <= 0) { + if (rank0 < 0) { + rank0 = 0; + rank1 = rank; + HUP + { + char pbuf[BUFSZ]; + Sprintf( + pbuf, + "You didn't beat your previous score of %ld points.", + t1->points); + topten_print(pbuf); + topten_print(""); + } + } + if (occ_cnt < 0) { + flg++; + continue; + } + } + if (rank <= sysopt.entrymax) { + t1->tt_next = newttentry(); + t1 = t1->tt_next; + rank++; + } + if (rank > sysopt.entrymax) { + t1->points = 0; + break; + } + } + if (flg) { /* rewrite record file */ #ifdef UPDATE_RECORD_IN_PLACE - (void) fseek(rfile, (t0->fpos >= 0 ? - t0->fpos : final_fpos), SEEK_SET); + (void) fseek(rfile, (t0->fpos >= 0 ? t0->fpos : final_fpos), + SEEK_SET); #else - (void) fclose(rfile); - if(!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))){ - HUP raw_print("Cannot write record file"); - unlock_file(RECORD); - free_ttlist(tt_head); - goto destroywin; - } -#endif /* UPDATE_RECORD_IN_PLACE */ - if(!done_stopprint) if(rank0 > 0){ - if(rank0 <= 10) - topten_print("You made the top ten list!"); - else { - char pbuf[BUFSZ]; - Sprintf(pbuf, - "You reached the %d%s place on the top %d list.", - rank0, ordin(rank0), sysopt.entrymax); - topten_print(pbuf); - } - topten_print(""); - } - } - if(rank0 == 0) rank0 = rank1; - if(rank0 <= 0) rank0 = rank; - if(!done_stopprint) outheader(); - t1 = tt_head; - for(rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { - if(flg + (void) fclose(rfile); + if (!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))) { + HUP raw_print("Cannot write record file"); + unlock_file(RECORD); + free_ttlist(tt_head); + goto destroywin; + } +#endif /* UPDATE_RECORD_IN_PLACE */ + if (!done_stopprint) + if (rank0 > 0) { + if (rank0 <= 10) + topten_print("You made the top ten list!"); + else { + char pbuf[BUFSZ]; + Sprintf(pbuf, + "You reached the %d%s place on the top %d list.", + rank0, ordin(rank0), sysopt.entrymax); + topten_print(pbuf); + } + topten_print(""); + } + } + if (rank0 == 0) + rank0 = rank1; + if (rank0 <= 0) + rank0 = rank; + if (!done_stopprint) + outheader(); + t1 = tt_head; + for (rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { + if (flg #ifdef UPDATE_RECORD_IN_PLACE - && rank >= rank0 + && rank >= rank0 #endif - ) writeentry(rfile, t1); - if (done_stopprint) continue; - if (rank > flags.end_top && - (rank < rank0 - flags.end_around || - rank > rank0 + flags.end_around) && - (!flags.end_own || - (sysopt.pers_is_uid - ? t1->uid == t0->uid - : strncmp(t1->name, t0->name, NAMSZ) == 0 - ) - )) continue; - if (rank == rank0 - flags.end_around && - rank0 > flags.end_top + flags.end_around + 1 && - !flags.end_own) - topten_print(""); - if(rank != rank0) - outentry(rank, t1, FALSE); - else if(!rank1) - outentry(rank, t1, TRUE); - else { - outentry(rank, t1, TRUE); - outentry(0, t0, TRUE); - } - } - if(rank0 >= rank) if(!done_stopprint) - outentry(0, t0, TRUE); + ) + writeentry(rfile, t1); + if (done_stopprint) + continue; + if (rank > flags.end_top && (rank < rank0 - flags.end_around + || rank > rank0 + flags.end_around) + && (!flags.end_own + || (sysopt.pers_is_uid + ? t1->uid == t0->uid + : strncmp(t1->name, t0->name, NAMSZ) == 0))) + continue; + if (rank == rank0 - flags.end_around + && rank0 > flags.end_top + flags.end_around + 1 && !flags.end_own) + topten_print(""); + if (rank != rank0) + outentry(rank, t1, FALSE); + else if (!rank1) + outentry(rank, t1, TRUE); + else { + outentry(rank, t1, TRUE); + outentry(0, t0, TRUE); + } + } + if (rank0 >= rank) + if (!done_stopprint) + outentry(0, t0, TRUE); #ifdef UPDATE_RECORD_IN_PLACE - if (flg) { -# ifdef TRUNCATE_FILE - /* if a reasonable way to truncate a file exists, use it */ - truncate_file(rfile); -# else - /* use sentinel record rather than relying on truncation */ - t1->points = 0L; /* terminates file when read back in */ - t1->ver_major = t1->ver_minor = t1->patchlevel = 0; - t1->uid = t1->deathdnum = t1->deathlev = 0; - t1->maxlvl = t1->hp = t1->maxhp = t1->deaths = 0; - t1->plrole[0] = t1->plrace[0] = t1->plgend[0] = t1->plalign[0] = '-'; - t1->plrole[1] = t1->plrace[1] = t1->plgend[1] = t1->plalign[1] = 0; - t1->birthdate = t1->deathdate = yyyymmdd((time_t)0L); - Strcpy(t1->name, "@"); - Strcpy(t1->death, "\n"); - writeentry(rfile, t1); - (void) fflush(rfile); -# endif /* TRUNCATE_FILE */ - } -#endif /* UPDATE_RECORD_IN_PLACE */ - (void) fclose(rfile); - unlock_file(RECORD); - free_ttlist(tt_head); + if (flg) { +#ifdef TRUNCATE_FILE + /* if a reasonable way to truncate a file exists, use it */ + truncate_file(rfile); +#else + /* use sentinel record rather than relying on truncation */ + t1->points = 0L; /* terminates file when read back in */ + t1->ver_major = t1->ver_minor = t1->patchlevel = 0; + t1->uid = t1->deathdnum = t1->deathlev = 0; + t1->maxlvl = t1->hp = t1->maxhp = t1->deaths = 0; + t1->plrole[0] = t1->plrace[0] = t1->plgend[0] = t1->plalign[0] = '-'; + t1->plrole[1] = t1->plrace[1] = t1->plgend[1] = t1->plalign[1] = 0; + t1->birthdate = t1->deathdate = yyyymmdd((time_t) 0L); + Strcpy(t1->name, "@"); + Strcpy(t1->death, "\n"); + writeentry(rfile, t1); + (void) fflush(rfile); +#endif /* TRUNCATE_FILE */ + } +#endif /* UPDATE_RECORD_IN_PLACE */ + (void) fclose(rfile); + unlock_file(RECORD); + free_ttlist(tt_head); - showwin: - if (iflags.toptenwin && !done_stopprint) - display_nhwindow(toptenwin, 1); - destroywin: - if (!t0_used) dealloc_ttentry(t0); - if (iflags.toptenwin) { - destroy_nhwindow(toptenwin); - toptenwin=WIN_ERR; - } +showwin: + if (iflags.toptenwin && !done_stopprint) + display_nhwindow(toptenwin, 1); +destroywin: + if (!t0_used) + dealloc_ttentry(t0); + if (iflags.toptenwin) { + destroy_nhwindow(toptenwin); + toptenwin = WIN_ERR; + } } STATIC_OVL void outheader() { - char linebuf[BUFSZ]; - register char *bp; + char linebuf[BUFSZ]; + register char *bp; - Strcpy(linebuf, " No Points Name"); - bp = eos(linebuf); - while(bp < linebuf + COLNO - 9) *bp++ = ' '; - Strcpy(bp, "Hp [max]"); - topten_print(linebuf); + Strcpy(linebuf, " No Points Name"); + bp = eos(linebuf); + while (bp < linebuf + COLNO - 9) + *bp++ = ' '; + Strcpy(bp, "Hp [max]"); + topten_print(linebuf); } /* so>0: standout line; so=0: ordinary line */ @@ -730,147 +748,161 @@ struct toptenentry *t1; int rank; boolean so; { - boolean second_line = TRUE; - char linebuf[BUFSZ]; - char *bp, hpbuf[24], linebuf3[BUFSZ]; - int hppos, lngr; + boolean second_line = TRUE; + char linebuf[BUFSZ]; + char *bp, hpbuf[24], linebuf3[BUFSZ]; + int hppos, lngr; + linebuf[0] = '\0'; + if (rank) + Sprintf(eos(linebuf), "%3d", rank); + else + Strcat(linebuf, " "); - linebuf[0] = '\0'; - if (rank) Sprintf(eos(linebuf), "%3d", rank); - else Strcat(linebuf, " "); + Sprintf(eos(linebuf), " %10ld %.10s", t1->points ? t1->points : u.urexp, + t1->name); + Sprintf(eos(linebuf), "-%s", t1->plrole); + if (t1->plrace[0] != '?') + Sprintf(eos(linebuf), "-%s", t1->plrace); + /* Printing of gender and alignment is intentional. It has been + * part of the NetHack Geek Code, and illustrates a proper way to + * specify a character from the command line. + */ + Sprintf(eos(linebuf), "-%s", t1->plgend); + if (t1->plalign[0] != '?') + Sprintf(eos(linebuf), "-%s ", t1->plalign); + else + Strcat(linebuf, " "); + if (!strncmp("escaped", t1->death, 7)) { + Sprintf(eos(linebuf), "escaped the dungeon %s[max level %d]", + !strncmp(" (", t1->death + 7, 2) ? t1->death + 7 + 2 : "", + t1->maxlvl); + /* fixup for closing paren in "escaped... with...Amulet)[max..." */ + if ((bp = index(linebuf, ')')) != 0) + *bp = (t1->deathdnum == astral_level.dnum) ? '\0' : ' '; + second_line = FALSE; + } else if (!strncmp("ascended", t1->death, 8)) { + Sprintf(eos(linebuf), "ascended to demigod%s-hood", + (t1->plgend[0] == 'F') ? "dess" : ""); + second_line = FALSE; + } else { + if (!strncmp(t1->death, "quit", 4)) { + Strcat(linebuf, "quit"); + second_line = FALSE; + } else if (!strncmp(t1->death, "died of st", 10)) { + Strcat(linebuf, "starved to death"); + second_line = FALSE; + } else if (!strncmp(t1->death, "choked", 6)) { + Sprintf(eos(linebuf), "choked on h%s food", + (t1->plgend[0] == 'F') ? "er" : "is"); + } else if (!strncmp(t1->death, "poisoned", 8)) { + Strcat(linebuf, "was poisoned"); + } else if (!strncmp(t1->death, "crushed", 7)) { + Strcat(linebuf, "was crushed to death"); + } else if (!strncmp(t1->death, "petrified by ", 13)) { + Strcat(linebuf, "turned to stone"); + } else + Strcat(linebuf, "died"); - Sprintf(eos(linebuf), " %10ld %.10s", t1->points?t1->points:u.urexp, - t1->name); - Sprintf(eos(linebuf), "-%s", t1->plrole); - if (t1->plrace[0] != '?') - Sprintf(eos(linebuf), "-%s", t1->plrace); - /* Printing of gender and alignment is intentional. It has been - * part of the NetHack Geek Code, and illustrates a proper way to - * specify a character from the command line. - */ - Sprintf(eos(linebuf), "-%s", t1->plgend); - if (t1->plalign[0] != '?') - Sprintf(eos(linebuf), "-%s ", t1->plalign); - else - Strcat(linebuf, " "); - if (!strncmp("escaped", t1->death, 7)) { - Sprintf(eos(linebuf), "escaped the dungeon %s[max level %d]", - !strncmp(" (", t1->death + 7, 2) ? t1->death + 7 + 2 : "", - t1->maxlvl); - /* fixup for closing paren in "escaped... with...Amulet)[max..." */ - if ((bp = index(linebuf, ')')) != 0) - *bp = (t1->deathdnum == astral_level.dnum) ? '\0' : ' '; - second_line = FALSE; - } else if (!strncmp("ascended", t1->death, 8)) { - Sprintf(eos(linebuf), "ascended to demigod%s-hood", - (t1->plgend[0] == 'F') ? "dess" : ""); - second_line = FALSE; - } else { - if (!strncmp(t1->death, "quit", 4)) { - Strcat(linebuf, "quit"); - second_line = FALSE; - } else if (!strncmp(t1->death, "died of st", 10)) { - Strcat(linebuf, "starved to death"); - second_line = FALSE; - } else if (!strncmp(t1->death, "choked", 6)) { - Sprintf(eos(linebuf), "choked on h%s food", - (t1->plgend[0] == 'F') ? "er" : "is"); - } else if (!strncmp(t1->death, "poisoned", 8)) { - Strcat(linebuf, "was poisoned"); - } else if (!strncmp(t1->death, "crushed", 7)) { - Strcat(linebuf, "was crushed to death"); - } else if (!strncmp(t1->death, "petrified by ", 13)) { - Strcat(linebuf, "turned to stone"); - } else Strcat(linebuf, "died"); + if (t1->deathdnum == astral_level.dnum) { + const char *arg, *fmt = " on the Plane of %s"; - if (t1->deathdnum == astral_level.dnum) { - const char *arg, *fmt = " on the Plane of %s"; + switch (t1->deathlev) { + case -5: + fmt = " on the %s Plane"; + arg = "Astral"; + break; + case -4: + arg = "Water"; + break; + case -3: + arg = "Fire"; + break; + case -2: + arg = "Air"; + break; + case -1: + arg = "Earth"; + break; + default: + arg = "Void"; + break; + } + Sprintf(eos(linebuf), fmt, arg); + } else { + Sprintf(eos(linebuf), " in %s", dungeons[t1->deathdnum].dname); + if (t1->deathdnum != knox_level.dnum) + Sprintf(eos(linebuf), " on level %d", t1->deathlev); + if (t1->deathlev != t1->maxlvl) + Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); + } - switch (t1->deathlev) { - case -5: - fmt = " on the %s Plane"; - arg = "Astral"; break; - case -4: - arg = "Water"; break; - case -3: - arg = "Fire"; break; - case -2: - arg = "Air"; break; - case -1: - arg = "Earth"; break; - default: - arg = "Void"; break; - } - Sprintf(eos(linebuf), fmt, arg); - } else { - Sprintf(eos(linebuf), " in %s", dungeons[t1->deathdnum].dname); - if (t1->deathdnum != knox_level.dnum) - Sprintf(eos(linebuf), " on level %d", t1->deathlev); - if (t1->deathlev != t1->maxlvl) - Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); - } + /* kludge for "quit while already on Charon's boat" */ + if (!strncmp(t1->death, "quit ", 5)) + Strcat(linebuf, t1->death + 4); + } + Strcat(linebuf, "."); - /* kludge for "quit while already on Charon's boat" */ - if (!strncmp(t1->death, "quit ", 5)) - Strcat(linebuf, t1->death + 4); - } - Strcat(linebuf, "."); + /* Quit, starved, ascended, and escaped contain no second line */ + if (second_line) + Sprintf(eos(linebuf), " %c%s.", highc(*(t1->death)), t1->death + 1); - /* Quit, starved, ascended, and escaped contain no second line */ - if (second_line) - Sprintf(eos(linebuf), " %c%s.", highc(*(t1->death)), t1->death+1); + lngr = (int) strlen(linebuf); + if (t1->hp <= 0) + hpbuf[0] = '-', hpbuf[1] = '\0'; + else + Sprintf(hpbuf, "%d", t1->hp); + /* beginning of hp column after padding (not actually padded yet) */ + hppos = COLNO - (sizeof(" Hp [max]") - 1); /* sizeof(str) includes \0 */ + while (lngr >= hppos) { + for (bp = eos(linebuf); !(*bp == ' ' && (bp - linebuf < hppos)); bp--) + ; + /* special case: word is too long, wrap in the middle */ + if (linebuf + 15 >= bp) + bp = linebuf + hppos - 1; + /* special case: if about to wrap in the middle of maximum + dungeon depth reached, wrap in front of it instead */ + if (bp > linebuf + 5 && !strncmp(bp - 5, " [max", 5)) + bp -= 5; + if (*bp != ' ') + Strcpy(linebuf3, bp); + else + Strcpy(linebuf3, bp + 1); + *bp = 0; + if (so) { + while (bp < linebuf + (COLNO - 1)) + *bp++ = ' '; + *bp = 0; + topten_print_bold(linebuf); + } else + topten_print(linebuf); + Sprintf(linebuf, "%15s %s", "", linebuf3); + lngr = strlen(linebuf); + } + /* beginning of hp column not including padding */ + hppos = COLNO - 7 - (int) strlen(hpbuf); + bp = eos(linebuf); - lngr = (int)strlen(linebuf); - if (t1->hp <= 0) hpbuf[0] = '-', hpbuf[1] = '\0'; - else Sprintf(hpbuf, "%d", t1->hp); - /* beginning of hp column after padding (not actually padded yet) */ - hppos = COLNO - (sizeof(" Hp [max]")-1); /* sizeof(str) includes \0 */ - while (lngr >= hppos) { - for(bp = eos(linebuf); - !(*bp == ' ' && (bp-linebuf < hppos)); - bp--) - ; - /* special case: word is too long, wrap in the middle */ - if (linebuf+15 >= bp) bp = linebuf + hppos - 1; - /* special case: if about to wrap in the middle of maximum - dungeon depth reached, wrap in front of it instead */ - if (bp > linebuf + 5 && !strncmp(bp - 5, " [max", 5)) bp -= 5; - if (*bp != ' ') - Strcpy(linebuf3, bp); - else - Strcpy(linebuf3, bp+1); - *bp = 0; - if (so) { - while (bp < linebuf + (COLNO-1)) *bp++ = ' '; - *bp = 0; - topten_print_bold(linebuf); - } else - topten_print(linebuf); - Sprintf(linebuf, "%15s %s", "", linebuf3); - lngr = strlen(linebuf); - } - /* beginning of hp column not including padding */ - hppos = COLNO - 7 - (int)strlen(hpbuf); - bp = eos(linebuf); + if (bp <= linebuf + hppos) { + /* pad any necessary blanks to the hit point entry */ + while (bp < linebuf + hppos) + *bp++ = ' '; + Strcpy(bp, hpbuf); + Sprintf(eos(bp), " %s[%d]", + (t1->maxhp < 10) ? " " : (t1->maxhp < 100) ? " " : "", + t1->maxhp); + } - if (bp <= linebuf + hppos) { - /* pad any necessary blanks to the hit point entry */ - while (bp < linebuf + hppos) *bp++ = ' '; - Strcpy(bp, hpbuf); - Sprintf(eos(bp), " %s[%d]", - (t1->maxhp < 10) ? " " : (t1->maxhp < 100) ? " " : "", - t1->maxhp); - } - - if (so) { - bp = eos(linebuf); - if (so >= COLNO) so = COLNO-1; - while (bp < linebuf + so) *bp++ = ' '; - *bp = 0; - topten_print_bold(linebuf); - } else - topten_print(linebuf); + if (so) { + bp = eos(linebuf); + if (so >= COLNO) + so = COLNO - 1; + while (bp < linebuf + so) + *bp++ = ' '; + *bp = 0; + topten_print_bold(linebuf); + } else + topten_print(linebuf); } STATIC_OVL int @@ -882,35 +914,34 @@ int playerct; const char **players; int uid; { - int i; + int i; - if (current_ver && (t1->ver_major != VERSION_MAJOR || - t1->ver_minor != VERSION_MINOR || - t1->patchlevel != PATCHLEVEL)) - return 0; + if (current_ver + && (t1->ver_major != VERSION_MAJOR || t1->ver_minor != VERSION_MINOR + || t1->patchlevel != PATCHLEVEL)) + return 0; - if (sysopt.pers_is_uid && !playerct && t1->uid == uid) - return 1; + if (sysopt.pers_is_uid && !playerct && t1->uid == uid) + return 1; - for (i = 0; i < playerct; i++) { - if (players[i][0] == '-' && index("pr", players[i][1]) && - players[i][2] == 0 && i + 1 < playerct) { - const char *arg = players[i + 1]; - if ((players[i][1] == 'p' && - str2role(arg) == str2role(t1->plrole)) || - (players[i][1] == 'r' && - str2race(arg) == str2race(t1->plrace))) - return 1; - i++; - } else if (strcmp(players[i], "all") == 0 || - strncmp(t1->name, players[i], NAMSZ) == 0 || - (players[i][0] == '-' && - players[i][1] == t1->plrole[0] && - players[i][2] == 0) || - (digit(players[i][0]) && rank <= atoi(players[i]))) - return 1; - } - return 0; + for (i = 0; i < playerct; i++) { + if (players[i][0] == '-' && index("pr", players[i][1]) + && players[i][2] == 0 && i + 1 < playerct) { + const char *arg = players[i + 1]; + if ((players[i][1] == 'p' + && str2role(arg) == str2role(t1->plrole)) + || (players[i][1] == 'r' + && str2race(arg) == str2race(t1->plrace))) + return 1; + i++; + } else if (strcmp(players[i], "all") == 0 + || strncmp(t1->name, players[i], NAMSZ) == 0 + || (players[i][0] == '-' && players[i][1] == t1->plrole[0] + && players[i][2] == 0) + || (digit(players[i][0]) && rank <= atoi(players[i]))) + return 1; + } + return 0; } /* @@ -919,166 +950,174 @@ int uid; * and argv[1] starting with "-s". */ void -prscore(argc,argv) +prscore(argc, argv) int argc; char **argv; { - const char **players; - int playerct, rank; - boolean current_ver = TRUE, init_done = FALSE; - register struct toptenentry *t1; - FILE *rfile; - boolean match_found = FALSE; - register int i; - char pbuf[BUFSZ]; - int uid = -1; - const char *player0; + const char **players; + int playerct, rank; + boolean current_ver = TRUE, init_done = FALSE; + register struct toptenentry *t1; + FILE *rfile; + boolean match_found = FALSE; + register int i; + char pbuf[BUFSZ]; + int uid = -1; + const char *player0; - if (argc < 2 || strncmp(argv[1], "-s", 2)) { - raw_printf("prscore: bad arguments (%d)", argc); - return; - } + if (argc < 2 || strncmp(argv[1], "-s", 2)) { + raw_printf("prscore: bad arguments (%d)", argc); + return; + } - rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); - if (!rfile) { - raw_print("Cannot open record file!"); - return; - } + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); + if (!rfile) { + raw_print("Cannot open record file!"); + return; + } -#ifdef AMIGA - { - extern winid amii_rawprwin; - init_nhwindows(&argc, argv); - amii_rawprwin = create_nhwindow(NHW_TEXT); - } +#ifdef AMIGA + { + extern winid amii_rawprwin; + init_nhwindows(&argc, argv); + amii_rawprwin = create_nhwindow(NHW_TEXT); + } #endif - /* If the score list isn't after a game, we never went through - * initialization. */ - if (wiz1_level.dlevel == 0) { - dlb_init(); - init_dungeons(); - init_done = TRUE; - } + /* If the score list isn't after a game, we never went through + * initialization. */ + if (wiz1_level.dlevel == 0) { + dlb_init(); + init_dungeons(); + init_done = TRUE; + } - if (!argv[1][2]){ /* plain "-s" */ - argc--; - argv++; - } else argv[1] += 2; + if (!argv[1][2]) { /* plain "-s" */ + argc--; + argv++; + } else + argv[1] += 2; - if (argc > 1 && !strcmp(argv[1], "-v")) { - current_ver = FALSE; - argc--; - argv++; - } + if (argc > 1 && !strcmp(argv[1], "-v")) { + current_ver = FALSE; + argc--; + argv++; + } - if (argc <= 1) { - if(sysopt.pers_is_uid){ - uid = getuid(); - playerct = 0; - players = (const char **)0; - } else { - player0 = plname; - if (!*player0) -# ifdef AMIGA - player0 = "all"; /* single user system */ -# else - player0 = "hackplayer"; -# endif - playerct = 1; - players = &player0; - } - } else { - playerct = --argc; - players = (const char **)++argv; - } - raw_print(""); + if (argc <= 1) { + if (sysopt.pers_is_uid) { + uid = getuid(); + playerct = 0; + players = (const char **) 0; + } else { + player0 = plname; + if (!*player0) +#ifdef AMIGA + player0 = "all"; /* single user system */ +#else + player0 = "hackplayer"; +#endif + playerct = 1; + players = &player0; + } + } else { + playerct = --argc; + players = (const char **) ++argv; + } + raw_print(""); - t1 = tt_head = newttentry(); - for (rank = 1; ; rank++) { - readentry(rfile, t1); - if (t1->points == 0) break; - if (!match_found && - score_wanted(current_ver, rank, t1, playerct, players, uid)) - match_found = TRUE; - t1->tt_next = newttentry(); - t1 = t1->tt_next; - } + t1 = tt_head = newttentry(); + for (rank = 1;; rank++) { + readentry(rfile, t1); + if (t1->points == 0) + break; + if (!match_found + && score_wanted(current_ver, rank, t1, playerct, players, uid)) + match_found = TRUE; + t1->tt_next = newttentry(); + t1 = t1->tt_next; + } - (void) fclose(rfile); - if (init_done) { - free_dungeons(); - dlb_cleanup(); - } + (void) fclose(rfile); + if (init_done) { + free_dungeons(); + dlb_cleanup(); + } - if (match_found) { - outheader(); - t1 = tt_head; - for (rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { - if (score_wanted(current_ver, rank, t1, playerct, players, uid)) - (void) outentry(rank, t1, FALSE); - } - } else { - Sprintf(pbuf, "Cannot find any %sentries for ", - current_ver ? "current " : ""); - if (playerct < 1) Strcat(pbuf, "you."); - else { - if (playerct > 1) Strcat(pbuf, "any of "); - for (i = 0; i < playerct; i++) { - /* stop printing players if there are too many to fit */ - if (strlen(pbuf) + strlen(players[i]) + 2 >= BUFSZ) { - if (strlen(pbuf) < BUFSZ-4) Strcat(pbuf, "..."); - else Strcpy(pbuf+strlen(pbuf)-4, "..."); - break; - } - Strcat(pbuf, players[i]); - if (i < playerct-1) { - if (players[i][0] == '-' && - index("pr", players[i][1]) && players[i][2] == 0) - Strcat(pbuf, " "); - else Strcat(pbuf, ":"); - } - } - } - raw_print(pbuf); - raw_printf("Usage: %s -s [-v] [maxrank] [playernames]", + if (match_found) { + outheader(); + t1 = tt_head; + for (rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { + if (score_wanted(current_ver, rank, t1, playerct, players, uid)) + (void) outentry(rank, t1, FALSE); + } + } else { + Sprintf(pbuf, "Cannot find any %sentries for ", + current_ver ? "current " : ""); + if (playerct < 1) + Strcat(pbuf, "you."); + else { + if (playerct > 1) + Strcat(pbuf, "any of "); + for (i = 0; i < playerct; i++) { + /* stop printing players if there are too many to fit */ + if (strlen(pbuf) + strlen(players[i]) + 2 >= BUFSZ) { + if (strlen(pbuf) < BUFSZ - 4) + Strcat(pbuf, "..."); + else + Strcpy(pbuf + strlen(pbuf) - 4, "..."); + break; + } + Strcat(pbuf, players[i]); + if (i < playerct - 1) { + if (players[i][0] == '-' && index("pr", players[i][1]) + && players[i][2] == 0) + Strcat(pbuf, " "); + else + Strcat(pbuf, ":"); + } + } + } + raw_print(pbuf); + raw_printf("Usage: %s -s [-v] [maxrank] [playernames]", - hname); - raw_printf("Player types are: [-p role] [-r race]"); - } - free_ttlist(tt_head); -#ifdef AMIGA - { - extern winid amii_rawprwin; - display_nhwindow(amii_rawprwin, 1); - destroy_nhwindow(amii_rawprwin); - amii_rawprwin = WIN_ERR; - } + hname); + raw_printf("Player types are: [-p role] [-r race]"); + } + free_ttlist(tt_head); +#ifdef AMIGA + { + extern winid amii_rawprwin; + display_nhwindow(amii_rawprwin, 1); + destroy_nhwindow(amii_rawprwin); + amii_rawprwin = WIN_ERR; + } #endif } STATIC_OVL int classmon(plch, fem) - char *plch; - boolean fem; +char *plch; +boolean fem; { - int i; + int i; - /* Look for this role in the role table */ - for (i = 0; roles[i].name.m; i++) - if (!strncmp(plch, roles[i].filecode, ROLESZ)) { - if (fem && roles[i].femalenum != NON_PM) - return roles[i].femalenum; - else if (roles[i].malenum != NON_PM) - return roles[i].malenum; - else - return PM_HUMAN; - } - /* this might be from a 3.2.x score for former Elf class */ - if (!strcmp(plch, "E")) return PM_RANGER; + /* Look for this role in the role table */ + for (i = 0; roles[i].name.m; i++) + if (!strncmp(plch, roles[i].filecode, ROLESZ)) { + if (fem && roles[i].femalenum != NON_PM) + return roles[i].femalenum; + else if (roles[i].malenum != NON_PM) + return roles[i].malenum; + else + return PM_HUMAN; + } + /* this might be from a 3.2.x score for former Elf class */ + if (!strcmp(plch, "E")) + return PM_RANGER; - impossible("What weird role is this? (%s)", plch); - return (PM_HUMAN_MUMMY); + impossible("What weird role is this? (%s)", plch); + return (PM_HUMAN_MUMMY); } /* @@ -1089,43 +1128,44 @@ struct obj * tt_oname(otmp) struct obj *otmp; { - int rank; - register int i; - register struct toptenentry *tt; - FILE *rfile; - struct toptenentry tt_buf; + int rank; + register int i; + register struct toptenentry *tt; + FILE *rfile; + struct toptenentry tt_buf; - if (!otmp) return((struct obj *) 0); + if (!otmp) + return ((struct obj *) 0); - rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); - if (!rfile) { - impossible("Cannot open record file!"); - return (struct obj *)0; - } + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); + if (!rfile) { + impossible("Cannot open record file!"); + return (struct obj *) 0; + } - tt = &tt_buf; - rank = rnd(sysopt.tt_oname_maxrank); + tt = &tt_buf; + rank = rnd(sysopt.tt_oname_maxrank); pickentry: - for(i = rank; i; i--) { - readentry(rfile, tt); - if(tt->points == 0) break; - } + for (i = rank; i; i--) { + readentry(rfile, tt); + if (tt->points == 0) + break; + } - if(tt->points == 0) { - if(rank > 1) { - rank = 1; - rewind(rfile); - goto pickentry; - } - otmp = (struct obj *) 0; - } else { - set_corpsenm(otmp, - classmon(tt->plrole, (tt->plgend[0] == 'F'))); - otmp = oname(otmp, tt->name); - } + if (tt->points == 0) { + if (rank > 1) { + rank = 1; + rewind(rfile); + goto pickentry; + } + otmp = (struct obj *) 0; + } else { + set_corpsenm(otmp, classmon(tt->plrole, (tt->plgend[0] == 'F'))); + otmp = oname(otmp, tt->name); + } - (void) fclose(rfile); - return otmp; + (void) fclose(rfile); + return otmp; } #ifdef NO_SCAN_BRACK @@ -1134,16 +1174,18 @@ pickentry: /* Now generally available (KL) */ STATIC_OVL void nsb_mung_line(p) - char *p; +char *p; { - while ((p = index(p, ' ')) != 0) *p = '|'; + while ((p = index(p, ' ')) != 0) + *p = '|'; } STATIC_OVL void nsb_unmung_line(p) - char *p; +char *p; { - while ((p = index(p, '|')) != 0) *p = ' '; + while ((p = index(p, '|')) != 0) + *p = ' '; } #endif /* NO_SCAN_BRACK */ diff --git a/src/track.c b/src/track.c index 285ee28b7..b17758450 100644 --- a/src/track.c +++ b/src/track.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 track.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 track.c $NHDT-Date: 1431192763 2015/05/09 17:32:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 track.c $Date: 2009/05/06 10:48:00 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)track.c 3.5 87/08/08 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -7,7 +7,7 @@ #include "hack.h" -#define UTSZ 50 +#define UTSZ 50 STATIC_VAR NEARDATA int utcnt, utpnt; STATIC_VAR NEARDATA coord utrack[UTSZ]; @@ -15,18 +15,20 @@ STATIC_VAR NEARDATA coord utrack[UTSZ]; void initrack() { - utcnt = utpnt = 0; + utcnt = utpnt = 0; } /* add to track */ void settrack() { - if(utcnt < UTSZ) utcnt++; - if(utpnt == UTSZ) utpnt = 0; - utrack[utpnt].x = u.ux; - utrack[utpnt].y = u.uy; - utpnt++; + if (utcnt < UTSZ) + utcnt++; + if (utpnt == UTSZ) + utpnt = 0; + utrack[utpnt].x = u.ux; + utrack[utpnt].y = u.uy; + utpnt++; } coord * @@ -36,25 +38,27 @@ register int x, y; register int cnt, ndist; register coord *tc; cnt = utcnt; - for(tc = &utrack[utpnt]; cnt--; ){ - if(tc == utrack) tc = &utrack[UTSZ-1]; - else tc--; - ndist = distmin(x,y,tc->x,tc->y); + for (tc = &utrack[utpnt]; cnt--;) { + if (tc == utrack) + tc = &utrack[UTSZ - 1]; + else + tc--; + ndist = distmin(x, y, tc->x, tc->y); - /* if far away, skip track entries til we're closer */ - if(ndist > 2) { - ndist -= 2; /* be careful due to extra decrement at top of loop */ - cnt -= ndist; - if(cnt <= 0) - return (coord *) 0; /* too far away, no matches possible */ - if(tc < &utrack[ndist]) - tc += (UTSZ-ndist); - else - tc -= ndist; - } else if(ndist <= 1) - return(ndist ? tc : 0); + /* if far away, skip track entries til we're closer */ + if (ndist > 2) { + ndist -= 2; /* be careful due to extra decrement at top of loop */ + cnt -= ndist; + if (cnt <= 0) + return (coord *) 0; /* too far away, no matches possible */ + if (tc < &utrack[ndist]) + tc += (UTSZ - ndist); + else + tc -= ndist; + } else if (ndist <= 1) + return (ndist ? tc : 0); } - return (coord *)0; + return (coord *) 0; } /*track.c*/ diff --git a/src/trap.c b/src/trap.c index 7da746e2d..0870bb76c 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1,101 +1,115 @@ -/* NetHack 3.6 trap.c $NHDT-Date: 1428207616 2015/04/05 04:20:16 $ $NHDT-Branch: nhmall-booktribute $:$NHDT-Revision: 1.224 $ */ +/* NetHack 3.6 trap.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.231 $ */ /* NetHack 3.6 trap.c $Date: 2013/03/14 01:58:21 $ $Revision: 1.179 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -extern const char * const destroy_strings[][3]; /* from zap.c */ +extern const char *const destroy_strings[][3]; /* from zap.c */ STATIC_DCL void FDECL(dofiretrap, (struct obj *)); STATIC_DCL void NDECL(domagictrap); STATIC_DCL boolean FDECL(emergency_disrobe, (boolean *)); STATIC_DCL int FDECL(untrap_prob, (struct trap *)); STATIC_DCL void FDECL(move_into_trap, (struct trap *)); -STATIC_DCL int FDECL(try_disarm, (struct trap *,BOOLEAN_P)); +STATIC_DCL int FDECL(try_disarm, (struct trap *, BOOLEAN_P)); STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *)); STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *)); STATIC_DCL int FDECL(disarm_landmine, (struct trap *)); STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *)); STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int)); -STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int, BOOLEAN_P)); +STATIC_DCL int FDECL(try_lift, + (struct monst *, struct trap *, int, BOOLEAN_P)); STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *)); -STATIC_DCL boolean FDECL(thitm, (int,struct monst *,struct obj *,int,BOOLEAN_P)); +STATIC_DCL boolean +FDECL(thitm, (int, struct monst *, struct obj *, int, BOOLEAN_P)); STATIC_DCL void FDECL(launch_drop_spot, (struct obj *, XCHAR_P, XCHAR_P)); STATIC_DCL int FDECL(mkroll_launch, - (struct trap *,XCHAR_P,XCHAR_P,SHORT_P,long)); -STATIC_DCL boolean FDECL(isclearpath,(coord *, int, SCHAR_P, SCHAR_P)); -STATIC_DCL char *FDECL(trapnote, (struct trap *,BOOLEAN_P)); + (struct trap *, XCHAR_P, XCHAR_P, SHORT_P, long)); +STATIC_DCL boolean FDECL(isclearpath, (coord *, int, SCHAR_P, SCHAR_P)); +STATIC_DCL char *FDECL(trapnote, (struct trap *, BOOLEAN_P)); #if 0 STATIC_DCL void FDECL(join_adjacent_pits, (struct trap *)); #endif STATIC_DCL void FDECL(clear_conjoined_pits, (struct trap *)); STATIC_DCL int FDECL(steedintrap, (struct trap *, struct obj *)); -STATIC_DCL boolean FDECL(keep_saddle_with_steedcorpse, - (unsigned, struct obj *, struct obj *)); +STATIC_DCL boolean +FDECL(keep_saddle_with_steedcorpse, (unsigned, struct obj *, struct obj *)); STATIC_DCL void NDECL(maybe_finish_sokoban); /* mintrap() should take a flags argument, but for time being we use this */ STATIC_VAR int force_mintrap = 0; -STATIC_VAR const char * const a_your[2] = { "a", "your" }; -STATIC_VAR const char * const A_Your[2] = { "A", "Your" }; +STATIC_VAR const char *const a_your[2] = { "a", "your" }; +STATIC_VAR const char *const A_Your[2] = { "A", "Your" }; STATIC_VAR const char tower_of_flame[] = "tower of flame"; -STATIC_VAR const char * const A_gush_of_water_hits = "A gush of water hits"; -STATIC_VAR const char * const blindgas[6] = - {"humid", "odorless", "pungent", "chilling", "acrid", "biting"}; +STATIC_VAR const char *const A_gush_of_water_hits = "A gush of water hits"; +STATIC_VAR const char *const blindgas[6] = { "humid", "odorless", + "pungent", "chilling", + "acrid", "biting" }; /* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode) */ -boolean /* returns TRUE if hit on torso */ -burnarmor(victim) +boolean /* returns TRUE if hit on torso */ + burnarmor(victim) struct monst *victim; { struct obj *item; char buf[BUFSZ]; int mat_idx; - - if (!victim) return 0; -#define burn_dmg(obj,descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE) + + if (!victim) + return 0; +#define burn_dmg(obj, descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE) while (1) { - switch (rn2(5)) { - case 0: - item = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH); - if (item) { - mat_idx = objects[item->otyp].oc_material; - Sprintf(buf,"%s %s", - materialnm[mat_idx], helm_simple_name(item)); - } - if (!burn_dmg(item, item ? buf : "helmet")) continue; - break; - case 1: - item = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC); - if (item) { - (void) burn_dmg(item, cloak_simple_name(item)); - return TRUE; - } - item = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM); - if (item) { - (void) burn_dmg(item, xname(item)); - return TRUE; - } - item = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU); - if (item) - (void) burn_dmg(item, "shirt"); - return TRUE; - case 2: - item = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS); - if (!burn_dmg(item, "wooden shield")) continue; - break; - case 3: - item = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG); - if (!burn_dmg(item, "gloves")) continue; - break; - case 4: - item = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF); - if (!burn_dmg(item, "boots")) continue; - break; - } - break; /* Out of while loop */ + switch (rn2(5)) { + case 0: + item = + (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH); + if (item) { + mat_idx = objects[item->otyp].oc_material; + Sprintf(buf, "%s %s", materialnm[mat_idx], + helm_simple_name(item)); + } + if (!burn_dmg(item, item ? buf : "helmet")) + continue; + break; + case 1: + item = + (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC); + if (item) { + (void) burn_dmg(item, cloak_simple_name(item)); + return TRUE; + } + item = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM); + if (item) { + (void) burn_dmg(item, xname(item)); + return TRUE; + } + item = + (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU); + if (item) + (void) burn_dmg(item, "shirt"); + return TRUE; + case 2: + item = + (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS); + if (!burn_dmg(item, "wooden shield")) + continue; + break; + case 3: + item = + (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG); + if (!burn_dmg(item, "gloves")) + continue; + break; + case 4: + item = + (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF); + if (!burn_dmg(item, "boots")) + continue; + break; + } + break; /* Out of while loop */ } return FALSE; #undef burn_dmg @@ -116,384 +130,392 @@ register const char *ostr; int type; int ef_flags; { - static NEARDATA const char * const action[] = { "smoulder", "rust", "rot", "corrode" }; - static NEARDATA const char * const msg[] = { "burnt", "rusted", "rotten", "corroded" }; - boolean vulnerable = FALSE; - boolean is_primary = TRUE; - boolean check_grease = ef_flags & EF_GREASE; - boolean print = ef_flags & EF_VERBOSE; - int erosion; - struct monst *victim; - boolean vismon; - boolean visobj; - int cost_type; + static NEARDATA const char *const action[] = { "smoulder", "rust", "rot", + "corrode" }; + static NEARDATA const char *const msg[] = { "burnt", "rusted", "rotten", + "corroded" }; + boolean vulnerable = FALSE; + boolean is_primary = TRUE; + boolean check_grease = ef_flags & EF_GREASE; + boolean print = ef_flags & EF_VERBOSE; + int erosion; + struct monst *victim; + boolean vismon; + boolean visobj; + int cost_type; - if (!otmp) return ER_NOTHING; + if (!otmp) + return ER_NOTHING; - victim = carried(otmp) ? &youmonst : mcarried(otmp) ? - otmp->ocarry : NULL; - vismon = victim && (victim != &youmonst) && canseemon(victim); - /* Is bhitpos correct here? Ugh. */ - visobj = !victim && cansee(bhitpos.x, bhitpos.y); + victim = carried(otmp) ? &youmonst : mcarried(otmp) ? otmp->ocarry : NULL; + vismon = victim && (victim != &youmonst) && canseemon(victim); + /* Is bhitpos correct here? Ugh. */ + visobj = !victim && cansee(bhitpos.x, bhitpos.y); - switch(type) { - case ERODE_BURN: - vulnerable = is_flammable(otmp); - check_grease = FALSE; - cost_type = COST_BURN; - break; - case ERODE_RUST: - vulnerable = is_rustprone(otmp); - cost_type = COST_RUST; - break; - case ERODE_ROT: - vulnerable = is_rottable(otmp); - check_grease = FALSE; - is_primary = FALSE; - cost_type = COST_ROT; - break; - case ERODE_CORRODE: - vulnerable = is_corrodeable(otmp); - is_primary = FALSE; - cost_type = COST_CORRODE; - break; - default: - impossible("Invalid erosion type in erode_obj"); - return ER_NOTHING; - } - erosion = is_primary ? otmp->oeroded : otmp->oeroded2; + switch (type) { + case ERODE_BURN: + vulnerable = is_flammable(otmp); + check_grease = FALSE; + cost_type = COST_BURN; + break; + case ERODE_RUST: + vulnerable = is_rustprone(otmp); + cost_type = COST_RUST; + break; + case ERODE_ROT: + vulnerable = is_rottable(otmp); + check_grease = FALSE; + is_primary = FALSE; + cost_type = COST_ROT; + break; + case ERODE_CORRODE: + vulnerable = is_corrodeable(otmp); + is_primary = FALSE; + cost_type = COST_CORRODE; + break; + default: + impossible("Invalid erosion type in erode_obj"); + return ER_NOTHING; + } + erosion = is_primary ? otmp->oeroded : otmp->oeroded2; - if (!ostr) - ostr = cxname(otmp); - - if (check_grease && otmp->greased) { - grease_protect(otmp, ostr, victim); - return ER_GREASED; - } else if (!vulnerable || (otmp->oerodeproof && otmp->rknown)) { - if (print && flags.verbose) { - if (victim == &youmonst) - Your("%s %s not affected.", ostr, vtense(ostr, "are")); - else if (vismon) - pline("%s %s %s not affected.", s_suffix(Monnam(victim)), - ostr, vtense(ostr, "are")); - } - return ER_NOTHING; - } else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) { - if (flags.verbose && (print || otmp->oerodeproof)) { - if (victim == &youmonst) - pline("Somehow, your %s %s not affected.", - ostr, vtense(ostr, "are")); - else if (vismon) - pline("Somehow, %s %s %s not affected.", - s_suffix(mon_nam(victim)), ostr, - vtense(ostr, "are")); - else if (visobj) - pline("Somehow, the %s %s not affected.", ostr, - vtense(ostr, "are")); - } - /* We assume here that if the object is protected because it - * is blessed, it still shows some minor signs of wear, and - * the hero can distinguish this from an object that is - * actually proof against damage. */ - if (otmp->oerodeproof) { - otmp->rknown = TRUE; - if (victim == &youmonst) - update_inventory(); - } - - return ER_NOTHING; - } else if (erosion < MAX_ERODE) { - const char *adverb = (erosion + 1 == MAX_ERODE) ? - " completely" : erosion ? " further" : ""; + if (!ostr) + ostr = cxname(otmp); + if (check_grease && otmp->greased) { + grease_protect(otmp, ostr, victim); + return ER_GREASED; + } else if (!vulnerable || (otmp->oerodeproof && otmp->rknown)) { + if (print && flags.verbose) { if (victim == &youmonst) - Your("%s %s%s!", ostr, vtense(ostr, action[type]), adverb); + Your("%s %s not affected.", ostr, vtense(ostr, "are")); else if (vismon) - pline("%s %s %s%s!", s_suffix(Monnam(victim)), ostr, - vtense(ostr, action[type]), adverb); + pline("%s %s %s not affected.", s_suffix(Monnam(victim)), + ostr, vtense(ostr, "are")); + } + return ER_NOTHING; + } else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) { + if (flags.verbose && (print || otmp->oerodeproof)) { + if (victim == &youmonst) + pline("Somehow, your %s %s not affected.", ostr, + vtense(ostr, "are")); + else if (vismon) + pline("Somehow, %s %s %s not affected.", + s_suffix(mon_nam(victim)), ostr, vtense(ostr, "are")); else if (visobj) - pline("The %s %s%s!", ostr, vtense(ostr, action[type]), adverb); - - if (ef_flags & EF_PAY) - costly_alteration(otmp, cost_type); - - if (is_primary) - otmp->oeroded++; - else - otmp->oeroded2++; - + pline("Somehow, the %s %s not affected.", ostr, + vtense(ostr, "are")); + } + /* We assume here that if the object is protected because it + * is blessed, it still shows some minor signs of wear, and + * the hero can distinguish this from an object that is + * actually proof against damage. */ + if (otmp->oerodeproof) { + otmp->rknown = TRUE; if (victim == &youmonst) update_inventory(); + } - return ER_DAMAGED; - } else if (ef_flags & EF_DESTROY) { + return ER_NOTHING; + } else if (erosion < MAX_ERODE) { + const char *adverb = (erosion + 1 == MAX_ERODE) + ? " completely" + : erosion ? " further" : ""; + + if (victim == &youmonst) + Your("%s %s%s!", ostr, vtense(ostr, action[type]), adverb); + else if (vismon) + pline("%s %s %s%s!", s_suffix(Monnam(victim)), ostr, + vtense(ostr, action[type]), adverb); + else if (visobj) + pline("The %s %s%s!", ostr, vtense(ostr, action[type]), adverb); + + if (ef_flags & EF_PAY) + costly_alteration(otmp, cost_type); + + if (is_primary) + otmp->oeroded++; + else + otmp->oeroded2++; + + if (victim == &youmonst) + update_inventory(); + + return ER_DAMAGED; + } else if (ef_flags & EF_DESTROY) { + if (victim == &youmonst) + Your("%s %s away!", ostr, vtense(ostr, action[type])); + else if (vismon) + pline("%s %s %s away!", s_suffix(Monnam(victim)), ostr, + vtense(ostr, action[type])); + else if (visobj) + pline("The %s %s away!", ostr, vtense(ostr, action[type])); + + if (ef_flags & EF_PAY) + costly_alteration(otmp, cost_type); + + setnotworn(otmp); + delobj(otmp); + return ER_DESTROYED; + } else { + if (flags.verbose && print) { if (victim == &youmonst) - Your("%s %s away!", ostr, vtense(ostr, action[type])); + Your("%s %s completely %s.", ostr, + vtense(ostr, Blind ? "feel" : "look"), msg[type]); else if (vismon) - pline("%s %s %s away!", s_suffix(Monnam(victim)), ostr, - vtense(ostr, action[type])); + pline("%s %s %s completely %s.", s_suffix(Monnam(victim)), + ostr, vtense(ostr, "look"), msg[type]); else if (visobj) - pline("The %s %s away!", ostr, vtense(ostr, action[type])); - - if (ef_flags & EF_PAY) - costly_alteration(otmp, cost_type); - - setnotworn(otmp); - delobj(otmp); - return ER_DESTROYED; - } else { - if (flags.verbose && print) { - if (victim == &youmonst) - Your("%s %s completely %s.", ostr, - vtense(ostr, Blind ? "feel" : "look"), - msg[type]); - else if (vismon) - pline("%s %s %s completely %s.", - s_suffix(Monnam(victim)), ostr, - vtense(ostr, "look"), msg[type]); - else if (visobj) - pline("The %s %s completely %s.", ostr, - vtense(ostr, "look"), msg[type]); - } - return ER_NOTHING; - } + pline("The %s %s completely %s.", ostr, vtense(ostr, "look"), + msg[type]); + } + return ER_NOTHING; + } } /* Protect an item from erosion with grease. Returns TRUE if the grease * wears off. */ boolean -grease_protect(otmp,ostr,victim) +grease_protect(otmp, ostr, victim) register struct obj *otmp; register const char *ostr; struct monst *victim; { - static const char txt[] = "protected by the layer of grease!"; - boolean vismon = victim && (victim != &youmonst) && canseemon(victim); + static const char txt[] = "protected by the layer of grease!"; + boolean vismon = victim && (victim != &youmonst) && canseemon(victim); - if (ostr) { - if (victim == &youmonst) - Your("%s %s %s", ostr, vtense(ostr, "are"), txt); - else if (vismon) - pline("%s's %s %s %s", Monnam(victim), - ostr, vtense(ostr, "are"), txt); - } else if ((victim == &youmonst) || vismon) { - pline("%s %s", Yobjnam2(otmp, "are"), txt); - } - if (!rn2(2)) { - otmp->greased = 0; - if (carried(otmp)) { - pline_The("grease dissolves."); - update_inventory(); - } - return TRUE; - } - return FALSE; + if (ostr) { + if (victim == &youmonst) + Your("%s %s %s", ostr, vtense(ostr, "are"), txt); + else if (vismon) + pline("%s's %s %s %s", Monnam(victim), ostr, vtense(ostr, "are"), + txt); + } else if ((victim == &youmonst) || vismon) { + pline("%s %s", Yobjnam2(otmp, "are"), txt); + } + if (!rn2(2)) { + otmp->greased = 0; + if (carried(otmp)) { + pline_The("grease dissolves."); + update_inventory(); + } + return TRUE; + } + return FALSE; } struct trap * -maketrap(x,y,typ) +maketrap(x, y, typ) register int x, y, typ; { - register struct trap *ttmp; - register struct rm *lev; - register boolean oldplace; + register struct trap *ttmp; + register struct rm *lev; + register boolean oldplace; - if ((ttmp = t_at(x,y)) != 0) { - if (ttmp->ttyp == MAGIC_PORTAL) return (struct trap *)0; - oldplace = TRUE; - if (u.utrap && (x == u.ux) && (y == u.uy) && - ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP) || - (u.utraptype == TT_WEB && typ != WEB) || - (u.utraptype == TT_PIT && typ != PIT && typ != SPIKED_PIT))) - u.utrap = 0; - } else { - oldplace = FALSE; - ttmp = newtrap(); - ttmp->tx = x; - ttmp->ty = y; - ttmp->launch.x = -1; /* force error if used before set */ - ttmp->launch.y = -1; - } - ttmp->ttyp = typ; - switch(typ) { - case SQKY_BOARD: - { - int tavail[12], tpick[12], tcnt = 0, k; - struct trap *t; + if ((ttmp = t_at(x, y)) != 0) { + if (ttmp->ttyp == MAGIC_PORTAL) + return (struct trap *) 0; + oldplace = TRUE; + if (u.utrap && (x == u.ux) && (y == u.uy) + && ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP) + || (u.utraptype == TT_WEB && typ != WEB) + || (u.utraptype == TT_PIT && typ != PIT + && typ != SPIKED_PIT))) + u.utrap = 0; + } else { + oldplace = FALSE; + ttmp = newtrap(); + ttmp->tx = x; + ttmp->ty = y; + ttmp->launch.x = -1; /* force error if used before set */ + ttmp->launch.y = -1; + } + ttmp->ttyp = typ; + switch (typ) { + case SQKY_BOARD: { + int tavail[12], tpick[12], tcnt = 0, k; + struct trap *t; - for (k = 0; k < 12; ++k) - tavail[k] = 0; - for (t = ftrap; t; t = t->ntrap) - if (t->ttyp == SQKY_BOARD) - tavail[t->tnote] = 1; + for (k = 0; k < 12; ++k) + tavail[k] = 0; + for (t = ftrap; t; t = t->ntrap) + if (t->ttyp == SQKY_BOARD) + tavail[t->tnote] = 1; - /* Now populate tpick with the available indexes */ - for (k = 0; k < 12; ++k) { - if (tavail[k] == 0) - tpick[tcnt++] = k; - } - if (tcnt > 0) - ttmp->tnote = (short)tpick[rn2(tcnt)]; - else - ttmp->tnote = (short)rn2(12); /* all in use anyway */ - break; - } - case STATUE_TRAP: /* create a "living" statue */ - { struct monst *mtmp; - struct obj *otmp, *statue; - struct permonst *mptr; - int trycount = 10; + /* Now populate tpick with the available indexes */ + for (k = 0; k < 12; ++k) { + if (tavail[k] == 0) + tpick[tcnt++] = k; + } + if (tcnt > 0) + ttmp->tnote = (short) tpick[rn2(tcnt)]; + else + ttmp->tnote = (short) rn2(12); /* all in use anyway */ + break; + } + case STATUE_TRAP: /* create a "living" statue */ + { + struct monst *mtmp; + struct obj *otmp, *statue; + struct permonst *mptr; + int trycount = 10; - do { /* avoid ultimately hostile co-aligned unicorn */ - mptr = &mons[rndmonnum()]; - } while (--trycount > 0 && is_unicorn(mptr) && - sgn(u.ualign.type) == sgn(mptr->maligntyp)); - statue = mkcorpstat(STATUE, (struct monst *)0, - mptr, x, y, CORPSTAT_NONE); - mtmp = makemon(&mons[statue->corpsenm], 0, 0, MM_NOCOUNTBIRTH); - if (!mtmp) break; /* should never happen */ - while(mtmp->minvent) { - otmp = mtmp->minvent; - otmp->owornmask = 0; - obj_extract_self(otmp); - (void) add_to_container(statue, otmp); - } - statue->owt = weight(statue); - mongone(mtmp); - break; - } - case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */ - (void) mkroll_launch(ttmp, x, y, BOULDER, 1L); - break; - case PIT: - case SPIKED_PIT: - ttmp->conjoined = 0; - /* fall through */ - case HOLE: - case TRAPDOOR: - lev = &levl[x][y]; - if (*in_rooms(x, y, SHOPBASE) && - ((typ == HOLE || typ == TRAPDOOR) || - IS_DOOR(lev->typ) || IS_WALL(lev->typ))) - add_damage(x, y, /* schedule repair */ - ((IS_DOOR(lev->typ) || IS_WALL(lev->typ)) - && !context.mon_moving) ? 200L : 0L); - lev->doormask = 0; /* subsumes altarmask, icedpool... */ - if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */ - lev->typ = ROOM; + do { /* avoid ultimately hostile co-aligned unicorn */ + mptr = &mons[rndmonnum()]; + } while (--trycount > 0 && is_unicorn(mptr) + && sgn(u.ualign.type) == sgn(mptr->maligntyp)); + statue = + mkcorpstat(STATUE, (struct monst *) 0, mptr, x, y, CORPSTAT_NONE); + mtmp = makemon(&mons[statue->corpsenm], 0, 0, MM_NOCOUNTBIRTH); + if (!mtmp) + break; /* should never happen */ + while (mtmp->minvent) { + otmp = mtmp->minvent; + otmp->owornmask = 0; + obj_extract_self(otmp); + (void) add_to_container(statue, otmp); + } + statue->owt = weight(statue); + mongone(mtmp); + break; + } + case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */ + (void) mkroll_launch(ttmp, x, y, BOULDER, 1L); + break; + case PIT: + case SPIKED_PIT: + ttmp->conjoined = 0; + /* fall through */ + case HOLE: + case TRAPDOOR: + lev = &levl[x][y]; + if (*in_rooms(x, y, SHOPBASE) + && ((typ == HOLE || typ == TRAPDOOR) || IS_DOOR(lev->typ) + || IS_WALL(lev->typ))) + add_damage(x, y, /* schedule repair */ + ((IS_DOOR(lev->typ) || IS_WALL(lev->typ)) + && !context.mon_moving) + ? 200L + : 0L); + lev->doormask = 0; /* subsumes altarmask, icedpool... */ + if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */ + lev->typ = ROOM; - /* - * some cases which can happen when digging - * down while phazing thru solid areas - */ - else if (lev->typ == STONE || lev->typ == SCORR) - lev->typ = CORR; - else if (IS_WALL(lev->typ) || lev->typ == SDOOR) - lev->typ = level.flags.is_maze_lev ? ROOM : - level.flags.is_cavernous_lev ? CORR : DOOR; + /* + * some cases which can happen when digging + * down while phazing thru solid areas + */ + else if (lev->typ == STONE || lev->typ == SCORR) + lev->typ = CORR; + else if (IS_WALL(lev->typ) || lev->typ == SDOOR) + lev->typ = level.flags.is_maze_lev + ? ROOM + : level.flags.is_cavernous_lev ? CORR : DOOR; - unearth_objs(x, y); - break; - } - ttmp->tseen = (ttmp->ttyp == HOLE); /* hide non-holes */ - ttmp->once = 0; - ttmp->madeby_u = 0; - ttmp->dst.dnum = -1; - ttmp->dst.dlevel = -1; - if (!oldplace) { - ttmp->ntrap = ftrap; - ftrap = ttmp; - } else { - /* oldplace; - it shouldn't be possible to override a sokoban pit or hole - with some other trap, but we'll check just to be safe */ - if (Sokoban) maybe_finish_sokoban(); - } - return(ttmp); + unearth_objs(x, y); + break; + } + ttmp->tseen = (ttmp->ttyp == HOLE); /* hide non-holes */ + ttmp->once = 0; + ttmp->madeby_u = 0; + ttmp->dst.dnum = -1; + ttmp->dst.dlevel = -1; + if (!oldplace) { + ttmp->ntrap = ftrap; + ftrap = ttmp; + } else { + /* oldplace; + it shouldn't be possible to override a sokoban pit or hole + with some other trap, but we'll check just to be safe */ + if (Sokoban) + maybe_finish_sokoban(); + } + return (ttmp); } void fall_through(td) -boolean td; /* td == TRUE : trap door or hole */ +boolean td; /* td == TRUE : trap door or hole */ { - d_level dtmp; - char msgbuf[BUFSZ]; - const char *dont_fall = 0; - int newlevel, bottom; + d_level dtmp; + char msgbuf[BUFSZ]; + const char *dont_fall = 0; + int newlevel, bottom; - /* we'll fall even while levitating in Sokoban; otherwise, if we - won't fall and won't be told that we aren't falling, give up now */ - if (Blind && Levitation && !Sokoban) return; + /* we'll fall even while levitating in Sokoban; otherwise, if we + won't fall and won't be told that we aren't falling, give up now */ + if (Blind && Levitation && !Sokoban) + return; - bottom = dunlevs_in_dungeon(&u.uz); - /* when in the upper half of the quest, don't fall past the - middle "quest locate" level if hero hasn't been there yet */ - if (In_quest(&u.uz)) { - int qlocate_depth = qlocate_level.dlevel; + bottom = dunlevs_in_dungeon(&u.uz); + /* when in the upper half of the quest, don't fall past the + middle "quest locate" level if hero hasn't been there yet */ + if (In_quest(&u.uz)) { + int qlocate_depth = qlocate_level.dlevel; - /* deepest reached < qlocate implies current < qlocate */ - if (dunlev_reached(&u.uz) < qlocate_depth) - bottom = qlocate_depth; /* early cut-off */ - } - newlevel = dunlev(&u.uz); /* current level */ - do { - newlevel++; - } while (!rn2(4) && newlevel < bottom); + /* deepest reached < qlocate implies current < qlocate */ + if (dunlev_reached(&u.uz) < qlocate_depth) + bottom = qlocate_depth; /* early cut-off */ + } + newlevel = dunlev(&u.uz); /* current level */ + do { + newlevel++; + } while (!rn2(4) && newlevel < bottom); - if(td) { - struct trap *t = t_at(u.ux,u.uy); + if (td) { + struct trap *t = t_at(u.ux, u.uy); - feeltrap(t); - if (!Sokoban) { - if (t->ttyp == TRAPDOOR) - pline("A trap door opens up under you!"); - else - pline("There's a gaping hole under you!"); - } - } else pline_The("%s opens up under you!", surface(u.ux,u.uy)); + feeltrap(t); + if (!Sokoban) { + if (t->ttyp == TRAPDOOR) + pline("A trap door opens up under you!"); + else + pline("There's a gaping hole under you!"); + } + } else + pline_The("%s opens up under you!", surface(u.ux, u.uy)); - if (Sokoban && Can_fall_thru(&u.uz)) - ; /* KMH -- You can't escape the Sokoban level traps */ - else if(Levitation || u.ustuck - || (!Can_fall_thru(&u.uz) && !levl[u.ux][u.uy].candig) - || Flying || is_clinger(youmonst.data) - || (Inhell && !u.uevent.invoked && newlevel == bottom) - ) { - dont_fall = "don't fall in."; - } else if (youmonst.data->msize >= MZ_HUGE) { - dont_fall = "don't fit through."; - } else if (!next_to_u()) { - dont_fall = "are jerked back by your pet!"; - } - if (dont_fall) { - You1(dont_fall); - /* hero didn't fall through, but any objects here might */ - impact_drop((struct obj *)0, u.ux, u.uy, 0); - if (!td) { - display_nhwindow(WIN_MESSAGE, FALSE); - pline_The("opening under you closes up."); - } - return; - } + if (Sokoban && Can_fall_thru(&u.uz)) + ; /* KMH -- You can't escape the Sokoban level traps */ + else if (Levitation || u.ustuck + || (!Can_fall_thru(&u.uz) && !levl[u.ux][u.uy].candig) || Flying + || is_clinger(youmonst.data) + || (Inhell && !u.uevent.invoked && newlevel == bottom)) { + dont_fall = "don't fall in."; + } else if (youmonst.data->msize >= MZ_HUGE) { + dont_fall = "don't fit through."; + } else if (!next_to_u()) { + dont_fall = "are jerked back by your pet!"; + } + if (dont_fall) { + You1(dont_fall); + /* hero didn't fall through, but any objects here might */ + impact_drop((struct obj *) 0, u.ux, u.uy, 0); + if (!td) { + display_nhwindow(WIN_MESSAGE, FALSE); + pline_The("opening under you closes up."); + } + return; + } - if(*u.ushops) shopdig(1); - if (Is_stronghold(&u.uz)) { - find_hell(&dtmp); - } else { - int dist = newlevel - dunlev(&u.uz); - dtmp.dnum = u.uz.dnum; - dtmp.dlevel = newlevel; - if (dist > 1) - You("fall down a %s%sshaft!", - dist > 3 ? "very " : "", - dist > 2 ? "deep " : ""); - } - if (!td) - Sprintf(msgbuf, "The hole in the %s above you closes up.", - ceiling(u.ux,u.uy)); - schedule_goto(&dtmp, FALSE, TRUE, 0, - (char *)0, !td ? msgbuf : (char *)0); + if (*u.ushops) + shopdig(1); + if (Is_stronghold(&u.uz)) { + find_hell(&dtmp); + } else { + int dist = newlevel - dunlev(&u.uz); + dtmp.dnum = u.uz.dnum; + dtmp.dlevel = newlevel; + if (dist > 1) + You("fall down a %s%sshaft!", dist > 3 ? "very " : "", + dist > 2 ? "deep " : ""); + } + if (!td) + Sprintf(msgbuf, "The hole in the %s above you closes up.", + ceiling(u.ux, u.uy)); + schedule_goto(&dtmp, FALSE, TRUE, 0, (char *) 0, + !td ? msgbuf : (char *) 0); } /* @@ -530,162 +552,172 @@ xchar x, y; int cause; int *fail_reason; { - int mnum = statue->corpsenm; - struct permonst *mptr = &mons[mnum]; - struct monst *mon = 0, *shkp; - struct obj *item; - coord cc; - boolean historic = (Role_if(PM_ARCHEOLOGIST) && - (statue->spe & STATUE_HISTORIC) != 0), - golem_xform = FALSE, use_saved_traits; - const char *comes_to_life; - char statuename[BUFSZ], tmpbuf[BUFSZ]; - static const char historic_statue_is_gone[] = - "that the historic statue is now gone"; + int mnum = statue->corpsenm; + struct permonst *mptr = &mons[mnum]; + struct monst *mon = 0, *shkp; + struct obj *item; + coord cc; + boolean historic = (Role_if(PM_ARCHEOLOGIST) + && (statue->spe & STATUE_HISTORIC) != 0), + golem_xform = FALSE, use_saved_traits; + const char *comes_to_life; + char statuename[BUFSZ], tmpbuf[BUFSZ]; + static const char historic_statue_is_gone[] = + "that the historic statue is now gone"; - if (cant_revive(&mnum, TRUE, statue)) { - /* mnum has changed; we won't be animating this statue as itself */ - if (mnum != PM_DOPPELGANGER) mptr = &mons[mnum]; - use_saved_traits = FALSE; - } else if (is_golem(mptr) && cause == ANIMATE_SPELL) { - /* statue of any golem hit by stone-to-flesh becomes flesh golem */ - golem_xform = (mptr != &mons[PM_FLESH_GOLEM]); - mnum = PM_FLESH_GOLEM; - mptr = &mons[PM_FLESH_GOLEM]; - use_saved_traits = (has_omonst(statue) && !golem_xform); - } else { - use_saved_traits = has_omonst(statue); - } + if (cant_revive(&mnum, TRUE, statue)) { + /* mnum has changed; we won't be animating this statue as itself */ + if (mnum != PM_DOPPELGANGER) + mptr = &mons[mnum]; + use_saved_traits = FALSE; + } else if (is_golem(mptr) && cause == ANIMATE_SPELL) { + /* statue of any golem hit by stone-to-flesh becomes flesh golem */ + golem_xform = (mptr != &mons[PM_FLESH_GOLEM]); + mnum = PM_FLESH_GOLEM; + mptr = &mons[PM_FLESH_GOLEM]; + use_saved_traits = (has_omonst(statue) && !golem_xform); + } else { + use_saved_traits = has_omonst(statue); + } - if (use_saved_traits) { - /* restore a petrified monster */ - cc.x = x, cc.y = y; - mon = montraits(statue, &cc); - if (mon && mon->mtame && !mon->isminion) - wary_dog(mon, TRUE); - } else { - /* statues of unique monsters from bones or wishing end - up here (cant_revive() sets mnum to be doppelganger; - mptr reflects the original form for use by newcham()) */ - if ((mnum == PM_DOPPELGANGER && - mptr != &mons[PM_DOPPELGANGER]) || - /* block quest guards from other roles */ - (mptr->msound == MS_GUARDIAN && - quest_info(MS_GUARDIAN) != mnum)) { - mon = makemon(&mons[PM_DOPPELGANGER], x, y, - NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK); - /* if hero has protection from shape changers, cham field will - be NON_PM; otherwise, set form to match the statue */ - if (mon && mon->cham >= LOW_PM) - (void) newcham(mon, mptr, FALSE, FALSE); - } else - mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL) ? - (NO_MINVENT | MM_ADJACENTOK) : NO_MINVENT); - } + if (use_saved_traits) { + /* restore a petrified monster */ + cc.x = x, cc.y = y; + mon = montraits(statue, &cc); + if (mon && mon->mtame && !mon->isminion) + wary_dog(mon, TRUE); + } else { + /* statues of unique monsters from bones or wishing end + up here (cant_revive() sets mnum to be doppelganger; + mptr reflects the original form for use by newcham()) */ + if ((mnum == PM_DOPPELGANGER && mptr != &mons[PM_DOPPELGANGER]) || + /* block quest guards from other roles */ + (mptr->msound == MS_GUARDIAN + && quest_info(MS_GUARDIAN) != mnum)) { + mon = makemon(&mons[PM_DOPPELGANGER], x, y, + NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK); + /* if hero has protection from shape changers, cham field will + be NON_PM; otherwise, set form to match the statue */ + if (mon && mon->cham >= LOW_PM) + (void) newcham(mon, mptr, FALSE, FALSE); + } else + mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL) + ? (NO_MINVENT | MM_ADJACENTOK) + : NO_MINVENT); + } - if (!mon) { - if (fail_reason) - *fail_reason = unique_corpstat(&mons[statue->corpsenm]) ? - AS_MON_IS_UNIQUE : AS_NO_MON; - return (struct monst *)0; - } + if (!mon) { + if (fail_reason) + *fail_reason = unique_corpstat(&mons[statue->corpsenm]) + ? AS_MON_IS_UNIQUE + : AS_NO_MON; + return (struct monst *) 0; + } - /* a non-montraits() statue might specify gender */ - if (statue->spe & STATUE_MALE) - mon->female = FALSE; - else if (statue->spe & STATUE_FEMALE) - mon->female = TRUE; - /* if statue has been named, give same name to the monster */ - if (has_oname(statue)) - mon = christen_monst(mon, ONAME(statue)); - /* mimic statue becomes seen mimic; other hiders won't be hidden */ - if (mon->m_ap_type) seemimic(mon); - else mon->mundetected = FALSE; - mon->msleeping = 0; - if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) { - /* trap always releases hostile monster */ - mon->mtame = 0; /* (might be petrified pet tossed onto trap) */ - mon->mpeaceful = 0; - set_malign(mon); - } + /* a non-montraits() statue might specify gender */ + if (statue->spe & STATUE_MALE) + mon->female = FALSE; + else if (statue->spe & STATUE_FEMALE) + mon->female = TRUE; + /* if statue has been named, give same name to the monster */ + if (has_oname(statue)) + mon = christen_monst(mon, ONAME(statue)); + /* mimic statue becomes seen mimic; other hiders won't be hidden */ + if (mon->m_ap_type) + seemimic(mon); + else + mon->mundetected = FALSE; + mon->msleeping = 0; + if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) { + /* trap always releases hostile monster */ + mon->mtame = 0; /* (might be petrified pet tossed onto trap) */ + mon->mpeaceful = 0; + set_malign(mon); + } - comes_to_life = !canspotmon(mon) ? "disappears" : - golem_xform ? "turns into flesh" : - (nonliving(mon->data) || is_vampshifter(mon)) ? - "moves" : "comes to life"; - if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) { - /* "the|your|Manlobbi's statue [of a wombat]" */ - shkp = shop_keeper(*in_rooms(mon->mx, mon->my, SHOPBASE)); - Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), - (cause == ANIMATE_SPELL && - /* avoid "of a shopkeeper" if it's Manlobbi himself - (if carried, it can't be unpaid--hence won't be - described as "Manlobbi's statue"--because there - wasn't any living shk when statue was picked up) */ - (mon != shkp || carried(statue))) ? xname(statue) : - "statue"); - pline("%s %s!", upstart(statuename), comes_to_life); - } else if (Hallucination) { /* They don't know it's a statue */ - pline_The("%s suddenly seems more animated.", rndmonnam(NULL)); - } else if (cause == ANIMATE_SHATTER) { - if (cansee(x, y)) - Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), - xname(statue)); - else - Strcpy(statuename, "a statue"); - pline("Instead of shattering, %s suddenly %s!", - statuename, comes_to_life); - } else { /* cause == ANIMATE_NORMAL */ - You("find %s posing as a statue.", - canspotmon(mon) ? a_monnam(mon) : something); - if (!canspotmon(mon) && Blind) - map_invisible(x,y); - stop_occupation(); - } + comes_to_life = !canspotmon(mon) + ? "disappears" + : golem_xform + ? "turns into flesh" + : (nonliving(mon->data) || is_vampshifter(mon)) + ? "moves" + : "comes to life"; + if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) { + /* "the|your|Manlobbi's statue [of a wombat]" */ + shkp = shop_keeper(*in_rooms(mon->mx, mon->my, SHOPBASE)); + Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), + (cause == ANIMATE_SPELL && + /* avoid "of a shopkeeper" if it's Manlobbi himself + (if carried, it can't be unpaid--hence won't be + described as "Manlobbi's statue"--because there + wasn't any living shk when statue was picked up) */ + (mon != shkp || carried(statue))) + ? xname(statue) + : "statue"); + pline("%s %s!", upstart(statuename), comes_to_life); + } else if (Hallucination) { /* They don't know it's a statue */ + pline_The("%s suddenly seems more animated.", rndmonnam(NULL)); + } else if (cause == ANIMATE_SHATTER) { + if (cansee(x, y)) + Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), + xname(statue)); + else + Strcpy(statuename, "a statue"); + pline("Instead of shattering, %s suddenly %s!", statuename, + comes_to_life); + } else { /* cause == ANIMATE_NORMAL */ + You("find %s posing as a statue.", + canspotmon(mon) ? a_monnam(mon) : something); + if (!canspotmon(mon) && Blind) + map_invisible(x, y); + stop_occupation(); + } - /* if this isn't caused by a monster using a wand of striking, - there might be consequences for the hero */ - if (!context.mon_moving) { - /* if statue is owned by a shop, hero will have to pay for it; - stolen_value gives a message (about debt or use of credit) - which refers to "it" so needs to follow a message describing - the object ("the statue comes to life" one above) */ - if (cause != ANIMATE_NORMAL && costly_spot(x, y) && - (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 && - /* avoid charging for Manlobbi's statue of Manlobbi - if stone-to-flesh is used on petrified shopkeep */ - mon != shkp) - (void) stolen_value(statue, x, y, - (boolean)shkp->mpeaceful, FALSE); + /* if this isn't caused by a monster using a wand of striking, + there might be consequences for the hero */ + if (!context.mon_moving) { + /* if statue is owned by a shop, hero will have to pay for it; + stolen_value gives a message (about debt or use of credit) + which refers to "it" so needs to follow a message describing + the object ("the statue comes to life" one above) */ + if (cause != ANIMATE_NORMAL && costly_spot(x, y) + && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 && + /* avoid charging for Manlobbi's statue of Manlobbi + if stone-to-flesh is used on petrified shopkeep */ + mon != shkp) + (void) stolen_value(statue, x, y, (boolean) shkp->mpeaceful, + FALSE); - if (historic) { - You_feel("guilty %s.", historic_statue_is_gone); - adjalign(-1); - } - } else { - if (historic && cansee(x, y)) - You_feel("regret %s.", historic_statue_is_gone); - /* no alignment penalty */ - } + if (historic) { + You_feel("guilty %s.", historic_statue_is_gone); + adjalign(-1); + } + } else { + if (historic && cansee(x, y)) + You_feel("regret %s.", historic_statue_is_gone); + /* no alignment penalty */ + } - /* transfer any statue contents to monster's inventory */ - while ((item = statue->cobj) != 0) { - obj_extract_self(item); - (void) mpickobj(mon, item); - } - m_dowear(mon, TRUE); - /* in case statue is wielded and hero zaps stone-to-flesh at self */ - if (statue->owornmask) remove_worn_item(statue, TRUE); - /* statue no longer exists */ - delobj(statue); + /* transfer any statue contents to monster's inventory */ + while ((item = statue->cobj) != 0) { + obj_extract_self(item); + (void) mpickobj(mon, item); + } + m_dowear(mon, TRUE); + /* in case statue is wielded and hero zaps stone-to-flesh at self */ + if (statue->owornmask) + remove_worn_item(statue, TRUE); + /* statue no longer exists */ + delobj(statue); - /* avoid hiding under nothing */ - if (x == u.ux && y == u.uy && - Upolyd && hides_under(youmonst.data) && !OBJ_AT(x, y)) - u.uundetected = 0; + /* avoid hiding under nothing */ + if (x == u.ux && y == u.uy && Upolyd && hides_under(youmonst.data) + && !OBJ_AT(x, y)) + u.uundetected = 0; - if (fail_reason) *fail_reason = AS_OK; - return mon; + if (fail_reason) + *fail_reason = AS_OK; + return mon; } /* @@ -699,27 +731,31 @@ struct trap *trap; xchar x, y; boolean shatter; { - struct monst *mtmp = (struct monst *)0; - struct obj *otmp = sobj_at(STATUE, x, y); - int fail_reason; + struct monst *mtmp = (struct monst *) 0; + struct obj *otmp = sobj_at(STATUE, x, y); + int fail_reason; - /* - * Try to animate the first valid statue. Stop the loop when we - * actually create something or the failure cause is not because - * the mon was unique. - */ - deltrap(trap); - while (otmp) { - mtmp = animate_statue(otmp, x, y, - shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL, &fail_reason); - if (mtmp || fail_reason != AS_MON_IS_UNIQUE) break; + /* + * Try to animate the first valid statue. Stop the loop when we + * actually create something or the failure cause is not because + * the mon was unique. + */ + deltrap(trap); + while (otmp) { + mtmp = animate_statue(otmp, x, y, + shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL, + &fail_reason); + if (mtmp || fail_reason != AS_MON_IS_UNIQUE) + break; - otmp = nxtobj(otmp, STATUE, TRUE); - } + otmp = nxtobj(otmp, STATUE, TRUE); + } - if (Blind) feel_location(x, y); - else newsym(x, y); - return mtmp; + if (Blind) + feel_location(x, y); + else + newsym(x, y); + return mtmp; } STATIC_OVL boolean @@ -727,27 +763,28 @@ keep_saddle_with_steedcorpse(steed_mid, objchn, saddle) unsigned steed_mid; struct obj *objchn, *saddle; { - if (!saddle) return FALSE; - while(objchn) { - if(objchn->otyp == CORPSE && has_omonst(objchn)) { - struct monst *mtmp = OMONST(objchn); - if (mtmp->m_id == steed_mid) { - /* move saddle */ - xchar x,y; - if (get_obj_location(objchn, &x, &y, 0)) { - obj_extract_self(saddle); - place_object(saddle, x, y); - stackobj(saddle); - } - return TRUE; - } - } - if (Has_contents(objchn) && - keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle)) - return TRUE; - objchn = objchn->nobj; - } - return FALSE; + if (!saddle) + return FALSE; + while (objchn) { + if (objchn->otyp == CORPSE && has_omonst(objchn)) { + struct monst *mtmp = OMONST(objchn); + if (mtmp->m_id == steed_mid) { + /* move saddle */ + xchar x, y; + if (get_obj_location(objchn, &x, &y, 0)) { + obj_extract_self(saddle); + place_object(saddle, x, y); + stackobj(saddle); + } + return TRUE; + } + } + if (Has_contents(objchn) + && keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle)) + return TRUE; + objchn = objchn->nobj; + } + return FALSE; } void @@ -755,633 +792,645 @@ dotrap(trap, trflags) register struct trap *trap; unsigned trflags; { - register int ttype = trap->ttyp; - register struct obj *otmp; - boolean already_seen = trap->tseen, - forcetrap = (trflags & FORCETRAP) != 0, - webmsgok = (trflags & NOWEBMSG) == 0, - forcebungle = (trflags & FORCEBUNGLE) != 0, - plunged = (trflags & TOOKPLUNGE) != 0, - adj_pit = conjoined_pits(trap, t_at(u.ux0,u.uy0), TRUE); - int oldumort; - int steed_article = ARTICLE_THE; + register int ttype = trap->ttyp; + register struct obj *otmp; + boolean already_seen = trap->tseen, + forcetrap = (trflags & FORCETRAP) != 0, + webmsgok = (trflags & NOWEBMSG) == 0, + forcebungle = (trflags & FORCEBUNGLE) != 0, + plunged = (trflags & TOOKPLUNGE) != 0, + adj_pit = conjoined_pits(trap, t_at(u.ux0, u.uy0), TRUE); + int oldumort; + int steed_article = ARTICLE_THE; - nomul(0); + nomul(0); - /* KMH -- You can't escape the Sokoban level traps */ - if (Sokoban && - (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE || - ttype == TRAPDOOR)) { - /* The "air currents" message is still appropriate -- even when - * the hero isn't flying or levitating -- because it conveys the - * reason why the player cannot escape the trap with a dexterity - * check, clinging to the ceiling, etc. - */ - pline("Air currents pull you down into %s %s!", - a_your[trap->madeby_u], - defsyms[trap_to_defsym(ttype)].explanation); - /* then proceed to normal trap effect */ - } else if (already_seen && !forcetrap) { - if ((Levitation || (Flying && !plunged)) && - (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE || - ttype == BEAR_TRAP)) { - You("%s over %s %s.", - Levitation ? "float" : "fly", - a_your[trap->madeby_u], - defsyms[trap_to_defsym(ttype)].explanation); - return; - } - if(!Fumbling && ttype != MAGIC_PORTAL && - ttype != ANTI_MAGIC && !forcebungle && !plunged && !adj_pit && - (!rn2(5) || - ((ttype == PIT || ttype == SPIKED_PIT) && is_clinger(youmonst.data)))) { - You("escape %s %s.", - (ttype == ARROW_TRAP && !trap->madeby_u) ? "an" : - a_your[trap->madeby_u], - defsyms[trap_to_defsym(ttype)].explanation); - return; - } - } + /* KMH -- You can't escape the Sokoban level traps */ + if (Sokoban && (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE + || ttype == TRAPDOOR)) { + /* The "air currents" message is still appropriate -- even when + * the hero isn't flying or levitating -- because it conveys the + * reason why the player cannot escape the trap with a dexterity + * check, clinging to the ceiling, etc. + */ + pline("Air currents pull you down into %s %s!", + a_your[trap->madeby_u], + defsyms[trap_to_defsym(ttype)].explanation); + /* then proceed to normal trap effect */ + } else if (already_seen && !forcetrap) { + if ((Levitation || (Flying && !plunged)) + && (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE + || ttype == BEAR_TRAP)) { + You("%s over %s %s.", Levitation ? "float" : "fly", + a_your[trap->madeby_u], + defsyms[trap_to_defsym(ttype)].explanation); + return; + } + if (!Fumbling && ttype != MAGIC_PORTAL && ttype != ANTI_MAGIC + && !forcebungle && !plunged && !adj_pit + && (!rn2(5) || ((ttype == PIT || ttype == SPIKED_PIT) + && is_clinger(youmonst.data)))) { + You("escape %s %s.", (ttype == ARROW_TRAP && !trap->madeby_u) + ? "an" + : a_your[trap->madeby_u], + defsyms[trap_to_defsym(ttype)].explanation); + return; + } + } - if (u.usteed) { - u.usteed->mtrapseen |= (1 << (ttype - 1)); - /* suppress article in various steed messages when using its - name (which won't occur when hallucinating) */ - if (has_mname(u.usteed) && !Hallucination) - steed_article = ARTICLE_NONE; - } + if (u.usteed) { + u.usteed->mtrapseen |= (1 << (ttype - 1)); + /* suppress article in various steed messages when using its + name (which won't occur when hallucinating) */ + if (has_mname(u.usteed) && !Hallucination) + steed_article = ARTICLE_NONE; + } - switch(ttype) { - case ARROW_TRAP: - if (trap->once && trap->tseen && !rn2(15)) { - You_hear("a loud click!"); - deltrap(trap); - newsym(u.ux,u.uy); - break; - } - trap->once = 1; - seetrap(trap); - pline("An arrow shoots out at you!"); - otmp = mksobj(ARROW, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); - otmp->opoisoned = 0; - if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */; - else if (thitu(8, dmgval(otmp, &youmonst), otmp, "arrow")) { - obfree(otmp, (struct obj *)0); - } else { - place_object(otmp, u.ux, u.uy); - if (!Blind) otmp->dknown = 1; - stackobj(otmp); - newsym(u.ux, u.uy); - } - break; - case DART_TRAP: - if (trap->once && trap->tseen && !rn2(15)) { - You_hear("a soft click."); - deltrap(trap); - newsym(u.ux,u.uy); - break; - } - trap->once = 1; - seetrap(trap); - pline("A little dart shoots out at you!"); - otmp = mksobj(DART, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); - if (!rn2(6)) otmp->opoisoned = 1; - oldumort = u.umortality; - if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */; - else if (thitu(7, dmgval(otmp, &youmonst), otmp, "little dart")) { - if (otmp->opoisoned) - poisoned("dart", A_CON, "little dart", - /* if damage triggered life-saving, - poison is limited to attrib loss */ - (u.umortality > oldumort) ? 0 : 10, TRUE); - obfree(otmp, (struct obj *)0); - } else { - place_object(otmp, u.ux, u.uy); - if (!Blind) otmp->dknown = 1; - stackobj(otmp); - newsym(u.ux, u.uy); - } - break; - case ROCKTRAP: - if (trap->once && trap->tseen && !rn2(15)) { - pline("A trap door in %s opens, but nothing falls out!", - the(ceiling(u.ux,u.uy))); - deltrap(trap); - newsym(u.ux,u.uy); - } else { - int dmg = d(2,6); /* should be std ROCK dmg? */ + switch (ttype) { + case ARROW_TRAP: + if (trap->once && trap->tseen && !rn2(15)) { + You_hear("a loud click!"); + deltrap(trap); + newsym(u.ux, u.uy); + break; + } + trap->once = 1; + seetrap(trap); + pline("An arrow shoots out at you!"); + otmp = mksobj(ARROW, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + otmp->opoisoned = 0; + if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */ + ; + else if (thitu(8, dmgval(otmp, &youmonst), otmp, "arrow")) { + obfree(otmp, (struct obj *) 0); + } else { + place_object(otmp, u.ux, u.uy); + if (!Blind) + otmp->dknown = 1; + stackobj(otmp); + newsym(u.ux, u.uy); + } + break; + case DART_TRAP: + if (trap->once && trap->tseen && !rn2(15)) { + You_hear("a soft click."); + deltrap(trap); + newsym(u.ux, u.uy); + break; + } + trap->once = 1; + seetrap(trap); + pline("A little dart shoots out at you!"); + otmp = mksobj(DART, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + if (!rn2(6)) + otmp->opoisoned = 1; + oldumort = u.umortality; + if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */ + ; + else if (thitu(7, dmgval(otmp, &youmonst), otmp, "little dart")) { + if (otmp->opoisoned) + poisoned("dart", A_CON, "little dart", + /* if damage triggered life-saving, + poison is limited to attrib loss */ + (u.umortality > oldumort) ? 0 : 10, TRUE); + obfree(otmp, (struct obj *) 0); + } else { + place_object(otmp, u.ux, u.uy); + if (!Blind) + otmp->dknown = 1; + stackobj(otmp); + newsym(u.ux, u.uy); + } + break; + case ROCKTRAP: + if (trap->once && trap->tseen && !rn2(15)) { + pline("A trap door in %s opens, but nothing falls out!", + the(ceiling(u.ux, u.uy))); + deltrap(trap); + newsym(u.ux, u.uy); + } else { + int dmg = d(2, 6); /* should be std ROCK dmg? */ - trap->once = 1; - feeltrap(trap); - otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); + trap->once = 1; + feeltrap(trap); + otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); - pline("A trap door in %s opens and %s falls on your %s!", - the(ceiling(u.ux,u.uy)), - an(xname(otmp)), - body_part(HEAD)); + pline("A trap door in %s opens and %s falls on your %s!", + the(ceiling(u.ux, u.uy)), an(xname(otmp)), body_part(HEAD)); - if (uarmh) { - if(is_metallic(uarmh)) { - pline("Fortunately, you are wearing a hard helmet."); - dmg = 2; - } else if (flags.verbose) { - pline("%s does not protect you.", Yname2(uarmh)); - } - } + if (uarmh) { + if (is_metallic(uarmh)) { + pline("Fortunately, you are wearing a hard helmet."); + dmg = 2; + } else if (flags.verbose) { + pline("%s does not protect you.", Yname2(uarmh)); + } + } - if (!Blind) otmp->dknown = 1; - stackobj(otmp); - newsym(u.ux,u.uy); /* map the rock */ + if (!Blind) + otmp->dknown = 1; + stackobj(otmp); + newsym(u.ux, u.uy); /* map the rock */ - losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); - exercise(A_STR, FALSE); - } - break; + losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); + exercise(A_STR, FALSE); + } + break; - case SQKY_BOARD: /* stepped on a squeaky board */ - if ((Levitation || Flying) && !forcetrap) { - if (!Blind) { - seetrap(trap); - if (Hallucination) - You("notice a crease in the linoleum."); - else - You("notice a loose board below you."); - } - } else { - seetrap(trap); - pline("A board beneath you %s%s%s.", - Deaf ? "vibrates" : "squeaks ", - Deaf ? "" : trapnote(trap,0), - Deaf ? "" : " loudly"); - wake_nearby(); - } - break; + case SQKY_BOARD: /* stepped on a squeaky board */ + if ((Levitation || Flying) && !forcetrap) { + if (!Blind) { + seetrap(trap); + if (Hallucination) + You("notice a crease in the linoleum."); + else + You("notice a loose board below you."); + } + } else { + seetrap(trap); + pline("A board beneath you %s%s%s.", + Deaf ? "vibrates" : "squeaks ", + Deaf ? "" : trapnote(trap, 0), Deaf ? "" : " loudly"); + wake_nearby(); + } + break; - case BEAR_TRAP: - { - int dmg = d(2, 4); + case BEAR_TRAP: { + int dmg = d(2, 4); - if ((Levitation || Flying) && !forcetrap) break; - feeltrap(trap); - if(amorphous(youmonst.data) || is_whirly(youmonst.data) || - unsolid(youmonst.data)) { - pline("%s bear trap closes harmlessly through you.", - A_Your[trap->madeby_u]); - break; - } - if( !u.usteed && youmonst.data->msize <= MZ_SMALL) { - pline("%s bear trap closes harmlessly over you.", - A_Your[trap->madeby_u]); - break; - } - u.utrap = rn1(4, 4); - u.utraptype = TT_BEARTRAP; - if (u.usteed) { - pline("%s bear trap closes on %s %s!", - A_Your[trap->madeby_u], s_suffix(mon_nam(u.usteed)), - mbodypart(u.usteed, FOOT)); - if (thitm(0, u.usteed, (struct obj *)0, dmg, FALSE)) - u.utrap = 0; /* steed died, hero not trapped */ - } else { - pline("%s bear trap closes on your %s!", - A_Your[trap->madeby_u], body_part(FOOT)); - set_wounded_legs(rn2(2) ? RIGHT_SIDE : LEFT_SIDE, rn1(10,10)); - if(u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR) - You("howl in anger!"); - losehp(Maybe_Half_Phys(dmg), "bear trap", KILLED_BY_AN); - } - exercise(A_DEX, FALSE); - break; - } + if ((Levitation || Flying) && !forcetrap) + break; + feeltrap(trap); + if (amorphous(youmonst.data) || is_whirly(youmonst.data) + || unsolid(youmonst.data)) { + pline("%s bear trap closes harmlessly through you.", + A_Your[trap->madeby_u]); + break; + } + if (!u.usteed && youmonst.data->msize <= MZ_SMALL) { + pline("%s bear trap closes harmlessly over you.", + A_Your[trap->madeby_u]); + break; + } + u.utrap = rn1(4, 4); + u.utraptype = TT_BEARTRAP; + if (u.usteed) { + pline("%s bear trap closes on %s %s!", A_Your[trap->madeby_u], + s_suffix(mon_nam(u.usteed)), mbodypart(u.usteed, FOOT)); + if (thitm(0, u.usteed, (struct obj *) 0, dmg, FALSE)) + u.utrap = 0; /* steed died, hero not trapped */ + } else { + pline("%s bear trap closes on your %s!", A_Your[trap->madeby_u], + body_part(FOOT)); + set_wounded_legs(rn2(2) ? RIGHT_SIDE : LEFT_SIDE, rn1(10, 10)); + if (u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR) + You("howl in anger!"); + losehp(Maybe_Half_Phys(dmg), "bear trap", KILLED_BY_AN); + } + exercise(A_DEX, FALSE); + break; + } - case SLP_GAS_TRAP: - seetrap(trap); - if(Sleep_resistance || breathless(youmonst.data)) { - You("are enveloped in a cloud of gas!"); - } else { - pline("A cloud of gas puts you to sleep!"); - fall_asleep(-rnd(25), TRUE); - } - (void) steedintrap(trap, (struct obj *)0); - break; + case SLP_GAS_TRAP: + seetrap(trap); + if (Sleep_resistance || breathless(youmonst.data)) { + You("are enveloped in a cloud of gas!"); + } else { + pline("A cloud of gas puts you to sleep!"); + fall_asleep(-rnd(25), TRUE); + } + (void) steedintrap(trap, (struct obj *) 0); + break; - case RUST_TRAP: - seetrap(trap); + case RUST_TRAP: + seetrap(trap); - /* Unlike monsters, traps cannot aim their rust attacks at - * you, so instead of looping through and taking either the - * first rustable one or the body, we take whatever we get, - * even if it is not rustable. - */ - switch (rn2(5)) { - case 0: - pline("%s you on the %s!", A_gush_of_water_hits, - body_part(HEAD)); - (void) water_damage(uarmh, helm_simple_name(uarmh), - TRUE); - break; - case 1: - pline("%s your left %s!", A_gush_of_water_hits, - body_part(ARM)); - if (water_damage(uarms, "shield", TRUE) != ER_NOTHING) - break; - if (u.twoweap || (uwep && bimanual(uwep))) - (void) water_damage(u.twoweap ? uswapwep : uwep, 0, - TRUE); -glovecheck: (void) water_damage(uarmg, "gauntlets", TRUE); - /* Not "metal gauntlets" since it gets called - * even if it's leather for the message - */ - break; - case 2: - pline("%s your right %s!", A_gush_of_water_hits, - body_part(ARM)); - (void) water_damage(uwep, 0, TRUE); - goto glovecheck; - default: - pline("%s you!", A_gush_of_water_hits); - for (otmp = invent; otmp; otmp = otmp->nobj) - if (otmp->lamplit && otmp != uwep && - (otmp != uswapwep || !u.twoweap)) - (void) snuff_lit(otmp); - if (uarmc) - (void) water_damage(uarmc, cloak_simple_name(uarmc), - TRUE); - else if (uarm) - (void) water_damage(uarm, "armor", TRUE); - else if (uarmu) - (void) water_damage(uarmu, "shirt", TRUE); - } - update_inventory(); + /* Unlike monsters, traps cannot aim their rust attacks at + * you, so instead of looping through and taking either the + * first rustable one or the body, we take whatever we get, + * even if it is not rustable. + */ + switch (rn2(5)) { + case 0: + pline("%s you on the %s!", A_gush_of_water_hits, body_part(HEAD)); + (void) water_damage(uarmh, helm_simple_name(uarmh), TRUE); + break; + case 1: + pline("%s your left %s!", A_gush_of_water_hits, body_part(ARM)); + if (water_damage(uarms, "shield", TRUE) != ER_NOTHING) + break; + if (u.twoweap || (uwep && bimanual(uwep))) + (void) water_damage(u.twoweap ? uswapwep : uwep, 0, TRUE); + glovecheck: + (void) water_damage(uarmg, "gauntlets", TRUE); + /* Not "metal gauntlets" since it gets called + * even if it's leather for the message + */ + break; + case 2: + pline("%s your right %s!", A_gush_of_water_hits, body_part(ARM)); + (void) water_damage(uwep, 0, TRUE); + goto glovecheck; + default: + pline("%s you!", A_gush_of_water_hits); + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->lamplit && otmp != uwep + && (otmp != uswapwep || !u.twoweap)) + (void) snuff_lit(otmp); + if (uarmc) + (void) water_damage(uarmc, cloak_simple_name(uarmc), TRUE); + else if (uarm) + (void) water_damage(uarm, "armor", TRUE); + else if (uarmu) + (void) water_damage(uarmu, "shirt", TRUE); + } + update_inventory(); - if (u.umonnum == PM_IRON_GOLEM) { - int dam = u.mhmax; + if (u.umonnum == PM_IRON_GOLEM) { + int dam = u.mhmax; - pline("%s you!", A_gush_of_water_hits); - You("are covered with rust!"); - losehp(Maybe_Half_Phys(dam), "rusting away", KILLED_BY); - } else if (u.umonnum == PM_GREMLIN && rn2(3)) { - pline("%s you!", A_gush_of_water_hits); - (void)split_mon(&youmonst, (struct monst *)0); - } + pline("%s you!", A_gush_of_water_hits); + You("are covered with rust!"); + losehp(Maybe_Half_Phys(dam), "rusting away", KILLED_BY); + } else if (u.umonnum == PM_GREMLIN && rn2(3)) { + pline("%s you!", A_gush_of_water_hits); + (void) split_mon(&youmonst, (struct monst *) 0); + } - break; + break; - case FIRE_TRAP: - seetrap(trap); - dofiretrap((struct obj *)0); - break; + case FIRE_TRAP: + seetrap(trap); + dofiretrap((struct obj *) 0); + break; - case PIT: - case SPIKED_PIT: - /* KMH -- You can't escape the Sokoban level traps */ - if (!Sokoban && (Levitation || (Flying && !plunged))) break; - feeltrap(trap); - if (!Sokoban && is_clinger(youmonst.data) && !plunged) { - if(trap->tseen) { - You_see("%s %spit below you.", a_your[trap->madeby_u], - ttype == SPIKED_PIT ? "spiked " : ""); - } else { - pline("%s pit %sopens up under you!", - A_Your[trap->madeby_u], - ttype == SPIKED_PIT ? "full of spikes " : ""); - You("don't fall in!"); - } - break; - } - if (!Sokoban) { - char verbbuf[BUFSZ]; - if (u.usteed) { - if ((trflags & RECURSIVETRAP) != 0) - Sprintf(verbbuf, "and %s fall", - x_monnam(u.usteed, steed_article, - (char *)0, SUPPRESS_SADDLE, FALSE)); - else - Sprintf(verbbuf, "lead %s", - x_monnam(u.usteed, steed_article, - "poor", SUPPRESS_SADDLE, FALSE)); - } else if (adj_pit) { - You("move into an adjacent pit."); - } else { - Strcpy(verbbuf, !plunged ? "fall" : - (Flying ? "dive" : "plunge")); - You("%s into %s pit!", verbbuf, a_your[trap->madeby_u]); - } - } - /* wumpus reference */ - if (Role_if(PM_RANGER) && !trap->madeby_u && !trap->once && - In_quest(&u.uz) && Is_qlocate(&u.uz)) { - pline("Fortunately it has a bottom after all..."); - trap->once = 1; - } else if (u.umonnum == PM_PIT_VIPER || - u.umonnum == PM_PIT_FIEND) - pline("How pitiful. Isn't that the pits?"); - if (ttype == SPIKED_PIT) { - const char *predicament = "on a set of sharp iron spikes"; - if (u.usteed) { - pline("%s %s %s!", - upstart(x_monnam(u.usteed, steed_article, - "poor", SUPPRESS_SADDLE, FALSE)), - adj_pit ? "steps" : "lands", - predicament); - } else - You("%s %s!", adj_pit ? "step" : "land", predicament); - } - u.utrap = rn1(6,2); - u.utraptype = TT_PIT; - if (!steedintrap(trap, (struct obj *)0)) { - if (ttype == SPIKED_PIT) { - oldumort = u.umortality; - losehp(Maybe_Half_Phys(rnd(adj_pit ? 6 : 10)), - plunged ? "deliberately plunged into a pit of iron spikes" : - adj_pit ? "stepped into a pit of iron spikes" : - "fell into a pit of iron spikes", - NO_KILLER_PREFIX); - if (!rn2(6)) - poisoned("spikes", A_STR, - adj_pit ? "stepping on poison spikes" : - "fall onto poison spikes", - /* if damage triggered life-saving, - poison is limited to attrib loss */ - (u.umortality > oldumort) ? 0 : 8, FALSE); - } else { - /* plunging flyers take spike damage but not pit damage */ - if (!adj_pit && - !(plunged && (Flying || is_clinger(youmonst.data)))) - losehp(Maybe_Half_Phys(rnd(6)), - plunged ? "deliberately plunged into a pit" : - "fell into a pit", - NO_KILLER_PREFIX); - } - if (Punished && !carried(uball)) { - unplacebc(); - ballfall(); - placebc(); - } - if (!adj_pit) selftouch("Falling, you"); - vision_full_recalc = 1; /* vision limits change */ - exercise(A_STR, FALSE); - exercise(A_DEX, FALSE); - } - break; - case HOLE: - case TRAPDOOR: - if (!Can_fall_thru(&u.uz)) { - seetrap(trap); /* normally done in fall_through */ - impossible("dotrap: %ss cannot exist on this level.", - defsyms[trap_to_defsym(ttype)].explanation); - break; /* don't activate it after all */ - } - fall_through(TRUE); - break; + case PIT: + case SPIKED_PIT: + /* KMH -- You can't escape the Sokoban level traps */ + if (!Sokoban && (Levitation || (Flying && !plunged))) + break; + feeltrap(trap); + if (!Sokoban && is_clinger(youmonst.data) && !plunged) { + if (trap->tseen) { + You_see("%s %spit below you.", a_your[trap->madeby_u], + ttype == SPIKED_PIT ? "spiked " : ""); + } else { + pline("%s pit %sopens up under you!", A_Your[trap->madeby_u], + ttype == SPIKED_PIT ? "full of spikes " : ""); + You("don't fall in!"); + } + break; + } + if (!Sokoban) { + char verbbuf[BUFSZ]; + if (u.usteed) { + if ((trflags & RECURSIVETRAP) != 0) + Sprintf(verbbuf, "and %s fall", + x_monnam(u.usteed, steed_article, (char *) 0, + SUPPRESS_SADDLE, FALSE)); + else + Sprintf(verbbuf, "lead %s", + x_monnam(u.usteed, steed_article, "poor", + SUPPRESS_SADDLE, FALSE)); + } else if (adj_pit) { + You("move into an adjacent pit."); + } else { + Strcpy(verbbuf, + !plunged ? "fall" : (Flying ? "dive" : "plunge")); + You("%s into %s pit!", verbbuf, a_your[trap->madeby_u]); + } + } + /* wumpus reference */ + if (Role_if(PM_RANGER) && !trap->madeby_u && !trap->once + && In_quest(&u.uz) && Is_qlocate(&u.uz)) { + pline("Fortunately it has a bottom after all..."); + trap->once = 1; + } else if (u.umonnum == PM_PIT_VIPER || u.umonnum == PM_PIT_FIEND) + pline("How pitiful. Isn't that the pits?"); + if (ttype == SPIKED_PIT) { + const char *predicament = "on a set of sharp iron spikes"; + if (u.usteed) { + pline("%s %s %s!", + upstart(x_monnam(u.usteed, steed_article, "poor", + SUPPRESS_SADDLE, FALSE)), + adj_pit ? "steps" : "lands", predicament); + } else + You("%s %s!", adj_pit ? "step" : "land", predicament); + } + u.utrap = rn1(6, 2); + u.utraptype = TT_PIT; + if (!steedintrap(trap, (struct obj *) 0)) { + if (ttype == SPIKED_PIT) { + oldumort = u.umortality; + losehp(Maybe_Half_Phys(rnd(adj_pit ? 6 : 10)), + plunged + ? "deliberately plunged into a pit of iron spikes" + : adj_pit ? "stepped into a pit of iron spikes" + : "fell into a pit of iron spikes", + NO_KILLER_PREFIX); + if (!rn2(6)) + poisoned("spikes", A_STR, + adj_pit ? "stepping on poison spikes" + : "fall onto poison spikes", + /* if damage triggered life-saving, + poison is limited to attrib loss */ + (u.umortality > oldumort) ? 0 : 8, FALSE); + } else { + /* plunging flyers take spike damage but not pit damage */ + if (!adj_pit + && !(plunged && (Flying || is_clinger(youmonst.data)))) + losehp(Maybe_Half_Phys(rnd(6)), + plunged ? "deliberately plunged into a pit" + : "fell into a pit", + NO_KILLER_PREFIX); + } + if (Punished && !carried(uball)) { + unplacebc(); + ballfall(); + placebc(); + } + if (!adj_pit) + selftouch("Falling, you"); + vision_full_recalc = 1; /* vision limits change */ + exercise(A_STR, FALSE); + exercise(A_DEX, FALSE); + } + break; + case HOLE: + case TRAPDOOR: + if (!Can_fall_thru(&u.uz)) { + seetrap(trap); /* normally done in fall_through */ + impossible("dotrap: %ss cannot exist on this level.", + defsyms[trap_to_defsym(ttype)].explanation); + break; /* don't activate it after all */ + } + fall_through(TRUE); + break; - case TELEP_TRAP: - seetrap(trap); - tele_trap(trap); - break; - case LEVEL_TELEP: - seetrap(trap); - level_tele_trap(trap); - break; + case TELEP_TRAP: + seetrap(trap); + tele_trap(trap); + break; + case LEVEL_TELEP: + seetrap(trap); + level_tele_trap(trap); + break; - case WEB: /* Our luckless player has stumbled into a web. */ - feeltrap(trap); - if (amorphous(youmonst.data) || is_whirly(youmonst.data) || - unsolid(youmonst.data)) { - if (acidic(youmonst.data) || u.umonnum == PM_GELATINOUS_CUBE || - u.umonnum == PM_FIRE_ELEMENTAL) { - if (webmsgok) - You("%s %s spider web!", - (u.umonnum == PM_FIRE_ELEMENTAL) ? "burn" : "dissolve", - a_your[trap->madeby_u]); - deltrap(trap); - newsym(u.ux,u.uy); - break; - } - if (webmsgok) You("flow through %s spider web.", - a_your[trap->madeby_u]); - break; - } - if (webmaker(youmonst.data)) { - if (webmsgok) - pline(trap->madeby_u ? "You take a walk on your web." - : "There is a spider web here."); - break; - } - if (webmsgok) { - char verbbuf[BUFSZ]; + case WEB: /* Our luckless player has stumbled into a web. */ + feeltrap(trap); + if (amorphous(youmonst.data) || is_whirly(youmonst.data) + || unsolid(youmonst.data)) { + if (acidic(youmonst.data) || u.umonnum == PM_GELATINOUS_CUBE + || u.umonnum == PM_FIRE_ELEMENTAL) { + if (webmsgok) + You("%s %s spider web!", + (u.umonnum == PM_FIRE_ELEMENTAL) ? "burn" + : "dissolve", + a_your[trap->madeby_u]); + deltrap(trap); + newsym(u.ux, u.uy); + break; + } + if (webmsgok) + You("flow through %s spider web.", a_your[trap->madeby_u]); + break; + } + if (webmaker(youmonst.data)) { + if (webmsgok) + pline(trap->madeby_u ? "You take a walk on your web." + : "There is a spider web here."); + break; + } + if (webmsgok) { + char verbbuf[BUFSZ]; - if (forcetrap) { - Strcpy(verbbuf, "are caught by"); - } else if (u.usteed) { - Sprintf(verbbuf, "lead %s into", - x_monnam(u.usteed, steed_article, - "poor", SUPPRESS_SADDLE, FALSE)); - } else { - Sprintf(verbbuf, "%s into", - Levitation ? (const char *)"float" : - locomotion(youmonst.data, "stumble")); - } - You("%s %s spider web!", verbbuf, a_your[trap->madeby_u]); - } - u.utraptype = TT_WEB; + if (forcetrap) { + Strcpy(verbbuf, "are caught by"); + } else if (u.usteed) { + Sprintf(verbbuf, "lead %s into", + x_monnam(u.usteed, steed_article, "poor", + SUPPRESS_SADDLE, FALSE)); + } else { + Sprintf(verbbuf, "%s into", + Levitation ? (const char *) "float" + : locomotion(youmonst.data, "stumble")); + } + You("%s %s spider web!", verbbuf, a_your[trap->madeby_u]); + } + u.utraptype = TT_WEB; - /* Time stuck in the web depends on your/steed strength. */ - { - register int str = ACURR(A_STR); + /* Time stuck in the web depends on your/steed strength. */ + { + register int str = ACURR(A_STR); - /* If mounted, the steed gets trapped. Use mintrap - * to do all the work. If mtrapped is set as a result, - * unset it and set utrap instead. In the case of a - * strongmonst and mintrap said it's trapped, use a - * short but non-zero trap time. Otherwise, monsters - * have no specific strength, so use player strength. - * This gets skipped for webmsgok, which implies that - * the steed isn't a factor. - */ - if (u.usteed && webmsgok) { - /* mtmp location might not be up to date */ - u.usteed->mx = u.ux; - u.usteed->my = u.uy; + /* If mounted, the steed gets trapped. Use mintrap + * to do all the work. If mtrapped is set as a result, + * unset it and set utrap instead. In the case of a + * strongmonst and mintrap said it's trapped, use a + * short but non-zero trap time. Otherwise, monsters + * have no specific strength, so use player strength. + * This gets skipped for webmsgok, which implies that + * the steed isn't a factor. + */ + if (u.usteed && webmsgok) { + /* mtmp location might not be up to date */ + u.usteed->mx = u.ux; + u.usteed->my = u.uy; - /* mintrap currently does not return 2(died) for webs */ - if (mintrap(u.usteed)) { - u.usteed->mtrapped = 0; - if (strongmonst(u.usteed->data)) str = 17; - } else { - break; - } + /* mintrap currently does not return 2(died) for webs */ + if (mintrap(u.usteed)) { + u.usteed->mtrapped = 0; + if (strongmonst(u.usteed->data)) + str = 17; + } else { + break; + } - webmsgok = FALSE; /* mintrap printed the messages */ - } - if (str <= 3) u.utrap = rn1(6,6); - else if (str < 6) u.utrap = rn1(6,4); - else if (str < 9) u.utrap = rn1(4,4); - else if (str < 12) u.utrap = rn1(4,2); - else if (str < 15) u.utrap = rn1(2,2); - else if (str < 18) u.utrap = rnd(2); - else if (str < 69) u.utrap = 1; - else { - u.utrap = 0; - if (webmsgok) - You("tear through %s web!", a_your[trap->madeby_u]); - deltrap(trap); - newsym(u.ux,u.uy); /* get rid of trap symbol */ - } - } - break; + webmsgok = FALSE; /* mintrap printed the messages */ + } + if (str <= 3) + u.utrap = rn1(6, 6); + else if (str < 6) + u.utrap = rn1(6, 4); + else if (str < 9) + u.utrap = rn1(4, 4); + else if (str < 12) + u.utrap = rn1(4, 2); + else if (str < 15) + u.utrap = rn1(2, 2); + else if (str < 18) + u.utrap = rnd(2); + else if (str < 69) + u.utrap = 1; + else { + u.utrap = 0; + if (webmsgok) + You("tear through %s web!", a_your[trap->madeby_u]); + deltrap(trap); + newsym(u.ux, u.uy); /* get rid of trap symbol */ + } + } + break; - case STATUE_TRAP: - (void) activate_statue_trap(trap, u.ux, u.uy, FALSE); - break; + case STATUE_TRAP: + (void) activate_statue_trap(trap, u.ux, u.uy, FALSE); + break; - case MAGIC_TRAP: /* A magic trap. */ - seetrap(trap); - if (!rn2(30)) { - deltrap(trap); - newsym(u.ux,u.uy); /* update position */ - You("are caught in a magical explosion!"); - losehp(rnd(10), "magical explosion", KILLED_BY_AN); - Your("body absorbs some of the magical energy!"); - u.uen = (u.uenmax += 2); - break; - } else domagictrap(); - (void) steedintrap(trap, (struct obj *)0); - break; + case MAGIC_TRAP: /* A magic trap. */ + seetrap(trap); + if (!rn2(30)) { + deltrap(trap); + newsym(u.ux, u.uy); /* update position */ + You("are caught in a magical explosion!"); + losehp(rnd(10), "magical explosion", KILLED_BY_AN); + Your("body absorbs some of the magical energy!"); + u.uen = (u.uenmax += 2); + break; + } else + domagictrap(); + (void) steedintrap(trap, (struct obj *) 0); + break; - case ANTI_MAGIC: - seetrap(trap); - /* hero without magic resistance loses spell energy, - hero with magic resistance takes damage instead; - possibly non-intuitive but useful for play balance */ - if (!Antimagic) { - drain_en(rnd(u.ulevel) + 1); - } else { - int dmgval2 = rnd(4), hp = Upolyd ? u.mh : u.uhp; + case ANTI_MAGIC: + seetrap(trap); + /* hero without magic resistance loses spell energy, + hero with magic resistance takes damage instead; + possibly non-intuitive but useful for play balance */ + if (!Antimagic) { + drain_en(rnd(u.ulevel) + 1); + } else { + int dmgval2 = rnd(4), hp = Upolyd ? u.mh : u.uhp; - /* Half_XXX_damage has opposite its usual effect (approx) - but isn't cumulative if hero has more than one */ - if (Half_physical_damage || Half_spell_damage) - dmgval2 += rnd(4); - /* give Magicbane wielder dose of own medicine */ - if (uwep && uwep->oartifact == ART_MAGICBANE) - dmgval2 += rnd(4); - /* having an artifact--other than own quest one--which - confers magic resistance simply by being carried - also increases the effect */ - for (otmp = invent; otmp; otmp = otmp->nobj) - if (otmp->oartifact && !is_quest_artifact(otmp) && - defends_when_carried(AD_MAGM, otmp)) break; - if (otmp) dmgval2 += rnd(4); - if (Passes_walls) dmgval2 = (dmgval2 + 3) / 4; + /* Half_XXX_damage has opposite its usual effect (approx) + but isn't cumulative if hero has more than one */ + if (Half_physical_damage || Half_spell_damage) + dmgval2 += rnd(4); + /* give Magicbane wielder dose of own medicine */ + if (uwep && uwep->oartifact == ART_MAGICBANE) + dmgval2 += rnd(4); + /* having an artifact--other than own quest one--which + confers magic resistance simply by being carried + also increases the effect */ + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->oartifact && !is_quest_artifact(otmp) + && defends_when_carried(AD_MAGM, otmp)) + break; + if (otmp) + dmgval2 += rnd(4); + if (Passes_walls) + dmgval2 = (dmgval2 + 3) / 4; - You_feel((dmgval2 >= hp) ? "unbearably torpid!" : - (dmgval2 >= hp / 4) ? "very lethargic." : - "sluggish."); - /* opposite of magical explosion */ - losehp(dmgval2, "anti-magic implosion", KILLED_BY_AN); - } - break; + You_feel((dmgval2 >= hp) ? "unbearably torpid!" + : (dmgval2 >= hp / 4) ? "very lethargic." + : "sluggish."); + /* opposite of magical explosion */ + losehp(dmgval2, "anti-magic implosion", KILLED_BY_AN); + } + break; - case POLY_TRAP: { - char verbbuf[BUFSZ]; - seetrap(trap); - if (u.usteed) - Sprintf(verbbuf, "lead %s", - x_monnam(u.usteed, steed_article, - (char *)0, SUPPRESS_SADDLE, FALSE)); - else - Sprintf(verbbuf,"%s", - Levitation ? (const char *)"float" : - locomotion(youmonst.data, "step")); - You("%s onto a polymorph trap!", verbbuf); - if(Antimagic || Unchanging) { - shieldeff(u.ux, u.uy); - You_feel("momentarily different."); - /* Trap did nothing; don't remove it --KAA */ - } else { - (void) steedintrap(trap, (struct obj *)0); - deltrap(trap); /* delete trap before polymorph */ - newsym(u.ux,u.uy); /* get rid of trap symbol */ - You_feel("a change coming over you."); - polyself(0); - } - break; - } - case LANDMINE: { - unsigned steed_mid = 0; - struct obj *saddle = 0; - if ((Levitation || Flying) && !forcetrap) { - if (!already_seen && rn2(3)) break; - feeltrap(trap); - pline("%s %s in a pile of soil below you.", - already_seen ? "There is" : "You discover", - trap->madeby_u ? "the trigger of your mine" : - "a trigger"); - if (already_seen && rn2(3)) break; - pline("KAABLAMM!!! %s %s%s off!", - forcebungle ? "Your inept attempt sets" : - "The air currents set", - already_seen ? a_your[trap->madeby_u] : "", - already_seen ? " land mine" : "it"); - } else { - /* prevent landmine from killing steed, throwing you to - * the ground, and you being affected again by the same - * mine because it hasn't been deleted yet - */ - static boolean recursive_mine = FALSE; + case POLY_TRAP: { + char verbbuf[BUFSZ]; + seetrap(trap); + if (u.usteed) + Sprintf(verbbuf, "lead %s", + x_monnam(u.usteed, steed_article, (char *) 0, + SUPPRESS_SADDLE, FALSE)); + else + Sprintf(verbbuf, "%s", Levitation + ? (const char *) "float" + : locomotion(youmonst.data, "step")); + You("%s onto a polymorph trap!", verbbuf); + if (Antimagic || Unchanging) { + shieldeff(u.ux, u.uy); + You_feel("momentarily different."); + /* Trap did nothing; don't remove it --KAA */ + } else { + (void) steedintrap(trap, (struct obj *) 0); + deltrap(trap); /* delete trap before polymorph */ + newsym(u.ux, u.uy); /* get rid of trap symbol */ + You_feel("a change coming over you."); + polyself(0); + } + break; + } + case LANDMINE: { + unsigned steed_mid = 0; + struct obj *saddle = 0; + if ((Levitation || Flying) && !forcetrap) { + if (!already_seen && rn2(3)) + break; + feeltrap(trap); + pline("%s %s in a pile of soil below you.", + already_seen ? "There is" : "You discover", + trap->madeby_u ? "the trigger of your mine" : "a trigger"); + if (already_seen && rn2(3)) + break; + pline("KAABLAMM!!! %s %s%s off!", + forcebungle ? "Your inept attempt sets" + : "The air currents set", + already_seen ? a_your[trap->madeby_u] : "", + already_seen ? " land mine" : "it"); + } else { + /* prevent landmine from killing steed, throwing you to + * the ground, and you being affected again by the same + * mine because it hasn't been deleted yet + */ + static boolean recursive_mine = FALSE; - if (recursive_mine) break; - feeltrap(trap); - pline("KAABLAMM!!! You triggered %s land mine!", - a_your[trap->madeby_u]); - if (u.usteed) steed_mid = u.usteed->m_id; - recursive_mine = TRUE; - (void) steedintrap(trap, (struct obj *)0); - recursive_mine = FALSE; - saddle = sobj_at(SADDLE,u.ux, u.uy); - set_wounded_legs(LEFT_SIDE, rn1(35, 41)); - set_wounded_legs(RIGHT_SIDE, rn1(35, 41)); - exercise(A_DEX, FALSE); - } - blow_up_landmine(trap); - if (steed_mid && saddle && !u.usteed) - (void)keep_saddle_with_steedcorpse(steed_mid, fobj, saddle); - newsym(u.ux,u.uy); /* update trap symbol */ - losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN); - /* fall recursively into the pit... */ - if ((trap = t_at(u.ux, u.uy)) != 0) dotrap(trap, RECURSIVETRAP); - fill_pit(u.ux, u.uy); - break; - } - case ROLLING_BOULDER_TRAP: { - int style = ROLL | (trap->tseen ? LAUNCH_KNOWN : 0); + if (recursive_mine) + break; + feeltrap(trap); + pline("KAABLAMM!!! You triggered %s land mine!", + a_your[trap->madeby_u]); + if (u.usteed) + steed_mid = u.usteed->m_id; + recursive_mine = TRUE; + (void) steedintrap(trap, (struct obj *) 0); + recursive_mine = FALSE; + saddle = sobj_at(SADDLE, u.ux, u.uy); + set_wounded_legs(LEFT_SIDE, rn1(35, 41)); + set_wounded_legs(RIGHT_SIDE, rn1(35, 41)); + exercise(A_DEX, FALSE); + } + blow_up_landmine(trap); + if (steed_mid && saddle && !u.usteed) + (void) keep_saddle_with_steedcorpse(steed_mid, fobj, saddle); + newsym(u.ux, u.uy); /* update trap symbol */ + losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN); + /* fall recursively into the pit... */ + if ((trap = t_at(u.ux, u.uy)) != 0) + dotrap(trap, RECURSIVETRAP); + fill_pit(u.ux, u.uy); + break; + } + case ROLLING_BOULDER_TRAP: { + int style = ROLL | (trap->tseen ? LAUNCH_KNOWN : 0); - feeltrap(trap); - pline("Click! You trigger a rolling boulder trap!"); - if(!launch_obj(BOULDER, trap->launch.x, trap->launch.y, - trap->launch2.x, trap->launch2.y, style)) { - deltrap(trap); - newsym(u.ux,u.uy); /* get rid of trap symbol */ - pline("Fortunately for you, no boulder was released."); - } - break; - } - case MAGIC_PORTAL: - feeltrap(trap); - domagicportal(trap); - break; + feeltrap(trap); + pline("Click! You trigger a rolling boulder trap!"); + if (!launch_obj(BOULDER, trap->launch.x, trap->launch.y, + trap->launch2.x, trap->launch2.y, style)) { + deltrap(trap); + newsym(u.ux, u.uy); /* get rid of trap symbol */ + pline("Fortunately for you, no boulder was released."); + } + break; + } + case MAGIC_PORTAL: + feeltrap(trap); + domagicportal(trap); + break; - default: - feeltrap(trap); - impossible("You hit a trap of type %u", trap->ttyp); - } + default: + feeltrap(trap); + impossible("You hit a trap of type %u", trap->ttyp); + } } STATIC_OVL char * @@ -1389,20 +1438,18 @@ trapnote(trap, noprefix) struct trap *trap; boolean noprefix; { - static char tnbuf[12]; - const char *tn, *tnnames[12] = { - "C note" , "D flat", "D note", - "E flat" , "E note", "F note", - "F sharp", "G note", "G sharp", - "A note" , "B flat", "B note" - }; - tnbuf[0] = '\0'; - tn = tnnames[trap->tnote]; - if (!noprefix) - Sprintf(tnbuf, "%s ", - (*tn == 'A' || *tn == 'E' || *tn == 'F') ? "an" : "a"); - Sprintf(eos(tnbuf), "%s", tn); - return tnbuf; + static char tnbuf[12]; + const char *tn, + *tnnames[12] = { "C note", "D flat", "D note", "E flat", + "E note", "F note", "F sharp", "G note", + "G sharp", "A note", "B flat", "B note" }; + tnbuf[0] = '\0'; + tn = tnnames[trap->tnote]; + if (!noprefix) + Sprintf(tnbuf, "%s ", + (*tn == 'A' || *tn == 'E' || *tn == 'F') ? "an" : "a"); + Sprintf(eos(tnbuf), "%s", tn); + return tnbuf; } STATIC_OVL int @@ -1410,75 +1457,75 @@ steedintrap(trap, otmp) struct trap *trap; struct obj *otmp; { - struct monst *steed = u.usteed; - int tt; - boolean trapkilled, steedhit; + struct monst *steed = u.usteed; + int tt; + boolean trapkilled, steedhit; - if (!steed || !trap) return 0; - tt = trap->ttyp; - steed->mx = u.ux; - steed->my = u.uy; - trapkilled = steedhit = FALSE; + if (!steed || !trap) + return 0; + tt = trap->ttyp; + steed->mx = u.ux; + steed->my = u.uy; + trapkilled = steedhit = FALSE; - switch (tt) { - case ARROW_TRAP: - if (!otmp) { - impossible("steed hit by non-existant arrow?"); - return 0; - } - trapkilled = thitm(8, steed, otmp, 0, FALSE); - steedhit = TRUE; - break; - case DART_TRAP: - if (!otmp) { - impossible("steed hit by non-existant dart?"); - return 0; - } - trapkilled = thitm(7, steed, otmp, 0, FALSE); - steedhit = TRUE; - break; - case SLP_GAS_TRAP: - if (!resists_sleep(steed) && !breathless(steed->data) && - !steed->msleeping && steed->mcanmove) { - if (sleep_monst(steed, rnd(25), -1)) - /* no in_sight check here; you can feel it even if blind */ - pline("%s suddenly falls asleep!", Monnam(steed)); - } - steedhit = TRUE; - break; - case LANDMINE: - trapkilled = thitm(0, steed, (struct obj *)0, rnd(16), FALSE); - steedhit = TRUE; - break; - case PIT: - case SPIKED_PIT: - trapkilled = (steed->mhp <= 0 || - thitm(0, steed, (struct obj *)0, - rnd((tt == PIT) ? 6 : 10), FALSE)); - steedhit = TRUE; - break; - case POLY_TRAP: - if (!resists_magm(steed) && - !resist(steed, WAND_CLASS, 0, NOTELL)) { - (void) newcham(steed, (struct permonst *)0, FALSE, FALSE); - if (!can_saddle(steed) || !can_ride(steed)) - dismount_steed(DISMOUNT_POLY); - else - You("have to adjust yourself in the saddle on %s.", - x_monnam(steed, ARTICLE_A, - (char *)0, SUPPRESS_SADDLE, FALSE)); - } - steedhit = TRUE; - break; - default: - break; - } + switch (tt) { + case ARROW_TRAP: + if (!otmp) { + impossible("steed hit by non-existant arrow?"); + return 0; + } + trapkilled = thitm(8, steed, otmp, 0, FALSE); + steedhit = TRUE; + break; + case DART_TRAP: + if (!otmp) { + impossible("steed hit by non-existant dart?"); + return 0; + } + trapkilled = thitm(7, steed, otmp, 0, FALSE); + steedhit = TRUE; + break; + case SLP_GAS_TRAP: + if (!resists_sleep(steed) && !breathless(steed->data) + && !steed->msleeping && steed->mcanmove) { + if (sleep_monst(steed, rnd(25), -1)) + /* no in_sight check here; you can feel it even if blind */ + pline("%s suddenly falls asleep!", Monnam(steed)); + } + steedhit = TRUE; + break; + case LANDMINE: + trapkilled = thitm(0, steed, (struct obj *) 0, rnd(16), FALSE); + steedhit = TRUE; + break; + case PIT: + case SPIKED_PIT: + trapkilled = + (steed->mhp <= 0 || thitm(0, steed, (struct obj *) 0, + rnd((tt == PIT) ? 6 : 10), FALSE)); + steedhit = TRUE; + break; + case POLY_TRAP: + if (!resists_magm(steed) && !resist(steed, WAND_CLASS, 0, NOTELL)) { + (void) newcham(steed, (struct permonst *) 0, FALSE, FALSE); + if (!can_saddle(steed) || !can_ride(steed)) + dismount_steed(DISMOUNT_POLY); + else + You("have to adjust yourself in the saddle on %s.", + x_monnam(steed, ARTICLE_A, (char *) 0, SUPPRESS_SADDLE, + FALSE)); + } + steedhit = TRUE; + break; + default: + break; + } - if (trapkilled) { - dismount_steed(DISMOUNT_POLY); - return 2; - } - return steedhit ? 1 : 0; + if (trapkilled) { + dismount_steed(DISMOUNT_POLY); + return 2; + } + return steedhit ? 1 : 0; } /* some actions common to both player and monsters for triggered landmine */ @@ -1489,31 +1536,31 @@ struct trap *trap; int x = trap->tx, y = trap->ty, dbx, dby; struct rm *lev = &levl[x][y]; - (void)scatter(x, y, 4, - MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS, - (struct obj *)0); + (void) scatter(x, y, 4, + MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS, + (struct obj *) 0); del_engr_at(x, y); wake_nearto(x, y, 400); if (IS_DOOR(lev->typ)) - lev->doormask = D_BROKEN; + lev->doormask = D_BROKEN; /* destroy drawbridge if present */ if (lev->typ == DRAWBRIDGE_DOWN || is_drawbridge_wall(x, y) >= 0) { - dbx = x, dby = y; - /* if under the portcullis, the bridge is adjacent */ - if (find_drawbridge(&dbx, &dby)) - destroy_drawbridge(dbx, dby); - trap = t_at(x, y); /* expected to be null after destruction */ + dbx = x, dby = y; + /* if under the portcullis, the bridge is adjacent */ + if (find_drawbridge(&dbx, &dby)) + destroy_drawbridge(dbx, dby); + trap = t_at(x, y); /* expected to be null after destruction */ } /* convert landmine into pit */ if (trap) { - if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { - /* no pits here */ - deltrap(trap); - } else { - trap->ttyp = PIT; /* explosion creates a pit */ - trap->madeby_u = FALSE; /* resulting pit isn't yours */ - seetrap(trap); /* and it isn't concealed */ - } + if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { + /* no pits here */ + deltrap(trap); + } else { + trap->ttyp = PIT; /* explosion creates a pit */ + trap->madeby_u = FALSE; /* resulting pit isn't yours */ + seetrap(trap); /* and it isn't concealed */ + } } } @@ -1523,40 +1570,41 @@ struct trap *trap; * will reappear at the launchplace in bones files. */ static struct { - struct obj *obj; - xchar x,y; + struct obj *obj; + xchar x, y; } launchplace; static void -launch_drop_spot(obj,x,y) +launch_drop_spot(obj, x, y) struct obj *obj; -xchar x,y; +xchar x, y; { - if (!obj) { - launchplace.obj = (struct obj *)0; - launchplace.x = 0; - launchplace.y = 0; - } else { - launchplace.obj = obj; - launchplace.x = x; - launchplace.y = y; - } + if (!obj) { + launchplace.obj = (struct obj *) 0; + launchplace.x = 0; + launchplace.y = 0; + } else { + launchplace.obj = obj; + launchplace.x = x; + launchplace.y = y; + } } boolean launch_in_progress() { - if (launchplace.obj) return TRUE; - return FALSE; + if (launchplace.obj) + return TRUE; + return FALSE; } void force_launch_placement() { - if (launchplace.obj) { - launchplace.obj->otrapped = 0; - place_object(launchplace.obj, launchplace.x, launchplace.y); - } + if (launchplace.obj) { + launchplace.obj->otrapped = 0; + place_object(launchplace.obj, launchplace.x, launchplace.y); + } } /* @@ -1569,255 +1617,264 @@ force_launch_placement() int launch_obj(otyp, x1, y1, x2, y2, style) short otyp; -register int x1,y1,x2,y2; +register int x1, y1, x2, y2; int style; { - register struct monst *mtmp; - register struct obj *otmp, *otmp2; - register int dx,dy; - struct obj *singleobj; - boolean used_up = FALSE; - boolean otherside = FALSE; - int dist; - int tmp; - int delaycnt = 0; + register struct monst *mtmp; + register struct obj *otmp, *otmp2; + register int dx, dy; + struct obj *singleobj; + boolean used_up = FALSE; + boolean otherside = FALSE; + int dist; + int tmp; + int delaycnt = 0; - otmp = sobj_at(otyp, x1, y1); - /* Try the other side too, for rolling boulder traps */ - if (!otmp && otyp == BOULDER) { - otherside = TRUE; - otmp = sobj_at(otyp, x2, y2); - } - if (!otmp) return 0; - if (otherside) { /* swap 'em */ - int tx, ty; + otmp = sobj_at(otyp, x1, y1); + /* Try the other side too, for rolling boulder traps */ + if (!otmp && otyp == BOULDER) { + otherside = TRUE; + otmp = sobj_at(otyp, x2, y2); + } + if (!otmp) + return 0; + if (otherside) { /* swap 'em */ + int tx, ty; - tx = x1; ty = y1; - x1 = x2; y1 = y2; - x2 = tx; y2 = ty; - } + tx = x1; + ty = y1; + x1 = x2; + y1 = y2; + x2 = tx; + y2 = ty; + } - if (otmp->quan == 1L) { - obj_extract_self(otmp); - singleobj = otmp; - otmp = (struct obj *) 0; - } else { - singleobj = splitobj(otmp, 1L); - obj_extract_self(singleobj); - } - newsym(x1,y1); - /* in case you're using a pick-axe to chop the boulder that's being - launched (perhaps a monster triggered it), destroy context so that - next dig attempt never thinks you're resuming previous effort */ - if ((otyp == BOULDER || otyp == STATUE) && - singleobj->ox == context.digging.pos.x && - singleobj->oy == context.digging.pos.y) - (void) memset((genericptr_t)&context.digging, 0, sizeof(struct dig_info)); + if (otmp->quan == 1L) { + obj_extract_self(otmp); + singleobj = otmp; + otmp = (struct obj *) 0; + } else { + singleobj = splitobj(otmp, 1L); + obj_extract_self(singleobj); + } + newsym(x1, y1); + /* in case you're using a pick-axe to chop the boulder that's being + launched (perhaps a monster triggered it), destroy context so that + next dig attempt never thinks you're resuming previous effort */ + if ((otyp == BOULDER || otyp == STATUE) + && singleobj->ox == context.digging.pos.x + && singleobj->oy == context.digging.pos.y) + (void) memset((genericptr_t) &context.digging, 0, + sizeof(struct dig_info)); - dist = distmin(x1,y1,x2,y2); - bhitpos.x = x1; - bhitpos.y = y1; - dx = sgn(x2 - x1); - dy = sgn(y2 - y1); - switch (style) { - case ROLL|LAUNCH_UNSEEN: - if (otyp == BOULDER) { - You_hear(Hallucination ? - "someone bowling." : - "rumbling in the distance."); - } - style &= ~LAUNCH_UNSEEN; - goto roll; - case ROLL|LAUNCH_KNOWN: - /* use otrapped as a flag to ohitmon */ - singleobj->otrapped = 1; - style &= ~LAUNCH_KNOWN; - /* fall through */ - roll: - case ROLL: - delaycnt = 2; - /* fall through */ - default: - if (!delaycnt) delaycnt = 1; - if (!cansee(bhitpos.x,bhitpos.y)) curs_on_u(); - tmp_at(DISP_FLASH, obj_to_glyph(singleobj)); - tmp_at(bhitpos.x, bhitpos.y); - } - /* Mark a spot to place object in bones files to prevent - * loss of object. Use the starting spot to ensure that - * a rolling boulder will still launch, which it wouldn't - * do if left midstream. Unfortunately we can't use the - * target resting spot, because there are some things/situations - * that would prevent it from ever getting there (bars), and we - * can't tell that yet. - */ - launch_drop_spot(singleobj, bhitpos.x, bhitpos.y); + dist = distmin(x1, y1, x2, y2); + bhitpos.x = x1; + bhitpos.y = y1; + dx = sgn(x2 - x1); + dy = sgn(y2 - y1); + switch (style) { + case ROLL | LAUNCH_UNSEEN: + if (otyp == BOULDER) { + You_hear(Hallucination ? "someone bowling." + : "rumbling in the distance."); + } + style &= ~LAUNCH_UNSEEN; + goto roll; + case ROLL | LAUNCH_KNOWN: + /* use otrapped as a flag to ohitmon */ + singleobj->otrapped = 1; + style &= ~LAUNCH_KNOWN; + /* fall through */ + roll: + case ROLL: + delaycnt = 2; + /* fall through */ + default: + if (!delaycnt) + delaycnt = 1; + if (!cansee(bhitpos.x, bhitpos.y)) + curs_on_u(); + tmp_at(DISP_FLASH, obj_to_glyph(singleobj)); + tmp_at(bhitpos.x, bhitpos.y); + } + /* Mark a spot to place object in bones files to prevent + * loss of object. Use the starting spot to ensure that + * a rolling boulder will still launch, which it wouldn't + * do if left midstream. Unfortunately we can't use the + * target resting spot, because there are some things/situations + * that would prevent it from ever getting there (bars), and we + * can't tell that yet. + */ + launch_drop_spot(singleobj, bhitpos.x, bhitpos.y); - /* Set the object in motion */ - while(dist-- > 0 && !used_up) { - struct trap *t; - tmp_at(bhitpos.x, bhitpos.y); - tmp = delaycnt; + /* Set the object in motion */ + while (dist-- > 0 && !used_up) { + struct trap *t; + tmp_at(bhitpos.x, bhitpos.y); + tmp = delaycnt; - /* dstage@u.washington.edu -- Delay only if hero sees it */ - if (cansee(bhitpos.x, bhitpos.y)) - while (tmp-- > 0) delay_output(); + /* dstage@u.washington.edu -- Delay only if hero sees it */ + if (cansee(bhitpos.x, bhitpos.y)) + while (tmp-- > 0) + delay_output(); - bhitpos.x += dx; - bhitpos.y += dy; - t = t_at(bhitpos.x, bhitpos.y); - - if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { - if (otyp == BOULDER && throws_rocks(mtmp->data)) { - if (rn2(3)) { - pline("%s snatches the boulder.", - Monnam(mtmp)); - singleobj->otrapped = 0; - (void) mpickobj(mtmp, singleobj); - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - break; - } - } - if (ohitmon(mtmp,singleobj, - (style==ROLL) ? -1 : dist, FALSE)) { - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - break; - } - } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { - if (multi) nomul(0); - if (thitu(9 + singleobj->spe, - dmgval(singleobj, &youmonst), - singleobj, (char *)0)) - stop_occupation(); - } - if (style == ROLL) { - if (down_gate(bhitpos.x, bhitpos.y) != -1) { - if(ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)){ - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - break; - } - } - if (t && otyp == BOULDER) { - switch(t->ttyp) { - case LANDMINE: - if (rn2(10) > 2) { - pline( - "KAABLAMM!!!%s", - cansee(bhitpos.x, bhitpos.y) ? - " The rolling boulder triggers a land mine." : ""); - deltrap(t); - del_engr_at(bhitpos.x,bhitpos.y); - place_object(singleobj, bhitpos.x, bhitpos.y); - singleobj->otrapped = 0; - fracture_rock(singleobj); - (void)scatter(bhitpos.x,bhitpos.y, 4, - MAY_DESTROY|MAY_HIT|MAY_FRACTURE|VIS_EFFECTS, - (struct obj *)0); - if (cansee(bhitpos.x,bhitpos.y)) - newsym(bhitpos.x,bhitpos.y); - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - } - break; - case LEVEL_TELEP: - case TELEP_TRAP: - if (cansee(bhitpos.x, bhitpos.y)) - pline("Suddenly the rolling boulder disappears!"); - else - You_hear("a rumbling stop abruptly."); - singleobj->otrapped = 0; - if (t->ttyp == TELEP_TRAP) - (void)rloco(singleobj); - else { - int newlev = random_teleport_level(); - d_level dest; + bhitpos.x += dx; + bhitpos.y += dy; + t = t_at(bhitpos.x, bhitpos.y); - if (newlev == depth(&u.uz) || In_endgame(&u.uz)) - continue; - add_to_migration(singleobj); - get_level(&dest, newlev); - singleobj->ox = dest.dnum; - singleobj->oy = dest.dlevel; - singleobj->owornmask = (long)MIGR_RANDOM; - } - seetrap(t); - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - break; - case PIT: - case SPIKED_PIT: - case HOLE: - case TRAPDOOR: - /* the boulder won't be used up if there is a - monster in the trap; stop rolling anyway */ - x2 = bhitpos.x, y2 = bhitpos.y; /* stops here */ - if (flooreffects(singleobj, x2, y2, "fall")) { - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - } - dist = -1; /* stop rolling immediately */ - break; - } - if (used_up || dist == -1) break; - } - if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) { - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - break; - } - if (otyp == BOULDER && - (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) { - const char *bmsg = - " as one boulder sets another in motion"; + if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { + if (otyp == BOULDER && throws_rocks(mtmp->data)) { + if (rn2(3)) { + pline("%s snatches the boulder.", Monnam(mtmp)); + singleobj->otrapped = 0; + (void) mpickobj(mtmp, singleobj); + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + break; + } + } + if (ohitmon(mtmp, singleobj, (style == ROLL) ? -1 : dist, + FALSE)) { + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + break; + } + } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { + if (multi) + nomul(0); + if (thitu(9 + singleobj->spe, dmgval(singleobj, &youmonst), + singleobj, (char *) 0)) + stop_occupation(); + } + if (style == ROLL) { + if (down_gate(bhitpos.x, bhitpos.y) != -1) { + if (ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)) { + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + break; + } + } + if (t && otyp == BOULDER) { + switch (t->ttyp) { + case LANDMINE: + if (rn2(10) > 2) { + pline( + "KAABLAMM!!!%s", + cansee(bhitpos.x, bhitpos.y) + ? " The rolling boulder triggers a land mine." + : ""); + deltrap(t); + del_engr_at(bhitpos.x, bhitpos.y); + place_object(singleobj, bhitpos.x, bhitpos.y); + singleobj->otrapped = 0; + fracture_rock(singleobj); + (void) scatter(bhitpos.x, bhitpos.y, 4, + MAY_DESTROY | MAY_HIT | MAY_FRACTURE + | VIS_EFFECTS, + (struct obj *) 0); + if (cansee(bhitpos.x, bhitpos.y)) + newsym(bhitpos.x, bhitpos.y); + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + } + break; + case LEVEL_TELEP: + case TELEP_TRAP: + if (cansee(bhitpos.x, bhitpos.y)) + pline("Suddenly the rolling boulder disappears!"); + else + You_hear("a rumbling stop abruptly."); + singleobj->otrapped = 0; + if (t->ttyp == TELEP_TRAP) + (void) rloco(singleobj); + else { + int newlev = random_teleport_level(); + d_level dest; - if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist || - IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)) - bmsg = " as one boulder hits another"; + if (newlev == depth(&u.uz) || In_endgame(&u.uz)) + continue; + add_to_migration(singleobj); + get_level(&dest, newlev); + singleobj->ox = dest.dnum; + singleobj->oy = dest.dlevel; + singleobj->owornmask = (long) MIGR_RANDOM; + } + seetrap(t); + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + break; + case PIT: + case SPIKED_PIT: + case HOLE: + case TRAPDOOR: + /* the boulder won't be used up if there is a + monster in the trap; stop rolling anyway */ + x2 = bhitpos.x, y2 = bhitpos.y; /* stops here */ + if (flooreffects(singleobj, x2, y2, "fall")) { + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + } + dist = -1; /* stop rolling immediately */ + break; + } + if (used_up || dist == -1) + break; + } + if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) { + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + break; + } + if (otyp == BOULDER + && (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) { + const char *bmsg = " as one boulder sets another in motion"; - You_hear("a loud crash%s!", - cansee(bhitpos.x, bhitpos.y) ? bmsg : ""); - obj_extract_self(otmp2); - /* pass off the otrapped flag to the next boulder */ - otmp2->otrapped = singleobj->otrapped; - singleobj->otrapped = 0; - place_object(singleobj, bhitpos.x, bhitpos.y); - singleobj = otmp2; - otmp2 = (struct obj *)0; - wake_nearto(bhitpos.x, bhitpos.y, 10*10); - } - } - if (otyp == BOULDER && closed_door(bhitpos.x,bhitpos.y)) { - if (cansee(bhitpos.x, bhitpos.y)) - pline_The("boulder crashes through a door."); - levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN; - if (dist) unblock_point(bhitpos.x, bhitpos.y); - } + if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist + || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)) + bmsg = " as one boulder hits another"; - /* if about to hit iron bars, do so now */ - if (dist > 0 && isok(bhitpos.x + dx,bhitpos.y + dy) && - levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) { - x2 = bhitpos.x, y2 = bhitpos.y; /* object stops here */ - if (hits_bars(&singleobj, x2, y2, !rn2(20), 0)) { - if (!singleobj) { - used_up = TRUE; - launch_drop_spot((struct obj *)0, 0, 0); - } - break; - } - } - } - tmp_at(DISP_END, 0); - launch_drop_spot((struct obj *)0, 0, 0); - if (!used_up) { - singleobj->otrapped = 0; - place_object(singleobj, x2,y2); - newsym(x2,y2); - return 1; - } else - return 2; + You_hear("a loud crash%s!", + cansee(bhitpos.x, bhitpos.y) ? bmsg : ""); + obj_extract_self(otmp2); + /* pass off the otrapped flag to the next boulder */ + otmp2->otrapped = singleobj->otrapped; + singleobj->otrapped = 0; + place_object(singleobj, bhitpos.x, bhitpos.y); + singleobj = otmp2; + otmp2 = (struct obj *) 0; + wake_nearto(bhitpos.x, bhitpos.y, 10 * 10); + } + } + if (otyp == BOULDER && closed_door(bhitpos.x, bhitpos.y)) { + if (cansee(bhitpos.x, bhitpos.y)) + pline_The("boulder crashes through a door."); + levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN; + if (dist) + unblock_point(bhitpos.x, bhitpos.y); + } + + /* if about to hit iron bars, do so now */ + if (dist > 0 && isok(bhitpos.x + dx, bhitpos.y + dy) + && levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) { + x2 = bhitpos.x, y2 = bhitpos.y; /* object stops here */ + if (hits_bars(&singleobj, x2, y2, !rn2(20), 0)) { + if (!singleobj) { + used_up = TRUE; + launch_drop_spot((struct obj *) 0, 0, 0); + } + break; + } + } + } + tmp_at(DISP_END, 0); + launch_drop_spot((struct obj *) 0, 0, 0); + if (!used_up) { + singleobj->otrapped = 0; + place_object(singleobj, x2, y2); + newsym(x2, y2); + return 1; + } else + return 2; } void @@ -1825,8 +1882,8 @@ seetrap(trap) struct trap *trap; { if (!trap->tseen) { - trap->tseen = 1; - newsym(trap->tx, trap->ty); + trap->tseen = 1; + newsym(trap->tx, trap->ty); } } @@ -1844,679 +1901,703 @@ struct trap *trap; STATIC_OVL int mkroll_launch(ttmp, x, y, otyp, ocount) struct trap *ttmp; -xchar x,y; +xchar x, y; short otyp; long ocount; { - struct obj *otmp; - register int tmp; - schar dx,dy; - int distance; - coord cc; - coord bcc; - int trycount = 0; - boolean success = FALSE; - int mindist = 4; + struct obj *otmp; + register int tmp; + schar dx, dy; + int distance; + coord cc; + coord bcc; + int trycount = 0; + boolean success = FALSE; + int mindist = 4; - if (ttmp->ttyp == ROLLING_BOULDER_TRAP) mindist = 2; - distance = rn1(5,4); /* 4..8 away */ - tmp = rn2(8); /* randomly pick a direction to try first */ - while (distance >= mindist) { - dx = xdir[tmp]; - dy = ydir[tmp]; - cc.x = x; cc.y = y; - /* Prevent boulder from being placed on water */ - if (ttmp->ttyp == ROLLING_BOULDER_TRAP - && is_pool_or_lava(x+distance*dx,y+distance*dy)) - success = FALSE; - else success = isclearpath(&cc, distance, dx, dy); - if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { - boolean success_otherway; - bcc.x = x; bcc.y = y; - success_otherway = isclearpath(&bcc, distance, - -(dx), -(dy)); - if (!success_otherway) success = FALSE; - } - if (success) break; - if (++tmp > 7) tmp = 0; - if ((++trycount % 8) == 0) --distance; - } - if (!success) { - /* create the trap without any ammo, launch pt at trap location */ - cc.x = bcc.x = x; - cc.y = bcc.y = y; - } else { - otmp = mksobj(otyp, TRUE, FALSE); - otmp->quan = ocount; - otmp->owt = weight(otmp); - place_object(otmp, cc.x, cc.y); - stackobj(otmp); - } - ttmp->launch.x = cc.x; - ttmp->launch.y = cc.y; - if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { - ttmp->launch2.x = bcc.x; - ttmp->launch2.y = bcc.y; - } else - ttmp->launch_otyp = otyp; - newsym(ttmp->launch.x, ttmp->launch.y); - return 1; + if (ttmp->ttyp == ROLLING_BOULDER_TRAP) + mindist = 2; + distance = rn1(5, 4); /* 4..8 away */ + tmp = rn2(8); /* randomly pick a direction to try first */ + while (distance >= mindist) { + dx = xdir[tmp]; + dy = ydir[tmp]; + cc.x = x; + cc.y = y; + /* Prevent boulder from being placed on water */ + if (ttmp->ttyp == ROLLING_BOULDER_TRAP + && is_pool_or_lava(x + distance * dx, y + distance * dy)) + success = FALSE; + else + success = isclearpath(&cc, distance, dx, dy); + if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { + boolean success_otherway; + bcc.x = x; + bcc.y = y; + success_otherway = isclearpath(&bcc, distance, -(dx), -(dy)); + if (!success_otherway) + success = FALSE; + } + if (success) + break; + if (++tmp > 7) + tmp = 0; + if ((++trycount % 8) == 0) + --distance; + } + if (!success) { + /* create the trap without any ammo, launch pt at trap location */ + cc.x = bcc.x = x; + cc.y = bcc.y = y; + } else { + otmp = mksobj(otyp, TRUE, FALSE); + otmp->quan = ocount; + otmp->owt = weight(otmp); + place_object(otmp, cc.x, cc.y); + stackobj(otmp); + } + ttmp->launch.x = cc.x; + ttmp->launch.y = cc.y; + if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { + ttmp->launch2.x = bcc.x; + ttmp->launch2.y = bcc.y; + } else + ttmp->launch_otyp = otyp; + newsym(ttmp->launch.x, ttmp->launch.y); + return 1; } STATIC_OVL boolean -isclearpath(cc,distance,dx,dy) +isclearpath(cc, distance, dx, dy) coord *cc; int distance; -schar dx,dy; +schar dx, dy; { - uchar typ; - xchar x, y; + uchar typ; + xchar x, y; - x = cc->x; - y = cc->y; - while (distance-- > 0) { - x += dx; - y += dy; - typ = levl[x][y].typ; - if (!isok(x,y) || !ZAP_POS(typ) || closed_door(x,y)) - return FALSE; - } - cc->x = x; - cc->y = y; - return TRUE; + x = cc->x; + y = cc->y; + while (distance-- > 0) { + x += dx; + y += dy; + typ = levl[x][y].typ; + if (!isok(x, y) || !ZAP_POS(typ) || closed_door(x, y)) + return FALSE; + } + cc->x = x; + cc->y = y; + return TRUE; } int mintrap(mtmp) register struct monst *mtmp; { - register struct trap *trap = t_at(mtmp->mx, mtmp->my); - boolean trapkilled = FALSE; - struct permonst *mptr = mtmp->data; - struct obj *otmp; + register struct trap *trap = t_at(mtmp->mx, mtmp->my); + boolean trapkilled = FALSE; + struct permonst *mptr = mtmp->data; + struct obj *otmp; - if (!trap) { - mtmp->mtrapped = 0; /* perhaps teleported? */ - } else if (mtmp->mtrapped) { /* is currently in the trap */ - if (!trap->tseen && - cansee(mtmp->mx, mtmp->my) && canseemon(mtmp) && - (trap->ttyp == SPIKED_PIT || trap->ttyp == BEAR_TRAP || - trap->ttyp == HOLE || trap->ttyp == PIT || - trap->ttyp == WEB)) { - /* If you come upon an obviously trapped monster, then - * you must be able to see the trap it's in too. - */ - seetrap(trap); - } - - if (!rn2(40)) { - if (sobj_at(BOULDER, mtmp->mx, mtmp->my) && - (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { - if (!rn2(2)) { - mtmp->mtrapped = 0; - if (canseemon(mtmp)) - pline("%s pulls free...", Monnam(mtmp)); - fill_pit(mtmp->mx, mtmp->my); - } - } else { - mtmp->mtrapped = 0; - } - } else if (metallivorous(mptr)) { - if (trap->ttyp == BEAR_TRAP) { - if (canseemon(mtmp)) - pline("%s eats a bear trap!", Monnam(mtmp)); - deltrap(trap); - mtmp->meating = 5; - mtmp->mtrapped = 0; - } else if (trap->ttyp == SPIKED_PIT) { - if (canseemon(mtmp)) - pline("%s munches on some spikes!", Monnam(mtmp)); - trap->ttyp = PIT; - mtmp->meating = 5; - } - } - } else { - register int tt = trap->ttyp; - boolean in_sight, tear_web, see_it, - inescapable = force_mintrap || - ((tt == HOLE || tt == PIT) && - Sokoban && !trap->madeby_u); - const char *fallverb; + if (!trap) { + mtmp->mtrapped = 0; /* perhaps teleported? */ + } else if (mtmp->mtrapped) { /* is currently in the trap */ + if (!trap->tseen && cansee(mtmp->mx, mtmp->my) && canseemon(mtmp) + && (trap->ttyp == SPIKED_PIT || trap->ttyp == BEAR_TRAP + || trap->ttyp == HOLE || trap->ttyp == PIT + || trap->ttyp == WEB)) { + /* If you come upon an obviously trapped monster, then + * you must be able to see the trap it's in too. + */ + seetrap(trap); + } - /* true when called from dotrap, inescapable is not an option */ - if (mtmp == u.usteed) inescapable = TRUE; - if (!inescapable && - ((mtmp->mtrapseen & (1 << (tt-1))) != 0 || - (tt == HOLE && !mindless(mptr)))) { - /* it has been in such a trap - perhaps it escapes */ - if(rn2(4)) return(0); - } else { - mtmp->mtrapseen |= (1 << (tt-1)); - } - /* Monster is aggravated by being trapped by you. - Recognizing who made the trap isn't completely - unreasonable; everybody has their own style. */ - if (trap->madeby_u && rnl(5)) setmangry(mtmp); + if (!rn2(40)) { + if (sobj_at(BOULDER, mtmp->mx, mtmp->my) + && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { + if (!rn2(2)) { + mtmp->mtrapped = 0; + if (canseemon(mtmp)) + pline("%s pulls free...", Monnam(mtmp)); + fill_pit(mtmp->mx, mtmp->my); + } + } else { + mtmp->mtrapped = 0; + } + } else if (metallivorous(mptr)) { + if (trap->ttyp == BEAR_TRAP) { + if (canseemon(mtmp)) + pline("%s eats a bear trap!", Monnam(mtmp)); + deltrap(trap); + mtmp->meating = 5; + mtmp->mtrapped = 0; + } else if (trap->ttyp == SPIKED_PIT) { + if (canseemon(mtmp)) + pline("%s munches on some spikes!", Monnam(mtmp)); + trap->ttyp = PIT; + mtmp->meating = 5; + } + } + } else { + register int tt = trap->ttyp; + boolean in_sight, tear_web, see_it, + inescapable = force_mintrap || ((tt == HOLE || tt == PIT) + && Sokoban && !trap->madeby_u); + const char *fallverb; - in_sight = canseemon(mtmp); - see_it = cansee(mtmp->mx, mtmp->my); - /* assume hero can tell what's going on for the steed */ - if (mtmp == u.usteed) in_sight = TRUE; - switch (tt) { - case ARROW_TRAP: - if (trap->once && trap->tseen && !rn2(15)) { - if (in_sight && see_it) - pline("%s triggers a trap but nothing happens.", - Monnam(mtmp)); - deltrap(trap); - newsym(mtmp->mx, mtmp->my); - break; - } - trap->once = 1; - otmp = mksobj(ARROW, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); - otmp->opoisoned = 0; - if (in_sight) seetrap(trap); - if (thitm(8, mtmp, otmp, 0, FALSE)) trapkilled = TRUE; - break; - case DART_TRAP: - if (trap->once && trap->tseen && !rn2(15)) { - if (in_sight && see_it) - pline("%s triggers a trap but nothing happens.", - Monnam(mtmp)); - deltrap(trap); - newsym(mtmp->mx, mtmp->my); - break; - } - trap->once = 1; - otmp = mksobj(DART, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); - if (!rn2(6)) otmp->opoisoned = 1; - if (in_sight) seetrap(trap); - if (thitm(7, mtmp, otmp, 0, FALSE)) trapkilled = TRUE; - break; - case ROCKTRAP: - if (trap->once && trap->tseen && !rn2(15)) { - if (in_sight && see_it) - pline("A trap door above %s opens, but nothing falls out!", - mon_nam(mtmp)); - deltrap(trap); - newsym(mtmp->mx, mtmp->my); - break; - } - trap->once = 1; - otmp = mksobj(ROCK, TRUE, FALSE); - otmp->quan = 1L; - otmp->owt = weight(otmp); - if (in_sight) seetrap(trap); - if (thitm(0, mtmp, otmp, d(2, 6), FALSE)) - trapkilled = TRUE; - break; + /* true when called from dotrap, inescapable is not an option */ + if (mtmp == u.usteed) + inescapable = TRUE; + if (!inescapable && ((mtmp->mtrapseen & (1 << (tt - 1))) != 0 + || (tt == HOLE && !mindless(mptr)))) { + /* it has been in such a trap - perhaps it escapes */ + if (rn2(4)) + return (0); + } else { + mtmp->mtrapseen |= (1 << (tt - 1)); + } + /* Monster is aggravated by being trapped by you. + Recognizing who made the trap isn't completely + unreasonable; everybody has their own style. */ + if (trap->madeby_u && rnl(5)) + setmangry(mtmp); - case SQKY_BOARD: - if(is_flyer(mptr)) break; - /* stepped on a squeaky board */ - if (in_sight) { - if (!Deaf) { - pline("A board beneath %s squeaks %s loudly.", - mon_nam(mtmp), trapnote(trap,0)); - seetrap(trap); - } else { - pline("%s stops momentarily and appears to cringe.", - Monnam(mtmp)); - } - } else - You_hear("a distant %s squeak.", - trapnote(trap,1)); - /* wake up nearby monsters */ - wake_nearto(mtmp->mx, mtmp->my, 40); - break; + in_sight = canseemon(mtmp); + see_it = cansee(mtmp->mx, mtmp->my); + /* assume hero can tell what's going on for the steed */ + if (mtmp == u.usteed) + in_sight = TRUE; + switch (tt) { + case ARROW_TRAP: + if (trap->once && trap->tseen && !rn2(15)) { + if (in_sight && see_it) + pline("%s triggers a trap but nothing happens.", + Monnam(mtmp)); + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + break; + } + trap->once = 1; + otmp = mksobj(ARROW, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + otmp->opoisoned = 0; + if (in_sight) + seetrap(trap); + if (thitm(8, mtmp, otmp, 0, FALSE)) + trapkilled = TRUE; + break; + case DART_TRAP: + if (trap->once && trap->tseen && !rn2(15)) { + if (in_sight && see_it) + pline("%s triggers a trap but nothing happens.", + Monnam(mtmp)); + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + break; + } + trap->once = 1; + otmp = mksobj(DART, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + if (!rn2(6)) + otmp->opoisoned = 1; + if (in_sight) + seetrap(trap); + if (thitm(7, mtmp, otmp, 0, FALSE)) + trapkilled = TRUE; + break; + case ROCKTRAP: + if (trap->once && trap->tseen && !rn2(15)) { + if (in_sight && see_it) + pline( + "A trap door above %s opens, but nothing falls out!", + mon_nam(mtmp)); + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + break; + } + trap->once = 1; + otmp = mksobj(ROCK, TRUE, FALSE); + otmp->quan = 1L; + otmp->owt = weight(otmp); + if (in_sight) + seetrap(trap); + if (thitm(0, mtmp, otmp, d(2, 6), FALSE)) + trapkilled = TRUE; + break; - case BEAR_TRAP: - if(mptr->msize > MZ_SMALL && - !amorphous(mptr) && !is_flyer(mptr) && - !is_whirly(mptr) && !unsolid(mptr)) { - mtmp->mtrapped = 1; - if(in_sight) { - pline("%s is caught in %s bear trap!", - Monnam(mtmp), a_your[trap->madeby_u]); - seetrap(trap); - } else { - if(mptr == &mons[PM_OWLBEAR] - || mptr == &mons[PM_BUGBEAR]) - You_hear("the roaring of an angry bear!"); - } - } else if (force_mintrap) { - if (in_sight) { - pline("%s evades %s bear trap!", - Monnam(mtmp), a_your[trap->madeby_u]); - seetrap(trap); - } - } - if (mtmp->mtrapped) - trapkilled = thitm(0, mtmp, (struct obj *)0, - d(2, 4), FALSE); - break; + case SQKY_BOARD: + if (is_flyer(mptr)) + break; + /* stepped on a squeaky board */ + if (in_sight) { + if (!Deaf) { + pline("A board beneath %s squeaks %s loudly.", + mon_nam(mtmp), trapnote(trap, 0)); + seetrap(trap); + } else { + pline("%s stops momentarily and appears to cringe.", + Monnam(mtmp)); + } + } else + You_hear("a distant %s squeak.", trapnote(trap, 1)); + /* wake up nearby monsters */ + wake_nearto(mtmp->mx, mtmp->my, 40); + break; - case SLP_GAS_TRAP: - if (!resists_sleep(mtmp) && !breathless(mptr) && - !mtmp->msleeping && mtmp->mcanmove) { - if (sleep_monst(mtmp, rnd(25), -1) && in_sight) { - pline("%s suddenly falls asleep!", - Monnam(mtmp)); - seetrap(trap); - } - } - break; + case BEAR_TRAP: + if (mptr->msize > MZ_SMALL && !amorphous(mptr) && !is_flyer(mptr) + && !is_whirly(mptr) && !unsolid(mptr)) { + mtmp->mtrapped = 1; + if (in_sight) { + pline("%s is caught in %s bear trap!", Monnam(mtmp), + a_your[trap->madeby_u]); + seetrap(trap); + } else { + if (mptr == &mons[PM_OWLBEAR] + || mptr == &mons[PM_BUGBEAR]) + You_hear("the roaring of an angry bear!"); + } + } else if (force_mintrap) { + if (in_sight) { + pline("%s evades %s bear trap!", Monnam(mtmp), + a_your[trap->madeby_u]); + seetrap(trap); + } + } + if (mtmp->mtrapped) + trapkilled = thitm(0, mtmp, (struct obj *) 0, d(2, 4), FALSE); + break; - case RUST_TRAP: - { - struct obj *target; + case SLP_GAS_TRAP: + if (!resists_sleep(mtmp) && !breathless(mptr) && !mtmp->msleeping + && mtmp->mcanmove) { + if (sleep_monst(mtmp, rnd(25), -1) && in_sight) { + pline("%s suddenly falls asleep!", Monnam(mtmp)); + seetrap(trap); + } + } + break; - if (in_sight) - seetrap(trap); - switch (rn2(5)) { - case 0: - if (in_sight) - pline("%s %s on the %s!", A_gush_of_water_hits, - mon_nam(mtmp), mbodypart(mtmp, HEAD)); - target = which_armor(mtmp, W_ARMH); - (void) water_damage(target, helm_simple_name(target), - TRUE); - break; - case 1: - if (in_sight) - pline("%s %s's left %s!", A_gush_of_water_hits, - mon_nam(mtmp), mbodypart(mtmp, ARM)); - target = which_armor(mtmp, W_ARMS); - if (water_damage(target, "shield", TRUE) != ER_NOTHING) - break; - target = MON_WEP(mtmp); - if (target && bimanual(target)) - (void) water_damage(target, 0, TRUE); -glovecheck: target = which_armor(mtmp, W_ARMG); - (void) water_damage(target, "gauntlets", TRUE); - break; - case 2: - if (in_sight) - pline("%s %s's right %s!", A_gush_of_water_hits, - mon_nam(mtmp), mbodypart(mtmp, ARM)); - (void) water_damage(MON_WEP(mtmp), 0, TRUE); - goto glovecheck; - default: - if (in_sight) - pline("%s %s!", A_gush_of_water_hits, - mon_nam(mtmp)); - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if (otmp->lamplit && - (otmp->owornmask & (W_WEP|W_SWAPWEP)) == 0) - (void) snuff_lit(otmp); - if ((target = which_armor(mtmp, W_ARMC)) != 0) - (void) water_damage(target, - cloak_simple_name(target), - TRUE); - else if ((target = which_armor(mtmp, W_ARM)) != 0) - (void) water_damage(target, "armor", TRUE); - else if ((target = which_armor(mtmp, W_ARMU)) != 0) - (void) water_damage(target, "shirt", TRUE); - } + case RUST_TRAP: { + struct obj *target; - if (mptr == &mons[PM_IRON_GOLEM]) { - if (in_sight) - pline("%s falls to pieces!", Monnam(mtmp)); - else if(mtmp->mtame) - pline("May %s rust in peace.", - mon_nam(mtmp)); - mondied(mtmp); - if (mtmp->mhp <= 0) - trapkilled = TRUE; - } else if (mptr == &mons[PM_GREMLIN] && rn2(3)) { - (void)split_mon(mtmp, (struct monst *)0); - } - break; - } - case FIRE_TRAP: - mfiretrap: - if (in_sight) - pline("A %s erupts from the %s under %s!", - tower_of_flame, - surface(mtmp->mx,mtmp->my), mon_nam(mtmp)); - else if (see_it) /* evidently `mtmp' is invisible */ - You_see("a %s erupt from the %s!", - tower_of_flame, surface(mtmp->mx,mtmp->my)); + if (in_sight) + seetrap(trap); + switch (rn2(5)) { + case 0: + if (in_sight) + pline("%s %s on the %s!", A_gush_of_water_hits, + mon_nam(mtmp), mbodypart(mtmp, HEAD)); + target = which_armor(mtmp, W_ARMH); + (void) water_damage(target, helm_simple_name(target), TRUE); + break; + case 1: + if (in_sight) + pline("%s %s's left %s!", A_gush_of_water_hits, + mon_nam(mtmp), mbodypart(mtmp, ARM)); + target = which_armor(mtmp, W_ARMS); + if (water_damage(target, "shield", TRUE) != ER_NOTHING) + break; + target = MON_WEP(mtmp); + if (target && bimanual(target)) + (void) water_damage(target, 0, TRUE); + glovecheck: + target = which_armor(mtmp, W_ARMG); + (void) water_damage(target, "gauntlets", TRUE); + break; + case 2: + if (in_sight) + pline("%s %s's right %s!", A_gush_of_water_hits, + mon_nam(mtmp), mbodypart(mtmp, ARM)); + (void) water_damage(MON_WEP(mtmp), 0, TRUE); + goto glovecheck; + default: + if (in_sight) + pline("%s %s!", A_gush_of_water_hits, mon_nam(mtmp)); + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->lamplit + && (otmp->owornmask & (W_WEP | W_SWAPWEP)) == 0) + (void) snuff_lit(otmp); + if ((target = which_armor(mtmp, W_ARMC)) != 0) + (void) water_damage(target, cloak_simple_name(target), + TRUE); + else if ((target = which_armor(mtmp, W_ARM)) != 0) + (void) water_damage(target, "armor", TRUE); + else if ((target = which_armor(mtmp, W_ARMU)) != 0) + (void) water_damage(target, "shirt", TRUE); + } - if (resists_fire(mtmp)) { - if (in_sight) { - shieldeff(mtmp->mx,mtmp->my); - pline("%s is uninjured.", Monnam(mtmp)); - } - } else { - int num = d(2,4), alt; - boolean immolate = FALSE; + if (mptr == &mons[PM_IRON_GOLEM]) { + if (in_sight) + pline("%s falls to pieces!", Monnam(mtmp)); + else if (mtmp->mtame) + pline("May %s rust in peace.", mon_nam(mtmp)); + mondied(mtmp); + if (mtmp->mhp <= 0) + trapkilled = TRUE; + } else if (mptr == &mons[PM_GREMLIN] && rn2(3)) { + (void) split_mon(mtmp, (struct monst *) 0); + } + break; + } + case FIRE_TRAP: + mfiretrap: + if (in_sight) + pline("A %s erupts from the %s under %s!", tower_of_flame, + surface(mtmp->mx, mtmp->my), mon_nam(mtmp)); + else if (see_it) /* evidently `mtmp' is invisible */ + You_see("a %s erupt from the %s!", tower_of_flame, + surface(mtmp->mx, mtmp->my)); - /* paper burns very fast, assume straw is tightly - * packed and burns a bit slower */ - switch (monsndx(mptr)) { - case PM_PAPER_GOLEM: immolate = TRUE; - alt = mtmp->mhpmax; break; - case PM_STRAW_GOLEM: alt = mtmp->mhpmax / 2; break; - case PM_WOOD_GOLEM: alt = mtmp->mhpmax / 4; break; - case PM_LEATHER_GOLEM: alt = mtmp->mhpmax / 8; break; - default: alt = 0; break; - } - if (alt > num) num = alt; + if (resists_fire(mtmp)) { + if (in_sight) { + shieldeff(mtmp->mx, mtmp->my); + pline("%s is uninjured.", Monnam(mtmp)); + } + } else { + int num = d(2, 4), alt; + boolean immolate = FALSE; - if (thitm(0, mtmp, (struct obj *)0, num, immolate)) - trapkilled = TRUE; - else - /* we know mhp is at least `num' below mhpmax, - so no (mhp > mhpmax) check is needed here */ - mtmp->mhpmax -= rn2(num + 1); - } - if (burnarmor(mtmp) || rn2(3)) { - (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); - (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); - (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); - } - if (burn_floor_objects(mtmp->mx, mtmp->my, see_it, FALSE) && - !see_it && distu(mtmp->mx, mtmp->my) <= 3*3) - You("smell smoke."); - if (is_ice(mtmp->mx,mtmp->my)) - melt_ice(mtmp->mx,mtmp->my, (char *)0); - if (see_it) seetrap(trap); - break; + /* paper burns very fast, assume straw is tightly + * packed and burns a bit slower */ + switch (monsndx(mptr)) { + case PM_PAPER_GOLEM: + immolate = TRUE; + alt = mtmp->mhpmax; + break; + case PM_STRAW_GOLEM: + alt = mtmp->mhpmax / 2; + break; + case PM_WOOD_GOLEM: + alt = mtmp->mhpmax / 4; + break; + case PM_LEATHER_GOLEM: + alt = mtmp->mhpmax / 8; + break; + default: + alt = 0; + break; + } + if (alt > num) + num = alt; - case PIT: - case SPIKED_PIT: - fallverb = "falls"; - if (is_flyer(mptr) || is_floater(mptr) || - (mtmp->wormno && count_wsegs(mtmp) > 5) || - is_clinger(mptr)) { - if (force_mintrap && !Sokoban) { - /* openfallingtrap; not inescapable here */ - if (in_sight) { - seetrap(trap); - pline("%s doesn't fall into the pit.", - Monnam(mtmp)); - } - break; /* inescapable = FALSE; */ - } - if (!inescapable) break; /* avoids trap */ - fallverb = "is dragged"; /* sokoban pit */ - } - if (!passes_walls(mptr)) - mtmp->mtrapped = 1; - if (in_sight) { - pline("%s %s into %s pit!", - Monnam(mtmp), fallverb, - a_your[trap->madeby_u]); - if (mptr == &mons[PM_PIT_VIPER] || - mptr == &mons[PM_PIT_FIEND]) - pline("How pitiful. Isn't that the pits?"); - seetrap(trap); - } - mselftouch(mtmp, "Falling, ", FALSE); - if (mtmp->mhp <= 0 || - thitm(0, mtmp, (struct obj *)0, - rnd((tt == PIT) ? 6 : 10), FALSE)) - trapkilled = TRUE; - break; - case HOLE: - case TRAPDOOR: - if (!Can_fall_thru(&u.uz)) { - impossible("mintrap: %ss cannot exist on this level.", - defsyms[trap_to_defsym(tt)].explanation); - break; /* don't activate it after all */ - } - if (is_flyer(mptr) || is_floater(mptr) || - mptr == &mons[PM_WUMPUS] || - (mtmp->wormno && count_wsegs(mtmp) > 5) || - mptr->msize >= MZ_HUGE) { - if (force_mintrap && !Sokoban) { - /* openfallingtrap; not inescapable here */ - if (in_sight) { - seetrap(trap); - if (tt == TRAPDOOR) - pline( - "A trap door opens, but %s doesn't fall through.", - mon_nam(mtmp)); - else /* (tt == HOLE) */ - pline( - "%s doesn't fall through the hole.", - Monnam(mtmp)); - } - break; /* inescapable = FALSE; */ - } - if (inescapable) { /* sokoban hole */ - if (in_sight) { - pline("%s seems to be yanked down!", - Monnam(mtmp)); - /* suppress message in mlevel_tele_trap() */ - in_sight = FALSE; - seetrap(trap); - } - } else - break; - } - /* Fall through */ - case LEVEL_TELEP: - case MAGIC_PORTAL: - { - int mlev_res; - mlev_res = mlevel_tele_trap(mtmp, trap, - inescapable, in_sight); - if (mlev_res) return(mlev_res); - } - break; + if (thitm(0, mtmp, (struct obj *) 0, num, immolate)) + trapkilled = TRUE; + else + /* we know mhp is at least `num' below mhpmax, + so no (mhp > mhpmax) check is needed here */ + mtmp->mhpmax -= rn2(num + 1); + } + if (burnarmor(mtmp) || rn2(3)) { + (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); + (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); + (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); + } + if (burn_floor_objects(mtmp->mx, mtmp->my, see_it, FALSE) + && !see_it && distu(mtmp->mx, mtmp->my) <= 3 * 3) + You("smell smoke."); + if (is_ice(mtmp->mx, mtmp->my)) + melt_ice(mtmp->mx, mtmp->my, (char *) 0); + if (see_it) + seetrap(trap); + break; - case TELEP_TRAP: - mtele_trap(mtmp, trap, in_sight); - break; + case PIT: + case SPIKED_PIT: + fallverb = "falls"; + if (is_flyer(mptr) || is_floater(mptr) + || (mtmp->wormno && count_wsegs(mtmp) > 5) + || is_clinger(mptr)) { + if (force_mintrap && !Sokoban) { + /* openfallingtrap; not inescapable here */ + if (in_sight) { + seetrap(trap); + pline("%s doesn't fall into the pit.", Monnam(mtmp)); + } + break; /* inescapable = FALSE; */ + } + if (!inescapable) + break; /* avoids trap */ + fallverb = "is dragged"; /* sokoban pit */ + } + if (!passes_walls(mptr)) + mtmp->mtrapped = 1; + if (in_sight) { + pline("%s %s into %s pit!", Monnam(mtmp), fallverb, + a_your[trap->madeby_u]); + if (mptr == &mons[PM_PIT_VIPER] + || mptr == &mons[PM_PIT_FIEND]) + pline("How pitiful. Isn't that the pits?"); + seetrap(trap); + } + mselftouch(mtmp, "Falling, ", FALSE); + if (mtmp->mhp <= 0 || thitm(0, mtmp, (struct obj *) 0, + rnd((tt == PIT) ? 6 : 10), FALSE)) + trapkilled = TRUE; + break; + case HOLE: + case TRAPDOOR: + if (!Can_fall_thru(&u.uz)) { + impossible("mintrap: %ss cannot exist on this level.", + defsyms[trap_to_defsym(tt)].explanation); + break; /* don't activate it after all */ + } + if (is_flyer(mptr) || is_floater(mptr) || mptr == &mons[PM_WUMPUS] + || (mtmp->wormno && count_wsegs(mtmp) > 5) + || mptr->msize >= MZ_HUGE) { + if (force_mintrap && !Sokoban) { + /* openfallingtrap; not inescapable here */ + if (in_sight) { + seetrap(trap); + if (tt == TRAPDOOR) + pline("A trap door opens, but %s doesn't fall " + "through.", + mon_nam(mtmp)); + else /* (tt == HOLE) */ + pline("%s doesn't fall through the hole.", + Monnam(mtmp)); + } + break; /* inescapable = FALSE; */ + } + if (inescapable) { /* sokoban hole */ + if (in_sight) { + pline("%s seems to be yanked down!", Monnam(mtmp)); + /* suppress message in mlevel_tele_trap() */ + in_sight = FALSE; + seetrap(trap); + } + } else + break; + } + /* Fall through */ + case LEVEL_TELEP: + case MAGIC_PORTAL: { + int mlev_res; + mlev_res = mlevel_tele_trap(mtmp, trap, inescapable, in_sight); + if (mlev_res) + return (mlev_res); + } break; - case WEB: - /* Monster in a web. */ - if (webmaker(mptr)) break; - if (amorphous(mptr) || is_whirly(mptr) || unsolid(mptr)){ - if(acidic(mptr) || - mptr == &mons[PM_GELATINOUS_CUBE] || - mptr == &mons[PM_FIRE_ELEMENTAL]) { - if (in_sight) - pline("%s %s %s spider web!", - Monnam(mtmp), - (mptr == &mons[PM_FIRE_ELEMENTAL]) ? - "burns" : "dissolves", - a_your[trap->madeby_u]); - deltrap(trap); - newsym(mtmp->mx, mtmp->my); - break; - } - if (in_sight) { - pline("%s flows through %s spider web.", - Monnam(mtmp), - a_your[trap->madeby_u]); - seetrap(trap); - } - break; - } - tear_web = FALSE; - switch (monsndx(mptr)) { - case PM_OWLBEAR: /* Eric Backus */ - case PM_BUGBEAR: - if (!in_sight) { - You_hear("the roaring of a confused bear!"); - mtmp->mtrapped = 1; - break; - } - /* fall though */ - default: - if (mptr->mlet == S_GIANT || - (mptr->mlet == S_DRAGON && - extra_nasty(mptr)) || /* excl. babies */ - (mtmp->wormno && count_wsegs(mtmp) > 5)) { - tear_web = TRUE; - } else if (in_sight) { - pline("%s is caught in %s spider web.", - Monnam(mtmp), - a_your[trap->madeby_u]); - seetrap(trap); - } - mtmp->mtrapped = tear_web ? 0 : 1; - break; - /* this list is fairly arbitrary; it deliberately - excludes wumpus & giant/ettin zombies/mummies */ - case PM_TITANOTHERE: - case PM_BALUCHITHERIUM: - case PM_PURPLE_WORM: - case PM_JABBERWOCK: - case PM_IRON_GOLEM: - case PM_BALROG: - case PM_KRAKEN: - case PM_MASTODON: - case PM_ORION: - case PM_NORN: - case PM_CYCLOPS: - case PM_LORD_SURTUR: - tear_web = TRUE; - break; - } - if (tear_web) { - if (in_sight) - pline("%s tears through %s spider web!", - Monnam(mtmp), a_your[trap->madeby_u]); - deltrap(trap); - newsym(mtmp->mx, mtmp->my); - } else if (force_mintrap && !mtmp->mtrapped) { - if (in_sight) { - pline("%s avoids %s spider web!", - Monnam(mtmp), a_your[trap->madeby_u]); - seetrap(trap); - } - } - break; + case TELEP_TRAP: + mtele_trap(mtmp, trap, in_sight); + break; - case STATUE_TRAP: - break; + case WEB: + /* Monster in a web. */ + if (webmaker(mptr)) + break; + if (amorphous(mptr) || is_whirly(mptr) || unsolid(mptr)) { + if (acidic(mptr) || mptr == &mons[PM_GELATINOUS_CUBE] + || mptr == &mons[PM_FIRE_ELEMENTAL]) { + if (in_sight) + pline("%s %s %s spider web!", Monnam(mtmp), + (mptr == &mons[PM_FIRE_ELEMENTAL]) + ? "burns" + : "dissolves", + a_your[trap->madeby_u]); + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + break; + } + if (in_sight) { + pline("%s flows through %s spider web.", Monnam(mtmp), + a_your[trap->madeby_u]); + seetrap(trap); + } + break; + } + tear_web = FALSE; + switch (monsndx(mptr)) { + case PM_OWLBEAR: /* Eric Backus */ + case PM_BUGBEAR: + if (!in_sight) { + You_hear("the roaring of a confused bear!"); + mtmp->mtrapped = 1; + break; + } + /* fall though */ + default: + if (mptr->mlet == S_GIANT + || (mptr->mlet == S_DRAGON && extra_nasty(mptr)) + || /* excl. babies */ + (mtmp->wormno && count_wsegs(mtmp) > 5)) { + tear_web = TRUE; + } else if (in_sight) { + pline("%s is caught in %s spider web.", Monnam(mtmp), + a_your[trap->madeby_u]); + seetrap(trap); + } + mtmp->mtrapped = tear_web ? 0 : 1; + break; + /* this list is fairly arbitrary; it deliberately + excludes wumpus & giant/ettin zombies/mummies */ + case PM_TITANOTHERE: + case PM_BALUCHITHERIUM: + case PM_PURPLE_WORM: + case PM_JABBERWOCK: + case PM_IRON_GOLEM: + case PM_BALROG: + case PM_KRAKEN: + case PM_MASTODON: + case PM_ORION: + case PM_NORN: + case PM_CYCLOPS: + case PM_LORD_SURTUR: + tear_web = TRUE; + break; + } + if (tear_web) { + if (in_sight) + pline("%s tears through %s spider web!", Monnam(mtmp), + a_your[trap->madeby_u]); + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + } else if (force_mintrap && !mtmp->mtrapped) { + if (in_sight) { + pline("%s avoids %s spider web!", Monnam(mtmp), + a_your[trap->madeby_u]); + seetrap(trap); + } + } + break; - case MAGIC_TRAP: - /* A magic trap. Monsters usually immune. */ - if (!rn2(21)) goto mfiretrap; - break; - case ANTI_MAGIC: - /* similar to hero's case, more or less */ - if (!resists_magm(mtmp)) { /* lose spell energy */ - if (!mtmp->mcan && - (attacktype(mptr, AT_MAGC) || - attacktype(mptr, AT_BREA))) { - mtmp->mspec_used += d(2, 2); - if (in_sight) { - seetrap(trap); - pline("%s seems lethargic.", Monnam(mtmp)); - } - } - } else { /* take some damage */ - int dmgval2 = rnd(4); + case STATUE_TRAP: + break; - if ((otmp = MON_WEP(mtmp)) != 0 && - otmp->oartifact == ART_MAGICBANE) - dmgval2 += rnd(4); - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if (otmp->oartifact && - defends_when_carried(AD_MAGM, otmp)) - break; - if (otmp) dmgval2 += rnd(4); - if (passes_walls(mptr)) dmgval2 = (dmgval2 + 3) / 4; + case MAGIC_TRAP: + /* A magic trap. Monsters usually immune. */ + if (!rn2(21)) + goto mfiretrap; + break; + case ANTI_MAGIC: + /* similar to hero's case, more or less */ + if (!resists_magm(mtmp)) { /* lose spell energy */ + if (!mtmp->mcan && (attacktype(mptr, AT_MAGC) + || attacktype(mptr, AT_BREA))) { + mtmp->mspec_used += d(2, 2); + if (in_sight) { + seetrap(trap); + pline("%s seems lethargic.", Monnam(mtmp)); + } + } + } else { /* take some damage */ + int dmgval2 = rnd(4); - if (in_sight) seetrap(trap); - if ((mtmp->mhp -= dmgval2) <= 0) - monkilled(mtmp, in_sight ? - "compression from an anti-magic field" : (const char *)0, - -AD_MAGM); - if (mtmp->mhp <= 0) trapkilled = TRUE; - if (see_it) newsym(trap->tx, trap->ty); - } - break; + if ((otmp = MON_WEP(mtmp)) != 0 + && otmp->oartifact == ART_MAGICBANE) + dmgval2 += rnd(4); + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->oartifact + && defends_when_carried(AD_MAGM, otmp)) + break; + if (otmp) + dmgval2 += rnd(4); + if (passes_walls(mptr)) + dmgval2 = (dmgval2 + 3) / 4; - case LANDMINE: - if(rn2(3)) - break; /* monsters usually don't set it off */ - if(is_flyer(mptr)) { - boolean already_seen = trap->tseen; - if (in_sight && !already_seen) { - pline("A trigger appears in a pile of soil below %s.", mon_nam(mtmp)); - seetrap(trap); - } - if (rn2(3)) break; - if (in_sight) { - newsym(mtmp->mx, mtmp->my); - pline_The("air currents set %s off!", - already_seen ? "a land mine" : "it"); - } - } else if(in_sight) { - newsym(mtmp->mx, mtmp->my); - pline("KAABLAMM!!! %s triggers %s land mine!", - Monnam(mtmp), a_your[trap->madeby_u]); - } - if (!in_sight) - pline("Kaablamm! You hear an explosion in the distance!"); - blow_up_landmine(trap); - /* explosion might have destroyed a drawbridge; don't - dish out more damage if monster is already dead */ - if (mtmp->mhp <= 0 || - thitm(0, mtmp, (struct obj *)0, rnd(16), FALSE)) - trapkilled = TRUE; - else { - /* monsters recursively fall into new pit */ - if (mintrap(mtmp) == 2) trapkilled=TRUE; - } - /* a boulder may fill the new pit, crushing monster */ - fill_pit(trap->tx, trap->ty); - if (mtmp->mhp <= 0) trapkilled = TRUE; - if (unconscious()) { - multi = -1; - nomovemsg = "The explosion awakens you!"; - } - break; + if (in_sight) + seetrap(trap); + if ((mtmp->mhp -= dmgval2) <= 0) + monkilled(mtmp, + in_sight + ? "compression from an anti-magic field" + : (const char *) 0, + -AD_MAGM); + if (mtmp->mhp <= 0) + trapkilled = TRUE; + if (see_it) + newsym(trap->tx, trap->ty); + } + break; - case POLY_TRAP: - if (resists_magm(mtmp)) { - shieldeff(mtmp->mx, mtmp->my); - } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) { - if (newcham(mtmp, (struct permonst *)0, FALSE, FALSE)) - /* we're done with mptr but keep it up to date */ - mptr = mtmp->data; - if (in_sight) seetrap(trap); - } - break; + case LANDMINE: + if (rn2(3)) + break; /* monsters usually don't set it off */ + if (is_flyer(mptr)) { + boolean already_seen = trap->tseen; + if (in_sight && !already_seen) { + pline("A trigger appears in a pile of soil below %s.", + mon_nam(mtmp)); + seetrap(trap); + } + if (rn2(3)) + break; + if (in_sight) { + newsym(mtmp->mx, mtmp->my); + pline_The("air currents set %s off!", + already_seen ? "a land mine" : "it"); + } + } else if (in_sight) { + newsym(mtmp->mx, mtmp->my); + pline("KAABLAMM!!! %s triggers %s land mine!", Monnam(mtmp), + a_your[trap->madeby_u]); + } + if (!in_sight) + pline("Kaablamm! You hear an explosion in the distance!"); + blow_up_landmine(trap); + /* explosion might have destroyed a drawbridge; don't + dish out more damage if monster is already dead */ + if (mtmp->mhp <= 0 + || thitm(0, mtmp, (struct obj *) 0, rnd(16), FALSE)) + trapkilled = TRUE; + else { + /* monsters recursively fall into new pit */ + if (mintrap(mtmp) == 2) + trapkilled = TRUE; + } + /* a boulder may fill the new pit, crushing monster */ + fill_pit(trap->tx, trap->ty); + if (mtmp->mhp <= 0) + trapkilled = TRUE; + if (unconscious()) { + multi = -1; + nomovemsg = "The explosion awakens you!"; + } + break; - case ROLLING_BOULDER_TRAP: - if (!is_flyer(mptr)) { - int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN); + case POLY_TRAP: + if (resists_magm(mtmp)) { + shieldeff(mtmp->mx, mtmp->my); + } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) { + if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE)) + /* we're done with mptr but keep it up to date */ + mptr = mtmp->data; + if (in_sight) + seetrap(trap); + } + break; - newsym(mtmp->mx,mtmp->my); - if (in_sight) - pline("Click! %s triggers %s.", Monnam(mtmp), - trap->tseen ? - "a rolling boulder trap" : - something); - if (launch_obj(BOULDER, trap->launch.x, trap->launch.y, - trap->launch2.x, trap->launch2.y, style)) { - if (in_sight) trap->tseen = TRUE; - if (mtmp->mhp <= 0) trapkilled = TRUE; - } else { - deltrap(trap); - newsym(mtmp->mx,mtmp->my); - } - } - break; + case ROLLING_BOULDER_TRAP: + if (!is_flyer(mptr)) { + int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN); - default: - impossible("Some monster encountered a strange trap of type %d.", tt); - } - } - if(trapkilled) return 2; - return mtmp->mtrapped; + newsym(mtmp->mx, mtmp->my); + if (in_sight) + pline("Click! %s triggers %s.", Monnam(mtmp), + trap->tseen ? "a rolling boulder trap" : something); + if (launch_obj(BOULDER, trap->launch.x, trap->launch.y, + trap->launch2.x, trap->launch2.y, style)) { + if (in_sight) + trap->tseen = TRUE; + if (mtmp->mhp <= 0) + trapkilled = TRUE; + } else { + deltrap(trap); + newsym(mtmp->mx, mtmp->my); + } + } + break; + + default: + impossible("Some monster encountered a strange trap of type %d.", + tt); + } + } + if (trapkilled) + return 2; + return mtmp->mtrapped; } /* Combine cockatrice checks into single functions to avoid repeating code. */ @@ -2524,485 +2605,506 @@ void instapetrify(str) const char *str; { - if (Stone_resistance) return; - if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) - return; - You("turn to stone..."); - killer.format = KILLED_BY; - if (str != killer.name) Strcpy(killer.name, str ? str : ""); - done(STONING); + if (Stone_resistance) + return; + if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) + return; + You("turn to stone..."); + killer.format = KILLED_BY; + if (str != killer.name) + Strcpy(killer.name, str ? str : ""); + done(STONING); } void -minstapetrify(mon,byplayer) +minstapetrify(mon, byplayer) struct monst *mon; boolean byplayer; { - if (resists_ston(mon)) return; - if (poly_when_stoned(mon->data)) { - mon_to_stone(mon); - return; - } + if (resists_ston(mon)) + return; + if (poly_when_stoned(mon->data)) { + mon_to_stone(mon); + return; + } - /* give a " is slowing down" message and also remove - intrinsic speed (comparable to similar effect on the hero) */ - mon_adjust_speed(mon, -3, (struct obj *)0); + /* give a " is slowing down" message and also remove + intrinsic speed (comparable to similar effect on the hero) */ + mon_adjust_speed(mon, -3, (struct obj *) 0); - if (cansee(mon->mx, mon->my)) - pline("%s turns to stone.", Monnam(mon)); - if (byplayer) { - stoned = TRUE; - xkilled(mon,0); - } else monstone(mon); + if (cansee(mon->mx, mon->my)) + pline("%s turns to stone.", Monnam(mon)); + if (byplayer) { + stoned = TRUE; + xkilled(mon, 0); + } else + monstone(mon); } void selftouch(arg) const char *arg; { - char kbuf[BUFSZ]; + char kbuf[BUFSZ]; - if(uwep && uwep->otyp == CORPSE && touch_petrifies(&mons[uwep->corpsenm]) - && !Stone_resistance) { - pline("%s touch the %s corpse.", arg, - mons[uwep->corpsenm].mname); - Sprintf(kbuf, "%s corpse", an(mons[uwep->corpsenm].mname)); - instapetrify(kbuf); - /* life-saved; unwield the corpse if we can't handle it */ - if (!uarmg && !Stone_resistance) uwepgone(); - } - /* Or your secondary weapon, if wielded [hypothetical; we don't - allow two-weapon combat when either weapon is a corpse] */ - if(u.twoweap && uswapwep && uswapwep->otyp == CORPSE && - touch_petrifies(&mons[uswapwep->corpsenm]) && !Stone_resistance){ - pline("%s touch the %s corpse.", arg, - mons[uswapwep->corpsenm].mname); - Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname)); - instapetrify(kbuf); - /* life-saved; unwield the corpse */ - if (!uarmg && !Stone_resistance) uswapwepgone(); - } + if (uwep && uwep->otyp == CORPSE && touch_petrifies(&mons[uwep->corpsenm]) + && !Stone_resistance) { + pline("%s touch the %s corpse.", arg, mons[uwep->corpsenm].mname); + Sprintf(kbuf, "%s corpse", an(mons[uwep->corpsenm].mname)); + instapetrify(kbuf); + /* life-saved; unwield the corpse if we can't handle it */ + if (!uarmg && !Stone_resistance) + uwepgone(); + } + /* Or your secondary weapon, if wielded [hypothetical; we don't + allow two-weapon combat when either weapon is a corpse] */ + if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE + && touch_petrifies(&mons[uswapwep->corpsenm]) && !Stone_resistance) { + pline("%s touch the %s corpse.", arg, mons[uswapwep->corpsenm].mname); + Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname)); + instapetrify(kbuf); + /* life-saved; unwield the corpse */ + if (!uarmg && !Stone_resistance) + uswapwepgone(); + } } void -mselftouch(mon,arg,byplayer) +mselftouch(mon, arg, byplayer) struct monst *mon; const char *arg; boolean byplayer; { - struct obj *mwep = MON_WEP(mon); + struct obj *mwep = MON_WEP(mon); - if (mwep && mwep->otyp == CORPSE && - touch_petrifies(&mons[mwep->corpsenm]) && - !resists_ston(mon)) { - if (cansee(mon->mx, mon->my)) { - pline("%s%s touches %s.", - arg ? arg : "", arg ? mon_nam(mon) : Monnam(mon), - corpse_xname(mwep, (const char *)0, CXN_PFX_THE)); - } - minstapetrify(mon, byplayer); - /* if life-saved, might not be able to continue wielding */ - if (mon->mhp > 0 && !which_armor(mon, W_ARMG) && - !resists_ston(mon)) - mwepgone(mon); - } + if (mwep && mwep->otyp == CORPSE && touch_petrifies(&mons[mwep->corpsenm]) + && !resists_ston(mon)) { + if (cansee(mon->mx, mon->my)) { + pline("%s%s touches %s.", arg ? arg : "", + arg ? mon_nam(mon) : Monnam(mon), + corpse_xname(mwep, (const char *) 0, CXN_PFX_THE)); + } + minstapetrify(mon, byplayer); + /* if life-saved, might not be able to continue wielding */ + if (mon->mhp > 0 && !which_armor(mon, W_ARMG) && !resists_ston(mon)) + mwepgone(mon); + } } void float_up() { - if(u.utrap) { - if(u.utraptype == TT_PIT) { - u.utrap = 0; - You("float up, out of the pit!"); - vision_full_recalc = 1; /* vision limits change */ - fill_pit(u.ux, u.uy); - } else if (u.utraptype == TT_INFLOOR) { - Your("body pulls upward, but your %s are still stuck.", - makeplural(body_part(LEG))); - } else { - You("float up, only your %s is still stuck.", - body_part(LEG)); - } - } + if (u.utrap) { + if (u.utraptype == TT_PIT) { + u.utrap = 0; + You("float up, out of the pit!"); + vision_full_recalc = 1; /* vision limits change */ + fill_pit(u.ux, u.uy); + } else if (u.utraptype == TT_INFLOOR) { + Your("body pulls upward, but your %s are still stuck.", + makeplural(body_part(LEG))); + } else { + You("float up, only your %s is still stuck.", body_part(LEG)); + } + } #if 0 else if(Is_waterlevel(&u.uz)) pline("It feels as though you've lost some weight."); #endif - else if(u.uinwater) - spoteffects(TRUE); - else if(u.uswallow) - You(is_animal(u.ustuck->data) ? - "float away from the %s." : - "spiral up into %s.", - is_animal(u.ustuck->data) ? - surface(u.ux, u.uy) : - mon_nam(u.ustuck)); - else if (Hallucination) - pline("Up, up, and awaaaay! You're walking on air!"); - else if(Is_airlevel(&u.uz)) - You("gain control over your movements."); - else - You("start to float in the air!"); - if (u.usteed && !is_floater(u.usteed->data) && - !is_flyer(u.usteed->data)) { - if (Lev_at_will) - pline("%s magically floats up!", Monnam(u.usteed)); - else { - You("cannot stay on %s.", mon_nam(u.usteed)); - dismount_steed(DISMOUNT_GENERIC); - } - } - if (Flying) You("are no longer able to control your flight."); - BFlying |= I_SPECIAL; - return; + else if (u.uinwater) + spoteffects(TRUE); + else if (u.uswallow) + You(is_animal(u.ustuck->data) ? "float away from the %s." + : "spiral up into %s.", + is_animal(u.ustuck->data) ? surface(u.ux, u.uy) + : mon_nam(u.ustuck)); + else if (Hallucination) + pline("Up, up, and awaaaay! You're walking on air!"); + else if (Is_airlevel(&u.uz)) + You("gain control over your movements."); + else + You("start to float in the air!"); + if (u.usteed && !is_floater(u.usteed->data) + && !is_flyer(u.usteed->data)) { + if (Lev_at_will) + pline("%s magically floats up!", Monnam(u.usteed)); + else { + You("cannot stay on %s.", mon_nam(u.usteed)); + dismount_steed(DISMOUNT_GENERIC); + } + } + if (Flying) + You("are no longer able to control your flight."); + BFlying |= I_SPECIAL; + return; } void fill_pit(x, y) int x, y; { - struct obj *otmp; - struct trap *t; + struct obj *otmp; + struct trap *t; - if ((t = t_at(x, y)) && - ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT)) && - (otmp = sobj_at(BOULDER, x, y))) { - obj_extract_self(otmp); - (void) flooreffects(otmp, x, y, "settle"); - } + if ((t = t_at(x, y)) && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT)) + && (otmp = sobj_at(BOULDER, x, y))) { + obj_extract_self(otmp); + (void) flooreffects(otmp, x, y, "settle"); + } } int float_down(hmask, emask) -long hmask, emask; /* might cancel timeout */ +long hmask, emask; /* might cancel timeout */ { - register struct trap *trap = (struct trap *)0; - d_level current_dungeon_level; - boolean no_msg = FALSE; + register struct trap *trap = (struct trap *) 0; + d_level current_dungeon_level; + boolean no_msg = FALSE; - HLevitation &= ~hmask; - ELevitation &= ~emask; - if (Levitation) return 0; /* maybe another ring/potion/boots */ - if (BLevitation) { - /* Levitation is blocked, so hero is not actually floating - hence shouldn't have float_down effects and feedback */ - float_vs_flight(); /* before nomul() rather than after */ - return 0; - } - nomul(0); /* stop running or resting */ - if (BFlying) { - /* controlled flight no longer overridden by levitation */ - BFlying &= ~I_SPECIAL; - if (Flying) { - You("have stopped levitating and are now flying."); - return 1; - } - } - if(u.uswallow) { - You("float down, but you are still %s.", - is_animal(u.ustuck->data) ? "swallowed" : "engulfed"); - return(1); - } + HLevitation &= ~hmask; + ELevitation &= ~emask; + if (Levitation) + return 0; /* maybe another ring/potion/boots */ + if (BLevitation) { + /* Levitation is blocked, so hero is not actually floating + hence shouldn't have float_down effects and feedback */ + float_vs_flight(); /* before nomul() rather than after */ + return 0; + } + nomul(0); /* stop running or resting */ + if (BFlying) { + /* controlled flight no longer overridden by levitation */ + BFlying &= ~I_SPECIAL; + if (Flying) { + You("have stopped levitating and are now flying."); + return 1; + } + } + if (u.uswallow) { + You("float down, but you are still %s.", + is_animal(u.ustuck->data) ? "swallowed" : "engulfed"); + return (1); + } - if (Punished && !carried(uball) && - (is_pool(uball->ox, uball->oy) || - ((trap = t_at(uball->ox, uball->oy)) && - ((trap->ttyp == PIT) || (trap->ttyp == SPIKED_PIT) || - (trap->ttyp == TRAPDOOR) || (trap->ttyp == HOLE))))) { - u.ux0 = u.ux; - u.uy0 = u.uy; - u.ux = uball->ox; - u.uy = uball->oy; - movobj(uchain, uball->ox, uball->oy); - newsym(u.ux0, u.uy0); - vision_full_recalc = 1; /* in case the hero moved. */ - } - /* check for falling into pool - added by GAN 10/20/86 */ - if(!Flying) { - if (!u.uswallow && u.ustuck) { - if (sticks(youmonst.data)) - You("aren't able to maintain your hold on %s.", - mon_nam(u.ustuck)); - else - pline("Startled, %s can no longer hold you!", - mon_nam(u.ustuck)); - u.ustuck = 0; - } - /* kludge alert: - * drown() and lava_effects() print various messages almost - * every time they're called which conflict with the "fall - * into" message below. Thus, we want to avoid printing - * confusing, duplicate or out-of-order messages. - * Use knowledge of the two routines as a hack -- this - * should really be handled differently -dlc - */ - if(is_pool(u.ux,u.uy) && !Wwalking && !Swimming && !u.uinwater) - no_msg = drown(); + if (Punished && !carried(uball) + && (is_pool(uball->ox, uball->oy) + || ((trap = t_at(uball->ox, uball->oy)) + && ((trap->ttyp == PIT) || (trap->ttyp == SPIKED_PIT) + || (trap->ttyp == TRAPDOOR) || (trap->ttyp == HOLE))))) { + u.ux0 = u.ux; + u.uy0 = u.uy; + u.ux = uball->ox; + u.uy = uball->oy; + movobj(uchain, uball->ox, uball->oy); + newsym(u.ux0, u.uy0); + vision_full_recalc = 1; /* in case the hero moved. */ + } + /* check for falling into pool - added by GAN 10/20/86 */ + if (!Flying) { + if (!u.uswallow && u.ustuck) { + if (sticks(youmonst.data)) + You("aren't able to maintain your hold on %s.", + mon_nam(u.ustuck)); + else + pline("Startled, %s can no longer hold you!", + mon_nam(u.ustuck)); + u.ustuck = 0; + } + /* kludge alert: + * drown() and lava_effects() print various messages almost + * every time they're called which conflict with the "fall + * into" message below. Thus, we want to avoid printing + * confusing, duplicate or out-of-order messages. + * Use knowledge of the two routines as a hack -- this + * should really be handled differently -dlc + */ + if (is_pool(u.ux, u.uy) && !Wwalking && !Swimming && !u.uinwater) + no_msg = drown(); - if(is_lava(u.ux,u.uy)) { - (void) lava_effects(); - no_msg = TRUE; - } - } - if (!trap) { - trap = t_at(u.ux,u.uy); - if(Is_airlevel(&u.uz)) - You("begin to tumble in place."); - else if (Is_waterlevel(&u.uz) && !no_msg) - You_feel("heavier."); - /* u.uinwater msgs already in spoteffects()/drown() */ - else if (!u.uinwater && !no_msg) { - if (!(emask & W_SADDLE)) { - if (Sokoban && trap) { - /* Justification elsewhere for Sokoban traps - * is based on air currents. This is - * consistent with that. - * The unexpected additional force of the - * air currents once leviation - * ceases knocks you off your feet. - */ - if (Hallucination) - pline("Bummer! You've crashed."); - else - You("fall over."); - losehp(rnd(2), "dangerous winds", KILLED_BY); - if (u.usteed) dismount_steed(DISMOUNT_FELL); - selftouch("As you fall, you"); - } else if (u.usteed && (is_floater(u.usteed->data) || - is_flyer(u.usteed->data))) { - You("settle more firmly in the saddle."); - } else if (Hallucination) - pline("Bummer! You've %s.", - is_pool(u.ux,u.uy) ? "splashed down" : - "hit the ground"); - else - You("float gently to the %s.", surface(u.ux, u.uy)); - } - } - } + if (is_lava(u.ux, u.uy)) { + (void) lava_effects(); + no_msg = TRUE; + } + } + if (!trap) { + trap = t_at(u.ux, u.uy); + if (Is_airlevel(&u.uz)) + You("begin to tumble in place."); + else if (Is_waterlevel(&u.uz) && !no_msg) + You_feel("heavier."); + /* u.uinwater msgs already in spoteffects()/drown() */ + else if (!u.uinwater && !no_msg) { + if (!(emask & W_SADDLE)) { + if (Sokoban && trap) { + /* Justification elsewhere for Sokoban traps + * is based on air currents. This is + * consistent with that. + * The unexpected additional force of the + * air currents once leviation + * ceases knocks you off your feet. + */ + if (Hallucination) + pline("Bummer! You've crashed."); + else + You("fall over."); + losehp(rnd(2), "dangerous winds", KILLED_BY); + if (u.usteed) + dismount_steed(DISMOUNT_FELL); + selftouch("As you fall, you"); + } else if (u.usteed && (is_floater(u.usteed->data) + || is_flyer(u.usteed->data))) { + You("settle more firmly in the saddle."); + } else if (Hallucination) + pline("Bummer! You've %s.", is_pool(u.ux, u.uy) + ? "splashed down" + : "hit the ground"); + else + You("float gently to the %s.", surface(u.ux, u.uy)); + } + } + } - /* can't rely on u.uz0 for detecting trap door-induced level change; - it gets changed to reflect the new level before we can check it */ - assign_level(¤t_dungeon_level, &u.uz); + /* can't rely on u.uz0 for detecting trap door-induced level change; + it gets changed to reflect the new level before we can check it */ + assign_level(¤t_dungeon_level, &u.uz); - if(trap) - switch(trap->ttyp) { - case STATUE_TRAP: - break; - case HOLE: - case TRAPDOOR: - if(!Can_fall_thru(&u.uz) || u.ustuck) - break; - /* fall into next case */ - default: - if (!u.utrap) /* not already in the trap */ - dotrap(trap, 0); - } + if (trap) + switch (trap->ttyp) { + case STATUE_TRAP: + break; + case HOLE: + case TRAPDOOR: + if (!Can_fall_thru(&u.uz) || u.ustuck) + break; + /* fall into next case */ + default: + if (!u.utrap) /* not already in the trap */ + dotrap(trap, 0); + } - if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow && - /* falling through trap door calls goto_level, - and goto_level does its own pickup() call */ - on_level(&u.uz, ¤t_dungeon_level)) - (void) pickup(1); - return 1; + if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow && + /* falling through trap door calls goto_level, + and goto_level does its own pickup() call */ + on_level(&u.uz, ¤t_dungeon_level)) + (void) pickup(1); + return 1; } /* shared code for climbing out of a pit */ void climb_pit() { - if (!u.utrap || u.utraptype != TT_PIT) return; + if (!u.utrap || u.utraptype != TT_PIT) + return; - if (Passes_walls) { - /* marked as trapped so they can pick things up */ - You("ascend from the pit."); - u.utrap = 0; - fill_pit(u.ux, u.uy); - vision_full_recalc = 1; /* vision limits change */ - } else if (!rn2(2) && sobj_at(BOULDER, u.ux, u.uy)) { - Your("%s gets stuck in a crevice.", body_part(LEG)); - display_nhwindow(WIN_MESSAGE, FALSE); - clear_nhwindow(WIN_MESSAGE); - You("free your %s.", body_part(LEG)); - } else if ((Flying || is_clinger(youmonst.data)) && !Sokoban) { - /* eg fell in pit, then poly'd to a flying monster; - or used '>' to deliberately enter it */ - You("%s from the pit.", Flying ? "fly" : "climb"); - u.utrap = 0; - fill_pit(u.ux, u.uy); - vision_full_recalc = 1; /* vision limits change */ - } else if (!(--u.utrap)) { - You("%s to the edge of the pit.", - (Sokoban && Levitation) ? - "struggle against the air currents and float" : - u.usteed ? "ride" : - "crawl"); - fill_pit(u.ux, u.uy); - vision_full_recalc = 1; /* vision limits change */ - } else if (u.dz || flags.verbose) { - if (u.usteed) - Norep("%s is still in a pit.", - upstart(y_monnam(u.usteed))); - else - Norep((Hallucination && !rn2(5)) ? - "You've fallen, and you can't get up." : - "You are still in a pit."); - } + if (Passes_walls) { + /* marked as trapped so they can pick things up */ + You("ascend from the pit."); + u.utrap = 0; + fill_pit(u.ux, u.uy); + vision_full_recalc = 1; /* vision limits change */ + } else if (!rn2(2) && sobj_at(BOULDER, u.ux, u.uy)) { + Your("%s gets stuck in a crevice.", body_part(LEG)); + display_nhwindow(WIN_MESSAGE, FALSE); + clear_nhwindow(WIN_MESSAGE); + You("free your %s.", body_part(LEG)); + } else if ((Flying || is_clinger(youmonst.data)) && !Sokoban) { + /* eg fell in pit, then poly'd to a flying monster; + or used '>' to deliberately enter it */ + You("%s from the pit.", Flying ? "fly" : "climb"); + u.utrap = 0; + fill_pit(u.ux, u.uy); + vision_full_recalc = 1; /* vision limits change */ + } else if (!(--u.utrap)) { + You("%s to the edge of the pit.", + (Sokoban && Levitation) + ? "struggle against the air currents and float" + : u.usteed ? "ride" : "crawl"); + fill_pit(u.ux, u.uy); + vision_full_recalc = 1; /* vision limits change */ + } else if (u.dz || flags.verbose) { + if (u.usteed) + Norep("%s is still in a pit.", upstart(y_monnam(u.usteed))); + else + Norep((Hallucination && !rn2(5)) + ? "You've fallen, and you can't get up." + : "You are still in a pit."); + } } STATIC_OVL void dofiretrap(box) -struct obj *box; /* null for floor trap */ +struct obj *box; /* null for floor trap */ { - boolean see_it = !Blind; - int num, alt; + boolean see_it = !Blind; + int num, alt; -/* Bug: for box case, the equivalent of burn_floor_objects() ought - * to be done upon its contents. - */ + /* Bug: for box case, the equivalent of burn_floor_objects() ought + * to be done upon its contents. + */ - if ((box && !carried(box)) ? is_pool(box->ox, box->oy) : Underwater) { - pline("A cascade of steamy bubbles erupts from %s!", - the(box ? xname(box) : surface(u.ux,u.uy))); - if (Fire_resistance) You("are uninjured."); - else losehp(rnd(3), "boiling water", KILLED_BY); - return; - } - pline("A %s %s from %s!", tower_of_flame, - box ? "bursts" : "erupts", - the(box ? xname(box) : surface(u.ux,u.uy))); - if (Fire_resistance) { - shieldeff(u.ux, u.uy); - num = rn2(2); - } else if (Upolyd) { - num = d(2,4); - switch (u.umonnum) { - case PM_PAPER_GOLEM: alt = u.mhmax; break; - case PM_STRAW_GOLEM: alt = u.mhmax / 2; break; - case PM_WOOD_GOLEM: alt = u.mhmax / 4; break; - case PM_LEATHER_GOLEM: alt = u.mhmax / 8; break; - default: alt = 0; break; - } - if (alt > num) num = alt; - if (u.mhmax > mons[u.umonnum].mlevel) - u.mhmax -= rn2(min(u.mhmax,num + 1)), context.botl = 1; - } else { - num = d(2,4); - if (u.uhpmax > u.ulevel) - u.uhpmax -= rn2(min(u.uhpmax,num + 1)), context.botl = 1; - } - if (!num) - You("are uninjured."); - else - losehp(num, tower_of_flame, KILLED_BY_AN); /* fire damage */ - burn_away_slime(); + if ((box && !carried(box)) ? is_pool(box->ox, box->oy) : Underwater) { + pline("A cascade of steamy bubbles erupts from %s!", + the(box ? xname(box) : surface(u.ux, u.uy))); + if (Fire_resistance) + You("are uninjured."); + else + losehp(rnd(3), "boiling water", KILLED_BY); + return; + } + pline("A %s %s from %s!", tower_of_flame, box ? "bursts" : "erupts", + the(box ? xname(box) : surface(u.ux, u.uy))); + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + num = rn2(2); + } else if (Upolyd) { + num = d(2, 4); + switch (u.umonnum) { + case PM_PAPER_GOLEM: + alt = u.mhmax; + break; + case PM_STRAW_GOLEM: + alt = u.mhmax / 2; + break; + case PM_WOOD_GOLEM: + alt = u.mhmax / 4; + break; + case PM_LEATHER_GOLEM: + alt = u.mhmax / 8; + break; + default: + alt = 0; + break; + } + if (alt > num) + num = alt; + if (u.mhmax > mons[u.umonnum].mlevel) + u.mhmax -= rn2(min(u.mhmax, num + 1)), context.botl = 1; + } else { + num = d(2, 4); + if (u.uhpmax > u.ulevel) + u.uhpmax -= rn2(min(u.uhpmax, num + 1)), context.botl = 1; + } + if (!num) + You("are uninjured."); + else + losehp(num, tower_of_flame, KILLED_BY_AN); /* fire damage */ + burn_away_slime(); - if (burnarmor(&youmonst) || rn2(3)) { - destroy_item(SCROLL_CLASS, AD_FIRE); - destroy_item(SPBOOK_CLASS, AD_FIRE); - destroy_item(POTION_CLASS, AD_FIRE); - } - if (!box && burn_floor_objects(u.ux, u.uy, see_it, TRUE) && !see_it) - You("smell paper burning."); - if (is_ice(u.ux, u.uy)) - melt_ice(u.ux, u.uy, (char *)0); + if (burnarmor(&youmonst) || rn2(3)) { + destroy_item(SCROLL_CLASS, AD_FIRE); + destroy_item(SPBOOK_CLASS, AD_FIRE); + destroy_item(POTION_CLASS, AD_FIRE); + } + if (!box && burn_floor_objects(u.ux, u.uy, see_it, TRUE) && !see_it) + You("smell paper burning."); + if (is_ice(u.ux, u.uy)) + melt_ice(u.ux, u.uy, (char *) 0); } STATIC_OVL void domagictrap() { - register int fate = rnd(20); + register int fate = rnd(20); - /* What happened to the poor sucker? */ + /* What happened to the poor sucker? */ - if (fate < 10) { - /* Most of the time, it creates some monsters. */ - register int cnt = rnd(4); + if (fate < 10) { + /* Most of the time, it creates some monsters. */ + register int cnt = rnd(4); - if (!resists_blnd(&youmonst)) { - You("are momentarily blinded by a flash of light!"); - make_blinded((long)rn1(5,10),FALSE); - if (!Blind) Your1(vision_clears); - } else if (!Blind) { - You_see("a flash of light!"); - } else - You_hear("a deafening roar!"); - incr_itimeout(&HDeaf, rn1(20,30)); - while(cnt--) - (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); - } - else - switch (fate) { + if (!resists_blnd(&youmonst)) { + You("are momentarily blinded by a flash of light!"); + make_blinded((long) rn1(5, 10), FALSE); + if (!Blind) + Your1(vision_clears); + } else if (!Blind) { + You_see("a flash of light!"); + } else + You_hear("a deafening roar!"); + incr_itimeout(&HDeaf, rn1(20, 30)); + while (cnt--) + (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); + } else + switch (fate) { + case 10: + case 11: + /* sometimes nothing happens */ + break; + case 12: /* a flash of fire */ + dofiretrap((struct obj *) 0); + break; - case 10: - case 11: - /* sometimes nothing happens */ - break; - case 12: /* a flash of fire */ - dofiretrap((struct obj *)0); - break; + /* odd feelings */ + case 13: + pline("A shiver runs up and down your %s!", body_part(SPINE)); + break; + case 14: + You_hear(Hallucination ? "the moon howling at you." + : "distant howling."); + break; + case 15: + if (on_level(&u.uz, &qstart_level)) + You_feel( + "%slike the prodigal son.", + (flags.female || (Upolyd && is_neuter(youmonst.data))) + ? "oddly " + : ""); + else + You("suddenly yearn for %s.", + Hallucination + ? "Cleveland" + : (In_quest(&u.uz) || at_dgn_entrance("The Quest")) + ? "your nearby homeland" + : "your distant homeland"); + break; + case 16: + Your("pack shakes violently!"); + break; + case 17: + You(Hallucination ? "smell hamburgers." : "smell charred flesh."); + break; + case 18: + You_feel("tired."); + break; - /* odd feelings */ - case 13: pline("A shiver runs up and down your %s!", - body_part(SPINE)); - break; - case 14: You_hear(Hallucination ? - "the moon howling at you." : - "distant howling."); - break; - case 15: if (on_level(&u.uz, &qstart_level)) - You_feel("%slike the prodigal son.", - (flags.female || (Upolyd && is_neuter(youmonst.data))) ? - "oddly " : ""); - else - You("suddenly yearn for %s.", - Hallucination ? "Cleveland" : - (In_quest(&u.uz) || at_dgn_entrance("The Quest")) ? - "your nearby homeland" : - "your distant homeland"); - break; - case 16: Your("pack shakes violently!"); - break; - case 17: You(Hallucination ? - "smell hamburgers." : - "smell charred flesh."); - break; - case 18: You_feel("tired."); - break; + /* very occasionally something nice happens. */ - /* very occasionally something nice happens. */ + case 19: + /* tame nearby monsters */ + { + register int i, j; + register struct monst *mtmp; - case 19: - /* tame nearby monsters */ - { register int i,j; - register struct monst *mtmp; + (void) adjattrib(A_CHA, 1, FALSE); + for (i = -1; i <= 1; i++) + for (j = -1; j <= 1; j++) { + if (!isok(u.ux + i, u.uy + j)) + continue; + mtmp = m_at(u.ux + i, u.uy + j); + if (mtmp) + (void) tamedog(mtmp, (struct obj *) 0); + } + break; + } - (void) adjattrib(A_CHA,1,FALSE); - for(i = -1; i <= 1; i++) for(j = -1; j <= 1; j++) { - if(!isok(u.ux+i, u.uy+j)) continue; - mtmp = m_at(u.ux+i, u.uy+j); - if(mtmp) - (void) tamedog(mtmp, (struct obj *)0); - } - break; - } + case 20: + /* uncurse stuff */ + { + struct obj pseudo; + long save_conf = HConfusion; - case 20: - /* uncurse stuff */ - { struct obj pseudo; - long save_conf = HConfusion; - - pseudo = zeroobj; /* neither cursed nor blessed, - and zero out oextra */ - pseudo.otyp = SCR_REMOVE_CURSE; - HConfusion = 0L; - (void) seffects(&pseudo); - HConfusion = save_conf; - break; - } - default: break; - } + pseudo = zeroobj; /* neither cursed nor blessed, + and zero out oextra */ + pseudo.otyp = SCR_REMOVE_CURSE; + HConfusion = 0L; + (void) seffects(&pseudo); + HConfusion = save_conf; + break; + } + default: + break; + } } /* Set an item on fire. @@ -3021,7 +3123,7 @@ xchar x, y; { int chance; struct obj *otmp, *ncobj; - int in_sight = !Blind && couldsee(x, y); /* Don't care if it's lit */ + int in_sight = !Blind && couldsee(x, y); /* Don't care if it's lit */ int dindx; /* object might light in a controlled manner */ @@ -3031,7 +3133,7 @@ xchar x, y; if (Is_container(obj)) { switch (obj->otyp) { case ICE_BOX: - return FALSE; /* Immune */ + return FALSE; /* Immune */ case CHEST: chance = 40; break; @@ -3042,13 +3144,15 @@ xchar x, y; chance = 20; break; } - if ((!force && (Luck + 5) > rn2(chance)) || - (is_flammable(obj) && obj->oerodeproof)) + if ((!force && (Luck + 5) > rn2(chance)) + || (is_flammable(obj) && obj->oerodeproof)) return FALSE; /* Container is burnt up - dump contents out */ - if (in_sight) pline("%s catches fire and burns.", Yname2(obj)); + if (in_sight) + pline("%s catches fire and burns.", Yname2(obj)); if (Has_contents(obj)) { - if (in_sight) pline("Its contents fall out."); + if (in_sight) + pline("Its contents fall out."); for (otmp = obj->cobj; otmp; otmp = ncobj) { ncobj = otmp->nobj; obj_extract_self(otmp); @@ -3070,8 +3174,9 @@ xchar x, y; if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) return FALSE; if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - if (in_sight) pline("Smoke rises from %s.", the(xname(obj))); - return FALSE; + if (in_sight) + pline("Smoke rises from %s.", the(xname(obj))); + return FALSE; } dindx = (obj->oclass == SCROLL_CLASS) ? 3 : 4; if (in_sight) @@ -3108,13 +3213,13 @@ xchar x, y; struct obj *obj, *nobj; int num = 0; for (obj = chain; obj; obj = nobj) { - nobj = here ? obj->nexthere : obj->nobj; + nobj = here ? obj->nexthere : obj->nobj; if (fire_damage(obj, force, x, y)) ++num; } if (num && (Blind && !couldsee(x, y))) - You("smell smoke."); + You("smell smoke."); return num; } @@ -3126,7 +3231,8 @@ struct obj *obj; struct monst *victim; boolean vismon; - if (!obj) return; + if (!obj) + return; victim = carried(obj) ? &youmonst : mcarried(obj) ? obj->ocarry : NULL; vismon = victim && (victim != &youmonst) && canseemon(victim); @@ -3136,9 +3242,9 @@ struct obj *obj; } else if (obj->oclass == SCROLL_CLASS && obj->otyp != SCR_BLANK_PAPER) { if (obj->otyp != SCR_BLANK_PAPER #ifdef MAIL - && obj->otyp != SCR_MAIL + && obj->otyp != SCR_MAIL #endif - ) { + ) { if (!Blind) { if (victim == &youmonst) pline("Your %s.", aobjnam(obj, "fade")); @@ -3158,7 +3264,7 @@ struct obj *obj; when more than one stack of potions of acid explode while processing a chain of objects, use alternate phrasing after the first message */ static struct h2o_ctx { - int dkn_boom, unk_boom; /* track dknown, !dknown separately */ + int dkn_boom, unk_boom; /* track dknown, !dknown separately */ boolean ctx_valid; } acid_ctx = { 0, 0, FALSE }; @@ -3174,129 +3280,133 @@ struct obj *obj; const char *ostr; boolean force; { - if (!obj) return ER_NOTHING; - - if (snuff_lit(obj)) - return ER_DAMAGED; - - if(obj->otyp == CAN_OF_GREASE && obj->spe > 0) { - return ER_NOTHING; - } else if(obj->greased) { - if (!rn2(2)) obj->greased = 0; - if (carried(obj)) update_inventory(); - return ER_GREASED; - } else if(Is_container(obj) && !Is_box(obj) && - (obj->otyp != OILSKIN_SACK || (obj->cursed && !rn2(3)))) { - water_damage_chain(obj->cobj, FALSE); - return ER_NOTHING; - } else if (!force && (Luck + 5) > rn2(20)) { - /* chance per item of sustaining damage: - * max luck: 10% - * avg luck (Luck==0): 75% - * awful luck (Luck<-4): 100% - */ - return ER_NOTHING; - } else if (obj->oclass == SCROLL_CLASS) { -#ifdef MAIL - if (obj->otyp == SCR_MAIL) return 0; -#endif - obj->otyp = SCR_BLANK_PAPER; - obj->dknown = 0; - obj->spe = 0; - if (carried(obj)) - update_inventory(); - return ER_DAMAGED; - } else if (obj->oclass == SPBOOK_CLASS) { - if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - pline("Steam rises from %s.", the(xname(obj))); - return 0; - } - if (obj->otyp == SPE_NOVEL) { - obj->novelidx = 0; - free_oname(obj); - } - obj->otyp = SPE_BLANK_PAPER; - obj->dknown = 0; - if (carried(obj)) - update_inventory(); - return ER_DAMAGED; - } else if (obj->oclass == POTION_CLASS) { - if (obj->otyp == POT_ACID) { - char *bufp; - boolean one = (obj->quan == 1L), - update = carried(obj), - exploded = FALSE; - - if (Blind && !carried(obj)) obj->dknown = 0; - if (acid_ctx.ctx_valid) - exploded = ((obj->dknown ? acid_ctx.dkn_boom - : acid_ctx.unk_boom) > 0); - /* First message is - * "a [potion| potion|potion of acid] explodes" - * depending on obj->dknown (potion has been seen) and - * objects[POT_ACID].oc_name_known (fully discovered), - * or "some {plural version} explode" when relevant. - * Second and subsequent messages for same chain and - * matching dknown status are - * "another [potion| &c] explodes" or plural - * variant. - */ - bufp = simpleonames(obj); - pline("%s %s %s!", /* "A potion explodes!" */ - !exploded ? (one ? "A" : "Some") : - (one ? "Another" : "More"), - bufp, vtense(bufp, "explode")); - if (acid_ctx.ctx_valid) { - if (obj->dknown) - acid_ctx.dkn_boom++; - else - acid_ctx.unk_boom++; - } - setnotworn(obj); - delobj(obj); - if (update) - update_inventory(); - return ER_DESTROYED; - } else if (obj->odiluted) { - obj->otyp = POT_WATER; - obj->dknown = 0; - obj->blessed = obj->cursed = 0; - obj->odiluted = 0; - if (carried(obj)) - update_inventory(); - return ER_DAMAGED; - } else if (obj->otyp != POT_WATER) { - obj->odiluted++; - if (carried(obj)) - update_inventory(); - return ER_DAMAGED; - } - } else { - return erode_obj(obj, ostr, ERODE_RUST, EF_NONE); - } + if (!obj) return ER_NOTHING; + + if (snuff_lit(obj)) + return ER_DAMAGED; + + if (obj->otyp == CAN_OF_GREASE && obj->spe > 0) { + return ER_NOTHING; + } else if (obj->greased) { + if (!rn2(2)) + obj->greased = 0; + if (carried(obj)) + update_inventory(); + return ER_GREASED; + } else if (Is_container(obj) && !Is_box(obj) + && (obj->otyp != OILSKIN_SACK || (obj->cursed && !rn2(3)))) { + water_damage_chain(obj->cobj, FALSE); + return ER_NOTHING; + } else if (!force && (Luck + 5) > rn2(20)) { + /* chance per item of sustaining damage: + * max luck: 10% + * avg luck (Luck==0): 75% + * awful luck (Luck<-4): 100% + */ + return ER_NOTHING; + } else if (obj->oclass == SCROLL_CLASS) { +#ifdef MAIL + if (obj->otyp == SCR_MAIL) + return 0; +#endif + obj->otyp = SCR_BLANK_PAPER; + obj->dknown = 0; + obj->spe = 0; + if (carried(obj)) + update_inventory(); + return ER_DAMAGED; + } else if (obj->oclass == SPBOOK_CLASS) { + if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { + pline("Steam rises from %s.", the(xname(obj))); + return 0; + } + if (obj->otyp == SPE_NOVEL) { + obj->novelidx = 0; + free_oname(obj); + } + obj->otyp = SPE_BLANK_PAPER; + obj->dknown = 0; + if (carried(obj)) + update_inventory(); + return ER_DAMAGED; + } else if (obj->oclass == POTION_CLASS) { + if (obj->otyp == POT_ACID) { + char *bufp; + boolean one = (obj->quan == 1L), update = carried(obj), + exploded = FALSE; + + if (Blind && !carried(obj)) + obj->dknown = 0; + if (acid_ctx.ctx_valid) + exploded = ((obj->dknown ? acid_ctx.dkn_boom + : acid_ctx.unk_boom) > 0); + /* First message is + * "a [potion| potion|potion of acid] explodes" + * depending on obj->dknown (potion has been seen) and + * objects[POT_ACID].oc_name_known (fully discovered), + * or "some {plural version} explode" when relevant. + * Second and subsequent messages for same chain and + * matching dknown status are + * "another [potion| &c] explodes" or plural + * variant. + */ + bufp = simpleonames(obj); + pline("%s %s %s!", /* "A potion explodes!" */ + !exploded ? (one ? "A" : "Some") + : (one ? "Another" : "More"), + bufp, vtense(bufp, "explode")); + if (acid_ctx.ctx_valid) { + if (obj->dknown) + acid_ctx.dkn_boom++; + else + acid_ctx.unk_boom++; + } + setnotworn(obj); + delobj(obj); + if (update) + update_inventory(); + return ER_DESTROYED; + } else if (obj->odiluted) { + obj->otyp = POT_WATER; + obj->dknown = 0; + obj->blessed = obj->cursed = 0; + obj->odiluted = 0; + if (carried(obj)) + update_inventory(); + return ER_DAMAGED; + } else if (obj->otyp != POT_WATER) { + obj->odiluted++; + if (carried(obj)) + update_inventory(); + return ER_DAMAGED; + } + } else { + return erode_obj(obj, ostr, ERODE_RUST, EF_NONE); + } + return ER_NOTHING; } void -water_damage_chain(obj,here) +water_damage_chain(obj, here) struct obj *obj; boolean here; { - struct obj *otmp; + struct obj *otmp; - /* initialize acid context: so far, neither seen (dknown) potions of - acid nor unseen have exploded during this water damage sequence */ - acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; - acid_ctx.ctx_valid = TRUE; + /* initialize acid context: so far, neither seen (dknown) potions of + acid nor unseen have exploded during this water damage sequence */ + acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; + acid_ctx.ctx_valid = TRUE; - for (; obj; obj = otmp) { - otmp = here ? obj->nexthere : obj->nobj; - water_damage(obj, NULL, FALSE); - } + for (; obj; obj = otmp) { + otmp = here ? obj->nexthere : obj->nobj; + water_damage(obj, NULL, FALSE); + } - /* reset acid context */ - acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; - acid_ctx.ctx_valid = FALSE; + /* reset acid context */ + acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; + acid_ctx.ctx_valid = FALSE; } /* @@ -3309,43 +3419,45 @@ STATIC_OVL boolean emergency_disrobe(lostsome) boolean *lostsome; { - int invc = inv_cnt(TRUE); + int invc = inv_cnt(TRUE); - while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) { - register struct obj *obj, *otmp = (struct obj *)0; - register int i; + while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) { + register struct obj *obj, *otmp = (struct obj *) 0; + register int i; - /* Pick a random object */ - if (invc > 0) { - i = rn2(invc); - for (obj = invent; obj; obj = obj->nobj) { - /* - * Undroppables are: body armor, boots, gloves, - * amulets, and rings because of the time and effort - * in removing them + loadstone and other cursed stuff - * for obvious reasons. - */ - if (!((obj->otyp == LOADSTONE && obj->cursed) || - obj == uamul || obj == uleft || obj == uright || - obj == ublindf || obj == uarm || obj == uarmc || - obj == uarmg || obj == uarmf || - obj == uarmu || - (obj->cursed && (obj == uarmh || obj == uarms)) || - welded(obj))) - otmp = obj; - /* reached the mark and found some stuff to drop? */ - if (--i < 0 && otmp) break; + /* Pick a random object */ + if (invc > 0) { + i = rn2(invc); + for (obj = invent; obj; obj = obj->nobj) { + /* + * Undroppables are: body armor, boots, gloves, + * amulets, and rings because of the time and effort + * in removing them + loadstone and other cursed stuff + * for obvious reasons. + */ + if (!((obj->otyp == LOADSTONE && obj->cursed) || obj == uamul + || obj == uleft || obj == uright || obj == ublindf + || obj == uarm || obj == uarmc || obj == uarmg + || obj == uarmf || obj == uarmu + || (obj->cursed && (obj == uarmh || obj == uarms)) + || welded(obj))) + otmp = obj; + /* reached the mark and found some stuff to drop? */ + if (--i < 0 && otmp) + break; - /* else continue */ - } - } - if (!otmp) return (FALSE); /* nothing to drop! */ - if (otmp->owornmask) remove_worn_item(otmp, FALSE); - *lostsome = TRUE; - dropx(otmp); - invc--; - } - return(TRUE); + /* else continue */ + } + } + if (!otmp) + return (FALSE); /* nothing to drop! */ + if (otmp->owornmask) + remove_worn_item(otmp, FALSE); + *lostsome = TRUE; + dropx(otmp); + invc--; + } + return (TRUE); } /* @@ -3354,148 +3466,153 @@ boolean *lostsome; boolean drown() { - const char *pool_of_water; - boolean inpool_ok = FALSE, crawl_ok; - int i, x, y; + const char *pool_of_water; + boolean inpool_ok = FALSE, crawl_ok; + int i, x, y; - /* happily wading in the same contiguous pool */ - if (u.uinwater && is_pool(u.ux-u.dx,u.uy-u.dy) && - (Swimming || Amphibious)) { - /* water effects on objects every now and then */ - if (!rn2(5)) inpool_ok = TRUE; - else return(FALSE); - } + /* happily wading in the same contiguous pool */ + if (u.uinwater && is_pool(u.ux - u.dx, u.uy - u.dy) + && (Swimming || Amphibious)) { + /* water effects on objects every now and then */ + if (!rn2(5)) + inpool_ok = TRUE; + else + return (FALSE); + } - if (!u.uinwater) { - You("%s into the water%c", - Is_waterlevel(&u.uz) ? "plunge" : "fall", - Amphibious || Swimming ? '.' : '!'); - if (!Swimming && !Is_waterlevel(&u.uz)) - You("sink like %s.", - Hallucination ? "the Titanic" : "a rock"); - } + if (!u.uinwater) { + You("%s into the water%c", Is_waterlevel(&u.uz) ? "plunge" : "fall", + Amphibious || Swimming ? '.' : '!'); + if (!Swimming && !Is_waterlevel(&u.uz)) + You("sink like %s.", Hallucination ? "the Titanic" : "a rock"); + } - water_damage_chain(invent, FALSE); + water_damage_chain(invent, FALSE); - if (u.umonnum == PM_GREMLIN && rn2(3)) - (void)split_mon(&youmonst, (struct monst *)0); - else if (u.umonnum == PM_IRON_GOLEM) { - You("rust!"); - i = Maybe_Half_Phys(d(2,6)); - if (u.mhmax > i) u.mhmax -= i; - losehp(i, "rusting away", KILLED_BY); - } - if (inpool_ok) return(FALSE); + if (u.umonnum == PM_GREMLIN && rn2(3)) + (void) split_mon(&youmonst, (struct monst *) 0); + else if (u.umonnum == PM_IRON_GOLEM) { + You("rust!"); + i = Maybe_Half_Phys(d(2, 6)); + if (u.mhmax > i) + u.mhmax -= i; + losehp(i, "rusting away", KILLED_BY); + } + if (inpool_ok) + return (FALSE); - if ((i = number_leashed()) > 0) { - pline_The("leash%s slip%s loose.", - (i > 1) ? "es" : "", - (i > 1) ? "" : "s"); - unleash_all(); - } + if ((i = number_leashed()) > 0) { + pline_The("leash%s slip%s loose.", (i > 1) ? "es" : "", + (i > 1) ? "" : "s"); + unleash_all(); + } - if (Amphibious || Swimming) { - if (Amphibious) { - if (flags.verbose) - pline("But you aren't drowning."); - if (!Is_waterlevel(&u.uz)) { - if (Hallucination) - Your("keel hits the bottom."); - else - You("touch bottom."); - } - } - if (Punished) { - unplacebc(); - placebc(); - } - vision_recalc(2); /* unsee old position */ - u.uinwater = 1; - under_water(1); - vision_full_recalc = 1; - return(FALSE); - } - if ((Teleportation || can_teleport(youmonst.data)) && - !Unaware && (Teleport_control || rn2(3) < Luck+2)) { - You("attempt a teleport spell."); /* utcsri!carroll */ - if (!level.flags.noteleport) { - (void) dotele(); - if(!is_pool(u.ux,u.uy)) - return(TRUE); - } else pline_The("attempted teleport spell fails."); - } - if (u.usteed) { - dismount_steed(DISMOUNT_GENERIC); - if(!is_pool(u.ux,u.uy)) - return(TRUE); - } - crawl_ok = FALSE; - x = y = 0; /* lint suppression */ - /* if sleeping, wake up now so that we don't crawl out of water - while still asleep; we can't do that the same way that waking - due to combat is handled; note unmul() clears u.usleep */ - if (u.usleep) unmul("Suddenly you wake up!"); - /* being doused will revive from fainting */ - if (is_fainted()) reset_faint(); - /* can't crawl if unable to move (crawl_ok flag stays false) */ - if (multi < 0 || (Upolyd && !youmonst.data->mmove)) goto crawl; - /* look around for a place to crawl to */ - for (i = 0; i < 100; i++) { - x = rn1(3,u.ux - 1); - y = rn1(3,u.uy - 1); - if (crawl_destination(x, y)) { - crawl_ok = TRUE; - goto crawl; - } - } - /* one more scan */ - for (x = u.ux - 1; x <= u.ux + 1; x++) - for (y = u.uy - 1; y <= u.uy + 1; y++) - if (crawl_destination(x, y)) { - crawl_ok = TRUE; - goto crawl; - } - crawl: - if (crawl_ok) { - boolean lost = FALSE; - /* time to do some strip-tease... */ - boolean succ = Is_waterlevel(&u.uz) ? TRUE : - emergency_disrobe(&lost); + if (Amphibious || Swimming) { + if (Amphibious) { + if (flags.verbose) + pline("But you aren't drowning."); + if (!Is_waterlevel(&u.uz)) { + if (Hallucination) + Your("keel hits the bottom."); + else + You("touch bottom."); + } + } + if (Punished) { + unplacebc(); + placebc(); + } + vision_recalc(2); /* unsee old position */ + u.uinwater = 1; + under_water(1); + vision_full_recalc = 1; + return (FALSE); + } + if ((Teleportation || can_teleport(youmonst.data)) && !Unaware + && (Teleport_control || rn2(3) < Luck + 2)) { + You("attempt a teleport spell."); /* utcsri!carroll */ + if (!level.flags.noteleport) { + (void) dotele(); + if (!is_pool(u.ux, u.uy)) + return (TRUE); + } else + pline_The("attempted teleport spell fails."); + } + if (u.usteed) { + dismount_steed(DISMOUNT_GENERIC); + if (!is_pool(u.ux, u.uy)) + return (TRUE); + } + crawl_ok = FALSE; + x = y = 0; /* lint suppression */ + /* if sleeping, wake up now so that we don't crawl out of water + while still asleep; we can't do that the same way that waking + due to combat is handled; note unmul() clears u.usleep */ + if (u.usleep) + unmul("Suddenly you wake up!"); + /* being doused will revive from fainting */ + if (is_fainted()) + reset_faint(); + /* can't crawl if unable to move (crawl_ok flag stays false) */ + if (multi < 0 || (Upolyd && !youmonst.data->mmove)) + goto crawl; + /* look around for a place to crawl to */ + for (i = 0; i < 100; i++) { + x = rn1(3, u.ux - 1); + y = rn1(3, u.uy - 1); + if (crawl_destination(x, y)) { + crawl_ok = TRUE; + goto crawl; + } + } + /* one more scan */ + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) + if (crawl_destination(x, y)) { + crawl_ok = TRUE; + goto crawl; + } +crawl: + if (crawl_ok) { + boolean lost = FALSE; + /* time to do some strip-tease... */ + boolean succ = Is_waterlevel(&u.uz) ? TRUE : emergency_disrobe(&lost); - You("try to crawl out of the water."); - if (lost) - You("dump some of your gear to lose weight..."); - if (succ) { - pline("Pheew! That was close."); - teleds(x,y,TRUE); - return(TRUE); - } - /* still too much weight */ - pline("But in vain."); - } - u.uinwater = 1; - You("drown."); - for (i = 0; i < 5; i++) { /* arbitrary number of loops */ - /* killer format and name are reconstructed every iteration - because lifesaving resets them */ - pool_of_water = waterbody_name(u.ux, u.uy); - killer.format = KILLED_BY_AN; - /* avoid "drowned in [a] water" */ - if (!strcmp(pool_of_water, "water")) - pool_of_water = "deep water", killer.format = KILLED_BY; - Strcpy(killer.name, pool_of_water); - done(DROWNING); - /* oops, we're still alive. better get out of the water. */ - if (safe_teleds(TRUE)) break; /* successful life-save */ - /* nowhere safe to land; repeat drowning loop... */ - pline("You're still drowning."); - } - if (u.uinwater) { - u.uinwater = 0; - You("find yourself back %s.", Is_waterlevel(&u.uz) ? - "in an air bubble" : "on land"); - } - return(TRUE); + You("try to crawl out of the water."); + if (lost) + You("dump some of your gear to lose weight..."); + if (succ) { + pline("Pheew! That was close."); + teleds(x, y, TRUE); + return (TRUE); + } + /* still too much weight */ + pline("But in vain."); + } + u.uinwater = 1; + You("drown."); + for (i = 0; i < 5; i++) { /* arbitrary number of loops */ + /* killer format and name are reconstructed every iteration + because lifesaving resets them */ + pool_of_water = waterbody_name(u.ux, u.uy); + killer.format = KILLED_BY_AN; + /* avoid "drowned in [a] water" */ + if (!strcmp(pool_of_water, "water")) + pool_of_water = "deep water", killer.format = KILLED_BY; + Strcpy(killer.name, pool_of_water); + done(DROWNING); + /* oops, we're still alive. better get out of the water. */ + if (safe_teleds(TRUE)) + break; /* successful life-save */ + /* nowhere safe to land; repeat drowning loop... */ + pline("You're still drowning."); + } + if (u.uinwater) { + u.uinwater = 0; + You("find yourself back %s.", + Is_waterlevel(&u.uz) ? "in an air bubble" : "on land"); + } + return (TRUE); } void @@ -3503,44 +3620,44 @@ drain_en(n) register int n; { if (!u.uenmax) { - /* energy is completely gone */ - You_feel("momentarily lethargic."); + /* energy is completely gone */ + You_feel("momentarily lethargic."); } else { - /* throttle further loss a bit when there's not much left to lose */ - if (n > u.uenmax || n > u.ulevel) n = rnd(n); + /* throttle further loss a bit when there's not much left to lose */ + if (n > u.uenmax || n > u.ulevel) + n = rnd(n); - You_feel("your magical energy drain away%c", - (n > u.uen) ? '!' : '.'); - u.uen -= n; - if(u.uen < 0) { - u.uenmax -= rnd(-u.uen); - if(u.uenmax < 0) u.uenmax = 0; - u.uen = 0; - } - context.botl = 1; + You_feel("your magical energy drain away%c", (n > u.uen) ? '!' : '.'); + u.uen -= n; + if (u.uen < 0) { + u.uenmax -= rnd(-u.uen); + if (u.uenmax < 0) + u.uenmax = 0; + u.uen = 0; + } + context.botl = 1; } } -int -dountrap() /* disarm a trap */ +int dountrap() /* disarm a trap */ { - if (near_capacity() >= HVY_ENCUMBER) { - pline("You're too strained to do that."); - return 0; - } - if ((nohands(youmonst.data) && !webmaker(youmonst.data)) || !youmonst.data->mmove) { - pline("And just how do you expect to do that?"); - return 0; - } else if (u.ustuck && sticks(youmonst.data)) { - pline("You'll have to let go of %s first.", mon_nam(u.ustuck)); - return 0; - } - if (u.ustuck || (welded(uwep) && bimanual(uwep))) { - Your("%s seem to be too busy for that.", - makeplural(body_part(HAND))); - return 0; - } - return untrap(FALSE); + if (near_capacity() >= HVY_ENCUMBER) { + pline("You're too strained to do that."); + return 0; + } + if ((nohands(youmonst.data) && !webmaker(youmonst.data)) + || !youmonst.data->mmove) { + pline("And just how do you expect to do that?"); + return 0; + } else if (u.ustuck && sticks(youmonst.data)) { + pline("You'll have to let go of %s first.", mon_nam(u.ustuck)); + return 0; + } + if (u.ustuck || (welded(uwep) && bimanual(uwep))) { + Your("%s seem to be too busy for that.", makeplural(body_part(HAND))); + return 0; + } + return untrap(FALSE); } /* Probability of disabling a trap. Helge Hafting */ @@ -3548,22 +3665,30 @@ STATIC_OVL int untrap_prob(ttmp) struct trap *ttmp; { - int chance = 3; + int chance = 3; - /* Only spiders know how to deal with webs reliably */ - if (ttmp->ttyp == WEB && !webmaker(youmonst.data)) - chance = 30; - if (Confusion || Hallucination) chance++; - if (Blind) chance++; - if (Stunned) chance += 2; - if (Fumbling) chance *= 2; - /* Your own traps are better known than others. */ - if (ttmp && ttmp->madeby_u) chance--; - if (Role_if(PM_ROGUE)) { - if (rn2(2 * MAXULEV) < u.ulevel) chance--; - if (u.uhave.questart && chance > 1) chance--; - } else if (Role_if(PM_RANGER) && chance > 1) chance--; - return rn2(chance); + /* Only spiders know how to deal with webs reliably */ + if (ttmp->ttyp == WEB && !webmaker(youmonst.data)) + chance = 30; + if (Confusion || Hallucination) + chance++; + if (Blind) + chance++; + if (Stunned) + chance += 2; + if (Fumbling) + chance *= 2; + /* Your own traps are better known than others. */ + if (ttmp && ttmp->madeby_u) + chance--; + if (Role_if(PM_ROGUE)) { + if (rn2(2 * MAXULEV) < u.ulevel) + chance--; + if (u.uhave.questart && chance > 1) + chance--; + } else if (Role_if(PM_RANGER) && chance > 1) + chance--; + return rn2(chance); } /* Replace trap with object(s). Helge Hafting */ @@ -3574,25 +3699,27 @@ int cnt; struct trap *ttmp; boolean bury_it; { - struct obj *otmp = mksobj(otyp, TRUE, FALSE); + struct obj *otmp = mksobj(otyp, TRUE, FALSE); - otmp->quan = cnt; - otmp->owt = weight(otmp); - /* Only dart traps are capable of being poisonous */ - if (otyp != DART) - otmp->opoisoned = 0; - place_object(otmp, ttmp->tx, ttmp->ty); - if (bury_it) { - /* magical digging first disarms this trap, then will unearth it */ - (void) bury_an_obj(otmp, NULL); - } else { - /* Sell your own traps only... */ - if (ttmp->madeby_u) sellobj(otmp, ttmp->tx, ttmp->ty); - stackobj(otmp); - } - newsym(ttmp->tx, ttmp->ty); - if (u.utrap && ttmp->tx == u.ux && ttmp->ty == u.uy) u.utrap = 0; - deltrap(ttmp); + otmp->quan = cnt; + otmp->owt = weight(otmp); + /* Only dart traps are capable of being poisonous */ + if (otyp != DART) + otmp->opoisoned = 0; + place_object(otmp, ttmp->tx, ttmp->ty); + if (bury_it) { + /* magical digging first disarms this trap, then will unearth it */ + (void) bury_an_obj(otmp, NULL); + } else { + /* Sell your own traps only... */ + if (ttmp->madeby_u) + sellobj(otmp, ttmp->tx, ttmp->ty); + stackobj(otmp); + } + newsym(ttmp->tx, ttmp->ty); + if (u.utrap && ttmp->tx == u.ux && ttmp->ty == u.uy) + u.utrap = 0; + deltrap(ttmp); } /* while attempting to disarm an adjacent trap, we've fallen into it */ @@ -3600,29 +3727,30 @@ STATIC_OVL void move_into_trap(ttmp) struct trap *ttmp; { - int bc; - xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy; - boolean unused; + int bc; + xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy; + boolean unused; - /* we know there's no monster in the way, and we're not trapped */ - if (!Punished || - drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) { - u.ux0 = u.ux, u.uy0 = u.uy; - u.ux = x, u.uy = y; - u.umoved = TRUE; - newsym(u.ux0, u.uy0); - vision_recalc(1); - check_leash(u.ux0, u.uy0); - if (Punished) move_bc(0, bc, bx, by, cx, cy); - /* marking the trap unseen forces dotrap() to treat it like a new - discovery and prevents pickup() -> look_here() -> check_here() - from giving a redudant "there is a here" message when - there are objects covering this trap */ - ttmp->tseen = 0; /* hack for check_here() */ - /* trigger the trap */ - spoteffects(TRUE); /* pickup() + dotrap() */ - exercise(A_WIS, FALSE); - } + /* we know there's no monster in the way, and we're not trapped */ + if (!Punished + || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) { + u.ux0 = u.ux, u.uy0 = u.uy; + u.ux = x, u.uy = y; + u.umoved = TRUE; + newsym(u.ux0, u.uy0); + vision_recalc(1); + check_leash(u.ux0, u.uy0); + if (Punished) + move_bc(0, bc, bx, by, cx, cy); + /* marking the trap unseen forces dotrap() to treat it like a new + discovery and prevents pickup() -> look_here() -> check_here() + from giving a redudant "there is a here" message when + there are objects covering this trap */ + ttmp->tseen = 0; /* hack for check_here() */ + /* trigger the trap */ + spoteffects(TRUE); /* pickup() + dotrap() */ + exercise(A_WIS, FALSE); + } } /* 0: doesn't even try @@ -3634,80 +3762,81 @@ try_disarm(ttmp, force_failure) struct trap *ttmp; boolean force_failure; { - struct monst *mtmp = m_at(ttmp->tx,ttmp->ty); - int ttype = ttmp->ttyp; - boolean under_u = (!u.dx && !u.dy); - boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB); - - /* Test for monster first, monsters are displayed instead of trap. */ - if (mtmp && (!mtmp->mtrapped || !holdingtrap)) { - pline("%s is in the way.", Monnam(mtmp)); - return 0; - } - /* We might be forced to move onto the trap's location. */ - if (sobj_at(BOULDER, ttmp->tx, ttmp->ty) - && !Passes_walls && !under_u) { - There("is a boulder in your way."); - return 0; - } - /* duplicate tight-space checks from test_move */ - if (u.dx && u.dy && - bad_rock(youmonst.data,u.ux,ttmp->ty) && - bad_rock(youmonst.data,ttmp->tx,u.uy)) { - if ((invent && (inv_weight() + weight_cap() > 600)) || - bigmonst(youmonst.data)) { - /* don't allow untrap if they can't get thru to it */ - You("are unable to reach the %s!", - defsyms[trap_to_defsym(ttype)].explanation); - return 0; - } - } - /* untrappable traps are located on the ground. */ - if (!can_reach_floor(TRUE)) { - if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) - rider_cant_reach(); - else - You("are unable to reach the %s!", - defsyms[trap_to_defsym(ttype)].explanation); - return 0; - } + struct monst *mtmp = m_at(ttmp->tx, ttmp->ty); + int ttype = ttmp->ttyp; + boolean under_u = (!u.dx && !u.dy); + boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB); - /* Will our hero succeed? */ - if (force_failure || untrap_prob(ttmp)) { - if (rnl(5)) { - pline("Whoops..."); - if (mtmp) { /* must be a trap that holds monsters */ - if (ttype == BEAR_TRAP) { - if (mtmp->mtame) abuse_dog(mtmp); - if ((mtmp->mhp -= rnd(4)) <= 0) killed(mtmp); - } else if (ttype == WEB) { - if (!webmaker(youmonst.data)) { - struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB); - if (ttmp2) { - pline_The("webbing sticks to you. You're caught too!"); - dotrap(ttmp2, NOWEBMSG); - if (u.usteed && u.utrap) { - /* you, not steed, are trapped */ - dismount_steed(DISMOUNT_FELL); - } - } - } else - pline("%s remains entangled.", Monnam(mtmp)); - } - } else if (under_u) { - dotrap(ttmp, 0); - } else { - move_into_trap(ttmp); - } - } else { - pline("%s %s is difficult to %s.", - ttmp->madeby_u ? "Your" : under_u ? "This" : "That", - defsyms[trap_to_defsym(ttype)].explanation, - (ttype == WEB) ? "remove" : "disarm"); - } - return 1; - } - return 2; + /* Test for monster first, monsters are displayed instead of trap. */ + if (mtmp && (!mtmp->mtrapped || !holdingtrap)) { + pline("%s is in the way.", Monnam(mtmp)); + return 0; + } + /* We might be forced to move onto the trap's location. */ + if (sobj_at(BOULDER, ttmp->tx, ttmp->ty) && !Passes_walls && !under_u) { + There("is a boulder in your way."); + return 0; + } + /* duplicate tight-space checks from test_move */ + if (u.dx && u.dy && bad_rock(youmonst.data, u.ux, ttmp->ty) + && bad_rock(youmonst.data, ttmp->tx, u.uy)) { + if ((invent && (inv_weight() + weight_cap() > 600)) + || bigmonst(youmonst.data)) { + /* don't allow untrap if they can't get thru to it */ + You("are unable to reach the %s!", + defsyms[trap_to_defsym(ttype)].explanation); + return 0; + } + } + /* untrappable traps are located on the ground. */ + if (!can_reach_floor(TRUE)) { + if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) + rider_cant_reach(); + else + You("are unable to reach the %s!", + defsyms[trap_to_defsym(ttype)].explanation); + return 0; + } + + /* Will our hero succeed? */ + if (force_failure || untrap_prob(ttmp)) { + if (rnl(5)) { + pline("Whoops..."); + if (mtmp) { /* must be a trap that holds monsters */ + if (ttype == BEAR_TRAP) { + if (mtmp->mtame) + abuse_dog(mtmp); + if ((mtmp->mhp -= rnd(4)) <= 0) + killed(mtmp); + } else if (ttype == WEB) { + if (!webmaker(youmonst.data)) { + struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB); + if (ttmp2) { + pline_The( + "webbing sticks to you. You're caught too!"); + dotrap(ttmp2, NOWEBMSG); + if (u.usteed && u.utrap) { + /* you, not steed, are trapped */ + dismount_steed(DISMOUNT_FELL); + } + } + } else + pline("%s remains entangled.", Monnam(mtmp)); + } + } else if (under_u) { + dotrap(ttmp, 0); + } else { + move_into_trap(ttmp); + } + } else { + pline("%s %s is difficult to %s.", + ttmp->madeby_u ? "Your" : under_u ? "This" : "That", + defsyms[trap_to_defsym(ttype)].explanation, + (ttype == WEB) ? "remove" : "disarm"); + } + return 1; + } + return 2; } STATIC_OVL void @@ -3715,103 +3844,105 @@ reward_untrap(ttmp, mtmp) struct trap *ttmp; struct monst *mtmp; { - if (!ttmp->madeby_u) { - if (rnl(10) < 8 && !mtmp->mpeaceful && - !mtmp->msleeping && !mtmp->mfrozen && - !mindless(mtmp->data) && - mtmp->data->mlet != S_HUMAN) { - mtmp->mpeaceful = 1; - set_malign(mtmp); /* reset alignment */ - pline("%s is grateful.", Monnam(mtmp)); - } - /* Helping someone out of a trap is a nice thing to do, - * A lawful may be rewarded, but not too often. */ - if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) { - adjalign(1); - You_feel("that you did the right thing."); - } - } + if (!ttmp->madeby_u) { + if (rnl(10) < 8 && !mtmp->mpeaceful && !mtmp->msleeping + && !mtmp->mfrozen && !mindless(mtmp->data) + && mtmp->data->mlet != S_HUMAN) { + mtmp->mpeaceful = 1; + set_malign(mtmp); /* reset alignment */ + pline("%s is grateful.", Monnam(mtmp)); + } + /* Helping someone out of a trap is a nice thing to do, + * A lawful may be rewarded, but not too often. */ + if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) { + adjalign(1); + You_feel("that you did the right thing."); + } + } } -STATIC_OVL int -disarm_holdingtrap(ttmp) /* Helge Hafting */ +STATIC_OVL int disarm_holdingtrap(ttmp) /* Helge Hafting */ struct trap *ttmp; { - struct monst *mtmp; - int fails = try_disarm(ttmp, FALSE); + struct monst *mtmp; + int fails = try_disarm(ttmp, FALSE); - if (fails < 2) return fails; + if (fails < 2) + return fails; - /* ok, disarm it. */ + /* ok, disarm it. */ - /* untrap the monster, if any. - There's no need for a cockatrice test, only the trap is touched */ - if ((mtmp = m_at(ttmp->tx,ttmp->ty)) != 0) { - mtmp->mtrapped = 0; - You("remove %s %s from %s.", the_your[ttmp->madeby_u], - (ttmp->ttyp == BEAR_TRAP) ? "bear trap" : "webbing", - mon_nam(mtmp)); - reward_untrap(ttmp, mtmp); - } else { - if (ttmp->ttyp == BEAR_TRAP) { - You("disarm %s bear trap.", the_your[ttmp->madeby_u]); - cnv_trap_obj(BEARTRAP, 1, ttmp, FALSE); - } else /* if (ttmp->ttyp == WEB) */ { - You("succeed in removing %s web.", the_your[ttmp->madeby_u]); - deltrap(ttmp); - } - } - newsym(u.ux + u.dx, u.uy + u.dy); - return 1; + /* untrap the monster, if any. + There's no need for a cockatrice test, only the trap is touched */ + if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) { + mtmp->mtrapped = 0; + You("remove %s %s from %s.", the_your[ttmp->madeby_u], + (ttmp->ttyp == BEAR_TRAP) ? "bear trap" : "webbing", + mon_nam(mtmp)); + reward_untrap(ttmp, mtmp); + } else { + if (ttmp->ttyp == BEAR_TRAP) { + You("disarm %s bear trap.", the_your[ttmp->madeby_u]); + cnv_trap_obj(BEARTRAP, 1, ttmp, FALSE); + } else /* if (ttmp->ttyp == WEB) */ { + You("succeed in removing %s web.", the_your[ttmp->madeby_u]); + deltrap(ttmp); + } + } + newsym(u.ux + u.dx, u.uy + u.dy); + return 1; } -STATIC_OVL int -disarm_landmine(ttmp) /* Helge Hafting */ +STATIC_OVL int disarm_landmine(ttmp) /* Helge Hafting */ struct trap *ttmp; { - int fails = try_disarm(ttmp, FALSE); + int fails = try_disarm(ttmp, FALSE); - if (fails < 2) return fails; - You("disarm %s land mine.", the_your[ttmp->madeby_u]); - cnv_trap_obj(LAND_MINE, 1, ttmp, FALSE); - return 1; + if (fails < 2) + return fails; + You("disarm %s land mine.", the_your[ttmp->madeby_u]); + cnv_trap_obj(LAND_MINE, 1, ttmp, FALSE); + return 1; } /* getobj will filter down to cans of grease and known potions of oil */ -static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS, 0 }; +static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS, + 0 }; /* it may not make much sense to use grease on floor boards, but so what? */ STATIC_OVL int disarm_squeaky_board(ttmp) struct trap *ttmp; { - struct obj *obj; - boolean bad_tool; - int fails; + struct obj *obj; + boolean bad_tool; + int fails; - obj = getobj(oil, "untrap with"); - if (!obj) return 0; + obj = getobj(oil, "untrap with"); + if (!obj) + return 0; - bad_tool = (obj->cursed || - ((obj->otyp != POT_OIL || obj->lamplit) && - (obj->otyp != CAN_OF_GREASE || !obj->spe))); + bad_tool = + (obj->cursed || ((obj->otyp != POT_OIL || obj->lamplit) + && (obj->otyp != CAN_OF_GREASE || !obj->spe))); - fails = try_disarm(ttmp, bad_tool); - if (fails < 2) return fails; + fails = try_disarm(ttmp, bad_tool); + if (fails < 2) + return fails; - /* successfully used oil or grease to fix squeaky board */ - if (obj->otyp == CAN_OF_GREASE) { - consume_obj_charge(obj, TRUE); - } else { - useup(obj); /* oil */ - makeknown(POT_OIL); - } - You("repair the squeaky board."); /* no madeby_u */ - deltrap(ttmp); - newsym(u.ux + u.dx, u.uy + u.dy); - more_experienced(1, 5); - newexplevel(); - return 1; + /* successfully used oil or grease to fix squeaky board */ + if (obj->otyp == CAN_OF_GREASE) { + consume_obj_charge(obj, TRUE); + } else { + useup(obj); /* oil */ + makeknown(POT_OIL); + } + You("repair the squeaky board."); /* no madeby_u */ + deltrap(ttmp); + newsym(u.ux + u.dx, u.uy + u.dy); + more_experienced(1, 5); + newexplevel(); + return 1; } /* removes traps that shoot arrows, darts, etc. */ @@ -3820,12 +3951,13 @@ disarm_shooting_trap(ttmp, otyp) struct trap *ttmp; int otyp; { - int fails = try_disarm(ttmp, FALSE); + int fails = try_disarm(ttmp, FALSE); - if (fails < 2) return fails; - You("disarm %s trap.", the_your[ttmp->madeby_u]); - cnv_trap_obj(otyp, 50-rnl(50), ttmp, FALSE); - return 1; + if (fails < 2) + return fails; + You("disarm %s trap.", the_your[ttmp->madeby_u]); + cnv_trap_obj(otyp, 50 - rnl(50), ttmp, FALSE); + return 1; } /* Is the weight too heavy? @@ -3837,21 +3969,21 @@ struct trap *ttmp; int wt; boolean stuff; { - int wc = weight_cap(); + int wc = weight_cap(); - if (((wt * 2) / wc) >= HVY_ENCUMBER) { - pline("%s is %s for you to lift.", Monnam(mtmp), - stuff ? "carrying too much" : "too heavy"); - if (!ttmp->madeby_u && !mtmp->mpeaceful && mtmp->mcanmove && - !mindless(mtmp->data) && - mtmp->data->mlet != S_HUMAN && rnl(10) < 3) { - mtmp->mpeaceful = 1; - set_malign(mtmp); /* reset alignment */ - pline("%s thinks it was nice of you to try.", Monnam(mtmp)); - } - return 0; - } - return 1; + if (((wt * 2) / wc) >= HVY_ENCUMBER) { + pline("%s is %s for you to lift.", Monnam(mtmp), + stuff ? "carrying too much" : "too heavy"); + if (!ttmp->madeby_u && !mtmp->mpeaceful && mtmp->mcanmove + && !mindless(mtmp->data) && mtmp->data->mlet != S_HUMAN + && rnl(10) < 3) { + mtmp->mpeaceful = 1; + set_malign(mtmp); /* reset alignment */ + pline("%s thinks it was nice of you to try.", Monnam(mtmp)); + } + return 0; + } + return 1; } /* Help trapped monster (out of a (spiked) pit) */ @@ -3860,311 +3992,324 @@ help_monster_out(mtmp, ttmp) struct monst *mtmp; struct trap *ttmp; { - int wt; - struct obj *otmp; - boolean uprob; + int wt; + struct obj *otmp; + boolean uprob; - /* - * This works when levitating too -- consistent with the ability - * to hit monsters while levitating. - * - * Should perhaps check that our hero has arms/hands at the - * moment. Helping can also be done by engulfing... - * - * Test the monster first - monsters are displayed before traps. - */ - if (!mtmp->mtrapped) { - pline("%s isn't trapped.", Monnam(mtmp)); - return 0; - } - /* Do you have the necessary capacity to lift anything? */ - if (check_capacity((char *)0)) return 1; + /* + * This works when levitating too -- consistent with the ability + * to hit monsters while levitating. + * + * Should perhaps check that our hero has arms/hands at the + * moment. Helping can also be done by engulfing... + * + * Test the monster first - monsters are displayed before traps. + */ + if (!mtmp->mtrapped) { + pline("%s isn't trapped.", Monnam(mtmp)); + return 0; + } + /* Do you have the necessary capacity to lift anything? */ + if (check_capacity((char *) 0)) + return 1; - /* Will our hero succeed? */ - if ((uprob = untrap_prob(ttmp)) && !mtmp->msleeping && mtmp->mcanmove) { - You("try to reach out your %s, but %s backs away skeptically.", - makeplural(body_part(ARM)), - mon_nam(mtmp)); - return 1; - } + /* Will our hero succeed? */ + if ((uprob = untrap_prob(ttmp)) && !mtmp->msleeping && mtmp->mcanmove) { + You("try to reach out your %s, but %s backs away skeptically.", + makeplural(body_part(ARM)), mon_nam(mtmp)); + return 1; + } + /* is it a cockatrice?... */ + if (touch_petrifies(mtmp->data) && !uarmg && !Stone_resistance) { + You("grab the trapped %s using your bare %s.", mtmp->data->mname, + makeplural(body_part(HAND))); - /* is it a cockatrice?... */ - if (touch_petrifies(mtmp->data) && !uarmg && !Stone_resistance) { - You("grab the trapped %s using your bare %s.", - mtmp->data->mname, makeplural(body_part(HAND))); + if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) + display_nhwindow(WIN_MESSAGE, FALSE); + else { + char kbuf[BUFSZ]; - if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) - display_nhwindow(WIN_MESSAGE, FALSE); - else { - char kbuf[BUFSZ]; + Sprintf(kbuf, "trying to help %s out of a pit", + an(mtmp->data->mname)); + instapetrify(kbuf); + return 1; + } + } + /* need to do cockatrice check first if sleeping or paralyzed */ + if (uprob) { + You("try to grab %s, but cannot get a firm grasp.", mon_nam(mtmp)); + if (mtmp->msleeping) { + mtmp->msleeping = 0; + pline("%s awakens.", Monnam(mtmp)); + } + return 1; + } - Sprintf(kbuf, "trying to help %s out of a pit", - an(mtmp->data->mname)); - instapetrify(kbuf); - return 1; - } - } - /* need to do cockatrice check first if sleeping or paralyzed */ - if (uprob) { - You("try to grab %s, but cannot get a firm grasp.", - mon_nam(mtmp)); - if (mtmp->msleeping) { - mtmp->msleeping = 0; - pline("%s awakens.", Monnam(mtmp)); - } - return 1; - } + You("reach out your %s and grab %s.", makeplural(body_part(ARM)), + mon_nam(mtmp)); - You("reach out your %s and grab %s.", - makeplural(body_part(ARM)), mon_nam(mtmp)); + if (mtmp->msleeping) { + mtmp->msleeping = 0; + pline("%s awakens.", Monnam(mtmp)); + } else if (mtmp->mfrozen && !rn2(mtmp->mfrozen)) { + /* After such manhandling, perhaps the effect wears off */ + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + pline("%s stirs.", Monnam(mtmp)); + } - if (mtmp->msleeping) { - mtmp->msleeping = 0; - pline("%s awakens.", Monnam(mtmp)); - } else if (mtmp->mfrozen && !rn2(mtmp->mfrozen)) { - /* After such manhandling, perhaps the effect wears off */ - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - pline("%s stirs.", Monnam(mtmp)); - } + /* is the monster too heavy? */ + wt = inv_weight() + mtmp->data->cwt; + if (!try_lift(mtmp, ttmp, wt, FALSE)) + return 1; - /* is the monster too heavy? */ - wt = inv_weight() + mtmp->data->cwt; - if (!try_lift(mtmp, ttmp, wt, FALSE)) return 1; + /* is the monster with inventory too heavy? */ + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + wt += otmp->owt; + if (!try_lift(mtmp, ttmp, wt, TRUE)) + return 1; - /* is the monster with inventory too heavy? */ - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - wt += otmp->owt; - if (!try_lift(mtmp, ttmp, wt, TRUE)) return 1; - - You("pull %s out of the pit.", mon_nam(mtmp)); - mtmp->mtrapped = 0; - fill_pit(mtmp->mx, mtmp->my); - reward_untrap(ttmp, mtmp); - return 1; + You("pull %s out of the pit.", mon_nam(mtmp)); + mtmp->mtrapped = 0; + fill_pit(mtmp->mx, mtmp->my); + reward_untrap(ttmp, mtmp); + return 1; } int untrap(force) boolean force; { - register struct obj *otmp; - register int x,y; - int ch; - struct trap *ttmp; - struct monst *mtmp; - const char *trapdescr; - boolean here, useplural, - confused = (Confusion || Hallucination), - trap_skipped = FALSE, - deal_with_floor_trap; - int boxcnt = 0; - char the_trap[BUFSZ], qbuf[QBUFSZ]; + register struct obj *otmp; + register int x, y; + int ch; + struct trap *ttmp; + struct monst *mtmp; + const char *trapdescr; + boolean here, useplural, confused = (Confusion || Hallucination), + trap_skipped = FALSE, deal_with_floor_trap; + int boxcnt = 0; + char the_trap[BUFSZ], qbuf[QBUFSZ]; - if(!getdir((char *)0)) return(0); - x = u.ux + u.dx; - y = u.uy + u.dy; - if (!isok(x, y)) { - pline_The("perils lurking there are beyond your grasp."); - return 0; - } - ttmp = t_at(x, y); - if (ttmp && !ttmp->tseen) ttmp = 0; - trapdescr = ttmp ? defsyms[trap_to_defsym(ttmp->ttyp)].explanation : 0; - here = (x == u.ux && y == u.uy); /* !u.dx && !u.dy */ + if (!getdir((char *) 0)) + return (0); + x = u.ux + u.dx; + y = u.uy + u.dy; + if (!isok(x, y)) { + pline_The("perils lurking there are beyond your grasp."); + return 0; + } + ttmp = t_at(x, y); + if (ttmp && !ttmp->tseen) + ttmp = 0; + trapdescr = ttmp ? defsyms[trap_to_defsym(ttmp->ttyp)].explanation : 0; + here = (x == u.ux && y == u.uy); /* !u.dx && !u.dy */ - if (here) /* are there are one or more containers here? */ - for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if (Is_box(otmp)) { - if (++boxcnt > 1) break; - } + if (here) /* are there are one or more containers here? */ + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (Is_box(otmp)) { + if (++boxcnt > 1) + break; + } - deal_with_floor_trap = can_reach_floor(FALSE); - if (!deal_with_floor_trap) { - *the_trap = '\0'; - if (ttmp) Strcat(the_trap, an(trapdescr)); - if (ttmp && boxcnt) Strcat(the_trap, " and "); - if (boxcnt) Strcat(the_trap, - (boxcnt == 1) ? "a container" : "containers"); - useplural = ((ttmp && boxcnt > 0) || boxcnt > 1); - /* note: boxcnt and useplural will always be 0 for !here case */ - if (ttmp || boxcnt) - There("%s %s %s but you can't reach %s%s.", - useplural ? "are" : "is", - the_trap, here ? "here" : "there", - useplural ? "them" : "it", - u.usteed ? " while mounted" : - ""); - trap_skipped = (ttmp != 0); - } else { /* deal_with_floor_trap */ + deal_with_floor_trap = can_reach_floor(FALSE); + if (!deal_with_floor_trap) { + *the_trap = '\0'; + if (ttmp) + Strcat(the_trap, an(trapdescr)); + if (ttmp && boxcnt) + Strcat(the_trap, " and "); + if (boxcnt) + Strcat(the_trap, (boxcnt == 1) ? "a container" : "containers"); + useplural = ((ttmp && boxcnt > 0) || boxcnt > 1); + /* note: boxcnt and useplural will always be 0 for !here case */ + if (ttmp || boxcnt) + There("%s %s %s but you can't reach %s%s.", + useplural ? "are" : "is", the_trap, here ? "here" : "there", + useplural ? "them" : "it", + u.usteed ? " while mounted" : ""); + trap_skipped = (ttmp != 0); + } else { /* deal_with_floor_trap */ - if (ttmp) { - Strcpy(the_trap, the(trapdescr)); - if (boxcnt) { - if (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) { - You_cant("do much about %s%s.", - the_trap, u.utrap ? - " that you're stuck in" : - " while standing on the edge of it"); - trap_skipped = TRUE; - deal_with_floor_trap = FALSE; - } else { - Sprintf(qbuf, "There %s and %s here. %s %s?", - (boxcnt == 1) ? "is a container" : - "are containers", - an(trapdescr), - (ttmp->ttyp == WEB) ? "Remove" : "Disarm", - the_trap); - switch (ynq(qbuf)) { - case 'q': return(0); - case 'n': trap_skipped = TRUE; - deal_with_floor_trap = FALSE; - break; - } - } - } - if (deal_with_floor_trap) { - if (u.utrap) { - You("cannot deal with %s while trapped%s!", the_trap, - (x == u.ux && y == u.uy) ? " in it" : ""); - return 1; - } - if ((mtmp = m_at(x, y)) != 0 && - (mtmp->m_ap_type == M_AP_FURNITURE || - mtmp->m_ap_type == M_AP_OBJECT)) { - stumble_onto_mimic(mtmp); - return 1; - } - switch(ttmp->ttyp) { - case BEAR_TRAP: - case WEB: - return disarm_holdingtrap(ttmp); - case LANDMINE: - return disarm_landmine(ttmp); - case SQKY_BOARD: - return disarm_squeaky_board(ttmp); - case DART_TRAP: - return disarm_shooting_trap(ttmp, DART); - case ARROW_TRAP: - return disarm_shooting_trap(ttmp, ARROW); - case PIT: - case SPIKED_PIT: - if (here) { - You("are already on the edge of the pit."); - return 0; - } - if (!mtmp) { - pline("Try filling the pit instead."); - return 0; - } - return help_monster_out(mtmp, ttmp); - default: - You("cannot disable %s trap.", - !here ? "that" : "this"); - return 0; - } - } - } /* end if */ + if (ttmp) { + Strcpy(the_trap, the(trapdescr)); + if (boxcnt) { + if (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) { + You_cant("do much about %s%s.", the_trap, + u.utrap ? " that you're stuck in" + : " while standing on the edge of it"); + trap_skipped = TRUE; + deal_with_floor_trap = FALSE; + } else { + Sprintf( + qbuf, "There %s and %s here. %s %s?", + (boxcnt == 1) ? "is a container" : "are containers", + an(trapdescr), + (ttmp->ttyp == WEB) ? "Remove" : "Disarm", the_trap); + switch (ynq(qbuf)) { + case 'q': + return (0); + case 'n': + trap_skipped = TRUE; + deal_with_floor_trap = FALSE; + break; + } + } + } + if (deal_with_floor_trap) { + if (u.utrap) { + You("cannot deal with %s while trapped%s!", the_trap, + (x == u.ux && y == u.uy) ? " in it" : ""); + return 1; + } + if ((mtmp = m_at(x, y)) != 0 + && (mtmp->m_ap_type == M_AP_FURNITURE + || mtmp->m_ap_type == M_AP_OBJECT)) { + stumble_onto_mimic(mtmp); + return 1; + } + switch (ttmp->ttyp) { + case BEAR_TRAP: + case WEB: + return disarm_holdingtrap(ttmp); + case LANDMINE: + return disarm_landmine(ttmp); + case SQKY_BOARD: + return disarm_squeaky_board(ttmp); + case DART_TRAP: + return disarm_shooting_trap(ttmp, DART); + case ARROW_TRAP: + return disarm_shooting_trap(ttmp, ARROW); + case PIT: + case SPIKED_PIT: + if (here) { + You("are already on the edge of the pit."); + return 0; + } + if (!mtmp) { + pline("Try filling the pit instead."); + return 0; + } + return help_monster_out(mtmp, ttmp); + default: + You("cannot disable %s trap.", !here ? "that" : "this"); + return 0; + } + } + } /* end if */ - if (boxcnt) { - for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) - if(Is_box(otmp)) { - (void)safe_qbuf(qbuf, "There is ", - " here. Check it for traps?", - otmp, doname, ansimpleoname, "a box"); - switch (ynq(qbuf)) { - case 'q': return(0); - case 'n': continue; - } + if (boxcnt) { + for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) + if (Is_box(otmp)) { + (void) safe_qbuf(qbuf, "There is ", + " here. Check it for traps?", otmp, + doname, ansimpleoname, "a box"); + switch (ynq(qbuf)) { + case 'q': + return (0); + case 'n': + continue; + } - if((otmp->otrapped && (force || (!confused - && rn2(MAXULEV + 1 - u.ulevel) < 10))) - || (!force && confused && !rn2(3))) { - You("find a trap on %s!", the(xname(otmp))); - if (!confused) exercise(A_WIS, TRUE); + if ((otmp->otrapped + && (force || (!confused + && rn2(MAXULEV + 1 - u.ulevel) < 10))) + || (!force && confused && !rn2(3))) { + You("find a trap on %s!", the(xname(otmp))); + if (!confused) + exercise(A_WIS, TRUE); - switch (ynq("Disarm it?")) { - case 'q': return(1); - case 'n': trap_skipped = TRUE; continue; - } + switch (ynq("Disarm it?")) { + case 'q': + return (1); + case 'n': + trap_skipped = TRUE; + continue; + } - if(otmp->otrapped) { - exercise(A_DEX, TRUE); - ch = ACURR(A_DEX) + u.ulevel; - if (Role_if(PM_ROGUE)) ch *= 2; - if(!force && (confused || Fumbling || - rnd(75+level_difficulty()/2) > ch)) { - (void) chest_trap(otmp, FINGER, TRUE); - } else { - You("disarm it!"); - otmp->otrapped = 0; - } - } else pline("That %s was not trapped.", xname(otmp)); - return(1); - } else { - You("find no traps on %s.", the(xname(otmp))); - return(1); - } - } + if (otmp->otrapped) { + exercise(A_DEX, TRUE); + ch = ACURR(A_DEX) + u.ulevel; + if (Role_if(PM_ROGUE)) + ch *= 2; + if (!force && (confused || Fumbling + || rnd(75 + level_difficulty() / 2) + > ch)) { + (void) chest_trap(otmp, FINGER, TRUE); + } else { + You("disarm it!"); + otmp->otrapped = 0; + } + } else + pline("That %s was not trapped.", xname(otmp)); + return (1); + } else { + You("find no traps on %s.", the(xname(otmp))); + return (1); + } + } - You(trap_skipped ? "find no other traps here." - : "know of no traps here."); - return(0); - } + You(trap_skipped ? "find no other traps here." + : "know of no traps here."); + return (0); + } - if (stumble_on_door_mimic(x,y)) return 1; + if (stumble_on_door_mimic(x, y)) + return 1; - } /* deal_with_floor_trap */ - /* doors can be manipulated even while levitating/unskilled riding */ + } /* deal_with_floor_trap */ + /* doors can be manipulated even while levitating/unskilled riding */ - if (!IS_DOOR(levl[x][y].typ)) { - if (!trap_skipped) - You("know of no traps there."); - return(0); - } + if (!IS_DOOR(levl[x][y].typ)) { + if (!trap_skipped) + You("know of no traps there."); + return (0); + } - switch (levl[x][y].doormask) { - case D_NODOOR: - You("%s no door there.", Blind ? "feel" : "see"); - return(0); - case D_ISOPEN: - pline("This door is safely open."); - return(0); - case D_BROKEN: - pline("This door is broken."); - return(0); - } + switch (levl[x][y].doormask) { + case D_NODOOR: + You("%s no door there.", Blind ? "feel" : "see"); + return (0); + case D_ISOPEN: + pline("This door is safely open."); + return (0); + case D_BROKEN: + pline("This door is broken."); + return (0); + } - if ((levl[x][y].doormask & D_TRAPPED - && (force || - (!confused && rn2(MAXULEV - u.ulevel + 11) < 10))) - || (!force && confused && !rn2(3))) { - You("find a trap on the door!"); - exercise(A_WIS, TRUE); - if (ynq("Disarm it?") != 'y') return(1); - if (levl[x][y].doormask & D_TRAPPED) { - ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel*3 : u.ulevel); - exercise(A_DEX, TRUE); - if(!force && (confused || Fumbling || - rnd(75+level_difficulty()/2) > ch)) { - You("set it off!"); - b_trapped("door", FINGER); - levl[x][y].doormask = D_NODOOR; - unblock_point(x, y); - newsym(x, y); - /* (probably ought to charge for this damage...) */ - if (*in_rooms(x, y, SHOPBASE)) add_damage(x, y, 0L); - } else { - You("disarm it!"); - levl[x][y].doormask &= ~D_TRAPPED; - } - } else pline("This door was not trapped."); - return(1); - } else { - You("find no traps on the door."); - return(1); - } + if ((levl[x][y].doormask & D_TRAPPED + && (force || (!confused && rn2(MAXULEV - u.ulevel + 11) < 10))) + || (!force && confused && !rn2(3))) { + You("find a trap on the door!"); + exercise(A_WIS, TRUE); + if (ynq("Disarm it?") != 'y') + return (1); + if (levl[x][y].doormask & D_TRAPPED) { + ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel * 3 : u.ulevel); + exercise(A_DEX, TRUE); + if (!force && (confused || Fumbling + || rnd(75 + level_difficulty() / 2) > ch)) { + You("set it off!"); + b_trapped("door", FINGER); + levl[x][y].doormask = D_NODOOR; + unblock_point(x, y); + newsym(x, y); + /* (probably ought to charge for this damage...) */ + if (*in_rooms(x, y, SHOPBASE)) + add_damage(x, y, 0L); + } else { + You("disarm it!"); + levl[x][y].doormask &= ~D_TRAPPED; + } + } else + pline("This door was not trapped."); + return (1); + } else { + You("find no traps on the door."); + return (1); + } } /* for magic unlocking; returns true if targetted monster (which might @@ -4172,51 +4317,56 @@ boolean force; boolean openholdingtrap(mon, noticed) struct monst *mon; -boolean *noticed; /* set to true iff hero notices the effect; */ -{ /* otherwise left with its previous value intact */ +boolean *noticed; /* set to true iff hero notices the effect; */ +{ /* otherwise left with its previous value intact */ struct trap *t; char buf[BUFSZ]; const char *trapdescr, *which; boolean ishero = (mon == &youmonst); - if (mon == u.usteed) ishero = TRUE; + if (mon == u.usteed) + ishero = TRUE; t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); /* if no trap here or it's not a holding trap, we're done */ - if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) return FALSE; + if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) + return FALSE; trapdescr = defsyms[trap_to_defsym(t->ttyp)].explanation; - which = t->tseen ? the_your[t->madeby_u] : - index(vowels, *trapdescr) ? "an" : "a"; + which = t->tseen ? the_your[t->madeby_u] + : index(vowels, *trapdescr) ? "an" : "a"; if (ishero) { - if (!u.utrap) return FALSE; - u.utrap = 0; /* released regardless of type */ - *noticed = TRUE; - /* give message only if trap was the expected type */ - if (u.utraptype == TT_BEARTRAP || u.utraptype == TT_WEB) { - if (u.usteed) - Sprintf(buf, "%s is", noit_Monnam(u.usteed)); - else - Strcpy(buf, "You are"); - pline("%s released from %s %s.", buf, which, trapdescr); - } + if (!u.utrap) + return FALSE; + u.utrap = 0; /* released regardless of type */ + *noticed = TRUE; + /* give message only if trap was the expected type */ + if (u.utraptype == TT_BEARTRAP || u.utraptype == TT_WEB) { + if (u.usteed) + Sprintf(buf, "%s is", noit_Monnam(u.usteed)); + else + Strcpy(buf, "You are"); + pline("%s released from %s %s.", buf, which, trapdescr); + } } else { - if (!mon->mtrapped) return FALSE; - mon->mtrapped = 0; - if (canspotmon(mon)) { - *noticed = TRUE; - pline("%s is released from %s %s.", - Monnam(mon), which, trapdescr); - } else if (cansee(t->tx, t->ty) && t->tseen) { - *noticed = TRUE; - if (t->ttyp == WEB) - pline("%s is released from %s %s.", - Something, which, trapdescr); - else /* BEAR_TRAP */ - pline("%s %s opens.", upstart(strcpy(buf, which)), trapdescr); - } - /* might pacify monster if adjacent */ - if (rn2(2) && distu(mon->mx, mon->my) <= 2) reward_untrap(t, mon); + if (!mon->mtrapped) + return FALSE; + mon->mtrapped = 0; + if (canspotmon(mon)) { + *noticed = TRUE; + pline("%s is released from %s %s.", Monnam(mon), which, + trapdescr); + } else if (cansee(t->tx, t->ty) && t->tseen) { + *noticed = TRUE; + if (t->ttyp == WEB) + pline("%s is released from %s %s.", Something, which, + trapdescr); + else /* BEAR_TRAP */ + pline("%s %s opens.", upstart(strcpy(buf, which)), trapdescr); + } + /* might pacify monster if adjacent */ + if (rn2(2) && distu(mon->mx, mon->my) <= 2) + reward_untrap(t, mon); } return TRUE; } @@ -4226,35 +4376,40 @@ boolean *noticed; /* set to true iff hero notices the effect; */ boolean closeholdingtrap(mon, noticed) struct monst *mon; -boolean *noticed; /* set to true iff hero notices the effect; */ -{ /* otherwise left with its previous value intact */ +boolean *noticed; /* set to true iff hero notices the effect; */ +{ /* otherwise left with its previous value intact */ struct trap *t; unsigned dotrapflags; boolean ishero = (mon == &youmonst), result; - if (mon == u.usteed) ishero = TRUE; + if (mon == u.usteed) + ishero = TRUE; t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); /* if no trap here or it's not a holding trap, we're done */ - if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) return FALSE; + if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) + return FALSE; if (ishero) { - if (u.utrap) return FALSE; /* already trapped */ - *noticed = TRUE; - dotrapflags = FORCETRAP; - /* dotrap calls mintrap when mounted hero encounters a web */ - if (u.usteed) dotrapflags |= NOWEBMSG; - ++force_mintrap; - dotrap(t, dotrapflags); - --force_mintrap; - result = (u.utrap != 0); + if (u.utrap) + return FALSE; /* already trapped */ + *noticed = TRUE; + dotrapflags = FORCETRAP; + /* dotrap calls mintrap when mounted hero encounters a web */ + if (u.usteed) + dotrapflags |= NOWEBMSG; + ++force_mintrap; + dotrap(t, dotrapflags); + --force_mintrap; + result = (u.utrap != 0); } else { - if (mon->mtrapped) return FALSE; /* already trapped */ - /* you notice it if you see the trap close/tremble/whatever - or if you sense the monster who becomes trapped */ - *noticed = cansee(t->tx, t->ty) || canspotmon(mon); - ++force_mintrap; - result = (mintrap(mon) != 0); - --force_mintrap; + if (mon->mtrapped) + return FALSE; /* already trapped */ + /* you notice it if you see the trap close/tremble/whatever + or if you sense the monster who becomes trapped */ + *noticed = cansee(t->tx, t->ty) || canspotmon(mon); + ++force_mintrap; + result = (mintrap(mon) != 0); + --force_mintrap; } return result; } @@ -4265,36 +4420,39 @@ boolean openfallingtrap(mon, trapdoor_only, noticed) struct monst *mon; boolean trapdoor_only; -boolean *noticed; /* set to true iff hero notices the effect; */ -{ /* otherwise left with its previous value intact */ +boolean *noticed; /* set to true iff hero notices the effect; */ +{ /* otherwise left with its previous value intact */ struct trap *t; boolean ishero = (mon == &youmonst), result; - if (mon == u.usteed) ishero = TRUE; + if (mon == u.usteed) + ishero = TRUE; t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); /* if no trap here or it's not a falling trap, we're done (note: falling rock traps have a trapdoor in the ceiling) */ - if (!t || ((t->ttyp != TRAPDOOR && t->ttyp != ROCKTRAP) && - (trapdoor_only || - (t->ttyp != HOLE && t->ttyp != PIT && t->ttyp != SPIKED_PIT)))) - return FALSE; + if (!t || ((t->ttyp != TRAPDOOR && t->ttyp != ROCKTRAP) + && (trapdoor_only || (t->ttyp != HOLE && t->ttyp != PIT + && t->ttyp != SPIKED_PIT)))) + return FALSE; if (ishero) { - if (u.utrap) return FALSE; /* already trapped */ - *noticed = TRUE; - dotrap(t, FORCETRAP); - result = (u.utrap != 0); + if (u.utrap) + return FALSE; /* already trapped */ + *noticed = TRUE; + dotrap(t, FORCETRAP); + result = (u.utrap != 0); } else { - if (mon->mtrapped) return FALSE; /* already trapped */ - /* you notice it if you see the trap close/tremble/whatever - or if you sense the monster who becomes trapped */ - *noticed = cansee(t->tx, t->ty) || canspotmon(mon); - /* monster will be angered; mintrap doesn't handle that */ - wakeup(mon); - ++force_mintrap; - result = (mintrap(mon) != 0); - --force_mintrap; - /* mon might now be on the migrating monsters list */ + if (mon->mtrapped) + return FALSE; /* already trapped */ + /* you notice it if you see the trap close/tremble/whatever + or if you sense the monster who becomes trapped */ + *noticed = cansee(t->tx, t->ty) || canspotmon(mon); + /* monster will be angered; mintrap doesn't handle that */ + wakeup(mon); + ++force_mintrap; + result = (mintrap(mon) != 0); + --force_mintrap; + /* mon might now be on the migrating monsters list */ } return TRUE; } @@ -4306,212 +4464,222 @@ register struct obj *obj; register int bodypart; boolean disarm; { - register struct obj *otmp = obj, *otmp2; - char buf[80]; - const char *msg; - coord cc; + register struct obj *otmp = obj, *otmp2; + char buf[80]; + const char *msg; + coord cc; - if (get_obj_location(obj, &cc.x, &cc.y, 0)) /* might be carried */ - obj->ox = cc.x, obj->oy = cc.y; + if (get_obj_location(obj, &cc.x, &cc.y, 0)) /* might be carried */ + obj->ox = cc.x, obj->oy = cc.y; - otmp->otrapped = 0; /* trap is one-shot; clear flag first in case - chest kills you and ends up in bones file */ - You(disarm ? "set it off!" : "trigger a trap!"); - display_nhwindow(WIN_MESSAGE, FALSE); - if (Luck > -13 && rn2(13+Luck) > 7) { /* saved by luck */ - /* trap went off, but good luck prevents damage */ - switch (rn2(13)) { - case 12: - case 11: msg = "explosive charge is a dud"; break; - case 10: - case 9: msg = "electric charge is grounded"; break; - case 8: - case 7: msg = "flame fizzles out"; break; - case 6: - case 5: - case 4: msg = "poisoned needle misses"; break; - case 3: - case 2: - case 1: - case 0: msg = "gas cloud blows away"; break; - default: impossible("chest disarm bug"); msg = (char *)0; - break; - } - if (msg) pline("But luckily the %s!", msg); - } else { - switch(rn2(20) ? ((Luck >= 13) ? 0 : rn2(13-Luck)) : rn2(26)) { - case 25: - case 24: - case 23: - case 22: - case 21: { - struct monst *shkp = 0; - long loss = 0L; - boolean costly, insider; - register xchar ox = obj->ox, oy = obj->oy; + otmp->otrapped = 0; /* trap is one-shot; clear flag first in case + chest kills you and ends up in bones file */ + You(disarm ? "set it off!" : "trigger a trap!"); + display_nhwindow(WIN_MESSAGE, FALSE); + if (Luck > -13 && rn2(13 + Luck) > 7) { /* saved by luck */ + /* trap went off, but good luck prevents damage */ + switch (rn2(13)) { + case 12: + case 11: + msg = "explosive charge is a dud"; + break; + case 10: + case 9: + msg = "electric charge is grounded"; + break; + case 8: + case 7: + msg = "flame fizzles out"; + break; + case 6: + case 5: + case 4: + msg = "poisoned needle misses"; + break; + case 3: + case 2: + case 1: + case 0: + msg = "gas cloud blows away"; + break; + default: + impossible("chest disarm bug"); + msg = (char *) 0; + break; + } + if (msg) + pline("But luckily the %s!", msg); + } else { + switch (rn2(20) ? ((Luck >= 13) ? 0 : rn2(13 - Luck)) : rn2(26)) { + case 25: + case 24: + case 23: + case 22: + case 21: { + struct monst *shkp = 0; + long loss = 0L; + boolean costly, insider; + register xchar ox = obj->ox, oy = obj->oy; - /* the obj location need not be that of player */ - costly = (costly_spot(ox, oy) && - (shkp = shop_keeper(*in_rooms(ox, oy, - SHOPBASE))) != (struct monst *)0); - insider = (*u.ushops && inside_shop(u.ux, u.uy) && - *in_rooms(ox, oy, SHOPBASE) == *u.ushops); + /* the obj location need not be that of player */ + costly = (costly_spot(ox, oy) + && (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) + != (struct monst *) 0); + insider = (*u.ushops && inside_shop(u.ux, u.uy) + && *in_rooms(ox, oy, SHOPBASE) == *u.ushops); - pline("%s!", Tobjnam(obj, "explode")); - Sprintf(buf, "exploding %s", xname(obj)); + pline("%s!", Tobjnam(obj, "explode")); + Sprintf(buf, "exploding %s", xname(obj)); - if(costly) - loss += stolen_value(obj, ox, oy, - (boolean)shkp->mpeaceful, TRUE); - delete_contents(obj); - /* we're about to delete all things at this location, - * which could include the ball & chain. - * If we attempt to call unpunish() in the - * for-loop below we can end up with otmp2 - * being invalid once the chain is gone. - * Deal with ball & chain right now instead. - */ - if (Punished && !carried(uball) && - ((uchain->ox == u.ux && uchain->oy == u.uy) || - (uball->ox == u.ux && uball->oy == u.uy))) - unpunish(); + if (costly) + loss += stolen_value(obj, ox, oy, (boolean) shkp->mpeaceful, + TRUE); + delete_contents(obj); + /* we're about to delete all things at this location, + * which could include the ball & chain. + * If we attempt to call unpunish() in the + * for-loop below we can end up with otmp2 + * being invalid once the chain is gone. + * Deal with ball & chain right now instead. + */ + if (Punished && !carried(uball) + && ((uchain->ox == u.ux && uchain->oy == u.uy) + || (uball->ox == u.ux && uball->oy == u.uy))) + unpunish(); - for(otmp = level.objects[u.ux][u.uy]; - otmp; otmp = otmp2) { - otmp2 = otmp->nexthere; - if(costly) - loss += stolen_value(otmp, otmp->ox, - otmp->oy, (boolean)shkp->mpeaceful, - TRUE); - delobj(otmp); - } - wake_nearby(); - losehp(Maybe_Half_Phys(d(6,6)), buf, KILLED_BY_AN); - exercise(A_STR, FALSE); - if(costly && loss) { - if(insider) - You("owe %ld %s for objects destroyed.", - loss, currency(loss)); - else { - You("caused %ld %s worth of damage!", - loss, currency(loss)); - make_angry_shk(shkp, ox, oy); - } - } - return TRUE; - } - case 20: - case 19: - case 18: - case 17: - pline("A cloud of noxious gas billows from %s.", - the(xname(obj))); - poisoned("gas cloud", A_STR, "cloud of poison gas", - 15, FALSE); - exercise(A_CON, FALSE); - break; - case 16: - case 15: - case 14: - case 13: - You_feel("a needle prick your %s.", - body_part(bodypart)); - poisoned("needle", A_CON, "poisoned needle", - 10, FALSE); - exercise(A_CON, FALSE); - break; - case 12: - case 11: - case 10: - case 9: - dofiretrap(obj); - break; - case 8: - case 7: - case 6: { - int dmg; + for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) { + otmp2 = otmp->nexthere; + if (costly) + loss += stolen_value(otmp, otmp->ox, otmp->oy, + (boolean) shkp->mpeaceful, TRUE); + delobj(otmp); + } + wake_nearby(); + losehp(Maybe_Half_Phys(d(6, 6)), buf, KILLED_BY_AN); + exercise(A_STR, FALSE); + if (costly && loss) { + if (insider) + You("owe %ld %s for objects destroyed.", loss, + currency(loss)); + else { + You("caused %ld %s worth of damage!", loss, + currency(loss)); + make_angry_shk(shkp, ox, oy); + } + } + return TRUE; + } + case 20: + case 19: + case 18: + case 17: + pline("A cloud of noxious gas billows from %s.", the(xname(obj))); + poisoned("gas cloud", A_STR, "cloud of poison gas", 15, FALSE); + exercise(A_CON, FALSE); + break; + case 16: + case 15: + case 14: + case 13: + You_feel("a needle prick your %s.", body_part(bodypart)); + poisoned("needle", A_CON, "poisoned needle", 10, FALSE); + exercise(A_CON, FALSE); + break; + case 12: + case 11: + case 10: + case 9: + dofiretrap(obj); + break; + case 8: + case 7: + case 6: { + int dmg; - You("are jolted by a surge of electricity!"); - if(Shock_resistance) { - shieldeff(u.ux, u.uy); - You("don't seem to be affected."); - dmg = 0; - } else - dmg = d(4, 4); - destroy_item(RING_CLASS, AD_ELEC); - destroy_item(WAND_CLASS, AD_ELEC); - if (dmg) losehp(dmg, "electric shock", KILLED_BY_AN); - break; - } - case 5: - case 4: - case 3: - if (!Free_action) { - pline("Suddenly you are frozen in place!"); - nomul(-d(5, 6)); - multi_reason = "frozen by a trap"; - exercise(A_DEX, FALSE); - nomovemsg = You_can_move_again; - } else You("momentarily stiffen."); - break; - case 2: - case 1: - case 0: - pline("A cloud of %s gas billows from %s.", - Blind ? blindgas[rn2(SIZE(blindgas))] : - rndcolor(), the(xname(obj))); - if(!Stunned) { - if (Hallucination) - pline("What a groovy feeling!"); - else - You("%s%s...", - stagger(youmonst.data, "stagger"), - Halluc_resistance ? "" : - Blind ? " and get dizzy" : - " and your vision blurs"); - } - make_stunned((HStun & TIMEOUT) + (long)rn1(7, 16), - FALSE); - (void) make_hallucinated((HHallucination & TIMEOUT) - + (long)rn1(5, 16), FALSE, 0L); - break; - default: impossible("bad chest trap"); - break; - } - bot(); /* to get immediate botl re-display */ - } + You("are jolted by a surge of electricity!"); + if (Shock_resistance) { + shieldeff(u.ux, u.uy); + You("don't seem to be affected."); + dmg = 0; + } else + dmg = d(4, 4); + destroy_item(RING_CLASS, AD_ELEC); + destroy_item(WAND_CLASS, AD_ELEC); + if (dmg) + losehp(dmg, "electric shock", KILLED_BY_AN); + break; + } + case 5: + case 4: + case 3: + if (!Free_action) { + pline("Suddenly you are frozen in place!"); + nomul(-d(5, 6)); + multi_reason = "frozen by a trap"; + exercise(A_DEX, FALSE); + nomovemsg = You_can_move_again; + } else + You("momentarily stiffen."); + break; + case 2: + case 1: + case 0: + pline("A cloud of %s gas billows from %s.", + Blind ? blindgas[rn2(SIZE(blindgas))] : rndcolor(), + the(xname(obj))); + if (!Stunned) { + if (Hallucination) + pline("What a groovy feeling!"); + else + You("%s%s...", stagger(youmonst.data, "stagger"), + Halluc_resistance ? "" + : Blind ? " and get dizzy" + : " and your vision blurs"); + } + make_stunned((HStun & TIMEOUT) + (long) rn1(7, 16), FALSE); + (void) make_hallucinated( + (HHallucination & TIMEOUT) + (long) rn1(5, 16), FALSE, 0L); + break; + default: + impossible("bad chest trap"); + break; + } + bot(); /* to get immediate botl re-display */ + } - return FALSE; + return FALSE; } struct trap * -t_at(x,y) +t_at(x, y) register int x, y; { - register struct trap *trap = ftrap; - while(trap) { - if(trap->tx == x && trap->ty == y) return(trap); - trap = trap->ntrap; - } - return((struct trap *)0); + register struct trap *trap = ftrap; + while (trap) { + if (trap->tx == x && trap->ty == y) + return (trap); + trap = trap->ntrap; + } + return ((struct trap *) 0); } void deltrap(trap) register struct trap *trap; { - register struct trap *ttmp; + register struct trap *ttmp; - clear_conjoined_pits(trap); - if(trap == ftrap) - ftrap = ftrap->ntrap; - else { - for(ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) ; - ttmp->ntrap = trap->ntrap; - } - if (Sokoban && (trap->ttyp == PIT || trap->ttyp == HOLE)) - maybe_finish_sokoban(); - dealloc_trap(trap); + clear_conjoined_pits(trap); + if (trap == ftrap) + ftrap = ftrap->ntrap; + else { + for (ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) + ; + ttmp->ntrap = trap->ntrap; + } + if (Sokoban && (trap->ttyp == PIT || trap->ttyp == HOLE)) + maybe_finish_sokoban(); + dealloc_trap(trap); } boolean @@ -4519,49 +4687,50 @@ conjoined_pits(trap2, trap1, u_entering_trap2) struct trap *trap2, *trap1; boolean u_entering_trap2; { - int dx, dy, diridx, adjidx; - if (!trap1 || !trap2) return FALSE; - if (!isok(trap2->tx,trap2->ty) || !isok(trap1->tx,trap1->ty) || - !(trap2->ttyp == PIT || trap2->ttyp == SPIKED_PIT) || - !(trap1->ttyp == PIT || trap1->ttyp == SPIKED_PIT) || - (u_entering_trap2 && !(u.utrap && u.utraptype == TT_PIT))) - return FALSE; - dx = sgn(trap2->tx - trap1->tx); - dy = sgn(trap2->ty - trap1->ty); - for (diridx = 0; diridx < 8; diridx++) - if (xdir[diridx] == dx && ydir[diridx] == dy) - break; - /* diridx is valid if < 8 */ - if (diridx < 8) { - adjidx = (diridx + 4) % 8; - if ((trap1->conjoined & (1 << diridx)) && - (trap2->conjoined & (1 << adjidx))) - return TRUE; - } - return FALSE; + int dx, dy, diridx, adjidx; + if (!trap1 || !trap2) + return FALSE; + if (!isok(trap2->tx, trap2->ty) || !isok(trap1->tx, trap1->ty) + || !(trap2->ttyp == PIT || trap2->ttyp == SPIKED_PIT) + || !(trap1->ttyp == PIT || trap1->ttyp == SPIKED_PIT) + || (u_entering_trap2 && !(u.utrap && u.utraptype == TT_PIT))) + return FALSE; + dx = sgn(trap2->tx - trap1->tx); + dy = sgn(trap2->ty - trap1->ty); + for (diridx = 0; diridx < 8; diridx++) + if (xdir[diridx] == dx && ydir[diridx] == dy) + break; + /* diridx is valid if < 8 */ + if (diridx < 8) { + adjidx = (diridx + 4) % 8; + if ((trap1->conjoined & (1 << diridx)) + && (trap2->conjoined & (1 << adjidx))) + return TRUE; + } + return FALSE; } void clear_conjoined_pits(trap) struct trap *trap; { - int diridx, adjidx, x, y; - struct trap *t; - if (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { - for(diridx = 0; diridx < 8; ++diridx) { - if (trap->conjoined & (1 << diridx)) { - x = trap->tx + xdir[diridx]; - y = trap->ty + ydir[diridx]; - t = t_at(x,y); - if (isok(x,y) && t && - (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { - adjidx = (diridx + 4) % 8; - t->conjoined &= ~(1 << adjidx); - } - trap->conjoined &= ~(1 << diridx); - } - } - } + int diridx, adjidx, x, y; + struct trap *t; + if (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { + for (diridx = 0; diridx < 8; ++diridx) { + if (trap->conjoined & (1 << diridx)) { + x = trap->tx + xdir[diridx]; + y = trap->ty + ydir[diridx]; + t = t_at(x, y); + if (isok(x, y) && t + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { + adjidx = (diridx + 4) % 8; + t->conjoined &= ~(1 << adjidx); + } + trap->conjoined &= ~(1 << diridx); + } + } + } } #if 0 @@ -4597,45 +4766,38 @@ boolean uteetering_at_seen_pit(trap) struct trap *trap; { - if (trap && trap->tseen && - (!u.utrap || u.utraptype != TT_PIT) && - (trap->ttyp==PIT || trap->ttyp==SPIKED_PIT)) - return TRUE; - else - return FALSE; -} + if (trap && trap->tseen && (!u.utrap || u.utraptype != TT_PIT) + && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) + return TRUE; + else + return FALSE; +} boolean delfloortrap(ttmp) register struct trap *ttmp; { - /* Destroy a trap that emanates from the floor. */ - /* some of these are arbitrary -dlc */ - if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || - (ttmp->ttyp == BEAR_TRAP) || - (ttmp->ttyp == LANDMINE) || - (ttmp->ttyp == FIRE_TRAP) || - (ttmp->ttyp == PIT) || - (ttmp->ttyp == SPIKED_PIT) || - (ttmp->ttyp == HOLE) || - (ttmp->ttyp == TRAPDOOR) || - (ttmp->ttyp == TELEP_TRAP) || - (ttmp->ttyp == LEVEL_TELEP) || - (ttmp->ttyp == WEB) || - (ttmp->ttyp == MAGIC_TRAP) || - (ttmp->ttyp == ANTI_MAGIC))) { - register struct monst *mtmp; + /* Destroy a trap that emanates from the floor. */ + /* some of these are arbitrary -dlc */ + if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || (ttmp->ttyp == BEAR_TRAP) + || (ttmp->ttyp == LANDMINE) || (ttmp->ttyp == FIRE_TRAP) + || (ttmp->ttyp == PIT) || (ttmp->ttyp == SPIKED_PIT) + || (ttmp->ttyp == HOLE) || (ttmp->ttyp == TRAPDOOR) + || (ttmp->ttyp == TELEP_TRAP) || (ttmp->ttyp == LEVEL_TELEP) + || (ttmp->ttyp == WEB) || (ttmp->ttyp == MAGIC_TRAP) + || (ttmp->ttyp == ANTI_MAGIC))) { + register struct monst *mtmp; - if (ttmp->tx == u.ux && ttmp->ty == u.uy) { - u.utrap = 0; - u.utraptype = 0; - } else if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) { - mtmp->mtrapped = 0; - } - deltrap(ttmp); - return TRUE; - } else - return FALSE; + if (ttmp->tx == u.ux && ttmp->ty == u.uy) { + u.utrap = 0; + u.utraptype = 0; + } else if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) { + mtmp->mtrapped = 0; + } + deltrap(ttmp); + return TRUE; + } else + return FALSE; } /* used for doors (also tins). can be used for anything else that opens. */ @@ -4644,15 +4806,16 @@ b_trapped(item, bodypart) register const char *item; register int bodypart; { - register int lvl = level_difficulty(); - int dmg = rnd(5 + (lvl < 5 ? lvl : 2+lvl/2)); + register int lvl = level_difficulty(); + int dmg = rnd(5 + (lvl < 5 ? lvl : 2 + lvl / 2)); - pline("KABOOM!! %s was booby-trapped!", The(item)); - wake_nearby(); - losehp(Maybe_Half_Phys(dmg), "explosion", KILLED_BY_AN); - exercise(A_STR, FALSE); - if (bodypart) exercise(A_CON, FALSE); - make_stunned((HStun & TIMEOUT) + (long)dmg, TRUE); + pline("KABOOM!! %s was booby-trapped!", The(item)); + wake_nearby(); + losehp(Maybe_Half_Phys(dmg), "explosion", KILLED_BY_AN); + exercise(A_STR, FALSE); + if (bodypart) + exercise(A_CON, FALSE); + make_stunned((HStun & TIMEOUT) + (long) dmg, TRUE); } /* Monster is hit by trap. */ @@ -4665,56 +4828,63 @@ struct obj *obj; int d_override; boolean nocorpse; { - int strike; - boolean trapkilled = FALSE; + int strike; + boolean trapkilled = FALSE; - if (d_override) strike = 1; - else if (obj) strike = (find_mac(mon) + tlev + obj->spe <= rnd(20)); - else strike = (find_mac(mon) + tlev <= rnd(20)); + if (d_override) + strike = 1; + else if (obj) + strike = (find_mac(mon) + tlev + obj->spe <= rnd(20)); + else + strike = (find_mac(mon) + tlev <= rnd(20)); - /* Actually more accurate than thitu, which doesn't take - * obj->spe into account. - */ - if(!strike) { - if (obj && cansee(mon->mx, mon->my)) - pline("%s is almost hit by %s!", Monnam(mon), doname(obj)); - } else { - int dam = 1; + /* Actually more accurate than thitu, which doesn't take + * obj->spe into account. + */ + if (!strike) { + if (obj && cansee(mon->mx, mon->my)) + pline("%s is almost hit by %s!", Monnam(mon), doname(obj)); + } else { + int dam = 1; - if (obj && cansee(mon->mx, mon->my)) - pline("%s is hit by %s!", Monnam(mon), doname(obj)); - if (d_override) dam = d_override; - else if (obj) { - dam = dmgval(obj, mon); - if (dam < 1) dam = 1; - } - if ((mon->mhp -= dam) <= 0) { - int xx = mon->mx; - int yy = mon->my; + if (obj && cansee(mon->mx, mon->my)) + pline("%s is hit by %s!", Monnam(mon), doname(obj)); + if (d_override) + dam = d_override; + else if (obj) { + dam = dmgval(obj, mon); + if (dam < 1) + dam = 1; + } + if ((mon->mhp -= dam) <= 0) { + int xx = mon->mx; + int yy = mon->my; - monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS); - if (mon->mhp <= 0) { - newsym(xx, yy); - trapkilled = TRUE; - } - } - } - if (obj && (!strike || d_override)) { - place_object(obj, mon->mx, mon->my); - stackobj(obj); - } else if (obj) dealloc_obj(obj); + monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS); + if (mon->mhp <= 0) { + newsym(xx, yy); + trapkilled = TRUE; + } + } + } + if (obj && (!strike || d_override)) { + place_object(obj, mon->mx, mon->my); + stackobj(obj); + } else if (obj) + dealloc_obj(obj); - return trapkilled; + return trapkilled; } boolean unconscious() { - return (boolean)(multi < 0 && - (u.usleep || (nomovemsg && - (!strncmp(nomovemsg, "You awake", 9) || - !strncmp(nomovemsg, "You regain con", 14) || - !strncmp(nomovemsg, "You are consci", 14))))); + return (boolean)( + multi < 0 + && (u.usleep || (nomovemsg + && (!strncmp(nomovemsg, "You awake", 9) + || !strncmp(nomovemsg, "You regain con", 14) + || !strncmp(nomovemsg, "You are consci", 14))))); } static const char lava_killer[] = "molten lava"; @@ -4723,11 +4893,12 @@ boolean lava_effects() { register struct obj *obj, *obj2; - int dmg = d(6, 6); /* only applicable for water walking */ + int dmg = d(6, 6); /* only applicable for water walking */ boolean usurvive, boil_away; burn_away_slime(); - if (likes_lava(youmonst.data)) return FALSE; + if (likes_lava(youmonst.data)) + return FALSE; usurvive = Fire_resistance || (Wwalking && dmg < u.uhp); /* @@ -4741,102 +4912,105 @@ lava_effects() * emergency save file created before item destruction. */ if (!usurvive) - for (obj = invent; obj; obj = obj->nobj) - if ((is_organic(obj) || obj->oclass == POTION_CLASS) && - !obj->oerodeproof && - objects[obj->otyp].oc_oprop != FIRE_RES && - obj->otyp != SCR_FIRE && obj->otyp != SPE_FIREBALL && - !obj_resists(obj, 0, 0)) /* for invocation items */ - obj->in_use = TRUE; + for (obj = invent; obj; obj = obj->nobj) + if ((is_organic(obj) || obj->oclass == POTION_CLASS) + && !obj->oerodeproof + && objects[obj->otyp].oc_oprop != FIRE_RES + && obj->otyp != SCR_FIRE && obj->otyp != SPE_FIREBALL + && !obj_resists(obj, 0, 0)) /* for invocation items */ + obj->in_use = TRUE; /* Check whether we should burn away boots *first* so we know whether to - * make the player sink into the lava. Assumption: water walking only comes + * make the player sink into the lava. Assumption: water walking only + * comes * from boots. */ if (Wwalking && uarmf && is_organic(uarmf) && !uarmf->oerodeproof) { obj = uarmf; pline("%s into flame!", Yobjnam2(obj, "burst")); - iflags.in_lava_effects++; /* (see above) */ + iflags.in_lava_effects++; /* (see above) */ (void) Boots_off(); useup(obj); iflags.in_lava_effects--; } if (!Fire_resistance) { - if(Wwalking) { - pline_The("lava here burns you!"); - if (usurvive) { - losehp(dmg, lava_killer, KILLED_BY); /* lava damage */ - goto burn_stuff; - } + if (Wwalking) { + pline_The("lava here burns you!"); + if (usurvive) { + losehp(dmg, lava_killer, KILLED_BY); /* lava damage */ + goto burn_stuff; + } } else - You("fall into the lava!"); + You("fall into the lava!"); - usurvive = Lifesaved || discover; - if (wizard) usurvive = TRUE; + usurvive = Lifesaved || discover; + if (wizard) + usurvive = TRUE; - /* prevent remove_worn_item() -> Boots_off(WATER_WALKING_BOOTS) -> - spoteffects() -> lava_effects() recursion which would - successfully delete (via useupall) the no-longer-worn boots; - once recursive call returned, we would try to delete them again - here in the outer call (and access stale memory, probably panic) */ - iflags.in_lava_effects++; + /* prevent remove_worn_item() -> Boots_off(WATER_WALKING_BOOTS) -> + spoteffects() -> lava_effects() recursion which would + successfully delete (via useupall) the no-longer-worn boots; + once recursive call returned, we would try to delete them again + here in the outer call (and access stale memory, probably panic) */ + iflags.in_lava_effects++; - for(obj = invent; obj; obj = obj2) { - obj2 = obj->nobj; - /* above, we set in_use for objects which are to be destroyed */ + for (obj = invent; obj; obj = obj2) { + obj2 = obj->nobj; + /* above, we set in_use for objects which are to be destroyed */ if (obj->otyp == SPE_BOOK_OF_THE_DEAD && !Blind) { if (usurvive) pline("%s glows a strange %s, but remains intact.", The(xname(obj)), hcolor("dark red")); } else if (obj->in_use) { - if (obj->owornmask) { - if (usurvive) - pline("%s into flame!", Yobjnam2(obj, "burst")); - remove_worn_item(obj, TRUE); - } - useupall(obj); - } - } + if (obj->owornmask) { + if (usurvive) + pline("%s into flame!", Yobjnam2(obj, "burst")); + remove_worn_item(obj, TRUE); + } + useupall(obj); + } + } - iflags.in_lava_effects--; + iflags.in_lava_effects--; - /* s/he died... */ - boil_away = (u.umonnum == PM_WATER_ELEMENTAL || - u.umonnum == PM_STEAM_VORTEX || - u.umonnum == PM_FOG_CLOUD); - for (;;) { - u.uhp = -1; - /* killer format and name are reconstructed every iteration - because lifesaving resets them */ - killer.format = KILLED_BY; - Strcpy(killer.name, lava_killer); - You("%s...", boil_away ? "boil away" : "burn to a crisp"); - done(BURNING); - if (safe_teleds(TRUE)) break; /* successful life-save */ - /* nowhere safe to land; repeat burning loop */ - pline("You're still burning."); - } - You("find yourself back on solid %s.", surface(u.ux, u.uy)); - return(TRUE); + /* s/he died... */ + boil_away = + (u.umonnum == PM_WATER_ELEMENTAL || u.umonnum == PM_STEAM_VORTEX + || u.umonnum == PM_FOG_CLOUD); + for (;;) { + u.uhp = -1; + /* killer format and name are reconstructed every iteration + because lifesaving resets them */ + killer.format = KILLED_BY; + Strcpy(killer.name, lava_killer); + You("%s...", boil_away ? "boil away" : "burn to a crisp"); + done(BURNING); + if (safe_teleds(TRUE)) + break; /* successful life-save */ + /* nowhere safe to land; repeat burning loop */ + pline("You're still burning."); + } + You("find yourself back on solid %s.", surface(u.ux, u.uy)); + return (TRUE); } else if (!Wwalking && (!u.utrap || u.utraptype != TT_LAVA)) { - boil_away = !Fire_resistance; - /* if not fire resistant, sink_into_lava() will quickly be fatal; - hero needs to escape immediately */ - u.utrap = rn1(4, 4) + ((boil_away ? 2 : rn1(4, 12)) << 8); - u.utraptype = TT_LAVA; - You("sink into the lava%s!", - !boil_away ? ", but it only burns slightly" : - " and are about to be immolated"); - if (u.uhp > 1) - losehp(!boil_away ? 1 : (u.uhp / 2), - lava_killer, KILLED_BY); /* lava damage */ + boil_away = !Fire_resistance; + /* if not fire resistant, sink_into_lava() will quickly be fatal; + hero needs to escape immediately */ + u.utrap = rn1(4, 4) + ((boil_away ? 2 : rn1(4, 12)) << 8); + u.utraptype = TT_LAVA; + You("sink into the lava%s!", !boil_away + ? ", but it only burns slightly" + : " and are about to be immolated"); + if (u.uhp > 1) + losehp(!boil_away ? 1 : (u.uhp / 2), lava_killer, + KILLED_BY); /* lava damage */ } burn_stuff: destroy_item(SCROLL_CLASS, AD_FIRE); destroy_item(SPBOOK_CLASS, AD_FIRE); destroy_item(POTION_CLASS, AD_FIRE); - return(FALSE); + return (FALSE); } /* called each turn when trapped in lava */ @@ -4846,34 +5020,35 @@ sink_into_lava() static const char sink_deeper[] = "You sink deeper into the lava."; if (!u.utrap || u.utraptype != TT_LAVA) { - ; /* do nothing; this shouldn't happen */ + ; /* do nothing; this shouldn't happen */ } else if (!is_lava(u.ux, u.uy)) { - u.utrap = 0; /* this shouldn't happen either */ + u.utrap = 0; /* this shouldn't happen either */ } else if (!u.uinvulnerable) { - /* ordinarily we'd have to be fire resistant to survive long - enough to become stuck in lava, but it can happen without - resistance if water walking boots allow survival and then - get burned up; u.utrap time will be quite short in that case */ - if (!Fire_resistance) u.uhp = (u.uhp + 2) / 3; + /* ordinarily we'd have to be fire resistant to survive long + enough to become stuck in lava, but it can happen without + resistance if water walking boots allow survival and then + get burned up; u.utrap time will be quite short in that case */ + if (!Fire_resistance) + u.uhp = (u.uhp + 2) / 3; - u.utrap -= (1 << 8); - if (u.utrap < (1 << 8)) { - killer.format = KILLED_BY; - Strcpy(killer.name, "molten lava"); - You("sink below the surface and die."); - burn_away_slime(); /* add insult to injury? */ - done(DISSOLVED); - } else if (!u.umoved) { - /* can't fully turn into slime while in lava, but might not - have it be burned away until you've come awfully close */ - if (Slimed && rnd(10 - 1) >= (int)(Slimed & TIMEOUT)) { - pline(sink_deeper); - burn_away_slime(); - } else { - Norep(sink_deeper); - } - u.utrap += rnd(4); - } + u.utrap -= (1 << 8); + if (u.utrap < (1 << 8)) { + killer.format = KILLED_BY; + Strcpy(killer.name, "molten lava"); + You("sink below the surface and die."); + burn_away_slime(); /* add insult to injury? */ + done(DISSOLVED); + } else if (!u.umoved) { + /* can't fully turn into slime while in lava, but might not + have it be burned away until you've come awfully close */ + if (Slimed && rnd(10 - 1) >= (int) (Slimed & TIMEOUT)) { + pline(sink_deeper); + burn_away_slime(); + } else { + Norep(sink_deeper); + } + u.utrap += rnd(4); + } } } @@ -4883,13 +5058,13 @@ void sokoban_guilt() { if (Sokoban) { - change_luck(-1); - /* TODO: issue some feedback so that player can learn that whatever - he/she just did is a naughty thing to do in sokoban and should - probably be avoided in future.... - Caveat: doing this might introduce message sequencing issues, - depending upon feedback during the various actions which trigger - Sokoban luck penalties. */ + change_luck(-1); + /* TODO: issue some feedback so that player can learn that whatever + he/she just did is a naughty thing to do in sokoban and should + probably be avoided in future.... + Caveat: doing this might introduce message sequencing issues, + depending upon feedback during the various actions which trigger + Sokoban luck penalties. */ } } @@ -4900,22 +5075,24 @@ maybe_finish_sokoban() struct trap *t; if (Sokoban && !in_mklev) { - /* scan all remaining traps, ignoring any created by the hero; - if this level has no more pits or holes, the current sokoban - puzzle has been solved */ - for (t = ftrap; t; t = t->ntrap) { - if (t->madeby_u) continue; - if (t->ttyp == PIT || t->ttyp == HOLE) break; - } - if (!t) { - /* we've passed the last trap without finding a pit or hole; - clear the sokoban_rules flag so that luck penalties for - things like breaking boulders or jumping will no longer - be given, and restrictions on diagonal moves are lifted */ - Sokoban = 0; /* clear level.flags.sokoban_rules */ - /* TODO: give some feedback about solving the sokoban puzzle - (perhaps say "congratulations" in Japanese?) */ - } + /* scan all remaining traps, ignoring any created by the hero; + if this level has no more pits or holes, the current sokoban + puzzle has been solved */ + for (t = ftrap; t; t = t->ntrap) { + if (t->madeby_u) + continue; + if (t->ttyp == PIT || t->ttyp == HOLE) + break; + } + if (!t) { + /* we've passed the last trap without finding a pit or hole; + clear the sokoban_rules flag so that luck penalties for + things like breaking boulders or jumping will no longer + be given, and restrictions on diagonal moves are lifted */ + Sokoban = 0; /* clear level.flags.sokoban_rules */ + /* TODO: give some feedback about solving the sokoban puzzle + (perhaps say "congratulations" in Japanese?) */ + } } } diff --git a/src/u_init.c b/src/u_init.c index 10c6a9842..598da8654 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 u_init.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 u_init.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */ /* NetHack 3.6 u_init.c $Date: 2011/10/01 00:25:56 $ $Revision: 1.18 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,321 +6,344 @@ #include "hack.h" struct trobj { - short trotyp; - schar trspe; - char trclass; - Bitfield(trquan,6); - Bitfield(trbless,2); + short trotyp; + schar trspe; + char trclass; + Bitfield(trquan, 6); + Bitfield(trbless, 2); }; STATIC_DCL void FDECL(ini_inv, (struct trobj *)); -STATIC_DCL void FDECL(knows_object,(int)); -STATIC_DCL void FDECL(knows_class,(CHAR_P)); +STATIC_DCL void FDECL(knows_object, (int)); +STATIC_DCL void FDECL(knows_class, (CHAR_P)); STATIC_DCL boolean FDECL(restricted_spell_discipline, (int)); -#define UNDEF_TYP 0 -#define UNDEF_SPE '\177' -#define UNDEF_BLESS 2 +#define UNDEF_TYP 0 +#define UNDEF_SPE '\177' +#define UNDEF_BLESS 2 /* * Initial inventory for the various roles. */ static struct trobj Archeologist[] = { - /* if adventure has a name... idea from tan@uvm-gen */ - { BULLWHIP, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, - { LEATHER_JACKET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { FEDORA, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, - { PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, - { TINNING_KIT, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, - { TOUCHSTONE, 0, GEM_CLASS, 1, 0 }, - { SACK, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } + /* if adventure has a name... idea from tan@uvm-gen */ + { BULLWHIP, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, + { LEATHER_JACKET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { FEDORA, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, + { PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, + { TINNING_KIT, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, + { TOUCHSTONE, 0, GEM_CLASS, 1, 0 }, + { SACK, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Barbarian[] = { -#define B_MAJOR 0 /* two-handed sword or battle-axe */ -#define B_MINOR 1 /* matched with axe or short sword */ - { TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { AXE, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { RING_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } +#define B_MAJOR 0 /* two-handed sword or battle-axe */ +#define B_MINOR 1 /* matched with axe or short sword */ + { TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { AXE, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { RING_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Cave_man[] = { -#define C_AMMO 2 - { CLUB, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { SLING, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, - { FLINT, 0, GEM_CLASS, 15, UNDEF_BLESS }, /* quan is variable */ - { ROCK, 0, GEM_CLASS, 3, 0 }, /* yields 18..33 */ - { LEATHER_ARMOR, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { 0, 0, 0, 0, 0 } +#define C_AMMO 2 + { CLUB, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { SLING, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, + { FLINT, 0, GEM_CLASS, 15, UNDEF_BLESS }, /* quan is variable */ + { ROCK, 0, GEM_CLASS, 3, 0 }, /* yields 18..33 */ + { LEATHER_ARMOR, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { 0, 0, 0, 0, 0 } }; static struct trobj Healer[] = { - { SCALPEL, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { LEATHER_GLOVES, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, - { STETHOSCOPE, 0, TOOL_CLASS, 1, 0 }, - { POT_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, - { POT_EXTRA_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, - { WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, - /* always blessed, so it's guaranteed readable */ - { SPE_HEALING, 0, SPBOOK_CLASS, 1, 1 }, - { SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1 }, - { SPE_STONE_TO_FLESH, 0, SPBOOK_CLASS, 1, 1 }, - { APPLE, 0, FOOD_CLASS, 5, 0 }, - { 0, 0, 0, 0, 0 } + { SCALPEL, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { LEATHER_GLOVES, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, + { STETHOSCOPE, 0, TOOL_CLASS, 1, 0 }, + { POT_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, + { POT_EXTRA_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, + { WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, + /* always blessed, so it's guaranteed readable */ + { SPE_HEALING, 0, SPBOOK_CLASS, 1, 1 }, + { SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1 }, + { SPE_STONE_TO_FLESH, 0, SPBOOK_CLASS, 1, 1 }, + { APPLE, 0, FOOD_CLASS, 5, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Knight[] = { - { LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { LANCE, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { RING_MAIL, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, - { HELMET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { LEATHER_GLOVES, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { APPLE, 0, FOOD_CLASS, 10, 0 }, - { CARROT, 0, FOOD_CLASS, 10, 0 }, - { 0, 0, 0, 0, 0 } + { LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { LANCE, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { RING_MAIL, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, + { HELMET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { LEATHER_GLOVES, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { APPLE, 0, FOOD_CLASS, 10, 0 }, + { CARROT, 0, FOOD_CLASS, 10, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Monk[] = { -#define M_BOOK 2 - { LEATHER_GLOVES, 2, ARMOR_CLASS, 1, UNDEF_BLESS }, - { ROBE, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, - { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1 }, - { UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 1, UNDEF_BLESS }, - { POT_HEALING, 0, POTION_CLASS, 3, UNDEF_BLESS }, - { FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, - { APPLE, 0, FOOD_CLASS, 5, UNDEF_BLESS }, - { ORANGE, 0, FOOD_CLASS, 5, UNDEF_BLESS }, - /* Yes, we know fortune cookies aren't really from China. They were - * invented by George Jung in Los Angeles, California, USA in 1916. - */ - { FORTUNE_COOKIE, 0, FOOD_CLASS, 3, UNDEF_BLESS }, - { 0, 0, 0, 0, 0 } +#define M_BOOK 2 + { LEATHER_GLOVES, 2, ARMOR_CLASS, 1, UNDEF_BLESS }, + { ROBE, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, + { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1 }, + { UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 1, UNDEF_BLESS }, + { POT_HEALING, 0, POTION_CLASS, 3, UNDEF_BLESS }, + { FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, + { APPLE, 0, FOOD_CLASS, 5, UNDEF_BLESS }, + { ORANGE, 0, FOOD_CLASS, 5, UNDEF_BLESS }, + /* Yes, we know fortune cookies aren't really from China. They were + * invented by George Jung in Los Angeles, California, USA in 1916. + */ + { FORTUNE_COOKIE, 0, FOOD_CLASS, 3, UNDEF_BLESS }, + { 0, 0, 0, 0, 0 } }; static struct trobj Priest[] = { - { MACE, 1, WEAPON_CLASS, 1, 1 }, - { ROBE, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { POT_WATER, 0, POTION_CLASS, 4, 1 }, /* holy water */ - { CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 0 }, - { SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 0 }, - { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, UNDEF_BLESS }, - { 0, 0, 0, 0, 0 } + { MACE, 1, WEAPON_CLASS, 1, 1 }, + { ROBE, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { POT_WATER, 0, POTION_CLASS, 4, 1 }, /* holy water */ + { CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 0 }, + { SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 0 }, + { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, UNDEF_BLESS }, + { 0, 0, 0, 0, 0 } }; static struct trobj Ranger[] = { -#define RAN_BOW 1 -#define RAN_TWO_ARROWS 2 -#define RAN_ZERO_ARROWS 3 - { DAGGER, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { BOW, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { ARROW, 2, WEAPON_CLASS, 50, UNDEF_BLESS }, - { ARROW, 0, WEAPON_CLASS, 30, UNDEF_BLESS }, - { CLOAK_OF_DISPLACEMENT, 2, ARMOR_CLASS, 1, UNDEF_BLESS }, - { CRAM_RATION, 0, FOOD_CLASS, 4, 0 }, - { 0, 0, 0, 0, 0 } +#define RAN_BOW 1 +#define RAN_TWO_ARROWS 2 +#define RAN_ZERO_ARROWS 3 + { DAGGER, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { BOW, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { ARROW, 2, WEAPON_CLASS, 50, UNDEF_BLESS }, + { ARROW, 0, WEAPON_CLASS, 30, UNDEF_BLESS }, + { CLOAK_OF_DISPLACEMENT, 2, ARMOR_CLASS, 1, UNDEF_BLESS }, + { CRAM_RATION, 0, FOOD_CLASS, 4, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Rogue[] = { -#define R_DAGGERS 1 - { SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { DAGGER, 0, WEAPON_CLASS, 10, 0 }, /* quan is variable */ - { LEATHER_ARMOR, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, - { POT_SICKNESS, 0, POTION_CLASS, 1, 0 }, - { LOCK_PICK, 9, TOOL_CLASS, 1, 0 }, - { SACK, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } +#define R_DAGGERS 1 + { SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { DAGGER, 0, WEAPON_CLASS, 10, 0 }, /* quan is variable */ + { LEATHER_ARMOR, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, + { POT_SICKNESS, 0, POTION_CLASS, 1, 0 }, + { LOCK_PICK, 9, TOOL_CLASS, 1, 0 }, + { SACK, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Samurai[] = { -#define S_ARROWS 3 - { KATANA, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, /* wakizashi */ - { YUMI, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { YA, 0, WEAPON_CLASS, 25, UNDEF_BLESS }, /* variable quan */ - { SPLINT_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { 0, 0, 0, 0, 0 } +#define S_ARROWS 3 + { KATANA, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, /* wakizashi */ + { YUMI, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { YA, 0, WEAPON_CLASS, 25, UNDEF_BLESS }, /* variable quan */ + { SPLINT_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { 0, 0, 0, 0, 0 } }; static struct trobj Tourist[] = { -#define T_DARTS 0 - { DART, 2, WEAPON_CLASS, 25, UNDEF_BLESS }, /* quan is variable */ - { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 0 }, - { POT_EXTRA_HEALING, 0, POTION_CLASS, 2, UNDEF_BLESS }, - { SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, UNDEF_BLESS }, - { HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { EXPENSIVE_CAMERA, UNDEF_SPE, TOOL_CLASS, 1, 0 }, - { CREDIT_CARD, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } +#define T_DARTS 0 + { DART, 2, WEAPON_CLASS, 25, UNDEF_BLESS }, /* quan is variable */ + { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 0 }, + { POT_EXTRA_HEALING, 0, POTION_CLASS, 2, UNDEF_BLESS }, + { SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, UNDEF_BLESS }, + { HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { EXPENSIVE_CAMERA, UNDEF_SPE, TOOL_CLASS, 1, 0 }, + { CREDIT_CARD, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Valkyrie[] = { - { LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, - { DAGGER, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, - { SMALL_SHIELD, 3, ARMOR_CLASS, 1, UNDEF_BLESS }, - { FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } + { LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, + { DAGGER, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, + { SMALL_SHIELD, 3, ARMOR_CLASS, 1, UNDEF_BLESS }, + { FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; static struct trobj Wizard[] = { -#define W_MULTSTART 2 -#define W_MULTEND 6 - { QUARTERSTAFF, 1, WEAPON_CLASS, 1, 1 }, - { CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, - { UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, - { UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, UNDEF_BLESS }, - { UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, UNDEF_BLESS }, - { UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, UNDEF_BLESS }, - { SPE_FORCE_BOLT, 0, SPBOOK_CLASS, 1, 1 }, - { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, UNDEF_BLESS }, - { 0, 0, 0, 0, 0 } +#define W_MULTSTART 2 +#define W_MULTEND 6 + { QUARTERSTAFF, 1, WEAPON_CLASS, 1, 1 }, + { CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, + { UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, + { UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, UNDEF_BLESS }, + { UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, UNDEF_BLESS }, + { UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, UNDEF_BLESS }, + { SPE_FORCE_BOLT, 0, SPBOOK_CLASS, 1, 1 }, + { UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, UNDEF_BLESS }, + { 0, 0, 0, 0, 0 } }; /* * Optional extra inventory items. */ -static struct trobj Tinopener[] = { - { TIN_OPENER, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Magicmarker[] = { - { MAGIC_MARKER, UNDEF_SPE, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Lamp[] = { - { OIL_LAMP, 1, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Blindfold[] = { - { BLINDFOLD, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Instrument[] = { - { WOODEN_FLUTE, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Xtra_food[] = { - { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 2, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Leash[] = { - { LEASH, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Towel[] = { - { TOWEL, 0, TOOL_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Wishing[] = { - { WAN_WISHING, 3, WAND_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; -static struct trobj Money[] = { - { GOLD_PIECE, 0 , COIN_CLASS, 1, 0 }, - { 0, 0, 0, 0, 0 } -}; +static struct trobj Tinopener[] = { { TIN_OPENER, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Magicmarker[] = { { MAGIC_MARKER, UNDEF_SPE, TOOL_CLASS, + 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Lamp[] = { { OIL_LAMP, 1, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Blindfold[] = { { BLINDFOLD, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Instrument[] = { { WOODEN_FLUTE, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Xtra_food[] = { { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 2, + 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Leash[] = { { LEASH, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Towel[] = { { TOWEL, 0, TOOL_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Wishing[] = { { WAN_WISHING, 3, WAND_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; +static struct trobj Money[] = { { GOLD_PIECE, 0, COIN_CLASS, 1, 0 }, + { 0, 0, 0, 0, 0 } }; /* race-based substitutions for initial inventory; the weaker cloak for elven rangers is intentional--they shoot better */ -static struct inv_sub { short race_pm, item_otyp, subs_otyp; } inv_subs[] = { - { PM_ELF, DAGGER, ELVEN_DAGGER }, - { PM_ELF, SPEAR, ELVEN_SPEAR }, - { PM_ELF, SHORT_SWORD, ELVEN_SHORT_SWORD }, - { PM_ELF, BOW, ELVEN_BOW }, - { PM_ELF, ARROW, ELVEN_ARROW }, - { PM_ELF, HELMET, ELVEN_LEATHER_HELM }, - /* { PM_ELF, SMALL_SHIELD, ELVEN_SHIELD }, */ - { PM_ELF, CLOAK_OF_DISPLACEMENT, ELVEN_CLOAK }, - { PM_ELF, CRAM_RATION, LEMBAS_WAFER }, - { PM_ORC, DAGGER, ORCISH_DAGGER }, - { PM_ORC, SPEAR, ORCISH_SPEAR }, - { PM_ORC, SHORT_SWORD, ORCISH_SHORT_SWORD }, - { PM_ORC, BOW, ORCISH_BOW }, - { PM_ORC, ARROW, ORCISH_ARROW }, - { PM_ORC, HELMET, ORCISH_HELM }, - { PM_ORC, SMALL_SHIELD, ORCISH_SHIELD }, - { PM_ORC, RING_MAIL, ORCISH_RING_MAIL }, - { PM_ORC, CHAIN_MAIL, ORCISH_CHAIN_MAIL }, - { PM_DWARF, SPEAR, DWARVISH_SPEAR }, - { PM_DWARF, SHORT_SWORD, DWARVISH_SHORT_SWORD }, - { PM_DWARF, HELMET, DWARVISH_IRON_HELM }, - /* { PM_DWARF, SMALL_SHIELD, DWARVISH_ROUNDSHIELD }, */ - /* { PM_DWARF, PICK_AXE, DWARVISH_MATTOCK }, */ - { PM_GNOME, BOW, CROSSBOW }, - { PM_GNOME, ARROW, CROSSBOW_BOLT }, - { NON_PM, STRANGE_OBJECT, STRANGE_OBJECT } +static struct inv_sub { + short race_pm, item_otyp, subs_otyp; +} inv_subs[] = { + { PM_ELF, DAGGER, ELVEN_DAGGER }, + { PM_ELF, SPEAR, ELVEN_SPEAR }, + { PM_ELF, SHORT_SWORD, ELVEN_SHORT_SWORD }, + { PM_ELF, BOW, ELVEN_BOW }, + { PM_ELF, ARROW, ELVEN_ARROW }, + { PM_ELF, HELMET, ELVEN_LEATHER_HELM }, + /* { PM_ELF, SMALL_SHIELD, ELVEN_SHIELD }, */ + { PM_ELF, CLOAK_OF_DISPLACEMENT, ELVEN_CLOAK }, + { PM_ELF, CRAM_RATION, LEMBAS_WAFER }, + { PM_ORC, DAGGER, ORCISH_DAGGER }, + { PM_ORC, SPEAR, ORCISH_SPEAR }, + { PM_ORC, SHORT_SWORD, ORCISH_SHORT_SWORD }, + { PM_ORC, BOW, ORCISH_BOW }, + { PM_ORC, ARROW, ORCISH_ARROW }, + { PM_ORC, HELMET, ORCISH_HELM }, + { PM_ORC, SMALL_SHIELD, ORCISH_SHIELD }, + { PM_ORC, RING_MAIL, ORCISH_RING_MAIL }, + { PM_ORC, CHAIN_MAIL, ORCISH_CHAIN_MAIL }, + { PM_DWARF, SPEAR, DWARVISH_SPEAR }, + { PM_DWARF, SHORT_SWORD, DWARVISH_SHORT_SWORD }, + { PM_DWARF, HELMET, DWARVISH_IRON_HELM }, + /* { PM_DWARF, SMALL_SHIELD, DWARVISH_ROUNDSHIELD }, */ + /* { PM_DWARF, PICK_AXE, DWARVISH_MATTOCK }, */ + { PM_GNOME, BOW, CROSSBOW }, + { PM_GNOME, ARROW, CROSSBOW_BOLT }, + { NON_PM, STRANGE_OBJECT, STRANGE_OBJECT } }; -static const struct def_skill Skill_A[] = { - { P_DAGGER, P_BASIC }, { P_KNIFE, P_BASIC }, - { P_PICK_AXE, P_EXPERT }, { P_SHORT_SWORD, P_BASIC }, - { P_SCIMITAR, P_SKILLED }, { P_SABER, P_EXPERT }, - { P_CLUB, P_SKILLED }, { P_QUARTERSTAFF, P_SKILLED }, - { P_SLING, P_SKILLED }, { P_DART, P_BASIC }, - { P_BOOMERANG, P_EXPERT }, { P_WHIP, P_EXPERT }, - { P_UNICORN_HORN, P_SKILLED }, - { P_ATTACK_SPELL, P_BASIC }, { P_HEALING_SPELL, P_BASIC }, - { P_DIVINATION_SPELL, P_EXPERT}, { P_MATTER_SPELL, P_BASIC}, - { P_RIDING, P_BASIC }, - { P_TWO_WEAPON_COMBAT, P_BASIC }, - { P_BARE_HANDED_COMBAT, P_EXPERT }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_A[] = { { P_DAGGER, P_BASIC }, + { P_KNIFE, P_BASIC }, + { P_PICK_AXE, P_EXPERT }, + { P_SHORT_SWORD, P_BASIC }, + { P_SCIMITAR, P_SKILLED }, + { P_SABER, P_EXPERT }, + { P_CLUB, P_SKILLED }, + { P_QUARTERSTAFF, P_SKILLED }, + { P_SLING, P_SKILLED }, + { P_DART, P_BASIC }, + { P_BOOMERANG, P_EXPERT }, + { P_WHIP, P_EXPERT }, + { P_UNICORN_HORN, P_SKILLED }, + { P_ATTACK_SPELL, P_BASIC }, + { P_HEALING_SPELL, P_BASIC }, + { P_DIVINATION_SPELL, P_EXPERT }, + { P_MATTER_SPELL, P_BASIC }, + { P_RIDING, P_BASIC }, + { P_TWO_WEAPON_COMBAT, P_BASIC }, + { P_BARE_HANDED_COMBAT, + P_EXPERT }, + { P_NONE, 0 } }; -static const struct def_skill Skill_B[] = { - { P_DAGGER, P_BASIC }, { P_AXE, P_EXPERT }, - { P_PICK_AXE, P_SKILLED }, { P_SHORT_SWORD, P_EXPERT }, - { P_BROAD_SWORD, P_SKILLED }, { P_LONG_SWORD, P_SKILLED }, - { P_TWO_HANDED_SWORD, P_EXPERT }, { P_SCIMITAR, P_SKILLED }, - { P_SABER, P_BASIC }, { P_CLUB, P_SKILLED }, - { P_MACE, P_SKILLED }, { P_MORNING_STAR, P_SKILLED }, - { P_FLAIL, P_BASIC }, { P_HAMMER, P_EXPERT }, - { P_QUARTERSTAFF, P_BASIC }, { P_SPEAR, P_SKILLED }, - { P_TRIDENT, P_SKILLED }, { P_BOW, P_BASIC }, - { P_ATTACK_SPELL, P_SKILLED }, - { P_RIDING, P_BASIC }, - { P_TWO_WEAPON_COMBAT, P_BASIC }, - { P_BARE_HANDED_COMBAT, P_MASTER }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_B[] = { { P_DAGGER, P_BASIC }, + { P_AXE, P_EXPERT }, + { P_PICK_AXE, P_SKILLED }, + { P_SHORT_SWORD, P_EXPERT }, + { P_BROAD_SWORD, P_SKILLED }, + { P_LONG_SWORD, P_SKILLED }, + { P_TWO_HANDED_SWORD, P_EXPERT }, + { P_SCIMITAR, P_SKILLED }, + { P_SABER, P_BASIC }, + { P_CLUB, P_SKILLED }, + { P_MACE, P_SKILLED }, + { P_MORNING_STAR, P_SKILLED }, + { P_FLAIL, P_BASIC }, + { P_HAMMER, P_EXPERT }, + { P_QUARTERSTAFF, P_BASIC }, + { P_SPEAR, P_SKILLED }, + { P_TRIDENT, P_SKILLED }, + { P_BOW, P_BASIC }, + { P_ATTACK_SPELL, P_SKILLED }, + { P_RIDING, P_BASIC }, + { P_TWO_WEAPON_COMBAT, P_BASIC }, + { P_BARE_HANDED_COMBAT, + P_MASTER }, + { P_NONE, 0 } }; -static const struct def_skill Skill_C[] = { - { P_DAGGER, P_BASIC }, { P_KNIFE, P_SKILLED }, - { P_AXE, P_SKILLED }, { P_PICK_AXE, P_BASIC }, - { P_CLUB, P_EXPERT }, { P_MACE, P_EXPERT }, - { P_MORNING_STAR, P_BASIC }, { P_FLAIL, P_SKILLED }, - { P_HAMMER, P_SKILLED }, { P_QUARTERSTAFF, P_EXPERT }, - { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_EXPERT }, - { P_TRIDENT, P_SKILLED }, - { P_BOW, P_SKILLED }, { P_SLING, P_EXPERT }, - { P_ATTACK_SPELL, P_BASIC }, { P_MATTER_SPELL, P_SKILLED }, - { P_BOOMERANG, P_EXPERT }, { P_UNICORN_HORN, P_BASIC }, - { P_BARE_HANDED_COMBAT, P_MASTER }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_C[] = { { P_DAGGER, P_BASIC }, + { P_KNIFE, P_SKILLED }, + { P_AXE, P_SKILLED }, + { P_PICK_AXE, P_BASIC }, + { P_CLUB, P_EXPERT }, + { P_MACE, P_EXPERT }, + { P_MORNING_STAR, P_BASIC }, + { P_FLAIL, P_SKILLED }, + { P_HAMMER, P_SKILLED }, + { P_QUARTERSTAFF, P_EXPERT }, + { P_POLEARMS, P_SKILLED }, + { P_SPEAR, P_EXPERT }, + { P_TRIDENT, P_SKILLED }, + { P_BOW, P_SKILLED }, + { P_SLING, P_EXPERT }, + { P_ATTACK_SPELL, P_BASIC }, + { P_MATTER_SPELL, P_SKILLED }, + { P_BOOMERANG, P_EXPERT }, + { P_UNICORN_HORN, P_BASIC }, + { P_BARE_HANDED_COMBAT, + P_MASTER }, + { P_NONE, 0 } }; -static const struct def_skill Skill_H[] = { - { P_DAGGER, P_SKILLED }, { P_KNIFE, P_EXPERT }, - { P_SHORT_SWORD, P_SKILLED }, { P_SCIMITAR, P_BASIC }, - { P_SABER, P_BASIC }, { P_CLUB, P_SKILLED }, - { P_MACE, P_BASIC }, { P_QUARTERSTAFF, P_EXPERT }, - { P_POLEARMS, P_BASIC }, { P_SPEAR, P_BASIC }, - { P_TRIDENT, P_BASIC }, - { P_SLING, P_SKILLED }, { P_DART, P_EXPERT }, - { P_SHURIKEN, P_SKILLED }, { P_UNICORN_HORN, P_EXPERT }, - { P_HEALING_SPELL, P_EXPERT }, - { P_BARE_HANDED_COMBAT, P_BASIC }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_H[] = { { P_DAGGER, P_SKILLED }, + { P_KNIFE, P_EXPERT }, + { P_SHORT_SWORD, P_SKILLED }, + { P_SCIMITAR, P_BASIC }, + { P_SABER, P_BASIC }, + { P_CLUB, P_SKILLED }, + { P_MACE, P_BASIC }, + { P_QUARTERSTAFF, P_EXPERT }, + { P_POLEARMS, P_BASIC }, + { P_SPEAR, P_BASIC }, + { P_TRIDENT, P_BASIC }, + { P_SLING, P_SKILLED }, + { P_DART, P_EXPERT }, + { P_SHURIKEN, P_SKILLED }, + { P_UNICORN_HORN, P_EXPERT }, + { P_HEALING_SPELL, P_EXPERT }, + { P_BARE_HANDED_COMBAT, P_BASIC }, + { P_NONE, 0 } }; static const struct def_skill Skill_K[] = { - { P_DAGGER, P_BASIC }, { P_KNIFE, P_BASIC }, - { P_AXE, P_SKILLED }, { P_PICK_AXE, P_BASIC }, - { P_SHORT_SWORD, P_SKILLED }, { P_BROAD_SWORD, P_SKILLED }, - { P_LONG_SWORD, P_EXPERT }, { P_TWO_HANDED_SWORD, P_SKILLED }, - { P_SCIMITAR, P_BASIC }, { P_SABER, P_SKILLED }, - { P_CLUB, P_BASIC }, { P_MACE, P_SKILLED }, - { P_MORNING_STAR, P_SKILLED }, { P_FLAIL, P_BASIC }, - { P_HAMMER, P_BASIC }, { P_POLEARMS, P_SKILLED }, + { P_DAGGER, P_BASIC }, + { P_KNIFE, P_BASIC }, + { P_AXE, P_SKILLED }, + { P_PICK_AXE, P_BASIC }, + { P_SHORT_SWORD, P_SKILLED }, + { P_BROAD_SWORD, P_SKILLED }, + { P_LONG_SWORD, P_EXPERT }, + { P_TWO_HANDED_SWORD, P_SKILLED }, + { P_SCIMITAR, P_BASIC }, + { P_SABER, P_SKILLED }, + { P_CLUB, P_BASIC }, + { P_MACE, P_SKILLED }, + { P_MORNING_STAR, P_SKILLED }, + { P_FLAIL, P_BASIC }, + { P_HAMMER, P_BASIC }, + { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_SKILLED }, - { P_TRIDENT, P_BASIC }, { P_LANCE, P_EXPERT }, - { P_BOW, P_BASIC }, { P_CROSSBOW, P_SKILLED }, - { P_ATTACK_SPELL, P_SKILLED }, { P_HEALING_SPELL, P_SKILLED }, + { P_TRIDENT, P_BASIC }, + { P_LANCE, P_EXPERT }, + { P_BOW, P_BASIC }, + { P_CROSSBOW, P_SKILLED }, + { P_ATTACK_SPELL, P_SKILLED }, + { P_HEALING_SPELL, P_SKILLED }, { P_CLERIC_SPELL, P_SKILLED }, { P_RIDING, P_EXPERT }, { P_TWO_WEAPON_COMBAT, P_SKILLED }, @@ -329,61 +352,91 @@ static const struct def_skill Skill_K[] = { }; static const struct def_skill Skill_Mon[] = { - { P_QUARTERSTAFF, P_BASIC }, { P_SPEAR, P_BASIC }, - { P_CROSSBOW, P_BASIC }, { P_SHURIKEN, P_BASIC }, - { P_ATTACK_SPELL, P_BASIC }, { P_HEALING_SPELL, P_EXPERT }, - { P_DIVINATION_SPELL, P_BASIC },{ P_ENCHANTMENT_SPELL, P_BASIC }, - { P_CLERIC_SPELL, P_SKILLED }, { P_ESCAPE_SPELL, P_SKILLED }, + { P_QUARTERSTAFF, P_BASIC }, + { P_SPEAR, P_BASIC }, + { P_CROSSBOW, P_BASIC }, + { P_SHURIKEN, P_BASIC }, + { P_ATTACK_SPELL, P_BASIC }, + { P_HEALING_SPELL, P_EXPERT }, + { P_DIVINATION_SPELL, P_BASIC }, + { P_ENCHANTMENT_SPELL, P_BASIC }, + { P_CLERIC_SPELL, P_SKILLED }, + { P_ESCAPE_SPELL, P_SKILLED }, { P_MATTER_SPELL, P_BASIC }, { P_MARTIAL_ARTS, P_GRAND_MASTER }, { P_NONE, 0 } }; -static const struct def_skill Skill_P[] = { - { P_CLUB, P_EXPERT }, { P_MACE, P_EXPERT }, - { P_MORNING_STAR, P_EXPERT }, { P_FLAIL, P_EXPERT }, - { P_HAMMER, P_EXPERT }, { P_QUARTERSTAFF, P_EXPERT }, - { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_SKILLED }, - { P_TRIDENT, P_SKILLED }, - { P_LANCE, P_BASIC }, { P_BOW, P_BASIC }, - { P_SLING, P_BASIC }, { P_CROSSBOW, P_BASIC }, - { P_DART, P_BASIC }, { P_SHURIKEN, P_BASIC }, - { P_BOOMERANG, P_BASIC }, { P_UNICORN_HORN, P_SKILLED }, - { P_HEALING_SPELL, P_EXPERT }, { P_DIVINATION_SPELL, P_EXPERT }, - { P_CLERIC_SPELL, P_EXPERT }, - { P_BARE_HANDED_COMBAT, P_BASIC }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_P[] = { { P_CLUB, P_EXPERT }, + { P_MACE, P_EXPERT }, + { P_MORNING_STAR, P_EXPERT }, + { P_FLAIL, P_EXPERT }, + { P_HAMMER, P_EXPERT }, + { P_QUARTERSTAFF, P_EXPERT }, + { P_POLEARMS, P_SKILLED }, + { P_SPEAR, P_SKILLED }, + { P_TRIDENT, P_SKILLED }, + { P_LANCE, P_BASIC }, + { P_BOW, P_BASIC }, + { P_SLING, P_BASIC }, + { P_CROSSBOW, P_BASIC }, + { P_DART, P_BASIC }, + { P_SHURIKEN, P_BASIC }, + { P_BOOMERANG, P_BASIC }, + { P_UNICORN_HORN, P_SKILLED }, + { P_HEALING_SPELL, P_EXPERT }, + { P_DIVINATION_SPELL, P_EXPERT }, + { P_CLERIC_SPELL, P_EXPERT }, + { P_BARE_HANDED_COMBAT, P_BASIC }, + { P_NONE, 0 } }; -static const struct def_skill Skill_R[] = { - { P_DAGGER, P_EXPERT }, { P_KNIFE, P_EXPERT }, - { P_SHORT_SWORD, P_EXPERT }, { P_BROAD_SWORD, P_SKILLED }, - { P_LONG_SWORD, P_SKILLED }, { P_TWO_HANDED_SWORD, P_BASIC }, - { P_SCIMITAR, P_SKILLED }, { P_SABER, P_SKILLED }, - { P_CLUB, P_SKILLED }, { P_MACE, P_SKILLED }, - { P_MORNING_STAR, P_BASIC }, { P_FLAIL, P_BASIC }, - { P_HAMMER, P_BASIC }, { P_POLEARMS, P_BASIC }, - { P_SPEAR, P_BASIC }, { P_CROSSBOW, P_EXPERT }, - { P_DART, P_EXPERT }, { P_SHURIKEN, P_SKILLED }, - { P_DIVINATION_SPELL, P_SKILLED }, { P_ESCAPE_SPELL, P_SKILLED }, - { P_MATTER_SPELL, P_SKILLED }, - { P_RIDING, P_BASIC }, - { P_TWO_WEAPON_COMBAT, P_EXPERT }, - { P_BARE_HANDED_COMBAT, P_EXPERT }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_R[] = { { P_DAGGER, P_EXPERT }, + { P_KNIFE, P_EXPERT }, + { P_SHORT_SWORD, P_EXPERT }, + { P_BROAD_SWORD, P_SKILLED }, + { P_LONG_SWORD, P_SKILLED }, + { P_TWO_HANDED_SWORD, P_BASIC }, + { P_SCIMITAR, P_SKILLED }, + { P_SABER, P_SKILLED }, + { P_CLUB, P_SKILLED }, + { P_MACE, P_SKILLED }, + { P_MORNING_STAR, P_BASIC }, + { P_FLAIL, P_BASIC }, + { P_HAMMER, P_BASIC }, + { P_POLEARMS, P_BASIC }, + { P_SPEAR, P_BASIC }, + { P_CROSSBOW, P_EXPERT }, + { P_DART, P_EXPERT }, + { P_SHURIKEN, P_SKILLED }, + { P_DIVINATION_SPELL, P_SKILLED }, + { P_ESCAPE_SPELL, P_SKILLED }, + { P_MATTER_SPELL, P_SKILLED }, + { P_RIDING, P_BASIC }, + { P_TWO_WEAPON_COMBAT, P_EXPERT }, + { P_BARE_HANDED_COMBAT, + P_EXPERT }, + { P_NONE, 0 } }; static const struct def_skill Skill_Ran[] = { - { P_DAGGER, P_EXPERT }, { P_KNIFE, P_SKILLED }, - { P_AXE, P_SKILLED }, { P_PICK_AXE, P_BASIC }, - { P_SHORT_SWORD, P_BASIC }, { P_MORNING_STAR, P_BASIC }, - { P_FLAIL, P_SKILLED }, { P_HAMMER, P_BASIC }, - { P_QUARTERSTAFF, P_BASIC }, { P_POLEARMS, P_SKILLED }, + { P_DAGGER, P_EXPERT }, + { P_KNIFE, P_SKILLED }, + { P_AXE, P_SKILLED }, + { P_PICK_AXE, P_BASIC }, + { P_SHORT_SWORD, P_BASIC }, + { P_MORNING_STAR, P_BASIC }, + { P_FLAIL, P_SKILLED }, + { P_HAMMER, P_BASIC }, + { P_QUARTERSTAFF, P_BASIC }, + { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_EXPERT }, - { P_TRIDENT, P_BASIC }, { P_BOW, P_EXPERT }, - { P_SLING, P_EXPERT }, { P_CROSSBOW, P_EXPERT }, - { P_DART, P_EXPERT }, { P_SHURIKEN, P_SKILLED }, - { P_BOOMERANG, P_EXPERT }, { P_WHIP, P_BASIC }, + { P_TRIDENT, P_BASIC }, + { P_BOW, P_EXPERT }, + { P_SLING, P_EXPERT }, + { P_CROSSBOW, P_EXPERT }, + { P_DART, P_EXPERT }, + { P_SHURIKEN, P_SKILLED }, + { P_BOOMERANG, P_EXPERT }, + { P_WHIP, P_BASIC }, { P_HEALING_SPELL, P_BASIC }, { P_DIVINATION_SPELL, P_EXPERT }, { P_ESCAPE_SPELL, P_BASIC }, @@ -392,38 +445,58 @@ static const struct def_skill Skill_Ran[] = { { P_NONE, 0 } }; -static const struct def_skill Skill_S[] = { - { P_DAGGER, P_BASIC }, { P_KNIFE, P_SKILLED }, - { P_SHORT_SWORD, P_EXPERT }, { P_BROAD_SWORD, P_SKILLED }, - { P_LONG_SWORD, P_EXPERT }, { P_TWO_HANDED_SWORD, P_EXPERT }, - { P_SCIMITAR, P_BASIC }, { P_SABER, P_BASIC }, - { P_FLAIL, P_SKILLED }, { P_QUARTERSTAFF, P_BASIC }, - { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_SKILLED }, - { P_LANCE, P_SKILLED }, - { P_BOW, P_EXPERT }, { P_SHURIKEN, P_EXPERT }, - { P_ATTACK_SPELL, P_SKILLED }, { P_CLERIC_SPELL, P_SKILLED }, - { P_RIDING, P_SKILLED }, - { P_TWO_WEAPON_COMBAT, P_EXPERT }, - { P_MARTIAL_ARTS, P_MASTER }, - { P_NONE, 0 } -}; +static const struct def_skill Skill_S[] = { { P_DAGGER, P_BASIC }, + { P_KNIFE, P_SKILLED }, + { P_SHORT_SWORD, P_EXPERT }, + { P_BROAD_SWORD, P_SKILLED }, + { P_LONG_SWORD, P_EXPERT }, + { P_TWO_HANDED_SWORD, P_EXPERT }, + { P_SCIMITAR, P_BASIC }, + { P_SABER, P_BASIC }, + { P_FLAIL, P_SKILLED }, + { P_QUARTERSTAFF, P_BASIC }, + { P_POLEARMS, P_SKILLED }, + { P_SPEAR, P_SKILLED }, + { P_LANCE, P_SKILLED }, + { P_BOW, P_EXPERT }, + { P_SHURIKEN, P_EXPERT }, + { P_ATTACK_SPELL, P_SKILLED }, + { P_CLERIC_SPELL, P_SKILLED }, + { P_RIDING, P_SKILLED }, + { P_TWO_WEAPON_COMBAT, P_EXPERT }, + { P_MARTIAL_ARTS, P_MASTER }, + { P_NONE, 0 } }; static const struct def_skill Skill_T[] = { - { P_DAGGER, P_EXPERT }, { P_KNIFE, P_SKILLED }, - { P_AXE, P_BASIC }, { P_PICK_AXE, P_BASIC }, - { P_SHORT_SWORD, P_EXPERT }, { P_BROAD_SWORD, P_BASIC }, - { P_LONG_SWORD, P_BASIC }, { P_TWO_HANDED_SWORD, P_BASIC }, - { P_SCIMITAR, P_SKILLED }, { P_SABER, P_SKILLED }, - { P_MACE, P_BASIC }, { P_MORNING_STAR, P_BASIC }, - { P_FLAIL, P_BASIC }, { P_HAMMER, P_BASIC }, - { P_QUARTERSTAFF, P_BASIC }, { P_POLEARMS, P_BASIC }, + { P_DAGGER, P_EXPERT }, + { P_KNIFE, P_SKILLED }, + { P_AXE, P_BASIC }, + { P_PICK_AXE, P_BASIC }, + { P_SHORT_SWORD, P_EXPERT }, + { P_BROAD_SWORD, P_BASIC }, + { P_LONG_SWORD, P_BASIC }, + { P_TWO_HANDED_SWORD, P_BASIC }, + { P_SCIMITAR, P_SKILLED }, + { P_SABER, P_SKILLED }, + { P_MACE, P_BASIC }, + { P_MORNING_STAR, P_BASIC }, + { P_FLAIL, P_BASIC }, + { P_HAMMER, P_BASIC }, + { P_QUARTERSTAFF, P_BASIC }, + { P_POLEARMS, P_BASIC }, { P_SPEAR, P_BASIC }, - { P_TRIDENT, P_BASIC }, { P_LANCE, P_BASIC }, - { P_BOW, P_BASIC }, { P_SLING, P_BASIC }, - { P_CROSSBOW, P_BASIC }, { P_DART, P_EXPERT }, - { P_SHURIKEN, P_BASIC }, { P_BOOMERANG, P_BASIC }, - { P_WHIP, P_BASIC }, { P_UNICORN_HORN, P_SKILLED }, - { P_DIVINATION_SPELL, P_BASIC }, { P_ENCHANTMENT_SPELL, P_BASIC }, + { P_TRIDENT, P_BASIC }, + { P_LANCE, P_BASIC }, + { P_BOW, P_BASIC }, + { P_SLING, P_BASIC }, + { P_CROSSBOW, P_BASIC }, + { P_DART, P_EXPERT }, + { P_SHURIKEN, P_BASIC }, + { P_BOOMERANG, P_BASIC }, + { P_WHIP, P_BASIC }, + { P_UNICORN_HORN, P_SKILLED }, + { P_DIVINATION_SPELL, P_BASIC }, + { P_ENCHANTMENT_SPELL, P_BASIC }, { P_ESCAPE_SPELL, P_SKILLED }, { P_RIDING, P_BASIC }, { P_TWO_WEAPON_COMBAT, P_SKILLED }, @@ -432,46 +505,61 @@ static const struct def_skill Skill_T[] = { }; static const struct def_skill Skill_V[] = { - { P_DAGGER, P_EXPERT }, { P_AXE, P_EXPERT }, - { P_PICK_AXE, P_SKILLED }, { P_SHORT_SWORD, P_SKILLED }, - { P_BROAD_SWORD, P_SKILLED }, { P_LONG_SWORD, P_EXPERT }, - { P_TWO_HANDED_SWORD, P_EXPERT }, { P_SCIMITAR, P_BASIC }, - { P_SABER, P_BASIC }, { P_HAMMER, P_EXPERT }, - { P_QUARTERSTAFF, P_BASIC }, { P_POLEARMS, P_SKILLED }, + { P_DAGGER, P_EXPERT }, + { P_AXE, P_EXPERT }, + { P_PICK_AXE, P_SKILLED }, + { P_SHORT_SWORD, P_SKILLED }, + { P_BROAD_SWORD, P_SKILLED }, + { P_LONG_SWORD, P_EXPERT }, + { P_TWO_HANDED_SWORD, P_EXPERT }, + { P_SCIMITAR, P_BASIC }, + { P_SABER, P_BASIC }, + { P_HAMMER, P_EXPERT }, + { P_QUARTERSTAFF, P_BASIC }, + { P_POLEARMS, P_SKILLED }, { P_SPEAR, P_SKILLED }, - { P_TRIDENT, P_BASIC }, { P_LANCE, P_SKILLED }, + { P_TRIDENT, P_BASIC }, + { P_LANCE, P_SKILLED }, { P_SLING, P_BASIC }, - { P_ATTACK_SPELL, P_BASIC }, { P_ESCAPE_SPELL, P_BASIC }, + { P_ATTACK_SPELL, P_BASIC }, + { P_ESCAPE_SPELL, P_BASIC }, { P_RIDING, P_SKILLED }, { P_TWO_WEAPON_COMBAT, P_SKILLED }, { P_BARE_HANDED_COMBAT, P_EXPERT }, { P_NONE, 0 } }; -static const struct def_skill Skill_W[] = { - { P_DAGGER, P_EXPERT }, { P_KNIFE, P_SKILLED }, - { P_AXE, P_SKILLED }, { P_SHORT_SWORD, P_BASIC }, - { P_CLUB, P_SKILLED }, { P_MACE, P_BASIC }, - { P_QUARTERSTAFF, P_EXPERT }, { P_POLEARMS, P_SKILLED }, - { P_SPEAR, P_BASIC }, - { P_TRIDENT, P_BASIC }, { P_SLING, P_SKILLED }, - { P_DART, P_EXPERT }, { P_SHURIKEN, P_BASIC }, - { P_ATTACK_SPELL, P_EXPERT }, { P_HEALING_SPELL, P_SKILLED }, - { P_DIVINATION_SPELL, P_EXPERT }, { P_ENCHANTMENT_SPELL, P_SKILLED }, - { P_CLERIC_SPELL, P_SKILLED }, { P_ESCAPE_SPELL, P_EXPERT }, - { P_MATTER_SPELL, P_EXPERT }, - { P_RIDING, P_BASIC }, - { P_BARE_HANDED_COMBAT, P_BASIC }, - { P_NONE, 0 } -}; - +static const struct def_skill Skill_W[] = { { P_DAGGER, P_EXPERT }, + { P_KNIFE, P_SKILLED }, + { P_AXE, P_SKILLED }, + { P_SHORT_SWORD, P_BASIC }, + { P_CLUB, P_SKILLED }, + { P_MACE, P_BASIC }, + { P_QUARTERSTAFF, P_EXPERT }, + { P_POLEARMS, P_SKILLED }, + { P_SPEAR, P_BASIC }, + { P_TRIDENT, P_BASIC }, + { P_SLING, P_SKILLED }, + { P_DART, P_EXPERT }, + { P_SHURIKEN, P_BASIC }, + { P_ATTACK_SPELL, P_EXPERT }, + { P_HEALING_SPELL, P_SKILLED }, + { P_DIVINATION_SPELL, P_EXPERT }, + { P_ENCHANTMENT_SPELL, + P_SKILLED }, + { P_CLERIC_SPELL, P_SKILLED }, + { P_ESCAPE_SPELL, P_EXPERT }, + { P_MATTER_SPELL, P_EXPERT }, + { P_RIDING, P_BASIC }, + { P_BARE_HANDED_COMBAT, P_BASIC }, + { P_NONE, 0 } }; STATIC_OVL void knows_object(obj) register int obj; { - discover_object(obj,TRUE,FALSE); - objects[obj].oc_pre_discovered = 1; /* not a "discovery" */ + discover_object(obj, TRUE, FALSE); + objects[obj].oc_pre_discovered = 1; /* not a "discovery" */ } /* Know ordinary (non-magical) objects of a certain class, @@ -481,31 +569,32 @@ STATIC_OVL void knows_class(sym) register char sym; { - register int ct; - for (ct = 1; ct < NUM_OBJECTS; ct++) - if (objects[ct].oc_class == sym && !objects[ct].oc_magic) - knows_object(ct); + register int ct; + for (ct = 1; ct < NUM_OBJECTS; ct++) + if (objects[ct].oc_class == sym && !objects[ct].oc_magic) + knows_object(ct); } void u_init() { - register int i; - struct u_roleplay tmpuroleplay = u.uroleplay; /* these set by rcfile options */ + register int i; + struct u_roleplay tmpuroleplay = + u.uroleplay; /* these set by rcfile options */ - flags.female = flags.initgend; - flags.beginner = 1; + flags.female = flags.initgend; + flags.beginner = 1; - /* zero u, including pointer values -- - * necessary when aborting from a failed restore */ - (void) memset((genericptr_t)&u, 0, sizeof(u)); - u.ustuck = (struct monst *)0; - (void) memset((genericptr_t)&ubirthday, 0, sizeof(ubirthday)); - (void) memset((genericptr_t)&urealtime, 0, sizeof(urealtime)); + /* zero u, including pointer values -- + * necessary when aborting from a failed restore */ + (void) memset((genericptr_t) &u, 0, sizeof(u)); + u.ustuck = (struct monst *) 0; + (void) memset((genericptr_t) &ubirthday, 0, sizeof(ubirthday)); + (void) memset((genericptr_t) &urealtime, 0, sizeof(urealtime)); - u.uroleplay = tmpuroleplay; /* restore options set via rcfile */ + u.uroleplay = tmpuroleplay; /* restore options set via rcfile */ -#if 0 /* documentation of more zero values as desirable */ +#if 0 /* documentation of more zero values as desirable */ u.usick_cause[0] = 0; u.uluck = u.moreluck = 0; uarmu = 0; @@ -524,275 +613,300 @@ u_init() u.mh = u.mhmax = u.mtimedone = 0; u.uz.dnum = u.uz0.dnum = 0; u.utotype = 0; -#endif /* 0 */ +#endif /* 0 */ - u.uz.dlevel = 1; - u.uz0.dlevel = 0; - u.utolev = u.uz; + u.uz.dlevel = 1; + u.uz0.dlevel = 0; + u.utolev = u.uz; - u.umoved = FALSE; - u.umortality = 0; - u.ugrave_arise = NON_PM; + u.umoved = FALSE; + u.umortality = 0; + u.ugrave_arise = NON_PM; - u.umonnum = u.umonster = (flags.female && - urole.femalenum != NON_PM) ? urole.femalenum : - urole.malenum; - u.ulycn = NON_PM; - set_uasmon(); + u.umonnum = u.umonster = (flags.female && urole.femalenum != NON_PM) + ? urole.femalenum + : urole.malenum; + u.ulycn = NON_PM; + set_uasmon(); - u.ulevel = 0; /* set up some of the initial attributes */ - u.uhp = u.uhpmax = newhp(); - u.uen = u.uenmax = newpw(); - u.uspellprot = 0; - adjabil(0,1); - u.ulevel = u.ulevelmax = 1; + u.ulevel = 0; /* set up some of the initial attributes */ + u.uhp = u.uhpmax = newhp(); + u.uen = u.uenmax = newpw(); + u.uspellprot = 0; + adjabil(0, 1); + u.ulevel = u.ulevelmax = 1; - init_uhunger(); - for (i = 0; i <= MAXSPELL; i++) spl_book[i].sp_id = NO_SPELL; - u.ublesscnt = 300; /* no prayers just yet */ - u.ualignbase[A_CURRENT] = u.ualignbase[A_ORIGINAL] = u.ualign.type = - aligns[flags.initalign].value; + init_uhunger(); + for (i = 0; i <= MAXSPELL; i++) + spl_book[i].sp_id = NO_SPELL; + u.ublesscnt = 300; /* no prayers just yet */ + u.ualignbase[A_CURRENT] = u.ualignbase[A_ORIGINAL] = u.ualign.type = + aligns[flags.initalign].value; #if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *)&ubirthday); + (void) time((long *) &ubirthday); #else - (void) time(&ubirthday); + (void) time(&ubirthday); #endif - /* - * For now, everyone starts out with a night vision range of 1 and - * their xray range disabled. - */ - u.nv_range = 1; - u.xray_range = -1; + /* + * For now, everyone starts out with a night vision range of 1 and + * their xray range disabled. + */ + u.nv_range = 1; + u.xray_range = -1; + /*** Role-specific initializations ***/ + switch (Role_switch) { + /* rn2(100) > 50 necessary for some choices because some + * random number generators are bad enough to seriously + * skew the results if we use rn2(2)... --KAA + */ + case PM_ARCHEOLOGIST: + ini_inv(Archeologist); + if (!rn2(10)) + ini_inv(Tinopener); + else if (!rn2(4)) + ini_inv(Lamp); + else if (!rn2(10)) + ini_inv(Magicmarker); + knows_object(SACK); + knows_object(TOUCHSTONE); + skill_init(Skill_A); + break; + case PM_BARBARIAN: + if (rn2(100) >= 50) { /* see above comment */ + Barbarian[B_MAJOR].trotyp = BATTLE_AXE; + Barbarian[B_MINOR].trotyp = SHORT_SWORD; + } + ini_inv(Barbarian); + if (!rn2(6)) + ini_inv(Lamp); + knows_class(WEAPON_CLASS); + knows_class(ARMOR_CLASS); + skill_init(Skill_B); + break; + case PM_CAVEMAN: + Cave_man[C_AMMO].trquan = rn1(11, 10); /* 10..20 */ + ini_inv(Cave_man); + skill_init(Skill_C); + break; + case PM_HEALER: + u.umoney0 = rn1(1000, 1001); + ini_inv(Healer); + if (!rn2(25)) + ini_inv(Lamp); + knows_object(POT_FULL_HEALING); + skill_init(Skill_H); + break; + case PM_KNIGHT: + ini_inv(Knight); + knows_class(WEAPON_CLASS); + knows_class(ARMOR_CLASS); + /* give knights chess-like mobility + * -- idea from wooledge@skybridge.scl.cwru.edu */ + HJumping |= FROMOUTSIDE; + skill_init(Skill_K); + break; + case PM_MONK: + switch (rn2(90) / 30) { + case 0: + Monk[M_BOOK].trotyp = SPE_HEALING; + break; + case 1: + Monk[M_BOOK].trotyp = SPE_PROTECTION; + break; + case 2: + Monk[M_BOOK].trotyp = SPE_SLEEP; + break; + } + ini_inv(Monk); + if (!rn2(5)) + ini_inv(Magicmarker); + else if (!rn2(10)) + ini_inv(Lamp); + knows_class(ARMOR_CLASS); + skill_init(Skill_Mon); + break; + case PM_PRIEST: + ini_inv(Priest); + if (!rn2(10)) + ini_inv(Magicmarker); + else if (!rn2(10)) + ini_inv(Lamp); + knows_object(POT_WATER); + skill_init(Skill_P); + /* KMH, conduct -- + * Some may claim that this isn't agnostic, since they + * are literally "priests" and they have holy water. + * But we don't count it as such. Purists can always + * avoid playing priests and/or confirm another player's + * role in their YAAP. + */ + break; + case PM_RANGER: + Ranger[RAN_TWO_ARROWS].trquan = rn1(10, 50); + Ranger[RAN_ZERO_ARROWS].trquan = rn1(10, 30); + ini_inv(Ranger); + skill_init(Skill_Ran); + break; + case PM_ROGUE: + Rogue[R_DAGGERS].trquan = rn1(10, 6); + u.umoney0 = 0; + ini_inv(Rogue); + if (!rn2(5)) + ini_inv(Blindfold); + knows_object(SACK); + skill_init(Skill_R); + break; + case PM_SAMURAI: + Samurai[S_ARROWS].trquan = rn1(20, 26); + ini_inv(Samurai); + if (!rn2(5)) + ini_inv(Blindfold); + knows_class(WEAPON_CLASS); + knows_class(ARMOR_CLASS); + skill_init(Skill_S); + break; + case PM_TOURIST: + Tourist[T_DARTS].trquan = rn1(20, 21); + u.umoney0 = rnd(1000); + ini_inv(Tourist); + if (!rn2(25)) + ini_inv(Tinopener); + else if (!rn2(25)) + ini_inv(Leash); + else if (!rn2(25)) + ini_inv(Towel); + else if (!rn2(25)) + ini_inv(Magicmarker); + skill_init(Skill_T); + break; + case PM_VALKYRIE: + ini_inv(Valkyrie); + if (!rn2(6)) + ini_inv(Lamp); + knows_class(WEAPON_CLASS); + knows_class(ARMOR_CLASS); + skill_init(Skill_V); + break; + case PM_WIZARD: + ini_inv(Wizard); + if (!rn2(5)) + ini_inv(Magicmarker); + if (!rn2(5)) + ini_inv(Blindfold); + skill_init(Skill_W); + break; - /*** Role-specific initializations ***/ - switch (Role_switch) { - /* rn2(100) > 50 necessary for some choices because some - * random number generators are bad enough to seriously - * skew the results if we use rn2(2)... --KAA - */ - case PM_ARCHEOLOGIST: - ini_inv(Archeologist); - if(!rn2(10)) ini_inv(Tinopener); - else if(!rn2(4)) ini_inv(Lamp); - else if(!rn2(10)) ini_inv(Magicmarker); - knows_object(SACK); - knows_object(TOUCHSTONE); - skill_init(Skill_A); - break; - case PM_BARBARIAN: - if (rn2(100) >= 50) { /* see above comment */ - Barbarian[B_MAJOR].trotyp = BATTLE_AXE; - Barbarian[B_MINOR].trotyp = SHORT_SWORD; - } - ini_inv(Barbarian); - if(!rn2(6)) ini_inv(Lamp); - knows_class(WEAPON_CLASS); - knows_class(ARMOR_CLASS); - skill_init(Skill_B); - break; - case PM_CAVEMAN: - Cave_man[C_AMMO].trquan = rn1(11, 10); /* 10..20 */ - ini_inv(Cave_man); - skill_init(Skill_C); - break; - case PM_HEALER: - u.umoney0 = rn1(1000, 1001); - ini_inv(Healer); - if(!rn2(25)) ini_inv(Lamp); - knows_object(POT_FULL_HEALING); - skill_init(Skill_H); - break; - case PM_KNIGHT: - ini_inv(Knight); - knows_class(WEAPON_CLASS); - knows_class(ARMOR_CLASS); - /* give knights chess-like mobility - * -- idea from wooledge@skybridge.scl.cwru.edu */ - HJumping |= FROMOUTSIDE; - skill_init(Skill_K); - break; - case PM_MONK: - switch (rn2(90) / 30) { - case 0: Monk[M_BOOK].trotyp = SPE_HEALING; break; - case 1: Monk[M_BOOK].trotyp = SPE_PROTECTION; break; - case 2: Monk[M_BOOK].trotyp = SPE_SLEEP; break; - } - ini_inv(Monk); - if(!rn2(5)) ini_inv(Magicmarker); - else if(!rn2(10)) ini_inv(Lamp); - knows_class(ARMOR_CLASS); - skill_init(Skill_Mon); - break; - case PM_PRIEST: - ini_inv(Priest); - if(!rn2(10)) ini_inv(Magicmarker); - else if(!rn2(10)) ini_inv(Lamp); - knows_object(POT_WATER); - skill_init(Skill_P); - /* KMH, conduct -- - * Some may claim that this isn't agnostic, since they - * are literally "priests" and they have holy water. - * But we don't count it as such. Purists can always - * avoid playing priests and/or confirm another player's - * role in their YAAP. - */ - break; - case PM_RANGER: - Ranger[RAN_TWO_ARROWS].trquan = rn1(10, 50); - Ranger[RAN_ZERO_ARROWS].trquan = rn1(10, 30); - ini_inv(Ranger); - skill_init(Skill_Ran); - break; - case PM_ROGUE: - Rogue[R_DAGGERS].trquan = rn1(10, 6); - u.umoney0 = 0; - ini_inv(Rogue); - if(!rn2(5)) ini_inv(Blindfold); - knows_object(SACK); - skill_init(Skill_R); - break; - case PM_SAMURAI: - Samurai[S_ARROWS].trquan = rn1(20, 26); - ini_inv(Samurai); - if(!rn2(5)) ini_inv(Blindfold); - knows_class(WEAPON_CLASS); - knows_class(ARMOR_CLASS); - skill_init(Skill_S); - break; - case PM_TOURIST: - Tourist[T_DARTS].trquan = rn1(20, 21); - u.umoney0 = rnd(1000); - ini_inv(Tourist); - if(!rn2(25)) ini_inv(Tinopener); - else if(!rn2(25)) ini_inv(Leash); - else if(!rn2(25)) ini_inv(Towel); - else if(!rn2(25)) ini_inv(Magicmarker); - skill_init(Skill_T); - break; - case PM_VALKYRIE: - ini_inv(Valkyrie); - if(!rn2(6)) ini_inv(Lamp); - knows_class(WEAPON_CLASS); - knows_class(ARMOR_CLASS); - skill_init(Skill_V); - break; - case PM_WIZARD: - ini_inv(Wizard); - if(!rn2(5)) ini_inv(Magicmarker); - if(!rn2(5)) ini_inv(Blindfold); - skill_init(Skill_W); - break; + default: /* impossible */ + break; + } - default: /* impossible */ - break; - } + /*** Race-specific initializations ***/ + switch (Race_switch) { + case PM_HUMAN: + /* Nothing special */ + break; + case PM_ELF: + /* + * Elves are people of music and song, or they are warriors. + * Non-warriors get an instrument. We use a kludge to + * get only non-magic instruments. + */ + if (Role_if(PM_PRIEST) || Role_if(PM_WIZARD)) { + static int trotyp[] = { WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP, + BELL, BUGLE, LEATHER_DRUM }; + Instrument[0].trotyp = trotyp[rn2(SIZE(trotyp))]; + ini_inv(Instrument); + } - /*** Race-specific initializations ***/ - switch (Race_switch) { - case PM_HUMAN: - /* Nothing special */ - break; + /* Elves can recognize all elvish objects */ + knows_object(ELVEN_SHORT_SWORD); + knows_object(ELVEN_ARROW); + knows_object(ELVEN_BOW); + knows_object(ELVEN_SPEAR); + knows_object(ELVEN_DAGGER); + knows_object(ELVEN_BROADSWORD); + knows_object(ELVEN_MITHRIL_COAT); + knows_object(ELVEN_LEATHER_HELM); + knows_object(ELVEN_SHIELD); + knows_object(ELVEN_BOOTS); + knows_object(ELVEN_CLOAK); + break; - case PM_ELF: - /* - * Elves are people of music and song, or they are warriors. - * Non-warriors get an instrument. We use a kludge to - * get only non-magic instruments. - */ - if (Role_if(PM_PRIEST) || Role_if(PM_WIZARD)) { - static int trotyp[] = { - WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP, - BELL, BUGLE, LEATHER_DRUM - }; - Instrument[0].trotyp = trotyp[rn2(SIZE(trotyp))]; - ini_inv(Instrument); - } + case PM_DWARF: + /* Dwarves can recognize all dwarvish objects */ + knows_object(DWARVISH_SPEAR); + knows_object(DWARVISH_SHORT_SWORD); + knows_object(DWARVISH_MATTOCK); + knows_object(DWARVISH_IRON_HELM); + knows_object(DWARVISH_MITHRIL_COAT); + knows_object(DWARVISH_CLOAK); + knows_object(DWARVISH_ROUNDSHIELD); + break; - /* Elves can recognize all elvish objects */ - knows_object(ELVEN_SHORT_SWORD); - knows_object(ELVEN_ARROW); - knows_object(ELVEN_BOW); - knows_object(ELVEN_SPEAR); - knows_object(ELVEN_DAGGER); - knows_object(ELVEN_BROADSWORD); - knows_object(ELVEN_MITHRIL_COAT); - knows_object(ELVEN_LEATHER_HELM); - knows_object(ELVEN_SHIELD); - knows_object(ELVEN_BOOTS); - knows_object(ELVEN_CLOAK); - break; + case PM_GNOME: + break; - case PM_DWARF: - /* Dwarves can recognize all dwarvish objects */ - knows_object(DWARVISH_SPEAR); - knows_object(DWARVISH_SHORT_SWORD); - knows_object(DWARVISH_MATTOCK); - knows_object(DWARVISH_IRON_HELM); - knows_object(DWARVISH_MITHRIL_COAT); - knows_object(DWARVISH_CLOAK); - knows_object(DWARVISH_ROUNDSHIELD); - break; + case PM_ORC: + /* compensate for generally inferior equipment */ + if (!Role_if(PM_WIZARD)) + ini_inv(Xtra_food); + /* Orcs can recognize all orcish objects */ + knows_object(ORCISH_SHORT_SWORD); + knows_object(ORCISH_ARROW); + knows_object(ORCISH_BOW); + knows_object(ORCISH_SPEAR); + knows_object(ORCISH_DAGGER); + knows_object(ORCISH_CHAIN_MAIL); + knows_object(ORCISH_RING_MAIL); + knows_object(ORCISH_HELM); + knows_object(ORCISH_SHIELD); + knows_object(URUK_HAI_SHIELD); + knows_object(ORCISH_CLOAK); + break; - case PM_GNOME: - break; + default: /* impossible */ + break; + } - case PM_ORC: - /* compensate for generally inferior equipment */ - if (!Role_if(PM_WIZARD)) - ini_inv(Xtra_food); - /* Orcs can recognize all orcish objects */ - knows_object(ORCISH_SHORT_SWORD); - knows_object(ORCISH_ARROW); - knows_object(ORCISH_BOW); - knows_object(ORCISH_SPEAR); - knows_object(ORCISH_DAGGER); - knows_object(ORCISH_CHAIN_MAIL); - knows_object(ORCISH_RING_MAIL); - knows_object(ORCISH_HELM); - knows_object(ORCISH_SHIELD); - knows_object(URUK_HAI_SHIELD); - knows_object(ORCISH_CLOAK); - break; + if (discover) + ini_inv(Wishing); - default: /* impossible */ - break; - } + if (wizard) + read_wizkit(); - if (discover) - ini_inv(Wishing); + if (u.umoney0) + ini_inv(Money); + u.umoney0 += hidden_gold(); /* in case sack has gold in it */ - if (wizard) - read_wizkit(); + find_ac(); /* get initial ac value */ + init_attr(75); /* init attribute values */ + max_rank_sz(); /* set max str size for class ranks */ + /* + * Do we really need this? + */ + for (i = 0; i < A_MAX; i++) + if (!rn2(20)) { + register int xd = rn2(7) - 2; /* biased variation */ + (void) adjattrib(i, xd, TRUE); + if (ABASE(i) < AMAX(i)) + AMAX(i) = ABASE(i); + } - if (u.umoney0) ini_inv(Money); - u.umoney0 += hidden_gold(); /* in case sack has gold in it */ + /* make sure you can carry all you have - especially for Tourists */ + while (inv_weight() > 0) { + if (adjattrib(A_STR, 1, TRUE)) + continue; + if (adjattrib(A_CON, 1, TRUE)) + continue; + /* only get here when didn't boost strength or constitution */ + break; + } - find_ac(); /* get initial ac value */ - init_attr(75); /* init attribute values */ - max_rank_sz(); /* set max str size for class ranks */ -/* - * Do we really need this? - */ - for(i = 0; i < A_MAX; i++) - if(!rn2(20)) { - register int xd = rn2(7) - 2; /* biased variation */ - (void) adjattrib(i, xd, TRUE); - if (ABASE(i) < AMAX(i)) AMAX(i) = ABASE(i); - } - - /* make sure you can carry all you have - especially for Tourists */ - while (inv_weight() > 0) { - if (adjattrib(A_STR, 1, TRUE)) continue; - if (adjattrib(A_CON, 1, TRUE)) continue; - /* only get here when didn't boost strength or constitution */ - break; - } - - return; + return; } /* skills aren't initialized, so we use the role-specific skill lists */ @@ -804,25 +918,54 @@ int otyp; int this_skill = spell_skilltype(otyp); switch (Role_switch) { - case PM_ARCHEOLOGIST: skills = Skill_A; break; - case PM_BARBARIAN: skills = Skill_B; break; - case PM_CAVEMAN: skills = Skill_C; break; - case PM_HEALER: skills = Skill_H; break; - case PM_KNIGHT: skills = Skill_K; break; - case PM_MONK: skills = Skill_Mon; break; - case PM_PRIEST: skills = Skill_P; break; - case PM_RANGER: skills = Skill_Ran; break; - case PM_ROGUE: skills = Skill_R; break; - case PM_SAMURAI: skills = Skill_S; break; - case PM_TOURIST: skills = Skill_T; break; - case PM_VALKYRIE: skills = Skill_V; break; - case PM_WIZARD: skills = Skill_W; break; - default: skills = 0; break; /* lint suppression */ + case PM_ARCHEOLOGIST: + skills = Skill_A; + break; + case PM_BARBARIAN: + skills = Skill_B; + break; + case PM_CAVEMAN: + skills = Skill_C; + break; + case PM_HEALER: + skills = Skill_H; + break; + case PM_KNIGHT: + skills = Skill_K; + break; + case PM_MONK: + skills = Skill_Mon; + break; + case PM_PRIEST: + skills = Skill_P; + break; + case PM_RANGER: + skills = Skill_Ran; + break; + case PM_ROGUE: + skills = Skill_R; + break; + case PM_SAMURAI: + skills = Skill_S; + break; + case PM_TOURIST: + skills = Skill_T; + break; + case PM_VALKYRIE: + skills = Skill_V; + break; + case PM_WIZARD: + skills = Skill_W; + break; + default: + skills = 0; + break; /* lint suppression */ } while (skills->skill != P_NONE) { - if (skills->skill == this_skill) return FALSE; - ++skills; + if (skills->skill == this_skill) + return FALSE; + ++skills; } return TRUE; } @@ -831,183 +974,180 @@ STATIC_OVL void ini_inv(trop) register struct trobj *trop; { - struct obj *obj; - int otyp, i; + struct obj *obj; + int otyp, i; - while (trop->trclass) { - if (trop->trotyp != UNDEF_TYP) { - otyp = (int)trop->trotyp; - if (urace.malenum != PM_HUMAN) { - /* substitute specific items for generic ones */ - for (i = 0; inv_subs[i].race_pm != NON_PM; ++i) - if (inv_subs[i].race_pm == urace.malenum && - otyp == inv_subs[i].item_otyp) { - otyp = inv_subs[i].subs_otyp; - break; - } - } - obj = mksobj(otyp, TRUE, FALSE); - } else { /* UNDEF_TYP */ - static NEARDATA short nocreate = STRANGE_OBJECT; - static NEARDATA short nocreate2 = STRANGE_OBJECT; - static NEARDATA short nocreate3 = STRANGE_OBJECT; - static NEARDATA short nocreate4 = STRANGE_OBJECT; - /* - * For random objects, do not create certain overly powerful - * items: wand of wishing, ring of levitation, or the - * polymorph/polymorph control combination. Specific objects, - * i.e. the discovery wishing, are still OK. - * Also, don't get a couple of really useless items. (Note: - * punishment isn't "useless". Some players who start out with - * one will immediately read it and use the iron ball as a - * weapon.) - */ - obj = mkobj(trop->trclass, FALSE); - otyp = obj->otyp; - while (otyp == WAN_WISHING - || otyp == nocreate - || otyp == nocreate2 - || otyp == nocreate3 - || otyp == nocreate4 - || otyp == RIN_LEVITATION - /* 'useless' items */ - || otyp == POT_HALLUCINATION - || otyp == POT_ACID - || otyp == SCR_AMNESIA - || otyp == SCR_FIRE - || otyp == SCR_BLANK_PAPER - || otyp == SPE_BLANK_PAPER - || otyp == RIN_AGGRAVATE_MONSTER - || otyp == RIN_HUNGER - || otyp == WAN_NOTHING - /* Monks don't use weapons */ - || (otyp == SCR_ENCHANT_WEAPON && - Role_if(PM_MONK)) - /* wizard patch -- they already have one */ - || (otyp == SPE_FORCE_BOLT && - Role_if(PM_WIZARD)) - /* powerful spells are either useless to - low level players or unbalancing; also - spells in restricted skill categories */ - || (obj->oclass == SPBOOK_CLASS && - (objects[otyp].oc_level > 3 || - restricted_spell_discipline(otyp))) - ) { - dealloc_obj(obj); - obj = mkobj(trop->trclass, FALSE); - otyp = obj->otyp; - } + while (trop->trclass) { + if (trop->trotyp != UNDEF_TYP) { + otyp = (int) trop->trotyp; + if (urace.malenum != PM_HUMAN) { + /* substitute specific items for generic ones */ + for (i = 0; inv_subs[i].race_pm != NON_PM; ++i) + if (inv_subs[i].race_pm == urace.malenum + && otyp == inv_subs[i].item_otyp) { + otyp = inv_subs[i].subs_otyp; + break; + } + } + obj = mksobj(otyp, TRUE, FALSE); + } else { /* UNDEF_TYP */ + static NEARDATA short nocreate = STRANGE_OBJECT; + static NEARDATA short nocreate2 = STRANGE_OBJECT; + static NEARDATA short nocreate3 = STRANGE_OBJECT; + static NEARDATA short nocreate4 = STRANGE_OBJECT; + /* + * For random objects, do not create certain overly powerful + * items: wand of wishing, ring of levitation, or the + * polymorph/polymorph control combination. Specific objects, + * i.e. the discovery wishing, are still OK. + * Also, don't get a couple of really useless items. (Note: + * punishment isn't "useless". Some players who start out with + * one will immediately read it and use the iron ball as a + * weapon.) + */ + obj = mkobj(trop->trclass, FALSE); + otyp = obj->otyp; + while (otyp == WAN_WISHING || otyp == nocreate + || otyp == nocreate2 || otyp == nocreate3 + || otyp == nocreate4 || otyp == RIN_LEVITATION + /* 'useless' items */ + || otyp == POT_HALLUCINATION + || otyp == POT_ACID + || otyp == SCR_AMNESIA + || otyp == SCR_FIRE + || otyp == SCR_BLANK_PAPER + || otyp == SPE_BLANK_PAPER + || otyp == RIN_AGGRAVATE_MONSTER + || otyp == RIN_HUNGER + || otyp == WAN_NOTHING + /* Monks don't use weapons */ + || (otyp == SCR_ENCHANT_WEAPON && Role_if(PM_MONK)) + /* wizard patch -- they already have one */ + || (otyp == SPE_FORCE_BOLT && Role_if(PM_WIZARD)) + /* powerful spells are either useless to + low level players or unbalancing; also + spells in restricted skill categories */ + || (obj->oclass == SPBOOK_CLASS + && (objects[otyp].oc_level > 3 + || restricted_spell_discipline(otyp)))) { + dealloc_obj(obj); + obj = mkobj(trop->trclass, FALSE); + otyp = obj->otyp; + } - /* Don't start with +0 or negative rings */ - if (objects[otyp].oc_charged && obj->spe <= 0) - obj->spe = rne(3); + /* Don't start with +0 or negative rings */ + if (objects[otyp].oc_charged && obj->spe <= 0) + obj->spe = rne(3); - /* Heavily relies on the fact that 1) we create wands - * before rings, 2) that we create rings before - * spellbooks, and that 3) not more than 1 object of a - * particular symbol is to be prohibited. (For more - * objects, we need more nocreate variables...) - */ - switch (otyp) { - case WAN_POLYMORPH: - case RIN_POLYMORPH: - case POT_POLYMORPH: - nocreate = RIN_POLYMORPH_CONTROL; - break; - case RIN_POLYMORPH_CONTROL: - nocreate = RIN_POLYMORPH; - nocreate2 = SPE_POLYMORPH; - nocreate3 = POT_POLYMORPH; - } - /* Don't have 2 of the same ring or spellbook */ - if (obj->oclass == RING_CLASS || - obj->oclass == SPBOOK_CLASS) - nocreate4 = otyp; - } + /* Heavily relies on the fact that 1) we create wands + * before rings, 2) that we create rings before + * spellbooks, and that 3) not more than 1 object of a + * particular symbol is to be prohibited. (For more + * objects, we need more nocreate variables...) + */ + switch (otyp) { + case WAN_POLYMORPH: + case RIN_POLYMORPH: + case POT_POLYMORPH: + nocreate = RIN_POLYMORPH_CONTROL; + break; + case RIN_POLYMORPH_CONTROL: + nocreate = RIN_POLYMORPH; + nocreate2 = SPE_POLYMORPH; + nocreate3 = POT_POLYMORPH; + } + /* Don't have 2 of the same ring or spellbook */ + if (obj->oclass == RING_CLASS || obj->oclass == SPBOOK_CLASS) + nocreate4 = otyp; + } - /* nudist gets no armor */ - if (u.uroleplay.nudist && obj->oclass == ARMOR_CLASS) { - dealloc_obj(obj); - trop++; - continue; - } + /* nudist gets no armor */ + if (u.uroleplay.nudist && obj->oclass == ARMOR_CLASS) { + dealloc_obj(obj); + trop++; + continue; + } - if (trop->trclass == COIN_CLASS) { - /* no "blessed" or "identified" money */ - obj->quan = u.umoney0; - } else { - if (objects[otyp].oc_uses_known) obj->known = 1; - obj->dknown = obj->bknown = obj->rknown = 1; - if (Is_container(obj) || obj->otyp == STATUE) { - obj->cknown = obj->lknown = 1; - obj->otrapped = 0; - } - obj->cursed = 0; - if (obj->opoisoned && u.ualign.type != A_CHAOTIC) - obj->opoisoned = 0; - if (obj->oclass == WEAPON_CLASS || - obj->oclass == TOOL_CLASS) { - obj->quan = (long) trop->trquan; - trop->trquan = 1; - } else if (obj->oclass == GEM_CLASS && - is_graystone(obj) && obj->otyp != FLINT) { - obj->quan = 1L; - } - if (trop->trspe != UNDEF_SPE) - obj->spe = trop->trspe; - if (trop->trbless != UNDEF_BLESS) - obj->blessed = trop->trbless; - } - /* defined after setting otyp+quan + blessedness */ - obj->owt = weight(obj); - obj = addinv(obj); + if (trop->trclass == COIN_CLASS) { + /* no "blessed" or "identified" money */ + obj->quan = u.umoney0; + } else { + if (objects[otyp].oc_uses_known) + obj->known = 1; + obj->dknown = obj->bknown = obj->rknown = 1; + if (Is_container(obj) || obj->otyp == STATUE) { + obj->cknown = obj->lknown = 1; + obj->otrapped = 0; + } + obj->cursed = 0; + if (obj->opoisoned && u.ualign.type != A_CHAOTIC) + obj->opoisoned = 0; + if (obj->oclass == WEAPON_CLASS || obj->oclass == TOOL_CLASS) { + obj->quan = (long) trop->trquan; + trop->trquan = 1; + } else if (obj->oclass == GEM_CLASS && is_graystone(obj) + && obj->otyp != FLINT) { + obj->quan = 1L; + } + if (trop->trspe != UNDEF_SPE) + obj->spe = trop->trspe; + if (trop->trbless != UNDEF_BLESS) + obj->blessed = trop->trbless; + } + /* defined after setting otyp+quan + blessedness */ + obj->owt = weight(obj); + obj = addinv(obj); - /* Make the type known if necessary */ - if (OBJ_DESCR(objects[otyp]) && obj->known) - discover_object(otyp, TRUE, FALSE); - if (otyp == OIL_LAMP) - discover_object(POT_OIL, TRUE, FALSE); + /* Make the type known if necessary */ + if (OBJ_DESCR(objects[otyp]) && obj->known) + discover_object(otyp, TRUE, FALSE); + if (otyp == OIL_LAMP) + discover_object(POT_OIL, TRUE, FALSE); - if(obj->oclass == ARMOR_CLASS){ - if (is_shield(obj) && !uarms) { - setworn(obj, W_ARMS); - if (uswapwep) setuswapwep((struct obj *) 0); - } else if (is_helmet(obj) && !uarmh) - setworn(obj, W_ARMH); - else if (is_gloves(obj) && !uarmg) - setworn(obj, W_ARMG); - else if (is_shirt(obj) && !uarmu) - setworn(obj, W_ARMU); - else if (is_cloak(obj) && !uarmc) - setworn(obj, W_ARMC); - else if (is_boots(obj) && !uarmf) - setworn(obj, W_ARMF); - else if (is_suit(obj) && !uarm) - setworn(obj, W_ARM); - } + if (obj->oclass == ARMOR_CLASS) { + if (is_shield(obj) && !uarms) { + setworn(obj, W_ARMS); + if (uswapwep) + setuswapwep((struct obj *) 0); + } else if (is_helmet(obj) && !uarmh) + setworn(obj, W_ARMH); + else if (is_gloves(obj) && !uarmg) + setworn(obj, W_ARMG); + else if (is_shirt(obj) && !uarmu) + setworn(obj, W_ARMU); + else if (is_cloak(obj) && !uarmc) + setworn(obj, W_ARMC); + else if (is_boots(obj) && !uarmf) + setworn(obj, W_ARMF); + else if (is_suit(obj) && !uarm) + setworn(obj, W_ARM); + } - if (obj->oclass == WEAPON_CLASS || is_weptool(obj) || - otyp == TIN_OPENER || otyp == FLINT || otyp == ROCK) { - if (is_ammo(obj) || is_missile(obj)) { - if (!uquiver) setuqwep(obj); - } else if (!uwep) setuwep(obj); - else if (!uswapwep) setuswapwep(obj); - } - if (obj->oclass == SPBOOK_CLASS && - obj->otyp != SPE_BLANK_PAPER) - initialspell(obj); + if (obj->oclass == WEAPON_CLASS || is_weptool(obj) + || otyp == TIN_OPENER || otyp == FLINT || otyp == ROCK) { + if (is_ammo(obj) || is_missile(obj)) { + if (!uquiver) + setuqwep(obj); + } else if (!uwep) + setuwep(obj); + else if (!uswapwep) + setuswapwep(obj); + } + if (obj->oclass == SPBOOK_CLASS && obj->otyp != SPE_BLANK_PAPER) + initialspell(obj); #if !defined(PYRAMID_BUG) && !defined(MAC) - if(--trop->trquan) continue; /* make a similar object */ + if (--trop->trquan) + continue; /* make a similar object */ #else - if(trop->trquan) { /* check if zero first */ - --trop->trquan; - if(trop->trquan) - continue; /* make a similar object */ - } + if (trop->trquan) { /* check if zero first */ + --trop->trquan; + if (trop->trquan) + continue; /* make a similar object */ + } #endif - trop++; - } + trop++; + } } /*u_init.c*/ diff --git a/src/uhitm.c b/src/uhitm.c index be1d7df1d..80d62b8ad 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -1,210 +1,216 @@ -/* NetHack 3.6 uhitm.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 uhitm.c $NHDT-Date: 1431192764 2015/05/09 17:32:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.143 $ */ /* NetHack 3.6 uhitm.c $Date: 2012/05/01 02:22:33 $ $Revision: 1.116 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -STATIC_DCL boolean FDECL(known_hitum, (struct monst *,struct obj *, - int *,int,int,struct attack *)); +STATIC_DCL boolean FDECL(known_hitum, (struct monst *, struct obj *, int *, + int, int, struct attack *)); STATIC_DCL boolean FDECL(theft_petrifies, (struct obj *)); STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *)); -STATIC_DCL boolean FDECL(hitum, (struct monst *,struct attack *)); -STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *,struct obj *,int)); -STATIC_DCL int FDECL(joust, (struct monst *,struct obj *)); +STATIC_DCL boolean FDECL(hitum, (struct monst *, struct attack *)); +STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *, struct obj *, int)); +STATIC_DCL int FDECL(joust, (struct monst *, struct obj *)); STATIC_DCL void NDECL(demonpet); -STATIC_DCL boolean FDECL(m_slips_free, (struct monst *mtmp,struct attack *mattk)); -STATIC_DCL int FDECL(explum, (struct monst *,struct attack *)); +STATIC_DCL boolean +FDECL(m_slips_free, (struct monst * mtmp, struct attack *mattk)); +STATIC_DCL int FDECL(explum, (struct monst *, struct attack *)); STATIC_DCL void FDECL(start_engulf, (struct monst *)); STATIC_DCL void NDECL(end_engulf); -STATIC_DCL int FDECL(gulpum, (struct monst *,struct attack *)); +STATIC_DCL int FDECL(gulpum, (struct monst *, struct attack *)); STATIC_DCL boolean FDECL(hmonas, (struct monst *)); STATIC_DCL void FDECL(nohandglow, (struct monst *)); STATIC_DCL boolean FDECL(shade_aware, (struct obj *)); -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ /* The below might become a parameter instead if we use it a lot */ static int dieroll; /* Used to flag attacks caused by Stormbringer's maliciousness. */ static boolean override_confirmation = FALSE; -#define PROJECTILE(obj) ((obj) && is_ammo(obj)) +#define PROJECTILE(obj) ((obj) && is_ammo(obj)) void erode_armor(mdef, hurt) struct monst *mdef; int hurt; { - struct obj *target; + struct obj *target; - /* What the following code does: it keeps looping until it - * finds a target for the rust monster. - * Head, feet, etc... not covered by metal, or covered by - * rusty metal, are not targets. However, your body always - * is, no matter what covers it. - */ - while (1) { - switch(rn2(5)) { - case 0: - target = which_armor(mdef, W_ARMH); - if (!target || - erode_obj(target, xname(target), hurt, EF_GREASE) == ER_NOTHING) - continue; - break; - case 1: - target = which_armor(mdef, W_ARMC); - if (target) { - (void)erode_obj(target, xname(target), hurt, EF_GREASE | EF_VERBOSE); - break; - } - if ((target = which_armor(mdef, W_ARM)) != (struct obj *)0) { - (void)erode_obj(target, xname(target), hurt, EF_GREASE | EF_VERBOSE); - } else if ((target = which_armor(mdef, W_ARMU)) != (struct obj *)0) { - (void)erode_obj(target, xname(target), hurt, EF_GREASE | EF_VERBOSE); - } - break; - case 2: - target = which_armor(mdef, W_ARMS); - if (!target || - erode_obj(target, xname(target), hurt, EF_GREASE) == ER_NOTHING) - continue; - break; - case 3: - target = which_armor(mdef, W_ARMG); - if (!target || - erode_obj(target, xname(target), hurt, EF_GREASE) == ER_NOTHING) - continue; - break; - case 4: - target = which_armor(mdef, W_ARMF); - if (!target || - erode_obj(target, xname(target), hurt, EF_GREASE) == ER_NOTHING) - continue; - break; - } - break; /* Out of while loop */ - } + /* What the following code does: it keeps looping until it + * finds a target for the rust monster. + * Head, feet, etc... not covered by metal, or covered by + * rusty metal, are not targets. However, your body always + * is, no matter what covers it. + */ + while (1) { + switch (rn2(5)) { + case 0: + target = which_armor(mdef, W_ARMH); + if (!target + || erode_obj(target, xname(target), hurt, EF_GREASE) + == ER_NOTHING) + continue; + break; + case 1: + target = which_armor(mdef, W_ARMC); + if (target) { + (void) erode_obj(target, xname(target), hurt, + EF_GREASE | EF_VERBOSE); + break; + } + if ((target = which_armor(mdef, W_ARM)) != (struct obj *) 0) { + (void) erode_obj(target, xname(target), hurt, + EF_GREASE | EF_VERBOSE); + } else if ((target = which_armor(mdef, W_ARMU)) + != (struct obj *) 0) { + (void) erode_obj(target, xname(target), hurt, + EF_GREASE | EF_VERBOSE); + } + break; + case 2: + target = which_armor(mdef, W_ARMS); + if (!target + || erode_obj(target, xname(target), hurt, EF_GREASE) + == ER_NOTHING) + continue; + break; + case 3: + target = which_armor(mdef, W_ARMG); + if (!target + || erode_obj(target, xname(target), hurt, EF_GREASE) + == ER_NOTHING) + continue; + break; + case 4: + target = which_armor(mdef, W_ARMF); + if (!target + || erode_obj(target, xname(target), hurt, EF_GREASE) + == ER_NOTHING) + continue; + break; + } + break; /* Out of while loop */ + } } /* FALSE means it's OK to attack */ boolean attack_checks(mtmp, wep) register struct monst *mtmp; -struct obj *wep; /* uwep for attack(), null for kick_monster() */ +struct obj *wep; /* uwep for attack(), null for kick_monster() */ { - char qbuf[QBUFSZ]; + char qbuf[QBUFSZ]; - /* if you're close enough to attack, alert any waiting monster */ - mtmp->mstrategy &= ~STRAT_WAITMASK; + /* if you're close enough to attack, alert any waiting monster */ + mtmp->mstrategy &= ~STRAT_WAITMASK; - if (u.uswallow && mtmp == u.ustuck) return FALSE; + if (u.uswallow && mtmp == u.ustuck) + return FALSE; - if (context.forcefight) { - /* Do this in the caller, after we checked that the monster - * didn't die from the blow. Reason: putting the 'I' there - * causes the hero to forget the square's contents since - * both 'I' and remembered contents are stored in .glyph. - * If the monster dies immediately from the blow, the 'I' will - * not stay there, so the player will have suddenly forgotten - * the square's contents for no apparent reason. - if (!canspotmon(mtmp) && - !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) - map_invisible(bhitpos.x, bhitpos.y); - */ - return FALSE; - } + if (context.forcefight) { + /* Do this in the caller, after we checked that the monster + * didn't die from the blow. Reason: putting the 'I' there + * causes the hero to forget the square's contents since + * both 'I' and remembered contents are stored in .glyph. + * If the monster dies immediately from the blow, the 'I' will + * not stay there, so the player will have suddenly forgotten + * the square's contents for no apparent reason. + if (!canspotmon(mtmp) && + !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) + map_invisible(bhitpos.x, bhitpos.y); + */ + return FALSE; + } - /* Put up an invisible monster marker, but with exceptions for - * monsters that hide and monsters you've been warned about. - * The former already prints a warning message and - * prevents you from hitting the monster just via the hidden monster - * code below; if we also did that here, similar behavior would be - * happening two turns in a row. The latter shows a glyph on - * the screen, so you know something is there. - */ - if (!canspotmon(mtmp) && - !glyph_is_warning(glyph_at(bhitpos.x,bhitpos.y)) && - !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph) && - !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) { - pline("Wait! There's %s there you can't see!", - something); - map_invisible(bhitpos.x, bhitpos.y); - /* if it was an invisible mimic, treat it as if we stumbled - * onto a visible mimic - */ - if (mtmp->m_ap_type && !Protection_from_shape_changers && - /* applied pole-arm attack is too far to get stuck */ - distu(mtmp->mx, mtmp->my) <= 2) { - if(!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data,AD_STCK)) - u.ustuck = mtmp; - } - wakeup(mtmp); /* always necessary; also un-mimics mimics */ - return TRUE; - } + /* Put up an invisible monster marker, but with exceptions for + * monsters that hide and monsters you've been warned about. + * The former already prints a warning message and + * prevents you from hitting the monster just via the hidden monster + * code below; if we also did that here, similar behavior would be + * happening two turns in a row. The latter shows a glyph on + * the screen, so you know something is there. + */ + if (!canspotmon(mtmp) && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y)) + && !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph) + && !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) { + pline("Wait! There's %s there you can't see!", something); + map_invisible(bhitpos.x, bhitpos.y); + /* if it was an invisible mimic, treat it as if we stumbled + * onto a visible mimic + */ + if (mtmp->m_ap_type && !Protection_from_shape_changers && + /* applied pole-arm attack is too far to get stuck */ + distu(mtmp->mx, mtmp->my) <= 2) { + if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)) + u.ustuck = mtmp; + } + wakeup(mtmp); /* always necessary; also un-mimics mimics */ + return TRUE; + } - if (mtmp->m_ap_type && !Protection_from_shape_changers && - !sensemon(mtmp) && - !glyph_is_warning(glyph_at(bhitpos.x,bhitpos.y))) { - /* If a hidden mimic was in a square where a player remembers - * some (probably different) unseen monster, the player is in - * luck--he attacks it even though it's hidden. - */ - if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) { - seemimic(mtmp); - return(FALSE); - } - stumble_onto_mimic(mtmp); - return TRUE; - } + if (mtmp->m_ap_type && !Protection_from_shape_changers && !sensemon(mtmp) + && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y))) { + /* If a hidden mimic was in a square where a player remembers + * some (probably different) unseen monster, the player is in + * luck--he attacks it even though it's hidden. + */ + if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) { + seemimic(mtmp); + return (FALSE); + } + stumble_onto_mimic(mtmp); + return TRUE; + } - if (mtmp->mundetected && !canseemon(mtmp) && - !glyph_is_warning(glyph_at(bhitpos.x,bhitpos.y)) && - (hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) { - mtmp->mundetected = mtmp->msleeping = 0; - newsym(mtmp->mx, mtmp->my); - if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) { - seemimic(mtmp); - return(FALSE); - } - if (!((Blind ? Blind_telepat : Unblind_telepat) || - Detect_monsters)) { - struct obj *obj; + if (mtmp->mundetected && !canseemon(mtmp) + && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y)) + && (hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) { + mtmp->mundetected = mtmp->msleeping = 0; + newsym(mtmp->mx, mtmp->my); + if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) { + seemimic(mtmp); + return (FALSE); + } + if (!((Blind ? Blind_telepat : Unblind_telepat) || Detect_monsters)) { + struct obj *obj; - if (Blind || (is_pool(mtmp->mx,mtmp->my) && !Underwater)) - pline("Wait! There's a hidden monster there!"); - else if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0) - pline("Wait! There's %s hiding under %s!", - an(l_monnam(mtmp)), doname(obj)); - return TRUE; - } - } + if (Blind || (is_pool(mtmp->mx, mtmp->my) && !Underwater)) + pline("Wait! There's a hidden monster there!"); + else if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0) + pline("Wait! There's %s hiding under %s!", + an(l_monnam(mtmp)), doname(obj)); + return TRUE; + } + } - /* - * make sure to wake up a monster from the above cases if the - * hero can sense that the monster is there. - */ - if ((mtmp->mundetected || mtmp->m_ap_type) && sensemon(mtmp)) { - mtmp->mundetected = 0; - wakeup(mtmp); - } + /* + * make sure to wake up a monster from the above cases if the + * hero can sense that the monster is there. + */ + if ((mtmp->mundetected || mtmp->m_ap_type) && sensemon(mtmp)) { + mtmp->mundetected = 0; + wakeup(mtmp); + } - if (flags.confirm && mtmp->mpeaceful - && !Confusion && !Hallucination && !Stunned) { - /* Intelligent chaotic weapons (Stormbringer) want blood */ - if (wep && wep->oartifact == ART_STORMBRINGER) { - override_confirmation = TRUE; - return(FALSE); - } - if (canspotmon(mtmp)) { - Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp)); - if (!paranoid_query(ParanoidHit, qbuf)) { - context.move = 0; - return(TRUE); - } - } - } + if (flags.confirm && mtmp->mpeaceful && !Confusion && !Hallucination + && !Stunned) { + /* Intelligent chaotic weapons (Stormbringer) want blood */ + if (wep && wep->oartifact == ART_STORMBRINGER) { + override_confirmation = TRUE; + return (FALSE); + } + if (canspotmon(mtmp)) { + Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp)); + if (!paranoid_query(ParanoidHit, qbuf)) { + context.move = 0; + return (TRUE); + } + } + } - return(FALSE); + return (FALSE); } /* @@ -214,84 +220,90 @@ void check_caitiff(mtmp) struct monst *mtmp; { - if (u.ualign.record <= -10) return; + if (u.ualign.record <= -10) + return; - if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL && - (!mtmp->mcanmove || mtmp->msleeping || - (mtmp->mflee && !mtmp->mavenge))) { - You("caitiff!"); - adjalign(-1); - } else if (Role_if(PM_SAMURAI) && mtmp->mpeaceful) { - /* attacking peaceful creatures is bad for the samurai's giri */ - You("dishonorably attack the innocent!"); - adjalign(-1); - } + if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL + && (!mtmp->mcanmove || mtmp->msleeping + || (mtmp->mflee && !mtmp->mavenge))) { + You("caitiff!"); + adjalign(-1); + } else if (Role_if(PM_SAMURAI) && mtmp->mpeaceful) { + /* attacking peaceful creatures is bad for the samurai's giri */ + You("dishonorably attack the innocent!"); + adjalign(-1); + } } int find_roll_to_hit(mtmp, aatyp, weapon, attk_count, role_roll_penalty) register struct monst *mtmp; -uchar aatyp; /* usually AT_WEAP or AT_KICK */ -struct obj *weapon; /* uwep or uswapwep or NULL */ +uchar aatyp; /* usually AT_WEAP or AT_KICK */ +struct obj *weapon; /* uwep or uswapwep or NULL */ int *attk_count, *role_roll_penalty; { - int tmp, tmp2; + int tmp, tmp2; - *role_roll_penalty = 0; /* default is `none' */ + *role_roll_penalty = 0; /* default is `none' */ - tmp = 1 + Luck + abon() + find_mac(mtmp) + u.uhitinc + - maybe_polyd(youmonst.data->mlevel, u.ulevel); + tmp = 1 + Luck + abon() + find_mac(mtmp) + u.uhitinc + + maybe_polyd(youmonst.data->mlevel, u.ulevel); - /* some actions should occur only once during multiple attacks */ - if (!(*attk_count)++) { - /* knight's chivalry or samurai's giri */ - check_caitiff(mtmp); - } + /* some actions should occur only once during multiple attacks */ + if (!(*attk_count)++) { + /* knight's chivalry or samurai's giri */ + check_caitiff(mtmp); + } - /* adjust vs. (and possibly modify) monster state */ - if(mtmp->mstun) tmp += 2; - if(mtmp->mflee) tmp += 2; + /* adjust vs. (and possibly modify) monster state */ + if (mtmp->mstun) + tmp += 2; + if (mtmp->mflee) + tmp += 2; - if (mtmp->msleeping) { - mtmp->msleeping = 0; - tmp += 2; - } - if(!mtmp->mcanmove) { - tmp += 4; - if(!rn2(10)) { - mtmp->mcanmove = 1; - mtmp->mfrozen = 0; - } - } + if (mtmp->msleeping) { + mtmp->msleeping = 0; + tmp += 2; + } + if (!mtmp->mcanmove) { + tmp += 4; + if (!rn2(10)) { + mtmp->mcanmove = 1; + mtmp->mfrozen = 0; + } + } - /* role/race adjustments */ - if (Role_if(PM_MONK) && !Upolyd) { - if (uarm) - tmp -= (*role_roll_penalty = urole.spelarmr); - else if (!uwep && !uarms) - tmp += (u.ulevel / 3) + 2; - } - if (is_orc(mtmp->data) && - maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) - tmp++; + /* role/race adjustments */ + if (Role_if(PM_MONK) && !Upolyd) { + if (uarm) + tmp -= (*role_roll_penalty = urole.spelarmr); + else if (!uwep && !uarms) + tmp += (u.ulevel / 3) + 2; + } + if (is_orc(mtmp->data) + && maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) + tmp++; - /* encumbrance: with a lot of luggage, your agility diminishes */ - if ((tmp2 = near_capacity()) != 0) tmp -= (tmp2*2) - 1; - if (u.utrap) tmp -= 3; + /* encumbrance: with a lot of luggage, your agility diminishes */ + if ((tmp2 = near_capacity()) != 0) + tmp -= (tmp2 * 2) - 1; + if (u.utrap) + tmp -= 3; - /* - * hitval applies if making a weapon attack while wielding a weapon; - * weapon_hit_bonus applies if doing a weapon attack even bare-handed - * or if kicking as martial artist - */ - if (aatyp == AT_WEAP || aatyp == AT_CLAW) { - if (weapon) tmp += hitval(weapon, mtmp); - tmp += weapon_hit_bonus(weapon); - } else if (aatyp == AT_KICK && martial_bonus()) { - tmp += weapon_hit_bonus((struct obj *)0); - } + /* + * hitval applies if making a weapon attack while wielding a weapon; + * weapon_hit_bonus applies if doing a weapon attack even bare-handed + * or if kicking as martial artist + */ + if (aatyp == AT_WEAP || aatyp == AT_CLAW) { + if (weapon) + tmp += hitval(weapon, mtmp); + tmp += weapon_hit_bonus(weapon); + } else if (aatyp == AT_KICK && martial_bonus()) { + tmp += weapon_hit_bonus((struct obj *) 0); + } - return tmp; + return tmp; } /* try to attack; return FALSE if monster evaded */ @@ -300,121 +312,123 @@ boolean attack(mtmp) register struct monst *mtmp; { - register struct permonst *mdat = mtmp->data; + register struct permonst *mdat = mtmp->data; - /* This section of code provides protection against accidentally - * hitting peaceful (like '@') and tame (like 'd') monsters. - * Protection is provided as long as player is not: blind, confused, - * hallucinating or stunned. - * changes by wwp 5/16/85 - * More changes 12/90, -dkh-. if its tame and safepet, (and protected - * 07/92) then we assume that you're not trying to attack. Instead, - * you'll usually just swap places if this is a movement command - */ - /* Intelligent chaotic weapons (Stormbringer) want blood */ - if (is_safepet(mtmp) && !context.forcefight) { - if (!uwep || uwep->oartifact != ART_STORMBRINGER) { - /* there are some additional considerations: this won't work - * if in a shop or Punished or you miss a random roll or - * if you can walk thru walls and your pet cannot (KAA) or - * if your pet is a long worm (unless someone does better). - * there's also a chance of displacing a "frozen" monster. - * sleeping monsters might magically walk in their sleep. - */ - boolean foo = (Punished || !rn2(7) || is_longworm(mtmp->data)), - inshop = FALSE; - char *p; + /* This section of code provides protection against accidentally + * hitting peaceful (like '@') and tame (like 'd') monsters. + * Protection is provided as long as player is not: blind, confused, + * hallucinating or stunned. + * changes by wwp 5/16/85 + * More changes 12/90, -dkh-. if its tame and safepet, (and protected + * 07/92) then we assume that you're not trying to attack. Instead, + * you'll usually just swap places if this is a movement command + */ + /* Intelligent chaotic weapons (Stormbringer) want blood */ + if (is_safepet(mtmp) && !context.forcefight) { + if (!uwep || uwep->oartifact != ART_STORMBRINGER) { + /* there are some additional considerations: this won't work + * if in a shop or Punished or you miss a random roll or + * if you can walk thru walls and your pet cannot (KAA) or + * if your pet is a long worm (unless someone does better). + * there's also a chance of displacing a "frozen" monster. + * sleeping monsters might magically walk in their sleep. + */ + boolean foo = (Punished || !rn2(7) || is_longworm(mtmp->data)), + inshop = FALSE; + char *p; - for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++) - if (tended_shop(&rooms[*p - ROOMOFFSET])) { - inshop = TRUE; - break; - } + for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++) + if (tended_shop(&rooms[*p - ROOMOFFSET])) { + inshop = TRUE; + break; + } - if (inshop || foo || - (IS_ROCK(levl[u.ux][u.uy].typ) && - !passes_walls(mtmp->data))) { - char buf[BUFSZ]; + if (inshop || foo || (IS_ROCK(levl[u.ux][u.uy].typ) + && !passes_walls(mtmp->data))) { + char buf[BUFSZ]; - monflee(mtmp, rnd(6), FALSE, FALSE); - Strcpy(buf, y_monnam(mtmp)); - buf[0] = highc(buf[0]); - You("stop. %s is in the way!", buf); - return(TRUE); - } else if ((mtmp->mfrozen || (! mtmp->mcanmove) - || (mtmp->data->mmove == 0)) && rn2(6)) { - pline("%s doesn't seem to move!", Monnam(mtmp)); - return(TRUE); - } else return(FALSE); - } - } + monflee(mtmp, rnd(6), FALSE, FALSE); + Strcpy(buf, y_monnam(mtmp)); + buf[0] = highc(buf[0]); + You("stop. %s is in the way!", buf); + return (TRUE); + } else if ((mtmp->mfrozen || (!mtmp->mcanmove) + || (mtmp->data->mmove == 0)) && rn2(6)) { + pline("%s doesn't seem to move!", Monnam(mtmp)); + return (TRUE); + } else + return (FALSE); + } + } - /* possibly set in attack_checks; - examined in known_hitum, called via hitum or hmonas below */ - override_confirmation = FALSE; - /* attack_checks() used to use directly, now - it uses bhitpos instead; it might map an invisible monster there */ - bhitpos.x = u.ux + u.dx; - bhitpos.y = u.uy + u.dy; - if (attack_checks(mtmp, uwep)) return(TRUE); + /* possibly set in attack_checks; + examined in known_hitum, called via hitum or hmonas below */ + override_confirmation = FALSE; + /* attack_checks() used to use directly, now + it uses bhitpos instead; it might map an invisible monster there */ + bhitpos.x = u.ux + u.dx; + bhitpos.y = u.uy + u.dy; + if (attack_checks(mtmp, uwep)) + return (TRUE); - if (Upolyd && noattacks(youmonst.data)) { - /* certain "pacifist" monsters don't attack */ - You("have no way to attack monsters physically."); - mtmp->mstrategy &= ~STRAT_WAITMASK; - goto atk_done; - } + if (Upolyd && noattacks(youmonst.data)) { + /* certain "pacifist" monsters don't attack */ + You("have no way to attack monsters physically."); + mtmp->mstrategy &= ~STRAT_WAITMASK; + goto atk_done; + } - if (check_capacity("You cannot fight while so heavily loaded.") || - /* consume extra nutrition during combat; maybe pass out */ - overexertion()) - goto atk_done; + if (check_capacity("You cannot fight while so heavily loaded.") || + /* consume extra nutrition during combat; maybe pass out */ + overexertion()) + goto atk_done; - if (u.twoweap && !can_twoweapon()) - untwoweapon(); + if (u.twoweap && !can_twoweapon()) + untwoweapon(); - if(unweapon) { - unweapon = FALSE; - if(flags.verbose) { - if(uwep) - You("begin bashing monsters with %s.", - yobjnam(uwep, (char *)0)); - else if (!cantwield(youmonst.data)) - You("begin %sing monsters with your %s %s.", - Role_if(PM_MONK) ? "strik" : "bash", - uarmg ? "gloved" : "bare", /* Del Lamb */ - makeplural(body_part(HAND))); - } - } - exercise(A_STR, TRUE); /* you're exercising muscles */ - /* andrew@orca: prevent unlimited pick-axe attacks */ - u_wipe_engr(3); + if (unweapon) { + unweapon = FALSE; + if (flags.verbose) { + if (uwep) + You("begin bashing monsters with %s.", + yobjnam(uwep, (char *) 0)); + else if (!cantwield(youmonst.data)) + You("begin %sing monsters with your %s %s.", + Role_if(PM_MONK) ? "strik" : "bash", + uarmg ? "gloved" : "bare", /* Del Lamb */ + makeplural(body_part(HAND))); + } + } + exercise(A_STR, TRUE); /* you're exercising muscles */ + /* andrew@orca: prevent unlimited pick-axe attacks */ + u_wipe_engr(3); - /* Is the "it died" check actually correct? */ - if(mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping && - !mtmp->mconf && mtmp->mcansee && !rn2(7) && - (m_move(mtmp, 0) == 2 || /* it died */ - mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy)) /* it moved */ - return(FALSE); + /* Is the "it died" check actually correct? */ + if (mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping + && !mtmp->mconf && mtmp->mcansee && !rn2(7) + && (m_move(mtmp, 0) == 2 || /* it died */ + mtmp->mx != u.ux + u.dx + || mtmp->my != u.uy + u.dy)) /* it moved */ + return (FALSE); - if (Upolyd) - (void) hmonas(mtmp); - else - (void) hitum(mtmp, youmonst.data->mattk); - mtmp->mstrategy &= ~STRAT_WAITMASK; + if (Upolyd) + (void) hmonas(mtmp); + else + (void) hitum(mtmp, youmonst.data->mattk); + mtmp->mstrategy &= ~STRAT_WAITMASK; atk_done: - /* see comment in attack_checks() */ - /* we only need to check for this if we did an attack_checks() - * and it returned 0 (it's okay to attack), and the monster didn't - * evade. - */ - if (context.forcefight && mtmp->mhp > 0 && !canspotmon(mtmp) && - !glyph_is_invisible(levl[u.ux+u.dx][u.uy+u.dy].glyph) && - !(u.uswallow && mtmp == u.ustuck)) - map_invisible(u.ux+u.dx, u.uy+u.dy); + /* see comment in attack_checks() */ + /* we only need to check for this if we did an attack_checks() + * and it returned 0 (it's okay to attack), and the monster didn't + * evade. + */ + if (context.forcefight && mtmp->mhp > 0 && !canspotmon(mtmp) + && !glyph_is_invisible(levl[u.ux + u.dx][u.uy + u.dy].glyph) + && !(u.uswallow && mtmp == u.ustuck)) + map_invisible(u.ux + u.dx, u.uy + u.dy); - return(TRUE); + return (TRUE); } /* really hit target monster; returns TRUE if it still lives */ @@ -423,55 +437,54 @@ known_hitum(mon, weapon, mhit, rollneeded, armorpenalty, uattk) register struct monst *mon; struct obj *weapon; int *mhit; -int rollneeded, armorpenalty; /* for monks */ +int rollneeded, armorpenalty; /* for monks */ struct attack *uattk; { - register boolean malive = TRUE; + register boolean malive = TRUE; - if (override_confirmation) { - /* this may need to be generalized if weapons other than - Stormbringer acquire similar anti-social behavior... */ - if (flags.verbose) Your("bloodthirsty blade attacks!"); - } + if (override_confirmation) { + /* this may need to be generalized if weapons other than + Stormbringer acquire similar anti-social behavior... */ + if (flags.verbose) + Your("bloodthirsty blade attacks!"); + } - if(!*mhit) { - missum(mon, uattk, (rollneeded + armorpenalty > dieroll)); - } else { - int oldhp = mon->mhp, - x = u.ux + u.dx, y = u.uy + u.dy; - long oldweaphit = u.uconduct.weaphit; + if (!*mhit) { + missum(mon, uattk, (rollneeded + armorpenalty > dieroll)); + } else { + int oldhp = mon->mhp, x = u.ux + u.dx, y = u.uy + u.dy; + long oldweaphit = u.uconduct.weaphit; - /* KMH, conduct */ - if (weapon && - (weapon->oclass == WEAPON_CLASS || is_weptool(weapon))) - u.uconduct.weaphit++; + /* KMH, conduct */ + if (weapon && (weapon->oclass == WEAPON_CLASS || is_weptool(weapon))) + u.uconduct.weaphit++; - /* we hit the monster; be careful: it might die or - be knocked into a different location */ - notonhead = (mon->mx != x || mon->my != y); - malive = hmon(mon, weapon, HMON_MELEE); - if (malive) { - /* monster still alive */ - if(!rn2(25) && mon->mhp < mon->mhpmax/2 - && !(u.uswallow && mon == u.ustuck)) { - /* maybe should regurgitate if swallowed? */ - monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE); + /* we hit the monster; be careful: it might die or + be knocked into a different location */ + notonhead = (mon->mx != x || mon->my != y); + malive = hmon(mon, weapon, HMON_MELEE); + if (malive) { + /* monster still alive */ + if (!rn2(25) && mon->mhp < mon->mhpmax / 2 + && !(u.uswallow && mon == u.ustuck)) { + /* maybe should regurgitate if swallowed? */ + monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE); - if(u.ustuck == mon && !u.uswallow && !sticks(youmonst.data)) - u.ustuck = 0; - } - /* Vorpal Blade hit converted to miss */ - /* could be headless monster or worm tail */ - if (mon->mhp == oldhp) { - *mhit = 0; - /* a miss does not break conduct */ - u.uconduct.weaphit = oldweaphit; - } - if (mon->wormno && *mhit) - cutworm(mon, x, y, weapon); - } - } - return(malive); + if (u.ustuck == mon && !u.uswallow && !sticks(youmonst.data)) + u.ustuck = 0; + } + /* Vorpal Blade hit converted to miss */ + /* could be headless monster or worm tail */ + if (mon->mhp == oldhp) { + *mhit = 0; + /* a miss does not break conduct */ + u.uconduct.weaphit = oldweaphit; + } + if (mon->wormno && *mhit) + cutworm(mon, x, y, weapon); + } + } + return (malive); } /* hit target monster; returns TRUE if it still lives */ @@ -480,47 +493,47 @@ hitum(mon, uattk) struct monst *mon; struct attack *uattk; { - boolean malive, wep_was_destroyed = FALSE; - struct obj *wepbefore = uwep; - int armorpenalty, attknum = 0, - x = u.ux + u.dx, y = u.uy + u.dy, - tmp = find_roll_to_hit(mon, uattk->aatyp, uwep, - &attknum, &armorpenalty); - int mhit = (tmp > (dieroll = rnd(20)) || u.uswallow); + boolean malive, wep_was_destroyed = FALSE; + struct obj *wepbefore = uwep; + int armorpenalty, attknum = 0, x = u.ux + u.dx, y = u.uy + u.dy, + tmp = find_roll_to_hit(mon, uattk->aatyp, uwep, + &attknum, &armorpenalty); + int mhit = (tmp > (dieroll = rnd(20)) || u.uswallow); - if(tmp > dieroll) exercise(A_DEX, TRUE); - malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk); - /* second attack for two-weapon combat; won't occur if Stormbringer - overrode confirmation (assumes Stormbringer is primary weapon) - or if the monster was killed or knocked to different location */ - if (u.twoweap && !override_confirmation && - malive && m_at(x, y) == mon) { - tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, - &attknum, &armorpenalty); - mhit = (tmp > (dieroll = rnd(20)) || u.uswallow); - malive = known_hitum(mon, uswapwep, &mhit, - tmp, armorpenalty, uattk); - } - if (wepbefore && !uwep) wep_was_destroyed = TRUE; - (void) passive(mon, mhit, malive, AT_WEAP, wep_was_destroyed); - return(malive); + if (tmp > dieroll) + exercise(A_DEX, TRUE); + malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk); + /* second attack for two-weapon combat; won't occur if Stormbringer + overrode confirmation (assumes Stormbringer is primary weapon) + or if the monster was killed or knocked to different location */ + if (u.twoweap && !override_confirmation && malive && m_at(x, y) == mon) { + tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum, + &armorpenalty); + mhit = (tmp > (dieroll = rnd(20)) || u.uswallow); + malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk); + } + if (wepbefore && !uwep) + wep_was_destroyed = TRUE; + (void) passive(mon, mhit, malive, AT_WEAP, wep_was_destroyed); + return (malive); } -boolean /* general "damage monster" routine */ -hmon(mon, obj, thrown) /* return TRUE if mon still alive */ +boolean /* general "damage monster" routine */ + hmon(mon, obj, thrown) /* return TRUE if mon still alive */ struct monst *mon; struct obj *obj; -int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ +int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ { - boolean result, anger_guards; + boolean result, anger_guards; - anger_guards = (mon->mpeaceful && - (mon->ispriest || mon->isshk || - is_watch(mon->data))); - result = hmon_hitmon(mon, obj, thrown); - if (mon->ispriest && !rn2(2)) ghod_hitsu(mon); - if (anger_guards) (void)angry_guards(!!Deaf); - return result; + anger_guards = (mon->mpeaceful + && (mon->ispriest || mon->isshk || is_watch(mon->data))); + result = hmon_hitmon(mon, obj, thrown); + if (mon->ispriest && !rn2(2)) + ghod_hitsu(mon); + if (anger_guards) + (void) angry_guards(!!Deaf); + return result; } /* guts of hmon() */ @@ -528,603 +541,642 @@ STATIC_OVL boolean hmon_hitmon(mon, obj, thrown) struct monst *mon; struct obj *obj; -int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ +int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ { - int tmp; - struct permonst *mdat = mon->data; - int barehand_silver_rings = 0; - /* The basic reason we need all these booleans is that we don't want - * a "hit" message when a monster dies, so we have to know how much - * damage it did _before_ outputting a hit message, but any messages - * associated with the damage don't come out until _after_ outputting - * a hit message. - */ - boolean hittxt = FALSE, destroyed = FALSE, already_killed = FALSE; - boolean get_dmg_bonus = TRUE; - boolean ispoisoned = FALSE, needpoismsg = FALSE, poiskilled = FALSE, - unpoisonmsg = FALSE; - boolean silvermsg = FALSE, silverobj = FALSE; - boolean valid_weapon_attack = FALSE; - boolean unarmed = !uwep && !uarm && !uarms; - boolean hand_to_hand = (thrown == HMON_MELEE || - /* not grapnels; applied implies uwep */ - (thrown == HMON_APPLIED && is_pole(uwep))); - int jousting = 0; - int wtype; - struct obj *monwep; - char unconventional[BUFSZ]; /* substituted for word "attack" in msg */ - char saved_oname[BUFSZ]; + int tmp; + struct permonst *mdat = mon->data; + int barehand_silver_rings = 0; + /* The basic reason we need all these booleans is that we don't want + * a "hit" message when a monster dies, so we have to know how much + * damage it did _before_ outputting a hit message, but any messages + * associated with the damage don't come out until _after_ outputting + * a hit message. + */ + boolean hittxt = FALSE, destroyed = FALSE, already_killed = FALSE; + boolean get_dmg_bonus = TRUE; + boolean ispoisoned = FALSE, needpoismsg = FALSE, poiskilled = FALSE, + unpoisonmsg = FALSE; + boolean silvermsg = FALSE, silverobj = FALSE; + boolean valid_weapon_attack = FALSE; + boolean unarmed = !uwep && !uarm && !uarms; + boolean hand_to_hand = (thrown == HMON_MELEE || + /* not grapnels; applied implies uwep */ + (thrown == HMON_APPLIED && is_pole(uwep))); + int jousting = 0; + int wtype; + struct obj *monwep; + char unconventional[BUFSZ]; /* substituted for word "attack" in msg */ + char saved_oname[BUFSZ]; - unconventional[0] = '\0'; - saved_oname[0] = '\0'; + unconventional[0] = '\0'; + saved_oname[0] = '\0'; - wakeup(mon); - if(!obj) { /* attack with bare hands */ - if (mdat == &mons[PM_SHADE]) - tmp = 0; - else if (martial_bonus()) - tmp = rnd(4); /* bonus for martial arts */ - else - tmp = rnd(2); - valid_weapon_attack = (tmp > 1); - /* blessed gloves give bonuses when fighting 'bare-handed' */ - if (uarmg && uarmg->blessed && - (is_undead(mdat) || is_demon(mdat) || is_vampshifter(mon))) - tmp += rnd(4); - /* So do silver rings. Note: rings are worn under gloves, so you - * don't get both bonuses. - */ - if (!uarmg) { - if (uleft && objects[uleft->otyp].oc_material == SILVER) - barehand_silver_rings++; - if (uright && objects[uright->otyp].oc_material == SILVER) - barehand_silver_rings++; - if (barehand_silver_rings && mon_hates_silver(mon)) { - tmp += rnd(20); - silvermsg = TRUE; - } - } - } else { - Strcpy(saved_oname, cxname(obj)); - if(obj->oclass == WEAPON_CLASS || is_weptool(obj) || - obj->oclass == GEM_CLASS) { + wakeup(mon); + if (!obj) { /* attack with bare hands */ + if (mdat == &mons[PM_SHADE]) + tmp = 0; + else if (martial_bonus()) + tmp = rnd(4); /* bonus for martial arts */ + else + tmp = rnd(2); + valid_weapon_attack = (tmp > 1); + /* blessed gloves give bonuses when fighting 'bare-handed' */ + if (uarmg && uarmg->blessed + && (is_undead(mdat) || is_demon(mdat) || is_vampshifter(mon))) + tmp += rnd(4); + /* So do silver rings. Note: rings are worn under gloves, so you + * don't get both bonuses. + */ + if (!uarmg) { + if (uleft && objects[uleft->otyp].oc_material == SILVER) + barehand_silver_rings++; + if (uright && objects[uright->otyp].oc_material == SILVER) + barehand_silver_rings++; + if (barehand_silver_rings && mon_hates_silver(mon)) { + tmp += rnd(20); + silvermsg = TRUE; + } + } + } else { + Strcpy(saved_oname, cxname(obj)); + if (obj->oclass == WEAPON_CLASS || is_weptool(obj) + || obj->oclass == GEM_CLASS) { + /* is it not a melee weapon? */ + if (/* if you strike with a bow... */ + is_launcher(obj) || + /* or strike with a missile in your hand... */ + (!thrown && (is_missile(obj) || is_ammo(obj))) || + /* or use a pole at short range and not mounted... */ + (!thrown && !u.usteed && is_pole(obj)) || + /* or throw a missile without the proper bow... */ + (is_ammo(obj) && (thrown != HMON_THROWN + || !ammo_and_launcher(obj, uwep)))) { + /* then do only 1-2 points of damage */ + if (mdat == &mons[PM_SHADE] && !shade_glare(obj)) + tmp = 0; + else + tmp = rnd(2); + if (objects[obj->otyp].oc_material == SILVER + && mon_hates_silver(mon)) { + silvermsg = TRUE; + silverobj = TRUE; + /* if it will already inflict dmg, make it worse */ + tmp += rnd((tmp) ? 20 : 10); + } + if (!thrown && obj == uwep && obj->otyp == BOOMERANG + && rnl(4) == 4 - 1) { + boolean more_than_1 = (obj->quan > 1L); - /* is it not a melee weapon? */ - if (/* if you strike with a bow... */ - is_launcher(obj) || - /* or strike with a missile in your hand... */ - (!thrown && (is_missile(obj) || is_ammo(obj))) || - /* or use a pole at short range and not mounted... */ - (!thrown && !u.usteed && is_pole(obj)) || - /* or throw a missile without the proper bow... */ - (is_ammo(obj) && (thrown != HMON_THROWN || - !ammo_and_launcher(obj, uwep)))) { - /* then do only 1-2 points of damage */ - if (mdat == &mons[PM_SHADE] && !shade_glare(obj)) - tmp = 0; - else - tmp = rnd(2); - if (objects[obj->otyp].oc_material == SILVER - && mon_hates_silver(mon)) { - silvermsg = TRUE; silverobj = TRUE; - /* if it will already inflict dmg, make it worse */ - tmp += rnd((tmp) ? 20 : 10); - } - if (!thrown && obj == uwep && obj->otyp == BOOMERANG && - rnl(4) == 4-1) { - boolean more_than_1 = (obj->quan > 1L); + pline("As you hit %s, %s%s breaks into splinters.", + mon_nam(mon), more_than_1 ? "one of " : "", + yname(obj)); + if (!more_than_1) + uwepgone(); /* set unweapon */ + useup(obj); + if (!more_than_1) + obj = (struct obj *) 0; + hittxt = TRUE; + if (mdat != &mons[PM_SHADE]) + tmp++; + } + } else { + tmp = dmgval(obj, mon); + /* a minimal hit doesn't exercise proficiency */ + valid_weapon_attack = (tmp > 1); + if (!valid_weapon_attack || mon == u.ustuck || u.twoweap) { + ; /* no special bonuses */ + } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd && + /* multi-shot throwing is too powerful here */ + hand_to_hand) { + You("strike %s from behind!", mon_nam(mon)); + tmp += rnd(u.ulevel); + hittxt = TRUE; + } else if (dieroll == 2 && obj == uwep + && obj->oclass == WEAPON_CLASS + && (bimanual(obj) + || (Role_if(PM_SAMURAI) && obj->otyp == KATANA + && !uarms)) + && ((wtype = uwep_skill_type()) != P_NONE + && P_SKILL(wtype) >= P_SKILLED) + && ((monwep = MON_WEP(mon)) != 0 + && !is_flimsy(monwep) + && !obj_resists( + monwep, 50 + 15 * greatest_erosion(obj), + 100))) { + /* + * 2.5% chance of shattering defender's weapon when + * using a two-handed weapon; less if uwep is rusted. + * [dieroll == 2 is most successful non-beheading or + * -bisecting hit, in case of special artifact damage; + * the percentage chance is (1/20)*(50/100).] + */ + setmnotwielded(mon, monwep); + MON_NOWEP(mon); + mon->weapon_check = NEED_WEAPON; + pline("%s from the force of your blow!", + Yobjnam2(monwep, "shatter")); + m_useupall(mon, monwep); + /* If someone just shattered MY weapon, I'd flee! */ + if (rn2(4)) { + monflee(mon, d(2, 3), TRUE, TRUE); + } + hittxt = TRUE; + } - pline("As you hit %s, %s%s breaks into splinters.", - mon_nam(mon), more_than_1 ? "one of " : "", - yname(obj)); - if (!more_than_1) uwepgone(); /* set unweapon */ - useup(obj); - if (!more_than_1) obj = (struct obj *) 0; - hittxt = TRUE; - if (mdat != &mons[PM_SHADE]) - tmp++; - } - } else { - tmp = dmgval(obj, mon); - /* a minimal hit doesn't exercise proficiency */ - valid_weapon_attack = (tmp > 1); - if (!valid_weapon_attack || mon == u.ustuck || u.twoweap) { - ; /* no special bonuses */ - } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd && - /* multi-shot throwing is too powerful here */ - hand_to_hand) { - You("strike %s from behind!", mon_nam(mon)); - tmp += rnd(u.ulevel); - hittxt = TRUE; - } else if (dieroll == 2 && obj == uwep && - obj->oclass == WEAPON_CLASS && - (bimanual(obj) || - (Role_if(PM_SAMURAI) && obj->otyp == KATANA && !uarms)) && - ((wtype = uwep_skill_type()) != P_NONE && - P_SKILL(wtype) >= P_SKILLED) && - ((monwep = MON_WEP(mon)) != 0 && - !is_flimsy(monwep) && - !obj_resists(monwep, - 50 + 15 * greatest_erosion(obj), 100))) { - /* - * 2.5% chance of shattering defender's weapon when - * using a two-handed weapon; less if uwep is rusted. - * [dieroll == 2 is most successful non-beheading or - * -bisecting hit, in case of special artifact damage; - * the percentage chance is (1/20)*(50/100).] - */ - setmnotwielded(mon,monwep); - MON_NOWEP(mon); - mon->weapon_check = NEED_WEAPON; - pline("%s from the force of your blow!", - Yobjnam2(monwep, "shatter")); - m_useupall(mon, monwep); - /* If someone just shattered MY weapon, I'd flee! */ - if (rn2(4)) { - monflee(mon, d(2,3), TRUE, TRUE); - } - hittxt = TRUE; - } - - if (obj->oartifact && - artifact_hit(&youmonst, mon, obj, &tmp, dieroll)) { - if(mon->mhp <= 0) /* artifact killed monster */ - return FALSE; - if (tmp == 0) return TRUE; - hittxt = TRUE; - } - if (objects[obj->otyp].oc_material == SILVER - && mon_hates_silver(mon)) { - silvermsg = TRUE; silverobj = TRUE; - } - if (u.usteed && !thrown && tmp > 0 && - weapon_type(obj) == P_LANCE && mon != u.ustuck) { - jousting = joust(mon, obj); - /* exercise skill even for minimal damage hits */ - if (jousting) valid_weapon_attack = TRUE; - } - if (thrown == HMON_THROWN && - (is_ammo(obj) || is_missile(obj))) { - if (ammo_and_launcher(obj, uwep)) { - /* Elves and Samurai do extra damage using - * their bows&arrows; they're highly trained. - */ - if (Role_if(PM_SAMURAI) && - obj->otyp == YA && uwep->otyp == YUMI) - tmp++; - else if (Race_if(PM_ELF) && - obj->otyp == ELVEN_ARROW && - uwep->otyp == ELVEN_BOW) - tmp++; - } - if(obj->opoisoned && is_poisonable(obj)) - ispoisoned = TRUE; - } - } - } else if(obj->oclass == POTION_CLASS) { - if (obj->quan > 1L) - obj = splitobj(obj, 1L); - else - setuwep((struct obj *)0); - freeinv(obj); - potionhit(mon, obj, TRUE); - if (mon->mhp <= 0) return FALSE; /* killed */ - hittxt = TRUE; - /* in case potion effect causes transformation */ - mdat = mon->data; - tmp = (mdat == &mons[PM_SHADE]) ? 0 : 1; - } else { - if (mdat == &mons[PM_SHADE] && !shade_aware(obj)) { - tmp = 0; - Strcpy(unconventional, cxname(obj)); - } else { - switch(obj->otyp) { - case BOULDER: /* 1d20 */ - case HEAVY_IRON_BALL: /* 1d25 */ - case IRON_CHAIN: /* 1d4+1 */ - tmp = dmgval(obj, mon); - break; - case MIRROR: - if (breaktest(obj)) { - You("break %s. That's bad luck!", - ysimple_name(obj)); - change_luck(-2); - useup(obj); - obj = (struct obj *) 0; - unarmed = FALSE; /* avoid obj==0 confusion */ - get_dmg_bonus = FALSE; - hittxt = TRUE; - } - tmp = 1; - break; - case EXPENSIVE_CAMERA: - You("succeed in destroying %s. Congratulations!", - ysimple_name(obj)); - release_camera_demon(obj, u.ux, u.uy); - useup(obj); - return(TRUE); - /*NOTREACHED*/ - break; - case CORPSE: /* fixed by polder@cs.vu.nl */ - if (touch_petrifies(&mons[obj->corpsenm])) { - tmp = 1; - hittxt = TRUE; - You("hit %s with %s.", mon_nam(mon), - corpse_xname(obj, (const char *)0, - obj->dknown ? CXN_PFX_THE : CXN_ARTICLE)); - obj->dknown = 1; - if (!munstone(mon, TRUE)) - minstapetrify(mon, TRUE); - if (resists_ston(mon)) break; - /* note: hp may be <= 0 even if munstoned==TRUE */ - return (boolean) (mon->mhp > 0); + if (obj->oartifact + && artifact_hit(&youmonst, mon, obj, &tmp, dieroll)) { + if (mon->mhp <= 0) /* artifact killed monster */ + return FALSE; + if (tmp == 0) + return TRUE; + hittxt = TRUE; + } + if (objects[obj->otyp].oc_material == SILVER + && mon_hates_silver(mon)) { + silvermsg = TRUE; + silverobj = TRUE; + } + if (u.usteed && !thrown && tmp > 0 + && weapon_type(obj) == P_LANCE && mon != u.ustuck) { + jousting = joust(mon, obj); + /* exercise skill even for minimal damage hits */ + if (jousting) + valid_weapon_attack = TRUE; + } + if (thrown == HMON_THROWN + && (is_ammo(obj) || is_missile(obj))) { + if (ammo_and_launcher(obj, uwep)) { + /* Elves and Samurai do extra damage using + * their bows&arrows; they're highly trained. + */ + if (Role_if(PM_SAMURAI) && obj->otyp == YA + && uwep->otyp == YUMI) + tmp++; + else if (Race_if(PM_ELF) && obj->otyp == ELVEN_ARROW + && uwep->otyp == ELVEN_BOW) + tmp++; + } + if (obj->opoisoned && is_poisonable(obj)) + ispoisoned = TRUE; + } + } + } else if (obj->oclass == POTION_CLASS) { + if (obj->quan > 1L) + obj = splitobj(obj, 1L); + else + setuwep((struct obj *) 0); + freeinv(obj); + potionhit(mon, obj, TRUE); + if (mon->mhp <= 0) + return FALSE; /* killed */ + hittxt = TRUE; + /* in case potion effect causes transformation */ + mdat = mon->data; + tmp = (mdat == &mons[PM_SHADE]) ? 0 : 1; + } else { + if (mdat == &mons[PM_SHADE] && !shade_aware(obj)) { + tmp = 0; + Strcpy(unconventional, cxname(obj)); + } else { + switch (obj->otyp) { + case BOULDER: /* 1d20 */ + case HEAVY_IRON_BALL: /* 1d25 */ + case IRON_CHAIN: /* 1d4+1 */ + tmp = dmgval(obj, mon); + break; + case MIRROR: + if (breaktest(obj)) { + You("break %s. That's bad luck!", ysimple_name(obj)); + change_luck(-2); + useup(obj); + obj = (struct obj *) 0; + unarmed = FALSE; /* avoid obj==0 confusion */ + get_dmg_bonus = FALSE; + hittxt = TRUE; + } + tmp = 1; + break; + case EXPENSIVE_CAMERA: + You("succeed in destroying %s. Congratulations!", + ysimple_name(obj)); + release_camera_demon(obj, u.ux, u.uy); + useup(obj); + return (TRUE); + /*NOTREACHED*/ + break; + case CORPSE: /* fixed by polder@cs.vu.nl */ + if (touch_petrifies(&mons[obj->corpsenm])) { + tmp = 1; + hittxt = TRUE; + You("hit %s with %s.", mon_nam(mon), + corpse_xname(obj, (const char *) 0, + obj->dknown ? CXN_PFX_THE + : CXN_ARTICLE)); + obj->dknown = 1; + if (!munstone(mon, TRUE)) + minstapetrify(mon, TRUE); + if (resists_ston(mon)) + break; + /* note: hp may be <= 0 even if munstoned==TRUE */ + return (boolean)(mon->mhp > 0); #if 0 } else if (touch_petrifies(mdat)) { /* maybe turn the corpse into a statue? */ #endif - } - tmp = (obj->corpsenm >= LOW_PM ? - mons[obj->corpsenm].msize : 0) + 1; - break; - case EGG: - { -#define useup_eggs(o) { if (thrown) obfree(o,(struct obj *)0); \ - else useupall(o); \ - o = (struct obj *)0; } /* now gone */ - long cnt = obj->quan; + } + tmp = (obj->corpsenm >= LOW_PM ? mons[obj->corpsenm].msize + : 0) + 1; + break; + case EGG: { +#define useup_eggs(o) \ + { \ + if (thrown) \ + obfree(o, (struct obj *) 0); \ + else \ + useupall(o); \ + o = (struct obj *) 0; \ + } /* now gone */ + long cnt = obj->quan; - tmp = 1; /* nominal physical damage */ - get_dmg_bonus = FALSE; - hittxt = TRUE; /* message always given */ - /* egg is always either used up or transformed, so next - hand-to-hand attack should yield a "bashing" mesg */ - if (obj == uwep) unweapon = TRUE; - if (obj->spe && obj->corpsenm >= LOW_PM) { - if (obj->quan < 5L) - change_luck((schar) -(obj->quan)); - else - change_luck(-5); - } + tmp = 1; /* nominal physical damage */ + get_dmg_bonus = FALSE; + hittxt = TRUE; /* message always given */ + /* egg is always either used up or transformed, so next + hand-to-hand attack should yield a "bashing" mesg */ + if (obj == uwep) + unweapon = TRUE; + if (obj->spe && obj->corpsenm >= LOW_PM) { + if (obj->quan < 5L) + change_luck((schar) - (obj->quan)); + else + change_luck(-5); + } - if (touch_petrifies(&mons[obj->corpsenm])) { - /*learn_egg_type(obj->corpsenm);*/ - pline("Splat! You hit %s with %s %s egg%s!", - mon_nam(mon), - obj->known ? "the" : cnt > 1L ? "some" : "a", - obj->known ? mons[obj->corpsenm].mname : "petrifying", - plur(cnt)); - obj->known = 1; /* (not much point...) */ - useup_eggs(obj); - if (!munstone(mon, TRUE)) - minstapetrify(mon, TRUE); - if (resists_ston(mon)) break; - return (boolean) (mon->mhp > 0); - } else { /* ordinary egg(s) */ - const char *eggp = - (obj->corpsenm != NON_PM && obj->known) ? - the(mons[obj->corpsenm].mname) : - (cnt > 1L) ? "some" : "an"; - You("hit %s with %s egg%s.", - mon_nam(mon), eggp, plur(cnt)); - if (touch_petrifies(mdat) && !stale_egg(obj)) { - pline_The("egg%s %s alive any more...", - plur(cnt), - (cnt == 1L) ? "isn't" : "aren't"); - if (obj->timed) obj_stop_timers(obj); - obj->otyp = ROCK; - obj->oclass = GEM_CLASS; - obj->oartifact = 0; - obj->spe = 0; - obj->known = obj->dknown = obj->bknown = 0; - obj->owt = weight(obj); - if (thrown) place_object(obj, mon->mx, mon->my); - } else { - pline("Splat!"); - useup_eggs(obj); - exercise(A_WIS, FALSE); - } - } - break; + if (touch_petrifies(&mons[obj->corpsenm])) { + /*learn_egg_type(obj->corpsenm);*/ + pline("Splat! You hit %s with %s %s egg%s!", + mon_nam(mon), + obj->known ? "the" : cnt > 1L ? "some" : "a", + obj->known ? mons[obj->corpsenm].mname + : "petrifying", + plur(cnt)); + obj->known = 1; /* (not much point...) */ + useup_eggs(obj); + if (!munstone(mon, TRUE)) + minstapetrify(mon, TRUE); + if (resists_ston(mon)) + break; + return (boolean)(mon->mhp > 0); + } else { /* ordinary egg(s) */ + const char *eggp = + (obj->corpsenm != NON_PM && obj->known) + ? the(mons[obj->corpsenm].mname) + : (cnt > 1L) ? "some" : "an"; + You("hit %s with %s egg%s.", mon_nam(mon), eggp, + plur(cnt)); + if (touch_petrifies(mdat) && !stale_egg(obj)) { + pline_The("egg%s %s alive any more...", plur(cnt), + (cnt == 1L) ? "isn't" : "aren't"); + if (obj->timed) + obj_stop_timers(obj); + obj->otyp = ROCK; + obj->oclass = GEM_CLASS; + obj->oartifact = 0; + obj->spe = 0; + obj->known = obj->dknown = obj->bknown = 0; + obj->owt = weight(obj); + if (thrown) + place_object(obj, mon->mx, mon->my); + } else { + pline("Splat!"); + useup_eggs(obj); + exercise(A_WIS, FALSE); + } + } + break; #undef useup_eggs - } - case CLOVE_OF_GARLIC: /* no effect against demons */ - if (is_undead(mdat) || is_vampshifter(mon)) { - monflee(mon, d(2, 4), FALSE, TRUE); - } - tmp = 1; - break; - case CREAM_PIE: - case BLINDING_VENOM: - mon->msleeping = 0; - if (can_blnd(&youmonst, mon, (uchar) - (obj->otyp == BLINDING_VENOM - ? AT_SPIT : AT_WEAP), obj)) { - if (Blind) { - pline(obj->otyp == CREAM_PIE ? - "Splat!" : "Splash!"); - } else if (obj->otyp == BLINDING_VENOM) { - pline_The("venom blinds %s%s!", mon_nam(mon), - mon->mcansee ? "" : " further"); - } else { - char *whom = mon_nam(mon); - char *what = The(xname(obj)); - if (!thrown && obj->quan > 1L) - what = An(singular(obj, xname)); - /* note: s_suffix returns a modifiable buffer */ - if (haseyes(mdat) - && mdat != &mons[PM_FLOATING_EYE]) - whom = strcat(strcat(s_suffix(whom), " "), - mbodypart(mon, FACE)); - pline("%s %s over %s!", - what, vtense(what, "splash"), whom); - } - setmangry(mon); - mon->mcansee = 0; - tmp = rn1(25, 21); - if(((int) mon->mblinded + tmp) > 127) - mon->mblinded = 127; - else mon->mblinded += tmp; - } else { - pline(obj->otyp==CREAM_PIE ? "Splat!" : "Splash!"); - setmangry(mon); - } - if (thrown) obfree(obj, (struct obj *)0); - else useup(obj); - hittxt = TRUE; - get_dmg_bonus = FALSE; - tmp = 0; - break; - case ACID_VENOM: /* thrown (or spit) */ - if (resists_acid(mon)) { - Your("venom hits %s harmlessly.", - mon_nam(mon)); - tmp = 0; - } else { - Your("venom burns %s!", mon_nam(mon)); - tmp = dmgval(obj, mon); - } - if (thrown) obfree(obj, (struct obj *)0); - else useup(obj); - hittxt = TRUE; - get_dmg_bonus = FALSE; - break; - default: - /* non-weapons can damage because of their weight */ - /* (but not too much) */ - tmp = obj->owt/100; - if(tmp < 1) tmp = 1; - else tmp = rnd(tmp); - if(tmp > 6) tmp = 6; - /* - * Things like silver wands can arrive here so - * so we need another silver check. - */ - if (objects[obj->otyp].oc_material == SILVER - && mon_hates_silver(mon)) { - tmp += rnd(20); - silvermsg = TRUE; silverobj = TRUE; - } - } - } - } - } + } + case CLOVE_OF_GARLIC: /* no effect against demons */ + if (is_undead(mdat) || is_vampshifter(mon)) { + monflee(mon, d(2, 4), FALSE, TRUE); + } + tmp = 1; + break; + case CREAM_PIE: + case BLINDING_VENOM: + mon->msleeping = 0; + if (can_blnd(&youmonst, mon, + (uchar)(obj->otyp == BLINDING_VENOM + ? AT_SPIT + : AT_WEAP), + obj)) { + if (Blind) { + pline(obj->otyp == CREAM_PIE ? "Splat!" + : "Splash!"); + } else if (obj->otyp == BLINDING_VENOM) { + pline_The("venom blinds %s%s!", mon_nam(mon), + mon->mcansee ? "" : " further"); + } else { + char *whom = mon_nam(mon); + char *what = The(xname(obj)); + if (!thrown && obj->quan > 1L) + what = An(singular(obj, xname)); + /* note: s_suffix returns a modifiable buffer */ + if (haseyes(mdat) + && mdat != &mons[PM_FLOATING_EYE]) + whom = strcat(strcat(s_suffix(whom), " "), + mbodypart(mon, FACE)); + pline("%s %s over %s!", what, + vtense(what, "splash"), whom); + } + setmangry(mon); + mon->mcansee = 0; + tmp = rn1(25, 21); + if (((int) mon->mblinded + tmp) > 127) + mon->mblinded = 127; + else + mon->mblinded += tmp; + } else { + pline(obj->otyp == CREAM_PIE ? "Splat!" : "Splash!"); + setmangry(mon); + } + if (thrown) + obfree(obj, (struct obj *) 0); + else + useup(obj); + hittxt = TRUE; + get_dmg_bonus = FALSE; + tmp = 0; + break; + case ACID_VENOM: /* thrown (or spit) */ + if (resists_acid(mon)) { + Your("venom hits %s harmlessly.", mon_nam(mon)); + tmp = 0; + } else { + Your("venom burns %s!", mon_nam(mon)); + tmp = dmgval(obj, mon); + } + if (thrown) + obfree(obj, (struct obj *) 0); + else + useup(obj); + hittxt = TRUE; + get_dmg_bonus = FALSE; + break; + default: + /* non-weapons can damage because of their weight */ + /* (but not too much) */ + tmp = obj->owt / 100; + if (tmp < 1) + tmp = 1; + else + tmp = rnd(tmp); + if (tmp > 6) + tmp = 6; + /* + * Things like silver wands can arrive here so + * so we need another silver check. + */ + if (objects[obj->otyp].oc_material == SILVER + && mon_hates_silver(mon)) { + tmp += rnd(20); + silvermsg = TRUE; + silverobj = TRUE; + } + } + } + } + } - /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) - * *OR* if attacking bare-handed!! */ + /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) + * *OR* if attacking bare-handed!! */ - if (get_dmg_bonus && tmp > 0) { - tmp += u.udaminc; - /* If you throw using a propellor, you don't get a strength - * bonus but you do get an increase-damage bonus. - */ - if (thrown != HMON_THROWN || !obj || !uwep || - !ammo_and_launcher(obj, uwep)) - tmp += dbon(); - } + if (get_dmg_bonus && tmp > 0) { + tmp += u.udaminc; + /* If you throw using a propellor, you don't get a strength + * bonus but you do get an increase-damage bonus. + */ + if (thrown != HMON_THROWN || !obj || !uwep + || !ammo_and_launcher(obj, uwep)) + tmp += dbon(); + } - if (valid_weapon_attack) { - struct obj *wep; + if (valid_weapon_attack) { + struct obj *wep; - /* to be valid a projectile must have had the correct projector */ - wep = PROJECTILE(obj) ? uwep : obj; - tmp += weapon_dam_bonus(wep); - /* [this assumes that `!thrown' implies wielded...] */ - wtype = thrown ? weapon_type(wep) : uwep_skill_type(); - use_skill(wtype, 1); - } + /* to be valid a projectile must have had the correct projector */ + wep = PROJECTILE(obj) ? uwep : obj; + tmp += weapon_dam_bonus(wep); + /* [this assumes that `!thrown' implies wielded...] */ + wtype = thrown ? weapon_type(wep) : uwep_skill_type(); + use_skill(wtype, 1); + } - if (ispoisoned) { - int nopoison = (10 - (obj->owt/10)); - if(nopoison < 2) nopoison = 2; - if Role_if(PM_SAMURAI) { - You("dishonorably use a poisoned weapon!"); - adjalign(-sgn(u.ualign.type)); - } else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) { - You_feel("like an evil coward for using a poisoned weapon."); - adjalign(-1); - } - if (obj && !rn2(nopoison)) { - /* remove poison now in case obj ends up in a bones file */ - obj->opoisoned = FALSE; - /* defer "obj is no longer poisoned" until after hit message */ - unpoisonmsg = TRUE; - } - if (resists_poison(mon)) - needpoismsg = TRUE; - else if (rn2(10)) - tmp += rnd(6); - else poiskilled = TRUE; - } - if (tmp < 1) { - /* make sure that negative damage adjustment can't result - in inadvertently boosting the victim's hit points */ - tmp = 0; - if (mdat == &mons[PM_SHADE]) { - if (!hittxt) { - const char *what = unconventional[0] ? unconventional : "attack"; - Your("%s %s harmlessly through %s.", - what, vtense(what, "pass"), - mon_nam(mon)); - hittxt = TRUE; - } - } else { - if (get_dmg_bonus) tmp = 1; - } - } + if (ispoisoned) { + int nopoison = (10 - (obj->owt / 10)); + if (nopoison < 2) + nopoison = 2; + if + Role_if(PM_SAMURAI) + { + You("dishonorably use a poisoned weapon!"); + adjalign(-sgn(u.ualign.type)); + } + else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) { + You_feel("like an evil coward for using a poisoned weapon."); + adjalign(-1); + } + if (obj && !rn2(nopoison)) { + /* remove poison now in case obj ends up in a bones file */ + obj->opoisoned = FALSE; + /* defer "obj is no longer poisoned" until after hit message */ + unpoisonmsg = TRUE; + } + if (resists_poison(mon)) + needpoismsg = TRUE; + else if (rn2(10)) + tmp += rnd(6); + else + poiskilled = TRUE; + } + if (tmp < 1) { + /* make sure that negative damage adjustment can't result + in inadvertently boosting the victim's hit points */ + tmp = 0; + if (mdat == &mons[PM_SHADE]) { + if (!hittxt) { + const char *what = + unconventional[0] ? unconventional : "attack"; + Your("%s %s harmlessly through %s.", what, + vtense(what, "pass"), mon_nam(mon)); + hittxt = TRUE; + } + } else { + if (get_dmg_bonus) + tmp = 1; + } + } - if (jousting) { - tmp += d(2, (obj == uwep) ? 10 : 2); /* [was in dmgval()] */ - You("joust %s%s", - mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); - if (jousting < 0) { - pline("%s shatters on impact!", Yname2(obj)); - /* (must be either primary or secondary weapon to get here) */ - u.twoweap = FALSE; /* untwoweapon() is too verbose here */ - if (obj == uwep) uwepgone(); /* set unweapon */ - /* minor side-effect: broken lance won't split puddings */ - useup(obj); - obj = 0; - } - /* avoid migrating a dead monster */ - if (mon->mhp > tmp) { - mhurtle(mon, u.dx, u.dy, 1); - mdat = mon->data; /* in case of a polymorph trap */ - if (DEADMONSTER(mon)) already_killed = TRUE; - } - hittxt = TRUE; - } else if (unarmed && tmp > 1 && !thrown && !obj && !Upolyd) { + if (jousting) { + tmp += d(2, (obj == uwep) ? 10 : 2); /* [was in dmgval()] */ + You("joust %s%s", mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); + if (jousting < 0) { + pline("%s shatters on impact!", Yname2(obj)); + /* (must be either primary or secondary weapon to get here) */ + u.twoweap = FALSE; /* untwoweapon() is too verbose here */ + if (obj == uwep) + uwepgone(); /* set unweapon */ + /* minor side-effect: broken lance won't split puddings */ + useup(obj); + obj = 0; + } + /* avoid migrating a dead monster */ + if (mon->mhp > tmp) { + mhurtle(mon, u.dx, u.dy, 1); + mdat = mon->data; /* in case of a polymorph trap */ + if (DEADMONSTER(mon)) + already_killed = TRUE; + } + hittxt = TRUE; + } else if (unarmed && tmp > 1 && !thrown && !obj && !Upolyd) { /* VERY small chance of stunning opponent if unarmed. */ - if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) && - !bigmonst(mdat) && !thick_skinned(mdat)) { - if (canspotmon(mon)) - pline("%s %s from your powerful strike!", Monnam(mon), - makeplural(stagger(mon->data, "stagger"))); - /* avoid migrating a dead monster */ - if (mon->mhp > tmp) { - mhurtle(mon, u.dx, u.dy, 1); - mdat = mon->data; /* in case of a polymorph trap */ - if (DEADMONSTER(mon)) already_killed = TRUE; - } - hittxt = TRUE; - } - } + if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) && !bigmonst(mdat) + && !thick_skinned(mdat)) { + if (canspotmon(mon)) + pline("%s %s from your powerful strike!", Monnam(mon), + makeplural(stagger(mon->data, "stagger"))); + /* avoid migrating a dead monster */ + if (mon->mhp > tmp) { + mhurtle(mon, u.dx, u.dy, 1); + mdat = mon->data; /* in case of a polymorph trap */ + if (DEADMONSTER(mon)) + already_killed = TRUE; + } + hittxt = TRUE; + } + } - if (!already_killed) mon->mhp -= tmp; - /* adjustments might have made tmp become less than what - a level draining artifact has already done to max HP */ - if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax; - if (mon->mhp < 1) - destroyed = TRUE; - if (mon->mtame && tmp > 0) { - /* do this even if the pet is being killed (affects revival) */ - abuse_dog(mon); /* reduces tameness */ - /* flee if still alive and still tame; if already suffering from - untimed fleeing, no effect, otherwise increases timed fleeing */ - if (mon->mtame && !destroyed) - monflee(mon, 10 * rnd(tmp), FALSE, FALSE); - } - if ((mdat == &mons[PM_BLACK_PUDDING] || - mdat == &mons[PM_BROWN_PUDDING]) && - /* pudding is alive and healthy enough to split */ - mon->mhp > 1 && !mon->mcan && - /* iron weapon using melee or polearm hit */ - obj && obj == uwep && - objects[obj->otyp].oc_material == IRON && - hand_to_hand) { - if (clone_mon(mon, 0, 0)) { - pline("%s divides as you hit it!", Monnam(mon)); - hittxt = TRUE; - } - } + if (!already_killed) + mon->mhp -= tmp; + /* adjustments might have made tmp become less than what + a level draining artifact has already done to max HP */ + if (mon->mhp > mon->mhpmax) + mon->mhp = mon->mhpmax; + if (mon->mhp < 1) + destroyed = TRUE; + if (mon->mtame && tmp > 0) { + /* do this even if the pet is being killed (affects revival) */ + abuse_dog(mon); /* reduces tameness */ + /* flee if still alive and still tame; if already suffering from + untimed fleeing, no effect, otherwise increases timed fleeing */ + if (mon->mtame && !destroyed) + monflee(mon, 10 * rnd(tmp), FALSE, FALSE); + } + if ((mdat == &mons[PM_BLACK_PUDDING] || mdat == &mons[PM_BROWN_PUDDING]) + && + /* pudding is alive and healthy enough to split */ + mon->mhp > 1 && !mon->mcan && + /* iron weapon using melee or polearm hit */ + obj && obj == uwep && objects[obj->otyp].oc_material == IRON + && hand_to_hand) { + if (clone_mon(mon, 0, 0)) { + pline("%s divides as you hit it!", Monnam(mon)); + hittxt = TRUE; + } + } - if (!hittxt && /*( thrown => obj exists )*/ - (!destroyed || (thrown && m_shot.n > 1 && m_shot.o == obj->otyp))) { - if (thrown) hit(mshot_xname(obj), mon, exclam(tmp)); - else if (!flags.verbose) You("hit it."); - else You("%s %s%s", Role_if(PM_BARBARIAN) ? "smite" : "hit", - mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); - } + if (!hittxt && /*( thrown => obj exists )*/ + (!destroyed || (thrown && m_shot.n > 1 && m_shot.o == obj->otyp))) { + if (thrown) + hit(mshot_xname(obj), mon, exclam(tmp)); + else if (!flags.verbose) + You("hit it."); + else + You("%s %s%s", Role_if(PM_BARBARIAN) ? "smite" : "hit", + mon_nam(mon), canseemon(mon) ? exclam(tmp) : "."); + } - if (silvermsg) { - const char *fmt; - char *whom = mon_nam(mon); - char silverobjbuf[BUFSZ]; + if (silvermsg) { + const char *fmt; + char *whom = mon_nam(mon); + char silverobjbuf[BUFSZ]; - if (canspotmon(mon)) { - if (barehand_silver_rings == 1) - fmt = "Your silver ring sears %s!"; - else if (barehand_silver_rings == 2) - fmt = "Your silver rings sear %s!"; - else if (silverobj && saved_oname[0]) { - Sprintf(silverobjbuf, "Your %s%s %s %%s!", - strstri(saved_oname, "silver") ? - "" : "silver ", - saved_oname, vtense(saved_oname, "sear")); - fmt = silverobjbuf; - } else - fmt = "The silver sears %s!"; - } else { - *whom = highc(*whom); /* "it" -> "It" */ - fmt = "%s is seared!"; - } - /* note: s_suffix returns a modifiable buffer */ - if (!noncorporeal(mdat) && !amorphous(mdat)) - whom = strcat(s_suffix(whom), " flesh"); - pline(fmt, whom); - } - /* if a "no longer poisoned" message is coming, it will be last; - obj->opoisoned was cleared above and any message referring to - "poisoned " has now been given; we want just "" for - last message, so reformat while obj is still accessible */ - if (unpoisonmsg) - Strcpy(saved_oname, cxname(obj)); + if (canspotmon(mon)) { + if (barehand_silver_rings == 1) + fmt = "Your silver ring sears %s!"; + else if (barehand_silver_rings == 2) + fmt = "Your silver rings sear %s!"; + else if (silverobj && saved_oname[0]) { + Sprintf(silverobjbuf, "Your %s%s %s %%s!", + strstri(saved_oname, "silver") ? "" : "silver ", + saved_oname, vtense(saved_oname, "sear")); + fmt = silverobjbuf; + } else + fmt = "The silver sears %s!"; + } else { + *whom = highc(*whom); /* "it" -> "It" */ + fmt = "%s is seared!"; + } + /* note: s_suffix returns a modifiable buffer */ + if (!noncorporeal(mdat) && !amorphous(mdat)) + whom = strcat(s_suffix(whom), " flesh"); + pline(fmt, whom); + } + /* if a "no longer poisoned" message is coming, it will be last; + obj->opoisoned was cleared above and any message referring to + "poisoned " has now been given; we want just "" for + last message, so reformat while obj is still accessible */ + if (unpoisonmsg) + Strcpy(saved_oname, cxname(obj)); - /* [note: thrown obj might go away during killed/xkilled call] */ + /* [note: thrown obj might go away during killed/xkilled call] */ - if (needpoismsg) - pline_The("poison doesn't seem to affect %s.", mon_nam(mon)); - if (poiskilled) { - pline_The("poison was deadly..."); - if (!already_killed) xkilled(mon, 0); - destroyed = TRUE; /* return FALSE; */ - } else if (destroyed) { - if (!already_killed) - killed(mon); /* takes care of most messages */ - } else if (u.umconf && hand_to_hand) { - nohandglow(mon); - if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) { - mon->mconf = 1; - if (!mon->mstun && mon->mcanmove && !mon->msleeping && - canseemon(mon)) - pline("%s appears confused.", Monnam(mon)); - } - } - if (unpoisonmsg) - Your("%s %s no longer poisoned.", saved_oname, - vtense(saved_oname, "are")); + if (needpoismsg) + pline_The("poison doesn't seem to affect %s.", mon_nam(mon)); + if (poiskilled) { + pline_The("poison was deadly..."); + if (!already_killed) + xkilled(mon, 0); + destroyed = TRUE; /* return FALSE; */ + } else if (destroyed) { + if (!already_killed) + killed(mon); /* takes care of most messages */ + } else if (u.umconf && hand_to_hand) { + nohandglow(mon); + if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) { + mon->mconf = 1; + if (!mon->mstun && mon->mcanmove && !mon->msleeping + && canseemon(mon)) + pline("%s appears confused.", Monnam(mon)); + } + } + if (unpoisonmsg) + Your("%s %s no longer poisoned.", saved_oname, + vtense(saved_oname, "are")); - return destroyed ? FALSE : TRUE; + return destroyed ? FALSE : TRUE; } STATIC_OVL boolean shade_aware(obj) struct obj *obj; { - if (!obj) return FALSE; - /* - * The things in this list either - * 1) affect shades. - * OR - * 2) are dealt with properly by other routines - * when it comes to shades. - */ - if (obj->otyp == BOULDER || obj->otyp == HEAVY_IRON_BALL - || obj->otyp == IRON_CHAIN /* dmgval handles those first three */ - || obj->otyp == MIRROR /* silver in the reflective surface */ - || obj->otyp == CLOVE_OF_GARLIC /* causes shades to flee */ - || objects[obj->otyp].oc_material == SILVER) - return TRUE; - return FALSE; + if (!obj) + return FALSE; + /* + * The things in this list either + * 1) affect shades. + * OR + * 2) are dealt with properly by other routines + * when it comes to shades. + */ + if (obj->otyp == BOULDER || obj->otyp == HEAVY_IRON_BALL + || obj->otyp == IRON_CHAIN /* dmgval handles those first three */ + || obj->otyp == MIRROR /* silver in the reflective surface */ + || obj->otyp == CLOVE_OF_GARLIC /* causes shades to flee */ + || objects[obj->otyp].oc_material == SILVER) + return TRUE; + return FALSE; } /* check whether slippery clothing protects from hug or wrap attack */ @@ -1134,100 +1186,106 @@ m_slips_free(mdef, mattk) struct monst *mdef; struct attack *mattk; { - struct obj *obj; + struct obj *obj; - if (mattk->adtyp == AD_DRIN) { - /* intelligence drain attacks the head */ - obj = which_armor(mdef, W_ARMH); - } else { - /* grabbing attacks the body */ - obj = which_armor(mdef, W_ARMC); /* cloak */ - if (!obj) obj = which_armor(mdef, W_ARM); /* suit */ - if (!obj) obj = which_armor(mdef, W_ARMU); /* shirt */ - } + if (mattk->adtyp == AD_DRIN) { + /* intelligence drain attacks the head */ + obj = which_armor(mdef, W_ARMH); + } else { + /* grabbing attacks the body */ + obj = which_armor(mdef, W_ARMC); /* cloak */ + if (!obj) + obj = which_armor(mdef, W_ARM); /* suit */ + if (!obj) + obj = which_armor(mdef, W_ARMU); /* shirt */ + } - /* if monster's cloak/armor is greased, your grab slips off; this - protection might fail (33% chance) when the armor is cursed */ - if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) && - (!obj->cursed || rn2(3))) { - You("%s %s %s %s!", - mattk->adtyp == AD_WRAP ? - "slip off of" : "grab, but cannot hold onto", - s_suffix(mon_nam(mdef)), - obj->greased ? "greased" : "slippery", - /* avoid "slippery slippery cloak" - for undiscovered oilskin cloak */ - (obj->greased || objects[obj->otyp].oc_name_known) ? - xname(obj) : cloak_simple_name(obj)); + /* if monster's cloak/armor is greased, your grab slips off; this + protection might fail (33% chance) when the armor is cursed */ + if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) + && (!obj->cursed || rn2(3))) { + You("%s %s %s %s!", + mattk->adtyp == AD_WRAP ? "slip off of" + : "grab, but cannot hold onto", + s_suffix(mon_nam(mdef)), obj->greased ? "greased" : "slippery", + /* avoid "slippery slippery cloak" + for undiscovered oilskin cloak */ + (obj->greased || objects[obj->otyp].oc_name_known) + ? xname(obj) + : cloak_simple_name(obj)); - if (obj->greased && !rn2(2)) { - pline_The("grease wears off."); - obj->greased = 0; - } - return TRUE; - } - return FALSE; + if (obj->greased && !rn2(2)) { + pline_The("grease wears off."); + obj->greased = 0; + } + return TRUE; + } + return FALSE; } /* used when hitting a monster with a lance while mounted */ -STATIC_OVL int /* 1: joust hit; 0: ordinary hit; -1: joust but break lance */ -joust(mon, obj) -struct monst *mon; /* target */ -struct obj *obj; /* weapon */ +STATIC_OVL int /* 1: joust hit; 0: ordinary hit; -1: joust but break lance */ + joust(mon, obj) +struct monst *mon; /* target */ +struct obj *obj; /* weapon */ { int skill_rating, joust_dieroll; - if (Fumbling || Stunned) return 0; + if (Fumbling || Stunned) + return 0; /* sanity check; lance must be wielded in order to joust */ - if (obj != uwep && (obj != uswapwep || !u.twoweap)) return 0; + if (obj != uwep && (obj != uswapwep || !u.twoweap)) + return 0; /* if using two weapons, use worse of lance and two-weapon skills */ - skill_rating = P_SKILL(weapon_type(obj)); /* lance skill */ + skill_rating = P_SKILL(weapon_type(obj)); /* lance skill */ if (u.twoweap && P_SKILL(P_TWO_WEAPON_COMBAT) < skill_rating) - skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT); - if (skill_rating == P_ISRESTRICTED) skill_rating = P_UNSKILLED; /* 0=>1 */ + skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT); + if (skill_rating == P_ISRESTRICTED) + skill_rating = P_UNSKILLED; /* 0=>1 */ /* odds to joust are expert:80%, skilled:60%, basic:40%, unskilled:20% */ if ((joust_dieroll = rn2(5)) < skill_rating) { - if (joust_dieroll == 0 && rnl(50) == (50-1) && - !unsolid(mon->data) && !obj_resists(obj, 0, 100)) - return -1; /* hit that breaks lance */ - return 1; /* successful joust */ + if (joust_dieroll == 0 && rnl(50) == (50 - 1) && !unsolid(mon->data) + && !obj_resists(obj, 0, 100)) + return -1; /* hit that breaks lance */ + return 1; /* successful joust */ } - return 0; /* no joust bonus; revert to ordinary attack */ + return 0; /* no joust bonus; revert to ordinary attack */ } /* * Send in a demon pet for the hero. Exercise wisdom. * * This function used to be inline to damageum(), but the Metrowerks compiler - * (DR4 and DR4.5) screws up with an internal error 5 "Expression Too Complex." + * (DR4 and DR4.5) screws up with an internal error 5 "Expression Too + * Complex." * Pulling it out makes it work. */ STATIC_OVL void demonpet() { - int i; - struct permonst *pm; - struct monst *dtmp; + int i; + struct permonst *pm; + struct monst *dtmp; - pline("Some hell-p has arrived!"); - i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM; - pm = i != NON_PM ? &mons[i] : youmonst.data; - if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0) - (void)tamedog(dtmp, (struct obj *)0); - exercise(A_WIS, TRUE); + pline("Some hell-p has arrived!"); + i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM; + pm = i != NON_PM ? &mons[i] : youmonst.data; + if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0) + (void) tamedog(dtmp, (struct obj *) 0); + exercise(A_WIS, TRUE); } STATIC_OVL boolean theft_petrifies(otmp) struct obj *otmp; { - if (uarmg || otmp->otyp != CORPSE || - !touch_petrifies(&mons[otmp->corpsenm]) || Stone_resistance) - return FALSE; + if (uarmg || otmp->otyp != CORPSE + || !touch_petrifies(&mons[otmp->corpsenm]) || Stone_resistance) + return FALSE; - /* no poly_when_stoned() critter has theft capability */ +/* no poly_when_stoned() critter has theft capability */ #if 0 if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { display_nhwindow(WIN_MESSAGE, FALSE); /* --More-- */ @@ -1252,72 +1310,76 @@ steal_it(mdef, mattk) struct monst *mdef; struct attack *mattk; { - struct obj *otmp, *stealoid, **minvent_ptr; - long unwornmask; + struct obj *otmp, *stealoid, **minvent_ptr; + long unwornmask; - if (!mdef->minvent) return; /* nothing to take */ + if (!mdef->minvent) + return; /* nothing to take */ - /* look for worn body armor */ - stealoid = (struct obj *)0; - if (could_seduce(&youmonst, mdef, mattk)) { - /* find armor, and move it to end of inventory in the process */ - minvent_ptr = &mdef->minvent; - while ((otmp = *minvent_ptr) != 0) - if (otmp->owornmask & W_ARM) { - if (stealoid) panic("steal_it: multiple worn suits"); - *minvent_ptr = otmp->nobj; /* take armor out of minvent */ - stealoid = otmp; - stealoid->nobj = (struct obj *)0; - } else { - minvent_ptr = &otmp->nobj; - } - *minvent_ptr = stealoid; /* put armor back into minvent */ - } + /* look for worn body armor */ + stealoid = (struct obj *) 0; + if (could_seduce(&youmonst, mdef, mattk)) { + /* find armor, and move it to end of inventory in the process */ + minvent_ptr = &mdef->minvent; + while ((otmp = *minvent_ptr) != 0) + if (otmp->owornmask & W_ARM) { + if (stealoid) + panic("steal_it: multiple worn suits"); + *minvent_ptr = otmp->nobj; /* take armor out of minvent */ + stealoid = otmp; + stealoid->nobj = (struct obj *) 0; + } else { + minvent_ptr = &otmp->nobj; + } + *minvent_ptr = stealoid; /* put armor back into minvent */ + } - if (stealoid) { /* we will be taking everything */ - if (gender(mdef) == (int) u.mfemale && - youmonst.data->mlet == S_NYMPH) - You("charm %s. She gladly hands over her possessions.", - mon_nam(mdef)); - else - You("seduce %s and %s starts to take off %s clothes.", - mon_nam(mdef), mhe(mdef), mhis(mdef)); - } + if (stealoid) { /* we will be taking everything */ + if (gender(mdef) == (int) u.mfemale && youmonst.data->mlet == S_NYMPH) + You("charm %s. She gladly hands over her possessions.", + mon_nam(mdef)); + else + You("seduce %s and %s starts to take off %s clothes.", + mon_nam(mdef), mhe(mdef), mhis(mdef)); + } - while ((otmp = mdef->minvent) != 0) { - if (!Upolyd) break; /* no longer have ability to steal */ - /* take the object away from the monster */ - obj_extract_self(otmp); - if ((unwornmask = otmp->owornmask) != 0L) { - mdef->misc_worn_check &= ~unwornmask; - if (otmp->owornmask & W_WEP) { - setmnotwielded(mdef,otmp); - MON_NOWEP(mdef); - } - otmp->owornmask = 0L; - update_mon_intrinsics(mdef, otmp, FALSE, FALSE); + while ((otmp = mdef->minvent) != 0) { + if (!Upolyd) + break; /* no longer have ability to steal */ + /* take the object away from the monster */ + obj_extract_self(otmp); + if ((unwornmask = otmp->owornmask) != 0L) { + mdef->misc_worn_check &= ~unwornmask; + if (otmp->owornmask & W_WEP) { + setmnotwielded(mdef, otmp); + MON_NOWEP(mdef); + } + otmp->owornmask = 0L; + update_mon_intrinsics(mdef, otmp, FALSE, FALSE); - if (otmp == stealoid) /* special message for final item */ - pline("%s finishes taking off %s suit.", - Monnam(mdef), mhis(mdef)); - } - /* give the object to the character */ - otmp = hold_another_object(otmp, "You snatched but dropped %s.", - doname(otmp), "You steal: "); - if (otmp->where != OBJ_INVENT) continue; - if (theft_petrifies(otmp)) - break; /* stop thieving even though hero survived */ - /* more take-away handling, after theft message */ - if (unwornmask & W_WEP) { /* stole wielded weapon */ - possibly_unwield(mdef, FALSE); - } else if (unwornmask & W_ARMG) { /* stole worn gloves */ - mselftouch(mdef, (const char *)0, TRUE); - if (mdef->mhp <= 0) /* it's now a statue */ - return; /* can't continue stealing */ - } + if (otmp == stealoid) /* special message for final item */ + pline("%s finishes taking off %s suit.", Monnam(mdef), + mhis(mdef)); + } + /* give the object to the character */ + otmp = hold_another_object(otmp, "You snatched but dropped %s.", + doname(otmp), "You steal: "); + if (otmp->where != OBJ_INVENT) + continue; + if (theft_petrifies(otmp)) + break; /* stop thieving even though hero survived */ + /* more take-away handling, after theft message */ + if (unwornmask & W_WEP) { /* stole wielded weapon */ + possibly_unwield(mdef, FALSE); + } else if (unwornmask & W_ARMG) { /* stole worn gloves */ + mselftouch(mdef, (const char *) 0, TRUE); + if (mdef->mhp <= 0) /* it's now a statue */ + return; /* can't continue stealing */ + } - if (!stealoid) break; /* only taking one item */ - } + if (!stealoid) + break; /* only taking one item */ + } } int @@ -1325,373 +1387,382 @@ damageum(mdef, mattk) register struct monst *mdef; register struct attack *mattk; { - register struct permonst *pd = mdef->data; - int armpro, tmp = d((int)mattk->damn, (int)mattk->damd); - boolean negated; + register struct permonst *pd = mdef->data; + int armpro, tmp = d((int) mattk->damn, (int) mattk->damd); + boolean negated; - armpro = magic_negation(mdef); - /* since hero can't be cancelled, only defender's armor applies */ - negated = !(rn2(10) >= 3 * armpro); + armpro = magic_negation(mdef); + /* since hero can't be cancelled, only defender's armor applies */ + negated = !(rn2(10) >= 3 * armpro); - if (is_demon(youmonst.data) && !rn2(13) && !uwep - && u.umonnum != PM_SUCCUBUS && u.umonnum != PM_INCUBUS - && u.umonnum != PM_BALROG) { - demonpet(); - return(0); - } - switch(mattk->adtyp) { - case AD_STUN: - if(!Blind) - pline("%s %s for a moment.", Monnam(mdef), - makeplural(stagger(pd, "stagger"))); - mdef->mstun = 1; - goto physical; - case AD_LEGS: - /* if (u.ucancelled) { */ - /* tmp = 0; */ - /* break; */ - /* } */ - goto physical; - case AD_WERE: /* no special effect on monsters */ - case AD_HEAL: /* likewise */ - case AD_PHYS: - physical: - if(mattk->aatyp == AT_WEAP) { - if(uwep) tmp = 0; - } else if(mattk->aatyp == AT_KICK) { - if (thick_skinned(pd)) tmp = 0; - if (pd == &mons[PM_SHADE]) { - if (!(uarmf && uarmf->blessed)) { - impossible("bad shade attack function flow?"); - tmp = 0; - } else - tmp = rnd(4); /* bless damage */ - } - /* add ring(s) of increase damage */ - if (u.udaminc > 0) { - /* applies even if damage was 0 */ - tmp += u.udaminc; - } else if (tmp > 0) { - /* ring(s) might be negative; avoid converting - 0 to non-0 or positive to non-positive */ - tmp += u.udaminc; - if (tmp < 1) tmp = 1; - } - } - break; - case AD_FIRE: - if (negated) { - tmp = 0; - break; - } - if (!Blind) - pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); - if (pd == &mons[PM_STRAW_GOLEM] || - pd == &mons[PM_PAPER_GOLEM]) { - if (!Blind) - pline("%s burns completely!", Monnam(mdef)); - xkilled(mdef,2); - tmp = 0; - break; - /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ - } - tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); - tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); - if (resists_fire(mdef)) { - if (!Blind) - pline_The("fire doesn't heat %s!", mon_nam(mdef)); - golemeffects(mdef, AD_FIRE, tmp); - shieldeff(mdef->mx, mdef->my); - tmp = 0; - } - /* only potions damage resistant players in destroy_item */ - tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE); - break; - case AD_COLD: - if (negated) { - tmp = 0; - break; - } - if (!Blind) pline("%s is covered in frost!", Monnam(mdef)); - if (resists_cold(mdef)) { - shieldeff(mdef->mx, mdef->my); - if (!Blind) - pline_The("frost doesn't chill %s!", mon_nam(mdef)); - golemeffects(mdef, AD_COLD, tmp); - tmp = 0; - } - tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD); - break; - case AD_ELEC: - if (negated) { - tmp = 0; - break; - } - if (!Blind) pline("%s is zapped!", Monnam(mdef)); - tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); - if (resists_elec(mdef)) { - if (!Blind) - pline_The("zap doesn't shock %s!", mon_nam(mdef)); - golemeffects(mdef, AD_ELEC, tmp); - shieldeff(mdef->mx, mdef->my); - tmp = 0; - } - /* only rings damage resistant players in destroy_item */ - tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC); - break; - case AD_ACID: - if (resists_acid(mdef)) tmp = 0; - break; - case AD_STON: - if (!munstone(mdef, TRUE)) - minstapetrify(mdef, TRUE); - tmp = 0; - break; - case AD_SSEX: - case AD_SEDU: - case AD_SITM: - steal_it(mdef, mattk); - tmp = 0; - break; - case AD_SGLD: - /* This you as a leprechaun, so steal - real gold only, no lesser coins */ - { - struct obj *mongold = findgold(mdef->minvent); - if (mongold) { - obj_extract_self(mongold); - if (merge_choice(invent, mongold) || - inv_cnt(FALSE) < 52) { - addinv(mongold); - Your("purse feels heavier."); - } else { - You("grab %s's gold, but find no room in your knapsack.", mon_nam(mdef)); - dropy(mongold); - } - } - } - exercise(A_DEX, TRUE); - tmp = 0; - break; - case AD_TLPT: - if (tmp <= 0) tmp = 1; - if (!negated && tmp < mdef->mhp) { - char nambuf[BUFSZ]; - boolean u_saw_mon = canseemon(mdef) || - (u.uswallow && u.ustuck == mdef); - /* record the name before losing sight of monster */ - Strcpy(nambuf, Monnam(mdef)); - if (u_teleport_mon(mdef, FALSE) && - u_saw_mon && !(canseemon(mdef) || - (u.uswallow && u.ustuck == mdef))) - pline("%s suddenly disappears!", nambuf); - } - break; - case AD_BLND: - if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj*)0)) { - if(!Blind && mdef->mcansee) - pline("%s is blinded.", Monnam(mdef)); - mdef->mcansee = 0; - tmp += mdef->mblinded; - if (tmp > 127) tmp = 127; - mdef->mblinded = tmp; - } - tmp = 0; - break; - case AD_CURS: - if (night() && !rn2(10) && !mdef->mcan) { - if (pd == &mons[PM_CLAY_GOLEM]) { - if (!Blind) - pline("Some writing vanishes from %s head!", - s_suffix(mon_nam(mdef))); - xkilled(mdef, 0); - /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ - } else { - mdef->mcan = 1; - You("chuckle."); - } - } - tmp = 0; - break; - case AD_DRLI: - if (!negated && !rn2(3) && !resists_drli(mdef)) { - int xtmp = d(2,6); - pline("%s suddenly seems weaker!", Monnam(mdef)); - mdef->mhpmax -= xtmp; - if ((mdef->mhp -= xtmp) <= 0 || !mdef->m_lev) { - pline("%s dies!", Monnam(mdef)); - xkilled(mdef,0); - } else - mdef->m_lev--; - tmp = 0; - } - break; - case AD_RUST: - if (pd == &mons[PM_IRON_GOLEM]) { - pline("%s falls to pieces!", Monnam(mdef)); - xkilled(mdef,0); - } - erode_armor(mdef, ERODE_RUST); - tmp = 0; - break; - case AD_CORR: - erode_armor(mdef, ERODE_CORRODE); - tmp = 0; - break; - case AD_DCAY: - if (pd == &mons[PM_WOOD_GOLEM] || - pd == &mons[PM_LEATHER_GOLEM]) { - pline("%s falls to pieces!", Monnam(mdef)); - xkilled(mdef,0); - } - erode_armor(mdef, ERODE_ROT); - tmp = 0; - break; - case AD_DREN: - if (!negated && !rn2(4)) - xdrainenergym(mdef, TRUE); - tmp = 0; - break; - case AD_DRST: - case AD_DRDX: - case AD_DRCO: - if (!negated && !rn2(8)) { - Your("%s was poisoned!", mpoisons_subj(&youmonst, mattk)); - if (resists_poison(mdef)) - pline_The("poison doesn't seem to affect %s.", - mon_nam(mdef)); - else { - if (!rn2(10)) { - Your("poison was deadly..."); - tmp = mdef->mhp; - } else tmp += rn1(10,6); - } - } - break; - case AD_DRIN: - { - struct obj *helmet; + if (is_demon(youmonst.data) && !rn2(13) && !uwep + && u.umonnum != PM_SUCCUBUS && u.umonnum != PM_INCUBUS + && u.umonnum != PM_BALROG) { + demonpet(); + return (0); + } + switch (mattk->adtyp) { + case AD_STUN: + if (!Blind) + pline("%s %s for a moment.", Monnam(mdef), + makeplural(stagger(pd, "stagger"))); + mdef->mstun = 1; + goto physical; + case AD_LEGS: + /* if (u.ucancelled) { */ + /* tmp = 0; */ + /* break; */ + /* } */ + goto physical; + case AD_WERE: /* no special effect on monsters */ + case AD_HEAL: /* likewise */ + case AD_PHYS: + physical: + if (mattk->aatyp == AT_WEAP) { + if (uwep) + tmp = 0; + } else if (mattk->aatyp == AT_KICK) { + if (thick_skinned(pd)) + tmp = 0; + if (pd == &mons[PM_SHADE]) { + if (!(uarmf && uarmf->blessed)) { + impossible("bad shade attack function flow?"); + tmp = 0; + } else + tmp = rnd(4); /* bless damage */ + } + /* add ring(s) of increase damage */ + if (u.udaminc > 0) { + /* applies even if damage was 0 */ + tmp += u.udaminc; + } else if (tmp > 0) { + /* ring(s) might be negative; avoid converting + 0 to non-0 or positive to non-positive */ + tmp += u.udaminc; + if (tmp < 1) + tmp = 1; + } + } + break; + case AD_FIRE: + if (negated) { + tmp = 0; + break; + } + if (!Blind) + pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk)); + if (pd == &mons[PM_STRAW_GOLEM] || pd == &mons[PM_PAPER_GOLEM]) { + if (!Blind) + pline("%s burns completely!", Monnam(mdef)); + xkilled(mdef, 2); + tmp = 0; + break; + /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ + } + tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); + tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); + if (resists_fire(mdef)) { + if (!Blind) + pline_The("fire doesn't heat %s!", mon_nam(mdef)); + golemeffects(mdef, AD_FIRE, tmp); + shieldeff(mdef->mx, mdef->my); + tmp = 0; + } + /* only potions damage resistant players in destroy_item */ + tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE); + break; + case AD_COLD: + if (negated) { + tmp = 0; + break; + } + if (!Blind) + pline("%s is covered in frost!", Monnam(mdef)); + if (resists_cold(mdef)) { + shieldeff(mdef->mx, mdef->my); + if (!Blind) + pline_The("frost doesn't chill %s!", mon_nam(mdef)); + golemeffects(mdef, AD_COLD, tmp); + tmp = 0; + } + tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD); + break; + case AD_ELEC: + if (negated) { + tmp = 0; + break; + } + if (!Blind) + pline("%s is zapped!", Monnam(mdef)); + tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC); + if (resists_elec(mdef)) { + if (!Blind) + pline_The("zap doesn't shock %s!", mon_nam(mdef)); + golemeffects(mdef, AD_ELEC, tmp); + shieldeff(mdef->mx, mdef->my); + tmp = 0; + } + /* only rings damage resistant players in destroy_item */ + tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC); + break; + case AD_ACID: + if (resists_acid(mdef)) + tmp = 0; + break; + case AD_STON: + if (!munstone(mdef, TRUE)) + minstapetrify(mdef, TRUE); + tmp = 0; + break; + case AD_SSEX: + case AD_SEDU: + case AD_SITM: + steal_it(mdef, mattk); + tmp = 0; + break; + case AD_SGLD: + /* This you as a leprechaun, so steal + real gold only, no lesser coins */ + { + struct obj *mongold = findgold(mdef->minvent); + if (mongold) { + obj_extract_self(mongold); + if (merge_choice(invent, mongold) || inv_cnt(FALSE) < 52) { + addinv(mongold); + Your("purse feels heavier."); + } else { + You("grab %s's gold, but find no room in your knapsack.", + mon_nam(mdef)); + dropy(mongold); + } + } + } + exercise(A_DEX, TRUE); + tmp = 0; + break; + case AD_TLPT: + if (tmp <= 0) + tmp = 1; + if (!negated && tmp < mdef->mhp) { + char nambuf[BUFSZ]; + boolean u_saw_mon = + canseemon(mdef) || (u.uswallow && u.ustuck == mdef); + /* record the name before losing sight of monster */ + Strcpy(nambuf, Monnam(mdef)); + if (u_teleport_mon(mdef, FALSE) && u_saw_mon + && !(canseemon(mdef) || (u.uswallow && u.ustuck == mdef))) + pline("%s suddenly disappears!", nambuf); + } + break; + case AD_BLND: + if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj *) 0)) { + if (!Blind && mdef->mcansee) + pline("%s is blinded.", Monnam(mdef)); + mdef->mcansee = 0; + tmp += mdef->mblinded; + if (tmp > 127) + tmp = 127; + mdef->mblinded = tmp; + } + tmp = 0; + break; + case AD_CURS: + if (night() && !rn2(10) && !mdef->mcan) { + if (pd == &mons[PM_CLAY_GOLEM]) { + if (!Blind) + pline("Some writing vanishes from %s head!", + s_suffix(mon_nam(mdef))); + xkilled(mdef, 0); + /* Don't return yet; keep hp<1 and tmp=0 for pet msg */ + } else { + mdef->mcan = 1; + You("chuckle."); + } + } + tmp = 0; + break; + case AD_DRLI: + if (!negated && !rn2(3) && !resists_drli(mdef)) { + int xtmp = d(2, 6); + pline("%s suddenly seems weaker!", Monnam(mdef)); + mdef->mhpmax -= xtmp; + if ((mdef->mhp -= xtmp) <= 0 || !mdef->m_lev) { + pline("%s dies!", Monnam(mdef)); + xkilled(mdef, 0); + } else + mdef->m_lev--; + tmp = 0; + } + break; + case AD_RUST: + if (pd == &mons[PM_IRON_GOLEM]) { + pline("%s falls to pieces!", Monnam(mdef)); + xkilled(mdef, 0); + } + erode_armor(mdef, ERODE_RUST); + tmp = 0; + break; + case AD_CORR: + erode_armor(mdef, ERODE_CORRODE); + tmp = 0; + break; + case AD_DCAY: + if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) { + pline("%s falls to pieces!", Monnam(mdef)); + xkilled(mdef, 0); + } + erode_armor(mdef, ERODE_ROT); + tmp = 0; + break; + case AD_DREN: + if (!negated && !rn2(4)) + xdrainenergym(mdef, TRUE); + tmp = 0; + break; + case AD_DRST: + case AD_DRDX: + case AD_DRCO: + if (!negated && !rn2(8)) { + Your("%s was poisoned!", mpoisons_subj(&youmonst, mattk)); + if (resists_poison(mdef)) + pline_The("poison doesn't seem to affect %s.", mon_nam(mdef)); + else { + if (!rn2(10)) { + Your("poison was deadly..."); + tmp = mdef->mhp; + } else + tmp += rn1(10, 6); + } + } + break; + case AD_DRIN: { + struct obj *helmet; - if (notonhead || !has_head(pd)) { - pline("%s doesn't seem harmed.", Monnam(mdef)); - tmp = 0; - if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) { - if (!Slimed) { - You("suck in some slime and don't feel very well."); - make_slimed(10L, (char*) 0); - } - } - break; - } - if (m_slips_free(mdef, mattk)) break; + if (notonhead || !has_head(pd)) { + pline("%s doesn't seem harmed.", Monnam(mdef)); + tmp = 0; + if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) { + if (!Slimed) { + You("suck in some slime and don't feel very well."); + make_slimed(10L, (char *) 0); + } + } + break; + } + if (m_slips_free(mdef, mattk)) + break; - if ((helmet = which_armor(mdef, W_ARMH)) != 0 && rn2(8)) { - pline("%s %s blocks your attack to %s head.", - s_suffix(Monnam(mdef)), - helm_simple_name(helmet), mhis(mdef)); - break; - } + if ((helmet = which_armor(mdef, W_ARMH)) != 0 && rn2(8)) { + pline("%s %s blocks your attack to %s head.", + s_suffix(Monnam(mdef)), helm_simple_name(helmet), + mhis(mdef)); + break; + } - (void) eat_brains(&youmonst, mdef, TRUE, &tmp); - break; - } - case AD_STCK: - if (!negated && !sticks(pd)) - u.ustuck = mdef; /* it's now stuck to you */ - break; - case AD_WRAP: - if (!sticks(pd)) { - if (!u.ustuck && !rn2(10)) { - if (m_slips_free(mdef, mattk)) { - tmp = 0; - } else { - You("swing yourself around %s!", - mon_nam(mdef)); - u.ustuck = mdef; - } - } else if(u.ustuck == mdef) { - /* Monsters don't wear amulets of magical breathing */ - if (is_pool(u.ux,u.uy) && !is_swimmer(pd) && - !amphibious(pd)) { - You("drown %s...", mon_nam(mdef)); - tmp = mdef->mhp; - } else if(mattk->aatyp == AT_HUGS) - pline("%s is being crushed.", Monnam(mdef)); - } else { - tmp = 0; - if (flags.verbose) - You("brush against %s %s.", - s_suffix(mon_nam(mdef)), - mbodypart(mdef, LEG)); - } - } else tmp = 0; - break; - case AD_PLYS: - if (!negated && mdef->mcanmove && !rn2(3) && tmp < mdef->mhp) { - if (!Blind) pline("%s is frozen by you!", Monnam(mdef)); - paralyze_monst(mdef, rnd(10)); - } - break; - case AD_SLEE: - if (!negated && !mdef->msleeping && - sleep_monst(mdef, rnd(10), -1)) { - if (!Blind) - pline("%s is put to sleep by you!", Monnam(mdef)); - slept_monst(mdef); - } - break; - case AD_SLIM: - if (negated) break; /* physical damage only */ - if (!rn2(4) && !slimeproof(pd)) { - if (!munslime(mdef, TRUE) && mdef->mhp > 0) { - /* this assumes newcham() won't fail; since hero has - a slime attack, green slimes haven't been geno'd */ - You("turn %s into slime.", mon_nam(mdef)); - if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE)) - pd = mdef->data; - } - /* munslime attempt could have been fatal */ - if (mdef->mhp < 1) return 2; /* skip death message */ - tmp = 0; - } - break; - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - /* there's no msomearmor() function, so just do damage */ - /* if (negated) break; */ - break; - case AD_SLOW: - if (!negated && mdef->mspeed != MSLOW) { - unsigned int oldspeed = mdef->mspeed; + (void) eat_brains(&youmonst, mdef, TRUE, &tmp); + break; + } + case AD_STCK: + if (!negated && !sticks(pd)) + u.ustuck = mdef; /* it's now stuck to you */ + break; + case AD_WRAP: + if (!sticks(pd)) { + if (!u.ustuck && !rn2(10)) { + if (m_slips_free(mdef, mattk)) { + tmp = 0; + } else { + You("swing yourself around %s!", mon_nam(mdef)); + u.ustuck = mdef; + } + } else if (u.ustuck == mdef) { + /* Monsters don't wear amulets of magical breathing */ + if (is_pool(u.ux, u.uy) && !is_swimmer(pd) + && !amphibious(pd)) { + You("drown %s...", mon_nam(mdef)); + tmp = mdef->mhp; + } else if (mattk->aatyp == AT_HUGS) + pline("%s is being crushed.", Monnam(mdef)); + } else { + tmp = 0; + if (flags.verbose) + You("brush against %s %s.", s_suffix(mon_nam(mdef)), + mbodypart(mdef, LEG)); + } + } else + tmp = 0; + break; + case AD_PLYS: + if (!negated && mdef->mcanmove && !rn2(3) && tmp < mdef->mhp) { + if (!Blind) + pline("%s is frozen by you!", Monnam(mdef)); + paralyze_monst(mdef, rnd(10)); + } + break; + case AD_SLEE: + if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) { + if (!Blind) + pline("%s is put to sleep by you!", Monnam(mdef)); + slept_monst(mdef); + } + break; + case AD_SLIM: + if (negated) + break; /* physical damage only */ + if (!rn2(4) && !slimeproof(pd)) { + if (!munslime(mdef, TRUE) && mdef->mhp > 0) { + /* this assumes newcham() won't fail; since hero has + a slime attack, green slimes haven't been geno'd */ + You("turn %s into slime.", mon_nam(mdef)); + if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE)) + pd = mdef->data; + } + /* munslime attempt could have been fatal */ + if (mdef->mhp < 1) + return 2; /* skip death message */ + tmp = 0; + } + break; + case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ + /* there's no msomearmor() function, so just do damage */ + /* if (negated) break; */ + break; + case AD_SLOW: + if (!negated && mdef->mspeed != MSLOW) { + unsigned int oldspeed = mdef->mspeed; - mon_adjust_speed(mdef, -1, (struct obj *)0); - if (mdef->mspeed != oldspeed && canseemon(mdef)) - pline("%s slows down.", Monnam(mdef)); - } - break; - case AD_CONF: - if (!mdef->mconf) { - if (canseemon(mdef)) - pline("%s looks confused.", Monnam(mdef)); - mdef->mconf = 1; - } - break; - default: tmp = 0; - break; - } + mon_adjust_speed(mdef, -1, (struct obj *) 0); + if (mdef->mspeed != oldspeed && canseemon(mdef)) + pline("%s slows down.", Monnam(mdef)); + } + break; + case AD_CONF: + if (!mdef->mconf) { + if (canseemon(mdef)) + pline("%s looks confused.", Monnam(mdef)); + mdef->mconf = 1; + } + break; + default: + tmp = 0; + break; + } - mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */ - if((mdef->mhp -= tmp) < 1) { - if (mdef->mtame && !cansee(mdef->mx,mdef->my)) { - You_feel("embarrassed for a moment."); - if (tmp) xkilled(mdef, 0); /* !tmp but hp<1: already killed */ - } else if (!flags.verbose) { - You("destroy it!"); - if (tmp) xkilled(mdef, 0); - } else - if (tmp) killed(mdef); - return(2); - } - return(1); + mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */ + if ((mdef->mhp -= tmp) < 1) { + if (mdef->mtame && !cansee(mdef->mx, mdef->my)) { + You_feel("embarrassed for a moment."); + if (tmp) + xkilled(mdef, 0); /* !tmp but hp<1: already killed */ + } else if (!flags.verbose) { + You("destroy it!"); + if (tmp) + xkilled(mdef, 0); + } else if (tmp) + killed(mdef); + return (2); + } + return (1); } STATIC_OVL int @@ -1699,267 +1770,275 @@ explum(mdef, mattk) register struct monst *mdef; register struct attack *mattk; { - register int tmp = d((int)mattk->damn, (int)mattk->damd); + register int tmp = d((int) mattk->damn, (int) mattk->damd); - You("explode!"); - switch(mattk->adtyp) { - boolean resistance; /* only for cold/fire/elec */ + You("explode!"); + switch (mattk->adtyp) { + boolean resistance; /* only for cold/fire/elec */ - case AD_BLND: - if (!resists_blnd(mdef)) { - pline("%s is blinded by your flash of light!", Monnam(mdef)); - mdef->mblinded = min((int)mdef->mblinded + tmp, 127); - mdef->mcansee = 0; - } - break; - case AD_HALU: - if (haseyes(mdef->data) && mdef->mcansee) { - pline("%s is affected by your flash of light!", - Monnam(mdef)); - mdef->mconf = 1; - } - break; - case AD_COLD: - resistance = resists_cold(mdef); - goto common; - case AD_FIRE: - resistance = resists_fire(mdef); - goto common; - case AD_ELEC: - resistance = resists_elec(mdef); -common: - if (!resistance) { - pline("%s gets blasted!", Monnam(mdef)); - mdef->mhp -= tmp; - if (mdef->mhp <= 0) { - killed(mdef); - return(2); - } - } else { - shieldeff(mdef->mx, mdef->my); - if (is_golem(mdef->data)) - golemeffects(mdef, (int)mattk->adtyp, tmp); - else - pline_The("blast doesn't seem to affect %s.", - mon_nam(mdef)); - } - break; - default: - break; - } - return(1); + case AD_BLND: + if (!resists_blnd(mdef)) { + pline("%s is blinded by your flash of light!", Monnam(mdef)); + mdef->mblinded = min((int) mdef->mblinded + tmp, 127); + mdef->mcansee = 0; + } + break; + case AD_HALU: + if (haseyes(mdef->data) && mdef->mcansee) { + pline("%s is affected by your flash of light!", Monnam(mdef)); + mdef->mconf = 1; + } + break; + case AD_COLD: + resistance = resists_cold(mdef); + goto common; + case AD_FIRE: + resistance = resists_fire(mdef); + goto common; + case AD_ELEC: + resistance = resists_elec(mdef); + common: + if (!resistance) { + pline("%s gets blasted!", Monnam(mdef)); + mdef->mhp -= tmp; + if (mdef->mhp <= 0) { + killed(mdef); + return (2); + } + } else { + shieldeff(mdef->mx, mdef->my); + if (is_golem(mdef->data)) + golemeffects(mdef, (int) mattk->adtyp, tmp); + else + pline_The("blast doesn't seem to affect %s.", mon_nam(mdef)); + } + break; + default: + break; + } + return (1); } STATIC_OVL void start_engulf(mdef) struct monst *mdef; { - if (!Invisible) { - map_location(u.ux, u.uy, TRUE); - tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst)); - tmp_at(mdef->mx, mdef->my); - } - You("engulf %s!", mon_nam(mdef)); - delay_output(); - delay_output(); + if (!Invisible) { + map_location(u.ux, u.uy, TRUE); + tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst)); + tmp_at(mdef->mx, mdef->my); + } + You("engulf %s!", mon_nam(mdef)); + delay_output(); + delay_output(); } STATIC_OVL void end_engulf() { - if (!Invisible) { - tmp_at(DISP_END, 0); - newsym(u.ux, u.uy); - } + if (!Invisible) { + tmp_at(DISP_END, 0); + newsym(u.ux, u.uy); + } } STATIC_OVL int -gulpum(mdef,mattk) +gulpum(mdef, mattk) register struct monst *mdef; register struct attack *mattk; { -#ifdef LINT /* static char msgbuf[BUFSZ]; */ - char msgbuf[BUFSZ]; +#ifdef LINT /* static char msgbuf[BUFSZ]; */ + char msgbuf[BUFSZ]; #else - static char msgbuf[BUFSZ]; /* for nomovemsg */ + static char msgbuf[BUFSZ]; /* for nomovemsg */ #endif - register int tmp; - register int dam = d((int)mattk->damn, (int)mattk->damd); - boolean fatal_gulp; - struct obj *otmp; - struct permonst *pd = mdef->data; + register int tmp; + register int dam = d((int) mattk->damn, (int) mattk->damd); + boolean fatal_gulp; + struct obj *otmp; + struct permonst *pd = mdef->data; - /* Not totally the same as for real monsters. Specifically, these - * don't take multiple moves. (It's just too hard, for too little - * result, to program monsters which attack from inside you, which - * would be necessary if done accurately.) Instead, we arbitrarily - * kill the monster immediately for AD_DGST and we regurgitate them - * after exactly 1 round of attack otherwise. -KAA - */ + /* Not totally the same as for real monsters. Specifically, these + * don't take multiple moves. (It's just too hard, for too little + * result, to program monsters which attack from inside you, which + * would be necessary if done accurately.) Instead, we arbitrarily + * kill the monster immediately for AD_DGST and we regurgitate them + * after exactly 1 round of attack otherwise. -KAA + */ - if (!engulf_target(&youmonst, mdef)) return 0; + if (!engulf_target(&youmonst, mdef)) + return 0; - if(u.uhunger < 1500 && !u.uswallow) { - for (otmp = mdef->minvent; otmp; otmp = otmp->nobj) - (void) snuff_lit(otmp); + if (u.uhunger < 1500 && !u.uswallow) { + for (otmp = mdef->minvent; otmp; otmp = otmp->nobj) + (void) snuff_lit(otmp); - /* engulfing a cockatrice or digesting a Rider or Medusa */ - fatal_gulp = (touch_petrifies(pd) && !Stone_resistance) || - (mattk->adtyp == AD_DGST && (is_rider(pd) || - (pd == &mons[PM_MEDUSA] && !Stone_resistance))); + /* engulfing a cockatrice or digesting a Rider or Medusa */ + fatal_gulp = (touch_petrifies(pd) && !Stone_resistance) + || (mattk->adtyp == AD_DGST + && (is_rider(pd) || (pd == &mons[PM_MEDUSA] + && !Stone_resistance))); - if ((mattk->adtyp == AD_DGST && !Slow_digestion) || fatal_gulp) - eating_conducts(pd); + if ((mattk->adtyp == AD_DGST && !Slow_digestion) || fatal_gulp) + eating_conducts(pd); - if (fatal_gulp && !is_rider(pd)) { /* petrification */ - char kbuf[BUFSZ]; - const char *mname = pd->mname; + if (fatal_gulp && !is_rider(pd)) { /* petrification */ + char kbuf[BUFSZ]; + const char *mname = pd->mname; - if (!type_is_pname(pd)) mname = an(mname); - You("englut %s.", mon_nam(mdef)); - Sprintf(kbuf, "swallowing %s whole", mname); - instapetrify(kbuf); - } else { - start_engulf(mdef); - switch(mattk->adtyp) { - case AD_DGST: - /* eating a Rider or its corpse is fatal */ - if (is_rider(pd)) { - pline("Unfortunately, digesting any of it is fatal."); - end_engulf(); - Sprintf(killer.name, "unwisely tried to eat %s", - pd->mname); - killer.format = NO_KILLER_PREFIX; - done(DIED); - return 0; /* lifesaved */ - } + if (!type_is_pname(pd)) + mname = an(mname); + You("englut %s.", mon_nam(mdef)); + Sprintf(kbuf, "swallowing %s whole", mname); + instapetrify(kbuf); + } else { + start_engulf(mdef); + switch (mattk->adtyp) { + case AD_DGST: + /* eating a Rider or its corpse is fatal */ + if (is_rider(pd)) { + pline("Unfortunately, digesting any of it is fatal."); + end_engulf(); + Sprintf(killer.name, "unwisely tried to eat %s", + pd->mname); + killer.format = NO_KILLER_PREFIX; + done(DIED); + return 0; /* lifesaved */ + } - if (Slow_digestion) { - dam = 0; - break; - } + if (Slow_digestion) { + dam = 0; + break; + } - /* Use up amulet of life saving */ - if (!!(otmp = mlifesaver(mdef))) m_useup(mdef, otmp); + /* Use up amulet of life saving */ + if (!!(otmp = mlifesaver(mdef))) + m_useup(mdef, otmp); - newuhs(FALSE); - xkilled(mdef,2); - if (mdef->mhp > 0) { /* monster lifesaved */ - You("hurriedly regurgitate the sizzling in your %s.", - body_part(STOMACH)); - } else { - tmp = 1 + (pd->cwt >> 8); - if (corpse_chance(mdef, &youmonst, TRUE) && - !(mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) { - /* nutrition only if there can be a corpse */ - u.uhunger += (pd->cnutrit + 1) / 2; - } else tmp = 0; - Sprintf(msgbuf, "You totally digest %s.", - mon_nam(mdef)); - if (tmp != 0) { - /* setting afternmv = end_engulf is tempting, - * but will cause problems if the player is - * attacked (which uses his real location) or - * if his See_invisible wears off - */ - You("digest %s.", mon_nam(mdef)); - if (Slow_digestion) tmp *= 2; - nomul(-tmp); - multi_reason = "digesting something"; - nomovemsg = msgbuf; - } else pline1(msgbuf); - if (pd == &mons[PM_GREEN_SLIME]) { - Sprintf(msgbuf, "%s isn't sitting well with you.", - The(pd->mname)); - if (!Unchanging) { - make_slimed(5L, (char*) 0); - } - } else - exercise(A_CON, TRUE); - } - end_engulf(); - return(2); - case AD_PHYS: - if (youmonst.data == &mons[PM_FOG_CLOUD]) { - pline("%s is laden with your moisture.", - Monnam(mdef)); - if (amphibious(pd) && !flaming(pd)) { - dam = 0; - pline("%s seems unharmed.", Monnam(mdef)); - } - } else - pline("%s is pummeled with your debris!", - Monnam(mdef)); - break; - case AD_ACID: - pline("%s is covered with your goo!", Monnam(mdef)); - if (resists_acid(mdef)) { - pline("It seems harmless to %s.", mon_nam(mdef)); - dam = 0; - } - break; - case AD_BLND: - if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj *)0)) { - if (mdef->mcansee) - pline("%s can't see in there!", Monnam(mdef)); - mdef->mcansee = 0; - dam += mdef->mblinded; - if (dam > 127) dam = 127; - mdef->mblinded = dam; - } - dam = 0; - break; - case AD_ELEC: - if (rn2(2)) { - pline_The("air around %s crackles with electricity.", mon_nam(mdef)); - if (resists_elec(mdef)) { - pline("%s seems unhurt.", Monnam(mdef)); - dam = 0; - } - golemeffects(mdef,(int)mattk->adtyp,dam); - } else dam = 0; - break; - case AD_COLD: - if (rn2(2)) { - if (resists_cold(mdef)) { - pline("%s seems mildly chilly.", Monnam(mdef)); - dam = 0; - } else - pline("%s is freezing to death!",Monnam(mdef)); - golemeffects(mdef,(int)mattk->adtyp,dam); - } else dam = 0; - break; - case AD_FIRE: - if (rn2(2)) { - if (resists_fire(mdef)) { - pline("%s seems mildly hot.", Monnam(mdef)); - dam = 0; - } else - pline("%s is burning to a crisp!",Monnam(mdef)); - golemeffects(mdef,(int)mattk->adtyp,dam); - } else dam = 0; - break; - case AD_DREN: - if (!rn2(4)) - xdrainenergym(mdef, TRUE); - dam = 0; - break; - } - end_engulf(); - if ((mdef->mhp -= dam) <= 0) { - killed(mdef); - if (mdef->mhp <= 0) /* not lifesaved */ - return(2); - } - You("%s %s!", is_animal(youmonst.data) ? "regurgitate" - : "expel", mon_nam(mdef)); - if (Slow_digestion || is_animal(youmonst.data)) { - pline("Obviously, you didn't like %s taste.", - s_suffix(mon_nam(mdef))); - } - } - } - return(0); + newuhs(FALSE); + xkilled(mdef, 2); + if (mdef->mhp > 0) { /* monster lifesaved */ + You("hurriedly regurgitate the sizzling in your %s.", + body_part(STOMACH)); + } else { + tmp = 1 + (pd->cwt >> 8); + if (corpse_chance(mdef, &youmonst, TRUE) + && !(mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) { + /* nutrition only if there can be a corpse */ + u.uhunger += (pd->cnutrit + 1) / 2; + } else + tmp = 0; + Sprintf(msgbuf, "You totally digest %s.", mon_nam(mdef)); + if (tmp != 0) { + /* setting afternmv = end_engulf is tempting, + * but will cause problems if the player is + * attacked (which uses his real location) or + * if his See_invisible wears off + */ + You("digest %s.", mon_nam(mdef)); + if (Slow_digestion) + tmp *= 2; + nomul(-tmp); + multi_reason = "digesting something"; + nomovemsg = msgbuf; + } else + pline1(msgbuf); + if (pd == &mons[PM_GREEN_SLIME]) { + Sprintf(msgbuf, "%s isn't sitting well with you.", + The(pd->mname)); + if (!Unchanging) { + make_slimed(5L, (char *) 0); + } + } else + exercise(A_CON, TRUE); + } + end_engulf(); + return (2); + case AD_PHYS: + if (youmonst.data == &mons[PM_FOG_CLOUD]) { + pline("%s is laden with your moisture.", Monnam(mdef)); + if (amphibious(pd) && !flaming(pd)) { + dam = 0; + pline("%s seems unharmed.", Monnam(mdef)); + } + } else + pline("%s is pummeled with your debris!", Monnam(mdef)); + break; + case AD_ACID: + pline("%s is covered with your goo!", Monnam(mdef)); + if (resists_acid(mdef)) { + pline("It seems harmless to %s.", mon_nam(mdef)); + dam = 0; + } + break; + case AD_BLND: + if (can_blnd(&youmonst, mdef, mattk->aatyp, + (struct obj *) 0)) { + if (mdef->mcansee) + pline("%s can't see in there!", Monnam(mdef)); + mdef->mcansee = 0; + dam += mdef->mblinded; + if (dam > 127) + dam = 127; + mdef->mblinded = dam; + } + dam = 0; + break; + case AD_ELEC: + if (rn2(2)) { + pline_The("air around %s crackles with electricity.", + mon_nam(mdef)); + if (resists_elec(mdef)) { + pline("%s seems unhurt.", Monnam(mdef)); + dam = 0; + } + golemeffects(mdef, (int) mattk->adtyp, dam); + } else + dam = 0; + break; + case AD_COLD: + if (rn2(2)) { + if (resists_cold(mdef)) { + pline("%s seems mildly chilly.", Monnam(mdef)); + dam = 0; + } else + pline("%s is freezing to death!", Monnam(mdef)); + golemeffects(mdef, (int) mattk->adtyp, dam); + } else + dam = 0; + break; + case AD_FIRE: + if (rn2(2)) { + if (resists_fire(mdef)) { + pline("%s seems mildly hot.", Monnam(mdef)); + dam = 0; + } else + pline("%s is burning to a crisp!", Monnam(mdef)); + golemeffects(mdef, (int) mattk->adtyp, dam); + } else + dam = 0; + break; + case AD_DREN: + if (!rn2(4)) + xdrainenergym(mdef, TRUE); + dam = 0; + break; + } + end_engulf(); + if ((mdef->mhp -= dam) <= 0) { + killed(mdef); + if (mdef->mhp <= 0) /* not lifesaved */ + return (2); + } + You("%s %s!", is_animal(youmonst.data) ? "regurgitate" : "expel", + mon_nam(mdef)); + if (Slow_digestion || is_animal(youmonst.data)) { + pline("Obviously, you didn't like %s taste.", + s_suffix(mon_nam(mdef))); + } + } + } + return (0); } void @@ -1968,224 +2047,214 @@ register struct monst *mdef; register struct attack *mattk; boolean wouldhavehit; { - if (wouldhavehit) /* monk is missing due to penalty for wearing suit */ - Your("armor is rather cumbersome..."); + if (wouldhavehit) /* monk is missing due to penalty for wearing suit */ + Your("armor is rather cumbersome..."); - if (could_seduce(&youmonst, mdef, mattk)) - You("pretend to be friendly to %s.", mon_nam(mdef)); - else if(canspotmon(mdef) && flags.verbose) - You("miss %s.", mon_nam(mdef)); - else - You("miss it."); - if (!mdef->msleeping && mdef->mcanmove) - wakeup(mdef); + if (could_seduce(&youmonst, mdef, mattk)) + You("pretend to be friendly to %s.", mon_nam(mdef)); + else if (canspotmon(mdef) && flags.verbose) + You("miss %s.", mon_nam(mdef)); + else + You("miss it."); + if (!mdef->msleeping && mdef->mcanmove) + wakeup(mdef); } -STATIC_OVL boolean -hmonas(mon) /* attack monster as a monster. */ +STATIC_OVL boolean hmonas(mon) /* attack monster as a monster. */ register struct monst *mon; { - struct attack *mattk, alt_attk; - struct obj *weapon; - boolean altwep = FALSE, weapon_used = FALSE; - int i, tmp, armorpenalty, sum[NATTK], - nsum = 0, dhit = 0, attknum = 0; + struct attack *mattk, alt_attk; + struct obj *weapon; + boolean altwep = FALSE, weapon_used = FALSE; + int i, tmp, armorpenalty, sum[NATTK], nsum = 0, dhit = 0, attknum = 0; - for(i = 0; i < NATTK; i++) { - sum[i] = 0; - mattk = getmattk(youmonst.data, i, sum, &alt_attk); - switch(mattk->aatyp) { - case AT_WEAP: -use_weapon: - /* Certain monsters don't use weapons when encountered as enemies, - * but players who polymorph into them have hands or claws and thus - * should be able to use weapons. This shouldn't prohibit the use - * of most special abilities, either. - * If a monster has multiple claw attacks, only one can use weapon. - */ - weapon_used = TRUE; - /* Potential problem: if the monster gets multiple weapon attacks, - * we currently allow the player to get each of these as a weapon - * attack. Is this really desirable? - */ - /* approximate two-weapon mode */ - weapon = (altwep && uswapwep) ? uswapwep : uwep; - altwep = !altwep; /* toggle for next attack */ - tmp = find_roll_to_hit(mon, AT_WEAP, weapon, - &attknum, &armorpenalty); - dhit = (tmp > (dieroll = rnd(20)) || u.uswallow); - /* Enemy dead, before any special abilities used */ - if (!known_hitum(mon, weapon, &dhit, - tmp, armorpenalty, mattk)) { - sum[i] = 2; - break; - } else sum[i] = dhit; - /* might be a worm that gets cut in half */ - if (m_at(u.ux+u.dx, u.uy+u.dy) != mon) - return (boolean)(nsum != 0); - /* Do not print "You hit" message, since known_hitum - * already did it. - */ - if (dhit && mattk->adtyp != AD_SPEL - && mattk->adtyp != AD_PHYS) - sum[i] = damageum(mon,mattk); - break; - case AT_CLAW: - if (uwep && !cantwield(youmonst.data) && - !weapon_used) goto use_weapon; - /*FALLTHRU*/ - case AT_TUCH: - if (uwep && youmonst.data->mlet == S_LICH && - !weapon_used) goto use_weapon; - /*FALLTHRU*/ - case AT_KICK: - case AT_BITE: - case AT_STNG: - case AT_BUTT: - case AT_TENT: - tmp = find_roll_to_hit(mon, mattk->aatyp, - (struct obj *)0, - &attknum, &armorpenalty); - dhit = (tmp > (dieroll = rnd(20)) || u.uswallow); - if (dhit) { - int compat; + for (i = 0; i < NATTK; i++) { + sum[i] = 0; + mattk = getmattk(youmonst.data, i, sum, &alt_attk); + switch (mattk->aatyp) { + case AT_WEAP: + use_weapon: + /* Certain monsters don't use weapons when encountered as enemies, + * but players who polymorph into them have hands or claws and + * thus + * should be able to use weapons. This shouldn't prohibit the use + * of most special abilities, either. + * If a monster has multiple claw attacks, only one can use + * weapon. + */ + weapon_used = TRUE; + /* Potential problem: if the monster gets multiple weapon attacks, + * we currently allow the player to get each of these as a weapon + * attack. Is this really desirable? + */ + /* approximate two-weapon mode */ + weapon = (altwep && uswapwep) ? uswapwep : uwep; + altwep = !altwep; /* toggle for next attack */ + tmp = find_roll_to_hit(mon, AT_WEAP, weapon, &attknum, + &armorpenalty); + dhit = (tmp > (dieroll = rnd(20)) || u.uswallow); + /* Enemy dead, before any special abilities used */ + if (!known_hitum(mon, weapon, &dhit, tmp, armorpenalty, mattk)) { + sum[i] = 2; + break; + } else + sum[i] = dhit; + /* might be a worm that gets cut in half */ + if (m_at(u.ux + u.dx, u.uy + u.dy) != mon) + return (boolean)(nsum != 0); + /* Do not print "You hit" message, since known_hitum + * already did it. + */ + if (dhit && mattk->adtyp != AD_SPEL && mattk->adtyp != AD_PHYS) + sum[i] = damageum(mon, mattk); + break; + case AT_CLAW: + if (uwep && !cantwield(youmonst.data) && !weapon_used) + goto use_weapon; + /*FALLTHRU*/ + case AT_TUCH: + if (uwep && youmonst.data->mlet == S_LICH && !weapon_used) + goto use_weapon; + /*FALLTHRU*/ + case AT_KICK: + case AT_BITE: + case AT_STNG: + case AT_BUTT: + case AT_TENT: + tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, + &attknum, &armorpenalty); + dhit = (tmp > (dieroll = rnd(20)) || u.uswallow); + if (dhit) { + int compat; - if (!u.uswallow && - (compat=could_seduce(&youmonst, mon, mattk))) { - You("%s %s %s.", - mon->mcansee && haseyes(mon->data) - ? "smile at" : "talk to", - mon_nam(mon), - compat == 2 ? "engagingly":"seductively"); - /* doesn't anger it; no wakeup() */ - sum[i] = damageum(mon, mattk); - break; - } - wakeup(mon); - /* maybe this check should be in damageum()? */ - if (mon->data == &mons[PM_SHADE] && - !(mattk->aatyp == AT_KICK && - uarmf && uarmf->blessed)) { - Your("attack passes harmlessly through %s.", - mon_nam(mon)); - break; - } - if (mattk->aatyp == AT_KICK) - You("kick %s.", mon_nam(mon)); - else if (mattk->aatyp == AT_BITE) - You("bite %s.", mon_nam(mon)); - else if (mattk->aatyp == AT_STNG) - You("sting %s.", mon_nam(mon)); - else if (mattk->aatyp == AT_BUTT) - You("butt %s.", mon_nam(mon)); - else if (mattk->aatyp == AT_TUCH) - You("touch %s.", mon_nam(mon)); - else if (mattk->aatyp == AT_TENT) - Your("tentacles suck %s.", mon_nam(mon)); - else You("hit %s.", mon_nam(mon)); - sum[i] = damageum(mon, mattk); - } else { - missum(mon, mattk, - (tmp + armorpenalty > dieroll)); - } - break; + if (!u.uswallow + && (compat = could_seduce(&youmonst, mon, mattk))) { + You("%s %s %s.", + mon->mcansee && haseyes(mon->data) ? "smile at" + : "talk to", + mon_nam(mon), + compat == 2 ? "engagingly" : "seductively"); + /* doesn't anger it; no wakeup() */ + sum[i] = damageum(mon, mattk); + break; + } + wakeup(mon); + /* maybe this check should be in damageum()? */ + if (mon->data == &mons[PM_SHADE] + && !(mattk->aatyp == AT_KICK && uarmf + && uarmf->blessed)) { + Your("attack passes harmlessly through %s.", + mon_nam(mon)); + break; + } + if (mattk->aatyp == AT_KICK) + You("kick %s.", mon_nam(mon)); + else if (mattk->aatyp == AT_BITE) + You("bite %s.", mon_nam(mon)); + else if (mattk->aatyp == AT_STNG) + You("sting %s.", mon_nam(mon)); + else if (mattk->aatyp == AT_BUTT) + You("butt %s.", mon_nam(mon)); + else if (mattk->aatyp == AT_TUCH) + You("touch %s.", mon_nam(mon)); + else if (mattk->aatyp == AT_TENT) + Your("tentacles suck %s.", mon_nam(mon)); + else + You("hit %s.", mon_nam(mon)); + sum[i] = damageum(mon, mattk); + } else { + missum(mon, mattk, (tmp + armorpenalty > dieroll)); + } + break; - case AT_HUGS: - /* automatic if prev two attacks succeed, or if - * already grabbed in a previous attack - */ - dhit = 1; - wakeup(mon); - if (mon->data == &mons[PM_SHADE]) - Your("hug passes harmlessly through %s.", - mon_nam(mon)); - else if (!sticks(mon->data) && !u.uswallow) { - if (mon==u.ustuck) { - pline("%s is being %s.", Monnam(mon), - u.umonnum==PM_ROPE_GOLEM ? "choked": - "crushed"); - sum[i] = damageum(mon, mattk); - } else if(i >= 2 && sum[i-1] && sum[i-2]) { - You("grab %s!", mon_nam(mon)); - u.ustuck = mon; - sum[i] = damageum(mon, mattk); - } - } - break; + case AT_HUGS: + /* automatic if prev two attacks succeed, or if + * already grabbed in a previous attack + */ + dhit = 1; + wakeup(mon); + if (mon->data == &mons[PM_SHADE]) + Your("hug passes harmlessly through %s.", mon_nam(mon)); + else if (!sticks(mon->data) && !u.uswallow) { + if (mon == u.ustuck) { + pline("%s is being %s.", Monnam(mon), + u.umonnum == PM_ROPE_GOLEM ? "choked" : "crushed"); + sum[i] = damageum(mon, mattk); + } else if (i >= 2 && sum[i - 1] && sum[i - 2]) { + You("grab %s!", mon_nam(mon)); + u.ustuck = mon; + sum[i] = damageum(mon, mattk); + } + } + break; - case AT_EXPL: /* automatic hit if next to */ - dhit = -1; - wakeup(mon); - sum[i] = explum(mon, mattk); - break; + case AT_EXPL: /* automatic hit if next to */ + dhit = -1; + wakeup(mon); + sum[i] = explum(mon, mattk); + break; - case AT_ENGL: - tmp = find_roll_to_hit(mon, mattk->aatyp, - (struct obj *)0, - &attknum, &armorpenalty); - if((dhit = (tmp > rnd(20+i)))) { - wakeup(mon); - if (mon->data == &mons[PM_SHADE]) - Your("attempt to surround %s is harmless.", - mon_nam(mon)); - else { - sum[i]= gulpum(mon,mattk); - if (sum[i] == 2 && - (mon->data->mlet == S_ZOMBIE || - mon->data->mlet == S_MUMMY) && - rn2(5) && - !Sick_resistance) { - You_feel("%ssick.", - (Sick) ? "very " : ""); - mdamageu(mon, rnd(8)); - } - } - } else { - missum(mon, mattk, FALSE); - } - break; + case AT_ENGL: + tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0, + &attknum, &armorpenalty); + if ((dhit = (tmp > rnd(20 + i)))) { + wakeup(mon); + if (mon->data == &mons[PM_SHADE]) + Your("attempt to surround %s is harmless.", mon_nam(mon)); + else { + sum[i] = gulpum(mon, mattk); + if (sum[i] == 2 && (mon->data->mlet == S_ZOMBIE + || mon->data->mlet == S_MUMMY) + && rn2(5) && !Sick_resistance) { + You_feel("%ssick.", (Sick) ? "very " : ""); + mdamageu(mon, rnd(8)); + } + } + } else { + missum(mon, mattk, FALSE); + } + break; - case AT_MAGC: - /* No check for uwep; if wielding nothing we want to - * do the normal 1-2 points bare hand damage... - */ - if ((youmonst.data->mlet == S_KOBOLD || - youmonst.data->mlet == S_ORC || - youmonst.data->mlet == S_GNOME) && - !weapon_used) goto use_weapon; + case AT_MAGC: + /* No check for uwep; if wielding nothing we want to + * do the normal 1-2 points bare hand damage... + */ + if ((youmonst.data->mlet == S_KOBOLD + || youmonst.data->mlet == S_ORC + || youmonst.data->mlet == S_GNOME) && !weapon_used) + goto use_weapon; - case AT_NONE: - case AT_BOOM: - continue; - /* Not break--avoid passive attacks from enemy */ + case AT_NONE: + case AT_BOOM: + continue; + /* Not break--avoid passive attacks from enemy */ - case AT_BREA: - case AT_SPIT: - case AT_GAZE: /* all done using #monster command */ - dhit = 0; - break; + case AT_BREA: + case AT_SPIT: + case AT_GAZE: /* all done using #monster command */ + dhit = 0; + break; - default: /* Strange... */ - impossible("strange attack of yours (%d)", - mattk->aatyp); - } - if (dhit == -1) { - u.mh = -1; /* dead in the current form */ - rehumanize(); - } - if (sum[i] == 2) - return((boolean)passive(mon, 1, 0, mattk->aatyp, FALSE)); - /* defender dead */ - else { - (void) passive(mon, sum[i], 1, mattk->aatyp, FALSE); - nsum |= sum[i]; - } - if (!Upolyd) - break; /* No extra attacks if no longer a monster */ - if (multi < 0) - break; /* If paralyzed while attacking, i.e. floating eye */ - } - return((boolean)(nsum != 0)); + default: /* Strange... */ + impossible("strange attack of yours (%d)", mattk->aatyp); + } + if (dhit == -1) { + u.mh = -1; /* dead in the current form */ + rehumanize(); + } + if (sum[i] == 2) + return ((boolean) passive(mon, 1, 0, mattk->aatyp, FALSE)); + /* defender dead */ + else { + (void) passive(mon, sum[i], 1, mattk->aatyp, FALSE); + nsum |= sum[i]; + } + if (!Upolyd) + break; /* No extra attacks if no longer a monster */ + if (multi < 0) + break; /* If paralyzed while attacking, i.e. floating eye */ + } + return ((boolean)(nsum != 0)); } /* Special (passive) attacks on you by monsters done here. */ @@ -2198,223 +2267,227 @@ register int malive; uchar aatyp; boolean wep_was_destroyed; { - register struct permonst *ptr = mon->data; - register int i, tmp; + register struct permonst *ptr = mon->data; + register int i, tmp; - for(i = 0; ; i++) { - if(i >= NATTK) return(malive | mhit); /* no passive attacks */ - if(ptr->mattk[i].aatyp == AT_NONE) break; /* try this one */ - } - /* Note: tmp not always used */ - if (ptr->mattk[i].damn) - tmp = d((int)ptr->mattk[i].damn, (int)ptr->mattk[i].damd); - else if(ptr->mattk[i].damd) - tmp = d((int)mon->m_lev+1, (int)ptr->mattk[i].damd); - else - tmp = 0; + for (i = 0;; i++) { + if (i >= NATTK) + return (malive | mhit); /* no passive attacks */ + if (ptr->mattk[i].aatyp == AT_NONE) + break; /* try this one */ + } + /* Note: tmp not always used */ + if (ptr->mattk[i].damn) + tmp = d((int) ptr->mattk[i].damn, (int) ptr->mattk[i].damd); + else if (ptr->mattk[i].damd) + tmp = d((int) mon->m_lev + 1, (int) ptr->mattk[i].damd); + else + tmp = 0; -/* These affect you even if they just died */ + /* These affect you even if they just died */ - switch(ptr->mattk[i].adtyp) { + switch (ptr->mattk[i].adtyp) { + case AD_FIRE: + if (mhit && !mon->mcan) { + if (aatyp == AT_KICK) { + if (uarmf && !rn2(6)) + (void) erode_obj(uarmf, xname(uarmf), ERODE_BURN, + EF_GREASE | EF_VERBOSE); + } else if (aatyp == AT_WEAP || aatyp == AT_CLAW + || aatyp == AT_MAGC || aatyp == AT_TUCH) + passive_obj(mon, (struct obj *) 0, &(ptr->mattk[i])); + } + break; - case AD_FIRE: - if(mhit && !mon->mcan) { - if (aatyp == AT_KICK) { - if (uarmf && !rn2(6)) - (void)erode_obj(uarmf, xname(uarmf), ERODE_BURN, - EF_GREASE | EF_VERBOSE); - } else if (aatyp == AT_WEAP || aatyp == AT_CLAW || - aatyp == AT_MAGC || aatyp == AT_TUCH) - passive_obj(mon, (struct obj*)0, &(ptr->mattk[i])); - } - break; + case AD_ACID: + if (mhit && rn2(2)) { + if (Blind || !flags.verbose) + You("are splashed!"); + else + You("are splashed by %s acid!", s_suffix(mon_nam(mon))); - case AD_ACID: - if(mhit && rn2(2)) { - if (Blind || !flags.verbose) You("are splashed!"); - else You("are splashed by %s acid!", - s_suffix(mon_nam(mon))); + if (!Acid_resistance) + mdamageu(mon, tmp); + if (!rn2(30)) + erode_armor(&youmonst, ERODE_CORRODE); + } + if (mhit) { + if (aatyp == AT_KICK) { + if (uarmf && !rn2(6)) + (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, + EF_GREASE | EF_VERBOSE); + } else if (aatyp == AT_WEAP || aatyp == AT_CLAW + || aatyp == AT_MAGC || aatyp == AT_TUCH) + passive_obj(mon, (struct obj *) 0, &(ptr->mattk[i])); + } + exercise(A_STR, FALSE); + break; + case AD_STON: + if (mhit) { /* successful attack */ + long protector = attk_protection((int) aatyp); - if (!Acid_resistance) - mdamageu(mon, tmp); - if(!rn2(30)) erode_armor(&youmonst, ERODE_CORRODE); - } - if (mhit) { - if (aatyp == AT_KICK) { - if (uarmf && !rn2(6)) - (void)erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, - EF_GREASE | EF_VERBOSE); - } else if (aatyp == AT_WEAP || aatyp == AT_CLAW || - aatyp == AT_MAGC || aatyp == AT_TUCH) - passive_obj(mon, (struct obj*)0, &(ptr->mattk[i])); - } - exercise(A_STR, FALSE); - break; - case AD_STON: - if (mhit) { /* successful attack */ - long protector = attk_protection((int)aatyp); + /* hero using monsters' AT_MAGC attack is hitting hand to + hand rather than casting a spell */ + if (aatyp == AT_MAGC) + protector = W_ARMG; - /* hero using monsters' AT_MAGC attack is hitting hand to - hand rather than casting a spell */ - if (aatyp == AT_MAGC) protector = W_ARMG; + if (protector == 0L || /* no protection */ + (protector == W_ARMG && !uarmg && !uwep && !wep_was_destroyed) + || (protector == W_ARMF && !uarmf) + || (protector == W_ARMH && !uarmh) + || (protector == (W_ARMC | W_ARMG) && (!uarmc || !uarmg))) { + if (!Stone_resistance + && !(poly_when_stoned(youmonst.data) + && polymon(PM_STONE_GOLEM))) { + done_in_by(mon, STONING); /* "You turn to stone..." */ + return 2; + } + } + } + break; + case AD_RUST: + if (mhit && !mon->mcan) { + if (aatyp == AT_KICK) { + if (uarmf) + (void) erode_obj(uarmf, xname(uarmf), ERODE_RUST, + EF_GREASE | EF_VERBOSE); + } else if (aatyp == AT_WEAP || aatyp == AT_CLAW + || aatyp == AT_MAGC || aatyp == AT_TUCH) + passive_obj(mon, (struct obj *) 0, &(ptr->mattk[i])); + } + break; + case AD_CORR: + if (mhit && !mon->mcan) { + if (aatyp == AT_KICK) { + if (uarmf) + (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, + EF_GREASE | EF_VERBOSE); + } else if (aatyp == AT_WEAP || aatyp == AT_CLAW + || aatyp == AT_MAGC || aatyp == AT_TUCH) + passive_obj(mon, (struct obj *) 0, &(ptr->mattk[i])); + } + break; + case AD_MAGM: + /* wrath of gods for attacking Oracle */ + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline("A hail of magic missiles narrowly misses you!"); + } else { + You("are hit by magic missiles appearing from thin air!"); + mdamageu(mon, tmp); + } + break; + case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ + if (mhit) { + struct obj *obj = (struct obj *) 0; - if (protector == 0L || /* no protection */ - (protector == W_ARMG && !uarmg && !uwep && !wep_was_destroyed) || - (protector == W_ARMF && !uarmf) || - (protector == W_ARMH && !uarmh) || - (protector == (W_ARMC|W_ARMG) && (!uarmc || !uarmg))) { - if (!Stone_resistance && - !(poly_when_stoned(youmonst.data) && - polymon(PM_STONE_GOLEM))) { - done_in_by(mon, STONING); /* "You turn to stone..." */ - return 2; - } - } - } - break; - case AD_RUST: - if(mhit && !mon->mcan) { - if (aatyp == AT_KICK) { - if (uarmf) - (void)erode_obj(uarmf, xname(uarmf), ERODE_RUST, - EF_GREASE | EF_VERBOSE); - } else if (aatyp == AT_WEAP || aatyp == AT_CLAW || - aatyp == AT_MAGC || aatyp == AT_TUCH) - passive_obj(mon, (struct obj*)0, &(ptr->mattk[i])); - } - break; - case AD_CORR: - if(mhit && !mon->mcan) { - if (aatyp == AT_KICK) { - if (uarmf) - (void)erode_obj(uarmf, xname(uarmf), ERODE_CORRODE, - EF_GREASE | EF_VERBOSE); - } else if (aatyp == AT_WEAP || aatyp == AT_CLAW || - aatyp == AT_MAGC || aatyp == AT_TUCH) - passive_obj(mon, (struct obj*)0, &(ptr->mattk[i])); - } - break; - case AD_MAGM: - /* wrath of gods for attacking Oracle */ - if(Antimagic) { - shieldeff(u.ux, u.uy); - pline("A hail of magic missiles narrowly misses you!"); - } else { - You("are hit by magic missiles appearing from thin air!"); - mdamageu(mon, tmp); - } - break; - case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */ - if (mhit) { - struct obj *obj = (struct obj *)0; + if (aatyp == AT_KICK) { + obj = uarmf; + if (!obj) + break; + } else if (aatyp == AT_BITE || aatyp == AT_BUTT + || (aatyp >= AT_STNG && aatyp < AT_WEAP)) { + break; /* no object involved */ + } + passive_obj(mon, obj, &(ptr->mattk[i])); + } + break; + default: + break; + } - if (aatyp == AT_KICK) { - obj = uarmf; - if (!obj) break; - } else if (aatyp == AT_BITE || aatyp == AT_BUTT || - (aatyp >= AT_STNG && aatyp < AT_WEAP)) { - break; /* no object involved */ - } - passive_obj(mon, obj, &(ptr->mattk[i])); - } - break; - default: - break; - } + /* These only affect you if they still live */ -/* These only affect you if they still live */ - - if(malive && !mon->mcan && rn2(3)) { - - switch(ptr->mattk[i].adtyp) { - - case AD_PLYS: - if(ptr == &mons[PM_FLOATING_EYE]) { - if (!canseemon(mon)) { - break; - } - if(mon->mcansee) { - if (ureflects("%s gaze is reflected by your %s.", - s_suffix(Monnam(mon)))) - ; - else if (Free_action) - You("momentarily stiffen under %s gaze!", - s_suffix(mon_nam(mon))); - else if (Hallucination && rn2(4)) - pline("%s looks %s%s.", Monnam(mon), - !rn2(2) ? "" : "rather ", - !rn2(2) ? "numb" : "stupified"); - else { - You("are frozen by %s gaze!", - s_suffix(mon_nam(mon))); - nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127); - multi_reason = "frozen by a monster's gaze"; - nomovemsg = 0; - } - } else { - pline("%s cannot defend itself.", - Adjmonnam(mon,"blind")); - if(!rn2(500)) change_luck(-1); - } - } else if (Free_action) { - You("momentarily stiffen."); - } else { /* gelatinous cube */ - You("are frozen by %s!", mon_nam(mon)); - nomovemsg = You_can_move_again; - nomul(-tmp); - multi_reason = "frozen by a monster"; - exercise(A_DEX, FALSE); - } - break; - case AD_COLD: /* brown mold or blue jelly */ - if(monnear(mon, u.ux, u.uy)) { - if(Cold_resistance) { - shieldeff(u.ux, u.uy); - You_feel("a mild chill."); - ugolemeffects(AD_COLD, tmp); - break; - } - You("are suddenly very cold!"); - mdamageu(mon, tmp); - /* monster gets stronger with your heat! */ - mon->mhp += tmp / 2; - if (mon->mhpmax < mon->mhp) mon->mhpmax = mon->mhp; - /* at a certain point, the monster will reproduce! */ - if(mon->mhpmax > ((int) (mon->m_lev+1) * 8)) - (void)split_mon(mon, &youmonst); - } - break; - case AD_STUN: /* specifically yellow mold */ - if(!Stunned) - make_stunned((long)tmp, TRUE); - break; - case AD_FIRE: - if(monnear(mon, u.ux, u.uy)) { - if(Fire_resistance) { - shieldeff(u.ux, u.uy); - You_feel("mildly warm."); - ugolemeffects(AD_FIRE, tmp); - break; - } - You("are suddenly very hot!"); - mdamageu(mon, tmp); /* fire damage */ - } - break; - case AD_ELEC: - if(Shock_resistance) { - shieldeff(u.ux, u.uy); - You_feel("a mild tingle."); - ugolemeffects(AD_ELEC, tmp); - break; - } - You("are jolted with electricity!"); - mdamageu(mon, tmp); - break; - default: - break; - } - } - return(malive | mhit); + if (malive && !mon->mcan && rn2(3)) { + switch (ptr->mattk[i].adtyp) { + case AD_PLYS: + if (ptr == &mons[PM_FLOATING_EYE]) { + if (!canseemon(mon)) { + break; + } + if (mon->mcansee) { + if (ureflects("%s gaze is reflected by your %s.", + s_suffix(Monnam(mon)))) + ; + else if (Free_action) + You("momentarily stiffen under %s gaze!", + s_suffix(mon_nam(mon))); + else if (Hallucination && rn2(4)) + pline("%s looks %s%s.", Monnam(mon), + !rn2(2) ? "" : "rather ", + !rn2(2) ? "numb" : "stupified"); + else { + You("are frozen by %s gaze!", s_suffix(mon_nam(mon))); + nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127); + multi_reason = "frozen by a monster's gaze"; + nomovemsg = 0; + } + } else { + pline("%s cannot defend itself.", + Adjmonnam(mon, "blind")); + if (!rn2(500)) + change_luck(-1); + } + } else if (Free_action) { + You("momentarily stiffen."); + } else { /* gelatinous cube */ + You("are frozen by %s!", mon_nam(mon)); + nomovemsg = You_can_move_again; + nomul(-tmp); + multi_reason = "frozen by a monster"; + exercise(A_DEX, FALSE); + } + break; + case AD_COLD: /* brown mold or blue jelly */ + if (monnear(mon, u.ux, u.uy)) { + if (Cold_resistance) { + shieldeff(u.ux, u.uy); + You_feel("a mild chill."); + ugolemeffects(AD_COLD, tmp); + break; + } + You("are suddenly very cold!"); + mdamageu(mon, tmp); + /* monster gets stronger with your heat! */ + mon->mhp += tmp / 2; + if (mon->mhpmax < mon->mhp) + mon->mhpmax = mon->mhp; + /* at a certain point, the monster will reproduce! */ + if (mon->mhpmax > ((int) (mon->m_lev + 1) * 8)) + (void) split_mon(mon, &youmonst); + } + break; + case AD_STUN: /* specifically yellow mold */ + if (!Stunned) + make_stunned((long) tmp, TRUE); + break; + case AD_FIRE: + if (monnear(mon, u.ux, u.uy)) { + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + You_feel("mildly warm."); + ugolemeffects(AD_FIRE, tmp); + break; + } + You("are suddenly very hot!"); + mdamageu(mon, tmp); /* fire damage */ + } + break; + case AD_ELEC: + if (Shock_resistance) { + shieldeff(u.ux, u.uy); + You_feel("a mild tingle."); + ugolemeffects(AD_ELEC, tmp); + break; + } + You("are jolted with electricity!"); + mdamageu(mon, tmp); + break; + default: + break; + } + } + return (malive | mhit); } /* @@ -2424,64 +2497,67 @@ boolean wep_was_destroyed; void passive_obj(mon, obj, mattk) register struct monst *mon; -register struct obj *obj; /* null means pick uwep, uswapwep or uarmg */ -struct attack *mattk; /* null means we find one internally */ +register struct obj *obj; /* null means pick uwep, uswapwep or uarmg */ +struct attack *mattk; /* null means we find one internally */ { - register struct permonst *ptr = mon->data; - register int i; + register struct permonst *ptr = mon->data; + register int i; - /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */ - if (!obj) { - obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep; - if (!obj && mattk->adtyp == AD_ENCH) - obj = uarmg; /* no weapon? then must be gloves */ - if (!obj) return; /* no object to affect */ - } + /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */ + if (!obj) { + obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep; + if (!obj && mattk->adtyp == AD_ENCH) + obj = uarmg; /* no weapon? then must be gloves */ + if (!obj) + return; /* no object to affect */ + } - /* if caller hasn't specified an attack, find one */ - if (!mattk) { - for(i = 0; ; i++) { - if(i >= NATTK) return; /* no passive attacks */ - if(ptr->mattk[i].aatyp == AT_NONE) break; /* try this one */ - } - mattk = &(ptr->mattk[i]); - } + /* if caller hasn't specified an attack, find one */ + if (!mattk) { + for (i = 0;; i++) { + if (i >= NATTK) + return; /* no passive attacks */ + if (ptr->mattk[i].aatyp == AT_NONE) + break; /* try this one */ + } + mattk = &(ptr->mattk[i]); + } - switch(mattk->adtyp) { + switch (mattk->adtyp) { + case AD_FIRE: + if (!rn2(6) && !mon->mcan) { + (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE); + } + break; + case AD_ACID: + if (!rn2(6)) { + (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE); + } + break; + case AD_RUST: + if (!mon->mcan) { + (void) erode_obj(obj, NULL, ERODE_RUST, EF_NONE); + } + break; + case AD_CORR: + if (!mon->mcan) { + (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE); + } + break; + case AD_ENCH: + if (!mon->mcan) { + if (drain_item(obj) && carried(obj) + && (obj->known || obj->oclass == ARMOR_CLASS)) { + pline("%s less effective.", Yobjnam2(obj, "seem")); + } + break; + } + default: + break; + } - case AD_FIRE: - if(!rn2(6) && !mon->mcan) { - (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE); - } - break; - case AD_ACID: - if(!rn2(6)) { - (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE); - } - break; - case AD_RUST: - if(!mon->mcan) { - (void) erode_obj(obj, NULL, ERODE_RUST, EF_NONE); - } - break; - case AD_CORR: - if(!mon->mcan) { - (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE); - } - break; - case AD_ENCH: - if (!mon->mcan) { - if (drain_item(obj) && carried(obj) && - (obj->known || obj->oclass == ARMOR_CLASS)) { - pline("%s less effective.", Yobjnam2(obj, "seem")); - } - break; - } - default: - break; - } - - if (carried(obj)) update_inventory(); + if (carried(obj)) + update_inventory(); } /* Note: caller must ascertain mtmp is mimicking... */ @@ -2489,104 +2565,102 @@ void stumble_onto_mimic(mtmp) struct monst *mtmp; { - const char *fmt = "Wait! That's %s!", - *generic = "a monster", - *what = 0; + const char *fmt = "Wait! That's %s!", *generic = "a monster", *what = 0; - if(!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data,AD_STCK)) - u.ustuck = mtmp; + if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)) + u.ustuck = mtmp; - if (Blind) { - if (!Blind_telepat) - what = generic; /* with default fmt */ - else if (mtmp->m_ap_type == M_AP_MONSTER) - what = a_monnam(mtmp); /* differs from what was sensed */ - } else { - int glyph = levl[u.ux+u.dx][u.uy+u.dy].glyph; + if (Blind) { + if (!Blind_telepat) + what = generic; /* with default fmt */ + else if (mtmp->m_ap_type == M_AP_MONSTER) + what = a_monnam(mtmp); /* differs from what was sensed */ + } else { + int glyph = levl[u.ux + u.dx][u.uy + u.dy].glyph; - if (glyph_is_cmap(glyph) && - (glyph_to_cmap(glyph) == S_hcdoor || - glyph_to_cmap(glyph) == S_vcdoor)) - fmt = "The door actually was %s!"; - else if (glyph_is_object(glyph) && - glyph_to_obj(glyph) == GOLD_PIECE) - fmt = "That gold was %s!"; + if (glyph_is_cmap(glyph) && (glyph_to_cmap(glyph) == S_hcdoor + || glyph_to_cmap(glyph) == S_vcdoor)) + fmt = "The door actually was %s!"; + else if (glyph_is_object(glyph) && glyph_to_obj(glyph) == GOLD_PIECE) + fmt = "That gold was %s!"; - /* cloned Wiz starts out mimicking some other monster and - might make himself invisible before being revealed */ - if (mtmp->minvis && !See_invisible) - what = generic; - else - what = a_monnam(mtmp); - } - if (what) pline(fmt, what); + /* cloned Wiz starts out mimicking some other monster and + might make himself invisible before being revealed */ + if (mtmp->minvis && !See_invisible) + what = generic; + else + what = a_monnam(mtmp); + } + if (what) + pline(fmt, what); - wakeup(mtmp); /* clears mimicking */ - /* if hero is blind, wakeup() won't display the monster even though - it's no longer concealed */ - if (!canspotmon(mtmp) && - !glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) - map_invisible(mtmp->mx, mtmp->my); + wakeup(mtmp); /* clears mimicking */ + /* if hero is blind, wakeup() won't display the monster even though + it's no longer concealed */ + if (!canspotmon(mtmp) + && !glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) + map_invisible(mtmp->mx, mtmp->my); } STATIC_OVL void nohandglow(mon) struct monst *mon; { - char *hands=makeplural(body_part(HAND)); + char *hands = makeplural(body_part(HAND)); - if (!u.umconf || mon->mconf) return; - if (u.umconf == 1) { - if (Blind) - Your("%s stop tingling.", hands); - else - Your("%s stop glowing %s.", hands, hcolor(NH_RED)); - } else { - if (Blind) - pline_The("tingling in your %s lessens.", hands); - else - Your("%s no longer glow so brightly %s.", hands, - hcolor(NH_RED)); - } - u.umconf--; + if (!u.umconf || mon->mconf) + return; + if (u.umconf == 1) { + if (Blind) + Your("%s stop tingling.", hands); + else + Your("%s stop glowing %s.", hands, hcolor(NH_RED)); + } else { + if (Blind) + pline_The("tingling in your %s lessens.", hands); + else + Your("%s no longer glow so brightly %s.", hands, hcolor(NH_RED)); + } + u.umconf--; } int flash_hits_mon(mtmp, otmp) struct monst *mtmp; -struct obj *otmp; /* source of flash */ +struct obj *otmp; /* source of flash */ { - int tmp, amt, res = 0, useeit = canseemon(mtmp); + int tmp, amt, res = 0, useeit = canseemon(mtmp); - if (mtmp->msleeping) { - mtmp->msleeping = 0; - if (useeit) { - pline_The("flash awakens %s.", mon_nam(mtmp)); - res = 1; - } - } else if (mtmp->data->mlet != S_LIGHT) { - if (!resists_blnd(mtmp)) { - tmp = dist2(otmp->ox, otmp->oy, mtmp->mx, mtmp->my); - if (useeit) { - pline("%s is blinded by the flash!", Monnam(mtmp)); - res = 1; - } - if (mtmp->data == &mons[PM_GREMLIN]) { - /* Rule #1: Keep them out of the light. */ - amt = otmp->otyp == WAN_LIGHT ? d(1 + otmp->spe, 4) : - rn2(min(mtmp->mhp,4)); - light_hits_gremlin(mtmp, amt); - } - if (mtmp->mhp > 0) { - if (!context.mon_moving) setmangry(mtmp); - if (tmp < 9 && !mtmp->isshk && rn2(4)) - monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE); - mtmp->mcansee = 0; - mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50/tmp); - } - } - } - return res; + if (mtmp->msleeping) { + mtmp->msleeping = 0; + if (useeit) { + pline_The("flash awakens %s.", mon_nam(mtmp)); + res = 1; + } + } else if (mtmp->data->mlet != S_LIGHT) { + if (!resists_blnd(mtmp)) { + tmp = dist2(otmp->ox, otmp->oy, mtmp->mx, mtmp->my); + if (useeit) { + pline("%s is blinded by the flash!", Monnam(mtmp)); + res = 1; + } + if (mtmp->data == &mons[PM_GREMLIN]) { + /* Rule #1: Keep them out of the light. */ + amt = otmp->otyp == WAN_LIGHT ? d(1 + otmp->spe, 4) + : rn2(min(mtmp->mhp, 4)); + light_hits_gremlin(mtmp, amt); + } + if (mtmp->mhp > 0) { + if (!context.mon_moving) + setmangry(mtmp); + if (tmp < 9 && !mtmp->isshk && rn2(4)) + monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE); + mtmp->mcansee = 0; + mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50 / tmp); + } + } + } + return res; } void @@ -2595,14 +2669,14 @@ struct monst *mon; int dmg; { pline("%s %s!", Monnam(mon), - (dmg > mon->mhp / 2) ? "wails in agony" : "cries out in pain"); + (dmg > mon->mhp / 2) ? "wails in agony" : "cries out in pain"); if ((mon->mhp -= dmg) <= 0) { - if (context.mon_moving) - monkilled(mon, (char *)0, AD_BLND); - else - killed(mon); + if (context.mon_moving) + monkilled(mon, (char *) 0, AD_BLND); + else + killed(mon); } else if (cansee(mon->mx, mon->my) && !canspotmon(mon)) { - map_invisible(mon->mx, mon->my); + map_invisible(mon->mx, mon->my); } } diff --git a/src/vault.c b/src/vault.c index 906b311a4..d82bdd662 100644 --- a/src/vault.c +++ b/src/vault.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vault.c $NHDT-Date: 1429584309 2015/04/21 02:45:09 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */ +/* NetHack 3.6 vault.c $NHDT-Date: 1431192768 2015/05/09 17:32:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.36 $ */ /* NetHack 3.6 vault.c $Date: 2011/10/13 00:31:10 $ $Revision: 1.28 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,33 +7,34 @@ STATIC_DCL struct monst *NDECL(findgd); -STATIC_DCL boolean FDECL(clear_fcorr, (struct monst *,BOOLEAN_P)); -STATIC_DCL void FDECL(blackout, (int,int)); -STATIC_DCL void FDECL(restfakecorr,(struct monst *)); -STATIC_DCL boolean FDECL(in_fcorridor, (struct monst *,int,int)); -STATIC_DCL void FDECL(move_gold,(struct obj *,int)); -STATIC_DCL void FDECL(wallify_vault,(struct monst *)); +STATIC_DCL boolean FDECL(clear_fcorr, (struct monst *, BOOLEAN_P)); +STATIC_DCL void FDECL(blackout, (int, int)); +STATIC_DCL void FDECL(restfakecorr, (struct monst *)); +STATIC_DCL boolean FDECL(in_fcorridor, (struct monst *, int, int)); +STATIC_DCL void FDECL(move_gold, (struct obj *, int)); +STATIC_DCL void FDECL(wallify_vault, (struct monst *)); void newegd(mtmp) struct monst *mtmp; { - if (!mtmp->mextra) mtmp->mextra = newmextra(); - if (!EGD(mtmp)) { - EGD(mtmp) = (struct egd *)alloc(sizeof(struct egd)); - (void) memset((genericptr_t) EGD(mtmp), 0, sizeof(struct egd)); - } + if (!mtmp->mextra) + mtmp->mextra = newmextra(); + if (!EGD(mtmp)) { + EGD(mtmp) = (struct egd *) alloc(sizeof(struct egd)); + (void) memset((genericptr_t) EGD(mtmp), 0, sizeof(struct egd)); + } } void free_egd(mtmp) struct monst *mtmp; { - if (mtmp->mextra && EGD(mtmp)) { - free((genericptr_t) EGD(mtmp)); - EGD(mtmp) = (struct egd *)0; - } - mtmp->isgd = 0; + if (mtmp->mextra && EGD(mtmp)) { + free((genericptr_t) EGD(mtmp)); + EGD(mtmp) = (struct egd *) 0; + } + mtmp->isgd = 0; } STATIC_OVL boolean @@ -41,57 +42,61 @@ clear_fcorr(grd, forceshow) struct monst *grd; boolean forceshow; { - register int fcx, fcy, fcbeg; - struct monst *mtmp; - boolean sawcorridor = FALSE; - struct egd *egrd = EGD(grd); - struct trap *trap; - struct rm *lev; + register int fcx, fcy, fcbeg; + struct monst *mtmp; + boolean sawcorridor = FALSE; + struct egd *egrd = EGD(grd); + struct trap *trap; + struct rm *lev; - if (!on_level(&egrd->gdlevel, &u.uz)) return TRUE; + if (!on_level(&egrd->gdlevel, &u.uz)) + return TRUE; - while ((fcbeg = egrd->fcbeg) < egrd->fcend) { - fcx = egrd->fakecorr[fcbeg].fx; - fcy = egrd->fakecorr[fcbeg].fy; - if((grd->mhp <= 0 || !in_fcorridor(grd, u.ux, u.uy)) && - egrd->gddone) - forceshow = TRUE; - if((u.ux == fcx && u.uy == fcy && grd->mhp > 0) - || (!forceshow && couldsee(fcx,fcy)) - || (Punished && !carried(uball) - && uball->ox == fcx && uball->oy == fcy)) - return FALSE; + while ((fcbeg = egrd->fcbeg) < egrd->fcend) { + fcx = egrd->fakecorr[fcbeg].fx; + fcy = egrd->fakecorr[fcbeg].fy; + if ((grd->mhp <= 0 || !in_fcorridor(grd, u.ux, u.uy)) && egrd->gddone) + forceshow = TRUE; + if ((u.ux == fcx && u.uy == fcy && grd->mhp > 0) + || (!forceshow && couldsee(fcx, fcy)) + || (Punished && !carried(uball) && uball->ox == fcx + && uball->oy == fcy)) + return FALSE; - if ((mtmp = m_at(fcx,fcy)) != 0) { - if (mtmp->isgd) { - return FALSE; - } else if (!in_fcorridor(grd, u.ux, u.uy)) { - if (mtmp->mtame) yelp(mtmp); - (void) rloc(mtmp, FALSE); - } - } - lev = &levl[fcx][fcy]; - if (lev->typ == CORR && cansee(fcx, fcy)) - sawcorridor = TRUE; - lev->typ = egrd->fakecorr[fcbeg].ftyp; - if (IS_STWALL(lev->typ)) { - /* destroy any trap here (pit dug by you, hole dug via - wand while levitating or by monster, bear trap or land - mine via object, spun web) when spot reverts to stone */ - if ((trap = t_at(fcx, fcy)) != 0) deltrap(trap); - /* undo scroll/wand/spell of light affecting this spot */ - if (lev->typ == STONE) blackout(fcx, fcy); - } - map_location(fcx, fcy, 1); /* bypass vision */ - if (!ACCESSIBLE(lev->typ)) block_point(fcx, fcy); - vision_full_recalc = 1; - egrd->fcbeg++; - } - if (sawcorridor) - pline_The("corridor disappears."); - if (IS_ROCK(levl[u.ux][u.uy].typ)) - You("are encased in rock."); - return TRUE; + if ((mtmp = m_at(fcx, fcy)) != 0) { + if (mtmp->isgd) { + return FALSE; + } else if (!in_fcorridor(grd, u.ux, u.uy)) { + if (mtmp->mtame) + yelp(mtmp); + (void) rloc(mtmp, FALSE); + } + } + lev = &levl[fcx][fcy]; + if (lev->typ == CORR && cansee(fcx, fcy)) + sawcorridor = TRUE; + lev->typ = egrd->fakecorr[fcbeg].ftyp; + if (IS_STWALL(lev->typ)) { + /* destroy any trap here (pit dug by you, hole dug via + wand while levitating or by monster, bear trap or land + mine via object, spun web) when spot reverts to stone */ + if ((trap = t_at(fcx, fcy)) != 0) + deltrap(trap); + /* undo scroll/wand/spell of light affecting this spot */ + if (lev->typ == STONE) + blackout(fcx, fcy); + } + map_location(fcx, fcy, 1); /* bypass vision */ + if (!ACCESSIBLE(lev->typ)) + block_point(fcx, fcy); + vision_full_recalc = 1; + egrd->fcbeg++; + } + if (sawcorridor) + pline_The("corridor disappears."); + if (IS_ROCK(levl[u.ux][u.uy].typ)) + You("are encased in rock."); + return TRUE; } /* as a temporary corridor is removed, set stone locations and adjacent @@ -106,53 +111,54 @@ int x, y; int i, j; for (i = x - 1; i <= x + 1; ++i) - for (j = y - 1; j <= y + 1; ++j) { - if (!isok(i, j)) continue; - lev = &levl[i][j]; - /* [possible bug: when (i != x || j != y), perhaps we ought - to check whether the spot on the far side is lit instead - of doing a blanket blackout of adjacent locations] */ - if (lev->typ == STONE) - lev->lit = lev->waslit = 0; - /* mark as not having been seen from */ - unset_seenv(lev, x, y, i, j); - } + for (j = y - 1; j <= y + 1; ++j) { + if (!isok(i, j)) + continue; + lev = &levl[i][j]; + /* [possible bug: when (i != x || j != y), perhaps we ought + to check whether the spot on the far side is lit instead + of doing a blanket blackout of adjacent locations] */ + if (lev->typ == STONE) + lev->lit = lev->waslit = 0; + /* mark as not having been seen from */ + unset_seenv(lev, x, y, i, j); + } } STATIC_OVL void restfakecorr(grd) register struct monst *grd; { - /* it seems you left the corridor - let the guard disappear */ - if (clear_fcorr(grd, FALSE)) { - grd->isgd = 0; /* dmonsfree() should delete this mon */ - mongone(grd); - } + /* it seems you left the corridor - let the guard disappear */ + if (clear_fcorr(grd, FALSE)) { + grd->isgd = 0; /* dmonsfree() should delete this mon */ + mongone(grd); + } } -boolean -grddead(grd) /* called in mon.c */ +boolean grddead(grd) /* called in mon.c */ register struct monst *grd; { - register boolean dispose = clear_fcorr(grd, TRUE); + register boolean dispose = clear_fcorr(grd, TRUE); - if (!dispose) { - /* destroy guard's gold; drop any other inventory */ - relobj(grd, 0, FALSE); - /* guard is dead; monster traversal loops should skip it */ - grd->mhp = 0; - if (grd == context.polearm.hitmon) - context.polearm.hitmon = 0; - /* see comment by newpos in gd_move() */ - remove_monster(grd->mx, grd->my); - newsym(grd->mx, grd->my); - place_monster(grd, 0, 0); - EGD(grd)->ogx = grd->mx; - EGD(grd)->ogy = grd->my; - dispose = clear_fcorr(grd, TRUE); - } - if (dispose) grd->isgd = 0; /* for dmonsfree() */ - return dispose; + if (!dispose) { + /* destroy guard's gold; drop any other inventory */ + relobj(grd, 0, FALSE); + /* guard is dead; monster traversal loops should skip it */ + grd->mhp = 0; + if (grd == context.polearm.hitmon) + context.polearm.hitmon = 0; + /* see comment by newpos in gd_move() */ + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, 0, 0); + EGD(grd)->ogx = grd->mx; + EGD(grd)->ogy = grd->my; + dispose = clear_fcorr(grd, TRUE); + } + if (dispose) + grd->isgd = 0; /* for dmonsfree() */ + return dispose; } STATIC_OVL boolean @@ -160,255 +166,284 @@ in_fcorridor(grd, x, y) register struct monst *grd; int x, y; { - register int fci; + register int fci; - for(fci = EGD(grd)->fcbeg; fci < EGD(grd)->fcend; fci++) - if(x == EGD(grd)->fakecorr[fci].fx && - y == EGD(grd)->fakecorr[fci].fy) - return(TRUE); - return(FALSE); + for (fci = EGD(grd)->fcbeg; fci < EGD(grd)->fcend; fci++) + if (x == EGD(grd)->fakecorr[fci].fx + && y == EGD(grd)->fakecorr[fci].fy) + return (TRUE); + return (FALSE); } STATIC_OVL struct monst * findgd() { - register struct monst *mtmp; + register struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->isgd && on_level(&(EGD(mtmp)->gdlevel), &u.uz)) - return(mtmp); - } - return((struct monst *)0); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->isgd && on_level(&(EGD(mtmp)->gdlevel), &u.uz)) + return (mtmp); + } + return ((struct monst *) 0); } char vault_occupied(array) char *array; { - register char *ptr; + register char *ptr; - for (ptr = array; *ptr; ptr++) - if (rooms[*ptr - ROOMOFFSET].rtype == VAULT) - return(*ptr); - return('\0'); + for (ptr = array; *ptr; ptr++) + if (rooms[*ptr - ROOMOFFSET].rtype == VAULT) + return (*ptr); + return ('\0'); } void invault() { #ifdef BSD_43_BUG - int dummy; /* hack to avoid schain botch */ + int dummy; /* hack to avoid schain botch */ #endif struct monst *guard; boolean gsensed; - int trycount, vaultroom = (int)vault_occupied(u.urooms); + int trycount, vaultroom = (int) vault_occupied(u.urooms); - if(!vaultroom) { - u.uinvault = 0; - return; + if (!vaultroom) { + u.uinvault = 0; + return; } vaultroom -= ROOMOFFSET; guard = findgd(); - if(++u.uinvault % 30 == 0 && !guard) { /* if time ok and no guard now. */ - char buf[BUFSZ]; - register int x, y, dd, gx, gy; - int lx = 0, ly = 0; - long umoney; + if (++u.uinvault % 30 == 0 && !guard) { /* if time ok and no guard now. */ + char buf[BUFSZ]; + register int x, y, dd, gx, gy; + int lx = 0, ly = 0; + long umoney; - /* first find the goal for the guard */ - for(dd = 2; (dd < ROWNO || dd < COLNO); dd++) { - for(y = u.uy-dd; y <= u.uy+dd; ly = y, y++) { - if(y < 0 || y > ROWNO-1) continue; - for(x = u.ux-dd; x <= u.ux+dd; lx = x, x++) { - if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd) - x = u.ux+dd; - if(x < 1 || x > COLNO-1) continue; - if(levl[x][y].typ == CORR) { - if(x < u.ux) lx = x + 1; - else if(x > u.ux) lx = x - 1; - else lx = x; - if(y < u.uy) ly = y + 1; - else if(y > u.uy) ly = y - 1; - else ly = y; - if(levl[lx][ly].typ != STONE && levl[lx][ly].typ != CORR) - goto incr_radius; - goto fnd; - } - } - } -incr_radius: ; - } - impossible("Not a single corridor on this level??"); - tele(); - return; -fnd: - gx = x; gy = y; + /* first find the goal for the guard */ + for (dd = 2; (dd < ROWNO || dd < COLNO); dd++) { + for (y = u.uy - dd; y <= u.uy + dd; ly = y, y++) { + if (y < 0 || y > ROWNO - 1) + continue; + for (x = u.ux - dd; x <= u.ux + dd; lx = x, x++) { + if (y != u.uy - dd && y != u.uy + dd && x != u.ux - dd) + x = u.ux + dd; + if (x < 1 || x > COLNO - 1) + continue; + if (levl[x][y].typ == CORR) { + if (x < u.ux) + lx = x + 1; + else if (x > u.ux) + lx = x - 1; + else + lx = x; + if (y < u.uy) + ly = y + 1; + else if (y > u.uy) + ly = y - 1; + else + ly = y; + if (levl[lx][ly].typ != STONE + && levl[lx][ly].typ != CORR) + goto incr_radius; + goto fnd; + } + } + } + incr_radius: + ; + } + impossible("Not a single corridor on this level??"); + tele(); + return; + fnd: + gx = x; + gy = y; - /* next find a good place for a door in the wall */ - x = u.ux; y = u.uy; - if(levl[x][y].typ != ROOM) { /* player dug a door and is in it */ - if(levl[x+1][y].typ == ROOM) x = x + 1; - else if(levl[x][y+1].typ == ROOM) y = y + 1; - else if(levl[x-1][y].typ == ROOM) x = x - 1; - else if(levl[x][y-1].typ == ROOM) y = y - 1; - else if(levl[x+1][y+1].typ == ROOM) { - x = x + 1; - y = y + 1; - } else if (levl[x-1][y-1].typ == ROOM) { - x = x - 1; - y = y - 1; - } else if (levl[x+1][y-1].typ == ROOM) { - x = x + 1; - y = y - 1; - } else if (levl[x-1][y+1].typ == ROOM) { - x = x - 1; - y = y + 1; - } - } - while(levl[x][y].typ == ROOM) { - register int dx,dy; + /* next find a good place for a door in the wall */ + x = u.ux; + y = u.uy; + if (levl[x][y].typ != ROOM) { /* player dug a door and is in it */ + if (levl[x + 1][y].typ == ROOM) + x = x + 1; + else if (levl[x][y + 1].typ == ROOM) + y = y + 1; + else if (levl[x - 1][y].typ == ROOM) + x = x - 1; + else if (levl[x][y - 1].typ == ROOM) + y = y - 1; + else if (levl[x + 1][y + 1].typ == ROOM) { + x = x + 1; + y = y + 1; + } else if (levl[x - 1][y - 1].typ == ROOM) { + x = x - 1; + y = y - 1; + } else if (levl[x + 1][y - 1].typ == ROOM) { + x = x + 1; + y = y - 1; + } else if (levl[x - 1][y + 1].typ == ROOM) { + x = x - 1; + y = y + 1; + } + } + while (levl[x][y].typ == ROOM) { + register int dx, dy; - dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; - dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; - if(abs(gx-x) >= abs(gy-y)) - x += dx; - else - y += dy; - } - if(x == u.ux && y == u.uy) { - if(levl[x+1][y].typ == HWALL || levl[x+1][y].typ == DOOR) - x = x + 1; - else if(levl[x-1][y].typ == HWALL || levl[x-1][y].typ == DOOR) - x = x - 1; - else if(levl[x][y+1].typ == VWALL || levl[x][y+1].typ == DOOR) - y = y + 1; - else if(levl[x][y-1].typ == VWALL || levl[x][y-1].typ == DOOR) - y = y - 1; - else return; - } + dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; + dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; + if (abs(gx - x) >= abs(gy - y)) + x += dx; + else + y += dy; + } + if (x == u.ux && y == u.uy) { + if (levl[x + 1][y].typ == HWALL || levl[x + 1][y].typ == DOOR) + x = x + 1; + else if (levl[x - 1][y].typ == HWALL + || levl[x - 1][y].typ == DOOR) + x = x - 1; + else if (levl[x][y + 1].typ == VWALL + || levl[x][y + 1].typ == DOOR) + y = y + 1; + else if (levl[x][y - 1].typ == VWALL + || levl[x][y - 1].typ == DOOR) + y = y - 1; + else + return; + } - /* make something interesting happen */ - if(!(guard = makemon(&mons[PM_GUARD], x, y, MM_EGD))) return; - guard->isgd = 1; - guard->mpeaceful = 1; - set_malign(guard); - EGD(guard)->gddone = 0; - EGD(guard)->ogx = x; - EGD(guard)->ogy = y; - assign_level(&(EGD(guard)->gdlevel), &u.uz); - EGD(guard)->vroom = vaultroom; - EGD(guard)->warncnt = 0; + /* make something interesting happen */ + if (!(guard = makemon(&mons[PM_GUARD], x, y, MM_EGD))) + return; + guard->isgd = 1; + guard->mpeaceful = 1; + set_malign(guard); + EGD(guard)->gddone = 0; + EGD(guard)->ogx = x; + EGD(guard)->ogy = y; + assign_level(&(EGD(guard)->gdlevel), &u.uz); + EGD(guard)->vroom = vaultroom; + EGD(guard)->warncnt = 0; - reset_faint(); /* if fainted - wake up */ - gsensed = !canspotmon(guard); - if (!gsensed) - pline("Suddenly one of the Vault's %s enters!", - makeplural(guard->data->mname)); - else - pline("Someone else has entered the Vault."); - newsym(guard->mx,guard->my); - if (u.uswallow) { - /* can't interrogate hero, don't interrogate engulfer */ - verbalize("What's going on here?"); - if (gsensed) pline_The("other presence vanishes."); - mongone(guard); - return; - } - if (youmonst.m_ap_type == M_AP_OBJECT || u.uundetected) { - if (youmonst.m_ap_type == M_AP_OBJECT && - youmonst.mappearance != GOLD_PIECE) - verbalize("Hey! Who left that %s in here?", - mimic_obj_name(&youmonst)); - /* You're mimicking some object or you're hidden. */ - pline("Puzzled, %s turns around and leaves.", mhe(guard)); - mongone(guard); - return; - } - if (Strangled || is_silent(youmonst.data) || multi < 0) { - /* [we ought to record whether this this message has already - been given in order to vary it upon repeat visits, but - discarding the monster and its egd data renders that hard] */ - verbalize("I'll be back when you're ready to speak to me!"); - mongone(guard); - return; - } + reset_faint(); /* if fainted - wake up */ + gsensed = !canspotmon(guard); + if (!gsensed) + pline("Suddenly one of the Vault's %s enters!", + makeplural(guard->data->mname)); + else + pline("Someone else has entered the Vault."); + newsym(guard->mx, guard->my); + if (u.uswallow) { + /* can't interrogate hero, don't interrogate engulfer */ + verbalize("What's going on here?"); + if (gsensed) + pline_The("other presence vanishes."); + mongone(guard); + return; + } + if (youmonst.m_ap_type == M_AP_OBJECT || u.uundetected) { + if (youmonst.m_ap_type == M_AP_OBJECT + && youmonst.mappearance != GOLD_PIECE) + verbalize("Hey! Who left that %s in here?", + mimic_obj_name(&youmonst)); + /* You're mimicking some object or you're hidden. */ + pline("Puzzled, %s turns around and leaves.", mhe(guard)); + mongone(guard); + return; + } + if (Strangled || is_silent(youmonst.data) || multi < 0) { + /* [we ought to record whether this this message has already + been given in order to vary it upon repeat visits, but + discarding the monster and its egd data renders that hard] */ + verbalize("I'll be back when you're ready to speak to me!"); + mongone(guard); + return; + } - stop_occupation(); /* if occupied, stop it *now* */ - if (multi > 0) { nomul(0); unmul((char *)0); } - trycount = 5; - do { - getlin("\"Hello stranger, who are you?\" -", buf); - (void) mungspaces(buf); - } while (!letter(buf[0]) && --trycount > 0); + stop_occupation(); /* if occupied, stop it *now* */ + if (multi > 0) { + nomul(0); + unmul((char *) 0); + } + trycount = 5; + do { + getlin("\"Hello stranger, who are you?\" -", buf); + (void) mungspaces(buf); + } while (!letter(buf[0]) && --trycount > 0); - if (u.ualign.type == A_LAWFUL && - /* ignore trailing text, in case player includes character's rank */ - strncmpi(buf, plname, (int) strlen(plname)) != 0) { - adjalign(-1); /* Liar! */ - } + if (u.ualign.type == A_LAWFUL && + /* ignore trailing text, in case player includes character's rank + */ + strncmpi(buf, plname, (int) strlen(plname)) != 0) { + adjalign(-1); /* Liar! */ + } - if (!strcmpi(buf, "Croesus") || !strcmpi(buf, "Kroisos") - || !strcmpi(buf, "Creosote")) { - if (!mvitals[PM_CROESUS].died) { - verbalize("Oh, yes, of course. Sorry to have disturbed you."); - mongone(guard); - } else { - setmangry(guard); - verbalize("Back from the dead, are you? I'll remedy that!"); - /* don't want guard to waste next turn wielding a weapon */ - if (!MON_WEP(guard)) { - guard->weapon_check = NEED_HTH_WEAPON; - (void) mon_wield_item(guard); - } - } - return; - } - verbalize("I don't know you."); - umoney = money_cnt(invent); - if (Deaf) { - ; - } else if (!umoney && !hidden_gold()) { - verbalize("Please follow me."); - } else { - if (!umoney) - verbalize("You have hidden gold."); - verbalize("Most likely all your gold was stolen from this vault."); - verbalize("Please drop that gold and follow me."); - } - EGD(guard)->gdx = gx; - EGD(guard)->gdy = gy; - EGD(guard)->fcbeg = 0; - EGD(guard)->fakecorr[0].fx = x; - EGD(guard)->fakecorr[0].fy = y; - if(IS_WALL(levl[x][y].typ)) - EGD(guard)->fakecorr[0].ftyp = levl[x][y].typ; - else { /* the initial guard location is a dug door */ - int vlt = EGD(guard)->vroom; - xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx; - xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy; + if (!strcmpi(buf, "Croesus") || !strcmpi(buf, "Kroisos") + || !strcmpi(buf, "Creosote")) { + if (!mvitals[PM_CROESUS].died) { + verbalize( + "Oh, yes, of course. Sorry to have disturbed you."); + mongone(guard); + } else { + setmangry(guard); + verbalize("Back from the dead, are you? I'll remedy that!"); + /* don't want guard to waste next turn wielding a weapon */ + if (!MON_WEP(guard)) { + guard->weapon_check = NEED_HTH_WEAPON; + (void) mon_wield_item(guard); + } + } + return; + } + verbalize("I don't know you."); + umoney = money_cnt(invent); + if (Deaf) { + ; + } else if (!umoney && !hidden_gold()) { + verbalize("Please follow me."); + } else { + if (!umoney) + verbalize("You have hidden gold."); + verbalize( + "Most likely all your gold was stolen from this vault."); + verbalize("Please drop that gold and follow me."); + } + EGD(guard)->gdx = gx; + EGD(guard)->gdy = gy; + EGD(guard)->fcbeg = 0; + EGD(guard)->fakecorr[0].fx = x; + EGD(guard)->fakecorr[0].fy = y; + if (IS_WALL(levl[x][y].typ)) + EGD(guard)->fakecorr[0].ftyp = levl[x][y].typ; + else { /* the initial guard location is a dug door */ + int vlt = EGD(guard)->vroom; + xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx; + xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy; - if(x == lowx-1 && y == lowy-1) - EGD(guard)->fakecorr[0].ftyp = TLCORNER; - else if(x == hix+1 && y == lowy-1) - EGD(guard)->fakecorr[0].ftyp = TRCORNER; - else if(x == lowx-1 && y == hiy+1) - EGD(guard)->fakecorr[0].ftyp = BLCORNER; - else if(x == hix+1 && y == hiy+1) - EGD(guard)->fakecorr[0].ftyp = BRCORNER; - else if(y == lowy-1 || y == hiy+1) - EGD(guard)->fakecorr[0].ftyp = HWALL; - else if(x == lowx-1 || x == hix+1) - EGD(guard)->fakecorr[0].ftyp = VWALL; - } - levl[x][y].typ = DOOR; - levl[x][y].doormask = D_NODOOR; - unblock_point(x, y); /* doesn't block light */ - EGD(guard)->fcend = 1; - EGD(guard)->warncnt = 1; + if (x == lowx - 1 && y == lowy - 1) + EGD(guard)->fakecorr[0].ftyp = TLCORNER; + else if (x == hix + 1 && y == lowy - 1) + EGD(guard)->fakecorr[0].ftyp = TRCORNER; + else if (x == lowx - 1 && y == hiy + 1) + EGD(guard)->fakecorr[0].ftyp = BLCORNER; + else if (x == hix + 1 && y == hiy + 1) + EGD(guard)->fakecorr[0].ftyp = BRCORNER; + else if (y == lowy - 1 || y == hiy + 1) + EGD(guard)->fakecorr[0].ftyp = HWALL; + else if (x == lowx - 1 || x == hix + 1) + EGD(guard)->fakecorr[0].ftyp = VWALL; + } + levl[x][y].typ = DOOR; + levl[x][y].doormask = D_NODOOR; + unblock_point(x, y); /* doesn't block light */ + EGD(guard)->fcend = 1; + EGD(guard)->warncnt = 1; } } @@ -417,80 +452,83 @@ move_gold(gold, vroom) struct obj *gold; int vroom; { - xchar nx, ny; + xchar nx, ny; - remove_object(gold); - newsym(gold->ox, gold->oy); - nx = rooms[vroom].lx + rn2(2); - ny = rooms[vroom].ly + rn2(2); - place_object(gold, nx, ny); - stackobj(gold); - newsym(nx,ny); + remove_object(gold); + newsym(gold->ox, gold->oy); + nx = rooms[vroom].lx + rn2(2); + ny = rooms[vroom].ly + rn2(2); + place_object(gold, nx, ny); + stackobj(gold); + newsym(nx, ny); } STATIC_OVL void wallify_vault(grd) struct monst *grd; { - int x, y, typ; - int vlt = EGD(grd)->vroom; - char tmp_viz; - xchar lox = rooms[vlt].lx - 1, hix = rooms[vlt].hx + 1, - loy = rooms[vlt].ly - 1, hiy = rooms[vlt].hy + 1; - struct monst *mon; - struct obj *gold; - struct trap *trap; - boolean fixed = FALSE; - boolean movedgold = FALSE; + int x, y, typ; + int vlt = EGD(grd)->vroom; + char tmp_viz; + xchar lox = rooms[vlt].lx - 1, hix = rooms[vlt].hx + 1, + loy = rooms[vlt].ly - 1, hiy = rooms[vlt].hy + 1; + struct monst *mon; + struct obj *gold; + struct trap *trap; + boolean fixed = FALSE; + boolean movedgold = FALSE; - for (x = lox; x <= hix; x++) - for (y = loy; y <= hiy; y++) { - /* if not on the room boundary, skip ahead */ - if (x != lox && x != hix && y != loy && y != hiy) continue; + for (x = lox; x <= hix; x++) + for (y = loy; y <= hiy; y++) { + /* if not on the room boundary, skip ahead */ + if (x != lox && x != hix && y != loy && y != hiy) + continue; - if (!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) { - if ((mon = m_at(x, y)) != 0 && mon != grd) { - if (mon->mtame) yelp(mon); - (void) rloc(mon, FALSE); - } - if ((gold = g_at(x, y)) != 0) { - move_gold(gold, EGD(grd)->vroom); - movedgold = TRUE; - } - if ((trap = t_at(x, y)) != 0) - deltrap(trap); - if (x == lox) - typ = (y == loy) ? TLCORNER : - (y == hiy) ? BLCORNER : VWALL; - else if (x == hix) - typ = (y == loy) ? TRCORNER : - (y == hiy) ? BRCORNER : VWALL; - else /* not left or right side, must be top or bottom */ - typ = HWALL; - levl[x][y].typ = typ; - levl[x][y].doormask = 0; - /* - * hack: player knows walls are restored because of the - * message, below, so show this on the screen. - */ - tmp_viz = viz_array[y][x]; - viz_array[y][x] = IN_SIGHT|COULD_SEE; - newsym(x,y); - viz_array[y][x] = tmp_viz; - block_point(x,y); - fixed = TRUE; - } - } + if (!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) { + if ((mon = m_at(x, y)) != 0 && mon != grd) { + if (mon->mtame) + yelp(mon); + (void) rloc(mon, FALSE); + } + if ((gold = g_at(x, y)) != 0) { + move_gold(gold, EGD(grd)->vroom); + movedgold = TRUE; + } + if ((trap = t_at(x, y)) != 0) + deltrap(trap); + if (x == lox) + typ = + (y == loy) ? TLCORNER : (y == hiy) ? BLCORNER : VWALL; + else if (x == hix) + typ = + (y == loy) ? TRCORNER : (y == hiy) ? BRCORNER : VWALL; + else /* not left or right side, must be top or bottom */ + typ = HWALL; + levl[x][y].typ = typ; + levl[x][y].doormask = 0; + /* + * hack: player knows walls are restored because of the + * message, below, so show this on the screen. + */ + tmp_viz = viz_array[y][x]; + viz_array[y][x] = IN_SIGHT | COULD_SEE; + newsym(x, y); + viz_array[y][x] = tmp_viz; + block_point(x, y); + fixed = TRUE; + } + } - if(movedgold || fixed) { - if(in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my)) - pline("%s whispers an incantation.", noit_Monnam(grd)); - else You_hear("a distant chant."); - if(movedgold) - pline("A mysterious force moves the gold into the vault."); - if(fixed) - pline_The("damaged vault's walls are magically restored!"); - } + if (movedgold || fixed) { + if (in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my)) + pline("%s whispers an incantation.", noit_Monnam(grd)); + else + You_hear("a distant chant."); + if (movedgold) + pline("A mysterious force moves the gold into the vault."); + if (fixed) + pline_The("damaged vault's walls are magically restored!"); + } } /* @@ -500,387 +538,398 @@ int gd_move(grd) register struct monst *grd; { - int x, y, nx, ny, m, n; - int dx, dy, gx, gy, fci; - uchar typ; - struct fakecorridor *fcp; - register struct egd *egrd = EGD(grd); - register struct rm *crm; - register boolean goldincorridor = FALSE, - u_in_vault = vault_occupied(u.urooms)? TRUE : FALSE, - grd_in_vault = *in_rooms(grd->mx, grd->my, VAULT)? - TRUE : FALSE; - boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0); - long umoney = money_cnt(invent); - register boolean u_carry_gold = ((umoney + hidden_gold()) > 0L); - boolean see_guard, newspot = FALSE; + int x, y, nx, ny, m, n; + int dx, dy, gx, gy, fci; + uchar typ; + struct fakecorridor *fcp; + register struct egd *egrd = EGD(grd); + register struct rm *crm; + register boolean goldincorridor = FALSE, + u_in_vault = vault_occupied(u.urooms) ? TRUE : FALSE, + grd_in_vault = + *in_rooms(grd->mx, grd->my, VAULT) ? TRUE : FALSE; + boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0); + long umoney = money_cnt(invent); + register boolean u_carry_gold = ((umoney + hidden_gold()) > 0L); + boolean see_guard, newspot = FALSE; - if(!on_level(&(egrd->gdlevel), &u.uz)) return(-1); - nx = ny = m = n = 0; - if(!u_in_vault && !grd_in_vault) - wallify_vault(grd); - if(!grd->mpeaceful) { - if(semi_dead) { - egrd->gddone =1; - goto newpos; - } - if(!u_in_vault && - (grd_in_vault || - (in_fcorridor(grd, grd->mx, grd->my) && - !in_fcorridor(grd, u.ux, u.uy)))) { - (void) rloc(grd, FALSE); - wallify_vault(grd); - (void) clear_fcorr(grd, TRUE); - goto letknow; - } - if(!in_fcorridor(grd, grd->mx, grd->my)) - (void) clear_fcorr(grd, TRUE); - return(-1); - } - if(abs(egrd->ogx - grd->mx) > 1 || - abs(egrd->ogy - grd->my) > 1) - return(-1); /* teleported guard - treat as monster */ + if (!on_level(&(egrd->gdlevel), &u.uz)) + return (-1); + nx = ny = m = n = 0; + if (!u_in_vault && !grd_in_vault) + wallify_vault(grd); + if (!grd->mpeaceful) { + if (semi_dead) { + egrd->gddone = 1; + goto newpos; + } + if (!u_in_vault + && (grd_in_vault || (in_fcorridor(grd, grd->mx, grd->my) + && !in_fcorridor(grd, u.ux, u.uy)))) { + (void) rloc(grd, FALSE); + wallify_vault(grd); + (void) clear_fcorr(grd, TRUE); + goto letknow; + } + if (!in_fcorridor(grd, grd->mx, grd->my)) + (void) clear_fcorr(grd, TRUE); + return (-1); + } + if (abs(egrd->ogx - grd->mx) > 1 || abs(egrd->ogy - grd->my) > 1) + return (-1); /* teleported guard - treat as monster */ - if(egrd->witness) { - verbalize("How dare you %s that gold, scoundrel!", - (egrd->witness & GD_EATGOLD) ? "consume" : "destroy"); - egrd->witness = 0; - grd->mpeaceful = 0; - return(-1); - } - if(egrd->fcend == 1) { - if(u_in_vault && - (u_carry_gold || um_dist(grd->mx, grd->my, 1))) { - if(egrd->warncnt == 3 && !Deaf) - verbalize("I repeat, %sfollow me!", - u_carry_gold ? ( - !umoney ? - "drop that hidden money and " : - "drop that money and ") : ""); - if(egrd->warncnt == 7) { - m = grd->mx; - n = grd->my; - if (!Deaf) - verbalize("You've been warned, knave!"); - mnexto(grd); - levl[m][n].typ = egrd->fakecorr[0].ftyp; - newsym(m,n); - grd->mpeaceful = 0; - return(-1); - } - /* not fair to get mad when (s)he's fainted or paralyzed */ - if(!is_fainted() && multi >= 0) egrd->warncnt++; - return(0); - } + if (egrd->witness) { + verbalize("How dare you %s that gold, scoundrel!", + (egrd->witness & GD_EATGOLD) ? "consume" : "destroy"); + egrd->witness = 0; + grd->mpeaceful = 0; + return (-1); + } + if (egrd->fcend == 1) { + if (u_in_vault && (u_carry_gold || um_dist(grd->mx, grd->my, 1))) { + if (egrd->warncnt == 3 && !Deaf) + verbalize("I repeat, %sfollow me!", + u_carry_gold + ? (!umoney ? "drop that hidden money and " + : "drop that money and ") + : ""); + if (egrd->warncnt == 7) { + m = grd->mx; + n = grd->my; + if (!Deaf) + verbalize("You've been warned, knave!"); + mnexto(grd); + levl[m][n].typ = egrd->fakecorr[0].ftyp; + newsym(m, n); + grd->mpeaceful = 0; + return (-1); + } + /* not fair to get mad when (s)he's fainted or paralyzed */ + if (!is_fainted() && multi >= 0) + egrd->warncnt++; + return (0); + } - if (!u_in_vault) { - if (u_carry_gold) { /* player teleported */ - m = grd->mx; - n = grd->my; - (void) rloc(grd, FALSE); - levl[m][n].typ = egrd->fakecorr[0].ftyp; - newsym(m,n); - grd->mpeaceful = 0; -letknow: - if (!cansee(grd->mx, grd->my) || !mon_visible(grd)) - You_hear("the shrill sound of a guard's whistle."); - else - You(um_dist(grd->mx, grd->my, 2) ? - "see %s approaching." : "are confronted by %s.", - /* "an angry guard" */ - x_monnam(grd, ARTICLE_A, "angry", 0, FALSE)); - return(-1); - } else { - if (!Deaf) - verbalize("Well, begone."); - wallify_vault(grd); - egrd->gddone = 1; - goto cleanup; - } - } - } + if (!u_in_vault) { + if (u_carry_gold) { /* player teleported */ + m = grd->mx; + n = grd->my; + (void) rloc(grd, FALSE); + levl[m][n].typ = egrd->fakecorr[0].ftyp; + newsym(m, n); + grd->mpeaceful = 0; + letknow: + if (!cansee(grd->mx, grd->my) || !mon_visible(grd)) + You_hear("the shrill sound of a guard's whistle."); + else + You(um_dist(grd->mx, grd->my, 2) + ? "see %s approaching." + : "are confronted by %s.", + /* "an angry guard" */ + x_monnam(grd, ARTICLE_A, "angry", 0, FALSE)); + return (-1); + } else { + if (!Deaf) + verbalize("Well, begone."); + wallify_vault(grd); + egrd->gddone = 1; + goto cleanup; + } + } + } - if(egrd->fcend > 1) { - if(egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) && - !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) && - levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ - == egrd->fakecorr[0].ftyp) { - pline("%s, confused, disappears.", noit_Monnam(grd)); - disappear_msg_seen = TRUE; - goto cleanup; - } - if(u_carry_gold && - (in_fcorridor(grd, u.ux, u.uy) || - /* cover a 'blind' spot */ - (egrd->fcend > 1 && u_in_vault))) { - if(!grd->mx) { - restfakecorr(grd); - return(-2); - } - if(egrd->warncnt < 6) { - egrd->warncnt = 6; - if (!Deaf) - verbalize("Drop all your gold, scoundrel!"); - return(0); - } else { - if (!Deaf) - verbalize("So be it, rogue!"); - grd->mpeaceful = 0; - return(-1); - } - } - } - for(fci = egrd->fcbeg; fci < egrd->fcend; fci++) - if(g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)){ - m = egrd->fakecorr[fci].fx; - n = egrd->fakecorr[fci].fy; - goldincorridor = TRUE; - } - if(goldincorridor && !egrd->gddone) { - x = grd->mx; - y = grd->my; - if (m == u.ux && n == u.uy) { - struct obj *gold = g_at(m,n); - /* Grab the gold from between the hero's feet. */ - obj_extract_self(gold); - add_to_minv(grd, gold); - newsym(m,n); - } else if (m == x && n == y) { - mpickgold(grd); /* does a newsym */ - } else { - /* just for insurance... */ - if (MON_AT(m, n) && m != grd->mx && n != grd->my) { - if (!Deaf) - verbalize("Out of my way, scum!"); - (void) rloc(m_at(m, n), FALSE); - } - remove_monster(grd->mx, grd->my); - newsym(grd->mx, grd->my); - place_monster(grd, m, n); - mpickgold(grd); /* does a newsym */ - } - if(cansee(m,n)) - pline("%s%s picks up the gold.", Monnam(grd), - grd->mpeaceful ? " calms down and" : ""); - if(x != grd->mx || y != grd->my) { - remove_monster(grd->mx, grd->my); - newsym(grd->mx, grd->my); - place_monster(grd, x, y); - newsym(x, y); - } - if (!grd->mpeaceful) return -1; - egrd->warncnt = 5; - return 0; - } - if(um_dist(grd->mx, grd->my, 1) || egrd->gddone) { - if (!egrd->gddone && !rn2(10) && !Deaf && !u.uswallow && - !(u.ustuck && !sticks(youmonst.data))) - verbalize("Move along!"); - restfakecorr(grd); - return(0); /* didn't move */ - } - x = grd->mx; - y = grd->my; + if (egrd->fcend > 1) { + if (egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) + && !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) + && levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ + == egrd->fakecorr[0].ftyp) { + pline("%s, confused, disappears.", noit_Monnam(grd)); + disappear_msg_seen = TRUE; + goto cleanup; + } + if (u_carry_gold && (in_fcorridor(grd, u.ux, u.uy) || + /* cover a 'blind' spot */ + (egrd->fcend > 1 && u_in_vault))) { + if (!grd->mx) { + restfakecorr(grd); + return (-2); + } + if (egrd->warncnt < 6) { + egrd->warncnt = 6; + if (!Deaf) + verbalize("Drop all your gold, scoundrel!"); + return (0); + } else { + if (!Deaf) + verbalize("So be it, rogue!"); + grd->mpeaceful = 0; + return (-1); + } + } + } + for (fci = egrd->fcbeg; fci < egrd->fcend; fci++) + if (g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)) { + m = egrd->fakecorr[fci].fx; + n = egrd->fakecorr[fci].fy; + goldincorridor = TRUE; + } + if (goldincorridor && !egrd->gddone) { + x = grd->mx; + y = grd->my; + if (m == u.ux && n == u.uy) { + struct obj *gold = g_at(m, n); + /* Grab the gold from between the hero's feet. */ + obj_extract_self(gold); + add_to_minv(grd, gold); + newsym(m, n); + } else if (m == x && n == y) { + mpickgold(grd); /* does a newsym */ + } else { + /* just for insurance... */ + if (MON_AT(m, n) && m != grd->mx && n != grd->my) { + if (!Deaf) + verbalize("Out of my way, scum!"); + (void) rloc(m_at(m, n), FALSE); + } + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, m, n); + mpickgold(grd); /* does a newsym */ + } + if (cansee(m, n)) + pline("%s%s picks up the gold.", Monnam(grd), + grd->mpeaceful ? " calms down and" : ""); + if (x != grd->mx || y != grd->my) { + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, x, y); + newsym(x, y); + } + if (!grd->mpeaceful) + return -1; + egrd->warncnt = 5; + return 0; + } + if (um_dist(grd->mx, grd->my, 1) || egrd->gddone) { + if (!egrd->gddone && !rn2(10) && !Deaf && !u.uswallow + && !(u.ustuck && !sticks(youmonst.data))) + verbalize("Move along!"); + restfakecorr(grd); + return (0); /* didn't move */ + } + x = grd->mx; + y = grd->my; - if(u_in_vault) goto nextpos; + if (u_in_vault) + goto nextpos; - /* look around (hor & vert only) for accessible places */ - for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) { - if((nx == x || ny == y) && (nx != x || ny != y) && isok(nx, ny)) { + /* look around (hor & vert only) for accessible places */ + for (nx = x - 1; nx <= x + 1; nx++) + for (ny = y - 1; ny <= y + 1; ny++) { + if ((nx == x || ny == y) && (nx != x || ny != y) + && isok(nx, ny)) { + typ = (crm = &levl[nx][ny])->typ; + if (!IS_STWALL(typ) && !IS_POOL(typ)) { + if (in_fcorridor(grd, nx, ny)) + goto nextnxy; - typ = (crm = &levl[nx][ny])->typ; - if(!IS_STWALL(typ) && !IS_POOL(typ)) { + if (*in_rooms(nx, ny, VAULT)) + continue; - if(in_fcorridor(grd, nx, ny)) - goto nextnxy; - - if(*in_rooms(nx,ny,VAULT)) - continue; - - /* seems we found a good place to leave him alone */ - egrd->gddone = 1; - if(ACCESSIBLE(typ)) goto newpos; + /* seems we found a good place to leave him alone */ + egrd->gddone = 1; + if (ACCESSIBLE(typ)) + goto newpos; #ifdef STUPID - if (typ == SCORR) - crm->typ = CORR; - else - crm->typ = DOOR; + if (typ == SCORR) + crm->typ = CORR; + else + crm->typ = DOOR; #else - crm->typ = (typ == SCORR) ? CORR : DOOR; + crm->typ = (typ == SCORR) ? CORR : DOOR; #endif - if(crm->typ == DOOR) crm->doormask = D_NODOOR; - goto proceed; - } - } -nextnxy: ; - } + if (crm->typ == DOOR) + crm->doormask = D_NODOOR; + goto proceed; + } + } + nextnxy: + ; + } nextpos: - nx = x; - ny = y; - gx = egrd->gdx; - gy = egrd->gdy; - dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; - dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; - if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy; + nx = x; + ny = y; + gx = egrd->gdx; + gy = egrd->gdy; + dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; + dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; + if (abs(gx - x) >= abs(gy - y)) + nx += dx; + else + ny += dy; - while((typ = (crm = &levl[nx][ny])->typ) != 0) { - /* in view of the above we must have IS_WALL(typ) or typ == POOL */ - /* must be a wall here */ - if(isok(nx+nx-x,ny+ny-y) && !IS_POOL(typ) && - IS_ROOM(levl[nx+nx-x][ny+ny-y].typ)){ - crm->typ = DOOR; - crm->doormask = D_NODOOR; - goto proceed; - } - if(dy && nx != x) { - nx = x; ny = y+dy; - continue; - } - if(dx && ny != y) { - ny = y; nx = x+dx; dy = 0; - continue; - } - /* I don't like this, but ... */ - if(IS_ROOM(typ)) { - crm->typ = DOOR; - crm->doormask = D_NODOOR; - goto proceed; - } - break; - } - crm->typ = CORR; + while ((typ = (crm = &levl[nx][ny])->typ) != 0) { + /* in view of the above we must have IS_WALL(typ) or typ == POOL */ + /* must be a wall here */ + if (isok(nx + nx - x, ny + ny - y) && !IS_POOL(typ) + && IS_ROOM(levl[nx + nx - x][ny + ny - y].typ)) { + crm->typ = DOOR; + crm->doormask = D_NODOOR; + goto proceed; + } + if (dy && nx != x) { + nx = x; + ny = y + dy; + continue; + } + if (dx && ny != y) { + ny = y; + nx = x + dx; + dy = 0; + continue; + } + /* I don't like this, but ... */ + if (IS_ROOM(typ)) { + crm->typ = DOOR; + crm->doormask = D_NODOOR; + goto proceed; + } + break; + } + crm->typ = CORR; proceed: - newspot = TRUE; - unblock_point(nx, ny); /* doesn't block light */ - if (cansee(nx,ny)) - newsym(nx,ny); + newspot = TRUE; + unblock_point(nx, ny); /* doesn't block light */ + if (cansee(nx, ny)) + newsym(nx, ny); - fcp = &(egrd->fakecorr[egrd->fcend]); - if(egrd->fcend++ == FCSIZ) panic("fakecorr overflow"); - fcp->fx = nx; - fcp->fy = ny; - fcp->ftyp = typ; + fcp = &(egrd->fakecorr[egrd->fcend]); + if (egrd->fcend++ == FCSIZ) + panic("fakecorr overflow"); + fcp->fx = nx; + fcp->fy = ny; + fcp->ftyp = typ; newpos: - if(egrd->gddone) { - /* The following is a kludge. We need to keep */ - /* the guard around in order to be able to make */ - /* the fake corridor disappear as the player */ - /* moves out of it, but we also need the guard */ - /* out of the way. We send the guard to never- */ - /* never land. We set ogx ogy to mx my in order */ - /* to avoid a check at the top of this function. */ - /* At the end of the process, the guard is killed */ - /* in restfakecorr(). */ -cleanup: - x = grd->mx; y = grd->my; + if (egrd->gddone) { + /* The following is a kludge. We need to keep */ + /* the guard around in order to be able to make */ + /* the fake corridor disappear as the player */ + /* moves out of it, but we also need the guard */ + /* out of the way. We send the guard to never- */ + /* never land. We set ogx ogy to mx my in order */ + /* to avoid a check at the top of this function. */ + /* At the end of the process, the guard is killed */ + /* in restfakecorr(). */ + cleanup: + x = grd->mx; + y = grd->my; - see_guard = canspotmon(grd); - wallify_vault(grd); - remove_monster(grd->mx, grd->my); - newsym(grd->mx,grd->my); - place_monster(grd, 0, 0); - egrd->ogx = grd->mx; - egrd->ogy = grd->my; - restfakecorr(grd); - if(!semi_dead && (in_fcorridor(grd, u.ux, u.uy) || - cansee(x, y))) { - if (!disappear_msg_seen && see_guard) - pline("Suddenly, %s disappears.", noit_mon_nam(grd)); - return(1); - } - return(-2); - } - egrd->ogx = grd->mx; /* update old positions */ - egrd->ogy = grd->my; - remove_monster(grd->mx, grd->my); - place_monster(grd, nx, ny); - if (newspot && g_at(nx, ny)) { - /* if there's gold already here (most likely from mineralize()), - pick it up now so that guard doesn't later think hero dropped - it and give an inappropriate message */ - mpickgold(grd); - if (canspotmon(grd)) pline("%s picks up some gold.", Monnam(grd)); - } else - newsym(grd->mx, grd->my); - restfakecorr(grd); - return(1); + see_guard = canspotmon(grd); + wallify_vault(grd); + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, 0, 0); + egrd->ogx = grd->mx; + egrd->ogy = grd->my; + restfakecorr(grd); + if (!semi_dead && (in_fcorridor(grd, u.ux, u.uy) || cansee(x, y))) { + if (!disappear_msg_seen && see_guard) + pline("Suddenly, %s disappears.", noit_mon_nam(grd)); + return (1); + } + return (-2); + } + egrd->ogx = grd->mx; /* update old positions */ + egrd->ogy = grd->my; + remove_monster(grd->mx, grd->my); + place_monster(grd, nx, ny); + if (newspot && g_at(nx, ny)) { + /* if there's gold already here (most likely from mineralize()), + pick it up now so that guard doesn't later think hero dropped + it and give an inappropriate message */ + mpickgold(grd); + if (canspotmon(grd)) + pline("%s picks up some gold.", Monnam(grd)); + } else + newsym(grd->mx, grd->my); + restfakecorr(grd); + return (1); } /* Routine when dying or quitting with a vault guard around */ void paygd() { - register struct monst *grd = findgd(); - long umoney = money_cnt(invent); - struct obj *coins, *nextcoins; - int gx,gy; - char buf[BUFSZ]; + register struct monst *grd = findgd(); + long umoney = money_cnt(invent); + struct obj *coins, *nextcoins; + int gx, gy; + char buf[BUFSZ]; - if (!umoney || !grd) return; + if (!umoney || !grd) + return; - if (u.uinvault) { - Your("%ld %s goes into the Magic Memory Vault.", - umoney, - currency(umoney)); - gx = u.ux; - gy = u.uy; - } else { - if(grd->mpeaceful) { /* guard has no "right" to your gold */ - mongone(grd); - return; - } - mnexto(grd); - pline("%s remits your gold to the vault.", Monnam(grd)); - gx = rooms[EGD(grd)->vroom].lx + rn2(2); - gy = rooms[EGD(grd)->vroom].ly + rn2(2); - Sprintf(buf, - "To Croesus: here's the gold recovered from %s the %s.", - plname, mons[u.umonster].mname); - make_grave(gx, gy, buf); - } - for (coins = invent; coins; coins = nextcoins) { - nextcoins = coins->nobj; - if (objects[coins->otyp].oc_class == COIN_CLASS) { - freeinv(coins); - place_object(coins, gx, gy); - stackobj(coins); - } + if (u.uinvault) { + Your("%ld %s goes into the Magic Memory Vault.", umoney, + currency(umoney)); + gx = u.ux; + gy = u.uy; + } else { + if (grd->mpeaceful) { /* guard has no "right" to your gold */ + mongone(grd); + return; } - mongone(grd); + mnexto(grd); + pline("%s remits your gold to the vault.", Monnam(grd)); + gx = rooms[EGD(grd)->vroom].lx + rn2(2); + gy = rooms[EGD(grd)->vroom].ly + rn2(2); + Sprintf(buf, "To Croesus: here's the gold recovered from %s the %s.", + plname, mons[u.umonster].mname); + make_grave(gx, gy, buf); + } + for (coins = invent; coins; coins = nextcoins) { + nextcoins = coins->nobj; + if (objects[coins->otyp].oc_class == COIN_CLASS) { + freeinv(coins); + place_object(coins, gx, gy); + stackobj(coins); + } + } + mongone(grd); } long hidden_gold() { - register long value = 0L; - register struct obj *obj; + register long value = 0L; + register struct obj *obj; - for (obj = invent; obj; obj = obj->nobj) - if (Has_contents(obj)) - value += contained_gold(obj); - /* unknown gold stuck inside statues may cause some consternation... */ + for (obj = invent; obj; obj = obj->nobj) + if (Has_contents(obj)) + value += contained_gold(obj); + /* unknown gold stuck inside statues may cause some consternation... */ - return(value); + return (value); } -boolean -gd_sound() /* prevent "You hear footsteps.." when inappropriate */ +boolean gd_sound() /* prevent "You hear footsteps.." when inappropriate */ { - register struct monst *grd = findgd(); + register struct monst *grd = findgd(); - if (vault_occupied(u.urooms)) return(FALSE); - else return((boolean)(grd == (struct monst *)0)); + if (vault_occupied(u.urooms)) + return (FALSE); + else + return ((boolean)(grd == (struct monst *) 0)); } void vault_gd_watching(activity) unsigned int activity; { - struct monst *guard = findgd(); - if (guard && guard->mcansee && m_canseeu(guard)) { - if (activity == GD_EATGOLD || - activity == GD_DESTROYGOLD) - EGD(guard)->witness = activity; - } + struct monst *guard = findgd(); + if (guard && guard->mcansee && m_canseeu(guard)) { + if (activity == GD_EATGOLD || activity == GD_DESTROYGOLD) + EGD(guard)->witness = activity; + } } /*vault.c*/ diff --git a/src/version.c b/src/version.c index b082e5be7..cca505b82 100644 --- a/src/version.c +++ b/src/version.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 version.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 version.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */ /* NetHack 3.6 version.c $Date: 2012/01/04 18:52:36 $ $Revision: 1.26 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -23,7 +23,7 @@ char * version_string(buf) char *buf; { - return strcpy(buf, VERSION_STRING); + return strcpy(buf, VERSION_STRING); } /* fill and return the given buffer with the long nethack version string */ @@ -31,86 +31,91 @@ char * getversionstring(buf) char *buf; { - Strcpy(buf, VERSION_ID); + Strcpy(buf, VERSION_ID); #if defined(BETA) && defined(BETA_INFO) - Sprintf(eos(buf), " %s", BETA_INFO); + Sprintf(eos(buf), " %s", BETA_INFO); #endif #if defined(RUNTIME_PORT_ID) - append_port_id(buf); + append_port_id(buf); #endif - return buf; + return buf; } /* the 'v' command */ int doversion() { - char buf[BUFSZ]; + char buf[BUFSZ]; - pline1(getversionstring(buf)); - return 0; + pline1(getversionstring(buf)); + return 0; } /* the '#version' command; also a choice for '?' */ int doextversion() { - dlb *f; - char *cr, buf[BUFSZ]; - winid win = create_nhwindow(NHW_TEXT); + dlb *f; + char *cr, buf[BUFSZ]; + winid win = create_nhwindow(NHW_TEXT); - /* instead of using ``display_file(OPTIONS_USED,TRUE)'' we handle - the file manually so we can include dynamic version info */ - putstr(win, 0, getversionstring(buf)); + /* instead of using ``display_file(OPTIONS_USED,TRUE)'' we handle + the file manually so we can include dynamic version info */ + putstr(win, 0, getversionstring(buf)); - f = dlb_fopen(OPTIONS_USED, "r"); - if (!f) { - putstr(win, 0, ""); - Sprintf(buf, "[Configuration '%s' not available?]", OPTIONS_USED); - putstr(win, 0, buf); - } else { - /* - * already inserted above: - * + outdented program name and version plus build date and time - * dat/options; display the contents with lines prefixed by '-' deleted: - * - blank-line - * - indented program name and version - * blank-line - * outdented feature header - * - blank-line - * indented feature list - * spread over multiple lines - * blank-line - * outdented windowing header - * - blank-line - * indented windowing choices with - * optional second line for default - * - blank-line - * - EOF - */ - boolean prolog = TRUE; /* to skip indented program name */ + f = dlb_fopen(OPTIONS_USED, "r"); + if (!f) { + putstr(win, 0, ""); + Sprintf(buf, "[Configuration '%s' not available?]", OPTIONS_USED); + putstr(win, 0, buf); + } else { + /* + * already inserted above: + * + outdented program name and version plus build date and time + * dat/options; display the contents with lines prefixed by '-' + * deleted: + * - blank-line + * - indented program name and version + * blank-line + * outdented feature header + * - blank-line + * indented feature list + * spread over multiple lines + * blank-line + * outdented windowing header + * - blank-line + * indented windowing choices with + * optional second line for default + * - blank-line + * - EOF + */ + boolean prolog = TRUE; /* to skip indented program name */ - while (dlb_fgets(buf, BUFSZ, f)) { - if ((cr = index(buf, '\n')) != 0) *cr = 0; - if ((cr = index(buf, '\r')) != 0) *cr = 0; - if (index(buf, '\t') != 0) (void) tabexpand(buf); + while (dlb_fgets(buf, BUFSZ, f)) { + if ((cr = index(buf, '\n')) != 0) + *cr = 0; + if ((cr = index(buf, '\r')) != 0) + *cr = 0; + if (index(buf, '\t') != 0) + (void) tabexpand(buf); - if (*buf && *buf != ' ') { - /* found outdented header; insert a separator since we'll - have skipped corresponding blank line inside the file */ - putstr(win, 0, ""); - prolog = FALSE; - } - /* skip blank lines and prolog (progame name plus version) */ - if (prolog || !*buf) continue; + if (*buf && *buf != ' ') { + /* found outdented header; insert a separator since we'll + have skipped corresponding blank line inside the file */ + putstr(win, 0, ""); + prolog = FALSE; + } + /* skip blank lines and prolog (progame name plus version) */ + if (prolog || !*buf) + continue; - putstr(win, 0, buf); - } - (void) dlb_fclose(f); - display_nhwindow(win, FALSE); - destroy_nhwindow(win); - } - return 0; + putstr(win, 0, buf); + } + (void) dlb_fclose(f); + display_nhwindow(win, FALSE); + destroy_nhwindow(win); + } + return 0; } #ifdef MICRO @@ -118,7 +123,7 @@ boolean comp_times(filetime) long filetime; { - return((boolean)(filetime < BUILD_TIME)); + return ((boolean)(filetime < BUILD_TIME)); } #endif @@ -128,33 +133,33 @@ struct version_info *version_data; const char *filename; boolean complain; { - if ( + if ( #ifdef VERSION_COMPATIBILITY - version_data->incarnation < VERSION_COMPATIBILITY || - version_data->incarnation > VERSION_NUMBER + version_data->incarnation < VERSION_COMPATIBILITY + || version_data->incarnation > VERSION_NUMBER #else - version_data->incarnation != VERSION_NUMBER + version_data->incarnation != VERSION_NUMBER #endif - ) { - if (complain) - pline("Version mismatch for file \"%s\".", filename); - return FALSE; - } else if ( + ) { + if (complain) + pline("Version mismatch for file \"%s\".", filename); + return FALSE; + } else if ( #ifndef IGNORED_FEATURES - version_data->feature_set != VERSION_FEATURES || + version_data->feature_set != VERSION_FEATURES || #else - (version_data->feature_set & ~IGNORED_FEATURES) != - (VERSION_FEATURES & ~IGNORED_FEATURES) || + (version_data->feature_set & ~IGNORED_FEATURES) + != (VERSION_FEATURES & ~IGNORED_FEATURES) + || #endif - version_data->entity_count != VERSION_SANITY1 || - version_data->struct_sizes1 != VERSION_SANITY2 || - version_data->struct_sizes2 != VERSION_SANITY3) { - if (complain) - pline("Configuration incompatibility for file \"%s\".", - filename); - return FALSE; - } - return TRUE; + version_data->entity_count != VERSION_SANITY1 + || version_data->struct_sizes1 != VERSION_SANITY2 + || version_data->struct_sizes2 != VERSION_SANITY3) { + if (complain) + pline("Configuration incompatibility for file \"%s\".", filename); + return FALSE; + } + return TRUE; } /* this used to be based on file date and somewhat OS-dependant, @@ -169,17 +174,18 @@ const char *name; boolean verbose = name ? TRUE : FALSE; rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info); - minit(); /* ZEROCOMP */ + minit(); /* ZEROCOMP */ if (rlen == 0) { - if (verbose) { - pline("File \"%s\" is empty?", name); - wait_synch(); - } - return FALSE; + if (verbose) { + pline("File \"%s\" is empty?", name); + wait_synch(); + } + return FALSE; } if (!check_version(&vers_info, name, verbose)) { - if (verbose) wait_synch(); - return FALSE; + if (verbose) + wait_synch(); + return FALSE; } return TRUE; } @@ -188,16 +194,17 @@ void store_version(fd) int fd; { - static const struct version_info version_data = { - VERSION_NUMBER, VERSION_FEATURES, - VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3 - }; + static const struct version_info version_data = { + VERSION_NUMBER, VERSION_FEATURES, VERSION_SANITY1, VERSION_SANITY2, + VERSION_SANITY3 + }; - bufoff(fd); - /* bwrite() before bufon() uses plain write() */ - bwrite(fd,(genericptr_t)&version_data,(unsigned)(sizeof version_data)); - bufon(fd); - return; + bufoff(fd); + /* bwrite() before bufon() uses plain write() */ + bwrite(fd, (genericptr_t) &version_data, + (unsigned) (sizeof version_data)); + bufon(fd); + return; } #ifdef AMIGA @@ -208,37 +215,40 @@ unsigned long get_feature_notice_ver(str) char *str; { - char buf[BUFSZ]; - int ver_maj, ver_min, patch; - char *istr[3]; - int j = 0; + char buf[BUFSZ]; + int ver_maj, ver_min, patch; + char *istr[3]; + int j = 0; - if (!str) return 0L; - str = strcpy(buf, str); - istr[j] = str; - while (*str) { - if (*str == '.') { - *str++ = '\0'; - j++; - istr[j] = str; - if (j == 2) break; - } else if (index("0123456789", *str) != 0) { - str++; - } else - return 0L; - } - if (j != 2) return 0L; - ver_maj = atoi(istr[0]); - ver_min = atoi(istr[1]); - patch = atoi(istr[2]); - return FEATURE_NOTICE_VER(ver_maj,ver_min,patch); - /* macro from hack.h */ + if (!str) + return 0L; + str = strcpy(buf, str); + istr[j] = str; + while (*str) { + if (*str == '.') { + *str++ = '\0'; + j++; + istr[j] = str; + if (j == 2) + break; + } else if (index("0123456789", *str) != 0) { + str++; + } else + return 0L; + } + if (j != 2) + return 0L; + ver_maj = atoi(istr[0]); + ver_min = atoi(istr[1]); + patch = atoi(istr[2]); + return FEATURE_NOTICE_VER(ver_maj, ver_min, patch); + /* macro from hack.h */ } unsigned long get_current_feature_ver() { - return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL); + return FEATURE_NOTICE_VER(VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); } /*ARGUSED*/ @@ -247,16 +257,20 @@ copyright_banner_line(indx) int indx; { #ifdef COPYRIGHT_BANNER_A - if (indx == 1) return COPYRIGHT_BANNER_A; + if (indx == 1) + return COPYRIGHT_BANNER_A; #endif #ifdef COPYRIGHT_BANNER_B - if (indx == 2) return COPYRIGHT_BANNER_B; + if (indx == 2) + return COPYRIGHT_BANNER_B; #endif #ifdef COPYRIGHT_BANNER_C - if (indx == 3) return COPYRIGHT_BANNER_C; + if (indx == 3) + return COPYRIGHT_BANNER_C; #endif #ifdef COPYRIGHT_BANNER_D - if (indx == 4) return COPYRIGHT_BANNER_D; + if (indx == 4) + return COPYRIGHT_BANNER_D; #endif return ""; } diff --git a/src/vision.c b/src/vision.c index 4e9aa87d9..d6a40dab4 100644 --- a/src/vision.c +++ b/src/vision.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vision.c $NHDT-Date: 1426449474 2015/03/15 19:57:54 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.14 $ */ +/* NetHack 3.6 vision.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */ /* NetHack 3.6 vision.c $Date: 2009/05/06 10:48:10 $ $Revision: 1.12 $ */ /* SCCS Id: @(#)vision.c 3.5 2007/11/05 */ /* Copyright (c) Dean Luick, with acknowledgements to Dave Cohrs, 1990. */ @@ -6,7 +6,8 @@ #include "hack.h" -/* Circles ==================================================================*/ +/* Circles + * ==================================================================*/ /* * These numbers are limit offsets for one quadrant of a circle of a given @@ -25,22 +26,23 @@ * */ char circle_data[] = { -/* 0*/ 1, 1, -/* 2*/ 2, 2, 1, -/* 5*/ 3, 3, 2, 1, -/* 9*/ 4, 4, 4, 3, 2, -/* 14*/ 5, 5, 5, 4, 3, 2, -/* 20*/ 6, 6, 6, 5, 5, 4, 2, -/* 27*/ 7, 7, 7, 6, 6, 5, 4, 2, -/* 35*/ 8, 8, 8, 7, 7, 6, 6, 4, 2, -/* 44*/ 9, 9, 9, 9, 8, 8, 7, 6, 5, 3, -/* 54*/ 10,10,10,10, 9, 9, 8, 7, 6, 5, 3, -/* 65*/ 11,11,11,11,10,10, 9, 9, 8, 7, 5, 3, -/* 77*/ 12,12,12,12,11,11,10,10, 9, 8, 7, 5, 3, -/* 90*/ 13,13,13,13,12,12,12,11,10,10, 9, 7, 6, 3, -/*104*/ 14,14,14,14,13,13,13,12,12,11,10, 9, 8, 6, 3, -/*119*/ 15,15,15,15,14,14,14,13,13,12,11,10, 9, 8, 6, 3, -/*135*/ 16 /* should be MAX_RADIUS+1; used to terminate range loops -dlc */ + /* 0*/ 1, 1, + /* 2*/ 2, 2, 1, + /* 5*/ 3, 3, 2, 1, + /* 9*/ 4, 4, 4, 3, 2, + /* 14*/ 5, 5, 5, 4, 3, 2, + /* 20*/ 6, 6, 6, 5, 5, 4, 2, + /* 27*/ 7, 7, 7, 6, 6, 5, 4, 2, + /* 35*/ 8, 8, 8, 7, 7, 6, 6, 4, 2, + /* 44*/ 9, 9, 9, 9, 8, 8, 7, 6, 5, 3, + /* 54*/ 10, 10, 10, 10, 9, 9, 8, 7, 6, 5, 3, + /* 65*/ 11, 11, 11, 11, 10, 10, 9, 9, 8, 7, 5, 3, + /* 77*/ 12, 12, 12, 12, 11, 11, 10, 10, 9, 8, 7, 5, 3, + /* 90*/ 13, 13, 13, 13, 12, 12, 12, 11, 10, 10, 9, 7, 6, 3, + /*104*/ 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 10, 9, 8, 6, 3, + /*119*/ 15, 15, 15, 15, 14, 14, 14, 13, 13, 12, 11, 10, 9, 8, 6, 3, + /*135*/ 16 /* should be MAX_RADIUS+1; used to terminate range loops -dlc + */ }; /* @@ -48,66 +50,65 @@ char circle_data[] = { * circle of a given radius. */ char circle_start[] = { -/* */ 0, /* circles of radius zero are not used */ -/* 1*/ 0, -/* 2*/ 2, -/* 3*/ 5, -/* 4*/ 9, -/* 5*/ 14, -/* 6*/ 20, -/* 7*/ 27, -/* 8*/ 35, -/* 9*/ 44, -/*10*/ 54, -/*11*/ 65, -/*12*/ 77, -/*13*/ 90, -/*14*/ 104, -/*15*/ 119, + /* */ 0, /* circles of radius zero are not used */ + /* 1*/ 0, + /* 2*/ 2, + /* 3*/ 5, + /* 4*/ 9, + /* 5*/ 14, + /* 6*/ 20, + /* 7*/ 27, + /* 8*/ 35, + /* 9*/ 44, + /*10*/ 54, + /*11*/ 65, + /*12*/ 77, + /*13*/ 90, + /*14*/ 104, + /*15*/ 119, }; - /*===========================================================================*/ -/* Vision (arbitrary line of sight) =========================================*/ +/* Vision (arbitrary line of sight) + * =========================================*/ /*------ global variables ------*/ -#if 0 /* (moved to decl.c) */ +#if 0 /* (moved to decl.c) */ /* True if we need to run a full vision recalculation. */ boolean vision_full_recalc = 0; /* Pointers to the current vision array. */ char **viz_array; #endif -char *viz_rmin, *viz_rmax; /* current vision cs bounds */ - +char *viz_rmin, *viz_rmax; /* current vision cs bounds */ /*------ local variables ------*/ - -static char could_see[2][ROWNO][COLNO]; /* vision work space */ +static char could_see[2][ROWNO][COLNO]; /* vision work space */ static char *cs_rows0[ROWNO], *cs_rows1[ROWNO]; -static char cs_rmin0[ROWNO], cs_rmax0[ROWNO]; -static char cs_rmin1[ROWNO], cs_rmax1[ROWNO]; +static char cs_rmin0[ROWNO], cs_rmax0[ROWNO]; +static char cs_rmin1[ROWNO], cs_rmax1[ROWNO]; -static char viz_clear[ROWNO][COLNO]; /* vision clear/blocked map */ +static char viz_clear[ROWNO][COLNO]; /* vision clear/blocked map */ static char *viz_clear_rows[ROWNO]; -static char left_ptrs[ROWNO][COLNO]; /* LOS algorithm helpers */ +static char left_ptrs[ROWNO][COLNO]; /* LOS algorithm helpers */ static char right_ptrs[ROWNO][COLNO]; /* Forward declarations. */ -STATIC_DCL void FDECL(fill_point, (int,int)); -STATIC_DCL void FDECL(dig_point, (int,int)); +STATIC_DCL void FDECL(fill_point, (int, int)); +STATIC_DCL void FDECL(dig_point, (int, int)); STATIC_DCL void NDECL(view_init); -STATIC_DCL void FDECL(view_from,(int,int,char **,char *,char *,int, - void (*)(int,int,genericptr_t),genericptr_t)); -STATIC_DCL void FDECL(get_unused_cs, (char ***,char **,char **)); -STATIC_DCL void FDECL(rogue_vision, (char **,char *,char *)); +STATIC_DCL void FDECL(view_from, + (int, int, char **, char *, char *, int, + void (*)(int, int, genericptr_t), genericptr_t)); +STATIC_DCL void FDECL(get_unused_cs, (char ***, char **, char **)); +STATIC_DCL void FDECL(rogue_vision, (char **, char *, char *)); /* Macro definitions that I can't find anywhere. */ -#define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0 )) -#define v_abs(z) ((z) < 0 ? -(z) : (z)) /* don't use abs -- it may exist */ +#define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0)) +#define v_abs(z) ((z) < 0 ? -(z) : (z)) /* don't use abs -- it may exist */ /* * vision_init() @@ -124,15 +125,15 @@ vision_init() /* Set up the pointers. */ for (i = 0; i < ROWNO; i++) { - cs_rows0[i] = could_see[0][i]; - cs_rows1[i] = could_see[1][i]; - viz_clear_rows[i] = viz_clear[i]; + cs_rows0[i] = could_see[0][i]; + cs_rows1[i] = could_see[1][i]; + viz_clear_rows[i] = viz_clear[i]; } /* Start out with cs0 as our current array */ viz_array = cs_rows0; - viz_rmin = cs_rmin0; - viz_rmax = cs_rmax0; + viz_rmin = cs_rmin0; + viz_rmax = cs_rmax0; vision_full_recalc = 0; (void) memset((genericptr_t) could_see, 0, sizeof(could_see)); @@ -142,7 +143,7 @@ vision_init() #ifdef VISION_TABLES /* Note: this initializer doesn't do anything except guarantee that - we're linked properly. + we're linked properly. */ vis_tab_init(); #endif @@ -155,32 +156,36 @@ vision_init() * sight. */ int -does_block(x,y,lev) - int x, y; - register struct rm *lev; +does_block(x, y, lev) +int x, y; +register struct rm *lev; { - struct obj *obj; + struct obj *obj; struct monst *mon; /* Features that block . . */ - if (IS_ROCK(lev->typ) || lev->typ == TREE || (IS_DOOR(lev->typ) && - (lev->doormask & (D_CLOSED|D_LOCKED|D_TRAPPED) ))) - return 1; + if (IS_ROCK(lev->typ) || lev->typ == TREE + || (IS_DOOR(lev->typ) + && (lev->doormask & (D_CLOSED | D_LOCKED | D_TRAPPED)))) + return 1; - if (lev->typ == CLOUD || lev->typ == WATER || - (lev->typ == MOAT && Underwater)) - return 1; + if (lev->typ == CLOUD || lev->typ == WATER + || (lev->typ == MOAT && Underwater)) + return 1; /* Boulders block light. */ for (obj = level.objects[x][y]; obj; obj = obj->nexthere) - if (obj->otyp == BOULDER) return 1; + if (obj->otyp == BOULDER) + return 1; /* Mimics mimicing a door or boulder block light. */ - if ((mon = m_at(x,y)) && (!mon->minvis || See_invisible) && - ((mon->m_ap_type == M_AP_FURNITURE && - (mon->mappearance == S_hcdoor || mon->mappearance == S_vcdoor)) || - (mon->m_ap_type == M_AP_OBJECT && mon->mappearance == BOULDER))) - return 1; + if ((mon = m_at(x, y)) && (!mon->minvis || See_invisible) + && ((mon->m_ap_type == M_AP_FURNITURE + && (mon->mappearance == S_hcdoor + || mon->mappearance == S_vcdoor)) + || (mon->m_ap_type == M_AP_OBJECT + && mon->mappearance == BOULDER))) + return 1; return 0; } @@ -196,57 +201,58 @@ vision_reset() { int y; register int x, i, dig_left, block; - register struct rm *lev; + register struct rm *lev; /* Start out with cs0 as our current array */ viz_array = cs_rows0; - viz_rmin = cs_rmin0; - viz_rmax = cs_rmax0; + viz_rmin = cs_rmin0; + viz_rmax = cs_rmax0; (void) memset((genericptr_t) could_see, 0, sizeof(could_see)); /* Reset the pointers and clear so that we have a "full" dungeon. */ - (void) memset((genericptr_t) viz_clear, 0, sizeof(viz_clear)); + (void) memset((genericptr_t) viz_clear, 0, sizeof(viz_clear)); /* Dig the level */ for (y = 0; y < ROWNO; y++) { - dig_left = 0; - block = TRUE; /* location (0,y) is always stone; it's !isok() */ - lev = &levl[1][y]; - for (x = 1; x < COLNO; x++, lev += ROWNO) - if (block != (IS_ROCK(lev->typ) || does_block(x,y,lev))) { - if(block) { - for(i=dig_left; ityp) || does_block(x, y, lev))) { + if (block) { + for (i = dig_left; i < x; i++) { + left_ptrs[y][i] = dig_left; + right_ptrs[y][i] = x - 1; + } + } else { + i = dig_left; + if (dig_left) + dig_left--; /* point at first blocked point */ + for (; i < x; i++) { + left_ptrs[y][i] = dig_left; + right_ptrs[y][i] = x; + viz_clear[y][i] = 1; + } + } + dig_left = x; + block = !block; + } + /* handle right boundary; almost identical for blocked/unblocked */ + i = dig_left; + if (!block && dig_left) + dig_left--; /* point at first blocked point */ + for (; i < COLNO; i++) { + left_ptrs[y][i] = dig_left; + right_ptrs[y][i] = (COLNO - 1); + viz_clear[y][i] = !block; + } } - iflags.vision_inited = 1; /* vision is ready */ - vision_full_recalc = 1; /* we want to run vision_recalc() */ + iflags.vision_inited = 1; /* vision is ready */ + vision_full_recalc = 1; /* we want to run vision_recalc() */ } - /* * get_unused_cs() * @@ -255,34 +261,34 @@ vision_reset() */ STATIC_OVL void get_unused_cs(rows, rmin, rmax) - char ***rows; - char **rmin, **rmax; +char ***rows; +char **rmin, **rmax; { - register int row; + register int row; register char *nrmin, *nrmax; if (viz_array == cs_rows0) { - *rows = cs_rows1; - *rmin = cs_rmin1; - *rmax = cs_rmax1; + *rows = cs_rows1; + *rmin = cs_rmin1; + *rmax = cs_rmax1; } else { - *rows = cs_rows0; - *rmin = cs_rmin0; - *rmax = cs_rmax0; + *rows = cs_rows0; + *rmin = cs_rmin0; + *rmax = cs_rmax0; } /* return an initialized, unused work area */ nrmin = *rmin; nrmax = *rmax; - (void) memset((genericptr_t)**rows, 0, ROWNO*COLNO); /* we see nothing */ - for (row = 0; row < ROWNO; row++) { /* set row min & max */ - *nrmin++ = COLNO-1; - *nrmax++ = 0; + (void) memset((genericptr_t) * *rows, 0, + ROWNO * COLNO); /* we see nothing */ + for (row = 0; row < ROWNO; row++) { /* set row min & max */ + *nrmin++ = COLNO - 1; + *nrmax++ = 0; } } - /* * rogue_vision() * @@ -297,8 +303,8 @@ get_unused_cs(rows, rmin, rmax) */ STATIC_OVL void rogue_vision(next, rmin, rmax) - char **next; /* could_see array pointers */ - char *rmin, *rmax; +char **next; /* could_see array pointers */ +char *rmin, *rmax; { int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; /* no SHARED... */ int start, stop, in_door, xhi, xlo, yhi, ylo; @@ -307,18 +313,18 @@ rogue_vision(next, rmin, rmax) /* If in a lit room, we are able to see to its boundaries. */ /* If dark, set COULD_SEE so various spells work -dlc */ if (rnum >= 0) { - for (zy = rooms[rnum].ly-1; zy <= rooms[rnum].hy+1; zy++) { - rmin[zy] = start = rooms[rnum].lx-1; - rmax[zy] = stop = rooms[rnum].hx+1; + for (zy = rooms[rnum].ly - 1; zy <= rooms[rnum].hy + 1; zy++) { + rmin[zy] = start = rooms[rnum].lx - 1; + rmax[zy] = stop = rooms[rnum].hx + 1; - for (zx = start; zx <= stop; zx++) { - if (rooms[rnum].rlit) { - next[zy][zx] = COULD_SEE | IN_SIGHT; - levl[zx][zy].seenv = SVALL; /* see the walls */ - } else - next[zy][zx] = COULD_SEE; - } - } + for (zx = start; zx <= stop; zx++) { + if (rooms[rnum].rlit) { + next[zy][zx] = COULD_SEE | IN_SIGHT; + levl[zx][zy].seenv = SVALL; /* see the walls */ + } else + next[zy][zx] = COULD_SEE; + } + } } in_door = levl[u.ux][u.uy].typ == DOOR; @@ -329,25 +335,28 @@ rogue_vision(next, rmin, rmax) xlo = max(u.ux - 1, 1); xhi = min(u.ux + 1, COLNO - 1); for (zy = ylo; zy <= yhi; zy++) { - if (xlo < rmin[zy]) rmin[zy] = xlo; - if (xhi > rmax[zy]) rmax[zy] = xhi; + if (xlo < rmin[zy]) + rmin[zy] = xlo; + if (xhi > rmax[zy]) + rmax[zy] = xhi; - for (zx = xlo; zx <= xhi; zx++) { - next[zy][zx] = COULD_SEE | IN_SIGHT; - /* - * Yuck, update adjacent non-diagonal positions when in a doorway. - * We need to do this to catch the case when we first step into - * a room. The room's walls were not seen from the outside, but - * now are seen (the seen bits are set just above). However, the - * positions are not updated because they were already in sight. - * So, we have to do it here. - */ - if (in_door && (zx == u.ux || zy == u.uy)) newsym(zx,zy); - } + for (zx = xlo; zx <= xhi; zx++) { + next[zy][zx] = COULD_SEE | IN_SIGHT; + /* + * Yuck, update adjacent non-diagonal positions when in a doorway. + * We need to do this to catch the case when we first step into + * a room. The room's walls were not seen from the outside, but + * now are seen (the seen bits are set just above). However, the + * positions are not updated because they were already in sight. + * So, we have to do it here. + */ + if (in_door && (zx == u.ux || zy == u.uy)) + newsym(zx, zy); + } } } -/*#define EXTEND_SPINE*/ /* possibly better looking wall-angle */ + /*#define EXTEND_SPINE*/ /* possibly better looking wall-angle */ #ifdef EXTEND_SPINE @@ -388,7 +397,7 @@ STATIC_DCL int FDECL(new_angle, (struct rm *, unsigned char *, int, int)); * bits, then again to correctly set the seenv bits. * + I'm trying to make this as cheap as possible. The display & * vision eat up too much CPU time. - * + * * * Note: Even as I write this, I'm still not convinced. There are too * many exceptions. I may have to bite the bullet and do more @@ -396,9 +405,9 @@ STATIC_DCL int FDECL(new_angle, (struct rm *, unsigned char *, int, int)); */ STATIC_OVL int new_angle(lev, sv, row, col) - struct rm *lev; - unsigned char *sv; - int row, col; +struct rm *lev; +unsigned char *sv; +int row, col; { register int res = *sv; @@ -407,24 +416,32 @@ new_angle(lev, sv, row, col) * an angle. */ if (lev->typ >= CROSSWALL && lev->typ <= TRWALL) { - switch (res) { - case SV0: - if (col > 0 && viz_clear[row][col-1]) res |= SV7; - if (row > 0 && viz_clear[row-1][col]) res |= SV1; - break; - case SV2: - if (row > 0 && viz_clear[row-1][col]) res |= SV1; - if (col < COLNO-1 && viz_clear[row][col+1]) res |= SV3; - break; - case SV4: - if (col < COLNO-1 && viz_clear[row][col+1]) res |= SV3; - if (row < ROWNO-1 && viz_clear[row+1][col]) res |= SV5; - break; - case SV6: - if (row < ROWNO-1 && viz_clear[row+1][col]) res |= SV5; - if (col > 0 && viz_clear[row][col-1]) res |= SV7; - break; - } + switch (res) { + case SV0: + if (col > 0 && viz_clear[row][col - 1]) + res |= SV7; + if (row > 0 && viz_clear[row - 1][col]) + res |= SV1; + break; + case SV2: + if (row > 0 && viz_clear[row - 1][col]) + res |= SV1; + if (col < COLNO - 1 && viz_clear[row][col + 1]) + res |= SV3; + break; + case SV4: + if (col < COLNO - 1 && viz_clear[row][col + 1]) + res |= SV3; + if (row < ROWNO - 1 && viz_clear[row + 1][col]) + res |= SV5; + break; + case SV6: + if (row < ROWNO - 1 && viz_clear[row + 1][col]) + res |= SV5; + if (col > 0 && viz_clear[row][col - 1]) + res |= SV7; + break; + } } return res; } @@ -441,7 +458,6 @@ new_angle(lev, sv, row, col) #endif - /* * vision_recalc() * @@ -490,28 +506,29 @@ new_angle(lev, sv, row, col) */ void vision_recalc(control) - int control; +int control; { - char **temp_array; /* points to the old vision array */ - char **next_array; /* points to the new vision array */ - char *next_row; /* row pointer for the new array */ - char *old_row; /* row pointer for the old array */ - char *next_rmin; /* min pointer for the new array */ - char *next_rmax; /* max pointer for the new array */ - char *ranges; /* circle ranges -- used for xray & night vision */ - int row = 0; /* row counter (outer loop) */ - int start, stop; /* inner loop starting/stopping index */ - int dx, dy; /* one step from a lit door or lit wall (see below) */ - register int col; /* inner loop counter */ - register struct rm *lev; /* pointer to current pos */ - struct rm *flev; /* pointer to position in "front" of current pos */ - extern unsigned char seenv_matrix[3][3]; /* from display.c */ - static unsigned char colbump[COLNO+1]; /* cols to bump sv */ - unsigned char *sv; /* ptr to seen angle bits */ - int oldseenv; /* previous seenv value */ + char **temp_array; /* points to the old vision array */ + char **next_array; /* points to the new vision array */ + char *next_row; /* row pointer for the new array */ + char *old_row; /* row pointer for the old array */ + char *next_rmin; /* min pointer for the new array */ + char *next_rmax; /* max pointer for the new array */ + char *ranges; /* circle ranges -- used for xray & night vision */ + int row = 0; /* row counter (outer loop) */ + int start, stop; /* inner loop starting/stopping index */ + int dx, dy; /* one step from a lit door or lit wall (see below) */ + register int col; /* inner loop counter */ + register struct rm *lev; /* pointer to current pos */ + struct rm *flev; /* pointer to position in "front" of current pos */ + extern unsigned char seenv_matrix[3][3]; /* from display.c */ + static unsigned char colbump[COLNO + 1]; /* cols to bump sv */ + unsigned char *sv; /* ptr to seen angle bits */ + int oldseenv; /* previous seenv value */ - vision_full_recalc = 0; /* reset flag */ - if (in_mklev || !iflags.vision_inited) return; + vision_full_recalc = 0; /* reset flag */ + if (in_mklev || !iflags.vision_inited) + return; /* * Either the light sources have been taken care of, or we must @@ -523,148 +540,165 @@ vision_recalc(control) /* You see nothing, nothing can see you --- if swallowed or refreshing. */ if (u.uswallow || control == 2) { - /* do nothing -- get_unused_cs() nulls out the new work area */ + /* do nothing -- get_unused_cs() nulls out the new work area */ } else if (Blind) { - /* - * Calculate the could_see array even when blind so that monsters - * can see you, even if you can't see them. Note that the current - * setup allows: - * - * + Monsters to see with the "new" vision, even on the rogue - * level. - * - * + Monsters can see you even when you're in a pit. - */ - view_from(u.uy, u.ux, next_array, next_rmin, next_rmax, - 0, (void FDECL((*),(int,int,genericptr_t)))0, (genericptr_t)0); + /* + * Calculate the could_see array even when blind so that monsters + * can see you, even if you can't see them. Note that the current + * setup allows: + * + * + Monsters to see with the "new" vision, even on the rogue + * level. + * + * + Monsters can see you even when you're in a pit. + */ + view_from(u.uy, u.ux, next_array, next_rmin, next_rmax, 0, + (void FDECL((*), (int, int, genericptr_t))) 0, + (genericptr_t) 0); - /* - * Our own version of the update loop below. We know we can't see - * anything, so we only need update positions we used to be able - * to see. - */ - temp_array = viz_array; /* set viz_array so newsym() will work */ - viz_array = next_array; + /* + * Our own version of the update loop below. We know we can't see + * anything, so we only need update positions we used to be able + * to see. + */ + temp_array = viz_array; /* set viz_array so newsym() will work */ + viz_array = next_array; - for (row = 0; row < ROWNO; row++) { - old_row = temp_array[row]; + for (row = 0; row < ROWNO; row++) { + old_row = temp_array[row]; - /* Find the min and max positions on the row. */ - start = min(viz_rmin[row], next_rmin[row]); - stop = max(viz_rmax[row], next_rmax[row]); + /* Find the min and max positions on the row. */ + start = min(viz_rmin[row], next_rmin[row]); + stop = max(viz_rmax[row], next_rmax[row]); - for (col = start; col <= stop; col++) - if (old_row[col] & IN_SIGHT) newsym(col,row); - } + for (col = start; col <= stop; col++) + if (old_row[col] & IN_SIGHT) + newsym(col, row); + } - /* skip the normal update loop */ - goto skip; + /* skip the normal update loop */ + goto skip; } else if (Is_rogue_level(&u.uz)) { - rogue_vision(next_array,next_rmin,next_rmax); + rogue_vision(next_array, next_rmin, next_rmax); } else { - int has_night_vision = 1; /* hero has night vision */ + int has_night_vision = 1; /* hero has night vision */ - if (Underwater && !Is_waterlevel(&u.uz)) { - /* - * The hero is under water. Only see surrounding locations if - * they are also underwater. This overrides night vision but - * does not override x-ray vision. - */ - has_night_vision = 0; + if (Underwater && !Is_waterlevel(&u.uz)) { + /* + * The hero is under water. Only see surrounding locations if + * they are also underwater. This overrides night vision but + * does not override x-ray vision. + */ + has_night_vision = 0; - for (row = u.uy-1; row <= u.uy+1; row++) - for (col = u.ux-1; col <= u.ux+1; col++) { - if (!isok(col,row) || !is_pool(col,row)) continue; + for (row = u.uy - 1; row <= u.uy + 1; row++) + for (col = u.ux - 1; col <= u.ux + 1; col++) { + if (!isok(col, row) || !is_pool(col, row)) + continue; - next_rmin[row] = min(next_rmin[row], col); - next_rmax[row] = max(next_rmax[row], col); - next_array[row][col] = IN_SIGHT | COULD_SEE; - } - } + next_rmin[row] = min(next_rmin[row], col); + next_rmax[row] = max(next_rmax[row], col); + next_array[row][col] = IN_SIGHT | COULD_SEE; + } + } - /* if in a pit, just update for immediate locations */ - else if (u.utrap && u.utraptype == TT_PIT) { - for (row = u.uy-1; row <= u.uy+1; row++) { - if (row < 0) continue; if (row >= ROWNO) break; + /* if in a pit, just update for immediate locations */ + else if (u.utrap && u.utraptype == TT_PIT) { + for (row = u.uy - 1; row <= u.uy + 1; row++) { + if (row < 0) + continue; + if (row >= ROWNO) + break; - next_rmin[row] = max( 0, u.ux - 1); - next_rmax[row] = min(COLNO-1, u.ux + 1); - next_row = next_array[row]; + next_rmin[row] = max(0, u.ux - 1); + next_rmax[row] = min(COLNO - 1, u.ux + 1); + next_row = next_array[row]; - for(col=next_rmin[row]; col <= next_rmax[row]; col++) - next_row[col] = IN_SIGHT | COULD_SEE; - } - } else - view_from(u.uy, u.ux, next_array, next_rmin, next_rmax, - 0, (void FDECL((*),(int,int,genericptr_t)))0, (genericptr_t)0); + for (col = next_rmin[row]; col <= next_rmax[row]; col++) + next_row[col] = IN_SIGHT | COULD_SEE; + } + } else + view_from(u.uy, u.ux, next_array, next_rmin, next_rmax, 0, + (void FDECL((*), (int, int, genericptr_t))) 0, + (genericptr_t) 0); - /* - * Set the IN_SIGHT bit for xray and night vision. - */ - if (u.xray_range >= 0) { - if (u.xray_range) { - ranges = circle_ptr(u.xray_range); + /* + * Set the IN_SIGHT bit for xray and night vision. + */ + if (u.xray_range >= 0) { + if (u.xray_range) { + ranges = circle_ptr(u.xray_range); - for (row = u.uy-u.xray_range; row <= u.uy+u.xray_range; row++) { - if (row < 0) continue; if (row >= ROWNO) break; - dy = v_abs(u.uy-row); next_row = next_array[row]; + for (row = u.uy - u.xray_range; row <= u.uy + u.xray_range; + row++) { + if (row < 0) + continue; + if (row >= ROWNO) + break; + dy = v_abs(u.uy - row); + next_row = next_array[row]; - start = max( 0, u.ux - ranges[dy]); - stop = min(COLNO-1, u.ux + ranges[dy]); + start = max(0, u.ux - ranges[dy]); + stop = min(COLNO - 1, u.ux + ranges[dy]); - for (col = start; col <= stop; col++) { - char old_row_val = next_row[col]; - next_row[col] |= IN_SIGHT; - oldseenv = levl[col][row].seenv; - levl[col][row].seenv = SVALL; /* see all! */ - /* Update if previously not in sight or new angle. */ - if (!(old_row_val & IN_SIGHT) || oldseenv != SVALL) - newsym(col,row); - } + for (col = start; col <= stop; col++) { + char old_row_val = next_row[col]; + next_row[col] |= IN_SIGHT; + oldseenv = levl[col][row].seenv; + levl[col][row].seenv = SVALL; /* see all! */ + /* Update if previously not in sight or new angle. */ + if (!(old_row_val & IN_SIGHT) || oldseenv != SVALL) + newsym(col, row); + } - next_rmin[row] = min(start, next_rmin[row]); - next_rmax[row] = max(stop, next_rmax[row]); - } + next_rmin[row] = min(start, next_rmin[row]); + next_rmax[row] = max(stop, next_rmax[row]); + } - } else { /* range is 0 */ - next_array[u.uy][u.ux] |= IN_SIGHT; - levl[u.ux][u.uy].seenv = SVALL; - next_rmin[u.uy] = min(u.ux, next_rmin[u.uy]); - next_rmax[u.uy] = max(u.ux, next_rmax[u.uy]); - } - } + } else { /* range is 0 */ + next_array[u.uy][u.ux] |= IN_SIGHT; + levl[u.ux][u.uy].seenv = SVALL; + next_rmin[u.uy] = min(u.ux, next_rmin[u.uy]); + next_rmax[u.uy] = max(u.ux, next_rmax[u.uy]); + } + } - if (has_night_vision && u.xray_range < u.nv_range) { - if (!u.nv_range) { /* range is 0 */ - next_array[u.uy][u.ux] |= IN_SIGHT; - levl[u.ux][u.uy].seenv = SVALL; - next_rmin[u.uy] = min(u.ux, next_rmin[u.uy]); - next_rmax[u.uy] = max(u.ux, next_rmax[u.uy]); - } else if (u.nv_range > 0) { - ranges = circle_ptr(u.nv_range); + if (has_night_vision && u.xray_range < u.nv_range) { + if (!u.nv_range) { /* range is 0 */ + next_array[u.uy][u.ux] |= IN_SIGHT; + levl[u.ux][u.uy].seenv = SVALL; + next_rmin[u.uy] = min(u.ux, next_rmin[u.uy]); + next_rmax[u.uy] = max(u.ux, next_rmax[u.uy]); + } else if (u.nv_range > 0) { + ranges = circle_ptr(u.nv_range); - for (row = u.uy-u.nv_range; row <= u.uy+u.nv_range; row++) { - if (row < 0) continue; if (row >= ROWNO) break; - dy = v_abs(u.uy-row); next_row = next_array[row]; + for (row = u.uy - u.nv_range; row <= u.uy + u.nv_range; + row++) { + if (row < 0) + continue; + if (row >= ROWNO) + break; + dy = v_abs(u.uy - row); + next_row = next_array[row]; - start = max( 0, u.ux - ranges[dy]); - stop = min(COLNO-1, u.ux + ranges[dy]); + start = max(0, u.ux - ranges[dy]); + stop = min(COLNO - 1, u.ux + ranges[dy]); - for (col = start; col <= stop; col++) - if (next_row[col]) next_row[col] |= IN_SIGHT; + for (col = start; col <= stop; col++) + if (next_row[col]) + next_row[col] |= IN_SIGHT; - next_rmin[row] = min(start, next_rmin[row]); - next_rmax[row] = max(stop, next_rmax[row]); - } - } - } + next_rmin[row] = min(start, next_rmin[row]); + next_rmax[row] = max(stop, next_rmax[row]); + } + } + } } /* Set the correct bits for all light sources. */ do_light_sources(next_array); - /* * Make the viz_array the new array so that cansee() will work correctly. */ @@ -687,104 +721,112 @@ vision_recalc(control) * Even so, that is not entirely correct. But it seems close * enough for now. */ - colbump[u.ux] = colbump[u.ux+1] = 1; + colbump[u.ux] = colbump[u.ux + 1] = 1; for (row = 0; row < ROWNO; row++) { - dy = u.uy - row; dy = sign(dy); - next_row = next_array[row]; old_row = temp_array[row]; + dy = u.uy - row; + dy = sign(dy); + next_row = next_array[row]; + old_row = temp_array[row]; - /* Find the min and max positions on the row. */ - start = min(viz_rmin[row], next_rmin[row]); - stop = max(viz_rmax[row], next_rmax[row]); - lev = &levl[start][row]; + /* Find the min and max positions on the row. */ + start = min(viz_rmin[row], next_rmin[row]); + stop = max(viz_rmax[row], next_rmax[row]); + lev = &levl[start][row]; - sv = &seenv_matrix[dy+1][start < u.ux ? 0 : (start > u.ux ? 2:1)]; + sv = &seenv_matrix[dy + 1][start < u.ux ? 0 : (start > u.ux ? 2 : 1)]; - for (col = start; col <= stop; - lev += ROWNO, sv += (int) colbump[++col]) { - if (next_row[col] & IN_SIGHT) { - /* - * We see this position because of night- or xray-vision. - */ - oldseenv = lev->seenv; - lev->seenv |= new_angle(lev,sv,row,col); /* update seen angle */ + for (col = start; col <= stop; + lev += ROWNO, sv += (int) colbump[++col]) { + if (next_row[col] & IN_SIGHT) { + /* + * We see this position because of night- or xray-vision. + */ + oldseenv = lev->seenv; + lev->seenv |= + new_angle(lev, sv, row, col); /* update seen angle */ - /* Update pos if previously not in sight or new angle. */ - if ( !(old_row[col] & IN_SIGHT) || oldseenv != lev->seenv) - newsym(col,row); - } + /* Update pos if previously not in sight or new angle. */ + if (!(old_row[col] & IN_SIGHT) || oldseenv != lev->seenv) + newsym(col, row); + } - else if ((next_row[col] & COULD_SEE) - && (lev->lit || (next_row[col] & TEMP_LIT))) { - /* - * We see this position because it is lit. - */ - if ((IS_DOOR(lev->typ) || lev->typ == SDOOR || - IS_WALL(lev->typ)) && !viz_clear[row][col]) { - /* - * Make sure doors, walls, boulders or mimics don't show up - * at the end of dark hallways. We do this by checking - * the adjacent position. If it is lit, then we can see - * the door or wall, otherwise we can't. - */ - dx = u.ux - col; dx = sign(dx); - flev = &(levl[col+dx][row+dy]); - if (flev->lit || next_array[row+dy][col+dx] & TEMP_LIT) { - next_row[col] |= IN_SIGHT; /* we see it */ + else if ((next_row[col] & COULD_SEE) + && (lev->lit || (next_row[col] & TEMP_LIT))) { + /* + * We see this position because it is lit. + */ + if ((IS_DOOR(lev->typ) || lev->typ == SDOOR + || IS_WALL(lev->typ)) && !viz_clear[row][col]) { + /* + * Make sure doors, walls, boulders or mimics don't show + * up + * at the end of dark hallways. We do this by checking + * the adjacent position. If it is lit, then we can see + * the door or wall, otherwise we can't. + */ + dx = u.ux - col; + dx = sign(dx); + flev = &(levl[col + dx][row + dy]); + if (flev->lit + || next_array[row + dy][col + dx] & TEMP_LIT) { + next_row[col] |= IN_SIGHT; /* we see it */ - oldseenv = lev->seenv; - lev->seenv |= new_angle(lev,sv,row,col); + oldseenv = lev->seenv; + lev->seenv |= new_angle(lev, sv, row, col); - /* Update pos if previously not in sight or new angle.*/ - if (!(old_row[col] & IN_SIGHT) || oldseenv!=lev->seenv) - newsym(col,row); - } else - goto not_in_sight; /* we don't see it */ + /* Update pos if previously not in sight or new + * angle.*/ + if (!(old_row[col] & IN_SIGHT) + || oldseenv != lev->seenv) + newsym(col, row); + } else + goto not_in_sight; /* we don't see it */ - } else { - next_row[col] |= IN_SIGHT; /* we see it */ + } else { + next_row[col] |= IN_SIGHT; /* we see it */ - oldseenv = lev->seenv; - lev->seenv |= new_angle(lev,sv,row,col); + oldseenv = lev->seenv; + lev->seenv |= new_angle(lev, sv, row, col); - /* Update pos if previously not in sight or new angle. */ - if ( !(old_row[col] & IN_SIGHT) || oldseenv != lev->seenv) - newsym(col,row); - } - } else if ((next_row[col] & COULD_SEE) && lev->waslit) { - /* - * If we make it here, the hero _could see_ the location, - * but doesn't see it (location is not lit). - * However, the hero _remembers_ it as lit (waslit is true). - * The hero can now see that it is not lit, so change waslit - * and update the location. - */ - lev->waslit = 0; /* remember lit condition */ - newsym(col,row); - } - /* - * At this point we know that the row position is *not* in normal - * sight. That is, the position is could be seen, but is dark - * or LOS is just plain blocked. - * - * Update the position if: - * o If the old one *was* in sight. We may need to clean up - * the glyph -- E.g. darken room spot, etc. - * o If we now could see the location (yet the location is not - * lit), but previously we couldn't see the location, or vice - * versa. Update the spot because there there may be an infared - * monster there. - */ - else { -not_in_sight: - if ((old_row[col] & IN_SIGHT) - || ((next_row[col] & COULD_SEE) - ^ (old_row[col] & COULD_SEE))) - newsym(col,row); - } + /* Update pos if previously not in sight or new angle. */ + if (!(old_row[col] & IN_SIGHT) || oldseenv != lev->seenv) + newsym(col, row); + } + } else if ((next_row[col] & COULD_SEE) && lev->waslit) { + /* + * If we make it here, the hero _could see_ the location, + * but doesn't see it (location is not lit). + * However, the hero _remembers_ it as lit (waslit is true). + * The hero can now see that it is not lit, so change waslit + * and update the location. + */ + lev->waslit = 0; /* remember lit condition */ + newsym(col, row); + } + /* + * At this point we know that the row position is *not* in normal + * sight. That is, the position is could be seen, but is dark + * or LOS is just plain blocked. + * + * Update the position if: + * o If the old one *was* in sight. We may need to clean up + * the glyph -- E.g. darken room spot, etc. + * o If we now could see the location (yet the location is not + * lit), but previously we couldn't see the location, or vice + * versa. Update the spot because there there may be an infared + * monster there. + */ + else { + not_in_sight: + if ((old_row[col] & IN_SIGHT) + || ((next_row[col] & COULD_SEE) + ^ (old_row[col] & COULD_SEE))) + newsym(col, row); + } - } /* end for col . . */ - } /* end for row . . */ - colbump[u.ux] = colbump[u.ux+1] = 0; + } /* end for col . . */ + } /* end for row . . */ + colbump[u.ux] = colbump[u.ux + 1] = 0; skip: /* This newsym() caused a crash delivering msg about failure to open @@ -793,26 +835,25 @@ skip: * program_state.panicking == 1 under those circumstances */ if (!program_state.panicking) - newsym(u.ux, u.uy); /* Make sure the hero shows up! */ + newsym(u.ux, u.uy); /* Make sure the hero shows up! */ /* Set the new min and max pointers. */ - viz_rmin = next_rmin; + viz_rmin = next_rmin; viz_rmax = next_rmax; recalc_mapseen(); } - /* * block_point() * * Make the location opaque to light. */ void -block_point(x,y) - int x, y; +block_point(x, y) +int x, y; { - fill_point(y,x); + fill_point(y, x); /* recalc light sources here? */ @@ -823,7 +864,8 @@ block_point(x,y) * was out of night-vision range of the hero. Suddenly the hero should * see the lit room. */ - if (viz_array[y][x]) vision_full_recalc = 1; + if (viz_array[y][x]) + vision_full_recalc = 1; } /* @@ -832,17 +874,17 @@ block_point(x,y) * Make the location transparent to light. */ void -unblock_point(x,y) - int x, y; +unblock_point(x, y) +int x, y; { - dig_point(y,x); + dig_point(y, x); /* recalc light sources here? */ - if (viz_array[y][x]) vision_full_recalc = 1; + if (viz_array[y][x]) + vision_full_recalc = 1; } - /*===========================================================================*\ | | | Everything below this line uses (y,x) instead of (x,y) --- the | @@ -851,10 +893,11 @@ unblock_point(x,y) | | \*===========================================================================*/ - -/* ========================================================================= *\ - Left and Right Pointer Updates -\* ========================================================================= */ +/* ========================================================================= +*\ + Left and Right Pointer Updates +\* ========================================================================= +*/ /* * LEFT and RIGHT pointer rules @@ -892,183 +935,189 @@ unblock_point(x,y) * spot on its right) will point to itself. */ STATIC_OVL void -dig_point(row,col) - int row,col; +dig_point(row, col) +int row, col; { int i; - if (viz_clear[row][col]) return; /* already done */ + if (viz_clear[row][col]) + return; /* already done */ viz_clear[row][col] = 1; /* * Boundary cases first. */ - if (col == 0) { /* left edge */ - if (viz_clear[row][1]) { - right_ptrs[row][0] = right_ptrs[row][1]; - } else { - right_ptrs[row][0] = 1; - for (i = 1; i <= right_ptrs[row][1]; i++) - left_ptrs[row][i] = 1; - } - } else if (col == (COLNO-1)) { /* right edge */ + if (col == 0) { /* left edge */ + if (viz_clear[row][1]) { + right_ptrs[row][0] = right_ptrs[row][1]; + } else { + right_ptrs[row][0] = 1; + for (i = 1; i <= right_ptrs[row][1]; i++) + left_ptrs[row][i] = 1; + } + } else if (col == (COLNO - 1)) { /* right edge */ - if (viz_clear[row][COLNO-2]) { - left_ptrs[row][COLNO-1] = left_ptrs[row][COLNO-2]; - } else { - left_ptrs[row][COLNO-1] = COLNO-2; - for (i = left_ptrs[row][COLNO-2]; i < COLNO-1; i++) - right_ptrs[row][i] = COLNO-2; - } + if (viz_clear[row][COLNO - 2]) { + left_ptrs[row][COLNO - 1] = left_ptrs[row][COLNO - 2]; + } else { + left_ptrs[row][COLNO - 1] = COLNO - 2; + for (i = left_ptrs[row][COLNO - 2]; i < COLNO - 1; i++) + right_ptrs[row][i] = COLNO - 2; + } } /* * At this point, we know we aren't on the boundaries. */ - else if (viz_clear[row][col-1] && viz_clear[row][col+1]) { - /* Both sides clear */ - for (i = left_ptrs[row][col-1]; i <= col; i++) { - if (!viz_clear[row][i]) continue; /* catch non-end case */ - right_ptrs[row][i] = right_ptrs[row][col+1]; - } - for (i = col; i <= right_ptrs[row][col+1]; i++) { - if (!viz_clear[row][i]) continue; /* catch non-end case */ - left_ptrs[row][i] = left_ptrs[row][col-1]; - } + else if (viz_clear[row][col - 1] && viz_clear[row][col + 1]) { + /* Both sides clear */ + for (i = left_ptrs[row][col - 1]; i <= col; i++) { + if (!viz_clear[row][i]) + continue; /* catch non-end case */ + right_ptrs[row][i] = right_ptrs[row][col + 1]; + } + for (i = col; i <= right_ptrs[row][col + 1]; i++) { + if (!viz_clear[row][i]) + continue; /* catch non-end case */ + left_ptrs[row][i] = left_ptrs[row][col - 1]; + } - } else if (viz_clear[row][col-1]) { - /* Left side clear, right side blocked. */ - for (i = col+1; i <= right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = col+1; + } else if (viz_clear[row][col - 1]) { + /* Left side clear, right side blocked. */ + for (i = col + 1; i <= right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = col + 1; - for (i = left_ptrs[row][col-1]; i <= col; i++) { - if (!viz_clear[row][i]) continue; /* catch non-end case */ - right_ptrs[row][i] = col+1; - } - left_ptrs[row][col] = left_ptrs[row][col-1]; + for (i = left_ptrs[row][col - 1]; i <= col; i++) { + if (!viz_clear[row][i]) + continue; /* catch non-end case */ + right_ptrs[row][i] = col + 1; + } + left_ptrs[row][col] = left_ptrs[row][col - 1]; - } else if (viz_clear[row][col+1]) { - /* Right side clear, left side blocked. */ - for (i = left_ptrs[row][col-1]; i < col; i++) - right_ptrs[row][i] = col-1; + } else if (viz_clear[row][col + 1]) { + /* Right side clear, left side blocked. */ + for (i = left_ptrs[row][col - 1]; i < col; i++) + right_ptrs[row][i] = col - 1; - for (i = col; i <= right_ptrs[row][col+1]; i++) { - if (!viz_clear[row][i]) continue; /* catch non-end case */ - left_ptrs[row][i] = col-1; - } - right_ptrs[row][col] = right_ptrs[row][col+1]; + for (i = col; i <= right_ptrs[row][col + 1]; i++) { + if (!viz_clear[row][i]) + continue; /* catch non-end case */ + left_ptrs[row][i] = col - 1; + } + right_ptrs[row][col] = right_ptrs[row][col + 1]; } else { - /* Both sides blocked */ - for (i = left_ptrs[row][col-1]; i < col; i++) - right_ptrs[row][i] = col-1; + /* Both sides blocked */ + for (i = left_ptrs[row][col - 1]; i < col; i++) + right_ptrs[row][i] = col - 1; - for (i = col+1; i <= right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = col+1; + for (i = col + 1; i <= right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = col + 1; - left_ptrs[row][col] = col-1; - right_ptrs[row][col] = col+1; + left_ptrs[row][col] = col - 1; + right_ptrs[row][col] = col + 1; } } STATIC_OVL void -fill_point(row,col) - int row, col; +fill_point(row, col) +int row, col; { int i; - if (!viz_clear[row][col]) return; + if (!viz_clear[row][col]) + return; viz_clear[row][col] = 0; if (col == 0) { - if (viz_clear[row][1]) { /* adjacent is clear */ - right_ptrs[row][0] = 0; - } else { - right_ptrs[row][0] = right_ptrs[row][1]; - for (i = 1; i <= right_ptrs[row][1]; i++) - left_ptrs[row][i] = 0; - } - } else if (col == COLNO-1) { - if (viz_clear[row][COLNO-2]) { /* adjacent is clear */ - left_ptrs[row][COLNO-1] = COLNO-1; - } else { - left_ptrs[row][COLNO-1] = left_ptrs[row][COLNO-2]; - for (i = left_ptrs[row][COLNO-2]; i < COLNO-1; i++) - right_ptrs[row][i] = COLNO-1; - } + if (viz_clear[row][1]) { /* adjacent is clear */ + right_ptrs[row][0] = 0; + } else { + right_ptrs[row][0] = right_ptrs[row][1]; + for (i = 1; i <= right_ptrs[row][1]; i++) + left_ptrs[row][i] = 0; + } + } else if (col == COLNO - 1) { + if (viz_clear[row][COLNO - 2]) { /* adjacent is clear */ + left_ptrs[row][COLNO - 1] = COLNO - 1; + } else { + left_ptrs[row][COLNO - 1] = left_ptrs[row][COLNO - 2]; + for (i = left_ptrs[row][COLNO - 2]; i < COLNO - 1; i++) + right_ptrs[row][i] = COLNO - 1; + } } /* * Else we know that we are not on an edge. */ - else if (viz_clear[row][col-1] && viz_clear[row][col+1]) { - /* Both sides clear */ - for (i = left_ptrs[row][col-1]+1; i <= col; i++) - right_ptrs[row][i] = col; + else if (viz_clear[row][col - 1] && viz_clear[row][col + 1]) { + /* Both sides clear */ + for (i = left_ptrs[row][col - 1] + 1; i <= col; i++) + right_ptrs[row][i] = col; - if (!left_ptrs[row][col-1]) /* catch the end case */ - right_ptrs[row][0] = col; + if (!left_ptrs[row][col - 1]) /* catch the end case */ + right_ptrs[row][0] = col; - for (i = col; i < right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = col; + for (i = col; i < right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = col; - if (right_ptrs[row][col+1] == COLNO-1) /* catch the end case */ - left_ptrs[row][COLNO-1] = col; + if (right_ptrs[row][col + 1] == COLNO - 1) /* catch the end case */ + left_ptrs[row][COLNO - 1] = col; - } else if (viz_clear[row][col-1]) { - /* Left side clear, right side blocked. */ - for (i = col; i <= right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = col; + } else if (viz_clear[row][col - 1]) { + /* Left side clear, right side blocked. */ + for (i = col; i <= right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = col; - for (i = left_ptrs[row][col-1]+1; i < col; i++) - right_ptrs[row][i] = col; + for (i = left_ptrs[row][col - 1] + 1; i < col; i++) + right_ptrs[row][i] = col; - if (!left_ptrs[row][col-1]) /* catch the end case */ - right_ptrs[row][i] = col; + if (!left_ptrs[row][col - 1]) /* catch the end case */ + right_ptrs[row][i] = col; - right_ptrs[row][col] = right_ptrs[row][col+1]; + right_ptrs[row][col] = right_ptrs[row][col + 1]; - } else if (viz_clear[row][col+1]) { - /* Right side clear, left side blocked. */ - for (i = left_ptrs[row][col-1]; i <= col; i++) - right_ptrs[row][i] = col; + } else if (viz_clear[row][col + 1]) { + /* Right side clear, left side blocked. */ + for (i = left_ptrs[row][col - 1]; i <= col; i++) + right_ptrs[row][i] = col; - for (i = col+1; i < right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = col; + for (i = col + 1; i < right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = col; - if (right_ptrs[row][col+1] == COLNO-1) /* catch the end case */ - left_ptrs[row][i] = col; + if (right_ptrs[row][col + 1] == COLNO - 1) /* catch the end case */ + left_ptrs[row][i] = col; - left_ptrs[row][col] = left_ptrs[row][col-1]; + left_ptrs[row][col] = left_ptrs[row][col - 1]; } else { - /* Both sides blocked */ - for (i = left_ptrs[row][col-1]; i <= col; i++) - right_ptrs[row][i] = right_ptrs[row][col+1]; + /* Both sides blocked */ + for (i = left_ptrs[row][col - 1]; i <= col; i++) + right_ptrs[row][i] = right_ptrs[row][col + 1]; - for (i = col; i <= right_ptrs[row][col+1]; i++) - left_ptrs[row][i] = left_ptrs[row][col-1]; + for (i = col; i <= right_ptrs[row][col + 1]; i++) + left_ptrs[row][i] = left_ptrs[row][col - 1]; } } - /*===========================================================================*/ /*===========================================================================*/ -/* Use either algorithm C or D. See the config.h for more details. =========*/ +/* Use either algorithm C or D. See the config.h for more details. + * =========*/ /* * Variables local to both Algorithms C and D. */ -static int start_row; -static int start_col; -static int step; +static int start_row; +static int start_col; +static int step; static char **cs_rows; static char *cs_left; static char *cs_right; -static void FDECL((*vis_func), (int,int,genericptr_t)); +static void FDECL((*vis_func), (int, int, genericptr_t)); static genericptr_t varg; /* @@ -1084,11 +1133,15 @@ static genericptr_t varg; * The last three macros depend on having local pointers row_min, row_max, * and rowp being set correctly. */ -#define set_cs(rowp,col) (rowp[col] = COULD_SEE) +#define set_cs(rowp, col) (rowp[col] = COULD_SEE) #define good_row(z) ((z) >= 0 && (z) < ROWNO) -#define set_min(z) if (*row_min > (z)) *row_min = (z) -#define set_max(z) if (*row_max < (z)) *row_max = (z) -#define is_clear(row,col) viz_clear_rows[row][col] +#define set_min(z) \ + if (*row_min > (z)) \ + *row_min = (z) +#define set_max(z) \ + if (*row_max < (z)) \ + *row_max = (z) +#define is_clear(row, col) viz_clear_rows[row][col] /* * clear_path() expanded into 4 macros/functions: @@ -1107,7 +1160,7 @@ static genericptr_t varg; * line drawing) for all quadrants. The algorithm was taken from _Procedural * Elements for Computer Graphics_, by David F. Rogers. McGraw-Hill, 1985. */ -#ifdef MACRO_CPATH /* quadrant calls are macros */ +#ifdef MACRO_CPATH /* quadrant calls are macros */ /* * When called, the result is in "result". @@ -1120,232 +1173,252 @@ static genericptr_t varg; /* * Quadrant I (step < 0). */ -#define q1_path(srow,scol,y2,x2,label) \ -{ \ - int dx, dy; \ - register int k, err, x, y, dxs, dys; \ - \ - x = (scol); y = (srow); \ - dx = (x2) - x; dy = y - (y2); \ - \ - result = 0; /* default to a blocked path */\ - \ - dxs = dx << 1; /* save the shifted values */\ - dys = dy << 1; \ - if (dy > dx) { \ - err = dxs - dy; \ - \ - for (k = dy-1; k; k--) { \ - if (err >= 0) { \ - x++; \ - err -= dys; \ - } \ - y--; \ - err += dxs; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } else { \ - err = dys - dx; \ - \ - for (k = dx-1; k; k--) { \ - if (err >= 0) { \ - y--; \ - err -= dxs; \ - } \ - x++; \ - err += dys; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } \ - \ - result = 1; \ -} +#define q1_path(srow, scol, y2, x2, label) \ + { \ + int dx, dy; \ + register int k, err, x, y, dxs, dys; \ + \ + x = (scol); \ + y = (srow); \ + dx = (x2) -x; \ + dy = y - (y2); \ + \ + result = 0; /* default to a blocked path */ \ + \ + dxs = dx << 1; /* save the shifted values */ \ + dys = dy << 1; \ + if (dy > dx) { \ + err = dxs - dy; \ + \ + for (k = dy - 1; k; k--) { \ + if (err >= 0) { \ + x++; \ + err -= dys; \ + } \ + y--; \ + err += dxs; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } else { \ + err = dys - dx; \ + \ + for (k = dx - 1; k; k--) { \ + if (err >= 0) { \ + y--; \ + err -= dxs; \ + } \ + x++; \ + err += dys; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } \ + \ + result = 1; \ + } /* * Quadrant IV (step > 0). */ -#define q4_path(srow,scol,y2,x2,label) \ -{ \ - int dx, dy; \ - register int k, err, x, y, dxs, dys; \ - \ - x = (scol); y = (srow); \ - dx = (x2) - x; dy = (y2) - y; \ - \ - result = 0; /* default to a blocked path */\ - \ - dxs = dx << 1; /* save the shifted values */\ - dys = dy << 1; \ - if (dy > dx) { \ - err = dxs - dy; \ - \ - for (k = dy-1; k; k--) { \ - if (err >= 0) { \ - x++; \ - err -= dys; \ - } \ - y++; \ - err += dxs; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - \ - } else { \ - err = dys - dx; \ - \ - for (k = dx-1; k; k--) { \ - if (err >= 0) { \ - y++; \ - err -= dxs; \ - } \ - x++; \ - err += dys; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } \ - \ - result = 1; \ -} +#define q4_path(srow, scol, y2, x2, label) \ + { \ + int dx, dy; \ + register int k, err, x, y, dxs, dys; \ + \ + x = (scol); \ + y = (srow); \ + dx = (x2) -x; \ + dy = (y2) -y; \ + \ + result = 0; /* default to a blocked path */ \ + \ + dxs = dx << 1; /* save the shifted values */ \ + dys = dy << 1; \ + if (dy > dx) { \ + err = dxs - dy; \ + \ + for (k = dy - 1; k; k--) { \ + if (err >= 0) { \ + x++; \ + err -= dys; \ + } \ + y++; \ + err += dxs; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + \ + } else { \ + err = dys - dx; \ + \ + for (k = dx - 1; k; k--) { \ + if (err >= 0) { \ + y++; \ + err -= dxs; \ + } \ + x++; \ + err += dys; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } \ + \ + result = 1; \ + } /* * Quadrant II (step < 0). */ -#define q2_path(srow,scol,y2,x2,label) \ -{ \ - int dx, dy; \ - register int k, err, x, y, dxs, dys; \ - \ - x = (scol); y = (srow); \ - dx = x - (x2); dy = y - (y2); \ - \ - result = 0; /* default to a blocked path */\ - \ - dxs = dx << 1; /* save the shifted values */\ - dys = dy << 1; \ - if (dy > dx) { \ - err = dxs - dy; \ - \ - for (k = dy-1; k; k--) { \ - if (err >= 0) { \ - x--; \ - err -= dys; \ - } \ - y--; \ - err += dxs; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } else { \ - err = dys - dx; \ - \ - for (k = dx-1; k; k--) { \ - if (err >= 0) { \ - y--; \ - err -= dxs; \ - } \ - x--; \ - err += dys; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } \ - \ - result = 1; \ -} +#define q2_path(srow, scol, y2, x2, label) \ + { \ + int dx, dy; \ + register int k, err, x, y, dxs, dys; \ + \ + x = (scol); \ + y = (srow); \ + dx = x - (x2); \ + dy = y - (y2); \ + \ + result = 0; /* default to a blocked path */ \ + \ + dxs = dx << 1; /* save the shifted values */ \ + dys = dy << 1; \ + if (dy > dx) { \ + err = dxs - dy; \ + \ + for (k = dy - 1; k; k--) { \ + if (err >= 0) { \ + x--; \ + err -= dys; \ + } \ + y--; \ + err += dxs; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } else { \ + err = dys - dx; \ + \ + for (k = dx - 1; k; k--) { \ + if (err >= 0) { \ + y--; \ + err -= dxs; \ + } \ + x--; \ + err += dys; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } \ + \ + result = 1; \ + } /* * Quadrant III (step > 0). */ -#define q3_path(srow,scol,y2,x2,label) \ -{ \ - int dx, dy; \ - register int k, err, x, y, dxs, dys; \ - \ - x = (scol); y = (srow); \ - dx = x - (x2); dy = (y2) - y; \ - \ - result = 0; /* default to a blocked path */\ - \ - dxs = dx << 1; /* save the shifted values */\ - dys = dy << 1; \ - if (dy > dx) { \ - err = dxs - dy; \ - \ - for (k = dy-1; k; k--) { \ - if (err >= 0) { \ - x--; \ - err -= dys; \ - } \ - y++; \ - err += dxs; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - \ - } else { \ - err = dys - dx; \ - \ - for (k = dx-1; k; k--) { \ - if (err >= 0) { \ - y++; \ - err -= dxs; \ - } \ - x--; \ - err += dys; \ - if (!is_clear(y,x)) goto label;/* blocked */\ - } \ - } \ - \ - result = 1; \ -} +#define q3_path(srow, scol, y2, x2, label) \ + { \ + int dx, dy; \ + register int k, err, x, y, dxs, dys; \ + \ + x = (scol); \ + y = (srow); \ + dx = x - (x2); \ + dy = (y2) -y; \ + \ + result = 0; /* default to a blocked path */ \ + \ + dxs = dx << 1; /* save the shifted values */ \ + dys = dy << 1; \ + if (dy > dx) { \ + err = dxs - dy; \ + \ + for (k = dy - 1; k; k--) { \ + if (err >= 0) { \ + x--; \ + err -= dys; \ + } \ + y++; \ + err += dxs; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + \ + } else { \ + err = dys - dx; \ + \ + for (k = dx - 1; k; k--) { \ + if (err >= 0) { \ + y++; \ + err -= dxs; \ + } \ + x--; \ + err += dys; \ + if (!is_clear(y, x)) \ + goto label; /* blocked */ \ + } \ + } \ + \ + result = 1; \ + } -#else /* quadrants are really functions */ +#else /* quadrants are really functions */ -STATIC_DCL int FDECL(_q1_path, (int,int,int,int)); -STATIC_DCL int FDECL(_q2_path, (int,int,int,int)); -STATIC_DCL int FDECL(_q3_path, (int,int,int,int)); -STATIC_DCL int FDECL(_q4_path, (int,int,int,int)); +STATIC_DCL int FDECL(_q1_path, (int, int, int, int)); +STATIC_DCL int FDECL(_q2_path, (int, int, int, int)); +STATIC_DCL int FDECL(_q3_path, (int, int, int, int)); +STATIC_DCL int FDECL(_q4_path, (int, int, int, int)); -#define q1_path(sy,sx,y,x,dummy) result = _q1_path(sy,sx,y,x) -#define q2_path(sy,sx,y,x,dummy) result = _q2_path(sy,sx,y,x) -#define q3_path(sy,sx,y,x,dummy) result = _q3_path(sy,sx,y,x) -#define q4_path(sy,sx,y,x,dummy) result = _q4_path(sy,sx,y,x) +#define q1_path(sy, sx, y, x, dummy) result = _q1_path(sy, sx, y, x) +#define q2_path(sy, sx, y, x, dummy) result = _q2_path(sy, sx, y, x) +#define q3_path(sy, sx, y, x, dummy) result = _q3_path(sy, sx, y, x) +#define q4_path(sy, sx, y, x, dummy) result = _q4_path(sy, sx, y, x) /* * Quadrant I (step < 0). */ STATIC_OVL int -_q1_path(srow,scol,y2,x2) - int scol, srow, y2, x2; +_q1_path(srow, scol, y2, x2) +int scol, srow, y2, x2; { int dx, dy; register int k, err, x, y, dxs, dys; - x = scol; y = srow; - dx = x2 - x; dy = y - y2; + x = scol; + y = srow; + dx = x2 - x; + dy = y - y2; - dxs = dx << 1; /* save the shifted values */ + dxs = dx << 1; /* save the shifted values */ dys = dy << 1; if (dy > dx) { - err = dxs - dy; + err = dxs - dy; - for (k = dy-1; k; k--) { - if (err >= 0) { - x++; - err -= dys; - } - y--; - err += dxs; - if (!is_clear(y,x)) return 0; /* blocked */ - } + for (k = dy - 1; k; k--) { + if (err >= 0) { + x++; + err -= dys; + } + y--; + err += dxs; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } else { - err = dys - dx; + err = dys - dx; - for (k = dx-1; k; k--) { - if (err >= 0) { - y--; - err -= dxs; - } - x++; - err += dys; - if (!is_clear(y,x)) return 0;/* blocked */ - } + for (k = dx - 1; k; k--) { + if (err >= 0) { + y--; + err -= dxs; + } + x++; + err += dys; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } return 1; @@ -1355,41 +1428,45 @@ _q1_path(srow,scol,y2,x2) * Quadrant IV (step > 0). */ STATIC_OVL int -_q4_path(srow,scol,y2,x2) - int scol, srow, y2, x2; +_q4_path(srow, scol, y2, x2) +int scol, srow, y2, x2; { int dx, dy; register int k, err, x, y, dxs, dys; - x = scol; y = srow; - dx = x2 - x; dy = y2 - y; + x = scol; + y = srow; + dx = x2 - x; + dy = y2 - y; - dxs = dx << 1; /* save the shifted values */ + dxs = dx << 1; /* save the shifted values */ dys = dy << 1; if (dy > dx) { - err = dxs - dy; + err = dxs - dy; - for (k = dy-1; k; k--) { - if (err >= 0) { - x++; - err -= dys; - } - y++; - err += dxs; - if (!is_clear(y,x)) return 0; /* blocked */ - } + for (k = dy - 1; k; k--) { + if (err >= 0) { + x++; + err -= dys; + } + y++; + err += dxs; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } else { - err = dys - dx; + err = dys - dx; - for (k = dx-1; k; k--) { - if (err >= 0) { - y++; - err -= dxs; - } - x++; - err += dys; - if (!is_clear(y,x)) return 0;/* blocked */ - } + for (k = dx - 1; k; k--) { + if (err >= 0) { + y++; + err -= dxs; + } + x++; + err += dys; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } return 1; @@ -1399,41 +1476,45 @@ _q4_path(srow,scol,y2,x2) * Quadrant II (step < 0). */ STATIC_OVL int -_q2_path(srow,scol,y2,x2) - int scol, srow, y2, x2; +_q2_path(srow, scol, y2, x2) +int scol, srow, y2, x2; { int dx, dy; register int k, err, x, y, dxs, dys; - x = scol; y = srow; - dx = x - x2; dy = y - y2; + x = scol; + y = srow; + dx = x - x2; + dy = y - y2; - dxs = dx << 1; /* save the shifted values */ + dxs = dx << 1; /* save the shifted values */ dys = dy << 1; if (dy > dx) { - err = dxs - dy; + err = dxs - dy; - for (k = dy-1; k; k--) { - if (err >= 0) { - x--; - err -= dys; - } - y--; - err += dxs; - if (!is_clear(y,x)) return 0; /* blocked */ - } + for (k = dy - 1; k; k--) { + if (err >= 0) { + x--; + err -= dys; + } + y--; + err += dxs; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } else { - err = dys - dx; + err = dys - dx; - for (k = dx-1; k; k--) { - if (err >= 0) { - y--; - err -= dxs; - } - x--; - err += dys; - if (!is_clear(y,x)) return 0;/* blocked */ - } + for (k = dx - 1; k; k--) { + if (err >= 0) { + y--; + err -= dxs; + } + x--; + err += dys; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } return 1; @@ -1443,47 +1524,51 @@ _q2_path(srow,scol,y2,x2) * Quadrant III (step > 0). */ STATIC_OVL int -_q3_path(srow,scol,y2,x2) - int scol, srow, y2, x2; +_q3_path(srow, scol, y2, x2) +int scol, srow, y2, x2; { int dx, dy; register int k, err, x, y, dxs, dys; - x = scol; y = srow; - dx = x - x2; dy = y2 - y; + x = scol; + y = srow; + dx = x - x2; + dy = y2 - y; - dxs = dx << 1; /* save the shifted values */ + dxs = dx << 1; /* save the shifted values */ dys = dy << 1; if (dy > dx) { - err = dxs - dy; + err = dxs - dy; - for (k = dy-1; k; k--) { - if (err >= 0) { - x--; - err -= dys; - } - y++; - err += dxs; - if (!is_clear(y,x)) return 0; /* blocked */ - } + for (k = dy - 1; k; k--) { + if (err >= 0) { + x--; + err -= dys; + } + y++; + err += dxs; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } else { - err = dys - dx; + err = dys - dx; - for (k = dx-1; k; k--) { - if (err >= 0) { - y++; - err -= dxs; - } - x--; - err += dys; - if (!is_clear(y,x)) return 0;/* blocked */ - } + for (k = dx - 1; k; k--) { + if (err >= 0) { + y++; + err -= dxs; + } + x--; + err += dys; + if (!is_clear(y, x)) + return 0; /* blocked */ + } } return 1; } -#endif /* quadrants are functions */ +#endif /* quadrants are functions */ /* * Use vision tables to determine if there is a clear path from @@ -1493,60 +1578,58 @@ _q3_path(srow,scol,y2,x2) * do_light_sources() */ boolean -clear_path(col1,row1,col2,row2) - int col1, row1, col2, row2; +clear_path(col1, row1, col2, row2) +int col1, row1, col2, row2; { int result; - if(col1 < col2) { - if(row1 > row2) { - q1_path(row1,col1,row2,col2,cleardone); - } else { - q4_path(row1,col1,row2,col2,cleardone); - } + if (col1 < col2) { + if (row1 > row2) { + q1_path(row1, col1, row2, col2, cleardone); + } else { + q4_path(row1, col1, row2, col2, cleardone); + } } else { - if(row1 > row2) { - q2_path(row1,col1,row2,col2,cleardone); - } else if(row1 == row2 && col1 == col2) { - result = 1; - } else { - q3_path(row1,col1,row2,col2,cleardone); - } + if (row1 > row2) { + q2_path(row1, col1, row2, col2, cleardone); + } else if (row1 == row2 && col1 == col2) { + result = 1; + } else { + q3_path(row1, col1, row2, col2, cleardone); + } } #ifdef MACRO_CPATH cleardone: #endif - return((boolean)result); + return ((boolean) result); } #ifdef VISION_TABLES /*===========================================================================*\ - GENERAL LINE OF SIGHT - Algorithm D + GENERAL LINE OF SIGHT + Algorithm D \*===========================================================================*/ - /* * Indicate caller for the shadow routines. */ #define FROM_RIGHT 0 -#define FROM_LEFT 1 - +#define FROM_LEFT 1 /* * Include the table definitions. */ #include "vis_tab.h" - /* 3D table pointers. */ static close2d *close_dy[CLOSE_MAX_BC_DY]; -static far2d *far_dy[FAR_MAX_BC_DY]; +static far2d *far_dy[FAR_MAX_BC_DY]; -STATIC_DCL void FDECL(right_side, (int,int,int,int,int,int,int,char*)); -STATIC_DCL void FDECL(left_side, (int,int,int,int,int,int,int,char*)); -STATIC_DCL int FDECL(close_shadow, (int,int,int,int)); -STATIC_DCL int FDECL(far_shadow, (int,int,int,int)); +STATIC_DCL void FDECL(right_side, + (int, int, int, int, int, int, int, char *)); +STATIC_DCL void FDECL(left_side, (int, int, int, int, int, int, int, char *)); +STATIC_DCL int FDECL(close_shadow, (int, int, int, int)); +STATIC_DCL int FDECL(far_shadow, (int, int, int, int)); /* * Initialize algorithm D's table pointers. If we don't have these, @@ -1558,13 +1641,12 @@ view_init() int i; for (i = 0; i < CLOSE_MAX_BC_DY; i++) - close_dy[i] = &close_table[i]; + close_dy[i] = &close_table[i]; for (i = 0; i < FAR_MAX_BC_DY; i++) - far_dy[i] = &far_table[i]; + far_dy[i] = &far_table[i]; } - /* * If the far table has an entry of OFF_TABLE, then the far block prevents * us from seeing the location just above/below it. I.e. the first visible @@ -1573,37 +1655,41 @@ view_init() #define OFF_TABLE 0xff STATIC_OVL int -close_shadow(side,this_row,block_row,block_col) - int side,this_row,block_row,block_col; +close_shadow(side, this_row, block_row, block_col) +int side, this_row, block_row, block_col; { register int sdy, sdx, pdy, offset; /* * If on the same column (block_row = -1), then we can see it. */ - if (block_row < 0) return block_col; + if (block_row < 0) + return block_col; /* Take explicit absolute values. Adjust. */ - if ((sdy = (start_row-block_row)) < 0) sdy = -sdy; --sdy; /* src dy */ - if ((sdx = (start_col-block_col)) < 0) sdx = -sdx; /* src dx */ - if ((pdy = (block_row-this_row)) < 0) pdy = -pdy; /* point dy */ + if ((sdy = (start_row - block_row)) < 0) + sdy = -sdy; + --sdy; /* src dy */ + if ((sdx = (start_col - block_col)) < 0) + sdx = -sdx; /* src dx */ + if ((pdy = (block_row - this_row)) < 0) + pdy = -pdy; /* point dy */ - if (sdy < 0 || sdy >= CLOSE_MAX_SB_DY || sdx >= CLOSE_MAX_SB_DX || - pdy >= CLOSE_MAX_BC_DY) { - impossible("close_shadow: bad value"); - return block_col; + if (sdy < 0 || sdy >= CLOSE_MAX_SB_DY || sdx >= CLOSE_MAX_SB_DX + || pdy >= CLOSE_MAX_BC_DY) { + impossible("close_shadow: bad value"); + return block_col; } offset = close_dy[sdy]->close[sdx][pdy]; if (side == FROM_RIGHT) - return block_col + offset; + return block_col + offset; return block_col - offset; } - STATIC_OVL int -far_shadow(side,this_row,block_row,block_col) - int side,this_row,block_row,block_col; +far_shadow(side, this_row, block_row, block_col) +int side, this_row, block_row, block_col; { register int sdy, sdx, pdy, offset; @@ -1616,26 +1702,32 @@ far_shadow(side,this_row,block_row,block_col) * Could easily have the column be -1, but then wouldn't know if it was * the left or right border. */ - if (block_row < 0) return block_col; + if (block_row < 0) + return block_col; /* Take explicit absolute values. Adjust. */ - if ((sdy = (start_row-block_row)) < 0) sdy = -sdy; /* src dy */ - if ((sdx = (start_col-block_col)) < 0) sdx = -sdx; --sdx; /* src dx */ - if ((pdy = (block_row-this_row)) < 0) pdy = -pdy; --pdy; /* point dy */ + if ((sdy = (start_row - block_row)) < 0) + sdy = -sdy; /* src dy */ + if ((sdx = (start_col - block_col)) < 0) + sdx = -sdx; + --sdx; /* src dx */ + if ((pdy = (block_row - this_row)) < 0) + pdy = -pdy; + --pdy; /* point dy */ - if (sdy >= FAR_MAX_SB_DY || sdx < 0 || sdx >= FAR_MAX_SB_DX || - pdy < 0 || pdy >= FAR_MAX_BC_DY) { - impossible("far_shadow: bad value"); - return block_col; + if (sdy >= FAR_MAX_SB_DY || sdx < 0 || sdx >= FAR_MAX_SB_DX || pdy < 0 + || pdy >= FAR_MAX_BC_DY) { + impossible("far_shadow: bad value"); + return block_col; } - if ((offset = far_dy[sdy]->far_q[sdx][pdy]) == OFF_TABLE) offset = -1; + if ((offset = far_dy[sdy]->far_q[sdx][pdy]) == OFF_TABLE) + offset = -1; if (side == FROM_RIGHT) - return block_col + offset; + return block_col + offset; return block_col - offset; } - /* * right_side() * @@ -1643,43 +1735,45 @@ far_shadow(side,this_row,block_row,block_col) */ STATIC_OVL void right_side(row, cb_row, cb_col, fb_row, fb_col, left, right_mark, limits) - int row; /* current row */ - int cb_row, cb_col; /* close block row and col */ - int fb_row, fb_col; /* far block row and col */ - int left; /* left mark of the previous row */ - int right_mark; /* right mark of previous row */ - char *limits; /* points at range limit for current row, or NULL */ +int row; /* current row */ +int cb_row, cb_col; /* close block row and col */ +int fb_row, fb_col; /* far block row and col */ +int left; /* left mark of the previous row */ +int right_mark; /* right mark of previous row */ +char *limits; /* points at range limit for current row, or NULL */ { - register int i; + register int i; register char *rowp = NULL; - int hit_stone = 0; - int left_shadow, right_shadow, loc_right; - int lblock_col; /* local block column (current row) */ - int nrow, deeper; - char *row_min = NULL; /* left most */ - char *row_max = NULL; /* right most */ - int lim_max; /* right most limit of circle */ + int hit_stone = 0; + int left_shadow, right_shadow, loc_right; + int lblock_col; /* local block column (current row) */ + int nrow, deeper; + char *row_min = NULL; /* left most */ + char *row_max = NULL; /* right most */ + int lim_max; /* right most limit of circle */ - nrow = row + step; - deeper = good_row(nrow) && (!limits || (*limits >= *(limits+1))); - if(!vis_func) { - rowp = cs_rows[row]; - row_min = &cs_left[row]; - row_max = &cs_right[row]; + nrow = row + step; + deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1))); + if (!vis_func) { + rowp = cs_rows[row]; + row_min = &cs_left[row]; + row_max = &cs_right[row]; } - if(limits) { - lim_max = start_col + *limits; - if(lim_max > COLNO-1) lim_max = COLNO-1; - if(right_mark > lim_max) right_mark = lim_max; - limits++; /* prepare for next row */ + if (limits) { + lim_max = start_col + *limits; + if (lim_max > COLNO - 1) + lim_max = COLNO - 1; + if (right_mark > lim_max) + right_mark = lim_max; + limits++; /* prepare for next row */ } else - lim_max = COLNO-1; + lim_max = COLNO - 1; /* * Get the left shadow from the close block. This value could be * illegal. */ - left_shadow = close_shadow(FROM_RIGHT,row,cb_row,cb_col); + left_shadow = close_shadow(FROM_RIGHT, row, cb_row, cb_col); /* * Mark all stone walls as seen before the left shadow. All this work @@ -1691,35 +1785,44 @@ right_side(row, cb_row, cb_col, fb_row, fb_col, left, right_mark, limits) * variable that gets the shadow. */ while (left <= right_mark) { - loc_right = right_ptrs[row][left]; - if(loc_right > lim_max) loc_right = lim_max; - if (viz_clear_rows[row][left]) { - if (loc_right >= left_shadow) { - left = left_shadow; /* opening ends beyond shadow */ - break; - } - left = loc_right; - loc_right = right_ptrs[row][left]; - if(loc_right > lim_max) loc_right = lim_max; - if (left == loc_right) return; /* boundary */ + loc_right = right_ptrs[row][left]; + if (loc_right > lim_max) + loc_right = lim_max; + if (viz_clear_rows[row][left]) { + if (loc_right >= left_shadow) { + left = left_shadow; /* opening ends beyond shadow */ + break; + } + left = loc_right; + loc_right = right_ptrs[row][left]; + if (loc_right > lim_max) + loc_right = lim_max; + if (left == loc_right) + return; /* boundary */ - /* Shadow covers opening, beyond right mark */ - if (left == right_mark && left_shadow > right_mark) return; - } + /* Shadow covers opening, beyond right mark */ + if (left == right_mark && left_shadow > right_mark) + return; + } - if (loc_right > right_mark) /* can't see stone beyond the mark */ - loc_right = right_mark; + if (loc_right > right_mark) /* can't see stone beyond the mark */ + loc_right = right_mark; - if(vis_func) { - for (i = left; i <= loc_right; i++) (*vis_func)(i, row, varg); - } else { - for (i = left; i <= loc_right; i++) set_cs(rowp,i); - set_min(left); set_max(loc_right); - } + if (vis_func) { + for (i = left; i <= loc_right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left; i <= loc_right; i++) + set_cs(rowp, i); + set_min(left); + set_max(loc_right); + } - if (loc_right == right_mark) return; /* all stone */ - if (loc_right >= left_shadow) hit_stone = 1; - left = loc_right + 1; + if (loc_right == right_mark) + return; /* all stone */ + if (loc_right >= left_shadow) + hit_stone = 1; + left = loc_right + 1; } /* @@ -1731,8 +1834,8 @@ right_side(row, cb_row, cb_col, fb_row, fb_col, left, right_mark, limits) /* * Get the right shadow. Make sure that it is a legal value. */ - if ((right_shadow = far_shadow(FROM_RIGHT,row,fb_row,fb_col)) >= COLNO) - right_shadow = COLNO-1; + if ((right_shadow = far_shadow(FROM_RIGHT, row, fb_row, fb_col)) >= COLNO) + right_shadow = COLNO - 1; /* * Make vertical walls work the way we want them. In this case, we * note when the close block blocks the column just above/beneath @@ -1741,152 +1844,167 @@ right_side(row, cb_row, cb_col, fb_row, fb_col, left, right_mark, limits) * right shadow back (same as fb_col). */ if (right_shadow < fb_col && !viz_clear_rows[row][fb_col]) - right_shadow = fb_col; - if(right_shadow > lim_max) right_shadow = lim_max; + right_shadow = fb_col; + if (right_shadow > lim_max) + right_shadow = lim_max; /* * Main loop. Within the range of sight of the previous row, mark all * stone walls as seen. Follow open areas recursively. */ while (left <= right_mark) { - /* Get the far right of the opening or wall */ - loc_right = right_ptrs[row][left]; - if(loc_right > lim_max) loc_right = lim_max; + /* Get the far right of the opening or wall */ + loc_right = right_ptrs[row][left]; + if (loc_right > lim_max) + loc_right = lim_max; - if (!viz_clear_rows[row][left]) { - hit_stone = 1; /* use stone on this row as close block */ - /* - * We can see all of the wall until the next open spot or the - * start of the shadow caused by the far block (right). - * - * Can't see stone beyond the right mark. - */ - if (loc_right > right_mark) loc_right = right_mark; + if (!viz_clear_rows[row][left]) { + hit_stone = 1; /* use stone on this row as close block */ + /* + * We can see all of the wall until the next open spot or the + * start of the shadow caused by the far block (right). + * + * Can't see stone beyond the right mark. + */ + if (loc_right > right_mark) + loc_right = right_mark; - if(vis_func) { - for (i = left; i <= loc_right; i++) (*vis_func)(i, row, varg); - } else { - for (i = left; i <= loc_right; i++) set_cs(rowp,i); - set_min(left); set_max(loc_right); - } + if (vis_func) { + for (i = left; i <= loc_right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left; i <= loc_right; i++) + set_cs(rowp, i); + set_min(left); + set_max(loc_right); + } - if (loc_right == right_mark) return; /* hit the end */ - left = loc_right + 1; - loc_right = right_ptrs[row][left]; - if(loc_right > lim_max) loc_right = lim_max; - /* fall through... we know at least one position is visible */ - } + if (loc_right == right_mark) + return; /* hit the end */ + left = loc_right + 1; + loc_right = right_ptrs[row][left]; + if (loc_right > lim_max) + loc_right = lim_max; + /* fall through... we know at least one position is visible */ + } - /* - * We are in an opening. - * - * If this is the first open spot since the could see area (this is - * true if we have hit stone), get the shadow generated by the wall - * just to our left. - */ - if (hit_stone) { - lblock_col = left-1; /* local block column */ - left = close_shadow(FROM_RIGHT,row,row,lblock_col); - if (left > lim_max) break; /* off the end */ - } + /* + * We are in an opening. + * + * If this is the first open spot since the could see area (this is + * true if we have hit stone), get the shadow generated by the wall + * just to our left. + */ + if (hit_stone) { + lblock_col = left - 1; /* local block column */ + left = close_shadow(FROM_RIGHT, row, row, lblock_col); + if (left > lim_max) + break; /* off the end */ + } - /* - * Check if the shadow covers the opening. If it does, then - * move to end of the opening. A shadow generated on from a - * wall on this row does *not* cover the wall on the right - * of the opening. - */ - if (left >= loc_right) { - if (loc_right == lim_max) { /* boundary */ - if (left == lim_max) { - if(vis_func) (*vis_func)(lim_max, row, varg); - else { - set_cs(rowp,lim_max); /* last pos */ - set_max(lim_max); - } - } - return; /* done */ - } - left = loc_right; - continue; - } + /* + * Check if the shadow covers the opening. If it does, then + * move to end of the opening. A shadow generated on from a + * wall on this row does *not* cover the wall on the right + * of the opening. + */ + if (left >= loc_right) { + if (loc_right == lim_max) { /* boundary */ + if (left == lim_max) { + if (vis_func) + (*vis_func)(lim_max, row, varg); + else { + set_cs(rowp, lim_max); /* last pos */ + set_max(lim_max); + } + } + return; /* done */ + } + left = loc_right; + continue; + } - /* - * If the far wall of the opening (loc_right) is closer than the - * shadow limit imposed by the far block (right) then use the far - * wall as our new far block when we recurse. - * - * If the limits are the the same, and the far block really exists - * (fb_row >= 0) then do the same as above. - * - * Normally, the check would be for the far wall being closer OR EQUAL - * to the shadow limit. However, there is a bug that arises from the - * fact that the clear area pointers end in an open space (if it - * exists) on a boundary. This then makes a far block exist where it - * shouldn't --- on a boundary. To get around that, I had to - * introduce the concept of a non-existent far block (when the - * row < 0). Next I have to check for it. Here is where that check - * exists. - */ - if ((loc_right < right_shadow) || - (fb_row >= 0 && loc_right == right_shadow)) { - if(vis_func) { - for (i = left; i <= loc_right; i++) (*vis_func)(i, row, varg); - } else { - for (i = left; i <= loc_right; i++) set_cs(rowp,i); - set_min(left); set_max(loc_right); - } + /* + * If the far wall of the opening (loc_right) is closer than the + * shadow limit imposed by the far block (right) then use the far + * wall as our new far block when we recurse. + * + * If the limits are the the same, and the far block really exists + * (fb_row >= 0) then do the same as above. + * + * Normally, the check would be for the far wall being closer OR EQUAL + * to the shadow limit. However, there is a bug that arises from the + * fact that the clear area pointers end in an open space (if it + * exists) on a boundary. This then makes a far block exist where it + * shouldn't --- on a boundary. To get around that, I had to + * introduce the concept of a non-existent far block (when the + * row < 0). Next I have to check for it. Here is where that check + * exists. + */ + if ((loc_right < right_shadow) + || (fb_row >= 0 && loc_right == right_shadow)) { + if (vis_func) { + for (i = left; i <= loc_right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left; i <= loc_right; i++) + set_cs(rowp, i); + set_min(left); + set_max(loc_right); + } - if (deeper) { - if (hit_stone) - right_side(nrow,row,lblock_col,row,loc_right, - left,loc_right,limits); - else - right_side(nrow,cb_row,cb_col,row,loc_right, - left,loc_right,limits); - } + if (deeper) { + if (hit_stone) + right_side(nrow, row, lblock_col, row, loc_right, left, + loc_right, limits); + else + right_side(nrow, cb_row, cb_col, row, loc_right, left, + loc_right, limits); + } - /* - * The following line, setting hit_stone, is needed for those - * walls that are only 1 wide. If hit stone is *not* set and - * the stone is only one wide, then the close block is the old - * one instead one on the current row. A way around having to - * set it here is to make left = loc_right (not loc_right+1) and - * let the outer loop take care of it. However, if we do that - * then we then have to check for boundary conditions here as - * well. - */ - hit_stone = 1; + /* + * The following line, setting hit_stone, is needed for those + * walls that are only 1 wide. If hit stone is *not* set and + * the stone is only one wide, then the close block is the old + * one instead one on the current row. A way around having to + * set it here is to make left = loc_right (not loc_right+1) and + * let the outer loop take care of it. However, if we do that + * then we then have to check for boundary conditions here as + * well. + */ + hit_stone = 1; - left = loc_right+1; - } - /* - * The opening extends beyond the right mark. This means that - * the next far block is the current far block. - */ - else { - if(vis_func) { - for (i=left; i <= right_shadow; i++) (*vis_func)(i, row, varg); - } else { - for (i = left; i <= right_shadow; i++) set_cs(rowp,i); - set_min(left); set_max(right_shadow); - } + left = loc_right + 1; + } + /* + * The opening extends beyond the right mark. This means that + * the next far block is the current far block. + */ + else { + if (vis_func) { + for (i = left; i <= right_shadow; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left; i <= right_shadow; i++) + set_cs(rowp, i); + set_min(left); + set_max(right_shadow); + } - if (deeper) { - if (hit_stone) - right_side(nrow, row,lblock_col,fb_row,fb_col, - left,right_shadow,limits); - else - right_side(nrow,cb_row, cb_col,fb_row,fb_col, - left,right_shadow,limits); - } + if (deeper) { + if (hit_stone) + right_side(nrow, row, lblock_col, fb_row, fb_col, left, + right_shadow, limits); + else + right_side(nrow, cb_row, cb_col, fb_row, fb_col, left, + right_shadow, limits); + } - return; /* we're outta here */ - } + return; /* we're outta here */ + } } } - /* * left_side() * @@ -1895,171 +2013,195 @@ right_side(row, cb_row, cb_col, fb_row, fb_col, left, right_mark, limits) */ STATIC_OVL void left_side(row, cb_row, cb_col, fb_row, fb_col, left_mark, right, limits) - int row; /* the current row */ - int cb_row, cb_col; /* close block row and col */ - int fb_row, fb_col; /* far block row and col */ - int left_mark; /* left mark of previous row */ - int right; /* right mark of the previous row */ - char *limits; +int row; /* the current row */ +int cb_row, cb_col; /* close block row and col */ +int fb_row, fb_col; /* far block row and col */ +int left_mark; /* left mark of previous row */ +int right; /* right mark of the previous row */ +char *limits; { - register int i; + register int i; register char *rowp = NULL; - int hit_stone = 0; - int left_shadow, right_shadow, loc_left; - int lblock_col; /* local block column (current row) */ - int nrow, deeper; - char *row_min = NULL; /* left most */ - char *row_max = NULL; /* right most */ - int lim_min; + int hit_stone = 0; + int left_shadow, right_shadow, loc_left; + int lblock_col; /* local block column (current row) */ + int nrow, deeper; + char *row_min = NULL; /* left most */ + char *row_max = NULL; /* right most */ + int lim_min; - nrow = row + step; - deeper = good_row(nrow) && (!limits || (*limits >= *(limits+1))); - if(!vis_func) { - rowp = cs_rows[row]; - row_min = &cs_left[row]; - row_max = &cs_right[row]; + nrow = row + step; + deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1))); + if (!vis_func) { + rowp = cs_rows[row]; + row_min = &cs_left[row]; + row_max = &cs_right[row]; } - if(limits) { - lim_min = start_col - *limits; - if(lim_min < 0) lim_min = 0; - if(left_mark < lim_min) left_mark = lim_min; - limits++; /* prepare for next row */ + if (limits) { + lim_min = start_col - *limits; + if (lim_min < 0) + lim_min = 0; + if (left_mark < lim_min) + left_mark = lim_min; + limits++; /* prepare for next row */ } else - lim_min = 0; + lim_min = 0; /* This value could be illegal. */ - right_shadow = close_shadow(FROM_LEFT,row,cb_row,cb_col); + right_shadow = close_shadow(FROM_LEFT, row, cb_row, cb_col); - while ( right >= left_mark ) { - loc_left = left_ptrs[row][right]; - if(loc_left < lim_min) loc_left = lim_min; - if (viz_clear_rows[row][right]) { - if (loc_left <= right_shadow) { - right = right_shadow; /* opening ends beyond shadow */ - break; - } - right = loc_left; - loc_left = left_ptrs[row][right]; - if(loc_left < lim_min) loc_left = lim_min; - if (right == loc_left) return; /* boundary */ - } + while (right >= left_mark) { + loc_left = left_ptrs[row][right]; + if (loc_left < lim_min) + loc_left = lim_min; + if (viz_clear_rows[row][right]) { + if (loc_left <= right_shadow) { + right = right_shadow; /* opening ends beyond shadow */ + break; + } + right = loc_left; + loc_left = left_ptrs[row][right]; + if (loc_left < lim_min) + loc_left = lim_min; + if (right == loc_left) + return; /* boundary */ + } - if (loc_left < left_mark) /* can't see beyond the left mark */ - loc_left = left_mark; + if (loc_left < left_mark) /* can't see beyond the left mark */ + loc_left = left_mark; - if(vis_func) { - for (i = loc_left; i <= right; i++) (*vis_func)(i, row, varg); - } else { - for (i = loc_left; i <= right; i++) set_cs(rowp,i); - set_min(loc_left); set_max(right); - } + if (vis_func) { + for (i = loc_left; i <= right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = loc_left; i <= right; i++) + set_cs(rowp, i); + set_min(loc_left); + set_max(right); + } - if (loc_left == left_mark) return; /* all stone */ - if (loc_left <= right_shadow) hit_stone = 1; - right = loc_left - 1; + if (loc_left == left_mark) + return; /* all stone */ + if (loc_left <= right_shadow) + hit_stone = 1; + right = loc_left - 1; } /* At first visible clear spot on or beyond the right shadow. */ - if ((left_shadow = far_shadow(FROM_LEFT,row,fb_row,fb_col)) < 0) - left_shadow = 0; + if ((left_shadow = far_shadow(FROM_LEFT, row, fb_row, fb_col)) < 0) + left_shadow = 0; /* Do vertical walls as we want. */ if (left_shadow > fb_col && !viz_clear_rows[row][fb_col]) - left_shadow = fb_col; - if(left_shadow < lim_min) left_shadow = lim_min; + left_shadow = fb_col; + if (left_shadow < lim_min) + left_shadow = lim_min; while (right >= left_mark) { - loc_left = left_ptrs[row][right]; + loc_left = left_ptrs[row][right]; - if (!viz_clear_rows[row][right]) { - hit_stone = 1; /* use stone on this row as close block */ + if (!viz_clear_rows[row][right]) { + hit_stone = 1; /* use stone on this row as close block */ - /* We can only see walls until the left mark */ - if (loc_left < left_mark) loc_left = left_mark; + /* We can only see walls until the left mark */ + if (loc_left < left_mark) + loc_left = left_mark; - if(vis_func) { - for (i = loc_left; i <= right; i++) (*vis_func)(i, row, varg); - } else { - for (i = loc_left; i <= right; i++) set_cs(rowp,i); - set_min(loc_left); set_max(right); - } + if (vis_func) { + for (i = loc_left; i <= right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = loc_left; i <= right; i++) + set_cs(rowp, i); + set_min(loc_left); + set_max(right); + } - if (loc_left == left_mark) return; /* hit end */ - right = loc_left - 1; - loc_left = left_ptrs[row][right]; - if (loc_left < lim_min) loc_left = lim_min; - /* fall through...*/ - } + if (loc_left == left_mark) + return; /* hit end */ + right = loc_left - 1; + loc_left = left_ptrs[row][right]; + if (loc_left < lim_min) + loc_left = lim_min; + /* fall through...*/ + } - /* We are in an opening. */ - if (hit_stone) { - lblock_col = right+1; /* stone block (local) */ - right = close_shadow(FROM_LEFT,row,row,lblock_col); - if (right < lim_min) return; /* off the end */ - } + /* We are in an opening. */ + if (hit_stone) { + lblock_col = right + 1; /* stone block (local) */ + right = close_shadow(FROM_LEFT, row, row, lblock_col); + if (right < lim_min) + return; /* off the end */ + } - /* Check if the shadow covers the opening. */ - if (right <= loc_left) { - /* Make a boundary condition work. */ - if (loc_left == lim_min) { /* at boundary */ - if (right == lim_min) { - if(vis_func) (*vis_func)(lim_min, row, varg); - else { - set_cs(rowp,lim_min); /* caught the last pos */ - set_min(lim_min); - } - } - return; /* and break out the loop */ - } + /* Check if the shadow covers the opening. */ + if (right <= loc_left) { + /* Make a boundary condition work. */ + if (loc_left == lim_min) { /* at boundary */ + if (right == lim_min) { + if (vis_func) + (*vis_func)(lim_min, row, varg); + else { + set_cs(rowp, lim_min); /* caught the last pos */ + set_min(lim_min); + } + } + return; /* and break out the loop */ + } - right = loc_left; - continue; - } + right = loc_left; + continue; + } - /* If the far wall of the opening is closer than the shadow limit. */ - if ((loc_left > left_shadow) || - (fb_row >= 0 && loc_left == left_shadow)) { - if(vis_func) { - for (i = loc_left; i <= right; i++) (*vis_func)(i, row, varg); - } else { - for (i = loc_left; i <= right; i++) set_cs(rowp,i); - set_min(loc_left); set_max(right); - } + /* If the far wall of the opening is closer than the shadow limit. */ + if ((loc_left > left_shadow) + || (fb_row >= 0 && loc_left == left_shadow)) { + if (vis_func) { + for (i = loc_left; i <= right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = loc_left; i <= right; i++) + set_cs(rowp, i); + set_min(loc_left); + set_max(right); + } - if (deeper) { - if (hit_stone) - left_side(nrow,row,lblock_col,row,loc_left, - loc_left,right,limits); - else - left_side(nrow,cb_row,cb_col,row,loc_left, - loc_left,right,limits); - } + if (deeper) { + if (hit_stone) + left_side(nrow, row, lblock_col, row, loc_left, loc_left, + right, limits); + else + left_side(nrow, cb_row, cb_col, row, loc_left, loc_left, + right, limits); + } - hit_stone = 1; /* needed for walls of width 1 */ - right = loc_left-1; - } - /* The opening extends beyond the left mark. */ - else { - if(vis_func) { - for (i=left_shadow; i <= right; i++) (*vis_func)(i, row, varg); - } else { - for (i = left_shadow; i <= right; i++) set_cs(rowp,i); - set_min(left_shadow); set_max(right); - } + hit_stone = 1; /* needed for walls of width 1 */ + right = loc_left - 1; + } + /* The opening extends beyond the left mark. */ + else { + if (vis_func) { + for (i = left_shadow; i <= right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left_shadow; i <= right; i++) + set_cs(rowp, i); + set_min(left_shadow); + set_max(right); + } - if (deeper) { - if (hit_stone) - left_side(nrow,row,lblock_col,fb_row,fb_col, - left_shadow,right,limits); - else - left_side(nrow,cb_row,cb_col,fb_row,fb_col, - left_shadow,right,limits); - } - - return; /* we're outta here */ - } + if (deeper) { + if (hit_stone) + left_side(nrow, row, lblock_col, fb_row, fb_col, + left_shadow, right, limits); + else + left_side(nrow, cb_row, cb_col, fb_row, fb_col, + left_shadow, right, limits); + } + return; /* we're outta here */ + } } } @@ -2072,98 +2214,103 @@ left_side(row, cb_row, cb_col, fb_row, fb_col, left_mark, right, limits) * and right most boundaries of what could be seen. */ STATIC_OVL void -view_from(srow,scol,loc_cs_rows,left_most,right_most, range, func, arg) - int srow, scol; /* source row and column */ - char **loc_cs_rows; /* could_see array (row pointers) */ - char *left_most, *right_most; /* limits of what could be seen */ - int range; /* 0 if unlimited */ - void FDECL((*func), (int,int,genericptr_t)); - genericptr_t arg; +view_from(srow, scol, loc_cs_rows, left_most, right_most, range, func, arg) +int srow, scol; /* source row and column */ +char **loc_cs_rows; /* could_see array (row pointers) */ +char *left_most, *right_most; /* limits of what could be seen */ +int range; /* 0 if unlimited */ +void FDECL((*func), (int, int, genericptr_t)); +genericptr_t arg; { register int i; - char *rowp; - int nrow, left, right, left_row, right_row; - char *limits; + char *rowp; + int nrow, left, right, left_row, right_row; + char *limits; /* Set globals for near_shadow(), far_shadow(), etc. to use. */ start_col = scol; start_row = srow; - cs_rows = loc_cs_rows; - cs_left = left_most; - cs_right = right_most; + cs_rows = loc_cs_rows; + cs_left = left_most; + cs_right = right_most; vis_func = func; varg = arg; /* Find the left and right limits of sight on the starting row. */ if (viz_clear_rows[srow][scol]) { - left = left_ptrs[srow][scol]; - right = right_ptrs[srow][scol]; + left = left_ptrs[srow][scol]; + right = right_ptrs[srow][scol]; } else { - left = (!scol) ? 0 : - (viz_clear_rows[srow][scol-1] ? left_ptrs[srow][scol-1] : scol-1); - right = (scol == COLNO-1) ? COLNO-1 : - (viz_clear_rows[srow][scol+1] ? right_ptrs[srow][scol+1] : scol+1); + left = (!scol) ? 0 : (viz_clear_rows[srow][scol - 1] + ? left_ptrs[srow][scol - 1] + : scol - 1); + right = (scol == COLNO - 1) ? COLNO - 1 + : (viz_clear_rows[srow][scol + 1] + ? right_ptrs[srow][scol + 1] + : scol + 1); } - if(range) { - if(range > MAX_RADIUS || range < 1) - panic("view_from called with range %d", range); - limits = circle_ptr(range) + 1; /* start at next row */ - if(left < scol - range) left = scol - range; - if(right > scol + range) right = scol + range; + if (range) { + if (range > MAX_RADIUS || range < 1) + panic("view_from called with range %d", range); + limits = circle_ptr(range) + 1; /* start at next row */ + if (left < scol - range) + left = scol - range; + if (right > scol + range) + right = scol + range; } else - limits = (char*) 0; + limits = (char *) 0; - if(func) { - for (i = left; i <= right; i++) (*func)(i, srow, arg); + if (func) { + for (i = left; i <= right; i++) + (*func)(i, srow, arg); } else { - /* Row optimization */ - rowp = cs_rows[srow]; + /* Row optimization */ + rowp = cs_rows[srow]; - /* We know that we can see our row. */ - for (i = left; i <= right; i++) set_cs(rowp,i); - cs_left[srow] = left; - cs_right[srow] = right; + /* We know that we can see our row. */ + for (i = left; i <= right; i++) + set_cs(rowp, i); + cs_left[srow] = left; + cs_right[srow] = right; } /* The far block has a row number of -1 if we are on an edge. */ - right_row = (right == COLNO-1) ? -1 : srow; - left_row = (!left) ? -1 : srow; + right_row = (right == COLNO - 1) ? -1 : srow; + left_row = (!left) ? -1 : srow; /* * Check what could be seen in quadrants. */ - if ( (nrow = srow+1) < ROWNO ) { - step = 1; /* move down */ - if (scol= 0 ) { - step = -1; /* move up */ - if (scol= 0) { + step = -1; /* move up */ + if (scol < COLNO - 1) + right_side(nrow, -1, scol, right_row, right, scol, right, limits); + if (scol) + left_side(nrow, -1, scol, left_row, left, left, scol, limits); } } - -#else /*===== End of algorithm D =====*/ - +#else /*===== End of algorithm D =====*/ /*===========================================================================*\ - GENERAL LINE OF SIGHT - Algorithm C + GENERAL LINE OF SIGHT + Algorithm C \*===========================================================================*/ /* * Defines local to Algorithm C. */ -STATIC_DCL void FDECL(right_side, (int,int,int,char*)); -STATIC_DCL void FDECL(left_side, (int,int,int,char*)); +STATIC_DCL void FDECL(right_side, (int, int, int, char *)); +STATIC_DCL void FDECL(left_side, (int, int, int, char *)); /* Initialize algorithm C (nothing). */ STATIC_OVL void @@ -2177,187 +2324,200 @@ view_init() */ STATIC_OVL void right_side(row, left, right_mark, limits) - int row; /* current row */ - int left; /* first (left side) visible spot on prev row */ - int right_mark; /* last (right side) visible spot on prev row */ - char *limits; /* points at range limit for current row, or NULL */ +int row; /* current row */ +int left; /* first (left side) visible spot on prev row */ +int right_mark; /* last (right side) visible spot on prev row */ +char *limits; /* points at range limit for current row, or NULL */ { - int right; /* right limit of "could see" */ - int right_edge; /* right edge of an opening */ - int nrow; /* new row (calculate once) */ - int deeper; /* if TRUE, call self as needed */ - int result; /* set by q?_path() */ - register int i; /* loop counter */ - register char *rowp = NULL; /* row optimization */ - char *row_min = NULL; /* left most [used by macro set_min()] */ - char *row_max = NULL; /* right most [used by macro set_max()] */ - int lim_max; /* right most limit of circle */ + int right; /* right limit of "could see" */ + int right_edge; /* right edge of an opening */ + int nrow; /* new row (calculate once) */ + int deeper; /* if TRUE, call self as needed */ + int result; /* set by q?_path() */ + register int i; /* loop counter */ + register char *rowp = NULL; /* row optimization */ + char *row_min = NULL; /* left most [used by macro set_min()] */ + char *row_max = NULL; /* right most [used by macro set_max()] */ + int lim_max; /* right most limit of circle */ - nrow = row + step; + nrow = row + step; /* * Can go deeper if the row is in bounds and the next row is within * the circle's limit. We tell the latter by checking to see if the next * limit value is the start of a new circle radius (meaning we depend * on the structure of circle_data[]). */ - deeper = good_row(nrow) && (!limits || (*limits >= *(limits+1))); - if(!vis_func) { - rowp = cs_rows[row]; /* optimization */ - row_min = &cs_left[row]; - row_max = &cs_right[row]; + deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1))); + if (!vis_func) { + rowp = cs_rows[row]; /* optimization */ + row_min = &cs_left[row]; + row_max = &cs_right[row]; } - if(limits) { - lim_max = start_col + *limits; - if(lim_max > COLNO-1) lim_max = COLNO-1; - if(right_mark > lim_max) right_mark = lim_max; - limits++; /* prepare for next row */ + if (limits) { + lim_max = start_col + *limits; + if (lim_max > COLNO - 1) + lim_max = COLNO - 1; + if (right_mark > lim_max) + right_mark = lim_max; + limits++; /* prepare for next row */ } else - lim_max = COLNO-1; + lim_max = COLNO - 1; while (left <= right_mark) { - right_edge = right_ptrs[row][left]; - if(right_edge > lim_max) right_edge = lim_max; + right_edge = right_ptrs[row][left]; + if (right_edge > lim_max) + right_edge = lim_max; - if (!is_clear(row,left)) { - /* - * Jump to the far side of a stone wall. We can set all - * the points in between as seen. - * - * If the right edge goes beyond the right mark, check to see - * how much we can see. - */ - if (right_edge > right_mark) { - /* - * If the mark on the previous row was a clear position, - * the odds are that we can actually see part of the wall - * beyond the mark on this row. If so, then see one beyond - * the mark. Otherwise don't. This is a kludge so corners - * with an adjacent doorway show up in nethack. - */ - right_edge = is_clear(row-step,right_mark) ? - right_mark+1 : right_mark; - } - if(vis_func) { - for (i = left; i <= right_edge; i++) (*vis_func)(i, row, varg); - } else { - for (i = left; i <= right_edge; i++) set_cs(rowp,i); - set_min(left); set_max(right_edge); - } - left = right_edge + 1; /* no limit check necessary */ - continue; - } + if (!is_clear(row, left)) { + /* + * Jump to the far side of a stone wall. We can set all + * the points in between as seen. + * + * If the right edge goes beyond the right mark, check to see + * how much we can see. + */ + if (right_edge > right_mark) { + /* + * If the mark on the previous row was a clear position, + * the odds are that we can actually see part of the wall + * beyond the mark on this row. If so, then see one beyond + * the mark. Otherwise don't. This is a kludge so corners + * with an adjacent doorway show up in nethack. + */ + right_edge = is_clear(row - step, right_mark) ? right_mark + 1 + : right_mark; + } + if (vis_func) { + for (i = left; i <= right_edge; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left; i <= right_edge; i++) + set_cs(rowp, i); + set_min(left); + set_max(right_edge); + } + left = right_edge + 1; /* no limit check necessary */ + continue; + } - /* No checking needed if our left side is the start column. */ - if (left != start_col) { - /* - * Find the left side. Move right until we can see it or we run - * into a wall. - */ - for (; left <= right_edge; left++) { - if (step < 0) { - q1_path(start_row,start_col,row,left,rside1); - } else { - q4_path(start_row,start_col,row,left,rside1); - } -rside1: /* used if q?_path() is a macro */ - if (result) break; - } + /* No checking needed if our left side is the start column. */ + if (left != start_col) { + /* + * Find the left side. Move right until we can see it or we run + * into a wall. + */ + for (; left <= right_edge; left++) { + if (step < 0) { + q1_path(start_row, start_col, row, left, rside1); + } else { + q4_path(start_row, start_col, row, left, rside1); + } + rside1: /* used if q?_path() is a macro */ + if (result) + break; + } - /* - * Check for boundary conditions. We *need* check (2) to break - * an infinite loop where: - * - * left == right_edge == right_mark == lim_max. - * - */ - if (left > lim_max) return; /* check (1) */ - if (left == lim_max) { /* check (2) */ - if(vis_func) (*vis_func)(lim_max, row, varg); - else { - set_cs(rowp,lim_max); - set_max(lim_max); - } - return; - } - /* - * Check if we can see any spots in the opening. We might - * (left == right_edge) or might not (left == right_edge+1) have - * been able to see the far wall. Make sure we *can* see the - * wall (remember, we can see the spot above/below this one) - * by backing up. - */ - if (left >= right_edge) { - left = right_edge; /* for the case left == right_edge+1 */ - continue; - } - } + /* + * Check for boundary conditions. We *need* check (2) to break + * an infinite loop where: + * + * left == right_edge == right_mark == lim_max. + * + */ + if (left > lim_max) + return; /* check (1) */ + if (left == lim_max) { /* check (2) */ + if (vis_func) + (*vis_func)(lim_max, row, varg); + else { + set_cs(rowp, lim_max); + set_max(lim_max); + } + return; + } + /* + * Check if we can see any spots in the opening. We might + * (left == right_edge) or might not (left == right_edge+1) have + * been able to see the far wall. Make sure we *can* see the + * wall (remember, we can see the spot above/below this one) + * by backing up. + */ + if (left >= right_edge) { + left = right_edge; /* for the case left == right_edge+1 */ + continue; + } + } - /* - * Find the right side. If the marker from the previous row is - * closer than the edge on this row, then we have to check - * how far we can see around the corner (under the overhang). Stop - * at the first non-visible spot or we actually hit the far wall. - * - * Otherwise, we know we can see the right edge of the current row. - * - * This must be a strict less than so that we can always see a - * horizontal wall, even if it is adjacent to us. - */ - if (right_mark < right_edge) { - for (right = right_mark; right <= right_edge; right++) { - if (step < 0) { - q1_path(start_row,start_col,row,right,rside2); - } else { - q4_path(start_row,start_col,row,right,rside2); - } -rside2: /* used if q?_path() is a macro */ - if (!result) break; - } - --right; /* get rid of the last increment */ - } - else - right = right_edge; + /* + * Find the right side. If the marker from the previous row is + * closer than the edge on this row, then we have to check + * how far we can see around the corner (under the overhang). Stop + * at the first non-visible spot or we actually hit the far wall. + * + * Otherwise, we know we can see the right edge of the current row. + * + * This must be a strict less than so that we can always see a + * horizontal wall, even if it is adjacent to us. + */ + if (right_mark < right_edge) { + for (right = right_mark; right <= right_edge; right++) { + if (step < 0) { + q1_path(start_row, start_col, row, right, rside2); + } else { + q4_path(start_row, start_col, row, right, rside2); + } + rside2: /* used if q?_path() is a macro */ + if (!result) + break; + } + --right; /* get rid of the last increment */ + } else + right = right_edge; - /* - * We have the range that we want. Set the bits. Note that - * there is no else --- we no longer handle splinters. - */ - if (left <= right) { - /* - * An ugly special case. If you are adjacent to a vertical wall - * and it has a break in it, then the right mark is set to be - * start_col. We *want* to be able to see adjacent vertical - * walls, so we have to set it back. - */ - if (left == right && left == start_col && - start_col < (COLNO-1) && !is_clear(row,start_col+1)) - right = start_col+1; + /* + * We have the range that we want. Set the bits. Note that + * there is no else --- we no longer handle splinters. + */ + if (left <= right) { + /* + * An ugly special case. If you are adjacent to a vertical wall + * and it has a break in it, then the right mark is set to be + * start_col. We *want* to be able to see adjacent vertical + * walls, so we have to set it back. + */ + if (left == right && left == start_col && start_col < (COLNO - 1) + && !is_clear(row, start_col + 1)) + right = start_col + 1; - if(right > lim_max) right = lim_max; - /* set the bits */ - if(vis_func) - for (i = left; i <= right; i++) (*vis_func)(i, row, varg); - else { - for (i = left; i <= right; i++) set_cs(rowp,i); - set_min(left); set_max(right); - } + if (right > lim_max) + right = lim_max; + /* set the bits */ + if (vis_func) + for (i = left; i <= right; i++) + (*vis_func)(i, row, varg); + else { + for (i = left; i <= right; i++) + set_cs(rowp, i); + set_min(left); + set_max(right); + } - /* recursive call for next finger of light */ - if (deeper) right_side(nrow,left,right,limits); - left = right + 1; /* no limit check necessary */ - } + /* recursive call for next finger of light */ + if (deeper) + right_side(nrow, left, right, limits); + left = right + 1; /* no limit check necessary */ + } } } - /* * This routine is the mirror image of right_side(). See right_side() for * extensive comments. */ STATIC_OVL void left_side(row, left_mark, right, limits) - int row, left_mark, right; - char *limits; +int row, left_mark, right; +char *limits; { int left, left_edge, nrow, deeper, result; register int i; @@ -2369,109 +2529,122 @@ left_side(row, left_mark, right, limits) #ifdef GCC_WARN rowp = row_min = row_max = 0; #endif - nrow = row+step; - deeper = good_row(nrow) && (!limits || (*limits >= *(limits+1))); - if(!vis_func) { - rowp = cs_rows[row]; - row_min = &cs_left[row]; - row_max = &cs_right[row]; + nrow = row + step; + deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1))); + if (!vis_func) { + rowp = cs_rows[row]; + row_min = &cs_left[row]; + row_max = &cs_right[row]; } - if(limits) { - lim_min = start_col - *limits; - if(lim_min < 0) lim_min = 0; - if(left_mark < lim_min) left_mark = lim_min; - limits++; /* prepare for next row */ + if (limits) { + lim_min = start_col - *limits; + if (lim_min < 0) + lim_min = 0; + if (left_mark < lim_min) + left_mark = lim_min; + limits++; /* prepare for next row */ } else - lim_min = 0; + lim_min = 0; while (right >= left_mark) { - left_edge = left_ptrs[row][right]; - if(left_edge < lim_min) left_edge = lim_min; + left_edge = left_ptrs[row][right]; + if (left_edge < lim_min) + left_edge = lim_min; - if (!is_clear(row,right)) { - /* Jump to the far side of a stone wall. */ - if (left_edge < left_mark) { - /* Maybe see more (kludge). */ - left_edge = is_clear(row-step,left_mark) ? - left_mark-1 : left_mark; - } - if(vis_func) { - for (i = left_edge; i <= right; i++) (*vis_func)(i, row, varg); - } else { - for (i = left_edge; i <= right; i++) set_cs(rowp,i); - set_min(left_edge); set_max(right); - } - right = left_edge - 1; /* no limit check necessary */ - continue; - } + if (!is_clear(row, right)) { + /* Jump to the far side of a stone wall. */ + if (left_edge < left_mark) { + /* Maybe see more (kludge). */ + left_edge = is_clear(row - step, left_mark) ? left_mark - 1 + : left_mark; + } + if (vis_func) { + for (i = left_edge; i <= right; i++) + (*vis_func)(i, row, varg); + } else { + for (i = left_edge; i <= right; i++) + set_cs(rowp, i); + set_min(left_edge); + set_max(right); + } + right = left_edge - 1; /* no limit check necessary */ + continue; + } - if (right != start_col) { - /* Find the right side. */ - for (; right >= left_edge; right--) { - if (step < 0) { - q2_path(start_row,start_col,row,right,lside1); - } else { - q3_path(start_row,start_col,row,right,lside1); - } -lside1: /* used if q?_path() is a macro */ - if (result) break; - } + if (right != start_col) { + /* Find the right side. */ + for (; right >= left_edge; right--) { + if (step < 0) { + q2_path(start_row, start_col, row, right, lside1); + } else { + q3_path(start_row, start_col, row, right, lside1); + } + lside1: /* used if q?_path() is a macro */ + if (result) + break; + } - /* Check for boundary conditions. */ - if (right < lim_min) return; - if (right == lim_min) { - if(vis_func) (*vis_func)(lim_min, row, varg); - else { - set_cs(rowp,lim_min); - set_min(lim_min); - } - return; - } - /* Check if we can see any spots in the opening. */ - if (right <= left_edge) { - right = left_edge; - continue; - } - } + /* Check for boundary conditions. */ + if (right < lim_min) + return; + if (right == lim_min) { + if (vis_func) + (*vis_func)(lim_min, row, varg); + else { + set_cs(rowp, lim_min); + set_min(lim_min); + } + return; + } + /* Check if we can see any spots in the opening. */ + if (right <= left_edge) { + right = left_edge; + continue; + } + } - /* Find the left side. */ - if (left_mark > left_edge) { - for (left = left_mark; left >= left_edge; --left) { - if (step < 0) { - q2_path(start_row,start_col,row,left,lside2); - } else { - q3_path(start_row,start_col,row,left,lside2); - } -lside2: /* used if q?_path() is a macro */ - if (!result) break; - } - left++; /* get rid of the last decrement */ - } - else - left = left_edge; + /* Find the left side. */ + if (left_mark > left_edge) { + for (left = left_mark; left >= left_edge; --left) { + if (step < 0) { + q2_path(start_row, start_col, row, left, lside2); + } else { + q3_path(start_row, start_col, row, left, lside2); + } + lside2: /* used if q?_path() is a macro */ + if (!result) + break; + } + left++; /* get rid of the last decrement */ + } else + left = left_edge; - if (left <= right) { - /* An ugly special case. */ - if (left == right && right == start_col && - start_col > 0 && !is_clear(row,start_col-1)) - left = start_col-1; + if (left <= right) { + /* An ugly special case. */ + if (left == right && right == start_col && start_col > 0 + && !is_clear(row, start_col - 1)) + left = start_col - 1; - if(left < lim_min) left = lim_min; - if(vis_func) - for (i = left; i <= right; i++) (*vis_func)(i, row, varg); - else { - for (i = left; i <= right; i++) set_cs(rowp,i); - set_min(left); set_max(right); - } + if (left < lim_min) + left = lim_min; + if (vis_func) + for (i = left; i <= right; i++) + (*vis_func)(i, row, varg); + else { + for (i = left; i <= right; i++) + set_cs(rowp, i); + set_min(left); + set_max(right); + } - /* Recurse */ - if (deeper) left_side(nrow,left,right,limits); - right = left - 1; /* no limit check necessary */ - } + /* Recurse */ + if (deeper) + left_side(nrow, left, right, limits); + right = left - 1; /* no limit check necessary */ + } } } - /* * Calculate all possible visible locations from the given location * (srow,scol). NOTE this is (y,x)! Mark the visible locations in the @@ -2479,66 +2652,73 @@ lside2: /* used if q?_path() is a macro */ */ STATIC_OVL void view_from(srow, scol, loc_cs_rows, left_most, right_most, range, func, arg) - int srow, scol; /* starting row and column */ - char **loc_cs_rows; /* pointers to the rows of the could_see array */ - char *left_most; /* min mark on each row */ - char *right_most; /* max mark on each row */ - int range; /* 0 if unlimited */ - void FDECL((*func), (int,int,genericptr_t)); - genericptr_t arg; +int srow, scol; /* starting row and column */ +char **loc_cs_rows; /* pointers to the rows of the could_see array */ +char *left_most; /* min mark on each row */ +char *right_most; /* max mark on each row */ +int range; /* 0 if unlimited */ +void FDECL((*func), (int, int, genericptr_t)); +genericptr_t arg; { - register int i; /* loop counter */ - char *rowp; /* optimization for setting could_see */ - int nrow; /* the next row */ - int left; /* the left-most visible column */ - int right; /* the right-most visible column */ - char *limits; /* range limit for next row */ + register int i; /* loop counter */ + char *rowp; /* optimization for setting could_see */ + int nrow; /* the next row */ + int left; /* the left-most visible column */ + int right; /* the right-most visible column */ + char *limits; /* range limit for next row */ /* Set globals for q?_path(), left_side(), and right_side() to use. */ start_col = scol; start_row = srow; - cs_rows = loc_cs_rows; /* 'could see' rows */ - cs_left = left_most; - cs_right = right_most; + cs_rows = loc_cs_rows; /* 'could see' rows */ + cs_left = left_most; + cs_right = right_most; vis_func = func; varg = arg; /* * Determine extent of sight on the starting row. */ - if (is_clear(srow,scol)) { - left = left_ptrs[srow][scol]; - right = right_ptrs[srow][scol]; + if (is_clear(srow, scol)) { + left = left_ptrs[srow][scol]; + right = right_ptrs[srow][scol]; } else { - /* - * When in stone, you can only see your adjacent squares, unless - * you are on an array boundary or a stone/clear boundary. - */ - left = (!scol) ? 0 : - (is_clear(srow,scol-1) ? left_ptrs[srow][scol-1] : scol-1); - right = (scol == COLNO-1) ? COLNO-1 : - (is_clear(srow,scol+1) ? right_ptrs[srow][scol+1] : scol+1); + /* + * When in stone, you can only see your adjacent squares, unless + * you are on an array boundary or a stone/clear boundary. + */ + left = (!scol) ? 0 + : (is_clear(srow, scol - 1) ? left_ptrs[srow][scol - 1] + : scol - 1); + right = (scol == COLNO - 1) + ? COLNO - 1 + : (is_clear(srow, scol + 1) ? right_ptrs[srow][scol + 1] + : scol + 1); } - if(range) { - if(range > MAX_RADIUS || range < 1) - panic("view_from called with range %d", range); - limits = circle_ptr(range) + 1; /* start at next row */ - if(left < scol - range) left = scol - range; - if(right > scol + range) right = scol + range; + if (range) { + if (range > MAX_RADIUS || range < 1) + panic("view_from called with range %d", range); + limits = circle_ptr(range) + 1; /* start at next row */ + if (left < scol - range) + left = scol - range; + if (right > scol + range) + right = scol + range; } else - limits = (char*) 0; + limits = (char *) 0; - if(func) { - for (i = left; i <= right; i++) (*func)(i, srow, arg); + if (func) { + for (i = left; i <= right; i++) + (*func)(i, srow, arg); } else { - /* Row pointer optimization. */ - rowp = cs_rows[srow]; + /* Row pointer optimization. */ + rowp = cs_rows[srow]; - /* We know that we can see our row. */ - for (i = left; i <= right; i++) set_cs(rowp,i); - cs_left[srow] = left; - cs_right[srow] = right; + /* We know that we can see our row. */ + for (i = left; i <= right; i++) + set_cs(rowp, i); + cs_left[srow] = left; + cs_right[srow] = right; } /* @@ -2546,20 +2726,24 @@ view_from(srow, scol, loc_cs_rows, left_most, right_most, range, func, arg) * rows here, since we don't do it in the routines right_side() and * left_side() [ugliness to remove extra routine calls]. */ - if ( (nrow = srow+1) < ROWNO ) { /* move down */ - step = 1; - if (scol < COLNO-1) right_side(nrow, scol, right, limits); - if (scol) left_side (nrow, left, scol, limits); + if ((nrow = srow + 1) < ROWNO) { /* move down */ + step = 1; + if (scol < COLNO - 1) + right_side(nrow, scol, right, limits); + if (scol) + left_side(nrow, left, scol, limits); } - if ( (nrow = srow-1) >= 0 ) { /* move up */ - step = -1; - if (scol < COLNO-1) right_side(nrow, scol, right, limits); - if (scol) left_side (nrow, left, scol, limits); + if ((nrow = srow - 1) >= 0) { /* move up */ + step = -1; + if (scol < COLNO - 1) + right_side(nrow, scol, right, limits); + if (scol) + left_side(nrow, left, scol, limits); } } -#endif /*===== End of algorithm C =====*/ +#endif /*===== End of algorithm C =====*/ /* * AREA OF EFFECT "ENGINE" @@ -2573,42 +2757,46 @@ view_from(srow, scol, loc_cs_rows, left_most, right_most, range, func, arg) * vision matrix and reduce extra work. */ void -do_clear_area(scol,srow,range,func,arg) - int scol, srow, range; - void FDECL((*func), (int,int,genericptr_t)); - genericptr_t arg; +do_clear_area(scol, srow, range, func, arg) +int scol, srow, range; +void FDECL((*func), (int, int, genericptr_t)); +genericptr_t arg; { - /* If not centered on hero, do the hard work of figuring the area */ - if (scol != u.ux || srow != u.uy) - view_from(srow, scol, (char **)0, (char *)0, (char *)0, - range, func, arg); - else { - register int x; - int y, min_x, max_x, max_y, offset; - char *limits; - boolean override_vision; + /* If not centered on hero, do the hard work of figuring the area */ + if (scol != u.ux || srow != u.uy) + view_from(srow, scol, (char **) 0, (char *) 0, (char *) 0, range, + func, arg); + else { + register int x; + int y, min_x, max_x, max_y, offset; + char *limits; + boolean override_vision; - /* vision doesn't pass through water or clouds, detection should - [this probably ought to be an arg supplied by our caller...] */ - override_vision = (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) && - detecting(func); + /* vision doesn't pass through water or clouds, detection should + [this probably ought to be an arg supplied by our caller...] */ + override_vision = + (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) && detecting(func); - if (range > MAX_RADIUS || range < 1) - panic("do_clear_area: illegal range %d", range); - if(vision_full_recalc) - vision_recalc(0); /* recalc vision if dirty */ - limits = circle_ptr(range); - if ((max_y = (srow + range)) >= ROWNO) max_y = ROWNO-1; - if ((y = (srow - range)) < 0) y = 0; - for (; y <= max_y; y++) { - offset = limits[v_abs(y-srow)]; - if((min_x = (scol - offset)) < 0) min_x = 0; - if((max_x = (scol + offset)) >= COLNO) max_x = COLNO-1; - for (x = min_x; x <= max_x; x++) - if (couldsee(x, y) || override_vision) - (*func)(x, y, arg); - } - } + if (range > MAX_RADIUS || range < 1) + panic("do_clear_area: illegal range %d", range); + if (vision_full_recalc) + vision_recalc(0); /* recalc vision if dirty */ + limits = circle_ptr(range); + if ((max_y = (srow + range)) >= ROWNO) + max_y = ROWNO - 1; + if ((y = (srow - range)) < 0) + y = 0; + for (; y <= max_y; y++) { + offset = limits[v_abs(y - srow)]; + if ((min_x = (scol - offset)) < 0) + min_x = 0; + if ((max_x = (scol + offset)) >= COLNO) + max_x = COLNO - 1; + for (x = min_x; x <= max_x; x++) + if (couldsee(x, y) || override_vision) + (*func)(x, y, arg); + } + } } /* bitmask indicating ways mon is seen; extracted from lookat(pager.c) */ @@ -2616,35 +2804,35 @@ unsigned howmonseen(mon) struct monst *mon; { - boolean useemon = (boolean)canseemon(mon); + boolean useemon = (boolean) canseemon(mon); int xraydist = (u.xray_range < 0) ? -1 : (u.xray_range * u.xray_range); - unsigned how_seen = 0; /* result */ + unsigned how_seen = 0; /* result */ /* normal vision; cansee is true for both normal and astral vision, but couldsee it not true for astral vision */ - if ((mon->wormno ? worm_known(mon) : - (cansee(mon->mx, mon->my) && couldsee(mon->mx, mon->my))) && - mon_visible(mon) && !mon->minvis) - how_seen |= MONSEEN_NORMAL; + if ((mon->wormno ? worm_known(mon) : (cansee(mon->mx, mon->my) + && couldsee(mon->mx, mon->my))) + && mon_visible(mon) && !mon->minvis) + how_seen |= MONSEEN_NORMAL; /* see invisible */ if (useemon && mon->minvis) - how_seen |= MONSEEN_SEEINVIS; + how_seen |= MONSEEN_SEEINVIS; /* infravision */ if ((!mon->minvis || See_invisible) && see_with_infrared(mon)) - how_seen |= MONSEEN_INFRAVIS; + how_seen |= MONSEEN_INFRAVIS; /* telepathy */ if (tp_sensemon(mon)) - how_seen |= MONSEEN_TELEPAT; + how_seen |= MONSEEN_TELEPAT; /* xray */ if (useemon && xraydist > 0 && distu(mon->mx, mon->my) <= xraydist) - how_seen |= MONSEEN_XRAYVIS; + how_seen |= MONSEEN_XRAYVIS; /* extended detection */ if (Detect_monsters) - how_seen |= MONSEEN_DETECT; + how_seen |= MONSEEN_DETECT; /* class-/type-specific warning */ if (MATCH_WARN_OF_MON(mon)) - how_seen |= MONSEEN_WARNMON; + how_seen |= MONSEEN_WARNMON; return how_seen; } diff --git a/src/weapon.c b/src/weapon.c index e7a836faf..7c9b64dae 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 weapon.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 weapon.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.49 $ */ /* NetHack 3.6 weapon.c $Date: 2011/12/18 05:16:28 $ $Revision: 1.38 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,60 +12,42 @@ /* Categories whose names don't come from OBJ_NAME(objects[type]) */ -#define PN_BARE_HANDED (-1) /* includes martial arts */ -#define PN_TWO_WEAPONS (-2) -#define PN_RIDING (-3) -#define PN_POLEARMS (-4) -#define PN_SABER (-5) -#define PN_HAMMER (-6) -#define PN_WHIP (-7) -#define PN_ATTACK_SPELL (-8) -#define PN_HEALING_SPELL (-9) -#define PN_DIVINATION_SPELL (-10) -#define PN_ENCHANTMENT_SPELL (-11) -#define PN_CLERIC_SPELL (-12) -#define PN_ESCAPE_SPELL (-13) -#define PN_MATTER_SPELL (-14) +#define PN_BARE_HANDED (-1) /* includes martial arts */ +#define PN_TWO_WEAPONS (-2) +#define PN_RIDING (-3) +#define PN_POLEARMS (-4) +#define PN_SABER (-5) +#define PN_HAMMER (-6) +#define PN_WHIP (-7) +#define PN_ATTACK_SPELL (-8) +#define PN_HEALING_SPELL (-9) +#define PN_DIVINATION_SPELL (-10) +#define PN_ENCHANTMENT_SPELL (-11) +#define PN_CLERIC_SPELL (-12) +#define PN_ESCAPE_SPELL (-13) +#define PN_MATTER_SPELL (-14) STATIC_DCL void FDECL(give_may_advance_msg, (int)); STATIC_VAR NEARDATA const short skill_names_indices[P_NUM_SKILLS] = { - 0, DAGGER, KNIFE, AXE, - PICK_AXE, SHORT_SWORD, BROADSWORD, LONG_SWORD, - TWO_HANDED_SWORD, SCIMITAR, PN_SABER, CLUB, - MACE, MORNING_STAR, FLAIL, - PN_HAMMER, QUARTERSTAFF, PN_POLEARMS, SPEAR, - TRIDENT, LANCE, BOW, - SLING, CROSSBOW, DART, - SHURIKEN, BOOMERANG, PN_WHIP, UNICORN_HORN, - PN_ATTACK_SPELL, PN_HEALING_SPELL, - PN_DIVINATION_SPELL, PN_ENCHANTMENT_SPELL, - PN_CLERIC_SPELL, PN_ESCAPE_SPELL, - PN_MATTER_SPELL, - PN_BARE_HANDED, PN_TWO_WEAPONS, - PN_RIDING + 0, DAGGER, KNIFE, AXE, PICK_AXE, SHORT_SWORD, BROADSWORD, LONG_SWORD, + TWO_HANDED_SWORD, SCIMITAR, PN_SABER, CLUB, MACE, MORNING_STAR, FLAIL, + PN_HAMMER, QUARTERSTAFF, PN_POLEARMS, SPEAR, TRIDENT, LANCE, BOW, SLING, + CROSSBOW, DART, SHURIKEN, BOOMERANG, PN_WHIP, UNICORN_HORN, + PN_ATTACK_SPELL, PN_HEALING_SPELL, PN_DIVINATION_SPELL, + PN_ENCHANTMENT_SPELL, PN_CLERIC_SPELL, PN_ESCAPE_SPELL, PN_MATTER_SPELL, + PN_BARE_HANDED, PN_TWO_WEAPONS, PN_RIDING }; /* note: entry [0] isn't used */ -STATIC_VAR NEARDATA const char * const odd_skill_names[] = { - "no skill", - "bare hands", /* use barehands_or_martial[] instead */ - "two weapon combat", - "riding", - "polearms", - "saber", - "hammer", - "whip", - "attack spells", - "healing spells", - "divination spells", - "enchantment spells", - "clerical spells", - "escape spells", - "matter spells", +STATIC_VAR NEARDATA const char *const odd_skill_names[] = { + "no skill", "bare hands", /* use barehands_or_martial[] instead */ + "two weapon combat", "riding", "polearms", "saber", "hammer", "whip", + "attack spells", "healing spells", "divination spells", + "enchantment spells", "clerical spells", "escape spells", "matter spells", }; /* indexed vis `is_martial() */ -STATIC_VAR NEARDATA const char * const barehands_or_martial[] = { +STATIC_VAR NEARDATA const char *const barehands_or_martial[] = { "bare handed combat", "martial arts" }; @@ -73,34 +55,33 @@ STATIC_OVL void give_may_advance_msg(skill) int skill; { - You_feel("more confident in your %sskills.", - skill == P_NONE ? - "" : - skill <= P_LAST_WEAPON ? - "weapon " : - skill <= P_LAST_SPELL ? - "spell casting " : - "fighting "); + You_feel("more confident in your %sskills.", + skill == P_NONE ? "" : skill <= P_LAST_WEAPON + ? "weapon " + : skill <= P_LAST_SPELL + ? "spell casting " + : "fighting "); } STATIC_DCL boolean FDECL(can_advance, (int, BOOLEAN_P)); STATIC_DCL boolean FDECL(could_advance, (int)); STATIC_DCL boolean FDECL(peaked_skill, (int)); STATIC_DCL int FDECL(slots_required, (int)); -STATIC_DCL char *FDECL(skill_level_name, (int,char *)); +STATIC_DCL char *FDECL(skill_level_name, (int, char *)); STATIC_DCL void FDECL(skill_advance, (int)); -#define P_NAME(type) ((skill_names_indices[type] > 0) ? \ - OBJ_NAME(objects[skill_names_indices[type]]) : \ - (type == P_BARE_HANDED_COMBAT) ? \ - barehands_or_martial[martial_bonus()] : \ - odd_skill_names[-skill_names_indices[type]]) +#define P_NAME(type) \ + ((skill_names_indices[type] > 0) \ + ? OBJ_NAME(objects[skill_names_indices[type]]) \ + : (type == P_BARE_HANDED_COMBAT) \ + ? barehands_or_martial[martial_bonus()] \ + : odd_skill_names[-skill_names_indices[type]]) -static NEARDATA const char kebabable[] = { - S_XORN, S_DRAGON, S_JABBERWOCK, S_NAGA, S_GIANT, '\0' -}; +static NEARDATA const char kebabable[] = { S_XORN, S_DRAGON, S_JABBERWOCK, + S_NAGA, S_GIANT, '\0' }; -/* weapon's skill category name for use as generalized description of weapon */ +/* weapon's skill category name for use as generalized description of weapon + */ const char * weapon_descr(obj) struct obj *obj; @@ -111,36 +92,44 @@ struct obj *obj; /* assorted special cases */ switch (skill) { case P_NONE: - /* not a weapon: use item class name; override "food" for corpses, - tins, and eggs and "large rock" for statues and boulders */ - descr = (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG || - obj->otyp == STATUE || obj->otyp == BOULDER) ? - OBJ_NAME(objects[obj->otyp]) : - def_oc_syms[(int)obj->oclass].name; - break; + /* not a weapon: use item class name; override "food" for corpses, + tins, and eggs and "large rock" for statues and boulders */ + descr = (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG + || obj->otyp == STATUE || obj->otyp == BOULDER) + ? OBJ_NAME(objects[obj->otyp]) + : def_oc_syms[(int) obj->oclass].name; + break; case P_SLING: - if (is_ammo(obj)) - descr = (obj->otyp == ROCK || is_graystone(obj)) ? "stone" : - /* avoid "rock"; what about known glass? */ - (obj->oclass == GEM_CLASS) ? "gem" : - /* in case somebody adds odd sling ammo */ - def_oc_syms[(int)obj->oclass].name; - break; + if (is_ammo(obj)) + descr = (obj->otyp == ROCK || is_graystone(obj)) + ? "stone" + : + /* avoid "rock"; what about known glass? */ + (obj->oclass == GEM_CLASS) + ? "gem" + : + /* in case somebody adds odd sling ammo */ + def_oc_syms[(int) obj->oclass].name; + break; case P_BOW: - if (is_ammo(obj)) descr = "arrow"; - break; + if (is_ammo(obj)) + descr = "arrow"; + break; case P_CROSSBOW: - if (is_ammo(obj)) descr = "bolt"; - break; + if (is_ammo(obj)) + descr = "bolt"; + break; case P_FLAIL: - if (obj->otyp == GRAPPLING_HOOK) descr = "hook"; - break; + if (obj->otyp == GRAPPLING_HOOK) + descr = "hook"; + break; case P_PICK_AXE: - /* even if "dwarvish mattock" hasn't been discovered yet */ - if (obj->otyp == DWARVISH_MATTOCK) descr = "mattock"; - break; + /* even if "dwarvish mattock" hasn't been discovered yet */ + if (obj->otyp == DWARVISH_MATTOCK) + descr = "mattock"; + break; default: - break; + break; } return makesingular(descr); } @@ -154,39 +143,43 @@ hitval(otmp, mon) struct obj *otmp; struct monst *mon; { - int tmp = 0; - struct permonst *ptr = mon->data; - boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp)); + int tmp = 0; + struct permonst *ptr = mon->data; + boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp)); - if (Is_weapon) - tmp += otmp->spe; + if (Is_weapon) + tmp += otmp->spe; -/* Put weapon specific "to hit" bonuses in below: */ - tmp += objects[otmp->otyp].oc_hitbon; + /* Put weapon specific "to hit" bonuses in below: */ + tmp += objects[otmp->otyp].oc_hitbon; -/* Put weapon vs. monster type "to hit" bonuses in below: */ + /* Put weapon vs. monster type "to hit" bonuses in below: */ - /* Blessed weapons used against undead or demons */ - if (Is_weapon && otmp->blessed && - (is_demon(ptr) || is_undead(ptr) || is_vampshifter(mon))) tmp += 2; + /* Blessed weapons used against undead or demons */ + if (Is_weapon && otmp->blessed + && (is_demon(ptr) || is_undead(ptr) || is_vampshifter(mon))) + tmp += 2; - if (is_spear(otmp) && - index(kebabable, ptr->mlet)) tmp += 2; + if (is_spear(otmp) && index(kebabable, ptr->mlet)) + tmp += 2; - /* trident is highly effective against swimmers */ - if (otmp->otyp == TRIDENT && is_swimmer(ptr)) { - if (is_pool(mon->mx, mon->my)) tmp += 4; - else if (ptr->mlet == S_EEL || ptr->mlet == S_SNAKE) tmp += 2; - } + /* trident is highly effective against swimmers */ + if (otmp->otyp == TRIDENT && is_swimmer(ptr)) { + if (is_pool(mon->mx, mon->my)) + tmp += 4; + else if (ptr->mlet == S_EEL || ptr->mlet == S_SNAKE) + tmp += 2; + } - /* Picks used against xorns and earth elementals */ - if (is_pick(otmp) && - (passes_walls(ptr) && thick_skinned(ptr))) tmp += 2; + /* Picks used against xorns and earth elementals */ + if (is_pick(otmp) && (passes_walls(ptr) && thick_skinned(ptr))) + tmp += 2; - /* Check specially named weapon "to hit" bonuses */ - if (otmp->oartifact) tmp += spec_abon(otmp, mon); + /* Check specially named weapon "to hit" bonuses */ + if (otmp->oartifact) + tmp += spec_abon(otmp, mon); - return tmp; + return tmp; } /* Historical note: The original versions of Hack used a range of damage @@ -220,324 +213,352 @@ dmgval(otmp, mon) struct obj *otmp; struct monst *mon; { - int tmp = 0, otyp = otmp->otyp; - struct permonst *ptr = mon->data; - boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp)); + int tmp = 0, otyp = otmp->otyp; + struct permonst *ptr = mon->data; + boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp)); - if (otyp == CREAM_PIE) return 0; + if (otyp == CREAM_PIE) + return 0; - if (bigmonst(ptr)) { - if (objects[otyp].oc_wldam) - tmp = rnd(objects[otyp].oc_wldam); - switch (otyp) { - case IRON_CHAIN: - case CROSSBOW_BOLT: - case MORNING_STAR: - case PARTISAN: - case RUNESWORD: - case ELVEN_BROADSWORD: - case BROADSWORD: tmp++; break; + if (bigmonst(ptr)) { + if (objects[otyp].oc_wldam) + tmp = rnd(objects[otyp].oc_wldam); + switch (otyp) { + case IRON_CHAIN: + case CROSSBOW_BOLT: + case MORNING_STAR: + case PARTISAN: + case RUNESWORD: + case ELVEN_BROADSWORD: + case BROADSWORD: + tmp++; + break; - case FLAIL: - case RANSEUR: - case VOULGE: tmp += rnd(4); break; + case FLAIL: + case RANSEUR: + case VOULGE: + tmp += rnd(4); + break; - case ACID_VENOM: - case HALBERD: - case SPETUM: tmp += rnd(6); break; + case ACID_VENOM: + case HALBERD: + case SPETUM: + tmp += rnd(6); + break; - case BATTLE_AXE: - case BARDICHE: - case TRIDENT: tmp += d(2,4); break; + case BATTLE_AXE: + case BARDICHE: + case TRIDENT: + tmp += d(2, 4); + break; - case TSURUGI: - case DWARVISH_MATTOCK: - case TWO_HANDED_SWORD: tmp += d(2,6); break; - } - } else { - if (objects[otyp].oc_wsdam) - tmp = rnd(objects[otyp].oc_wsdam); - switch (otyp) { - case IRON_CHAIN: - case CROSSBOW_BOLT: - case MACE: - case WAR_HAMMER: - case FLAIL: - case SPETUM: - case TRIDENT: tmp++; break; + case TSURUGI: + case DWARVISH_MATTOCK: + case TWO_HANDED_SWORD: + tmp += d(2, 6); + break; + } + } else { + if (objects[otyp].oc_wsdam) + tmp = rnd(objects[otyp].oc_wsdam); + switch (otyp) { + case IRON_CHAIN: + case CROSSBOW_BOLT: + case MACE: + case WAR_HAMMER: + case FLAIL: + case SPETUM: + case TRIDENT: + tmp++; + break; - case BATTLE_AXE: - case BARDICHE: - case BILL_GUISARME: - case GUISARME: - case LUCERN_HAMMER: - case MORNING_STAR: - case RANSEUR: - case BROADSWORD: - case ELVEN_BROADSWORD: - case RUNESWORD: - case VOULGE: tmp += rnd(4); break; + case BATTLE_AXE: + case BARDICHE: + case BILL_GUISARME: + case GUISARME: + case LUCERN_HAMMER: + case MORNING_STAR: + case RANSEUR: + case BROADSWORD: + case ELVEN_BROADSWORD: + case RUNESWORD: + case VOULGE: + tmp += rnd(4); + break; - case ACID_VENOM: tmp += rnd(6); break; - } - } - if (Is_weapon) { - tmp += otmp->spe; - /* negative enchantment mustn't produce negative damage */ - if (tmp < 0) tmp = 0; - } + case ACID_VENOM: + tmp += rnd(6); + break; + } + } + if (Is_weapon) { + tmp += otmp->spe; + /* negative enchantment mustn't produce negative damage */ + if (tmp < 0) + tmp = 0; + } - if (objects[otyp].oc_material <= LEATHER && thick_skinned(ptr)) - /* thick skinned/scaled creatures don't feel it */ - tmp = 0; - if (ptr == &mons[PM_SHADE] && !shade_glare(otmp)) - tmp = 0; + if (objects[otyp].oc_material <= LEATHER && thick_skinned(ptr)) + /* thick skinned/scaled creatures don't feel it */ + tmp = 0; + if (ptr == &mons[PM_SHADE] && !shade_glare(otmp)) + tmp = 0; - /* "very heavy iron ball"; weight increase is in increments of 160 */ - if (otyp == HEAVY_IRON_BALL && tmp > 0) { - int wt = (int)objects[HEAVY_IRON_BALL].oc_weight; + /* "very heavy iron ball"; weight increase is in increments of 160 */ + if (otyp == HEAVY_IRON_BALL && tmp > 0) { + int wt = (int) objects[HEAVY_IRON_BALL].oc_weight; - if ((int)otmp->owt > wt) { - wt = ((int)otmp->owt - wt) / 160; - tmp += rnd(4 * wt); - if (tmp > 25) tmp = 25; /* objects[].oc_wldam */ - } - } + if ((int) otmp->owt > wt) { + wt = ((int) otmp->owt - wt) / 160; + tmp += rnd(4 * wt); + if (tmp > 25) + tmp = 25; /* objects[].oc_wldam */ + } + } -/* Put weapon vs. monster type damage bonuses in below: */ - if (Is_weapon || otmp->oclass == GEM_CLASS || - otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS) { - int bonus = 0; + /* Put weapon vs. monster type damage bonuses in below: */ + if (Is_weapon || otmp->oclass == GEM_CLASS || otmp->oclass == BALL_CLASS + || otmp->oclass == CHAIN_CLASS) { + int bonus = 0; - if (otmp->blessed && - (is_undead(ptr) || is_demon(ptr) || is_vampshifter(mon))) - bonus += rnd(4); - if (is_axe(otmp) && is_wooden(ptr)) - bonus += rnd(4); - if (objects[otyp].oc_material == SILVER && mon_hates_silver(mon)) - bonus += rnd(20); + if (otmp->blessed + && (is_undead(ptr) || is_demon(ptr) || is_vampshifter(mon))) + bonus += rnd(4); + if (is_axe(otmp) && is_wooden(ptr)) + bonus += rnd(4); + if (objects[otyp].oc_material == SILVER && mon_hates_silver(mon)) + bonus += rnd(20); - /* if the weapon is going to get a double damage bonus, adjust - this bonus so that effectively it's added after the doubling */ - if (bonus > 1 && otmp->oartifact && spec_dbon(otmp, mon, 25) >= 25) - bonus = (bonus + 1) / 2; + /* if the weapon is going to get a double damage bonus, adjust + this bonus so that effectively it's added after the doubling */ + if (bonus > 1 && otmp->oartifact && spec_dbon(otmp, mon, 25) >= 25) + bonus = (bonus + 1) / 2; - tmp += bonus; - } + tmp += bonus; + } - if (tmp > 0) { - /* It's debateable whether a rusted blunt instrument - should do less damage than a pristine one, since - it will hit with essentially the same impact, but - there ought to some penalty for using damaged gear - so always subtract erosion even for blunt weapons. */ - tmp -= greatest_erosion(otmp); - if (tmp < 1) tmp = 1; - } + if (tmp > 0) { + /* It's debateable whether a rusted blunt instrument + should do less damage than a pristine one, since + it will hit with essentially the same impact, but + there ought to some penalty for using damaged gear + so always subtract erosion even for blunt weapons. */ + tmp -= greatest_erosion(otmp); + if (tmp < 1) + tmp = 1; + } - return(tmp); + return (tmp); } -STATIC_DCL struct obj *FDECL(oselect, (struct monst *,int)); -#define Oselect(x) if ((otmp = oselect(mtmp, x)) != 0) return(otmp); +STATIC_DCL struct obj *FDECL(oselect, (struct monst *, int)); +#define Oselect(x) \ + if ((otmp = oselect(mtmp, x)) != 0) \ + return (otmp); STATIC_OVL struct obj * oselect(mtmp, x) struct monst *mtmp; int x; { - struct obj *otmp; + struct obj *otmp; - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { - if (otmp->otyp == x && - /* never select non-cockatrice corpses */ - !((x == CORPSE || x == EGG) && - !touch_petrifies(&mons[otmp->corpsenm])) && - (!otmp->oartifact || touch_artifact(otmp,mtmp))) - return otmp; - } - return (struct obj *)0; + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { + if (otmp->otyp == x + && + /* never select non-cockatrice corpses */ + !((x == CORPSE || x == EGG) + && !touch_petrifies(&mons[otmp->corpsenm])) + && (!otmp->oartifact || touch_artifact(otmp, mtmp))) + return otmp; + } + return (struct obj *) 0; } -static NEARDATA const int rwep[] = -{ DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, - JAVELIN, SHURIKEN, YA, SILVER_ARROW, ELVEN_ARROW, ARROW, - ORCISH_ARROW, CROSSBOW_BOLT, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, - ORCISH_DAGGER, KNIFE, FLINT, ROCK, LOADSTONE, LUCKSTONE, DART, - /* BOOMERANG, */ CREAM_PIE +static NEARDATA const int rwep[] = { + DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, JAVELIN, + SHURIKEN, YA, SILVER_ARROW, ELVEN_ARROW, ARROW, ORCISH_ARROW, + CROSSBOW_BOLT, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, KNIFE, + FLINT, ROCK, LOADSTONE, LUCKSTONE, DART, + /* BOOMERANG, */ CREAM_PIE }; -static NEARDATA const int pwep[] = -{ HALBERD, BARDICHE, SPETUM, BILL_GUISARME, VOULGE, RANSEUR, GUISARME, - GLAIVE, LUCERN_HAMMER, BEC_DE_CORBIN, FAUCHARD, PARTISAN, LANCE -}; +static NEARDATA const int pwep[] = { HALBERD, BARDICHE, SPETUM, + BILL_GUISARME, VOULGE, RANSEUR, + GUISARME, GLAIVE, LUCERN_HAMMER, + BEC_DE_CORBIN, FAUCHARD, PARTISAN, + LANCE }; static struct obj *propellor; -struct obj * -select_rwep(mtmp) /* select a ranged weapon for the monster */ +struct obj *select_rwep(mtmp) /* select a ranged weapon for the monster */ register struct monst *mtmp; { - register struct obj *otmp; - struct obj *mwep; - boolean mweponly; - int i; + register struct obj *otmp; + struct obj *mwep; + boolean mweponly; + int i; - char mlet = mtmp->data->mlet; + char mlet = mtmp->data->mlet; - propellor = &zeroobj; - Oselect(EGG); /* cockatrice egg */ - if(mlet == S_KOP) /* pies are first choice for Kops */ - Oselect(CREAM_PIE); - if(throws_rocks(mtmp->data)) /* ...boulders for giants */ - Oselect(BOULDER); + propellor = &zeroobj; + Oselect(EGG); /* cockatrice egg */ + if (mlet == S_KOP) /* pies are first choice for Kops */ + Oselect(CREAM_PIE); + if (throws_rocks(mtmp->data)) /* ...boulders for giants */ + Oselect(BOULDER); - /* Select polearms first; they do more damage and aren't expendable. - But don't pick one if monster's weapon is welded, because then - we'd never have a chance to throw non-wielding missiles. */ - /* The limit of 13 here is based on the monster polearm range limit - * (defined as 5 in mthrowu.c). 5 corresponds to a distance of 2 in - * one direction and 1 in another; one space beyond that would be 3 in - * one direction and 2 in another; 3^2+2^2=13. - */ - mwep = MON_WEP(mtmp); - /* NO_WEAPON_WANTED means we already tried to wield and failed */ - mweponly = (mwelded(mwep) && mtmp->weapon_check == NO_WEAPON_WANTED); - if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13 && - couldsee(mtmp->mx, mtmp->my)) { - for (i = 0; i < SIZE(pwep); i++) { - /* Only strong monsters can wield big (esp. long) weapons. - * Big weapon is basically the same as bimanual. - * All monsters can wield the remaining weapons. - */ - if (((strongmonst(mtmp->data) && (mtmp->misc_worn_check & W_ARMS) == 0) - || !objects[pwep[i]].oc_bimanual) && - (objects[pwep[i]].oc_material != SILVER - || !mon_hates_silver(mtmp))) { - if ((otmp = oselect(mtmp, pwep[i])) != 0 && - (otmp == mwep || !mweponly)) { - propellor = otmp; /* force the monster to wield it */ - return otmp; - } - } - } - } + /* Select polearms first; they do more damage and aren't expendable. + But don't pick one if monster's weapon is welded, because then + we'd never have a chance to throw non-wielding missiles. */ + /* The limit of 13 here is based on the monster polearm range limit + * (defined as 5 in mthrowu.c). 5 corresponds to a distance of 2 in + * one direction and 1 in another; one space beyond that would be 3 in + * one direction and 2 in another; 3^2+2^2=13. + */ + mwep = MON_WEP(mtmp); + /* NO_WEAPON_WANTED means we already tried to wield and failed */ + mweponly = (mwelded(mwep) && mtmp->weapon_check == NO_WEAPON_WANTED); + if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13 + && couldsee(mtmp->mx, mtmp->my)) { + for (i = 0; i < SIZE(pwep); i++) { + /* Only strong monsters can wield big (esp. long) weapons. + * Big weapon is basically the same as bimanual. + * All monsters can wield the remaining weapons. + */ + if (((strongmonst(mtmp->data) + && (mtmp->misc_worn_check & W_ARMS) == 0) + || !objects[pwep[i]].oc_bimanual) + && (objects[pwep[i]].oc_material != SILVER + || !mon_hates_silver(mtmp))) { + if ((otmp = oselect(mtmp, pwep[i])) != 0 + && (otmp == mwep || !mweponly)) { + propellor = otmp; /* force the monster to wield it */ + return otmp; + } + } + } + } - /* - * other than these two specific cases, always select the - * most potent ranged weapon to hand. - */ - for (i = 0; i < SIZE(rwep); i++) { - int prop; + /* + * other than these two specific cases, always select the + * most potent ranged weapon to hand. + */ + for (i = 0; i < SIZE(rwep); i++) { + int prop; - /* shooting gems from slings; this goes just before the darts */ - /* (shooting rocks is already handled via the rwep[] ordering) */ - if (rwep[i] == DART && !likes_gems(mtmp->data) && - m_carrying(mtmp, SLING)) { /* propellor */ - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if (otmp->oclass == GEM_CLASS && - (otmp->otyp != LOADSTONE || !otmp->cursed)) { - propellor = m_carrying(mtmp, SLING); - return otmp; - } - } + /* shooting gems from slings; this goes just before the darts */ + /* (shooting rocks is already handled via the rwep[] ordering) */ + if (rwep[i] == DART && !likes_gems(mtmp->data) + && m_carrying(mtmp, SLING)) { /* propellor */ + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->oclass == GEM_CLASS + && (otmp->otyp != LOADSTONE || !otmp->cursed)) { + propellor = m_carrying(mtmp, SLING); + return otmp; + } + } - /* KMH -- This belongs here so darts will work */ - propellor = &zeroobj; + /* KMH -- This belongs here so darts will work */ + propellor = &zeroobj; - prop = (objects[rwep[i]]).oc_skill; - if (prop < 0) { - switch (-prop) { - case P_BOW: - propellor = (oselect(mtmp, YUMI)); - if (!propellor) propellor = (oselect(mtmp, ELVEN_BOW)); - if (!propellor) propellor = (oselect(mtmp, BOW)); - if (!propellor) propellor = (oselect(mtmp, ORCISH_BOW)); - break; - case P_SLING: - propellor = (oselect(mtmp, SLING)); - break; - case P_CROSSBOW: - propellor = (oselect(mtmp, CROSSBOW)); - } - if ((otmp = MON_WEP(mtmp)) && mwelded(otmp) && otmp != propellor - && mtmp->weapon_check == NO_WEAPON_WANTED) - propellor = 0; - } - /* propellor = obj, propellor to use - * propellor = &zeroobj, doesn't need a propellor - * propellor = 0, needed one and didn't have one - */ - if (propellor != 0) { - /* Note: cannot use m_carrying for loadstones, since it will - * always select the first object of a type, and maybe the - * monster is carrying two but only the first is unthrowable. - */ - if (rwep[i] != LOADSTONE) { - /* Don't throw a cursed weapon-in-hand or an artifact */ - if ((otmp = oselect(mtmp, rwep[i])) && !otmp->oartifact - && !(otmp == MON_WEP(mtmp) && mwelded(otmp))) - return(otmp); - } else for(otmp=mtmp->minvent; otmp; otmp=otmp->nobj) { - if (otmp->otyp == LOADSTONE && !otmp->cursed) - return otmp; - } - } - } + prop = (objects[rwep[i]]).oc_skill; + if (prop < 0) { + switch (-prop) { + case P_BOW: + propellor = (oselect(mtmp, YUMI)); + if (!propellor) + propellor = (oselect(mtmp, ELVEN_BOW)); + if (!propellor) + propellor = (oselect(mtmp, BOW)); + if (!propellor) + propellor = (oselect(mtmp, ORCISH_BOW)); + break; + case P_SLING: + propellor = (oselect(mtmp, SLING)); + break; + case P_CROSSBOW: + propellor = (oselect(mtmp, CROSSBOW)); + } + if ((otmp = MON_WEP(mtmp)) && mwelded(otmp) && otmp != propellor + && mtmp->weapon_check == NO_WEAPON_WANTED) + propellor = 0; + } + /* propellor = obj, propellor to use + * propellor = &zeroobj, doesn't need a propellor + * propellor = 0, needed one and didn't have one + */ + if (propellor != 0) { + /* Note: cannot use m_carrying for loadstones, since it will + * always select the first object of a type, and maybe the + * monster is carrying two but only the first is unthrowable. + */ + if (rwep[i] != LOADSTONE) { + /* Don't throw a cursed weapon-in-hand or an artifact */ + if ((otmp = oselect(mtmp, rwep[i])) && !otmp->oartifact + && !(otmp == MON_WEP(mtmp) && mwelded(otmp))) + return (otmp); + } else + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { + if (otmp->otyp == LOADSTONE && !otmp->cursed) + return otmp; + } + } + } - /* failure */ - return (struct obj *)0; + /* failure */ + return (struct obj *) 0; } /* Weapons in order of preference */ static const NEARDATA short hwep[] = { - CORPSE, /* cockatrice corpse */ - TSURUGI, RUNESWORD, DWARVISH_MATTOCK, TWO_HANDED_SWORD, BATTLE_AXE, - KATANA, UNICORN_HORN, CRYSKNIFE, TRIDENT, LONG_SWORD, - ELVEN_BROADSWORD, BROADSWORD, SCIMITAR, SILVER_SABER, - MORNING_STAR, ELVEN_SHORT_SWORD, DWARVISH_SHORT_SWORD, SHORT_SWORD, - ORCISH_SHORT_SWORD, MACE, AXE, DWARVISH_SPEAR, SILVER_SPEAR, - ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, FLAIL, BULLWHIP, QUARTERSTAFF, - JAVELIN, AKLYS, CLUB, PICK_AXE, RUBBER_HOSE, WAR_HAMMER, SILVER_DAGGER, - ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, ATHAME, SCALPEL, KNIFE, WORM_TOOTH - }; + CORPSE, /* cockatrice corpse */ + TSURUGI, RUNESWORD, DWARVISH_MATTOCK, TWO_HANDED_SWORD, BATTLE_AXE, + KATANA, UNICORN_HORN, CRYSKNIFE, TRIDENT, LONG_SWORD, ELVEN_BROADSWORD, + BROADSWORD, SCIMITAR, SILVER_SABER, MORNING_STAR, ELVEN_SHORT_SWORD, + DWARVISH_SHORT_SWORD, SHORT_SWORD, ORCISH_SHORT_SWORD, MACE, AXE, + DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, FLAIL, + BULLWHIP, QUARTERSTAFF, JAVELIN, AKLYS, CLUB, PICK_AXE, RUBBER_HOSE, + WAR_HAMMER, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, ATHAME, + SCALPEL, KNIFE, WORM_TOOTH +}; struct obj * -select_hwep(mtmp) /* select a hand to hand weapon for the monster */ +select_hwep(mtmp) /* select a hand to hand weapon for the monster */ register struct monst *mtmp; { - register struct obj *otmp; - register int i; - boolean strong = strongmonst(mtmp->data); - boolean wearing_shield = (mtmp->misc_worn_check & W_ARMS) != 0; + register struct obj *otmp; + register int i; + boolean strong = strongmonst(mtmp->data); + boolean wearing_shield = (mtmp->misc_worn_check & W_ARMS) != 0; - /* prefer artifacts to everything else */ - for(otmp=mtmp->minvent; otmp; otmp = otmp->nobj) { - if (otmp->oclass == WEAPON_CLASS - && otmp->oartifact && touch_artifact(otmp,mtmp) - && ((strong && !wearing_shield) - || !objects[otmp->otyp].oc_bimanual)) - return otmp; - } + /* prefer artifacts to everything else */ + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { + if (otmp->oclass == WEAPON_CLASS && otmp->oartifact + && touch_artifact(otmp, mtmp) + && ((strong && !wearing_shield) + || !objects[otmp->otyp].oc_bimanual)) + return otmp; + } - if(is_giant(mtmp->data)) /* giants just love to use clubs */ - Oselect(CLUB); + if (is_giant(mtmp->data)) /* giants just love to use clubs */ + Oselect(CLUB); - /* only strong monsters can wield big (esp. long) weapons */ - /* big weapon is basically the same as bimanual */ - /* all monsters can wield the remaining weapons */ - for (i = 0; i < SIZE(hwep); i++) { - if (hwep[i] == CORPSE && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp)) - continue; - if (((strong && !wearing_shield) - || !objects[hwep[i]].oc_bimanual) && - (objects[hwep[i]].oc_material != SILVER - || !mon_hates_silver(mtmp))) - Oselect(hwep[i]); - } + /* only strong monsters can wield big (esp. long) weapons */ + /* big weapon is basically the same as bimanual */ + /* all monsters can wield the remaining weapons */ + for (i = 0; i < SIZE(hwep); i++) { + if (hwep[i] == CORPSE && !(mtmp->misc_worn_check & W_ARMG) + && !resists_ston(mtmp)) + continue; + if (((strong && !wearing_shield) || !objects[hwep[i]].oc_bimanual) + && (objects[hwep[i]].oc_material != SILVER + || !mon_hates_silver(mtmp))) + Oselect(hwep[i]); + } - /* failure */ - return (struct obj *)0; + /* failure */ + return (struct obj *) 0; } /* Called after polymorphing a monster, robbing it, etc.... Monsters @@ -548,51 +569,52 @@ possibly_unwield(mon, polyspot) struct monst *mon; boolean polyspot; { - struct obj *obj, *mw_tmp; + struct obj *obj, *mw_tmp; - if (!(mw_tmp = MON_WEP(mon))) - return; - for (obj = mon->minvent; obj; obj = obj->nobj) - if (obj == mw_tmp) break; - if (!obj) { /* The weapon was stolen or destroyed */ - MON_NOWEP(mon); - mon->weapon_check = NEED_WEAPON; - return; - } - if (!attacktype(mon->data, AT_WEAP)) { - setmnotwielded(mon, mw_tmp); - MON_NOWEP(mon); - mon->weapon_check = NO_WEAPON_WANTED; - obj_extract_self(obj); - if (cansee(mon->mx, mon->my)) { - pline("%s drops %s.", Monnam(mon), - distant_name(obj, doname)); - newsym(mon->mx, mon->my); - } - /* might be dropping object into water or lava */ - if (!flooreffects(obj, mon->mx, mon->my, "drop")) { - if (polyspot) bypass_obj(obj); - place_object(obj, mon->mx, mon->my); - stackobj(obj); - } - return; - } - /* The remaining case where there is a change is where a monster - * is polymorphed into a stronger/weaker monster with a different - * choice of weapons. This has no parallel for players. It can - * be handled by waiting until mon_wield_item is actually called. - * Though the monster still wields the wrong weapon until then, - * this is OK since the player can't see it. (FIXME: Not okay since - * probing can reveal it.) - * Note that if there is no change, setting the check to NEED_WEAPON - * is harmless. - * Possible problem: big monster with big cursed weapon gets - * polymorphed into little monster. But it's not quite clear how to - * handle this anyway.... - */ - if (!(mwelded(mw_tmp) && mon->weapon_check == NO_WEAPON_WANTED)) - mon->weapon_check = NEED_WEAPON; - return; + if (!(mw_tmp = MON_WEP(mon))) + return; + for (obj = mon->minvent; obj; obj = obj->nobj) + if (obj == mw_tmp) + break; + if (!obj) { /* The weapon was stolen or destroyed */ + MON_NOWEP(mon); + mon->weapon_check = NEED_WEAPON; + return; + } + if (!attacktype(mon->data, AT_WEAP)) { + setmnotwielded(mon, mw_tmp); + MON_NOWEP(mon); + mon->weapon_check = NO_WEAPON_WANTED; + obj_extract_self(obj); + if (cansee(mon->mx, mon->my)) { + pline("%s drops %s.", Monnam(mon), distant_name(obj, doname)); + newsym(mon->mx, mon->my); + } + /* might be dropping object into water or lava */ + if (!flooreffects(obj, mon->mx, mon->my, "drop")) { + if (polyspot) + bypass_obj(obj); + place_object(obj, mon->mx, mon->my); + stackobj(obj); + } + return; + } + /* The remaining case where there is a change is where a monster + * is polymorphed into a stronger/weaker monster with a different + * choice of weapons. This has no parallel for players. It can + * be handled by waiting until mon_wield_item is actually called. + * Though the monster still wields the wrong weapon until then, + * this is OK since the player can't see it. (FIXME: Not okay since + * probing can reveal it.) + * Note that if there is no change, setting the check to NEED_WEAPON + * is harmless. + * Possible problem: big monster with big cursed weapon gets + * polymorphed into little monster. But it's not quite clear how to + * handle this anyway.... + */ + if (!(mwelded(mw_tmp) && mon->weapon_check == NO_WEAPON_WANTED)) + mon->weapon_check = NEED_WEAPON; + return; } /* Let a monster try to wield a weapon, based on mon->weapon_check. @@ -602,106 +624,107 @@ int mon_wield_item(mon) register struct monst *mon; { - struct obj *obj; + struct obj *obj; - /* This case actually should never happen */ - if (mon->weapon_check == NO_WEAPON_WANTED) return 0; - switch(mon->weapon_check) { - case NEED_HTH_WEAPON: - obj = select_hwep(mon); - break; - case NEED_RANGED_WEAPON: - (void)select_rwep(mon); - obj = propellor; - break; - case NEED_PICK_AXE: - obj = m_carrying(mon, PICK_AXE); - /* KMH -- allow other picks */ - if (!obj && !which_armor(mon, W_ARMS)) - obj = m_carrying(mon, DWARVISH_MATTOCK); - break; - case NEED_AXE: - /* currently, only 2 types of axe */ - obj = m_carrying(mon, BATTLE_AXE); - if (!obj || which_armor(mon, W_ARMS)) - obj = m_carrying(mon, AXE); - break; - case NEED_PICK_OR_AXE: - /* prefer pick for fewer switches on most levels */ - obj = m_carrying(mon, DWARVISH_MATTOCK); - if (!obj) obj = m_carrying(mon, BATTLE_AXE); - if (!obj || which_armor(mon, W_ARMS)) { - obj = m_carrying(mon, PICK_AXE); - if (!obj) obj = m_carrying(mon, AXE); - } - break; - default: impossible("weapon_check %d for %s?", - mon->weapon_check, mon_nam(mon)); - return 0; - } - if (obj && obj != &zeroobj) { - struct obj *mw_tmp = MON_WEP(mon); - if (mw_tmp && mw_tmp->otyp == obj->otyp) { - /* already wielding it */ - mon->weapon_check = NEED_WEAPON; - return 0; - } - /* Actually, this isn't necessary--as soon as the monster - * wields the weapon, the weapon welds itself, so the monster - * can know it's cursed and needn't even bother trying. - * Still.... - */ - if (mw_tmp && mwelded(mw_tmp)) { - if (canseemon(mon)) { - char welded_buf[BUFSZ]; - const char *mon_hand = mbodypart(mon, HAND); + /* This case actually should never happen */ + if (mon->weapon_check == NO_WEAPON_WANTED) + return 0; + switch (mon->weapon_check) { + case NEED_HTH_WEAPON: + obj = select_hwep(mon); + break; + case NEED_RANGED_WEAPON: + (void) select_rwep(mon); + obj = propellor; + break; + case NEED_PICK_AXE: + obj = m_carrying(mon, PICK_AXE); + /* KMH -- allow other picks */ + if (!obj && !which_armor(mon, W_ARMS)) + obj = m_carrying(mon, DWARVISH_MATTOCK); + break; + case NEED_AXE: + /* currently, only 2 types of axe */ + obj = m_carrying(mon, BATTLE_AXE); + if (!obj || which_armor(mon, W_ARMS)) + obj = m_carrying(mon, AXE); + break; + case NEED_PICK_OR_AXE: + /* prefer pick for fewer switches on most levels */ + obj = m_carrying(mon, DWARVISH_MATTOCK); + if (!obj) + obj = m_carrying(mon, BATTLE_AXE); + if (!obj || which_armor(mon, W_ARMS)) { + obj = m_carrying(mon, PICK_AXE); + if (!obj) + obj = m_carrying(mon, AXE); + } + break; + default: + impossible("weapon_check %d for %s?", mon->weapon_check, + mon_nam(mon)); + return 0; + } + if (obj && obj != &zeroobj) { + struct obj *mw_tmp = MON_WEP(mon); + if (mw_tmp && mw_tmp->otyp == obj->otyp) { + /* already wielding it */ + mon->weapon_check = NEED_WEAPON; + return 0; + } + /* Actually, this isn't necessary--as soon as the monster + * wields the weapon, the weapon welds itself, so the monster + * can know it's cursed and needn't even bother trying. + * Still.... + */ + if (mw_tmp && mwelded(mw_tmp)) { + if (canseemon(mon)) { + char welded_buf[BUFSZ]; + const char *mon_hand = mbodypart(mon, HAND); - if (bimanual(mw_tmp)) mon_hand = makeplural(mon_hand); - Sprintf(welded_buf, "%s welded to %s %s", - otense(mw_tmp, "are"), - mhis(mon), mon_hand); + if (bimanual(mw_tmp)) + mon_hand = makeplural(mon_hand); + Sprintf(welded_buf, "%s welded to %s %s", + otense(mw_tmp, "are"), mhis(mon), mon_hand); - if (obj->otyp == PICK_AXE) { - pline("Since %s weapon%s %s,", - s_suffix(mon_nam(mon)), - plur(mw_tmp->quan), welded_buf); - pline("%s cannot wield that %s.", - mon_nam(mon), xname(obj)); - } else { - pline("%s tries to wield %s.", Monnam(mon), - doname(obj)); - pline("%s %s!", Yname2(mw_tmp), welded_buf); - } - mw_tmp->bknown = 1; - } - mon->weapon_check = NO_WEAPON_WANTED; - return 1; - } - mon->mw = obj; /* wield obj */ - setmnotwielded(mon, mw_tmp); - mon->weapon_check = NEED_WEAPON; - if (canseemon(mon)) { - pline("%s wields %s!", Monnam(mon), doname(obj)); - if (mwelded(mw_tmp)) { - pline("%s %s to %s %s!", - Tobjnam(obj, "weld"), - is_plural(obj) ? "themselves" : "itself", - s_suffix(mon_nam(mon)), mbodypart(mon,HAND)); - obj->bknown = 1; - } - } - if (artifact_light(obj) && !obj->lamplit) { - begin_burn(obj, FALSE); - if (canseemon(mon)) - pline("%s %s in %s %s!", Tobjnam(obj, "shine"), - arti_light_description(obj), - s_suffix(mon_nam(mon)), mbodypart(mon,HAND)); - } - obj->owornmask = W_WEP; - return 1; - } - mon->weapon_check = NEED_WEAPON; - return 0; + if (obj->otyp == PICK_AXE) { + pline("Since %s weapon%s %s,", s_suffix(mon_nam(mon)), + plur(mw_tmp->quan), welded_buf); + pline("%s cannot wield that %s.", mon_nam(mon), + xname(obj)); + } else { + pline("%s tries to wield %s.", Monnam(mon), doname(obj)); + pline("%s %s!", Yname2(mw_tmp), welded_buf); + } + mw_tmp->bknown = 1; + } + mon->weapon_check = NO_WEAPON_WANTED; + return 1; + } + mon->mw = obj; /* wield obj */ + setmnotwielded(mon, mw_tmp); + mon->weapon_check = NEED_WEAPON; + if (canseemon(mon)) { + pline("%s wields %s!", Monnam(mon), doname(obj)); + if (mwelded(mw_tmp)) { + pline("%s %s to %s %s!", Tobjnam(obj, "weld"), + is_plural(obj) ? "themselves" : "itself", + s_suffix(mon_nam(mon)), mbodypart(mon, HAND)); + obj->bknown = 1; + } + } + if (artifact_light(obj) && !obj->lamplit) { + begin_burn(obj, FALSE); + if (canseemon(mon)) + pline("%s %s in %s %s!", Tobjnam(obj, "shine"), + arti_light_description(obj), s_suffix(mon_nam(mon)), + mbodypart(mon, HAND)); + } + obj->owornmask = W_WEP; + return 1; + } + mon->weapon_check = NEED_WEAPON; + return 0; } /* force monster to stop wielding current weapon, if any */ @@ -712,54 +735,73 @@ struct monst *mon; struct obj *mwep = MON_WEP(mon); if (mwep) { - setmnotwielded(mon, mwep); - MON_NOWEP(mon); - mon->weapon_check = NEED_WEAPON; + setmnotwielded(mon, mwep); + MON_NOWEP(mon); + mon->weapon_check = NEED_WEAPON; } } -int -abon() /* attack bonus for strength & dexterity */ +int abon() /* attack bonus for strength & dexterity */ { - int sbon; - int str = ACURR(A_STR), dex = ACURR(A_DEX); + int sbon; + int str = ACURR(A_STR), dex = ACURR(A_DEX); - if (Upolyd) return(adj_lev(&mons[u.umonnum]) - 3); - if (str < 6) sbon = -2; - else if (str < 8) sbon = -1; - else if (str < 17) sbon = 0; - else if (str <= STR18(50)) sbon = 1; /* up to 18/50 */ - else if (str < STR18(100)) sbon = 2; - else sbon = 3; + if (Upolyd) + return (adj_lev(&mons[u.umonnum]) - 3); + if (str < 6) + sbon = -2; + else if (str < 8) + sbon = -1; + else if (str < 17) + sbon = 0; + else if (str <= STR18(50)) + sbon = 1; /* up to 18/50 */ + else if (str < STR18(100)) + sbon = 2; + else + sbon = 3; -/* Game tuning kludge: make it a bit easier for a low level character to hit */ - sbon += (u.ulevel < 3) ? 1 : 0; + /* Game tuning kludge: make it a bit easier for a low level character to + * hit */ + sbon += (u.ulevel < 3) ? 1 : 0; - if (dex < 4) return(sbon-3); - else if (dex < 6) return(sbon-2); - else if (dex < 8) return(sbon-1); - else if (dex < 14) return(sbon); - else return(sbon + dex-14); + if (dex < 4) + return (sbon - 3); + else if (dex < 6) + return (sbon - 2); + else if (dex < 8) + return (sbon - 1); + else if (dex < 14) + return (sbon); + else + return (sbon + dex - 14); } -int -dbon() /* damage bonus for strength */ +int dbon() /* damage bonus for strength */ { - int str = ACURR(A_STR); + int str = ACURR(A_STR); - if (Upolyd) return(0); + if (Upolyd) + return (0); - if (str < 6) return(-1); - else if (str < 16) return(0); - else if (str < 18) return(1); - else if (str == 18) return(2); /* up to 18 */ - else if (str <= STR18(75)) return(3); /* up to 18/75 */ - else if (str <= STR18(90)) return(4); /* up to 18/90 */ - else if (str < STR18(100)) return(5); /* up to 18/99 */ - else return(6); + if (str < 6) + return (-1); + else if (str < 16) + return (0); + else if (str < 18) + return (1); + else if (str == 18) + return (2); /* up to 18 */ + else if (str <= STR18(75)) + return (3); /* up to 18/75 */ + else if (str <= STR18(90)) + return (4); /* up to 18/90 */ + else if (str < STR18(100)) + return (5); /* up to 18/99 */ + else + return (6); } - /* copy the skill level name into the given buffer */ STATIC_OVL char * skill_level_name(skill, buf) @@ -769,14 +811,28 @@ char *buf; const char *ptr; switch (P_SKILL(skill)) { - case P_UNSKILLED: ptr = "Unskilled"; break; - case P_BASIC: ptr = "Basic"; break; - case P_SKILLED: ptr = "Skilled"; break; - case P_EXPERT: ptr = "Expert"; break; - /* these are for unarmed combat/martial arts only */ - case P_MASTER: ptr = "Master"; break; - case P_GRAND_MASTER: ptr = "Grand Master"; break; - default: ptr = "Unknown"; break; + case P_UNSKILLED: + ptr = "Unskilled"; + break; + case P_BASIC: + ptr = "Basic"; + break; + case P_SKILLED: + ptr = "Skilled"; + break; + case P_EXPERT: + ptr = "Expert"; + break; + /* these are for unarmed combat/martial arts only */ + case P_MASTER: + ptr = "Master"; + break; + case P_GRAND_MASTER: + ptr = "Grand Master"; + break; + default: + ptr = "Unknown"; + break; } Strcpy(buf, ptr); return buf; @@ -795,7 +851,7 @@ int skill; * skilled -> expert 3 */ if (skill <= P_LAST_WEAPON || skill == P_TWO_WEAPON_COMBAT) - return tmp; + return tmp; /* Fewer slots used up for unarmed or martial. * unskilled -> basic 1 @@ -814,13 +870,12 @@ can_advance(skill, speedy) int skill; boolean speedy; { - return !P_RESTRICTED(skill) - && P_SKILL(skill) < P_MAX_SKILL(skill) && ( - (wizard && speedy) || - (P_ADVANCE(skill) >= - (unsigned) practice_needed_to_advance(P_SKILL(skill)) - && u.skills_advanced < P_SKILL_LIMIT - && u.weapon_slots >= slots_required(skill))); + return !P_RESTRICTED(skill) && P_SKILL(skill) < P_MAX_SKILL(skill) + && ((wizard && speedy) + || (P_ADVANCE(skill) >= (unsigned) practice_needed_to_advance( + P_SKILL(skill)) + && u.skills_advanced < P_SKILL_LIMIT + && u.weapon_slots >= slots_required(skill))); } /* return true if this skill could be advanced if more slots were available */ @@ -828,11 +883,10 @@ STATIC_OVL boolean could_advance(skill) int skill; { - return !P_RESTRICTED(skill) - && P_SKILL(skill) < P_MAX_SKILL(skill) && ( - (P_ADVANCE(skill) >= - (unsigned) practice_needed_to_advance(P_SKILL(skill)) - && u.skills_advanced < P_SKILL_LIMIT)); + return !P_RESTRICTED(skill) && P_SKILL(skill) < P_MAX_SKILL(skill) + && ((P_ADVANCE(skill) + >= (unsigned) practice_needed_to_advance(P_SKILL(skill)) + && u.skills_advanced < P_SKILL_LIMIT)); } /* return true if this skill has reached its maximum and there's been enough @@ -841,10 +895,9 @@ STATIC_OVL boolean peaked_skill(skill) int skill; { - return !P_RESTRICTED(skill) - && P_SKILL(skill) >= P_MAX_SKILL(skill) && ( - (P_ADVANCE(skill) >= - (unsigned) practice_needed_to_advance(P_SKILL(skill)))); + return !P_RESTRICTED(skill) && P_SKILL(skill) >= P_MAX_SKILL(skill) + && ((P_ADVANCE(skill) + >= (unsigned) practice_needed_to_advance(P_SKILL(skill)))); } STATIC_OVL void @@ -856,17 +909,17 @@ int skill; u.skill_record[u.skills_advanced++] = skill; /* subtly change the advance message to indicate no more advancement */ You("are now %s skilled in %s.", - P_SKILL(skill) >= P_MAX_SKILL(skill) ? "most" : "more", - P_NAME(skill)); + P_SKILL(skill) >= P_MAX_SKILL(skill) ? "most" : "more", + P_NAME(skill)); } static const struct skill_range { - short first, last; - const char *name; + short first, last; + const char *name; } skill_ranges[] = { { P_FIRST_H_TO_H, P_LAST_H_TO_H, "Fighting Skills" }, { P_FIRST_WEAPON, P_LAST_WEAPON, "Weapon Skills" }, - { P_FIRST_SPELL, P_LAST_SPELL, "Spellcasting Skills" }, + { P_FIRST_SPELL, P_LAST_SPELL, "Spellcasting Skills" }, }; /* @@ -880,8 +933,7 @@ static const struct skill_range { int enhance_weapon_skill() { - int pass, i, n, len, longest, - to_advance, eventually_advance, maxxed_cnt; + int pass, i, n, len, longest, to_advance, eventually_advance, maxxed_cnt; char buf[BUFSZ], sklnambuf[BUFSZ]; const char *prefix; menu_item *selected; @@ -889,127 +941,132 @@ enhance_weapon_skill() winid win; boolean speedy = FALSE; - if (wizard && yn("Advance skills without practice?") == 'y') - speedy = TRUE; + if (wizard && yn("Advance skills without practice?") == 'y') + speedy = TRUE; - do { - /* find longest available skill name, count those that can advance */ - to_advance = eventually_advance = maxxed_cnt = 0; - for (longest = 0, i = 0; i < P_NUM_SKILLS; i++) { - if (P_RESTRICTED(i)) continue; - if ((len = strlen(P_NAME(i))) > longest) - longest = len; - if (can_advance(i, speedy)) to_advance++; - else if (could_advance(i)) eventually_advance++; - else if (peaked_skill(i)) maxxed_cnt++; - } + do { + /* find longest available skill name, count those that can advance */ + to_advance = eventually_advance = maxxed_cnt = 0; + for (longest = 0, i = 0; i < P_NUM_SKILLS; i++) { + if (P_RESTRICTED(i)) + continue; + if ((len = strlen(P_NAME(i))) > longest) + longest = len; + if (can_advance(i, speedy)) + to_advance++; + else if (could_advance(i)) + eventually_advance++; + else if (peaked_skill(i)) + maxxed_cnt++; + } - win = create_nhwindow(NHW_MENU); - start_menu(win); + win = create_nhwindow(NHW_MENU); + start_menu(win); - /* start with a legend if any entries will be annotated - with "*" or "#" below */ - if (eventually_advance > 0 || maxxed_cnt > 0) { - any = zeroany; - if (eventually_advance > 0) { - Sprintf(buf, - "(Skill%s flagged by \"*\" may be enhanced %s.)", - plur(eventually_advance), - (u.ulevel < MAXULEV) ? - "when you're more experienced" : - "if skill slots become available"); - add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, - buf, MENU_UNSELECTED); - } - if (maxxed_cnt > 0) { - Sprintf(buf, - "(Skill%s flagged by \"#\" cannot be enhanced any further.)", - plur(maxxed_cnt)); - add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, - buf, MENU_UNSELECTED); - } - add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, - "", MENU_UNSELECTED); - } + /* start with a legend if any entries will be annotated + with "*" or "#" below */ + if (eventually_advance > 0 || maxxed_cnt > 0) { + any = zeroany; + if (eventually_advance > 0) { + Sprintf(buf, "(Skill%s flagged by \"*\" may be enhanced %s.)", + plur(eventually_advance), + (u.ulevel < MAXULEV) + ? "when you're more experienced" + : "if skill slots become available"); + add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + } + if (maxxed_cnt > 0) { + Sprintf(buf, "(Skill%s flagged by \"#\" cannot be enhanced " + "any further.)", + plur(maxxed_cnt)); + add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + } + add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", + MENU_UNSELECTED); + } - /* List the skills, making ones that could be advanced - selectable. List the miscellaneous skills first. - Possible future enhancement: list spell skills before - weapon skills for spellcaster roles. */ - for (pass = 0; pass < SIZE(skill_ranges); pass++) - for (i = skill_ranges[pass].first; - i <= skill_ranges[pass].last; i++) { - /* Print headings for skill types */ - any = zeroany; - if (i == skill_ranges[pass].first) - add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, - skill_ranges[pass].name, MENU_UNSELECTED); + /* List the skills, making ones that could be advanced + selectable. List the miscellaneous skills first. + Possible future enhancement: list spell skills before + weapon skills for spellcaster roles. */ + for (pass = 0; pass < SIZE(skill_ranges); pass++) + for (i = skill_ranges[pass].first; i <= skill_ranges[pass].last; + i++) { + /* Print headings for skill types */ + any = zeroany; + if (i == skill_ranges[pass].first) + add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, + skill_ranges[pass].name, MENU_UNSELECTED); - if (P_RESTRICTED(i)) continue; - /* - * Sigh, this assumes a monospaced font unless - * iflags.menu_tab_sep is set in which case it puts - * tabs between columns. - * The 12 is the longest skill level name. - * The " " is room for a selection letter and dash, "a - ". - */ - if (can_advance(i, speedy)) - prefix = ""; /* will be preceded by menu choice */ - else if (could_advance(i)) - prefix = " * "; - else if (peaked_skill(i)) - prefix = " # "; - else - prefix = (to_advance + eventually_advance + - maxxed_cnt > 0) ? " " : ""; - (void) skill_level_name(i, sklnambuf); - if (wizard) { - if (!iflags.menu_tab_sep) - Sprintf(buf, " %s%-*s %-12s %5d(%4d)", - prefix, longest, P_NAME(i), sklnambuf, - P_ADVANCE(i), - practice_needed_to_advance(P_SKILL(i))); - else - Sprintf(buf, " %s%s\t%s\t%5d(%4d)", - prefix, P_NAME(i), sklnambuf, - P_ADVANCE(i), - practice_needed_to_advance(P_SKILL(i))); - } else { - if (!iflags.menu_tab_sep) - Sprintf(buf, " %s %-*s [%s]", - prefix, longest, P_NAME(i), sklnambuf); - else - Sprintf(buf, " %s%s\t[%s]", - prefix, P_NAME(i), sklnambuf); - } - any.a_int = can_advance(i, speedy) ? i+1 : 0; - add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, - buf, MENU_UNSELECTED); - } + if (P_RESTRICTED(i)) + continue; + /* + * Sigh, this assumes a monospaced font unless + * iflags.menu_tab_sep is set in which case it puts + * tabs between columns. + * The 12 is the longest skill level name. + * The " " is room for a selection letter and dash, "a - ". + */ + if (can_advance(i, speedy)) + prefix = ""; /* will be preceded by menu choice */ + else if (could_advance(i)) + prefix = " * "; + else if (peaked_skill(i)) + prefix = " # "; + else + prefix = + (to_advance + eventually_advance + maxxed_cnt > 0) + ? " " + : ""; + (void) skill_level_name(i, sklnambuf); + if (wizard) { + if (!iflags.menu_tab_sep) + Sprintf(buf, " %s%-*s %-12s %5d(%4d)", prefix, + longest, P_NAME(i), sklnambuf, P_ADVANCE(i), + practice_needed_to_advance(P_SKILL(i))); + else + Sprintf(buf, " %s%s\t%s\t%5d(%4d)", prefix, P_NAME(i), + sklnambuf, P_ADVANCE(i), + practice_needed_to_advance(P_SKILL(i))); + } else { + if (!iflags.menu_tab_sep) + Sprintf(buf, " %s %-*s [%s]", prefix, longest, + P_NAME(i), sklnambuf); + else + Sprintf(buf, " %s%s\t[%s]", prefix, P_NAME(i), + sklnambuf); + } + any.a_int = can_advance(i, speedy) ? i + 1 : 0; + add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, + MENU_UNSELECTED); + } - Strcpy(buf, (to_advance > 0) ? "Pick a skill to advance:" : - "Current skills:"); - if (wizard && !speedy) - Sprintf(eos(buf), " (%d slot%s available)", - u.weapon_slots, plur(u.weapon_slots)); - end_menu(win, buf); - n = select_menu(win, to_advance ? PICK_ONE : PICK_NONE, &selected); - destroy_nhwindow(win); - if (n > 0) { - n = selected[0].item.a_int - 1; /* get item selected */ - free((genericptr_t)selected); - skill_advance(n); - /* check for more skills able to advance, if so then .. */ - for (n = i = 0; i < P_NUM_SKILLS; i++) { - if (can_advance(i, speedy)) { - if (!speedy) You_feel("you could be more dangerous!"); - n++; - break; - } - } - } - } while (speedy && n > 0); - return 0; + Strcpy(buf, (to_advance > 0) ? "Pick a skill to advance:" + : "Current skills:"); + if (wizard && !speedy) + Sprintf(eos(buf), " (%d slot%s available)", u.weapon_slots, + plur(u.weapon_slots)); + end_menu(win, buf); + n = select_menu(win, to_advance ? PICK_ONE : PICK_NONE, &selected); + destroy_nhwindow(win); + if (n > 0) { + n = selected[0].item.a_int - 1; /* get item selected */ + free((genericptr_t) selected); + skill_advance(n); + /* check for more skills able to advance, if so then .. */ + for (n = i = 0; i < P_NUM_SKILLS; i++) { + if (can_advance(i, speedy)) { + if (!speedy) + You_feel("you could be more dangerous!"); + n++; + break; + } + } + } + } while (speedy && n > 0); + return 0; } /* @@ -1021,63 +1078,66 @@ unrestrict_weapon_skill(skill) int skill; { if (skill < P_NUM_SKILLS && P_RESTRICTED(skill)) { - P_SKILL(skill) = P_UNSKILLED; - P_MAX_SKILL(skill) = P_BASIC; - P_ADVANCE(skill) = 0; + P_SKILL(skill) = P_UNSKILLED; + P_MAX_SKILL(skill) = P_BASIC; + P_ADVANCE(skill) = 0; } } void -use_skill(skill,degree) +use_skill(skill, degree) int skill; int degree; { boolean advance_before; if (skill != P_NONE && !P_RESTRICTED(skill)) { - advance_before = can_advance(skill, FALSE); - P_ADVANCE(skill)+=degree; - if (!advance_before && can_advance(skill, FALSE)) - give_may_advance_msg(skill); + advance_before = can_advance(skill, FALSE); + P_ADVANCE(skill) += degree; + if (!advance_before && can_advance(skill, FALSE)) + give_may_advance_msg(skill); } } void add_weapon_skill(n) -int n; /* number of slots to gain; normally one */ +int n; /* number of slots to gain; normally one */ { int i, before, after; for (i = 0, before = 0; i < P_NUM_SKILLS; i++) - if (can_advance(i, FALSE)) before++; + if (can_advance(i, FALSE)) + before++; u.weapon_slots += n; for (i = 0, after = 0; i < P_NUM_SKILLS; i++) - if (can_advance(i, FALSE)) after++; + if (can_advance(i, FALSE)) + after++; if (before < after) - give_may_advance_msg(P_NONE); + give_may_advance_msg(P_NONE); } void lose_weapon_skill(n) -int n; /* number of slots to lose; normally one */ +int n; /* number of slots to lose; normally one */ { int skill; while (--n >= 0) { - /* deduct first from unused slots, then from last placed slot, if any */ - if (u.weapon_slots) { - u.weapon_slots--; - } else if (u.skills_advanced) { - skill = u.skill_record[--u.skills_advanced]; - if (P_SKILL(skill) <= P_UNSKILLED) - panic("lose_weapon_skill (%d)", skill); - P_SKILL(skill)--; /* drop skill one level */ - /* Lost skill might have taken more than one slot; refund rest. */ - u.weapon_slots = slots_required(skill) - 1; - /* It might now be possible to advance some other pending - skill by using the refunded slots, but giving a message - to that effect would seem pretty confusing.... */ - } + /* deduct first from unused slots, then from last placed slot, if any + */ + if (u.weapon_slots) { + u.weapon_slots--; + } else if (u.skills_advanced) { + skill = u.skill_record[--u.skills_advanced]; + if (P_SKILL(skill) <= P_UNSKILLED) + panic("lose_weapon_skill (%d)", skill); + P_SKILL(skill)--; /* drop skill one level */ + /* Lost skill might have taken more than one slot; refund rest. */ + u.weapon_slots = slots_required(skill) - 1; + /* It might now be possible to advance some other pending + skill by using the refunded slots, but giving a message + to that effect would seem pretty confusing.... */ + } } } @@ -1085,26 +1145,26 @@ int weapon_type(obj) struct obj *obj; { - /* KMH -- now uses the object table */ - int type; + /* KMH -- now uses the object table */ + int type; - if (!obj) - /* Not using a weapon */ - return (P_BARE_HANDED_COMBAT); - if (obj->oclass != WEAPON_CLASS && obj->oclass != TOOL_CLASS && - obj->oclass != GEM_CLASS) - /* Not a weapon, weapon-tool, or ammo */ - return (P_NONE); - type = objects[obj->otyp].oc_skill; - return ((type < 0) ? -type : type); + if (!obj) + /* Not using a weapon */ + return (P_BARE_HANDED_COMBAT); + if (obj->oclass != WEAPON_CLASS && obj->oclass != TOOL_CLASS + && obj->oclass != GEM_CLASS) + /* Not a weapon, weapon-tool, or ammo */ + return (P_NONE); + type = objects[obj->otyp].oc_skill; + return ((type < 0) ? -type : type); } int uwep_skill_type() { - if (u.twoweap) - return P_TWO_WEAPON_COMBAT; - return weapon_type(uwep); + if (u.twoweap) + return P_TWO_WEAPON_COMBAT; + return weapon_type(uwep); } /* @@ -1119,57 +1179,85 @@ struct obj *weapon; static const char bad_skill[] = "weapon_hit_bonus: bad skill %d"; wep_type = weapon_type(weapon); - /* use two weapon skill only if attacking with one of the wielded weapons */ - type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) ? - P_TWO_WEAPON_COMBAT : wep_type; + /* use two weapon skill only if attacking with one of the wielded weapons + */ + type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) + ? P_TWO_WEAPON_COMBAT + : wep_type; if (type == P_NONE) { - bonus = 0; + bonus = 0; } else if (type <= P_LAST_WEAPON) { - switch (P_SKILL(type)) { - default: impossible(bad_skill, P_SKILL(type)); /* fall through */ - case P_ISRESTRICTED: - case P_UNSKILLED: bonus = -4; break; - case P_BASIC: bonus = 0; break; - case P_SKILLED: bonus = 2; break; - case P_EXPERT: bonus = 3; break; - } + switch (P_SKILL(type)) { + default: + impossible(bad_skill, P_SKILL(type)); /* fall through */ + case P_ISRESTRICTED: + case P_UNSKILLED: + bonus = -4; + break; + case P_BASIC: + bonus = 0; + break; + case P_SKILLED: + bonus = 2; + break; + case P_EXPERT: + bonus = 3; + break; + } } else if (type == P_TWO_WEAPON_COMBAT) { - skill = P_SKILL(P_TWO_WEAPON_COMBAT); - if (P_SKILL(wep_type) < skill) skill = P_SKILL(wep_type); - switch (skill) { - default: impossible(bad_skill, skill); /* fall through */ - case P_ISRESTRICTED: - case P_UNSKILLED: bonus = -9; break; - case P_BASIC: bonus = -7; break; - case P_SKILLED: bonus = -5; break; - case P_EXPERT: bonus = -3; break; - } + skill = P_SKILL(P_TWO_WEAPON_COMBAT); + if (P_SKILL(wep_type) < skill) + skill = P_SKILL(wep_type); + switch (skill) { + default: + impossible(bad_skill, skill); /* fall through */ + case P_ISRESTRICTED: + case P_UNSKILLED: + bonus = -9; + break; + case P_BASIC: + bonus = -7; + break; + case P_SKILLED: + bonus = -5; + break; + case P_EXPERT: + bonus = -3; + break; + } } else if (type == P_BARE_HANDED_COMBAT) { - /* - * b.h. m.a. - * unskl: +1 n/a - * basic: +1 +3 - * skild: +2 +4 - * exprt: +2 +5 - * mastr: +3 +6 - * grand: +3 +7 - */ - bonus = P_SKILL(type); - bonus = max(bonus,P_UNSKILLED) - 1; /* unskilled => 0 */ - bonus = ((bonus + 2) * (martial_bonus() ? 2 : 1)) / 2; + /* + * b.h. m.a. + * unskl: +1 n/a + * basic: +1 +3 + * skild: +2 +4 + * exprt: +2 +5 + * mastr: +3 +6 + * grand: +3 +7 + */ + bonus = P_SKILL(type); + bonus = max(bonus, P_UNSKILLED) - 1; /* unskilled => 0 */ + bonus = ((bonus + 2) * (martial_bonus() ? 2 : 1)) / 2; } - /* KMH -- It's harder to hit while you are riding */ - if (u.usteed) { - switch (P_SKILL(P_RIDING)) { - case P_ISRESTRICTED: - case P_UNSKILLED: bonus -= 2; break; - case P_BASIC: bonus -= 1; break; - case P_SKILLED: break; - case P_EXPERT: break; - } - if (u.twoweap) bonus -= 2; - } + /* KMH -- It's harder to hit while you are riding */ + if (u.usteed) { + switch (P_SKILL(P_RIDING)) { + case P_ISRESTRICTED: + case P_UNSKILLED: + bonus -= 2; + break; + case P_BASIC: + bonus -= 1; + break; + case P_SKILLED: + break; + case P_EXPERT: + break; + } + if (u.twoweap) + bonus -= 2; + } return bonus; } @@ -1185,57 +1273,83 @@ struct obj *weapon; int type, wep_type, skill, bonus = 0; wep_type = weapon_type(weapon); - /* use two weapon skill only if attacking with one of the wielded weapons */ - type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) ? - P_TWO_WEAPON_COMBAT : wep_type; + /* use two weapon skill only if attacking with one of the wielded weapons + */ + type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) + ? P_TWO_WEAPON_COMBAT + : wep_type; if (type == P_NONE) { - bonus = 0; + bonus = 0; } else if (type <= P_LAST_WEAPON) { - switch (P_SKILL(type)) { - default: impossible("weapon_dam_bonus: bad skill %d",P_SKILL(type)); - /* fall through */ - case P_ISRESTRICTED: - case P_UNSKILLED: bonus = -2; break; - case P_BASIC: bonus = 0; break; - case P_SKILLED: bonus = 1; break; - case P_EXPERT: bonus = 2; break; - } + switch (P_SKILL(type)) { + default: + impossible("weapon_dam_bonus: bad skill %d", P_SKILL(type)); + /* fall through */ + case P_ISRESTRICTED: + case P_UNSKILLED: + bonus = -2; + break; + case P_BASIC: + bonus = 0; + break; + case P_SKILLED: + bonus = 1; + break; + case P_EXPERT: + bonus = 2; + break; + } } else if (type == P_TWO_WEAPON_COMBAT) { - skill = P_SKILL(P_TWO_WEAPON_COMBAT); - if (P_SKILL(wep_type) < skill) skill = P_SKILL(wep_type); - switch (skill) { - default: - case P_ISRESTRICTED: - case P_UNSKILLED: bonus = -3; break; - case P_BASIC: bonus = -1; break; - case P_SKILLED: bonus = 0; break; - case P_EXPERT: bonus = 1; break; - } + skill = P_SKILL(P_TWO_WEAPON_COMBAT); + if (P_SKILL(wep_type) < skill) + skill = P_SKILL(wep_type); + switch (skill) { + default: + case P_ISRESTRICTED: + case P_UNSKILLED: + bonus = -3; + break; + case P_BASIC: + bonus = -1; + break; + case P_SKILLED: + bonus = 0; + break; + case P_EXPERT: + bonus = 1; + break; + } } else if (type == P_BARE_HANDED_COMBAT) { - /* - * b.h. m.a. - * unskl: 0 n/a - * basic: +1 +3 - * skild: +1 +4 - * exprt: +2 +6 - * mastr: +2 +7 - * grand: +3 +9 - */ - bonus = P_SKILL(type); - bonus = max(bonus,P_UNSKILLED) - 1; /* unskilled => 0 */ - bonus = ((bonus + 1) * (martial_bonus() ? 3 : 1)) / 2; + /* + * b.h. m.a. + * unskl: 0 n/a + * basic: +1 +3 + * skild: +1 +4 + * exprt: +2 +6 + * mastr: +2 +7 + * grand: +3 +9 + */ + bonus = P_SKILL(type); + bonus = max(bonus, P_UNSKILLED) - 1; /* unskilled => 0 */ + bonus = ((bonus + 1) * (martial_bonus() ? 3 : 1)) / 2; } - /* KMH -- Riding gives some thrusting damage */ - if (u.usteed && type != P_TWO_WEAPON_COMBAT) { - switch (P_SKILL(P_RIDING)) { - case P_ISRESTRICTED: - case P_UNSKILLED: break; - case P_BASIC: break; - case P_SKILLED: bonus += 1; break; - case P_EXPERT: bonus += 2; break; - } - } + /* KMH -- Riding gives some thrusting damage */ + if (u.usteed && type != P_TWO_WEAPON_COMBAT) { + switch (P_SKILL(P_RIDING)) { + case P_ISRESTRICTED: + case P_UNSKILLED: + break; + case P_BASIC: + break; + case P_SKILLED: + bonus += 1; + break; + case P_EXPERT: + bonus += 2; + break; + } + } return bonus; } @@ -1250,83 +1364,85 @@ void skill_init(class_skill) const struct def_skill *class_skill; { - struct obj *obj; - int skmax, skill; + struct obj *obj; + int skmax, skill; - /* initialize skill array; by default, everything is restricted */ - for (skill = 0; skill < P_NUM_SKILLS; skill++) { - P_SKILL(skill) = P_ISRESTRICTED; - P_MAX_SKILL(skill) = P_ISRESTRICTED; - P_ADVANCE(skill) = 0; - } + /* initialize skill array; by default, everything is restricted */ + for (skill = 0; skill < P_NUM_SKILLS; skill++) { + P_SKILL(skill) = P_ISRESTRICTED; + P_MAX_SKILL(skill) = P_ISRESTRICTED; + P_ADVANCE(skill) = 0; + } - /* Set skill for all weapons in inventory to be basic */ - for (obj = invent; obj; obj = obj->nobj) { - /* don't give skill just because of carried ammo, wait until - we see the relevant launcher (prevents an archeologist's - touchstone from inadvertently providing skill in sling) */ - if (is_ammo(obj)) continue; + /* Set skill for all weapons in inventory to be basic */ + for (obj = invent; obj; obj = obj->nobj) { + /* don't give skill just because of carried ammo, wait until + we see the relevant launcher (prevents an archeologist's + touchstone from inadvertently providing skill in sling) */ + if (is_ammo(obj)) + continue; - skill = weapon_type(obj); - if (skill != P_NONE) - P_SKILL(skill) = P_BASIC; - } + skill = weapon_type(obj); + if (skill != P_NONE) + P_SKILL(skill) = P_BASIC; + } - /* set skills for magic */ - if (Role_if(PM_HEALER) || Role_if(PM_MONK)) { - P_SKILL(P_HEALING_SPELL) = P_BASIC; - } else if (Role_if(PM_PRIEST)) { - P_SKILL(P_CLERIC_SPELL) = P_BASIC; - } else if (Role_if(PM_WIZARD)) { - P_SKILL(P_ATTACK_SPELL) = P_BASIC; - P_SKILL(P_ENCHANTMENT_SPELL) = P_BASIC; - } + /* set skills for magic */ + if (Role_if(PM_HEALER) || Role_if(PM_MONK)) { + P_SKILL(P_HEALING_SPELL) = P_BASIC; + } else if (Role_if(PM_PRIEST)) { + P_SKILL(P_CLERIC_SPELL) = P_BASIC; + } else if (Role_if(PM_WIZARD)) { + P_SKILL(P_ATTACK_SPELL) = P_BASIC; + P_SKILL(P_ENCHANTMENT_SPELL) = P_BASIC; + } - /* walk through array to set skill maximums */ - for (; class_skill->skill != P_NONE; class_skill++) { - skmax = class_skill->skmax; - skill = class_skill->skill; + /* walk through array to set skill maximums */ + for (; class_skill->skill != P_NONE; class_skill++) { + skmax = class_skill->skmax; + skill = class_skill->skill; - P_MAX_SKILL(skill) = skmax; - if (P_SKILL(skill) == P_ISRESTRICTED) /* skill pre-set */ - P_SKILL(skill) = P_UNSKILLED; - } + P_MAX_SKILL(skill) = skmax; + if (P_SKILL(skill) == P_ISRESTRICTED) /* skill pre-set */ + P_SKILL(skill) = P_UNSKILLED; + } - /* High potential fighters already know how to use their hands. */ - if (P_MAX_SKILL(P_BARE_HANDED_COMBAT) > P_EXPERT) - P_SKILL(P_BARE_HANDED_COMBAT) = P_BASIC; + /* High potential fighters already know how to use their hands. */ + if (P_MAX_SKILL(P_BARE_HANDED_COMBAT) > P_EXPERT) + P_SKILL(P_BARE_HANDED_COMBAT) = P_BASIC; - /* Roles that start with a horse know how to ride it */ - if (urole.petnum == PM_PONY) - P_SKILL(P_RIDING) = P_BASIC; + /* Roles that start with a horse know how to ride it */ + if (urole.petnum == PM_PONY) + P_SKILL(P_RIDING) = P_BASIC; - /* - * Make sure we haven't missed setting the max on a skill - * & set advance - */ - for (skill = 0; skill < P_NUM_SKILLS; skill++) { - if (!P_RESTRICTED(skill)) { - if (P_MAX_SKILL(skill) < P_SKILL(skill)) { - impossible("skill_init: curr > max: %s", P_NAME(skill)); - P_MAX_SKILL(skill) = P_SKILL(skill); - } - P_ADVANCE(skill) = practice_needed_to_advance(P_SKILL(skill)-1); - } - } + /* + * Make sure we haven't missed setting the max on a skill + * & set advance + */ + for (skill = 0; skill < P_NUM_SKILLS; skill++) { + if (!P_RESTRICTED(skill)) { + if (P_MAX_SKILL(skill) < P_SKILL(skill)) { + impossible("skill_init: curr > max: %s", P_NAME(skill)); + P_MAX_SKILL(skill) = P_SKILL(skill); + } + P_ADVANCE(skill) = practice_needed_to_advance(P_SKILL(skill) - 1); + } + } } void -setmnotwielded(mon,obj) +setmnotwielded(mon, obj) register struct monst *mon; register struct obj *obj; { - if (!obj) return; + if (!obj) + return; if (artifact_light(obj) && obj->lamplit) { - end_burn(obj, FALSE); - if (canseemon(mon)) - pline("%s in %s %s %s shining.", The(xname(obj)), - s_suffix(mon_nam(mon)), mbodypart(mon,HAND), - otense(obj, "stop")); + end_burn(obj, FALSE); + if (canseemon(mon)) + pline("%s in %s %s %s shining.", The(xname(obj)), + s_suffix(mon_nam(mon)), mbodypart(mon, HAND), + otense(obj, "stop")); } obj->owornmask &= ~W_WEP; } diff --git a/src/were.c b/src/were.c index e7e91a567..9c1c3c38f 100644 --- a/src/were.c +++ b/src/were.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 were.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 were.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ /* NetHack 3.6 were.c $Date: 2011/02/28 11:29:27 $ $Revision: 1.14 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,44 +9,57 @@ void were_change(mon) register struct monst *mon; { - if (!is_were(mon->data)) - return; + if (!is_were(mon->data)) + return; - if (is_human(mon->data)) { - if (!Protection_from_shape_changers && - !rn2(night() ? (flags.moonphase == FULL_MOON ? 3 : 30) - : (flags.moonphase == FULL_MOON ? 10 : 50))) { - new_were(mon); /* change into animal form */ - if (!Deaf && !canseemon(mon)) { - const char *howler; + if (is_human(mon->data)) { + if (!Protection_from_shape_changers + && !rn2(night() ? (flags.moonphase == FULL_MOON ? 3 : 30) + : (flags.moonphase == FULL_MOON ? 10 : 50))) { + new_were(mon); /* change into animal form */ + if (!Deaf && !canseemon(mon)) { + const char *howler; - switch (monsndx(mon->data)) { - case PM_WEREWOLF: howler = "wolf"; break; - case PM_WEREJACKAL: howler = "jackal"; break; - default: howler = (char *)0; break; - } - if (howler) - You_hear("a %s howling at the moon.", howler); - } - } - } else if (!rn2(30) || Protection_from_shape_changers) { - new_were(mon); /* change back into human form */ - } + switch (monsndx(mon->data)) { + case PM_WEREWOLF: + howler = "wolf"; + break; + case PM_WEREJACKAL: + howler = "jackal"; + break; + default: + howler = (char *) 0; + break; + } + if (howler) + You_hear("a %s howling at the moon.", howler); + } + } + } else if (!rn2(30) || Protection_from_shape_changers) { + new_were(mon); /* change back into human form */ + } } int counter_were(pm) int pm; { - switch(pm) { - case PM_WEREWOLF: return(PM_HUMAN_WEREWOLF); - case PM_HUMAN_WEREWOLF: return(PM_WEREWOLF); - case PM_WEREJACKAL: return(PM_HUMAN_WEREJACKAL); - case PM_HUMAN_WEREJACKAL: return(PM_WEREJACKAL); - case PM_WERERAT: return(PM_HUMAN_WERERAT); - case PM_HUMAN_WERERAT: return(PM_WERERAT); - default: return NON_PM; - } + switch (pm) { + case PM_WEREWOLF: + return (PM_HUMAN_WEREWOLF); + case PM_HUMAN_WEREWOLF: + return (PM_WEREWOLF); + case PM_WEREJACKAL: + return (PM_HUMAN_WEREJACKAL); + case PM_HUMAN_WEREJACKAL: + return (PM_WEREJACKAL); + case PM_WERERAT: + return (PM_HUMAN_WERERAT); + case PM_HUMAN_WERERAT: + return (PM_WERERAT); + default: + return NON_PM; + } } /* convert monsters similar to werecritters into appropriate werebeast */ @@ -59,19 +72,19 @@ int pm; case PM_SEWER_RAT: case PM_GIANT_RAT: case PM_RABID_RAT: - return PM_WERERAT; + return PM_WERERAT; case PM_WEREJACKAL: case PM_JACKAL: case PM_FOX: case PM_COYOTE: - return PM_WEREJACKAL; + return PM_WEREJACKAL; case PM_WEREWOLF: case PM_WOLF: case PM_WARG: case PM_WINTER_WOLF: - return PM_WEREWOLF; + return PM_WEREWOLF; default: - break; + break; } return NON_PM; } @@ -80,108 +93,113 @@ void new_were(mon) register struct monst *mon; { - register int pm; + register int pm; - pm = counter_were(monsndx(mon->data)); - if (pm < LOW_PM) { - impossible("unknown lycanthrope %s.", mon->data->mname); - return; - } + pm = counter_were(monsndx(mon->data)); + if (pm < LOW_PM) { + impossible("unknown lycanthrope %s.", mon->data->mname); + return; + } - if(canseemon(mon) && !Hallucination) - pline("%s changes into a %s.", Monnam(mon), - is_human(&mons[pm]) ? "human" : - mons[pm].mname+4); + if (canseemon(mon) && !Hallucination) + pline("%s changes into a %s.", Monnam(mon), + is_human(&mons[pm]) ? "human" : mons[pm].mname + 4); - set_mon_data(mon, &mons[pm], 0); - if (mon->msleeping || !mon->mcanmove) { - /* transformation wakens and/or revitalizes */ - mon->msleeping = 0; - mon->mfrozen = 0; /* not asleep or paralyzed */ - mon->mcanmove = 1; - } - /* regenerate by 1/4 of the lost hit points */ - mon->mhp += (mon->mhpmax - mon->mhp) / 4; - newsym(mon->mx,mon->my); - mon_break_armor(mon, FALSE); - possibly_unwield(mon, FALSE); + set_mon_data(mon, &mons[pm], 0); + if (mon->msleeping || !mon->mcanmove) { + /* transformation wakens and/or revitalizes */ + mon->msleeping = 0; + mon->mfrozen = 0; /* not asleep or paralyzed */ + mon->mcanmove = 1; + } + /* regenerate by 1/4 of the lost hit points */ + mon->mhp += (mon->mhpmax - mon->mhp) / 4; + newsym(mon->mx, mon->my); + mon_break_armor(mon, FALSE); + possibly_unwield(mon, FALSE); } -int -were_summon(ptr,yours,visible,genbuf) /* were-creature (even you) summons a horde */ +int were_summon(ptr, yours, visible, + genbuf) /* were-creature (even you) summons a horde */ register struct permonst *ptr; register boolean yours; -int *visible; /* number of visible helpers created */ +int *visible; /* number of visible helpers created */ char *genbuf; { - register int i, typ, pm = monsndx(ptr); - register struct monst *mtmp; - int total = 0; + register int i, typ, pm = monsndx(ptr); + register struct monst *mtmp; + int total = 0; - *visible = 0; - if(Protection_from_shape_changers && !yours) - return 0; - for(i = rnd(5); i > 0; i--) { - switch(pm) { - - case PM_WERERAT: - case PM_HUMAN_WERERAT: - typ = rn2(3) ? PM_SEWER_RAT : rn2(3) ? PM_GIANT_RAT : PM_RABID_RAT ; - if (genbuf) Strcpy(genbuf, "rat"); - break; - case PM_WEREJACKAL: - case PM_HUMAN_WEREJACKAL: - typ = PM_JACKAL; - if (genbuf) Strcpy(genbuf, "jackal"); - break; - case PM_WEREWOLF: - case PM_HUMAN_WEREWOLF: - typ = rn2(5) ? PM_WOLF : PM_WINTER_WOLF ; - if (genbuf) Strcpy(genbuf, "wolf"); - break; - default: - continue; - } - mtmp = makemon(&mons[typ], u.ux, u.uy, NO_MM_FLAGS); - if (mtmp) { - total++; - if (canseemon(mtmp)) *visible += 1; - } - if (yours && mtmp) - (void) tamedog(mtmp, (struct obj *) 0); - } - return total; + *visible = 0; + if (Protection_from_shape_changers && !yours) + return 0; + for (i = rnd(5); i > 0; i--) { + switch (pm) { + case PM_WERERAT: + case PM_HUMAN_WERERAT: + typ = + rn2(3) ? PM_SEWER_RAT : rn2(3) ? PM_GIANT_RAT : PM_RABID_RAT; + if (genbuf) + Strcpy(genbuf, "rat"); + break; + case PM_WEREJACKAL: + case PM_HUMAN_WEREJACKAL: + typ = PM_JACKAL; + if (genbuf) + Strcpy(genbuf, "jackal"); + break; + case PM_WEREWOLF: + case PM_HUMAN_WEREWOLF: + typ = rn2(5) ? PM_WOLF : PM_WINTER_WOLF; + if (genbuf) + Strcpy(genbuf, "wolf"); + break; + default: + continue; + } + mtmp = makemon(&mons[typ], u.ux, u.uy, NO_MM_FLAGS); + if (mtmp) { + total++; + if (canseemon(mtmp)) + *visible += 1; + } + if (yours && mtmp) + (void) tamedog(mtmp, (struct obj *) 0); + } + return total; } void you_were() { - char qbuf[QBUFSZ]; - boolean controllable_poly = Polymorph_control && !(Stunned || Unaware); + char qbuf[QBUFSZ]; + boolean controllable_poly = Polymorph_control && !(Stunned || Unaware); - if (Unchanging || (u.umonnum == u.ulycn)) return; - if (controllable_poly) { - /* `+4' => skip "were" prefix to get name of beast */ - Sprintf(qbuf, "Do you want to change into %s?", - an(mons[u.ulycn].mname+4)); - if(yn(qbuf) == 'n') return; - } - (void) polymon(u.ulycn); + if (Unchanging || (u.umonnum == u.ulycn)) + return; + if (controllable_poly) { + /* `+4' => skip "were" prefix to get name of beast */ + Sprintf(qbuf, "Do you want to change into %s?", + an(mons[u.ulycn].mname + 4)); + if (yn(qbuf) == 'n') + return; + } + (void) polymon(u.ulycn); } void you_unwere(purify) boolean purify; { - boolean controllable_poly = Polymorph_control && !(Stunned || Unaware); + boolean controllable_poly = Polymorph_control && !(Stunned || Unaware); - if (purify) { - You_feel("purified."); - u.ulycn = NON_PM; /* cure lycanthropy */ - } - if (!Unchanging && is_were(youmonst.data) && - (!controllable_poly || yn("Remain in beast form?") == 'n')) - rehumanize(); + if (purify) { + You_feel("purified."); + u.ulycn = NON_PM; /* cure lycanthropy */ + } + if (!Unchanging && is_were(youmonst.data) + && (!controllable_poly || yn("Remain in beast form?") == 'n')) + rehumanize(); } /*were.c*/ diff --git a/src/wield.c b/src/wield.c index 62117dc90..f863b66f0 100644 --- a/src/wield.c +++ b/src/wield.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wield.c $NHDT-Date: 1427062304 2015/03/22 22:11:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ +/* NetHack 3.6 wield.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */ /* NetHack 3.6 wield.c $Date: 2009/05/06 10:48:14 $ $Revision: 1.31 $ */ /* SCCS Id: @(#)wield.c 3.5 2009/01/20 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -51,22 +51,18 @@ * No item may be in more than one of these slots. */ - STATIC_DCL boolean FDECL(cant_wield_corpse, (struct obj *)); STATIC_DCL int FDECL(ready_weapon, (struct obj *)); /* used by will_weld() */ /* probably should be renamed */ -#define erodeable_wep(optr) ((optr)->oclass == WEAPON_CLASS \ - || is_weptool(optr) \ - || (optr)->otyp == HEAVY_IRON_BALL \ - || (optr)->otyp == IRON_CHAIN) +#define erodeable_wep(optr) \ + ((optr)->oclass == WEAPON_CLASS || is_weptool(optr) \ + || (optr)->otyp == HEAVY_IRON_BALL || (optr)->otyp == IRON_CHAIN) /* used by welded(), and also while wielding */ -#define will_weld(optr) ((optr)->cursed \ - && (erodeable_wep(optr) \ - || (optr)->otyp == TIN_OPENER)) - +#define will_weld(optr) \ + ((optr)->cursed && (erodeable_wep(optr) || (optr)->otyp == TIN_OPENER)) /*** Functions that place a given item in a slot ***/ /* Proper usage includes: @@ -87,111 +83,113 @@ void setuwep(obj) register struct obj *obj; { - struct obj *olduwep = uwep; + 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 shining.", 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(); + 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 shining.", 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(); } STATIC_OVL boolean cant_wield_corpse(obj) struct obj *obj; { - char kbuf[BUFSZ]; + char kbuf[BUFSZ]; - if (uarmg || obj->otyp != CORPSE || - !touch_petrifies(&mons[obj->corpsenm]) || Stone_resistance) - return FALSE; + if (uarmg || obj->otyp != CORPSE || !touch_petrifies(&mons[obj->corpsenm]) + || Stone_resistance) + return FALSE; - /* Prevent wielding cockatrice when not wearing gloves --KAA */ - You("wield %s in your bare %s.", - corpse_xname(obj, (const char *)0, CXN_PFX_THE), - makeplural(body_part(HAND))); - Sprintf(kbuf, "wielding %s bare-handed", killer_xname(obj)); - instapetrify(kbuf); - return TRUE; + /* Prevent wielding cockatrice when not wearing gloves --KAA */ + You("wield %s in your bare %s.", + corpse_xname(obj, (const char *) 0, CXN_PFX_THE), + makeplural(body_part(HAND))); + Sprintf(kbuf, "wielding %s bare-handed", killer_xname(obj)); + instapetrify(kbuf); + return TRUE; } STATIC_OVL int ready_weapon(wep) struct obj *wep; { - /* Separated function so swapping works easily */ - int res = 0; + /* Separated function so swapping works easily */ + int res = 0; - if (!wep) { - /* No weapon */ - if (uwep) { - You("are empty %s.", body_part(HANDED)); - setuwep((struct obj *) 0); - res++; - } else - You("are already empty %s.", body_part(HANDED)); - } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) { - /* hero must have been life-saved to get here; use a turn */ - res++; /* corpse won't be wielded */ - } else if (uarms && bimanual(wep)) { - You("cannot wield a two-handed %s while wearing a shield.", - is_sword(wep) ? "sword" : - wep->otyp == BATTLE_AXE ? "axe" : "weapon"); - } else if (!retouch_object(&wep, FALSE)) { - res++; /* takes a turn even though it doesn't get wielded */ - } else { - /* Weapon WILL be wielded after this point */ - res++; - if (will_weld(wep)) { - const char *tmp = xname(wep), *thestr = "The "; - if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp),thestr,4)) - tmp = thestr; - else tmp = ""; - pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"), - (wep->quan == 1L) ? "itself" : "themselves", /* a3 */ - bimanual(wep) ? - (const char *)makeplural(body_part(HAND)) - : body_part(HAND)); - wep->bknown = TRUE; - } else { - /* The message must be printed before setuwep (since - * you might die and be revived from changing weapons), - * and the message must be before the death message and - * Lifesaved rewielding. Yet we want the message to - * say "weapon in hand", thus this kludge. - */ - long dummy = wep->owornmask; - wep->owornmask |= W_WEP; - prinv((char *)0, wep, 0L); - wep->owornmask = dummy; - } - setuwep(wep); + if (!wep) { + /* No weapon */ + if (uwep) { + You("are empty %s.", body_part(HANDED)); + setuwep((struct obj *) 0); + res++; + } else + You("are already empty %s.", body_part(HANDED)); + } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) { + /* hero must have been life-saved to get here; use a turn */ + res++; /* corpse won't be wielded */ + } else if (uarms && bimanual(wep)) { + You("cannot wield a two-handed %s while wearing a shield.", + is_sword(wep) ? "sword" : wep->otyp == BATTLE_AXE ? "axe" + : "weapon"); + } else if (!retouch_object(&wep, FALSE)) { + res++; /* takes a turn even though it doesn't get wielded */ + } else { + /* Weapon WILL be wielded after this point */ + res++; + if (will_weld(wep)) { + const char *tmp = xname(wep), *thestr = "The "; + if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp), thestr, 4)) + tmp = thestr; + else + tmp = ""; + pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"), + (wep->quan == 1L) ? "itself" : "themselves", /* a3 */ + bimanual(wep) ? (const char *) makeplural(body_part(HAND)) + : body_part(HAND)); + wep->bknown = TRUE; + } else { + /* The message must be printed before setuwep (since + * you might die and be revived from changing weapons), + * and the message must be before the death message and + * Lifesaved rewielding. Yet we want the message to + * say "weapon in hand", thus this kludge. + */ + long dummy = wep->owornmask; + wep->owornmask |= W_WEP; + prinv((char *) 0, wep, 0L); + wep->owornmask = dummy; + } + setuwep(wep); - /* KMH -- Talking artifacts are finally implemented */ - arti_speak(wep); + /* KMH -- Talking artifacts are finally implemented */ + arti_speak(wep); - if (artifact_light(wep) && !wep->lamplit) { - begin_burn(wep, FALSE); - if (!Blind) - pline("%s to shine %s!", Tobjnam(wep, "begin"), - arti_light_description(wep)); - } + if (artifact_light(wep) && !wep->lamplit) { + begin_burn(wep, FALSE); + if (!Blind) + pline("%s to shine %s!", Tobjnam(wep, "begin"), + arti_light_description(wep)); + } #if 0 /* we'll get back to this someday, but it's not balanced yet */ @@ -203,345 +201,352 @@ struct obj *wep; } #endif - if (wep->unpaid) { - struct monst *this_shkp; + if (wep->unpaid) { + struct monst *this_shkp; - if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy))) != - (struct monst *)0) { - pline("%s says \"You be careful with my %s!\"", - shkname(this_shkp), - xname(wep)); - } - } - } - return(res); + if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy))) + != (struct monst *) 0) { + pline("%s says \"You be careful with my %s!\"", + shkname(this_shkp), xname(wep)); + } + } + } + return (res); } void setuqwep(obj) register struct obj *obj; { - setworn(obj, W_QUIVER); - update_inventory(); + setworn(obj, W_QUIVER); + update_inventory(); } void setuswapwep(obj) register struct obj *obj; { - setworn(obj, W_SWAPWEP); - update_inventory(); + setworn(obj, W_SWAPWEP); + update_inventory(); } - /*** Commands to change particular slot(s) ***/ -static NEARDATA const char wield_objs[] = - { ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, TOOL_CLASS, 0 }; -static NEARDATA const char ready_objs[] = - { COIN_CLASS, ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, 0 }; -static NEARDATA const char bullets[] = /* (note: different from dothrow.c) */ - { COIN_CLASS, ALL_CLASSES, ALLOW_NONE, GEM_CLASS, WEAPON_CLASS, 0 }; +static NEARDATA const char wield_objs[] = { ALL_CLASSES, ALLOW_NONE, + WEAPON_CLASS, TOOL_CLASS, 0 }; +static NEARDATA const char ready_objs[] = { COIN_CLASS, ALL_CLASSES, + ALLOW_NONE, WEAPON_CLASS, 0 }; +static NEARDATA const char bullets[] = /* (note: different from dothrow.c) */ + { COIN_CLASS, ALL_CLASSES, ALLOW_NONE, GEM_CLASS, WEAPON_CLASS, 0 }; int dowield() { - register struct obj *wep, *oldwep; - int result; + register struct obj *wep, *oldwep; + int result; - /* May we attempt this? */ - multi = 0; - if (cantwield(youmonst.data)) { - pline("Don't be ridiculous!"); - return(0); - } + /* May we attempt this? */ + multi = 0; + if (cantwield(youmonst.data)) { + pline("Don't be ridiculous!"); + return (0); + } - /* Prompt for a new weapon */ - if (!(wep = getobj(wield_objs, "wield"))) - /* Cancelled */ - return (0); - else if (wep == uwep) { - You("are already wielding that!"); - if (is_weptool(wep)) unweapon = FALSE; /* [see setuwep()] */ - return (0); - } else if (welded(uwep)) { - weldmsg(uwep); - /* previously interrupted armor removal mustn't be resumed */ - reset_remarm(); - return (0); - } + /* Prompt for a new weapon */ + if (!(wep = getobj(wield_objs, "wield"))) + /* Cancelled */ + return (0); + else if (wep == uwep) { + You("are already wielding that!"); + if (is_weptool(wep)) + unweapon = FALSE; /* [see setuwep()] */ + return (0); + } else if (welded(uwep)) { + weldmsg(uwep); + /* previously interrupted armor removal mustn't be resumed */ + reset_remarm(); + return (0); + } - /* Handle no object, or object in other slot */ - if (wep == &zeroobj) - wep = (struct obj *) 0; - else if (wep == uswapwep) - return (doswapweapon()); - else if (wep == uquiver) - setuqwep((struct obj *) 0); - else if (wep->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_SADDLE)) { - You("cannot wield that!"); - return (0); - } + /* Handle no object, or object in other slot */ + if (wep == &zeroobj) + wep = (struct obj *) 0; + else if (wep == uswapwep) + return (doswapweapon()); + else if (wep == uquiver) + setuqwep((struct obj *) 0); + else if (wep->owornmask + & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_SADDLE)) { + You("cannot wield that!"); + return (0); + } - /* Set your new primary weapon */ - oldwep = uwep; - result = ready_weapon(wep); - if (flags.pushweapon && oldwep && uwep != oldwep) - setuswapwep(oldwep); - untwoweapon(); + /* Set your new primary weapon */ + oldwep = uwep; + result = ready_weapon(wep); + if (flags.pushweapon && oldwep && uwep != oldwep) + setuswapwep(oldwep); + untwoweapon(); - return (result); + return (result); } int doswapweapon() { - register struct obj *oldwep, *oldswap; - int result = 0; + register struct obj *oldwep, *oldswap; + int result = 0; + /* May we attempt this? */ + multi = 0; + if (cantwield(youmonst.data)) { + pline("Don't be ridiculous!"); + return (0); + } + if (welded(uwep)) { + weldmsg(uwep); + return (0); + } - /* May we attempt this? */ - multi = 0; - if (cantwield(youmonst.data)) { - pline("Don't be ridiculous!"); - return(0); - } - if (welded(uwep)) { - weldmsg(uwep); - return (0); - } + /* Unwield your current secondary weapon */ + oldwep = uwep; + oldswap = uswapwep; + setuswapwep((struct obj *) 0); - /* Unwield your current secondary weapon */ - oldwep = uwep; - oldswap = uswapwep; - setuswapwep((struct obj *) 0); + /* Set your new primary weapon */ + result = ready_weapon(oldswap); - /* Set your new primary weapon */ - result = ready_weapon(oldswap); + /* Set your new secondary weapon */ + if (uwep == oldwep) + /* Wield failed for some reason */ + setuswapwep(oldswap); + else { + setuswapwep(oldwep); + if (uswapwep) + prinv((char *) 0, uswapwep, 0L); + else + You("have no secondary weapon readied."); + } - /* Set your new secondary weapon */ - if (uwep == oldwep) - /* Wield failed for some reason */ - setuswapwep(oldswap); - else { - setuswapwep(oldwep); - if (uswapwep) - prinv((char *)0, uswapwep, 0L); - else - You("have no secondary weapon readied."); - } + if (u.twoweap && !can_twoweapon()) + untwoweapon(); - if (u.twoweap && !can_twoweapon()) - untwoweapon(); - - return (result); + return (result); } int dowieldquiver() { - register struct obj *newquiver; - const char *quivee_types = (uslinging() || - (uswapwep && objects[uswapwep->otyp].oc_skill == P_SLING)) ? - bullets : ready_objs; + register struct obj *newquiver; + const char *quivee_types = + (uslinging() + || (uswapwep && objects[uswapwep->otyp].oc_skill == P_SLING)) + ? bullets + : ready_objs; - /* Since the quiver isn't in your hands, don't check cantwield(), */ - /* will_weld(), touch_petrifies(), etc. */ - multi = 0; + /* Since the quiver isn't in your hands, don't check cantwield(), */ + /* will_weld(), touch_petrifies(), etc. */ + multi = 0; - /* Prompt for a new quiver */ - if (!(newquiver = getobj(quivee_types, "ready"))) - /* Cancelled */ - return (0); + /* Prompt for a new quiver */ + if (!(newquiver = getobj(quivee_types, "ready"))) + /* Cancelled */ + return (0); - /* Handle no object, or object in other slot */ - /* Any type is okay, since we give no intrinsics anyways */ - if (newquiver == &zeroobj) { - /* Explicitly nothing */ - if (uquiver) { - You("now have no ammunition readied."); - setuqwep(newquiver = (struct obj *) 0); - } else { - You("already have no ammunition readied!"); - return(0); - } - } else if (newquiver == uquiver) { - pline("That ammunition is already readied!"); - return(0); - } else if (newquiver == uwep) { - /* Prevent accidentally readying the main weapon */ - pline("%s already being used as a weapon!", - !is_plural(uwep) ? "That is" : "They are"); - return(0); - } else if (newquiver->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL - | W_SADDLE)) { - You("cannot ready that!"); - return (0); - } else { - long dummy; + /* Handle no object, or object in other slot */ + /* Any type is okay, since we give no intrinsics anyways */ + if (newquiver == &zeroobj) { + /* Explicitly nothing */ + if (uquiver) { + You("now have no ammunition readied."); + setuqwep(newquiver = (struct obj *) 0); + } else { + You("already have no ammunition readied!"); + return (0); + } + } else if (newquiver == uquiver) { + pline("That ammunition is already readied!"); + return (0); + } else if (newquiver == uwep) { + /* Prevent accidentally readying the main weapon */ + pline("%s already being used as a weapon!", + !is_plural(uwep) ? "That is" : "They are"); + return (0); + } else if (newquiver->owornmask + & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_SADDLE)) { + You("cannot ready that!"); + return (0); + } else { + long dummy; + /* Check if it's the secondary weapon */ + if (newquiver == uswapwep) { + setuswapwep((struct obj *) 0); + untwoweapon(); + } - /* Check if it's the secondary weapon */ - if (newquiver == uswapwep) { - setuswapwep((struct obj *) 0); - untwoweapon(); - } + /* Okay to put in quiver; print it */ + dummy = newquiver->owornmask; + newquiver->owornmask |= W_QUIVER; + prinv((char *) 0, newquiver, 0L); + newquiver->owornmask = dummy; + } - /* Okay to put in quiver; print it */ - dummy = newquiver->owornmask; - newquiver->owornmask |= W_QUIVER; - prinv((char *)0, newquiver, 0L); - newquiver->owornmask = dummy; - } - - /* Finally, place it in the quiver */ - setuqwep(newquiver); - /* Take no time since this is a convenience slot */ - return (0); + /* Finally, place it in the quiver */ + setuqwep(newquiver); + /* Take no time since this is a convenience slot */ + return (0); } -/* used for #rub and for applying pick-axe, whip, grappling hook, or polearm */ +/* used for #rub and for applying pick-axe, whip, grappling hook, or polearm + */ /* (moved from apply.c) */ boolean wield_tool(obj, verb) struct obj *obj; -const char *verb; /* "rub",&c */ +const char *verb; /* "rub",&c */ { const char *what; boolean more_than_1; - if (obj == uwep) return TRUE; /* nothing to do if already wielding it */ + if (obj == uwep) + return TRUE; /* nothing to do if already wielding it */ - if (!verb) verb = "wield"; + if (!verb) + verb = "wield"; what = xname(obj); - more_than_1 = (obj->quan > 1L || - strstri(what, "pair of ") != 0 || - strstri(what, "s of ") != 0); + more_than_1 = (obj->quan > 1L || strstri(what, "pair of ") != 0 + || strstri(what, "s of ") != 0); - if (obj->owornmask & (W_ARMOR|W_RING|W_AMUL|W_TOOL)) { - You_cant("%s %s while wearing %s.", - verb, yname(obj), more_than_1 ? "them" : "it"); - return FALSE; + if (obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) { + You_cant("%s %s while wearing %s.", verb, yname(obj), + more_than_1 ? "them" : "it"); + return FALSE; } if (welded(uwep)) { - if (flags.verbose) { - const char *hand = body_part(HAND); + if (flags.verbose) { + const char *hand = body_part(HAND); - if (bimanual(uwep)) hand = makeplural(hand); - if (strstri(what, "pair of ") != 0) more_than_1 = FALSE; - pline( - "Since your weapon is welded to your %s, you cannot %s %s %s.", - hand, verb, more_than_1 ? "those" : "that", xname(obj)); - } else { - You_cant("do that."); - } - return FALSE; + if (bimanual(uwep)) + hand = makeplural(hand); + if (strstri(what, "pair of ") != 0) + more_than_1 = FALSE; + pline("Since your weapon is welded to your %s, you cannot %s %s " + "%s.", + hand, verb, more_than_1 ? "those" : "that", xname(obj)); + } else { + You_cant("do that."); + } + return FALSE; } if (cantwield(youmonst.data)) { - You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it"); - return FALSE; + You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it"); + return FALSE; } /* check shield */ if (uarms && bimanual(obj)) { - You("cannot %s a two-handed %s while wearing a shield.", - verb, (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool"); - return FALSE; + You("cannot %s a two-handed %s while wearing a shield.", verb, + (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool"); + return FALSE; } - if (uquiver == obj) setuqwep((struct obj *)0); + if (uquiver == obj) + setuqwep((struct obj *) 0); if (uswapwep == obj) { - (void) doswapweapon(); - /* doswapweapon might fail */ - if (uswapwep == obj) return FALSE; + (void) doswapweapon(); + /* doswapweapon might fail */ + if (uswapwep == obj) + return FALSE; } else { - struct obj *oldwep = uwep; + struct obj *oldwep = uwep; - You("now wield %s.", doname(obj)); - setuwep(obj); - if (flags.pushweapon && oldwep && uwep != oldwep) - setuswapwep(oldwep); + You("now wield %s.", doname(obj)); + setuwep(obj); + if (flags.pushweapon && oldwep && uwep != oldwep) + setuswapwep(oldwep); } - if (uwep != obj) return FALSE; /* rewielded old object after dying */ + if (uwep != obj) + return FALSE; /* rewielded old object after dying */ /* applying weapon or tool that gets wielded ends two-weapon combat */ if (u.twoweap) - untwoweapon(); + untwoweapon(); if (obj->oclass != WEAPON_CLASS) - unweapon = TRUE; + unweapon = TRUE; return TRUE; } int can_twoweapon() { - struct obj *otmp; + struct obj *otmp; #define NOT_WEAPON(obj) (!is_weptool(obj) && obj->oclass != WEAPON_CLASS) - if (!could_twoweap(youmonst.data)) { - if (Upolyd) - You_cant("use two weapons in your current form."); - else - pline("%s aren't able to use two weapons at once.", - makeplural((flags.female && urole.name.f) ? - urole.name.f : urole.name.m)); - } else if (!uwep || !uswapwep) - Your("%s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "", - body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is"); - else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) { - otmp = NOT_WEAPON(uwep) ? uwep : uswapwep; - pline("%s %s.", Yname2(otmp), - is_plural(otmp) ? "aren't weapons" : "isn't a weapon"); - } else if (bimanual(uwep) || bimanual(uswapwep)) { - otmp = bimanual(uwep) ? uwep : uswapwep; - pline("%s isn't one-handed.", Yname2(otmp)); - } else if (uarms) - You_cant("use two weapons while wearing a shield."); - else if (uswapwep->oartifact) - pline("%s being held second to another weapon!", - Yobjnam2(uswapwep, "resist")); - else if (uswapwep->otyp == CORPSE && cant_wield_corpse(uswapwep)) { - /* [Note: NOT_WEAPON() check prevents ever getting here...] */ - ; /* must be life-saved to reach here; return FALSE */ - } else if (Glib || uswapwep->cursed) { - if (!Glib) - uswapwep->bknown = TRUE; - drop_uswapwep(); - } else - return (TRUE); - return (FALSE); + if (!could_twoweap(youmonst.data)) { + if (Upolyd) + You_cant("use two weapons in your current form."); + else + pline("%s aren't able to use two weapons at once.", + makeplural((flags.female && urole.name.f) ? urole.name.f + : urole.name.m)); + } else if (!uwep || !uswapwep) + Your("%s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "", + body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is"); + else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) { + otmp = NOT_WEAPON(uwep) ? uwep : uswapwep; + pline("%s %s.", Yname2(otmp), + is_plural(otmp) ? "aren't weapons" : "isn't a weapon"); + } else if (bimanual(uwep) || bimanual(uswapwep)) { + otmp = bimanual(uwep) ? uwep : uswapwep; + pline("%s isn't one-handed.", Yname2(otmp)); + } else if (uarms) + You_cant("use two weapons while wearing a shield."); + else if (uswapwep->oartifact) + pline("%s being held second to another weapon!", + Yobjnam2(uswapwep, "resist")); + else if (uswapwep->otyp == CORPSE && cant_wield_corpse(uswapwep)) { + /* [Note: NOT_WEAPON() check prevents ever getting here...] */ + ; /* must be life-saved to reach here; return FALSE */ + } else if (Glib || uswapwep->cursed) { + if (!Glib) + uswapwep->bknown = TRUE; + drop_uswapwep(); + } else + return (TRUE); + return (FALSE); } void drop_uswapwep() { - char str[BUFSZ]; - struct obj *obj = uswapwep; + char str[BUFSZ]; + struct obj *obj = uswapwep; - /* Avoid trashing makeplural's static buffer */ - Strcpy(str, makeplural(body_part(HAND))); - pline("%s from your %s!", Yobjnam2(obj, "slip"), str); - dropx(obj); + /* Avoid trashing makeplural's static buffer */ + Strcpy(str, makeplural(body_part(HAND))); + pline("%s from your %s!", Yobjnam2(obj, "slip"), str); + dropx(obj); } int dotwoweapon() { - /* You can always toggle it off */ - if (u.twoweap) { - You("switch to your primary weapon."); - u.twoweap = 0; - update_inventory(); - return (0); - } + /* You can always toggle it off */ + if (u.twoweap) { + You("switch to your primary weapon."); + u.twoweap = 0; + update_inventory(); + return (0); + } - /* May we use two weapons? */ - if (can_twoweapon()) { - /* Success! */ - You("begin two-weapon combat."); - u.twoweap = 1; - update_inventory(); - return (rnd(20) > ACURR(A_DEX)); - } - return (0); + /* May we use two weapons? */ + if (can_twoweapon()) { + /* Success! */ + You("begin two-weapon combat."); + u.twoweap = 1; + update_inventory(); + return (rnd(20) > ACURR(A_DEX)); + } + return (0); } /*** Functions to empty a given slot ***/ @@ -553,44 +558,45 @@ dotwoweapon() void uwepgone() { - if (uwep) { - if (artifact_light(uwep) && uwep->lamplit) { - end_burn(uwep, FALSE); - if (!Blind) pline("%s shining.", Tobjnam(uwep, "stop")); - } - setworn((struct obj *)0, W_WEP); - unweapon = TRUE; - update_inventory(); - } + if (uwep) { + if (artifact_light(uwep) && uwep->lamplit) { + end_burn(uwep, FALSE); + if (!Blind) + pline("%s shining.", Tobjnam(uwep, "stop")); + } + setworn((struct obj *) 0, W_WEP); + unweapon = TRUE; + update_inventory(); + } } void uswapwepgone() { - if (uswapwep) { - setworn((struct obj *)0, W_SWAPWEP); - update_inventory(); - } + if (uswapwep) { + setworn((struct obj *) 0, W_SWAPWEP); + update_inventory(); + } } void uqwepgone() { - if (uquiver) { - setworn((struct obj *)0, W_QUIVER); - update_inventory(); - } + if (uquiver) { + setworn((struct obj *) 0, W_QUIVER); + update_inventory(); + } } void untwoweapon() { - if (u.twoweap) { - You("can no longer use two weapons at once."); - u.twoweap = FALSE; - update_inventory(); - } - return; + if (u.twoweap) { + You("can no longer use two weapons at once."); + u.twoweap = FALSE; + update_inventory(); + } + return; } int @@ -598,137 +604,145 @@ chwepon(otmp, amount) register struct obj *otmp; register int amount; { - const char *color = hcolor((amount < 0) ? NH_BLACK : NH_BLUE); - const char *xtime, *wepname = ""; - boolean multiple; - int otyp = STRANGE_OBJECT; + const char *color = hcolor((amount < 0) ? NH_BLACK : NH_BLUE); + const char *xtime, *wepname = ""; + boolean multiple; + int otyp = STRANGE_OBJECT; - if(!uwep || (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))) { - char buf[BUFSZ]; + if (!uwep || (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))) { + char buf[BUFSZ]; - Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)), - (amount >= 0) ? "twitch" : "itch"); - strange_feeling(otmp, buf); - exercise(A_DEX, (boolean) (amount >= 0)); - return(0); - } + Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)), + (amount >= 0) ? "twitch" : "itch"); + strange_feeling(otmp, buf); + exercise(A_DEX, (boolean)(amount >= 0)); + return (0); + } - if (otmp && otmp->oclass == SCROLL_CLASS) otyp = otmp->otyp; + if (otmp && otmp->oclass == SCROLL_CLASS) + otyp = otmp->otyp; - if (uwep->otyp == WORM_TOOTH && amount >= 0) { - multiple = (uwep->quan > 1L); - /* order: message, transformation, shop handling */ - Your("%s %s much sharper now.", simpleonames(uwep), - multiple ? "fuse, and become" : "is"); - uwep->otyp = CRYSKNIFE; - uwep->oerodeproof = 0; - if (multiple) { - uwep->quan = 1L; - uwep->owt = weight(uwep); - } - if (uwep->cursed) uncurse(uwep); - /* update shop bill to reflect new higher value */ - if (uwep->unpaid) alter_cost(uwep, 0L); - if (otyp != STRANGE_OBJECT) makeknown(otyp); - if (multiple) encumber_msg(); - return 1; - } else if (uwep->otyp == CRYSKNIFE && amount < 0) { - multiple = (uwep->quan > 1L); - /* order matters: message, shop handling, transformation */ - Your("%s %s much duller now.", simpleonames(uwep), - multiple ? "fuse, and become" : "is"); - costly_alteration(uwep, COST_DEGRD); /* DECHNT? other? */ - uwep->otyp = WORM_TOOTH; - uwep->oerodeproof = 0; - if (multiple) { - uwep->quan = 1L; - uwep->owt = weight(uwep); - } - if (otyp != STRANGE_OBJECT && otmp->bknown) makeknown(otyp); - if (multiple) encumber_msg(); - return 1; - } + if (uwep->otyp == WORM_TOOTH && amount >= 0) { + multiple = (uwep->quan > 1L); + /* order: message, transformation, shop handling */ + Your("%s %s much sharper now.", simpleonames(uwep), + multiple ? "fuse, and become" : "is"); + uwep->otyp = CRYSKNIFE; + uwep->oerodeproof = 0; + if (multiple) { + uwep->quan = 1L; + uwep->owt = weight(uwep); + } + if (uwep->cursed) + uncurse(uwep); + /* update shop bill to reflect new higher value */ + if (uwep->unpaid) + alter_cost(uwep, 0L); + if (otyp != STRANGE_OBJECT) + makeknown(otyp); + if (multiple) + encumber_msg(); + return 1; + } else if (uwep->otyp == CRYSKNIFE && amount < 0) { + multiple = (uwep->quan > 1L); + /* order matters: message, shop handling, transformation */ + Your("%s %s much duller now.", simpleonames(uwep), + multiple ? "fuse, and become" : "is"); + costly_alteration(uwep, COST_DEGRD); /* DECHNT? other? */ + uwep->otyp = WORM_TOOTH; + uwep->oerodeproof = 0; + if (multiple) { + uwep->quan = 1L; + uwep->owt = weight(uwep); + } + if (otyp != STRANGE_OBJECT && otmp->bknown) + makeknown(otyp); + if (multiple) + encumber_msg(); + return 1; + } - if (has_oname(uwep)) - wepname = ONAME(uwep); - if (amount < 0 && uwep->oartifact && restrict_name(uwep, wepname)) { - if (!Blind) - pline("%s %s.", Yobjnam2(uwep, "faintly glow"), color); - return(1); - } - /* there is a (soft) upper and lower limit to uwep->spe */ - if(((uwep->spe > 5 && amount >= 0) || (uwep->spe < -5 && amount < 0)) - && rn2(3)) { - if (!Blind) - pline("%s %s for a while and then %s.", - Yobjnam2(uwep, "violently glow"), color, - otense(uwep, "evaporate")); - else - pline("%s.", Yobjnam2(uwep, "evaporate")); + if (has_oname(uwep)) + wepname = ONAME(uwep); + if (amount < 0 && uwep->oartifact && restrict_name(uwep, wepname)) { + if (!Blind) + pline("%s %s.", Yobjnam2(uwep, "faintly glow"), color); + return (1); + } + /* there is a (soft) upper and lower limit to uwep->spe */ + if (((uwep->spe > 5 && amount >= 0) || (uwep->spe < -5 && amount < 0)) + && rn2(3)) { + if (!Blind) + pline("%s %s for a while and then %s.", + Yobjnam2(uwep, "violently glow"), color, + otense(uwep, "evaporate")); + else + pline("%s.", Yobjnam2(uwep, "evaporate")); - useupall(uwep); /* let all of them disappear */ - return(1); - } - if (!Blind) { - xtime = (amount*amount == 1) ? "moment" : "while"; - pline("%s %s for a %s.", - Yobjnam2(uwep, amount == 0 ? "violently glow" : "glow"), - color, xtime); - if (otyp != STRANGE_OBJECT && uwep->known && - (amount > 0 || (amount < 0 && otmp->bknown))) - makeknown(otyp); - } - if (amount < 0) costly_alteration(uwep, COST_DECHNT); - uwep->spe += amount; - if (amount > 0) { - if (uwep->cursed) uncurse(uwep); - /* update shop bill to reflect new higher price */ - if (uwep->unpaid) alter_cost(uwep, 0L); - } + useupall(uwep); /* let all of them disappear */ + return (1); + } + if (!Blind) { + xtime = (amount * amount == 1) ? "moment" : "while"; + pline("%s %s for a %s.", + Yobjnam2(uwep, amount == 0 ? "violently glow" : "glow"), color, + xtime); + if (otyp != STRANGE_OBJECT && uwep->known + && (amount > 0 || (amount < 0 && otmp->bknown))) + makeknown(otyp); + } + if (amount < 0) + costly_alteration(uwep, COST_DECHNT); + uwep->spe += amount; + if (amount > 0) { + if (uwep->cursed) + uncurse(uwep); + /* update shop bill to reflect new higher price */ + if (uwep->unpaid) + alter_cost(uwep, 0L); + } - /* - * Enchantment, which normally improves a weapon, has an - * addition adverse reaction on Magicbane whose effects are - * spe dependent. Give an obscure clue here. - */ - if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) { - Your("right %s %sches!", - body_part(HAND), - (((amount > 1) && (uwep->spe > 1)) ? "flin" : "it")); - } + /* + * Enchantment, which normally improves a weapon, has an + * addition adverse reaction on Magicbane whose effects are + * spe dependent. Give an obscure clue here. + */ + if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) { + Your("right %s %sches!", body_part(HAND), + (((amount > 1) && (uwep->spe > 1)) ? "flin" : "it")); + } - /* an elven magic clue, cookie@keebler */ - /* elven weapons vibrate warningly when enchanted beyond a limit */ - if ((uwep->spe > 5) - && (is_elven_weapon(uwep) || uwep->oartifact || !rn2(7))) - pline("%s unexpectedly.", Yobjnam2(uwep, "suddenly vibrate")); + /* an elven magic clue, cookie@keebler */ + /* elven weapons vibrate warningly when enchanted beyond a limit */ + if ((uwep->spe > 5) + && (is_elven_weapon(uwep) || uwep->oartifact || !rn2(7))) + pline("%s unexpectedly.", Yobjnam2(uwep, "suddenly vibrate")); - return(1); + return (1); } int welded(obj) register struct obj *obj; { - if (obj && obj == uwep && will_weld(obj)) { - obj->bknown = TRUE; - return 1; - } - return 0; + if (obj && obj == uwep && will_weld(obj)) { + obj->bknown = TRUE; + return 1; + } + return 0; } void weldmsg(obj) register struct obj *obj; { - long savewornmask; + long savewornmask; - savewornmask = obj->owornmask; - pline("%s welded to your %s!", - Yobjnam2(obj, "are"), - bimanual(obj) ? (const char *)makeplural(body_part(HAND)) - : body_part(HAND)); - obj->owornmask = savewornmask; + savewornmask = obj->owornmask; + pline("%s welded to your %s!", Yobjnam2(obj, "are"), + bimanual(obj) ? (const char *) makeplural(body_part(HAND)) + : body_part(HAND)); + obj->owornmask = savewornmask; } /* test whether monster's wielded weapon is stuck to hand/paw/whatever */ @@ -737,7 +751,8 @@ mwelded(obj) struct obj *obj; { /* caller is responsible for making sure this is a monster's item */ - if (obj && (obj->owornmask & W_WEP) && will_weld(obj)) return TRUE; + if (obj && (obj->owornmask & W_WEP) && will_weld(obj)) + return TRUE; return FALSE; } diff --git a/src/windows.c b/src/windows.c index a3ae3bf41..3b380d393 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 windows.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 windows.c $NHDT-Date: 1431192762 2015/05/09 17:32:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */ /* NetHack 3.6 windows.c $Date: 2012/01/23 10:45:28 $ $Revision: 1.23 $ */ /* Copyright (c) D. Cohrs, 1993. */ /* NetHack may be freely redistributed. See license for details. */ @@ -24,10 +24,11 @@ extern struct window_procs mac_procs; #endif #ifdef BEOS_GRAPHICS extern struct window_procs beos_procs; -extern void FDECL(be_win_init, (int)); FAIL /* be_win_init doesn't exist? XXX*/ +extern void FDECL(be_win_init, (int)); +FAIL /* be_win_init doesn't exist? XXX*/ #endif #ifdef AMIGA_INTUITION -extern struct window_procs amii_procs; + extern struct window_procs amii_procs; extern struct window_procs amiv_procs; extern void FDECL(ami_wininit_data, (int)); #endif @@ -60,20 +61,19 @@ STATIC_DCL void FDECL(def_raw_print, (const char *s)); #ifdef HANGUPHANDLING volatile #endif -NEARDATA struct window_procs windowprocs; + NEARDATA struct window_procs windowprocs; #ifdef WINCHAIN -# define CHAINR(x) ,x +#define CHAINR(x) , x #else -# define CHAINR(x) +#define CHAINR(x) #endif -static -struct win_choices { +static struct win_choices { struct window_procs *procs; - void FDECL((*ini_routine), (int)); /* optional (can be 0) */ + void FDECL((*ini_routine), (int)); /* optional (can be 0) */ #ifdef WINCHAIN - void *FDECL((*chain_routine),(int, int, void *, void *, void *)); + void *FDECL((*chain_routine), (int, int, void *, void *, void *)); #endif } winchoices[] = { #ifdef TTY_GRAPHICS @@ -95,8 +95,10 @@ struct win_choices { { &beos_procs, be_win_init CHAINR(0) }, #endif #ifdef AMIGA_INTUITION - { &amii_procs, ami_wininit_data CHAINR(0) }, /* Old font version of the game */ - { &amiv_procs, ami_wininit_data CHAINR(0) }, /* Tile version of the game */ + { &amii_procs, + ami_wininit_data CHAINR(0) }, /* Old font version of the game */ + { &amiv_procs, + ami_wininit_data CHAINR(0) }, /* Tile version of the game */ #endif #ifdef WIN32_GRAPHICS { &win32_procs, 0 CHAINR(0) }, @@ -109,49 +111,64 @@ struct win_choices { #endif #ifdef WINCHAIN { &chainin_procs, chainin_procs_init, chainin_procs_chain }, - { (struct window_procs *)&chainout_procs, chainout_procs_init, chainout_procs_chain }, + { (struct window_procs *) &chainout_procs, chainout_procs_init, + chainout_procs_chain }, - { (struct window_procs *)&trace_procs, trace_procs_init, trace_procs_chain }, + { (struct window_procs *) &trace_procs, trace_procs_init, + trace_procs_chain }, #endif - { 0, 0 CHAINR(0) } /* must be last */ + { 0, 0 CHAINR(0) } /* must be last */ }; #ifdef WINCHAIN struct winlink { - struct winlink *nextlink; - struct win_choices *wincp; - void *linkdata; + struct winlink *nextlink; + struct win_choices *wincp; + void *linkdata; }; /* NB: this chain does not contain the terminal real window system pointer */ static struct winlink *chain = 0; -static struct winlink *wl_new(){ - return calloc(1, sizeof(struct winlink)); +static struct winlink * +wl_new() +{ + return calloc(1, sizeof(struct winlink)); } -static void wl_addhead(struct winlink *wl){ - wl->nextlink = chain; - chain = wl; +static void +wl_addhead(struct winlink *wl) +{ + wl->nextlink = chain; + chain = wl; } -static void wl_addtail(struct winlink *wl){ - struct winlink *p = chain; +static void +wl_addtail(struct winlink *wl) +{ + struct winlink *p = chain; - if(!chain){ chain = wl; return; } - while(p->nextlink){ p=p->nextlink; } - p->nextlink = wl; - return; + if (!chain) { + chain = wl; + return; + } + while (p->nextlink) { + p = p->nextlink; + } + p->nextlink = wl; + return; } #endif static struct win_choices *last_winchoice = 0; boolean -genl_can_suspend_no(VOID_ARGS){ +genl_can_suspend_no(VOID_ARGS) +{ return FALSE; } boolean -genl_can_suspend_yes(VOID_ARGS){ +genl_can_suspend_yes(VOID_ARGS) +{ return TRUE; } @@ -170,14 +187,13 @@ const char *s; { register int i; - for(i=0; winchoices[i].procs; i++){ - if(!strcmpi(s, winchoices[i].procs->name)){ - return &winchoices[i]; - } + for (i = 0; winchoices[i].procs; i++) { + if (!strcmpi(s, winchoices[i].procs->name)) { + return &winchoices[i]; + } } return NULL; - } #endif @@ -187,42 +203,46 @@ const char *s; { register int i; - for(i=0; winchoices[i].procs; i++){ - if ('+' == winchoices[i].procs->name[0]) continue; - if ('-' == winchoices[i].procs->name[0]) continue; - if (!strcmpi(s, winchoices[i].procs->name)) { - windowprocs = *winchoices[i].procs; + for (i = 0; winchoices[i].procs; i++) { + if ('+' == winchoices[i].procs->name[0]) + continue; + if ('-' == winchoices[i].procs->name[0]) + continue; + if (!strcmpi(s, winchoices[i].procs->name)) { + windowprocs = *winchoices[i].procs; - if (last_winchoice && last_winchoice->ini_routine) - (*last_winchoice->ini_routine)(WININIT_UNDO); - if (winchoices[i].ini_routine) - (*winchoices[i].ini_routine)(WININIT); - last_winchoice = &winchoices[i]; - return; - } + if (last_winchoice && last_winchoice->ini_routine) + (*last_winchoice->ini_routine)(WININIT_UNDO); + if (winchoices[i].ini_routine) + (*winchoices[i].ini_routine)(WININIT); + last_winchoice = &winchoices[i]; + return; + } } if (!windowprocs.win_raw_print) - windowprocs.win_raw_print = def_raw_print; + windowprocs.win_raw_print = def_raw_print; - if(!winchoices[0].procs){ - raw_printf("No window types?"); - exit(EXIT_FAILURE); + if (!winchoices[0].procs) { + raw_printf("No window types?"); + exit(EXIT_FAILURE); } - if(!winchoices[1].procs){ - raw_printf("Window type %s not recognized. The only choice is: %s.", - s, winchoices[0].procs->name); + if (!winchoices[1].procs) { + raw_printf("Window type %s not recognized. The only choice is: %s.", + s, winchoices[0].procs->name); } else { - raw_printf("Window type %s not recognized. Choices are:", s); - for(i=0; winchoices[i].procs; i++){ - if ('+' == winchoices[i].procs->name[0]) continue; - if ('-' == winchoices[i].procs->name[0]) continue; - raw_printf(" %s", winchoices[i].procs->name); - } + raw_printf("Window type %s not recognized. Choices are:", s); + for (i = 0; winchoices[i].procs; i++) { + if ('+' == winchoices[i].procs->name[0]) + continue; + if ('-' == winchoices[i].procs->name[0]) + continue; + raw_printf(" %s", winchoices[i].procs->name); + } } if (windowprocs.win_raw_print == def_raw_print) - terminate(EXIT_SUCCESS); + terminate(EXIT_SUCCESS); wait_synch(); } @@ -233,101 +253,100 @@ const char *s; { register int i; - for(i=0; winchoices[i].procs; i++) { - if ('+' != winchoices[i].procs->name[0]) continue; - if (!strcmpi(s, winchoices[i].procs->name)) { - struct winlink *p = wl_new(); - p->wincp = &winchoices[i]; - wl_addtail(p); - /* NB: The ini_routine() will be called during commit. */ - return; - } + for (i = 0; winchoices[i].procs; i++) { + if ('+' != winchoices[i].procs->name[0]) + continue; + if (!strcmpi(s, winchoices[i].procs->name)) { + struct winlink *p = wl_new(); + p->wincp = &winchoices[i]; + wl_addtail(p); + /* NB: The ini_routine() will be called during commit. */ + return; + } } windowprocs.win_raw_print = def_raw_print; raw_printf("Window processor %s not recognized. Choices are:", s); - for(i=0; winchoices[i].procs; i++) { - if ('+' != winchoices[i].procs->name[0]) continue; - raw_printf(" %s", winchoices[i].procs->name); + for (i = 0; winchoices[i].procs; i++) { + if ('+' != winchoices[i].procs->name[0]) + continue; + raw_printf(" %s", winchoices[i].procs->name); } exit(EXIT_FAILURE); } void -commit_windowchain(){ +commit_windowchain() +{ struct winlink *p; int n; int wincap, wincap2; - if(!chain) return; + if (!chain) + return; - /* Save wincap* from the real window system - we'll restore it below. */ + /* Save wincap* from the real window system - we'll restore it below. */ wincap = windowprocs.wincap; wincap2 = windowprocs.wincap2; - /* add -chainin at head and -chainout at tail */ - p=wl_new(); + /* add -chainin at head and -chainout at tail */ + p = wl_new(); p->wincp = win_choices_find("-chainin"); - if(! p->wincp){ - raw_printf("Can't locate processor '-chainin'"); - exit(EXIT_FAILURE); + if (!p->wincp) { + raw_printf("Can't locate processor '-chainin'"); + exit(EXIT_FAILURE); } wl_addhead(p); - p=wl_new(); + p = wl_new(); p->wincp = win_choices_find("-chainout"); - if(! p->wincp){ - raw_printf("Can't locate processor '-chainout'"); - exit(EXIT_FAILURE); + if (!p->wincp) { + raw_printf("Can't locate processor '-chainout'"); + exit(EXIT_FAILURE); } wl_addtail(p); - /* Now alloc() init() similar to Objective-C. */ - for(n=1,p=chain;p;n++,p=p->nextlink){ - p->linkdata = (*p->wincp->chain_routine)(WINCHAIN_ALLOC,n,0,0,0); + /* Now alloc() init() similar to Objective-C. */ + for (n = 1, p = chain; p; n++, p = p->nextlink) { + p->linkdata = (*p->wincp->chain_routine)(WINCHAIN_ALLOC, n, 0, 0, 0); } - for(n=1,p=chain;p;n++,p=p->nextlink){ - if(p->nextlink){ - (void)(*p->wincp->chain_routine)( - WINCHAIN_INIT,n, - p->linkdata,p->nextlink->wincp->procs, - p->nextlink->linkdata - ); - } else { - (void)(*p->wincp->chain_routine)( - WINCHAIN_INIT,n, - p->linkdata,last_winchoice->procs, - 0 - ); - } + for (n = 1, p = chain; p; n++, p = p->nextlink) { + if (p->nextlink) { + (void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata, + p->nextlink->wincp->procs, + p->nextlink->linkdata); + } else { + (void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata, + last_winchoice->procs, 0); + } } - /* Restore the saved wincap* values. We do it here to give the - * ini_routine()s a chance to change or check them. */ + /* Restore the saved wincap* values. We do it here to give the + * ini_routine()s a chance to change or check them. */ chain->wincp->procs->wincap = wincap; chain->wincp->procs->wincap2 = wincap2; - /* Call the init procs. Do not re-init the terminal real win. */ - p=chain; - while(p->nextlink){ - if(p->wincp->ini_routine){ - (*p->wincp->ini_routine)(WININIT); - } - p=p->nextlink; + /* Call the init procs. Do not re-init the terminal real win. */ + p = chain; + while (p->nextlink) { + if (p->wincp->ini_routine) { + (*p->wincp->ini_routine)(WININIT); + } + p = p->nextlink; } - /* Install the chain into window procs very late so ini_routine()s - * can raw_print on error. */ + /* Install the chain into window procs very late so ini_routine()s + * can raw_print on error. */ windowprocs = *chain->wincp->procs; - p=chain; - while(p){ - struct winlink *np = p->nextlink; - free(p); - p = np; /* assignment, not proof */ + p = chain; + while (p) { + struct winlink *np = p->nextlink; + free(p); + p = np; /* assignment, not proof */ } } #endif @@ -352,30 +371,30 @@ void genl_preference_update(pref) const char *pref UNUSED; { - /* window ports are expected to provide - their own preference update routine - for the preference capabilities that - they support. - Just return in this genl one. */ - return; + /* window ports are expected to provide + their own preference update routine + for the preference capabilities that + they support. + Just return in this genl one. */ + return; } char * genl_getmsghistory(init) boolean init UNUSED; { - /* window ports can provide - their own getmsghistory() routine to - preserve message history between games. - The routine is called repeatedly from - the core save routine, and the window - port is expected to successively return - each message that it wants saved, starting - with the oldest message first, finishing - with the most recent. - Return null pointer when finished. - */ - return (char *)0; + /* window ports can provide + their own getmsghistory() routine to + preserve message history between games. + The routine is called repeatedly from + the core save routine, and the window + port is expected to successively return + each message that it wants saved, starting + with the oldest message first, finishing + with the most recent. + Return null pointer when finished. + */ + return (char *) 0; } /*ARGSUSED*/ @@ -384,65 +403,65 @@ genl_putmsghistory(msg, is_restoring) const char *msg UNUSED; boolean is_restoring UNUSED; { - /* window ports can provide - their own putmsghistory() routine to - load message history from a saved game. - The routine is called repeatedly from - the core restore routine, starting with - the oldest saved message first, and - finishing with the latest. - The window port routine is expected to - load the message recall buffers in such - a way that the ordering is preserved. - The window port routine should make no - assumptions about how many messages are - forthcoming, nor should it assume that - another message will follow this one, - so it should keep all pointers/indexes - intact at the end of each call. - */ -#if 0 /* maybe... */ +/* window ports can provide + their own putmsghistory() routine to + load message history from a saved game. + The routine is called repeatedly from + the core restore routine, starting with + the oldest saved message first, and + finishing with the latest. + The window port routine is expected to + load the message recall buffers in such + a way that the ordering is preserved. + The window port routine should make no + assumptions about how many messages are + forthcoming, nor should it assume that + another message will follow this one, + so it should keep all pointers/indexes + intact at the end of each call. + */ +#if 0 /* maybe... */ if (!is_restoring) pline1("%s", msg); #endif - return; + return; } #ifdef HANGUPHANDLING - /* - * Dummy windowing scheme used to replace current one with no-ops - * in order to avoid all terminal I/O after hangup/disconnect. - */ +/* + * Dummy windowing scheme used to replace current one with no-ops + * in order to avoid all terminal I/O after hangup/disconnect. + */ static int NDECL(hup_nhgetch); -static char FDECL(hup_yn_function, (const char *,const char *,CHAR_P)); -static int FDECL(hup_nh_poskey, (int *,int *,int *)); -static void FDECL(hup_getlin, (const char *,char *)); -static void FDECL(hup_init_nhwindows, (int *,char **)); +static char FDECL(hup_yn_function, (const char *, const char *, CHAR_P)); +static int FDECL(hup_nh_poskey, (int *, int *, int *)); +static void FDECL(hup_getlin, (const char *, char *)); +static void FDECL(hup_init_nhwindows, (int *, char **)); static void FDECL(hup_exit_nhwindows, (const char *)); static winid FDECL(hup_create_nhwindow, (int)); -static int FDECL(hup_select_menu, (winid,int,MENU_ITEM_P **)); -static void FDECL(hup_add_menu, (winid,int,const anything *,CHAR_P,CHAR_P, - int,const char *,BOOLEAN_P)); -static void FDECL(hup_end_menu, (winid,const char *)); -static void FDECL(hup_putstr, (winid,int,const char *)); -static void FDECL(hup_print_glyph, (winid,XCHAR_P,XCHAR_P,int)); -static void FDECL(hup_outrip, (winid,int,time_t)); -static void FDECL(hup_curs, (winid,int,int)); -static void FDECL(hup_display_nhwindow, (winid,BOOLEAN_P)); -static void FDECL(hup_display_file, (const char *,BOOLEAN_P)); -# ifdef CLIPPING -static void FDECL(hup_cliparound, (int,int)); -# endif -# ifdef CHANGE_COLOR -static void FDECL(hup_change_color, (int,long,int)); -# ifdef MAC -static short FDECL(hup_set_font_name, (winid,char *)); -# endif +static int FDECL(hup_select_menu, (winid, int, MENU_ITEM_P **)); +static void FDECL(hup_add_menu, (winid, int, const anything *, CHAR_P, CHAR_P, + int, const char *, BOOLEAN_P)); +static void FDECL(hup_end_menu, (winid, const char *)); +static void FDECL(hup_putstr, (winid, int, const char *)); +static void FDECL(hup_print_glyph, (winid, XCHAR_P, XCHAR_P, int)); +static void FDECL(hup_outrip, (winid, int, time_t)); +static void FDECL(hup_curs, (winid, int, int)); +static void FDECL(hup_display_nhwindow, (winid, BOOLEAN_P)); +static void FDECL(hup_display_file, (const char *, BOOLEAN_P)); +#ifdef CLIPPING +static void FDECL(hup_cliparound, (int, int)); +#endif +#ifdef CHANGE_COLOR +static void FDECL(hup_change_color, (int, long, int)); +#ifdef MAC +static short FDECL(hup_set_font_name, (winid, char *)); +#endif static char *NDECL(hup_get_color_string); -# endif /* CHANGE_COLOR */ -# ifdef STATUS_VIA_WINDOWPORT -static void FDECL(hup_status_update, (int,genericptr_t,int,int)); -# endif +#endif /* CHANGE_COLOR */ +#ifdef STATUS_VIA_WINDOWPORT +static void FDECL(hup_status_update, (int, genericptr_t, int, int)); +#endif static int NDECL(hup_int_ndecl); static void NDECL(hup_void_ndecl); @@ -451,73 +470,54 @@ static void FDECL(hup_void_fdecl_winid, (winid)); static void FDECL(hup_void_fdecl_constchar_p, (const char *)); static struct window_procs hup_procs = { - "hup", - 0L, - 0L, - hup_init_nhwindows, - hup_void_ndecl, /* player_selection */ - hup_void_ndecl, /* askname */ - hup_void_ndecl, /* get_nh_event */ - hup_exit_nhwindows, - hup_void_fdecl_constchar_p, /* suspend_nhwindows */ - hup_void_ndecl, /* resume_nhwindows */ - hup_create_nhwindow, - hup_void_fdecl_winid, /* clear_nhwindow */ - hup_display_nhwindow, - hup_void_fdecl_winid, /* destroy_nhwindow */ - hup_curs, - hup_putstr, - hup_putstr, /* putmixed */ - hup_display_file, - hup_void_fdecl_winid, /* start_menu */ - hup_add_menu, - hup_end_menu, - hup_select_menu, - genl_message_menu, - hup_void_ndecl, /* update_inventory */ - hup_void_ndecl, /* mark_synch */ - hup_void_ndecl, /* wait_synch */ -# ifdef CLIPPING + "hup", 0L, 0L, hup_init_nhwindows, hup_void_ndecl, /* player_selection */ + hup_void_ndecl, /* askname */ + hup_void_ndecl, /* get_nh_event */ + hup_exit_nhwindows, hup_void_fdecl_constchar_p, /* suspend_nhwindows */ + hup_void_ndecl, /* resume_nhwindows */ + hup_create_nhwindow, hup_void_fdecl_winid, /* clear_nhwindow */ + hup_display_nhwindow, hup_void_fdecl_winid, /* destroy_nhwindow */ + hup_curs, hup_putstr, hup_putstr, /* putmixed */ + hup_display_file, hup_void_fdecl_winid, /* start_menu */ + hup_add_menu, hup_end_menu, hup_select_menu, genl_message_menu, + hup_void_ndecl, /* update_inventory */ + hup_void_ndecl, /* mark_synch */ + hup_void_ndecl, /* wait_synch */ +#ifdef CLIPPING hup_cliparound, -# endif -# ifdef POSITIONBAR - (void FDECL((*),(char *)))hup_void_fdecl_constchar_p, /* update_positionbar */ -# endif +#endif +#ifdef POSITIONBAR + (void FDECL( + (*), (char *))) hup_void_fdecl_constchar_p, /* update_positionbar */ +#endif hup_print_glyph, - hup_void_fdecl_constchar_p, /* raw_print */ - hup_void_fdecl_constchar_p, /* raw_print_bold */ - hup_nhgetch, - hup_nh_poskey, - hup_void_ndecl, /* nhbell */ - hup_int_ndecl, /* doprev_message */ - hup_yn_function, - hup_getlin, - hup_int_ndecl, /* get_ext_cmd */ - hup_void_fdecl_int, /* number_pad */ - hup_void_ndecl, /* delay_output */ -# ifdef CHANGE_COLOR + hup_void_fdecl_constchar_p, /* raw_print */ + hup_void_fdecl_constchar_p, /* raw_print_bold */ + hup_nhgetch, hup_nh_poskey, hup_void_ndecl, /* nhbell */ + hup_int_ndecl, /* doprev_message */ + hup_yn_function, hup_getlin, hup_int_ndecl, /* get_ext_cmd */ + hup_void_fdecl_int, /* number_pad */ + hup_void_ndecl, /* delay_output */ +#ifdef CHANGE_COLOR hup_change_color, -# ifdef MAC - hup_void_fdecl_int, /* change_background */ +#ifdef MAC + hup_void_fdecl_int, /* change_background */ hup_set_font_name, -# endif +#endif hup_get_color_string, -# endif /* CHANGE_COLOR */ - hup_void_ndecl, /* start_screen */ - hup_void_ndecl, /* end_screen */ - hup_outrip, - genl_preference_update, - genl_getmsghistory, +#endif /* CHANGE_COLOR */ + hup_void_ndecl, /* start_screen */ + hup_void_ndecl, /* end_screen */ + hup_outrip, genl_preference_update, genl_getmsghistory, genl_putmsghistory, -# ifdef STATUS_VIA_WINDOWPORT - hup_void_ndecl, /* status_init */ - hup_void_ndecl, /* status_finish */ - genl_status_enablefield, - hup_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_VIA_WINDOWPORT + hup_void_ndecl, /* status_init */ + hup_void_ndecl, /* status_finish */ + genl_status_enablefield, hup_status_update, +#ifdef STATUS_HILITES genl_status_threshold, -# endif -# endif /* STATUS_VIA_WINDOWPORT */ +#endif +#endif /* STATUS_VIA_WINDOWPORT */ genl_can_suspend_no, }; @@ -537,19 +537,19 @@ nhwindows_hangup() /* don't call exit_nhwindows() directly here; if a hangup occurs while interface code is executing, exit_nhwindows could knock the interface's active data structures out from under itself */ - if (iflags.window_inited && - windowprocs.win_exit_nhwindows != hup_exit_nhwindows) - previnterface_exit_nhwindows = windowprocs.win_exit_nhwindows; + if (iflags.window_inited + && windowprocs.win_exit_nhwindows != hup_exit_nhwindows) + previnterface_exit_nhwindows = windowprocs.win_exit_nhwindows; /* also, we have to leave the old interface's getmsghistory() in place because it will be called while saving the game */ if (windowprocs.win_getmsghistory != hup_procs.win_getmsghistory) - previnterface_getmsghistory = windowprocs.win_getmsghistory; + previnterface_getmsghistory = windowprocs.win_getmsghistory; windowprocs = hup_procs; if (previnterface_getmsghistory) - windowprocs.win_getmsghistory = previnterface_getmsghistory; + windowprocs.win_getmsghistory = previnterface_getmsghistory; } static void @@ -560,17 +560,17 @@ const char *lastgasp; shutdown routine now; xxx_exit_nhwindows() needs to call other xxx_ routines directly rather than through windowprocs pointers */ if (previnterface_exit_nhwindows) { - lastgasp = 0; /* don't want exit routine to attempt extra output */ - (*previnterface_exit_nhwindows)(lastgasp); - previnterface_exit_nhwindows = 0; + lastgasp = 0; /* don't want exit routine to attempt extra output */ + (*previnterface_exit_nhwindows)(lastgasp); + previnterface_exit_nhwindows = 0; } iflags.window_inited = 0; } static int -hup_nhgetch( VOID_ARGS ) +hup_nhgetch(VOID_ARGS) { - return '\033'; /* ESC */ + return '\033'; /* ESC */ } /*ARGSUSED*/ @@ -579,7 +579,8 @@ hup_yn_function(prompt, resp, deflt) const char *prompt UNUSED, *resp UNUSED; char deflt; { - if (!deflt) deflt = '\033'; + if (!deflt) + deflt = '\033'; return deflt; } @@ -706,7 +707,7 @@ boolean complain UNUSED; return; } -# ifdef CLIPPING +#ifdef CLIPPING /*ARGSUSED*/ static void hup_cliparound(x, y) @@ -714,9 +715,9 @@ int x UNUSED, y UNUSED; { return; } -# endif +#endif -# ifdef CHANGE_COLOR +#ifdef CHANGE_COLOR /*ARGSUSED*/ static void hup_change_color(color, rgb, reverse) @@ -726,7 +727,7 @@ long rgb; return; } -# ifdef MAC +#ifdef MAC /*ARGSUSED*/ static short hup_set_font_name(window, fontname) @@ -735,16 +736,16 @@ char *fontname; { return 0; } -# endif /* MAC */ +#endif /* MAC */ static char * hup_get_color_string(VOID_ARGS) { - return (char *)0; + return (char *) 0; } -# endif /* CHANGE_COLOR */ +#endif /* CHANGE_COLOR */ -# ifdef STATUS_VIA_WINDOWPORT +#ifdef STATUS_VIA_WINDOWPORT /*ARGSUSED*/ static void hup_status_update(idx, ptr, chg, percent) @@ -753,11 +754,11 @@ genericptr_t ptr UNUSED; { return; } -# endif /* STATUS_VIA_WINDOWPORT */ +#endif /* STATUS_VIA_WINDOWPORT */ - /* - * Non-specific stubs. - */ +/* + * Non-specific stubs. + */ static int hup_int_ndecl(VOID_ARGS) diff --git a/src/wizard.c b/src/wizard.c index 2aca29269..f4ee623cf 100644 --- a/src/wizard.c +++ b/src/wizard.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wizard.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wizard.c $NHDT-Date: 1431192761 2015/05/09 17:32:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.35 $ */ /* NetHack 3.6 wizard.c $Date: 2009/05/06 10:48:16 $ $Revision: 1.32 $ */ /* SCCS Id: @(#)wizard.c 3.5 2008/11/14 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -15,32 +15,28 @@ extern const int monstr[]; STATIC_DCL short FDECL(which_arti, (int)); -STATIC_DCL boolean FDECL(mon_has_arti, (struct monst *,SHORT_P)); -STATIC_DCL struct monst *FDECL(other_mon_has_arti, (struct monst *,SHORT_P)); +STATIC_DCL boolean FDECL(mon_has_arti, (struct monst *, SHORT_P)); +STATIC_DCL struct monst *FDECL(other_mon_has_arti, (struct monst *, SHORT_P)); STATIC_DCL struct obj *FDECL(on_ground, (SHORT_P)); STATIC_DCL boolean FDECL(you_have, (int)); -STATIC_DCL unsigned long FDECL(target_on, (int,struct monst *)); +STATIC_DCL unsigned long FDECL(target_on, (int, struct monst *)); STATIC_DCL unsigned long FDECL(strategy, (struct monst *)); static NEARDATA const int nasties[] = { - PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR, PM_RED_DRAGON, - PM_BLACK_DRAGON, PM_GREEN_DRAGON, PM_OWLBEAR, PM_PURPLE_WORM, - PM_ROCK_TROLL, PM_XAN, PM_GREMLIN, PM_UMBER_HULK, PM_VAMPIRE_LORD, - PM_XORN, PM_ZRUTY, PM_ELF_LORD, PM_ELVENKING, PM_YELLOW_DRAGON, - PM_LEOCROTTA, PM_BALUCHITHERIUM, PM_CARNIVOROUS_APE, PM_FIRE_GIANT, - PM_COUATL, PM_CAPTAIN, PM_WINGED_GARGOYLE, PM_MASTER_MIND_FLAYER, - PM_FIRE_ELEMENTAL, PM_JABBERWOCK, PM_ARCH_LICH, PM_OGRE_KING, - PM_OLOG_HAI, PM_IRON_GOLEM, PM_OCHRE_JELLY, PM_GREEN_SLIME, - PM_DISENCHANTER - }; + PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR, PM_RED_DRAGON, + PM_BLACK_DRAGON, PM_GREEN_DRAGON, PM_OWLBEAR, PM_PURPLE_WORM, + PM_ROCK_TROLL, PM_XAN, PM_GREMLIN, PM_UMBER_HULK, PM_VAMPIRE_LORD, + PM_XORN, PM_ZRUTY, PM_ELF_LORD, PM_ELVENKING, PM_YELLOW_DRAGON, + PM_LEOCROTTA, PM_BALUCHITHERIUM, PM_CARNIVOROUS_APE, PM_FIRE_GIANT, + PM_COUATL, PM_CAPTAIN, PM_WINGED_GARGOYLE, PM_MASTER_MIND_FLAYER, + PM_FIRE_ELEMENTAL, PM_JABBERWOCK, PM_ARCH_LICH, PM_OGRE_KING, PM_OLOG_HAI, + PM_IRON_GOLEM, PM_OCHRE_JELLY, PM_GREEN_SLIME, PM_DISENCHANTER +}; static NEARDATA const unsigned wizapp[] = { - PM_HUMAN, PM_WATER_DEMON, PM_VAMPIRE, - PM_RED_DRAGON, PM_TROLL, PM_UMBER_HULK, - PM_XORN, PM_XAN, PM_COCKATRICE, - PM_FLOATING_EYE, - PM_GUARDIAN_NAGA, - PM_TRAPPER + PM_HUMAN, PM_WATER_DEMON, PM_VAMPIRE, PM_RED_DRAGON, + PM_TROLL, PM_UMBER_HULK, PM_XORN, PM_XAN, + PM_COCKATRICE, PM_FLOATING_EYE, PM_GUARDIAN_NAGA, PM_TRAPPER }; /* If you've found the Amulet, make the Wizard appear after some time */ @@ -48,72 +44,73 @@ static NEARDATA const unsigned wizapp[] = { void amulet() { - struct monst *mtmp; - struct trap *ttmp; - struct obj *amu; + struct monst *mtmp; + struct trap *ttmp; + struct obj *amu; -#if 0 /* caller takes care of this check */ +#if 0 /* caller takes care of this check */ if (!u.uhave.amulet) return; #endif - if ((((amu = uamul) != 0 && amu->otyp == AMULET_OF_YENDOR) || - ((amu = uwep) != 0 && amu->otyp == AMULET_OF_YENDOR)) - && !rn2(15)) { - for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { - if(ttmp->ttyp == MAGIC_PORTAL) { - int du = distu(ttmp->tx, ttmp->ty); - if (du <= 9) - pline("%s hot!", Tobjnam(amu, "feel")); - else if (du <= 64) - pline("%s very warm.", Tobjnam(amu, "feel")); - else if (du <= 144) - pline("%s warm.", Tobjnam(amu, "feel")); - /* else, the amulet feels normal */ - break; - } - } - } + if ((((amu = uamul) != 0 && amu->otyp == AMULET_OF_YENDOR) + || ((amu = uwep) != 0 && amu->otyp == AMULET_OF_YENDOR)) + && !rn2(15)) { + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { + if (ttmp->ttyp == MAGIC_PORTAL) { + int du = distu(ttmp->tx, ttmp->ty); + if (du <= 9) + pline("%s hot!", Tobjnam(amu, "feel")); + else if (du <= 64) + pline("%s very warm.", Tobjnam(amu, "feel")); + else if (du <= 144) + pline("%s warm.", Tobjnam(amu, "feel")); + /* else, the amulet feels normal */ + break; + } + } + } - if (!context.no_of_wizards) - return; - /* find Wizard, and wake him if necessary */ - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) { - mtmp->msleeping = 0; - if (distu(mtmp->mx,mtmp->my) > 2) - You( - "get the creepy feeling that somebody noticed your taking the Amulet." - ); - return; - } - } + if (!context.no_of_wizards) + return; + /* find Wizard, and wake him if necessary */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) { + mtmp->msleeping = 0; + if (distu(mtmp->mx, mtmp->my) > 2) + You("get the creepy feeling that somebody noticed your " + "taking the Amulet."); + return; + } + } } int mon_has_amulet(mtmp) register struct monst *mtmp; { - register struct obj *otmp; + register struct obj *otmp; - for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if(otmp->otyp == AMULET_OF_YENDOR) return(1); - return(0); + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->otyp == AMULET_OF_YENDOR) + return (1); + return (0); } int mon_has_special(mtmp) register struct monst *mtmp; { - register struct obj *otmp; + register struct obj *otmp; - for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - if(otmp->otyp == AMULET_OF_YENDOR || - is_quest_artifact(otmp) || - otmp->otyp == BELL_OF_OPENING || - otmp->otyp == CANDELABRUM_OF_INVOCATION || - otmp->otyp == SPE_BOOK_OF_THE_DEAD) return(1); - return(0); + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + if (otmp->otyp == AMULET_OF_YENDOR || is_quest_artifact(otmp) + || otmp->otyp == BELL_OF_OPENING + || otmp->otyp == CANDELABRUM_OF_INVOCATION + || otmp->otyp == SPE_BOOK_OF_THE_DEAD) + return (1); + return (0); } /* @@ -123,23 +120,29 @@ register struct monst *mtmp; * The strategy section decides *what* the monster is going * to attempt, the tactics section implements the decision. */ -#define STRAT(w,x,y,typ) ((unsigned long)(w) | ((unsigned long)(x) << 16) | \ - ((unsigned long)(y) << 8) | (unsigned long)(typ)) +#define STRAT(w, x, y, typ) \ + ((unsigned long) (w) | ((unsigned long) (x) << 16) \ + | ((unsigned long) (y) << 8) | (unsigned long) (typ)) -#define M_Wants(mask) (mtmp->data->mflags3 & (mask)) +#define M_Wants(mask) (mtmp->data->mflags3 & (mask)) STATIC_OVL short which_arti(mask) - register int mask; +register int mask; { - switch(mask) { - case M3_WANTSAMUL: return(AMULET_OF_YENDOR); - case M3_WANTSBELL: return(BELL_OF_OPENING); - case M3_WANTSCAND: return(CANDELABRUM_OF_INVOCATION); - case M3_WANTSBOOK: return(SPE_BOOK_OF_THE_DEAD); - default: break; /* 0 signifies quest artifact */ - } - return(0); + switch (mask) { + case M3_WANTSAMUL: + return (AMULET_OF_YENDOR); + case M3_WANTSBELL: + return (BELL_OF_OPENING); + case M3_WANTSCAND: + return (CANDELABRUM_OF_INVOCATION); + case M3_WANTSBOOK: + return (SPE_BOOK_OF_THE_DEAD); + default: + break; /* 0 signifies quest artifact */ + } + return (0); } /* @@ -149,265 +152,278 @@ which_arti(mask) */ STATIC_OVL boolean mon_has_arti(mtmp, otyp) - register struct monst *mtmp; - register short otyp; +register struct monst *mtmp; +register short otyp; { - register struct obj *otmp; - - for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { - if(otyp) { - if(otmp->otyp == otyp) - return(1); - } - else if(is_quest_artifact(otmp)) return(1); - } - return(0); + register struct obj *otmp; + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { + if (otyp) { + if (otmp->otyp == otyp) + return (1); + } else if (is_quest_artifact(otmp)) + return (1); + } + return (0); } STATIC_OVL struct monst * other_mon_has_arti(mtmp, otyp) - register struct monst *mtmp; - register short otyp; +register struct monst *mtmp; +register short otyp; { - register struct monst *mtmp2; + register struct monst *mtmp2; - for(mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) - /* no need for !DEADMONSTER check here since they have no inventory */ - if(mtmp2 != mtmp) - if(mon_has_arti(mtmp2, otyp)) return(mtmp2); + for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) + /* no need for !DEADMONSTER check here since they have no inventory */ + if (mtmp2 != mtmp) + if (mon_has_arti(mtmp2, otyp)) + return (mtmp2); - return((struct monst *)0); + return ((struct monst *) 0); } STATIC_OVL struct obj * on_ground(otyp) - register short otyp; +register short otyp; { - register struct obj *otmp; + register struct obj *otmp; - for (otmp = fobj; otmp; otmp = otmp->nobj) - if (otyp) { - if (otmp->otyp == otyp) - return(otmp); - } else if (is_quest_artifact(otmp)) - return(otmp); - return((struct obj *)0); + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otyp) { + if (otmp->otyp == otyp) + return (otmp); + } else if (is_quest_artifact(otmp)) + return (otmp); + return ((struct obj *) 0); } STATIC_OVL boolean you_have(mask) - register int mask; +register int mask; { - switch(mask) { - case M3_WANTSAMUL: return(boolean)(u.uhave.amulet); - case M3_WANTSBELL: return(boolean)(u.uhave.bell); - case M3_WANTSCAND: return(boolean)(u.uhave.menorah); - case M3_WANTSBOOK: return(boolean)(u.uhave.book); - case M3_WANTSARTI: return(boolean)(u.uhave.questart); - default: break; - } - return(0); + switch (mask) { + case M3_WANTSAMUL: + return (boolean)(u.uhave.amulet); + case M3_WANTSBELL: + return (boolean)(u.uhave.bell); + case M3_WANTSCAND: + return (boolean)(u.uhave.menorah); + case M3_WANTSBOOK: + return (boolean)(u.uhave.book); + case M3_WANTSARTI: + return (boolean)(u.uhave.questart); + default: + break; + } + return (0); } STATIC_OVL unsigned long target_on(mask, mtmp) - register int mask; - register struct monst *mtmp; +register int mask; +register struct monst *mtmp; { - register short otyp; - register struct obj *otmp; - register struct monst *mtmp2; + register short otyp; + register struct obj *otmp; + register struct monst *mtmp2; - if (!M_Wants(mask)) return (unsigned long)STRAT_NONE; + if (!M_Wants(mask)) + return (unsigned long) STRAT_NONE; - otyp = which_arti(mask); - if(!mon_has_arti(mtmp, otyp)) { - if(you_have(mask)) - return(STRAT(STRAT_PLAYER, u.ux, u.uy, mask)); - else if((otmp = on_ground(otyp))) - return(STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask)); - else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0 && - /* when seeking the Amulet, avoid targetting the Wizard - or temple priests (to protect Moloch's high priest) */ - (otyp != AMULET_OF_YENDOR || - (!mtmp2->iswiz && !inhistemple(mtmp2)))) - return(STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask)); - } - return (unsigned long)STRAT_NONE; + otyp = which_arti(mask); + if (!mon_has_arti(mtmp, otyp)) { + if (you_have(mask)) + return (STRAT(STRAT_PLAYER, u.ux, u.uy, mask)); + else if ((otmp = on_ground(otyp))) + return (STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask)); + else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0 && + /* when seeking the Amulet, avoid targetting the Wizard + or temple priests (to protect Moloch's high priest) */ + (otyp != AMULET_OF_YENDOR + || (!mtmp2->iswiz && !inhistemple(mtmp2)))) + return (STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask)); + } + return (unsigned long) STRAT_NONE; } STATIC_OVL unsigned long strategy(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - unsigned long strat, dstrat; + unsigned long strat, dstrat; - if (!is_covetous(mtmp->data) || - /* perhaps a shopkeeper has been polymorphed into a master - lich; we don't want it teleporting to the stairs to heal - because that will leave its shop untended */ - (mtmp->isshk && inhishop(mtmp)) || - /* likewise for temple priests */ - (mtmp->ispriest && inhistemple(mtmp))) - return (unsigned long)STRAT_NONE; + if (!is_covetous(mtmp->data) || + /* perhaps a shopkeeper has been polymorphed into a master + lich; we don't want it teleporting to the stairs to heal + because that will leave its shop untended */ + (mtmp->isshk && inhishop(mtmp)) || + /* likewise for temple priests */ + (mtmp->ispriest && inhistemple(mtmp))) + return (unsigned long) STRAT_NONE; - switch((mtmp->mhp*3)/mtmp->mhpmax) { /* 0-3 */ + switch ((mtmp->mhp * 3) / mtmp->mhpmax) { /* 0-3 */ - default: - case 0: /* panic time - mtmp is almost snuffed */ - return (unsigned long)(STRAT_HEAL); + default: + case 0: /* panic time - mtmp is almost snuffed */ + return (unsigned long) (STRAT_HEAL); - case 1: /* the wiz is less cautious */ - if(mtmp->data != &mons[PM_WIZARD_OF_YENDOR]) - return (unsigned long)(STRAT_HEAL); - /* else fall through */ + case 1: /* the wiz is less cautious */ + if (mtmp->data != &mons[PM_WIZARD_OF_YENDOR]) + return (unsigned long) (STRAT_HEAL); + /* else fall through */ - case 2: dstrat = STRAT_HEAL; - break; + case 2: + dstrat = STRAT_HEAL; + break; - case 3: dstrat = STRAT_NONE; - break; - } + case 3: + dstrat = STRAT_NONE; + break; + } - if(context.made_amulet) - if((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE) - return(strat); + if (context.made_amulet) + if ((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE) + return (strat); - if(u.uevent.invoked) { /* priorities change once gate opened */ + if (u.uevent.invoked) { /* priorities change once gate opened */ - if((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) - return(strat); - } else { - - if((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) - return(strat); - if((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) - return(strat); - } - return(dstrat); + if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) + return (strat); + } else { + if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) + return (strat); + if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) + return (strat); + } + return (dstrat); } int tactics(mtmp) - register struct monst *mtmp; +register struct monst *mtmp; { - unsigned long strat = strategy(mtmp); + unsigned long strat = strategy(mtmp); - mtmp->mstrategy = (mtmp->mstrategy & (STRAT_WAITMASK|STRAT_APPEARMSG)) | strat; + mtmp->mstrategy = + (mtmp->mstrategy & (STRAT_WAITMASK | STRAT_APPEARMSG)) | strat; - switch (strat) { - case STRAT_HEAL: /* hide and recover */ - /* if wounded, hole up on or near the stairs (to block them) */ - /* unless, of course, there are no stairs (e.g. endlevel) */ - mtmp->mavenge = 1; /* covetous monsters attack while fleeing */ - if (In_W_tower(mtmp->mx, mtmp->my, &u.uz) || - (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) { - if (!rn2(3 + mtmp->mhp/10)) (void) rloc(mtmp, FALSE); - } else if (xupstair && - (mtmp->mx != xupstair || mtmp->my != yupstair)) { - (void) mnearto(mtmp, xupstair, yupstair, TRUE); - } - /* if you're not around, cast healing spells */ - if (distu(mtmp->mx,mtmp->my) > (BOLT_LIM * BOLT_LIM)) - if(mtmp->mhp <= mtmp->mhpmax - 8) { - mtmp->mhp += rnd(8); - return(1); - } - /* fall through :-) */ + switch (strat) { + case STRAT_HEAL: /* hide and recover */ + /* if wounded, hole up on or near the stairs (to block them) */ + /* unless, of course, there are no stairs (e.g. endlevel) */ + mtmp->mavenge = 1; /* covetous monsters attack while fleeing */ + if (In_W_tower(mtmp->mx, mtmp->my, &u.uz) + || (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) { + if (!rn2(3 + mtmp->mhp / 10)) + (void) rloc(mtmp, FALSE); + } else if (xupstair + && (mtmp->mx != xupstair || mtmp->my != yupstair)) { + (void) mnearto(mtmp, xupstair, yupstair, TRUE); + } + /* if you're not around, cast healing spells */ + if (distu(mtmp->mx, mtmp->my) > (BOLT_LIM * BOLT_LIM)) + if (mtmp->mhp <= mtmp->mhpmax - 8) { + mtmp->mhp += rnd(8); + return (1); + } + /* fall through :-) */ - case STRAT_NONE: /* harrass */ - if (!rn2(!mtmp->mflee ? 5 : 33)) mnexto(mtmp); - return(0); + case STRAT_NONE: /* harrass */ + if (!rn2(!mtmp->mflee ? 5 : 33)) + mnexto(mtmp); + return (0); - default: /* kill, maim, pillage! */ - { - long where = (strat & STRAT_STRATMASK); - xchar tx = STRAT_GOALX(strat), - ty = STRAT_GOALY(strat); - int targ = (int)(strat & STRAT_GOAL); - struct obj *otmp; + default: /* kill, maim, pillage! */ + { + long where = (strat & STRAT_STRATMASK); + xchar tx = STRAT_GOALX(strat), ty = STRAT_GOALY(strat); + int targ = (int) (strat & STRAT_GOAL); + struct obj *otmp; - if(!targ) { /* simply wants you to close */ - return(0); - } - if((u.ux == tx && u.uy == ty) || where == STRAT_PLAYER) { - /* player is standing on it (or has it) */ - mnexto(mtmp); - return(0); - } - if(where == STRAT_GROUND) { - if(!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) { - /* teleport to it and pick it up */ - rloc_to(mtmp, tx, ty); /* clean old pos */ + if (!targ) { /* simply wants you to close */ + return (0); + } + if ((u.ux == tx && u.uy == ty) || where == STRAT_PLAYER) { + /* player is standing on it (or has it) */ + mnexto(mtmp); + return (0); + } + if (where == STRAT_GROUND) { + if (!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) { + /* teleport to it and pick it up */ + rloc_to(mtmp, tx, ty); /* clean old pos */ - if ((otmp = on_ground(which_arti(targ))) != 0) { - if (cansee(mtmp->mx, mtmp->my)) - pline("%s picks up %s.", - Monnam(mtmp), - (distu(mtmp->mx, mtmp->my) <= 5) ? - doname(otmp) : distant_name(otmp, doname)); - obj_extract_self(otmp); - (void) mpickobj(mtmp, otmp); - return(1); - } else return(0); - } else { - /* a monster is standing on it - cause some trouble */ - if (!rn2(5)) mnexto(mtmp); - return(0); - } - } else { /* a monster has it - 'port beside it. */ - (void) mnearto(mtmp, tx, ty, FALSE); - return(0); - } - } - } - /*NOTREACHED*/ - return(0); + if ((otmp = on_ground(which_arti(targ))) != 0) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s picks up %s.", Monnam(mtmp), + (distu(mtmp->mx, mtmp->my) <= 5) + ? doname(otmp) + : distant_name(otmp, doname)); + obj_extract_self(otmp); + (void) mpickobj(mtmp, otmp); + return (1); + } else + return (0); + } else { + /* a monster is standing on it - cause some trouble */ + if (!rn2(5)) + mnexto(mtmp); + return (0); + } + } else { /* a monster has it - 'port beside it. */ + (void) mnearto(mtmp, tx, ty, FALSE); + return (0); + } + } + } + /*NOTREACHED*/ + return (0); } void aggravate() { - register struct monst *mtmp; + register struct monst *mtmp; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - mtmp->mstrategy &= ~(STRAT_WAITFORU|STRAT_APPEARMSG); - mtmp->msleeping = 0; - if (!mtmp->mcanmove && !rn2(5)) { - mtmp->mfrozen = 0; - mtmp->mcanmove = 1; - } - } + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + mtmp->mstrategy &= ~(STRAT_WAITFORU | STRAT_APPEARMSG); + mtmp->msleeping = 0; + if (!mtmp->mcanmove && !rn2(5)) { + mtmp->mfrozen = 0; + mtmp->mcanmove = 1; + } + } } void clonewiz() { - register struct monst *mtmp2; + register struct monst *mtmp2; - if ((mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], - u.ux, u.uy, NO_MM_FLAGS)) != 0) { - mtmp2->msleeping = mtmp2->mtame = mtmp2->mpeaceful = 0; - if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */ - (void) add_to_minv(mtmp2, mksobj(FAKE_AMULET_OF_YENDOR, - TRUE, FALSE)); - } - mtmp2->m_ap_type = M_AP_MONSTER; - mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))]; - newsym(mtmp2->mx,mtmp2->my); - } + if ((mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, NO_MM_FLAGS)) + != 0) { + mtmp2->msleeping = mtmp2->mtame = mtmp2->mpeaceful = 0; + if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */ + (void) add_to_minv(mtmp2, + mksobj(FAKE_AMULET_OF_YENDOR, TRUE, FALSE)); + } + mtmp2->m_ap_type = M_AP_MONSTER; + mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))]; + newsym(mtmp2->mx, mtmp2->my); + } } /* also used by newcham() */ @@ -423,10 +439,10 @@ pick_nasty() /* a null caster defaults to a chaotic caster (e.g. the wizard) */ int nasty(mcast) - struct monst *mcast; +struct monst *mcast; { - register struct monst *mtmp; - register int i, j, tmp; + register struct monst *mtmp; + register int i, j, tmp; int castalign = (mcast ? sgn(mcast->data->maligntyp) : -1); coord bypos; int count, census; @@ -435,46 +451,49 @@ nasty(mcast) of non-null makemon() return is inadequate */ census = monster_census(FALSE); - if(!rn2(10) && Inhell) { - count = msummon((struct monst *) 0); /* summons like WoY */ + if (!rn2(10) && Inhell) { + count = msummon((struct monst *) 0); /* summons like WoY */ } else { - count = 0; - tmp = (u.ulevel > 3) ? u.ulevel/3 : 1; /* just in case -- rph */ - /* if we don't have a casting monster, the nasties appear around you */ - bypos.x = u.ux; - bypos.y = u.uy; - for(i = rnd(tmp); i > 0; --i) - for(j=0; j<20; j++) { - int makeindex; + count = 0; + tmp = (u.ulevel > 3) ? u.ulevel / 3 : 1; /* just in case -- rph */ + /* if we don't have a casting monster, the nasties appear around you + */ + bypos.x = u.ux; + bypos.y = u.uy; + for (i = rnd(tmp); i > 0; --i) + for (j = 0; j < 20; j++) { + int makeindex; - /* Don't create more spellcasters of the monsters' level or - * higher--avoids chain summoners filling up the level. - */ - do { - makeindex = pick_nasty(); - } while(mcast && attacktype(&mons[makeindex], AT_MAGC) && - monstr[makeindex] >= monstr[mcast->mnum]); - /* do this after picking the monster to place */ - if (mcast && - !enexto(&bypos, mcast->mux, mcast->muy, &mons[makeindex])) - continue; - if ((mtmp = makemon(&mons[makeindex], - bypos.x, bypos.y, NO_MM_FLAGS)) != 0) { - mtmp->msleeping = mtmp->mpeaceful = mtmp->mtame = 0; - set_malign(mtmp); - } else /* GENOD? */ - mtmp = makemon((struct permonst *)0, - bypos.x, bypos.y, NO_MM_FLAGS); - if (mtmp) { - count++; - if (mtmp->data->maligntyp == 0 || - sgn(mtmp->data->maligntyp) == castalign) - break; - } - } + /* Don't create more spellcasters of the monsters' level or + * higher--avoids chain summoners filling up the level. + */ + do { + makeindex = pick_nasty(); + } while (mcast && attacktype(&mons[makeindex], AT_MAGC) + && monstr[makeindex] >= monstr[mcast->mnum]); + /* do this after picking the monster to place */ + if (mcast + && !enexto(&bypos, mcast->mux, mcast->muy, + &mons[makeindex])) + continue; + if ((mtmp = makemon(&mons[makeindex], bypos.x, bypos.y, + NO_MM_FLAGS)) != 0) { + mtmp->msleeping = mtmp->mpeaceful = mtmp->mtame = 0; + set_malign(mtmp); + } else /* GENOD? */ + mtmp = makemon((struct permonst *) 0, bypos.x, bypos.y, + NO_MM_FLAGS); + if (mtmp) { + count++; + if (mtmp->data->maligntyp == 0 + || sgn(mtmp->data->maligntyp) == castalign) + break; + } + } } - if (count) count = monster_census(FALSE) - census; + if (count) + count = monster_census(FALSE) - census; return count; } @@ -482,54 +501,54 @@ nasty(mcast) void resurrect() { - struct monst *mtmp, **mmtmp; - long elapsed; - const char *verb; + struct monst *mtmp, **mmtmp; + long elapsed; + const char *verb; - if (!context.no_of_wizards) { - /* make a new Wizard */ - verb = "kill"; - mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT); - /* affects experience; he's not coming back from a corpse - but is subject to repeated killing like a revived corpse */ - mtmp->mrevived = 1; - } else { - /* look for a migrating Wizard */ - verb = "elude"; - mmtmp = &migrating_mons; - while ((mtmp = *mmtmp) != 0) { - if (mtmp->iswiz && - /* if he has the Amulet, he won't bring it to you */ - !mon_has_amulet(mtmp) && - (elapsed = monstermoves - mtmp->mlstmv) > 0L) { - mon_catchup_elapsed_time(mtmp, elapsed); - if (elapsed >= LARGEST_INT) elapsed = LARGEST_INT - 1; - elapsed /= 50L; - if (mtmp->msleeping && rn2((int)elapsed + 1)) - mtmp->msleeping = 0; - if (mtmp->mfrozen == 1) /* would unfreeze on next move */ - mtmp->mfrozen = 0, mtmp->mcanmove = 1; - if (mtmp->mcanmove && !mtmp->msleeping) { - *mmtmp = mtmp->nmon; - mon_arrive(mtmp, TRUE); - /* note: there might be a second Wizard; if so, - he'll have to wait til the next resurrection */ - break; - } - } - mmtmp = &mtmp->nmon; - } - } - - if (mtmp) { - mtmp->mtame = mtmp->mpeaceful = 0; /* paranoia */ - set_malign(mtmp); - if (!Deaf) { - pline("A voice booms out..."); - verbalize("So thou thought thou couldst %s me, fool.", verb); - } - } + if (!context.no_of_wizards) { + /* make a new Wizard */ + verb = "kill"; + mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT); + /* affects experience; he's not coming back from a corpse + but is subject to repeated killing like a revived corpse */ + mtmp->mrevived = 1; + } else { + /* look for a migrating Wizard */ + verb = "elude"; + mmtmp = &migrating_mons; + while ((mtmp = *mmtmp) != 0) { + if (mtmp->iswiz && + /* if he has the Amulet, he won't bring it to you */ + !mon_has_amulet(mtmp) + && (elapsed = monstermoves - mtmp->mlstmv) > 0L) { + mon_catchup_elapsed_time(mtmp, elapsed); + if (elapsed >= LARGEST_INT) + elapsed = LARGEST_INT - 1; + elapsed /= 50L; + if (mtmp->msleeping && rn2((int) elapsed + 1)) + mtmp->msleeping = 0; + if (mtmp->mfrozen == 1) /* would unfreeze on next move */ + mtmp->mfrozen = 0, mtmp->mcanmove = 1; + if (mtmp->mcanmove && !mtmp->msleeping) { + *mmtmp = mtmp->nmon; + mon_arrive(mtmp, TRUE); + /* note: there might be a second Wizard; if so, + he'll have to wait til the next resurrection */ + break; + } + } + mmtmp = &mtmp->nmon; + } + } + if (mtmp) { + mtmp->mtame = mtmp->mpeaceful = 0; /* paranoia */ + set_malign(mtmp); + if (!Deaf) { + pline("A voice booms out..."); + verbalize("So thou thought thou couldst %s me, fool.", verb); + } + } } /* Here, we make trouble for the poor shmuck who actually */ @@ -537,117 +556,92 @@ resurrect() void intervene() { - int which = Is_astralevel(&u.uz) ? rnd(4) : rn2(6); - /* cases 0 and 5 don't apply on the Astral level */ - switch (which) { - case 0: - case 1: You_feel("vaguely nervous."); - break; - case 2: if (!Blind) - You("notice a %s glow surrounding you.", - hcolor(NH_BLACK)); - rndcurse(); - break; - case 3: aggravate(); - break; - case 4: (void)nasty((struct monst *)0); - break; - case 5: resurrect(); - break; - } + int which = Is_astralevel(&u.uz) ? rnd(4) : rn2(6); + /* cases 0 and 5 don't apply on the Astral level */ + switch (which) { + case 0: + case 1: + You_feel("vaguely nervous."); + break; + case 2: + if (!Blind) + You("notice a %s glow surrounding you.", hcolor(NH_BLACK)); + rndcurse(); + break; + case 3: + aggravate(); + break; + case 4: + (void) nasty((struct monst *) 0); + break; + case 5: + resurrect(); + break; + } } void wizdead() { - context.no_of_wizards--; - if (!u.uevent.udemigod) { - u.uevent.udemigod = TRUE; - u.udg_cnt = rn1(250, 50); - } + context.no_of_wizards--; + if (!u.uevent.udemigod) { + u.uevent.udemigod = TRUE; + u.udg_cnt = rn1(250, 50); + } } -const char * const random_insult[] = { - "antic", - "blackguard", - "caitiff", - "chucklehead", - "coistrel", - "craven", - "cretin", - "cur", - "dastard", - "demon fodder", - "dimwit", - "dolt", - "fool", - "footpad", - "imbecile", - "knave", - "maledict", - "miscreant", - "niddering", - "poltroon", - "rattlepate", - "reprobate", - "scapegrace", - "varlet", - "villein", /* (sic.) */ - "wittol", - "worm", - "wretch", +const char *const random_insult[] = { + "antic", "blackguard", "caitiff", "chucklehead", + "coistrel", "craven", "cretin", "cur", + "dastard", "demon fodder", "dimwit", "dolt", + "fool", "footpad", "imbecile", "knave", + "maledict", "miscreant", "niddering", "poltroon", + "rattlepate", "reprobate", "scapegrace", "varlet", + "villein", /* (sic.) */ + "wittol", "worm", "wretch", }; -const char * const random_malediction[] = { - "Hell shall soon claim thy remains,", - "I chortle at thee, thou pathetic", - "Prepare to die, thou", - "Resistance is useless,", - "Surrender or die, thou", - "There shall be no mercy, thou", - "Thou shalt repent of thy cunning,", - "Thou art as a flea to me,", - "Thou art doomed,", - "Thy fate is sealed,", - "Verily, thou shalt be one dead" +const char *const random_malediction[] = { + "Hell shall soon claim thy remains,", "I chortle at thee, thou pathetic", + "Prepare to die, thou", "Resistance is useless,", + "Surrender or die, thou", "There shall be no mercy, thou", + "Thou shalt repent of thy cunning,", "Thou art as a flea to me,", + "Thou art doomed,", "Thy fate is sealed,", + "Verily, thou shalt be one dead" }; /* Insult or intimidate the player */ void cuss(mtmp) -register struct monst *mtmp; +register struct monst *mtmp; { - if (Deaf) - return; - if (mtmp->iswiz) { - if (!rn2(5)) /* typical bad guy action */ - pline("%s laughs fiendishly.", Monnam(mtmp)); - else - if (u.uhave.amulet && !rn2(SIZE(random_insult))) - verbalize("Relinquish the amulet, %s!", - random_insult[rn2(SIZE(random_insult))]); - else if (u.uhp < 5 && !rn2(2)) /* Panic */ - verbalize(rn2(2) ? - "Even now thy life force ebbs, %s!" : - "Savor thy breath, %s, it be thy last!", - random_insult[rn2(SIZE(random_insult))]); - else if (mtmp->mhp < 5 && !rn2(2)) /* Parthian shot */ - verbalize(rn2(2) ? - "I shall return." : - "I'll be back."); - else - verbalize("%s %s!", - random_malediction[rn2(SIZE(random_malediction))], - random_insult[rn2(SIZE(random_insult))]); - } else if(is_lminion(mtmp)) { - com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0)) + - QT_ANGELIC); - } else { - if (!rn2(5)) - pline("%s casts aspersions on your ancestry.", Monnam(mtmp)); - else - com_pager(rn2(QTN_DEMONIC) + QT_DEMONIC); - } + if (Deaf) + return; + if (mtmp->iswiz) { + if (!rn2(5)) /* typical bad guy action */ + pline("%s laughs fiendishly.", Monnam(mtmp)); + else if (u.uhave.amulet && !rn2(SIZE(random_insult))) + verbalize("Relinquish the amulet, %s!", + random_insult[rn2(SIZE(random_insult))]); + else if (u.uhp < 5 && !rn2(2)) /* Panic */ + verbalize(rn2(2) ? "Even now thy life force ebbs, %s!" + : "Savor thy breath, %s, it be thy last!", + random_insult[rn2(SIZE(random_insult))]); + else if (mtmp->mhp < 5 && !rn2(2)) /* Parthian shot */ + verbalize(rn2(2) ? "I shall return." : "I'll be back."); + else + verbalize("%s %s!", + random_malediction[rn2(SIZE(random_malediction))], + random_insult[rn2(SIZE(random_insult))]); + } else if (is_lminion(mtmp)) { + com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0)) + + QT_ANGELIC); + } else { + if (!rn2(5)) + pline("%s casts aspersions on your ancestry.", Monnam(mtmp)); + else + com_pager(rn2(QTN_DEMONIC) + QT_DEMONIC); + } } /*wizard.c*/ diff --git a/src/worm.c b/src/worm.c index f3fec5aab..afcd9a3f4 100644 --- a/src/worm.c +++ b/src/worm.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 worm.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 worm.c $NHDT-Date: 1431192765 2015/05/09 17:32:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.15 $ */ /* NetHack 3.6 worm.c $Date: 2009/05/06 10:48:17 $ $Revision: 1.12 $ */ /* SCCS Id: @(#)worm.c 3.5 2009/03/05 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -7,18 +7,18 @@ #include "hack.h" #include "lev.h" -#define newseg() (struct wseg *) alloc(sizeof(struct wseg)) -#define dealloc_seg(wseg) free((genericptr_t) (wseg)) +#define newseg() (struct wseg *) alloc(sizeof(struct wseg)) +#define dealloc_seg(wseg) free((genericptr_t)(wseg)) /* worm segment structure */ struct wseg { struct wseg *nseg; - xchar wx, wy; /* the segment's position */ + xchar wx, wy; /* the segment's position */ }; -STATIC_DCL void FDECL(toss_wsegs, (struct wseg *,BOOLEAN_P)); +STATIC_DCL void FDECL(toss_wsegs, (struct wseg *, BOOLEAN_P)); STATIC_DCL void FDECL(shrink_worm, (int)); -STATIC_DCL void FDECL(random_dir, (XCHAR_P,XCHAR_P,xchar *,xchar *)); +STATIC_DCL void FDECL(random_dir, (XCHAR_P, XCHAR_P, xchar *, xchar *)); STATIC_DCL struct wseg *FDECL(create_worm_tail, (int)); /* Description of long worm implementation. @@ -44,7 +44,8 @@ STATIC_DCL struct wseg *FDECL(create_worm_tail, (int)); * the segment that is at the same position as the real monster * (the head). Note that the segment that wheads[wormno] points * to, is not displayed. It is simply there to keep track of - * where the head came from, so that worm movement and display are + * where the head came from, so that worm movement and display + *are * simplified later. * Keeping the head segment of the worm at the end of the list * of tail segments is an endless source of confusion, but it is @@ -68,8 +69,8 @@ STATIC_DCL struct wseg *FDECL(create_worm_tail, (int)); * segment, and remove hit points from the worm. */ -struct wseg *wheads[MAX_NUM_WORMS] = DUMMY, *wtails[MAX_NUM_WORMS] = DUMMY; -long wgrowtime[MAX_NUM_WORMS] = DUMMY; +struct wseg *wheads[MAX_NUM_WORMS] = DUMMY, *wtails[MAX_NUM_WORMS] = DUMMY; +long wgrowtime[MAX_NUM_WORMS] = DUMMY; /* * get_wormno() @@ -90,12 +91,13 @@ get_wormno() register int new_wormno = 1; while (new_wormno < MAX_NUM_WORMS) { - if (!wheads[new_wormno]) - return new_wormno; /* found an empty wtails[] slot at new_wormno */ - new_wormno++; + if (!wheads[new_wormno]) + return new_wormno; /* found an empty wtails[] slot at new_wormno + */ + new_wormno++; } - return(0); /* level infested with worms */ + return (0); /* level infested with worms */ } /* @@ -111,28 +113,28 @@ get_wormno() */ void initworm(worm, wseg_count) - struct monst *worm; - int wseg_count; +struct monst *worm; +int wseg_count; { register struct wseg *seg, *new_tail = create_worm_tail(wseg_count); register int wnum = worm->wormno; -/* if (!wnum) return; bullet proofing */ + /* if (!wnum) return; bullet proofing */ if (new_tail) { - wtails[wnum] = new_tail; - for (seg = new_tail; seg->nseg; seg = seg->nseg); - wheads[wnum] = seg; + wtails[wnum] = new_tail; + for (seg = new_tail; seg->nseg; seg = seg->nseg) + ; + wheads[wnum] = seg; } else { - wtails[wnum] = wheads[wnum] = seg = newseg(); - seg->nseg = (struct wseg *) 0; - seg->wx = worm->mx; - seg->wy = worm->my; + wtails[wnum] = wheads[wnum] = seg = newseg(); + seg->nseg = (struct wseg *) 0; + seg->wx = worm->mx; + seg->wy = worm->my; } wgrowtime[wnum] = 0L; } - /* * toss_wsegs() * @@ -142,31 +144,31 @@ initworm(worm, wseg_count) STATIC_OVL void toss_wsegs(curr, display_update) - register struct wseg *curr; - register boolean display_update; +register struct wseg *curr; +register boolean display_update; { register struct wseg *seg; while (curr) { - seg = curr->nseg; + seg = curr->nseg; - /* remove from level.monsters[][] */ + /* remove from level.monsters[][] */ - /* need to check curr->wx for genocided while migrating_mon */ - if (curr->wx) { - remove_monster(curr->wx, curr->wy); + /* need to check curr->wx for genocided while migrating_mon */ + if (curr->wx) { + remove_monster(curr->wx, curr->wy); - /* update screen before deallocation */ - if (display_update) newsym(curr->wx,curr->wy); - } + /* update screen before deallocation */ + if (display_update) + newsym(curr->wx, curr->wy); + } - /* free memory used by the segment */ - dealloc_seg(curr); - curr = seg; + /* free memory used by the segment */ + dealloc_seg(curr); + curr = seg; } } - /* * shrink_worm() * @@ -175,11 +177,12 @@ toss_wsegs(curr, display_update) STATIC_OVL void shrink_worm(wnum) - int wnum; /* worm number */ +int wnum; /* worm number */ { struct wseg *seg; - if (wtails[wnum] == wheads[wnum]) return; /* no tail */ + if (wtails[wnum] == wheads[wnum]) + return; /* no tail */ seg = wtails[wnum]; wtails[wnum] = seg->nseg; @@ -196,43 +199,43 @@ shrink_worm(wnum) */ void worm_move(worm) - struct monst *worm; +struct monst *worm; { - register struct wseg *seg, *new_seg; /* new segment */ - register int wnum = worm->wormno; /* worm number */ + register struct wseg *seg, *new_seg; /* new segment */ + register int wnum = worm->wormno; /* worm number */ - -/* if (!wnum) return; bullet proofing */ + /* if (!wnum) return; bullet proofing */ /* * Place a segment at the old worm head. The head has already moved. */ seg = wheads[wnum]; place_worm_seg(worm, seg->wx, seg->wy); - newsym(seg->wx,seg->wy); /* display the new segment */ + newsym(seg->wx, seg->wy); /* display the new segment */ /* * Create a new dummy segment head and place it at the end of the list. */ - new_seg = newseg(); - new_seg->wx = worm->mx; - new_seg->wy = worm->my; + new_seg = newseg(); + new_seg->wx = worm->mx; + new_seg->wy = worm->my; new_seg->nseg = (struct wseg *) 0; - seg->nseg = new_seg; /* attach it to the end of the list */ - wheads[wnum] = new_seg; /* move the end pointer */ - + seg->nseg = new_seg; /* attach it to the end of the list */ + wheads[wnum] = new_seg; /* move the end pointer */ if (wgrowtime[wnum] <= moves) { - if (!wgrowtime[wnum]) - wgrowtime[wnum] = moves + rnd(5); - else - wgrowtime[wnum] += rn1(15, 3); - worm->mhp += 3; - if (worm->mhp > MHPMAX) worm->mhp = MHPMAX; - if (worm->mhp > worm->mhpmax) worm->mhpmax = worm->mhp; + if (!wgrowtime[wnum]) + wgrowtime[wnum] = moves + rnd(5); + else + wgrowtime[wnum] += rn1(15, 3); + worm->mhp += 3; + if (worm->mhp > MHPMAX) + worm->mhp = MHPMAX; + if (worm->mhp > worm->mhpmax) + worm->mhpmax = worm->mhp; } else - /* The worm doesn't grow, so the last segment goes away. */ - shrink_worm(wnum); + /* The worm doesn't grow, so the last segment goes away. */ + shrink_worm(wnum); } /* @@ -244,14 +247,14 @@ worm_move(worm) */ void worm_nomove(worm) - register struct monst *worm; +register struct monst *worm; { - shrink_worm((int) worm->wormno); /* shrink */ + shrink_worm((int) worm->wormno); /* shrink */ if (worm->mhp > 3) - worm->mhp -= 3; /* mhpmax not changed ! */ + worm->mhp -= 3; /* mhpmax not changed ! */ else - worm->mhp = 1; + worm->mhp = 1; } /* @@ -263,11 +266,11 @@ worm_nomove(worm) */ void wormgone(worm) - register struct monst *worm; +register struct monst *worm; { register int wnum = worm->wormno; -/* if (!wnum) return; bullet proofing */ + /* if (!wnum) return; bullet proofing */ worm->wormno = 0; @@ -288,21 +291,23 @@ wormgone(worm) */ void wormhitu(worm) - register struct monst *worm; +register struct monst *worm; { register int wnum = worm->wormno; register struct wseg *seg; -/* if (!wnum) return; bullet proofing */ + /* if (!wnum) return; bullet proofing */ -/* This does not work right now because mattacku() thinks that the head is - * out of range of the player. We might try to kludge, and bring the head - * within range for a tiny moment, but this needs a bit more looking at - * before we decide to do this. - */ + /* This does not work right now because mattacku() thinks that the head + * is + * out of range of the player. We might try to kludge, and bring the + * head + * within range for a tiny moment, but this needs a bit more looking at + * before we decide to do this. + */ for (seg = wtails[wnum]; seg; seg = seg->nseg) - if (distu(seg->wx, seg->wy) < 3) - (void) mattacku(worm); + if (distu(seg->wx, seg->wy) < 3) + (void) mattacku(worm); } /* cutworm() @@ -315,43 +320,46 @@ wormhitu(worm) */ void cutworm(worm, x, y, weap) - struct monst *worm; - xchar x,y; - struct obj *weap; +struct monst *worm; +xchar x, y; +struct obj *weap; { - register struct wseg *curr, *new_tail; + register struct wseg *curr, *new_tail; register struct monst *new_worm; int wnum = worm->wormno; int cut_chance, new_wnum; - if (!wnum) return; /* bullet proofing */ + if (!wnum) + return; /* bullet proofing */ - if (x == worm->mx && y == worm->my) return; /* hit on head */ + if (x == worm->mx && y == worm->my) + return; /* hit on head */ /* cutting goes best with a bladed weapon */ - cut_chance = rnd(20); /* Normally 1-16 does not cut */ - /* Normally 17-20 does */ + cut_chance = rnd(20); /* Normally 1-16 does not cut */ + /* Normally 17-20 does */ - if (weap && is_blade(weap)) /* With a blade 1- 6 does not cut */ - cut_chance += 10; /* 7-20 does */ + if (weap && is_blade(weap)) /* With a blade 1- 6 does not cut */ + cut_chance += 10; /* 7-20 does */ - if (cut_chance < 17) return; /* not good enough */ + if (cut_chance < 17) + return; /* not good enough */ /* Find the segment that was attacked. */ curr = wtails[wnum]; - while ( (curr->wx != x) || (curr->wy != y) ) { - curr = curr->nseg; - if (!curr) { - impossible("cutworm: no segment at (%d,%d)", (int) x, (int) y); - return; - } + while ((curr->wx != x) || (curr->wy != y)) { + curr = curr->nseg; + if (!curr) { + impossible("cutworm: no segment at (%d,%d)", (int) x, (int) y); + return; + } } /* If this is the tail segment, then the worm just loses it. */ if (curr == wtails[wnum]) { - shrink_worm(wnum); - return; + shrink_worm(wnum); + return; } /* @@ -361,65 +369,66 @@ cutworm(worm, x, y, weap) */ new_tail = wtails[wnum]; wtails[wnum] = curr->nseg; - curr->nseg = (struct wseg *) 0; /* split the worm */ + curr->nseg = (struct wseg *) 0; /* split the worm */ /* * At this point, the old worm is correct. Any new worm will have - * it's head at "curr" and its tail at "new_tail". The old worm + * it's head at "curr" and its tail at "new_tail". The old worm * must be at least level 3 in order to produce a new worm. */ new_worm = 0; new_wnum = (worm->m_lev >= 3 && !rn2(3)) ? get_wormno() : 0; if (new_wnum) { - remove_monster(x, y); /* clone_mon puts new head here */ - /* clone_mon() will fail if enough long worms have been - created to have them be marked as extinct or if the hit - that cut the current one has dropped it down to 1 HP */ - new_worm = clone_mon(worm, x, y); + remove_monster(x, y); /* clone_mon puts new head here */ + /* clone_mon() will fail if enough long worms have been + created to have them be marked as extinct or if the hit + that cut the current one has dropped it down to 1 HP */ + new_worm = clone_mon(worm, x, y); } /* Sometimes the tail end dies. */ if (!new_worm) { - if (context.mon_moving) { - if (canspotmon(worm)) - pline("Part of %s tail has been cut off.", - s_suffix(mon_nam(worm))); - } else - You("cut part of the tail off of %s.", mon_nam(worm)); - toss_wsegs(new_tail, TRUE); - if (worm->mhp > 1) worm->mhp /= 2; - return; + if (context.mon_moving) { + if (canspotmon(worm)) + pline("Part of %s tail has been cut off.", + s_suffix(mon_nam(worm))); + } else + You("cut part of the tail off of %s.", mon_nam(worm)); + toss_wsegs(new_tail, TRUE); + if (worm->mhp > 1) + worm->mhp /= 2; + return; } - new_worm->wormno = new_wnum; /* affix new worm number */ - new_worm->mcloned = 0; /* treat second worm as a normal monster */ + new_worm->wormno = new_wnum; /* affix new worm number */ + new_worm->mcloned = 0; /* treat second worm as a normal monster */ /* Devalue the monster level of both halves of the worm. Note: m_lev is always at least 3 in order to get this far. */ - worm->m_lev = max((unsigned)worm->m_lev - 2, 3); + worm->m_lev = max((unsigned) worm->m_lev - 2, 3); new_worm->m_lev = worm->m_lev; /* Calculate the lower-level mhp; use d8 for long worms. Can't use newmonhp() here because it would reset m_lev. */ - new_worm->mhpmax = new_worm->mhp = d((int)new_worm->m_lev, 8); - worm->mhpmax = d((int)worm->m_lev, 8); /* new maxHP for old worm */ - if (worm->mhpmax < worm->mhp) worm->mhp = worm->mhpmax; + new_worm->mhpmax = new_worm->mhp = d((int) new_worm->m_lev, 8); + worm->mhpmax = d((int) worm->m_lev, 8); /* new maxHP for old worm */ + if (worm->mhpmax < worm->mhp) + worm->mhp = worm->mhpmax; - wtails[new_wnum] = new_tail; /* We've got all the info right now */ - wheads[new_wnum] = curr; /* so we can do this faster than */ - wgrowtime[new_wnum] = 0L; /* trying to call initworm(). */ + wtails[new_wnum] = new_tail; /* We've got all the info right now */ + wheads[new_wnum] = curr; /* so we can do this faster than */ + wgrowtime[new_wnum] = 0L; /* trying to call initworm(). */ /* Place the new monster at all the segment locations. */ place_wsegs(new_worm); if (context.mon_moving) - pline("%s is cut in half.", Monnam(worm)); + pline("%s is cut in half.", Monnam(worm)); else - You("cut %s in half.", mon_nam(worm)); + You("cut %s in half.", mon_nam(worm)); } - /* * see_wsegs() * @@ -429,15 +438,15 @@ cutworm(worm, x, y, weap) */ void see_wsegs(worm) - struct monst *worm; +struct monst *worm; { struct wseg *curr = wtails[worm->wormno]; -/* if (!mtmp->wormno) return; bullet proofing */ + /* if (!mtmp->wormno) return; bullet proofing */ while (curr != wheads[worm->wormno]) { - newsym(curr->wx,curr->wy); - curr = curr->nseg; + newsym(curr->wx, curr->wy); + curr = curr->nseg; } } @@ -448,24 +457,23 @@ see_wsegs(worm) */ void detect_wsegs(worm, use_detection_glyph) - struct monst *worm; - boolean use_detection_glyph; +struct monst *worm; +boolean use_detection_glyph; { int num; struct wseg *curr = wtails[worm->wormno]; -/* if (!mtmp->wormno) return; bullet proofing */ + /* if (!mtmp->wormno) return; bullet proofing */ while (curr != wheads[worm->wormno]) { - num = use_detection_glyph ? - detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)) : - monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); - show_glyph(curr->wx,curr->wy,num); - curr = curr->nseg; + num = use_detection_glyph + ? detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)) + : monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)); + show_glyph(curr->wx, curr->wy, num); + curr = curr->nseg; } } - /* * save_worm() * @@ -474,43 +482,44 @@ detect_wsegs(worm, use_detection_glyph) */ void save_worm(fd, mode) - int fd, mode; +int fd, mode; { int i; int count; struct wseg *curr, *temp; if (perform_bwrite(mode)) { - for (i = 1; i < MAX_NUM_WORMS; i++) { - for (count = 0, curr = wtails[i]; curr; curr = curr->nseg) count++; - /* Save number of segments */ - bwrite(fd, (genericptr_t) &count, sizeof(int)); - /* Save segment locations of the monster. */ - if (count) { - for (curr = wtails[i]; curr; curr = curr->nseg) { - bwrite(fd, (genericptr_t) &(curr->wx), sizeof(xchar)); - bwrite(fd, (genericptr_t) &(curr->wy), sizeof(xchar)); - } - } - } - bwrite(fd, (genericptr_t) wgrowtime, sizeof(wgrowtime)); + for (i = 1; i < MAX_NUM_WORMS; i++) { + for (count = 0, curr = wtails[i]; curr; curr = curr->nseg) + count++; + /* Save number of segments */ + bwrite(fd, (genericptr_t) &count, sizeof(int)); + /* Save segment locations of the monster. */ + if (count) { + for (curr = wtails[i]; curr; curr = curr->nseg) { + bwrite(fd, (genericptr_t) & (curr->wx), sizeof(xchar)); + bwrite(fd, (genericptr_t) & (curr->wy), sizeof(xchar)); + } + } + } + bwrite(fd, (genericptr_t) wgrowtime, sizeof(wgrowtime)); } if (release_data(mode)) { - /* Free the segments only. savemonchn() will take care of the - * monsters. */ - for (i = 1; i < MAX_NUM_WORMS; i++) { - if (!(curr = wtails[i])) continue; + /* Free the segments only. savemonchn() will take care of the + * monsters. */ + for (i = 1; i < MAX_NUM_WORMS; i++) { + if (!(curr = wtails[i])) + continue; - while (curr) { - temp = curr->nseg; - dealloc_seg(curr); /* free the segment */ - curr = temp; - } - wheads[i] = wtails[i] = (struct wseg *) 0; - } + while (curr) { + temp = curr->nseg; + dealloc_seg(curr); /* free the segment */ + curr = temp; + } + wheads[i] = wtails[i] = (struct wseg *) 0; + } } - } /* @@ -520,28 +529,29 @@ save_worm(fd, mode) */ void rest_worm(fd) - int fd; +int fd; { int i, j, count; struct wseg *curr, *temp; for (i = 1; i < MAX_NUM_WORMS; i++) { - mread(fd, (genericptr_t) &count, sizeof(int)); - if (!count) continue; /* none */ + mread(fd, (genericptr_t) &count, sizeof(int)); + if (!count) + continue; /* none */ - /* Get the segments. */ - for (curr = (struct wseg *) 0, j = 0; j < count; j++) { - temp = newseg(); - temp->nseg = (struct wseg *) 0; - mread(fd, (genericptr_t) &(temp->wx), sizeof(xchar)); - mread(fd, (genericptr_t) &(temp->wy), sizeof(xchar)); - if (curr) - curr->nseg = temp; - else - wtails[i] = temp; - curr = temp; - } - wheads[i] = curr; + /* Get the segments. */ + for (curr = (struct wseg *) 0, j = 0; j < count; j++) { + temp = newseg(); + temp->nseg = (struct wseg *) 0; + mread(fd, (genericptr_t) & (temp->wx), sizeof(xchar)); + mread(fd, (genericptr_t) & (temp->wy), sizeof(xchar)); + if (curr) + curr->nseg = temp; + else + wtails[i] = temp; + curr = temp; + } + wheads[i] = curr; } mread(fd, (genericptr_t) wgrowtime, sizeof(wgrowtime)); } @@ -553,15 +563,15 @@ rest_worm(fd) */ void place_wsegs(worm) - struct monst *worm; +struct monst *worm; { struct wseg *curr = wtails[worm->wormno]; -/* if (!mtmp->wormno) return; bullet proofing */ + /* if (!mtmp->wormno) return; bullet proofing */ while (curr != wheads[worm->wormno]) { - place_worm_seg(worm,curr->wx,curr->wy); - curr = curr->nseg; + place_worm_seg(worm, curr->wx, curr->wy); + curr = curr->nseg; } } @@ -575,16 +585,16 @@ place_wsegs(worm) */ void remove_worm(worm) - register struct monst *worm; +register struct monst *worm; { register struct wseg *curr = wtails[worm->wormno]; -/* if (!mtmp->wormno) return; bullet proofing */ + /* if (!mtmp->wormno) return; bullet proofing */ while (curr) { - remove_monster(curr->wx, curr->wy); - newsym(curr->wx, curr->wy); - curr = curr->nseg; + remove_monster(curr->wx, curr->wy); + newsym(curr->wx, curr->wy); + curr = curr->nseg; } } @@ -599,19 +609,19 @@ remove_worm(worm) */ void place_worm_tail_randomly(worm, x, y) - struct monst *worm; - xchar x, y; +struct monst *worm; +xchar x, y; { int wnum = worm->wormno; struct wseg *curr = wtails[wnum]; struct wseg *new_tail; register xchar ox = x, oy = y; -/* if (!wnum) return; bullet proofing */ + /* if (!wnum) return; bullet proofing */ - if (wnum && (!wtails[wnum] || !wheads[wnum]) ) { - impossible("place_worm_tail_randomly: wormno is set without a tail!"); - return; + if (wnum && (!wtails[wnum] || !wheads[wnum])) { + impossible("place_worm_tail_randomly: wormno is set without a tail!"); + return; } wheads[wnum] = new_tail = curr; @@ -620,29 +630,29 @@ place_worm_tail_randomly(worm, x, y) new_tail->wx = x; new_tail->wy = y; - while(curr) { - xchar nx, ny; - char tryct = 0; + while (curr) { + xchar nx, ny; + char tryct = 0; - /* pick a random direction from x, y and search for goodpos() */ + /* pick a random direction from x, y and search for goodpos() */ - do { - random_dir(ox, oy, &nx, &ny); - } while (!goodpos(nx, ny, worm, 0) && (tryct++ < 50)); + do { + random_dir(ox, oy, &nx, &ny); + } while (!goodpos(nx, ny, worm, 0) && (tryct++ < 50)); - if (tryct < 50) { - place_worm_seg(worm, nx, ny); - curr->wx = ox = nx; - curr->wy = oy = ny; - wtails[wnum] = curr; - curr = curr->nseg; - wtails[wnum]->nseg = new_tail; - new_tail = wtails[wnum]; - newsym(nx, ny); - } else { /* Oops. Truncate because there was */ - toss_wsegs(curr, FALSE); /* no place for the rest of it */ - curr = (struct wseg *) 0; - } + if (tryct < 50) { + place_worm_seg(worm, nx, ny); + curr->wx = ox = nx; + curr->wy = oy = ny; + wtails[wnum] = curr; + curr = curr->nseg; + wtails[wnum]->nseg = new_tail; + new_tail = wtails[wnum]; + newsym(nx, ny); + } else { /* Oops. Truncate because there was */ + toss_wsegs(curr, FALSE); /* no place for the rest of it */ + curr = (struct wseg *) 0; + } } } @@ -656,31 +666,22 @@ place_worm_tail_randomly(worm, x, y) STATIC_OVL void random_dir(x, y, nx, ny) - register xchar x, y; - register xchar *nx, *ny; +register xchar x, y; +register xchar *nx, *ny; { *nx = x; *ny = y; - *nx += (x > 1 ? /* extreme left ? */ - (x < COLNO ? /* extreme right ? */ - (rn2(3) - 1) /* neither so +1, 0, or -1 */ - : -rn2(2)) /* 0, or -1 */ - : rn2(2)); /* 0, or 1 */ + *nx += (x > 1 ? /* extreme left ? */ + (x < COLNO ? /* extreme right ? */ + (rn2(3) - 1) /* neither so +1, 0, or -1 */ + : -rn2(2)) /* 0, or -1 */ + : rn2(2)); /* 0, or 1 */ - *ny += (*nx == x ? /* same kind of thing with y */ - (y > 1 ? - (y < ROWNO ? - (rn2(2) ? - 1 - : -1) - : -1) - : 1) - : (y > 1 ? - (y < ROWNO ? - (rn2(3) - 1) - : -rn2(2)) - : rn2(2))); + *ny += + (*nx == x ? /* same kind of thing with y */ + (y > 1 ? (y < ROWNO ? (rn2(2) ? 1 : -1) : -1) : 1) + : (y > 1 ? (y < ROWNO ? (rn2(3) - 1) : -rn2(2)) : rn2(2))); } /* count_wsegs() @@ -691,16 +692,16 @@ random_dir(x, y, nx, ny) int count_wsegs(mtmp) - struct monst *mtmp; +struct monst *mtmp; { - register int i=0; + register int i = 0; register struct wseg *curr = (wtails[mtmp->wormno])->nseg; -/* if (!mtmp->wormno) return 0; bullet proofing */ + /* if (!mtmp->wormno) return 0; bullet proofing */ while (curr) { - i++; - curr = curr->nseg; + i++; + curr = curr->nseg; } return i; @@ -708,30 +709,32 @@ count_wsegs(mtmp) /* create_worm_tail() * - * will create a worm tail chain of (num_segs + 1) and return a pointer to it. + * will create a worm tail chain of (num_segs + 1) and return a pointer to + * it. */ STATIC_OVL struct wseg * create_worm_tail(num_segs) - int num_segs; +int num_segs; { - register int i=0; + register int i = 0; register struct wseg *new_tail, *curr; - if (!num_segs) return (struct wseg *)0; + if (!num_segs) + return (struct wseg *) 0; new_tail = curr = newseg(); - curr->nseg = (struct wseg *)0; + curr->nseg = (struct wseg *) 0; curr->wx = 0; curr->wy = 0; while (i < num_segs) { - curr->nseg = newseg(); - curr = curr->nseg; - curr->nseg = (struct wseg *)0; - curr->wx = 0; - curr->wy = 0; - i++; + curr->nseg = newseg(); + curr = curr->nseg; + curr->nseg = (struct wseg *) 0; + curr->wx = 0; + curr->wy = 0; + i++; } return (new_tail); @@ -750,8 +753,9 @@ struct monst *worm; struct wseg *curr = wtails[worm->wormno]; while (curr) { - if(cansee(curr->wx,curr->wy)) return TRUE; - curr = curr->nseg; + if (cansee(curr->wx, curr->wy)) + return TRUE; + curr = curr->nseg; } return FALSE; } @@ -776,28 +780,31 @@ int x1, y1, x2, y2; */ if (distmin(x1, y1, x2, y2) != 1) { - impossible("worm_cross checking for non-adjacent location?"); - return FALSE; + impossible("worm_cross checking for non-adjacent location?"); + return FALSE; } /* attempting to pass between worm segs is only relevant for diagonal */ - if (x1 == x2 || y1 == y2) return FALSE; + if (x1 == x2 || y1 == y2) + return FALSE; /* is the same monster at and at ? */ worm = m_at(x1, y2); - if (!worm || m_at(x2, y1) != worm) return FALSE; + if (!worm || m_at(x2, y1) != worm) + return FALSE; /* same monster is at both adjacent spots, so must be a worm; we need to figure out if the two spots are occupied by consecutive segments */ for (curr = wtails[worm->wormno]; curr; curr = wnxt) { - wnxt = curr->nseg; - if (!wnxt) break; /* no next segment; can't continue */ + wnxt = curr->nseg; + if (!wnxt) + break; /* no next segment; can't continue */ - /* we don't know which of or we'll hit first, but - whichever it is, they're consecutive iff next seg is the other */ - if (curr->wx == x1 && curr->wy == y2) - return (boolean)(wnxt->wx == x2 && wnxt->wy == y1); - if (curr->wx == x2 && curr->wy == y1) - return (boolean)(wnxt->wx == x1 && wnxt->wy == y2); + /* we don't know which of or we'll hit first, but + whichever it is, they're consecutive iff next seg is the other */ + if (curr->wx == x1 && curr->wy == y2) + return (boolean)(wnxt->wx == x2 && wnxt->wy == y1); + if (curr->wx == x2 && curr->wy == y1) + return (boolean)(wnxt->wx == x1 && wnxt->wy == y2); } /* should never reach here... */ return FALSE; diff --git a/src/worn.c b/src/worn.c index 31274d77f..0efb02462 100644 --- a/src/worn.c +++ b/src/worn.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 worn.c $NHDT-Date: 1427580338 2015/03/28 22:05:38 $ $NHDT-Branch: master $:$NHDT-Revision: 1.35 $ */ +/* NetHack 3.6 worn.c $NHDT-Date: 1431192767 2015/05/09 17:32:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.43 $ */ /* NetHack 3.6 worn.c $Date: 2013/11/05 00:57:56 $ $Revision: 1.32 $ */ /* SCCS Id: @(#)worn.c 3.5 2009/02/28 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -6,41 +6,41 @@ #include "hack.h" -STATIC_DCL void FDECL(m_lose_armor, (struct monst *,struct obj *)); -STATIC_DCL void FDECL(m_dowear_type, (struct monst *,long, BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL void FDECL(m_lose_armor, (struct monst *, struct obj *)); +STATIC_DCL void FDECL(m_dowear_type, + (struct monst *, long, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL int FDECL(extra_pref, (struct monst *, struct obj *)); const struct worn { - long w_mask; - struct obj **w_obj; -} worn[] = { - { W_ARM, &uarm }, - { W_ARMC, &uarmc }, - { W_ARMH, &uarmh }, - { W_ARMS, &uarms }, - { W_ARMG, &uarmg }, - { W_ARMF, &uarmf }, - { W_ARMU, &uarmu }, - { W_RINGL, &uleft }, - { W_RINGR, &uright }, - { W_WEP, &uwep }, - { W_SWAPWEP, &uswapwep }, - { W_QUIVER, &uquiver }, - { W_AMUL, &uamul }, - { W_TOOL, &ublindf }, - { W_BALL, &uball }, - { W_CHAIN, &uchain }, - { 0, 0 } -}; + long w_mask; + struct obj **w_obj; +} worn[] = { { W_ARM, &uarm }, + { W_ARMC, &uarmc }, + { W_ARMH, &uarmh }, + { W_ARMS, &uarms }, + { W_ARMG, &uarmg }, + { W_ARMF, &uarmf }, + { W_ARMU, &uarmu }, + { W_RINGL, &uleft }, + { W_RINGR, &uright }, + { W_WEP, &uwep }, + { W_SWAPWEP, &uswapwep }, + { W_QUIVER, &uquiver }, + { W_AMUL, &uamul }, + { W_TOOL, &ublindf }, + { W_BALL, &uball }, + { W_CHAIN, &uchain }, + { 0, 0 } }; /* This only allows for one blocking item per property */ -#define w_blocks(o,m) \ - ((o->otyp == MUMMY_WRAPPING && ((m) & W_ARMC)) ? INVIS : \ - (o->otyp == CORNUTHAUM && ((m) & W_ARMH) && \ - !Role_if(PM_WIZARD)) ? CLAIRVOYANT : 0) - /* note: monsters don't have clairvoyance, so your role - has no significant effect on their use of w_blocks() */ - +#define w_blocks(o, m) \ + ((o->otyp == MUMMY_WRAPPING && ((m) &W_ARMC)) \ + ? INVIS \ + : (o->otyp == CORNUTHAUM && ((m) &W_ARMH) && !Role_if(PM_WIZARD)) \ + ? CLAIRVOYANT \ + : 0) +/* note: monsters don't have clairvoyance, so your role + has no significant effect on their use of w_blocks() */ /* Updated to use the extrinsic and blocked fields. */ void @@ -48,60 +48,62 @@ setworn(obj, mask) register struct obj *obj; long mask; { - register const struct worn *wp; - register struct obj *oobj; - register int p; + register const struct worn *wp; + register struct obj *oobj; + register int p; - if ((mask & (W_ARM|I_SPECIAL)) == (W_ARM|I_SPECIAL)) { - /* restoring saved game; no properties are conferred via skin */ - uskin = obj; - /* assert( !uarm ); */ - } else { - if ((mask & W_ARMOR)) u.uroleplay.nudist = FALSE; - for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) { - oobj = *(wp->w_obj); - if(oobj && !(oobj->owornmask & wp->w_mask)) - impossible("Setworn: mask = %ld.", wp->w_mask); - if(oobj) { - if (u.twoweap && (oobj->owornmask & (W_WEP|W_SWAPWEP))) - u.twoweap = 0; - oobj->owornmask &= ~wp->w_mask; - if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) { - /* leave as "x = x y", here and below, for broken - * compilers */ - p = objects[oobj->otyp].oc_oprop; - u.uprops[p].extrinsic = - u.uprops[p].extrinsic & ~wp->w_mask; - if ((p = w_blocks(oobj,mask)) != 0) - u.uprops[p].blocked &= ~wp->w_mask; - if (oobj->oartifact) - set_artifact_intrinsic(oobj, 0, mask); - } - } - *(wp->w_obj) = obj; - if(obj) { - obj->owornmask |= wp->w_mask; - /* Prevent getting/blocking intrinsics from wielding - * potions, through the quiver, etc. - * Allow weapon-tools, too. - * wp_mask should be same as mask at this point. - */ - if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) { - if (obj->oclass == WEAPON_CLASS || is_weptool(obj) || - mask != W_WEP) { - p = objects[obj->otyp].oc_oprop; - u.uprops[p].extrinsic = - u.uprops[p].extrinsic | wp->w_mask; - if ((p = w_blocks(obj, mask)) != 0) - u.uprops[p].blocked |= wp->w_mask; - } - if (obj->oartifact) - set_artifact_intrinsic(obj, 1, mask); - } - } - } - } - update_inventory(); + if ((mask & (W_ARM | I_SPECIAL)) == (W_ARM | I_SPECIAL)) { + /* restoring saved game; no properties are conferred via skin */ + uskin = obj; + /* assert( !uarm ); */ + } else { + if ((mask & W_ARMOR)) + u.uroleplay.nudist = FALSE; + for (wp = worn; wp->w_mask; wp++) + if (wp->w_mask & mask) { + oobj = *(wp->w_obj); + if (oobj && !(oobj->owornmask & wp->w_mask)) + impossible("Setworn: mask = %ld.", wp->w_mask); + if (oobj) { + if (u.twoweap && (oobj->owornmask & (W_WEP | W_SWAPWEP))) + u.twoweap = 0; + oobj->owornmask &= ~wp->w_mask; + if (wp->w_mask & ~(W_SWAPWEP | W_QUIVER)) { + /* leave as "x = x y", here and below, for broken + * compilers */ + p = objects[oobj->otyp].oc_oprop; + u.uprops[p].extrinsic = + u.uprops[p].extrinsic & ~wp->w_mask; + if ((p = w_blocks(oobj, mask)) != 0) + u.uprops[p].blocked &= ~wp->w_mask; + if (oobj->oartifact) + set_artifact_intrinsic(oobj, 0, mask); + } + } + *(wp->w_obj) = obj; + if (obj) { + obj->owornmask |= wp->w_mask; + /* Prevent getting/blocking intrinsics from wielding + * potions, through the quiver, etc. + * Allow weapon-tools, too. + * wp_mask should be same as mask at this point. + */ + if (wp->w_mask & ~(W_SWAPWEP | W_QUIVER)) { + if (obj->oclass == WEAPON_CLASS || is_weptool(obj) + || mask != W_WEP) { + p = objects[obj->otyp].oc_oprop; + u.uprops[p].extrinsic = + u.uprops[p].extrinsic | wp->w_mask; + if ((p = w_blocks(obj, mask)) != 0) + u.uprops[p].blocked |= wp->w_mask; + } + if (obj->oartifact) + set_artifact_intrinsic(obj, 1, mask); + } + } + } + } + update_inventory(); } /* called e.g. when obj is destroyed */ @@ -110,23 +112,25 @@ void setnotworn(obj) register struct obj *obj; { - register const struct worn *wp; - register int p; + register const struct worn *wp; + register int p; - if (!obj) return; - if (obj == uwep || obj == uswapwep) u.twoweap = 0; - for(wp = worn; wp->w_mask; wp++) - if(obj == *(wp->w_obj)) { - *(wp->w_obj) = 0; - p = objects[obj->otyp].oc_oprop; - u.uprops[p].extrinsic = u.uprops[p].extrinsic & ~wp->w_mask; - obj->owornmask &= ~wp->w_mask; - if (obj->oartifact) - set_artifact_intrinsic(obj, 0, wp->w_mask); - if ((p = w_blocks(obj,wp->w_mask)) != 0) - u.uprops[p].blocked &= ~wp->w_mask; - } - update_inventory(); + if (!obj) + return; + if (obj == uwep || obj == uswapwep) + u.twoweap = 0; + for (wp = worn; wp->w_mask; wp++) + if (obj == *(wp->w_obj)) { + *(wp->w_obj) = 0; + p = objects[obj->otyp].oc_oprop; + u.uprops[p].extrinsic = u.uprops[p].extrinsic & ~wp->w_mask; + obj->owornmask &= ~wp->w_mask; + if (obj->oartifact) + set_artifact_intrinsic(obj, 0, wp->w_mask); + if ((p = w_blocks(obj, wp->w_mask)) != 0) + u.uprops[p].blocked &= ~wp->w_mask; + } + update_inventory(); } /* return a bitmask of the equipment slot(s) a given item might be worn in */ @@ -137,52 +141,68 @@ struct obj *obj; int otyp = obj->otyp; /* practically any item can be wielded or quivered; it's up to our caller to handle such things--we assume "normal" usage */ - long res = 0L; /* default: can't be worn anywhere */ + long res = 0L; /* default: can't be worn anywhere */ switch (obj->oclass) { case AMULET_CLASS: - res = W_AMUL; /* WORN_AMUL */ - break; + res = W_AMUL; /* WORN_AMUL */ + break; case RING_CLASS: - res = W_RINGL|W_RINGR; /* W_RING, BOTH_SIDES */ - break; + res = W_RINGL | W_RINGR; /* W_RING, BOTH_SIDES */ + break; case ARMOR_CLASS: - switch (objects[otyp].oc_armcat) { - case ARM_SUIT: res = W_ARM; break; /* WORN_ARMOR */ - case ARM_SHIELD: res = W_ARMS; break; /* WORN_SHIELD */ - case ARM_HELM: res = W_ARMH; break; /* WORN_HELMET */ - case ARM_GLOVES: res = W_ARMG; break; /* WORN_GLOVES */ - case ARM_BOOTS: res = W_ARMF; break; /* WORN_BOOTS */ - case ARM_CLOAK: res = W_ARMC; break; /* WORN_CLOAK */ - case ARM_SHIRT: res = W_ARMU; break; /* WORN_SHIRT */ - } - break; + switch (objects[otyp].oc_armcat) { + case ARM_SUIT: + res = W_ARM; + break; /* WORN_ARMOR */ + case ARM_SHIELD: + res = W_ARMS; + break; /* WORN_SHIELD */ + case ARM_HELM: + res = W_ARMH; + break; /* WORN_HELMET */ + case ARM_GLOVES: + res = W_ARMG; + break; /* WORN_GLOVES */ + case ARM_BOOTS: + res = W_ARMF; + break; /* WORN_BOOTS */ + case ARM_CLOAK: + res = W_ARMC; + break; /* WORN_CLOAK */ + case ARM_SHIRT: + res = W_ARMU; + break; /* WORN_SHIRT */ + } + break; case WEAPON_CLASS: - res = W_WEP|W_SWAPWEP; - if (objects[otyp].oc_merge) res |= W_QUIVER; - break; + res = W_WEP | W_SWAPWEP; + if (objects[otyp].oc_merge) + res |= W_QUIVER; + break; case TOOL_CLASS: - if (otyp == BLINDFOLD || otyp == TOWEL || otyp == LENSES) - res = W_TOOL; /* WORN_BLINDF */ - else if (is_weptool(obj) || otyp == TIN_OPENER) - res = W_WEP|W_SWAPWEP; - else if (otyp == SADDLE) - res = W_SADDLE; - break; + if (otyp == BLINDFOLD || otyp == TOWEL || otyp == LENSES) + res = W_TOOL; /* WORN_BLINDF */ + else if (is_weptool(obj) || otyp == TIN_OPENER) + res = W_WEP | W_SWAPWEP; + else if (otyp == SADDLE) + res = W_SADDLE; + break; case FOOD_CLASS: - if (obj->otyp == MEAT_RING) res = W_RINGL|W_RINGR; - break; + if (obj->otyp == MEAT_RING) + res = W_RINGL | W_RINGR; + break; case GEM_CLASS: - res = W_QUIVER; - break; + res = W_QUIVER; + break; case BALL_CLASS: - res = W_BALL; - break; + res = W_BALL; + break; case CHAIN_CLASS: - res = W_CHAIN; - break; + res = W_CHAIN; + break; default: - break; + break; } return res; } @@ -191,81 +211,89 @@ void mon_set_minvis(mon) struct monst *mon; { - mon->perminvis = 1; - if (!mon->invis_blkd) { - mon->minvis = 1; - newsym(mon->mx, mon->my); /* make it disappear */ - if (mon->wormno) see_wsegs(mon); /* and any tail too */ - } + mon->perminvis = 1; + if (!mon->invis_blkd) { + mon->minvis = 1; + newsym(mon->mx, mon->my); /* make it disappear */ + if (mon->wormno) + see_wsegs(mon); /* and any tail too */ + } } void mon_adjust_speed(mon, adjust, obj) struct monst *mon; -int adjust; /* positive => increase speed, negative => decrease */ -struct obj *obj; /* item to make known if effect can be seen */ +int adjust; /* positive => increase speed, negative => decrease */ +struct obj *obj; /* item to make known if effect can be seen */ { struct obj *otmp; boolean give_msg = !in_mklev, petrify = FALSE; unsigned int oldspeed = mon->mspeed; switch (adjust) { - case 2: - mon->permspeed = MFAST; - give_msg = FALSE; /* special case monster creation */ - break; - case 1: - if (mon->permspeed == MSLOW) mon->permspeed = 0; - else mon->permspeed = MFAST; - break; - case 0: /* just check for worn speed boots */ - break; - case -1: - if (mon->permspeed == MFAST) mon->permspeed = 0; - else mon->permspeed = MSLOW; - break; - case -2: - mon->permspeed = MSLOW; - give_msg = FALSE; /* (not currently used) */ - break; - case -3: /* petrification */ - /* take away intrinsic speed but don't reduce normal speed */ - if (mon->permspeed == MFAST) mon->permspeed = 0; - petrify = TRUE; - break; - case -4: /* green slime */ - if (mon->permspeed == MFAST) mon->permspeed = 0; - give_msg = FALSE; - break; + case 2: + mon->permspeed = MFAST; + give_msg = FALSE; /* special case monster creation */ + break; + case 1: + if (mon->permspeed == MSLOW) + mon->permspeed = 0; + else + mon->permspeed = MFAST; + break; + case 0: /* just check for worn speed boots */ + break; + case -1: + if (mon->permspeed == MFAST) + mon->permspeed = 0; + else + mon->permspeed = MSLOW; + break; + case -2: + mon->permspeed = MSLOW; + give_msg = FALSE; /* (not currently used) */ + break; + case -3: /* petrification */ + /* take away intrinsic speed but don't reduce normal speed */ + if (mon->permspeed == MFAST) + mon->permspeed = 0; + petrify = TRUE; + break; + case -4: /* green slime */ + if (mon->permspeed == MFAST) + mon->permspeed = 0; + give_msg = FALSE; + break; } for (otmp = mon->minvent; otmp; otmp = otmp->nobj) - if (otmp->owornmask && objects[otmp->otyp].oc_oprop == FAST) - break; - if (otmp) /* speed boots */ - mon->mspeed = MFAST; + if (otmp->owornmask && objects[otmp->otyp].oc_oprop == FAST) + break; + if (otmp) /* speed boots */ + mon->mspeed = MFAST; else - mon->mspeed = mon->permspeed; + mon->mspeed = mon->permspeed; /* no message if monster is immobile (temp or perm) or unseen */ - if (give_msg && (mon->mspeed != oldspeed || petrify) && - mon->data->mmove && !(mon->mfrozen || mon->msleeping) && - canseemon(mon)) { - /* fast to slow (skipping intermediate state) or vice versa */ - const char *howmuch = (mon->mspeed + oldspeed == MFAST + MSLOW) ? - "much " : ""; + if (give_msg && (mon->mspeed != oldspeed || petrify) && mon->data->mmove + && !(mon->mfrozen || mon->msleeping) && canseemon(mon)) { + /* fast to slow (skipping intermediate state) or vice versa */ + const char *howmuch = + (mon->mspeed + oldspeed == MFAST + MSLOW) ? "much " : ""; - if (petrify) { - /* mimic the player's petrification countdown; "slowing down" - even if fast movement rate retained via worn speed boots */ - if (flags.verbose) pline("%s is slowing down.", Monnam(mon)); - } else if (adjust > 0 || mon->mspeed == MFAST) - pline("%s is suddenly moving %sfaster.", Monnam(mon), howmuch); - else - pline("%s seems to be moving %sslower.", Monnam(mon), howmuch); + if (petrify) { + /* mimic the player's petrification countdown; "slowing down" + even if fast movement rate retained via worn speed boots */ + if (flags.verbose) + pline("%s is slowing down.", Monnam(mon)); + } else if (adjust > 0 || mon->mspeed == MFAST) + pline("%s is suddenly moving %sfaster.", Monnam(mon), howmuch); + else + pline("%s seems to be moving %sslower.", Monnam(mon), howmuch); - /* might discover an object if we see the speed change happen */ - if (obj != 0) learnwand(obj); + /* might discover an object if we see the speed change happen */ + if (obj != 0) + learnwand(obj); } } @@ -282,126 +310,128 @@ boolean on, silently; int which = (int) objects[obj->otyp].oc_oprop; unseen = !canseemon(mon); - if (!which) goto maybe_blocks; + if (!which) + goto maybe_blocks; if (on) { - switch (which) { - case INVIS: - mon->minvis = !mon->invis_blkd; - break; - case FAST: - { - boolean save_in_mklev = in_mklev; - if (silently) in_mklev = TRUE; - mon_adjust_speed(mon, 0, obj); - in_mklev = save_in_mklev; - break; - } - /* properties handled elsewhere */ - case ANTIMAGIC: - case REFLECTING: - break; - /* properties which have no effect for monsters */ - case CLAIRVOYANT: - case STEALTH: - case TELEPAT: - break; - /* properties which should have an effect but aren't implemented */ - case LEVITATION: - case WWALKING: - break; - /* properties which maybe should have an effect but don't */ - case DISPLACED: - case FUMBLING: - case JUMPING: - case PROTECTION: - break; - default: - if (which <= 8) { /* 1 thru 8 correspond to MR_xxx mask values */ - /* FIRE,COLD,SLEEP,DISINT,SHOCK,POISON,ACID,STONE */ - mask = (uchar) (1 << (which - 1)); - mon->mintrinsics |= (unsigned short) mask; - } - break; - } - } else { /* off */ - switch (which) { - case INVIS: - mon->minvis = mon->perminvis; - break; - case FAST: - { - boolean save_in_mklev = in_mklev; - if (silently) in_mklev = TRUE; - mon_adjust_speed(mon, 0, obj); - in_mklev = save_in_mklev; - break; - } - case FIRE_RES: - case COLD_RES: - case SLEEP_RES: - case DISINT_RES: - case SHOCK_RES: - case POISON_RES: - case ACID_RES: - case STONE_RES: - mask = (uchar) (1 << (which - 1)); - /* If the monster doesn't have this resistance intrinsically, - check whether any other worn item confers it. Note that - we don't currently check for anything conferred via simply - carrying an object. */ - if (!(mon->data->mresists & mask)) { - for (otmp = mon->minvent; otmp; otmp = otmp->nobj) - if (otmp->owornmask && - (int) objects[otmp->otyp].oc_oprop == which) - break; - if (!otmp) - mon->mintrinsics &= ~((unsigned short) mask); - } - break; - default: - break; - } + switch (which) { + case INVIS: + mon->minvis = !mon->invis_blkd; + break; + case FAST: { + boolean save_in_mklev = in_mklev; + if (silently) + in_mklev = TRUE; + mon_adjust_speed(mon, 0, obj); + in_mklev = save_in_mklev; + break; + } + /* properties handled elsewhere */ + case ANTIMAGIC: + case REFLECTING: + break; + /* properties which have no effect for monsters */ + case CLAIRVOYANT: + case STEALTH: + case TELEPAT: + break; + /* properties which should have an effect but aren't implemented */ + case LEVITATION: + case WWALKING: + break; + /* properties which maybe should have an effect but don't */ + case DISPLACED: + case FUMBLING: + case JUMPING: + case PROTECTION: + break; + default: + if (which <= 8) { /* 1 thru 8 correspond to MR_xxx mask values */ + /* FIRE,COLD,SLEEP,DISINT,SHOCK,POISON,ACID,STONE */ + mask = (uchar)(1 << (which - 1)); + mon->mintrinsics |= (unsigned short) mask; + } + break; + } + } else { /* off */ + switch (which) { + case INVIS: + mon->minvis = mon->perminvis; + break; + case FAST: { + boolean save_in_mklev = in_mklev; + if (silently) + in_mklev = TRUE; + mon_adjust_speed(mon, 0, obj); + in_mklev = save_in_mklev; + break; + } + case FIRE_RES: + case COLD_RES: + case SLEEP_RES: + case DISINT_RES: + case SHOCK_RES: + case POISON_RES: + case ACID_RES: + case STONE_RES: + mask = (uchar)(1 << (which - 1)); + /* If the monster doesn't have this resistance intrinsically, + check whether any other worn item confers it. Note that + we don't currently check for anything conferred via simply + carrying an object. */ + if (!(mon->data->mresists & mask)) { + for (otmp = mon->minvent; otmp; otmp = otmp->nobj) + if (otmp->owornmask + && (int) objects[otmp->otyp].oc_oprop == which) + break; + if (!otmp) + mon->mintrinsics &= ~((unsigned short) mask); + } + break; + default: + break; + } } - maybe_blocks: +maybe_blocks: /* obj->owornmask has been cleared by this point, so we can't use it. However, since monsters don't wield armor, we don't have to guard against that and can get away with a blanket worn-mask value. */ - switch (w_blocks(obj,~0L)) { - case INVIS: - mon->invis_blkd = on ? 1 : 0; - mon->minvis = on ? 0 : mon->perminvis; - break; - default: - break; + switch (w_blocks(obj, ~0L)) { + case INVIS: + mon->invis_blkd = on ? 1 : 0; + mon->minvis = on ? 0 : mon->perminvis; + break; + default: + break; } - if (!on && mon == u.usteed && obj->otyp == SADDLE) - dismount_steed(DISMOUNT_FELL); + if (!on && mon == u.usteed && obj->otyp == SADDLE) + dismount_steed(DISMOUNT_FELL); /* if couldn't see it but now can, or vice versa, update display */ if (!silently && (unseen ^ !canseemon(mon))) - newsym(mon->mx, mon->my); + newsym(mon->mx, mon->my); } int find_mac(mon) register struct monst *mon; { - register struct obj *obj; - int base = mon->data->ac; - long mwflags = mon->misc_worn_check; + register struct obj *obj; + int base = mon->data->ac; + long mwflags = mon->misc_worn_check; - for (obj = mon->minvent; obj; obj = obj->nobj) { - if (obj->owornmask & mwflags) - base -= ARM_BONUS(obj); - /* since ARM_BONUS is positive, subtracting it increases AC */ - } - return base; + for (obj = mon->minvent; obj; obj = obj->nobj) { + if (obj->owornmask & mwflags) + base -= ARM_BONUS(obj); + /* since ARM_BONUS is positive, subtracting it increases AC */ + } + return base; } -/* weapons are handled separately; rings and eyewear aren't used by monsters */ +/* weapons are handled separately; rings and eyewear aren't used by monsters + */ /* Wear the best object of each type that the monster has. During creation, * the monster can put everything on at once; otherwise, wearing takes time. @@ -422,36 +452,37 @@ register struct monst *mon; boolean creation; { #define RACE_EXCEPTION TRUE - /* Note the restrictions here are the same as in dowear in do_wear.c - * except for the additional restriction on intelligence. (Players - * are always intelligent, even if polymorphed). - */ - if (verysmall(mon->data) || nohands(mon->data) || is_animal(mon->data)) - return; - /* give mummies a chance to wear their wrappings - * and let skeletons wear their initial armor */ - if (mindless(mon->data) && (!creation || - (mon->data->mlet != S_MUMMY && mon->data != &mons[PM_SKELETON]))) - return; + /* Note the restrictions here are the same as in dowear in do_wear.c + * except for the additional restriction on intelligence. (Players + * are always intelligent, even if polymorphed). + */ + if (verysmall(mon->data) || nohands(mon->data) || is_animal(mon->data)) + return; + /* give mummies a chance to wear their wrappings + * and let skeletons wear their initial armor */ + if (mindless(mon->data) + && (!creation || (mon->data->mlet != S_MUMMY + && mon->data != &mons[PM_SKELETON]))) + return; - m_dowear_type(mon, W_AMUL, creation, FALSE); - /* can't put on shirt if already wearing suit */ - if (!cantweararm(mon->data) && !(mon->misc_worn_check & W_ARM)) - m_dowear_type(mon, W_ARMU, creation, FALSE); - /* treating small as a special case allows - hobbits, gnomes, and kobolds to wear cloaks */ - if (!cantweararm(mon->data) || mon->data->msize == MZ_SMALL) - m_dowear_type(mon, W_ARMC, creation, FALSE); - m_dowear_type(mon, W_ARMH, creation, FALSE); - if (!MON_WEP(mon) || !bimanual(MON_WEP(mon))) - m_dowear_type(mon, W_ARMS, creation, FALSE); - m_dowear_type(mon, W_ARMG, creation, FALSE); - if (!slithy(mon->data) && mon->data->mlet != S_CENTAUR) - m_dowear_type(mon, W_ARMF, creation, FALSE); - if (!cantweararm(mon->data)) - m_dowear_type(mon, W_ARM, creation, FALSE); - else - m_dowear_type(mon, W_ARM, creation, RACE_EXCEPTION); + m_dowear_type(mon, W_AMUL, creation, FALSE); + /* can't put on shirt if already wearing suit */ + if (!cantweararm(mon->data) && !(mon->misc_worn_check & W_ARM)) + m_dowear_type(mon, W_ARMU, creation, FALSE); + /* treating small as a special case allows + hobbits, gnomes, and kobolds to wear cloaks */ + if (!cantweararm(mon->data) || mon->data->msize == MZ_SMALL) + m_dowear_type(mon, W_ARMC, creation, FALSE); + m_dowear_type(mon, W_ARMH, creation, FALSE); + if (!MON_WEP(mon) || !bimanual(MON_WEP(mon))) + m_dowear_type(mon, W_ARMS, creation, FALSE); + m_dowear_type(mon, W_ARMG, creation, FALSE); + if (!slithy(mon->data) && mon->data->mlet != S_CENTAUR) + m_dowear_type(mon, W_ARMF, creation, FALSE); + if (!cantweararm(mon->data)) + m_dowear_type(mon, W_ARM, creation, FALSE); + else + m_dowear_type(mon, W_ARM, creation, RACE_EXCEPTION); } STATIC_OVL void @@ -461,121 +492,140 @@ long flag; boolean creation; boolean racialexception; { - struct obj *old, *best, *obj; - int m_delay = 0; - int unseen = !canseemon(mon); - boolean autocurse; - char nambuf[BUFSZ]; + struct obj *old, *best, *obj; + int m_delay = 0; + int unseen = !canseemon(mon); + boolean autocurse; + char nambuf[BUFSZ]; - if (mon->mfrozen) return; /* probably putting previous item on */ + if (mon->mfrozen) + return; /* probably putting previous item on */ - /* Get a copy of monster's name before altering its visibility */ - Strcpy(nambuf, See_invisible ? Monnam(mon) : mon_nam(mon)); + /* Get a copy of monster's name before altering its visibility */ + Strcpy(nambuf, See_invisible ? Monnam(mon) : mon_nam(mon)); - old = which_armor(mon, flag); - if (old && old->cursed) return; - if (old && flag == W_AMUL) return; /* no such thing as better amulets */ - best = old; + old = which_armor(mon, flag); + if (old && old->cursed) + return; + if (old && flag == W_AMUL) + return; /* no such thing as better amulets */ + best = old; - for(obj = mon->minvent; obj; obj = obj->nobj) { - switch(flag) { - case W_AMUL: - if (obj->oclass != AMULET_CLASS || - (obj->otyp != AMULET_OF_LIFE_SAVING && - obj->otyp != AMULET_OF_REFLECTION)) - continue; - best = obj; - goto outer_break; /* no such thing as better amulets */ - case W_ARMU: - if (!is_shirt(obj)) continue; - break; - case W_ARMC: - if (!is_cloak(obj)) continue; - break; - case W_ARMH: - if (!is_helmet(obj)) continue; - /* changing alignment is not implemented for monsters; - priests and minions could change alignment but wouldn't - want to, so they reject helms of opposite alignment */ - if (obj->otyp == HELM_OF_OPPOSITE_ALIGNMENT && - (mon->ispriest || mon->isminion)) continue; - /* (flimsy exception matches polyself handling) */ - if (has_horns(mon->data) && !is_flimsy(obj)) continue; - break; - case W_ARMS: - if (!is_shield(obj)) continue; - break; - case W_ARMG: - if (!is_gloves(obj)) continue; - break; - case W_ARMF: - if (!is_boots(obj)) continue; - break; - case W_ARM: - if (!is_suit(obj)) continue; - if (racialexception && (racial_exception(mon, obj) < 1)) continue; - break; - } - if (obj->owornmask) continue; - /* I'd like to define a VISIBLE_ARM_BONUS which doesn't assume the - * monster knows obj->spe, but if I did that, a monster would keep - * switching forever between two -2 caps since when it took off one - * it would forget spe and once again think the object is better - * than what it already has. - */ - if (best && (ARM_BONUS(best) + extra_pref(mon,best) >= ARM_BONUS(obj) + extra_pref(mon,obj))) - continue; - best = obj; - } + for (obj = mon->minvent; obj; obj = obj->nobj) { + switch (flag) { + case W_AMUL: + if (obj->oclass != AMULET_CLASS + || (obj->otyp != AMULET_OF_LIFE_SAVING + && obj->otyp != AMULET_OF_REFLECTION)) + continue; + best = obj; + goto outer_break; /* no such thing as better amulets */ + case W_ARMU: + if (!is_shirt(obj)) + continue; + break; + case W_ARMC: + if (!is_cloak(obj)) + continue; + break; + case W_ARMH: + if (!is_helmet(obj)) + continue; + /* changing alignment is not implemented for monsters; + priests and minions could change alignment but wouldn't + want to, so they reject helms of opposite alignment */ + if (obj->otyp == HELM_OF_OPPOSITE_ALIGNMENT + && (mon->ispriest || mon->isminion)) + continue; + /* (flimsy exception matches polyself handling) */ + if (has_horns(mon->data) && !is_flimsy(obj)) + continue; + break; + case W_ARMS: + if (!is_shield(obj)) + continue; + break; + case W_ARMG: + if (!is_gloves(obj)) + continue; + break; + case W_ARMF: + if (!is_boots(obj)) + continue; + break; + case W_ARM: + if (!is_suit(obj)) + continue; + if (racialexception && (racial_exception(mon, obj) < 1)) + continue; + break; + } + if (obj->owornmask) + continue; + /* I'd like to define a VISIBLE_ARM_BONUS which doesn't assume the + * monster knows obj->spe, but if I did that, a monster would keep + * switching forever between two -2 caps since when it took off one + * it would forget spe and once again think the object is better + * than what it already has. + */ + if (best && (ARM_BONUS(best) + extra_pref(mon, best) + >= ARM_BONUS(obj) + extra_pref(mon, obj))) + continue; + best = obj; + } outer_break: - if (!best || best == old) return; + if (!best || best == old) + return; - /* same auto-cursing behavior as for hero */ - autocurse = ((best->otyp == HELM_OF_OPPOSITE_ALIGNMENT || - best->otyp == DUNCE_CAP) && !best->cursed); - /* if wearing a cloak, account for the time spent removing - and re-wearing it when putting on a suit or shirt */ - if ((flag == W_ARM || flag == W_ARMU) && (mon->misc_worn_check & W_ARMC)) - m_delay += 2; - /* when upgrading a piece of armor, account for time spent - taking off current one */ - if (old) - m_delay += objects[old->otyp].oc_delay; + /* same auto-cursing behavior as for hero */ + autocurse = ((best->otyp == HELM_OF_OPPOSITE_ALIGNMENT + || best->otyp == DUNCE_CAP) && !best->cursed); + /* if wearing a cloak, account for the time spent removing + and re-wearing it when putting on a suit or shirt */ + if ((flag == W_ARM || flag == W_ARMU) && (mon->misc_worn_check & W_ARMC)) + m_delay += 2; + /* when upgrading a piece of armor, account for time spent + taking off current one */ + if (old) + m_delay += objects[old->otyp].oc_delay; - if (old) /* do this first to avoid "(being worn)" */ - old->owornmask = 0L; - if (!creation) { - if (canseemon(mon)) { - char buf[BUFSZ]; + if (old) /* do this first to avoid "(being worn)" */ + old->owornmask = 0L; + if (!creation) { + if (canseemon(mon)) { + char buf[BUFSZ]; - if (old) - Sprintf(buf, " removes %s and", distant_name(old, doname)); - else - buf[0] = '\0'; - pline("%s%s puts on %s.", Monnam(mon), - buf, distant_name(best,doname)); - if (autocurse) - pline("%s %s %s %s for a moment.", - s_suffix(Monnam(mon)), simpleonames(best), - otense(best, "glow"), hcolor(NH_BLACK)); - } /* can see it */ - m_delay += objects[best->otyp].oc_delay; - mon->mfrozen = m_delay; - if (mon->mfrozen) mon->mcanmove = 0; - } - if (old) - update_mon_intrinsics(mon, old, FALSE, creation); - mon->misc_worn_check |= flag; - best->owornmask |= flag; - if (autocurse) curse(best); - update_mon_intrinsics(mon, best, TRUE, creation); - /* if couldn't see it but now can, or vice versa, */ - if (!creation && (unseen ^ !canseemon(mon))) { - if (mon->minvis && !See_invisible) { - pline("Suddenly you cannot see %s.", nambuf); - makeknown(best->otyp); - } /* else if (!mon->minvis) pline("%s suddenly appears!", Amonnam(mon)); */ - } + if (old) + Sprintf(buf, " removes %s and", distant_name(old, doname)); + else + buf[0] = '\0'; + pline("%s%s puts on %s.", Monnam(mon), buf, + distant_name(best, doname)); + if (autocurse) + pline("%s %s %s %s for a moment.", s_suffix(Monnam(mon)), + simpleonames(best), otense(best, "glow"), + hcolor(NH_BLACK)); + } /* can see it */ + m_delay += objects[best->otyp].oc_delay; + mon->mfrozen = m_delay; + if (mon->mfrozen) + mon->mcanmove = 0; + } + if (old) + update_mon_intrinsics(mon, old, FALSE, creation); + mon->misc_worn_check |= flag; + best->owornmask |= flag; + if (autocurse) + curse(best); + update_mon_intrinsics(mon, best, TRUE, creation); + /* if couldn't see it but now can, or vice versa, */ + if (!creation && (unseen ^ !canseemon(mon))) { + if (mon->minvis && !See_invisible) { + pline("Suddenly you cannot see %s.", nambuf); + makeknown(best->otyp); + } /* else if (!mon->minvis) pline("%s suddenly appears!", + Amonnam(mon)); */ + } } #undef RACE_EXCEPTION @@ -584,26 +634,34 @@ which_armor(mon, flag) struct monst *mon; long flag; { - if (mon == &youmonst) { - switch (flag) { - case W_ARM: return uarm; - case W_ARMC: return uarmc; - case W_ARMH: return uarmh; - case W_ARMS: return uarms; - case W_ARMG: return uarmg; - case W_ARMF: return uarmf; - case W_ARMU: return uarmu; - default: - impossible("bad flag in which_armor"); - return 0; - } - } else { - register struct obj *obj; - - for(obj = mon->minvent; obj; obj = obj->nobj) - if (obj->owornmask & flag) return obj; - return((struct obj *)0); + if (mon == &youmonst) { + switch (flag) { + case W_ARM: + return uarm; + case W_ARMC: + return uarmc; + case W_ARMH: + return uarmh; + case W_ARMS: + return uarms; + case W_ARMG: + return uarmg; + case W_ARMF: + return uarmf; + case W_ARMU: + return uarmu; + default: + impossible("bad flag in which_armor"); + return 0; } + } else { + register struct obj *obj; + + for (obj = mon->minvent; obj; obj = obj->nobj) + if (obj->owornmask & flag) + return obj; + return ((struct obj *) 0); + } } /* remove an item of armor and then drop it */ @@ -612,32 +670,32 @@ m_lose_armor(mon, obj) struct monst *mon; struct obj *obj; { - mon->misc_worn_check &= ~obj->owornmask; - if (obj->owornmask) - update_mon_intrinsics(mon, obj, FALSE, FALSE); - obj->owornmask = 0L; + mon->misc_worn_check &= ~obj->owornmask; + if (obj->owornmask) + update_mon_intrinsics(mon, obj, FALSE, FALSE); + obj->owornmask = 0L; - obj_extract_self(obj); - place_object(obj, mon->mx, mon->my); - /* call stackobj() if we ever drop anything that can merge */ - newsym(mon->mx, mon->my); + obj_extract_self(obj); + place_object(obj, mon->mx, mon->my); + /* call stackobj() if we ever drop anything that can merge */ + newsym(mon->mx, mon->my); } /* all objects with their bypass bit set should now be reset to normal */ void clear_bypasses() { - struct obj *otmp, *nobj; - struct monst *mtmp; + struct obj *otmp, *nobj; + struct monst *mtmp; - for (otmp = fobj; otmp; otmp = nobj) { - nobj = otmp->nobj; - if (otmp->bypass) { - otmp->bypass = 0; - /* bypass will have inhibited any stacking, but since it's - used for polymorph handling, the objects here probably - have been transformed and won't be stacked in the usual - manner afterwards; so don't bother with this */ + for (otmp = fobj; otmp; otmp = nobj) { + nobj = otmp->nobj; + if (otmp->bypass) { + otmp->bypass = 0; +/* bypass will have inhibited any stacking, but since it's + used for polymorph handling, the objects here probably + have been transformed and won't be stacked in the usual + manner afterwards; so don't bother with this */ #if 0 if (objects[otmp->otyp].oc_merge) { xchar ox, oy; @@ -646,45 +704,47 @@ clear_bypasses() stack_object(otmp); newsym(ox, oy); } -#endif /*0*/ - } - } - for (otmp = invent; otmp; otmp = otmp->nobj) - otmp->bypass = 0; - for (otmp = migrating_objs; otmp; otmp = otmp->nobj) - otmp->bypass = 0; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) continue; - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - otmp->bypass = 0; - } - for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) { - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) - otmp->bypass = 0; - } - /* billobjs and mydogs chains don't matter here */ - context.bypasses = FALSE; +#endif /*0*/ + } + } + for (otmp = invent; otmp; otmp = otmp->nobj) + otmp->bypass = 0; + for (otmp = migrating_objs; otmp; otmp = otmp->nobj) + otmp->bypass = 0; + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (DEADMONSTER(mtmp)) + continue; + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + otmp->bypass = 0; + } + for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) { + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) + otmp->bypass = 0; + } + /* billobjs and mydogs chains don't matter here */ + context.bypasses = FALSE; } void bypass_obj(obj) struct obj *obj; { - obj->bypass = 1; - context.bypasses = TRUE; + obj->bypass = 1; + context.bypasses = TRUE; } /* set or clear the bypass bit in a list of objects */ void bypass_objlist(objchain, on) struct obj *objchain; -boolean on; /* TRUE => set, FALSE => clear */ +boolean on; /* TRUE => set, FALSE => clear */ { - if (on && objchain) context.bypasses = TRUE; - while (objchain) { - objchain->bypass = on ? 1 : 0; - objchain = objchain->nobj; - } + if (on && objchain) + context.bypasses = TRUE; + while (objchain) { + objchain->bypass = on ? 1 : 0; + objchain = objchain->nobj; + } } /* return the first object without its bypass bit set; set that bit @@ -693,14 +753,14 @@ struct obj * nxt_unbypassed_obj(objchain) struct obj *objchain; { - while (objchain) { - if (!objchain->bypass) { - bypass_obj(objchain); - break; - } - objchain = objchain->nobj; - } - return objchain; + while (objchain) { + if (!objchain->bypass) { + bypass_obj(objchain); + break; + } + objchain = objchain->nobj; + } + return objchain; } void @@ -708,155 +768,159 @@ mon_break_armor(mon, polyspot) struct monst *mon; boolean polyspot; { - register struct obj *otmp; - struct permonst *mdat = mon->data; - boolean vis = cansee(mon->mx, mon->my); - boolean handless_or_tiny = (nohands(mdat) || verysmall(mdat)); - const char *pronoun = mhim(mon), - *ppronoun = mhis(mon); + register struct obj *otmp; + struct permonst *mdat = mon->data; + boolean vis = cansee(mon->mx, mon->my); + boolean handless_or_tiny = (nohands(mdat) || verysmall(mdat)); + const char *pronoun = mhim(mon), *ppronoun = mhis(mon); - if (breakarm(mdat)) { - if ((otmp = which_armor(mon, W_ARM)) != 0) { - if ((Is_dragon_scales(otmp) && - mdat == Dragon_scales_to_pm(otmp)) || - (Is_dragon_mail(otmp) && mdat == Dragon_mail_to_pm(otmp))) - ; /* no message here; - "the dragon merges with his scaly armor" is odd - and the monster's previous form is already gone */ - else if (vis) - pline("%s breaks out of %s armor!", Monnam(mon), ppronoun); - else - You_hear("a cracking sound."); - m_useup(mon, otmp); - } - if ((otmp = which_armor(mon, W_ARMC)) != 0) { - if (otmp->oartifact) { - if (vis) - pline("%s %s falls off!", s_suffix(Monnam(mon)), - cloak_simple_name(otmp)); - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } else { - if (vis) - pline("%s %s tears apart!", s_suffix(Monnam(mon)), - cloak_simple_name(otmp)); - else - You_hear("a ripping sound."); - m_useup(mon, otmp); - } - } - if ((otmp = which_armor(mon, W_ARMU)) != 0) { - if (vis) - pline("%s shirt rips to shreds!", s_suffix(Monnam(mon))); - else - You_hear("a ripping sound."); - m_useup(mon, otmp); - } - } else if (sliparm(mdat)) { - if ((otmp = which_armor(mon, W_ARM)) != 0) { - if (vis) - pline("%s armor falls around %s!", - s_suffix(Monnam(mon)), pronoun); - else - You_hear("a thud."); - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - if ((otmp = which_armor(mon, W_ARMC)) != 0) { - if (vis) { - if (is_whirly(mon->data)) - pline("%s %s falls, unsupported!", - s_suffix(Monnam(mon)), cloak_simple_name(otmp)); - else - pline("%s shrinks out of %s %s!", Monnam(mon), - ppronoun, cloak_simple_name(otmp)); - } - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - if ((otmp = which_armor(mon, W_ARMU)) != 0) { - if (vis) { - if (sliparm(mon->data)) - pline("%s seeps right through %s shirt!", - Monnam(mon), ppronoun); - else - pline("%s becomes much too small for %s shirt!", - Monnam(mon), ppronoun); - } - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - } - if (handless_or_tiny) { - /* [caller needs to handle weapon checks] */ - if ((otmp = which_armor(mon, W_ARMG)) != 0) { - if (vis) - pline("%s drops %s gloves%s!", Monnam(mon), ppronoun, - MON_WEP(mon) ? " and weapon" : ""); - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - if ((otmp = which_armor(mon, W_ARMS)) != 0) { - if (vis) - pline("%s can no longer hold %s shield!", Monnam(mon), - ppronoun); - else - You_hear("a clank."); - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - } - if (handless_or_tiny || has_horns(mdat)) { - if ((otmp = which_armor(mon, W_ARMH)) != 0 && - /* flimsy test for horns matches polyself handling */ - (handless_or_tiny || !is_flimsy(otmp))) { - if (vis) - pline("%s helmet falls to the %s!", - s_suffix(Monnam(mon)), surface(mon->mx, mon->my)); - else - You_hear("a clank."); - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - } - if (handless_or_tiny || slithy(mdat) || mdat->mlet == S_CENTAUR) { - if ((otmp = which_armor(mon, W_ARMF)) != 0) { - if (vis) { - if (is_whirly(mon->data)) - pline("%s boots fall away!", - s_suffix(Monnam(mon))); - else pline("%s boots %s off %s feet!", - s_suffix(Monnam(mon)), - verysmall(mdat) ? "slide" : "are pushed", ppronoun); - } - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - } - } - if (!can_saddle(mon)) { - if ((otmp = which_armor(mon, W_SADDLE)) != 0) { - if (polyspot) bypass_obj(otmp); - m_lose_armor(mon, otmp); - if (vis) - pline("%s saddle falls off.", s_suffix(Monnam(mon))); - } - if (mon == u.usteed) - goto noride; - } else if (mon == u.usteed && !can_ride(mon)) { - noride: - You("can no longer ride %s.", mon_nam(mon)); - if (touch_petrifies(u.usteed->data) && - !Stone_resistance && rnl(3)) { - char buf[BUFSZ]; + if (breakarm(mdat)) { + if ((otmp = which_armor(mon, W_ARM)) != 0) { + if ((Is_dragon_scales(otmp) && mdat == Dragon_scales_to_pm(otmp)) + || (Is_dragon_mail(otmp) && mdat == Dragon_mail_to_pm(otmp))) + ; /* no message here; + "the dragon merges with his scaly armor" is odd + and the monster's previous form is already gone */ + else if (vis) + pline("%s breaks out of %s armor!", Monnam(mon), ppronoun); + else + You_hear("a cracking sound."); + m_useup(mon, otmp); + } + if ((otmp = which_armor(mon, W_ARMC)) != 0) { + if (otmp->oartifact) { + if (vis) + pline("%s %s falls off!", s_suffix(Monnam(mon)), + cloak_simple_name(otmp)); + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } else { + if (vis) + pline("%s %s tears apart!", s_suffix(Monnam(mon)), + cloak_simple_name(otmp)); + else + You_hear("a ripping sound."); + m_useup(mon, otmp); + } + } + if ((otmp = which_armor(mon, W_ARMU)) != 0) { + if (vis) + pline("%s shirt rips to shreds!", s_suffix(Monnam(mon))); + else + You_hear("a ripping sound."); + m_useup(mon, otmp); + } + } else if (sliparm(mdat)) { + if ((otmp = which_armor(mon, W_ARM)) != 0) { + if (vis) + pline("%s armor falls around %s!", s_suffix(Monnam(mon)), + pronoun); + else + You_hear("a thud."); + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + if ((otmp = which_armor(mon, W_ARMC)) != 0) { + if (vis) { + if (is_whirly(mon->data)) + pline("%s %s falls, unsupported!", s_suffix(Monnam(mon)), + cloak_simple_name(otmp)); + else + pline("%s shrinks out of %s %s!", Monnam(mon), ppronoun, + cloak_simple_name(otmp)); + } + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + if ((otmp = which_armor(mon, W_ARMU)) != 0) { + if (vis) { + if (sliparm(mon->data)) + pline("%s seeps right through %s shirt!", Monnam(mon), + ppronoun); + else + pline("%s becomes much too small for %s shirt!", + Monnam(mon), ppronoun); + } + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + } + if (handless_or_tiny) { + /* [caller needs to handle weapon checks] */ + if ((otmp = which_armor(mon, W_ARMG)) != 0) { + if (vis) + pline("%s drops %s gloves%s!", Monnam(mon), ppronoun, + MON_WEP(mon) ? " and weapon" : ""); + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + if ((otmp = which_armor(mon, W_ARMS)) != 0) { + if (vis) + pline("%s can no longer hold %s shield!", Monnam(mon), + ppronoun); + else + You_hear("a clank."); + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + } + if (handless_or_tiny || has_horns(mdat)) { + if ((otmp = which_armor(mon, W_ARMH)) != 0 && + /* flimsy test for horns matches polyself handling */ + (handless_or_tiny || !is_flimsy(otmp))) { + if (vis) + pline("%s helmet falls to the %s!", s_suffix(Monnam(mon)), + surface(mon->mx, mon->my)); + else + You_hear("a clank."); + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + } + if (handless_or_tiny || slithy(mdat) || mdat->mlet == S_CENTAUR) { + if ((otmp = which_armor(mon, W_ARMF)) != 0) { + if (vis) { + if (is_whirly(mon->data)) + pline("%s boots fall away!", s_suffix(Monnam(mon))); + else + pline("%s boots %s off %s feet!", s_suffix(Monnam(mon)), + verysmall(mdat) ? "slide" : "are pushed", ppronoun); + } + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + } + } + if (!can_saddle(mon)) { + if ((otmp = which_armor(mon, W_SADDLE)) != 0) { + if (polyspot) + bypass_obj(otmp); + m_lose_armor(mon, otmp); + if (vis) + pline("%s saddle falls off.", s_suffix(Monnam(mon))); + } + if (mon == u.usteed) + goto noride; + } else if (mon == u.usteed && !can_ride(mon)) { + noride: + You("can no longer ride %s.", mon_nam(mon)); + if (touch_petrifies(u.usteed->data) && !Stone_resistance && rnl(3)) { + char buf[BUFSZ]; - You("touch %s.", mon_nam(u.usteed)); - Sprintf(buf, "falling off %s", - an(u.usteed->data->mname)); - instapetrify(buf); - } - dismount_steed(DISMOUNT_FELL); - } - return; + You("touch %s.", mon_nam(u.usteed)); + Sprintf(buf, "falling off %s", an(u.usteed->data->mname)); + instapetrify(buf); + } + dismount_steed(DISMOUNT_FELL); + } + return; } /* bias a monster's preferences towards armor that has special benefits. */ @@ -868,14 +932,15 @@ struct monst *mon; struct obj *obj; { if (obj) { - if (obj->otyp == SPEED_BOOTS && mon->permspeed != MFAST) - return 20; + if (obj->otyp == SPEED_BOOTS && mon->permspeed != MFAST) + return 20; } return 0; } /* - * Exceptions to things based on race. Correctly checks polymorphed player race. + * Exceptions to things based on race. Correctly checks polymorphed player + *race. * Returns: * 0 No exception, normal rules apply. * 1 If the race/object combination is acceptable. @@ -891,7 +956,7 @@ struct obj *obj; /* Acceptable Exceptions: */ /* Allow hobbits to wear elven armor - LoTR */ if (ptr == &mons[PM_HOBBIT] && is_elven_armor(obj)) - return 1; + return 1; /* Unacceptable Exceptions: */ /* Checks for object that certain races should never use go here */ /* return -1; */ diff --git a/src/write.c b/src/write.c index 0674da821..365047c8a 100644 --- a/src/write.c +++ b/src/write.c @@ -1,12 +1,12 @@ -/* NetHack 3.6 write.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 write.c $NHDT-Date: 1431192759 2015/05/09 17:32:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */ /* NetHack 3.6 write.c $Date: 2010/12/28 19:54:41 $ $Revision: 1.9 $ */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" -STATIC_DCL int FDECL(cost,(struct obj *)); -STATIC_DCL boolean FDECL(label_known, (int,struct obj *)); -STATIC_DCL char *FDECL(new_book_description, (int,char *)); +STATIC_DCL int FDECL(cost, (struct obj *)); +STATIC_DCL boolean FDECL(label_known, (int, struct obj *)); +STATIC_DCL char *FDECL(new_book_description, (int, char *)); /* * returns basecost of a scroll or a spellbook @@ -15,56 +15,55 @@ STATIC_OVL int cost(otmp) register struct obj *otmp; { + if (otmp->oclass == SPBOOK_CLASS) + return (10 * objects[otmp->otyp].oc_level); - if (otmp->oclass == SPBOOK_CLASS) - return(10 * objects[otmp->otyp].oc_level); - - switch (otmp->otyp) { -# ifdef MAIL - case SCR_MAIL: - return(2); + switch (otmp->otyp) { +#ifdef MAIL + case SCR_MAIL: + return (2); /* break; */ -# endif - case SCR_LIGHT: - case SCR_GOLD_DETECTION: - case SCR_FOOD_DETECTION: - case SCR_MAGIC_MAPPING: - case SCR_AMNESIA: - case SCR_FIRE: - case SCR_EARTH: - return(8); -/* break; */ - case SCR_DESTROY_ARMOR: - case SCR_CREATE_MONSTER: - case SCR_PUNISHMENT: - return(10); -/* break; */ - case SCR_CONFUSE_MONSTER: - return(12); -/* break; */ - case SCR_IDENTIFY: - return(14); -/* break; */ - case SCR_ENCHANT_ARMOR: - case SCR_REMOVE_CURSE: - case SCR_ENCHANT_WEAPON: - case SCR_CHARGING: - return(16); -/* break; */ - case SCR_SCARE_MONSTER: - case SCR_STINKING_CLOUD: - case SCR_TAMING: - case SCR_TELEPORTATION: - return(20); -/* break; */ - case SCR_GENOCIDE: - return(30); -/* break; */ - case SCR_BLANK_PAPER: - default: - impossible("You can't write such a weird scroll!"); - } - return(1000); +#endif + case SCR_LIGHT: + case SCR_GOLD_DETECTION: + case SCR_FOOD_DETECTION: + case SCR_MAGIC_MAPPING: + case SCR_AMNESIA: + case SCR_FIRE: + case SCR_EARTH: + return (8); + /* break; */ + case SCR_DESTROY_ARMOR: + case SCR_CREATE_MONSTER: + case SCR_PUNISHMENT: + return (10); + /* break; */ + case SCR_CONFUSE_MONSTER: + return (12); + /* break; */ + case SCR_IDENTIFY: + return (14); + /* break; */ + case SCR_ENCHANT_ARMOR: + case SCR_REMOVE_CURSE: + case SCR_ENCHANT_WEAPON: + case SCR_CHARGING: + return (16); + /* break; */ + case SCR_SCARE_MONSTER: + case SCR_STINKING_CLOUD: + case SCR_TAMING: + case SCR_TELEPORTATION: + return (20); + /* break; */ + case SCR_GENOCIDE: + return (30); + /* break; */ + case SCR_BLANK_PAPER: + default: + impossible("You can't write such a weird scroll!"); + } + return (1000); } /* decide whether the hero knowns a particular scroll's label; @@ -80,18 +79,18 @@ struct obj *objlist; /* only scrolls */ if (objects[scrolltype].oc_class != SCROLL_CLASS) - return FALSE; + return FALSE; /* type known implies full discovery; otherwise, user-assigned name implies partial discovery */ if (objects[scrolltype].oc_name_known || objects[scrolltype].oc_uname) - return TRUE; + return TRUE; /* check inventory, including carried containers with known contents */ for (otmp = objlist; otmp; otmp = otmp->nobj) { - if (otmp->otyp == scrolltype && otmp->dknown) - return TRUE; - if (Has_contents(otmp) && otmp->cknown && - label_known(scrolltype, otmp->cobj)) - return TRUE; + if (otmp->otyp == scrolltype && otmp->dknown) + return TRUE; + if (Has_contents(otmp) && otmp->cknown + && label_known(scrolltype, otmp->cobj)) + return TRUE; } /* not found */ return FALSE; @@ -103,242 +102,245 @@ int dowrite(pen) register struct obj *pen; { - register struct obj *paper; - char namebuf[BUFSZ], *nm, *bp; - register struct obj *new_obj; - int basecost, actualcost; - int curseval; - char qbuf[QBUFSZ]; - int first, last, i, deferred, deferralchance; - boolean by_descr = FALSE; - const char *typeword; + register struct obj *paper; + char namebuf[BUFSZ], *nm, *bp; + register struct obj *new_obj; + int basecost, actualcost; + int curseval; + char qbuf[QBUFSZ]; + int first, last, i, deferred, deferralchance; + boolean by_descr = FALSE; + const char *typeword; - if (nohands(youmonst.data)) { - You("need hands to be able to write!"); - return 0; - } else if (Glib) { - pline("%s from your %s.", - Tobjnam(pen, "slip"), makeplural(body_part(FINGER))); - dropx(pen); - return 1; - } + if (nohands(youmonst.data)) { + You("need hands to be able to write!"); + return 0; + } else if (Glib) { + pline("%s from your %s.", Tobjnam(pen, "slip"), + makeplural(body_part(FINGER))); + dropx(pen); + return 1; + } - /* get paper to write on */ - paper = getobj(write_on,"write on"); - if(!paper) - return(0); - typeword = (paper->oclass == SPBOOK_CLASS) ? "spellbook" : "scroll"; - if (Blind) { - if (!paper->dknown) { - You("don't know if that %s is blank or not.", typeword); - return 1; - } else if (paper->oclass == SPBOOK_CLASS) { - /* can't write a magic book while blind */ - pline("%s can't create braille text.", - upstart(ysimple_name(pen))); - return 1; - } - } - paper->dknown = 1; - if(paper->otyp != SCR_BLANK_PAPER && paper->otyp != SPE_BLANK_PAPER) { - pline("That %s is not blank!", typeword); - exercise(A_WIS, FALSE); - return(1); - } + /* get paper to write on */ + paper = getobj(write_on, "write on"); + if (!paper) + return (0); + typeword = (paper->oclass == SPBOOK_CLASS) ? "spellbook" : "scroll"; + if (Blind) { + if (!paper->dknown) { + You("don't know if that %s is blank or not.", typeword); + return 1; + } else if (paper->oclass == SPBOOK_CLASS) { + /* can't write a magic book while blind */ + pline("%s can't create braille text.", + upstart(ysimple_name(pen))); + return 1; + } + } + paper->dknown = 1; + if (paper->otyp != SCR_BLANK_PAPER && paper->otyp != SPE_BLANK_PAPER) { + pline("That %s is not blank!", typeword); + exercise(A_WIS, FALSE); + return (1); + } - /* what to write */ - Sprintf(qbuf, "What type of %s do you want to write?", typeword); - getlin(qbuf, namebuf); - (void)mungspaces(namebuf); /* remove any excess whitespace */ - if(namebuf[0] == '\033' || !namebuf[0]) - return(1); - nm = namebuf; - if (!strncmpi(nm, "scroll ", 7)) nm += 7; - else if (!strncmpi(nm, "spellbook ", 10)) nm += 10; - if (!strncmpi(nm, "of ", 3)) nm += 3; + /* what to write */ + Sprintf(qbuf, "What type of %s do you want to write?", typeword); + getlin(qbuf, namebuf); + (void) mungspaces(namebuf); /* remove any excess whitespace */ + if (namebuf[0] == '\033' || !namebuf[0]) + return (1); + nm = namebuf; + if (!strncmpi(nm, "scroll ", 7)) + nm += 7; + else if (!strncmpi(nm, "spellbook ", 10)) + nm += 10; + if (!strncmpi(nm, "of ", 3)) + nm += 3; - if ((bp = strstri(nm, " armour")) != 0) { - (void)strncpy(bp, " armor ", 7); /* won't add '\0' */ - (void)mungspaces(bp + 1); /* remove the extra space */ - } + if ((bp = strstri(nm, " armour")) != 0) { + (void) strncpy(bp, " armor ", 7); /* won't add '\0' */ + (void) mungspaces(bp + 1); /* remove the extra space */ + } - deferred = 0; /* not any scroll or book */ - deferralchance = 0; /* incremented for each oc_uname match */ - first = bases[(int)paper->oclass]; - last = bases[(int)paper->oclass + 1] - 1; - for (i = first; i <= last; i++) { - /* extra shufflable descr not representing a real object */ - if (!OBJ_NAME(objects[i])) continue; + deferred = 0; /* not any scroll or book */ + deferralchance = 0; /* incremented for each oc_uname match */ + first = bases[(int) paper->oclass]; + last = bases[(int) paper->oclass + 1] - 1; + for (i = first; i <= last; i++) { + /* extra shufflable descr not representing a real object */ + if (!OBJ_NAME(objects[i])) + continue; - if (!strcmpi(OBJ_NAME(objects[i]), nm)) - goto found; - if (!strcmpi(OBJ_DESCR(objects[i]), nm)) { - by_descr = TRUE; - goto found; - } - /* user-assigned name might match real name of a later - entry, so we don't simply use first match with it; - also, player might assign same name multiple times - and if so, we choose one of those matches randomly */ - if (objects[i].oc_uname && !strcmpi(objects[i].oc_uname, nm) && - /* first match: chance incremented to 1, - !rn2(1) is 1, we remember i; - second match: chance incremented to 2, - !rn2(2) has 1/2 chance to replace i; - third match: chance incremented to 3, - !rn2(3) has 1/3 chance to replace i - and 2/3 chance to keep previous 50:50 - choice; so on for higher match counts */ - !rn2(++deferralchance)) - deferred = i; - } - /* writing by user-assigned name is same as by description: - fails for books, works for scrolls (having an assigned - type name guarantees presence on discoveries list) */ - if (deferred) { - i = deferred; - by_descr = TRUE; - goto found; - } + if (!strcmpi(OBJ_NAME(objects[i]), nm)) + goto found; + if (!strcmpi(OBJ_DESCR(objects[i]), nm)) { + by_descr = TRUE; + goto found; + } + /* user-assigned name might match real name of a later + entry, so we don't simply use first match with it; + also, player might assign same name multiple times + and if so, we choose one of those matches randomly */ + if (objects[i].oc_uname && !strcmpi(objects[i].oc_uname, nm) && + /* first match: chance incremented to 1, + !rn2(1) is 1, we remember i; + second match: chance incremented to 2, + !rn2(2) has 1/2 chance to replace i; + third match: chance incremented to 3, + !rn2(3) has 1/3 chance to replace i + and 2/3 chance to keep previous 50:50 + choice; so on for higher match counts */ + !rn2(++deferralchance)) + deferred = i; + } + /* writing by user-assigned name is same as by description: + fails for books, works for scrolls (having an assigned + type name guarantees presence on discoveries list) */ + if (deferred) { + i = deferred; + by_descr = TRUE; + goto found; + } - There("is no such %s!", typeword); - return 1; + There("is no such %s!", typeword); + return 1; found: - if (i == SCR_BLANK_PAPER || i == SPE_BLANK_PAPER) { - You_cant("write that!"); - pline("It's obscene!"); - return 1; - } else if (i == SPE_BOOK_OF_THE_DEAD) { - pline("No mere dungeon adventurer could write that."); - return 1; - } else if (by_descr && paper->oclass == SPBOOK_CLASS && - !objects[i].oc_name_known) { - /* can't write unknown spellbooks by description */ - pline( - "Unfortunately you don't have enough information to go on."); - return 1; - } + if (i == SCR_BLANK_PAPER || i == SPE_BLANK_PAPER) { + You_cant("write that!"); + pline("It's obscene!"); + return 1; + } else if (i == SPE_BOOK_OF_THE_DEAD) { + pline("No mere dungeon adventurer could write that."); + return 1; + } else if (by_descr && paper->oclass == SPBOOK_CLASS + && !objects[i].oc_name_known) { + /* can't write unknown spellbooks by description */ + pline("Unfortunately you don't have enough information to go on."); + return 1; + } - /* KMH, conduct */ - u.uconduct.literate++; + /* KMH, conduct */ + u.uconduct.literate++; - new_obj = mksobj(i, FALSE, FALSE); - new_obj->bknown = (paper->bknown && pen->bknown); + new_obj = mksobj(i, FALSE, FALSE); + new_obj->bknown = (paper->bknown && pen->bknown); - /* shk imposes a flat rate per use, not based on actual charges used */ - check_unpaid(pen); + /* shk imposes a flat rate per use, not based on actual charges used */ + check_unpaid(pen); - /* see if there's enough ink */ - basecost = cost(new_obj); - if(pen->spe < basecost/2) { - Your("marker is too dry to write that!"); - obfree(new_obj, (struct obj *) 0); - return(1); - } + /* see if there's enough ink */ + basecost = cost(new_obj); + if (pen->spe < basecost / 2) { + Your("marker is too dry to write that!"); + obfree(new_obj, (struct obj *) 0); + return (1); + } - /* we're really going to write now, so calculate cost - */ - actualcost = rn1(basecost/2,basecost/2); - curseval = bcsign(pen) + bcsign(paper); - exercise(A_WIS, TRUE); - /* dry out marker */ - if (pen->spe < actualcost) { - pen->spe = 0; - Your("marker dries out!"); - /* scrolls disappear, spellbooks don't */ - if (paper->oclass == SPBOOK_CLASS) { - pline_The( - "spellbook is left unfinished and your writing fades."); - update_inventory(); /* pen charges */ - } else { - pline_The("scroll is now useless and disappears!"); - useup(paper); - } - obfree(new_obj, (struct obj *) 0); - return(1); - } - pen->spe -= actualcost; + /* we're really going to write now, so calculate cost + */ + actualcost = rn1(basecost / 2, basecost / 2); + curseval = bcsign(pen) + bcsign(paper); + exercise(A_WIS, TRUE); + /* dry out marker */ + if (pen->spe < actualcost) { + pen->spe = 0; + Your("marker dries out!"); + /* scrolls disappear, spellbooks don't */ + if (paper->oclass == SPBOOK_CLASS) { + pline_The("spellbook is left unfinished and your writing fades."); + update_inventory(); /* pen charges */ + } else { + pline_The("scroll is now useless and disappears!"); + useup(paper); + } + obfree(new_obj, (struct obj *) 0); + return (1); + } + pen->spe -= actualcost; - /* - * Writing by name requires that the hero knows the scroll or - * book type. One has previously been read (and its effect - * was evident) or been ID'd via scroll/spell/throne and it - * will be on the discoveries list. - * (Previous versions allowed scrolls and books to be written - * by type name if they were on the discoveries list via being - * given a user-assigned name, even though doing the latter - * doesn't--and shouldn't--make the actual type become known.) - * - * Writing by description requires that the hero knows the - * description (a scroll's label, that is, since books by_descr - * are rejected above). BUG: We can only do this for known - * scrolls and for the case where the player has assigned a - * name to put it onto the discoveries list; we lack a way to - * track other scrolls which have been seen closely enough to - * read the label without then being ID'd or named. The only - * exception is for currently carried inventory, where we can - * check for one [with its dknown bit set] of the same type. - * - * Normal requirements can be overridden if hero is Lucky. - */ + /* + * Writing by name requires that the hero knows the scroll or + * book type. One has previously been read (and its effect + * was evident) or been ID'd via scroll/spell/throne and it + * will be on the discoveries list. + * (Previous versions allowed scrolls and books to be written + * by type name if they were on the discoveries list via being + * given a user-assigned name, even though doing the latter + * doesn't--and shouldn't--make the actual type become known.) + * + * Writing by description requires that the hero knows the + * description (a scroll's label, that is, since books by_descr + * are rejected above). BUG: We can only do this for known + * scrolls and for the case where the player has assigned a + * name to put it onto the discoveries list; we lack a way to + * track other scrolls which have been seen closely enough to + * read the label without then being ID'd or named. The only + * exception is for currently carried inventory, where we can + * check for one [with its dknown bit set] of the same type. + * + * Normal requirements can be overridden if hero is Lucky. + */ - /* if known, then either by-name or by-descr works */ - if (!objects[new_obj->otyp].oc_name_known && - /* else if named, then only by-descr works */ - !(by_descr && label_known(new_obj->otyp, invent)) && - /* and Luck might override after both checks have failed */ - rnl(Role_if(PM_WIZARD) ? 5 : 15)) { - You("%s to write that.", by_descr ? "fail" : "don't know how"); - /* scrolls disappear, spellbooks don't */ - if (paper->oclass == SPBOOK_CLASS) { - You( - "write in your best handwriting: \"My Diary\", but it quickly fades."); - update_inventory(); /* pen charges */ - } else { - if (by_descr) { - Strcpy(namebuf, OBJ_DESCR(objects[new_obj->otyp])); - wipeout_text(namebuf, (6+MAXULEV - u.ulevel)/6, 0); - } else - Sprintf(namebuf, "%s was here!", plname); - You("write \"%s\" and the scroll disappears.", namebuf); - useup(paper); - } - obfree(new_obj, (struct obj *) 0); - return(1); - } - /* can write scrolls when blind, but requires luck too; - attempts to write books when blind are caught above */ - if (Blind && rnl(3)) { - /* writing while blind usually fails regardless of - whether the target scroll is known; even if we - have passed the write-an-unknown scroll test - above we can still fail this one, so it's doubly - hard to write an unknown scroll while blind */ - You("fail to write the scroll correctly and it disappears."); - useup(paper); - obfree(new_obj, (struct obj *) 0); - return 1; - } + /* if known, then either by-name or by-descr works */ + if (!objects[new_obj->otyp].oc_name_known && + /* else if named, then only by-descr works */ + !(by_descr && label_known(new_obj->otyp, invent)) && + /* and Luck might override after both checks have failed */ + rnl(Role_if(PM_WIZARD) ? 5 : 15)) { + You("%s to write that.", by_descr ? "fail" : "don't know how"); + /* scrolls disappear, spellbooks don't */ + if (paper->oclass == SPBOOK_CLASS) { + You("write in your best handwriting: \"My Diary\", but it " + "quickly fades."); + update_inventory(); /* pen charges */ + } else { + if (by_descr) { + Strcpy(namebuf, OBJ_DESCR(objects[new_obj->otyp])); + wipeout_text(namebuf, (6 + MAXULEV - u.ulevel) / 6, 0); + } else + Sprintf(namebuf, "%s was here!", plname); + You("write \"%s\" and the scroll disappears.", namebuf); + useup(paper); + } + obfree(new_obj, (struct obj *) 0); + return (1); + } + /* can write scrolls when blind, but requires luck too; + attempts to write books when blind are caught above */ + if (Blind && rnl(3)) { + /* writing while blind usually fails regardless of + whether the target scroll is known; even if we + have passed the write-an-unknown scroll test + above we can still fail this one, so it's doubly + hard to write an unknown scroll while blind */ + You("fail to write the scroll correctly and it disappears."); + useup(paper); + obfree(new_obj, (struct obj *) 0); + return 1; + } - /* useup old scroll / spellbook */ - useup(paper); + /* useup old scroll / spellbook */ + useup(paper); - /* success */ - if (new_obj->oclass == SPBOOK_CLASS) { - /* acknowledge the change in the object's description... */ - pline_The("spellbook warps strangely, then turns %s.", - new_book_description(new_obj->otyp, namebuf)); - } - new_obj->blessed = (curseval > 0); - new_obj->cursed = (curseval < 0); + /* success */ + if (new_obj->oclass == SPBOOK_CLASS) { + /* acknowledge the change in the object's description... */ + pline_The("spellbook warps strangely, then turns %s.", + new_book_description(new_obj->otyp, namebuf)); + } + new_obj->blessed = (curseval > 0); + new_obj->cursed = (curseval < 0); #ifdef MAIL - if (new_obj->otyp == SCR_MAIL) new_obj->spe = 1; + if (new_obj->otyp == SCR_MAIL) + new_obj->spe = 1; #endif - new_obj = hold_another_object(new_obj, "Oops! %s out of your grasp!", - The(aobjnam(new_obj, "slip")), - (const char *)0); - return(1); + new_obj = + hold_another_object(new_obj, "Oops! %s out of your grasp!", + The(aobjnam(new_obj, "slip")), (const char *) 0); + return (1); } /* most book descriptions refer to cover appearance, so we can issue a @@ -356,18 +358,21 @@ char *outbuf; /* subset of description strings from objects.c; if it grows much, we may need to add a new flag field to objects[] instead */ static const char *const compositions[] = { - "parchment", "vellum", "cloth", + "parchment", + "vellum", + "cloth", #if 0 "canvas", "hardcover", /* not used */ "papyrus", /* not applicable--can't be produced via writing */ #endif /*0*/ - 0 + 0 }; const char *descr, *const *comp_p; descr = OBJ_DESCR(objects[booktype]); for (comp_p = compositions; *comp_p; ++comp_p) - if (!strcmpi(descr, *comp_p)) break; + if (!strcmpi(descr, *comp_p)) + break; Sprintf(outbuf, "%s%s", *comp_p ? "into " : "", descr); return outbuf; diff --git a/src/zap.c b/src/zap.c index 67cb4fa14..c95a0baaf 100644 --- a/src/zap.c +++ b/src/zap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 zap.c $NHDT-Date: 1430355196 2015/04/30 00:53:16 $ $NHDT-Branch: master $:$NHDT-Revision: 1.218 $ */ +/* NetHack 3.6 zap.c $NHDT-Date: 1431192757 2015/05/09 17:32:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.222 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,81 +14,63 @@ static NEARDATA boolean obj_zapped; static NEARDATA int poly_zapped; -extern boolean notonhead; /* for long worms */ +extern boolean notonhead; /* for long worms */ /* kludge to use mondied instead of killed */ extern boolean m_using; -STATIC_DCL void FDECL(polyuse, (struct obj *,int,int)); -STATIC_DCL void FDECL(create_polymon, (struct obj *,int)); +STATIC_DCL void FDECL(polyuse, (struct obj *, int, int)); +STATIC_DCL void FDECL(create_polymon, (struct obj *, int)); STATIC_DCL int FDECL(stone_to_flesh_obj, (struct obj *)); STATIC_DCL boolean FDECL(zap_updown, (struct obj *)); -STATIC_DCL void FDECL(zhitu, (int,int,const char *,XCHAR_P,XCHAR_P)); +STATIC_DCL void FDECL(zhitu, (int, int, const char *, XCHAR_P, XCHAR_P)); STATIC_DCL void FDECL(revive_egg, (struct obj *)); STATIC_DCL boolean FDECL(zap_steed, (struct obj *)); -STATIC_DCL void FDECL(skiprange, (int,int *,int *)); +STATIC_DCL void FDECL(skiprange, (int, int *, int *)); -STATIC_DCL int FDECL(zap_hit, (int,int)); -STATIC_OVL void FDECL(disintegrate_mon, (struct monst *,int,const char *)); +STATIC_DCL int FDECL(zap_hit, (int, int)); +STATIC_OVL void FDECL(disintegrate_mon, (struct monst *, int, const char *)); STATIC_DCL void FDECL(backfire, (struct obj *)); STATIC_DCL int FDECL(spell_hit_bonus, (int)); -#define ZT_MAGIC_MISSILE (AD_MAGM-1) -#define ZT_FIRE (AD_FIRE-1) -#define ZT_COLD (AD_COLD-1) -#define ZT_SLEEP (AD_SLEE-1) -#define ZT_DEATH (AD_DISN-1) /* or disintegration */ -#define ZT_LIGHTNING (AD_ELEC-1) -#define ZT_POISON_GAS (AD_DRST-1) -#define ZT_ACID (AD_ACID-1) +#define ZT_MAGIC_MISSILE (AD_MAGM - 1) +#define ZT_FIRE (AD_FIRE - 1) +#define ZT_COLD (AD_COLD - 1) +#define ZT_SLEEP (AD_SLEE - 1) +#define ZT_DEATH (AD_DISN - 1) /* or disintegration */ +#define ZT_LIGHTNING (AD_ELEC - 1) +#define ZT_POISON_GAS (AD_DRST - 1) +#define ZT_ACID (AD_ACID - 1) /* 8 and 9 are currently unassigned */ -#define ZT_WAND(x) (x) -#define ZT_SPELL(x) (10+(x)) -#define ZT_BREATH(x) (20+(x)) +#define ZT_WAND(x) (x) +#define ZT_SPELL(x) (10 + (x)) +#define ZT_BREATH(x) (20 + (x)) -#define is_hero_spell(type) ((type) >= 10 && (type) < 20) +#define is_hero_spell(type) ((type) >= 10 && (type) < 20) -#define M_IN_WATER(ptr) ((ptr)->mlet == S_EEL || \ - amphibious(ptr) || \ - is_swimmer(ptr)) +#define M_IN_WATER(ptr) \ + ((ptr)->mlet == S_EEL || amphibious(ptr) || is_swimmer(ptr)) -STATIC_VAR const char are_blinded_by_the_flash[] = "are blinded by the flash!"; +STATIC_VAR const char are_blinded_by_the_flash[] = + "are blinded by the flash!"; -const char * const flash_types[] = { /* also used in buzzmu(mcastu.c) */ - "magic missile", /* Wands must be 0-9 */ - "bolt of fire", - "bolt of cold", - "sleep ray", - "death ray", - "bolt of lightning", - "", - "", - "", - "", +const char *const flash_types[] = + { /* also used in buzzmu(mcastu.c) */ + "magic missile", /* Wands must be 0-9 */ + "bolt of fire", "bolt of cold", "sleep ray", "death ray", + "bolt of lightning", "", "", "", "", - "magic missile", /* Spell equivalents must be 10-19 */ - "fireball", - "cone of cold", - "sleep ray", - "finger of death", - "bolt of lightning", /* There is no spell, used for retribution */ - "", - "", - "", - "", + "magic missile", /* Spell equivalents must be 10-19 */ + "fireball", "cone of cold", "sleep ray", "finger of death", + "bolt of lightning", /* There is no spell, used for retribution */ + "", "", "", "", - "blast of missiles", /* Dragon breath equivalents 20-29*/ - "blast of fire", - "blast of frost", - "blast of sleep gas", - "blast of disintegration", - "blast of lightning", - "blast of poison gas", - "blast of acid", - "", - "" -}; + "blast of missiles", /* Dragon breath equivalents 20-29*/ + "blast of fire", "blast of frost", "blast of sleep gas", + "blast of disintegration", "blast of lightning", "blast of poison gas", + "blast of acid", "", "" + }; /* * Recognizing unseen wands by zapping: in 3.4.3 and earlier, zapping @@ -127,18 +109,23 @@ struct obj *obj; seen. Suppress spells (which use fake spellbook object for `obj') so that casting a spell won't re-discover its forgotten book. */ if (obj->oclass != SPBOOK_CLASS) { - /* if type already discovered, treat this item has having been seen - even if the hero is currently blinded (skips redundant makeknown) */ - if (objects[obj->otyp].oc_name_known) { - obj->dknown = 1; /* will usually be set already */ - /* otherwise discover it if this item itself has been or can be seen */ - } else { - /* in case it was picked up while blind and then zapped without - examining inventory after regaining sight (bypassing xname()) */ - if (!Blind) obj->dknown = 1; - /* make the discovery iff we know what we're manipulating */ - if (obj->dknown) makeknown(obj->otyp); - } + /* if type already discovered, treat this item has having been seen + even if the hero is currently blinded (skips redundant makeknown) + */ + if (objects[obj->otyp].oc_name_known) { + obj->dknown = 1; /* will usually be set already */ + /* otherwise discover it if this item itself has been or can be + * seen */ + } else { + /* in case it was picked up while blind and then zapped without + examining inventory after regaining sight (bypassing xname()) + */ + if (!Blind) + obj->dknown = 1; + /* make the discovery iff we know what we're manipulating */ + if (obj->dknown) + makeknown(obj->otyp); + } } } @@ -149,305 +136,315 @@ bhitm(mtmp, otmp) struct monst *mtmp; struct obj *otmp; { - boolean wake = TRUE; /* Most 'zaps' should wake monster */ - boolean reveal_invis = FALSE, learn_it = FALSE; - boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart; - int dmg, otyp = otmp->otyp; - const char *zap_type_text = "spell"; - struct obj *obj; - boolean disguised_mimic = (mtmp->data->mlet == S_MIMIC && - mtmp->m_ap_type != M_AP_NOTHING); + boolean wake = TRUE; /* Most 'zaps' should wake monster */ + boolean reveal_invis = FALSE, learn_it = FALSE; + boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart; + int dmg, otyp = otmp->otyp; + const char *zap_type_text = "spell"; + struct obj *obj; + boolean disguised_mimic = + (mtmp->data->mlet == S_MIMIC && mtmp->m_ap_type != M_AP_NOTHING); - if (u.uswallow && mtmp == u.ustuck) - reveal_invis = FALSE; + if (u.uswallow && mtmp == u.ustuck) + reveal_invis = FALSE; - switch(otyp) { - case WAN_STRIKING: - zap_type_text = "wand"; - /* fall through */ - case SPE_FORCE_BOLT: - reveal_invis = TRUE; - if (resists_magm(mtmp)) { /* match effect on player */ - shieldeff(mtmp->mx, mtmp->my); - pline("Boing!"); - break; /* skip makeknown */ - } else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) { - dmg = d(2,12); - if(dbldam) dmg *= 2; - if (otyp == SPE_FORCE_BOLT) - dmg = spell_damage_bonus(dmg); - hit(zap_type_text, mtmp, exclam(dmg)); - (void) resist(mtmp, otmp->oclass, dmg, TELL); - } else miss(zap_type_text, mtmp); - learn_it = TRUE; - break; - case WAN_SLOW_MONSTER: - case SPE_SLOW_MONSTER: - if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { - mon_adjust_speed(mtmp, -1, otmp); - m_dowear(mtmp, FALSE); /* might want speed boots */ - if (u.uswallow && (mtmp == u.ustuck) && - is_whirly(mtmp->data)) { - You("disrupt %s!", mon_nam(mtmp)); - pline("A huge hole opens up..."); - expels(mtmp, mtmp->data, TRUE); - } - } - break; - case WAN_SPEED_MONSTER: - if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { - mon_adjust_speed(mtmp, 1, otmp); - m_dowear(mtmp, FALSE); /* might want speed boots */ - } - break; - case WAN_UNDEAD_TURNING: - case SPE_TURN_UNDEAD: - wake = FALSE; - if (unturn_dead(mtmp)) wake = TRUE; - if (is_undead(mtmp->data) || is_vampshifter(mtmp)) { - reveal_invis = TRUE; - wake = TRUE; - dmg = rnd(8); - if(dbldam) dmg *= 2; - if (otyp == SPE_TURN_UNDEAD) - dmg = spell_damage_bonus(dmg); - context.bypasses = TRUE; /* for make_corpse() */ - if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) { - if (mtmp->mhp > 0) monflee(mtmp, 0, FALSE, TRUE); - } - } - break; - case WAN_POLYMORPH: - case SPE_POLYMORPH: - case POT_POLYMORPH: - if (resists_magm(mtmp)) { - /* magic resistance protects from polymorph traps, so make - it guard against involuntary polymorph attacks too... */ - shieldeff(mtmp->mx, mtmp->my); - } else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { - /* dropped inventory (due to death by system shock, - or loss of wielded weapon and/or worn armor due to - limitations of new shape) won't be hit by this zap */ - for (obj = mtmp->minvent; obj; obj = obj->nobj) - bypass_obj(obj); - /* natural shapechangers aren't affected by system shock - (unless protection from shapechangers is interfering - with their metabolism...) */ - if (mtmp->cham == NON_PM && !rn2(25)) { - if (canseemon(mtmp)) { - pline("%s shudders!", Monnam(mtmp)); - learn_it = TRUE; - } - /* context.bypasses = TRUE; ## for make_corpse() */ - /* no corpse after system shock */ - xkilled(mtmp, 3); - } else if (newcham(mtmp, (struct permonst *)0, - (otyp != POT_POLYMORPH), FALSE)) { - if (!Hallucination && canspotmon(mtmp)) - learn_it = TRUE; - } - } - break; - case WAN_CANCELLATION: - case SPE_CANCELLATION: - (void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE); - break; - case WAN_TELEPORTATION: - case SPE_TELEPORT_AWAY: - reveal_invis = !u_teleport_mon(mtmp, TRUE); - break; - case WAN_MAKE_INVISIBLE: - { - int oldinvis = mtmp->minvis; - char nambuf[BUFSZ]; + switch (otyp) { + case WAN_STRIKING: + zap_type_text = "wand"; + /* fall through */ + case SPE_FORCE_BOLT: + reveal_invis = TRUE; + if (resists_magm(mtmp)) { /* match effect on player */ + shieldeff(mtmp->mx, mtmp->my); + pline("Boing!"); + break; /* skip makeknown */ + } else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) { + dmg = d(2, 12); + if (dbldam) + dmg *= 2; + if (otyp == SPE_FORCE_BOLT) + dmg = spell_damage_bonus(dmg); + hit(zap_type_text, mtmp, exclam(dmg)); + (void) resist(mtmp, otmp->oclass, dmg, TELL); + } else + miss(zap_type_text, mtmp); + learn_it = TRUE; + break; + case WAN_SLOW_MONSTER: + case SPE_SLOW_MONSTER: + if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { + mon_adjust_speed(mtmp, -1, otmp); + m_dowear(mtmp, FALSE); /* might want speed boots */ + if (u.uswallow && (mtmp == u.ustuck) && is_whirly(mtmp->data)) { + You("disrupt %s!", mon_nam(mtmp)); + pline("A huge hole opens up..."); + expels(mtmp, mtmp->data, TRUE); + } + } + break; + case WAN_SPEED_MONSTER: + if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { + mon_adjust_speed(mtmp, 1, otmp); + m_dowear(mtmp, FALSE); /* might want speed boots */ + } + break; + case WAN_UNDEAD_TURNING: + case SPE_TURN_UNDEAD: + wake = FALSE; + if (unturn_dead(mtmp)) + wake = TRUE; + if (is_undead(mtmp->data) || is_vampshifter(mtmp)) { + reveal_invis = TRUE; + wake = TRUE; + dmg = rnd(8); + if (dbldam) + dmg *= 2; + if (otyp == SPE_TURN_UNDEAD) + dmg = spell_damage_bonus(dmg); + context.bypasses = TRUE; /* for make_corpse() */ + if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) { + if (mtmp->mhp > 0) + monflee(mtmp, 0, FALSE, TRUE); + } + } + break; + case WAN_POLYMORPH: + case SPE_POLYMORPH: + case POT_POLYMORPH: + if (resists_magm(mtmp)) { + /* magic resistance protects from polymorph traps, so make + it guard against involuntary polymorph attacks too... */ + shieldeff(mtmp->mx, mtmp->my); + } else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { + /* dropped inventory (due to death by system shock, + or loss of wielded weapon and/or worn armor due to + limitations of new shape) won't be hit by this zap */ + for (obj = mtmp->minvent; obj; obj = obj->nobj) + bypass_obj(obj); + /* natural shapechangers aren't affected by system shock + (unless protection from shapechangers is interfering + with their metabolism...) */ + if (mtmp->cham == NON_PM && !rn2(25)) { + if (canseemon(mtmp)) { + pline("%s shudders!", Monnam(mtmp)); + learn_it = TRUE; + } + /* context.bypasses = TRUE; ## for make_corpse() */ + /* no corpse after system shock */ + xkilled(mtmp, 3); + } else if (newcham(mtmp, (struct permonst *) 0, + (otyp != POT_POLYMORPH), FALSE)) { + if (!Hallucination && canspotmon(mtmp)) + learn_it = TRUE; + } + } + break; + case WAN_CANCELLATION: + case SPE_CANCELLATION: + (void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE); + break; + case WAN_TELEPORTATION: + case SPE_TELEPORT_AWAY: + reveal_invis = !u_teleport_mon(mtmp, TRUE); + break; + case WAN_MAKE_INVISIBLE: { + int oldinvis = mtmp->minvis; + char nambuf[BUFSZ]; - /* format monster's name before altering its visibility */ - Strcpy(nambuf, Monnam(mtmp)); - mon_set_minvis(mtmp); - if (!oldinvis && knowninvisible(mtmp)) { - pline("%s turns transparent!", nambuf); - learn_it = TRUE; - } - break; - } - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - wake = closeholdingtrap(mtmp, &learn_it); - break; - case WAN_PROBING: - wake = FALSE; - reveal_invis = TRUE; - probe_monster(mtmp); - learn_it = TRUE; - break; - case WAN_OPENING: - case SPE_KNOCK: - wake = FALSE; /* don't want immediate counterattack */ - if (u.uswallow && mtmp == u.ustuck) { - if (is_animal(mtmp->data)) { - if (Blind) You_feel("a sudden rush of air!"); - else pline("%s opens its mouth!", Monnam(mtmp)); - } - expels(mtmp, mtmp->data, TRUE); - /* zap which hits steed will only release saddle if it - doesn't hit a holding or falling trap; playability - here overrides the more logical target ordering */ - } else if (openholdingtrap(mtmp, &learn_it)) { - break; - } else if (openfallingtrap(mtmp, TRUE, &learn_it)) { - /* mtmp might now be on the migrating monsters list */ - break; - } else if ((obj = which_armor(mtmp, W_SADDLE)) != 0) { - char buf[BUFSZ]; + /* format monster's name before altering its visibility */ + Strcpy(nambuf, Monnam(mtmp)); + mon_set_minvis(mtmp); + if (!oldinvis && knowninvisible(mtmp)) { + pline("%s turns transparent!", nambuf); + learn_it = TRUE; + } + break; + } + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + wake = closeholdingtrap(mtmp, &learn_it); + break; + case WAN_PROBING: + wake = FALSE; + reveal_invis = TRUE; + probe_monster(mtmp); + learn_it = TRUE; + break; + case WAN_OPENING: + case SPE_KNOCK: + wake = FALSE; /* don't want immediate counterattack */ + if (u.uswallow && mtmp == u.ustuck) { + if (is_animal(mtmp->data)) { + if (Blind) + You_feel("a sudden rush of air!"); + else + pline("%s opens its mouth!", Monnam(mtmp)); + } + expels(mtmp, mtmp->data, TRUE); + /* zap which hits steed will only release saddle if it + doesn't hit a holding or falling trap; playability + here overrides the more logical target ordering */ + } else if (openholdingtrap(mtmp, &learn_it)) { + break; + } else if (openfallingtrap(mtmp, TRUE, &learn_it)) { + /* mtmp might now be on the migrating monsters list */ + break; + } else if ((obj = which_armor(mtmp, W_SADDLE)) != 0) { + char buf[BUFSZ]; - Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)), - distant_name(obj, xname)); - if (cansee(mtmp->mx, mtmp->my)) { - if (!canspotmon(mtmp)) - Strcpy(buf, An(distant_name(obj, xname))); - pline("%s falls to the %s.", - buf, surface(mtmp->mx, mtmp->my)); - } else if (canspotmon(mtmp)) { - pline("%s falls off.", buf); - } - obj_extract_self(obj); - mdrop_obj(mtmp, obj, FALSE); - } - break; - case SPE_HEALING: - case SPE_EXTRA_HEALING: - reveal_invis = TRUE; - if (mtmp->data != &mons[PM_PESTILENCE]) { - wake = FALSE; /* wakeup() makes the target angry */ - mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4); - if (mtmp->mhp > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - if (mtmp->mblinded) { - mtmp->mblinded = 0; - mtmp->mcansee = 1; - } - if (canseemon(mtmp)) { - if (disguised_mimic) { - if (mtmp->m_ap_type == M_AP_OBJECT && - mtmp->mappearance == STRANGE_OBJECT) { - /* it can do better now */ - set_mimic_sym(mtmp); - newsym(mtmp->mx, mtmp->my); - } else - mimic_hit_msg(mtmp, otyp); - } else pline("%s looks%s better.", Monnam(mtmp), - otyp == SPE_EXTRA_HEALING ? " much" : "" ); - } - if (mtmp->mtame || mtmp->mpeaceful) { - adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type)); - } - } else { /* Pestilence */ - /* Pestilence will always resist; damage is half of 3d{4,8} */ - (void) resist(mtmp, otmp->oclass, - d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL); - } - break; - case WAN_LIGHT: /* (broken wand) */ - if (flash_hits_mon(mtmp, otmp)) { - learn_it = TRUE; - reveal_invis = TRUE; - } - break; - case WAN_SLEEP: /* (broken wand) */ - /* [wakeup() doesn't rouse victims of temporary sleep, - so it's okay to leave `wake' set to TRUE here] */ - reveal_invis = TRUE; - if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS)) - slept_monst(mtmp); - if (!Blind) learn_it = TRUE; - break; - case SPE_STONE_TO_FLESH: - if (monsndx(mtmp->data) == PM_STONE_GOLEM) { - char *name = Monnam(mtmp); - /* turn into flesh golem */ - if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) { - if (canseemon(mtmp)) - pline("%s turns to flesh!", name); - } else { - if (canseemon(mtmp)) - pline("%s looks rather fleshy for a moment.", - name); - } - } else - wake = FALSE; - break; - case SPE_DRAIN_LIFE: - dmg = monhp_per_lvl(mtmp); - if(dbldam) dmg *= 2; - if (otyp == SPE_DRAIN_LIFE) - dmg = spell_damage_bonus(dmg); - if (resists_drli(mtmp)) - shieldeff(mtmp->mx, mtmp->my); - else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) && - mtmp->mhp > 0) { - mtmp->mhp -= dmg; - mtmp->mhpmax -= dmg; - if (mtmp->mhp <= 0 || mtmp->mhpmax <= 0 || mtmp->m_lev < 1) - xkilled(mtmp, 1); - else { - mtmp->m_lev--; - if (canseemon(mtmp)) - pline("%s suddenly seems weaker!", Monnam(mtmp)); - } - } - break; - case WAN_NOTHING: - wake = FALSE; - break; - default: - impossible("What an interesting effect (%d)", otyp); - break; - } - if(wake) { - if(mtmp->mhp > 0) { - wakeup(mtmp); - m_respond(mtmp); - if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp); - } else if(mtmp->m_ap_type) - seemimic(mtmp); /* might unblock if mimicing a boulder/door */ - } - /* note: bhitpos won't be set if swallowed, but that's okay since - * reveal_invis will be false. We can't use mtmp->mx, my since it - * might be an invisible worm hit on the tail. - */ - if (reveal_invis) { - if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y) && - !canspotmon(mtmp)) - map_invisible(bhitpos.x, bhitpos.y); - } - /* if effect was observable then discover the wand type provided - that the wand itself has been seen */ - if (learn_it) learnwand(otmp); - return 0; + Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)), + distant_name(obj, xname)); + if (cansee(mtmp->mx, mtmp->my)) { + if (!canspotmon(mtmp)) + Strcpy(buf, An(distant_name(obj, xname))); + pline("%s falls to the %s.", buf, + surface(mtmp->mx, mtmp->my)); + } else if (canspotmon(mtmp)) { + pline("%s falls off.", buf); + } + obj_extract_self(obj); + mdrop_obj(mtmp, obj, FALSE); + } + break; + case SPE_HEALING: + case SPE_EXTRA_HEALING: + reveal_invis = TRUE; + if (mtmp->data != &mons[PM_PESTILENCE]) { + wake = FALSE; /* wakeup() makes the target angry */ + mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4); + if (mtmp->mhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + if (mtmp->mblinded) { + mtmp->mblinded = 0; + mtmp->mcansee = 1; + } + if (canseemon(mtmp)) { + if (disguised_mimic) { + if (mtmp->m_ap_type == M_AP_OBJECT + && mtmp->mappearance == STRANGE_OBJECT) { + /* it can do better now */ + set_mimic_sym(mtmp); + newsym(mtmp->mx, mtmp->my); + } else + mimic_hit_msg(mtmp, otyp); + } else + pline("%s looks%s better.", Monnam(mtmp), + otyp == SPE_EXTRA_HEALING ? " much" : ""); + } + if (mtmp->mtame || mtmp->mpeaceful) { + adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type)); + } + } else { /* Pestilence */ + /* Pestilence will always resist; damage is half of 3d{4,8} */ + (void) resist(mtmp, otmp->oclass, + d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL); + } + break; + case WAN_LIGHT: /* (broken wand) */ + if (flash_hits_mon(mtmp, otmp)) { + learn_it = TRUE; + reveal_invis = TRUE; + } + break; + case WAN_SLEEP: /* (broken wand) */ + /* [wakeup() doesn't rouse victims of temporary sleep, + so it's okay to leave `wake' set to TRUE here] */ + reveal_invis = TRUE; + if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS)) + slept_monst(mtmp); + if (!Blind) + learn_it = TRUE; + break; + case SPE_STONE_TO_FLESH: + if (monsndx(mtmp->data) == PM_STONE_GOLEM) { + char *name = Monnam(mtmp); + /* turn into flesh golem */ + if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) { + if (canseemon(mtmp)) + pline("%s turns to flesh!", name); + } else { + if (canseemon(mtmp)) + pline("%s looks rather fleshy for a moment.", name); + } + } else + wake = FALSE; + break; + case SPE_DRAIN_LIFE: + dmg = monhp_per_lvl(mtmp); + if (dbldam) + dmg *= 2; + if (otyp == SPE_DRAIN_LIFE) + dmg = spell_damage_bonus(dmg); + if (resists_drli(mtmp)) + shieldeff(mtmp->mx, mtmp->my); + else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) && mtmp->mhp > 0) { + mtmp->mhp -= dmg; + mtmp->mhpmax -= dmg; + if (mtmp->mhp <= 0 || mtmp->mhpmax <= 0 || mtmp->m_lev < 1) + xkilled(mtmp, 1); + else { + mtmp->m_lev--; + if (canseemon(mtmp)) + pline("%s suddenly seems weaker!", Monnam(mtmp)); + } + } + break; + case WAN_NOTHING: + wake = FALSE; + break; + default: + impossible("What an interesting effect (%d)", otyp); + break; + } + if (wake) { + if (mtmp->mhp > 0) { + wakeup(mtmp); + m_respond(mtmp); + if (mtmp->isshk && !*u.ushops) + hot_pursuit(mtmp); + } else if (mtmp->m_ap_type) + seemimic(mtmp); /* might unblock if mimicing a boulder/door */ + } + /* note: bhitpos won't be set if swallowed, but that's okay since + * reveal_invis will be false. We can't use mtmp->mx, my since it + * might be an invisible worm hit on the tail. + */ + if (reveal_invis) { + if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y) + && !canspotmon(mtmp)) + map_invisible(bhitpos.x, bhitpos.y); + } + /* if effect was observable then discover the wand type provided + that the wand itself has been seen */ + if (learn_it) + learnwand(otmp); + return 0; } void probe_monster(mtmp) struct monst *mtmp; { - struct obj *otmp; + struct obj *otmp; - mstatusline(mtmp); - if (notonhead) return; /* don't show minvent for long worm tail */ + mstatusline(mtmp); + if (notonhead) + return; /* don't show minvent for long worm tail */ - if (mtmp->minvent) { - for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { - otmp->dknown = 1; /* treat as "seen" */ - if (Is_container(otmp) || otmp->otyp == STATUE) { - otmp->lknown = 1; - if (!SchroedingersBox(otmp)) otmp->cknown = 1; - } - } - (void) display_minventory(mtmp, MINV_ALL|MINV_NOLET, (char *)0); - } else { - pline("%s is not carrying anything%s.", noit_Monnam(mtmp), - (u.uswallow && mtmp == u.ustuck) ? " besides you" : ""); - } + if (mtmp->minvent) { + for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { + otmp->dknown = 1; /* treat as "seen" */ + if (Is_container(otmp) || otmp->otyp == STATUE) { + otmp->lknown = 1; + if (!SchroedingersBox(otmp)) + otmp->cknown = 1; + } + } + (void) display_minventory(mtmp, MINV_ALL | MINV_NOLET, (char *) 0); + } else { + pline("%s is not carrying anything%s.", noit_Monnam(mtmp), + (u.uswallow && mtmp == u.ustuck) ? " besides you" : ""); + } } /* @@ -467,142 +464,143 @@ struct obj *obj; xchar *xp, *yp; int locflags; { - switch (obj->where) { - case OBJ_INVENT: - *xp = u.ux; - *yp = u.uy; - return TRUE; - case OBJ_FLOOR: - *xp = obj->ox; - *yp = obj->oy; - return TRUE; - case OBJ_MINVENT: - if (obj->ocarry->mx) { - *xp = obj->ocarry->mx; - *yp = obj->ocarry->my; - return TRUE; - } - break; /* !mx => migrating monster */ - case OBJ_BURIED: - if (locflags & BURIED_TOO) { - *xp = obj->ox; - *yp = obj->oy; - return TRUE; - } - break; - case OBJ_CONTAINED: - if (locflags & CONTAINED_TOO) - return get_obj_location(obj->ocontainer, xp, yp, locflags); - break; - } - *xp = *yp = 0; - return FALSE; + switch (obj->where) { + case OBJ_INVENT: + *xp = u.ux; + *yp = u.uy; + return TRUE; + case OBJ_FLOOR: + *xp = obj->ox; + *yp = obj->oy; + return TRUE; + case OBJ_MINVENT: + if (obj->ocarry->mx) { + *xp = obj->ocarry->mx; + *yp = obj->ocarry->my; + return TRUE; + } + break; /* !mx => migrating monster */ + case OBJ_BURIED: + if (locflags & BURIED_TOO) { + *xp = obj->ox; + *yp = obj->oy; + return TRUE; + } + break; + case OBJ_CONTAINED: + if (locflags & CONTAINED_TOO) + return get_obj_location(obj->ocontainer, xp, yp, locflags); + break; + } + *xp = *yp = 0; + return FALSE; } boolean get_mon_location(mon, xp, yp, locflags) struct monst *mon; xchar *xp, *yp; -int locflags; /* non-zero means get location even if monster is buried */ +int locflags; /* non-zero means get location even if monster is buried */ { - if (mon == &youmonst) { - *xp = u.ux; - *yp = u.uy; - return TRUE; - } else if (mon->mx > 0 && (!mon->mburied || locflags)) { - *xp = mon->mx; - *yp = mon->my; - return TRUE; - } else { /* migrating or buried */ - *xp = *yp = 0; - return FALSE; - } + if (mon == &youmonst) { + *xp = u.ux; + *yp = u.uy; + return TRUE; + } else if (mon->mx > 0 && (!mon->mburied || locflags)) { + *xp = mon->mx; + *yp = mon->my; + return TRUE; + } else { /* migrating or buried */ + *xp = *yp = 0; + return FALSE; + } } /* used by revive() and animate_statue() */ struct monst * -montraits(obj,cc) +montraits(obj, cc) struct obj *obj; coord *cc; { - struct monst *mtmp = (struct monst *)0; - struct monst *mtmp2 = (struct monst *)0; + struct monst *mtmp = (struct monst *) 0; + struct monst *mtmp2 = (struct monst *) 0; - if (has_omonst(obj)) - mtmp2 = get_mtraits(obj, TRUE); - if (mtmp2) { - /* save_mtraits() validated mtmp2->mnum */ - mtmp2->data = &mons[mtmp2->mnum]; - if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data)) - return (struct monst *)0; - mtmp = makemon(mtmp2->data, - cc->x, cc->y, NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH); - if (!mtmp) return mtmp; + if (has_omonst(obj)) + mtmp2 = get_mtraits(obj, TRUE); + if (mtmp2) { + /* save_mtraits() validated mtmp2->mnum */ + mtmp2->data = &mons[mtmp2->mnum]; + if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data)) + return (struct monst *) 0; + mtmp = makemon(mtmp2->data, cc->x, cc->y, + NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH); + if (!mtmp) + return mtmp; - /* heal the monster */ - if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data)) - mtmp2->mhpmax = mtmp->mhpmax; - mtmp2->mhp = mtmp2->mhpmax; - /* Get these ones from mtmp */ - mtmp2->minvent = mtmp->minvent; /*redundant*/ - /* monster ID is available if the monster died in the current - game, but will be zero if the corpse was in a bones level - (we cleared it when loading bones) */ - if (mtmp->m_id) { - mtmp2->m_id = mtmp->m_id; - /* might be bringing quest leader back to life */ - if (quest_status.leader_is_dead && - /* leader_is_dead implies leader_m_id is valid */ - mtmp2->m_id == quest_status.leader_m_id) - quest_status.leader_is_dead = FALSE; - } - mtmp2->mx = mtmp->mx; - mtmp2->my = mtmp->my; - mtmp2->mux = mtmp->mux; - mtmp2->muy = mtmp->muy; - mtmp2->mw = mtmp->mw; - mtmp2->wormno = mtmp->wormno; - mtmp2->misc_worn_check = mtmp->misc_worn_check; - mtmp2->weapon_check = mtmp->weapon_check; - mtmp2->mtrapseen = mtmp->mtrapseen; - mtmp2->mflee = mtmp->mflee; - mtmp2->mburied = mtmp->mburied; - mtmp2->mundetected = mtmp->mundetected; - mtmp2->mfleetim = mtmp->mfleetim; - mtmp2->mlstmv = mtmp->mlstmv; - mtmp2->m_ap_type = mtmp->m_ap_type; - /* set these ones explicitly */ - mtmp2->mrevived = 1; - mtmp2->mavenge = 0; - mtmp2->meating = 0; - mtmp2->mleashed = 0; - mtmp2->mtrapped = 0; - mtmp2->msleeping = 0; - mtmp2->mfrozen = 0; - mtmp2->mcanmove = 1; - /* most cancelled monsters return to normal, - but some need to stay cancelled */ - if (!dmgtype(mtmp2->data, AD_SEDU) - && (!SYSOPT_SEDUCE || !dmgtype(mtmp2->data, AD_SSEX)) - ) mtmp2->mcan = 0; - mtmp2->mcansee = 1; /* set like in makemon */ - mtmp2->mblinded = 0; - mtmp2->mstun = 0; - mtmp2->mconf = 0; - replmon(mtmp,mtmp2); - newsym(mtmp2->mx, mtmp2->my); /* Might now be invisible */ + /* heal the monster */ + if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data)) + mtmp2->mhpmax = mtmp->mhpmax; + mtmp2->mhp = mtmp2->mhpmax; + /* Get these ones from mtmp */ + mtmp2->minvent = mtmp->minvent; /*redundant*/ + /* monster ID is available if the monster died in the current + game, but will be zero if the corpse was in a bones level + (we cleared it when loading bones) */ + if (mtmp->m_id) { + mtmp2->m_id = mtmp->m_id; + /* might be bringing quest leader back to life */ + if (quest_status.leader_is_dead && + /* leader_is_dead implies leader_m_id is valid */ + mtmp2->m_id == quest_status.leader_m_id) + quest_status.leader_is_dead = FALSE; + } + mtmp2->mx = mtmp->mx; + mtmp2->my = mtmp->my; + mtmp2->mux = mtmp->mux; + mtmp2->muy = mtmp->muy; + mtmp2->mw = mtmp->mw; + mtmp2->wormno = mtmp->wormno; + mtmp2->misc_worn_check = mtmp->misc_worn_check; + mtmp2->weapon_check = mtmp->weapon_check; + mtmp2->mtrapseen = mtmp->mtrapseen; + mtmp2->mflee = mtmp->mflee; + mtmp2->mburied = mtmp->mburied; + mtmp2->mundetected = mtmp->mundetected; + mtmp2->mfleetim = mtmp->mfleetim; + mtmp2->mlstmv = mtmp->mlstmv; + mtmp2->m_ap_type = mtmp->m_ap_type; + /* set these ones explicitly */ + mtmp2->mrevived = 1; + mtmp2->mavenge = 0; + mtmp2->meating = 0; + mtmp2->mleashed = 0; + mtmp2->mtrapped = 0; + mtmp2->msleeping = 0; + mtmp2->mfrozen = 0; + mtmp2->mcanmove = 1; + /* most cancelled monsters return to normal, + but some need to stay cancelled */ + if (!dmgtype(mtmp2->data, AD_SEDU) + && (!SYSOPT_SEDUCE || !dmgtype(mtmp2->data, AD_SSEX))) + mtmp2->mcan = 0; + mtmp2->mcansee = 1; /* set like in makemon */ + mtmp2->mblinded = 0; + mtmp2->mstun = 0; + mtmp2->mconf = 0; + replmon(mtmp, mtmp2); + newsym(mtmp2->mx, mtmp2->my); /* Might now be invisible */ - /* in case Protection_from_shape_changers is different - now than it was when the traits were stored */ - restore_cham(mtmp2); - } - return mtmp2; + /* in case Protection_from_shape_changers is different + now than it was when the traits were stored */ + restore_cham(mtmp2); + } + return mtmp2; } /* * get_container_location() returns the following information * about the outermost container: - * loc argument gets set to: + * loc argument gets set to: * OBJ_INVENT if in hero's inventory; return 0. * OBJ_FLOOR if on the floor; return 0. * OBJ_BURIED if buried; return 0. @@ -616,19 +614,22 @@ struct obj *obj; int *loc; int *container_nesting; { - if (!obj || !loc) - return 0; + if (!obj || !loc) + return 0; - if (container_nesting) *container_nesting = 0; - while (obj && obj->where == OBJ_CONTAINED) { - if (container_nesting) *container_nesting += 1; - obj = obj->ocontainer; - } - if (obj) { - *loc = obj->where; /* outermost container's location */ - if (obj->where == OBJ_MINVENT) return obj->ocarry; - } - return (struct monst *)0; + if (container_nesting) + *container_nesting = 0; + while (obj && obj->where == OBJ_CONTAINED) { + if (container_nesting) + *container_nesting += 1; + obj = obj->ocontainer; + } + if (obj) { + *loc = obj->where; /* outermost container's location */ + if (obj->where == OBJ_MINVENT) + return obj->ocarry; + } + return (struct monst *) 0; } /* @@ -648,52 +649,51 @@ boolean by_hero; int montype, container_nesting = 0; if (corpse->otyp != CORPSE) { - impossible("Attempting to revive %s?", xname(corpse)); - return (struct monst *)0; + impossible("Attempting to revive %s?", xname(corpse)); + return (struct monst *) 0; } x = y = 0; if (corpse->where != OBJ_CONTAINED) { - /* only for invent, minvent, or floor */ - container = 0; - (void) get_obj_location(corpse, &x, &y, 0); + /* only for invent, minvent, or floor */ + container = 0; + (void) get_obj_location(corpse, &x, &y, 0); } else { - /* deal with corpses in [possibly nested] containers */ - struct monst *carrier; - int holder = OBJ_FREE; + /* deal with corpses in [possibly nested] containers */ + struct monst *carrier; + int holder = OBJ_FREE; - container = corpse->ocontainer; - carrier = get_container_location(container, &holder, - &container_nesting); - switch (holder) { - case OBJ_MINVENT: - x = carrier->mx, y = carrier->my; - break; - case OBJ_INVENT: - x = u.ux, y = u.uy; - break; - case OBJ_FLOOR: - (void) get_obj_location(corpse, &x, &y, CONTAINED_TOO); - break; - default: - break; /* x,y are 0 */ - } + container = corpse->ocontainer; + carrier = + get_container_location(container, &holder, &container_nesting); + switch (holder) { + case OBJ_MINVENT: + x = carrier->mx, y = carrier->my; + break; + case OBJ_INVENT: + x = u.ux, y = u.uy; + break; + case OBJ_FLOOR: + (void) get_obj_location(corpse, &x, &y, CONTAINED_TOO); + break; + default: + break; /* x,y are 0 */ + } } if (!x || !y || - /* Rules for revival from containers: - - the container cannot be locked - - the container cannot be heavily nested (>2 is arbitrary) - - the container cannot be a statue or bag of holding - (except in very rare cases for the latter) - */ - (container && - (container->olocked || container_nesting > 2 || - container->otyp == STATUE || - (container->otyp == BAG_OF_HOLDING && rn2(40))))) - return (struct monst *)0; + /* Rules for revival from containers: + - the container cannot be locked + - the container cannot be heavily nested (>2 is arbitrary) + - the container cannot be a statue or bag of holding + (except in very rare cases for the latter) + */ + (container && (container->olocked || container_nesting > 2 + || container->otyp == STATUE + || (container->otyp == BAG_OF_HOLDING && rn2(40))))) + return (struct monst *) 0; /* record the object's location now that we're sure where it is */ - corpse->ox = x, corpse->oy = y; + corpse->ox = x, corpse->oy = y; /* prepare for the monster */ montype = corpse->corpsenm; @@ -701,135 +701,141 @@ boolean by_hero; /* [should probably handle recorporealization first; if corpse and ghost are at same location, revived creature shouldn't be bumped to an adjacent spot by ghost which joins with it] */ - if (MON_AT(x,y)) { - if (enexto(&xy, x, y, mptr)) - x = xy.x, y = xy.y; + if (MON_AT(x, y)) { + if (enexto(&xy, x, y, mptr)) + x = xy.x, y = xy.y; } if (cant_revive(&montype, TRUE, corpse)) { - /* make a zombie or doppelganger instead */ - /* note: montype has changed; mptr keeps old value for newcham() */ - mtmp = makemon(&mons[montype], x, y, NO_MINVENT|MM_NOWAIT); - if (mtmp) { - /* skip ghost handling */ - if (has_omid(corpse)) free_omid(corpse); - if (has_omonst(corpse)) free_omonst(corpse); - if (mtmp->cham == PM_DOPPELGANGER) { - /* change shape to match the corpse */ - (void) newcham(mtmp, mptr, FALSE, FALSE); - } else if (mtmp->data->mlet == S_ZOMBIE) { - mtmp->mhp = mtmp->mhpmax = 100; - mon_adjust_speed(mtmp, 2, (struct obj *)0); /* MFAST */ - } - } + /* make a zombie or doppelganger instead */ + /* note: montype has changed; mptr keeps old value for newcham() */ + mtmp = makemon(&mons[montype], x, y, NO_MINVENT | MM_NOWAIT); + if (mtmp) { + /* skip ghost handling */ + if (has_omid(corpse)) + free_omid(corpse); + if (has_omonst(corpse)) + free_omonst(corpse); + if (mtmp->cham == PM_DOPPELGANGER) { + /* change shape to match the corpse */ + (void) newcham(mtmp, mptr, FALSE, FALSE); + } else if (mtmp->data->mlet == S_ZOMBIE) { + mtmp->mhp = mtmp->mhpmax = 100; + mon_adjust_speed(mtmp, 2, (struct obj *) 0); /* MFAST */ + } + } } else if (has_omonst(corpse)) { - /* use saved traits */ - xy.x = x, xy.y = y; - mtmp = montraits(corpse, &xy); - if (mtmp && mtmp->mtame && !mtmp->isminion) - wary_dog(mtmp, TRUE); + /* use saved traits */ + xy.x = x, xy.y = y; + mtmp = montraits(corpse, &xy); + if (mtmp && mtmp->mtame && !mtmp->isminion) + wary_dog(mtmp, TRUE); } else { - /* make a new monster */ - mtmp = makemon(mptr, x, y, NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH); + /* make a new monster */ + mtmp = makemon(mptr, x, y, NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH); } - if (!mtmp) return (struct monst *)0; + if (!mtmp) + return (struct monst *) 0; /* hiders shouldn't already be re-hidden when they revive */ if (mtmp->mundetected) { - mtmp->mundetected = 0; - newsym(mtmp->mx, mtmp->my); + mtmp->mundetected = 0; + newsym(mtmp->mx, mtmp->my); } - if (mtmp->m_ap_type) seemimic(mtmp); + if (mtmp->m_ap_type) + seemimic(mtmp); /* if this is caused by the hero there might be a shop charge */ if (by_hero) { - struct monst *shkp = 0; + struct monst *shkp = 0; - x = corpse->ox, y = corpse->oy; - if (costly_spot(x, y)) - shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); + x = corpse->ox, y = corpse->oy; + if (costly_spot(x, y)) + shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); - if (cansee(x, y)) - pline("%s glows iridescently.", - upstart(corpse_xname(corpse, (const char *)0, CXN_PFX_THE))); - else if (shkp) - /* need some prior description of the corpse since - stolen_value() will refer to the object as "it" */ - pline("A corpse is resuscitated."); + if (cansee(x, y)) + pline( + "%s glows iridescently.", + upstart(corpse_xname(corpse, (const char *) 0, CXN_PFX_THE))); + else if (shkp) + /* need some prior description of the corpse since + stolen_value() will refer to the object as "it" */ + pline("A corpse is resuscitated."); - /* don't charge for shopkeeper's own corpse if we just revived him */ - if (shkp && mtmp != shkp) - (void) stolen_value(corpse, x, y, (boolean)shkp->mpeaceful, FALSE); + /* don't charge for shopkeeper's own corpse if we just revived him */ + if (shkp && mtmp != shkp) + (void) stolen_value(corpse, x, y, (boolean) shkp->mpeaceful, + FALSE); - /* [we don't give any comparable message about the corpse for - the !by_hero case because caller might have already done so] */ + /* [we don't give any comparable message about the corpse for + the !by_hero case because caller might have already done so] */ } /* handle recorporealization of an active ghost */ if (has_omid(corpse)) { - unsigned m_id; - struct monst *ghost; - struct obj *otmp; + unsigned m_id; + struct monst *ghost; + struct obj *otmp; - (void) memcpy((genericptr_t)&m_id, - (genericptr_t)OMID(corpse), sizeof m_id); - ghost = find_mid(m_id, FM_FMON); - if (ghost && ghost->data == &mons[PM_GHOST]) { - if (canseemon(ghost)) - pline("%s is suddenly drawn into its former body!", - Monnam(ghost)); - /* transfer the ghost's inventory along with it */ - while ((otmp = ghost->minvent) != 0) { - obj_extract_self(otmp); - add_to_minv(mtmp, otmp); - } - /* tame the revived monster if its ghost was tame */ - if (ghost->mtame && !mtmp->mtame) { - if (tamedog(mtmp, (struct obj *)0)) { - /* ghost's edog data is ignored */ - mtmp->mtame = ghost->mtame; - } - } - /* was ghost, now alive, it's all very confusing */ - mtmp->mconf = 1; - /* separate ghost monster no longer exists */ - mongone(ghost); - } - free_omid(corpse); + (void) memcpy((genericptr_t) &m_id, (genericptr_t) OMID(corpse), + sizeof m_id); + ghost = find_mid(m_id, FM_FMON); + if (ghost && ghost->data == &mons[PM_GHOST]) { + if (canseemon(ghost)) + pline("%s is suddenly drawn into its former body!", + Monnam(ghost)); + /* transfer the ghost's inventory along with it */ + while ((otmp = ghost->minvent) != 0) { + obj_extract_self(otmp); + add_to_minv(mtmp, otmp); + } + /* tame the revived monster if its ghost was tame */ + if (ghost->mtame && !mtmp->mtame) { + if (tamedog(mtmp, (struct obj *) 0)) { + /* ghost's edog data is ignored */ + mtmp->mtame = ghost->mtame; + } + } + /* was ghost, now alive, it's all very confusing */ + mtmp->mconf = 1; + /* separate ghost monster no longer exists */ + mongone(ghost); + } + free_omid(corpse); } /* monster retains its name */ if (has_oname(corpse)) - mtmp = christen_monst(mtmp, ONAME(corpse)); + mtmp = christen_monst(mtmp, ONAME(corpse)); /* partially eaten corpse yields wounded monster */ if (corpse->oeaten) - mtmp->mhp = eaten_stat(mtmp->mhp, corpse); + mtmp->mhp = eaten_stat(mtmp->mhp, corpse); /* track that this monster was revived at least once */ mtmp->mrevived = 1; /* finally, get rid of the corpse--it's gone now */ switch (corpse->where) { case OBJ_INVENT: - useup(corpse); - break; + useup(corpse); + break; case OBJ_FLOOR: - /* in case MON_AT+enexto for invisible mon */ - x = corpse->ox, y = corpse->oy; - /* not useupf(), which charges */ - if (corpse->quan > 1L) - corpse = splitobj(corpse, 1L); - delobj(corpse); - newsym(x, y); - break; + /* in case MON_AT+enexto for invisible mon */ + x = corpse->ox, y = corpse->oy; + /* not useupf(), which charges */ + if (corpse->quan > 1L) + corpse = splitobj(corpse, 1L); + delobj(corpse); + newsym(x, y); + break; case OBJ_MINVENT: - m_useup(corpse->ocarry, corpse); - break; + m_useup(corpse->ocarry, corpse); + break; case OBJ_CONTAINED: - obj_extract_self(corpse); - obfree(corpse, (struct obj *)0); - break; + obj_extract_self(corpse); + obfree(corpse, (struct obj *) 0); + break; default: - panic("revive"); + panic("revive"); } return mtmp; @@ -839,12 +845,13 @@ STATIC_OVL void revive_egg(obj) struct obj *obj; { - /* - * Note: generic eggs with corpsenm set to NON_PM will never hatch. - */ - if (obj->otyp != EGG) return; - if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE)) - attach_egg_hatch_timeout(obj, 0L); + /* + * Note: generic eggs with corpsenm set to NON_PM will never hatch. + */ + if (obj->otyp != EGG) + return; + if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE)) + attach_egg_hatch_timeout(obj, 0L); } /* try to revive all corpses and eggs carried by `mon' */ @@ -852,38 +859,39 @@ int unturn_dead(mon) struct monst *mon; { - struct obj *otmp, *otmp2; - struct monst *mtmp2; - char owner[BUFSZ], corpse[BUFSZ]; - boolean youseeit; - int once = 0, res = 0; + struct obj *otmp, *otmp2; + struct monst *mtmp2; + char owner[BUFSZ], corpse[BUFSZ]; + boolean youseeit; + int once = 0, res = 0; - youseeit = (mon == &youmonst) ? TRUE : canseemon(mon); - otmp2 = (mon == &youmonst) ? invent : mon->minvent; + youseeit = (mon == &youmonst) ? TRUE : canseemon(mon); + otmp2 = (mon == &youmonst) ? invent : mon->minvent; - while ((otmp = otmp2) != 0) { - otmp2 = otmp->nobj; - if (otmp->otyp == EGG) - revive_egg(otmp); - if (otmp->otyp != CORPSE) continue; - /* save the name; the object is liable to go away */ - if (youseeit) - Strcpy(corpse, - corpse_xname(otmp, (const char *)0, CXN_SINGULAR)); + while ((otmp = otmp2) != 0) { + otmp2 = otmp->nobj; + if (otmp->otyp == EGG) + revive_egg(otmp); + if (otmp->otyp != CORPSE) + continue; + /* save the name; the object is liable to go away */ + if (youseeit) + Strcpy(corpse, + corpse_xname(otmp, (const char *) 0, CXN_SINGULAR)); - /* for a merged group, only one is revived; should this be fixed? */ - if ((mtmp2 = revive(otmp, !context.mon_moving)) != 0) { - ++res; - if (youseeit) { - if (!once++) Strcpy(owner, - (mon == &youmonst) ? "Your" : - s_suffix(Monnam(mon))); - pline("%s %s suddenly comes alive!", owner, corpse); - } else if (canseemon(mtmp2)) - pline("%s suddenly appears!", Amonnam(mtmp2)); - } - } - return res; + /* for a merged group, only one is revived; should this be fixed? */ + if ((mtmp2 = revive(otmp, !context.mon_moving)) != 0) { + ++res; + if (youseeit) { + if (!once++) + Strcpy(owner, (mon == &youmonst) ? "Your" + : s_suffix(Monnam(mon))); + pline("%s %s suddenly comes alive!", owner, corpse); + } else if (canseemon(mtmp2)) + pline("%s suddenly appears!", Amonnam(mtmp2)); + } + } + return res; } /* cancel obj, possibly carried by you or a monster */ @@ -891,96 +899,98 @@ void cancel_item(obj) register struct obj *obj; { - boolean u_ring = (obj == uleft || obj == uright); - int otyp = obj->otyp; + boolean u_ring = (obj == uleft || obj == uright); + int otyp = obj->otyp; - switch (otyp) { - case RIN_GAIN_STRENGTH: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_STR) -= obj->spe; - context.botl = 1; - } - break; - case RIN_GAIN_CONSTITUTION: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_CON) -= obj->spe; - context.botl = 1; - } - break; - case RIN_ADORNMENT: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_CHA) -= obj->spe; - context.botl = 1; - } - break; - case RIN_INCREASE_ACCURACY: - if ((obj->owornmask & W_RING) && u_ring) - u.uhitinc -= obj->spe; - break; - case RIN_INCREASE_DAMAGE: - if ((obj->owornmask & W_RING) && u_ring) - u.udaminc -= obj->spe; - break; - case GAUNTLETS_OF_DEXTERITY: - if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { - ABON(A_DEX) -= obj->spe; - context.botl = 1; - } - break; - case HELM_OF_BRILLIANCE: - if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { - ABON(A_INT) -= obj->spe; - ABON(A_WIS) -= obj->spe; - context.botl = 1; - } - break; - /* case RIN_PROTECTION: not needed */ - } - if (objects[otyp].oc_magic || - (obj->spe && (obj->oclass == ARMOR_CLASS || - obj->oclass == WEAPON_CLASS || is_weptool(obj))) || - otyp == POT_ACID || otyp == POT_SICKNESS || - (otyp == POT_WATER && (obj->blessed || obj->cursed))) { - if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) && - otyp != WAN_CANCELLATION && /* can't cancel cancellation */ - otyp != MAGIC_LAMP && /* cancelling doesn't remove djini */ - otyp != CANDELABRUM_OF_INVOCATION) { - costly_alteration(obj, COST_CANCEL); - obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0; - } - switch (obj->oclass) { - case SCROLL_CLASS: - costly_alteration(obj, COST_CANCEL); - obj->otyp = SCR_BLANK_PAPER; - obj->spe = 0; - break; - case SPBOOK_CLASS: - if (otyp != SPE_CANCELLATION && - otyp != SPE_NOVEL && - otyp != SPE_BOOK_OF_THE_DEAD) { - costly_alteration(obj, COST_CANCEL); - obj->otyp = SPE_BLANK_PAPER; - } - break; - case POTION_CLASS: - costly_alteration(obj, (otyp != POT_WATER) ? COST_CANCEL : - obj->cursed ? COST_UNCURS : COST_UNBLSS); - if (otyp == POT_SICKNESS || otyp == POT_SEE_INVISIBLE) { - /* sickness is "biologically contaminated" fruit juice; - cancel it and it just becomes fruit juice... - whereas see invisible tastes like "enchanted" fruit - juice, it similarly cancels */ - obj->otyp = POT_FRUIT_JUICE; - } else { - obj->otyp = POT_WATER; - obj->odiluted = 0; /* same as any other water */ - } - break; - } - } - unbless(obj); - uncurse(obj); - return; + switch (otyp) { + case RIN_GAIN_STRENGTH: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_STR) -= obj->spe; + context.botl = 1; + } + break; + case RIN_GAIN_CONSTITUTION: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_CON) -= obj->spe; + context.botl = 1; + } + break; + case RIN_ADORNMENT: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_CHA) -= obj->spe; + context.botl = 1; + } + break; + case RIN_INCREASE_ACCURACY: + if ((obj->owornmask & W_RING) && u_ring) + u.uhitinc -= obj->spe; + break; + case RIN_INCREASE_DAMAGE: + if ((obj->owornmask & W_RING) && u_ring) + u.udaminc -= obj->spe; + break; + case GAUNTLETS_OF_DEXTERITY: + if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { + ABON(A_DEX) -= obj->spe; + context.botl = 1; + } + break; + case HELM_OF_BRILLIANCE: + if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { + ABON(A_INT) -= obj->spe; + ABON(A_WIS) -= obj->spe; + context.botl = 1; + } + break; + /* case RIN_PROTECTION: not needed */ + } + if (objects[otyp].oc_magic + || (obj->spe && (obj->oclass == ARMOR_CLASS + || obj->oclass == WEAPON_CLASS || is_weptool(obj))) + || otyp == POT_ACID + || otyp == POT_SICKNESS + || (otyp == POT_WATER && (obj->blessed || obj->cursed))) { + if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) + && otyp != WAN_CANCELLATION && /* can't cancel cancellation */ + otyp != MAGIC_LAMP && /* cancelling doesn't remove djini */ + otyp != CANDELABRUM_OF_INVOCATION) { + costly_alteration(obj, COST_CANCEL); + obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0; + } + switch (obj->oclass) { + case SCROLL_CLASS: + costly_alteration(obj, COST_CANCEL); + obj->otyp = SCR_BLANK_PAPER; + obj->spe = 0; + break; + case SPBOOK_CLASS: + if (otyp != SPE_CANCELLATION && otyp != SPE_NOVEL + && otyp != SPE_BOOK_OF_THE_DEAD) { + costly_alteration(obj, COST_CANCEL); + obj->otyp = SPE_BLANK_PAPER; + } + break; + case POTION_CLASS: + costly_alteration(obj, + (otyp != POT_WATER) + ? COST_CANCEL + : obj->cursed ? COST_UNCURS : COST_UNBLSS); + if (otyp == POT_SICKNESS || otyp == POT_SEE_INVISIBLE) { + /* sickness is "biologically contaminated" fruit juice; + cancel it and it just becomes fruit juice... + whereas see invisible tastes like "enchanted" fruit + juice, it similarly cancels */ + obj->otyp = POT_FRUIT_JUICE; + } else { + obj->otyp = POT_WATER; + obj->odiluted = 0; /* same as any other water */ + } + break; + } + } + unbless(obj); + uncurse(obj); + return; } /* Remove a positive enchantment or charge from obj, @@ -990,111 +1000,112 @@ boolean drain_item(obj) register struct obj *obj; { - boolean u_ring; + boolean u_ring; - /* Is this a charged/enchanted object? */ - if (!obj || (!objects[obj->otyp].oc_charged && - obj->oclass != WEAPON_CLASS && - obj->oclass != ARMOR_CLASS && !is_weptool(obj)) || - obj->spe <= 0) - return (FALSE); - if (defends(AD_DRLI, obj) || defends_when_carried(AD_DRLI, obj) || - obj_resists(obj, 10, 90)) - return (FALSE); + /* Is this a charged/enchanted object? */ + if (!obj || (!objects[obj->otyp].oc_charged && obj->oclass != WEAPON_CLASS + && obj->oclass != ARMOR_CLASS && !is_weptool(obj)) + || obj->spe <= 0) + return (FALSE); + if (defends(AD_DRLI, obj) || defends_when_carried(AD_DRLI, obj) + || obj_resists(obj, 10, 90)) + return (FALSE); - /* Charge for the cost of the object */ - costly_alteration(obj, COST_DRAIN); + /* Charge for the cost of the object */ + costly_alteration(obj, COST_DRAIN); - /* Drain the object and any implied effects */ - obj->spe--; - u_ring = (obj == uleft) || (obj == uright); - switch(obj->otyp) { - case RIN_GAIN_STRENGTH: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_STR)--; - context.botl = 1; - } - break; - case RIN_GAIN_CONSTITUTION: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_CON)--; - context.botl = 1; - } - break; - case RIN_ADORNMENT: - if ((obj->owornmask & W_RING) && u_ring) { - ABON(A_CHA)--; - context.botl = 1; - } - break; - case RIN_INCREASE_ACCURACY: - if ((obj->owornmask & W_RING) && u_ring) - u.uhitinc--; - break; - case RIN_INCREASE_DAMAGE: - if ((obj->owornmask & W_RING) && u_ring) - u.udaminc--; - break; - case HELM_OF_BRILLIANCE: - if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { - ABON(A_INT)--; - ABON(A_WIS)--; - context.botl = 1; - } - break; - case GAUNTLETS_OF_DEXTERITY: - if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { - ABON(A_DEX)--; - context.botl = 1; - } - break; - case RIN_PROTECTION: - context.botl = 1; - break; - } - if (carried(obj)) update_inventory(); - return (TRUE); + /* Drain the object and any implied effects */ + obj->spe--; + u_ring = (obj == uleft) || (obj == uright); + switch (obj->otyp) { + case RIN_GAIN_STRENGTH: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_STR)--; + context.botl = 1; + } + break; + case RIN_GAIN_CONSTITUTION: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_CON)--; + context.botl = 1; + } + break; + case RIN_ADORNMENT: + if ((obj->owornmask & W_RING) && u_ring) { + ABON(A_CHA)--; + context.botl = 1; + } + break; + case RIN_INCREASE_ACCURACY: + if ((obj->owornmask & W_RING) && u_ring) + u.uhitinc--; + break; + case RIN_INCREASE_DAMAGE: + if ((obj->owornmask & W_RING) && u_ring) + u.udaminc--; + break; + case HELM_OF_BRILLIANCE: + if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { + ABON(A_INT)--; + ABON(A_WIS)--; + context.botl = 1; + } + break; + case GAUNTLETS_OF_DEXTERITY: + if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { + ABON(A_DEX)--; + context.botl = 1; + } + break; + case RIN_PROTECTION: + context.botl = 1; + break; + } + if (carried(obj)) + update_inventory(); + return (TRUE); } boolean obj_resists(obj, ochance, achance) struct obj *obj; -int ochance, achance; /* percent chance for ordinary objects, artifacts */ +int ochance, achance; /* percent chance for ordinary objects, artifacts */ { - if (obj->otyp == AMULET_OF_YENDOR || - obj->otyp == SPE_BOOK_OF_THE_DEAD || - obj->otyp == CANDELABRUM_OF_INVOCATION || - obj->otyp == BELL_OF_OPENING || - (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) { - return TRUE; - } else { - int chance = rn2(100); + if (obj->otyp == AMULET_OF_YENDOR || obj->otyp == SPE_BOOK_OF_THE_DEAD + || obj->otyp == CANDELABRUM_OF_INVOCATION + || obj->otyp == BELL_OF_OPENING + || (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) { + return TRUE; + } else { + int chance = rn2(100); - return((boolean)(chance < (obj->oartifact ? achance : ochance))); - } + return ((boolean)(chance < (obj->oartifact ? achance : ochance))); + } } boolean obj_shudders(obj) struct obj *obj; { - int zap_odds; + int zap_odds; - if (context.bypasses && obj->bypass) return FALSE; + if (context.bypasses && obj->bypass) + return FALSE; - if (obj->oclass == WAND_CLASS) - zap_odds = 3; /* half-life = 2 zaps */ - else if (obj->cursed) - zap_odds = 3; /* half-life = 2 zaps */ - else if (obj->blessed) - zap_odds = 12; /* half-life = 8 zaps */ - else - zap_odds = 8; /* half-life = 6 zaps */ + if (obj->oclass == WAND_CLASS) + zap_odds = 3; /* half-life = 2 zaps */ + else if (obj->cursed) + zap_odds = 3; /* half-life = 2 zaps */ + else if (obj->blessed) + zap_odds = 12; /* half-life = 8 zaps */ + else + zap_odds = 8; /* half-life = 6 zaps */ - /* adjust for "large" quantities of identical things */ - if(obj->quan > 4L) zap_odds /= 2; + /* adjust for "large" quantities of identical things */ + if (obj->quan > 4L) + zap_odds /= 2; - return((boolean)(! rn2(zap_odds))); + return ((boolean)(!rn2(zap_odds))); } /* Use up at least minwt number of things made of material mat. @@ -1104,36 +1115,40 @@ struct obj *obj; */ STATIC_OVL void polyuse(objhdr, mat, minwt) - struct obj *objhdr; - int mat, minwt; +struct obj *objhdr; +int mat, minwt; { register struct obj *otmp, *otmp2; - for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) { - otmp2 = otmp->nexthere; - if (context.bypasses && otmp->bypass) continue; - if (otmp == uball || otmp == uchain) continue; - if (obj_resists(otmp, 0, 0)) continue; /* preserve unique objects */ + for (otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) { + otmp2 = otmp->nexthere; + if (context.bypasses && otmp->bypass) + continue; + if (otmp == uball || otmp == uchain) + continue; + if (obj_resists(otmp, 0, 0)) + continue; /* preserve unique objects */ #ifdef MAIL - if (otmp->otyp == SCR_MAIL) continue; + if (otmp->otyp == SCR_MAIL) + continue; #endif - if (((int) objects[otmp->otyp].oc_material == mat) == - (rn2(minwt + 1) != 0)) { - /* appropriately add damage to bill */ - if (costly_spot(otmp->ox, otmp->oy)) { - if (*u.ushops) - addtobill(otmp, FALSE, FALSE, FALSE); - else - (void)stolen_value(otmp, - otmp->ox, otmp->oy, FALSE, FALSE); - } - if (otmp->quan < LARGEST_INT) - minwt -= (int)otmp->quan; - else - minwt = 0; - delobj(otmp); - } + if (((int) objects[otmp->otyp].oc_material == mat) + == (rn2(minwt + 1) != 0)) { + /* appropriately add damage to bill */ + if (costly_spot(otmp->ox, otmp->oy)) { + if (*u.ushops) + addtobill(otmp, FALSE, FALSE, FALSE); + else + (void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE, + FALSE); + } + if (otmp->quan < LARGEST_INT) + minwt -= (int) otmp->quan; + else + minwt = 0; + delobj(otmp); + } } } @@ -1143,92 +1158,94 @@ polyuse(objhdr, mat, minwt) */ STATIC_OVL void create_polymon(obj, okind) - struct obj *obj; - int okind; +struct obj *obj; +int okind; { - struct permonst *mdat = (struct permonst *)0; - struct monst *mtmp; - const char *material; - int pm_index; + struct permonst *mdat = (struct permonst *) 0; + struct monst *mtmp; + const char *material; + int pm_index; - if (context.bypasses) { - /* this is approximate because the "no golems" !obj->nexthere - check below doesn't understand bypassed objects; but it - should suffice since bypassed objects always end up as a - consecutive group at the top of their pile */ - while (obj && obj->bypass) obj = obj->nexthere; - } + if (context.bypasses) { + /* this is approximate because the "no golems" !obj->nexthere + check below doesn't understand bypassed objects; but it + should suffice since bypassed objects always end up as a + consecutive group at the top of their pile */ + while (obj && obj->bypass) + obj = obj->nexthere; + } - /* no golems if you zap only one object -- not enough stuff */ - if(!obj || (!obj->nexthere && obj->quan == 1L)) return; + /* no golems if you zap only one object -- not enough stuff */ + if (!obj || (!obj->nexthere && obj->quan == 1L)) + return; - /* some of these choices are arbitrary */ - switch(okind) { - case IRON: - case METAL: - case MITHRIL: - pm_index = PM_IRON_GOLEM; - material = "metal "; - break; - case COPPER: - case SILVER: - case PLATINUM: - case GEMSTONE: - case MINERAL: - pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM; - material = "lithic "; - break; - case 0: - case FLESH: - /* there is no flesh type, but all food is type 0, so we use it */ - pm_index = PM_FLESH_GOLEM; - material = "organic "; - break; - case WOOD: - pm_index = PM_WOOD_GOLEM; - material = "wood "; - break; - case LEATHER: - pm_index = PM_LEATHER_GOLEM; - material = "leather "; - break; - case CLOTH: - pm_index = PM_ROPE_GOLEM; - material = "cloth "; - break; - case BONE: - pm_index = PM_SKELETON; /* nearest thing to "bone golem" */ - material = "bony "; - break; - case GOLD: - pm_index = PM_GOLD_GOLEM; - material = "gold "; - break; - case GLASS: - pm_index = PM_GLASS_GOLEM; - material = "glassy "; - break; - case PAPER: - pm_index = PM_PAPER_GOLEM; - material = "paper "; - break; - default: - /* if all else fails... */ - pm_index = PM_STRAW_GOLEM; - material = ""; - break; - } + /* some of these choices are arbitrary */ + switch (okind) { + case IRON: + case METAL: + case MITHRIL: + pm_index = PM_IRON_GOLEM; + material = "metal "; + break; + case COPPER: + case SILVER: + case PLATINUM: + case GEMSTONE: + case MINERAL: + pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM; + material = "lithic "; + break; + case 0: + case FLESH: + /* there is no flesh type, but all food is type 0, so we use it */ + pm_index = PM_FLESH_GOLEM; + material = "organic "; + break; + case WOOD: + pm_index = PM_WOOD_GOLEM; + material = "wood "; + break; + case LEATHER: + pm_index = PM_LEATHER_GOLEM; + material = "leather "; + break; + case CLOTH: + pm_index = PM_ROPE_GOLEM; + material = "cloth "; + break; + case BONE: + pm_index = PM_SKELETON; /* nearest thing to "bone golem" */ + material = "bony "; + break; + case GOLD: + pm_index = PM_GOLD_GOLEM; + material = "gold "; + break; + case GLASS: + pm_index = PM_GLASS_GOLEM; + material = "glassy "; + break; + case PAPER: + pm_index = PM_PAPER_GOLEM; + material = "paper "; + break; + default: + /* if all else fails... */ + pm_index = PM_STRAW_GOLEM; + material = ""; + break; + } - if (!(mvitals[pm_index].mvflags & G_GENOD)) - mdat = &mons[pm_index]; + if (!(mvitals[pm_index].mvflags & G_GENOD)) + mdat = &mons[pm_index]; - mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS); - polyuse(obj, okind, (int)mons[pm_index].cwt); + mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS); + polyuse(obj, okind, (int) mons[pm_index].cwt); - if(mtmp && cansee(mtmp->mx, mtmp->my)) { - pline("Some %sobjects meld, and %s arises from the pile!", - material, a_monnam(mtmp)); - } + if (mtmp && cansee(mtmp->mx, mtmp->my)) { + pline("Some %sobjects meld, and %s arises from the pile!", material, + a_monnam(mtmp)); + } } /* Assumes obj is on the floor. */ @@ -1236,47 +1253,47 @@ void do_osshock(obj) struct obj *obj; { - long i; + long i; #ifdef MAIL - if (obj->otyp == SCR_MAIL) return; + if (obj->otyp == SCR_MAIL) + return; #endif - obj_zapped = TRUE; + obj_zapped = TRUE; - if(poly_zapped < 0) { - /* some may metamorphosize */ - for (i = obj->quan; i; i--) - if (! rn2(Luck + 45)) { - poly_zapped = objects[obj->otyp].oc_material; - break; - } - } + if (poly_zapped < 0) { + /* some may metamorphosize */ + for (i = obj->quan; i; i--) + if (!rn2(Luck + 45)) { + poly_zapped = objects[obj->otyp].oc_material; + break; + } + } - /* if quan > 1 then some will survive intact */ - if (obj->quan > 1L) { - if (obj->quan > LARGEST_INT) - obj = splitobj(obj, (long)rnd(30000)); - else - obj = splitobj(obj, (long)rnd((int)obj->quan - 1)); - } + /* if quan > 1 then some will survive intact */ + if (obj->quan > 1L) { + if (obj->quan > LARGEST_INT) + obj = splitobj(obj, (long) rnd(30000)); + else + obj = splitobj(obj, (long) rnd((int) obj->quan - 1)); + } - /* appropriately add damage to bill */ - if (costly_spot(obj->ox, obj->oy)) { - if (*u.ushops) - addtobill(obj, FALSE, FALSE, FALSE); - else - (void)stolen_value(obj, - obj->ox, obj->oy, FALSE, FALSE); - } + /* appropriately add damage to bill */ + if (costly_spot(obj->ox, obj->oy)) { + if (*u.ushops) + addtobill(obj, FALSE, FALSE, FALSE); + else + (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE); + } - /* zap the object */ - delobj(obj); + /* zap the object */ + delobj(obj); } -/* classes of items whose current charge count carries over across polymorph */ -static const char charged_objs[] = { - WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, '\0' -}; +/* classes of items whose current charge count carries over across polymorph + */ +static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, + '\0' }; /* * Polymorph the object to the given object ID. If the ID is STRANGE_OBJECT @@ -1291,256 +1308,266 @@ static const char charged_objs[] = { */ struct obj * poly_obj(obj, id) - struct obj *obj; - int id; +struct obj *obj; +int id; { - struct obj *otmp; - xchar ox, oy; - boolean can_merge = (id == STRANGE_OBJECT); - int obj_location = obj->where; + struct obj *otmp; + xchar ox, oy; + boolean can_merge = (id == STRANGE_OBJECT); + int obj_location = obj->where; - if (obj->otyp == BOULDER) - sokoban_guilt(); - if (id == STRANGE_OBJECT) { /* preserve symbol */ - int try_limit = 3; - unsigned magic_obj = objects[obj->otyp].oc_magic; + if (obj->otyp == BOULDER) + sokoban_guilt(); + if (id == STRANGE_OBJECT) { /* preserve symbol */ + int try_limit = 3; + unsigned magic_obj = objects[obj->otyp].oc_magic; - if (obj->otyp == UNICORN_HORN && obj->degraded_horn) magic_obj = 0; - /* Try up to 3 times to make the magic-or-not status of - the new item be the same as it was for the old one. */ - otmp = (struct obj *)0; - do { - if (otmp) delobj(otmp); - otmp = mkobj(obj->oclass, FALSE); - } while (--try_limit > 0 && - objects[otmp->otyp].oc_magic != magic_obj); - } else { - /* literally replace obj with this new thing */ - otmp = mksobj(id, FALSE, FALSE); - /* Actually more things use corpsenm but they polymorph differently */ -#define USES_CORPSENM(typ) ((typ)==CORPSE || (typ)==STATUE || (typ)==FIGURINE) - if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id)) - set_corpsenm(otmp, obj->corpsenm); + if (obj->otyp == UNICORN_HORN && obj->degraded_horn) + magic_obj = 0; + /* Try up to 3 times to make the magic-or-not status of + the new item be the same as it was for the old one. */ + otmp = (struct obj *) 0; + do { + if (otmp) + delobj(otmp); + otmp = mkobj(obj->oclass, FALSE); + } while (--try_limit > 0 + && objects[otmp->otyp].oc_magic != magic_obj); + } else { + /* literally replace obj with this new thing */ + otmp = mksobj(id, FALSE, FALSE); +/* Actually more things use corpsenm but they polymorph differently */ +#define USES_CORPSENM(typ) \ + ((typ) == CORPSE || (typ) == STATUE || (typ) == FIGURINE) + if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id)) + set_corpsenm(otmp, obj->corpsenm); #undef USES_CORPSENM - } + } - /* preserve quantity */ - otmp->quan = obj->quan; - /* preserve the shopkeepers (lack of) interest */ - otmp->no_charge = obj->no_charge; - /* preserve inventory letter if in inventory */ - if (obj_location == OBJ_INVENT) - otmp->invlet = obj->invlet; + /* preserve quantity */ + otmp->quan = obj->quan; + /* preserve the shopkeepers (lack of) interest */ + otmp->no_charge = obj->no_charge; + /* preserve inventory letter if in inventory */ + if (obj_location == OBJ_INVENT) + otmp->invlet = obj->invlet; #ifdef MAIL - /* You can't send yourself 100 mail messages and then - * polymorph them into useful scrolls - */ - if (obj->otyp == SCR_MAIL) { - otmp->otyp = SCR_MAIL; - otmp->spe = 1; - } + /* You can't send yourself 100 mail messages and then + * polymorph them into useful scrolls + */ + if (obj->otyp == SCR_MAIL) { + otmp->otyp = SCR_MAIL; + otmp->spe = 1; + } #endif - /* avoid abusing eggs laid by you */ - if (obj->otyp == EGG && obj->spe) { - int mnum, tryct = 100; + /* avoid abusing eggs laid by you */ + if (obj->otyp == EGG && obj->spe) { + int mnum, tryct = 100; - /* first, turn into a generic egg */ - if (otmp->otyp == EGG) - kill_egg(otmp); - else { - otmp->otyp = EGG; - otmp->owt = weight(otmp); - } - otmp->corpsenm = NON_PM; - otmp->spe = 0; + /* first, turn into a generic egg */ + if (otmp->otyp == EGG) + kill_egg(otmp); + else { + otmp->otyp = EGG; + otmp->owt = weight(otmp); + } + otmp->corpsenm = NON_PM; + otmp->spe = 0; - /* now change it into something layed by the hero */ - while (tryct--) { - mnum = can_be_hatched(random_monster()); - if (mnum != NON_PM && !dead_species(mnum, TRUE)) { - otmp->spe = 1; /* layed by hero */ - set_corpsenm(otmp, mnum); /* also sets hatch timer */ - break; - } - } - } + /* now change it into something layed by the hero */ + while (tryct--) { + mnum = can_be_hatched(random_monster()); + if (mnum != NON_PM && !dead_species(mnum, TRUE)) { + otmp->spe = 1; /* layed by hero */ + set_corpsenm(otmp, mnum); /* also sets hatch timer */ + break; + } + } + } - /* keep special fields (including charges on wands) */ - if (index(charged_objs, otmp->oclass)) otmp->spe = obj->spe; - otmp->recharged = obj->recharged; + /* keep special fields (including charges on wands) */ + if (index(charged_objs, otmp->oclass)) + otmp->spe = obj->spe; + otmp->recharged = obj->recharged; - otmp->cursed = obj->cursed; - otmp->blessed = obj->blessed; - otmp->oeroded = obj->oeroded; - otmp->oeroded2 = obj->oeroded2; - if (!is_flammable(otmp) && !is_rustprone(otmp)) otmp->oeroded = 0; - if (!is_corrodeable(otmp) && !is_rottable(otmp)) otmp->oeroded2 = 0; - if (is_damageable(otmp)) - otmp->oerodeproof = obj->oerodeproof; + otmp->cursed = obj->cursed; + otmp->blessed = obj->blessed; + otmp->oeroded = obj->oeroded; + otmp->oeroded2 = obj->oeroded2; + if (!is_flammable(otmp) && !is_rustprone(otmp)) + otmp->oeroded = 0; + if (!is_corrodeable(otmp) && !is_rottable(otmp)) + otmp->oeroded2 = 0; + if (is_damageable(otmp)) + otmp->oerodeproof = obj->oerodeproof; - /* Keep chest/box traps and poisoned ammo if we may */ - if (obj->otrapped && Is_box(otmp)) otmp->otrapped = TRUE; + /* Keep chest/box traps and poisoned ammo if we may */ + if (obj->otrapped && Is_box(otmp)) + otmp->otrapped = TRUE; - if (obj->opoisoned && is_poisonable(otmp)) - otmp->opoisoned = TRUE; + if (obj->opoisoned && is_poisonable(otmp)) + otmp->opoisoned = TRUE; - if (id == STRANGE_OBJECT && obj->otyp == CORPSE) { - /* turn crocodile corpses into shoes */ - if (obj->corpsenm == PM_CROCODILE) { - otmp->otyp = LOW_BOOTS; - otmp->oclass = ARMOR_CLASS; - otmp->spe = 0; - otmp->oeroded = 0; - otmp->oerodeproof = TRUE; - otmp->quan = 1L; - otmp->cursed = FALSE; - } - } + if (id == STRANGE_OBJECT && obj->otyp == CORPSE) { + /* turn crocodile corpses into shoes */ + if (obj->corpsenm == PM_CROCODILE) { + otmp->otyp = LOW_BOOTS; + otmp->oclass = ARMOR_CLASS; + otmp->spe = 0; + otmp->oeroded = 0; + otmp->oerodeproof = TRUE; + otmp->quan = 1L; + otmp->cursed = FALSE; + } + } - /* no box contents --KAA */ - if (Has_contents(otmp)) delete_contents(otmp); + /* no box contents --KAA */ + if (Has_contents(otmp)) + delete_contents(otmp); - /* 'n' merged objects may be fused into 1 object */ - if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge || - (can_merge && otmp->quan > (long)rn2(1000)))) - otmp->quan = 1L; + /* 'n' merged objects may be fused into 1 object */ + if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge + || (can_merge && otmp->quan > (long) rn2(1000)))) + otmp->quan = 1L; - switch (otmp->oclass) { + switch (otmp->oclass) { + case TOOL_CLASS: + if (otmp->otyp == MAGIC_LAMP) { + otmp->otyp = OIL_LAMP; + otmp->age = 1500L; /* "best" oil lamp possible */ + } else if (otmp->otyp == MAGIC_MARKER) { + otmp->recharged = 1; /* degraded quality */ + } + /* don't care about the recharge count of other tools */ + break; - case TOOL_CLASS: - if (otmp->otyp == MAGIC_LAMP) { - otmp->otyp = OIL_LAMP; - otmp->age = 1500L; /* "best" oil lamp possible */ - } else if (otmp->otyp == MAGIC_MARKER) { - otmp->recharged = 1; /* degraded quality */ - } - /* don't care about the recharge count of other tools */ - break; + case WAND_CLASS: + while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH) + otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); + /* altering the object tends to degrade its quality + (analogous to spellbook `read count' handling) */ + if ((int) otmp->recharged < rn2(7)) /* recharge_limit */ + otmp->recharged++; + break; - case WAND_CLASS: - while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH) - otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); - /* altering the object tends to degrade its quality - (analogous to spellbook `read count' handling) */ - if ((int)otmp->recharged < rn2(7)) /* recharge_limit */ - otmp->recharged++; - break; + case POTION_CLASS: + while (otmp->otyp == POT_POLYMORPH) + otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER); + break; - case POTION_CLASS: - while (otmp->otyp == POT_POLYMORPH) - otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER); - break; + case SPBOOK_CLASS: + while (otmp->otyp == SPE_POLYMORPH) + otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER); + /* reduce spellbook abuse; non-blank books degrade */ + if (otmp->otyp != SPE_BLANK_PAPER) { + otmp->spestudied = obj->spestudied + 1; + if (otmp->spestudied > MAX_SPELL_STUDY) { + otmp->otyp = SPE_BLANK_PAPER; + /* writing a new book over it will yield an unstudied + one; re-polymorphing this one as-is may or may not + get something non-blank */ + otmp->spestudied = rn2(otmp->spestudied); + } + } + break; - case SPBOOK_CLASS: - while (otmp->otyp == SPE_POLYMORPH) - otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER); - /* reduce spellbook abuse; non-blank books degrade */ - if (otmp->otyp != SPE_BLANK_PAPER) { - otmp->spestudied = obj->spestudied + 1; - if (otmp->spestudied > MAX_SPELL_STUDY) { - otmp->otyp = SPE_BLANK_PAPER; - /* writing a new book over it will yield an unstudied - one; re-polymorphing this one as-is may or may not - get something non-blank */ - otmp->spestudied = rn2(otmp->spestudied); - } - } - break; + case GEM_CLASS: + if (otmp->quan > (long) rnd(4) + && objects[obj->otyp].oc_material == MINERAL + && objects[otmp->otyp].oc_material != MINERAL) { + otmp->otyp = ROCK; /* transmutation backfired */ + otmp->quan /= 2L; /* some material has been lost */ + } + break; + } - case GEM_CLASS: - if (otmp->quan > (long) rnd(4) && - objects[obj->otyp].oc_material == MINERAL && - objects[otmp->otyp].oc_material != MINERAL) { - otmp->otyp = ROCK; /* transmutation backfired */ - otmp->quan /= 2L; /* some material has been lost */ - } - break; - } + /* update the weight */ + otmp->owt = weight(otmp); - /* update the weight */ - otmp->owt = weight(otmp); + /* handle polymorph of worn item: stone-to-flesh cast on self can + affect multiple objects at once, but their new forms won't + produce any side-effects; a single worn item dipped into potion + of polymorph can produce side-effects but those won't yield out + of sequence messages because current polymorph is finished */ + if (obj_location == OBJ_INVENT && obj->owornmask) { + long old_wornmask = obj->owornmask & ~(W_ART | W_ARTI), + new_wornmask = wearslot(otmp); + boolean was_twohanded = bimanual(obj), was_twoweap = u.twoweap; - /* handle polymorph of worn item: stone-to-flesh cast on self can - affect multiple objects at once, but their new forms won't - produce any side-effects; a single worn item dipped into potion - of polymorph can produce side-effects but those won't yield out - of sequence messages because current polymorph is finished */ - if (obj_location == OBJ_INVENT && obj->owornmask) { - long old_wornmask = obj->owornmask & ~(W_ART|W_ARTI), - new_wornmask = wearslot(otmp); - boolean was_twohanded = bimanual(obj), - was_twoweap = u.twoweap; + remove_worn_item(obj, TRUE); + /* if the new form can be worn in the same slot, make it so + [possible extension: if it could be worn in some other + slot which is currently unfilled, wear it there instead] */ + if ((old_wornmask & W_QUIVER) != 0L) { + setuqwep(otmp); + } else if ((old_wornmask & W_SWAPWEP) != 0L) { + if (was_twohanded || !bimanual(otmp)) + setuswapwep(otmp); + if (was_twoweap && uswapwep) + u.twoweap = TRUE; + } else if ((old_wornmask & W_WEP) != 0L) { + if (was_twohanded || !bimanual(otmp) || !uarms) + setuwep(otmp); + if (was_twoweap && uwep && !bimanual(uwep)) + u.twoweap = TRUE; + } else if ((old_wornmask & new_wornmask) != 0L) { + new_wornmask &= old_wornmask; + setworn(otmp, new_wornmask); + set_wear(otmp); /* Armor_on() for side-effects */ + } + } - remove_worn_item(obj, TRUE); - /* if the new form can be worn in the same slot, make it so - [possible extension: if it could be worn in some other - slot which is currently unfilled, wear it there instead] */ - if ((old_wornmask & W_QUIVER) != 0L) { - setuqwep(otmp); - } else if ((old_wornmask & W_SWAPWEP) != 0L) { - if (was_twohanded || !bimanual(otmp)) - setuswapwep(otmp); - if (was_twoweap && uswapwep) u.twoweap = TRUE; - } else if ((old_wornmask & W_WEP) != 0L) { - if (was_twohanded || !bimanual(otmp) || !uarms) - setuwep(otmp); - if (was_twoweap && uwep && !bimanual(uwep)) u.twoweap = TRUE; - } else if ((old_wornmask & new_wornmask) != 0L) { - new_wornmask &= old_wornmask; - setworn(otmp, new_wornmask); - set_wear(otmp); /* Armor_on() for side-effects */ - } - } + /* ** we are now done adjusting the object ** */ - /* ** we are now done adjusting the object ** */ + /* swap otmp for obj */ + replace_object(obj, otmp); + if (obj_location == OBJ_INVENT) { + /* + * We may need to do extra adjustments for the hero if we're + * messing with the hero's inventory. The following calls are + * equivalent to calling freeinv on obj and addinv on otmp, + * while doing an in-place swap of the actual objects. + */ + freeinv_core(obj); + addinv_core1(otmp); + addinv_core2(otmp); + } else if (obj_location == OBJ_FLOOR) { + ox = otmp->ox, oy = otmp->oy; /* set by replace_object() */ + if (obj->otyp == BOULDER && otmp->otyp != BOULDER + && !does_block(ox, oy, &levl[ox][oy])) + unblock_point(ox, oy); + else if (obj->otyp != BOULDER && otmp->otyp == BOULDER) + /* (checking does_block() here would be redundant) */ + block_point(ox, oy); + } - /* swap otmp for obj */ - replace_object(obj, otmp); - if (obj_location == OBJ_INVENT) { - /* - * We may need to do extra adjustments for the hero if we're - * messing with the hero's inventory. The following calls are - * equivalent to calling freeinv on obj and addinv on otmp, - * while doing an in-place swap of the actual objects. - */ - freeinv_core(obj); - addinv_core1(otmp); - addinv_core2(otmp); - } else if (obj_location == OBJ_FLOOR) { - ox = otmp->ox, oy = otmp->oy; /* set by replace_object() */ - if (obj->otyp == BOULDER && otmp->otyp != BOULDER && - !does_block(ox, oy, &levl[ox][oy])) - unblock_point(ox, oy); - else if (obj->otyp != BOULDER && otmp->otyp == BOULDER) - /* (checking does_block() here would be redundant) */ - block_point(ox, oy); - } + if ((!carried(otmp) || obj->unpaid) + && get_obj_location(otmp, &ox, &oy, BURIED_TOO | CONTAINED_TOO) + && costly_spot(ox, oy)) { + register struct monst *shkp = + shop_keeper(*in_rooms(ox, oy, SHOPBASE)); - if ((!carried(otmp) || obj->unpaid) && - get_obj_location(otmp, &ox, &oy, BURIED_TOO|CONTAINED_TOO) && - costly_spot(ox, oy)) { - register struct monst *shkp = - shop_keeper(*in_rooms(ox, oy, SHOPBASE)); - - if ((!obj->no_charge || - (Has_contents(obj) && - (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L))) - && inhishop(shkp)) { - if(shkp->mpeaceful) { - if(*u.ushops && *in_rooms(u.ux, u.uy, 0) == - *in_rooms(shkp->mx, shkp->my, 0) && - !costly_spot(u.ux, u.uy)) - make_angry_shk(shkp, ox, oy); - else { - pline("%s gets angry!", Monnam(shkp)); - hot_pursuit(shkp); - } - } else Norep("%s is furious!", Monnam(shkp)); - } - } - delobj(obj); - return otmp; + if ((!obj->no_charge + || (Has_contents(obj) + && (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L))) + && inhishop(shkp)) { + if (shkp->mpeaceful) { + if (*u.ushops + && *in_rooms(u.ux, u.uy, 0) + == *in_rooms(shkp->mx, shkp->my, 0) + && !costly_spot(u.ux, u.uy)) + make_angry_shk(shkp, ox, oy); + else { + pline("%s gets angry!", Monnam(shkp)); + hot_pursuit(shkp); + } + } else + Norep("%s is furious!", Monnam(shkp)); + } + } + delobj(obj); + return otmp; } /* stone-to-flesh spell hits and maybe transforms or animates obj */ @@ -1548,113 +1575,118 @@ STATIC_OVL int stone_to_flesh_obj(obj) struct obj *obj; { - int res = 1; /* affected object by default */ + int res = 1; /* affected object by default */ struct permonst *ptr; struct monst *mon; struct obj *item; xchar oox, ooy; boolean smell = FALSE, golem_xform = FALSE; - if (objects[obj->otyp].oc_material != MINERAL && - objects[obj->otyp].oc_material != GEMSTONE) return 0; + if (objects[obj->otyp].oc_material != MINERAL + && objects[obj->otyp].oc_material != GEMSTONE) + return 0; /* Heart of Ahriman usually resists; ordinary items rarely do */ - if (obj_resists(obj, 2, 98)) return 0; + if (obj_resists(obj, 2, 98)) + return 0; (void) get_obj_location(obj, &oox, &ooy, 0); /* add more if stone objects are added.. */ switch (objects[obj->otyp].oc_class) { - case ROCK_CLASS: /* boulders and statues */ - case TOOL_CLASS: /* figurines */ - if (obj->otyp == BOULDER) { - obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT); - smell = TRUE; - } else if (obj->otyp == STATUE || obj->otyp == FIGURINE) { - ptr = &mons[obj->corpsenm]; - if (is_golem(ptr)) { - golem_xform = (ptr != &mons[PM_FLESH_GOLEM]); - } else if (vegetarian(ptr)) { - /* Don't animate monsters that aren't flesh */ - obj = poly_obj(obj, MEATBALL); - smell = TRUE; - break; - } - if (obj->otyp == STATUE) { - /* animate_statue() forces all golems to become flesh golems */ - mon = animate_statue(obj, oox, ooy, ANIMATE_SPELL, (int *)0); - } else { /* (obj->otyp == FIGURINE) */ - if (golem_xform) ptr = &mons[PM_FLESH_GOLEM]; - mon = makemon(ptr, oox, ooy, NO_MINVENT); - if (mon) { - if (costly_spot(oox, ooy) && !obj->no_charge) { - if (costly_spot(u.ux, u.uy)) - addtobill(obj, carried(obj), FALSE, FALSE); - else - stolen_value(obj, oox, ooy, TRUE, FALSE); - } - if (obj->timed) obj_stop_timers(obj); - if (carried(obj)) - useup(obj); - else - delobj(obj); - if (cansee(mon->mx, mon->my)) - pline_The("figurine %sanimates!", - golem_xform ? "turns to flesh and " : ""); - } - } - if (mon) { - ptr = mon->data; - /* this golem handling is redundant... */ - if (is_golem(ptr) && ptr != &mons[PM_FLESH_GOLEM]) - (void)newcham(mon, &mons[PM_FLESH_GOLEM], TRUE, FALSE); - } else if ((ptr->geno & (G_NOCORPSE|G_UNIQ)) != 0) { - /* didn't revive but can't leave corpse either */ - res = 0; - } else { - /* unlikely to get here since genociding monsters also - sets the G_NOCORPSE flag; drop statue's contents */ - while ((item = obj->cobj) != 0) { - bypass_obj(item); /* make stone-to-flesh miss it */ - obj_extract_self(item); - place_object(item, oox, ooy); - } - obj = poly_obj(obj, CORPSE); - } - } else { /* miscellaneous tool or unexpected rock... */ - res = 0; - } - break; + case ROCK_CLASS: /* boulders and statues */ + case TOOL_CLASS: /* figurines */ + if (obj->otyp == BOULDER) { + obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT); + smell = TRUE; + } else if (obj->otyp == STATUE || obj->otyp == FIGURINE) { + ptr = &mons[obj->corpsenm]; + if (is_golem(ptr)) { + golem_xform = (ptr != &mons[PM_FLESH_GOLEM]); + } else if (vegetarian(ptr)) { + /* Don't animate monsters that aren't flesh */ + obj = poly_obj(obj, MEATBALL); + smell = TRUE; + break; + } + if (obj->otyp == STATUE) { + /* animate_statue() forces all golems to become flesh golems + */ + mon = animate_statue(obj, oox, ooy, ANIMATE_SPELL, (int *) 0); + } else { /* (obj->otyp == FIGURINE) */ + if (golem_xform) + ptr = &mons[PM_FLESH_GOLEM]; + mon = makemon(ptr, oox, ooy, NO_MINVENT); + if (mon) { + if (costly_spot(oox, ooy) && !obj->no_charge) { + if (costly_spot(u.ux, u.uy)) + addtobill(obj, carried(obj), FALSE, FALSE); + else + stolen_value(obj, oox, ooy, TRUE, FALSE); + } + if (obj->timed) + obj_stop_timers(obj); + if (carried(obj)) + useup(obj); + else + delobj(obj); + if (cansee(mon->mx, mon->my)) + pline_The("figurine %sanimates!", + golem_xform ? "turns to flesh and " : ""); + } + } + if (mon) { + ptr = mon->data; + /* this golem handling is redundant... */ + if (is_golem(ptr) && ptr != &mons[PM_FLESH_GOLEM]) + (void) newcham(mon, &mons[PM_FLESH_GOLEM], TRUE, FALSE); + } else if ((ptr->geno & (G_NOCORPSE | G_UNIQ)) != 0) { + /* didn't revive but can't leave corpse either */ + res = 0; + } else { + /* unlikely to get here since genociding monsters also + sets the G_NOCORPSE flag; drop statue's contents */ + while ((item = obj->cobj) != 0) { + bypass_obj(item); /* make stone-to-flesh miss it */ + obj_extract_self(item); + place_object(item, oox, ooy); + } + obj = poly_obj(obj, CORPSE); + } + } else { /* miscellaneous tool or unexpected rock... */ + res = 0; + } + break; /* maybe add weird things to become? */ - case RING_CLASS: /* some of the rings are stone */ - obj = poly_obj(obj, MEAT_RING); - smell = TRUE; - break; - case WAND_CLASS: /* marble wand */ - obj = poly_obj(obj, MEAT_STICK); - smell = TRUE; - break; - case GEM_CLASS: /* stones & gems */ - obj = poly_obj(obj, MEATBALL); - smell = TRUE; - break; - case WEAPON_CLASS: /* crysknife */ - /* fall through */ + case RING_CLASS: /* some of the rings are stone */ + obj = poly_obj(obj, MEAT_RING); + smell = TRUE; + break; + case WAND_CLASS: /* marble wand */ + obj = poly_obj(obj, MEAT_STICK); + smell = TRUE; + break; + case GEM_CLASS: /* stones & gems */ + obj = poly_obj(obj, MEATBALL); + smell = TRUE; + break; + case WEAPON_CLASS: /* crysknife */ + /* fall through */ default: - res = 0; - break; + res = 0; + break; } if (smell) { - /* non-meat eaters smell meat, meat eaters smell its flavor; - monks are considered non-meat eaters regardless of behavior; - other roles are non-meat eaters if they haven't broken - vegetarian conduct yet (or if poly'd into non-carnivorous/ - non-omnivorous form, regardless of whether it's herbivorous, - non-eating, or something stranger) */ - if (Role_if(PM_MONK) || !u.uconduct.unvegetarian || - !carnivorous(youmonst.data)) - Norep("You smell the odor of meat."); - else - Norep("You smell a delicious smell."); + /* non-meat eaters smell meat, meat eaters smell its flavor; + monks are considered non-meat eaters regardless of behavior; + other roles are non-meat eaters if they haven't broken + vegetarian conduct yet (or if poly'd into non-carnivorous/ + non-omnivorous form, regardless of whether it's herbivorous, + non-eating, or something stranger) */ + if (Role_if(PM_MONK) || !u.uconduct.unvegetarian + || !carnivorous(youmonst.data)) + Norep("You smell the odor of meat."); + else + Norep("You smell a delicious smell."); } newsym(oox, ooy); return res; @@ -1668,264 +1700,270 @@ int bhito(obj, otmp) struct obj *obj, *otmp; { - int res = 1; /* affected object by default */ - boolean learn_it = FALSE, maybelearnit; + int res = 1; /* affected object by default */ + boolean learn_it = FALSE, maybelearnit; - /* fundamental: a wand effect hitting itself doesn't do anything; - otherwise we need to guard against accessing otmp after something - strange has happened to it (along the lines of polymorph or - stone-to-flesh [which aren't good examples since polymorph wands - aren't affected by polymorph zaps and stone-to-flesh isn't - available in wand form, but the concept still applies...]) */ - if (obj == otmp) return 0; + /* fundamental: a wand effect hitting itself doesn't do anything; + otherwise we need to guard against accessing otmp after something + strange has happened to it (along the lines of polymorph or + stone-to-flesh [which aren't good examples since polymorph wands + aren't affected by polymorph zaps and stone-to-flesh isn't + available in wand form, but the concept still applies...]) */ + if (obj == otmp) + return 0; - if (obj->bypass) { - /* The bypass bit is currently only used as follows: - * - * POLYMORPH - When a monster being polymorphed drops something - * from its inventory as a result of the change. - * If the items fall to the floor, they are not - * subject to direct subsequent polymorphing - * themselves on that same zap. This makes it - * consistent with items that remain in the - * monster's inventory. They are not polymorphed - * either. - * UNDEAD_TURNING - When an undead creature gets killed via - * undead turning, prevent its corpse from being - * immediately revived by the same effect. - * STONE_TO_FLESH - If a statue can't be revived, its - * contents get dropped before turning it into - * meat; prevent those contents from being hit. - * retouch_equipment() - bypass flag is used to track which - * items have been handled (bhito isn't involved). - * menu_drop(), askchain() - inventory traversal where multiple - * Drop can alter the invent chain while traversal - * is in progress (bhito isn't involved). - * - * The bypass bit on all objects is reset each turn, whenever - * context.bypasses is set. - * - * We check the obj->bypass bit above AND context.bypasses - * as a safeguard against any stray occurrence left in an obj - * struct someplace, although that should never happen. - */ - if (context.bypasses) { - return 0; - } else { - debugpline1("%s for a moment.", - Tobjnam(obj, "pulsate")); - obj->bypass = 0; - } - } + if (obj->bypass) { + /* The bypass bit is currently only used as follows: + * + * POLYMORPH - When a monster being polymorphed drops something + * from its inventory as a result of the change. + * If the items fall to the floor, they are not + * subject to direct subsequent polymorphing + * themselves on that same zap. This makes it + * consistent with items that remain in the + * monster's inventory. They are not polymorphed + * either. + * UNDEAD_TURNING - When an undead creature gets killed via + * undead turning, prevent its corpse from being + * immediately revived by the same effect. + * STONE_TO_FLESH - If a statue can't be revived, its + * contents get dropped before turning it into + * meat; prevent those contents from being hit. + * retouch_equipment() - bypass flag is used to track which + * items have been handled (bhito isn't involved). + * menu_drop(), askchain() - inventory traversal where multiple + * Drop can alter the invent chain while traversal + * is in progress (bhito isn't involved). + * + * The bypass bit on all objects is reset each turn, whenever + * context.bypasses is set. + * + * We check the obj->bypass bit above AND context.bypasses + * as a safeguard against any stray occurrence left in an obj + * struct someplace, although that should never happen. + */ + if (context.bypasses) { + return 0; + } else { + debugpline1("%s for a moment.", Tobjnam(obj, "pulsate")); + obj->bypass = 0; + } + } - /* - * Some parts of this function expect the object to be on the floor - * obj->{ox,oy} to be valid. The exception to this (so far) is - * for the STONE_TO_FLESH spell. - */ - if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH)) - impossible("bhito: obj is not floor or Stone To Flesh spell"); + /* + * Some parts of this function expect the object to be on the floor + * obj->{ox,oy} to be valid. The exception to this (so far) is + * for the STONE_TO_FLESH spell. + */ + if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH)) + impossible("bhito: obj is not floor or Stone To Flesh spell"); - if (obj == uball) { - res = 0; - } else if (obj == uchain) { - if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) { - learn_it = TRUE; - unpunish(); - } else - res = 0; - } else - switch(otmp->otyp) { - case WAN_POLYMORPH: - case SPE_POLYMORPH: - if (obj->otyp == WAN_POLYMORPH || - obj->otyp == SPE_POLYMORPH || - obj->otyp == POT_POLYMORPH || - obj_resists(obj, 5, 95)) { - res = 0; - break; - } - /* KMH, conduct */ - u.uconduct.polypiles++; - /* any saved lock context will be dangerously obsolete */ - if (Is_box(obj)) (void) boxlock(obj, otmp); + if (obj == uball) { + res = 0; + } else if (obj == uchain) { + if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) { + learn_it = TRUE; + unpunish(); + } else + res = 0; + } else + switch (otmp->otyp) { + case WAN_POLYMORPH: + case SPE_POLYMORPH: + if (obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH + || obj->otyp == POT_POLYMORPH || obj_resists(obj, 5, 95)) { + res = 0; + break; + } + /* KMH, conduct */ + u.uconduct.polypiles++; + /* any saved lock context will be dangerously obsolete */ + if (Is_box(obj)) + (void) boxlock(obj, otmp); - if (obj_shudders(obj)) { - boolean cover = ((obj == level.objects[u.ux][u.uy]) && - u.uundetected && - hides_under(youmonst.data)); + if (obj_shudders(obj)) { + boolean cover = + ((obj == level.objects[u.ux][u.uy]) && u.uundetected + && hides_under(youmonst.data)); - if (cansee(obj->ox, obj->oy)) learn_it = TRUE; - do_osshock(obj); - /* eek - your cover might have been blown */ - if (cover) (void) hideunder(&youmonst); - break; - } - obj = poly_obj(obj, STRANGE_OBJECT); - newsym(obj->ox,obj->oy); - break; - case WAN_PROBING: - res = !obj->dknown; - /* target object has now been "seen (up close)" */ - obj->dknown = 1; - if (Is_container(obj) || obj->otyp == STATUE) { - obj->cknown = obj->lknown = 1; - if (!obj->cobj) { - boolean catbox = SchroedingersBox(obj); + if (cansee(obj->ox, obj->oy)) + learn_it = TRUE; + do_osshock(obj); + /* eek - your cover might have been blown */ + if (cover) + (void) hideunder(&youmonst); + break; + } + obj = poly_obj(obj, STRANGE_OBJECT); + newsym(obj->ox, obj->oy); + break; + case WAN_PROBING: + res = !obj->dknown; + /* target object has now been "seen (up close)" */ + obj->dknown = 1; + if (Is_container(obj) || obj->otyp == STATUE) { + obj->cknown = obj->lknown = 1; + if (!obj->cobj) { + boolean catbox = SchroedingersBox(obj); - /* we don't want to force alive vs dead - determination for Schroedinger's Cat here, - so just make probing be inconclusive for it */ - if (catbox) obj->cknown = 0; - pline("%s empty.", - Tobjnam(obj, catbox ? "seem" : "are")); - } else { - struct obj *o; - /* view contents (not recursively) */ - for (o = obj->cobj; o; o = o->nobj) - o->dknown = 1; /* "seen", even if blind */ - (void) display_cinventory(obj); - } - res = 1; - } - if (res) learn_it = TRUE; - break; - case WAN_STRIKING: - case SPE_FORCE_BOLT: - /* learn the type if you see or hear something break - (the sound could be implicit) */ - maybelearnit = cansee(obj->ox, obj->oy) || !Deaf; - if (obj->otyp == BOULDER) { - if (cansee(obj->ox, obj->oy)) - pline_The("boulder falls apart."); - else - You_hear("a crumbling sound."); - fracture_rock(obj); - } - else if (obj->otyp == STATUE) { - if (break_statue(obj)) { - if (cansee(obj->ox, obj->oy)) { - if (Hallucination) - pline_The("%s shatters.", rndmonnam(NULL)); - else - pline_The("statue shatters."); - } else - You_hear("a crumbling sound."); - } - } else { - if (context.mon_moving ? - !breaks(obj, obj->ox, obj->oy) : - !hero_breaks(obj, obj->ox, obj->oy, FALSE)) - maybelearnit = FALSE; /* nothing broke */ - res = 0; - } - if (maybelearnit) learn_it = TRUE; - break; - case WAN_CANCELLATION: - case SPE_CANCELLATION: - cancel_item(obj); + /* we don't want to force alive vs dead + determination for Schroedinger's Cat here, + so just make probing be inconclusive for it */ + if (catbox) + obj->cknown = 0; + pline("%s empty.", Tobjnam(obj, catbox ? "seem" : "are")); + } else { + struct obj *o; + /* view contents (not recursively) */ + for (o = obj->cobj; o; o = o->nobj) + o->dknown = 1; /* "seen", even if blind */ + (void) display_cinventory(obj); + } + res = 1; + } + if (res) + learn_it = TRUE; + break; + case WAN_STRIKING: + case SPE_FORCE_BOLT: + /* learn the type if you see or hear something break + (the sound could be implicit) */ + maybelearnit = cansee(obj->ox, obj->oy) || !Deaf; + if (obj->otyp == BOULDER) { + if (cansee(obj->ox, obj->oy)) + pline_The("boulder falls apart."); + else + You_hear("a crumbling sound."); + fracture_rock(obj); + } else if (obj->otyp == STATUE) { + if (break_statue(obj)) { + if (cansee(obj->ox, obj->oy)) { + if (Hallucination) + pline_The("%s shatters.", rndmonnam(NULL)); + else + pline_The("statue shatters."); + } else + You_hear("a crumbling sound."); + } + } else { + if (context.mon_moving + ? !breaks(obj, obj->ox, obj->oy) + : !hero_breaks(obj, obj->ox, obj->oy, FALSE)) + maybelearnit = FALSE; /* nothing broke */ + res = 0; + } + if (maybelearnit) + learn_it = TRUE; + break; + case WAN_CANCELLATION: + case SPE_CANCELLATION: + cancel_item(obj); #ifdef TEXTCOLOR - newsym(obj->ox,obj->oy); /* might change color */ + newsym(obj->ox, obj->oy); /* might change color */ #endif - break; - case SPE_DRAIN_LIFE: - (void) drain_item(obj); - break; - case WAN_TELEPORTATION: - case SPE_TELEPORT_AWAY: - (void) rloco(obj); - break; - case WAN_MAKE_INVISIBLE: - break; - case WAN_UNDEAD_TURNING: - case SPE_TURN_UNDEAD: - if (obj->otyp == EGG) { - revive_egg(obj); - } else if (obj->otyp == CORPSE) { - int corpsenm = corpse_revive_type(obj); + break; + case SPE_DRAIN_LIFE: + (void) drain_item(obj); + break; + case WAN_TELEPORTATION: + case SPE_TELEPORT_AWAY: + (void) rloco(obj); + break; + case WAN_MAKE_INVISIBLE: + break; + case WAN_UNDEAD_TURNING: + case SPE_TURN_UNDEAD: + if (obj->otyp == EGG) { + revive_egg(obj); + } else if (obj->otyp == CORPSE) { + int corpsenm = corpse_revive_type(obj); - res = !!revive(obj, TRUE); - if (res && Role_if(PM_HEALER)) { - if (Hallucination && !Deaf) { - You_hear("the sound of a defibrillator."); - learn_it = TRUE; - } else if (!Blind) { - You("observe %s %s change dramatically.", - s_suffix(an(mons[corpsenm].mname)), - nonliving(&mons[corpsenm]) ? - "motility" : "health"); - learn_it = TRUE; - } - if (learn_it) exercise(A_WIS, TRUE); - } - } - break; - case WAN_OPENING: - case SPE_KNOCK: - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - if(Is_box(obj)) - res = boxlock(obj, otmp); - else - res = 0; - if (res) learn_it = TRUE; - break; - case WAN_SLOW_MONSTER: /* no effect on objects */ - case SPE_SLOW_MONSTER: - case WAN_SPEED_MONSTER: - case WAN_NOTHING: - case SPE_HEALING: - case SPE_EXTRA_HEALING: - res = 0; - break; - case SPE_STONE_TO_FLESH: - res = stone_to_flesh_obj(obj); - break; - default: - impossible("What an interesting effect (%d)", otmp->otyp); - break; - } - /* if effect was observable then discover the wand type provided - that the wand itself has been seen */ - if (learn_it) learnwand(otmp); - return res; + res = !!revive(obj, TRUE); + if (res && Role_if(PM_HEALER)) { + if (Hallucination && !Deaf) { + You_hear("the sound of a defibrillator."); + learn_it = TRUE; + } else if (!Blind) { + You("observe %s %s change dramatically.", + s_suffix(an(mons[corpsenm].mname)), + nonliving(&mons[corpsenm]) ? "motility" + : "health"); + learn_it = TRUE; + } + if (learn_it) + exercise(A_WIS, TRUE); + } + } + break; + case WAN_OPENING: + case SPE_KNOCK: + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + if (Is_box(obj)) + res = boxlock(obj, otmp); + else + res = 0; + if (res) + learn_it = TRUE; + break; + case WAN_SLOW_MONSTER: /* no effect on objects */ + case SPE_SLOW_MONSTER: + case WAN_SPEED_MONSTER: + case WAN_NOTHING: + case SPE_HEALING: + case SPE_EXTRA_HEALING: + res = 0; + break; + case SPE_STONE_TO_FLESH: + res = stone_to_flesh_obj(obj); + break; + default: + impossible("What an interesting effect (%d)", otmp->otyp); + break; + } + /* if effect was observable then discover the wand type provided + that the wand itself has been seen */ + if (learn_it) + learnwand(otmp); + return res; } /* returns nonzero if something was hit */ int bhitpile(obj, fhito, tx, ty, zz) - struct obj *obj; - int FDECL((*fhito), (OBJ_P,OBJ_P)); - int tx, ty; - schar zz; +struct obj *obj; +int FDECL((*fhito), (OBJ_P, OBJ_P)); +int tx, ty; +schar zz; { int hitanything = 0; register struct obj *otmp, *next_obj; if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) { - struct trap *t = t_at(tx, ty); + struct trap *t = t_at(tx, ty); - /* We can't settle for the default calling sequence of - bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy) - because that last call might end up operating on our `next_obj' - (below), rather than on the current object, if it happens to - encounter a statue which mustn't become animated. */ - if (t && t->ttyp == STATUE_TRAP && - activate_statue_trap(t, tx, ty, TRUE)) - learnwand(obj); + /* We can't settle for the default calling sequence of + bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy) + because that last call might end up operating on our `next_obj' + (below), rather than on the current object, if it happens to + encounter a statue which mustn't become animated. */ + if (t && t->ttyp == STATUE_TRAP + && activate_statue_trap(t, tx, ty, TRUE)) + learnwand(obj); } poly_zapped = -1; - for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) { - next_obj = otmp->nexthere; - /* for zap downwards, don't hit object poly'd hero is hiding under */ - if (zz > 0 && u.uundetected && otmp == level.objects[u.ux][u.uy] - && hides_under(youmonst.data)) continue; + for (otmp = level.objects[tx][ty]; otmp; otmp = next_obj) { + next_obj = otmp->nexthere; + /* for zap downwards, don't hit object poly'd hero is hiding under */ + if (zz > 0 && u.uundetected && otmp == level.objects[u.ux][u.uy] + && hides_under(youmonst.data)) + continue; - hitanything += (*fhito)(otmp, obj); + hitanything += (*fhito)(otmp, obj); } - if(poly_zapped >= 0) - create_polymon(level.objects[tx][ty], poly_zapped); + if (poly_zapped >= 0) + create_polymon(level.objects[tx][ty], poly_zapped); return hitanything; } @@ -1939,12 +1977,12 @@ int zappable(wand) register struct obj *wand; { - if(wand->spe < 0 || (wand->spe == 0 && rn2(121))) - return 0; - if(wand->spe == 0) - You("wrest one last charge from the worn-out wand."); - wand->spe--; - return 1; + if (wand->spe < 0 || (wand->spe == 0 && rn2(121))) + return 0; + if (wand->spe == 0) + You("wrest one last charge from the worn-out wand."); + wand->spe--; + return 1; } /* @@ -1955,60 +1993,64 @@ void zapnodir(obj) register struct obj *obj; { - boolean known = FALSE; + boolean known = FALSE; - switch(obj->otyp) { - case WAN_LIGHT: - case SPE_LIGHT: - litroom(TRUE,obj); - if (!Blind) known = TRUE; - if (lightdamage(obj, TRUE, 5)) known = TRUE; - break; - case WAN_SECRET_DOOR_DETECTION: - case SPE_DETECT_UNSEEN: - if(!findit()) return; - if (!Blind) known = TRUE; - break; - case WAN_CREATE_MONSTER: - known = create_critters(rn2(23) ? 1 : rn1(7,2), - (struct permonst *)0, FALSE); - break; - case WAN_WISHING: - known = TRUE; - if(Luck + rn2(5) < 0) { - pline("Unfortunately, nothing happens."); - break; - } - makewish(); - break; - case WAN_ENLIGHTENMENT: - known = TRUE; - You_feel("self-knowledgeable..."); - display_nhwindow(WIN_MESSAGE, FALSE); - enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); - pline_The("feeling subsides."); - exercise(A_WIS, TRUE); - break; - } - if (known) { - if (!objects[obj->otyp].oc_name_known) - more_experienced(0,10); - /* effect was observable; discover the wand type provided - that the wand itself has been seen */ - learnwand(obj); - } + switch (obj->otyp) { + case WAN_LIGHT: + case SPE_LIGHT: + litroom(TRUE, obj); + if (!Blind) + known = TRUE; + if (lightdamage(obj, TRUE, 5)) + known = TRUE; + break; + case WAN_SECRET_DOOR_DETECTION: + case SPE_DETECT_UNSEEN: + if (!findit()) + return; + if (!Blind) + known = TRUE; + break; + case WAN_CREATE_MONSTER: + known = create_critters(rn2(23) ? 1 : rn1(7, 2), + (struct permonst *) 0, FALSE); + break; + case WAN_WISHING: + known = TRUE; + if (Luck + rn2(5) < 0) { + pline("Unfortunately, nothing happens."); + break; + } + makewish(); + break; + case WAN_ENLIGHTENMENT: + known = TRUE; + You_feel("self-knowledgeable..."); + display_nhwindow(WIN_MESSAGE, FALSE); + enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); + pline_The("feeling subsides."); + exercise(A_WIS, TRUE); + break; + } + if (known) { + if (!objects[obj->otyp].oc_name_known) + more_experienced(0, 10); + /* effect was observable; discover the wand type provided + that the wand itself has been seen */ + learnwand(obj); + } } STATIC_OVL void backfire(otmp) struct obj *otmp; { - int dmg; - otmp->in_use = TRUE; /* in case losehp() is fatal */ - pline("%s suddenly explodes!", The(xname(otmp))); - dmg = d(otmp->spe+2,6); - losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN); - useup(otmp); + int dmg; + otmp->in_use = TRUE; /* in case losehp() is fatal */ + pline("%s suddenly explodes!", The(xname(otmp))); + dmg = d(otmp->spe + 2, 6); + losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN); + useup(otmp); } static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 }; @@ -2016,50 +2058,53 @@ static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 }; int dozap() { - register struct obj *obj; - int damage; + register struct obj *obj; + int damage; - if(check_capacity((char *)0)) return(0); - obj = getobj(zap_syms, "zap"); - if(!obj) return(0); + if (check_capacity((char *) 0)) + return (0); + obj = getobj(zap_syms, "zap"); + if (!obj) + return (0); - check_unpaid(obj); + check_unpaid(obj); - /* zappable addition done by GAN 11/03/86 */ - if(!zappable(obj)) pline1(nothing_happens); - else if(obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { - backfire(obj); /* the wand blows up in your face! */ - exercise(A_STR, FALSE); - return(1); - } else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *)0)) { - if (!Blind) - pline("%s glows and fades.", The(xname(obj))); - /* make him pay for knowing !NODIR */ - } else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) { - if ((damage = zapyourself(obj, TRUE)) != 0) { - char buf[BUFSZ]; - Sprintf(buf, "zapped %sself with a wand", uhim()); - losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); - } - } else { - - /* Are we having fun yet? - * weffects -> buzz(obj->otyp) -> zhitm (temple priest) -> - * attack -> hitum -> known_hitum -> ghod_hitsu -> - * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) -> - * useup -> obfree -> dealloc_obj -> free(obj) - */ - current_wand = obj; - weffects(obj); - obj = current_wand; - current_wand = 0; - } - if (obj && obj->spe < 0) { - pline("%s to dust.", Tobjnam(obj, "turn")); - useup(obj); - } - update_inventory(); /* maybe used a charge */ - return(1); + /* zappable addition done by GAN 11/03/86 */ + if (!zappable(obj)) + pline1(nothing_happens); + else if (obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { + backfire(obj); /* the wand blows up in your face! */ + exercise(A_STR, FALSE); + return (1); + } else if (!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *) 0)) { + if (!Blind) + pline("%s glows and fades.", The(xname(obj))); + /* make him pay for knowing !NODIR */ + } else if (!u.dx && !u.dy && !u.dz + && !(objects[obj->otyp].oc_dir == NODIR)) { + if ((damage = zapyourself(obj, TRUE)) != 0) { + char buf[BUFSZ]; + Sprintf(buf, "zapped %sself with a wand", uhim()); + losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); + } + } else { + /* Are we having fun yet? + * weffects -> buzz(obj->otyp) -> zhitm (temple priest) -> + * attack -> hitum -> known_hitum -> ghod_hitsu -> + * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) -> + * useup -> obfree -> dealloc_obj -> free(obj) + */ + current_wand = obj; + weffects(obj); + obj = current_wand; + current_wand = 0; + } + if (obj && obj->spe < 0) { + pline("%s to dust.", Tobjnam(obj, "turn")); + useup(obj); + } + update_inventory(); /* maybe used a charge */ + return (1); } int @@ -2067,304 +2112,305 @@ zapyourself(obj, ordinary) struct obj *obj; boolean ordinary; { - boolean learn_it = FALSE; - int damage = 0; + boolean learn_it = FALSE; + int damage = 0; - switch(obj->otyp) { - case WAN_STRIKING: - case SPE_FORCE_BOLT: - learn_it = TRUE; - if(Antimagic) { - shieldeff(u.ux, u.uy); - pline("Boing!"); - } else { - if (ordinary) { - You("bash yourself!"); - damage = d(2,12); - } else - damage = d(1 + obj->spe,6); - exercise(A_STR, FALSE); - } - break; + switch (obj->otyp) { + case WAN_STRIKING: + case SPE_FORCE_BOLT: + learn_it = TRUE; + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline("Boing!"); + } else { + if (ordinary) { + You("bash yourself!"); + damage = d(2, 12); + } else + damage = d(1 + obj->spe, 6); + exercise(A_STR, FALSE); + } + break; - case WAN_LIGHTNING: - learn_it = TRUE; - if (!Shock_resistance) { - You("shock yourself!"); - damage = d(12,6); - exercise(A_CON, FALSE); - } else { - shieldeff(u.ux, u.uy); - You("zap yourself, but seem unharmed."); - ugolemeffects(AD_ELEC, d(12,6)); - } - destroy_item(WAND_CLASS, AD_ELEC); - destroy_item(RING_CLASS, AD_ELEC); - (void) flashburn((long)rnd(100)); - break; + case WAN_LIGHTNING: + learn_it = TRUE; + if (!Shock_resistance) { + You("shock yourself!"); + damage = d(12, 6); + exercise(A_CON, FALSE); + } else { + shieldeff(u.ux, u.uy); + You("zap yourself, but seem unharmed."); + ugolemeffects(AD_ELEC, d(12, 6)); + } + destroy_item(WAND_CLASS, AD_ELEC); + destroy_item(RING_CLASS, AD_ELEC); + (void) flashburn((long) rnd(100)); + break; - case SPE_FIREBALL: - You("explode a fireball on top of yourself!"); - explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS, EXPL_FIERY); - break; - case WAN_FIRE: - case FIRE_HORN: - learn_it = TRUE; - if (Fire_resistance) { - shieldeff(u.ux, u.uy); - You_feel("rather warm."); - ugolemeffects(AD_FIRE, d(12,6)); - } else { - pline("You've set yourself afire!"); - damage = d(12,6); - } - burn_away_slime(); - (void) burnarmor(&youmonst); - destroy_item(SCROLL_CLASS, AD_FIRE); - destroy_item(POTION_CLASS, AD_FIRE); - destroy_item(SPBOOK_CLASS, AD_FIRE); - destroy_item(FOOD_CLASS, AD_FIRE); /* only slime for now */ - break; + case SPE_FIREBALL: + You("explode a fireball on top of yourself!"); + explode(u.ux, u.uy, 11, d(6, 6), WAND_CLASS, EXPL_FIERY); + break; + case WAN_FIRE: + case FIRE_HORN: + learn_it = TRUE; + if (Fire_resistance) { + shieldeff(u.ux, u.uy); + You_feel("rather warm."); + ugolemeffects(AD_FIRE, d(12, 6)); + } else { + pline("You've set yourself afire!"); + damage = d(12, 6); + } + burn_away_slime(); + (void) burnarmor(&youmonst); + destroy_item(SCROLL_CLASS, AD_FIRE); + destroy_item(POTION_CLASS, AD_FIRE); + destroy_item(SPBOOK_CLASS, AD_FIRE); + destroy_item(FOOD_CLASS, AD_FIRE); /* only slime for now */ + break; - case WAN_COLD: - case SPE_CONE_OF_COLD: - case FROST_HORN: - learn_it = TRUE; - if (Cold_resistance) { - shieldeff(u.ux, u.uy); - You_feel("a little chill."); - ugolemeffects(AD_COLD, d(12,6)); - } else { - You("imitate a popsicle!"); - damage = d(12,6); - } - destroy_item(POTION_CLASS, AD_COLD); - break; + case WAN_COLD: + case SPE_CONE_OF_COLD: + case FROST_HORN: + learn_it = TRUE; + if (Cold_resistance) { + shieldeff(u.ux, u.uy); + You_feel("a little chill."); + ugolemeffects(AD_COLD, d(12, 6)); + } else { + You("imitate a popsicle!"); + damage = d(12, 6); + } + destroy_item(POTION_CLASS, AD_COLD); + break; - case WAN_MAGIC_MISSILE: - case SPE_MAGIC_MISSILE: - learn_it = TRUE; - if(Antimagic) { - shieldeff(u.ux, u.uy); - pline_The("missiles bounce!"); - } else { - damage = d(4,6); - pline("Idiot! You've shot yourself!"); - } - break; + case WAN_MAGIC_MISSILE: + case SPE_MAGIC_MISSILE: + learn_it = TRUE; + if (Antimagic) { + shieldeff(u.ux, u.uy); + pline_The("missiles bounce!"); + } else { + damage = d(4, 6); + pline("Idiot! You've shot yourself!"); + } + break; - case WAN_POLYMORPH: - case SPE_POLYMORPH: - if (!Unchanging) { - learn_it = TRUE; - polyself(0); - } - break; + case WAN_POLYMORPH: + case SPE_POLYMORPH: + if (!Unchanging) { + learn_it = TRUE; + polyself(0); + } + break; - case WAN_CANCELLATION: - case SPE_CANCELLATION: - (void) cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE); - break; + case WAN_CANCELLATION: + case SPE_CANCELLATION: + (void) cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE); + break; - case SPE_DRAIN_LIFE: - if (!Drain_resistance) { - learn_it = TRUE; /* (no effect for spells...) */ - losexp("life drainage"); - } - damage = 0; /* No additional damage */ - break; + case SPE_DRAIN_LIFE: + if (!Drain_resistance) { + learn_it = TRUE; /* (no effect for spells...) */ + losexp("life drainage"); + } + damage = 0; /* No additional damage */ + break; - case WAN_MAKE_INVISIBLE: { - /* have to test before changing HInvis but must change - * HInvis before doing newsym(). - */ - int msg = !Invis && !Blind && !BInvis; + case WAN_MAKE_INVISIBLE: { + /* have to test before changing HInvis but must change + * HInvis before doing newsym(). + */ + int msg = !Invis && !Blind && !BInvis; - if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { - /* A mummy wrapping absorbs it and protects you */ - You_feel("rather itchy under %s.", yname(uarmc)); - break; - } - if (ordinary || !rn2(10)) { /* permanent */ - HInvis |= FROMOUTSIDE; - } else { /* temporary */ - incr_itimeout(&HInvis, d(obj->spe, 250)); - } - if (msg) { - learn_it = TRUE; - newsym(u.ux, u.uy); - self_invis_message(); - } - break; - } + if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { + /* A mummy wrapping absorbs it and protects you */ + You_feel("rather itchy under %s.", yname(uarmc)); + break; + } + if (ordinary || !rn2(10)) { /* permanent */ + HInvis |= FROMOUTSIDE; + } else { /* temporary */ + incr_itimeout(&HInvis, d(obj->spe, 250)); + } + if (msg) { + learn_it = TRUE; + newsym(u.ux, u.uy); + self_invis_message(); + } + break; + } - case WAN_SPEED_MONSTER: - if (!(HFast & INTRINSIC)) { - learn_it = TRUE; - if (!Fast) - You("speed up."); - else - Your("quickness feels more natural."); - exercise(A_DEX, TRUE); - } - HFast |= FROMOUTSIDE; - break; + case WAN_SPEED_MONSTER: + if (!(HFast & INTRINSIC)) { + learn_it = TRUE; + if (!Fast) + You("speed up."); + else + Your("quickness feels more natural."); + exercise(A_DEX, TRUE); + } + HFast |= FROMOUTSIDE; + break; - case WAN_SLEEP: - case SPE_SLEEP: - learn_it = TRUE; - if(Sleep_resistance) { - shieldeff(u.ux, u.uy); - You("don't feel sleepy!"); - } else { - pline_The("sleep ray hits you!"); - fall_asleep(-rnd(50), TRUE); - } - break; + case WAN_SLEEP: + case SPE_SLEEP: + learn_it = TRUE; + if (Sleep_resistance) { + shieldeff(u.ux, u.uy); + You("don't feel sleepy!"); + } else { + pline_The("sleep ray hits you!"); + fall_asleep(-rnd(50), TRUE); + } + break; - case WAN_SLOW_MONSTER: - case SPE_SLOW_MONSTER: - if(HFast & (TIMEOUT | INTRINSIC)) { - learn_it = TRUE; - u_slow_down(); - } - break; + case WAN_SLOW_MONSTER: + case SPE_SLOW_MONSTER: + if (HFast & (TIMEOUT | INTRINSIC)) { + learn_it = TRUE; + u_slow_down(); + } + break; - case WAN_TELEPORTATION: - case SPE_TELEPORT_AWAY: - tele(); - /* same criteria as when mounted (zap_steed) */ - if ((Teleport_control && !Stunned) || - !couldsee(u.ux0, u.uy0) || - distu(u.ux0, u.uy0) >= 16) - learn_it = TRUE; - break; + case WAN_TELEPORTATION: + case SPE_TELEPORT_AWAY: + tele(); + /* same criteria as when mounted (zap_steed) */ + if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0) + || distu(u.ux0, u.uy0) >= 16) + learn_it = TRUE; + break; - case WAN_DEATH: - case SPE_FINGER_OF_DEATH: - if (nonliving(youmonst.data) || is_demon(youmonst.data)) { - pline((obj->otyp == WAN_DEATH) ? - "The wand shoots an apparently harmless beam at you." - : "You seem no deader than before."); - break; - } - learn_it = TRUE; - Sprintf(killer.name,"shot %sself with a death ray",uhim()); - killer.format = NO_KILLER_PREFIX; - You("irradiate yourself with pure energy!"); - You("die."); - /* They might survive with an amulet of life saving */ - done(DIED); - break; - case WAN_UNDEAD_TURNING: - case SPE_TURN_UNDEAD: - learn_it = TRUE; - (void) unturn_dead(&youmonst); - if (is_undead(youmonst.data)) { - You_feel("frightened and %sstunned.", - Stunned ? "even more " : ""); - make_stunned((HStun & TIMEOUT) + (long)rnd(30), FALSE); - } else - You("shudder in dread."); - break; - case SPE_HEALING: - case SPE_EXTRA_HEALING: - learn_it = TRUE; /* (no effect for spells...) */ - healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4), - 0, FALSE, (obj->otyp == SPE_EXTRA_HEALING)); - You_feel("%sbetter.", - obj->otyp == SPE_EXTRA_HEALING ? "much " : ""); - break; - case WAN_LIGHT: /* (broken wand) */ - /* assert( !ordinary ); */ - damage = d(obj->spe, 25); - case EXPENSIVE_CAMERA: - if (!damage) damage = 5; - damage = lightdamage(obj, ordinary, damage); - damage += rnd(25); - if (flashburn((long)damage)) learn_it = TRUE; - damage = 0; /* reset */ - break; - case WAN_OPENING: - case SPE_KNOCK: - if (Punished) { - learn_it = TRUE; - unpunish(); - } - if (u.utrap) { /* escape web or bear trap */ - (void) openholdingtrap(&youmonst, &learn_it); - } else { /* trigger previously escaped trapdoor */ - (void) openfallingtrap(&youmonst, TRUE, &learn_it); - } - break; - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - if (!u.utrap) { - (void) closeholdingtrap(&youmonst, &learn_it); - } - break; - case WAN_DIGGING: - case SPE_DIG: - case SPE_DETECT_UNSEEN: - case WAN_NOTHING: - break; - case WAN_PROBING: - { - struct obj *otmp; + case WAN_DEATH: + case SPE_FINGER_OF_DEATH: + if (nonliving(youmonst.data) || is_demon(youmonst.data)) { + pline((obj->otyp == WAN_DEATH) + ? "The wand shoots an apparently harmless beam at you." + : "You seem no deader than before."); + break; + } + learn_it = TRUE; + Sprintf(killer.name, "shot %sself with a death ray", uhim()); + killer.format = NO_KILLER_PREFIX; + You("irradiate yourself with pure energy!"); + You("die."); + /* They might survive with an amulet of life saving */ + done(DIED); + break; + case WAN_UNDEAD_TURNING: + case SPE_TURN_UNDEAD: + learn_it = TRUE; + (void) unturn_dead(&youmonst); + if (is_undead(youmonst.data)) { + You_feel("frightened and %sstunned.", + Stunned ? "even more " : ""); + make_stunned((HStun & TIMEOUT) + (long) rnd(30), FALSE); + } else + You("shudder in dread."); + break; + case SPE_HEALING: + case SPE_EXTRA_HEALING: + learn_it = TRUE; /* (no effect for spells...) */ + healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4), 0, FALSE, + (obj->otyp == SPE_EXTRA_HEALING)); + You_feel("%sbetter.", obj->otyp == SPE_EXTRA_HEALING ? "much " : ""); + break; + case WAN_LIGHT: /* (broken wand) */ + /* assert( !ordinary ); */ + damage = d(obj->spe, 25); + case EXPENSIVE_CAMERA: + if (!damage) + damage = 5; + damage = lightdamage(obj, ordinary, damage); + damage += rnd(25); + if (flashburn((long) damage)) + learn_it = TRUE; + damage = 0; /* reset */ + break; + case WAN_OPENING: + case SPE_KNOCK: + if (Punished) { + learn_it = TRUE; + unpunish(); + } + if (u.utrap) { /* escape web or bear trap */ + (void) openholdingtrap(&youmonst, &learn_it); + } else { /* trigger previously escaped trapdoor */ + (void) openfallingtrap(&youmonst, TRUE, &learn_it); + } + break; + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + if (!u.utrap) { + (void) closeholdingtrap(&youmonst, &learn_it); + } + break; + case WAN_DIGGING: + case SPE_DIG: + case SPE_DETECT_UNSEEN: + case WAN_NOTHING: + break; + case WAN_PROBING: { + struct obj *otmp; - for (otmp = invent; otmp; otmp = otmp->nobj) { - otmp->dknown = 1; - if (Is_container(otmp) || otmp->otyp == STATUE) { - otmp->lknown = 1; - if (!SchroedingersBox(otmp)) otmp->cknown = 1; - } - } - learn_it = TRUE; - ustatusline(); - break; - } - case SPE_STONE_TO_FLESH: - { - struct obj *otmp, *onxt; - boolean didmerge; + for (otmp = invent; otmp; otmp = otmp->nobj) { + otmp->dknown = 1; + if (Is_container(otmp) || otmp->otyp == STATUE) { + otmp->lknown = 1; + if (!SchroedingersBox(otmp)) + otmp->cknown = 1; + } + } + learn_it = TRUE; + ustatusline(); + break; + } + case SPE_STONE_TO_FLESH: { + struct obj *otmp, *onxt; + boolean didmerge; - if (u.umonnum == PM_STONE_GOLEM) { - learn_it = TRUE; - (void) polymon(PM_FLESH_GOLEM); - } - if (Stoned) { - learn_it = TRUE; - fix_petrification(); /* saved! */ - } - /* but at a cost.. */ - for (otmp = invent; otmp; otmp = onxt) { - onxt = otmp->nobj; - if (bhito(otmp, obj)) learn_it = TRUE; - } - /* - * It is possible that we can now merge some inventory. - * Do a higly paranoid merge. Restart from the beginning - * until no merges. - */ - do { - didmerge = FALSE; - for (otmp = invent; !didmerge && otmp; otmp = otmp->nobj) - for (onxt = otmp->nobj; onxt; onxt = onxt->nobj) - if (merged(&otmp, &onxt)) { - didmerge = TRUE; - break; - } - } while (didmerge); - break; - } - default: - impossible("zapyourself: object %d used?", obj->otyp); - break; - } - /* if effect was observable then discover the wand type provided - that the wand itself has been seen */ - if (learn_it) learnwand(obj); - return(damage); + if (u.umonnum == PM_STONE_GOLEM) { + learn_it = TRUE; + (void) polymon(PM_FLESH_GOLEM); + } + if (Stoned) { + learn_it = TRUE; + fix_petrification(); /* saved! */ + } + /* but at a cost.. */ + for (otmp = invent; otmp; otmp = onxt) { + onxt = otmp->nobj; + if (bhito(otmp, obj)) + learn_it = TRUE; + } + /* + * It is possible that we can now merge some inventory. + * Do a higly paranoid merge. Restart from the beginning + * until no merges. + */ + do { + didmerge = FALSE; + for (otmp = invent; !didmerge && otmp; otmp = otmp->nobj) + for (onxt = otmp->nobj; onxt; onxt = onxt->nobj) + if (merged(&otmp, &onxt)) { + didmerge = TRUE; + break; + } + } while (didmerge); + break; + } + default: + impossible("zapyourself: object %d used?", obj->otyp); + break; + } + /* if effect was observable then discover the wand type provided + that the wand itself has been seen */ + if (learn_it) + learnwand(obj); + return (damage); } /* called when poly'd hero uses breath attack against self */ @@ -2372,39 +2418,42 @@ void ubreatheu(mattk) struct attack *mattk; { - int dtyp = 20 + mattk->adtyp - 1; /* breath by hero */ - const char *fltxt = flash_types[dtyp]; /* blast of */ + int dtyp = 20 + mattk->adtyp - 1; /* breath by hero */ + const char *fltxt = flash_types[dtyp]; /* blast of */ - zhitu(dtyp, mattk->damn, fltxt, u.ux, u.uy); + zhitu(dtyp, mattk->damn, fltxt, u.ux, u.uy); } /* light damages hero in gremlin form */ int lightdamage(obj, ordinary, amt) -struct obj *obj; /* item making light (fake book if spell) */ -boolean ordinary; /* wand/camera zap vs wand destruction */ -int amt; /* pseudo-damage used to determine blindness duration */ +struct obj *obj; /* item making light (fake book if spell) */ +boolean ordinary; /* wand/camera zap vs wand destruction */ +int amt; /* pseudo-damage used to determine blindness duration */ { char buf[BUFSZ]; const char *how; int dmg = amt; if (dmg && youmonst.data == &mons[PM_GREMLIN]) { - /* reduce high values (from destruction of wand with many charges) */ - dmg = rnd(dmg); - if (dmg > 10) dmg = 10 + rnd(dmg - 10); - if (dmg > 20) dmg = 20; - pline("Ow, that light hurts%c", (dmg > 2 || u.mh <= 5) ? '!' : '.'); - /* [composing killer/reason is superfluous here; if fatal, cause - of death will always be "killed while stuck in creature form"] */ - if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) - ordinary = FALSE; /* say blasted rather than zapped */ - how = (obj->oclass != SPBOOK_CLASS) ? - (const char *)ansimpleoname(obj) : "spell of light"; - Sprintf(buf, "%s %sself with %s", - ordinary ? "zapped" : "blasted", uhim(), how); - /* might rehumanize(); could be fatal, but only for Unchanging */ - losehp(Maybe_Half_Phys(dmg), buf, NO_KILLER_PREFIX); + /* reduce high values (from destruction of wand with many charges) */ + dmg = rnd(dmg); + if (dmg > 10) + dmg = 10 + rnd(dmg - 10); + if (dmg > 20) + dmg = 20; + pline("Ow, that light hurts%c", (dmg > 2 || u.mh <= 5) ? '!' : '.'); + /* [composing killer/reason is superfluous here; if fatal, cause + of death will always be "killed while stuck in creature form"] */ + if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) + ordinary = FALSE; /* say blasted rather than zapped */ + how = (obj->oclass != SPBOOK_CLASS) + ? (const char *) ansimpleoname(obj) + : "spell of light"; + Sprintf(buf, "%s %sself with %s", ordinary ? "zapped" : "blasted", + uhim(), how); + /* might rehumanize(); could be fatal, but only for Unchanging */ + losehp(Maybe_Half_Phys(dmg), buf, NO_KILLER_PREFIX); } return dmg; } @@ -2414,13 +2463,14 @@ boolean flashburn(duration) long duration; { - if (!resists_blnd(&youmonst)) { - You(are_blinded_by_the_flash); - make_blinded(duration, FALSE); - if (!Blind) Your1(vision_clears); - return TRUE; - } - return FALSE; + if (!resists_blnd(&youmonst)) { + You(are_blinded_by_the_flash); + make_blinded(duration, FALSE); + if (!Blind) + Your1(vision_clears); + return TRUE; + } + return FALSE; } /* you've zapped a wand downwards while riding @@ -2429,60 +2479,58 @@ long duration; */ STATIC_OVL boolean zap_steed(obj) -struct obj *obj; /* wand or spell */ +struct obj *obj; /* wand or spell */ { - int steedhit = FALSE; - - switch (obj->otyp) { + int steedhit = FALSE; - /* - * Wands that are allowed to hit the steed - * Carefully test the results of any that are - * moved here from the bottom section. - */ - case WAN_PROBING: - probe_monster(u.usteed); - learnwand(obj); - steedhit = TRUE; - break; - case WAN_TELEPORTATION: - case SPE_TELEPORT_AWAY: - /* you go together */ - tele(); - /* same criteria as when unmounted (zapyourself) */ - if ((Teleport_control && !Stunned) || - !couldsee(u.ux0, u.uy0) || - distu(u.ux0, u.uy0) >= 16) - learnwand(obj); - steedhit = TRUE; - break; + switch (obj->otyp) { + /* + * Wands that are allowed to hit the steed + * Carefully test the results of any that are + * moved here from the bottom section. + */ + case WAN_PROBING: + probe_monster(u.usteed); + learnwand(obj); + steedhit = TRUE; + break; + case WAN_TELEPORTATION: + case SPE_TELEPORT_AWAY: + /* you go together */ + tele(); + /* same criteria as when unmounted (zapyourself) */ + if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0) + || distu(u.ux0, u.uy0) >= 16) + learnwand(obj); + steedhit = TRUE; + break; - /* Default processing via bhitm() for these */ - case SPE_CURE_SICKNESS: - case WAN_MAKE_INVISIBLE: - case WAN_CANCELLATION: - case SPE_CANCELLATION: - case WAN_POLYMORPH: - case SPE_POLYMORPH: - case WAN_STRIKING: - case SPE_FORCE_BOLT: - case WAN_SLOW_MONSTER: - case SPE_SLOW_MONSTER: - case WAN_SPEED_MONSTER: - case SPE_HEALING: - case SPE_EXTRA_HEALING: - case SPE_DRAIN_LIFE: - case WAN_OPENING: - case SPE_KNOCK: - (void) bhitm(u.usteed, obj); - steedhit = TRUE; - break; + /* Default processing via bhitm() for these */ + case SPE_CURE_SICKNESS: + case WAN_MAKE_INVISIBLE: + case WAN_CANCELLATION: + case SPE_CANCELLATION: + case WAN_POLYMORPH: + case SPE_POLYMORPH: + case WAN_STRIKING: + case SPE_FORCE_BOLT: + case WAN_SLOW_MONSTER: + case SPE_SLOW_MONSTER: + case WAN_SPEED_MONSTER: + case SPE_HEALING: + case SPE_EXTRA_HEALING: + case SPE_DRAIN_LIFE: + case WAN_OPENING: + case SPE_KNOCK: + (void) bhitm(u.usteed, obj); + steedhit = TRUE; + break; - default: - steedhit = FALSE; - break; - } - return steedhit; + default: + steedhit = FALSE; + break; + } + return steedhit; } /* @@ -2493,262 +2541,264 @@ struct obj *obj; /* wand or spell */ */ boolean cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel) -register struct monst *mdef; -register struct obj *obj; -boolean youattack, allow_cancel_kill, self_cancel; +register struct monst *mdef; +register struct obj *obj; +boolean youattack, allow_cancel_kill, self_cancel; { - boolean youdefend = (mdef == &youmonst); - static const char writing_vanishes[] = - "Some writing vanishes from %s head!"; - static const char your[] = "your"; /* should be extern */ + boolean youdefend = (mdef == &youmonst); + static const char writing_vanishes[] = + "Some writing vanishes from %s head!"; + static const char your[] = "your"; /* should be extern */ - if (youdefend ? (!youattack && Antimagic) - : resist(mdef, obj->oclass, 0, NOTELL)) - return FALSE; /* resisted cancellation */ + if (youdefend ? (!youattack && Antimagic) + : resist(mdef, obj->oclass, 0, NOTELL)) + return FALSE; /* resisted cancellation */ - if (self_cancel) { /* 1st cancel inventory */ - struct obj *otmp; + if (self_cancel) { /* 1st cancel inventory */ + struct obj *otmp; - for (otmp = (youdefend ? invent : mdef->minvent); - otmp; otmp = otmp->nobj) - cancel_item(otmp); - if (youdefend) { - context.botl = 1; /* potential AC change */ - find_ac(); - } - } + for (otmp = (youdefend ? invent : mdef->minvent); otmp; + otmp = otmp->nobj) + cancel_item(otmp); + if (youdefend) { + context.botl = 1; /* potential AC change */ + find_ac(); + } + } - /* now handle special cases */ - if (youdefend) { - if (Upolyd) { - if ((u.umonnum == PM_CLAY_GOLEM) && !Blind) - pline(writing_vanishes, your); + /* now handle special cases */ + if (youdefend) { + if (Upolyd) { + if ((u.umonnum == PM_CLAY_GOLEM) && !Blind) + pline(writing_vanishes, your); - if (Unchanging) - Your("amulet grows hot for a moment, then cools."); - else - rehumanize(); - } - } else { - mdef->mcan = TRUE; + if (Unchanging) + Your("amulet grows hot for a moment, then cools."); + else + rehumanize(); + } + } else { + mdef->mcan = TRUE; - if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN) - were_change(mdef); + if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN) + were_change(mdef); - if (mdef->data == &mons[PM_CLAY_GOLEM]) { - if (canseemon(mdef)) - pline(writing_vanishes, s_suffix(mon_nam(mdef))); + if (mdef->data == &mons[PM_CLAY_GOLEM]) { + if (canseemon(mdef)) + pline(writing_vanishes, s_suffix(mon_nam(mdef))); - if (allow_cancel_kill) { - if (youattack) - killed(mdef); - else - monkilled(mdef, "", AD_SPEL); - } - } - } - return TRUE; + if (allow_cancel_kill) { + if (youattack) + killed(mdef); + else + monkilled(mdef, "", AD_SPEL); + } + } + } + return TRUE; } /* you've zapped an immediate type wand up or down */ STATIC_OVL boolean zap_updown(obj) -struct obj *obj; /* wand or spell */ +struct obj *obj; /* wand or spell */ { - boolean striking = FALSE, disclose = FALSE; - int x, y, xx, yy, ptmp; - struct obj *otmp; - struct engr *e; - struct trap *ttmp; - char buf[BUFSZ]; + boolean striking = FALSE, disclose = FALSE; + int x, y, xx, yy, ptmp; + struct obj *otmp; + struct engr *e; + struct trap *ttmp; + char buf[BUFSZ]; - /* some wands have special effects other than normal bhitpile */ - /* drawbridge might change */ - x = xx = u.ux; /* is zap location */ - y = yy = u.uy; /* is drawbridge (portcullis) position */ - ttmp = t_at(x, y); /* trap if there is one */ + /* some wands have special effects other than normal bhitpile */ + /* drawbridge might change */ + x = xx = u.ux; /* is zap location */ + y = yy = u.uy; /* is drawbridge (portcullis) position */ + ttmp = t_at(x, y); /* trap if there is one */ - switch (obj->otyp) { - case WAN_PROBING: - ptmp = 0; - if (u.dz < 0) { - You("probe towards the %s.", ceiling(x,y)); - } else { - ptmp += bhitpile(obj, bhito, x, y, u.dz); - You("probe beneath the %s.", surface(x,y)); - ptmp += display_binventory(x, y, TRUE); - } - if (!ptmp) Your("probe reveals nothing."); - return TRUE; /* we've done our own bhitpile */ - case WAN_OPENING: - case SPE_KNOCK: - /* up or down, but at closed portcullis only */ - if (is_db_wall(x,y) && find_drawbridge(&xx, &yy)) { - open_drawbridge(xx, yy); - disclose = TRUE; - } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) && - /* can't use the stairs down to quest level 2 until - leader "unlocks" them; give feedback if you try */ - on_level(&u.uz, &qstart_level) && !ok_to_quest()) { - pline_The("stairs seem to ripple momentarily."); - disclose = TRUE; - } - /* down will release you from bear trap or web */ - if (u.dz > 0 && u.utrap) { - (void) openholdingtrap(&youmonst, &disclose); - /* down will trigger trapdoor, hole, or [spiked-] pit */ - } else if (u.dz > 0 && !u.utrap) { - (void) openfallingtrap(&youmonst, FALSE, &disclose); - } - break; - case WAN_STRIKING: - case SPE_FORCE_BOLT: - striking = TRUE; - /*FALLTHRU*/ - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - /* down at open bridge or up or down at open portcullis */ - if (((levl[x][y].typ == DRAWBRIDGE_DOWN) ? (u.dz > 0) : - (is_drawbridge_wall(x,y) >= 0 && !is_db_wall(x,y))) && - find_drawbridge(&xx, &yy)) { - if (!striking) - close_drawbridge(xx, yy); - else - destroy_drawbridge(xx, yy); - disclose = TRUE; - } else if (striking && u.dz < 0 && rn2(3) && - !Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && - !Underwater && !Is_qstart(&u.uz)) { - int dmg; - /* similar to zap_dig() */ - pline("A rock is dislodged from the %s and falls on your %s.", - ceiling(x, y), body_part(HEAD)); - dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); - losehp(Maybe_Half_Phys(dmg), - "falling rock", KILLED_BY_AN); - if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) { - (void)xname(otmp); /* set dknown, maybe bknown */ - stackobj(otmp); - } - newsym(x, y); - } else if (u.dz > 0 && ttmp) { - if (!striking && closeholdingtrap(&youmonst, &disclose)) { - ; /* now stuck in web or bear trap */ - } else if (striking && ttmp->ttyp == TRAPDOOR) { - /* striking transforms trapdoor into hole */ - if (Blind && !ttmp->tseen) { - pline("%s beneath you shatters.", Something); - } else if (!ttmp->tseen) { /* => !Blind */ - pline("There's a trapdoor beneath you; it shatters."); - } else { - pline("The trapdoor beneath you shatters."); - disclose = TRUE; - } - ttmp->ttyp = HOLE; - ttmp->tseen = 1; - newsym(x, y); - /* might fall down hole */ - dotrap(ttmp, 0); - } else if (!striking && ttmp->ttyp == HOLE) { - /* locking transforms hole into trapdoor */ - ttmp->ttyp = TRAPDOOR; - if (Blind || !ttmp->tseen) { - pline("Some %s swirls beneath you.", - is_ice(x,y) ? "frost" : "dust"); - } else { - ttmp->tseen = 1; - newsym(x, y); - pline("A trapdoor appears beneath you."); - disclose = TRUE; - } - /* hadn't fallen down hole; won't fall now */ - } - } - break; - case SPE_STONE_TO_FLESH: - if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) || - Underwater || (Is_qstart(&u.uz) && u.dz < 0)) { - pline1(nothing_happens); - } else if (u.dz < 0) { /* we should do more... */ - pline("Blood drips on your %s.", body_part(FACE)); - } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) { - /* - Print this message only if there wasn't an engraving - affected here. If water or ice, act like waterlevel case. - */ - e = engr_at(u.ux, u.uy); - if (!(e && e->engr_type == ENGRAVE)) { - if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy)) - pline1(nothing_happens); - else - pline("Blood %ss %s your %s.", - is_lava(u.ux, u.uy) ? "boil" : "pool", - Levitation ? "beneath" : "at", - makeplural(body_part(FOOT))); - } - } - break; - default: - break; - } + switch (obj->otyp) { + case WAN_PROBING: + ptmp = 0; + if (u.dz < 0) { + You("probe towards the %s.", ceiling(x, y)); + } else { + ptmp += bhitpile(obj, bhito, x, y, u.dz); + You("probe beneath the %s.", surface(x, y)); + ptmp += display_binventory(x, y, TRUE); + } + if (!ptmp) + Your("probe reveals nothing."); + return TRUE; /* we've done our own bhitpile */ + case WAN_OPENING: + case SPE_KNOCK: + /* up or down, but at closed portcullis only */ + if (is_db_wall(x, y) && find_drawbridge(&xx, &yy)) { + open_drawbridge(xx, yy); + disclose = TRUE; + } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) && + /* can't use the stairs down to quest level 2 until + leader "unlocks" them; give feedback if you try */ + on_level(&u.uz, &qstart_level) && !ok_to_quest()) { + pline_The("stairs seem to ripple momentarily."); + disclose = TRUE; + } + /* down will release you from bear trap or web */ + if (u.dz > 0 && u.utrap) { + (void) openholdingtrap(&youmonst, &disclose); + /* down will trigger trapdoor, hole, or [spiked-] pit */ + } else if (u.dz > 0 && !u.utrap) { + (void) openfallingtrap(&youmonst, FALSE, &disclose); + } + break; + case WAN_STRIKING: + case SPE_FORCE_BOLT: + striking = TRUE; + /*FALLTHRU*/ + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + /* down at open bridge or up or down at open portcullis */ + if (((levl[x][y].typ == DRAWBRIDGE_DOWN) + ? (u.dz > 0) + : (is_drawbridge_wall(x, y) >= 0 && !is_db_wall(x, y))) + && find_drawbridge(&xx, &yy)) { + if (!striking) + close_drawbridge(xx, yy); + else + destroy_drawbridge(xx, yy); + disclose = TRUE; + } else if (striking && u.dz < 0 && rn2(3) && !Is_airlevel(&u.uz) + && !Is_waterlevel(&u.uz) && !Underwater + && !Is_qstart(&u.uz)) { + int dmg; + /* similar to zap_dig() */ + pline("A rock is dislodged from the %s and falls on your %s.", + ceiling(x, y), body_part(HEAD)); + dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); + losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); + if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) { + (void) xname(otmp); /* set dknown, maybe bknown */ + stackobj(otmp); + } + newsym(x, y); + } else if (u.dz > 0 && ttmp) { + if (!striking && closeholdingtrap(&youmonst, &disclose)) { + ; /* now stuck in web or bear trap */ + } else if (striking && ttmp->ttyp == TRAPDOOR) { + /* striking transforms trapdoor into hole */ + if (Blind && !ttmp->tseen) { + pline("%s beneath you shatters.", Something); + } else if (!ttmp->tseen) { /* => !Blind */ + pline("There's a trapdoor beneath you; it shatters."); + } else { + pline("The trapdoor beneath you shatters."); + disclose = TRUE; + } + ttmp->ttyp = HOLE; + ttmp->tseen = 1; + newsym(x, y); + /* might fall down hole */ + dotrap(ttmp, 0); + } else if (!striking && ttmp->ttyp == HOLE) { + /* locking transforms hole into trapdoor */ + ttmp->ttyp = TRAPDOOR; + if (Blind || !ttmp->tseen) { + pline("Some %s swirls beneath you.", + is_ice(x, y) ? "frost" : "dust"); + } else { + ttmp->tseen = 1; + newsym(x, y); + pline("A trapdoor appears beneath you."); + disclose = TRUE; + } + /* hadn't fallen down hole; won't fall now */ + } + } + break; + case SPE_STONE_TO_FLESH: + if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) || Underwater + || (Is_qstart(&u.uz) && u.dz < 0)) { + pline1(nothing_happens); + } else if (u.dz < 0) { /* we should do more... */ + pline("Blood drips on your %s.", body_part(FACE)); + } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) { + /* + Print this message only if there wasn't an engraving + affected here. If water or ice, act like waterlevel case. + */ + e = engr_at(u.ux, u.uy); + if (!(e && e->engr_type == ENGRAVE)) { + if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy)) + pline1(nothing_happens); + else + pline("Blood %ss %s your %s.", + is_lava(u.ux, u.uy) ? "boil" : "pool", + Levitation ? "beneath" : "at", + makeplural(body_part(FOOT))); + } + } + break; + default: + break; + } - if (u.dz > 0) { - /* zapping downward */ - (void) bhitpile(obj, bhito, x, y, u.dz); + if (u.dz > 0) { + /* zapping downward */ + (void) bhitpile(obj, bhito, x, y, u.dz); - /* subset of engraving effects; none sets `disclose' */ - if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) { - switch (obj->otyp) { - case WAN_POLYMORPH: - case SPE_POLYMORPH: - del_engr(e); - make_engr_at(x, y, random_engraving(buf), moves, (xchar)0); - break; - case WAN_CANCELLATION: - case SPE_CANCELLATION: - case WAN_MAKE_INVISIBLE: - del_engr(e); - break; - case WAN_TELEPORTATION: - case SPE_TELEPORT_AWAY: - rloc_engr(e); - break; - case SPE_STONE_TO_FLESH: - if (e->engr_type == ENGRAVE) { - /* only affects things in stone */ - pline_The(Hallucination ? - "floor runs like butter!" : - "edges on the floor get smoother."); - wipe_engr_at(x, y, d(2,4), TRUE); - } - break; - case WAN_STRIKING: - case SPE_FORCE_BOLT: - wipe_engr_at(x, y, d(2,4), TRUE); - break; - default: - break; - } - } - } else if (u.dz < 0) { - /* zapping upward */ + /* subset of engraving effects; none sets `disclose' */ + if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) { + switch (obj->otyp) { + case WAN_POLYMORPH: + case SPE_POLYMORPH: + del_engr(e); + make_engr_at(x, y, random_engraving(buf), moves, (xchar) 0); + break; + case WAN_CANCELLATION: + case SPE_CANCELLATION: + case WAN_MAKE_INVISIBLE: + del_engr(e); + break; + case WAN_TELEPORTATION: + case SPE_TELEPORT_AWAY: + rloc_engr(e); + break; + case SPE_STONE_TO_FLESH: + if (e->engr_type == ENGRAVE) { + /* only affects things in stone */ + pline_The(Hallucination + ? "floor runs like butter!" + : "edges on the floor get smoother."); + wipe_engr_at(x, y, d(2, 4), TRUE); + } + break; + case WAN_STRIKING: + case SPE_FORCE_BOLT: + wipe_engr_at(x, y, d(2, 4), TRUE); + break; + default: + break; + } + } + } else if (u.dz < 0) { + /* zapping upward */ - /* game flavor: if you're hiding under "something" - * a zap upward should hit that "something". - */ - if (u.uundetected && hides_under(youmonst.data)) { - int hitit = 0; - otmp = level.objects[u.ux][u.uy]; + /* game flavor: if you're hiding under "something" + * a zap upward should hit that "something". + */ + if (u.uundetected && hides_under(youmonst.data)) { + int hitit = 0; + otmp = level.objects[u.ux][u.uy]; - if (otmp) hitit = bhito(otmp, obj); - if (hitit) { - (void) hideunder(&youmonst); - disclose = TRUE; - } - } - } + if (otmp) + hitit = bhito(otmp, obj); + if (hitit) { + (void) hideunder(&youmonst); + disclose = TRUE; + } + } + } - return disclose; + return disclose; } /* used by do_break_wand() was well as by weffects() */ @@ -2763,82 +2813,83 @@ zapwrapup() { /* if do_osshock() set obj_zapped while polying, give a message now */ if (obj_zapped) - You_feel("shuddering vibrations."); + You_feel("shuddering vibrations."); obj_zapped = FALSE; } /* called for various wand and spell effects - M. Stephenson */ void weffects(obj) -struct obj *obj; +struct obj *obj; { - int otyp = obj->otyp; - boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known; + int otyp = obj->otyp; + boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known; - exercise(A_WIS, TRUE); - if (u.usteed && (objects[otyp].oc_dir != NODIR) && - !u.dx && !u.dy && (u.dz > 0) && zap_steed(obj)) { - disclose = TRUE; - } else if (objects[otyp].oc_dir == IMMEDIATE) { - zapsetup(); /* reset obj_zapped */ - if (u.uswallow) { - (void) bhitm(u.ustuck, obj); - /* [how about `bhitpile(u.ustuck->minvent)' effect?] */ - } else if (u.dz) { - disclose = zap_updown(obj); - } else { - (void) bhit(u.dx,u.dy, rn1(8,6),ZAPPED_WAND, bhitm,bhito, &obj); - } - zapwrapup(); /* give feedback for obj_zapped */ + exercise(A_WIS, TRUE); + if (u.usteed && (objects[otyp].oc_dir != NODIR) && !u.dx && !u.dy + && (u.dz > 0) && zap_steed(obj)) { + disclose = TRUE; + } else if (objects[otyp].oc_dir == IMMEDIATE) { + zapsetup(); /* reset obj_zapped */ + if (u.uswallow) { + (void) bhitm(u.ustuck, obj); + /* [how about `bhitpile(u.ustuck->minvent)' effect?] */ + } else if (u.dz) { + disclose = zap_updown(obj); + } else { + (void) bhit(u.dx, u.dy, rn1(8, 6), ZAPPED_WAND, bhitm, bhito, + &obj); + } + zapwrapup(); /* give feedback for obj_zapped */ - } else if (objects[otyp].oc_dir == NODIR) { - zapnodir(obj); + } else if (objects[otyp].oc_dir == NODIR) { + zapnodir(obj); - } else { - /* neither immediate nor directionless */ + } else { + /* neither immediate nor directionless */ - if (otyp == WAN_DIGGING || otyp == SPE_DIG) - zap_dig(); - else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH) - buzz(otyp - SPE_MAGIC_MISSILE + 10, - u.ulevel / 2 + 1, - u.ux, u.uy, u.dx, u.dy); - else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING) - buzz(otyp - WAN_MAGIC_MISSILE, - (otyp == WAN_MAGIC_MISSILE) ? 2 : 6, - u.ux, u.uy, u.dx, u.dy); - else - impossible("weffects: unexpected spell or wand"); - disclose = TRUE; - } - if (disclose) { - learnwand(obj); - if (was_unkn) more_experienced(0, 10); - } - return; + if (otyp == WAN_DIGGING || otyp == SPE_DIG) + zap_dig(); + else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH) + buzz(otyp - SPE_MAGIC_MISSILE + 10, u.ulevel / 2 + 1, u.ux, u.uy, + u.dx, u.dy); + else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING) + buzz(otyp - WAN_MAGIC_MISSILE, + (otyp == WAN_MAGIC_MISSILE) ? 2 : 6, u.ux, u.uy, u.dx, u.dy); + else + impossible("weffects: unexpected spell or wand"); + disclose = TRUE; + } + if (disclose) { + learnwand(obj); + if (was_unkn) + more_experienced(0, 10); + } + return; } /* augment damage for a spell dased on the hero's intelligence (and level) */ int spell_damage_bonus(dmg) -int dmg; /* base amount to be adjusted by bonus or penalty */ +int dmg; /* base amount to be adjusted by bonus or penalty */ { int intell = ACURR(A_INT); /* Punish low intellegence before low level else low intellegence gets punished only when high level */ if (intell <= 9) { - /* -3 penalty, but never reduce combined amount below 1 - (if dmg is 0 for some reason, we're careful to leave it there) */ - if (dmg > 1) dmg = (dmg <= 3) ? 1 : dmg - 3; + /* -3 penalty, but never reduce combined amount below 1 + (if dmg is 0 for some reason, we're careful to leave it there) */ + if (dmg > 1) + dmg = (dmg <= 3) ? 1 : dmg - 3; } else if (intell <= 13 || u.ulevel < 5) - ; /* no bonus or penalty; dmg remains same */ + ; /* no bonus or penalty; dmg remains same */ else if (intell <= 18) - dmg += 1; + dmg += 1; else if (intell <= 24 || u.ulevel < 14) - dmg += 2; + dmg += 2; else - dmg += 3; /* Int 25 */ + dmg += 3; /* Int 25 */ return dmg; } @@ -2855,25 +2906,33 @@ int skill; int dex = ACURR(A_DEX); switch (P_SKILL(spell_skilltype(skill))) { - case P_ISRESTRICTED: - case P_UNSKILLED: hit_bon = -4; break; - case P_BASIC: hit_bon = 0; break; - case P_SKILLED: hit_bon = 2; break; - case P_EXPERT: hit_bon = 3; break; + case P_ISRESTRICTED: + case P_UNSKILLED: + hit_bon = -4; + break; + case P_BASIC: + hit_bon = 0; + break; + case P_SKILLED: + hit_bon = 2; + break; + case P_EXPERT: + hit_bon = 3; + break; } if (dex < 4) - hit_bon -= 3; + hit_bon -= 3; else if (dex < 6) - hit_bon -= 2; + hit_bon -= 2; else if (dex < 8) - hit_bon -= 1; + hit_bon -= 1; else if (dex < 14) /* Will change when print stuff below removed */ - hit_bon -= 0; + hit_bon -= 0; else - /* Even increment for dextrous heroes (see weapon.c abon) */ - hit_bon += dex - 14; + /* Even increment for dextrous heroes (see weapon.c abon) */ + hit_bon += dex - 14; return hit_bon; } @@ -2882,45 +2941,47 @@ const char * exclam(force) register int force; { - /* force == 0 occurs e.g. with sleep ray */ - /* note that large force is usual with wands so that !! would - require information about hand/weapon/wand */ - return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!"); + /* force == 0 occurs e.g. with sleep ray */ + /* note that large force is usual with wands so that !! would + require information about hand/weapon/wand */ + return (const char *) ((force < 0) ? "?" : (force <= 4) ? "." : "!"); } void -hit(str,mtmp,force) +hit(str, mtmp, force) register const char *str; register struct monst *mtmp; -register const char *force; /* usually either "." or "!" */ +register const char *force; /* usually either "." or "!" */ { - if((!cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp) && - !(u.uswallow && mtmp == u.ustuck)) - || !flags.verbose) - pline("%s %s it.", The(str), vtense(str, "hit")); - else pline("%s %s %s%s", The(str), vtense(str, "hit"), - mon_nam(mtmp), force); + if ((!cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp) + && !(u.uswallow && mtmp == u.ustuck)) || !flags.verbose) + pline("%s %s it.", The(str), vtense(str, "hit")); + else + pline("%s %s %s%s", The(str), vtense(str, "hit"), mon_nam(mtmp), + force); } void -miss(str,mtmp) +miss(str, mtmp) register const char *str; register struct monst *mtmp; { - pline("%s %s %s.", The(str), vtense(str, "miss"), - ((cansee(bhitpos.x,bhitpos.y) || canspotmon(mtmp)) - && flags.verbose) ? - mon_nam(mtmp) : "it"); + pline( + "%s %s %s.", The(str), vtense(str, "miss"), + ((cansee(bhitpos.x, bhitpos.y) || canspotmon(mtmp)) && flags.verbose) + ? mon_nam(mtmp) + : "it"); } STATIC_OVL void skiprange(range, skipstart, skipend) int range, *skipstart, *skipend; { - int tmp = range - (rnd(range / 4)); - *skipstart = tmp; - *skipend = tmp - ((tmp / 4) * rnd(3)); - if (*skipend >= tmp) *skipend = tmp - 1; + int tmp = range - (rnd(range / 4)); + *skipstart = tmp; + *skipend = tmp - ((tmp / 4) * rnd(3)); + if (*skipend >= tmp) + *skipend = tmp - 1; } /* @@ -2930,7 +2991,8 @@ int range, *skipstart, *skipend; * when an IMMEDIATE wand is zapped (ZAPPED_WAND) * when a light beam is flashed (FLASHED_LIGHT) * when a mirror is applied (INVIS_BEAM) - * A thrown/kicked object falls down at the end of its range or when a monster + * A thrown/kicked object falls down at the end of its range or when a + *monster * is hit. The variable 'bhitpos' is set to the final position of the weapon * thrown/zapped. The ray of a wand may affect (by calling a provided * function) several objects and monsters on its path. The return value @@ -2945,275 +3007,276 @@ int range, *skipstart, *skipend; * one is revealed for a weapon, but if not a weapon is left up to fhitm(). */ struct monst * -bhit(ddx,ddy,range,weapon,fhitm,fhito,pobj) -register int ddx,ddy,range; /* direction and range */ -int weapon; /* see values in hack.h */ -int FDECL((*fhitm), (MONST_P, OBJ_P)), /* fns called when mon/obj hit */ +bhit(ddx, ddy, range, weapon, fhitm, fhito, pobj) +register int ddx, ddy, range; /* direction and range */ +int weapon; /* see values in hack.h */ +int FDECL((*fhitm), (MONST_P, OBJ_P)), /* fns called when mon/obj hit */ FDECL((*fhito), (OBJ_P, OBJ_P)); -struct obj **pobj; /* object tossed/used, set to NULL - * if object is destroyed */ +struct obj **pobj; /* object tossed/used, set to NULL + * if object is destroyed */ { - struct monst *mtmp; - struct obj *obj = *pobj; - uchar typ; - boolean shopdoor = FALSE, point_blank = TRUE; - boolean in_skip = FALSE, allow_skip = FALSE; - int skiprange_start = 0, skiprange_end = 0, skipcount = 0; + struct monst *mtmp; + struct obj *obj = *pobj; + uchar typ; + boolean shopdoor = FALSE, point_blank = TRUE; + boolean in_skip = FALSE, allow_skip = FALSE; + int skiprange_start = 0, skiprange_end = 0, skipcount = 0; - if (weapon == KICKED_WEAPON) { - /* object starts one square in front of player */ - bhitpos.x = u.ux + ddx; - bhitpos.y = u.uy + ddy; - range--; - } else { - bhitpos.x = u.ux; - bhitpos.y = u.uy; - } + if (weapon == KICKED_WEAPON) { + /* object starts one square in front of player */ + bhitpos.x = u.ux + ddx; + bhitpos.y = u.uy + ddy; + range--; + } else { + bhitpos.x = u.ux; + bhitpos.y = u.uy; + } - if (weapon == THROWN_WEAPON && obj && obj->otyp == ROCK) { - skiprange(range, &skiprange_start, &skiprange_end); - allow_skip = !rn2(3); - } + if (weapon == THROWN_WEAPON && obj && obj->otyp == ROCK) { + skiprange(range, &skiprange_start, &skiprange_end); + allow_skip = !rn2(3); + } - if (weapon == FLASHED_LIGHT) { - tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam)); - } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) - tmp_at(DISP_FLASH, obj_to_glyph(obj)); + if (weapon == FLASHED_LIGHT) { + tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam)); + } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) + tmp_at(DISP_FLASH, obj_to_glyph(obj)); - while(range-- > 0) { - int x,y; + while (range-- > 0) { + int x, y; - bhitpos.x += ddx; - bhitpos.y += ddy; - x = bhitpos.x; y = bhitpos.y; + bhitpos.x += ddx; + bhitpos.y += ddy; + x = bhitpos.x; + y = bhitpos.y; - if(!isok(x, y)) { - bhitpos.x -= ddx; - bhitpos.y -= ddy; - break; - } + if (!isok(x, y)) { + bhitpos.x -= ddx; + bhitpos.y -= ddy; + break; + } - if(is_pick(obj) && inside_shop(x, y) && - (mtmp = shkcatch(obj, x, y))) { - tmp_at(DISP_END, 0); - return(mtmp); - } + if (is_pick(obj) && inside_shop(x, y) + && (mtmp = shkcatch(obj, x, y))) { + tmp_at(DISP_END, 0); + return (mtmp); + } - typ = levl[bhitpos.x][bhitpos.y].typ; + typ = levl[bhitpos.x][bhitpos.y].typ; - /* iron bars will block anything big enough */ - if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON) && - typ == IRONBARS && - hits_bars(pobj, x - ddx, y - ddy, - point_blank ? 0 : !rn2(5), 1)) { - /* caveat: obj might now be null... */ - obj = *pobj; - bhitpos.x -= ddx; - bhitpos.y -= ddy; - break; - } + /* iron bars will block anything big enough */ + if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON) + && typ == IRONBARS && hits_bars(pobj, x - ddx, y - ddy, + point_blank ? 0 : !rn2(5), 1)) { + /* caveat: obj might now be null... */ + obj = *pobj; + bhitpos.x -= ddx; + bhitpos.y -= ddy; + break; + } - if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y)) { - boolean learn_it = FALSE; + if (weapon == ZAPPED_WAND && find_drawbridge(&x, &y)) { + boolean learn_it = FALSE; - switch (obj->otyp) { - case WAN_OPENING: - case SPE_KNOCK: - if (is_db_wall(bhitpos.x, bhitpos.y)) { - if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y)) - learn_it = TRUE; - open_drawbridge(x,y); - } - break; - case WAN_LOCKING: - case SPE_WIZARD_LOCK: - if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y)) && - levl[x][y].typ == DRAWBRIDGE_DOWN) - learn_it = TRUE; - close_drawbridge(x,y); - break; - case WAN_STRIKING: - case SPE_FORCE_BOLT: - if (typ != DRAWBRIDGE_UP) - destroy_drawbridge(x,y); - learn_it = TRUE; - break; - } - if (learn_it) learnwand(obj); - } + switch (obj->otyp) { + case WAN_OPENING: + case SPE_KNOCK: + if (is_db_wall(bhitpos.x, bhitpos.y)) { + if (cansee(x, y) || cansee(bhitpos.x, bhitpos.y)) + learn_it = TRUE; + open_drawbridge(x, y); + } + break; + case WAN_LOCKING: + case SPE_WIZARD_LOCK: + if ((cansee(x, y) || cansee(bhitpos.x, bhitpos.y)) + && levl[x][y].typ == DRAWBRIDGE_DOWN) + learn_it = TRUE; + close_drawbridge(x, y); + break; + case WAN_STRIKING: + case SPE_FORCE_BOLT: + if (typ != DRAWBRIDGE_UP) + destroy_drawbridge(x, y); + learn_it = TRUE; + break; + } + if (learn_it) + learnwand(obj); + } - mtmp = m_at(bhitpos.x, bhitpos.y); - - /* - * skipping rocks - * - * skiprange_start is only set if this is a thrown rock - */ - if (skiprange_start && (range == skiprange_start) && allow_skip) { - if (is_pool(bhitpos.x, bhitpos.y) && !mtmp) { - in_skip = TRUE; - if (!Blind) pline("%s %s%s.", Yname2(obj), - otense(obj, "skip"), - skipcount ? " again" : ""); - else You_hear("%s skip.", yname(obj)); - skipcount++; - } else if (skiprange_start > skiprange_end + 1) { - --skiprange_start; - } - } - if (in_skip) { - if (range <= skiprange_end) { - in_skip = FALSE; - if (range > 3) /* another bounce? */ - skiprange(range, &skiprange_start, &skiprange_end); - } else if (mtmp && M_IN_WATER(mtmp->data)) { - if ((!Blind && canseemon(mtmp)) || sensemon(mtmp)) - pline("%s %s over %s.", - Yname2(obj), otense(obj, "pass"), - mon_nam(mtmp)); - } - } + mtmp = m_at(bhitpos.x, bhitpos.y); - if (mtmp && !(in_skip && M_IN_WATER(mtmp->data))) { - notonhead = (bhitpos.x != mtmp->mx || - bhitpos.y != mtmp->my); - if (weapon == FLASHED_LIGHT) { - /* FLASHED_LIGHT hitting invisible monster should - pass through instead of stop so we call - flash_hits_mon() directly rather than returning - mtmp back to caller. That allows the flash to - keep on going. Note that we use mtmp->minvis - not canspotmon() because it makes no difference - whether the hero can see the monster or not. */ - if (mtmp->minvis) { - obj->ox = u.ux, obj->oy = u.uy; - (void) flash_hits_mon(mtmp, obj); - } else { - tmp_at(DISP_END, 0); - return mtmp; /* caller will call flash_hits_mon */ - } - } else if (weapon == INVIS_BEAM) { - /* Like FLASHED_LIGHT, INVIS_BEAM should continue - through invisible targets; unlike it, we aren't - prepared for multiple hits so just get first one - that's either visible or could see its invisible - self. [No tmp_at() cleanup is needed here.] */ - if (!mtmp->minvis || perceives(mtmp->data)) - return mtmp; - } else if (weapon != ZAPPED_WAND) { - /* THROWN_WEAPON, KICKED_WEAPON */ - tmp_at(DISP_END, 0); - if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) - map_invisible(bhitpos.x, bhitpos.y); - return mtmp; - } else { - /* ZAPPED_WAND */ - (*fhitm)(mtmp, obj); - range -= 3; - } - } else { - if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING && - glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) { - unmap_object(bhitpos.x, bhitpos.y); - newsym(x, y); - } - } - if(fhito) { - if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y,0)) - range--; - } else { - if(weapon == KICKED_WEAPON && - ((obj->oclass == COIN_CLASS && - OBJ_AT(bhitpos.x, bhitpos.y)) || - ship_object(obj, bhitpos.x, bhitpos.y, - costly_spot(bhitpos.x, bhitpos.y)))) { - tmp_at(DISP_END, 0); - return (struct monst *)0; - } - } - if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) { - switch (obj->otyp) { - case WAN_OPENING: - case WAN_LOCKING: - case WAN_STRIKING: - case SPE_KNOCK: - case SPE_WIZARD_LOCK: - case SPE_FORCE_BOLT: - if (doorlock(obj, bhitpos.x, bhitpos.y)) { - if (cansee(bhitpos.x, bhitpos.y) || - (obj->otyp == WAN_STRIKING && !Deaf)) - learnwand(obj); - if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN && - *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) { - shopdoor = TRUE; - add_damage(bhitpos.x, bhitpos.y, 400L); - } - } - break; - } - } - if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) { - bhitpos.x -= ddx; - bhitpos.y -= ddy; - break; - } - if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) { - /* 'I' present but no monster: erase */ - /* do this before the tmp_at() */ - if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph) - && cansee(x, y)) { - unmap_object(bhitpos.x, bhitpos.y); - newsym(x, y); - } - tmp_at(bhitpos.x, bhitpos.y); - delay_output(); - /* kicked objects fall in pools */ - if((weapon == KICKED_WEAPON) && - (is_pool(bhitpos.x, bhitpos.y) || - is_lava(bhitpos.x, bhitpos.y))) - break; - if(IS_SINK(typ) && weapon != FLASHED_LIGHT) - break; /* physical objects fall onto sink */ - } - /* limit range of ball so hero won't make an invalid move */ - if (weapon == THROWN_WEAPON && range > 0 && - obj->otyp == HEAVY_IRON_BALL) { - struct obj *bobj; - struct trap *t; - if ((bobj = sobj_at(BOULDER, x, y)) != 0) { - if (cansee(x,y)) - pline("%s hits %s.", - The(distant_name(obj, xname)), an(xname(bobj))); - range = 0; - } else if (obj == uball) { - if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) { - /* nb: it didn't hit anything directly */ - if (cansee(x,y)) - pline("%s jerks to an abrupt halt.", - The(distant_name(obj, xname))); /* lame */ - range = 0; - } else if (Sokoban && (t = t_at(x, y)) != 0 && - (t->ttyp == PIT || t->ttyp == SPIKED_PIT || - t->ttyp == HOLE || t->ttyp == TRAPDOOR)) { - /* hero falls into the trap, so ball stops */ - range = 0; - } - } - } + /* + * skipping rocks + * + * skiprange_start is only set if this is a thrown rock + */ + if (skiprange_start && (range == skiprange_start) && allow_skip) { + if (is_pool(bhitpos.x, bhitpos.y) && !mtmp) { + in_skip = TRUE; + if (!Blind) + pline("%s %s%s.", Yname2(obj), otense(obj, "skip"), + skipcount ? " again" : ""); + else + You_hear("%s skip.", yname(obj)); + skipcount++; + } else if (skiprange_start > skiprange_end + 1) { + --skiprange_start; + } + } + if (in_skip) { + if (range <= skiprange_end) { + in_skip = FALSE; + if (range > 3) /* another bounce? */ + skiprange(range, &skiprange_start, &skiprange_end); + } else if (mtmp && M_IN_WATER(mtmp->data)) { + if ((!Blind && canseemon(mtmp)) || sensemon(mtmp)) + pline("%s %s over %s.", Yname2(obj), otense(obj, "pass"), + mon_nam(mtmp)); + } + } - /* thrown/kicked missile has moved away from its starting spot */ - point_blank = FALSE; /* affects passing through iron bars */ - } + if (mtmp && !(in_skip && M_IN_WATER(mtmp->data))) { + notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); + if (weapon == FLASHED_LIGHT) { + /* FLASHED_LIGHT hitting invisible monster should + pass through instead of stop so we call + flash_hits_mon() directly rather than returning + mtmp back to caller. That allows the flash to + keep on going. Note that we use mtmp->minvis + not canspotmon() because it makes no difference + whether the hero can see the monster or not. */ + if (mtmp->minvis) { + obj->ox = u.ux, obj->oy = u.uy; + (void) flash_hits_mon(mtmp, obj); + } else { + tmp_at(DISP_END, 0); + return mtmp; /* caller will call flash_hits_mon */ + } + } else if (weapon == INVIS_BEAM) { + /* Like FLASHED_LIGHT, INVIS_BEAM should continue + through invisible targets; unlike it, we aren't + prepared for multiple hits so just get first one + that's either visible or could see its invisible + self. [No tmp_at() cleanup is needed here.] */ + if (!mtmp->minvis || perceives(mtmp->data)) + return mtmp; + } else if (weapon != ZAPPED_WAND) { + /* THROWN_WEAPON, KICKED_WEAPON */ + tmp_at(DISP_END, 0); + if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) + map_invisible(bhitpos.x, bhitpos.y); + return mtmp; + } else { + /* ZAPPED_WAND */ + (*fhitm)(mtmp, obj); + range -= 3; + } + } else { + if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING + && glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) { + unmap_object(bhitpos.x, bhitpos.y); + newsym(x, y); + } + } + if (fhito) { + if (bhitpile(obj, fhito, bhitpos.x, bhitpos.y, 0)) + range--; + } else { + if (weapon == KICKED_WEAPON + && ((obj->oclass == COIN_CLASS + && OBJ_AT(bhitpos.x, bhitpos.y)) + || ship_object(obj, bhitpos.x, bhitpos.y, + costly_spot(bhitpos.x, bhitpos.y)))) { + tmp_at(DISP_END, 0); + return (struct monst *) 0; + } + } + if (weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) { + switch (obj->otyp) { + case WAN_OPENING: + case WAN_LOCKING: + case WAN_STRIKING: + case SPE_KNOCK: + case SPE_WIZARD_LOCK: + case SPE_FORCE_BOLT: + if (doorlock(obj, bhitpos.x, bhitpos.y)) { + if (cansee(bhitpos.x, bhitpos.y) + || (obj->otyp == WAN_STRIKING && !Deaf)) + learnwand(obj); + if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN + && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) { + shopdoor = TRUE; + add_damage(bhitpos.x, bhitpos.y, 400L); + } + } + break; + } + } + if (!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) { + bhitpos.x -= ddx; + bhitpos.y -= ddy; + break; + } + if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) { + /* 'I' present but no monster: erase */ + /* do this before the tmp_at() */ + if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph) + && cansee(x, y)) { + unmap_object(bhitpos.x, bhitpos.y); + newsym(x, y); + } + tmp_at(bhitpos.x, bhitpos.y); + delay_output(); + /* kicked objects fall in pools */ + if ((weapon == KICKED_WEAPON) + && (is_pool(bhitpos.x, bhitpos.y) + || is_lava(bhitpos.x, bhitpos.y))) + break; + if (IS_SINK(typ) && weapon != FLASHED_LIGHT) + break; /* physical objects fall onto sink */ + } + /* limit range of ball so hero won't make an invalid move */ + if (weapon == THROWN_WEAPON && range > 0 + && obj->otyp == HEAVY_IRON_BALL) { + struct obj *bobj; + struct trap *t; + if ((bobj = sobj_at(BOULDER, x, y)) != 0) { + if (cansee(x, y)) + pline("%s hits %s.", The(distant_name(obj, xname)), + an(xname(bobj))); + range = 0; + } else if (obj == uball) { + if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) { + /* nb: it didn't hit anything directly */ + if (cansee(x, y)) + pline("%s jerks to an abrupt halt.", + The(distant_name(obj, xname))); /* lame */ + range = 0; + } else if (Sokoban && (t = t_at(x, y)) != 0 + && (t->ttyp == PIT || t->ttyp == SPIKED_PIT + || t->ttyp == HOLE || t->ttyp == TRAPDOOR)) { + /* hero falls into the trap, so ball stops */ + range = 0; + } + } + } - if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0); + /* thrown/kicked missile has moved away from its starting spot */ + point_blank = FALSE; /* affects passing through iron bars */ + } - if(shopdoor) - pay_for_damage("destroy", FALSE); + if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) + tmp_at(DISP_END, 0); - return (struct monst *)0; + if (shopdoor) + pay_for_damage("destroy", FALSE); + + return (struct monst *) 0; } -/* process thrown boomerang, which travels a curving path... +/* process thrown boomerang, which travels a curving path... * A multi-shot volley ought to have all missiles in flight at once, * but we're called separately for each one. We terminate the volley * early on a failed catch since continuing to throw after being hit @@ -3224,225 +3287,240 @@ boomhit(obj, dx, dy) struct obj *obj; int dx, dy; { - register int i, ct; - int boom; /* showsym[] index */ - struct monst *mtmp; - boolean counterclockwise = TRUE; /* right-handed throw */ + register int i, ct; + int boom; /* showsym[] index */ + struct monst *mtmp; + boolean counterclockwise = TRUE; /* right-handed throw */ -/* counterclockwise traversal patterns: - * ..........................54................................. - * ..................43.....6..3....765......................... - * ..........32.....5..2...7...2...8...4....87.................. - * .........4..1....6..1...8..1....9...3...9..6.....98.......... - * ..21@....5...@...7..@....9@......@12....@...5...@..7.....@9.. - * .3...9....6..9....89.....................1..4...1..6....1..8. - * .4...8.....78.............................23....2..5...2...7. - * ..567............................................34....3..6.. - * ........................................................45... - * (invert rows for corresponding clockwise patterns) - */ + /* counterclockwise traversal patterns: + * ..........................54................................. + * ..................43.....6..3....765......................... + * ..........32.....5..2...7...2...8...4....87.................. + * .........4..1....6..1...8..1....9...3...9..6.....98.......... + * ..21@....5...@...7..@....9@......@12....@...5...@..7.....@9.. + * .3...9....6..9....89.....................1..4...1..6....1..8. + * .4...8.....78.............................23....2..5...2...7. + * ..567............................................34....3..6.. + * ........................................................45... + * (invert rows for corresponding clockwise patterns) + */ - bhitpos.x = u.ux; - bhitpos.y = u.uy; - boom = counterclockwise ? S_boomleft : S_boomright; - for (i = 0; i < 8; i++) if (xdir[i] == dx && ydir[i] == dy) break; - tmp_at(DISP_FLASH, cmap_to_glyph(boom)); - for (ct = 0; ct < 10; ct++) { - i = (i + 8) % 8; /* 0..7 (8 -> 0, -1 -> 7) */ - boom = (S_boomleft + S_boomright - boom); /* toggle */ - tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */ - dx = xdir[i]; - dy = ydir[i]; - bhitpos.x += dx; - bhitpos.y += dy; - if(MON_AT(bhitpos.x, bhitpos.y)) { - mtmp = m_at(bhitpos.x,bhitpos.y); - m_respond(mtmp); - tmp_at(DISP_END, 0); - return(mtmp); - } - if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) || - closed_door(bhitpos.x, bhitpos.y)) { - bhitpos.x -= dx; - bhitpos.y -= dy; - break; - } - if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */ - if(Fumbling || rn2(20) >= ACURR(A_DEX)) { - /* we hit ourselves */ - (void) thitu(10 + obj->spe, - dmgval(obj, &youmonst), - obj, "boomerang"); - endmultishot(TRUE); - break; - } else { /* we catch it */ - tmp_at(DISP_END, 0); - You("skillfully catch the boomerang."); - return(&youmonst); - } - } - tmp_at(bhitpos.x, bhitpos.y); - delay_output(); - if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) { - if (!Deaf) pline("Klonk!"); - break; /* boomerang falls on sink */ - } - /* ct==0, initial position, we want next delta to be same; - ct==5, opposite position, repeat delta undoes first one */ - if (ct % 5 != 0) i += (counterclockwise ? -1 : 1); - } - tmp_at(DISP_END, 0); /* do not leave last symbol */ - return (struct monst *)0; + bhitpos.x = u.ux; + bhitpos.y = u.uy; + boom = counterclockwise ? S_boomleft : S_boomright; + for (i = 0; i < 8; i++) + if (xdir[i] == dx && ydir[i] == dy) + break; + tmp_at(DISP_FLASH, cmap_to_glyph(boom)); + for (ct = 0; ct < 10; ct++) { + i = (i + 8) % 8; /* 0..7 (8 -> 0, -1 -> 7) */ + boom = (S_boomleft + S_boomright - boom); /* toggle */ + tmp_at(DISP_CHANGE, cmap_to_glyph(boom)); /* change glyph */ + dx = xdir[i]; + dy = ydir[i]; + bhitpos.x += dx; + bhitpos.y += dy; + if (MON_AT(bhitpos.x, bhitpos.y)) { + mtmp = m_at(bhitpos.x, bhitpos.y); + m_respond(mtmp); + tmp_at(DISP_END, 0); + return (mtmp); + } + if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) + || closed_door(bhitpos.x, bhitpos.y)) { + bhitpos.x -= dx; + bhitpos.y -= dy; + break; + } + if (bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */ + if (Fumbling || rn2(20) >= ACURR(A_DEX)) { + /* we hit ourselves */ + (void) thitu(10 + obj->spe, dmgval(obj, &youmonst), obj, + "boomerang"); + endmultishot(TRUE); + break; + } else { /* we catch it */ + tmp_at(DISP_END, 0); + You("skillfully catch the boomerang."); + return (&youmonst); + } + } + tmp_at(bhitpos.x, bhitpos.y); + delay_output(); + if (IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) { + if (!Deaf) + pline("Klonk!"); + break; /* boomerang falls on sink */ + } + /* ct==0, initial position, we want next delta to be same; + ct==5, opposite position, repeat delta undoes first one */ + if (ct % 5 != 0) + i += (counterclockwise ? -1 : 1); + } + tmp_at(DISP_END, 0); /* do not leave last symbol */ + return (struct monst *) 0; } /* used by buzz(); also used by munslime(muse.c) */ -int -zhitm(mon, type, nd, ootmp) /* returns damage to mon */ +int zhitm(mon, type, nd, ootmp) /* returns damage to mon */ register struct monst *mon; register int type, nd; -struct obj **ootmp; /* to return worn armor for caller to disintegrate */ +struct obj **ootmp; /* to return worn armor for caller to disintegrate */ { - register int tmp = 0; - register int abstype = abs(type) % 10; - boolean sho_shieldeff = FALSE; - boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */ + register int tmp = 0; + register int abstype = abs(type) % 10; + boolean sho_shieldeff = FALSE; + boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */ - *ootmp = (struct obj *)0; - switch(abstype) { - case ZT_MAGIC_MISSILE: - if (resists_magm(mon)) { - sho_shieldeff = TRUE; - break; - } - tmp = d(nd,6); - if (spellcaster) - tmp = spell_damage_bonus(tmp); - break; - case ZT_FIRE: - if (resists_fire(mon)) { - sho_shieldeff = TRUE; - break; - } - tmp = d(nd,6); - if (resists_cold(mon)) tmp += 7; - if (spellcaster) - tmp = spell_damage_bonus(tmp); - if (burnarmor(mon)) { - if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_FIRE); - if (!rn2(3)) (void)destroy_mitem(mon, SCROLL_CLASS, AD_FIRE); - if (!rn2(5)) (void)destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE); - destroy_mitem(mon, FOOD_CLASS, AD_FIRE); /* carried slime */ - } - break; - case ZT_COLD: - if (resists_cold(mon)) { - sho_shieldeff = TRUE; - break; - } - tmp = d(nd,6); - if (resists_fire(mon)) tmp += d(nd, 3); - if (spellcaster) - tmp = spell_damage_bonus(tmp); - if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_COLD); - break; - case ZT_SLEEP: - tmp = 0; - (void)sleep_monst(mon, d(nd, 25), - type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0'); - break; - case ZT_DEATH: /* death/disintegration */ - if(abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */ - if(mon->data == &mons[PM_DEATH]) { - mon->mhpmax += mon->mhpmax/2; - if (mon->mhpmax >= MAGIC_COOKIE) - mon->mhpmax = MAGIC_COOKIE - 1; - mon->mhp = mon->mhpmax; - tmp = 0; - break; - } - if (nonliving(mon->data) || is_demon(mon->data) || - is_vampshifter(mon) || resists_magm(mon)) { - /* similar to player */ - sho_shieldeff = TRUE; - break; - } - type = -1; /* so they don't get saving throws */ - } else { - struct obj *otmp2; + *ootmp = (struct obj *) 0; + switch (abstype) { + case ZT_MAGIC_MISSILE: + if (resists_magm(mon)) { + sho_shieldeff = TRUE; + break; + } + tmp = d(nd, 6); + if (spellcaster) + tmp = spell_damage_bonus(tmp); + break; + case ZT_FIRE: + if (resists_fire(mon)) { + sho_shieldeff = TRUE; + break; + } + tmp = d(nd, 6); + if (resists_cold(mon)) + tmp += 7; + if (spellcaster) + tmp = spell_damage_bonus(tmp); + if (burnarmor(mon)) { + if (!rn2(3)) + (void) destroy_mitem(mon, POTION_CLASS, AD_FIRE); + if (!rn2(3)) + (void) destroy_mitem(mon, SCROLL_CLASS, AD_FIRE); + if (!rn2(5)) + (void) destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE); + destroy_mitem(mon, FOOD_CLASS, AD_FIRE); /* carried slime */ + } + break; + case ZT_COLD: + if (resists_cold(mon)) { + sho_shieldeff = TRUE; + break; + } + tmp = d(nd, 6); + if (resists_fire(mon)) + tmp += d(nd, 3); + if (spellcaster) + tmp = spell_damage_bonus(tmp); + if (!rn2(3)) + (void) destroy_mitem(mon, POTION_CLASS, AD_COLD); + break; + case ZT_SLEEP: + tmp = 0; + (void) sleep_monst(mon, d(nd, 25), + type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0'); + break; + case ZT_DEATH: /* death/disintegration */ + if (abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */ + if (mon->data == &mons[PM_DEATH]) { + mon->mhpmax += mon->mhpmax / 2; + if (mon->mhpmax >= MAGIC_COOKIE) + mon->mhpmax = MAGIC_COOKIE - 1; + mon->mhp = mon->mhpmax; + tmp = 0; + break; + } + if (nonliving(mon->data) || is_demon(mon->data) + || is_vampshifter(mon) || resists_magm(mon)) { + /* similar to player */ + sho_shieldeff = TRUE; + break; + } + type = -1; /* so they don't get saving throws */ + } else { + struct obj *otmp2; - if (resists_disint(mon)) { - sho_shieldeff = TRUE; - } else if (mon->misc_worn_check & W_ARMS) { - /* destroy shield; victim survives */ - *ootmp = which_armor(mon, W_ARMS); - } else if (mon->misc_worn_check & W_ARM) { - /* destroy body armor, also cloak if present */ - *ootmp = which_armor(mon, W_ARM); - if ((otmp2 = which_armor(mon, W_ARMC)) != 0) - m_useup(mon, otmp2); - } else { - /* no body armor, victim dies; destroy cloak - and shirt now in case target gets life-saved */ - tmp = MAGIC_COOKIE; - if ((otmp2 = which_armor(mon, W_ARMC)) != 0) - m_useup(mon, otmp2); - if ((otmp2 = which_armor(mon, W_ARMU)) != 0) - m_useup(mon, otmp2); - } - type = -1; /* no saving throw wanted */ - break; /* not ordinary damage */ - } - tmp = mon->mhp+1; - break; - case ZT_LIGHTNING: - if (resists_elec(mon)) { - sho_shieldeff = TRUE; - tmp = 0; - /* can still blind the monster */ - } else - tmp = d(nd,6); - if (spellcaster) - tmp = spell_damage_bonus(tmp); - if (!resists_blnd(mon) && - !(type > 0 && u.uswallow && mon == u.ustuck)) { - register unsigned rnd_tmp = rnd(50); - mon->mcansee = 0; - if((mon->mblinded + rnd_tmp) > 127) - mon->mblinded = 127; - else mon->mblinded += rnd_tmp; - } - if (!rn2(3)) (void)destroy_mitem(mon, WAND_CLASS, AD_ELEC); - /* not actually possible yet */ - if (!rn2(3)) (void)destroy_mitem(mon, RING_CLASS, AD_ELEC); - break; - case ZT_POISON_GAS: - if (resists_poison(mon)) { - sho_shieldeff = TRUE; - break; - } - tmp = d(nd,6); - break; - case ZT_ACID: - if (resists_acid(mon)) { - sho_shieldeff = TRUE; - break; - } - tmp = d(nd,6); - if (!rn2(6)) acid_damage(MON_WEP(mon)); - if (!rn2(6)) erode_armor(mon, ERODE_CORRODE); - break; - } - if (sho_shieldeff) shieldeff(mon->mx, mon->my); - if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart)) - tmp *= 2; - if (tmp > 0 && type >= 0 && - resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL)) - tmp /= 2; - if (tmp < 0) tmp = 0; /* don't allow negative damage */ - debugpline3("zapped monster hp = %d (= %d - %d)", - mon->mhp-tmp, mon->mhp, tmp); - mon->mhp -= tmp; - return(tmp); + if (resists_disint(mon)) { + sho_shieldeff = TRUE; + } else if (mon->misc_worn_check & W_ARMS) { + /* destroy shield; victim survives */ + *ootmp = which_armor(mon, W_ARMS); + } else if (mon->misc_worn_check & W_ARM) { + /* destroy body armor, also cloak if present */ + *ootmp = which_armor(mon, W_ARM); + if ((otmp2 = which_armor(mon, W_ARMC)) != 0) + m_useup(mon, otmp2); + } else { + /* no body armor, victim dies; destroy cloak + and shirt now in case target gets life-saved */ + tmp = MAGIC_COOKIE; + if ((otmp2 = which_armor(mon, W_ARMC)) != 0) + m_useup(mon, otmp2); + if ((otmp2 = which_armor(mon, W_ARMU)) != 0) + m_useup(mon, otmp2); + } + type = -1; /* no saving throw wanted */ + break; /* not ordinary damage */ + } + tmp = mon->mhp + 1; + break; + case ZT_LIGHTNING: + if (resists_elec(mon)) { + sho_shieldeff = TRUE; + tmp = 0; + /* can still blind the monster */ + } else + tmp = d(nd, 6); + if (spellcaster) + tmp = spell_damage_bonus(tmp); + if (!resists_blnd(mon) + && !(type > 0 && u.uswallow && mon == u.ustuck)) { + register unsigned rnd_tmp = rnd(50); + mon->mcansee = 0; + if ((mon->mblinded + rnd_tmp) > 127) + mon->mblinded = 127; + else + mon->mblinded += rnd_tmp; + } + if (!rn2(3)) + (void) destroy_mitem(mon, WAND_CLASS, AD_ELEC); + /* not actually possible yet */ + if (!rn2(3)) + (void) destroy_mitem(mon, RING_CLASS, AD_ELEC); + break; + case ZT_POISON_GAS: + if (resists_poison(mon)) { + sho_shieldeff = TRUE; + break; + } + tmp = d(nd, 6); + break; + case ZT_ACID: + if (resists_acid(mon)) { + sho_shieldeff = TRUE; + break; + } + tmp = d(nd, 6); + if (!rn2(6)) + acid_damage(MON_WEP(mon)); + if (!rn2(6)) + erode_armor(mon, ERODE_CORRODE); + break; + } + if (sho_shieldeff) + shieldeff(mon->mx, mon->my); + if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart)) + tmp *= 2; + if (tmp > 0 && type >= 0 + && resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL)) + tmp /= 2; + if (tmp < 0) + tmp = 0; /* don't allow negative damage */ + debugpline3("zapped monster hp = %d (= %d - %d)", mon->mhp - tmp, + mon->mhp, tmp); + mon->mhp -= tmp; + return (tmp); } STATIC_OVL void @@ -3451,242 +3529,258 @@ int type, nd; const char *fltxt; xchar sx, sy; { - int dam = 0, abstyp = abs(type); + int dam = 0, abstyp = abs(type); - switch (abstyp % 10) { - case ZT_MAGIC_MISSILE: - if (Antimagic) { - shieldeff(sx, sy); - pline_The("missiles bounce off!"); - } else { - dam = d(nd,6); - exercise(A_STR, FALSE); - } - break; - case ZT_FIRE: - if (Fire_resistance) { - shieldeff(sx, sy); - You("don't feel hot!"); - ugolemeffects(AD_FIRE, d(nd, 6)); - } else { - dam = d(nd, 6); - } - burn_away_slime(); - if (burnarmor(&youmonst)) { /* "body hit" */ - if (!rn2(3)) destroy_item(POTION_CLASS, AD_FIRE); - if (!rn2(3)) destroy_item(SCROLL_CLASS, AD_FIRE); - if (!rn2(5)) destroy_item(SPBOOK_CLASS, AD_FIRE); - destroy_item(FOOD_CLASS, AD_FIRE); - } - break; - case ZT_COLD: - if (Cold_resistance) { - shieldeff(sx, sy); - You("don't feel cold."); - ugolemeffects(AD_COLD, d(nd, 6)); - } else { - dam = d(nd, 6); - } - if (!rn2(3)) destroy_item(POTION_CLASS, AD_COLD); - break; - case ZT_SLEEP: - if (Sleep_resistance) { - shieldeff(u.ux, u.uy); - You("don't feel sleepy."); - } else { - fall_asleep(-d(nd,25), TRUE); /* sleep ray */ - } - break; - case ZT_DEATH: - if (abstyp == ZT_BREATH(ZT_DEATH)) { - if (Disint_resistance) { - You("are not disintegrated."); - break; - } else if (uarms) { - /* destroy shield; other possessions are safe */ - (void) destroy_arm(uarms); - break; - } else if (uarm) { - /* destroy suit; if present, cloak goes too */ - if (uarmc) (void) destroy_arm(uarmc); - (void) destroy_arm(uarm); - break; - } - /* no shield or suit, you're dead; wipe out cloak - and/or shirt in case of life-saving or bones */ - if (uarmc) (void) destroy_arm(uarmc); - if (uarmu) (void) destroy_arm(uarmu); - } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) { - shieldeff(sx, sy); - You("seem unaffected."); - break; - } else if (Antimagic) { - shieldeff(sx, sy); - You("aren't affected."); - break; - } - killer.format = KILLED_BY_AN; - Strcpy(killer.name, fltxt ? fltxt : ""); - /* when killed by disintegration breath, don't leave corpse */ - u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM; - done(DIED); - return; /* lifesaved */ - case ZT_LIGHTNING: - if (Shock_resistance) { - shieldeff(sx, sy); - You("aren't affected."); - ugolemeffects(AD_ELEC, d(nd, 6)); - } else { - dam = d(nd, 6); - exercise(A_CON, FALSE); - } - if (!rn2(3)) destroy_item(WAND_CLASS, AD_ELEC); - if (!rn2(3)) destroy_item(RING_CLASS, AD_ELEC); - break; - case ZT_POISON_GAS: - poisoned("blast", A_DEX, "poisoned blast", 15, FALSE); - break; - case ZT_ACID: - if (Acid_resistance) { - pline_The("acid doesn't hurt."); - dam = 0; - } else { - pline_The("acid burns!"); - dam = d(nd,6); - exercise(A_STR, FALSE); - } - /* using two weapons at once makes both of them more vulnerable */ - if (!rn2(u.twoweap ? 3 : 6)) - acid_damage(uwep); - if (u.twoweap && !rn2(3)) - acid_damage(uswapwep); - if (!rn2(6)) erode_armor(&youmonst, ERODE_CORRODE); - break; - } + switch (abstyp % 10) { + case ZT_MAGIC_MISSILE: + if (Antimagic) { + shieldeff(sx, sy); + pline_The("missiles bounce off!"); + } else { + dam = d(nd, 6); + exercise(A_STR, FALSE); + } + break; + case ZT_FIRE: + if (Fire_resistance) { + shieldeff(sx, sy); + You("don't feel hot!"); + ugolemeffects(AD_FIRE, d(nd, 6)); + } else { + dam = d(nd, 6); + } + burn_away_slime(); + if (burnarmor(&youmonst)) { /* "body hit" */ + if (!rn2(3)) + destroy_item(POTION_CLASS, AD_FIRE); + if (!rn2(3)) + destroy_item(SCROLL_CLASS, AD_FIRE); + if (!rn2(5)) + destroy_item(SPBOOK_CLASS, AD_FIRE); + destroy_item(FOOD_CLASS, AD_FIRE); + } + break; + case ZT_COLD: + if (Cold_resistance) { + shieldeff(sx, sy); + You("don't feel cold."); + ugolemeffects(AD_COLD, d(nd, 6)); + } else { + dam = d(nd, 6); + } + if (!rn2(3)) + destroy_item(POTION_CLASS, AD_COLD); + break; + case ZT_SLEEP: + if (Sleep_resistance) { + shieldeff(u.ux, u.uy); + You("don't feel sleepy."); + } else { + fall_asleep(-d(nd, 25), TRUE); /* sleep ray */ + } + break; + case ZT_DEATH: + if (abstyp == ZT_BREATH(ZT_DEATH)) { + if (Disint_resistance) { + You("are not disintegrated."); + break; + } else if (uarms) { + /* destroy shield; other possessions are safe */ + (void) destroy_arm(uarms); + break; + } else if (uarm) { + /* destroy suit; if present, cloak goes too */ + if (uarmc) + (void) destroy_arm(uarmc); + (void) destroy_arm(uarm); + break; + } + /* no shield or suit, you're dead; wipe out cloak + and/or shirt in case of life-saving or bones */ + if (uarmc) + (void) destroy_arm(uarmc); + if (uarmu) + (void) destroy_arm(uarmu); + } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) { + shieldeff(sx, sy); + You("seem unaffected."); + break; + } else if (Antimagic) { + shieldeff(sx, sy); + You("aren't affected."); + break; + } + killer.format = KILLED_BY_AN; + Strcpy(killer.name, fltxt ? fltxt : ""); + /* when killed by disintegration breath, don't leave corpse */ + u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM; + done(DIED); + return; /* lifesaved */ + case ZT_LIGHTNING: + if (Shock_resistance) { + shieldeff(sx, sy); + You("aren't affected."); + ugolemeffects(AD_ELEC, d(nd, 6)); + } else { + dam = d(nd, 6); + exercise(A_CON, FALSE); + } + if (!rn2(3)) + destroy_item(WAND_CLASS, AD_ELEC); + if (!rn2(3)) + destroy_item(RING_CLASS, AD_ELEC); + break; + case ZT_POISON_GAS: + poisoned("blast", A_DEX, "poisoned blast", 15, FALSE); + break; + case ZT_ACID: + if (Acid_resistance) { + pline_The("acid doesn't hurt."); + dam = 0; + } else { + pline_The("acid burns!"); + dam = d(nd, 6); + exercise(A_STR, FALSE); + } + /* using two weapons at once makes both of them more vulnerable */ + if (!rn2(u.twoweap ? 3 : 6)) + acid_damage(uwep); + if (u.twoweap && !rn2(3)) + acid_damage(uswapwep); + if (!rn2(6)) + erode_armor(&youmonst, ERODE_CORRODE); + break; + } - /* Half_spell_damage protection yields half-damage for wands & spells, - including hero's own ricochets; breath attacks do full damage */ - if (dam && Half_spell_damage && !(abstyp >= 20 && abstyp <= 29)) - dam = (dam + 1) / 2; - losehp(dam, fltxt, KILLED_BY_AN); - return; + /* Half_spell_damage protection yields half-damage for wands & spells, + including hero's own ricochets; breath attacks do full damage */ + if (dam && Half_spell_damage && !(abstyp >= 20 && abstyp <= 29)) + dam = (dam + 1) / 2; + losehp(dam, fltxt, KILLED_BY_AN); + return; } /* - * burn objects (such as scrolls and spellbooks) on floor + * burn objects (such as scrolls and spellbooks) on floor * at position x,y; return the number of objects burned */ int burn_floor_objects(x, y, give_feedback, u_caused) int x, y; -boolean give_feedback; /* caller needs to decide about visibility checks */ +boolean give_feedback; /* caller needs to decide about visibility checks */ boolean u_caused; { - struct obj *obj, *obj2; - long i, scrquan, delquan; - char buf1[BUFSZ], buf2[BUFSZ]; - int cnt = 0; + struct obj *obj, *obj2; + long i, scrquan, delquan; + char buf1[BUFSZ], buf2[BUFSZ]; + int cnt = 0; - for (obj = level.objects[x][y]; obj; obj = obj2) { - obj2 = obj->nexthere; - if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS - || (obj->oclass == FOOD_CLASS + for (obj = level.objects[x][y]; obj; obj = obj2) { + obj2 = obj->nexthere; + if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS + || (obj->oclass == FOOD_CLASS && obj->otyp == GLOB_OF_GREEN_SLIME)) { - if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL || - obj_resists(obj, 2, 100)) + if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL + || obj_resists(obj, 2, 100)) continue; - scrquan = obj->quan; /* number present */ - delquan = 0L; /* number to destroy */ + scrquan = obj->quan; /* number present */ + delquan = 0L; /* number to destroy */ for (i = scrquan; i > 0L; i--) - if (!rn2(3)) delquan++; + if (!rn2(3)) + delquan++; if (delquan) { /* save name before potential delobj() */ if (give_feedback) { - obj->quan = 1L; - Strcpy(buf1, (x == u.ux && y == u.uy) ? - xname(obj) : distant_name(obj, xname)); - obj->quan = 2L; - Strcpy(buf2, (x == u.ux && y == u.uy) ? - xname(obj) : distant_name(obj, xname)); - obj->quan = scrquan; + obj->quan = 1L; + Strcpy(buf1, (x == u.ux && y == u.uy) + ? xname(obj) + : distant_name(obj, xname)); + obj->quan = 2L; + Strcpy(buf2, (x == u.ux && y == u.uy) + ? xname(obj) + : distant_name(obj, xname)); + obj->quan = scrquan; } /* useupf(), which charges, only if hero caused damage */ - if (u_caused) useupf(obj, delquan); - else if (delquan < scrquan) obj->quan -= delquan; - else delobj(obj); + if (u_caused) + useupf(obj, delquan); + else if (delquan < scrquan) + obj->quan -= delquan; + else + delobj(obj); cnt += delquan; if (give_feedback) { - if (delquan > 1L) - pline("%ld %s burn.", delquan, buf2); - else - pline("%s burns.", An(buf1)); + if (delquan > 1L) + pline("%ld %s burn.", delquan, buf2); + else + pline("%s burns.", An(buf1)); } } - } - } - return cnt; + } + } + return cnt; } /* will zap/spell/breath attack score a hit against armor class `ac'? */ STATIC_OVL int zap_hit(ac, type) int ac; -int type; /* either hero cast spell type or 0 */ +int type; /* either hero cast spell type or 0 */ { int chance = rn2(20); int spell_bonus = type ? spell_hit_bonus(type) : 0; /* small chance for naked target to avoid being hit */ - if (!chance) return rnd(10) < ac+spell_bonus; + if (!chance) + return rnd(10) < ac + spell_bonus; /* very high armor protection does not achieve invulnerability */ ac = AC_VALUE(ac); - return (3 - chance) < ac+spell_bonus; + return (3 - chance) < ac + spell_bonus; } STATIC_OVL void disintegrate_mon(mon, type, fltxt) struct monst *mon; -int type; /* hero vs other */ +int type; /* hero vs other */ const char *fltxt; { struct obj *otmp, *otmp2, *m_amulet = mlifesaver(mon); if (canseemon(mon)) { - if (!m_amulet) - pline("%s is disintegrated!", Monnam(mon)); - else - hit(fltxt, mon, "!"); + if (!m_amulet) + pline("%s is disintegrated!", Monnam(mon)); + else + hit(fltxt, mon, "!"); } /* note: worn amulet of life saving must be preserved in order to operate */ -#define oresist_disintegration(obj) \ - (objects[obj->otyp].oc_oprop == DISINT_RES || \ - obj_resists(obj, 5, 50) || is_quest_artifact(obj) || \ - obj == m_amulet) +#define oresist_disintegration(obj) \ + (objects[obj->otyp].oc_oprop == DISINT_RES || obj_resists(obj, 5, 50) \ + || is_quest_artifact(obj) || obj == m_amulet) for (otmp = mon->minvent; otmp; otmp = otmp2) { - otmp2 = otmp->nobj; - if (!oresist_disintegration(otmp)) { - if (otmp->owornmask) { - /* in case monster's life gets saved */ - mon->misc_worn_check &= ~otmp->owornmask; - /* also dismounts hero if this object is steed's saddle */ - update_mon_intrinsics(mon, otmp, FALSE, TRUE); - otmp->owornmask = 0L; - } - obj_extract_self(otmp); - obfree(otmp, (struct obj *)0); - } + otmp2 = otmp->nobj; + if (!oresist_disintegration(otmp)) { + if (otmp->owornmask) { + /* in case monster's life gets saved */ + mon->misc_worn_check &= ~otmp->owornmask; + /* also dismounts hero if this object is steed's saddle */ + update_mon_intrinsics(mon, otmp, FALSE, TRUE); + otmp->owornmask = 0L; + } + obj_extract_self(otmp); + obfree(otmp, (struct obj *) 0); + } } #undef oresist_disintegration if (type < 0) - monkilled(mon, (char *)0, -AD_RBRE); + monkilled(mon, (char *) 0, -AD_RBRE); else - xkilled(mon, 2); + xkilled(mon, 2); } /* type == 0 to 9 : you shooting a wand */ @@ -3697,10 +3791,10 @@ const char *fltxt; /* type == -30 to -39 : monster shooting a wand */ /* called with dx = dy = 0 with vertical bolts */ void -buzz(type,nd,sx,sy,dx,dy) +buzz(type, nd, sx, sy, dx, dy) register int type, nd; -register xchar sx,sy; -register int dx,dy; +register xchar sx, sy; +register int dx, dy; { int range, abstype = abs(type) % 10; struct rm *lev; @@ -3716,198 +3810,223 @@ register int dx,dy; spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0; fltxt = flash_types[(type <= -30) ? abstype : abs(type)]; - if(u.uswallow) { - register int tmp; + if (u.uswallow) { + register int tmp; - if(type < 0) return; - tmp = zhitm(u.ustuck, type, nd, &otmp); - if(!u.ustuck) u.uswallow = 0; - else pline("%s rips into %s%s", - The(fltxt), mon_nam(u.ustuck), exclam(tmp)); - /* Using disintegration from the inside only makes a hole... */ - if (tmp == MAGIC_COOKIE) - u.ustuck->mhp = 0; - if (u.ustuck->mhp < 1) - killed(u.ustuck); - return; + if (type < 0) + return; + tmp = zhitm(u.ustuck, type, nd, &otmp); + if (!u.ustuck) + u.uswallow = 0; + else + pline("%s rips into %s%s", The(fltxt), mon_nam(u.ustuck), + exclam(tmp)); + /* Using disintegration from the inside only makes a hole... */ + if (tmp == MAGIC_COOKIE) + u.ustuck->mhp = 0; + if (u.ustuck->mhp < 1) + killed(u.ustuck); + return; } - if(type < 0) newsym(u.ux,u.uy); - range = rn1(7,7); - if(dx == 0 && dy == 0) range = 1; + if (type < 0) + newsym(u.ux, u.uy); + range = rn1(7, 7); + if (dx == 0 && dy == 0) + range = 1; save_bhitpos = bhitpos; tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype)); - while(range-- > 0) { - lsx = sx; sx += dx; - lsy = sy; sy += dy; - if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) { - mon = m_at(sx, sy); - if(cansee(sx,sy)) { - /* reveal/unreveal invisible monsters before tmp_at() */ - if (mon && !canspotmon(mon)) - map_invisible(sx, sy); - else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) { - unmap_object(sx, sy); - newsym(sx, sy); - } - if(ZAP_POS(lev->typ) || (isok(lsx,lsy) && cansee(lsx,lsy))) - tmp_at(sx,sy); - delay_output(); /* wait a little */ - } - } else - goto make_bounce; + while (range-- > 0) { + lsx = sx; + sx += dx; + lsy = sy; + sy += dy; + if (isok(sx, sy) && (lev = &levl[sx][sy])->typ) { + mon = m_at(sx, sy); + if (cansee(sx, sy)) { + /* reveal/unreveal invisible monsters before tmp_at() */ + if (mon && !canspotmon(mon)) + map_invisible(sx, sy); + else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) { + unmap_object(sx, sy); + newsym(sx, sy); + } + if (ZAP_POS(lev->typ) || (isok(lsx, lsy) && cansee(lsx, lsy))) + tmp_at(sx, sy); + delay_output(); /* wait a little */ + } + } else + goto make_bounce; - /* hit() and miss() need bhitpos to match the target */ - bhitpos.x = sx, bhitpos.y = sy; - /* Fireballs only damage when they explode */ - if (type != ZT_SPELL(ZT_FIRE)) - range += zap_over_floor(sx, sy, type, &shopdamage, 0); + /* hit() and miss() need bhitpos to match the target */ + bhitpos.x = sx, bhitpos.y = sy; + /* Fireballs only damage when they explode */ + if (type != ZT_SPELL(ZT_FIRE)) + range += zap_over_floor(sx, sy, type, &shopdamage, 0); - if (mon) { - if (type == ZT_SPELL(ZT_FIRE)) break; - if (type >= 0) mon->mstrategy &= ~STRAT_WAITMASK; - buzzmonst: - if (zap_hit(find_mac(mon), spell_type)) { - if (mon_reflects(mon, (char *)0)) { - if(cansee(mon->mx,mon->my)) { - hit(fltxt, mon, exclam(0)); - shieldeff(mon->mx, mon->my); - (void) mon_reflects(mon, "But it reflects from %s %s!"); - } - dx = -dx; - dy = -dy; - } else { - boolean mon_could_move = mon->mcanmove; - int tmp = zhitm(mon, type, nd, &otmp); + if (mon) { + if (type == ZT_SPELL(ZT_FIRE)) + break; + if (type >= 0) + mon->mstrategy &= ~STRAT_WAITMASK; + buzzmonst: + if (zap_hit(find_mac(mon), spell_type)) { + if (mon_reflects(mon, (char *) 0)) { + if (cansee(mon->mx, mon->my)) { + hit(fltxt, mon, exclam(0)); + shieldeff(mon->mx, mon->my); + (void) mon_reflects(mon, + "But it reflects from %s %s!"); + } + dx = -dx; + dy = -dy; + } else { + boolean mon_could_move = mon->mcanmove; + int tmp = zhitm(mon, type, nd, &otmp); - if (is_rider(mon->data) && abs(type) == ZT_BREATH(ZT_DEATH)) { - if (canseemon(mon)) { - hit(fltxt, mon, "."); - pline("%s disintegrates.", Monnam(mon)); - pline("%s body reintegrates before your %s!", - s_suffix(Monnam(mon)), - (eyecount(youmonst.data) == 1) ? - body_part(EYE) : makeplural(body_part(EYE))); - pline("%s resurrects!", Monnam(mon)); - } - mon->mhp = mon->mhpmax; - break; /* Out of while loop */ - } - if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) { - if (canseemon(mon)) { - hit(fltxt, mon, "."); - pline("%s absorbs the deadly %s!", Monnam(mon), - type == ZT_BREATH(ZT_DEATH) ? - "blast" : "ray"); - pline("It seems even stronger than before."); - } - break; /* Out of while loop */ - } + if (is_rider(mon->data) + && abs(type) == ZT_BREATH(ZT_DEATH)) { + if (canseemon(mon)) { + hit(fltxt, mon, "."); + pline("%s disintegrates.", Monnam(mon)); + pline("%s body reintegrates before your %s!", + s_suffix(Monnam(mon)), + (eyecount(youmonst.data) == 1) + ? body_part(EYE) + : makeplural(body_part(EYE))); + pline("%s resurrects!", Monnam(mon)); + } + mon->mhp = mon->mhpmax; + break; /* Out of while loop */ + } + if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) { + if (canseemon(mon)) { + hit(fltxt, mon, "."); + pline("%s absorbs the deadly %s!", Monnam(mon), + type == ZT_BREATH(ZT_DEATH) ? "blast" + : "ray"); + pline("It seems even stronger than before."); + } + break; /* Out of while loop */ + } - if (tmp == MAGIC_COOKIE) { /* disintegration */ - disintegrate_mon(mon, type, fltxt); - } else if(mon->mhp < 1) { - if(type < 0) - monkilled(mon, fltxt, AD_RBRE); - else - killed(mon); - } else { - if (!otmp) { - /* normal non-fatal hit */ - hit(fltxt, mon, exclam(tmp)); - } else { - /* some armor was destroyed; no damage done */ - if (canseemon(mon)) - pline("%s %s is disintegrated!", - s_suffix(Monnam(mon)), - distant_name(otmp, xname)); - m_useup(mon, otmp); - } - if (mon_could_move && !mon->mcanmove) /* ZT_SLEEP */ - slept_monst(mon); - } - } - range -= 2; - } else { - miss(fltxt,mon); - } - } else if (sx == u.ux && sy == u.uy && range >= 0) { - nomul(0); - if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *)0)) { - mon = u.usteed; - goto buzzmonst; - } else if (zap_hit((int) u.uac, 0)) { - range -= 2; - pline("%s hits you!", The(fltxt)); - if (Reflecting) { - if (!Blind) { - (void) ureflects("But %s reflects from your %s!", "it"); - } else - pline("For some reason you are not affected."); - dx = -dx; - dy = -dy; - shieldeff(sx, sy); - } else { - zhitu(type, nd, fltxt, sx, sy); - } - } else if (!Blind) { - pline("%s whizzes by you!", The(fltxt)); - } else if (abstype == ZT_LIGHTNING) { - Your("%s tingles.", body_part(ARM)); - } - if (abstype == ZT_LIGHTNING) (void) flashburn((long)d(nd,50)); - stop_occupation(); - nomul(0); - } + if (tmp == MAGIC_COOKIE) { /* disintegration */ + disintegrate_mon(mon, type, fltxt); + } else if (mon->mhp < 1) { + if (type < 0) + monkilled(mon, fltxt, AD_RBRE); + else + killed(mon); + } else { + if (!otmp) { + /* normal non-fatal hit */ + hit(fltxt, mon, exclam(tmp)); + } else { + /* some armor was destroyed; no damage done */ + if (canseemon(mon)) + pline("%s %s is disintegrated!", + s_suffix(Monnam(mon)), + distant_name(otmp, xname)); + m_useup(mon, otmp); + } + if (mon_could_move && !mon->mcanmove) /* ZT_SLEEP */ + slept_monst(mon); + } + } + range -= 2; + } else { + miss(fltxt, mon); + } + } else if (sx == u.ux && sy == u.uy && range >= 0) { + nomul(0); + if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *) 0)) { + mon = u.usteed; + goto buzzmonst; + } else if (zap_hit((int) u.uac, 0)) { + range -= 2; + pline("%s hits you!", The(fltxt)); + if (Reflecting) { + if (!Blind) { + (void) ureflects("But %s reflects from your %s!", + "it"); + } else + pline("For some reason you are not affected."); + dx = -dx; + dy = -dy; + shieldeff(sx, sy); + } else { + zhitu(type, nd, fltxt, sx, sy); + } + } else if (!Blind) { + pline("%s whizzes by you!", The(fltxt)); + } else if (abstype == ZT_LIGHTNING) { + Your("%s tingles.", body_part(ARM)); + } + if (abstype == ZT_LIGHTNING) + (void) flashburn((long) d(nd, 50)); + stop_occupation(); + nomul(0); + } - if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) { - int bounce; - uchar rmn; + if (!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) { + int bounce; + uchar rmn; - make_bounce: - if (type == ZT_SPELL(ZT_FIRE)) { - sx = lsx; - sy = lsy; - break; /* fireballs explode before the wall */ - } - bounce = 0; - range--; - if(range && isok(lsx, lsy) && cansee(lsx,lsy)) - pline("%s bounces!", The(fltxt)); - if(!dx || !dy || !rn2(20)) { - dx = -dx; - dy = -dy; - } else { - if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) && - !closed_door(sx,lsy) && - (IS_ROOM(rmn) || (isok(sx+dx,lsy) && - ZAP_POS(levl[sx+dx][lsy].typ)))) - bounce = 1; - if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) && - !closed_door(lsx,sy) && - (IS_ROOM(rmn) || (isok(lsx,sy+dy) && - ZAP_POS(levl[lsx][sy+dy].typ)))) - if(!bounce || rn2(2)) - bounce = 2; + make_bounce: + if (type == ZT_SPELL(ZT_FIRE)) { + sx = lsx; + sy = lsy; + break; /* fireballs explode before the wall */ + } + bounce = 0; + range--; + if (range && isok(lsx, lsy) && cansee(lsx, lsy)) + pline("%s bounces!", The(fltxt)); + if (!dx || !dy || !rn2(20)) { + dx = -dx; + dy = -dy; + } else { + if (isok(sx, lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) + && !closed_door(sx, lsy) + && (IS_ROOM(rmn) || (isok(sx + dx, lsy) + && ZAP_POS(levl[sx + dx][lsy].typ)))) + bounce = 1; + if (isok(lsx, sy) && ZAP_POS(rmn = levl[lsx][sy].typ) + && !closed_door(lsx, sy) + && (IS_ROOM(rmn) || (isok(lsx, sy + dy) + && ZAP_POS(levl[lsx][sy + dy].typ)))) + if (!bounce || rn2(2)) + bounce = 2; - switch(bounce) { - case 0: dx = -dx; /* fall into... */ - case 1: dy = -dy; break; - case 2: dx = -dx; break; - } - tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype)); - } - } + switch (bounce) { + case 0: + dx = -dx; /* fall into... */ + case 1: + dy = -dy; + break; + case 2: + dx = -dx; + break; + } + tmp_at(DISP_CHANGE, zapdir_to_glyph(dx, dy, abstype)); + } + } } - tmp_at(DISP_END,0); + tmp_at(DISP_END, 0); if (type == ZT_SPELL(ZT_FIRE)) - explode(sx, sy, type, d(12,6), 0, EXPL_FIERY); + explode(sx, sy, type, d(12, 6), 0, EXPL_FIERY); if (shopdamage) - pay_for_damage(abstype == ZT_FIRE ? "burn away" : - abstype == ZT_COLD ? "shatter" : - /* "damage" indicates wall rather than door */ - abstype == ZT_ACID ? "damage" : - abstype == ZT_DEATH ? "disintegrate" : "destroy", FALSE); + pay_for_damage( + abstype == ZT_FIRE + ? "burn away" + : abstype == ZT_COLD + ? "shatter" + : + /* "damage" indicates wall rather than door */ + abstype == ZT_ACID ? "damage" : abstype == ZT_DEATH + ? "disintegrate" + : "destroy", + FALSE); bhitpos = save_bhitpos; } @@ -3916,39 +4035,45 @@ melt_ice(x, y, msg) xchar x, y; const char *msg; { - struct rm *lev = &levl[x][y]; - struct obj *otmp; + struct rm *lev = &levl[x][y]; + struct obj *otmp; - if (!msg) msg = "The ice crackles and melts."; - if (lev->typ == DRAWBRIDGE_UP) - lev->drawbridgemask &= ~DB_ICE; /* revert to DB_MOAT */ - else { /* lev->typ == ICE */ + if (!msg) + msg = "The ice crackles and melts."; + if (lev->typ == DRAWBRIDGE_UP) + lev->drawbridgemask &= ~DB_ICE; /* revert to DB_MOAT */ + else { /* lev->typ == ICE */ #ifdef STUPID - if (lev->icedpool == ICED_POOL) lev->typ = POOL; - else lev->typ = MOAT; + if (lev->icedpool == ICED_POOL) + lev->typ = POOL; + else + lev->typ = MOAT; #else - lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT); + lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT); #endif - lev->icedpool = 0; - } - spot_stop_timers(x, y, MELT_ICE_AWAY); /* no more ice to melt away */ - obj_ice_effects(x, y, FALSE); - unearth_objs(x, y); - if (Underwater) vision_recalc(1); - newsym(x,y); - if (cansee(x,y)) Norep("%s", msg); - if ((otmp = sobj_at(BOULDER, x, y)) != 0) { - if (cansee(x,y)) pline("%s settles...", An(xname(otmp))); - do { - obj_extract_self(otmp); /* boulder isn't being pushed */ - if (!boulder_hits_pool(otmp, x, y, FALSE)) - impossible("melt_ice: no pool?"); - /* try again if there's another boulder and pool didn't fill */ - } while (is_pool(x,y) && (otmp = sobj_at(BOULDER, x, y)) != 0); - newsym(x,y); - } - if (x == u.ux && y == u.uy) - spoteffects(TRUE); /* possibly drown, notice objects */ + lev->icedpool = 0; + } + spot_stop_timers(x, y, MELT_ICE_AWAY); /* no more ice to melt away */ + obj_ice_effects(x, y, FALSE); + unearth_objs(x, y); + if (Underwater) + vision_recalc(1); + newsym(x, y); + if (cansee(x, y)) + Norep("%s", msg); + if ((otmp = sobj_at(BOULDER, x, y)) != 0) { + if (cansee(x, y)) + pline("%s settles...", An(xname(otmp))); + do { + obj_extract_self(otmp); /* boulder isn't being pushed */ + if (!boulder_hits_pool(otmp, x, y, FALSE)) + impossible("melt_ice: no pool?"); + /* try again if there's another boulder and pool didn't fill */ + } while (is_pool(x, y) && (otmp = sobj_at(BOULDER, x, y)) != 0); + newsym(x, y); + } + if (x == u.ux && y == u.uy) + spoteffects(TRUE); /* possibly drown, notice objects */ } #define MIN_ICE_TIME 50 @@ -3960,25 +4085,27 @@ const char *msg; void start_melt_ice_timeout(x, y, min_time) xchar x, y; -long min_time; /* 's old melt timeout (deleted by time we get here) */ +long min_time; /* 's old melt timeout (deleted by time we get here) */ { - int when; - long where; + int when; + long where; - when = (int)min_time; - if (when < MIN_ICE_TIME - 1) when = MIN_ICE_TIME - 1; + when = (int) min_time; + if (when < MIN_ICE_TIME - 1) + when = MIN_ICE_TIME - 1; - /* random timeout; surrounding ice locations ought to be a factor... */ - while (++when <= MAX_ICE_TIME) - if (!rn2((MAX_ICE_TIME - when) + MIN_ICE_TIME)) break; + /* random timeout; surrounding ice locations ought to be a factor... */ + while (++when <= MAX_ICE_TIME) + if (!rn2((MAX_ICE_TIME - when) + MIN_ICE_TIME)) + break; - /* if we're within MAX_ICE_TIME, install a melt timer; - otherwise, omit it to leave this ice permanent */ - if (when <= MAX_ICE_TIME) { - where = ((long)x << 16) | (long)y; - (void) start_timer((long)when, TIMER_LEVEL, - MELT_ICE_AWAY, long_to_any(where)); - } + /* if we're within MAX_ICE_TIME, install a melt timer; + otherwise, omit it to leave this ice permanent */ + if (when <= MAX_ICE_TIME) { + where = ((long) x << 16) | (long) y; + (void) start_timer((long) when, TIMER_LEVEL, MELT_ICE_AWAY, + long_to_any(where)); + } } #undef MIN_ICE_TIME #undef MAX_ICE_TIME @@ -3991,13 +4118,13 @@ melt_ice_away(arg, timeout) anything *arg; long timeout UNUSED; { - xchar x,y; - long where = arg->a_long; + xchar x, y; + long where = arg->a_long; - y = (xchar)(where & 0xFFFF); - x = (xchar)((where >> 16) & 0xFFFF); - /* melt_ice does newsym when appropriate */ - melt_ice(x,y,"Some ice melts away."); + y = (xchar)(where & 0xFFFF); + x = (xchar)((where >> 16) & 0xFFFF); + /* melt_ice does newsym when appropriate */ + melt_ice(x, y, "Some ice melts away."); } /* Burn floor scrolls, evaporate pools, etc... in a single square. Used @@ -4012,312 +4139,323 @@ int type; boolean *shopdamage; short exploding_wand_typ; { - const char *zapverb; - struct monst *mon; - struct trap *t; - struct rm *lev = &levl[x][y]; - boolean see_it = cansee(x, y), yourzap; - int rangemod = 0, abstype = abs(type) % 10; + const char *zapverb; + struct monst *mon; + struct trap *t; + struct rm *lev = &levl[x][y]; + boolean see_it = cansee(x, y), yourzap; + int rangemod = 0, abstype = abs(type) % 10; - switch (abstype) { - case ZT_FIRE: - t = t_at(x, y); - if (t && t->ttyp == WEB) { - /* a burning web is too flimsy to notice if you can't see it */ - if (see_it) Norep("A web bursts into flames!"); - (void) delfloortrap(t); - if (see_it) newsym(x,y); - } - if(is_ice(x, y)) { - melt_ice(x, y, (char *)0); - } else if(is_pool(x,y)) { - const char *msgtxt = "You hear hissing gas."; - if(lev->typ != POOL) { /* MOAT or DRAWBRIDGE_UP */ - if (see_it) msgtxt = "Some water evaporates."; - } else { - rangemod -= 3; - lev->typ = ROOM; - t = maketrap(x, y, PIT); - if (t) t->tseen = 1; - if (see_it) msgtxt = "The water evaporates."; - } - Norep("%s", msgtxt); - if (lev->typ == ROOM) newsym(x,y); - } else if(IS_FOUNTAIN(lev->typ)) { - if (see_it) - pline("Steam billows from the fountain."); - rangemod -= 1; - dryup(x, y, type > 0); - } - break; /* ZT_FIRE */ + switch (abstype) { + case ZT_FIRE: + t = t_at(x, y); + if (t && t->ttyp == WEB) { + /* a burning web is too flimsy to notice if you can't see it */ + if (see_it) + Norep("A web bursts into flames!"); + (void) delfloortrap(t); + if (see_it) + newsym(x, y); + } + if (is_ice(x, y)) { + melt_ice(x, y, (char *) 0); + } else if (is_pool(x, y)) { + const char *msgtxt = "You hear hissing gas."; + if (lev->typ != POOL) { /* MOAT or DRAWBRIDGE_UP */ + if (see_it) + msgtxt = "Some water evaporates."; + } else { + rangemod -= 3; + lev->typ = ROOM; + t = maketrap(x, y, PIT); + if (t) + t->tseen = 1; + if (see_it) + msgtxt = "The water evaporates."; + } + Norep("%s", msgtxt); + if (lev->typ == ROOM) + newsym(x, y); + } else if (IS_FOUNTAIN(lev->typ)) { + if (see_it) + pline("Steam billows from the fountain."); + rangemod -= 1; + dryup(x, y, type > 0); + } + break; /* ZT_FIRE */ - case ZT_COLD: - if (is_pool(x,y) || is_lava(x,y)) { - boolean lava = is_lava(x,y); - boolean moat = is_moat(x,y); + case ZT_COLD: + if (is_pool(x, y) || is_lava(x, y)) { + boolean lava = is_lava(x, y); + boolean moat = is_moat(x, y); - if (lev->typ == WATER) { - /* For now, don't let WATER freeze. */ - if (see_it) - pline_The("water freezes for a moment."); - else - You_hear("a soft crackling."); - rangemod -= 1000; /* stop */ - } else { - rangemod -= 3; - if (lev->typ == DRAWBRIDGE_UP) { - lev->drawbridgemask &= ~DB_UNDER; /* clear lava */ - lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE); - } else { - if (!lava) - lev->icedpool = - (lev->typ == POOL ? ICED_POOL : ICED_MOAT); - lev->typ = (lava ? ROOM : ICE); - } - bury_objs(x,y); - if (see_it) { - if(lava) - Norep("The lava cools and solidifies."); - else if(moat) - Norep("The %s is bridged with ice!", - waterbody_name(x,y)); - else - Norep("The water freezes."); - newsym(x,y); - } else if(!lava) - You_hear("a crackling sound."); + if (lev->typ == WATER) { + /* For now, don't let WATER freeze. */ + if (see_it) + pline_The("water freezes for a moment."); + else + You_hear("a soft crackling."); + rangemod -= 1000; /* stop */ + } else { + rangemod -= 3; + if (lev->typ == DRAWBRIDGE_UP) { + lev->drawbridgemask &= ~DB_UNDER; /* clear lava */ + lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE); + } else { + if (!lava) + lev->icedpool = + (lev->typ == POOL ? ICED_POOL : ICED_MOAT); + lev->typ = (lava ? ROOM : ICE); + } + bury_objs(x, y); + if (see_it) { + if (lava) + Norep("The lava cools and solidifies."); + else if (moat) + Norep("The %s is bridged with ice!", + waterbody_name(x, y)); + else + Norep("The water freezes."); + newsym(x, y); + } else if (!lava) + You_hear("a crackling sound."); - if (x == u.ux && y == u.uy) { - if (u.uinwater) { /* not just `if (Underwater)' */ - /* leave the no longer existent water */ - u.uinwater = 0; - u.uundetected = 0; - docrt(); - vision_full_recalc = 1; - } else if (u.utrap && u.utraptype == TT_LAVA) { - if (Passes_walls) { - u.utrap = 0; - You("pass through the now-solid rock."); - } else { - u.utrap = rn1(50,20); - u.utraptype = TT_INFLOOR; - You("are firmly stuck in the cooling rock."); - } - } - } else if ((mon = m_at(x,y)) != 0) { - /* probably ought to do some hefty damage to any - non-ice creature caught in freezing water; - at a minimum, eels are forced out of hiding */ - if (is_swimmer(mon->data) && mon->mundetected) { - mon->mundetected = 0; - newsym(x,y); - } - } - if (!lava) { - start_melt_ice_timeout(x, y, 0L); - obj_ice_effects(x,y,TRUE); - } - } /* ?WATER */ + if (x == u.ux && y == u.uy) { + if (u.uinwater) { /* not just `if (Underwater)' */ + /* leave the no longer existent water */ + u.uinwater = 0; + u.uundetected = 0; + docrt(); + vision_full_recalc = 1; + } else if (u.utrap && u.utraptype == TT_LAVA) { + if (Passes_walls) { + u.utrap = 0; + You("pass through the now-solid rock."); + } else { + u.utrap = rn1(50, 20); + u.utraptype = TT_INFLOOR; + You("are firmly stuck in the cooling rock."); + } + } + } else if ((mon = m_at(x, y)) != 0) { + /* probably ought to do some hefty damage to any + non-ice creature caught in freezing water; + at a minimum, eels are forced out of hiding */ + if (is_swimmer(mon->data) && mon->mundetected) { + mon->mundetected = 0; + newsym(x, y); + } + } + if (!lava) { + start_melt_ice_timeout(x, y, 0L); + obj_ice_effects(x, y, TRUE); + } + } /* ?WATER */ - } else if (is_ice(x, y)) { - long melt_time; + } else if (is_ice(x, y)) { + long melt_time; - /* Already ice here, so just firm it up. */ - /* Now ensure that only ice that is already timed is affected */ - if ((melt_time = spot_time_left(x, y, MELT_ICE_AWAY)) != 0L) { - spot_stop_timers(x, y, MELT_ICE_AWAY); - start_melt_ice_timeout(x, y, melt_time); - } - } - break; /* ZT_COLD */ + /* Already ice here, so just firm it up. */ + /* Now ensure that only ice that is already timed is affected */ + if ((melt_time = spot_time_left(x, y, MELT_ICE_AWAY)) != 0L) { + spot_stop_timers(x, y, MELT_ICE_AWAY); + start_melt_ice_timeout(x, y, melt_time); + } + } + break; /* ZT_COLD */ - case ZT_ACID: - if (lev->typ == IRONBARS) { - if ((lev->wall_info & W_NONDIGGABLE) != 0) { - if (see_it) - Norep("The %s corrode somewhat but remain intact.", - defsyms[S_bars].explanation); - /* but nothing actually happens... */ - } else { - rangemod -= 3; - if (see_it) - Norep("The %s melt.", defsyms[S_bars].explanation); - if (*in_rooms(x, y, SHOPBASE)) { - /* in case we ever have a shop bounded by bars */ - lev->typ = ROOM; - if (see_it) newsym(x, y); - add_damage(x, y, (type >= 0) ? 300L : 0L); - if (type >= 0) *shopdamage = TRUE; - } else { - lev->typ = DOOR; - lev->doormask = D_NODOOR; - if (see_it) newsym(x, y); - } - } - } - break; /* ZT_ACID */ + case ZT_ACID: + if (lev->typ == IRONBARS) { + if ((lev->wall_info & W_NONDIGGABLE) != 0) { + if (see_it) + Norep("The %s corrode somewhat but remain intact.", + defsyms[S_bars].explanation); + /* but nothing actually happens... */ + } else { + rangemod -= 3; + if (see_it) + Norep("The %s melt.", defsyms[S_bars].explanation); + if (*in_rooms(x, y, SHOPBASE)) { + /* in case we ever have a shop bounded by bars */ + lev->typ = ROOM; + if (see_it) + newsym(x, y); + add_damage(x, y, (type >= 0) ? 300L : 0L); + if (type >= 0) + *shopdamage = TRUE; + } else { + lev->typ = DOOR; + lev->doormask = D_NODOOR; + if (see_it) + newsym(x, y); + } + } + } + break; /* ZT_ACID */ - default: - break; - } + default: + break; + } - /* set up zap text for possible door feedback; for exploding wand, we - want "the blast" rather than "your blast" even if hero caused it */ - yourzap = (type >= 0 && !exploding_wand_typ); - zapverb = "blast"; /* breath attack or wand explosion */ - if (!exploding_wand_typ) { - if (abs(type) < ZT_SPELL(0)) zapverb = "bolt"; /* wand zap */ - else if (abs(type) < ZT_BREATH(0)) zapverb = "spell"; - } + /* set up zap text for possible door feedback; for exploding wand, we + want "the blast" rather than "your blast" even if hero caused it */ + yourzap = (type >= 0 && !exploding_wand_typ); + zapverb = "blast"; /* breath attack or wand explosion */ + if (!exploding_wand_typ) { + if (abs(type) < ZT_SPELL(0)) + zapverb = "bolt"; /* wand zap */ + else if (abs(type) < ZT_BREATH(0)) + zapverb = "spell"; + } - /* secret door gets revealed, converted into regular door */ - if (levl[x][y].typ == SDOOR) { - cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ - /* target spot will now pass closed_door() test below - (except on rogue level) */ - newsym(x, y); - if (see_it) - pline("%s %s reveals a secret door.", - yourzap ? "Your" : "The", zapverb); - else if (Is_rogue_level(&u.uz)) - You_feel("a draft."); /* new open doorway */ - } + /* secret door gets revealed, converted into regular door */ + if (levl[x][y].typ == SDOOR) { + cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ + /* target spot will now pass closed_door() test below + (except on rogue level) */ + newsym(x, y); + if (see_it) + pline("%s %s reveals a secret door.", yourzap ? "Your" : "The", + zapverb); + else if (Is_rogue_level(&u.uz)) + You_feel("a draft."); /* new open doorway */ + } - /* regular door absorbs remaining zap range, possibly gets destroyed */ - if(closed_door(x, y)) { - int new_doormask = -1; - const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0; - rangemod = -1000; - switch(abstype) { - case ZT_FIRE: - new_doormask = D_NODOOR; - see_txt = "The door is consumed in flames!"; - sense_txt = "smell smoke."; - break; - case ZT_COLD: - new_doormask = D_NODOOR; - see_txt = "The door freezes and shatters!"; - sense_txt = "feel cold."; - break; - case ZT_DEATH: - /* death spells/wands don't disintegrate */ - if(abs(type) != ZT_BREATH(ZT_DEATH)) - goto def_case; - new_doormask = D_NODOOR; - see_txt = "The door disintegrates!"; - hear_txt = "crashing wood."; - break; - case ZT_LIGHTNING: - new_doormask = D_BROKEN; - see_txt = "The door splinters!"; - hear_txt = "crackling."; - break; - default: - def_case: - if (exploding_wand_typ > 0) { - /* Magical explosion from misc exploding wand */ - if (exploding_wand_typ == WAN_STRIKING) { - new_doormask = D_BROKEN; - see_txt = "The door crashes open!"; - sense_txt = "feel a burst of cool air."; - break; - } - } - if (see_it) { - /* "the door absorbs the blast" would be - inaccurate for an exploding wand since - other adjacent locations still get hit */ - if (exploding_wand_typ) - pline_The("door remains intact."); - else - pline_The("door absorbs %s %s!", - yourzap ? "your" : "the", zapverb); - } else - You_feel("vibrations."); - break; - } - if (new_doormask >= 0) { /* door gets broken */ - if (*in_rooms(x, y, SHOPBASE)) { - if (type >= 0) { - add_damage(x, y, 400L); - *shopdamage = TRUE; - } else /* caused by monster */ - add_damage(x, y, 0L); - } - lev->doormask = new_doormask; - unblock_point(x, y); /* vision */ - if (see_it) { - pline1(see_txt); - newsym(x, y); - } else if (sense_txt) { - You1(sense_txt); - } else if (hear_txt) - You_hear1(hear_txt); - if (picking_at(x, y)) { - stop_occupation(); - reset_pick(); - } - } - } + /* regular door absorbs remaining zap range, possibly gets destroyed */ + if (closed_door(x, y)) { + int new_doormask = -1; + const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0; + rangemod = -1000; + switch (abstype) { + case ZT_FIRE: + new_doormask = D_NODOOR; + see_txt = "The door is consumed in flames!"; + sense_txt = "smell smoke."; + break; + case ZT_COLD: + new_doormask = D_NODOOR; + see_txt = "The door freezes and shatters!"; + sense_txt = "feel cold."; + break; + case ZT_DEATH: + /* death spells/wands don't disintegrate */ + if (abs(type) != ZT_BREATH(ZT_DEATH)) + goto def_case; + new_doormask = D_NODOOR; + see_txt = "The door disintegrates!"; + hear_txt = "crashing wood."; + break; + case ZT_LIGHTNING: + new_doormask = D_BROKEN; + see_txt = "The door splinters!"; + hear_txt = "crackling."; + break; + default: + def_case: + if (exploding_wand_typ > 0) { + /* Magical explosion from misc exploding wand */ + if (exploding_wand_typ == WAN_STRIKING) { + new_doormask = D_BROKEN; + see_txt = "The door crashes open!"; + sense_txt = "feel a burst of cool air."; + break; + } + } + if (see_it) { + /* "the door absorbs the blast" would be + inaccurate for an exploding wand since + other adjacent locations still get hit */ + if (exploding_wand_typ) + pline_The("door remains intact."); + else + pline_The("door absorbs %s %s!", yourzap ? "your" : "the", + zapverb); + } else + You_feel("vibrations."); + break; + } + if (new_doormask >= 0) { /* door gets broken */ + if (*in_rooms(x, y, SHOPBASE)) { + if (type >= 0) { + add_damage(x, y, 400L); + *shopdamage = TRUE; + } else /* caused by monster */ + add_damage(x, y, 0L); + } + lev->doormask = new_doormask; + unblock_point(x, y); /* vision */ + if (see_it) { + pline1(see_txt); + newsym(x, y); + } else if (sense_txt) { + You1(sense_txt); + } else if (hear_txt) + You_hear1(hear_txt); + if (picking_at(x, y)) { + stop_occupation(); + reset_pick(); + } + } + } - if(OBJ_AT(x, y) && abstype == ZT_FIRE) - if (burn_floor_objects(x, y, FALSE, type > 0) && couldsee(x, y)) { - newsym(x,y); - You("%s of smoke.", - !Blind ? "see a puff" : "smell a whiff"); - } - if ((mon = m_at(x,y)) != 0) { - /* Cannot use wakeup() which also angers the monster */ - mon->msleeping = 0; - if(mon->m_ap_type) seemimic(mon); - if(type >= 0) { - setmangry(mon); - if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE)) - ghod_hitsu(mon); - if(mon->isshk && !*u.ushops) - hot_pursuit(mon); - } - } - return rangemod; + if (OBJ_AT(x, y) && abstype == ZT_FIRE) + if (burn_floor_objects(x, y, FALSE, type > 0) && couldsee(x, y)) { + newsym(x, y); + You("%s of smoke.", !Blind ? "see a puff" : "smell a whiff"); + } + if ((mon = m_at(x, y)) != 0) { + /* Cannot use wakeup() which also angers the monster */ + mon->msleeping = 0; + if (mon->m_ap_type) + seemimic(mon); + if (type >= 0) { + setmangry(mon); + if (mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE)) + ghod_hitsu(mon); + if (mon->isshk && !*u.ushops) + hot_pursuit(mon); + } + } + return rangemod; } -void -fracture_rock(obj) /* fractured by pick-axe or wand of striking */ -register struct obj *obj; /* no texts here! */ +void fracture_rock(obj) /* fractured by pick-axe or wand of striking */ +register struct obj *obj; /* no texts here! */ { - xchar x, y; - boolean by_you = !context.mon_moving; + xchar x, y; + boolean by_you = !context.mon_moving; - if (by_you && get_obj_location(obj, &x, &y, 0) && costly_spot(x, y)) { - struct monst *shkp = 0; - char objroom = *in_rooms(x, y, SHOPBASE); + if (by_you && get_obj_location(obj, &x, &y, 0) && costly_spot(x, y)) { + struct monst *shkp = 0; + char objroom = *in_rooms(x, y, SHOPBASE); - if (billable(&shkp, obj, objroom, FALSE)) { - /* shop message says "you owe <$> for it!" so we need - to precede that with a message explaining what "it" is */ - You("fracture %s %s.", s_suffix(shkname(shkp)), xname(obj)); - breakobj(obj, x, y, TRUE, FALSE); /* charges for shop goods */ - } - } - if (by_you && obj->otyp == BOULDER) - sokoban_guilt(); + if (billable(&shkp, obj, objroom, FALSE)) { + /* shop message says "you owe <$> for it!" so we need + to precede that with a message explaining what "it" is */ + You("fracture %s %s.", s_suffix(shkname(shkp)), xname(obj)); + breakobj(obj, x, y, TRUE, FALSE); /* charges for shop goods */ + } + } + if (by_you && obj->otyp == BOULDER) + sokoban_guilt(); - obj->otyp = ROCK; - obj->oclass = GEM_CLASS; - obj->quan = (long) rn1(60, 7); - obj->owt = weight(obj); - obj->dknown = obj->bknown = obj->rknown = 0; - obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1; - if (obj->oextra) dealloc_oextra(obj->oextra); - obj->oextra = (struct oextra *)0; - if (obj->where == OBJ_FLOOR) { - obj_extract_self(obj); /* move rocks back on top */ - place_object(obj, obj->ox, obj->oy); - if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy])) - unblock_point(obj->ox,obj->oy); - if(cansee(obj->ox,obj->oy)) - newsym(obj->ox,obj->oy); - } + obj->otyp = ROCK; + obj->oclass = GEM_CLASS; + obj->quan = (long) rn1(60, 7); + obj->owt = weight(obj); + obj->dknown = obj->bknown = obj->rknown = 0; + obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1; + if (obj->oextra) + dealloc_oextra(obj->oextra); + obj->oextra = (struct oextra *) 0; + if (obj->where == OBJ_FLOOR) { + obj_extract_self(obj); /* move rocks back on top */ + place_object(obj, obj->ox, obj->oy); + if (!does_block(obj->ox, obj->oy, &levl[obj->ox][obj->oy])) + unblock_point(obj->ox, obj->oy); + if (cansee(obj->ox, obj->oy)) + newsym(obj->ox, obj->oy); + } } /* handle statue hit by striking/force bolt/pick-axe */ @@ -4325,26 +4463,26 @@ boolean break_statue(obj) register struct obj *obj; { - /* [obj is assumed to be on floor, so no get_obj_location() needed] */ - struct trap *trap = t_at(obj->ox, obj->oy); - struct obj *item; - boolean by_you = !context.mon_moving; + /* [obj is assumed to be on floor, so no get_obj_location() needed] */ + struct trap *trap = t_at(obj->ox, obj->oy); + struct obj *item; + boolean by_you = !context.mon_moving; - if (trap && trap->ttyp == STATUE_TRAP && - activate_statue_trap(trap, obj->ox, obj->oy, TRUE)) - return FALSE; - /* drop any objects contained inside the statue */ - while ((item = obj->cobj) != 0) { - obj_extract_self(item); - place_object(item, obj->ox, obj->oy); - } - if (by_you && Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) { - You_feel("guilty about damaging such a historic statue."); - adjalign(-1); - } - obj->spe = 0; - fracture_rock(obj); - return TRUE; + if (trap && trap->ttyp == STATUE_TRAP + && activate_statue_trap(trap, obj->ox, obj->oy, TRUE)) + return FALSE; + /* drop any objects contained inside the statue */ + while ((item = obj->cobj) != 0) { + obj_extract_self(item); + place_object(item, obj->ox, obj->oy); + } + if (by_you && Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) { + You_feel("guilty about damaging such a historic statue."); + adjalign(-1); + } + obj->spe = 0; + fracture_rock(obj); + return TRUE; } /* @@ -4359,7 +4497,8 @@ register struct obj *obj; * (books, rings, and wands don't stack so don't need plural form; * crumbling ring doesn't do damage so doesn't need killer reason) */ -const char * const destroy_strings[][3] = { /* also used in trap.c */ +const char *const destroy_strings[][3] = { + /* also used in trap.c */ { "freezes and shatters", "freeze and shatter", "shattered potion" }, { "boils and explodes", "boil and explode", "boiling potion" }, { "ignites and explodes", "ignite and explode", "exploding potion" }, @@ -4371,7 +4510,7 @@ const char * const destroy_strings[][3] = { /* also used in trap.c */ void destroy_item(osym, dmgtyp) - register int osym, dmgtyp; +register int osym, dmgtyp; { register struct obj *obj, *obj2; register int dmg, xresist, skip; @@ -4380,101 +4519,115 @@ destroy_item(osym, dmgtyp) const char *mult; boolean physical_damage; - for(obj = invent; obj; obj = obj2) { + for (obj = invent; obj; obj = obj2) { obj2 = obj->nobj; physical_damage = FALSE; - if(obj->oclass != osym) continue; /* test only objs of type osym */ - if(obj->oartifact) continue; /* don't destroy artifacts */ - if(obj->in_use && obj->quan == 1L) continue; /* not available */ + if (obj->oclass != osym) + continue; /* test only objs of type osym */ + if (obj->oartifact) + continue; /* don't destroy artifacts */ + if (obj->in_use && obj->quan == 1L) + continue; /* not available */ xresist = skip = 0; /* lint suppression */ dmg = dindx = 0; quan = 0L; - switch(dmgtyp) { - case AD_COLD: - if(osym == POTION_CLASS && obj->otyp != POT_OIL) { - quan = obj->quan; - dindx = 0; - dmg = rnd(4); - } else skip++; - break; - case AD_FIRE: - xresist = (Fire_resistance - && obj->oclass != POTION_CLASS - && obj->otyp != GLOB_OF_GREEN_SLIME); + switch (dmgtyp) { + case AD_COLD: + if (osym == POTION_CLASS && obj->otyp != POT_OIL) { + quan = obj->quan; + dindx = 0; + dmg = rnd(4); + } else + skip++; + break; + case AD_FIRE: + xresist = (Fire_resistance && obj->oclass != POTION_CLASS + && obj->otyp != GLOB_OF_GREEN_SLIME); - if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) - skip++; - if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - skip++; - if (!Blind) - pline("%s glows a strange %s, but remains intact.", - The(xname(obj)), hcolor("dark red")); - } - quan = obj->quan; - switch(osym) { - case POTION_CLASS: - dindx = (obj->otyp != POT_OIL) ? 1 : 2; - dmg = rnd(6); - break; - case SCROLL_CLASS: - dindx = 3; - dmg = 1; - break; - case SPBOOK_CLASS: - dindx = 4; - dmg = 1; - break; - case FOOD_CLASS: - if (obj->otyp == GLOB_OF_GREEN_SLIME) { - dindx = obj->owt / 20; - dmg = 1; - } else { skip++; } - break; - default: - skip++; - break; - } + if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) + skip++; + if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { + skip++; + if (!Blind) + pline("%s glows a strange %s, but remains intact.", + The(xname(obj)), hcolor("dark red")); + } + quan = obj->quan; + switch (osym) { + case POTION_CLASS: + dindx = (obj->otyp != POT_OIL) ? 1 : 2; + dmg = rnd(6); break; - case AD_ELEC: - xresist = (Shock_resistance && obj->oclass != RING_CLASS); - quan = obj->quan; - switch(osym) { - case RING_CLASS: - if(obj->otyp == RIN_SHOCK_RESISTANCE) - { skip++; break; } - dindx = 5; - dmg = 0; - break; - case WAND_CLASS: - if(obj->otyp == WAN_LIGHTNING) { skip++; break; } -#if 0 - if (obj == current_wand) { skip++; break; } -#endif - dindx = 6; - dmg = rnd(10); - break; - default: - skip++; - break; + case SCROLL_CLASS: + dindx = 3; + dmg = 1; + break; + case SPBOOK_CLASS: + dindx = 4; + dmg = 1; + break; + case FOOD_CLASS: + if (obj->otyp == GLOB_OF_GREEN_SLIME) { + dindx = obj->owt / 20; + dmg = 1; + } else { + skip++; } break; default: skip++; break; + } + break; + case AD_ELEC: + xresist = (Shock_resistance && obj->oclass != RING_CLASS); + quan = obj->quan; + switch (osym) { + case RING_CLASS: + if (obj->otyp == RIN_SHOCK_RESISTANCE) { + skip++; + break; + } + dindx = 5; + dmg = 0; + break; + case WAND_CLASS: + if (obj->otyp == WAN_LIGHTNING) { + skip++; + break; + } +#if 0 + if (obj == current_wand) { skip++; break; } +#endif + dindx = 6; + dmg = rnd(10); + break; + default: + skip++; + break; + } + break; + default: + skip++; + break; } - if(!skip) { - if (obj->in_use) --quan; /* one will be used up elsewhere */ - for(i = cnt = 0L; i < quan; i++) - if(!rn2(3)) cnt++; + if (!skip) { + if (obj->in_use) + --quan; /* one will be used up elsewhere */ + for (i = cnt = 0L; i < quan; i++) + if (!rn2(3)) + cnt++; - if(!cnt) continue; - mult = (cnt == quan) ? (quan > 1) ? "All of your " : "Your" : - (cnt == 1L) ? "One of your" : "Some of your"; + if (!cnt) + continue; + mult = (cnt == quan) + ? (quan > 1) ? "All of your " : "Your" + : (cnt == 1L) ? "One of your" : "Some of your"; pline("%s %s %s!", mult, xname(obj), - destroy_strings[dindx][(cnt > 1L)]); - if(osym == POTION_CLASS && dmgtyp != AD_COLD) { + destroy_strings[dindx][(cnt > 1L)]); + if (osym == POTION_CLASS && dmgtyp != AD_COLD) { if (!breathless(youmonst.data) || haseyes(youmonst.data)) potionbreathe(obj); } @@ -4484,18 +4637,21 @@ destroy_item(osym, dmgtyp) else setnotworn(obj); } - if (obj == current_wand) current_wand = 0; /* destroyed */ + if (obj == current_wand) + current_wand = 0; /* destroyed */ for (i = 0; i < cnt; i++) useup(obj); - if(dmg) { - if(xresist) You("aren't hurt!"); + if (dmg) { + if (xresist) + You("aren't hurt!"); else { const char *how = destroy_strings[dindx][2]; boolean one = (cnt == 1L); - if (physical_damage) dmg = Maybe_Half_Phys(dmg); - losehp(dmg, one ? how : (const char *)makeplural(how), - one ? KILLED_BY_AN : KILLED_BY); + if (physical_damage) + dmg = Maybe_Half_Phys(dmg); + losehp(dmg, one ? how : (const char *) makeplural(how), + one ? KILLED_BY_AN : KILLED_BY); exercise(A_STR, FALSE); } } @@ -4509,104 +4665,116 @@ destroy_mitem(mtmp, osym, dmgtyp) struct monst *mtmp; int osym, dmgtyp; { - struct obj *obj, *obj2; - int skip, tmp = 0; - long i, cnt, quan; - int dindx; - boolean vis; + struct obj *obj, *obj2; + int skip, tmp = 0; + long i, cnt, quan; + int dindx; + boolean vis; - if (mtmp == &youmonst) { /* this simplifies artifact_hit() */ - destroy_item(osym, dmgtyp); - return 0; /* arbitrary; value doesn't matter to artifact_hit() */ - } + if (mtmp == &youmonst) { /* this simplifies artifact_hit() */ + destroy_item(osym, dmgtyp); + return 0; /* arbitrary; value doesn't matter to artifact_hit() */ + } - vis = canseemon(mtmp); - for(obj = mtmp->minvent; obj; obj = obj2) { - obj2 = obj->nobj; - if(obj->oclass != osym) continue; /* test only objs of type osym */ - skip = 0; - quan = 0L; - dindx = 0; + vis = canseemon(mtmp); + for (obj = mtmp->minvent; obj; obj = obj2) { + obj2 = obj->nobj; + if (obj->oclass != osym) + continue; /* test only objs of type osym */ + skip = 0; + quan = 0L; + dindx = 0; - switch(dmgtyp) { - case AD_COLD: - if(osym == POTION_CLASS && obj->otyp != POT_OIL) { - quan = obj->quan; - dindx = 0; - tmp++; - } else skip++; - break; - case AD_FIRE: - if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) - skip++; - if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { - skip++; - if (vis) - pline("%s glows a strange %s, but remains intact.", - The(distant_name(obj, xname)), - hcolor("dark red")); - } - quan = obj->quan; - switch(osym) { - case POTION_CLASS: - dindx = (obj->otyp != POT_OIL) ? 1 : 2; - tmp++; - break; - case SCROLL_CLASS: - dindx = 3; - tmp++; - break; - case SPBOOK_CLASS: - dindx = 4; - tmp++; - break; + switch (dmgtyp) { + case AD_COLD: + if (osym == POTION_CLASS && obj->otyp != POT_OIL) { + quan = obj->quan; + dindx = 0; + tmp++; + } else + skip++; + break; + case AD_FIRE: + if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) + skip++; + if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { + skip++; + if (vis) + pline("%s glows a strange %s, but remains intact.", + The(distant_name(obj, xname)), hcolor("dark red")); + } + quan = obj->quan; + switch (osym) { + case POTION_CLASS: + dindx = (obj->otyp != POT_OIL) ? 1 : 2; + tmp++; + break; + case SCROLL_CLASS: + dindx = 3; + tmp++; + break; + case SPBOOK_CLASS: + dindx = 4; + tmp++; + break; case FOOD_CLASS: if (obj->otyp == GLOB_OF_GREEN_SLIME) { dindx = obj->owt / 20; tmp++; - } else { skip++; } + } else { + skip++; + } break; - default: - skip++; - break; - } - break; - case AD_ELEC: - quan = obj->quan; - switch(osym) { - case RING_CLASS: - if(obj->otyp == RIN_SHOCK_RESISTANCE) - { skip++; break; } - dindx = 5; - break; - case WAND_CLASS: - if(obj->otyp == WAN_LIGHTNING) { skip++; break; } - dindx = 6; - tmp++; - break; - default: - skip++; - break; - } - break; - default: - skip++; - break; - } - if(!skip) { - for(i = cnt = 0L; i < quan; i++) - if(!rn2(3)) cnt++; + default: + skip++; + break; + } + break; + case AD_ELEC: + quan = obj->quan; + switch (osym) { + case RING_CLASS: + if (obj->otyp == RIN_SHOCK_RESISTANCE) { + skip++; + break; + } + dindx = 5; + break; + case WAND_CLASS: + if (obj->otyp == WAN_LIGHTNING) { + skip++; + break; + } + dindx = 6; + tmp++; + break; + default: + skip++; + break; + } + break; + default: + skip++; + break; + } + if (!skip) { + for (i = cnt = 0L; i < quan; i++) + if (!rn2(3)) + cnt++; - if(!cnt) continue; - if (vis) pline("%s%s %s!", - (cnt == obj->quan) ? "" : - (cnt > 1L) ? "Some of " : "One of ", - (cnt == obj->quan) ? Yname2(obj) : yname(obj), - destroy_strings[dindx][(cnt > 1L)]); - for(i = 0; i < cnt; i++) m_useup(mtmp, obj); - } - } - return(tmp); + if (!cnt) + continue; + if (vis) + pline("%s%s %s!", + (cnt == obj->quan) ? "" : (cnt > 1L) ? "Some of " + : "One of ", + (cnt == obj->quan) ? Yname2(obj) : yname(obj), + destroy_strings[dindx][(cnt > 1L)]); + for (i = 0; i < cnt; i++) + m_useup(mtmp, obj); + } + } + return (tmp); } int @@ -4615,41 +4783,59 @@ struct monst *mtmp; char oclass; int damage, tell; { - int resisted; - int alev, dlev; + int resisted; + int alev, dlev; - /* attack level */ - switch (oclass) { - case WAND_CLASS: alev = 12; break; - case TOOL_CLASS: alev = 10; break; /* instrument */ - case WEAPON_CLASS: alev = 10; break; /* artifact */ - case SCROLL_CLASS: alev = 9; break; - case POTION_CLASS: alev = 6; break; - case RING_CLASS: alev = 5; break; - default: alev = u.ulevel; break; /* spell */ - } - /* defense level */ - dlev = (int)mtmp->m_lev; - if (dlev > 50) dlev = 50; - else if (dlev < 1) dlev = is_mplayer(mtmp->data) ? u.ulevel : 1; + /* attack level */ + switch (oclass) { + case WAND_CLASS: + alev = 12; + break; + case TOOL_CLASS: + alev = 10; + break; /* instrument */ + case WEAPON_CLASS: + alev = 10; + break; /* artifact */ + case SCROLL_CLASS: + alev = 9; + break; + case POTION_CLASS: + alev = 6; + break; + case RING_CLASS: + alev = 5; + break; + default: + alev = u.ulevel; + break; /* spell */ + } + /* defense level */ + dlev = (int) mtmp->m_lev; + if (dlev > 50) + dlev = 50; + else if (dlev < 1) + dlev = is_mplayer(mtmp->data) ? u.ulevel : 1; - resisted = rn2(100 + alev - dlev) < mtmp->data->mr; - if (resisted) { - if (tell) { - shieldeff(mtmp->mx, mtmp->my); - pline("%s resists!", Monnam(mtmp)); - } - damage = (damage + 1) / 2; - } + resisted = rn2(100 + alev - dlev) < mtmp->data->mr; + if (resisted) { + if (tell) { + shieldeff(mtmp->mx, mtmp->my); + pline("%s resists!", Monnam(mtmp)); + } + damage = (damage + 1) / 2; + } - if (damage) { - mtmp->mhp -= damage; - if (mtmp->mhp < 1) { - if(m_using) monkilled(mtmp, "", AD_RBRE); - else killed(mtmp); - } - } - return(resisted); + if (damage) { + mtmp->mhp -= damage; + if (mtmp->mhp < 1) { + if (m_using) + monkilled(mtmp, "", AD_RBRE); + else + killed(mtmp); + } + } + return (resisted); } #define MAXWISHTRY 5 @@ -4658,118 +4844,125 @@ STATIC_OVL void wishcmdassist(triesleft) int triesleft; { - static NEARDATA const char *wishinfo[] = { - "Wish details:", - "", - "Enter the name of an object, such as \"potion of monster detection\",", - "\"scroll labeled README\", \"elven mithril-coat\", or \"Grimtooth\"", - "(without the quotes).", - "", - "For object types which come in stacks, you may specify a plural name", - "such as \"potions of healing\", or specify a count, such as \"1000 gold", - "pieces\", although that aspect of your wish might not be granted.", - "", - "You may also specify various prefix values which might be used to", - "modify the item, such as \"uncursed\" or \"rustproof\" or \"+1\".", - "Most modifiers shown when viewing your inventory can be specified.", - "", - "You may specify 'nothing' to explicitly decline this wish.", - 0, - }, - preserve_wishless[] = "Doing so will preserve 'wishless' conduct.", - retry_info[] = - "If you specify an unrecognized object name %s%s time%s,", - retry_too[] = "a randomly chosen item will be granted.", - suppress_cmdassist[] = - "(Suppress this assistance with !cmdassist in your config file.)", - *cardinals[] = { "zero", "one", "two", "three", "four", "five" }, - too_many[] = "too many"; - int i; - winid win; - char buf[BUFSZ]; + static NEARDATA const char *wishinfo[] = + { + "Wish details:", "", "Enter the name of an object, such as " + "\"potion of monster detection\",", + "\"scroll labeled README\", \"elven mithril-coat\", or " + "\"Grimtooth\"", + "(without the quotes).", "", "For object types which come in " + "stacks, you may specify a plural " + "name", + "such as \"potions of healing\", or specify a count, such as " + "\"1000 gold", + "pieces\", although that aspect of your wish might not be granted.", + "", + "You may also specify various prefix values which might be used to", + "modify the item, such as \"uncursed\" or \"rustproof\" or \"+1\".", + "Most modifiers shown when viewing your inventory can be " + "specified.", + "", "You may specify 'nothing' to explicitly decline this wish.", 0, + }, + preserve_wishless[] = "Doing so will preserve " + "'wishless' conduct.", + retry_info[] = "If you specify an " + "unrecognized object name %s%s " + "time%s,", + retry_too[] = + "a randomly chosen item will be granted.", + suppress_cmdassist[] = + "(Suppress this assistance with " + "!cmdassist in your config file.)", + *cardinals[] = { "zero", "one", "two", + "three", "four", "five" }, + too_many[] = "too many"; + int i; + winid win; + char buf[BUFSZ]; - win = create_nhwindow(NHW_TEXT); - if (!win) return; - for (i = 0; i < SIZE(wishinfo) - 1; ++i) - putstr(win, 0, wishinfo[i]); - if (!u.uconduct.wishes) - putstr(win, 0, preserve_wishless); - putstr(win, 0, ""); - Sprintf(buf, retry_info, - (triesleft >= 0 && triesleft < SIZE(cardinals)) ? - cardinals[triesleft] : too_many, - (triesleft < MAXWISHTRY) ? " more" : "", - plur(triesleft)); - putstr(win, 0, buf); - putstr(win, 0, retry_too); - putstr(win, 0, ""); - if (iflags.cmdassist) - putstr(win, 0, suppress_cmdassist); - display_nhwindow(win, FALSE); - destroy_nhwindow(win); + win = create_nhwindow(NHW_TEXT); + if (!win) + return; + for (i = 0; i < SIZE(wishinfo) - 1; ++i) + putstr(win, 0, wishinfo[i]); + if (!u.uconduct.wishes) + putstr(win, 0, preserve_wishless); + putstr(win, 0, ""); + Sprintf(buf, retry_info, (triesleft >= 0 && triesleft < SIZE(cardinals)) + ? cardinals[triesleft] + : too_many, + (triesleft < MAXWISHTRY) ? " more" : "", plur(triesleft)); + putstr(win, 0, buf); + putstr(win, 0, retry_too); + putstr(win, 0, ""); + if (iflags.cmdassist) + putstr(win, 0, suppress_cmdassist); + display_nhwindow(win, FALSE); + destroy_nhwindow(win); } void makewish() { - char buf[BUFSZ], promptbuf[BUFSZ]; - struct obj *otmp, nothing; - int tries = 0; + char buf[BUFSZ], promptbuf[BUFSZ]; + struct obj *otmp, nothing; + int tries = 0; - promptbuf[0] = '\0'; - nothing = zeroobj; /* lint suppression; only its address matters */ - if (flags.verbose) You("may wish for an object."); + promptbuf[0] = '\0'; + nothing = zeroobj; /* lint suppression; only its address matters */ + if (flags.verbose) + You("may wish for an object."); retry: - Strcpy(promptbuf, "For what do you wish"); - if (iflags.cmdassist && tries > 0) - Strcat(promptbuf, " (enter 'help' for assistance)"); - Strcat(promptbuf, "?"); - getlin(promptbuf, buf); - (void)mungspaces(buf); - if (buf[0] == '\033') { - buf[0] = '\0'; - } else if (!strcmpi(buf, "help")) { - wishcmdassist(MAXWISHTRY - tries); - goto retry; - } - /* - * Note: if they wished for and got a non-object successfully, - * otmp == &zeroobj. That includes gold, or an artifact that - * has been denied. Wishing for "nothing" requires a separate - * value to remain distinct. - */ - otmp = readobjnam(buf, ¬hing); - if (!otmp) { - pline("Nothing fitting that description exists in the game."); - if (++tries < MAXWISHTRY) goto retry; - pline1(thats_enough_tries); - otmp = readobjnam((char *)0, (struct obj *)0); - if (!otmp) return; /* for safety; should never happen */ - } else if (otmp == ¬hing) { - /* explicitly wished for "nothing", presumeably attempting - to retain wishless conduct */ - return; - } + Strcpy(promptbuf, "For what do you wish"); + if (iflags.cmdassist && tries > 0) + Strcat(promptbuf, " (enter 'help' for assistance)"); + Strcat(promptbuf, "?"); + getlin(promptbuf, buf); + (void) mungspaces(buf); + if (buf[0] == '\033') { + buf[0] = '\0'; + } else if (!strcmpi(buf, "help")) { + wishcmdassist(MAXWISHTRY - tries); + goto retry; + } + /* + * Note: if they wished for and got a non-object successfully, + * otmp == &zeroobj. That includes gold, or an artifact that + * has been denied. Wishing for "nothing" requires a separate + * value to remain distinct. + */ + otmp = readobjnam(buf, ¬hing); + if (!otmp) { + pline("Nothing fitting that description exists in the game."); + if (++tries < MAXWISHTRY) + goto retry; + pline1(thats_enough_tries); + otmp = readobjnam((char *) 0, (struct obj *) 0); + if (!otmp) + return; /* for safety; should never happen */ + } else if (otmp == ¬hing) { + /* explicitly wished for "nothing", presumeably attempting + to retain wishless conduct */ + return; + } - /* KMH, conduct */ - u.uconduct.wishes++; + /* KMH, conduct */ + u.uconduct.wishes++; - if (otmp != &zeroobj) { - /* The(aobjnam()) is safe since otmp is unidentified -dlc */ - (void) hold_another_object(otmp, u.uswallow ? - "Oops! %s out of your reach!" : - (Is_airlevel(&u.uz) || - Is_waterlevel(&u.uz) || - levl[u.ux][u.uy].typ < IRONBARS || - levl[u.ux][u.uy].typ >= ICE) ? - "Oops! %s away from you!" : - "Oops! %s to the floor!", - The(aobjnam(otmp, - Is_airlevel(&u.uz) || u.uinwater ? - "slip" : "drop")), - (const char *)0); - u.ublesscnt += rn1(100,50); /* the gods take notice */ - } + if (otmp != &zeroobj) { + /* The(aobjnam()) is safe since otmp is unidentified -dlc */ + (void) hold_another_object( + otmp, u.uswallow ? "Oops! %s out of your reach!" + : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) + || levl[u.ux][u.uy].typ < IRONBARS + || levl[u.ux][u.uy].typ >= ICE) + ? "Oops! %s away from you!" + : "Oops! %s to the floor!", + The(aobjnam(otmp, + Is_airlevel(&u.uz) || u.uinwater ? "slip" : "drop")), + (const char *) 0); + u.ublesscnt += rn1(100, 50); /* the gods take notice */ + } } /*zap.c*/ diff --git a/sys/amiga/amidos.c b/sys/amiga/amidos.c index 486e202e0..0220ed6a7 100644 --- a/sys/amiga/amidos.c +++ b/sys/amiga/amidos.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amidos.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amidos.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 amidos.c $Date: 2009/05/06 10:48:29 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)amidos.c 3.5 2000/01/12 /* Copyright (c) Olaf Seibert, Nijmegen, The Netherlands, 1988,1990. */ @@ -21,13 +21,13 @@ #undef COUNT #if defined(__SASC_60) || defined(__GNUC__) -# include -# include +#include +#include #endif #ifdef AZTEC_50 -# include -# undef strcmpi +#include +#undef strcmpi #endif /* Prototypes */ @@ -39,7 +39,7 @@ extern char Initialized; extern struct window_procs amii_procs; #ifndef __SASC_60 -int Enable_Abort = 0; /* for stdio package */ +int Enable_Abort = 0; /* for stdio package */ #endif /* Initial path, so we can find NetHack.cnf */ @@ -73,7 +73,7 @@ int abs(x) int x; { - return x < 0? -x: x; + return x < 0 ? -x : x; } #endif @@ -82,31 +82,28 @@ int dosh() { int i; - char buf[ BUFSZ ]; + char buf[BUFSZ]; extern struct ExecBase *SysBase; /* Only under 2.0 and later ROMs do we have System() */ - if( SysBase->LibNode.lib_Version >= 37 && !amibbs) - { - getlin("Enter CLI Command...", buf ); - if (buf[0] != '\033') - i = System( buf, NULL ); - } - else - { - i = 0; - pline("No mysterious force prevented you from using multitasking."); + if (SysBase->LibNode.lib_Version >= 37 && !amibbs) { + getlin("Enter CLI Command...", buf); + if (buf[0] != '\033') + i = System(buf, NULL); + } else { + i = 0; + pline("No mysterious force prevented you from using multitasking."); } return i; } #endif /* SHELL */ #ifdef MFLOPPY -# include +#include -# define Sprintf (void) sprintf +#define Sprintf (void) sprintf -#define EXTENSION 72 +#define EXTENSION 72 /* * This routine uses an approximation of the free bytes on a disk. @@ -122,10 +119,10 @@ freediskspace(path) char *path; { #ifdef UNTESTED - /* these changes from Patric Mueller for AROS to - * handle larger disks. Also needs limits.h and aros/oldprograms.h - * for AROS. (keni) - */ + /* these changes from Patric Mueller for AROS to + * handle larger disks. Also needs limits.h and aros/oldprograms.h + * for AROS. (keni) + */ unsigned long long freeBytes = 0; #else register long freeBytes = 0; @@ -142,49 +139,51 @@ char *path; * so must be on the current device, so "" is enough... */ { - register char *colon; + register char *colon; - strncpy(fileName, path, sizeof(fileName) - 1); - fileName[31] = 0; - if (colon = index(fileName, ':')) - colon[1] = '\0'; - else - fileName[0] = '\0'; + strncpy(fileName, path, sizeof(fileName) - 1); + fileName[31] = 0; + if (colon = index(fileName, ':')) + colon[1] = '\0'; + else + fileName[0] = '\0'; } { - BPTR fileLock; - infoData = (struct InfoData *) alloc(sizeof(struct InfoData)); - if (fileLock = Lock(fileName, SHARED_LOCK)) { - if (Info(fileLock, infoData)) { - /* We got a kind of DOS volume, since we can Lock it. */ - /* Calculate number of blocks available for new file */ - /* Kludge for the ever-full VOID: (oops RAM:) device */ - if (infoData->id_UnitNumber == -1 && - infoData->id_NumBlocks == infoData->id_NumBlocksUsed) { - freeBytes = AvailMem(0L) - 64 * 1024L; - /* Just a stupid guess at the */ - /* Ram-Handler overhead per block: */ - freeBytes -= freeBytes/16; - } else { - /* Normal kind of DOS file system device/volume */ - freeBytes = infoData->id_NumBlocks - infoData->id_NumBlocksUsed; - freeBytes -= (freeBytes + EXTENSION) / (EXTENSION + 1); - freeBytes *= infoData->id_BytesPerBlock; + BPTR fileLock; + infoData = (struct InfoData *) alloc(sizeof(struct InfoData)); + if (fileLock = Lock(fileName, SHARED_LOCK)) { + if (Info(fileLock, infoData)) { + /* We got a kind of DOS volume, since we can Lock it. */ + /* Calculate number of blocks available for new file */ + /* Kludge for the ever-full VOID: (oops RAM:) device */ + if (infoData->id_UnitNumber == -1 + && infoData->id_NumBlocks == infoData->id_NumBlocksUsed) { + freeBytes = AvailMem(0L) - 64 * 1024L; + /* Just a stupid guess at the */ + /* Ram-Handler overhead per block: */ + freeBytes -= freeBytes / 16; + } else { + /* Normal kind of DOS file system device/volume */ + freeBytes = + infoData->id_NumBlocks - infoData->id_NumBlocksUsed; + freeBytes -= (freeBytes + EXTENSION) / (EXTENSION + 1); + freeBytes *= infoData->id_BytesPerBlock; #ifdef UNTESTED - if (freeBytes > LONG_MAX) { freeBytes = LONG_MAX; } + if (freeBytes > LONG_MAX) { + freeBytes = LONG_MAX; + } #endif - } - if (freeBytes < 0) - freeBytes = 0; - } - UnLock(fileLock); - } - free(infoData); - return freeBytes; + } + if (freeBytes < 0) + freeBytes = 0; + } + UnLock(fileLock); + } + free(infoData); + return freeBytes; } } - long filesize(file) char *file; @@ -193,12 +192,13 @@ char *file; register struct FileInfoBlock *fileInfoBlock; register long size = 0; - fileInfoBlock = (struct FileInfoBlock *)alloc(sizeof(struct FileInfoBlock)); + fileInfoBlock = + (struct FileInfoBlock *) alloc(sizeof(struct FileInfoBlock)); if (fileLock = Lock(file, SHARED_LOCK)) { - if (Examine(fileLock, fileInfoBlock)) { - size = fileInfoBlock->fib_Size; - } - UnLock(fileLock); + if (Examine(fileLock, fileInfoBlock)) { + size = fileInfoBlock->fib_Size; + } + UnLock(fileLock); } free(fileInfoBlock); return size; @@ -240,7 +240,7 @@ const char *path, *files; /* This size makes that most files can be copied with two Read()/Write()s */ #if 0 /* Unused */ -#define COPYSIZE 4096 +#define COPYSIZE 4096 char *CopyFile(from, to) const char *from, *to; @@ -280,48 +280,50 @@ saveDiskPrompt(start) char buf[BUFSIZ], *bp; BPTR fileLock; if (sysflags.asksavedisk) { - /* Don't prompt if you can find the save file */ - if (fileLock = Lock(SAVEF, SHARED_LOCK)) { - UnLock(fileLock); + /* Don't prompt if you can find the save file */ + if (fileLock = Lock(SAVEF, SHARED_LOCK)) { + UnLock(fileLock); #if defined(TTY_GRAPHICS) - if(windowprocs.win_init_nhwindows!=amii_procs.win_init_nhwindows) - clear_nhwindow( WIN_MAP ); + if (windowprocs.win_init_nhwindows + != amii_procs.win_init_nhwindows) + clear_nhwindow(WIN_MAP); #endif #if defined(AMII_GRAPHICS) - if(windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows) - clear_nhwindow( WIN_BASE ); + if (windowprocs.win_init_nhwindows + == amii_procs.win_init_nhwindows) + clear_nhwindow(WIN_BASE); #endif - return 1; - } - pline( "If save file is on a SAVE disk, put that disk in now." ); - if( strlen( SAVEF ) > QBUFSZ - 25 - 22 ) - panic( "not enough buffer space for prompt" ); + return 1; + } + pline("If save file is on a SAVE disk, put that disk in now."); + if (strlen(SAVEF) > QBUFSZ - 25 - 22) + panic("not enough buffer space for prompt"); /* THIS IS A HACK */ #if defined(TTY_GRAPHICS) - if(windowprocs.win_init_nhwindows!=amii_procs.win_init_nhwindows){ - getlin("File name ?",buf); - clear_nhwindow( WIN_MAP ); - } + if (windowprocs.win_init_nhwindows != amii_procs.win_init_nhwindows) { + getlin("File name ?", buf); + clear_nhwindow(WIN_MAP); + } #endif #if defined(AMII_GRAPHICS) - if(windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows){ - getlind("File name ?", buf, SAVEF); - clear_nhwindow( WIN_BASE ); - } + if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) { + getlind("File name ?", buf, SAVEF); + clear_nhwindow(WIN_BASE); + } #endif - clear_nhwindow( WIN_MESSAGE); - if (!start && *buf == '\033') - return 0; + clear_nhwindow(WIN_MESSAGE); + if (!start && *buf == '\033') + return 0; - /* Strip any whitespace. Also, if nothing was entered except - * whitespace, do not change the value of SAVEF. - */ - for (bp = buf; *bp; bp++) { - if (!isspace(*bp)) { - strncpy(SAVEF, bp, PATHLEN); - break; - } - } + /* Strip any whitespace. Also, if nothing was entered except + * whitespace, do not change the value of SAVEF. + */ + for (bp = buf; *bp; bp++) { + if (!isspace(*bp)) { + strncpy(SAVEF, bp, PATHLEN); + break; + } + } } return 1; } @@ -333,8 +335,8 @@ record_exists() FILE *file; if (file = fopenp(RECORD, "r")) { - fclose(file); - return TRUE; + fclose(file); + return TRUE; } return FALSE; } @@ -345,7 +347,9 @@ record_exists() * For Amiga: do nothing, but called from restore.c */ void -gameDiskPrompt(){} +gameDiskPrompt() +{ +} #endif /* @@ -358,16 +362,16 @@ char *name; { char *ptr; - if (!*name)return; + if (!*name) + return; ptr = eos(name) - 1; if (*ptr != '/' && *ptr != ':') { - *++ptr = '/'; - *++ptr = '\0'; + *++ptr = '/'; + *++ptr = '\0'; } } - void getreturn(str) const char *str; @@ -375,13 +379,13 @@ const char *str; int ch; raw_printf("Hit %s.", str); - while ((ch = nhgetch()) != '\n' && ch != '\r' ) - continue; + while ((ch = nhgetch()) != '\n' && ch != '\r') + continue; } /* Follow the PATH, trying to fopen the file. */ -#define PATHSEP ';' +#define PATHSEP ';' FILE * fopenp(name, mode) @@ -394,30 +398,34 @@ register const char *name, *mode; /* Try the default directory first. Then look along PATH. */ - if (strlen(name) >= BUFSIZ) return( NULL ); + if (strlen(name) >= BUFSIZ) + return (NULL); strcpy(buf, name); if (theLock = Lock(buf, SHARED_LOCK)) { - UnLock(theLock); - if (fp = fopen(buf, mode)) - return fp; + UnLock(theLock); + if (fp = fopen(buf, mode)) + return fp; } pp = PATH; while (pp && *pp) { - bp = buf; - while (*pp && *pp != PATHSEP){ - if( bp > buf + BUFSIZ - 1 ) return( NULL ); - lastch = *bp++ = *pp++; - } - if (lastch != ':' && lastch != '/' && bp != buf) - *bp++ = '/'; - if (bp + strlen(name) > buf + BUFSIZ - 1) return( NULL ); - strcpy(bp, name); - if (theLock = Lock(buf, SHARED_LOCK)) { - UnLock(theLock); - if (fp = fopen(buf, mode)) return fp; - } - if (*pp) - pp++; + bp = buf; + while (*pp && *pp != PATHSEP) { + if (bp > buf + BUFSIZ - 1) + return (NULL); + lastch = *bp++ = *pp++; + } + if (lastch != ':' && lastch != '/' && bp != buf) + *bp++ = '/'; + if (bp + strlen(name) > buf + BUFSIZ - 1) + return (NULL); + strcpy(bp, name); + if (theLock = Lock(buf, SHARED_LOCK)) { + UnLock(theLock); + if (fp = fopen(buf, mode)) + return fp; + } + if (*pp) + pp++; } return NULL; } @@ -432,37 +440,36 @@ register const char *name, *mode; * Assumes -1 is not a valid lock, since 0 is valid. */ -#define NO_LOCK ((BPTR) -1) +#define NO_LOCK ((BPTR) -1) static BPTR OrgDirLock = NO_LOCK; -chdir(dir) -char *dir; +chdir(dir) char *dir; { extern char orgdir[]; if (dir == orgdir) { - /* We want to go back to where we came from. */ - if (OrgDirLock != NO_LOCK) { - UnLock(CurrentDir(OrgDirLock)); - OrgDirLock = NO_LOCK; - } + /* We want to go back to where we came from. */ + if (OrgDirLock != NO_LOCK) { + UnLock(CurrentDir(OrgDirLock)); + OrgDirLock = NO_LOCK; + } } else { - /* - * Go to some new place. If still at the original - * directory, save the FileLock. - */ - BPTR newDir; + /* + * Go to some new place. If still at the original + * directory, save the FileLock. + */ + BPTR newDir; - if (newDir = Lock( (char *)dir, SHARED_LOCK)) { - if (OrgDirLock == NO_LOCK) { - OrgDirLock = CurrentDir(newDir); - } else { - UnLock(CurrentDir(newDir)); - } - } else { - return -1; /* Failed */ - } + if (newDir = Lock((char *) dir, SHARED_LOCK)) { + if (OrgDirLock == NO_LOCK) { + OrgDirLock = CurrentDir(newDir); + } else { + UnLock(CurrentDir(newDir)); + } + } else { + return -1; /* Failed */ + } } /* CurrentDir always succeeds if you have a lock */ return 0; @@ -481,22 +488,21 @@ nethack_exit(code) #endif #ifdef CHDIR - chdir(orgdir); /* chdir, not chdirx */ + chdir(orgdir); /* chdir, not chdirx */ #endif #ifdef AMII_GRAPHICS - if(windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows) - CleanUp(); + if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) + CleanUp(); #endif exit(code); } -void -regularize(s) /* normalize file name - we don't like :'s or /'s */ +void regularize(s) /* normalize file name - we don't like :'s or /'s */ register char *s; { register char *lp; - while((lp = index(s, ':')) || (lp = index(s, '/'))) - *lp = '_'; + while ((lp = index(s, ':')) || (lp = index(s, '/'))) + *lp = '_'; } diff --git a/sys/amiga/amigst.c b/sys/amiga/amigst.c index 0ec268402..7644b5db8 100644 --- a/sys/amiga/amigst.c +++ b/sys/amiga/amigst.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amigst.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amigst.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 amigst.c $Date: 2009/05/06 10:48:29 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)amigst.c 3.5 1993/01/08 /* Copyright (c) Gregg Wonderly, Naperville, IL, 1992, 1993 */ @@ -15,12 +15,12 @@ #include #include #include -#undef strcmpi +#undef strcmpi #include #include #ifdef __SASC -#include /* for __emit */ +#include /* for __emit */ #include #include #include diff --git a/sys/amiga/amimenu.c b/sys/amiga/amimenu.c index c1046700d..1b0a76cbf 100644 --- a/sys/amiga/amimenu.c +++ b/sys/amiga/amimenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amimenu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amimenu.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 amimenu.c $Date: 2009/05/06 10:48:29 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)amimenu.c 3.5 1996/02/04 */ /* Copyright (c) Olaf 'Rhialto' Seibert, 1989 */ @@ -11,87 +11,99 @@ /* GadTools menus by jhsa */ struct NewMenu GTHackMenu[] = { - { NM_TITLE, "Commands", 0, 0, 0, 0}, - { NM_ITEM, "? Display help menu", 0, 0, 0, (void *)'?'}, - { NM_ITEM, "& Explain a command", 0, 0, 0, (void *)'&'}, - { NM_ITEM, "O Set options", 0, 0, 0, (void *)'O'}, - { NM_ITEM, "! AmigaDos command", 0, 0, 0, (void *)'!'}, - { NM_ITEM, "v Version number", 0, 0, 0, (void *)'v'}, - { NM_ITEM, "V Long version and game history", 0, 0, 0, (void *)'V'}, - { NM_ITEM, "^R Redraw screen", 0, 0, 0, (void *)022}, - { NM_ITEM, "^P Repeat previous messages", 0, 0, 0, (void *)020}, - { NM_ITEM, "M-q #quit the game", 0, 0, 0, (void *)(128+'q')}, - { NM_ITEM, "S Save the game", 0, 0, 0, (void *)'S'}, - { NM_TITLE, "Inventory", 0, 0, 0, 0}, - { NM_ITEM, "i Inventory", 0, 0, 0, (void *)'i'}, - { NM_ITEM, "p Pay your bill", 0, 0, 0, (void *)'p'}, - { NM_ITEM, "d Drop an object", 0, 0, 0, (void *)'d'}, - { NM_ITEM, "D Drop several things", 0, 0, 0, (void *)'D'}, - { NM_ITEM, ", Pickup an object", 0, 0, 0, (void *)','}, - { NM_ITEM, "@ Toggle pickup", 0, 0, 0, (void *)'@'}, - { NM_ITEM, "/ Identify something", 0, 0, 0, (void *)'/'}, - { NM_ITEM, "C Christen a monster", 0, 0, 0, (void *)'C'}, - { NM_ITEM, "+ List known spells", 0, 0, 0, (void *)'+'}, - { NM_ITEM, "$ Your gold", 0, 0, 0, (void *)'$'}, - { NM_TITLE, "Actions", 0, 0, 0, 0}, - { NM_ITEM, "a Apply/use something", 0, 0, 0, (void *)'a'}, - { NM_ITEM, "e Eat something", 0, 0, 0, (void *)'e'}, - { NM_ITEM, "f Fire ammunition", 0, 0, 0, (void *)'f'}, - { NM_ITEM, "F Fight a monster", 0, 0, 0, (void *)'F'}, - { NM_ITEM, "q Quaff a monster", 0, 0, 0, (void *)'q'}, - { NM_ITEM, "r Read scroll/book", 0, 0, 0, (void *)'r'}, - { NM_ITEM, "t Throw something", 0, 0, 0, (void *)'t'}, - { NM_ITEM, "z Zap a wand", 0, 0, 0, (void *)'z'}, - { NM_ITEM, "Z Cast a spell", 0, 0, 0, (void *)'Z'}, - { NM_TITLE, "Preparations", 0, 0, 0, 0}, - { NM_ITEM, "A Remove all armor", 0, 0, 0, (void *)'A'}, - { NM_ITEM, "P Put on a ring", 0, 0, 0, (void *)'P'}, - { NM_ITEM, "R Remove ring", 0, 0, 0, (void *)'R'}, - { NM_ITEM, "Q Select ammunition for quiver", 0, 0, 0, (void *)'Q'}, - { NM_ITEM, "T Take off armor", 0, 0, 0, (void *)'T'}, - { NM_ITEM, "w Wield a weapon", 0, 0, 0, (void *)'w'}, - { NM_ITEM, "W Wear armor", 0, 0, 0, (void *)'W'}, - { NM_ITEM, "x Swap wielded and secondary weapons", 0, 0, 0, (void *)'x'}, - { NM_ITEM, ") Current weapon", 0, 0, 0, (void *)')'}, - { NM_ITEM, "[ Current armor", 0, 0, 0, (void *)'['}, - { NM_ITEM, "= Current rings", 0, 0, 0, (void *)'='}, - { NM_ITEM,"\" Current amulet", 0, 0, 0, (void *)'"'}, - { NM_ITEM, "( Current tools", 0, 0, 0, (void *)'('}, - { NM_ITEM, "* Current equipment", 0, 0, 0, (void *)'*'}, - { NM_TITLE, "Movement", 0, 0, 0, 0}, - { NM_ITEM, "o Open door", 0, 0, 0, (void *)'o'}, - { NM_ITEM, "c Close door", 0, 0, 0, (void *)'c'}, - { NM_ITEM, "^D Kick door", 0, 0, 0, (void *)004}, - { NM_ITEM, "s Search", 0, 0, 0, (void *)'s'}, - { NM_ITEM, "< Go up stairs", 0, 0, 0, (void *)'<'}, - { NM_ITEM, "> Go down stairs", 0, 0, 0, (void *)'>'}, - { NM_ITEM, "^T Teleport", 0, 0, 0, (void *)024}, - { NM_ITEM, ". Wait a moment", 0, 0, 0, (void *)'.'}, - { NM_ITEM, "E Engrave message on floor", 0, 0, 0, (void *)'E'}, - { NM_TITLE, "Extended", 0, 0, 0, 0}, - { NM_ITEM, "M-a #adjust inventory letters", 0, 0, 0, (void *)(128+'a')}, - { NM_ITEM, "M-c #chat with someone", 0, 0, 0, (void *)(128+'c')}, - { NM_ITEM, "M-d #dip an object into something", 0, 0, 0, (void *)(128+'d')}, + { NM_TITLE, "Commands", 0, 0, 0, 0 }, + { NM_ITEM, "? Display help menu", 0, 0, 0, (void *) '?' }, + { NM_ITEM, "& Explain a command", 0, 0, 0, (void *) '&' }, + { NM_ITEM, "O Set options", 0, 0, 0, (void *) 'O' }, + { NM_ITEM, "! AmigaDos command", 0, 0, 0, (void *) '!' }, + { NM_ITEM, "v Version number", 0, 0, 0, (void *) 'v' }, + { NM_ITEM, "V Long version and game history", 0, 0, 0, (void *) 'V' }, + { NM_ITEM, "^R Redraw screen", 0, 0, 0, (void *) 022 }, + { NM_ITEM, "^P Repeat previous messages", 0, 0, 0, (void *) 020 }, + { NM_ITEM, "M-q #quit the game", 0, 0, 0, (void *)(128 + 'q') }, + { NM_ITEM, "S Save the game", 0, 0, 0, (void *) 'S' }, + { NM_TITLE, "Inventory", 0, 0, 0, 0 }, + { NM_ITEM, "i Inventory", 0, 0, 0, (void *) 'i' }, + { NM_ITEM, "p Pay your bill", 0, 0, 0, (void *) 'p' }, + { NM_ITEM, "d Drop an object", 0, 0, 0, (void *) 'd' }, + { NM_ITEM, "D Drop several things", 0, 0, 0, (void *) 'D' }, + { NM_ITEM, ", Pickup an object", 0, 0, 0, (void *) ',' }, + { NM_ITEM, "@ Toggle pickup", 0, 0, 0, (void *) '@' }, + { NM_ITEM, "/ Identify something", 0, 0, 0, (void *) '/' }, + { NM_ITEM, "C Christen a monster", 0, 0, 0, (void *) 'C' }, + { NM_ITEM, "+ List known spells", 0, 0, 0, (void *) '+' }, + { NM_ITEM, "$ Your gold", 0, 0, 0, (void *) '$' }, + { NM_TITLE, "Actions", 0, 0, 0, 0 }, + { NM_ITEM, "a Apply/use something", 0, 0, 0, (void *) 'a' }, + { NM_ITEM, "e Eat something", 0, 0, 0, (void *) 'e' }, + { NM_ITEM, "f Fire ammunition", 0, 0, 0, (void *) 'f' }, + { NM_ITEM, "F Fight a monster", 0, 0, 0, (void *) 'F' }, + { NM_ITEM, "q Quaff a monster", 0, 0, 0, (void *) 'q' }, + { NM_ITEM, "r Read scroll/book", 0, 0, 0, (void *) 'r' }, + { NM_ITEM, "t Throw something", 0, 0, 0, (void *) 't' }, + { NM_ITEM, "z Zap a wand", 0, 0, 0, (void *) 'z' }, + { NM_ITEM, "Z Cast a spell", 0, 0, 0, (void *) 'Z' }, + { NM_TITLE, "Preparations", 0, 0, 0, 0 }, + { NM_ITEM, "A Remove all armor", 0, 0, 0, (void *) 'A' }, + { NM_ITEM, "P Put on a ring", 0, 0, 0, (void *) 'P' }, + { NM_ITEM, "R Remove ring", 0, 0, 0, (void *) 'R' }, + { NM_ITEM, "Q Select ammunition for quiver", 0, 0, 0, (void *) 'Q' }, + { NM_ITEM, "T Take off armor", 0, 0, 0, (void *) 'T' }, + { NM_ITEM, "w Wield a weapon", 0, 0, 0, (void *) 'w' }, + { NM_ITEM, "W Wear armor", 0, 0, 0, (void *) 'W' }, + { NM_ITEM, "x Swap wielded and secondary weapons", 0, 0, 0, + (void *) 'x' }, + { NM_ITEM, ") Current weapon", 0, 0, 0, (void *) ')' }, + { NM_ITEM, "[ Current armor", 0, 0, 0, (void *) '[' }, + { NM_ITEM, "= Current rings", 0, 0, 0, (void *) '=' }, + { NM_ITEM, "\" Current amulet", 0, 0, 0, (void *) '"' }, + { NM_ITEM, "( Current tools", 0, 0, 0, (void *) '(' }, + { NM_ITEM, "* Current equipment", 0, 0, 0, (void *) '*' }, + { NM_TITLE, "Movement", 0, 0, 0, 0 }, + { NM_ITEM, "o Open door", 0, 0, 0, (void *) 'o' }, + { NM_ITEM, "c Close door", 0, 0, 0, (void *) 'c' }, + { NM_ITEM, "^D Kick door", 0, 0, 0, (void *) 004 }, + { NM_ITEM, "s Search", 0, 0, 0, (void *) 's' }, + { NM_ITEM, "< Go up stairs", 0, 0, 0, (void *) '<' }, + { NM_ITEM, "> Go down stairs", 0, 0, 0, (void *) '>' }, + { NM_ITEM, "^T Teleport", 0, 0, 0, (void *) 024 }, + { NM_ITEM, ". Wait a moment", 0, 0, 0, (void *) '.' }, + { NM_ITEM, "E Engrave message on floor", 0, 0, 0, (void *) 'E' }, + { NM_TITLE, "Extended", 0, 0, 0, 0 }, + { NM_ITEM, "M-a #adjust inventory letters", 0, 0, 0, + (void *)(128 + 'a') }, + { NM_ITEM, "M-c #chat with someone", 0, 0, 0, (void *)(128 + 'c') }, + { NM_ITEM, "M-d #dip an object into something", 0, 0, 0, + (void *)(128 + 'd') }, #ifdef WEAPON_SKILLS - { NM_ITEM, "M-e #enhance weapon skills", 0, 0, 0, (void *)(128+'e')}, + { NM_ITEM, "M-e #enhance weapon skills", 0, 0, 0, (void *)(128 + 'e') }, #endif - { NM_ITEM, "M-f #force a lock", 0, 0, 0, (void *)(128+'f')}, - { NM_ITEM, "M-i #invoke an object's special powers", 0, 0, 0, (void *)(128+'i')}, - { NM_ITEM, "M-j #jump to another location", 0, 0, 0, (void *)(128+'j')}, - { NM_ITEM, "M-l #loot a box on the floor", 0, 0, 0, (void *)(128+'l')}, - { NM_ITEM, "M-m Use a #monster's special ability", 0, 0, 0, (void *)(128+'m')}, - { NM_ITEM, "M-n #name an item or type of object", 0, 0, 0, (void *)(128+'n')}, - { NM_ITEM, "M-o #offer a sacrifice to the gods", 0, 0, 0, (void *)(128+'o')}, - { NM_ITEM, "M-p #pray to the gods for help", 0, 0, 0, (void *)(128+'p')}, - { NM_ITEM, "M-q #quit the game", 0, 0, 0, (void *)(128+'q')}, - { NM_ITEM, "M-r #rub a lamp", 0, 0, 0, (void *)(128+'r')}, - { NM_ITEM, "M-s #sit down", 0, 0, 0, (void *)(128+'s')}, - { NM_ITEM, "M-t #turn undead", 0, 0, 0, (void *)(128+'t')}, - { NM_ITEM, "M-u #untrap something", 0, 0, 0, (void *)(128+'u')}, - { NM_ITEM, "M-v Long #version information", 0, 0, 0, (void *)(128+'v')}, - { NM_ITEM, "M-w #wipe off your face", 0, 0, 0, (void *)(128+'w')}, - { NM_ITEM, " Your #conduct", 0, 0, 0, (void *)'#'}, /* "#co\n" */ - { NM_ITEM, " #ride your steed", 0, 0, 0, (void *)'#'}, /* "#ri\n" */ - { NM_ITEM, "M-2 Switch #twoweapon mode on/off", 0, 0, 0, (void *)(128+'2')}, - { NM_END, NULL, 0, 0, 0, 0} + { NM_ITEM, "M-f #force a lock", 0, 0, 0, (void *)(128 + 'f') }, + { NM_ITEM, "M-i #invoke an object's special powers", 0, 0, 0, + (void *)(128 + 'i') }, + { NM_ITEM, "M-j #jump to another location", 0, 0, 0, + (void *)(128 + 'j') }, + { NM_ITEM, "M-l #loot a box on the floor", 0, 0, 0, + (void *)(128 + 'l') }, + { NM_ITEM, "M-m Use a #monster's special ability", 0, 0, 0, + (void *)(128 + 'm') }, + { NM_ITEM, "M-n #name an item or type of object", 0, 0, 0, + (void *)(128 + 'n') }, + { NM_ITEM, "M-o #offer a sacrifice to the gods", 0, 0, 0, + (void *)(128 + 'o') }, + { NM_ITEM, "M-p #pray to the gods for help", 0, 0, 0, + (void *)(128 + 'p') }, + { NM_ITEM, "M-q #quit the game", 0, 0, 0, (void *)(128 + 'q') }, + { NM_ITEM, "M-r #rub a lamp", 0, 0, 0, (void *)(128 + 'r') }, + { NM_ITEM, "M-s #sit down", 0, 0, 0, (void *)(128 + 's') }, + { NM_ITEM, "M-t #turn undead", 0, 0, 0, (void *)(128 + 't') }, + { NM_ITEM, "M-u #untrap something", 0, 0, 0, (void *)(128 + 'u') }, + { NM_ITEM, "M-v Long #version information", 0, 0, 0, + (void *)(128 + 'v') }, + { NM_ITEM, "M-w #wipe off your face", 0, 0, 0, (void *)(128 + 'w') }, + { NM_ITEM, " Your #conduct", 0, 0, 0, (void *) '#' }, /* "#co\n" */ + { NM_ITEM, " #ride your steed", 0, 0, 0, (void *) '#' }, /* "#ri\n" */ + { NM_ITEM, "M-2 Switch #twoweapon mode on/off", 0, 0, 0, + (void *)(128 + '2') }, + { NM_END, NULL, 0, 0, 0, 0 } }; diff --git a/sys/amiga/amirip.c b/sys/amiga/amirip.c index 669699f4e..c00194e5a 100644 --- a/sys/amiga/amirip.c +++ b/sys/amiga/amirip.c @@ -1,6 +1,7 @@ -/* NetHack 3.6 amirip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amirip.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */ /* NetHack 3.6 amirip.c $Date: 2012/01/24 04:26:20 $ $Revision: 1.7 $ */ -/* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996. */ +/* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996. + */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" @@ -25,59 +26,60 @@ static struct RastPort *rp; #ifdef AMII_GRAPHICS -#undef NULL -#define NULL 0 +#undef NULL +#define NULL 0 #ifdef AZTEC_C -# include +#include #else -# ifdef _DCC -# include -# include -# include -# include -# else -# include -# include -# include -# include -# endif +#ifdef _DCC +#include +#include +#include +#include +#else +#include +#include +#include +#include +#endif -static char *load_list[]={"tomb.iff",0}; +static char *load_list[] = { "tomb.iff", 0 }; static BitMapHeader tomb_bmhd; -static struct BitMap *tbmp[ 1 ] = {0}; +static struct BitMap *tbmp[1] = { 0 }; -static int cols[2]={154,319}; /* X location of center of columns */ -static int cno = 0; /* current column */ -#define TEXT_TOP (65+yoff) +static int cols[2] = { 154, 319 }; /* X location of center of columns */ +static int cno = 0; /* current column */ +#define TEXT_TOP (65 + yoff) -static xoff, yoff; /* image centering */ +static xoff, yoff; /* image centering */ /* terrible kludge */ /* this is why prototypes should have ONLY types in them! */ -# undef red -# undef green -# undef blue -# undef index -# ifdef _DCC -# include -# include -# else -# include -# include -# endif +#undef red +#undef green +#undef blue +#undef index +#ifdef _DCC +#include +#include +#else +#include +#include +#endif #endif /* AZTEC_C */ -static struct Window *ripwin=0; -static void tomb_text(char*); -static void dofade(int,int,int); -static int search_cmap(int,int,int); +static struct Window *ripwin = 0; +static void tomb_text(char *); +static void dofade(int, int, int); +static int search_cmap(int, int, int); -#define STONE_LINE_LEN 13 /* # chars that fit on one line - * (note 1 ' ' border) */ +#define STONE_LINE_LEN \ + 13 /* # chars that fit on one line \ + * (note 1 ' ' border) */ -#define DEATH_LINE 10 -#define YEAR_LINE 15 +#define DEATH_LINE 10 +#define YEAR_LINE 15 static unsigned short tomb_line; @@ -85,22 +87,22 @@ extern struct amii_DisplayDesc *amiIDisplay; extern struct Screen *HackScreen; extern int havelace; -static unsigned short transpalette[ AMII_MAXCOLORS ] = { 0x0000, }; - -static struct NewWindow newwin = -{ - 0,0,640,200,1,0, - MOUSEBUTTONS|VANILLAKEY|NOCAREREFRESH, - BORDERLESS|ACTIVATE|SMART_REFRESH, - NULL,NULL,(UBYTE*)NULL,NULL,NULL,-1,-1,0xffff,0xffff,CUSTOMSCREEN +static unsigned short transpalette[AMII_MAXCOLORS] = { + 0x0000, }; +static struct NewWindow newwin = { 0, 0, 640, 200, 1, 0, + MOUSEBUTTONS | VANILLAKEY | NOCAREREFRESH, + BORDERLESS | ACTIVATE | SMART_REFRESH, + NULL, NULL, (UBYTE *) NULL, NULL, NULL, -1, + -1, 0xffff, 0xffff, CUSTOMSCREEN }; + int wh; /* was local in outrip, but needed for SCALE macro */ int cmap_white, cmap_black; void -amii_outrip( tmpwin, how, when ) +amii_outrip(tmpwin, how, when) winid tmpwin; int how; time_t when; @@ -110,72 +112,79 @@ time_t when; struct IntuiMessage *imsg; int i; register char *dpx; - char buf[ 200 ]; + char buf[200]; int line, tw, ww; char *errstr = NULL; long year; - if(!WINVERS_AMIV || HackScreen->RastPort.BitMap->Depth < 4)goto cleanup; + if (!WINVERS_AMIV || HackScreen->RastPort.BitMap->Depth < 4) + goto cleanup; /* Use the users display size */ newwin.Height = amiIDisplay->ypix - newwin.TopEdge; newwin.Width = amiIDisplay->xpix; newwin.Screen = HackScreen; - for( i = 0; i < amii_numcolors; ++i ) - sysflags.amii_curmap[i] = GetRGB4( HackScreen->ViewPort.ColorMap, i ); + for (i = 0; i < amii_numcolors; ++i) + sysflags.amii_curmap[i] = GetRGB4(HackScreen->ViewPort.ColorMap, i); - ripwin = OpenWindow( (void *)&newwin ); - if( !ripwin ) goto cleanup; + ripwin = OpenWindow((void *) &newwin); + if (!ripwin) + goto cleanup; - LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors ); + LoadRGB4(&HackScreen->ViewPort, transpalette, amii_numcolors); - rp= ripwin->RPort; + rp = ripwin->RPort; wh = ripwin->Height; ww = ripwin->Width; #ifdef HACKFONT if (HackFont) - SetFont(rp, HackFont); + SetFont(rp, HackFont); #endif - tomb_bmhd = ReadImageFiles(load_list, tbmp, &errstr ); - if(errstr)goto cleanup; - if(tomb_bmhd.w > ww || tomb_bmhd.h > wh)goto cleanup; + tomb_bmhd = ReadImageFiles(load_list, tbmp, &errstr); + if (errstr) + goto cleanup; + if (tomb_bmhd.w > ww || tomb_bmhd.h > wh) + goto cleanup; -#define GENOFF(full,used) ((((full)-(used))/2) & ~7) - xoff = GENOFF(ww,tomb_bmhd.w); - yoff = GENOFF(wh,tomb_bmhd.h); - for(i=0;iBitMap, xoff, yoff, tomb_bmhd.w, tomb_bmhd.h, 0xc0, 0xff, NULL); + BltBitMap(*tbmp, 0, 0, rp->BitMap, xoff, yoff, tomb_bmhd.w, tomb_bmhd.h, + 0xc0, 0xff, NULL); /* Put together death description */ formatkiller(buf, sizeof buf, how); - tw = TextLength(rp,buf,STONE_LINE_LEN) + 40; + tw = TextLength(rp, buf, STONE_LINE_LEN) + 40; { - char *p=buf; - int x, tmp; - for(x=STONE_LINE_LEN;x;x--)*p++='W'; - *p='\0'; - tmp = TextLength(rp,buf,STONE_LINE_LEN) + 40; - tw = max( tw, tmp); + char *p = buf; + int x, tmp; + for (x = STONE_LINE_LEN; x; x--) + *p++ = 'W'; + *p = '\0'; + tmp = TextLength(rp, buf, STONE_LINE_LEN) + 40; + tw = max(tw, tmp); } /* There are 5 lines of text on the stone. */ rtxth = ripwin->RPort->TxHeight * 5; - SetAfPt( rp, (UWORD *)NULL, 0 ); - SetDrPt( rp, 0xFFFF ); + SetAfPt(rp, (UWORD *) NULL, 0); + SetDrPt(rp, 0xFFFF); - tomb_line=TEXT_TOP; + tomb_line = TEXT_TOP; - SetDrMd(rp,JAM1); + SetDrMd(rp, JAM1); /* Put name on stone */ Sprintf(buf, "%s", plname); @@ -191,35 +200,29 @@ time_t when; formatkiller(buf, sizeof buf, how); /* Put death type on stone */ - for (line=DEATH_LINE, dpx = buf; line STONE_LINE_LEN) - { - for(i=STONE_LINE_LEN;((i0 > STONE_LINE_LEN) && i); i--) - { - if(dpx[i] == ' ') - i0 = i; - } - if(!i) - i0 = STONE_LINE_LEN; - } + if ((i0 = strlen(dpx)) > STONE_LINE_LEN) { + for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--) { + if (dpx[i] == ' ') + i0 = i; + } + if (!i) + i0 = STONE_LINE_LEN; + } - tmpchar = dpx[i0]; - dpx[i0] = 0; - tomb_text(dpx); + tmpchar = dpx[i0]; + dpx[i0] = 0; + tomb_text(dpx); - if (tmpchar != ' ') - { - dpx[i0] = tmpchar; - dpx= &dpx[i0]; - } - else - { - dpx= &dpx[i0+1]; - } + if (tmpchar != ' ') { + dpx[i0] = tmpchar; + dpx = &dpx[i0]; + } else { + dpx = &dpx[i0 + 1]; + } } /* Put year on stone */ @@ -230,7 +233,7 @@ time_t when; #ifdef NH320_DEDICATION /* dedication */ cno = 1; - tomb_line=TEXT_TOP; + tomb_line = TEXT_TOP; tomb_text("This release"); tomb_text("of NetHack"); tomb_text("is dedicated"); @@ -245,131 +248,129 @@ time_t when; tomb_text("Ascended"); #endif /* Fade from black to full color */ - dofade(0,16,1); + dofade(0, 16, 1); /* Flush all messages to avoid typeahead */ - while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) ) - ReplyMsg( (struct Message *) imsg ); + while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort)) + ReplyMsg((struct Message *) imsg); done = 0; - while( !done ) - { - WaitPort( ripwin->UserPort ); - while( imsg = (struct IntuiMessage *)GetMsg(ripwin->UserPort) ) - { - switch( imsg->Class ) - { - case MOUSEBUTTONS: - case VANILLAKEY: - done = 1; - break; - } - ReplyMsg( (struct Message *)imsg ); - } + while (!done) { + WaitPort(ripwin->UserPort); + while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort)) { + switch (imsg->Class) { + case MOUSEBUTTONS: + case VANILLAKEY: + done = 1; + break; + } + ReplyMsg((struct Message *) imsg); + } } /* Fade out */ - dofade(16,0,-1); + dofade(16, 0, -1); just_return = 1; cleanup: - /* free everything */ - if(ripwin){ - Forbid(); - while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) ) - ReplyMsg( (struct Message *)imsg ); - CloseWindow( ripwin ); - Permit(); + /* free everything */ + if (ripwin) { + Forbid(); + while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort)) + ReplyMsg((struct Message *) imsg); + CloseWindow(ripwin); + Permit(); } - LoadRGB4( &HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors ); + LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors); - if(tbmp[0])FreeImageFiles(load_list, tbmp); - if(just_return) return; - /* fall back to the straight-ASCII version */ + if (tbmp[0]) + FreeImageFiles(load_list, tbmp); + if (just_return) + return; + /* fall back to the straight-ASCII version */ genl_outrip(tmpwin, how, when); } -static void tomb_text(p) +static void +tomb_text(p) char *p; { - char buf[STONE_LINE_LEN*2]; + char buf[STONE_LINE_LEN * 2]; int l; tomb_line += rp->TxHeight; - if( !*p ) - return; - sprintf(buf," %s ",p); - l=TextLength(rp,buf,strlen(buf)); + if (!*p) + return; + sprintf(buf, " %s ", p); + l = TextLength(rp, buf, strlen(buf)); - SetAPen(rp,cmap_white); - Move(rp,cols[cno]-(l/2)-1, tomb_line); - Text(rp,buf,strlen(buf)); + SetAPen(rp, cmap_white); + Move(rp, cols[cno] - (l / 2) - 1, tomb_line); + Text(rp, buf, strlen(buf)); - SetAPen(rp,cmap_white); - Move(rp,cols[cno]-(l/2)+1, tomb_line); - Text(rp,buf,strlen(buf)); + SetAPen(rp, cmap_white); + Move(rp, cols[cno] - (l / 2) + 1, tomb_line); + Text(rp, buf, strlen(buf)); - SetAPen(rp,cmap_white); - Move(rp,cols[cno]-(l/2), tomb_line-1); - Text(rp,buf,strlen(buf)); + SetAPen(rp, cmap_white); + Move(rp, cols[cno] - (l / 2), tomb_line - 1); + Text(rp, buf, strlen(buf)); - SetAPen(rp,cmap_white); - Move(rp,cols[cno]-(l/2), tomb_line+1); - Text(rp,buf,strlen(buf)); + SetAPen(rp, cmap_white); + Move(rp, cols[cno] - (l / 2), tomb_line + 1); + Text(rp, buf, strlen(buf)); - SetAPen(rp,cmap_black); - Move(rp,cols[cno]-(l/2), tomb_line); - Text(rp,buf,strlen(buf)); + SetAPen(rp, cmap_black); + Move(rp, cols[cno] - (l / 2), tomb_line); + Text(rp, buf, strlen(buf)); } /* search colormap for best match to given color */ static int -search_cmap(int r0, int g0, int b0){ +search_cmap(int r0, int g0, int b0) +{ int best = 0; int bdiff = 0x0fffffff; int x; - for(x=0;x> 8) & 15); - int g = g0-((amiv_init_map[x] >> 4) & 15); - int b = b0-((amiv_init_map[x] ) & 15); - int diff = (r*r) + (g*g) + (b*b); - if(diff> 8) & 15); + int g = g0 - ((amiv_init_map[x] >> 4) & 15); + int b = b0 - ((amiv_init_map[x]) & 15); + int diff = (r * r) + (g * g) + (b * b); + if (diff < bdiff) { + bdiff = diff; + best = x; + } } return best; } /* caution: this is NOT general! */ static void -dofade(int start, int stop, int inc){ - int i,j; - for( i = start; (i*inc) <= stop; i+=inc ) - { - for( j = 0; j < amii_numcolors; ++j ) - { - int r, g, b; +dofade(int start, int stop, int inc) +{ + int i, j; + for (i = start; (i * inc) <= stop; i += inc) { + for (j = 0; j < amii_numcolors; ++j) { + int r, g, b; - r = ( amiv_init_map[ j ] & 0xf00 ) >> 8; - g = ( amiv_init_map[ j ] & 0xf0 ) >> 4; - b = ( amiv_init_map[ j ] & 0xf ); - r = ( r * i ) / 16; - g = ( g * i ) / 16; - b = ( b * i ) / 16; - transpalette[ j ] = ((r<<8)|(g<<4)|b); - } - LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors ); - Delay( 1 ); + r = (amiv_init_map[j] & 0xf00) >> 8; + g = (amiv_init_map[j] & 0xf0) >> 4; + b = (amiv_init_map[j] & 0xf); + r = (r * i) / 16; + g = (g * i) / 16; + b = (b * i) / 16; + transpalette[j] = ((r << 8) | (g << 4) | b); + } + LoadRGB4(&HackScreen->ViewPort, transpalette, amii_numcolors); + Delay(1); } } - - #endif /* AMII_GRAPHICS */ /* TODO: - memory leaks - fix ReadImageFiles to return error instead of panic on error + memory leaks + fix ReadImageFiles to return error instead of panic on error */ diff --git a/sys/amiga/amisnd.c b/sys/amiga/amisnd.c index 58d9e8991..1e2a63067 100644 --- a/sys/amiga/amisnd.c +++ b/sys/amiga/amisnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amisnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amisnd.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 amisnd.c $Date: 2009/05/06 10:48:30 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)amisnd.c 3.5 2000/01/12*/ /* Copyright (c) 1992, 1993, 1995 by Gregg Wonderly */ @@ -33,254 +33,289 @@ #include #include -#define AMII_AVERAGE_VOLUME 60 +#define AMII_AVERAGE_VOLUME 60 int amii_volume = AMII_AVERAGE_VOLUME; -typedef struct VHDR -{ - char name[4]; - long len; - unsigned long oneshot, repeat, samples; - UWORD freq; - UBYTE n_octaves, compress; - LONG volume; +typedef struct VHDR { + char name[4]; + long len; + unsigned long oneshot, repeat, samples; + UWORD freq; + UBYTE n_octaves, compress; + LONG volume; } VHDR; -typedef struct IFFHEAD -{ - char FORM[4]; - long flen; - char _8SVX[4]; - VHDR vhdr; - char NAME[4]; - long namelen; +typedef struct IFFHEAD { + char FORM[4]; + long flen; + char _8SVX[4]; + VHDR vhdr; + char NAME[4]; + long namelen; } IFFHEAD; extern struct GfxBase *GfxBase; UBYTE whichannel[] = { 1, 2, 4, 8 }; -void makesound( char *, char *, int vol); -void amii_speaker( struct obj *instr, char *melody, int vol ); +void makesound(char *, char *, int vol); +void amii_speaker(struct obj *instr, char *melody, int vol); /* A major scale in indexs to freqtab... */ int notetab[] = { 0, 2, 4, 5, 7, 9, 11, 12 }; /* Frequencies for a scale starting at one octave below 'middle C' */ long freqtab[] = { - 220, /*A */ - 233, /*Bb*/ - 246, /*B */ - 261, /*C */ - 277, /*Db*/ - 293, /*D */ - 311, /*Eb*/ - 329, /*E */ - 349, /*F */ - 370, /*Gb*/ - 392, /*G */ - 415, /*Ab*/ - 440, /*A */ + 220, /*A */ + 233, /*Bb*/ + 246, /*B */ + 261, /*C */ + 277, /*Db*/ + 293, /*D */ + 311, /*Eb*/ + 329, /*E */ + 349, /*F */ + 370, /*Gb*/ + 392, /*G */ + 415, /*Ab*/ + 440, /*A */ }; -#ifdef TESTING -main( argc, argv ) - int argc; - char **argv; +#ifdef TESTING +main(argc, argv) int argc; +char **argv; { - makesound( "wooden_flute", "AwBwCwDwEwFwGwawbwcwdwewfwgw", 60 ); - makesound( "wooden_flute", "AhBhChDhEhFhGhahbhchdhehfhgh", 60 ); - makesound( "wooden_flute", "AqBqCqDqEqFqGqaqbqcqdqeqfqgq", 60 ); - makesound( "wooden_flute", "AeBeCeDeEeFeGeaebecedeeefege", 60 ); - makesound( "wooden_flute", "AxBxCxDxExFxGxaxbxcxdxexfxgx", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); - makesound( "wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60 ); + makesound("wooden_flute", "AwBwCwDwEwFwGwawbwcwdwewfwgw", 60); + makesound("wooden_flute", "AhBhChDhEhFhGhahbhchdhehfhgh", 60); + makesound("wooden_flute", "AqBqCqDqEqFqGqaqbqcqdqeqfqgq", 60); + makesound("wooden_flute", "AeBeCeDeEeFeGeaebecedeeefege", 60); + makesound("wooden_flute", "AxBxCxDxExFxGxaxbxcxdxexfxgx", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); + makesound("wooden_flute", "AtBtCtDtEtFtGtatbtctdtetftgt", 60); } #else void -amii_speaker( struct obj *instr, char *melody, int vol ) +amii_speaker(struct obj *instr, char *melody, int vol) { - int typ = instr->otyp; - char * actualn = (char *)OBJ_NAME( objects[typ] ) ; + int typ = instr->otyp; + char *actualn = (char *) OBJ_NAME(objects[typ]); - /* Make volume be relative to users volume level, with 60 being the - * average level that will be passed to us. - */ - vol = vol * amii_volume / AMII_AVERAGE_VOLUME; + /* Make volume be relative to users volume level, with 60 being the + * average level that will be passed to us. + */ + vol = vol * amii_volume / AMII_AVERAGE_VOLUME; - makesound( actualn, melody, vol ); + makesound(actualn, melody, vol); } #endif void -makesound ( char *actualn , char * melody, int vol ) +makesound(char *actualn, char *melody, int vol) { - char *t; - int c, cycles, dot, dlay; - dlb *stream = 0; - IFFHEAD iffhead; - struct IOAudio *AudioIO = 0; - struct MsgPort *AudioMP = 0; - struct Message *AudioMSG = 0; - ULONG device = -1; - BYTE *waveptr = 0; - LONG frequency=440, duration=1, clock, samp, samples, samcyc=1; - unsigned char name [ 100 ] ; + char *t; + int c, cycles, dot, dlay; + dlb *stream = 0; + IFFHEAD iffhead; + struct IOAudio *AudioIO = 0; + struct MsgPort *AudioMP = 0; + struct Message *AudioMSG = 0; + ULONG device = -1; + BYTE *waveptr = 0; + LONG frequency = 440, duration = 1, clock, samp, samples, samcyc = 1; + unsigned char name[100]; - if ( flags.silent ) - return; + if (flags.silent) + return; - if( GfxBase->DisplayFlags & PAL ) - clock = 3546895; - else - clock = 3579545; + if (GfxBase->DisplayFlags & PAL) + clock = 3546895; + else + clock = 3579545; - /* - * Convert type to file name - if there's nothing to play we - * shouldn't be here in the first place. - */ - strncpy(name, actualn,sizeof(name) ) ; - for( t = strchr( name, ' ' ); t; t = strchr( name, ' ' ) ) - *t = '_'; - if( (stream = dlb_fopen( name, "r" )) == NULL ) - { - perror( name ); - return; - } + /* + * Convert type to file name - if there's nothing to play we + * shouldn't be here in the first place. + */ + strncpy(name, actualn, sizeof(name)); + for (t = strchr(name, ' '); t; t = strchr(name, ' ')) + *t = '_'; + if ((stream = dlb_fopen(name, "r")) == NULL) { + perror(name); + return; + } - AudioIO = (struct IOAudio *) - AllocMem( sizeof( struct IOAudio ), MEMF_PUBLIC|MEMF_CLEAR ); - if( AudioIO == 0 ) - goto killaudio; + AudioIO = (struct IOAudio *) AllocMem(sizeof(struct IOAudio), + MEMF_PUBLIC | MEMF_CLEAR); + if (AudioIO == 0) + goto killaudio; - AudioMP = CreateMsgPort(); - if( AudioMP == 0 ) - goto killaudio; + AudioMP = CreateMsgPort(); + if (AudioMP == 0) + goto killaudio; - AudioIO->ioa_Request.io_Message.mn_ReplyPort = AudioMP; - AudioIO->ioa_Request.io_Message.mn_Node.ln_Pri = 0; - AudioIO->ioa_Request.io_Command = ADCMD_ALLOCATE; - AudioIO->ioa_Request.io_Flags = ADIOF_NOWAIT; - AudioIO->ioa_AllocKey = 0; - AudioIO->ioa_Data = whichannel; - AudioIO->ioa_Length = sizeof( whichannel ); + AudioIO->ioa_Request.io_Message.mn_ReplyPort = AudioMP; + AudioIO->ioa_Request.io_Message.mn_Node.ln_Pri = 0; + AudioIO->ioa_Request.io_Command = ADCMD_ALLOCATE; + AudioIO->ioa_Request.io_Flags = ADIOF_NOWAIT; + AudioIO->ioa_AllocKey = 0; + AudioIO->ioa_Data = whichannel; + AudioIO->ioa_Length = sizeof(whichannel); - device = OpenDevice( AUDIONAME, 0L, (struct IORequest *)AudioIO, 0L ); - if( device != 0 ) - goto killaudio; + device = OpenDevice(AUDIONAME, 0L, (struct IORequest *) AudioIO, 0L); + if (device != 0) + goto killaudio; - if( dlb_fread( (genericptr_t)&iffhead, sizeof( iffhead ), 1, stream ) != 1 ) - goto killaudio; + if (dlb_fread((genericptr_t) &iffhead, sizeof(iffhead), 1, stream) != 1) + goto killaudio; - /* This is an even number of bytes long */ - if( dlb_fread( name, (iffhead.namelen+1) & ~1, 1, stream ) != 1 ) - goto killaudio; + /* This is an even number of bytes long */ + if (dlb_fread(name, (iffhead.namelen + 1) & ~1, 1, stream) != 1) + goto killaudio; - if( dlb_fread( (genericptr_t)&samples, 4, 1, stream ) != 1 ) - goto killaudio; + if (dlb_fread((genericptr_t) &samples, 4, 1, stream) != 1) + goto killaudio; - if( dlb_fread( (genericptr_t)&samples, 4, 1, stream ) != 1 ) - goto killaudio; + if (dlb_fread((genericptr_t) &samples, 4, 1, stream) != 1) + goto killaudio; - waveptr = AllocMem( samples, MEMF_CHIP|MEMF_PUBLIC ); - if( !waveptr ) - goto killaudio; + waveptr = AllocMem(samples, MEMF_CHIP | MEMF_PUBLIC); + if (!waveptr) + goto killaudio; - if( dlb_fread( waveptr, samples, 1, stream ) != 1 ) - goto killaudio; + if (dlb_fread(waveptr, samples, 1, stream) != 1) + goto killaudio; - while( melody[0] && melody[1] ) - { - c = *melody++; - duration = *melody++; - dot = 0; - if( *melody == '.' ) - { - dot = 1; - ++melody; - } - switch( duration ) - { - case 'w': dlay = 3; duration = 1; cycles = 1; break; - case 'h': dlay = 3; duration = 2; cycles = 1; break; - case 'q': dlay = 2; duration = 4; cycles = 1; break; - case 'e': dlay = 1; duration = 8; cycles = 1; break; - case 'x': dlay = 0; duration = 16; cycles = 1; break; - case 't': dlay = 0; duration = 32; cycles = 1; break; - default: goto killaudio; /* unrecognized duration */ - } + while (melody[0] && melody[1]) { + c = *melody++; + duration = *melody++; + dot = 0; + if (*melody == '.') { + dot = 1; + ++melody; + } + switch (duration) { + case 'w': + dlay = 3; + duration = 1; + cycles = 1; + break; + case 'h': + dlay = 3; + duration = 2; + cycles = 1; + break; + case 'q': + dlay = 2; + duration = 4; + cycles = 1; + break; + case 'e': + dlay = 1; + duration = 8; + cycles = 1; + break; + case 'x': + dlay = 0; + duration = 16; + cycles = 1; + break; + case 't': + dlay = 0; + duration = 32; + cycles = 1; + break; + default: + goto killaudio; /* unrecognized duration */ + } - /* Lower case characters are one octave above upper case */ - switch( c ) - { - case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': case 'g': - c -= 'a' - 7; - break; + /* Lower case characters are one octave above upper case */ + switch (c) { + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + c -= 'a' - 7; + break; - case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': case 'G': - c -= 'A'; - break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + c -= 'A'; + break; - default: - continue; - } + default: + continue; + } - samcyc = samples; + samcyc = samples; - /* lowercase start at middle 'C', upper case are one octave below */ - frequency = c > 7 ? freqtab[notetab[c%7]]*2 : freqtab[notetab[c]]; + /* lowercase start at middle 'C', upper case are one octave below */ + frequency = c > 7 ? freqtab[notetab[c % 7]] * 2 : freqtab[notetab[c]]; - /* We can't actually do a dotted whole note unless we add code for a real - * 8SVX sample which includes sustain sample information to tell us how - * to hold the note steady... So when duration == 1, ignore 'dot'... - */ - if( dot && duration > 1 ) - samp = ((samples / duration) * 3) / 2; - else - samp = samples / duration; + /* We can't actually do a dotted whole note unless we add code for a + * real + * 8SVX sample which includes sustain sample information to tell us + * how + * to hold the note steady... So when duration == 1, ignore 'dot'... + */ + if (dot && duration > 1) + samp = ((samples / duration) * 3) / 2; + else + samp = samples / duration; - /* Only use some of the samples based on frequency */ - samp = frequency * samp / 880; + /* Only use some of the samples based on frequency */ + samp = frequency * samp / 880; - /* The 22khz samples are middle C samples, so adjust the play - * back frequency accordingly - */ - frequency = (frequency * (iffhead.vhdr.freq*2)/3) / 440L; + /* The 22khz samples are middle C samples, so adjust the play + * back frequency accordingly + */ + frequency = (frequency * (iffhead.vhdr.freq * 2) / 3) / 440L; - AudioIO->ioa_Request.io_Message.mn_ReplyPort = AudioMP; - AudioIO->ioa_Request.io_Command = CMD_WRITE; - AudioIO->ioa_Request.io_Flags = ADIOF_PERVOL; - AudioIO->ioa_Data = (BYTE *)waveptr; - AudioIO->ioa_Length = samp; + AudioIO->ioa_Request.io_Message.mn_ReplyPort = AudioMP; + AudioIO->ioa_Request.io_Command = CMD_WRITE; + AudioIO->ioa_Request.io_Flags = ADIOF_PERVOL; + AudioIO->ioa_Data = (BYTE *) waveptr; + AudioIO->ioa_Length = samp; - /* The clock rate represents the unity rate, so dividing by - * the frequency gives us a period ratio... - */ -/*printf( "clock: %ld, freq: %ld, div: %ld\n", clock, frequency, clock/frequency );*/ - AudioIO->ioa_Period = clock/frequency; - AudioIO->ioa_Volume = vol; - AudioIO->ioa_Cycles = cycles; + /* The clock rate represents the unity rate, so dividing by + * the frequency gives us a period ratio... + */ + /*printf( "clock: %ld, freq: %ld, div: %ld\n", clock, frequency, + * clock/frequency );*/ + AudioIO->ioa_Period = clock / frequency; + AudioIO->ioa_Volume = vol; + AudioIO->ioa_Cycles = cycles; - BeginIO( (struct IORequest *)AudioIO ); - WaitPort( AudioMP ); - AudioMSG = GetMsg( AudioMP ); - if( dlay ) - Delay( dlay ); - } + BeginIO((struct IORequest *) AudioIO); + WaitPort(AudioMP); + AudioMSG = GetMsg(AudioMP); + if (dlay) + Delay(dlay); + } - killaudio: - if( stream ) dlb_fclose( stream ); - if( waveptr ) FreeMem( waveptr, samples ); - if( device == 0 ) CloseDevice( (struct IORequest *)AudioIO ); - if( AudioMP ) DeleteMsgPort( AudioMP ); - if( AudioIO ) FreeMem( AudioIO, sizeof( *AudioIO ) ); +killaudio: + if (stream) + dlb_fclose(stream); + if (waveptr) + FreeMem(waveptr, samples); + if (device == 0) + CloseDevice((struct IORequest *) AudioIO); + if (AudioMP) + DeleteMsgPort(AudioMP); + if (AudioIO) + FreeMem(AudioIO, sizeof(*AudioIO)); } diff --git a/sys/amiga/amistack.c b/sys/amiga/amistack.c index 8fd2cdb4c..18da07bf7 100644 --- a/sys/amiga/amistack.c +++ b/sys/amiga/amistack.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amistack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amistack.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 amistack.c $Date: 2009/05/06 10:48:30 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)amistack.c 3.5 2000/05/03 */ /* Copyright (c) Janne Salmijärvi, Tampere, Finland, 2000 */ @@ -6,7 +6,7 @@ /* * Increase stack size to allow deep recursions. - * + * * Note: This is SAS/C specific, using other compiler probably * requires another method for increasing stack. * @@ -19,5 +19,5 @@ * At the moment 90*1024 would suffice, but just to be on the safe side ... */ -long __stack = 128*1024; +long __stack = 128 * 1024; #endif diff --git a/sys/amiga/amitty.c b/sys/amiga/amitty.c index bdda1a819..c5068c983 100644 --- a/sys/amiga/amitty.c +++ b/sys/amiga/amitty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amitty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amitty.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 amitty.c $Date: 2009/05/06 10:48:30 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)amitty.c 3.5 2000/01/12 /* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1993,1996 */ @@ -16,54 +16,71 @@ #include #ifdef _DCC -# define getch() getchar() +#define getch() getchar() #endif #ifdef __SASC_60 -# include +#include #endif -void NDECL( tty_change_color ); -char *NDECL( tty_get_color_string ); +void NDECL(tty_change_color); +char *NDECL(tty_get_color_string); #ifdef TTY_GRAPHICS -int amibbs=0; /* BBS mode */ -char bbs_id[80]=""; /* BBS uid equivalent */ -long afh_in, afh_out; /* BBS mode Amiga filehandles */ +int amibbs = 0; /* BBS mode */ +char bbs_id[80] = ""; /* BBS uid equivalent */ +long afh_in, afh_out; /* BBS mode Amiga filehandles */ -void settty(const char *s){ - end_screen(); - if(s)raw_print(s); - iflags.cbreak=ON; /* this is too easy: probably wrong */ -#if 1 /* should be version>=36 */ -/* if(IsInteractive(afh_in)){ */ - SetMode(afh_in,0); /* con mode */ +void +settty(const char *s) +{ + end_screen(); + if (s) + raw_print(s); + iflags.cbreak = ON; /* this is too easy: probably wrong */ +#if 1 /* should be version>=36 */ + /* if(IsInteractive(afh_in)){ */ + SetMode(afh_in, 0); /* con mode */ /* } */ #endif } -void gettty(){ -#if 1 /* should be VERSION >=36 */ -/* if(IsInteractive(afh_in)){ */ - SetMode(afh_in,1); /* raw mode */ +void +gettty() +{ +#if 1 /* should be VERSION >=36 */ + /* if(IsInteractive(afh_in)){ */ + SetMode(afh_in, 1); /* raw mode */ /* } */ #endif } -void setftty(){ - iflags.cbreak=ON; /* ditto */ +void +setftty() +{ + iflags.cbreak = ON; /* ditto */ } -char kill_char='X'-'@'; -char erase_char='\b'; -tgetch(){ - char x; - Read(afh_in,&x,1); - return (x=='\r')?'\n':x; +char kill_char = 'X' - '@'; +char erase_char = '\b'; +tgetch() +{ + char x; + Read(afh_in, &x, 1); + return (x == '\r') ? '\n' : x; } -void get_scr_size(){ - CO=80; - LI=24; +void +get_scr_size() +{ + CO = 80; + LI = 24; } #endif -void tty_change_color() {} -char *tty_get_color_string() { return( "" ); } +void +tty_change_color() +{ +} +char * +tty_get_color_string() +{ + return (""); +} diff --git a/sys/amiga/amiwind.c b/sys/amiga/amiwind.c index 9e1095e43..576eaf91a 100644 --- a/sys/amiga/amiwind.c +++ b/sys/amiga/amiwind.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 amiwind.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 amiwind.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 amiwind.c $Date: 2009/05/06 10:48:30 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)amiwind.c 3.5 2000/01/12 /* Copyright (c) Olaf Seibert (KosmoSoft), 1989, 1992 */ @@ -12,14 +12,14 @@ /* Have to undef CLOSE as display.h and intuition.h both use it */ #undef CLOSE -#ifdef AMII_GRAPHICS /* too early in the file? too late? */ +#ifdef AMII_GRAPHICS /* too early in the file? too late? */ #ifdef AMIFLUSH -static struct Message *FDECL(GetFMsg,(struct MsgPort *)); +static struct Message *FDECL(GetFMsg, (struct MsgPort *)); #endif static int BufferGetchar(void); -static void ProcessMessage( register struct IntuiMessage *message ); +static void ProcessMessage(register struct IntuiMessage *message); #define BufferQueueChar(ch) (KbdBuffer[KbdBuffered++] = (ch)) @@ -44,7 +44,7 @@ struct GfxBase *GfxBase; struct Library *DiskfontBase; #endif -#define KBDBUFFER 10 +#define KBDBUFFER 10 static unsigned char KbdBuffer[KBDBUFFER]; unsigned char KbdBuffered; @@ -55,8 +55,8 @@ struct TextFont *HackFont = NULL; struct TextFont *RogueFont = NULL; UBYTE FontName[] = "NetHack:hack.font"; - /* # chars in "NetHack:": */ -#define SIZEOF_DISKNAME 8 +/* # chars in "NetHack:": */ +#define SIZEOF_DISKNAME 8 #endif @@ -66,41 +66,39 @@ struct TextAttr Hack80 = { #else (UBYTE *) "topaz.font", #endif - 8, FS_NORMAL, FPF_DISKFONT | FPF_DESIGNED - | FPF_ROMFONT + 8, FS_NORMAL, FPF_DISKFONT | FPF_DESIGNED | FPF_ROMFONT }; -struct TextAttr TextsFont13 = { - (UBYTE *) "courier.font", - 13, FS_NORMAL, FPF_DISKFONT | FPF_DESIGNED -#ifndef HACKFONT - | FPF_ROMFONT +struct TextAttr TextsFont13 = { (UBYTE *) "courier.font", 13, FS_NORMAL, + FPF_DISKFONT | FPF_DESIGNED +#ifndef HACKFONT + | FPF_ROMFONT #endif }; /* Avoid doing a ReplyMsg through a window that no longer exists. */ -static enum {NoAction, CloseOver} delayed_key_action = NoAction; +static enum { NoAction, CloseOver } delayed_key_action = NoAction; /* * Open a window that shares the HackPort IDCMP. Use CloseShWindow() * to close. */ -struct Window *OpenShWindow(nw) +struct Window * +OpenShWindow(nw) struct NewWindow *nw; { register struct Window *win; register ULONG idcmpflags; - if (!HackPort) /* Sanity check */ - return (struct Window *) 0; + if (!HackPort) /* Sanity check */ + return (struct Window *) 0; idcmpflags = nw->IDCMPFlags; nw->IDCMPFlags = 0; - if (!(win = OpenWindow((void *)nw))) - { - nw->IDCMPFlags = idcmpflags; - return (struct Window *) 0; + if (!(win = OpenWindow((void *) nw))) { + nw->IDCMPFlags = idcmpflags; + return (struct Window *) 0; } nw->IDCMPFlags = idcmpflags; @@ -109,28 +107,28 @@ struct NewWindow *nw; return win; } - /* * Close a window that shared the HackPort IDCMP port. */ void FDECL(CloseShWindow, (struct Window *)); -void CloseShWindow(win) +void +CloseShWindow(win) struct Window *win; { register struct IntuiMessage *msg; - if( !HackPort ) - panic("HackPort NULL in CloseShWindow" ); + if (!HackPort) + panic("HackPort NULL in CloseShWindow"); if (!win) - return; + return; Forbid(); /* Flush all messages for all windows to avoid typeahead and other * similar problems... */ - while( msg = (struct IntuiMessage *)GetMsg( win->UserPort ) ) - ReplyMsg( (struct Message *) msg ); + while (msg = (struct IntuiMessage *) GetMsg(win->UserPort)) + ReplyMsg((struct Message *) msg); KbdBuffered = 0; win->UserPort = (struct MsgPort *) 0; ModifyIDCMP(win, 0L); @@ -138,17 +136,18 @@ struct Window *win; CloseWindow(win); } -static int BufferGetchar() +static int +BufferGetchar() { register int c; if (KbdBuffered > 0) { - c = KbdBuffer[0]; - KbdBuffered--; - /* Move the remaining characters */ - if( KbdBuffered < sizeof( KbdBuffer ) ) - memcpy( KbdBuffer, KbdBuffer+1, KbdBuffered ); - return c; + c = KbdBuffer[0]; + KbdBuffered--; + /* Move the remaining characters */ + if (KbdBuffered < sizeof(KbdBuffer)) + memcpy(KbdBuffer, KbdBuffer + 1, KbdBuffered); + return c; } return NO_CHAR; @@ -165,12 +164,13 @@ static int BufferGetchar() * qualifier keys... Is this because I never RawKeyConvert those events??? */ -int ConvertKey(message) +int +ConvertKey(message) register struct IntuiMessage *message; { static struct InputEvent theEvent; - static char numpad[] = "bjnh.lyku"; - static char ctrl_numpad[] = "\x02\x0A\x0E\x08.\x0C\x19\x0B\x15"; + static char numpad[] = "bjnh.lyku"; + static char ctrl_numpad[] = "\x02\x0A\x0E\x08.\x0C\x19\x0B\x15"; static char shift_numpad[] = "BJNH.LYKU"; unsigned char buffer[10]; @@ -179,18 +179,18 @@ register struct IntuiMessage *message; register ULONG qualifier; char numeric_pad, shift, control, alt; - if( amii_wins[ WIN_MAP ] ) - w = amii_wins[ WIN_MAP ]->win; + if (amii_wins[WIN_MAP]) + w = amii_wins[WIN_MAP]->win; qualifier = message->Qualifier; - control = (qualifier & IEQUALIFIER_CONTROL) != 0; - shift = (qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)) != 0; - alt = (qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT )) != 0; + control = (qualifier & IEQUALIFIER_CONTROL) != 0; + shift = (qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)) != 0; + alt = (qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT)) != 0; /* Allow ALT to function as a META key ... */ /* But make it switchable - alt is needed for some non-US keymaps */ - if(sysflags.altmeta) - qualifier &= ~(IEQUALIFIER_LALT | IEQUALIFIER_RALT); + if (sysflags.altmeta) + qualifier &= ~(IEQUALIFIER_LALT | IEQUALIFIER_RALT); numeric_pad = (qualifier & IEQUALIFIER_NUMERICPAD) != 0; /* @@ -201,153 +201,151 @@ register struct IntuiMessage *message; */ switch (message->Code) { - case RAWHELP: - if( alt ) - { - EditColor(); - return( -1 ); - } -#ifdef CLIPPING - else if( WINVERS_AMIV && control ) - { - EditClipping(); + case RAWHELP: + if (alt) { + EditColor(); + return (-1); + } +#ifdef CLIPPING + else if (WINVERS_AMIV && control) { + EditClipping(); - CO = ( w->Width - w->BorderLeft - w->BorderRight ) / mxsize; - LI = ( w->Height - w->BorderTop - w->BorderBottom ) / mysize; - clipxmax = CO + clipx; - clipymax = LI + clipy; - if( CO < COLNO || LI < ROWNO ) - { - clipping = TRUE; - amii_cliparound( u.ux, u.uy ); - } - else - { - clipping = FALSE; - clipx = clipy = 0; - } - BufferQueueChar( 'R'-64 ); - return(-1); - } + CO = (w->Width - w->BorderLeft - w->BorderRight) / mxsize; + LI = (w->Height - w->BorderTop - w->BorderBottom) / mysize; + clipxmax = CO + clipx; + clipymax = LI + clipy; + if (CO < COLNO || LI < ROWNO) { + clipping = TRUE; + amii_cliparound(u.ux, u.uy); + } else { + clipping = FALSE; + clipx = clipy = 0; + } + BufferQueueChar('R' - 64); + return (-1); + } #endif - else if( WINVERS_AMIV && shift ) - { - if( WIN_OVER == WIN_ERR ) - { - WIN_OVER = amii_create_nhwindow( NHW_OVER ); - BufferQueueChar( 'R'-64 ); - } - else - { - delayed_key_action = CloseOver; - } - return( -1 ); - } - return( '?' ); - break; - case CURSORLEFT: - length = '4'; - numeric_pad = 1; - goto arrow; - case CURSORDOWN: - length = '2'; - numeric_pad = 1; - goto arrow; - case CURSORUP: - length = '8'; - numeric_pad = 1; - goto arrow; - case CURSORRIGHT: - length = '6'; - numeric_pad = 1; - goto arrow; + else if (WINVERS_AMIV && shift) { + if (WIN_OVER == WIN_ERR) { + WIN_OVER = amii_create_nhwindow(NHW_OVER); + BufferQueueChar('R' - 64); + } else { + delayed_key_action = CloseOver; + } + return (-1); + } + return ('?'); + break; + case CURSORLEFT: + length = '4'; + numeric_pad = 1; + goto arrow; + case CURSORDOWN: + length = '2'; + numeric_pad = 1; + goto arrow; + case CURSORUP: + length = '8'; + numeric_pad = 1; + goto arrow; + case CURSORRIGHT: + length = '6'; + numeric_pad = 1; + goto arrow; } theEvent.ie_Class = IECLASS_RAWKEY; theEvent.ie_Code = message->Code; theEvent.ie_Qualifier = numeric_pad ? IEQUALIFIER_NUMERICPAD : qualifier; - theEvent.ie_EventAddress = (APTR) (message->IAddress); + theEvent.ie_EventAddress = (APTR)(message->IAddress); - length = RawKeyConvert(&theEvent, (char *)buffer, - (long) sizeof(buffer), NULL); + length = RawKeyConvert(&theEvent, (char *) buffer, (long) sizeof(buffer), + NULL); - if (length == 1) { /* Plain ASCII character */ - length = buffer[0]; - /* - * If iflags.num_pad is set, movement is by 4286. - * If not set, translate 4286 into hjkl. - * This way, the numeric pad can /always/ be used - * for moving, though best results are when it is off. - */ -arrow: - if (!iflags.num_pad && numeric_pad && length >= '1' && length <= '9') { - length -= '1'; - if (control) { - length = ctrl_numpad[length]; - } else if (shift) { - length = shift_numpad[length]; - } else { - length = numpad[length]; - } - } + if (length == 1) { /* Plain ASCII character */ + length = buffer[0]; + /* + * If iflags.num_pad is set, movement is by 4286. + * If not set, translate 4286 into hjkl. + * This way, the numeric pad can /always/ be used + * for moving, though best results are when it is off. + */ + arrow: + if (!iflags.num_pad && numeric_pad && length >= '1' + && length <= '9') { + length -= '1'; + if (control) { + length = ctrl_numpad[length]; + } else if (shift) { + length = shift_numpad[length]; + } else { + length = numpad[length]; + } + } - /* Kludge to allow altmeta on eg. scandinavian keymap (# == shift+alt+3) + /* Kludge to allow altmeta on eg. scandinavian keymap (# == + shift+alt+3) and prevent it from interfering with # command (M-#) */ - if (length == ('#'|0x80)) - return '#'; - if (alt && sysflags.altmeta) - length |= 0x80; - return(length); + if (length == ('#' | 0x80)) + return '#'; + if (alt && sysflags.altmeta) + length |= 0x80; + return (length); } /* else shift, ctrl, alt, amiga, F-key, shift-tab, etc */ - else if( length > 1 ) - { - int i; + else if (length > 1) { + int i; - if( length == 3 && buffer[ 0 ] == 155 && buffer[ 2 ] == 126 ) - { - int got = 1; - switch( buffer[ 1 ] ) - { - case 53: mxsize = mysize = 8; break; - case 54: mxsize = mysize = 16; break; - case 55: mxsize = mysize = 24; break; - case 56: mxsize = mysize = 32; break; - case 57: mxsize = mysize = 48; break; - default: got = 0; break; - } + if (length == 3 && buffer[0] == 155 && buffer[2] == 126) { + int got = 1; + switch (buffer[1]) { + case 53: + mxsize = mysize = 8; + break; + case 54: + mxsize = mysize = 16; + break; + case 55: + mxsize = mysize = 24; + break; + case 56: + mxsize = mysize = 32; + break; + case 57: + mxsize = mysize = 48; + break; + default: + got = 0; + break; + } #ifdef OPT_DISPMAP - dispmap_sanity(); + dispmap_sanity(); #endif - if( got ) - { - CO = (w->Width-w->BorderLeft-w->BorderRight)/mxsize; - LI = (w->Height-w->BorderTop-w->BorderBottom)/mysize; - clipxmax = CO + clipx; - clipymax = LI + clipy; - if( CO < COLNO || LI < ROWNO ) - { - amii_cliparound( u.ux, u.uy ); - } - else - { - CO = COLNO; - LI = ROWNO; - } - reclip = 1; - doredraw(); - flush_screen( 1 ); - reclip = 0; - /*BufferQueueChar( 'R'-64 );*/ - return( -1 ); - } - } - printf( "Unrecognized key: %d ", (int)buffer[0]); - for( i = 1; i < length; ++i ) - printf( "%d ", (int)buffer[i]); - printf( "\n" ); + if (got) { + CO = (w->Width - w->BorderLeft - w->BorderRight) / mxsize; + LI = (w->Height - w->BorderTop - w->BorderBottom) / mysize; + clipxmax = CO + clipx; + clipymax = LI + clipy; + if (CO < COLNO || LI < ROWNO) { + amii_cliparound(u.ux, u.uy); + } else { + CO = COLNO; + LI = ROWNO; + } + reclip = 1; + doredraw(); + flush_screen(1); + reclip = 0; + /*BufferQueueChar( 'R'-64 );*/ + return (-1); + } + } + printf("Unrecognized key: %d ", (int) buffer[0]); + for (i = 1; i < length; ++i) + printf("%d ", (int) buffer[i]); + printf("\n"); } - return( -1 ); + return (-1); } /* @@ -359,202 +357,175 @@ arrow: * ahead of input demands, when the user types ahead. */ -static void ProcessMessage(message) +static void +ProcessMessage(message) register struct IntuiMessage *message; { int c; int cnt; menu_item *mip; - static int skip_mouse=0; /* need to ignore next mouse event on - * a window activation */ + static int skip_mouse = 0; /* need to ignore next mouse event on + * a window activation */ struct Window *w = message->IDCMPWindow; - switch(message->Class) { + switch (message->Class) { case ACTIVEWINDOW: - if( alwaysinvent && WIN_INVEN != WIN_ERR && - w == amii_wins[ WIN_INVEN ]->win ) - { - cnt = DoMenuScroll( WIN_INVEN, 0, PICK_NONE, &mip ); - } - else if( scrollmsg && WIN_MESSAGE != WIN_ERR && - w == amii_wins[ WIN_MESSAGE ]->win ) - { - cnt = DoMenuScroll( WIN_MESSAGE, 0, PICK_NONE, &mip ); - } - else - { - skip_mouse=1; - } - break; + if (alwaysinvent && WIN_INVEN != WIN_ERR + && w == amii_wins[WIN_INVEN]->win) { + cnt = DoMenuScroll(WIN_INVEN, 0, PICK_NONE, &mip); + } else if (scrollmsg && WIN_MESSAGE != WIN_ERR + && w == amii_wins[WIN_MESSAGE]->win) { + cnt = DoMenuScroll(WIN_MESSAGE, 0, PICK_NONE, &mip); + } else { + skip_mouse = 1; + } + break; - case MOUSEBUTTONS: - { - if( skip_mouse ) - { - skip_mouse=0; - break; - } + case MOUSEBUTTONS: { + if (skip_mouse) { + skip_mouse = 0; + break; + } - if( !amii_wins[ WIN_MAP ] || w != amii_wins[ WIN_MAP ]->win ) - break; + if (!amii_wins[WIN_MAP] || w != amii_wins[WIN_MAP]->win) + break; - if( message->Code == SELECTDOWN ) - { - lastevent.type = WEMOUSE; - lastevent.un.mouse.x = message->MouseX; - lastevent.un.mouse.y = message->MouseY; - /* With shift equals RUN */ - lastevent.un.mouse.qual = (message->Qualifier & - (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)) != 0; - } - } - break; + if (message->Code == SELECTDOWN) { + lastevent.type = WEMOUSE; + lastevent.un.mouse.x = message->MouseX; + lastevent.un.mouse.y = message->MouseY; + /* With shift equals RUN */ + lastevent.un.mouse.qual = + (message->Qualifier + & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)) != 0; + } + } break; - case MENUPICK: - { - USHORT thismenu; - struct MenuItem *item; + case MENUPICK: { + USHORT thismenu; + struct MenuItem *item; - thismenu = message->Code; - while (thismenu != MENUNULL) - { - item = ItemAddress(MenuStrip, (ULONG) thismenu); - if (KbdBuffered < KBDBUFFER) - BufferQueueChar((char)(GTMENUITEM_USERDATA(item))); - thismenu = item->NextSelect; - } - } - break; + thismenu = message->Code; + while (thismenu != MENUNULL) { + item = ItemAddress(MenuStrip, (ULONG) thismenu); + if (KbdBuffered < KBDBUFFER) + BufferQueueChar((char) (GTMENUITEM_USERDATA(item))); + thismenu = item->NextSelect; + } + } break; - case REFRESHWINDOW: - { - if( scrollmsg - && amii_wins[ WIN_MESSAGE ] - && w == amii_wins[ WIN_MESSAGE ]->win - ){ - cnt = DoMenuScroll( WIN_MESSAGE, 0, PICK_NONE, &mip ); - } - } - break; + case REFRESHWINDOW: { + if (scrollmsg && amii_wins[WIN_MESSAGE] + && w == amii_wins[WIN_MESSAGE]->win) { + cnt = DoMenuScroll(WIN_MESSAGE, 0, PICK_NONE, &mip); + } + } break; case CLOSEWINDOW: - if( WIN_INVEN != WIN_ERR && w == amii_wins[ WIN_INVEN ]->win ) - { - dismiss_nhwindow( WIN_INVEN ); - } - if( WINVERS_AMIV - && ( WIN_OVER != WIN_ERR && w == amii_wins[ WIN_OVER ]->win ) - ){ - destroy_nhwindow( WIN_OVER ); - WIN_OVER = WIN_ERR; - } - break; + if (WIN_INVEN != WIN_ERR && w == amii_wins[WIN_INVEN]->win) { + dismiss_nhwindow(WIN_INVEN); + } + if (WINVERS_AMIV + && (WIN_OVER != WIN_ERR && w == amii_wins[WIN_OVER]->win)) { + destroy_nhwindow(WIN_OVER); + WIN_OVER = WIN_ERR; + } + break; case RAWKEY: - if (!(message->Code & IECODE_UP_PREFIX)){ - /* May queue multiple characters - * but doesn't do that yet... - */ - if( ( c = ConvertKey(message) ) > 0 ) - BufferQueueChar( c ); + if (!(message->Code & IECODE_UP_PREFIX)) { + /* May queue multiple characters + * but doesn't do that yet... + */ + if ((c = ConvertKey(message)) > 0) + BufferQueueChar(c); } break; case GADGETDOWN: - if( WIN_MESSAGE != WIN_ERR && w == amii_wins[ WIN_MESSAGE ]->win ) - { - cnt = DoMenuScroll( WIN_MESSAGE, 0, PICK_NONE, &mip ); - } - else if( WIN_INVEN != WIN_ERR && w == amii_wins[ WIN_INVEN ]->win ) - { - cnt = DoMenuScroll( WIN_INVEN, 0, PICK_NONE, &mip ); - } - break; + if (WIN_MESSAGE != WIN_ERR && w == amii_wins[WIN_MESSAGE]->win) { + cnt = DoMenuScroll(WIN_MESSAGE, 0, PICK_NONE, &mip); + } else if (WIN_INVEN != WIN_ERR && w == amii_wins[WIN_INVEN]->win) { + cnt = DoMenuScroll(WIN_INVEN, 0, PICK_NONE, &mip); + } + break; case NEWSIZE: - if( WIN_MESSAGE != WIN_ERR && w == amii_wins[ WIN_MESSAGE ]->win ) - { - if( WINVERS_AMIV ) - { - /* Make sure that new size is honored for good. */ - SetAPen( w->RPort, amii_msgBPen ); - SetBPen( w->RPort, amii_msgBPen ); - SetDrMd( w->RPort, JAM2 ); - RectFill( w->RPort, w->BorderLeft, w->BorderTop, - w->Width - w->BorderRight-1, - w->Height - w->BorderBottom-1 ); - } - ReDisplayData( WIN_MESSAGE ); - } - else if( WIN_INVEN != WIN_ERR && w == amii_wins[ WIN_INVEN ]->win ) - { - ReDisplayData( WIN_INVEN ); - } - else if( WINVERS_AMIV - && ( WIN_OVER != WIN_ERR && w == amii_wins[ WIN_OVER ]->win ) - ){ - BufferQueueChar( 'R'-64 ); - } - else if( WIN_MAP != WIN_ERR && w == amii_wins[ WIN_MAP ]->win ) - { -#ifdef CLIPPING - CO = (w->Width-w->BorderLeft-w->BorderRight)/mxsize; - LI = (w->Height-w->BorderTop-w->BorderBottom)/mysize; - clipxmax = CO + clipx; - clipymax = LI + clipy; - if( CO < COLNO || LI < ROWNO ) - { - amii_cliparound( u.ux, u.uy ); - } - else - { - clipping = FALSE; - clipx = clipy = 0; - } - BufferQueueChar( 'R'-64 ); + if (WIN_MESSAGE != WIN_ERR && w == amii_wins[WIN_MESSAGE]->win) { + if (WINVERS_AMIV) { + /* Make sure that new size is honored for good. */ + SetAPen(w->RPort, amii_msgBPen); + SetBPen(w->RPort, amii_msgBPen); + SetDrMd(w->RPort, JAM2); + RectFill(w->RPort, w->BorderLeft, w->BorderTop, + w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); + } + ReDisplayData(WIN_MESSAGE); + } else if (WIN_INVEN != WIN_ERR && w == amii_wins[WIN_INVEN]->win) { + ReDisplayData(WIN_INVEN); + } else if (WINVERS_AMIV && (WIN_OVER != WIN_ERR + && w == amii_wins[WIN_OVER]->win)) { + BufferQueueChar('R' - 64); + } else if (WIN_MAP != WIN_ERR && w == amii_wins[WIN_MAP]->win) { +#ifdef CLIPPING + CO = (w->Width - w->BorderLeft - w->BorderRight) / mxsize; + LI = (w->Height - w->BorderTop - w->BorderBottom) / mysize; + clipxmax = CO + clipx; + clipymax = LI + clipy; + if (CO < COLNO || LI < ROWNO) { + amii_cliparound(u.ux, u.uy); + } else { + clipping = FALSE; + clipx = clipy = 0; + } + BufferQueueChar('R' - 64); #endif - } - break; + } + break; } ReplyMsg((struct Message *) message); - switch(delayed_key_action){ + switch (delayed_key_action) { case CloseOver: - amii_destroy_nhwindow( WIN_OVER ); - WIN_OVER = WIN_ERR; - delayed_key_action = NoAction; + amii_destroy_nhwindow(WIN_OVER); + WIN_OVER = WIN_ERR; + delayed_key_action = NoAction; case NoAction: - ; /* null */ + ; /* null */ } } #endif /* AMII_GRAPHICS */ -/* - * Get all incoming messages and fill up the keyboard buffer, - * thus allowing Intuition to (maybe) free up the IntuiMessages. - * Return when no more messages left, or keyboard buffer half full. - * We need to do this since there is no one-to-one correspondence - * between characters and incoming messages. - */ + /* + * Get all incoming messages and fill up the keyboard buffer, + * thus allowing Intuition to (maybe) free up the IntuiMessages. + * Return when no more messages left, or keyboard buffer half full. + * We need to do this since there is no one-to-one correspondence + * between characters and incoming messages. + */ #if defined(TTY_GRAPHICS) && !defined(AMII_GRAPHICS) -int kbhit(){ - return 0; +int +kbhit() +{ + return 0; } #else int kbhit() { int c; -# ifdef TTY_GRAPHICS - /* a kludge to defuse the mess in allmain.c */ - /* I hope this is the right approach */ - if(windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows)return 0; -# endif +#ifdef TTY_GRAPHICS + /* a kludge to defuse the mess in allmain.c */ + /* I hope this is the right approach */ + if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) + return 0; +#endif c = amikbhit(); - if( c <= 0 ) - return( 0 ); - return( c ); + if (c <= 0) + return (0); + return (c); } #endif @@ -564,23 +535,20 @@ int amikbhit() { register struct IntuiMessage *message; - while( KbdBuffered < KBDBUFFER / 2 ) - { + while (KbdBuffered < KBDBUFFER / 2) { #ifdef AMIFLUSH - message = (struct IntuiMessage *) GetFMsg(HackPort); + message = (struct IntuiMessage *) GetFMsg(HackPort); #else - message = (struct IntuiMessage *) GetMsg(HackPort); + message = (struct IntuiMessage *) GetMsg(HackPort); #endif - if(message) - { - ProcessMessage(message); - if( lastevent.type != WEUNK && lastevent.type != WEKEY ) - break; - } - else - break; + if (message) { + ProcessMessage(message); + if (lastevent.type != WEUNK && lastevent.type != WEKEY) + break; + } else + break; } - return ( lastevent.type == WEUNK ) ? KbdBuffered : -1; + return (lastevent.type == WEUNK) ? KbdBuffered : -1; } /* @@ -588,28 +556,28 @@ amikbhit() * Ignore other kinds of events that happen in the mean time. */ -int WindowGetchar( ) +int +WindowGetchar() { while ((lastevent.type = WEUNK), amikbhit() <= 0) { - WaitPort(HackPort); + WaitPort(HackPort); } return BufferGetchar(); } -WETYPE WindowGetevent() +WETYPE +WindowGetevent() { lastevent.type = WEUNK; - while (amikbhit() == 0) - { - WaitPort(HackPort); + while (amikbhit() == 0) { + WaitPort(HackPort); } - if( KbdBuffered ) - { - lastevent.type = WEKEY; - lastevent.un.key = BufferGetchar(); + if (KbdBuffered) { + lastevent.type = WEKEY; + lastevent.un.key = BufferGetchar(); } - return( lastevent.type ); + return (lastevent.type); } /* @@ -617,118 +585,107 @@ WETYPE WindowGetevent() * when there is something that s/he should read. */ -void amii_cleanup() +void +amii_cleanup() { register struct IntuiMessage *msg; /* Close things up */ - if( HackPort ) - { - amii_raw_print(""); - amii_getret(); + if (HackPort) { + amii_raw_print(""); + amii_getret(); } if (ConsoleIO.io_Device) - CloseDevice( (struct IORequest *)&ConsoleIO ); + CloseDevice((struct IORequest *) &ConsoleIO); ConsoleIO.io_Device = 0; - if( ConsoleIO.io_Message.mn_ReplyPort ) - DeleteMsgPort( ConsoleIO.io_Message.mn_ReplyPort ); + if (ConsoleIO.io_Message.mn_ReplyPort) + DeleteMsgPort(ConsoleIO.io_Message.mn_ReplyPort); ConsoleIO.io_Message.mn_ReplyPort = 0; /* Strip messages before deleting the port */ - if( HackPort ) - { - Forbid(); - while (msg = (struct IntuiMessage *) GetMsg(HackPort)) - ReplyMsg((struct Message *) msg); - kill_nhwindows( 1 ); - DeleteMsgPort( HackPort ); - HackPort = NULL; - Permit(); + if (HackPort) { + Forbid(); + while (msg = (struct IntuiMessage *) GetMsg(HackPort)) + ReplyMsg((struct Message *) msg); + kill_nhwindows(1); + DeleteMsgPort(HackPort); + HackPort = NULL; + Permit(); } /* Close the screen, under v37 or greater it is a pub screen and there may * be visitors, so check close status and wait till everyone is gone. */ - if( HackScreen ) - { -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - if (MenuStrip) FreeMenus(MenuStrip); - if (VisualInfo) FreeVisualInfo(VisualInfo); - while( CloseScreen( HackScreen ) == FALSE ) - { - struct EasyStruct easy = - { - sizeof( struct EasyStruct ), - 0, - "Nethack Problem", - "Can't Close Screen, Close Visiting Windows", - "Okay" - }; - EasyRequest( NULL, &easy, NULL, NULL ); - } - } - else + if (HackScreen) { +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + if (MenuStrip) + FreeMenus(MenuStrip); + if (VisualInfo) + FreeVisualInfo(VisualInfo); + while (CloseScreen(HackScreen) == FALSE) { + struct EasyStruct easy = { + sizeof(struct EasyStruct), 0, "Nethack Problem", + "Can't Close Screen, Close Visiting Windows", "Okay" + }; + EasyRequest(NULL, &easy, NULL, NULL); + } + } else #endif - { - CloseScreen(HackScreen); - } - HackScreen = NULL; + { + CloseScreen(HackScreen); + } + HackScreen = NULL; } #ifdef HACKFONT - if (HackFont) - { - CloseFont(HackFont); - HackFont = NULL; + if (HackFont) { + CloseFont(HackFont); + HackFont = NULL; } - if( TextsFont ) - { - CloseFont( TextsFont ); - TextsFont = NULL; + if (TextsFont) { + CloseFont(TextsFont); + TextsFont = NULL; } - if( RogueFont ) - { - CloseFont( RogueFont ); - RogueFont = NULL; + if (RogueFont) { + CloseFont(RogueFont); + RogueFont = NULL; } - if( DiskfontBase ) - { - CloseLibrary(DiskfontBase); - DiskfontBase = NULL; + if (DiskfontBase) { + CloseLibrary(DiskfontBase); + DiskfontBase = NULL; } #endif if (GadToolsBase) { - CloseLibrary((struct Library *)GadToolsBase); - GadToolsBase=NULL; + CloseLibrary((struct Library *) GadToolsBase); + GadToolsBase = NULL; } if (LayersBase) { - CloseLibrary((struct Library *)LayersBase); - LayersBase = NULL; + CloseLibrary((struct Library *) LayersBase); + LayersBase = NULL; } if (GfxBase) { - CloseLibrary((struct Library *)GfxBase); - GfxBase = NULL; + CloseLibrary((struct Library *) GfxBase); + GfxBase = NULL; } if (IntuitionBase) { - CloseLibrary((struct Library *)IntuitionBase); - IntuitionBase = NULL; + CloseLibrary((struct Library *) IntuitionBase); + IntuitionBase = NULL; } -#ifdef SHAREDLIB +#ifdef SHAREDLIB if (DOSBase) { - CloseLibrary((struct Library *)DOSBase); - DOSBase = NULL; + CloseLibrary((struct Library *) DOSBase); + DOSBase = NULL; } #endif @@ -737,10 +694,11 @@ void amii_cleanup() Initialized = 0; } -#endif /* AMII_GRAPHICS */ +#endif /* AMII_GRAPHICS */ -#ifndef SHAREDLIB -void Abort(rc) +#ifndef SHAREDLIB +void +Abort(rc) long rc; { int fault = 1; @@ -749,46 +707,40 @@ long rc; chdir(orgdir); #endif #ifdef AMII_GRAPHICS - if (Initialized - && ConsoleDevice - && windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows) { - printf("\n\nAbort with alert code %08lx...\n", rc); - amii_getret(); + if (Initialized && ConsoleDevice + && windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) { + printf("\n\nAbort with alert code %08lx...\n", rc); + amii_getret(); } else #endif - printf("\n\nAbort with alert code %08lx...\n",rc); - /* Alert(rc); this is too severe */ + printf("\n\nAbort with alert code %08lx...\n", rc); +/* Alert(rc); this is too severe */ #ifdef __SASC -# ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - struct EasyStruct es = - { - sizeof( struct EasyStruct ), - 0, - "NetHack Panic Request", - "NetHack is Aborting with code == 0x%08lx", - "Continue Abort|Return to Program|Clean up and exit", - }; - fault = EasyRequest( NULL, &es, NULL, (long)rc ); - if( fault == 2 ) - return; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + struct EasyStruct es = { + sizeof(struct EasyStruct), 0, "NetHack Panic Request", + "NetHack is Aborting with code == 0x%08lx", + "Continue Abort|Return to Program|Clean up and exit", + }; + fault = EasyRequest(NULL, &es, NULL, (long) rc); + if (fault == 2) + return; } -# endif - if( fault == 1 ) - { -/* __emit(0x4afc); */ /* illegal instruction */ - __emit(0x40fc); /* divide by */ - __emit(0x0000); /* #0 */ - /* NOTE: don't move amii_cleanup() above here - */ - /* it is too likely to kill the system */ - /* before it can get the SnapShot out, if */ - /* there is something really wrong. */ +#endif + if (fault == 1) { + /* __emit(0x4afc); */ /* illegal instruction */ + __emit(0x40fc); /* divide by */ + __emit(0x0000); /* #0 */ + /* NOTE: don't move amii_cleanup() above here - */ + /* it is too likely to kill the system */ + /* before it can get the SnapShot out, if */ + /* there is something really wrong. */ } #endif #ifdef AMII_GRAPHICS - if(windowprocs.win_init_nhwindows==amii_procs.win_init_nhwindows) - amii_cleanup(); + if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) + amii_cleanup(); #endif #undef exit #ifdef AZTEC_C @@ -800,7 +752,7 @@ long rc; void CleanUp() { - amii_cleanup(); + amii_cleanup(); } #endif @@ -810,33 +762,34 @@ CleanUp() /* This routine adapted from AmigaMail IV-37 by Michael Sinz */ static struct Message * GetFMsg(port) - struct MsgPort *port; - { - struct IntuiMessage *msg,*succ,*succ1; +struct MsgPort *port; +{ + struct IntuiMessage *msg, *succ, *succ1; - if(msg=(struct IntuiMessage *)GetMsg(port)){ - if(!sysflags.amiflush)return((struct Message *)msg); - if(msg->Class==RAWKEY){ - Forbid(); - succ=(struct IntuiMessage *)(port->mp_MsgList.lh_Head); - while(succ1=(struct IntuiMessage *) - (succ->ExecMessage.mn_Node.ln_Succ)){ - if(succ->Class==RAWKEY){ - Remove((struct Node *)succ); - ReplyMsg((struct Message *)succ); - } - succ=succ1; - } - Permit(); - } + if (msg = (struct IntuiMessage *) GetMsg(port)) { + if (!sysflags.amiflush) + return ((struct Message *) msg); + if (msg->Class == RAWKEY) { + Forbid(); + succ = (struct IntuiMessage *) (port->mp_MsgList.lh_Head); + while (succ1 = (struct IntuiMessage *) (succ->ExecMessage.mn_Node + .ln_Succ)) { + if (succ->Class == RAWKEY) { + Remove((struct Node *) succ); + ReplyMsg((struct Message *) succ); + } + succ = succ1; + } + Permit(); + } } - return((struct Message *)msg); + return ((struct Message *) msg); } #endif struct NewWindow * -DupNewWindow( win ) - struct NewWindow *win; +DupNewWindow(win) +struct NewWindow *win; { struct NewWindow *nwin; struct Gadget *ngd, *gd, *pgd = NULL; @@ -845,68 +798,65 @@ DupNewWindow( win ) /* Copy the (Ext)NewWindow structure */ - nwin = (struct NewWindow *)alloc( sizeof( struct NewWindow ) ); + nwin = (struct NewWindow *) alloc(sizeof(struct NewWindow)); *nwin = *win; /* Now do the gadget list */ nwin->FirstGadget = NULL; - for( gd = win->FirstGadget; gd; gd = gd->NextGadget ) - { - ngd = (struct Gadget *)alloc( sizeof( struct Gadget ) ); - *ngd = *gd; - if( gd->GadgetType == STRGADGET ) - { - sip = (struct StringInfo *)alloc( sizeof( struct StringInfo ) ); - *sip = *((struct StringInfo *)gd->SpecialInfo); - sip->Buffer = (UBYTE *) alloc( sip->MaxChars ); - *sip->Buffer = 0; - ngd->SpecialInfo = (APTR)sip; - } - else if( gd->GadgetType == PROPGADGET ) - { - pip = (struct PropInfo *)alloc( sizeof( struct PropInfo ) ); - *pip = *((struct PropInfo *)gd->SpecialInfo); - ngd->SpecialInfo = (APTR)pip; - } - if( pgd ) - pgd->NextGadget = ngd; - else - nwin->FirstGadget = ngd; - pgd = ngd; - ngd->NextGadget = NULL; - ngd->UserData = (APTR) 0x45f35c3d; // magic cookie for FreeNewWindow() + for (gd = win->FirstGadget; gd; gd = gd->NextGadget) { + ngd = (struct Gadget *) alloc(sizeof(struct Gadget)); + *ngd = *gd; + if (gd->GadgetType == STRGADGET) { + sip = (struct StringInfo *) alloc(sizeof(struct StringInfo)); + *sip = *((struct StringInfo *) gd->SpecialInfo); + sip->Buffer = (UBYTE *) alloc(sip->MaxChars); + *sip->Buffer = 0; + ngd->SpecialInfo = (APTR) sip; + } else if (gd->GadgetType == PROPGADGET) { + pip = (struct PropInfo *) alloc(sizeof(struct PropInfo)); + *pip = *((struct PropInfo *) gd->SpecialInfo); + ngd->SpecialInfo = (APTR) pip; + } + if (pgd) + pgd->NextGadget = ngd; + else + nwin->FirstGadget = ngd; + pgd = ngd; + ngd->NextGadget = NULL; + ngd->UserData = (APTR) 0x45f35c3d; // magic cookie for FreeNewWindow() } - return( nwin ); + return (nwin); } void -FreeNewWindow( win ) - struct NewWindow *win; +FreeNewWindow(win) +struct NewWindow *win; { register struct Gadget *gd, *pgd; register struct StringInfo *sip; - for( gd = win->FirstGadget; gd; gd = pgd ) { - pgd = gd->NextGadget; - if ((ULONG)gd->UserData == 0x45f35c3d) { - if( gd->GadgetType == STRGADGET ) { - sip = (struct StringInfo *)gd->SpecialInfo; - free( sip->Buffer ); - free( sip ); - } else if( gd->GadgetType == PROPGADGET ) { - free( (struct PropInfo *)gd->SpecialInfo ); - } - free( gd ); - } + for (gd = win->FirstGadget; gd; gd = pgd) { + pgd = gd->NextGadget; + if ((ULONG) gd->UserData == 0x45f35c3d) { + if (gd->GadgetType == STRGADGET) { + sip = (struct StringInfo *) gd->SpecialInfo; + free(sip->Buffer); + free(sip); + } else if (gd->GadgetType == PROPGADGET) { + free((struct PropInfo *) gd->SpecialInfo); + } + free(gd); + } } - free( win ); + free(win); } void bell() { - if (flags.silent) return; + if (flags.silent) + return; DisplayBeep(NULL); } @@ -922,22 +872,23 @@ amii_number_pad(state) int state; { } -#endif /* AMII_GRAPHICS */ +#endif /* AMII_GRAPHICS */ -#ifndef SHAREDLIB +#ifndef SHAREDLIB void -amiv_loadlib( void ) +amiv_loadlib(void) { } void -amii_loadlib( void ) +amii_loadlib(void) { } /* fatal error */ /*VARARGS1*/ -void error VA_DECL(const char *, s) +void error +VA_DECL(const char *, s) VA_START(s); VA_INIT(s, char *); diff --git a/sys/amiga/clipwin.c b/sys/amiga/clipwin.c index a5ede30a7..f2d38ce64 100644 --- a/sys/amiga/clipwin.c +++ b/sys/amiga/clipwin.c @@ -1,268 +1,258 @@ static USHORT Palette[] = { - 0x0AAA, /* color #0 */ - 0x0000, /* color #1 */ - 0x0FFF, /* color #2 */ - 0x058B, /* color #3 */ - 0x000F, /* color #4 */ - 0x0F0F, /* color #5 */ - 0x00FF, /* color #6 */ - 0x0FFF /* color #7 */ + 0x0AAA, /* color #0 */ + 0x0000, /* color #1 */ + 0x0FFF, /* color #2 */ + 0x058B, /* color #3 */ + 0x000F, /* color #4 */ + 0x0F0F, /* color #5 */ + 0x00FF, /* color #6 */ + 0x0FFF /* color #7 */ #define PaletteColorCount 8 }; #define PALETTE Palette -static SHORT ClipBorderVectors1[] = { - 0,0, - 76,0, - 76,11, - 0,11, - 0,0 -}; +static SHORT ClipBorderVectors1[] = { 0, 0, 76, 0, 76, 11, 0, 11, 0, 0 }; static struct Border ClipBorder1 = { - -1,-1, /* XY origin relative to container TopLeft */ - 3,0,JAM1, /* front pen, back pen and drawmode */ - 5, /* number of XY vectors */ - ClipBorderVectors1, /* pointer to XY vectors */ - NULL /* next border in list */ + -1, -1, /* XY origin relative to container TopLeft */ + 3, 0, JAM1, /* front pen, back pen and drawmode */ + 5, /* number of XY vectors */ + ClipBorderVectors1, /* pointer to XY vectors */ + NULL /* next border in list */ }; static struct IntuiText ClipIText1 = { - 4,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 15,1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Cancel", /* pointer to text */ - NULL /* next IntuiText structure */ + 4, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 15, 1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Cancel", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipCancel = { - NULL, /* next gadget */ - 240,59, /* origin XY of hit box relative to window TopLeft */ - 75,10, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY, /* activation flags */ - BOOLGADGET, /* gadget type flags */ - (APTR)&ClipBorder1, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText1, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - NULL, /* SpecialInfo structure */ - GADCANCEL, /* user-definable data */ - NULL /* pointer to user-definable data */ + NULL, /* next gadget */ + 240, 59, /* origin XY of hit box relative to window TopLeft */ + 75, 10, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY, /* activation flags */ + BOOLGADGET, /* gadget type flags */ + (APTR) &ClipBorder1, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText1, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + NULL, /* SpecialInfo structure */ + GADCANCEL, /* user-definable data */ + NULL /* pointer to user-definable data */ }; -static SHORT ClipBorderVectors2[] = { - 0,0, - 78,0, - 78,11, - 0,11, - 0,0 -}; +static SHORT ClipBorderVectors2[] = { 0, 0, 78, 0, 78, 11, 0, 11, 0, 0 }; static struct Border ClipBorder2 = { - -1,-1, /* XY origin relative to container TopLeft */ - 3,0,JAM1, /* front pen, back pen and drawmode */ - 5, /* number of XY vectors */ - ClipBorderVectors2, /* pointer to XY vectors */ - NULL /* next border in list */ + -1, -1, /* XY origin relative to container TopLeft */ + 3, 0, JAM1, /* front pen, back pen and drawmode */ + 5, /* number of XY vectors */ + ClipBorderVectors2, /* pointer to XY vectors */ + NULL /* next border in list */ }; static struct IntuiText ClipIText2 = { - 4,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 24,1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Okay", /* pointer to text */ - NULL /* next IntuiText structure */ + 4, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 24, 1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Okay", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipOkay = { - &ClipCancel, /* next gadget */ - 17,60, /* origin XY of hit box relative to window TopLeft */ - 77,10, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY, /* activation flags */ - BOOLGADGET, /* gadget type flags */ - (APTR)&ClipBorder2, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText2, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - NULL, /* SpecialInfo structure */ - GADOKAY, /* user-definable data */ - NULL /* pointer to user-definable data */ + &ClipCancel, /* next gadget */ + 17, 60, /* origin XY of hit box relative to window TopLeft */ + 77, 10, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY, /* activation flags */ + BOOLGADGET, /* gadget type flags */ + (APTR) &ClipBorder2, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText2, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + NULL, /* SpecialInfo structure */ + GADOKAY, /* user-definable data */ + NULL /* pointer to user-definable data */ }; static struct PropInfo ClipClipXCLIPSInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 24504,-1, /* horizontal and vertical pot values */ - 10922,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 24504, -1, /* horizontal and vertical pot values */ + 10922, -1, /* horizontal and vertical body values */ }; static struct Image ClipImage1 = { - 43,0, /* XY origin relative to container TopLeft */ - 24,3, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 43, 0, /* XY origin relative to container TopLeft */ + 24, 3, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; static struct IntuiText ClipIText3 = { - 3,0,JAM1, /* front and back text pens, drawmode and fill byte */ - -116,-1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "X Clip Border:", /* pointer to text */ - NULL /* next IntuiText structure */ + 3, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + -116, -1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "X Clip Border:", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipXCLIP = { - &ClipOkay, /* next gadget */ - 134,37, /* origin XY of hit box relative to window TopLeft */ - -199,7, /* hit box width and height */ - GRELWIDTH, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&ClipImage1, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText3, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&ClipClipXCLIPSInfo, /* SpecialInfo structure */ - XCLIP, /* user-definable data */ - NULL /* pointer to user-definable data */ + &ClipOkay, /* next gadget */ + 134, 37, /* origin XY of hit box relative to window TopLeft */ + -199, 7, /* hit box width and height */ + GRELWIDTH, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &ClipImage1, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText3, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &ClipClipXCLIPSInfo, /* SpecialInfo structure */ + XCLIP, /* user-definable data */ + NULL /* pointer to user-definable data */ }; static struct PropInfo ClipClipYCLIPSInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 13106,-1, /* horizontal and vertical pot values */ - 10922,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 13106, -1, /* horizontal and vertical pot values */ + 10922, -1, /* horizontal and vertical body values */ }; static struct Image ClipImage2 = { - 22,0, /* XY origin relative to container TopLeft */ - 24,3, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 22, 0, /* XY origin relative to container TopLeft */ + 24, 3, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; static struct IntuiText ClipIText4 = { - 3,0,JAM1, /* front and back text pens, drawmode and fill byte */ - -116,-1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Y Clip Border:", /* pointer to text */ - NULL /* next IntuiText structure */ + 3, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + -116, -1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Y Clip Border:", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipYCLIP = { - &ClipXCLIP, /* next gadget */ - 134,46, /* origin XY of hit box relative to window TopLeft */ - -199,7, /* hit box width and height */ - GRELWIDTH, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&ClipImage2, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText4, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&ClipClipYCLIPSInfo, /* SpecialInfo structure */ - YCLIP, /* user-definable data */ - NULL /* pointer to user-definable data */ + &ClipXCLIP, /* next gadget */ + 134, 46, /* origin XY of hit box relative to window TopLeft */ + -199, 7, /* hit box width and height */ + GRELWIDTH, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &ClipImage2, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText4, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &ClipClipYCLIPSInfo, /* SpecialInfo structure */ + YCLIP, /* user-definable data */ + NULL /* pointer to user-definable data */ }; static struct PropInfo ClipClipXSIZESInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 26212,-1, /* horizontal and vertical pot values */ - 10922,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 26212, -1, /* horizontal and vertical pot values */ + 10922, -1, /* horizontal and vertical body values */ }; static struct Image ClipImage3 = { - 45,0, /* XY origin relative to container TopLeft */ - 24,3, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 45, 0, /* XY origin relative to container TopLeft */ + 24, 3, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; static struct IntuiText ClipIText5 = { - 3,0,JAM1, /* front and back text pens, drawmode and fill byte */ - -124,-1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "X Scale Factor:", /* pointer to text */ - NULL /* next IntuiText structure */ + 3, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + -124, -1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "X Scale Factor:", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipXSIZE = { - &ClipYCLIP, /* next gadget */ - 134,15, /* origin XY of hit box relative to window TopLeft */ - -199,7, /* hit box width and height */ - GRELWIDTH, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&ClipImage3, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText5, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&ClipClipXSIZESInfo, /* SpecialInfo structure */ - XSIZE, /* user-definable data */ - NULL /* pointer to user-definable data */ + &ClipYCLIP, /* next gadget */ + 134, 15, /* origin XY of hit box relative to window TopLeft */ + -199, 7, /* hit box width and height */ + GRELWIDTH, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &ClipImage3, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText5, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &ClipClipXSIZESInfo, /* SpecialInfo structure */ + XSIZE, /* user-definable data */ + NULL /* pointer to user-definable data */ }; static struct PropInfo ClipClipYSIZESInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - -25937,-1, /* horizontal and vertical pot values */ - 10922,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + -25937, -1, /* horizontal and vertical pot values */ + 10922, -1, /* horizontal and vertical body values */ }; static struct Image ClipImage4 = { - 69,0, /* XY origin relative to container TopLeft */ - 24,3, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 69, 0, /* XY origin relative to container TopLeft */ + 24, 3, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; static struct IntuiText ClipIText6 = { - 3,0,JAM1, /* front and back text pens, drawmode and fill byte */ - -124,-1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Y Scale Factor:", /* pointer to text */ - NULL /* next IntuiText structure */ + 3, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + -124, -1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Y Scale Factor:", /* pointer to text */ + NULL /* next IntuiText structure */ }; static struct Gadget ClipYSIZE = { - &ClipXSIZE, /* next gadget */ - 134,24, /* origin XY of hit box relative to window TopLeft */ - -199,7, /* hit box width and height */ - GRELWIDTH, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&ClipImage4, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &ClipIText6, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&ClipClipYSIZESInfo, /* SpecialInfo structure */ - YSIZE, /* user-definable data */ - NULL /* pointer to user-definable data */ + &ClipXSIZE, /* next gadget */ + 134, 24, /* origin XY of hit box relative to window TopLeft */ + -199, 7, /* hit box width and height */ + GRELWIDTH, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &ClipImage4, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &ClipIText6, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &ClipClipYSIZESInfo, /* SpecialInfo structure */ + YSIZE, /* user-definable data */ + NULL /* pointer to user-definable data */ }; #define ClipGadgetList1 ClipYSIZE static struct NewWindow ClipNewWindowStructure1 = { - 114,16, /* window XY origin relative to TopLeft of screen */ - 346,76, /* window width and height */ - 0,1, /* detail and block pens */ - NEWSIZE+MOUSEMOVE+GADGETDOWN+GADGETUP+CLOSEWINDOW+ACTIVEWINDOW+VANILLAKEY+INTUITICKS, /* IDCMP flags */ - WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, /* other window flags */ - &ClipYSIZE, /* first gadget in gadget list */ - NULL, /* custom CHECKMARK imagery */ - "Edit Clipping Parameters", /* window title */ - NULL, /* custom screen pointer */ - NULL, /* custom bitmap */ - 350,76, /* minimum width and height */ - -1,-1, /* maximum width and height */ - CUSTOMSCREEN /* destination screen type */ + 114, 16, /* window XY origin relative to TopLeft of screen */ + 346, 76, /* window width and height */ + 0, 1, /* detail and block pens */ + NEWSIZE + MOUSEMOVE + GADGETDOWN + GADGETUP + CLOSEWINDOW + ACTIVEWINDOW + + VANILLAKEY + INTUITICKS, /* IDCMP flags */ + WINDOWSIZING + WINDOWDRAG + WINDOWDEPTH + WINDOWCLOSE + ACTIVATE + + NOCAREREFRESH, /* other window flags */ + &ClipYSIZE, /* first gadget in gadget list */ + NULL, /* custom CHECKMARK imagery */ + "Edit Clipping Parameters", /* window title */ + NULL, /* custom screen pointer */ + NULL, /* custom bitmap */ + 350, + 76, /* minimum width and height */ + -1, -1, /* maximum width and height */ + CUSTOMSCREEN /* destination screen type */ }; - /* end of PowerWindows source generation */ diff --git a/sys/amiga/colorwin.c b/sys/amiga/colorwin.c index a9cf25c99..fdf1599d3 100644 --- a/sys/amiga/colorwin.c +++ b/sys/amiga/colorwin.c @@ -1,256 +1,242 @@ -SHORT Col_BorderVectors1[] = { - 0,0, - 59,0, - 59,12, - 0,12, - 0,0 -}; +SHORT Col_BorderVectors1[] = { 0, 0, 59, 0, 59, 12, 0, 12, 0, 0 }; struct Border Col_Border1 = { - -1,-1, /* XY origin relative to container TopLeft */ - 3,0,JAM1, /* front pen, back pen and drawmode */ - 5, /* number of XY vectors */ - Col_BorderVectors1, /* pointer to XY vectors */ - NULL /* next border in list */ + -1, -1, /* XY origin relative to container TopLeft */ + 3, 0, JAM1, /* front pen, back pen and drawmode */ + 5, /* number of XY vectors */ + Col_BorderVectors1, /* pointer to XY vectors */ + NULL /* next border in list */ }; struct IntuiText Col_IText1 = { - 7,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 13,1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Save", /* pointer to text */ - NULL /* next IntuiText structure */ + 7, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 13, 1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Save", /* pointer to text */ + NULL /* next IntuiText structure */ }; struct Gadget Col_Save = { - NULL, /* next gadget */ - 9,77, /* origin XY of hit box relative to window TopLeft */ - 58,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY, /* activation flags */ - BOOLGADGET, /* gadget type flags */ - (APTR)&Col_Border1, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &Col_IText1, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - NULL, /* SpecialInfo structure */ - GADCOLSAVE, /* user-definable data */ - NULL /* pointer to user-definable data */ + NULL, /* next gadget */ + 9, 77, /* origin XY of hit box relative to window TopLeft */ + 58, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY, /* activation flags */ + BOOLGADGET, /* gadget type flags */ + (APTR) &Col_Border1, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &Col_IText1, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + NULL, /* SpecialInfo structure */ + GADCOLSAVE, /* user-definable data */ + NULL /* pointer to user-definable data */ }; -SHORT Col_BorderVectors2[] = { - 0,0, - 59,0, - 59,12, - 0,12, - 0,0 -}; +SHORT Col_BorderVectors2[] = { 0, 0, 59, 0, 59, 12, 0, 12, 0, 0 }; struct Border Col_Border2 = { - -1,-1, /* XY origin relative to container TopLeft */ - 3,0,JAM1, /* front pen, back pen and drawmode */ - 5, /* number of XY vectors */ - Col_BorderVectors2, /* pointer to XY vectors */ - NULL /* next border in list */ + -1, -1, /* XY origin relative to container TopLeft */ + 3, 0, JAM1, /* front pen, back pen and drawmode */ + 5, /* number of XY vectors */ + Col_BorderVectors2, /* pointer to XY vectors */ + NULL /* next border in list */ }; struct IntuiText Col_IText2 = { - 7,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 17,1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Use", /* pointer to text */ - NULL /* next IntuiText structure */ + 7, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 17, 1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Use", /* pointer to text */ + NULL /* next IntuiText structure */ }; struct Gadget Col_Okay = { - &Col_Save, /* next gadget */ - 128,77, /* origin XY of hit box relative to window TopLeft */ - 58,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY, /* activation flags */ - BOOLGADGET, /* gadget type flags */ - (APTR)&Col_Border2, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &Col_IText2, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - NULL, /* SpecialInfo structure */ - GADCOLOKAY, /* user-definable data */ - NULL /* pointer to user-definable data */ + &Col_Save, /* next gadget */ + 128, 77, /* origin XY of hit box relative to window TopLeft */ + 58, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY, /* activation flags */ + BOOLGADGET, /* gadget type flags */ + (APTR) &Col_Border2, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &Col_IText2, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + NULL, /* SpecialInfo structure */ + GADCOLOKAY, /* user-definable data */ + NULL /* pointer to user-definable data */ }; -SHORT Col_BorderVectors3[] = { - 0,0, - 59,0, - 59,12, - 0,12, - 0,0 -}; +SHORT Col_BorderVectors3[] = { 0, 0, 59, 0, 59, 12, 0, 12, 0, 0 }; struct Border Col_Border3 = { - -1,-1, /* XY origin relative to container TopLeft */ - 3,0,JAM1, /* front pen, back pen and drawmode */ - 5, /* number of XY vectors */ - Col_BorderVectors3, /* pointer to XY vectors */ - NULL /* next border in list */ + -1, -1, /* XY origin relative to container TopLeft */ + 3, 0, JAM1, /* front pen, back pen and drawmode */ + 5, /* number of XY vectors */ + Col_BorderVectors3, /* pointer to XY vectors */ + NULL /* next border in list */ }; struct IntuiText Col_IText3 = { - 7,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 6,1, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "Cancel", /* pointer to text */ - NULL /* next IntuiText structure */ + 7, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 6, 1, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "Cancel", /* pointer to text */ + NULL /* next IntuiText structure */ }; struct Gadget Col_Cancel = { - &Col_Okay, /* next gadget */ - 244,77, /* origin XY of hit box relative to window TopLeft */ - 58,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY, /* activation flags */ - BOOLGADGET, /* gadget type flags */ - (APTR)&Col_Border3, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - &Col_IText3, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - NULL, /* SpecialInfo structure */ - GADCOLCANCEL, /* user-definable data */ - NULL /* pointer to user-definable data */ + &Col_Okay, /* next gadget */ + 244, 77, /* origin XY of hit box relative to window TopLeft */ + 58, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY, /* activation flags */ + BOOLGADGET, /* gadget type flags */ + (APTR) &Col_Border3, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + &Col_IText3, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + NULL, /* SpecialInfo structure */ + GADCOLCANCEL, /* user-definable data */ + NULL /* pointer to user-definable data */ }; struct PropInfo Col_Col_RedPenSInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 0,0, /* horizontal and vertical pot values */ - -1,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 0, 0, /* horizontal and vertical pot values */ + -1, -1, /* horizontal and vertical body values */ }; struct Image Col_Image1 = { - 0,0, /* XY origin relative to container TopLeft */ - 263,7, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 0, 0, /* XY origin relative to container TopLeft */ + 263, 7, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; struct Gadget Col_RedPen = { - &Col_Cancel, /* next gadget */ - 32,12, /* origin XY of hit box relative to window TopLeft */ - 271,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE+FOLLOWMOUSE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&Col_Image1, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - NULL, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&Col_Col_RedPenSInfo, /* SpecialInfo structure */ - GADREDPEN, /* user-definable data */ - NULL /* pointer to user-definable data */ + &Col_Cancel, /* next gadget */ + 32, 12, /* origin XY of hit box relative to window TopLeft */ + 271, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE + FOLLOWMOUSE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &Col_Image1, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + NULL, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &Col_Col_RedPenSInfo, /* SpecialInfo structure */ + GADREDPEN, /* user-definable data */ + NULL /* pointer to user-definable data */ }; struct PropInfo Col_Col_GreenPenSInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 0,0, /* horizontal and vertical pot values */ - -1,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 0, 0, /* horizontal and vertical pot values */ + -1, -1, /* horizontal and vertical body values */ }; struct Image Col_Image2 = { - 0,0, /* XY origin relative to container TopLeft */ - 263,7, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 0, 0, /* XY origin relative to container TopLeft */ + 263, 7, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; struct Gadget Col_GreenPen = { - &Col_RedPen, /* next gadget */ - 32,24, /* origin XY of hit box relative to window TopLeft */ - 271,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE+FOLLOWMOUSE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&Col_Image2, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - NULL, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&Col_Col_GreenPenSInfo, /* SpecialInfo structure */ - GADGREENPEN, /* user-definable data */ - NULL /* pointer to user-definable data */ + &Col_RedPen, /* next gadget */ + 32, 24, /* origin XY of hit box relative to window TopLeft */ + 271, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE + FOLLOWMOUSE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &Col_Image2, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + NULL, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &Col_Col_GreenPenSInfo, /* SpecialInfo structure */ + GADGREENPEN, /* user-definable data */ + NULL /* pointer to user-definable data */ }; struct PropInfo Col_Col_BluePenSInfo = { - AUTOKNOB+FREEHORIZ, /* PropInfo flags */ - 0,0, /* horizontal and vertical pot values */ - -1,-1, /* horizontal and vertical body values */ + AUTOKNOB + FREEHORIZ, /* PropInfo flags */ + 0, 0, /* horizontal and vertical pot values */ + -1, -1, /* horizontal and vertical body values */ }; struct Image Col_Image3 = { - 0,0, /* XY origin relative to container TopLeft */ - 263,7, /* Image width and height in pixels */ - 0, /* number of bitplanes in Image */ - NULL, /* pointer to ImageData */ - 0x0000,0x0000, /* PlanePick and PlaneOnOff */ - NULL /* next Image structure */ + 0, 0, /* XY origin relative to container TopLeft */ + 263, 7, /* Image width and height in pixels */ + 0, /* number of bitplanes in Image */ + NULL, /* pointer to ImageData */ + 0x0000, 0x0000, /* PlanePick and PlaneOnOff */ + NULL /* next Image structure */ }; struct Gadget Col_BluePen = { - &Col_GreenPen, /* next gadget */ - 32,36, /* origin XY of hit box relative to window TopLeft */ - 271,11, /* hit box width and height */ - NULL, /* gadget flags */ - RELVERIFY+GADGIMMEDIATE+FOLLOWMOUSE, /* activation flags */ - PROPGADGET, /* gadget type flags */ - (APTR)&Col_Image3, /* gadget border or image to be rendered */ - NULL, /* alternate imagery for selection */ - NULL, /* first IntuiText structure */ - NULL, /* gadget mutual-exclude long word */ - (APTR)&Col_Col_BluePenSInfo, /* SpecialInfo structure */ - GADBLUEPEN, /* user-definable data */ - NULL /* pointer to user-definable data */ + &Col_GreenPen, /* next gadget */ + 32, 36, /* origin XY of hit box relative to window TopLeft */ + 271, 11, /* hit box width and height */ + NULL, /* gadget flags */ + RELVERIFY + GADGIMMEDIATE + FOLLOWMOUSE, /* activation flags */ + PROPGADGET, /* gadget type flags */ + (APTR) &Col_Image3, /* gadget border or image to be rendered */ + NULL, /* alternate imagery for selection */ + NULL, /* first IntuiText structure */ + NULL, /* gadget mutual-exclude long word */ + (APTR) &Col_Col_BluePenSInfo, /* SpecialInfo structure */ + GADBLUEPEN, /* user-definable data */ + NULL /* pointer to user-definable data */ }; #define Col_GadgetList1 Col_BluePen struct IntuiText Col_IText6 = { - 3,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 17,38, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "B", /* pointer to text */ - NULL /* next IntuiText structure */ + 3, 0, JAM1, /* front and back text pens, drawmode and fill byte */ + 17, 38, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "B", /* pointer to text */ + NULL /* next IntuiText structure */ }; struct IntuiText Col_IText5 = { - 4,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 16,26, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "G", /* pointer to text */ - &Col_IText6 /* next IntuiText structure */ + 4, 0, + JAM1, /* front and back text pens, drawmode and fill byte */ + 16, 26, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "G", /* pointer to text */ + &Col_IText6 /* next IntuiText structure */ }; struct IntuiText Col_IText4 = { - 7,0,JAM1, /* front and back text pens, drawmode and fill byte */ - 16,14, /* XY origin relative to container TopLeft */ - NULL, /* font pointer or NULL for default */ - "R", /* pointer to text */ - &Col_IText5 /* next IntuiText structure */ + 7, 0, + JAM1, /* front and back text pens, drawmode and fill byte */ + 16, 14, /* XY origin relative to container TopLeft */ + NULL, /* font pointer or NULL for default */ + "R", /* pointer to text */ + &Col_IText5 /* next IntuiText structure */ }; #define Col_IntuiTextList1 Col_IText4 struct NewWindow Col_NewWindowStructure1 = { - 175,45, /* window XY origin relative to TopLeft of screen */ - 312,93, /* window width and height */ - 0,1, /* detail and block pens */ - MOUSEBUTTONS+MOUSEMOVE+GADGETDOWN+GADGETUP+CLOSEWINDOW+VANILLAKEY+INTUITICKS, /* IDCMP flags */ - WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, /* other window flags */ - &Col_BluePen, /* first gadget in gadget list */ - NULL, /* custom CHECKMARK imagery */ - "Edit Screen Colors", /* window title */ - NULL, /* custom screen pointer */ - NULL, /* custom bitmap */ - 5,5, /* minimum width and height */ - -1,-1, /* maximum width and height */ - CUSTOMSCREEN /* destination screen type */ + 175, 45, /* window XY origin relative to TopLeft of screen */ + 312, 93, /* window width and height */ + 0, 1, /* detail and block pens */ + MOUSEBUTTONS + MOUSEMOVE + GADGETDOWN + GADGETUP + CLOSEWINDOW + + VANILLAKEY + INTUITICKS, /* IDCMP flags */ + WINDOWDRAG + WINDOWDEPTH + WINDOWCLOSE + ACTIVATE + + NOCAREREFRESH, /* other window flags */ + &Col_BluePen, /* first gadget in gadget list */ + NULL, /* custom CHECKMARK imagery */ + "Edit Screen Colors", /* window title */ + NULL, /* custom screen pointer */ + NULL, /* custom bitmap */ + 5, + 5, /* minimum width and height */ + -1, -1, /* maximum width and height */ + CUSTOMSCREEN /* destination screen type */ }; - /* end of PowerWindows source generation */ diff --git a/sys/amiga/cvtsnd.c b/sys/amiga/cvtsnd.c index 48e37cd5e..53f61cb3b 100644 --- a/sys/amiga/cvtsnd.c +++ b/sys/amiga/cvtsnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 cvtsnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 cvtsnd.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 cvtsnd.c $Date: 2009/05/06 10:48:31 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)cvtsnd.c 3.5 1995/09/10 */ /* Copyright (c) 1995, Andrew Church, Olney, Maryland */ @@ -11,7 +11,7 @@ typedef struct { short namelen; char name[62]; - char misc[64]; /* rest of MacBinary header */ + char misc[64]; /* rest of MacBinary header */ long FORM; long flen; long AIFF; @@ -26,19 +26,18 @@ typedef struct { char VHDR[4]; long vhlen; long oneshot, repeat; - long samples; /* 'samplesPerHiCycle' in the docs - usually 32, so - * we'll use that */ + long samples; /* 'samplesPerHiCycle' in the docs - usually 32, so + * we'll use that */ short freq; char octaves, compress; long volume; char NAME[4]; - long nlen; /* should be 64; see name[] comment */ - char name[64]; /* for simplicity, i.e. just fwrite() entiree header */ + long nlen; /* should be 64; see name[] comment */ + char name[64]; /* for simplicity, i.e. just fwrite() entiree header */ char BODY[4]; long blen; } IFF; - main(int ac, char **av) { FILE *in, *out; @@ -48,51 +47,53 @@ main(int ac, char **av) long n, len; if (ac != 3) { - fprintf(stderr, "Usage: %s input-file output-file\n", av[0]); - exit(20); + fprintf(stderr, "Usage: %s input-file output-file\n", av[0]); + exit(20); } if (!(in = fopen(av[1], "r"))) { - fprintf(stderr, "Can't open input file\n"); - exit(20); + fprintf(stderr, "Can't open input file\n"); + exit(20); } if (!(out = fopen(av[2], "w"))) { - fprintf(stderr, "Can't open output file\n"); - exit(20); + fprintf(stderr, "Can't open output file\n"); + exit(20); } fread(&aiff, sizeof(aiff), 1, in); memcpy(iff.FORM, "FORM", 4); - iff.flen = sizeof(iff) + aiff.sndlen - 8; + iff.flen = sizeof(iff) + aiff.sndlen - 8; memcpy(iff._8SVX, "8SVX", 4); memcpy(iff.VHDR, "VHDR", 4); - iff.vhlen = 20; - iff.oneshot = aiff.sndlen; - iff.repeat = 0; - iff.samples = 32; - iff.freq = 22000; - iff.octaves = 1; - iff.compress= 0; - iff.volume = 0x10000; + iff.vhlen = 20; + iff.oneshot = aiff.sndlen; + iff.repeat = 0; + iff.samples = 32; + iff.freq = 22000; + iff.octaves = 1; + iff.compress = 0; + iff.volume = 0x10000; memcpy(iff.NAME, "NAME", 4); - iff.nlen = 64; - strncpy(iff.name, aiff.name, 62); iff.name[aiff.namelen] = 0; + iff.nlen = 64; + strncpy(iff.name, aiff.name, 62); + iff.name[aiff.namelen] = 0; memcpy(iff.BODY, "BODY", 4); - iff.blen = aiff.sndlen; + iff.blen = aiff.sndlen; fwrite(&iff, sizeof(iff), 1, out); len = aiff.sndlen; do { - if (len >= sizeof(buf)) - n = fread(buf, 1, sizeof(buf), in); - else - n = fread(buf, 1, len, in); - if (n) { - fwrite(buf, 1, n, out); - len -= n; - } + if (len >= sizeof(buf)) + n = fread(buf, 1, sizeof(buf), in); + else + n = fread(buf, 1, len, in); + if (n) { + fwrite(buf, 1, n, out); + len -= n; + } } while (len && n); if (len) - fprintf(stderr, "Warning: %ld bytes of sample missing\n", len); - fclose(in); fclose(out); + fprintf(stderr, "Warning: %ld bytes of sample missing\n", len); + fclose(in); + fclose(out); exit(0); } diff --git a/sys/amiga/txt2iff.c b/sys/amiga/txt2iff.c index 72129244a..79b2081bb 100644 --- a/sys/amiga/txt2iff.c +++ b/sys/amiga/txt2iff.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 txt2iff.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 txt2iff.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 txt2iff.c $Date: 2009/05/06 10:48:31 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)txt2iff.c 3.5 1995/07/28 */ /* Copyright (c) 1995 by Gregg Wonderly, Naperville, Illinois */ @@ -20,9 +20,9 @@ #include #include #ifndef _DCC -# include -# include -# include +#include +#include +#include #endif void panic(const char *); @@ -39,36 +39,36 @@ extern int colorsinmap; */ struct { - int Height; - int Width; + int Height; + int Width; } IFFScreen; /* * We are using a hybrid form of our own design which we call a BMAP (for * bitmap) form. It is an ILBM with the bitmaps already deinterleaved, * completely uncompressed. - * This speeds the loading of the images from the games point of view because it + * This speeds the loading of the images from the games point of view because + * it * does not have to deinterleave and uncompress them. */ -#define ID_BMAP MAKE_ID( 'B', 'M', 'A', 'P' ) /* instead of ILBM */ -#define ID_BMHD MAKE_ID( 'B', 'M', 'H', 'D' ) /* Same as ILBM */ -#define ID_CAMG MAKE_ID( 'C', 'A', 'M', 'G' ) /* Same as ILBM */ -#define ID_CMAP MAKE_ID( 'C', 'M', 'A', 'P' ) /* Same as ILBM */ -#define ID_PDAT MAKE_ID( 'P', 'D', 'A', 'T' ) /* Extra data describing plane - * size due to graphics.library - * rounding requirements. - */ -#define ID_PLNE MAKE_ID( 'P', 'L', 'N', 'E' ) /* The planes of the image */ - +#define ID_BMAP MAKE_ID('B', 'M', 'A', 'P') /* instead of ILBM */ +#define ID_BMHD MAKE_ID('B', 'M', 'H', 'D') /* Same as ILBM */ +#define ID_CAMG MAKE_ID('C', 'A', 'M', 'G') /* Same as ILBM */ +#define ID_CMAP MAKE_ID('C', 'M', 'A', 'P') /* Same as ILBM */ +#define ID_PDAT \ + MAKE_ID('P', 'D', 'A', 'T') /* Extra data describing plane \ + * size due to graphics.library \ + * rounding requirements. \ + */ +#define ID_PLNE MAKE_ID('P', 'L', 'N', 'E') /* The planes of the image */ #ifndef _DCC extern #endif -struct Library *IFFParseBase; + struct Library *IFFParseBase; int nplanes; - /* BMHD from IFF documentation */ typedef struct { UWORD w, h; @@ -89,19 +89,18 @@ typedef struct { pixel pixels[TILE_Y][TILE_X]; AmiColorMap *cmap; - -int findcolor( register pixel *pix ); -void packwritebody( pixel (*tile)[TILE_X], char **planes, int tileno ); - +int findcolor(register pixel *pix); +void packwritebody(pixel (*tile)[TILE_X], char **planes, int tileno); void -error( char *str ) +error(char *str) { - fprintf( stderr, "ERROR: %s\n", str ); + fprintf(stderr, "ERROR: %s\n", str); } /* - * This array maps the image colors to the amiga's first 16 colors. The colors + * This array maps the image colors to the amiga's first 16 colors. The + * colors * are reordered to help with maintaining dripen settings. */ int colrmap[] = { 0, 6, 9, 15, 4, 10, 2, 3, 5, 11, 7, 13, 8, 1, 14, 12 }; @@ -109,65 +108,62 @@ int colrmap[] = { 0, 6, 9, 15, 4, 10, 2, 3, 5, 11, 7, 13, 8, 1, 14, 12 }; /* How many tiles fit across and down. */ #define COLS 20 -#define ROWS ((tiles + COLS-1) / COLS) +#define ROWS ((tiles + COLS - 1) / COLS) -main( int argc, char **argv ) +main(int argc, char **argv) { int colors; struct { - long nplanes; - long pbytes; - long across; - long down; - long npics; - long xsize; - long ysize; + long nplanes; + long pbytes; + long across; + long down; + long npics; + long xsize; + long ysize; } pdat; - long pbytes; /* Bytes of data in a plane */ + long pbytes; /* Bytes of data in a plane */ int i, cnt; BitMapHeader bmhd; struct IFFHandle *iff; - long camg = HIRES|LACE; - int tiles=0; + long camg = HIRES | LACE; + int tiles = 0; char **planes; - if(argc != 3){ - fprintf(stderr, "Usage: %s source destination\n", argv[0]); - exit(1); + if (argc != 3) { + fprintf(stderr, "Usage: %s source destination\n", argv[0]); + exit(1); } #if defined(_DCC) || defined(__GNUC__) - IFFParseBase = OpenLibrary( "iffparse.library", 0 ); - if( !IFFParseBase ) { - error( "unable to open iffparse.library" ); - exit( 1 ); + IFFParseBase = OpenLibrary("iffparse.library", 0); + if (!IFFParseBase) { + error("unable to open iffparse.library"); + exit(1); } #endif /* First, count the files in the file */ - if( fopen_text_file( argv[1], "r" ) != TRUE ) - { - perror( argv[1] ); - return( 1 ); + if (fopen_text_file(argv[1], "r") != TRUE) { + perror(argv[1]); + return (1); } nplanes = 0; - i = colorsinmap-1; /*IFFScreen.Colors - 1; */ - while( i != 0 ) - { - nplanes++; - i >>= 1; + i = colorsinmap - 1; /*IFFScreen.Colors - 1; */ + while (i != 0) { + nplanes++; + i >>= 1; } - planes = malloc( nplanes * sizeof( char * ) ); - if( planes == 0 ) - { - error( "can not allocate planes pointer" ); - exit( 1 ); + planes = malloc(nplanes * sizeof(char *)); + if (planes == 0) { + error("can not allocate planes pointer"); + exit(1); } - while( read_text_tile( pixels ) == TRUE ) - ++tiles; + while (read_text_tile(pixels) == TRUE) + ++tiles; fclose_text_file(); IFFScreen.Width = COLS * TILE_X; @@ -175,41 +171,36 @@ main( int argc, char **argv ) pbytes = (COLS * ROWS * TILE_X + 15) / 16 * 2 * TILE_Y; - for( i = 0; i < nplanes; ++i ) - { - planes[ i ] = calloc( 1, pbytes ); - if( planes[ i ] == 0 ) - { - error( "can not allocate planes pointer" ); - exit( 1 ); - } + for (i = 0; i < nplanes; ++i) { + planes[i] = calloc(1, pbytes); + if (planes[i] == 0) { + error("can not allocate planes pointer"); + exit(1); + } } /* Now, process it */ - if( fopen_text_file( argv[1], "r" ) != TRUE ) - { - perror( argv[1] ); - return( 1 ); + if (fopen_text_file(argv[1], "r") != TRUE) { + perror(argv[1]); + return (1); } iff = AllocIFF(); - if( !iff ) - { - error( "Can not allocate IFFHandle" ); - return( 1 ); + if (!iff) { + error("Can not allocate IFFHandle"); + return (1); } - iff->iff_Stream = Open( argv[2], MODE_NEWFILE ); - if( !iff->iff_Stream ) - { - error( "Can not open output file" ); - return( 1 ); + iff->iff_Stream = Open(argv[2], MODE_NEWFILE); + if (!iff->iff_Stream) { + error("Can not open output file"); + return (1); } - InitIFFasDOS( iff ); - OpenIFF( iff, IFFF_WRITE ); + InitIFFasDOS(iff); + OpenIFF(iff, IFFF_WRITE); - PushChunk( iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN ); + PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN); bmhd.w = IFFScreen.Width; bmhd.h = IFFScreen.Height; @@ -225,40 +216,38 @@ main( int argc, char **argv ) bmhd.pageWidth = TILE_X; bmhd.pageHeight = TILE_Y; - PushChunk( iff, ID_BMAP, ID_BMHD, sizeof( bmhd ) ); - WriteChunkBytes( iff, &bmhd, sizeof( bmhd ) ); - PopChunk( iff ); + PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd)); + WriteChunkBytes(iff, &bmhd, sizeof(bmhd)); + PopChunk(iff); - PushChunk( iff, ID_BMAP, ID_CAMG, sizeof( camg ) ); - WriteChunkBytes( iff, &camg, sizeof( camg ) ); - PopChunk( iff ); + PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg)); + WriteChunkBytes(iff, &camg, sizeof(camg)); + PopChunk(iff); /* We need to reorder the colors to get reasonable default pens but * we also need to know where some of the colors are - so go find out. */ map_colors(); - cmap = malloc( (colors = (1L<iff_Stream ); - FreeIFF( iff ); + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); - printf( "\n%d tiles converted\n", cnt ); + printf("\n%d tiles converted\n", cnt); #if defined(_DCC) || defined(__GNUC__) - CloseLibrary( IFFParseBase ); + CloseLibrary(IFFParseBase); #endif - exit( 0 ); + exit(0); } -findcolor( register pixel *pix ) +findcolor(register pixel *pix) { register int i; - for( i = 0; i < MAXCOLORMAPSIZE; ++i ) - { - if( (pix->r == ColorMap[ CM_RED ][i] ) && - (pix->g == ColorMap[ CM_GREEN ][i] ) && - (pix->b == ColorMap[ CM_BLUE ][i] ) ) - { - return( i ); - } + for (i = 0; i < MAXCOLORMAPSIZE; ++i) { + if ((pix->r == ColorMap[CM_RED][i]) + && (pix->g == ColorMap[CM_GREEN][i]) + && (pix->b == ColorMap[CM_BLUE][i])) { + return (i); + } } - return( -1 ); + return (-1); } void -packwritebody( pixel (*tile)[TILE_X], char **planes, int tileno ) +packwritebody(pixel (*tile)[TILE_X], char **planes, int tileno) { register int i, j, k, col; register char *buf; @@ -317,46 +304,43 @@ packwritebody( pixel (*tile)[TILE_X], char **planes, int tileno ) across = COLS; /* How many bytes per pixel row */ - rowbytes = ((IFFScreen.Width + 15)/16)*2; + rowbytes = ((IFFScreen.Width + 15) / 16) * 2; /* How many bytes to account for y distance in planes */ yoff = ((tileno / across) * TILE_Y) * rowbytes; /* How many bytes to account for x distance in planes */ - xoff = (tileno % across) * (TILE_X/8); + xoff = (tileno % across) * (TILE_X / 8); /* For each row... */ - for( i = 0; i < TILE_Y; ++i ) - { - /* For each bitplane... */ - for( k = 0; k < nplanes; ++k ) - { - const int mask = 1l< rate){ - bestrate = rate; - bestslot = x; - } - } + int x; + int bestslot; + int bestrate = 99999999L; + for (x = 0; x < 16; x++) { + int rr = r - ColorMap[CM_RED][x]; + int gg = g - ColorMap[CM_GREEN][x]; + int bb = b - ColorMap[CM_BLUE][x]; + int rate = rr * rr + gg * gg + bb * bb; + if (bestrate > rate) { + bestrate = rate; + bestslot = x; + } + } #ifdef DBG - printf("map (%d,%d,%d) -> %d (error=%d)\n",r,g,b,bestslot,bestrate); + printf("map (%d,%d,%d) -> %d (error=%d)\n", r, g, b, bestslot, bestrate); #endif - return bestslot; + return bestslot; } - long * -alloc( unsigned int n ) +alloc(unsigned int n) { - long *ret = malloc( n ); - if(!ret){ - error("Can't allocate memory"); - exit(1); + long *ret = malloc(n); + if (!ret) { + error("Can't allocate memory"); + exit(1); } - return( ret ); + return (ret); } void -panic(const char *msg){ - fprintf(stderr,"PANIC: %s\n",msg); +panic(const char *msg) +{ + fprintf(stderr, "PANIC: %s\n", msg); exit(1); } diff --git a/sys/amiga/winami.c b/sys/amiga/winami.c index 5e64d7afb..ad2c8cbf5 100644 --- a/sys/amiga/winami.c +++ b/sys/amiga/winami.c @@ -1,6 +1,7 @@ -/* NetHack 3.6 winami.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winami.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */ /* NetHack 3.6 winami.c $Date: 2012/01/10 17:47:21 $ $Revision: 1.13 $ */ -/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. */ +/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. + */ /* NetHack may be freely redistributed. See license for details. */ #include "NH:sys/amiga/windefs.h" @@ -10,15 +11,15 @@ #ifdef AMIGA_INTUITION -static int FDECL( put_ext_cmd, ( char *, int, struct amii_WinDesc *, int ) ); +static int FDECL(put_ext_cmd, (char *, int, struct amii_WinDesc *, int)); -struct amii_DisplayDesc *amiIDisplay; /* the Amiga Intuition descriptor */ +struct amii_DisplayDesc *amiIDisplay; /* the Amiga Intuition descriptor */ struct Rectangle lastinvent, lastmsg; int clipping = 0; -int clipx=0; -int clipy=0; -int clipxmax=0; -int clipymax=0; +int clipx = 0; +int clipy = 0; +int clipxmax = 0; +int clipymax = 0; int scrollmsg = 1; int alwaysinvent = 0; int amii_numcolors; @@ -27,71 +28,36 @@ long amii_scrnmode; /* Interface definition, for use by windows.c and winprocs.h to provide * the intuition interface for the amiga... */ -struct window_procs amii_procs = -{ - "amii", - WC_COLOR|WC_HILITE_PET|WC_INVERSE, - 0L, - amii_init_nhwindows, - amii_player_selection, - amii_askname, - amii_get_nh_event, - amii_exit_nhwindows, - amii_suspend_nhwindows, - amii_resume_nhwindows, - amii_create_nhwindow, - amii_clear_nhwindow, - amii_display_nhwindow, - amii_destroy_nhwindow, - amii_curs, - amii_putstr, - genl_putmixed, - amii_display_file, - amii_start_menu, - amii_add_menu, - amii_end_menu, - amii_select_menu, - genl_message_menu, - amii_update_inventory, - amii_mark_synch, - amii_wait_synch, +struct window_procs amii_procs = { + "amii", WC_COLOR | WC_HILITE_PET | WC_INVERSE, 0L, amii_init_nhwindows, + amii_player_selection, amii_askname, amii_get_nh_event, + amii_exit_nhwindows, amii_suspend_nhwindows, amii_resume_nhwindows, + amii_create_nhwindow, amii_clear_nhwindow, amii_display_nhwindow, + amii_destroy_nhwindow, amii_curs, amii_putstr, genl_putmixed, + amii_display_file, amii_start_menu, amii_add_menu, amii_end_menu, + amii_select_menu, genl_message_menu, amii_update_inventory, + amii_mark_synch, amii_wait_synch, #ifdef CLIPPING amii_cliparound, #endif #ifdef POSITIONBAR donull, #endif - amii_print_glyph, - amii_raw_print, - amii_raw_print_bold, - amii_nhgetch, - amii_nh_poskey, - amii_bell, - amii_doprev_message, - amii_yn_function, - amii_getlin, - amii_get_ext_cmd, - amii_number_pad, - amii_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - amii_change_color, - amii_get_color_string, + amii_print_glyph, amii_raw_print, amii_raw_print_bold, amii_nhgetch, + amii_nh_poskey, amii_bell, amii_doprev_message, amii_yn_function, + amii_getlin, amii_get_ext_cmd, amii_number_pad, amii_delay_output, +#ifdef CHANGE_COLOR /* only a Mac option currently */ + amii_change_color, amii_get_color_string, #endif /* other defs that really should go away (they're tty specific) */ - amii_delay_output, - amii_delay_output, - amii_outrip, - genl_preference_update, - genl_getmsghistory, - genl_putmsghistory, + amii_delay_output, amii_delay_output, amii_outrip, genl_preference_update, + genl_getmsghistory, genl_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, + genl_status_init, genl_status_finish, genl_status_enablefield, genl_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES genl_status_threshold, -# endif +#endif #endif genl_can_suspend_yes, }; @@ -99,79 +65,43 @@ struct window_procs amii_procs = /* The view window layout uses the same function names so we can use * a shared library to allow the executable to be smaller. */ -struct window_procs amiv_procs = -{ - "amitile", - WC_COLOR|WC_HILITE_PET|WC_INVERSE, - 0L, - amii_init_nhwindows, - amii_player_selection, - amii_askname, - amii_get_nh_event, - amii_exit_nhwindows, - amii_suspend_nhwindows, - amii_resume_nhwindows, - amii_create_nhwindow, - amii_clear_nhwindow, - amii_display_nhwindow, - amii_destroy_nhwindow, - amii_curs, - amii_putstr, - genl_putmixed, - amii_display_file, - amii_start_menu, - amii_add_menu, - amii_end_menu, - amii_select_menu, - genl_message_menu, - amii_update_inventory, - amii_mark_synch, - amii_wait_synch, +struct window_procs amiv_procs = { + "amitile", WC_COLOR | WC_HILITE_PET | WC_INVERSE, 0L, amii_init_nhwindows, + amii_player_selection, amii_askname, amii_get_nh_event, + amii_exit_nhwindows, amii_suspend_nhwindows, amii_resume_nhwindows, + amii_create_nhwindow, amii_clear_nhwindow, amii_display_nhwindow, + amii_destroy_nhwindow, amii_curs, amii_putstr, genl_putmixed, + amii_display_file, amii_start_menu, amii_add_menu, amii_end_menu, + amii_select_menu, genl_message_menu, amii_update_inventory, + amii_mark_synch, amii_wait_synch, #ifdef CLIPPING amii_cliparound, #endif #ifdef POSITIONBAR donull, #endif - amii_print_glyph, - amii_raw_print, - amii_raw_print_bold, - amii_nhgetch, - amii_nh_poskey, - amii_bell, - amii_doprev_message, - amii_yn_function, - amii_getlin, - amii_get_ext_cmd, - amii_number_pad, - amii_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - amii_change_color, - amii_get_color_string, + amii_print_glyph, amii_raw_print, amii_raw_print_bold, amii_nhgetch, + amii_nh_poskey, amii_bell, amii_doprev_message, amii_yn_function, + amii_getlin, amii_get_ext_cmd, amii_number_pad, amii_delay_output, +#ifdef CHANGE_COLOR /* only a Mac option currently */ + amii_change_color, amii_get_color_string, #endif /* other defs that really should go away (they're tty specific) */ - amii_delay_output, - amii_delay_output, - amii_outrip, - genl_preference_update, - genl_getmsghistory, - genl_putmsghistory, + amii_delay_output, amii_delay_output, amii_outrip, genl_preference_update, + genl_getmsghistory, genl_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, + genl_status_init, genl_status_finish, genl_status_enablefield, genl_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES genl_status_threshold, -# endif +#endif #endif genl_can_suspend_yes, }; -unsigned short amii_initmap[ AMII_MAXCOLORS ]; +unsigned short amii_initmap[AMII_MAXCOLORS]; /* Default pens used unless user overides in nethack.cnf. */ -unsigned short amii_init_map[ AMII_MAXCOLORS ] = -{ +unsigned short amii_init_map[AMII_MAXCOLORS] = { 0x0000, /* color #0 C_BLACK */ 0x0FFF, /* color #1 C_WHITE */ 0x0830, /* color #2 C_BROWN */ @@ -182,8 +112,7 @@ unsigned short amii_init_map[ AMII_MAXCOLORS ] = 0x0c00, /* color #7 C_RED */ }; -unsigned short amiv_init_map[ AMII_MAXCOLORS ] = -{ +unsigned short amiv_init_map[AMII_MAXCOLORS] = { 0x0000, /* color #0 C_BLACK */ 0x0fff, /* color #1 C_WHITE */ 0x00bf, /* color #2 C_CYAN */ @@ -220,11 +149,12 @@ unsigned short amiv_init_map[ AMII_MAXCOLORS ] = 0x0fff, /* color #31 */ }; -#if !defined( TTY_GRAPHICS ) || defined( SHAREDLIB ) /* this should be shared better */ -char morc; /* the character typed in response to a --more-- prompt */ +#if !defined(TTY_GRAPHICS) \ + || defined(SHAREDLIB) /* this should be shared better */ +char morc; /* the character typed in response to a --more-- prompt */ #endif -char spaces[ 76 ] = -" "; +char spaces[76] = " " + " "; winid WIN_BASE = WIN_ERR; winid WIN_OVER = WIN_ERR; @@ -240,39 +170,38 @@ int txwidth = FONTWIDTH, txheight = FONTHEIGHT, txbaseline = FONTBASELINE; int bigscreen = 0; /* This gadget data is replicated for menu/text windows... */ -struct PropInfo PropScroll = { AUTOKNOB|FREEVERT, - 0xffff,0xffff, 0xffff,0xffff, }; -struct Image Image1 = { 0,0, 7,102, 0, NULL, 0x0000,0x0000, NULL }; -struct Gadget MenuScroll = { - NULL, -15,10, 15,-19, GRELRIGHT|GRELHEIGHT, - RELVERIFY|FOLLOWMOUSE|RIGHTBORDER|GADGIMMEDIATE|RELVERIFY, - PROPGADGET, (APTR)&Image1, NULL, NULL, NULL, (APTR)&PropScroll, - 1, NULL +struct PropInfo PropScroll = { + AUTOKNOB | FREEVERT, 0xffff, 0xffff, 0xffff, 0xffff, }; +struct Image Image1 = { 0, 0, 7, 102, 0, NULL, 0x0000, 0x0000, NULL }; +struct Gadget MenuScroll = { NULL, -15, 10, 15, -19, GRELRIGHT | GRELHEIGHT, + RELVERIFY | FOLLOWMOUSE | RIGHTBORDER + | GADGIMMEDIATE | RELVERIFY, + PROPGADGET, (APTR) &Image1, NULL, NULL, NULL, + (APTR) &PropScroll, 1, NULL }; /* This gadget is for the message window... */ -struct PropInfo MsgPropScroll = { AUTOKNOB|FREEVERT, - 0xffff,0xffff, 0xffff,0xffff, }; -struct Image MsgImage1 = { 0,0, 7,102, 0, NULL, 0x0000,0x0000, NULL }; -struct Gadget MsgScroll = { - NULL, -15,10, 14,-19, GRELRIGHT|GRELHEIGHT, - RELVERIFY|FOLLOWMOUSE|RIGHTBORDER|GADGIMMEDIATE|RELVERIFY, - PROPGADGET, (APTR)&MsgImage1, NULL, NULL, NULL, (APTR)&MsgPropScroll, - 1, NULL +struct PropInfo MsgPropScroll = { + AUTOKNOB | FREEVERT, 0xffff, 0xffff, 0xffff, 0xffff, }; +struct Image MsgImage1 = { 0, 0, 7, 102, 0, NULL, 0x0000, 0x0000, NULL }; +struct Gadget MsgScroll = { NULL, -15, 10, 14, -19, GRELRIGHT | GRELHEIGHT, + RELVERIFY | FOLLOWMOUSE | RIGHTBORDER + | GADGIMMEDIATE | RELVERIFY, + PROPGADGET, (APTR) &MsgImage1, NULL, NULL, NULL, + (APTR) &MsgPropScroll, 1, NULL }; -int wincnt=0; /* # of nh windows opened */ +int wincnt = 0; /* # of nh windows opened */ /* We advertise a public screen to allow some people to do other things * while they are playing... like compiling... */ -#ifdef INTUI_NEW_LOOK +#ifdef INTUI_NEW_LOOK extern struct Hook fillhook; -struct TagItem tags[] = -{ - { WA_BackFill, (ULONG)&fillhook }, - { WA_PubScreenName, (ULONG)"NetHack" }, +struct TagItem tags[] = { + { WA_BackFill, (ULONG) &fillhook }, + { WA_PubScreenName, (ULONG) "NetHack" }, { TAG_DONE, 0 }, }; #endif @@ -282,184 +211,208 @@ struct TagItem tags[] = * data here is generally changed in create_nhwindow(), so beware that * what you see here may not be exactly what you get. */ -struct win_setup new_wins[] = -{ +struct win_setup new_wins[] = { /* First entry not used, types are based at 1 */ - {{0}}, + { { 0 } }, /* NHW_MESSAGE */ - {{0,1,640,11, - 0xff,0xff, - NEWSIZE|GADGETUP|GADGETDOWN|MOUSEMOVE|MOUSEBUTTONS|RAWKEY, - BORDERLESS|ACTIVATE|SMART_REFRESH -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 0, 1, 640, 11, 0xff, 0xff, + NEWSIZE | GADGETUP | GADGETDOWN | MOUSEMOVE | MOUSEBUTTONS | RAWKEY, + BORDERLESS | ACTIVATE | SMART_REFRESH +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - NULL,NULL,(UBYTE*)"Messages",NULL,NULL,320,40,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + NULL, NULL, (UBYTE *) "Messages", NULL, NULL, 320, 40, 0xffff, 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,1,1,80,80}, + }, + 0, + 0, + 1, + 1, + 80, + 80 }, /* NHW_STATUS */ - {{0,181,640,24, - 0xff,0xff, - RAWKEY|MENUPICK|DISKINSERTED, - BORDERLESS|ACTIVATE|SMART_REFRESH|BACKDROP -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 0, 181, 640, 24, 0xff, 0xff, RAWKEY | MENUPICK | DISKINSERTED, + BORDERLESS | ACTIVATE | SMART_REFRESH | BACKDROP +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - NULL,NULL,(UBYTE*)"Game Status",NULL,NULL,0,0,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + NULL, NULL, (UBYTE *) "Game Status", NULL, NULL, 0, 0, 0xffff, 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,2,2,78,78}, + }, + 0, + 0, + 2, + 2, + 78, + 78 }, /* NHW_MAP */ - {{0,0,WIDTH,WINDOWHEIGHT, - 0xff,0xff, - RAWKEY|MENUPICK|MOUSEBUTTONS|ACTIVEWINDOW|MOUSEMOVE, - BORDERLESS|ACTIVATE|SMART_REFRESH|BACKDROP -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 0, 0, WIDTH, WINDOWHEIGHT, 0xff, 0xff, + RAWKEY | MENUPICK | MOUSEBUTTONS | ACTIVEWINDOW | MOUSEMOVE, + BORDERLESS | ACTIVATE | SMART_REFRESH | BACKDROP +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - NULL,NULL,(UBYTE*)"Dungeon Map",NULL,NULL,64,64,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + NULL, NULL, (UBYTE *) "Dungeon Map", NULL, NULL, 64, 64, 0xffff, + 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,22,22,80,80}, + }, + 0, + 0, + 22, + 22, + 80, + 80 }, /* NHW_MENU */ - {{400,10,10,10, - 0xff,0xff, - RAWKEY|MENUPICK|DISKINSERTED|MOUSEMOVE|MOUSEBUTTONS| - GADGETUP|GADGETDOWN|CLOSEWINDOW|VANILLAKEY|NEWSIZE|INACTIVEWINDOW, - WINDOWSIZING|WINDOWCLOSE|WINDOWDRAG|ACTIVATE|SMART_REFRESH -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 400, 10, 10, 10, 0xff, 0xff, + RAWKEY | MENUPICK | DISKINSERTED | MOUSEMOVE | MOUSEBUTTONS | GADGETUP + | GADGETDOWN | CLOSEWINDOW | VANILLAKEY | NEWSIZE + | INACTIVEWINDOW, + WINDOWSIZING | WINDOWCLOSE | WINDOWDRAG | ACTIVATE | SMART_REFRESH +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - &MenuScroll,NULL,NULL,NULL,NULL,64,32,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + &MenuScroll, NULL, NULL, NULL, NULL, 64, 32, 0xffff, 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,1,1,22,78}, + }, + 0, + 0, + 1, + 1, + 22, + 78 }, /* NHW_TEXT */ - {{0,0,640,200, - 0xff,0xff, - RAWKEY|MENUPICK|DISKINSERTED|MOUSEMOVE| - GADGETUP|CLOSEWINDOW|VANILLAKEY|NEWSIZE, - WINDOWSIZING|WINDOWCLOSE|WINDOWDRAG|ACTIVATE|SMART_REFRESH -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 0, 0, 640, 200, 0xff, 0xff, + RAWKEY | MENUPICK | DISKINSERTED | MOUSEMOVE | GADGETUP | CLOSEWINDOW + | VANILLAKEY | NEWSIZE, + WINDOWSIZING | WINDOWCLOSE | WINDOWDRAG | ACTIVATE | SMART_REFRESH +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - &MenuScroll,NULL,(UBYTE*)NULL,NULL,NULL,100,32,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + &MenuScroll, NULL, (UBYTE *) NULL, NULL, NULL, 100, 32, 0xffff, + 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,1,1,22,78}, + }, + 0, + 0, + 1, + 1, + 22, + 78 }, /* NHW_BASE */ - {{0,0,WIDTH,WINDOWHEIGHT, - 0xff,0xff, - RAWKEY|MENUPICK|MOUSEBUTTONS, - BORDERLESS|ACTIVATE|SMART_REFRESH|BACKDROP -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 0, 0, WIDTH, WINDOWHEIGHT, 0xff, 0xff, + RAWKEY | MENUPICK | MOUSEBUTTONS, + BORDERLESS | ACTIVATE | SMART_REFRESH | BACKDROP +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - NULL,NULL,(UBYTE*)NULL,NULL,NULL,-1,-1,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + NULL, NULL, (UBYTE *) NULL, NULL, NULL, -1, -1, 0xffff, 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,22,22,80,80}, + }, + 0, + 0, + 22, + 22, + 80, + 80 }, /* NHW_OVER */ - {{320,20,319,179, - 0xff,0xff, - RAWKEY|MENUPICK|MOUSEBUTTONS, - BORDERLESS|ACTIVATE|SMART_REFRESH|BACKDROP -#ifdef INTUI_NEW_LOOK - |WFLG_NW_EXTENDED + { { 320, 20, 319, 179, 0xff, 0xff, RAWKEY | MENUPICK | MOUSEBUTTONS, + BORDERLESS | ACTIVATE | SMART_REFRESH | BACKDROP +#ifdef INTUI_NEW_LOOK + | WFLG_NW_EXTENDED #endif - , - NULL,NULL,(UBYTE*)NULL,NULL,NULL,64,32,0xffff,0xffff, -#ifdef INTUI_NEW_LOOK - PUBLICSCREEN,tags + , + NULL, NULL, (UBYTE *) NULL, NULL, NULL, 64, 32, 0xffff, 0xffff, +#ifdef INTUI_NEW_LOOK + PUBLICSCREEN, tags #else - CUSTOMSCREEN + CUSTOMSCREEN #endif - }, - 0,0,22,22,80,80}, + }, + 0, + 0, + 22, + 22, + 80, + 80 }, }; const char winpanicstr[] = "Bad winid %d in %s()"; /* The opened windows information */ -struct amii_WinDesc *amii_wins[ MAXWIN + 1 ]; +struct amii_WinDesc *amii_wins[MAXWIN + 1]; -#ifdef INTUI_NEW_LOOK +#ifdef INTUI_NEW_LOOK /* * NUMDRIPENS varies based on headers, so don't use it * here, its value is used elsewhere. */ -UWORD amii_defpens[ 20 ]; +UWORD amii_defpens[20]; -struct TagItem scrntags[] = -{ - { SA_PubName, (ULONG)"NetHack" }, +struct TagItem scrntags[] = { + { SA_PubName, (ULONG) "NetHack" }, { SA_Overscan, OSCAN_TEXT }, { SA_AutoScroll, TRUE }, #if LIBRARY_VERSION >= 39 { SA_Interleaved, TRUE }, #endif - { SA_Pens, (ULONG)0 }, + { SA_Pens, (ULONG) 0 }, { SA_DisplayID, 0 }, { TAG_DONE, 0 }, }; #endif -struct NewScreen NewHackScreen = -{ - 0, 0, WIDTH, SCREENHEIGHT, 3, - 0, 1, /* DetailPen, BlockPen */ - HIRES, - CUSTOMSCREEN -#ifdef INTUI_NEW_LOOK - |NS_EXTENDED +struct NewScreen NewHackScreen = { 0, 0, WIDTH, SCREENHEIGHT, 3, 0, + 1, /* DetailPen, BlockPen */ + HIRES, CUSTOMSCREEN +#ifdef INTUI_NEW_LOOK + | NS_EXTENDED #endif - , - &Hack80, /* Font */ - NULL, /*(UBYTE *)" NetHack X.Y.Z" */ - NULL, /* Gadgets */ - NULL, /* CustomBitmap */ -#ifdef INTUI_NEW_LOOK - scrntags + , + &Hack80, /* Font */ + NULL, /*(UBYTE *)" NetHack X.Y.Z" */ + NULL, /* Gadgets */ + NULL, /* CustomBitmap */ +#ifdef INTUI_NEW_LOOK + scrntags #endif }; @@ -475,17 +428,16 @@ amii_askname() char plnametmp[300]; /* From winreq.c: sizeof(StrStringSIBuff) */ *plnametmp = 0; do { - amii_getlin( "Who are you?", plnametmp ); - } while( strlen( plnametmp ) == 0 ); + amii_getlin("Who are you?", plnametmp); + } while (strlen(plnametmp) == 0); - strncpy(plname, plnametmp, PL_NSIZ-1); /* Avoid overflowing plname[] */ - plname[PL_NSIZ-1] = 0; + strncpy(plname, plnametmp, PL_NSIZ - 1); /* Avoid overflowing plname[] */ + plname[PL_NSIZ - 1] = 0; - if( *plname == '\33' ) - { - clearlocks(); - exit_nhwindows(NULL); - terminate(0); + if (*plname == '\33') { + clearlocks(); + exit_nhwindows(NULL); + terminate(0); } } @@ -515,7 +467,7 @@ amii_player_selection() } #if 0 /* Don't query the user ... instead give random character -jhsa */ -#if 0 /* OBSOLETE */ +#if 0 /* OBSOLETE */ if( *pl_character ){ pl_character[ 0 ] = toupper( pl_character[ 0 ] ); if( index( pl_classes, pl_character[ 0 ] ) ) @@ -539,7 +491,7 @@ amii_player_selection() if( WINVERS_AMIV ) { -# ifdef INTUI_NEW_LOOK +#ifdef INTUI_NEW_LOOK Type_NewWindowStructure1.Extension = wintags; Type_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; fillhook.h_Entry = (ULONG(*)())LayerFillHook; @@ -578,7 +530,7 @@ amii_player_selection() else if( code == ' ' || code == '\n' || code == '\r' ) { flags.initrole = randrole(); -#if 0 /* OBSOLETE */ +#if 0 /* OBSOLETE */ strcpy( pl_character, roles[ rnd( 11 ) ] ); #endif aredone = 1; @@ -603,7 +555,7 @@ amii_player_selection() { case 1: /* Random Character */ flags.initrole = randrole(); -#if 0 /* OBSOLETE */ +#if 0 /* OBSOLETE */ strcpy( pl_character, roles[ rnd( 11 ) ] ); #endif amii_clear_nhwindow( WIN_BASE ); @@ -712,7 +664,7 @@ allocerr: if( WINVERS_AMIV ) { -#ifdef INTUI_NEW_LOOK +#ifdef INTUI_NEW_LOOK Rnd_NewWindowStructure1.Extension = wintags; Rnd_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; fillhook.h_Entry = (ULONG(*)())LayerFillHook; @@ -793,7 +745,7 @@ flush_output(){} */ * when enough characters have been entered to make a unique command. */ int -amii_get_ext_cmd( void ) +amii_get_ext_cmd(void) { menu_item *mip; anything id; @@ -806,322 +758,283 @@ amii_get_ext_cmd( void ) int colx; int bottom = 0; struct Window *w; - char obufp[ 100 ]; + char obufp[100]; register char *bufp = obufp; register int c; int com_index, oindex; - int did_comp=0; /* did successful completion? */ + int did_comp = 0; /* did successful completion? */ int sel = -1; - if( WIN_MESSAGE == WIN_ERR || ( cw = amii_wins[ WIN_MESSAGE ] ) == NULL ) - panic(winpanicstr, WIN_MESSAGE, "get_ext_cmd"); + if (WIN_MESSAGE == WIN_ERR || (cw = amii_wins[WIN_MESSAGE]) == NULL) + panic(winpanicstr, WIN_MESSAGE, "get_ext_cmd"); w = cw->win; - bottom = amii_msgborder( w ); + bottom = amii_msgborder(w); colx = 3; -#ifdef EXTMENU +#ifdef EXTMENU if (iflags.extmenu) { - win = amii_create_nhwindow( NHW_MENU ); - amii_start_menu( win ); - pline("#"); - amii_putstr( WIN_MESSAGE, -1, " " ); + win = amii_create_nhwindow(NHW_MENU); + amii_start_menu(win); + pline("#"); + amii_putstr(WIN_MESSAGE, -1, " "); - for( i = 0; extcmdlist[ i ].ef_txt != NULL; ++i ) - { - id.a_char = *extcmdlist[ i ].ef_txt; - sprintf( buf, "%-10s - %s ", - extcmdlist[ i ].ef_txt, - extcmdlist[ i ].ef_desc ); - amii_add_menu( win, NO_GLYPH, &id, extcmdlist[i].ef_txt[0], 0, 0, buf, MENU_UNSELECTED); - } + for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { + id.a_char = *extcmdlist[i].ef_txt; + sprintf(buf, "%-10s - %s ", extcmdlist[i].ef_txt, + extcmdlist[i].ef_desc); + amii_add_menu(win, NO_GLYPH, &id, extcmdlist[i].ef_txt[0], 0, 0, + buf, MENU_UNSELECTED); + } - amii_end_menu( win, (char*)0 ); - sel = amii_select_menu( win, PICK_ONE, &mip ); - amii_destroy_nhwindow( win ); + amii_end_menu(win, (char *) 0); + sel = amii_select_menu(win, PICK_ONE, &mip); + amii_destroy_nhwindow(win); - if( sel == 1 ) - { - sel = mip->item.a_char; - for( i = 0; extcmdlist[ i ].ef_txt != NULL; ++i ) - { - if( sel == extcmdlist[i].ef_txt[0] ) - break; - } + if (sel == 1) { + sel = mip->item.a_char; + for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { + if (sel == extcmdlist[i].ef_txt[0]) + break; + } - /* copy in the text */ - if( extcmdlist[ i ].ef_txt != NULL ) - { - amii_clear_nhwindow( WIN_MESSAGE ); - (void) put_ext_cmd( (char *)extcmdlist[i].ef_txt, 0, cw, bottom ); - return( i ); - } - else - DisplayBeep( NULL ); - } + /* copy in the text */ + if (extcmdlist[i].ef_txt != NULL) { + amii_clear_nhwindow(WIN_MESSAGE); + (void) put_ext_cmd((char *) extcmdlist[i].ef_txt, 0, cw, + bottom); + return (i); + } else + DisplayBeep(NULL); + } - return( -1 ); + return (-1); } else { #else - amii_clear_nhwindow( WIN_MESSAGE ); /* Was NHW_MESSAGE */ - if( scrollmsg ) - { - pline("#"); - amii_addtopl(" "); - } - else - { - pline("# "); + amii_clear_nhwindow(WIN_MESSAGE); /* Was NHW_MESSAGE */ + if (scrollmsg) { + pline("#"); + amii_addtopl(" "); + } else { + pline("# "); } sel = -1; - while((c = WindowGetchar()) != EOF) - { - amii_curs( WIN_MESSAGE, colx, bottom ); - if(c == '?' ) - { - int win, i; - char buf[ 100 ]; + while ((c = WindowGetchar()) != EOF) { + amii_curs(WIN_MESSAGE, colx, bottom); + if (c == '?') { + int win, i; + char buf[100]; - if(did_comp){ - while(bufp!=obufp) - { - bufp--; - amii_curs(WIN_MESSAGE, --colx, bottom); - Text(w->RPort,spaces,1); - amii_curs(WIN_MESSAGE,colx,bottom); - did_comp=0; - } - } + if (did_comp) { + while (bufp != obufp) { + bufp--; + amii_curs(WIN_MESSAGE, --colx, bottom); + Text(w->RPort, spaces, 1); + amii_curs(WIN_MESSAGE, colx, bottom); + did_comp = 0; + } + } - win = amii_create_nhwindow( NHW_MENU ); - amii_start_menu( win ); + win = amii_create_nhwindow(NHW_MENU); + amii_start_menu(win); - for( i = 0; extcmdlist[ i ].ef_txt != NULL; ++i ) - { - id.a_char = extcmdlist[i].ef_txt[0]; - sprintf( buf, "%-10s - %s ", - extcmdlist[ i ].ef_txt, - extcmdlist[ i ].ef_desc ); - amii_add_menu( win, NO_GLYPH, &id, extcmdlist[i].ef_txt[0], 0, - 0, buf, MENU_UNSELECTED); - } + for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { + id.a_char = extcmdlist[i].ef_txt[0]; + sprintf(buf, "%-10s - %s ", extcmdlist[i].ef_txt, + extcmdlist[i].ef_desc); + amii_add_menu(win, NO_GLYPH, &id, extcmdlist[i].ef_txt[0], 0, + 0, buf, MENU_UNSELECTED); + } - amii_end_menu( win, (char*)0 ); - sel = amii_select_menu( win, PICK_ONE, &mip ); - amii_destroy_nhwindow( win ); + amii_end_menu(win, (char *) 0); + sel = amii_select_menu(win, PICK_ONE, &mip); + amii_destroy_nhwindow(win); - if( sel == 0 ) - { - return( -1 ); - } - else - { - sel = mip->item.a_char; - for( i = 0; extcmdlist[ i ].ef_txt != NULL; ++i ) - { - if( sel == extcmdlist[i].ef_txt[0] ) - break; - } + if (sel == 0) { + return (-1); + } else { + sel = mip->item.a_char; + for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { + if (sel == extcmdlist[i].ef_txt[0]) + break; + } - /* copy in the text */ - if( extcmdlist[ i ].ef_txt != NULL ) - { - amii_clear_nhwindow( WIN_MESSAGE ); - strcpy( bufp = obufp, extcmdlist[ i ].ef_txt ); - (void) put_ext_cmd( obufp, colx, cw, bottom ); - return( i ); - } - else - DisplayBeep( NULL ); - } - } - else if(c == '\033') - { - return( -1 ); - } - else if(c == '\b') - { - if(did_comp){ - while(bufp!=obufp){ - bufp--; - amii_curs(WIN_MESSAGE, --colx, bottom); - Text(w->RPort,spaces,1); - amii_curs(WIN_MESSAGE,colx,bottom); - did_comp=0; - sel = -1; - } - } - else if(bufp != obufp) - { - sel = -1; - bufp--; - amii_curs( WIN_MESSAGE, --colx, bottom); - Text( w->RPort, spaces, 1 ); - amii_curs( WIN_MESSAGE, colx, bottom); - } - else - DisplayBeep( NULL ); - } - else if( c == '\n' || c == '\r' ) - { - return(sel); - } - else if( c >= ' ' && c < '\177') - { - /* avoid isprint() - some people don't have it - ' ' is not always a printing char */ - *bufp = c; - bufp[1] = 0; - oindex = 0; - com_index = -1; + /* copy in the text */ + if (extcmdlist[i].ef_txt != NULL) { + amii_clear_nhwindow(WIN_MESSAGE); + strcpy(bufp = obufp, extcmdlist[i].ef_txt); + (void) put_ext_cmd(obufp, colx, cw, bottom); + return (i); + } else + DisplayBeep(NULL); + } + } else if (c == '\033') { + return (-1); + } else if (c == '\b') { + if (did_comp) { + while (bufp != obufp) { + bufp--; + amii_curs(WIN_MESSAGE, --colx, bottom); + Text(w->RPort, spaces, 1); + amii_curs(WIN_MESSAGE, colx, bottom); + did_comp = 0; + sel = -1; + } + } else if (bufp != obufp) { + sel = -1; + bufp--; + amii_curs(WIN_MESSAGE, --colx, bottom); + Text(w->RPort, spaces, 1); + amii_curs(WIN_MESSAGE, colx, bottom); + } else + DisplayBeep(NULL); + } else if (c == '\n' || c == '\r') { + return (sel); + } else if (c >= ' ' && c < '\177') { + /* avoid isprint() - some people don't have it + ' ' is not always a printing char */ + *bufp = c; + bufp[1] = 0; + oindex = 0; + com_index = -1; - while(extcmdlist[oindex].ef_txt != NULL) - { - if(!strnicmp(obufp, (char *)extcmdlist[oindex].ef_txt, strlen(obufp))) - { - if(com_index == -1) /* No matches yet*/ - com_index = oindex; - else /* More than 1 match */ - com_index = -2; - } - oindex++; - } + while (extcmdlist[oindex].ef_txt != NULL) { + if (!strnicmp(obufp, (char *) extcmdlist[oindex].ef_txt, + strlen(obufp))) { + if (com_index == -1) /* No matches yet*/ + com_index = oindex; + else /* More than 1 match */ + com_index = -2; + } + oindex++; + } - if(com_index >= 0 && *obufp ) - { - Strcpy(obufp, extcmdlist[com_index].ef_txt); - /* finish printing our string */ - colx = put_ext_cmd( obufp, colx, cw, bottom ); - bufp = obufp; /* reset it */ - if(strlen(obufp) < BUFSZ-1 && strlen(obufp) < COLNO) - bufp += strlen(obufp); - did_comp=1; - sel = com_index; - } - else - { - colx = put_ext_cmd( obufp, colx, cw, bottom ); - if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO) - bufp++; - } - } - else if(c == ('X'-64) || c == '\177') - { - colx = 0; - amii_clear_nhwindow( WIN_MESSAGE ); - pline( "# " ); - bufp = obufp; - } else - DisplayBeep( NULL ); + if (com_index >= 0 && *obufp) { + Strcpy(obufp, extcmdlist[com_index].ef_txt); + /* finish printing our string */ + colx = put_ext_cmd(obufp, colx, cw, bottom); + bufp = obufp; /* reset it */ + if (strlen(obufp) < BUFSZ - 1 && strlen(obufp) < COLNO) + bufp += strlen(obufp); + did_comp = 1; + sel = com_index; + } else { + colx = put_ext_cmd(obufp, colx, cw, bottom); + if (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO) + bufp++; + } + } else if (c == ('X' - 64) || c == '\177') { + colx = 0; + amii_clear_nhwindow(WIN_MESSAGE); + pline("# "); + bufp = obufp; + } else + DisplayBeep(NULL); } - return(-1); + return (-1); #endif -} + } -static int -put_ext_cmd( obufp, colx, cw, bottom ) - char *obufp; + static int put_ext_cmd(obufp, colx, cw, bottom) char * obufp; int colx, bottom; struct amii_WinDesc *cw; -{ - struct Window *w = cw->win; - char *t; - - t = (char *)alloc( strlen( obufp ) + 7 ); - if( t != NULL ) { - if( scrollmsg ) - { - sprintf( t, "xxx%s", obufp ); - t[0] = 1; - t[1] = 1; - t[2] = '#'; - amii_curs( WIN_MESSAGE, 0, bottom); - SetAPen( w->RPort, C_WHITE ); - Text(w->RPort, "># ", 3 ); - /* SetAPen( w->RPort, C_BLACK ); */ /* Black text on black screen doesn't look too well ... -jhsa */ - Text(w->RPort, t+3, strlen( t ) - 3 ); - } - else - { - sprintf( t, "# %s", obufp ); - amii_curs( WIN_MESSAGE, 0, bottom); - SetAPen( w->RPort, C_WHITE ); - Text(w->RPort, t, strlen( t ) ); - } - if( scrollmsg ) - SetAPen( w->RPort, C_WHITE ); - if( cw->data[ cw->maxrow - 1 ] ) - free( cw->data[ cw->maxrow - 1 ] ); - cw->data[ cw->maxrow - 1 ] = t; + struct Window *w = cw->win; + char *t; + + t = (char *) alloc(strlen(obufp) + 7); + if (t != NULL) { + if (scrollmsg) { + sprintf(t, "xxx%s", obufp); + t[0] = 1; + t[1] = 1; + t[2] = '#'; + amii_curs(WIN_MESSAGE, 0, bottom); + SetAPen(w->RPort, C_WHITE); + Text(w->RPort, "># ", 3); + /* SetAPen( w->RPort, C_BLACK ); */ /* Black text on black + screen doesn't look too + well ... -jhsa */ + Text(w->RPort, t + 3, strlen(t) - 3); + } else { + sprintf(t, "# %s", obufp); + amii_curs(WIN_MESSAGE, 0, bottom); + SetAPen(w->RPort, C_WHITE); + Text(w->RPort, t, strlen(t)); + } + if (scrollmsg) + SetAPen(w->RPort, C_WHITE); + if (cw->data[cw->maxrow - 1]) + free(cw->data[cw->maxrow - 1]); + cw->data[cw->maxrow - 1] = t; + } else { + amii_curs(WIN_MESSAGE, 0, bottom); + SetAPen(w->RPort, C_WHITE); + Text(w->RPort, "# ", 2); + /* SetAPen( w->RPort, C_BLACK ); */ /* Black on black ... -jhsa */ + Text(w->RPort, obufp, strlen(obufp)); + SetAPen(w->RPort, C_WHITE); + } + amii_curs(WIN_MESSAGE, colx = strlen(obufp) + 3 + (scrollmsg != 0), + bottom); + return (colx); } - else + + /* Ask a question and get a response */ + + char amii_yn_function(query, resp, def) const char * query, *resp; + char def; + /* + * Generic yes/no function. 'def' is the default (returned by space or + * return; 'esc' returns 'q', or 'n', or the default, depending on + * what's in the string. The 'query' string is printed before the user + * is asked about the string. + * If resp is NULL, any single character is accepted and returned. + * If not-NULL, only characters in it are allowed (exceptions: the + * quitchars are always allowed, and if it contains '#' then digits + * are allowed); if it includes an , anything beyond that won't + * be shown in the prompt to the user but will be acceptable as input. + */ { - amii_curs( WIN_MESSAGE, 0, bottom); - SetAPen( w->RPort, C_WHITE ); - Text(w->RPort, "# ", 2 ); - /* SetAPen( w->RPort, C_BLACK ); */ /* Black on black ... -jhsa */ - Text(w->RPort, obufp, strlen( obufp ) ); - SetAPen( w->RPort, C_WHITE ); - } - amii_curs( WIN_MESSAGE, colx = strlen( obufp ) + 3 + ( scrollmsg != 0 ), bottom); - return( colx ); -} + register char q; + char rtmp[40]; + boolean digit_ok, allow_num; + char prompt[BUFSZ]; + register struct amii_WinDesc *cw; -/* Ask a question and get a response */ + if (cw = amii_wins[WIN_MESSAGE]) + cw->disprows = 0; + if (resp) { + char *rb, respbuf[QBUFSZ]; -char amii_yn_function(query, resp, def) -const char *query,*resp; -char def; -/* - * Generic yes/no function. 'def' is the default (returned by space or - * return; 'esc' returns 'q', or 'n', or the default, depending on - * what's in the string. The 'query' string is printed before the user - * is asked about the string. - * If resp is NULL, any single character is accepted and returned. - * If not-NULL, only characters in it are allowed (exceptions: the - * quitchars are always allowed, and if it contains '#' then digits - * are allowed); if it includes an , anything beyond that won't - * be shown in the prompt to the user but will be acceptable as input. - */ -{ - register char q; - char rtmp[40]; - boolean digit_ok, allow_num; - char prompt[BUFSZ]; - register struct amii_WinDesc *cw; + allow_num = (index(resp, '#') != 0); + Strcpy(respbuf, resp); + /* any acceptable responses that follow aren't displayed */ + if ((rb = index(respbuf, '\033')) != 0) + *rb = '\0'; + (void) strncpy(prompt, query, QBUFSZ - 1); + prompt[QBUFSZ - 1] = '\0'; + Sprintf(eos(prompt), " [%s]", respbuf); + if (def) + Sprintf(eos(prompt), " (%c)", def); + Strcat(prompt, " "); + pline("%s", prompt); + } else { + amii_putstr(WIN_MESSAGE, 0, query); + cursor_on(WIN_MESSAGE); + q = WindowGetchar(); + cursor_off(WIN_MESSAGE); + *rtmp = q; + rtmp[1] = 0; + amii_addtopl(rtmp); + goto clean_up; + } - if( cw = amii_wins[ WIN_MESSAGE ] ) - cw->disprows = 0; - if (resp) { - char *rb, respbuf[QBUFSZ]; - - allow_num = (index(resp, '#') != 0); - Strcpy(respbuf, resp); - /* any acceptable responses that follow aren't displayed */ - if ((rb = index(respbuf, '\033')) != 0) *rb = '\0'; - (void)strncpy(prompt, query, QBUFSZ-1); - prompt[QBUFSZ-1] = '\0'; - Sprintf(eos(prompt), " [%s]", respbuf); - if (def) Sprintf(eos(prompt), " (%c)", def); - Strcat(prompt, " "); - pline("%s", prompt); - } else { - amii_putstr(WIN_MESSAGE, 0, query); - cursor_on(WIN_MESSAGE); - q = WindowGetchar(); - cursor_off(WIN_MESSAGE); - *rtmp = q; - rtmp[ 1 ] = 0; - amii_addtopl(rtmp); - goto clean_up; - } - - do { /* loop until we get valid input */ - cursor_on(WIN_MESSAGE); - q = lowc(WindowGetchar()); - cursor_off(WIN_MESSAGE); + do { /* loop until we get valid input */ + cursor_on(WIN_MESSAGE); + q = lowc(WindowGetchar()); + cursor_off(WIN_MESSAGE); #if 0 /* fix for PL2 */ if (q == '\020') { /* ctrl-P */ @@ -1138,610 +1051,621 @@ char def; continue; } #endif - digit_ok = allow_num && isdigit(q); - if (q == '\033') { - if (index(resp, 'q')) - q = 'q'; - else if (index(resp, 'n')) - q = 'n'; - else - q = def; - break; - } else if (index(quitchars, q)) { - q = def; - break; - } - if (!index(resp, q) && !digit_ok) { - amii_bell(); - q = (char)0; - } else if (q == '#' || digit_ok) { - char z, digit_string[2]; - int n_len = 0; - long value = 0; - amii_addtopl("#"), n_len++; - digit_string[1] = '\0'; - if (q != '#') { - digit_string[0] = q; - amii_addtopl(digit_string), n_len++; - value = q - '0'; - q = '#'; - } - do { /* loop until we get a non-digit */ - cursor_on(WIN_MESSAGE); - z = lowc(WindowGetchar()); - cursor_off(WIN_MESSAGE); - if (isdigit(z)) { - value = (10 * value) + (z - '0'); - if (value < 0) break; /* overflow: try again */ - digit_string[0] = z; - amii_addtopl(digit_string), n_len++; - } else if (z == 'y' || index(quitchars, z)) { - if (z == '\033') value = -1; /* abort */ - z = '\n'; /* break */ - } else if ( z == '\b') { - if (n_len <= 1) { value = -1; break; } - else { value /= 10; removetopl(1), n_len--; } - } else { - value = -1; /* abort */ - amii_bell(); - break; - } - } while (z != '\n'); - if (value > 0) yn_number = value; - else if (value == 0) q = 'n'; /* 0 => "no" */ - else { /* remove number from top line, then try again */ - removetopl(n_len), n_len = 0; - q = '\0'; - } - } - } while(!q); + digit_ok = allow_num && isdigit(q); + if (q == '\033') { + if (index(resp, 'q')) + q = 'q'; + else if (index(resp, 'n')) + q = 'n'; + else + q = def; + break; + } else if (index(quitchars, q)) { + q = def; + break; + } + if (!index(resp, q) && !digit_ok) { + amii_bell(); + q = (char) 0; + } else if (q == '#' || digit_ok) { + char z, digit_string[2]; + int n_len = 0; + long value = 0; + amii_addtopl("#"), n_len++; + digit_string[1] = '\0'; + if (q != '#') { + digit_string[0] = q; + amii_addtopl(digit_string), n_len++; + value = q - '0'; + q = '#'; + } + do { /* loop until we get a non-digit */ + cursor_on(WIN_MESSAGE); + z = lowc(WindowGetchar()); + cursor_off(WIN_MESSAGE); + if (isdigit(z)) { + value = (10 * value) + (z - '0'); + if (value < 0) + break; /* overflow: try again */ + digit_string[0] = z; + amii_addtopl(digit_string), n_len++; + } else if (z == 'y' || index(quitchars, z)) { + if (z == '\033') + value = -1; /* abort */ + z = '\n'; /* break */ + } else if (z == '\b') { + if (n_len <= 1) { + value = -1; + break; + } else { + value /= 10; + removetopl(1), n_len--; + } + } else { + value = -1; /* abort */ + amii_bell(); + break; + } + } while (z != '\n'); + if (value > 0) + yn_number = value; + else if (value == 0) + q = 'n'; /* 0 => "no" */ + else { /* remove number from top line, then try again */ + removetopl(n_len), n_len = 0; + q = '\0'; + } + } + } while (!q); - if (q != '#' && q != '\033') { - Sprintf(rtmp, "%c", q); - amii_addtopl(rtmp); - } + if (q != '#' && q != '\033') { + Sprintf(rtmp, "%c", q); + amii_addtopl(rtmp); + } clean_up: - cursor_off(WIN_MESSAGE); - clear_nhwindow(WIN_MESSAGE); - return q; -} + cursor_off(WIN_MESSAGE); + clear_nhwindow(WIN_MESSAGE); + return q; + } -void -amii_display_file(fn, complain) -const char *fn; -boolean complain; -{ - register struct amii_WinDesc *cw; - register int win; - register dlb *fp; - register char *t; - register char buf[ 200 ]; - - if( fn == NULL ) - panic("NULL file name in display_file()"); - - if( ( fp = dlb_fopen( fn, RDTMODE ) ) == (dlb *)NULL ) + void amii_display_file(fn, complain) const char * fn; + boolean complain; { - if (complain) { - sprintf( buf, "Can't display %s: %s", fn, + register struct amii_WinDesc *cw; + register int win; + register dlb *fp; + register char *t; + register char buf[200]; + + if (fn == NULL) + panic("NULL file name in display_file()"); + + if ((fp = dlb_fopen(fn, RDTMODE)) == (dlb *) NULL) { + if (complain) { + sprintf(buf, "Can't display %s: %s", fn, #if defined(_DCC) || defined(__GNUC__) - strerror(errno) + strerror(errno) #else -# ifdef __SASC_60 - __sys_errlist[ errno ] -# else - sys_errlist[ errno ] -# endif +#ifdef __SASC_60 + __sys_errlist[errno] +#else + sys_errlist[errno] #endif - ); - amii_addtopl( buf ); - } - return; - } - win = amii_create_nhwindow( NHW_TEXT ); - - /* Set window title to file name */ - if( cw = amii_wins[ win ] ) - cw->morestr = (char *)fn; - - while( dlb_fgets( buf, sizeof( buf ), fp ) != NULL ) - { - if( t = index( buf, '\n' ) ) - *t = 0; - amii_putstr( win, 0, buf ); - } - dlb_fclose( fp ); - - /* If there were lines in the file, display those lines */ - - if( amii_wins[ win ]->cury > 0 ) - amii_display_nhwindow( win, TRUE ); - - amii_wins[win]->morestr = NULL; /* don't free title string */ - amii_destroy_nhwindow( win ); -} - -/* Put a 3-D motif border around the gadget. String gadgets or those - * which do not have highlighting are rendered down. Boolean gadgets - * are rendered in the up position by default. - */ - -void -SetBorder( gd ) - register struct Gadget *gd; -{ - register struct Border *bp; - register short *sp; - register int i, inc = -1, dec = -1; - int borders = 6; - int hipen = sysflags.amii_dripens[ SHINEPEN ], shadowpen = sysflags.amii_dripens[ SHADOWPEN ]; -#ifdef INTUI_NEW_LOOK - struct DrawInfo *dip; #endif + ); + amii_addtopl(buf); + } + return; + } + win = amii_create_nhwindow(NHW_TEXT); -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - if( dip = GetScreenDrawInfo( HackScreen ) ) - { - hipen = dip->dri_Pens[ SHINEPEN ]; - shadowpen = dip->dri_Pens[ SHADOWPEN ]; - FreeScreenDrawInfo( HackScreen, dip ); - } + /* Set window title to file name */ + if (cw = amii_wins[win]) + cw->morestr = (char *) fn; + + while (dlb_fgets(buf, sizeof(buf), fp) != NULL) { + if (t = index(buf, '\n')) + *t = 0; + amii_putstr(win, 0, buf); + } + dlb_fclose(fp); + + /* If there were lines in the file, display those lines */ + + if (amii_wins[win]->cury > 0) + amii_display_nhwindow(win, TRUE); + + amii_wins[win]->morestr = NULL; /* don't free title string */ + amii_destroy_nhwindow(win); } -#endif - /* Allocate two border structures one for up image and one for down - * image, plus vector arrays for the border lines. + + /* Put a 3-D motif border around the gadget. String gadgets or those + * which do not have highlighting are rendered down. Boolean gadgets + * are rendered in the up position by default. */ - if( gd->GadgetType == STRGADGET ) - borders = 12; - - if( ( bp = (struct Border *)alloc( ( ( sizeof( struct Border ) * 2 ) + - ( sizeof( short ) * borders ) ) * 2 ) ) == NULL ) + void SetBorder(gd) register struct Gadget * gd; { - return; + register struct Border *bp; + register short *sp; + register int i, inc = -1, dec = -1; + int borders = 6; + int hipen = sysflags.amii_dripens[SHINEPEN], + shadowpen = sysflags.amii_dripens[SHADOWPEN]; +#ifdef INTUI_NEW_LOOK + struct DrawInfo *dip; +#endif + +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + if (dip = GetScreenDrawInfo(HackScreen)) { + hipen = dip->dri_Pens[SHINEPEN]; + shadowpen = dip->dri_Pens[SHADOWPEN]; + FreeScreenDrawInfo(HackScreen, dip); + } + } +#endif + /* Allocate two border structures one for up image and one for down + * image, plus vector arrays for the border lines. + */ + + if (gd->GadgetType == STRGADGET) + borders = 12; + + if ((bp = (struct Border *) alloc(((sizeof(struct Border) * 2) + + (sizeof(short) * borders)) * 2)) + == NULL) { + return; + } + + /* For a string gadget, we expand the border beyond the area where + * the text will be entered. + */ + + /* Remove any special rendering flags to avoid confusing intuition + */ + + gd->Flags &= ~(GADGHIGHBITS | GADGIMAGE); + + sp = (short *) (bp + 4); + if (gd->GadgetType == STRGADGET + || (gd->GadgetType == BOOLGADGET + && (gd->Flags & GADGHIGHBITS) == GADGHNONE)) { + sp[0] = -1; + sp[1] = gd->Height - 1; + sp[2] = -1; + sp[3] = -1; + sp[4] = gd->Width - 1; + sp[5] = -1; + + sp[6] = gd->Width + 1; + sp[7] = -2; + sp[8] = gd->Width + 1; + sp[9] = gd->Height + 1; + sp[10] = -2; + sp[11] = gd->Height + 1; + + sp[12] = -2; + sp[13] = gd->Height; + sp[14] = -2; + sp[15] = -2; + sp[16] = gd->Width; + sp[17] = -2; + sp[18] = gd->Width; + sp[19] = gd->Height; + sp[20] = -2; + sp[21] = gd->Height; + + for (i = 0; i < 3; ++i) { + bp[i].LeftEdge = bp[i].TopEdge = -1; + bp[i].FrontPen = (i == 0 || i == 1) ? shadowpen : hipen; + + /* Have to use JAM2 so that the old colors disappear. */ + bp[i].BackPen = C_BLACK; + bp[i].DrawMode = JAM2; + bp[i].Count = (i == 0 || i == 1) ? 3 : 5; + bp[i].XY = &sp[i * 6]; + bp[i].NextBorder = (i == 2) ? NULL : &bp[i + 1]; + } + + /* bp[0] and bp[1] two pieces for the up image */ + gd->GadgetRender = (APTR) bp; + + /* No image change for select */ + gd->SelectRender = (APTR) bp; + + gd->LeftEdge++; + gd->TopEdge++; + gd->Flags |= GADGHCOMP; + } else { + /* Create the border vector values for up and left side, and + * also the lower and right side. + */ + + sp[0] = dec; + sp[1] = gd->Height + inc; + sp[2] = dec; + sp[3] = dec; + sp[4] = gd->Width + inc; + sp[5] = dec; + + sp[6] = gd->Width + inc; + sp[7] = dec; + sp[8] = gd->Width + inc; + sp[9] = gd->Height + inc; + sp[10] = dec; + sp[11] = gd->Height + inc; + + /* We are creating 4 sets of borders, the two sides of the + * rectangle share the border vectors with the opposite image, + * but specify different colors. + */ + + for (i = 0; i < 4; ++i) { + bp[i].TopEdge = bp[i].LeftEdge = 0; + + /* A GADGHNONE is always down */ + + if (gd->GadgetType == BOOLGADGET + && (gd->Flags & GADGHIGHBITS) != GADGHNONE) { + bp[i].FrontPen = (i == 1 || i == 2) ? shadowpen : hipen; + } else { + bp[i].FrontPen = (i == 1 || i == 3) ? hipen : shadowpen; + } + + /* Have to use JAM2 so that the old colors disappear. */ + bp[i].BackPen = C_BLACK; + bp[i].DrawMode = JAM2; + bp[i].Count = 3; + bp[i].XY = &sp[6 * ((i & 1) != 0)]; + bp[i].NextBorder = (i == 1 || i == 3) ? NULL : &bp[i + 1]; + } + + /* bp[0] and bp[1] two pieces for the up image */ + gd->GadgetRender = (APTR) bp; + + /* bp[2] and bp[3] two pieces for the down image */ + gd->SelectRender = (APTR)(bp + 2); + gd->Flags |= GADGHIMAGE; + } } - /* For a string gadget, we expand the border beyond the area where - * the text will be entered. - */ + /* Following function copied from wintty.c */ + /* Modified slightly to fit amiga needs */ - /* Remove any special rendering flags to avoid confusing intuition - */ - - gd->Flags &= ~(GADGHIGHBITS|GADGIMAGE); - - sp = (short *)(bp + 4); - if( gd->GadgetType == STRGADGET || ( gd->GadgetType == BOOLGADGET && - ( gd->Flags & GADGHIGHBITS ) == GADGHNONE ) ) + void amii_player_selection() { - sp[0] = -1; - sp[1] = gd->Height - 1; - sp[2] = -1; - sp[3] = -1; - sp[4] = gd->Width - 1; - sp[5] = -1; + int i, k, n; + char pick4u = 'n', thisch, lastch = 0; + char pbuf[QBUFSZ], plbuf[QBUFSZ], rolenamebuf[QBUFSZ]; + winid win; + anything any; + menu_item *selected = 0; - sp[6] = gd->Width + 1; - sp[7] = -2; - sp[8] = gd->Width + 1; - sp[9] = gd->Height + 1; - sp[10] = -2; - sp[11] = gd->Height + 1; + rigid_role_checks(); - sp[12] = -2; - sp[13] = gd->Height; - sp[14] = -2; - sp[15] = -2; - sp[16] = gd->Width; - sp[17] = -2; - sp[18] = gd->Width; - sp[19] = gd->Height; - sp[20] = -2; - sp[21] = gd->Height; + /* Should we randomly pick for the player? */ + if (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE + || flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE) { + char *prompt = build_plselection_prompt( + pbuf, QBUFSZ, flags.initrole, flags.initrace, flags.initgend, + flags.initalign); + pline("%s", prompt); + do { /* loop until we get valid input */ + cursor_on(WIN_MESSAGE); + pick4u = lowc(WindowGetchar()); + cursor_off(WIN_MESSAGE); + if (index(quitchars, pick4u)) + pick4u = 'y'; + } while (!index(ynqchars, pick4u)); + pbuf[0] = pick4u; + pbuf[1] = 0; + amii_addtopl(pbuf); - for( i = 0; i < 3; ++i ) - { - bp[ i ].LeftEdge = bp[ i ].TopEdge = -1; - bp[ i ].FrontPen = ( i == 0 || i == 1 ) ? shadowpen : hipen; + if (pick4u != 'y' && pick4u != 'n') { + give_up: /* Quit */ + if (selected) + free((genericptr_t) selected); + clearlocks(); + exit_nhwindows(NULL); + terminate(0); + /*NOTREACHED*/ + return; + } + } - /* Have to use JAM2 so that the old colors disappear. */ - bp[ i ].BackPen = C_BLACK; - bp[ i ].DrawMode = JAM2; - bp[ i ].Count = ( i == 0 || i == 1 ) ? 3 : 5; - bp[ i ].XY = &sp[ i*6 ]; - bp[ i ].NextBorder = ( i == 2 ) ? NULL : &bp[ i + 1 ]; - } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); - /* bp[0] and bp[1] two pieces for the up image */ - gd->GadgetRender = (APTR) bp; + /* Select a role, if necessary */ + /* we'll try to be compatible with pre-selected race/gender/alignment, + * but may not succeed */ + if (flags.initrole < 0) { + /* Process the choice */ + if (pick4u == 'y' || flags.initrole == ROLE_RANDOM + || flags.randomall) { + /* Pick a random role */ + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + amii_putstr(WIN_MESSAGE, 0, "Incompatible role!"); + flags.initrole = randrole(); + } + } else { + /* Prompt for a role */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; roles[i].name.m; i++) { + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + thisch = lowc(roles[i].name.m[0]); + if (thisch == lastch) + thisch = highc(thisch); + if (flags.initgend != ROLE_NONE + && flags.initgend != ROLE_RANDOM) { + if (flags.initgend == 1 && roles[i].name.f) + Strcpy(rolenamebuf, roles[i].name.f); + else + Strcpy(rolenamebuf, roles[i].name.m); + } else { + if (roles[i].name.f) { + Strcpy(rolenamebuf, roles[i].name.m); + Strcat(rolenamebuf, "/"); + Strcat(rolenamebuf, roles[i].name.f); + } else + Strcpy(rolenamebuf, roles[i].name.m); + } + add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE, + an(rolenamebuf), MENU_UNSELECTED); + lastch = thisch; + } + } + any.a_int = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrole() + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick a role for your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); - /* No image change for select */ - gd->SelectRender = (APTR) bp; + /* Process the choice */ + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - gd->LeftEdge++; - gd->TopEdge++; - gd->Flags |= GADGHCOMP; + flags.initrole = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } + + /* Select a race, if necessary */ + /* force compatibility with role, try for compatibility with + * pre-selected gender/alignment */ + if (flags.initrace < 0 + || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (pick4u == 'y' || flags.initrace == ROLE_RANDOM + || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + amii_putstr(WIN_MESSAGE, 0, "Incompatible race!"); + flags.initrace = randrace(flags.initrole); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid races */ + n = 0; /* number valid */ + k = 0; /* valid race */ + for (i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; races[i].noun; i++) { + if (validrace(flags.initrole, i)) { + n++; + k = i; + } + } + } + + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; races[i].noun; i++) + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0, + ATR_NONE, races[i].noun, + MENU_UNSELECTED); + } + any.a_int = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrace(flags.initrole) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the race of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initrace = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } + + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (pick4u == 'y' || flags.initgend == ROLE_RANDOM + || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + amii_putstr(WIN_MESSAGE, 0, "Incompatible gender!"); + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid genders */ + n = 0; /* number valid */ + k = 0; /* valid gender */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) { + if (validgend(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, genders[i].adj[0], + 0, ATR_NONE, genders[i].adj, + MENU_UNSELECTED); + } + any.a_int = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = + randgend(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the gender of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initgend = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } + + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (pick4u == 'y' || flags.initalign == ROLE_RANDOM + || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + amii_putstr(WIN_MESSAGE, 0, "Incompatible alignment!"); + flags.initalign = + randalign(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid alignments */ + n = 0; /* number valid */ + k = 0; /* valid alignment */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, + flags.initgend, i)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) { + if (validalign(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(flags.initrole, flags.initrace, + flags.initgend, i)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0, + ATR_NONE, aligns[i].adj, + MENU_UNSELECTED); + } + any.a_int = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = + randalign(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the alignment of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initalign = k; + } + } + /* Success! */ } - else - { - /* Create the border vector values for up and left side, and - * also the lower and right side. - */ - - sp[0] = dec; - sp[1] = gd->Height + inc; - sp[2] = dec; - sp[3] = dec; - sp[4] = gd->Width + inc; - sp[5] = dec; - - sp[6] = gd->Width + inc; - sp[7] = dec; - sp[8] = gd->Width + inc; - sp[9] = gd->Height + inc; - sp[10] = dec; - sp[11] = gd->Height + inc; - - /* We are creating 4 sets of borders, the two sides of the - * rectangle share the border vectors with the opposite image, - * but specify different colors. - */ - - for( i = 0; i < 4; ++i ) - { - bp[ i ].TopEdge = bp[ i ].LeftEdge = 0; - - /* A GADGHNONE is always down */ - - if( gd->GadgetType == BOOLGADGET && - ( gd->Flags & GADGHIGHBITS ) != GADGHNONE ) - { - bp[ i ].FrontPen = - ( i == 1 || i == 2 ) ? shadowpen : hipen; - } - else - { - bp[ i ].FrontPen = - ( i == 1 || i == 3 ) ? hipen : shadowpen; - } - - /* Have to use JAM2 so that the old colors disappear. */ - bp[ i ].BackPen = C_BLACK; - bp[ i ].DrawMode = JAM2; - bp[ i ].Count = 3; - bp[ i ].XY = &sp[ 6 * ((i &1) != 0) ]; - bp[ i ].NextBorder = - ( i == 1 || i == 3 ) ? NULL : &bp[ i + 1 ]; - } - - /* bp[0] and bp[1] two pieces for the up image */ - gd->GadgetRender = (APTR) bp; - - /* bp[2] and bp[3] two pieces for the down image */ - gd->SelectRender = (APTR) (bp + 2); - gd->Flags |= GADGHIMAGE; - } -} - -/* Following function copied from wintty.c */ -/* Modified slightly to fit amiga needs */ - -void -amii_player_selection() -{ - int i, k, n; - char pick4u = 'n', thisch, lastch = 0; - char pbuf[QBUFSZ], plbuf[QBUFSZ], rolenamebuf[QBUFSZ]; - winid win; - anything any; - menu_item *selected = 0; - - rigid_role_checks(); - - /* Should we randomly pick for the player? */ - if (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE || - flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE) { - char *prompt = build_plselection_prompt(pbuf, QBUFSZ, flags.initrole, - flags.initrace, flags.initgend, flags.initalign); - pline("%s", prompt); - do { /* loop until we get valid input */ - cursor_on(WIN_MESSAGE); - pick4u = lowc(WindowGetchar()); - cursor_off(WIN_MESSAGE); - if (index(quitchars, pick4u)) pick4u = 'y'; - } while(!index(ynqchars, pick4u)); - pbuf[0] = pick4u; - pbuf[1] = 0; - amii_addtopl(pbuf); - - if (pick4u != 'y' && pick4u != 'n') { -give_up: /* Quit */ - if (selected) free((genericptr_t) selected); - clearlocks(); - exit_nhwindows(NULL); - terminate(0); - /*NOTREACHED*/ - return; - } - } - - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - - /* Select a role, if necessary */ - /* we'll try to be compatible with pre-selected race/gender/alignment, - * but may not succeed */ - if (flags.initrole < 0) { - /* Process the choice */ - if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) { - /* Pick a random role */ - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - amii_putstr(WIN_MESSAGE, 0, "Incompatible role!"); - flags.initrole = randrole(); - } - } else { - /* Prompt for a role */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; roles[i].name.m; i++) { - if (ok_role(i, flags.initrace, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - thisch = lowc(roles[i].name.m[0]); - if (thisch == lastch) thisch = highc(thisch); - if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) { - if (flags.initgend == 1 && roles[i].name.f) - Strcpy(rolenamebuf, roles[i].name.f); - else - Strcpy(rolenamebuf, roles[i].name.m); - } else { - if (roles[i].name.f) { - Strcpy(rolenamebuf, roles[i].name.m); - Strcat(rolenamebuf, "/"); - Strcat(rolenamebuf, roles[i].name.f); - } else - Strcpy(rolenamebuf, roles[i].name.m); - } - add_menu(win, NO_GLYPH, &any, thisch, - 0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED); - lastch = thisch; - } - } - any.a_int = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrole()+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick a role for your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - - /* Process the choice */ - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - - flags.initrole = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } - - /* Select a race, if necessary */ - /* force compatibility with role, try for compatibility with - * pre-selected gender/alignment */ - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - amii_putstr(WIN_MESSAGE, 0, "Incompatible race!"); - flags.initrace = randrace(flags.initrole); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid races */ - n = 0; /* number valid */ - k = 0; /* valid race */ - for (i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; races[i].noun; i++) { - if (validrace(flags.initrole, i)) { - n++; - k = i; - } - } - } - - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; races[i].noun; i++) - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any, races[i].noun[0], - 0, ATR_NONE, races[i].noun, MENU_UNSELECTED); - } - any.a_int = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrace(flags.initrole)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the race of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initrace = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } - - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - /* pre-selected gender not valid */ - if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - amii_putstr(WIN_MESSAGE, 0, "Incompatible gender!"); - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid genders */ - n = 0; /* number valid */ - k = 0; /* valid gender */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) { - if (validgend(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } - - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, genders[i].adj[0], - 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randgend(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the gender of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initgend = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } - - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - /* pre-selected alignment not valid */ - if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - amii_putstr(WIN_MESSAGE, 0, "Incompatible alignment!"); - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid alignments */ - n = 0; /* number valid */ - k = 0; /* valid alignment */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, flags.initrace, flags.initgend, - i)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) { - if (validalign(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } - - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(flags.initrole, flags.initrace, - flags.initgend, i)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], - 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randalign(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the alignment of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initalign = k; - } - } - /* Success! */ -} #endif /* AMIGA_INTUITION */ diff --git a/sys/amiga/winchar.c b/sys/amiga/winchar.c index 5e4e2c44a..5a47a7f6f 100644 --- a/sys/amiga/winchar.c +++ b/sys/amiga/winchar.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winchar.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winchar.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 winchar.c $Date: 2009/05/06 10:48:33 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)winchar.c 3.5 1993/07/22 */ /* Copyright (c) Olaf Seibert (KosmoSoft), 1989, 1992 */ @@ -14,9 +14,9 @@ #endif #ifdef TESTING -# include "hack.h" +#include "hack.h" #else -# include "NH:src/tile.c" +#include "NH:src/tile.c" #endif #include "NH:win/share/tile.h" @@ -26,33 +26,33 @@ #include "NH:sys/amiga/winproto.h" #ifdef OPT_DISPMAP -# define DISPMAP /* use display_map() from dispmap.s */ +#define DISPMAP /* use display_map() from dispmap.s */ #endif /* NH:sys/amiga/winvchar.c */ -int main ( int , char ** ); -struct BitMap *MyAllocBitMap ( int , int , int , long ); -void MyFreeBitMap ( struct BitMap * ); -void FreeImageFiles ( char **, struct BitMap ** ); -void amiv_flush_glyph_buffer ( struct Window * ); -void amiv_lprint_glyph ( winid , int , int ); -void amii_lprint_glyph ( winid , int , int ); -void amiv_start_glyphout ( winid ); -void amii_end_glyphout ( winid ); -void SetMazeType ( MazeType ); -int GlyphToIcon ( int ); -void amii_start_glyphout ( winid ); -void amii_end_glyphout ( winid ); -void amii_flush_glyph_buffer( struct Window * ); +int main(int, char **); +struct BitMap *MyAllocBitMap(int, int, int, long); +void MyFreeBitMap(struct BitMap *); +void FreeImageFiles(char **, struct BitMap **); +void amiv_flush_glyph_buffer(struct Window *); +void amiv_lprint_glyph(winid, int, int); +void amii_lprint_glyph(winid, int, int); +void amiv_start_glyphout(winid); +void amii_end_glyphout(winid); +void SetMazeType(MazeType); +int GlyphToIcon(int); +void amii_start_glyphout(winid); +void amii_end_glyphout(winid); +void amii_flush_glyph_buffer(struct Window *); int amii_extraplanes = 0; extern int reclip; -struct BitMap *MyAllocBitMap( int xsize, int ysize, int depth, long mflags ); -void MyFreeBitMap( struct BitMap *bmp ); +struct BitMap *MyAllocBitMap(int xsize, int ysize, int depth, long mflags); +void MyFreeBitMap(struct BitMap *bmp); #ifdef DISPMAP -extern void display_map( struct Window * ); +extern void display_map(struct Window *); #endif /* @@ -63,36 +63,34 @@ extern void display_map( struct Window * ); * #define MAXOTHTILE 841 */ -#define IMGROWS 12 -#define IMGCOLUMNS 20 -#define IMGPAGESIZE (IMGROWS*IMGCOLUMNS) +#define IMGROWS 12 +#define IMGCOLUMNS 20 +#define IMGPAGESIZE (IMGROWS * IMGCOLUMNS) -#define ID_BMAP MAKE_ID('B','M','A','P') /* The type of form we use */ -#define ID_BMHD MAKE_ID('B','M','H','D') /* The ILBM bitmap header */ -#define ID_CAMG MAKE_ID('C','A','M','G') /* The ILBM camg (ignored) */ -#define ID_CMAP MAKE_ID('C','M','A','P') /* Standard ILBM color map */ -#define ID_PLNE MAKE_ID('P','L','N','E') /* The plane data */ -#define ID_PDAT MAKE_ID('P','D','A','T') /* The PDAT structure below */ +#define ID_BMAP MAKE_ID('B', 'M', 'A', 'P') /* The type of form we use */ +#define ID_BMHD MAKE_ID('B', 'M', 'H', 'D') /* The ILBM bitmap header */ +#define ID_CAMG MAKE_ID('C', 'A', 'M', 'G') /* The ILBM camg (ignored) */ +#define ID_CMAP MAKE_ID('C', 'M', 'A', 'P') /* Standard ILBM color map */ +#define ID_PLNE MAKE_ID('P', 'L', 'N', 'E') /* The plane data */ +#define ID_PDAT MAKE_ID('P', 'D', 'A', 'T') /* The PDAT structure below */ struct PDAT pictdata; -#define NUMTILEIMAGES 3 -char *tileimages[] = -{ -#define TBLMONTILE 0 - "NetHack:tiles/monsters.iff", -#define TBLOBJTILE 1 - "NetHack:tiles/objects.iff", -#define TBLOTHTILE 2 - "NetHack:tiles/other.iff", - 0, +#define NUMTILEIMAGES 3 +char *tileimages[] = { +#define TBLMONTILE 0 + "NetHack:tiles/monsters.iff", +#define TBLOBJTILE 1 + "NetHack:tiles/objects.iff", +#define TBLOTHTILE 2 + "NetHack:tiles/other.iff", 0, }; -struct BitMap *ifftimg[ NUMTILEIMAGES ], *tile; +struct BitMap *ifftimg[NUMTILEIMAGES], *tile; #ifdef TESTING short pens[NUMDRIPENS] = { 8, 3, 15, 0, 15, 7, 7, 8, 0 }; -main( int argc, char **argv ) +main(int argc, char **argv) { BitMapHeader bmhd; struct IntuiMessage *imsg; @@ -102,109 +100,86 @@ main( int argc, char **argv ) struct Window *w; struct Screen *scr; - bmhd = ReadTileImageFiles( ); + bmhd = ReadTileImageFiles(); - scr = OpenScreenTags( NULL, - SA_Depth, pictdata.nplanes + amii_extraplanes, - SA_DisplayID, DBLNTSC_MONITOR_ID|HIRESLACE_KEY, - SA_Overscan, OSCAN_TEXT, - SA_Top, 0, - SA_Left, 0, - SA_Width, STDSCREENWIDTH, - SA_Height, STDSCREENHEIGHT, - SA_Type, CUSTOMSCREEN, - SA_DetailPen, 0, - SA_BlockPen, 1, - SA_Title, "NetHack Chars", - SA_Pens, pens, - TAG_DONE - ); - if( scr == NULL ) - { - printf( "no screen\n" ); + scr = OpenScreenTags( + NULL, SA_Depth, pictdata.nplanes + amii_extraplanes, SA_DisplayID, + DBLNTSC_MONITOR_ID | HIRESLACE_KEY, SA_Overscan, OSCAN_TEXT, SA_Top, + 0, SA_Left, 0, SA_Width, STDSCREENWIDTH, SA_Height, STDSCREENHEIGHT, + SA_Type, CUSTOMSCREEN, SA_DetailPen, 0, SA_BlockPen, 1, SA_Title, + "NetHack Chars", SA_Pens, pens, TAG_DONE); + if (scr == NULL) { + printf("no screen\n"); #undef exit - exit( 1 ); + exit(1); } - w = OpenWindowTags( 0, - WA_CustomScreen, scr, - WA_Flags, WFLG_DRAGBAR|WFLG_SIZEGADGET|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET, - WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|IDCMP_MOUSEBUTTONS, - WA_Left, 0, - WA_Top, scr->WBorTop + 1 + 13, - WA_MinWidth, 100, - WA_MinHeight, 100, - WA_MaxWidth, 700, - WA_MaxHeight, 1000, - WA_Width, 640, - WA_Height, 340, - WA_SmartRefresh, TRUE, - TAG_DONE ); - if( w ) - { - while( !done ) - { - for( i = 0; i < NUMTILEIMAGES * IMGPAGESIZE; ++i ) - { - int dx, dy; - tbl = i/IMGPAGESIZE; - x = i % IMGPAGESIZE; - y = x / IMGCOLUMNS; - x = x % IMGCOLUMNS; - dx = i % (IMGCOLUMNS*2); - dy = i / (IMGCOLUMNS*2); - BltBitMapRastPort( ifftimg[ tbl ], - x * pictdata.xsize, y * pictdata.ysize, - w->RPort, - w->BorderLeft + 1 + dx*pictdata.xsize, - w->BorderTop + 1 + dy*pictdata.ysize, - pictdata.xsize, pictdata.ysize, 0xc0 ); - } - WaitPort( w->UserPort ); - while( imsg = (struct IntuiMessage *)GetMsg( w->UserPort ) ) - { - class = imsg->Class; - code = imsg->Code; - ReplyMsg( (struct Message *)imsg ); - switch( class ) - { - case IDCMP_MOUSEBUTTONS: - { - x = imsg->MouseX - w->BorderLeft; - y = imsg->MouseY - w->BorderTop; - num = ((y/pictdata.ysize)*IMGCOLUMNS*2)+(x/pictdata.xsize); - sprintf( buf, "Char #%d", num ); - SetWindowTitles( w, buf, buf ); - } - break; - case IDCMP_CLOSEWINDOW: - done = 1; - break; - } - } - } - CloseWindow( w ); - CloseScreen( scr ); + w = OpenWindowTags( + 0, WA_CustomScreen, scr, WA_Flags, + WFLG_DRAGBAR | WFLG_SIZEGADGET | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET, + WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS, + WA_Left, 0, WA_Top, scr->WBorTop + 1 + 13, WA_MinWidth, 100, + WA_MinHeight, 100, WA_MaxWidth, 700, WA_MaxHeight, 1000, WA_Width, + 640, WA_Height, 340, WA_SmartRefresh, TRUE, TAG_DONE); + if (w) { + while (!done) { + for (i = 0; i < NUMTILEIMAGES * IMGPAGESIZE; ++i) { + int dx, dy; + tbl = i / IMGPAGESIZE; + x = i % IMGPAGESIZE; + y = x / IMGCOLUMNS; + x = x % IMGCOLUMNS; + dx = i % (IMGCOLUMNS * 2); + dy = i / (IMGCOLUMNS * 2); + BltBitMapRastPort(ifftimg[tbl], x * pictdata.xsize, + y * pictdata.ysize, w->RPort, + w->BorderLeft + 1 + dx * pictdata.xsize, + w->BorderTop + 1 + dy * pictdata.ysize, + pictdata.xsize, pictdata.ysize, 0xc0); + } + WaitPort(w->UserPort); + while (imsg = (struct IntuiMessage *) GetMsg(w->UserPort)) { + class = imsg->Class; + code = imsg->Code; + ReplyMsg((struct Message *) imsg); + switch (class) { + case IDCMP_MOUSEBUTTONS: { + x = imsg->MouseX - w->BorderLeft; + y = imsg->MouseY - w->BorderTop; + num = ((y / pictdata.ysize) * IMGCOLUMNS * 2) + + (x / pictdata.xsize); + sprintf(buf, "Char #%d", num); + SetWindowTitles(w, buf, buf); + } break; + case IDCMP_CLOSEWINDOW: + done = 1; + break; + } + } + } + CloseWindow(w); + CloseScreen(scr); } - FreeImageFiles(tileimages, ifftimg ); + FreeImageFiles(tileimages, ifftimg); - return(0); + return (0); } #endif BitMapHeader -ReadTileImageFiles(){ +ReadTileImageFiles() +{ char *errstr = NULL; BitMapHeader ret = ReadImageFiles(tileimages, ifftimg, &errstr); - if(errstr){ - panic(errstr); + if (errstr) { + panic(errstr); } return ret; } BitMapHeader -ReadImageFiles(char **filenames, struct BitMap **iffimg, char **errstrp ) +ReadImageFiles(char **filenames, struct BitMap **iffimg, char **errstrp) { BitMapHeader *bmhd = NULL, bmhds; unsigned char *cmap; @@ -213,70 +188,61 @@ ReadImageFiles(char **filenames, struct BitMap **iffimg, char **errstrp ) struct IFFHandle *iff; struct StoredProperty *prop; - IFFParseBase = OpenLibrary( "iffparse.library", 0L ); - if( !IFFParseBase ) - { - *errstrp = "No iffparse.library"; - return bmhds; + IFFParseBase = OpenLibrary("iffparse.library", 0L); + if (!IFFParseBase) { + *errstrp = "No iffparse.library"; + return bmhds; } -/* - for( i = 0; filenames[i]; ++i ) - memset( iffimg[i], 0, sizeof( struct BitMap ) ); -*/ - for( i = 0; filenames[i]; ++i ) - { - iff = AllocIFF(); - if( !iff ) - { - FreeImageFiles(filenames, iffimg ); - *errstrp = "can't start IFF processing"; - return bmhds; - } - iff->iff_Stream = Open( filenames[i], MODE_OLDFILE ); - if( iff->iff_Stream == 0 ) - { - char *buf = malloc(100+strlen(filenames[i])); - FreeImageFiles( filenames, iffimg ); - sprintf(buf, "Can't open %s: %s", filenames[i], strerror( errno )); - *errstrp = buf; - return bmhds; - } - InitIFFasDOS( iff ); - OpenIFF( iff, IFFF_READ ); - PropChunk( iff, ID_BMAP, ID_BMHD ); - PropChunk( iff, ID_BMAP, ID_CMAP ); - PropChunk( iff, ID_BMAP, ID_CAMG ); - PropChunk( iff, ID_BMAP, ID_PDAT ); - StopChunk( iff, ID_BMAP, ID_PLNE ); - if( ( j = ParseIFF( iff, IFFPARSE_SCAN ) ) != 0 ) - { - char *buf = malloc(100); - FreeImageFiles( filenames, iffimg ); - sprintf(buf,"ParseIFF failed for image %d, failure code: %d",i,j); - *errstrp = buf; - return bmhds; - } + /* + for( i = 0; filenames[i]; ++i ) + memset( iffimg[i], 0, sizeof( struct BitMap ) ); + */ + for (i = 0; filenames[i]; ++i) { + iff = AllocIFF(); + if (!iff) { + FreeImageFiles(filenames, iffimg); + *errstrp = "can't start IFF processing"; + return bmhds; + } + iff->iff_Stream = Open(filenames[i], MODE_OLDFILE); + if (iff->iff_Stream == 0) { + char *buf = malloc(100 + strlen(filenames[i])); + FreeImageFiles(filenames, iffimg); + sprintf(buf, "Can't open %s: %s", filenames[i], strerror(errno)); + *errstrp = buf; + return bmhds; + } + InitIFFasDOS(iff); + OpenIFF(iff, IFFF_READ); + PropChunk(iff, ID_BMAP, ID_BMHD); + PropChunk(iff, ID_BMAP, ID_CMAP); + PropChunk(iff, ID_BMAP, ID_CAMG); + PropChunk(iff, ID_BMAP, ID_PDAT); + StopChunk(iff, ID_BMAP, ID_PLNE); + if ((j = ParseIFF(iff, IFFPARSE_SCAN)) != 0) { + char *buf = malloc(100); + FreeImageFiles(filenames, iffimg); + sprintf(buf, "ParseIFF failed for image %d, failure code: %d", i, + j); + *errstrp = buf; + return bmhds; + } - if( prop = FindProp( iff, ID_BMAP, ID_BMHD ) ) - { - bmhd = (BitMapHeader *)prop->sp_Data; - } - else - { - FreeImageFiles(filenames, iffimg); - CloseIFF( iff ); - Close( iff->iff_Stream ); - FreeIFF( iff ); - *errstrp = "No BMHD CHUNK in file"; - return bmhds; - } + if (prop = FindProp(iff, ID_BMAP, ID_BMHD)) { + bmhd = (BitMapHeader *) prop->sp_Data; + } else { + FreeImageFiles(filenames, iffimg); + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); + *errstrp = "No BMHD CHUNK in file"; + return bmhds; + } - if( prop = FindProp( iff, ID_BMAP, ID_CMAP ) ) - { - cmap = prop->sp_Data; - for( j = 0; j < (1L << bmhd->nPlanes)*3; j+=3 ) - { + if (prop = FindProp(iff, ID_BMAP, ID_CMAP)) { + cmap = prop->sp_Data; + for (j = 0; j < (1L << bmhd->nPlanes) * 3; j += 3) { #if 0 /* Some day we will want to use the larger palette * resolution available under v39 and later. i.e. @@ -300,171 +266,163 @@ ReadImageFiles(char **filenames, struct BitMap **iffimg, char **errstrp ) } else #endif - { - /* We can only use 4 bits of the 8 that are stored in the - * cmap, so mask them and then shift them into position - * for the UWORD value to store. - */ + { +/* We can only use 4 bits of the 8 that are stored in the + * cmap, so mask them and then shift them into position + * for the UWORD value to store. + */ #ifndef TESTING - amii_initmap[ j/3 ] = - amiv_init_map[ j/3 ] = - ((cmap[j+0]>>4)<<8)| - ((cmap[j+1]>>4)<<4)| - (cmap[j+2]>>4); + amii_initmap[j / 3] = amiv_init_map[j / 3] = + ((cmap[j + 0] >> 4) << 8) | ((cmap[j + 1] >> 4) << 4) + | (cmap[j + 2] >> 4); #endif - } - } - } - else - { - FreeImageFiles(filenames, iffimg); - CloseIFF( iff ); - Close( iff->iff_Stream ); - FreeIFF( iff ); - *errstrp = "No CMAP CHUNK in file"; - return bmhds; - } + } + } + } else { + FreeImageFiles(filenames, iffimg); + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); + *errstrp = "No CMAP CHUNK in file"; + return bmhds; + } - if( prop = FindProp( iff, ID_BMAP, ID_PDAT ) ) - { - struct PDAT *pp; + if (prop = FindProp(iff, ID_BMAP, ID_PDAT)) { + struct PDAT *pp; - pp = (struct PDAT *)prop->sp_Data; - pictdata = *pp; - } - else - { - FreeImageFiles(filenames, iffimg); - CloseIFF( iff ); - Close( iff->iff_Stream ); - FreeIFF( iff ); - *errstrp = "No PDAT CHUNK in file"; - return bmhds; - } + pp = (struct PDAT *) prop->sp_Data; + pictdata = *pp; + } else { + FreeImageFiles(filenames, iffimg); + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); + *errstrp = "No PDAT CHUNK in file"; + return bmhds; + } - iffimg[ i ] = MyAllocBitMap( bmhd->w, bmhd->h, - pictdata.nplanes + amii_extraplanes, MEMF_CHIP|MEMF_CLEAR ); - if( iffimg[ i ] == NULL ) - { - char *buf = malloc(80); - FreeImageFiles(filenames, iffimg); - sprintf(buf, "Can't allocate bitmap for image %d\n", i ); - *errstrp = buf; - return bmhds; - } - for( j = 0; j < pictdata.nplanes + amii_extraplanes; ++j ) - { - ReadChunkBytes( iff, iffimg[i]->Planes[j], RASSIZE( bmhd->w, bmhd->h ) ); - } - bmhds = *bmhd; - CloseIFF( iff ); - Close( iff->iff_Stream ); - FreeIFF( iff ); + iffimg[i] = MyAllocBitMap(bmhd->w, bmhd->h, + pictdata.nplanes + amii_extraplanes, + MEMF_CHIP | MEMF_CLEAR); + if (iffimg[i] == NULL) { + char *buf = malloc(80); + FreeImageFiles(filenames, iffimg); + sprintf(buf, "Can't allocate bitmap for image %d\n", i); + *errstrp = buf; + return bmhds; + } + for (j = 0; j < pictdata.nplanes + amii_extraplanes; ++j) { + ReadChunkBytes(iff, iffimg[i]->Planes[j], + RASSIZE(bmhd->w, bmhd->h)); + } + bmhds = *bmhd; + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); } - CloseLibrary( IFFParseBase ); + CloseLibrary(IFFParseBase); - tile = MyAllocBitMap( pictdata.xsize, pictdata.ysize, - pictdata.nplanes + amii_extraplanes, MEMF_CHIP|MEMF_CLEAR ); - if( tile == NULL ) - { - FreeImageFiles(filenames, iffimg); - *errstrp = "Can't allocate tile bitmap for scaling"; + tile = MyAllocBitMap(pictdata.xsize, pictdata.ysize, + pictdata.nplanes + amii_extraplanes, + MEMF_CHIP | MEMF_CLEAR); + if (tile == NULL) { + FreeImageFiles(filenames, iffimg); + *errstrp = "Can't allocate tile bitmap for scaling"; } - return( bmhds ); + return (bmhds); } -struct MyBitMap -{ - struct BitMap bm; - long mflags; - USHORT xsize, ysize; +struct MyBitMap { + struct BitMap bm; + long mflags; + USHORT xsize, ysize; }; struct BitMap * -MyAllocBitMap( int xsize, int ysize, int depth, long mflags ) +MyAllocBitMap(int xsize, int ysize, int depth, long mflags) { int j; struct MyBitMap *bm; - bm = (struct MyBitMap *)alloc( sizeof( *bm ) ); - if( !bm ) - return( NULL ); + bm = (struct MyBitMap *) alloc(sizeof(*bm)); + if (!bm) + return (NULL); bm->xsize = xsize; bm->ysize = ysize; - InitBitMap( &bm->bm, depth, xsize, ysize ); - for( j = 0; j < depth; ++j ) - { - if( mflags & MEMF_CHIP ) - bm->bm.Planes[ j ] = AllocRaster( xsize, ysize ); - else - bm->bm.Planes[ j ] = AllocMem( RASSIZE( xsize, ysize ), mflags ); + InitBitMap(&bm->bm, depth, xsize, ysize); + for (j = 0; j < depth; ++j) { + if (mflags & MEMF_CHIP) + bm->bm.Planes[j] = AllocRaster(xsize, ysize); + else + bm->bm.Planes[j] = AllocMem(RASSIZE(xsize, ysize), mflags); - if( bm->bm.Planes[ j ] == 0 ) - { - MyFreeBitMap( &bm->bm ); - return( NULL ); - } - if( mflags & MEMF_CLEAR ) - memset( bm->bm.Planes[ j ], 0, RASSIZE( xsize, ysize ) ); + if (bm->bm.Planes[j] == 0) { + MyFreeBitMap(&bm->bm); + return (NULL); + } + if (mflags & MEMF_CLEAR) + memset(bm->bm.Planes[j], 0, RASSIZE(xsize, ysize)); } - return( &bm->bm ); + return (&bm->bm); } void -MyFreeBitMap( struct BitMap *bmp ) +MyFreeBitMap(struct BitMap *bmp) { int j; - struct MyBitMap *bm = (struct MyBitMap *)bmp; + struct MyBitMap *bm = (struct MyBitMap *) bmp; - for( j = 0; j < bm->bm.Depth; ++j ) - { - if( bm->bm.Planes[j] ) - { - if( bm->mflags & MEMF_CHIP ) - FreeRaster( bm->bm.Planes[j], bm->xsize, bm->ysize ); - else - FreeMem( bm->bm.Planes[j], RASSIZE( bm->xsize, bm->ysize ) ); - } + for (j = 0; j < bm->bm.Depth; ++j) { + if (bm->bm.Planes[j]) { + if (bm->mflags & MEMF_CHIP) + FreeRaster(bm->bm.Planes[j], bm->xsize, bm->ysize); + else + FreeMem(bm->bm.Planes[j], RASSIZE(bm->xsize, bm->ysize)); + } } - free( bm ); + free(bm); } -#ifdef TESTING +#ifdef TESTING void -panic(s,a1,a2,a3,a4) - char *s; +panic(s, a1, a2, a3, a4) +char *s; { - printf( s, a1, a2, a3, a4 ); + printf(s, a1, a2, a3, a4); putchar('\n'); } long * -alloc(unsigned int x){ - long *p = (long *)malloc(x); - if(!p){panic("malloc failed"); exit(1);} - return p; +alloc(unsigned int x) +{ + long *p = (long *) malloc(x); + if (!p) { + panic("malloc failed"); + exit(1); + } + return p; } #endif void -FreeTileImageFiles(){ - FreeImageFiles(tileimages,ifftimg); +FreeTileImageFiles() +{ + FreeImageFiles(tileimages, ifftimg); } void -FreeImageFiles(char **filenames, struct BitMap **img ) +FreeImageFiles(char **filenames, struct BitMap **img) { register int i; - for( i = 0; filenames[i]; ++i ) - { - if( img[ i ] ) - MyFreeBitMap( img[ i ] ); + for (i = 0; filenames[i]; ++i) { + if (img[i]) + MyFreeBitMap(img[i]); } - /* REALLY ugly hack alert! */ - if( tile && img==ifftimg) - MyFreeBitMap( tile ); + /* REALLY ugly hack alert! */ + if (tile && img == ifftimg) + MyFreeBitMap(tile); } #ifndef TESTING @@ -472,32 +430,32 @@ FreeImageFiles(char **filenames, struct BitMap **img ) * Define some stuff for our special glyph drawing routines */ unsigned short glyph_node_index, glyph_buffer_index; -#define NUMBER_GLYPH_NODES 80 -#define GLYPH_BUFFER_SIZE 512 +#define NUMBER_GLYPH_NODES 80 +#define GLYPH_BUFFER_SIZE 512 struct amiv_glyph_node { - short odstx, odsty; - short srcx, srcy, dstx, dsty; - struct BitMap *bitmap; + short odstx, odsty; + short srcx, srcy, dstx, dsty; + struct BitMap *bitmap; }; struct amiv_glyph_node amiv_g_nodes[NUMBER_GLYPH_NODES]; static char amiv_glyph_buffer[GLYPH_BUFFER_SIZE]; void -flush_glyph_buffer( vw ) - struct Window *vw; +flush_glyph_buffer(vw) +struct Window *vw; { - if( WINVERS_AMIV ) - amiv_flush_glyph_buffer ( vw ); + if (WINVERS_AMIV) + amiv_flush_glyph_buffer(vw); else - amii_flush_glyph_buffer ( vw ); + amii_flush_glyph_buffer(vw); } /* * Routine to flush whatever is buffered */ void -amiv_flush_glyph_buffer( vw ) - struct Window *vw; +amiv_flush_glyph_buffer(vw) +struct Window *vw; { #if !defined(DISPMAP) || defined(OPT_DISPMAP) int xsize, ysize, x, y; @@ -512,161 +470,160 @@ amiv_flush_glyph_buffer( vw ) #endif /* If nothing is buffered, return before we do anything */ - if(glyph_node_index == 0) - return; + if (glyph_node_index == 0) + return; - cursor_off( WIN_MAP ); - amiv_start_glyphout( WIN_MAP ); + cursor_off(WIN_MAP); + amiv_start_glyphout(WIN_MAP); #ifdef OPT_DISPMAP - if(sysflags.fast_map){ + if (sysflags.fast_map) { #endif #ifdef DISPMAP - display_map( vw ); + display_map(vw); #endif #ifdef OPT_DISPMAP } else { #endif #if !defined(DISPMAP) || defined(OPT_DISPMAP) -/* XXX fix indent */ - /* This is a dynamic value based on this relationship. */ - scaling_needed = ( pictdata.xsize != mxsize || pictdata.ysize != mysize ); + /* XXX fix indent */ + /* This is a dynamic value based on this relationship. */ + scaling_needed = + (pictdata.xsize != mxsize || pictdata.ysize != mysize); - /* If overview window is up, set up to render the correct scale there */ - if( WIN_OVER != WIN_ERR && ( w = amii_wins[ WIN_OVER ]->win ) != NULL ) - { - InitRastPort( &rast ); + /* If overview window is up, set up to render the correct scale there + */ + if (WIN_OVER != WIN_ERR && (w = amii_wins[WIN_OVER]->win) != NULL) { + InitRastPort(&rast); - /* Calculate the x and y size of each tile for a ROWNO by COLNO map */ - xsize = (w->Width - w->BorderLeft - w->BorderRight) / COLNO; - ysize = (w->Height - w->BorderTop - w->BorderBottom) / ROWNO; + /* Calculate the x and y size of each tile for a ROWNO by COLNO + * map */ + xsize = (w->Width - w->BorderLeft - w->BorderRight) / COLNO; + ysize = (w->Height - w->BorderTop - w->BorderBottom) / ROWNO; - /* Get a chip memory bitmap to blit out of */ - bm = MyAllocBitMap( pictdata.xsize, pictdata.ysize, - pictdata.nplanes + amii_extraplanes, MEMF_CLEAR|MEMF_CHIP ); - if( bm == NULL ) - { - amii_putstr( WIN_MESSAGE, 0, "Can't allocate bitmap for scaling overview window" ); - } + /* Get a chip memory bitmap to blit out of */ + bm = MyAllocBitMap(pictdata.xsize, pictdata.ysize, + pictdata.nplanes + amii_extraplanes, + MEMF_CLEAR | MEMF_CHIP); + if (bm == NULL) { + amii_putstr( + WIN_MESSAGE, 0, + "Can't allocate bitmap for scaling overview window"); + } - rast.BitMap = bm; + rast.BitMap = bm; - memset( &bsa, 0, sizeof( bsa ) ); - bsa.bsa_SrcX = bsa.bsa_SrcY = 0; - bsa.bsa_SrcBitMap = tile; - bsa.bsa_SrcWidth = pictdata.xsize; - bsa.bsa_SrcHeight = pictdata.ysize; - bsa.bsa_XSrcFactor = pictdata.xsize; - bsa.bsa_YSrcFactor = pictdata.ysize; - bsa.bsa_DestX = 0; - bsa.bsa_DestY = 0; - bsa.bsa_DestWidth = xsize; - bsa.bsa_DestHeight = ysize; - bsa.bsa_XDestFactor = xsize; - bsa.bsa_YDestFactor = ysize; - bsa.bsa_DestBitMap = bm; - } + memset(&bsa, 0, sizeof(bsa)); + bsa.bsa_SrcX = bsa.bsa_SrcY = 0; + bsa.bsa_SrcBitMap = tile; + bsa.bsa_SrcWidth = pictdata.xsize; + bsa.bsa_SrcHeight = pictdata.ysize; + bsa.bsa_XSrcFactor = pictdata.xsize; + bsa.bsa_YSrcFactor = pictdata.ysize; + bsa.bsa_DestX = 0; + bsa.bsa_DestY = 0; + bsa.bsa_DestWidth = xsize; + bsa.bsa_DestHeight = ysize; + bsa.bsa_XDestFactor = xsize; + bsa.bsa_YDestFactor = ysize; + bsa.bsa_DestBitMap = bm; + } - if( scaling_needed ) - { - /* Fill in scaling data for map rendering */ - memset( &bsm, 0, sizeof( bsm ) ); - bsm.bsa_SrcX = bsm.bsa_SrcY = 0; - bsm.bsa_SrcBitMap = tile; + if (scaling_needed) { + /* Fill in scaling data for map rendering */ + memset(&bsm, 0, sizeof(bsm)); + bsm.bsa_SrcX = bsm.bsa_SrcY = 0; + bsm.bsa_SrcBitMap = tile; - bsm.bsa_SrcWidth = pictdata.xsize; - bsm.bsa_SrcHeight = pictdata.ysize; + bsm.bsa_SrcWidth = pictdata.xsize; + bsm.bsa_SrcHeight = pictdata.ysize; - bsm.bsa_XSrcFactor = pictdata.xsize; - bsm.bsa_YSrcFactor = pictdata.ysize; + bsm.bsa_XSrcFactor = pictdata.xsize; + bsm.bsa_YSrcFactor = pictdata.ysize; - bsm.bsa_DestWidth = mxsize; - bsm.bsa_DestHeight = mysize; + bsm.bsa_DestWidth = mxsize; + bsm.bsa_DestHeight = mysize; - bsm.bsa_XDestFactor = mxsize; - bsm.bsa_YDestFactor = mysize; - bsm.bsa_DestBitMap = rp->BitMap; - bsm.bsa_DestY = bsm.bsa_DestX = 0; + bsm.bsa_XDestFactor = mxsize; + bsm.bsa_YDestFactor = mysize; + bsm.bsa_DestBitMap = rp->BitMap; + bsm.bsa_DestY = bsm.bsa_DestX = 0; - imgbm = MyAllocBitMap( mxsize, mysize, - pictdata.nplanes + amii_extraplanes, MEMF_CLEAR|MEMF_CHIP ); - if( imgbm == NULL ) - { - amii_putstr( WIN_MESSAGE, 0, - "Can't allocate scaling bitmap for map window" ); - } - else - bsm.bsa_DestBitMap = imgbm; - } + imgbm = MyAllocBitMap(mxsize, mysize, + pictdata.nplanes + amii_extraplanes, + MEMF_CLEAR | MEMF_CHIP); + if (imgbm == NULL) { + amii_putstr(WIN_MESSAGE, 0, + "Can't allocate scaling bitmap for map window"); + } else + bsm.bsa_DestBitMap = imgbm; + } - /* Go ahead and start dumping the stuff */ - for( i=0; iBytesPerRow; - for( j = 0; j < pictdata.nplanes + amii_extraplanes; ++j ) - { - for( k = 0; k < pictdata.ysize; ++k ) - { + offx = amiv_g_nodes[i].srcx / 8; /* 8 is bits per byte */ + offy = amiv_g_nodes[i].srcy * nodebm->BytesPerRow; + for (j = 0; j < pictdata.nplanes + amii_extraplanes; ++j) { + for (k = 0; k < pictdata.ysize; ++k) { + /* For a 16x16 tile, this could just be short assignments, + * but + * this code is generalized to handle any size tile + * image... + */ + memcpy(tile->Planes[j] + ((k * pictdata.ysize) / 8), + nodebm->Planes[j] + offx + offy + + (nodebm->BytesPerRow * k), + pictdata.ysize / 8); + } + } - /* For a 16x16 tile, this could just be short assignments, but - * this code is generalized to handle any size tile image... - */ - memcpy( tile->Planes[ j ] + ( ( k * pictdata.ysize ) / 8 ), - nodebm->Planes[ j ] + offx + offy + ( nodebm->BytesPerRow * k ), - pictdata.ysize/8 ); - } - } + if (!clipping || (x >= clipx && y >= clipy && x < clipxmax + && y < clipymax)) { + /* scaling is needed, do it */ + if (scaling_needed) { + BitMapScale(&bsm); + BltBitMapRastPort(imgbm, 0, 0, rp, amiv_g_nodes[i].dstx, + amiv_g_nodes[i].dsty, mxsize, mysize, + 0xc0); + } else { + BltBitMapRastPort(tile, 0, 0, rp, amiv_g_nodes[i].dstx, + amiv_g_nodes[i].dsty, pictdata.xsize, + pictdata.ysize, 0xc0); + } + } + /* Draw the overview window unless we are scrolling the map raster + * around */ + if (bm && w && reclip != 2) { + BitMapScale(&bsa); + BltBitMapRastPort( + rast.BitMap, 0, 0, w->RPort, + w->BorderLeft + amiv_g_nodes[i].odstx * xsize, + w->BorderTop + amiv_g_nodes[i].odsty * ysize, xsize, + ysize, 0xc0); + } + } - if( !clipping || - ( x >= clipx && y >= clipy && - x < clipxmax && y < clipymax ) ) - { - /* scaling is needed, do it */ - if( scaling_needed ) - { - BitMapScale( &bsm ); - BltBitMapRastPort( imgbm, 0, 0, - rp, amiv_g_nodes[ i ].dstx, amiv_g_nodes[ i ].dsty, - mxsize, mysize, 0xc0 ); - } - else - { - BltBitMapRastPort( tile, 0, 0, - rp, amiv_g_nodes[ i ].dstx, amiv_g_nodes[ i ].dsty, - pictdata.xsize, pictdata.ysize, 0xc0 ); - } - } - /* Draw the overview window unless we are scrolling the map raster around */ - if( bm && w && reclip != 2 ) - { - BitMapScale( &bsa ); - BltBitMapRastPort( rast.BitMap, 0, 0, - w->RPort, - w->BorderLeft + amiv_g_nodes[ i ].odstx*xsize, - w->BorderTop + amiv_g_nodes[ i ].odsty*ysize, - xsize, ysize, 0xc0 ); - } - } - - if( imgbm ) MyFreeBitMap( imgbm ); - if( bm ) MyFreeBitMap( bm ); + if (imgbm) + MyFreeBitMap(imgbm); + if (bm) + MyFreeBitMap(bm); #endif /* DISPMAP */ #ifdef OPT_DISPMAP } #endif - amii_end_glyphout( WIN_MAP ); + amii_end_glyphout(WIN_MAP); /* Clean up */ glyph_node_index = glyph_buffer_index = 0; @@ -676,9 +633,9 @@ amiv_flush_glyph_buffer( vw ) * Glyph buffering routine. Called instead of WindowPuts(). */ void -amiv_lprint_glyph(window,color_index, glyph) - winid window; - int color_index, glyph; +amiv_lprint_glyph(window, color_index, glyph) +winid window; +int color_index, glyph; { int base; struct amii_WinDesc *cw; @@ -689,163 +646,153 @@ amiv_lprint_glyph(window,color_index, glyph) register int xoff, yoff; /* Get the real icon index */ - if( glyph != NO_GLYPH ) - icon = GlyphToIcon( glyph ); + if (glyph != NO_GLYPH) + icon = GlyphToIcon(glyph); - if( ( cw=amii_wins[window] ) == (struct amii_WinDesc *)NULL ) - panic("bad winid in amiv_lprint_glyph: %d", window ); + if ((cw = amii_wins[window]) == (struct amii_WinDesc *) NULL) + panic("bad winid in amiv_lprint_glyph: %d", window); w = cw->win; - if( glyph != NO_GLYPH && glyph < 10000) - { - /* decide on which image has the needed picture */ - if( icon <= MAXMONTILE ) - { - tbl = TBLMONTILE; - base = 0; - } - else if( icon <= MAXOBJTILE ) - { - tbl = TBLOBJTILE; - base = MAXMONTILE+1; - } - else if( icon <= MAXOTHTILE ) - { - tbl = TBLOTHTILE; - base = MAXOBJTILE+1; - } - else - panic( "Bad icon #%d, glyph #%d, only %d icons known\n", icon, glyph, MAXOTHTILE ); + if (glyph != NO_GLYPH && glyph < 10000) { + /* decide on which image has the needed picture */ + if (icon <= MAXMONTILE) { + tbl = TBLMONTILE; + base = 0; + } else if (icon <= MAXOBJTILE) { + tbl = TBLOBJTILE; + base = MAXMONTILE + 1; + } else if (icon <= MAXOTHTILE) { + tbl = TBLOTHTILE; + base = MAXOBJTILE + 1; + } else + panic("Bad icon #%d, glyph #%d, only %d icons known\n", icon, + glyph, MAXOTHTILE); - /* Get the relative offset in the page */ + /* Get the relative offset in the page */ - /* How many pixels to account for y distance down */ - yoff = ((icon-base) / pictdata.across) * pictdata.ysize; + /* How many pixels to account for y distance down */ + yoff = ((icon - base) / pictdata.across) * pictdata.ysize; - /* How many pixels to account for x distance across */ - xoff = ((icon-base) % pictdata.across) * pictdata.xsize; + /* How many pixels to account for x distance across */ + xoff = ((icon - base) % pictdata.across) * pictdata.xsize; } - if(glyph >= 10000){ - /* Run a single ASCII character out to the rastport right now */ - char c= glyph-10000; - int xxx,xxy; - struct RastPort *rp = w->RPort; + if (glyph >= 10000) { + /* Run a single ASCII character out to the rastport right now */ + char c = glyph - 10000; + int xxx, xxy; + struct RastPort *rp = w->RPort; - Move(rp, xxx=(((cw->curx-clipx)*rp->TxWidth) + w->BorderLeft), - xxy=(w->BorderTop + (((cw->cury-clipy)+1)* rp->TxHeight)+1)); - Text(rp,&c,1); - /* XXX this shouldn't be necessary: */ - if(cw->cursx == xxx && cw->cursy == xxy){ - cw->wflags &= ~FLMAP_CURSUP; - } - cw->curx += rp->TxWidth; /* keep things in sync */ - return; + Move(rp, xxx = (((cw->curx - clipx) * rp->TxWidth) + w->BorderLeft), + xxy = (w->BorderTop + (((cw->cury - clipy) + 1) * rp->TxHeight) + + 1)); + Text(rp, &c, 1); + /* XXX this shouldn't be necessary: */ + if (cw->cursx == xxx && cw->cursy == xxy) { + cw->wflags &= ~FLMAP_CURSUP; + } + cw->curx += rp->TxWidth; /* keep things in sync */ + return; } - - if( cw->type == NHW_MAP ) - { - curx = cw->curx - clipx; - cury = cw->cury - clipy; - /* See if we're out of glyph nodes */ - if(glyph_node_index >= NUMBER_GLYPH_NODES) - amiv_flush_glyph_buffer( w ); + if (cw->type == NHW_MAP) { + curx = cw->curx - clipx; + cury = cw->cury - clipy; - /* Fill in the node. */ - amiv_g_nodes[glyph_node_index].dsty = min( w->BorderTop + (cury * mysize), - w->Height - 1 ); + /* See if we're out of glyph nodes */ + if (glyph_node_index >= NUMBER_GLYPH_NODES) + amiv_flush_glyph_buffer(w); + + /* Fill in the node. */ + amiv_g_nodes[glyph_node_index].dsty = + min(w->BorderTop + (cury * mysize), w->Height - 1); #ifdef OPT_DISPMAP - if(sysflags.fast_map){ + if (sysflags.fast_map) { #endif /* keni */ -#ifdef DISPMAP - /* display_map() needs byte-aligned destinations, and we don't want to - * overwrite the window border. - */ - amiv_g_nodes[glyph_node_index].dstx = - (w->BorderLeft + 8 + (curx * mxsize)) & -8; +#ifdef DISPMAP + /* display_map() needs byte-aligned destinations, and we don't + * want to + * overwrite the window border. + */ + amiv_g_nodes[glyph_node_index].dstx = + (w->BorderLeft + 8 + (curx * mxsize)) & -8; #endif #ifdef OPT_DISPMAP -} else { + } else { #endif #if !defined(DISPMAP) || defined(OPT_DISPMAP) - amiv_g_nodes[glyph_node_index].dstx = min( w->BorderLeft + (curx * mxsize), - w->Width - 1 ); + amiv_g_nodes[glyph_node_index].dstx = + min(w->BorderLeft + (curx * mxsize), w->Width - 1); #endif #ifdef OPT_DISPMAP -} + } #endif - amiv_g_nodes[glyph_node_index].odsty = cw->cury; - amiv_g_nodes[glyph_node_index].odstx = cw->curx; - amiv_g_nodes[glyph_node_index].srcx = xoff; - amiv_g_nodes[glyph_node_index].srcy = yoff; - amiv_g_nodes[glyph_node_index].bitmap = ifftimg[ tbl ]; - ++glyph_node_index; - } - else - { - /* Do it */ - register int j, k, x, y, apen; - struct RastPort *rp = w->RPort; - x = rp->cp_x - pictdata.xsize - 3; + amiv_g_nodes[glyph_node_index].odsty = cw->cury; + amiv_g_nodes[glyph_node_index].odstx = cw->curx; + amiv_g_nodes[glyph_node_index].srcx = xoff; + amiv_g_nodes[glyph_node_index].srcy = yoff; + amiv_g_nodes[glyph_node_index].bitmap = ifftimg[tbl]; + ++glyph_node_index; + } else { + /* Do it */ + register int j, k, x, y, apen; + struct RastPort *rp = w->RPort; + x = rp->cp_x - pictdata.xsize - 3; #ifdef OPT_DISPMAP - if(sysflags.fast_map){ + if (sysflags.fast_map) { #endif #ifdef DISPMAP - x &= -8; - if(x==0) x = 8; + x &= -8; + if (x == 0) + x = 8; #endif #ifdef OPT_DISPMAP - } + } #endif - y = rp->cp_y - pictdata.ysize + 1; + y = rp->cp_y - pictdata.ysize + 1; - if( glyph != NO_GLYPH ) - { - struct BitMap *bm = ifftimg[ tbl ]; + if (glyph != NO_GLYPH) { + struct BitMap *bm = ifftimg[tbl]; - /* 8 bits per byte */ - xoff /= 8; - yoff *= bm->BytesPerRow; - for( j = 0; j < pictdata.nplanes; ++j ) - { - for( k = 0; k < pictdata.ysize; ++k ) - { - memcpy( tile->Planes[ j ] + ( ( k * pictdata.ysize ) / 8 ), - bm->Planes[ j ] + xoff + yoff + ( bm->BytesPerRow * k ), - pictdata.ysize/8 ); - } - } + /* 8 bits per byte */ + xoff /= 8; + yoff *= bm->BytesPerRow; + for (j = 0; j < pictdata.nplanes; ++j) { + for (k = 0; k < pictdata.ysize; ++k) { + memcpy(tile->Planes[j] + ((k * pictdata.ysize) / 8), + bm->Planes[j] + xoff + yoff + + (bm->BytesPerRow * k), + pictdata.ysize / 8); + } + } - BltBitMapRastPort( tile, 0, 0, - rp, x, y, - pictdata.xsize, pictdata.ysize, 0xc0 ); + BltBitMapRastPort(tile, 0, 0, rp, x, y, pictdata.xsize, + pictdata.ysize, 0xc0); - apen = rp->FgPen; - SetAPen( rp, sysflags.amii_dripens[ SHINEPEN ] ); - Move( rp, x-1, y + pictdata.ysize ); - Draw( rp, x-1, y - 1 ); - Draw( rp, x + pictdata.xsize, y - 1 ); - SetAPen( rp, sysflags.amii_dripens[ SHADOWPEN ] ); - Move( rp, x + pictdata.xsize, y ); - Draw( rp, x + pictdata.xsize, y + pictdata.ysize ); - Draw( rp, x, y + pictdata.ysize ); - SetAPen( rp, apen ); - } - else if( x > w->BorderLeft ) - { - int apen, bpen; - apen = rp->FgPen; - bpen = rp->BgPen; - SetAPen( rp, amii_menuBPen ); - SetBPen( rp, amii_menuBPen ); - RectFill( rp, x-1, y-1, x + pictdata.xsize, y + pictdata.ysize ); - SetAPen( rp, apen ); - SetBPen( rp, bpen ); - } + apen = rp->FgPen; + SetAPen(rp, sysflags.amii_dripens[SHINEPEN]); + Move(rp, x - 1, y + pictdata.ysize); + Draw(rp, x - 1, y - 1); + Draw(rp, x + pictdata.xsize, y - 1); + SetAPen(rp, sysflags.amii_dripens[SHADOWPEN]); + Move(rp, x + pictdata.xsize, y); + Draw(rp, x + pictdata.xsize, y + pictdata.ysize); + Draw(rp, x, y + pictdata.ysize); + SetAPen(rp, apen); + } else if (x > w->BorderLeft) { + int apen, bpen; + apen = rp->FgPen; + bpen = rp->BgPen; + SetAPen(rp, amii_menuBPen); + SetBPen(rp, amii_menuBPen); + RectFill(rp, x - 1, y - 1, x + pictdata.xsize, + y + pictdata.ysize); + SetAPen(rp, apen); + SetBPen(rp, bpen); + } } } @@ -863,19 +810,19 @@ static int usecolor; void amiv_start_glyphout(window) - winid window; +winid window; { struct amii_WinDesc *cw; struct Window *w; - if( ( cw=amii_wins[window] ) == (struct amii_WinDesc *)NULL ) - panic( "bad winid %d in start_glyphout()", window ); + if ((cw = amii_wins[window]) == (struct amii_WinDesc *) NULL) + panic("bad winid %d in start_glyphout()", window); - if( cw->wflags & FLMAP_INGLYPH ) - return; + if (cw->wflags & FLMAP_INGLYPH) + return; - if( !(w = cw->win ) ) - panic( "bad winid %d, no window ptr set", window ); + if (!(w = cw->win)) + panic("bad winid %d, no window ptr set", window); /* * Save the context of the window @@ -899,20 +846,20 @@ amiv_start_glyphout(window) */ void amii_end_glyphout(window) - winid window; +winid window; { struct amii_WinDesc *cw; struct Window *w; - if( ( cw = amii_wins[ window ] ) == (struct amii_WinDesc *)NULL ) - panic("bad window id %d in amii_end_glyphout()", window ); + if ((cw = amii_wins[window]) == (struct amii_WinDesc *) NULL) + panic("bad window id %d in amii_end_glyphout()", window); - if( ( cw->wflags & FLMAP_INGLYPH ) == 0 ) - return; + if ((cw->wflags & FLMAP_INGLYPH) == 0) + return; cw->wflags &= ~(FLMAP_INGLYPH); - if( !(w = cw->win ) ) - panic( "bad winid %d, no window ptr set", window ); + if (!(w = cw->win)) + panic("bad winid %d, no window ptr set", window); /* * Clean up whatever is left in the buffer @@ -929,37 +876,40 @@ amii_end_glyphout(window) Move(w->RPort, xsave, ysave); } -static maze_type=COL_MAZE_BRICK; +static maze_type = COL_MAZE_BRICK; -void SetMazeType(MazeType t) +void +SetMazeType(MazeType t) { - maze_type=t; + maze_type = t; } -int GlyphToIcon(int glyph) +int +GlyphToIcon(int glyph) { - if(glyph>10000)return glyph; - return( glyph2tile[glyph] ); + if (glyph > 10000) + return glyph; + return (glyph2tile[glyph]); } #endif #ifdef AMII_GRAPHICS -# ifdef TESTING +#ifdef TESTING /* * Define some stuff for our special glyph drawing routines */ static unsigned short glyph_node_index, glyph_buffer_index; -# define NUMBER_GLYPH_NODES 80 -# define GLYPH_BUFFER_SIZE 512 -# endif /* TESTING */ +#define NUMBER_GLYPH_NODES 80 +#define GLYPH_BUFFER_SIZE 512 +#endif /* TESTING */ struct amii_glyph_node { - short x; - short y; - short len; - unsigned char bg_color; - unsigned char fg_color; - char *buffer; + short x; + short y; + short len; + unsigned char bg_color; + unsigned char fg_color; + char *buffer; }; static struct amii_glyph_node amii_g_nodes[NUMBER_GLYPH_NODES]; static char amii_glyph_buffer[GLYPH_BUFFER_SIZE]; @@ -970,26 +920,30 @@ static char amii_glyph_buffer[GLYPH_BUFFER_SIZE]; * See winami.c for the amiga specific colormap. */ -int foreg[AMII_MAXCOLORS] = { 0, 7, 4, 2, 6, 5, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; -int backg[AMII_MAXCOLORS] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 4, 1, 6, 5, 3, 1 }; +int foreg[AMII_MAXCOLORS] = { + 0, 7, 4, 2, 6, 5, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0 +}; +int backg[AMII_MAXCOLORS] = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 4, 1, 6, 5, 3, 1 +}; #if 0 - #define CLR_BLACK 0 - #define CLR_RED 1 - #define CLR_GREEN 2 - #define CLR_BROWN 3 /* on IBM, low-intensity yellow is brown */ - #define CLR_BLUE 4 - #define CLR_MAGENTA 5 - #define CLR_CYAN 6 - #define CLR_GRAY 7 /* low-intensity white */ - #define NO_COLOR 8 - #define CLR_ORANGE 9 - #define CLR_BRIGHT_GREEN 10 - #define CLR_YELLOW 11 - #define CLR_BRIGHT_BLUE 12 - #define CLR_BRIGHT_MAGENTA 13 - #define CLR_BRIGHT_CYAN 14 - #define CLR_WHITE 15 - #define CLR_MAX 16 +#define CLR_BLACK 0 +#define CLR_RED 1 +#define CLR_GREEN 2 +#define CLR_BROWN 3 /* on IBM, low-intensity yellow is brown */ +#define CLR_BLUE 4 +#define CLR_MAGENTA 5 +#define CLR_CYAN 6 +#define CLR_GRAY 7 /* low-intensity white */ +#define NO_COLOR 8 +#define CLR_ORANGE 9 +#define CLR_BRIGHT_GREEN 10 +#define CLR_YELLOW 11 +#define CLR_BRIGHT_BLUE 12 +#define CLR_BRIGHT_MAGENTA 13 +#define CLR_BRIGHT_CYAN 14 +#define CLR_WHITE 15 +#define CLR_MAX 16 #endif #endif @@ -1017,65 +971,65 @@ int backg[AMII_MAXCOLORS] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 4, 1, 6, 5, 3, 1 }; * Routine to simply flush whatever is buffered */ void -amii_flush_glyph_buffer( w ) - struct Window *w; +amii_flush_glyph_buffer(w) +struct Window *w; { short i, x, y; register struct RastPort *rp = w->RPort; /* If nothing is buffered, return before we do anything */ - if(glyph_node_index == 0) - return; + if (glyph_node_index == 0) + return; - cursor_off( WIN_MAP ); - amii_start_glyphout( WIN_MAP ); + cursor_off(WIN_MAP); + amii_start_glyphout(WIN_MAP); /* Set up the drawing mode */ - SetDrMd( rp, JAM2); + SetDrMd(rp, JAM2); /* Go ahead and start dumping the stuff */ - for(i=0; iBorderTop + (amii_g_nodes[i].y-2) * rp->TxHeight + - rp->TxBaseline + 1; - x = amii_g_nodes[i].x * rp->TxWidth + w->BorderLeft; + for (i = 0; i < glyph_node_index; ++i) { + /* These coordinate calculations must be synced with the + * code in amii_curs() in winfuncs.c. curs_on_u() calls amii_curs() + * to draw the cursor on top of the player + */ + y = w->BorderTop + (amii_g_nodes[i].y - 2) * rp->TxHeight + + rp->TxBaseline + 1; + x = amii_g_nodes[i].x * rp->TxWidth + w->BorderLeft; - /* Move pens to correct location */ - Move( rp, (long)x, (long)y); + /* Move pens to correct location */ + Move(rp, (long) x, (long) y); - /* Setup the colors */ - SetAPen( rp, (long)amii_g_nodes[i].fg_color); - SetBPen( rp, (long)amii_g_nodes[i].bg_color); + /* Setup the colors */ + SetAPen(rp, (long) amii_g_nodes[i].fg_color); + SetBPen(rp, (long) amii_g_nodes[i].bg_color); - /* Do it */ - Text( rp, amii_g_nodes[i].buffer, amii_g_nodes[i].len); + /* Do it */ + Text(rp, amii_g_nodes[i].buffer, amii_g_nodes[i].len); } - amii_end_glyphout( WIN_MAP ); + amii_end_glyphout(WIN_MAP); /* Clean up */ glyph_node_index = glyph_buffer_index = 0; } void -amiga_print_glyph(window,color_index, glyph) - winid window; - int color_index, glyph; +amiga_print_glyph(window, color_index, glyph) +winid window; +int color_index, glyph; { - if( WINVERS_AMIV ) - amiv_lprint_glyph(window,color_index, glyph); + if (WINVERS_AMIV) + amiv_lprint_glyph(window, color_index, glyph); else - amii_lprint_glyph(window,color_index, glyph); + amii_lprint_glyph(window, color_index, glyph); } /* * Glyph buffering routine. Called instead of WindowPuts(). */ void -amii_lprint_glyph(window,color_index, glyph) - winid window; - int color_index, glyph; +amii_lprint_glyph(window, color_index, glyph) +winid window; +int color_index, glyph; { int fg_color, bg_color; struct amii_WinDesc *cw; @@ -1083,12 +1037,12 @@ amii_lprint_glyph(window,color_index, glyph) int curx; int cury; - if( ( cw=amii_wins[window] ) == (struct amii_WinDesc *)NULL ) - panic("bad winid in amii_lprint_glyph: %d", window ); + if ((cw = amii_wins[window]) == (struct amii_WinDesc *) NULL) + panic("bad winid in amii_lprint_glyph: %d", window); w = cw->win; - curx=cw->curx; - cury=cw->cury; + curx = cw->curx; + cury = cw->cury; #ifdef TEXTCOLOR fg_color = foreg[color_index]; @@ -1099,8 +1053,8 @@ amii_lprint_glyph(window,color_index, glyph) #endif /* TEXTCOLOR */ /* See if we have enough character buffer space... */ - if(glyph_buffer_index >= GLYPH_BUFFER_SIZE) - amii_flush_glyph_buffer( w ); + if (glyph_buffer_index >= GLYPH_BUFFER_SIZE) + amii_flush_glyph_buffer(w); /* * See if we can append it to the current active node of glyph buffer. It @@ -1110,30 +1064,31 @@ amii_lprint_glyph(window,color_index, glyph) * * foreground colors are the same, AND * * they are precisely side by side */ - if((glyph_buffer_index != 0) && - (fg_color == amii_g_nodes[glyph_node_index-1].fg_color) && - (bg_color == amii_g_nodes[glyph_node_index-1].bg_color) && - (amii_g_nodes[glyph_node_index-1].x+ - amii_g_nodes[glyph_node_index-1].len == curx) && - (amii_g_nodes[glyph_node_index-1].y == cury)) { - /* - * Add it to the end of the buffer - */ - amii_glyph_buffer[glyph_buffer_index++] = glyph; - amii_g_nodes[glyph_node_index-1].len ++; - } else { - /* See if we're out of glyph nodes */ - if(glyph_node_index >= NUMBER_GLYPH_NODES) - amii_flush_glyph_buffer( w ); - amii_g_nodes[glyph_node_index].len = 1; - amii_g_nodes[glyph_node_index].x = curx; - amii_g_nodes[glyph_node_index].y = cury; - amii_g_nodes[glyph_node_index].fg_color = fg_color; - amii_g_nodes[glyph_node_index].bg_color = bg_color; - amii_g_nodes[glyph_node_index].buffer = &amii_glyph_buffer[glyph_buffer_index]; - amii_glyph_buffer[glyph_buffer_index] = glyph; - ++glyph_buffer_index; - ++glyph_node_index; + if ((glyph_buffer_index != 0) + && (fg_color == amii_g_nodes[glyph_node_index - 1].fg_color) + && (bg_color == amii_g_nodes[glyph_node_index - 1].bg_color) + && (amii_g_nodes[glyph_node_index - 1].x + + amii_g_nodes[glyph_node_index - 1].len + == curx) && (amii_g_nodes[glyph_node_index - 1].y == cury)) { + /* + * Add it to the end of the buffer + */ + amii_glyph_buffer[glyph_buffer_index++] = glyph; + amii_g_nodes[glyph_node_index - 1].len++; + } else { + /* See if we're out of glyph nodes */ + if (glyph_node_index >= NUMBER_GLYPH_NODES) + amii_flush_glyph_buffer(w); + amii_g_nodes[glyph_node_index].len = 1; + amii_g_nodes[glyph_node_index].x = curx; + amii_g_nodes[glyph_node_index].y = cury; + amii_g_nodes[glyph_node_index].fg_color = fg_color; + amii_g_nodes[glyph_node_index].bg_color = bg_color; + amii_g_nodes[glyph_node_index].buffer = + &amii_glyph_buffer[glyph_buffer_index]; + amii_glyph_buffer[glyph_buffer_index] = glyph; + ++glyph_buffer_index; + ++glyph_node_index; } } #endif /* !TESTING */ @@ -1155,19 +1110,19 @@ static int usecolor; void amii_start_glyphout(window) - winid window; +winid window; { struct amii_WinDesc *cw; struct Window *w; - if( ( cw=amii_wins[window] ) == (struct amii_WinDesc *)NULL ) - panic( "bad winid %d in start_glyphout()", window ); + if ((cw = amii_wins[window]) == (struct amii_WinDesc *) NULL) + panic("bad winid %d in start_glyphout()", window); - if( cw->wflags & FLMAP_INGLYPH ) - return; + if (cw->wflags & FLMAP_INGLYPH) + return; - if( !(w = cw->win ) ) - panic( "bad winid %d, no window ptr set", window ); + if (!(w = cw->win)) + panic("bad winid %d, no window ptr set", window); /* * Save the context of the window @@ -1187,7 +1142,7 @@ amii_start_glyphout(window) } #endif /* !TESTING */ -# if 0 +#if 0 /* * General cleanup routine -- flushes and restores cursor */ @@ -1222,27 +1177,26 @@ amii_end_glyphout(window) Move(w->RPort, xsave, ysave); } -# endif +#endif #endif #ifndef TESTING -# ifdef OPT_DISPMAP +#ifdef OPT_DISPMAP /* don't use dispmap unless x & y are 8,16,24,32,48 and equal */ void -dispmap_sanity(){ - if( - mxsize != mysize || - dispmap_sanity1(mxsize) || - dispmap_sanity1(mysize)){ - sysflags.fast_map = 0; - } +dispmap_sanity() +{ + if (mxsize != mysize || dispmap_sanity1(mxsize) + || dispmap_sanity1(mysize)) { + sysflags.fast_map = 0; + } } int dispmap_sanity1(x) - int x; +int x; { - static unsigned char valid[] = {8,16,24,32,48,0}; - return !!strchr(valid,x); + static unsigned char valid[] = { 8, 16, 24, 32, 48, 0 }; + return !!strchr(valid, x); } -# endif /* OPT_DISPMAP */ +#endif /* OPT_DISPMAP */ #endif /* TESTING */ diff --git a/sys/amiga/winfuncs.c b/sys/amiga/winfuncs.c index 154e88d8f..f4547816f 100644 --- a/sys/amiga/winfuncs.c +++ b/sys/amiga/winfuncs.c @@ -1,6 +1,7 @@ -/* NetHack 3.6 winfuncs.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winfuncs.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 winfuncs.c $Date: 2012/01/10 17:47:21 $ $Revision: 1.8 $ */ -/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. */ +/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. + */ /* NetHack may be freely redistributed. See license for details. */ #include "NH:sys/amiga/windefs.h" @@ -14,7 +15,7 @@ extern struct TagItem scrntags[]; static BitMapHeader amii_bmhd; static void cursor_common(struct RastPort *, int, int); -#ifdef CLIPPING +#ifdef CLIPPING int CO, LI; /* Changing clipping region, skip clear of screen in overview window. */ @@ -43,222 +44,215 @@ int amii_otherBPen; long amii_libvers = LIBRARY_FONT_VERSION; void -ami_wininit_data( dir ) - int dir; +ami_wininit_data(dir) +int dir; { - extern unsigned short amii_init_map[ AMII_MAXCOLORS ]; - extern unsigned short amiv_init_map[ AMII_MAXCOLORS ]; + extern unsigned short amii_init_map[AMII_MAXCOLORS]; + extern unsigned short amiv_init_map[AMII_MAXCOLORS]; - if( dir != WININIT) return; + if (dir != WININIT) + return; - if( !WINVERS_AMIV ) - { -# ifdef TEXTCOLOR - amii_numcolors = 8; -# else - amii_numcolors = 4; -# endif - amii_defpens[ 0 ] = C_BLACK; /* DETAILPEN */ - amii_defpens[ 1 ] = C_BLUE; /* BLOCKPEN */ - amii_defpens[ 2 ] = C_BROWN; /* TEXTPEN */ - amii_defpens[ 3 ] = C_WHITE; /* SHINEPEN */ - amii_defpens[ 4 ] = C_BLUE; /* SHADOWPEN */ - amii_defpens[ 5 ] = C_CYAN; /* FILLPEN */ - amii_defpens[ 6 ] = C_WHITE; /* FILLTEXTPEN */ - amii_defpens[ 7 ] = C_CYAN; /* BACKGROUNDPEN */ - amii_defpens[ 8 ] = C_RED; /* HIGHLIGHTTEXTPEN */ - amii_defpens[ 9 ] = C_WHITE; /* BARDETAILPEN */ - amii_defpens[ 10 ] = C_CYAN; /* BARBLOCKPEN */ - amii_defpens[ 11 ] = C_BLUE; /* BARTRIMPEN */ - amii_defpens[ 12 ] = (unsigned short) ~0; + if (!WINVERS_AMIV) { +#ifdef TEXTCOLOR + amii_numcolors = 8; +#else + amii_numcolors = 4; +#endif + amii_defpens[0] = C_BLACK; /* DETAILPEN */ + amii_defpens[1] = C_BLUE; /* BLOCKPEN */ + amii_defpens[2] = C_BROWN; /* TEXTPEN */ + amii_defpens[3] = C_WHITE; /* SHINEPEN */ + amii_defpens[4] = C_BLUE; /* SHADOWPEN */ + amii_defpens[5] = C_CYAN; /* FILLPEN */ + amii_defpens[6] = C_WHITE; /* FILLTEXTPEN */ + amii_defpens[7] = C_CYAN; /* BACKGROUNDPEN */ + amii_defpens[8] = C_RED; /* HIGHLIGHTTEXTPEN */ + amii_defpens[9] = C_WHITE; /* BARDETAILPEN */ + amii_defpens[10] = C_CYAN; /* BARBLOCKPEN */ + amii_defpens[11] = C_BLUE; /* BARTRIMPEN */ + amii_defpens[12] = (unsigned short) ~0; - amii_msgAPen = C_WHITE; - amii_msgBPen = C_BLACK; - amii_statAPen = C_WHITE; - amii_statBPen = C_BLACK; - amii_menuAPen = C_WHITE; - amii_menuBPen = C_BLACK; - amii_textAPen = C_WHITE; - amii_textBPen = C_BLACK; - amii_otherAPen = C_RED; - amii_otherBPen = C_BLACK; + amii_msgAPen = C_WHITE; + amii_msgBPen = C_BLACK; + amii_statAPen = C_WHITE; + amii_statBPen = C_BLACK; + amii_menuAPen = C_WHITE; + amii_menuBPen = C_BLACK; + amii_textAPen = C_WHITE; + amii_textBPen = C_BLACK; + amii_otherAPen = C_RED; + amii_otherBPen = C_BLACK; - mxsize = 8; - mysize = 8; + mxsize = 8; + mysize = 8; - amii_libvers = LIBRARY_FONT_VERSION; - memcpy( amii_initmap, amii_init_map, sizeof( amii_initmap ) ); - } - else - { - mxsize = 16; - mysize = 16; + amii_libvers = LIBRARY_FONT_VERSION; + memcpy(amii_initmap, amii_init_map, sizeof(amii_initmap)); + } else { + mxsize = 16; + mysize = 16; - amii_numcolors = 16; + amii_numcolors = 16; - amii_defpens[ 0 ] = C_BLACK; /* DETAILPEN */ - amii_defpens[ 1 ] = C_WHITE; /* BLOCKPEN */ - amii_defpens[ 2 ] = C_BLACK; /* TEXTPEN */ - amii_defpens[ 3 ] = C_CYAN; /* SHINEPEN */ - amii_defpens[ 4 ] = C_BLUE; /* SHADOWPEN */ - amii_defpens[ 5 ] = C_GREYBLUE; /* FILLPEN */ - amii_defpens[ 6 ] = C_LTGREY; /* FILLTEXTPEN */ - amii_defpens[ 7 ] = C_GREYBLUE; /* BACKGROUNDPEN */ - amii_defpens[ 8 ] = C_RED; /* HIGHLIGHTTEXTPEN */ - amii_defpens[ 9 ] = C_WHITE; /* BARDETAILPEN */ - amii_defpens[ 10] = C_GREYBLUE; /* BARBLOCKPEN */ - amii_defpens[ 11] = C_BLUE; /* BARTRIMPEN */ - amii_defpens[ 12] = (unsigned short) ~0; + amii_defpens[0] = C_BLACK; /* DETAILPEN */ + amii_defpens[1] = C_WHITE; /* BLOCKPEN */ + amii_defpens[2] = C_BLACK; /* TEXTPEN */ + amii_defpens[3] = C_CYAN; /* SHINEPEN */ + amii_defpens[4] = C_BLUE; /* SHADOWPEN */ + amii_defpens[5] = C_GREYBLUE; /* FILLPEN */ + amii_defpens[6] = C_LTGREY; /* FILLTEXTPEN */ + amii_defpens[7] = C_GREYBLUE; /* BACKGROUNDPEN */ + amii_defpens[8] = C_RED; /* HIGHLIGHTTEXTPEN */ + amii_defpens[9] = C_WHITE; /* BARDETAILPEN */ + amii_defpens[10] = C_GREYBLUE; /* BARBLOCKPEN */ + amii_defpens[11] = C_BLUE; /* BARTRIMPEN */ + amii_defpens[12] = (unsigned short) ~0; - amii_msgAPen = C_WHITE; - amii_msgBPen = C_GREYBLUE; - amii_statAPen = C_WHITE; - amii_statBPen = C_GREYBLUE; - amii_menuAPen = C_BLACK; - amii_menuBPen = C_LTGREY; - amii_textAPen = C_BLACK; - amii_textBPen = C_LTGREY; - amii_otherAPen = C_RED; - amii_otherBPen = C_BLACK; - amii_libvers = LIBRARY_TILE_VERSION; + amii_msgAPen = C_WHITE; + amii_msgBPen = C_GREYBLUE; + amii_statAPen = C_WHITE; + amii_statBPen = C_GREYBLUE; + amii_menuAPen = C_BLACK; + amii_menuBPen = C_LTGREY; + amii_textAPen = C_BLACK; + amii_textBPen = C_LTGREY; + amii_otherAPen = C_RED; + amii_otherBPen = C_BLACK; + amii_libvers = LIBRARY_TILE_VERSION; - memcpy( amii_initmap, amiv_init_map, sizeof( amii_initmap ) ); + memcpy(amii_initmap, amiv_init_map, sizeof(amii_initmap)); } #ifdef OPT_DISPMAP dispmap_sanity(); #endif - memcpy(sysflags.amii_dripens,amii_defpens,sizeof(sysflags.amii_dripens)); + memcpy(sysflags.amii_dripens, amii_defpens, + sizeof(sysflags.amii_dripens)); } -# ifdef INTUI_NEW_LOOK +#ifdef INTUI_NEW_LOOK struct Hook SM_FilterHook; struct Hook fillhook; -struct TagItem wintags[] = -{ - { WA_BackFill, (ULONG)&fillhook }, - { WA_PubScreenName, (ULONG)"NetHack" }, - { TAG_END, 0 }, +struct TagItem wintags[] = { + { WA_BackFill, (ULONG) &fillhook }, + { WA_PubScreenName, (ULONG) "NetHack" }, + { TAG_END, 0 }, }; -# endif +#endif -void -amii_destroy_nhwindow(win) /* just hide */ - register winid win; +void amii_destroy_nhwindow(win) /* just hide */ +register winid win; { int i; int type; register struct amii_WinDesc *cw; - if( win == WIN_ERR || ( cw = amii_wins[win] ) == NULL ) - { - panic(winpanicstr,win,"destroy_nhwindow"); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL) { + panic(winpanicstr, win, "destroy_nhwindow"); } - if( WINVERS_AMIV ) - { - if( cw->type == NHW_MAP ) - { - /* If inventory is up, close it now, it will be freed later */ - if( alwaysinvent && WIN_INVEN != WIN_ERR && - amii_wins[ WIN_INVEN ] && - amii_wins[ WIN_INVEN ]->win ) - { - dismiss_nhwindow( WIN_INVEN ); - } + if (WINVERS_AMIV) { + if (cw->type == NHW_MAP) { + /* If inventory is up, close it now, it will be freed later */ + if (alwaysinvent && WIN_INVEN != WIN_ERR && amii_wins[WIN_INVEN] + && amii_wins[WIN_INVEN]->win) { + dismiss_nhwindow(WIN_INVEN); + } - /* Tear down overview window if it is up */ - if( WIN_OVER != WIN_ERR ) - { - amii_destroy_nhwindow( WIN_OVER ); - WIN_OVER = WIN_ERR; - } - } - else if( cw->type == NHW_OVER ) - { - struct Window *w = amii_wins[ WIN_OVER ]->win; - amii_oldover.MinX = w->LeftEdge; - amii_oldover.MinY = w->TopEdge; - amii_oldover.MaxX = w->Width; - amii_oldover.MaxY = w->Height; + /* Tear down overview window if it is up */ + if (WIN_OVER != WIN_ERR) { + amii_destroy_nhwindow(WIN_OVER); + WIN_OVER = WIN_ERR; + } + } else if (cw->type == NHW_OVER) { + struct Window *w = amii_wins[WIN_OVER]->win; + amii_oldover.MinX = w->LeftEdge; + amii_oldover.MinY = w->TopEdge; + amii_oldover.MaxX = w->Width; + amii_oldover.MaxY = w->Height; - if( WIN_MESSAGE != WIN_ERR && amii_wins[ WIN_MESSAGE ] ) - { - w = amii_wins[ WIN_MESSAGE ]->win; - amii_oldmsg.MinX = w->LeftEdge; - amii_oldmsg.MinY = w->TopEdge; - amii_oldmsg.MaxX = w->Width; - amii_oldmsg.MaxY = w->Height; - SizeWindow( amii_wins[ WIN_MESSAGE ]->win, - (amiIDisplay->xpix - - amii_wins[ WIN_MESSAGE ]->win->LeftEdge) - - amii_wins[ WIN_MESSAGE ]->win->Width, - 0 ); - } - } + if (WIN_MESSAGE != WIN_ERR && amii_wins[WIN_MESSAGE]) { + w = amii_wins[WIN_MESSAGE]->win; + amii_oldmsg.MinX = w->LeftEdge; + amii_oldmsg.MinY = w->TopEdge; + amii_oldmsg.MaxX = w->Width; + amii_oldmsg.MaxY = w->Height; + SizeWindow(amii_wins[WIN_MESSAGE]->win, + (amiIDisplay->xpix + - amii_wins[WIN_MESSAGE]->win->LeftEdge) + - amii_wins[WIN_MESSAGE]->win->Width, + 0); + } + } } /* Tear down the Intuition stuff */ dismiss_nhwindow(win); type = cw->type; - if( cw->resp ) { - free( cw->resp ); - cw->resp = NULL; + if (cw->resp) { + free(cw->resp); + cw->resp = NULL; } - if( cw->canresp ) { - free( cw->canresp ); - cw->canresp = NULL; + if (cw->canresp) { + free(cw->canresp); + cw->canresp = NULL; } - if( cw->morestr ) { - free( cw->morestr ); - cw->morestr = NULL; + if (cw->morestr) { + free(cw->morestr); + cw->morestr = NULL; } - if( cw->hook ) { - free( cw->hook ); - cw->hook = NULL; + if (cw->hook) { + free(cw->hook); + cw->hook = NULL; } - if( cw->data && ( cw->type == NHW_MESSAGE || - cw->type == NHW_MENU || cw->type == NHW_TEXT ) ) - { - for( i = 0; i < cw->maxrow; ++i ) - { - if( cw->data[ i ] ) - free( cw->data[ i ] ); - } - free( cw->data ); + if (cw->data && (cw->type == NHW_MESSAGE || cw->type == NHW_MENU + || cw->type == NHW_TEXT)) { + for (i = 0; i < cw->maxrow; ++i) { + if (cw->data[i]) + free(cw->data[i]); + } + free(cw->data); } - free( cw ); + free(cw); amii_wins[win] = NULL; /* Set globals to WIN_ERR for known one-of-a-kind windows. */ - if( win == WIN_MAP) WIN_MAP = WIN_ERR; - else if( win == WIN_STATUS) WIN_STATUS = WIN_ERR; - else if( win == WIN_MESSAGE) WIN_MESSAGE = WIN_ERR; - else if( win == WIN_INVEN) WIN_INVEN = WIN_ERR; - + if (win == WIN_MAP) + WIN_MAP = WIN_ERR; + else if (win == WIN_STATUS) + WIN_STATUS = WIN_ERR; + else if (win == WIN_MESSAGE) + WIN_MESSAGE = WIN_ERR; + else if (win == WIN_INVEN) + WIN_INVEN = WIN_ERR; } #ifdef INTUI_NEW_LOOK -struct FillParams -{ - struct Layer *layer; - struct Rectangle bounds; - WORD offsetx; - WORD offsety; +struct FillParams { + struct Layer *layer; + struct Rectangle bounds; + WORD offsetx; + WORD offsety; }; #ifdef __GNUC__ #ifdef __PPC__ void PPC_LayerFillHook(void); -struct EmulLibEntry LayerFillHook = {TRAP_LIB, 0, (void (*)(void)) PPC_LayerFillHook}; -void PPC_LayerFillHook(void) { - struct Hook *hk = (struct Hook*)REG_A0; - struct RastPort *rp = (struct RastPort *)REG_A2; - struct FillParams *fp = (struct FillParams*)REG_A1; +struct EmulLibEntry LayerFillHook = { TRAP_LIB, 0, + (void (*)(void)) PPC_LayerFillHook }; +void +PPC_LayerFillHook(void) +{ + struct Hook *hk = (struct Hook *) REG_A0; + struct RastPort *rp = (struct RastPort *) REG_A2; + struct FillParams *fp = (struct FillParams *) REG_A1; #else -void LayerFillHook(void) { +void +LayerFillHook(void) +{ register struct Hook *hk asm("a0"); register struct RastPort *rp asm("a2"); register struct FillParams *fp asm("a1"); @@ -266,12 +260,11 @@ void LayerFillHook(void) { #else void #ifndef _DCC -__interrupt + __interrupt #endif -__saveds __asm LayerFillHook( - register __a0 struct Hook *hk, - register __a2 struct RastPort *rp, - register __a1 struct FillParams *fp ) + __saveds __asm LayerFillHook(register __a0 struct Hook *hk, + register __a2 struct RastPort *rp, + register __a1 struct FillParams *fp) { #endif @@ -282,29 +275,28 @@ __saveds __asm LayerFillHook( memcpy(&rptmp, rp, sizeof(struct RastPort)); rptmp.Layer = NULL; - switch( (int)hk->h_Data ) - { + switch ((int) hk->h_Data) { case NHW_STATUS: - apen = amii_statBPen; - break; + apen = amii_statBPen; + break; case NHW_MESSAGE: - apen = amii_msgBPen; - break; + apen = amii_msgBPen; + break; case NHW_TEXT: - apen = amii_textBPen; - break; + apen = amii_textBPen; + break; case NHW_MENU: - apen = amii_menuBPen; - break; + apen = amii_menuBPen; + break; case -2: - apen = amii_otherBPen; - break; + apen = amii_otherBPen; + break; case NHW_BASE: case NHW_MAP: case NHW_OVER: default: - apen = C_BLACK; - break; + apen = C_BLACK; + break; } x = fp->bounds.MinX; @@ -319,9 +311,7 @@ __saveds __asm LayerFillHook( } #endif - -amii_create_nhwindow(type) - register int type; +amii_create_nhwindow(type) register int type; { register struct Window *w = NULL; register struct NewWindow *nw = NULL; @@ -336,306 +326,280 @@ amii_create_nhwindow(type) * Initial mapwindow height, this might change later in tilemode * and low screen */ - maph = ( 21 * mxsize ) + 2 + (bigscreen ? - HackScreen->WBorTop + HackScreen->WBorBottom + scrfontysize + 1 : 0); + maph = (21 * mxsize) + 2 + + (bigscreen + ? HackScreen->WBorTop + HackScreen->WBorBottom + + scrfontysize + 1 + : 0); /* Status window height, avoids having to calculate many times */ - stath = txheight * 2 + 2 + (WINVERS_AMIV || bigscreen ? - HackScreen->WBorTop + HackScreen->WBorBottom + - ( bigscreen ? scrfontysize + 1 : 0 ) : 0); + stath = + txheight * 2 + 2 + (WINVERS_AMIV || bigscreen + ? HackScreen->WBorTop + HackScreen->WBorBottom + + (bigscreen ? scrfontysize + 1 : 0) + : 0); - if( WIN_STATUS != WIN_ERR && amii_wins[ WIN_STATUS ] ) - stwin = amii_wins[ WIN_STATUS ]->win; + if (WIN_STATUS != WIN_ERR && amii_wins[WIN_STATUS]) + stwin = amii_wins[WIN_STATUS]->win; - if( WIN_MESSAGE != WIN_ERR && amii_wins[ WIN_MESSAGE ] ) - msgwin = amii_wins[ WIN_MESSAGE ]->win; + if (WIN_MESSAGE != WIN_ERR && amii_wins[WIN_MESSAGE]) + msgwin = amii_wins[WIN_MESSAGE]->win; - if( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) - mapwin = amii_wins[ WIN_MAP ]->win; + if (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP]) + mapwin = amii_wins[WIN_MAP]->win; /* Create Port anytime that we need it */ - if( HackPort == NULL ) - { - HackPort = CreateMsgPort(); - if( !HackPort ) - panic( "no memory for msg port" ); + if (HackPort == NULL) { + HackPort = CreateMsgPort(); + if (!HackPort) + panic("no memory for msg port"); } - nw = &new_wins[ type ].newwin; + nw = &new_wins[type].newwin; nw->Width = amiIDisplay->xpix; nw->Screen = HackScreen; - if( WINVERS_AMIV ) - { - nw->DetailPen = C_WHITE; - nw->BlockPen = C_GREYBLUE; - } - else - { - nw->DetailPen = C_WHITE; - nw->BlockPen = C_BLACK; + if (WINVERS_AMIV) { + nw->DetailPen = C_WHITE; + nw->BlockPen = C_GREYBLUE; + } else { + nw->DetailPen = C_WHITE; + nw->BlockPen = C_BLACK; } - if ( type == NHW_BASE ) { - nw->LeftEdge = 0; - nw->TopEdge = HackScreen->BarHeight+1; - nw->Width = HackScreen->Width; - nw->Height = HackScreen->Height - nw->TopEdge; - } else if( !WINVERS_AMIV && type == NHW_MAP ) { - nw->LeftEdge = 0; - nw->Height = maph; + if (type == NHW_BASE) { + nw->LeftEdge = 0; + nw->TopEdge = HackScreen->BarHeight + 1; + nw->Width = HackScreen->Width; + nw->Height = HackScreen->Height - nw->TopEdge; + } else if (!WINVERS_AMIV && type == NHW_MAP) { + nw->LeftEdge = 0; + nw->Height = maph; - if( msgwin && stwin ) { - nw->TopEdge = stwin->TopEdge - maph; - } else { - panic( "msgwin and stwin must open before map" ); - } - if (nw->TopEdge < 0) - panic( "Too small screen to fit map" ); - } - else if( type == NHW_MAP && WINVERS_AMIV ) - { - struct Window *w; + if (msgwin && stwin) { + nw->TopEdge = stwin->TopEdge - maph; + } else { + panic("msgwin and stwin must open before map"); + } + if (nw->TopEdge < 0) + panic("Too small screen to fit map"); + } else if (type == NHW_MAP && WINVERS_AMIV) { + struct Window *w; - w = amii_wins[ WIN_MESSAGE ]->win; - nw->LeftEdge = 0; - nw->TopEdge = w->TopEdge + w->Height; - nw->Width = amiIDisplay->xpix - nw->LeftEdge; + w = amii_wins[WIN_MESSAGE]->win; + nw->LeftEdge = 0; + nw->TopEdge = w->TopEdge + w->Height; + nw->Width = amiIDisplay->xpix - nw->LeftEdge; - w = amii_wins[ WIN_STATUS ]->win; - nw->Height = w->TopEdge - nw->TopEdge; - nw->MaxHeight = 0xffff; - nw->MaxWidth = 0xffff; + w = amii_wins[WIN_STATUS]->win; + nw->Height = w->TopEdge - nw->TopEdge; + nw->MaxHeight = 0xffff; + nw->MaxWidth = 0xffff; - if( nw->TopEdge + nw->Height > amiIDisplay->ypix - 1 ) - nw->Height = amiIDisplay->ypix - nw->TopEdge - 1; - } - else if( type == NHW_STATUS ) - { - if( !WINVERS_AMIV && ( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) ) - w = amii_wins[ WIN_MAP ]->win; - else if( WIN_BASE != WIN_ERR && amii_wins[ WIN_BASE ] ) - w = amii_wins[ WIN_BASE ]->win; - else - panic( "No window to base STATUS location from" ); + if (nw->TopEdge + nw->Height > amiIDisplay->ypix - 1) + nw->Height = amiIDisplay->ypix - nw->TopEdge - 1; + } else if (type == NHW_STATUS) { + if (!WINVERS_AMIV && (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP])) + w = amii_wins[WIN_MAP]->win; + else if (WIN_BASE != WIN_ERR && amii_wins[WIN_BASE]) + w = amii_wins[WIN_BASE]->win; + else + panic("No window to base STATUS location from"); - nw->Height = stath; - nw->TopEdge = amiIDisplay->ypix - nw->Height; - nw->LeftEdge = w->LeftEdge; + nw->Height = stath; + nw->TopEdge = amiIDisplay->ypix - nw->Height; + nw->LeftEdge = w->LeftEdge; - if( nw->LeftEdge + nw->Width >= amiIDisplay->xpix ) - nw->LeftEdge = 0; + if (nw->LeftEdge + nw->Width >= amiIDisplay->xpix) + nw->LeftEdge = 0; - if( nw->Width >= amiIDisplay->xpix - nw->LeftEdge ) - nw->Width = amiIDisplay->xpix - nw->LeftEdge; - } - else if( WINVERS_AMIV && type == NHW_OVER ) - { - nw->Flags |= WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE; - nw->IDCMPFlags |= CLOSEWINDOW; - /* Bring up window as half the width of the message window, and make - * the message window change to one half the width... - */ - if( amii_oldover.MaxX != 0 ) - { - nw->LeftEdge = amii_oldover.MinX; - nw->TopEdge = amii_oldover.MinY; - nw->Width = amii_oldover.MaxX; - nw->Height = amii_oldover.MaxY; - ChangeWindowBox( amii_wins[ WIN_MESSAGE ]->win, - amii_oldmsg.MinX, amii_oldmsg.MinY, - amii_oldmsg.MaxX, amii_oldmsg.MaxY ); - } - else - { - nw->LeftEdge = (amii_wins[ WIN_MESSAGE ]->win->Width*4)/9; - nw->TopEdge = amii_wins[ WIN_MESSAGE ]->win->TopEdge; - nw->Width = amiIDisplay->xpix - nw->LeftEdge; - nw->Height = amii_wins[ WIN_MESSAGE ]->win->Height; - SizeWindow( amii_wins[ WIN_MESSAGE ]->win, - nw->LeftEdge - amii_wins[ WIN_MESSAGE ]->win->Width, 0 ); - } - } - else if( type == NHW_MESSAGE ) - { - if( !WINVERS_AMIV && ( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) ) - w = amii_wins[ WIN_MAP ]->win; - else if( WIN_BASE != WIN_ERR && amii_wins[ WIN_BASE ] ) - w = amii_wins[ WIN_BASE ]->win; - else - panic( "No window to base STATUS location from" ); + if (nw->Width >= amiIDisplay->xpix - nw->LeftEdge) + nw->Width = amiIDisplay->xpix - nw->LeftEdge; + } else if (WINVERS_AMIV && type == NHW_OVER) { + nw->Flags |= WINDOWSIZING | WINDOWDRAG | WINDOWCLOSE; + nw->IDCMPFlags |= CLOSEWINDOW; + /* Bring up window as half the width of the message window, and make + * the message window change to one half the width... + */ + if (amii_oldover.MaxX != 0) { + nw->LeftEdge = amii_oldover.MinX; + nw->TopEdge = amii_oldover.MinY; + nw->Width = amii_oldover.MaxX; + nw->Height = amii_oldover.MaxY; + ChangeWindowBox(amii_wins[WIN_MESSAGE]->win, amii_oldmsg.MinX, + amii_oldmsg.MinY, amii_oldmsg.MaxX, + amii_oldmsg.MaxY); + } else { + nw->LeftEdge = (amii_wins[WIN_MESSAGE]->win->Width * 4) / 9; + nw->TopEdge = amii_wins[WIN_MESSAGE]->win->TopEdge; + nw->Width = amiIDisplay->xpix - nw->LeftEdge; + nw->Height = amii_wins[WIN_MESSAGE]->win->Height; + SizeWindow(amii_wins[WIN_MESSAGE]->win, + nw->LeftEdge - amii_wins[WIN_MESSAGE]->win->Width, 0); + } + } else if (type == NHW_MESSAGE) { + if (!WINVERS_AMIV && (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP])) + w = amii_wins[WIN_MAP]->win; + else if (WIN_BASE != WIN_ERR && amii_wins[WIN_BASE]) + w = amii_wins[WIN_BASE]->win; + else + panic("No window to base STATUS location from"); - nw->TopEdge = bigscreen ? HackScreen->BarHeight+1 : 0; + nw->TopEdge = bigscreen ? HackScreen->BarHeight + 1 : 0; - /* Assume highest possible message window */ - nw->Height = HackScreen->Height - nw->TopEdge - maph - stath; + /* Assume highest possible message window */ + nw->Height = HackScreen->Height - nw->TopEdge - maph - stath; - /* In tilemode we can cope with this */ - if (WINVERS_AMIV && nw->Height < 0) - nw->Height = 0; + /* In tilemode we can cope with this */ + if (WINVERS_AMIV && nw->Height < 0) + nw->Height = 0; - /* If in fontmode messagewindow is too small, open it with 3 lines - and overlap it with map */ - if (nw->Height < txheight+2) { - nw->Height = txheight*4 + 3 + HackScreen->WBorTop + HackScreen->WBorBottom; - } + /* If in fontmode messagewindow is too small, open it with 3 lines + and overlap it with map */ + if (nw->Height < txheight + 2) { + nw->Height = txheight * 4 + 3 + HackScreen->WBorTop + + HackScreen->WBorBottom; + } - if ((nw->Height-2)/txheight < 3) { - scrollmsg = 0; - nw->Title = 0; - } else { - nw->FirstGadget = &MsgScroll; - nw->Flags |= WINDOWSIZING|WINDOWDRAG; - nw->Flags &= ~BORDERLESS; + if ((nw->Height - 2) / txheight < 3) { + scrollmsg = 0; + nw->Title = 0; + } else { + nw->FirstGadget = &MsgScroll; + nw->Flags |= WINDOWSIZING | WINDOWDRAG; + nw->Flags &= ~BORDERLESS; - if( WINVERS_AMIV || nw->Height == 0) { - if( WINVERS_AMIV ) { - nw->Height = TextsFont->tf_YSize + HackScreen->WBorTop + 3 + - HackScreen->WBorBottom; - if( bigscreen ) - nw->Height += ( txheight * 6 ); - else - nw->Height += ( txheight * 3 ); - } - else - { - nw->Height = HackScreen->Height - nw->TopEdge - stath - maph; - } - } - } + if (WINVERS_AMIV || nw->Height == 0) { + if (WINVERS_AMIV) { + nw->Height = TextsFont->tf_YSize + HackScreen->WBorTop + 3 + + HackScreen->WBorBottom; + if (bigscreen) + nw->Height += (txheight * 6); + else + nw->Height += (txheight * 3); + } else { + nw->Height = + HackScreen->Height - nw->TopEdge - stath - maph; + } + } + } - /* Do we have room for larger message window ? - * This is possible if we can show full height map in tile - * mode with default scaling. - */ - if (nw->Height + stath + maph < HackScreen->Height - nw->TopEdge ) - nw->Height = HackScreen->Height - nw->TopEdge - 1 - maph - stath; + /* Do we have room for larger message window ? + * This is possible if we can show full height map in tile + * mode with default scaling. + */ + if (nw->Height + stath + maph < HackScreen->Height - nw->TopEdge) + nw->Height = HackScreen->Height - nw->TopEdge - 1 - maph - stath; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - MsgPropScroll.Flags |= PROPNEWLOOK; - PropScroll.Flags |= PROPNEWLOOK; - } +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + MsgPropScroll.Flags |= PROPNEWLOOK; + PropScroll.Flags |= PROPNEWLOOK; + } #endif } nw->IDCMPFlags |= MENUPICK; /* Check if there is "Room" for all this stuff... */ - if( ( WINVERS_AMIV || bigscreen ) && - type != NHW_BASE ) - { - nw->Flags &= ~( BORDERLESS | BACKDROP ); + if ((WINVERS_AMIV || bigscreen) && type != NHW_BASE) { + nw->Flags &= ~(BORDERLESS | BACKDROP); - if( WINVERS_AMIV ) - { - if( type == NHW_STATUS ) - { - nw->Flags &= ~( WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | WINDOWSIZING ); - nw->IDCMPFlags &= ~NEWSIZE; - } - else - { - nw->Flags |= ( WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | WINDOWSIZING ); - nw->IDCMPFlags |= NEWSIZE; - } - } - else - { - if( HackScreen->Width < 657 ) - { - nw->Flags |= ( WINDOWDRAG | WINDOWDEPTH ); - } - else - { - nw->Flags |= ( WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT ); - } - } + if (WINVERS_AMIV) { + if (type == NHW_STATUS) { + nw->Flags &= + ~(WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | WINDOWSIZING); + nw->IDCMPFlags &= ~NEWSIZE; + } else { + nw->Flags |= + (WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | WINDOWSIZING); + nw->IDCMPFlags |= NEWSIZE; + } + } else { + if (HackScreen->Width < 657) { + nw->Flags |= (WINDOWDRAG | WINDOWDEPTH); + } else { + nw->Flags |= (WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT); + } + } } - if ( WINVERS_AMII && type == NHW_MAP ) - nw->Flags &= ~WINDOWSIZING; + if (WINVERS_AMII && type == NHW_MAP) + nw->Flags &= ~WINDOWSIZING; - if ( type == NHW_MESSAGE && scrollmsg ) { - nw->Flags |= WINDOWDRAG|WINDOWDEPTH|SIZEBRIGHT|WINDOWSIZING; - nw->Flags &= ~BORDERLESS; + if (type == NHW_MESSAGE && scrollmsg) { + nw->Flags |= WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | WINDOWSIZING; + nw->Flags &= ~BORDERLESS; } /* No titles on a hires only screen except for messagewindow */ - if( !(WINVERS_AMIV && type == NHW_MAP) && !bigscreen && type != NHW_MESSAGE ) - nw->Title = 0; + if (!(WINVERS_AMIV && type == NHW_MAP) && !bigscreen + && type != NHW_MESSAGE) + nw->Title = 0; - wd = (struct amii_WinDesc *)alloc(sizeof(struct amii_WinDesc)); - memset( wd, 0, sizeof( struct amii_WinDesc ) ); + wd = (struct amii_WinDesc *) alloc(sizeof(struct amii_WinDesc)); + memset(wd, 0, sizeof(struct amii_WinDesc)); /* Both, since user may have changed the pen settings so respect those */ - if( WINVERS_AMII || WINVERS_AMIV ) - { - /* Special backfill for these types of layers */ - switch( type ) - { - case NHW_MESSAGE: - case NHW_STATUS: - case NHW_TEXT: - case NHW_MENU: - case NHW_BASE: - case NHW_OVER: - case NHW_MAP: - if( wd ) - { + if (WINVERS_AMII || WINVERS_AMIV) { + /* Special backfill for these types of layers */ + switch (type) { + case NHW_MESSAGE: + case NHW_STATUS: + case NHW_TEXT: + case NHW_MENU: + case NHW_BASE: + case NHW_OVER: + case NHW_MAP: + if (wd) { #ifdef __GNUC__ - fillhook.h_Entry = (void *)&LayerFillHook; + fillhook.h_Entry = (void *) &LayerFillHook; #else - fillhook.h_Entry = (ULONG(*)())LayerFillHook; + fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; #endif - fillhook.h_Data = (void *)type; - fillhook.h_SubEntry = 0; - wd->hook = alloc( sizeof( fillhook ) ); - memcpy( wd->hook, &fillhook, sizeof( fillhook ) ); - memcpy( wd->wintags, wintags, sizeof( wd->wintags) ); - wd->wintags[0].ti_Data = (long)wd->hook; - nw->Extension = (void *)wd->wintags; - } - break; - } + fillhook.h_Data = (void *) type; + fillhook.h_SubEntry = 0; + wd->hook = alloc(sizeof(fillhook)); + memcpy(wd->hook, &fillhook, sizeof(fillhook)); + memcpy(wd->wintags, wintags, sizeof(wd->wintags)); + wd->wintags[0].ti_Data = (long) wd->hook; + nw->Extension = (void *) wd->wintags; + } + break; + } } /* Don't open MENU or TEXT windows yet */ - if( type == NHW_MENU || type == NHW_TEXT ) - w = NULL; + if (type == NHW_MENU || type == NHW_TEXT) + w = NULL; else - w=OpenShWindow( (void *)nw ); + w = OpenShWindow((void *) nw); - if( w == NULL && type != NHW_MENU && type != NHW_TEXT ) - { - char buf[ 100 ]; + if (w == NULL && type != NHW_MENU && type != NHW_TEXT) { + char buf[100]; - sprintf( buf, "nw type (%d) dims l: %d, t: %d, w: %d, h: %d", - type, - nw->LeftEdge, nw->TopEdge, - nw->Width, nw->Height ); - raw_print( buf ); - panic("bad openwin %d",type); + sprintf(buf, "nw type (%d) dims l: %d, t: %d, w: %d, h: %d", type, + nw->LeftEdge, nw->TopEdge, nw->Width, nw->Height); + raw_print(buf); + panic("bad openwin %d", type); } /* Check for an empty slot */ - for(newid = 0; newid wincnt ) - wincnt = newid; + if (newid > wincnt) + wincnt = newid; /* Do common initialization */ @@ -646,220 +610,211 @@ amii_create_nhwindow(type) wd->type = type; wd->wflags = 0; wd->active = FALSE; - wd->curx=wd->cury = 0; - wd->resp = wd->canresp = wd->morestr = 0; /* CHECK THESE */ + wd->curx = wd->cury = 0; + wd->resp = wd->canresp = wd->morestr = 0; /* CHECK THESE */ wd->maxrow = new_wins[type].maxrow; wd->maxcol = new_wins[type].maxcol; - if( type != NHW_TEXT && type != NHW_MENU ) - { - if( TextsFont && ( type == NHW_MESSAGE || type == NHW_STATUS ) ) - { - SetFont(w->RPort, TextsFont); - txheight = w->RPort->TxHeight; - txwidth = w->RPort->TxWidth; - txbaseline = w->RPort->TxBaseline; - if( type == NHW_MESSAGE ) - { - if (scrollmsg ) - { - if( WINVERS_AMIV ) - { - WindowLimits( w, 100, w->BorderTop + - w->BorderBottom + - ((txheight+1)*2) + 1, 0, 0 ); - } - else - { - WindowLimits( w, w->Width, w->BorderTop + - w->BorderBottom + - ((txheight+1)*2) + 1, 0, 0 ); - } - } - else - { - WindowLimits( w, w->Width, w->BorderTop + - w->BorderBottom + - txheight + 2, 0, 0 ); - } - } - } - if ( type != NHW_MAP) { - SetFont(w->RPort, TextsFont); - } + if (type != NHW_TEXT && type != NHW_MENU) { + if (TextsFont && (type == NHW_MESSAGE || type == NHW_STATUS)) { + SetFont(w->RPort, TextsFont); + txheight = w->RPort->TxHeight; + txwidth = w->RPort->TxWidth; + txbaseline = w->RPort->TxBaseline; + if (type == NHW_MESSAGE) { + if (scrollmsg) { + if (WINVERS_AMIV) { + WindowLimits(w, 100, w->BorderTop + w->BorderBottom + + ((txheight + 1) * 2) + 1, + 0, 0); + } else { + WindowLimits(w, w->Width, + w->BorderTop + w->BorderBottom + + ((txheight + 1) * 2) + 1, + 0, 0); + } + } else { + WindowLimits(w, w->Width, w->BorderTop + w->BorderBottom + + txheight + 2, + 0, 0); + } + } + } + if (type != NHW_MAP) { + SetFont(w->RPort, TextsFont); + } #ifdef HACKFONT - else if( HackFont ) - SetFont(w->RPort, HackFont); + else if (HackFont) + SetFont(w->RPort, HackFont); #endif } /* Text and menu windows are not opened yet */ - if( w ) - { - wd->rows = ( w->Height - w->BorderTop - - w->BorderBottom - 2 ) / w->RPort->TxHeight; - wd->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 2 ) / w->RPort->TxWidth; + if (w) { + wd->rows = (w->Height - w->BorderTop - w->BorderBottom - 2) + / w->RPort->TxHeight; + wd->cols = (w->Width - w->BorderLeft - w->BorderRight - 2) + / w->RPort->TxWidth; } /* Okay, now do the individual type initialization */ - switch(type) - { - /* History lines for MESSAGE windows are stored in cw->data[?]. - * maxcol and maxrow are used as cursors. maxrow is the count - * of the number of history lines stored. maxcol is the cursor - * to the last line that was displayed by ^P. - */ - case NHW_MESSAGE: - SetMenuStrip(w, MenuStrip); - MsgScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; - iflags.msg_history = wd->rows*10; - if (iflags.msg_history < 40) - iflags.msg_history = 40; - if (iflags.msg_history > 400) - iflags.msg_history = 400; - iflags.window_inited=TRUE; - wd->data = (char **)alloc( iflags.msg_history*sizeof( char * ) ); - memset( wd->data, 0, iflags.msg_history * sizeof( char * ) ); - wd->maxrow = wd->maxcol = 0; - /* Indicate that we have not positioned the cursor yet */ - wd->curx = -1; - break; + switch (type) { + /* History lines for MESSAGE windows are stored in cw->data[?]. + * maxcol and maxrow are used as cursors. maxrow is the count + * of the number of history lines stored. maxcol is the cursor + * to the last line that was displayed by ^P. + */ + case NHW_MESSAGE: + SetMenuStrip(w, MenuStrip); + MsgScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; + iflags.msg_history = wd->rows * 10; + if (iflags.msg_history < 40) + iflags.msg_history = 40; + if (iflags.msg_history > 400) + iflags.msg_history = 400; + iflags.window_inited = TRUE; + wd->data = (char **) alloc(iflags.msg_history * sizeof(char *)); + memset(wd->data, 0, iflags.msg_history * sizeof(char *)); + wd->maxrow = wd->maxcol = 0; + /* Indicate that we have not positioned the cursor yet */ + wd->curx = -1; + break; - /* A MENU contains a list of lines in wd->data[?]. These - * lines are created in amii_putstr() by reallocating the size - * of wd->data to hold enough (char *)'s. wd->rows is the - * number of (char *)'s allocated. wd->maxrow is the number - * used. wd->maxcol is used to track how wide the menu needs - * to be. wd->resp[x] contains the characters that correspond - * to selecting wd->data[x]. wd->resp[x] corresponds to - * wd->data[x] for any x. Elements of wd->data[?] that are not - * valid selections have the corresponding element of - * wd->resp[] set to a value of '\01'; i.e. a ^A which is - * not currently a valid keystroke for responding to any - * MENU or TEXT window. - */ - case NHW_MENU: - MenuScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; - wd->resp=(char*)alloc(256); - wd->resp[0]=0; - wd->rows = wd->maxrow = 0; - wd->cols = wd->maxcol = 0; - wd->data = NULL; - break; + /* A MENU contains a list of lines in wd->data[?]. These + * lines are created in amii_putstr() by reallocating the size + * of wd->data to hold enough (char *)'s. wd->rows is the + * number of (char *)'s allocated. wd->maxrow is the number + * used. wd->maxcol is used to track how wide the menu needs + * to be. wd->resp[x] contains the characters that correspond + * to selecting wd->data[x]. wd->resp[x] corresponds to + * wd->data[x] for any x. Elements of wd->data[?] that are not + * valid selections have the corresponding element of + * wd->resp[] set to a value of '\01'; i.e. a ^A which is + * not currently a valid keystroke for responding to any + * MENU or TEXT window. + */ + case NHW_MENU: + MenuScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; + wd->resp = (char *) alloc(256); + wd->resp[0] = 0; + wd->rows = wd->maxrow = 0; + wd->cols = wd->maxcol = 0; + wd->data = NULL; + break; - /* See the explanation of MENU above. Except, wd->resp[] is not - * used for TEXT windows since there is no selection of a - * a line performed/allowed. The window is always full - * screen width. - */ - case NHW_TEXT: - MenuScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; - wd->rows = wd->maxrow = 0; - wd->cols = wd->maxcol = amiIDisplay->cols; - wd->data = NULL; - wd->morestr = NULL; - break; + /* See the explanation of MENU above. Except, wd->resp[] is not + * used for TEXT windows since there is no selection of a + * a line performed/allowed. The window is always full + * screen width. + */ + case NHW_TEXT: + MenuScroll.TopEdge = HackScreen->WBorTop + scrfontysize + 1; + wd->rows = wd->maxrow = 0; + wd->cols = wd->maxcol = amiIDisplay->cols; + wd->data = NULL; + wd->morestr = NULL; + break; - /* The status window has only two lines. These are stored in - * wd->data[], and here we allocate the space for them. - */ - case NHW_STATUS: - SetMenuStrip(w, MenuStrip); - /* wd->cols is the number of characters which fit across the - * screen. - */ - wd->data=(char **)alloc(3*sizeof(char *)); - wd->data[0] = (char *)alloc(wd->cols + 10); - wd->data[1] = (char *)alloc(wd->cols + 10); - wd->data[2] = NULL; - break; + /* The status window has only two lines. These are stored in + * wd->data[], and here we allocate the space for them. + */ + case NHW_STATUS: + SetMenuStrip(w, MenuStrip); + /* wd->cols is the number of characters which fit across the + * screen. + */ + wd->data = (char **) alloc(3 * sizeof(char *)); + wd->data[0] = (char *) alloc(wd->cols + 10); + wd->data[1] = (char *) alloc(wd->cols + 10); + wd->data[2] = NULL; + break; - /* NHW_OVER does not use wd->data[] or the other text - * manipulating members of the amii_WinDesc structure. - */ - case NHW_OVER: - SetMenuStrip(w, MenuStrip); - break; + /* NHW_OVER does not use wd->data[] or the other text + * manipulating members of the amii_WinDesc structure. + */ + case NHW_OVER: + SetMenuStrip(w, MenuStrip); + break; - /* NHW_MAP does not use wd->data[] or the other text - * manipulating members of the amii_WinDesc structure. - */ - case NHW_MAP: - SetMenuStrip(w, MenuStrip); - if( WINVERS_AMIV ) - { - CO = (w->Width-w->BorderLeft-w->BorderRight)/mxsize; - LI = (w->Height-w->BorderTop-w->BorderBottom)/mysize; - amii_setclipped(); - SetFont( w->RPort, RogueFont); - SetAPen( w->RPort, C_WHITE); /* XXX not sufficient */ - SetBPen( w->RPort, C_BLACK); - SetDrMd( w->RPort, JAM2); - } - else - { - if( HackFont ) - SetFont( w->RPort, HackFont ); - } - break; + /* NHW_MAP does not use wd->data[] or the other text + * manipulating members of the amii_WinDesc structure. + */ + case NHW_MAP: + SetMenuStrip(w, MenuStrip); + if (WINVERS_AMIV) { + CO = (w->Width - w->BorderLeft - w->BorderRight) / mxsize; + LI = (w->Height - w->BorderTop - w->BorderBottom) / mysize; + amii_setclipped(); + SetFont(w->RPort, RogueFont); + SetAPen(w->RPort, C_WHITE); /* XXX not sufficient */ + SetBPen(w->RPort, C_BLACK); + SetDrMd(w->RPort, JAM2); + } else { + if (HackFont) + SetFont(w->RPort, HackFont); + } + break; - /* The base window must exist until CleanUp() deletes it. */ - case NHW_BASE: - SetMenuStrip(w, MenuStrip); - /* Make our requesters come to our screen */ - { - register struct Process *myProcess = - (struct Process *) FindTask(NULL); - pr_WindowPtr = (struct Window *)(myProcess->pr_WindowPtr); - myProcess->pr_WindowPtr = (APTR) w; - } + /* The base window must exist until CleanUp() deletes it. */ + case NHW_BASE: + SetMenuStrip(w, MenuStrip); + /* Make our requesters come to our screen */ + { + register struct Process *myProcess = + (struct Process *) FindTask(NULL); + pr_WindowPtr = (struct Window *) (myProcess->pr_WindowPtr); + myProcess->pr_WindowPtr = (APTR) w; + } - /* Need this for RawKeyConvert() */ + /* Need this for RawKeyConvert() */ - ConsoleIO.io_Data = (APTR) w; - ConsoleIO.io_Length = sizeof( struct Window ); - ConsoleIO.io_Message.mn_ReplyPort = CreateMsgPort(); - if( OpenDevice("console.device", -1L, - (struct IORequest *) &ConsoleIO, 0L) != 0) - { - Abort(AG_OpenDev | AO_ConsoleDev); - } + ConsoleIO.io_Data = (APTR) w; + ConsoleIO.io_Length = sizeof(struct Window); + ConsoleIO.io_Message.mn_ReplyPort = CreateMsgPort(); + if (OpenDevice("console.device", -1L, (struct IORequest *) &ConsoleIO, + 0L) != 0) { + Abort(AG_OpenDev | AO_ConsoleDev); + } - ConsoleDevice = (struct Library *) ConsoleIO.io_Device; + ConsoleDevice = (struct Library *) ConsoleIO.io_Device; - KbdBuffered = 0; + KbdBuffered = 0; #ifdef HACKFONT - if( TextsFont ) - SetFont( w->RPort, TextsFont ); - else if( HackFont ) - SetFont( w->RPort, HackFont ); + if (TextsFont) + SetFont(w->RPort, TextsFont); + else if (HackFont) + SetFont(w->RPort, HackFont); #endif - txwidth = w->RPort->TxWidth; - txheight = w->RPort->TxHeight; - txbaseline = w->RPort->TxBaseline; - break; + txwidth = w->RPort->TxWidth; + txheight = w->RPort->TxHeight; + txbaseline = w->RPort->TxBaseline; + break; - default: - panic("bad create_nhwindow( %d )\n",type); - return WIN_ERR; + default: + panic("bad create_nhwindow( %d )\n", type); + return WIN_ERR; } - return( newid ); + return (newid); } #ifdef __GNUC__ #ifdef __PPC__ int PPC_SM_Filter(void); -struct EmulLibEntry SM_Filter = {TRAP_LIB, 0, (int (*)(void)) PPC_SM_Filter}; -int PPC_SM_Filter(void) { - struct Hook *hk = (struct Hook*)REG_A0; - ULONG modeID = (ULONG)REG_A1; - struct ScreenModeRequester *smr = (struct ScreenModeRequester *)REG_A2; +struct EmulLibEntry SM_Filter = { TRAP_LIB, 0, + (int (*)(void)) PPC_SM_Filter }; +int +PPC_SM_Filter(void) +{ + struct Hook *hk = (struct Hook *) REG_A0; + ULONG modeID = (ULONG) REG_A1; + struct ScreenModeRequester *smr = (struct ScreenModeRequester *) REG_A2; #else -int SM_Filter(void) { +int +SM_Filter(void) +{ register struct Hook *hk asm("a0"); register ULONG modeID asm("a1"); register struct ScreenModeRequester *smr asm("a2"); @@ -867,12 +822,11 @@ int SM_Filter(void) { #else int #ifndef _DCC -__interrupt + __interrupt #endif -__saveds __asm SM_Filter( - register __a0 struct Hook *hk, - register __a1 ULONG modeID, - register __a2 struct ScreenModeRequester *smr) + __saveds __asm SM_Filter( + register __a0 struct Hook *hk, register __a1 ULONG modeID, + register __a2 struct ScreenModeRequester *smr) { #endif struct DimensionInfo dims; @@ -880,14 +834,15 @@ __saveds __asm SM_Filter( DisplayInfoHandle handle; handle = FindDisplayInfo(modeID); if (handle) { - GetDisplayInfoData(handle, (char *)&dims, sizeof(dims), DTAG_DIMS, modeID); - GetDisplayInfoData(handle, (char *)&disp, sizeof(disp), DTAG_DISP, modeID); - if (!disp.NotAvailable && - dims.MaxDepth <= 8 && - dims.StdOScan.MaxX >= WIDTH-1 && - dims.StdOScan.MaxY >= SCREENHEIGHT-1) { - return 1; - } + GetDisplayInfoData(handle, (char *) &dims, sizeof(dims), DTAG_DIMS, + modeID); + GetDisplayInfoData(handle, (char *) &disp, sizeof(disp), DTAG_DISP, + modeID); + if (!disp.NotAvailable && dims.MaxDepth <= 8 + && dims.StdOScan.MaxX >= WIDTH - 1 + && dims.StdOScan.MaxY >= SCREENHEIGHT - 1) { + return 1; + } } return 0; } @@ -895,36 +850,36 @@ __saveds __asm SM_Filter( /* Initialize the windowing environment */ void -amii_init_nhwindows(argcp,argv) - int *argcp; - char **argv; +amii_init_nhwindows(argcp, argv) +int *argcp; +char **argv; { int i; struct Screen *wbscr; int forcenobig = 0; - if( HackScreen ) - panic( "init_nhwindows() called twice", 0 ); + if (HackScreen) + panic("init_nhwindows() called twice", 0); - /* run args & set bigscreen from -L(1)/-l(-1) */ + /* run args & set bigscreen from -L(1)/-l(-1) */ { - int lclargc = *argcp; - int t; - char **argv_in = argv; - char **argv_out = argv; + int lclargc = *argcp; + int t; + char **argv_in = argv; + char **argv_out = argv; - for(t=1;t<=lclargc;t++){ - if(!strcmp("-L",*argv_in) || !strcmp("-l",*argv_in)){ - bigscreen = (*argv_in[1]=='l') ? -1 : 1; - /* and eat the flag */ - (*argcp)--; - } else { - *argv_out = *argv_in; /* keep the flag */ - argv_out++; - } - argv_in++; - } - *argv_out = 0; + for (t = 1; t <= lclargc; t++) { + if (!strcmp("-L", *argv_in) || !strcmp("-l", *argv_in)) { + bigscreen = (*argv_in[1] == 'l') ? -1 : 1; + /* and eat the flag */ + (*argcp)--; + } else { + *argv_out = *argv_in; /* keep the flag */ + argv_out++; + } + argv_in++; + } + *argv_out = 0; } WIN_MESSAGE = WIN_ERR; @@ -934,95 +889,81 @@ amii_init_nhwindows(argcp,argv) WIN_BASE = WIN_ERR; WIN_OVER = WIN_ERR; - if ( (IntuitionBase = (struct IntuitionBase *) - OpenLibrary("intuition.library", amii_libvers )) == NULL) - { - Abort(AG_OpenLib | AO_Intuition); + if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary( + "intuition.library", amii_libvers)) == NULL) { + Abort(AG_OpenLib | AO_Intuition); } - if ( (GfxBase = (struct GfxBase *) - OpenLibrary("graphics.library", amii_libvers )) == NULL) - { - Abort(AG_OpenLib | AO_GraphicsLib); + if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", + amii_libvers)) == NULL) { + Abort(AG_OpenLib | AO_GraphicsLib); } - if( (LayersBase = (struct Library *) - OpenLibrary("layers.library", amii_libvers )) == NULL) - { - Abort(AG_OpenLib | AO_LayersLib); + if ((LayersBase = (struct Library *) OpenLibrary("layers.library", + amii_libvers)) == NULL) { + Abort(AG_OpenLib | AO_LayersLib); } - if ((GadToolsBase = OpenLibrary("gadtools.library", amii_libvers)) == NULL) { - Abort(AG_OpenLib | AO_GadTools); + if ((GadToolsBase = OpenLibrary("gadtools.library", amii_libvers)) + == NULL) { + Abort(AG_OpenLib | AO_GadTools); } if ((AslBase = OpenLibrary("asl.library", amii_libvers)) == NULL) { - Abort(AG_OpenLib); + Abort(AG_OpenLib); } - amiIDisplay=(struct amii_DisplayDesc *)alloc(sizeof(struct amii_DisplayDesc)); - memset( amiIDisplay, 0, sizeof( struct amii_DisplayDesc ) ); + amiIDisplay = + (struct amii_DisplayDesc *) alloc(sizeof(struct amii_DisplayDesc)); + memset(amiIDisplay, 0, sizeof(struct amii_DisplayDesc)); /* Use Intuition sizes for overscan screens... */ amiIDisplay->xpix = 0; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - if( wbscr = LockPubScreen( "Workbench" ) ) - { - amiIDisplay->xpix = wbscr->Width; - amiIDisplay->ypix = wbscr->Height; - UnlockPubScreen( NULL, wbscr ); - } +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + if (wbscr = LockPubScreen("Workbench")) { + amiIDisplay->xpix = wbscr->Width; + amiIDisplay->ypix = wbscr->Height; + UnlockPubScreen(NULL, wbscr); + } } #endif - if( amiIDisplay->xpix == 0 ) - { - amiIDisplay->ypix = GfxBase->NormalDisplayRows; - amiIDisplay->xpix = GfxBase->NormalDisplayColumns; + if (amiIDisplay->xpix == 0) { + amiIDisplay->ypix = GfxBase->NormalDisplayRows; + amiIDisplay->xpix = GfxBase->NormalDisplayColumns; } amiIDisplay->cols = amiIDisplay->xpix / FONTWIDTH; - amiIDisplay->toplin=0; - amiIDisplay->rawprint=0; - amiIDisplay->lastwin=0; + amiIDisplay->toplin = 0; + amiIDisplay->rawprint = 0; + amiIDisplay->lastwin = 0; - if( bigscreen == 0 ) - { - if( ( GfxBase->ActiView->ViewPort->Modes & LACE ) == LACE ) - { - amiIDisplay->ypix *= 2; - NewHackScreen.ViewModes |= LACE; - bigscreen = 1; - } - else if( GfxBase->NormalDisplayRows >= 300 || - amiIDisplay->ypix >= 300 ) - { - bigscreen = 1; - } - } - else if( bigscreen == -1 ) - { - bigscreen = 0; - forcenobig = 1; - } - else if( bigscreen ) - { - /* If bigscreen requested and we don't have enough rows in - * noninterlaced mode, switch to interlaced... - */ - if( GfxBase->NormalDisplayRows < 300 ) - { - amiIDisplay->ypix *= 2; - NewHackScreen.ViewModes |= LACE; - } + if (bigscreen == 0) { + if ((GfxBase->ActiView->ViewPort->Modes & LACE) == LACE) { + amiIDisplay->ypix *= 2; + NewHackScreen.ViewModes |= LACE; + bigscreen = 1; + } else if (GfxBase->NormalDisplayRows >= 300 + || amiIDisplay->ypix >= 300) { + bigscreen = 1; + } + } else if (bigscreen == -1) { + bigscreen = 0; + forcenobig = 1; + } else if (bigscreen) { + /* If bigscreen requested and we don't have enough rows in + * noninterlaced mode, switch to interlaced... + */ + if (GfxBase->NormalDisplayRows < 300) { + amiIDisplay->ypix *= 2; + NewHackScreen.ViewModes |= LACE; + } } - if( !bigscreen ) - { - alwaysinvent = 0; + if (!bigscreen) { + alwaysinvent = 0; } amiIDisplay->rows = amiIDisplay->ypix / FONTHEIGHT; @@ -1031,268 +972,258 @@ amii_init_nhwindows(argcp,argv) * Load the fonts that we need. */ - if( DiskfontBase = - OpenLibrary( "diskfont.library", amii_libvers ) ) - { - Hack80.ta_Name -= SIZEOF_DISKNAME; - HackFont = OpenDiskFont( &Hack80 ); - Hack80.ta_Name += SIZEOF_DISKNAME; + if (DiskfontBase = OpenLibrary("diskfont.library", amii_libvers)) { + Hack80.ta_Name -= SIZEOF_DISKNAME; + HackFont = OpenDiskFont(&Hack80); + Hack80.ta_Name += SIZEOF_DISKNAME; - /* Textsfont13 is filled in with "FONT=" settings. The default is - * courier/13. - */ - TextsFont = NULL; - if( bigscreen ) - TextsFont = OpenDiskFont( &TextsFont13 ); + /* Textsfont13 is filled in with "FONT=" settings. The default is + * courier/13. + */ + TextsFont = NULL; + if (bigscreen) + TextsFont = OpenDiskFont(&TextsFont13); - /* Try hack/8 for texts if no user specified font */ - if( TextsFont == NULL ) - { - Hack80.ta_Name -= SIZEOF_DISKNAME; - TextsFont = OpenDiskFont( &Hack80 ); - Hack80.ta_Name += SIZEOF_DISKNAME; - } + /* Try hack/8 for texts if no user specified font */ + if (TextsFont == NULL) { + Hack80.ta_Name -= SIZEOF_DISKNAME; + TextsFont = OpenDiskFont(&Hack80); + Hack80.ta_Name += SIZEOF_DISKNAME; + } - /* If no fonts, make everything topaz 8 for non-view windows. - */ - Hack80.ta_Name = "topaz.font"; - RogueFont = OpenFont( &Hack80 ); - if(!RogueFont) panic("Can't get topaz:8"); - if( !HackFont || !TextsFont ) - { - if( !HackFont ) - { - HackFont = OpenFont( &Hack80 ); - if( !HackFont ) - panic( "Can't get a map font, topaz:8" ); - } + /* If no fonts, make everything topaz 8 for non-view windows. + */ + Hack80.ta_Name = "topaz.font"; + RogueFont = OpenFont(&Hack80); + if (!RogueFont) + panic("Can't get topaz:8"); + if (!HackFont || !TextsFont) { + if (!HackFont) { + HackFont = OpenFont(&Hack80); + if (!HackFont) + panic("Can't get a map font, topaz:8"); + } - if( !TextsFont ) - { - TextsFont = OpenFont( &Hack80 ); - if( !TextsFont ) - panic( "Can't open text font" ); - } - } - CloseLibrary(DiskfontBase); - DiskfontBase = NULL; + if (!TextsFont) { + TextsFont = OpenFont(&Hack80); + if (!TextsFont) + panic("Can't open text font"); + } + } + CloseLibrary(DiskfontBase); + DiskfontBase = NULL; } #endif /* Adjust getlin window size to font */ if (TextsFont) { - extern SHORT BorderVectors1[]; - extern SHORT BorderVectors2[]; - extern struct Gadget Gadget2; - extern struct Gadget String; - extern struct NewWindow StrWindow; - BorderVectors1[2] += (TextsFont->tf_XSize-8)*6; /* strlen("Cancel") == 6 */ - BorderVectors1[4] += (TextsFont->tf_XSize-8)*6; - BorderVectors1[5] += TextsFont->tf_YSize-8; - BorderVectors1[7] += TextsFont->tf_YSize-8; - BorderVectors2[2] += (TextsFont->tf_XSize-8)*6; - BorderVectors2[4] += (TextsFont->tf_XSize-8)*6; - BorderVectors2[5] += TextsFont->tf_YSize-8; - BorderVectors2[7] += TextsFont->tf_YSize-8; - Gadget2.TopEdge += TextsFont->tf_YSize-8; - Gadget2.Width += (TextsFont->tf_XSize-8)*6; - Gadget2.Height += TextsFont->tf_YSize-8; - String.LeftEdge += (TextsFont->tf_XSize-8)*6; - String.TopEdge += TextsFont->tf_YSize-8; - String.Width += TextsFont->tf_XSize-8; - String.Height += TextsFont->tf_YSize-8; - StrWindow.Width += (TextsFont->tf_XSize-8)*7; - StrWindow.Height += (TextsFont->tf_YSize-8)*2; /* Titlebar + 1 row of gadgets */ + extern SHORT BorderVectors1[]; + extern SHORT BorderVectors2[]; + extern struct Gadget Gadget2; + extern struct Gadget String; + extern struct NewWindow StrWindow; + BorderVectors1[2] += + (TextsFont->tf_XSize - 8) * 6; /* strlen("Cancel") == 6 */ + BorderVectors1[4] += (TextsFont->tf_XSize - 8) * 6; + BorderVectors1[5] += TextsFont->tf_YSize - 8; + BorderVectors1[7] += TextsFont->tf_YSize - 8; + BorderVectors2[2] += (TextsFont->tf_XSize - 8) * 6; + BorderVectors2[4] += (TextsFont->tf_XSize - 8) * 6; + BorderVectors2[5] += TextsFont->tf_YSize - 8; + BorderVectors2[7] += TextsFont->tf_YSize - 8; + Gadget2.TopEdge += TextsFont->tf_YSize - 8; + Gadget2.Width += (TextsFont->tf_XSize - 8) * 6; + Gadget2.Height += TextsFont->tf_YSize - 8; + String.LeftEdge += (TextsFont->tf_XSize - 8) * 6; + String.TopEdge += TextsFont->tf_YSize - 8; + String.Width += TextsFont->tf_XSize - 8; + String.Height += TextsFont->tf_YSize - 8; + StrWindow.Width += (TextsFont->tf_XSize - 8) * 7; + StrWindow.Height += + (TextsFont->tf_YSize - 8) * 2; /* Titlebar + 1 row of gadgets */ } /* This is the size screen we want to open, within reason... */ - NewHackScreen.Width = max( WIDTH, amiIDisplay->xpix ); - NewHackScreen.Height = max( SCREENHEIGHT, amiIDisplay->ypix ); + NewHackScreen.Width = max(WIDTH, amiIDisplay->xpix); + NewHackScreen.Height = max(SCREENHEIGHT, amiIDisplay->ypix); { - static char fname[18]; - sprintf(fname,"NetHack %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); - NewHackScreen.DefaultTitle=fname; + static char fname[18]; + sprintf(fname, "NetHack %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, + PATCHLEVEL); + NewHackScreen.DefaultTitle = fname; } #if 0 NewHackScreen.BlockPen = C_BLACK; NewHackScreen.DetailPen = C_WHITE; #endif -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - int i; - struct DimensionInfo dims; - DisplayInfoHandle handle; - struct DisplayInfo disp; - ULONG modeid = DEFAULT_MONITOR_ID|HIRES_KEY; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + int i; + struct DimensionInfo dims; + DisplayInfoHandle handle; + struct DisplayInfo disp; + ULONG modeid = DEFAULT_MONITOR_ID | HIRES_KEY; - NewHackScreen.Width = STDSCREENWIDTH; - NewHackScreen.Height = STDSCREENHEIGHT; + NewHackScreen.Width = STDSCREENWIDTH; + NewHackScreen.Height = STDSCREENHEIGHT; #ifdef HACKFONT - if (TextsFont) { - NewHackScreen.Font = &TextsFont13; - } + if (TextsFont) { + NewHackScreen.Font = &TextsFont13; + } #endif - if ( amii_scrnmode == 0xffffffff ) { - struct ScreenModeRequester *SMR; + if (amii_scrnmode == 0xffffffff) { + struct ScreenModeRequester *SMR; #ifdef __GNUC__ - SM_FilterHook.h_Entry = (void *)&SM_Filter; + SM_FilterHook.h_Entry = (void *) &SM_Filter; #else - SM_FilterHook.h_Entry = (ULONG(*)())SM_Filter; + SM_FilterHook.h_Entry = (ULONG (*) ()) SM_Filter; #endif - SM_FilterHook.h_Data = 0; - SM_FilterHook.h_SubEntry = 0; - SMR = AllocAslRequest(ASL_ScreenModeRequest,NULL); - if (AslRequestTags(SMR, - ASLSM_FilterFunc, (ULONG)&SM_FilterHook, - TAG_END)) - amii_scrnmode = SMR->sm_DisplayID; - else - amii_scrnmode = 0; - FreeAslRequest(SMR); - } + SM_FilterHook.h_Data = 0; + SM_FilterHook.h_SubEntry = 0; + SMR = AllocAslRequest(ASL_ScreenModeRequest, NULL); + if (AslRequestTags(SMR, ASLSM_FilterFunc, (ULONG) &SM_FilterHook, + TAG_END)) + amii_scrnmode = SMR->sm_DisplayID; + else + amii_scrnmode = 0; + FreeAslRequest(SMR); + } - if( forcenobig == 0 ) - { - if( ( wbscr = LockPubScreen( "Workbench" ) ) != NULL || - ( wbscr = LockPubScreen( NULL ) ) != NULL ) - { - /* Get the default pub screen's size */ - modeid = GetVPModeID( &wbscr->ViewPort ); - if( modeid == INVALID_ID || - ModeNotAvailable( modeid ) || - ( handle = FindDisplayInfo( modeid ) ) == NULL || - GetDisplayInfoData( handle, (char *)&dims, sizeof( dims ), - DTAG_DIMS, modeid ) <= 0 || - GetDisplayInfoData( handle, (char *)&disp, sizeof( disp ), - DTAG_DISP, modeid ) <= 0 ) - { - modeid = DEFAULT_MONITOR_ID|HIRES_KEY; - /* If the display database seems to not work, use the screen - * dimensions - */ - NewHackScreen.Height = wbscr->Height; - NewHackScreen.Width = wbscr->Width; - - /* - * Request LACE if it looks laced. For 2.1/3.0, we will get - * promoted to the users choice of modes (if promotion is allowed) - * If the user is using a dragable screen, things will get hosed - * but that is life... - */ - if( wbscr->ViewPort.Modes & LACE ) - NewHackScreen.ViewModes |= LACE; - modeid = -1; - } - else - { - /* Use the display database to get the correct information */ - if( disp.PropertyFlags & DIPF_IS_LACE ) - NewHackScreen.ViewModes |= LACE; - NewHackScreen.Height = dims.StdOScan.MaxY+1; - NewHackScreen.Width = dims.StdOScan.MaxX+1; - } - NewHackScreen.TopEdge = 0; - NewHackScreen.LeftEdge = 0; + if (forcenobig == 0) { + if ((wbscr = LockPubScreen("Workbench")) != NULL + || (wbscr = LockPubScreen(NULL)) != NULL) { + /* Get the default pub screen's size */ + modeid = GetVPModeID(&wbscr->ViewPort); + if (modeid == INVALID_ID || ModeNotAvailable(modeid) + || (handle = FindDisplayInfo(modeid)) == NULL + || GetDisplayInfoData(handle, (char *) &dims, + sizeof(dims), DTAG_DIMS, + modeid) <= 0 + || GetDisplayInfoData(handle, (char *) &disp, + sizeof(disp), DTAG_DISP, + modeid) <= 0) { + modeid = DEFAULT_MONITOR_ID | HIRES_KEY; + /* If the display database seems to not work, use the + * screen + * dimensions + */ + NewHackScreen.Height = wbscr->Height; + NewHackScreen.Width = wbscr->Width; - UnlockPubScreen( NULL, wbscr ); - } - } + /* + * Request LACE if it looks laced. For 2.1/3.0, we will + * get + * promoted to the users choice of modes (if promotion is + * allowed) + * If the user is using a dragable screen, things will get + * hosed + * but that is life... + */ + if (wbscr->ViewPort.Modes & LACE) + NewHackScreen.ViewModes |= LACE; + modeid = -1; + } else { + /* Use the display database to get the correct information + */ + if (disp.PropertyFlags & DIPF_IS_LACE) + NewHackScreen.ViewModes |= LACE; + NewHackScreen.Height = dims.StdOScan.MaxY + 1; + NewHackScreen.Width = dims.StdOScan.MaxX + 1; + } + NewHackScreen.TopEdge = 0; + NewHackScreen.LeftEdge = 0; - for( i = 0; scrntags[i].ti_Tag != TAG_DONE; ++i ) - { - switch( scrntags[i].ti_Tag ) - { - case SA_DisplayID: - if( !amii_scrnmode || ModeNotAvailable( amii_scrnmode ) ) - { - if( ModeNotAvailable( modeid ) ) - { - scrntags[i].ti_Tag = TAG_IGNORE; - break; - } - else - scrntags[i].ti_Data = (long)modeid; - } - else - modeid = scrntags[i].ti_Data = (long)amii_scrnmode; - if( ( handle = FindDisplayInfo( modeid ) ) != NULL && - GetDisplayInfoData( handle, (char *)&dims, sizeof( dims ), - DTAG_DIMS, modeid ) > 0 && - GetDisplayInfoData( handle, (char *)&disp, sizeof( disp ), - DTAG_DISP, modeid ) > 0 ) - { - if( disp.PropertyFlags & DIPF_IS_LACE ) - NewHackScreen.ViewModes |= LACE; - NewHackScreen.Height = dims.StdOScan.MaxY+1; - NewHackScreen.Width = dims.StdOScan.MaxX+1; - } - break; + UnlockPubScreen(NULL, wbscr); + } + } - case SA_Pens: - scrntags[i].ti_Data = (long)sysflags.amii_dripens; - break; - } - } + for (i = 0; scrntags[i].ti_Tag != TAG_DONE; ++i) { + switch (scrntags[i].ti_Tag) { + case SA_DisplayID: + if (!amii_scrnmode || ModeNotAvailable(amii_scrnmode)) { + if (ModeNotAvailable(modeid)) { + scrntags[i].ti_Tag = TAG_IGNORE; + break; + } else + scrntags[i].ti_Data = (long) modeid; + } else + modeid = scrntags[i].ti_Data = (long) amii_scrnmode; + if ((handle = FindDisplayInfo(modeid)) != NULL + && GetDisplayInfoData(handle, (char *) &dims, + sizeof(dims), DTAG_DIMS, modeid) > 0 + && GetDisplayInfoData(handle, (char *) &disp, + sizeof(disp), DTAG_DISP, + modeid) > 0) { + if (disp.PropertyFlags & DIPF_IS_LACE) + NewHackScreen.ViewModes |= LACE; + NewHackScreen.Height = dims.StdOScan.MaxY + 1; + NewHackScreen.Width = dims.StdOScan.MaxX + 1; + } + break; + + case SA_Pens: + scrntags[i].ti_Data = (long) sysflags.amii_dripens; + break; + } + } } #endif - if( WINVERS_AMIV ) - amii_bmhd = ReadTileImageFiles( ); + if (WINVERS_AMIV) + amii_bmhd = ReadTileImageFiles(); else - memcpy( amii_initmap, amii_init_map, sizeof( amii_initmap ) ); - memcpy(sysflags.amii_curmap,amii_initmap,sizeof(sysflags.amii_curmap)); + memcpy(amii_initmap, amii_init_map, sizeof(amii_initmap)); + memcpy(sysflags.amii_curmap, amii_initmap, sizeof(sysflags.amii_curmap)); /* Find out how deep the screen needs to be, 32 planes is enough! */ - for( i = 0; i < 32; ++i ) - { - if( ( 1L << i ) >= amii_numcolors ) - break; + for (i = 0; i < 32; ++i) { + if ((1L << i) >= amii_numcolors) + break; } NewHackScreen.Depth = i; /* If for some reason Height/Width became smaller than the required, - have the required one */ + have the required one */ if (NewHackScreen.Height < SCREENHEIGHT) - NewHackScreen.Height = SCREENHEIGHT; + NewHackScreen.Height = SCREENHEIGHT; if (NewHackScreen.Width < WIDTH) - NewHackScreen.Width = WIDTH; + NewHackScreen.Width = WIDTH; #ifdef HACKFONT i = max(TextsFont->tf_XSize, HackFont->tf_XSize); - if (NewHackScreen.Width < 80*i+4) - NewHackScreen.Width = 80*i+4; + if (NewHackScreen.Width < 80 * i + 4) + NewHackScreen.Width = 80 * i + 4; #endif - /* While openscreen fails try fewer colors to see if that is the problem. */ - while( ( HackScreen = OpenScreen( (void *)&NewHackScreen ) ) == NULL ) - { -#ifdef TEXTCOLOR - if( --NewHackScreen.Depth < 3 ) + /* While openscreen fails try fewer colors to see if that is the problem. + */ + while ((HackScreen = OpenScreen((void *) &NewHackScreen)) == NULL) { +#ifdef TEXTCOLOR + if (--NewHackScreen.Depth < 3) #else - if( --NewHackScreen.Depth < 2 ) + if (--NewHackScreen.Depth < 2) #endif - Abort( AN_OpenScreen & ~AT_DeadEnd ); + Abort(AN_OpenScreen & ~AT_DeadEnd); } amii_numcolors = 1L << NewHackScreen.Depth; - if( HackScreen->Height > 300 && forcenobig == 0 ) - bigscreen = 1; + if (HackScreen->Height > 300 && forcenobig == 0) + bigscreen = 1; else - bigscreen = 0; + bigscreen = 0; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - PubScreenStatus( HackScreen, 0 ); +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) + PubScreenStatus(HackScreen, 0); #endif amiIDisplay->ypix = HackScreen->Height; amiIDisplay->xpix = HackScreen->Width; - LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors ); + LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors); VisualInfo = GetVisualInfo(HackScreen, TAG_END); MenuStrip = CreateMenus(GTHackMenu, TAG_END); @@ -1300,118 +1231,115 @@ amii_init_nhwindows(argcp,argv) /* Display the copyright etc... */ - if( WIN_BASE == WIN_ERR ) - WIN_BASE = amii_create_nhwindow( NHW_BASE ); - amii_clear_nhwindow( WIN_BASE ); - amii_putstr( WIN_BASE, 0, "" ); - amii_putstr( WIN_BASE, 0, "" ); - amii_putstr( WIN_BASE, 0, "" ); - amii_putstr( WIN_BASE, 0, COPYRIGHT_BANNER_A); - amii_putstr( WIN_BASE, 0, COPYRIGHT_BANNER_B); - amii_putstr( WIN_BASE, 0, COPYRIGHT_BANNER_C); - amii_putstr( WIN_BASE, 0, COPYRIGHT_BANNER_D); - amii_putstr( WIN_BASE, 0, ""); + if (WIN_BASE == WIN_ERR) + WIN_BASE = amii_create_nhwindow(NHW_BASE); + amii_clear_nhwindow(WIN_BASE); + amii_putstr(WIN_BASE, 0, ""); + amii_putstr(WIN_BASE, 0, ""); + amii_putstr(WIN_BASE, 0, ""); + amii_putstr(WIN_BASE, 0, COPYRIGHT_BANNER_A); + amii_putstr(WIN_BASE, 0, COPYRIGHT_BANNER_B); + amii_putstr(WIN_BASE, 0, COPYRIGHT_BANNER_C); + amii_putstr(WIN_BASE, 0, COPYRIGHT_BANNER_D); + amii_putstr(WIN_BASE, 0, ""); Initialized = 1; } void -amii_sethipens( struct Window *w, int type, int attr ) +amii_sethipens(struct Window *w, int type, int attr) { - switch( type ) - { - default: - SetAPen( w->RPort, attr ? C_RED : amii_otherAPen ); - SetBPen( w->RPort, C_BLACK ); - break; - case NHW_STATUS: - SetAPen( w->RPort, attr ? C_WHITE : amii_statAPen ); - SetBPen( w->RPort, amii_statBPen ); - break; - case NHW_MESSAGE: - SetAPen( w->RPort, attr ? C_WHITE : amii_msgAPen ); - SetBPen( w->RPort, amii_msgBPen ); - break; - case NHW_MENU: - SetAPen( w->RPort, attr ? C_BLACK : amii_menuAPen ); - SetBPen( w->RPort, amii_menuBPen ); - break; - case NHW_TEXT: - SetAPen( w->RPort, attr ? C_BLACK : amii_textAPen ); - SetBPen( w->RPort, amii_textBPen ); - case -2: - SetBPen( w->RPort, amii_otherBPen ); - SetAPen( w->RPort, attr ? C_RED : amii_otherAPen ); - break; - } -} - -void -amii_setfillpens( struct Window *w, int type ) -{ - switch( type ) - { - case NHW_MESSAGE: - SetAPen( w->RPort, amii_msgBPen ); - SetBPen( w->RPort, amii_msgBPen ); - break; - case NHW_STATUS: - SetAPen( w->RPort, amii_statBPen ); - SetBPen( w->RPort, amii_statBPen ); - break; - case NHW_MENU: - SetAPen( w->RPort, amii_menuBPen ); - SetBPen( w->RPort, amii_menuBPen ); - break; - case NHW_TEXT: - SetAPen( w->RPort, amii_textBPen ); - SetBPen( w->RPort, amii_textBPen ); - break; - case NHW_MAP: - case NHW_BASE: - case NHW_OVER: + switch (type) { default: - SetAPen( w->RPort, C_BLACK ); - SetBPen( w->RPort, C_BLACK ); - break; + SetAPen(w->RPort, attr ? C_RED : amii_otherAPen); + SetBPen(w->RPort, C_BLACK); + break; + case NHW_STATUS: + SetAPen(w->RPort, attr ? C_WHITE : amii_statAPen); + SetBPen(w->RPort, amii_statBPen); + break; + case NHW_MESSAGE: + SetAPen(w->RPort, attr ? C_WHITE : amii_msgAPen); + SetBPen(w->RPort, amii_msgBPen); + break; + case NHW_MENU: + SetAPen(w->RPort, attr ? C_BLACK : amii_menuAPen); + SetBPen(w->RPort, amii_menuBPen); + break; + case NHW_TEXT: + SetAPen(w->RPort, attr ? C_BLACK : amii_textAPen); + SetBPen(w->RPort, amii_textBPen); case -2: - SetAPen( w->RPort, amii_otherBPen ); - SetBPen( w->RPort, amii_otherBPen ); - break; + SetBPen(w->RPort, amii_otherBPen); + SetAPen(w->RPort, attr ? C_RED : amii_otherAPen); + break; } } void -amii_setdrawpens( struct Window *w, int type ) +amii_setfillpens(struct Window *w, int type) { - switch( type ) - { + switch (type) { case NHW_MESSAGE: - SetAPen( w->RPort, amii_msgAPen ); - SetBPen( w->RPort, amii_msgBPen ); - break; + SetAPen(w->RPort, amii_msgBPen); + SetBPen(w->RPort, amii_msgBPen); + break; case NHW_STATUS: - SetAPen( w->RPort, amii_statAPen ); - SetBPen( w->RPort, amii_statBPen ); - break; + SetAPen(w->RPort, amii_statBPen); + SetBPen(w->RPort, amii_statBPen); + break; case NHW_MENU: - SetAPen( w->RPort, amii_menuAPen ); - SetBPen( w->RPort, amii_menuBPen ); - break; + SetAPen(w->RPort, amii_menuBPen); + SetBPen(w->RPort, amii_menuBPen); + break; case NHW_TEXT: - SetAPen( w->RPort, amii_textAPen ); - SetBPen( w->RPort, amii_textBPen ); - break; + SetAPen(w->RPort, amii_textBPen); + SetBPen(w->RPort, amii_textBPen); + break; case NHW_MAP: case NHW_BASE: case NHW_OVER: - SetAPen( w->RPort, C_WHITE ); - SetBPen( w->RPort, C_BLACK ); - break; default: - SetAPen( w->RPort, amii_otherAPen ); - SetBPen( w->RPort, amii_otherBPen ); - break; + SetAPen(w->RPort, C_BLACK); + SetBPen(w->RPort, C_BLACK); + break; + case -2: + SetAPen(w->RPort, amii_otherBPen); + SetBPen(w->RPort, amii_otherBPen); + break; + } +} + +void +amii_setdrawpens(struct Window *w, int type) +{ + switch (type) { + case NHW_MESSAGE: + SetAPen(w->RPort, amii_msgAPen); + SetBPen(w->RPort, amii_msgBPen); + break; + case NHW_STATUS: + SetAPen(w->RPort, amii_statAPen); + SetBPen(w->RPort, amii_statBPen); + break; + case NHW_MENU: + SetAPen(w->RPort, amii_menuAPen); + SetBPen(w->RPort, amii_menuBPen); + break; + case NHW_TEXT: + SetAPen(w->RPort, amii_textAPen); + SetBPen(w->RPort, amii_textBPen); + break; + case NHW_MAP: + case NHW_BASE: + case NHW_OVER: + SetAPen(w->RPort, C_WHITE); + SetBPen(w->RPort, C_BLACK); + break; + default: + SetAPen(w->RPort, amii_otherAPen); + SetBPen(w->RPort, amii_otherBPen); + break; } } @@ -1419,429 +1347,392 @@ amii_setdrawpens( struct Window *w, int type ) void amii_clear_nhwindow(win) - register winid win; +register winid win; { register struct amii_WinDesc *cw; register struct Window *w; - if( reclip == 2 ) return; + if (reclip == 2) + return; - if( win == WIN_ERR || ( cw = amii_wins[win] ) == NULL ) - panic( winpanicstr, win, "clear_nhwindow" ); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL) + panic(winpanicstr, win, "clear_nhwindow"); /* Clear the overview window too if it is displayed */ - if( WINVERS_AMIV && ( cw->type == WIN_MAP && WIN_OVER != WIN_ERR && reclip == 0 ) ) - { - amii_clear_nhwindow( WIN_OVER ); + if (WINVERS_AMIV + && (cw->type == WIN_MAP && WIN_OVER != WIN_ERR && reclip == 0)) { + amii_clear_nhwindow(WIN_OVER); } - if( w = cw->win ) - SetDrMd( w->RPort, JAM2); + if (w = cw->win) + SetDrMd(w->RPort, JAM2); else return; - if( (cw->wflags & FLMAP_CURSUP ) ) - { - if( cw->type != NHW_MAP ) - cursor_off( win ); - else - cw->wflags &= ~FLMAP_CURSUP; + if ((cw->wflags & FLMAP_CURSUP)) { + if (cw->type != NHW_MAP) + cursor_off(win); + else + cw->wflags &= ~FLMAP_CURSUP; } - amii_setfillpens( w, cw->type ); - SetDrMd( w->RPort, JAM2 ); + amii_setfillpens(w, cw->type); + SetDrMd(w->RPort, JAM2); - if( cw->type == NHW_MENU || cw->type == NHW_TEXT ) - { - RectFill( w->RPort, w->BorderLeft, w->BorderTop, - w->Width - w->BorderRight-1, - w->Height - w->BorderBottom-1 ); - } - else - { - if( cw->type == NHW_MESSAGE ) - { - amii_curs( win, 1, 0 ); - if( !scrollmsg ) - TextSpaces( w->RPort, cw->cols ); - } - else - { - RectFill( w->RPort, w->BorderLeft, w->BorderTop, - w->Width - w->BorderRight-1, - w->Height - w->BorderBottom-1 ); - } + if (cw->type == NHW_MENU || cw->type == NHW_TEXT) { + RectFill(w->RPort, w->BorderLeft, w->BorderTop, + w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); + } else { + if (cw->type == NHW_MESSAGE) { + amii_curs(win, 1, 0); + if (!scrollmsg) + TextSpaces(w->RPort, cw->cols); + } else { + RectFill(w->RPort, w->BorderLeft, w->BorderTop, + w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); + } } cw->cury = 0; cw->curx = 0; - amii_curs( win, 1, 0 ); + amii_curs(win, 1, 0); } /* Dismiss the window from the screen */ void dismiss_nhwindow(win) - register winid win; +register winid win; { register struct Window *w; register struct amii_WinDesc *cw; - if( win == WIN_ERR || ( cw = amii_wins[win] ) == NULL ) - { - panic(winpanicstr,win, "dismiss_nhwindow"); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL) { + panic(winpanicstr, win, "dismiss_nhwindow"); } w = cw->win; - if( w ) - { - /* All windows have this stuff attached to them. */ - if( cw->type == NHW_MAP || - cw->type == NHW_OVER || - cw->type == NHW_BASE || - cw->type == NHW_MESSAGE || - cw->type == NHW_STATUS ) - { - ClearMenuStrip( w ); - } + if (w) { + /* All windows have this stuff attached to them. */ + if (cw->type == NHW_MAP || cw->type == NHW_OVER + || cw->type == NHW_BASE || cw->type == NHW_MESSAGE + || cw->type == NHW_STATUS) { + ClearMenuStrip(w); + } - /* Save where user like inventory to appear */ - if( win == WIN_INVEN ) - { - lastinvent.MinX = w->LeftEdge; - lastinvent.MinY = w->TopEdge; - lastinvent.MaxX = w->Width; - lastinvent.MaxY = w->Height; - } + /* Save where user like inventory to appear */ + if (win == WIN_INVEN) { + lastinvent.MinX = w->LeftEdge; + lastinvent.MinY = w->TopEdge; + lastinvent.MaxX = w->Width; + lastinvent.MaxY = w->Height; + } - /* Close the window */ - CloseShWindow( w ); - cw->win = NULL; + /* Close the window */ + CloseShWindow(w); + cw->win = NULL; - /* Free copy of NewWindow structure for TEXT/MENU windows. */ - if( cw->newwin ) - FreeNewWindow( (void *)cw->newwin ); - cw->newwin = NULL; + /* Free copy of NewWindow structure for TEXT/MENU windows. */ + if (cw->newwin) + FreeNewWindow((void *) cw->newwin); + cw->newwin = NULL; } } void amii_exit_nhwindows(str) - const char *str; +const char *str; { /* Seems strange to have to do this... but we need the BASE window * left behind... */ - kill_nhwindows( 0 ); - if( WINVERS_AMIV ) - FreeTileImageFiles( ); + kill_nhwindows(0); + if (WINVERS_AMIV) + FreeTileImageFiles(); - if( str ) - { - raw_print( "" ); /* be sure we're not under the top margin */ - raw_print( str ); + if (str) { + raw_print(""); /* be sure we're not under the top margin */ + raw_print(str); } } void -amii_display_nhwindow(win,blocking) - winid win; - boolean blocking; +amii_display_nhwindow(win, blocking) +winid win; +boolean blocking; { menu_item *mip; int cnt; static int lastwin = -1; struct amii_WinDesc *cw; - if( !Initialized ) - return; + if (!Initialized) + return; lastwin = win; - if( win == WIN_ERR || ( cw = amii_wins[win] ) == NULL ) - panic(winpanicstr,win,"display_nhwindow"); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL) + panic(winpanicstr, win, "display_nhwindow"); - if( cw->type == NHW_MESSAGE ) - cw->wflags &= ~FLMAP_SKIP; + if (cw->type == NHW_MESSAGE) + cw->wflags &= ~FLMAP_SKIP; - if( cw->type == NHW_MESSAGE || cw->type == NHW_STATUS ) - return; + if (cw->type == NHW_MESSAGE || cw->type == NHW_STATUS) + return; - if( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) - { - flush_glyph_buffer( amii_wins[ WIN_MAP ]->win ); + if (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP]) { + flush_glyph_buffer(amii_wins[WIN_MAP]->win); } - if( cw->type == NHW_MENU || cw->type == NHW_TEXT ) - { - cnt = DoMenuScroll( win, blocking, PICK_ONE, &mip ); - } - else if( cw->type==NHW_MAP ) - { - amii_end_glyphout( win ); - /* Do more if it is time... */ - if( blocking == TRUE && amii_wins[ WIN_MESSAGE ]->curx ) - { - outmore( amii_wins[ WIN_MESSAGE ] ); - } + if (cw->type == NHW_MENU || cw->type == NHW_TEXT) { + cnt = DoMenuScroll(win, blocking, PICK_ONE, &mip); + } else if (cw->type == NHW_MAP) { + amii_end_glyphout(win); + /* Do more if it is time... */ + if (blocking == TRUE && amii_wins[WIN_MESSAGE]->curx) { + outmore(amii_wins[WIN_MESSAGE]); + } } } void amii_curs(window, x, y) winid window; -register int x, y; /* not xchar: perhaps xchar is unsigned and - curx-x would be unsigned as well */ +register int x, y; /* not xchar: perhaps xchar is unsigned and + curx-x would be unsigned as well */ { register struct amii_WinDesc *cw; register struct Window *w; register struct RastPort *rp; - if( window == WIN_ERR || ( cw = amii_wins[window] ) == NULL ) - panic(winpanicstr, window, "curs"); - if( (w = cw->win) == NULL ) - { - if( cw->type == NHW_MENU || cw->type == NHW_TEXT ) - return; - else - panic( "No window open yet in curs() for winid %d\n", window ); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL) + panic(winpanicstr, window, "curs"); + if ((w = cw->win) == NULL) { + if (cw->type == NHW_MENU || cw->type == NHW_TEXT) + return; + else + panic("No window open yet in curs() for winid %d\n", window); } amiIDisplay->lastwin = window; /* Make sure x is within bounds */ - if( x > 0 ) - --x; /* column 0 is never used */ + if (x > 0) + --x; /* column 0 is never used */ else - x = 0; + x = 0; cw->curx = x; cw->cury = y; #ifdef DEBUG - if( x<0 || y<0 || y >= cw->rows || x >= cw->cols ) - { - char *s = "[unknown type]"; - switch(cw->type) - { - case NHW_MESSAGE: s = "[topl window]"; break; - case NHW_STATUS: s = "[status window]"; break; - case NHW_MAP: s = "[map window]"; break; - case NHW_MENU: s = "[menu window]"; break; - case NHW_TEXT: s = "[text window]"; break; - case NHW_BASE: s = "[base window]"; break; - case NHW_OVER: s = "[overview window]"; break; - } - impossible("bad curs positioning win %d %s (%d,%d)", window, s, x, y); - return; + if (x < 0 || y < 0 || y >= cw->rows || x >= cw->cols) { + char *s = "[unknown type]"; + switch (cw->type) { + case NHW_MESSAGE: + s = "[topl window]"; + break; + case NHW_STATUS: + s = "[status window]"; + break; + case NHW_MAP: + s = "[map window]"; + break; + case NHW_MENU: + s = "[menu window]"; + break; + case NHW_TEXT: + s = "[text window]"; + break; + case NHW_BASE: + s = "[base window]"; + break; + case NHW_OVER: + s = "[overview window]"; + break; + } + impossible("bad curs positioning win %d %s (%d,%d)", window, s, x, y); + return; } #endif #ifdef CLIPPING - if(clipping && cw->type == NHW_MAP) - { - x -= clipx; - y -= clipy; + if (clipping && cw->type == NHW_MAP) { + x -= clipx; + y -= clipy; } #endif /* Output all saved output before doing cursor movements for MAP */ - if( cw->type == NHW_MAP ) - { - flush_glyph_buffer( w ); + if (cw->type == NHW_MAP) { + flush_glyph_buffer(w); } /* Actually do it */ rp = w->RPort; - if( cw->type == NHW_MENU ) - { - if( WINVERS_AMIV ) - { - if( window == WIN_INVEN ) - { - Move( rp, (x * rp->TxWidth) + w->BorderLeft + 1 + pictdata.xsize + 4, - (y * max(rp->TxHeight,pictdata.ysize + 3) ) + - rp->TxBaseline + pictdata.ysize - rp->TxHeight + w->BorderTop + 4 ); - } - else - { - Move( rp, (x * rp->TxWidth) + w->BorderLeft + 1, - (y * rp->TxHeight) + rp->TxBaseline + w->BorderTop + 1 ); - } - } - else - { - Move( rp, (x * rp->TxWidth) + w->BorderLeft + 1, - (y*rp->TxHeight ) + rp->TxBaseline + w->BorderTop + 1 ); - } - } - else if( cw->type == NHW_TEXT ) - { - Move( rp, (x * rp->TxWidth) + w->BorderLeft + 1, - (y*rp->TxHeight ) + rp->TxBaseline + w->BorderTop + 1 ); - } - else if( cw->type == NHW_MAP || cw->type == NHW_BASE ) - { - /* These coordinate calculations must be synced with those - * in flush_glyph_buffer() in winchar.c. curs_on_u() will - * use this code, all other drawing occurs through the glyph - * code. In order for the cursor to appear on top of the hero, - * the code must compute X,Y in the same manner relative to - * the RastPort coordinates. - * - * y = w->BorderTop + (g_nodes[i].y-2) * rp->TxHeight + - * rp->TxBaseline + 1; - * x = g_nodes[i].x * rp->TxWidth + w->BorderLeft; - */ + if (cw->type == NHW_MENU) { + if (WINVERS_AMIV) { + if (window == WIN_INVEN) { + Move(rp, (x * rp->TxWidth) + w->BorderLeft + 1 + + pictdata.xsize + 4, + (y * max(rp->TxHeight, pictdata.ysize + 3)) + + rp->TxBaseline + pictdata.ysize - rp->TxHeight + + w->BorderTop + 4); + } else { + Move(rp, (x * rp->TxWidth) + w->BorderLeft + 1, + (y * rp->TxHeight) + rp->TxBaseline + w->BorderTop + 1); + } + } else { + Move(rp, (x * rp->TxWidth) + w->BorderLeft + 1, + (y * rp->TxHeight) + rp->TxBaseline + w->BorderTop + 1); + } + } else if (cw->type == NHW_TEXT) { + Move(rp, (x * rp->TxWidth) + w->BorderLeft + 1, + (y * rp->TxHeight) + rp->TxBaseline + w->BorderTop + 1); + } else if (cw->type == NHW_MAP || cw->type == NHW_BASE) { + /* These coordinate calculations must be synced with those + * in flush_glyph_buffer() in winchar.c. curs_on_u() will + * use this code, all other drawing occurs through the glyph + * code. In order for the cursor to appear on top of the hero, + * the code must compute X,Y in the same manner relative to + * the RastPort coordinates. + * + * y = w->BorderTop + (g_nodes[i].y-2) * rp->TxHeight + + * rp->TxBaseline + 1; + * x = g_nodes[i].x * rp->TxWidth + w->BorderLeft; + */ - if( WINVERS_AMIV ) - { - if( cw->type == NHW_MAP ) - { - if(Is_rogue_level(&u.uz)){ + if (WINVERS_AMIV) { + if (cw->type == NHW_MAP) { + if (Is_rogue_level(&u.uz)) { #if 0 int qqx= (x * w->RPort->TxWidth) + w->BorderLeft; int qqy= w->BorderTop + ( (y+1) * w->RPort->TxHeight ) + 1; printf("pos: (%d,%d)->(%d,%d)\n",x,y,qqx,qqy); #endif - SetAPen(w->RPort,C_WHITE); /* XXX should be elsewhere (was 4)*/ - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft, - w->BorderTop + ( (y+1) * w->RPort->TxHeight ) + 1 ); - } else { - Move( rp, (x * mxsize) + w->BorderLeft, - w->BorderTop + ( (y+1) * mysize ) + 1 ); - } - } - else - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft, - w->BorderTop + ( (y + 1) * w->RPort->TxHeight ) + - w->RPort->TxBaseline + 1 ); - } - } - else - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft, - w->BorderTop + ( y * w->RPort->TxHeight ) + - w->RPort->TxBaseline + 1 ); - } - } - else if( WINVERS_AMIV && cw->type == NHW_OVER ) - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, - w->BorderTop + w->RPort->TxBaseline + 3 ); - } - else if( cw->type == NHW_MESSAGE && !scrollmsg ) - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, - w->BorderTop + w->RPort->TxBaseline + 3 ); - } - else if( cw->type == NHW_STATUS ) - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, - (y*(w->RPort->TxHeight+1)) + w->BorderTop + - w->RPort->TxBaseline + 1 ); - } - else - { - Move( rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, - (y*w->RPort->TxHeight) + w->BorderTop + - w->RPort->TxBaseline + 1 ); + SetAPen(w->RPort, + C_WHITE); /* XXX should be elsewhere (was 4)*/ + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft, + w->BorderTop + ((y + 1) * w->RPort->TxHeight) + 1); + } else { + Move(rp, (x * mxsize) + w->BorderLeft, + w->BorderTop + ((y + 1) * mysize) + 1); + } + } else { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft, + w->BorderTop + ((y + 1) * w->RPort->TxHeight) + + w->RPort->TxBaseline + 1); + } + } else { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft, + w->BorderTop + (y * w->RPort->TxHeight) + + w->RPort->TxBaseline + 1); + } + } else if (WINVERS_AMIV && cw->type == NHW_OVER) { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, + w->BorderTop + w->RPort->TxBaseline + 3); + } else if (cw->type == NHW_MESSAGE && !scrollmsg) { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, + w->BorderTop + w->RPort->TxBaseline + 3); + } else if (cw->type == NHW_STATUS) { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, + (y * (w->RPort->TxHeight + 1)) + w->BorderTop + + w->RPort->TxBaseline + 1); + } else { + Move(rp, (x * w->RPort->TxWidth) + w->BorderLeft + 2, + (y * w->RPort->TxHeight) + w->BorderTop + w->RPort->TxBaseline + + 1); } } void -amii_set_text_font( name, size ) - char *name; - int size; +amii_set_text_font(name, size) +char *name; +int size; { register int i; register struct amii_WinDesc *cw; int osize = TextsFont13.ta_YSize; - static char nname[ 100 ]; + static char nname[100]; - strncpy( nname, name, sizeof( nname ) - 1 ); - nname[ sizeof( nname ) - 1 ] = 0; + strncpy(nname, name, sizeof(nname) - 1); + nname[sizeof(nname) - 1] = 0; TextsFont13.ta_Name = nname; TextsFont13.ta_YSize = size; /* No alternate text font allowed for 640x269 or smaller */ - if( !HackScreen || !bigscreen ) - return; + if (!HackScreen || !bigscreen) + return; /* Look for windows to set, and change them */ - if( DiskfontBase = - OpenLibrary( "diskfont.library", amii_libvers ) ) - { - TextsFont = OpenDiskFont( &TextsFont13 ); - for( i = 0; TextsFont && i < MAXWIN; ++i ) - { - if( (cw = amii_wins[ i ]) && cw->win != NULL ) - { - switch( cw->type ) - { - case NHW_STATUS: - MoveWindow( cw->win, 0, -( size - osize ) * 2 ); - SizeWindow( cw->win, 0, ( size - osize ) * 2 ); - SetFont( cw->win->RPort, TextsFont ); - break; - case NHW_MESSAGE: - case NHW_MAP: - case NHW_BASE: - case NHW_OVER: - SetFont( cw->win->RPort, TextsFont ); - break; - } - } - } + if (DiskfontBase = OpenLibrary("diskfont.library", amii_libvers)) { + TextsFont = OpenDiskFont(&TextsFont13); + for (i = 0; TextsFont && i < MAXWIN; ++i) { + if ((cw = amii_wins[i]) && cw->win != NULL) { + switch (cw->type) { + case NHW_STATUS: + MoveWindow(cw->win, 0, -(size - osize) * 2); + SizeWindow(cw->win, 0, (size - osize) * 2); + SetFont(cw->win->RPort, TextsFont); + break; + case NHW_MESSAGE: + case NHW_MAP: + case NHW_BASE: + case NHW_OVER: + SetFont(cw->win->RPort, TextsFont); + break; + } + } + } } CloseLibrary(DiskfontBase); DiskfontBase = NULL; } void -kill_nhwindows( all ) - register int all; +kill_nhwindows(all) +register int all; { register int i; register struct amii_WinDesc *cw; - /* Foreach open window in all of amii_wins[], CloseShWindow, free memory */ + /* Foreach open window in all of amii_wins[], CloseShWindow, free memory + */ - for( i = 0; i < MAXWIN; ++i ) - { - if( (cw = amii_wins[ i ]) && (cw->type != NHW_BASE || all) ) - { - amii_destroy_nhwindow( i ); - } + for (i = 0; i < MAXWIN; ++i) { + if ((cw = amii_wins[i]) && (cw->type != NHW_BASE || all)) { + amii_destroy_nhwindow(i); + } } } void -amii_cl_end( cw, curs_pos ) - register struct amii_WinDesc *cw; - register int curs_pos; +amii_cl_end(cw, curs_pos) +register struct amii_WinDesc *cw; +register int curs_pos; { register struct Window *w = cw->win; register int oy, ox; - if( !w ) - panic("NULL window pointer in amii_cl_end()"); + if (!w) + panic("NULL window pointer in amii_cl_end()"); oy = w->RPort->cp_y; ox = w->RPort->cp_x; - TextSpaces( w->RPort, cw->cols - curs_pos ); + TextSpaces(w->RPort, cw->cols - curs_pos); - Move( w->RPort, ox, oy ); + Move(w->RPort, ox, oy); } void -cursor_off( window ) - winid window; +cursor_off(window) +winid window; { register struct amii_WinDesc *cw; register struct Window *w; @@ -1852,19 +1743,18 @@ cursor_off( window ) short apen, bpen; unsigned char ch; - if( window == WIN_ERR || ( cw = amii_wins[window] ) == NULL ) - { - iflags.window_inited=0; - panic(winpanicstr,window, "cursor_off"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL) { + iflags.window_inited = 0; + panic(winpanicstr, window, "cursor_off"); } - if( !(cw->wflags & FLMAP_CURSUP ) ) - return; + if (!(cw->wflags & FLMAP_CURSUP)) + return; w = cw->win; - if( !w ) - return; + if (!w) + return; cw->wflags &= ~FLMAP_CURSUP; rp = w->RPort; @@ -1877,35 +1767,32 @@ cursor_off( window ) dmode = rp->DrawMode; apen = rp->FgPen; bpen = rp->BgPen; - SetAPen( rp, cw->curs_apen ); - SetBPen( rp, cw->curs_bpen ); - SetDrMd( rp, COMPLEMENT ); -/*printf("CURSOR OFF: %d %d\n",x,y);*/ + SetAPen(rp, cw->curs_apen); + SetBPen(rp, cw->curs_bpen); + SetDrMd(rp, COMPLEMENT); + /*printf("CURSOR OFF: %d %d\n",x,y);*/ - if( WINVERS_AMIV && cw->type == NHW_MAP) - { - cursor_common(rp, x, y); - if(Is_rogue_level(&u.uz)) - Move(rp,curx,cury); + if (WINVERS_AMIV && cw->type == NHW_MAP) { + cursor_common(rp, x, y); + if (Is_rogue_level(&u.uz)) + Move(rp, curx, cury); + } else { + ch = CURSOR_CHAR; + Move(rp, x, y); + Text(rp, &ch, 1); + + /* Put back the other stuff */ + + Move(rp, curx, cury); } - else - { - ch = CURSOR_CHAR; - Move( rp, x, y ); - Text( rp, &ch, 1 ); - - /* Put back the other stuff */ - - Move( rp, curx, cury ); - } - SetDrMd( rp, dmode ); - SetAPen( rp, apen ); - SetBPen( rp, bpen ); + SetDrMd(rp, dmode); + SetAPen(rp, apen); + SetBPen(rp, bpen); } void -cursor_on( window ) - winid window; +cursor_on(window) +winid window; { int x, y; register struct amii_WinDesc *cw; @@ -1915,33 +1802,33 @@ cursor_on( window ) long dmode; short apen, bpen; - if( window == WIN_ERR || ( cw = amii_wins[window] ) == NULL ) - { - /* tty does this differently - is this OK? */ - iflags.window_inited=0; - panic(winpanicstr,window, "cursor_on"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL) { + /* tty does this differently - is this OK? */ + iflags.window_inited = 0; + panic(winpanicstr, window, "cursor_on"); } -/*printf("CURSOR ON: %d %d\n",cw->win->RPort->cp_x, cw->win->RPort->cp_y);*/ - if( (cw->wflags & FLMAP_CURSUP ) ) - cursor_off( window ); + /*printf("CURSOR ON: %d %d\n",cw->win->RPort->cp_x, + * cw->win->RPort->cp_y);*/ + if ((cw->wflags & FLMAP_CURSUP)) + cursor_off(window); w = cw->win; - if( !w ) - return; + if (!w) + return; cw->wflags |= FLMAP_CURSUP; rp = w->RPort; - /* Save the current information */ +/* Save the current information */ -#ifdef DISPMAP - if( WINVERS_AMIV && cw->type == NHW_MAP && !Is_rogue_level(&u.uz)) - x = cw->cursx = (rp->cp_x & -8) + 8; +#ifdef DISPMAP + if (WINVERS_AMIV && cw->type == NHW_MAP && !Is_rogue_level(&u.uz)) + x = cw->cursx = (rp->cp_x & -8) + 8; else #endif - x = cw->cursx = rp->cp_x; + x = cw->cursx = rp->cp_x; y = cw->cursy = rp->cp_y; apen = rp->FgPen; bpen = rp->BgPen; @@ -1951,85 +1838,92 @@ cursor_on( window ) cw->curs_apen = 0xff; /* Last color/all planes, regardless of depth */ cw->curs_bpen = 0xff; - SetAPen( rp, cw->curs_apen ); - SetBPen( rp, cw->curs_bpen ); - SetDrMd( rp, COMPLEMENT ); - if( WINVERS_AMIV && cw->type == NHW_MAP) - { - cursor_common(rp, x, y); - } - else - { - Move( rp, x, y ); - ch = CURSOR_CHAR; - Text( rp, &ch, 1 ); - Move( rp, x, y ); + SetAPen(rp, cw->curs_apen); + SetBPen(rp, cw->curs_bpen); + SetDrMd(rp, COMPLEMENT); + if (WINVERS_AMIV && cw->type == NHW_MAP) { + cursor_common(rp, x, y); + } else { + Move(rp, x, y); + ch = CURSOR_CHAR; + Text(rp, &ch, 1); + Move(rp, x, y); } - SetDrMd( rp, dmode ); - SetAPen( rp, apen ); - SetBPen( rp, bpen ); + SetDrMd(rp, dmode); + SetAPen(rp, apen); + SetBPen(rp, bpen); } static void cursor_common(rp, x, y) - struct RastPort *rp; - int x,y; +struct RastPort *rp; +int x, y; { - int x1,x2,y1,y2; + int x1, x2, y1, y2; - if(Is_rogue_level(&u.uz)){ - x1 = x-2; y1 = y-rp->TxHeight; - x2 = x+rp->TxWidth+1; y2 = y+3; -/*printf("COMM: (%d %d) (%d %d) (%d %d) (%d %d)\n",x1,y1,x2,y2,x1+2,y1+2,x2-2,y2-2);*/ + if (Is_rogue_level(&u.uz)) { + x1 = x - 2; + y1 = y - rp->TxHeight; + x2 = x + rp->TxWidth + 1; + y2 = y + 3; + /*printf("COMM: (%d %d) (%d %d) (%d %d) (%d + * %d)\n",x1,y1,x2,y2,x1+2,y1+2,x2-2,y2-2);*/ } else { - x1 = x; y1 = y-mysize-1; - x2 = x+mxsize-1; y2 = y-2; - RectFill(rp, x1, y1, x2, y2); + x1 = x; + y1 = y - mysize - 1; + x2 = x + mxsize - 1; + y2 = y - 2; + RectFill(rp, x1, y1, x2, y2); } - RectFill(rp, x1+2, y1+2, x2-2, y2-2); + RectFill(rp, x1 + 2, y1 + 2, x2 - 2, y2 - 2); } -void amii_suspend_nhwindows( str ) - const char *str; +void +amii_suspend_nhwindows(str) +const char *str; { - if( HackScreen ) - ScreenToBack( HackScreen ); + if (HackScreen) + ScreenToBack(HackScreen); } -void amii_resume_nhwindows() +void +amii_resume_nhwindows() { - if( HackScreen ) - ScreenToFront( HackScreen ); + if (HackScreen) + ScreenToFront(HackScreen); } -void amii_bell() +void +amii_bell() { - DisplayBeep( NULL ); + DisplayBeep(NULL); } void removetopl(cnt) - int cnt; +int cnt; { - struct amii_WinDesc *cw=amii_wins[WIN_MESSAGE]; - /* NB - this is sufficient for - * yn_function, but that's it - */ - if(cw->curx < cnt)cw->curx=0; - else cw->curx -= cnt; + struct amii_WinDesc *cw = amii_wins[WIN_MESSAGE]; + /* NB - this is sufficient for + * yn_function, but that's it + */ + if (cw->curx < cnt) + cw->curx = 0; + else + cw->curx -= cnt; - amii_curs(WIN_MESSAGE, cw->curx+1, cw->cury); + amii_curs(WIN_MESSAGE, cw->curx + 1, cw->cury); amii_cl_end(cw, cw->curx); } /*#endif /* AMIGA_INTUITION */ -#ifdef PORT_HELP +#ifdef PORT_HELP void port_help() { - display_file( PORT_HELP, 1 ); + display_file(PORT_HELP, 1); } #endif @@ -2043,33 +1937,31 @@ port_help() */ void -amii_print_glyph(win,x,y,glyph) - winid win; - xchar x,y; - int glyph; +amii_print_glyph(win, x, y, glyph) +winid win; +xchar x, y; +int glyph; { struct amii_WinDesc *cw; - uchar ch; - int color, och; + uchar ch; + int color, och; extern const int zapcolors[]; unsigned special; /* In order for the overview window to work, we can not clip here */ - if( !WINVERS_AMIV ) - { -#ifdef CLIPPING - /* If point not in visible part of window just skip it */ - if( clipping ) - { - if( x <= clipx || y < clipy || x >= clipxmax || y >= clipymax ) - return; - } + if (!WINVERS_AMIV) { +#ifdef CLIPPING + /* If point not in visible part of window just skip it */ + if (clipping) { + if (x <= clipx || y < clipy || x >= clipxmax || y >= clipymax) + return; + } #endif } - if( win == WIN_ERR || (cw=amii_wins[win]) == NULL || cw->type != NHW_MAP) - { - panic(winpanicstr,win,"amii_print_glyph"); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL + || cw->type != NHW_MAP) { + panic(winpanicstr, win, "amii_print_glyph"); } #if 0 @@ -2081,34 +1973,32 @@ if(u.uz.dlevel != x){ } } #endif - if(WINVERS_AMIV && !Is_rogue_level(&u.uz)) + if (WINVERS_AMIV && !Is_rogue_level(&u.uz)) { + amii_curs(win, x, y); + amiga_print_glyph(win, 0, glyph); + } else /* AMII, or Rogue level in either version */ { - amii_curs(win,x,y); - amiga_print_glyph(win,0,glyph); - } - else /* AMII, or Rogue level in either version */ - { - /* map glyph to character and color */ - (void) mapglyph(glyph, &och, &color, &special, x, y); - ch = (uchar)och; - if( WINVERS_AMIV ){ /* implies Rogue level here */ - amii_curs(win,x,y); - amiga_print_glyph(win,NO_COLOR,ch + 10000); - } else { - /* Move the cursor. */ - amii_curs(win,x,y+2); + /* map glyph to character and color */ + (void) mapglyph(glyph, &och, &color, &special, x, y); + ch = (uchar) och; + if (WINVERS_AMIV) { /* implies Rogue level here */ + amii_curs(win, x, y); + amiga_print_glyph(win, NO_COLOR, ch + 10000); + } else { + /* Move the cursor. */ + amii_curs(win, x, y + 2); #ifdef TEXTCOLOR - /* Turn off color if rogue level. */ - if (Is_rogue_level(&u.uz)) - color = NO_COLOR; + /* Turn off color if rogue level. */ + if (Is_rogue_level(&u.uz)) + color = NO_COLOR; - amiga_print_glyph(win,color,ch); + amiga_print_glyph(win, color, ch); #else - g_putch(ch); /* print the character */ + g_putch(ch); /* print the character */ #endif - cw->curx++; /* one character over */ - } + cw->curx++; /* one character over */ + } } } @@ -2116,14 +2006,14 @@ if(u.uz.dlevel != x){ void amii_raw_print(s) - register const char *s; +register const char *s; { int argc = 0; - if( !s ) - return; - if(amiIDisplay) - amiIDisplay->rawprint++; + if (!s) + return; + if (amiIDisplay) + amiIDisplay->rawprint++; if (!Initialized) { /* Not yet screen open ... */ puts(s); @@ -2131,19 +2021,18 @@ amii_raw_print(s) return; } - if( Initialized == 0 && WIN_BASE == WIN_ERR ) - init_nhwindows(&argc, (char **)0); + if (Initialized == 0 && WIN_BASE == WIN_ERR) + init_nhwindows(&argc, (char **) 0); - if( amii_rawprwin != WIN_ERR ) - amii_putstr( amii_rawprwin, 0, s ); - else if( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) - amii_putstr( WIN_MAP, 0, s ); - else if( WIN_BASE != WIN_ERR && amii_wins[ WIN_BASE ] ) - amii_putstr( WIN_BASE, 0, s ); - else - { - puts( s); - fflush(stdout); + if (amii_rawprwin != WIN_ERR) + amii_putstr(amii_rawprwin, 0, s); + else if (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP]) + amii_putstr(WIN_MAP, 0, s); + else if (WIN_BASE != WIN_ERR && amii_wins[WIN_BASE]) + amii_putstr(WIN_BASE, 0, s); + else { + puts(s); + fflush(stdout); } } @@ -2153,15 +2042,15 @@ amii_raw_print(s) void amii_raw_print_bold(s) - register const char *s; +register const char *s; { int argc = 0; - if( !s ) - return; + if (!s) + return; - if(amiIDisplay) - amiIDisplay->rawprint++; + if (amiIDisplay) + amiIDisplay->rawprint++; if (!Initialized) { /* Not yet screen open ... */ puts(s); @@ -2169,19 +2058,18 @@ amii_raw_print_bold(s) return; } - if( Initialized == 0 && WIN_BASE == WIN_ERR ) - init_nhwindows(&argc, (char **)0); + if (Initialized == 0 && WIN_BASE == WIN_ERR) + init_nhwindows(&argc, (char **) 0); - if( amii_rawprwin != WIN_ERR ) - amii_putstr( amii_rawprwin, 1, s ); - else if( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) - amii_putstr( WIN_MAP, 1, s ); - else if( WIN_BASE != WIN_ERR && amii_wins[ WIN_BASE ] ) - amii_putstr( WIN_BASE, 1, s ); - else - { - printf("\33[1m%s\33[0m\n",s); - fflush(stdout); + if (amii_rawprwin != WIN_ERR) + amii_putstr(amii_rawprwin, 1, s); + else if (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP]) + amii_putstr(WIN_MAP, 1, s); + else if (WIN_BASE != WIN_ERR && amii_wins[WIN_BASE]) + amii_putstr(WIN_BASE, 1, s); + else { + printf("\33[1m%s\33[0m\n", s); + fflush(stdout); } } @@ -2192,10 +2080,9 @@ amii_update_inventory() { register struct amii_WinDesc *cw; - if( WIN_INVEN != WIN_ERR && ( cw = amii_wins[ WIN_INVEN ] ) && - cw->type == NHW_MENU && cw->win ) - { - display_inventory( NULL, FALSE ); + if (WIN_INVEN != WIN_ERR && (cw = amii_wins[WIN_INVEN]) + && cw->type == NHW_MENU && cw->win) { + display_inventory(NULL, FALSE); } } @@ -2204,9 +2091,9 @@ amii_update_inventory() void amii_mark_synch() { - if(!amiIDisplay) - fflush(stderr); -/* anything else? do we need this much? */ + if (!amiIDisplay) + fflush(stderr); + /* anything else? do we need this much? */ } /* Wait for everything to sync. Nothing is asynchronous, so we just @@ -2215,28 +2102,25 @@ amii_mark_synch() void amii_wait_synch() { - if(!amiIDisplay || amiIDisplay->rawprint) - { - if(amiIDisplay) amiIDisplay->rawprint=0; - } - else - { - if( WIN_MAP != WIN_ERR ) - { - display_nhwindow(WIN_MAP,TRUE); - flush_glyph_buffer( amii_wins[ WIN_MAP ]->win ); - } + if (!amiIDisplay || amiIDisplay->rawprint) { + if (amiIDisplay) + amiIDisplay->rawprint = 0; + } else { + if (WIN_MAP != WIN_ERR) { + display_nhwindow(WIN_MAP, TRUE); + flush_glyph_buffer(amii_wins[WIN_MAP]->win); + } } } void amii_setclipped() { -#ifdef CLIPPING +#ifdef CLIPPING clipping = TRUE; - clipx=clipy=0; - clipxmax=CO; - clipymax=LI; + clipx = clipy = 0; + clipxmax = CO; + clipymax = LI; /* some of this is now redundant with top of amii_cliparound XXX */ #endif } @@ -2245,115 +2129,117 @@ amii_setclipped() * edge of the map is already displayed */ void -amii_cliparound(x,y) - register int x,y; +amii_cliparound(x, y) +register int x, y; { extern boolean restoring; -#ifdef CLIPPING +#ifdef CLIPPING int oldx = clipx, oldy = clipy; int oldxmax = clipxmax, oldymax = clipymax; int COx, LIx; -#define SCROLLCNT 1 /* Get there in 3 moves... */ - int scrollcnt = SCROLLCNT; /* ...or 1 if we changed level */ - if (!clipping) /* And 1 in anycase, cleaner, simpler, quicker */ - return; +#define SCROLLCNT 1 /* Get there in 3 moves... */ + int scrollcnt = SCROLLCNT; /* ...or 1 if we changed level */ + if (!clipping) /* And 1 in anycase, cleaner, simpler, quicker */ + return; - if(Is_rogue_level(&u.uz)){ - struct Window *w = amii_wins[WIN_MAP]->win; - struct RastPort *rp = w->RPort; + if (Is_rogue_level(&u.uz)) { + struct Window *w = amii_wins[WIN_MAP]->win; + struct RastPort *rp = w->RPort; - COx = (w->Width-w->BorderLeft-w->BorderRight)/rp->TxWidth; - LIx = (w->Height-w->BorderTop-w->BorderBottom)/rp->TxHeight; - }else{ - COx = CO; - LIx = LI; + COx = (w->Width - w->BorderLeft - w->BorderRight) / rp->TxWidth; + LIx = (w->Height - w->BorderTop - w->BorderBottom) / rp->TxHeight; + } else { + COx = CO; + LIx = LI; } - /* - * On a level change, move the clipping region so that for a - * reasonablely large window extra motion is avoided; for - * the rogue level hopefully this means no motion at all. - */ + /* + * On a level change, move the clipping region so that for a + * reasonablely large window extra motion is avoided; for + * the rogue level hopefully this means no motion at all. + */ { - static d_level saved_level = {127,127}; /* XXX */ + static d_level saved_level = { 127, 127 }; /* XXX */ - if(!on_level(&u.uz, &saved_level)){ - scrollcnt = 1; /* jump with blanking */ - clipx=clipy=0; - clipxmax = COx; clipymax = LIx; - saved_level = u.uz; /* save as new current level */ - } + if (!on_level(&u.uz, &saved_level)) { + scrollcnt = 1; /* jump with blanking */ + clipx = clipy = 0; + clipxmax = COx; + clipymax = LIx; + saved_level = u.uz; /* save as new current level */ + } } - if (x <= clipx + xclipbord ) { - clipx = max(0, x - (clipxmax - clipx)/2 ); - clipxmax = clipx + COx; - } - else if (x > clipxmax - xclipbord ) { - clipxmax = min(COLNO, x + (clipxmax - clipx)/2 ); - clipx = clipxmax - COx; + if (x <= clipx + xclipbord) { + clipx = max(0, x - (clipxmax - clipx) / 2); + clipxmax = clipx + COx; + } else if (x > clipxmax - xclipbord) { + clipxmax = min(COLNO, x + (clipxmax - clipx) / 2); + clipx = clipxmax - COx; } - if (y <= clipy + yclipbord ) { - clipy = max(0, y - (clipymax - clipy) / 2); - clipymax = clipy + LIx; - } - else if (y > clipymax - yclipbord ) { - clipymax = min(ROWNO, y + (clipymax - clipy) / 2); - clipy = clipymax - LIx; + if (y <= clipy + yclipbord) { + clipy = max(0, y - (clipymax - clipy) / 2); + clipymax = clipy + LIx; + } else if (y > clipymax - yclipbord) { + clipymax = min(ROWNO, y + (clipymax - clipy) / 2); + clipy = clipymax - LIx; } reclip = 1; - if (clipx != oldx || clipy != oldy || clipxmax != oldxmax || clipymax != oldymax ) - { + if (clipx != oldx || clipy != oldy || clipxmax != oldxmax + || clipymax != oldymax) { #ifndef NOSCROLLRASTER - struct Window *w = amii_wins[ WIN_MAP ]->win; - struct RastPort *rp = w->RPort; - int xdelta, ydelta, xmod, ymod, i; - int incx, incy, mincx, mincy; - int savex, savey, savexmax, saveymax; - int scrx, scry; + struct Window *w = amii_wins[WIN_MAP]->win; + struct RastPort *rp = w->RPort; + int xdelta, ydelta, xmod, ymod, i; + int incx, incy, mincx, mincy; + int savex, savey, savexmax, saveymax; + int scrx, scry; - if(Is_rogue_level(&u.uz)){ - scrx = rp->TxWidth; - scry = rp->TxHeight; - } else { - scrx = mxsize; - scry = mysize; - } + if (Is_rogue_level(&u.uz)) { + scrx = rp->TxWidth; + scry = rp->TxHeight; + } else { + scrx = mxsize; + scry = mysize; + } - /* Ask that the glyph routines not draw the overview window */ - reclip = 2; - cursor_off( WIN_MAP ); + /* Ask that the glyph routines not draw the overview window */ + reclip = 2; + cursor_off(WIN_MAP); - /* Compute how far we are moving in terms of tiles */ - mincx = clipx - oldx ; - mincy = clipy - oldy ; + /* Compute how far we are moving in terms of tiles */ + mincx = clipx - oldx; + mincy = clipy - oldy; - /* How many tiles to get there in SCROLLCNT moves */ - incx = ( clipx - oldx )/scrollcnt; - incy = ( clipy - oldy )/scrollcnt; + /* How many tiles to get there in SCROLLCNT moves */ + incx = (clipx - oldx) / scrollcnt; + incy = (clipy - oldy) / scrollcnt; - /* If less than SCROLLCNT tiles, then move by 1 tile if moving at all */ - if( incx == 0 ) incx = (mincx != 0); - if( incy == 0 ) incy = (mincy != 0); + /* If less than SCROLLCNT tiles, then move by 1 tile if moving at all + */ + if (incx == 0) + incx = (mincx != 0); + if (incy == 0) + incy = (mincy != 0); - /* Get count of pixels to move each iteration and final pixel count */ - xdelta = ((clipx-oldx )*scrx) / scrollcnt; - xmod = ((clipx-oldx )*scrx) % scrollcnt; - ydelta = ((clipy-oldy )*scry) / scrollcnt; - ymod = ((clipy-oldy )*scry) % scrollcnt; + /* Get count of pixels to move each iteration and final pixel count */ + xdelta = ((clipx - oldx) * scrx) / scrollcnt; + xmod = ((clipx - oldx) * scrx) % scrollcnt; + ydelta = ((clipy - oldy) * scry) / scrollcnt; + ymod = ((clipy - oldy) * scry) % scrollcnt; - /* Preserve the final move location */ - savex = clipx; - savey = clipy; - saveymax = clipymax; - savexmax = clipxmax; + /* Preserve the final move location */ + savex = clipx; + savey = clipy; + saveymax = clipymax; + savexmax = clipxmax; - /* - * Set clipping rectangle to be just the region that will be exposed so - * that drawing will be faster - */ -#if 0 /* Doesn't seem to work quite the way it should */ +/* + * Set clipping rectangle to be just the region that will be exposed so + * that drawing will be faster + */ +#if 0 /* Doesn't seem to work quite the way it should */ /* In some cases hero is 'centered' offscreen */ if( xdelta < 0 ) { @@ -2387,64 +2273,64 @@ amii_cliparound(x,y) clipymax = oldymax; } #endif - /* Now, in scrollcnt moves, move the picture toward the final view */ - for( i = 0; i < scrollcnt; ++i ) - { -#ifdef DISPMAP - if( i == scrollcnt - 1 && (xmod != 0 || ymod != 0) && - (xdelta != 0 || ydelta != 0) ) - { - incx += (clipx - oldx)%scrollcnt; - incy += (clipy - oldy)%scrollcnt; - xdelta += xmod; - ydelta += ymod; - } + /* Now, in scrollcnt moves, move the picture toward the final view */ + for (i = 0; i < scrollcnt; ++i) { +#ifdef DISPMAP + if (i == scrollcnt - 1 && (xmod != 0 || ymod != 0) + && (xdelta != 0 || ydelta != 0)) { + incx += (clipx - oldx) % scrollcnt; + incy += (clipy - oldy) % scrollcnt; + xdelta += xmod; + ydelta += ymod; + } #endif - /* Scroll the raster if we are scrolling */ - if( xdelta != 0 || ydelta != 0 ) - { - ScrollRaster( rp, xdelta, ydelta, - w->BorderLeft, w->BorderTop, - w->Width - w->BorderRight - 1, - w->Height - w->BorderBottom - 1 ); + /* Scroll the raster if we are scrolling */ + if (xdelta != 0 || ydelta != 0) { + ScrollRaster(rp, xdelta, ydelta, w->BorderLeft, w->BorderTop, + w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); - if( mincx == 0 ) incx = 0; - else mincx -= incx; + if (mincx == 0) + incx = 0; + else + mincx -= incx; - clipx += incx; - clipxmax += incx; + clipx += incx; + clipxmax += incx; - if( mincy == 0 ) incy = 0; - else mincy -= incy; + if (mincy == 0) + incy = 0; + else + mincy -= incy; - clipy += incy; - clipymax += incy; + clipy += incy; + clipymax += incy; - /* Draw the exposed portion */ - if (on_level(&u.uz0, &u.uz) && !restoring) - (void) doredraw(); - flush_glyph_buffer( amii_wins[ WIN_MAP ]->win ); - } - } + /* Draw the exposed portion */ + if (on_level(&u.uz0, &u.uz) && !restoring) + (void) doredraw(); + flush_glyph_buffer(amii_wins[WIN_MAP]->win); + } + } - clipx = savex; - clipy = savey; - clipymax = saveymax; - clipxmax = savexmax; + clipx = savex; + clipy = savey; + clipymax = saveymax; + clipxmax = savexmax; #endif - if (on_level(&u.uz0, &u.uz) && !restoring && moves > 1) - (void) doredraw(); - flush_glyph_buffer( amii_wins[ WIN_MAP ]->win ); + if (on_level(&u.uz0, &u.uz) && !restoring && moves > 1) + (void) doredraw(); + flush_glyph_buffer(amii_wins[WIN_MAP]->win); } reclip = 0; #endif } void -flushIDCMP( port ) - struct MsgPort *port; +flushIDCMP(port) +struct MsgPort *port; { - struct Message *msg; - while( msg = GetMsg( port ) ) - ReplyMsg( msg ); + struct Message *msg; + while (msg = GetMsg(port)) + ReplyMsg(msg); } diff --git a/sys/amiga/winkey.c b/sys/amiga/winkey.c index b938cc4f4..097e3748b 100644 --- a/sys/amiga/winkey.c +++ b/sys/amiga/winkey.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winkey.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winkey.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 winkey.c $Date: 2009/05/06 10:48:37 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)winkey.c 3.5 1993/04/02 */ /* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993. */ @@ -8,58 +8,49 @@ #include "NH:sys/amiga/winext.h" #include "NH:sys/amiga/winproto.h" -amii_nh_poskey(x, y, mod) - int*x, *y, *mod; +amii_nh_poskey(x, y, mod) int *x, *y, *mod; { struct amii_WinDesc *cw; WETYPE type; struct RastPort *rp; struct Window *w; - if( cw = amii_wins[WIN_MESSAGE] ) - { - cw->wflags &= ~FLMAP_SKIP; - if( scrollmsg ) - cw->wflags |= FLMSG_FIRST; - cw->disprows = 0; + if (cw = amii_wins[WIN_MESSAGE]) { + cw->wflags &= ~FLMAP_SKIP; + if (scrollmsg) + cw->wflags |= FLMSG_FIRST; + cw->disprows = 0; } - if( WIN_MAP != WIN_ERR && (cw = amii_wins[ WIN_MAP ]) && ( w = cw->win ) ) - { - cursor_on( WIN_MAP ); - } - else - panic( "no MAP window opened for nh_poskey\n" ); + if (WIN_MAP != WIN_ERR && (cw = amii_wins[WIN_MAP]) && (w = cw->win)) { + cursor_on(WIN_MAP); + } else + panic("no MAP window opened for nh_poskey\n"); rp = w->RPort; - while( 1 ) - { - type = WindowGetevent( ); - if( type == WEMOUSE ) - { - *mod = CLICK_1; - if( lastevent.un.mouse.qual ) - *mod = 0; + while (1) { + type = WindowGetevent(); + if (type == WEMOUSE) { + *mod = CLICK_1; + if (lastevent.un.mouse.qual) + *mod = 0; - /* X coordinates are 1 based, Y are 1 based. */ - *x = ( (lastevent.un.mouse.x - w->BorderLeft) / mxsize ) + 1; - *y = ( ( lastevent.un.mouse.y - w->BorderTop - MAPFTBASELN ) / - mysize ) + 1; -#ifdef CLIPPING - if( clipping ) - { - *x += clipx; - *y += clipy; - } + /* X coordinates are 1 based, Y are 1 based. */ + *x = ((lastevent.un.mouse.x - w->BorderLeft) / mxsize) + 1; + *y = ((lastevent.un.mouse.y - w->BorderTop - MAPFTBASELN) + / mysize) + 1; +#ifdef CLIPPING + if (clipping) { + *x += clipx; + *y += clipy; + } #endif - return( 0 ); - } - else if( type == WEKEY ) - { - lastevent.type = WEUNK; - return( lastevent.un.key ); - } + return (0); + } else if (type == WEKEY) { + lastevent.type = WEUNK; + return (lastevent.un.key); + } } } @@ -67,17 +58,16 @@ int amii_nhgetch() { int ch; - struct amii_WinDesc *cw=amii_wins[WIN_MESSAGE]; + struct amii_WinDesc *cw = amii_wins[WIN_MESSAGE]; - if( WIN_MAP != WIN_ERR && amii_wins[ WIN_MAP ] ) - { - cursor_on( WIN_MAP ); + if (WIN_MAP != WIN_ERR && amii_wins[WIN_MAP]) { + cursor_on(WIN_MAP); } - if(cw) - cw->wflags &= ~FLMAP_SKIP; + if (cw) + cw->wflags &= ~FLMAP_SKIP; ch = WindowGetchar(); - return( ch ); + return (ch); } void @@ -91,18 +81,16 @@ amii_getret() { register int c; - raw_print( "" ); - raw_print( "Press Return..." ); + raw_print(""); + raw_print("Press Return..."); c = 0; - while( c != '\n' && c != '\r' ) - { - if( HackPort ) - c = WindowGetchar(); - else - c = getchar(); + while (c != '\n' && c != '\r') { + if (HackPort) + c = WindowGetchar(); + else + c = getchar(); } return; } - diff --git a/sys/amiga/winmenu.c b/sys/amiga/winmenu.c index 6403c1497..d79942cbf 100644 --- a/sys/amiga/winmenu.c +++ b/sys/amiga/winmenu.c @@ -1,7 +1,8 @@ -/* NetHack 3.6 winmenu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winmenu.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 winmenu.c $Date: 2009/05/06 10:48:38 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)winmenu.c 3.5 1996/02/17 */ -/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. */ +/* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. + */ /* NetHack may be freely redistributed. See license for details. */ #include "NH:sys/amiga/windefs.h" @@ -11,46 +12,45 @@ /* Start building the text for a menu */ void amii_start_menu(window) - register winid window; +register winid window; { register int i; register struct amii_WinDesc *cw; register amii_menu_item *mip; - if(window == WIN_ERR || (cw = amii_wins[window]) == NULL || cw->type != NHW_MENU) - panic(winpanicstr,window, "start_menu"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL + || cw->type != NHW_MENU) + panic(winpanicstr, window, "start_menu"); amii_clear_nhwindow(window); - if( cw->data && ( cw->type == NHW_MESSAGE || - cw->type == NHW_MENU || cw->type == NHW_TEXT ) ) - { - for( i = 0; i < cw->maxrow; ++i ) - { - if( cw->data[ i ] ) - free( cw->data[ i ] ); - } - free( cw->data ); - cw->data = NULL; + if (cw->data && (cw->type == NHW_MESSAGE || cw->type == NHW_MENU + || cw->type == NHW_TEXT)) { + for (i = 0; i < cw->maxrow; ++i) { + if (cw->data[i]) + free(cw->data[i]); + } + free(cw->data); + cw->data = NULL; } - for( mip = cw->menu.items, i = 0; (mip = cw->menu.items) && i < cw->menu.count; ++i ) - { - cw->menu.items = mip->next; - free( mip ); + for (mip = cw->menu.items, i = 0; + (mip = cw->menu.items) && i < cw->menu.count; ++i) { + cw->menu.items = mip->next; + free(mip); } cw->menu.items = 0; cw->menu.count = 0; cw->menu.chr = 'a'; - if( cw->morestr ) free( cw->morestr ); + if (cw->morestr) + free(cw->morestr); cw->morestr = NULL; - if( window == WIN_INVEN && cw->win != NULL ) - { - if( alwaysinvent ) - cw->wasup = 1; + if (window == WIN_INVEN && cw->win != NULL) { + if (alwaysinvent) + cw->wasup = 1; } cw->cury = cw->rows = cw->maxrow = cw->maxcol = 0; return; @@ -58,26 +58,28 @@ amii_start_menu(window) /* Add a string to a menu */ void -amii_add_menu(window,glyph, id, ch, gch, attr, str, preselected) - register winid window; - register int glyph; - register const anything *id; - register char ch; - register char gch; - register int attr; - register const char *str; - register BOOLEAN_P preselected; +amii_add_menu(window, glyph, id, ch, gch, attr, str, preselected) +register winid window; +register int glyph; +register const anything *id; +register char ch; +register char gch; +register int attr; +register const char *str; +register BOOLEAN_P preselected; { register struct amii_WinDesc *cw; amii_menu_item *mip; - char buf[ 4+BUFSZ ]; + char buf[4 + BUFSZ]; - if(str == NULL)return; + if (str == NULL) + return; - if(window == WIN_ERR || (cw = amii_wins[window]) == NULL || cw->type != NHW_MENU) - panic(winpanicstr,window, "add_menu"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL + || cw->type != NHW_MENU) + panic(winpanicstr, window, "add_menu"); - mip = (amii_menu_item *)alloc( sizeof( *mip ) ); + mip = (amii_menu_item *) alloc(sizeof(*mip)); mip->identifier = *id; mip->selected = preselected; mip->attr = attr; @@ -86,157 +88,150 @@ amii_add_menu(window,glyph, id, ch, gch, attr, str, preselected) mip->gselector = gch; mip->count = -1; - if (id->a_void && !ch && cw->menu.chr != 0) - { - ch = cw->menu.chr++; - if( ch == 'z' ) - cw->menu.chr = 'A'; - if( ch == 'Z' ) - cw->menu.chr = 0; + if (id->a_void && !ch && cw->menu.chr != 0) { + ch = cw->menu.chr++; + if (ch == 'z') + cw->menu.chr = 'A'; + if (ch == 'Z') + cw->menu.chr = 0; } - mip->canselect = ( id->a_void != 0 ); + mip->canselect = (id->a_void != 0); - if( id->a_void && ch != '\0') - { - Sprintf( buf, "%c - %s", ch, str ); - str = buf; - mip->canselect = 1; + if (id->a_void && ch != '\0') { + Sprintf(buf, "%c - %s", ch, str); + str = buf; + mip->canselect = 1; } mip->selector = ch; - amii_putstr( window, attr, str ); + amii_putstr(window, attr, str); - mip->str = cw->data[ cw->cury - 1 ]; + mip->str = cw->data[cw->cury - 1]; cw->menu.count++; mip->next = NULL; - if( cw->menu.items == 0 ) - cw->menu.last = cw->menu.items = mip; - else - { - cw->menu.last->next = mip; - cw->menu.last = mip; + if (cw->menu.items == 0) + cw->menu.last = cw->menu.items = mip; + else { + cw->menu.last->next = mip; + cw->menu.last = mip; } } /* Done building a menu. */ void -amii_end_menu(window,morestr) - register winid window; - register const char *morestr; +amii_end_menu(window, morestr) +register winid window; +register const char *morestr; { register struct amii_WinDesc *cw; - if(window == WIN_ERR || (cw=amii_wins[window]) == NULL - || cw->type != NHW_MENU ) - panic(winpanicstr,window, "end_menu"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL + || cw->type != NHW_MENU) + panic(winpanicstr, window, "end_menu"); - if( morestr && *morestr ) - { - anything any; + if (morestr && *morestr) { + anything any; #define PROMPTFIRST /* Define this to have prompt first */ #ifdef PROMPTFIRST - amii_menu_item *mip; - int i; - char *t; - mip = cw->menu.last; + amii_menu_item *mip; + int i; + char *t; + mip = cw->menu.last; #endif - any.a_void = 0; - amii_add_menu( window, NO_GLYPH, &any, 0, 0, ATR_NONE, morestr, - MENU_UNSELECTED); -#ifdef PROMPTFIRST /* Do some shuffling. Last first, push others one forward */ - mip->next = NULL; - cw->menu.last->next = cw->menu.items; - cw->menu.items = cw->menu.last; - cw->menu.last = mip; - t = cw->data[cw->cury-1]; - for (i=cw->cury-1; i>0; i--) { - cw->data[i] = cw->data[i-1]; - } - cw->data[0] = t; + any.a_void = 0; + amii_add_menu(window, NO_GLYPH, &any, 0, 0, ATR_NONE, morestr, + MENU_UNSELECTED); +#ifdef PROMPTFIRST /* Do some shuffling. Last first, push others one forward \ + */ + mip->next = NULL; + cw->menu.last->next = cw->menu.items; + cw->menu.items = cw->menu.last; + cw->menu.last = mip; + t = cw->data[cw->cury - 1]; + for (i = cw->cury - 1; i > 0; i--) { + cw->data[i] = cw->data[i - 1]; + } + cw->data[0] = t; #endif } - /* If prompt first, don't put same string in title where in most cases - it's not entirely visible anyway */ +/* If prompt first, don't put same string in title where in most cases + it's not entirely visible anyway */ #ifndef PROMPTFIRST - if( morestr ) - cw->morestr = strdup( morestr ); + if (morestr) + cw->morestr = strdup(morestr); #endif } /* Select something from the menu. */ int -amii_select_menu(window, how, mip ) - register winid window; - register int how; - register menu_item **mip; +amii_select_menu(window, how, mip) +register winid window; +register int how; +register menu_item **mip; { int cnt; register struct amii_WinDesc *cw; - if( window == WIN_ERR || ( cw=amii_wins[window] ) == NULL || - cw->type != NHW_MENU ) - panic(winpanicstr,window, "select_menu"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL + || cw->type != NHW_MENU) + panic(winpanicstr, window, "select_menu"); - cnt = DoMenuScroll( window, 1, how, mip ); + cnt = DoMenuScroll(window, 1, how, mip); /* This would allow the inventory window to stay open. */ - if( !alwaysinvent || window != WIN_INVEN ) - dismiss_nhwindow(window); /* Now tear it down */ + if (!alwaysinvent || window != WIN_INVEN) + dismiss_nhwindow(window); /* Now tear it down */ return cnt; } amii_menu_item * -find_menu_item( register struct amii_WinDesc *cw, int idx ) +find_menu_item(register struct amii_WinDesc *cw, int idx) { amii_menu_item *mip; - for( mip = cw->menu.items; idx > 0 && mip; mip = mip->next ) - --idx; + for (mip = cw->menu.items; idx > 0 && mip; mip = mip->next) + --idx; - return( mip ); + return (mip); } int -make_menu_items( register struct amii_WinDesc *cw, register menu_item **rmip ) +make_menu_items(register struct amii_WinDesc *cw, register menu_item **rmip) { register int idx = 0; register amii_menu_item *mip; register menu_item *mmip; - for( mip = cw->menu.items; mip; mip = mip->next ) - { - if( mip->selected ) - ++idx; + for (mip = cw->menu.items; mip; mip = mip->next) { + if (mip->selected) + ++idx; } - if( idx ) - { - mmip = *rmip = (menu_item *)alloc( idx * sizeof( *mip ) ); - for( mip = cw->menu.items; mip; mip = mip->next ) - { - if( mip->selected ) - { - mmip->item = mip->identifier; - mmip->count = mip->count; - mmip++; - } - } + if (idx) { + mmip = *rmip = (menu_item *) alloc(idx * sizeof(*mip)); + for (mip = cw->menu.items; mip; mip = mip->next) { + if (mip->selected) { + mmip->item = mip->identifier; + mmip->count = mip->count; + mmip++; + } + } - cw->mi = *rmip; + cw->mi = *rmip; } - return( idx ); + return (idx); } int -DoMenuScroll( win, blocking, how, retmip ) - int win, blocking, how; - menu_item **retmip; +DoMenuScroll(win, blocking, how, retmip) +int win, blocking, how; +menu_item **retmip; { amii_menu_item *amip; register struct Window *w; @@ -252,27 +247,25 @@ DoMenuScroll( win, blocking, how, retmip ) int aidx, oidx, topidx, hidden; int totalvis; SHORT mx, my; - static char title[ 100 ]; + static char title[100]; int dosize = 1; struct Screen *scrn = HackScreen; - int x1,x2,y1,y2; + int x1, x2, y1, y2; long counting = FALSE, count = 0, reset_counting = FALSE; char countString[32]; - if( win == WIN_ERR || ( cw = amii_wins[ win ] ) == NULL ) - panic(winpanicstr,win,"DoMenuScroll"); + if (win == WIN_ERR || (cw = amii_wins[win]) == NULL) + panic(winpanicstr, win, "DoMenuScroll"); /* Initial guess at window sizing values */ txwd = txwidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - txh = max( txheight, pictdata.ysize + 3 ); /* interline space */ - else - txh = txheight; /* interline space */ - } - else - txh = txheight; /* interline space */ + if (WINVERS_AMIV) { + if (win == WIN_INVEN) + txh = max(txheight, pictdata.ysize + 3); /* interline space */ + else + txh = txheight; /* interline space */ + } else + txh = txheight; /* interline space */ /* Check to see if we should open the window, should need to for * TEXT and MENU but not MESSAGE. @@ -281,224 +274,197 @@ DoMenuScroll( win, blocking, how, retmip ) w = cw->win; topidx = 0; - if( w == NULL ) - { - -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - PropScroll.Flags |= PROPNEWLOOK; - } + if (w == NULL) { +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + PropScroll.Flags |= PROPNEWLOOK; + } #endif - nw = (void *)DupNewWindow( (void *)(&new_wins[ cw->type ].newwin) ); - if( !alwaysinvent || win != WIN_INVEN ) - { - xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 + - (txwd * cw->maxcol); - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - xsize += pictdata.xsize + 4; - } - if( xsize > amiIDisplay->xpix ) - xsize = amiIDisplay->xpix; + nw = (void *) DupNewWindow((void *) (&new_wins[cw->type].newwin)); + if (!alwaysinvent || win != WIN_INVEN) { + xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 + + (txwd * cw->maxcol); + if (WINVERS_AMIV) { + if (win == WIN_INVEN) + xsize += pictdata.xsize + 4; + } + if (xsize > amiIDisplay->xpix) + xsize = amiIDisplay->xpix; - /* If next row not off window, use it, else use the bottom */ + /* If next row not off window, use it, else use the bottom */ - ysize = ( txh * cw->maxrow ) + /* The text space */ - HackScreen->WBorTop + txheight + 1 + /* Top border */ - HackScreen->WBorBottom + 3; /* The bottom border */ - if( ysize > amiIDisplay->ypix ) - ysize = amiIDisplay->ypix; + ysize = (txh * cw->maxrow) + /* The text space */ + HackScreen->WBorTop + txheight + 1 + /* Top border */ + HackScreen->WBorBottom + 3; /* The bottom border */ + if (ysize > amiIDisplay->ypix) + ysize = amiIDisplay->ypix; - /* Adjust the size of the menu scroll gadget */ + /* Adjust the size of the menu scroll gadget */ - nw->TopEdge = 0; - if( cw->type == NHW_TEXT && ysize < amiIDisplay->ypix ) - nw->TopEdge += ( amiIDisplay->ypix - ysize ) / 2; - nw->LeftEdge = amiIDisplay->xpix - xsize; - if( cw->type == NHW_MENU ) - { - if( nw->LeftEdge > 10 ) - nw->LeftEdge -= 10; - else - nw->LeftEdge = 0; - if( amiIDisplay->ypix - nw->Height > 10 ) - nw->TopEdge += 10; - else - nw->TopEdge = amiIDisplay->ypix - nw->Height - 1; - } - if( cw->type == NHW_TEXT && xsize < amiIDisplay->xpix ) - nw->LeftEdge -= ( amiIDisplay->xpix - xsize ) / 2; - } - else if( win == WIN_INVEN ) - { - struct Window *mw = amii_wins[ WIN_MAP ]->win; - struct Window *sw = amii_wins[ WIN_STATUS ]->win; + nw->TopEdge = 0; + if (cw->type == NHW_TEXT && ysize < amiIDisplay->ypix) + nw->TopEdge += (amiIDisplay->ypix - ysize) / 2; + nw->LeftEdge = amiIDisplay->xpix - xsize; + if (cw->type == NHW_MENU) { + if (nw->LeftEdge > 10) + nw->LeftEdge -= 10; + else + nw->LeftEdge = 0; + if (amiIDisplay->ypix - nw->Height > 10) + nw->TopEdge += 10; + else + nw->TopEdge = amiIDisplay->ypix - nw->Height - 1; + } + if (cw->type == NHW_TEXT && xsize < amiIDisplay->xpix) + nw->LeftEdge -= (amiIDisplay->xpix - xsize) / 2; + } else if (win == WIN_INVEN) { + struct Window *mw = amii_wins[WIN_MAP]->win; + struct Window *sw = amii_wins[WIN_STATUS]->win; - xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 + - (txwd * cw->maxcol); + xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 + + (txwd * cw->maxcol); - /* Make space for the glyph to appear at the left of the description */ - if( WINVERS_AMIV ) - xsize += pictdata.xsize + 4; + /* Make space for the glyph to appear at the left of the + * description */ + if (WINVERS_AMIV) + xsize += pictdata.xsize + 4; - if( xsize > amiIDisplay->xpix ) - xsize = amiIDisplay->xpix; + if (xsize > amiIDisplay->xpix) + xsize = amiIDisplay->xpix; - /* If next row not off window, use it, else use the bottom */ + /* If next row not off window, use it, else use the bottom */ - ysize = sw->TopEdge - (mw->TopEdge + mw->Height) - 1; - if( ysize > amiIDisplay->ypix ) - ysize = amiIDisplay->ypix; + ysize = sw->TopEdge - (mw->TopEdge + mw->Height) - 1; + if (ysize > amiIDisplay->ypix) + ysize = amiIDisplay->ypix; - /* Adjust the size of the menu scroll gadget */ + /* Adjust the size of the menu scroll gadget */ - nw->TopEdge = mw->TopEdge + mw->Height; - nw->LeftEdge = 0; - } - cw->newwin = (void *)nw; - if( nw == NULL ) - panic("No NewWindow Allocated" ); + nw->TopEdge = mw->TopEdge + mw->Height; + nw->LeftEdge = 0; + } + cw->newwin = (void *) nw; + if (nw == NULL) + panic("No NewWindow Allocated"); - nw->Screen = HackScreen; + nw->Screen = HackScreen; - if( win == WIN_INVEN ) - { - sprintf( title, "%s the %s's Inventory", plname, pl_character ); - nw->Title = title; - if( lastinvent.MaxX != 0 ) - { - nw->LeftEdge = lastinvent.MinX; - nw->TopEdge = lastinvent.MinY; - nw->Width = lastinvent.MaxX; - nw->Height = lastinvent.MaxY; - } - } - else if( cw->morestr ) - nw->Title = cw->morestr; + if (win == WIN_INVEN) { + sprintf(title, "%s the %s's Inventory", plname, pl_character); + nw->Title = title; + if (lastinvent.MaxX != 0) { + nw->LeftEdge = lastinvent.MinX; + nw->TopEdge = lastinvent.MinY; + nw->Width = lastinvent.MaxX; + nw->Height = lastinvent.MaxY; + } + } else if (cw->morestr) + nw->Title = cw->morestr; - /* Adjust the window coordinates and size now that we know - * how many items are to be displayed. - */ + /* Adjust the window coordinates and size now that we know + * how many items are to be displayed. + */ - if( ( xsize > amiIDisplay->xpix - nw->LeftEdge ) && - ( xsize < amiIDisplay->xpix ) ) - { - nw->LeftEdge = amiIDisplay->xpix - xsize; - nw->Width = xsize; - } - else - { - nw->Width = min( xsize, amiIDisplay->xpix - nw->LeftEdge ); - } - nw->Height = min( ysize, amiIDisplay->ypix - nw->TopEdge ); + if ((xsize > amiIDisplay->xpix - nw->LeftEdge) + && (xsize < amiIDisplay->xpix)) { + nw->LeftEdge = amiIDisplay->xpix - xsize; + nw->Width = xsize; + } else { + nw->Width = min(xsize, amiIDisplay->xpix - nw->LeftEdge); + } + nw->Height = min(ysize, amiIDisplay->ypix - nw->TopEdge); - if( WINVERS_AMIV || WINVERS_AMII ) - { - /* Make sure we are using the correct hook structure */ - nw->Extension = cw->wintags; - } + if (WINVERS_AMIV || WINVERS_AMII) { + /* Make sure we are using the correct hook structure */ + nw->Extension = cw->wintags; + } - /* Now, open the window */ - w = cw->win = OpenShWindow( (void *)nw ); + /* Now, open the window */ + w = cw->win = OpenShWindow((void *) nw); - if( w == NULL ) - { - char buf[ 130 ]; + if (w == NULL) { + char buf[130]; - sprintf( buf, "No Window Opened For Menu (%d,%d,%d-%d,%d-%d)", - nw->LeftEdge, nw->TopEdge, nw->Width, amiIDisplay->xpix, - nw->Height, amiIDisplay->ypix ); - panic( buf ); - } + sprintf(buf, "No Window Opened For Menu (%d,%d,%d-%d,%d-%d)", + nw->LeftEdge, nw->TopEdge, nw->Width, amiIDisplay->xpix, + nw->Height, amiIDisplay->ypix); + panic(buf); + } #ifdef HACKFONT - if( TextsFont ) - SetFont(w->RPort, TextsFont ); - else if( HackFont ) - SetFont(w->RPort, HackFont ); + if (TextsFont) + SetFont(w->RPort, TextsFont); + else if (HackFont) + SetFont(w->RPort, HackFont); #endif - txwd = w->RPort->TxWidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - txh = max( w->RPort->TxHeight, pictdata.ysize + 3 ); /* interline space */ - else - txh = w->RPort->TxHeight; /* interline space */ - } - else - txh = w->RPort->TxHeight; /* interline space */ + txwd = w->RPort->TxWidth; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) + txh = max(w->RPort->TxHeight, + pictdata.ysize + 3); /* interline space */ + else + txh = w->RPort->TxHeight; /* interline space */ + } else + txh = w->RPort->TxHeight; /* interline space */ - /* subtract 2 to account for spacing away from border (1 on each side) */ - wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / txh; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - totalvis = CountLines( win ); - } - else - { - txwd = w->RPort->TxWidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - txh = max( w->RPort->TxHeight, pictdata.ysize + 3 ); /* interline space */ - else - txh = w->RPort->TxHeight; /* interline space */ - } - else - { - txh = w->RPort->TxHeight; /* interline space */ - } + /* subtract 2 to account for spacing away from border (1 on each side) + */ + wheight = (w->Height - w->BorderTop - w->BorderBottom - 2) / txh; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4 + - pictdata.xsize - 3) / txwd; + } else { + cw->cols = + (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } + totalvis = CountLines(win); + } else { + txwd = w->RPort->TxWidth; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) + txh = max(w->RPort->TxHeight, + pictdata.ysize + 3); /* interline space */ + else + txh = w->RPort->TxHeight; /* interline space */ + } else { + txh = w->RPort->TxHeight; /* interline space */ + } - /* subtract 2 to account for spacing away from border (1 on each side) */ - wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / txh; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3) / txwd; - } - else - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } + /* subtract 2 to account for spacing away from border (1 on each side) + */ + wheight = (w->Height - w->BorderTop - w->BorderBottom - 2) / txh; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4 + - pictdata.xsize - 3) / txwd; + } else + cw->cols = + (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } - totalvis = CountLines( win ); + totalvis = CountLines(win); - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( gd ) - { - pip = (struct PropInfo *)gd->SpecialInfo; - hidden = max( totalvis - wheight, 0 ); - topidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16; - } + if (gd) { + pip = (struct PropInfo *) gd->SpecialInfo; + hidden = max(totalvis - wheight, 0); + topidx = (((ULONG) hidden * pip->VertPot) + (MAXPOT / 2)) >> 16; + } } - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); morc = 0; oidx = -1; @@ -510,671 +476,617 @@ DoMenuScroll( win, blocking, how, retmip ) amip->selected = 0; #endif - DisplayData( win, topidx ); + DisplayData(win, topidx); /* Make the prop gadget the right size and place */ - SetPropInfo( w, gd, wheight, totalvis, topidx ); + SetPropInfo(w, gd, wheight, totalvis, topidx); oldsecs = oldmics = 0; /* If window already up, don't stop to process events */ - if( cw->wasup ) - { - aredone = 1; - cw->wasup = 0; + if (cw->wasup) { + aredone = 1; + cw->wasup = 0; } - while( !aredone ) - { - /* Process window messages */ + while (!aredone) { + /* Process window messages */ - WaitPort( w->UserPort ); - while( imsg = (struct IntuiMessage * ) GetMsg( w->UserPort ) ) - { - class = imsg->Class; - code = imsg->Code; - mics = imsg->Micros; - secs = imsg->Seconds; - gd = (struct Gadget *) imsg->IAddress; - mx = imsg->MouseX; - my = imsg->MouseY; + WaitPort(w->UserPort); + while (imsg = (struct IntuiMessage *) GetMsg(w->UserPort)) { + class = imsg->Class; + code = imsg->Code; + mics = imsg->Micros; + secs = imsg->Seconds; + gd = (struct Gadget *) imsg->IAddress; + mx = imsg->MouseX; + my = imsg->MouseY; - /* Only do our window or VANILLAKEY from other windows */ + /* Only do our window or VANILLAKEY from other windows */ - if( imsg->IDCMPWindow != w && class != VANILLAKEY && - class != RAWKEY ) - { - ReplyMsg( (struct Message *) imsg ); - continue; - } + if (imsg->IDCMPWindow != w && class != VANILLAKEY + && class != RAWKEY) { + ReplyMsg((struct Message *) imsg); + continue; + } - /* Do DeadKeyConvert() stuff if RAWKEY... */ - if( class == RAWKEY ) - { - class = VANILLAKEY; - code = ConvertKey( imsg ); - } - ReplyMsg( (struct Message *) imsg ); + /* Do DeadKeyConvert() stuff if RAWKEY... */ + if (class == RAWKEY) { + class = VANILLAKEY; + code = ConvertKey(imsg); + } + ReplyMsg((struct Message *) imsg); - switch( class ) - { - case NEWSIZE: + switch (class) { + case NEWSIZE: - /* - * Ignore every other newsize, no action needed, - * except RefreshWindowFrame() in case borders got overwritten - * for some reason. It should not happen, but ... - */ + /* + * Ignore every other newsize, no action needed, + * except RefreshWindowFrame() in case borders got overwritten + * for some reason. It should not happen, but ... + */ - if( !dosize ) - { - RefreshWindowFrame(w); - dosize = 1; - break; - } + if (!dosize) { + RefreshWindowFrame(w); + dosize = 1; + break; + } - if( win == WIN_INVEN ) - { - lastinvent.MinX = w->LeftEdge; - lastinvent.MinY = w->TopEdge; - lastinvent.MaxX = w->Width; - lastinvent.MaxY = w->Height; - } - else if( win == WIN_MESSAGE ) - { - lastmsg.MinX = w->LeftEdge; - lastmsg.MinY = w->TopEdge; - lastmsg.MaxX = w->Width; - lastmsg.MaxY = w->Height; - } + if (win == WIN_INVEN) { + lastinvent.MinX = w->LeftEdge; + lastinvent.MinY = w->TopEdge; + lastinvent.MaxX = w->Width; + lastinvent.MaxY = w->Height; + } else if (win == WIN_MESSAGE) { + lastmsg.MinX = w->LeftEdge; + lastmsg.MinY = w->TopEdge; + lastmsg.MaxX = w->Width; + lastmsg.MaxY = w->Height; + } - /* Find the gadget */ + /* Find the gadget */ - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) - panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); - totalvis = CountLines( win ); - wheight = ( w->Height - w->BorderTop - - w->BorderBottom - 2) / txh; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3) / txwd; - } - else - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } + totalvis = CountLines(win); + wheight = + (w->Height - w->BorderTop - w->BorderBottom - 2) / txh; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight + - 4 - pictdata.xsize - 3) / txwd; + } else + cw->cols = (w->Width - w->BorderLeft - w->BorderRight + - 4) / txwd; + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) + / txwd; + } - if( wheight < 2 ) - wheight = 2; + if (wheight < 2) + wheight = 2; - /* - * Clear the right side & bottom. Parts of letters are not erased by - * amii_cl_end if window shrinks and columns decrease. - */ + /* + * Clear the right side & bottom. Parts of letters are not + * erased by + * amii_cl_end if window shrinks and columns decrease. + */ - if ( WINVERS_AMII || WINVERS_AMIV ) { - amii_setfillpens(w, cw->type); - SetDrMd(w->RPort, JAM2); - x2 = w->Width - w->BorderRight; - y2 = w->Height - w->BorderBottom; - x1 = x2 - w->IFont->tf_XSize - w->IFont->tf_XSize; - y1 = w->BorderTop; - if (x1 < w->BorderLeft) - x1 = w->BorderLeft; - RectFill(w->RPort, x1, y1, x2, y2); - x1 = w->BorderLeft; - y1 = y1 - w->IFont->tf_YSize; - RectFill(w->RPort, x1, y1, x2, y2); - RefreshWindowFrame(w); - } + if (WINVERS_AMII || WINVERS_AMIV) { + amii_setfillpens(w, cw->type); + SetDrMd(w->RPort, JAM2); + x2 = w->Width - w->BorderRight; + y2 = w->Height - w->BorderBottom; + x1 = x2 - w->IFont->tf_XSize - w->IFont->tf_XSize; + y1 = w->BorderTop; + if (x1 < w->BorderLeft) + x1 = w->BorderLeft; + RectFill(w->RPort, x1, y1, x2, y2); + x1 = w->BorderLeft; + y1 = y1 - w->IFont->tf_YSize; + RectFill(w->RPort, x1, y1, x2, y2); + RefreshWindowFrame(w); + } - /* Make the prop gadget the right size and place */ + /* Make the prop gadget the right size and place */ - DisplayData( win, topidx ); - SetPropInfo( w, gd, wheight, totalvis, topidx ); + DisplayData(win, topidx); + SetPropInfo(w, gd, wheight, totalvis, topidx); - /* Force the window to a text line boundary <= to - * what the user dragged it to. This eliminates - * having to clean things up on the bottom edge. - */ + /* Force the window to a text line boundary <= to + * what the user dragged it to. This eliminates + * having to clean things up on the bottom edge. + */ - SizeWindow( w, 0, ( wheight * txh) + - w->BorderTop + w->BorderBottom + 2 - w->Height ); + SizeWindow(w, 0, (wheight * txh) + w->BorderTop + + w->BorderBottom + 2 - w->Height); - /* Don't do next NEWSIZE, we caused it */ - dosize = 0; - oldsecs = oldmics = 0; - break; + /* Don't do next NEWSIZE, we caused it */ + dosize = 0; + oldsecs = oldmics = 0; + break; - case VANILLAKEY: -#define CTRL(x) ((x)-'@') - morc = code = map_menu_cmd(code); - if (code == MENU_SELECT_ALL) { - if (how == PICK_ANY) { - amip = cw->menu.items; - while (amip) { - if (amip->canselect && amip->selector) { - /* - * Select those yet unselected - * and apply count if necessary - */ - if (!amip->selected) { - amip->selected = TRUE; - if (counting) { - amip->count = count; - reset_counting = TRUE; - /* - * This makes the assumption that - * the string is in format "X - foo" - * with additional selecting and formatting - * data in front (size SOFF) - */ - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - } - } - amip=amip->next; - } - DisplayData(win, topidx); - } - } else if (code == MENU_UNSELECT_ALL) { - if (how == PICK_ANY) { - amip = cw->menu.items; - while (amip) { - if (amip->selected) { - amip->selected = FALSE; - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - amip=amip->next; - } - DisplayData(win, topidx); - } - } else if (code == MENU_INVERT_ALL) { - if (how == PICK_ANY) { - amip = cw->menu.items; - while (amip) { - if (amip->canselect && amip->selector) { - amip->selected = !amip->selected; - if (counting && amip->selected) { - amip->count = count; - amip->str[SOFF+2] = '#'; - reset_counting = TRUE; - } else { - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - } - amip=amip->next; - } - DisplayData(win, topidx); - } - } else if (code == MENU_SELECT_PAGE) { - if (how == PICK_ANY) { - int i = 0; - amip = cw->menu.items; - while (amip && i++ < topidx) - amip = amip->next; - for (i=0;i < wheight && amip; i++, amip=amip->next) { - if (amip->canselect && amip->selector) { - if (!amip->selected) { - if (counting) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - } - amip->selected = TRUE; - } - } - DisplayData(win, topidx); - } - } else if (code == MENU_UNSELECT_PAGE) { - if (how == PICK_ANY) { - int i = 0; - amip = cw->menu.items; - while (amip && i++ < topidx) - amip = amip->next; - for (i=0;i < wheight && amip; i++, amip=amip->next) { - if (amip->selected) { - amip->selected = FALSE; - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - } - DisplayData(win, topidx); - } - } else if (code == MENU_INVERT_PAGE) { - if (how == PICK_ANY) { - int i = 0; - amip = cw->menu.items; - while (amip && i++ < topidx) - amip = amip->next; - for (i=0;i < wheight && amip; i++, amip=amip->next) { - if (amip->canselect && amip->selector) { - amip->selected = !amip->selected; - if (counting && amip->selected) { - amip->count = count; - amip->str[SOFF+2] = '#'; - reset_counting = TRUE; - } else { - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - } - } - DisplayData(win, topidx); - } - } else if (code == MENU_SEARCH && cw->type == NHW_MENU) { - if (how == PICK_ONE || how == PICK_ANY) { - char buf[BUFSZ]; - amip = cw->menu.items; - amii_getlin("Search for:", buf); - if (!*buf || *buf == '\033') - break; - while (amip) { - if (amip->canselect && amip->selector && amip->str && - strstri(&amip->str[SOFF], buf)) { - if (how == PICK_ONE) { - amip->selected = TRUE; - aredone = 1; - break; - } - amip->selected = !amip->selected; - if (counting && amip->selected) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - reset_counting = TRUE; - amip->str[SOFF+2] = '-'; - } - } - amip = amip->next; - } - } - DisplayData(win, topidx); - } else if (how == PICK_ANY && isdigit(code) && - (counting || (!counting && code !='0'))) { - if (count < LARGEST_INT) { - count = count*10 + (long)(code-'0'); - if (count > LARGEST_INT) - count = LARGEST_INT; - if (count > 0) { - counting = TRUE; - reset_counting = FALSE; - } else { - reset_counting = TRUE; - } - sprintf(countString, "Count: %d", count); - pline(countString); - } - } else if( code == CTRL('D') || code == CTRL('U') || - code == MENU_NEXT_PAGE || code == MENU_PREVIOUS_PAGE || - code == MENU_FIRST_PAGE || code == MENU_LAST_PAGE ) - { - int endcnt, i; + case VANILLAKEY: +#define CTRL(x) ((x) - '@') + morc = code = map_menu_cmd(code); + if (code == MENU_SELECT_ALL) { + if (how == PICK_ANY) { + amip = cw->menu.items; + while (amip) { + if (amip->canselect && amip->selector) { + /* + * Select those yet unselected + * and apply count if necessary + */ + if (!amip->selected) { + amip->selected = TRUE; + if (counting) { + amip->count = count; + reset_counting = TRUE; + /* + * This makes the assumption that + * the string is in format "X - foo" + * with additional selecting and + * formatting + * data in front (size SOFF) + */ + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + } + } + amip = amip->next; + } + DisplayData(win, topidx); + } + } else if (code == MENU_UNSELECT_ALL) { + if (how == PICK_ANY) { + amip = cw->menu.items; + while (amip) { + if (amip->selected) { + amip->selected = FALSE; + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + amip = amip->next; + } + DisplayData(win, topidx); + } + } else if (code == MENU_INVERT_ALL) { + if (how == PICK_ANY) { + amip = cw->menu.items; + while (amip) { + if (amip->canselect && amip->selector) { + amip->selected = !amip->selected; + if (counting && amip->selected) { + amip->count = count; + amip->str[SOFF + 2] = '#'; + reset_counting = TRUE; + } else { + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + } + amip = amip->next; + } + DisplayData(win, topidx); + } + } else if (code == MENU_SELECT_PAGE) { + if (how == PICK_ANY) { + int i = 0; + amip = cw->menu.items; + while (amip && i++ < topidx) + amip = amip->next; + for (i = 0; i < wheight && amip; + i++, amip = amip->next) { + if (amip->canselect && amip->selector) { + if (!amip->selected) { + if (counting) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + } + amip->selected = TRUE; + } + } + DisplayData(win, topidx); + } + } else if (code == MENU_UNSELECT_PAGE) { + if (how == PICK_ANY) { + int i = 0; + amip = cw->menu.items; + while (amip && i++ < topidx) + amip = amip->next; + for (i = 0; i < wheight && amip; + i++, amip = amip->next) { + if (amip->selected) { + amip->selected = FALSE; + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + } + DisplayData(win, topidx); + } + } else if (code == MENU_INVERT_PAGE) { + if (how == PICK_ANY) { + int i = 0; + amip = cw->menu.items; + while (amip && i++ < topidx) + amip = amip->next; + for (i = 0; i < wheight && amip; + i++, amip = amip->next) { + if (amip->canselect && amip->selector) { + amip->selected = !amip->selected; + if (counting && amip->selected) { + amip->count = count; + amip->str[SOFF + 2] = '#'; + reset_counting = TRUE; + } else { + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + } + } + DisplayData(win, topidx); + } + } else if (code == MENU_SEARCH && cw->type == NHW_MENU) { + if (how == PICK_ONE || how == PICK_ANY) { + char buf[BUFSZ]; + amip = cw->menu.items; + amii_getlin("Search for:", buf); + if (!*buf || *buf == '\033') + break; + while (amip) { + if (amip->canselect && amip->selector && amip->str + && strstri(&amip->str[SOFF], buf)) { + if (how == PICK_ONE) { + amip->selected = TRUE; + aredone = 1; + break; + } + amip->selected = !amip->selected; + if (counting && amip->selected) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + reset_counting = TRUE; + amip->str[SOFF + 2] = '-'; + } + } + amip = amip->next; + } + } + DisplayData(win, topidx); + } else if (how == PICK_ANY && isdigit(code) + && (counting || (!counting && code != '0'))) { + if (count < LARGEST_INT) { + count = count * 10 + (long) (code - '0'); + if (count > LARGEST_INT) + count = LARGEST_INT; + if (count > 0) { + counting = TRUE; + reset_counting = FALSE; + } else { + reset_counting = TRUE; + } + sprintf(countString, "Count: %d", count); + pline(countString); + } + } else if (code == CTRL('D') || code == CTRL('U') + || code == MENU_NEXT_PAGE + || code == MENU_PREVIOUS_PAGE + || code == MENU_FIRST_PAGE + || code == MENU_LAST_PAGE) { + int endcnt, i; - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) - panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); - endcnt = wheight; /* /2; */ - if( endcnt == 0 ) - endcnt = 1; + endcnt = wheight; /* /2; */ + if (endcnt == 0) + endcnt = 1; - if (code == MENU_FIRST_PAGE) { - topidx = 0; - } else if (code == MENU_LAST_PAGE) { - topidx = cw->maxrow - wheight; - } else for( i = 0; i < endcnt; ++i ) - { - if (code == CTRL('D') || code == MENU_NEXT_PAGE) - { - if( topidx + wheight < cw->maxrow ) - ++topidx; - else - break; - } - else if (code = CTRL('U') || code == MENU_PREVIOUS_PAGE) - { - if( topidx > 0 ) - --topidx; - else - break; - } - } - /* Make prop gadget the right size and place */ + if (code == MENU_FIRST_PAGE) { + topidx = 0; + } else if (code == MENU_LAST_PAGE) { + topidx = cw->maxrow - wheight; + } else + for (i = 0; i < endcnt; ++i) { + if (code == CTRL('D') || code == MENU_NEXT_PAGE) { + if (topidx + wheight < cw->maxrow) + ++topidx; + else + break; + } else if (code = CTRL('U') + || code == MENU_PREVIOUS_PAGE) { + if (topidx > 0) + --topidx; + else + break; + } + } + /* Make prop gadget the right size and place */ - DisplayData( win, topidx ); - SetPropInfo( w,gd, wheight, totalvis, topidx ); - oldsecs = oldmics = 0; - } - else if( code == '\b' ) - { - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + DisplayData(win, topidx); + SetPropInfo(w, gd, wheight, totalvis, topidx); + oldsecs = oldmics = 0; + } else if (code == '\b') { + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) - panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); - if( topidx - wheight - 2 < 0 ) - { - topidx = 0; - } - else - { - topidx -= wheight - 2; - } - DisplayData( win, topidx ); - SetPropInfo( w, gd, wheight, totalvis, topidx ); - oldsecs = oldmics = 0; - } - else if( code == ' ' ) - { - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + if (topidx - wheight - 2 < 0) { + topidx = 0; + } else { + topidx -= wheight - 2; + } + DisplayData(win, topidx); + SetPropInfo(w, gd, wheight, totalvis, topidx); + oldsecs = oldmics = 0; + } else if (code == ' ') { + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) - panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); - if( topidx + wheight >= cw->maxrow ) - { - morc = 0; - aredone = 1; - } - else - { - /* If there are still lines to be seen */ + if (topidx + wheight >= cw->maxrow) { + morc = 0; + aredone = 1; + } else { + /* If there are still lines to be seen */ - if( cw->maxrow > topidx + wheight ) - { - if( wheight > 2 ) - topidx += wheight - 2; - else - ++topidx; - DisplayData( win, topidx ); - SetPropInfo( w, gd, wheight, - totalvis, topidx ); - } - oldsecs = oldmics = 0; - } - } - else if( code == '\n' || code == '\r' ) - { - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + if (cw->maxrow > topidx + wheight) { + if (wheight > 2) + topidx += wheight - 2; + else + ++topidx; + DisplayData(win, topidx); + SetPropInfo(w, gd, wheight, totalvis, topidx); + } + oldsecs = oldmics = 0; + } + } else if (code == '\n' || code == '\r') { + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( !gd ) - panic("Can't find scroll gadget" ); + if (!gd) + panic("Can't find scroll gadget"); - /* If all line displayed, we are done */ + /* If all line displayed, we are done */ - if( topidx + wheight >= cw->maxrow ) - { - morc = 0; - aredone = 1; - } - else - { - /* If there are still lines to be seen */ + if (topidx + wheight >= cw->maxrow) { + morc = 0; + aredone = 1; + } else { + /* If there are still lines to be seen */ - if( cw->maxrow > topidx + 1 ) - { - ++topidx; - DisplayData( win, topidx ); - SetPropInfo( w, gd, wheight, - totalvis, topidx ); - } - oldsecs = oldmics = 0; - } - } - else if( code == '\33' ) - { - if (counting) { - reset_counting = TRUE; - } else { - aredone = 1; - } - } - else - { - int selected = FALSE; - for( amip = cw->menu.items; amip; amip = amip->next ) - { - if( amip->selector == code ) - { - if( how == PICK_ONE ) - aredone = 1; - amip->selected = !amip->selected; - if (counting && amip->selected) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - reset_counting = TRUE; - amip->str[SOFF+2] = '-'; - } - selected = TRUE; - } else if (amip->gselector == code ) - { - amip->selected = !amip->selected; - if (counting) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - reset_counting = TRUE; - amip->str[SOFF+2] = '-'; - } - selected = TRUE; - } - } - if (selected) - DisplayData( win, topidx ); - } - break; + if (cw->maxrow > topidx + 1) { + ++topidx; + DisplayData(win, topidx); + SetPropInfo(w, gd, wheight, totalvis, topidx); + } + oldsecs = oldmics = 0; + } + } else if (code == '\33') { + if (counting) { + reset_counting = TRUE; + } else { + aredone = 1; + } + } else { + int selected = FALSE; + for (amip = cw->menu.items; amip; amip = amip->next) { + if (amip->selector == code) { + if (how == PICK_ONE) + aredone = 1; + amip->selected = !amip->selected; + if (counting && amip->selected) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + reset_counting = TRUE; + amip->str[SOFF + 2] = '-'; + } + selected = TRUE; + } else if (amip->gselector == code) { + amip->selected = !amip->selected; + if (counting) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + reset_counting = TRUE; + amip->str[SOFF + 2] = '-'; + } + selected = TRUE; + } + } + if (selected) + DisplayData(win, topidx); + } + break; - case CLOSEWINDOW: - if( win == WIN_INVEN ) - { - lastinvent.MinX = w->LeftEdge; - lastinvent.MinY = w->TopEdge; - lastinvent.MaxX = w->Width; - lastinvent.MaxY = w->Height; - } - else if( win == WIN_MESSAGE ) - { - lastmsg.MinX = w->LeftEdge; - lastmsg.MinY = w->TopEdge; - lastmsg.MaxX = w->Width; - lastmsg.MaxY = w->Height; - } - aredone = 1; - morc = '\33'; - break; + case CLOSEWINDOW: + if (win == WIN_INVEN) { + lastinvent.MinX = w->LeftEdge; + lastinvent.MinY = w->TopEdge; + lastinvent.MaxX = w->Width; + lastinvent.MaxY = w->Height; + } else if (win == WIN_MESSAGE) { + lastmsg.MinX = w->LeftEdge; + lastmsg.MinY = w->TopEdge; + lastmsg.MaxX = w->Width; + lastmsg.MaxY = w->Height; + } + aredone = 1; + morc = '\33'; + break; - case GADGETUP: - if( win == WIN_MESSAGE ) - aredone = 1; - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + case GADGETUP: + if (win == WIN_MESSAGE) + aredone = 1; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - pip = (struct PropInfo *)gd->SpecialInfo; - totalvis = CountLines( win ); - hidden = max( totalvis - wheight, 0 ); - aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16; - if( aidx != topidx ) - DisplayData( win, topidx = aidx ); - break; + pip = (struct PropInfo *) gd->SpecialInfo; + totalvis = CountLines(win); + hidden = max(totalvis - wheight, 0); + aidx = (((ULONG) hidden * pip->VertPot) + (MAXPOT / 2)) >> 16; + if (aidx != topidx) + DisplayData(win, topidx = aidx); + break; - case MOUSEMOVE: - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + case MOUSEMOVE: + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - pip = (struct PropInfo *)gd->SpecialInfo; - totalvis = CountLines( win ); - hidden = max( totalvis - wheight, 0 ); - aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16; - if( aidx != topidx ) - DisplayData( win, topidx = aidx ); - break; + pip = (struct PropInfo *) gd->SpecialInfo; + totalvis = CountLines(win); + hidden = max(totalvis - wheight, 0); + aidx = (((ULONG) hidden * pip->VertPot) + (MAXPOT / 2)) >> 16; + if (aidx != topidx) + DisplayData(win, topidx = aidx); + break; - case INACTIVEWINDOW: - if( win == WIN_MESSAGE || ( win == WIN_INVEN && alwaysinvent ) ) - aredone = 1; - break; + case INACTIVEWINDOW: + if (win == WIN_MESSAGE || (win == WIN_INVEN && alwaysinvent)) + aredone = 1; + break; - case MOUSEBUTTONS: - if( ( code == SELECTUP || code == SELECTDOWN ) && - cw->type == NHW_MENU && how != PICK_NONE ) - { - /* Which one is the mouse pointing at? */ + case MOUSEBUTTONS: + if ((code == SELECTUP || code == SELECTDOWN) + && cw->type == NHW_MENU && how != PICK_NONE) { + /* Which one is the mouse pointing at? */ - aidx = ( ( my - w->BorderTop - 1 ) / txh ) + topidx; + aidx = ((my - w->BorderTop - 1) / txh) + topidx; - /* If different lines, don't select double click */ + /* If different lines, don't select double click */ - if( aidx != oidx ) - { - oldsecs = 0; - oldmics = 0; - } + if (aidx != oidx) { + oldsecs = 0; + oldmics = 0; + } - /* If releasing, check for double click */ + /* If releasing, check for double click */ - if( code == SELECTUP ) - { - amip = find_menu_item( cw, aidx ); - if( aidx == oidx ) - { - if( DoubleClick( oldsecs, - oldmics, secs, mics ) ) - { - aredone = 1; - } - oldsecs = secs; - oldmics = mics; - } - else - { - amip = find_menu_item( cw, oidx ); - amip->selected = 0; - amip->count = -1; - reset_counting = TRUE; - if (amip->canselect && amip->selector) - amip->str[SOFF+2] = '-'; - } - if (counting && amip->selected && amip->canselect && amip->selector) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } - DisplayData( win, topidx ); - } - else if( aidx - topidx < wheight && - aidx < cw->maxrow && code == SELECTDOWN ) - { - /* Remove old highlighting if visible */ + if (code == SELECTUP) { + amip = find_menu_item(cw, aidx); + if (aidx == oidx) { + if (DoubleClick(oldsecs, oldmics, secs, mics)) { + aredone = 1; + } + oldsecs = secs; + oldmics = mics; + } else { + amip = find_menu_item(cw, oidx); + amip->selected = 0; + amip->count = -1; + reset_counting = TRUE; + if (amip->canselect && amip->selector) + amip->str[SOFF + 2] = '-'; + } + if (counting && amip->selected && amip->canselect + && amip->selector) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } + DisplayData(win, topidx); + } else if (aidx - topidx < wheight && aidx < cw->maxrow + && code == SELECTDOWN) { + /* Remove old highlighting if visible */ - amip = find_menu_item( cw, oidx ); - if( amip && oidx != aidx && - ( oidx > topidx && oidx - topidx < wheight ) ) - { - if( how != PICK_ANY ) { - amip->selected = 0; - amip->count = -1; - reset_counting = TRUE; - if (amip->canselect && amip->selector) - amip->str[SOFF+2] = '-'; - } - oidx = -1; - } - amip = find_menu_item( cw, aidx ); + amip = find_menu_item(cw, oidx); + if (amip && oidx != aidx + && (oidx > topidx && oidx - topidx < wheight)) { + if (how != PICK_ANY) { + amip->selected = 0; + amip->count = -1; + reset_counting = TRUE; + if (amip->canselect && amip->selector) + amip->str[SOFF + 2] = '-'; + } + oidx = -1; + } + amip = find_menu_item(cw, aidx); - if( amip && amip->canselect && amip->selector && how != PICK_NONE ) - { - oidx = aidx; - if( !DoubleClick( oldsecs, - oldmics, secs, mics ) ) - { - amip->selected = !amip->selected; - if (counting && amip->selected) { - amip->count = count; - reset_counting = TRUE; - amip->str[SOFF+2] = '#'; - } else { - amip->count = -1; - reset_counting = TRUE; - if (amip->canselect && amip->selector) - amip->str[SOFF+2] = '-'; - } - } - } - else - { - DisplayBeep( NULL ); - oldsecs = 0; - oldmics = 0; - } - DisplayData( win, topidx ); - } - } - else - { - DisplayBeep( NULL ); - } - break; - } - if (!counting && morc == '\33') { - amip = cw->menu.items; - while (amip) { - if (amip->canselect && amip->selector) { - amip->selected = FALSE; - amip->count = -1; - amip->str[SOFF+2] = '-'; - } - amip=amip->next; - } - } - if (reset_counting) { - count = 0; - if (counting) - pline("Count: 0"); - counting = FALSE; - } - } + if (amip && amip->canselect && amip->selector + && how != PICK_NONE) { + oidx = aidx; + if (!DoubleClick(oldsecs, oldmics, secs, mics)) { + amip->selected = !amip->selected; + if (counting && amip->selected) { + amip->count = count; + reset_counting = TRUE; + amip->str[SOFF + 2] = '#'; + } else { + amip->count = -1; + reset_counting = TRUE; + if (amip->canselect && amip->selector) + amip->str[SOFF + 2] = '-'; + } + } + } else { + DisplayBeep(NULL); + oldsecs = 0; + oldmics = 0; + } + DisplayData(win, topidx); + } + } else { + DisplayBeep(NULL); + } + break; + } + if (!counting && morc == '\33') { + amip = cw->menu.items; + while (amip) { + if (amip->canselect && amip->selector) { + amip->selected = FALSE; + amip->count = -1; + amip->str[SOFF + 2] = '-'; + } + amip = amip->next; + } + } + if (reset_counting) { + count = 0; + if (counting) + pline("Count: 0"); + counting = FALSE; + } + } } /* Force a cursor reposition before next message output */ - if( win == WIN_MESSAGE ) - cw->curx = -1; - return( make_menu_items( cw, retmip ) ); + if (win == WIN_MESSAGE) + cw->curx = -1; + return (make_menu_items(cw, retmip)); } void -ReDisplayData( win ) - winid win; +ReDisplayData(win) +winid win; { int totalvis; register struct amii_WinDesc *cw; @@ -1182,30 +1094,31 @@ ReDisplayData( win ) register struct Gadget *gd; unsigned long hidden, aidx, wheight; struct PropInfo *pip; - - if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) ) - return; - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + if (win == WIN_ERR || !(cw = amii_wins[win]) || !(w = cw->win)) + return; - if( !gd ) - return; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - wheight = (w->Height - w->BorderTop - w->BorderBottom-2)/w->RPort->TxHeight; + if (!gd) + return; - pip = (struct PropInfo *)gd->SpecialInfo; - totalvis = CountLines( win ); - hidden = max( totalvis - wheight, 0 ); - aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16; - clear_nhwindow( win ); - DisplayData( win, aidx ); + wheight = + (w->Height - w->BorderTop - w->BorderBottom - 2) / w->RPort->TxHeight; + + pip = (struct PropInfo *) gd->SpecialInfo; + totalvis = CountLines(win); + hidden = max(totalvis - wheight, 0); + aidx = (((ULONG) hidden * pip->VertPot) + (MAXPOT / 2)) >> 16; + clear_nhwindow(win); + DisplayData(win, aidx); } long -FindLine( win, line ) - winid win; - int line; +FindLine(win, line) +winid win; +int line; { int txwd; register char *t; @@ -1214,70 +1127,60 @@ FindLine( win, line ) register int i, disprow, len; int col = -1; - if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) ) - { - panic( winpanicstr, win, "No Window in FindLine" ); + if (win == WIN_ERR || !(cw = amii_wins[win]) || !(w = cw->win)) { + panic(winpanicstr, win, "No Window in FindLine"); } txwd = w->RPort->TxWidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3) / txwd; - } - else - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4 + - pictdata.xsize - 3) / txwd; + } else + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; } disprow = 0; - for( col = i = 0; line > disprow && i < cw->maxrow; ++i ) - { - t = cw->data[ i ] + SOFF; - if( cw->data[i][1] >= 0 ) - { - ++disprow; - col = 0; - } + for (col = i = 0; line > disprow && i < cw->maxrow; ++i) { + t = cw->data[i] + SOFF; + if (cw->data[i][1] >= 0) { + ++disprow; + col = 0; + } - while( *t ) - { - len = strlen( t ); - if( col + len > cw->cols ) - len = cw->cols - col; - while( len > 0 ) - { - if( !t[len] || t[len] == ' ' ) - break; - --len; - } - if( len == 0 ) { - while ( *t && *t != ' ') { - t++; col++; - } - } else { - t += len; - col += len; - } - if( *t ) - { - while( *t == ' ' ) - ++t; - col = 0; - ++disprow; - } - } + while (*t) { + len = strlen(t); + if (col + len > cw->cols) + len = cw->cols - col; + while (len > 0) { + if (!t[len] || t[len] == ' ') + break; + --len; + } + if (len == 0) { + while (*t && *t != ' ') { + t++; + col++; + } + } else { + t += len; + col += len; + } + if (*t) { + while (*t == ' ') + ++t; + col = 0; + ++disprow; + } + } } - return( i ); + return (i); } long -CountLines( win ) - winid win; +CountLines(win) +winid win; { int txwd; amii_menu_item *mip; @@ -1287,71 +1190,62 @@ CountLines( win ) register int i, disprow, len; int col = -1; - if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) ) - { - panic( winpanicstr, win, "No Window in CountLines" ); + if (win == WIN_ERR || !(cw = amii_wins[win]) || !(w = cw->win)) { + panic(winpanicstr, win, "No Window in CountLines"); } txwd = w->RPort->TxWidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3) / txwd; - } - else - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4 + - pictdata.xsize - 3) / txwd; + } else + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; } disprow = cw->maxrow; mip = cw->menu.items; - for( col = i = 0; i < cw->maxrow; ++i ) - { - t = cw->data[ i ] + SOFF; - if( cw->type == NHW_MESSAGE && cw->data[ i ][ SEL_ITEM ] < 0 ) - --disprow; - else - col = 0; - while( *t ) - { - len = strlen( t ); - if( col + len > cw->cols ) - len = cw->cols - col; - while( len > 0 ) - { - if( !t[len] || t[len] == ' ' ) - break; - --len; - } - if( len == 0 ) { - while ( *t && *t != ' ') { - t++; col++; - } - } else { - t += len; - col += len; - } - if( *t ) - { - while( *t == ' ' ) - ++t; - col = 0; - ++disprow; - } - } + for (col = i = 0; i < cw->maxrow; ++i) { + t = cw->data[i] + SOFF; + if (cw->type == NHW_MESSAGE && cw->data[i][SEL_ITEM] < 0) + --disprow; + else + col = 0; + while (*t) { + len = strlen(t); + if (col + len > cw->cols) + len = cw->cols - col; + while (len > 0) { + if (!t[len] || t[len] == ' ') + break; + --len; + } + if (len == 0) { + while (*t && *t != ' ') { + t++; + col++; + } + } else { + t += len; + col += len; + } + if (*t) { + while (*t == ' ') + ++t; + col = 0; + ++disprow; + } + } } - return( disprow ); + return (disprow); } void -DisplayData( win, start ) - winid win; - int start; +DisplayData(win, start) +winid win; +int start; { int txwd; amii_menu_item *mip; @@ -1363,237 +1257,204 @@ DisplayData( win, start ) int whichcolor = -1; int col; - if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) ) - { - panic( winpanicstr, win, "No Window in DisplayData" ); + if (win == WIN_ERR || !(cw = amii_wins[win]) || !(w = cw->win)) { + panic(winpanicstr, win, "No Window in DisplayData"); } rp = w->RPort; - SetDrMd( rp, JAM2 ); - if( WINVERS_AMIV && win == WIN_INVEN ) - { - wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / - max( rp->TxHeight, pictdata.ysize + 3 ); - } - else - { - wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / - rp->TxHeight; + SetDrMd(rp, JAM2); + if (WINVERS_AMIV && win == WIN_INVEN) { + wheight = (w->Height - w->BorderTop - w->BorderBottom - 2) + / max(rp->TxHeight, pictdata.ysize + 3); + } else { + wheight = + (w->Height - w->BorderTop - w->BorderBottom - 2) / rp->TxHeight; } cw->rows = wheight; txwd = rp->TxWidth; - if( WINVERS_AMIV ) - { - if( win == WIN_INVEN ) - { - cw->cols = ( w->Width - w->BorderLeft - - w->BorderRight - 4 - pictdata.xsize - 3) / txwd; - } - else - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; - } - else - { - cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd; + if (WINVERS_AMIV) { + if (win == WIN_INVEN) { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4 + - pictdata.xsize - 3) / txwd; + } else + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; + } else { + cw->cols = (w->Width - w->BorderLeft - w->BorderRight - 4) / txwd; } /* Get the real line to display at */ - start = FindLine( win, start ); + start = FindLine(win, start); mip = cw->menu.items; - for( i = 0; mip && i < start; ++i ) - { - mip = mip->next; + for (i = 0; mip && i < start; ++i) { + mip = mip->next; } /* Skip any initial response to a previous line */ - if( cw->type == NHW_MESSAGE && mip && mip->selected < 0 ) - ++start; - if( WINVERS_AMIV && cw->type == NHW_MESSAGE ) - SetAPen( rp, amii_msgAPen ); - - for( disprow = i = start; disprow < wheight + start; i++ ) - { - /* Just erase unused lines in the window */ - if( i >= cw->maxrow ) - { - if (WINVERS_AMIV && win == WIN_INVEN) { - amii_curs( win, 0, disprow - start ); - amiga_print_glyph( win, 0, NO_GLYPH); - } - amii_curs( win, 1, disprow - start ); - amii_cl_end( cw, 0 ); - ++disprow; - continue; - } + if (cw->type == NHW_MESSAGE && mip && mip->selected < 0) + ++start; + if (WINVERS_AMIV && cw->type == NHW_MESSAGE) + SetAPen(rp, amii_msgAPen); - /* Any string with a highlighted attribute goes - * onto the end of the current line in the message window. - */ - if( cw->type == NHW_MESSAGE ) - SetAPen( rp, cw->data[ i ][ SEL_ITEM ] < 0 ? C_RED : amii_msgAPen ); + for (disprow = i = start; disprow < wheight + start; i++) { + /* Just erase unused lines in the window */ + if (i >= cw->maxrow) { + if (WINVERS_AMIV && win == WIN_INVEN) { + amii_curs(win, 0, disprow - start); + amiga_print_glyph(win, 0, NO_GLYPH); + } + amii_curs(win, 1, disprow - start); + amii_cl_end(cw, 0); + ++disprow; + continue; + } - /* Selected text in the message window goes onto the end of the current line */ - if( cw->type != NHW_MESSAGE || cw->data[ i ][ SEL_ITEM ] >= 0 ) - { - amii_curs( win, 1, disprow - start ); - if( WINVERS_AMIV && win == WIN_INVEN ) - { - if( mip ) - amiga_print_glyph( win, 0, mip->glyph ); - amii_curs( win, 1, disprow - start ); - } - col = 0; - } + /* Any string with a highlighted attribute goes + * onto the end of the current line in the message window. + */ + if (cw->type == NHW_MESSAGE) + SetAPen(rp, cw->data[i][SEL_ITEM] < 0 ? C_RED : amii_msgAPen); - /* If this entry is to be highlighted, do so */ - if( mip && mip->selected != 0 ) - { - if( whichcolor != 1 ) - { - SetDrMd( rp, JAM2 ); - if( WINVERS_AMIV ) - { - SetAPen( rp, amii_menuBPen ); - SetBPen( rp, C_BLUE ); - } - else - { - SetAPen( rp, C_BLUE ); - SetBPen( rp, amii_menuAPen ); - } - whichcolor = 1; - } - } - else if( whichcolor != 2 ) - { - SetDrMd( rp, JAM2 ); - if( cw->type == NHW_MESSAGE ) - { - SetAPen( rp, amii_msgAPen ); - SetBPen( rp, amii_msgBPen ); - } - else if( cw->type == NHW_MENU ) - { - SetAPen( rp, amii_menuAPen ); - SetBPen( rp, amii_menuBPen ); - } - else if( cw->type == NHW_TEXT ) - { - SetAPen( rp, amii_textAPen ); - SetBPen( rp, amii_textBPen ); - } - whichcolor = 2; - } + /* Selected text in the message window goes onto the end of the + * current line */ + if (cw->type != NHW_MESSAGE || cw->data[i][SEL_ITEM] >= 0) { + amii_curs(win, 1, disprow - start); + if (WINVERS_AMIV && win == WIN_INVEN) { + if (mip) + amiga_print_glyph(win, 0, mip->glyph); + amii_curs(win, 1, disprow - start); + } + col = 0; + } - /* Next line out, wrap if too long */ + /* If this entry is to be highlighted, do so */ + if (mip && mip->selected != 0) { + if (whichcolor != 1) { + SetDrMd(rp, JAM2); + if (WINVERS_AMIV) { + SetAPen(rp, amii_menuBPen); + SetBPen(rp, C_BLUE); + } else { + SetAPen(rp, C_BLUE); + SetBPen(rp, amii_menuAPen); + } + whichcolor = 1; + } + } else if (whichcolor != 2) { + SetDrMd(rp, JAM2); + if (cw->type == NHW_MESSAGE) { + SetAPen(rp, amii_msgAPen); + SetBPen(rp, amii_msgBPen); + } else if (cw->type == NHW_MENU) { + SetAPen(rp, amii_menuAPen); + SetBPen(rp, amii_menuBPen); + } else if (cw->type == NHW_TEXT) { + SetAPen(rp, amii_textAPen); + SetBPen(rp, amii_textBPen); + } + whichcolor = 2; + } - t = cw->data[ i ] + SOFF; - ++disprow; - col = 0; - while( *t ) - { - len = strlen( t ); - if( len > (cw->cols - col) ) - len = cw->cols - col; - while( len > 0 ) - { - if( !t[len] || t[len] == ' ' ) - break; - --len; - } - if( len == 0 ) { - Text( rp, t, cw->cols - col ); - while ( *t && *t != ' ') { - t++; col++; - } - } else { - Text( rp, t, len ); - t += len; - col += len; - } - amii_cl_end( cw, col ); - if( *t ) - { - ++disprow; - /* Stop at the bottom of the window */ - if( disprow > wheight + start ) - break; - while( *t == ' ' ) - ++t; - amii_curs( win, 1, disprow - start - 1 ); - if( mip && win == WIN_INVEN && WINVERS_AMIV ) - { - /* Erase any previous glyph drawn here. */ - amiga_print_glyph( win, 0, NO_GLYPH ); - amii_curs( win, 1, disprow - start - 1 ); - } - Text( rp, "+", 1 ); - col = 1; - } - } + /* Next line out, wrap if too long */ - if( cw->type == NHW_MESSAGE ) - { - SetAPen( rp, amii_msgBPen ); - SetBPen( rp, amii_msgBPen ); - } - else if( cw->type == NHW_MENU ) - { - SetAPen( rp, amii_menuBPen ); - SetBPen( rp, amii_menuBPen ); - } - else if( cw->type == NHW_TEXT ) - { - SetAPen( rp, amii_textBPen ); - SetBPen( rp, amii_textBPen ); - } - amii_cl_end( cw, col ); - whichcolor = -1; - if( mip ) mip = mip->next; + t = cw->data[i] + SOFF; + ++disprow; + col = 0; + while (*t) { + len = strlen(t); + if (len > (cw->cols - col)) + len = cw->cols - col; + while (len > 0) { + if (!t[len] || t[len] == ' ') + break; + --len; + } + if (len == 0) { + Text(rp, t, cw->cols - col); + while (*t && *t != ' ') { + t++; + col++; + } + } else { + Text(rp, t, len); + t += len; + col += len; + } + amii_cl_end(cw, col); + if (*t) { + ++disprow; + /* Stop at the bottom of the window */ + if (disprow > wheight + start) + break; + while (*t == ' ') + ++t; + amii_curs(win, 1, disprow - start - 1); + if (mip && win == WIN_INVEN && WINVERS_AMIV) { + /* Erase any previous glyph drawn here. */ + amiga_print_glyph(win, 0, NO_GLYPH); + amii_curs(win, 1, disprow - start - 1); + } + Text(rp, "+", 1); + col = 1; + } + } + + if (cw->type == NHW_MESSAGE) { + SetAPen(rp, amii_msgBPen); + SetBPen(rp, amii_msgBPen); + } else if (cw->type == NHW_MENU) { + SetAPen(rp, amii_menuBPen); + SetBPen(rp, amii_menuBPen); + } else if (cw->type == NHW_TEXT) { + SetAPen(rp, amii_textBPen); + SetBPen(rp, amii_textBPen); + } + amii_cl_end(cw, col); + whichcolor = -1; + if (mip) + mip = mip->next; } RefreshWindowFrame(w); return; } -void SetPropInfo( win, gad, vis, total, top ) - register struct Window *win; - register struct Gadget *gad; - register long vis, total, top; +void +SetPropInfo(win, gad, vis, total, top) +register struct Window *win; +register struct Gadget *gad; +register long vis, total, top; { long mflags; register long hidden; register int body, pot; - hidden = max( total-vis, 0 ); + hidden = max(total - vis, 0); /* Force the last section to be just to the bottom */ - if( top > hidden ) - top = hidden; + if (top > hidden) + top = hidden; /* Scale the body position. */ /* 2 lines overlap */ - if( hidden > 0 && total > 2) - body = (ULONG) ((vis - 2) * MAXBODY) / (total - 2); + if (hidden > 0 && total > 2) + body = (ULONG)((vis - 2) * MAXBODY) / (total - 2); else - body = MAXBODY; + body = MAXBODY; - if( hidden > 0 ) - pot = (ULONG) (top * MAXPOT) / hidden; + if (hidden > 0) + pot = (ULONG)(top * MAXPOT) / hidden; else - pot = 0; + pot = 0; - mflags = AUTOKNOB|FREEVERT; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - mflags |= PROPNEWLOOK; + mflags = AUTOKNOB | FREEVERT; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + mflags |= PROPNEWLOOK; } #endif - NewModifyProp( gad, win, NULL, - mflags, 0, pot, MAXBODY, body, 1 ); + NewModifyProp(gad, win, NULL, mflags, 0, pot, MAXBODY, body, 1); } diff --git a/sys/amiga/winreq.c b/sys/amiga/winreq.c index bebfac482..49d472b9c 100644 --- a/sys/amiga/winreq.c +++ b/sys/amiga/winreq.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winreq.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winreq.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 winreq.c $Date: 2009/05/06 10:48:41 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)winreq.c 3.5 1993/04/02 */ /* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993. */ @@ -8,56 +8,54 @@ #include "NH:sys/amiga/winext.h" #include "NH:sys/amiga/winproto.h" -#define GADBLUEPEN 2 -#define GADREDPEN 3 -#define GADGREENPEN 4 -#define GADCOLOKAY 5 -#define GADCOLCANCEL 6 -#define GADCOLSAVE 7 +#define GADBLUEPEN 2 +#define GADREDPEN 3 +#define GADGREENPEN 4 +#define GADCOLOKAY 5 +#define GADCOLCANCEL 6 +#define GADCOLSAVE 7 UBYTE UNDOBUFFER[300]; -SHORT BorderVectors1[] = { 0,0, 57,0, 57,11, 0,11, 0,0 }; -struct Border Border1 = { -1,-1, 3,0,JAM1, 5, BorderVectors1, NULL }; -struct IntuiText IText1 = { 3,0,JAM1, 4,1, NULL, (UBYTE *)"Cancel", NULL }; -struct Gadget Gadget2 = { - NULL, 9,15, 56,10, NULL, RELVERIFY, BOOLGADGET, (APTR)&Border1, - NULL, &IText1, NULL, NULL, 1, NULL -}; +SHORT BorderVectors1[] = { 0, 0, 57, 0, 57, 11, 0, 11, 0, 0 }; +struct Border Border1 = { -1, -1, 3, 0, JAM1, 5, BorderVectors1, NULL }; +struct IntuiText IText1 = { 3, 0, JAM1, 4, 1, NULL, (UBYTE *) "Cancel", + NULL }; +struct Gadget Gadget2 = { NULL, 9, 15, 56, 10, NULL, RELVERIFY, BOOLGADGET, + (APTR) &Border1, NULL, &IText1, NULL, NULL, 1, + NULL }; UBYTE StrStringSIBuff[300]; -struct StringInfo StrStringSInfo = { - StrStringSIBuff, UNDOBUFFER, 0, 300, 0, 0,0,0,0,0, 0, 0, NULL -}; -SHORT BorderVectors2[] = { 0,0, 439,0, 439,11, 0,11, 0,0 }; -struct Border Border2 = { -1,-1, 3,0,JAM1, 5, BorderVectors2, NULL }; -struct Gadget String = { - &Gadget2, 77,15, 438,10, NULL, RELVERIFY+STRINGCENTER, STRGADGET, - (APTR)&Border2, NULL, NULL, NULL, (APTR)&StrStringSInfo, 2, NULL -}; +struct StringInfo StrStringSInfo = { StrStringSIBuff, UNDOBUFFER, 0, 300, 0, + 0, 0, 0, 0, 0, 0, 0, NULL }; +SHORT BorderVectors2[] = { 0, 0, 439, 0, 439, 11, 0, 11, 0, 0 }; +struct Border Border2 = { -1, -1, 3, 0, JAM1, 5, BorderVectors2, NULL }; +struct Gadget String = { &Gadget2, 77, 15, 438, 10, NULL, + RELVERIFY + STRINGCENTER, STRGADGET, (APTR) &Border2, + NULL, NULL, NULL, (APTR) &StrStringSInfo, 2, NULL }; #define StrString \ - ((char *)(((struct StringInfo *)(String.SpecialInfo))->Buffer)) + ((char *) (((struct StringInfo *) (String.SpecialInfo))->Buffer)) struct NewWindow StrWindow = { - 57,74, 526,31, 0,1, GADGETUP+CLOSEWINDOW+ACTIVEWINDOW+VANILLAKEY, - WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, - &String, NULL, NULL, NULL, NULL, 5,5, 0xffff,0xffff, CUSTOMSCREEN + 57, 74, 526, 31, 0, 1, GADGETUP + CLOSEWINDOW + ACTIVEWINDOW + VANILLAKEY, + WINDOWDRAG + WINDOWDEPTH + WINDOWCLOSE + ACTIVATE + NOCAREREFRESH, + &String, NULL, NULL, NULL, NULL, 5, 5, 0xffff, 0xffff, CUSTOMSCREEN }; #include "NH:sys/amiga/colorwin.c" -#define XSIZE 2 -#define YSIZE 3 -#define XCLIP 4 -#define YCLIP 5 -#define GADOKAY 6 -#define GADCANCEL 7 +#define XSIZE 2 +#define YSIZE 3 +#define XCLIP 4 +#define YCLIP 5 +#define GADOKAY 6 +#define GADCANCEL 7 #include "NH:sys/amiga/clipwin.c" -void ClearCol( struct Window *w ); +void ClearCol(struct Window *w); void -EditColor( ) +EditColor() { extern const char *configfile; int i, done = 0, okay = 0; @@ -71,323 +69,279 @@ EditColor( ) int msx, msy; int curcol = 0, drag = 0; int bxorx, bxory, bxxlen, bxylen; - static UWORD colors[ AMII_MAXCOLORS ]; - static UWORD svcolors[ AMII_MAXCOLORS ]; + static UWORD colors[AMII_MAXCOLORS]; + static UWORD svcolors[AMII_MAXCOLORS]; static int once = 0; scrn = HackScreen; - if( !once ) - { - if( WINVERS_AMIV ) - { - Col_NewWindowStructure1.Width += 300; - Col_NewWindowStructure1.Height += 20; - Col_NewWindowStructure1.LeftEdge -= 150; - Col_BluePen.Width += 300; - Col_RedPen.Width += 300; - Col_GreenPen.Width += 300; - Col_Cancel.LeftEdge += 300; - Col_Okay.LeftEdge += 150; - Col_Cancel.TopEdge += 20; - Col_Save.TopEdge += 20; - Col_Okay.TopEdge += 20; - } - SetBorder( &Col_Okay ); - SetBorder( &Col_Cancel ); - SetBorder( &Col_Save ); - once = 1; + if (!once) { + if (WINVERS_AMIV) { + Col_NewWindowStructure1.Width += 300; + Col_NewWindowStructure1.Height += 20; + Col_NewWindowStructure1.LeftEdge -= 150; + Col_BluePen.Width += 300; + Col_RedPen.Width += 300; + Col_GreenPen.Width += 300; + Col_Cancel.LeftEdge += 300; + Col_Okay.LeftEdge += 150; + Col_Cancel.TopEdge += 20; + Col_Save.TopEdge += 20; + Col_Okay.TopEdge += 20; + } + SetBorder(&Col_Okay); + SetBorder(&Col_Cancel); + SetBorder(&Col_Save); + once = 1; } - bxylen = Col_NewWindowStructure1.Height - - ( Col_BluePen.TopEdge + Col_BluePen.Height + 6 ); + bxylen = Col_NewWindowStructure1.Height + - (Col_BluePen.TopEdge + Col_BluePen.Height + 6); bxxlen = Col_BluePen.Width; bxorx = Col_BluePen.LeftEdge; bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2; /* Save the current colors */ - for( i = 0; i < amii_numcolors; ++i ) - svcolors[ i ] = colors[ i ] = GetRGB4( scrn->ViewPort.ColorMap, i ); + for (i = 0; i < amii_numcolors; ++i) + svcolors[i] = colors[i] = GetRGB4(scrn->ViewPort.ColorMap, i); Col_NewWindowStructure1.Screen = scrn; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - ((struct PropInfo *)Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK; - ((struct PropInfo *)Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK; - ((struct PropInfo *)Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + ((struct PropInfo *) Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK; + ((struct PropInfo *) Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK; + ((struct PropInfo *) Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK; } #endif - if( WINVERS_AMIV || WINVERS_AMII ) - { -#ifdef INTUI_NEW_LOOK - Col_NewWindowStructure1.Extension = wintags; - Col_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; -# ifdef __GNUC__ - fillhook.h_Entry = (void *)&LayerFillHook; -# else - fillhook.h_Entry = (ULONG(*)())LayerFillHook; -# endif - fillhook.h_Data = (void *)-2; - fillhook.h_SubEntry = 0; + if (WINVERS_AMIV || WINVERS_AMII) { +#ifdef INTUI_NEW_LOOK + Col_NewWindowStructure1.Extension = wintags; + Col_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; +#ifdef __GNUC__ + fillhook.h_Entry = (void *) &LayerFillHook; +#else + fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; +#endif + fillhook.h_Data = (void *) -2; + fillhook.h_SubEntry = 0; #endif - } - - nw = OpenWindow( (void *)&Col_NewWindowStructure1 ); - - if( nw == NULL ) - { - DisplayBeep( NULL ); - return; } - PrintIText( nw->RPort, &Col_IntuiTextList1, 0, 0 ); + nw = OpenWindow((void *) &Col_NewWindowStructure1); - ClearCol( nw ); - DrawCol( nw, curcol, colors ); - while( !done ) - { - WaitPort( nw->UserPort ); - - while( imsg = (struct IntuiMessage * )GetMsg( nw->UserPort ) ) - { - gd = (struct Gadget *)imsg->IAddress; - code = imsg->Code; - class = imsg->Class; - qual = imsg->Qualifier; - msx = imsg->MouseX; - msy = imsg->MouseY; - - ReplyMsg( (struct Message *)imsg ); - - switch( class ) - { - case VANILLAKEY: - if( code == 'v' && qual == AMIGALEFT ) - okay = done = 1; - else if( code == 'b' && qual == AMIGALEFT ) - okay = 0, done = 1; - else if( code == 'o' || code == 'O' ) - okay = done = 1; - else if( code == 'c' || code == 'C' ) - okay = 0, done = 1; - break; - - case CLOSEWINDOW: - done = 1; - break; - - case GADGETUP: - drag = 0; - if( gd->GadgetID == GADREDPEN || - gd->GadgetID == GADBLUEPEN || - gd->GadgetID == GADGREENPEN ) - { - pip = (struct PropInfo *)gd->SpecialInfo; - aidx = pip->HorizPot / (MAXPOT/15); - if( gd->GadgetID == GADREDPEN ) - { - colors[ curcol ] = - ( colors[ curcol ] & ~0xf00 ) | (aidx << 8); - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - else if( gd->GadgetID == GADBLUEPEN ) - { - colors[ curcol ] = - ( colors[ curcol ] & ~0xf ) | aidx; - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - else if( gd->GadgetID == GADGREENPEN ) - { - colors[ curcol ] = ( colors[ curcol ] & ~0x0f0 ) | (aidx << 4); - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - DispCol( nw, curcol, colors ); - } - else if( gd->GadgetID == GADCOLOKAY ) - { - done = 1; - okay = 1; - } - else if( gd->GadgetID == GADCOLSAVE ) - { - FILE *fp, *nfp; - char buf[ 300 ], nname[ 300 ], oname[ 300 ]; - int once = 0; - - fp = fopen( configfile, "r" ); - if( !fp ) - { - pline( "can't find NetHack.cnf" ); - break; - } - - strcpy( oname, dirname( (char *)configfile ) ); - if( oname[ strlen(oname)-1 ] != ':' ) - { - sprintf( nname, "%s/New_NetHack.cnf", oname ); - strcat( oname, "/" ); - strcat( oname, "Old_NetHack.cnf" ); - } - else - { - sprintf( nname, "%sNew_NetHack.cnf", oname ); - strcat( oname, "Old_NetHack.cnf" ); - } - - nfp = fopen( nname, "w" ); - if( !nfp ) - { - pline( "can't write to New_NetHack.cnf" ); - fclose( fp ); - break; - } - while( fgets( buf, sizeof( buf ), fp ) ) - { - if( strncmp( buf, "PENS=", 5 ) == 0 ) - { - once = 1; - fputs( "PENS=", nfp ); - for( i = 0; i < amii_numcolors; ++i ) - { - fprintf( nfp, "%03x", colors[i] ); - if(( i + 1 ) < amii_numcolors) - putc( '/', nfp ); - } - putc( '\n', nfp ); - } - else - { - fputs( buf, nfp ); - } - } - - /* If none in the file yet, now write it */ - if( !once ) - { - fputs( "PENS=", nfp ); - for( i = 0; i < amii_numcolors; ++i ) - { - fprintf( nfp, "%03x", colors[i] ); - if(( i + 1 ) < amii_numcolors) - putc( ',', nfp ); - } - putc( '\n', nfp ); - } - fclose( fp ); - fclose( nfp ); - unlink( oname ); - if( filecopy( (char *)configfile, oname ) == 0 ) - if( filecopy( nname, (char *)configfile ) == 0 ) - unlink( nname ); - done = 1; - okay = 1; - } - else if( gd->GadgetID == GADCOLCANCEL ) - { - done = 1; - okay = 0; - } - break; - - case GADGETDOWN: - drag = 1; - dgad = gd; - break; - - case MOUSEMOVE: - if( !drag ) - break; - pip = (struct PropInfo *)dgad->SpecialInfo; - aidx = pip->HorizPot / (MAXPOT/15); - if( dgad->GadgetID == GADREDPEN ) - { - colors[ curcol ] = - ( colors[ curcol ] & ~0xf00 ) | (aidx << 8); - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - else if( dgad->GadgetID == GADBLUEPEN ) - { - colors[ curcol ] = ( colors[ curcol ] & ~0xf ) | aidx; - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - else if( dgad->GadgetID == GADGREENPEN ) - { - colors[ curcol ] = - ( colors[ curcol ] & ~0x0f0 ) | (aidx << 4); - LoadRGB4( &scrn->ViewPort, colors, amii_numcolors ); - } - DispCol( nw, curcol, colors ); - break; - - case MOUSEBUTTONS: - if( code == SELECTDOWN ) - { - if( msy > bxory && msy < bxory + bxylen - 1 && - msx > bxorx && msx < bxorx + bxxlen - 1 ) - { - curcol = ( msx - bxorx )/(bxxlen / amii_numcolors); - if( curcol >= 0 && curcol < amii_numcolors ) - DrawCol( nw, curcol, colors ); - } - } - break; - } - } + if (nw == NULL) { + DisplayBeep(NULL); + return; } - if( okay ) - { - for( i = 0; i < ( amii_numcolors ); ++i ) - sysflags.amii_curmap[ i ] = colors[ i ]; - LoadRGB4( &scrn->ViewPort, sysflags.amii_curmap, amii_numcolors ); + PrintIText(nw->RPort, &Col_IntuiTextList1, 0, 0); + + ClearCol(nw); + DrawCol(nw, curcol, colors); + while (!done) { + WaitPort(nw->UserPort); + + while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) { + gd = (struct Gadget *) imsg->IAddress; + code = imsg->Code; + class = imsg->Class; + qual = imsg->Qualifier; + msx = imsg->MouseX; + msy = imsg->MouseY; + + ReplyMsg((struct Message *) imsg); + + switch (class) { + case VANILLAKEY: + if (code == 'v' && qual == AMIGALEFT) + okay = done = 1; + else if (code == 'b' && qual == AMIGALEFT) + okay = 0, done = 1; + else if (code == 'o' || code == 'O') + okay = done = 1; + else if (code == 'c' || code == 'C') + okay = 0, done = 1; + break; + + case CLOSEWINDOW: + done = 1; + break; + + case GADGETUP: + drag = 0; + if (gd->GadgetID == GADREDPEN || gd->GadgetID == GADBLUEPEN + || gd->GadgetID == GADGREENPEN) { + pip = (struct PropInfo *) gd->SpecialInfo; + aidx = pip->HorizPot / (MAXPOT / 15); + if (gd->GadgetID == GADREDPEN) { + colors[curcol] = + (colors[curcol] & ~0xf00) | (aidx << 8); + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } else if (gd->GadgetID == GADBLUEPEN) { + colors[curcol] = (colors[curcol] & ~0xf) | aidx; + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } else if (gd->GadgetID == GADGREENPEN) { + colors[curcol] = + (colors[curcol] & ~0x0f0) | (aidx << 4); + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } + DispCol(nw, curcol, colors); + } else if (gd->GadgetID == GADCOLOKAY) { + done = 1; + okay = 1; + } else if (gd->GadgetID == GADCOLSAVE) { + FILE *fp, *nfp; + char buf[300], nname[300], oname[300]; + int once = 0; + + fp = fopen(configfile, "r"); + if (!fp) { + pline("can't find NetHack.cnf"); + break; + } + + strcpy(oname, dirname((char *) configfile)); + if (oname[strlen(oname) - 1] != ':') { + sprintf(nname, "%s/New_NetHack.cnf", oname); + strcat(oname, "/"); + strcat(oname, "Old_NetHack.cnf"); + } else { + sprintf(nname, "%sNew_NetHack.cnf", oname); + strcat(oname, "Old_NetHack.cnf"); + } + + nfp = fopen(nname, "w"); + if (!nfp) { + pline("can't write to New_NetHack.cnf"); + fclose(fp); + break; + } + while (fgets(buf, sizeof(buf), fp)) { + if (strncmp(buf, "PENS=", 5) == 0) { + once = 1; + fputs("PENS=", nfp); + for (i = 0; i < amii_numcolors; ++i) { + fprintf(nfp, "%03x", colors[i]); + if ((i + 1) < amii_numcolors) + putc('/', nfp); + } + putc('\n', nfp); + } else { + fputs(buf, nfp); + } + } + + /* If none in the file yet, now write it */ + if (!once) { + fputs("PENS=", nfp); + for (i = 0; i < amii_numcolors; ++i) { + fprintf(nfp, "%03x", colors[i]); + if ((i + 1) < amii_numcolors) + putc(',', nfp); + } + putc('\n', nfp); + } + fclose(fp); + fclose(nfp); + unlink(oname); + if (filecopy((char *) configfile, oname) == 0) + if (filecopy(nname, (char *) configfile) == 0) + unlink(nname); + done = 1; + okay = 1; + } else if (gd->GadgetID == GADCOLCANCEL) { + done = 1; + okay = 0; + } + break; + + case GADGETDOWN: + drag = 1; + dgad = gd; + break; + + case MOUSEMOVE: + if (!drag) + break; + pip = (struct PropInfo *) dgad->SpecialInfo; + aidx = pip->HorizPot / (MAXPOT / 15); + if (dgad->GadgetID == GADREDPEN) { + colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8); + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } else if (dgad->GadgetID == GADBLUEPEN) { + colors[curcol] = (colors[curcol] & ~0xf) | aidx; + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } else if (dgad->GadgetID == GADGREENPEN) { + colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4); + LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); + } + DispCol(nw, curcol, colors); + break; + + case MOUSEBUTTONS: + if (code == SELECTDOWN) { + if (msy > bxory && msy < bxory + bxylen - 1 && msx > bxorx + && msx < bxorx + bxxlen - 1) { + curcol = (msx - bxorx) / (bxxlen / amii_numcolors); + if (curcol >= 0 && curcol < amii_numcolors) + DrawCol(nw, curcol, colors); + } + } + break; + } + } } - else - LoadRGB4( &scrn->ViewPort, svcolors, amii_numcolors ); - CloseWindow( nw ); + + if (okay) { + for (i = 0; i < (amii_numcolors); ++i) + sysflags.amii_curmap[i] = colors[i]; + LoadRGB4(&scrn->ViewPort, sysflags.amii_curmap, amii_numcolors); + } else + LoadRGB4(&scrn->ViewPort, svcolors, amii_numcolors); + CloseWindow(nw); } void -ShowClipValues( struct Window *nw ) +ShowClipValues(struct Window *nw) { - char buf[ 50 ]; + char buf[50]; struct Gadget *gd; - SetAPen( nw->RPort, 5 ); - SetBPen( nw->RPort, amii_otherBPen ); - SetDrMd( nw->RPort, JAM2 ); + SetAPen(nw->RPort, 5); + SetBPen(nw->RPort, amii_otherBPen); + SetDrMd(nw->RPort, JAM2); - sprintf( buf, "%d ", mxsize ); + sprintf(buf, "%d ", mxsize); gd = &ClipXSIZE; - Move( nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, - gd->TopEdge + nw->RPort->TxBaseline ); - Text( nw->RPort, buf, strlen( buf ) ); + Move(nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, + gd->TopEdge + nw->RPort->TxBaseline); + Text(nw->RPort, buf, strlen(buf)); - sprintf( buf, "%d ", mysize ); + sprintf(buf, "%d ", mysize); gd = &ClipYSIZE; - Move( nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, - gd->TopEdge + nw->RPort->TxBaseline ); - Text( nw->RPort, buf, strlen( buf ) ); + Move(nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, + gd->TopEdge + nw->RPort->TxBaseline); + Text(nw->RPort, buf, strlen(buf)); - sprintf( buf, "%d ", xclipbord ); + sprintf(buf, "%d ", xclipbord); gd = &ClipXCLIP; - Move( nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, - gd->TopEdge + nw->RPort->TxBaseline ); - Text( nw->RPort, buf, strlen( buf ) ); + Move(nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, + gd->TopEdge + nw->RPort->TxBaseline); + Text(nw->RPort, buf, strlen(buf)); - sprintf( buf, "%d ", yclipbord ); + sprintf(buf, "%d ", yclipbord); gd = &ClipYCLIP; - Move( nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, - gd->TopEdge + nw->RPort->TxBaseline ); - Text( nw->RPort, buf, strlen( buf ) ); + Move(nw->RPort, gd->LeftEdge + (nw->Width + gd->Width) + 8, + gd->TopEdge + nw->RPort->TxBaseline); + Text(nw->RPort, buf, strlen(buf)); } void -EditClipping( void ) +EditClipping(void) { int i; long mflags; static int sizes[] = { 8, 16, 20, 24, 28, 32, 36 }; - char buf[ 40 ]; + char buf[40]; int done = 0, okay = 0; long code, qual, class; register struct Gadget *gd, *dgad; @@ -404,334 +358,272 @@ EditClipping( void ) scrn = HackScreen; - if( !once ) - { - SetBorder( &ClipOkay ); - SetBorder( &ClipCancel ); - once = 1; + if (!once) { + SetBorder(&ClipOkay); + SetBorder(&ClipCancel); + once = 1; } ClipNewWindowStructure1.Screen = scrn; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - ((struct PropInfo *)ClipXSIZE.SpecialInfo)->Flags |= PROPNEWLOOK; - ((struct PropInfo *)ClipYSIZE.SpecialInfo)->Flags |= PROPNEWLOOK; - ((struct PropInfo *)ClipXCLIP.SpecialInfo)->Flags |= PROPNEWLOOK; - ((struct PropInfo *)ClipYCLIP.SpecialInfo)->Flags |= PROPNEWLOOK; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + ((struct PropInfo *) ClipXSIZE.SpecialInfo)->Flags |= PROPNEWLOOK; + ((struct PropInfo *) ClipYSIZE.SpecialInfo)->Flags |= PROPNEWLOOK; + ((struct PropInfo *) ClipXCLIP.SpecialInfo)->Flags |= PROPNEWLOOK; + ((struct PropInfo *) ClipYCLIP.SpecialInfo)->Flags |= PROPNEWLOOK; } #endif - if( WINVERS_AMIV || WINVERS_AMII ) - { -# ifdef INTUI_NEW_LOOK - ClipNewWindowStructure1.Extension = wintags; - ClipNewWindowStructure1.Flags |= WFLG_NW_EXTENDED; -# ifdef __GNUC__ - fillhook.h_Entry = (void *)&LayerFillHook; -# else - fillhook.h_Entry = (ULONG(*)())LayerFillHook; -# endif - fillhook.h_Data = (void *)-2; - fillhook.h_SubEntry = 0; -# endif + if (WINVERS_AMIV || WINVERS_AMII) { +#ifdef INTUI_NEW_LOOK + ClipNewWindowStructure1.Extension = wintags; + ClipNewWindowStructure1.Flags |= WFLG_NW_EXTENDED; +#ifdef __GNUC__ + fillhook.h_Entry = (void *) &LayerFillHook; +#else + fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; +#endif + fillhook.h_Data = (void *) -2; + fillhook.h_SubEntry = 0; +#endif } - nw = OpenWindow( (void *)&ClipNewWindowStructure1 ); + nw = OpenWindow((void *) &ClipNewWindowStructure1); - if( nw == NULL ) - { - DisplayBeep( NULL ); - return; + if (nw == NULL) { + DisplayBeep(NULL); + return; } - ShowClipValues( nw ); - mflags = AUTOKNOB|FREEHORIZ; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - mflags |= PROPNEWLOOK; + ShowClipValues(nw); + mflags = AUTOKNOB | FREEHORIZ; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + mflags |= PROPNEWLOOK; } #endif - for( i = 0; i < 7; ++i ) - { - if( mxsize <= sizes[ i ] ) - break; + for (i = 0; i < 7; ++i) { + if (mxsize <= sizes[i]) + break; } - NewModifyProp( &ClipXSIZE, nw, NULL, mflags, (i * MAXPOT ) / 6, 0, - MAXPOT/6, 0, 1 ); - for( i = 0; i < 7; ++i ) - { - if( mysize <= sizes[ i ] ) - break; + NewModifyProp(&ClipXSIZE, nw, NULL, mflags, (i * MAXPOT) / 6, 0, + MAXPOT / 6, 0, 1); + for (i = 0; i < 7; ++i) { + if (mysize <= sizes[i]) + break; } - NewModifyProp( &ClipYSIZE, nw, NULL, mflags, (i * MAXPOT ) / 6, 0, - MAXPOT/6, 0, 1 ); + NewModifyProp(&ClipYSIZE, nw, NULL, mflags, (i * MAXPOT) / 6, 0, + MAXPOT / 6, 0, 1); - NewModifyProp( &ClipXCLIP, nw, NULL, mflags, ((xclipbord-2) * MAXPOT ) / 6, 0, - MAXPOT/6, 0, 1 ); - NewModifyProp( &ClipYCLIP, nw, NULL, mflags, ((yclipbord-2) * MAXPOT ) / 6, 0, - MAXPOT/6, 0, 1 ); + NewModifyProp(&ClipXCLIP, nw, NULL, mflags, + ((xclipbord - 2) * MAXPOT) / 6, 0, MAXPOT / 6, 0, 1); + NewModifyProp(&ClipYCLIP, nw, NULL, mflags, + ((yclipbord - 2) * MAXPOT) / 6, 0, MAXPOT / 6, 0, 1); - while( !done ) - { - WaitPort( nw->UserPort ); + while (!done) { + WaitPort(nw->UserPort); - while( imsg = (struct IntuiMessage * )GetMsg( nw->UserPort ) ) - { - gd = (struct Gadget *)imsg->IAddress; - code = imsg->Code; - class = imsg->Class; - qual = imsg->Qualifier; - msx = imsg->MouseX; - msy = imsg->MouseY; + while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) { + gd = (struct Gadget *) imsg->IAddress; + code = imsg->Code; + class = imsg->Class; + qual = imsg->Qualifier; + msx = imsg->MouseX; + msy = imsg->MouseY; - ReplyMsg( (struct Message *)imsg ); + ReplyMsg((struct Message *) imsg); - switch( class ) - { - case VANILLAKEY: - if( code == '\33' ) - okay = 0, done = 1; - else if( code == 'v' && qual == AMIGALEFT ) - okay = done = 1; - else if( code == 'b' && qual == AMIGALEFT ) - okay = 0, done = 1; - else if( code == 'o' || code == 'O' ) - okay = done = 1; - else if( code == 'c' || code == 'C' ) - okay = 0, done = 1; - break; + switch (class) { + case VANILLAKEY: + if (code == '\33') + okay = 0, done = 1; + else if (code == 'v' && qual == AMIGALEFT) + okay = done = 1; + else if (code == 'b' && qual == AMIGALEFT) + okay = 0, done = 1; + else if (code == 'o' || code == 'O') + okay = done = 1; + else if (code == 'c' || code == 'C') + okay = 0, done = 1; + break; - case CLOSEWINDOW: - done = 1; - break; + case CLOSEWINDOW: + done = 1; + break; - case GADGETUP: - drag = 0; - if( gd->GadgetID == XSIZE || gd->GadgetID == YSIZE || - gd->GadgetID == XCLIP || gd->GadgetID == YCLIP ) - { - pip = (struct PropInfo *)gd->SpecialInfo; - aidx = pip->HorizPot / (MAXPOT/6); - if( gd->GadgetID == XSIZE ) - { - mxsize = sizes[ aidx ]; - } - else if( gd->GadgetID == YSIZE ) - { - mysize = sizes[ aidx ]; - } - else if( gd->GadgetID == XCLIP ) - { - xclipbord = aidx + 2; - } - else if( gd->GadgetID == YCLIP ) - { - yclipbord = aidx + 2; - } - ShowClipValues( nw ); + case GADGETUP: + drag = 0; + if (gd->GadgetID == XSIZE || gd->GadgetID == YSIZE + || gd->GadgetID == XCLIP || gd->GadgetID == YCLIP) { + pip = (struct PropInfo *) gd->SpecialInfo; + aidx = pip->HorizPot / (MAXPOT / 6); + if (gd->GadgetID == XSIZE) { + mxsize = sizes[aidx]; + } else if (gd->GadgetID == YSIZE) { + mysize = sizes[aidx]; + } else if (gd->GadgetID == XCLIP) { + xclipbord = aidx + 2; + } else if (gd->GadgetID == YCLIP) { + yclipbord = aidx + 2; + } + ShowClipValues(nw); #ifdef OPT_DISPMAP - dispmap_sanity(); + dispmap_sanity(); #endif - } - else if( gd->GadgetID == GADOKAY ) - { - done = 1; - okay = 1; - } - else if( gd->GadgetID == GADCANCEL ) - { - done = 1; - okay = 0; - } - ReportMouse( 0, nw ); - reclip = 2; - doredraw(); - flush_glyph_buffer( amii_wins[ WIN_MAP ]->win ); - reclip = 0; - break; + } else if (gd->GadgetID == GADOKAY) { + done = 1; + okay = 1; + } else if (gd->GadgetID == GADCANCEL) { + done = 1; + okay = 0; + } + ReportMouse(0, nw); + reclip = 2; + doredraw(); + flush_glyph_buffer(amii_wins[WIN_MAP]->win); + reclip = 0; + break; - case GADGETDOWN: - drag = 1; - dgad = gd; - ReportMouse( 1, nw ); - break; + case GADGETDOWN: + drag = 1; + dgad = gd; + ReportMouse(1, nw); + break; - case MOUSEMOVE: - if( !drag ) - break; - pip = (struct PropInfo *)dgad->SpecialInfo; - aidx = pip->HorizPot / (MAXPOT/6); - Move( nw->RPort, dgad->LeftEdge + (nw->Width + dgad->Width) + 8, - dgad->TopEdge + nw->RPort->TxBaseline ); - if( dgad->GadgetID == XSIZE ) - { - mxsize = sizes[ aidx ]; - sprintf( buf, "%d ",lmxsize ); - } - else if( dgad->GadgetID == YSIZE ) - { - mysize = sizes[ aidx ]; - sprintf( buf, "%d ", mysize ); - } - else if( dgad->GadgetID == XCLIP ) - { - xclipbord = aidx + 2; - sprintf( buf, "%d ", xclipbord ); - } - else if( dgad->GadgetID == YCLIP ) - { - yclipbord = aidx + 2; - sprintf( buf, "%d ", yclipbord ); - } - SetAPen( nw->RPort, 5 ); - SetBPen( nw->RPort, amii_otherBPen ); - SetDrMd( nw->RPort, JAM2 ); - Text( nw->RPort, buf, strlen( buf ) ); + case MOUSEMOVE: + if (!drag) + break; + pip = (struct PropInfo *) dgad->SpecialInfo; + aidx = pip->HorizPot / (MAXPOT / 6); + Move(nw->RPort, + dgad->LeftEdge + (nw->Width + dgad->Width) + 8, + dgad->TopEdge + nw->RPort->TxBaseline); + if (dgad->GadgetID == XSIZE) { + mxsize = sizes[aidx]; + sprintf(buf, "%d ", lmxsize); + } else if (dgad->GadgetID == YSIZE) { + mysize = sizes[aidx]; + sprintf(buf, "%d ", mysize); + } else if (dgad->GadgetID == XCLIP) { + xclipbord = aidx + 2; + sprintf(buf, "%d ", xclipbord); + } else if (dgad->GadgetID == YCLIP) { + yclipbord = aidx + 2; + sprintf(buf, "%d ", yclipbord); + } + SetAPen(nw->RPort, 5); + SetBPen(nw->RPort, amii_otherBPen); + SetDrMd(nw->RPort, JAM2); + Text(nw->RPort, buf, strlen(buf)); #ifdef OPT_DISPMAP - dispmap_sanity(); + dispmap_sanity(); #endif - break; - } - } + break; + } + } } - CloseWindow( nw ); + CloseWindow(nw); /* Restore oldvalues if cancelled. */ - if( !okay ) - { - mxsize = lmxsize; - mysize = lmysize; - xclipbord = lxclipbord; - yclipbord = lyclipbord; + if (!okay) { + mxsize = lmxsize; + mysize = lmysize; + xclipbord = lxclipbord; + yclipbord = lyclipbord; } } -char *dirname( str ) - char *str; +char * +dirname(str) +char *str; { char *t, c; - static char dir[ 300 ]; + static char dir[300]; - t = strrchr( str, '/' ); - if( !t ) - t = strrchr( str, ':' ); - if( !t ) - t = str; - else - { - c = *t; - *t = 0; - strcpy( dir, str ); - *t = c; + t = strrchr(str, '/'); + if (!t) + t = strrchr(str, ':'); + if (!t) + t = str; + else { + c = *t; + *t = 0; + strcpy(dir, str); + *t = c; } - return( dir ); + return (dir); } -char *basename( str ) - char *str; +char * +basename(str) +char *str; { char *t; - t = strrchr( str, '/' ); - if( !t ) - t = strrchr( str, ':' ); - if( !t ) - t = str; + t = strrchr(str, '/'); + if (!t) + t = strrchr(str, ':'); + if (!t) + t = str; else - ++t; - return( t ); + ++t; + return (t); } -filecopy( from, to ) - char *from, *to; +filecopy(from, to) char *from, *to; { char *buf; int i = 0; - buf = (char *)alloc( strlen(to) + strlen(from) + 20 ); - if( buf ) - { - sprintf( buf, "c:copy \"%s\" \"%s\" clone", from, to ); + buf = (char *) alloc(strlen(to) + strlen(from) + 20); + if (buf) { + sprintf(buf, "c:copy \"%s\" \"%s\" clone", from, to); - /* Check SysBase instead? Shouldn't matter */ -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - i = System( buf, NULL ); - else +/* Check SysBase instead? Shouldn't matter */ +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) + i = System(buf, NULL); + else #endif - Execute( buf, NULL, NULL ); - free( buf ); + Execute(buf, NULL, NULL); + free(buf); + } else { + return (-1); } - else - { - return( -1 ); - } - return( i ); + return (i); } /* The colornames, and the default values for the pens */ -static struct COLDEF -{ +static struct COLDEF { char *name, *defval; }; -struct COLDEF amii_colnames[ AMII_MAXCOLORS ] = -{ - "Black","(000)", - "White","(fff)", - "Brown","(830)", - "Cyan","(7ac)", - "Green","(181)", - "Magenta","(c06)", - "Blue","(23e)", - "Red","(c00)", +struct COLDEF amii_colnames[AMII_MAXCOLORS] = { + "Black", "(000)", "White", "(fff)", "Brown", "(830)", "Cyan", "(7ac)", + "Green", "(181)", "Magenta", "(c06)", "Blue", "(23e)", "Red", "(c00)", }; -struct COLDEF amiv_colnames[ AMII_MAXCOLORS ] = -{ - "Black","(000)", - "White","(fff)", - "Cyan","(0bf)", - "Orange","(f60)", - "Blue","(00f)", - "Green","(090)", - "Grey","(69b)", - "Red","(f00)", - "Light Green","(6f0)", - "Yellow","(ff0)", - "Magenta","(f0f)", - "Brown","(940)", - "Grey Blue","(466)", - "Light Brown","(c40)", - "Light Grey","(ddb)", - "Peach","(fb9)", - "Col 16","(222)", - "Col 17","(eee)", - "Col 18","(000)", - "Col 19","(ccc)", - "Col 20","(bbb)", - "Col 21","(aaa)", - "Col 22","(999)", - "Col 23","(888)", - "Col 24","(777)", - "Col 25","(666)", - "Col 26","(555)", - "Col 27","(444)", - "Col 28","(333)", - "Col 29","(18f)", - "Col 30","(f81)", - "Col 31","(fff)", +struct COLDEF amiv_colnames[AMII_MAXCOLORS] = { + "Black", "(000)", "White", "(fff)", "Cyan", "(0bf)", + "Orange", "(f60)", "Blue", "(00f)", "Green", "(090)", + "Grey", "(69b)", "Red", "(f00)", "Light Green", "(6f0)", + "Yellow", "(ff0)", "Magenta", "(f0f)", "Brown", "(940)", + "Grey Blue", "(466)", "Light Brown", "(c40)", "Light Grey", "(ddb)", + "Peach", "(fb9)", "Col 16", "(222)", "Col 17", "(eee)", + "Col 18", "(000)", "Col 19", "(ccc)", "Col 20", "(bbb)", + "Col 21", "(aaa)", "Col 22", "(999)", "Col 23", "(888)", + "Col 24", "(777)", "Col 25", "(666)", "Col 26", "(555)", + "Col 27", "(444)", "Col 28", "(333)", "Col 29", "(18f)", + "Col 30", "(f81)", "Col 31", "(fff)", }; void -ClearCol( struct Window *w ) +ClearCol(struct Window *w) { int bxorx, bxory, bxxlen, bxylen; int incx, incy; - bxylen = Col_Okay.TopEdge - ( Col_BluePen.TopEdge + Col_BluePen.Height ) - 1 - - txheight - 3; + bxylen = Col_Okay.TopEdge - (Col_BluePen.TopEdge + Col_BluePen.Height) - 1 + - txheight - 3; bxxlen = Col_BluePen.Width - 2; bxorx = Col_BluePen.LeftEdge + 1; bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2; @@ -743,27 +635,27 @@ ClearCol( struct Window *w ) bxxlen *= incx; bxxlen += 2; - SetAPen( w->RPort, C_WHITE ); - SetDrMd( w->RPort, JAM1 ); - RectFill( w->RPort, bxorx, bxory, bxorx + bxxlen + 1, bxory + bxylen ); + SetAPen(w->RPort, C_WHITE); + SetDrMd(w->RPort, JAM1); + RectFill(w->RPort, bxorx, bxory, bxorx + bxxlen + 1, bxory + bxylen); - SetAPen( w->RPort, C_BLACK ); - RectFill( w->RPort, bxorx+1, bxory+1, - bxorx + bxxlen, bxory + bxylen - 1); + SetAPen(w->RPort, C_BLACK); + RectFill(w->RPort, bxorx + 1, bxory + 1, bxorx + bxxlen, + bxory + bxylen - 1); } void -DrawCol( w, idx, colors ) - struct Window *w; - int idx; - UWORD *colors; +DrawCol(w, idx, colors) +struct Window *w; +int idx; +UWORD *colors; { int bxorx, bxory, bxxlen, bxylen; int i, incx, incy, r, g, b; long mflags; - bxylen = Col_Okay.TopEdge - ( Col_BluePen.TopEdge + Col_BluePen.Height ) - 1 - - txheight - 3; + bxylen = Col_Okay.TopEdge - (Col_BluePen.TopEdge + Col_BluePen.Height) - 1 + - txheight - 3; bxxlen = Col_BluePen.Width - 2; bxorx = Col_BluePen.LeftEdge + 1; bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2; @@ -775,188 +667,164 @@ DrawCol( w, idx, colors ) bxxlen *= incx; bxxlen += 2; - for( i = 0; i < amii_numcolors; ++i ) - { - int x, y; - x = bxorx + 2 + (i*incx); - y = bxory + 2; + for (i = 0; i < amii_numcolors; ++i) { + int x, y; + x = bxorx + 2 + (i * incx); + y = bxory + 2; - if( i == idx ) - { - SetAPen( w->RPort, sysflags.amii_dripens[ SHADOWPEN ] ); - Move( w->RPort, x, y+bxylen-4 ); - Draw( w->RPort, x, y ); - Draw( w->RPort, x+incx-1, y ); + if (i == idx) { + SetAPen(w->RPort, sysflags.amii_dripens[SHADOWPEN]); + Move(w->RPort, x, y + bxylen - 4); + Draw(w->RPort, x, y); + Draw(w->RPort, x + incx - 1, y); - Move( w->RPort, x+1, y+bxylen-5 ); - Draw( w->RPort, x+1, y+1 ); - Draw( w->RPort, x+incx-2, y+1 ); + Move(w->RPort, x + 1, y + bxylen - 5); + Draw(w->RPort, x + 1, y + 1); + Draw(w->RPort, x + incx - 2, y + 1); - SetAPen( w->RPort, sysflags.amii_dripens[ SHINEPEN ] ); - Move( w->RPort, x+incx-1, y+1 ); - Draw( w->RPort, x+incx-1, y+bxylen-4 ); - Draw( w->RPort, x, y+bxylen-4 ); + SetAPen(w->RPort, sysflags.amii_dripens[SHINEPEN]); + Move(w->RPort, x + incx - 1, y + 1); + Draw(w->RPort, x + incx - 1, y + bxylen - 4); + Draw(w->RPort, x, y + bxylen - 4); - Move( w->RPort, x+incx-2, y+2 ); - Draw( w->RPort, x+incx-2, y+bxylen-5 ); - Draw( w->RPort, x+1, y+bxylen-5 ); - } - else - { - SetAPen( w->RPort, C_BLACK ); - Move( w->RPort, x, y ); - Draw( w->RPort, x +incx-1, y ); - Draw( w->RPort, x +incx-1, y +bxylen - 4 ); - Draw( w->RPort, x, y + bxylen - 4 ); - Draw( w->RPort, x, y ); - SetAPen( w->RPort, C_BLACK ); - Move( w->RPort, x+1, y+1 ); - Draw( w->RPort, x +incx-2, y+1 ); - Draw( w->RPort, x +incx-2, y +bxylen - 6 ); - Draw( w->RPort, x+1, y + bxylen - 6 ); - Draw( w->RPort, x+1, y+1 ); - } + Move(w->RPort, x + incx - 2, y + 2); + Draw(w->RPort, x + incx - 2, y + bxylen - 5); + Draw(w->RPort, x + 1, y + bxylen - 5); + } else { + SetAPen(w->RPort, C_BLACK); + Move(w->RPort, x, y); + Draw(w->RPort, x + incx - 1, y); + Draw(w->RPort, x + incx - 1, y + bxylen - 4); + Draw(w->RPort, x, y + bxylen - 4); + Draw(w->RPort, x, y); + SetAPen(w->RPort, C_BLACK); + Move(w->RPort, x + 1, y + 1); + Draw(w->RPort, x + incx - 2, y + 1); + Draw(w->RPort, x + incx - 2, y + bxylen - 6); + Draw(w->RPort, x + 1, y + bxylen - 6); + Draw(w->RPort, x + 1, y + 1); + } - SetAPen( w->RPort, i ); - RectFill( w->RPort, x + 3, y + 3, x + incx - 4, y + bxylen - 6 ); + SetAPen(w->RPort, i); + RectFill(w->RPort, x + 3, y + 3, x + incx - 4, y + bxylen - 6); } - DispCol( w, idx, colors ); + DispCol(w, idx, colors); - r = (colors[ idx ] & 0xf00) >> 8; - g = (colors[ idx ] & 0x0f0) >> 4; - b = colors[ idx ] & 0x00f; + r = (colors[idx] & 0xf00) >> 8; + g = (colors[idx] & 0x0f0) >> 4; + b = colors[idx] & 0x00f; - mflags = AUTOKNOB|FREEHORIZ; -#ifdef INTUI_NEW_LOOK - if( IntuitionBase->LibNode.lib_Version >= 37 ) - { - mflags |= PROPNEWLOOK; + mflags = AUTOKNOB | FREEHORIZ; +#ifdef INTUI_NEW_LOOK + if (IntuitionBase->LibNode.lib_Version >= 37) { + mflags |= PROPNEWLOOK; } #endif - NewModifyProp( &Col_RedPen, w, NULL, mflags, (r * MAXPOT ) / 15, 0, - MAXPOT/15, 0, 1 ); - NewModifyProp( &Col_GreenPen, w, NULL, mflags, (g * MAXPOT ) / 15, 0, - MAXPOT/15, 0, 1 ); - NewModifyProp( &Col_BluePen, w, NULL, mflags, (b * MAXPOT ) / 15, 0, - MAXPOT/15, 0, 1 ); + NewModifyProp(&Col_RedPen, w, NULL, mflags, (r * MAXPOT) / 15, 0, + MAXPOT / 15, 0, 1); + NewModifyProp(&Col_GreenPen, w, NULL, mflags, (g * MAXPOT) / 15, 0, + MAXPOT / 15, 0, 1); + NewModifyProp(&Col_BluePen, w, NULL, mflags, (b * MAXPOT) / 15, 0, + MAXPOT / 15, 0, 1); } void -DispCol( w, idx, colors ) - struct Window *w; - int idx; - UWORD *colors; +DispCol(w, idx, colors) +struct Window *w; +int idx; +UWORD *colors; { - char buf[ 50 ]; + char buf[50]; char *colname, *defval; - if( WINVERS_AMIV ) - { - colname = amiv_colnames[idx].name; - defval = amiv_colnames[idx].defval; - } - else - { - colname = amii_colnames[idx].name; - defval = amii_colnames[idx].defval; + if (WINVERS_AMIV) { + colname = amiv_colnames[idx].name; + defval = amiv_colnames[idx].defval; + } else { + colname = amii_colnames[idx].name; + defval = amii_colnames[idx].defval; } - if( colname == NULL ) - { - colname = "unknown"; - defval = "unknown"; + if (colname == NULL) { + colname = "unknown"; + defval = "unknown"; } - Move( w->RPort, Col_Save.LeftEdge, - Col_Save.TopEdge - 7 ); - sprintf( buf, "%s=%03x default=%s%s", colname, colors[idx], defval, - " "+strlen(colname)+1 ); - SetAPen( w->RPort, C_RED ); - SetBPen( w->RPort, amii_otherBPen ); - SetDrMd( w->RPort, JAM2 ); - Text( w->RPort, buf, strlen( buf ) ); + Move(w->RPort, Col_Save.LeftEdge, Col_Save.TopEdge - 7); + sprintf(buf, "%s=%03x default=%s%s", colname, colors[idx], defval, + " " + strlen(colname) + 1); + SetAPen(w->RPort, C_RED); + SetBPen(w->RPort, amii_otherBPen); + SetDrMd(w->RPort, JAM2); + Text(w->RPort, buf, strlen(buf)); } void -amii_setpens( int count ) +amii_setpens(int count) { -#ifdef INTUI_NEW_LOOK - struct EasyStruct ea = { - sizeof( struct EasyStruct ), - 0l, - "NetHack Request", - "Number of pens requested(%ld) not correct", - "Use default pens|Use requested pens" - }; - struct EasyStruct ea2 = { - sizeof( struct EasyStruct ), - 0l, - "NetHack Request", - "Number of pens requested(%ld) not\ncompatible with game configuration(%ld)", - "Use default pens|Use requested pens" - }; +#ifdef INTUI_NEW_LOOK + struct EasyStruct ea = { sizeof(struct EasyStruct), 0l, "NetHack Request", + "Number of pens requested(%ld) not correct", + "Use default pens|Use requested pens" }; + struct EasyStruct ea2 = { sizeof(struct EasyStruct), 0l, + "NetHack Request", + "Number of pens requested(%ld) not\ncompatible " + "with game configuration(%ld)", + "Use default pens|Use requested pens" }; #endif - /* If the pens in amii_curmap are - * more pens than in amii_numcolors, then we choose to ignore - * those pens. - */ -#ifdef INTUI_NEW_LOOK - if( IntuitionBase && IntuitionBase->LibNode.lib_Version >= 39 ) - { - if( count != amii_numcolors ) - { - long args[2]; - args[0] = count; - args[1] = amii_numcolors; - if( EasyRequest( NULL, &ea2, NULL, args ) == 1 ) - { - memcpy( sysflags.amii_curmap, amii_initmap, - amii_numcolors*sizeof(amii_initmap[0])); - } - } - } - else if( IntuitionBase && IntuitionBase->LibNode.lib_Version >= 37 ) - { - if( count != amii_numcolors ) - { - if( EasyRequest( NULL, &ea, NULL, NULL ) == 1 ) - { - memcpy( sysflags.amii_curmap, amii_initmap, - amii_numcolors*sizeof(amii_initmap[0])); - } - } - } - else +/* If the pens in amii_curmap are + * more pens than in amii_numcolors, then we choose to ignore + * those pens. + */ +#ifdef INTUI_NEW_LOOK + if (IntuitionBase && IntuitionBase->LibNode.lib_Version >= 39) { + if (count != amii_numcolors) { + long args[2]; + args[0] = count; + args[1] = amii_numcolors; + if (EasyRequest(NULL, &ea2, NULL, args) == 1) { + memcpy(sysflags.amii_curmap, amii_initmap, + amii_numcolors * sizeof(amii_initmap[0])); + } + } + } else if (IntuitionBase && IntuitionBase->LibNode.lib_Version >= 37) { + if (count != amii_numcolors) { + if (EasyRequest(NULL, &ea, NULL, NULL) == 1) { + memcpy(sysflags.amii_curmap, amii_initmap, + amii_numcolors * sizeof(amii_initmap[0])); + } + } + } else #endif - if( count != amii_numcolors ) - { - memcpy( sysflags.amii_curmap, amii_initmap, - amii_numcolors*sizeof(amii_initmap[0])); + if (count != amii_numcolors) { + memcpy(sysflags.amii_curmap, amii_initmap, + amii_numcolors * sizeof(amii_initmap[0])); } /* If the pens are set in NetHack.cnf, we can get called before * HackScreen has been opened. */ - if( HackScreen != NULL ) - { - LoadRGB4( &HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors ); + if (HackScreen != NULL) { + LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors); } } /* Generate a requester for a string value. */ -void amii_getlin(prompt,bufp) - const char *prompt; - char *bufp; +void +amii_getlin(prompt, bufp) +const char *prompt; +char *bufp; { - getlind(prompt,bufp,0); + getlind(prompt, bufp, 0); } /* and with default */ -void getlind(prompt,bufp, dflt) - const char *prompt; - char *bufp; - const char *dflt; +void +getlind(prompt, bufp, dflt) +const char *prompt; +char *bufp; +const char *dflt; { #ifndef TOPL_GETLINE register struct Window *cwin; @@ -967,213 +835,190 @@ void getlind(prompt,bufp, dflt) static int once; *StrString = 0; - if( dflt ) - strcpy( StrString, dflt ); - StrWindow.Title = (UBYTE *)prompt; + if (dflt) + strcpy(StrString, dflt); + StrWindow.Title = (UBYTE *) prompt; StrWindow.Screen = HackScreen; - if( !once ) - { - if( bigscreen ) { - StrWindow.LeftEdge = (HackScreen->Width/2) - (StrWindow.Width/2); - if (amii_wins[WIN_MAP]) { - StrWindow.TopEdge = amii_wins[WIN_MAP]->win->TopEdge; - } else { - StrWindow.TopEdge = (HackScreen->Height/2) - (StrWindow.Height/2); - } - } - SetBorder( &String ); - SetBorder( &Gadget2 ); - once = 1; + if (!once) { + if (bigscreen) { + StrWindow.LeftEdge = + (HackScreen->Width / 2) - (StrWindow.Width / 2); + if (amii_wins[WIN_MAP]) { + StrWindow.TopEdge = amii_wins[WIN_MAP]->win->TopEdge; + } else { + StrWindow.TopEdge = + (HackScreen->Height / 2) - (StrWindow.Height / 2); + } + } + SetBorder(&String); + SetBorder(&Gadget2); + once = 1; } - if( WINVERS_AMIV || WINVERS_AMII ) - { -#ifdef INTUI_NEW_LOOK - StrWindow.Extension = wintags; - StrWindow.Flags |= WFLG_NW_EXTENDED; -# ifdef __GNUC__ - fillhook.h_Entry = (void *)&LayerFillHook; -# else - fillhook.h_Entry = (ULONG(*)())LayerFillHook; -# endif - fillhook.h_Data = (void *)-2; - fillhook.h_SubEntry = 0; + if (WINVERS_AMIV || WINVERS_AMII) { +#ifdef INTUI_NEW_LOOK + StrWindow.Extension = wintags; + StrWindow.Flags |= WFLG_NW_EXTENDED; +#ifdef __GNUC__ + fillhook.h_Entry = (void *) &LayerFillHook; +#else + fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; +#endif + fillhook.h_Data = (void *) -2; + fillhook.h_SubEntry = 0; #endif } - if( ( cwin = OpenWindow( (void *)&StrWindow ) ) == NULL ) - { - return; + if ((cwin = OpenWindow((void *) &StrWindow)) == NULL) { + return; } - while( !aredone ) - { - WaitPort( cwin->UserPort ); - while( ( imsg = (void *) GetMsg( cwin->UserPort ) ) != NULL ) - { - class = imsg->Class; - code = imsg->Code; - qual = imsg->Qualifier; - gd = (struct Gadget *) imsg->IAddress; + while (!aredone) { + WaitPort(cwin->UserPort); + while ((imsg = (void *) GetMsg(cwin->UserPort)) != NULL) { + class = imsg->Class; + code = imsg->Code; + qual = imsg->Qualifier; + gd = (struct Gadget *) imsg->IAddress; - switch( class ) - { - case VANILLAKEY: - if( code == '\033' && (qual & - (IEQUALIFIER_LALT|IEQUALIFIER_RALT| - IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND) ) == 0 ) - { - if( bufp ) - { - bufp[0]='\033'; - bufp[1]=0; - } - aredone = 1; - } - else - { - ActivateGadget( &String, cwin, NULL ); - } - break; + switch (class) { + case VANILLAKEY: + if (code == '\033' + && (qual & (IEQUALIFIER_LALT | IEQUALIFIER_RALT + | IEQUALIFIER_LCOMMAND + | IEQUALIFIER_RCOMMAND)) == 0) { + if (bufp) { + bufp[0] = '\033'; + bufp[1] = 0; + } + aredone = 1; + } else { + ActivateGadget(&String, cwin, NULL); + } + break; - case ACTIVEWINDOW: - ActivateGadget( &String, cwin, NULL ); - break; + case ACTIVEWINDOW: + ActivateGadget(&String, cwin, NULL); + break; - case GADGETUP: - switch( gd->GadgetID ) - { - case 2: - aredone = 1; - if( bufp ) - strcpy( bufp, StrString ); - break; + case GADGETUP: + switch (gd->GadgetID) { + case 2: + aredone = 1; + if (bufp) + strcpy(bufp, StrString); + break; - case 1: - if( bufp ) - { - bufp[0]='\033'; - bufp[1]=0; - } - aredone = 1; - break; - } - break; + case 1: + if (bufp) { + bufp[0] = '\033'; + bufp[1] = 0; + } + aredone = 1; + break; + } + break; - case CLOSEWINDOW: - if( bufp ) - { - bufp[0]='\033'; - bufp[1]=0; - } - aredone = 1; - break; - } - ReplyMsg( (struct Message *) imsg ); - } + case CLOSEWINDOW: + if (bufp) { + bufp[0] = '\033'; + bufp[1] = 0; + } + aredone = 1; + break; + } + ReplyMsg((struct Message *) imsg); + } } - CloseWindow( cwin ); + CloseWindow(cwin); #else struct amii_WinDesc *cw; struct Window *w; int colx, ocolx, c; char *obufp; - amii_clear_nhwindow( WIN_MESSAGE ); - amii_putstr( WIN_MESSAGE, 0, prompt ); - cw = amii_wins[ WIN_MESSAGE ]; + amii_clear_nhwindow(WIN_MESSAGE); + amii_putstr(WIN_MESSAGE, 0, prompt); + cw = amii_wins[WIN_MESSAGE]; w = cw->win; - ocolx = colx = strlen( prompt ) + 1; + ocolx = colx = strlen(prompt) + 1; obufp = bufp; cursor_on(WIN_MESSAGE); - while((c = WindowGetchar()) != EOF) - { - cursor_off(WIN_MESSAGE); - amii_curs( WIN_MESSAGE, colx, 0 ); - if(c == '\033') - { - *obufp = c; - obufp[1] = 0; - return; - } - else if(c == '\b') - { - if(bufp != obufp) - { - bufp--; - amii_curs( WIN_MESSAGE, --colx, 0); - Text( w->RPort, "\177 ", 2 ); - amii_curs( WIN_MESSAGE, colx, 0); - } - else - DisplayBeep( NULL ); - } - else if( c == '\n' || c == '\r' ) - { - *bufp = 0; - amii_addtopl( obufp ); - return; - } - else if(' ' <= c && c < '\177') - { - /* avoid isprint() - some people don't have it - ' ' is not always a printing char */ - *bufp = c; - bufp[1] = 0; + while ((c = WindowGetchar()) != EOF) { + cursor_off(WIN_MESSAGE); + amii_curs(WIN_MESSAGE, colx, 0); + if (c == '\033') { + *obufp = c; + obufp[1] = 0; + return; + } else if (c == '\b') { + if (bufp != obufp) { + bufp--; + amii_curs(WIN_MESSAGE, --colx, 0); + Text(w->RPort, "\177 ", 2); + amii_curs(WIN_MESSAGE, colx, 0); + } else + DisplayBeep(NULL); + } else if (c == '\n' || c == '\r') { + *bufp = 0; + amii_addtopl(obufp); + return; + } else if (' ' <= c && c < '\177') { + /* avoid isprint() - some people don't have it + ' ' is not always a printing char */ + *bufp = c; + bufp[1] = 0; - Text( w->RPort, bufp, 1 ); - Text( w->RPort, "\177", 1 ); - if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO) - { - colx++; - bufp++; - } - } - else if(c == ('X'-64) || c == '\177') - { - amii_curs( WIN_MESSAGE, ocolx, 0 ); - Text( w->RPort, - " ", - colx - ocolx ); - amii_curs( WIN_MESSAGE, colx = ocolx, 0 ); - } else - DisplayBeep( NULL ); - cursor_on(WIN_MESSAGE); + Text(w->RPort, bufp, 1); + Text(w->RPort, "\177", 1); + if (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO) { + colx++; + bufp++; + } + } else if (c == ('X' - 64) || c == '\177') { + amii_curs(WIN_MESSAGE, ocolx, 0); + Text(w->RPort, " " + " ", + colx - ocolx); + amii_curs(WIN_MESSAGE, colx = ocolx, 0); + } else + DisplayBeep(NULL); + cursor_on(WIN_MESSAGE); } cursor_off(WIN_MESSAGE); *bufp = 0; #endif } -void amii_change_color( pen, val, rev ) - int pen, rev; - long val; +void +amii_change_color(pen, val, rev) +int pen, rev; +long val; { - if( rev ) - sysflags.amii_curmap[ pen ] = ~val; + if (rev) + sysflags.amii_curmap[pen] = ~val; else - sysflags.amii_curmap[ pen ] = val; + sysflags.amii_curmap[pen] = val; - if( HackScreen ) - LoadRGB4( &HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors ); + if (HackScreen) + LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors); } char * -amii_get_color_string( ) +amii_get_color_string() { int i; - char s[ 10 ]; - static char buf[ BUFSZ ]; + char s[10]; + static char buf[BUFSZ]; *buf = 0; - for( i = 0; i < min(32,amii_numcolors); ++i ) - { - sprintf( s, "%s%03lx", i ? "/" : "", (long)sysflags.amii_curmap[ i ] ); - strcat( buf, s ); + for (i = 0; i < min(32, amii_numcolors); ++i) { + sprintf(s, "%s%03lx", i ? "/" : "", (long) sysflags.amii_curmap[i]); + strcat(buf, s); } - return( buf ); + return (buf); } diff --git a/sys/amiga/winstr.c b/sys/amiga/winstr.c index bbb148def..efdeb898e 100644 --- a/sys/amiga/winstr.c +++ b/sys/amiga/winstr.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winstr.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winstr.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 winstr.c $Date: 2009/05/06 10:48:42 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)winstr.c 3.5 1993/04/02 */ /* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993. */ @@ -11,10 +11,10 @@ /* Put a string into the indicated window using the indicated attribute */ void -amii_putstr(window,attr,str) - winid window; - int attr; - const char *str; +amii_putstr(window, attr, str) +winid window; +int attr; +const char *str; { int fudge; int len; @@ -25,131 +25,123 @@ amii_putstr(window,attr,str) static int wrapping = 0; /* Always try to avoid a panic when there is no window */ - if( window == WIN_ERR ) - { - window = WIN_BASE; - if( window == WIN_ERR ) - window = WIN_BASE = amii_create_nhwindow( NHW_BASE ); + if (window == WIN_ERR) { + window = WIN_BASE; + if (window == WIN_ERR) + window = WIN_BASE = amii_create_nhwindow(NHW_BASE); } - if( window == WIN_ERR || ( cw = amii_wins[window] ) == NULL ) - { - iflags.window_inited=0; - panic(winpanicstr,window, "putstr"); + if (window == WIN_ERR || (cw = amii_wins[window]) == NULL) { + iflags.window_inited = 0; + panic(winpanicstr, window, "putstr"); } w = cw->win; - if(!str) return; - amiIDisplay->lastwin = window; /* do we care??? */ + if (!str) + return; + amiIDisplay->lastwin = window; /* do we care??? */ /* NHW_MENU windows are not opened immediately, so check if we * have the window pointer yet */ - if( w ) - { - /* Set the drawing mode and pen colors */ - SetDrMd( w->RPort, JAM2 ); - amii_sethipens( w, cw->type, attr ); - } - else if( cw->type != NHW_MENU && cw->type != NHW_TEXT ) - { - panic( "NULL window pointer in putstr 2: %d", window ); + if (w) { + /* Set the drawing mode and pen colors */ + SetDrMd(w->RPort, JAM2); + amii_sethipens(w, cw->type, attr); + } else if (cw->type != NHW_MENU && cw->type != NHW_TEXT) { + panic("NULL window pointer in putstr 2: %d", window); } /* Okay now do the work for each type */ - switch(cw->type) - { + switch (cw->type) { case NHW_MESSAGE: - if( WINVERS_AMIV ) - fudge = 2; - else - { - /* 8 for --more--, 1 for preceeding sp, 1 for putstr pad */ - fudge = 10; - } + if (WINVERS_AMIV) + fudge = 2; + else { + /* 8 for --more--, 1 for preceeding sp, 1 for putstr pad */ + fudge = 10; + } - /* There is a one pixel border at the borders, so subtract two */ - bottom = amii_msgborder( w ); + /* There is a one pixel border at the borders, so subtract two */ + bottom = amii_msgborder(w); - wheight = ( w->Height - w->BorderTop - - w->BorderBottom - 3 ) / w->RPort->TxHeight; - - if (scrollmsg || wheight > 1) - fudge = 0; + wheight = (w->Height - w->BorderTop - w->BorderBottom - 3) + / w->RPort->TxHeight; - amii_scrollmsg( w, cw ); + if (scrollmsg || wheight > 1) + fudge = 0; - while (isspace(*str)) str++; - strncpy( toplines, str, TBUFSZ ); - toplines[ TBUFSZ - 1 ] = 0; + amii_scrollmsg(w, cw); - /* For initial message to be visible, we need to explicitly position the - * cursor. This flag, cw->curx == -1 is set elsewhere to force the - * cursor to be repositioned to the "bottom". - */ - if( cw->curx == -1 ) - { - amii_curs( WIN_MESSAGE, 1, bottom ); - cw->curx = 0; - } + while (isspace(*str)) + str++; + strncpy(toplines, str, TBUFSZ); + toplines[TBUFSZ - 1] = 0; - /* If used all of history lines, move them down */ - if( cw->maxrow >= iflags.msg_history ) - { - if( cw->data[ 0 ] ) - free( cw->data[ 0 ] ); - memcpy( cw->data, &cw->data[ 1 ], - ( iflags.msg_history - 1 ) * sizeof( char * ) ); - cw->data[ iflags.msg_history - 1 ] = - (char *) alloc( strlen( toplines ) + 5 ); - strcpy( cw->data[ i = iflags.msg_history - 1 ] + - SOFF + (scrollmsg!=0), toplines ); - } - else - { - /* Otherwise, allocate a new one and copy the line in */ - cw->data[ cw->maxrow ] = (char *) - alloc( strlen( toplines ) + 5 ); - strcpy( cw->data[ i = cw->maxrow++ ] + - SOFF + (scrollmsg!=0), toplines ); - } - cw->data[ i ][ SEL_ITEM ] = 1; - cw->data[ i ][ VATTR ] = attr+1; + /* For initial message to be visible, we need to explicitly position + * the + * cursor. This flag, cw->curx == -1 is set elsewhere to force the + * cursor to be repositioned to the "bottom". + */ + if (cw->curx == -1) { + amii_curs(WIN_MESSAGE, 1, bottom); + cw->curx = 0; + } - if( scrollmsg ) - { - cw->curx = 0; - cw->data[ i ][2] = (cw->wflags & FLMSG_FIRST ) ? '>' : ' '; - } + /* If used all of history lines, move them down */ + if (cw->maxrow >= iflags.msg_history) { + if (cw->data[0]) + free(cw->data[0]); + memcpy(cw->data, &cw->data[1], + (iflags.msg_history - 1) * sizeof(char *)); + cw->data[iflags.msg_history - 1] = + (char *) alloc(strlen(toplines) + 5); + strcpy(cw->data[i = iflags.msg_history - 1] + SOFF + + (scrollmsg != 0), + toplines); + } else { + /* Otherwise, allocate a new one and copy the line in */ + cw->data[cw->maxrow] = (char *) alloc(strlen(toplines) + 5); + strcpy(cw->data[i = cw->maxrow++] + SOFF + (scrollmsg != 0), + toplines); + } + cw->data[i][SEL_ITEM] = 1; + cw->data[i][VATTR] = attr + 1; - str = cw->data[i] + SOFF; - if( cw->curx + strlen(str) >= (cw->cols-fudge) ) - { - int i; - char *ostr = (char *)str; - char *p; + if (scrollmsg) { + cw->curx = 0; + cw->data[i][2] = (cw->wflags & FLMSG_FIRST) ? '>' : ' '; + } - while( cw->curx + strlen( str ) >= (cw->cols-fudge) ) - { - for(p=((char *)&str[ cw->cols-1 - cw->curx ])-fudge; !isspace(*p) && p > str;) - --p; - if (p < str) p = (char *)str; + str = cw->data[i] + SOFF; + if (cw->curx + strlen(str) >= (cw->cols - fudge)) { + int i; + char *ostr = (char *) str; + char *p; - if( p == str ) { - /* p = (char *)&str[ cw->cols ]; */ - outmore(cw); - continue; - } + while (cw->curx + strlen(str) >= (cw->cols - fudge)) { + for (p = ((char *) &str[cw->cols - 1 - cw->curx]) - fudge; + !isspace(*p) && p > str;) + --p; + if (p < str) + p = (char *) str; - i = (long)p-(long)str; - outsubstr( cw, (char *)str, i, fudge ); - cw->curx += i; + if (p == str) { + /* p = (char *)&str[ cw->cols ]; */ + outmore(cw); + continue; + } - while(isspace(*p)) p++; - str = p; + i = (long) p - (long) str; + outsubstr(cw, (char *) str, i, fudge); + cw->curx += i; + + while (isspace(*p)) + p++; + str = p; #if 0 if( str != ostr ) { @@ -157,263 +149,247 @@ amii_putstr(window,attr,str) cw->curx+=2; } #endif - if(*str) - amii_scrollmsg( w, cw ); - amii_cl_end( cw, cw->curx ); - } + if (*str) + amii_scrollmsg(w, cw); + amii_cl_end(cw, cw->curx); + } - if( *str ) - { - if( str != ostr ) - { - outsubstr( cw, "+", 1, fudge ); - cw->curx+=2; - } - while ( isspace( *str ) ) - ++str; - outsubstr( cw, (char *)str, i = strlen( (char *)str ), fudge ); - cw->curx += i; - amii_cl_end( cw, cw->curx ); - } - } - else - { - outsubstr( cw, (char *)str, i = strlen( (char *)str ), fudge ); - cw->curx += i; - amii_cl_end( cw, cw->curx ); - } - cw->wflags &= ~FLMSG_FIRST; - len = 0; - if( scrollmsg ) - { - totalvis = CountLines( window ); - SetPropInfo( w, &MsgScroll, - ( w->Height-w->BorderTop-w->BorderBottom ) / w->RPort->TxHeight, - totalvis, totalvis ); - } - i = strlen( toplines + SOFF ); - cw->maxcol = max( cw->maxcol, i ); - cw->vwy = cw->maxrow; - break; + if (*str) { + if (str != ostr) { + outsubstr(cw, "+", 1, fudge); + cw->curx += 2; + } + while (isspace(*str)) + ++str; + outsubstr(cw, (char *) str, i = strlen((char *) str), fudge); + cw->curx += i; + amii_cl_end(cw, cw->curx); + } + } else { + outsubstr(cw, (char *) str, i = strlen((char *) str), fudge); + cw->curx += i; + amii_cl_end(cw, cw->curx); + } + cw->wflags &= ~FLMSG_FIRST; + len = 0; + if (scrollmsg) { + totalvis = CountLines(window); + SetPropInfo(w, &MsgScroll, + (w->Height - w->BorderTop - w->BorderBottom) + / w->RPort->TxHeight, + totalvis, totalvis); + } + i = strlen(toplines + SOFF); + cw->maxcol = max(cw->maxcol, i); + cw->vwy = cw->maxrow; + break; case NHW_STATUS: - if( cw->data[ cw->cury ] == NULL ) - panic( "NULL pointer for status window" ); - ob = &cw->data[cw->cury][j = cw->curx]; - if(flags.botlx) *ob = 0; + if (cw->data[cw->cury] == NULL) + panic("NULL pointer for status window"); + ob = &cw->data[cw->cury][j = cw->curx]; + if (flags.botlx) + *ob = 0; - /* Display when beam at top to avoid flicker... */ - WaitTOF(); - Text(w->RPort,(char *)str,strlen((char *)str)); - if( cw->cols > strlen( str ) ) - TextSpaces( w->RPort, cw->cols - strlen( str ) ); + /* Display when beam at top to avoid flicker... */ + WaitTOF(); + Text(w->RPort, (char *) str, strlen((char *) str)); + if (cw->cols > strlen(str)) + TextSpaces(w->RPort, cw->cols - strlen(str)); - (void) strncpy(cw->data[cw->cury], str, cw->cols ); - cw->data[cw->cury][cw->cols-1] = '\0'; /* null terminate */ - cw->cury = (cw->cury+1) % 2; - cw->curx = 0; - break; + (void) strncpy(cw->data[cw->cury], str, cw->cols); + cw->data[cw->cury][cw->cols - 1] = '\0'; /* null terminate */ + cw->cury = (cw->cury + 1) % 2; + cw->curx = 0; + break; case NHW_MAP: case NHW_BASE: - if (cw->type == NHW_BASE && wrapping) { - amii_curs(window, cw->curx+1, cw->cury); - TextSpaces(w->RPort, cw->cols); - if (cw->cury < cw->rows) { - amii_curs(window, cw->curx+1, cw->cury+1); - TextSpaces(w->RPort, cw->cols); - cw->cury--; - } - } - amii_curs(window, cw->curx+1, cw->cury); - Text(w->RPort,(char *)str,strlen((char *)str)); - cw->curx = 0; - /* CR-LF is automatic in these windows */ - cw->cury++; - if (cw->type == NHW_BASE && cw->cury >= cw->rows) { - cw->cury = 0; - wrapping = 1; - } - break; + if (cw->type == NHW_BASE && wrapping) { + amii_curs(window, cw->curx + 1, cw->cury); + TextSpaces(w->RPort, cw->cols); + if (cw->cury < cw->rows) { + amii_curs(window, cw->curx + 1, cw->cury + 1); + TextSpaces(w->RPort, cw->cols); + cw->cury--; + } + } + amii_curs(window, cw->curx + 1, cw->cury); + Text(w->RPort, (char *) str, strlen((char *) str)); + cw->curx = 0; + /* CR-LF is automatic in these windows */ + cw->cury++; + if (cw->type == NHW_BASE && cw->cury >= cw->rows) { + cw->cury = 0; + wrapping = 1; + } + break; case NHW_MENU: case NHW_TEXT: - /* always grows one at a time, but alloc 12 at a time */ + /* always grows one at a time, but alloc 12 at a time */ - if( cw->cury >= cw->rows || !cw->data ) - { - char **tmp; + if (cw->cury >= cw->rows || !cw->data) { + char **tmp; - /* Allocate 12 more rows */ - cw->rows += 12; - tmp = (char**) alloc(sizeof(char*) * cw->rows); + /* Allocate 12 more rows */ + cw->rows += 12; + tmp = (char **) alloc(sizeof(char *) * cw->rows); - /* Copy the old lines */ - for(i=0; icury; i++) - tmp[i] = cw->data[i]; + /* Copy the old lines */ + for (i = 0; i < cw->cury; i++) + tmp[i] = cw->data[i]; - if( cw->data ) { - free( cw->data ); - cw->data = NULL; - } + if (cw->data) { + free(cw->data); + cw->data = NULL; + } - cw->data = tmp; + cw->data = tmp; - /* Null out the unused entries. */ - for(i=cw->cury; irows; i++) - cw->data[i] = 0; - } + /* Null out the unused entries. */ + for (i = cw->cury; i < cw->rows; i++) + cw->data[i] = 0; + } - if( !cw->data ) - panic("no data storage"); + if (!cw->data) + panic("no data storage"); - /* Shouldn't need to do this, but... */ + /* Shouldn't need to do this, but... */ - if( cw->data && cw->data[cw->cury] ) { - free( cw->data[cw->cury] ); - cw->data[cw->cury] = NULL; - } + if (cw->data && cw->data[cw->cury]) { + free(cw->data[cw->cury]); + cw->data[cw->cury] = NULL; + } - n0 = strlen(str)+1; - cw->data[cw->cury] = (char*) alloc(n0+SOFF); + n0 = strlen(str) + 1; + cw->data[cw->cury] = (char *) alloc(n0 + SOFF); - /* avoid nuls, for convenience */ - cw->data[cw->cury][VATTR] = attr+1; - cw->data[cw->cury][SEL_ITEM] = 0; - Strcpy( cw->data[cw->cury] + SOFF, str); + /* avoid nuls, for convenience */ + cw->data[cw->cury][VATTR] = attr + 1; + cw->data[cw->cury][SEL_ITEM] = 0; + Strcpy(cw->data[cw->cury] + SOFF, str); - if(n0 > cw->maxcol) cw->maxcol = n0; - if(++cw->cury > cw->maxrow) cw->maxrow = cw->cury; - break; + if (n0 > cw->maxcol) + cw->maxcol = n0; + if (++cw->cury > cw->maxrow) + cw->maxrow = cw->cury; + break; default: - panic("Invalid or unset window type in putstr()"); + panic("Invalid or unset window type in putstr()"); } } void -amii_scrollmsg( w, cw ) - register struct Window *w; - register struct amii_WinDesc *cw; +amii_scrollmsg(w, cw) +register struct Window *w; +register struct amii_WinDesc *cw; { int bottom, wheight; - bottom = amii_msgborder( w ); + bottom = amii_msgborder(w); - wheight = ( w->Height - w->BorderTop - - w->BorderBottom - 3 ) / w->RPort->TxHeight; - - if( scrollmsg ) - { - if( ++cw->disprows > wheight ) - { - outmore( cw ); - cw->disprows = 1; /* count this line... */ - } - else - { - ScrollRaster( w->RPort, 0, w->RPort->TxHeight, - w->BorderLeft, w->BorderTop + 1, - w->Width - w->BorderRight-1, - w->Height - w->BorderBottom - 1 ); - } - amii_curs( WIN_MESSAGE, 1, bottom ); + wheight = + (w->Height - w->BorderTop - w->BorderBottom - 3) / w->RPort->TxHeight; + + if (scrollmsg) { + if (++cw->disprows > wheight) { + outmore(cw); + cw->disprows = 1; /* count this line... */ + } else { + ScrollRaster(w->RPort, 0, w->RPort->TxHeight, w->BorderLeft, + w->BorderTop + 1, w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); + } + amii_curs(WIN_MESSAGE, 1, bottom); } } int -amii_msgborder( w ) - struct Window *w; +amii_msgborder(w) +struct Window *w; { register int bottom; /* There is a one pixel border at the borders, so subtract two */ bottom = w->Height - w->BorderTop - w->BorderBottom - 2; bottom /= w->RPort->TxHeight; - if( bottom > 0 ) - --bottom; - return( bottom ); + if (bottom > 0) + --bottom; + return (bottom); } void -outmore( cw ) - register struct amii_WinDesc *cw; +outmore(cw) +register struct amii_WinDesc *cw; { struct Window *w = cw->win; - if((cw->wflags & FLMAP_SKIP) == 0) - { - if( scrollmsg ) - { - int bottom; + if ((cw->wflags & FLMAP_SKIP) == 0) { + if (scrollmsg) { + int bottom; - bottom = amii_msgborder( w ); + bottom = amii_msgborder(w); - ScrollRaster( w->RPort, 0, w->RPort->TxHeight, - w->BorderLeft, w->BorderTop+1, - w->Width - w->BorderRight-1, - w->Height - w->BorderBottom - 1 ); - amii_curs( WIN_MESSAGE, 1, bottom ); /* -1 for inner border */ - Text( w->RPort, "--more--", 8 ); - } - else - Text( w->RPort, " --more--", 9 ); + ScrollRaster(w->RPort, 0, w->RPort->TxHeight, w->BorderLeft, + w->BorderTop + 1, w->Width - w->BorderRight - 1, + w->Height - w->BorderBottom - 1); + amii_curs(WIN_MESSAGE, 1, bottom); /* -1 for inner border */ + Text(w->RPort, "--more--", 8); + } else + Text(w->RPort, " --more--", 9); - /* Make sure there are no events in the queue */ - flushIDCMP( HackPort ); + /* Make sure there are no events in the queue */ + flushIDCMP(HackPort); - /* Allow mouse clicks to clear --more-- */ - WindowGetchar(); - if( lastevent.type == WEKEY && lastevent.un.key == '\33' ) - cw->wflags |= FLMAP_SKIP; + /* Allow mouse clicks to clear --more-- */ + WindowGetchar(); + if (lastevent.type == WEKEY && lastevent.un.key == '\33') + cw->wflags |= FLMAP_SKIP; } - if( !scrollmsg ) - { - amii_curs( WIN_MESSAGE, 1, 0 ); - amii_cl_end( cw, cw->curx ); + if (!scrollmsg) { + amii_curs(WIN_MESSAGE, 1, 0); + amii_cl_end(cw, cw->curx); } } void -outsubstr( cw, str, len, fudge ) - register struct amii_WinDesc *cw; - char *str; - int len; - int fudge; +outsubstr(cw, str, len, fudge) +register struct amii_WinDesc *cw; +char *str; +int len; +int fudge; { struct Window *w = cw->win; - if( cw->curx ) - { - /* Check if this string and --more-- fit, if not, - * then put out --more-- and wait for a key. - */ - if( (len + fudge ) + cw->curx >= cw->cols ) - { - if( !scrollmsg ) - outmore( cw ); - } - else - { - /* Otherwise, move and put out a blank separator */ - Text( w->RPort, spaces, 1 ); - cw->curx += 1; - } + if (cw->curx) { + /* Check if this string and --more-- fit, if not, + * then put out --more-- and wait for a key. + */ + if ((len + fudge) + cw->curx >= cw->cols) { + if (!scrollmsg) + outmore(cw); + } else { + /* Otherwise, move and put out a blank separator */ + Text(w->RPort, spaces, 1); + cw->curx += 1; + } } - Text(w->RPort,str,len); + Text(w->RPort, str, len); } /* Put a graphics character onto the screen */ void -amii_putsym( st, i, y, c ) - winid st; - int i, y; - CHAR_P c; +amii_putsym(st, i, y, c) +winid st; +int i, y; +CHAR_P c; { - amii_curs( st, i, y ); + amii_curs(st, i, y); Text(amii_wins[st]->win->RPort, &c, 1); } @@ -421,33 +397,32 @@ amii_putsym( st, i, y, c ) void amii_addtopl(s) - const char *s; +const char *s; { register struct amii_WinDesc *cw = amii_wins[WIN_MESSAGE]; - while(*s) { - if(cw->curx == cw->cols - 1) - amii_putstr(WIN_MESSAGE, 0, ""); - amii_putsym(WIN_MESSAGE, cw->curx + 1, amii_msgborder(cw->win), *s++); - cw->curx++; + while (*s) { + if (cw->curx == cw->cols - 1) + amii_putstr(WIN_MESSAGE, 0, ""); + amii_putsym(WIN_MESSAGE, cw->curx + 1, amii_msgborder(cw->win), *s++); + cw->curx++; } } void -TextSpaces( rp, nr ) - struct RastPort *rp; - int nr; +TextSpaces(rp, nr) +struct RastPort *rp; +int nr; { - if( nr < 1 ) - return; + if (nr < 1) + return; - while (nr > sizeof(spaces) - 1) - { - Text(rp, spaces, (long)sizeof(spaces) - 1); - nr -= sizeof(spaces) - 1; + while (nr > sizeof(spaces) - 1) { + Text(rp, spaces, (long) sizeof(spaces) - 1); + nr -= sizeof(spaces) - 1; } if (nr > 0) - Text(rp, spaces, (long)nr); + Text(rp, spaces, (long) nr); } void @@ -465,60 +440,55 @@ amii_doprev_message() struct Window *w; char *str; - if( WIN_MESSAGE == WIN_ERR || - ( cw = amii_wins[ WIN_MESSAGE ] ) == NULL || ( w = cw->win ) == NULL ) - { - panic(winpanicstr,WIN_MESSAGE, "doprev_message"); + if (WIN_MESSAGE == WIN_ERR || (cw = amii_wins[WIN_MESSAGE]) == NULL + || (w = cw->win) == NULL) { + panic(winpanicstr, WIN_MESSAGE, "doprev_message"); } - /* When an interlaced/tall screen is in use, the scroll bar will be there */ + /* When an interlaced/tall screen is in use, the scroll bar will be there + */ /* Or in some other cases as well */ - if( scrollmsg ) - { - struct Gadget *gd; - struct PropInfo *pip; - int hidden, topidx, i, total, wheight; + if (scrollmsg) { + struct Gadget *gd; + struct PropInfo *pip; + int hidden, topidx, i, total, wheight; - for( gd = w->FirstGadget; gd && gd->GadgetID != 1; ) - gd = gd->NextGadget; + for (gd = w->FirstGadget; gd && gd->GadgetID != 1;) + gd = gd->NextGadget; - if( gd ) - { - pip = (struct PropInfo *)gd->SpecialInfo; - wheight = ( w->Height - w->BorderTop - - w->BorderBottom - 2 ) / w->RPort->TxHeight; - hidden = max( cw->maxrow - wheight, 0 ); - topidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16; - for( total = i = 0; i < cw->maxrow; ++i ) - { - if( cw->data[i][1] != 0 ) - ++total; - } + if (gd) { + pip = (struct PropInfo *) gd->SpecialInfo; + wheight = (w->Height - w->BorderTop - w->BorderBottom - 2) + / w->RPort->TxHeight; + hidden = max(cw->maxrow - wheight, 0); + topidx = (((ULONG) hidden * pip->VertPot) + (MAXPOT / 2)) >> 16; + for (total = i = 0; i < cw->maxrow; ++i) { + if (cw->data[i][1] != 0) + ++total; + } - i = 0; - topidx -= wheight/4 + 1; - if (topidx < 0) - topidx = 0; - SetPropInfo( w, &MsgScroll, wheight, total, topidx ); - DisplayData( WIN_MESSAGE, topidx ); - } - return(0); + i = 0; + topidx -= wheight / 4 + 1; + if (topidx < 0) + topidx = 0; + SetPropInfo(w, &MsgScroll, wheight, total, topidx); + DisplayData(WIN_MESSAGE, topidx); + } + return (0); } - if( --cw->vwy < 0 ) - { - cw->maxcol = 0; - DisplayBeep( NULL ); - str = "\0\0No more history saved..."; - } - else - str = cw->data[ cw->vwy ]; + if (--cw->vwy < 0) { + cw->maxcol = 0; + DisplayBeep(NULL); + str = "\0\0No more history saved..."; + } else + str = cw->data[cw->vwy]; amii_cl_end(cw, 0); - amii_curs( WIN_MESSAGE, 1, 0 ); - amii_setdrawpens( amii_wins[WIN_MESSAGE]->win, NHW_MESSAGE ); - Text(w->RPort,str+SOFF,strlen(str+SOFF)); + amii_curs(WIN_MESSAGE, 1, 0); + amii_setdrawpens(amii_wins[WIN_MESSAGE]->win, NHW_MESSAGE); + Text(w->RPort, str + SOFF, strlen(str + SOFF)); cw->curx = cw->cols + 1; - return( 0 ); + return (0); } diff --git a/sys/amiga/xpm2iff.c b/sys/amiga/xpm2iff.c index fcbfee217..2d6000c70 100644 --- a/sys/amiga/xpm2iff.c +++ b/sys/amiga/xpm2iff.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 xpm2iff.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 xpm2iff.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 xpm2iff.c $Date: 2009/05/06 10:48:44 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)xpm2iff.c 3.5 1995/08/04 */ /* Copyright (c) 1995 by Gregg Wonderly, Naperville, Illinois */ @@ -18,28 +18,28 @@ #include #include #ifndef _DCC -# include -# include -# include +#include +#include +#include #endif struct xpmscreen { - int Width; - int Height; - int Colors; - int ColorResolution; - int Background; - int AspectRatio; - int Interlace; - int BytesPerRow; + int Width; + int Height; + int Colors; + int ColorResolution; + int Background; + int AspectRatio; + int Interlace; + int BytesPerRow; } XpmScreen; /* translation table from xpm characters to RGB and colormap slots */ struct Ttable { - char flag; - char r,g,b; - int slot; /* output colortable index */ -}ttable[256]; + char flag; + char r, g, b; + int slot; /* output colortable index */ +} ttable[256]; pixval ColorMap[3][MAXCOLORMAPSIZE]; int colorsinmap; @@ -48,18 +48,20 @@ int colorsinmap; * We are using a hybrid form of our own design which we call a BMAP (for * bitmap) form. It is an ILBM with the bitmaps already deinterleaved, * completely uncompressed. - * This speeds the loading of the images from the games point of view because it + * This speeds the loading of the images from the games point of view because + * it * does not have to deinterleave and uncompress them. */ -#define ID_BMAP MAKE_ID( 'B', 'M', 'A', 'P' ) /* instead of ILBM */ -#define ID_BMHD MAKE_ID( 'B', 'M', 'H', 'D' ) /* Same as ILBM */ -#define ID_CAMG MAKE_ID( 'C', 'A', 'M', 'G' ) /* Same as ILBM */ -#define ID_CMAP MAKE_ID( 'C', 'M', 'A', 'P' ) /* Same as ILBM */ -#define ID_PDAT MAKE_ID( 'P', 'D', 'A', 'T' ) /* Extra data describing plane - * size due to graphics.library - * rounding requirements. - */ -#define ID_PLNE MAKE_ID( 'P', 'L', 'N', 'E' ) /* The planes of the image */ +#define ID_BMAP MAKE_ID('B', 'M', 'A', 'P') /* instead of ILBM */ +#define ID_BMHD MAKE_ID('B', 'M', 'H', 'D') /* Same as ILBM */ +#define ID_CAMG MAKE_ID('C', 'A', 'M', 'G') /* Same as ILBM */ +#define ID_CMAP MAKE_ID('C', 'M', 'A', 'P') /* Same as ILBM */ +#define ID_PDAT \ + MAKE_ID('P', 'D', 'A', 'T') /* Extra data describing plane \ + * size due to graphics.library \ + * rounding requirements. \ + */ +#define ID_PLNE MAKE_ID('P', 'L', 'N', 'E') /* The planes of the image */ int nplanes; @@ -84,93 +86,86 @@ pixel pixels[TILE_Y][TILE_X]; AmiColorMap *cmap; void -error( char *str ) +error(char *str) { - fprintf( stderr, "ERROR: %s\n", str ); + fprintf(stderr, "ERROR: %s\n", str); } char **planes; -main( int argc, char **argv ) +main(int argc, char **argv) { int colors; struct { - long nplanes; - long pbytes; - long across; - long down; - long npics; - long xsize; - long ysize; + long nplanes; + long pbytes; + long across; + long down; + long npics; + long xsize; + long ysize; } pdat; - long pbytes; /* Bytes of data in a plane */ + long pbytes; /* Bytes of data in a plane */ int i, cnt; BitMapHeader bmhd; struct IFFHandle *iff; - long camg = HIRES|LACE; - int tiles=0; + long camg = HIRES | LACE; + int tiles = 0; int index; -#if defined(_DCC) || defined (__GNUC__) - IFFParseBase = OpenLibrary( "iffparse.library", 0 ); - if( !IFFParseBase ) { - error( "unable to open iffparse.library" ); - exit( 1 ); +#if defined(_DCC) || defined(__GNUC__) + IFFParseBase = OpenLibrary("iffparse.library", 0); + if (!IFFParseBase) { + error("unable to open iffparse.library"); + exit(1); } #endif - if( fopen_xpm_file( argv[1], "r" ) != TRUE ) - { - perror( argv[1] ); - return( 1 ); + if (fopen_xpm_file(argv[1], "r") != TRUE) { + perror(argv[1]); + return (1); } nplanes = 0; i = XpmScreen.Colors - 1; - while( i != 0 ) - { - nplanes++; - i >>= 1; + while (i != 0) { + nplanes++; + i >>= 1; } - planes = malloc( nplanes * sizeof( char * ) ); - if( planes == 0 ) - { - error( "can not allocate planes pointer" ); - exit( 1 ); + planes = malloc(nplanes * sizeof(char *)); + if (planes == 0) { + error("can not allocate planes pointer"); + exit(1); } - XpmScreen.BytesPerRow = ((XpmScreen.Width + 15)/16)*2; + XpmScreen.BytesPerRow = ((XpmScreen.Width + 15) / 16) * 2; pbytes = XpmScreen.BytesPerRow * XpmScreen.Height; - for( i = 0; i < nplanes; ++i ) - { - planes[ i ] = malloc( pbytes ); - if( planes[ i ] == 0 ) - { - error( "can not allocate planes pointer" ); - exit( 1 ); - } - memset( planes[i], 0, pbytes ); + for (i = 0; i < nplanes; ++i) { + planes[i] = malloc(pbytes); + if (planes[i] == 0) { + error("can not allocate planes pointer"); + exit(1); + } + memset(planes[i], 0, pbytes); } iff = AllocIFF(); - if( !iff ) - { - error( "Can not allocate IFFHandle" ); - return( 1 ); + if (!iff) { + error("Can not allocate IFFHandle"); + return (1); } - iff->iff_Stream = Open( argv[2], MODE_NEWFILE ); - if( !iff->iff_Stream ) - { - error( "Can not open output file" ); - return( 1 ); + iff->iff_Stream = Open(argv[2], MODE_NEWFILE); + if (!iff->iff_Stream) { + error("Can not open output file"); + return (1); } - InitIFFasDOS( iff ); - OpenIFF( iff, IFFF_WRITE ); + InitIFFasDOS(iff); + OpenIFF(iff, IFFF_WRITE); - PushChunk( iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN ); + PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN); bmhd.w = XpmScreen.Width; bmhd.h = XpmScreen.Height; @@ -183,35 +178,35 @@ main( int argc, char **argv ) bmhd.transparentColor = 0; bmhd.xAspect = 100; bmhd.yAspect = 100; - bmhd.pageWidth = 0; /* not needed for this program */ - bmhd.pageHeight = 0; /* not needed for this program */ + bmhd.pageWidth = 0; /* not needed for this program */ + bmhd.pageHeight = 0; /* not needed for this program */ - PushChunk( iff, ID_BMAP, ID_BMHD, sizeof( bmhd ) ); - WriteChunkBytes( iff, &bmhd, sizeof( bmhd ) ); - PopChunk( iff ); + PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd)); + WriteChunkBytes(iff, &bmhd, sizeof(bmhd)); + PopChunk(iff); - PushChunk( iff, ID_BMAP, ID_CAMG, sizeof( camg ) ); - WriteChunkBytes( iff, &camg, sizeof( camg ) ); - PopChunk( iff ); + PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg)); + WriteChunkBytes(iff, &camg, sizeof(camg)); + PopChunk(iff); #define SCALE(x) (x) - cmap = malloc( (colors = (1L<iff_Stream ); - FreeIFF( iff ); + CloseIFF(iff); + Close(iff->iff_Stream); + FreeIFF(iff); -#if defined(_DCC) || defined (__GNUC__) - CloseLibrary( IFFParseBase ); +#if defined(_DCC) || defined(__GNUC__) + CloseLibrary(IFFParseBase); #endif - exit( 0 ); + exit(0); } -#define SETBIT(Plane, Plane_offset, Col, Value) \ - if(Value){ \ - planes[Plane][Plane_offset + (Col/8)] |= 1<<(7-(Col & 7)); \ - } +#define SETBIT(Plane, Plane_offset, Col, Value) \ + if (Value) { \ + planes[Plane][Plane_offset + (Col / 8)] |= 1 << (7 - (Col & 7)); \ + } -conv_image(){ +conv_image() +{ int row, col, planeno; - for(row = 0;row if any */ - for(bp = buf;*bp;bp++); - bp--; - while(isspace(*bp))bp--; - if(*bp==',')bp--; - if(*bp=='"')bp--; - bp++; - *bp = '\0'; +xpmgetline() +{ + char *bp; + do { + if (fgets(buf, bufsz, xpmfh) == 0) + return 0; + } while (buf[0] != '"'); + /* strip off the trailing <",> if any */ + for (bp = buf; *bp; bp++) + ; + bp--; + while (isspace(*bp)) + bp--; + if (*bp == ',') + bp--; + if (*bp == '"') + bp--; + bp++; + *bp = '\0'; - return &buf[1]; + return &buf[1]; } diff --git a/sys/atari/tos.c b/sys/atari/tos.c index 1e746875c..33fef380a 100644 --- a/sys/atari/tos.c +++ b/sys/atari/tos.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tos.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 tos.c $NHDT-Date: 1431192784 2015/05/09 17:33:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 tos.c $Date: 2009/05/06 10:48:51 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)tos.c 3.5 1990/14/08 /* NetHack may be freely redistributed. See license for details. */ @@ -11,50 +11,50 @@ #include "hack.h" #ifdef TTY_GRAPHICS -# include "tcap.h" +#include "tcap.h" #else /* To avoid error for tos.c; will be removed later */ -static char *nh_HE="\033q"; +static char *nh_HE = "\033q"; #endif #ifdef TOS -# include -# ifndef WORD -# define WORD short /* 16 bits -- redefine if necessary */ -# endif +#include +#ifndef WORD +#define WORD short /* 16 bits -- redefine if necessary */ +#endif #include static char NDECL(DOSgetch); static char NDECL(BIOSgetch); static void NDECL(init_aline); -char *_a_line; /* for Line A variables */ -# ifdef TEXTCOLOR +char *_a_line; /* for Line A variables */ +#ifdef TEXTCOLOR boolean colors_changed = FALSE; -# endif +#endif int tgetch() { - char ch; + char ch; - /* BIOSgetch can use the numeric key pad on IBM compatibles. */ - if (iflags.BIOS) - ch = BIOSgetch(); - else - ch = DOSgetch(); - return ((ch == '\r') ? '\n' : ch); + /* BIOSgetch can use the numeric key pad on IBM compatibles. */ + if (iflags.BIOS) + ch = BIOSgetch(); + else + ch = DOSgetch(); + return ((ch == '\r') ? '\n' : ch); } /* * Keyboard translation tables. */ -#define KEYPADLO 0x61 -#define KEYPADHI 0x71 +#define KEYPADLO 0x61 +#define KEYPADHI 0x71 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -62,44 +62,46 @@ tgetch() * shift values below. */ static const struct pad { - char normal, shift, cntrl; -} keypad[PADKEYS] = { - {C('['), 'Q', C('[')}, /* UNDO */ - {'?', '/', '?'}, /* HELP */ - {'(', 'a', '('}, /* ( */ - {')', 'w', ')'}, /* ) */ - {'/', '/', '/'}, /* / */ - {C('p'), '$', C('p')}, /* * */ - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'h', 'H', C('h')}, /* 4 */ - {'.', '.', '.'}, - {'l', 'L', C('l')}, /* 6 */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {C('['), 'Q', C('[')} , /* UNDO */ - {'?', '/', '?'}, /* HELP */ - {'(', 'a', '('}, /* ( */ - {')', 'w', ')'}, /* ) */ - {'/', '/', '/'}, /* / */ - {C('p'), '$', C('p')}, /* * */ - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'4', M('4'), '4'}, /* 4 */ - {'.', '.', '.'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + char normal, shift, cntrl; +} keypad[PADKEYS] = + { + { C('['), 'Q', C('[') }, /* UNDO */ + { '?', '/', '?' }, /* HELP */ + { '(', 'a', '(' }, /* ( */ + { ')', 'w', ')' }, /* ) */ + { '/', '/', '/' }, /* / */ + { C('p'), '$', C('p') }, /* * */ + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'h', 'H', C('h') }, /* 4 */ + { '.', '.', '.' }, + { 'l', 'L', C('l') }, /* 6 */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { C('['), 'Q', C('[') }, /* UNDO */ + { '?', '/', '?' }, /* HELP */ + { '(', 'a', '(' }, /* ( */ + { ')', 'w', ')' }, /* ) */ + { '/', '/', '/' }, /* / */ + { C('p'), '$', C('p') }, /* * */ + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { '4', M('4'), '4' }, /* 4 */ + { '.', '.', '.' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; /* * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII @@ -109,81 +111,82 @@ static const struct pad { * scan code table to translate the scan code into a letter, then set the * "meta" bit for it. -3. */ -#define SCANLO 0x10 +#define SCANLO 0x10 -static const char scanmap[] = { /* ... */ - 'q','w','e','r','t','y','u','i','o','p','[',']', '\n', - 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`', - 0, '\\', 'z','x','c','v','b','N','m',',','.','?' /* ... */ +static const char scanmap[] = { + /* ... */ + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', + 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', + 'c', 'v', 'b', 'N', 'm', ',', '.', '?' /* ... */ }; -#define inmap(x) (SCANLO <= (x) && (x) < SCANLO + SIZE(scanmap)) +#define inmap(x) (SCANLO <= (x) && (x) < SCANLO + SIZE(scanmap)) /* * BIOSgetch gets keys directly with a BIOS call. */ -#define SHIFT (0x1 | 0x2) -#define CTRL 0x4 -#define ALT 0x8 +#define SHIFT (0x1 | 0x2) +#define CTRL 0x4 +#define ALT 0x8 static char BIOSgetch() { - unsigned char scan, shift, ch; - const struct pad *kpad; + unsigned char scan, shift, ch; + const struct pad *kpad; - long x; + long x; - /* Get scan code. - */ - x = Crawcin(); - ch = x & 0x0ff; - scan = (x & 0x00ff0000L) >> 16; - /* Get shift status. - */ - shift = Kbshift(-1); + /* Get scan code. + */ + x = Crawcin(); + ch = x & 0x0ff; + scan = (x & 0x00ff0000L) >> 16; + /* Get shift status. + */ + shift = Kbshift(-1); - /* Translate keypad keys */ - if (iskeypad(scan)) { - kpad = iflags.num_pad ? numpad : keypad; - if (shift & SHIFT) - ch = kpad[scan - KEYPADLO].shift; - else if (shift & CTRL) - ch = kpad[scan - KEYPADLO].cntrl; - else - ch = kpad[scan - KEYPADLO].normal; - } - /* Translate unassigned Alt-letters */ - if ((shift & ALT) && !ch) { - if (inmap(scan)) - ch = scanmap[scan - SCANLO]; - return (isprint(ch) ? M(ch) : ch); - } - return ch; + /* Translate keypad keys */ + if (iskeypad(scan)) { + kpad = iflags.num_pad ? numpad : keypad; + if (shift & SHIFT) + ch = kpad[scan - KEYPADLO].shift; + else if (shift & CTRL) + ch = kpad[scan - KEYPADLO].cntrl; + else + ch = kpad[scan - KEYPADLO].normal; + } + /* Translate unassigned Alt-letters */ + if ((shift & ALT) && !ch) { + if (inmap(scan)) + ch = scanmap[scan - SCANLO]; + return (isprint(ch) ? M(ch) : ch); + } + return ch; } static char DOSgetch() { - return (Crawcin() & 0x007f); + return (Crawcin() & 0x007f); } - long freediskspace(path) char *path; { - int drive = 0; - struct { - long freal; /*free allocation units*/ - long total; /*total number of allocation units*/ - long bps; /*bytes per sector*/ - long pspal; /*physical sectors per allocation unit*/ - } freespace; - if (path[0] && path[1] == ':') - drive = (toupper(path[0]) - 'A') + 1; - if (Dfree(&freespace,drive)<0) return -1; - return freespace.freal*freespace.bps*freespace.pspal; + int drive = 0; + struct { + long freal; /*free allocation units*/ + long total; /*total number of allocation units*/ + long bps; /*bytes per sector*/ + long pspal; /*physical sectors per allocation unit*/ + } freespace; + if (path[0] && path[1] == ':') + drive = (toupper(path[0]) - 'A') + 1; + if (Dfree(&freespace, drive) < 0) + return -1; + return freespace.freal * freespace.bps * freespace.pspal; } /* @@ -193,29 +196,29 @@ int findfirst(path) char *path; { - return (Fsfirst(path, 0) == 0); + return (Fsfirst(path, 0) == 0); } int findnext() { - return (Fsnext() == 0); + return (Fsnext() == 0); } char * foundfile_buffer() { - return (char *)Fgetdta() + 30; + return (char *) Fgetdta() + 30; } long filesize(file) char *file; { - if (findfirst(file)) - return (* (long *) ((char *)Fgetdta() + 26)); - else - return -1L; + if (findfirst(file)) + return (*(long *) ((char *) Fgetdta() + 26)); + else + return -1L; } /* @@ -225,150 +228,151 @@ void chdrive(str) char *str; { - char *ptr; - char drive; + char *ptr; + char drive; - if ((ptr = index(str, ':')) != (char *)0) { - drive = toupper(*(ptr - 1)); - (void)Dsetdrv(drive - 'A'); - } - return; + if ((ptr = index(str, ':')) != (char *) 0) { + drive = toupper(*(ptr - 1)); + (void) Dsetdrv(drive - 'A'); + } + return; } - void get_scr_size() { -# ifdef MINT -# include - struct winsize win; - char *tmp; +#ifdef MINT +#include + struct winsize win; + char *tmp; - if((tmp=nh_getenv("LINES"))) - LI = atoi(tmp); - else if((tmp=nh_getenv("ROWS"))) - LI = atoi(tmp); - if(tmp && (tmp=nh_getenv("COLUMNS"))) - CO = atoi(tmp); - else { - ioctl(0,TIOCGWINSZ, &win); - LI = win.ws_row; - CO = win.ws_col; - } -# else - init_aline(); - LI = (*((WORD *)(_a_line + -42L))) + 1; - CO = (*((WORD *)(_a_line + -44L))) + 1; -# endif + if ((tmp = nh_getenv("LINES"))) + LI = atoi(tmp); + else if ((tmp = nh_getenv("ROWS"))) + LI = atoi(tmp); + if (tmp && (tmp = nh_getenv("COLUMNS"))) + CO = atoi(tmp); + else { + ioctl(0, TIOCGWINSZ, &win); + LI = win.ws_row; + CO = win.ws_col; + } +#else + init_aline(); + LI = (*((WORD *) (_a_line + -42L))) + 1; + CO = (*((WORD *) (_a_line + -44L))) + 1; +#endif } -# define BIGBUF 8192 +#define BIGBUF 8192 int _copyfile(from, to) char *from, *to; { - int fromfd, tofd, r; - char *buf; + int fromfd, tofd, r; + char *buf; - if ((fromfd = open(from, O_RDONLY|O_BINARY, 0)) < 0) - return -1; - if ((tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, FCMASK)) < 0) - return -1; - buf = (char *)alloc((size_t)BIGBUF); - while ( (r = read(fromfd, buf, BIGBUF)) > 0) - write(tofd, buf, r); - close(fromfd); - close(tofd); - free(buf); - return 0; /* successful */ + if ((fromfd = open(from, O_RDONLY | O_BINARY, 0)) < 0) + return -1; + if ((tofd = open(to, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, FCMASK)) + < 0) + return -1; + buf = (char *) alloc((size_t) BIGBUF); + while ((r = read(fromfd, buf, BIGBUF)) > 0) + write(tofd, buf, r); + close(fromfd); + close(tofd); + free(buf); + return 0; /* successful */ } -int kbhit() +int +kbhit() { - return Cconis(); + return Cconis(); } static void init_aline() { -# ifdef __GNUC__ -/* line A calls nuke registers d0-d2,a0-a2; not all compilers regard these - as scratch registers, though, so we save them - */ - asm(" moveml d0-d2/a0-a2, sp@-"); - asm(" .word 0xa000; movel d0, __a_line"); - asm(" moveml sp@+, d0-d2/a0-a2"); -# else - asm(" movem.l d0-d2/a0-a2, -(sp)"); - asm(" .dc.w 0xa000"); /* tweak as necessary for your compiler */ - asm(" move.l d0, __a_line"); - asm(" movem.l (sp)+, d0-d2/a0-a2"); -# endif +#ifdef __GNUC__ + /* line A calls nuke registers d0-d2,a0-a2; not all compilers regard these + as scratch registers, though, so we save them + */ + asm(" moveml d0-d2/a0-a2, sp@-"); + asm(" .word 0xa000; movel d0, __a_line"); + asm(" moveml sp@+, d0-d2/a0-a2"); +#else + asm(" movem.l d0-d2/a0-a2, -(sp)"); + asm(" .dc.w 0xa000"); /* tweak as necessary for your compiler */ + asm(" move.l d0, __a_line"); + asm(" movem.l (sp)+, d0-d2/a0-a2"); +#endif } -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR /* used in termcap.c to decide how to set up the hilites */ unsigned long tos_numcolors = 2; void set_colors() { - static char colorHE[] = "\033q\033b0"; + static char colorHE[] = "\033q\033b0"; - if (!iflags.BIOS) - return; - init_aline(); - tos_numcolors = 1 << (((unsigned char *) _a_line)[1]); - if (tos_numcolors <= 2) { /* mono */ - iflags.use_color = FALSE; - return; - } else { - colors_changed = TRUE; - nh_HE = colorHE; - } + if (!iflags.BIOS) + return; + init_aline(); + tos_numcolors = 1 << (((unsigned char *) _a_line)[1]); + if (tos_numcolors <= 2) { /* mono */ + iflags.use_color = FALSE; + return; + } else { + colors_changed = TRUE; + nh_HE = colorHE; + } } void restore_colors() { - static char plainHE[] = "\033q"; + static char plainHE[] = "\033q"; - if (colors_changed) - nh_HE = plainHE; - colors_changed = FALSE; + if (colors_changed) + nh_HE = plainHE; + colors_changed = FALSE; } -# endif /* TEXTCOLOR */ +#endif /* TEXTCOLOR */ -# ifdef SUSPEND +#ifdef SUSPEND -#include +#include -# ifdef MINT +#ifdef MINT extern int __mint; -# endif +#endif int -dosuspend() { -# ifdef MINT - extern int kill(); - if (__mint == 0) { -# endif - pline("Sorry, it seems we have no SIGTSTP here. Try ! or S."); -# ifdef MINT - } - else if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) { - suspend_nhwindows((char *)0); - (void) signal(SIGTSTP, SIG_DFL); - (void) kill(0, SIGTSTP); - get_scr_size(); - resume_nhwindows(); - } else { - pline("I don't think your shell has job control."); - } -# endif /* MINT */ - return(0); +dosuspend() +{ +#ifdef MINT + extern int kill(); + if (__mint == 0) { +#endif + pline("Sorry, it seems we have no SIGTSTP here. Try ! or S."); +#ifdef MINT + } else if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { + suspend_nhwindows((char *) 0); + (void) signal(SIGTSTP, SIG_DFL); + (void) kill(0, SIGTSTP); + get_scr_size(); + resume_nhwindows(); + } else { + pline("I don't think your shell has job control."); + } +#endif /* MINT */ + return (0); } -# endif /* SUSPEND */ +#endif /* SUSPEND */ #endif /* TOS */ diff --git a/sys/be/bemain.c b/sys/be/bemain.c index 089611c70..9e8181f59 100644 --- a/sys/be/bemain.c +++ b/sys/be/bemain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 bemain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 bemain.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ /* NetHack 3.6 bemain.c $Date: 2009/05/06 10:48:59 $ $Revision: 1.11 $ */ /* SCCS Id: @(#)bemain.c 3.5 2008/01/30 */ /* Copyright (c) Dean Luick, 1996. */ @@ -14,245 +14,254 @@ static void chdirx(const char *dir); static void getlock(void); #ifdef __begui__ - #define MAIN nhmain - int nhmain(int argc, char **argv); +#define MAIN nhmain +int nhmain(int argc, char **argv); #else - #define MAIN main +#define MAIN main #endif - -int MAIN(int argc, char **argv) +int +MAIN(int argc, char **argv) { - int fd; - char *dir; - boolean resuming = FALSE; /* assume new game */ + int fd; + char *dir; + boolean resuming = FALSE; /* assume new game */ - sys_early_init(); + sys_early_init(); - dir = nh_getenv("NETHACKDIR"); - if (!dir) dir = nh_getenv("HACKDIR"); + dir = nh_getenv("NETHACKDIR"); + if (!dir) + dir = nh_getenv("HACKDIR"); - choose_windows(DEFAULT_WINDOW_SYS); - chdirx(dir); - initoptions(); + choose_windows(DEFAULT_WINDOW_SYS); + chdirx(dir); + initoptions(); - init_nhwindows(&argc, argv); - whoami(); + init_nhwindows(&argc, argv); + whoami(); - /* - * It seems you really want to play. - */ - u.uhp = 1; /* prevent RIP on early quits */ - process_options(argc, argv); /* command line options */ + /* + * It seems you really want to play. + */ + u.uhp = 1; /* prevent RIP on early quits */ + process_options(argc, argv); /* command line options */ - set_playmode(); /* sets plname to "wizard" for wizard mode */ - /* strip role,race,&c suffix; calls askname() if plname[] is empty - or holds a generic user name like "player" or "games" */ - plnamesuffix(); - /* unlike Unix where the game might be invoked with a script - which forces a particular character name for each player - using a shared account, we always allow player to rename - the character during role/race/&c selection */ - iflags.renameallowed = TRUE; + set_playmode(); /* sets plname to "wizard" for wizard mode */ + /* strip role,race,&c suffix; calls askname() if plname[] is empty + or holds a generic user name like "player" or "games" */ + plnamesuffix(); + /* unlike Unix where the game might be invoked with a script + which forces a particular character name for each player + using a shared account, we always allow player to rename + the character during role/race/&c selection */ + iflags.renameallowed = TRUE; - getlock(); + getlock(); - dlb_init(); /* must be before newgame() */ + dlb_init(); /* must be before newgame() */ - /* - * Initialize the vision system. This must be before mklev() on a - * new game or before a level restore on a saved game. - */ - vision_init(); + /* + * Initialize the vision system. This must be before mklev() on a + * new game or before a level restore on a saved game. + */ + vision_init(); - display_gamewindows(); + display_gamewindows(); - /* - * First, try to find and restore a save file for specified character. - * We'll return here if new game player_selection() renames the hero. - */ - attempt_restore: - if ((fd = restore_saved_game()) >= 0) { +/* + * First, try to find and restore a save file for specified character. + * We'll return here if new game player_selection() renames the hero. + */ +attempt_restore: + if ((fd = restore_saved_game()) >= 0) { #ifdef NEWS - if(iflags.news) { - display_file(NEWS, FALSE); - iflags.news = FALSE; /* in case dorecover() fails */ - } + if (iflags.news) { + display_file(NEWS, FALSE); + iflags.news = FALSE; /* in case dorecover() fails */ + } #endif - pline("Restoring save file..."); - mark_synch(); /* flush output */ - if (dorecover(fd)) { - resuming = TRUE; /* not starting new game */ - if (discover) - You("are in non-scoring discovery mode."); - if (discover || wizard) { - if(yn("Do you want to keep the save file?") == 'n') - (void) delete_savefile(); - else { - nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); - } - } - } - } + pline("Restoring save file..."); + mark_synch(); /* flush output */ + if (dorecover(fd)) { + resuming = TRUE; /* not starting new game */ + if (discover) + You("are in non-scoring discovery mode."); + if (discover || wizard) { + if (yn("Do you want to keep the save file?") == 'n') + (void) delete_savefile(); + else { + nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); + } + } + } + } - if (!resuming) { - /* new game: start by choosing role, race, etc; - player might change the hero's name while doing that, - in which case we try to restore under the new name - and skip selection this time if that didn't succeed */ - if (!iflags.renameinprogress) { - player_selection(); - if (iflags.renameinprogress) { - /* player has renamed the hero while selecting role; - discard current lock file and create another for - the new character name */ - delete_levelfile(0); /* remove empty lock file */ - getlock(); - goto attempt_restore; - } - } - newgame(); - if (discover) - You("are in non-scoring discovery mode."); - } + if (!resuming) { + /* new game: start by choosing role, race, etc; + player might change the hero's name while doing that, + in which case we try to restore under the new name + and skip selection this time if that didn't succeed */ + if (!iflags.renameinprogress) { + player_selection(); + if (iflags.renameinprogress) { + /* player has renamed the hero while selecting role; + discard current lock file and create another for + the new character name */ + delete_levelfile(0); /* remove empty lock file */ + getlock(); + goto attempt_restore; + } + } + newgame(); + if (discover) + You("are in non-scoring discovery mode."); + } - moveloop(resuming); - return 0; + moveloop(resuming); + return 0; } -static void whoami(void) +static void +whoami(void) { - /* - * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS - * 2. Use $USER or $LOGNAME (if 1. fails) - * The resulting name is overridden by command line options. - * If everything fails, or if the resulting name is some generic - * account like "games", "play", "player", "hack" then eventually - * we'll ask him. - */ - char *s; + /* + * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS + * 2. Use $USER or $LOGNAME (if 1. fails) + * The resulting name is overridden by command line options. + * If everything fails, or if the resulting name is some generic + * account like "games", "play", "player", "hack" then eventually + * we'll ask him. + */ + char *s; - if (*plname) return; - if (s = nh_getenv("USER")) { - (void) strncpy(plname, s, sizeof(plname)-1); - return; - } - if (s = nh_getenv("LOGNAME")) { - (void) strncpy(plname, s, sizeof(plname)-1); - return; - } + if (*plname) + return; + if (s = nh_getenv("USER")) { + (void) strncpy(plname, s, sizeof(plname) - 1); + return; + } + if (s = nh_getenv("LOGNAME")) { + (void) strncpy(plname, s, sizeof(plname) - 1); + return; + } } /* normalize file name - we don't like .'s, /'s, spaces */ -void regularize(char *s) +void +regularize(char *s) { - register char *lp; + register char *lp; - while((lp=strchr(s, '.')) || (lp=strchr(s, '/')) || (lp=strchr(s,' '))) - *lp = '_'; + while ((lp = strchr(s, '.')) || (lp = strchr(s, '/')) + || (lp = strchr(s, ' '))) + *lp = '_'; } -static void process_options(int argc, char **argv) +static void +process_options(int argc, char **argv) { - int i; + int i; - while (argc > 1 && argv[1][0] == '-') { - argv++; - argc--; - switch (argv[0][1]) { - case 'D': - wizard = TRUE, discover = FALSE; - break; - /* otherwise fall thru to discover */ - case 'X': - discover = TRUE, wizard = FALSE; - break; + while (argc > 1 && argv[1][0] == '-') { + argv++; + argc--; + switch (argv[0][1]) { + case 'D': + wizard = TRUE, discover = FALSE; + break; + /* otherwise fall thru to discover */ + case 'X': + discover = TRUE, wizard = FALSE; + break; #ifdef NEWS - case 'n': - iflags.news = FALSE; - break; + case 'n': + iflags.news = FALSE; + break; #endif - case 'u': - if(argv[0][2]) - (void) strncpy(plname, argv[0]+2, sizeof(plname)-1); - else if (argc > 1) { - argc--; - argv++; - (void) strncpy(plname, argv[0], sizeof(plname)-1); - } else - raw_print("Player name expected after -u"); - break; - case 'p': /* profession (role) */ - if (argv[0][2]) { - if ((i = str2role(&argv[0][2])) >= 0) - flags.initrole = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2role(argv[0])) >= 0) - flags.initrole = i; - } - break; - case 'r': /* race */ - if (argv[0][2]) { - if ((i = str2race(&argv[0][2])) >= 0) - flags.initrace = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2race(argv[0])) >= 0) - flags.initrace = i; - } - break; - case '@': - flags.randomall = 1; - break; - default: - raw_printf("Unknown option: %s", *argv); - break; - } - } + case 'u': + if (argv[0][2]) + (void) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); + else if (argc > 1) { + argc--; + argv++; + (void) strncpy(plname, argv[0], sizeof(plname) - 1); + } else + raw_print("Player name expected after -u"); + break; + case 'p': /* profession (role) */ + if (argv[0][2]) { + if ((i = str2role(&argv[0][2])) >= 0) + flags.initrole = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2role(argv[0])) >= 0) + flags.initrole = i; + } + break; + case 'r': /* race */ + if (argv[0][2]) { + if ((i = str2race(&argv[0][2])) >= 0) + flags.initrace = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2race(argv[0])) >= 0) + flags.initrace = i; + } + break; + case '@': + flags.randomall = 1; + break; + default: + raw_printf("Unknown option: %s", *argv); + break; + } + } } -static void chdirx(const char *dir) +static void +chdirx(const char *dir) { - if (!dir) dir = HACKDIR; + if (!dir) + dir = HACKDIR; - if (chdir(dir) < 0) - error("Cannot chdir to %s.", dir); + if (chdir(dir) < 0) + error("Cannot chdir to %s.", dir); - /* Warn the player if we can't write the record file */ - /* perhaps we should also test whether . is writable */ - check_recordfile(dir); + /* Warn the player if we can't write the record file */ + /* perhaps we should also test whether . is writable */ + check_recordfile(dir); } -void getlock(void) +void +getlock(void) { - int fd; + int fd; - Sprintf(lock, "%d%s", getuid(), plname); - regularize(lock); - set_levelfile_name(lock, 0); - fd = creat(lock, FCMASK); - if(fd == -1) { - error("cannot creat lock file."); - } else { - if(write(fd, (genericptr_t) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ - error("cannot write lock"); - } - if(close(fd) == -1) { - error("cannot close lock"); - } - } + Sprintf(lock, "%d%s", getuid(), plname); + regularize(lock); + set_levelfile_name(lock, 0); + fd = creat(lock, FCMASK); + if (fd == -1) { + error("cannot creat lock file."); + } else { + if (write(fd, (genericptr_t) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { + error("cannot write lock"); + } + if (close(fd) == -1) { + error("cannot close lock"); + } + } } /* validate wizard mode if player has requested access to it */ boolean authorize_wizard_mode() { - /* other ports validate user name or character name here */ - return TRUE; + /* other ports validate user name or character name here */ + return TRUE; } #ifndef __begui__ @@ -261,9 +270,10 @@ authorize_wizard_mode() * do anything extra. */ void nethack_exit(int status); -void nethack_exit(int status) +void +nethack_exit(int status) { - exit(status); + exit(status); } #endif /* !__begui__ */ diff --git a/sys/mac/dprintf.c b/sys/mac/dprintf.c index f2c238373..43aa52674 100644 --- a/sys/mac/dprintf.c +++ b/sys/mac/dprintf.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dprintf.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dprintf.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 dprintf.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)dprintf.c 3.5 1994/01/29 */ /* Copyright (c) Jon W{tte, 1993. */ @@ -8,42 +8,43 @@ #include "macwin.h" static Boolean -KeyDown (unsigned short code) { -unsigned char keys [16]; +KeyDown(unsigned short code) +{ + unsigned char keys[16]; - GetKeys ((void *) keys); - return ((keys [code >> 3] >> (code & 7)) & 1) != 0; + GetKeys((void *) keys); + return ((keys[code >> 3] >> (code & 7)) & 1) != 0; } - void -dprintf (char *format, ...) +dprintf(char *format, ...) { -char buffer [500]; -va_list list; -int doit; + char buffer[500]; + va_list list; + int doit; #define DO_DEBUGSTR 1 #define DO_PLINE 2 - if (flags.debug) { - doit = 0; - if (macFlags.hasDebugger && KeyDown (0x39)) { /* Caps Lock */ - doit = DO_DEBUGSTR; - } else if (KeyDown (0x3B) && iflags.window_inited && /* Control */ - (WIN_MESSAGE != -1) && theWindows [WIN_MESSAGE].its_window) { - doit = DO_PLINE; - } - - if (doit) { - va_start (list, format); - vsprintf (&buffer [1], format, list); - va_end (list) ; + if (flags.debug) { + doit = 0; + if (macFlags.hasDebugger && KeyDown(0x39)) { /* Caps Lock */ + doit = DO_DEBUGSTR; + } else if (KeyDown(0x3B) && iflags.window_inited && /* Control */ + (WIN_MESSAGE != -1) + && theWindows[WIN_MESSAGE].its_window) { + doit = DO_PLINE; + } - if (doit == DO_DEBUGSTR) { - buffer [0] = strlen (&buffer [1]); - DebugStr ((uchar *) buffer); - } else if (doit == DO_PLINE) - pline ("%s", &buffer [1]); - } - } + if (doit) { + va_start(list, format); + vsprintf(&buffer[1], format, list); + va_end(list); + + if (doit == DO_DEBUGSTR) { + buffer[0] = strlen(&buffer[1]); + DebugStr((uchar *) buffer); + } else if (doit == DO_PLINE) + pline("%s", &buffer[1]); + } + } } diff --git a/sys/mac/maccurs.c b/sys/mac/maccurs.c index 19b68aadc..3591e97b3 100644 --- a/sys/mac/maccurs.c +++ b/sys/mac/maccurs.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 maccurs.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 maccurs.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 maccurs.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)maccurs.c 3.5 1993/01/24 */ /* Copyright (c) Jon W{tte, 1992. */ @@ -14,212 +14,201 @@ #include #endif - static Boolean winFileInit = 0; -static unsigned char winFileName [32] = "\pNetHack Preferences"; +static unsigned char winFileName[32] = "\pNetHack Preferences"; static long winFileDir; static short winFileVol; typedef struct WinPosSave { - char validPos; - char validSize; - short top; - short left; - short height; - short width; + char validPos; + char validSize; + short top; + short left; + short height; + short width; } WinPosSave; -static WinPosSave savePos [kLastWindowKind + 1]; - +static WinPosSave savePos[kLastWindowKind + 1]; static void -InitWinFile (void) +InitWinFile(void) { - StringHandle sh; - long len; - short ref = 0; + StringHandle sh; + long len; + short ref = 0; - if (winFileInit) { - return; - } -/* We trust the glue. If there's an error, store in game dir. */ - if (FindFolder (kOnSystemDisk, kPreferencesFolderType, kCreateFolder , - &winFileVol, &winFileDir)) { - winFileVol = 0; - winFileDir = 0; - } - sh = GetString (128); - if (sh && *sh) { - BlockMove (*sh, winFileName, **sh + 1); - ReleaseResource ((Handle) sh); - } - if (HOpen (winFileVol, winFileDir, winFileName, fsRdPerm, &ref)) { - return; - } - len = sizeof (savePos); - if (!FSRead (ref, &len, savePos)) { - winFileInit = 1; - } - FSClose (ref); + if (winFileInit) { + return; + } + /* We trust the glue. If there's an error, store in game dir. */ + if (FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder, + &winFileVol, &winFileDir)) { + winFileVol = 0; + winFileDir = 0; + } + sh = GetString(128); + if (sh && *sh) { + BlockMove(*sh, winFileName, **sh + 1); + ReleaseResource((Handle) sh); + } + if (HOpen(winFileVol, winFileDir, winFileName, fsRdPerm, &ref)) { + return; + } + len = sizeof(savePos); + if (!FSRead(ref, &len, savePos)) { + winFileInit = 1; + } + FSClose(ref); } - static void -FlushWinFile (void) +FlushWinFile(void) { - short ref; - long len; + short ref; + long len; - if (!winFileInit) { - if (!winFileName [0]) { - return; - } - HCreate (winFileVol, winFileDir, winFileName, MAC_CREATOR, PREF_TYPE); - HCreateResFile (winFileVol, winFileDir, winFileName); - } - if (HOpen (winFileVol, winFileDir, winFileName, fsWrPerm, &ref)) { - return; - } - winFileInit = 1; - len = sizeof (savePos); - (void) FSWrite (ref, &len, savePos); /* Don't care about error */ - FSClose (ref); + if (!winFileInit) { + if (!winFileName[0]) { + return; + } + HCreate(winFileVol, winFileDir, winFileName, MAC_CREATOR, PREF_TYPE); + HCreateResFile(winFileVol, winFileDir, winFileName); + } + if (HOpen(winFileVol, winFileDir, winFileName, fsWrPerm, &ref)) { + return; + } + winFileInit = 1; + len = sizeof(savePos); + (void) FSWrite(ref, &len, savePos); /* Don't care about error */ + FSClose(ref); } Boolean -RetrievePosition (short kind, short *top, short *left) { -Point p; +RetrievePosition(short kind, short *top, short *left) +{ + Point p; - if (kind < 0 || kind > kLastWindowKind) { - dprintf ("Retrieve Bad kind %d", kind); - return 0; - } - InitWinFile (); - if (!savePos [kind].validPos) { - dprintf ("Retrieve Not stored kind %d", kind); - return 0; - } - p.v = savePos [kind].top; - p.h = savePos [kind].left; - *left = p.h; - *top = p.v; - dprintf ("Retrieve Kind %d Pt (%d,%d)", kind, p.h, p.v); - return (PtInRgn (p, GetGrayRgn ())); + if (kind < 0 || kind > kLastWindowKind) { + dprintf("Retrieve Bad kind %d", kind); + return 0; + } + InitWinFile(); + if (!savePos[kind].validPos) { + dprintf("Retrieve Not stored kind %d", kind); + return 0; + } + p.v = savePos[kind].top; + p.h = savePos[kind].left; + *left = p.h; + *top = p.v; + dprintf("Retrieve Kind %d Pt (%d,%d)", kind, p.h, p.v); + return (PtInRgn(p, GetGrayRgn())); } - Boolean -RetrieveSize (short kind, short top, short left, short *height, short *width) +RetrieveSize(short kind, short top, short left, short *height, short *width) { - Point p; + Point p; - if (kind < 0 || kind > kLastWindowKind) { - return 0; - } - InitWinFile (); - if (!savePos [kind].validSize) { - return 0; - } - *width = savePos [kind].width; - *height = savePos [kind].height; - p.h = left + *width; - p.v = top + *height; - return PtInRgn (p, GetGrayRgn ()); + if (kind < 0 || kind > kLastWindowKind) { + return 0; + } + InitWinFile(); + if (!savePos[kind].validSize) { + return 0; + } + *width = savePos[kind].width; + *height = savePos[kind].height; + p.h = left + *width; + p.v = top + *height; + return PtInRgn(p, GetGrayRgn()); } - static void -SavePosition (short kind, short top, short left) +SavePosition(short kind, short top, short left) { - if (kind < 0 || kind > kLastWindowKind) { - dprintf ("Save bad kind %d", kind); - return; - } - InitWinFile(); - savePos[kind].validPos = 1; - savePos[kind].top = top; - savePos[kind].left = left; - dprintf("Save kind %d pt (%d,%d)", kind, left, top); - FlushWinFile(); + if (kind < 0 || kind > kLastWindowKind) { + dprintf("Save bad kind %d", kind); + return; + } + InitWinFile(); + savePos[kind].validPos = 1; + savePos[kind].top = top; + savePos[kind].left = left; + dprintf("Save kind %d pt (%d,%d)", kind, left, top); + FlushWinFile(); } - static void -SaveSize (short kind, short height, short width) +SaveSize(short kind, short height, short width) { - if (kind < 0 || kind > kLastWindowKind) { - dprintf ("Save bad kind %d", kind); - return; - } - InitWinFile (); - savePos [kind].validSize = 1; - savePos [kind].width = width; - savePos [kind].height = height; - FlushWinFile (); + if (kind < 0 || kind > kLastWindowKind) { + dprintf("Save bad kind %d", kind); + return; + } + InitWinFile(); + savePos[kind].validSize = 1; + savePos[kind].width = width; + savePos[kind].height = height; + FlushWinFile(); } - static short -GetWinKind (WindowPtr win) +GetWinKind(WindowPtr win) { - short kind; + short kind; - if (!CheckNhWin (win)) { - return -1; - } - kind = GetWindowKind(win) - WIN_BASE_KIND; - if (kind < 0 || kind > NHW_TEXT) { - return -1; - } - dprintf ("In win kind %d (%lx)", kind, win); - switch (kind) { - case NHW_MAP : - case NHW_STATUS : - case NHW_BASE : - kind = kMapWindow; - break; - case NHW_MESSAGE : - kind = kMessageWindow; - break; - case NHW_MENU : - kind = kMenuWindow; - break; - default : - kind = kTextWindow; - break; - } - dprintf ("Out kind %d", kind); - return kind; + if (!CheckNhWin(win)) { + return -1; + } + kind = GetWindowKind(win) - WIN_BASE_KIND; + if (kind < 0 || kind > NHW_TEXT) { + return -1; + } + dprintf("In win kind %d (%lx)", kind, win); + switch (kind) { + case NHW_MAP: + case NHW_STATUS: + case NHW_BASE: + kind = kMapWindow; + break; + case NHW_MESSAGE: + kind = kMessageWindow; + break; + case NHW_MENU: + kind = kMenuWindow; + break; + default: + kind = kTextWindow; + break; + } + dprintf("Out kind %d", kind); + return kind; } - Boolean RetrieveWinPos(WindowPtr win, short *top, short *left) { - return RetrievePosition(GetWinKind (win), top, left); + return RetrievePosition(GetWinKind(win), top, left); } - void SaveWindowPos(WindowPtr win) { - Rect r; + Rect r; - - GetWindowBounds(win, kWindowContentRgn, &r); - SavePosition(GetWinKind(win), r.top, r.left); + GetWindowBounds(win, kWindowContentRgn, &r); + SavePosition(GetWinKind(win), r.top, r.left); } - void SaveWindowSize(WindowPtr win) { - short width, height; - Rect r; + short width, height; + Rect r; - - GetWindowBounds(win, kWindowContentRgn, &r); - width = r.right - r.left; - height = r.bottom - r.top; - SaveSize(GetWinKind (win), height, width); + GetWindowBounds(win, kWindowContentRgn, &r); + width = r.right - r.left; + height = r.bottom - r.top; + SaveSize(GetWinKind(win), height, width); } diff --git a/sys/mac/macerrs.c b/sys/mac/macerrs.c index 6ed11f9eb..092032b11 100644 --- a/sys/mac/macerrs.c +++ b/sys/mac/macerrs.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macerrs.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macerrs.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 macerrs.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)macerrs.c 3.5 1993/01/24 */ /* Copyright (c) Michael Hamel, 1991 */ @@ -17,26 +17,25 @@ #include #endif - -void error(const char *format,...) +void +error(const char *format, ...) { - Str255 buf; - va_list ap; + Str255 buf; + va_list ap; - va_start(ap, format); - vsprintf((char *)buf, format, ap); - va_end(ap); + va_start(ap, format); + vsprintf((char *) buf, format, ap); + va_end(ap); - C2P((char *)buf, buf); - ParamText(buf, (StringPtr)"", (StringPtr)"", (StringPtr)""); - Alert(128, (ModalFilterUPP) NULL); - ExitToShell(); + C2P((char *) buf, buf); + ParamText(buf, (StringPtr) "", (StringPtr) "", (StringPtr) ""); + Alert(128, (ModalFilterUPP) NULL); + ExitToShell(); } +#if 0 /* Remainder of file is obsolete and will be removed */ -#if 0 /* Remainder of file is obsolete and will be removed */ - -#define stackDepth 1 +#define stackDepth 1 #define errAlertID 129 #define stdIOErrID 1999 @@ -95,34 +94,33 @@ void mustwork(short errcode) else ExitToShell(); } - #if defined(USE_STDARG) || defined(USE_VARARGS) -# ifdef USE_STDARG +#ifdef USE_STDARG static void vprogerror(const char *line, va_list the_args); -# else +#else static void vprogerror(); -# endif +#endif /* Macro substitute for error() */ -void error VA_DECL(const char *, line) +void error VA_DECL(const char *, line){ VA_START(line); VA_INIT(line, char *); vprogerror(line, VA_ARGS); VA_END(); } -# ifdef USE_STDARG +#ifdef USE_STDARG static void vprogerror(const char *line, va_list the_args) { -# else +#else static void vprogerror(line, the_args) const char *line; va_list the_args; { -# endif +#endif -#else /* USE_STDARG | USE_VARARG */ +#else /* USE_STDARG | USE_VARARG */ void -error VA_DECL(const char *, line) +error VA_DECL(const char *, line){ #endif /* Do NOT use VA_START and VA_END in here... see above */ char pbuf[BUFSZ]; diff --git a/sys/mac/macfile.c b/sys/mac/macfile.c index 041ab4ced..9d4c3c4e4 100644 --- a/sys/mac/macfile.c +++ b/sys/mac/macfile.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macfile.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macfile.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 macfile.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)macfile.c 3.5 1993/01/24 */ /* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */ @@ -27,201 +27,200 @@ * the situation at startup... For now, this will have to do. */ - /* The HandleFiles are resources built into the application which are treated as read-only files: if we fail to open a file we look for a resource */ - -#define FIRST_HF 32000 /* file ID of first HandleFile */ -#define MAX_HF 6 /* Max # of open HandleFiles */ -#define APP_NAME_RES_ID (-16396) +#define FIRST_HF 32000 /* file ID of first HandleFile */ +#define MAX_HF 6 /* Max # of open HandleFiles */ + +#define APP_NAME_RES_ID (-16396) typedef struct handlefile { - long type; /* Resource type */ - short id; /* Resource id */ - long mark; /* Current position */ - long size; /* total size */ - Handle data; /* The resource, purgeable */ + long type; /* Resource type */ + short id; /* Resource id */ + long mark; /* Current position */ + long size; /* total size */ + Handle data; /* The resource, purgeable */ } HandleFile; -static HandleFile *FDECL(IsHandleFile,(int)); -static int FDECL(OpenHandleFile,(const unsigned char *, long)); -static int FDECL(CloseHandleFile,(int)); -static int FDECL(ReadHandleFile,(int, void *, unsigned)); -static long FDECL(SetHandleFilePos,(int, short, long)); - -HandleFile theHandleFiles [MAX_HF]; -MacDirs theDirs; /* also referenced in macwin.c */ +static HandleFile *FDECL(IsHandleFile, (int)); +static int FDECL(OpenHandleFile, (const unsigned char *, long)); +static int FDECL(CloseHandleFile, (int)); +static int FDECL(ReadHandleFile, (int, void *, unsigned)); +static long FDECL(SetHandleFilePos, (int, short, long)); +HandleFile theHandleFiles[MAX_HF]; +MacDirs theDirs; /* also referenced in macwin.c */ static HandleFile * IsHandleFile(int fd) { - HandleFile *hfp = NULL; + HandleFile *hfp = NULL; - if (fd >= FIRST_HF && fd < FIRST_HF+MAX_HF) { - /* in valid range, check for data */ - hfp = &theHandleFiles[fd-FIRST_HF]; - if (!hfp->data) hfp = NULL; - } - return hfp; + if (fd >= FIRST_HF && fd < FIRST_HF + MAX_HF) { + /* in valid range, check for data */ + hfp = &theHandleFiles[fd - FIRST_HF]; + if (!hfp->data) + hfp = NULL; + } + return hfp; } - static int -OpenHandleFile (const unsigned char *name, long fileType) +OpenHandleFile(const unsigned char *name, long fileType) { - int i; - Handle h; - Str255 s; + int i; + Handle h; + Str255 s; - for (i = 0; i < MAX_HF; i ++) { - if (theHandleFiles[i].data == 0L) break; - } - - if (i >= MAX_HF) - return -1; + for (i = 0; i < MAX_HF; i++) { + if (theHandleFiles[i].data == 0L) + break; + } - h = GetNamedResource (fileType, name); - if (!h) return (-1); - - theHandleFiles[i].data = h; - theHandleFiles[i].size = GetHandleSize (h); - GetResInfo (h, &theHandleFiles[i].id, (void*) &theHandleFiles[i].type, s); - theHandleFiles[i].mark = 0L; + if (i >= MAX_HF) + return -1; - return(i + FIRST_HF); + h = GetNamedResource(fileType, name); + if (!h) + return (-1); + + theHandleFiles[i].data = h; + theHandleFiles[i].size = GetHandleSize(h); + GetResInfo(h, &theHandleFiles[i].id, (void *) &theHandleFiles[i].type, s); + theHandleFiles[i].mark = 0L; + + return (i + FIRST_HF); } - static int -CloseHandleFile (int fd) +CloseHandleFile(int fd) { - if (!IsHandleFile (fd)) { - return -1; - } - fd -= FIRST_HF; - ReleaseResource (theHandleFiles[fd].data); - theHandleFiles[fd].data = 0L; - return(0); + if (!IsHandleFile(fd)) { + return -1; + } + fd -= FIRST_HF; + ReleaseResource(theHandleFiles[fd].data); + theHandleFiles[fd].data = 0L; + return (0); } - static int -ReadHandleFile (int fd, void *ptr, unsigned len) +ReadHandleFile(int fd, void *ptr, unsigned len) { - unsigned maxBytes; - Handle h; + unsigned maxBytes; + Handle h; - if (!IsHandleFile (fd)) return -1; - - fd -= FIRST_HF; - maxBytes = theHandleFiles[fd].size - theHandleFiles[fd].mark; - if (len > maxBytes) len = maxBytes; - - h = theHandleFiles[fd].data; - - HLock(h); - BlockMove (*h + theHandleFiles[fd].mark, ptr, len); - HUnlock(h); - theHandleFiles[fd].mark += len; - - return(len); + if (!IsHandleFile(fd)) + return -1; + + fd -= FIRST_HF; + maxBytes = theHandleFiles[fd].size - theHandleFiles[fd].mark; + if (len > maxBytes) + len = maxBytes; + + h = theHandleFiles[fd].data; + + HLock(h); + BlockMove(*h + theHandleFiles[fd].mark, ptr, len); + HUnlock(h); + theHandleFiles[fd].mark += len; + + return (len); } - static long -SetHandleFilePos (int fd, short whence, long pos) +SetHandleFilePos(int fd, short whence, long pos) { - long curpos; - - if (!IsHandleFile (fd)) return -1; - - fd -= FIRST_HF; - - curpos = theHandleFiles [fd].mark; - switch (whence) { - case SEEK_CUR : - curpos += pos; - break; - case SEEK_END : - curpos = theHandleFiles[fd].size - pos; - break; - default : /* set */ - curpos = pos; - break; - } + long curpos; - if (curpos < 0) - curpos = 0; - else if (curpos > theHandleFiles [fd].size) - curpos = theHandleFiles [fd].size; - - theHandleFiles [fd].mark = curpos; - - return curpos; -} + if (!IsHandleFile(fd)) + return -1; + fd -= FIRST_HF; -void -C2P (const char *c, unsigned char *p) -{ - int len = strlen (c), i; + curpos = theHandleFiles[fd].mark; + switch (whence) { + case SEEK_CUR: + curpos += pos; + break; + case SEEK_END: + curpos = theHandleFiles[fd].size - pos; + break; + default: /* set */ + curpos = pos; + break; + } - if (len > 255) len = 255; + if (curpos < 0) + curpos = 0; + else if (curpos > theHandleFiles[fd].size) + curpos = theHandleFiles[fd].size; - for (i = len; i > 0; i--) - p[i] = c[i-1]; - p[0] = len; + theHandleFiles[fd].mark = curpos; + + return curpos; } void -P2C (const unsigned char *p, char *c) +C2P(const char *c, unsigned char *p) { - int idx = *p++; - for (; idx > 0; idx--) - *c++ = *p++; - *c = '\0'; + int len = strlen(c), i; + + if (len > 255) + len = 255; + + for (i = len; i > 0; i--) + p[i] = c[i - 1]; + p[0] = len; } +void +P2C(const unsigned char *p, char *c) +{ + int idx = *p++; + for (; idx > 0; idx--) + *c++ = *p++; + *c = '\0'; +} static void -replace_resource(Handle new_res, ResType its_type, short its_id, Str255 its_name) +replace_resource(Handle new_res, ResType its_type, short its_id, + Str255 its_name) { - Handle old_res; + Handle old_res; - SetResLoad(false); - old_res = Get1Resource(its_type, its_id); - SetResLoad(true); - if (old_res) { - RemoveResource(old_res); - DisposeHandle(old_res); - } + SetResLoad(false); + old_res = Get1Resource(its_type, its_id); + SetResLoad(true); + if (old_res) { + RemoveResource(old_res); + DisposeHandle(old_res); + } - AddResource(new_res, its_type, its_id, its_name); + AddResource(new_res, its_type, its_id, its_name); } - int -maccreat (const char *name, long fileType){ - return macopen (name, O_RDWR | O_CREAT | O_TRUNC, fileType); +maccreat(const char *name, long fileType) +{ + return macopen(name, O_RDWR | O_CREAT | O_TRUNC, fileType); } - int -macopen (const char *name, int flags, long fileType) +macopen(const char *name, int flags, long fileType) { - short refNum; - short perm; - Str255 s; + short refNum; + short perm; + Str255 s; - C2P (name, s); - if (flags & O_CREAT) { - if (HCreate (theDirs.dataRefNum, theDirs.dataDirID, s , - TEXT_CREATOR, fileType) && (flags & O_EXCL)) { - return -1; - } -#if 0 /* Fails during makedefs */ + C2P(name, s); + if (flags & O_CREAT) { + if (HCreate(theDirs.dataRefNum, theDirs.dataDirID, s, TEXT_CREATOR, + fileType) && (flags & O_EXCL)) { + return -1; + } +#if 0 /* Fails during makedefs */ if (fileType == SAVE_TYPE) { short resRef; HCreateResFile(theDirs.dataRefNum, theDirs.dataDirID, s); @@ -249,66 +248,63 @@ macopen (const char *name, int flags, long fileType) } } #endif - - } - /* - * Here, we should check for file type, maybe a SFdialog if - * we fail with default, etc. etc. Besides, we should use HOpen - * and permissions. - */ - if ((flags & O_RDONLY) == O_RDONLY) { - perm = fsRdPerm; - } - if ((flags & O_WRONLY) == O_WRONLY) { - perm = fsWrPerm; - } - if ((flags & O_RDWR) == O_RDWR) { - perm = fsRdWrPerm; - } - if (HOpen (theDirs.dataRefNum, theDirs.dataDirID, s, perm, &refNum)) { - return OpenHandleFile (s, fileType); - } - if (flags & O_TRUNC) { - if (SetEOF (refNum, 0L)) { - FSClose (refNum); - return -1; - } - } - return refNum; + } + /* + * Here, we should check for file type, maybe a SFdialog if + * we fail with default, etc. etc. Besides, we should use HOpen + * and permissions. + */ + if ((flags & O_RDONLY) == O_RDONLY) { + perm = fsRdPerm; + } + if ((flags & O_WRONLY) == O_WRONLY) { + perm = fsWrPerm; + } + if ((flags & O_RDWR) == O_RDWR) { + perm = fsRdWrPerm; + } + if (HOpen(theDirs.dataRefNum, theDirs.dataDirID, s, perm, &refNum)) { + return OpenHandleFile(s, fileType); + } + if (flags & O_TRUNC) { + if (SetEOF(refNum, 0L)) { + FSClose(refNum); + return -1; + } + } + return refNum; } - int -macclose (int fd) +macclose(int fd) { - if (IsHandleFile (fd)) { - CloseHandleFile (fd); - } else { - if (FSClose (fd)) { - return -1; - } - FlushVol ((StringPtr) 0, theDirs . dataRefNum); - } - return 0; + if (IsHandleFile(fd)) { + CloseHandleFile(fd); + } else { + if (FSClose(fd)) { + return -1; + } + FlushVol((StringPtr) 0, theDirs.dataRefNum); + } + return 0; } - int -macread (int fd, void *ptr, unsigned len) +macread(int fd, void *ptr, unsigned len) { - long amt = len; - - if (IsHandleFile (fd)) { - return ReadHandleFile (fd, ptr, amt); - } else { - short err = FSRead (fd, &amt, ptr); + long amt = len; - return ((err == noErr) || (err == eofErr && len)) ? amt : -1; - } + if (IsHandleFile(fd)) { + return ReadHandleFile(fd, ptr, amt); + } else { + short err = FSRead(fd, &amt, ptr); + + return ((err == noErr) || (err == eofErr && len)) ? amt : -1; + } } - -#if 0 /* this function isn't used, if you use it, uncomment prototype in macwin.h */ +#if 0 /* this function isn't used, if you use it, uncomment prototype in \ + macwin.h */ char * macgets (int fd, char *ptr, unsigned len) { @@ -327,142 +323,160 @@ macgets (int fd, char *ptr, unsigned len) } #endif /* 0 */ - int -macwrite (int fd, void *ptr, unsigned len) +macwrite(int fd, void *ptr, unsigned len) { - long amt = len; + long amt = len; - if (IsHandleFile (fd)) return -1; - if (FSWrite(fd, &amt, ptr) == noErr) - return (amt); - else - return (-1); + if (IsHandleFile(fd)) + return -1; + if (FSWrite(fd, &amt, ptr) == noErr) + return (amt); + else + return (-1); } - long -macseek (int fd, long where, short whence) +macseek(int fd, long where, short whence) { - short posMode; - long curPos; + short posMode; + long curPos; - if (IsHandleFile (fd)) { - return SetHandleFilePos (fd, whence, where); - } + if (IsHandleFile(fd)) { + return SetHandleFilePos(fd, whence, where); + } - switch (whence) { - default : - posMode = fsFromStart; - break; - case SEEK_CUR : - posMode = fsFromMark; - break; - case SEEK_END : - posMode = fsFromLEOF; - break; - } + switch (whence) { + default: + posMode = fsFromStart; + break; + case SEEK_CUR: + posMode = fsFromMark; + break; + case SEEK_END: + posMode = fsFromLEOF; + break; + } - if (SetFPos(fd, posMode, where) == noErr && GetFPos(fd, &curPos) == noErr) - return (curPos); - else - return(-1); + if (SetFPos(fd, posMode, where) == noErr && GetFPos(fd, &curPos) == noErr) + return (curPos); + else + return (-1); } - int macunlink(const char *name) { - Str255 pname; + Str255 pname; - - C2P(name, pname); - return (HDelete(theDirs.dataRefNum, theDirs.dataDirID, pname) == noErr ? 0 : -1); + C2P(name, pname); + return (HDelete(theDirs.dataRefNum, theDirs.dataDirID, pname) == noErr + ? 0 + : -1); } - - /* ---------------------------------------------------------------------- */ -boolean rsrc_dlb_init(void) { - return TRUE; +boolean +rsrc_dlb_init(void) +{ + return TRUE; } -void rsrc_dlb_cleanup(void) { +void +rsrc_dlb_cleanup(void) +{ } -boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode) { +boolean +rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(mode) +#pragma unused(mode) #endif - Str255 pname; - - C2P(name, pname); - dp->fd = OpenHandleFile(pname, 'File'); /* automatically read-only */ - return dp->fd >= 0; + Str255 pname; + + C2P(name, pname); + dp->fd = OpenHandleFile(pname, 'File'); /* automatically read-only */ + return dp->fd >= 0; } -int rsrc_dlb_fclose(dlb *dp) { - return CloseHandleFile(dp->fd); +int +rsrc_dlb_fclose(dlb *dp) +{ + return CloseHandleFile(dp->fd); } -int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp) { - int nread; +int +rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp) +{ + int nread; - if (size < 0 || quan < 0) return 0; - nread = ReadHandleFile(dp->fd, buf, (unsigned)size * (unsigned)quan); - - return nread/size; /* # of whole pieces (== quan in normal case) */ + if (size < 0 || quan < 0) + return 0; + nread = ReadHandleFile(dp->fd, buf, (unsigned) size * (unsigned) quan); + + return nread / size; /* # of whole pieces (== quan in normal case) */ } -int rsrc_dlb_fseek(dlb *dp, long pos, int whence) { - return SetHandleFilePos(dp->fd, whence, pos); +int +rsrc_dlb_fseek(dlb *dp, long pos, int whence) +{ + return SetHandleFilePos(dp->fd, whence, pos); } -char *rsrc_dlb_fgets(char *buf, int len, dlb *dp) { - HandleFile *hfp = IsHandleFile(dp->fd); - char *p; - int bytesLeft, n = 0; +char * +rsrc_dlb_fgets(char *buf, int len, dlb *dp) +{ + HandleFile *hfp = IsHandleFile(dp->fd); + char *p; + int bytesLeft, n = 0; - if (hfp && hfp->mark < hfp->size) { - bytesLeft = hfp->size - hfp->mark; - if (bytesLeft < len) - len = bytesLeft; + if (hfp && hfp->mark < hfp->size) { + bytesLeft = hfp->size - hfp->mark; + if (bytesLeft < len) + len = bytesLeft; - HLock(hfp->data); - for (n = 0, p = *hfp->data+hfp->mark; n < len; n++, p++) { - buf[n] = *p; - if (*p == '\r') buf[n] = '\n'; - if (buf[n] == '\n') { - n++; /* we want the return in the buffer */ - break; - } - } - HUnlock(hfp->data); + HLock(hfp->data); + for (n = 0, p = *hfp->data + hfp->mark; n < len; n++, p++) { + buf[n] = *p; + if (*p == '\r') + buf[n] = '\n'; + if (buf[n] == '\n') { + n++; /* we want the return in the buffer */ + break; + } + } + HUnlock(hfp->data); - hfp->mark += n; - if (n != 0) - buf[n] = '\0'; /* null terminate result */ - } + hfp->mark += n; + if (n != 0) + buf[n] = '\0'; /* null terminate result */ + } - return n ? buf : NULL; + return n ? buf : NULL; } -int rsrc_dlb_fgetc(dlb *dp) { - HandleFile *hfp = IsHandleFile(dp->fd); - int ret; +int +rsrc_dlb_fgetc(dlb *dp) +{ + HandleFile *hfp = IsHandleFile(dp->fd); + int ret; - if (!hfp || hfp->size <= hfp->mark) return EOF; + if (!hfp || hfp->size <= hfp->mark) + return EOF; - ret = *(unsigned char *)(*hfp->data + hfp->mark); - hfp->mark++; - return ret; + ret = *(unsigned char *) (*hfp->data + hfp->mark); + hfp->mark++; + return ret; } -long rsrc_dlb_ftell(dlb *dp) { - HandleFile *hfp = IsHandleFile(dp->fd); +long +rsrc_dlb_ftell(dlb *dp) +{ + HandleFile *hfp = IsHandleFile(dp->fd); - if (!hfp) return 0; - return hfp->mark; + if (!hfp) + return 0; + return hfp->mark; } - diff --git a/sys/mac/macmain.c b/sys/mac/macmain.c index f391ae509..ae1e9eea1 100644 --- a/sys/mac/macmain.c +++ b/sys/mac/macmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macmain.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */ /* NetHack 3.6 macmain.c $Date: 2009/05/06 10:49:11 $ $Revision: 1.15 $ */ /* SCCS Id: @(#)macmain.c 3.5 2008/01/30 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -33,230 +33,232 @@ int main(void); QDGlobals qd; #endif - int -main (void) +main(void) { - register int fd = -1; - int argc = 1; - boolean resuming = FALSE; /* assume new game */ + register int fd = -1; + int argc = 1; + boolean resuming = FALSE; /* assume new game */ - sys_early_init(); - windowprocs = mac_procs; - InitMac (); + sys_early_init(); + windowprocs = mac_procs; + InitMac(); - hname = "Mac Hack"; - hackpid = getpid(); + hname = "Mac Hack"; + hackpid = getpid(); - setrandom(); - initoptions(); - init_nhwindows(&argc, (char **)&hname); + setrandom(); + initoptions(); + init_nhwindows(&argc, (char **) &hname); - /* - * It seems you really want to play. - */ - u.uhp = 1; /* prevent RIP on early quits */ + /* + * It seems you really want to play. + */ + u.uhp = 1; /* prevent RIP on early quits */ - finder_file_request (); + finder_file_request(); - dlb_init(); /* must be before newgame() */ + dlb_init(); /* must be before newgame() */ - /* - * Initialize the vision system. This must be before mklev() on a - * new game or before a level restore on a saved game. - */ - vision_init(); + /* + * Initialize the vision system. This must be before mklev() on a + * new game or before a level restore on a saved game. + */ + vision_init(); - display_gamewindows(); + display_gamewindows(); - set_playmode(); /* sets plname to "wizard" for wizard mode */ - /* strip role,race,&c suffix; calls askname() if plname[] is empty - or holds a generic user name like "player" or "games" */ - plnamesuffix(); - /* unlike Unix where the game might be invoked with a script - which forces a particular character name for each player - using a shared account, we always allow player to rename - the character during role/race/&c selection */ - iflags.renameallowed = TRUE; + set_playmode(); /* sets plname to "wizard" for wizard mode */ + /* strip role,race,&c suffix; calls askname() if plname[] is empty + or holds a generic user name like "player" or "games" */ + plnamesuffix(); + /* unlike Unix where the game might be invoked with a script + which forces a particular character name for each player + using a shared account, we always allow player to rename + the character during role/race/&c selection */ + iflags.renameallowed = TRUE; - getlock(); + getlock(); - /* - * First, try to find and restore a save file for specified character. - * We'll return here if new game player_selection() renames the hero. - */ - attempt_restore: - if ((fd = restore_saved_game()) >= 0) { +/* + * First, try to find and restore a save file for specified character. + * We'll return here if new game player_selection() renames the hero. + */ +attempt_restore: + if ((fd = restore_saved_game()) >= 0) { #ifdef NEWS - if(iflags.news) { - display_file(NEWS, FALSE); - iflags.news = FALSE; /* in case dorecover() fails */ - } + if (iflags.news) { + display_file(NEWS, FALSE); + iflags.news = FALSE; /* in case dorecover() fails */ + } #endif - pline("Restoring save file..."); - mark_synch(); /* flush output */ - game_active = 1; - if (dorecover(fd)) { - resuming = TRUE; /* not starting new game */ - if (discover) - You("are in non-scoring discovery mode."); - if (discover || wizard) { - if(yn("Do you want to keep the save file?") == 'n') - (void) delete_savefile(); - else { - nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); - } - } - } - } + pline("Restoring save file..."); + mark_synch(); /* flush output */ + game_active = 1; + if (dorecover(fd)) { + resuming = TRUE; /* not starting new game */ + if (discover) + You("are in non-scoring discovery mode."); + if (discover || wizard) { + if (yn("Do you want to keep the save file?") == 'n') + (void) delete_savefile(); + else { + nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); + } + } + } + } - if (!resuming) { - /* new game: start by choosing role, race, etc; - player might change the hero's name while doing that, - in which case we try to restore under the new name - and skip selection this time if that didn't succeed */ - if (!iflags.renameinprogress) { - player_selection(); - if (iflags.renameinprogress) { - /* player has renamed the hero while selecting role; - discard current lock file and create another for - the new character name */ - delete_levelfile(0); /* remove empty lock file */ - getlock(); - goto attempt_restore; - } - } - game_active = 1; /* done with selection, draw active game window */ - newgame(); - if (discover) - You("are in non-scoring discovery mode."); - } + if (!resuming) { + /* new game: start by choosing role, race, etc; + player might change the hero's name while doing that, + in which case we try to restore under the new name + and skip selection this time if that didn't succeed */ + if (!iflags.renameinprogress) { + player_selection(); + if (iflags.renameinprogress) { + /* player has renamed the hero while selecting role; + discard current lock file and create another for + the new character name */ + delete_levelfile(0); /* remove empty lock file */ + getlock(); + goto attempt_restore; + } + } + game_active = 1; /* done with selection, draw active game window */ + newgame(); + if (discover) + You("are in non-scoring discovery mode."); + } - UndimMenuBar (); /* Yes, this is the place for it (!) */ + UndimMenuBar(); /* Yes, this is the place for it (!) */ - moveloop(resuming); + moveloop(resuming); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } - static OSErr copy_file(short src_vol, long src_dir, short dst_vol, long dst_dir, - Str255 fName, - pascal OSErr (*opener)(short vRefNum, long dirID, - ConstStr255Param fileName, - signed char permission, short *refNum)) { - short src_ref, dst_ref; - OSErr err = (*opener)(src_vol, src_dir, fName, fsRdPerm, &src_ref); - if (err == noErr) { - err = (*opener)(dst_vol, dst_dir, fName, fsWrPerm, &dst_ref); - if (err == noErr) { + Str255 fName, + pascal OSErr (*opener)(short vRefNum, long dirID, + ConstStr255Param fileName, + signed char permission, short *refNum)) +{ + short src_ref, dst_ref; + OSErr err = (*opener)(src_vol, src_dir, fName, fsRdPerm, &src_ref); + if (err == noErr) { + err = (*opener)(dst_vol, dst_dir, fName, fsWrPerm, &dst_ref); + if (err == noErr) { + long file_len; + err = GetEOF(src_ref, &file_len); + if (err == noErr) { + Handle buf; + long count = MaxBlock(); + if (count > file_len) + count = file_len; - long file_len; - err = GetEOF(src_ref, &file_len); - if (err == noErr) { - Handle buf; - long count = MaxBlock(); - if (count > file_len) - count = file_len; + buf = NewHandle(count); + err = MemError(); + if (err == noErr) { + while (count > 0) { + OSErr rd_err = FSRead(src_ref, &count, *buf); + err = FSWrite(dst_ref, &count, *buf); + if (err == noErr) + err = rd_err; + file_len -= count; + } + if (file_len == 0) + err = noErr; - buf = NewHandle(count); - err = MemError(); - if (err == noErr) { + DisposeHandle(buf); + } + } + FSClose(dst_ref); + } + FSClose(src_ref); + } - while (count > 0) { - OSErr rd_err = FSRead(src_ref, &count, *buf); - err = FSWrite(dst_ref, &count, *buf); - if (err == noErr) - err = rd_err; - file_len -= count; - } - if (file_len == 0) - err = noErr; - - DisposeHandle(buf); - - } - } - FSClose(dst_ref); - } - FSClose(src_ref); - } - - return err; + return err; } static void force_hdelete(short vol, long dir, Str255 fName) { - HRstFLock(vol, dir, fName); - HDelete (vol, dir, fName); + HRstFLock(vol, dir, fName); + HDelete(vol, dir, fName); } - void -process_openfile (short src_vol, long src_dir, Str255 fName, OSType ftype) +process_openfile(short src_vol, long src_dir, Str255 fName, OSType ftype) { - OSErr err = noErr; - - if (ftype != SAVE_TYPE) - return; /* only deal with save files */ - - if (src_vol != theDirs.dataRefNum || src_dir != theDirs.dataDirID && - CatMove(src_vol, src_dir, fName, theDirs.dataDirID, "\p:") != noErr) { + OSErr err = noErr; - HCreate(theDirs.dataRefNum, theDirs.dataDirID, fName, MAC_CREATOR, SAVE_TYPE); - err = copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID, - fName, &HOpen); /* HOpenDF is only there under 7.0 */ - if (err == noErr) - err = copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID, - fName, &HOpenRF); - if (err == noErr) - force_hdelete(src_vol, src_dir, fName); - else - HDelete(theDirs.dataRefNum, theDirs.dataDirID, fName); - } + if (ftype != SAVE_TYPE) + return; /* only deal with save files */ - if (err == noErr) { - short ref; + if (src_vol != theDirs.dataRefNum + || src_dir != theDirs.dataDirID + && CatMove(src_vol, src_dir, fName, theDirs.dataDirID, "\p:") + != noErr) { + HCreate(theDirs.dataRefNum, theDirs.dataDirID, fName, MAC_CREATOR, + SAVE_TYPE); + err = + copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID, + fName, &HOpen); /* HOpenDF is only there under 7.0 */ + if (err == noErr) + err = copy_file(src_vol, src_dir, theDirs.dataRefNum, + theDirs.dataDirID, fName, &HOpenRF); + if (err == noErr) + force_hdelete(src_vol, src_dir, fName); + else + HDelete(theDirs.dataRefNum, theDirs.dataDirID, fName); + } - ref = HOpenResFile(theDirs.dataRefNum, theDirs.dataDirID, fName, fsRdPerm); - if (ref != -1) { - Handle name = Get1Resource('STR ', PLAYER_NAME_RES_ID); - if (name) { - Str255 save_f_p; - P2C(*(StringHandle)name, plname); - set_savefile_name(TRUE); - C2P(fqname(SAVEF, SAVEPREFIX, 0), save_f_p); - force_hdelete(theDirs.dataRefNum, theDirs.dataDirID, save_f_p); + if (err == noErr) { + short ref; - if (HRename(theDirs.dataRefNum, theDirs.dataDirID, fName, save_f_p) == noErr) - macFlags.gotOpen = 1; - } - CloseResFile(ref); - } - } + ref = HOpenResFile(theDirs.dataRefNum, theDirs.dataDirID, fName, + fsRdPerm); + if (ref != -1) { + Handle name = Get1Resource('STR ', PLAYER_NAME_RES_ID); + if (name) { + Str255 save_f_p; + P2C(*(StringHandle) name, plname); + set_savefile_name(TRUE); + C2P(fqname(SAVEF, SAVEPREFIX, 0), save_f_p); + force_hdelete(theDirs.dataRefNum, theDirs.dataDirID, + save_f_p); + + if (HRename(theDirs.dataRefNum, theDirs.dataDirID, fName, + save_f_p) == noErr) + macFlags.gotOpen = 1; + } + CloseResFile(ref); + } + } } - static void finder_file_request(void) { - if (macFlags.hasAE) { - /* we're capable of handling Apple Events, so let's see if we have any */ - EventRecord event; - long toWhen = TickCount () + 20; /* wait a third of a second for all initial AE */ + if (macFlags.hasAE) { + /* we're capable of handling Apple Events, so let's see if we have any + */ + EventRecord event; + long toWhen = TickCount() + + 20; /* wait a third of a second for all initial AE */ - while (TickCount () < toWhen) { - if (WaitNextEvent (highLevelEventMask, &event, 3L, 0)) { - AEProcessAppleEvent(&event); - if (macFlags.gotOpen) - break; - } - } - } + while (TickCount() < toWhen) { + if (WaitNextEvent(highLevelEventMask, &event, 3L, 0)) { + AEProcessAppleEvent(&event); + if (macFlags.gotOpen) + break; + } + } + } #if 0 #ifdef MAC68K else { @@ -284,8 +286,8 @@ finder_file_request(void) boolean authorize_wizard_mode() { - /* other ports validate user name or character name here */ - return TRUE; + /* other ports validate user name or character name here */ + return TRUE; } /*macmain.c*/ diff --git a/sys/mac/macmenu.c b/sys/mac/macmenu.c index 066d2c033..873d3b9c4 100644 --- a/sys/mac/macmenu.c +++ b/sys/mac/macmenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macmenu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macmenu.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */ /* NetHack 3.6 macmenu.c $Date: 2009/05/06 10:49:13 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)macmenu.c 3.5 1999/11/24 */ /* Copyright (c) Macintosh NetHack Port Team, 1993. */ @@ -45,67 +45,61 @@ extern WindowPtr _mt_window; /******** Local Defines ********/ /* 'MNU#' (menu list record) */ -typedef union menuRefUnn -{ - short mresID; /* MENU resource ID (before GetMenu) */ - MenuHandle mhnd; /* MENU handle (after GetMenu) */ +typedef union menuRefUnn { + short mresID; /* MENU resource ID (before GetMenu) */ + MenuHandle mhnd; /* MENU handle (after GetMenu) */ } menuRefUnn; -typedef struct menuListRec -{ - short firstMenuID; - short numMenus; - menuRefUnn mref[]; +typedef struct menuListRec { + short firstMenuID; + short numMenus; + menuRefUnn mref[]; } menuListRec, *menuListPtr, **menuListHandle; /* indices and resource IDs of the menu list data */ -enum -{ - listMenubar, - listSubmenu, +enum { + listMenubar, + listSubmenu, - menuBarListID = 128, - subMenuListID + menuBarListID = 128, + subMenuListID }; /* the following mref[] indices are reserved */ -enum -{ - /* menu bar */ - menuApple, - menuFile, - menuEdit, +enum { + /* menu bar */ + menuApple, + menuFile, + menuEdit, - /* submenu */ - menuWizard = 0 + /* submenu */ + menuWizard = 0 }; /* the following menu items are reserved */ -enum -{ - /* apple */ - menuAppleAboutBox = 1, - ____Apple__1, +enum { + /* apple */ + menuAppleAboutBox = 1, + ____Apple__1, - /* File */ - menuFileRedraw = 1, - menuFilePrevMsg, - menuFileCleanup, - ____File___1, - menuFilePlayMode, - menuFileEnterExplore, - ____File___2, - menuFileSave, - ____File___3, - menuFileQuit, + /* File */ + menuFileRedraw = 1, + menuFilePrevMsg, + menuFileCleanup, + ____File___1, + menuFilePlayMode, + menuFileEnterExplore, + ____File___2, + menuFileSave, + ____File___3, + menuFileQuit, - /* standard minimum Edit menu items */ + /* standard minimum Edit menu items */ - /* Wizard */ - menuWizardAttributes = 1 + /* Wizard */ + menuWizardAttributes = 1 }; - /* * menuListRec data (preloaded and locked) specifies the number of menus in * the menu bar, the number of hierarchal or submenus and the menu IDs of @@ -134,392 +128,378 @@ enum * extents of the menu IDs. this must be correctly setup by the programmer. */ -#define ID1_MBAR pMenuList[listMenubar]->firstMenuID -#define ID1_SUBM pMenuList[listSubmenu]->firstMenuID +#define ID1_MBAR pMenuList[listMenubar]->firstMenuID +#define ID1_SUBM pMenuList[listSubmenu]->firstMenuID -#define NUM_MBAR pMenuList[listMenubar]->numMenus -#define NUM_SUBM pMenuList[listSubmenu]->numMenus +#define NUM_MBAR pMenuList[listMenubar]->numMenus +#define NUM_SUBM pMenuList[listSubmenu]->numMenus -#define MHND_APPLE pMenuList[listMenubar]->mref[menuApple].mhnd -#define MHND_FILE pMenuList[listMenubar]->mref[menuFile].mhnd -#define MHND_EDIT pMenuList[listMenubar]->mref[menuEdit].mhnd +#define MHND_APPLE pMenuList[listMenubar]->mref[menuApple].mhnd +#define MHND_FILE pMenuList[listMenubar]->mref[menuFile].mhnd +#define MHND_EDIT pMenuList[listMenubar]->mref[menuEdit].mhnd -#define MBARHND(x) pMenuList[listMenubar]->mref[(x)].mhnd - -#define MHND_WIZ pMenuList[listSubmenu]->mref[menuWizard].mhnd +#define MBARHND(x) pMenuList[listMenubar]->mref[(x)].mhnd +#define MHND_WIZ pMenuList[listSubmenu]->mref[menuWizard].mhnd /* mutually exclusive (and prioritized) menu bar states */ -enum -{ - mbarDim, - mbarNoWindows, - mbarDA, - mbarNoMap, - mbarRegular, - mbarSpecial /* explore or debug mode */ +enum { + mbarDim, + mbarNoWindows, + mbarDA, + mbarNoMap, + mbarRegular, + mbarSpecial /* explore or debug mode */ }; -#define WKND_MAP (WIN_BASE_KIND + NHW_MAP) - +#define WKND_MAP (WIN_BASE_KIND + NHW_MAP) /* menu routine error numbers */ -enum -{ - errGetMenuList, - errGetMenu, - errGetANDlogTemplate, - errGetANDlogItems, - errGetANDialog, - errANNewMenu, - err_Menu_total +enum { + errGetMenuList, + errGetMenu, + errGetANDlogTemplate, + errGetANDlogItems, + errGetANDialog, + errANNewMenu, + err_Menu_total }; - /* menu 'STR#' comment char */ -#define mstrEndChar 0xA5 /* '\245' or option-* or "bullet" */ +#define mstrEndChar 0xA5 /* '\245' or option-* or "bullet" */ /* 'ALRT' */ -enum -{ - alrt_Menu_start = 5000, - alrtMenuNote = alrt_Menu_start, - alrtMenu_NY, - alrt_Menu_limit -}; - -#define beepMenuAlertErr 1 /* # of SysBeep()'s before exitting */ -enum -{ - bttnMenuAlertNo = 1, - bttnMenuAlertYes +enum { + alrt_Menu_start = 5000, + alrtMenuNote = alrt_Menu_start, + alrtMenu_NY, + alrt_Menu_limit }; +#define beepMenuAlertErr 1 /* # of SysBeep()'s before exitting */ +enum { bttnMenuAlertNo = 1, bttnMenuAlertYes }; /******** Globals ********/ -static unsigned char *menuErrStr[err_Menu_total] = - { - "\pAbort: Bad \'MNU#\' resource!", /* errGetMenuList */ - "\pAbort: Bad \'MENU\' resource!", /* errGetMenu */ - "\pAbort: Bad \'DLOG\' resource!", /* errGetANDlogTemplate */ - "\pAbort: Bad \'DITL\' resource!", /* errGetANDlogItems */ - "\pAbort: Bad Dialog Allocation!", /* errGetANDialog */ - "\pAbort: Bad Menu Allocation!", /* errANNewMenu */ - }; -static menuListPtr pMenuList[2]; -static short theMenubar = mbarDA; /* force initial update */ -static short kAdjustWizardMenu = 1; - +static unsigned char *menuErrStr[err_Menu_total] = { + "\pAbort: Bad \'MNU#\' resource!", /* errGetMenuList */ + "\pAbort: Bad \'MENU\' resource!", /* errGetMenu */ + "\pAbort: Bad \'DLOG\' resource!", /* errGetANDlogTemplate */ + "\pAbort: Bad \'DITL\' resource!", /* errGetANDlogItems */ + "\pAbort: Bad Dialog Allocation!", /* errGetANDialog */ + "\pAbort: Bad Menu Allocation!", /* errANNewMenu */ +}; +static menuListPtr pMenuList[2]; +static short theMenubar = mbarDA; /* force initial update */ +static short kAdjustWizardMenu = 1; /******** Prototypes ********/ #if !TARGET_API_MAC_CARBON -static void alignAD(Rect *, short); +static void alignAD(Rect *, short); #endif -static void mustGetMenuAlerts(void); -static void menuError(short); -static void aboutNetHack(void); -static void askSave(void); -static void askQuit(void); - +static void mustGetMenuAlerts(void); +static void menuError(short); +static void aboutNetHack(void); +static void askSave(void); +static void askQuit(void); /*** Askname dialog box ***/ -#define RSRC_ASK 6000 /* Askname dialog and item list */ -#define RSRC_ASK_PLAY 1 /* Play button */ -#define RSRC_ASK_QUIT 2 /* Quit button */ -#define RSRC_ASK_DEFAULT 3 /* Default ring */ -#define RSRC_ASK_ROLE 4 /* Role popup menu */ -#define RSRC_ASK_RACE 5 /* Race popup menu */ -#define RSRC_ASK_GEND 6 /* Gender popup menu */ -#define RSRC_ASK_ALIGN 7 /* Alignment popup menu */ -#define RSRC_ASK_MODE 8 /* Mode popup menu */ -#define RSRC_ASK_NAME 9 /* Name text field */ -#define RSRC_ASK_MAX 10 /* Maximum enabled item */ +#define RSRC_ASK 6000 /* Askname dialog and item list */ +#define RSRC_ASK_PLAY 1 /* Play button */ +#define RSRC_ASK_QUIT 2 /* Quit button */ +#define RSRC_ASK_DEFAULT 3 /* Default ring */ +#define RSRC_ASK_ROLE 4 /* Role popup menu */ +#define RSRC_ASK_RACE 5 /* Race popup menu */ +#define RSRC_ASK_GEND 6 /* Gender popup menu */ +#define RSRC_ASK_ALIGN 7 /* Alignment popup menu */ +#define RSRC_ASK_MODE 8 /* Mode popup menu */ +#define RSRC_ASK_NAME 9 /* Name text field */ +#define RSRC_ASK_MAX 10 /* Maximum enabled item */ -#define KEY_MASK 0xff00 -#define KEY_RETURN 0x2400 -#define KEY_ENTER 0x4c00 -#define KEY_ESCAPE 0x3500 -#define CH_MASK 0x00ff -#define CH_RETURN 0x000d -#define CH_ENTER 0x0003 -#define CH_ESCAPE 0x001b +#define KEY_MASK 0xff00 +#define KEY_RETURN 0x2400 +#define KEY_ENTER 0x4c00 +#define KEY_ESCAPE 0x3500 +#define CH_MASK 0x00ff +#define CH_RETURN 0x000d +#define CH_ENTER 0x0003 +#define CH_ESCAPE 0x001b static void ask_restring(const char *cstr, unsigned char *pstr); static void ask_enable(DialogRef wind, short item, int enable); static pascal void ask_redraw(DialogRef wind, DialogItemIndex item); -static pascal Boolean ask_filter(DialogRef wind, EventRecord *event, DialogItemIndex *item); -#define noresource(t,n) {SysBeep(3); ExitToShell();} -#define fatal(s) {SysBeep(3); ExitToShell();} +static pascal Boolean +ask_filter(DialogRef wind, EventRecord *event, DialogItemIndex *item); +#define noresource(t, n) \ + { \ + SysBeep(3); \ + ExitToShell(); \ + } +#define fatal(s) \ + { \ + SysBeep(3); \ + ExitToShell(); \ + } static MenuHandle askmenu[RSRC_ASK_MAX]; static int askselect[RSRC_ASK_MAX]; -#define currrole askselect[RSRC_ASK_ROLE] -#define currrace askselect[RSRC_ASK_RACE] -#define currgend askselect[RSRC_ASK_GEND] -#define curralign askselect[RSRC_ASK_ALIGN] -#define currmode askselect[RSRC_ASK_MODE] - -static RGBColor - blackcolor = {0x0000, 0x0000, 0x0000}, -// indentcolor = {0x4000, 0x4000, 0x4000}, - darkcolor = {0x8000, 0x8000, 0x8000}, - backcolor = {0xdddd, 0xdddd, 0xdddd}, - lightcolor = {0xffff, 0xffff, 0xffff}, - whitecolor = {0xffff, 0xffff, 0xffff}; +#define currrole askselect[RSRC_ASK_ROLE] +#define currrace askselect[RSRC_ASK_RACE] +#define currgend askselect[RSRC_ASK_GEND] +#define curralign askselect[RSRC_ASK_ALIGN] +#define currmode askselect[RSRC_ASK_MODE] +static RGBColor blackcolor = { 0x0000, 0x0000, 0x0000 }, + // indentcolor = {0x4000, 0x4000, 0x4000}, + darkcolor = { 0x8000, 0x8000, 0x8000 }, + backcolor = { 0xdddd, 0xdddd, 0xdddd }, + lightcolor = { 0xffff, 0xffff, 0xffff }, + whitecolor = { 0xffff, 0xffff, 0xffff }; /* Convert a mixed-case C string to a Capitalized Pascal string */ static void -ask_restring (const char *cstr, unsigned char *pstr) +ask_restring(const char *cstr, unsigned char *pstr) { - int i; + int i; - - for (i = 0; *cstr && (i < 255); i++) - pstr[i+1] = *cstr++; - pstr[0] = i; - if ((pstr[1] >= 'a') && (pstr[1] <= 'z')) - pstr[1] += 'A' - 'a'; - return; + for (i = 0; *cstr && (i < 255); i++) + pstr[i + 1] = *cstr++; + pstr[0] = i; + if ((pstr[1] >= 'a') && (pstr[1] <= 'z')) + pstr[1] += 'A' - 'a'; + return; } - /* Enable the dialog item with the given index */ static void -ask_enable (DialogRef wind, short item, int enable) +ask_enable(DialogRef wind, short item, int enable) { - short type; - Handle handle; - Rect rect; + short type; + Handle handle; + Rect rect; - - /* Enable or disable the appropriate item */ - GetDialogItem(wind, item, &type, &handle, &rect); - if (enable) type &= ~itemDisable; - else type |= itemDisable; - HiliteControl((ControlHandle)handle, enable ? 0 : 255); - SetDialogItem(wind, item, type, handle, &rect); - return; + /* Enable or disable the appropriate item */ + GetDialogItem(wind, item, &type, &handle, &rect); + if (enable) + type &= ~itemDisable; + else + type |= itemDisable; + HiliteControl((ControlHandle) handle, enable ? 0 : 255); + SetDialogItem(wind, item, type, handle, &rect); + return; } - static pascal void -ask_redraw (DialogRef wind, DialogItemIndex item) +ask_redraw(DialogRef wind, DialogItemIndex item) { - short type; - Handle handle; - Rect rect; - static char *modechar = "NED"; + short type; + Handle handle; + Rect rect; + static char *modechar = "NED"; + /* Which item shall we redraw? */ + GetDialogItem(wind, item, &type, &handle, &rect); + switch (item) { + case RSRC_ASK_DEFAULT: + PenSize(3, 3); + FrameRoundRect(&rect, 16, 16); + break; - /* Which item shall we redraw? */ - GetDialogItem(wind, item, &type, &handle, &rect); - switch (item) { - case RSRC_ASK_DEFAULT: - PenSize(3, 3); - FrameRoundRect(&rect, 16, 16); - break; + case RSRC_ASK_ROLE: + case RSRC_ASK_RACE: + case RSRC_ASK_GEND: + case RSRC_ASK_ALIGN: + case RSRC_ASK_MODE: + if (macFlags.color) { + RGBForeColor(&blackcolor); + RGBBackColor(&backcolor); + } + PenNormal(); + TextMode(srcOr); + EraseRect(&rect); - case RSRC_ASK_ROLE: - case RSRC_ASK_RACE: - case RSRC_ASK_GEND: - case RSRC_ASK_ALIGN: - case RSRC_ASK_MODE: - if (macFlags.color) { - RGBForeColor(&blackcolor); - RGBBackColor(&backcolor); - } - PenNormal(); - TextMode(srcOr); - EraseRect(&rect); + /* Draw the frame and drop shadow */ + rect.right--; + rect.bottom--; + FrameRect(&rect); + MoveTo(rect.right, rect.top + 1); + LineTo(rect.right, rect.bottom); + LineTo(rect.left + 1, rect.bottom); - /* Draw the frame and drop shadow */ - rect.right--; - rect.bottom--; - FrameRect(&rect); - MoveTo(rect.right, rect.top+1); - LineTo(rect.right, rect.bottom); - LineTo(rect.left+1, rect.bottom); + /* Draw the menu character */ + MoveTo(rect.left + 4, rect.top + 12); + switch (item) { + case RSRC_ASK_ROLE: + DrawText(roles[askselect[item]].filecode, 0, 3); + break; + case RSRC_ASK_RACE: + DrawText(races[askselect[item]].filecode, 0, 3); + break; + case RSRC_ASK_GEND: + DrawText(genders[askselect[item]].filecode, 0, 3); + break; + case RSRC_ASK_ALIGN: + DrawText(aligns[askselect[item]].filecode, 0, 3); + break; + case RSRC_ASK_MODE: + DrawChar(modechar[askselect[item]]); + break; + } - /* Draw the menu character */ - MoveTo(rect.left+4, rect.top+12); - switch (item) { - case RSRC_ASK_ROLE: - DrawText(roles[askselect[item]].filecode, 0, 3); - break; - case RSRC_ASK_RACE: - DrawText(races[askselect[item]].filecode, 0, 3); - break; - case RSRC_ASK_GEND: - DrawText(genders[askselect[item]].filecode, 0, 3); - break; - case RSRC_ASK_ALIGN: - DrawText(aligns[askselect[item]].filecode, 0, 3); - break; - case RSRC_ASK_MODE: - DrawChar(modechar[askselect[item]]); - break; - } + /* Draw the popup symbol */ + MoveTo(rect.right - 16, rect.top + 5); + LineTo(rect.right - 6, rect.top + 5); + LineTo(rect.right - 11, rect.top + 10); + LineTo(rect.right - 15, rect.top + 6); + LineTo(rect.right - 8, rect.top + 6); + LineTo(rect.right - 11, rect.top + 9); + LineTo(rect.right - 13, rect.top + 7); + LineTo(rect.right - 10, rect.top + 7); + LineTo(rect.right - 11, rect.top + 8); - /* Draw the popup symbol */ - MoveTo(rect.right - 16, rect.top + 5); - LineTo(rect.right - 6, rect.top + 5); - LineTo(rect.right - 11, rect.top + 10); - LineTo(rect.right - 15, rect.top + 6); - LineTo(rect.right - 8, rect.top + 6); - LineTo(rect.right - 11, rect.top + 9); - LineTo(rect.right - 13, rect.top + 7); - LineTo(rect.right - 10, rect.top + 7); - LineTo(rect.right - 11, rect.top + 8); + /* Draw the shadow */ + InsetRect(&rect, 1, 1); + if (macFlags.color) { + RGBColor color; - /* Draw the shadow */ - InsetRect(&rect, 1, 1); - if (macFlags.color) { - RGBColor color; + /* Save the foreground color */ + GetForeColor(&color); + /* Draw the top and left */ + RGBForeColor(&lightcolor); + MoveTo(rect.left, rect.bottom - 1); + LineTo(rect.left, rect.top); + LineTo(rect.right - 1, rect.top); - /* Save the foreground color */ - GetForeColor(&color); + /* Draw the bottom and right */ + RGBForeColor(&darkcolor); + MoveTo(rect.right - 1, rect.top + 1); + LineTo(rect.right - 1, rect.bottom - 1); + LineTo(rect.left + 1, rect.bottom - 1); - /* Draw the top and left */ - RGBForeColor(&lightcolor); - MoveTo(rect.left, rect.bottom-1); - LineTo(rect.left, rect.top); - LineTo(rect.right-1, rect.top); + /* Restore the foreground color */ + RGBForeColor(&color); + } + break; - /* Draw the bottom and right */ - RGBForeColor(&darkcolor); - MoveTo(rect.right-1, rect.top+1); - LineTo(rect.right-1, rect.bottom-1); - LineTo(rect.left+1, rect.bottom-1); + case RSRC_ASK_NAME: + PenNormal(); + if (macFlags.color) { + RGBForeColor(&whitecolor); + RGBBackColor(&whitecolor); + TextMode(srcOr); + } else { + PenMode(notPatCopy); + TextMode(srcBic); + } + InsetRect(&rect, -1, -1); + FrameRect(&rect); + InsetRect(&rect, -1, -1); + FrameRect(&rect); + InsetRect(&rect, -2, -2); + if (macFlags.color) { + /* Draw the top and left */ + RGBForeColor(&darkcolor); + MoveTo(rect.left, rect.bottom - 1); + LineTo(rect.left, rect.top); + LineTo(rect.right - 1, rect.top); - /* Restore the foreground color */ - RGBForeColor(&color); - } - break; + /* Draw the bottom and right */ + RGBForeColor(&lightcolor); + MoveTo(rect.right - 1, rect.top + 1); + LineTo(rect.right - 1, rect.bottom - 1); + LineTo(rect.left + 1, rect.bottom - 1); - case RSRC_ASK_NAME: - PenNormal(); - if (macFlags.color) { - RGBForeColor(&whitecolor); - RGBBackColor(&whitecolor); - TextMode(srcOr); - } else { - PenMode(notPatCopy); - TextMode(srcBic); - } - InsetRect(&rect, -1, -1); - FrameRect(&rect); - InsetRect(&rect, -1, -1); - FrameRect(&rect); - InsetRect(&rect, -2, -2); - if (macFlags.color) { - /* Draw the top and left */ - RGBForeColor(&darkcolor); - MoveTo(rect.left, rect.bottom-1); - LineTo(rect.left, rect.top); - LineTo(rect.right-1, rect.top); - - /* Draw the bottom and right */ - RGBForeColor(&lightcolor); - MoveTo(rect.right-1, rect.top+1); - LineTo(rect.right-1, rect.bottom-1); - LineTo(rect.left+1, rect.bottom-1); - - /* Restore the colors */ - RGBForeColor(&blackcolor); - RGBBackColor(&backcolor); - } - break; - } - return; + /* Restore the colors */ + RGBForeColor(&blackcolor); + RGBBackColor(&backcolor); + } + break; + } + return; } - static pascal Boolean -ask_filter (DialogRef wind, EventRecord *event, DialogItemIndex *item) +ask_filter(DialogRef wind, EventRecord *event, DialogItemIndex *item) { - short ch, key; + short ch, key; - - switch (event->what) { - case keyDown: - case autoKey: - ch = event->message & CH_MASK; - key = event->message & KEY_MASK; - /* Handle equivalents for OK */ - if ((ch == CH_RETURN) || (key == KEY_RETURN) || - (ch == CH_ENTER) || (key == KEY_ENTER)) { - if (GetDialogTextEditHandle(wind)[0]->teLength) { - FlashButton(wind, RSRC_ASK_PLAY); - *item = RSRC_ASK_PLAY; - } else - *item = 0; - return (TRUE); - } - /* Handle equivalents for Normal/Explore/Debug */ - if ((event->modifiers & cmdKey) && (ch == 'n')) { - currmode = 0; - ask_redraw(wind, RSRC_ASK_MODE); - *item = RSRC_ASK_MODE; - return (TRUE); - } - if ((event->modifiers & cmdKey) && (ch == 'e')) { - currmode = 1; - ask_redraw(wind, RSRC_ASK_MODE); - *item = RSRC_ASK_MODE; - return (TRUE); - } - if ((event->modifiers & cmdKey) && (ch == 'd')) { - currmode = 2; - ask_redraw(wind, RSRC_ASK_MODE); - *item = RSRC_ASK_MODE; - return (TRUE); - } - /* Handle equivalents for Cancel and Quit */ - if ((ch == CH_ESCAPE) || (key == KEY_ESCAPE) || - ((event->modifiers & cmdKey) && (ch == 'q')) || - ((event->modifiers & cmdKey) && (ch == '.'))) { - FlashButton(wind, RSRC_ASK_QUIT); - *item = RSRC_ASK_QUIT; - return (TRUE); - } - return (FALSE); - case updateEvt: - ask_redraw(wind, RSRC_ASK_NAME); - return (FALSE); - default: - return (FALSE); - } + switch (event->what) { + case keyDown: + case autoKey: + ch = event->message & CH_MASK; + key = event->message & KEY_MASK; + /* Handle equivalents for OK */ + if ((ch == CH_RETURN) || (key == KEY_RETURN) || (ch == CH_ENTER) + || (key == KEY_ENTER)) { + if (GetDialogTextEditHandle(wind)[0]->teLength) { + FlashButton(wind, RSRC_ASK_PLAY); + *item = RSRC_ASK_PLAY; + } else + *item = 0; + return (TRUE); + } + /* Handle equivalents for Normal/Explore/Debug */ + if ((event->modifiers & cmdKey) && (ch == 'n')) { + currmode = 0; + ask_redraw(wind, RSRC_ASK_MODE); + *item = RSRC_ASK_MODE; + return (TRUE); + } + if ((event->modifiers & cmdKey) && (ch == 'e')) { + currmode = 1; + ask_redraw(wind, RSRC_ASK_MODE); + *item = RSRC_ASK_MODE; + return (TRUE); + } + if ((event->modifiers & cmdKey) && (ch == 'd')) { + currmode = 2; + ask_redraw(wind, RSRC_ASK_MODE); + *item = RSRC_ASK_MODE; + return (TRUE); + } + /* Handle equivalents for Cancel and Quit */ + if ((ch == CH_ESCAPE) || (key == KEY_ESCAPE) + || ((event->modifiers & cmdKey) && (ch == 'q')) + || ((event->modifiers & cmdKey) && (ch == '.'))) { + FlashButton(wind, RSRC_ASK_QUIT); + *item = RSRC_ASK_QUIT; + return (TRUE); + } + return (FALSE); + case updateEvt: + ask_redraw(wind, RSRC_ASK_NAME); + return (FALSE); + default: + return (FALSE); + } } - -void mac_askname () +void +mac_askname() { - GrafPtr oldport; - DialogRef askdialog; - short i, j, item, type; - Handle handle; - Rect rect; - Str255 str; - Point pt; - UserItemUPP redraw = NewUserItemUPP(ask_redraw); - ModalFilterUPP filter = NewModalFilterUPP(ask_filter); + GrafPtr oldport; + DialogRef askdialog; + short i, j, item, type; + Handle handle; + Rect rect; + Str255 str; + Point pt; + UserItemUPP redraw = NewUserItemUPP(ask_redraw); + ModalFilterUPP filter = NewModalFilterUPP(ask_filter); + /* Create the dialog */ + if (!(askdialog = GetNewDialog(RSRC_ASK, NULL, (WindowRef) -1))) + noresource('DLOG', RSRC_ASK); + GetPort(&oldport); + SetPortDialogPort(askdialog); - /* Create the dialog */ - if (!(askdialog = GetNewDialog(RSRC_ASK, NULL, (WindowRef)-1))) - noresource('DLOG', RSRC_ASK); - GetPort(&oldport); - SetPortDialogPort(askdialog); - - /* Initialize the name text item */ - ask_restring(plname, str); - if (plname[0]) { - GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect); - SetDialogItemText(handle, str); - } + /* Initialize the name text item */ + ask_restring(plname, str); + if (plname[0]) { + GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect); + SetDialogItemText(handle, str); + } #if 0 { Str32 pName; @@ -557,179 +537,180 @@ void mac_askname () } } #endif - SelectDialogItemText(askdialog, RSRC_ASK_NAME, 0, 32767); + SelectDialogItemText(askdialog, RSRC_ASK_NAME, 0, 32767); - /* Initialize the role popup menu */ - if (!(askmenu[RSRC_ASK_ROLE] = NewMenu(RSRC_ASK_ROLE, "\p"))) - fatal("\pCannot create role menu"); - for (i = 0; roles[i].name.m; i++) { - ask_restring(roles[i].name.m, str); - AppendMenu(askmenu[RSRC_ASK_ROLE], str); - } - InsertMenu(askmenu[RSRC_ASK_ROLE], hierMenu); - if (flags.initrole >= 0) - currrole = flags.initrole; - /* Check for backward compatibility */ - else if ((currrole = str2role(pl_character)) < 0) - currrole = randrole(); + /* Initialize the role popup menu */ + if (!(askmenu[RSRC_ASK_ROLE] = NewMenu(RSRC_ASK_ROLE, "\p"))) + fatal("\pCannot create role menu"); + for (i = 0; roles[i].name.m; i++) { + ask_restring(roles[i].name.m, str); + AppendMenu(askmenu[RSRC_ASK_ROLE], str); + } + InsertMenu(askmenu[RSRC_ASK_ROLE], hierMenu); + if (flags.initrole >= 0) + currrole = flags.initrole; + /* Check for backward compatibility */ + else if ((currrole = str2role(pl_character)) < 0) + currrole = randrole(); - /* Initialize the race popup menu */ - if (!(askmenu[RSRC_ASK_RACE] = NewMenu(RSRC_ASK_RACE, "\p"))) - fatal("\pCannot create race menu"); - for (i = 0; races[i].noun; i++) { - ask_restring(races[i].noun, str); - AppendMenu(askmenu[RSRC_ASK_RACE], str); - } - InsertMenu(askmenu[RSRC_ASK_RACE], hierMenu); - if (flags.initrace >= 0) - currrace = flags.initrace; - else - currrace = randrace(currrole); + /* Initialize the race popup menu */ + if (!(askmenu[RSRC_ASK_RACE] = NewMenu(RSRC_ASK_RACE, "\p"))) + fatal("\pCannot create race menu"); + for (i = 0; races[i].noun; i++) { + ask_restring(races[i].noun, str); + AppendMenu(askmenu[RSRC_ASK_RACE], str); + } + InsertMenu(askmenu[RSRC_ASK_RACE], hierMenu); + if (flags.initrace >= 0) + currrace = flags.initrace; + else + currrace = randrace(currrole); - /* Initialize the gender popup menu */ - if (!(askmenu[RSRC_ASK_GEND] = NewMenu(RSRC_ASK_GEND, "\p"))) - fatal("\pCannot create gender menu"); - for (i = 0; i < ROLE_GENDERS; i++) { - ask_restring(genders[i].adj, str); - AppendMenu(askmenu[RSRC_ASK_GEND], str); - } - InsertMenu(askmenu[RSRC_ASK_GEND], hierMenu); - if (flags.initgend >= 0) - currgend = flags.initgend; - else if (flags.female) - currgend = 1; - else - currgend = randgend(currrole, currrace); + /* Initialize the gender popup menu */ + if (!(askmenu[RSRC_ASK_GEND] = NewMenu(RSRC_ASK_GEND, "\p"))) + fatal("\pCannot create gender menu"); + for (i = 0; i < ROLE_GENDERS; i++) { + ask_restring(genders[i].adj, str); + AppendMenu(askmenu[RSRC_ASK_GEND], str); + } + InsertMenu(askmenu[RSRC_ASK_GEND], hierMenu); + if (flags.initgend >= 0) + currgend = flags.initgend; + else if (flags.female) + currgend = 1; + else + currgend = randgend(currrole, currrace); - /* Initialize the alignment popup menu */ - if (!(askmenu[RSRC_ASK_ALIGN] = NewMenu(RSRC_ASK_ALIGN, "\p"))) - fatal("\pCannot create alignment menu"); - for (i = 0; i < ROLE_ALIGNS; i++) { - ask_restring(aligns[i].adj, str); - AppendMenu(askmenu[RSRC_ASK_ALIGN], str); - } - InsertMenu(askmenu[RSRC_ASK_ALIGN], hierMenu); - if (flags.initalign >= 0) - curralign = flags.initalign; - else - curralign = randalign(currrole, currrace); + /* Initialize the alignment popup menu */ + if (!(askmenu[RSRC_ASK_ALIGN] = NewMenu(RSRC_ASK_ALIGN, "\p"))) + fatal("\pCannot create alignment menu"); + for (i = 0; i < ROLE_ALIGNS; i++) { + ask_restring(aligns[i].adj, str); + AppendMenu(askmenu[RSRC_ASK_ALIGN], str); + } + InsertMenu(askmenu[RSRC_ASK_ALIGN], hierMenu); + if (flags.initalign >= 0) + curralign = flags.initalign; + else + curralign = randalign(currrole, currrace); - /* Initialize the mode popup menu */ - if (!(askmenu[RSRC_ASK_MODE] = NewMenu(RSRC_ASK_MODE, "\p"))) - fatal("\pCannot create mode menu"); - AppendMenu(askmenu[RSRC_ASK_MODE], "\pNormal"); - AppendMenu(askmenu[RSRC_ASK_MODE], "\pExplore"); - AppendMenu(askmenu[RSRC_ASK_MODE], "\pDebug"); - InsertMenu(askmenu[RSRC_ASK_MODE], hierMenu); - currmode = 0; + /* Initialize the mode popup menu */ + if (!(askmenu[RSRC_ASK_MODE] = NewMenu(RSRC_ASK_MODE, "\p"))) + fatal("\pCannot create mode menu"); + AppendMenu(askmenu[RSRC_ASK_MODE], "\pNormal"); + AppendMenu(askmenu[RSRC_ASK_MODE], "\pExplore"); + AppendMenu(askmenu[RSRC_ASK_MODE], "\pDebug"); + InsertMenu(askmenu[RSRC_ASK_MODE], hierMenu); + currmode = 0; - /* Set the redraw procedures */ - for (item = RSRC_ASK_DEFAULT; item <= RSRC_ASK_MODE; item++) { - GetDialogItem(askdialog, item, &type, &handle, &rect); - SetDialogItem(askdialog, item, type, (Handle)redraw, &rect); - } + /* Set the redraw procedures */ + for (item = RSRC_ASK_DEFAULT; item <= RSRC_ASK_MODE; item++) { + GetDialogItem(askdialog, item, &type, &handle, &rect); + SetDialogItem(askdialog, item, type, (Handle) redraw, &rect); + } - /* Handle dialog events */ - do { - /* Adjust the Play button */ - ask_enable(askdialog, RSRC_ASK_PLAY, - GetDialogTextEditHandle(askdialog)[0]->teLength); + /* Handle dialog events */ + do { + /* Adjust the Play button */ + ask_enable(askdialog, RSRC_ASK_PLAY, + GetDialogTextEditHandle(askdialog)[0]->teLength); - /* Adjust the race popup menu */ - i = j = currrace; - do { - if (validrace(currrole, j)) { - EnableMenuItem(askmenu[RSRC_ASK_RACE], j+1); - CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1, - currrace == j); - } else { - DisableMenuItem(askmenu[RSRC_ASK_RACE], j+1); - CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1, FALSE); - if ((currrace == j) && !races[++currrace].noun) - currrace = 0; - } - if (!races[++j].noun) j = 0; - } while (i != j); - if (currrace != i) { - GetDialogItem(askdialog, RSRC_ASK_RACE, &type, &handle, &rect); - InvalWindowRect(GetDialogWindow(askdialog), &rect); - } + /* Adjust the race popup menu */ + i = j = currrace; + do { + if (validrace(currrole, j)) { + EnableMenuItem(askmenu[RSRC_ASK_RACE], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_RACE], j + 1, currrace == j); + } else { + DisableMenuItem(askmenu[RSRC_ASK_RACE], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_RACE], j + 1, FALSE); + if ((currrace == j) && !races[++currrace].noun) + currrace = 0; + } + if (!races[++j].noun) + j = 0; + } while (i != j); + if (currrace != i) { + GetDialogItem(askdialog, RSRC_ASK_RACE, &type, &handle, &rect); + InvalWindowRect(GetDialogWindow(askdialog), &rect); + } - /* Adjust the gender popup menu */ - i = j = currgend; - do { - if (validgend(currrole, currrace, j)) { - EnableMenuItem(askmenu[RSRC_ASK_GEND], j+1); - CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1, - currgend == j); - } else { - DisableMenuItem(askmenu[RSRC_ASK_GEND], j+1); - CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1, FALSE); - if ((currgend == j) && (++currgend >= ROLE_GENDERS)) - currgend = 0; - } - if (++j >= ROLE_GENDERS) j = 0; - } while (i != j); - if (currgend != i) { - GetDialogItem(askdialog, RSRC_ASK_GEND, &type, &handle, &rect); - InvalWindowRect(GetDialogWindow(askdialog), &rect); - } + /* Adjust the gender popup menu */ + i = j = currgend; + do { + if (validgend(currrole, currrace, j)) { + EnableMenuItem(askmenu[RSRC_ASK_GEND], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_GEND], j + 1, currgend == j); + } else { + DisableMenuItem(askmenu[RSRC_ASK_GEND], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_GEND], j + 1, FALSE); + if ((currgend == j) && (++currgend >= ROLE_GENDERS)) + currgend = 0; + } + if (++j >= ROLE_GENDERS) + j = 0; + } while (i != j); + if (currgend != i) { + GetDialogItem(askdialog, RSRC_ASK_GEND, &type, &handle, &rect); + InvalWindowRect(GetDialogWindow(askdialog), &rect); + } - /* Adjust the alignment popup menu */ - i = j = curralign; - do { - if (validalign(currrole, currrace, j)) { - EnableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1); - CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1, - curralign == j); - } else { - DisableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1); - CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1, FALSE); - if ((curralign == j) && (++curralign >= ROLE_ALIGNS)) - curralign = 0; - } - if (++j >= ROLE_ALIGNS) j = 0; - } while (i != j); - if (curralign != i) { - GetDialogItem(askdialog, RSRC_ASK_ALIGN, &type, &handle, &rect); - InvalWindowRect(GetDialogWindow(askdialog), &rect); - } + /* Adjust the alignment popup menu */ + i = j = curralign; + do { + if (validalign(currrole, currrace, j)) { + EnableMenuItem(askmenu[RSRC_ASK_ALIGN], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j + 1, curralign == j); + } else { + DisableMenuItem(askmenu[RSRC_ASK_ALIGN], j + 1); + CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j + 1, FALSE); + if ((curralign == j) && (++curralign >= ROLE_ALIGNS)) + curralign = 0; + } + if (++j >= ROLE_ALIGNS) + j = 0; + } while (i != j); + if (curralign != i) { + GetDialogItem(askdialog, RSRC_ASK_ALIGN, &type, &handle, &rect); + InvalWindowRect(GetDialogWindow(askdialog), &rect); + } - /* Adjust the role popup menu */ - for (i = 0; roles[i].name.m; i++) { - ask_restring((currgend && roles[i].name.f) ? - roles[i].name.f : roles[i].name.m, str); - SetMenuItemText(askmenu[RSRC_ASK_ROLE], i+1, str); - CheckMenuItem(askmenu[RSRC_ASK_ROLE], i+1, currrole == i); - } + /* Adjust the role popup menu */ + for (i = 0; roles[i].name.m; i++) { + ask_restring((currgend && roles[i].name.f) ? roles[i].name.f + : roles[i].name.m, + str); + SetMenuItemText(askmenu[RSRC_ASK_ROLE], i + 1, str); + CheckMenuItem(askmenu[RSRC_ASK_ROLE], i + 1, currrole == i); + } - /* Adjust the mode popup menu */ - CheckMenuItem(askmenu[RSRC_ASK_MODE], 1, currmode == 0); - CheckMenuItem(askmenu[RSRC_ASK_MODE], 2, currmode == 1); - CheckMenuItem(askmenu[RSRC_ASK_MODE], 3, currmode == 2); + /* Adjust the mode popup menu */ + CheckMenuItem(askmenu[RSRC_ASK_MODE], 1, currmode == 0); + CheckMenuItem(askmenu[RSRC_ASK_MODE], 2, currmode == 1); + CheckMenuItem(askmenu[RSRC_ASK_MODE], 3, currmode == 2); - /* Wait for an action on an item */ - ModalDialog(filter, &item); - switch (item) { - case RSRC_ASK_PLAY: - break; - case RSRC_ASK_QUIT: - currmode = -1; - break; - case RSRC_ASK_ROLE: - case RSRC_ASK_RACE: - case RSRC_ASK_ALIGN: - case RSRC_ASK_GEND: - case RSRC_ASK_MODE: - GetDialogItem(askdialog, item, &type, &handle, &rect); - pt = *(Point *)▭ - LocalToGlobal(&pt); - if (!!(i = PopUpMenuSelect(askmenu[item], pt.v, pt.h, - askselect[item] + 1))) - askselect[item] = LoWord(i) - 1; - InvalWindowRect(GetDialogWindow(askdialog), &rect); - break; - case RSRC_ASK_NAME: + /* Wait for an action on an item */ + ModalDialog(filter, &item); + switch (item) { + case RSRC_ASK_PLAY: + break; + case RSRC_ASK_QUIT: + currmode = -1; + break; + case RSRC_ASK_ROLE: + case RSRC_ASK_RACE: + case RSRC_ASK_ALIGN: + case RSRC_ASK_GEND: + case RSRC_ASK_MODE: + GetDialogItem(askdialog, item, &type, &handle, &rect); + pt = *(Point *) ▭ + LocalToGlobal(&pt); + if (!!(i = PopUpMenuSelect(askmenu[item], pt.v, pt.h, + askselect[item] + 1))) + askselect[item] = LoWord(i) - 1; + InvalWindowRect(GetDialogWindow(askdialog), &rect); + break; + case RSRC_ASK_NAME: #if 0 /* limit the data here to 25 chars */ { @@ -747,441 +728,427 @@ void mac_askname () if (((**dRec.textH).teLength == 1) && (**((**dRec.textH).hText) < 32)) TEKey('\b', dRec.textH); #endif - break; - } - } while ((item != RSRC_ASK_PLAY) && (item != RSRC_ASK_QUIT)); + break; + } + } while ((item != RSRC_ASK_PLAY) && (item != RSRC_ASK_QUIT)); - /* Process the name */ - GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect); - GetDialogItemText(handle, str); - if (str[0] > PL_NSIZ-1) str[0] = PL_NSIZ-1; - BlockMove(&str[1], plname, str[0]); - plname[str[0]] = '\0'; + /* Process the name */ + GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect); + GetDialogItemText(handle, str); + if (str[0] > PL_NSIZ - 1) + str[0] = PL_NSIZ - 1; + BlockMove(&str[1], plname, str[0]); + plname[str[0]] = '\0'; - /* Destroy the dialog */ - for (i = RSRC_ASK_ROLE; i <= RSRC_ASK_MODE; i++) { - DeleteMenu(i); - DisposeMenu(askmenu[i]); - } - SetPort(oldport); - DisposeDialog(askdialog); - DisposeModalFilterUPP(filter); - DisposeUserItemUPP(redraw); + /* Destroy the dialog */ + for (i = RSRC_ASK_ROLE; i <= RSRC_ASK_MODE; i++) { + DeleteMenu(i); + DisposeMenu(askmenu[i]); + } + SetPort(oldport); + DisposeDialog(askdialog); + DisposeModalFilterUPP(filter); + DisposeUserItemUPP(redraw); - /* Process the mode */ - wizard = discover = 0; - switch (currmode) { - case 0: /* Normal */ - break; - case 1: /* Explore */ - discover = 1; - break; - case 2: /* Debug */ - wizard = 1; - strcpy(plname, WIZARD_NAME); - break; - default: /* Quit */ - ExitToShell(); - } + /* Process the mode */ + wizard = discover = 0; + switch (currmode) { + case 0: /* Normal */ + break; + case 1: /* Explore */ + discover = 1; + break; + case 2: /* Debug */ + wizard = 1; + strcpy(plname, WIZARD_NAME); + break; + default: /* Quit */ + ExitToShell(); + } - /* Process the role */ - strcpy(pl_character, roles[currrole].name.m); - flags.initrole = currrole; + /* Process the role */ + strcpy(pl_character, roles[currrole].name.m); + flags.initrole = currrole; - /* Process the race */ - flags.initrace = currrace; + /* Process the race */ + flags.initrace = currrace; - /* Process the gender */ - flags.female = flags.initgend = currgend; + /* Process the gender */ + flags.female = flags.initgend = currgend; - /* Process the alignment */ - flags.initalign = curralign; + /* Process the alignment */ + flags.initalign = curralign; - return; + return; } - - /*** Menu bar routines ***/ #if !TARGET_API_MAC_CARBON static void alignAD(Rect *pRct, short vExempt) { - BitMap qbitmap; + BitMap qbitmap; - - GetQDGlobalsScreenBits(&qbitmap); - (*pRct).right -= (*pRct).left; /* width */ - (*pRct).bottom -= (*pRct).top; /* height */ - (*pRct).left = (qbitmap.bounds.right - (*pRct).right) / 2; - (*pRct).top = (qbitmap.bounds.bottom - (*pRct).bottom - vExempt) / 2; - (*pRct).top += vExempt; - (*pRct).right += (*pRct).left; - (*pRct).bottom += (*pRct).top; + GetQDGlobalsScreenBits(&qbitmap); + (*pRct).right -= (*pRct).left; /* width */ + (*pRct).bottom -= (*pRct).top; /* height */ + (*pRct).left = (qbitmap.bounds.right - (*pRct).right) / 2; + (*pRct).top = (qbitmap.bounds.bottom - (*pRct).bottom - vExempt) / 2; + (*pRct).top += vExempt; + (*pRct).right += (*pRct).left; + (*pRct).bottom += (*pRct).top; } #endif - static void mustGetMenuAlerts() { - short i; - Rect **hRct; + short i; + Rect **hRct; - for (i = alrt_Menu_start; i < alrt_Menu_limit; i++) - { - if (! (hRct = (Rect **) GetResource('ALRT', i))) /* AlertTHndl */ - { - for (i = 0; i < beepMenuAlertErr; i++) - SysBeep(3); - ExitToShell(); - } + for (i = alrt_Menu_start; i < alrt_Menu_limit; i++) { + if (!(hRct = (Rect **) GetResource('ALRT', i))) /* AlertTHndl */ + { + for (i = 0; i < beepMenuAlertErr; i++) + SysBeep(3); + ExitToShell(); + } #if !TARGET_API_MAC_CARBON - alignAD(*hRct, GetMBarHeight()); + alignAD(*hRct, GetMBarHeight()); #endif - } + } } static void menuError(short menuErr) { - short i; + short i; - for (i = 0; i < beepMenuAlertErr; i++) - SysBeep(3); + for (i = 0; i < beepMenuAlertErr; i++) + SysBeep(3); - ParamText(menuErrStr[menuErr], "\p", "\p", "\p"); - (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L); + ParamText(menuErrStr[menuErr], "\p", "\p", "\p"); + (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L); - ExitToShell(); + ExitToShell(); } void InitMenuRes() { - static Boolean was_inited = 0; - short i, j; - menuListHandle mlHnd; - MenuHandle menu; + static Boolean was_inited = 0; + short i, j; + menuListHandle mlHnd; + MenuHandle menu; - if (was_inited) - return; - was_inited = 1; + if (was_inited) + return; + was_inited = 1; - mustGetMenuAlerts(); + mustGetMenuAlerts(); - for (i = listMenubar; i <= listSubmenu; i++) { - if (! (mlHnd = (menuListHandle) GetResource('MNU#', (menuBarListID + i)))) - menuError(errGetMenuList); + for (i = listMenubar; i <= listSubmenu; i++) { + if (!(mlHnd = + (menuListHandle) GetResource('MNU#', (menuBarListID + i)))) + menuError(errGetMenuList); - pMenuList[i] = (menuListPtr) NewPtr(GetHandleSize((Handle) mlHnd)); - *pMenuList[i] = **mlHnd; + pMenuList[i] = (menuListPtr) NewPtr(GetHandleSize((Handle) mlHnd)); + *pMenuList[i] = **mlHnd; - for (j = 0; j < pMenuList[i]->numMenus; j++) - { - if (! (menu = (MenuHandle) GetMenu((**mlHnd).mref[j].mresID))) { - Str31 d; - NumToString ((**mlHnd).mref[j].mresID, d); - menuError(errGetMenu); - } + for (j = 0; j < pMenuList[i]->numMenus; j++) { + if (!(menu = (MenuHandle) GetMenu((**mlHnd).mref[j].mresID))) { + Str31 d; + NumToString((**mlHnd).mref[j].mresID, d); + menuError(errGetMenu); + } - pMenuList[i]->mref[j].mhnd = menu; - SetMenuID(menu, j + (**mlHnd).firstMenuID); /* consecutive IDs */ + pMenuList[i]->mref[j].mhnd = menu; + SetMenuID(menu, j + (**mlHnd).firstMenuID); /* consecutive IDs */ - /* expand apple menu */ - if ((i == listMenubar) && (j == menuApple)) { - AppendResMenu(menu, 'DRVR'); - } + /* expand apple menu */ + if ((i == listMenubar) && (j == menuApple)) { + AppendResMenu(menu, 'DRVR'); + } - InsertMenu(menu, ((i == listSubmenu) ? hierMenu : 0)); - } - } - DrawMenuBar(); - return; + InsertMenu(menu, ((i == listSubmenu) ? hierMenu : 0)); + } + } + DrawMenuBar(); + return; } void AdjustMenus(short dimMenubar) { - short newMenubar = mbarRegular; - WindowRef win = FrontWindow(); - short i; + short newMenubar = mbarRegular; + WindowRef win = FrontWindow(); + short i; - /* - * if (windowprocs != mac_procs) { - * return; - * } - */ - /* determine the new menubar state */ - if (dimMenubar) - newMenubar = mbarDim; - else if (!win) - newMenubar = mbarNoWindows; - else if (GetWindowKind(win) < 0) - newMenubar = mbarDA; - else if (!IsWindowVisible(_mt_window)) - newMenubar = mbarNoMap; + /* + * if (windowprocs != mac_procs) { + * return; + * } + */ + /* determine the new menubar state */ + if (dimMenubar) + newMenubar = mbarDim; + else if (!win) + newMenubar = mbarNoWindows; + else if (GetWindowKind(win) < 0) + newMenubar = mbarDA; + else if (!IsWindowVisible(_mt_window)) + newMenubar = mbarNoMap; - if (newMenubar != mbarRegular) - ; /* we've already found its state */ - else if (wizard) - { - newMenubar = mbarSpecial; + if (newMenubar != mbarRegular) + ; /* we've already found its state */ + else if (wizard) { + newMenubar = mbarSpecial; - if (kAdjustWizardMenu) - { - kAdjustWizardMenu = 0; + if (kAdjustWizardMenu) { + kAdjustWizardMenu = 0; - SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pDebug"); - } - } + SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pDebug"); + } + } - else if (discover) - { - newMenubar = mbarSpecial; + else if (discover) { + newMenubar = mbarSpecial; - if (kAdjustWizardMenu) - { - kAdjustWizardMenu = 0; + if (kAdjustWizardMenu) { + kAdjustWizardMenu = 0; - SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pExplore"); + SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pExplore"); - for (i = CountMenuItems(MHND_WIZ); i > menuWizardAttributes; i--) - DeleteMenuItem(MHND_WIZ, i); - } - } + for (i = CountMenuItems(MHND_WIZ); i > menuWizardAttributes; i--) + DeleteMenuItem(MHND_WIZ, i); + } + } - /* adjust the menubar, if there's a state change */ - if (theMenubar != newMenubar) - { - switch(theMenubar = newMenubar) - { - case mbarDim: - /* disable all menus (except the apple menu) */ - for (i = menuFile; i < NUM_MBAR; i++) - DisableMenuItem(MBARHND(i), 0); - break; + /* adjust the menubar, if there's a state change */ + if (theMenubar != newMenubar) { + switch (theMenubar = newMenubar) { + case mbarDim: + /* disable all menus (except the apple menu) */ + for (i = menuFile; i < NUM_MBAR; i++) + DisableMenuItem(MBARHND(i), 0); + break; - case mbarNoWindows: - case mbarDA: - case mbarNoMap: - /* enable the file menu, but ... */ - EnableMenuItem(MHND_FILE, 0); + case mbarNoWindows: + case mbarDA: + case mbarNoMap: + /* enable the file menu, but ... */ + EnableMenuItem(MHND_FILE, 0); - /* ... disable the window commands! */ - for (i = menuFileRedraw; i <= menuFileEnterExplore; i++) - DisableMenuItem(MHND_FILE, i); + /* ... disable the window commands! */ + for (i = menuFileRedraw; i <= menuFileEnterExplore; i++) + DisableMenuItem(MHND_FILE, i); - /* ... and disable the rest of the menus */ - for (i = menuEdit; i < NUM_MBAR; i++) - DisableMenuItem(MBARHND(i), 0); + /* ... and disable the rest of the menus */ + for (i = menuEdit; i < NUM_MBAR; i++) + DisableMenuItem(MBARHND(i), 0); - if (theMenubar == mbarDA) - EnableMenuItem(MHND_EDIT, 0); + if (theMenubar == mbarDA) + EnableMenuItem(MHND_EDIT, 0); - break; + break; - case mbarRegular: - case mbarSpecial: - /* enable all menus ... */ - for (i = menuFile; i < NUM_MBAR; i++) - EnableMenuItem(MBARHND(i), 0); + case mbarRegular: + case mbarSpecial: + /* enable all menus ... */ + for (i = menuFile; i < NUM_MBAR; i++) + EnableMenuItem(MBARHND(i), 0); - /* ... except the unused Edit menu */ - DisableMenuItem(MHND_EDIT, 0); + /* ... except the unused Edit menu */ + DisableMenuItem(MHND_EDIT, 0); - /* ... enable the window commands */ - for (i = menuFileRedraw; i <= menuFileEnterExplore; i++) - EnableMenuItem(MHND_FILE, i); + /* ... enable the window commands */ + for (i = menuFileRedraw; i <= menuFileEnterExplore; i++) + EnableMenuItem(MHND_FILE, i); - if (theMenubar == mbarRegular) - DisableMenuItem(MHND_FILE, menuFilePlayMode); - else - DisableMenuItem(MHND_FILE, menuFileEnterExplore); + if (theMenubar == mbarRegular) + DisableMenuItem(MHND_FILE, menuFilePlayMode); + else + DisableMenuItem(MHND_FILE, menuFileEnterExplore); - break; - } + break; + } - DrawMenuBar(); - } + DrawMenuBar(); + } } void DoMenuEvt(long menuEntry) { - short menuID = HiWord(menuEntry); - short menuItem = LoWord(menuEntry); + short menuID = HiWord(menuEntry); + short menuItem = LoWord(menuEntry); - switch(menuID - ID1_MBAR) /* all submenus are default case */ - { - case menuApple: - if (menuItem == menuAppleAboutBox) - aboutNetHack(); + switch (menuID - ID1_MBAR) /* all submenus are default case */ + { + case menuApple: + if (menuItem == menuAppleAboutBox) + aboutNetHack(); #if !TARGET_API_MAC_CARBON - else - { - unsigned char daName[32]; + else { + unsigned char daName[32]; - GetMenuItemText(MHND_APPLE, menuItem, * (Str255 *) daName); - (void) OpenDeskAcc(daName); - } + GetMenuItemText(MHND_APPLE, menuItem, *(Str255 *) daName); + (void) OpenDeskAcc(daName); + } #endif - break; + break; - /* - * Those direct calls are ugly: they should be installed into cmd.c . - * Those AddToKeyQueue() calls are also ugly: they should be put into - * the 'STR#' resource. - */ - case menuFile: - switch(menuItem) - { - case menuFileRedraw: - AddToKeyQueue ('R' & 0x1f, 1); - break; + /* + * Those direct calls are ugly: they should be installed into cmd.c . + * Those AddToKeyQueue() calls are also ugly: they should be put into + * the 'STR#' resource. + */ + case menuFile: + switch (menuItem) { + case menuFileRedraw: + AddToKeyQueue('R' & 0x1f, 1); + break; - case menuFilePrevMsg: - AddToKeyQueue ('P' & 0x1f, 1); - break; + case menuFilePrevMsg: + AddToKeyQueue('P' & 0x1f, 1); + break; - case menuFileCleanup: - (void) SanePositions(); - break; + case menuFileCleanup: + (void) SanePositions(); + break; - case menuFileEnterExplore: - AddToKeyQueue ('X', 1); - break; + case menuFileEnterExplore: + AddToKeyQueue('X', 1); + break; - case menuFileSave: - askSave(); - break; + case menuFileSave: + askSave(); + break; - case menuFileQuit: - askQuit(); - break; - } - break; + case menuFileQuit: + askQuit(); + break; + } + break; - case menuEdit: + case menuEdit: #if !TARGET_API_MAC_CARBON - (void) SystemEdit(menuItem - 1); + (void) SystemEdit(menuItem - 1); #endif - break; + break; - default: /* get associated string and add to key queue */ - { - Str255 mstr; - short i; + default: /* get associated string and add to key queue */ + { + Str255 mstr; + short i; - GetIndString(mstr, menuID, menuItem); - if (mstr[0] > QUEUE_LEN) - mstr[0] = QUEUE_LEN; + GetIndString(mstr, menuID, menuItem); + if (mstr[0] > QUEUE_LEN) + mstr[0] = QUEUE_LEN; - for (i = 1; ((i <= mstr[0]) && (mstr[i] != mstrEndChar)); i++) - AddToKeyQueue(mstr[i], false); - } - break; - } + for (i = 1; ((i <= mstr[0]) && (mstr[i] != mstrEndChar)); i++) + AddToKeyQueue(mstr[i], false); + } break; + } - HiliteMenu(0); + HiliteMenu(0); } - static void -aboutNetHack() { - if (theMenubar >= mbarRegular) { - (void) doversion(); /* is this necessary? */ - } else { - unsigned char aboutStr[32] = "\pNetHack 3.4."; +aboutNetHack() +{ + if (theMenubar >= mbarRegular) { + (void) doversion(); /* is this necessary? */ + } else { + unsigned char aboutStr[32] = "\pNetHack 3.4."; - if (PATCHLEVEL > 10) { - aboutStr[++aboutStr[0]] = '0'+PATCHLEVEL/10; - } + if (PATCHLEVEL > 10) { + aboutStr[++aboutStr[0]] = '0' + PATCHLEVEL / 10; + } - aboutStr[++aboutStr[0]] = '0' + (PATCHLEVEL % 10); + aboutStr[++aboutStr[0]] = '0' + (PATCHLEVEL % 10); - ParamText(aboutStr, "\p\rdevteam@www.nethack.org", "\p", "\p"); - (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L); - ResetAlertStage(); - } + ParamText(aboutStr, "\p\rdevteam@www.nethack.org", "\p", "\p"); + (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L); + ResetAlertStage(); + } } - static void askSave() { - Boolean doSave = 1; - Boolean doYes = 0; + Boolean doSave = 1; + Boolean doYes = 0; - if (theMenubar < mbarRegular) { - short itemHit; + if (theMenubar < mbarRegular) { + short itemHit; - ParamText("\pReally Save?", "\p", "\p", "\p"); - itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L); - ResetAlertStage(); + ParamText("\pReally Save?", "\p", "\p", "\p"); + itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L); + ResetAlertStage(); - if (itemHit != bttnMenuAlertYes) { - doSave = 0; - } else { - doYes = 1; - } - } - if (doSave) { - AddToKeyQueue ('S', 1); - if (doYes) { - AddToKeyQueue ('y', 1); - } - } + if (itemHit != bttnMenuAlertYes) { + doSave = 0; + } else { + doYes = 1; + } + } + if (doSave) { + AddToKeyQueue('S', 1); + if (doYes) { + AddToKeyQueue('y', 1); + } + } } static void askQuit() { - Boolean doQuit = 1; - Boolean doYes = 0; - Boolean winMac; - char *quitinput; + Boolean doQuit = 1; + Boolean doYes = 0; + Boolean winMac; + char *quitinput; - if (!strcmp (windowprocs.name, "mac")) - winMac = 1; - else - winMac = 0; - - if (theMenubar < mbarRegular) { - short itemHit; + if (!strcmp(windowprocs.name, "mac")) + winMac = 1; + else + winMac = 0; - ParamText("\pReally Quit?", "\p", "\p", "\p"); - itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L); - ResetAlertStage(); + if (theMenubar < mbarRegular) { + short itemHit; - if (itemHit != bttnMenuAlertYes) { - doQuit = 0; - } else { - doYes = 1; - } - } - if (doQuit) { - /* MWM -- forgive me lord, an even uglier kludge to deal with differences - in command input handling - */ - if (winMac) - quitinput = "#quit\r"; - else - quitinput = "#q\r"; - - /* KMH -- Ugly kludge */ - while (*quitinput) - AddToKeyQueue(*quitinput++, 1); - if (doYes) { - if (winMac) - quitinput = "y\rq\r\r\r"; - else - quitinput = "yq\r"; - while (*quitinput) - AddToKeyQueue(*quitinput++, 1); - } - } + ParamText("\pReally Quit?", "\p", "\p", "\p"); + itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L); + ResetAlertStage(); + + if (itemHit != bttnMenuAlertYes) { + doQuit = 0; + } else { + doYes = 1; + } + } + if (doQuit) { + /* MWM -- forgive me lord, an even uglier kludge to deal with + differences + in command input handling + */ + if (winMac) + quitinput = "#quit\r"; + else + quitinput = "#q\r"; + + /* KMH -- Ugly kludge */ + while (*quitinput) + AddToKeyQueue(*quitinput++, 1); + if (doYes) { + if (winMac) + quitinput = "y\rq\r\r\r"; + else + quitinput = "yq\r"; + while (*quitinput) + AddToKeyQueue(*quitinput++, 1); + } + } } - diff --git a/sys/mac/macsnd.c b/sys/mac/macsnd.c index 4a3788aa3..121c50c42 100644 --- a/sys/mac/macsnd.c +++ b/sys/mac/macsnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macsnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macsnd.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 macsnd.c $Date: 2009/05/06 10:49:14 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)macsnd.c 3.5 1992/11/28 */ /* Copyright (c) 1992 by Jon Watte */ @@ -20,92 +20,94 @@ #include "mactty.h" #include "macwin.h" #if 1 /*!TARGET_API_MAC_CARBON*/ -# include -# include +#include +#include #endif #ifndef freqDurationCmd -# define freqDurationCmd 40 +#define freqDurationCmd 40 #endif #define SND_BUFFER(s) (&(*s)[20]) -#define SND_LEN(s) (GetHandleSize(s)-42) - +#define SND_LEN(s) (GetHandleSize(s) - 42) void -mac_speaker (struct obj *instr, char *melody) { - SndChannelPtr theChannel = (SndChannelPtr) 0; - SndCommand theCmd; - Handle theSound; - unsigned char theName [32]; - char *n = (char *) &theName [1]; - int typ = instr->otyp; - const char *actualn = OBJ_NAME (objects [typ]); +mac_speaker(struct obj *instr, char *melody) +{ + SndChannelPtr theChannel = (SndChannelPtr) 0; + SndCommand theCmd; + Handle theSound; + unsigned char theName[32]; + char *n = (char *) &theName[1]; + int typ = instr->otyp; + const char *actualn = OBJ_NAME(objects[typ]); - /* - * First: are we in the library ? - */ - if (flags.silent) { - return; - } + /* + * First: are we in the library ? + */ + if (flags.silent) { + return; + } - /* - * Is this a known instrument ? - */ - strcpy (n, actualn); - theName [0] = strlen (n); - theSound = GetNamedResource ('snd ', theName); - if (! theSound) { - return; - } - HLock (theSound); + /* + * Is this a known instrument ? + */ + strcpy(n, actualn); + theName[0] = strlen(n); + theSound = GetNamedResource('snd ', theName); + if (!theSound) { + return; + } + HLock(theSound); - /* - * Set up the synth - */ - if (SndNewChannel(&theChannel, sampledSynth, initMono + - initNoInterp, (void *) 0) == noErr) { - char midi_note [] = {57, 59, 60, 62, 64, 65, 67}; + /* + * Set up the synth + */ + if (SndNewChannel(&theChannel, sampledSynth, initMono + initNoInterp, + (void *) 0) == noErr) { + char midi_note[] = { 57, 59, 60, 62, 64, 65, 67 }; - short err; - short snd_len = SND_LEN (theSound) / 18; + short err; + short snd_len = SND_LEN(theSound) / 18; - theCmd.cmd = soundCmd; - theCmd.param1 = 0; - theCmd.param2 = (long) SND_BUFFER (theSound); - err = SndDoCommand (theChannel, &theCmd, false); + theCmd.cmd = soundCmd; + theCmd.param1 = 0; + theCmd.param2 = (long) SND_BUFFER(theSound); + err = SndDoCommand(theChannel, &theCmd, false); - /* - * We rack 'em up all in a row - * The mac will play them correctly and then end, since - * we do a sync close below. - * - */ - while (*melody && ! err) { - while (*melody > 'G') { - *melody -= 8; - } - while (*melody < 'A') { - *melody += 8; - } - theCmd.cmd = freqDurationCmd; - theCmd.param1 = snd_len; - theCmd.param2 = midi_note [*melody - 'A']; - err = SndDoCommand (theChannel, &theCmd, false); - melody ++; - } - SndDisposeChannel (theChannel, false); /* Sync wait for completion */ - ReleaseResource (theSound); - } + /* + * We rack 'em up all in a row + * The mac will play them correctly and then end, since + * we do a sync close below. + * + */ + while (*melody && !err) { + while (*melody > 'G') { + *melody -= 8; + } + while (*melody < 'A') { + *melody += 8; + } + theCmd.cmd = freqDurationCmd; + theCmd.param1 = snd_len; + theCmd.param2 = midi_note[*melody - 'A']; + err = SndDoCommand(theChannel, &theCmd, false); + melody++; + } + SndDisposeChannel(theChannel, false); /* Sync wait for completion */ + ReleaseResource(theSound); + } } -void tty_nhbell (void) { - Handle h = GetNamedResource ('snd ', "\pNetHack Bell"); +void +tty_nhbell(void) +{ + Handle h = GetNamedResource('snd ', "\pNetHack Bell"); - if (h) { - HLock (h); - SndPlay ((SndChannelPtr) 0, (SndListHandle) h, 0); - ReleaseResource (h); - } else - SysBeep (30); + if (h) { + HLock(h); + SndPlay((SndChannelPtr) 0, (SndListHandle) h, 0); + ReleaseResource(h); + } else + SysBeep(30); } diff --git a/sys/mac/mactopl.c b/sys/mac/mactopl.c index 1422523ad..55d5cb072 100644 --- a/sys/mac/mactopl.c +++ b/sys/mac/mactopl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mactopl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mactopl.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 mactopl.c $Date: 2009/05/06 10:49:14 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)mactopl.c 3.5 1991/07/23 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -10,48 +10,48 @@ #include "macpopup.h" char -queued_resp(char *resp) { - char buf[30]; - if (try_key_queue(buf)) { - if (!resp || strchr(resp, buf[0])) - return buf[0]; - if (digit(buf[0]) && strchr(resp, '#')) { - yn_number = atoi(buf); - return '#'; - } - } - return '\0'; +queued_resp(char *resp) +{ + char buf[30]; + if (try_key_queue(buf)) { + if (!resp || strchr(resp, buf[0])) + return buf[0]; + if (digit(buf[0]) && strchr(resp, '#')) { + yn_number = atoi(buf); + return '#'; + } + } + return '\0'; } - char -topl_yn_function(const char *query, const char *resp, char def) { - char buf[30]; - char c = queued_resp((char *) resp); - if (!c) { - enter_topl_mode((char *) query); - topl_set_resp((char *) resp, def); +topl_yn_function(const char *query, const char *resp, char def) +{ + char buf[30]; + char c = queued_resp((char *) resp); + if (!c) { + enter_topl_mode((char *) query); + topl_set_resp((char *) resp, def); - do { - c = readchar(); - if (c && resp && !strchr(resp, c)) { - nhbell(); - c = '\0'; - } - } while (!c); + do { + c = readchar(); + if (c && resp && !strchr(resp, c)) { + nhbell(); + c = '\0'; + } + } while (!c); - topl_set_resp("", '\0'); - leave_topl_mode(buf); - if (c == '#') - yn_number = atoi(buf); - } - return c; + topl_set_resp("", '\0'); + leave_topl_mode(buf); + if (c == '#') + yn_number = atoi(buf); + } + return c; } - char mac_yn_function(query, resp, def) -const char *query,*resp; +const char *query, *resp; char def; /* * Generic yes/no function. 'def' is the default (returned by space or @@ -61,7 +61,7 @@ char def; * If resp is NULL, any single character is accepted and returned. */ { - return topl_yn_function(query, resp, def); + return topl_yn_function(query, resp, def); } /* mactopl.c */ diff --git a/sys/mac/mactty.c b/sys/mac/mactty.c index 66b7c79ab..fe0557607 100644 --- a/sys/mac/mactty.c +++ b/sys/mac/mactty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mactty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mactty.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 mactty.c $Date: 2009/05/06 10:49:14 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)mactty.c 3.5 1993/03/01 */ /* Copyright (c) Jon W{tte 1993. */ @@ -7,46 +7,45 @@ /* * mactty.c * - * This file contains the actual code for the tty library. For a + * This file contains the actual code for the tty library. For a * description, see the file mactty.h, which contains all you * need to know to use the library. */ -#include "hack.h" /* to get flags */ +#include "hack.h" /* to get flags */ #include "mttypriv.h" #if !TARGET_API_MAC_CARBON #include #endif -char game_active = 0; /* flag to window rendering routines not to use ppat */ +char game_active = 0; /* flag to window rendering routines not to use ppat */ -/* these declarations are here because I can't include macwin.h without including the world */ -extern void dprintf(char *, ...); /* dprintf.c */ +/* these declarations are here because I can't include macwin.h without + * including the world */ +extern void dprintf(char *, ...); /* dprintf.c */ /* * Borrowed from the Mac tty port */ extern WindowPtr _mt_window; -static void select_onscreen_window (tty_record *record); -static void select_offscreen_port (tty_record *record); +static void select_onscreen_window(tty_record *record); +static void select_offscreen_port(tty_record *record); #define MEMORY_MARGIN 30000 /* * Convenience macro for most functions - put last in declaration */ -#define RECORD_EXISTS(record) \ - tty_record * record; \ - if (!window || !(record = (tty_record *) GetWRefCon (window))) \ - return general_failure; - +#define RECORD_EXISTS(record) \ + tty_record *record; \ + if (!window || !(record = (tty_record *) GetWRefCon(window))) \ + return general_failure; /* * Simple macro for deciding wether we draw at once or delay */ -#define DRAW_DIRECT (TA_ALWAYS_REFRESH & record->attribute [TTY_ATTRIB_FLAGS]) - +#define DRAW_DIRECT (TA_ALWAYS_REFRESH & record->attribute[TTY_ATTRIB_FLAGS]) /* * Table of special characters. Zero is ALWAYS special; it means @@ -56,58 +55,57 @@ static void select_offscreen_port (tty_record *record); #define RAW_CONTROLS 1 static unsigned long s_control = COOKED_CONTROLS; - /* * Memory-related error */ static short -mem_err (void) { - short ret_val = MemError(); - if (!ret_val) { - ret_val = general_failure; - } - return ret_val; +mem_err(void) +{ + short ret_val = MemError(); + if (!ret_val) { + ret_val = general_failure; + } + return ret_val; } - /* * Make a rectangle empty */ static void -empty_rect (Rect *r) { - r->right = -20000; - r->left = 20000; - r->top = 20000; - r->bottom = -20000; +empty_rect(Rect *r) +{ + r->right = -20000; + r->left = 20000; + r->top = 20000; + r->bottom = -20000; } - /* * Union twp rect together */ static void -union_rect (Rect *r1, Rect *r2, Rect *dest) { - dest->left = min (r1->left, r2->left); - dest->top = min (r1->top, r2 ->top); - dest->bottom = max (r1->bottom, r2->bottom); - dest->right = max (r1->right, r2->right); +union_rect(Rect *r1, Rect *r2, Rect *dest) +{ + dest->left = min(r1->left, r2->left); + dest->top = min(r1->top, r2->top); + dest->bottom = max(r1->bottom, r2->bottom); + dest->right = max(r1->right, r2->right); } - /* * Dispose a pointer using the set memory-allocator */ static short -dispose_ptr (void *ptr) { - if (!ptr) { - return noErr; /* Silently accept disposing nulls */ - } - DisposePtr (ptr); - return MemError (); +dispose_ptr(void *ptr) +{ + if (!ptr) { + return noErr; /* Silently accept disposing nulls */ + } + DisposePtr(ptr); + return MemError(); } - -#if 0 /* Use alloc.c instead */ +#if 0 /* Use alloc.c instead */ /* * Allocate a pointer using the set memory-allocator */ @@ -118,417 +116,420 @@ alloc_ptr (void **ptr, long size) { } #endif - /* * Set up a GWorld in the record */ static short -allocate_offscreen_world (tty_record *record) { -GWorldPtr gw = (GWorldPtr)0; -GWorldFlags world_flags = 0; -long mem_here, mem_there, other, required_mem; -Point p = {0, 0}; -Rect r_screen; -GDHandle gdh; -short s_err; +allocate_offscreen_world(tty_record *record) +{ + GWorldPtr gw = (GWorldPtr) 0; + GWorldFlags world_flags = 0; + long mem_here, mem_there, other, required_mem; + Point p = { 0, 0 }; + Rect r_screen; + GDHandle gdh; + short s_err; - select_onscreen_window (record); - LocalToGlobal (&p); - r_screen = record->its_bits.bounds; - OffsetRect (&r_screen, p.h, p.v); + select_onscreen_window(record); + LocalToGlobal(&p); + r_screen = record->its_bits.bounds; + OffsetRect(&r_screen, p.h, p.v); - gdh = GetMaxDevice (&r_screen); - required_mem = (long) (*((*gdh)->gdPMap))->pixelSize * - ((long) record->its_bits.bounds.right * - record->its_bits.bounds.bottom) >> 3; + gdh = GetMaxDevice(&r_screen); + required_mem = (long) (*((*gdh)->gdPMap))->pixelSize + * ((long) record->its_bits.bounds.right + * record->its_bits.bounds.bottom) + >> 3; - PurgeSpace (&other, &mem_here); - if (other < mem_here + MEMORY_MARGIN) { - mem_here = other - MEMORY_MARGIN; - } - dprintf ("Heap %ld Required %ld", mem_here, required_mem); - if (required_mem > mem_here) { - mem_there = required_mem; - if (required_mem > TempMaxMem (&mem_there)) { - dprintf ("No memory"); - return memFullErr; - } - world_flags |= useTempMem; - } - s_err = NewGWorld (&gw, 0, &r_screen, (CTabHandle) 0, (GDHandle) 0, world_flags); - if (!s_err) { - record->offscreen_world = gw; - select_offscreen_port (record); - SetOrigin (0, 0); - select_onscreen_window (record); - dprintf ("New GWorld @ %lx;dm", gw); - } - return s_err; + PurgeSpace(&other, &mem_here); + if (other < mem_here + MEMORY_MARGIN) { + mem_here = other - MEMORY_MARGIN; + } + dprintf("Heap %ld Required %ld", mem_here, required_mem); + if (required_mem > mem_here) { + mem_there = required_mem; + if (required_mem > TempMaxMem(&mem_there)) { + dprintf("No memory"); + return memFullErr; + } + world_flags |= useTempMem; + } + s_err = NewGWorld(&gw, 0, &r_screen, (CTabHandle) 0, (GDHandle) 0, + world_flags); + if (!s_err) { + record->offscreen_world = gw; + select_offscreen_port(record); + SetOrigin(0, 0); + select_onscreen_window(record); + dprintf("New GWorld @ %lx;dm", gw); + } + return s_err; } - /* * Done with GWorld, release data */ static short -deallocate_gworld (tty_record *record) { - if (record->offscreen_world) { - DisposeGWorld (record->offscreen_world); - record->offscreen_world = (GWorldPtr) 0; - } - return noErr; +deallocate_gworld(tty_record *record) +{ + if (record->offscreen_world) { + DisposeGWorld(record->offscreen_world); + record->offscreen_world = (GWorldPtr) 0; + } + return noErr; } - - - /* * Get rid of offscreen bitmap */ static short -free_bits (tty_record *record) { - short s_err; +free_bits(tty_record *record) +{ + short s_err; - if (record->uses_gworld) { - s_err = deallocate_gworld (record); + if (record->uses_gworld) { + s_err = deallocate_gworld(record); #if !TARGET_API_MAC_CARBON - } else { - s_err = dispose_ptr (record->its_bits.baseAddr); - if (!s_err) { - record->its_bits.baseAddr = (char *)0; - if (record->offscreen_port) { - ClosePort (record->offscreen_port); - s_err = dispose_ptr (record->offscreen_port); - if (!s_err) { - record->offscreen_port = (GrafPtr) 0; - } - } - } + } else { + s_err = dispose_ptr(record->its_bits.baseAddr); + if (!s_err) { + record->its_bits.baseAddr = (char *) 0; + if (record->offscreen_port) { + ClosePort(record->offscreen_port); + s_err = dispose_ptr(record->offscreen_port); + if (!s_err) { + record->offscreen_port = (GrafPtr) 0; + } + } + } #endif - } - return s_err; + } + return s_err; } - /* * Snatch a window from the resource fork. Create the record. * Otherwise, do nothing. */ short -create_tty (WindowRef *window, short resource_id, Boolean in_color) +create_tty(WindowRef *window, short resource_id, Boolean in_color) { - tty_record * record; - Boolean was_allocated = !!*window; + tty_record *record; + Boolean was_allocated = !!*window; - if (in_color) { - *window = GetNewCWindow (resource_id, (Ptr) *window, (WindowRef) -1L); - } else { - *window = GetNewWindow (resource_id, (Ptr) *window, (WindowRef) -1L); - } - if (!*window) { - return mem_err (); - } + if (in_color) { + *window = GetNewCWindow(resource_id, (Ptr) *window, (WindowRef) -1L); + } else { + *window = GetNewWindow(resource_id, (Ptr) *window, (WindowRef) -1L); + } + if (!*window) { + return mem_err(); + } - record = (tty_record *) NewPtrClear (sizeof (tty_record)); - if (!record) { + record = (tty_record *) NewPtrClear(sizeof(tty_record)); + if (!record) { #if !TARGET_API_MAC_CARBON - if (was_allocated) { - CloseWindow (*window); - } else { + if (was_allocated) { + CloseWindow(*window); + } else { #endif - DisposeWindow (*window); + DisposeWindow(*window); #if !TARGET_API_MAC_CARBON - } + } #endif - return mem_err (); - } - record->its_window = *window; - SetWRefCon (*window, (long) record); - record->was_allocated = was_allocated; - record->its_bits.baseAddr = (char *)0; - record->curs_state = TRUE; + return mem_err(); + } + record->its_window = *window; + SetWRefCon(*window, (long) record); + record->was_allocated = was_allocated; + record->its_bits.baseAddr = (char *) 0; + record->curs_state = TRUE; -/* - * We need to keep the window world around if we switch worlds - */ - record->offscreen_world = (GWorldPtr) 0; - record->uses_gworld = in_color; - if (in_color) { - GDHandle gh; + /* + * We need to keep the window world around if we switch worlds + */ + record->offscreen_world = (GWorldPtr) 0; + record->uses_gworld = in_color; + if (in_color) { + GDHandle gh; - SetPortWindowPort(*window); - GetGWorld(&(record->its_window_world), &gh); - } else { - record->its_window_world = (GWorldPtr)0; - } + SetPortWindowPort(*window); + GetGWorld(&(record->its_window_world), &gh); + } else { + record->its_window_world = (GWorldPtr) 0; + } #if CLIP_RECT_ONLY - empty_rect (&(record->invalid_rect)); + empty_rect(&(record->invalid_rect)); #else - record->invalid_part = NewRgn (); - if (!record->invalid_part) { - return destroy_tty (*window); - } + record->invalid_part = NewRgn(); + if (!record->invalid_part) { + return destroy_tty(*window); + } #endif - return noErr; + return noErr; } - short -init_tty_number (WindowPtr window, short font_number, short font_size, - short x_size, short y_size) { -RECORD_EXISTS (record); +init_tty_number(WindowPtr window, short font_number, short font_size, + short x_size, short y_size) +{ + RECORD_EXISTS(record); - record->font_number = font_number; - record->font_size = font_size; - record->x_size = x_size; - record->y_size = y_size; + record->font_number = font_number; + record->font_size = font_size; + record->x_size = x_size; + record->y_size = y_size; - return force_tty_coordinate_system_recalc (window); + return force_tty_coordinate_system_recalc(window); } - /* * Done with a window - destroy it. Release the memory only if * it wasn't allocated when we got it! */ short -destroy_tty (WindowPtr window) { -short s_err; -RECORD_EXISTS (record); +destroy_tty(WindowPtr window) +{ + short s_err; + RECORD_EXISTS(record); - s_err = free_bits (record); - if (!s_err) { + s_err = free_bits(record); + if (!s_err) { #if !TARGET_API_MAC_CARBON - if (record->was_allocated) { - CloseWindow (window); - } else { + if (record->was_allocated) { + CloseWindow(window); + } else { #endif - DisposeWindow (window); + DisposeWindow(window); #if !TARGET_API_MAC_CARBON - } + } #endif - s_err = dispose_ptr (record); - } - - return s_err; + s_err = dispose_ptr(record); + } + + return s_err; } - static void -do_set_port_font (tty_record *record) { - - PenNormal (); - TextFont (record->font_number); - TextSize (record->font_size); - if (0L != (record->attribute [TTY_ATTRIB_FLAGS] & TA_OVERSTRIKE)) { - TextMode (srcOr); - } else { - TextMode (srcCopy); - } +do_set_port_font(tty_record *record) +{ + PenNormal(); + TextFont(record->font_number); + TextSize(record->font_size); + if (0L != (record->attribute[TTY_ATTRIB_FLAGS] & TA_OVERSTRIKE)) { + TextMode(srcOr); + } else { + TextMode(srcCopy); + } } - /* * Fill in some fields from some other fields that may have changed */ static void -calc_font_sizes (tty_record *record) { -FontInfo font_info; +calc_font_sizes(tty_record *record) +{ + FontInfo font_info; - do_set_port_font (record); + do_set_port_font(record); - GetFontInfo (&font_info); - record->char_width = font_info.widMax; - record->ascent_height = font_info.ascent + font_info.leading; - record->row_height = record->ascent_height + font_info.descent; + GetFontInfo(&font_info); + record->char_width = font_info.widMax; + record->ascent_height = font_info.ascent + font_info.leading; + record->row_height = record->ascent_height + font_info.descent; } - /* * Allocate memory for the bitmap holding the tty window */ static short -alloc_bits (tty_record *record) { -short s_err; +alloc_bits(tty_record *record) +{ + short s_err; - SetRect (&record->its_bits.bounds, 0, 0, - record->char_width * record->x_size, - record->row_height * record->y_size); + SetRect(&record->its_bits.bounds, 0, 0, + record->char_width * record->x_size, + record->row_height * record->y_size); -/* - * Clear two highest and lowest bit - not a color pixMap, and even in size - */ - record->its_bits.rowBytes = ((record->its_bits.bounds.right + 15) - >> 3) & 0x1ffe; + /* + * Clear two highest and lowest bit - not a color pixMap, and even in size + */ + record->its_bits.rowBytes = + ((record->its_bits.bounds.right + 15) >> 3) & 0x1ffe; - if (record->uses_gworld) { - s_err = allocate_offscreen_world (record); + if (record->uses_gworld) { + s_err = allocate_offscreen_world(record); #if !TARGET_API_MAC_CARBON - } else { - s_err = alloc_ptr ((void **) &(record->its_bits.baseAddr), - record->its_bits.rowBytes * record->its_bits.bounds.bottom); - if (!s_err) { - s_err = alloc_ptr ((void **) &(record->offscreen_port), - sizeof (GrafPort)); - } - if (!s_err) { - OpenPort (record->offscreen_port); - SetPort (record->offscreen_port); - ClipRect (&(record->its_bits.bounds)); - SetPortBits (&(record->its_bits)); - } + } else { + s_err = alloc_ptr((void **) &(record->its_bits.baseAddr), + record->its_bits.rowBytes + * record->its_bits.bounds.bottom); + if (!s_err) { + s_err = alloc_ptr((void **) &(record->offscreen_port), + sizeof(GrafPort)); + } + if (!s_err) { + OpenPort(record->offscreen_port); + SetPort(record->offscreen_port); + ClipRect(&(record->its_bits.bounds)); + SetPortBits(&(record->its_bits)); + } #endif - } - return s_err; + } + return s_err; } - /* * Save the current port/world in a safe place for later retrieval */ static void -save_port (tty_record *record, void *save) { -GWorldPtr gw; -GDHandle gh; -GrafPtr gp; +save_port(tty_record *record, void *save) +{ + GWorldPtr gw; + GDHandle gh; + GrafPtr gp; - if (record->uses_gworld) { - GetGWorld (&gw, &gh); - *(GWorldPtr *) save = gw; - } else { - GetPort (&gp); - *(GrafPtr *) save = gp; - } + if (record->uses_gworld) { + GetGWorld(&gw, &gh); + *(GWorldPtr *) save = gw; + } else { + GetPort(&gp); + *(GrafPtr *) save = gp; + } } - /* * Restore current port/world after a save */ static void -use_port (tty_record *record, void *port) { - if (record->uses_gworld) { - PixMapHandle pix_map; +use_port(tty_record *record, void *port) +{ + if (record->uses_gworld) { + PixMapHandle pix_map; - SetGWorld ((GWorldPtr) port, (GDHandle) 0); - pix_map = GetGWorldPixMap (record->offscreen_world); - if (pix_map) { - if (port == record->offscreen_world) - LockPixels (pix_map); - else - UnlockPixels (pix_map); - } - } else { - SetPort ((GrafPtr) port); - } + SetGWorld((GWorldPtr) port, (GDHandle) 0); + pix_map = GetGWorldPixMap(record->offscreen_world); + if (pix_map) { + if (port == record->offscreen_world) + LockPixels(pix_map); + else + UnlockPixels(pix_map); + } + } else { + SetPort((GrafPtr) port); + } } - /* * Use offscreen drawing - lock the pixels through use_port */ static void -select_offscreen_port (tty_record *record) { - if (record->uses_gworld) { - use_port (record, record->offscreen_world); - } else { - use_port (record, record->offscreen_port); - } +select_offscreen_port(tty_record *record) +{ + if (record->uses_gworld) { + use_port(record, record->offscreen_world); + } else { + use_port(record, record->offscreen_port); + } } - /* * Use the window - unlock pixels */ static void -select_onscreen_window (tty_record *record) { - if (record->uses_gworld) { - use_port (record, record->its_window_world); - SetPortWindowPort(record->its_window); - } else { - use_port(record, record->its_window); - } +select_onscreen_window(tty_record *record) +{ + if (record->uses_gworld) { + use_port(record, record->its_window_world); + SetPortWindowPort(record->its_window); + } else { + use_port(record, record->its_window); + } } - /* * Do bits copy depending on if we're using color or not */ static void -copy_bits(tty_record *record, Rect *bounds, short xfer_mode, RgnHandle mask_rgn) +copy_bits(tty_record *record, Rect *bounds, short xfer_mode, + RgnHandle mask_rgn) { - GWorldFlags pix_state; - BitMap * source; + GWorldFlags pix_state; + BitMap *source; - if (record->uses_gworld) { - pix_state = GetPixelsState (GetGWorldPixMap (record->offscreen_world)); - LockPixels (GetGWorldPixMap (record->offscreen_world)); - source = (BitMapPtr) *GetGWorldPixMap(record->offscreen_world); - } - else source = &record->its_bits; + if (record->uses_gworld) { + pix_state = GetPixelsState(GetGWorldPixMap(record->offscreen_world)); + LockPixels(GetGWorldPixMap(record->offscreen_world)); + source = (BitMapPtr) *GetGWorldPixMap(record->offscreen_world); + } else + source = &record->its_bits; - SetPortWindowPort(record->its_window); - CopyBits(source, GetPortBitMapForCopyBits(GetWindowPort(record->its_window)), - bounds, bounds, xfer_mode, mask_rgn); + SetPortWindowPort(record->its_window); + CopyBits(source, + GetPortBitMapForCopyBits(GetWindowPort(record->its_window)), + bounds, bounds, xfer_mode, mask_rgn); - if (record->uses_gworld) { - SetPixelsState (GetGWorldPixMap (record->offscreen_world), pix_state); - } + if (record->uses_gworld) { + SetPixelsState(GetGWorldPixMap(record->offscreen_world), pix_state); + } } - /* * Fill an area with the background color */ static void -erase_rect (tty_record *record, Rect *area) { - if (game_active && u.uhp > 0 && iflags.use_stone && record->its_window == _mt_window) { - PixPatHandle ppat; - - ppat = GetPixPat(iflags.use_stone + 127); /* find which pat to get */ - if (ppat) { /* in game window, using backgroung pattern, and have pattern */ - FillCRect (area, ppat); - DisposePixPat (ppat); - return; - } - } - EraseRect (area); -} +erase_rect(tty_record *record, Rect *area) +{ + if (game_active && u.uhp > 0 && iflags.use_stone + && record->its_window == _mt_window) { + PixPatHandle ppat; + ppat = GetPixPat(iflags.use_stone + 127); /* find which pat to get */ + if (ppat) { /* in game window, using backgroung pattern, and have + pattern */ + FillCRect(area, ppat); + DisposePixPat(ppat); + return; + } + } + EraseRect(area); +} /* * Recalculate the window based on new size, font, extent values, * and re-allocate the bitmap. */ short -force_tty_coordinate_system_recalc (WindowPtr window) { -short s_err; -RECORD_EXISTS (record); +force_tty_coordinate_system_recalc(WindowPtr window) +{ + short s_err; + RECORD_EXISTS(record); - s_err = free_bits (record); - if (s_err) { - return s_err; - } - calc_font_sizes (record); + s_err = free_bits(record); + if (s_err) { + return s_err; + } + calc_font_sizes(record); - s_err = alloc_bits (record); - if (s_err) { -/* - * Catastrophe! We could not allocate memory for the bitmap! Things may go very - * much downhill from here! - */ - dprintf ("alloc_bits returned null in force_tty_coordinate_system_recalc!"); - return s_err; - } - select_offscreen_port (record); - do_set_port_font (record); - return clear_tty (window); + s_err = alloc_bits(record); + if (s_err) { + /* + * Catastrophe! We could not allocate memory for the bitmap! Things + * may go very + * much downhill from here! + */ + dprintf("alloc_bits returned null in " + "force_tty_coordinate_system_recalc!"); + return s_err; + } + select_offscreen_port(record); + do_set_port_font(record); + return clear_tty(window); } - #if 0 /* * Update TTY according to new color environment for the window @@ -552,676 +553,696 @@ Rect r_screen; } #endif - /* * Read a lot of interesting and useful information from the current tty */ short -get_tty_metrics (WindowPtr window, short *x_size, short *y_size, - short *x_size_pixels, short *y_size_pixels, short *font_number, - short *font_size, short *char_width, short *row_height) { -RECORD_EXISTS (record); +get_tty_metrics(WindowPtr window, short *x_size, short *y_size, + short *x_size_pixels, short *y_size_pixels, + short *font_number, short *font_size, short *char_width, + short *row_height) +{ + RECORD_EXISTS(record); -/* - * First, test that we actually have something to draw to... - */ - if ((((char *)0 == record->its_bits.baseAddr) && !record->uses_gworld) || - (((GWorldPtr)0 == record->offscreen_world) && record->uses_gworld)) { - return general_failure; - } + /* + * First, test that we actually have something to draw to... + */ + if ((((char *) 0 == record->its_bits.baseAddr) && !record->uses_gworld) + || (((GWorldPtr) 0 == record->offscreen_world) + && record->uses_gworld)) { + return general_failure; + } - *x_size = record->x_size; - *y_size = record->y_size; - *x_size_pixels = record->its_bits.bounds.right; - *y_size_pixels = record->its_bits.bounds.bottom; - *font_number = record->font_number; - *font_size = record->font_size; - *char_width = record->char_width; - *row_height = record->row_height; + *x_size = record->x_size; + *y_size = record->y_size; + *x_size_pixels = record->its_bits.bounds.right; + *y_size_pixels = record->its_bits.bounds.bottom; + *font_number = record->font_number; + *font_size = record->font_size; + *char_width = record->char_width; + *row_height = record->row_height; - return noErr; + return noErr; } - /* * Map a position on the map to screen coordinates */ static void -pos_rect (tty_record *record, Rect *r, short x_pos, short y_pos, - short x_end, short y_end) { - - SetRect (r, x_pos * (record->char_width), y_pos * (record->row_height), - (1 + x_end) * (record->char_width) , (1 + y_end) * - (record->row_height)); +pos_rect(tty_record *record, Rect *r, short x_pos, short y_pos, short x_end, + short y_end) +{ + SetRect(r, x_pos * (record->char_width), y_pos * (record->row_height), + (1 + x_end) * (record->char_width), + (1 + y_end) * (record->row_height)); } - static void -accumulate_rect (tty_record *record, Rect *rect) { +accumulate_rect(tty_record *record, Rect *rect) +{ #if CLIP_RECT_ONLY - union_rect (rect, &(record->invalid_rect), &(record->invalid_rect)); + union_rect(rect, &(record->invalid_rect), &(record->invalid_rect)); #else -RgnHandle rh = NewRgn (); + RgnHandle rh = NewRgn(); - RectRgn (rh, rect); - UnionRgn (record->invalid_part, rh, record->invalid_part); - DisposeRgn (rh); + RectRgn(rh, rect); + UnionRgn(record->invalid_part, rh, record->invalid_part); + DisposeRgn(rh); #endif } - /* - * get and set window invalid region. exposed for HandleUpdateEvent in macwin.c + * get and set window invalid region. exposed for HandleUpdateEvent in + * macwin.c * to correct display problem */ -short get_invalid_region (WindowPtr window, Rect *inval_rect) { - RECORD_EXISTS (record); +short +get_invalid_region(WindowPtr window, Rect *inval_rect) +{ + RECORD_EXISTS(record); #if CLIP_RECT_ONLY - if (record->invalid_rect.right <= record->invalid_rect.left || - record->invalid_rect.bottom <= record->invalid_rect.top) { - return general_failure; - } - *inval_rect = record->invalid_rect; + if (record->invalid_rect.right <= record->invalid_rect.left + || record->invalid_rect.bottom <= record->invalid_rect.top) { + return general_failure; + } + *inval_rect = record->invalid_rect; #else - if (EmptyRgn (record->invalid_part)) { - return general_failure; - } - *inval_rect = (*(record->invalid_part))->rgnBBox; + if (EmptyRgn(record->invalid_part)) { + return general_failure; + } + *inval_rect = (*(record->invalid_part))->rgnBBox; #endif - return noErr; + return noErr; } -short set_invalid_region (WindowPtr window, Rect *inval_rect) { - RECORD_EXISTS (record); - accumulate_rect (record, inval_rect); - return noErr; +short +set_invalid_region(WindowPtr window, Rect *inval_rect) +{ + RECORD_EXISTS(record); + accumulate_rect(record, inval_rect); + return noErr; } - /* * Invert the specified position */ static void -curs_pos (tty_record *record, short x_pos, short y_pos, short to_state) { -Rect r; +curs_pos(tty_record *record, short x_pos, short y_pos, short to_state) +{ + Rect r; - if (record->curs_state == to_state) { - return; - } - record->curs_state = to_state; - pos_rect (record, &r, x_pos, y_pos, x_pos, y_pos); + if (record->curs_state == to_state) { + return; + } + record->curs_state = to_state; + pos_rect(record, &r, x_pos, y_pos, x_pos, y_pos); - if (DRAW_DIRECT) { - void *old_port; + if (DRAW_DIRECT) { + void *old_port; - save_port (record, &old_port); - select_onscreen_window (record); - InvertRect (&r); - use_port (record, old_port); - } else { - accumulate_rect (record, &r); - } + save_port(record, &old_port); + select_onscreen_window(record); + InvertRect(&r); + use_port(record, old_port); + } else { + accumulate_rect(record, &r); + } } - /* * Move the cursor (both as displayed and where drawing goes) * HOWEVER: The cursor is NOT stored in the bitmap! */ short -move_tty_cursor (WindowPtr window, short x_pos, short y_pos) { -RECORD_EXISTS (record); +move_tty_cursor(WindowPtr window, short x_pos, short y_pos) +{ + RECORD_EXISTS(record); - if (record->x_curs == x_pos && record->y_curs == y_pos) { - return noErr; - } - if (record->x_size <= x_pos || x_pos < 0 || - record->y_size <= y_pos || y_pos < 0) { - return general_failure; - } - curs_pos (record, record->x_curs, record->y_curs, 0); - record->x_curs = x_pos; - record->y_curs = y_pos; - curs_pos (record, x_pos, y_pos, 1); + if (record->x_curs == x_pos && record->y_curs == y_pos) { + return noErr; + } + if (record->x_size <= x_pos || x_pos < 0 || record->y_size <= y_pos + || y_pos < 0) { + return general_failure; + } + curs_pos(record, record->x_curs, record->y_curs, 0); + record->x_curs = x_pos; + record->y_curs = y_pos; + curs_pos(record, x_pos, y_pos, 1); - return noErr; + return noErr; } - /* * Update the screen to match the current bitmap, after adding stuff * with add_tty_char etc. */ short -update_tty (WindowPtr window) { -Rect r; -RECORD_EXISTS (record); +update_tty(WindowPtr window) +{ + Rect r; + RECORD_EXISTS(record); #if CLIP_RECT_ONLY - if (record->invalid_rect.right <= record->invalid_rect.left || - record->invalid_rect.bottom <= record->invalid_rect.top) { - return noErr; - } - r = record->invalid_rect; + if (record->invalid_rect.right <= record->invalid_rect.left + || record->invalid_rect.bottom <= record->invalid_rect.top) { + return noErr; + } + r = record->invalid_rect; #else - if (EmptyRgn (record->invalid_part)) { - return noErr; - } - r = (*(record->invalid_part))->rgnBBox; + if (EmptyRgn(record->invalid_part)) { + return noErr; + } + r = (*(record->invalid_part))->rgnBBox; #endif - select_onscreen_window (record); - copy_bits (record, &r, srcCopy, (RgnHandle) 0); + select_onscreen_window(record); + copy_bits(record, &r, srcCopy, (RgnHandle) 0); #if CLIP_RECT_ONLY - empty_rect (&(record->invalid_rect)); + empty_rect(&(record->invalid_rect)); #else - SetEmptyRgn (record->invalid_part); + SetEmptyRgn(record->invalid_part); #endif - if (record->curs_state) { - pos_rect (record, &r, record->x_curs, record->y_curs, - record->x_curs, record->y_curs); - InvertRect (&r); - } + if (record->curs_state) { + pos_rect(record, &r, record->x_curs, record->y_curs, record->x_curs, + record->y_curs); + InvertRect(&r); + } - return noErr; + return noErr; } - /* * Low level add to screen */ static void -do_add_string (tty_record *record, char *str, short len) { -Rect r; +do_add_string(tty_record *record, char *str, short len) +{ + Rect r; - if (len < 1) { - return; - } - select_offscreen_port (record); + if (len < 1) { + return; + } + select_offscreen_port(record); - MoveTo (record->x_curs * record->char_width, record->y_curs * - record->row_height + record->ascent_height); - DrawText (str, 0, len); + MoveTo(record->x_curs * record->char_width, + record->y_curs * record->row_height + record->ascent_height); + DrawText(str, 0, len); - pos_rect (record, &r, record->x_curs, record->y_curs, - record->x_curs + len - 1, record->y_curs); - select_onscreen_window (record); - if (DRAW_DIRECT) { - copy_bits (record, &r, srcCopy, (RgnHandle)0); - } else { - accumulate_rect (record, &r); - } + pos_rect(record, &r, record->x_curs, record->y_curs, + record->x_curs + len - 1, record->y_curs); + select_onscreen_window(record); + if (DRAW_DIRECT) { + copy_bits(record, &r, srcCopy, (RgnHandle) 0); + } else { + accumulate_rect(record, &r); + } } - /* * Low-level cursor handling routine */ static void -do_add_cursor (tty_record *record, short x_pos) { - - record->x_curs = x_pos; - if (record->x_curs >= record->x_size) { - if (0L != (record->attribute [TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND)) { - record->y_curs ++; - record->x_curs = 0; - if (record->y_curs >= record->y_size) { - if (0L != (record->attribute [TTY_ATTRIB_FLAGS] & - TA_INHIBIT_VERT_SCROLL)) { - record->y_curs = record->y_size; - } else { - scroll_tty (record->its_window, 0, 1 + record->y_curs - - record->y_size); - } - } - } else { - record->x_curs = record->x_size; - } - } +do_add_cursor(tty_record *record, short x_pos) +{ + record->x_curs = x_pos; + if (record->x_curs >= record->x_size) { + if (0L != (record->attribute[TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND)) { + record->y_curs++; + record->x_curs = 0; + if (record->y_curs >= record->y_size) { + if (0L != (record->attribute[TTY_ATTRIB_FLAGS] + & TA_INHIBIT_VERT_SCROLL)) { + record->y_curs = record->y_size; + } else { + scroll_tty(record->its_window, 0, + 1 + record->y_curs - record->y_size); + } + } + } else { + record->x_curs = record->x_size; + } + } } - /* * Do control character */ static void -do_control (tty_record *record, short character) { - int recurse = 0; +do_control(tty_record *record, short character) +{ + int recurse = 0; -/* - * Check recursion because nl_add_cr and cr_add_nl may both be set and invoke each other - */ - do { - switch (character) { - case CHAR_CR : - record->x_curs = 0; - if (!recurse && (record->attribute [TTY_ATTRIB_CURSOR] & TA_CR_ADD_NL)) { - recurse = 1; - } - else { - recurse = 0; - break; - } /* FALL-THROUGH: if CR-LF, don't bother with loop */ - case CHAR_LF : - record->y_curs++; - if (record->y_curs >= record->y_size) { - scroll_tty (record->its_window, 0, 1 + record->y_curs - record->y_size); - } - if (!recurse && (record->attribute [TTY_ATTRIB_CURSOR] & TA_NL_ADD_CR)) { - character = CHAR_CR; - recurse = 1; - } - else recurse = 0; - break; - case CHAR_BELL : - tty_nhbell(); - break; - case CHAR_BS : - if (record->x_curs > 0) - record->x_curs --; - default : - break; - } - } while (recurse); + /* + * Check recursion because nl_add_cr and cr_add_nl may both be set and + * invoke each other + */ + do { + switch (character) { + case CHAR_CR: + record->x_curs = 0; + if (!recurse + && (record->attribute[TTY_ATTRIB_CURSOR] & TA_CR_ADD_NL)) { + recurse = 1; + } else { + recurse = 0; + break; + } /* FALL-THROUGH: if CR-LF, don't bother with loop */ + case CHAR_LF: + record->y_curs++; + if (record->y_curs >= record->y_size) { + scroll_tty(record->its_window, 0, + 1 + record->y_curs - record->y_size); + } + if (!recurse + && (record->attribute[TTY_ATTRIB_CURSOR] & TA_NL_ADD_CR)) { + character = CHAR_CR; + recurse = 1; + } else + recurse = 0; + break; + case CHAR_BELL: + tty_nhbell(); + break; + case CHAR_BS: + if (record->x_curs > 0) + record->x_curs--; + default: + break; + } + } while (recurse); } - /* * Add a single character. It is drawn directly if the correct flag is set, * else deferred to the next update event or call of update_tty() */ short -add_tty_char (WindowPtr window, short character) { -register char is_control; -char ch; -RECORD_EXISTS (record); +add_tty_char(WindowPtr window, short character) +{ + register char is_control; + char ch; + RECORD_EXISTS(record); - if (!(record->attribute [TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND) && - record->x_curs >= record->x_size) - return noErr; /* Optimize away drawing across border without wrap */ + if (!(record->attribute[TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND) + && record->x_curs >= record->x_size) + return noErr; /* Optimize away drawing across border without wrap */ - if (record->curs_state != 0) - curs_pos (record, record->x_curs, record->y_curs, 0); + if (record->curs_state != 0) + curs_pos(record, record->x_curs, record->y_curs, 0); - ch = character; - is_control = (ch < sizeof(long) * 8) && ((s_control & (1 << ch)) != 0L); - if (is_control) - do_control (record, ch); - else { - do_add_string (record, (char *)&ch, 1); - do_add_cursor (record, record->x_curs + 1); - } + ch = character; + is_control = (ch < sizeof(long) * 8) && ((s_control & (1 << ch)) != 0L); + if (is_control) + do_control(record, ch); + else { + do_add_string(record, (char *) &ch, 1); + do_add_cursor(record, record->x_curs + 1); + } - return noErr; + return noErr; } - /* * Add a null-terminated string of characters */ short add_tty_string(WindowPtr window, const char *string) { - register const unsigned char * start_c; - register const unsigned char * the_c; - register unsigned char ch, is_control = 0, tty_wrap; - register short max_x, pos_x; - RECORD_EXISTS (record); + register const unsigned char *start_c; + register const unsigned char *the_c; + register unsigned char ch, is_control = 0, tty_wrap; + register short max_x, pos_x; + RECORD_EXISTS(record); - if (record->curs_state != 0) - curs_pos (record, record->x_curs, record->y_curs, 0); + if (record->curs_state != 0) + curs_pos(record, record->x_curs, record->y_curs, 0); - the_c = (const unsigned char *) string; - max_x = record->x_size; - tty_wrap = (record->attribute [TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND); - for (;;) { - pos_x = record->x_curs; - if (!tty_wrap && pos_x >= max_x) - break; /* Optimize away drawing across border without wrap */ + the_c = (const unsigned char *) string; + max_x = record->x_size; + tty_wrap = (record->attribute[TTY_ATTRIB_FLAGS] & TA_WRAP_AROUND); + for (;;) { + pos_x = record->x_curs; + if (!tty_wrap && pos_x >= max_x) + break; /* Optimize away drawing across border without wrap */ - start_c = the_c; - ch = *the_c; - while (pos_x < max_x) { - is_control = (ch < sizeof(long) * 8) && ((s_control & (1 << ch)) != 0L); - if (is_control) - break; - the_c ++; ch = *the_c; - pos_x ++; - } - do_add_string (record, (char *) start_c, the_c - start_c); - do_add_cursor (record, pos_x); - if (!ch) - break; + start_c = the_c; + ch = *the_c; + while (pos_x < max_x) { + is_control = + (ch < sizeof(long) * 8) && ((s_control & (1 << ch)) != 0L); + if (is_control) + break; + the_c++; + ch = *the_c; + pos_x++; + } + do_add_string(record, (char *) start_c, the_c - start_c); + do_add_cursor(record, pos_x); + if (!ch) + break; - if (is_control) { - do_control (record, ch); - the_c ++; - } - } + if (is_control) { + do_control(record, ch); + the_c++; + } + } - return noErr; + return noErr; } - /* * Read or change attributes for the tty. Note that some attribs may * very well clear and reallocate the bitmap when changed, whereas * others (color, highlight, ...) are guaranteed not to. */ -short get_tty_attrib (WindowPtr window, tty_attrib attrib, long *value) { -RECORD_EXISTS (record); +short +get_tty_attrib(WindowPtr window, tty_attrib attrib, long *value) +{ + RECORD_EXISTS(record); - if (attrib < 0 || attrib >= TTY_NUMBER_ATTRIBUTES) { - return general_failure; - } - *value = record->attribute [attrib]; + if (attrib < 0 || attrib >= TTY_NUMBER_ATTRIBUTES) { + return general_failure; + } + *value = record->attribute[attrib]; - return noErr; + return noErr; } +short +set_tty_attrib(WindowPtr window, tty_attrib attrib, long value) +{ + RGBColor rgb_color; + RECORD_EXISTS(record); -short set_tty_attrib (WindowPtr window, tty_attrib attrib, long value) { -RGBColor rgb_color; -RECORD_EXISTS (record); - - if (attrib < 0 || attrib >= TTY_NUMBER_ATTRIBUTES) { - return general_failure; - } - record->attribute [attrib] = value; - /* - * Presently, no attributes generate a new bitmap. - */ - switch (attrib) { - case TTY_ATTRIB_CURSOR : -/* - * Check if we should change tables - */ - if (0L != (value & TA_RAW_OUTPUT)) { - s_control = RAW_CONTROLS; - } else { - s_control = COOKED_CONTROLS; - } - break; - case TTY_ATTRIB_FLAGS : -/* - * Check if we should flush the output going from cached to draw-direct - */ - if (0L != (value & TA_ALWAYS_REFRESH)) { - update_tty (window); - } - break; - case TTY_ATTRIB_FOREGROUND : -/* - * Set foreground color - */ - TA_TO_RGB (value, rgb_color); - select_offscreen_port (record); - RGBForeColor (&rgb_color); - select_onscreen_window (record); - break; - case TTY_ATTRIB_BACKGROUND : -/* - * Set background color - */ - TA_TO_RGB (value, rgb_color); - select_offscreen_port (record); - RGBBackColor (&rgb_color); - select_onscreen_window (record); - break; - default : - break; - } - return noErr; + if (attrib < 0 || attrib >= TTY_NUMBER_ATTRIBUTES) { + return general_failure; + } + record->attribute[attrib] = value; + /* + * Presently, no attributes generate a new bitmap. + */ + switch (attrib) { + case TTY_ATTRIB_CURSOR: + /* + * Check if we should change tables + */ + if (0L != (value & TA_RAW_OUTPUT)) { + s_control = RAW_CONTROLS; + } else { + s_control = COOKED_CONTROLS; + } + break; + case TTY_ATTRIB_FLAGS: + /* + * Check if we should flush the output going from cached to + * draw-direct + */ + if (0L != (value & TA_ALWAYS_REFRESH)) { + update_tty(window); + } + break; + case TTY_ATTRIB_FOREGROUND: + /* + * Set foreground color + */ + TA_TO_RGB(value, rgb_color); + select_offscreen_port(record); + RGBForeColor(&rgb_color); + select_onscreen_window(record); + break; + case TTY_ATTRIB_BACKGROUND: + /* + * Set background color + */ + TA_TO_RGB(value, rgb_color); + select_offscreen_port(record); + RGBBackColor(&rgb_color); + select_onscreen_window(record); + break; + default: + break; + } + return noErr; } - /* - * Scroll the window. Positive is up/left. scroll_tty ( window, 0, 1 ) is a line feed. + * Scroll the window. Positive is up/left. scroll_tty ( window, 0, 1 ) is a + * line feed. * Scroll flushes the accumulated update area by calling update_tty(). */ -short scroll_tty (WindowPtr window, short delta_x, short delta_y) { -RgnHandle rgn; -short s_err; -RECORD_EXISTS (record); +short +scroll_tty(WindowPtr window, short delta_x, short delta_y) +{ + RgnHandle rgn; + short s_err; + RECORD_EXISTS(record); - s_err = update_tty (window); + s_err = update_tty(window); - rgn = NewRgn (); + rgn = NewRgn(); - select_offscreen_port (record); - ScrollRect (&(record->its_bits.bounds), -delta_x * record->char_width, - -delta_y * record->row_height, rgn); - EraseRgn (rgn); - SetEmptyRgn (rgn); + select_offscreen_port(record); + ScrollRect(&(record->its_bits.bounds), -delta_x * record->char_width, + -delta_y * record->row_height, rgn); + EraseRgn(rgn); + SetEmptyRgn(rgn); - select_onscreen_window (record); - ScrollRect (&(record->its_bits.bounds), -delta_x * record->char_width, - -delta_y*record->row_height, rgn); - EraseRgn (rgn); - DisposeRgn (rgn); + select_onscreen_window(record); + ScrollRect(&(record->its_bits.bounds), -delta_x * record->char_width, + -delta_y * record->row_height, rgn); + EraseRgn(rgn); + DisposeRgn(rgn); - record->y_curs -= delta_y; - record->x_curs -= delta_x; + record->y_curs -= delta_y; + record->x_curs -= delta_x; - return noErr; + return noErr; } - /* * Clear the screen. Immediate. */ -short clear_tty (WindowPtr window) { -RECORD_EXISTS (record); +short +clear_tty(WindowPtr window) +{ + RECORD_EXISTS(record); - record->curs_state = 0; - select_offscreen_port (record); - erase_rect (record, &(record->its_bits.bounds)); - accumulate_rect (record, &(record->its_bits.bounds)); - update_tty (window); + record->curs_state = 0; + select_offscreen_port(record); + erase_rect(record, &(record->its_bits.bounds)); + accumulate_rect(record, &(record->its_bits.bounds)); + update_tty(window); - return noErr; + return noErr; } - /* * Blink cursor on window if necessary */ -short blink_cursor (WindowPtr window, long when) { - RECORD_EXISTS (record); +short +blink_cursor(WindowPtr window, long when) +{ + RECORD_EXISTS(record); - if ((record->attribute [TTY_ATTRIB_CURSOR] & TA_BLINKING_CURSOR)) { - if (when > record->last_cursor + GetCaretTime ()) { - curs_pos (record, record->x_curs, record->y_curs, !record->curs_state); - record->last_cursor = when; - update_tty (window); - } - } - return 0; + if ((record->attribute[TTY_ATTRIB_CURSOR] & TA_BLINKING_CURSOR)) { + if (when > record->last_cursor + GetCaretTime()) { + curs_pos(record, record->x_curs, record->y_curs, + !record->curs_state); + record->last_cursor = when; + update_tty(window); + } + } + return 0; } - /* * Draw an image of the tty - used for update events and can be called * for screen dumps. */ short -image_tty (EventRecord *theEvent, WindowPtr window) { +image_tty(EventRecord *theEvent, WindowPtr window) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(theEvent) +#pragma unused(theEvent) #endif -RECORD_EXISTS (record); + RECORD_EXISTS(record); #if CLIP_RECT_ONLY - record->invalid_rect = record->its_bits.bounds; + record->invalid_rect = record->its_bits.bounds; #else -RgnHandle rh = NewRgn (); + RgnHandle rh = NewRgn(); - RectRgn (rh, record ->its_bits.bounds); - UnionRgn (record->invalid_part, rh, record->invalid_part); - DisposeRgn (rh); + RectRgn(rh, record->its_bits.bounds); + UnionRgn(record->invalid_part, rh, record->invalid_part); + DisposeRgn(rh); #endif - return update_tty (window); + return update_tty(window); } - - /* * Clear an area */ -short clear_tty_window (WindowPtr window, short from_x, short from_y, - short to_x, short to_y) { -Rect r; -RECORD_EXISTS (record); +short +clear_tty_window(WindowPtr window, short from_x, short from_y, short to_x, + short to_y) +{ + Rect r; + RECORD_EXISTS(record); - if (from_x > to_x || from_y > to_y) { - return general_failure; - } - pos_rect (record, &r, from_x, from_y, to_x, to_y); - select_offscreen_port (record); - erase_rect (record, &r); - accumulate_rect (record, &r); - if (DRAW_DIRECT) { - update_tty (window); - } else - select_onscreen_window (record); - return noErr; + if (from_x > to_x || from_y > to_y) { + return general_failure; + } + pos_rect(record, &r, from_x, from_y, to_x, to_y); + select_offscreen_port(record); + erase_rect(record, &r); + accumulate_rect(record, &r); + if (DRAW_DIRECT) { + update_tty(window); + } else + select_onscreen_window(record); + return noErr; } - #if EXTENDED_SUPPORT /* * Delete or insert operations used by many terminals can bottleneck through * here. Note that the order of executin for row/colum insertions is NOT * specified. Negative values for num_ mean delete, zero means no effect. */ -short mangle_tty_rows_columns (WindowPtr window, short from_row, short num_rows, - short from_column, short num_columns) { -Rect r; -RgnHandle rh = NewRgn (); -RECORD_EXISTS (record); +short +mangle_tty_rows_columns(WindowPtr window, short from_row, short num_rows, + short from_column, short num_columns) +{ + Rect r; + RgnHandle rh = NewRgn(); + RECORD_EXISTS(record); - update_tty (window); /* Always make sure screen is OK */ - curs_pos (record, record->x_curs, record->y_curs, 0); + update_tty(window); /* Always make sure screen is OK */ + curs_pos(record, record->x_curs, record->y_curs, 0); - if (num_rows) { - pos_rect (record, &r, 0, from_row, record->x_size - 1, - record->y_size - 1); - select_offscreen_port (record); - ScrollRect (&r, 0, num_rows * record->row_height, rh); - EraseRgn (rh); - SetEmptyRgn (rh); - select_onscreen_window (record); - ScrollRect (&r, 0, num_rows * record->row_height, rh); - EraseRgn (rh); - SetEmptyRgn (rh); - } - if (num_columns) { - pos_rect (record, &r, from_column, 0, record->x_size - 1, - record->y_size - 1); - select_offscreen_port (record); - ScrollRect (&r, num_columns * record->char_width, 0, rh); - EraseRgn (rh); - SetEmptyRgn (rh); - select_onscreen_window (record); - ScrollRect (&r, num_columns * record->char_width, 0, rh); - EraseRgn (rh); - SetEmptyRgn (rh); - } - DisposeRgn (rh); - if (record->x_curs >= from_column) { - record->x_curs += num_columns; - } - if (record->y_curs >= from_row) { - record->y_curs += num_rows; - } - curs_pos (record, record->x_curs, record->y_curs, 1); + if (num_rows) { + pos_rect(record, &r, 0, from_row, record->x_size - 1, + record->y_size - 1); + select_offscreen_port(record); + ScrollRect(&r, 0, num_rows * record->row_height, rh); + EraseRgn(rh); + SetEmptyRgn(rh); + select_onscreen_window(record); + ScrollRect(&r, 0, num_rows * record->row_height, rh); + EraseRgn(rh); + SetEmptyRgn(rh); + } + if (num_columns) { + pos_rect(record, &r, from_column, 0, record->x_size - 1, + record->y_size - 1); + select_offscreen_port(record); + ScrollRect(&r, num_columns * record->char_width, 0, rh); + EraseRgn(rh); + SetEmptyRgn(rh); + select_onscreen_window(record); + ScrollRect(&r, num_columns * record->char_width, 0, rh); + EraseRgn(rh); + SetEmptyRgn(rh); + } + DisposeRgn(rh); + if (record->x_curs >= from_column) { + record->x_curs += num_columns; + } + if (record->y_curs >= from_row) { + record->y_curs += num_rows; + } + curs_pos(record, record->x_curs, record->y_curs, 1); - return noErr; + return noErr; } /* * Frame an area in an aesthetically pleasing way. */ -short frame_tty_window (WindowPtr window, short from_x, short from_y , - short to_x, short to_y, short frame_fatness) { -Rect r; -RECORD_EXISTS (record); +short +frame_tty_window(WindowPtr window, short from_x, short from_y, short to_x, + short to_y, short frame_fatness) +{ + Rect r; + RECORD_EXISTS(record); - if (from_x > to_x || from_y > to_y) { - return general_failure; - } - pos_rect (record, & r, from_x, from_y, to_x, to_y); - select_offscreen_port (record); - PenSize (frame_fatness, frame_fatness); - FrameRect (&r); - PenNormal (); - accumulate_rect (record, &r); - if (DRAW_DIRECT) { - update_tty (window); - } else - select_onscreen_window (record); + if (from_x > to_x || from_y > to_y) { + return general_failure; + } + pos_rect(record, &r, from_x, from_y, to_x, to_y); + select_offscreen_port(record); + PenSize(frame_fatness, frame_fatness); + FrameRect(&r); + PenNormal(); + accumulate_rect(record, &r); + if (DRAW_DIRECT) { + update_tty(window); + } else + select_onscreen_window(record); } - /* * Highlighting a specific part of the tty window */ -short invert_tty_window (WindowPtr window, short from_x, short from_y , - short to_x, short to_y) { -Rect r; -RECORD_EXISTS (record); +short +invert_tty_window(WindowPtr window, short from_x, short from_y, short to_x, + short to_y) +{ + Rect r; + RECORD_EXISTS(record); - if (from_x > to_x || from_y > to_y) { - return general_failure; - } - pos_rect (record, &r, from_x, from_y, to_x, to_y); - select_offscreen_port (record); - InvertRect ( &r); - accumulate_rect (record, &r); - if (DRAW_DIRECT) { - update_tty (window); - } else - select_onscreen_window (record); + if (from_x > to_x || from_y > to_y) { + return general_failure; + } + pos_rect(record, &r, from_x, from_y, to_x, to_y); + select_offscreen_port(record); + InvertRect(&r); + accumulate_rect(record, &r); + if (DRAW_DIRECT) { + update_tty(window); + } else + select_onscreen_window(record); } - static void -canonical_rect (Rect * r, short x1, short y1, short x2, short y2) { - if (x1 < x2) { - if (y1 < y2) { - SetRect (r, x1, x2, y1, y2); - } else { - SetRect (r, x1, x2, y2, y1); - } - } else { - if (y1 < y2) { - SetRect (r, x2, x1, y1, y2); - } else { - SetRect (r, x2, x1, y2, y1); - } - } +canonical_rect(Rect *r, short x1, short y1, short x2, short y2) +{ + if (x1 < x2) { + if (y1 < y2) { + SetRect(r, x1, x2, y1, y2); + } else { + SetRect(r, x1, x2, y2, y1); + } + } else { + if (y1 < y2) { + SetRect(r, x2, x1, y1, y2); + } else { + SetRect(r, x2, x1, y2, y1); + } + } } - /* * Line drawing - very device dependent */ -short draw_tty_line (WindowPtr window, short from_x, short from_y , - short to_x, short to_y) { -Rect r; -RECORD_EXISTS (record); +short +draw_tty_line(WindowPtr window, short from_x, short from_y, short to_x, + short to_y) +{ + Rect r; + RECORD_EXISTS(record); - select_offscreen_port (record); - MoveTo (from_x, from_y); - LineTo (to_x, to_y); - canonical_rect (&r, from_x, from_y, to_x, to_y); - accumulate_rect (record, &r); - if (DRAW_DIRECT) { - update_tty (window); - } else - select_onscreen_window (record); + select_offscreen_port(record); + MoveTo(from_x, from_y); + LineTo(to_x, to_y); + canonical_rect(&r, from_x, from_y, to_x, to_y); + accumulate_rect(record, &r); + if (DRAW_DIRECT) { + update_tty(window); + } else + select_onscreen_window(record); } - #endif /* EXTENDED_SUPPORT */ diff --git a/sys/mac/macunix.c b/sys/mac/macunix.c index b015c7247..56b45eeaa 100644 --- a/sys/mac/macunix.c +++ b/sys/mac/macunix.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 macunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macunix.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 macunix.c $Date: 2009/05/06 10:49:16 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)macunix.c 3.5 1994/11/07 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -11,31 +11,31 @@ void regularize(char *s) { - register char *lp; + register char *lp; - for (lp = s; *lp; lp++) { - if (*lp == '.' || *lp == ':') - *lp = '_'; - } + for (lp = s; *lp; lp++) { + if (*lp == '.' || *lp == ':') + *lp = '_'; + } } void getlock(void) { - int fd; - int pid = getpid(); /* Process ID */ + int fd; + int pid = getpid(); /* Process ID */ - Sprintf(lock, "%d%s", getuid(), plname); - set_levelfile_name (lock, 0); + Sprintf(lock, "%d%s", getuid(), plname); + set_levelfile_name(lock, 0); - if ((fd = open (lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) { - raw_printf ("Could not lock the game %s.", lock); - panic ("Another game in progress?"); - } + if ((fd = open(lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) { + raw_printf("Could not lock the game %s.", lock); + panic("Another game in progress?"); + } - if (write (fd, (char *)&pid, sizeof (pid)) != sizeof (pid)) { - raw_printf ("Could not lock the game %s.", lock); - panic("Disk locked?"); - } - close (fd); + if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) { + raw_printf("Could not lock the game %s.", lock); + panic("Disk locked?"); + } + close(fd); } diff --git a/sys/mac/macwin.c b/sys/mac/macwin.c index d2d53b7f4..64fb13125 100644 --- a/sys/mac/macwin.c +++ b/sys/mac/macwin.c @@ -1,9 +1,8 @@ -/* NetHack 3.6 macwin.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 macwin.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */ /* NetHack 3.6 macwin.c $Date: 2012/01/10 17:47:23 $ $Revision: 1.22 $ */ /* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */ /* NetHack may be freely redistributed. See license for details. */ - /********************************************************************** * Imported variables and functions */ @@ -23,13 +22,11 @@ #include #endif - - /********************************************************************** * Local variables and functions */ -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static EventTypeSpec baseevents[] = { { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyRepeat }, @@ -103,7 +100,6 @@ static void FDECL(GeneralCursor, (EventRecord *, WindowPtr, RgnHandle)); static void TextUpdate(NhWindow *wind); - NhWindow *theWindows = (NhWindow *) 0; Cursor qdarrow; @@ -111,8 +107,8 @@ Cursor qdarrow; extern WindowPtr _mt_window; /* Some useful #defines for the scroll bar width and height */ -#define SBARWIDTH 15 -#define SBARHEIGHT 15 +#define SBARWIDTH 15 +#define SBARHEIGHT 15 /* * We put a TE on the message window for the "top line" queries. @@ -123,9 +119,9 @@ extern WindowPtr _mt_window; * default response to a yn query. */ static TEHandle top_line = (TEHandle) nil; -static int topl_query_len; -static int topl_def_idx = -1; -static char topl_resp[10] = ""; +static int topl_query_len; +static int topl_def_idx = -1; +static char topl_resp[10] = ""; #define CHAR_ANY '\n' @@ -140,68 +136,65 @@ static char topl_resp[10] = ""; static winid inSelect = WIN_ERR; /* - * The key queue ring buffer where Read is where to take from, + * The key queue ring buffer where Read is where to take from, * Write is where next char goes and count is queue depth. */ -static unsigned char keyQueue [QUEUE_LEN]; -static int keyQueueRead = 0, - keyQueueWrite = 0, - keyQueueCount = 0; +static unsigned char keyQueue[QUEUE_LEN]; +static int keyQueueRead = 0, keyQueueWrite = 0, keyQueueCount = 0; -static Boolean gClickedToMove = 0; /* For ObscureCursor */ +static Boolean gClickedToMove = 0; /* For ObscureCursor */ -static Point clicked_pos; /* For nh_poskey */ +static Point clicked_pos; /* For nh_poskey */ static int clicked_mod; static Boolean cursor_locked = false; -static ControlActionUPP MoveScrollUPP; /* scrolling callback, init'ed in InitMac */ +static ControlActionUPP + MoveScrollUPP; /* scrolling callback, init'ed in InitMac */ void -lock_mouse_cursor(Boolean new_cursor_locked) { - cursor_locked = new_cursor_locked; +lock_mouse_cursor(Boolean new_cursor_locked) +{ + cursor_locked = new_cursor_locked; } - /* * Add key to input queue, force means flush left and replace if full */ void -AddToKeyQueue (unsigned char ch, Boolean force) { - if (keyQueueCount < QUEUE_LEN) { - keyQueue [keyQueueWrite++] = ch; - keyQueueCount++; - } - else if (force) { - keyQueue [keyQueueWrite++] = ch; - keyQueueRead++; - if (keyQueueRead >= QUEUE_LEN) - keyQueueRead = 0; - keyQueueCount = QUEUE_LEN; - } - if (keyQueueWrite >= QUEUE_LEN) - keyQueueWrite = 0; +AddToKeyQueue(unsigned char ch, Boolean force) +{ + if (keyQueueCount < QUEUE_LEN) { + keyQueue[keyQueueWrite++] = ch; + keyQueueCount++; + } else if (force) { + keyQueue[keyQueueWrite++] = ch; + keyQueueRead++; + if (keyQueueRead >= QUEUE_LEN) + keyQueueRead = 0; + keyQueueCount = QUEUE_LEN; + } + if (keyQueueWrite >= QUEUE_LEN) + keyQueueWrite = 0; } - /* * Get key from queue */ unsigned char -GetFromKeyQueue (void) { - unsigned char ret; +GetFromKeyQueue(void) +{ + unsigned char ret; - if (keyQueueCount) { - ret = keyQueue [keyQueueRead++]; - keyQueueCount--; - if (keyQueueRead >= QUEUE_LEN) - keyQueueRead = 0; - } - else - ret = 0; - return ret; + if (keyQueueCount) { + ret = keyQueue[keyQueueRead++]; + keyQueueCount--; + if (keyQueueRead >= QUEUE_LEN) + keyQueueRead = 0; + } else + ret = 0; + return ret; } - /* * Cursor movement */ @@ -219,253 +212,261 @@ MacFlags macFlags; Boolean small_screen = 0; #ifdef NHW_BASE -# undef NHW_BASE +#undef NHW_BASE #endif #define NHW_BASE 0 -static int FDECL(filter_scroll_key,(const int, NhWindow *)); +static int FDECL(filter_scroll_key, (const int, NhWindow *)); - -#if 1//!TARGET_API_MAC_CARBON -static void FDECL(DoScrollBar,(Point, short, ControlHandle, NhWindow *)); +#if 1 //!TARGET_API_MAC_CARBON +static void FDECL(DoScrollBar, (Point, short, ControlHandle, NhWindow *)); #endif static pascal void FDECL(MoveScrollBar, (ControlHandle, short)); -#if 1//!TARGET_API_MAC_CARBON -typedef void (*CbFunc) (EventRecord *, WindowPtr); -typedef short (*CbUpFunc) (EventRecord *, WindowPtr); -typedef void (*CbCursFunc) (EventRecord *, WindowPtr, RgnHandle); +#if 1 //!TARGET_API_MAC_CARBON +typedef void (*CbFunc)(EventRecord *, WindowPtr); +typedef short (*CbUpFunc)(EventRecord *, WindowPtr); +typedef void (*CbCursFunc)(EventRecord *, WindowPtr, RgnHandle); #define NUM_FUNCS 6 -static const CbFunc winKeyFuncs [NUM_FUNCS] = { - GeneralKey, GeneralKey, GeneralKey, GeneralKey, macKeyMenu, macKeyText +static const CbFunc winKeyFuncs[NUM_FUNCS] = { GeneralKey, GeneralKey, + GeneralKey, GeneralKey, + macKeyMenu, macKeyText }; + +static const CbFunc winClickFuncs[NUM_FUNCS] = { + (CbFunc) macDoNull, macClickMessage, macClickTerm, + macClickTerm, macClickMenu, macClickText }; -static const CbFunc winClickFuncs [NUM_FUNCS] = { - (CbFunc)macDoNull, macClickMessage, macClickTerm, macClickTerm, macClickMenu, - macClickText +static const CbUpFunc winUpdateFuncs[NUM_FUNCS] = { + macDoNull, macUpdateMessage, image_tty, + image_tty, macUpdateMenu, GeneralUpdate }; -static const CbUpFunc winUpdateFuncs [NUM_FUNCS] = { - macDoNull, macUpdateMessage, image_tty, image_tty, - macUpdateMenu, GeneralUpdate -}; - -static const CbCursFunc winCursorFuncs [NUM_FUNCS] = { - (CbCursFunc) macDoNull, GeneralCursor, macCursorTerm, macCursorTerm, - GeneralCursor, GeneralCursor +static const CbCursFunc winCursorFuncs[NUM_FUNCS] = { + (CbCursFunc) macDoNull, GeneralCursor, macCursorTerm, + macCursorTerm, GeneralCursor, GeneralCursor }; #endif - static NhWindow * -GetNhWin(WindowPtr mac_win) { - if (mac_win == _mt_window) /* term window is still maintained by both systems, and */ - return theWindows; /* WRefCon still refers to tty struct, so we have to map it */ - else { - NhWindow *aWin = (NhWindow *)GetWRefCon (mac_win); - if (aWin >= theWindows && aWin < &theWindows[NUM_MACWINDOWS]) - return aWin; - } - return ((NhWindow *) nil); +GetNhWin(WindowPtr mac_win) +{ + if (mac_win == _mt_window) /* term window is still maintained by both + systems, and */ + return theWindows; /* WRefCon still refers to tty struct, so we have + to map it */ + else { + NhWindow *aWin = (NhWindow *) GetWRefCon(mac_win); + if (aWin >= theWindows && aWin < &theWindows[NUM_MACWINDOWS]) + return aWin; + } + return ((NhWindow *) nil); } - -Boolean CheckNhWin (WindowPtr mac_win) { - return GetNhWin (mac_win) != nil; +Boolean +CheckNhWin(WindowPtr mac_win) +{ + return GetNhWin(mac_win) != nil; } - static pascal OSErr -AppleEventHandler (const AppleEvent* inAppleEvent, AppleEvent* outAEReply, long inRefCon) { +AppleEventHandler(const AppleEvent *inAppleEvent, AppleEvent *outAEReply, + long inRefCon) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(outAEReply,inRefCon) +#pragma unused(outAEReply, inRefCon) #endif - Size actualSize; - DescType typeCode; - AEEventID EventID; - OSErr err; + Size actualSize; + DescType typeCode; + AEEventID EventID; + OSErr err; - /* Get Event ID */ - err = AEGetAttributePtr (inAppleEvent, keyEventIDAttr, typeType, &typeCode, - &EventID, sizeof (EventID), &actualSize); - if (err == noErr) { - switch (EventID) { - default : - case kAEOpenApplication : - macFlags.gotOpen = 1; - /* fall through */ - case kAEPrintDocuments : - err = errAEEventNotHandled; - break; - case kAEQuitApplication : - /* Flush key queue */ - keyQueueCount = keyQueueWrite = keyQueueRead = 0; - AddToKeyQueue ('S', 1); - break; - case kAEOpenDocuments : { - FSSpec fss; - FInfo fndrInfo; - AEKeyword keywd; - AEDescList docList; - long index, itemsInList; + /* Get Event ID */ + err = AEGetAttributePtr(inAppleEvent, keyEventIDAttr, typeType, &typeCode, + &EventID, sizeof(EventID), &actualSize); + if (err == noErr) { + switch (EventID) { + default: + case kAEOpenApplication: + macFlags.gotOpen = 1; + /* fall through */ + case kAEPrintDocuments: + err = errAEEventNotHandled; + break; + case kAEQuitApplication: + /* Flush key queue */ + keyQueueCount = keyQueueWrite = keyQueueRead = 0; + AddToKeyQueue('S', 1); + break; + case kAEOpenDocuments: { + FSSpec fss; + FInfo fndrInfo; + AEKeyword keywd; + AEDescList docList; + long index, itemsInList; - if((err = AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docList)) != noErr || - (err = AECountItems(&docList, &itemsInList)) != noErr){ - if (err == errAEDescNotFound) - itemsInList = 0; - else - break; - } + if ((err = AEGetParamDesc(inAppleEvent, keyDirectObject, + typeAEList, &docList)) != noErr + || (err = AECountItems(&docList, &itemsInList)) != noErr) { + if (err == errAEDescNotFound) + itemsInList = 0; + else + break; + } - for(index = 1; index <= itemsInList; index++){ - err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &typeCode, (Ptr)&fss, - sizeof(FSSpec), &actualSize); - if(noErr != err) - break; + for (index = 1; index <= itemsInList; index++) { + err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &typeCode, + (Ptr) &fss, sizeof(FSSpec), &actualSize); + if (noErr != err) + break; - err = FSpGetFInfo (&fss, &fndrInfo); - if (noErr != err) - break; + err = FSpGetFInfo(&fss, &fndrInfo); + if (noErr != err) + break; - if (fndrInfo.fdType != SAVE_TYPE) - continue; /* only look at save files */ + if (fndrInfo.fdType != SAVE_TYPE) + continue; /* only look at save files */ - process_openfile (fss.vRefNum, fss.parID, fss.name, fndrInfo.fdType); - if (macFlags.gotOpen) - break; /* got our save file */ - } - err = AEDisposeDesc(&docList); - break; - } - } - } + process_openfile(fss.vRefNum, fss.parID, fss.name, + fndrInfo.fdType); + if (macFlags.gotOpen) + break; /* got our save file */ + } + err = AEDisposeDesc(&docList); + break; + } + } + } - /* Check to see if all required parameters for this type of event are present */ - if (err == noErr) { - err = AEGetAttributePtr (inAppleEvent, keyMissedKeywordAttr, - typeWildCard, &typeCode, NULL, 0, &actualSize); - if (err == errAEDescNotFound) - err = noErr; /* got all the required parameters */ - else if (err == noErr) /* missed a required parameter */ - err = errAEEventNotHandled; - } + /* Check to see if all required parameters for this type of event are + * present */ + if (err == noErr) { + err = + AEGetAttributePtr(inAppleEvent, keyMissedKeywordAttr, + typeWildCard, &typeCode, NULL, 0, &actualSize); + if (err == errAEDescNotFound) + err = noErr; /* got all the required parameters */ + else if (err == noErr) /* missed a required parameter */ + err = errAEEventNotHandled; + } - return err; + return err; } - -short win_fonts [NHW_TEXT + 1]; +short win_fonts[NHW_TEXT + 1]; void -InitMac(void) { - short i; - long l; - Str255 volName; - +InitMac(void) +{ + short i; + long l; + Str255 volName; #if !TARGET_API_MAC_CARBON - if (LMGetDefltStack() < 50 * 1024L) { - SetApplLimit ((void *) ((long) LMGetCurStackBase() - (50 * 1024L))); - } - MaxApplZone (); - for (i = 0; i < 5; i ++) - MoreMasters (); + if (LMGetDefltStack() < 50 * 1024L) { + SetApplLimit((void *) ((long) LMGetCurStackBase() - (50 * 1024L))); + } + MaxApplZone(); + for (i = 0; i < 5; i++) + MoreMasters(); - InitGraf (&qd.thePort); - InitFonts (); - InitWindows (); - InitMenus (); - InitDialogs (0L); - TEInit (); + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + InitDialogs(0L); + TEInit(); #endif - memset (&macFlags, 0, sizeof(macFlags)); - if (!Gestalt (gestaltOSAttr, & l)) { - macFlags.processes = (l & (1 << gestaltLaunchControl)) ? 1 : 0; - macFlags.tempMem = (l & (1 << gestaltRealTempMemory)) ? 1 : 0; - macFlags.hasDebugger = (l & (1 << gestaltSysDebuggerSupport)) ? 1 : 0; - } - if (!Gestalt (gestaltQuickdrawVersion, & l)) - macFlags.color = (l >= gestalt8BitQD) ? 1 : 0; + memset(&macFlags, 0, sizeof(macFlags)); + if (!Gestalt(gestaltOSAttr, &l)) { + macFlags.processes = (l & (1 << gestaltLaunchControl)) ? 1 : 0; + macFlags.tempMem = (l & (1 << gestaltRealTempMemory)) ? 1 : 0; + macFlags.hasDebugger = (l & (1 << gestaltSysDebuggerSupport)) ? 1 : 0; + } + if (!Gestalt(gestaltQuickdrawVersion, &l)) + macFlags.color = (l >= gestalt8BitQD) ? 1 : 0; - if (!Gestalt (gestaltFindFolderAttr, & l)) - macFlags.folders = (l & (1 << gestaltFindFolderPresent)) ? 1 : 0; - - if (!Gestalt (gestaltHelpMgrAttr, & l)) - macFlags.help = (l & (1 << gestaltHelpMgrPresent)) ? 1 : 0; + if (!Gestalt(gestaltFindFolderAttr, &l)) + macFlags.folders = (l & (1 << gestaltFindFolderPresent)) ? 1 : 0; - if (!Gestalt (gestaltFSAttr, & l)) - macFlags.fsSpec = (l & (1 << gestaltHasFSSpecCalls)) ? 1 : 0; + if (!Gestalt(gestaltHelpMgrAttr, &l)) + macFlags.help = (l & (1 << gestaltHelpMgrPresent)) ? 1 : 0; - if (!Gestalt (gestaltFontMgrAttr, & l)) - macFlags.trueType = (l & (1 << gestaltOutlineFonts)) ? 1 : 0; + if (!Gestalt(gestaltFSAttr, &l)) + macFlags.fsSpec = (l & (1 << gestaltHasFSSpecCalls)) ? 1 : 0; - if (!Gestalt (gestaltAUXVersion, & l)) - macFlags.aux = (l >= 0x200) ? 1 : 0; + if (!Gestalt(gestaltFontMgrAttr, &l)) + macFlags.trueType = (l & (1 << gestaltOutlineFonts)) ? 1 : 0; - if (!Gestalt (gestaltAliasMgrAttr, & l)) - macFlags.alias = (l & (1 << gestaltAliasMgrPresent)) ? 1 : 0; + if (!Gestalt(gestaltAUXVersion, &l)) + macFlags.aux = (l >= 0x200) ? 1 : 0; - if (!Gestalt (gestaltStandardFileAttr, & l)) - macFlags.standardFile = (l & (1 << gestaltStandardFile58)) ? 1 : 0; + if (!Gestalt(gestaltAliasMgrAttr, &l)) + macFlags.alias = (l & (1 << gestaltAliasMgrPresent)) ? 1 : 0; - gMouseRgn = NewRgn (); - InitCursor(); - GetQDGlobalsArrow(&qdarrow); - ObscureCursor(); + if (!Gestalt(gestaltStandardFileAttr, &l)) + macFlags.standardFile = (l & (1 << gestaltStandardFile58)) ? 1 : 0; - MoveScrollUPP = NewControlActionUPP(MoveScrollBar); + gMouseRgn = NewRgn(); + InitCursor(); + GetQDGlobalsArrow(&qdarrow); + ObscureCursor(); - /* Set up base fonts for all window types */ - GetFNum("\pHackFont", &i); - if (i == 0) - i = kFontIDMonaco; - win_fonts [NHW_BASE] = win_fonts [NHW_MAP] = win_fonts [NHW_STATUS] = i; - GetFNum("\pPSHackFont", &i); - if (i == 0) - i = kFontIDGeneva; - win_fonts[NHW_MESSAGE] = i; - win_fonts[NHW_TEXT] = kFontIDGeneva; + MoveScrollUPP = NewControlActionUPP(MoveScrollBar); - macFlags.hasAE = 0; - if(!Gestalt(gestaltAppleEventsAttr, &l) && (l & (1L << gestaltAppleEventsPresent))){ - if (AEInstallEventHandler (kCoreEventClass, typeWildCard, - NewAEEventHandlerUPP(AppleEventHandler), - 0, - FALSE) == noErr) - macFlags.hasAE = 1; - } + /* Set up base fonts for all window types */ + GetFNum("\pHackFont", &i); + if (i == 0) + i = kFontIDMonaco; + win_fonts[NHW_BASE] = win_fonts[NHW_MAP] = win_fonts[NHW_STATUS] = i; + GetFNum("\pPSHackFont", &i); + if (i == 0) + i = kFontIDGeneva; + win_fonts[NHW_MESSAGE] = i; + win_fonts[NHW_TEXT] = kFontIDGeneva; + + macFlags.hasAE = 0; + if (!Gestalt(gestaltAppleEventsAttr, &l) + && (l & (1L << gestaltAppleEventsPresent))) { + if (AEInstallEventHandler(kCoreEventClass, typeWildCard, + NewAEEventHandlerUPP(AppleEventHandler), 0, + FALSE) == noErr) + macFlags.hasAE = 1; + } #if TARGET_API_MAC_CARBON - HGetVol(volName, &theDirs.dataRefNum, &theDirs.dataDirID); + HGetVol(volName, &theDirs.dataRefNum, &theDirs.dataDirID); #else - /* - * We should try to get this data from a rsrc, in the profile file - * the user double-clicked... This data should be saved with the - * save file in the resource fork, AND be saveable in "stationary" - */ - GetVol (volName, &theDirs.dataRefNum ); - GetWDInfo (theDirs.dataRefNum, &theDirs.dataRefNum, &theDirs.dataDirID, &l); + /* + * We should try to get this data from a rsrc, in the profile file + * the user double-clicked... This data should be saved with the + * save file in the resource fork, AND be saveable in "stationary" + */ + GetVol(volName, &theDirs.dataRefNum); + GetWDInfo(theDirs.dataRefNum, &theDirs.dataRefNum, &theDirs.dataDirID, + &l); #endif - if (volName [0] > 31) volName [0] = 31; - for (l = 1; l <= volName [0]; l++) { - if (volName [l] == ':') { - volName [l] = 0; - volName [0] = l - 1; - break; - } - } - BlockMove (volName, theDirs.dataName, l); - BlockMove (volName, theDirs.saveName, l); - BlockMove (volName, theDirs.levelName, l); - theDirs.saveRefNum = theDirs.levelRefNum = theDirs.dataRefNum; - theDirs.saveDirID = theDirs.levelDirID = theDirs.dataDirID; + if (volName[0] > 31) + volName[0] = 31; + for (l = 1; l <= volName[0]; l++) { + if (volName[l] == ':') { + volName[l] = 0; + volName[0] = l - 1; + break; + } + } + BlockMove(volName, theDirs.dataName, l); + BlockMove(volName, theDirs.saveName, l); + BlockMove(volName, theDirs.levelName, l); + theDirs.saveRefNum = theDirs.levelRefNum = theDirs.dataRefNum; + theDirs.saveDirID = theDirs.levelDirID = theDirs.dataDirID; - /* Create the "record" file, if necessary */ - check_recordfile(""); + /* Create the "record" file, if necessary */ + check_recordfile(""); -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON /* Create event handler universal procedure pointers */ dispatcher = GetEventDispatcherTarget(); baseupp = NewEventHandlerUPP(BaseEvent); @@ -475,88 +476,86 @@ InitMac(void) { InstallApplicationEventHandler(NewEventHandlerUPP(GlobalEvent), sizeof(globalevents)/sizeof(EventTypeSpec), globalevents, NULL, NULL); #endif - return; + return; } - /* * Change default window fonts. */ short -set_tty_font_name (int window_type, char *font_name) { - short fnum; - Str255 new_font; - - if (window_type < NHW_BASE || window_type > NHW_TEXT) - return general_failure; - - C2P (font_name, new_font); - GetFNum (new_font, &(fnum)); - if (!fnum) - return general_failure; - win_fonts [window_type] = fnum; - return noErr; -} +set_tty_font_name(int window_type, char *font_name) +{ + short fnum; + Str255 new_font; + if (window_type < NHW_BASE || window_type > NHW_TEXT) + return general_failure; + + C2P(font_name, new_font); + GetFNum(new_font, &(fnum)); + if (!fnum) + return general_failure; + win_fonts[window_type] = fnum; + return noErr; +} static void -DrawScrollbar (NhWindow *aWin) +DrawScrollbar(NhWindow *aWin) { - WindowPtr theWindow = aWin->its_window; - Rect crect, wrect; - Boolean vis; - short val, lin, win_height; + WindowPtr theWindow = aWin->its_window; + Rect crect, wrect; + Boolean vis; + short val, lin, win_height; + if (!aWin->scrollBar) + return; + GetControlBounds(aWin->scrollBar, &crect); + GetWindowBounds(aWin->its_window, kWindowContentRgn, &wrect); + OffsetRect(&wrect, -wrect.left, -wrect.top); + win_height = wrect.bottom - wrect.top; - if (!aWin->scrollBar) - return; - GetControlBounds(aWin->scrollBar, &crect); - GetWindowBounds(aWin->its_window, kWindowContentRgn, &wrect); - OffsetRect(&wrect, -wrect.left, -wrect.top); - win_height = wrect.bottom - wrect.top; - - if (crect.top != wrect.top - 1 || - crect.left != wrect.right - SBARWIDTH) { - MoveControl (aWin->scrollBar, wrect.right - SBARWIDTH, wrect.top - 1); - } - if (crect.bottom != wrect.bottom - SBARHEIGHT || - crect.right != wrect.right + 1) { - SizeControl (aWin->scrollBar, SBARWIDTH+1, win_height - SBARHEIGHT + 2); - } - vis = (win_height > (50 + SBARHEIGHT)); - if (vis != IsControlVisible(aWin->scrollBar)) { - /* current status != control */ - if (vis)/* if visible, show */ - ShowControl (aWin->scrollBar); - else /* else hide */ - HideControl (aWin->scrollBar); - } - lin = aWin->y_size; - if (aWin == theWindows + WIN_MESSAGE) { - /* calculate how big scroll bar is for message window */ - lin -= (win_height - SBARHEIGHT) / aWin->row_height; - if (lin < 0) - lin = 0; - val = 0; /* always have message scrollbar active */ - } - else { - /* calculate how big scroll bar is for other windows */ - lin -= win_height / aWin->row_height; - if (lin < 0) - lin = 0; - if (lin) val = 0; /* if there are 1+ screen lines, activate scrollbar */ - else val = 255; /* else grey it out */ - } - SetControlMaximum (aWin->scrollBar, lin); - HiliteControl (aWin->scrollBar, val); - val = GetControlValue (aWin->scrollBar); - if (val != aWin->scrollPos) { - InvalWindowRect(theWindow, &wrect); - aWin->scrollPos = val; - } + if (crect.top != wrect.top - 1 || crect.left != wrect.right - SBARWIDTH) { + MoveControl(aWin->scrollBar, wrect.right - SBARWIDTH, wrect.top - 1); + } + if (crect.bottom != wrect.bottom - SBARHEIGHT + || crect.right != wrect.right + 1) { + SizeControl(aWin->scrollBar, SBARWIDTH + 1, + win_height - SBARHEIGHT + 2); + } + vis = (win_height > (50 + SBARHEIGHT)); + if (vis != IsControlVisible(aWin->scrollBar)) { + /* current status != control */ + if (vis) /* if visible, show */ + ShowControl(aWin->scrollBar); + else /* else hide */ + HideControl(aWin->scrollBar); + } + lin = aWin->y_size; + if (aWin == theWindows + WIN_MESSAGE) { + /* calculate how big scroll bar is for message window */ + lin -= (win_height - SBARHEIGHT) / aWin->row_height; + if (lin < 0) + lin = 0; + val = 0; /* always have message scrollbar active */ + } else { + /* calculate how big scroll bar is for other windows */ + lin -= win_height / aWin->row_height; + if (lin < 0) + lin = 0; + if (lin) + val = 0; /* if there are 1+ screen lines, activate scrollbar */ + else + val = 255; /* else grey it out */ + } + SetControlMaximum(aWin->scrollBar, lin); + HiliteControl(aWin->scrollBar, val); + val = GetControlValue(aWin->scrollBar); + if (val != aWin->scrollPos) { + InvalWindowRect(theWindow, &wrect); + aWin->scrollPos = val; + } } - #define MAX_HEIGHT 100 #define MIN_HEIGHT 50 #define MIN_WIDTH 300 @@ -565,249 +564,262 @@ DrawScrollbar (NhWindow *aWin) * This function could be overloaded with any amount of intelligence... */ int -SanePositions (void) +SanePositions(void) { #if TARGET_API_MAC_CARBON - Rect rbase, rmsg; - SInt16 i, width, height; + Rect rbase, rmsg; + SInt16 i, width, height; + ConstrainWindowToScreen(_mt_window, kWindowContentRgn, + kWindowConstrainMoveRegardlessOfFit, NULL, NULL); + GetWindowBounds(_mt_window, kWindowContentRgn, &rbase); + if (RetrievePosition(kMapWindow, &rbase.top, &rbase.left)) + MoveWindow(_mt_window, rbase.left, rbase.top, TRUE); - ConstrainWindowToScreen(_mt_window, kWindowContentRgn, - kWindowConstrainMoveRegardlessOfFit, NULL, NULL); - GetWindowBounds(_mt_window, kWindowContentRgn, &rbase); - if (RetrievePosition(kMapWindow, &rbase.top, &rbase.left)) - MoveWindow(_mt_window, rbase.left, rbase.top, TRUE); + GetWindowBounds(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn, + &rmsg); + height = rmsg.bottom - rmsg.top; + rmsg.top = rbase.bottom + 2; + rmsg.bottom = rmsg.top + height; + rmsg.left = rbase.left; + rmsg.right = rbase.right; + RetrievePosition(kMessageWindow, &rmsg.top, &rmsg.left); + if (RetrieveSize(kMessageWindow, rmsg.top, rmsg.left, &height, &width)) { + rmsg.right = rmsg.left + width; + rmsg.bottom = rmsg.top + height; + } + SetWindowBounds(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn, + &rmsg); + ConstrainWindowToScreen(theWindows[NHW_MESSAGE].its_window, + kWindowContentRgn, + kWindowConstrainMoveRegardlessOfFit, NULL, NULL); + DrawScrollbar(&theWindows[NHW_MESSAGE]); - GetWindowBounds(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn, &rmsg); - height = rmsg.bottom - rmsg.top; - rmsg.top = rbase.bottom+2; - rmsg.bottom = rmsg.top + height; - rmsg.left = rbase.left; - rmsg.right = rbase.right; - RetrievePosition(kMessageWindow, &rmsg.top, &rmsg.left); - if (RetrieveSize(kMessageWindow, rmsg.top, rmsg.left, &height, &width)) { - rmsg.right = rmsg.left + width; - rmsg.bottom = rmsg.top + height; - } - SetWindowBounds(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn, &rmsg); - ConstrainWindowToScreen(theWindows[NHW_MESSAGE].its_window, kWindowContentRgn, - kWindowConstrainMoveRegardlessOfFit, NULL, NULL); - DrawScrollbar(&theWindows[NHW_MESSAGE]); - - for (i = 0; i < NUM_MACWINDOWS; i++) - if (i != WIN_STATUS && i != WIN_MESSAGE && i != WIN_MAP && - i != BASE_WINDOW && theWindows[i].its_window) { - /* FIXME */ - ConstrainWindowToScreen(theWindows[i].its_window, kWindowContentRgn, - kWindowConstrainMoveRegardlessOfFit, NULL, NULL); - } + for (i = 0; i < NUM_MACWINDOWS; i++) + if (i != WIN_STATUS && i != WIN_MESSAGE && i != WIN_MAP + && i != BASE_WINDOW && theWindows[i].its_window) { + /* FIXME */ + ConstrainWindowToScreen( + theWindows[i].its_window, kWindowContentRgn, + kWindowConstrainMoveRegardlessOfFit, NULL, NULL); + } #else - short left, top, width, height; - int ix, numText = 0, numMenu = 0; - int mbar_height = GetMBarHeight(); - BitMap qbitmap; - Rect screenArea; - WindowPtr theWindow; - NhWindow *nhWin; + short left, top, width, height; + int ix, numText = 0, numMenu = 0; + int mbar_height = GetMBarHeight(); + BitMap qbitmap; + Rect screenArea; + WindowPtr theWindow; + NhWindow *nhWin; + screenArea = GetQDGlobalsScreenBits(&qbitmap)->bounds; + OffsetRect(&screenArea, -screenArea.left, -screenArea.top); - screenArea = GetQDGlobalsScreenBits(&qbitmap)->bounds; - OffsetRect (&screenArea, - screenArea.left, - screenArea.top); + /* Map Window */ + height = _mt_window->portRect.bottom - _mt_window->portRect.top; + width = _mt_window->portRect.right - _mt_window->portRect.left; -/* Map Window */ - height = _mt_window->portRect.bottom - _mt_window->portRect.top; - width = _mt_window->portRect.right - _mt_window->portRect.left; + if (!RetrievePosition(kMapWindow, &top, &left)) { + top = mbar_height + (small_screen ? 2 : 20); + left = (screenArea.right - width) / 2; + } + MoveWindow(_mt_window, left, top, 1); - if (!RetrievePosition (kMapWindow, &top, &left)) { - top = mbar_height + (small_screen ? 2 : 20); - left = (screenArea.right - width) / 2; - } - MoveWindow (_mt_window, left, top, 1); + /* Message Window */ + if (!RetrievePosition(kMessageWindow, &top, &left)) { + top += height; + if (!small_screen) + top += 20; + } -/* Message Window */ - if (!RetrievePosition (kMessageWindow, &top, &left)) { - top += height; - if (!small_screen) - top += 20; - } + if (!RetrieveSize(kMessageWindow, top, left, &height, &width)) { + height = + screenArea.bottom - top - (small_screen ? 2 - SBARHEIGHT : 2); + if (height > MAX_HEIGHT) { + height = MAX_HEIGHT; + } else if (height < MIN_HEIGHT) { + height = MIN_HEIGHT; + width = MIN_WIDTH; + left = screenArea.right - width; + top = screenArea.bottom - MIN_HEIGHT; + } + } - if (!RetrieveSize (kMessageWindow, top, left, &height, &width)) { - height = screenArea.bottom - top - (small_screen ? 2-SBARHEIGHT : 2); - if (height > MAX_HEIGHT) { - height = MAX_HEIGHT; - } else if (height < MIN_HEIGHT) { - height = MIN_HEIGHT; - width = MIN_WIDTH; - left = screenArea.right - width; - top = screenArea.bottom - MIN_HEIGHT; - } - } + /* Move these windows */ + nhWin = theWindows + WIN_MESSAGE; + theWindow = nhWin->its_window; -/* Move these windows */ - nhWin = theWindows + WIN_MESSAGE; - theWindow = nhWin->its_window; + MoveWindow(theWindow, left, top, 1); + SizeWindow(theWindow, width, height, 1); + if (nhWin->scrollBar) + DrawScrollbar(nhWin); - MoveWindow (theWindow, left, top, 1); - SizeWindow (theWindow, width, height, 1); - if (nhWin->scrollBar) - DrawScrollbar (nhWin); - - /* Handle other windows */ - for (ix = 0; ix < NUM_MACWINDOWS; ix ++) { - if (ix != WIN_STATUS && ix != WIN_MESSAGE && ix != WIN_MAP && ix != BASE_WINDOW) { - theWindow = theWindows [ix].its_window; - if (theWindow && ((WindowPeek) theWindow)->visible) { - int shift; - if (((WindowPeek)theWindow)->windowKind == WIN_BASE_KIND + NHW_MENU) { - if (!RetrievePosition (kMenuWindow, &top, &left)) { - top = mbar_height * 2; - left = 2; - } - top += (numMenu * mbar_height); - numMenu++; - shift = 20; - } else { - if (!RetrievePosition (kTextWindow, &top, &left)) { - top = mbar_height * 2; - left = screenArea.right - 3 - - (theWindow->portRect.right - theWindow->portRect.left); - } - top += (numText * mbar_height); - numText++; - shift = -20; - } - while (top > screenArea.bottom - MIN_HEIGHT) { - top -= screenArea.bottom - mbar_height * 2; - left += shift; - } - MoveWindow (theWindow, left, top, 1); - } - } - } + /* Handle other windows */ + for (ix = 0; ix < NUM_MACWINDOWS; ix++) { + if (ix != WIN_STATUS && ix != WIN_MESSAGE && ix != WIN_MAP + && ix != BASE_WINDOW) { + theWindow = theWindows[ix].its_window; + if (theWindow && ((WindowPeek) theWindow)->visible) { + int shift; + if (((WindowPeek) theWindow)->windowKind + == WIN_BASE_KIND + NHW_MENU) { + if (!RetrievePosition(kMenuWindow, &top, &left)) { + top = mbar_height * 2; + left = 2; + } + top += (numMenu * mbar_height); + numMenu++; + shift = 20; + } else { + if (!RetrievePosition(kTextWindow, &top, &left)) { + top = mbar_height * 2; + left = screenArea.right - 3 + - (theWindow->portRect.right + - theWindow->portRect.left); + } + top += (numText * mbar_height); + numText++; + shift = -20; + } + while (top > screenArea.bottom - MIN_HEIGHT) { + top -= screenArea.bottom - mbar_height * 2; + left += shift; + } + MoveWindow(theWindow, left, top, 1); + } + } + } #endif - return (0); + return (0); } - void -mac_init_nhwindows (int *argcp, char **argv) +mac_init_nhwindows(int *argcp, char **argv) { - Rect r; + Rect r; #if !TARGET_API_MAC_CARBON - Rect scr = (*GetGrayRgn())->rgnBBox; - small_screen = scr.bottom - scr.top <= (iflags.large_font ? 12*40 : 9*40); + Rect scr = (*GetGrayRgn())->rgnBBox; + small_screen = + scr.bottom - scr.top <= (iflags.large_font ? 12 * 40 : 9 * 40); #endif + InitMenuRes(); - InitMenuRes(); + theWindows = (NhWindow *) NewPtrClear(NUM_MACWINDOWS * sizeof(NhWindow)); + if (MemError()) + error("mac_init_nhwindows: Couldn't allocate memory for windows."); - theWindows = (NhWindow *) NewPtrClear (NUM_MACWINDOWS * sizeof (NhWindow)); - if (MemError()) - error("mac_init_nhwindows: Couldn't allocate memory for windows."); + DimMenuBar(); - DimMenuBar(); + tty_init_nhwindows(argcp, argv); + iflags.window_inited = TRUE; - tty_init_nhwindows(argcp, argv); - iflags.window_inited = TRUE; + /* Some ugly hacks to make both interfaces happy: + * Mac port uses both tty interface (for main map) and extra windows. The + * winids need to + * be kept in synch for both interfaces to map. Also, the "blocked" + * display_nhwindow case + * for the map automatically calls the tty interface for the message box, + * so some version + * of the message box has to exist in the tty world to prevent a meltdown, + * even though most + * messages are handled in mac window. + */ + mac_create_nhwindow(NHW_BASE); + tty_create_nhwindow(NHW_MESSAGE); - /* Some ugly hacks to make both interfaces happy: - * Mac port uses both tty interface (for main map) and extra windows. The winids need to - * be kept in synch for both interfaces to map. Also, the "blocked" display_nhwindow case - * for the map automatically calls the tty interface for the message box, so some version - * of the message box has to exist in the tty world to prevent a meltdown, even though most - * messages are handled in mac window. - */ - mac_create_nhwindow(NHW_BASE); - tty_create_nhwindow(NHW_MESSAGE); - -#if 1//!TARGET_API_MAC_CARBON - /* Resize and reposition the message window */ - RetrievePosition(kMessageWindow, &r.top, &r.left); - RetrieveSize(kMessageWindow, r.top, r.left, &r.bottom, &r.right); - MoveWindow(theWindows[NHW_MESSAGE].its_window, r.left, r.top, false); - SizeWindow(theWindows[NHW_MESSAGE].its_window, r.right, r.bottom, true); +#if 1 //!TARGET_API_MAC_CARBON + /* Resize and reposition the message window */ + RetrievePosition(kMessageWindow, &r.top, &r.left); + RetrieveSize(kMessageWindow, r.top, r.left, &r.bottom, &r.right); + MoveWindow(theWindows[NHW_MESSAGE].its_window, r.left, r.top, false); + SizeWindow(theWindows[NHW_MESSAGE].its_window, r.right, r.bottom, true); #endif - return; + return; } - winid -mac_create_nhwindow (int kind) { - int i; - NhWindow *aWin; - FontInfo fi; +mac_create_nhwindow(int kind) +{ + int i; + NhWindow *aWin; + FontInfo fi; - if (kind < NHW_BASE || kind > NHW_TEXT) { - error ("cre_win: Invalid kind %d.", kind); - return WIN_ERR; - } + if (kind < NHW_BASE || kind > NHW_TEXT) { + error("cre_win: Invalid kind %d.", kind); + return WIN_ERR; + } - for (i = 0; i < NUM_MACWINDOWS; i ++) { - if (!theWindows [i].its_window) - break; - } - if (i >= NUM_MACWINDOWS) { - error ("cre_win: Win full; freeing extras"); - for (i = 0; i < NUM_MACWINDOWS; i ++) { - if (IsWindowVisible(theWindows [i].its_window) || i == WIN_INVEN || - GetWindowKind(theWindows [i].its_window) != WIN_BASE_KIND + NHW_MENU && - GetWindowKind(theWindows [i].its_window) != WIN_BASE_KIND + NHW_TEXT) - continue; - mac_destroy_nhwindow(i); - goto got1; - } - error ("cre_win: Out of ids!"); - return WIN_ERR; - } + for (i = 0; i < NUM_MACWINDOWS; i++) { + if (!theWindows[i].its_window) + break; + } + if (i >= NUM_MACWINDOWS) { + error("cre_win: Win full; freeing extras"); + for (i = 0; i < NUM_MACWINDOWS; i++) { + if (IsWindowVisible(theWindows[i].its_window) || i == WIN_INVEN + || GetWindowKind(theWindows[i].its_window) + != WIN_BASE_KIND + NHW_MENU + && GetWindowKind(theWindows[i].its_window) + != WIN_BASE_KIND + NHW_TEXT) + continue; + mac_destroy_nhwindow(i); + goto got1; + } + error("cre_win: Out of ids!"); + return WIN_ERR; + } -got1 : - aWin = &theWindows [i]; - aWin->windowTextLen = 0L; - aWin->scrollBar = (ControlHandle) 0; - aWin->menuInfo = 0; - aWin->menuSelected = 0; - aWin->miLen = 0; - aWin->miSize = 0; - aWin->menuChar = 'a'; - - dprintf ("cre_win: New kind %d", kind); +got1: + aWin = &theWindows[i]; + aWin->windowTextLen = 0L; + aWin->scrollBar = (ControlHandle) 0; + aWin->menuInfo = 0; + aWin->menuSelected = 0; + aWin->miLen = 0; + aWin->miSize = 0; + aWin->menuChar = 'a'; - if (kind == NHW_BASE || kind == NHW_MAP || kind == NHW_STATUS) { - short x_sz, x_sz_p, y_sz, y_sz_p; - if (kind != NHW_BASE) { - if (i != tty_create_nhwindow(kind)) { - dprintf ("cre_win: error creating kind %d", kind); - } - if (kind == NHW_MAP) { - wins[i]->offy = 0; /* the message box is in a separate window */ - } - } - aWin->its_window = _mt_window; - get_tty_metrics(aWin->its_window, &x_sz, &y_sz, &x_sz_p, &y_sz_p, - &aWin->font_number, &aWin->font_size, - &aWin->char_width, &aWin->row_height); -#if 0//TARGET_API_MAC_CARBON + dprintf("cre_win: New kind %d", kind); + + if (kind == NHW_BASE || kind == NHW_MAP || kind == NHW_STATUS) { + short x_sz, x_sz_p, y_sz, y_sz_p; + if (kind != NHW_BASE) { + if (i != tty_create_nhwindow(kind)) { + dprintf("cre_win: error creating kind %d", kind); + } + if (kind == NHW_MAP) { + wins[i]->offy = + 0; /* the message box is in a separate window */ + } + } + aWin->its_window = _mt_window; + get_tty_metrics(aWin->its_window, &x_sz, &y_sz, &x_sz_p, &y_sz_p, + &aWin->font_number, &aWin->font_size, + &aWin->char_width, &aWin->row_height); +#if 0 // TARGET_API_MAC_CARBON InstallWindowEventHandler(aWin->its_window, baseupp, sizeof(baseevents)/sizeof(EventTypeSpec), baseevents, (void *)aWin, NULL); #endif - return i; - } + return i; + } - aWin->its_window = GetNewWindow (WIN_BASE_RES + kind, (WindowPtr) 0L, (WindowPtr) -1L); - SetWindowKind(aWin->its_window, WIN_BASE_KIND + kind); - SetWRefCon(aWin->its_window, (long) aWin); - if (!(aWin->windowText = NewHandle (TEXT_BLOCK))) { - error ("cre_win: NewHandle fail(%ld)", (long) TEXT_BLOCK); - DisposeWindow (aWin->its_window); - aWin->its_window = (WindowPtr) 0; - return WIN_ERR; - } - aWin->x_size = aWin->y_size = 0; - aWin->x_curs = aWin->y_curs = 0; - aWin->drawn = TRUE; - mac_clear_nhwindow (i); -#if 0//TARGET_API_MAC_CARBON + aWin->its_window = + GetNewWindow(WIN_BASE_RES + kind, (WindowPtr) 0L, (WindowPtr) -1L); + SetWindowKind(aWin->its_window, WIN_BASE_KIND + kind); + SetWRefCon(aWin->its_window, (long) aWin); + if (!(aWin->windowText = NewHandle(TEXT_BLOCK))) { + error("cre_win: NewHandle fail(%ld)", (long) TEXT_BLOCK); + DisposeWindow(aWin->its_window); + aWin->its_window = (WindowPtr) 0; + return WIN_ERR; + } + aWin->x_size = aWin->y_size = 0; + aWin->x_curs = aWin->y_curs = 0; + aWin->drawn = TRUE; + mac_clear_nhwindow(i); +#if 0 // TARGET_API_MAC_CARBON switch (kind) { case NHW_MESSAGE: InstallWindowEventHandler(aWin->its_window, msgupp, @@ -827,558 +839,578 @@ got1 : } #endif - SetPortWindowPort(aWin->its_window); + SetPortWindowPort(aWin->its_window); - if (kind == NHW_MESSAGE) { - aWin->font_number = win_fonts [NHW_MESSAGE]; - aWin->font_size = iflags.wc_fontsiz_message? iflags.wc_fontsiz_message : - iflags.large_font ? 12 : 9; - if (!top_line) { - const Rect out_of_scr = {10000, 10000, 10100, 10100}; - TextFont(aWin->font_number); - TextSize(aWin->font_size); - TextFace(bold); - top_line = TENew(&out_of_scr, &out_of_scr); - TEActivate(top_line); - TextFace(normal); - } - } else { - aWin->font_number = win_fonts [NHW_TEXT]; - aWin->font_size = iflags.wc_fontsiz_text ? iflags.wc_fontsiz_text : 9; - } + if (kind == NHW_MESSAGE) { + aWin->font_number = win_fonts[NHW_MESSAGE]; + aWin->font_size = iflags.wc_fontsiz_message + ? iflags.wc_fontsiz_message + : iflags.large_font ? 12 : 9; + if (!top_line) { + const Rect out_of_scr = { 10000, 10000, 10100, 10100 }; + TextFont(aWin->font_number); + TextSize(aWin->font_size); + TextFace(bold); + top_line = TENew(&out_of_scr, &out_of_scr); + TEActivate(top_line); + TextFace(normal); + } + } else { + aWin->font_number = win_fonts[NHW_TEXT]; + aWin->font_size = iflags.wc_fontsiz_text ? iflags.wc_fontsiz_text : 9; + } - TextFont (aWin->font_number); - TextSize (aWin->font_size); + TextFont(aWin->font_number); + TextSize(aWin->font_size); - GetFontInfo (&fi); - aWin->ascent_height = fi.ascent + fi.leading; - aWin->row_height = aWin->ascent_height + fi.descent; - aWin->char_width = fi.widMax; + GetFontInfo(&fi); + aWin->ascent_height = fi.ascent + fi.leading; + aWin->row_height = aWin->ascent_height + fi.descent; + aWin->char_width = fi.widMax; - if (kind == NHW_MENU || kind == NHW_TEXT || kind == NHW_MESSAGE) { - Rect r; + if (kind == NHW_MENU || kind == NHW_TEXT || kind == NHW_MESSAGE) { + Rect r; - GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); - r.right -= (r.left - 1); - r.left = r.right - SBARWIDTH; - r.bottom -= (r.top + SBARHEIGHT); - r.top = -1; - aWin->scrollBar = NewControl(aWin->its_window, &r, "\p", (r.bottom > r.top + 50), - 0, 0, 0, 16, 0L); - aWin->scrollPos = 0; - } - return i; + GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); + r.right -= (r.left - 1); + r.left = r.right - SBARWIDTH; + r.bottom -= (r.top + SBARHEIGHT); + r.top = -1; + aWin->scrollBar = + NewControl(aWin->its_window, &r, "\p", (r.bottom > r.top + 50), 0, + 0, 0, 16, 0L); + aWin->scrollPos = 0; + } + return i; } - void -mac_clear_nhwindow (winid win) { - long l; - Rect r; - NhWindow *aWin = &theWindows [win]; - WindowPtr theWindow = aWin->its_window; +mac_clear_nhwindow(winid win) +{ + long l; + Rect r; + NhWindow *aWin = &theWindows[win]; + WindowPtr theWindow = aWin->its_window; - if (win < 0 || win >= NUM_MACWINDOWS || !theWindow) { - error ("clr_win: Invalid win %d.", win); - return; - } - if (theWindow == _mt_window) { - tty_clear_nhwindow(win); - return; - } - if (!aWin->drawn) - return; + if (win < 0 || win >= NUM_MACWINDOWS || !theWindow) { + error("clr_win: Invalid win %d.", win); + return; + } + if (theWindow == _mt_window) { + tty_clear_nhwindow(win); + return; + } + if (!aWin->drawn) + return; - SetPortWindowPort(theWindow); - GetWindowBounds(theWindow, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - if (aWin->scrollBar) - r.right -= SBARWIDTH; + SetPortWindowPort(theWindow); + GetWindowBounds(theWindow, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + if (aWin->scrollBar) + r.right -= SBARWIDTH; - switch (GetWindowKind(theWindow) - WIN_BASE_KIND) { - case NHW_MESSAGE : - if (aWin->scrollPos == aWin->y_size - 1) /* if no change since last clear */ - return; /* don't bother with redraw */ - r.bottom -= SBARHEIGHT; - for (l = 0; aWin->y_size > iflags.msg_history;) { - const char cr = CHAR_CR; - l = Munger(aWin->windowText, l, &cr, 1, nil, 0) + 1; - --aWin->y_size; - } - if (l) { - aWin->windowTextLen -= l; - BlockMove(*aWin->windowText + l, *aWin->windowText, aWin->windowTextLen); - } - aWin->last_more_lin = aWin->y_size; - aWin->save_lin = aWin->y_size; - aWin->scrollPos = aWin->y_size ? aWin->y_size - 1 : 0; - break; - case NHW_MENU: - if (aWin->menuInfo) { - DisposeHandle((Handle)aWin->menuInfo); - aWin->menuInfo = NULL; - } - if (aWin->menuSelected) { - DisposeHandle((Handle)aWin->menuSelected); - aWin->menuSelected = NULL; - } - aWin->menuChar = 'a'; - aWin->miSelLen = 0; - aWin->miLen = 0; - aWin->miSize = 0; - /* Fall-Through */ - default : - SetHandleSize (aWin->windowText, TEXT_BLOCK); - aWin->windowTextLen = 0L; - aWin->x_size = 0; - aWin->y_size = 0; - aWin->scrollPos = 0; - break; - } - if (aWin->scrollBar) { - SetControlMaximum (aWin->scrollBar, aWin->y_size); - SetControlValue(aWin->scrollBar, aWin->scrollPos); - } - aWin->y_curs = 0; - aWin->x_curs = 0; - aWin->drawn = FALSE; - InvalWindowRect(theWindow, &r); + switch (GetWindowKind(theWindow) - WIN_BASE_KIND) { + case NHW_MESSAGE: + if (aWin->scrollPos + == aWin->y_size - 1) /* if no change since last clear */ + return; /* don't bother with redraw */ + r.bottom -= SBARHEIGHT; + for (l = 0; aWin->y_size > iflags.msg_history;) { + const char cr = CHAR_CR; + l = Munger(aWin->windowText, l, &cr, 1, nil, 0) + 1; + --aWin->y_size; + } + if (l) { + aWin->windowTextLen -= l; + BlockMove(*aWin->windowText + l, *aWin->windowText, + aWin->windowTextLen); + } + aWin->last_more_lin = aWin->y_size; + aWin->save_lin = aWin->y_size; + aWin->scrollPos = aWin->y_size ? aWin->y_size - 1 : 0; + break; + case NHW_MENU: + if (aWin->menuInfo) { + DisposeHandle((Handle) aWin->menuInfo); + aWin->menuInfo = NULL; + } + if (aWin->menuSelected) { + DisposeHandle((Handle) aWin->menuSelected); + aWin->menuSelected = NULL; + } + aWin->menuChar = 'a'; + aWin->miSelLen = 0; + aWin->miLen = 0; + aWin->miSize = 0; + /* Fall-Through */ + default: + SetHandleSize(aWin->windowText, TEXT_BLOCK); + aWin->windowTextLen = 0L; + aWin->x_size = 0; + aWin->y_size = 0; + aWin->scrollPos = 0; + break; + } + if (aWin->scrollBar) { + SetControlMaximum(aWin->scrollBar, aWin->y_size); + SetControlValue(aWin->scrollBar, aWin->scrollPos); + } + aWin->y_curs = 0; + aWin->x_curs = 0; + aWin->drawn = FALSE; + InvalWindowRect(theWindow, &r); } - static Boolean -ClosingWindowChar(const int c) { - return (c == CHAR_ESC || c == CHAR_BLANK || c == CHAR_LF || c == CHAR_CR); +ClosingWindowChar(const int c) +{ + return (c == CHAR_ESC || c == CHAR_BLANK || c == CHAR_LF || c == CHAR_CR); } - static Boolean in_topl_mode(void) { - Rect rect; + Rect rect; - - GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, &rect); - OffsetRect(&rect, -rect.left, -rect.top); - return (WIN_MESSAGE != WIN_ERR && top_line && - (*top_line)->viewRect.left < rect.right); + GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, + &rect); + OffsetRect(&rect, -rect.left, -rect.top); + return (WIN_MESSAGE != WIN_ERR && top_line + && (*top_line)->viewRect.left < rect.right); } - #define BTN_IND 2 -#define BTN_W 40 -#define BTN_H (SBARHEIGHT-3) +#define BTN_W 40 +#define BTN_H (SBARHEIGHT - 3) static void topl_resp_rect(int resp_idx, Rect *r) { - Rect rect; + Rect rect; - - GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, &rect); - OffsetRect(&rect, -rect.left, -rect.top); - r->left = (BTN_IND + BTN_W) * resp_idx + BTN_IND; - r->right = r->left + BTN_W; - r->bottom = rect.bottom - 1; - r->top = r->bottom - BTN_H; - return; + GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, + &rect); + OffsetRect(&rect, -rect.left, -rect.top); + r->left = (BTN_IND + BTN_W) * resp_idx + BTN_IND; + r->right = r->left + BTN_W; + r->bottom = rect.bottom - 1; + r->top = r->bottom - BTN_H; + return; } - void -enter_topl_mode(char *query) { - if (in_topl_mode()) - return; +enter_topl_mode(char *query) +{ + if (in_topl_mode()) + return; - putstr(WIN_MESSAGE, ATR_BOLD, query); + putstr(WIN_MESSAGE, ATR_BOLD, query); - topl_query_len = strlen(query); - (*top_line)->selStart = topl_query_len; - (*top_line)->selEnd = topl_query_len; - (*top_line)->viewRect.left = 0; - PtrToXHand(query, (*top_line)->hText, topl_query_len); - TECalText(top_line); + topl_query_len = strlen(query); + (*top_line)->selStart = topl_query_len; + (*top_line)->selEnd = topl_query_len; + (*top_line)->viewRect.left = 0; + PtrToXHand(query, (*top_line)->hText, topl_query_len); + TECalText(top_line); - DimMenuBar(); - mac_display_nhwindow(WIN_MESSAGE, FALSE); + DimMenuBar(); + mac_display_nhwindow(WIN_MESSAGE, FALSE); } - void -leave_topl_mode(char *answer) { - /*unsigned*/ char *ap, *bp; +leave_topl_mode(char *answer) +{ + /*unsigned*/ char *ap, *bp; - int ans_len = (*top_line)->teLength - topl_query_len; - NhWindow *aWin = theWindows + WIN_MESSAGE; + int ans_len = (*top_line)->teLength - topl_query_len; + NhWindow *aWin = theWindows + WIN_MESSAGE; - if (!in_topl_mode()) - return; + if (!in_topl_mode()) + return; - /* Cap length of reply */ - if (ans_len >= BUFSZ) - ans_len = BUFSZ-1; + /* Cap length of reply */ + if (ans_len >= BUFSZ) + ans_len = BUFSZ - 1; - /* remove unprintables from the answer */ - for (ap = *(*top_line)->hText + topl_query_len, bp = answer; ans_len > 0; ans_len--, ap++) { - if (*ap >= ' ' && *ap < 128) { - *bp++ = *ap; - } - } - *bp = 0; - - if (aWin->windowTextLen && (*aWin->windowText)[aWin->windowTextLen-1] == CHAR_CR) { - -- aWin->windowTextLen; - -- aWin->y_size; - } - putstr(WIN_MESSAGE, ATR_BOLD, answer); + /* remove unprintables from the answer */ + for (ap = *(*top_line)->hText + topl_query_len, bp = answer; ans_len > 0; + ans_len--, ap++) { + if (*ap >= ' ' && *ap < 128) { + *bp++ = *ap; + } + } + *bp = 0; - (*top_line)->viewRect.left += 10000; - UndimMenuBar(); + if (aWin->windowTextLen + && (*aWin->windowText)[aWin->windowTextLen - 1] == CHAR_CR) { + --aWin->windowTextLen; + --aWin->y_size; + } + putstr(WIN_MESSAGE, ATR_BOLD, answer); + + (*top_line)->viewRect.left += 10000; + UndimMenuBar(); } /* * TESetSelect flushes out all the pending key strokes. I hate it. */ static void -topl_set_select(short selStart, short selEnd) { - TEDeactivate(top_line); - (*top_line)->selStart = selStart; - (*top_line)->selEnd = selEnd; - TEActivate(top_line); +topl_set_select(short selStart, short selEnd) +{ + TEDeactivate(top_line); + (*top_line)->selStart = selStart; + (*top_line)->selEnd = selEnd; + TEActivate(top_line); } - static void -topl_replace(char *new_ans) { - topl_set_select(topl_query_len, (*top_line)->teLength); - TEDelete(top_line); - TEInsert(new_ans, strlen(new_ans), top_line); +topl_replace(char *new_ans) +{ + topl_set_select(topl_query_len, (*top_line)->teLength); + TEDelete(top_line); + TEInsert(new_ans, strlen(new_ans), top_line); } - Boolean -topl_key(unsigned char ch, Boolean ext) { - switch (ch) { - case CHAR_ESC: - topl_replace("\x1b"); - case CHAR_ENTER: case CHAR_CR: case CHAR_LF: - return false; +topl_key(unsigned char ch, Boolean ext) +{ + switch (ch) { + case CHAR_ESC: + topl_replace("\x1b"); + case CHAR_ENTER: + case CHAR_CR: + case CHAR_LF: + return false; - case 0x1f & 'P': - mac_doprev_message(); - return true; - case '\x1e'/* up arrow */: - topl_replace (""); - return true; - case CHAR_BS: case '\x1c'/* left arrow */: - if ((*top_line)->selEnd <= topl_query_len) - return true; - else if (ext) { - topl_replace (""); - return true; - } - default: - TEKey(ch, top_line); - if (ext) { - int com_index = -1, oindex = 0; - while(extcmdlist[oindex].ef_txt != (char *)0) { - if(!strncmpi(*(*top_line)->hText + topl_query_len, - extcmdlist[oindex].ef_txt, - (*top_line)->teLength - topl_query_len)) { - if(com_index == -1) /* No matches yet*/ - com_index = oindex; - else /* More than 1 match */ { - com_index = -2; - break; - } - } - oindex++; - } - if(com_index >= 0) - topl_replace((char *) extcmdlist[com_index].ef_txt); - } - return true; - } + case 0x1f & 'P': + mac_doprev_message(); + return true; + case '\x1e' /* up arrow */: + topl_replace(""); + return true; + case CHAR_BS: + case '\x1c' /* left arrow */: + if ((*top_line)->selEnd <= topl_query_len) + return true; + else if (ext) { + topl_replace(""); + return true; + } + default: + TEKey(ch, top_line); + if (ext) { + int com_index = -1, oindex = 0; + while (extcmdlist[oindex].ef_txt != (char *) 0) { + if (!strncmpi(*(*top_line)->hText + topl_query_len, + extcmdlist[oindex].ef_txt, + (*top_line)->teLength - topl_query_len)) { + if (com_index == -1) /* No matches yet*/ + com_index = oindex; + else /* More than 1 match */ { + com_index = -2; + break; + } + } + oindex++; + } + if (com_index >= 0) + topl_replace((char *) extcmdlist[com_index].ef_txt); + } + return true; + } } - static void -topl_flash_resp(int resp_idx) { - unsigned long dont_care; - Rect frame; - SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); - topl_resp_rect(resp_idx, &frame); - InsetRect(&frame, 1, 1); - InvertRect(&frame); - Delay(GetDblTime() / 2, &dont_care); - InvertRect(&frame); +topl_flash_resp(int resp_idx) +{ + unsigned long dont_care; + Rect frame; + SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); + topl_resp_rect(resp_idx, &frame); + InsetRect(&frame, 1, 1); + InvertRect(&frame); + Delay(GetDblTime() / 2, &dont_care); + InvertRect(&frame); } - static void -topl_set_def(int new_def_idx) { - Rect frame; - SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); - topl_resp_rect(topl_def_idx, &frame); - InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); - topl_def_idx = new_def_idx; - topl_resp_rect(new_def_idx, &frame); - InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); +topl_set_def(int new_def_idx) +{ + Rect frame; + SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); + topl_resp_rect(topl_def_idx, &frame); + InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); + topl_def_idx = new_def_idx; + topl_resp_rect(new_def_idx, &frame); + InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); } - void -topl_set_resp(char *resp, char def) { - char *loc; - Rect frame; - int r_len, r_len1; +topl_set_resp(char *resp, char def) +{ + char *loc; + Rect frame; + int r_len, r_len1; - if (!resp) { - const char any_str[2] = {CHAR_ANY, '\0'}; - resp = (char *) any_str; - def = CHAR_ANY; - } + if (!resp) { + const char any_str[2] = { CHAR_ANY, '\0' }; + resp = (char *) any_str; + def = CHAR_ANY; + } - SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); - r_len1 = strlen(resp); - r_len = strlen(topl_resp); - if (r_len < r_len1) - r_len = r_len1; - topl_resp_rect(0, &frame); - frame.right = (BTN_IND + BTN_W) * r_len; - InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); + SetPortWindowPort(theWindows[WIN_MESSAGE].its_window); + r_len1 = strlen(resp); + r_len = strlen(topl_resp); + if (r_len < r_len1) + r_len = r_len1; + topl_resp_rect(0, &frame); + frame.right = (BTN_IND + BTN_W) * r_len; + InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame); - strcpy(topl_resp, resp); - loc = strchr (resp, def); - topl_def_idx = loc ? loc - resp : -1; + strcpy(topl_resp, resp); + loc = strchr(resp, def); + topl_def_idx = loc ? loc - resp : -1; } - static char -topl_resp_key(char ch) { - if (strlen(topl_resp) > 0) { - char *loc = strchr(topl_resp, ch); +topl_resp_key(char ch) +{ + if (strlen(topl_resp) > 0) { + char *loc = strchr(topl_resp, ch); - if (!loc) { - if (ch == '\x9'/* tab */) { - topl_set_def(topl_def_idx<=0 ? strlen(topl_resp)-1 : topl_def_idx-1); - ch = '\0'; - } else if (ch == CHAR_ESC) { - loc = strchr(topl_resp, 'q'); - if (!loc) { - loc = strchr(topl_resp, 'n'); - if (!loc && topl_def_idx >= 0) - loc = topl_resp + topl_def_idx; - } - } else if (ch == (0x1f & 'P')) { - mac_doprev_message(); - ch = '\0'; - } else if (topl_def_idx >= 0) { - if (ch == CHAR_ENTER || ch == CHAR_CR || ch == CHAR_LF || - ch == CHAR_BLANK || topl_resp[topl_def_idx] == CHAR_ANY) - loc = topl_resp + topl_def_idx; + if (!loc) { + if (ch == '\x9' /* tab */) { + topl_set_def(topl_def_idx <= 0 ? strlen(topl_resp) - 1 + : topl_def_idx - 1); + ch = '\0'; + } else if (ch == CHAR_ESC) { + loc = strchr(topl_resp, 'q'); + if (!loc) { + loc = strchr(topl_resp, 'n'); + if (!loc && topl_def_idx >= 0) + loc = topl_resp + topl_def_idx; + } + } else if (ch == (0x1f & 'P')) { + mac_doprev_message(); + ch = '\0'; + } else if (topl_def_idx >= 0) { + if (ch == CHAR_ENTER || ch == CHAR_CR || ch == CHAR_LF + || ch == CHAR_BLANK + || topl_resp[topl_def_idx] == CHAR_ANY) + loc = topl_resp + topl_def_idx; - else if (strchr(topl_resp, '#')) { - if (digit(ch)) { - topl_set_def(strchr(topl_resp, '#') - topl_resp); - TEKey(ch, top_line); - ch = '\0'; + else if (strchr(topl_resp, '#')) { + if (digit(ch)) { + topl_set_def(strchr(topl_resp, '#') - topl_resp); + TEKey(ch, top_line); + ch = '\0'; - } else if (topl_resp[topl_def_idx] == '#') { - if (ch == '\x1e'/* up arrow */) { - topl_set_select(topl_query_len, topl_query_len); - ch = '\0'; - } else if (ch == '\x1d'/* right arrow */ || - ch == '\x1f'/* down arrow */ || - ch == CHAR_BS || ch == '\x1c'/* left arrow */ && - (*top_line)->selEnd > topl_query_len) { - TEKey(ch, top_line); - ch = '\0'; - } - } - } - } - } + } else if (topl_resp[topl_def_idx] == '#') { + if (ch == '\x1e' /* up arrow */) { + topl_set_select(topl_query_len, topl_query_len); + ch = '\0'; + } else if (ch == '\x1d' /* right arrow */ + || ch == '\x1f' /* down arrow */ + || ch == CHAR_BS + || ch == '\x1c' /* left arrow */ + && (*top_line)->selEnd + > topl_query_len) { + TEKey(ch, top_line); + ch = '\0'; + } + } + } + } + } - if (loc) { - topl_flash_resp(loc - topl_resp); - if (*loc != CHAR_ANY) - ch = *loc; - TEKey(ch, top_line); - } - } + if (loc) { + topl_flash_resp(loc - topl_resp); + if (*loc != CHAR_ANY) + ch = *loc; + TEKey(ch, top_line); + } + } - return ch; + return ch; } - static void adjust_window_pos(NhWindow *aWin, short width, short height) { - WindowRef theWindow = aWin->its_window; + WindowRef theWindow = aWin->its_window; #if TARGET_API_MAC_CARBON - Rect r; + Rect r; - - GetWindowBounds(theWindow, kWindowContentRgn, &r); - RetrieveWinPos(theWindow, &r.top, &r.left); - MoveWindow(theWindow, r.left, r.top, false); - SizeWindow(theWindow, width, height, true); - ConstrainWindowToScreen(theWindow, kWindowStructureRgn, - kWindowConstrainMayResize|kWindowConstrainMoveRegardlessOfFit, NULL, NULL); + GetWindowBounds(theWindow, kWindowContentRgn, &r); + RetrieveWinPos(theWindow, &r.top, &r.left); + MoveWindow(theWindow, r.left, r.top, false); + SizeWindow(theWindow, width, height, true); + ConstrainWindowToScreen(theWindow, kWindowStructureRgn, + kWindowConstrainMayResize + | kWindowConstrainMoveRegardlessOfFit, + NULL, NULL); #else - Rect scr_r = (*GetGrayRgn())->rgnBBox; - const Rect win_ind = {2, 2, 3, 3}; - const short min_w = theWindow->portRect.right - theWindow->portRect.left, - max_w = scr_r.right - scr_r.left - win_ind.left - win_ind.right; - Point pos; - short max_h; + Rect scr_r = (*GetGrayRgn())->rgnBBox; + const Rect win_ind = { 2, 2, 3, 3 }; + const short min_w = theWindow->portRect.right - theWindow->portRect.left, + max_w = + scr_r.right - scr_r.left - win_ind.left - win_ind.right; + Point pos; + short max_h; - SetPortWindowPort(theWindow); - if (!RetrieveWinPos(theWindow, &pos.v, &pos.h)) { - pos.v = 0; /* take window's existing position */ - pos.h = 0; - LocalToGlobal(&pos); - } + SetPortWindowPort(theWindow); + if (!RetrieveWinPos(theWindow, &pos.v, &pos.h)) { + pos.v = 0; /* take window's existing position */ + pos.h = 0; + LocalToGlobal(&pos); + } - max_h = scr_r.bottom - win_ind.bottom - pos.v; - if (height > max_h) height = max_h; - if (height < MIN_HEIGHT) height = MIN_HEIGHT; - if (width < min_w) width = min_w; - if (width > max_w) width = max_w; - SizeWindow(theWindow, width, height, true); + max_h = scr_r.bottom - win_ind.bottom - pos.v; + if (height > max_h) + height = max_h; + if (height < MIN_HEIGHT) + height = MIN_HEIGHT; + if (width < min_w) + width = min_w; + if (width > max_w) + width = max_w; + SizeWindow(theWindow, width, height, true); - if (pos.v + height + win_ind.bottom > scr_r.bottom) - pos.v = scr_r.bottom - height - win_ind.bottom; - if (pos.h + width + win_ind.right > scr_r.right) - pos.h = scr_r.right - width - win_ind.right; - MoveWindow(theWindow, pos.h, pos.v, false); + if (pos.v + height + win_ind.bottom > scr_r.bottom) + pos.v = scr_r.bottom - height - win_ind.bottom; + if (pos.h + width + win_ind.right > scr_r.right) + pos.h = scr_r.right - width - win_ind.right; + MoveWindow(theWindow, pos.h, pos.v, false); #endif - if (aWin->scrollBar) - DrawScrollbar(aWin); - return; + if (aWin->scrollBar) + DrawScrollbar(aWin); + return; } - /* * display/select/update the window. * If f is true, this window should be "modal" - don't return * until presumed seen. */ void -mac_display_nhwindow (winid win, BOOLEAN_P f) { - NhWindow *aWin = &theWindows [win]; - WindowPtr theWindow = aWin->its_window; +mac_display_nhwindow(winid win, BOOLEAN_P f) +{ + NhWindow *aWin = &theWindows[win]; + WindowPtr theWindow = aWin->its_window; - if (win < 0 || win >= NUM_MACWINDOWS || !theWindow) { - error ("disp_win: Invalid window %d.", win); - return; - } + if (win < 0 || win >= NUM_MACWINDOWS || !theWindow) { + error("disp_win: Invalid window %d.", win); + return; + } - if (theWindow == _mt_window) { - tty_display_nhwindow(win, f); - return; - } + if (theWindow == _mt_window) { + tty_display_nhwindow(win, f); + return; + } - if (f && inSelect == WIN_ERR && win == WIN_MESSAGE) { - topl_set_resp ((char *)0, 0); - if (aWin->windowTextLen > 0 && - (*aWin->windowText) [aWin->windowTextLen - 1] == CHAR_CR) { - -- aWin->windowTextLen; - -- aWin->y_size; - } - putstr (win, flags.standout ? ATR_INVERSE : ATR_NONE, " --More--"); - } + if (f && inSelect == WIN_ERR && win == WIN_MESSAGE) { + topl_set_resp((char *) 0, 0); + if (aWin->windowTextLen > 0 + && (*aWin->windowText)[aWin->windowTextLen - 1] == CHAR_CR) { + --aWin->windowTextLen; + --aWin->y_size; + } + putstr(win, flags.standout ? ATR_INVERSE : ATR_NONE, " --More--"); + } - if (!IsWindowVisible(theWindow)) { - if (win != WIN_MESSAGE) - adjust_window_pos(aWin, aWin->x_size + SBARWIDTH+1, aWin->y_size *aWin->row_height); + if (!IsWindowVisible(theWindow)) { + if (win != WIN_MESSAGE) + adjust_window_pos(aWin, aWin->x_size + SBARWIDTH + 1, + aWin->y_size * aWin->row_height); - SelectWindow (theWindow); - ShowWindow (theWindow); - } + SelectWindow(theWindow); + ShowWindow(theWindow); + } - if (f && inSelect == WIN_ERR) { - int ch; + if (f && inSelect == WIN_ERR) { + int ch; - DimMenuBar(); - inSelect = win; - do { - ch = mac_nhgetch (); - } while (!ClosingWindowChar (ch)); - inSelect = WIN_ERR; - UndimMenuBar(); + DimMenuBar(); + inSelect = win; + do { + ch = mac_nhgetch(); + } while (!ClosingWindowChar(ch)); + inSelect = WIN_ERR; + UndimMenuBar(); - if (win == WIN_MESSAGE) - topl_set_resp ("", '\0'); - else - HideWindow (theWindow); - - } + if (win == WIN_MESSAGE) + topl_set_resp("", '\0'); + else + HideWindow(theWindow); + } } - void -mac_destroy_nhwindow (winid win) { - WindowPtr theWindow; - NhWindow *aWin = &theWindows [win]; - int kind; +mac_destroy_nhwindow(winid win) +{ + WindowPtr theWindow; + NhWindow *aWin = &theWindows[win]; + int kind; - if (win < 0 || win >= NUM_MACWINDOWS) { - if (iflags.window_inited) error ("dest_win: Invalid win %d.", win); - return; - } - theWindow = aWin->its_window; - if (!theWindow) { - error ("dest_win: Not allocated win %d.", win); - return; - } + if (win < 0 || win >= NUM_MACWINDOWS) { + if (iflags.window_inited) + error("dest_win: Invalid win %d.", win); + return; + } + theWindow = aWin->its_window; + if (!theWindow) { + error("dest_win: Not allocated win %d.", win); + return; + } - /* - * Check special windows. The base window should never go away. - * Other "standard" windows should not go away unless we've exitted nhwindows. - */ - if (theWindow == _mt_window) { - return; - } - if (win == WIN_INVEN || win == WIN_MESSAGE) { - if (iflags.window_inited) { - if (flags.tombstone && killer[0]) { - /* Prepare for the coming of the tombstone window. */ - win_fonts [NHW_TEXT] = kFontIDMonaco; - } - return; - } - if (win == WIN_MESSAGE) - WIN_MESSAGE = WIN_ERR; - } + /* + * Check special windows. The base window should never go away. + * Other "standard" windows should not go away unless we've exitted + * nhwindows. + */ + if (theWindow == _mt_window) { + return; + } + if (win == WIN_INVEN || win == WIN_MESSAGE) { + if (iflags.window_inited) { + if (flags.tombstone && killer[0]) { + /* Prepare for the coming of the tombstone window. */ + win_fonts[NHW_TEXT] = kFontIDMonaco; + } + return; + } + if (win == WIN_MESSAGE) + WIN_MESSAGE = WIN_ERR; + } - kind = GetWindowKind(theWindow) - WIN_BASE_KIND; + kind = GetWindowKind(theWindow) - WIN_BASE_KIND; - if ((!IsWindowVisible(theWindow) || (kind != NHW_MENU && kind != NHW_TEXT))) { - DisposeWindow (theWindow); - if (aWin->windowText) { - DisposeHandle(aWin->windowText); - } - aWin->its_window = (WindowPtr) 0; - aWin->windowText = (Handle) 0; - } + if ((!IsWindowVisible(theWindow) + || (kind != NHW_MENU && kind != NHW_TEXT))) { + DisposeWindow(theWindow); + if (aWin->windowText) { + DisposeHandle(aWin->windowText); + } + aWin->its_window = (WindowPtr) 0; + aWin->windowText = (Handle) 0; + } } - void -mac_number_pad (int pad) { /* no effect */ +mac_number_pad(int pad) +{ /* no effect */ #if defined(__SC__) || defined(__MRC__) -# pragma unused(pad) +#pragma unused(pad) #endif - return; + return; } - void -trans_num_keys(EventRecord *theEvent) { +trans_num_keys(EventRecord *theEvent) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(theEvent) +#pragma unused(theEvent) #endif /* KMH -- Removed this translation. * Number pad keys should always emit digit characters. @@ -1402,41 +1434,44 @@ trans_num_keys(EventRecord *theEvent) { #endif } - /* - * Routine used to select and de-select elements in a menu window, used by KeyMenu, - * ClickMenu, and UpdateMenu. Takes the NhWindow and a line ref relative to the scrollbar. + * Routine used to select and de-select elements in a menu window, used by + * KeyMenu, + * ClickMenu, and UpdateMenu. Takes the NhWindow and a line ref relative to + * the scrollbar. */ -static void ToggleMenuSelect (NhWindow *aWin, int line) { - Rect r; +static void +ToggleMenuSelect(NhWindow *aWin, int line) +{ + Rect r; + GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + if (aWin->scrollBar) + r.right -= SBARWIDTH; + r.top = line * aWin->row_height; + r.bottom = r.top + aWin->row_height; - GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - if (aWin->scrollBar) - r.right -= SBARWIDTH; - r.top = line * aWin->row_height; - r.bottom = r.top + aWin->row_height; - - LMSetHiliteMode((UInt8) (LMGetHiliteMode() & 0x7F)); - InvertRect(&r); + LMSetHiliteMode((UInt8)(LMGetHiliteMode() & 0x7F)); + InvertRect(&r); } /* * Check to see if given item is selected, return index if it is */ static int -ListItemSelected (NhWindow *aWin, int item) { - int i; +ListItemSelected(NhWindow *aWin, int item) +{ + int i; - HLock ((char**)aWin->menuSelected); - /* Find item in selection list */ - for (i = aWin->miSelLen - 1; i >= 0; i--) { - if ((*aWin->menuSelected) [i] == item) - break; - } - HUnlock ((char**)aWin->menuSelected); - return i; + HLock((char **) aWin->menuSelected); + /* Find item in selection list */ + for (i = aWin->miSelLen - 1; i >= 0; i--) { + if ((*aWin->menuSelected)[i] == item) + break; + } + HUnlock((char **) aWin->menuSelected); + return i; } /* @@ -1444,94 +1479,94 @@ ListItemSelected (NhWindow *aWin, int item) { * If it is selected already, remove it from the list. */ static void -ToggleMenuListItemSelected (NhWindow *aWin, short item) { - int i = ListItemSelected (aWin, item); +ToggleMenuListItemSelected(NhWindow *aWin, short item) +{ + int i = ListItemSelected(aWin, item); - HLock ((char**)aWin->menuSelected); - if (i < 0) { /* not there, so add */ - (*aWin->menuSelected) [aWin->miSelLen] = item; - aWin->miSelLen++; - } - else { /* there, so remove */ - short *mi = &(*aWin->menuSelected)[i]; - aWin->miSelLen --; - memcpy (mi, mi + 1, (aWin->miSelLen - i)*sizeof(short)); - } - HUnlock ((char**)aWin->menuSelected); + HLock((char **) aWin->menuSelected); + if (i < 0) { /* not there, so add */ + (*aWin->menuSelected)[aWin->miSelLen] = item; + aWin->miSelLen++; + } else { /* there, so remove */ + short *mi = &(*aWin->menuSelected)[i]; + aWin->miSelLen--; + memcpy(mi, mi + 1, (aWin->miSelLen - i) * sizeof(short)); + } + HUnlock((char **) aWin->menuSelected); } - /* * Find menu item in list given a line number on the window */ static short -ListCoordinateToItem (NhWindow *aWin, short Row) { - int i, item = -1; - MacMHMenuItem * mi; +ListCoordinateToItem(NhWindow *aWin, short Row) +{ + int i, item = -1; + MacMHMenuItem *mi; - HLock ((char**)aWin->menuInfo); - for (i = 0, mi = *aWin->menuInfo; i < aWin->miLen; i++, mi++) { - if (mi->line == Row + aWin->scrollPos) { - item = i; - break; - } - } - HUnlock ((char**)aWin->menuInfo); - return item; + HLock((char **) aWin->menuInfo); + for (i = 0, mi = *aWin->menuInfo; i < aWin->miLen; i++, mi++) { + if (mi->line == Row + aWin->scrollPos) { + item = i; + break; + } + } + HUnlock((char **) aWin->menuInfo); + return item; } - static pascal void -MoveScrollBar (ControlHandle theBar, short part) { -#if 1//!TARGET_API_MAC_CARBON - EventRecord fake; +MoveScrollBar(ControlHandle theBar, short part) +{ +#if 1 //!TARGET_API_MAC_CARBON + EventRecord fake; #endif - Rect r; - RgnHandle rgn; - int now, amtToScroll; - WindowPtr theWin; - NhWindow *winToScroll; - - if (!part) - return; + Rect r; + RgnHandle rgn; + int now, amtToScroll; + WindowPtr theWin; + NhWindow *winToScroll; - theWin = GetControlOwner(theBar); - GetWindowBounds(theWin, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - winToScroll = (NhWindow*)(GetWRefCon(theWin)); - now = GetControlValue (theBar); + if (!part) + return; - if (part == kControlPageUpPart || part == kControlPageDownPart) - amtToScroll = (r.bottom - r.top) / winToScroll->row_height; - else - amtToScroll = 1; + theWin = GetControlOwner(theBar); + GetWindowBounds(theWin, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + winToScroll = (NhWindow *) (GetWRefCon(theWin)); + now = GetControlValue(theBar); - if (part == kControlPageUpPart || part == kControlUpButtonPart) { - int bound = GetControlMinimum (theBar); - if (now - bound < amtToScroll) - amtToScroll = now - bound; - amtToScroll = -amtToScroll; - } else { - int bound = GetControlMaximum (theBar); - if (bound - now < amtToScroll) - amtToScroll = bound - now; - } - - if (!amtToScroll) - return; + if (part == kControlPageUpPart || part == kControlPageDownPart) + amtToScroll = (r.bottom - r.top) / winToScroll->row_height; + else + amtToScroll = 1; - SetControlValue (theBar, now + amtToScroll); - winToScroll->scrollPos = now + amtToScroll; - r.right -= SBARWIDTH; - if (winToScroll == theWindows + WIN_MESSAGE) - r.bottom -= SBARHEIGHT; - rgn = NewRgn (); - ScrollRect (&r, 0, -amtToScroll * winToScroll->row_height, rgn); - if (rgn) { - InvalWindowRgn(theWin, rgn); - BeginUpdate(theWin); - } -#if 0//TARGET_API_MAC_CARBON + if (part == kControlPageUpPart || part == kControlUpButtonPart) { + int bound = GetControlMinimum(theBar); + if (now - bound < amtToScroll) + amtToScroll = now - bound; + amtToScroll = -amtToScroll; + } else { + int bound = GetControlMaximum(theBar); + if (bound - now < amtToScroll) + amtToScroll = bound - now; + } + + if (!amtToScroll) + return; + + SetControlValue(theBar, now + amtToScroll); + winToScroll->scrollPos = now + amtToScroll; + r.right -= SBARWIDTH; + if (winToScroll == theWindows + WIN_MESSAGE) + r.bottom -= SBARHEIGHT; + rgn = NewRgn(); + ScrollRect(&r, 0, -amtToScroll * winToScroll->row_height, rgn); + if (rgn) { + InvalWindowRgn(theWin, rgn); + BeginUpdate(theWin); + } +#if 0 // TARGET_API_MAC_CARBON switch (GetWindowKind(theWin) - WIN_BASE_KIND) { case NHW_MESSAGE: MsgUpdate(GetNhWin(theWin)); @@ -1544,164 +1579,162 @@ MoveScrollBar (ControlHandle theBar, short part) { break; } #else - winUpdateFuncs [GetWindowKind(theWin) - WIN_BASE_KIND] (&fake, theWin); + winUpdateFuncs[GetWindowKind(theWin) - WIN_BASE_KIND](&fake, theWin); #endif - if (rgn) { - EndUpdate(theWin); - DisposeRgn(rgn); - } + if (rgn) { + EndUpdate(theWin); + DisposeRgn(rgn); + } } - -#if 1//!TARGET_API_MAC_CARBON +#if 1 //!TARGET_API_MAC_CARBON static void -DoScrollBar (Point p, short code, ControlHandle theBar, NhWindow *aWin) +DoScrollBar(Point p, short code, ControlHandle theBar, NhWindow *aWin) { - ControlActionUPP func = NULL; - Rect rect; + ControlActionUPP func = NULL; + Rect rect; - if (code == kControlUpButtonPart || code == kControlPageUpPart || - code == kControlDownButtonPart || code == kControlPageDownPart) - func = MoveScrollUPP; - (void) TrackControl(theBar, p, func); - if (!func) { - if (aWin->scrollPos != GetControlValue (theBar)) { - aWin->scrollPos = GetControlValue (theBar); - GetWindowBounds(aWin->its_window, kWindowContentRgn, &rect); - OffsetRect(&rect, -rect.left, -rect.top); - InvalWindowRect(aWin->its_window, &rect); - } - } + if (code == kControlUpButtonPart || code == kControlPageUpPart + || code == kControlDownButtonPart || code == kControlPageDownPart) + func = MoveScrollUPP; + (void) TrackControl(theBar, p, func); + if (!func) { + if (aWin->scrollPos != GetControlValue(theBar)) { + aWin->scrollPos = GetControlValue(theBar); + GetWindowBounds(aWin->its_window, kWindowContentRgn, &rect); + OffsetRect(&rect, -rect.left, -rect.top); + InvalWindowRect(aWin->its_window, &rect); + } + } } #endif - static int -filter_scroll_key(const int ch, NhWindow *aWin) { - if (aWin->scrollBar && GetControlValue(aWin->scrollBar) < GetControlMaximum(aWin->scrollBar)) { - short part = 0; - if (ch == CHAR_BLANK) { - part = kControlPageDownPart; - } - else if (ch == CHAR_CR || ch == CHAR_LF) { - part = kControlDownButtonPart; - } - if (part) { - SetPortWindowPort(aWin->its_window); - MoveScrollBar(aWin->scrollBar, part); - return 0; - } - } - return ch; +filter_scroll_key(const int ch, NhWindow *aWin) +{ + if (aWin->scrollBar + && GetControlValue(aWin->scrollBar) + < GetControlMaximum(aWin->scrollBar)) { + short part = 0; + if (ch == CHAR_BLANK) { + part = kControlPageDownPart; + } else if (ch == CHAR_CR || ch == CHAR_LF) { + part = kControlDownButtonPart; + } + if (part) { + SetPortWindowPort(aWin->its_window); + MoveScrollBar(aWin->scrollBar, part); + return 0; + } + } + return ch; } - int -mac_doprev_message(void) { - if (WIN_MESSAGE) { - NhWindow *winToScroll = &theWindows[WIN_MESSAGE]; - mac_display_nhwindow(WIN_MESSAGE, FALSE); - SetPortWindowPort(winToScroll->its_window); - MoveScrollBar(winToScroll->scrollBar, kControlUpButtonPart); - } - return 0; +mac_doprev_message(void) +{ + if (WIN_MESSAGE) { + NhWindow *winToScroll = &theWindows[WIN_MESSAGE]; + mac_display_nhwindow(WIN_MESSAGE, FALSE); + SetPortWindowPort(winToScroll->its_window); + MoveScrollBar(winToScroll->scrollBar, kControlUpButtonPart); + } + return 0; } - static void draw_growicon_vert_only(WindowPtr wind) { - GrafPtr org_port; - RgnHandle org_clip = NewRgn(); - Rect r; + GrafPtr org_port; + RgnHandle org_clip = NewRgn(); + Rect r; - GetPort(&org_port); - SetPortWindowPort(wind); - GetClip(org_clip); - GetWindowBounds(wind, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - r.left = r.right - SBARWIDTH; - ClipRect(&r); - DrawGrowIcon(wind); - SetClip(org_clip); - DisposeRgn(org_clip); - SetPort(org_port); + GetPort(&org_port); + SetPortWindowPort(wind); + GetClip(org_clip); + GetWindowBounds(wind, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + r.left = r.right - SBARWIDTH; + ClipRect(&r); + DrawGrowIcon(wind); + SetClip(org_clip); + DisposeRgn(org_clip); + SetPort(org_port); } - /* NOT_IN_CARBON */ static void -WindowGoAway (EventRecord *theEvent, WindowPtr theWindow) { - NhWindow *aWin = GetNhWin(theWindow); +WindowGoAway(EventRecord *theEvent, WindowPtr theWindow) +{ + NhWindow *aWin = GetNhWin(theWindow); - if (!theEvent || TrackGoAway (theWindow, theEvent->where)) { - if (aWin - theWindows == BASE_WINDOW && !iflags.window_inited) { - AddToKeyQueue ('\033', 1); - } else { - HideWindow (theWindow); - if (aWin - theWindows != inSelect) - mac_destroy_nhwindow (aWin - theWindows); - else /* if this IS the inSelect window put a close char */ - AddToKeyQueue (CHAR_CR, 1); /* in queue to exit and maintain inSelect */ - } - } + if (!theEvent || TrackGoAway(theWindow, theEvent->where)) { + if (aWin - theWindows == BASE_WINDOW && !iflags.window_inited) { + AddToKeyQueue('\033', 1); + } else { + HideWindow(theWindow); + if (aWin - theWindows != inSelect) + mac_destroy_nhwindow(aWin - theWindows); + else /* if this IS the inSelect window put a close char */ + AddToKeyQueue(CHAR_CR, + 1); /* in queue to exit and maintain inSelect */ + } + } } - void -mac_get_nh_event(void) { - EventRecord anEvent; +mac_get_nh_event(void) +{ + EventRecord anEvent; - - /* KMH -- Don't proceed if the window system isn't set up */ - if (!iflags.window_inited) - return; + /* KMH -- Don't proceed if the window system isn't set up */ + if (!iflags.window_inited) + return; #if TARGET_API_MAC_CARBON - QDFlushPortBuffer(GetWindowPort(_mt_window), NULL); + QDFlushPortBuffer(GetWindowPort(_mt_window), NULL); #endif - (void) WaitNextEvent (everyEvent, &anEvent, 1, gMouseRgn); - HandleEvent(&anEvent); - return; + (void) WaitNextEvent(everyEvent, &anEvent, 1, gMouseRgn); + HandleEvent(&anEvent); + return; } - int -mac_nhgetch(void) { - int ch; - long doDawdle = 1L; - EventRecord anEvent; +mac_nhgetch(void) +{ + int ch; + long doDawdle = 1L; + EventRecord anEvent; +#if 1 //!TARGET_API_MAC_CARBON + /* We want to take care of keys in the buffer as fast as + * possible + */ + if (keyQueueCount) + doDawdle = 0L; + else { + long total, contig; + static char warn = 0; -#if 1//!TARGET_API_MAC_CARBON - /* We want to take care of keys in the buffer as fast as - * possible - */ - if (keyQueueCount) - doDawdle = 0L; - else { - long total, contig; - static char warn = 0; - - doDawdle = (in_topl_mode() ? GetCaretTime () : 120L); - /* Since we have time, check memory */ - PurgeSpace(&total, &contig); - if (contig < 25000L || total < 50000L) { - if (!warn) { - pline ("Low Memory!"); - warn = 1; - } - } else { - warn = 0; - } - } + doDawdle = (in_topl_mode() ? GetCaretTime() : 120L); + /* Since we have time, check memory */ + PurgeSpace(&total, &contig); + if (contig < 25000L || total < 50000L) { + if (!warn) { + pline("Low Memory!"); + warn = 1; + } + } else { + warn = 0; + } + } #endif - do { + do { #if TARGET_API_MAC_CARBON - QDFlushPortBuffer(GetWindowPort(_mt_window), NULL); + QDFlushPortBuffer(GetWindowPort(_mt_window), NULL); #endif -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON EventRef event; if (ReceiveNextEvent(0, NULL, kEventDurationForever, TRUE, &event) == noErr) { @@ -1709,271 +1742,278 @@ mac_nhgetch(void) { ReleaseEvent(event); } #else - (void) WaitNextEvent(everyEvent, &anEvent, doDawdle, gMouseRgn); - HandleEvent(&anEvent); + (void) WaitNextEvent(everyEvent, &anEvent, doDawdle, gMouseRgn); + HandleEvent(&anEvent); #endif - ch = GetFromKeyQueue(); - } while (!ch && !gClickedToMove); + ch = GetFromKeyQueue(); + } while (!ch && !gClickedToMove); - if (!gClickedToMove) - ObscureCursor(); - else - gClickedToMove = 0; + if (!gClickedToMove) + ObscureCursor(); + else + gClickedToMove = 0; #ifdef THINK_C - if (ch == '\r') ch = '\n'; + if (ch == '\r') + ch = '\n'; #endif - return (ch); + return (ch); } - void -mac_delay_output(void) { - long destTicks = TickCount () + 1; +mac_delay_output(void) +{ + long destTicks = TickCount() + 1; - while (TickCount () < destTicks) { - mac_get_nh_event (); - } + while (TickCount() < destTicks) { + mac_get_nh_event(); + } } - #ifdef CLIPPING static void -mac_cliparound (int x, int y) { +mac_cliparound(int x, int y) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(x,y) +#pragma unused(x, y) #endif - /* TODO */ + /* TODO */ } #endif void -mac_exit_nhwindows (const char *s) { - clear_screen (); - tty_exit_nhwindows (s); - mac_destroy_nhwindow (WIN_MESSAGE); - mac_destroy_nhwindow (WIN_INVEN); +mac_exit_nhwindows(const char *s) +{ + clear_screen(); + tty_exit_nhwindows(s); + mac_destroy_nhwindow(WIN_MESSAGE); + mac_destroy_nhwindow(WIN_INVEN); } - /* * Don't forget to decrease in_putstr before returning... */ void -mac_putstr (winid win, int attr, const char *str) { - long len, slen; - NhWindow *aWin = &theWindows [win]; - static char in_putstr = 0; - short newWidth, maxWidth; - Rect r; - char *src, *sline, *dst, ch; +mac_putstr(winid win, int attr, const char *str) +{ + long len, slen; + NhWindow *aWin = &theWindows[win]; + static char in_putstr = 0; + short newWidth, maxWidth; + Rect r; + char *src, *sline, *dst, ch; - if (win < 0 || win >= NUM_MACWINDOWS || !aWin->its_window) { - error ("putstr: Invalid win %d (Max %d).", win, NUM_MACWINDOWS, attr); - return; - } + if (win < 0 || win >= NUM_MACWINDOWS || !aWin->its_window) { + error("putstr: Invalid win %d (Max %d).", win, NUM_MACWINDOWS, attr); + return; + } - if (aWin->its_window == _mt_window) { - tty_putstr(win, attr, str); - return; - } + if (aWin->its_window == _mt_window) { + tty_putstr(win, attr, str); + return; + } - if (in_putstr > 3) - return; + if (in_putstr > 3) + return; - in_putstr ++; - slen = strlen (str); + in_putstr++; + slen = strlen(str); - SetPortWindowPort(aWin->its_window); - GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - if (win == WIN_MESSAGE) { - r.right -= SBARWIDTH; - r.bottom -= SBARHEIGHT; - if (flags.page_wait && - aWin->last_more_lin <= aWin->y_size - (r.bottom - r.top) / aWin->row_height) { - aWin->last_more_lin = aWin->y_size; - mac_display_nhwindow(win, TRUE); - } - } + SetPortWindowPort(aWin->its_window); + GetWindowBounds(aWin->its_window, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + if (win == WIN_MESSAGE) { + r.right -= SBARWIDTH; + r.bottom -= SBARHEIGHT; + if (flags.page_wait + && aWin->last_more_lin + <= aWin->y_size - (r.bottom - r.top) / aWin->row_height) { + aWin->last_more_lin = aWin->y_size; + mac_display_nhwindow(win, TRUE); + } + } - /* - * A "default" text window - uses TETextBox - * We just add the text, without attributes for now - */ - len = GetHandleSize (aWin->windowText); - while (aWin->windowTextLen + slen + 1 > len) { - len = (len > 2048) ? (len + 2048) : (len * 2); - SetHandleSize (aWin->windowText, len); - if (MemError ()) { - error ("putstr: SetHandleSize"); - aWin->windowTextLen = 0L; - aWin->save_lin = 0; - aWin->y_curs = 0; - aWin->y_size = 0; - } - } - - len = aWin->windowTextLen; - dst = *(aWin->windowText) + len; - sline = src = (char *)str; - maxWidth = newWidth = 0; - for (ch = *src; ch; ch = *src) { - if (ch == CHAR_LF) - ch = CHAR_CR; - *dst++ = ch; - if (ch == CHAR_CR) { - aWin->y_curs ++; - aWin->y_size ++; - aWin->x_curs = 0; - newWidth = TextWidth (sline, 0, src - sline); - if (newWidth > maxWidth) { - maxWidth = newWidth; - } - sline = src+1; /* keep track of where new line begins */ - } - else - aWin->x_curs ++; - src++; - } + /* + * A "default" text window - uses TETextBox + * We just add the text, without attributes for now + */ + len = GetHandleSize(aWin->windowText); + while (aWin->windowTextLen + slen + 1 > len) { + len = (len > 2048) ? (len + 2048) : (len * 2); + SetHandleSize(aWin->windowText, len); + if (MemError()) { + error("putstr: SetHandleSize"); + aWin->windowTextLen = 0L; + aWin->save_lin = 0; + aWin->y_curs = 0; + aWin->y_size = 0; + } + } - newWidth = TextWidth (sline, 0, src - sline); - if (newWidth > maxWidth) { - maxWidth = newWidth; - } + len = aWin->windowTextLen; + dst = *(aWin->windowText) + len; + sline = src = (char *) str; + maxWidth = newWidth = 0; + for (ch = *src; ch; ch = *src) { + if (ch == CHAR_LF) + ch = CHAR_CR; + *dst++ = ch; + if (ch == CHAR_CR) { + aWin->y_curs++; + aWin->y_size++; + aWin->x_curs = 0; + newWidth = TextWidth(sline, 0, src - sline); + if (newWidth > maxWidth) { + maxWidth = newWidth; + } + sline = src + 1; /* keep track of where new line begins */ + } else + aWin->x_curs++; + src++; + } - aWin->windowTextLen += slen; - - if (ch != CHAR_CR) { - (*(aWin->windowText)) [len + slen] = CHAR_CR; - aWin->windowTextLen ++; - aWin->y_curs ++; - aWin->y_size ++; - aWin->x_curs = 0; - } + newWidth = TextWidth(sline, 0, src - sline); + if (newWidth > maxWidth) { + maxWidth = newWidth; + } - if (win == WIN_MESSAGE) { - short min = aWin->y_size - (r.bottom - r.top) / aWin->row_height; - if (aWin->scrollPos < min) { - aWin->scrollPos = min; - SetControlMaximum (aWin->scrollBar, aWin->y_size); - SetControlValue(aWin->scrollBar, min); - } - InvalWindowRect(aWin->its_window, &r); - } - else /* Message has a fixed width, other windows base on content */ - if (maxWidth > aWin->x_size) - aWin->x_size = maxWidth; - in_putstr --; + aWin->windowTextLen += slen; + + if (ch != CHAR_CR) { + (*(aWin->windowText))[len + slen] = CHAR_CR; + aWin->windowTextLen++; + aWin->y_curs++; + aWin->y_size++; + aWin->x_curs = 0; + } + + if (win == WIN_MESSAGE) { + short min = aWin->y_size - (r.bottom - r.top) / aWin->row_height; + if (aWin->scrollPos < min) { + aWin->scrollPos = min; + SetControlMaximum(aWin->scrollBar, aWin->y_size); + SetControlValue(aWin->scrollBar, min); + } + InvalWindowRect(aWin->its_window, &r); + } else /* Message has a fixed width, other windows base on content */ + if (maxWidth > aWin->x_size) + aWin->x_size = maxWidth; + in_putstr--; } - void -mac_curs (winid win, int x, int y) { - NhWindow *aWin = &theWindows [win]; +mac_curs(winid win, int x, int y) +{ + NhWindow *aWin = &theWindows[win]; - if (aWin->its_window == _mt_window) { - tty_curs(win, x, y); - return; - } + if (aWin->its_window == _mt_window) { + tty_curs(win, x, y); + return; + } - SetPortWindowPort(aWin->its_window); - MoveTo (x * aWin->char_width, (y * aWin->row_height) + aWin->ascent_height); - aWin->x_curs = x; - aWin->y_curs = y; + SetPortWindowPort(aWin->its_window); + MoveTo(x * aWin->char_width, + (y * aWin->row_height) + aWin->ascent_height); + aWin->x_curs = x; + aWin->y_curs = y; } - int -mac_nh_poskey (int *a, int *b, int *c) { - int ch = mac_nhgetch(); - *a = clicked_pos.h; - *b = clicked_pos.v; - *c = clicked_mod; - return ch; +mac_nh_poskey(int *a, int *b, int *c) +{ + int ch = mac_nhgetch(); + *a = clicked_pos.h; + *b = clicked_pos.v; + *c = clicked_mod; + return ch; } - void -mac_start_menu (winid win) { - HideWindow (theWindows [win].its_window); - mac_clear_nhwindow (win); +mac_start_menu(winid win) +{ + HideWindow(theWindows[win].its_window); + mac_clear_nhwindow(win); } - void -mac_add_menu (winid win, int glyph, const anything *any, CHAR_P menuChar, CHAR_P groupAcc, int attr, const char *inStr, int preselected) { +mac_add_menu(winid win, int glyph, const anything *any, CHAR_P menuChar, + CHAR_P groupAcc, int attr, const char *inStr, int preselected) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(glyph) +#pragma unused(glyph) #endif - NhWindow *aWin = &theWindows [win]; - const char *str; - char locStr[4+BUFSZ]; - MacMHMenuItem *item; + NhWindow *aWin = &theWindows[win]; + const char *str; + char locStr[4 + BUFSZ]; + MacMHMenuItem *item; - if (!inStr) return; - - if (any->a_void != 0) { + if (!inStr) + return; + if (any->a_void != 0) { #define kMenuSizeBump 26 - if (!aWin->miSize) { - aWin->menuInfo = (MacMHMenuItem **)NewHandle(sizeof(MacMHMenuItem) * kMenuSizeBump); - if (!aWin->menuInfo) { - error("Can't alloc menu handle"); - return; - } - aWin->menuSelected = (short **)NewHandle(sizeof(short) * kMenuSizeBump); - if (!aWin->menuSelected) { - error("Can't alloc menu select handle"); - return; - } - aWin->miSize = kMenuSizeBump; - } + if (!aWin->miSize) { + aWin->menuInfo = (MacMHMenuItem **) NewHandle( + sizeof(MacMHMenuItem) * kMenuSizeBump); + if (!aWin->menuInfo) { + error("Can't alloc menu handle"); + return; + } + aWin->menuSelected = + (short **) NewHandle(sizeof(short) * kMenuSizeBump); + if (!aWin->menuSelected) { + error("Can't alloc menu select handle"); + return; + } + aWin->miSize = kMenuSizeBump; + } - if (aWin->miLen >= aWin->miSize) { - SetHandleSize((Handle)aWin->menuInfo, sizeof(MacMHMenuItem) * (aWin->miLen+kMenuSizeBump)); - if (MemError()) { - error("Can't resize menu handle"); - return; - } - SetHandleSize((Handle)aWin->menuSelected, sizeof(short) * (aWin->miLen+kMenuSizeBump)); - if (MemError()) { - error("Can't resize menu select handle"); - return; - } - aWin->miSize += kMenuSizeBump; - } + if (aWin->miLen >= aWin->miSize) { + SetHandleSize((Handle) aWin->menuInfo, + sizeof(MacMHMenuItem) + * (aWin->miLen + kMenuSizeBump)); + if (MemError()) { + error("Can't resize menu handle"); + return; + } + SetHandleSize((Handle) aWin->menuSelected, + sizeof(short) * (aWin->miLen + kMenuSizeBump)); + if (MemError()) { + error("Can't resize menu select handle"); + return; + } + aWin->miSize += kMenuSizeBump; + } - if (menuChar == 0) { - if (('a' <= aWin->menuChar && aWin->menuChar <= 'z') || - ('A' <= aWin->menuChar && aWin->menuChar <= 'Z')) { - menuChar = aWin->menuChar++; - if (menuChar == 'z') - aWin->menuChar = 'A'; - } - } - - Sprintf(locStr, "%c - %s", (menuChar ? menuChar : ' '), inStr); - str = locStr; - HLock ((char**)aWin->menuInfo); - HLock ((char**)aWin->menuSelected); - (*aWin->menuSelected)[aWin->miLen] = preselected; - item = &(*aWin->menuInfo)[aWin->miLen]; - aWin->miLen++; - item->id = *any; - item->accelerator = menuChar; - item->groupAcc = groupAcc; - item->line = aWin->y_size; - HUnlock ((char**)aWin->menuInfo); - HUnlock ((char**)aWin->menuSelected); - } else - str = inStr; + if (menuChar == 0) { + if (('a' <= aWin->menuChar && aWin->menuChar <= 'z') + || ('A' <= aWin->menuChar && aWin->menuChar <= 'Z')) { + menuChar = aWin->menuChar++; + if (menuChar == 'z') + aWin->menuChar = 'A'; + } + } - putstr (win, attr, str); + Sprintf(locStr, "%c - %s", (menuChar ? menuChar : ' '), inStr); + str = locStr; + HLock((char **) aWin->menuInfo); + HLock((char **) aWin->menuSelected); + (*aWin->menuSelected)[aWin->miLen] = preselected; + item = &(*aWin->menuInfo)[aWin->miLen]; + aWin->miLen++; + item->id = *any; + item->accelerator = menuChar; + item->groupAcc = groupAcc; + item->line = aWin->y_size; + HUnlock((char **) aWin->menuInfo); + HUnlock((char **) aWin->menuSelected); + } else + str = inStr; + + putstr(win, attr, str); } - /* * End a menu in this window, window must a type NHW_MENU. * str is a list of cancel characters (values that may be input) @@ -1981,138 +2021,139 @@ mac_add_menu (winid win, int glyph, const anything *any, CHAR_P menuChar, CHAR_P * str and morestr might be ignored by some ports. */ void -mac_end_menu (winid win, const char *morestr) { - Str255 buf; - NhWindow *aWin = &theWindows [win]; +mac_end_menu(winid win, const char *morestr) +{ + Str255 buf; + NhWindow *aWin = &theWindows[win]; - buf [0] = 0; - if (morestr) - C2P (morestr, buf); - SetWTitle (aWin->its_window, buf); + buf[0] = 0; + if (morestr) + C2P(morestr, buf); + SetWTitle(aWin->its_window, buf); } - int -mac_select_menu (winid win, int how, menu_item **selected_list) { - int c; - NhWindow *aWin = &theWindows [win]; - WindowPtr theWin = aWin->its_window; +mac_select_menu(winid win, int how, menu_item **selected_list) +{ + int c; + NhWindow *aWin = &theWindows[win]; + WindowPtr theWin = aWin->its_window; - inSelect = win; + inSelect = win; - mac_display_nhwindow (win, FALSE); + mac_display_nhwindow(win, FALSE); - aWin->how = (short) how; - for (;;) { - c = map_menu_cmd (mac_nhgetch()); - if (c == CHAR_ESC) { - /* deselect everything */ - aWin->miSelLen = 0; - break; - } else if (ClosingWindowChar(c)) { - break; - } else { - nhbell(); - } - } + aWin->how = (short) how; + for (;;) { + c = map_menu_cmd(mac_nhgetch()); + if (c == CHAR_ESC) { + /* deselect everything */ + aWin->miSelLen = 0; + break; + } else if (ClosingWindowChar(c)) { + break; + } else { + nhbell(); + } + } - HideWindow (theWin); + HideWindow(theWin); - if (aWin->miSelLen) { - menu_item *mp; - MacMHMenuItem *mi; - *selected_list = mp = (menu_item *) alloc(aWin->miSelLen * sizeof(menu_item)); - HLock ((char**)aWin->menuInfo); - HLock ((char**)aWin->menuSelected); - for (c = 0; c < aWin->miSelLen; c++) { - mi = &(*aWin->menuInfo)[(*aWin->menuSelected) [c]]; - mp->item = mi->id; - mp->count = -1L; - mp++; - } - HUnlock ((char**)aWin->menuInfo); - HUnlock ((char**)aWin->menuSelected); - } else - *selected_list = 0; + if (aWin->miSelLen) { + menu_item *mp; + MacMHMenuItem *mi; + *selected_list = mp = + (menu_item *) alloc(aWin->miSelLen * sizeof(menu_item)); + HLock((char **) aWin->menuInfo); + HLock((char **) aWin->menuSelected); + for (c = 0; c < aWin->miSelLen; c++) { + mi = &(*aWin->menuInfo)[(*aWin->menuSelected)[c]]; + mp->item = mi->id; + mp->count = -1L; + mp++; + } + HUnlock((char **) aWin->menuInfo); + HUnlock((char **) aWin->menuSelected); + } else + *selected_list = 0; - inSelect = WIN_ERR; + inSelect = WIN_ERR; - return aWin->miSelLen; + return aWin->miSelLen; } #include "dlb.h" static void -mac_display_file (name, complain) -const char *name; /* not ANSI prototype because of boolean parameter */ +mac_display_file(name, complain) +const char *name; /* not ANSI prototype because of boolean parameter */ boolean complain; { - Ptr buf; - int win; - dlb *fp = dlb_fopen(name, "r"); - - if (fp) { - long l = dlb_fseek(fp, 0, SEEK_END); - (void) dlb_fseek(fp, 0, 0L); - buf = NewPtr(l+1); - if (buf) { - l = dlb_fread(buf, 1, l, fp); - if (l > 0) { - buf[l] = '\0'; - win = create_nhwindow(NHW_TEXT); - if (WIN_ERR == win) { - if (complain) error ("Cannot make window."); - } else { - putstr(win, 0, buf); - display_nhwindow(win, FALSE); - } - } - DisposePtr(buf); - } - dlb_fclose(fp); - } else if (complain) - error("Cannot open %s.", name); -} + Ptr buf; + int win; + dlb *fp = dlb_fopen(name, "r"); + if (fp) { + long l = dlb_fseek(fp, 0, SEEK_END); + (void) dlb_fseek(fp, 0, 0L); + buf = NewPtr(l + 1); + if (buf) { + l = dlb_fread(buf, 1, l, fp); + if (l > 0) { + buf[l] = '\0'; + win = create_nhwindow(NHW_TEXT); + if (WIN_ERR == win) { + if (complain) + error("Cannot make window."); + } else { + putstr(win, 0, buf); + display_nhwindow(win, FALSE); + } + } + DisposePtr(buf); + } + dlb_fclose(fp); + } else if (complain) + error("Cannot open %s.", name); +} void -port_help () { - display_file (PORT_HELP, TRUE); +port_help() +{ + display_file(PORT_HELP, TRUE); } - static void -mac_unimplemented (void) { +mac_unimplemented(void) +{ } - static void -mac_suspend_nhwindows (const char *foo) { +mac_suspend_nhwindows(const char *foo) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(foo) +#pragma unused(foo) #endif - /* Can't really do that :-) */ + /* Can't really do that :-) */ } - int -try_key_queue (char *bufp) { - if (keyQueueCount) { - char ch; - for (ch = GetFromKeyQueue(); ; ch = GetFromKeyQueue()) { - if (ch == CHAR_LF || ch == CHAR_CR) - ch = 0; - *bufp++ = ch; - if (ch == 0) - break; - } - return 1; - } - return 0; +try_key_queue(char *bufp) +{ + if (keyQueueCount) { + char ch; + for (ch = GetFromKeyQueue();; ch = GetFromKeyQueue()) { + if (ch == CHAR_LF || ch == CHAR_CR) + ch = 0; + *bufp++ = ch; + if (ch == 0) + break; + } + return 1; + } + return 0; } - - /********************************************************************** * Base window */ @@ -2120,53 +2161,51 @@ try_key_queue (char *bufp) { static void BaseClick(NhWindow *wind, Point pt, UInt32 modifiers) { - pt.h = pt.h / wind->char_width + 1; - pt.v = pt.v / wind->row_height; - clicked_mod = (modifiers & shiftKey) ? CLICK_2 : CLICK_1; + pt.h = pt.h / wind->char_width + 1; + pt.v = pt.v / wind->row_height; + clicked_mod = (modifiers & shiftKey) ? CLICK_2 : CLICK_1; - if (strchr(topl_resp, *click_to_cmd(pt.h, pt.v, clicked_mod))) - nhbell(); - else { -#if 1//!TARGET_API_MAC_CARBON - if (cursor_locked) - while (WaitMouseUp()) - /*SystemTask()*/; + if (strchr(topl_resp, *click_to_cmd(pt.h, pt.v, clicked_mod))) + nhbell(); + else { +#if 1 //!TARGET_API_MAC_CARBON + if (cursor_locked) + while (WaitMouseUp()) + /*SystemTask()*/; #endif - gClickedToMove = TRUE; - clicked_pos = pt; - } - return; + gClickedToMove = TRUE; + clicked_pos = pt; + } + return; } - static void BaseCursor(NhWindow *wind, Point pt) { - char *dir_bas, *dir; - CursHandle ch; + char *dir_bas, *dir; + CursHandle ch; - - if (cursor_locked) - dir = (char *)0; - else { - dir_bas = (char *)Cmd.dirchars; - dir = strchr(dir_bas, *click_to_cmd(pt.h / wind->char_width + 1 , - pt.v / wind->row_height, CLICK_1)); - } - ch = GetCursor(dir ? dir - dir_bas + 513 : 512); - if (ch) { - HLock((Handle) ch); - SetCursor(*ch); - HUnlock((Handle) ch); - } else { - SetCursor(&qdarrow); - } - return; + if (cursor_locked) + dir = (char *) 0; + else { + dir_bas = (char *) Cmd.dirchars; + dir = + strchr(dir_bas, *click_to_cmd(pt.h / wind->char_width + 1, + pt.v / wind->row_height, CLICK_1)); + } + ch = GetCursor(dir ? dir - dir_bas + 513 : 512); + if (ch) { + HLock((Handle) ch); + SetCursor(*ch); + HUnlock((Handle) ch); + } else { + SetCursor(&qdarrow); + } + return; } - -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static pascal OSStatus BaseEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) { @@ -2245,48 +2284,42 @@ BaseEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) #else static void -macClickTerm (EventRecord *theEvent, WindowPtr theWindow) { - Point where = theEvent->where; +macClickTerm(EventRecord *theEvent, WindowPtr theWindow) +{ + Point where = theEvent->where; - GlobalToLocal(&where); - BaseClick(GetNhWin(theWindow), where, theEvent->modifiers); - return; + GlobalToLocal(&where); + BaseClick(GetNhWin(theWindow), where, theEvent->modifiers); + return; } - static void -macCursorTerm (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) { - GrafPtr gp; - Point where = theEvent->where; - Rect r = {0, 0, 1, 1}; +macCursorTerm(EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) +{ + GrafPtr gp; + Point where = theEvent->where; + Rect r = { 0, 0, 1, 1 }; - - GetPort(&gp); - SetPortWindowPort(theWindow); - GlobalToLocal(&where); - BaseCursor(GetNhWin(theWindow), where); - OffsetRect(&r, theEvent->where.h, theEvent->where.v); - RectRgn(mouseRgn, &r); - SetPort(gp); - return; + GetPort(&gp); + SetPortWindowPort(theWindow); + GlobalToLocal(&where); + BaseCursor(GetNhWin(theWindow), where); + OffsetRect(&r, theEvent->where.h, theEvent->where.v); + RectRgn(mouseRgn, &r); + SetPort(gp); + return; } -#endif /* !TARGET_API_MAC_CARBON */ - - +#endif /* !TARGET_API_MAC_CARBON */ /********************************************************************** * Status subwindow */ - - /********************************************************************** * Map subwindow */ - - /********************************************************************** * Message window */ @@ -2294,107 +2327,104 @@ macCursorTerm (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) { static void MsgClick(NhWindow *wind, Point pt) { - int r_idx = 0; + int r_idx = 0; + while (topl_resp[r_idx]) { + Rect frame; + topl_resp_rect(r_idx, &frame); + InsetRect(&frame, 1, 1); + if (PtInRect(pt, &frame)) { + Boolean in_btn = true; - while (topl_resp[r_idx]) { - Rect frame; - topl_resp_rect(r_idx, &frame); - InsetRect(&frame, 1, 1); - if (PtInRect(pt, &frame)) { - Boolean in_btn = true; - - InvertRect(&frame); - while (WaitMouseUp()) { + InvertRect(&frame); + while (WaitMouseUp()) { #if !TARGET_API_MAC_CARBON - SystemTask(); + SystemTask(); #endif - GetMouse(&pt); - if (PtInRect(pt, &frame) != in_btn) { - in_btn = !in_btn; - InvertRect(&frame); - } - } - if (in_btn) { - InvertRect(&frame); - AddToKeyQueue (topl_resp [r_idx], 1); - } - return; - - } - ++r_idx; - } - return; + GetMouse(&pt); + if (PtInRect(pt, &frame) != in_btn) { + in_btn = !in_btn; + InvertRect(&frame); + } + } + if (in_btn) { + InvertRect(&frame); + AddToKeyQueue(topl_resp[r_idx], 1); + } + return; + } + ++r_idx; + } + return; } - static void MsgUpdate(NhWindow *wind) { - RgnHandle org_clip = NewRgn(), clip = NewRgn(); - Rect r; - int l; + RgnHandle org_clip = NewRgn(), clip = NewRgn(); + Rect r; + int l; + GetClip(org_clip); + GetWindowBounds(wind->its_window, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); - GetClip(org_clip); - GetWindowBounds(wind->its_window, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); + DrawControls(wind->its_window); + DrawGrowIcon(wind->its_window); - DrawControls(wind->its_window); - DrawGrowIcon(wind->its_window); + for (l = 0; topl_resp[l]; l++) { + StringPtr name; + unsigned char tmp[2]; + FontInfo font; + Rect frame; + topl_resp_rect(l, &frame); + switch (topl_resp[l]) { + case 'y': + name = "\pyes"; + break; + case 'n': + name = "\pno"; + break; + case 'N': + name = "\pNone"; + break; + case 'a': + name = "\pall"; + break; + case 'q': + name = "\pquit"; + break; + case CHAR_ANY: + name = "\pany key"; + break; + default: + tmp[0] = 1; + tmp[1] = topl_resp[l]; + name = tmp; + break; + } + TextFont(kFontIDGeneva); + TextSize(9); + GetFontInfo(&font); + MoveTo((frame.left + frame.right - StringWidth(name)) / 2, + (frame.top + frame.bottom + font.ascent - font.descent + - font.leading - 1) / 2); + DrawString(name); + PenNormal(); + if (l == topl_def_idx) + PenSize(2, 2); + FrameRoundRect(&frame, 4, 4); + } - for (l = 0; topl_resp[l]; l++) { - StringPtr name; - unsigned char tmp[2]; - FontInfo font; - Rect frame; - topl_resp_rect(l, &frame); - switch (topl_resp[l]) { - case 'y': - name = "\pyes"; - break; - case 'n': - name = "\pno"; - break; - case 'N': - name = "\pNone"; - break; - case 'a': - name = "\pall"; - break; - case 'q': - name = "\pquit"; - break; - case CHAR_ANY: - name = "\pany key"; - break; - default: - tmp[0] = 1; - tmp[1] = topl_resp[l]; - name = tmp; - break; - } - TextFont(kFontIDGeneva); - TextSize(9); - GetFontInfo(&font); - MoveTo ((frame.left + frame.right - StringWidth(name)) / 2, - (frame.top + frame.bottom + font.ascent-font.descent-font.leading-1) / 2); - DrawString(name); - PenNormal(); - if (l == topl_def_idx) - PenSize(2, 2); - FrameRoundRect(&frame, 4, 4); - } - - r.right -= SBARWIDTH; - r.bottom -= SBARHEIGHT; - /* Clip to the portrect - scrollbar/growicon *before* adjusting the rect - to be larger than the size of the window (!) */ - RectRgn(clip, &r); - SectRgn(clip, org_clip, clip); - if (r.right < MIN_RIGHT) - r.right = MIN_RIGHT; - r.top -= wind->scrollPos * wind->row_height; + r.right -= SBARWIDTH; + r.bottom -= SBARHEIGHT; + /* Clip to the portrect - scrollbar/growicon *before* adjusting the rect + to be larger than the size of the window (!) */ + RectRgn(clip, &r); + SectRgn(clip, org_clip, clip); + if (r.right < MIN_RIGHT) + r.right = MIN_RIGHT; + r.top -= wind->scrollPos * wind->row_height; #if 0 /* If you enable this band of code (and disable the next band), you will get @@ -2413,43 +2443,42 @@ MsgUpdate(NhWindow *wind) } #endif - if (in_topl_mode()) { - RgnHandle topl_rgn = NewRgn(); - Rect topl_r = r; - topl_r.top += (wind->y_size - 1) * wind->row_height; - l = (*top_line)->destRect.right - (*top_line)->destRect.left; - (*top_line)->viewRect = topl_r; - (*top_line)->destRect = topl_r; - if (l != topl_r.right - topl_r.left) - TECalText(top_line); - TEUpdate(&topl_r, top_line); - RectRgn(topl_rgn, &topl_r); - DiffRgn(clip, topl_rgn, clip); - DisposeRgn(topl_rgn); - SetClip(clip); - } + if (in_topl_mode()) { + RgnHandle topl_rgn = NewRgn(); + Rect topl_r = r; + topl_r.top += (wind->y_size - 1) * wind->row_height; + l = (*top_line)->destRect.right - (*top_line)->destRect.left; + (*top_line)->viewRect = topl_r; + (*top_line)->destRect = topl_r; + if (l != topl_r.right - topl_r.left) + TECalText(top_line); + TEUpdate(&topl_r, top_line); + RectRgn(topl_rgn, &topl_r); + DiffRgn(clip, topl_rgn, clip); + DisposeRgn(topl_rgn); + SetClip(clip); + } - DisposeRgn(clip); + DisposeRgn(clip); - TextFont (wind->font_number); - TextSize (wind->font_size); - HLock (wind->windowText); - TETextBox (*wind->windowText, wind->windowTextLen, &r, teJustLeft); - HUnlock (wind->windowText); + TextFont(wind->font_number); + TextSize(wind->font_size); + HLock(wind->windowText); + TETextBox(*wind->windowText, wind->windowTextLen, &r, teJustLeft); + HUnlock(wind->windowText); #if !TARGET_API_MAC_CARBON - r.bottom = r.top + aWin->save_lin * aWin->row_height; - r.top = r.bottom - 1; - FillRect(&r, (void *) &qd.gray); + r.bottom = r.top + aWin->save_lin * aWin->row_height; + r.top = r.bottom - 1; + FillRect(&r, (void *) &qd.gray); #endif - SetClip(org_clip); - DisposeRgn(org_clip); - return; + SetClip(org_clip); + DisposeRgn(org_clip); + return; } - -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static pascal OSStatus MsgEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) { @@ -2521,27 +2550,25 @@ MsgEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) #else static void -macClickMessage (EventRecord *theEvent, WindowPtr theWindow) { - Point mouse = theEvent->where; +macClickMessage(EventRecord *theEvent, WindowPtr theWindow) +{ + Point mouse = theEvent->where; - GlobalToLocal(&mouse); - MsgClick(GetNhWin(theWindow), mouse); - macClickText(theEvent, theWindow); + GlobalToLocal(&mouse); + MsgClick(GetNhWin(theWindow), mouse); + macClickText(theEvent, theWindow); } - static short -macUpdateMessage (EventRecord *theEvent, WindowPtr theWindow) +macUpdateMessage(EventRecord *theEvent, WindowPtr theWindow) { - if (!theEvent) - return 0; - MsgUpdate(GetNhWin(theWindow)); - return 0; + if (!theEvent) + return 0; + MsgUpdate(GetNhWin(theWindow)); + return 0; } -#endif /* !TARGET_API_MAC_CARBON */ - - +#endif /* !TARGET_API_MAC_CARBON */ /********************************************************************** * Menu windows @@ -2550,131 +2577,127 @@ macUpdateMessage (EventRecord *theEvent, WindowPtr theWindow) static void MenwKey(NhWindow *wind, char ch) { - MacMHMenuItem *mi; - int i; + MacMHMenuItem *mi; + int i; + ch = filter_scroll_key(ch, wind); + if (!ch) + return; + if (ClosingWindowChar(ch)) { + AddToKeyQueue(CHAR_CR, 1); + return; + } - ch = filter_scroll_key(ch, wind); - if (!ch) - return; - if (ClosingWindowChar(ch)) { - AddToKeyQueue(CHAR_CR, 1); - return; - } - - if (!wind || !wind->menuInfo) - return; - HLock((char**)wind->menuInfo); - for (i = 0, mi = *wind->menuInfo; i < wind->miLen; i++, mi++) { - if (mi->accelerator == ch) { - ToggleMenuListItemSelected (wind, i); - if (mi->line >= wind->scrollPos && mi->line <= wind->y_size) { - SetPortWindowPort(wind->its_window); - ToggleMenuSelect(wind, mi->line - wind->scrollPos); - } - /* Dismiss window if only picking one item */ - if (wind->how != PICK_ANY) - AddToKeyQueue(CHAR_CR, 1); - break; - } - } - HUnlock ((char**)wind->menuInfo); - /* add key if didn't find it in menu and not filtered */ - return; + if (!wind || !wind->menuInfo) + return; + HLock((char **) wind->menuInfo); + for (i = 0, mi = *wind->menuInfo; i < wind->miLen; i++, mi++) { + if (mi->accelerator == ch) { + ToggleMenuListItemSelected(wind, i); + if (mi->line >= wind->scrollPos && mi->line <= wind->y_size) { + SetPortWindowPort(wind->its_window); + ToggleMenuSelect(wind, mi->line - wind->scrollPos); + } + /* Dismiss window if only picking one item */ + if (wind->how != PICK_ANY) + AddToKeyQueue(CHAR_CR, 1); + break; + } + } + HUnlock((char **) wind->menuInfo); + /* add key if didn't find it in menu and not filtered */ + return; } - static void MenwClick(NhWindow *wind, Point pt) { - Rect wrect; + Rect wrect; + GetWindowBounds(wind->its_window, kWindowContentRgn, &wrect); + OffsetRect(&wrect, -wrect.left, -wrect.top); + if (inSelect != WIN_ERR && wind->how != PICK_NONE) { + short currentRow = -1, previousRow = -1; + short previousItem = -1, item = -1; + Boolean majorSelectState, firstRow = TRUE; - GetWindowBounds(wind->its_window, kWindowContentRgn, &wrect); - OffsetRect(&wrect, -wrect.left, -wrect.top); - if (inSelect != WIN_ERR && wind->how != PICK_NONE) { - short currentRow = -1, previousRow = -1; - short previousItem = -1, item = -1; - Boolean majorSelectState, firstRow = TRUE; - - do { + do { #if !TARGET_API_MAC_CARBON - SystemTask (); + SystemTask(); #endif - GetMouse (&pt); - currentRow = pt.v / wind->row_height; - if (pt.h < wrect.left || pt.h > wrect.right || - pt.v < 0 || pt.v > wrect.bottom || currentRow >= wind->y_size) { - continue; /* not in window range */ - } + GetMouse(&pt); + currentRow = pt.v / wind->row_height; + if (pt.h < wrect.left || pt.h > wrect.right || pt.v < 0 + || pt.v > wrect.bottom || currentRow >= wind->y_size) { + continue; /* not in window range */ + } - item = ListCoordinateToItem(wind, currentRow); + item = ListCoordinateToItem(wind, currentRow); - if (item != previousItem) { - /* Implement typical Mac multiple-selection behavior - * (ie, not the UI implemented by the Finder) - */ - Boolean itemIsSelected = (ListItemSelected(wind,item) >= 0); + if (item != previousItem) { + /* Implement typical Mac multiple-selection behavior + * (ie, not the UI implemented by the Finder) + */ + Boolean itemIsSelected = (ListItemSelected(wind, item) >= 0); - if (firstRow) { - /* this is first valid row, so major state is opposite of what this row is */ - majorSelectState = !itemIsSelected; - firstRow = FALSE; - } + if (firstRow) { + /* this is first valid row, so major state is opposite of + * what this row is */ + majorSelectState = !itemIsSelected; + firstRow = FALSE; + } - if (wind->how == PICK_ONE && previousItem != -1) { - /* if previous row was selected and we're only selecting one object, - * deselect previous row! - */ - ToggleMenuListItemSelected(wind, previousItem); - ToggleMenuSelect(wind, previousRow); - previousItem = -1; - } + if (wind->how == PICK_ONE && previousItem != -1) { + /* if previous row was selected and we're only selecting + * one object, + * deselect previous row! + */ + ToggleMenuListItemSelected(wind, previousItem); + ToggleMenuSelect(wind, previousRow); + previousItem = -1; + } - if (item == -1) - continue; /* header line */ - - if (majorSelectState != itemIsSelected) { - ToggleMenuListItemSelected(wind, item); - ToggleMenuSelect(wind, currentRow); - } + if (item == -1) + continue; /* header line */ - previousRow = currentRow; - previousItem = item; - } - } while (StillDown()); + if (majorSelectState != itemIsSelected) { + ToggleMenuListItemSelected(wind, item); + ToggleMenuSelect(wind, currentRow); + } - /* Dismiss window if only picking one item */ - if (wind->how == PICK_ONE) - AddToKeyQueue(CHAR_CR, 1); - } - return; + previousRow = currentRow; + previousItem = item; + } + } while (StillDown()); + + /* Dismiss window if only picking one item */ + if (wind->how == PICK_ONE) + AddToKeyQueue(CHAR_CR, 1); + } + return; } - static void MenwUpdate(NhWindow *wind) { - int i, line; - MacMHMenuItem *mi; + int i, line; + MacMHMenuItem *mi; - - TextUpdate(wind); - HLock((Handle) wind->menuInfo); - HLock((Handle) wind->menuSelected); - for (i = 0; i < wind->miSelLen; i++) { - mi = &(*wind->menuInfo)[(*wind->menuSelected)[i]]; - line = mi->line; - if (line > wind->scrollPos && line <= wind->y_size) - ToggleMenuSelect(wind, line - wind->scrollPos); - } - HUnlock((Handle) wind->menuInfo); - HUnlock((Handle) wind->menuSelected); - return; + TextUpdate(wind); + HLock((Handle) wind->menuInfo); + HLock((Handle) wind->menuSelected); + for (i = 0; i < wind->miSelLen; i++) { + mi = &(*wind->menuInfo)[(*wind->menuSelected)[i]]; + line = mi->line; + if (line > wind->scrollPos && line <= wind->y_size) + ToggleMenuSelect(wind, line - wind->scrollPos); + } + HUnlock((Handle) wind->menuInfo); + HUnlock((Handle) wind->menuSelected); + return; } - -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static pascal OSStatus MenwEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) { @@ -2743,47 +2766,44 @@ MenwEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) return (eventNotHandledErr); } - #else static void -macKeyMenu (EventRecord *theEvent, WindowPtr theWindow) { - MenwKey(GetNhWin(theWindow), theEvent->message & 0xff); - return; +macKeyMenu(EventRecord *theEvent, WindowPtr theWindow) +{ + MenwKey(GetNhWin(theWindow), theEvent->message & 0xff); + return; } - static void -macClickMenu (EventRecord *theEvent, WindowRef theWindow) { - Point p; - NhWindow *aWin = GetNhWin(theWindow); +macClickMenu(EventRecord *theEvent, WindowRef theWindow) +{ + Point p; + NhWindow *aWin = GetNhWin(theWindow); + if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) { + short code; + ControlHandle theBar; - if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) { - short code; - ControlHandle theBar; - - p = theEvent->where; - GlobalToLocal (&p); - code = FindControl (p, theWindow, &theBar); - if (code) { - DoScrollBar (p, code, theBar, aWin); - return; - } - } - MenwClick(aWin, theEvent->where); + p = theEvent->where; + GlobalToLocal(&p); + code = FindControl(p, theWindow, &theBar); + if (code) { + DoScrollBar(p, code, theBar, aWin); + return; + } + } + MenwClick(aWin, theEvent->where); } - -static short -macUpdateMenu (EventRecord *theEvent, WindowPtr theWindow) { - MenwUpdate(GetNhWin(theWindow)); - return 0; +static short +macUpdateMenu(EventRecord *theEvent, WindowPtr theWindow) +{ + MenwUpdate(GetNhWin(theWindow)); + return 0; } -#endif /* !TARGET_API_MAC_CARBON */ - - +#endif /* !TARGET_API_MAC_CARBON */ /********************************************************************** * Text windows @@ -2792,67 +2812,64 @@ macUpdateMenu (EventRecord *theEvent, WindowPtr theWindow) { static void TextKey(NhWindow *wind, char ch) { - ch = filter_scroll_key(ch, wind); - if (!ch) - return; - if (inSelect == WIN_ERR && ClosingWindowChar(ch)) { - HideWindow (wind->its_window); - mac_destroy_nhwindow(wind - theWindows); - } else - AddToKeyQueue(topl_resp_key(ch), TRUE); - return; + ch = filter_scroll_key(ch, wind); + if (!ch) + return; + if (inSelect == WIN_ERR && ClosingWindowChar(ch)) { + HideWindow(wind->its_window); + mac_destroy_nhwindow(wind - theWindows); + } else + AddToKeyQueue(topl_resp_key(ch), TRUE); + return; } - static void TextUpdate(NhWindow *wind) { - Rect r, r2; - RgnHandle h; - Boolean vis; + Rect r, r2; + RgnHandle h; + Boolean vis; + GetWindowBounds(wind->its_window, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + r2 = r; + r2.left = r2.right - SBARWIDTH; + r2.right += 1; + r2.top -= 1; + vis = (r2.bottom > r2.top + 50); - GetWindowBounds(wind->its_window, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - r2 = r; - r2.left = r2.right - SBARWIDTH; - r2.right += 1; - r2.top -= 1; - vis = (r2.bottom > r2.top + 50); + draw_growicon_vert_only(wind->its_window); + DrawControls(wind->its_window); - draw_growicon_vert_only(wind->its_window); - DrawControls(wind->its_window); - - h = (RgnHandle) 0; - if (vis && (h = NewRgn())) { - RgnHandle tmp = NewRgn(); - if (!tmp) { - DisposeRgn(h); - h = (RgnHandle) 0; - } else { - GetClip(h); - RectRgn(tmp, &r2); - DiffRgn(h, tmp, tmp); - SetClip(tmp); - DisposeRgn(tmp); - } - } - if (r.right < MIN_RIGHT) - r.right = MIN_RIGHT; - r.top -= wind->scrollPos * wind->row_height; - r.right -= SBARWIDTH; - HLock(wind->windowText); - TETextBox(*wind->windowText, wind->windowTextLen, &r, teJustLeft); - HUnlock(wind->windowText); - if (h) { - SetClip(h); - DisposeRgn(h); - } - return; + h = (RgnHandle) 0; + if (vis && (h = NewRgn())) { + RgnHandle tmp = NewRgn(); + if (!tmp) { + DisposeRgn(h); + h = (RgnHandle) 0; + } else { + GetClip(h); + RectRgn(tmp, &r2); + DiffRgn(h, tmp, tmp); + SetClip(tmp); + DisposeRgn(tmp); + } + } + if (r.right < MIN_RIGHT) + r.right = MIN_RIGHT; + r.top -= wind->scrollPos * wind->row_height; + r.right -= SBARWIDTH; + HLock(wind->windowText); + TETextBox(*wind->windowText, wind->windowTextLen, &r, teJustLeft); + HUnlock(wind->windowText); + if (h) { + SetClip(h); + DisposeRgn(h); + } + return; } - -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static pascal OSStatus TextEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) { @@ -2906,41 +2923,40 @@ TextEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) return (eventNotHandledErr); } - #else static void -macKeyText (EventRecord *theEvent, WindowPtr theWindow) { - TextKey(GetNhWin(theWindow), theEvent->message & 0xff); - return; +macKeyText(EventRecord *theEvent, WindowPtr theWindow) +{ + TextKey(GetNhWin(theWindow), theEvent->message & 0xff); + return; } static void -macClickText (EventRecord *theEvent, WindowPtr theWindow) { - NhWindow *aWin = GetNhWin (theWindow); +macClickText(EventRecord *theEvent, WindowPtr theWindow) +{ + NhWindow *aWin = GetNhWin(theWindow); - if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) { - short code; - Point p = theEvent->where; - ControlHandle theBar; + if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) { + short code; + Point p = theEvent->where; + ControlHandle theBar; - GlobalToLocal (&p); - code = FindControl (p, theWindow, &theBar); - if (code) { - DoScrollBar (p, code, theBar, aWin); - } - } + GlobalToLocal(&p); + code = FindControl(p, theWindow, &theBar); + if (code) { + DoScrollBar(p, code, theBar, aWin); + } + } } -#endif /* !TARGET_API_MAC_CARBON */ - - +#endif /* !TARGET_API_MAC_CARBON */ /********************************************************************** * Global events */ -#if 0//TARGET_API_MAC_CARBON +#if 0 // TARGET_API_MAC_CARBON static pascal OSStatus GlobalEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) { @@ -2951,176 +2967,174 @@ GlobalEvent(EventHandlerCallRef nexthandler, EventRef event, void *userdata) return (eventNotHandledErr); } - #else static short -macDoNull (EventRecord *theEvent, WindowPtr theWindow) { - return 0; +macDoNull(EventRecord *theEvent, WindowPtr theWindow) +{ + return 0; } - /* * Note; theWindow may very well be null here, since keyDown may call * it when theres no window !!! */ /* NOT_IN_CARBON */ static void -GeneralKey (EventRecord *theEvent, WindowPtr theWindow) { +GeneralKey(EventRecord *theEvent, WindowPtr theWindow) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(theWindow) +#pragma unused(theWindow) #endif #if 0 trans_num_keys (theEvent); #endif - AddToKeyQueue (topl_resp_key (theEvent->message & 0xff), TRUE); + AddToKeyQueue(topl_resp_key(theEvent->message & 0xff), TRUE); } - static void -HandleKey (EventRecord *theEvent) { - WindowPtr theWindow = FrontWindow (); +HandleKey(EventRecord *theEvent) +{ + WindowPtr theWindow = FrontWindow(); - if (theEvent->modifiers & cmdKey) { - if (theEvent->message & 0xff == '.') { - /* Flush key queue */ - keyQueueCount = keyQueueWrite = keyQueueRead = 0; - theEvent->message = '\033'; - goto dispatchKey; - } else { - UndimMenuBar (); - DoMenuEvt (MenuKey (theEvent->message & 0xff)); - } - } else { - -dispatchKey : - if (theWindow) { - int kind = GetWindowKind(theWindow) - WIN_BASE_KIND; - winKeyFuncs [kind] (theEvent, theWindow); - } else { - GeneralKey (theEvent, (WindowPtr) 0); - } - } + if (theEvent->modifiers & cmdKey) { + if (theEvent->message & 0xff == '.') { + /* Flush key queue */ + keyQueueCount = keyQueueWrite = keyQueueRead = 0; + theEvent->message = '\033'; + goto dispatchKey; + } else { + UndimMenuBar(); + DoMenuEvt(MenuKey(theEvent->message & 0xff)); + } + } else { + dispatchKey: + if (theWindow) { + int kind = GetWindowKind(theWindow) - WIN_BASE_KIND; + winKeyFuncs[kind](theEvent, theWindow); + } else { + GeneralKey(theEvent, (WindowPtr) 0); + } + } } - -#endif /* !TARGET_API_MAC_CARBON */ - +#endif /* !TARGET_API_MAC_CARBON */ static void -HandleClick (EventRecord *theEvent) { - int code; - unsigned long l; - WindowPtr theWindow; - NhWindow *aWin; - Rect r; - Boolean not_inSelect; +HandleClick(EventRecord *theEvent) +{ + int code; + unsigned long l; + WindowPtr theWindow; + NhWindow *aWin; + Rect r; + Boolean not_inSelect; - InsetRect(GetRegionBounds(GetGrayRgn(), &r), 4, 4); + InsetRect(GetRegionBounds(GetGrayRgn(), &r), 4, 4); - code = FindWindow (theEvent->where, &theWindow); - aWin = GetNhWin (theWindow); - not_inSelect = (inSelect == WIN_ERR || aWin - theWindows == inSelect); - - switch (code) { - case inContent : -#if 1//!TARGET_API_MAC_CARBON - if (not_inSelect) { - int kind = GetWindowKind(theWindow) - WIN_BASE_KIND; - winCursorFuncs [kind] (theEvent, theWindow, gMouseRgn); - SelectWindow (theWindow); - SetPortWindowPort(theWindow); - winClickFuncs [kind] (theEvent, theWindow); - } else { - nhbell (); - } + code = FindWindow(theEvent->where, &theWindow); + aWin = GetNhWin(theWindow); + not_inSelect = (inSelect == WIN_ERR || aWin - theWindows == inSelect); + + switch (code) { + case inContent: +#if 1 //!TARGET_API_MAC_CARBON + if (not_inSelect) { + int kind = GetWindowKind(theWindow) - WIN_BASE_KIND; + winCursorFuncs[kind](theEvent, theWindow, gMouseRgn); + SelectWindow(theWindow); + SetPortWindowPort(theWindow); + winClickFuncs[kind](theEvent, theWindow); + } else { + nhbell(); + } #endif - break; + break; - case inDrag : - if (not_inSelect) { - SetCursor(&qdarrow); - DragWindow (theWindow, theEvent->where, &r); - SaveWindowPos(theWindow); - } else { - nhbell (); - } - break; + case inDrag: + if (not_inSelect) { + SetCursor(&qdarrow); + DragWindow(theWindow, theEvent->where, &r); + SaveWindowPos(theWindow); + } else { + nhbell(); + } + break; - case inGrow : - if (not_inSelect) { - SetCursor(&qdarrow); - SetRect (&r, 80, 2 * aWin->row_height + 1, r.right, r.bottom); - if (aWin == theWindows + WIN_MESSAGE) - r.top += SBARHEIGHT; - l = GrowWindow (theWindow, theEvent->where, &r); - SizeWindow (theWindow, l & 0xffff, l >> 16, FALSE); - SaveWindowSize(theWindow); - SetPortWindowPort(theWindow); - GetWindowBounds(theWindow, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - InvalWindowRect(theWindow, &r); - if (aWin->scrollBar) { - DrawScrollbar (aWin); - } - } else { - nhbell (); - } - break; + case inGrow: + if (not_inSelect) { + SetCursor(&qdarrow); + SetRect(&r, 80, 2 * aWin->row_height + 1, r.right, r.bottom); + if (aWin == theWindows + WIN_MESSAGE) + r.top += SBARHEIGHT; + l = GrowWindow(theWindow, theEvent->where, &r); + SizeWindow(theWindow, l & 0xffff, l >> 16, FALSE); + SaveWindowSize(theWindow); + SetPortWindowPort(theWindow); + GetWindowBounds(theWindow, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + InvalWindowRect(theWindow, &r); + if (aWin->scrollBar) { + DrawScrollbar(aWin); + } + } else { + nhbell(); + } + break; - case inGoAway : - WindowGoAway(theEvent, theWindow); - break; + case inGoAway: + WindowGoAway(theEvent, theWindow); + break; - case inMenuBar : - DoMenuEvt (MenuSelect (theEvent->where)); - break; + case inMenuBar: + DoMenuEvt(MenuSelect(theEvent->where)); + break; #if !TARGET_API_MAC_CARBON - case inSysWindow : - SystemClick(theEvent, theWindow); + case inSysWindow: + SystemClick(theEvent, theWindow); #endif - default : - break; - } + default: + break; + } } - -#if 1//!TARGET_API_MAC_CARBON +#if 1 //!TARGET_API_MAC_CARBON static short -GeneralUpdate (EventRecord *theEvent, WindowPtr theWindow) { - if (!theEvent) - return 0; - TextUpdate(GetNhWin(theWindow)); - return 0; +GeneralUpdate(EventRecord *theEvent, WindowPtr theWindow) +{ + if (!theEvent) + return 0; + TextUpdate(GetNhWin(theWindow)); + return 0; } #endif - static void -HandleUpdate (EventRecord *theEvent) { - WindowPtr theWindow = (WindowPtr) theEvent->message; - NhWindow *aWin = GetNhWin (theWindow); - Rect r; -#if 1//!TARGET_API_MAC_CARBON - EventRecord fake; +HandleUpdate(EventRecord *theEvent) +{ + WindowPtr theWindow = (WindowPtr) theEvent->message; + NhWindow *aWin = GetNhWin(theWindow); + Rect r; +#if 1 //!TARGET_API_MAC_CARBON + EventRecord fake; #endif + char existing_update_region = FALSE; + Rect rect; - char existing_update_region = FALSE; - Rect rect; - - if (theWindow == _mt_window) { - existing_update_region = (get_invalid_region (theWindow, &rect) == noErr); - } - BeginUpdate (theWindow); - SetPortWindowPort(theWindow); - GetWindowBounds(theWindow, kWindowContentRgn, &r); - OffsetRect(&r, -r.left, -r.top); - EraseRect(&r); -#if 0//TARGET_API_MAC_CARBON + if (theWindow == _mt_window) { + existing_update_region = + (get_invalid_region(theWindow, &rect) == noErr); + } + BeginUpdate(theWindow); + SetPortWindowPort(theWindow); + GetWindowBounds(theWindow, kWindowContentRgn, &r); + OffsetRect(&r, -r.left, -r.top); + EraseRect(&r); +#if 0 // TARGET_API_MAC_CARBON switch (GetWindowKind(theWindow) - WIN_BASE_KIND) { case NHW_BASE: case NHW_MAP: @@ -3138,162 +3152,131 @@ HandleUpdate (EventRecord *theEvent) { break; } #else - winUpdateFuncs[GetWindowKind(theWindow) - WIN_BASE_KIND](&fake, theWindow); + winUpdateFuncs[GetWindowKind(theWindow) - WIN_BASE_KIND](&fake, + theWindow); #endif - if (theWindow == _mt_window && existing_update_region) { - set_invalid_region (theWindow, &rect); - } - aWin->drawn = TRUE; - EndUpdate (theWindow); + if (theWindow == _mt_window && existing_update_region) { + set_invalid_region(theWindow, &rect); + } + aWin->drawn = TRUE; + EndUpdate(theWindow); } - -#if 1//!TARGET_API_MAC_CARBON +#if 1 //!TARGET_API_MAC_CARBON static void -GeneralCursor (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) { +GeneralCursor(EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(theWindow) +#pragma unused(theWindow) #endif - Rect r = {-1, -1, 2, 2}; + Rect r = { -1, -1, 2, 2 }; - SetCursor(&qdarrow); - OffsetRect (&r, theEvent->where.h, theEvent->where.v); - RectRgn (mouseRgn, &r); + SetCursor(&qdarrow); + OffsetRect(&r, theEvent->where.h, theEvent->where.v); + RectRgn(mouseRgn, &r); } - static void -DoOsEvt (EventRecord *theEvent) { - WindowRef win; - short code; +DoOsEvt(EventRecord *theEvent) +{ + WindowRef win; + short code; - if ((theEvent->message & 0xff000000) == 0xfa000000) { - /* Mouse Moved */ + if ((theEvent->message & 0xff000000) == 0xfa000000) { + /* Mouse Moved */ - code = FindWindow (theEvent->where, &win); - if (code != inContent) { - Rect r = {-1, -1, 2, 2}; + code = FindWindow(theEvent->where, &win); + if (code != inContent) { + Rect r = { -1, -1, 2, 2 }; - SetCursor(&qdarrow); - OffsetRect (&r, theEvent->where.h, theEvent->where.v); - RectRgn (gMouseRgn, &r); - } else { -#if 1//!TARGET_API_MAC_CARBON - int kind = GetWindowKind(win) - WIN_BASE_KIND; - if (kind >= 0 && kind <= NHW_TEXT) { - winCursorFuncs [kind] (theEvent, win, gMouseRgn); - } + SetCursor(&qdarrow); + OffsetRect(&r, theEvent->where.h, theEvent->where.v); + RectRgn(gMouseRgn, &r); + } else { +#if 1 //!TARGET_API_MAC_CARBON + int kind = GetWindowKind(win) - WIN_BASE_KIND; + if (kind >= 0 && kind <= NHW_TEXT) { + winCursorFuncs[kind](theEvent, win, gMouseRgn); + } #endif - } - } + } + } } - -#endif /* !TARGET_API_MAC_CARBON */ - +#endif /* !TARGET_API_MAC_CARBON */ void -HandleEvent (EventRecord *theEvent) { - switch (theEvent->what) { -#if 1//!TARGET_API_MAC_CARBON - case autoKey: - case keyDown: - HandleKey(theEvent); - break; +HandleEvent(EventRecord *theEvent) +{ + switch (theEvent->what) { +#if 1 //!TARGET_API_MAC_CARBON + case autoKey: + case keyDown: + HandleKey(theEvent); + break; #endif - case updateEvt: - HandleUpdate(theEvent); - break; - case mouseDown: - HandleClick(theEvent); - break; + case updateEvt: + HandleUpdate(theEvent); + break; + case mouseDown: + HandleClick(theEvent); + break; #if !TARGET_API_MAC_CARBON - case diskEvt: - if ((theEvent->message & 0xffff0000) != 0) { - Point p = {150, 150}; - (void) DIBadMount(p, theEvent->message); - } - break; + case diskEvt: + if ((theEvent->message & 0xffff0000) != 0) { + Point p = { 150, 150 }; + (void) DIBadMount(p, theEvent->message); + } + break; #endif #if !TARGET_API_MAC_CARBON - case osEvt: - DoOsEvt(theEvent); - break; + case osEvt: + DoOsEvt(theEvent); + break; #endif - case kHighLevelEvent: - AEProcessAppleEvent(theEvent); - default: - break; - } + case kHighLevelEvent: + AEProcessAppleEvent(theEvent); + default: + break; + } } - - /********************************************************************** * Interface definition, for windows.c */ struct window_procs mac_procs = { - "mac", - WC_COLOR | WC_HILITE_PET | - WC_FONT_MAP | WC_FONT_MENU | WC_FONT_MESSAGE | WC_FONT_STATUS | WC_FONT_TEXT | - WC_FONTSIZ_MAP | WC_FONTSIZ_MENU | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS | WC_FONTSIZ_TEXT, - 0L, - mac_init_nhwindows, - mac_unimplemented, /* see macmenu.c:mac_askname() for player selection */ - mac_askname, - mac_get_nh_event, - mac_exit_nhwindows, - mac_suspend_nhwindows, - mac_unimplemented, - mac_create_nhwindow, - mac_clear_nhwindow, - mac_display_nhwindow, - mac_destroy_nhwindow, - mac_curs, - mac_putstr, - genl_putmixed, - mac_display_file, - mac_start_menu, - mac_add_menu, - mac_end_menu, - mac_select_menu, - genl_message_menu, - mac_unimplemented, - mac_get_nh_event, - mac_get_nh_event, + "mac", + WC_COLOR | WC_HILITE_PET | WC_FONT_MAP | WC_FONT_MENU | WC_FONT_MESSAGE + | WC_FONT_STATUS | WC_FONT_TEXT | WC_FONTSIZ_MAP | WC_FONTSIZ_MENU + | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS | WC_FONTSIZ_TEXT, + 0L, mac_init_nhwindows, + mac_unimplemented, /* see macmenu.c:mac_askname() for player selection */ + mac_askname, mac_get_nh_event, mac_exit_nhwindows, mac_suspend_nhwindows, + mac_unimplemented, mac_create_nhwindow, mac_clear_nhwindow, + mac_display_nhwindow, mac_destroy_nhwindow, mac_curs, mac_putstr, + genl_putmixed, mac_display_file, mac_start_menu, mac_add_menu, + mac_end_menu, mac_select_menu, genl_message_menu, mac_unimplemented, + mac_get_nh_event, mac_get_nh_event, #ifdef CLIPPING - mac_cliparound, + mac_cliparound, #endif #ifdef POSITIONBAR - donull, + donull, #endif - tty_print_glyph, - tty_raw_print, - tty_raw_print_bold, - mac_nhgetch, - mac_nh_poskey, - tty_nhbell, - mac_doprev_message, - mac_yn_function, - mac_getlin, - mac_get_ext_cmd, - mac_number_pad, - mac_delay_output, + tty_print_glyph, tty_raw_print, tty_raw_print_bold, mac_nhgetch, + mac_nh_poskey, tty_nhbell, mac_doprev_message, mac_yn_function, + mac_getlin, mac_get_ext_cmd, mac_number_pad, mac_delay_output, #ifdef CHANGE_COLOR - tty_change_color, - tty_change_background, - set_tty_font_name, - tty_get_color_string, + tty_change_color, tty_change_background, set_tty_font_name, + tty_get_color_string, #endif -/* other defs that really should go away (they're tty specific) */ - 0, // mac_start_screen, - 0, // mac_end_screen, - genl_outrip, - genl_preference_update, - genl_can_suspend_no, + /* other defs that really should go away (they're tty specific) */ + 0, // mac_start_screen, + 0, // mac_end_screen, + genl_outrip, genl_preference_update, genl_can_suspend_no, }; /*macwin.c*/ diff --git a/sys/mac/mgetline.c b/sys/mac/mgetline.c index 44b6b3318..c06a4d855 100644 --- a/sys/mac/mgetline.c +++ b/sys/mac/mgetline.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mgetline.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mgetline.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 mgetline.c $Date: 2009/05/06 10:49:18 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)getline.c 3.5 1990/22/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -10,38 +10,38 @@ #include "macpopup.h" #include "func_tab.h" -extern int NDECL(extcmd_via_menu); /* cmd.c */ +extern int NDECL(extcmd_via_menu); /* cmd.c */ -typedef Boolean FDECL ((* key_func), (unsigned char)); +typedef Boolean FDECL((*key_func), (unsigned char)); int -get_line_from_key_queue (char * bufp) { - * bufp = 0; - if (try_key_queue (bufp)) { - while (* bufp) { - if (* bufp == 10 || * bufp == 13) { - * bufp = 0; - } - bufp ++; - } - return true; - } - return false; +get_line_from_key_queue(char *bufp) +{ + *bufp = 0; + if (try_key_queue(bufp)) { + while (*bufp) { + if (*bufp == 10 || *bufp == 13) { + *bufp = 0; + } + bufp++; + } + return true; + } + return false; } - static void -topl_getlin(const char *query, char *bufp, Boolean ext) { - if (get_line_from_key_queue (bufp)) - return; +topl_getlin(const char *query, char *bufp, Boolean ext) +{ + if (get_line_from_key_queue(bufp)) + return; - enter_topl_mode((char *) query); - while (topl_key(nhgetch(), ext)) - ; - leave_topl_mode(bufp); + enter_topl_mode((char *) query); + while (topl_key(nhgetch(), ext)) + ; + leave_topl_mode(bufp); } - /* * Read a line closed with '\n' into the array char bufp[BUFSZ]. * (The '\n' is not stored. The string is closed with a '\0'.) @@ -49,28 +49,31 @@ topl_getlin(const char *query, char *bufp, Boolean ext) { * resulting string is "\033". */ void -mac_getlin(const char *query, char *bufp) { - topl_getlin (query, bufp, false); +mac_getlin(const char *query, char *bufp) +{ + topl_getlin(query, bufp, false); } - /* Read in an extended command - doing command line completion for * when enough characters have been entered to make a unique command. * This is just a modified getlin() followed by a lookup. -jsb */ int -mac_get_ext_cmd() { - char bufp[BUFSZ]; - int i; +mac_get_ext_cmd() +{ + char bufp[BUFSZ]; + int i; - if (iflags.extmenu) return extcmd_via_menu(); - topl_getlin("# ", bufp, true); - for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) - if (!strcmp(bufp, extcmdlist[i].ef_txt)) break; - if (extcmdlist[i].ef_txt == (char *)0) i = -1; /* not found */ + if (iflags.extmenu) + return extcmd_via_menu(); + topl_getlin("# ", bufp, true); + for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++) + if (!strcmp(bufp, extcmdlist[i].ef_txt)) + break; + if (extcmdlist[i].ef_txt == (char *) 0) + i = -1; /* not found */ - return i; + return i; } - /* macgetline.c */ diff --git a/sys/mac/mmodal.c b/sys/mac/mmodal.c index 7d2ee6abe..9cabf875f 100644 --- a/sys/mac/mmodal.c +++ b/sys/mac/mmodal.c @@ -1,32 +1,31 @@ -/* NetHack 3.6 mmodal.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mmodal.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 mmodal.c $Date: 2009/05/06 10:49:18 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)mmodal.c 3.5 1993/01/24 */ /* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */ /* NetHack may be freely redistributed. See license for details. */ #if 1 /*!TARGET_API_MAC_CARBON*/ -# include -# include +#include +#include #else -# include +#include #endif #include "macpopup.h" /* Flash a dialog button when its accelerator key is pressed */ void -FlashButton(DialogRef wind, short item) { - short type; - Handle handle; - Rect rect; - unsigned long ticks; +FlashButton(DialogRef wind, short item) +{ + short type; + Handle handle; + Rect rect; + unsigned long ticks; - /* Apple recommends 8 ticks */ - GetDialogItem(wind, item, &type, &handle, &rect); - HiliteControl((ControlHandle)handle, kControlButtonPart); - Delay(8, &ticks); - HiliteControl((ControlHandle)handle, 0); - return; + /* Apple recommends 8 ticks */ + GetDialogItem(wind, item, &type, &handle, &rect); + HiliteControl((ControlHandle) handle, kControlButtonPart); + Delay(8, &ticks); + HiliteControl((ControlHandle) handle, 0); + return; } - - diff --git a/sys/mac/mrecover.c b/sys/mac/mrecover.c index e90e5deed..34e8471b7 100644 --- a/sys/mac/mrecover.c +++ b/sys/mac/mrecover.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mrecover.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mrecover.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 mrecover.c $Date: 2009/05/06 10:49:19 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)mrecover.c 3.5 1996/07/24 */ /* Copyright (c) David Hairston, 1993. */ @@ -24,7 +24,7 @@ * FAR CODE [no], FAR DATA [no], SEPARATE STRS [no], single segment, * short macsbug symbols */ - + /* * To do (maybe, just maybe): * - Merge with the code in util/recover.c. @@ -37,7 +37,6 @@ * - Share AppleEvents with NetHack to auto-recover crashed games. */ - #include "config.h" /**** Toolbox defines ****/ @@ -63,267 +62,239 @@ #include #include -#ifdef THINK /* glue for System 7 Icon Family call (needed by Think C 5.0.4) */ -pascal OSErr GetIconSuite(Handle *theIconSuite, short theResID, long selector) - = {0x303C, 0x0501, 0xABC9}; +#ifdef THINK /* glue for System 7 Icon Family call (needed by Think C 5.0.4) \ + */ +pascal OSErr GetIconSuite(Handle *theIconSuite, short theResID, + long selector) = { 0x303C, 0x0501, 0xABC9 }; #endif - /**** Application defines ****/ /* Memory */ -typedef struct memBytes /* format of 'memB' resource, preloaded/locked */ -{ - short memReserved; - short memCleanup; /* 4 - memory monitor activity limit */ - long memPreempt; /* 32k - start iff FreeMem() > */ - long memWarning; /* 12k - warn if MaxMem() < */ - long memAbort; /* 4k - abort if MaxMem() < */ - long memIOBuf; /* 16k - read/write buffer size */ +typedef struct memBytes /* format of 'memB' resource, preloaded/locked */ + { + short memReserved; + short memCleanup; /* 4 - memory monitor activity limit */ + long memPreempt; /* 32k - start iff FreeMem() > */ + long memWarning; /* 12k - warn if MaxMem() < */ + long memAbort; /* 4k - abort if MaxMem() < */ + long memIOBuf; /* 16k - read/write buffer size */ } memBytes, *memBytesPtr, **memBytesHandle; -#define membID 128 /* 'memB' resource ID */ - +#define membID 128 /* 'memB' resource ID */ /* Cursor */ -#define CURS_FRAME 4L /* 1/15 second - spin cursor */ -#define CURS_LATENT 60L /* pause before spin cursor */ -#define curs_Init (-1) /* token for set arrow */ -#define curs_Total 8 /* maybe 'acur' would be better */ -#define cursorOffset 128 /* GetCursor(cursorOffset + i) */ - +#define CURS_FRAME 4L /* 1/15 second - spin cursor */ +#define CURS_LATENT 60L /* pause before spin cursor */ +#define curs_Init (-1) /* token for set arrow */ +#define curs_Total 8 /* maybe 'acur' would be better */ +#define cursorOffset 128 /* GetCursor(cursorOffset + i) */ /* Menu */ -enum -{ - mbar_Init = -1, - mbarAppl, /* normal mode */ - mbarRecover, /* in recovery mode */ - mbarDA /* DA in front mode */ +enum { + mbar_Init = -1, + mbarAppl, /* normal mode */ + mbarRecover, /* in recovery mode */ + mbarDA /* DA in front mode */ }; -enum -{ - menuApple, - menuFile, - menuEdit, - menu_Total, +enum { + menuApple, + menuFile, + menuEdit, + menu_Total, - muidApple = 128, - muidFile, - muidEdit + muidApple = 128, + muidFile, + muidEdit }; -enum -{ - /* Apple menu */ - mitmAbout = 1, - mitmHelp, - ____128_1, +enum { + /* Apple menu */ + mitmAbout = 1, + mitmHelp, + ____128_1, - /* File menu */ - mitmOpen = 1, - ____129_1, - mitmClose_DA, - ____129_2, - mitmQuit + /* File menu */ + mitmOpen = 1, + ____129_1, + mitmClose_DA, + ____129_2, + mitmQuit - /* standard minimum required Edit menu */ + /* standard minimum required Edit menu */ }; - /* Alerts */ -enum -{ - alrtNote, /* general messages */ - alrtHelp, /* help message */ - alrt_Total, +enum { + alrtNote, /* general messages */ + alrtHelp, /* help message */ + alrt_Total, - alertAppleMenu = 127, /* menuItem to alert ID offset */ - alidNote, - alidHelp + alertAppleMenu = 127, /* menuItem to alert ID offset */ + alidNote, + alidHelp }; -#define aboutBufSize 80 /* i.e. 2 lines of 320 pixels */ - +#define aboutBufSize 80 /* i.e. 2 lines of 320 pixels */ /* Notification */ -#define nmBufSize (32 + aboutBufSize + 32) -typedef struct notifRec -{ - NMRec nmr; - struct notifRec * nmNext; - short nmDispose; - unsigned char nmBuf[nmBufSize]; +#define nmBufSize (32 + aboutBufSize + 32) +typedef struct notifRec { + NMRec nmr; + struct notifRec *nmNext; + short nmDispose; + unsigned char nmBuf[nmBufSize]; } notifRec, *notifPtr; -#define nmPending nmRefCon /* &in.Notify */ -#define iconNotifyID 128 -#define ics_1_and_4 0x00000300 +#define nmPending nmRefCon /* &in.Notify */ +#define iconNotifyID 128 +#define ics_1_and_4 0x00000300 /* Dialogs */ -enum -{ - dlogProgress = 256 -}; -enum -{ - uitmThermo = 1 -}; -enum -{ - initItem, - invalItem, - drawItem -}; - +enum { dlogProgress = 256 }; +enum { uitmThermo = 1 }; +enum { initItem, invalItem, drawItem }; /* Miscellaneous */ -typedef struct modeFlags -{ - short Front; /* fg/bg event handling */ - short Notify; /* level of pending NM notifications */ - short Dialog; /* a modeless dialog is open */ - short Recover; /* restoration progress index */ +typedef struct modeFlags { + short Front; /* fg/bg event handling */ + short Notify; /* level of pending NM notifications */ + short Dialog; /* a modeless dialog is open */ + short Recover; /* restoration progress index */ } modeFlags; /* convenient define to allow easier (for me) parsing of 'vers' resource */ -typedef struct versXRec -{ - NumVersion numVers; - short placeCode; - unsigned char versStr[]; /* (small string)(large string) */ +typedef struct versXRec { + NumVersion numVers; + short placeCode; + unsigned char versStr[]; /* (small string)(large string) */ } versXRec, *versXPtr, **versXHandle; - - /**** Global variables ****/ -modeFlags in = {1}; /* in Front */ -EventRecord wnEvt; -SysEnvRec sysEnv; -unsigned char aboutBuf[aboutBufSize]; /* vers 1 "Get Info" string */ -memBytesPtr pBytes; /* memory management */ -unsigned short memActivity; /* more memory management */ -MenuHandle mHnd[menu_Total]; -CursPtr cPtr[curs_Total]; /* busy cursors */ -unsigned long timeCursor; /* next cursor frame time */ -short oldCursor = curs_Init; /* see adjustGUI() below */ -notifPtr pNMQ; /* notification queue pointer */ -notifRec nmt; /* notification template */ -DialogTHndl thermoTHnd; -DialogRecord dlgThermo; /* progress thermometer */ -#define DLGTHM ((DialogPtr) &dlgThermo) -#define WNDTHM ((WindowPtr) &dlgThermo) -#define GRFTHM ((GrafPtr) &dlgThermo) +modeFlags in = { 1 }; /* in Front */ +EventRecord wnEvt; +SysEnvRec sysEnv; +unsigned char aboutBuf[aboutBufSize]; /* vers 1 "Get Info" string */ +memBytesPtr pBytes; /* memory management */ +unsigned short memActivity; /* more memory management */ +MenuHandle mHnd[menu_Total]; +CursPtr cPtr[curs_Total]; /* busy cursors */ +unsigned long timeCursor; /* next cursor frame time */ +short oldCursor = curs_Init; /* see adjustGUI() below */ +notifPtr pNMQ; /* notification queue pointer */ +notifRec nmt; /* notification template */ +DialogTHndl thermoTHnd; +DialogRecord dlgThermo; /* progress thermometer */ +#define DLGTHM ((DialogPtr) &dlgThermo) +#define WNDTHM ((WindowPtr) &dlgThermo) +#define GRFTHM ((GrafPtr) &dlgThermo) -Point sfGetWhere; /* top left corner of get file dialog */ -Ptr pIOBuf; /* read/write buffer pointer */ -short vRefNum; /* SFGetFile working directory/volume refnum */ -long dirID; /* directory i.d. */ -NMUPP nmCompletionUPP; /* UPP for nmCompletion */ -FileFilterUPP basenameFileFilterUPP; /* UPP for basenameFileFilter */ -UserItemUPP drawThermoUPP; /* UPP for progress callback */ +Point sfGetWhere; /* top left corner of get file dialog */ +Ptr pIOBuf; /* read/write buffer pointer */ +short vRefNum; /* SFGetFile working directory/volume refnum */ +long dirID; /* directory i.d. */ +NMUPP nmCompletionUPP; /* UPP for nmCompletion */ +FileFilterUPP basenameFileFilterUPP; /* UPP for basenameFileFilter */ +UserItemUPP drawThermoUPP; /* UPP for progress callback */ -#define MAX_RECOVER_COUNT 256 +#define MAX_RECOVER_COUNT 256 -#define APP_NAME_RES_ID (-16396) /* macfile.h */ -#define PLAYER_NAME_RES_ID 1001 /* macfile.h */ +#define APP_NAME_RES_ID (-16396) /* macfile.h */ +#define PLAYER_NAME_RES_ID 1001 /* macfile.h */ /* variables from util/recover.c */ -#define SAVESIZE FILENAME -unsigned char savename[SAVESIZE]; /* originally a C string */ -unsigned char lock[256]; /* pascal string */ - -int hpid; /* NetHack (unix-style) process i.d. */ -short saveRefNum; /* save file descriptor */ -short gameRefNum; /* level 0 file descriptor */ -short levRefNum; /* level n file descriptor */ +#define SAVESIZE FILENAME +unsigned char savename[SAVESIZE]; /* originally a C string */ +unsigned char lock[256]; /* pascal string */ +int hpid; /* NetHack (unix-style) process i.d. */ +short saveRefNum; /* save file descriptor */ +short gameRefNum; /* level 0 file descriptor */ +short levRefNum; /* level n file descriptor */ /**** Prototypes ****/ -static void warmup(void); -static Handle alignTemplate(ResType, short, short, short, Point *); -pascal void nmCompletion(NMRec *); -static void noteErrorMessage(unsigned char *, unsigned char *); -static void note(short, short, unsigned char *); -static void adjustGUI(void); -static void adjustMemory(void); -static void optionMemStats(void); -static void RecoverMenuEvent(long); -static void eventLoop(void); -static void cooldown(void); +static void warmup(void); +static Handle alignTemplate(ResType, short, short, short, Point *); +pascal void nmCompletion(NMRec *); +static void noteErrorMessage(unsigned char *, unsigned char *); +static void note(short, short, unsigned char *); +static void adjustGUI(void); +static void adjustMemory(void); +static void optionMemStats(void); +static void RecoverMenuEvent(long); +static void eventLoop(void); +static void cooldown(void); -pascal void drawThermo(WindowPtr, short); -static void itemizeThermo(short); -pascal Boolean basenameFileFilter(ParmBlkPtr); -static void beginRecover(void); -static void continueRecover(void); -static void endRecover(void); -static short saveRezStrings(void); +pascal void drawThermo(WindowPtr, short); +static void itemizeThermo(short); +pascal Boolean basenameFileFilter(ParmBlkPtr); +static void beginRecover(void); +static void continueRecover(void); +static void endRecover(void); +static short saveRezStrings(void); /* analogous prototypes from util/recover.c */ -static void set_levelfile_name(long); -static short open_levelfile(long); -static short create_savefile(unsigned char *); -static void copy_bytes(short, short); -static void restore_savefile(void); +static void set_levelfile_name(long); +static short open_levelfile(long); +static short create_savefile(unsigned char *); +static void copy_bytes(short, short); +static void restore_savefile(void); /* auxiliary prototypes */ -static long read_levelfile(short, Ptr, long); -static long write_savefile(short, Ptr, long); -static void close_file(short *); -static void unlink_file(unsigned char *); - +static long read_levelfile(short, Ptr, long); +static long write_savefile(short, Ptr, long); +static void close_file(short *); +static void unlink_file(unsigned char *); /**** Routines ****/ main() { - /* heap adjust */ - MaxApplZone(); - MoreMasters(); - MoreMasters(); + /* heap adjust */ + MaxApplZone(); + MoreMasters(); + MoreMasters(); - /* manager initialization */ - InitGraf(&qd.thePort); - InitFonts(); - InitWindows(); - InitMenus(); - TEInit(); - InitDialogs(0L); - InitCursor(); - nmCompletionUPP = NewNMProc(nmCompletion); - basenameFileFilterUPP = NewFileFilterProc(basenameFileFilter); - drawThermoUPP = NewUserItemProc(drawThermo); + /* manager initialization */ + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + TEInit(); + InitDialogs(0L); + InitCursor(); + nmCompletionUPP = NewNMProc(nmCompletion); + basenameFileFilterUPP = NewFileFilterProc(basenameFileFilter); + drawThermoUPP = NewUserItemProc(drawThermo); - /* get system environment, notification requires 6.0 or better */ - (void) SysEnvirons(curSysEnvVers, &sysEnv); - if (sysEnv.systemVersion < 0x0600) - { - ParamText("\pAbort: System 6.0 is required", "\p", "\p", "\p"); - (void) Alert(alidNote, (ModalFilterUPP) 0L); - ExitToShell(); - } + /* get system environment, notification requires 6.0 or better */ + (void) SysEnvirons(curSysEnvVers, &sysEnv); + if (sysEnv.systemVersion < 0x0600) { + ParamText("\pAbort: System 6.0 is required", "\p", "\p", "\p"); + (void) Alert(alidNote, (ModalFilterUPP) 0L); + ExitToShell(); + } - warmup(); - eventLoop(); + warmup(); + eventLoop(); - /* normally these routines are never reached from here */ - cooldown(); - ExitToShell(); - return 0; + /* normally these routines are never reached from here */ + cooldown(); + ExitToShell(); + return 0; } static void warmup() { - short i; + short i; - /* pre-System 7 MultiFinder hack for smooth launch */ - for (i = 0; i < 10; i++) - { - if (WaitNextEvent(osMask, &wnEvt, 2L, (RgnHandle) 0L)) - if (((wnEvt.message & osEvtMessageMask) >> 24) == suspendResumeMessage) - in.Front = (wnEvt.message & resumeFlag); - } + /* pre-System 7 MultiFinder hack for smooth launch */ + for (i = 0; i < 10; i++) { + if (WaitNextEvent(osMask, &wnEvt, 2L, (RgnHandle) 0L)) + if (((wnEvt.message & osEvtMessageMask) >> 24) + == suspendResumeMessage) + in.Front = (wnEvt.message & resumeFlag); + } #if 0 // ??? /* clear out the Finder info */ @@ -336,165 +307,161 @@ warmup() } #endif - /* fill out the notification template */ - nmt.nmr.qType = nmType; - nmt.nmr.nmMark = 1; - nmt.nmr.nmSound = (Handle) -1L; /* system beep */ - nmt.nmr.nmStr = nmt.nmBuf; - nmt.nmr.nmResp = nmCompletionUPP; - nmt.nmr.nmPending = (long) &in.Notify; - + /* fill out the notification template */ + nmt.nmr.qType = nmType; + nmt.nmr.nmMark = 1; + nmt.nmr.nmSound = (Handle) -1L; /* system beep */ + nmt.nmr.nmStr = nmt.nmBuf; + nmt.nmr.nmResp = nmCompletionUPP; + nmt.nmr.nmPending = (long) &in.Notify; #if 1 - { - /* get the app name */ - ProcessInfoRec info; - ProcessSerialNumber psn; + { + /* get the app name */ + ProcessInfoRec info; + ProcessSerialNumber psn; - info.processInfoLength = sizeof(info); - info.processName = nmt.nmBuf; - info.processAppSpec = NULL; - GetCurrentProcess(&psn); - GetProcessInformation(&psn, &info); - } + info.processInfoLength = sizeof(info); + info.processName = nmt.nmBuf; + info.processAppSpec = NULL; + GetCurrentProcess(&psn); + GetProcessInformation(&psn, &info); + } #else - /* prepend app name (31 chars or less) to notification buffer */ - { - short apRefNum; - Handle apParams; + /* prepend app name (31 chars or less) to notification buffer */ + { + short apRefNum; + Handle apParams; - GetAppParms(* (Str255 *) &nmt.nmBuf, &apRefNum, &apParams); - } + GetAppParms(*(Str255 *) &nmt.nmBuf, &apRefNum, &apParams); + } #endif - /* add formatting (two line returns) */ - nmt.nmBuf[++(nmt.nmBuf[0])] = '\r'; - nmt.nmBuf[++(nmt.nmBuf[0])] = '\r'; + /* add formatting (two line returns) */ + nmt.nmBuf[++(nmt.nmBuf[0])] = '\r'; + nmt.nmBuf[++(nmt.nmBuf[0])] = '\r'; - /**** note() is usable now but not aesthetically complete ****/ + /**** note() is usable now but not aesthetically complete ****/ - /* get notification icon */ - if (sysEnv.systemVersion < 0x0700) - { - if (! (nmt.nmr.nmIcon = GetResource('SICN', iconNotifyID))) - note(nilHandleErr, 0, "\pNil SICN Handle"); - } - else - { - if (GetIconSuite(&nmt.nmr.nmIcon, iconNotifyID, ics_1_and_4)) - note(nilHandleErr, 0, "\pBad Icon Family"); - } + /* get notification icon */ + if (sysEnv.systemVersion < 0x0700) { + if (!(nmt.nmr.nmIcon = GetResource('SICN', iconNotifyID))) + note(nilHandleErr, 0, "\pNil SICN Handle"); + } else { + if (GetIconSuite(&nmt.nmr.nmIcon, iconNotifyID, ics_1_and_4)) + note(nilHandleErr, 0, "\pBad Icon Family"); + } - /* load and align various dialog/alert templates */ - (void) alignTemplate('ALRT', alidNote, 0, 4, (Point *) 0L); - (void) alignTemplate('ALRT', alidHelp, 0, 4, (Point *) 0L); + /* load and align various dialog/alert templates */ + (void) alignTemplate('ALRT', alidNote, 0, 4, (Point *) 0L); + (void) alignTemplate('ALRT', alidHelp, 0, 4, (Point *) 0L); - thermoTHnd = (DialogTHndl) alignTemplate('DLOG', dlogProgress, 20, 8, (Point *) 0L); + thermoTHnd = (DialogTHndl) alignTemplate('DLOG', dlogProgress, 20, 8, + (Point *) 0L); - (void) alignTemplate('DLOG', getDlgID, 0, 6, (Point *) &sfGetWhere); + (void) alignTemplate('DLOG', getDlgID, 0, 6, (Point *) &sfGetWhere); - /* get the "busy cursors" (preloaded/locked) */ - for (i = 0; i < curs_Total; i++) - { - CursHandle cHnd; + /* get the "busy cursors" (preloaded/locked) */ + for (i = 0; i < curs_Total; i++) { + CursHandle cHnd; - if (! (cHnd = GetCursor(i + cursorOffset))) - note(nilHandleErr, 0, "\pNil CURS Handle"); + if (!(cHnd = GetCursor(i + cursorOffset))) + note(nilHandleErr, 0, "\pNil CURS Handle"); - cPtr[i] = *cHnd; - } + cPtr[i] = *cHnd; + } - /* get the 'vers' 1 long (Get Info) string - About Recover... */ - { - versXHandle vHnd; + /* get the 'vers' 1 long (Get Info) string - About Recover... */ + { + versXHandle vHnd; - if (! (vHnd = (versXHandle) GetResource('vers', 1))) - note(nilHandleErr, 0, "\pNil vers Handle"); + if (!(vHnd = (versXHandle) GetResource('vers', 1))) + note(nilHandleErr, 0, "\pNil vers Handle"); - i = (**vHnd).versStr[0] + 1; /* offset to Get Info pascal string */ + i = (**vHnd).versStr[0] + 1; /* offset to Get Info pascal string */ - if ((aboutBuf[0] = (**vHnd).versStr[i]) > (aboutBufSize - 1)) - aboutBuf[0] = aboutBufSize - 1; + if ((aboutBuf[0] = (**vHnd).versStr[i]) > (aboutBufSize - 1)) + aboutBuf[0] = aboutBufSize - 1; - i++; + i++; - MoveHHi((Handle) vHnd); /* DEE - Fense ... */ - HLock((Handle) vHnd); - BlockMove(&((**vHnd).versStr[i]), &(aboutBuf[1]), aboutBuf[0]); - ReleaseResource((Handle) vHnd); - } + MoveHHi((Handle) vHnd); /* DEE - Fense ... */ + HLock((Handle) vHnd); + BlockMove(&((**vHnd).versStr[i]), &(aboutBuf[1]), aboutBuf[0]); + ReleaseResource((Handle) vHnd); + } - /* form the menubar */ - for (i = 0; i < menu_Total; i++) - { - if (! (mHnd[i] = GetMenu(i + muidApple))) - note(nilHandleErr, 0, "\pNil MENU Handle"); + /* form the menubar */ + for (i = 0; i < menu_Total; i++) { + if (!(mHnd[i] = GetMenu(i + muidApple))) + note(nilHandleErr, 0, "\pNil MENU Handle"); - /* expand the apple menu */ - if (i == menuApple) - AddResMenu(mHnd[menuApple], 'DRVR'); + /* expand the apple menu */ + if (i == menuApple) + AddResMenu(mHnd[menuApple], 'DRVR'); - InsertMenu(mHnd[i], 0); - } + InsertMenu(mHnd[i], 0); + } - /* pre-emptive memory check */ - { - memBytesHandle hBytes; - Size grow; + /* pre-emptive memory check */ + { + memBytesHandle hBytes; + Size grow; - if (! (hBytes = (memBytesHandle) GetResource('memB', membID))) - note(nilHandleErr, 0, "\pNil Memory Handle"); + if (!(hBytes = (memBytesHandle) GetResource('memB', membID))) + note(nilHandleErr, 0, "\pNil Memory Handle"); - pBytes = *hBytes; + pBytes = *hBytes; - if (MaxMem(&grow) < pBytes->memPreempt) - note(memFullErr, 0, "\pMore Memory Required\rTry adding 16k"); + if (MaxMem(&grow) < pBytes->memPreempt) + note(memFullErr, 0, "\pMore Memory Required\rTry adding 16k"); - memActivity = pBytes->memCleanup; /* force initial cleanup */ - } + memActivity = pBytes->memCleanup; /* force initial cleanup */ + } - /* get the I/O buffer */ - if (! (pIOBuf = NewPtr(pBytes->memIOBuf))) - note(memFullErr, 0, "\pNil I/O Pointer"); + /* get the I/O buffer */ + if (!(pIOBuf = NewPtr(pBytes->memIOBuf))) + note(memFullErr, 0, "\pNil I/O Pointer"); } /* align a window-related template to the main screen */ static Handle -alignTemplate(ResType rezType, short rezID, short vOff, short vDenom, Point *pPt) +alignTemplate(ResType rezType, short rezID, short vOff, short vDenom, + Point *pPt) { - Handle rtnHnd; - Rect *pRct; + Handle rtnHnd; + Rect *pRct; - vOff += GetMBarHeight(); + vOff += GetMBarHeight(); - if (! (rtnHnd = GetResource(rezType, rezID))) - note(nilHandleErr, 0, "\pNil Template Handle"); + if (!(rtnHnd = GetResource(rezType, rezID))) + note(nilHandleErr, 0, "\pNil Template Handle"); - pRct = (Rect *) *rtnHnd; + pRct = (Rect *) *rtnHnd; - /* don't move memory while aligning rect */ - pRct->right -= pRct->left; /* width */ - pRct->bottom -= pRct->top; /* height */ - pRct->left = (qd.screenBits.bounds.right - pRct->right) / 2; - pRct->top = (qd.screenBits.bounds.bottom - pRct->bottom - vOff) / vDenom; - pRct->top += vOff; - pRct->right += pRct->left; - pRct->bottom += pRct->top; + /* don't move memory while aligning rect */ + pRct->right -= pRct->left; /* width */ + pRct->bottom -= pRct->top; /* height */ + pRct->left = (qd.screenBits.bounds.right - pRct->right) / 2; + pRct->top = (qd.screenBits.bounds.bottom - pRct->bottom - vOff) / vDenom; + pRct->top += vOff; + pRct->right += pRct->left; + pRct->bottom += pRct->top; - if (pPt) - *pPt = * (Point *) pRct; /* top left corner */ + if (pPt) + *pPt = *(Point *) pRct; /* top left corner */ - return rtnHnd; + return rtnHnd; } /* notification completion routine */ pascal void -nmCompletion(NMRec * pNMR) +nmCompletion(NMRec *pNMR) { - (void) NMRemove(pNMR); + (void) NMRemove(pNMR); - (* (short *) (pNMR->nmPending))--; /* decrement pending note level */ - ((notifPtr) pNMR)->nmDispose = 1; /* allow DisposPtr() */ + (*(short *) (pNMR->nmPending))--; /* decrement pending note level */ + ((notifPtr) pNMR)->nmDispose = 1; /* allow DisposPtr() */ } /* @@ -504,13 +471,13 @@ nmCompletion(NMRec * pNMR) static void noteErrorMessage(unsigned char *msg, unsigned char *errMsg) { - short i = nmt.nmBuf[0] + 1; /* insertion point */ + short i = nmt.nmBuf[0] + 1; /* insertion point */ - BlockMove(&msg[1], &nmt.nmBuf[i], msg[0]); - nmt.nmBuf[i + msg[0]] = '\r'; - nmt.nmBuf[0] += (msg[0] + 1); + BlockMove(&msg[1], &nmt.nmBuf[i], msg[0]); + nmt.nmBuf[i + msg[0]] = '\r'; + nmt.nmBuf[0] += (msg[0] + 1); - note(memFullErr, 0, errMsg); + note(memFullErr, 0, errMsg); } /* @@ -521,901 +488,853 @@ noteErrorMessage(unsigned char *msg, unsigned char *errMsg) static void note(short errorSignal, short alertID, unsigned char *msg) { - if (! errorSignal) - { - Size grow; + if (!errorSignal) { + Size grow; - if (MaxMem(&grow) < pBytes->memAbort) - noteErrorMessage(msg, "\pOut of Memory"); - } + if (MaxMem(&grow) < pBytes->memAbort) + noteErrorMessage(msg, "\pOut of Memory"); + } - if (errorSignal || !in.Front) - { - notifPtr pNMR; - short i = nmt.nmBuf[0] + 1; /* insertion point */ + if (errorSignal || !in.Front) { + notifPtr pNMR; + short i = nmt.nmBuf[0] + 1; /* insertion point */ - if (errorSignal) /* use notification template */ - { - pNMR = &nmt; + if (errorSignal) /* use notification template */ + { + pNMR = &nmt; - /* we're going to abort so add in this prefix */ - BlockMove("Abort: ", &nmt.nmBuf[i], 7); - i += 7; - nmt.nmBuf[0] += 7; - } - else /* allocate a notification record */ - { - if (! (pNMR = (notifPtr) NewPtr(sizeof(notifRec)))) - noteErrorMessage(msg, "\pNil New Pointer"); + /* we're going to abort so add in this prefix */ + BlockMove("Abort: ", &nmt.nmBuf[i], 7); + i += 7; + nmt.nmBuf[0] += 7; + } else /* allocate a notification record */ + { + if (!(pNMR = (notifPtr) NewPtr(sizeof(notifRec)))) + noteErrorMessage(msg, "\pNil New Pointer"); - /* initialize it */ - *pNMR = nmt; - pNMR->nmr.nmStr = (StringPtr) &(pNMR->nmBuf); + /* initialize it */ + *pNMR = nmt; + pNMR->nmr.nmStr = (StringPtr) & (pNMR->nmBuf); - /* update the notification queue */ - if (!pNMQ) - pNMQ = pNMR; - else - { - notifPtr pNMX; + /* update the notification queue */ + if (!pNMQ) + pNMQ = pNMR; + else { + notifPtr pNMX; - /* find the end of the queue */ - for (pNMX = pNMQ; pNMX->nmNext; pNMX = pNMX->nmNext) - ; + /* find the end of the queue */ + for (pNMX = pNMQ; pNMX->nmNext; pNMX = pNMX->nmNext) + ; - pNMX->nmNext = pNMR; - } - } + pNMX->nmNext = pNMR; + } + } - /* concatenate the message */ - BlockMove(&msg[1], &((pNMR->nmBuf)[i]), msg[0]); - (pNMR->nmBuf)[0] += msg[0]; + /* concatenate the message */ + BlockMove(&msg[1], &((pNMR->nmBuf)[i]), msg[0]); + (pNMR->nmBuf)[0] += msg[0]; - in.Notify++; /* increase note pending level */ + in.Notify++; /* increase note pending level */ - NMInstall((NMRec *) pNMR); + NMInstall((NMRec *) pNMR); - if (errorSignal) - cooldown(); + if (errorSignal) + cooldown(); - return; - } + return; + } - /* in front and no error so use an alert */ - ParamText(msg, "\p", "\p", "\p"); - (void) Alert(alertID, (ModalFilterUPP) 0L); - ResetAlrtStage(); + /* in front and no error so use an alert */ + ParamText(msg, "\p", "\p", "\p"); + (void) Alert(alertID, (ModalFilterUPP) 0L); + ResetAlrtStage(); - memActivity++; + memActivity++; } static void adjustGUI() { - static short oldMenubar = mbar_Init; /* force initial update */ - short newMenubar; - WindowPeek frontWindow; + static short oldMenubar = mbar_Init; /* force initial update */ + short newMenubar; + WindowPeek frontWindow; - /* oldCursor is external so it can be reset in endRecover() */ - static short newCursor = curs_Init; - unsigned long timeNow; - short useArrow; + /* oldCursor is external so it can be reset in endRecover() */ + static short newCursor = curs_Init; + unsigned long timeNow; + short useArrow; - /* adjust menubar 1st */ - newMenubar = in.Recover ? mbarRecover : mbarAppl; + /* adjust menubar 1st */ + newMenubar = in.Recover ? mbarRecover : mbarAppl; - /* desk accessories take precedence */ - if (frontWindow = (WindowPeek) FrontWindow()) - if (frontWindow->windowKind < 0) - newMenubar = mbarDA; + /* desk accessories take precedence */ + if (frontWindow = (WindowPeek) FrontWindow()) + if (frontWindow->windowKind < 0) + newMenubar = mbarDA; - if (newMenubar != oldMenubar) - { - /* adjust menus */ - switch (oldMenubar = newMenubar) - { - case mbarAppl: - EnableItem(mHnd[menuFile], mitmOpen); - SetItemMark(mHnd[menuFile], mitmOpen, noMark); - DisableItem(mHnd[menuFile], mitmClose_DA); - DisableItem(mHnd[menuEdit], 0); - break; + if (newMenubar != oldMenubar) { + /* adjust menus */ + switch (oldMenubar = newMenubar) { + case mbarAppl: + EnableItem(mHnd[menuFile], mitmOpen); + SetItemMark(mHnd[menuFile], mitmOpen, noMark); + DisableItem(mHnd[menuFile], mitmClose_DA); + DisableItem(mHnd[menuEdit], 0); + break; - case mbarRecover: - DisableItem(mHnd[menuFile], mitmOpen); - SetItemMark(mHnd[menuFile], mitmOpen, checkMark); - DisableItem(mHnd[menuFile], mitmClose_DA); - DisableItem(mHnd[menuEdit], 0); - break; + case mbarRecover: + DisableItem(mHnd[menuFile], mitmOpen); + SetItemMark(mHnd[menuFile], mitmOpen, checkMark); + DisableItem(mHnd[menuFile], mitmClose_DA); + DisableItem(mHnd[menuEdit], 0); + break; - case mbarDA: - DisableItem(mHnd[menuFile], mitmOpen); - EnableItem(mHnd[menuFile], mitmClose_DA); - EnableItem(mHnd[menuEdit], 0); - break; - } + case mbarDA: + DisableItem(mHnd[menuFile], mitmOpen); + EnableItem(mHnd[menuFile], mitmClose_DA); + EnableItem(mHnd[menuEdit], 0); + break; + } - DrawMenuBar(); - } + DrawMenuBar(); + } - /* now adjust the cursor */ - if (useArrow = (!in.Recover || (newMenubar == mbarDA))) - newCursor = curs_Init; - else if ((timeNow = TickCount()) >= timeCursor) /* spin cursor */ - { - timeCursor = timeNow + CURS_FRAME; - if (++newCursor >= curs_Total) - newCursor = 0; - } + /* now adjust the cursor */ + if (useArrow = (!in.Recover || (newMenubar == mbarDA))) + newCursor = curs_Init; + else if ((timeNow = TickCount()) >= timeCursor) /* spin cursor */ + { + timeCursor = timeNow + CURS_FRAME; + if (++newCursor >= curs_Total) + newCursor = 0; + } - if (newCursor != oldCursor) - { - oldCursor = newCursor; + if (newCursor != oldCursor) { + oldCursor = newCursor; - SetCursor(useArrow ? &qd.arrow : cPtr[newCursor]); - } + SetCursor(useArrow ? &qd.arrow : cPtr[newCursor]); + } } static void adjustMemory() { - Size grow; + Size grow; - memActivity = 0; + memActivity = 0; - if (MaxMem(&grow) < pBytes->memWarning) - note(noErr, alidNote, "\pWarning: Memory is running low"); + if (MaxMem(&grow) < pBytes->memWarning) + note(noErr, alidNote, "\pWarning: Memory is running low"); - (void) ResrvMem((Size) FreeMem()); /* move all handles high */ + (void) ResrvMem((Size) FreeMem()); /* move all handles high */ } /* show memory stats: FreeMem, MaxBlock, PurgeSpace, and StackSpace */ static void optionMemStats() { - unsigned char *pFormat = "\pFree:#k Max:#k Purge:#k Stack:#k"; - char *pSub = "#"; /* not a pascal string */ - unsigned char nBuf[16]; - long nStat, contig; - Handle strHnd; - long nOffset; - short i; + unsigned char *pFormat = "\pFree:#k Max:#k Purge:#k Stack:#k"; + char *pSub = "#"; /* not a pascal string */ + unsigned char nBuf[16]; + long nStat, contig; + Handle strHnd; + long nOffset; + short i; - if (wnEvt.modifiers & shiftKey) - adjustMemory(); + if (wnEvt.modifiers & shiftKey) + adjustMemory(); - if (! (strHnd = NewHandle((Size) 128))) - { - note(noErr, alidNote, "\pOops: Memory stats unavailable!"); - return; - } - - SetString((StringHandle) strHnd, pFormat); - nOffset = 1L; + if (!(strHnd = NewHandle((Size) 128))) { + note(noErr, alidNote, "\pOops: Memory stats unavailable!"); + return; + } - for (i = 1; i <= 4; i++) - { - /* get the replacement number stat */ - switch (i) - { - case 1: nStat = FreeMem(); break; - case 2: nStat = MaxBlock(); break; - case 3: PurgeSpace(&nStat, &contig); break; - case 4: nStat = StackSpace(); break; - } + SetString((StringHandle) strHnd, pFormat); + nOffset = 1L; - NumToString((nStat >> 10), * (Str255 *) &nBuf); + for (i = 1; i <= 4; i++) { + /* get the replacement number stat */ + switch (i) { + case 1: + nStat = FreeMem(); + break; + case 2: + nStat = MaxBlock(); + break; + case 3: + PurgeSpace(&nStat, &contig); + break; + case 4: + nStat = StackSpace(); + break; + } - **strHnd += nBuf[0] - 1; - nOffset = Munger(strHnd, nOffset, (Ptr) pSub, 1L, (Ptr) &nBuf[1], nBuf[0]); - } + NumToString((nStat >> 10), *(Str255 *) &nBuf); - MoveHHi(strHnd); - HLock(strHnd); - note(noErr, alidNote, (unsigned char *) *strHnd); - DisposHandle(strHnd); + **strHnd += nBuf[0] - 1; + nOffset = + Munger(strHnd, nOffset, (Ptr) pSub, 1L, (Ptr) &nBuf[1], nBuf[0]); + } + + MoveHHi(strHnd); + HLock(strHnd); + note(noErr, alidNote, (unsigned char *) *strHnd); + DisposHandle(strHnd); } static void RecoverMenuEvent(long menuEntry) { - short menuID = HiWord(menuEntry); - short menuItem = LoWord(menuEntry); + short menuID = HiWord(menuEntry); + short menuItem = LoWord(menuEntry); - switch (menuID) - { - case muidApple: - switch (menuItem) - { - case mitmAbout: - if (wnEvt.modifiers & optionKey) - optionMemStats(); - /* fall thru */ - case mitmHelp: - note(noErr, (alertAppleMenu + menuItem), aboutBuf); - break; + switch (menuID) { + case muidApple: + switch (menuItem) { + case mitmAbout: + if (wnEvt.modifiers & optionKey) + optionMemStats(); + /* fall thru */ + case mitmHelp: + note(noErr, (alertAppleMenu + menuItem), aboutBuf); + break; - default: /* DA's or apple menu items */ - { - unsigned char daName[32]; + default: /* DA's or apple menu items */ + { + unsigned char daName[32]; - GetItem(mHnd[menuApple], menuItem, * (Str255 *) &daName); - (void) OpenDeskAcc(daName); + GetItem(mHnd[menuApple], menuItem, *(Str255 *) &daName); + (void) OpenDeskAcc(daName); - memActivity++; - } - break; - } - break; + memActivity++; + } break; + } + break; - case muidFile: - switch (menuItem) - { - case mitmOpen: - beginRecover(); - break; + case muidFile: + switch (menuItem) { + case mitmOpen: + beginRecover(); + break; - case mitmClose_DA: - { - WindowPeek frontWindow; - short refNum; + case mitmClose_DA: { + WindowPeek frontWindow; + short refNum; - if (frontWindow = (WindowPeek) FrontWindow()) - if ((refNum = frontWindow->windowKind) < 0) - CloseDeskAcc(refNum); + if (frontWindow = (WindowPeek) FrontWindow()) + if ((refNum = frontWindow->windowKind) < 0) + CloseDeskAcc(refNum); - memActivity++; - } - break; + memActivity++; + } break; - case mitmQuit: - cooldown(); - break; - } - break; + case mitmQuit: + cooldown(); + break; + } + break; - case muidEdit: - (void) SystemEdit(menuItem - 1); - break; - } + case muidEdit: + (void) SystemEdit(menuItem - 1); + break; + } - HiliteMenu(0); + HiliteMenu(0); } static void eventLoop() { - short wneMask = (in.Front ? everyEvent : (osMask + updateMask)); - long wneSleep = (in.Front ? 0L : 3L); + short wneMask = (in.Front ? everyEvent : (osMask + updateMask)); + long wneSleep = (in.Front ? 0L : 3L); - while (1) - { - if (in.Front) - adjustGUI(); + while (1) { + if (in.Front) + adjustGUI(); - if (memActivity >= pBytes->memCleanup) - adjustMemory(); + if (memActivity >= pBytes->memCleanup) + adjustMemory(); - (void) WaitNextEvent(wneMask, &wnEvt, wneSleep, (RgnHandle) 0L); + (void) WaitNextEvent(wneMask, &wnEvt, wneSleep, (RgnHandle) 0L); - if (in.Dialog) - (void) IsDialogEvent(&wnEvt); + if (in.Dialog) + (void) IsDialogEvent(&wnEvt); - switch (wnEvt.what) - { - case osEvt: - if (((wnEvt.message & osEvtMessageMask) >> 24) == suspendResumeMessage) - { - in.Front = (wnEvt.message & resumeFlag); - wneMask = (in.Front ? everyEvent : (osMask + updateMask)); - wneSleep = (in.Front ? 0L : 3L); - } - break; + switch (wnEvt.what) { + case osEvt: + if (((wnEvt.message & osEvtMessageMask) >> 24) + == suspendResumeMessage) { + in.Front = (wnEvt.message & resumeFlag); + wneMask = (in.Front ? everyEvent : (osMask + updateMask)); + wneSleep = (in.Front ? 0L : 3L); + } + break; - case nullEvent: - /* adjust the FIFO notification queue */ - if (pNMQ && pNMQ->nmDispose) - { - notifPtr pNMX = pNMQ->nmNext; + case nullEvent: + /* adjust the FIFO notification queue */ + if (pNMQ && pNMQ->nmDispose) { + notifPtr pNMX = pNMQ->nmNext; - DisposPtr((Ptr) pNMQ); - pNMQ = pNMX; + DisposPtr((Ptr) pNMQ); + pNMQ = pNMX; - memActivity++; - } + memActivity++; + } - if (in.Recover) - continueRecover(); - break; + if (in.Recover) + continueRecover(); + break; - case mouseDown: - { - WindowPtr whichWindow; - - switch(FindWindow( wnEvt . where , &whichWindow)) - { - case inMenuBar: - RecoverMenuEvent(MenuSelect( wnEvt . where )); - break; + case mouseDown: { + WindowPtr whichWindow; - case inSysWindow: - SystemClick(&wnEvt, whichWindow); - break; + switch (FindWindow(wnEvt.where, &whichWindow)) { + case inMenuBar: + RecoverMenuEvent(MenuSelect(wnEvt.where)); + break; - case inDrag: - { - Rect boundsRect = qd.screenBits.bounds; - Point offsetPt; + case inSysWindow: + SystemClick(&wnEvt, whichWindow); + break; - InsetRect(&boundsRect, 4, 4); - boundsRect.top += GetMBarHeight(); + case inDrag: { + Rect boundsRect = qd.screenBits.bounds; + Point offsetPt; - DragWindow(whichWindow, * ((Point *) &wnEvt.where), &boundsRect); + InsetRect(&boundsRect, 4, 4); + boundsRect.top += GetMBarHeight(); - boundsRect = whichWindow->portRect; - offsetPt = * (Point *) &(whichWindow->portBits.bounds); - OffsetRect(&boundsRect, -offsetPt.h, -offsetPt.v); + DragWindow(whichWindow, *((Point *) &wnEvt.where), + &boundsRect); - * (Rect *) *thermoTHnd = boundsRect; - } - break; - } - } - break; + boundsRect = whichWindow->portRect; + offsetPt = *(Point *) &(whichWindow->portBits.bounds); + OffsetRect(&boundsRect, -offsetPt.h, -offsetPt.v); - case keyDown: - { - char key = (wnEvt.message & charCodeMask); + *(Rect *) *thermoTHnd = boundsRect; + } break; + } + } break; - if (wnEvt.modifiers & cmdKey) - { - if (key == '.') - { - if (in.Recover) - { - endRecover(); - note(noErr, alidNote, "\pSorry: Recovery aborted"); - } - } - else - RecoverMenuEvent(MenuKey(key)); - } - } - break; + case keyDown: { + char key = (wnEvt.message & charCodeMask); - /* without windows these events belong to our thermometer */ - case updateEvt: - case activateEvt: - { - DialogPtr dPtr; - short itemHit; + if (wnEvt.modifiers & cmdKey) { + if (key == '.') { + if (in.Recover) { + endRecover(); + note(noErr, alidNote, "\pSorry: Recovery aborted"); + } + } else + RecoverMenuEvent(MenuKey(key)); + } + } break; - (void) DialogSelect(&wnEvt, &dPtr, &itemHit); - } + /* without windows these events belong to our thermometer */ + case updateEvt: + case activateEvt: { + DialogPtr dPtr; + short itemHit; - case diskEvt: - if (HiWord(wnEvt.message)) - { - Point pt = {60, 60}; + (void) DialogSelect(&wnEvt, &dPtr, &itemHit); + } - (void) DIBadMount(pt, wnEvt.message); - DIUnload(); + case diskEvt: + if (HiWord(wnEvt.message)) { + Point pt = { 60, 60 }; - memActivity++; - } - break; - } /* switch (wnEvt.what) */ - } /* while (1) */ + (void) DIBadMount(pt, wnEvt.message); + DIUnload(); + + memActivity++; + } + break; + } /* switch (wnEvt.what) */ + } /* while (1) */ } static void cooldown() { - if (in.Recover) - endRecover(); + if (in.Recover) + endRecover(); - /* wait for pending notifications to complete */ - while (in.Notify) - (void) WaitNextEvent(0, &wnEvt, 3L, (RgnHandle) 0L); + /* wait for pending notifications to complete */ + while (in.Notify) + (void) WaitNextEvent(0, &wnEvt, 3L, (RgnHandle) 0L); - ExitToShell(); + ExitToShell(); } /* draw the progress thermometer and frame. 1 level <=> 1 horiz. pixel */ pascal void drawThermo(WindowPtr wPtr, short inum) { - itemizeThermo(drawItem); + itemizeThermo(drawItem); } /* manage progress thermometer dialog */ static void itemizeThermo(short itemMode) { - short iTyp, iTmp; - Handle iHnd; - Rect iRct; + short iTyp, iTmp; + Handle iHnd; + Rect iRct; - GetDItem(DLGTHM, uitmThermo, &iTyp, &iHnd, &iRct); + GetDItem(DLGTHM, uitmThermo, &iTyp, &iHnd, &iRct); - switch(itemMode) - { - case initItem: - SetDItem(DLGTHM, uitmThermo, iTyp, (Handle) drawThermoUPP, &iRct); - break; + switch (itemMode) { + case initItem: + SetDItem(DLGTHM, uitmThermo, iTyp, (Handle) drawThermoUPP, &iRct); + break; - case invalItem: - { - GrafPtr oldPort; + case invalItem: { + GrafPtr oldPort; - GetPort(&oldPort); - SetPort(GRFTHM); + GetPort(&oldPort); + SetPort(GRFTHM); - InsetRect(&iRct, 1, 1); - InvalRect(&iRct); + InsetRect(&iRct, 1, 1); + InvalRect(&iRct); - SetPort(oldPort); - } - break; + SetPort(oldPort); + } break; - case drawItem: - FrameRect(&iRct); - InsetRect(&iRct, 1, 1); + case drawItem: + FrameRect(&iRct); + InsetRect(&iRct, 1, 1); - iTmp = iRct.right; - iRct.right = iRct.left + in.Recover; - PaintRect(&iRct); + iTmp = iRct.right; + iRct.right = iRct.left + in.Recover; + PaintRect(&iRct); - iRct.left = iRct.right; - iRct.right = iTmp; - EraseRect(&iRct); - break; - } + iRct.left = iRct.right; + iRct.right = iTmp; + EraseRect(&iRct); + break; + } } /* show only .0 files in get file dialog */ pascal Boolean basenameFileFilter(ParmBlkPtr pPB) { - unsigned char *pC; + unsigned char *pC; - if (! (pC = (unsigned char *) pPB->fileParam.ioNamePtr)) - return true; + if (!(pC = (unsigned char *) pPB->fileParam.ioNamePtr)) + return true; - if ((*pC < 4) || (*pC > 28)) /* save/ 1name .0 */ - return true; + if ((*pC < 4) || (*pC > 28)) /* save/ 1name .0 */ + return true; - if ((pC[*pC - 1] == '.') && (pC[*pC] == '0')) /* bingo! */ - return false; + if ((pC[*pC - 1] == '.') && (pC[*pC] == '0')) /* bingo! */ + return false; - return true; + return true; } static void beginRecover() { - SFTypeList levlType = {'LEVL'}; - SFReply sfGetReply; + SFTypeList levlType = { 'LEVL' }; + SFReply sfGetReply; - SFGetFile(sfGetWhere, "\p", basenameFileFilterUPP, 1, levlType, - (DlgHookUPP) 0L, &sfGetReply); + SFGetFile(sfGetWhere, "\p", basenameFileFilterUPP, 1, levlType, + (DlgHookUPP) 0L, &sfGetReply); - memActivity++; + memActivity++; - if (! sfGetReply.good) - return; + if (!sfGetReply.good) + return; - /* get volume (working directory) refnum, basename, and directory i.d. */ - vRefNum = sfGetReply.vRefNum; - BlockMove(sfGetReply.fName, lock, sfGetReply.fName[0] + 1); - { - static CInfoPBRec catInfo; + /* get volume (working directory) refnum, basename, and directory i.d. */ + vRefNum = sfGetReply.vRefNum; + BlockMove(sfGetReply.fName, lock, sfGetReply.fName[0] + 1); + { + static CInfoPBRec catInfo; - catInfo.hFileInfo.ioNamePtr = (StringPtr) sfGetReply.fName; - catInfo.hFileInfo.ioVRefNum = sfGetReply.vRefNum; - catInfo.hFileInfo.ioDirID = 0L; + catInfo.hFileInfo.ioNamePtr = (StringPtr) sfGetReply.fName; + catInfo.hFileInfo.ioVRefNum = sfGetReply.vRefNum; + catInfo.hFileInfo.ioDirID = 0L; - if (PBGetCatInfoSync(&catInfo)) - { - note(noErr, alidNote, "\pSorry: Bad File Info"); - return; - } + if (PBGetCatInfoSync(&catInfo)) { + note(noErr, alidNote, "\pSorry: Bad File Info"); + return; + } - dirID = catInfo.hFileInfo.ioFlParID; - } + dirID = catInfo.hFileInfo.ioFlParID; + } - /* open the progress thermometer dialog */ - (void) GetNewDialog(dlogProgress, (Ptr) &dlgThermo, (WindowPtr) -1L); - if (ResError() || MemError()) - note(noErr, alidNote, "\pOops: Progress thermometer unavailable"); - else - { - in.Dialog = 1; - memActivity++; + /* open the progress thermometer dialog */ + (void) GetNewDialog(dlogProgress, (Ptr) &dlgThermo, (WindowPtr) -1L); + if (ResError() || MemError()) + note(noErr, alidNote, "\pOops: Progress thermometer unavailable"); + else { + in.Dialog = 1; + memActivity++; - itemizeThermo(initItem); + itemizeThermo(initItem); - ShowWindow(WNDTHM); - } + ShowWindow(WNDTHM); + } - timeCursor = TickCount() + CURS_LATENT; - saveRefNum = gameRefNum = levRefNum = -1; - in.Recover = 1; + timeCursor = TickCount() + CURS_LATENT; + saveRefNum = gameRefNum = levRefNum = -1; + in.Recover = 1; } static void continueRecover() { - restore_savefile(); + restore_savefile(); - /* update the thermometer */ - if (in.Dialog && ! (in.Recover % 4)) - itemizeThermo(invalItem); + /* update the thermometer */ + if (in.Dialog && !(in.Recover % 4)) + itemizeThermo(invalItem); - if (in.Recover <= MAX_RECOVER_COUNT) - return; + if (in.Recover <= MAX_RECOVER_COUNT) + return; - endRecover(); + endRecover(); - if (saveRezStrings()) - return; + if (saveRezStrings()) + return; - note(noErr, alidNote, "\pOK: Recovery succeeded"); + note(noErr, alidNote, "\pOK: Recovery succeeded"); } /* no messages from here (since we might be quitting) */ static void endRecover() { - in.Recover = 0; + in.Recover = 0; - oldCursor = curs_Init; - SetCursor(&qd.arrow); + oldCursor = curs_Init; + SetCursor(&qd.arrow); - /* clean up abandoned files */ - if (gameRefNum >= 0) - (void) FSClose(gameRefNum); + /* clean up abandoned files */ + if (gameRefNum >= 0) + (void) FSClose(gameRefNum); - if (levRefNum >= 0) - (void) FSClose(levRefNum); + if (levRefNum >= 0) + (void) FSClose(levRefNum); - if (saveRefNum >= 0) - { - (void) FSClose(saveRefNum); - (void) FlushVol((StringPtr) 0L, vRefNum); - /* its corrupted so trash it ... */ - (void) HDelete(vRefNum, dirID, savename); - } + if (saveRefNum >= 0) { + (void) FSClose(saveRefNum); + (void) FlushVol((StringPtr) 0L, vRefNum); + /* its corrupted so trash it ... */ + (void) HDelete(vRefNum, dirID, savename); + } - saveRefNum = gameRefNum = levRefNum = -1; + saveRefNum = gameRefNum = levRefNum = -1; - /* close the progress thermometer dialog */ - in.Dialog = 0; - CloseDialog(DLGTHM); - DisposHandle(dlgThermo.items); - memActivity++; + /* close the progress thermometer dialog */ + in.Dialog = 0; + CloseDialog(DLGTHM); + DisposHandle(dlgThermo.items); + memActivity++; } /* add friendly, non-essential resource strings to save file */ static short saveRezStrings() { - short sRefNum; - StringHandle strHnd; - short i, rezID; - unsigned char *plName; + short sRefNum; + StringHandle strHnd; + short i, rezID; + unsigned char *plName; - HCreateResFile(vRefNum, dirID, savename); + HCreateResFile(vRefNum, dirID, savename); - sRefNum = HOpenResFile(vRefNum, dirID, savename, fsRdWrPerm); - if (sRefNum <= 0) - { - note(noErr, alidNote, "\pOK: Minor resource map error"); - return 1; - } + sRefNum = HOpenResFile(vRefNum, dirID, savename, fsRdWrPerm); + if (sRefNum <= 0) { + note(noErr, alidNote, "\pOK: Minor resource map error"); + return 1; + } - /* savename and hpid get mutilated here... */ - plName = savename + 5; /* save/ */ - *savename -= 5; - do - { - plName++; - (*savename)--; - hpid /= 10; - } - while (hpid); - *plName = *savename; + /* savename and hpid get mutilated here... */ + plName = savename + 5; /* save/ */ + *savename -= 5; + do { + plName++; + (*savename)--; + hpid /= 10; + } while (hpid); + *plName = *savename; - for (i = 1; i <= 2; i++) - { - switch (i) - { - case 1: - rezID = PLAYER_NAME_RES_ID; - strHnd = NewString(* (Str255 *) plName); - break; + for (i = 1; i <= 2; i++) { + switch (i) { + case 1: + rezID = PLAYER_NAME_RES_ID; + strHnd = NewString(*(Str255 *) plName); + break; - case 2: - rezID = APP_NAME_RES_ID; - strHnd = NewString(* (Str255 *) "\pNetHack"); - break; - } + case 2: + rezID = APP_NAME_RES_ID; + strHnd = NewString(*(Str255 *) "\pNetHack"); + break; + } - if (! strHnd) - { - note(noErr, alidNote, "\pOK: Minor \'STR \' resource error"); - CloseResFile(sRefNum); - return 1; - } + if (!strHnd) { + note(noErr, alidNote, "\pOK: Minor \'STR \' resource error"); + CloseResFile(sRefNum); + return 1; + } - /* should check for errors... */ - AddResource((Handle) strHnd, 'STR ', rezID, * (Str255 *) "\p"); - } + /* should check for errors... */ + AddResource((Handle) strHnd, 'STR ', rezID, *(Str255 *) "\p"); + } - memActivity++; + memActivity++; - /* should check for errors... */ - CloseResFile(sRefNum); - return 0; + /* should check for errors... */ + CloseResFile(sRefNum); + return 0; } static void set_levelfile_name(long lev) { - unsigned char *tf; + unsigned char *tf; - /* find the dot. this is guaranteed to happen. */ - for (tf = (lock + *lock); *tf != '.'; tf--, lock[0]--) - ; + /* find the dot. this is guaranteed to happen. */ + for (tf = (lock + *lock); *tf != '.'; tf--, lock[0]--) + ; - /* append the level number string (pascal) */ - if (tf > lock) - { - NumToString(lev, * (Str255 *) tf); - lock[0] += *tf; - *tf = '.'; - } - else /* huh??? */ - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Name Error"); - } + /* append the level number string (pascal) */ + if (tf > lock) { + NumToString(lev, *(Str255 *) tf); + lock[0] += *tf; + *tf = '.'; + } else /* huh??? */ + { + endRecover(); + note(noErr, alidNote, "\pSorry: File Name Error"); + } } static short open_levelfile(long lev) { - OSErr openErr; - short fRefNum; + OSErr openErr; + short fRefNum; - set_levelfile_name(lev); - if (! in.Recover) - return (-1); + set_levelfile_name(lev); + if (!in.Recover) + return (-1); - if ((openErr = HOpen(vRefNum, dirID, lock, fsRdWrPerm, &fRefNum)) - && (openErr != fnfErr)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Open Error"); - return (-1); - } + if ((openErr = HOpen(vRefNum, dirID, lock, fsRdWrPerm, &fRefNum)) + && (openErr != fnfErr)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Open Error"); + return (-1); + } - return (openErr ? -1 : fRefNum); + return (openErr ? -1 : fRefNum); } static short create_savefile(unsigned char *savename) { - short fRefNum; + short fRefNum; - /* translate savename to a pascal string (in place) */ - { - unsigned char *pC; - short nameLen; + /* translate savename to a pascal string (in place) */ + { + unsigned char *pC; + short nameLen; - for (pC = savename; *pC; pC++); + for (pC = savename; *pC; pC++) + ; - nameLen = pC - savename; + nameLen = pC - savename; - for ( ; pC > savename; pC--) - *pC = *(pC - 1); + for (; pC > savename; pC--) + *pC = *(pC - 1); - *savename = nameLen; - } + *savename = nameLen; + } - if (HCreate(vRefNum, dirID, savename, MAC_CREATOR, SAVE_TYPE) - || HOpen(vRefNum, dirID, savename, fsRdWrPerm, &fRefNum)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Create Error"); - return (-1); - } + if (HCreate(vRefNum, dirID, savename, MAC_CREATOR, SAVE_TYPE) + || HOpen(vRefNum, dirID, savename, fsRdWrPerm, &fRefNum)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Create Error"); + return (-1); + } - return fRefNum; + return fRefNum; } static void copy_bytes(short inRefNum, short outRefNum) { - char *buf = (char *) pIOBuf; - long bufSiz = pBytes->memIOBuf; + char *buf = (char *) pIOBuf; + long bufSiz = pBytes->memIOBuf; - long nfrom, nto; + long nfrom, nto; - do - { - nfrom = read_levelfile(inRefNum, buf, bufSiz); - if (! in.Recover) - return; + do { + nfrom = read_levelfile(inRefNum, buf, bufSiz); + if (!in.Recover) + return; - nto = write_savefile(outRefNum, buf, nfrom); - if (! in.Recover) - return; + nto = write_savefile(outRefNum, buf, nfrom); + if (!in.Recover) + return; - if (nto != nfrom) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Copy Error"); - return; - } - } - while (nfrom == bufSiz); + if (nto != nfrom) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Copy Error"); + return; + } + } while (nfrom == bufSiz); } static void restore_savefile() { - static int savelev; - long saveTemp, lev; - xchar levc; - struct version_info version_data; + static int savelev; + long saveTemp, lev; + xchar levc; + struct version_info version_data; - /* level 0 file contains: - * pid of creating process (ignored here) - * level number for current level of save file - * name of save file nethack would have created - * and game state - */ + /* level 0 file contains: + * pid of creating process (ignored here) + * level number for current level of save file + * name of save file nethack would have created + * and game state + */ - lev = in.Recover - 1; - if (lev == 0L) - { - gameRefNum = open_levelfile(0L); + lev = in.Recover - 1; + if (lev == 0L) { + gameRefNum = open_levelfile(0L); - if (in.Recover) - (void) read_levelfile(gameRefNum, (Ptr) &hpid, sizeof(hpid)); + if (in.Recover) + (void) read_levelfile(gameRefNum, (Ptr) &hpid, sizeof(hpid)); - if (in.Recover) - saveTemp = read_levelfile(gameRefNum, (Ptr) &savelev, sizeof(savelev)); + if (in.Recover) + saveTemp = + read_levelfile(gameRefNum, (Ptr) &savelev, sizeof(savelev)); - if (in.Recover && (saveTemp != sizeof(savelev))) - { - endRecover(); - note(noErr, alidNote, "\pSorry: \"checkpoint\" was not enabled"); - return; - } + if (in.Recover && (saveTemp != sizeof(savelev))) { + endRecover(); + note(noErr, alidNote, "\pSorry: \"checkpoint\" was not enabled"); + return; + } - if (in.Recover) - (void) read_levelfile(gameRefNum, (Ptr) savename, sizeof(savename)); - if (in.Recover) - (void) read_levelfile(gameRefNum, - (Ptr) &version_data, sizeof version_data); + if (in.Recover) + (void) read_levelfile(gameRefNum, (Ptr) savename, + sizeof(savename)); + if (in.Recover) + (void) read_levelfile(gameRefNum, (Ptr) &version_data, + sizeof version_data); - /* save file should contain: - * current level (including pets) - * (non-level-based) game state - * other levels - */ - if (in.Recover) - saveRefNum = create_savefile(savename); + /* save file should contain: + * current level (including pets) + * (non-level-based) game state + * other levels + */ + if (in.Recover) + saveRefNum = create_savefile(savename); - if (in.Recover) - levRefNum = open_levelfile(savelev); + if (in.Recover) + levRefNum = open_levelfile(savelev); - if (in.Recover) - (void) write_savefile(saveRefNum, - (Ptr) &version_data, sizeof version_data); - if (in.Recover) - copy_bytes(levRefNum, saveRefNum); + if (in.Recover) + (void) write_savefile(saveRefNum, (Ptr) &version_data, + sizeof version_data); + if (in.Recover) + copy_bytes(levRefNum, saveRefNum); - if (in.Recover) - close_file(&levRefNum); + if (in.Recover) + close_file(&levRefNum); - if (in.Recover) - unlink_file(lock); + if (in.Recover) + unlink_file(lock); - if (in.Recover) - copy_bytes(gameRefNum, saveRefNum); + if (in.Recover) + copy_bytes(gameRefNum, saveRefNum); - if (in.Recover) - close_file(&gameRefNum); + if (in.Recover) + close_file(&gameRefNum); - if (in.Recover) - set_levelfile_name(0L); + if (in.Recover) + set_levelfile_name(0L); - if (in.Recover) - unlink_file(lock); - } - else if (lev != savelev) - { - levRefNum = open_levelfile(lev); - if (levRefNum >= 0) - { - /* any or all of these may not exist */ - levc = (xchar) lev; + if (in.Recover) + unlink_file(lock); + } else if (lev != savelev) { + levRefNum = open_levelfile(lev); + if (levRefNum >= 0) { + /* any or all of these may not exist */ + levc = (xchar) lev; - (void) write_savefile(saveRefNum, (Ptr) &levc, sizeof(levc)); + (void) write_savefile(saveRefNum, (Ptr) &levc, sizeof(levc)); - if (in.Recover) - copy_bytes(levRefNum, saveRefNum); + if (in.Recover) + copy_bytes(levRefNum, saveRefNum); - if (in.Recover) - close_file(&levRefNum); + if (in.Recover) + close_file(&levRefNum); - if (in.Recover) - unlink_file(lock); - } - } + if (in.Recover) + unlink_file(lock); + } + } - if (in.Recover == MAX_RECOVER_COUNT) - close_file(&saveRefNum); + if (in.Recover == MAX_RECOVER_COUNT) + close_file(&saveRefNum); - if (in.Recover) - in.Recover++; + if (in.Recover) + in.Recover++; } static long read_levelfile(short rdRefNum, Ptr bufPtr, long count) { - OSErr rdErr; - long rdCount = count; + OSErr rdErr; + long rdCount = count; - if ((rdErr = FSRead(rdRefNum, &rdCount, bufPtr)) && (rdErr != eofErr)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Read Error"); - return (-1L); - } + if ((rdErr = FSRead(rdRefNum, &rdCount, bufPtr)) && (rdErr != eofErr)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Read Error"); + return (-1L); + } - return rdCount; + return rdCount; } static long write_savefile(short wrRefNum, Ptr bufPtr, long count) { - long wrCount = count; + long wrCount = count; - if (FSWrite(wrRefNum, &wrCount, bufPtr)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Write Error"); - return (-1L); - } + if (FSWrite(wrRefNum, &wrCount, bufPtr)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Write Error"); + return (-1L); + } - return wrCount; + return wrCount; } static void close_file(short *pFRefNum) { - if (FSClose(*pFRefNum) || FlushVol((StringPtr) 0L, vRefNum)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Close Error"); - return; - } + if (FSClose(*pFRefNum) || FlushVol((StringPtr) 0L, vRefNum)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Close Error"); + return; + } - *pFRefNum = -1; + *pFRefNum = -1; } static void unlink_file(unsigned char *filename) { - if (HDelete(vRefNum, dirID, filename)) - { - endRecover(); - note(noErr, alidNote, "\pSorry: File Delete Error"); - return; - } + if (HDelete(vRefNum, dirID, filename)) { + endRecover(); + note(noErr, alidNote, "\pSorry: File Delete Error"); + return; + } } - diff --git a/sys/mac/mttymain.c b/sys/mac/mttymain.c index b3e28b280..4bb6e038d 100644 --- a/sys/mac/mttymain.c +++ b/sys/mac/mttymain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mttymain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mttymain.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 mttymain.c $Date: 2009/05/06 10:49:20 $ $Revision: 1.8 $ */ /* SCCS Id: @(#)mttymain.c 3.5 1993/02/26 */ /* Copyright (c) Jon W{tte, 1993 */ @@ -19,7 +19,6 @@ #define MT_WIDTH 80 #define MT_HEIGHT 24 - /* * Names: * @@ -27,49 +26,43 @@ * Mac-tty becomes mt_ */ -static long _mt_attrs [5] [2] = { - { 0x000000, 0xffffff }, /* Normal */ - { 0xff8080, 0xffffff }, /* Underline */ - { 0x40c020, 0xe0e0e0 }, /* Bold */ - { 0x003030, 0xff0060 }, /* Blink */ - { 0xff8888, 0x000000 }, /* Inverse */ +static long _mt_attrs[5][2] = { + { 0x000000, 0xffffff }, /* Normal */ + { 0xff8080, 0xffffff }, /* Underline */ + { 0x40c020, 0xe0e0e0 }, /* Bold */ + { 0x003030, 0xff0060 }, /* Blink */ + { 0xff8888, 0x000000 }, /* Inverse */ }; - -static char _attrs_inverse [5] = { - 0, 0, 0, 0, 0 , +static char _attrs_inverse[5] = { + 0, 0, 0, 0, 0, }; - /* see color.h */ -static long _mt_colors [CLR_MAX] [2] = { - { 0x000000, 0x808080 }, /* Black */ - { 0x880000, 0xffffff }, /* Red */ - { 0x008800, 0xffffff }, /* Green */ - { 0x553300, 0xffffff }, /* Brown */ - { 0x000088, 0xffffff }, /* Blue */ - { 0x880088, 0xffffff }, /* Magenta */ - { 0x008888, 0xffffff }, /* Cyan */ - { 0x888888, 0xffffff }, /* Gray */ - { 0x000000, 0xffffff }, /* No Color */ - { 0xff4400, 0xffffff }, /* Orange */ - { 0x00ff00, 0xffffff }, /* Bright Green */ - { 0xffff00, 0x606060 }, /* Yellow */ - { 0x0033ff, 0xffffff }, /* Bright Blue */ - { 0xff00ff, 0xffffff }, /* Bright Magenta */ - { 0x00ffff, 0xffffff }, /* Bright Cyan */ - { 0xffffff, 0x505050 }, /* White */ +static long _mt_colors[CLR_MAX][2] = { + { 0x000000, 0x808080 }, /* Black */ + { 0x880000, 0xffffff }, /* Red */ + { 0x008800, 0xffffff }, /* Green */ + { 0x553300, 0xffffff }, /* Brown */ + { 0x000088, 0xffffff }, /* Blue */ + { 0x880088, 0xffffff }, /* Magenta */ + { 0x008888, 0xffffff }, /* Cyan */ + { 0x888888, 0xffffff }, /* Gray */ + { 0x000000, 0xffffff }, /* No Color */ + { 0xff4400, 0xffffff }, /* Orange */ + { 0x00ff00, 0xffffff }, /* Bright Green */ + { 0xffff00, 0x606060 }, /* Yellow */ + { 0x0033ff, 0xffffff }, /* Bright Blue */ + { 0xff00ff, 0xffffff }, /* Bright Magenta */ + { 0x00ffff, 0xffffff }, /* Bright Cyan */ + { 0xffffff, 0x505050 }, /* White */ }; -static char _colors_inverse [CLR_MAX] = { - 1, 0, 0, 0 , - 0, 0, 0, 0 , - 0, 0, 0, 0 , - 0, 0, 0, 0 , +static char _colors_inverse[CLR_MAX] = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - #ifdef CHANGE_COLOR #define POWER_LIMIT 22 @@ -78,512 +71,521 @@ static char _colors_inverse [CLR_MAX] = { #define SECONDARY_CHANNEL_LIMIT 12 void -tty_change_color (int color, long rgb, int reverse) { -long inverse, working_rgb = rgb; -int total_power = 0, max_channel = 0; -int cnt = 3; +tty_change_color(int color, long rgb, int reverse) +{ + long inverse, working_rgb = rgb; + int total_power = 0, max_channel = 0; + int cnt = 3; - working_rgb >>= 4; - while (cnt -- > 0) { - total_power += working_rgb & 0xf; - max_channel = max (max_channel, working_rgb & 0xf); - working_rgb >>= 8; - } + working_rgb >>= 4; + while (cnt-- > 0) { + total_power += working_rgb & 0xf; + max_channel = max(max_channel, working_rgb & 0xf); + working_rgb >>= 8; + } - if (total_power >= POWER_LIMIT || - (total_power >= SECONDARY_POWER_LIMIT && - max_channel >= SECONDARY_CHANNEL_LIMIT) || - max_channel >= CHANNEL_LIMIT) - inverse = 0x000000; - else - inverse = 0xffffff; + if (total_power >= POWER_LIMIT + || (total_power >= SECONDARY_POWER_LIMIT + && max_channel >= SECONDARY_CHANNEL_LIMIT) + || max_channel >= CHANNEL_LIMIT) + inverse = 0x000000; + else + inverse = 0xffffff; - if (reverse) { - working_rgb = rgb; - rgb = inverse; - inverse = working_rgb; - } + if (reverse) { + working_rgb = rgb; + rgb = inverse; + inverse = working_rgb; + } - if (color >= CLR_MAX) { - if (color - CLR_MAX >= 5) - impossible ("Changing too many colors"); - else { - _mt_attrs [color - CLR_MAX] [0] = rgb; - _mt_attrs [color - CLR_MAX] [1] = inverse; - _attrs_inverse [color - CLR_MAX] = reverse; - } - } else if (color >= 0) { - _mt_colors [color] [0] = rgb; - _mt_colors [color] [1] = inverse; - _colors_inverse [color] = reverse; - } else - impossible ("Changing negative color"); + if (color >= CLR_MAX) { + if (color - CLR_MAX >= 5) + impossible("Changing too many colors"); + else { + _mt_attrs[color - CLR_MAX][0] = rgb; + _mt_attrs[color - CLR_MAX][1] = inverse; + _attrs_inverse[color - CLR_MAX] = reverse; + } + } else if (color >= 0) { + _mt_colors[color][0] = rgb; + _mt_colors[color][1] = inverse; + _colors_inverse[color] = reverse; + } else + impossible("Changing negative color"); } -void tty_change_background (int white_or_black) { - register int i; - - for (i = 0; i < CLR_MAX; i++) { - if (white_or_black) - _mt_colors [i] [1] = 0xffffff; /* white */ - else - _mt_colors [i] [1] = 0x000000; /* black */ - } - - /* special cases */ - if (white_or_black) { - _mt_colors [CLR_BLACK] [1] = 0x808080; /* differentiate black from no color */ - _mt_colors [CLR_WHITE] [1] = 0x505050; /* highlight white with grey background */ - _mt_colors [CLR_YELLOW] [1] = 0x606060; /* highlight yellow with grey background */ - _mt_colors [CLR_BLUE] [0] = 0x000088; /* make pure blue */ - _mt_colors [NO_COLOR] [0] = 0x000000; /* make no_color black on white */ - _mt_attrs [0] [0] = 0x000000; /* "normal" is black on white */ - _mt_attrs [0] [1] = 0xffffff; - } else { - _mt_colors [NO_COLOR] [0] = 0xffffff; /* make no_color white on black */ - _mt_colors [CLR_BLACK] [1] = 0x808080; /* differentiate black from no color */ - _mt_colors [CLR_BLUE] [0] = 0x222288; /* lighten blue - it's too dark on black */ - _mt_attrs [0] [0] = 0xffffff; /* "normal" is white on black */ - _mt_attrs [0] [1] = 0x000000; - } +void +tty_change_background(int white_or_black) +{ + register int i; + + for (i = 0; i < CLR_MAX; i++) { + if (white_or_black) + _mt_colors[i][1] = 0xffffff; /* white */ + else + _mt_colors[i][1] = 0x000000; /* black */ + } + + /* special cases */ + if (white_or_black) { + _mt_colors[CLR_BLACK][1] = + 0x808080; /* differentiate black from no color */ + _mt_colors[CLR_WHITE][1] = + 0x505050; /* highlight white with grey background */ + _mt_colors[CLR_YELLOW][1] = + 0x606060; /* highlight yellow with grey background */ + _mt_colors[CLR_BLUE][0] = 0x000088; /* make pure blue */ + _mt_colors[NO_COLOR][0] = 0x000000; /* make no_color black on white */ + _mt_attrs[0][0] = 0x000000; /* "normal" is black on white */ + _mt_attrs[0][1] = 0xffffff; + } else { + _mt_colors[NO_COLOR][0] = 0xffffff; /* make no_color white on black */ + _mt_colors[CLR_BLACK][1] = + 0x808080; /* differentiate black from no color */ + _mt_colors[CLR_BLUE][0] = + 0x222288; /* lighten blue - it's too dark on black */ + _mt_attrs[0][0] = 0xffffff; /* "normal" is white on black */ + _mt_attrs[0][1] = 0x000000; + } } char * -tty_get_color_string (void) { -char *ptr; -int count; -static char color_buf [5 * (CLR_MAX + 5) + 1]; +tty_get_color_string(void) +{ + char *ptr; + int count; + static char color_buf[5 * (CLR_MAX + 5) + 1]; - color_buf [0] = 0; - ptr = color_buf; + color_buf[0] = 0; + ptr = color_buf; - for (count = 0; count < CLR_MAX; count ++) { - int flag = _colors_inverse [count] ? 1 : 0; + for (count = 0; count < CLR_MAX; count++) { + int flag = _colors_inverse[count] ? 1 : 0; - sprintf (ptr, "%s%s%x%x%x", count ? "/" : "" , - flag ? "-" : "" , - (int)(_mt_colors [count] [flag] >> 20) & 0xf , - (int)(_mt_colors [count] [flag] >> 12) & 0xf , - (int)(_mt_colors [count] [flag] >> 4) & 0xf); - ptr += strlen (ptr); - } - for (count = 0; count < 5; count ++) { - int flag = _attrs_inverse [count] ? 1 : 0; + sprintf(ptr, "%s%s%x%x%x", count ? "/" : "", flag ? "-" : "", + (int) (_mt_colors[count][flag] >> 20) & 0xf, + (int) (_mt_colors[count][flag] >> 12) & 0xf, + (int) (_mt_colors[count][flag] >> 4) & 0xf); + ptr += strlen(ptr); + } + for (count = 0; count < 5; count++) { + int flag = _attrs_inverse[count] ? 1 : 0; - sprintf (ptr, "/%s%x%x%x" , - flag ? "-" : "" , - (int)(_mt_attrs [count] [flag] >> 20) & 0xf , - (int)(_mt_attrs [count] [flag] >> 12) & 0xf , - (int)(_mt_attrs [count] [flag] >> 4) & 0xf); - ptr += strlen (ptr); - } + sprintf(ptr, "/%s%x%x%x", flag ? "-" : "", + (int) (_mt_attrs[count][flag] >> 20) & 0xf, + (int) (_mt_attrs[count][flag] >> 12) & 0xf, + (int) (_mt_attrs[count][flag] >> 4) & 0xf); + ptr += strlen(ptr); + } - return color_buf; + return color_buf; } #endif - -extern struct DisplayDesc *ttyDisplay; /* the tty display descriptor */ +extern struct DisplayDesc *ttyDisplay; /* the tty display descriptor */ char kill_char = CHAR_ESC; char erase_char = CHAR_BS; WindowRef _mt_window = (WindowRef) 0; static Boolean _mt_in_color = 0; -extern short win_fonts [NHW_TEXT + 1]; +extern short win_fonts[NHW_TEXT + 1]; static void -_mt_init_stuff (void) { -long resp, flag; -short num_cols, num_rows, win_width, win_height, font_num, font_size; -short char_width, row_height; -short hor, vert; +_mt_init_stuff(void) +{ + long resp, flag; + short num_cols, num_rows, win_width, win_height, font_num, font_size; + short char_width, row_height; + short hor, vert; - LI = MT_HEIGHT; - CO = MT_WIDTH; + LI = MT_HEIGHT; + CO = MT_WIDTH; - if (!strcmp(windowprocs.name, "mac")) { - dprintf ("Mac Windows"); - LI -= 1; - } else { - dprintf ("TTY Windows"); - } - - /* - * If there is at least one screen CAPABLE of color, and if - * 32-bit QD is there, we use color. 32-bit QD is needed for the - * offscreen GWorld - */ - if (!Gestalt (gestaltQuickdrawVersion, &resp) && resp > 0x1ff) { - GDHandle gdh = GetDeviceList (); - while (gdh) { - if (TestDeviceAttribute (gdh, screenDevice)) { - if (HasDepth (gdh, 4, 1, 1) || - HasDepth (gdh, 8, 1, 1) || - HasDepth (gdh, 16, 1, 1) || - HasDepth (gdh, 32, 1, 1)) { - _mt_in_color = 1; - break; - } - } - gdh = GetNextDevice (gdh); - } - } + if (!strcmp(windowprocs.name, "mac")) { + dprintf("Mac Windows"); + LI -= 1; + } else { + dprintf("TTY Windows"); + } - if (create_tty (&_mt_window, WIN_BASE_KIND + NHW_MAP, _mt_in_color) != noErr) - error("_mt_init_stuff: Couldn't create tty."); - SetWindowKind(_mt_window, WIN_BASE_KIND + NHW_MAP); - SelectWindow(_mt_window); - SetPortWindowPort(_mt_window); - SetOrigin(-1, -1); + /* + * If there is at least one screen CAPABLE of color, and if + * 32-bit QD is there, we use color. 32-bit QD is needed for the + * offscreen GWorld + */ + if (!Gestalt(gestaltQuickdrawVersion, &resp) && resp > 0x1ff) { + GDHandle gdh = GetDeviceList(); + while (gdh) { + if (TestDeviceAttribute(gdh, screenDevice)) { + if (HasDepth(gdh, 4, 1, 1) || HasDepth(gdh, 8, 1, 1) + || HasDepth(gdh, 16, 1, 1) || HasDepth(gdh, 32, 1, 1)) { + _mt_in_color = 1; + break; + } + } + gdh = GetNextDevice(gdh); + } + } - font_size = iflags.wc_fontsiz_map ? iflags.wc_fontsiz_map : - (iflags.large_font && !small_screen) ? 12 : 9; - if (init_tty_number (_mt_window, win_fonts [NHW_MAP], font_size, CO, LI) != noErr) - error("_mt_init_stuff: Couldn't init tty."); + if (create_tty(&_mt_window, WIN_BASE_KIND + NHW_MAP, _mt_in_color) + != noErr) + error("_mt_init_stuff: Couldn't create tty."); + SetWindowKind(_mt_window, WIN_BASE_KIND + NHW_MAP); + SelectWindow(_mt_window); + SetPortWindowPort(_mt_window); + SetOrigin(-1, -1); - if (get_tty_metrics (_mt_window, &num_cols, &num_rows, &win_width , - &win_height, &font_num, &font_size, &char_width, &row_height)) - error("_mt_init_stuff: Couldn't get tty metrics."); + font_size = iflags.wc_fontsiz_map + ? iflags.wc_fontsiz_map + : (iflags.large_font && !small_screen) ? 12 : 9; + if (init_tty_number(_mt_window, win_fonts[NHW_MAP], font_size, CO, LI) + != noErr) + error("_mt_init_stuff: Couldn't init tty."); - SizeWindow (_mt_window, win_width + 2, win_height + 2, 1); - if (RetrievePosition (kMapWindow, &vert, &hor)) { - dprintf ("Moving window to (%d,%d)", hor, vert); - MoveWindow (_mt_window, hor, vert, 1); - } - ShowWindow (_mt_window); + if (get_tty_metrics(_mt_window, &num_cols, &num_rows, &win_width, + &win_height, &font_num, &font_size, &char_width, + &row_height)) + error("_mt_init_stuff: Couldn't get tty metrics."); - /* Start in raw, always flushing mode */ - get_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, &flag); - flag |= TA_ALWAYS_REFRESH | TA_WRAP_AROUND; - set_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, flag); + SizeWindow(_mt_window, win_width + 2, win_height + 2, 1); + if (RetrievePosition(kMapWindow, &vert, &hor)) { + dprintf("Moving window to (%d,%d)", hor, vert); + MoveWindow(_mt_window, hor, vert, 1); + } + ShowWindow(_mt_window); - get_tty_attrib(_mt_window, TTY_ATTRIB_CURSOR, &flag); - flag |= (TA_BLINKING_CURSOR | TA_NL_ADD_CR); - set_tty_attrib(_mt_window, TTY_ATTRIB_CURSOR, flag); + /* Start in raw, always flushing mode */ + get_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, &flag); + flag |= TA_ALWAYS_REFRESH | TA_WRAP_AROUND; + set_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, flag); - set_tty_attrib(_mt_window, TTY_ATTRIB_FOREGROUND, _mt_colors[NO_COLOR][0]); - set_tty_attrib(_mt_window, TTY_ATTRIB_BACKGROUND, _mt_colors[NO_COLOR][1]); - clear_tty (_mt_window); + get_tty_attrib(_mt_window, TTY_ATTRIB_CURSOR, &flag); + flag |= (TA_BLINKING_CURSOR | TA_NL_ADD_CR); + set_tty_attrib(_mt_window, TTY_ATTRIB_CURSOR, flag); - InitMenuRes (); + set_tty_attrib(_mt_window, TTY_ATTRIB_FOREGROUND, + _mt_colors[NO_COLOR][0]); + set_tty_attrib(_mt_window, TTY_ATTRIB_BACKGROUND, + _mt_colors[NO_COLOR][1]); + clear_tty(_mt_window); + + InitMenuRes(); } - int -tgetch (void) { -EventRecord event; -long sleepTime = 0; -int ret = 0; +tgetch(void) +{ + EventRecord event; + long sleepTime = 0; + int ret = 0; - for (;!ret;) { - WaitNextEvent (-1, &event, sleepTime, 0); - HandleEvent (&event); - blink_cursor (_mt_window, event.when); - if (event.what == nullEvent) { - sleepTime = GetCaretTime (); - } else { - sleepTime = 0; - } - ret = GetFromKeyQueue (); - if (ret == CHAR_CR) ret = CHAR_LF; - } - return ret; + for (; !ret;) { + WaitNextEvent(-1, &event, sleepTime, 0); + HandleEvent(&event); + blink_cursor(_mt_window, event.when); + if (event.what == nullEvent) { + sleepTime = GetCaretTime(); + } else { + sleepTime = 0; + } + ret = GetFromKeyQueue(); + if (ret == CHAR_CR) + ret = CHAR_LF; + } + return ret; } - void -getreturn (char *str) { - FlushEvents (-1, 0); - msmsg ("Press space %s", str); - (void) tgetch (); +getreturn(char *str) +{ + FlushEvents(-1, 0); + msmsg("Press space %s", str); + (void) tgetch(); } - int -has_color (int color) { +has_color(int color) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(color) +#pragma unused(color) #endif - Rect r; -// Point p = {0, 0}; - GDHandle gh; + Rect r; + // Point p = {0, 0}; + GDHandle gh; + if (!_mt_in_color) + return 0; - if (!_mt_in_color) - return 0; + GetWindowBounds(_mt_window, kWindowContentRgn, &r); + // SetPortWindowPort(_mt_window); + // LocalToGlobal (&p); + // OffsetRect (&r, p.h, p.v); - GetWindowBounds(_mt_window, kWindowContentRgn, &r); -// SetPortWindowPort(_mt_window); -// LocalToGlobal (&p); -// OffsetRect (&r, p.h, p.v); + gh = GetMaxDevice(&r); + if (!gh) { + return 0; + } - gh = GetMaxDevice (&r); - if (!gh) { - return 0; - } - - return (*((*gh)->gdPMap))->pixelSize > 4; /* > 4 bpp */ + return (*((*gh)->gdPMap))->pixelSize > 4; /* > 4 bpp */ } - void -tty_delay_output (void) { -EventRecord event; -long toWhen = TickCount () + 3; +tty_delay_output(void) +{ + EventRecord event; + long toWhen = TickCount() + 3; - while (TickCount () < toWhen) { - WaitNextEvent (updateMask, &event, 3L, 0); - if (event.what == updateEvt) { - HandleEvent (&event); - blink_cursor (_mt_window, event.when); - } - } + while (TickCount() < toWhen) { + WaitNextEvent(updateMask, &event, 3L, 0); + if (event.what == updateEvt) { + HandleEvent(&event); + blink_cursor(_mt_window, event.when); + } + } } - void -cmov (int x, int y) { - move_tty_cursor (_mt_window, x, y); - ttyDisplay->cury = y; - ttyDisplay->curx = x; +cmov(int x, int y) +{ + move_tty_cursor(_mt_window, x, y); + ttyDisplay->cury = y; + ttyDisplay->curx = x; } - void -nocmov (int x, int y) { - cmov (x, y); +nocmov(int x, int y) +{ + cmov(x, y); } - static void -_mt_set_colors (long *colors) { -short err; +_mt_set_colors(long *colors) +{ + short err; - if (!_mt_in_color) { - return; - } - err = set_tty_attrib (_mt_window, TTY_ATTRIB_FOREGROUND, colors [0]); - err = set_tty_attrib (_mt_window, TTY_ATTRIB_BACKGROUND, colors [1]); + if (!_mt_in_color) { + return; + } + err = set_tty_attrib(_mt_window, TTY_ATTRIB_FOREGROUND, colors[0]); + err = set_tty_attrib(_mt_window, TTY_ATTRIB_BACKGROUND, colors[1]); } - void -term_end_attr (int attr) { +term_end_attr(int attr) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused (attr) +#pragma unused(attr) #endif - _mt_set_colors (_mt_attrs [0]); + _mt_set_colors(_mt_attrs[0]); } - void -term_start_attr (int attr) { - switch (attr) { - case ATR_ULINE: - _mt_set_colors (_mt_attrs [1]); - break; - case ATR_BOLD: - _mt_set_colors (_mt_attrs [2]); - break; - case ATR_BLINK: - _mt_set_colors (_mt_attrs [3]); - break; - case ATR_INVERSE: - _mt_set_colors (_mt_attrs [4]); - break; - default: - _mt_set_colors (_mt_attrs [0]); - break; - } -} - - -void -standoutend (void) { - term_end_attr (ATR_INVERSE); -} - - -void -standoutbeg (void) { - term_start_attr (ATR_INVERSE); -} - - -void -term_end_color (void) { - _mt_set_colors (_mt_colors [NO_COLOR]); -} - - -void -cl_end (void) { - _mt_set_colors (_mt_attrs [0]); - clear_tty_window (_mt_window, ttyDisplay->curx, ttyDisplay->cury, - CO - 1, ttyDisplay->cury); -} - - -void -clear_screen (void) { - _mt_set_colors (_mt_attrs [0]); - clear_tty (_mt_window); -} - - -void -cl_eos (void) { - _mt_set_colors (_mt_attrs [0]); - clear_tty_window (_mt_window, ttyDisplay->curx, ttyDisplay->cury, CO - 1, - LI - 1); -} - - -void -home (void) { - cmov (0,0); -} - - -void -backsp (void) { -char eraser [] = { CHAR_BS, CHAR_BLANK, CHAR_BS, 0 }; -short err; - - err = add_tty_string (_mt_window, eraser); - err = update_tty (_mt_window); -} - - -void -msmsg (const char *str, ...) { -va_list args; -char buf [1000]; - - va_start (args, str); - vsprintf (buf, str, args); - va_end (args); - - xputs (buf); -} - - -void -term_end_raw_bold (void) { - term_end_attr (ATR_INVERSE); -} - - -void -term_start_raw_bold (void) { - term_start_attr (ATR_INVERSE); -} - - -void -term_start_color (int color) { - if (color >= 0 && color < CLR_MAX) { - _mt_set_colors (_mt_colors [color]); - } -} - - -void -setftty (void) +term_start_attr(int attr) { - long flag; - - /* Buffered output for the game */ - get_tty_attrib (_mt_window, TTY_ATTRIB_FLAGS, &flag); - flag &= ~ TA_ALWAYS_REFRESH; - flag |= TA_INHIBIT_VERT_SCROLL; /* don't scroll */ - set_tty_attrib (_mt_window, TTY_ATTRIB_FLAGS, flag); - iflags.cbreak = 1; + switch (attr) { + case ATR_ULINE: + _mt_set_colors(_mt_attrs[1]); + break; + case ATR_BOLD: + _mt_set_colors(_mt_attrs[2]); + break; + case ATR_BLINK: + _mt_set_colors(_mt_attrs[3]); + break; + case ATR_INVERSE: + _mt_set_colors(_mt_attrs[4]); + break; + default: + _mt_set_colors(_mt_attrs[0]); + break; + } } - void -tty_startup (int *width, int *height ) { - _mt_init_stuff (); - *width = CO; - *height = LI; -} - - -void -gettty (void) { -} - - -void -settty (const char *str) +standoutend(void) { - long flag; - - update_tty (_mt_window); - - /* Buffered output for the game, raw in "raw" mode */ - get_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, &flag); - flag &= ~ TA_INHIBIT_VERT_SCROLL; /* scroll */ - flag |= TA_ALWAYS_REFRESH; - set_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, flag); - - tty_raw_print ("\n"); - if (str) { - tty_raw_print (str); - } + term_end_attr(ATR_INVERSE); } +void +standoutbeg(void) +{ + term_start_attr(ATR_INVERSE); +} void -tty_number_pad (int arg) { +term_end_color(void) +{ + _mt_set_colors(_mt_colors[NO_COLOR]); +} + +void +cl_end(void) +{ + _mt_set_colors(_mt_attrs[0]); + clear_tty_window(_mt_window, ttyDisplay->curx, ttyDisplay->cury, CO - 1, + ttyDisplay->cury); +} + +void +clear_screen(void) +{ + _mt_set_colors(_mt_attrs[0]); + clear_tty(_mt_window); +} + +void +cl_eos(void) +{ + _mt_set_colors(_mt_attrs[0]); + clear_tty_window(_mt_window, ttyDisplay->curx, ttyDisplay->cury, CO - 1, + LI - 1); +} + +void +home(void) +{ + cmov(0, 0); +} + +void +backsp(void) +{ + char eraser[] = { CHAR_BS, CHAR_BLANK, CHAR_BS, 0 }; + short err; + + err = add_tty_string(_mt_window, eraser); + err = update_tty(_mt_window); +} + +void +msmsg(const char *str, ...) +{ + va_list args; + char buf[1000]; + + va_start(args, str); + vsprintf(buf, str, args); + va_end(args); + + xputs(buf); +} + +void +term_end_raw_bold(void) +{ + term_end_attr(ATR_INVERSE); +} + +void +term_start_raw_bold(void) +{ + term_start_attr(ATR_INVERSE); +} + +void +term_start_color(int color) +{ + if (color >= 0 && color < CLR_MAX) { + _mt_set_colors(_mt_colors[color]); + } +} + +void +setftty(void) +{ + long flag; + + /* Buffered output for the game */ + get_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, &flag); + flag &= ~TA_ALWAYS_REFRESH; + flag |= TA_INHIBIT_VERT_SCROLL; /* don't scroll */ + set_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, flag); + iflags.cbreak = 1; +} + +void +tty_startup(int *width, int *height) +{ + _mt_init_stuff(); + *width = CO; + *height = LI; +} + +void +gettty(void) +{ +} + +void +settty(const char *str) +{ + long flag; + + update_tty(_mt_window); + + /* Buffered output for the game, raw in "raw" mode */ + get_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, &flag); + flag &= ~TA_INHIBIT_VERT_SCROLL; /* scroll */ + flag |= TA_ALWAYS_REFRESH; + set_tty_attrib(_mt_window, TTY_ATTRIB_FLAGS, flag); + + tty_raw_print("\n"); + if (str) { + tty_raw_print(str); + } +} + +void +tty_number_pad(int arg) +{ #if defined(__SC__) || defined(__MRC__) -# pragma unused(arg) +#pragma unused(arg) #endif } +void +tty_start_screen(void) +{ + iflags.cbreak = 1; +} void -tty_start_screen (void) { - iflags.cbreak = 1; +tty_end_screen(void) +{ } - void -tty_end_screen (void) { +xputs(const char *str) +{ + add_tty_string(_mt_window, str); } - -void -xputs (const char *str) { - add_tty_string (_mt_window, str); -} - - int -term_puts (const char *str) { - xputs (str); - return strlen (str); +term_puts(const char *str) +{ + xputs(str); + return strlen(str); } - int -term_putc (int c) { -short err; +term_putc(int c) +{ + short err; - err = add_tty_char (_mt_window, c); - return err ? EOF : c; + err = add_tty_char(_mt_window, c); + return err ? EOF : c; } - int -term_flush (void *desc) { - if (desc == stdout || desc == stderr) { - update_tty (_mt_window); - } else { - impossible ("Substituted flush for file"); - return fflush (desc); - } - return 0; +term_flush(void *desc) +{ + if (desc == stdout || desc == stderr) { + update_tty(_mt_window); + } else { + impossible("Substituted flush for file"); + return fflush(desc); + } + return 0; } diff --git a/sys/msdos/msdos.c b/sys/msdos/msdos.c index d73093594..e9fcbb02c 100644 --- a/sys/msdos/msdos.c +++ b/sys/msdos/msdos.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 msdos.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 msdos.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 msdos.c $Date: 2012/01/22 06:27:07 $ $Revision: 1.7 $ */ /* Copyright (c) NetHack PC Development Team 1990 */ /* NetHack may be freely redistributed. See license for details. */ @@ -21,18 +21,18 @@ /* * MS-DOS functions */ -#define DIRECT_INPUT 0x07 /* Unfiltered Character Input Without Echo */ -#define FATINFO 0x1B /* Get Default Drive Data */ +#define DIRECT_INPUT 0x07 /* Unfiltered Character Input Without Echo */ +#define FATINFO 0x1B /* Get Default Drive Data */ /* MS-DOS 2.0+: */ -#define GETDTA 0x2F /* Get DTA Address */ -#define FREESPACE 0x36 /* Get Drive Allocation Info */ -#define GETSWITCHAR 0x3700 /* Get Switch Character */ -#define FINDFIRST 0x4E /* Find First File */ -#define FINDNEXT 0x4F /* Find Next File */ -#define SETFILETIME 0x5701 /* Set File Date & Time */ -/* - * BIOS interrupts - */ +#define GETDTA 0x2F /* Get DTA Address */ +#define FREESPACE 0x36 /* Get Drive Allocation Info */ +#define GETSWITCHAR 0x3700 /* Get Switch Character */ +#define FINDFIRST 0x4E /* Find First File */ +#define FINDNEXT 0x4F /* Find Next File */ +#define SETFILETIME 0x5701 /* Set File Date & Time */ + /* + * BIOS interrupts + */ #ifdef PC9800 #define KEYBRD_BIOS 0x18 #else @@ -42,58 +42,58 @@ /* * Keyboard BIOS functions */ -#define READCHAR 0x00 /* Read Character from Keyboard */ +#define READCHAR 0x00 /* Read Character from Keyboard */ #define GETKEYFLAGS 0x02 /* Get Keyboard Flags */ -/*#define KEY_DEBUG */ /* print values of unexpected key codes - devel*/ +/*#define KEY_DEBUG */ /* print values of unexpected key codes - devel*/ -void FDECL(get_cursor,(int *, int *)); +void FDECL(get_cursor, (int *, int *)); /* direct bios calls are used only when iflags.BIOS is set */ STATIC_DCL char NDECL(DOSgetch); STATIC_DCL char NDECL(BIOSgetch); #ifndef __GO32__ -STATIC_DCL char * NDECL(getdta); +STATIC_DCL char *NDECL(getdta); #endif -STATIC_DCL unsigned int FDECL(dos_ioctl, (int,int,unsigned)); +STATIC_DCL unsigned int FDECL(dos_ioctl, (int, int, unsigned)); #ifdef USE_TILES -extern boolean FDECL(pckeys,(unsigned char, unsigned char)); /* pckeys.c */ +extern boolean FDECL(pckeys, (unsigned char, unsigned char)); /* pckeys.c */ #endif int tgetch() { - char ch; + char ch; - /* BIOSgetch can use the numeric key pad on IBM compatibles. */ -# ifdef SIMULATE_CURSOR - if (iflags.grmode && cursor_flag) DrawCursor(); -# endif - if (iflags.BIOS) - ch = BIOSgetch(); - else - ch = DOSgetch(); -# ifdef SIMULATE_CURSOR - if (iflags.grmode && cursor_flag) HideCursor(); -# endif - return ((ch == '\r') ? '\n' : ch); +/* BIOSgetch can use the numeric key pad on IBM compatibles. */ +#ifdef SIMULATE_CURSOR + if (iflags.grmode && cursor_flag) + DrawCursor(); +#endif + if (iflags.BIOS) + ch = BIOSgetch(); + else + ch = DOSgetch(); +#ifdef SIMULATE_CURSOR + if (iflags.grmode && cursor_flag) + HideCursor(); +#endif + return ((ch == '\r') ? '\n' : ch); } - - /* * Keyboard translation tables. */ #ifdef PC9800 -#define KEYPADLO 0x38 -#define KEYPADHI 0x50 +#define KEYPADLO 0x38 +#define KEYPADHI 0x50 #else -#define KEYPADLO 0x47 -#define KEYPADHI 0x53 +#define KEYPADLO 0x47 +#define KEYPADHI 0x53 #endif -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -101,92 +101,94 @@ tgetch() * shift values below. */ static const struct pad { - char normal, shift, cntrl; -} keypad[PADKEYS] = { + char normal, shift, cntrl; +} keypad[PADKEYS] = + { #ifdef PC9800 - {'>', '>', '>'}, /* Ins */ - {'<', '<', '<'}, /* Del */ - {'k', 'K', C('k')}, /* Up */ - {'h', 'H', C('h')}, /* Left */ - {'l', 'L', C('l')}, /* Right */ - {'j', 'J', C('j')}, /* Down */ - { 0 , 0 , 0 }, /* HomeClr */ - {'?', '?', '?' }, /* Help */ - {'m', C('p'), C('p')}, /* - */ - {'/', '/', '/'}, /* / */ - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'*', '*', '*'}, /* * */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'g', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'=', '=', '='}, /* = */ - {'i', 'I', C('i')}, /* 0 */ - {',', ':', ':'}, /* , */ - {'.', '.', '.'} /* . */ + { '>', '>', '>' }, /* Ins */ + { '<', '<', '<' }, /* Del */ + { 'k', 'K', C('k') }, /* Up */ + { 'h', 'H', C('h') }, /* Left */ + { 'l', 'L', C('l') }, /* Right */ + { 'j', 'J', C('j') }, /* Down */ + { 0, 0, 0 }, /* HomeClr */ + { '?', '?', '?' }, /* Help */ + { 'm', C('p'), C('p') }, /* - */ + { '/', '/', '/' }, /* / */ + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { '*', '*', '*' }, /* * */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'g', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { '=', '=', '=' }, /* = */ + { 'i', 'I', C('i') }, /* 0 */ + { ',', ':', ':' }, /* , */ + { '.', '.', '.' } /* . */ #else - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'g', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'g', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ #endif -}, numpad[PADKEYS] = { + }, + numpad[PADKEYS] = { #ifdef PC9800 - {'>', '>', '>'}, /* Ins */ - {'<', '<', '<'}, /* Del */ - {'8', M('8'), '8'}, /* Up */ - {'4', M('4'), '4'}, /* Left */ - {'6', M('6'), '6'}, /* Right */ - {'2', M('2'), '2'}, /* Down */ - { 0 , 0 , 0 }, /* HomeClr */ - {'?', '?', '?'}, /* Help */ - {'m', C('p'), C('p')}, /* - */ - {'/', '/', '/'}, /* / */ - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'*', '*', '*'}, /* * */ - {'4', M('4'), '4'}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'=', '=', '='}, /* = */ - {'i', 'I', C('i')}, /* 0 */ - {',', ':', ':'}, /* , */ - {'.', '.', '.'} /* . */ + { '>', '>', '>' }, /* Ins */ + { '<', '<', '<' }, /* Del */ + { '8', M('8'), '8' }, /* Up */ + { '4', M('4'), '4' }, /* Left */ + { '6', M('6'), '6' }, /* Right */ + { '2', M('2'), '2' }, /* Down */ + { 0, 0, 0 }, /* HomeClr */ + { '?', '?', '?' }, /* Help */ + { 'm', C('p'), C('p') }, /* - */ + { '/', '/', '/' }, /* / */ + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { '*', '*', '*' }, /* * */ + { '4', M('4'), '4' }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { '=', '=', '=' }, /* = */ + { 'i', 'I', C('i') }, /* 0 */ + { ',', ':', ':' }, /* , */ + { '.', '.', '.' } /* . */ #else - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'5', M('5'), '5'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'0', M('0'), '0'}, /* Ins */ - {'.', ':', ':'} /* Del */ + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { '5', M('5'), '5' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { '0', M('0'), '0' }, /* Ins */ + { '.', ':', ':' } /* Del */ #endif -}; + }; /* * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII @@ -197,172 +199,176 @@ static const struct pad { * "meta" bit for it. -3. */ #ifdef PC9800 -#define SCANLO 0x5 +#define SCANLO 0x5 #else -#define SCANLO 0x10 +#define SCANLO 0x10 #endif /* PC9800 */ -static const char scanmap[] = { /* ... */ +static const char scanmap[] = { + /* ... */ #ifdef PC9800 - 0, 0, 0, 0, 0, 0, '-','^','\\','\b', - '\t','q','w','e','r','t','y','u','i','o','p','@','[', '\n', - 'a','s','d','f','g','h','j','k','l',';',':', ']', - 'z','x','c','v','b','N','m',',','.','/' /* ... */ + 0, 0, 0, 0, 0, 0, '-', '^', '\\', '\b', '\t', 'q', 'w', 'e', 'r', 't', + 'y', 'u', 'i', 'o', 'p', '@', '[', '\n', 'a', 's', 'd', 'f', 'g', 'h', + 'j', 'k', 'l', ';', ':', ']', 'z', 'x', 'c', 'v', 'b', 'N', 'm', ',', '.', + '/' /* ... */ #else - 'q','w','e','r','t','y','u','i','o','p','[',']', '\n', - 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`', - 0, '\\', 'z','x','c','v','b','n','m',',','.','?' /* ... */ + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', + 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', + 'c', 'v', 'b', 'n', 'm', ',', '.', '?' /* ... */ #endif /* PC9800 */ }; -#define inmap(x) (SCANLO <= (x) && (x) < SCANLO + SIZE(scanmap)) +#define inmap(x) (SCANLO <= (x) && (x) < SCANLO + SIZE(scanmap)) #ifdef NEW_ALT -#define NUMERIC_SCANLO 0x78 -static const char numeric_scanmap[] = { /* ... */ - '1','2','3','4','5','6','7','8','9','0','-','=' +#define NUMERIC_SCANLO 0x78 +static const char numeric_scanmap[] = { /* ... */ + '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '-', '=' }; -# define in_numericmap(x) (NUMERIC_SCANLO <= (x) && \ - (x) < NUMERIC_SCANLO + SIZE(numeric_scanmap)) -# endif +#define in_numericmap(x) \ + (NUMERIC_SCANLO <= (x) && (x) < NUMERIC_SCANLO + SIZE(numeric_scanmap)) +#endif /* * BIOSgetch gets keys directly with a BIOS call. */ #ifdef PC9800 -#define SHIFT 0x1 -#define KANA 0x4 -#define GRPH 0x8 -#define CTRL 0x10 +#define SHIFT 0x1 +#define KANA 0x4 +#define GRPH 0x8 +#define CTRL 0x10 #else -#define SHIFT (0x1 | 0x2) -#define CTRL 0x4 -#define ALT 0x8 +#define SHIFT (0x1 | 0x2) +#define CTRL 0x4 +#define ALT 0x8 #endif /* PC9800 */ STATIC_OVL char BIOSgetch() { - unsigned char scan, shift, ch=0; - const struct pad *kpad; - union REGS regs; + unsigned char scan, shift, ch = 0; + const struct pad *kpad; + union REGS regs; - do { - /* Get scan code. - */ - regs.h.ah = READCHAR; - int86(KEYBRD_BIOS, ®s, ®s); - ch = regs.h.al; - scan = regs.h.ah; - /* Get shift status. - */ - regs.h.ah = GETKEYFLAGS; - int86(KEYBRD_BIOS, ®s, ®s); - shift = regs.h.al; + do { + /* Get scan code. + */ + regs.h.ah = READCHAR; + int86(KEYBRD_BIOS, ®s, ®s); + ch = regs.h.al; + scan = regs.h.ah; + /* Get shift status. + */ + regs.h.ah = GETKEYFLAGS; + int86(KEYBRD_BIOS, ®s, ®s); + shift = regs.h.al; - /* Translate keypad keys */ - if (iskeypad(scan)) { - kpad = iflags.num_pad ? numpad : keypad; - if (shift & SHIFT) - ch = kpad[scan - KEYPADLO].shift; - else if (shift & CTRL) - ch = kpad[scan - KEYPADLO].cntrl; - else - ch = kpad[scan - KEYPADLO].normal; - } + /* Translate keypad keys */ + if (iskeypad(scan)) { + kpad = iflags.num_pad ? numpad : keypad; + if (shift & SHIFT) + ch = kpad[scan - KEYPADLO].shift; + else if (shift & CTRL) + ch = kpad[scan - KEYPADLO].cntrl; + else + ch = kpad[scan - KEYPADLO].normal; + } #ifdef USE_TILES - /* Check for special interface manipulation keys */ - if (pckeys(scan, shift)) { - ch = 0xFF; - continue; - } + /* Check for special interface manipulation keys */ + if (pckeys(scan, shift)) { + ch = 0xFF; + continue; + } #endif - /* Translate unassigned Alt-letters */ +/* Translate unassigned Alt-letters */ #ifdef PC9800 - if (shift & KANA) - return 0; - if ((shift & GRPH) && (ch >= 0x80)) { + if (shift & KANA) + return 0; + if ((shift & GRPH) && (ch >= 0x80)) { #else - if ((shift & ALT) && !ch) { + if ((shift & ALT) && !ch) { #endif #if 0 pline("Scan code: %d 0x%03X", scan, scan); #endif - if (inmap(scan)) - ch = scanmap[scan - SCANLO]; + if (inmap(scan)) + ch = scanmap[scan - SCANLO]; #ifdef NEW_ALT - else if (in_numericmap(scan)) - ch = numeric_scanmap[scan - NUMERIC_SCANLO]; + else if (in_numericmap(scan)) + ch = numeric_scanmap[scan - NUMERIC_SCANLO]; #endif - return (isprint(ch) ? M(ch) : ch); - } - } while (ch == 0xFF); - return ch; + return (isprint(ch) ? M(ch) : ch); + } + } while (ch == 0xFF); + return ch; } STATIC_OVL char DOSgetch() { - union REGS regs; - char ch; - struct pad (*kpad)[PADKEYS]; + union REGS regs; + char ch; + struct pad(*kpad)[PADKEYS]; - regs.h.ah = DIRECT_INPUT; - intdos(®s, ®s); - ch = regs.h.al; + regs.h.ah = DIRECT_INPUT; + intdos(®s, ®s); + ch = regs.h.al; #ifdef PC9800 - if (ch < 0) /* KANA letters and GRPH-shifted letters(?) */ - ch = 0; /* munch it */ + if (ch < 0) /* KANA letters and GRPH-shifted letters(?) */ + ch = 0; /* munch it */ #else - /* - * The extended codes for Alt-shifted letters, and unshifted keypad - * and function keys, correspond to the scan codes. So we can still - * translate the unshifted cursor keys and Alt-letters. -3. - */ - if (ch == 0) { /* an extended key */ - regs.h.ah = DIRECT_INPUT; - intdos(®s, ®s); /* get the extended key code */ - ch = regs.h.al; + /* + * The extended codes for Alt-shifted letters, and unshifted keypad + * and function keys, correspond to the scan codes. So we can still + * translate the unshifted cursor keys and Alt-letters. -3. + */ + if (ch == 0) { /* an extended key */ + regs.h.ah = DIRECT_INPUT; + intdos(®s, ®s); /* get the extended key code */ + ch = regs.h.al; - if (iskeypad(ch)) { /* unshifted keypad keys */ - kpad = (void *)(iflags.num_pad ? numpad : keypad); - ch = (*kpad)[ch - KEYPADLO].normal; - } else if (inmap(ch)) { /* Alt-letters */ - ch = scanmap[ch - SCANLO]; - if (isprint(ch)) ch = M(ch); - } else ch = 0; /* munch it */ - } + if (iskeypad(ch)) { /* unshifted keypad keys */ + kpad = (void *) (iflags.num_pad ? numpad : keypad); + ch = (*kpad)[ch - KEYPADLO].normal; + } else if (inmap(ch)) { /* Alt-letters */ + ch = scanmap[ch - SCANLO]; + if (isprint(ch)) + ch = M(ch); + } else + ch = 0; /* munch it */ + } #endif - return (ch); + return (ch); } char switchar() { - union REGS regs; + union REGS regs; - regs.x.ax = GETSWITCHAR; - intdos(®s, ®s); - return regs.h.dl; + regs.x.ax = GETSWITCHAR; + intdos(®s, ®s); + return regs.h.dl; } long freediskspace(path) char *path; { - union REGS regs; + union REGS regs; - regs.h.ah = FREESPACE; - if (path[0] && path[1] == ':') - regs.h.dl = (toupper(path[0]) - 'A') + 1; - else - regs.h.dl = 0; - intdos(®s, ®s); - if (regs.x.ax == 0xFFFF) - return -1L; /* bad drive number */ - else - return ((long) regs.x.bx * regs.x.cx * regs.x.ax); + regs.h.ah = FREESPACE; + if (path[0] && path[1] == ':') + regs.h.dl = (toupper(path[0]) - 'A') + 1; + else + regs.h.dl = 0; + intdos(®s, ®s); + if (regs.x.ax == 0xFFFF) + return -1L; /* bad drive number */ + else + return ((long) regs.x.bx * regs.x.cx * regs.x.ax); } #ifndef __GO32__ @@ -373,63 +379,63 @@ int findfirst_file(path) char *path; { - union REGS regs; - struct SREGS sregs; + union REGS regs; + struct SREGS sregs; - regs.h.ah = FINDFIRST; - regs.x.cx = 0; /* attribute: normal files */ - regs.x.dx = FP_OFF(path); - sregs.ds = FP_SEG(path); - intdosx(®s, ®s, &sregs); - return !regs.x.cflag; + regs.h.ah = FINDFIRST; + regs.x.cx = 0; /* attribute: normal files */ + regs.x.dx = FP_OFF(path); + sregs.ds = FP_SEG(path); + intdosx(®s, ®s, &sregs); + return !regs.x.cflag; } int -findnext_file() { - union REGS regs; +findnext_file() +{ + union REGS regs; - regs.h.ah = FINDNEXT; - intdos(®s, ®s); - return !regs.x.cflag; + regs.h.ah = FINDNEXT; + intdos(®s, ®s); + return !regs.x.cflag; } char * foundfile_buffer() { - return (getdta() + 30); + return (getdta() + 30); } - /* Get disk transfer area */ STATIC_OVL char * getdta() { - union REGS regs; - struct SREGS sregs; - char *ret; + union REGS regs; + struct SREGS sregs; + char *ret; - regs.h.ah = GETDTA; - intdosx(®s, ®s, &sregs); -# ifdef MK_FP - ret = (char *)MK_FP(sregs.es, regs.x.bx); -# else - FP_OFF(ret) = regs.x.bx; - FP_SEG(ret) = sregs.es; -# endif - return ret; + regs.h.ah = GETDTA; + intdosx(®s, ®s, &sregs); +#ifdef MK_FP + ret = (char *) MK_FP(sregs.es, regs.x.bx); +#else + FP_OFF(ret) = regs.x.bx; + FP_SEG(ret) = sregs.es; +#endif + return ret; } long filesize_nh(file) char *file; { - char *dta; + char *dta; - if (findfirst_file(file)) { - dta = getdta(); - return (* (long *) (dta + 26)); - } else - return -1L; + if (findfirst_file(file)) { + dta = getdta(); + return (*(long *) (dta + 26)); + } else + return -1L; } #endif /* __GO32__ */ @@ -441,61 +447,61 @@ void chdrive(str) char *str; { -# define SELECTDISK 0x0E - char *ptr; - union REGS inregs; - char drive; +#define SELECTDISK 0x0E + char *ptr; + union REGS inregs; + char drive; - if ((ptr = index(str, ':')) != (char *)0) { - drive = toupper(*(ptr - 1)); - inregs.h.ah = SELECTDISK; - inregs.h.dl = drive - 'A'; - intdos(&inregs, &inregs); - } - return; + if ((ptr = index(str, ':')) != (char *) 0) { + drive = toupper(*(ptr - 1)); + inregs.h.ah = SELECTDISK; + inregs.h.dl = drive - 'A'; + intdos(&inregs, &inregs); + } + return; } - /* Use the IOCTL DOS function call to change stdin and stdout to raw * mode. For stdin, this prevents MSDOS from trapping ^P, thus * freeing us of ^P toggling 'echo to printer'. * Thanks to Mark Zbikowski (markz@microsoft.UUCP). */ -#define DEVICE 0x80 -#define RAW 0x20 -#define IOCTL 0x44 -#define STDIN fileno(stdin) -#define STDOUT fileno(stdout) -#define GETBITS 0 -#define SETBITS 1 +#define DEVICE 0x80 +#define RAW 0x20 +#define IOCTL 0x44 +#define STDIN fileno(stdin) +#define STDOUT fileno(stdout) +#define GETBITS 0 +#define SETBITS 1 -static unsigned int old_stdin, old_stdout; +static unsigned int old_stdin, old_stdout; void disable_ctrlP() { - - if (!iflags.rawio) return; + if (!iflags.rawio) + return; old_stdin = dos_ioctl(STDIN, GETBITS, 0); old_stdout = dos_ioctl(STDOUT, GETBITS, 0); - if (old_stdin & DEVICE) + if (old_stdin & DEVICE) dos_ioctl(STDIN, SETBITS, old_stdin | RAW); - if (old_stdout & DEVICE) + if (old_stdout & DEVICE) dos_ioctl(STDOUT, SETBITS, old_stdout | RAW); - return; + return; } void enable_ctrlP() { - if (!iflags.rawio) return; - if (old_stdin) + if (!iflags.rawio) + return; + if (old_stdin) (void) dos_ioctl(STDIN, SETBITS, old_stdin); - if (old_stdout) + if (old_stdout) (void) dos_ioctl(STDOUT, SETBITS, old_stdout); - return; + return; } STATIC_OVL unsigned int @@ -503,15 +509,15 @@ dos_ioctl(handle, mode, setvalue) int handle, mode; unsigned setvalue; { - union REGS regs; + union REGS regs; - regs.h.ah = IOCTL; - regs.h.al = mode; - regs.x.bx = handle; - regs.h.dl = setvalue; - regs.h.dh = 0; /* Zero out dh */ - intdos(®s, ®s); - return (regs.x.dx); + regs.h.ah = IOCTL; + regs.h.al = mode; + regs.x.bx = handle; + regs.h.dl = setvalue; + regs.h.dh = 0; /* Zero out dh */ + intdos(®s, ®s); + return (regs.x.dx); } #endif /* MSDOS */ diff --git a/sys/msdos/ovlinit.c b/sys/msdos/ovlinit.c index 379cbafe3..7c43fb9d8 100644 --- a/sys/msdos/ovlinit.c +++ b/sys/msdos/ovlinit.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 ovlinit.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 ovlinit.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 ovlinit.c $Date: 2009/05/06 10:49:38 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)ovlinit.c 3.5 1994/03/20 */ /* Copyright (c) NetHack PC Development Team 1995 */ @@ -8,57 +8,57 @@ #include #include - #ifdef _MSC_VER -#define RESERVED_PARAGRAPHS 5120 /* leave 80K for malloc and inits */ - /* subject to change before release */ +#define RESERVED_PARAGRAPHS 5120 /* leave 80K for malloc and inits */ + /* subject to change before release */ /* * memavail() Returns the amount of RAM available (in paragraphs which are 16 * bytes) - the amount to be reserved for heap allocations. * */ -unsigned memavail(minovl) -unsigned minovl; /* minimum size of overlay heap */ +unsigned +memavail(minovl) +unsigned minovl; /* minimum size of overlay heap */ { - unsigned available; + unsigned available; - unsigned farparaavail; - unsigned tmp; + unsigned farparaavail; + unsigned tmp; - /* - * _dos_allocmem will return the maximum block size available. - * It uses DOS (int 21h) service 0x48. - */ + /* + * _dos_allocmem will return the maximum block size available. + * It uses DOS (int 21h) service 0x48. + */ - _dos_allocmem(0xFFFF, &farparaavail); - available = farparaavail - RESERVED_PARAGRAPHS; - tmp = RESERVED_PARAGRAPHS + minovl; - if (farparaavail < tmp) { - panic("Not enough free RAM to begin a game of NetHack (%ld bytes)", - (long)((long)tmp * 16L)); - } - return available; + _dos_allocmem(0xFFFF, &farparaavail); + available = farparaavail - RESERVED_PARAGRAPHS; + tmp = RESERVED_PARAGRAPHS + minovl; + if (farparaavail < tmp) { + panic("Not enough free RAM to begin a game of NetHack (%ld bytes)", + (long) ((long) tmp * 16L)); + } + return available; } -#endif /*_MSC_VER*/ +#endif /*_MSC_VER*/ #ifdef __BORLANDC__ -#define RSRVD_MALLOC 65 * 1024L /* malloc() calls use about 65K */ -#define RSRVD_CRTL 50 * 1024L /* C runtime library uses 50K */ -#define RSRVD_TOTAL 115 * 1024L /* reserved for use in malloc() */ - /* as well as by C runtime library */ - /* routines which allocate memory */ - /* after this routine runs. */ -#define MIN_OVRBUF 30 * 1024L /* Overlay buffer gets minimum of */ -#define MAX_OVRBUF 200 * 1024L /* 30K and maximum of 200K. */ +#define RSRVD_MALLOC 65 * 1024L /* malloc() calls use about 65K */ +#define RSRVD_CRTL 50 * 1024L /* C runtime library uses 50K */ +#define RSRVD_TOTAL 115 * 1024L /* reserved for use in malloc() */ + /* as well as by C runtime library */ + /* routines which allocate memory */ + /* after this routine runs. */ +#define MIN_OVRBUF 30 * 1024L /* Overlay buffer gets minimum of */ +#define MAX_OVRBUF 200 * 1024L /* 30K and maximum of 200K. */ #define RESIZE_OVL #ifdef RESIZE_OVL -extern unsigned _ovrbuffer = 0; /* Use default size initially */ -unsigned appFail = 0; /* Fail flag if not enough RAM */ +extern unsigned _ovrbuffer = 0; /* Use default size initially */ +unsigned appFail = 0; /* Fail flag if not enough RAM */ unsigned memAlloc = 0; unsigned long ProgramSize; unsigned long runAlloc; @@ -70,87 +70,89 @@ int xmsstatus; void NDECL(_resizeOvrBuffer); -void _resizeOvrBuffer() +void +_resizeOvrBuffer() { - mem_top = (unsigned far *) MK_FP( _psp, 0x02 ); - total = *mem_top - _psp; + mem_top = (unsigned far *) MK_FP(_psp, 0x02); + total = *mem_top - _psp; - ProgramSize = * (unsigned far *) MK_FP( _psp - 1, 0x03 ); - tmpbuffer = total - ProgramSize - RSRVD_TOTAL / 16; - memAlloc = min (MAX_OVRBUF / 16, tmpbuffer); - if (tmpbuffer >= MIN_OVRBUF / 16) - _ovrbuffer = memAlloc; - else { - _ovrbuffer = 1; - appFail = 1; - }; - - -/* - * Remember, when inside this code, nothing has been setup on - * the system, so do NOT call any RTL functions for I/O or - * anything else that might rely on a startup function. This - * includes accessing any global objects as their constructors - * have not been called yet. - */ + ProgramSize = *(unsigned far *) MK_FP(_psp - 1, 0x03); + tmpbuffer = total - ProgramSize - RSRVD_TOTAL / 16; + memAlloc = min(MAX_OVRBUF / 16, tmpbuffer); + if (tmpbuffer >= MIN_OVRBUF / 16) + _ovrbuffer = memAlloc; + else { + _ovrbuffer = 1; + appFail = 1; + }; + /* + * Remember, when inside this code, nothing has been setup on + * the system, so do NOT call any RTL functions for I/O or + * anything else that might rely on a startup function. This + * includes accessing any global objects as their constructors + * have not been called yet. + */ } -#pragma startup _resizeOvrBuffer 0 /* Put function in table */ +#pragma startup _resizeOvrBuffer 0 /* Put function in table */ void -startup () +startup() { - if (appFail) { - printf ("NetHack fits in memory, but it cannot allocate memory"); - printf (" for the overlay buffer\nand the runtime functions. "); - printf ("Please free up just %ld more bytes.", - (long)(MIN_OVRBUF - tmpbuffer * 16L)); - exit (-1); - } else { + if (appFail) { + printf("NetHack fits in memory, but it cannot allocate memory"); + printf(" for the overlay buffer\nand the runtime functions. "); + printf("Please free up just %ld more bytes.", + (long) (MIN_OVRBUF - tmpbuffer * 16L)); + exit(-1); + } else { + /* Now try to use expanded memory for the overlay manager */ + /* If that doesn't work, we revert to extended memory */ - /* Now try to use expanded memory for the overlay manager */ - /* If that doesn't work, we revert to extended memory */ - - emsstatus = _OvrInitEms (0, 0, 0); + emsstatus = _OvrInitEms(0, 0, 0); #ifdef RECOGNIZE_XMS - xmsstatus = (emsstatus) ? _OvrInitExt (0, 0) : -1; + xmsstatus = (emsstatus) ? _OvrInitExt(0, 0) : -1; #endif - - } + } } void show_borlandc_stats(win) winid win; { - char buf[BUFSZ]; + char buf[BUFSZ]; - putstr(win, 0, ""); - putstr(win, 0, ""); - putstr(win, 0, "Memory usage stats"); putstr(win, 0, ""); - putstr(win, 0, ""); - Sprintf (buf, "Overlay buffer memory allocation: %ld bytes.", - memAlloc * 16L); putstr(win, 0, buf); - Sprintf (buf, "_ovrbuffer = %u.", _ovrbuffer); putstr(win, 0, buf); - Sprintf (buf, "Startup memory usage: 0x%X", ProgramSize); - putstr(win, 0, buf); - runAlloc = * (unsigned far *) MK_FP( _psp - 1, 0x03); - Sprintf (buf, "Current memory usage: 0x%X", runAlloc); - putstr(win, 0, buf); - if (emsstatus) Sprintf (buf, "EMS search failed (%d).", emsstatus); - else Sprintf (buf, "EMS search successful."); - putstr(win, 0, buf); + putstr(win, 0, ""); + putstr(win, 0, ""); + putstr(win, 0, "Memory usage stats"); + putstr(win, 0, ""); + putstr(win, 0, ""); + Sprintf(buf, "Overlay buffer memory allocation: %ld bytes.", + memAlloc * 16L); + putstr(win, 0, buf); + Sprintf(buf, "_ovrbuffer = %u.", _ovrbuffer); + putstr(win, 0, buf); + Sprintf(buf, "Startup memory usage: 0x%X", ProgramSize); + putstr(win, 0, buf); + runAlloc = *(unsigned far *) MK_FP(_psp - 1, 0x03); + Sprintf(buf, "Current memory usage: 0x%X", runAlloc); + putstr(win, 0, buf); + if (emsstatus) + Sprintf(buf, "EMS search failed (%d).", emsstatus); + else + Sprintf(buf, "EMS search successful."); + putstr(win, 0, buf); #ifdef RECOGNIZE_XMS - if (xmsstatus) Sprintf (buf, "XMS search failed (%d).", xmsstatus); - else Sprintf (buf, "XMS search successful."); - putstr(win, 0, buf); + if (xmsstatus) + Sprintf(buf, "XMS search failed (%d).", xmsstatus); + else + Sprintf(buf, "XMS search successful."); + putstr(win, 0, buf); #endif - - } -#endif /* #ifdef RESIZE_OVL */ +#endif /* #ifdef RESIZE_OVL */ #endif /* #ifdef __BORLANDC__ */ /*ovlinit.c*/ diff --git a/sys/msdos/pckeys.c b/sys/msdos/pckeys.c index 12f8eef78..c8f0289bb 100644 --- a/sys/msdos/pckeys.c +++ b/sys/msdos/pckeys.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pckeys.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 pckeys.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 pckeys.c $Date: 2009/05/06 10:49:39 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)pckeys.c 3.5 1996/05/11 */ /* Copyright (c) NetHack PC Development Team 1996 */ @@ -11,18 +11,18 @@ #include "hack.h" #ifdef MSDOS -# ifdef USE_TILES -#include "wintty.h" +#ifdef USE_TILES +#include "wintty.h" #include "pcvideo.h" boolean FDECL(pckeys, (unsigned char, unsigned char)); -extern struct WinDesc *wins[MAXWIN]; /* from wintty.c */ -extern boolean inmap; /* from video.c */ +extern struct WinDesc *wins[MAXWIN]; /* from wintty.c */ +extern boolean inmap; /* from video.c */ -#define SHIFT (0x1 | 0x2) -#define CTRL 0x4 -#define ALT 0x8 +#define SHIFT (0x1 | 0x2) +#define CTRL 0x4 +#define ALT 0x8 /* * Check for special interface manipulation keys. @@ -34,49 +34,48 @@ pckeys(scancode, shift) unsigned char scancode; unsigned char shift; { - boolean opening_dialog; + boolean opening_dialog; - opening_dialog = pl_character[0] ? FALSE : TRUE; -# ifdef SIMULATE_CURSOR - switch(scancode) { - case 0x3d: /* F3 = toggle cursor type */ - HideCursor(); - cursor_type += 1; - if (cursor_type >= NUM_CURSOR_TYPES) cursor_type = 0; - DrawCursor(); - break; -# endif - case 0x74: /* Control-right_arrow = scroll horizontal to right */ - if ((shift & CTRL) && iflags.tile_view && !opening_dialog) - vga_userpan(1); - break; + opening_dialog = pl_character[0] ? FALSE : TRUE; +#ifdef SIMULATE_CURSOR + switch (scancode) { + case 0x3d: /* F3 = toggle cursor type */ + HideCursor(); + cursor_type += 1; + if (cursor_type >= NUM_CURSOR_TYPES) + cursor_type = 0; + DrawCursor(); + break; +#endif + case 0x74: /* Control-right_arrow = scroll horizontal to right */ + if ((shift & CTRL) && iflags.tile_view && !opening_dialog) + vga_userpan(1); + break; - case 0x73: /* Control-left_arrow = scroll horizontal to left */ - if ((shift & CTRL) && iflags.tile_view && !opening_dialog) - vga_userpan(0); - break; - case 0x3E: /* F4 = toggle overview mode */ - if (iflags.tile_view && !opening_dialog - && !Is_rogue_level(&u.uz)) { - iflags.traditional_view = FALSE; - vga_overview(iflags.over_view ? FALSE : TRUE); - vga_refresh(); - } - break; - case 0x3F: /* F5 = toggle traditional mode */ - if (iflags.tile_view && !opening_dialog - && !Is_rogue_level(&u.uz)) { - iflags.over_view = FALSE; - vga_traditional(iflags.traditional_view ? FALSE : TRUE); - vga_refresh(); - } - break; - default: - return FALSE; + case 0x73: /* Control-left_arrow = scroll horizontal to left */ + if ((shift & CTRL) && iflags.tile_view && !opening_dialog) + vga_userpan(0); + break; + case 0x3E: /* F4 = toggle overview mode */ + if (iflags.tile_view && !opening_dialog && !Is_rogue_level(&u.uz)) { + iflags.traditional_view = FALSE; + vga_overview(iflags.over_view ? FALSE : TRUE); + vga_refresh(); + } + break; + case 0x3F: /* F5 = toggle traditional mode */ + if (iflags.tile_view && !opening_dialog && !Is_rogue_level(&u.uz)) { + iflags.over_view = FALSE; + vga_traditional(iflags.traditional_view ? FALSE : TRUE); + vga_refresh(); + } + break; + default: + return FALSE; } return TRUE; } -# endif /* USE_TILES */ +#endif /* USE_TILES */ #endif /* MSDOS */ /*pckeys.c*/ diff --git a/sys/msdos/pctiles.c b/sys/msdos/pctiles.c index 206263eb8..b00338eaf 100644 --- a/sys/msdos/pctiles.c +++ b/sys/msdos/pctiles.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pctiles.c $NHDT-Date: 1425319883 2015/03/02 18:11:23 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ +/* NetHack 3.6 pctiles.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 pctiles.c $Date: 2009/05/06 10:49:39 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)pctiles.c 3.5 1995/07/31 */ /* Copyright (c) NetHack PC Development Team 1993, 1994 */ @@ -6,7 +6,7 @@ /* */ /* * pctiles.c - PC Graphical Tile Support Routines - * + * *Edit History: * Initial Creation M. Allison 93/10/30 * @@ -18,18 +18,18 @@ #if defined(__GO32__) || defined(__DJGPP__) #include -#define TILES_IN_RAM /* allow tiles to be read into ram */ +#define TILES_IN_RAM /* allow tiles to be read into ram */ #endif -# if defined(_MSC_VER) -# if _MSC_VER >= 700 -#pragma warning(disable:4018) /* signed/unsigned mismatch */ -#pragma warning(disable:4127) /* conditional expression is constant */ -#pragma warning(disable:4131) /* old style declarator */ -#pragma warning(disable:4309) /* initializing */ -# endif +#if defined(_MSC_VER) +#if _MSC_VER >= 700 +#pragma warning(disable : 4018) /* signed/unsigned mismatch */ +#pragma warning(disable : 4127) /* conditional expression is constant */ +#pragma warning(disable : 4131) /* old style declarator */ +#pragma warning(disable : 4309) /* initializing */ +#endif #include -# endif +#endif #include "pcvideo.h" #include "tile.h" @@ -37,14 +37,14 @@ STATIC_VAR FILE *tilefile; STATIC_VAR FILE *tilefile_O; -extern short glyph2tile[]; /* in tile.c (made from tilemap.c) */ +extern short glyph2tile[]; /* in tile.c (made from tilemap.c) */ #ifdef TILES_IN_RAM struct planar_cell_struct *ramtiles; struct overview_planar_cell_struct *oramtiles; boolean tiles_in_ram = FALSE; boolean otiles_in_ram = FALSE; -extern int total_tiles_used; /* tile.c */ +extern int total_tiles_used; /* tile.c */ #endif /* @@ -55,19 +55,20 @@ extern int total_tiles_used; /* tile.c */ * at the start of the file, including a palette. * */ -int ReadTileFileHeader(tibhdr, filestyle) +int +ReadTileFileHeader(tibhdr, filestyle) struct tibhdr_struct *tibhdr; boolean filestyle; { - FILE *x; - x = filestyle ? tilefile_O : tilefile; - if (fseek(x,0L,SEEK_SET)) { - return 1; - } else { - fread(tibhdr, sizeof(struct tibhdr_struct), 1, x); - } - return 0; -} + FILE *x; + x = filestyle ? tilefile_O : tilefile; + if (fseek(x, 0L, SEEK_SET)) { + return 1; + } else { + fread(tibhdr, sizeof(struct tibhdr_struct), 1, x); + } + return 0; +} /* * Open the requested tile file. @@ -91,74 +92,80 @@ char *tilefilename; boolean filestyle; { #ifdef TILES_IN_RAM - int k; + int k; #endif - if (filestyle) { - tilefile_O = fopen(tilefilename,"rb"); - if (tilefile_O == (FILE *)0) return 1; - } else { - tilefile = fopen(tilefilename,"rb"); - if (tilefile == (FILE *)0) return 1; - } + if (filestyle) { + tilefile_O = fopen(tilefilename, "rb"); + if (tilefile_O == (FILE *) 0) + return 1; + } else { + tilefile = fopen(tilefilename, "rb"); + if (tilefile == (FILE *) 0) + return 1; + } #ifdef TILES_IN_RAM if (iflags.preload_tiles) { - if (filestyle) { - struct overview_planar_cell_struct *gp; - long ram_needed = sizeof(struct overview_planar_cell_struct) * - total_tiles_used; - if (fseek(tilefile_O,(long)TIBHEADER_SIZE, SEEK_SET)) { /*failure*/ - } - oramtiles = (struct overview_planar_cell_struct *)alloc(ram_needed); - /* Todo: fall back to file method here if alloc failed */ - gp = oramtiles; - for(k=0; k < total_tiles_used; ++k) { - fread(gp, sizeof(struct overview_planar_cell_struct), - 1, tilefile_O); - ++gp; - } + if (filestyle) { + struct overview_planar_cell_struct *gp; + long ram_needed = + sizeof(struct overview_planar_cell_struct) * total_tiles_used; + if (fseek(tilefile_O, (long) TIBHEADER_SIZE, + SEEK_SET)) { /*failure*/ + } + oramtiles = + (struct overview_planar_cell_struct *) alloc(ram_needed); + /* Todo: fall back to file method here if alloc failed */ + gp = oramtiles; + for (k = 0; k < total_tiles_used; ++k) { + fread(gp, sizeof(struct overview_planar_cell_struct), 1, + tilefile_O); + ++gp; + } #ifdef DEBUG_RAMTILES - pline("%d overview tiles read into ram.", k); - mark_synch(); + pline("%d overview tiles read into ram.", k); + mark_synch(); #endif - otiles_in_ram = TRUE; - } else { - struct planar_cell_struct *gp; - long ram_needed = sizeof(struct planar_cell_struct) * - total_tiles_used; - if (fseek(tilefile,(long)TIBHEADER_SIZE, SEEK_SET)) { /*failure*/ - } - ramtiles = (struct planar_cell_struct *)alloc(ram_needed); - /* Todo: fall back to file method here if alloc failed */ - gp = ramtiles; - for(k=0; k < total_tiles_used; ++k) { - fread(gp, sizeof(struct planar_cell_struct), - 1, tilefile); - ++gp; - } + otiles_in_ram = TRUE; + } else { + struct planar_cell_struct *gp; + long ram_needed = + sizeof(struct planar_cell_struct) * total_tiles_used; + if (fseek(tilefile, (long) TIBHEADER_SIZE, + SEEK_SET)) { /*failure*/ + } + ramtiles = (struct planar_cell_struct *) alloc(ram_needed); + /* Todo: fall back to file method here if alloc failed */ + gp = ramtiles; + for (k = 0; k < total_tiles_used; ++k) { + fread(gp, sizeof(struct planar_cell_struct), 1, tilefile); + ++gp; + } #ifdef DEBUG_RAMTILES - pline("%d tiles read into ram.", k); - mark_synch(); + pline("%d tiles read into ram.", k); + mark_synch(); #endif - tiles_in_ram = TRUE; - } + tiles_in_ram = TRUE; + } } #endif - return 0; + return 0; } void CloseTileFile(filestyle) boolean filestyle; { - fclose(filestyle ? tilefile_O : tilefile); + fclose(filestyle ? tilefile_O : tilefile); #ifdef TILES_IN_RAM - if (!filestyle && tiles_in_ram) { - if (ramtiles) free((genericptr_t) ramtiles); - tiles_in_ram = FALSE; - } else if (filestyle && otiles_in_ram) { - if (oramtiles) free((genericptr_t) oramtiles); - otiles_in_ram = FALSE; - } + if (!filestyle && tiles_in_ram) { + if (ramtiles) + free((genericptr_t) ramtiles); + tiles_in_ram = FALSE; + } else if (filestyle && otiles_in_ram) { + if (oramtiles) + free((genericptr_t) oramtiles); + otiles_in_ram = FALSE; + } #endif } @@ -184,72 +191,75 @@ struct overview_planar_cell_struct oplancell; * increasing the memory requirement - can't have everything). * */ -# ifdef PLANAR_FILE -int ReadPlanarTileFile(tilenum,gp) +#ifdef PLANAR_FILE +int +ReadPlanarTileFile(tilenum, gp) int tilenum; struct planar_cell_struct **gp; { - long fpos; + long fpos; #ifdef TILES_IN_RAM - if (tiles_in_ram) { - *gp = ramtiles + tilenum; - return 0; - } + if (tiles_in_ram) { + *gp = ramtiles + tilenum; + return 0; + } #endif - fpos = ((long)(tilenum) * (long)sizeof(struct planar_cell_struct)) + - (long)TIBHEADER_SIZE; - if (fseek(tilefile,fpos,SEEK_SET)) { - return 1; - } else { - fread(&plancell, sizeof(struct planar_cell_struct), 1, tilefile); - } - *gp = &plancell; - return 0; + fpos = ((long) (tilenum) * (long) sizeof(struct planar_cell_struct)) + + (long) TIBHEADER_SIZE; + if (fseek(tilefile, fpos, SEEK_SET)) { + return 1; + } else { + fread(&plancell, sizeof(struct planar_cell_struct), 1, tilefile); + } + *gp = &plancell; + return 0; } -int ReadPlanarTileFile_O(tilenum,gp) +int +ReadPlanarTileFile_O(tilenum, gp) int tilenum; struct overview_planar_cell_struct **gp; { - long fpos; + long fpos; #ifdef TILES_IN_RAM - if (otiles_in_ram) { - *gp = oramtiles + tilenum; - return 0; - } + if (otiles_in_ram) { + *gp = oramtiles + tilenum; + return 0; + } #endif - fpos = ((long)(tilenum) * - (long)sizeof(struct overview_planar_cell_struct)) + - (long)TIBHEADER_SIZE; - if (fseek(tilefile_O,fpos,SEEK_SET)) { - return 1; - } else { - fread(&oplancell, sizeof(struct overview_planar_cell_struct), - 1, tilefile_O); - } - *gp = &oplancell; - return 0; + fpos = + ((long) (tilenum) * (long) sizeof(struct overview_planar_cell_struct)) + + (long) TIBHEADER_SIZE; + if (fseek(tilefile_O, fpos, SEEK_SET)) { + return 1; + } else { + fread(&oplancell, sizeof(struct overview_planar_cell_struct), 1, + tilefile_O); + } + *gp = &oplancell; + return 0; } -# endif +#endif -# ifdef PACKED_FILE -int ReadPackedTileFile(tilenum,pta) +#ifdef PACKED_FILE +int +ReadPackedTileFile(tilenum, pta) int tilenum; char (*pta)[TILE_X]; { - long fpos; - - fpos = ((long)(tilenum) * (long)(TILE_Y * TILE_X) + - (long)TIBHEADER_SIZE); - if (fseek(tilefile,fpos,SEEK_SET)) { - return 1; - } else { - fread(pta, (TILE_Y * TILE_X), 1, tilefile); - } - return 0; + long fpos; + + fpos = + ((long) (tilenum) * (long) (TILE_Y * TILE_X) + (long) TIBHEADER_SIZE); + if (fseek(tilefile, fpos, SEEK_SET)) { + return 1; + } else { + fread(pta, (TILE_Y * TILE_X), 1, tilefile); + } + return 0; } -# endif +#endif #endif /* USE_TILES */ /* pctiles.c */ diff --git a/sys/msdos/sound.c b/sys/msdos/sound.c index cb9fb264b..eb9557564 100644 --- a/sys/msdos/sound.c +++ b/sys/msdos/sound.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 sound.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 sound.c $Date: 2009/05/06 10:49:43 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)sound.c 3.5 1996/02/19 */ /* Copyright (c) NetHack PC Development Team 1993,1995 */ @@ -23,40 +23,40 @@ #ifndef TESTING -#define printf pline +#define printf pline int assign_soundcard(sopt) char *sopt; { + iflags.hassound = 0; +#ifdef PCMUSIC + iflags.usepcspeaker = 0; +#endif - iflags.hassound = 0; -# ifdef PCMUSIC - iflags.usepcspeaker = 0; -# endif - - if (strncmpi(sopt,"def",3) == 0) { /* default */ - /* do nothing - default */ - } -# ifdef PCMUSIC - else if (strncmpi(sopt,"speaker",7) == 0) { /* pc speaker */ - iflags.usepcspeaker = 1; - } -# endif - else if (strncmpi(sopt,"auto",4) == 0) { /* autodetect */ - /* - * Auto-detect Priorities (arbitrary for now): - * Just pcspeaker - */ - if (0) ; -# ifdef PCMUSIC - else iflags.usepcspeaker = 1; -# endif - } else { - return 0; - } - return 1; - + if (strncmpi(sopt, "def", 3) == 0) { /* default */ + /* do nothing - default */ + } +#ifdef PCMUSIC + else if (strncmpi(sopt, "speaker", 7) == 0) { /* pc speaker */ + iflags.usepcspeaker = 1; + } +#endif + else if (strncmpi(sopt, "auto", 4) == 0) { /* autodetect */ + /* + * Auto-detect Priorities (arbitrary for now): + * Just pcspeaker + */ + if (0) + ; +#ifdef PCMUSIC + else + iflags.usepcspeaker = 1; +#endif + } else { + return 0; + } + return 1; } #endif @@ -64,78 +64,80 @@ char *sopt; /* 8254/3 Control Word Defines */ -#define CTR0SEL (0<<6) -#define CTR1SEL (1<<6) -#define CTR2SEL (2<<6) -#define RDBACK (3<<6) +#define CTR0SEL (0 << 6) +#define CTR1SEL (1 << 6) +#define CTR2SEL (2 << 6) +#define RDBACK (3 << 6) -#define LATCH (0<<4) -#define RW_LSB (1<<4) -#define RW_MSB (2<<4) /* If both LSB and MSB are read, LSB is done first */ +#define LATCH (0 << 4) +#define RW_LSB (1 << 4) +#define RW_MSB (2 << 4) /* If both LSB and MSB are read, LSB is done first \ + */ -#define MODE0 (0<<1) /* Interrupt on terminal count */ -#define MODE1 (1<<1) /* Hardware One-Shot */ -#define MODE2 (2<<1) /* Pulse Generator */ -#define MODE3 (3<<1) /* Square Wave Generator */ -#define MODE4 (4<<1) /* Software Triggered Strobe */ -#define MODE5 (5<<1) /* Hardware Triggered Strobe */ +#define MODE0 (0 << 1) /* Interrupt on terminal count */ +#define MODE1 (1 << 1) /* Hardware One-Shot */ +#define MODE2 (2 << 1) /* Pulse Generator */ +#define MODE3 (3 << 1) /* Square Wave Generator */ +#define MODE4 (4 << 1) /* Software Triggered Strobe */ +#define MODE5 (5 << 1) /* Hardware Triggered Strobe */ -#define BINARY (0<<0) /* Binary counter (16 bits) */ -#define BCD (1<<0) /* Binary Coded Decimal (BCD) Counter (4 Decades) */ +#define BINARY (0 << 0) /* Binary counter (16 bits) */ +#define BCD (1 << 0) /* Binary Coded Decimal (BCD) Counter (4 Decades) */ /* Misc 8254/3 Defines */ -#define TIMRFRQ (1193180UL) /* Input frequency to the clock (Hz) */ +#define TIMRFRQ (1193180UL) /* Input frequency to the clock (Hz) */ /* Speaker Defines */ -#define TIMER (1<<0) /* Timer 2 Output connected to Speaker */ -#define SPKR_ON (1<<1) /* Turn on/off Speaker */ +#define TIMER (1 << 0) /* Timer 2 Output connected to Speaker */ +#define SPKR_ON (1 << 1) /* Turn on/off Speaker */ /* Port Definitions */ /* 8254/3 Ports */ -#define CTR0 0x40 -#define CTR1 0x41 -#define CTR2 0x42 -#define CTRL 0x43 +#define CTR0 0x40 +#define CTR1 0x41 +#define CTR2 0x42 +#define CTRL 0x43 /* Speaker Port */ -#define SPEAKER 0x61 +#define SPEAKER 0x61 void -startsound (unsigned freq) +startsound(unsigned freq) { - /* To start a sound on the PC: - * - * First, set the second counter to have the correct frequency: - */ + /* To start a sound on the PC: + * + * First, set the second counter to have the correct frequency: + */ - unsigned count; + unsigned count; - if (freq == 0) freq = 523; + if (freq == 0) + freq = 523; - count = TIMRFRQ / freq; /* Divide frequencies to get count. */ + count = TIMRFRQ / freq; /* Divide frequencies to get count. */ #ifdef TESTING - printf ("freq = %u, count = %u\n", freq, count); + printf("freq = %u, count = %u\n", freq, count); #endif - outportb (CTRL, CTR2SEL|RW_LSB|RW_MSB|MODE3|BINARY); - outportb (CTR2, count & 0x0FF); - outportb (CTR2, count / 0x100); + outportb(CTRL, CTR2SEL | RW_LSB | RW_MSB | MODE3 | BINARY); + outportb(CTR2, count & 0x0FF); + outportb(CTR2, count / 0x100); - /* Next, turn on the speaker */ + /* Next, turn on the speaker */ - outportb (SPEAKER, inportb(SPEAKER)|TIMER|SPKR_ON); + outportb(SPEAKER, inportb(SPEAKER) | TIMER | SPKR_ON); } void -stopsound (void) +stopsound(void) { - outportb (SPEAKER, inportb(SPEAKER) & ~(TIMER|SPKR_ON)); + outportb(SPEAKER, inportb(SPEAKER) & ~(TIMER | SPKR_ON)); } static unsigned tempo, length, octave, mtype; @@ -154,97 +156,117 @@ static unsigned tempo, length, octave, mtype; * number. */ -unsigned long notefactors[12] = { 483852, 456695, 431063, 406869, 384033, - 362479, 342135, 322932, 304808, 287700, 271553, 256312 }; +unsigned long notefactors[12] = { 483852, 456695, 431063, 406869, + 384033, 362479, 342135, 322932, + 304808, 287700, 271553, 256312 }; void -note (long notenum) +note(long notenum) { - startsound ((unsigned) (4050816000UL / notefactors[notenum % 12] - >> (7 - notenum / 12))); + startsound((unsigned) (4050816000UL / notefactors[notenum % 12] + >> (7 - notenum / 12))); } int notes[7] = { 9, 11, 0, 2, 4, 5, 7 }; char * -startnote (char *c) +startnote(char *c) { - long n; + long n; - n = notes[toupper(*c++) - 'A'] + octave * 12; - if (*c == '#' || *c == '+') { n++; c++; } - else if (*c == '-') { if (n) n--; c++; } + n = notes[toupper(*c++) - 'A'] + octave * 12; + if (*c == '#' || *c == '+') { + n++; + c++; + } else if (*c == '-') { + if (n) + n--; + c++; + } - note (n); + note(n); - return --c; + return --c; } void -delaytime (unsigned time) +delaytime(unsigned time) { - /* time and twait are in units of milliseconds */ + /* time and twait are in units of milliseconds */ - unsigned twait; + unsigned twait; - switch (toupper (mtype)) { - case 'S': twait = time / 4; break; - case 'L': twait = 0; break; - default: twait = time / 8; break; - } + switch (toupper(mtype)) { + case 'S': + twait = time / 4; + break; + case 'L': + twait = 0; + break; + default: + twait = time / 8; + break; + } - msleep (time - twait); - stopsound (); - msleep (twait); + msleep(time - twait); + stopsound(); + msleep(twait); } char * -delaynote (char *c) +delaynote(char *c) { - unsigned time = 0; + unsigned time = 0; - while (isdigit(*c)) time = time * 10 + (*c++ - '0'); + while (isdigit(*c)) + time = time * 10 + (*c++ - '0'); - if (!time) time = length; + if (!time) + time = length; - time = (unsigned)(240000 / time / tempo); + time = (unsigned) (240000 / time / tempo); - while (*c == '.') { time = time * 3 / 2; c++; } + while (*c == '.') { + time = time * 3 / 2; + c++; + } - delaytime (time); + delaytime(time); - return c; + return c; } void -initspeaker (void) +initspeaker(void) { - tempo = 120, length = 4, octave = 3, mtype = 'N'; + tempo = 120, length = 4, octave = 3, mtype = 'N'; } - void -play (char *tune) +play(char *tune) { - char *c, *n; - unsigned num; + char *c, *n; + unsigned num; - for (c = tune; *c; ) { - sscanf (c + 1, "%u", &num); - for (n = c + 1; isdigit(*n); n++) /* do nothing */; - if (isspace(*c)) c++; - else switch (toupper(*c)) { - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - c = startnote (c); - case 'P': - c = delaynote (++c); - break; + for (c = tune; *c;) { + sscanf(c + 1, "%u", &num); + for (n = c + 1; isdigit(*n); n++) /* do nothing */ + ; + if (isspace(*c)) + c++; + else + switch (toupper(*c)) { + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + c = startnote(c); + case 'P': + c = delaynote(++c); + break; #if 0 case 'M': c++; mtype = *c; c++; break; case 'T': @@ -270,62 +292,72 @@ play (char *tune) case '>': if (octave < 7) octave++; c++; break; case '<': if (octave) octave--; c++; break; #endif - case ' ': c++; break; - default: - printf ("Unrecognized play value (%s)!\n", c); - return; - } - } + case ' ': + c++; + break; + default: + printf("Unrecognized play value (%s)!\n", c); + return; + } + } } #ifndef TESTING void -pc_speaker (struct obj *instr, char *tune) +pc_speaker(struct obj *instr, char *tune) { - if (!iflags.usepcspeaker) return; - initspeaker (); - switch (instr->otyp) - { - case WOODEN_FLUTE: - case MAGIC_FLUTE: - octave = 5; /* up one octave */ - break; - case TOOLED_HORN: - case FROST_HORN: - case FIRE_HORN: - octave = 2; /* drop two octaves */ - break; - case BUGLE: - break; - case WOODEN_HARP: - case MAGIC_HARP: - length = 8; - mtype = 'L'; /* fast, legato */ - break; + if (!iflags.usepcspeaker) + return; + initspeaker(); + switch (instr->otyp) { + case WOODEN_FLUTE: + case MAGIC_FLUTE: + octave = 5; /* up one octave */ + break; + case TOOLED_HORN: + case FROST_HORN: + case FIRE_HORN: + octave = 2; /* drop two octaves */ + break; + case BUGLE: + break; + case WOODEN_HARP: + case MAGIC_HARP: + length = 8; + mtype = 'L'; /* fast, legato */ + break; } - play (tune); + play(tune); } #else -main () +main() { - char s[80]; - int tool; + char s[80]; + int tool; - initspeaker(); - printf ("1) flute\n2) horn\n3) harp\n4) other\n"); - fgets (s, 80, stdin); - sscanf (s, "%d", &tool); - switch (tool) { - case 1: octave = 5; break; - case 2: octave = 2; break; - case 3: length = 8; mtype = 'L'; break; - default: break; - } - printf ("Enter tune:"); - fgets(s, 80, stdin); - play (s); + initspeaker(); + printf("1) flute\n2) horn\n3) harp\n4) other\n"); + fgets(s, 80, stdin); + sscanf(s, "%d", &tool); + switch (tool) { + case 1: + octave = 5; + break; + case 2: + octave = 2; + break; + case 3: + length = 8; + mtype = 'L'; + break; + default: + break; + } + printf("Enter tune:"); + fgets(s, 80, stdin); + play(s); } #endif diff --git a/sys/msdos/tile2bin.c b/sys/msdos/tile2bin.c index b1e56d799..b117257c1 100644 --- a/sys/msdos/tile2bin.c +++ b/sys/msdos/tile2bin.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tile2bin.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 tile2bin.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 tile2bin.c $Date: 2009/05/06 10:49:47 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)tile2bin.c 3.5 1995/01/26 */ /* Copyright (c) NetHack PC Development Team 1993, 1994, 1995 */ @@ -14,7 +14,6 @@ * */ - #include "hack.h" #include "pcvideo.h" #include "tile.h" @@ -31,10 +30,10 @@ #endif #if defined(_MSC_VER) && _MSC_VER >= 700 -#pragma warning(disable:4309) /* initializing */ -#pragma warning(disable:4018) /* signed/unsigned mismatch */ -#pragma warning(disable:4131) /* old style declarator */ -#pragma warning(disable:4127) /* conditional express. is constant */ +#pragma warning(disable : 4309) /* initializing */ +#pragma warning(disable : 4018) /* signed/unsigned mismatch */ +#pragma warning(disable : 4131) /* old style declarator */ +#pragma warning(disable : 4127) /* conditional express. is constant */ #endif #ifdef __BORLANDC__ @@ -44,7 +43,7 @@ extern unsigned _stklen = STKSIZ; extern char *FDECL(tilename, (int, int)); #ifdef PLANAR_FILE -char masktable[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; +char masktable[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; char charcolors[MAXCOLORMAPSIZE]; #ifdef OVERVIEW_FILE struct overview_planar_cell_struct planetile; @@ -65,16 +64,14 @@ struct tibhdr_struct tibheader; static void FDECL(write_tibtile, (int)); static void FDECL(write_tibheader, (FILE *, struct tibhdr_struct *)); -static void FDECL(build_tibtile, (pixel (*)[TILE_X])); +static void FDECL(build_tibtile, (pixel(*) [TILE_X])); #ifndef OVERVIEW_FILE -char *tilefiles[] = { "../win/share/monsters.txt", - "../win/share/objects.txt", - "../win/share/other.txt"}; +char *tilefiles[] = { "../win/share/monsters.txt", "../win/share/objects.txt", + "../win/share/other.txt" }; #else -char *tilefiles[] = { "../win/share/monthin.txt", - "../win/share/objthin.txt", - "../win/share/oththin.txt"}; +char *tilefiles[] = { "../win/share/monthin.txt", "../win/share/objthin.txt", + "../win/share/oththin.txt" }; #endif int tilecount; @@ -86,229 +83,221 @@ main(argc, argv) int argc; char *argv[]; { - int i; - struct tm *newtime; - time_t aclock; - char *paletteptr; + int i; + struct tm *newtime; + time_t aclock; + char *paletteptr; - if (argc != 1) { - Fprintf(stderr, "usage: tile2bin (from the util directory)\n"); - exit(EXIT_FAILURE); - } + if (argc != 1) { + Fprintf(stderr, "usage: tile2bin (from the util directory)\n"); + exit(EXIT_FAILURE); + } #ifdef PLANAR_FILE -# ifndef OVERVIEW_FILE - tibfile1 = fopen(NETHACK_PLANAR_TILEFILE, WRBMODE); -# else - tibfile1 = fopen(NETHACK_OVERVIEW_TILEFILE, WRBMODE); -# endif - if (tibfile1 == (FILE *)0) { - Fprintf(stderr, "Unable to open output file %s\n", -# ifndef OVERVIEW_FILE - NETHACK_PLANAR_TILEFILE); +#ifndef OVERVIEW_FILE + tibfile1 = fopen(NETHACK_PLANAR_TILEFILE, WRBMODE); #else - NETHACK_OVERVIEW_TILEFILE); + tibfile1 = fopen(NETHACK_OVERVIEW_TILEFILE, WRBMODE); #endif - exit(EXIT_FAILURE); - } + if (tibfile1 == (FILE *) 0) { + Fprintf(stderr, "Unable to open output file %s\n", +#ifndef OVERVIEW_FILE + NETHACK_PLANAR_TILEFILE); +#else + NETHACK_OVERVIEW_TILEFILE); +#endif + exit(EXIT_FAILURE); + } #endif #ifdef PACKED_FILE - tibfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); - if (tibfile2 == (FILE *)0) { - Fprintf(stderr, "Unable to open output file %s\n", - NETHACK_PACKED_TILEFILE); - exit(EXIT_FAILURE); - } + tibfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); + if (tibfile2 == (FILE *) 0) { + Fprintf(stderr, "Unable to open output file %s\n", + NETHACK_PACKED_TILEFILE); + exit(EXIT_FAILURE); + } #endif - time(&aclock); - newtime = localtime(&aclock); + time(&aclock); + newtime = localtime(&aclock); - tilecount = 0; - paletteflag = 0; - filenum = 0; - while (filenum < 3) { - if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { - Fprintf(stderr, - "usage: tile2bin (from the util or src directory)\n"); - exit(EXIT_FAILURE); - } - num_colors = colorsinmap; - if (num_colors > 62) { - Fprintf(stderr, "too many colors (%d)\n", num_colors); - exit(EXIT_FAILURE); - } + tilecount = 0; + paletteflag = 0; + filenum = 0; + while (filenum < 3) { + if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { + Fprintf(stderr, + "usage: tile2bin (from the util or src directory)\n"); + exit(EXIT_FAILURE); + } + num_colors = colorsinmap; + if (num_colors > 62) { + Fprintf(stderr, "too many colors (%d)\n", num_colors); + exit(EXIT_FAILURE); + } - if (!paletteflag) { - paletteptr = tibheader.palette; - for (i = 0; i < num_colors; i++) { - *paletteptr++ = ColorMap[CM_RED][i], - *paletteptr++ = ColorMap[CM_GREEN][i], - *paletteptr++ = ColorMap[CM_BLUE][i]; - } - paletteflag++; - } + if (!paletteflag) { + paletteptr = tibheader.palette; + for (i = 0; i < num_colors; i++) { + *paletteptr++ = ColorMap[CM_RED][i], + *paletteptr++ = ColorMap[CM_GREEN][i], + *paletteptr++ = ColorMap[CM_BLUE][i]; + } + paletteflag++; + } - - while (read_text_tile(pixels)) { - build_tibtile(pixels); - write_tibtile(tilecount); - tilecount++; - } + while (read_text_tile(pixels)) { + build_tibtile(pixels); + write_tibtile(tilecount); + tilecount++; + } - (void) fclose_text_file(); - ++filenum; - } + (void) fclose_text_file(); + ++filenum; + } -# if defined(_MSC_VER) - tibheader.compiler = MSC_COMP; -# elif defined(__BORLANDC__) - tibheader.compiler = BC_COMP; -# elif defined(__GO32__) - tibheader.compiler = DJGPP_COMP; -# else - tibheader.compiler = OTHER_COMP; -# endif - - strncpy(tibheader.ident, - "NetHack 3.6 MSDOS Port binary tile file", 80); - strncpy(tibheader.timestamp, asctime(newtime), 24); - tibheader.timestamp[25] = '\0'; - tibheader.tilecount = tilecount; - tibheader.numcolors = num_colors; -# ifdef PLANAR_FILE - tibheader.tilestyle = PLANAR_STYLE; - write_tibheader(tibfile1, &tibheader); - (void) fclose(tibfile1); -# ifndef OVERVIEW_FILE - Fprintf(stderr, "Total of %d planar tiles written to %s.\n", - tilecount, NETHACK_PLANAR_TILEFILE); -# else - Fprintf(stderr, "Total of %d planar tiles written to %s.\n", - tilecount, NETHACK_OVERVIEW_TILEFILE); -# endif -# endif +#if defined(_MSC_VER) + tibheader.compiler = MSC_COMP; +#elif defined(__BORLANDC__) + tibheader.compiler = BC_COMP; +#elif defined(__GO32__) + tibheader.compiler = DJGPP_COMP; +#else + tibheader.compiler = OTHER_COMP; +#endif -# ifdef PACKED_FILE - tibheader.tilestyle = PACKED_STYLE; - write_tibheader(tibfile2, &tibheader); - Fprintf(stderr, "Total of %d packed tiles written to %s.\n", - tilecount, NETHACK_PACKED_TILEFILE); - (void) fclose(tibfile2); -# endif + strncpy(tibheader.ident, "NetHack 3.6 MSDOS Port binary tile file", 80); + strncpy(tibheader.timestamp, asctime(newtime), 24); + tibheader.timestamp[25] = '\0'; + tibheader.tilecount = tilecount; + tibheader.numcolors = num_colors; +#ifdef PLANAR_FILE + tibheader.tilestyle = PLANAR_STYLE; + write_tibheader(tibfile1, &tibheader); + (void) fclose(tibfile1); +#ifndef OVERVIEW_FILE + Fprintf(stderr, "Total of %d planar tiles written to %s.\n", tilecount, + NETHACK_PLANAR_TILEFILE); +#else + Fprintf(stderr, "Total of %d planar tiles written to %s.\n", tilecount, + NETHACK_OVERVIEW_TILEFILE); +#endif +#endif - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; +#ifdef PACKED_FILE + tibheader.tilestyle = PACKED_STYLE; + write_tibheader(tibfile2, &tibheader); + Fprintf(stderr, "Total of %d packed tiles written to %s.\n", tilecount, + NETHACK_PACKED_TILEFILE); + (void) fclose(tibfile2); +#endif + + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } - static void -write_tibheader(fileptr,tibhdr) +write_tibheader(fileptr, tibhdr) FILE *fileptr; struct tibhdr_struct *tibhdr; { - - if (fseek(fileptr,0L,SEEK_SET)) { - Fprintf(stderr, "Error writing header to tile file\n"); - } - fwrite(tibhdr, sizeof(struct tibhdr_struct), 1, fileptr); + if (fseek(fileptr, 0L, SEEK_SET)) { + Fprintf(stderr, "Error writing header to tile file\n"); + } + fwrite(tibhdr, sizeof(struct tibhdr_struct), 1, fileptr); } static void build_tibtile(pixels) pixel (*pixels)[TILE_X]; { - int i, j, k, co_off; - unsigned char co_mask,tmp; + int i, j, k, co_off; + unsigned char co_mask, tmp; #ifndef OVERVIEW_FILE - memset((void *)&planetile,0,sizeof(struct planar_cell_struct)); + memset((void *) &planetile, 0, sizeof(struct planar_cell_struct)); #else - memset((void *)&planetile,0, - sizeof(struct overview_planar_cell_struct)); + memset((void *) &planetile, 0, + sizeof(struct overview_planar_cell_struct)); #endif - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - for (k = 0; k < num_colors; k++) { - if (ColorMap[CM_RED][k] == pixels[j][i].r && - ColorMap[CM_GREEN][k] == pixels[j][i].g && - ColorMap[CM_BLUE][k] == pixels[j][i].b) - break; - } - if (k >= num_colors) - Fprintf(stderr, "color not in colormap!\n"); + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + for (k = 0; k < num_colors; k++) { + if (ColorMap[CM_RED][k] == pixels[j][i].r + && ColorMap[CM_GREEN][k] == pixels[j][i].g + && ColorMap[CM_BLUE][k] == pixels[j][i].b) + break; + } + if (k >= num_colors) + Fprintf(stderr, "color not in colormap!\n"); #ifdef PACKED_FILE - packtile[j][i] = k; + packtile[j][i] = k; #endif #ifdef PLANAR_FILE - if (i > 7) { - co_off = 1; - co_mask = masktable[i - 8]; - } else { - co_off = 0; - co_mask = masktable[i]; - } + if (i > 7) { + co_off = 1; + co_mask = masktable[i - 8]; + } else { + co_off = 0; + co_mask = masktable[i]; + } - tmp = planetile.plane[0].image[j][co_off]; - planetile.plane[0].image[j][co_off] = (k & 0x0008) ? - (tmp | co_mask) : - (tmp & ~co_mask); + tmp = planetile.plane[0].image[j][co_off]; + planetile.plane[0].image[j][co_off] = + (k & 0x0008) ? (tmp | co_mask) : (tmp & ~co_mask); - tmp = planetile.plane[1].image[j][co_off]; - planetile.plane[1].image[j][co_off] = (k & 0x0004) ? - (tmp | co_mask) : - (tmp & ~co_mask); + tmp = planetile.plane[1].image[j][co_off]; + planetile.plane[1].image[j][co_off] = + (k & 0x0004) ? (tmp | co_mask) : (tmp & ~co_mask); - tmp = planetile.plane[2].image[j][co_off]; - planetile.plane[2].image[j][co_off] = (k & 0x0002) ? - (tmp | co_mask) : - (tmp & ~co_mask); + tmp = planetile.plane[2].image[j][co_off]; + planetile.plane[2].image[j][co_off] = + (k & 0x0002) ? (tmp | co_mask) : (tmp & ~co_mask); - tmp = planetile.plane[3].image[j][co_off]; - planetile.plane[3].image[j][co_off] = (k & 0x0001) ? - (tmp | co_mask) : - (tmp & ~co_mask); + tmp = planetile.plane[3].image[j][co_off]; + planetile.plane[3].image[j][co_off] = + (k & 0x0001) ? (tmp | co_mask) : (tmp & ~co_mask); #endif /* PLANAR_FILE */ - } - } + } + } } static void write_tibtile(recnum) int recnum; { - long fpos; + long fpos; #ifdef PLANAR_FILE -# ifndef OVERVIEW_FILE - fpos = ((long)(recnum) * (long)sizeof(struct planar_cell_struct)) + - (long)TIBHEADER_SIZE; -# else - fpos = ((long)(recnum) * - (long)sizeof(struct overview_planar_cell_struct)) + - (long)TIBHEADER_SIZE; -# endif - if (fseek(tibfile1,fpos,SEEK_SET)) { - Fprintf(stderr, "Error seeking before planar tile write %d\n", - recnum); - } -# ifndef OVERVIEW_FILE - fwrite(&planetile, sizeof(struct planar_cell_struct), 1, tibfile1); -# else - fwrite(&planetile, - sizeof(struct overview_planar_cell_struct), 1, tibfile1); -# endif +#ifndef OVERVIEW_FILE + fpos = ((long) (recnum) * (long) sizeof(struct planar_cell_struct)) + + (long) TIBHEADER_SIZE; +#else + fpos = + ((long) (recnum) * (long) sizeof(struct overview_planar_cell_struct)) + + (long) TIBHEADER_SIZE; +#endif + if (fseek(tibfile1, fpos, SEEK_SET)) { + Fprintf(stderr, "Error seeking before planar tile write %d\n", + recnum); + } +#ifndef OVERVIEW_FILE + fwrite(&planetile, sizeof(struct planar_cell_struct), 1, tibfile1); +#else + fwrite(&planetile, sizeof(struct overview_planar_cell_struct), 1, + tibfile1); +#endif #endif #ifdef PACKED_FILE - fpos = ((long)(recnum) * (long)sizeof(packtile)) + - (long)TIBHEADER_SIZE; - if (fseek(tibfile2,fpos,SEEK_SET)) { - Fprintf(stderr, "Error seeking before packed tile write %d\n", - recnum); - } - fwrite(&packtile, sizeof(packtile), 1, tibfile2); + fpos = + ((long) (recnum) * (long) sizeof(packtile)) + (long) TIBHEADER_SIZE; + if (fseek(tibfile2, fpos, SEEK_SET)) { + Fprintf(stderr, "Error seeking before packed tile write %d\n", + recnum); + } + fwrite(&packtile, sizeof(packtile), 1, tibfile2); #endif } diff --git a/sys/msdos/video.c b/sys/msdos/video.c index f3fa219f7..0f83ac883 100644 --- a/sys/msdos/video.c +++ b/sys/msdos/video.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 video.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 video.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 video.c $Date: 2009/05/06 10:49:49 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)video.c 3.5 2001/04/07 */ /* Copyright (c) NetHack PC Development Team 1993, 1994, 2001 */ @@ -22,14 +22,14 @@ #include "pctiles.h" #if defined(_MSC_VER) -# if _MSC_VER >= 700 -#pragma warning(disable:4018) /* signed/unsigned mismatch */ -#pragma warning(disable:4127) /* conditional expression is constant */ -#pragma warning(disable:4131) /* old style declarator */ -#pragma warning(disable:4305) /* prevents complaints with MK_FP */ -#pragma warning(disable:4309) /* initializing */ -#pragma warning(disable:4759) /* prevents complaints with MK_FP */ -# endif +#if _MSC_VER >= 700 +#pragma warning(disable : 4018) /* signed/unsigned mismatch */ +#pragma warning(disable : 4127) /* conditional expression is constant */ +#pragma warning(disable : 4131) /* old style declarator */ +#pragma warning(disable : 4305) /* prevents complaints with MK_FP */ +#pragma warning(disable : 4309) /* initializing */ +#pragma warning(disable : 4759) /* prevents complaints with MK_FP */ +#endif #endif /*========================================================================= * General PC Video routines. @@ -42,29 +42,29 @@ * * - Supported defaults.nh file video options: * - * If OPTIONS=video:autodetect is defined in defaults.nh then - * check for a VGA video adapter. If one is detected, then - * use the VGA code, otherwise resort to using the 'standard' + * If OPTIONS=video:autodetect is defined in defaults.nh then + * check for a VGA video adapter. If one is detected, then + * use the VGA code, otherwise resort to using the 'standard' * video BIOS routines. * - * If OPTIONS=video:vga is defined in defaults.nh, then use + * If OPTIONS=video:vga is defined in defaults.nh, then use * the VGA code. * * If OPTIONS=video:default is defined in defaults.nh use the - * 'standard' video BIOS routines (in the overlaid version), - * or DJGPPFAST routines (under djgpp). This is equivalent to + * 'standard' video BIOS routines (in the overlaid version), + * or DJGPPFAST routines (under djgpp). This is equivalent to * having no OPTIONS=video:xxxx entry at all. * * Notes (94/04/23): * - * - The handler for defaults.nh file entry: - * - * OPTIONS=video:xxxxx + * - The handler for defaults.nh file entry: * - * has now been added. The handler is in video.c and is called + * OPTIONS=video:xxxxx + * + * has now been added. The handler is in video.c and is called * from options.c. * - * - Handling of videocolors and videoshades are now done with + * - Handling of videocolors and videoshades are now done with * OPTIONS= statements. The new syntax separates the colour * values with dashes ('-') rather than spaces (' '). * @@ -74,16 +74,15 @@ *========================================================================= */ - void get_scr_size() { -# ifdef SCREEN_VGA - if (iflags.usevga) { - vga_get_scr_size(); - } else -# endif - txt_get_scr_size(); +#ifdef SCREEN_VGA + if (iflags.usevga) { + vga_get_scr_size(); + } else +#endif + txt_get_scr_size(); } /* @@ -97,189 +96,181 @@ get_scr_size() #include #include "wintty.h" -# ifdef __GO32__ +#ifdef __GO32__ #include #include #if !(__DJGPP__ >= 2) typedef long clock_t; #endif -# endif +#endif -# ifdef __BORLANDC__ -#include /* needed for delay() */ -# endif +#ifdef __BORLANDC__ +#include /* needed for delay() */ +#endif -# ifdef SCREEN_DJGPPFAST /* parts of this block may be unecessary now */ -#define get_cursor(x,y) ScreenGetCursor(y,x) -# endif +#ifdef SCREEN_DJGPPFAST /* parts of this block may be unecessary now */ +#define get_cursor(x, y) ScreenGetCursor(y, x) +#endif -# ifdef SCREEN_BIOS +#ifdef SCREEN_BIOS void FDECL(get_cursor, (int *, int *)); -# endif +#endif void FDECL(adjust_cursor_flags, (struct WinDesc *)); void FDECL(cmov, (int, int)); void FDECL(nocmov, (int, int)); STATIC_DCL void NDECL(init_ttycolor); -int savevmode; /* store the original video mode in here */ -int curcol,currow; /* graphics mode current cursor locations */ -int g_attribute; /* Current attribute to use */ -int monoflag; /* 0 = not monochrome, else monochrome */ -int attrib_text_normal; /* text mode normal attribute */ -int attrib_gr_normal; /* graphics mode normal attribute */ -int attrib_text_intense; /* text mode intense attribute */ -int attrib_gr_intense; /* graphics mode intense attribute */ +int savevmode; /* store the original video mode in here */ +int curcol, currow; /* graphics mode current cursor locations */ +int g_attribute; /* Current attribute to use */ +int monoflag; /* 0 = not monochrome, else monochrome */ +int attrib_text_normal; /* text mode normal attribute */ +int attrib_gr_normal; /* graphics mode normal attribute */ +int attrib_text_intense; /* text mode intense attribute */ +int attrib_gr_intense; /* graphics mode intense attribute */ boolean traditional = FALSE; /* traditonal TTY character mode */ -boolean inmap = FALSE; /* in the map window */ -# ifdef TEXTCOLOR -char ttycolors[CLR_MAX]; /* also used/set in options.c */ -# endif /* TEXTCOLOR */ +boolean inmap = FALSE; /* in the map window */ +#ifdef TEXTCOLOR +char ttycolors[CLR_MAX]; /* also used/set in options.c */ +#endif /* TEXTCOLOR */ void backsp() { - if (!iflags.grmode) { - txt_backsp(); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_backsp(); -# endif - } + if (!iflags.grmode) { + txt_backsp(); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_backsp(); +#endif + } } void clear_screen() { - if (!iflags.grmode) { - txt_clear_screen(); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_clear_screen(BACKGROUND_VGA_COLOR); -# endif - } + if (!iflags.grmode) { + txt_clear_screen(); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_clear_screen(BACKGROUND_VGA_COLOR); +#endif + } } -void -cl_end() /* clear to end of line */ +void cl_end() /* clear to end of line */ { - int col,row; + int col, row; - col = (int)ttyDisplay->curx; - row = (int)ttyDisplay->cury; - if (!iflags.grmode) { - txt_cl_end(col,row); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_cl_end(col,row); -# endif - } - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, - (int)ttyDisplay->cury); + col = (int) ttyDisplay->curx; + row = (int) ttyDisplay->cury; + if (!iflags.grmode) { + txt_cl_end(col, row); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_cl_end(col, row); +#endif + } + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury); } -void -cl_eos() /* clear to end of screen */ +void cl_eos() /* clear to end of screen */ { - int cy = (int)ttyDisplay->cury+1; + int cy = (int) ttyDisplay->cury + 1; - if (!iflags.grmode) { - txt_cl_eos(); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_cl_eos(cy); -# endif - } - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, - (int)ttyDisplay->cury); + if (!iflags.grmode) { + txt_cl_eos(); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_cl_eos(cy); +#endif + } + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury); } void cmov(col, row) register int col, row; { - ttyDisplay->cury = (uchar)row; - ttyDisplay->curx = (uchar)col; - if (!iflags.grmode) { - txt_gotoxy(col,row); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_gotoloc(col,row); -# endif - } + ttyDisplay->cury = (uchar) row; + ttyDisplay->curx = (uchar) col; + if (!iflags.grmode) { + txt_gotoxy(col, row); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_gotoloc(col, row); +#endif + } } int has_color(int color) { - ++color; /* prevents compiler warning (unref. param) */ -# ifdef TEXTCOLOR - return (monoflag) ? 0 : 1; -# else - return 0; -# endif + ++color; /* prevents compiler warning (unref. param) */ +#ifdef TEXTCOLOR + return (monoflag) ? 0 : 1; +#else + return 0; +#endif } void home() { - tty_curs(BASE_WINDOW, 1, 0); - ttyDisplay->curx = ttyDisplay->cury = (uchar)0; - if (!iflags.grmode) { - txt_gotoxy(0,0); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_gotoloc(0,0); -# endif - } + tty_curs(BASE_WINDOW, 1, 0); + ttyDisplay->curx = ttyDisplay->cury = (uchar) 0; + if (!iflags.grmode) { + txt_gotoxy(0, 0); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_gotoloc(0, 0); +#endif + } } void nocmov(col, row) -int col,row; +int col, row; { - if (!iflags.grmode) { - txt_gotoxy(col,row); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_gotoloc(col,row); -# endif - } + if (!iflags.grmode) { + txt_gotoxy(col, row); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_gotoloc(col, row); +#endif + } } void standoutbeg() { - g_attribute = iflags.grmode ? attrib_gr_intense - : attrib_text_intense; + g_attribute = iflags.grmode ? attrib_gr_intense : attrib_text_intense; } void standoutend() { - g_attribute = iflags.grmode ? attrib_gr_normal - : attrib_text_normal; + g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; } void term_end_attr(int attr) { - switch(attr) { - case ATR_ULINE: - case ATR_BOLD: - case ATR_BLINK: - case ATR_INVERSE: - default: - g_attribute = iflags.grmode ? attrib_gr_normal - : attrib_text_normal; - } + switch (attr) { + case ATR_ULINE: + case ATR_BOLD: + case ATR_BLINK: + case ATR_INVERSE: + default: + g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; + } } void term_end_color(void) { - g_attribute = iflags.grmode ? attrib_gr_normal - : attrib_text_normal; + g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; } void @@ -288,63 +279,58 @@ term_end_raw_bold(void) standoutend(); } - void term_start_attr(int attr) { - switch(attr){ - - case ATR_ULINE: - if (monoflag) { - g_attribute = ATTRIB_MONO_UNDERLINE; - } else { - g_attribute = iflags.grmode ? attrib_gr_intense - : attrib_text_intense; - } - break; - case ATR_BOLD: - g_attribute = iflags.grmode ? attrib_gr_intense - : attrib_text_intense; - break; - case ATR_BLINK: - if (monoflag) { - g_attribute = ATTRIB_MONO_BLINK; - } else { - g_attribute = iflags.grmode ? attrib_gr_intense - : attrib_text_intense; - } - break; - case ATR_INVERSE: - if (monoflag) { - g_attribute = ATTRIB_MONO_REVERSE; - } else { - g_attribute = iflags.grmode ? attrib_gr_intense - : attrib_text_intense; - } - break; - default: - g_attribute = iflags.grmode ? attrib_gr_normal - : attrib_text_normal; - break; + switch (attr) { + case ATR_ULINE: + if (monoflag) { + g_attribute = ATTRIB_MONO_UNDERLINE; + } else { + g_attribute = + iflags.grmode ? attrib_gr_intense : attrib_text_intense; + } + break; + case ATR_BOLD: + g_attribute = iflags.grmode ? attrib_gr_intense : attrib_text_intense; + break; + case ATR_BLINK: + if (monoflag) { + g_attribute = ATTRIB_MONO_BLINK; + } else { + g_attribute = + iflags.grmode ? attrib_gr_intense : attrib_text_intense; + } + break; + case ATR_INVERSE: + if (monoflag) { + g_attribute = ATTRIB_MONO_REVERSE; + } else { + g_attribute = + iflags.grmode ? attrib_gr_intense : attrib_text_intense; + } + break; + default: + g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; + break; } } - void term_start_color(int color) { -# ifdef TEXTCOLOR - if (monoflag) { - g_attribute = attrib_text_normal; - } else { - if (color >= 0 && color < CLR_MAX) { - if (iflags.grmode) - g_attribute = color; - else - g_attribute = ttycolors[color]; - } - } -# endif +#ifdef TEXTCOLOR + if (monoflag) { + g_attribute = attrib_text_normal; + } else { + if (color >= 0 && color < CLR_MAX) { + if (iflags.grmode) + g_attribute = color; + else + g_attribute = ttycolors[color]; + } + } +#endif } void @@ -357,130 +343,129 @@ void tty_delay_output() { #ifdef TIMED_DELAY - if (flags.nap) { - (void) fflush(stdout); - msleep(50); /* sleep for 50 milliseconds */ - return; - } + if (flags.nap) { + (void) fflush(stdout); + msleep(50); /* sleep for 50 milliseconds */ + return; + } #endif } void tty_end_screen() { - - if (!iflags.grmode) { - txt_clear_screen(); -# ifdef PC9800 - fputs("\033[>1l", stdout); -# endif -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_tty_end_screen(); -# endif - } + if (!iflags.grmode) { + txt_clear_screen(); +#ifdef PC9800 + fputs("\033[>1l", stdout); +#endif +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_tty_end_screen(); +#endif + } } void tty_nhbell() { - txt_nhbell(); + txt_nhbell(); } - void tty_number_pad(state) int state; { - ++state; /* prevents compiler warning (unref. param) */ + ++state; /* prevents compiler warning (unref. param) */ } void tty_startup(wid, hgt) int *wid, *hgt; { + /* code to sense display adapter is required here - MJA */ - /* code to sense display adapter is required here - MJA */ + attrib_text_normal = ATTRIB_NORMAL; + attrib_text_intense = ATTRIB_INTENSE; - attrib_text_normal = ATTRIB_NORMAL; - attrib_text_intense = ATTRIB_INTENSE; + /* These are defaults and may get overridden */ + attrib_gr_normal = attrib_text_normal; + attrib_gr_intense = attrib_text_intense; + g_attribute = attrib_text_normal; /* Give it a starting value */ - /* These are defaults and may get overridden */ - attrib_gr_normal = attrib_text_normal; - attrib_gr_intense = attrib_text_intense; - g_attribute = attrib_text_normal; /* Give it a starting value */ +#ifdef SCREEN_VGA + if (iflags.usevga) { + vga_tty_startup(wid, hgt); + } else +#endif + txt_startup(wid, hgt); -# ifdef SCREEN_VGA - if (iflags.usevga) { - vga_tty_startup(wid, hgt); - } else -# endif - txt_startup(wid, hgt); + *wid = CO; + *hgt = LI; - *wid = CO; - *hgt = LI; +#ifdef CLIPPING + if (CO < COLNO || LI < ROWNO + 3) + setclipped(); +#endif -# ifdef CLIPPING - if (CO < COLNO || LI < ROWNO+3) setclipped(); -# endif - -# ifdef TEXTCOLOR - init_ttycolor(); -# endif - -# ifdef MONO_CHECK - monoflag = txt_monoadapt_check(); -# else - monoflag = 0; -# endif +#ifdef TEXTCOLOR + init_ttycolor(); +#endif +#ifdef MONO_CHECK + monoflag = txt_monoadapt_check(); +#else + monoflag = 0; +#endif } void tty_start_screen() { -# ifdef PC9800 - fputs("\033[>1h", stdout); -# endif - if (iflags.num_pad) tty_number_pad(1); /* make keypad send digits */ +#ifdef PC9800 + fputs("\033[>1h", stdout); +#endif + if (iflags.num_pad) + tty_number_pad(1); /* make keypad send digits */ } void -gr_init(){ - if (iflags.usevga) { -# ifdef SCREEN_VGA - vga_Init(); -# endif -# ifdef SCREEN_VESA - } else if (iflags.usevesa) { - vesa_Init(); +gr_init() +{ + if (iflags.usevga) { +#ifdef SCREEN_VGA + vga_Init(); +#endif +#ifdef SCREEN_VESA + } else if (iflags.usevesa) { + vesa_Init(); -# endif -# ifdef SCREEN_8514 - } else if (iflags.use8514) { - v8514_Init(); -# endif - } +#endif +#ifdef SCREEN_8514 + } else if (iflags.use8514) { + v8514_Init(); +#endif + } } void gr_finish() { - if (iflags.grmode) { - if (iflags.usevga) { -# ifdef SCREEN_VGA - vga_Finish(); -# endif -# ifdef SCREEN_VESA - } else if (iflags.usevesa) { - vesa_Finish(); -# endif -# ifdef SCREEN_8514 - } else if (iflags.use8514) { - v8514_Finish(); -# endif - } - } + if (iflags.grmode) { + if (iflags.usevga) { +#ifdef SCREEN_VGA + vga_Finish(); +#endif +#ifdef SCREEN_VESA + } else if (iflags.usevesa) { + vesa_Finish(); +#endif +#ifdef SCREEN_8514 + } else if (iflags.use8514) { + v8514_Finish(); +#endif + } + } } /* @@ -517,93 +502,91 @@ void xputs(s) const char *s; { - int col,row; + int col, row; - col = (int)ttyDisplay->curx; - row = (int)ttyDisplay->cury; + col = (int) ttyDisplay->curx; + row = (int) ttyDisplay->cury; - if (!iflags.grmode) { - txt_xputs(s,col,row); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_xputs(s,col,row); -# endif - } + if (!iflags.grmode) { + txt_xputs(s, col, row); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_xputs(s, col, row); +#endif + } } -void -xputc(ch) /* write out character (and attribute) */ +void xputc(ch) /* write out character (and attribute) */ char ch; { - int i; - char attribute; + int i; + char attribute; - i = iflags.grmode ? attrib_gr_normal - : attrib_text_normal; + i = iflags.grmode ? attrib_gr_normal : attrib_text_normal; - attribute = (char)((g_attribute == 0) ? i : g_attribute); - if (!iflags.grmode) { - txt_xputc(ch,attribute); -# ifdef SCREEN_VGA - } else if (iflags.usevga) { - vga_xputc(ch,attribute); -# endif /*SCREEN_VGA*/ - } + attribute = (char) ((g_attribute == 0) ? i : g_attribute); + if (!iflags.grmode) { + txt_xputc(ch, attribute); +#ifdef SCREEN_VGA + } else if (iflags.usevga) { + vga_xputc(ch, attribute); +#endif /*SCREEN_VGA*/ + } } -void -xputg(glyphnum,ch,special) /* write out a glyph picture at current location */ +void xputg(glyphnum, ch, + special) /* write out a glyph picture at current location */ int glyphnum; int ch; unsigned special; { - if (!iflags.grmode || !iflags.tile_view) { - xputc((char)ch); -# ifdef SCREEN_VGA - } else { - vga_xputg(glyphnum, ch, special); -# endif - } + if (!iflags.grmode || !iflags.tile_view) { + xputc((char) ch); +#ifdef SCREEN_VGA + } else { + vga_xputg(glyphnum, ch, special); +#endif + } } -# ifdef POSITIONBAR +#ifdef POSITIONBAR void video_update_positionbar(posbar) char *posbar; { - if (!iflags.grmode) - return; -# ifdef SCREEN_VGA - else - vga_update_positionbar(posbar); -# endif + if (!iflags.grmode) + return; +#ifdef SCREEN_VGA + else + vga_update_positionbar(posbar); +#endif } -# endif +#endif void adjust_cursor_flags(cw) struct WinDesc *cw; { -# ifdef SIMULATE_CURSOR -# if 0 +#ifdef SIMULATE_CURSOR +#if 0 if (cw->type == NHW_MAP) cursor_flag = 1; else cursor_flag = 0; -# else +#else if (cw->type == NHW_MAP) { - inmap = 1; - cursor_flag = 1; + inmap = 1; + cursor_flag = 1; } else { - inmap = 0; - cursor_flag = 1; + inmap = 0; + cursor_flag = 1; } -# endif /* 0 */ -# endif /* SIMULATE_CURSOR */ +#endif /* 0 */ +#endif /* SIMULATE_CURSOR */ } -# ifdef SIMULATE_CURSOR +#ifdef SIMULATE_CURSOR /* change the defaults in pcvideo.h, not here */ -int cursor_type = CURSOR_DEFAULT_STYLE; +int cursor_type = CURSOR_DEFAULT_STYLE; int cursor_color = CURSOR_DEFAULT_COLOR; int cursor_flag; @@ -611,22 +594,22 @@ int cursor_flag; void DrawCursor() { -# ifdef SCREEN_VGA - vga_DrawCursor(); -# endif +#ifdef SCREEN_VGA + vga_DrawCursor(); +#endif } void HideCursor() { -# ifdef SCREEN_VGA - vga_HideCursor(); -# endif +#ifdef SCREEN_VGA + vga_HideCursor(); +#endif } -# endif /* SIMULATE_CURSOR */ +#endif /* SIMULATE_CURSOR */ -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR /* * CLR_BLACK 0 * CLR_RED 1 @@ -648,116 +631,130 @@ HideCursor() * BRIGHT 8 */ -# ifdef VIDEOSHADES +#ifdef VIDEOSHADES /* assign_videoshades() is prototyped in extern.h */ /* assign_videocolors() is prototyped in extern.h */ /* assign_video() is prototyped in extern.h */ -int shadeflag; /* shades are initialized */ -int colorflag; /* colors are initialized */ -char *schoice[3] = {"dark","normal","light"}; +int shadeflag; /* shades are initialized */ +int colorflag; /* colors are initialized */ +char *schoice[3] = { "dark", "normal", "light" }; char *shade[3]; -# endif /* VIDEOSHADES */ +#endif /* VIDEOSHADES */ STATIC_OVL void init_ttycolor() { -# ifdef VIDEOSHADES - if (!shadeflag) { - ttycolors[CLR_BLACK] = M_BLACK; /* 8 = dark gray */ - ttycolors[CLR_WHITE] = M_WHITE; /* 15 = bright white */ - ttycolors[CLR_GRAY] = M_GRAY; /* 7 = normal white */ - shade[0] = schoice[0]; - shade[1] = schoice[1]; - shade[2] = schoice[2]; - } -# else - ttycolors[CLR_BLACK] = M_GRAY; /* mapped to white */ - ttycolors[CLR_WHITE] = M_GRAY; /* mapped to white */ - ttycolors[CLR_GRAY] = M_GRAY; /* mapped to white */ -# endif +#ifdef VIDEOSHADES + if (!shadeflag) { + ttycolors[CLR_BLACK] = M_BLACK; /* 8 = dark gray */ + ttycolors[CLR_WHITE] = M_WHITE; /* 15 = bright white */ + ttycolors[CLR_GRAY] = M_GRAY; /* 7 = normal white */ + shade[0] = schoice[0]; + shade[1] = schoice[1]; + shade[2] = schoice[2]; + } +#else + ttycolors[CLR_BLACK] = M_GRAY; /* mapped to white */ + ttycolors[CLR_WHITE] = M_GRAY; /* mapped to white */ + ttycolors[CLR_GRAY] = M_GRAY; /* mapped to white */ +#endif -# ifdef VIDEOSHADES - if (!colorflag) { -# endif - ttycolors[CLR_RED] = M_RED; - ttycolors[CLR_GREEN] = M_GREEN; - ttycolors[CLR_BROWN] = M_BROWN; - ttycolors[CLR_BLUE] = M_BLUE; - ttycolors[CLR_MAGENTA] = M_MAGENTA; - ttycolors[CLR_CYAN] = M_CYAN; - ttycolors[BRIGHT] = M_WHITE; - ttycolors[CLR_ORANGE] = M_ORANGE; - ttycolors[CLR_BRIGHT_GREEN] = M_BRIGHTGREEN; - ttycolors[CLR_YELLOW] = M_YELLOW; - ttycolors[CLR_BRIGHT_BLUE] = M_BRIGHTBLUE; - ttycolors[CLR_BRIGHT_MAGENTA] = M_BRIGHTMAGENTA; - ttycolors[CLR_BRIGHT_CYAN] = M_BRIGHTCYAN; -# ifdef VIDEOSHADES - } -# endif +#ifdef VIDEOSHADES + if (!colorflag) { +#endif + ttycolors[CLR_RED] = M_RED; + ttycolors[CLR_GREEN] = M_GREEN; + ttycolors[CLR_BROWN] = M_BROWN; + ttycolors[CLR_BLUE] = M_BLUE; + ttycolors[CLR_MAGENTA] = M_MAGENTA; + ttycolors[CLR_CYAN] = M_CYAN; + ttycolors[BRIGHT] = M_WHITE; + ttycolors[CLR_ORANGE] = M_ORANGE; + ttycolors[CLR_BRIGHT_GREEN] = M_BRIGHTGREEN; + ttycolors[CLR_YELLOW] = M_YELLOW; + ttycolors[CLR_BRIGHT_BLUE] = M_BRIGHTBLUE; + ttycolors[CLR_BRIGHT_MAGENTA] = M_BRIGHTMAGENTA; + ttycolors[CLR_BRIGHT_CYAN] = M_BRIGHTCYAN; +#ifdef VIDEOSHADES + } +#endif } - static int FDECL(convert_uchars,(char *, uchar *, int)); -# ifdef VIDEOSHADES -int assign_videoshades(char *choiceptr) +static int FDECL(convert_uchars, (char *, uchar *, int)); +#ifdef VIDEOSHADES +int +assign_videoshades(char *choiceptr) { - char choices[120]; - char *cptr, *cvalue[3]; - int i,icolor = CLR_WHITE; + char choices[120]; + char *cptr, *cvalue[3]; + int i, icolor = CLR_WHITE; - strcpy(choices,choiceptr); - cvalue[0] = choices; + strcpy(choices, choiceptr); + cvalue[0] = choices; - /* find the next ' ' or tab */ - cptr = index(cvalue[0], '-'); - if (!cptr) cptr = index(cvalue[0], ' '); - if (!cptr) cptr = index(cvalue[0], '\t'); - if (!cptr) return 0; - *cptr = '\0'; - /* skip whitespace between '=' and value */ - do { ++cptr; } while (isspace(*cptr) || (*cptr == '-')); - cvalue[1] = cptr; + /* find the next ' ' or tab */ + cptr = index(cvalue[0], '-'); + if (!cptr) + cptr = index(cvalue[0], ' '); + if (!cptr) + cptr = index(cvalue[0], '\t'); + if (!cptr) + return 0; + *cptr = '\0'; + /* skip whitespace between '=' and value */ + do { + ++cptr; + } while (isspace(*cptr) || (*cptr == '-')); + cvalue[1] = cptr; - cptr = index(cvalue[1], '-'); - if (!cptr) cptr = index(cvalue[0], ' '); - if (!cptr) cptr = index(cvalue[0], '\t'); - if (!cptr) return 0; - *cptr = '\0'; - do { ++cptr; } while (isspace(*cptr) || (*cptr == '-')); - cvalue[2] = cptr; + cptr = index(cvalue[1], '-'); + if (!cptr) + cptr = index(cvalue[0], ' '); + if (!cptr) + cptr = index(cvalue[0], '\t'); + if (!cptr) + return 0; + *cptr = '\0'; + do { + ++cptr; + } while (isspace(*cptr) || (*cptr == '-')); + cvalue[2] = cptr; - for (i=0; i < 3; ++i) { - switch(i) { - case 0: icolor = CLR_BLACK; - break; - case 1: icolor = CLR_GRAY; - break; - case 2: icolor = CLR_WHITE; - break; - } + for (i = 0; i < 3; ++i) { + switch (i) { + case 0: + icolor = CLR_BLACK; + break; + case 1: + icolor = CLR_GRAY; + break; + case 2: + icolor = CLR_WHITE; + break; + } - shadeflag = 1; - if ((strncmpi(cvalue[i],"black",5) == 0) || - (strncmpi(cvalue[i],"dark",4) == 0)) { - shade[i] = schoice[0]; - ttycolors[icolor] = M_BLACK; /* dark gray */ - } else if ((strncmpi(cvalue[i],"gray",4) == 0) || - (strncmpi(cvalue[i],"grey",4) == 0) || - (strncmpi(cvalue[i],"medium",6) == 0) || - (strncmpi(cvalue[i],"normal",6) == 0)) { - shade[i] = schoice[1]; - ttycolors[icolor] = M_GRAY; /* regular gray */ - } else if ((strncmpi(cvalue[i],"white",5) == 0) || - (strncmpi(cvalue[i],"light",5) == 0)) { - shade[i] = schoice[2]; - ttycolors[icolor] = M_WHITE; /* bright white */ - } else { - shadeflag = 0; - return 0; - } - } - return 1; + shadeflag = 1; + if ((strncmpi(cvalue[i], "black", 5) == 0) + || (strncmpi(cvalue[i], "dark", 4) == 0)) { + shade[i] = schoice[0]; + ttycolors[icolor] = M_BLACK; /* dark gray */ + } else if ((strncmpi(cvalue[i], "gray", 4) == 0) + || (strncmpi(cvalue[i], "grey", 4) == 0) + || (strncmpi(cvalue[i], "medium", 6) == 0) + || (strncmpi(cvalue[i], "normal", 6) == 0)) { + shade[i] = schoice[1]; + ttycolors[icolor] = M_GRAY; /* regular gray */ + } else if ((strncmpi(cvalue[i], "white", 5) == 0) + || (strncmpi(cvalue[i], "light", 5) == 0)) { + shade[i] = schoice[2]; + ttycolors[icolor] = M_WHITE; /* bright white */ + } else { + shadeflag = 0; + return 0; + } + } + return 1; } /* @@ -768,65 +765,76 @@ int assign_videoshades(char *choiceptr) * * Default Mapping (BIOS): 4-2-6-1-5-3-12-10-14-9-13-11 */ -int assign_videocolors(char *colorvals) +int +assign_videocolors(char *colorvals) { - int i,icolor; - uchar *tmpcolor; + int i, icolor; + uchar *tmpcolor; - init_ttycolor(); /* in case defaults.nh entry wasn't complete */ - i = strlen(colorvals); - tmpcolor = (uchar *)alloc(i); - (void)convert_uchars(colorvals,tmpcolor,i); - icolor = CLR_RED; - for( i = 0; tmpcolor[i] != 0; ++i) { - if (icolor < (CLR_WHITE)) { - ttycolors[icolor++] = tmpcolor[i]; - if ((icolor > CLR_CYAN) && (icolor < CLR_ORANGE)) { - icolor = CLR_ORANGE; - } - } - } - colorflag = 1; - free((genericptr_t)tmpcolor); - return 1; + init_ttycolor(); /* in case defaults.nh entry wasn't complete */ + i = strlen(colorvals); + tmpcolor = (uchar *) alloc(i); + (void) convert_uchars(colorvals, tmpcolor, i); + icolor = CLR_RED; + for (i = 0; tmpcolor[i] != 0; ++i) { + if (icolor < (CLR_WHITE)) { + ttycolors[icolor++] = tmpcolor[i]; + if ((icolor > CLR_CYAN) && (icolor < CLR_ORANGE)) { + icolor = CLR_ORANGE; + } + } + } + colorflag = 1; + free((genericptr_t) tmpcolor); + return 1; } static int -convert_uchars(bufp,list,size) - char *bufp; /* current pointer */ - uchar *list; /* return list */ - int size; +convert_uchars(bufp, list, size) +char *bufp; /* current pointer */ +uchar *list; /* return list */ +int size; { unsigned int num = 0; int count = 0; while (1) { - switch(*bufp) { - case ' ': case '\0': - case '\t': case '-': - case '\n': - if (num) { - list[count++] = num; - num = 0; - } - if ((count==size) || !*bufp) return count; - bufp++; - break; + switch (*bufp) { + case ' ': + case '\0': + case '\t': + case '-': + case '\n': + if (num) { + list[count++] = num; + num = 0; + } + if ((count == size) || !*bufp) + return count; + bufp++; + break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - num = num*10 + (*bufp-'0'); - bufp++; - break; - return count; - } + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + num = num * 10 + (*bufp - '0'); + bufp++; + break; + return count; + } } /*NOTREACHED*/ } -# endif /* VIDEOSHADES */ -# endif /* TEXTCOLOR */ +#endif /* VIDEOSHADES */ +#endif /* TEXTCOLOR */ /* * Process defaults.nh OPTIONS=video:xxxx @@ -841,82 +849,83 @@ int assign_video(sopt) char *sopt; { + /* + * debug + * + * printf("video is %s",sopt); + * getch(); + */ + iflags.grmode = 0; + iflags.hasvga = 0; + iflags.usevga = 0; -/* - * debug - * - * printf("video is %s",sopt); - * getch(); - */ - iflags.grmode = 0; - iflags.hasvga = 0; - iflags.usevga = 0; - - if (strncmpi(sopt,"def",3) == 0) { /* default */ - /* do nothing - default */ -# ifdef SCREEN_VGA - } else if (strncmpi(sopt,"vga",3) == 0) { /* vga */ - iflags.usevga = 1; - iflags.hasvga = 1; -# endif -# ifdef SCREEN_VESA - } else if (strncmpi(sopt,"vesa",4) == 0) { /* vesa */ - iflags.hasvesa = 1; - iflags.usevesa = 1; -# endif -# ifdef SCREEN_8514 - } else if (strncmpi(sopt,"8514",4) == 0) { /* 8514/A */ - iflags.use8514 = 1; - iflags.has8514 = 1; -# endif - } else if (strncmpi(sopt,"auto",4) == 0) { /* autodetect */ -# ifdef SCREEN_VESA - if (vesa_detect()) { - iflags.hasvesa = 1; - } -# endif -# ifdef SCREEN_8514 - if (v8514_detect()) { - iflags.has8514 = 1; - } -# endif -# ifdef SCREEN_VGA - if (vga_detect()) { - iflags.hasvga = 1; - } -# endif - /* - * Auto-detect Priorities (arbitrary for now): - * VGA - */ - if (iflags.hasvga) { - iflags.usevga = 1; - /* VGA depends on BIOS to enable function keys*/ - iflags.BIOS = 1; - iflags.rawio = 1; - } - } else { - return 0; - } - return 1; + if (strncmpi(sopt, "def", 3) == 0) { /* default */ + /* do nothing - default */ +#ifdef SCREEN_VGA + } else if (strncmpi(sopt, "vga", 3) == 0) { /* vga */ + iflags.usevga = 1; + iflags.hasvga = 1; +#endif +#ifdef SCREEN_VESA + } else if (strncmpi(sopt, "vesa", 4) == 0) { /* vesa */ + iflags.hasvesa = 1; + iflags.usevesa = 1; +#endif +#ifdef SCREEN_8514 + } else if (strncmpi(sopt, "8514", 4) == 0) { /* 8514/A */ + iflags.use8514 = 1; + iflags.has8514 = 1; +#endif + } else if (strncmpi(sopt, "auto", 4) == 0) { /* autodetect */ +#ifdef SCREEN_VESA + if (vesa_detect()) { + iflags.hasvesa = 1; + } +#endif +#ifdef SCREEN_8514 + if (v8514_detect()) { + iflags.has8514 = 1; + } +#endif +#ifdef SCREEN_VGA + if (vga_detect()) { + iflags.hasvga = 1; + } +#endif + /* + * Auto-detect Priorities (arbitrary for now): + * VGA + */ + if (iflags.hasvga) { + iflags.usevga = 1; + /* VGA depends on BIOS to enable function keys*/ + iflags.BIOS = 1; + iflags.rawio = 1; + } + } else { + return 0; + } + return 1; } -void tileview(enable) +void +tileview(enable) boolean enable; { #ifdef SCREEN_VGA - if (iflags.grmode) vga_traditional(enable ? FALSE : TRUE); + if (iflags.grmode) + vga_traditional(enable ? FALSE : TRUE); #endif } #endif /* NO_TERMS */ -#else /* STUBVIDEO */ +#else /* STUBVIDEO */ -void tileview(enable) +void +tileview(enable) boolean enable; { } #endif /* STUBVIDEO */ /*video.c*/ - diff --git a/sys/msdos/vidtxt.c b/sys/msdos/vidtxt.c index 6cdecaffc..393829577 100644 --- a/sys/msdos/vidtxt.c +++ b/sys/msdos/vidtxt.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vidtxt.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vidtxt.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 vidtxt.c $Date: 2009/05/06 10:49:49 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)vidtxt.c 3.5 1994/04/04 */ /* Copyright (c) NetHack PC Development Team 1993 */ @@ -6,7 +6,7 @@ /* */ /* * vidtxt.c - Textmode video hardware support (BIOS and DJGPPFAST) - * + * *Edit History: * Initial Creation M. Allison 93/04/04 * Add djgpp support K. Smolkowski 93/04/26 @@ -23,66 +23,67 @@ #include #if defined(_MSC_VER) -# if _MSC_VER >= 700 -#pragma warning(disable:4018) /* signed/unsigned mismatch */ -#pragma warning(disable:4127) /* conditional expression is constant */ -#pragma warning(disable:4131) /* old style declarator */ -#pragma warning(disable:4305) /* prevents complaints with MK_FP */ -#pragma warning(disable:4309) /* initializing */ -#pragma warning(disable:4759) /* prevents complaints with MK_FP */ -# endif +#if _MSC_VER >= 700 +#pragma warning(disable : 4018) /* signed/unsigned mismatch */ +#pragma warning(disable : 4127) /* conditional expression is constant */ +#pragma warning(disable : 4131) /* old style declarator */ +#pragma warning(disable : 4305) /* prevents complaints with MK_FP */ +#pragma warning(disable : 4309) /* initializing */ +#pragma warning(disable : 4759) /* prevents complaints with MK_FP */ +#endif #endif -/* void FDECL(txt_xputc,(char, int)); */ /* write out character (and attribute) */ +/* void FDECL(txt_xputc,(char, int)); */ /* write out character (and + attribute) */ -extern int attrib_text_normal; /* text mode normal attribute */ -extern int attrib_gr_normal; /* graphics mode normal attribute */ -extern int attrib_text_intense; /* text mode intense attribute */ -extern int attrib_gr_intense; /* graphics mode intense attribute */ +extern int attrib_text_normal; /* text mode normal attribute */ +extern int attrib_gr_normal; /* graphics mode normal attribute */ +extern int attrib_text_intense; /* text mode intense attribute */ +extern int attrib_gr_intense; /* graphics mode intense attribute */ void txt_get_scr_size() { - union REGS regs; + union REGS regs; - if (!iflags.BIOS) { - CO = 80; - LI = 24; - return; - } + if (!iflags.BIOS) { + CO = 80; + LI = 24; + return; + } -# ifdef PC9800 - regs.h.ah = SENSEMODE; - (void) int86(CRT_BIOS, ®s, ®s); +#ifdef PC9800 + regs.h.ah = SENSEMODE; + (void) int86(CRT_BIOS, ®s, ®s); - CO = (regs.h.al & 0x02) ? 40 : 80; - LI = (regs.h.al & 0x01) ? 20 : 25; -# else - regs.x.ax = FONTINFO; - regs.x.bx = 0; /* current ROM BIOS font */ - regs.h.dl = 24; /* default row count */ - /* in case no EGA/MCGA/VGA */ - (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Font Information */ + CO = (regs.h.al & 0x02) ? 40 : 80; + LI = (regs.h.al & 0x01) ? 20 : 25; +#else + regs.x.ax = FONTINFO; + regs.x.bx = 0; /* current ROM BIOS font */ + regs.h.dl = 24; /* default row count */ + /* in case no EGA/MCGA/VGA */ + (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Font Information */ - /* MDA/CGA/PCjr ignore INT 10h, Function 11h, but since we - * cleverly loaded up DL with the default, everything's fine. - * - * Otherwise, DL now contains rows - 1. Also, CX contains the - * points (bytes per character) and ES:BP points to the font - * table. -3. - */ + /* MDA/CGA/PCjr ignore INT 10h, Function 11h, but since we + * cleverly loaded up DL with the default, everything's fine. + * + * Otherwise, DL now contains rows - 1. Also, CX contains the + * points (bytes per character) and ES:BP points to the font + * table. -3. + */ - regs.h.ah = GETMODE; - (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Video Mode */ + regs.h.ah = GETMODE; + (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Video Mode */ - /* This goes back all the way to the original PC. Completely - * safe. AH contains # of columns, AL contains display mode, - * and BH contains the active display page. - */ + /* This goes back all the way to the original PC. Completely + * safe. AH contains # of columns, AL contains display mode, + * and BH contains the active display page. + */ - LI = regs.h.dl + 1; - CO = regs.h.ah; -# endif /* PC9800 */ + LI = regs.h.dl + 1; + CO = regs.h.ah; +#endif /* PC9800 */ } /* @@ -94,54 +95,56 @@ txt_get_scr_size() #ifdef NO_TERMS /* #include "wintty.h" */ -# ifdef SCREEN_DJGPPFAST +#ifdef SCREEN_DJGPPFAST #include #include -# endif +#endif -void FDECL(txt_gotoxy, (int,int)); +void FDECL(txt_gotoxy, (int, int)); -# if defined(SCREEN_BIOS) && !defined(PC9800) +#if defined(SCREEN_BIOS) && !defined(PC9800) void FDECL(txt_get_cursor, (int *, int *)); -# endif +#endif -# ifdef SCREEN_DJGPPFAST -#define txt_get_cursor(x,y) ScreenGetCursor(y,x) -# endif +#ifdef SCREEN_DJGPPFAST +#define txt_get_cursor(x, y) ScreenGetCursor(y, x) +#endif -extern int g_attribute; /* Current attribute to use */ -extern int monoflag; /* 0 = not monochrome, else monochrome */ +extern int g_attribute; /* Current attribute to use */ +extern int monoflag; /* 0 = not monochrome, else monochrome */ void txt_backsp() { -# ifdef PC9800 - union REGS regs; +#ifdef PC9800 + union REGS regs; - regs.h.dl = 0x01; /* one column */ - regs.h.ah = CURSOR_LEFT; - regs.h.cl = DIRECT_CON_IO; + regs.h.dl = 0x01; /* one column */ + regs.h.ah = CURSOR_LEFT; + regs.h.cl = DIRECT_CON_IO; - int86(DOS_EXT_FUNC, ®s, ®s); + int86(DOS_EXT_FUNC, ®s, ®s); -# else - int col,row; +#else + int col, row; - txt_get_cursor(&col, &row); - if (col > 0) col = col-1; - txt_gotoxy(col,row); -# endif + txt_get_cursor(&col, &row); + if (col > 0) + col = col - 1; + txt_gotoxy(col, row); +#endif } void txt_nhbell() { - union REGS regs; + union REGS regs; - if (flags.silent) return; - regs.h.dl = 0x07; /* bell */ - regs.h.ah = 0x02; /* Character Output function */ - (void) int86(DOSCALL, ®s, ®s); + if (flags.silent) + return; + regs.h.dl = 0x07; /* bell */ + regs.h.ah = 0x02; /* Character Output function */ + (void) int86(DOSCALL, ®s, ®s); } void @@ -150,118 +153,116 @@ txt_clear_screen() * so for now we just use the BIOS Routines */ { - union REGS regs; -# ifdef PC9800 - regs.h.dl = attr98[attrib_text_normal]; - regs.h.ah = SETATT; - regs.h.cl = DIRECT_CON_IO; + union REGS regs; +#ifdef PC9800 + regs.h.dl = attr98[attrib_text_normal]; + regs.h.ah = SETATT; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); + (void) int86(DOS_EXT_FUNC, ®s, ®s); - regs.h.dl = 0x02; /* clear whole screen */ - regs.h.ah = SCREEN_CLEAR; - regs.h.cl = DIRECT_CON_IO; + regs.h.dl = 0x02; /* clear whole screen */ + regs.h.ah = SCREEN_CLEAR; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); -# else - regs.h.dl = (char)(CO - 1); /* columns */ - regs.h.dh = (char)(LI - 1); /* rows */ - regs.x.cx = 0; /* CL,CH = x,y of upper left */ - regs.x.ax = 0; - regs.x.bx = 0; - regs.h.bh = (char)attrib_text_normal; - regs.h.ah = (char)SCROLL; - /* DL,DH = x,y of lower rt */ - (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or init window */ - txt_gotoxy(0,0); -# endif + (void) int86(DOS_EXT_FUNC, ®s, ®s); +#else + regs.h.dl = (char) (CO - 1); /* columns */ + regs.h.dh = (char) (LI - 1); /* rows */ + regs.x.cx = 0; /* CL,CH = x,y of upper left */ + regs.x.ax = 0; + regs.x.bx = 0; + regs.h.bh = (char) attrib_text_normal; + regs.h.ah = (char) SCROLL; + /* DL,DH = x,y of lower rt */ + (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or init window */ + txt_gotoxy(0, 0); +#endif } -void -txt_cl_end(col,row) /* clear to end of line */ -int col,row; +void txt_cl_end(col, row) /* clear to end of line */ +int col, row; { - union REGS regs; -# ifndef PC9800 - int count; -# endif + union REGS regs; +#ifndef PC9800 + int count; +#endif -# ifdef PC9800 - regs.h.dl = attr98[attrib_text_normal]; - regs.h.ah = SETATT; - regs.h.cl = DIRECT_CON_IO; +#ifdef PC9800 + regs.h.dl = attr98[attrib_text_normal]; + regs.h.ah = SETATT; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); + (void) int86(DOS_EXT_FUNC, ®s, ®s); - regs.h.dl = 0x00; /* clear to end of line */ - regs.h.ah = LINE_CLEAR; - regs.h.cl = DIRECT_CON_IO; + regs.h.dl = 0x00; /* clear to end of line */ + regs.h.ah = LINE_CLEAR; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); -# else - count = CO - col; - txt_gotoxy(col,row); - regs.h.ah = PUTCHARATT; /* write attribute & character */ - regs.h.al = ' '; /* character */ - regs.h.bh = 0; /* display page */ - /* BL = attribute */ - regs.h.bl = (char)attrib_text_normal; - regs.x.cx = count; - if (count != 0) - (void) int86(VIDEO_BIOS, ®s, ®s); /* write attribute - & character */ -# endif + (void) int86(DOS_EXT_FUNC, ®s, ®s); +#else + count = CO - col; + txt_gotoxy(col, row); + regs.h.ah = PUTCHARATT; /* write attribute & character */ + regs.h.al = ' '; /* character */ + regs.h.bh = 0; /* display page */ + /* BL = attribute */ + regs.h.bl = (char) attrib_text_normal; + regs.x.cx = count; + if (count != 0) + (void) int86(VIDEO_BIOS, ®s, ®s); /* write attribute + & character */ +#endif } -void -txt_cl_eos() /* clear to end of screen */ +void txt_cl_eos() /* clear to end of screen */ { - union REGS regs; -# ifndef PC9800 - int col,row; -# endif + union REGS regs; +#ifndef PC9800 + int col, row; +#endif -# ifdef PC9800 - regs.h.dl = attr98[attrib_text_normal]; - regs.h.ah = SETATT; - regs.h.cl = DIRECT_CON_IO; +#ifdef PC9800 + regs.h.dl = attr98[attrib_text_normal]; + regs.h.ah = SETATT; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); + (void) int86(DOS_EXT_FUNC, ®s, ®s); - regs.h.dl = 0x00; /* clear to end of screen */ - regs.h.ah = SCREEN_CLEAR; - regs.h.cl = DIRECT_CON_IO; + regs.h.dl = 0x00; /* clear to end of screen */ + regs.h.ah = SCREEN_CLEAR; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); -# else - txt_get_cursor(&col, &row); - txt_cl_end(col,row); /* clear to end of line */ - txt_gotoxy(0,(row < (LI-1) ? row+1 : (LI-1))); - regs.h.dl = (char) (CO-1); /* X of lower right */ - regs.h.dh = (char) (LI-1); /* Y of lower right */ - regs.h.cl = 0; /* X of upper left */ - /* Y (row) of upper left */ - regs.h.ch = (char) (row < (LI-1) ? row+1 :(LI-1)); - regs.x.cx = 0; - regs.x.ax = 0; - regs.x.bx = 0; - regs.h.bh = (char)attrib_text_normal; - regs.h.ah = SCROLL; - (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or initialize window */ -# endif + (void) int86(DOS_EXT_FUNC, ®s, ®s); +#else + txt_get_cursor(&col, &row); + txt_cl_end(col, row); /* clear to end of line */ + txt_gotoxy(0, (row < (LI - 1) ? row + 1 : (LI - 1))); + regs.h.dl = (char) (CO - 1); /* X of lower right */ + regs.h.dh = (char) (LI - 1); /* Y of lower right */ + regs.h.cl = 0; /* X of upper left */ + /* Y (row) of upper left */ + regs.h.ch = (char) (row < (LI - 1) ? row + 1 : (LI - 1)); + regs.x.cx = 0; + regs.x.ax = 0; + regs.x.bx = 0; + regs.h.bh = (char) attrib_text_normal; + regs.h.ah = SCROLL; + (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or initialize window */ +#endif } void txt_startup(wid, hgt) - int *wid, *hgt; +int *wid, *hgt; { - txt_get_scr_size(); - *wid = CO; - *hgt = LI; + txt_get_scr_size(); + *wid = CO; + *hgt = LI; - attrib_gr_normal = attrib_text_normal; - attrib_gr_intense = attrib_text_intense; - g_attribute = attrib_text_normal; /* Give it a starting value */ + attrib_gr_normal = attrib_text_normal; + attrib_gr_intense = attrib_text_intense; + g_attribute = attrib_text_normal; /* Give it a starting value */ } /* @@ -289,80 +290,81 @@ txt_startup(wid, hgt) */ void -txt_xputs(s,col,row) +txt_xputs(s, col, row) const char *s; -int col,row; +int col, row; { - char c; + char c; - if (s != (char *)0) { - while (*s != '\0') { - txt_gotoxy(col,row); - c = *s++; - txt_xputc(c,g_attribute); - if (col < (CO-1)) col++; - txt_gotoxy(col,row); - } - } + if (s != (char *) 0) { + while (*s != '\0') { + txt_gotoxy(col, row); + c = *s++; + txt_xputc(c, g_attribute); + if (col < (CO - 1)) + col++; + txt_gotoxy(col, row); + } + } } -void -txt_xputc(ch,attr) /* write out character (and attribute) */ +void txt_xputc(ch, attr) /* write out character (and attribute) */ char ch; int attr; { -# ifdef PC9800 - union REGS regs; +#ifdef PC9800 + union REGS regs; - regs.h.dl = attr98[attr]; - regs.h.ah = SETATT; - regs.h.cl = DIRECT_CON_IO; + regs.h.dl = attr98[attr]; + regs.h.ah = SETATT; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); + (void) int86(DOS_EXT_FUNC, ®s, ®s); - if (ch == '\n') { - regs.h.dl = '\r'; - regs.h.ah = PUTCHAR; - regs.h.cl = DIRECT_CON_IO; + if (ch == '\n') { + regs.h.dl = '\r'; + regs.h.ah = PUTCHAR; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); - } - regs.h.dl = ch; - regs.h.ah = PUTCHAR; - regs.h.cl = DIRECT_CON_IO; + (void) int86(DOS_EXT_FUNC, ®s, ®s); + } + regs.h.dl = ch; + regs.h.ah = PUTCHAR; + regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); -# else -# ifdef SCREEN_BIOS - union REGS regs; -# endif - int col,row; + (void) int86(DOS_EXT_FUNC, ®s, ®s); +#else +#ifdef SCREEN_BIOS + union REGS regs; +#endif + int col, row; - txt_get_cursor(&col,&row); - switch(ch) { - case '\n': + txt_get_cursor(&col, &row); + switch (ch) { + case '\n': #if 0 col = 0; ++row; #endif - break; - default: -# ifdef SCREEN_DJGPPFAST - ScreenPutChar((int)ch,attr,col,row); -# endif -# ifdef SCREEN_BIOS - regs.h.ah = PUTCHARATT; /* write att & character */ - regs.h.al = ch; /* character */ - regs.h.bh = 0; /* display page */ - regs.h.bl = (char)attr; /* BL = attribute */ - regs.x.cx = 1; /* one character */ - (void) int86(VIDEO_BIOS, ®s, ®s); -# endif - if (col < (CO -1 )) ++col; - break; - } /* end switch */ - txt_gotoxy(col,row); -# endif /* PC9800 */ + break; + default: +#ifdef SCREEN_DJGPPFAST + ScreenPutChar((int) ch, attr, col, row); +#endif +#ifdef SCREEN_BIOS + regs.h.ah = PUTCHARATT; /* write att & character */ + regs.h.al = ch; /* character */ + regs.h.bh = 0; /* display page */ + regs.h.bl = (char) attr; /* BL = attribute */ + regs.x.cx = 1; /* one character */ + (void) int86(VIDEO_BIOS, ®s, ®s); +#endif + if (col < (CO - 1)) + ++col; + break; + } /* end switch */ + txt_gotoxy(col, row); +#endif /* PC9800 */ } /* @@ -386,74 +388,74 @@ int attr; * screen writes will occur next, it does not change * the location of the player on the NetHack level. */ - -# if defined(SCREEN_BIOS) && !defined(PC9800) + +#if defined(SCREEN_BIOS) && !defined(PC9800) /* * This is implemented as a macro under DJGPPFAST. */ -void -txt_get_cursor(x,y) /* get cursor position */ +void txt_get_cursor(x, y) /* get cursor position */ int *x, *y; { - union REGS regs; + union REGS regs; - regs.x.dx = 0; - regs.h.ah = GETCURPOS; /* get cursor position */ - regs.x.cx = 0; - regs.x.bx = 0; - (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Cursor Position */ - *x = regs.h.dl; - *y = regs.h.dh; + regs.x.dx = 0; + regs.h.ah = GETCURPOS; /* get cursor position */ + regs.x.cx = 0; + regs.x.bx = 0; + (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Cursor Position */ + *x = regs.h.dl; + *y = regs.h.dh; } -# endif /* SCREEN_BIOS && !PC9800 */ +#endif /* SCREEN_BIOS && !PC9800 */ void -txt_gotoxy(x,y) -int x,y; +txt_gotoxy(x, y) +int x, y; { -# ifdef SCREEN_BIOS - union REGS regs; +#ifdef SCREEN_BIOS + union REGS regs; -# ifdef PC9800 - regs.h.dh = (char)y; /* row */ - regs.h.dl = (char)x; /* column */ - regs.h.ah = SETCURPOS; - regs.h.cl = DIRECT_CON_IO; - (void) int86(DOS_EXT_FUNC, ®s, ®s); /* Set Cursor Position */ -# else - regs.h.ah = SETCURPOS; - regs.h.bh = 0; /* display page */ - regs.h.dh = (char)y; /* row */ - regs.h.dl = (char)x; /* column */ - (void) int86(VIDEO_BIOS, ®s, ®s); /* Set Cursor Position */ -# endif -# endif -# if defined(SCREEN_DJGPPFAST) - ScreenSetCursor(y,x); -# endif - /* The above, too, goes back all the way to the original PC. If - * we ever get so fancy as to swap display pages (i doubt it), - * then we'll need to set BH appropriately. This function - * returns nothing. -3. - */ +#ifdef PC9800 + regs.h.dh = (char) y; /* row */ + regs.h.dl = (char) x; /* column */ + regs.h.ah = SETCURPOS; + regs.h.cl = DIRECT_CON_IO; + (void) int86(DOS_EXT_FUNC, ®s, ®s); /* Set Cursor Position */ +#else + regs.h.ah = SETCURPOS; + regs.h.bh = 0; /* display page */ + regs.h.dh = (char) y; /* row */ + regs.h.dl = (char) x; /* column */ + (void) int86(VIDEO_BIOS, ®s, ®s); /* Set Cursor Position */ +#endif +#endif +#if defined(SCREEN_DJGPPFAST) + ScreenSetCursor(y, x); +#endif + /* The above, too, goes back all the way to the original PC. If + * we ever get so fancy as to swap display pages (i doubt it), + * then we'll need to set BH appropriately. This function + * returns nothing. -3. + */ } /* * This marks the end of the cursor manipulation/information routines. * ------------------------------------------------------------------- - */ + */ -# ifdef MONO_CHECK -int txt_monoadapt_check() +#ifdef MONO_CHECK +int +txt_monoadapt_check() { - union REGS regs; + union REGS regs; - regs.h.al = 0; - regs.h.ah = GETMODE; /* get video mode */ - (void) int86(VIDEO_BIOS, ®s, ®s); - return (regs.h.al == 7) ? 1 : 0; /* 7 means monochrome mode */ + regs.h.al = 0; + regs.h.ah = GETMODE; /* get video mode */ + (void) int86(VIDEO_BIOS, ®s, ®s); + return (regs.h.al == 7) ? 1 : 0; /* 7 means monochrome mode */ } -# endif /* MONO_CHECK */ +#endif /* MONO_CHECK */ #endif /* NO_TERMS */ /* vidtxt.c */ diff --git a/sys/msdos/vidvga.c b/sys/msdos/vidvga.c index 2515be57a..352d63ef0 100644 --- a/sys/msdos/vidvga.c +++ b/sys/msdos/vidvga.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vidvga.c $NHDT-Date: 1425319884 2015/03/02 18:11:24 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ +/* NetHack 3.6 vidvga.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ /* NetHack 3.6 vidvga.c $Date: 2009/05/06 10:49:50 $ $Revision: 1.9 $ */ /* SCCS Id: @(#)vidvga.c 3.5 2006/07/08 */ /* Copyright (c) NetHack PC Development Team 1995 */ @@ -9,7 +9,7 @@ #include "hack.h" -#ifdef SCREEN_VGA /* this file is for SCREEN_VGA only */ +#ifdef SCREEN_VGA /* this file is for SCREEN_VGA only */ #include "pcvideo.h" #include "tile.h" #include "pctiles.h" @@ -18,10 +18,10 @@ #include #include "wintty.h" -# ifdef __GO32__ +#ifdef __GO32__ #include #include -# endif +#endif /*========================================================================= * VGA Video supporting routines (for tiles). @@ -30,14 +30,14 @@ * to make PC NetHack work with VGA graphics. * * - The binary files NetHack1.tib and NetHacko.tib must be in your - * game directory. Currently, unpredictable results may occur if they + * game directory. Currently, unpredictable results may occur if they * aren't since the code hasn't been tested with it missing (yet). * * Notes (96/02/16): * * - Cursor emulation on the map is now implemented. The input routine * in msdos.c calls the routine to display the cursor just before - * waiting for input, and hides the cursor immediately after satisfying + * waiting for input, and hides the cursor immediately after satisfying * the input request. * * - A check for a VGA adapter is implemented. @@ -47,23 +47,23 @@ * TTY CLIPPING code. The right/left scrolling with this can be * a little annoying. Feel free to rework the routines. * - * - NetHack1.tib is built from text files derived from bitmap files - * provided by Warwick Allison, using routines developed and supplied - * by Janet Walz. The icons are very well done and thanks to + * - NetHack1.tib is built from text files derived from bitmap files + * provided by Warwick Allison, using routines developed and supplied + * by Janet Walz. The icons are very well done and thanks to * Warwick Allison for an excellent effort! * * - The text fonts that this is using while in graphics mode come from * the Video BIOS ROM on board the VGA adapter. Code in vga_WriteChar * copies the appropriate pixels from the video ROM to the Video buffer. * - * - VGA 640 by 480, 16 colour mode (0x12) uses an odd method to - * represent a colour value from the palette. There are four + * - VGA 640 by 480, 16 colour mode (0x12) uses an odd method to + * represent a colour value from the palette. There are four * planes of video memory, all overlaid at the same memory location. * For example, if a pixel has the colour value 7: * * 0 1 1 1 * \ \ \ \ - * \ \ \ plane 0 + * \ \ \ plane 0 * \ \ plane 1 * \ plane 2 * plane 3 @@ -78,7 +78,7 @@ * - A check for valid mode switches has been added. * * - No tiles are displayed on the Rogue Level in keeping with the - * original Rogue. The display adapter remains in graphics mode + * original Rogue. The display adapter remains in graphics mode * however. * * - Added handling for missing NetHackX.tib files, and resort to using @@ -90,68 +90,76 @@ *========================================================================= */ - -# if defined(_MSC_VER) -# if _MSC_VER >= 700 -#pragma warning(disable:4018) /* signed/unsigned mismatch */ -#pragma warning(disable:4127) /* conditional expression is constant */ -#pragma warning(disable:4131) /* old style declarator */ -#pragma warning(disable:4305) /* prevents complaints with MK_FP */ -#pragma warning(disable:4309) /* initializing */ -# if _MSC_VER > 700 -#pragma warning(disable:4759) /* prevents complaints with MK_FP */ -# endif -# endif -# include -# endif +#if defined(_MSC_VER) +#if _MSC_VER >= 700 +#pragma warning(disable : 4018) /* signed/unsigned mismatch */ +#pragma warning(disable : 4127) /* conditional expression is constant */ +#pragma warning(disable : 4131) /* old style declarator */ +#pragma warning(disable : 4305) /* prevents complaints with MK_FP */ +#pragma warning(disable : 4309) /* initializing */ +#if _MSC_VER > 700 +#pragma warning(disable : 4759) /* prevents complaints with MK_FP */ +#endif +#endif +#include +#endif /* STATIC_DCL void FDECL(vga_NoBorder, (int)); */ -void FDECL(vga_gotoloc, (int,int)); /* This should be made a macro */ +void FDECL(vga_gotoloc, (int, int)); /* This should be made a macro */ void NDECL(vga_backsp); #ifdef SCROLLMAP -STATIC_DCL void FDECL(vga_scrollmap,(BOOLEAN_P)); +STATIC_DCL void FDECL(vga_scrollmap, (BOOLEAN_P)); #endif -STATIC_DCL void FDECL(vga_redrawmap,(BOOLEAN_P)); -void FDECL(vga_cliparound,(int, int)); -STATIC_OVL void FDECL(decal_planar,(struct planar_cell_struct *, unsigned)); +STATIC_DCL void FDECL(vga_redrawmap, (BOOLEAN_P)); +void FDECL(vga_cliparound, (int, int)); +STATIC_OVL void FDECL(decal_planar, (struct planar_cell_struct *, unsigned)); #ifdef POSITIONBAR STATIC_DCL void NDECL(positionbar); -static void FDECL(vga_special,(int, int, int)); +static void FDECL(vga_special, (int, int, int)); #endif -extern int clipx, clipxmax; /* current clipping column from wintty.c */ -extern boolean clipping; /* clipping on? from wintty.c */ -extern int savevmode; /* store the original video mode */ -extern int curcol,currow; /* current column and row */ +extern int clipx, clipxmax; /* current clipping column from wintty.c */ +extern boolean clipping; /* clipping on? from wintty.c */ +extern int savevmode; /* store the original video mode */ +extern int curcol, currow; /* current column and row */ extern int g_attribute; -extern int attrib_text_normal; /* text mode normal attribute */ -extern int attrib_gr_normal; /* graphics mode normal attribute */ -extern int attrib_text_intense; /* text mode intense attribute */ -extern int attrib_gr_intense; /* graphics mode intense attribute */ -extern boolean inmap; /* in the map window */ +extern int attrib_text_normal; /* text mode normal attribute */ +extern int attrib_gr_normal; /* graphics mode normal attribute */ +extern int attrib_text_intense; /* text mode intense attribute */ +extern int attrib_gr_intense; /* graphics mode intense attribute */ +extern boolean inmap; /* in the map window */ /* * Global Variables - */ + */ STATIC_VAR unsigned char __far *font; STATIC_VAR char *screentable[SCREENHEIGHT]; STATIC_VAR char *paletteptr; STATIC_VAR struct map_struct { - int glyph; - int ch; - int attr; - unsigned special; -} map[ROWNO][COLNO]; /* track the glyphs */ + int glyph; + int ch; + int attr; + unsigned special; +} map[ROWNO][COLNO]; /* track the glyphs */ -# define vga_clearmap() { int x,y; for (y=0; y < ROWNO; ++y) \ - for (x=0; x < COLNO; ++x) { map[y][x].glyph = cmap_to_glyph(S_stone); \ - map[y][x].ch = S_stone; map[y][x].attr = 0; map[y][x].special = 0;} } -# define TOP_MAP_ROW 1 +#define vga_clearmap() \ + { \ + int x, y; \ + for (y = 0; y < ROWNO; ++y) \ + for (x = 0; x < COLNO; ++x) { \ + map[y][x].glyph = cmap_to_glyph(S_stone); \ + map[y][x].ch = S_stone; \ + map[y][x].attr = 0; \ + map[y][x].special = 0; \ + } \ + } +#define TOP_MAP_ROW 1 -STATIC_VAR int vgacmap[CLR_MAX] = {0,3,5,9,4,8,12,14,11,2,6,7,1,8,12,13}; +STATIC_VAR int vgacmap[CLR_MAX] = { 0, 3, 5, 9, 4, 8, 12, 14, + 11, 2, 6, 7, 1, 8, 12, 13 }; STATIC_VAR int viewport_size = 40; /* STATIC_VAR char masktable[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; */ /* STATIC_VAR char bittable[8]= {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; */ @@ -176,123 +184,120 @@ STATIC_VAR char defpalette[] = { /* Default VGA palette */ }; #endif -# ifndef ALTERNATE_VIDEO_METHOD -int vp[SCREENPLANES] = {8,4,2,1}; -# endif -int vp2[SCREENPLANES] = {1,2,4,8}; +#ifndef ALTERNATE_VIDEO_METHOD +int vp[SCREENPLANES] = { 8, 4, 2, 1 }; +#endif +int vp2[SCREENPLANES] = { 1, 2, 4, 8 }; STATIC_VAR struct planar_cell_struct *planecell; STATIC_VAR struct overview_planar_cell_struct *planecell_O; -# if defined(USE_TILES) +#if defined(USE_TILES) STATIC_VAR struct tibhdr_struct tibheader; /* extern FILE *tilefile; */ /* Not needed in here most likely */ -# endif +#endif -/* STATIC_VAR int g_attribute; */ /* Current attribute to use */ +/* STATIC_VAR int g_attribute; */ /* Current attribute to use */ void vga_get_scr_size() { - CO = 80; - LI = 29; + CO = 80; + LI = 29; } void vga_backsp() { - int col,row; + int col, row; - col = curcol; /* Character cell row and column */ - row = currow; + col = curcol; /* Character cell row and column */ + row = currow; - if (col > 0) col = col-1; - vga_gotoloc(col,row); + if (col > 0) + col = col - 1; + vga_gotoloc(col, row); } void vga_clear_screen(colour) int colour; { - char __far *pch; - int y,j; - char volatile a; + char __far *pch; + int y, j; + char volatile a; - outportb(0x3ce,5); - outportb(0x3cf,2); + outportb(0x3ce, 5); + outportb(0x3cf, 2); - for (y=0; y < SCREENHEIGHT; ++y) { - pch = screentable[y]; - for (j=0; j < SCREENBYTES; ++j) { - outportb(0x3ce,8); - outportb(0x3cf,255); - a = READ_ABSOLUTE(pch); /* Must read , then write */ - WRITE_ABSOLUTE(pch, (char)colour); - ++pch; - } - } - outportb(0x3ce,5); - outportb(0x3cf,0); - if (iflags.tile_view) vga_clearmap(); - vga_gotoloc(0,0); /* is this needed? */ + for (y = 0; y < SCREENHEIGHT; ++y) { + pch = screentable[y]; + for (j = 0; j < SCREENBYTES; ++j) { + outportb(0x3ce, 8); + outportb(0x3cf, 255); + a = READ_ABSOLUTE(pch); /* Must read , then write */ + WRITE_ABSOLUTE(pch, (char) colour); + ++pch; + } + } + outportb(0x3ce, 5); + outportb(0x3cf, 0); + if (iflags.tile_view) + vga_clearmap(); + vga_gotoloc(0, 0); /* is this needed? */ } -void -vga_cl_end(col,row) /* clear to end of line */ -int col,row; +void vga_cl_end(col, row) /* clear to end of line */ +int col, row; { - int count; + int count; - /* - * This is being done via character writes. - * This should perhaps be optimized for speed by using VGA write - * mode 2 methods as did clear_screen() - */ - for (count = col; count < (CO-1); ++count) { - vga_WriteChar(' ',count,row,BACKGROUND_VGA_COLOR); - } + /* + * This is being done via character writes. + * This should perhaps be optimized for speed by using VGA write + * mode 2 methods as did clear_screen() + */ + for (count = col; count < (CO - 1); ++count) { + vga_WriteChar(' ', count, row, BACKGROUND_VGA_COLOR); + } } -void -vga_cl_eos(cy) /* clear to end of screen */ +void vga_cl_eos(cy) /* clear to end of screen */ int cy; { - int count; + int count; - cl_end(); - while(cy <= LI-2) { - for (count = 0; count < (CO-1); ++count) { - vga_WriteChar(' ',count,cy, - BACKGROUND_VGA_COLOR); - } - cy++; - } + cl_end(); + while (cy <= LI - 2) { + for (count = 0; count < (CO - 1); ++count) { + vga_WriteChar(' ', count, cy, BACKGROUND_VGA_COLOR); + } + cy++; + } } void vga_tty_end_screen() { - vga_clear_screen(BACKGROUND_VGA_COLOR); - vga_SwitchMode(MODETEXT); + vga_clear_screen(BACKGROUND_VGA_COLOR); + vga_SwitchMode(MODETEXT); } - void vga_tty_startup(wid, hgt) - int *wid, *hgt; +int *wid, *hgt; { + /* code to sense display adapter is required here - MJA */ - /* code to sense display adapter is required here - MJA */ + vga_get_scr_size(); + if (CO && LI) { + *wid = CO; + *hgt = LI; + } - vga_get_scr_size(); - if (CO && LI) { - *wid = CO; - *hgt = LI; - } - - attrib_gr_normal = ATTRIB_VGA_NORMAL; - attrib_gr_intense = ATTRIB_VGA_INTENSE; - g_attribute = attrib_gr_normal; /* Give it a starting value */ + attrib_gr_normal = ATTRIB_VGA_NORMAL; + attrib_gr_intense = ATTRIB_VGA_INTENSE; + g_attribute = attrib_gr_normal; /* Give it a starting value */ } /* @@ -317,83 +322,86 @@ vga_tty_startup(wid, hgt) */ void -vga_xputs(s,col,row) +vga_xputs(s, col, row) const char *s; -int col,row; +int col, row; { - - if (s != (char *)0) { - vga_WriteStr((char *)s,strlen(s),col,row,g_attribute); - } + if (s != (char *) 0) { + vga_WriteStr((char *) s, strlen(s), col, row, g_attribute); + } } -void -vga_xputc(ch,attr) /* write out character (and attribute) */ +void vga_xputc(ch, attr) /* write out character (and attribute) */ char ch; int attr; { - int col,row; + int col, row; - col = curcol; - row = currow; + col = curcol; + row = currow; - switch(ch) { - case '\n': - col = 0; - ++row; - break; - default: - vga_WriteChar((unsigned char)ch,col,row,attr); - if (col < (CO -1 )) ++col; - break; - } /* end switch */ - vga_gotoloc(col,row); + switch (ch) { + case '\n': + col = 0; + ++row; + break; + default: + vga_WriteChar((unsigned char) ch, col, row, attr); + if (col < (CO - 1)) + ++col; + break; + } /* end switch */ + vga_gotoloc(col, row); } -# if defined(USE_TILES) +#if defined(USE_TILES) void -vga_xputg(glyphnum,ch, special) /* Place tile represent. a glyph at current location */ +vga_xputg(glyphnum, ch, + special) /* Place tile represent. a glyph at current location */ int glyphnum; int ch; -unsigned special; /* special feature: corpse, invis, detected, pet, ridden - hack.h */ +unsigned special; /* special feature: corpse, invis, detected, pet, ridden - + hack.h */ { - int col,row; - int attr; - int ry; + int col, row; + int attr; + int ry; - row = currow; - col = curcol; - if ((col < 0 || col >= COLNO) || - (row < TOP_MAP_ROW || row >= (ROWNO + TOP_MAP_ROW))) return; - ry = row - TOP_MAP_ROW; - map[ry][col].glyph = glyphnum; - map[ry][col].ch = ch; - map[ry][col].special = special; - attr = (g_attribute == 0) ? attrib_gr_normal : g_attribute; - map[ry][col].attr = attr; - if (iflags.traditional_view) { - vga_WriteChar((unsigned char)ch,col,row,attr); - } else if (!iflags.over_view) { - if ((col >= clipx) && (col <= clipxmax)) { - if (!ReadPlanarTileFile(glyph2tile[glyphnum], &planecell)) { - if (map[ry][col].special) decal_planar(planecell, special); - vga_DisplayCell(planecell, - col - clipx, row); - } else - pline("vga_xputg: Error reading tile (%d,%d) from file", - glyphnum,glyph2tile[glyphnum]); - } - } else { - if (!ReadPlanarTileFile_O(glyph2tile[glyphnum], &planecell_O)) - vga_DisplayCell_O(planecell_O, col, row); - else - pline("vga_xputg: Error reading tile (%d,%d) from file", - glyphnum,glyph2tile[glyphnum]); - } - if (col < (CO - 1 )) ++col; - vga_gotoloc(col,row); + row = currow; + col = curcol; + if ((col < 0 || col >= COLNO) + || (row < TOP_MAP_ROW || row >= (ROWNO + TOP_MAP_ROW))) + return; + ry = row - TOP_MAP_ROW; + map[ry][col].glyph = glyphnum; + map[ry][col].ch = ch; + map[ry][col].special = special; + attr = (g_attribute == 0) ? attrib_gr_normal : g_attribute; + map[ry][col].attr = attr; + if (iflags.traditional_view) { + vga_WriteChar((unsigned char) ch, col, row, attr); + } else if (!iflags.over_view) { + if ((col >= clipx) && (col <= clipxmax)) { + if (!ReadPlanarTileFile(glyph2tile[glyphnum], &planecell)) { + if (map[ry][col].special) + decal_planar(planecell, special); + vga_DisplayCell(planecell, col - clipx, row); + } else + pline("vga_xputg: Error reading tile (%d,%d) from file", + glyphnum, glyph2tile[glyphnum]); + } + } else { + if (!ReadPlanarTileFile_O(glyph2tile[glyphnum], &planecell_O)) + vga_DisplayCell_O(planecell_O, col, row); + else + pline("vga_xputg: Error reading tile (%d,%d) from file", glyphnum, + glyph2tile[glyphnum]); + } + if (col < (CO - 1)) + ++col; + vga_gotoloc(col, row); } -# endif /* USE_TILES */ +#endif /* USE_TILES */ /* * Cursor location manipulation, and location information fetching @@ -406,238 +414,238 @@ unsigned special; /* special feature: corpse, invis, detected, pet, ridden - hac * will occur next, it does not change the location * of the player on the NetHack level. */ - + void -vga_gotoloc(col,row) -int col,row; +vga_gotoloc(col, row) +int col, row; { - curcol = min(col,CO - 1); /* protection from callers */ - currow = min(row,LI - 1); + curcol = min(col, CO - 1); /* protection from callers */ + currow = min(row, LI - 1); } -# if defined(USE_TILES) && defined(CLIPPING) +#if defined(USE_TILES) && defined(CLIPPING) void vga_cliparound(x, y) int x, y; { - extern boolean restoring; - int oldx = clipx; + extern boolean restoring; + int oldx = clipx; - if (!iflags.tile_view || iflags.over_view || iflags.traditional_view) - return; + if (!iflags.tile_view || iflags.over_view || iflags.traditional_view) + return; - if (x < clipx + 5) { - clipx = max(0, x - (viewport_size / 2)); - clipxmax = clipx + (viewport_size - 1); - } - else if (x > clipxmax - 5) { - clipxmax = min(COLNO - 1, x + (viewport_size / 2)); - clipx = clipxmax - (viewport_size - 1); - } - if (clipx != oldx) { - if (on_level(&u.uz0, &u.uz) && !restoring) - /* (void) doredraw(); */ - vga_redrawmap(1); - } + if (x < clipx + 5) { + clipx = max(0, x - (viewport_size / 2)); + clipxmax = clipx + (viewport_size - 1); + } else if (x > clipxmax - 5) { + clipxmax = min(COLNO - 1, x + (viewport_size / 2)); + clipx = clipxmax - (viewport_size - 1); + } + if (clipx != oldx) { + if (on_level(&u.uz0, &u.uz) && !restoring) + /* (void) doredraw(); */ + vga_redrawmap(1); + } } STATIC_OVL void vga_redrawmap(clearfirst) boolean clearfirst; { - int j,x,y,t; - char __far *pch; - char volatile a; - - if (clearfirst) { - /* y here is in pixel rows */ - outportb(0x3ce,5); - outportb(0x3cf,2); - t = TOP_MAP_ROW * ROWS_PER_CELL; - for (y = t; y < (ROWNO * ROWS_PER_CELL) + t; ++y) { - pch = screentable[y]; - for (j=0; j < SCREENBYTES; ++j) { - outportb(0x3ce,8); - outportb(0x3cf,255); - /* On VGA mode2, must read first, then write */ - a = READ_ABSOLUTE(pch); - WRITE_ABSOLUTE(pch, (char)BACKGROUND_VGA_COLOR); - ++pch; - } - } - outportb(0x3ce,5); - outportb(0x3cf,0); - } - /* y here is in screen rows*/ -# ifdef ROW_BY_ROW - for (y = 0; y < ROWNO; ++y) - for (x = clipx; x <= clipxmax; ++x) { -# else - for (x = clipx; x <= clipxmax; ++x) - for (y = 0; y < ROWNO; ++y) { -# endif - if (iflags.traditional_view) { - if (!(clearfirst && map[y][x].ch == S_stone)) - vga_WriteChar( - (unsigned char)map[y][x].ch, - x,y + TOP_MAP_ROW,map[y][x].attr); - } else { - t = map[y][x].glyph; - if (!(clearfirst && t == cmap_to_glyph(S_stone))) { - if (!iflags.over_view) { - if (!ReadPlanarTileFile(glyph2tile[t], - &planecell)) { - if (map[y][x].special) - decal_planar(planecell, map[y][x].special); - vga_DisplayCell(planecell, - x - clipx, y + TOP_MAP_ROW); - } else - pline("vga_redrawmap: Error reading tile (%d,%d)", - t,glyph2tile[t]); - } else { - if (!ReadPlanarTileFile_O(glyph2tile[t], - &planecell_O)) { - vga_DisplayCell_O(planecell_O, - x, y + TOP_MAP_ROW); - } else - pline("vga_redrawmap: Error reading tile (%d,%d)", - t,glyph2tile[t]); - } - } - } - } + int j, x, y, t; + char __far *pch; + char volatile a; + + if (clearfirst) { + /* y here is in pixel rows */ + outportb(0x3ce, 5); + outportb(0x3cf, 2); + t = TOP_MAP_ROW * ROWS_PER_CELL; + for (y = t; y < (ROWNO * ROWS_PER_CELL) + t; ++y) { + pch = screentable[y]; + for (j = 0; j < SCREENBYTES; ++j) { + outportb(0x3ce, 8); + outportb(0x3cf, 255); + /* On VGA mode2, must read first, then write */ + a = READ_ABSOLUTE(pch); + WRITE_ABSOLUTE(pch, (char) BACKGROUND_VGA_COLOR); + ++pch; + } + } + outportb(0x3ce, 5); + outportb(0x3cf, 0); + } +/* y here is in screen rows*/ +#ifdef ROW_BY_ROW + for (y = 0; y < ROWNO; ++y) + for (x = clipx; x <= clipxmax; ++x) { +#else + for (x = clipx; x <= clipxmax; ++x) + for (y = 0; y < ROWNO; ++y) { +#endif + if (iflags.traditional_view) { + if (!(clearfirst && map[y][x].ch == S_stone)) + vga_WriteChar((unsigned char) map[y][x].ch, x, + y + TOP_MAP_ROW, map[y][x].attr); + } else { + t = map[y][x].glyph; + if (!(clearfirst && t == cmap_to_glyph(S_stone))) { + if (!iflags.over_view) { + if (!ReadPlanarTileFile(glyph2tile[t], &planecell)) { + if (map[y][x].special) + decal_planar(planecell, map[y][x].special); + vga_DisplayCell(planecell, x - clipx, + y + TOP_MAP_ROW); + } else + pline("vga_redrawmap: Error reading tile (%d,%d)", + t, glyph2tile[t]); + } else { + if (!ReadPlanarTileFile_O(glyph2tile[t], + &planecell_O)) { + vga_DisplayCell_O(planecell_O, x, + y + TOP_MAP_ROW); + } else + pline("vga_redrawmap: Error reading tile (%d,%d)", + t, glyph2tile[t]); + } + } + } + } } -# endif /* USE_TILES && CLIPPING */ +#endif /* USE_TILES && CLIPPING */ void vga_userpan(left) boolean left; { - int x; + int x; -/* pline("Into userpan"); */ - if (iflags.over_view || iflags.traditional_view) return; - if (left) - x = min(COLNO - 1, clipxmax + 10); - else - x = max(0, clipx - 10); - vga_cliparound(x, 10); /* y value is irrelevant on VGA clipping */ - positionbar(); - vga_DrawCursor(); + /* pline("Into userpan"); */ + if (iflags.over_view || iflags.traditional_view) + return; + if (left) + x = min(COLNO - 1, clipxmax + 10); + else + x = max(0, clipx - 10); + vga_cliparound(x, 10); /* y value is irrelevant on VGA clipping */ + positionbar(); + vga_DrawCursor(); } - -void vga_overview(on) +void +vga_overview(on) boolean on; { -/* vga_HideCursor(); */ - if (on) { - iflags.over_view = TRUE; - clipx = 0; - clipxmax = CO - 1; - } else { - iflags.over_view = FALSE; - clipx = max(0, (curcol - viewport_size / 2)); - if (clipx > ((CO - 1) - viewport_size)) - clipx = (CO - 1) - viewport_size; - clipxmax = clipx + (viewport_size - 1); - } + /* vga_HideCursor(); */ + if (on) { + iflags.over_view = TRUE; + clipx = 0; + clipxmax = CO - 1; + } else { + iflags.over_view = FALSE; + clipx = max(0, (curcol - viewport_size / 2)); + if (clipx > ((CO - 1) - viewport_size)) + clipx = (CO - 1) - viewport_size; + clipxmax = clipx + (viewport_size - 1); + } } -void vga_traditional(on) +void +vga_traditional(on) boolean on; { -/* vga_HideCursor(); */ - if (on) { -/* switch_symbols(FALSE); */ - iflags.traditional_view = TRUE; - clipx = 0; - clipxmax = CO - 1; - } else { - iflags.traditional_view = FALSE; - if (!iflags.over_view) { - clipx = max(0, (curcol - viewport_size / 2)); - if (clipx > ((CO - 1) - viewport_size)) - clipx = (CO - 1) - viewport_size; - clipxmax = clipx + (viewport_size - 1); - } - } + /* vga_HideCursor(); */ + if (on) { + /* switch_symbols(FALSE); */ + iflags.traditional_view = TRUE; + clipx = 0; + clipxmax = CO - 1; + } else { + iflags.traditional_view = FALSE; + if (!iflags.over_view) { + clipx = max(0, (curcol - viewport_size / 2)); + if (clipx > ((CO - 1) - viewport_size)) + clipx = (CO - 1) - viewport_size; + clipxmax = clipx + (viewport_size - 1); + } + } } -void vga_refresh() +void +vga_refresh() { - positionbar(); - vga_redrawmap(1); - vga_DrawCursor(); + positionbar(); + vga_redrawmap(1); + vga_DrawCursor(); } -# ifdef SCROLLMAP +#ifdef SCROLLMAP STATIC_OVL void vga_scrollmap(left) boolean left; { - int j,x,y,t; - int i,pixx,pixy,x1,y1,x2,y2; - int byteoffset, vplane; - char __far *tmp1; - char __far *tmp2; - unsigned char source[SCREENPLANES][80]; - unsigned char first,second; + int j, x, y, t; + int i, pixx, pixy, x1, y1, x2, y2; + int byteoffset, vplane; + char __far *tmp1; + char __far *tmp2; + unsigned char source[SCREENPLANES][80]; + unsigned char first, second; - - pixy = row2y(TOP_MAP_ROW); /* convert to pixels */ - pixx = col2x(x1); - if (left) { - x1 = 20; - x2 = 0; - } else { - x1 = 0; - x2 = 20; - } - /* read each row, all columns but the one to be replaced */ - for(i = 0;i < (ROWNO-1) * ROWS_PER_CELL; ++i) { - tmp1 = screentable[i + pixy]; - tmp1 += x1; - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egareadplane(vplane); - for (byteoffset = 0; byteoffset < 20; ++byteoffset) { - tmp2 = tmp1 + byteoffset; - source[vplane][byteoffset] = READ_ABSOLUTE(tmp2); - } - } - tmp1 = screentable[i + pixy]; - tmp1 += x2; - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egawriteplane(vp2[vplane]); - for (byteoffset = 0; byteoffset < 20; ++byteoffset) { - tmp2 = tmp1 + byteoffset; - WRITE_ABSOLUTE(tmp2,source[vplane][byteoffset]); - } - } - egawriteplane(15); - } + pixy = row2y(TOP_MAP_ROW); /* convert to pixels */ + pixx = col2x(x1); + if (left) { + x1 = 20; + x2 = 0; + } else { + x1 = 0; + x2 = 20; + } + /* read each row, all columns but the one to be replaced */ + for (i = 0; i < (ROWNO - 1) * ROWS_PER_CELL; ++i) { + tmp1 = screentable[i + pixy]; + tmp1 += x1; + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egareadplane(vplane); + for (byteoffset = 0; byteoffset < 20; ++byteoffset) { + tmp2 = tmp1 + byteoffset; + source[vplane][byteoffset] = READ_ABSOLUTE(tmp2); + } + } + tmp1 = screentable[i + pixy]; + tmp1 += x2; + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egawriteplane(vp2[vplane]); + for (byteoffset = 0; byteoffset < 20; ++byteoffset) { + tmp2 = tmp1 + byteoffset; + WRITE_ABSOLUTE(tmp2, source[vplane][byteoffset]); + } + } + egawriteplane(15); + } - if (left) { - i = clipxmax - 1; - j = clipxmax; - } else { - i = clipx; - j = clipx + 1; - } - for (y = 0; y < ROWNO; ++y) { - for (x = i; x < j; x += 2) { - t = map[y][x].glyph; - if (!ReadPlanarTileFile(glyph2tile[t], &planecell)) { - if (map[y][x].special) decal_planar(planecell, map[y][x].special); - vga_DisplayCell(planecell, x - clipx, y + TOP_MAP_ROW); - } else { - pline("vga_shiftmap: Error reading tile (%d,%d)", - t, glyph2tile[t]); - } - } - } + if (left) { + i = clipxmax - 1; + j = clipxmax; + } else { + i = clipx; + j = clipx + 1; + } + for (y = 0; y < ROWNO; ++y) { + for (x = i; x < j; x += 2) { + t = map[y][x].glyph; + if (!ReadPlanarTileFile(glyph2tile[t], &planecell)) { + if (map[y][x].special) + decal_planar(planecell, map[y][x].special); + vga_DisplayCell(planecell, x - clipx, y + TOP_MAP_ROW); + } else { + pline("vga_shiftmap: Error reading tile (%d,%d)", t, + glyph2tile[t]); + } + } + } } -# endif /* SCROLLMAP */ +#endif /* SCROLLMAP */ STATIC_OVL void decal_planar(gp, special) @@ -645,9 +653,9 @@ struct planar_cell_struct *gp; unsigned special; { if (special & MG_CORPSE) { - } else if (special & MG_INVIS) { + } else if (special & MG_INVIS) { } else if (special & MG_DETECT) { - } else if (special & MG_PET) { + } else if (special & MG_PET) { } else if (special & MG_RIDDEN) { } } @@ -659,56 +667,61 @@ unsigned special; * the screen. * */ -void vga_Init(void) +void +vga_Init(void) { - int i; + int i; -# ifdef USE_TILES - int tilefailure = 0; -/* - * Attempt to open the required tile files. If we can't - * don't perform the video mode switch, use TTY code instead. - * - */ - if (OpenTileFile(NETHACK_PLANAR_TILEFILE, FALSE)) tilefailure |= 1; - if (OpenTileFile(NETHACK_OVERVIEW_TILEFILE, TRUE)) tilefailure |= 2; - if (ReadTileFileHeader(&tibheader, FALSE)) tilefailure |= 4; +#ifdef USE_TILES + int tilefailure = 0; + /* + * Attempt to open the required tile files. If we can't + * don't perform the video mode switch, use TTY code instead. + * + */ + if (OpenTileFile(NETHACK_PLANAR_TILEFILE, FALSE)) + tilefailure |= 1; + if (OpenTileFile(NETHACK_OVERVIEW_TILEFILE, TRUE)) + tilefailure |= 2; + if (ReadTileFileHeader(&tibheader, FALSE)) + tilefailure |= 4; - if (tilefailure) { - raw_printf("Reverting to TTY mode, tile initialization failure (%d).", - tilefailure); - wait_synch(); - iflags.usevga = 0; - iflags.tile_view = FALSE; - iflags.over_view = FALSE; - CO = 80; - LI = 25; -/* clear_screen() */ /* not vga_clear_screen() */ - return; - } -# endif + if (tilefailure) { + raw_printf("Reverting to TTY mode, tile initialization failure (%d).", + tilefailure); + wait_synch(); + iflags.usevga = 0; + iflags.tile_view = FALSE; + iflags.over_view = FALSE; + CO = 80; + LI = 25; + /* clear_screen() */ /* not vga_clear_screen() */ + return; + } +#endif - if (iflags.usevga) { - for (i=0; i < SCREENHEIGHT; ++i) { - screentable[i]=MK_PTR(VIDEOSEG, (i * SCREENBYTES)); - } - } - vga_SwitchMode(MODE640x480); - windowprocs.win_cliparound = vga_cliparound; -/* vga_NoBorder(BACKGROUND_VGA_COLOR); */ /* Not needed after palette mod */ -# ifdef USE_TILES - paletteptr = tibheader.palette; - iflags.tile_view = TRUE; - iflags.over_view = FALSE; -# else - paletteptr = defpalette; -# endif - vga_SetPalette(paletteptr); - g_attribute = attrib_gr_normal; - font = vga_FontPtrs(); - clear_screen(); - clipx = 0; - clipxmax = clipx + (viewport_size - 1); + if (iflags.usevga) { + for (i = 0; i < SCREENHEIGHT; ++i) { + screentable[i] = MK_PTR(VIDEOSEG, (i * SCREENBYTES)); + } + } + vga_SwitchMode(MODE640x480); + windowprocs.win_cliparound = vga_cliparound; + /* vga_NoBorder(BACKGROUND_VGA_COLOR); */ /* Not needed after palette + mod */ +#ifdef USE_TILES + paletteptr = tibheader.palette; + iflags.tile_view = TRUE; + iflags.over_view = FALSE; +#else + paletteptr = defpalette; +#endif + vga_SetPalette(paletteptr); + g_attribute = attrib_gr_normal; + font = vga_FontPtrs(); + clear_screen(); + clipx = 0; + clipxmax = clipx + (viewport_size - 1); } /* @@ -719,26 +732,26 @@ void vga_Init(void) * mode (video mode 0x12). No other modes are currently supported. * */ -void vga_SwitchMode(unsigned int mode) +void +vga_SwitchMode(unsigned int mode) { - union REGS regs; + union REGS regs; - if ((mode == MODE640x480) || (mode == MODETEXT)) { - if (iflags.usevga && (mode == MODE640x480)) { - iflags.grmode = 1; - } else { - iflags.grmode = 0; - } - regs.x.ax = mode; - (void) int86(VIDEO_BIOS, ®s, ®s); - } else { - iflags.grmode = 0; /* force text mode for error msg */ - regs.x.ax = MODETEXT; - (void) int86(VIDEO_BIOS, ®s, ®s); - g_attribute = attrib_text_normal; - impossible("vga_SwitchMode: Bad video mode requested 0x%X", - mode); - } + if ((mode == MODE640x480) || (mode == MODETEXT)) { + if (iflags.usevga && (mode == MODE640x480)) { + iflags.grmode = 1; + } else { + iflags.grmode = 0; + } + regs.x.ax = mode; + (void) int86(VIDEO_BIOS, ®s, ®s); + } else { + iflags.grmode = 0; /* force text mode for error msg */ + regs.x.ax = MODETEXT; + (void) int86(VIDEO_BIOS, ®s, ®s); + g_attribute = attrib_text_normal; + impossible("vga_SwitchMode: Bad video mode requested 0x%X", mode); + } } /* @@ -746,14 +759,15 @@ void vga_SwitchMode(unsigned int mode) * switching back to text mode. This is a public (extern) function. * */ -void vga_Finish(void) +void +vga_Finish(void) { - CloseTileFile(0); - CloseTileFile(1); - vga_SwitchMode(MODETEXT); - windowprocs.win_cliparound = tty_cliparound; - g_attribute = attrib_text_normal; - iflags.tile_view = FALSE; + CloseTileFile(0); + CloseTileFile(1); + vga_SwitchMode(MODETEXT); + windowprocs.win_cliparound = tty_cliparound; + g_attribute = attrib_text_normal; + iflags.tile_view = FALSE; } #if 0 @@ -779,7 +793,7 @@ vga_NoBorder(int bc) #endif /* - * + * * Returns a far pointer (or flat 32 bit pointer under djgpp) to the * location of the appropriate ROM font for the _current_ video mode * (so you must place the card into the desired video mode before @@ -789,18 +803,19 @@ vga_NoBorder(int bc) * address of the appropriate character definition table for * the current graphics mode into interrupt vector 0x43 (0000:010C). */ -char __far *vga_FontPtrs(void) +char __far * +vga_FontPtrs(void) { - USHORT __far *tmp; - char __far *retval; - USHORT fseg, foff; - tmp = (USHORT __far *)MK_PTR(((USHORT)FONT_PTR_SEGMENT), - ((USHORT)FONT_PTR_OFFSET)); - foff = READ_ABSOLUTE_WORD(tmp); - ++tmp; - fseg = READ_ABSOLUTE_WORD(tmp); - retval = (char __far *)MK_PTR(fseg,foff); - return retval; + USHORT __far *tmp; + char __far *retval; + USHORT fseg, foff; + tmp = (USHORT __far *) MK_PTR(((USHORT) FONT_PTR_SEGMENT), + ((USHORT) FONT_PTR_OFFSET)); + foff = READ_ABSOLUTE_WORD(tmp); + ++tmp; + fseg = READ_ABSOLUTE_WORD(tmp); + retval = (char __far *) MK_PTR(fseg, foff); + return retval; } /* @@ -808,30 +823,31 @@ char __far *vga_FontPtrs(void) * Video function call 0x1a returns 0x1a in AL if successful, and * returns the following values in BL for the active display: * - * 0=no display, 1=MDA, 2=CGA, 4=EGA(color-monitor), + * 0=no display, 1=MDA, 2=CGA, 4=EGA(color-monitor), * 5=EGA(mono-monitor), 6=PGA, 7=VGA(mono-monitor), 8=VGA(color-monitor), * 0xB=MCGA(mono-monitor), 0xC=MCGA(color-monitor), 0xFF=unknown) */ -int vga_detect() +int +vga_detect() { - union REGS regs; - - regs.h.al = 0; - regs.h.ah = 0x1a; - (void) int86(VIDEO_BIOS, ®s, ®s); -/* - * debug - * - * printf("vga_detect returned al=%02x, bh=%02x, bl=%02x\n", - * (int)regs.h.al, (int)regs.h.bh, (int)regs.h.bl); - * getch(); - */ - if ((int)regs.h.al == 0x1a) { - if (((int)regs.h.bl == 8) || ((int)regs.h.bl == 7)) { - return 1; - } - } - return 0; + union REGS regs; + + regs.h.al = 0; + regs.h.ah = 0x1a; + (void) int86(VIDEO_BIOS, ®s, ®s); + /* + * debug + * + * printf("vga_detect returned al=%02x, bh=%02x, bl=%02x\n", + * (int)regs.h.al, (int)regs.h.bh, (int)regs.h.bl); + * getch(); + */ + if ((int) regs.h.al == 0x1a) { + if (((int) regs.h.bl == 8) || ((int) regs.h.bl == 7)) { + return 1; + } + } + return 0; } /* @@ -839,44 +855,43 @@ int vga_detect() * do it using the colour 'colour'. * */ -void -vga_WriteChar(chr,col,row,colour) -int chr,col,row,colour; +void +vga_WriteChar(chr, col, row, colour) +int chr, col, row, colour; { - int i; - int x,pixy; + int i; + int x, pixy; - char volatile tc; - char __far *cp; - unsigned char __far *fp = font; - unsigned char fnt; - int actual_colour = vgacmap[colour]; + char volatile tc; + char __far *cp; + unsigned char __far *fp = font; + unsigned char fnt; + int actual_colour = vgacmap[colour]; + x = min(col, (CO - 1)); /* min() used protection from callers */ + pixy = min(row, (LI - 1)) * 16; /* assumes 8 x 16 char set */ + /* if (chr < ' ') chr = ' '; */ /* assumes ASCII set */ - x = min(col,(CO-1)); /* min() used protection from callers */ - pixy = min(row,(LI-1)) * 16; /* assumes 8 x 16 char set */ -/* if (chr < ' ') chr = ' '; */ /* assumes ASCII set */ + outportb(0x3ce, 5); + outportb(0x3cf, 2); - outportb(0x3ce,5); - outportb(0x3cf,2); - - chr = chr<<4; - for (i=0; i < MAX_ROWS_PER_CELL; ++i) { - cp = screentable[pixy+i] + x; - fnt = READ_ABSOLUTE((fp + chr + i)); - outportb(0x3ce,8); - outportb(0x3cf,fnt); - tc = READ_ABSOLUTE(cp); /* wrt mode 2, must read, then write */ - WRITE_ABSOLUTE(cp, (char)actual_colour); - outportb(0x3ce,8); - outportb(0x3cf,~fnt); - tc = READ_ABSOLUTE(cp); /* wrt mode 2, must read, then write */ - WRITE_ABSOLUTE(cp, (char)BACKGROUND_VGA_COLOR); - } - outportb(0x3ce,5); - outportb(0x3cf,0); - outportb(0x3ce,8); - outportb(0x3cf,255); + chr = chr << 4; + for (i = 0; i < MAX_ROWS_PER_CELL; ++i) { + cp = screentable[pixy + i] + x; + fnt = READ_ABSOLUTE((fp + chr + i)); + outportb(0x3ce, 8); + outportb(0x3cf, fnt); + tc = READ_ABSOLUTE(cp); /* wrt mode 2, must read, then write */ + WRITE_ABSOLUTE(cp, (char) actual_colour); + outportb(0x3ce, 8); + outportb(0x3cf, ~fnt); + tc = READ_ABSOLUTE(cp); /* wrt mode 2, must read, then write */ + WRITE_ABSOLUTE(cp, (char) BACKGROUND_VGA_COLOR); + } + outportb(0x3ce, 5); + outportb(0x3cf, 0); + outportb(0x3ce, 8); + outportb(0x3cf, 255); } /* @@ -889,61 +904,62 @@ int chr,col,row,colour; * */ void -vga_DisplayCell(gp,col,row) +vga_DisplayCell(gp, col, row) struct planar_cell_struct *gp; -int col,row; +int col, row; { - int i,pixx,pixy; - char __far *tmp_s; /* source pointer */ - char __far *tmp_d; /* destination pointer */ - int vplane; + int i, pixx, pixy; + char __far *tmp_s; /* source pointer */ + char __far *tmp_d; /* destination pointer */ + int vplane; - pixy = row2y(row); /* convert to pixels */ - pixx = col2x(col); - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egawriteplane(vp[vplane]); - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp_d = screentable[i+pixy]; - tmp_d += pixx; - /* - * memcpy((void *)tmp,(void *)gp->plane[vplane].image[i], - * BYTES_PER_CELL); - */ - tmp_s = gp->plane[vplane].image[i]; - WRITE_ABSOLUTE(tmp_d, (*tmp_s)); - ++tmp_s; ++tmp_d; - WRITE_ABSOLUTE(tmp_d, (*tmp_s)); - } - } - egawriteplane(15); + pixy = row2y(row); /* convert to pixels */ + pixx = col2x(col); + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egawriteplane(vp[vplane]); + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp_d = screentable[i + pixy]; + tmp_d += pixx; + /* + * memcpy((void *)tmp,(void *)gp->plane[vplane].image[i], + * BYTES_PER_CELL); + */ + tmp_s = gp->plane[vplane].image[i]; + WRITE_ABSOLUTE(tmp_d, (*tmp_s)); + ++tmp_s; + ++tmp_d; + WRITE_ABSOLUTE(tmp_d, (*tmp_s)); + } + } + egawriteplane(15); } void -vga_DisplayCell_O(gp,col,row) +vga_DisplayCell_O(gp, col, row) struct overview_planar_cell_struct *gp; -int col,row; +int col, row; { - int i,pixx,pixy; - char __far *tmp_s; /* source pointer */ - char __far *tmp_d; /* destination pointer */ - int vplane; + int i, pixx, pixy; + char __far *tmp_s; /* source pointer */ + char __far *tmp_d; /* destination pointer */ + int vplane; - pixy = row2y(row); /* convert to pixels */ - pixx = col; - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egawriteplane(vp[vplane]); - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp_d = screentable[i+pixy]; - tmp_d += pixx; - /* - * memcpy((void *)tmp,(void *)gp->plane[vplane].image[i], - * BYTES_PER_CELL); - */ - tmp_s = gp->plane[vplane].image[i]; - WRITE_ABSOLUTE(tmp_d, (*tmp_s)); - } - } - egawriteplane(15); + pixy = row2y(row); /* convert to pixels */ + pixx = col; + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egawriteplane(vp[vplane]); + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp_d = screentable[i + pixy]; + tmp_d += pixx; + /* + * memcpy((void *)tmp,(void *)gp->plane[vplane].image[i], + * BYTES_PER_CELL); + */ + tmp_s = gp->plane[vplane].image[i]; + WRITE_ABSOLUTE(tmp_d, (*tmp_s)); + } + } + egawriteplane(15); } /* @@ -951,25 +967,26 @@ int col,row; * is 'len' at location (x,y) using the 'colour' colour. * */ -void -vga_WriteStr(s,len,col,row,colour) +void +vga_WriteStr(s, len, col, row, colour) char *s; -int len,col,row,colour; +int len, col, row, colour; { - unsigned char *us; - int i = 0; + unsigned char *us; + int i = 0; - /* protection from callers */ - if (row > (LI-1)) return; + /* protection from callers */ + if (row > (LI - 1)) + return; - i = 0; - us = (unsigned char *)s; - while( (*us != 0) && (i < len) && (col < (CO - 1))) { - vga_WriteChar(*us,col,row,colour); - ++us; - ++i; - ++col; - } + i = 0; + us = (unsigned char *) s; + while ((*us != 0) && (i < len) && (col < (CO - 1))) { + vga_WriteChar(*us, col, row, colour); + ++us; + ++i; + ++col; + } } /* @@ -980,185 +997,189 @@ int len,col,row,colour; */ void vga_SetPalette(p) - char *p; +char *p; { - union REGS regs; - int i; + union REGS regs; + int i; - outportb(0x3c6,0xff); - for(i=0;i < COLORDEPTH; ++i) { - outportb(0x3c8,i); - outportb(0x3c9,(*p++) >> 2); - outportb(0x3c9,(*p++) >> 2); - outportb(0x3c9,(*p++) >> 2); - } - regs.x.bx = 0x0000; - for(i=0;i < COLORDEPTH; ++i) { - regs.x.ax = 0x1000; - (void) int86(VIDEO_BIOS,®s,®s); - regs.x.bx += 0x0101; - } + outportb(0x3c6, 0xff); + for (i = 0; i < COLORDEPTH; ++i) { + outportb(0x3c8, i); + outportb(0x3c9, (*p++) >> 2); + outportb(0x3c9, (*p++) >> 2); + outportb(0x3c9, (*p++) >> 2); + } + regs.x.bx = 0x0000; + for (i = 0; i < COLORDEPTH; ++i) { + regs.x.ax = 0x1000; + (void) int86(VIDEO_BIOS, ®s, ®s); + regs.x.bx += 0x0101; + } } /*static unsigned char colorbits[]={0x01,0x02,0x04,0x08}; */ /* wrong */ -static unsigned char colorbits[]={0x08,0x04,0x02,0x01}; +static unsigned char colorbits[] = { 0x08, 0x04, 0x02, 0x01 }; #ifdef POSITIONBAR #define PBAR_ROW (LI - 4) -#define PBAR_COLOR_ON 15 /* slate grey background colour of tiles */ -#define PBAR_COLOR_OFF 12 /* bluish grey, used in old style only */ -#define PBAR_COLOR_STAIRS 9 /* brown */ -#define PBAR_COLOR_HERO 14 /* creamy white */ +#define PBAR_COLOR_ON 15 /* slate grey background colour of tiles */ +#define PBAR_COLOR_OFF 12 /* bluish grey, used in old style only */ +#define PBAR_COLOR_STAIRS 9 /* brown */ +#define PBAR_COLOR_HERO 14 /* creamy white */ static unsigned char pbar[COLNO]; -void +void vga_update_positionbar(posbar) char *posbar; { - char *p = pbar; - if (posbar) while (*posbar) *p++ = *posbar++; - *p = 0; + char *p = pbar; + if (posbar) + while (*posbar) + *p++ = *posbar++; + *p = 0; } -STATIC_OVL void +STATIC_OVL void positionbar() { - char *posbar = pbar; - int feature, ucol; - int k, y, colour, row; - char __far *pch; + char *posbar = pbar; + int feature, ucol; + int k, y, colour, row; + char __far *pch; - int startk, stopk; - char volatile a; - boolean nowhere = FALSE; - int pixy = (PBAR_ROW * MAX_ROWS_PER_CELL); - int tmp; + int startk, stopk; + char volatile a; + boolean nowhere = FALSE; + int pixy = (PBAR_ROW * MAX_ROWS_PER_CELL); + int tmp; - if (!iflags.grmode || !iflags.tile_view) return; - if ((clipx < 0) || (clipxmax <= 0) || (clipx >= clipxmax)) - nowhere = TRUE; - if (nowhere) { + if (!iflags.grmode || !iflags.tile_view) + return; + if ((clipx < 0) || (clipxmax <= 0) || (clipx >= clipxmax)) + nowhere = TRUE; + if (nowhere) { #ifdef DEBUG - pline("Would have put bar using %d - %d.",clipx,clipxmax); + pline("Would have put bar using %d - %d.", clipx, clipxmax); #endif - return; - } + return; + } #ifdef OLD_STYLE - outportb(0x3ce,5); - outportb(0x3cf,2); - for (y=pixy; y < (pixy + MAX_ROWS_PER_CELL); ++y) { - pch = screentable[y]; - for (k=0; k < SCREENBYTES; ++k) { - if ((k < clipx) || (k > clipxmax)) { - colour = PBAR_COLOR_OFF; - } else colour = PBAR_COLOR_ON; - outportb(0x3ce,8); - outportb(0x3cf,255); - a = READ_ABSOLUTE(pch); /* Must read , then write */ - WRITE_ABSOLUTE(pch, (char)colour); - ++pch; - } - } - outportb(0x3ce,5); - outportb(0x3cf,0); + outportb(0x3ce, 5); + outportb(0x3cf, 2); + for (y = pixy; y < (pixy + MAX_ROWS_PER_CELL); ++y) { + pch = screentable[y]; + for (k = 0; k < SCREENBYTES; ++k) { + if ((k < clipx) || (k > clipxmax)) { + colour = PBAR_COLOR_OFF; + } else + colour = PBAR_COLOR_ON; + outportb(0x3ce, 8); + outportb(0x3cf, 255); + a = READ_ABSOLUTE(pch); /* Must read , then write */ + WRITE_ABSOLUTE(pch, (char) colour); + ++pch; + } + } + outportb(0x3ce, 5); + outportb(0x3cf, 0); #else - colour = PBAR_COLOR_ON; - outportb(0x3ce,5); - outportb(0x3cf,2); - for (y=pixy, row = 0; y < (pixy + MAX_ROWS_PER_CELL); ++y, ++row) { - pch = screentable[y]; - if ((!row) || (row == (ROWS_PER_CELL-1))) { - startk = 0; - stopk = SCREENBYTES; - } else { - startk = clipx; - stopk = clipxmax; - } - for (k=0; k < SCREENBYTES; ++k) { - if ((k < startk) || (k > stopk)) - colour = BACKGROUND_VGA_COLOR; - else - colour = PBAR_COLOR_ON; - outportb(0x3ce,8); - outportb(0x3cf,255); - a = READ_ABSOLUTE(pch); /* Must read , then write */ - WRITE_ABSOLUTE(pch, (char)colour); - ++pch; - } - } - outportb(0x3ce,5); - outportb(0x3cf,0); + colour = PBAR_COLOR_ON; + outportb(0x3ce, 5); + outportb(0x3cf, 2); + for (y = pixy, row = 0; y < (pixy + MAX_ROWS_PER_CELL); ++y, ++row) { + pch = screentable[y]; + if ((!row) || (row == (ROWS_PER_CELL - 1))) { + startk = 0; + stopk = SCREENBYTES; + } else { + startk = clipx; + stopk = clipxmax; + } + for (k = 0; k < SCREENBYTES; ++k) { + if ((k < startk) || (k > stopk)) + colour = BACKGROUND_VGA_COLOR; + else + colour = PBAR_COLOR_ON; + outportb(0x3ce, 8); + outportb(0x3cf, 255); + a = READ_ABSOLUTE(pch); /* Must read , then write */ + WRITE_ABSOLUTE(pch, (char) colour); + ++pch; + } + } + outportb(0x3ce, 5); + outportb(0x3cf, 0); +#endif + ucol = 0; + if (posbar) { + while (*posbar != 0) { + feature = *posbar++; + switch (feature) { + case '>': + vga_special(feature, (int) *posbar++, PBAR_COLOR_STAIRS); + break; + case '<': + vga_special(feature, (int) *posbar++, PBAR_COLOR_STAIRS); + break; + case '@': + ucol = (int) *posbar++; + vga_special(feature, ucol, PBAR_COLOR_HERO); + break; + default: /* unanticipated symbols */ + vga_special(feature, (int) *posbar++, PBAR_COLOR_STAIRS); + break; + } + } + } +#ifdef SIMULATE_CURSOR + if (inmap) { + tmp = curcol + 1; + if ((tmp != ucol) && (curcol >= 0)) + vga_special('_', tmp, PBAR_COLOR_HERO); + } #endif - ucol = 0; - if (posbar) { - while (*posbar != 0) { - feature = *posbar++; - switch (feature) { - case '>': - vga_special(feature, (int)*posbar++, PBAR_COLOR_STAIRS); - break; - case '<': - vga_special(feature, (int)*posbar++, PBAR_COLOR_STAIRS); - break; - case '@': - ucol = (int)*posbar++; - vga_special(feature, ucol, PBAR_COLOR_HERO); - break; - default: /* unanticipated symbols */ - vga_special(feature, (int)*posbar++, PBAR_COLOR_STAIRS); - break; - } - } - } -# ifdef SIMULATE_CURSOR - if (inmap) { - tmp = curcol + 1; - if ((tmp != ucol) && (curcol >= 0)) - vga_special('_', tmp, PBAR_COLOR_HERO); - } -# endif } void -vga_special(chr,col,color) -int chr,col,color; +vga_special(chr, col, color) +int chr, col, color; { - int i,y,pixy; - char __far *tmp_d; /* destination pointer */ - int vplane; - char fnt; - char bits[SCREENPLANES][ROWS_PER_CELL]; + int i, y, pixy; + char __far *tmp_d; /* destination pointer */ + int vplane; + char fnt; + char bits[SCREENPLANES][ROWS_PER_CELL]; - pixy = PBAR_ROW * MAX_ROWS_PER_CELL; - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egareadplane(vplane); - y = pixy; - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp_d = screentable[y++] + col; - bits[vplane][i] = READ_ABSOLUTE(tmp_d); - fnt = READ_ABSOLUTE((font + ((chr<<4) + i))); - if (colorbits[vplane] & color) - bits[vplane][i] |= fnt; - else - bits[vplane][i] &= ~fnt; - } - } - for(vplane=0; vplane < SCREENPLANES; ++vplane) { - egawriteplane(vp[vplane]); - y = pixy; - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp_d = screentable[y++] + col; - WRITE_ABSOLUTE(tmp_d, (bits[vplane][i])); - } - } - egawriteplane(15); + pixy = PBAR_ROW * MAX_ROWS_PER_CELL; + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egareadplane(vplane); + y = pixy; + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp_d = screentable[y++] + col; + bits[vplane][i] = READ_ABSOLUTE(tmp_d); + fnt = READ_ABSOLUTE((font + ((chr << 4) + i))); + if (colorbits[vplane] & color) + bits[vplane][i] |= fnt; + else + bits[vplane][i] &= ~fnt; + } + } + for (vplane = 0; vplane < SCREENPLANES; ++vplane) { + egawriteplane(vp[vplane]); + y = pixy; + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp_d = screentable[y++] + col; + WRITE_ABSOLUTE(tmp_d, (bits[vplane][i])); + } + } + egawriteplane(15); } -# endif /*POSITIONBAR*/ +#endif /*POSITIONBAR*/ -# ifdef SIMULATE_CURSOR +#ifdef SIMULATE_CURSOR static struct planar_cell_struct undercursor; static struct planar_cell_struct cursor; @@ -1166,268 +1187,284 @@ static struct planar_cell_struct cursor; void vga_DrawCursor() { - int i,pixx,pixy,x,y,p; - char __far *tmp1; - char __far *tmp2; - unsigned char first,second; -/* char on[2] = {0xFF,0xFF}; */ -/* char off[2] = {0x00,0x00}; */ - boolean isrogue = Is_rogue_level(&u.uz); - boolean singlebyte = (isrogue || iflags.over_view - || iflags.traditional_view || !inmap); - int curtyp; + int i, pixx, pixy, x, y, p; + char __far *tmp1; + char __far *tmp2; + unsigned char first, second; + /* char on[2] = {0xFF,0xFF}; */ + /* char off[2] = {0x00,0x00}; */ + boolean isrogue = Is_rogue_level(&u.uz); + boolean singlebyte = + (isrogue || iflags.over_view || iflags.traditional_view || !inmap); + int curtyp; - if (!cursor_type && inmap) return; /* CURSOR_INVIS - nothing to do */ + if (!cursor_type && inmap) + return; /* CURSOR_INVIS - nothing to do */ - x = min(curcol,(CO - 1)); /* protection from callers */ - y = min(currow,(LI - 1)); /* protection from callers */ - if (!singlebyte && ((x < clipx) || (x > clipxmax))) return; - pixy = row2y(y); /* convert to pixels */ - if (singlebyte) - pixx = x; - else - pixx = col2x((x-clipx)); + x = min(curcol, (CO - 1)); /* protection from callers */ + y = min(currow, (LI - 1)); /* protection from callers */ + if (!singlebyte && ((x < clipx) || (x > clipxmax))) + return; + pixy = row2y(y); /* convert to pixels */ + if (singlebyte) + pixx = x; + else + pixx = col2x((x - clipx)); - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp1 = screentable[i+pixy]; - tmp1 += pixx; - tmp2 = tmp1 + 1; - egareadplane(3); - /* memcpy(undercursor.plane[3].image[i],tmp1,BYTES_PER_CELL); */ - undercursor.plane[3].image[i][0] = READ_ABSOLUTE(tmp1); - if (!singlebyte) - undercursor.plane[3].image[i][1] = READ_ABSOLUTE(tmp2); + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp1 = screentable[i + pixy]; + tmp1 += pixx; + tmp2 = tmp1 + 1; + egareadplane(3); + /* memcpy(undercursor.plane[3].image[i],tmp1,BYTES_PER_CELL); */ + undercursor.plane[3].image[i][0] = READ_ABSOLUTE(tmp1); + if (!singlebyte) + undercursor.plane[3].image[i][1] = READ_ABSOLUTE(tmp2); - egareadplane(2); - /* memcpy(undercursor.plane[2].image[i],tmp1,BYTES_PER_CELL); */ - undercursor.plane[2].image[i][0] = READ_ABSOLUTE(tmp1); - if (!singlebyte) - undercursor.plane[2].image[i][1] = READ_ABSOLUTE(tmp2); + egareadplane(2); + /* memcpy(undercursor.plane[2].image[i],tmp1,BYTES_PER_CELL); */ + undercursor.plane[2].image[i][0] = READ_ABSOLUTE(tmp1); + if (!singlebyte) + undercursor.plane[2].image[i][1] = READ_ABSOLUTE(tmp2); - egareadplane(1); - /* memcpy(undercursor.plane[1].image[i],tmp1,BYTES_PER_CELL); */ - undercursor.plane[1].image[i][0] = READ_ABSOLUTE(tmp1); - if (!singlebyte) - undercursor.plane[1].image[i][1] = READ_ABSOLUTE(tmp2); + egareadplane(1); + /* memcpy(undercursor.plane[1].image[i],tmp1,BYTES_PER_CELL); */ + undercursor.plane[1].image[i][0] = READ_ABSOLUTE(tmp1); + if (!singlebyte) + undercursor.plane[1].image[i][1] = READ_ABSOLUTE(tmp2); - egareadplane(0); - /* memcpy(undercursor.plane[0].image[i],tmp1,BYTES_PER_CELL); */ - undercursor.plane[0].image[i][0] = READ_ABSOLUTE(tmp1); - if (!singlebyte) - undercursor.plane[0].image[i][1] = READ_ABSOLUTE(tmp2); - } + egareadplane(0); + /* memcpy(undercursor.plane[0].image[i],tmp1,BYTES_PER_CELL); */ + undercursor.plane[0].image[i][0] = READ_ABSOLUTE(tmp1); + if (!singlebyte) + undercursor.plane[0].image[i][1] = READ_ABSOLUTE(tmp2); + } - /* - * Now we have a snapshot of the current cell. - * Make a copy of it, then manipulate the copy - * to include the cursor, and place the tinkered - * version on the display. - */ + /* + * Now we have a snapshot of the current cell. + * Make a copy of it, then manipulate the copy + * to include the cursor, and place the tinkered + * version on the display. + */ - cursor = undercursor; - if (inmap) curtyp = cursor_type; - else curtyp = CURSOR_UNDERLINE; + cursor = undercursor; + if (inmap) + curtyp = cursor_type; + else + curtyp = CURSOR_UNDERLINE; - switch(curtyp) { + switch (curtyp) { + case CURSOR_CORNER: + for (i = 0; i < 2; ++i) { + if (!i) { + if (singlebyte) + first = 0xC3; + else + first = 0xC0; + second = 0x03; + } else { + if (singlebyte) + first = 0x81; + else + first = 0x80; + second = 0x01; + } + for (p = 0; p < 4; ++p) { + if (cursor_color & colorbits[p]) { + cursor.plane[p].image[i][0] |= first; + if (!singlebyte) + cursor.plane[p].image[i][1] |= second; + } else { + cursor.plane[p].image[i][0] &= ~first; + if (!singlebyte) + cursor.plane[p].image[i][1] &= ~second; + } + } + } - case CURSOR_CORNER: - for(i = 0; i < 2; ++i) { - if (!i) { - if (singlebyte) first = 0xC3; - else first = 0xC0; - second = 0x03; - } else { - if (singlebyte) first = 0x81; - else first = 0x80; - second = 0x01; - } - for (p=0; p < 4; ++p) { - if (cursor_color & colorbits[p]) { - cursor.plane[p].image[i][0] |= first; - if (!singlebyte) - cursor.plane[p].image[i][1] |= second; - } else { - cursor.plane[p].image[i][0] &= ~first; - if (!singlebyte) - cursor.plane[p].image[i][1] &= ~second; - } - } - } + for (i = ROWS_PER_CELL - 2; i < ROWS_PER_CELL; ++i) { + if (i != (ROWS_PER_CELL - 1)) { + if (singlebyte) + first = 0x81; + else + first = 0x80; + second = 0x01; + } else { + if (singlebyte) + first = 0xC3; + else + first = 0xC0; + second = 0x03; + } + for (p = 0; p < SCREENPLANES; ++p) { + if (cursor_color & colorbits[p]) { + cursor.plane[p].image[i][0] |= first; + if (!singlebyte) + cursor.plane[p].image[i][1] |= second; + } else { + cursor.plane[p].image[i][0] &= ~first; + if (!singlebyte) + cursor.plane[p].image[i][1] &= ~second; + } + } + } + break; - for(i = ROWS_PER_CELL - 2; i < ROWS_PER_CELL; ++i) { - if (i != (ROWS_PER_CELL-1)) { - if (singlebyte) first = 0x81; - else first = 0x80; - second = 0x01; - } else { - if (singlebyte) first = 0xC3; - else first = 0xC0; - second = 0x03; - } - for (p=0; p < SCREENPLANES; ++p) { - if (cursor_color & colorbits[p]) { - cursor.plane[p].image[i][0] |= first; - if (!singlebyte) - cursor.plane[p].image[i][1] |= second; - } else { - cursor.plane[p].image[i][0] &= ~first; - if (!singlebyte) - cursor.plane[p].image[i][1] &= ~second; - } - } - } - break; + case CURSOR_UNDERLINE: - case CURSOR_UNDERLINE: + i = ROWS_PER_CELL - 1; + first = 0xFF; + second = 0xFF; + for (p = 0; p < SCREENPLANES; ++p) { + if (cursor_color & colorbits[p]) { + cursor.plane[p].image[i][0] |= first; + if (!singlebyte) + cursor.plane[p].image[i][1] |= second; + } else { + cursor.plane[p].image[i][0] &= ~first; + if (!singlebyte) + cursor.plane[p].image[i][1] &= ~second; + } + } + break; - i = ROWS_PER_CELL - 1; - first = 0xFF; - second = 0xFF; - for (p=0; p < SCREENPLANES; ++p) { - if (cursor_color & colorbits[p]) { - cursor.plane[p].image[i][0] |= first; - if (!singlebyte) - cursor.plane[p].image[i][1] |= second; - } else { - cursor.plane[p].image[i][0] &= ~first; - if (!singlebyte) - cursor.plane[p].image[i][1] &= ~second; - } - } - break; + case CURSOR_FRAME: - case CURSOR_FRAME: + /* fall through */ - /* fall through */ + default: + for (i = 0; i < ROWS_PER_CELL; ++i) { + if ((i == 0) || (i == (ROWS_PER_CELL - 1))) { + first = 0xFF; + second = 0xFF; + } else { + if (singlebyte) + first = 0x81; + else + first = 0x80; + second = 0x01; + } + for (p = 0; p < SCREENPLANES; ++p) { + if (cursor_color & colorbits[p]) { + cursor.plane[p].image[i][0] |= first; + if (!singlebyte) + cursor.plane[p].image[i][1] |= second; + } else { + cursor.plane[p].image[i][0] &= ~first; + if (!singlebyte) + cursor.plane[p].image[i][1] &= ~second; + } + } + } + break; + } - default: - for(i = 0; i < ROWS_PER_CELL; ++i) { + /* + * Place the new cell onto the display. + * + */ - if ((i == 0) || (i == (ROWS_PER_CELL-1))) { - first = 0xFF; - second = 0xFF; - } else { - if (singlebyte) first = 0x81; - else first = 0x80; - second = 0x01; - } - for (p=0; p < SCREENPLANES; ++p) { - if (cursor_color & colorbits[p]) { - cursor.plane[p].image[i][0] |= first; - if (!singlebyte) - cursor.plane[p].image[i][1] |= second; - } else { - cursor.plane[p].image[i][0] &= ~first; - if (!singlebyte) - cursor.plane[p].image[i][1] &= ~second; - } - } - } - break; - } + for (i = 0; i < ROWS_PER_CELL; ++i) { + tmp1 = screentable[i + pixy]; + tmp1 += pixx; + tmp2 = tmp1 + 1; + egawriteplane(8); + /* memcpy(tmp1,cursor.plane[3].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, cursor.plane[3].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, cursor.plane[3].image[i][1]); - /* - * Place the new cell onto the display. - * - */ - - for(i=0;i < ROWS_PER_CELL; ++i) { - tmp1 = screentable[i+pixy]; - tmp1 += pixx; - tmp2 = tmp1 + 1; - egawriteplane(8); - /* memcpy(tmp1,cursor.plane[3].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,cursor.plane[3].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,cursor.plane[3].image[i][1]); + egawriteplane(4); + /* memcpy(tmp1,cursor.plane[2].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, cursor.plane[2].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, cursor.plane[2].image[i][1]); - egawriteplane(4); - /* memcpy(tmp1,cursor.plane[2].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,cursor.plane[2].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,cursor.plane[2].image[i][1]); + egawriteplane(2); + /* memcpy(tmp1,cursor.plane[1].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, cursor.plane[1].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, cursor.plane[1].image[i][1]); - egawriteplane(2); - /* memcpy(tmp1,cursor.plane[1].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,cursor.plane[1].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,cursor.plane[1].image[i][1]); - - egawriteplane(1); - /* memcpy(tmp1,cursor.plane[0].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,cursor.plane[0].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,cursor.plane[0].image[i][1]); - } - egawriteplane(15); + egawriteplane(1); + /* memcpy(tmp1,cursor.plane[0].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, cursor.plane[0].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, cursor.plane[0].image[i][1]); + } + egawriteplane(15); #ifdef POSITIONBAR - if (inmap) positionbar(); + if (inmap) + positionbar(); #endif } void vga_HideCursor() { + int i, pixx, pixy, x, y; + char __far *tmp1; + char __far *tmp2; + boolean isrogue = Is_rogue_level(&u.uz); + boolean singlebyte = + (isrogue || iflags.over_view || iflags.traditional_view || !inmap); + int curtyp; - int i,pixx,pixy,x,y; - char __far *tmp1; - char __far *tmp2; - boolean isrogue = Is_rogue_level(&u.uz); - boolean singlebyte = (isrogue || iflags.over_view - || iflags.traditional_view || !inmap); - int curtyp; - - if (inmap && !cursor_type) return; /* CURSOR_INVIS - nothing to do */ - /* protection from callers */ - x = min(curcol,(CO - 1)); - y = min(currow,(LI-1)); - if (!singlebyte && ((x < clipx) || (x > clipxmax))) return; + if (inmap && !cursor_type) + return; /* CURSOR_INVIS - nothing to do */ + /* protection from callers */ + x = min(curcol, (CO - 1)); + y = min(currow, (LI - 1)); + if (!singlebyte && ((x < clipx) || (x > clipxmax))) + return; - pixy = row2y(y); /* convert to pixels */ - if (singlebyte) - pixx = x; - else - pixx = col2x((x-clipx)); + pixy = row2y(y); /* convert to pixels */ + if (singlebyte) + pixx = x; + else + pixx = col2x((x - clipx)); - if (inmap) curtyp = cursor_type; - else curtyp = CURSOR_UNDERLINE; + if (inmap) + curtyp = cursor_type; + else + curtyp = CURSOR_UNDERLINE; - if (curtyp == CURSOR_UNDERLINE) /* optimization for uline */ - i = ROWS_PER_CELL - 1; - else - i = 0; + if (curtyp == CURSOR_UNDERLINE) /* optimization for uline */ + i = ROWS_PER_CELL - 1; + else + i = 0; - for(;i < ROWS_PER_CELL; ++i) { - tmp1 = screentable[i+pixy]; - tmp1 += pixx; - tmp2 = tmp1 + 1; - egawriteplane(8); - /* memcpy(tmp,undercursor.plane[3].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,undercursor.plane[3].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,undercursor.plane[3].image[i][1]); + for (; i < ROWS_PER_CELL; ++i) { + tmp1 = screentable[i + pixy]; + tmp1 += pixx; + tmp2 = tmp1 + 1; + egawriteplane(8); + /* memcpy(tmp,undercursor.plane[3].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, undercursor.plane[3].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, undercursor.plane[3].image[i][1]); - egawriteplane(4); - /* memcpy(tmp,undercursor.plane[2].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,undercursor.plane[2].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,undercursor.plane[2].image[i][1]); + egawriteplane(4); + /* memcpy(tmp,undercursor.plane[2].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, undercursor.plane[2].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, undercursor.plane[2].image[i][1]); - egawriteplane(2); - /* memcpy(tmp,undercursor.plane[1].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,undercursor.plane[1].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,undercursor.plane[1].image[i][1]); + egawriteplane(2); + /* memcpy(tmp,undercursor.plane[1].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, undercursor.plane[1].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, undercursor.plane[1].image[i][1]); - egawriteplane(1); - /* memcpy(tmp,undercursor.plane[0].image[i],BYTES_PER_CELL); */ - WRITE_ABSOLUTE(tmp1,undercursor.plane[0].image[i][0]); - if (!singlebyte) - WRITE_ABSOLUTE(tmp2,undercursor.plane[0].image[i][1]); - } - egawriteplane(15); + egawriteplane(1); + /* memcpy(tmp,undercursor.plane[0].image[i],BYTES_PER_CELL); */ + WRITE_ABSOLUTE(tmp1, undercursor.plane[0].image[i][0]); + if (!singlebyte) + WRITE_ABSOLUTE(tmp2, undercursor.plane[0].image[i][1]); + } + egawriteplane(15); } -# endif /* SIMULATE_CURSOR */ +#endif /* SIMULATE_CURSOR */ #endif /* SCREEN_VGA */ /* vidvga.c */ diff --git a/sys/os2/os2.c b/sys/os2/os2.c index abbbf6d25..acac019ec 100644 --- a/sys/os2/os2.c +++ b/sys/os2/os2.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 os2.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 os2.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 os2.c $Date: 2009/05/06 10:50:12 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)os2.c 3.5 1996/02/29 */ /* Copyright (c) Timo Hakulinen, 1990, 1991, 1992, 1993, 1996. */ @@ -38,24 +38,24 @@ static char NDECL(BIOSgetch); int tgetch() { - char ch; + char ch; - /* BIOSgetch can use the numeric key pad on IBM compatibles. */ - if (iflags.BIOS) - ch = BIOSgetch(); - else - ch = DOSgetch(); - return ((ch == '\r') ? '\n' : ch); + /* BIOSgetch can use the numeric key pad on IBM compatibles. */ + if (iflags.BIOS) + ch = BIOSgetch(); + else + ch = DOSgetch(); + return ((ch == '\r') ? '\n' : ch); } /* * Keyboard translation tables. */ -#define KEYPADLO 0x47 -#define KEYPADHI 0x53 +#define KEYPADLO 0x47 +#define KEYPADHI 0x53 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -63,36 +63,38 @@ tgetch() * shift values below. */ static const struct pad { - char normal, shift, cntrl; -} keypad[PADKEYS] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'g', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'p', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + char normal, shift, cntrl; +} keypad[PADKEYS] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'g', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { 'p', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; /* * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII @@ -102,116 +104,119 @@ static const struct pad { * scan code table to translate the scan code into a letter, then set the * "meta" bit for it. -3. */ -#define SCANLO 0x10 -#define SCANHI 0x32 -#define SCANKEYS (SCANHI - SCANLO + 1) -#define inmap(x) (SCANLO <= (x) && (x) <= SCANHI) +#define SCANLO 0x10 +#define SCANHI 0x32 +#define SCANKEYS (SCANHI - SCANLO + 1) +#define inmap(x) (SCANLO <= (x) && (x) <= SCANHI) -static const char scanmap[SCANKEYS] = { /* ... */ - 'q','w','e','r','t','y','u','i','o','p','[',']', '\n', - 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`', - 0, '\\', 'z','x','c','v','b','N','m' /* ... */ +static const char scanmap[SCANKEYS] = { + /* ... */ + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', + 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', + 'c', 'v', 'b', 'N', 'm' /* ... */ }; /* * BIOSgetch emulates the MSDOS way of getting keys directly with a BIOS call. */ -#define SHIFT_KEY (0x1 | 0x2) -#define CTRL_KEY 0x4 -#define ALT_KEY 0x8 +#define SHIFT_KEY (0x1 | 0x2) +#define CTRL_KEY 0x4 +#define ALT_KEY 0x8 static char BIOSgetch() { - unsigned char scan, shift, ch; - const struct pad *kpad; + unsigned char scan, shift, ch; + const struct pad *kpad; - KBDKEYINFO CharData; - USHORT IOWait = 0; - HKBD KbdHandle = 0; + KBDKEYINFO CharData; + USHORT IOWait = 0; + HKBD KbdHandle = 0; - KbdCharIn(&CharData,IOWait,KbdHandle); - ch = CharData.chChar; - scan = CharData.chScan; - shift = CharData.fsState; + KbdCharIn(&CharData, IOWait, KbdHandle); + ch = CharData.chChar; + scan = CharData.chScan; + shift = CharData.fsState; - /* Translate keypad keys */ - if (iskeypad(scan)) { - kpad = iflags.num_pad ? numpad : keypad; - if (shift & SHIFT_KEY) - ch = kpad[scan - KEYPADLO].shift; - else if (shift & CTRL_KEY) - ch = kpad[scan - KEYPADLO].cntrl; - else - ch = kpad[scan - KEYPADLO].normal; - } - /* Translate unassigned Alt-letters */ - if ((shift & ALT_KEY) && !ch) { - if (inmap(scan)) - ch = scanmap[scan - SCANLO]; - return (isprint(ch) ? M(ch) : ch); - } - return ch; + /* Translate keypad keys */ + if (iskeypad(scan)) { + kpad = iflags.num_pad ? numpad : keypad; + if (shift & SHIFT_KEY) + ch = kpad[scan - KEYPADLO].shift; + else if (shift & CTRL_KEY) + ch = kpad[scan - KEYPADLO].cntrl; + else + ch = kpad[scan - KEYPADLO].normal; + } + /* Translate unassigned Alt-letters */ + if ((shift & ALT_KEY) && !ch) { + if (inmap(scan)) + ch = scanmap[scan - SCANLO]; + return (isprint(ch) ? M(ch) : ch); + } + return ch; } static char DOSgetch() { - KBDKEYINFO CharData; - USHORT IOWait = 0; - HKBD KbdHandle = 0; + KBDKEYINFO CharData; + USHORT IOWait = 0; + HKBD KbdHandle = 0; - KbdCharIn(&CharData,IOWait,KbdHandle); - if (CharData.chChar == 0) { /* an extended code -- not yet supported */ - KbdCharIn(&CharData,IOWait,KbdHandle); /* eat the next character */ - CharData.chChar = 0; /* and return a 0 */ - } - return (CharData.chChar); + KbdCharIn(&CharData, IOWait, KbdHandle); + if (CharData.chChar == 0) { /* an extended code -- not yet supported */ + KbdCharIn(&CharData, IOWait, KbdHandle); /* eat the next character */ + CharData.chChar = 0; /* and return a 0 */ + } + return (CharData.chChar); } char switchar() { - return '/'; + return '/'; } int kbhit() { - KBDKEYINFO CharData; - HKBD KbdHandle = 0; + KBDKEYINFO CharData; + HKBD KbdHandle = 0; - KbdPeek(&CharData,KbdHandle); - return (CharData.fbStatus & (1 << 6)); + KbdPeek(&CharData, KbdHandle); + return (CharData.fbStatus & (1 << 6)); } long freediskspace(path) char *path; { - FSALLOCATE FSInfoBuf; + FSALLOCATE FSInfoBuf; #ifdef OS2_32BITAPI - ULONG + ULONG #else - USHORT + USHORT #endif - DriveNumber, FSInfoLevel = 1, res; + DriveNumber, FSInfoLevel = 1, res; - if (path[0] && path[1] == ':') - DriveNumber = (toupper(path[0]) - 'A') + 1; - else - DriveNumber = 0; - res = + if (path[0] && path[1] == ':') + DriveNumber = (toupper(path[0]) - 'A') + 1; + else + DriveNumber = 0; + res = #ifdef OS2_32BITAPI - DosQueryFSInfo(DriveNumber,FSInfoLevel,(PVOID)&FSInfoBuf,(ULONG)sizeof(FSInfoBuf)); + DosQueryFSInfo(DriveNumber, FSInfoLevel, (PVOID) &FSInfoBuf, + (ULONG) sizeof(FSInfoBuf)); #else - DosQFSInfo(DriveNumber,FSInfoLevel,(PBYTE)&FSInfoBuf,(USHORT)sizeof(FSInfoBuf)); + DosQFSInfo(DriveNumber, FSInfoLevel, (PBYTE) &FSInfoBuf, + (USHORT) sizeof(FSInfoBuf)); #endif - if (res) - return -1L; /* error */ - else - return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail * - FSInfoBuf.cbSector); + if (res) + return -1L; /* error */ + else + return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail + * FSInfoBuf.cbSector); } /* @@ -230,55 +235,59 @@ findfirst(path) char *path; { #ifdef OS2_32BITAPI - ULONG + ULONG #else - USHORT + USHORT #endif - res, SearchCount = 1; + res, SearchCount = 1; - DirHandle = 1; - res = + DirHandle = 1; + res = #ifdef OS2_32BITAPI - DosFindFirst((PSZ)path,&DirHandle,0L,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount,1L); + DosFindFirst((PSZ) path, &DirHandle, 0L, (PVOID) &ResultBuf, + (ULONG) sizeof(ResultBuf), &SearchCount, 1L); #else - DosFindFirst((PSZ)path,&DirHandle,0,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount,0L); + DosFindFirst((PSZ) path, &DirHandle, 0, &ResultBuf, + (USHORT) sizeof(ResultBuf), &SearchCount, 0L); #endif - return(!res); + return (!res); } int findnext() { #ifdef OS2_32BITAPI - ULONG + ULONG #else - USHORT + USHORT #endif - res, SearchCount = 1; + res, SearchCount = 1; - res = + res = #ifdef OS2_32BITAPI - DosFindNext(DirHandle,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount); + DosFindNext(DirHandle, (PVOID) &ResultBuf, (ULONG) sizeof(ResultBuf), + &SearchCount); #else - DosFindNext(DirHandle,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount); + DosFindNext(DirHandle, &ResultBuf, (USHORT) sizeof(ResultBuf), + &SearchCount); #endif - return(!res); + return (!res); } char * foundfile_buffer() { - return(ResultBuf.achName); + return (ResultBuf.achName); } long filesize(file) char *file; { - if (findfirst(file)) { - return (* (long *) (ResultBuf.cbFileAlloc)); - } else - return -1L; + if (findfirst(file)) { + return (*(long *) (ResultBuf.cbFileAlloc)); + } else + return -1L; } /* @@ -288,77 +297,80 @@ void chdrive(str) char *str; { - char *ptr; - char drive; + char *ptr; + char drive; - if ((ptr = index(str, ':')) != (char *)0) { - drive = toupper(*(ptr - 1)); + if ((ptr = index(str, ':')) != (char *) 0) { + drive = toupper(*(ptr - 1)); #ifdef OS2_32BITAPI - DosSetDefaultDisk((ULONG)(drive - 'A' + 1)); + DosSetDefaultDisk((ULONG)(drive - 'A' + 1)); #else - DosSelectDisk((USHORT)(drive - 'A' + 1)); + DosSelectDisk((USHORT)(drive - 'A' + 1)); #endif - } + } } void disable_ctrlP() { - KBDINFO KbdInfo; - HKBD KbdHandle = 0; + KBDINFO KbdInfo; + HKBD KbdHandle = 0; - if (!iflags.rawio) return; - KbdInfo.cb = sizeof(KbdInfo); - KbdGetStatus(&KbdInfo,KbdHandle); - KbdInfo.fsMask &= 0xFFF7; /* ASCII off */ - KbdInfo.fsMask |= 0x0004; /* BINARY on */ - KbdSetStatus(&KbdInfo,KbdHandle); + if (!iflags.rawio) + return; + KbdInfo.cb = sizeof(KbdInfo); + KbdGetStatus(&KbdInfo, KbdHandle); + KbdInfo.fsMask &= 0xFFF7; /* ASCII off */ + KbdInfo.fsMask |= 0x0004; /* BINARY on */ + KbdSetStatus(&KbdInfo, KbdHandle); } void enable_ctrlP() { - KBDINFO KbdInfo; - HKBD KbdHandle = 0; + KBDINFO KbdInfo; + HKBD KbdHandle = 0; - if (!iflags.rawio) return; - KbdInfo.cb = sizeof(KbdInfo); - KbdGetStatus(&KbdInfo,KbdHandle); - KbdInfo.fsMask &= 0xFFFB; /* BINARY off */ - KbdInfo.fsMask |= 0x0008; /* ASCII on */ - KbdSetStatus(&KbdInfo,KbdHandle); + if (!iflags.rawio) + return; + KbdInfo.cb = sizeof(KbdInfo); + KbdGetStatus(&KbdInfo, KbdHandle); + KbdInfo.fsMask &= 0xFFFB; /* BINARY off */ + KbdInfo.fsMask |= 0x0008; /* ASCII on */ + KbdSetStatus(&KbdInfo, KbdHandle); } void get_scr_size() { - VIOMODEINFO ModeInfo; - HVIO VideoHandle = 0; + VIOMODEINFO ModeInfo; + HVIO VideoHandle = 0; - ModeInfo.cb = sizeof(ModeInfo); + ModeInfo.cb = sizeof(ModeInfo); - (void) VioGetMode(&ModeInfo,VideoHandle); + (void) VioGetMode(&ModeInfo, VideoHandle); - CO = ModeInfo.col; - LI = ModeInfo.row; + CO = ModeInfo.col; + LI = ModeInfo.row; } void -gotoxy(x,y) -int x,y; +gotoxy(x, y) +int x, y; { - HVIO VideoHandle = 0; + HVIO VideoHandle = 0; - x--; y--; /* (0,0) is upper right corner */ + x--; + y--; /* (0,0) is upper right corner */ - (void) VioSetCurPos(x, y, VideoHandle); + (void) VioSetCurPos(x, y, VideoHandle); } - -char* get_username(lan_username_size) +char * +get_username(lan_username_size) int *lan_username_size; { - return (char*)0; + return (char *) 0; } #ifdef X11_GRAPHICS int errno; diff --git a/sys/share/dgn_lex.c b/sys/share/dgn_lex.c index c3def56ea..667b7797b 100644 --- a/sys/share/dgn_lex.c +++ b/sys/share/dgn_lex.c @@ -8,7 +8,7 @@ #define YY_FLEX_MINOR_VERSION 5 #include "config.h" -#define yyconst const /* some code inserted by flex will refer to yyconst */ +#define yyconst const /* some code inserted by flex will refer to yyconst */ /* Returned upon end-of-file. */ #define YY_NULL 0 @@ -37,7 +37,7 @@ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) +#define YY_NEW_FILE yyrestart(yyin) #define YY_END_OF_BUFFER_CHAR 0 @@ -53,18 +53,17 @@ extern FILE *yyin, *yyout; #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 -/* Return all but the first 'n' matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) +/* Return all but the first 'n' matched characters back to the input stream. + */ +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) -#define unput(c) yyunput( c, yytext_ptr ) +#define unput(c) yyunput(c, yytext_ptr) /* The following is because we cannot portably get our hands on size_t * (without autoconf's help, which isn't available because we want @@ -72,63 +71,61 @@ extern FILE *yyin, *yyout; */ typedef unsigned int yy_size_t; +struct yy_buffer_state { + FILE *yy_input_file; -struct yy_buffer_state - { - FILE *yy_input_file; + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; + int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ +/* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - }; +}; static YY_BUFFER_STATE yy_current_buffer = 0; @@ -141,14 +138,14 @@ static YY_BUFFER_STATE yy_current_buffer = 0; /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ +static int yy_n_chars; /* number of characters read into yy_ch_buf */ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... @@ -159,31 +156,31 @@ void FDECL(yyrestart, (FILE *)); void FDECL(yy_switch_to_buffer, (YY_BUFFER_STATE)); void NDECL(yy_load_buffer_state); -YY_BUFFER_STATE FDECL(yy_create_buffer, (FILE *,int)); +YY_BUFFER_STATE FDECL(yy_create_buffer, (FILE *, int)); void FDECL(yy_delete_buffer, (YY_BUFFER_STATE)); -void FDECL(yy_init_buffer, (YY_BUFFER_STATE,FILE *)); +void FDECL(yy_init_buffer, (YY_BUFFER_STATE, FILE *)); void FDECL(yy_flush_buffer, (YY_BUFFER_STATE)); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) +#define YY_FLUSH_BUFFER yy_flush_buffer(yy_current_buffer) static genericptr_t FDECL(yy_flex_alloc, (yy_size_t)); -static genericptr_t FDECL(yy_flex_realloc2, (genericptr_t,yy_size_t,int)); +static genericptr_t FDECL(yy_flex_realloc2, (genericptr_t, yy_size_t, int)); static void FDECL(yy_flex_free, (genericptr_t)); #define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!yy_current_buffer) \ + yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } -#define yy_set_bol(at_bol) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ - } +#define yy_set_bol(at_bol) \ + { \ + if (!yy_current_buffer) \ + yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (yy_current_buffer->yy_at_bol) @@ -201,199 +198,142 @@ static void FDECL(yy_fatal_error, (const char *)); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; #define YY_NUM_RULES 35 #define YY_END_OF_BUFFER 36 -static yyconst short int yy_accept[196] = - { 0, - 0, 0, 36, 34, 33, 32, 34, 34, 29, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 33, - 32, 0, 30, 29, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 31, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, +static yyconst short int yy_accept[196] = { + 0, 0, 0, 36, 34, 33, 32, 34, 34, 29, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 33, 32, 0, 30, + 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, - 4, 0, 25, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 6, 0, 0, 0, 5, 0, 0, 23, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 20, 0, 0, 0, 0, 8, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 22, - 15, 0, 21, 7, 19, 0, 0, 0, 0, 0, - 0, 13, 0, 0, 0, 26, 16, 0, 0, 12, - 0, 0, 0, 11, 9, 0, 17, 18, 0, 27, - 0, 28, 24, 10, 0 + 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 4, 0, 25, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 6, 0, 0, 0, 5, 0, 0, 23, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 8, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 22, 15, 0, 21, 7, 19, 0, 0, 0, + 0, 0, 0, 13, 0, 0, 0, 26, 16, 0, 0, 12, 0, 0, 0, 11, 9, + 0, 17, 18, 0, 27, 0, 28, 24, 10, 0 - } ; +}; -static yyconst int yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 5, 6, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 7, 1, 1, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 1, 1, 1, - 1, 1, 1, 1, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 1, 1, 17, 18, 19, 20, 21, - 1, 22, 23, 24, 25, 26, 1, 1, 27, 1, - 1, 1, 1, 1, 28, 1, 29, 1, 30, 31, +static yyconst int yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 5, 6, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 7, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 1, 1, 1, 1, 1, 1, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 1, + 17, 18, 19, 20, 21, 1, 22, 23, 24, 25, 26, 1, 1, 27, 1, 1, 1, 1, 1, + 28, 1, 29, 1, 30, 31, - 32, 33, 34, 35, 36, 1, 37, 38, 39, 40, - 41, 42, 1, 43, 44, 45, 46, 1, 47, 1, - 1, 48, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 32, 33, 34, 35, 36, 1, 37, 38, 39, 40, 41, 42, 1, 43, 44, 45, 46, 1, 47, + 1, 1, 48, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; -static yyconst int yy_meta[49] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1 - } ; +static yyconst int yy_meta[49] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; -static yyconst short int yy_base[198] = - { 0, - 0, 213, 218, 220, 215, 220, 213, 210, 207, 196, - 190, 196, 37, 191, 197, 186, 188, 171, 164, 172, - 174, 173, 18, 160, 159, 154, 157, 11, 194, 194, - 220, 190, 220, 187, 177, 184, 183, 167, 170, 164, - 161, 166, 174, 155, 136, 144, 134, 132, 133, 26, - 135, 143, 147, 128, 145, 220, 170, 220, 158, 152, - 154, 159, 154, 145, 44, 142, 47, 124, 124, 125, - 129, 129, 115, 27, 121, 113, 111, 120, 115, 116, - 134, 142, 132, 128, 137, 121, 130, 129, 125, 129, - 131, 97, 220, 105, 94, 101, 95, 96, 94, 99, +static yyconst short int yy_base[198] = { + 0, 0, 213, 218, 220, 215, 220, 213, 210, 207, 196, 190, 196, 37, 191, + 197, 186, 188, 171, 164, 172, 174, 173, 18, 160, 159, 154, 157, 11, 194, + 194, 220, 190, 220, 187, 177, 184, 183, 167, 170, 164, 161, 166, 174, 155, + 136, 144, 134, 132, 133, 26, 135, 143, 147, 128, 145, 220, 170, 220, 158, + 152, 154, 159, 154, 145, 44, 142, 47, 124, 124, 125, 129, 129, 115, 27, + 121, 113, 111, 120, 115, 116, 134, 142, 132, 128, 137, 121, 130, 129, 125, + 129, 131, 97, 220, 105, 94, 101, 95, 96, 94, 99, - 105, 101, 89, 220, 95, 112, 114, 51, 112, 107, - 220, 110, 114, 111, 106, 96, 85, 76, 81, 82, - 88, 69, 220, 81, 76, 75, 220, 78, 99, 220, - 88, 97, 87, 88, 92, 93, 88, 91, 90, 71, - 65, 220, 62, 60, 57, 56, 220, 59, 54, 74, - 84, 65, 66, 220, 70, 65, 70, 60, 68, 220, - 220, 52, 220, 220, 220, 46, 50, 57, 61, 67, - 62, 220, 67, 64, 63, 220, 220, 42, 41, 220, - 61, 53, 49, 220, 220, 50, 220, 220, 51, 220, - 46, 220, 220, 220, 220, 62, 60 + 105, 101, 89, 220, 95, 112, 114, 51, 112, 107, 220, 110, 114, 111, 106, + 96, 85, 76, 81, 82, 88, 69, 220, 81, 76, 75, 220, 78, 99, 220, + 88, 97, 87, 88, 92, 93, 88, 91, 90, 71, 65, 220, 62, 60, 57, + 56, 220, 59, 54, 74, 84, 65, 66, 220, 70, 65, 70, 60, 68, 220, + 220, 52, 220, 220, 220, 46, 50, 57, 61, 67, 62, 220, 67, 64, 63, + 220, 220, 42, 41, 220, 61, 53, 49, 220, 220, 50, 220, 220, 51, 220, + 46, 220, 220, 220, 220, 62, 60 - } ; +}; -static yyconst short int yy_def[198] = - { 0, - 195, 1, 195, 195, 195, 195, 195, 196, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 197, 195, - 195, 196, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 197, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, +static yyconst short int yy_def[198] = { + 0, 195, 1, 195, 195, 195, 195, 195, 196, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 197, + 195, 195, 196, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 197, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 0, 195, 195 + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 0, 195, 195 - } ; +}; -static yyconst short int yy_nxt[269] = - { 0, - 4, 5, 6, 7, 8, 4, 9, 10, 11, 12, - 13, 14, 4, 4, 4, 4, 15, 4, 4, 4, - 16, 17, 4, 4, 4, 4, 4, 4, 4, 18, - 19, 4, 4, 4, 20, 4, 4, 21, 22, 23, - 4, 24, 25, 26, 27, 28, 4, 4, 38, 49, - 55, 87, 56, 74, 75, 88, 90, 98, 50, 131, - 57, 39, 32, 91, 194, 193, 192, 132, 191, 190, - 189, 188, 99, 187, 186, 185, 184, 183, 182, 181, - 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, - 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, +static yyconst short int yy_nxt[269] = { + 0, 4, 5, 6, 7, 8, 4, 9, 10, 11, 12, 13, 14, 4, 4, + 4, 4, 15, 4, 4, 4, 16, 17, 4, 4, 4, 4, 4, 4, 4, + 18, 19, 4, 4, 4, 20, 4, 4, 21, 22, 23, 4, 24, 25, 26, + 27, 28, 4, 4, 38, 49, 55, 87, 56, 74, 75, 88, 90, 98, 50, + 131, 57, 39, 32, 91, 194, 193, 192, 132, 191, 190, 189, 188, 99, 187, + 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172, + 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, - 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, - 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, - 140, 139, 138, 137, 136, 135, 134, 133, 130, 129, - 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, - 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, - 108, 107, 106, 105, 104, 103, 102, 101, 100, 97, - 96, 95, 94, 93, 92, 89, 86, 85, 84, 83, - 82, 81, 58, 80, 79, 78, 77, 76, 73, 72, - 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, - 61, 60, 59, 34, 33, 30, 58, 54, 53, 52, + 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, + 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 130, 129, + 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, + 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 97, + 96, 95, 94, 93, 92, 89, 86, 85, 84, 83, 82, 81, 58, 80, 79, + 78, 77, 76, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, + 61, 60, 59, 34, 33, 30, 58, 54, 53, 52, - 51, 48, 47, 46, 45, 44, 43, 42, 41, 40, - 37, 36, 35, 34, 33, 31, 30, 195, 29, 3, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195 - } ; + 51, 48, 47, 46, 45, 44, 43, 42, 41, 40, 37, 36, 35, 34, 33, + 31, 30, 195, 29, 3, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195 +}; -static yyconst short int yy_chk[269] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 13, 23, - 28, 65, 28, 50, 50, 65, 67, 74, 23, 108, - 197, 13, 196, 67, 191, 189, 186, 108, 183, 182, - 181, 179, 74, 178, 175, 174, 173, 171, 170, 169, - 168, 167, 166, 162, 159, 158, 157, 156, 155, 153, - 152, 151, 150, 149, 148, 146, 145, 144, 143, 141, +static yyconst short int yy_chk[269] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 13, 23, 28, 65, 28, 50, 50, 65, 67, 74, 23, + 108, 197, 13, 196, 67, 191, 189, 186, 108, 183, 182, 181, 179, 74, 178, + 175, 174, 173, 171, 170, 169, 168, 167, 166, 162, 159, 158, 157, 156, 155, + 153, 152, 151, 150, 149, 148, 146, 145, 144, 143, 141, - 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, - 129, 128, 126, 125, 124, 122, 121, 120, 119, 118, - 117, 116, 115, 114, 113, 112, 110, 109, 107, 106, - 105, 103, 102, 101, 100, 99, 98, 97, 96, 95, - 94, 92, 91, 90, 89, 88, 87, 86, 85, 84, - 83, 82, 81, 80, 79, 78, 77, 76, 75, 73, - 72, 71, 70, 69, 68, 66, 64, 63, 62, 61, - 60, 59, 57, 55, 54, 53, 52, 51, 49, 48, - 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, - 37, 36, 35, 34, 32, 30, 29, 27, 26, 25, + 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 129, 128, 126, 125, 124, + 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 110, 109, 107, 106, + 105, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 92, 91, 90, 89, + 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 73, + 72, 71, 70, 69, 68, 66, 64, 63, 62, 61, 60, 59, 57, 55, 54, + 53, 52, 51, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, + 37, 36, 35, 34, 32, 30, 29, 27, 26, 25, - 24, 22, 21, 20, 19, 18, 17, 16, 15, 14, - 12, 11, 10, 9, 8, 7, 5, 3, 2, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 195, 195, 195, 195, 195, 195 - } ; + 24, 22, 21, 20, 19, 18, 17, 16, 15, 14, 12, 11, 10, 9, 8, + 7, 5, 3, 2, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 195 +}; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; @@ -423,55 +363,54 @@ char *yytext; * yyunput is properly declared in flex.skel. */ #if !defined(FLEX_SCANNER) && !defined(FLEXHACK_SCANNER) -int FDECL(yyback, (int *,int)); +int FDECL(yyback, (int *, int)); int NDECL(yylook); int NDECL(yyinput); int NDECL(yywrap); int NDECL(yylex); - /* Traditional lexes let yyunput() and yyoutput() default to int; - * newer ones may declare them as void since they don't return - * values. For even more fun, the lex supplied as part of the - * newer unbundled compiler for SunOS 4.x adds the void declarations - * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain - * int) while the bundled lex and the one with the older unbundled - * compiler do not. To detect this, we need help from outside -- - * sys/unix/Makefile.utl. - * - * Digital UNIX is difficult and still has int in spite of all - * other signs. - */ -# if defined(NeXT) || defined(SVR4) || defined(_AIX32) -# define VOIDYYPUT -# endif -# if !defined(VOIDYYPUT) && defined(POSIX_TYPES) -# if !defined(BOS) && !defined(HISX) && !defined(_M_UNIX) && !defined(VMS) -# define VOIDYYPUT -# endif -# endif -# if !defined(VOIDYYPUT) && defined(WEIRD_LEX) -# if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX > 1) -# define VOIDYYPUT -# endif -# endif -# if defined(VOIDYYPUT) && defined(__osf__) -# undef VOIDYYPUT -# endif -# ifdef VOIDYYPUT +/* Traditional lexes let yyunput() and yyoutput() default to int; + * newer ones may declare them as void since they don't return + * values. For even more fun, the lex supplied as part of the + * newer unbundled compiler for SunOS 4.x adds the void declarations + * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain + * int) while the bundled lex and the one with the older unbundled + * compiler do not. To detect this, we need help from outside -- + * sys/unix/Makefile.utl. + * + * Digital UNIX is difficult and still has int in spite of all + * other signs. + */ +#if defined(NeXT) || defined(SVR4) || defined(_AIX32) +#define VOIDYYPUT +#endif +#if !defined(VOIDYYPUT) && defined(POSIX_TYPES) +#if !defined(BOS) && !defined(HISX) && !defined(_M_UNIX) && !defined(VMS) +#define VOIDYYPUT +#endif +#endif +#if !defined(VOIDYYPUT) && defined(WEIRD_LEX) +#if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX > 1) +#define VOIDYYPUT +#endif +#endif +#if defined(VOIDYYPUT) && defined(__osf__) +#undef VOIDYYPUT +#endif +#ifdef VOIDYYPUT void FDECL(yyunput, (int)); void FDECL(yyoutput, (int)); -# else +#else int FDECL(yyunput, (int)); int FDECL(yyoutput, (int)); -# endif -#endif /* !FLEX_SCANNER && !FLEXHACK_SCANNER */ +#endif +#endif /* !FLEX_SCANNER && !FLEXHACK_SCANNER */ #ifdef FLEX_SCANNER -#define YY_MALLOC_DECL \ - genericptr_t FDECL(malloc, (size_t)); \ - genericptr_t FDECL(realloc, (genericptr_t,size_t)); +#define YY_MALLOC_DECL \ + genericptr_t FDECL(malloc, (size_t)); \ + genericptr_t FDECL(realloc, (genericptr_t, size_t)); #endif - void FDECL(init_yyin, (FILE *)); void FDECL(init_yyout, (FILE *)); @@ -483,7 +422,6 @@ extern YYSTYPE yylval; int nh_line_number = 1; - /* Macros after this point can all be overridden by user definitions in * section 1. */ @@ -493,11 +431,11 @@ extern int NDECL(yywrap); #endif #ifndef YY_NO_UNPUT -static void FDECL(yyunput, (int,char *)); +static void FDECL(yyunput, (int, char *)); #endif #ifndef yytext_ptr -static void FDECL(yy_flex_strncpy, (char *,const char *,int)); +static void FDECL(yy_flex_strncpy, (char *, const char *, int)); #endif #ifndef YY_NO_INPUT @@ -515,29 +453,28 @@ static int NDECL(input); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO (void) fwrite(yytext, yyleng, 1, yyout) #endif -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, +/* Gets input and stuffs it into "buf". number of characters read, or + * YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); +#define YY_INPUT(buf, result, max_size) \ + if (yy_current_buffer->yy_is_interactive) { \ + int c = '*', n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; \ + ++n) \ + buf[n] = (char) c; \ + if (c == '\n') \ + buf[n++] = (char) c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } else if (((result = fread(buf, 1, max_size, yyin)) == 0) \ + && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - @@ -555,7 +492,7 @@ static int NDECL(input); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg) #endif /* Code executed at the beginning of each rule, after yytext and yyleng @@ -570,377 +507,402 @@ static int NDECL(input); #define YY_BREAK break; #endif -#define YY_RULE_SETUP \ - if ( yyleng > 0 ) \ - yy_current_buffer->yy_at_bol = \ - (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION +#define YY_RULE_SETUP \ + if (yyleng > 0) \ + yy_current_buffer->yy_at_bol = (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION int NDECL(yylex); -int yylex() - { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; +int +yylex() +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; - - - if ( yy_init ) - { - yy_init = 0; + if (yy_init) { + yy_init = 0; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! yy_start ) - yy_start = 1; /* first start state */ + if (!yy_start) + yy_start = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) + yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) + yyout = stdout; - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); + if (!yy_current_buffer) + yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE); - yy_load_buffer_state(); - } + yy_load_buffer_state(); + } - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = yy_c_buf_p; + while (1) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; - /* Support of yytext. */ - *yy_cp = yy_hold_char; + /* Support of yytext. */ + *yy_cp = yy_hold_char; - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; - yy_current_state = yy_start; - yy_current_state += YY_AT_BOL(); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 196 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 220 ); + yy_current_state = yy_start; + yy_current_state += YY_AT_BOL(); + yy_match: + do { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] + != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 196) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } while (yy_base[yy_current_state] != 220); -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } + yy_find_action: + yy_act = yy_accept[yy_current_state]; + if (yy_act == 0) { /* have to back up */ + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } - YY_DO_BEFORE_ACTION; + YY_DO_BEFORE_ACTION; + do_action: /* This label is used only to access EOF actions. */ -do_action: /* This label is used only to access EOF actions. */ + switch (yy_act) { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + case 1: + YY_RULE_SETUP + return (A_DUNGEON); + YY_BREAK + case 2: + YY_RULE_SETUP + { + yylval.i = 1; + return (UP_OR_DOWN); + } + YY_BREAK + case 3: + YY_RULE_SETUP + { + yylval.i = 0; + return (UP_OR_DOWN); + } + YY_BREAK + case 4: + YY_RULE_SETUP + return (ENTRY); + YY_BREAK + case 5: + YY_RULE_SETUP + return (STAIR); + YY_BREAK + case 6: + YY_RULE_SETUP + return (NO_UP); + YY_BREAK + case 7: + YY_RULE_SETUP + return (NO_DOWN); + YY_BREAK + case 8: + YY_RULE_SETUP + return (PORTAL); + YY_BREAK + case 9: + YY_RULE_SETUP + return (PROTOFILE); + YY_BREAK + case 10: + YY_RULE_SETUP + return (DESCRIPTION); + YY_BREAK + case 11: + YY_RULE_SETUP + return (LEVELDESC); + YY_BREAK + case 12: + YY_RULE_SETUP + return (ALIGNMENT); + YY_BREAK + case 13: + YY_RULE_SETUP + return (LEVALIGN); + YY_BREAK + case 14: + YY_RULE_SETUP + { + yylval.i = TOWN; + return (DESCRIPTOR); + } + YY_BREAK + case 15: + YY_RULE_SETUP + { + yylval.i = HELLISH; + return (DESCRIPTOR); + } + YY_BREAK + case 16: + YY_RULE_SETUP + { + yylval.i = MAZELIKE; + return (DESCRIPTOR); + } + YY_BREAK + case 17: + YY_RULE_SETUP + { + yylval.i = ROGUELIKE; + return (DESCRIPTOR); + } + YY_BREAK + case 18: + YY_RULE_SETUP + { + yylval.i = D_ALIGN_NONE; + return (DESCRIPTOR); + } + YY_BREAK + case 19: + YY_RULE_SETUP + { + yylval.i = D_ALIGN_NONE; + return (DESCRIPTOR); + } + YY_BREAK + case 20: + YY_RULE_SETUP + { + yylval.i = D_ALIGN_LAWFUL; + return (DESCRIPTOR); + } + YY_BREAK + case 21: + YY_RULE_SETUP + { + yylval.i = D_ALIGN_NEUTRAL; + return (DESCRIPTOR); + } + YY_BREAK + case 22: + YY_RULE_SETUP + { + yylval.i = D_ALIGN_CHAOTIC; + return (DESCRIPTOR); + } + YY_BREAK + case 23: + YY_RULE_SETUP + return (BRANCH); + YY_BREAK + case 24: + YY_RULE_SETUP + return (CHBRANCH); + YY_BREAK + case 25: + YY_RULE_SETUP + return (LEVEL); + YY_BREAK + case 26: + YY_RULE_SETUP + return (RNDLEVEL); + YY_BREAK + case 27: + YY_RULE_SETUP + return (CHLEVEL); + YY_BREAK + case 28: + YY_RULE_SETUP + return (RNDCHLEVEL); + YY_BREAK + case 29: + YY_RULE_SETUP + { + yylval.i = atoi(yytext); + return (INTEGER); + } + YY_BREAK + case 30: + YY_RULE_SETUP + { + yytext[yyleng - 1] = 0; /* Discard the trailing \" */ + yylval.str = (char *) alloc(strlen(yytext + 1) + 1); + Strcpy(yylval.str, yytext + 1); /* Discard the first \" */ + return (STRING); + } + YY_BREAK + case 31: + YY_RULE_SETUP + { + nh_line_number++; + } + YY_BREAK + case 32: + YY_RULE_SETUP + { + nh_line_number++; + } + YY_BREAK + case 33: + YY_RULE_SETUP; /* skip trailing tabs & spaces */ + YY_BREAK + case 34: + YY_RULE_SETUP + { + return yytext[0]; + } + YY_BREAK + case 35: + YY_RULE_SETUP + ECHO; + YY_BREAK + case YY_STATE_EOF(INITIAL): + yyterminate(); - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yy_hold_char; - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - goto yy_find_action; + case YY_END_OF_BUFFER: { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; -case 1: -YY_RULE_SETUP -return(A_DUNGEON); - YY_BREAK -case 2: -YY_RULE_SETUP -{ yylval.i=1; return(UP_OR_DOWN); } - YY_BREAK -case 3: -YY_RULE_SETUP -{ yylval.i=0; return(UP_OR_DOWN); } - YY_BREAK -case 4: -YY_RULE_SETUP -return(ENTRY); - YY_BREAK -case 5: -YY_RULE_SETUP -return(STAIR); - YY_BREAK -case 6: -YY_RULE_SETUP -return(NO_UP); - YY_BREAK -case 7: -YY_RULE_SETUP -return(NO_DOWN); - YY_BREAK -case 8: -YY_RULE_SETUP -return(PORTAL); - YY_BREAK -case 9: -YY_RULE_SETUP -return(PROTOFILE); - YY_BREAK -case 10: -YY_RULE_SETUP -return(DESCRIPTION); - YY_BREAK -case 11: -YY_RULE_SETUP -return(LEVELDESC); - YY_BREAK -case 12: -YY_RULE_SETUP -return(ALIGNMENT); - YY_BREAK -case 13: -YY_RULE_SETUP -return(LEVALIGN); - YY_BREAK -case 14: -YY_RULE_SETUP -{ yylval.i=TOWN ; return(DESCRIPTOR); } - YY_BREAK -case 15: -YY_RULE_SETUP -{ yylval.i=HELLISH ; return(DESCRIPTOR); } - YY_BREAK -case 16: -YY_RULE_SETUP -{ yylval.i=MAZELIKE ; return(DESCRIPTOR); } - YY_BREAK -case 17: -YY_RULE_SETUP -{ yylval.i=ROGUELIKE ; return(DESCRIPTOR); } - YY_BREAK -case 18: -YY_RULE_SETUP -{ yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); } - YY_BREAK -case 19: -YY_RULE_SETUP -{ yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); } - YY_BREAK -case 20: -YY_RULE_SETUP -{ yylval.i=D_ALIGN_LAWFUL ; return(DESCRIPTOR); } - YY_BREAK -case 21: -YY_RULE_SETUP -{ yylval.i=D_ALIGN_NEUTRAL ; return(DESCRIPTOR); } - YY_BREAK -case 22: -YY_RULE_SETUP -{ yylval.i=D_ALIGN_CHAOTIC ; return(DESCRIPTOR); } - YY_BREAK -case 23: -YY_RULE_SETUP -return(BRANCH); - YY_BREAK -case 24: -YY_RULE_SETUP -return(CHBRANCH); - YY_BREAK -case 25: -YY_RULE_SETUP -return(LEVEL); - YY_BREAK -case 26: -YY_RULE_SETUP -return(RNDLEVEL); - YY_BREAK -case 27: -YY_RULE_SETUP -return(CHLEVEL); - YY_BREAK -case 28: -YY_RULE_SETUP -return(RNDCHLEVEL); - YY_BREAK -case 29: -YY_RULE_SETUP -{ yylval.i=atoi(yytext); return(INTEGER); } - YY_BREAK -case 30: -YY_RULE_SETUP -{ yytext[yyleng-1] = 0; /* Discard the trailing \" */ - yylval.str = (char *) alloc(strlen(yytext+1)+1); - Strcpy(yylval.str, yytext+1); /* Discard the first \" */ - return(STRING); } - YY_BREAK -case 31: -YY_RULE_SETUP -{ nh_line_number++; } - YY_BREAK -case 32: -YY_RULE_SETUP -{ nh_line_number++; } - YY_BREAK -case 33: -YY_RULE_SETUP -; /* skip trailing tabs & spaces */ - YY_BREAK -case 34: -YY_RULE_SETUP -{ return yytext[0]; } - YY_BREAK -case 35: -YY_RULE_SETUP -ECHO; - YY_BREAK -case YY_STATE_EOF(INITIAL): - yyterminate(); + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + if (yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW) { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if (yy_c_buf_p + <= &yy_current_buffer->yy_ch_buf[yy_n_chars]) { /* This was + really a + NUL. */ + yy_state_type yy_next_state; - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; - } + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; + yy_current_state = yy_get_previous_state(); - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ - yy_current_state = yy_get_previous_state(); + yy_next_state = yy_try_NUL_trans(yy_current_state); - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ + yy_bp = yytext_ptr + YY_MORE_ADJ; - yy_next_state = yy_try_NUL_trans( yy_current_state ); + if (yy_next_state) { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } - yy_bp = yytext_ptr + YY_MORE_ADJ; + else { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } + else + switch (yy_get_next_buffer()) { + case EOB_ACT_END_OF_FILE: { + yy_did_buffer_switch_on_eof = 0; - else - { - yy_cp = yy_c_buf_p; - goto yy_find_action; - } - } + if (yywrap()) { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - else switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - yy_did_buffer_switch_on_eof = 0; + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } - if ( yywrap() ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + else { + if (!yy_did_buffer_switch_on_eof) + YY_NEW_FILE; + } + break; + } - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - else - { - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } + yy_current_state = yy_get_previous_state(); - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; - yy_current_state = yy_get_previous_state(); + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = &yy_current_buffer->yy_ch_buf[yy_n_chars]; - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_match; + yy_current_state = yy_get_previous_state(); - case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of yylex */ + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * @@ -950,165 +912,151 @@ case YY_STATE_EOF(INITIAL): * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer() - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; - register int number_to_move, i; - int ret_val; +static int +yy_get_next_buffer() +{ + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); + if (yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1]) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed"); - if ( yy_current_buffer->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a singled characater, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } + if (yy_current_buffer->yy_fill_buffer + == 0) { /* Don't try to fill the buffer, so this is an EOF. */ + if (yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1) { + /* We matched a singled characater, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } + else { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } - /* Try to read more data. */ + /* Try to read more data. */ - /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); + for (i = 0; i < number_to_move; ++i) + *(dest++) = *(source++); - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - yy_n_chars = 0; + if (yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; - else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; + else { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ + while (num_to_read + <= 0) { /* Not enough room in the buffer - grow it. */ #ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); + YY_FATAL_ERROR("input buffer overflow, can't enlarge buffer " + "because scanner uses REJECT"); #else - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; - int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); + int yy_c_buf_p_offset = (int) (yy_c_buf_p - b->yy_ch_buf); - if ( b->yy_is_our_buffer ) - { - int old_size = b->yy_buf_size + 2; - int new_size = b->yy_buf_size * 2; + if (b->yy_is_our_buffer) { + int old_size = b->yy_buf_size + 2; + int new_size = b->yy_buf_size * 2; - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yy_flex_realloc2( (genericptr_t) b->yy_ch_buf, - b->yy_buf_size + 2, old_size ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc2((genericptr_t) b->yy_ch_buf, + b->yy_buf_size + 2, old_size); + } else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; + num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; #endif - } + } - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; + if (num_to_read > YY_READ_BUF_SIZE) + num_to_read = YY_READ_BUF_SIZE; - /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); - } + /* Read in more data. */ + YY_INPUT((&yy_current_buffer->yy_ch_buf[number_to_move]), yy_n_chars, + num_to_read); + } - if ( yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } + if (yy_n_chars == 0) { + if (number_to_move == YY_MORE_ADJ) { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin); + } - else - { - ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } + else { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } + } - else - ret_val = EOB_ACT_CONTINUE_SCAN; + else + ret_val = EOB_ACT_CONTINUE_SCAN; - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - return ret_val; - } + return ret_val; +} +/* yy_get_previous_state - get the state just before the EOB char was reached + */ -/* yy_get_previous_state - get the state just before the EOB char was reached */ +static yy_state_type +yy_get_previous_state() +{ + register yy_state_type yy_current_state; + register char *yy_cp; -static yy_state_type yy_get_previous_state() - { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_current_state = yy_start; + yy_current_state += YY_AT_BOL(); - yy_current_state = yy_start; - yy_current_state += YY_AT_BOL(); - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 196 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; - } + for (yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp) { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 196) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + return yy_current_state; +} /* yy_try_NUL_trans - try to make a transition on the NUL character * @@ -1116,217 +1064,206 @@ static yy_state_type yy_get_previous_state() * next_state = yy_try_NUL_trans( current_state ); */ -static yy_state_type yy_try_NUL_trans( yy_current_state ) +static yy_state_type +yy_try_NUL_trans(yy_current_state) yy_state_type yy_current_state; - { - register int yy_is_jam; - register char *yy_cp = yy_c_buf_p; +{ + register int yy_is_jam; + register char *yy_cp = yy_c_buf_p; - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 196 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 195); - - return yy_is_jam ? 0 : yy_current_state; - } + register YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 196) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 195); + return yy_is_jam ? 0 : yy_current_state; +} #ifndef YY_NO_UNPUT -static void yyunput( c, yy_bp ) +static void +yyunput(c, yy_bp) int c; register char *yy_bp; - { - register char *yy_cp = yy_c_buf_p; +{ + register char *yy_cp = yy_c_buf_p; - /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; + if (yy_cp < yy_current_buffer->yy_ch_buf + + 2) { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register char *source = &yy_current_buffer->yy_ch_buf[number_to_move]; - while ( source > yy_current_buffer->yy_ch_buf ) - *--dest = *--source; + while (source > yy_current_buffer->yy_ch_buf) + *--dest = *--source; - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - yy_n_chars = yy_current_buffer->yy_buf_size; + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_n_chars = yy_current_buffer->yy_buf_size; - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } + if (yy_cp < yy_current_buffer->yy_ch_buf + 2) + YY_FATAL_ERROR("flex scanner push-back overflow"); + } - *--yy_cp = (char) c; + *--yy_cp = (char) c; + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; +} +#endif /* ifndef YY_NO_UNPUT */ - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -#endif /* ifndef YY_NO_UNPUT */ +static int +input() +{ + int c; + *yy_c_buf_p = yy_hold_char; -static int input() - { - int c; + if (*yy_c_buf_p == YY_END_OF_BUFFER_CHAR) { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if (yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars]) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; - *yy_c_buf_p = yy_hold_char; + else { /* need more input */ + yytext_ptr = yy_c_buf_p; + ++yy_c_buf_p; - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - /* This was really a NUL. */ - *yy_c_buf_p = '\0'; + switch (yy_get_next_buffer()) { + case EOB_ACT_END_OF_FILE: { + if (yywrap()) { + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + return EOF; + } - else - { /* need more input */ - yytext_ptr = yy_c_buf_p; - ++yy_c_buf_p; + if (!yy_did_buffer_switch_on_eof) + YY_NEW_FILE; + return input(); + } - switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - if ( yywrap() ) - { - yy_c_buf_p = - yytext_ptr + YY_MORE_ADJ; - return EOF; - } + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + break; - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - return input(); - } + case EOB_ACT_LAST_MATCH: + YY_FATAL_ERROR("unexpected last match in input()"); + } + } + } - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - break; + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; - case EOB_ACT_LAST_MATCH: - YY_FATAL_ERROR( - "unexpected last match in input()" ); - } - } - } + yy_current_buffer->yy_at_bol = (c == '\n'); - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; + return c; +} - yy_current_buffer->yy_at_bol = (c == '\n'); - - return c; - } - - -void yyrestart( input_file ) +void +yyrestart(input_file) FILE *input_file; - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); +{ + if (!yy_current_buffer) + yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE); - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } + yy_init_buffer(yy_current_buffer, input_file); + yy_load_buffer_state(); +} - -void yy_switch_to_buffer( new_buffer ) +void +yy_switch_to_buffer(new_buffer) YY_BUFFER_STATE new_buffer; - { - if ( yy_current_buffer == new_buffer ) - return; +{ + if (yy_current_buffer == new_buffer) + return; - if ( yy_current_buffer ) - { - /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } + if (yy_current_buffer) { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } - yy_current_buffer = new_buffer; - yy_load_buffer_state(); + yy_current_buffer = new_buffer; + yy_load_buffer_state(); - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yy_did_buffer_switch_on_eof = 1; - } + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; +} +void +yy_load_buffer_state() +{ + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; +} -void yy_load_buffer_state() - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -YY_BUFFER_STATE yy_create_buffer( file, size ) +YY_BUFFER_STATE +yy_create_buffer(file, size) FILE *file; int size; - { - YY_BUFFER_STATE b; +{ + YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state)); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - b->yy_buf_size = size; + b->yy_buf_size = size; - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc(b->yy_buf_size + 2); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - b->yy_is_our_buffer = 1; + b->yy_is_our_buffer = 1; - yy_init_buffer( b, file ); + yy_init_buffer(b, file); - return b; - } + return b; +} - -void yy_delete_buffer( b ) +void +yy_delete_buffer(b) YY_BUFFER_STATE b; - { - if ( ! b ) - return; +{ + if (!b) + return; - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; + if (b == yy_current_buffer) + yy_current_buffer = (YY_BUFFER_STATE) 0; - if ( b->yy_is_our_buffer ) - yy_flex_free( (genericptr_t) b->yy_ch_buf ); - - yy_flex_free( (genericptr_t) b ); - } + if (b->yy_is_our_buffer) + yy_flex_free((genericptr_t) b->yy_ch_buf); + yy_flex_free((genericptr_t) b); +} #ifndef YY_ALWAYS_INTERACTIVE #ifndef YY_NEVER_INTERACTIVE @@ -1334,143 +1271,143 @@ extern int FDECL(isatty, (int)); #endif #endif -void yy_init_buffer( b, file ) +void +yy_init_buffer(b, file) YY_BUFFER_STATE b; FILE *file; - { - yy_flush_buffer( b ); +{ + yy_flush_buffer(b); - b->yy_input_file = file; - b->yy_fill_buffer = 1; + b->yy_input_file = file; + b->yy_fill_buffer = 1; #ifdef YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; + b->yy_is_interactive = 1; #else #ifdef YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; + b->yy_is_interactive = 0; #else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0; #endif #endif - } +} - -void yy_flush_buffer( b ) +void +yy_flush_buffer(b) YY_BUFFER_STATE b; - { - b->yy_n_chars = 0; +{ + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == yy_current_buffer ) - yy_load_buffer_state(); - } + b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + if (b == yy_current_buffer) + yy_load_buffer_state(); +} #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error( msg ) +static void +yy_fatal_error(msg) const char msg[]; - { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); - } - - +{ + (void) fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); +} /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n - YY_MORE_ADJ; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) - +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n - YY_MORE_ADJ; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } while (0) /* Internal utility routines. */ #ifndef yytext_ptr -static void yy_flex_strncpy( s1, s2, n ) +static void +yy_flex_strncpy(s1, s2, n) char *s1; const char *s2; int n; - { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; - } +{ + register int i; + for (i = 0; i < n; ++i) + s1[i] = s2[i]; +} #endif - -static genericptr_t yy_flex_alloc( size ) +static genericptr_t +yy_flex_alloc(size) yy_size_t size; - { - return (genericptr_t) alloc((unsigned)size); - } +{ + return (genericptr_t) alloc((unsigned) size); +} /* we want to avoid use of realloc(), so we require that caller supply the size of the old block of memory */ -static genericptr_t yy_flex_realloc2( ptr, size, old_size ) +static genericptr_t +yy_flex_realloc2(ptr, size, old_size) genericptr_t ptr; yy_size_t size; int old_size; - { - genericptr_t outptr = yy_flex_alloc(size); +{ + genericptr_t outptr = yy_flex_alloc(size); - if (ptr) { - char *p = (char *) outptr, *q = (char *) ptr; + if (ptr) { + char *p = (char *) outptr, *q = (char *) ptr; - while (--old_size >= 0) *p++ = *q++; - yy_flex_free(ptr); - } - return outptr; - } + while (--old_size >= 0) + *p++ = *q++; + yy_flex_free(ptr); + } + return outptr; +} -static void yy_flex_free( ptr ) +static void +yy_flex_free(ptr) genericptr_t ptr; - { - free( ptr ); - } +{ + free(ptr); +} /*flexhack.skl*/ - /* routine to switch to another input file; needed for flex */ -void init_yyin( input_f ) +void +init_yyin(input_f) FILE *input_f; { #if defined(FLEX_SCANNER) || defined(FLEXHACK_SCANNER) - if (yyin) - yyrestart(input_f); - else + if (yyin) + yyrestart(input_f); + else #endif - yyin = input_f; + yyin = input_f; } /* analogous routine (for completeness) */ -void init_yyout( output_f ) +void +init_yyout(output_f) FILE *output_f; { - yyout = output_f; + yyout = output_f; } /*dgn_comp.l*/ diff --git a/sys/share/dgn_yacc.c b/sys/share/dgn_yacc.c index 8ae2ae37d..59e7a6446 100644 --- a/sys/share/dgn_yacc.c +++ b/sys/share/dgn_yacc.c @@ -4,9 +4,9 @@ static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 -#define yyclearin (yychar=(-1)) -#define yyerrok (yyerrflag=0) -#define YYRECOVERING (yyerrflag!=0) +#define yyclearin (yychar = (-1)) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING (yyerrflag != 0) #define YYPREFIX "yy" /* NetHack 3.6 dgn_comp.y $Date: 2009/05/11 22:53:51 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)dgn_comp.c 3.5 1996/06/22 */ @@ -29,7 +29,7 @@ static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; */ #ifdef _AIX - #pragma alloca /* keep leading space! */ +#pragma alloca /* keep leading space! */ #endif #include "config.h" @@ -49,16 +49,16 @@ void NDECL(init_branch); void NDECL(init_level); void NDECL(output_dgn); -#define Free(ptr) free((genericptr_t)ptr) +#define Free(ptr) free((genericptr_t) ptr) #ifdef AMIGA -# undef printf -#ifndef LATTICE -# define memset(addr,val,len) setmem(addr,len,val) +#undef printf +#ifndef LATTICE +#define memset(addr, val, len) setmem(addr, len, val) #endif #endif -#define ERR (-1) +#define ERR (-1) static struct couple couple; static struct tmpdungeon tmpdungeon[MAXDUNGEON]; @@ -69,12 +69,11 @@ static int in_dungeon = 0, n_dgns = -1, n_levs = -1, n_brs = -1; extern int fatal_error; extern const char *fname; -extern FILE *yyin, *yyout; /* from dgn_lex.c */ +extern FILE *yyin, *yyout; /* from dgn_lex.c */ -typedef union -{ - int i; - char* str; +typedef union { + int i; + char *str; } YYSTYPE; #define INTEGER 257 #define A_DUNGEON 258 @@ -98,147 +97,101 @@ typedef union #define PORTAL 276 #define STRING 277 #define YYERRCODE 256 -short yylhs[] = { -1, - 0, 0, 5, 5, 6, 6, 6, 6, 7, 1, - 1, 8, 8, 8, 12, 13, 15, 15, 14, 10, - 10, 10, 10, 10, 16, 16, 17, 17, 18, 18, - 19, 19, 20, 20, 9, 9, 22, 23, 3, 3, - 3, 3, 3, 2, 2, 4, 21, 11, +short yylhs[] = { + -1, 0, 0, 5, 5, 6, 6, 6, 6, 7, 1, 1, 8, 8, 8, 12, 13, + 15, 15, 14, 10, 10, 10, 10, 10, 16, 16, 17, 17, 18, 18, 19, 19, 20, + 20, 9, 9, 22, 23, 3, 3, 3, 3, 3, 2, 2, 4, 21, 11, }; -short yylen[] = { 2, - 0, 1, 1, 2, 1, 1, 1, 1, 6, 0, - 1, 1, 1, 1, 3, 1, 3, 3, 3, 1, - 1, 1, 1, 1, 6, 7, 7, 8, 3, 3, - 7, 8, 8, 9, 1, 1, 7, 8, 0, 1, - 1, 1, 1, 0, 1, 1, 5, 5, +short yylen[] = { + 2, 0, 1, 1, 2, 1, 1, 1, 1, 6, 0, 1, 1, 1, 1, 3, 1, 3, 3, 3, 1, 1, 1, 1, 1, + 6, 7, 7, 8, 3, 3, 7, 8, 8, 9, 1, 1, 7, 8, 0, 1, 1, 1, 1, 0, 1, 1, 5, 5, }; -short yydefred[] = { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 3, 5, 6, 7, 8, - 12, 13, 14, 16, 20, 21, 22, 23, 24, 35, - 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, - 0, 0, 19, 17, 29, 18, 30, 15, 46, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 11, 9, 0, 40, - 41, 42, 43, 0, 0, 0, 0, 0, 0, 0, - 0, 45, 37, 0, 27, 0, 0, 0, 0, 0, - 38, 28, 33, 0, 48, 47, 34, +short yydefred[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, + 6, 7, 8, 12, 13, 14, 16, 20, 21, 22, 23, 24, 35, 36, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 19, + 17, 29, 18, 30, 15, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 11, 9, 0, 40, 41, 42, 43, 0, 0, 0, 0, 0, 0, + 0, 0, 45, 37, 0, 27, 0, 0, 0, 0, 0, 38, 28, 33, 0, 48, 47, 34, }; -short yydgoto[] = { 14, - 78, 93, 84, 60, 15, 16, 17, 18, 19, 20, - 68, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 70, 30, 31, +short yydgoto[] = { + 14, 78, 93, 84, 60, 15, 16, 17, 18, 19, 20, 68, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 70, 30, 31, }; -short yysindex[] = { -237, - -46, -45, -44, -39, -38, -30, -22, -21, -20, -19, - -18, -17, -16, 0, -237, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -262, -234, -233, -232, -230, -229, -228, -227, -217, - -216, -215, -214, -202, 0, -221, -7, -219, -221, -221, - -221, -221, 0, 0, 0, 0, 0, 0, 0, 19, - 20, 21, -2, -1, -212, -211, -190, -189, -188, -271, - 19, 20, 20, 27, 28, 29, 0, 0, 30, 0, - 0, 0, 0, -193, -271, -182, -180, 19, 19, -179, - -178, 0, 0, -193, 0, -177, -176, -175, 42, 43, - 0, 0, 0, -172, 0, 0, 0, +short yysindex[] = { + -237, -46, -45, -44, -39, -38, -30, -22, -21, -20, -19, -18, + -17, -16, 0, -237, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, -262, -234, -233, -232, + -230, -229, -228, -227, -217, -216, -215, -214, -202, 0, -221, -7, + -219, -221, -221, -221, -221, 0, 0, 0, 0, 0, 0, 0, + 19, 20, 21, -2, -1, -212, -211, -190, -189, -188, -271, 19, + 20, 20, 27, 28, 29, 0, 0, 30, 0, 0, 0, 0, + -193, -271, -182, -180, 19, 19, -179, -178, 0, 0, -193, 0, + -177, -176, -175, 42, 43, 0, 0, 0, -172, 0, 0, 0, }; -short yyrindex[] = { 86, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 16, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 31, 1, 46, 0, 0, 0, 0, - 0, 0, 0, 31, 0, 61, 76, 0, 0, 0, - 0, 0, 0, 91, 0, 0, 0, +short yyrindex[] = { + 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 16, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 1, 46, 0, + 0, 0, 0, 0, 0, 0, 31, 0, 61, 76, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, }; -short yygindex[] = { 0, - 0, -6, 4, -43, 0, 75, 0, 0, 0, 0, - -71, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -62, 0, 0, +short yygindex[] = { + 0, 0, -6, 4, -43, 0, 75, 0, 0, 0, 0, -71, + 0, 0, 0, 0, 0, 0, 0, 0, 0, -62, 0, 0, }; #define YYTABLESIZE 363 -short yytable[] = { 85, - 39, 80, 81, 82, 83, 63, 64, 65, 66, 86, - 87, 32, 33, 34, 46, 10, 97, 98, 35, 36, - 1, 2, 3, 4, 5, 6, 7, 37, 8, 9, - 44, 10, 11, 12, 13, 38, 39, 40, 41, 42, - 43, 44, 47, 48, 49, 25, 50, 51, 52, 53, - 54, 55, 56, 57, 58, 59, 61, 62, 67, 69, - 26, 72, 73, 71, 74, 75, 76, 77, 79, 88, - 89, 92, 90, 91, 95, 31, 96, 99, 100, 102, - 103, 104, 105, 106, 107, 1, 2, 101, 94, 45, - 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 0, 39, - 39, 39, 39, 10, 10, 10, 10, 10, 10, 10, - 0, 10, 10, 0, 10, 10, 10, 10, 44, 44, - 44, 44, 44, 44, 44, 0, 44, 44, 0, 44, - 44, 44, 44, 25, 25, 25, 25, 25, 25, 25, - 0, 25, 25, 0, 25, 25, 25, 25, 26, 26, - 26, 26, 26, 26, 26, 0, 26, 26, 0, 26, - 26, 26, 26, 31, 31, 31, 31, 31, 31, 31, - 0, 31, 31, 0, 31, 31, 31, 31, 32, 32, - 32, 32, 32, 32, 32, 0, 32, 32, 0, 32, - 32, 32, 32, +short yytable[] = { + 85, 39, 80, 81, 82, 83, 63, 64, 65, 66, 86, 87, 32, 33, 34, 46, + 10, 97, 98, 35, 36, 1, 2, 3, 4, 5, 6, 7, 37, 8, 9, 44, + 10, 11, 12, 13, 38, 39, 40, 41, 42, 43, 44, 47, 48, 49, 25, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 67, 69, 26, 72, 73, + 71, 74, 75, 76, 77, 79, 88, 89, 92, 90, 91, 95, 31, 96, 99, 100, + 102, 103, 104, 105, 106, 107, 1, 2, 101, 94, 45, 32, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 0, 39, 39, + 39, 39, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 0, 10, 10, 10, + 10, 44, 44, 44, 44, 44, 44, 44, 0, 44, 44, 0, 44, 44, 44, 44, + 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 0, 25, 25, 25, 25, 26, + 26, 26, 26, 26, 26, 26, 0, 26, 26, 0, 26, 26, 26, 26, 31, 31, + 31, 31, 31, 31, 31, 0, 31, 31, 0, 31, 31, 31, 31, 32, 32, 32, + 32, 32, 32, 32, 0, 32, 32, 0, 32, 32, 32, 32, }; -short yycheck[] = { 71, - 0, 273, 274, 275, 276, 49, 50, 51, 52, 72, - 73, 58, 58, 58, 277, 0, 88, 89, 58, 58, - 258, 259, 260, 261, 262, 263, 264, 58, 266, 267, - 0, 269, 270, 271, 272, 58, 58, 58, 58, 58, - 58, 58, 277, 277, 277, 0, 277, 277, 277, 277, - 268, 268, 268, 268, 257, 277, 64, 277, 40, 40, - 0, 64, 64, 43, 277, 277, 257, 257, 257, 43, - 43, 265, 44, 44, 257, 0, 257, 257, 257, 257, - 257, 257, 41, 41, 257, 0, 0, 94, 85, 15, - 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, -1, 269, - 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, - -1, 266, 267, -1, 269, 270, 271, 272, 258, 259, - 260, 261, 262, 263, 264, -1, 266, 267, -1, 269, - 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, - -1, 266, 267, -1, 269, 270, 271, 272, 258, 259, - 260, 261, 262, 263, 264, -1, 266, 267, -1, 269, - 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, - -1, 266, 267, -1, 269, 270, 271, 272, 258, 259, - 260, 261, 262, 263, 264, -1, 266, 267, -1, 269, - 270, 271, 272, +short yycheck[] = { + 71, 0, 273, 274, 275, 276, 49, 50, 51, 52, 72, 73, 58, 58, 58, + 277, 0, 88, 89, 58, 58, 258, 259, 260, 261, 262, 263, 264, 58, 266, + 267, 0, 269, 270, 271, 272, 58, 58, 58, 58, 58, 58, 58, 277, 277, + 277, 0, 277, 277, 277, 277, 268, 268, 268, 268, 257, 277, 64, 277, 40, + 40, 0, 64, 64, 43, 277, 277, 257, 257, 257, 43, 43, 265, 44, 44, + 257, 0, 257, 257, 257, 257, 257, 257, 41, 41, 257, 0, 0, 94, 85, + 15, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, 258, 259, 260, 261, 262, 263, 264, -1, 266, 267, -1, + 269, 270, 271, 272, }; #define YYFINAL 14 #ifndef YYDEBUG @@ -247,67 +200,51 @@ short yycheck[] = { 71, #define YYMAXTOKEN 277 #if YYDEBUG char *yyname[] = { -"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,"'('","')'",0,"'+'","','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0, -"'@'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"INTEGER", -"A_DUNGEON","BRANCH","CHBRANCH","LEVEL","RNDLEVEL","CHLEVEL","RNDCHLEVEL", -"UP_OR_DOWN","PROTOFILE","DESCRIPTION","DESCRIPTOR","LEVELDESC","ALIGNMENT", -"LEVALIGN","ENTRY","STAIR","NO_UP","NO_DOWN","PORTAL","STRING", + "end-of-file", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "'('", "')'", 0, + "'+'", "','", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "':'", 0, 0, 0, 0, 0, + "'@'", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "INTEGER", + "A_DUNGEON", "BRANCH", "CHBRANCH", "LEVEL", "RNDLEVEL", "CHLEVEL", + "RNDCHLEVEL", "UP_OR_DOWN", "PROTOFILE", "DESCRIPTION", "DESCRIPTOR", + "LEVELDESC", "ALIGNMENT", "LEVALIGN", "ENTRY", "STAIR", "NO_UP", + "NO_DOWN", "PORTAL", "STRING", }; char *yyrule[] = { -"$accept : file", -"file :", -"file : dungeons", -"dungeons : dungeon", -"dungeons : dungeons dungeon", -"dungeon : dungeonline", -"dungeon : dungeondesc", -"dungeon : branches", -"dungeon : levels", -"dungeonline : A_DUNGEON ':' STRING bones_tag rcouple optional_int", -"optional_int :", -"optional_int : INTEGER", -"dungeondesc : entry", -"dungeondesc : descriptions", -"dungeondesc : prototype", -"entry : ENTRY ':' INTEGER", -"descriptions : desc", -"desc : DESCRIPTION ':' DESCRIPTOR", -"desc : ALIGNMENT ':' DESCRIPTOR", -"prototype : PROTOFILE ':' STRING", -"levels : level1", -"levels : level2", -"levels : levdesc", -"levels : chlevel1", -"levels : chlevel2", -"level1 : LEVEL ':' STRING bones_tag '@' acouple", -"level1 : RNDLEVEL ':' STRING bones_tag '@' acouple INTEGER", -"level2 : LEVEL ':' STRING bones_tag '@' acouple INTEGER", -"level2 : RNDLEVEL ':' STRING bones_tag '@' acouple INTEGER INTEGER", -"levdesc : LEVELDESC ':' DESCRIPTOR", -"levdesc : LEVALIGN ':' DESCRIPTOR", -"chlevel1 : CHLEVEL ':' STRING bones_tag STRING '+' rcouple", -"chlevel1 : RNDCHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER", -"chlevel2 : CHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER", -"chlevel2 : RNDCHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER INTEGER", -"branches : branch", -"branches : chbranch", -"branch : BRANCH ':' STRING '@' acouple branch_type direction", -"chbranch : CHBRANCH ':' STRING STRING '+' rcouple branch_type direction", -"branch_type :", -"branch_type : STAIR", -"branch_type : NO_UP", -"branch_type : NO_DOWN", -"branch_type : PORTAL", -"direction :", -"direction : UP_OR_DOWN", -"bones_tag : STRING", -"acouple : '(' INTEGER ',' INTEGER ')'", -"rcouple : '(' INTEGER ',' INTEGER ')'", + "$accept : file", "file :", "file : dungeons", "dungeons : dungeon", + "dungeons : dungeons dungeon", "dungeon : dungeonline", + "dungeon : dungeondesc", "dungeon : branches", "dungeon : levels", + "dungeonline : A_DUNGEON ':' STRING bones_tag rcouple optional_int", + "optional_int :", "optional_int : INTEGER", "dungeondesc : entry", + "dungeondesc : descriptions", "dungeondesc : prototype", + "entry : ENTRY ':' INTEGER", "descriptions : desc", + "desc : DESCRIPTION ':' DESCRIPTOR", "desc : ALIGNMENT ':' DESCRIPTOR", + "prototype : PROTOFILE ':' STRING", "levels : level1", "levels : level2", + "levels : levdesc", "levels : chlevel1", "levels : chlevel2", + "level1 : LEVEL ':' STRING bones_tag '@' acouple", + "level1 : RNDLEVEL ':' STRING bones_tag '@' acouple INTEGER", + "level2 : LEVEL ':' STRING bones_tag '@' acouple INTEGER", + "level2 : RNDLEVEL ':' STRING bones_tag '@' acouple INTEGER INTEGER", + "levdesc : LEVELDESC ':' DESCRIPTOR", "levdesc : LEVALIGN ':' DESCRIPTOR", + "chlevel1 : CHLEVEL ':' STRING bones_tag STRING '+' rcouple", + "chlevel1 : RNDCHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER", + "chlevel2 : CHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER", + "chlevel2 : RNDCHLEVEL ':' STRING bones_tag STRING '+' rcouple INTEGER " + "INTEGER", + "branches : branch", "branches : chbranch", + "branch : BRANCH ':' STRING '@' acouple branch_type direction", + "chbranch : CHBRANCH ':' STRING STRING '+' rcouple branch_type direction", + "branch_type :", "branch_type : STAIR", "branch_type : NO_UP", + "branch_type : NO_DOWN", "branch_type : PORTAL", "direction :", + "direction : UP_OR_DOWN", "bones_tag : STRING", + "acouple : '(' INTEGER ',' INTEGER ')'", + "rcouple : '(' INTEGER ',' INTEGER ')'", }; #endif #ifdef YYSTACKSIZE @@ -336,71 +273,70 @@ YYSTYPE yyvs[YYSTACKSIZE]; void init_dungeon() { - if(++n_dgns > MAXDUNGEON) { - (void) fprintf(stderr, "FATAL - Too many dungeons (limit: %d).\n", - MAXDUNGEON); - (void) fprintf(stderr, "To increase the limit edit MAXDUNGEON in global.h\n"); - exit(EXIT_FAILURE); - } + if (++n_dgns > MAXDUNGEON) { + (void) fprintf(stderr, "FATAL - Too many dungeons (limit: %d).\n", + MAXDUNGEON); + (void) fprintf(stderr, + "To increase the limit edit MAXDUNGEON in global.h\n"); + exit(EXIT_FAILURE); + } - in_dungeon = 1; - tmpdungeon[n_dgns].lev.base = 0; - tmpdungeon[n_dgns].lev.rand = 0; - tmpdungeon[n_dgns].chance = 100; - Strcpy(tmpdungeon[n_dgns].name, ""); - Strcpy(tmpdungeon[n_dgns].protoname, ""); - tmpdungeon[n_dgns].flags = 0; - tmpdungeon[n_dgns].levels = 0; - tmpdungeon[n_dgns].branches = 0; - tmpdungeon[n_dgns].entry_lev = 0; + in_dungeon = 1; + tmpdungeon[n_dgns].lev.base = 0; + tmpdungeon[n_dgns].lev.rand = 0; + tmpdungeon[n_dgns].chance = 100; + Strcpy(tmpdungeon[n_dgns].name, ""); + Strcpy(tmpdungeon[n_dgns].protoname, ""); + tmpdungeon[n_dgns].flags = 0; + tmpdungeon[n_dgns].levels = 0; + tmpdungeon[n_dgns].branches = 0; + tmpdungeon[n_dgns].entry_lev = 0; } void init_level() { - if(++n_levs > LEV_LIMIT) { - - yyerror("FATAL - Too many special levels defined."); - exit(EXIT_FAILURE); - } - tmplevel[n_levs].lev.base = 0; - tmplevel[n_levs].lev.rand = 0; - tmplevel[n_levs].chance = 100; - tmplevel[n_levs].rndlevs = 0; - tmplevel[n_levs].flags = 0; - Strcpy(tmplevel[n_levs].name, ""); - tmplevel[n_levs].chain = -1; + if (++n_levs > LEV_LIMIT) { + yyerror("FATAL - Too many special levels defined."); + exit(EXIT_FAILURE); + } + tmplevel[n_levs].lev.base = 0; + tmplevel[n_levs].lev.rand = 0; + tmplevel[n_levs].chance = 100; + tmplevel[n_levs].rndlevs = 0; + tmplevel[n_levs].flags = 0; + Strcpy(tmplevel[n_levs].name, ""); + tmplevel[n_levs].chain = -1; } void init_branch() { - if(++n_brs > BRANCH_LIMIT) { - - yyerror("FATAL - Too many special levels defined."); - exit(EXIT_FAILURE); - } - tmpbranch[n_brs].lev.base = 0; - tmpbranch[n_brs].lev.rand = 0; - Strcpy(tmpbranch[n_brs].name, ""); - tmpbranch[n_brs].chain = -1; + if (++n_brs > BRANCH_LIMIT) { + yyerror("FATAL - Too many special levels defined."); + exit(EXIT_FAILURE); + } + tmpbranch[n_brs].lev.base = 0; + tmpbranch[n_brs].lev.rand = 0; + Strcpy(tmpbranch[n_brs].name, ""); + tmpbranch[n_brs].chain = -1; } int getchain(s) - char *s; +char *s; { - int i; + int i; - if(strlen(s)) { + if (strlen(s)) { + for (i = n_levs - tmpdungeon[n_dgns].levels + 1; i <= n_levs; i++) + if (!strcmp(tmplevel[i].name, s)) + return i; - for(i = n_levs - tmpdungeon[n_dgns].levels + 1; i <= n_levs; i++) - if(!strcmp(tmplevel[i].name, s)) return i; - - yyerror("Can't locate the specified chain level."); - return(-2); - } - return(-1); + yyerror("Can't locate the specified chain level."); + return (-2); + } + return (-1); } /* @@ -415,30 +351,30 @@ getchain(s) int check_dungeon() { - int i; + int i; - for(i = 0; i < n_dgns; i++) - if(!strcmp(tmpdungeon[i].name, tmpdungeon[n_dgns].name)) { - yyerror("Duplicate dungeon name."); - return(0); - } + for (i = 0; i < n_dgns; i++) + if (!strcmp(tmpdungeon[i].name, tmpdungeon[n_dgns].name)) { + yyerror("Duplicate dungeon name."); + return (0); + } - if(n_dgns) - for(i = 0; i < n_brs - tmpdungeon[n_dgns].branches; i++) { - if(!strcmp(tmpbranch[i].name, tmpdungeon[n_dgns].name)) break; + if (n_dgns) + for (i = 0; i < n_brs - tmpdungeon[n_dgns].branches; i++) { + if (!strcmp(tmpbranch[i].name, tmpdungeon[n_dgns].name)) + break; - if(i >= n_brs - tmpdungeon[n_dgns].branches) { - yyerror("Dungeon cannot be reached."); - return(0); - } - } + if (i >= n_brs - tmpdungeon[n_dgns].branches) { + yyerror("Dungeon cannot be reached."); + return (0); + } + } - if(tmpdungeon[n_dgns].lev.base <= 0 || - tmpdungeon[n_dgns].lev.rand < 0) { - yyerror("Invalid dungeon depth specified."); - return(0); - } - return(1); /* OK */ + if (tmpdungeon[n_dgns].lev.base <= 0 || tmpdungeon[n_dgns].lev.rand < 0) { + yyerror("Invalid dungeon depth specified."); + return (0); + } + return (1); /* OK */ } /* @@ -452,33 +388,33 @@ check_dungeon() int check_level() { - int i; + int i; - if(!in_dungeon) { - yyerror("Level defined outside of dungeon."); - return(0); - } + if (!in_dungeon) { + yyerror("Level defined outside of dungeon."); + return (0); + } - for(i = 0; i < n_levs; i++) - if(!strcmp(tmplevel[i].name, tmplevel[n_levs].name)) { - yyerror("Duplicate level name."); - return(0); - } + for (i = 0; i < n_levs; i++) + if (!strcmp(tmplevel[i].name, tmplevel[n_levs].name)) { + yyerror("Duplicate level name."); + return (0); + } - if(tmplevel[i].chain == -2) { - yyerror("Invaild level chain reference."); - return(0); - } else if(tmplevel[i].chain != -1) { /* there is a chain */ - /* KMH -- tmplevel[tmpbranch[i].chain].chance was in error */ - if(tmplevel[tmplevel[i].chain].chance != 100) { - yyerror("Level cannot chain from a probabilistic level."); - return(0); - } else if(tmplevel[i].chain == n_levs) { - yyerror("A level cannot chain to itself!"); - return(0); - } - } - return(1); /* OK */ + if (tmplevel[i].chain == -2) { + yyerror("Invaild level chain reference."); + return (0); + } else if (tmplevel[i].chain != -1) { /* there is a chain */ + /* KMH -- tmplevel[tmpbranch[i].chain].chance was in error */ + if (tmplevel[tmplevel[i].chain].chance != 100) { + yyerror("Level cannot chain from a probabilistic level."); + return (0); + } else if (tmplevel[i].chain == n_levs) { + yyerror("A level cannot chain to itself!"); + return (0); + } + } + return (1); /* OK */ } /* @@ -494,32 +430,30 @@ check_level() int check_branch() { - int i; + int i; - if(!in_dungeon) { - yyerror("Branch defined outside of dungeon."); - return(0); - } + if (!in_dungeon) { + yyerror("Branch defined outside of dungeon."); + return (0); + } - for(i = 0; i < n_dgns; i++) - if(!strcmp(tmpdungeon[i].name, tmpbranch[n_brs].name)) { + for (i = 0; i < n_dgns; i++) + if (!strcmp(tmpdungeon[i].name, tmpbranch[n_brs].name)) { + yyerror("Reverse branching not allowed."); + return (0); + } - yyerror("Reverse branching not allowed."); - return(0); - } + if (tmpbranch[i].chain == -2) { + yyerror("Invaild branch chain reference."); + return (0); + } else if (tmpbranch[i].chain != -1) { /* it is chained */ - if(tmpbranch[i].chain == -2) { - - yyerror("Invaild branch chain reference."); - return(0); - } else if(tmpbranch[i].chain != -1) { /* it is chained */ - - if(tmplevel[tmpbranch[i].chain].chance != 100) { - yyerror("Branch cannot chain from a probabilistic level."); - return(0); - } - } - return(1); /* OK */ + if (tmplevel[tmpbranch[i].chain].chance != 100) { + yyerror("Branch cannot chain from a probabilistic level."); + return (0); + } + } + return (1); /* OK */ } /* @@ -541,40 +475,39 @@ check_branch() void output_dgn() { - int nd, cl = 0, nl = 0, - cb = 0, nb = 0; - static struct version_info version_data = { - VERSION_NUMBER, VERSION_FEATURES, - VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3 - }; + int nd, cl = 0, nl = 0, cb = 0, nb = 0; + static struct version_info version_data = { + VERSION_NUMBER, VERSION_FEATURES, VERSION_SANITY1, VERSION_SANITY2, + VERSION_SANITY3 + }; - if(++n_dgns <= 0) { - yyerror("FATAL - no dungeons were defined."); - exit(EXIT_FAILURE); - } + if (++n_dgns <= 0) { + yyerror("FATAL - no dungeons were defined."); + exit(EXIT_FAILURE); + } - if (fwrite((char *)&version_data, sizeof version_data, 1, yyout) != 1) { - yyerror("FATAL - output failure."); - exit(EXIT_FAILURE); - } + if (fwrite((char *) &version_data, sizeof version_data, 1, yyout) != 1) { + yyerror("FATAL - output failure."); + exit(EXIT_FAILURE); + } - (void) fwrite((char *)&n_dgns, sizeof(int), 1, yyout); - for (nd = 0; nd < n_dgns; nd++) { - (void) fwrite((char *)&tmpdungeon[nd], sizeof(struct tmpdungeon), - 1, yyout); + (void) fwrite((char *) &n_dgns, sizeof(int), 1, yyout); + for (nd = 0; nd < n_dgns; nd++) { + (void) fwrite((char *) &tmpdungeon[nd], sizeof(struct tmpdungeon), 1, + yyout); - nl += tmpdungeon[nd].levels; - for(; cl < nl; cl++) - (void) fwrite((char *)&tmplevel[cl], sizeof(struct tmplevel), - 1, yyout); + nl += tmpdungeon[nd].levels; + for (; cl < nl; cl++) + (void) fwrite((char *) &tmplevel[cl], sizeof(struct tmplevel), 1, + yyout); - nb += tmpdungeon[nd].branches; - for(; cb < nb; cb++) - (void) fwrite((char *)&tmpbranch[cb], sizeof(struct tmpbranch), - 1, yyout); - } - /* apparently necessary for Think C 5.x, otherwise harmless */ - (void) fflush(yyout); + nb += tmpdungeon[nd].branches; + for (; cb < nb; cb++) + (void) fwrite((char *) &tmpbranch[cb], sizeof(struct tmpbranch), + 1, yyout); + } + /* apparently necessary for Think C 5.x, otherwise harmless */ + (void) fflush(yyout); } /*dgn_comp.y*/ @@ -590,8 +523,7 @@ yyparse() register char *yys; extern char *getenv(); - if ((yys = getenv("YYDEBUG")) != 0) - { + if ((yys = getenv("YYDEBUG")) != 0) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; @@ -607,46 +539,47 @@ yyparse() *yyssp = yystate = 0; yyloop: - if ((yyn = yydefred[yystate]) != 0) goto yyreduce; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; + if ((yyn = yydefred[yystate]) != 0) + goto yyreduce; + if (yychar < 0) { + if ((yychar = yylex()) < 0) + yychar = 0; #if YYDEBUG - if (yydebug) - { + if (yydebug) { yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, yystate, yychar, yys); + if (yychar <= YYMAXTOKEN) + yys = yyname[yychar]; + if (!yys) + yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, + yychar, yys); } #endif } - if ((yyn = yysindex[yystate]) != 0 && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { + if ((yyn = yysindex[yystate]) != 0 && (yyn += yychar) >= 0 + && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { #if YYDEBUG if (yydebug) - printf("%sdebug: state %d, shifting to state %d\n", - YYPREFIX, yystate, yytable[yyn]); + printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, + yystate, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) - { + if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); - if (yyerrflag > 0) --yyerrflag; + if (yyerrflag > 0) + --yyerrflag; goto yyloop; } - if ((yyn = yyrindex[yystate]) != 0 && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { + if ((yyn = yyrindex[yystate]) != 0 && (yyn += yychar) >= 0 + && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } - if (yyerrflag) goto yyinrecovery; + if (yyerrflag) + goto yyinrecovery; #ifdef lint goto yynewerror; #endif @@ -658,51 +591,48 @@ yynewerror: yyerrlab: ++yynerrs; yyinrecovery: - if (yyerrflag < 3) - { + if (yyerrflag < 3) { yyerrflag = 3; - for (;;) - { - if ((yyn = yysindex[*yyssp]) != 0 && (yyn += YYERRCODE) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) - { + for (;;) { + if ((yyn = yysindex[*yyssp]) != 0 && (yyn += YYERRCODE) >= 0 + && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); + to state %d\n", + YYPREFIX, *yyssp, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) - { + if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; - } - else - { + } else { #if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); + YYPREFIX, *yyssp); #endif - if (yyssp <= yyss) goto yyabort; + if (yyssp <= yyss) + goto yyabort; --yyssp; --yyvsp; } } - } - else - { - if (yychar == 0) goto yyabort; + } else { + if (yychar == 0) + goto yyabort; #if YYDEBUG - if (yydebug) - { + if (yydebug) { yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, error recovery discards token %d (%s)\n", - YYPREFIX, yystate, yychar, yys); + if (yychar <= YYMAXTOKEN) + yys = yyname[yychar]; + if (!yys) + yys = "illegal-symbol"; + printf( + "%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); } #endif yychar = (-1); @@ -711,336 +641,291 @@ yyinrecovery: yyreduce: #if YYDEBUG if (yydebug) - printf("%sdebug: state %d, reducing by rule %d (%s)\n", - YYPREFIX, yystate, yyn, yyrule[yyn]); + printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, + yystate, yyn, yyrule[yyn]); #endif yym = yylen[yyn]; - yyval = yyvsp[1-yym]; - switch (yyn) - { -case 2: -{ - output_dgn(); - } -break; -case 9: -{ - init_dungeon(); - Strcpy(tmpdungeon[n_dgns].name, yyvsp[-3].str); - tmpdungeon[n_dgns].boneschar = (char)yyvsp[-2].i; - tmpdungeon[n_dgns].lev.base = couple.base; - tmpdungeon[n_dgns].lev.rand = couple.rand; - tmpdungeon[n_dgns].chance = yyvsp[0].i; - Free(yyvsp[-3].str); - } -break; -case 10: -{ - yyval.i = 0; - } -break; -case 11: -{ - yyval.i = yyvsp[0].i; - } -break; -case 15: -{ - tmpdungeon[n_dgns].entry_lev = yyvsp[0].i; - } -break; -case 17: -{ - if(yyvsp[0].i <= TOWN || yyvsp[0].i >= D_ALIGN_CHAOTIC) - yyerror("Illegal description - ignoring!"); - else - tmpdungeon[n_dgns].flags |= yyvsp[0].i ; - } -break; -case 18: -{ - if(yyvsp[0].i && yyvsp[0].i < D_ALIGN_CHAOTIC) - yyerror("Illegal alignment - ignoring!"); - else - tmpdungeon[n_dgns].flags |= yyvsp[0].i ; - } -break; -case 19: -{ - Strcpy(tmpdungeon[n_dgns].protoname, yyvsp[0].str); - Free(yyvsp[0].str); - } -break; -case 25: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-3].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-2].i; - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmpdungeon[n_dgns].levels++; - Free(yyvsp[-3].str); - } -break; -case 26: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-3].i; - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].rndlevs = yyvsp[0].i; - tmpdungeon[n_dgns].levels++; - Free(yyvsp[-4].str); - } -break; -case 27: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-3].i; - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].chance = yyvsp[0].i; - tmpdungeon[n_dgns].levels++; - Free(yyvsp[-4].str); - } -break; -case 28: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-4].i; - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].chance = yyvsp[-1].i; - tmplevel[n_levs].rndlevs = yyvsp[0].i; - tmpdungeon[n_dgns].levels++; - Free(yyvsp[-5].str); - } -break; -case 29: -{ - if(yyvsp[0].i >= D_ALIGN_CHAOTIC) - yyerror("Illegal description - ignoring!"); - else - tmplevel[n_levs].flags |= yyvsp[0].i ; - } -break; -case 30: -{ - if(yyvsp[0].i && yyvsp[0].i < D_ALIGN_CHAOTIC) - yyerror("Illegal alignment - ignoring!"); - else - tmplevel[n_levs].flags |= yyvsp[0].i ; - } -break; -case 31: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-3].i; - tmplevel[n_levs].chain = getchain(yyvsp[-2].str); - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - if(!check_level()) n_levs--; - else tmpdungeon[n_dgns].levels++; - Free(yyvsp[-4].str); - Free(yyvsp[-2].str); - } -break; -case 32: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-4].i; - tmplevel[n_levs].chain = getchain(yyvsp[-3].str); - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].rndlevs = yyvsp[0].i; - if(!check_level()) n_levs--; - else tmpdungeon[n_dgns].levels++; - Free(yyvsp[-5].str); - Free(yyvsp[-3].str); - } -break; -case 33: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-4].i; - tmplevel[n_levs].chain = getchain(yyvsp[-3].str); - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].chance = yyvsp[0].i; - if(!check_level()) n_levs--; - else tmpdungeon[n_dgns].levels++; - Free(yyvsp[-5].str); - Free(yyvsp[-3].str); - } -break; -case 34: -{ - init_level(); - Strcpy(tmplevel[n_levs].name, yyvsp[-6].str); - tmplevel[n_levs].boneschar = (char)yyvsp[-5].i; - tmplevel[n_levs].chain = getchain(yyvsp[-4].str); - tmplevel[n_levs].lev.base = couple.base; - tmplevel[n_levs].lev.rand = couple.rand; - tmplevel[n_levs].chance = yyvsp[-1].i; - tmplevel[n_levs].rndlevs = yyvsp[0].i; - if(!check_level()) n_levs--; - else tmpdungeon[n_dgns].levels++; - Free(yyvsp[-6].str); - Free(yyvsp[-4].str); - } -break; -case 37: -{ - init_branch(); - Strcpy(tmpbranch[n_brs].name, yyvsp[-4].str); - tmpbranch[n_brs].lev.base = couple.base; - tmpbranch[n_brs].lev.rand = couple.rand; - tmpbranch[n_brs].type = yyvsp[-1].i; - tmpbranch[n_brs].up = yyvsp[0].i; - if(!check_branch()) n_brs--; - else tmpdungeon[n_dgns].branches++; - Free(yyvsp[-4].str); - } -break; -case 38: -{ - init_branch(); - Strcpy(tmpbranch[n_brs].name, yyvsp[-5].str); - tmpbranch[n_brs].chain = getchain(yyvsp[-4].str); - tmpbranch[n_brs].lev.base = couple.base; - tmpbranch[n_brs].lev.rand = couple.rand; - tmpbranch[n_brs].type = yyvsp[-1].i; - tmpbranch[n_brs].up = yyvsp[0].i; - if(!check_branch()) n_brs--; - else tmpdungeon[n_dgns].branches++; - Free(yyvsp[-5].str); - Free(yyvsp[-4].str); - } -break; -case 39: -{ - yyval.i = TBR_STAIR; /* two way stair */ - } -break; -case 40: -{ - yyval.i = TBR_STAIR; /* two way stair */ - } -break; -case 41: -{ - yyval.i = TBR_NO_UP; /* no up staircase */ - } -break; -case 42: -{ - yyval.i = TBR_NO_DOWN; /* no down staircase */ - } -break; -case 43: -{ - yyval.i = TBR_PORTAL; /* portal connection */ - } -break; -case 44: -{ - yyval.i = 0; /* defaults to down */ - } -break; -case 45: -{ - yyval.i = yyvsp[0].i; - } -break; -case 46: -{ - char *p = yyvsp[0].str; - if (strlen(p) != 1) { - if (strcmp(p, "none") != 0) - yyerror("Bones marker must be a single char, or \"none\"!"); - *p = '\0'; - } - yyval.i = *p; - Free(p); - } -break; -case 47: -{ - if (yyvsp[-3].i < -MAXLEVEL || yyvsp[-3].i > MAXLEVEL) { - yyerror("Abs base out of dlevel range - zeroing!"); - couple.base = couple.rand = 0; - } else if (yyvsp[-1].i < -1 || - ((yyvsp[-3].i < 0) ? (MAXLEVEL + yyvsp[-3].i + yyvsp[-1].i + 1) > MAXLEVEL : - (yyvsp[-3].i + yyvsp[-1].i) > MAXLEVEL)) { - yyerror("Abs range out of dlevel range - zeroing!"); - couple.base = couple.rand = 0; - } else { - couple.base = yyvsp[-3].i; - couple.rand = yyvsp[-1].i; - } - } -break; -case 48: -{ - if (yyvsp[-3].i < -MAXLEVEL || yyvsp[-3].i > MAXLEVEL) { - yyerror("Rel base out of dlevel range - zeroing!"); - couple.base = couple.rand = 0; - } else { - couple.base = yyvsp[-3].i; - couple.rand = yyvsp[-1].i; - } - } -break; + yyval = yyvsp[1 - yym]; + switch (yyn) { + case 2: { + output_dgn(); + } break; + case 9: { + init_dungeon(); + Strcpy(tmpdungeon[n_dgns].name, yyvsp[-3].str); + tmpdungeon[n_dgns].boneschar = (char) yyvsp[-2].i; + tmpdungeon[n_dgns].lev.base = couple.base; + tmpdungeon[n_dgns].lev.rand = couple.rand; + tmpdungeon[n_dgns].chance = yyvsp[0].i; + Free(yyvsp[-3].str); + } break; + case 10: { + yyval.i = 0; + } break; + case 11: { + yyval.i = yyvsp[0].i; + } break; + case 15: { + tmpdungeon[n_dgns].entry_lev = yyvsp[0].i; + } break; + case 17: { + if (yyvsp[0].i <= TOWN || yyvsp[0].i >= D_ALIGN_CHAOTIC) + yyerror("Illegal description - ignoring!"); + else + tmpdungeon[n_dgns].flags |= yyvsp[0].i; + } break; + case 18: { + if (yyvsp[0].i && yyvsp[0].i < D_ALIGN_CHAOTIC) + yyerror("Illegal alignment - ignoring!"); + else + tmpdungeon[n_dgns].flags |= yyvsp[0].i; + } break; + case 19: { + Strcpy(tmpdungeon[n_dgns].protoname, yyvsp[0].str); + Free(yyvsp[0].str); + } break; + case 25: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-3].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-2].i; + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-3].str); + } break; + case 26: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-3].i; + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].rndlevs = yyvsp[0].i; + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-4].str); + } break; + case 27: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-3].i; + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].chance = yyvsp[0].i; + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-4].str); + } break; + case 28: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-4].i; + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].chance = yyvsp[-1].i; + tmplevel[n_levs].rndlevs = yyvsp[0].i; + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-5].str); + } break; + case 29: { + if (yyvsp[0].i >= D_ALIGN_CHAOTIC) + yyerror("Illegal description - ignoring!"); + else + tmplevel[n_levs].flags |= yyvsp[0].i; + } break; + case 30: { + if (yyvsp[0].i && yyvsp[0].i < D_ALIGN_CHAOTIC) + yyerror("Illegal alignment - ignoring!"); + else + tmplevel[n_levs].flags |= yyvsp[0].i; + } break; + case 31: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-4].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-3].i; + tmplevel[n_levs].chain = getchain(yyvsp[-2].str); + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + if (!check_level()) + n_levs--; + else + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-4].str); + Free(yyvsp[-2].str); + } break; + case 32: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-4].i; + tmplevel[n_levs].chain = getchain(yyvsp[-3].str); + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].rndlevs = yyvsp[0].i; + if (!check_level()) + n_levs--; + else + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-5].str); + Free(yyvsp[-3].str); + } break; + case 33: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-5].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-4].i; + tmplevel[n_levs].chain = getchain(yyvsp[-3].str); + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].chance = yyvsp[0].i; + if (!check_level()) + n_levs--; + else + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-5].str); + Free(yyvsp[-3].str); + } break; + case 34: { + init_level(); + Strcpy(tmplevel[n_levs].name, yyvsp[-6].str); + tmplevel[n_levs].boneschar = (char) yyvsp[-5].i; + tmplevel[n_levs].chain = getchain(yyvsp[-4].str); + tmplevel[n_levs].lev.base = couple.base; + tmplevel[n_levs].lev.rand = couple.rand; + tmplevel[n_levs].chance = yyvsp[-1].i; + tmplevel[n_levs].rndlevs = yyvsp[0].i; + if (!check_level()) + n_levs--; + else + tmpdungeon[n_dgns].levels++; + Free(yyvsp[-6].str); + Free(yyvsp[-4].str); + } break; + case 37: { + init_branch(); + Strcpy(tmpbranch[n_brs].name, yyvsp[-4].str); + tmpbranch[n_brs].lev.base = couple.base; + tmpbranch[n_brs].lev.rand = couple.rand; + tmpbranch[n_brs].type = yyvsp[-1].i; + tmpbranch[n_brs].up = yyvsp[0].i; + if (!check_branch()) + n_brs--; + else + tmpdungeon[n_dgns].branches++; + Free(yyvsp[-4].str); + } break; + case 38: { + init_branch(); + Strcpy(tmpbranch[n_brs].name, yyvsp[-5].str); + tmpbranch[n_brs].chain = getchain(yyvsp[-4].str); + tmpbranch[n_brs].lev.base = couple.base; + tmpbranch[n_brs].lev.rand = couple.rand; + tmpbranch[n_brs].type = yyvsp[-1].i; + tmpbranch[n_brs].up = yyvsp[0].i; + if (!check_branch()) + n_brs--; + else + tmpdungeon[n_dgns].branches++; + Free(yyvsp[-5].str); + Free(yyvsp[-4].str); + } break; + case 39: { + yyval.i = TBR_STAIR; /* two way stair */ + } break; + case 40: { + yyval.i = TBR_STAIR; /* two way stair */ + } break; + case 41: { + yyval.i = TBR_NO_UP; /* no up staircase */ + } break; + case 42: { + yyval.i = TBR_NO_DOWN; /* no down staircase */ + } break; + case 43: { + yyval.i = TBR_PORTAL; /* portal connection */ + } break; + case 44: { + yyval.i = 0; /* defaults to down */ + } break; + case 45: { + yyval.i = yyvsp[0].i; + } break; + case 46: { + char *p = yyvsp[0].str; + if (strlen(p) != 1) { + if (strcmp(p, "none") != 0) + yyerror("Bones marker must be a single char, or \"none\"!"); + *p = '\0'; + } + yyval.i = *p; + Free(p); + } break; + case 47: { + if (yyvsp[-3].i < -MAXLEVEL || yyvsp[-3].i > MAXLEVEL) { + yyerror("Abs base out of dlevel range - zeroing!"); + couple.base = couple.rand = 0; + } else if (yyvsp[-1].i < -1 + || ((yyvsp[-3].i < 0) + ? (MAXLEVEL + yyvsp[-3].i + yyvsp[-1].i + 1) + > MAXLEVEL + : (yyvsp[-3].i + yyvsp[-1].i) > MAXLEVEL)) { + yyerror("Abs range out of dlevel range - zeroing!"); + couple.base = couple.rand = 0; + } else { + couple.base = yyvsp[-3].i; + couple.rand = yyvsp[-1].i; + } + } break; + case 48: { + if (yyvsp[-3].i < -MAXLEVEL || yyvsp[-3].i > MAXLEVEL) { + yyerror("Rel base out of dlevel range - zeroing!"); + couple.base = couple.rand = 0; + } else { + couple.base = yyvsp[-3].i; + couple.rand = yyvsp[-1].i; + } + } break; } yyssp -= yym; yystate = *yyssp; yyvsp -= yym; yym = yylhs[yyn]; - if (yystate == 0 && yym == 0) - { + if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state 0 to\ - state %d\n", YYPREFIX, YYFINAL); + state %d\n", + YYPREFIX, YYFINAL); #endif yystate = YYFINAL; *++yyssp = YYFINAL; *++yyvsp = yyval; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; + if (yychar < 0) { + if ((yychar = yylex()) < 0) + yychar = 0; #if YYDEBUG - if (yydebug) - { + if (yydebug) { yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, YYFINAL, yychar, yys); + if (yychar <= YYMAXTOKEN) + yys = yyname[yychar]; + if (!yys) + yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, + YYFINAL, yychar, yys); } #endif } - if (yychar == 0) goto yyaccept; + if (yychar == 0) + goto yyaccept; goto yyloop; } - if ((yyn = yygindex[yym]) != 0 && (yyn += yystate) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + if ((yyn = yygindex[yym]) != 0 && (yyn += yystate) >= 0 + && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); +to state %d\n", + YYPREFIX, *yyssp, yystate); #endif - if (yyssp >= yyss + yystacksize - 1) - { + if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate; diff --git a/sys/share/ioctl.c b/sys/share/ioctl.c index 8c0961212..8d1f044c0 100644 --- a/sys/share/ioctl.c +++ b/sys/share/ioctl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 ioctl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 ioctl.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 ioctl.c $Date: 2011/06/16 15:10:14 $ $Revision: 1.8 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,63 +10,65 @@ #include "hack.h" #if defined(BSD_JOB_CONTROL) || defined(_BULL_SOURCE) -# ifdef HPUX +#ifdef HPUX #include -# else -# if defined(AIX_31) && !defined(_ALL_SOURCE) -# define _ALL_SOURCE /* causes struct winsize to be present */ -# ifdef _AIX32 -# include -# endif -# endif -# if defined(_BULL_SOURCE) -# include +#else +#if defined(AIX_31) && !defined(_ALL_SOURCE) +#define _ALL_SOURCE /* causes struct winsize to be present */ +#ifdef _AIX32 +#include +#endif +#endif +#if defined(_BULL_SOURCE) +#include struct termios termio; -# undef TIMEOUT /* defined in you.h and sys/tty.h */ -# include /* define winsize */ -# include /* define struct ltchars */ -# include /* define TIOGWINSZ */ -# else -# ifdef LINUX -# include -# else -# include -# endif -# endif -# endif +#undef TIMEOUT /* defined in you.h and sys/tty.h */ +#include /* define winsize */ +#include /* define struct ltchars */ +#include /* define TIOGWINSZ */ +#else +#ifdef LINUX +#include +#else +#include +#endif +#endif +#endif struct ltchars ltchars; struct ltchars ltchars0 = { -1, -1, -1, -1, -1, -1 }; /* turn all off */ #else -# ifdef POSIX_TYPES +#ifdef POSIX_TYPES #include struct termios termio; -# if defined(BSD) || defined(_AIX32) || defined(__linux__) -# if defined(_AIX32) && !defined(_ALL_SOURCE) -# define _ALL_SOURCE -# endif +#if defined(BSD) || defined(_AIX32) || defined(__linux__) +#if defined(_AIX32) && !defined(_ALL_SOURCE) +#define _ALL_SOURCE +#endif #include -# endif -# else -#include /* also includes part of */ -# if defined(TCSETS) && !defined(AIX_31) +#endif +#else +#include /* also includes part of */ +#if defined(TCSETS) && !defined(AIX_31) struct termios termio; -# else +#else struct termio termio; -# endif -# endif -# if defined(AMIX) || defined(__APPLE__) +#endif +#endif +#if defined(AMIX) || defined(__APPLE__) #include -# endif /* AMIX */ +#endif /* AMIX */ #endif -#ifdef SUSPEND /* BSD isn't alone anymore... */ -#include +#ifdef SUSPEND /* BSD isn't alone anymore... */ +#include #endif -#if defined(TIOCGWINSZ) && (defined(BSD) || defined(ULTRIX) || defined(AIX_31) || defined(_BULL_SOURCE) || defined(SVR4)) +#if defined(TIOCGWINSZ) \ + && (defined(BSD) || defined(ULTRIX) || defined(AIX_31) \ + || defined(_BULL_SOURCE) || defined(SVR4)) #define USE_WIN_IOCTL -#include "tcap.h" /* for LI and CO */ +#include "tcap.h" /* for LI and CO */ #endif #ifdef _M_UNIX @@ -97,15 +99,15 @@ getwindowsz() */ struct winsize ttsz; - if (ioctl(fileno(stdin), (int)TIOCGWINSZ, (char *)&ttsz) != -1) { - /* - * Use the kernel's values for lines and columns if it has - * any idea. - */ - if (ttsz.ws_row) - LI = ttsz.ws_row; - if (ttsz.ws_col) - CO = ttsz.ws_col; + if (ioctl(fileno(stdin), (int) TIOCGWINSZ, (char *) &ttsz) != -1) { + /* + * Use the kernel's values for lines and columns if it has + * any idea. + */ + if (ttsz.ws_row) + LI = ttsz.ws_row; + if (ttsz.ws_col) + CO = ttsz.ws_col; } #endif } @@ -114,22 +116,22 @@ void getioctls() { #ifdef BSD_JOB_CONTROL - (void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars); - (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0); + (void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars); + (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0); #else -# ifdef POSIX_TYPES - (void) tcgetattr(fileno(stdin), &termio); -# else -# if defined(TCSETS) && !defined(AIX_31) - (void) ioctl(fileno(stdin), (int) TCGETS, &termio); -# else - (void) ioctl(fileno(stdin), (int) TCGETA, &termio); -# endif -# endif +#ifdef POSIX_TYPES + (void) tcgetattr(fileno(stdin), &termio); +#else +#if defined(TCSETS) && !defined(AIX_31) + (void) ioctl(fileno(stdin), (int) TCGETS, &termio); +#else + (void) ioctl(fileno(stdin), (int) TCGETA, &termio); #endif - getwindowsz(); +#endif +#endif + getwindowsz(); #ifdef AUX - ( void ) signal ( SIGTSTP , catch_stp ) ; + (void) signal(SIGTSTP, catch_stp); #endif } @@ -137,62 +139,60 @@ void setioctls() { #ifdef BSD_JOB_CONTROL - (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars); + (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars); #else -# ifdef POSIX_TYPES - (void) tcsetattr(fileno(stdin), TCSADRAIN, &termio); -# else -# if defined(TCSETS) && !defined(AIX_31) - (void) ioctl(fileno(stdin), (int) TCSETSW, &termio); -# else - (void) ioctl(fileno(stdin), (int) TCSETAW, &termio); -# endif -# endif +#ifdef POSIX_TYPES + (void) tcsetattr(fileno(stdin), TCSADRAIN, &termio); +#else +#if defined(TCSETS) && !defined(AIX_31) + (void) ioctl(fileno(stdin), (int) TCSETSW, &termio); +#else + (void) ioctl(fileno(stdin), (int) TCSETAW, &termio); +#endif +#endif #endif } -#ifdef SUSPEND /* No longer implies BSD */ +#ifdef SUSPEND /* No longer implies BSD */ int dosuspend() { #ifdef SYSCF - /* NB: check_user_string() is port-specific. */ - if( !sysopt.shellers - || !sysopt.shellers[0] - || !check_user_string(sysopt.shellers) - ){ - Norep("Suspend command not available."); - return 0; - } + /* NB: check_user_string() is port-specific. */ + if (!sysopt.shellers || !sysopt.shellers[0] + || !check_user_string(sysopt.shellers)) { + Norep("Suspend command not available."); + return 0; + } #endif -# if defined(SIGTSTP) && !defined(NO_SIGNAL) - if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) { - suspend_nhwindows((char *)0); -# ifdef _M_UNIX - sco_mapon(); -# endif -# ifdef __linux__ - linux_mapon(); -# endif - (void) signal(SIGTSTP, SIG_DFL); -# ifdef AUX - ( void ) kill ( 0 , SIGSTOP ) ; -# else - (void) kill(0, SIGTSTP); -# endif -# ifdef _M_UNIX - sco_mapoff(); -# endif -# ifdef __linux__ - linux_mapoff(); -# endif - resume_nhwindows(); - } else { - pline("I don't think your shell has job control."); - } -# else - pline("Sorry, it seems we have no SIGTSTP here. Try ! or S."); -# endif - return(0); +#if defined(SIGTSTP) && !defined(NO_SIGNAL) + if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { + suspend_nhwindows((char *) 0); +#ifdef _M_UNIX + sco_mapon(); +#endif +#ifdef __linux__ + linux_mapon(); +#endif + (void) signal(SIGTSTP, SIG_DFL); +#ifdef AUX + (void) kill(0, SIGSTOP); +#else + (void) kill(0, SIGTSTP); +#endif +#ifdef _M_UNIX + sco_mapoff(); +#endif +#ifdef __linux__ + linux_mapoff(); +#endif + resume_nhwindows(); + } else { + pline("I don't think your shell has job control."); + } +#else + pline("Sorry, it seems we have no SIGTSTP here. Try ! or S."); +#endif + return (0); } #endif /* SUSPEND */ diff --git a/sys/share/lev_lex.c b/sys/share/lev_lex.c index bb0a82909..347d65968 100644 --- a/sys/share/lev_lex.c +++ b/sys/share/lev_lex.c @@ -1,7 +1,7 @@ #line 3 "lex.yy.c" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ @@ -30,10 +30,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -50,37 +50,37 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #endif /* ! C99 */ @@ -92,15 +92,15 @@ typedef unsigned int flex_uint32_t; /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST -#else /* ! __cplusplus */ +#else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) +#if defined(__STDC__) #define YY_USE_CONST -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const @@ -128,14 +128,14 @@ typedef unsigned int flex_uint32_t; * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START (((yy_start) -1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) +#define YY_NEW_FILE yyrestart(yyin) #define YY_END_OF_BUFFER_CHAR 0 @@ -152,9 +152,10 @@ typedef unsigned int flex_uint32_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the + * main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -174,94 +175,91 @@ extern FILE *yyin, *yyout; #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) +#define YY_LESS_LINENO(n) +#define YY_LINENO_REWIND_TO(ptr) -#define unput(c) yyunput( c, (yytext_ptr) ) +/* Return all but the first "n" matched characters back to the input stream. + */ +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET(yy_c_buf_p) = yy_cp = \ + yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) + +#define unput(c) yyunput(c, (yytext_ptr)) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; +struct yy_buffer_state { + FILE *yy_input_file; - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - yy_size_t yy_n_chars; + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - int yy_buffer_status; + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ +/* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - - }; +}; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE *yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general @@ -269,73 +267,71 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) +#define YY_CURRENT_BUFFER \ + ((yy_buffer_stack) ? (yy_buffer_stack)[(yy_buffer_stack_top)] : NULL) -/* Same as previous macro, but useful when we know that the buffer stack is not +/* Same as previous macro, but useful when we know that the buffer stack is + * not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ yy_size_t yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); +void yyrestart(FILE *input_file); +void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer); +YY_BUFFER_STATE yy_create_buffer(FILE *file, int size); +void yy_delete_buffer(YY_BUFFER_STATE b); +void yy_flush_buffer(YY_BUFFER_STATE b); +void yypush_buffer_state(YY_BUFFER_STATE new_buffer); +void yypop_buffer_state(void); -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); +static void yyensure_buffer_stack(void); +static void yy_load_buffer_state(void); +static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file); -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER) -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); +YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size); +YY_BUFFER_STATE yy_scan_string(yyconst char *yy_str); +YY_BUFFER_STATE yy_scan_bytes(yyconst char *bytes, yy_size_t len); -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); +void *yyalloc(yy_size_t); +void *yyrealloc(void *, yy_size_t); +void yyfree(void *); #define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!YY_CURRENT_BUFFER) { \ + yyensure_buffer_stack(); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_bol(at_bol) \ + { \ + if (!YY_CURRENT_BUFFER) { \ + yyensure_buffer_stack(); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) @@ -354,725 +350,623 @@ int yylineno = 1; extern char *yytext; #define yytext_ptr yytext -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); +static yy_state_type yy_get_previous_state(void); +static yy_state_type yy_try_NUL_trans(yy_state_type current_state); +static int yy_get_next_buffer(void); +static void yy_fatal_error(yyconst char msg[]); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t)(yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 198 #define YY_END_OF_BUFFER 199 /* This struct is not used in this scanner, but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[1038] = - { 0, - 0, 0, 0, 0, 199, 197, 193, 192, 197, 197, - 197, 197, 197, 197, 196, 182, 190, 197, 191, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 197, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 193, 197, 196, 2, 197, 193, 197, 197, 196, 182, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 193, 197, 193, 192, 186, 0, 183, 184, - 0, 0, 180, 196, 179, 181, 182, 196, 188, 187, +struct yy_trans_info { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; +}; +static yyconst flex_int16_t yy_accept[1038] = { + 0, 0, 0, 0, 0, 199, 197, 193, 192, 197, 197, 197, 197, 197, 197, + 196, 182, 190, 197, 191, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 197, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 193, 197, 196, 2, 197, 193, 197, 197, 196, 182, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 193, 197, 193, 192, 186, 0, 183, + 184, 0, 0, 180, 196, 179, 181, 182, 196, 188, 187, - 185, 189, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 39, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 55, 196, 196, 0, 0, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 185, 189, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 39, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 55, 196, 196, 0, 0, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 153, 196, 196, 193, 0, 0, 3, 196, - 2, 2, 0, 193, 0, 180, 196, 179, 182, 196, - 196, 196, 196, 39, 196, 196, 196, 196, 196, 196, - 193, 0, 2, 0, 0, 195, 0, 195, 177, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 54, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 0, 196, 103, 196, 83, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 153, 196, 196, + 193, 0, 0, 3, 196, 2, 2, 0, 193, 0, 180, 196, 179, 182, 196, + 196, 196, 196, 39, 196, 196, 196, 196, 196, 196, 193, 0, 2, 0, 0, + 195, 0, 195, 177, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 54, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 0, 196, 103, 196, 83, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 79, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 81, - 196, 196, 196, 196, 138, 196, 196, 196, 196, 127, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 16, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 125, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 79, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 81, 196, 196, 196, 196, 138, + 196, 196, 196, 196, 127, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 16, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 125, 196, 196, 196, 196, 196, 196, 196, 196, - 80, 196, 196, 196, 196, 196, 196, 196, 196, 194, - 196, 196, 196, 58, 196, 196, 196, 22, 196, 40, - 196, 41, 196, 196, 196, 196, 49, 196, 196, 196, - 196, 56, 6, 196, 196, 196, 53, 196, 196, 196, - 36, 196, 196, 196, 196, 42, 196, 35, 196, 196, - 196, 196, 196, 21, 196, 0, 178, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 159, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 154, 157, 113, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 69, 196, 196, 196, 196, + 80, 196, 196, 196, 196, 196, 196, 196, 196, 194, 196, 196, 196, 58, 196, + 196, 196, 22, 196, 40, 196, 41, 196, 196, 196, 196, 49, 196, 196, 196, + 196, 56, 6, 196, 196, 196, 53, 196, 196, 196, 36, 196, 196, 196, 196, + 42, 196, 35, 196, 196, 196, 196, 196, 21, 196, 0, 178, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 159, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 154, 157, 113, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 69, 196, 196, 196, 196, - 196, 196, 196, 196, 120, 196, 196, 67, 196, 196, - 196, 196, 160, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 118, 196, 196, 196, 106, 196, 196, 196, - 196, 196, 196, 196, 65, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 156, 196, 196, 196, 196, 196, 115, - 15, 0, 196, 196, 196, 196, 196, 28, 196, 59, - 196, 196, 196, 196, 196, 13, 196, 196, 196, 50, - 196, 196, 7, 196, 196, 196, 196, 5, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 30, 196, 196, + 196, 196, 196, 196, 120, 196, 196, 67, 196, 196, 196, 196, 160, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 118, 196, 196, 196, 106, 196, 196, 196, + 196, 196, 196, 196, 65, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 156, 196, 196, 196, 196, 196, 115, + 15, 0, 196, 196, 196, 196, 196, 28, 196, 59, 196, 196, 196, 196, 196, + 13, 196, 196, 196, 50, 196, 196, 7, 196, 196, 196, 196, 5, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 30, 196, 196, - 196, 196, 196, 119, 152, 196, 196, 196, 146, 196, - 196, 161, 196, 196, 196, 196, 196, 140, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 155, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 11, 196, 196, 196, 196, 196, - 196, 196, 112, 196, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 124, 196, 12, 196, 196, - 196, 196, 196, 196, 196, 82, 114, 196, 196, 196, - 196, 196, 196, 196, 196, 128, 196, 196, 196, 196, + 196, 196, 196, 119, 152, 196, 196, 196, 146, 196, 196, 161, 196, 196, 196, + 196, 196, 140, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 155, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 11, 196, 196, 196, 196, 196, + 196, 196, 112, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + 124, 196, 12, 196, 196, 196, 196, 196, 196, 196, 82, 114, 196, 196, 196, + 196, 196, 196, 196, 196, 128, 196, 196, 196, 196, - 33, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 29, 196, 196, 196, 196, 196, 196, 17, 31, 196, - 27, 196, 196, 196, 196, 57, 196, 196, 196, 196, - 145, 96, 196, 196, 126, 110, 86, 196, 122, 72, - 107, 196, 196, 196, 196, 164, 196, 196, 87, 196, - 93, 129, 196, 74, 196, 196, 196, 196, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 134, 196, 196, - 108, 196, 196, 196, 196, 196, 196, 196, 196, 196, - 109, 167, 196, 196, 16, 196, 196, 196, 196, 77, - 196, 116, 196, 196, 196, 196, 196, 111, 196, 196, + 33, 196, 196, 196, 196, 196, 196, 196, 196, 196, 29, 196, 196, 196, 196, + 196, 196, 17, 31, 196, 27, 196, 196, 196, 196, 57, 196, 196, 196, 196, + 145, 96, 196, 196, 126, 110, 86, 196, 122, 72, 107, 196, 196, 196, 196, + 164, 196, 196, 87, 196, 93, 129, 196, 74, 196, 196, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 134, 196, 196, 108, 196, 196, 196, 196, + 196, 196, 196, 196, 196, 109, 167, 196, 196, 16, 196, 196, 196, 196, 77, + 196, 116, 196, 196, 196, 196, 196, 111, 196, 196, - 196, 151, 172, 196, 196, 78, 196, 196, 196, 196, - 196, 196, 196, 196, 1, 57, 196, 196, 196, 60, - 196, 196, 196, 196, 196, 196, 196, 4, 196, 19, - 196, 196, 196, 196, 196, 62, 43, 196, 46, 26, - 196, 162, 98, 196, 196, 196, 196, 196, 73, 158, - 196, 196, 97, 196, 196, 196, 92, 196, 196, 196, - 196, 144, 196, 196, 196, 196, 135, 196, 196, 196, - 196, 196, 20, 63, 139, 137, 196, 196, 196, 196, - 196, 196, 196, 117, 196, 131, 95, 196, 150, 196, - 196, 196, 196, 196, 100, 47, 89, 196, 196, 196, + 196, 151, 172, 196, 196, 78, 196, 196, 196, 196, 196, 196, 196, 196, 1, + 57, 196, 196, 196, 60, 196, 196, 196, 196, 196, 196, 196, 4, 196, 19, + 196, 196, 196, 196, 196, 62, 43, 196, 46, 26, 196, 162, 98, 196, 196, + 196, 196, 196, 73, 158, 196, 196, 97, 196, 196, 196, 92, 196, 196, 196, + 196, 144, 196, 196, 196, 196, 135, 196, 196, 196, 196, 196, 20, 63, 139, + 137, 196, 196, 196, 196, 196, 196, 196, 117, 196, 131, 95, 196, 150, 196, + 196, 196, 196, 196, 100, 47, 89, 196, 196, 196, - 196, 196, 196, 45, 196, 196, 34, 61, 14, 8, - 25, 196, 196, 196, 196, 196, 23, 196, 168, 196, - 196, 196, 101, 176, 196, 66, 196, 75, 196, 196, - 196, 196, 196, 196, 196, 196, 196, 196, 196, 149, - 9, 196, 196, 196, 196, 143, 196, 85, 68, 196, - 71, 196, 196, 196, 196, 175, 163, 130, 133, 196, - 105, 18, 196, 51, 196, 196, 196, 196, 196, 196, - 94, 141, 196, 196, 70, 173, 121, 196, 166, 196, - 174, 91, 132, 84, 147, 148, 170, 196, 196, 99, - 171, 90, 196, 64, 196, 10, 136, 24, 52, 196, + 196, 196, 196, 45, 196, 196, 34, 61, 14, 8, 25, 196, 196, 196, 196, + 196, 23, 196, 168, 196, 196, 196, 101, 176, 196, 66, 196, 75, 196, 196, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 149, 9, 196, 196, 196, 196, + 143, 196, 85, 68, 196, 71, 196, 196, 196, 196, 175, 163, 130, 133, 196, + 105, 18, 196, 51, 196, 196, 196, 196, 196, 196, 94, 141, 196, 196, 70, + 173, 121, 196, 166, 196, 174, 91, 132, 84, 147, 148, 170, 196, 196, 99, + 171, 90, 196, 64, 196, 10, 136, 24, 52, 196, - 196, 196, 196, 196, 76, 88, 123, 104, 196, 165, - 102, 196, 196, 196, 196, 196, 196, 196, 196, 37, - 38, 196, 196, 196, 142, 169, 196, 196, 196, 196, - 196, 196, 196, 48, 32, 44, 0 - } ; + 196, 196, 196, 196, 76, 88, 123, 104, 196, 165, 102, 196, 196, 196, 196, + 196, 196, 196, 196, 37, 38, 196, 196, 196, 142, 169, 196, 196, 196, 196, + 196, 196, 196, 48, 32, 44, 0 +}; -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 5, 6, 7, 8, 9, 10, 1, 11, 1, - 1, 1, 12, 1, 13, 14, 1, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 1, 1, 16, - 17, 18, 1, 1, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 1, 48, 1, 49, 50, 51, 52, +static yyconst flex_int32_t yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 1, 11, 1, 1, 1, 12, 1, 13, 14, 1, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 1, 1, 16, 17, 18, 1, 1, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 1, 48, 1, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 14, 14, 14, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 14, 14, 14, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 +}; -static yyconst flex_int32_t yy_meta[75] = - { 0, - 1, 2, 3, 2, 2, 1, 1, 2, 1, 1, - 1, 2, 4, 2, 4, 1, 1, 1, 5, 5, - 5, 6, 6, 5, 6, 5, 5, 6, 5, 5, - 6, 6, 6, 5, 6, 6, 5, 5, 6, 6, - 5, 6, 6, 6, 1, 2, 1, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 5, 6, 6 - } ; +static yyconst flex_int32_t + yy_meta[75] = { 0, 1, 2, 3, 2, 2, 1, 1, 2, 1, 1, 1, 2, 4, 2, 4, 1, 1, 1, + 5, 5, 5, 6, 6, 5, 6, 5, 5, 6, 5, 5, 6, 6, 6, 5, 6, 6, 5, + 5, 6, 6, 5, 6, 6, 6, 1, 2, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6 }; -static yyconst flex_int16_t yy_base[1045] = - { 0, - 0, 73, 102, 77, 1235, 1236, 75, 1236, 1231, 1216, - 1225, 0, 1185, 1215, 1214, 78, 66, 1211, 1210, 1196, - 1189, 57, 63, 59, 64, 101, 0, 63, 79, 119, - 94, 1204, 1190, 122, 123, 121, 1203, 104, 105, 100, - 124, 90, 129, 137, 1155, 84, 117, 1157, 139, 150, - 151, 151, 156, 1150, 163, 168, 166, 56, 1165, 1164, - 232, 1213, 216, 1236, 1212, 242, 248, 251, 264, 196, - 155, 167, 208, 228, 241, 1199, 249, 242, 195, 277, - 284, 223, 319, 334, 257, 1236, 1236, 1206, 1236, 0, - 1201, 1200, 1195, 0, 1194, 1236, 298, 1193, 1236, 1236, +static yyconst flex_int16_t yy_base[1045] = { + 0, 0, 73, 102, 77, 1235, 1236, 75, 1236, 1231, 1216, 1225, + 0, 1185, 1215, 1214, 78, 66, 1211, 1210, 1196, 1189, 57, 63, + 59, 64, 101, 0, 63, 79, 119, 94, 1204, 1190, 122, 123, + 121, 1203, 104, 105, 100, 124, 90, 129, 137, 1155, 84, 117, + 1157, 139, 150, 151, 151, 156, 1150, 163, 168, 166, 56, 1165, + 1164, 232, 1213, 216, 1236, 1212, 242, 248, 251, 264, 196, 155, + 167, 208, 228, 241, 1199, 249, 242, 195, 277, 284, 223, 319, + 334, 257, 1236, 1236, 1206, 1236, 0, 1201, 1200, 1195, 0, 1194, + 1236, 298, 1193, 1236, 1236, - 1236, 1236, 1169, 263, 1169, 264, 1181, 1171, 1184, 1165, - 1176, 1173, 1180, 270, 1166, 1164, 1166, 1176, 0, 1167, - 1171, 1152, 1158, 1146, 1152, 1156, 1155, 1155, 280, 1157, - 292, 1152, 301, 1150, 1143, 1149, 1161, 1159, 1151, 259, - 0, 1158, 1146, 203, 304, 272, 1102, 1124, 1113, 1119, - 1122, 288, 1102, 1106, 1102, 1105, 1104, 1116, 1098, 1100, - 308, 1096, 1090, 1087, 1092, 1091, 1097, 1101, 1092, 1094, - 1092, 1092, 234, 281, 296, 299, 1098, 1080, 1083, 1091, - 1076, 81, 315, 1095, 324, 26, 1083, 1082, 1082, 1073, - 330, 1083, 1087, 1073, 1089, 1084, 1087, 281, 333, 1080, + 1236, 1236, 1169, 263, 1169, 264, 1181, 1171, 1184, 1165, 1176, 1173, + 1180, 270, 1166, 1164, 1166, 1176, 0, 1167, 1171, 1152, 1158, 1146, + 1152, 1156, 1155, 1155, 280, 1157, 292, 1152, 301, 1150, 1143, 1149, + 1161, 1159, 1151, 259, 0, 1158, 1146, 203, 304, 272, 1102, 1124, + 1113, 1119, 1122, 288, 1102, 1106, 1102, 1105, 1104, 1116, 1098, 1100, + 308, 1096, 1090, 1087, 1092, 1091, 1097, 1101, 1092, 1094, 1092, 1092, + 234, 281, 296, 299, 1098, 1080, 1083, 1091, 1076, 81, 315, 1095, + 324, 26, 1083, 1082, 1082, 1073, 330, 1083, 1087, 1073, 1089, 1084, + 1087, 281, 333, 1080, - 1082, 1078, 1070, 342, 323, 321, 1062, 1061, 1063, 1064, - 345, 350, 0, 1061, 332, 407, 1123, 1122, 1236, 363, - 1236, 1236, 1121, 411, 415, 416, 1108, 0, 412, 390, - 396, 404, 415, 1107, 337, 410, 420, 417, 423, 424, - 0, 0, 1236, 1118, 0, 1236, 1109, 1108, 1103, 1098, - 1084, 1096, 1091, 1075, 1076, 1092, 1074, 1068, 1085, 1071, - 1068, 1080, 0, 1072, 1082, 1071, 1079, 1060, 1061, 1076, - 1074, 1062, 1072, 1057, 1070, 1055, 1068, 1071, 1041, 1065, - 1057, 1048, 1063, 1057, 1053, 1051, 1057, 1051, 1052, 1042, - 1039, 1053, 1039, 1040, 1043, 326, 1017, 0, 1022, 0, + 1082, 1078, 1070, 342, 323, 321, 1062, 1061, 1063, 1064, 345, 350, + 0, 1061, 332, 407, 1123, 1122, 1236, 363, 1236, 1236, 1121, 411, + 415, 416, 1108, 0, 412, 390, 396, 404, 415, 1107, 337, 410, + 420, 417, 423, 424, 0, 0, 1236, 1118, 0, 1236, 1109, 1108, + 1103, 1098, 1084, 1096, 1091, 1075, 1076, 1092, 1074, 1068, 1085, 1071, + 1068, 1080, 0, 1072, 1082, 1071, 1079, 1060, 1061, 1076, 1074, 1062, + 1072, 1057, 1070, 1055, 1068, 1071, 1041, 1065, 1057, 1048, 1063, 1057, + 1053, 1051, 1057, 1051, 1052, 1042, 1039, 1053, 1039, 1040, 1043, 326, + 1017, 0, 1022, 0, - 1007, 1016, 1006, 1008, 999, 1003, 1001, 995, 1003, 380, - 1010, 992, 996, 1007, 990, 996, 991, 1000, 987, 985, - 989, 0, 982, 981, 991, 981, 994, 978, 995, 380, - 990, 979, 389, 992, 969, 985, 986, 980, 968, 0, - 983, 977, 980, 970, 0, 963, 964, 972, 975, 0, - 968, 973, 962, 974, 964, 969, 968, 376, 967, 951, - 958, 954, 955, 394, 947, 961, 960, 950, 962, 959, - 948, 946, 950, 954, 390, 936, 947, 947, 951, 932, - 949, 933, 936, 944, 930, 394, 938, 926, 944, 930, - 925, 0, 926, 936, 919, 930, 923, 928, 916, 915, + 1007, 1016, 1006, 1008, 999, 1003, 1001, 995, 1003, 380, 1010, 992, + 996, 1007, 990, 996, 991, 1000, 987, 985, 989, 0, 982, 981, + 991, 981, 994, 978, 995, 380, 990, 979, 389, 992, 969, 985, + 986, 980, 968, 0, 983, 977, 980, 970, 0, 963, 964, 972, + 975, 0, 968, 973, 962, 974, 964, 969, 968, 376, 967, 951, + 958, 954, 955, 394, 947, 961, 960, 950, 962, 959, 948, 946, + 950, 954, 390, 936, 947, 947, 951, 932, 949, 933, 936, 944, + 930, 394, 938, 926, 944, 930, 925, 0, 926, 936, 919, 930, + 923, 928, 916, 915, - 0, 452, 446, 445, 951, 438, 447, 451, 452, 1236, - 945, 959, 950, 0, 959, 950, 937, 0, 955, 0, - 955, 0, 936, 934, 933, 947, 0, 946, 920, 944, - 936, 0, 924, 945, 927, 924, 0, 927, 447, 939, - 0, 940, 925, 924, 937, 933, 930, 0, 917, 919, - 930, 916, 930, 0, 921, 465, 1236, 885, 880, 879, - 891, 888, 889, 874, 888, 887, 875, 884, 883, 0, - 882, 881, 866, 872, 878, 873, 869, 859, 866, 873, - 0, 0, 0, 861, 875, 870, 869, 861, 418, 867, - 862, 866, 860, 863, 848, 0, 901, 859, 838, 854, + 0, 452, 446, 445, 951, 438, 447, 451, 452, 1236, 945, 959, + 950, 0, 959, 950, 937, 0, 955, 0, 955, 0, 936, 934, + 933, 947, 0, 946, 920, 944, 936, 0, 924, 945, 927, 924, + 0, 927, 447, 939, 0, 940, 925, 924, 937, 933, 930, 0, + 917, 919, 930, 916, 930, 0, 921, 465, 1236, 885, 880, 879, + 891, 888, 889, 874, 888, 887, 875, 884, 883, 0, 882, 881, + 866, 872, 878, 873, 869, 859, 866, 873, 0, 0, 0, 861, + 875, 870, 869, 861, 418, 867, 862, 866, 860, 863, 848, 0, + 901, 859, 838, 854, - 846, 842, 853, 854, 0, 853, 837, 0, 851, 854, - 840, 843, 0, 417, 833, 831, 825, 831, 839, 832, - 845, 830, 0, 836, 831, 839, 0, 829, 835, 838, - 818, 836, 413, 835, 0, 823, 812, 813, 817, 826, - 810, 824, 828, 824, 806, 811, 803, 819, 814, 803, - 806, 818, 802, 0, 799, 804, 806, 417, 805, 0, - 1236, 858, 460, 841, 464, 465, 468, 0, 833, 0, - 831, 835, 826, 819, 814, 0, 834, 825, 813, 0, - 819, 813, 0, 829, 822, 827, 822, 0, 817, 824, - 804, 811, 809, 807, 817, 804, 806, 0, 802, 808, + 846, 842, 853, 854, 0, 853, 837, 0, 851, 854, 840, 843, + 0, 417, 833, 831, 825, 831, 839, 832, 845, 830, 0, 836, + 831, 839, 0, 829, 835, 838, 818, 836, 413, 835, 0, 823, + 812, 813, 817, 826, 810, 824, 828, 824, 806, 811, 803, 819, + 814, 803, 806, 818, 802, 0, 799, 804, 806, 417, 805, 0, + 1236, 858, 460, 841, 464, 465, 468, 0, 833, 0, 831, 835, + 826, 819, 814, 0, 834, 825, 813, 0, 819, 813, 0, 829, + 822, 827, 822, 0, 817, 824, 804, 811, 809, 807, 817, 804, + 806, 0, 802, 808, - 800, 805, 807, 0, 0, 777, 765, 775, 0, 774, - 773, 0, 764, 762, 771, 762, 755, 0, 767, 767, - 763, 764, 749, 766, 762, 746, 742, 435, 0, 758, - 758, 756, 742, 745, 752, 752, 731, 750, 428, 742, - 738, 740, 736, 741, 728, 744, 740, 741, 741, 724, - 724, 737, 723, 735, 0, 734, 722, 736, 729, 717, - 718, 732, 0, 727, 711, 705, 723, 712, 718, 714, - 716, 711, 705, 721, 716, 0, 705, 0, 698, 698, - 697, 696, 696, 709, 709, 436, 0, 707, 706, 701, - 704, 689, 695, 692, 696, 0, 701, 717, 476, 477, + 800, 805, 807, 0, 0, 777, 765, 775, 0, 774, 773, 0, + 764, 762, 771, 762, 755, 0, 767, 767, 763, 764, 749, 766, + 762, 746, 742, 435, 0, 758, 758, 756, 742, 745, 752, 752, + 731, 750, 428, 742, 738, 740, 736, 741, 728, 744, 740, 741, + 741, 724, 724, 737, 723, 735, 0, 734, 722, 736, 729, 717, + 718, 732, 0, 727, 711, 705, 723, 712, 718, 714, 716, 711, + 705, 721, 716, 0, 705, 0, 698, 698, 697, 696, 696, 709, + 709, 436, 0, 707, 706, 701, 704, 689, 695, 692, 696, 0, + 701, 717, 476, 477, - 0, 718, 716, 710, 720, 719, 718, 711, 707, 723, - 0, 711, 717, 709, 699, 691, 74, 0, 0, 110, - 0, 207, 230, 474, 467, 0, 467, 472, 462, 457, - 0, 0, 455, 456, 0, 0, 0, 449, 0, 0, - 0, 448, 450, 460, 440, 0, 462, 463, 0, 451, - 0, 0, 467, 0, 464, 463, 459, 473, 471, 471, - 468, 463, 465, 475, 466, 480, 471, 0, 475, 481, - 0, 465, 467, 485, 480, 468, 473, 487, 481, 480, - 0, 0, 483, 480, 0, 471, 477, 483, 480, 0, - 487, 505, 496, 486, 501, 488, 494, 0, 490, 500, + 0, 718, 716, 710, 720, 719, 718, 711, 707, 723, 0, 711, + 717, 709, 699, 691, 74, 0, 0, 110, 0, 207, 230, 474, + 467, 0, 467, 472, 462, 457, 0, 0, 455, 456, 0, 0, + 0, 449, 0, 0, 0, 448, 450, 460, 440, 0, 462, 463, + 0, 451, 0, 0, 467, 0, 464, 463, 459, 473, 471, 471, + 468, 463, 465, 475, 466, 480, 471, 0, 475, 481, 0, 465, + 467, 485, 480, 468, 473, 487, 481, 480, 0, 0, 483, 480, + 0, 471, 477, 483, 480, 0, 487, 505, 496, 486, 501, 488, + 494, 0, 490, 500, - 501, 0, 0, 502, 506, 0, 509, 500, 511, 511, - 512, 513, 499, 519, 0, 554, 555, 548, 536, 0, - 551, 542, 543, 544, 534, 544, 550, 0, 553, 0, - 556, 545, 562, 536, 549, 0, 0, 548, 0, 0, - 527, 0, 0, 535, 536, 537, 539, 539, 0, 0, - 530, 526, 0, 535, 528, 531, 0, 545, 545, 538, - 534, 0, 543, 544, 556, 543, 0, 541, 555, 541, - 558, 558, 0, 0, 0, 0, 555, 550, 561, 555, - 563, 544, 565, 1236, 566, 0, 0, 568, 0, 572, - 559, 568, 564, 552, 0, 0, 0, 574, 575, 576, + 501, 0, 0, 502, 506, 0, 509, 500, 511, 511, 512, 513, + 499, 519, 0, 554, 555, 548, 536, 0, 551, 542, 543, 544, + 534, 544, 550, 0, 553, 0, 556, 545, 562, 536, 549, 0, + 0, 548, 0, 0, 527, 0, 0, 535, 536, 537, 539, 539, + 0, 0, 530, 526, 0, 535, 528, 531, 0, 545, 545, 538, + 534, 0, 543, 544, 556, 543, 0, 541, 555, 541, 558, 558, + 0, 0, 0, 0, 555, 550, 561, 555, 563, 544, 565, 1236, + 566, 0, 0, 568, 0, 572, 559, 568, 564, 552, 0, 0, + 0, 574, 575, 576, - 576, 570, 595, 0, 607, 608, 0, 0, 0, 0, - 0, 590, 616, 595, 604, 600, 0, 591, 0, 588, - 589, 580, 0, 0, 580, 0, 584, 0, 593, 578, - 591, 582, 600, 583, 598, 586, 591, 601, 589, 0, - 0, 596, 602, 592, 607, 0, 608, 0, 0, 609, - 0, 598, 601, 608, 605, 0, 0, 0, 0, 614, - 0, 0, 644, 0, 645, 649, 651, 635, 649, 637, - 0, 0, 606, 621, 0, 0, 0, 608, 0, 617, - 0, 0, 0, 0, 0, 0, 0, 616, 611, 0, - 0, 0, 613, 0, 613, 0, 0, 0, 0, 652, + 576, 570, 595, 0, 607, 608, 0, 0, 0, 0, 0, 590, + 616, 595, 604, 600, 0, 591, 0, 588, 589, 580, 0, 0, + 580, 0, 584, 0, 593, 578, 591, 582, 600, 583, 598, 586, + 591, 601, 589, 0, 0, 596, 602, 592, 607, 0, 608, 0, + 0, 609, 0, 598, 601, 608, 605, 0, 0, 0, 0, 614, + 0, 0, 644, 0, 645, 649, 651, 635, 649, 637, 0, 0, + 606, 621, 0, 0, 0, 608, 0, 617, 0, 0, 0, 0, + 0, 0, 0, 616, 611, 0, 0, 0, 613, 0, 613, 0, + 0, 0, 0, 652, - 653, 648, 649, 663, 0, 0, 0, 0, 634, 0, - 0, 635, 666, 660, 664, 656, 668, 642, 643, 0, - 0, 674, 678, 671, 0, 0, 666, 673, 668, 666, - 671, 672, 668, 0, 0, 0, 1236, 705, 707, 713, - 716, 722, 727, 732 - } ; + 653, 648, 649, 663, 0, 0, 0, 0, 634, 0, 0, 635, + 666, 660, 664, 656, 668, 642, 643, 0, 0, 674, 678, 671, + 0, 0, 666, 673, 668, 666, 671, 672, 668, 0, 0, 0, + 1236, 705, 707, 713, 716, 722, 727, 732 +}; -static yyconst flex_int16_t yy_def[1045] = - { 0, - 1037, 1, 1, 3, 1037, 1037, 1037, 1037, 1037, 1037, - 1038, 1039, 1040, 1037, 1041, 1041, 1037, 1037, 1037, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1037, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1037, 1042, 1041, 1037, 1037, 1043, 1043, 1043, 1041, 69, - 69, 69, 69, 1041, 69, 69, 69, 69, 69, 69, - 69, 69, 1043, 1042, 1037, 1037, 1037, 1038, 1037, 1039, - 1037, 1044, 1037, 1041, 1041, 1037, 1041, 1041, 1037, 1037, +static yyconst flex_int16_t yy_def[1045] = { + 0, 1037, 1, 1, 3, 1037, 1037, 1037, 1037, 1037, 1037, 1038, + 1039, 1040, 1037, 1041, 1041, 1037, 1037, 1037, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1037, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1037, 1042, 1041, 1037, 1037, 1043, 1043, 1043, 1041, 69, 69, + 69, 69, 1041, 69, 69, 69, 69, 69, 69, 69, 69, 1043, + 1042, 1037, 1037, 1037, 1038, 1037, 1039, 1037, 1044, 1037, 1041, 1041, + 1037, 1041, 1041, 1037, 1037, - 1037, 1037, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1037, 1037, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1037, 1037, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1037, 1037, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1037, 1042, 1042, 1037, 1041, - 1037, 1037, 1037, 83, 83, 83, 69, 69, 69, 69, - 69, 1041, 69, 69, 69, 69, 69, 69, 69, 69, - 83, 84, 1037, 1042, 84, 1037, 1037, 1037, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1037, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1037, 1042, 1042, 1037, 1041, 1037, 1037, 1037, 83, + 83, 83, 69, 69, 69, 69, 69, 1041, 69, 69, 69, 69, + 69, 69, 69, 69, 83, 84, 1037, 1042, 84, 1037, 1037, 1037, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1037, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 69, 69, 1041, 69, 69, 69, 69, 1037, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1037, 1037, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 69, 69, 1041, 69, 69, 69, 69, 1037, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1037, 1037, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1037, 1037, 69, 1041, 69, 69, 69, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1037, 1037, 69, 1041, 69, 69, 69, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 69, 69, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 69, 69, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 69, 69, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1037, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 69, 69, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1037, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 0, 1037, 1037, 1037, - 1037, 1037, 1037, 1037 - } ; + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, + 0, 1037, 1037, 1037, 1037, 1037, 1037, 1037 +}; -static yyconst flex_int16_t yy_nxt[1311] = - { 0, - 6, 7, 8, 9, 7, 10, 11, 6, 12, 6, - 13, 14, 15, 6, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 26, 27, 28, 27, 27, 29, - 30, 31, 32, 33, 27, 34, 35, 36, 27, 27, - 37, 27, 27, 27, 38, 6, 6, 27, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 27, 49, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 27, 27, 27, 61, 105, 85, 61, 61, 85, - 62, 83, 99, 100, 84, 107, 119, 96, 110, 106, - 111, 355, 97, 113, 120, 108, 114, 121, 109, 356, +static yyconst flex_int16_t yy_nxt[1311] = { + 0, 6, 7, 8, 9, 7, 10, 11, 6, 12, 6, 13, + 14, 15, 6, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 27, 27, 29, 30, 31, 32, 33, 27, + 34, 35, 36, 27, 27, 37, 27, 27, 27, 38, 6, 6, + 27, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 27, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 27, 27, 27, 61, 105, 85, 61, 61, 85, 62, 83, 99, + 100, 84, 107, 119, 96, 110, 106, 111, 355, 97, 113, 120, + 108, 114, 121, 109, 356, - 112, 122, 115, 63, 64, 65, 66, 63, 144, 67, - 832, 123, 128, 68, 69, 67, 70, 212, 145, 213, - 71, 72, 73, 116, 74, 75, 129, 76, 77, 98, - 76, 78, 175, 117, 346, 79, 118, 124, 80, 81, - 132, 125, 82, 140, 133, 126, 176, 67, 135, 136, - 347, 127, 163, 141, 134, 164, 142, 833, 165, 152, - 137, 138, 153, 139, 146, 154, 147, 177, 155, 227, - 148, 149, 156, 76, 150, 151, 157, 166, 178, 158, - 159, 227, 179, 160, 230, 170, 161, 181, 167, 171, - 168, 182, 162, 172, 169, 183, 173, 185, 186, 189, + 112, 122, 115, 63, 64, 65, 66, 63, 144, 67, 832, 123, + 128, 68, 69, 67, 70, 212, 145, 213, 71, 72, 73, 116, + 74, 75, 129, 76, 77, 98, 76, 78, 175, 117, 346, 79, + 118, 124, 80, 81, 132, 125, 82, 140, 133, 126, 176, 67, + 135, 136, 347, 127, 163, 141, 134, 164, 142, 833, 165, 152, + 137, 138, 153, 139, 146, 154, 147, 177, 155, 227, 148, 149, + 156, 76, 150, 151, 157, 166, 178, 158, 159, 227, 179, 160, + 230, 170, 161, 181, 167, 171, 168, 182, 162, 172, 169, 183, + 173, 185, 186, 189, - 192, 184, 104, 190, 194, 96, 187, 144, 195, 227, - 229, 198, 188, 191, 193, 199, 203, 145, 209, 200, - 204, 196, 227, 205, 201, 202, 231, 131, 210, 834, - 206, 211, 207, 216, 220, 208, 216, 227, 125, 217, - 106, 240, 126, 85, 222, 223, 224, 98, 127, 1037, - 222, 223, 1037, 222, 223, 227, 227, 110, 85, 232, - 235, 85, 835, 227, 122, 226, 222, 223, 225, 112, - 233, 225, 234, 114, 123, 225, 227, 225, 228, 115, - 120, 251, 227, 227, 227, 252, 331, 227, 292, 227, - 227, 227, 227, 227, 293, 254, 332, 227, 227, 255, + 192, 184, 104, 190, 194, 96, 187, 144, 195, 227, 229, 198, + 188, 191, 193, 199, 203, 145, 209, 200, 204, 196, 227, 205, + 201, 202, 231, 131, 210, 834, 206, 211, 207, 216, 220, 208, + 216, 227, 125, 217, 106, 240, 126, 85, 222, 223, 224, 98, + 127, 1037, 222, 223, 1037, 222, 223, 227, 227, 110, 85, 232, + 235, 85, 835, 227, 122, 226, 222, 223, 225, 112, 233, 225, + 234, 114, 123, 225, 227, 225, 228, 115, 120, 251, 227, 227, + 227, 252, 331, 227, 292, 227, 227, 227, 227, 227, 293, 254, + 332, 227, 227, 255, - 227, 227, 236, 237, 227, 263, 140, 96, 264, 225, - 278, 279, 97, 296, 238, 138, 141, 239, 145, 142, - 216, 222, 223, 241, 281, 284, 242, 282, 297, 333, - 456, 298, 373, 334, 285, 227, 243, 244, 245, 299, - 305, 245, 374, 335, 306, 245, 245, 245, 245, 98, - 307, 227, 245, 245, 245, 336, 316, 245, 270, 245, - 245, 337, 245, 245, 338, 339, 340, 245, 317, 318, - 245, 245, 457, 319, 245, 348, 349, 352, 361, 245, - 387, 362, 350, 375, 353, 385, 354, 376, 386, 388, - 363, 364, 382, 393, 383, 365, 402, 366, 400, 401, + 227, 227, 236, 237, 227, 263, 140, 96, 264, 225, 278, 279, + 97, 296, 238, 138, 141, 239, 145, 142, 216, 222, 223, 241, + 281, 284, 242, 282, 297, 333, 456, 298, 373, 334, 285, 227, + 243, 244, 245, 299, 305, 245, 374, 335, 306, 245, 245, 245, + 245, 98, 307, 227, 245, 245, 245, 336, 316, 245, 270, 245, + 245, 337, 245, 245, 338, 339, 340, 245, 317, 318, 245, 245, + 457, 319, 245, 348, 349, 352, 361, 245, 387, 362, 350, 375, + 353, 385, 354, 376, 386, 388, 363, 364, 382, 393, 383, 365, + 402, 366, 400, 401, - 395, 384, 377, 396, 227, 245, 273, 397, 216, 398, - 227, 216, 85, 394, 217, 224, 1037, 1037, 225, 225, - 225, 96, 225, 225, 227, 405, 229, 403, 260, 227, - 226, 227, 404, 406, 227, 407, 469, 227, 227, 489, - 493, 470, 516, 517, 522, 534, 523, 490, 287, 408, - 546, 288, 227, 409, 561, 562, 547, 535, 494, 227, - 227, 227, 423, 98, 563, 227, 227, 414, 589, 456, - 631, 653, 671, 565, 227, 672, 654, 695, 227, 227, - 590, 567, 227, 632, 696, 699, 749, 760, 566, 804, - 227, 227, 805, 761, 700, 568, 836, 837, 750, 598, + 395, 384, 377, 396, 227, 245, 273, 397, 216, 398, 227, 216, + 85, 394, 217, 224, 1037, 1037, 225, 225, 225, 96, 225, 225, + 227, 405, 229, 403, 260, 227, 226, 227, 404, 406, 227, 407, + 469, 227, 227, 489, 493, 470, 516, 517, 522, 534, 523, 490, + 287, 408, 546, 288, 227, 409, 561, 562, 547, 535, 494, 227, + 227, 227, 423, 98, 563, 227, 227, 414, 589, 456, 631, 653, + 671, 565, 227, 672, 654, 695, 227, 227, 590, 567, 227, 632, + 696, 699, 749, 760, 566, 804, 227, 227, 805, 761, 700, 568, + 836, 837, 750, 598, - 817, 816, 838, 839, 840, 841, 842, 843, 844, 845, - 846, 457, 847, 848, 849, 850, 851, 852, 853, 854, - 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, - 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, - 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, - 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, - 895, 896, 897, 898, 899, 900, 901, 902, 227, 227, - 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, - 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, - 923, 924, 925, 926, 927, 928, 929, 840, 930, 931, + 817, 816, 838, 839, 840, 841, 842, 843, 844, 845, 846, 457, + 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, + 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, + 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, + 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, + 895, 896, 897, 898, 899, 900, 901, 902, 227, 227, 903, 904, + 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, + 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, + 929, 840, 930, 931, - 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, - 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, - 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, - 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, - 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, - 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, - 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, - 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, - 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, - 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, + 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, + 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, + 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, + 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, + 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, + 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, + 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, + 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, + 1028, 1029, 1030, 1031, - 1032, 1033, 1034, 1035, 1036, 88, 88, 88, 88, 88, - 88, 90, 90, 91, 91, 831, 91, 91, 91, 94, - 94, 94, 218, 218, 218, 218, 218, 218, 225, 225, - 225, 225, 247, 247, 830, 247, 247, 247, 829, 828, - 827, 826, 825, 824, 823, 822, 821, 820, 819, 818, - 815, 814, 813, 812, 811, 810, 809, 808, 807, 806, - 803, 802, 801, 800, 799, 798, 797, 796, 795, 794, - 793, 792, 791, 790, 789, 788, 787, 786, 785, 784, - 783, 782, 781, 780, 779, 778, 777, 776, 775, 774, - 773, 772, 771, 770, 769, 768, 767, 766, 765, 764, + 1032, 1033, 1034, 1035, 1036, 88, 88, 88, 88, 88, 88, 90, + 90, 91, 91, 831, 91, 91, 91, 94, 94, 94, 218, 218, + 218, 218, 218, 218, 225, 225, 225, 225, 247, 247, 830, 247, + 247, 247, 829, 828, 827, 826, 825, 824, 823, 822, 821, 820, + 819, 818, 815, 814, 813, 812, 811, 810, 809, 808, 807, 806, + 803, 802, 801, 800, 799, 798, 797, 796, 795, 794, 793, 792, + 791, 790, 789, 788, 787, 786, 785, 784, 783, 782, 781, 780, + 779, 778, 777, 776, 775, 774, 773, 772, 771, 770, 769, 768, + 767, 766, 765, 764, - 763, 762, 759, 758, 757, 756, 755, 754, 753, 752, - 751, 748, 747, 746, 745, 744, 743, 742, 741, 740, - 739, 738, 737, 736, 735, 734, 733, 732, 731, 730, - 729, 728, 727, 726, 725, 724, 723, 722, 721, 720, - 719, 718, 717, 716, 715, 714, 713, 712, 711, 710, - 709, 708, 707, 706, 705, 704, 703, 702, 701, 698, - 561, 697, 694, 693, 692, 691, 690, 689, 688, 687, - 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, - 676, 675, 674, 673, 670, 669, 668, 667, 666, 665, - 664, 663, 662, 661, 660, 659, 658, 657, 656, 655, + 763, 762, 759, 758, 757, 756, 755, 754, 753, 752, 751, 748, + 747, 746, 745, 744, 743, 742, 741, 740, 739, 738, 737, 736, + 735, 734, 733, 732, 731, 730, 729, 728, 727, 726, 725, 724, + 723, 722, 721, 720, 719, 718, 717, 716, 715, 714, 713, 712, + 711, 710, 709, 708, 707, 706, 705, 704, 703, 702, 701, 698, + 561, 697, 694, 693, 692, 691, 690, 689, 688, 687, 686, 685, + 684, 683, 682, 681, 680, 679, 678, 677, 676, 675, 674, 673, + 670, 669, 668, 667, 666, 665, 664, 663, 662, 661, 660, 659, + 658, 657, 656, 655, - 652, 651, 650, 649, 648, 647, 646, 645, 644, 643, - 642, 641, 640, 639, 638, 637, 636, 635, 634, 633, - 630, 629, 628, 627, 626, 625, 624, 623, 622, 621, - 620, 619, 618, 617, 616, 615, 614, 613, 612, 611, - 610, 609, 608, 607, 606, 605, 604, 603, 602, 601, - 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, - 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, - 578, 577, 576, 575, 574, 573, 572, 571, 570, 569, - 568, 564, 560, 559, 558, 557, 556, 555, 554, 553, - 552, 551, 550, 549, 548, 545, 544, 543, 542, 541, + 652, 651, 650, 649, 648, 647, 646, 645, 644, 643, 642, 641, + 640, 639, 638, 637, 636, 635, 634, 633, 630, 629, 628, 627, + 626, 625, 624, 623, 622, 621, 620, 619, 618, 617, 616, 615, + 614, 613, 612, 611, 610, 609, 608, 607, 606, 605, 604, 603, + 602, 601, 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, + 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, + 576, 575, 574, 573, 572, 571, 570, 569, 568, 564, 560, 559, + 558, 557, 556, 555, 554, 553, 552, 551, 550, 549, 548, 545, + 544, 543, 542, 541, - 540, 539, 538, 537, 536, 533, 532, 531, 530, 529, - 528, 527, 526, 525, 524, 521, 520, 519, 518, 437, - 515, 514, 513, 512, 511, 510, 509, 508, 507, 506, - 505, 504, 503, 502, 501, 500, 499, 498, 497, 496, - 495, 492, 491, 488, 487, 486, 485, 484, 483, 482, - 481, 480, 479, 478, 477, 476, 475, 474, 473, 472, - 471, 468, 467, 466, 465, 464, 463, 462, 461, 460, - 459, 458, 455, 454, 453, 452, 451, 450, 449, 448, - 447, 446, 445, 444, 443, 442, 441, 440, 439, 438, - 437, 436, 435, 434, 433, 432, 431, 430, 429, 428, + 540, 539, 538, 537, 536, 533, 532, 531, 530, 529, 528, 527, + 526, 525, 524, 521, 520, 519, 518, 437, 515, 514, 513, 512, + 511, 510, 509, 508, 507, 506, 505, 504, 503, 502, 501, 500, + 499, 498, 497, 496, 495, 492, 491, 488, 487, 486, 485, 484, + 483, 482, 481, 480, 479, 478, 477, 476, 475, 474, 473, 472, + 471, 468, 467, 466, 465, 464, 463, 462, 461, 460, 459, 458, + 455, 454, 453, 452, 451, 450, 449, 448, 447, 446, 445, 444, + 443, 442, 441, 440, 439, 438, 437, 436, 435, 434, 433, 432, + 431, 430, 429, 428, - 427, 426, 425, 424, 423, 422, 421, 420, 419, 418, - 417, 416, 415, 414, 413, 412, 411, 249, 410, 410, - 243, 227, 227, 222, 219, 219, 399, 392, 391, 390, - 389, 381, 380, 379, 378, 372, 371, 370, 369, 368, - 367, 360, 359, 358, 357, 351, 345, 344, 343, 342, - 341, 330, 329, 328, 327, 326, 325, 324, 323, 322, - 321, 320, 315, 314, 313, 312, 311, 310, 309, 308, - 304, 303, 302, 301, 300, 295, 294, 291, 290, 289, - 288, 287, 286, 283, 280, 277, 276, 275, 274, 273, - 272, 271, 270, 269, 268, 267, 266, 265, 262, 261, + 427, 426, 425, 424, 423, 422, 421, 420, 419, 418, 417, 416, + 415, 414, 413, 412, 411, 249, 410, 410, 243, 227, 227, 222, + 219, 219, 399, 392, 391, 390, 389, 381, 380, 379, 378, 372, + 371, 370, 369, 368, 367, 360, 359, 358, 357, 351, 345, 344, + 343, 342, 341, 330, 329, 328, 327, 326, 325, 324, 323, 322, + 321, 320, 315, 314, 313, 312, 311, 310, 309, 308, 304, 303, + 302, 301, 300, 295, 294, 291, 290, 289, 288, 287, 286, 283, + 280, 277, 276, 275, 274, 273, 272, 271, 270, 269, 268, 267, + 266, 265, 262, 261, - 260, 259, 258, 257, 256, 253, 250, 249, 95, 93, - 248, 246, 89, 227, 221, 219, 215, 214, 197, 180, - 174, 143, 131, 130, 104, 103, 102, 101, 95, 93, - 92, 89, 87, 86, 1037, 5, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 260, 259, 258, 257, 256, 253, 250, 249, 95, 93, 248, 246, + 89, 227, 221, 219, 215, 214, 197, 180, 174, 143, 131, 130, + 104, 103, 102, 101, 95, 93, 92, 89, 87, 86, 1037, 5, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037 - } ; + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037 +}; -static yyconst flex_int16_t yy_chk[1311] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 22, 7, 2, 4, 7, - 2, 4, 17, 17, 4, 23, 28, 16, 24, 22, - 24, 186, 16, 25, 28, 23, 25, 29, 23, 186, +static yyconst flex_int16_t yy_chk[1311] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 22, 7, 2, 4, 7, 2, 4, 17, + 17, 4, 23, 28, 16, 24, 22, 24, 186, 16, 25, 28, + 23, 25, 29, 23, 186, - 24, 29, 25, 2, 3, 3, 3, 4, 38, 3, - 717, 29, 31, 3, 3, 3, 3, 58, 38, 58, - 3, 3, 3, 26, 3, 3, 31, 3, 3, 16, - 3, 3, 46, 26, 182, 3, 26, 30, 3, 3, - 34, 30, 3, 36, 34, 30, 46, 3, 35, 35, - 182, 30, 42, 36, 34, 42, 36, 720, 42, 40, - 35, 35, 40, 35, 39, 40, 39, 47, 40, 71, - 39, 39, 41, 3, 39, 39, 41, 43, 47, 41, - 41, 72, 47, 41, 71, 44, 41, 49, 43, 44, - 43, 49, 41, 44, 43, 49, 44, 50, 50, 51, + 24, 29, 25, 2, 3, 3, 3, 4, 38, 3, 717, 29, + 31, 3, 3, 3, 3, 58, 38, 58, 3, 3, 3, 26, + 3, 3, 31, 3, 3, 16, 3, 3, 46, 26, 182, 3, + 26, 30, 3, 3, 34, 30, 3, 36, 34, 30, 46, 3, + 35, 35, 182, 30, 42, 36, 34, 42, 36, 720, 42, 40, + 35, 35, 40, 35, 39, 40, 39, 47, 40, 71, 39, 39, + 41, 3, 39, 39, 41, 43, 47, 41, 41, 72, 47, 41, + 71, 44, 41, 49, 43, 44, 43, 49, 41, 44, 43, 49, + 44, 50, 50, 51, - 52, 49, 72, 51, 53, 70, 50, 144, 53, 79, - 70, 55, 50, 51, 52, 55, 56, 144, 57, 55, - 56, 53, 73, 56, 55, 55, 73, 79, 57, 722, - 56, 57, 56, 61, 63, 56, 61, 82, 63, 61, - 73, 82, 63, 66, 66, 66, 66, 70, 63, 67, - 67, 67, 68, 68, 68, 75, 78, 74, 85, 74, - 78, 85, 723, 77, 78, 68, 69, 69, 69, 74, - 75, 69, 77, 75, 78, 69, 69, 69, 69, 75, - 77, 104, 69, 69, 69, 104, 173, 69, 140, 69, - 69, 80, 69, 69, 140, 106, 173, 69, 81, 106, + 52, 49, 72, 51, 53, 70, 50, 144, 53, 79, 70, 55, + 50, 51, 52, 55, 56, 144, 57, 55, 56, 53, 73, 56, + 55, 55, 73, 79, 57, 722, 56, 57, 56, 61, 63, 56, + 61, 82, 63, 61, 73, 82, 63, 66, 66, 66, 66, 70, + 63, 67, 67, 67, 68, 68, 68, 75, 78, 74, 85, 74, + 78, 85, 723, 77, 78, 68, 69, 69, 69, 74, 75, 69, + 77, 75, 78, 69, 69, 69, 69, 75, 77, 104, 69, 69, + 69, 104, 173, 69, 140, 69, 69, 80, 69, 69, 140, 106, + 173, 69, 81, 106, - 69, 69, 80, 80, 69, 114, 81, 97, 114, 69, - 129, 129, 97, 145, 80, 80, 81, 80, 145, 81, - 83, 83, 83, 83, 131, 133, 83, 131, 146, 174, - 296, 146, 198, 174, 133, 69, 84, 84, 84, 146, - 152, 84, 198, 174, 152, 84, 84, 84, 84, 97, - 152, 235, 84, 84, 84, 175, 161, 84, 235, 84, - 84, 175, 84, 84, 176, 176, 176, 84, 161, 161, - 84, 84, 296, 161, 84, 183, 183, 185, 191, 84, - 206, 191, 183, 199, 185, 205, 185, 199, 205, 206, - 191, 191, 204, 211, 204, 191, 220, 191, 215, 215, + 69, 69, 80, 80, 69, 114, 81, 97, 114, 69, 129, 129, + 97, 145, 80, 80, 81, 80, 145, 81, 83, 83, 83, 83, + 131, 133, 83, 131, 146, 174, 296, 146, 198, 174, 133, 69, + 84, 84, 84, 146, 152, 84, 198, 174, 152, 84, 84, 84, + 84, 97, 152, 235, 84, 84, 84, 175, 161, 84, 235, 84, + 84, 175, 84, 84, 176, 176, 176, 84, 161, 161, 84, 84, + 296, 161, 84, 183, 183, 185, 191, 84, 206, 191, 183, 199, + 185, 205, 185, 199, 205, 206, 191, 191, 204, 211, 204, 191, + 220, 191, 215, 215, - 212, 204, 199, 212, 230, 84, 220, 212, 216, 212, - 231, 216, 224, 211, 216, 224, 225, 226, 224, 225, - 226, 229, 225, 226, 236, 232, 229, 230, 232, 233, - 226, 238, 231, 233, 237, 238, 310, 239, 240, 330, - 333, 310, 358, 358, 364, 375, 364, 330, 236, 239, - 386, 237, 406, 240, 402, 402, 386, 375, 333, 404, - 403, 407, 406, 229, 403, 408, 409, 404, 439, 456, - 489, 514, 533, 407, 563, 533, 514, 558, 565, 566, - 439, 409, 567, 489, 558, 566, 628, 639, 408, 686, - 699, 700, 686, 639, 567, 563, 724, 725, 628, 565, + 212, 204, 199, 212, 230, 84, 220, 212, 216, 212, 231, 216, + 224, 211, 216, 224, 225, 226, 224, 225, 226, 229, 225, 226, + 236, 232, 229, 230, 232, 233, 226, 238, 231, 233, 237, 238, + 310, 239, 240, 330, 333, 310, 358, 358, 364, 375, 364, 330, + 236, 239, 386, 237, 406, 240, 402, 402, 386, 375, 333, 404, + 403, 407, 406, 229, 403, 408, 409, 404, 439, 456, 489, 514, + 533, 407, 563, 533, 514, 558, 565, 566, 439, 409, 567, 489, + 558, 566, 628, 639, 408, 686, 699, 700, 686, 639, 567, 563, + 724, 725, 628, 565, - 700, 699, 727, 728, 729, 730, 733, 734, 738, 742, - 743, 456, 744, 745, 747, 748, 750, 753, 755, 756, - 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, - 767, 769, 770, 772, 773, 774, 775, 776, 777, 778, - 779, 780, 783, 784, 786, 787, 788, 789, 791, 792, - 793, 794, 795, 796, 797, 799, 800, 801, 804, 805, - 807, 808, 809, 810, 811, 812, 813, 814, 816, 817, - 818, 819, 821, 822, 823, 824, 825, 826, 827, 829, - 831, 832, 833, 834, 835, 838, 841, 844, 845, 846, - 847, 848, 851, 852, 854, 855, 856, 817, 858, 859, + 700, 699, 727, 728, 729, 730, 733, 734, 738, 742, 743, 456, + 744, 745, 747, 748, 750, 753, 755, 756, 757, 758, 759, 760, + 761, 762, 763, 764, 765, 766, 767, 769, 770, 772, 773, 774, + 775, 776, 777, 778, 779, 780, 783, 784, 786, 787, 788, 789, + 791, 792, 793, 794, 795, 796, 797, 799, 800, 801, 804, 805, + 807, 808, 809, 810, 811, 812, 813, 814, 816, 817, 818, 819, + 821, 822, 823, 824, 825, 826, 827, 829, 831, 832, 833, 834, + 835, 838, 841, 844, 845, 846, 847, 848, 851, 852, 854, 855, + 856, 817, 858, 859, - 860, 861, 863, 864, 865, 866, 868, 869, 870, 871, - 872, 877, 878, 879, 880, 881, 882, 883, 885, 888, - 890, 891, 892, 893, 894, 898, 899, 900, 901, 902, - 903, 905, 906, 912, 913, 914, 915, 916, 918, 920, - 921, 922, 925, 927, 929, 930, 931, 932, 933, 934, - 935, 936, 937, 938, 939, 942, 943, 944, 945, 947, - 950, 952, 953, 954, 955, 960, 963, 965, 966, 967, - 968, 969, 970, 973, 974, 978, 980, 988, 989, 993, - 995, 1000, 1001, 1002, 1003, 1004, 1009, 1012, 1013, 1014, - 1015, 1016, 1017, 1018, 1019, 1022, 1023, 1024, 1027, 1028, + 860, 861, 863, 864, 865, 866, 868, 869, 870, 871, 872, 877, + 878, 879, 880, 881, 882, 883, 885, 888, 890, 891, 892, 893, + 894, 898, 899, 900, 901, 902, 903, 905, 906, 912, 913, 914, + 915, 916, 918, 920, 921, 922, 925, 927, 929, 930, 931, 932, + 933, 934, 935, 936, 937, 938, 939, 942, 943, 944, 945, 947, + 950, 952, 953, 954, 955, 960, 963, 965, 966, 967, 968, 969, + 970, 973, 974, 978, 980, 988, 989, 993, 995, 1000, 1001, 1002, + 1003, 1004, 1009, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1022, + 1023, 1024, 1027, 1028, - 1029, 1030, 1031, 1032, 1033, 1038, 1038, 1038, 1038, 1038, - 1038, 1039, 1039, 1040, 1040, 716, 1040, 1040, 1040, 1041, - 1041, 1041, 1042, 1042, 1042, 1042, 1042, 1042, 1043, 1043, - 1043, 1043, 1044, 1044, 715, 1044, 1044, 1044, 714, 713, - 712, 710, 709, 708, 707, 706, 705, 704, 703, 702, - 698, 697, 695, 694, 693, 692, 691, 690, 689, 688, - 685, 684, 683, 682, 681, 680, 679, 677, 675, 674, - 673, 672, 671, 670, 669, 668, 667, 666, 665, 664, - 662, 661, 660, 659, 658, 657, 656, 654, 653, 652, - 651, 650, 649, 648, 647, 646, 645, 644, 643, 642, + 1029, 1030, 1031, 1032, 1033, 1038, 1038, 1038, 1038, 1038, 1038, 1039, + 1039, 1040, 1040, 716, 1040, 1040, 1040, 1041, 1041, 1041, 1042, 1042, + 1042, 1042, 1042, 1042, 1043, 1043, 1043, 1043, 1044, 1044, 715, 1044, + 1044, 1044, 714, 713, 712, 710, 709, 708, 707, 706, 705, 704, + 703, 702, 698, 697, 695, 694, 693, 692, 691, 690, 689, 688, + 685, 684, 683, 682, 681, 680, 679, 677, 675, 674, 673, 672, + 671, 670, 669, 668, 667, 666, 665, 664, 662, 661, 660, 659, + 658, 657, 656, 654, 653, 652, 651, 650, 649, 648, 647, 646, + 645, 644, 643, 642, - 641, 640, 638, 637, 636, 635, 634, 633, 632, 631, - 630, 627, 626, 625, 624, 623, 622, 621, 620, 619, - 617, 616, 615, 614, 613, 611, 610, 608, 607, 606, - 603, 602, 601, 600, 599, 597, 596, 595, 594, 593, - 592, 591, 590, 589, 587, 586, 585, 584, 582, 581, - 579, 578, 577, 575, 574, 573, 572, 571, 569, 564, - 562, 559, 557, 556, 555, 553, 552, 551, 550, 549, - 548, 547, 546, 545, 544, 543, 542, 541, 540, 539, - 538, 537, 536, 534, 532, 531, 530, 529, 528, 526, - 525, 524, 522, 521, 520, 519, 518, 517, 516, 515, + 641, 640, 638, 637, 636, 635, 634, 633, 632, 631, 630, 627, + 626, 625, 624, 623, 622, 621, 620, 619, 617, 616, 615, 614, + 613, 611, 610, 608, 607, 606, 603, 602, 601, 600, 599, 597, + 596, 595, 594, 593, 592, 591, 590, 589, 587, 586, 585, 584, + 582, 581, 579, 578, 577, 575, 574, 573, 572, 571, 569, 564, + 562, 559, 557, 556, 555, 553, 552, 551, 550, 549, 548, 547, + 546, 545, 544, 543, 542, 541, 540, 539, 538, 537, 536, 534, + 532, 531, 530, 529, 528, 526, 525, 524, 522, 521, 520, 519, + 518, 517, 516, 515, - 512, 511, 510, 509, 507, 506, 504, 503, 502, 501, - 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, - 488, 487, 486, 485, 484, 480, 479, 478, 477, 476, - 475, 474, 473, 472, 471, 469, 468, 467, 466, 465, - 464, 463, 462, 461, 460, 459, 458, 455, 453, 452, - 451, 450, 449, 447, 446, 445, 444, 443, 442, 440, - 438, 436, 435, 434, 433, 431, 430, 429, 428, 426, - 425, 424, 423, 421, 419, 417, 416, 415, 413, 412, - 411, 405, 400, 399, 398, 397, 396, 395, 394, 393, - 391, 390, 389, 388, 387, 385, 384, 383, 382, 381, + 512, 511, 510, 509, 507, 506, 504, 503, 502, 501, 500, 499, + 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 485, + 484, 480, 479, 478, 477, 476, 475, 474, 473, 472, 471, 469, + 468, 467, 466, 465, 464, 463, 462, 461, 460, 459, 458, 455, + 453, 452, 451, 450, 449, 447, 446, 445, 444, 443, 442, 440, + 438, 436, 435, 434, 433, 431, 430, 429, 428, 426, 425, 424, + 423, 421, 419, 417, 416, 415, 413, 412, 411, 405, 400, 399, + 398, 397, 396, 395, 394, 393, 391, 390, 389, 388, 387, 385, + 384, 383, 382, 381, - 380, 379, 378, 377, 376, 374, 373, 372, 371, 370, - 369, 368, 367, 366, 365, 363, 362, 361, 360, 359, - 357, 356, 355, 354, 353, 352, 351, 349, 348, 347, - 346, 344, 343, 342, 341, 339, 338, 337, 336, 335, - 334, 332, 331, 329, 328, 327, 326, 325, 324, 323, - 321, 320, 319, 318, 317, 316, 315, 314, 313, 312, - 311, 309, 308, 307, 306, 305, 304, 303, 302, 301, - 299, 297, 295, 294, 293, 292, 291, 290, 289, 288, - 287, 286, 285, 284, 283, 282, 281, 280, 279, 278, - 277, 276, 275, 274, 273, 272, 271, 270, 269, 268, + 380, 379, 378, 377, 376, 374, 373, 372, 371, 370, 369, 368, + 367, 366, 365, 363, 362, 361, 360, 359, 357, 356, 355, 354, + 353, 352, 351, 349, 348, 347, 346, 344, 343, 342, 341, 339, + 338, 337, 336, 335, 334, 332, 331, 329, 328, 327, 326, 325, + 324, 323, 321, 320, 319, 318, 317, 316, 315, 314, 313, 312, + 311, 309, 308, 307, 306, 305, 304, 303, 302, 301, 299, 297, + 295, 294, 293, 292, 291, 290, 289, 288, 287, 286, 285, 284, + 283, 282, 281, 280, 279, 278, 277, 276, 275, 274, 273, 272, + 271, 270, 269, 268, - 267, 266, 265, 264, 262, 261, 260, 259, 258, 257, - 256, 255, 254, 253, 252, 251, 250, 249, 248, 247, - 244, 234, 227, 223, 218, 217, 214, 210, 209, 208, - 207, 203, 202, 201, 200, 197, 196, 195, 194, 193, - 192, 190, 189, 188, 187, 184, 181, 180, 179, 178, - 177, 172, 171, 170, 169, 168, 167, 166, 165, 164, - 163, 162, 160, 159, 158, 157, 156, 155, 154, 153, - 151, 150, 149, 148, 147, 143, 142, 139, 138, 137, - 136, 135, 134, 132, 130, 128, 127, 126, 125, 124, - 123, 122, 121, 120, 118, 117, 116, 115, 113, 112, + 267, 266, 265, 264, 262, 261, 260, 259, 258, 257, 256, 255, + 254, 253, 252, 251, 250, 249, 248, 247, 244, 234, 227, 223, + 218, 217, 214, 210, 209, 208, 207, 203, 202, 201, 200, 197, + 196, 195, 194, 193, 192, 190, 189, 188, 187, 184, 181, 180, + 179, 178, 177, 172, 171, 170, 169, 168, 167, 166, 165, 164, + 163, 162, 160, 159, 158, 157, 156, 155, 154, 153, 151, 150, + 149, 148, 147, 143, 142, 139, 138, 137, 136, 135, 134, 132, + 130, 128, 127, 126, 125, 124, 123, 122, 121, 120, 118, 117, + 116, 115, 113, 112, - 111, 110, 109, 108, 107, 105, 103, 98, 95, 93, - 92, 91, 88, 76, 65, 62, 60, 59, 54, 48, - 45, 37, 33, 32, 21, 20, 19, 18, 15, 14, - 13, 11, 10, 9, 5, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 111, 110, 109, 108, 107, 105, 103, 98, 95, 93, 92, 91, + 88, 76, 65, 62, 60, 59, 54, 48, 45, 37, 33, 32, + 21, 20, 19, 18, 15, 14, 13, 11, 10, 9, 5, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, + 1037, 1037, 1037, 1037, - 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037 - } ; + 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037, 1037 +}; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; @@ -1090,7 +984,7 @@ int yy_flex_debug = 0; char *yytext; #line 1 "lev_comp.l" #line 2 "lev_comp.l" -/* NetHack 3.6 lev_comp.l $NHDT-Date: 1428240296 2015/04/05 13:24:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ +/* NetHack 3.6 lev_comp.l $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.15 $ */ /* NetHack 3.6 lev_comp.l $Date: 2009/05/06 10:54:31 $ $Revision: 1.9 $ */ /* SCCS Id: @(#)lev_lex.c 3.5 2002/03/27 */ /* Copyright (c) 1989 by Jean-Christophe Collet */ @@ -1106,52 +1000,52 @@ char *yytext; * yyunput is properly declared in flex.skel. */ #if !defined(FLEX_SCANNER) && !defined(FLEXHACK_SCANNER) -int FDECL(yyback, (int *,int)); +int FDECL(yyback, (int *, int)); int NDECL(yylook); int NDECL(yyinput); int NDECL(yywrap); int NDECL(yylex); - /* Traditional lexes let yyunput() and yyoutput() default to int; - * newer ones may declare them as void since they don't return - * values. For even more fun, the lex supplied as part of the - * newer unbundled compiler for SunOS 4.x adds the void declarations - * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain - * int) while the bundled lex and the one with the older unbundled - * compiler do not. To detect this, we need help from outside -- - * sys/unix/Makefile.utl. - * - * Digital UNIX is difficult and still has int in spite of all - * other signs. - */ -# if defined(NeXT) || defined(SVR4) || defined(_AIX32) -# define VOIDYYPUT -# endif -# if !defined(VOIDYYPUT) && defined(POSIX_TYPES) -# if !defined(BOS) && !defined(HISX) && !defined(_M_UNIX) && !defined(VMS) -# define VOIDYYPUT -# endif -# endif -# if !defined(VOIDYYPUT) && defined(WEIRD_LEX) -# if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX > 1) -# define VOIDYYPUT -# endif -# endif -# if defined(VOIDYYPUT) && defined(__osf__) -# undef VOIDYYPUT -# endif -# ifdef VOIDYYPUT +/* Traditional lexes let yyunput() and yyoutput() default to int; + * newer ones may declare them as void since they don't return + * values. For even more fun, the lex supplied as part of the + * newer unbundled compiler for SunOS 4.x adds the void declarations + * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain + * int) while the bundled lex and the one with the older unbundled + * compiler do not. To detect this, we need help from outside -- + * sys/unix/Makefile.utl. + * + * Digital UNIX is difficult and still has int in spite of all + * other signs. + */ +#if defined(NeXT) || defined(SVR4) || defined(_AIX32) +#define VOIDYYPUT +#endif +#if !defined(VOIDYYPUT) && defined(POSIX_TYPES) +#if !defined(BOS) && !defined(HISX) && !defined(_M_UNIX) && !defined(VMS) +#define VOIDYYPUT +#endif +#endif +#if !defined(VOIDYYPUT) && defined(WEIRD_LEX) +#if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX > 1) +#define VOIDYYPUT +#endif +#endif +#if defined(VOIDYYPUT) && defined(__osf__) +#undef VOIDYYPUT +#endif +#ifdef VOIDYYPUT void FDECL(yyunput, (int)); void FDECL(yyoutput, (int)); -# else +#else int FDECL(yyunput, (int)); int FDECL(yyoutput, (int)); -# endif -#endif /* !FLEX_SCANNER && !FLEXHACK_SCANNER */ +#endif +#endif /* !FLEX_SCANNER && !FLEXHACK_SCANNER */ #ifdef FLEX_SCANNER -#define YY_MALLOC_DECL \ - genericptr_t FDECL(malloc, (size_t)); \ - genericptr_t FDECL(realloc, (genericptr_t,size_t)); +#define YY_MALLOC_DECL \ + genericptr_t FDECL(malloc, (size_t)); \ + genericptr_t FDECL(realloc, (genericptr_t, size_t)); #endif void FDECL(init_yyin, (FILE *)); @@ -1161,7 +1055,8 @@ long NDECL(handle_varstring_check); long FDECL(corefunc_str_check, (char *, long)); extern void VDECL(lc_error, (const char *, ...)); -extern struct lc_vardefs *FDECL(vardef_defined,(struct lc_vardefs *,char *, int)); +extern struct lc_vardefs *FDECL(vardef_defined, + (struct lc_vardefs *, char *, int)); extern struct lc_vardefs *variable_definitions; @@ -1185,9 +1080,17 @@ static int map_cnt = 0; FILE *orig_yyin = NULL; -#define ST_RET(x) do { savetoken(yytext); return x; } while (0); -#define ST_RETF(y, x) do { savetoken(yytext); y; return x; } while (0); - +#define ST_RET(x) \ + do { \ + savetoken(yytext); \ + return x; \ + } while (0); +#define ST_RETF(y, x) \ + do { \ + savetoken(yytext); \ + y; \ + return x; \ + } while (0); #line 1193 "lex.yy.c" @@ -1206,36 +1109,36 @@ FILE *orig_yyin = NULL; #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals (void ); +static int yy_init_globals(void); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy (void ); +int yylex_destroy(void); -int yyget_debug (void ); +int yyget_debug(void); -void yyset_debug (int debug_flag ); +void yyset_debug(int debug_flag); -YY_EXTRA_TYPE yyget_extra (void ); +YY_EXTRA_TYPE yyget_extra(void); -void yyset_extra (YY_EXTRA_TYPE user_defined ); +void yyset_extra(YY_EXTRA_TYPE user_defined); -FILE *yyget_in (void ); +FILE *yyget_in(void); -void yyset_in (FILE * in_str ); +void yyset_in(FILE *in_str); -FILE *yyget_out (void ); +FILE *yyget_out(void); -void yyset_out (FILE * out_str ); +void yyset_out(FILE *out_str); -yy_size_t yyget_leng (void ); +yy_size_t yyget_leng(void); -char *yyget_text (void ); +char *yyget_text(void); -int yyget_lineno (void ); +int yyget_lineno(void); -void yyset_lineno (int line_number ); +void yyset_lineno(int line_number); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -1243,28 +1146,28 @@ void yyset_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap (void ); +extern "C" int yywrap(void); #else -extern int yywrap (void ); +extern int yywrap(void); #endif #endif - static void yyunput (int c,char *buf_ptr ); - +static void yyunput(int c, char *buf_ptr); + #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy(char *, yyconst char *, int); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen(yyconst char *); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput (void ); +static int yyinput(void); #else -static int input (void ); +static int input(void); #endif #endif @@ -1284,44 +1187,44 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO \ + do { \ + if (fwrite(yytext, yyleng, 1, yyout)) { \ + } \ + } while (0) #endif -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, +/* Gets input and stuffs it into "buf". number of characters read, or + * YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif +#define YY_INPUT(buf, result, max_size) \ + if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) { \ + int c = '*'; \ + size_t n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; \ + ++n) \ + buf[n] = (char) c; \ + if (c == '\n') \ + buf[n++] = (char) c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } else { \ + errno = 0; \ + while ((result = fread(buf, 1, max_size, yyin)) == 0 \ + && ferror(yyin)) { \ + if (errno != EINTR) { \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + break; \ + } \ + errno = 0; \ + clearerr(yyin); \ + } \ + } \ + \ + #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause @@ -1338,7 +1241,7 @@ static int input (void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg) #endif /* end tables serialization structures and prototypes */ @@ -1349,9 +1252,9 @@ static int input (void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex(void); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex(void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1366,1272 +1269,1651 @@ extern int yylex (void); #define YY_BREAK break; #endif -#define YY_RULE_SETUP \ - if ( yyleng > 0 ) \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ - (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION +#define YY_RULE_SETUP \ + if (yyleng > 0) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + + if (!(yy_init)) { + (yy_init) = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if (!(yy_start)) + (yy_start) = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) + yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) + yyout = stdout; - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } + if (!YY_CURRENT_BUFFER) { + yyensure_buffer_stack(); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); + } - yy_load_buffer_state( ); - } + yy_load_buffer_state(); + } - { + { #line 105 "lev_comp.l" #line 1413 "lex.yy.c" - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); + while (1) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); - /* Support of yytext. */ - *yy_cp = (yy_hold_char); + /* Support of yytext. */ + *yy_cp = (yy_hold_char); - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1038 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 1236 ); + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + yy_match: + do { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] + != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 1038) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } while (yy_base[yy_current_state] != 1236); -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } + yy_find_action: + yy_act = yy_accept[yy_current_state]; + if (yy_act == 0) { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } - YY_DO_BEFORE_ACTION; + YY_DO_BEFORE_ACTION; -do_action: /* This label is used only to access EOF actions. */ + do_action: /* This label is used only to access EOF actions. */ - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; + switch (yy_act) { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; -case 1: -YY_RULE_SETUP + case 1: + YY_RULE_SETUP #line 106 "lev_comp.l" -{ - savetoken(yytext); - BEGIN(INITIAL); - yylval.map = (char *) alloc(map_cnt + 1); - (void) strncpy(yylval.map, map, map_cnt); - yylval.map[map_cnt] = 0; - map_cnt = 0; - return MAP_ID; - } - YY_BREAK -case 2: -/* rule 2 can match eol */ -YY_RULE_SETUP + { + savetoken(yytext); + BEGIN(INITIAL); + yylval.map = (char *) alloc(map_cnt + 1); + (void) strncpy(yylval.map, map, map_cnt); + yylval.map[map_cnt] = 0; + map_cnt = 0; + return MAP_ID; + } + YY_BREAK + case 2: + /* rule 2 can match eol */ + YY_RULE_SETUP #line 115 "lev_comp.l" -{ - int len = yyleng; - savetoken(yytext); - /* convert \r\n to \n */ - if (len >= 2 && yytext[len - 2] == '\r') len -= 1; - (void) strncpy(map + map_cnt, yytext, len); - map_cnt += len; - map[map_cnt - 1] = '\n'; - map[map_cnt] = '\0'; - newline(); - } - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP + { + int len = yyleng; + savetoken(yytext); + /* convert \r\n to \n */ + if (len >= 2 && yytext[len - 2] == '\r') + len -= 1; + (void) strncpy(map + map_cnt, yytext, len); + map_cnt += len; + map[map_cnt - 1] = '\n'; + map[map_cnt] = '\0'; + newline(); + } + YY_BREAK + case 3: + /* rule 3 can match eol */ + YY_RULE_SETUP #line 126 "lev_comp.l" -{ savetoken(yytext); newline(); } - YY_BREAK -case 4: -YY_RULE_SETUP + { + savetoken(yytext); + newline(); + } + YY_BREAK + case 4: + YY_RULE_SETUP #line 127 "lev_comp.l" -ST_RET(MESSAGE_ID); - YY_BREAK -case 5: -YY_RULE_SETUP + ST_RET(MESSAGE_ID); + YY_BREAK + case 5: + YY_RULE_SETUP #line 128 "lev_comp.l" -ST_RET(NOMAP_ID); - YY_BREAK -case 6: -YY_RULE_SETUP + ST_RET(NOMAP_ID); + YY_BREAK + case 6: + YY_RULE_SETUP #line 129 "lev_comp.l" -ST_RET(MAZE_ID); - YY_BREAK -case 7: -YY_RULE_SETUP + ST_RET(MAZE_ID); + YY_BREAK + case 7: + YY_RULE_SETUP #line 130 "lev_comp.l" -ST_RET(LEVEL_ID); - YY_BREAK -case 8: -YY_RULE_SETUP + ST_RET(LEVEL_ID); + YY_BREAK + case 8: + YY_RULE_SETUP #line 131 "lev_comp.l" -ST_RET(LEV_INIT_ID); - YY_BREAK -case 9: -YY_RULE_SETUP + ST_RET(LEV_INIT_ID); + YY_BREAK + case 9: + YY_RULE_SETUP #line 132 "lev_comp.l" -ST_RET(MAZE_GRID_ID); - YY_BREAK -case 10: -YY_RULE_SETUP + ST_RET(MAZE_GRID_ID); + YY_BREAK + case 10: + YY_RULE_SETUP #line 133 "lev_comp.l" -ST_RET(SOLID_FILL_ID); - YY_BREAK -case 11: -YY_RULE_SETUP + ST_RET(SOLID_FILL_ID); + YY_BREAK + case 11: + YY_RULE_SETUP #line 134 "lev_comp.l" -ST_RET(MINES_ID); - YY_BREAK -case 12: -YY_RULE_SETUP + ST_RET(MINES_ID); + YY_BREAK + case 12: + YY_RULE_SETUP #line 135 "lev_comp.l" -ST_RET(ROGUELEV_ID); - YY_BREAK -case 13: -YY_RULE_SETUP + ST_RET(ROGUELEV_ID); + YY_BREAK + case 13: + YY_RULE_SETUP #line 136 "lev_comp.l" -ST_RET(FLAGS_ID); - YY_BREAK -case 14: -YY_RULE_SETUP + ST_RET(FLAGS_ID); + YY_BREAK + case 14: + YY_RULE_SETUP #line 137 "lev_comp.l" -ST_RET(GEOMETRY_ID); - YY_BREAK -case 15: -/* rule 15 can match eol */ -YY_RULE_SETUP + ST_RET(GEOMETRY_ID); + YY_BREAK + case 15: + /* rule 15 can match eol */ + YY_RULE_SETUP #line 138 "lev_comp.l" -{ savetoken(yytext); BEGIN(MAPC); newline(); } - YY_BREAK -case 16: -YY_RULE_SETUP + { + savetoken(yytext); + BEGIN(MAPC); + newline(); + } + YY_BREAK + case 16: + YY_RULE_SETUP #line 139 "lev_comp.l" -ST_RET(object_ID); - YY_BREAK -case 17: -YY_RULE_SETUP + ST_RET(object_ID); + YY_BREAK + case 17: + YY_RULE_SETUP #line 140 "lev_comp.l" -ST_RET(OBJECT_ID); - YY_BREAK -case 18: -YY_RULE_SETUP + ST_RET(OBJECT_ID); + YY_BREAK + case 18: + YY_RULE_SETUP #line 141 "lev_comp.l" -ST_RET(COBJECT_ID); - YY_BREAK -case 19: -YY_RULE_SETUP + ST_RET(COBJECT_ID); + YY_BREAK + case 19: + YY_RULE_SETUP #line 142 "lev_comp.l" -ST_RET(MONSTER_ID); - YY_BREAK -case 20: -YY_RULE_SETUP + ST_RET(MONSTER_ID); + YY_BREAK + case 20: + YY_RULE_SETUP #line 143 "lev_comp.l" -ST_RET(monster_ID); - YY_BREAK -case 21: -YY_RULE_SETUP + ST_RET(monster_ID); + YY_BREAK + case 21: + YY_RULE_SETUP #line 144 "lev_comp.l" -ST_RET(TRAP_ID); - YY_BREAK -case 22: -YY_RULE_SETUP + ST_RET(TRAP_ID); + YY_BREAK + case 22: + YY_RULE_SETUP #line 145 "lev_comp.l" -ST_RET(DOOR_ID); - YY_BREAK -case 23: -YY_RULE_SETUP + ST_RET(DOOR_ID); + YY_BREAK + case 23: + YY_RULE_SETUP #line 146 "lev_comp.l" -ST_RET(ROOMDOOR_ID); - YY_BREAK -case 24: -YY_RULE_SETUP + ST_RET(ROOMDOOR_ID); + YY_BREAK + case 24: + YY_RULE_SETUP #line 147 "lev_comp.l" -ST_RET(DRAWBRIDGE_ID); - YY_BREAK -case 25: -YY_RULE_SETUP + ST_RET(DRAWBRIDGE_ID); + YY_BREAK + case 25: + YY_RULE_SETUP #line 148 "lev_comp.l" -ST_RET(MAZEWALK_ID); - YY_BREAK -case 26: -YY_RULE_SETUP + ST_RET(MAZEWALK_ID); + YY_BREAK + case 26: + YY_RULE_SETUP #line 149 "lev_comp.l" -ST_RET(WALLIFY_ID); - YY_BREAK -case 27: -YY_RULE_SETUP + ST_RET(WALLIFY_ID); + YY_BREAK + case 27: + YY_RULE_SETUP #line 150 "lev_comp.l" -ST_RET(REGION_ID); - YY_BREAK -case 28: -YY_RULE_SETUP + ST_RET(REGION_ID); + YY_BREAK + case 28: + YY_RULE_SETUP #line 151 "lev_comp.l" -ST_RET(ALTAR_ID); - YY_BREAK -case 29: -YY_RULE_SETUP + ST_RET(ALTAR_ID); + YY_BREAK + case 29: + YY_RULE_SETUP #line 152 "lev_comp.l" -ST_RET(LADDER_ID); - YY_BREAK -case 30: -YY_RULE_SETUP + ST_RET(LADDER_ID); + YY_BREAK + case 30: + YY_RULE_SETUP #line 153 "lev_comp.l" -ST_RET(STAIR_ID); - YY_BREAK -case 31: -YY_RULE_SETUP + ST_RET(STAIR_ID); + YY_BREAK + case 31: + YY_RULE_SETUP #line 154 "lev_comp.l" -ST_RET(PORTAL_ID); - YY_BREAK -case 32: -YY_RULE_SETUP + ST_RET(PORTAL_ID); + YY_BREAK + case 32: + YY_RULE_SETUP #line 155 "lev_comp.l" -ST_RET(TELEPRT_ID); - YY_BREAK -case 33: -YY_RULE_SETUP + ST_RET(TELEPRT_ID); + YY_BREAK + case 33: + YY_RULE_SETUP #line 156 "lev_comp.l" -ST_RET(BRANCH_ID); - YY_BREAK -case 34: -YY_RULE_SETUP + ST_RET(BRANCH_ID); + YY_BREAK + case 34: + YY_RULE_SETUP #line 157 "lev_comp.l" -ST_RET(FOUNTAIN_ID); - YY_BREAK -case 35: -YY_RULE_SETUP + ST_RET(FOUNTAIN_ID); + YY_BREAK + case 35: + YY_RULE_SETUP #line 158 "lev_comp.l" -ST_RET(SINK_ID); - YY_BREAK -case 36: -YY_RULE_SETUP + ST_RET(SINK_ID); + YY_BREAK + case 36: + YY_RULE_SETUP #line 159 "lev_comp.l" -ST_RET(POOL_ID); - YY_BREAK -case 37: -YY_RULE_SETUP + ST_RET(POOL_ID); + YY_BREAK + case 37: + YY_RULE_SETUP #line 160 "lev_comp.l" -ST_RET(NON_DIGGABLE_ID); - YY_BREAK -case 38: -YY_RULE_SETUP + ST_RET(NON_DIGGABLE_ID); + YY_BREAK + case 38: + YY_RULE_SETUP #line 161 "lev_comp.l" -ST_RET(NON_PASSWALL_ID); - YY_BREAK -case 39: -YY_RULE_SETUP + ST_RET(NON_PASSWALL_ID); + YY_BREAK + case 39: + YY_RULE_SETUP #line 162 "lev_comp.l" -ST_RET(IF_ID); - YY_BREAK -case 40: -YY_RULE_SETUP + ST_RET(IF_ID); + YY_BREAK + case 40: + YY_RULE_SETUP #line 163 "lev_comp.l" -ST_RET(ELSE_ID); - YY_BREAK -case 41: -YY_RULE_SETUP + ST_RET(ELSE_ID); + YY_BREAK + case 41: + YY_RULE_SETUP #line 164 "lev_comp.l" -ST_RET(EXIT_ID); - YY_BREAK -case 42: -YY_RULE_SETUP + ST_RET(EXIT_ID); + YY_BREAK + case 42: + YY_RULE_SETUP #line 165 "lev_comp.l" -ST_RET(ROOM_ID); - YY_BREAK -case 43: -YY_RULE_SETUP + ST_RET(ROOM_ID); + YY_BREAK + case 43: + YY_RULE_SETUP #line 166 "lev_comp.l" -ST_RET(SUBROOM_ID); - YY_BREAK -case 44: -YY_RULE_SETUP + ST_RET(SUBROOM_ID); + YY_BREAK + case 44: + YY_RULE_SETUP #line 167 "lev_comp.l" -ST_RET(RAND_CORRIDOR_ID); - YY_BREAK -case 45: -YY_RULE_SETUP + ST_RET(RAND_CORRIDOR_ID); + YY_BREAK + case 45: + YY_RULE_SETUP #line 168 "lev_comp.l" -ST_RET(CORRIDOR_ID); - YY_BREAK -case 46: -YY_RULE_SETUP + ST_RET(CORRIDOR_ID); + YY_BREAK + case 46: + YY_RULE_SETUP #line 169 "lev_comp.l" -ST_RET(TERRAIN_ID); - YY_BREAK -case 47: -YY_RULE_SETUP + ST_RET(TERRAIN_ID); + YY_BREAK + case 47: + YY_RULE_SETUP #line 170 "lev_comp.l" -ST_RET(terrain_ID); - YY_BREAK -case 48: -YY_RULE_SETUP + ST_RET(terrain_ID); + YY_BREAK + case 48: + YY_RULE_SETUP #line 171 "lev_comp.l" -ST_RET(REPLACE_TERRAIN_ID); - YY_BREAK -case 49: -YY_RULE_SETUP + ST_RET(REPLACE_TERRAIN_ID); + YY_BREAK + case 49: + YY_RULE_SETUP #line 172 "lev_comp.l" -ST_RET(GOLD_ID); - YY_BREAK -case 50: -YY_RULE_SETUP + ST_RET(GOLD_ID); + YY_BREAK + case 50: + YY_RULE_SETUP #line 173 "lev_comp.l" -ST_RET(GRAVE_ID); - YY_BREAK -case 51: -YY_RULE_SETUP + ST_RET(GRAVE_ID); + YY_BREAK + case 51: + YY_RULE_SETUP #line 174 "lev_comp.l" -ST_RET(ENGRAVING_ID); - YY_BREAK -case 52: -YY_RULE_SETUP + ST_RET(ENGRAVING_ID); + YY_BREAK + case 52: + YY_RULE_SETUP #line 175 "lev_comp.l" -ST_RET(MINERALIZE_ID); - YY_BREAK -case 53: -YY_RULE_SETUP + ST_RET(MINERALIZE_ID); + YY_BREAK + case 53: + YY_RULE_SETUP #line 176 "lev_comp.l" -ST_RET(NAME_ID); - YY_BREAK -case 54: -YY_RULE_SETUP + ST_RET(NAME_ID); + YY_BREAK + case 54: + YY_RULE_SETUP #line 177 "lev_comp.l" -ST_RET(FOR_ID); - YY_BREAK -case 55: -YY_RULE_SETUP + ST_RET(FOR_ID); + YY_BREAK + case 55: + YY_RULE_SETUP #line 178 "lev_comp.l" -ST_RET(TO_ID); - YY_BREAK -case 56: -YY_RULE_SETUP + ST_RET(TO_ID); + YY_BREAK + case 56: + YY_RULE_SETUP #line 179 "lev_comp.l" -ST_RET(LOOP_ID); - YY_BREAK -case 57: -YY_RULE_SETUP + ST_RET(LOOP_ID); + YY_BREAK + case 57: + YY_RULE_SETUP #line 180 "lev_comp.l" -ST_RET(SWITCH_ID); - YY_BREAK -case 58: -YY_RULE_SETUP + ST_RET(SWITCH_ID); + YY_BREAK + case 58: + YY_RULE_SETUP #line 181 "lev_comp.l" -ST_RET(CASE_ID); - YY_BREAK -case 59: -YY_RULE_SETUP + ST_RET(CASE_ID); + YY_BREAK + case 59: + YY_RULE_SETUP #line 182 "lev_comp.l" -ST_RET(BREAK_ID); - YY_BREAK -case 60: -YY_RULE_SETUP + ST_RET(BREAK_ID); + YY_BREAK + case 60: + YY_RULE_SETUP #line 183 "lev_comp.l" -ST_RET(DEFAULT_ID); - YY_BREAK -case 61: -YY_RULE_SETUP + ST_RET(DEFAULT_ID); + YY_BREAK + case 61: + YY_RULE_SETUP #line 184 "lev_comp.l" -ST_RET(FUNCTION_ID); - YY_BREAK -case 62: -YY_RULE_SETUP + ST_RET(FUNCTION_ID); + YY_BREAK + case 62: + YY_RULE_SETUP #line 185 "lev_comp.l" -ST_RET(SHUFFLE_ID); - YY_BREAK -case 63: -YY_RULE_SETUP + ST_RET(SHUFFLE_ID); + YY_BREAK + case 63: + YY_RULE_SETUP #line 186 "lev_comp.l" -ST_RET(MONTYPE_ID); - YY_BREAK -case 64: -YY_RULE_SETUP + ST_RET(MONTYPE_ID); + YY_BREAK + case 64: + YY_RULE_SETUP #line 187 "lev_comp.l" -ST_RET(selection_ID); - YY_BREAK -case 65: -YY_RULE_SETUP + ST_RET(selection_ID); + YY_BREAK + case 65: + YY_RULE_SETUP #line 188 "lev_comp.l" -ST_RET(rect_ID); - YY_BREAK -case 66: -YY_RULE_SETUP + ST_RET(rect_ID); + YY_BREAK + case 66: + YY_RULE_SETUP #line 189 "lev_comp.l" -ST_RET(fillrect_ID); - YY_BREAK -case 67: -YY_RULE_SETUP + ST_RET(fillrect_ID); + YY_BREAK + case 67: + YY_RULE_SETUP #line 190 "lev_comp.l" -ST_RET(line_ID); - YY_BREAK -case 68: -YY_RULE_SETUP + ST_RET(line_ID); + YY_BREAK + case 68: + YY_RULE_SETUP #line 191 "lev_comp.l" -ST_RET(randline_ID); - YY_BREAK -case 69: -YY_RULE_SETUP + ST_RET(randline_ID); + YY_BREAK + case 69: + YY_RULE_SETUP #line 192 "lev_comp.l" -ST_RET(grow_ID); - YY_BREAK -case 70: -YY_RULE_SETUP + ST_RET(grow_ID); + YY_BREAK + case 70: + YY_RULE_SETUP #line 193 "lev_comp.l" -ST_RET(flood_ID); - YY_BREAK -case 71: -YY_RULE_SETUP + ST_RET(flood_ID); + YY_BREAK + case 71: + YY_RULE_SETUP #line 194 "lev_comp.l" -ST_RET(rndcoord_ID); - YY_BREAK -case 72: -YY_RULE_SETUP + ST_RET(rndcoord_ID); + YY_BREAK + case 72: + YY_RULE_SETUP #line 195 "lev_comp.l" -ST_RET(circle_ID); - YY_BREAK -case 73: -YY_RULE_SETUP + ST_RET(circle_ID); + YY_BREAK + case 73: + YY_RULE_SETUP #line 196 "lev_comp.l" -ST_RET(ellipse_ID); - YY_BREAK -case 74: -YY_RULE_SETUP + ST_RET(ellipse_ID); + YY_BREAK + case 74: + YY_RULE_SETUP #line 197 "lev_comp.l" -ST_RET(filter_ID); - YY_BREAK -case 75: -YY_RULE_SETUP + ST_RET(filter_ID); + YY_BREAK + case 75: + YY_RULE_SETUP #line 198 "lev_comp.l" -ST_RET(gradient_ID); - YY_BREAK -case 76: -YY_RULE_SETUP + ST_RET(gradient_ID); + YY_BREAK + case 76: + YY_RULE_SETUP #line 199 "lev_comp.l" -ST_RET(complement_ID); - YY_BREAK -case 77: -YY_RULE_SETUP + ST_RET(complement_ID); + YY_BREAK + case 77: + YY_RULE_SETUP #line 200 "lev_comp.l" -{ savetoken(yytext); yylval.i=SEL_GRADIENT_RADIAL; return GRADIENT_TYPE; } - YY_BREAK -case 78: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SEL_GRADIENT_RADIAL; + return GRADIENT_TYPE; + } + YY_BREAK + case 78: + YY_RULE_SETUP #line 201 "lev_comp.l" -{ savetoken(yytext); yylval.i=SEL_GRADIENT_SQUARE; return GRADIENT_TYPE; } - YY_BREAK -case 79: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SEL_GRADIENT_SQUARE; + return GRADIENT_TYPE; + } + YY_BREAK + case 79: + YY_RULE_SETUP #line 202 "lev_comp.l" -{ savetoken(yytext); yylval.i=DRY; return HUMIDITY_TYPE; } - YY_BREAK -case 80: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = DRY; + return HUMIDITY_TYPE; + } + YY_BREAK + case 80: + YY_RULE_SETUP #line 203 "lev_comp.l" -{ savetoken(yytext); yylval.i=WET; return HUMIDITY_TYPE; } - YY_BREAK -case 81: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = WET; + return HUMIDITY_TYPE; + } + YY_BREAK + case 81: + YY_RULE_SETUP #line 204 "lev_comp.l" -{ savetoken(yytext); yylval.i=HOT; return HUMIDITY_TYPE; } - YY_BREAK -case 82: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = HOT; + return HUMIDITY_TYPE; + } + YY_BREAK + case 82: + YY_RULE_SETUP #line 205 "lev_comp.l" -{ savetoken(yytext); yylval.i=SOLID; return HUMIDITY_TYPE; } - YY_BREAK -case 83: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SOLID; + return HUMIDITY_TYPE; + } + YY_BREAK + case 83: + YY_RULE_SETUP #line 206 "lev_comp.l" -{ savetoken(yytext); yylval.i=ANY_LOC; return HUMIDITY_TYPE; } - YY_BREAK -case 84: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = ANY_LOC; + return HUMIDITY_TYPE; + } + YY_BREAK + case 84: + YY_RULE_SETUP #line 207 "lev_comp.l" -ST_RET(LEV); - YY_BREAK -case 85: -YY_RULE_SETUP + ST_RET(LEV); + YY_BREAK + case 85: + YY_RULE_SETUP #line 208 "lev_comp.l" -ST_RET(QUANTITY_ID); - YY_BREAK -case 86: -YY_RULE_SETUP + ST_RET(QUANTITY_ID); + YY_BREAK + case 86: + YY_RULE_SETUP #line 209 "lev_comp.l" -ST_RET(BURIED_ID); - YY_BREAK -case 87: -YY_RULE_SETUP + ST_RET(BURIED_ID); + YY_BREAK + case 87: + YY_RULE_SETUP #line 210 "lev_comp.l" -ST_RET(ERODED_ID); - YY_BREAK -case 88: -YY_RULE_SETUP + ST_RET(ERODED_ID); + YY_BREAK + case 88: + YY_RULE_SETUP #line 211 "lev_comp.l" -ST_RET(ERODEPROOF_ID); - YY_BREAK -case 89: -YY_RULE_SETUP + ST_RET(ERODEPROOF_ID); + YY_BREAK + case 89: + YY_RULE_SETUP #line 212 "lev_comp.l" -ST_RET(TRAPPED_ID); - YY_BREAK -case 90: -YY_RULE_SETUP + ST_RET(TRAPPED_ID); + YY_BREAK + case 90: + YY_RULE_SETUP #line 213 "lev_comp.l" -ST_RET(RECHARGED_ID); - YY_BREAK -case 91: -YY_RULE_SETUP + ST_RET(RECHARGED_ID); + YY_BREAK + case 91: + YY_RULE_SETUP #line 214 "lev_comp.l" -ST_RET(INVIS_ID); - YY_BREAK -case 92: -YY_RULE_SETUP + ST_RET(INVIS_ID); + YY_BREAK + case 92: + YY_RULE_SETUP #line 215 "lev_comp.l" -ST_RET(GREASED_ID); - YY_BREAK -case 93: -YY_RULE_SETUP + ST_RET(GREASED_ID); + YY_BREAK + case 93: + YY_RULE_SETUP #line 216 "lev_comp.l" -ST_RET(FEMALE_ID); - YY_BREAK -case 94: -YY_RULE_SETUP + ST_RET(FEMALE_ID); + YY_BREAK + case 94: + YY_RULE_SETUP #line 217 "lev_comp.l" -ST_RET(CANCELLED_ID); - YY_BREAK -case 95: -YY_RULE_SETUP + ST_RET(CANCELLED_ID); + YY_BREAK + case 95: + YY_RULE_SETUP #line 218 "lev_comp.l" -ST_RET(REVIVED_ID); - YY_BREAK -case 96: -YY_RULE_SETUP + ST_RET(REVIVED_ID); + YY_BREAK + case 96: + YY_RULE_SETUP #line 219 "lev_comp.l" -ST_RET(AVENGE_ID); - YY_BREAK -case 97: -YY_RULE_SETUP + ST_RET(AVENGE_ID); + YY_BREAK + case 97: + YY_RULE_SETUP #line 220 "lev_comp.l" -ST_RET(FLEEING_ID); - YY_BREAK -case 98: -YY_RULE_SETUP + ST_RET(FLEEING_ID); + YY_BREAK + case 98: + YY_RULE_SETUP #line 221 "lev_comp.l" -ST_RET(BLINDED_ID); - YY_BREAK -case 99: -YY_RULE_SETUP + ST_RET(BLINDED_ID); + YY_BREAK + case 99: + YY_RULE_SETUP #line 222 "lev_comp.l" -ST_RET(PARALYZED_ID); - YY_BREAK -case 100: -YY_RULE_SETUP + ST_RET(PARALYZED_ID); + YY_BREAK + case 100: + YY_RULE_SETUP #line 223 "lev_comp.l" -ST_RET(STUNNED_ID); - YY_BREAK -case 101: -YY_RULE_SETUP + ST_RET(STUNNED_ID); + YY_BREAK + case 101: + YY_RULE_SETUP #line 224 "lev_comp.l" -ST_RET(CONFUSED_ID); - YY_BREAK -case 102: -YY_RULE_SETUP + ST_RET(CONFUSED_ID); + YY_BREAK + case 102: + YY_RULE_SETUP #line 225 "lev_comp.l" -ST_RET(SEENTRAPS_ID); - YY_BREAK -case 103: -YY_RULE_SETUP + ST_RET(SEENTRAPS_ID); + YY_BREAK + case 103: + YY_RULE_SETUP #line 226 "lev_comp.l" -ST_RET(ALL_ID); - YY_BREAK -case 104: -YY_RULE_SETUP + ST_RET(ALL_ID); + YY_BREAK + case 104: + YY_RULE_SETUP #line 227 "lev_comp.l" -ST_RETF((yylval.i=1), HORIZ_OR_VERT); - YY_BREAK -case 105: -YY_RULE_SETUP + ST_RETF((yylval.i = 1), HORIZ_OR_VERT); + YY_BREAK + case 105: + YY_RULE_SETUP #line 228 "lev_comp.l" -{ savetoken(yytext); yylval.i=2; return HORIZ_OR_VERT; } - YY_BREAK -case 106: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 2; + return HORIZ_OR_VERT; + } + YY_BREAK + case 106: + YY_RULE_SETUP #line 229 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_ISOPEN; return DOOR_STATE; } - YY_BREAK -case 107: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_ISOPEN; + return DOOR_STATE; + } + YY_BREAK + case 107: + YY_RULE_SETUP #line 230 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_CLOSED; return DOOR_STATE; } - YY_BREAK -case 108: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_CLOSED; + return DOOR_STATE; + } + YY_BREAK + case 108: + YY_RULE_SETUP #line 231 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_LOCKED; return DOOR_STATE; } - YY_BREAK -case 109: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_LOCKED; + return DOOR_STATE; + } + YY_BREAK + case 109: + YY_RULE_SETUP #line 232 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_NODOOR; return DOOR_STATE; } - YY_BREAK -case 110: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_NODOOR; + return DOOR_STATE; + } + YY_BREAK + case 110: + YY_RULE_SETUP #line 233 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_BROKEN; return DOOR_STATE; } - YY_BREAK -case 111: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_BROKEN; + return DOOR_STATE; + } + YY_BREAK + case 111: + YY_RULE_SETUP #line 234 "lev_comp.l" -{ savetoken(yytext); yylval.i=D_SECRET; return DOOR_STATE; } - YY_BREAK -case 112: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = D_SECRET; + return DOOR_STATE; + } + YY_BREAK + case 112: + YY_RULE_SETUP #line 235 "lev_comp.l" -{ savetoken(yytext); yylval.i=W_NORTH; return DIRECTION; } - YY_BREAK -case 113: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = W_NORTH; + return DIRECTION; + } + YY_BREAK + case 113: + YY_RULE_SETUP #line 236 "lev_comp.l" -{ savetoken(yytext); yylval.i=W_EAST; return DIRECTION; } - YY_BREAK -case 114: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = W_EAST; + return DIRECTION; + } + YY_BREAK + case 114: + YY_RULE_SETUP #line 237 "lev_comp.l" -{ savetoken(yytext); yylval.i=W_SOUTH; return DIRECTION; } - YY_BREAK -case 115: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = W_SOUTH; + return DIRECTION; + } + YY_BREAK + case 115: + YY_RULE_SETUP #line 238 "lev_comp.l" -{ savetoken(yytext); yylval.i=W_WEST; return DIRECTION; } - YY_BREAK -case 116: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = W_WEST; + return DIRECTION; + } + YY_BREAK + case 116: + YY_RULE_SETUP #line 239 "lev_comp.l" -{ savetoken(yytext); yylval.i = -1; return RANDOM_TYPE; } - YY_BREAK -case 117: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = -1; + return RANDOM_TYPE; + } + YY_BREAK + case 117: + YY_RULE_SETUP #line 240 "lev_comp.l" -{ savetoken(yytext); yylval.i = -1; return RANDOM_TYPE_BRACKET; } - YY_BREAK -case 118: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = -1; + return RANDOM_TYPE_BRACKET; + } + YY_BREAK + case 118: + YY_RULE_SETUP #line 241 "lev_comp.l" -{ savetoken(yytext); yylval.i = -2; return NONE; } - YY_BREAK -case 119: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = -2; + return NONE; + } + YY_BREAK + case 119: + YY_RULE_SETUP #line 242 "lev_comp.l" -ST_RET(A_REGISTER); - YY_BREAK -case 120: -YY_RULE_SETUP + ST_RET(A_REGISTER); + YY_BREAK + case 120: + YY_RULE_SETUP #line 243 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return LEFT_OR_RIGHT; } - YY_BREAK -case 121: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return LEFT_OR_RIGHT; + } + YY_BREAK + case 121: + YY_RULE_SETUP #line 244 "lev_comp.l" -{ savetoken(yytext); yylval.i=2; return LEFT_OR_RIGHT; } - YY_BREAK -case 122: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 2; + return LEFT_OR_RIGHT; + } + YY_BREAK + case 122: + YY_RULE_SETUP #line 245 "lev_comp.l" -{ savetoken(yytext); yylval.i=3; return CENTER; } - YY_BREAK -case 123: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 3; + return CENTER; + } + YY_BREAK + case 123: + YY_RULE_SETUP #line 246 "lev_comp.l" -{ savetoken(yytext); yylval.i=4; return LEFT_OR_RIGHT; } - YY_BREAK -case 124: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 4; + return LEFT_OR_RIGHT; + } + YY_BREAK + case 124: + YY_RULE_SETUP #line 247 "lev_comp.l" -{ savetoken(yytext); yylval.i=5; return LEFT_OR_RIGHT; } - YY_BREAK -case 125: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 5; + return LEFT_OR_RIGHT; + } + YY_BREAK + case 125: + YY_RULE_SETUP #line 248 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return TOP_OR_BOT; } - YY_BREAK -case 126: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return TOP_OR_BOT; + } + YY_BREAK + case 126: + YY_RULE_SETUP #line 249 "lev_comp.l" -{ savetoken(yytext); yylval.i=5; return TOP_OR_BOT; } - YY_BREAK -case 127: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 5; + return TOP_OR_BOT; + } + YY_BREAK + case 127: + YY_RULE_SETUP #line 250 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return LIGHT_STATE; } - YY_BREAK -case 128: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return LIGHT_STATE; + } + YY_BREAK + case 128: + YY_RULE_SETUP #line 251 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return LIGHT_STATE; } - YY_BREAK -case 129: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return LIGHT_STATE; + } + YY_BREAK + case 129: + YY_RULE_SETUP #line 252 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return FILLING; } - YY_BREAK -case 130: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return FILLING; + } + YY_BREAK + case 130: + YY_RULE_SETUP #line 253 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return FILLING; } - YY_BREAK -case 131: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return FILLING; + } + YY_BREAK + case 131: + YY_RULE_SETUP #line 254 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return IRREGULAR; } - YY_BREAK -case 132: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return IRREGULAR; + } + YY_BREAK + case 132: + YY_RULE_SETUP #line 255 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return IRREGULAR; } - YY_BREAK -case 133: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return IRREGULAR; + } + YY_BREAK + case 133: + YY_RULE_SETUP #line 256 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return JOINED; } - YY_BREAK -case 134: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return JOINED; + } + YY_BREAK + case 134: + YY_RULE_SETUP #line 257 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return JOINED; } - YY_BREAK -case 135: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return JOINED; + } + YY_BREAK + case 135: + YY_RULE_SETUP #line 258 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return LIMITED; } - YY_BREAK -case 136: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return LIMITED; + } + YY_BREAK + case 136: + YY_RULE_SETUP #line 259 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return LIMITED; } - YY_BREAK -case 137: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return LIMITED; + } + YY_BREAK + case 137: + YY_RULE_SETUP #line 260 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_NONE; return ALIGNMENT; } - YY_BREAK -case 138: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_NONE; + return ALIGNMENT; + } + YY_BREAK + case 138: + YY_RULE_SETUP #line 261 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_LAWFUL; return ALIGNMENT; } - YY_BREAK -case 139: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_LAWFUL; + return ALIGNMENT; + } + YY_BREAK + case 139: + YY_RULE_SETUP #line 262 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_NEUTRAL; return ALIGNMENT; } - YY_BREAK -case 140: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_NEUTRAL; + return ALIGNMENT; + } + YY_BREAK + case 140: + YY_RULE_SETUP #line 263 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_CHAOTIC; return ALIGNMENT; } - YY_BREAK -case 141: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_CHAOTIC; + return ALIGNMENT; + } + YY_BREAK + case 141: + YY_RULE_SETUP #line 264 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_SPLEV_CO; return ALIGNMENT; } - YY_BREAK -case 142: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_SPLEV_CO; + return ALIGNMENT; + } + YY_BREAK + case 142: + YY_RULE_SETUP #line 265 "lev_comp.l" -{ savetoken(yytext); yylval.i= AM_SPLEV_NONCO; return ALIGNMENT; } - YY_BREAK -case 143: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = AM_SPLEV_NONCO; + return ALIGNMENT; + } + YY_BREAK + case 143: + YY_RULE_SETUP #line 266 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return MON_ATTITUDE; } - YY_BREAK -case 144: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return MON_ATTITUDE; + } + YY_BREAK + case 144: + YY_RULE_SETUP #line 267 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return MON_ATTITUDE; } - YY_BREAK -case 145: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return MON_ATTITUDE; + } + YY_BREAK + case 145: + YY_RULE_SETUP #line 268 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return MON_ALERTNESS; } - YY_BREAK -case 146: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return MON_ALERTNESS; + } + YY_BREAK + case 146: + YY_RULE_SETUP #line 269 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return MON_ALERTNESS; } - YY_BREAK -case 147: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return MON_ALERTNESS; + } + YY_BREAK + case 147: + YY_RULE_SETUP #line 270 "lev_comp.l" -{ savetoken(yytext); yylval.i= M_AP_FURNITURE; return MON_APPEARANCE; } - YY_BREAK -case 148: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = M_AP_FURNITURE; + return MON_APPEARANCE; + } + YY_BREAK + case 148: + YY_RULE_SETUP #line 271 "lev_comp.l" -{ savetoken(yytext); yylval.i= M_AP_MONSTER; return MON_APPEARANCE; } - YY_BREAK -case 149: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = M_AP_MONSTER; + return MON_APPEARANCE; + } + YY_BREAK + case 149: + YY_RULE_SETUP #line 272 "lev_comp.l" -{ savetoken(yytext); yylval.i= M_AP_OBJECT; return MON_APPEARANCE; } - YY_BREAK -case 150: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = M_AP_OBJECT; + return MON_APPEARANCE; + } + YY_BREAK + case 150: + YY_RULE_SETUP #line 273 "lev_comp.l" -{ savetoken(yytext); yylval.i=2; return ALTAR_TYPE; } - YY_BREAK -case 151: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 2; + return ALTAR_TYPE; + } + YY_BREAK + case 151: + YY_RULE_SETUP #line 274 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return ALTAR_TYPE; } - YY_BREAK -case 152: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return ALTAR_TYPE; + } + YY_BREAK + case 152: + YY_RULE_SETUP #line 275 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return ALTAR_TYPE; } - YY_BREAK -case 153: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return ALTAR_TYPE; + } + YY_BREAK + case 153: + YY_RULE_SETUP #line 276 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return UP_OR_DOWN; } - YY_BREAK -case 154: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return UP_OR_DOWN; + } + YY_BREAK + case 154: + YY_RULE_SETUP #line 277 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return UP_OR_DOWN; } - YY_BREAK -case 155: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return UP_OR_DOWN; + } + YY_BREAK + case 155: + YY_RULE_SETUP #line 278 "lev_comp.l" -{ savetoken(yytext); yylval.i=0; return BOOLEAN; } - YY_BREAK -case 156: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 0; + return BOOLEAN; + } + YY_BREAK + case 156: + YY_RULE_SETUP #line 279 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return BOOLEAN; } - YY_BREAK -case 157: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return BOOLEAN; + } + YY_BREAK + case 157: + YY_RULE_SETUP #line 280 "lev_comp.l" -{ savetoken(yytext); yylval.i=DUST; return ENGRAVING_TYPE; } - YY_BREAK -case 158: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = DUST; + return ENGRAVING_TYPE; + } + YY_BREAK + case 158: + YY_RULE_SETUP #line 281 "lev_comp.l" -{ savetoken(yytext); yylval.i=ENGRAVE; return ENGRAVING_TYPE; } - YY_BREAK -case 159: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = ENGRAVE; + return ENGRAVING_TYPE; + } + YY_BREAK + case 159: + YY_RULE_SETUP #line 282 "lev_comp.l" -{ savetoken(yytext); yylval.i=BURN; return ENGRAVING_TYPE; } - YY_BREAK -case 160: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = BURN; + return ENGRAVING_TYPE; + } + YY_BREAK + case 160: + YY_RULE_SETUP #line 283 "lev_comp.l" -{ savetoken(yytext); yylval.i=MARK; return ENGRAVING_TYPE; } - YY_BREAK -case 161: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = MARK; + return ENGRAVING_TYPE; + } + YY_BREAK + case 161: + YY_RULE_SETUP #line 284 "lev_comp.l" -{ savetoken(yytext); yylval.i=ENGR_BLOOD; return ENGRAVING_TYPE; } - YY_BREAK -case 162: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = ENGR_BLOOD; + return ENGRAVING_TYPE; + } + YY_BREAK + case 162: + YY_RULE_SETUP #line 285 "lev_comp.l" -{ savetoken(yytext); yylval.i=1; return CURSE_TYPE; } - YY_BREAK -case 163: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 1; + return CURSE_TYPE; + } + YY_BREAK + case 163: + YY_RULE_SETUP #line 286 "lev_comp.l" -{ savetoken(yytext); yylval.i=2; return CURSE_TYPE; } - YY_BREAK -case 164: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 2; + return CURSE_TYPE; + } + YY_BREAK + case 164: + YY_RULE_SETUP #line 287 "lev_comp.l" -{ savetoken(yytext); yylval.i=3; return CURSE_TYPE; } - YY_BREAK -case 165: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = 3; + return CURSE_TYPE; + } + YY_BREAK + case 165: + YY_RULE_SETUP #line 288 "lev_comp.l" -{ savetoken(yytext); yylval.i=NOTELEPORT; return FLAG_TYPE; } - YY_BREAK -case 166: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = NOTELEPORT; + return FLAG_TYPE; + } + YY_BREAK + case 166: + YY_RULE_SETUP #line 289 "lev_comp.l" -{ savetoken(yytext); yylval.i=HARDFLOOR; return FLAG_TYPE; } - YY_BREAK -case 167: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = HARDFLOOR; + return FLAG_TYPE; + } + YY_BREAK + case 167: + YY_RULE_SETUP #line 290 "lev_comp.l" -{ savetoken(yytext); yylval.i=NOMMAP; return FLAG_TYPE; } - YY_BREAK -case 168: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = NOMMAP; + return FLAG_TYPE; + } + YY_BREAK + case 168: + YY_RULE_SETUP #line 291 "lev_comp.l" -{ savetoken(yytext); yylval.i=ARBOREAL; return FLAG_TYPE; } /* KMH */ - YY_BREAK -case 169: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = ARBOREAL; + return FLAG_TYPE; + } /* KMH */ + YY_BREAK + case 169: + YY_RULE_SETUP #line 292 "lev_comp.l" -{ savetoken(yytext); yylval.i=SHORTSIGHTED; return FLAG_TYPE; } - YY_BREAK -case 170: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SHORTSIGHTED; + return FLAG_TYPE; + } + YY_BREAK + case 170: + YY_RULE_SETUP #line 293 "lev_comp.l" -{ savetoken(yytext); yylval.i=MAZELEVEL; return FLAG_TYPE; } - YY_BREAK -case 171: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = MAZELEVEL; + return FLAG_TYPE; + } + YY_BREAK + case 171: + YY_RULE_SETUP #line 294 "lev_comp.l" -{ savetoken(yytext); yylval.i=PREMAPPED; return FLAG_TYPE; } - YY_BREAK -case 172: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = PREMAPPED; + return FLAG_TYPE; + } + YY_BREAK + case 172: + YY_RULE_SETUP #line 295 "lev_comp.l" -{ savetoken(yytext); yylval.i=SHROUD; return FLAG_TYPE; } - YY_BREAK -case 173: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SHROUD; + return FLAG_TYPE; + } + YY_BREAK + case 173: + YY_RULE_SETUP #line 296 "lev_comp.l" -{ savetoken(yytext); yylval.i=GRAVEYARD; return FLAG_TYPE; } - YY_BREAK -case 174: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = GRAVEYARD; + return FLAG_TYPE; + } + YY_BREAK + case 174: + YY_RULE_SETUP #line 297 "lev_comp.l" -{ savetoken(yytext); yylval.i=ICEDPOOLS; return FLAG_TYPE; } - YY_BREAK -case 175: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = ICEDPOOLS; + return FLAG_TYPE; + } + YY_BREAK + case 175: + YY_RULE_SETUP #line 298 "lev_comp.l" -{ savetoken(yytext); yylval.i=SOLIDIFY; return FLAG_TYPE; } - YY_BREAK -case 176: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SOLIDIFY; + return FLAG_TYPE; + } + YY_BREAK + case 176: + YY_RULE_SETUP #line 299 "lev_comp.l" -{ savetoken(yytext); yylval.i=CORRMAZE; return FLAG_TYPE; } - YY_BREAK -case 177: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = CORRMAZE; + return FLAG_TYPE; + } + YY_BREAK + case 177: + YY_RULE_SETUP #line 300 "lev_comp.l" -{ char *p = strchr(yytext, 'd'); - savetoken(yytext); - if (p) { - *p = '\0'; - p++; - yylval.dice.num=atoi(yytext); - yylval.dice.die=atoi(p); - } else { yylval.dice.num = yylval.dice.die = 1; } - return DICE; - } - YY_BREAK -case 178: -YY_RULE_SETUP + { + char *p = strchr(yytext, 'd'); + savetoken(yytext); + if (p) { + *p = '\0'; + p++; + yylval.dice.num = atoi(yytext); + yylval.dice.die = atoi(p); + } else { + yylval.dice.num = yylval.dice.die = 1; + } + return DICE; + } + YY_BREAK + case 178: + YY_RULE_SETUP #line 310 "lev_comp.l" -{ savetoken(yytext); yylval.i = atoi(yytext + 1); - if (yylval.i < 0 || yylval.i > 100) - lc_error("Unexpected percentile '%li%%'", yylval.i); - return PERCENT; } - YY_BREAK -case 179: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = atoi(yytext + 1); + if (yylval.i < 0 || yylval.i > 100) + lc_error("Unexpected percentile '%li%%'", yylval.i); + return PERCENT; + } + YY_BREAK + case 179: + YY_RULE_SETUP #line 314 "lev_comp.l" -{ savetoken(yytext); yylval.i=atoi(yytext); return MINUS_INTEGER; } - YY_BREAK -case 180: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = atoi(yytext); + return MINUS_INTEGER; + } + YY_BREAK + case 180: + YY_RULE_SETUP #line 315 "lev_comp.l" -{ savetoken(yytext); yylval.i=atoi(yytext); return PLUS_INTEGER; } - YY_BREAK -case 181: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = atoi(yytext); + return PLUS_INTEGER; + } + YY_BREAK + case 181: + YY_RULE_SETUP #line 316 "lev_comp.l" -{ savetoken(yytext); yylval.i = atoi(yytext); - if (yylval.i < 0 || yylval.i > 100) - lc_error("Unexpected percentile '%li%%'", yylval.i); - return SPERCENT; } - YY_BREAK -case 182: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = atoi(yytext); + if (yylval.i < 0 || yylval.i > 100) + lc_error("Unexpected percentile '%li%%'", yylval.i); + return SPERCENT; + } + YY_BREAK + case 182: + YY_RULE_SETUP #line 320 "lev_comp.l" -{ savetoken(yytext); yylval.i=atoi(yytext); return INTEGER; } - YY_BREAK -case 183: -/* rule 183 can match eol */ -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = atoi(yytext); + return INTEGER; + } + YY_BREAK + case 183: + /* rule 183 can match eol */ + YY_RULE_SETUP #line 321 "lev_comp.l" -{ savetoken(yytext); - yytext[yyleng-1] = 0; /* Discard the trailing \" */ - yylval.map = (char *) alloc(strlen(yytext+1)+1); - Strcpy(yylval.map, yytext+1); /* Discard the first \" */ - return STRING; } - YY_BREAK -case 184: -YY_RULE_SETUP + { + savetoken(yytext); + yytext[yyleng - 1] = 0; /* Discard the trailing \" */ + yylval.map = (char *) alloc(strlen(yytext + 1) + 1); + Strcpy(yylval.map, yytext + 1); /* Discard the first \" */ + return STRING; + } + YY_BREAK + case 184: + YY_RULE_SETUP #line 326 "lev_comp.l" -{ savetoken(yytext); return handle_varstring_check(); } - YY_BREAK -case 185: -YY_RULE_SETUP + { + savetoken(yytext); + return handle_varstring_check(); + } + YY_BREAK + case 185: + YY_RULE_SETUP #line 327 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JE; return COMPARE_TYPE; } - YY_BREAK -case 186: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JE; + return COMPARE_TYPE; + } + YY_BREAK + case 186: + YY_RULE_SETUP #line 328 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JNE; return COMPARE_TYPE; } - YY_BREAK -case 187: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JNE; + return COMPARE_TYPE; + } + YY_BREAK + case 187: + YY_RULE_SETUP #line 329 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JNE; return COMPARE_TYPE; } - YY_BREAK -case 188: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JNE; + return COMPARE_TYPE; + } + YY_BREAK + case 188: + YY_RULE_SETUP #line 330 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JLE; return COMPARE_TYPE; } - YY_BREAK -case 189: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JLE; + return COMPARE_TYPE; + } + YY_BREAK + case 189: + YY_RULE_SETUP #line 331 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JGE; return COMPARE_TYPE; } - YY_BREAK -case 190: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JGE; + return COMPARE_TYPE; + } + YY_BREAK + case 190: + YY_RULE_SETUP #line 332 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JL; return COMPARE_TYPE; } - YY_BREAK -case 191: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JL; + return COMPARE_TYPE; + } + YY_BREAK + case 191: + YY_RULE_SETUP #line 333 "lev_comp.l" -{ savetoken(yytext); yylval.i = SPO_JG; return COMPARE_TYPE; } - YY_BREAK -case 192: -/* rule 192 can match eol */ -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = SPO_JG; + return COMPARE_TYPE; + } + YY_BREAK + case 192: + /* rule 192 can match eol */ + YY_RULE_SETUP #line 334 "lev_comp.l" -{ newline(); } - YY_BREAK -case 193: -YY_RULE_SETUP + { + newline(); + } + YY_BREAK + case 193: + YY_RULE_SETUP #line 335 "lev_comp.l" -{ advancepos(yytext); } - YY_BREAK -case 194: -YY_RULE_SETUP + { + advancepos(yytext); + } + YY_BREAK + case 194: + YY_RULE_SETUP #line 336 "lev_comp.l" -{ savetoken(yytext); yylval.i = yytext[2]; return CHAR; } - YY_BREAK -case 195: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = yytext[2]; + return CHAR; + } + YY_BREAK + case 195: + YY_RULE_SETUP #line 337 "lev_comp.l" -{ savetoken(yytext); yylval.i = yytext[1]; return CHAR; } - YY_BREAK -case 196: -YY_RULE_SETUP + { + savetoken(yytext); + yylval.i = yytext[1]; + return CHAR; + } + YY_BREAK + case 196: + YY_RULE_SETUP #line 338 "lev_comp.l" -ST_RET(UNKNOWN_TYPE); - YY_BREAK -case 197: -YY_RULE_SETUP + ST_RET(UNKNOWN_TYPE); + YY_BREAK + case 197: + YY_RULE_SETUP #line 339 "lev_comp.l" -{ savetoken(yytext); return yytext[0]; } - YY_BREAK -case 198: -YY_RULE_SETUP + { + savetoken(yytext); + return yytext[0]; + } + YY_BREAK + case 198: + YY_RULE_SETUP #line 340 "lev_comp.l" -ECHO; - YY_BREAK + ECHO; + YY_BREAK #line 2503 "lex.yy.c" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(MAPC): - yyterminate(); + case YY_STATE_EOF(INITIAL): + case YY_STATE_EOF(MAPC): + yyterminate(); - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + case YY_END_OF_BUFFER: { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = + (int) (yy_cp - (yytext_ptr)) - 1; - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status + == YY_BUFFER_NEW) { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_NORMAL; + } - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ((yy_c_buf_p) + <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[( + yy_n_chars)]) { /* This was really a NUL. */ + yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state(); - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans(yy_current_state); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = (yytext_ptr) + YY_MORE_ADJ; - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } + if (yy_next_state) { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } + else { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; + else + switch (yy_get_next_buffer()) { + case EOB_ACT_END_OF_FILE: { + (yy_did_buffer_switch_on_eof) = 0; - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + if (yywrap()) { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } + else { + if (!(yy_did_buffer_switch_on_eof)) + YY_NEW_FILE; + } + break; + } - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state(); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE + ->yy_ch_buf[(yy_n_chars)]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state(); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer @@ -2641,166 +2923,160 @@ case YY_STATE_EOF(MAPC): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int +yy_get_next_buffer(void) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); + if ((yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1]) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed"); - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } + if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer + == 0) { /* Don't try to fill the buffer, so this is an EOF. */ + if ((yy_c_buf_p) - (yytext_ptr) -YY_MORE_ADJ == 1) { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } + else { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } - /* Try to read more data. */ + /* Try to read more data. */ - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); + for (i = 0; i < number_to_move; ++i) + *(dest++) = *(source++); - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + else { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ + while (num_to_read + <= 0) { /* Not enough room in the buffer - grow it. */ - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + int yy_c_buf_p_offset = (int) ((yy_c_buf_p) -b->yy_ch_buf); - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; + if (b->yy_is_our_buffer) { + yy_size_t new_size = b->yy_buf_size * 2; - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf, b->yy_buf_size + 2); + } else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; + num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + } - } + if (num_to_read > YY_READ_BUF_SIZE) + num_to_read = YY_READ_BUF_SIZE; - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; + /* Read in more data. */ + YY_INPUT((&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read); - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } + if ((yy_n_chars) == 0) { + if (number_to_move == YY_MORE_ADJ) { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin); + } - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } + else { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } + else + ret_val = EOB_ACT_CONTINUE_SCAN; - else - ret_val = EOB_ACT_CONTINUE_SCAN; + if ((yy_size_t)((yy_n_chars) + number_to_move) + > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = + (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, new_size); + if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + } - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = + YY_END_OF_BUFFER_CHAR; - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; + return ret_val; } -/* yy_get_previous_state - get the state just before the EOB char was reached */ +/* yy_get_previous_state - get the state just before the EOB char was reached + */ - static yy_state_type yy_get_previous_state (void) +static yy_state_type +yy_get_previous_state(void) { - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); + register yy_state_type yy_current_state; + register char *yy_cp; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1038 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); - return yy_current_state; + for (yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp) { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 1038) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -2808,603 +3084,623 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +static yy_state_type +yy_try_NUL_trans(yy_state_type yy_current_state) { - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1038 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 1037); + register YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 1038) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 1037); - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } - static void yyunput (int c, register char * yy_bp ) +static void +yyunput(int c, register char *yy_bp) { - register char *yy_cp; - + register char *yy_cp; + yy_cp = (yy_c_buf_p); - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + + 2) { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register yy_size_t number_to_move = (yy_n_chars) + 2; + register char *dest = + &YY_CURRENT_BUFFER_LVALUE + ->yy_ch_buf[YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; + while (source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + *--dest = *--source; - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } + if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2) + YY_FATAL_ERROR("flex scanner push-back overflow"); + } - *--yy_cp = (char) c; + *--yy_cp = (char) c; - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; } #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) +static int +yyinput(void) #else - static int input (void) +static int +input(void) #endif { - int c; - - *(yy_c_buf_p) = (yy_hold_char); + int c; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *(yy_c_buf_p) = (yy_hold_char); - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); + if (*(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR) { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ((yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ + else { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); - /* Reset buffer status. */ - yyrestart(yyin ); + switch (yy_get_next_buffer()) { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ - /*FALLTHROUGH*/ + /* Reset buffer status. */ + yyrestart(yyin); - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; + /*FALLTHROUGH*/ - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; + case EOB_ACT_END_OF_FILE: { + if (yywrap()) + return EOF; + + if (!(yy_did_buffer_switch_on_eof)) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(); #else - return input(); + return input(); #endif - } + } - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); - return c; + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) +void +yyrestart(FILE *input_file) { - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } + if (!YY_CURRENT_BUFFER) { + yyensure_buffer_stack(); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); + } - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); + yy_init_buffer(YY_CURRENT_BUFFER, input_file); + yy_load_buffer_state(); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +void +yy_switch_to_buffer(YY_BUFFER_STATE new_buffer) { - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack(); + if (YY_CURRENT_BUFFER == new_buffer) + return; + + if (YY_CURRENT_BUFFER) { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; + (yy_did_buffer_switch_on_eof) = 1; } -static void yy_load_buffer_state (void) +static void +yy_load_buffer_state(void) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param size The character buffer size in bytes. When in doubt, use @c + * YY_BUF_SIZE. + * * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +YY_BUFFER_STATE +yy_create_buffer(FILE *file, int size) { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + YY_BUFFER_STATE b; - b->yy_buf_size = size; + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state)); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + b->yy_buf_size = size; - b->yy_is_our_buffer = 1; + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - yy_init_buffer(b,file ); + b->yy_is_our_buffer = 1; - return b; + yy_init_buffer(b, file); + + return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * */ - void yy_delete_buffer (YY_BUFFER_STATE b ) +void +yy_delete_buffer(YY_BUFFER_STATE b) { - - if ( ! b ) - return; + if (!b) + return; - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); + if (b->yy_is_our_buffer) + yyfree((void *) b->yy_ch_buf); - yyfree((void *) b ); + yyfree((void *) b); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) +static void +yy_init_buffer(YY_BUFFER_STATE b, FILE *file) { - int oerrno = errno; - - yy_flush_buffer(b ); + int oerrno = errno; - b->yy_input_file = file; - b->yy_fill_buffer = 1; + yy_flush_buffer(b); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ - if (b != YY_CURRENT_BUFFER){ + if (b != YY_CURRENT_BUFFER) { b->yy_bs_lineno = 1; b->yy_bs_column = 0; } - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; + b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0; + + errno = oerrno; } -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. +/** Discard all buffered characters. On the next scan, YY_INPUT will be + * called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * */ - void yy_flush_buffer (YY_BUFFER_STATE b ) +void +yy_flush_buffer(YY_BUFFER_STATE b) { - if ( ! b ) - return; + if (!b) + return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + if (b == YY_CURRENT_BUFFER) + yy_load_buffer_state(); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void +yypush_buffer_state(YY_BUFFER_STATE new_buffer) { - if (new_buffer == NULL) - return; + if (new_buffer == NULL) + return; - yyensure_buffer_stack(); + yyensure_buffer_stack(); - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } + /* This block is copied from yy_switch_to_buffer. */ + if (YY_CURRENT_BUFFER) { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state(); + (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * */ -void yypop_buffer_state (void) +void +yypop_buffer_state(void) { - if (!YY_CURRENT_BUFFER) - return; + if (!YY_CURRENT_BUFFER) + return; - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + yy_delete_buffer(YY_CURRENT_BUFFER); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state(); + (yy_did_buffer_switch_on_eof) = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void +yyensure_buffer_stack(void) { - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { + yy_size_t num_to_alloc; - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } + if (!(yy_buffer_stack)) { + /* First allocation is just for 2 elements, since we don't know if + * this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state **) yyalloc( + num_to_alloc * sizeof(struct yy_buffer_state *)); + if (!(yy_buffer_stack)) + YY_FATAL_ERROR( + "out of dynamic memory in yyensure_buffer_stack()"); - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + memset((yy_buffer_stack), 0, + num_to_alloc * sizeof(struct yy_buffer_state *)); - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1) { + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state **) yyrealloc( + (yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state *)); + if (!(yy_buffer_stack)) + YY_FATAL_ERROR( + "out of dynamic memory in yyensure_buffer_stack()"); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, + grow_size * sizeof(struct yy_buffer_state *)); + (yy_buffer_stack_max) = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified character buffer. +/** Setup the input buffer state to scan directly from a user-specified + * character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. + * + * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE +yy_scan_buffer(char *base, yy_size_t size) { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; + YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR + || base[size - 1] != YY_END_OF_BUFFER_CHAR) + /* They forgot to leave room for the EOB's. */ + return 0; - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state)); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); - yy_switch_to_buffer(b ); + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; - return b; + yy_switch_to_buffer(b); + + return b; } -/** Setup the input buffer state to scan a string. The next call to yylex() will +/** Setup the input buffer state to scan a string. The next call to yylex() + * will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +YY_BUFFER_STATE +yy_scan_string(yyconst char *yystr) { - - return yy_scan_bytes(yystr,strlen(yystr) ); + return yy_scan_bytes(yystr, strlen(yystr)); } -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will +/** Setup the input buffer state to scan the given bytes. The next call to + * yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param _yybytes_len the number of bytes in the buffer pointed to by @a + * bytes. + * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +YY_BUFFER_STATE +yy_scan_bytes(yyconst char *yybytes, yy_size_t _yybytes_len) { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n); + if (!buf) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()"); - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + for (i = 0; i < _yybytes_len; ++i) + buf[i] = yybytes[i]; - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; + b = yy_scan_buffer(buf, n); + if (!b) + YY_FATAL_ERROR("bad buffer in yy_scan_bytes()"); - return b; + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg ) +static void +yy_fatal_error(yyconst char *msg) { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); + (void) fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } while (0) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. - * + * */ -int yyget_lineno (void) +int +yyget_lineno(void) { - return yylineno; } /** Get the input stream. - * + * */ -FILE *yyget_in (void) +FILE * +yyget_in(void) { - return yyin; + return yyin; } /** Get the output stream. - * + * */ -FILE *yyget_out (void) +FILE * +yyget_out(void) { - return yyout; + return yyout; } /** Get the length of the current token. - * + * */ -yy_size_t yyget_leng (void) +yy_size_t +yyget_leng(void) { - return yyleng; + return yyleng; } /** Get the current token. - * + * */ -char *yyget_text (void) +char * +yyget_text(void) { - return yytext; + return yytext; } /** Set the current line number. * @param line_number - * + * */ -void yyset_lineno (int line_number ) +void +yyset_lineno(int line_number) { - yylineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. - * + * * @see yy_switch_to_buffer */ -void yyset_in (FILE * in_str ) +void +yyset_in(FILE *in_str) { - yyin = in_str ; + yyin = in_str; } -void yyset_out (FILE * out_str ) +void +yyset_out(FILE *out_str) { - yyout = out_str ; + yyout = out_str; } -int yyget_debug (void) +int +yyget_debug(void) { - return yy_flex_debug; + return yy_flex_debug; } -void yyset_debug (int bdebug ) +void +yyset_debug(int bdebug) { - yy_flex_debug = bdebug ; + yy_flex_debug = bdebug; } -static int yy_init_globals (void) +static int +yy_init_globals(void) { - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; @@ -3429,23 +3725,24 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int +yylex_destroy(void) { - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } + while (YY_CURRENT_BUFFER) { + yy_delete_buffer(YY_CURRENT_BUFFER); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack)); + (yy_buffer_stack) = NULL; - /* Reset the globals. This is important in a non-reentrant scanner so the next time + /* Reset the globals. This is important in a non-reentrant scanner so the + * next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals(); return 0; } @@ -3455,125 +3752,140 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +static void +yy_flex_strncpy(char *s1, yyconst char *s2, int n) { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; + register int i; + for (i = 0; i < n; ++i) + s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int +yy_flex_strlen(yyconst char *s) { - register int n; - for ( n = 0; s[n]; ++n ) - ; + register int n; + for (n = 0; s[n]; ++n) + ; - return n; + return n; } #endif -void *yyalloc (yy_size_t size ) +void * +yyalloc(yy_size_t size) { - return (void *) malloc( size ); + return (void *) malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size ) +void * +yyrealloc(void *ptr, yy_size_t size) { - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc((char *) ptr, size); } -void yyfree (void * ptr ) +void +yyfree(void *ptr) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + free((char *) ptr); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 339 "lev_comp.l" - -#ifdef AMIGA -long *alloc(n) - unsigned n; +#ifdef AMIGA +long * +alloc(n) +unsigned n; { - return ((long *)malloc (n)); + return ((long *) malloc(n)); } #endif /* routine to switch to another input file; needed for flex */ -void init_yyin( input_f ) +void +init_yyin(input_f) FILE *input_f; { #if defined(FLEX_SCANNER) || defined(FLEXHACK_SCANNER) - if (yyin) - yyrestart(input_f); - else + if (yyin) + yyrestart(input_f); + else #endif - yyin = input_f; - if (!orig_yyin) orig_yyin = yyin; + yyin = input_f; + if (!orig_yyin) + orig_yyin = yyin; } /* analogous routine (for completeness) */ -void init_yyout( output_f ) +void +init_yyout(output_f) FILE *output_f; { - yyout = output_f; + yyout = output_f; } long handle_varstring_check() { - struct lc_vardefs *vd; - yylval.map = (char *) alloc(strlen(yytext)+1); - Strcpy(yylval.map, yytext); - if ((vd = vardef_defined(variable_definitions, yytext, 1))) { - long l = vd->var_type; - long a = ((l & SPOVAR_ARRAY) == SPOVAR_ARRAY); - l = (l & ~SPOVAR_ARRAY); - if (l == SPOVAR_INT) return (a ? VARSTRING_INT_ARRAY : VARSTRING_INT); - if (l == SPOVAR_STRING) return (a ? VARSTRING_STRING_ARRAY : VARSTRING_STRING); - if (l == SPOVAR_VARIABLE) return (a ? VARSTRING_VAR_ARRAY : VARSTRING_VAR); - if (l == SPOVAR_COORD) return (a ? VARSTRING_COORD_ARRAY : VARSTRING_COORD); - if (l == SPOVAR_REGION) return (a ? VARSTRING_REGION_ARRAY : VARSTRING_REGION); - if (l == SPOVAR_MAPCHAR) return (a ? VARSTRING_MAPCHAR_ARRAY : VARSTRING_MAPCHAR); - if (l == SPOVAR_MONST) return (a ? VARSTRING_MONST_ARRAY : VARSTRING_MONST); - if (l == SPOVAR_OBJ) return (a ? VARSTRING_OBJ_ARRAY : VARSTRING_OBJ); - if (l == SPOVAR_SEL) return (a ? VARSTRING_SEL_ARRAY : VARSTRING_SEL); - } - return VARSTRING; + struct lc_vardefs *vd; + yylval.map = (char *) alloc(strlen(yytext) + 1); + Strcpy(yylval.map, yytext); + if ((vd = vardef_defined(variable_definitions, yytext, 1))) { + long l = vd->var_type; + long a = ((l & SPOVAR_ARRAY) == SPOVAR_ARRAY); + l = (l & ~SPOVAR_ARRAY); + if (l == SPOVAR_INT) + return (a ? VARSTRING_INT_ARRAY : VARSTRING_INT); + if (l == SPOVAR_STRING) + return (a ? VARSTRING_STRING_ARRAY : VARSTRING_STRING); + if (l == SPOVAR_VARIABLE) + return (a ? VARSTRING_VAR_ARRAY : VARSTRING_VAR); + if (l == SPOVAR_COORD) + return (a ? VARSTRING_COORD_ARRAY : VARSTRING_COORD); + if (l == SPOVAR_REGION) + return (a ? VARSTRING_REGION_ARRAY : VARSTRING_REGION); + if (l == SPOVAR_MAPCHAR) + return (a ? VARSTRING_MAPCHAR_ARRAY : VARSTRING_MAPCHAR); + if (l == SPOVAR_MONST) + return (a ? VARSTRING_MONST_ARRAY : VARSTRING_MONST); + if (l == SPOVAR_OBJ) + return (a ? VARSTRING_OBJ_ARRAY : VARSTRING_OBJ); + if (l == SPOVAR_SEL) + return (a ? VARSTRING_SEL_ARRAY : VARSTRING_SEL); + } + return VARSTRING; } - void newline() { - nh_line_number++; - token_start_pos = 0; - memset(curr_token, 0, 512); + nh_line_number++; + token_start_pos = 0; + memset(curr_token, 0, 512); } void savetoken(s) char *s; { - sprintf(curr_token, "%s", s); - advancepos(s); + sprintf(curr_token, "%s", s); + advancepos(s); } void advancepos(s) char *s; { - token_start_pos += strlen(s); + token_start_pos += strlen(s); } /*lev_comp.l*/ - diff --git a/sys/share/lev_yacc.c b/sys/share/lev_yacc.c index b6f81af9e..124dd6854 100644 --- a/sys/share/lev_yacc.c +++ b/sys/share/lev_yacc.c @@ -58,13 +58,10 @@ /* Pull parsers. */ #define YYPULL 1 - - - /* Copy the first part of user declarations. */ #line 1 "lev_comp.y" /* yacc.c:339 */ -/* NetHack 3.6 lev_comp.y $NHDT-Date: 1428655167 2015/04/10 08:39:27 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ +/* NetHack 3.6 lev_comp.y $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 lev_comp.y $Date: 2009/05/06 10:54:31 $ $Revision: 1.8 $ */ /* SCCS Id: @(#)lev_yacc.c 3.5 2007/08/01 */ /* Copyright (c) 1989 by Jean-Christophe Collet */ @@ -85,27 +82,27 @@ * and AIX will still see the directive. */ #ifdef _AIX - #pragma alloca /* keep leading space! */ +#pragma alloca /* keep leading space! */ #endif -#define SPEC_LEV /* for USE_OLDARGS (sp_lev.h) */ +#define SPEC_LEV /* for USE_OLDARGS (sp_lev.h) */ #include "hack.h" #include "sp_lev.h" -#define ERR (-1) +#define ERR (-1) /* many types of things are put in chars for transference to NetHack. * since some systems will use signed chars, limit everybody to the * same number for portability. */ -#define MAX_OF_TYPE 128 +#define MAX_OF_TYPE 128 -#define MAX_NESTED_IFS 20 +#define MAX_NESTED_IFS 20 #define MAX_SWITCH_CASES 20 -#define New(type) \ - (type *) memset((genericptr_t)alloc(sizeof(type)), 0, sizeof(type)) -#define NewTab(type, size) (type **) alloc(sizeof(type *) * size) -#define Free(ptr) free((genericptr_t)ptr) +#define New(type) \ + (type *) memset((genericptr_t) alloc(sizeof(type)), 0, sizeof(type)) +#define NewTab(type, size) (type **) alloc(sizeof(type *) * size) +#define Free(ptr) free((genericptr_t) ptr) extern void VDECL(lc_error, (const char *, ...)); extern void VDECL(lc_warning, (const char *, ...)); @@ -117,30 +114,32 @@ int NDECL(yyparse); extern int FDECL(get_floor_type, (CHAR_P)); extern int FDECL(get_room_type, (char *)); extern int FDECL(get_trap_type, (char *)); -extern int FDECL(get_monster_id, (char *,CHAR_P)); -extern int FDECL(get_object_id, (char *,CHAR_P)); +extern int FDECL(get_monster_id, (char *, CHAR_P)); +extern int FDECL(get_object_id, (char *, CHAR_P)); extern boolean FDECL(check_monster_char, (CHAR_P)); extern boolean FDECL(check_object_char, (CHAR_P)); extern char FDECL(what_map_char, (CHAR_P)); extern void FDECL(scan_map, (char *, sp_lev *)); extern void FDECL(add_opcode, (sp_lev *, int, genericptr_t)); extern genericptr_t FDECL(get_last_opcode_data1, (sp_lev *, int)); -extern genericptr_t FDECL(get_last_opcode_data2, (sp_lev *, int,int)); +extern genericptr_t FDECL(get_last_opcode_data2, (sp_lev *, int, int)); extern boolean FDECL(check_subrooms, (sp_lev *)); -extern boolean FDECL(write_level_file, (char *,sp_lev *)); +extern boolean FDECL(write_level_file, (char *, sp_lev *)); extern struct opvar *FDECL(set_opvar_int, (struct opvar *, long)); extern void VDECL(add_opvars, (sp_lev *, const char *, ...)); -extern void FDECL(start_level_def, (sp_lev * *, char *)); +extern void FDECL(start_level_def, (sp_lev **, char *)); -extern struct lc_funcdefs *FDECL(funcdef_new,(long,char *)); -extern void FDECL(funcdef_free_all,(struct lc_funcdefs *)); -extern struct lc_funcdefs *FDECL(funcdef_defined,(struct lc_funcdefs *,char *, int)); +extern struct lc_funcdefs *FDECL(funcdef_new, (long, char *)); +extern void FDECL(funcdef_free_all, (struct lc_funcdefs *)); +extern struct lc_funcdefs *FDECL(funcdef_defined, + (struct lc_funcdefs *, char *, int)); extern char *FDECL(funcdef_paramtypes, (struct lc_funcdefs *)); extern char *FDECL(decode_parm_str, (char *)); -extern struct lc_vardefs *FDECL(vardef_new,(long,char *)); -extern void FDECL(vardef_free_all,(struct lc_vardefs *)); -extern struct lc_vardefs *FDECL(vardef_defined,(struct lc_vardefs *,char *, int)); +extern struct lc_vardefs *FDECL(vardef_new, (long, char *)); +extern void FDECL(vardef_free_all, (struct lc_vardefs *)); +extern struct lc_vardefs *FDECL(vardef_defined, + (struct lc_vardefs *, char *, int)); extern void NDECL(break_stmt_start); extern void FDECL(break_stmt_end, (sp_lev *)); @@ -150,13 +149,14 @@ extern void FDECL(splev_add_from, (sp_lev *, sp_lev *)); extern void FDECL(check_vardef_type, (struct lc_vardefs *, char *, long)); extern void FDECL(vardef_used, (struct lc_vardefs *, char *)); -extern struct lc_vardefs *FDECL(add_vardef_type, (struct lc_vardefs *, char *, long)); +extern struct lc_vardefs *FDECL(add_vardef_type, + (struct lc_vardefs *, char *, long)); extern int FDECL(reverse_jmp_opcode, (int)); struct coord { - long x; - long y; + long x; + long y; }; struct forloopdef { @@ -166,7 +166,6 @@ struct forloopdef { static struct forloopdef forloop_list[MAX_NESTED_IFS]; static short n_forloops = 0; - sp_lev *splev = NULL; static struct opvar *if_list[MAX_NESTED_IFS]; @@ -178,7 +177,8 @@ int obj_containment = 0; int in_container_obj = 0; -/* integer value is possibly an inconstant value (eg. dice notation or a variable) */ +/* integer value is possibly an inconstant value (eg. dice notation or a + * variable) */ int is_inconstant_number = 0; int in_switch_statement = 0; @@ -193,11 +193,10 @@ struct lc_breakdef *break_list = NULL; extern struct lc_vardefs *variable_definitions; - struct lc_vardefs *function_tmp_var_defs = NULL; extern struct lc_funcdefs *function_definitions; struct lc_funcdefs *curr_function = NULL; -struct lc_funcdefs_parm * curr_function_param = NULL; +struct lc_funcdefs_parm *curr_function_param = NULL; int in_function_definition = 0; sp_lev *function_splev_backup = NULL; @@ -208,32 +207,31 @@ extern const char *fname; extern char curr_token[512]; - #line 213 "y.tab.c" /* yacc.c:339 */ -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif +#ifndef YY_NULLPTR +#if defined __cplusplus && 201103L <= __cplusplus +#define YY_NULLPTR nullptr +#else +#define YY_NULLPTR 0 +#endif +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 +#undef YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE 0 +#define YYERROR_VERBOSE 0 #endif /* In a future release of Bison, this section will be replaced by #include "y.tab.h". */ #ifndef YY_YY_Y_TAB_H_INCLUDED -# define YY_YY_Y_TAB_H_INCLUDED +#define YY_YY_Y_TAB_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int yydebug; @@ -241,9 +239,8 @@ extern int yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { +#define YYTOKENTYPE +enum yytokentype { CHAR = 258, INTEGER = 259, BOOLEAN = 260, @@ -418,7 +415,7 @@ extern int yydebug; METHOD_SEL = 429, METHOD_SEL_ARRAY = 430, DICE = 431 - }; +}; #endif /* Tokens. */ #define CHAR 258 @@ -597,57 +594,55 @@ extern int yydebug; #define DICE 431 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED typedef union YYSTYPE YYSTYPE; -union YYSTYPE -{ +union YYSTYPE { #line 149 "lev_comp.y" /* yacc.c:355 */ - long i; - char* map; - struct { - long room; - long wall; - long door; - } corpos; + long i; + char *map; struct { - long area; - long x1; - long y1; - long x2; - long y2; + long room; + long wall; + long door; + } corpos; + struct { + long area; + long x1; + long y1; + long x2; + long y2; } lregn; struct { - long x; - long y; + long x; + long y; } crd; struct { - long ter; - long lit; + long ter; + long lit; } terr; struct { - long height; - long width; + long height; + long width; } sze; struct { - long die; - long num; + long die; + long num; } dice; struct { - long cfunc; - char *varstr; + long cfunc; + char *varstr; } meth; #line 642 "y.tab.c" /* yacc.c:355 */ }; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - extern YYSTYPE yylval; -int yyparse (void); +int yyparse(void); #endif /* !YY_YY_Y_TAB_H_INCLUDED */ @@ -656,7 +651,7 @@ int yyparse (void); #line 657 "y.tab.c" /* yacc.c:358 */ #ifdef short -# undef short +#undef short #endif #ifdef YYTYPE_UINT8 @@ -684,1190 +679,948 @@ typedef short int yytype_int16; #endif #ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif +#ifdef __SIZE_TYPE__ +#define YYSIZE_T __SIZE_TYPE__ +#elif defined size_t +#define YYSIZE_T size_t +#elif !defined YYSIZE_T +#include /* INFRINGES ON USER NAME SPACE */ +#define YYSIZE_T size_t +#else +#define YYSIZE_T unsigned int +#endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif +#if defined YYENABLE_NLS && YYENABLE_NLS +#if ENABLE_NLS +#include /* INFRINGES ON USER NAME SPACE */ +#define YY_(Msgid) dgettext("bison-runtime", Msgid) +#endif +#endif +#ifndef YY_ +#define YY_(Msgid) Msgid +#endif #endif #ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif +#if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +#define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#else +#define YY_ATTRIBUTE(Spec) /* empty */ +#endif #endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) #endif #if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +#if defined _MSC_VER && 1200 <= _MSC_VER +#define _Noreturn __declspec(noreturn) +#else +#define _Noreturn YY_ATTRIBUTE((__noreturn__)) +#endif #endif /* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +#if !defined lint || defined __GNUC__ +#define YYUSE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +#define YYUSE(E) /* empty */ #endif #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else -# define YY_INITIAL_VALUE(Value) Value +#define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +#define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif - -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif +#ifdef YYSTACK_USE_ALLOCA +#if YYSTACK_USE_ALLOCA +#ifdef __GNUC__ +#define YYSTACK_ALLOC __builtin_alloca +#elif defined __BUILTIN_VA_ARG_INCR +#include /* INFRINGES ON USER NAME SPACE */ +#elif defined _AIX +#define YYSTACK_ALLOC __alloca +#elif defined _MSC_VER +#include /* INFRINGES ON USER NAME SPACE */ +#define alloca _alloca +#else +#define YYSTACK_ALLOC alloca +#if !defined _ALLOCA_H && !defined EXIT_SUCCESS +#include /* INFRINGES ON USER NAME SPACE */ +/* Use EXIT_SUCCESS as a witness for stdlib.h. */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#endif +#endif +#endif -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif +#ifdef YYSTACK_ALLOC +/* Pacify GCC's 'empty if-body' warning. */ +#define YYSTACK_FREE(Ptr) \ + do { /* empty */ \ + ; \ + } while (0) +#ifndef YYSTACK_ALLOC_MAXIMUM +/* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +#define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +#endif +#else +#define YYSTACK_ALLOC YYMALLOC +#define YYSTACK_FREE YYFREE +#ifndef YYSTACK_ALLOC_MAXIMUM +#define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +#endif +#if (defined __cplusplus && !defined EXIT_SUCCESS \ + && !((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +#include /* INFRINGES ON USER NAME SPACE */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#ifndef YYMALLOC +#define YYMALLOC malloc +#if !defined malloc && !defined EXIT_SUCCESS +void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#ifndef YYFREE +#define YYFREE free +#if !defined free && !defined EXIT_SUCCESS +void free(void *); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ +#if (!defined yyoverflow \ + && (!defined __cplusplus \ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yytype_int16 yyss_alloc; - YYSTYPE yyvs_alloc; +union yyalloc { + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +#define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) +#define YYSTACK_BYTES(N) \ + ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +#define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) +#define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do { \ + YYSIZE_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof(*yyptr); \ + } while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif +#ifndef YYCOPY +#if defined __GNUC__ && 1 < __GNUC__ +#define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +#else +#define YYCOPY(Dst, Src, Count) \ + do { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } while (0) +#endif +#endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 9 +#define YYFINAL 9 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 1033 +#define YYLAST 1033 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 194 +#define YYNTOKENS 194 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 160 +#define YYNNTS 160 /* YYNRULES -- Number of rules. */ -#define YYNRULES 406 +#define YYNRULES 406 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 866 +#define YYNSTATES 866 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 431 +#define YYUNDEFTOK 2 +#define YYMAXUTOK 431 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 189, 193, 2, - 133, 134, 187, 185, 131, 186, 191, 188, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 132, 2, - 2, 190, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 135, 2, 136, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 137, 192, 138, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 127, 128, 129, 130, 139, 140, 141, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, - 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, - 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, - 183, 184 +static const yytype_uint8 yytranslate[] = { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 189, 193, 2, 133, 134, 187, 185, 131, + 186, 191, 188, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 132, 2, + 2, 190, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 135, 2, 136, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 137, 192, 138, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184 }; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 276, 276, 277, 280, 281, 284, 306, 311, 332, - 336, 342, 352, 363, 369, 398, 401, 408, 412, 419, - 422, 429, 430, 434, 437, 443, 447, 454, 457, 463, - 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, - 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 526, 527, 528, 529, 530, 531, 532, - 533, 534, 537, 538, 539, 542, 543, 546, 558, 564, - 570, 576, 582, 588, 594, 600, 606, 614, 622, 630, - 638, 646, 654, 664, 669, 676, 681, 688, 693, 700, - 704, 710, 715, 722, 726, 732, 736, 743, 765, 742, - 779, 827, 834, 837, 843, 850, 854, 863, 867, 862, - 929, 930, 934, 933, 946, 945, 960, 970, 971, 974, - 1013, 1012, 1046, 1045, 1075, 1074, 1105, 1104, 1130, 1139, - 1138, 1165, 1171, 1176, 1181, 1188, 1195, 1204, 1212, 1224, - 1223, 1242, 1241, 1260, 1263, 1269, 1279, 1285, 1294, 1300, - 1305, 1311, 1316, 1322, 1333, 1339, 1340, 1343, 1344, 1347, - 1351, 1357, 1358, 1361, 1368, 1376, 1384, 1385, 1388, 1389, - 1392, 1397, 1396, 1410, 1417, 1423, 1431, 1436, 1442, 1448, - 1454, 1460, 1465, 1470, 1475, 1480, 1485, 1490, 1495, 1500, - 1505, 1510, 1518, 1525, 1529, 1542, 1549, 1548, 1564, 1572, - 1578, 1586, 1592, 1597, 1602, 1607, 1612, 1617, 1622, 1627, - 1632, 1643, 1648, 1653, 1658, 1663, 1670, 1676, 1705, 1710, - 1718, 1724, 1730, 1737, 1744, 1754, 1764, 1779, 1790, 1793, - 1799, 1805, 1811, 1817, 1822, 1829, 1836, 1842, 1848, 1855, - 1854, 1879, 1882, 1888, 1895, 1899, 1904, 1911, 1917, 1924, - 1928, 1935, 1943, 1946, 1956, 1960, 1963, 1969, 1973, 1980, - 1984, 1988, 1994, 1995, 1998, 1999, 2002, 2003, 2004, 2010, - 2011, 2012, 2018, 2019, 2022, 2031, 2036, 2043, 2053, 2059, - 2063, 2067, 2074, 2083, 2089, 2093, 2099, 2103, 2111, 2115, - 2122, 2131, 2142, 2146, 2153, 2162, 2171, 2182, 2186, 2193, - 2202, 2211, 2220, 2229, 2235, 2239, 2246, 2255, 2265, 2274, - 2283, 2290, 2291, 2297, 2301, 2305, 2309, 2317, 2326, 2330, - 2334, 2338, 2342, 2346, 2349, 2356, 2365, 2393, 2394, 2397, - 2398, 2401, 2405, 2412, 2419, 2430, 2433, 2441, 2445, 2449, - 2453, 2457, 2462, 2466, 2470, 2475, 2480, 2485, 2489, 2494, - 2499, 2503, 2507, 2512, 2516, 2523, 2529, 2533, 2539, 2546, - 2547, 2548, 2551, 2555, 2559, 2563, 2569, 2570, 2573, 2574, - 2577, 2578, 2581, 2582, 2585, 2589, 2607 +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = { + 0, 276, 276, 277, 280, 281, 284, 306, 311, 332, 336, 342, + 352, 363, 369, 398, 401, 408, 412, 419, 422, 429, 430, 434, + 437, 443, 447, 454, 457, 463, 469, 470, 471, 472, 473, 474, + 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, + 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 515, 516, 517, 518, 519, 520, 521, 522, 523, 526, + 527, 528, 529, 530, 531, 532, 533, 534, 537, 538, 539, 542, + 543, 546, 558, 564, 570, 576, 582, 588, 594, 600, 606, 614, + 622, 630, 638, 646, 654, 664, 669, 676, 681, 688, 693, 700, + 704, 710, 715, 722, 726, 732, 736, 743, 765, 742, 779, 827, + 834, 837, 843, 850, 854, 863, 867, 862, 929, 930, 934, 933, + 946, 945, 960, 970, 971, 974, 1013, 1012, 1046, 1045, 1075, 1074, + 1105, 1104, 1130, 1139, 1138, 1165, 1171, 1176, 1181, 1188, 1195, 1204, + 1212, 1224, 1223, 1242, 1241, 1260, 1263, 1269, 1279, 1285, 1294, 1300, + 1305, 1311, 1316, 1322, 1333, 1339, 1340, 1343, 1344, 1347, 1351, 1357, + 1358, 1361, 1368, 1376, 1384, 1385, 1388, 1389, 1392, 1397, 1396, 1410, + 1417, 1423, 1431, 1436, 1442, 1448, 1454, 1460, 1465, 1470, 1475, 1480, + 1485, 1490, 1495, 1500, 1505, 1510, 1518, 1525, 1529, 1542, 1549, 1548, + 1564, 1572, 1578, 1586, 1592, 1597, 1602, 1607, 1612, 1617, 1622, 1627, + 1632, 1643, 1648, 1653, 1658, 1663, 1670, 1676, 1705, 1710, 1718, 1724, + 1730, 1737, 1744, 1754, 1764, 1779, 1790, 1793, 1799, 1805, 1811, 1817, + 1822, 1829, 1836, 1842, 1848, 1855, 1854, 1879, 1882, 1888, 1895, 1899, + 1904, 1911, 1917, 1924, 1928, 1935, 1943, 1946, 1956, 1960, 1963, 1969, + 1973, 1980, 1984, 1988, 1994, 1995, 1998, 1999, 2002, 2003, 2004, 2010, + 2011, 2012, 2018, 2019, 2022, 2031, 2036, 2043, 2053, 2059, 2063, 2067, + 2074, 2083, 2089, 2093, 2099, 2103, 2111, 2115, 2122, 2131, 2142, 2146, + 2153, 2162, 2171, 2182, 2186, 2193, 2202, 2211, 2220, 2229, 2235, 2239, + 2246, 2255, 2265, 2274, 2283, 2290, 2291, 2297, 2301, 2305, 2309, 2317, + 2326, 2330, 2334, 2338, 2342, 2346, 2349, 2356, 2365, 2393, 2394, 2397, + 2398, 2401, 2405, 2412, 2419, 2430, 2433, 2441, 2445, 2449, 2453, 2457, + 2462, 2466, 2470, 2475, 2480, 2485, 2489, 2494, 2499, 2503, 2507, 2512, + 2516, 2523, 2529, 2533, 2539, 2546, 2547, 2548, 2551, 2555, 2559, 2563, + 2569, 2570, 2573, 2574, 2577, 2578, 2581, 2582, 2585, 2589, 2607 }; #endif #if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "CHAR", "INTEGER", "BOOLEAN", "PERCENT", - "SPERCENT", "MINUS_INTEGER", "PLUS_INTEGER", "MAZE_GRID_ID", - "SOLID_FILL_ID", "MINES_ID", "ROGUELEV_ID", "MESSAGE_ID", "MAZE_ID", - "LEVEL_ID", "LEV_INIT_ID", "GEOMETRY_ID", "NOMAP_ID", "OBJECT_ID", - "COBJECT_ID", "MONSTER_ID", "TRAP_ID", "DOOR_ID", "DRAWBRIDGE_ID", - "object_ID", "monster_ID", "terrain_ID", "MAZEWALK_ID", "WALLIFY_ID", - "REGION_ID", "FILLING", "IRREGULAR", "JOINED", "ALTAR_ID", "LADDER_ID", - "STAIR_ID", "NON_DIGGABLE_ID", "NON_PASSWALL_ID", "ROOM_ID", "PORTAL_ID", - "TELEPRT_ID", "BRANCH_ID", "LEV", "MINERALIZE_ID", "CORRIDOR_ID", - "GOLD_ID", "ENGRAVING_ID", "FOUNTAIN_ID", "POOL_ID", "SINK_ID", "NONE", - "RAND_CORRIDOR_ID", "DOOR_STATE", "LIGHT_STATE", "CURSE_TYPE", - "ENGRAVING_TYPE", "DIRECTION", "RANDOM_TYPE", "RANDOM_TYPE_BRACKET", - "A_REGISTER", "ALIGNMENT", "LEFT_OR_RIGHT", "CENTER", "TOP_OR_BOT", - "ALTAR_TYPE", "UP_OR_DOWN", "SUBROOM_ID", "NAME_ID", "FLAGS_ID", - "FLAG_TYPE", "MON_ATTITUDE", "MON_ALERTNESS", "MON_APPEARANCE", - "ROOMDOOR_ID", "IF_ID", "ELSE_ID", "TERRAIN_ID", "HORIZ_OR_VERT", - "REPLACE_TERRAIN_ID", "EXIT_ID", "SHUFFLE_ID", "QUANTITY_ID", - "BURIED_ID", "LOOP_ID", "FOR_ID", "TO_ID", "SWITCH_ID", "CASE_ID", - "BREAK_ID", "DEFAULT_ID", "ERODED_ID", "TRAPPED_ID", "RECHARGED_ID", - "INVIS_ID", "GREASED_ID", "FEMALE_ID", "CANCELLED_ID", "REVIVED_ID", - "AVENGE_ID", "FLEEING_ID", "BLINDED_ID", "PARALYZED_ID", "STUNNED_ID", - "CONFUSED_ID", "SEENTRAPS_ID", "ALL_ID", "MONTYPE_ID", "GRAVE_ID", - "ERODEPROOF_ID", "FUNCTION_ID", "MSG_OUTPUT_TYPE", "COMPARE_TYPE", - "UNKNOWN_TYPE", "rect_ID", "fillrect_ID", "line_ID", "randline_ID", - "grow_ID", "selection_ID", "flood_ID", "rndcoord_ID", "circle_ID", - "ellipse_ID", "filter_ID", "complement_ID", "gradient_ID", - "GRADIENT_TYPE", "LIMITED", "HUMIDITY_TYPE", "','", "':'", "'('", "')'", - "'['", "']'", "'{'", "'}'", "STRING", "MAP_ID", "NQSTRING", "VARSTRING", - "CFUNC", "CFUNC_INT", "CFUNC_STR", "CFUNC_COORD", "CFUNC_REGION", - "VARSTRING_INT", "VARSTRING_INT_ARRAY", "VARSTRING_STRING", - "VARSTRING_STRING_ARRAY", "VARSTRING_VAR", "VARSTRING_VAR_ARRAY", - "VARSTRING_COORD", "VARSTRING_COORD_ARRAY", "VARSTRING_REGION", - "VARSTRING_REGION_ARRAY", "VARSTRING_MAPCHAR", "VARSTRING_MAPCHAR_ARRAY", - "VARSTRING_MONST", "VARSTRING_MONST_ARRAY", "VARSTRING_OBJ", - "VARSTRING_OBJ_ARRAY", "VARSTRING_SEL", "VARSTRING_SEL_ARRAY", - "METHOD_INT", "METHOD_INT_ARRAY", "METHOD_STRING", "METHOD_STRING_ARRAY", - "METHOD_VAR", "METHOD_VAR_ARRAY", "METHOD_COORD", "METHOD_COORD_ARRAY", - "METHOD_REGION", "METHOD_REGION_ARRAY", "METHOD_MAPCHAR", - "METHOD_MAPCHAR_ARRAY", "METHOD_MONST", "METHOD_MONST_ARRAY", - "METHOD_OBJ", "METHOD_OBJ_ARRAY", "METHOD_SEL", "METHOD_SEL_ARRAY", - "DICE", "'+'", "'-'", "'*'", "'/'", "'%'", "'='", "'.'", "'|'", "'&'", - "$accept", "file", "levels", "level", "level_def", "mazefiller", - "lev_init", "opt_limited", "opt_coord_or_var", "opt_fillchar", "walled", - "flags", "flag_list", "levstatements", "stmt_block", "levstatement", - "any_var_array", "any_var", "any_var_or_arr", "any_var_or_unk", - "shuffle_detail", "variable_define", "encodeobj_list", - "encodemonster_list", "mapchar_list", "encoderegion_list", - "encodecoord_list", "integer_list", "string_list", "function_define", - "$@1", "$@2", "function_call", "exitstatement", "opt_percent", - "comparestmt", "switchstatement", "$@3", "$@4", "switchcases", - "switchcase", "$@5", "$@6", "breakstatement", "for_to_span", - "forstmt_start", "forstatement", "$@7", "loopstatement", "$@8", - "chancestatement", "$@9", "ifstatement", "$@10", "if_ending", "$@11", - "message", "random_corridors", "corridor", "corr_spec", "room_begin", - "subroom_def", "$@12", "room_def", "$@13", "roomfill", "room_pos", - "subroom_pos", "room_align", "room_size", "door_detail", "secret", - "door_wall", "dir_list", "door_pos", "map_definition", "h_justif", - "v_justif", "monster_detail", "$@14", "monster_desc", "monster_infos", - "monster_info", "seen_trap_mask", "object_detail", "$@15", "object_desc", - "object_infos", "object_info", "trap_detail", "drawbridge_detail", - "mazewalk_detail", "wallify_detail", "ladder_detail", "stair_detail", - "stair_region", "portal_region", "teleprt_region", "branch_region", - "teleprt_detail", "fountain_detail", "sink_detail", "pool_detail", - "terrain_type", "replace_terrain_detail", "terrain_detail", - "diggable_detail", "passwall_detail", "region_detail", "@16", - "region_detail_end", "altar_detail", "grave_detail", "gold_detail", - "engraving_detail", "mineralize", "trap_name", "room_type", - "optroomregionflags", "roomregionflags", "roomregionflag", "door_state", - "light_state", "alignment", "alignment_prfx", "altar_type", "a_register", - "string_or_var", "integer_or_var", "coord_or_var", "encodecoord", - "humidity_flags", "region_or_var", "encoderegion", "mapchar_or_var", - "mapchar", "monster_or_var", "encodemonster", "object_or_var", - "encodeobj", "string_expr", "math_expr_var", "func_param_type", - "func_param_part", "func_param_list", "func_params_list", - "func_call_param_part", "func_call_param_list", "func_call_params_list", - "ter_selection_x", "ter_selection", "dice", "all_integers", - "all_ints_push", "objectid", "monsterid", "terrainid", "engraving_type", - "lev_region", "region", YY_NULLPTR +static const char *const yytname[] = { + "$end", "error", "$undefined", "CHAR", "INTEGER", "BOOLEAN", "PERCENT", + "SPERCENT", "MINUS_INTEGER", "PLUS_INTEGER", "MAZE_GRID_ID", + "SOLID_FILL_ID", "MINES_ID", "ROGUELEV_ID", "MESSAGE_ID", "MAZE_ID", + "LEVEL_ID", "LEV_INIT_ID", "GEOMETRY_ID", "NOMAP_ID", "OBJECT_ID", + "COBJECT_ID", "MONSTER_ID", "TRAP_ID", "DOOR_ID", "DRAWBRIDGE_ID", + "object_ID", "monster_ID", "terrain_ID", "MAZEWALK_ID", "WALLIFY_ID", + "REGION_ID", "FILLING", "IRREGULAR", "JOINED", "ALTAR_ID", "LADDER_ID", + "STAIR_ID", "NON_DIGGABLE_ID", "NON_PASSWALL_ID", "ROOM_ID", "PORTAL_ID", + "TELEPRT_ID", "BRANCH_ID", "LEV", "MINERALIZE_ID", "CORRIDOR_ID", + "GOLD_ID", "ENGRAVING_ID", "FOUNTAIN_ID", "POOL_ID", "SINK_ID", "NONE", + "RAND_CORRIDOR_ID", "DOOR_STATE", "LIGHT_STATE", "CURSE_TYPE", + "ENGRAVING_TYPE", "DIRECTION", "RANDOM_TYPE", "RANDOM_TYPE_BRACKET", + "A_REGISTER", "ALIGNMENT", "LEFT_OR_RIGHT", "CENTER", "TOP_OR_BOT", + "ALTAR_TYPE", "UP_OR_DOWN", "SUBROOM_ID", "NAME_ID", "FLAGS_ID", + "FLAG_TYPE", "MON_ATTITUDE", "MON_ALERTNESS", "MON_APPEARANCE", + "ROOMDOOR_ID", "IF_ID", "ELSE_ID", "TERRAIN_ID", "HORIZ_OR_VERT", + "REPLACE_TERRAIN_ID", "EXIT_ID", "SHUFFLE_ID", "QUANTITY_ID", "BURIED_ID", + "LOOP_ID", "FOR_ID", "TO_ID", "SWITCH_ID", "CASE_ID", "BREAK_ID", + "DEFAULT_ID", "ERODED_ID", "TRAPPED_ID", "RECHARGED_ID", "INVIS_ID", + "GREASED_ID", "FEMALE_ID", "CANCELLED_ID", "REVIVED_ID", "AVENGE_ID", + "FLEEING_ID", "BLINDED_ID", "PARALYZED_ID", "STUNNED_ID", "CONFUSED_ID", + "SEENTRAPS_ID", "ALL_ID", "MONTYPE_ID", "GRAVE_ID", "ERODEPROOF_ID", + "FUNCTION_ID", "MSG_OUTPUT_TYPE", "COMPARE_TYPE", "UNKNOWN_TYPE", + "rect_ID", "fillrect_ID", "line_ID", "randline_ID", "grow_ID", + "selection_ID", "flood_ID", "rndcoord_ID", "circle_ID", "ellipse_ID", + "filter_ID", "complement_ID", "gradient_ID", "GRADIENT_TYPE", "LIMITED", + "HUMIDITY_TYPE", "','", "':'", "'('", "')'", "'['", "']'", "'{'", "'}'", + "STRING", "MAP_ID", "NQSTRING", "VARSTRING", "CFUNC", "CFUNC_INT", + "CFUNC_STR", "CFUNC_COORD", "CFUNC_REGION", "VARSTRING_INT", + "VARSTRING_INT_ARRAY", "VARSTRING_STRING", "VARSTRING_STRING_ARRAY", + "VARSTRING_VAR", "VARSTRING_VAR_ARRAY", "VARSTRING_COORD", + "VARSTRING_COORD_ARRAY", "VARSTRING_REGION", "VARSTRING_REGION_ARRAY", + "VARSTRING_MAPCHAR", "VARSTRING_MAPCHAR_ARRAY", "VARSTRING_MONST", + "VARSTRING_MONST_ARRAY", "VARSTRING_OBJ", "VARSTRING_OBJ_ARRAY", + "VARSTRING_SEL", "VARSTRING_SEL_ARRAY", "METHOD_INT", "METHOD_INT_ARRAY", + "METHOD_STRING", "METHOD_STRING_ARRAY", "METHOD_VAR", "METHOD_VAR_ARRAY", + "METHOD_COORD", "METHOD_COORD_ARRAY", "METHOD_REGION", + "METHOD_REGION_ARRAY", "METHOD_MAPCHAR", "METHOD_MAPCHAR_ARRAY", + "METHOD_MONST", "METHOD_MONST_ARRAY", "METHOD_OBJ", "METHOD_OBJ_ARRAY", + "METHOD_SEL", "METHOD_SEL_ARRAY", "DICE", "'+'", "'-'", "'*'", "'/'", + "'%'", "'='", "'.'", "'|'", "'&'", "$accept", "file", "levels", "level", + "level_def", "mazefiller", "lev_init", "opt_limited", "opt_coord_or_var", + "opt_fillchar", "walled", "flags", "flag_list", "levstatements", + "stmt_block", "levstatement", "any_var_array", "any_var", + "any_var_or_arr", "any_var_or_unk", "shuffle_detail", "variable_define", + "encodeobj_list", "encodemonster_list", "mapchar_list", + "encoderegion_list", "encodecoord_list", "integer_list", "string_list", + "function_define", "$@1", "$@2", "function_call", "exitstatement", + "opt_percent", "comparestmt", "switchstatement", "$@3", "$@4", + "switchcases", "switchcase", "$@5", "$@6", "breakstatement", + "for_to_span", "forstmt_start", "forstatement", "$@7", "loopstatement", + "$@8", "chancestatement", "$@9", "ifstatement", "$@10", "if_ending", + "$@11", "message", "random_corridors", "corridor", "corr_spec", + "room_begin", "subroom_def", "$@12", "room_def", "$@13", "roomfill", + "room_pos", "subroom_pos", "room_align", "room_size", "door_detail", + "secret", "door_wall", "dir_list", "door_pos", "map_definition", + "h_justif", "v_justif", "monster_detail", "$@14", "monster_desc", + "monster_infos", "monster_info", "seen_trap_mask", "object_detail", + "$@15", "object_desc", "object_infos", "object_info", "trap_detail", + "drawbridge_detail", "mazewalk_detail", "wallify_detail", "ladder_detail", + "stair_detail", "stair_region", "portal_region", "teleprt_region", + "branch_region", "teleprt_detail", "fountain_detail", "sink_detail", + "pool_detail", "terrain_type", "replace_terrain_detail", "terrain_detail", + "diggable_detail", "passwall_detail", "region_detail", "@16", + "region_detail_end", "altar_detail", "grave_detail", "gold_detail", + "engraving_detail", "mineralize", "trap_name", "room_type", + "optroomregionflags", "roomregionflags", "roomregionflag", "door_state", + "light_state", "alignment", "alignment_prfx", "altar_type", "a_register", + "string_or_var", "integer_or_var", "coord_or_var", "encodecoord", + "humidity_flags", "region_or_var", "encoderegion", "mapchar_or_var", + "mapchar", "monster_or_var", "encodemonster", "object_or_var", + "encodeobj", "string_expr", "math_expr_var", "func_param_type", + "func_param_part", "func_param_list", "func_params_list", + "func_call_param_part", "func_call_param_list", "func_call_params_list", + "ter_selection_x", "ter_selection", "dice", "all_integers", + "all_ints_push", "objectid", "monsterid", "terrainid", "engraving_type", + "lev_region", "region", YY_NULLPTR }; #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, - 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, - 385, 44, 58, 40, 41, 91, 93, 123, 125, 386, - 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, - 427, 428, 429, 430, 431, 43, 45, 42, 47, 37, - 61, 46, 124, 38 +static const yytype_uint16 yytoknum[] = { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, + 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, + 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 44, 58, 40, 41, + 91, 93, 123, 125, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 430, 431, 43, 45, 42, 47, 37, 61, 46, 124, 38 }; -# endif +#endif #define YYPACT_NINF -654 -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-654))) +#define yypact_value_is_default(Yystate) (!!((Yystate) == (-654))) #define YYTABLE_NINF -202 -#define yytable_value_is_error(Yytable_value) \ - 0 +#define yytable_value_is_error(Yytable_value) 0 - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - 137, 7, 27, 83, -654, 137, 24, -15, 37, -654, - -654, 91, 733, -10, -654, 113, -654, 99, 131, 133, - -654, 161, 164, 166, 174, 183, 199, 214, 231, 233, - 239, 241, 243, 245, 247, 250, 268, 269, 275, 276, - 281, 295, 305, 317, 322, 323, 325, 326, 327, 28, - 340, 343, -654, 345, 205, 757, -654, -654, 346, 49, - 66, 265, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, 733, -654, -654, 190, -654, -654, -654, - -654, -654, 353, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, 59, 308, -654, -31, 406, 351, 58, 58, - 144, -11, 57, -18, -18, 672, -57, -18, -18, 248, - -57, -57, -6, -1, -1, -1, 66, 303, 66, -18, - 672, 672, 672, 319, -6, 51, -654, 672, -57, 751, - 66, -654, -654, 279, 339, -18, 355, -654, 29, -654, - 344, -654, 198, -654, 56, -654, 18, -654, 359, -654, - -654, -654, 113, -654, -654, 360, -654, 309, 368, 371, - 372, -654, -654, 374, -654, -654, 375, 503, -654, 378, - 379, 383, -654, -654, -654, 506, -654, -654, 402, -654, - -654, -654, -654, -654, -654, 537, -654, -654, 413, 404, - 418, -654, -654, -654, 420, -654, -654, 427, 439, 446, - -57, -57, -18, -18, 417, -18, 436, 445, 449, 672, - 450, 508, -654, -654, 391, -654, 582, -654, 453, 458, - -654, 459, 460, 466, 599, 473, 474, -654, -654, -654, - -654, -654, 475, 601, 608, 482, 483, 489, 490, 387, - 618, 526, 208, 529, -654, -654, -654, -654, -654, -654, - -654, -654, 530, -654, -654, 534, 359, 538, 539, -654, - 523, 66, 66, 540, -654, 548, 342, 66, 66, -654, - 66, 66, 66, 66, 66, 309, 387, -654, 542, 549, - -654, -654, -654, -654, -654, -654, 554, 60, 32, -654, - -654, 309, 387, 555, 556, 558, 733, 733, -654, -654, - 66, -31, 671, 46, 698, 571, 567, 672, 573, 66, - 215, 700, 566, 581, 66, 587, 359, 589, 66, 359, - -18, -18, 672, 663, 664, -654, -654, 592, 593, 521, - -654, -18, -18, 307, -654, 598, 596, 672, 597, 66, - 67, 186, 660, 730, 604, 669, -1, 8, -654, 606, - 607, -1, -1, -1, 66, 609, 89, -18, 141, 12, - 57, 665, -654, 52, 52, -654, 156, 605, -38, 697, - -654, -654, 331, 347, 168, 168, -654, -654, -654, 56, - -654, 672, 612, -52, -50, 4, 140, -654, -654, 309, - 387, 55, 127, 158, -654, 611, 358, -654, -654, -654, - 743, -654, 628, 374, -654, 626, 761, 430, -654, -654, - 383, -654, -654, 627, 464, 266, -654, 638, 492, -654, - -654, -654, -654, 636, 654, -18, -18, 600, 673, 666, - 675, 676, -654, 679, 438, -654, 667, 681, -654, 685, - 686, -654, -654, 799, 522, -654, -654, 689, -654, 687, - -654, 693, -654, -654, 694, 824, -654, 699, -654, 825, - 701, 67, 827, 702, 703, -654, 704, 779, -654, -654, - -654, -654, -654, 707, -654, 836, 710, 712, 786, 861, - -654, 734, 359, -654, 678, 66, -654, -654, 309, 735, - -654, 739, 732, -654, -654, -654, -654, 867, 740, -654, - -8, -654, 66, -654, -31, -654, 21, -654, 25, -654, - 54, -654, -654, -654, 741, 873, -654, -654, 744, -654, - 737, 745, -654, -654, -654, -654, -654, -654, -654, 748, - 769, -654, 771, -654, 788, -654, -654, 790, -654, -654, - -654, -654, -654, 784, -654, 792, 57, 919, -654, 794, - 868, 672, -654, 66, 66, 672, 796, 66, 672, 672, - 795, 798, -654, -6, 926, 90, 927, -49, 865, 802, - 13, -654, 803, 797, 870, -654, 66, 804, -31, 807, - 15, 254, 359, 52, -654, -654, 387, 805, 224, 697, - -654, -29, -654, -654, 387, 309, 151, -654, 159, -654, - 171, -654, 67, 808, -654, -654, -654, -31, 66, 66, - 66, 144, -654, 594, -654, 809, 66, -654, 810, 258, - 337, 811, 67, 528, 812, 813, 66, 937, 817, 814, - -654, -654, -654, 818, 939, -654, 947, -654, 289, 821, - -654, -654, 822, 85, 309, 950, -654, 951, 817, -654, - 826, -654, -654, 828, 160, -654, -654, -654, -654, 359, - 21, -654, 25, -654, 54, -654, 829, 953, 309, -654, - -654, -654, -654, 149, -654, -654, -654, -31, -654, -654, - -654, -654, -654, 830, 832, 833, -654, -654, 834, -654, - -654, -654, 309, 957, -654, 387, -654, 924, -654, 66, - -654, 835, -654, -654, -654, 409, 837, 419, -654, -654, - 963, 839, 838, 840, 15, 66, -654, -654, 841, 842, - 843, -654, 85, 954, 329, 845, 844, 160, -654, -654, - -654, -654, -654, 847, 914, 309, 66, 66, 66, -44, - -654, 846, 304, -654, 66, 975, -654, -654, -654, -654, - 850, 359, 852, 980, -654, 215, 817, -654, -654, -654, - 981, 359, -654, -654, 854, -654, -654, -654, 982, -654, - -654, -654, -654, -654, 800, -654, -654, 956, -654, 217, - 855, 419, -654, -654, 986, 857, 859, -654, 860, -654, - -654, 733, 864, -44, 862, 869, 863, -654, -654, 866, - -654, -654, 359, -654, 733, -654, 67, -654, -654, -654, - 871, -654, -654, -654, 872, -18, 68, 874, -654, -654, - 809, -18, 875, -654, -654, -654 +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = { + 137, 7, 27, 83, -654, 137, 24, -15, 37, -654, -654, 91, + 733, -10, -654, 113, -654, 99, 131, 133, -654, 161, 164, 166, + 174, 183, 199, 214, 231, 233, 239, 241, 243, 245, 247, 250, + 268, 269, 275, 276, 281, 295, 305, 317, 322, 323, 325, 326, + 327, 28, 340, 343, -654, 345, 205, 757, -654, -654, 346, 49, + 66, 265, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, 733, + -654, -654, 190, -654, -654, -654, -654, -654, 353, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, + 59, 308, -654, -31, 406, 351, 58, 58, 144, -11, 57, -18, + -18, 672, -57, -18, -18, 248, -57, -57, -6, -1, -1, -1, + 66, 303, 66, -18, 672, 672, 672, 319, -6, 51, -654, 672, + -57, 751, 66, -654, -654, 279, 339, -18, 355, -654, 29, -654, + 344, -654, 198, -654, 56, -654, 18, -654, 359, -654, -654, -654, + 113, -654, -654, 360, -654, 309, 368, 371, 372, -654, -654, 374, + -654, -654, 375, 503, -654, 378, 379, 383, -654, -654, -654, 506, + -654, -654, 402, -654, -654, -654, -654, -654, -654, 537, -654, -654, + 413, 404, 418, -654, -654, -654, 420, -654, -654, 427, 439, 446, + -57, -57, -18, -18, 417, -18, 436, 445, 449, 672, 450, 508, + -654, -654, 391, -654, 582, -654, 453, 458, -654, 459, 460, 466, + 599, 473, 474, -654, -654, -654, -654, -654, 475, 601, 608, 482, + 483, 489, 490, 387, 618, 526, 208, 529, -654, -654, -654, -654, + -654, -654, -654, -654, 530, -654, -654, 534, 359, 538, 539, -654, + 523, 66, 66, 540, -654, 548, 342, 66, 66, -654, 66, 66, + 66, 66, 66, 309, 387, -654, 542, 549, -654, -654, -654, -654, + -654, -654, 554, 60, 32, -654, -654, 309, 387, 555, 556, 558, + 733, 733, -654, -654, 66, -31, 671, 46, 698, 571, 567, 672, + 573, 66, 215, 700, 566, 581, 66, 587, 359, 589, 66, 359, + -18, -18, 672, 663, 664, -654, -654, 592, 593, 521, -654, -18, + -18, 307, -654, 598, 596, 672, 597, 66, 67, 186, 660, 730, + 604, 669, -1, 8, -654, 606, 607, -1, -1, -1, 66, 609, + 89, -18, 141, 12, 57, 665, -654, 52, 52, -654, 156, 605, + -38, 697, -654, -654, 331, 347, 168, 168, -654, -654, -654, 56, + -654, 672, 612, -52, -50, 4, 140, -654, -654, 309, 387, 55, + 127, 158, -654, 611, 358, -654, -654, -654, 743, -654, 628, 374, + -654, 626, 761, 430, -654, -654, 383, -654, -654, 627, 464, 266, + -654, 638, 492, -654, -654, -654, -654, 636, 654, -18, -18, 600, + 673, 666, 675, 676, -654, 679, 438, -654, 667, 681, -654, 685, + 686, -654, -654, 799, 522, -654, -654, 689, -654, 687, -654, 693, + -654, -654, 694, 824, -654, 699, -654, 825, 701, 67, 827, 702, + 703, -654, 704, 779, -654, -654, -654, -654, -654, 707, -654, 836, + 710, 712, 786, 861, -654, 734, 359, -654, 678, 66, -654, -654, + 309, 735, -654, 739, 732, -654, -654, -654, -654, 867, 740, -654, + -8, -654, 66, -654, -31, -654, 21, -654, 25, -654, 54, -654, + -654, -654, 741, 873, -654, -654, 744, -654, 737, 745, -654, -654, + -654, -654, -654, -654, -654, 748, 769, -654, 771, -654, 788, -654, + -654, 790, -654, -654, -654, -654, -654, 784, -654, 792, 57, 919, + -654, 794, 868, 672, -654, 66, 66, 672, 796, 66, 672, 672, + 795, 798, -654, -6, 926, 90, 927, -49, 865, 802, 13, -654, + 803, 797, 870, -654, 66, 804, -31, 807, 15, 254, 359, 52, + -654, -654, 387, 805, 224, 697, -654, -29, -654, -654, 387, 309, + 151, -654, 159, -654, 171, -654, 67, 808, -654, -654, -654, -31, + 66, 66, 66, 144, -654, 594, -654, 809, 66, -654, 810, 258, + 337, 811, 67, 528, 812, 813, 66, 937, 817, 814, -654, -654, + -654, 818, 939, -654, 947, -654, 289, 821, -654, -654, 822, 85, + 309, 950, -654, 951, 817, -654, 826, -654, -654, 828, 160, -654, + -654, -654, -654, 359, 21, -654, 25, -654, 54, -654, 829, 953, + 309, -654, -654, -654, -654, 149, -654, -654, -654, -31, -654, -654, + -654, -654, -654, 830, 832, 833, -654, -654, 834, -654, -654, -654, + 309, 957, -654, 387, -654, 924, -654, 66, -654, 835, -654, -654, + -654, 409, 837, 419, -654, -654, 963, 839, 838, 840, 15, 66, + -654, -654, 841, 842, 843, -654, 85, 954, 329, 845, 844, 160, + -654, -654, -654, -654, -654, 847, 914, 309, 66, 66, 66, -44, + -654, 846, 304, -654, 66, 975, -654, -654, -654, -654, 850, 359, + 852, 980, -654, 215, 817, -654, -654, -654, 981, 359, -654, -654, + 854, -654, -654, -654, 982, -654, -654, -654, -654, -654, 800, -654, + -654, 956, -654, 217, 855, 419, -654, -654, 986, 857, 859, -654, + 860, -654, -654, 733, 864, -44, 862, 869, 863, -654, -654, 866, + -654, -654, 359, -654, 733, -654, 67, -654, -654, -654, 871, -654, + -654, -654, 872, -18, 68, 874, -654, -654, 809, -18, 875, -654, + -654, -654 }; - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint16 yydefact[] = -{ - 2, 0, 0, 0, 3, 4, 23, 0, 0, 1, - 5, 0, 27, 0, 7, 0, 134, 0, 0, 0, - 193, 0, 0, 0, 0, 0, 0, 0, 250, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 280, - 0, 0, 0, 0, 0, 0, 162, 0, 0, 0, - 0, 0, 131, 0, 0, 0, 137, 146, 0, 0, - 0, 0, 94, 83, 74, 84, 75, 85, 76, 86, - 77, 87, 78, 88, 79, 89, 80, 90, 81, 91, - 82, 31, 6, 27, 92, 93, 0, 37, 36, 52, - 53, 50, 0, 45, 51, 150, 46, 47, 49, 48, - 30, 62, 35, 65, 64, 39, 55, 57, 58, 72, - 40, 56, 73, 54, 69, 70, 61, 71, 34, 43, - 66, 60, 68, 67, 38, 59, 63, 32, 33, 44, - 41, 42, 0, 26, 24, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 156, 0, 0, 0, - 0, 95, 96, 0, 0, 0, 0, 343, 0, 346, - 0, 388, 0, 344, 365, 28, 0, 154, 0, 10, - 9, 8, 0, 305, 306, 0, 341, 161, 0, 0, - 0, 13, 314, 0, 196, 197, 0, 0, 311, 0, - 0, 173, 309, 338, 340, 0, 337, 335, 0, 225, - 229, 334, 226, 331, 333, 0, 330, 328, 0, 200, - 0, 327, 282, 281, 0, 292, 293, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 384, 367, 386, 251, 0, 319, 0, 0, - 318, 0, 0, 0, 0, 0, 0, 404, 267, 268, - 284, 283, 0, 132, 0, 0, 0, 0, 0, 308, - 0, 0, 0, 0, 260, 262, 261, 391, 389, 390, - 164, 163, 0, 185, 186, 0, 0, 0, 0, 97, - 0, 0, 0, 276, 127, 0, 0, 0, 0, 136, - 0, 0, 0, 0, 0, 362, 361, 363, 366, 0, - 397, 399, 396, 398, 400, 401, 0, 0, 0, 104, - 105, 100, 98, 0, 0, 0, 0, 27, 151, 25, - 0, 0, 0, 0, 0, 316, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 368, 369, 0, 0, 0, - 377, 0, 0, 0, 383, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 133, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 158, 157, 0, 0, 152, 0, 0, 0, 359, - 345, 353, 0, 0, 348, 349, 350, 351, 352, 0, - 130, 0, 343, 0, 0, 0, 0, 121, 119, 125, - 123, 0, 0, 0, 155, 0, 0, 342, 12, 263, - 0, 11, 0, 0, 315, 0, 0, 0, 199, 198, - 173, 174, 195, 0, 0, 0, 227, 0, 0, 202, - 204, 246, 184, 0, 248, 0, 0, 189, 0, 0, - 0, 0, 325, 0, 0, 323, 0, 0, 322, 0, - 0, 385, 387, 0, 0, 294, 295, 0, 298, 0, - 296, 0, 297, 252, 0, 0, 253, 0, 176, 0, - 0, 0, 0, 0, 258, 257, 0, 0, 165, 166, - 277, 402, 403, 0, 178, 0, 0, 0, 0, 0, - 266, 0, 0, 148, 0, 0, 138, 275, 274, 0, - 357, 360, 0, 347, 135, 364, 99, 0, 0, 108, - 0, 107, 0, 106, 0, 112, 0, 103, 0, 102, - 0, 101, 29, 307, 0, 0, 317, 310, 0, 312, - 0, 0, 336, 394, 392, 393, 240, 237, 231, 0, - 0, 236, 0, 241, 0, 243, 244, 0, 239, 230, - 245, 395, 233, 0, 329, 203, 0, 0, 370, 0, - 0, 0, 372, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 320, 0, 0, 0, 0, 0, 0, 0, - 0, 168, 0, 0, 0, 256, 0, 0, 0, 0, - 0, 0, 0, 0, 153, 147, 149, 0, 0, 0, - 128, 0, 120, 122, 124, 126, 0, 113, 0, 115, - 0, 117, 0, 0, 313, 194, 339, 0, 0, 0, - 0, 0, 332, 0, 247, 19, 0, 190, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 285, 0, - 303, 302, 273, 0, 0, 254, 0, 180, 0, 0, - 255, 259, 0, 0, 278, 0, 182, 0, 285, 188, - 0, 187, 160, 0, 140, 354, 355, 356, 358, 0, - 0, 111, 0, 110, 0, 109, 0, 0, 234, 235, - 238, 242, 232, 0, 299, 207, 208, 0, 212, 211, - 213, 214, 215, 0, 0, 0, 219, 220, 0, 205, - 209, 300, 206, 0, 249, 371, 373, 0, 378, 0, - 374, 0, 324, 376, 375, 0, 0, 0, 269, 304, - 0, 0, 0, 0, 0, 0, 191, 192, 0, 0, - 0, 169, 0, 0, 0, 0, 0, 140, 129, 114, - 116, 118, 264, 0, 0, 210, 0, 0, 0, 0, - 20, 0, 0, 326, 0, 0, 289, 290, 291, 286, - 287, 271, 0, 0, 175, 0, 285, 279, 167, 177, - 0, 0, 183, 265, 0, 144, 139, 141, 0, 301, - 216, 217, 218, 223, 222, 221, 379, 0, 380, 349, - 0, 0, 272, 270, 0, 0, 0, 171, 0, 170, - 142, 27, 0, 0, 0, 0, 0, 321, 288, 0, - 406, 179, 0, 181, 27, 145, 0, 224, 381, 16, - 0, 405, 172, 143, 0, 0, 0, 17, 21, 22, - 19, 0, 0, 14, 18, 382 +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint16 yydefact[] = { + 2, 0, 0, 0, 3, 4, 23, 0, 0, 1, 5, 0, 27, 0, 7, + 0, 134, 0, 0, 0, 193, 0, 0, 0, 0, 0, 0, 0, 250, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 280, 0, 0, 0, 0, 0, + 0, 162, 0, 0, 0, 0, 0, 131, 0, 0, 0, 137, 146, 0, 0, + 0, 0, 94, 83, 74, 84, 75, 85, 76, 86, 77, 87, 78, 88, 79, + 89, 80, 90, 81, 91, 82, 31, 6, 27, 92, 93, 0, 37, 36, 52, + 53, 50, 0, 45, 51, 150, 46, 47, 49, 48, 30, 62, 35, 65, 64, + 39, 55, 57, 58, 72, 40, 56, 73, 54, 69, 70, 61, 71, 34, 43, + 66, 60, 68, 67, 38, 59, 63, 32, 33, 44, 41, 42, 0, 26, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 156, 0, 0, 0, 0, 95, 96, 0, 0, 0, 0, 343, 0, 346, + 0, 388, 0, 344, 365, 28, 0, 154, 0, 10, 9, 8, 0, 305, 306, + 0, 341, 161, 0, 0, 0, 13, 314, 0, 196, 197, 0, 0, 311, 0, + 0, 173, 309, 338, 340, 0, 337, 335, 0, 225, 229, 334, 226, 331, 333, + 0, 330, 328, 0, 200, 0, 327, 282, 281, 0, 292, 293, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 384, 367, 386, + 251, 0, 319, 0, 0, 318, 0, 0, 0, 0, 0, 0, 404, 267, 268, + 284, 283, 0, 132, 0, 0, 0, 0, 0, 308, 0, 0, 0, 0, 260, + 262, 261, 391, 389, 390, 164, 163, 0, 185, 186, 0, 0, 0, 0, 97, + 0, 0, 0, 276, 127, 0, 0, 0, 0, 136, 0, 0, 0, 0, 0, + 362, 361, 363, 366, 0, 397, 399, 396, 398, 400, 401, 0, 0, 0, 104, + 105, 100, 98, 0, 0, 0, 0, 27, 151, 25, 0, 0, 0, 0, 0, + 316, 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 368, 369, 0, 0, 0, 377, 0, 0, 0, 383, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 133, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158, 157, 0, 0, + 152, 0, 0, 0, 359, 345, 353, 0, 0, 348, 349, 350, 351, 352, 0, + 130, 0, 343, 0, 0, 0, 0, 121, 119, 125, 123, 0, 0, 0, 155, + 0, 0, 342, 12, 263, 0, 11, 0, 0, 315, 0, 0, 0, 199, 198, + 173, 174, 195, 0, 0, 0, 227, 0, 0, 202, 204, 246, 184, 0, 248, + 0, 0, 189, 0, 0, 0, 0, 325, 0, 0, 323, 0, 0, 322, 0, + 0, 385, 387, 0, 0, 294, 295, 0, 298, 0, 296, 0, 297, 252, 0, + 0, 253, 0, 176, 0, 0, 0, 0, 0, 258, 257, 0, 0, 165, 166, + 277, 402, 403, 0, 178, 0, 0, 0, 0, 0, 266, 0, 0, 148, 0, + 0, 138, 275, 274, 0, 357, 360, 0, 347, 135, 364, 99, 0, 0, 108, + 0, 107, 0, 106, 0, 112, 0, 103, 0, 102, 0, 101, 29, 307, 0, + 0, 317, 310, 0, 312, 0, 0, 336, 394, 392, 393, 240, 237, 231, 0, + 0, 236, 0, 241, 0, 243, 244, 0, 239, 230, 245, 395, 233, 0, 329, + 203, 0, 0, 370, 0, 0, 0, 372, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 320, 0, 0, 0, 0, 0, 0, 0, 0, 168, 0, 0, 0, + 256, 0, 0, 0, 0, 0, 0, 0, 0, 153, 147, 149, 0, 0, 0, + 128, 0, 120, 122, 124, 126, 0, 113, 0, 115, 0, 117, 0, 0, 313, + 194, 339, 0, 0, 0, 0, 0, 332, 0, 247, 19, 0, 190, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 285, 0, 303, 302, 273, 0, 0, + 254, 0, 180, 0, 0, 255, 259, 0, 0, 278, 0, 182, 0, 285, 188, + 0, 187, 160, 0, 140, 354, 355, 356, 358, 0, 0, 111, 0, 110, 0, + 109, 0, 0, 234, 235, 238, 242, 232, 0, 299, 207, 208, 0, 212, 211, + 213, 214, 215, 0, 0, 0, 219, 220, 0, 205, 209, 300, 206, 0, 249, + 371, 373, 0, 378, 0, 374, 0, 324, 376, 375, 0, 0, 0, 269, 304, + 0, 0, 0, 0, 0, 0, 191, 192, 0, 0, 0, 169, 0, 0, 0, + 0, 0, 140, 129, 114, 116, 118, 264, 0, 0, 210, 0, 0, 0, 0, + 20, 0, 0, 326, 0, 0, 289, 290, 291, 286, 287, 271, 0, 0, 175, + 0, 285, 279, 167, 177, 0, 0, 183, 265, 0, 144, 139, 141, 0, 301, + 216, 217, 218, 223, 222, 221, 379, 0, 380, 349, 0, 0, 272, 270, 0, + 0, 0, 171, 0, 170, 142, 27, 0, 0, 0, 0, 0, 321, 288, 0, + 406, 179, 0, 181, 27, 145, 0, 224, 381, 16, 0, 405, 172, 143, 0, + 0, 0, 17, 21, 22, 19, 0, 0, 14, 18, 382 }; - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -654, -654, 994, -654, -654, -654, -654, -654, -654, 146, - -654, -654, 815, -83, -290, 668, 848, 946, -390, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, 959, -654, -654, -654, 244, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, 614, - 849, -654, -654, -654, -654, 562, -654, -654, -654, 260, - -654, -654, -654, -531, 253, -654, 338, 223, -654, -654, - -654, -654, -654, 187, -654, -654, 880, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, - -654, -654, -654, -654, -654, -654, -654, 421, -653, 200, - -654, -385, -492, -654, -654, -654, 369, 682, -168, -136, - -312, 583, 150, -308, -386, -485, -418, -473, 602, -459, - -132, -55, -654, 396, -654, -654, 610, -654, -654, 778, - -135, 575, -392, -654, -654, -654, -654, -654, -124, -654 +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = { + -654, -654, 994, -654, -654, -654, -654, -654, -654, 146, -654, -654, + 815, -83, -290, 668, 848, 946, -390, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, 959, + -654, -654, -654, 244, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, 614, + 849, -654, -654, -654, -654, 562, -654, -654, -654, 260, -654, -654, + -654, -531, 253, -654, 338, 223, -654, -654, -654, -654, -654, 187, + -654, -654, 880, -654, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, -654, + -654, -654, -654, -654, -654, -654, -654, -654, -654, 421, -653, 200, + -654, -385, -492, -654, -654, -654, 369, 682, -168, -136, -312, 583, + 150, -308, -386, -485, -418, -473, 602, -459, -132, -55, -654, 396, + -654, -654, 610, -654, -654, 778, -135, 575, -392, -654, -654, -654, + -654, -654, -124, -654 }; - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 3, 4, 5, 6, 191, 81, 836, 862, 734, - 860, 12, 134, 82, 338, 83, 84, 85, 86, 173, - 87, 88, 636, 638, 640, 423, 424, 425, 426, 89, - 409, 699, 90, 91, 389, 92, 93, 174, 627, 766, - 767, 844, 831, 94, 525, 95, 96, 188, 97, 522, - 98, 336, 99, 296, 402, 518, 100, 101, 102, 281, - 272, 103, 801, 104, 842, 352, 500, 516, 679, 688, - 105, 295, 690, 468, 758, 106, 210, 450, 107, 359, - 229, 585, 729, 815, 108, 356, 219, 355, 579, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 615, - 119, 120, 121, 441, 122, 123, 124, 125, 126, 791, - 823, 127, 128, 129, 130, 131, 234, 273, 748, 789, - 790, 237, 487, 491, 730, 672, 492, 196, 278, 253, - 212, 346, 259, 260, 477, 478, 230, 231, 220, 221, - 315, 279, 697, 530, 531, 532, 317, 318, 319, 254, - 376, 183, 291, 582, 333, 334, 335, 513, 266, 267 +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = { + -1, 3, 4, 5, 6, 191, 81, 836, 862, 734, 860, 12, 134, 82, 338, + 83, 84, 85, 86, 173, 87, 88, 636, 638, 640, 423, 424, 425, 426, 89, + 409, 699, 90, 91, 389, 92, 93, 174, 627, 766, 767, 844, 831, 94, 525, + 95, 96, 188, 97, 522, 98, 336, 99, 296, 402, 518, 100, 101, 102, 281, + 272, 103, 801, 104, 842, 352, 500, 516, 679, 688, 105, 295, 690, 468, 758, + 106, 210, 450, 107, 359, 229, 585, 729, 815, 108, 356, 219, 355, 579, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 615, 119, 120, 121, 441, 122, + 123, 124, 125, 126, 791, 823, 127, 128, 129, 130, 131, 234, 273, 748, 789, + 790, 237, 487, 491, 730, 672, 492, 196, 278, 253, 212, 346, 259, 260, 477, + 478, 230, 231, 220, 221, 315, 279, 697, 530, 531, 532, 317, 318, 319, 254, + 376, 183, 291, 582, 333, 334, 335, 513, 266, 267 }; - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 185, 211, 300, 197, 509, 182, 401, 238, 239, 611, - 255, 261, 262, 265, 549, 517, 427, 520, 521, 529, - 428, 527, 177, 283, 213, 284, 285, 286, 223, 275, - 276, 277, 297, 177, 16, 761, 177, 305, 320, 303, - 321, 202, 203, 263, 322, 323, 324, 551, 232, 439, - 329, 202, 203, 270, 331, 472, 293, 472, 213, 657, - 177, 213, 189, 813, 422, 641, 456, 498, 305, 459, - 177, 514, 677, 858, 686, 639, 256, 202, 203, 538, - 214, 540, 674, 9, 224, 644, 539, 637, 541, 756, - 691, 202, 203, 287, 11, 814, 325, 288, 289, 257, - 258, 193, 667, 282, 206, 644, 367, 368, 193, 370, - 294, 235, 194, 195, 214, 207, 236, 214, 190, 194, - 195, 132, 485, 306, 13, 207, 486, 859, 233, 316, - 223, 332, 274, 271, 407, 542, 208, 209, 326, 7, - 206, 499, 543, 827, 757, 515, 678, 223, 687, 670, - 706, 327, 1, 2, 215, 328, 671, 193, 225, 8, - 216, 472, 178, 60, 226, 327, 179, 180, 194, 195, - 741, 193, 208, 209, 257, 258, 14, 179, 180, 440, - 179, 180, 194, 195, 133, 519, 224, 519, 215, 178, - 176, 215, 546, 178, 216, 193, 429, 216, 511, 178, - 512, 654, 181, 224, 179, 180, 194, 195, 179, 180, - 475, 476, 445, 181, 179, 180, 181, 217, 218, 771, - 217, 218, 280, 15, 460, 461, 506, 462, 633, 770, - 632, 135, 624, 712, 469, 470, 471, 693, 479, 529, - 181, 769, 482, 523, 181, 488, 406, 489, 490, 764, - 181, 765, 412, 413, 435, 414, 415, 416, 417, 418, - 225, 510, 497, 136, 548, 137, 226, 503, 504, 505, - 563, 544, 306, 430, 564, 565, 528, 225, 545, 448, - 449, 774, 700, 226, 604, 436, 536, 227, 228, 701, - 702, 519, 263, 138, 447, 550, 139, 703, 140, 454, - 268, 269, 704, 458, 227, 228, 141, 202, 203, 705, - 472, 308, 467, 689, 473, 142, 475, 476, 298, 580, - 566, 567, 568, 287, 484, 202, 203, 288, 289, 588, - 589, 143, 692, 287, 309, 569, 330, 288, 289, 397, - 170, 310, 311, 312, 313, 314, 144, 524, 835, 570, - 571, -15, 204, 205, 854, 312, 313, 314, 572, 573, - 574, 575, 576, 145, 316, 146, 202, 203, 695, 696, - 206, 147, 804, 148, 577, 149, 578, 150, 290, 151, - 186, 264, 152, 310, 311, 312, 313, 314, 206, 737, - 365, 366, 738, 310, 311, 312, 313, 314, 184, 207, - 153, 154, 208, 209, 312, 313, 314, 155, 156, 768, - 202, 203, 635, 157, 204, 205, 198, 199, 200, 201, - 208, 209, 240, 241, 242, 243, 244, 158, 245, 206, - 246, 247, 248, 249, 250, 817, 280, 159, 818, 192, - 474, 596, 348, 310, 311, 312, 313, 314, 682, 160, - 181, 786, 787, 788, 161, 162, 658, 163, 164, 165, - 661, 208, 209, 664, 665, 475, 476, 533, 739, 301, - 626, 252, 167, 206, 302, 168, 411, 169, 175, 307, - 709, 710, 711, 534, 207, 187, 684, 634, 304, 310, - 311, 312, 313, 314, 553, 340, 337, 202, 203, 342, - 341, 822, 343, 344, 345, 208, 209, 348, 347, 353, - 350, 829, 348, 349, 351, 708, 310, 311, 312, 313, - 314, 732, 310, 311, 312, 313, 314, 310, 311, 312, - 313, 314, 310, 311, 312, 313, 314, 354, 659, 660, - 357, -201, 663, 310, 311, 312, 313, 314, 358, 360, - 369, 361, 852, 240, 241, 242, 243, 244, 362, 245, - 206, 246, 247, 248, 249, 250, 559, 202, 203, 371, - 363, 251, 310, 311, 312, 313, 314, 364, 372, 467, - 202, 203, 373, 375, 377, 775, 378, 797, 379, 380, - 381, 382, 208, 209, 310, 784, 312, 313, 314, 383, - 562, 735, 252, 384, 385, 386, 387, 388, 810, 811, - 812, 745, 390, 391, 392, 310, 311, 312, 313, 314, - 393, 394, 395, 240, 241, 242, 243, 244, 584, 245, - 206, 246, 247, 248, 249, 250, 240, 241, 242, 243, - 244, 251, 245, 206, 246, 247, 248, 249, 250, 310, - 311, 312, 313, 314, 251, 713, 714, 396, 602, 405, - 398, 399, 208, 209, 742, 400, 715, 716, 717, 403, - 404, 408, 252, 419, 438, 208, 209, 310, 311, 312, - 313, 314, 410, 420, 782, 252, 421, 431, 432, 718, - 433, 719, 720, 721, 722, 723, 724, 725, 726, 727, - 728, 442, 443, 444, 446, 451, 452, 310, 311, 312, - 313, 314, 453, 310, 311, 312, 313, 314, 455, 857, - 457, 463, 464, 465, 466, 864, 480, 493, 483, 819, - 481, 202, 203, 193, 494, 495, 496, 501, 502, 16, - 507, 526, -159, 537, 194, 195, 554, 17, 845, 552, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 555, - 557, 853, 27, 28, 29, 558, 561, 586, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 583, 39, 40, - 41, 42, 43, 44, 45, 587, 46, 240, 241, 242, - 243, 244, 590, 245, 206, 246, 247, 248, 249, 250, - 592, 47, 597, 601, 591, 251, 593, 594, 48, 49, - 595, 50, 598, 51, 52, 53, 599, 600, 54, 55, - 603, 56, 604, 57, 605, 606, 208, 209, 607, 609, - 608, 612, 610, 613, 614, 616, 252, 617, 618, 62, - 619, 620, 58, 621, 59, 63, 64, 65, 66, 67, - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, 80, 622, 596, 623, 630, 628, 60, 625, - 629, 631, 642, 256, 61, 62, 643, 645, 644, 646, - 647, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80, 171, - 64, 648, 66, 649, 68, 63, 70, 65, 72, 67, - 74, 69, 76, 71, 78, 73, 80, 75, 652, 77, - 650, 79, 651, 653, 655, 656, 467, 662, 666, 667, - 669, 673, 675, 676, 674, 683, 680, 681, 685, 707, - 733, 746, 694, 751, 736, 740, 743, 744, 747, 750, - 749, 752, 754, 755, 759, 760, 781, 762, 773, 763, - 780, 803, 776, 772, 777, 778, 779, 792, 785, 783, - 793, 795, 794, 809, 800, 798, 799, 805, 808, 820, - 816, 821, 806, 824, 825, 828, 830, 832, 834, 837, - 839, 840, 833, 841, 843, 846, 848, 850, 849, 10, - 851, 172, 855, 856, 434, 861, 863, 339, 166, 865, - 508, 807, 560, 292, 796, 802, 753, 299, 826, 222, - 847, 838, 731, 437, 668, 698, 556, 374, 0, 535, - 581, 0, 0, 547 +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = { + 185, 211, 300, 197, 509, 182, 401, 238, 239, 611, 255, 261, 262, 265, + 549, 517, 427, 520, 521, 529, 428, 527, 177, 283, 213, 284, 285, 286, + 223, 275, 276, 277, 297, 177, 16, 761, 177, 305, 320, 303, 321, 202, + 203, 263, 322, 323, 324, 551, 232, 439, 329, 202, 203, 270, 331, 472, + 293, 472, 213, 657, 177, 213, 189, 813, 422, 641, 456, 498, 305, 459, + 177, 514, 677, 858, 686, 639, 256, 202, 203, 538, 214, 540, 674, 9, + 224, 644, 539, 637, 541, 756, 691, 202, 203, 287, 11, 814, 325, 288, + 289, 257, 258, 193, 667, 282, 206, 644, 367, 368, 193, 370, 294, 235, + 194, 195, 214, 207, 236, 214, 190, 194, 195, 132, 485, 306, 13, 207, + 486, 859, 233, 316, 223, 332, 274, 271, 407, 542, 208, 209, 326, 7, + 206, 499, 543, 827, 757, 515, 678, 223, 687, 670, 706, 327, 1, 2, + 215, 328, 671, 193, 225, 8, 216, 472, 178, 60, 226, 327, 179, 180, + 194, 195, 741, 193, 208, 209, 257, 258, 14, 179, 180, 440, 179, 180, + 194, 195, 133, 519, 224, 519, 215, 178, 176, 215, 546, 178, 216, 193, + 429, 216, 511, 178, 512, 654, 181, 224, 179, 180, 194, 195, 179, 180, + 475, 476, 445, 181, 179, 180, 181, 217, 218, 771, 217, 218, 280, 15, + 460, 461, 506, 462, 633, 770, 632, 135, 624, 712, 469, 470, 471, 693, + 479, 529, 181, 769, 482, 523, 181, 488, 406, 489, 490, 764, 181, 765, + 412, 413, 435, 414, 415, 416, 417, 418, 225, 510, 497, 136, 548, 137, + 226, 503, 504, 505, 563, 544, 306, 430, 564, 565, 528, 225, 545, 448, + 449, 774, 700, 226, 604, 436, 536, 227, 228, 701, 702, 519, 263, 138, + 447, 550, 139, 703, 140, 454, 268, 269, 704, 458, 227, 228, 141, 202, + 203, 705, 472, 308, 467, 689, 473, 142, 475, 476, 298, 580, 566, 567, + 568, 287, 484, 202, 203, 288, 289, 588, 589, 143, 692, 287, 309, 569, + 330, 288, 289, 397, 170, 310, 311, 312, 313, 314, 144, 524, 835, 570, + 571, -15, 204, 205, 854, 312, 313, 314, 572, 573, 574, 575, 576, 145, + 316, 146, 202, 203, 695, 696, 206, 147, 804, 148, 577, 149, 578, 150, + 290, 151, 186, 264, 152, 310, 311, 312, 313, 314, 206, 737, 365, 366, + 738, 310, 311, 312, 313, 314, 184, 207, 153, 154, 208, 209, 312, 313, + 314, 155, 156, 768, 202, 203, 635, 157, 204, 205, 198, 199, 200, 201, + 208, 209, 240, 241, 242, 243, 244, 158, 245, 206, 246, 247, 248, 249, + 250, 817, 280, 159, 818, 192, 474, 596, 348, 310, 311, 312, 313, 314, + 682, 160, 181, 786, 787, 788, 161, 162, 658, 163, 164, 165, 661, 208, + 209, 664, 665, 475, 476, 533, 739, 301, 626, 252, 167, 206, 302, 168, + 411, 169, 175, 307, 709, 710, 711, 534, 207, 187, 684, 634, 304, 310, + 311, 312, 313, 314, 553, 340, 337, 202, 203, 342, 341, 822, 343, 344, + 345, 208, 209, 348, 347, 353, 350, 829, 348, 349, 351, 708, 310, 311, + 312, 313, 314, 732, 310, 311, 312, 313, 314, 310, 311, 312, 313, 314, + 310, 311, 312, 313, 314, 354, 659, 660, 357, -201, 663, 310, 311, 312, + 313, 314, 358, 360, 369, 361, 852, 240, 241, 242, 243, 244, 362, 245, + 206, 246, 247, 248, 249, 250, 559, 202, 203, 371, 363, 251, 310, 311, + 312, 313, 314, 364, 372, 467, 202, 203, 373, 375, 377, 775, 378, 797, + 379, 380, 381, 382, 208, 209, 310, 784, 312, 313, 314, 383, 562, 735, + 252, 384, 385, 386, 387, 388, 810, 811, 812, 745, 390, 391, 392, 310, + 311, 312, 313, 314, 393, 394, 395, 240, 241, 242, 243, 244, 584, 245, + 206, 246, 247, 248, 249, 250, 240, 241, 242, 243, 244, 251, 245, 206, + 246, 247, 248, 249, 250, 310, 311, 312, 313, 314, 251, 713, 714, 396, + 602, 405, 398, 399, 208, 209, 742, 400, 715, 716, 717, 403, 404, 408, + 252, 419, 438, 208, 209, 310, 311, 312, 313, 314, 410, 420, 782, 252, + 421, 431, 432, 718, 433, 719, 720, 721, 722, 723, 724, 725, 726, 727, + 728, 442, 443, 444, 446, 451, 452, 310, 311, 312, 313, 314, 453, 310, + 311, 312, 313, 314, 455, 857, 457, 463, 464, 465, 466, 864, 480, 493, + 483, 819, 481, 202, 203, 193, 494, 495, 496, 501, 502, 16, 507, 526, + -159, 537, 194, 195, 554, 17, 845, 552, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 555, 557, 853, 27, 28, 29, 558, 561, 586, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 583, 39, 40, 41, 42, 43, 44, + 45, 587, 46, 240, 241, 242, 243, 244, 590, 245, 206, 246, 247, 248, + 249, 250, 592, 47, 597, 601, 591, 251, 593, 594, 48, 49, 595, 50, + 598, 51, 52, 53, 599, 600, 54, 55, 603, 56, 604, 57, 605, 606, + 208, 209, 607, 609, 608, 612, 610, 613, 614, 616, 252, 617, 618, 62, + 619, 620, 58, 621, 59, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, 622, 596, 623, 630, 628, + 60, 625, 629, 631, 642, 256, 61, 62, 643, 645, 644, 646, 647, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, 80, 171, 64, 648, 66, 649, 68, 63, 70, 65, 72, 67, + 74, 69, 76, 71, 78, 73, 80, 75, 652, 77, 650, 79, 651, 653, + 655, 656, 467, 662, 666, 667, 669, 673, 675, 676, 674, 683, 680, 681, + 685, 707, 733, 746, 694, 751, 736, 740, 743, 744, 747, 750, 749, 752, + 754, 755, 759, 760, 781, 762, 773, 763, 780, 803, 776, 772, 777, 778, + 779, 792, 785, 783, 793, 795, 794, 809, 800, 798, 799, 805, 808, 820, + 816, 821, 806, 824, 825, 828, 830, 832, 834, 837, 839, 840, 833, 841, + 843, 846, 848, 850, 849, 10, 851, 172, 855, 856, 434, 861, 863, 339, + 166, 865, 508, 807, 560, 292, 796, 802, 753, 299, 826, 222, 847, 838, + 731, 437, 668, 698, 556, 374, 0, 535, 581, 0, 0, 547 }; -static const yytype_int16 yycheck[] = -{ - 83, 137, 170, 135, 396, 60, 296, 143, 144, 501, - 145, 147, 148, 149, 432, 400, 328, 403, 404, 409, - 328, 59, 4, 159, 3, 160, 161, 162, 3, 153, - 154, 155, 167, 4, 6, 688, 4, 8, 20, 175, - 22, 59, 60, 44, 26, 27, 28, 433, 59, 3, - 186, 59, 60, 59, 186, 3, 5, 3, 3, 590, - 4, 3, 3, 107, 4, 550, 356, 59, 8, 359, - 4, 59, 59, 5, 59, 548, 133, 59, 60, 131, - 59, 131, 131, 0, 59, 134, 138, 546, 138, 4, - 621, 59, 60, 4, 70, 139, 78, 8, 9, 156, - 157, 139, 131, 158, 122, 134, 242, 243, 139, 245, - 59, 54, 150, 151, 59, 133, 59, 59, 59, 150, - 151, 131, 55, 178, 139, 133, 59, 59, 139, 184, - 3, 186, 133, 139, 302, 131, 154, 155, 120, 132, - 122, 133, 138, 796, 59, 133, 133, 3, 133, 59, - 642, 133, 15, 16, 133, 137, 66, 139, 133, 132, - 139, 3, 133, 135, 139, 133, 148, 149, 150, 151, - 662, 139, 154, 155, 156, 157, 139, 148, 149, 133, - 148, 149, 150, 151, 71, 133, 59, 133, 133, 133, - 141, 133, 137, 133, 139, 139, 328, 139, 57, 133, - 59, 586, 184, 59, 148, 149, 150, 151, 148, 149, - 158, 159, 347, 184, 148, 149, 184, 162, 163, 704, - 162, 163, 133, 132, 360, 361, 394, 362, 540, 702, - 538, 132, 522, 651, 369, 371, 372, 623, 373, 629, - 184, 700, 377, 87, 184, 59, 301, 61, 62, 89, - 184, 91, 307, 308, 337, 310, 311, 312, 313, 314, - 133, 397, 386, 132, 137, 132, 139, 391, 392, 393, - 4, 131, 327, 328, 8, 9, 408, 133, 138, 64, - 65, 132, 131, 139, 135, 340, 421, 160, 161, 138, - 131, 133, 44, 132, 349, 137, 132, 138, 132, 354, - 150, 151, 131, 358, 160, 161, 132, 59, 60, 138, - 3, 113, 58, 59, 7, 132, 158, 159, 168, 455, - 54, 55, 56, 4, 379, 59, 60, 8, 9, 465, - 466, 132, 622, 4, 136, 69, 186, 8, 9, 131, - 135, 185, 186, 187, 188, 189, 132, 191, 131, 83, - 84, 134, 63, 64, 846, 187, 188, 189, 92, 93, - 94, 95, 96, 132, 419, 132, 59, 60, 144, 145, - 122, 132, 764, 132, 108, 132, 110, 132, 59, 132, - 190, 133, 132, 185, 186, 187, 188, 189, 122, 131, - 240, 241, 134, 185, 186, 187, 188, 189, 133, 133, - 132, 132, 154, 155, 187, 188, 189, 132, 132, 699, - 59, 60, 544, 132, 63, 64, 10, 11, 12, 13, - 154, 155, 115, 116, 117, 118, 119, 132, 121, 122, - 123, 124, 125, 126, 127, 131, 133, 132, 134, 131, - 133, 3, 4, 185, 186, 187, 188, 189, 616, 132, - 184, 32, 33, 34, 132, 132, 591, 132, 132, 132, - 595, 154, 155, 598, 599, 158, 159, 136, 131, 190, - 525, 164, 132, 122, 135, 132, 134, 132, 132, 135, - 648, 649, 650, 136, 133, 132, 618, 542, 133, 185, - 186, 187, 188, 189, 136, 135, 137, 59, 60, 131, - 191, 791, 131, 131, 130, 154, 155, 4, 133, 3, - 131, 801, 4, 135, 131, 647, 185, 186, 187, 188, - 189, 653, 185, 186, 187, 188, 189, 185, 186, 187, - 188, 189, 185, 186, 187, 188, 189, 135, 593, 594, - 3, 137, 597, 185, 186, 187, 188, 189, 135, 131, - 133, 131, 842, 115, 116, 117, 118, 119, 131, 121, - 122, 123, 124, 125, 126, 127, 136, 59, 60, 133, - 131, 133, 185, 186, 187, 188, 189, 131, 133, 58, - 59, 60, 133, 133, 193, 717, 4, 755, 135, 131, - 131, 131, 154, 155, 185, 186, 187, 188, 189, 133, - 136, 656, 164, 4, 131, 131, 131, 6, 776, 777, - 778, 666, 4, 131, 131, 185, 186, 187, 188, 189, - 131, 131, 4, 115, 116, 117, 118, 119, 136, 121, - 122, 123, 124, 125, 126, 127, 115, 116, 117, 118, - 119, 133, 121, 122, 123, 124, 125, 126, 127, 185, - 186, 187, 188, 189, 133, 61, 62, 131, 136, 136, - 131, 131, 154, 155, 136, 131, 72, 73, 74, 131, - 131, 131, 164, 131, 3, 154, 155, 185, 186, 187, - 188, 189, 134, 134, 739, 164, 132, 132, 132, 95, - 132, 97, 98, 99, 100, 101, 102, 103, 104, 105, - 106, 3, 131, 136, 131, 5, 140, 185, 186, 187, - 188, 189, 131, 185, 186, 187, 188, 189, 131, 855, - 131, 58, 58, 131, 131, 861, 128, 67, 131, 784, - 134, 59, 60, 139, 4, 131, 67, 131, 131, 6, - 131, 136, 77, 131, 150, 151, 3, 14, 831, 138, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 131, - 134, 844, 29, 30, 31, 4, 139, 131, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 139, 45, 46, - 47, 48, 49, 50, 51, 131, 53, 115, 116, 117, - 118, 119, 192, 121, 122, 123, 124, 125, 126, 127, - 134, 68, 135, 4, 131, 133, 131, 131, 75, 76, - 131, 78, 131, 80, 81, 82, 131, 131, 85, 86, - 131, 88, 135, 90, 131, 131, 154, 155, 4, 4, - 131, 4, 131, 131, 131, 131, 164, 58, 131, 142, - 4, 131, 109, 131, 111, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, - 163, 164, 165, 77, 3, 131, 134, 132, 135, 191, - 131, 4, 131, 133, 141, 142, 3, 140, 134, 134, - 132, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, 162, 163, 164, 165, 142, - 149, 132, 151, 132, 153, 148, 155, 150, 157, 152, - 159, 154, 161, 156, 163, 158, 165, 160, 134, 162, - 132, 164, 132, 131, 5, 131, 58, 131, 133, 131, - 4, 4, 67, 131, 131, 131, 139, 67, 131, 131, - 131, 4, 137, 4, 134, 134, 134, 134, 131, 131, - 136, 4, 131, 131, 4, 4, 32, 131, 5, 131, - 3, 7, 132, 134, 132, 132, 132, 4, 131, 134, - 131, 131, 134, 59, 131, 134, 134, 132, 131, 4, - 134, 131, 138, 131, 4, 4, 132, 5, 32, 134, - 4, 134, 192, 134, 134, 131, 134, 134, 129, 5, - 134, 55, 131, 131, 336, 131, 860, 192, 49, 134, - 396, 767, 450, 164, 754, 762, 678, 169, 795, 139, - 833, 821, 653, 341, 603, 629, 443, 249, -1, 419, - 455, -1, -1, 431 +static const yytype_int16 yycheck[] = { + 83, 137, 170, 135, 396, 60, 296, 143, 144, 501, 145, 147, 148, 149, 432, + 400, 328, 403, 404, 409, 328, 59, 4, 159, 3, 160, 161, 162, 3, 153, + 154, 155, 167, 4, 6, 688, 4, 8, 20, 175, 22, 59, 60, 44, 26, + 27, 28, 433, 59, 3, 186, 59, 60, 59, 186, 3, 5, 3, 3, 590, + 4, 3, 3, 107, 4, 550, 356, 59, 8, 359, 4, 59, 59, 5, 59, + 548, 133, 59, 60, 131, 59, 131, 131, 0, 59, 134, 138, 546, 138, 4, + 621, 59, 60, 4, 70, 139, 78, 8, 9, 156, 157, 139, 131, 158, 122, + 134, 242, 243, 139, 245, 59, 54, 150, 151, 59, 133, 59, 59, 59, 150, + 151, 131, 55, 178, 139, 133, 59, 59, 139, 184, 3, 186, 133, 139, 302, + 131, 154, 155, 120, 132, 122, 133, 138, 796, 59, 133, 133, 3, 133, 59, + 642, 133, 15, 16, 133, 137, 66, 139, 133, 132, 139, 3, 133, 135, 139, + 133, 148, 149, 150, 151, 662, 139, 154, 155, 156, 157, 139, 148, 149, 133, + 148, 149, 150, 151, 71, 133, 59, 133, 133, 133, 141, 133, 137, 133, 139, + 139, 328, 139, 57, 133, 59, 586, 184, 59, 148, 149, 150, 151, 148, 149, + 158, 159, 347, 184, 148, 149, 184, 162, 163, 704, 162, 163, 133, 132, 360, + 361, 394, 362, 540, 702, 538, 132, 522, 651, 369, 371, 372, 623, 373, 629, + 184, 700, 377, 87, 184, 59, 301, 61, 62, 89, 184, 91, 307, 308, 337, + 310, 311, 312, 313, 314, 133, 397, 386, 132, 137, 132, 139, 391, 392, 393, + 4, 131, 327, 328, 8, 9, 408, 133, 138, 64, 65, 132, 131, 139, 135, + 340, 421, 160, 161, 138, 131, 133, 44, 132, 349, 137, 132, 138, 132, 354, + 150, 151, 131, 358, 160, 161, 132, 59, 60, 138, 3, 113, 58, 59, 7, + 132, 158, 159, 168, 455, 54, 55, 56, 4, 379, 59, 60, 8, 9, 465, + 466, 132, 622, 4, 136, 69, 186, 8, 9, 131, 135, 185, 186, 187, 188, + 189, 132, 191, 131, 83, 84, 134, 63, 64, 846, 187, 188, 189, 92, 93, + 94, 95, 96, 132, 419, 132, 59, 60, 144, 145, 122, 132, 764, 132, 108, + 132, 110, 132, 59, 132, 190, 133, 132, 185, 186, 187, 188, 189, 122, 131, + 240, 241, 134, 185, 186, 187, 188, 189, 133, 133, 132, 132, 154, 155, 187, + 188, 189, 132, 132, 699, 59, 60, 544, 132, 63, 64, 10, 11, 12, 13, + 154, 155, 115, 116, 117, 118, 119, 132, 121, 122, 123, 124, 125, 126, 127, + 131, 133, 132, 134, 131, 133, 3, 4, 185, 186, 187, 188, 189, 616, 132, + 184, 32, 33, 34, 132, 132, 591, 132, 132, 132, 595, 154, 155, 598, 599, + 158, 159, 136, 131, 190, 525, 164, 132, 122, 135, 132, 134, 132, 132, 135, + 648, 649, 650, 136, 133, 132, 618, 542, 133, 185, 186, 187, 188, 189, 136, + 135, 137, 59, 60, 131, 191, 791, 131, 131, 130, 154, 155, 4, 133, 3, + 131, 801, 4, 135, 131, 647, 185, 186, 187, 188, 189, 653, 185, 186, 187, + 188, 189, 185, 186, 187, 188, 189, 185, 186, 187, 188, 189, 135, 593, 594, + 3, 137, 597, 185, 186, 187, 188, 189, 135, 131, 133, 131, 842, 115, 116, + 117, 118, 119, 131, 121, 122, 123, 124, 125, 126, 127, 136, 59, 60, 133, + 131, 133, 185, 186, 187, 188, 189, 131, 133, 58, 59, 60, 133, 133, 193, + 717, 4, 755, 135, 131, 131, 131, 154, 155, 185, 186, 187, 188, 189, 133, + 136, 656, 164, 4, 131, 131, 131, 6, 776, 777, 778, 666, 4, 131, 131, + 185, 186, 187, 188, 189, 131, 131, 4, 115, 116, 117, 118, 119, 136, 121, + 122, 123, 124, 125, 126, 127, 115, 116, 117, 118, 119, 133, 121, 122, 123, + 124, 125, 126, 127, 185, 186, 187, 188, 189, 133, 61, 62, 131, 136, 136, + 131, 131, 154, 155, 136, 131, 72, 73, 74, 131, 131, 131, 164, 131, 3, + 154, 155, 185, 186, 187, 188, 189, 134, 134, 739, 164, 132, 132, 132, 95, + 132, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 3, 131, 136, 131, + 5, 140, 185, 186, 187, 188, 189, 131, 185, 186, 187, 188, 189, 131, 855, + 131, 58, 58, 131, 131, 861, 128, 67, 131, 784, 134, 59, 60, 139, 4, + 131, 67, 131, 131, 6, 131, 136, 77, 131, 150, 151, 3, 14, 831, 138, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 131, 134, 844, 29, 30, 31, + 4, 139, 131, 35, 36, 37, 38, 39, 40, 41, 42, 43, 139, 45, 46, + 47, 48, 49, 50, 51, 131, 53, 115, 116, 117, 118, 119, 192, 121, 122, + 123, 124, 125, 126, 127, 134, 68, 135, 4, 131, 133, 131, 131, 75, 76, + 131, 78, 131, 80, 81, 82, 131, 131, 85, 86, 131, 88, 135, 90, 131, + 131, 154, 155, 4, 4, 131, 4, 131, 131, 131, 131, 164, 58, 131, 142, + 4, 131, 109, 131, 111, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, 160, 161, 162, 163, 164, 165, 77, 3, 131, 134, 132, 135, 191, + 131, 4, 131, 133, 141, 142, 3, 140, 134, 134, 132, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 142, + 149, 132, 151, 132, 153, 148, 155, 150, 157, 152, 159, 154, 161, 156, 163, + 158, 165, 160, 134, 162, 132, 164, 132, 131, 5, 131, 58, 131, 133, 131, + 4, 4, 67, 131, 131, 131, 139, 67, 131, 131, 131, 4, 137, 4, 134, + 134, 134, 134, 131, 131, 136, 4, 131, 131, 4, 4, 32, 131, 5, 131, + 3, 7, 132, 134, 132, 132, 132, 4, 131, 134, 131, 131, 134, 59, 131, + 134, 134, 132, 131, 4, 134, 131, 138, 131, 4, 4, 132, 5, 32, 134, + 4, 134, 192, 134, 134, 131, 134, 134, 129, 5, 134, 55, 131, 131, 336, + 131, 860, 192, 49, 134, 396, 767, 450, 164, 754, 762, 678, 169, 795, 139, + 833, 821, 653, 341, 603, 629, 443, 249, -1, 419, 455, -1, -1, 431 }; - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint16 yystos[] = -{ - 0, 15, 16, 195, 196, 197, 198, 132, 132, 0, - 196, 70, 205, 139, 139, 132, 6, 14, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 29, 30, 31, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, - 46, 47, 48, 49, 50, 51, 53, 68, 75, 76, - 78, 80, 81, 82, 85, 86, 88, 90, 109, 111, - 135, 141, 142, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, - 165, 200, 207, 209, 210, 211, 212, 214, 215, 223, - 226, 227, 229, 230, 237, 239, 240, 242, 244, 246, - 250, 251, 252, 255, 257, 264, 269, 272, 278, 283, - 284, 285, 286, 287, 288, 289, 290, 291, 292, 294, - 295, 296, 298, 299, 300, 301, 302, 305, 306, 307, - 308, 309, 131, 71, 206, 132, 132, 132, 132, 132, - 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, - 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, - 132, 132, 132, 132, 132, 132, 229, 132, 132, 132, - 135, 142, 211, 213, 231, 132, 141, 4, 133, 148, - 149, 184, 335, 345, 133, 207, 190, 132, 241, 3, - 59, 199, 131, 139, 150, 151, 321, 334, 10, 11, - 12, 13, 59, 60, 63, 64, 122, 133, 154, 155, - 270, 323, 324, 3, 59, 133, 139, 162, 163, 280, - 332, 333, 280, 3, 59, 133, 139, 160, 161, 274, - 330, 331, 59, 139, 310, 54, 59, 315, 323, 323, - 115, 116, 117, 118, 119, 121, 123, 124, 125, 126, - 127, 133, 164, 323, 343, 344, 133, 156, 157, 326, - 327, 323, 323, 44, 133, 323, 352, 353, 326, 326, - 59, 139, 254, 311, 133, 352, 352, 352, 322, 335, - 133, 253, 335, 323, 344, 344, 344, 4, 8, 9, - 59, 346, 254, 5, 59, 265, 247, 344, 326, 210, - 322, 190, 135, 323, 133, 8, 335, 135, 113, 136, - 185, 186, 187, 188, 189, 334, 335, 340, 341, 342, - 20, 22, 26, 27, 28, 78, 120, 133, 137, 323, - 326, 334, 335, 348, 349, 350, 245, 137, 208, 206, - 135, 191, 131, 131, 131, 130, 325, 133, 4, 135, - 131, 131, 259, 3, 135, 281, 279, 3, 135, 273, - 131, 131, 131, 131, 131, 326, 326, 323, 323, 133, - 323, 133, 133, 133, 343, 133, 344, 193, 4, 135, - 131, 131, 131, 133, 4, 131, 131, 131, 6, 228, - 4, 131, 131, 131, 131, 4, 131, 131, 131, 131, - 131, 208, 248, 131, 131, 136, 335, 322, 131, 224, - 134, 134, 335, 335, 335, 335, 335, 335, 335, 131, - 134, 132, 4, 219, 220, 221, 222, 324, 327, 334, - 335, 132, 132, 132, 209, 207, 335, 321, 3, 3, - 133, 297, 3, 131, 136, 344, 131, 335, 64, 65, - 271, 5, 140, 131, 335, 131, 208, 131, 335, 208, - 323, 323, 344, 58, 58, 131, 131, 58, 267, 344, - 323, 323, 3, 7, 133, 158, 159, 328, 329, 344, - 128, 134, 344, 131, 335, 55, 59, 316, 59, 61, - 62, 317, 320, 67, 4, 131, 67, 352, 59, 133, - 260, 131, 131, 352, 352, 352, 322, 131, 253, 346, - 323, 57, 59, 351, 59, 133, 261, 315, 249, 133, - 328, 328, 243, 87, 191, 238, 136, 59, 334, 212, - 337, 338, 339, 136, 136, 340, 344, 131, 131, 138, - 131, 138, 131, 138, 131, 138, 137, 332, 137, 330, - 137, 328, 138, 136, 3, 131, 325, 134, 4, 136, - 259, 139, 136, 4, 8, 9, 54, 55, 56, 69, - 83, 84, 92, 93, 94, 95, 96, 108, 110, 282, - 323, 345, 347, 139, 136, 275, 131, 131, 323, 323, - 192, 131, 134, 131, 131, 131, 3, 135, 131, 131, - 131, 4, 136, 131, 135, 131, 131, 4, 131, 4, - 131, 316, 4, 131, 131, 293, 131, 58, 131, 4, - 131, 131, 77, 131, 208, 191, 335, 232, 132, 131, - 134, 4, 327, 324, 335, 334, 216, 333, 217, 331, - 218, 329, 131, 3, 134, 140, 134, 132, 132, 132, - 132, 132, 134, 131, 315, 5, 131, 267, 344, 335, - 335, 344, 131, 335, 344, 344, 133, 131, 311, 4, - 59, 66, 319, 4, 131, 67, 131, 59, 133, 262, - 139, 67, 322, 131, 334, 131, 59, 133, 263, 59, - 266, 267, 208, 328, 137, 144, 145, 336, 337, 225, - 131, 138, 131, 138, 131, 138, 316, 131, 334, 322, - 322, 322, 330, 61, 62, 72, 73, 74, 95, 97, - 98, 99, 100, 101, 102, 103, 104, 105, 106, 276, - 318, 320, 334, 131, 203, 335, 134, 131, 134, 131, - 134, 316, 136, 134, 134, 335, 4, 131, 312, 136, - 131, 4, 4, 270, 131, 131, 4, 59, 268, 4, - 4, 312, 131, 131, 89, 91, 233, 234, 208, 333, - 331, 329, 134, 5, 132, 334, 132, 132, 132, 132, - 3, 32, 335, 134, 186, 131, 32, 33, 34, 313, - 314, 303, 4, 131, 134, 131, 263, 322, 134, 134, - 131, 256, 268, 7, 346, 132, 138, 233, 131, 59, - 322, 322, 322, 107, 139, 277, 134, 131, 134, 335, - 4, 131, 208, 304, 131, 4, 271, 312, 4, 208, - 132, 236, 5, 192, 32, 131, 201, 134, 313, 4, - 134, 134, 258, 134, 235, 207, 131, 277, 134, 129, - 134, 134, 208, 207, 316, 131, 131, 323, 5, 59, - 204, 131, 202, 203, 323, 134 +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint16 yystos[] = { + 0, 15, 16, 195, 196, 197, 198, 132, 132, 0, 196, 70, 205, 139, 139, + 132, 6, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 29, 30, 31, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, + 51, 53, 68, 75, 76, 78, 80, 81, 82, 85, 86, 88, 90, 109, 111, + 135, 141, 142, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 200, 207, 209, 210, 211, 212, 214, 215, 223, + 226, 227, 229, 230, 237, 239, 240, 242, 244, 246, 250, 251, 252, 255, 257, + 264, 269, 272, 278, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 294, + 295, 296, 298, 299, 300, 301, 302, 305, 306, 307, 308, 309, 131, 71, 206, + 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, + 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, + 132, 229, 132, 132, 132, 135, 142, 211, 213, 231, 132, 141, 4, 133, 148, + 149, 184, 335, 345, 133, 207, 190, 132, 241, 3, 59, 199, 131, 139, 150, + 151, 321, 334, 10, 11, 12, 13, 59, 60, 63, 64, 122, 133, 154, 155, + 270, 323, 324, 3, 59, 133, 139, 162, 163, 280, 332, 333, 280, 3, 59, + 133, 139, 160, 161, 274, 330, 331, 59, 139, 310, 54, 59, 315, 323, 323, + 115, 116, 117, 118, 119, 121, 123, 124, 125, 126, 127, 133, 164, 323, 343, + 344, 133, 156, 157, 326, 327, 323, 323, 44, 133, 323, 352, 353, 326, 326, + 59, 139, 254, 311, 133, 352, 352, 352, 322, 335, 133, 253, 335, 323, 344, + 344, 344, 4, 8, 9, 59, 346, 254, 5, 59, 265, 247, 344, 326, 210, + 322, 190, 135, 323, 133, 8, 335, 135, 113, 136, 185, 186, 187, 188, 189, + 334, 335, 340, 341, 342, 20, 22, 26, 27, 28, 78, 120, 133, 137, 323, + 326, 334, 335, 348, 349, 350, 245, 137, 208, 206, 135, 191, 131, 131, 131, + 130, 325, 133, 4, 135, 131, 131, 259, 3, 135, 281, 279, 3, 135, 273, + 131, 131, 131, 131, 131, 326, 326, 323, 323, 133, 323, 133, 133, 133, 343, + 133, 344, 193, 4, 135, 131, 131, 131, 133, 4, 131, 131, 131, 6, 228, + 4, 131, 131, 131, 131, 4, 131, 131, 131, 131, 131, 208, 248, 131, 131, + 136, 335, 322, 131, 224, 134, 134, 335, 335, 335, 335, 335, 335, 335, 131, + 134, 132, 4, 219, 220, 221, 222, 324, 327, 334, 335, 132, 132, 132, 209, + 207, 335, 321, 3, 3, 133, 297, 3, 131, 136, 344, 131, 335, 64, 65, + 271, 5, 140, 131, 335, 131, 208, 131, 335, 208, 323, 323, 344, 58, 58, + 131, 131, 58, 267, 344, 323, 323, 3, 7, 133, 158, 159, 328, 329, 344, + 128, 134, 344, 131, 335, 55, 59, 316, 59, 61, 62, 317, 320, 67, 4, + 131, 67, 352, 59, 133, 260, 131, 131, 352, 352, 352, 322, 131, 253, 346, + 323, 57, 59, 351, 59, 133, 261, 315, 249, 133, 328, 328, 243, 87, 191, + 238, 136, 59, 334, 212, 337, 338, 339, 136, 136, 340, 344, 131, 131, 138, + 131, 138, 131, 138, 131, 138, 137, 332, 137, 330, 137, 328, 138, 136, 3, + 131, 325, 134, 4, 136, 259, 139, 136, 4, 8, 9, 54, 55, 56, 69, + 83, 84, 92, 93, 94, 95, 96, 108, 110, 282, 323, 345, 347, 139, 136, + 275, 131, 131, 323, 323, 192, 131, 134, 131, 131, 131, 3, 135, 131, 131, + 131, 4, 136, 131, 135, 131, 131, 4, 131, 4, 131, 316, 4, 131, 131, + 293, 131, 58, 131, 4, 131, 131, 77, 131, 208, 191, 335, 232, 132, 131, + 134, 4, 327, 324, 335, 334, 216, 333, 217, 331, 218, 329, 131, 3, 134, + 140, 134, 132, 132, 132, 132, 132, 134, 131, 315, 5, 131, 267, 344, 335, + 335, 344, 131, 335, 344, 344, 133, 131, 311, 4, 59, 66, 319, 4, 131, + 67, 131, 59, 133, 262, 139, 67, 322, 131, 334, 131, 59, 133, 263, 59, + 266, 267, 208, 328, 137, 144, 145, 336, 337, 225, 131, 138, 131, 138, 131, + 138, 316, 131, 334, 322, 322, 322, 330, 61, 62, 72, 73, 74, 95, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 276, 318, 320, 334, 131, 203, + 335, 134, 131, 134, 131, 134, 316, 136, 134, 134, 335, 4, 131, 312, 136, + 131, 4, 4, 270, 131, 131, 4, 59, 268, 4, 4, 312, 131, 131, 89, + 91, 233, 234, 208, 333, 331, 329, 134, 5, 132, 334, 132, 132, 132, 132, + 3, 32, 335, 134, 186, 131, 32, 33, 34, 313, 314, 303, 4, 131, 134, + 131, 263, 322, 134, 134, 131, 256, 268, 7, 346, 132, 138, 233, 131, 59, + 322, 322, 322, 107, 139, 277, 134, 131, 134, 335, 4, 131, 208, 304, 131, + 4, 271, 312, 4, 208, 132, 236, 5, 192, 32, 131, 201, 134, 313, 4, + 134, 134, 258, 134, 235, 207, 131, 277, 134, 129, 134, 134, 208, 207, 316, + 131, 131, 323, 5, 59, 204, 131, 202, 203, 323, 134 }; - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint16 yyr1[] = -{ - 0, 194, 195, 195, 196, 196, 197, 198, 198, 199, - 199, 200, 200, 200, 200, 201, 201, 202, 202, 203, - 203, 204, 204, 205, 205, 206, 206, 207, 207, 208, - 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, - 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, - 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, - 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, - 209, 209, 209, 209, 210, 210, 210, 210, 210, 210, - 210, 210, 210, 211, 211, 211, 211, 211, 211, 211, - 211, 211, 212, 212, 212, 213, 213, 214, 215, 215, - 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, - 215, 215, 215, 216, 216, 217, 217, 218, 218, 219, - 219, 220, 220, 221, 221, 222, 222, 224, 225, 223, - 226, 227, 228, 228, 229, 229, 229, 231, 232, 230, - 233, 233, 235, 234, 236, 234, 237, 238, 238, 239, - 241, 240, 243, 242, 245, 244, 247, 246, 248, 249, - 248, 250, 251, 251, 251, 252, 252, 253, 254, 256, - 255, 258, 257, 259, 259, 260, 260, 261, 261, 262, - 262, 263, 263, 264, 264, 265, 265, 266, 266, 267, - 267, 268, 268, 269, 269, 269, 270, 270, 271, 271, - 272, 273, 272, 274, 275, 275, 276, 276, 276, 276, - 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - 276, 276, 277, 277, 277, 278, 279, 278, 280, 281, - 281, 282, 282, 282, 282, 282, 282, 282, 282, 282, - 282, 282, 282, 282, 282, 282, 283, 284, 285, 285, - 286, 286, 287, 288, 289, 290, 291, 292, 293, 293, - 294, 295, 296, 297, 297, 298, 299, 300, 301, 303, - 302, 304, 304, 305, 306, 306, 306, 307, 308, 309, - 309, 310, 310, 311, 311, 312, 312, 313, 313, 314, - 314, 314, 315, 315, 316, 316, 317, 317, 317, 318, - 318, 318, 319, 319, 320, 321, 321, 321, 322, 323, - 323, 323, 323, 324, 324, 324, 325, 325, 326, 326, - 326, 327, 328, 328, 328, 329, 329, 330, 330, 330, - 331, 331, 331, 331, 332, 332, 332, 333, 333, 333, - 333, 334, 334, 335, 335, 335, 335, 335, 335, 335, - 335, 335, 335, 335, 336, 336, 337, 338, 338, 339, - 339, 340, 340, 341, 341, 342, 342, 343, 343, 343, - 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, - 343, 343, 343, 343, 343, 343, 344, 344, 345, 346, - 346, 346, 347, 347, 347, 347, 348, 348, 349, 349, - 350, 350, 351, 351, 352, 352, 353 +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint16 yyr1[] = { + 0, 194, 195, 195, 196, 196, 197, 198, 198, 199, 199, 200, 200, 200, 200, + 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 206, 207, 207, 208, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 210, + 210, 210, 210, 210, 210, 210, 210, 210, 211, 211, 211, 211, 211, 211, 211, + 211, 211, 212, 212, 212, 213, 213, 214, 215, 215, 215, 215, 215, 215, 215, + 215, 215, 215, 215, 215, 215, 215, 215, 216, 216, 217, 217, 218, 218, 219, + 219, 220, 220, 221, 221, 222, 222, 224, 225, 223, 226, 227, 228, 228, 229, + 229, 229, 231, 232, 230, 233, 233, 235, 234, 236, 234, 237, 238, 238, 239, + 241, 240, 243, 242, 245, 244, 247, 246, 248, 249, 248, 250, 251, 251, 251, + 252, 252, 253, 254, 256, 255, 258, 257, 259, 259, 260, 260, 261, 261, 262, + 262, 263, 263, 264, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, + 269, 270, 270, 271, 271, 272, 273, 272, 274, 275, 275, 276, 276, 276, 276, + 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, 277, 277, 277, + 278, 279, 278, 280, 281, 281, 282, 282, 282, 282, 282, 282, 282, 282, 282, + 282, 282, 282, 282, 282, 282, 283, 284, 285, 285, 286, 286, 287, 288, 289, + 290, 291, 292, 293, 293, 294, 295, 296, 297, 297, 298, 299, 300, 301, 303, + 302, 304, 304, 305, 306, 306, 306, 307, 308, 309, 309, 310, 310, 311, 311, + 312, 312, 313, 313, 314, 314, 314, 315, 315, 316, 316, 317, 317, 317, 318, + 318, 318, 319, 319, 320, 321, 321, 321, 322, 323, 323, 323, 323, 324, 324, + 324, 325, 325, 326, 326, 326, 327, 328, 328, 328, 329, 329, 330, 330, 330, + 331, 331, 331, 331, 332, 332, 332, 333, 333, 333, 333, 334, 334, 335, 335, + 335, 335, 335, 335, 335, 335, 335, 335, 335, 336, 336, 337, 338, 338, 339, + 339, 340, 340, 341, 341, 342, 342, 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 344, 344, 345, 346, + 346, 346, 347, 347, 347, 347, 348, 348, 349, 349, 350, 350, 351, 351, 352, + 352, 353 }; - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 0, 1, 1, 2, 3, 3, 5, 1, - 1, 5, 5, 3, 16, 0, 2, 0, 2, 0, - 2, 1, 1, 0, 3, 3, 1, 0, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 3, 3, 5, - 3, 5, 5, 5, 3, 3, 5, 5, 5, 7, - 7, 7, 5, 1, 3, 1, 3, 1, 3, 1, - 3, 1, 3, 1, 3, 1, 3, 0, 0, 8, - 4, 1, 0, 1, 1, 5, 3, 0, 0, 9, - 0, 2, 0, 5, 0, 4, 1, 2, 1, 6, - 0, 3, 0, 6, 0, 4, 0, 4, 1, 0, - 4, 3, 1, 3, 3, 5, 5, 7, 4, 0, - 10, 0, 12, 0, 2, 5, 1, 5, 1, 5, - 1, 5, 1, 9, 5, 1, 1, 1, 1, 1, - 3, 1, 1, 1, 7, 5, 1, 1, 1, 1, - 3, 0, 5, 4, 0, 3, 1, 1, 1, 1, - 2, 1, 1, 1, 1, 1, 3, 3, 3, 1, - 1, 3, 1, 1, 3, 3, 0, 5, 2, 0, - 3, 1, 3, 1, 3, 3, 1, 1, 3, 1, - 1, 1, 3, 1, 1, 1, 5, 7, 5, 8, - 1, 3, 5, 5, 7, 7, 6, 5, 0, 2, - 3, 3, 3, 1, 5, 9, 5, 3, 3, 0, - 10, 0, 1, 7, 5, 5, 3, 5, 7, 9, - 1, 1, 1, 1, 1, 0, 2, 1, 3, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 3, 1, 1, 4, 1, 1, 4, 1, 1, - 4, 1, 4, 5, 1, 3, 1, 3, 1, 1, - 4, 9, 1, 1, 4, 1, 5, 1, 1, 4, - 1, 1, 5, 1, 1, 1, 4, 1, 1, 5, - 1, 1, 3, 1, 1, 3, 1, 4, 3, 3, - 3, 3, 3, 3, 1, 1, 3, 1, 3, 0, - 1, 1, 1, 1, 3, 0, 1, 1, 2, 2, - 4, 6, 4, 6, 6, 6, 6, 2, 6, 8, - 8, 10, 14, 2, 1, 3, 1, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 10, 9 +/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = { + 0, 2, 0, 1, 1, 2, 3, 3, 5, 1, 1, 5, 5, 3, 16, 0, 2, 0, 2, 0, 2, 1, 1, + 0, 3, 3, 1, 0, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 3, 3, 5, 3, 5, 5, 5, 3, 3, 5, 5, 5, 7, 7, 7, 5, 1, 3, + 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 0, 0, 8, 4, 1, 0, 1, 1, 5, 3, 0, + 0, 9, 0, 2, 0, 5, 0, 4, 1, 2, 1, 6, 0, 3, 0, 6, 0, 4, 0, 4, 1, 0, 4, + 3, 1, 3, 3, 5, 5, 7, 4, 0, 10, 0, 12, 0, 2, 5, 1, 5, 1, 5, 1, 5, 1, 9, + 5, 1, 1, 1, 1, 1, 3, 1, 1, 1, 7, 5, 1, 1, 1, 1, 3, 0, 5, 4, 0, 3, 1, + 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 3, 1, 1, 3, 3, 0, 5, 2, 0, + 3, 1, 3, 1, 3, 3, 1, 1, 3, 1, 1, 1, 3, 1, 1, 1, 5, 7, 5, 8, 1, 3, 5, + 5, 7, 7, 6, 5, 0, 2, 3, 3, 3, 1, 5, 9, 5, 3, 3, 0, 10, 0, 1, 7, 5, 5, + 3, 5, 7, 9, 1, 1, 1, 1, 1, 0, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 3, 1, 1, 4, 1, 1, 4, 1, 1, 4, 1, 4, 5, 1, 3, 1, 3, 1, 1, 4, 9, + 1, 1, 4, 1, 5, 1, 1, 4, 1, 1, 5, 1, 1, 1, 4, 1, 1, 5, 1, 1, 3, 1, 1, + 3, 1, 4, 3, 3, 3, 3, 3, 3, 1, 1, 3, 1, 3, 0, 1, 1, 1, 1, 3, 0, 1, 1, + 2, 2, 4, 6, 4, 6, 6, 6, 6, 2, 6, 8, 8, 10, 14, 2, 1, 3, 1, 3, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 9 }; +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab +#define YYRECOVERING() (!!yyerrstatus) - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK(yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } else { \ + yyerror(YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - +#define YYTERROR 1 +#define YYERRCODE 256 /* Enable debugging if requested. */ #if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +#ifndef YYFPRINTF +#include /* INFRINGES ON USER NAME SPACE */ +#define YYFPRINTF fprintf +#endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) +#define YYDPRINTF(Args) \ + do { \ + if (yydebug) \ + YYFPRINTF Args; \ + } while (0) /* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do { \ + if (yydebug) { \ + YYFPRINTF(stderr, "%s ", Title); \ + yy_symbol_print(stderr, Type, Value); \ + YYFPRINTF(stderr, "\n"); \ + } \ + } while (0) /*----------------------------------------. | Print this symbol's value on YYOUTPUT. | `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_value_print(FILE *yyoutput, int yytype, + YYSTYPE const *const yyvaluep) { - FILE *yyo = yyoutput; - YYUSE (yyo); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + FILE *yyo = yyoutput; + YYUSE(yyo); + if (!yyvaluep) + return; +#ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep); +#endif + YYUSE(yytype); } - /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_print(FILE *yyoutput, int yytype, YYSTYPE const *const yyvaluep) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF(yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", + yytname[yytype]); - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); + yy_symbol_value_print(yyoutput, yytype, yyvaluep); + YYFPRINTF(yyoutput, ")"); } /*------------------------------------------------------------------. @@ -1876,68 +1629,62 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) { - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); + YYFPRINTF(stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) { + int yybot = *yybottom; + YYFPRINTF(stderr, " %d", yybot); } - YYFPRINTF (stderr, "\n"); + YYFPRINTF(stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - +#define YY_STACK_PRINT(Bottom, Top) \ + do { \ + if (yydebug) \ + yy_stack_print((Bottom), (Top)); \ + } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) +yy_reduce_print(yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { - unsigned long int yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; - int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - YYFPRINTF (stderr, "\n"); + unsigned long int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, + yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) { + YYFPRINTF(stderr, " $%d = ", yyi + 1); + yy_symbol_print(stderr, yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)])); + YYFPRINTF(stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule); \ -} while (0) +#define YY_REDUCE_PRINT(Rule) \ + do { \ + if (yydebug) \ + yy_reduce_print(yyssp, yyvsp, Rule); \ + } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +#define YYDPRINTF(Args) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#define YY_STACK_PRINT(Bottom, Top) +#define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ - /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +#define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -1948,49 +1695,48 @@ int yydebug; evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +#define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +#ifndef yystrlen +#if defined __GLIBC__ && defined _STRING_H +#define yystrlen strlen +#else /* Return the length of YYSTR. */ static YYSIZE_T -yystrlen (const char *yystr) +yystrlen(const char *yystr) { - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; } -# endif -# endif +#endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +#if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +#define yystpcpy stpcpy +#else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * -yystpcpy (char *yydest, const char *yysrc) +yystpcpy(char *yydest, const char *yysrc) { - char *yyd = yydest; - const char *yys = yysrc; + char *yyd = yydest; + const char *yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; + while ((*yyd++ = *yys++) != '\0') + continue; - return yyd - 1; + return yyd - 1; } -# endif -# endif +#endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -1999,44 +1745,43 @@ yystpcpy (char *yydest, const char *yysrc) null, do not copy; instead, return the length of what the result would have been. */ static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) +yytnamerr(char *yyres, const char *yystr) { - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; + if (*yystr == '"') { + YYSIZE_T yyn = 0; + char const *yyp = yystr; - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; + for (;;) + switch (*++yyp) { + case '\'': + case ',': + goto do_not_strip_quotes; - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: + ; } - if (! yyres) - return yystrlen (yystr); + if (!yyres) + return yystrlen(yystr); - return yystpcpy (yyres, yystr) - yyres; + return yystpcpy(yyres, yystr) - yyres; } -# endif +#endif /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message about the unexpected token YYTOKEN for the state stack whose top is @@ -2047,130 +1792,124 @@ yytnamerr (char *yyres, const char *yystr) *YYMSG_ALLOC to the required number of bytes. Return 2 if the required number of bytes is too large to store. */ static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +yysyntax_error(YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, + int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; + YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default(yyn)) { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error(yytable[yyx + yyn])) { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = + yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); + if (!(yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } - } } } - switch (yycount) + switch (yycount) { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, + YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or " + "%s or %s")); +#undef YYCASE_ + } + { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ + YYSIZE_T yysize1 = yysize + yystrlen(yyformat); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; } - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + if (*yymsg_alloc < yysize) { + *yymsg_alloc = 2 * yysize; + if (!(yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } - if (*yymsg_alloc < yysize) + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) { + yyp += yytnamerr(yyp, yyarg[yyi++]); + yyformat += 2; + } else { + yyp++; + yyformat++; + } } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; + return 0; } #endif /* YYERROR_VERBOSE */ @@ -2179,21 +1918,18 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep) { - YYUSE (yyvaluep); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YYUSE(yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); - YY_IGNORE_MAYBE_UNINITIALIZED_END + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE(yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END } - - - /* The lookahead symbol. */ int yychar; @@ -2202,13 +1938,12 @@ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; - /*----------. | yyparse. | `----------*/ int -yyparse (void) +yyparse(void) { int yystate; /* Number of tokens to shift before error messages enabled. */ @@ -2233,3557 +1968,3619 @@ yyparse (void) YYSIZE_T yystacksize; - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; #if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); + YYDPRINTF((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; - yysetstate: - *yyssp = yystate; +yysetstate: + *yyssp = yystate; - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + if (yyss + yystacksize - 1 <= yyssp) { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow(YY_("memory exhausted"), &yyss1, + yysize * sizeof(*yyssp), &yyvs1, + yysize * sizeof(*yyvsp), &yystacksize); - yyss = yyss1; - yyvs = yyvs1; - } + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) +#ifndef YYSTACK_RELOCATE goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; +#else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize)); + if (!yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE(yyss_alloc, yyss); + YYSTACK_RELOCATE(yyvs_alloc, yyvs); +#undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE(yyss1); + } +#endif #endif /* no yyoverflow */ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YYDPRINTF((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; } - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YYDPRINTF((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) - YYACCEPT; + if (yystate == YYFINAL) + YYACCEPT; - goto yybackup; + goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default(yyn)) + goto yydefault; - /* Not known => get a lookahead token if don't already have one. */ + /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (); + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) { + YYDPRINTF((stderr, "Reading a token: ")); + yychar = yylex(); } - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + if (yychar <= YYEOF) { + yychar = yytoken = YYEOF; + YYDPRINTF((stderr, "Now at end of input.\n")); + } else { + yytoken = YYTRANSLATE(yychar); + YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc); } - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) { + if (yytable_value_is_error(yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; } - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); - /* Discard the shifted token. */ - yychar = YYEMPTY; + /* Discard the shifted token. */ + yychar = YYEMPTY; - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - goto yynewstate; + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1 - yylen]; - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 6: + YY_REDUCE_PRINT(yyn); + switch (yyn) { + case 6: #line 285 "lev_comp.y" /* yacc.c:1646 */ { - if (fatal_error > 0) { - (void) fprintf(stderr, - "%s: %d errors detected for level \"%s\". No output created!\n", - fname, fatal_error, (yyvsp[-2].map)); - fatal_error = 0; - got_errors++; - } else if (!got_errors) { - if (!write_level_file((yyvsp[-2].map), splev)) { - lc_error("Can't write output file for '%s'!", (yyvsp[-2].map)); - exit(EXIT_FAILURE); - } - } - Free((yyvsp[-2].map)); - Free(splev); - splev = NULL; - vardef_free_all(variable_definitions); - variable_definitions = NULL; - } + if (fatal_error > 0) { + (void) fprintf(stderr, "%s: %d errors detected for level \"%s\". " + "No output created!\n", + fname, fatal_error, (yyvsp[-2].map)); + fatal_error = 0; + got_errors++; + } else if (!got_errors) { + if (!write_level_file((yyvsp[-2].map), splev)) { + lc_error("Can't write output file for '%s'!", + (yyvsp[-2].map)); + exit(EXIT_FAILURE); + } + } + Free((yyvsp[-2].map)); + Free(splev); + splev = NULL; + vardef_free_all(variable_definitions); + variable_definitions = NULL; + } #line 2467 "y.tab.c" /* yacc.c:1646 */ break; - case 7: + case 7: #line 307 "lev_comp.y" /* yacc.c:1646 */ { - start_level_def(&splev, (yyvsp[0].map)); - (yyval.map) = (yyvsp[0].map); - } + start_level_def(&splev, (yyvsp[0].map)); + (yyval.map) = (yyvsp[0].map); + } #line 2476 "y.tab.c" /* yacc.c:1646 */ break; - case 8: + case 8: #line 312 "lev_comp.y" /* yacc.c:1646 */ { - start_level_def(&splev, (yyvsp[-2].map)); - if ((yyvsp[0].i) == -1) { - add_opvars(splev, "iiiiiiiio", - VA_PASS9(LVLINIT_MAZEGRID,HWALL,0,0, - 0,0,0,0, SPO_INITLEVEL)); - } else { - long bg = what_map_char((char) (yyvsp[0].i)); - add_opvars(splev, "iiiiiiiio", - VA_PASS9(LVLINIT_SOLIDFILL, bg, 0,0, - 0,0,0,0, SPO_INITLEVEL)); - } - add_opvars(splev, "io", - VA_PASS2(MAZELEVEL, SPO_LEVEL_FLAGS)); - max_x_map = COLNO-1; - max_y_map = ROWNO; - (yyval.map) = (yyvsp[-2].map); - } + start_level_def(&splev, (yyvsp[-2].map)); + if ((yyvsp[0].i) == -1) { + add_opvars(splev, "iiiiiiiio", + VA_PASS9(LVLINIT_MAZEGRID, HWALL, 0, 0, 0, 0, 0, 0, + SPO_INITLEVEL)); + } else { + long bg = what_map_char((char) (yyvsp[0].i)); + add_opvars(splev, "iiiiiiiio", + VA_PASS9(LVLINIT_SOLIDFILL, bg, 0, 0, 0, 0, 0, 0, + SPO_INITLEVEL)); + } + add_opvars(splev, "io", VA_PASS2(MAZELEVEL, SPO_LEVEL_FLAGS)); + max_x_map = COLNO - 1; + max_y_map = ROWNO; + (yyval.map) = (yyvsp[-2].map); + } #line 2499 "y.tab.c" /* yacc.c:1646 */ break; - case 9: + case 9: #line 333 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 2507 "y.tab.c" /* yacc.c:1646 */ break; - case 10: + case 10: #line 337 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = what_map_char((char) (yyvsp[0].i)); - } + (yyval.i) = what_map_char((char) (yyvsp[0].i)); + } #line 2515 "y.tab.c" /* yacc.c:1646 */ break; - case 11: + case 11: #line 343 "lev_comp.y" /* yacc.c:1646 */ { - long filling = (yyvsp[0].terr).ter; - if (filling == INVALID_TYPE || filling >= MAX_TYPE) - lc_error("INIT_MAP: Invalid fill char type."); - add_opvars(splev, "iiiiiiiio", - LVLINIT_SOLIDFILL,filling,0,(long)(yyvsp[0].terr).lit, 0,0,0,0, SPO_INITLEVEL); - max_x_map = COLNO-1; - max_y_map = ROWNO; - } + long filling = (yyvsp[0].terr).ter; + if (filling == INVALID_TYPE || filling >= MAX_TYPE) + lc_error("INIT_MAP: Invalid fill char type."); + add_opvars(splev, "iiiiiiiio", LVLINIT_SOLIDFILL, filling, 0, + (long) (yyvsp[0].terr).lit, 0, 0, 0, 0, SPO_INITLEVEL); + max_x_map = COLNO - 1; + max_y_map = ROWNO; + } #line 2529 "y.tab.c" /* yacc.c:1646 */ break; - case 12: + case 12: #line 353 "lev_comp.y" /* yacc.c:1646 */ { - long filling = what_map_char((char) (yyvsp[0].i)); - if (filling == INVALID_TYPE || filling >= MAX_TYPE) - lc_error("INIT_MAP: Invalid fill char type."); - add_opvars(splev, "iiiiiiiio", - VA_PASS9(LVLINIT_MAZEGRID,filling,0,0, - 0,0,0,0, SPO_INITLEVEL)); - max_x_map = COLNO-1; - max_y_map = ROWNO; - } + long filling = what_map_char((char) (yyvsp[0].i)); + if (filling == INVALID_TYPE || filling >= MAX_TYPE) + lc_error("INIT_MAP: Invalid fill char type."); + add_opvars(splev, "iiiiiiiio", + VA_PASS9(LVLINIT_MAZEGRID, filling, 0, 0, 0, 0, 0, 0, + SPO_INITLEVEL)); + max_x_map = COLNO - 1; + max_y_map = ROWNO; + } #line 2544 "y.tab.c" /* yacc.c:1646 */ break; - case 13: + case 13: #line 364 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiiiio", - VA_PASS9(LVLINIT_ROGUE,0,0,0, - 0,0,0,0, SPO_INITLEVEL)); - } + add_opvars(splev, "iiiiiiiio", VA_PASS9(LVLINIT_ROGUE, 0, 0, 0, 0, 0, + 0, 0, SPO_INITLEVEL)); + } #line 2554 "y.tab.c" /* yacc.c:1646 */ break; - case 14: + case 14: #line 370 "lev_comp.y" /* yacc.c:1646 */ { - long fg = what_map_char((char) (yyvsp[-11].i)); - long bg = what_map_char((char) (yyvsp[-9].i)); - long smoothed = (yyvsp[-7].i); - long joined = (yyvsp[-5].i); - long lit = (yyvsp[-3].i); - long walled = (yyvsp[-1].i); - long filling = (yyvsp[0].i); - if (fg == INVALID_TYPE || fg >= MAX_TYPE) - lc_error("INIT_MAP: Invalid foreground type."); - if (bg == INVALID_TYPE || bg >= MAX_TYPE) - lc_error("INIT_MAP: Invalid background type."); - if (joined && fg != CORR && fg != ROOM) - lc_error("INIT_MAP: Invalid foreground type for joined map."); + long fg = what_map_char((char) (yyvsp[-11].i)); + long bg = what_map_char((char) (yyvsp[-9].i)); + long smoothed = (yyvsp[-7].i); + long joined = (yyvsp[-5].i); + long lit = (yyvsp[-3].i); + long walled = (yyvsp[-1].i); + long filling = (yyvsp[0].i); + if (fg == INVALID_TYPE || fg >= MAX_TYPE) + lc_error("INIT_MAP: Invalid foreground type."); + if (bg == INVALID_TYPE || bg >= MAX_TYPE) + lc_error("INIT_MAP: Invalid background type."); + if (joined && fg != CORR && fg != ROOM) + lc_error("INIT_MAP: Invalid foreground type for joined map."); - if (filling == INVALID_TYPE) - lc_error("INIT_MAP: Invalid fill char type."); + if (filling == INVALID_TYPE) + lc_error("INIT_MAP: Invalid fill char type."); - add_opvars(splev, "iiiiiiiio", - VA_PASS9(LVLINIT_MINES,filling,walled,lit, - joined,smoothed,bg,fg, - SPO_INITLEVEL)); - max_x_map = COLNO-1; - max_y_map = ROWNO; - } + add_opvars(splev, "iiiiiiiio", + VA_PASS9(LVLINIT_MINES, filling, walled, lit, joined, + smoothed, bg, fg, SPO_INITLEVEL)); + max_x_map = COLNO - 1; + max_y_map = ROWNO; + } #line 2584 "y.tab.c" /* yacc.c:1646 */ break; - case 15: + case 15: #line 398 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 0; - } + (yyval.i) = 0; + } #line 2592 "y.tab.c" /* yacc.c:1646 */ break; - case 16: + case 16: #line 402 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 2600 "y.tab.c" /* yacc.c:1646 */ break; - case 17: + case 17: #line 408 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_COPY)); - (yyval.i) = 0; - } + add_opvars(splev, "o", VA_PASS1(SPO_COPY)); + (yyval.i) = 0; + } #line 2609 "y.tab.c" /* yacc.c:1646 */ break; - case 18: + case 18: #line 413 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1; - } + (yyval.i) = 1; + } #line 2617 "y.tab.c" /* yacc.c:1646 */ break; - case 19: + case 19: #line 419 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 2625 "y.tab.c" /* yacc.c:1646 */ break; - case 20: + case 20: #line 423 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = what_map_char((char) (yyvsp[0].i)); - } + (yyval.i) = what_map_char((char) (yyvsp[0].i)); + } #line 2633 "y.tab.c" /* yacc.c:1646 */ break; - case 23: + case 23: #line 434 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(0, SPO_LEVEL_FLAGS)); - } + add_opvars(splev, "io", VA_PASS2(0, SPO_LEVEL_FLAGS)); + } #line 2641 "y.tab.c" /* yacc.c:1646 */ break; - case 24: + case 24: #line 438 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2((yyvsp[0].i), SPO_LEVEL_FLAGS)); - } + add_opvars(splev, "io", VA_PASS2((yyvsp[0].i), SPO_LEVEL_FLAGS)); + } #line 2649 "y.tab.c" /* yacc.c:1646 */ break; - case 25: + case 25: #line 444 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); - } + (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); + } #line 2657 "y.tab.c" /* yacc.c:1646 */ break; - case 26: + case 26: #line 448 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 2665 "y.tab.c" /* yacc.c:1646 */ break; - case 27: + case 27: #line 454 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 0; - } + (yyval.i) = 0; + } #line 2673 "y.tab.c" /* yacc.c:1646 */ break; - case 28: + case 28: #line 458 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1 + (yyvsp[0].i); - } + (yyval.i) = 1 + (yyvsp[0].i); + } #line 2681 "y.tab.c" /* yacc.c:1646 */ break; - case 29: + case 29: #line 464 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[-1].i); - } + (yyval.i) = (yyvsp[-1].i); + } #line 2689 "y.tab.c" /* yacc.c:1646 */ break; - case 97: + case 97: #line 547 "lev_comp.y" /* yacc.c:1646 */ { - struct lc_vardefs *vd; - if ((vd = vardef_defined(variable_definitions, (yyvsp[0].map), 1))) { - if (!(vd->var_type & SPOVAR_ARRAY)) - lc_error("Trying to shuffle non-array variable '%s'", (yyvsp[0].map)); - } else lc_error("Trying to shuffle undefined variable '%s'", (yyvsp[0].map)); - add_opvars(splev, "so", VA_PASS2((yyvsp[0].map), SPO_SHUFFLE_ARRAY)); - Free((yyvsp[0].map)); - } + struct lc_vardefs *vd; + if ((vd = vardef_defined(variable_definitions, (yyvsp[0].map), 1))) { + if (!(vd->var_type & SPOVAR_ARRAY)) + lc_error("Trying to shuffle non-array variable '%s'", + (yyvsp[0].map)); + } else + lc_error("Trying to shuffle undefined variable '%s'", + (yyvsp[0].map)); + add_opvars(splev, "so", VA_PASS2((yyvsp[0].map), SPO_SHUFFLE_ARRAY)); + Free((yyvsp[0].map)); + } #line 2703 "y.tab.c" /* yacc.c:1646 */ break; - case 98: + case 98: #line 559 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-2].map), SPOVAR_INT); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); - Free((yyvsp[-2].map)); - } + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-2].map), SPOVAR_INT); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); + Free((yyvsp[-2].map)); + } #line 2713 "y.tab.c" /* yacc.c:1646 */ break; - case 99: + case 99: #line 565 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_SEL); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-4].map), SPOVAR_SEL); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2723 "y.tab.c" /* yacc.c:1646 */ break; - case 100: + case 100: #line 571 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-2].map), SPOVAR_STRING); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); - Free((yyvsp[-2].map)); - } + variable_definitions = add_vardef_type( + variable_definitions, (yyvsp[-2].map), SPOVAR_STRING); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); + Free((yyvsp[-2].map)); + } #line 2733 "y.tab.c" /* yacc.c:1646 */ break; - case 101: + case 101: #line 577 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_MAPCHAR); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + variable_definitions = add_vardef_type( + variable_definitions, (yyvsp[-4].map), SPOVAR_MAPCHAR); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2743 "y.tab.c" /* yacc.c:1646 */ break; - case 102: + case 102: #line 583 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_MONST); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-4].map), SPOVAR_MONST); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2753 "y.tab.c" /* yacc.c:1646 */ break; - case 103: + case 103: #line 589 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_OBJ); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-4].map), SPOVAR_OBJ); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2763 "y.tab.c" /* yacc.c:1646 */ break; - case 104: + case 104: #line 595 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-2].map), SPOVAR_COORD); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); - Free((yyvsp[-2].map)); - } + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-2].map), SPOVAR_COORD); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); + Free((yyvsp[-2].map)); + } #line 2773 "y.tab.c" /* yacc.c:1646 */ break; - case 105: + case 105: #line 601 "lev_comp.y" /* yacc.c:1646 */ { - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-2].map), SPOVAR_REGION); - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); - Free((yyvsp[-2].map)); - } + variable_definitions = add_vardef_type( + variable_definitions, (yyvsp[-2].map), SPOVAR_REGION); + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-2].map), SPO_VAR_INIT)); + Free((yyvsp[-2].map)); + } #line 2783 "y.tab.c" /* yacc.c:1646 */ break; - case 106: + case 106: #line 607 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_INT|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = add_vardef_type( + variable_definitions, (yyvsp[-4].map), SPOVAR_INT | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2795 "y.tab.c" /* yacc.c:1646 */ break; - case 107: + case 107: #line 615 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_COORD|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-4].map), + SPOVAR_COORD | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2807 "y.tab.c" /* yacc.c:1646 */ break; - case 108: + case 108: #line 623 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_REGION|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-4].map), + SPOVAR_REGION | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2819 "y.tab.c" /* yacc.c:1646 */ break; - case 109: + case 109: #line 631 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-6].map), SPOVAR_MAPCHAR|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); - Free((yyvsp[-6].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-6].map), + SPOVAR_MAPCHAR | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); + Free((yyvsp[-6].map)); + } #line 2831 "y.tab.c" /* yacc.c:1646 */ break; - case 110: + case 110: #line 639 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-6].map), SPOVAR_MONST|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); - Free((yyvsp[-6].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-6].map), + SPOVAR_MONST | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); + Free((yyvsp[-6].map)); + } #line 2843 "y.tab.c" /* yacc.c:1646 */ break; - case 111: + case 111: #line 647 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-6].map), SPOVAR_OBJ|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); - Free((yyvsp[-6].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = add_vardef_type( + variable_definitions, (yyvsp[-6].map), SPOVAR_OBJ | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-6].map), SPO_VAR_INIT)); + Free((yyvsp[-6].map)); + } #line 2855 "y.tab.c" /* yacc.c:1646 */ break; - case 112: + case 112: #line 655 "lev_comp.y" /* yacc.c:1646 */ { - long n_items = (yyvsp[-1].i); - variable_definitions = add_vardef_type(variable_definitions, (yyvsp[-4].map), SPOVAR_STRING|SPOVAR_ARRAY); - add_opvars(splev, "iso", - VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); - Free((yyvsp[-4].map)); - } + long n_items = (yyvsp[-1].i); + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-4].map), + SPOVAR_STRING | SPOVAR_ARRAY); + add_opvars(splev, "iso", + VA_PASS3(n_items, (yyvsp[-4].map), SPO_VAR_INIT)); + Free((yyvsp[-4].map)); + } #line 2867 "y.tab.c" /* yacc.c:1646 */ break; - case 113: + case 113: #line 665 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1; - } + add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1; + } #line 2876 "y.tab.c" /* yacc.c:1646 */ break; - case 114: + case 114: #line 670 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1 + (yyvsp[-2].i); - } + add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2885 "y.tab.c" /* yacc.c:1646 */ break; - case 115: + case 115: #line 677 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1; - } + add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1; + } #line 2894 "y.tab.c" /* yacc.c:1646 */ break; - case 116: + case 116: #line 682 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1 + (yyvsp[-2].i); - } + add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2903 "y.tab.c" /* yacc.c:1646 */ break; - case 117: + case 117: #line 689 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1; - } + add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1; + } #line 2912 "y.tab.c" /* yacc.c:1646 */ break; - case 118: + case 118: #line 694 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1 + (yyvsp[-2].i); - } + add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2921 "y.tab.c" /* yacc.c:1646 */ break; - case 119: + case 119: #line 701 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1; - } + (yyval.i) = 1; + } #line 2929 "y.tab.c" /* yacc.c:1646 */ break; - case 120: + case 120: #line 705 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1 + (yyvsp[-2].i); - } + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2937 "y.tab.c" /* yacc.c:1646 */ break; - case 121: + case 121: #line 711 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1; - } + add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1; + } #line 2946 "y.tab.c" /* yacc.c:1646 */ break; - case 122: + case 122: #line 716 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); - (yyval.i) = 1 + (yyvsp[-2].i); - } + add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2955 "y.tab.c" /* yacc.c:1646 */ break; - case 123: + case 123: #line 723 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1; - } + (yyval.i) = 1; + } #line 2963 "y.tab.c" /* yacc.c:1646 */ break; - case 124: + case 124: #line 727 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1 + (yyvsp[-2].i); - } + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2971 "y.tab.c" /* yacc.c:1646 */ break; - case 125: + case 125: #line 733 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1; - } + (yyval.i) = 1; + } #line 2979 "y.tab.c" /* yacc.c:1646 */ break; - case 126: + case 126: #line 737 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1 + (yyvsp[-2].i); - } + (yyval.i) = 1 + (yyvsp[-2].i); + } #line 2987 "y.tab.c" /* yacc.c:1646 */ break; - case 127: + case 127: #line 743 "lev_comp.y" /* yacc.c:1646 */ { - struct lc_funcdefs *funcdef; + struct lc_funcdefs *funcdef; - if (in_function_definition) - lc_error("Recursively defined functions not allowed (function %s).", (yyvsp[-1].map)); + if (in_function_definition) + lc_error( + "Recursively defined functions not allowed (function %s).", + (yyvsp[-1].map)); - in_function_definition++; + in_function_definition++; - if (funcdef_defined(function_definitions, (yyvsp[-1].map), 1)) - lc_error("Function '%s' already defined once.", (yyvsp[-1].map)); + if (funcdef_defined(function_definitions, (yyvsp[-1].map), 1)) + lc_error("Function '%s' already defined once.", (yyvsp[-1].map)); - funcdef = funcdef_new(-1, (yyvsp[-1].map)); - funcdef->next = function_definitions; - function_definitions = funcdef; - function_splev_backup = splev; - splev = &(funcdef->code); - Free((yyvsp[-1].map)); - curr_function = funcdef; - function_tmp_var_defs = variable_definitions; - variable_definitions = NULL; - } + funcdef = funcdef_new(-1, (yyvsp[-1].map)); + funcdef->next = function_definitions; + function_definitions = funcdef; + function_splev_backup = splev; + splev = &(funcdef->code); + Free((yyvsp[-1].map)); + curr_function = funcdef; + function_tmp_var_defs = variable_definitions; + variable_definitions = NULL; + } #line 3013 "y.tab.c" /* yacc.c:1646 */ break; - case 128: + case 128: #line 765 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 3021 "y.tab.c" /* yacc.c:1646 */ break; - case 129: + case 129: #line 769 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(0, SPO_RETURN)); - splev = function_splev_backup; - in_function_definition--; - curr_function = NULL; - vardef_free_all(variable_definitions); - variable_definitions = function_tmp_var_defs; - } + add_opvars(splev, "io", VA_PASS2(0, SPO_RETURN)); + splev = function_splev_backup; + in_function_definition--; + curr_function = NULL; + vardef_free_all(variable_definitions); + variable_definitions = function_tmp_var_defs; + } #line 3034 "y.tab.c" /* yacc.c:1646 */ break; - case 130: + case 130: #line 780 "lev_comp.y" /* yacc.c:1646 */ { - struct lc_funcdefs *tmpfunc; - tmpfunc = funcdef_defined(function_definitions, (yyvsp[-3].map), 1); - if (tmpfunc) { - long l; - long nparams = strlen( (yyvsp[-1].map) ); - char *fparamstr = funcdef_paramtypes(tmpfunc); - if (strcmp((yyvsp[-1].map), fparamstr)) { - char *tmps = strdup(decode_parm_str(fparamstr)); - lc_error("Function '%s' requires params '%s', got '%s' instead.", (yyvsp[-3].map), tmps, decode_parm_str((yyvsp[-1].map))); - Free(tmps); - } - Free(fparamstr); - Free((yyvsp[-1].map)); - if (!(tmpfunc->n_called)) { - /* we haven't called the function yet, so insert it in the code */ - struct opvar *jmp = New(struct opvar); - set_opvar_int(jmp, splev->n_opcodes+1); - add_opcode(splev, SPO_PUSH, jmp); - add_opcode(splev, SPO_JMP, NULL); /* we must jump past it first, then CALL it, due to RETURN. */ + struct lc_funcdefs *tmpfunc; + tmpfunc = funcdef_defined(function_definitions, (yyvsp[-3].map), 1); + if (tmpfunc) { + long l; + long nparams = strlen((yyvsp[-1].map)); + char *fparamstr = funcdef_paramtypes(tmpfunc); + if (strcmp((yyvsp[-1].map), fparamstr)) { + char *tmps = strdup(decode_parm_str(fparamstr)); + lc_error( + "Function '%s' requires params '%s', got '%s' instead.", + (yyvsp[-3].map), tmps, decode_parm_str((yyvsp[-1].map))); + Free(tmps); + } + Free(fparamstr); + Free((yyvsp[-1].map)); + if (!(tmpfunc->n_called)) { + /* we haven't called the function yet, so insert it in the + * code */ + struct opvar *jmp = New(struct opvar); + set_opvar_int(jmp, splev->n_opcodes + 1); + add_opcode(splev, SPO_PUSH, jmp); + add_opcode( + splev, + SPO_JMP, NULL); /* we must jump past it first, then CALL + it, due to RETURN. */ - tmpfunc->addr = splev->n_opcodes; + tmpfunc->addr = splev->n_opcodes; - { /* init function parameter variables */ - struct lc_funcdefs_parm *tfp = tmpfunc->params; - while (tfp) { - add_opvars(splev, "iso", - VA_PASS3(0, tfp->name, - SPO_VAR_INIT)); - tfp = tfp->next; - } - } + { /* init function parameter variables */ + struct lc_funcdefs_parm *tfp = tmpfunc->params; + while (tfp) { + add_opvars(splev, "iso", + VA_PASS3(0, tfp->name, SPO_VAR_INIT)); + tfp = tfp->next; + } + } - splev_add_from(splev, &(tmpfunc->code)); - set_opvar_int(jmp, splev->n_opcodes - jmp->vardata.l); - } - l = tmpfunc->addr - splev->n_opcodes - 2; - add_opvars(splev, "iio", - VA_PASS3(nparams, l, SPO_CALL)); - tmpfunc->n_called++; - } else { - lc_error("Function '%s' not defined.", (yyvsp[-3].map)); - } - Free((yyvsp[-3].map)); - } + splev_add_from(splev, &(tmpfunc->code)); + set_opvar_int(jmp, splev->n_opcodes - jmp->vardata.l); + } + l = tmpfunc->addr - splev->n_opcodes - 2; + add_opvars(splev, "iio", VA_PASS3(nparams, l, SPO_CALL)); + tmpfunc->n_called++; + } else { + lc_error("Function '%s' not defined.", (yyvsp[-3].map)); + } + Free((yyvsp[-3].map)); + } #line 3084 "y.tab.c" /* yacc.c:1646 */ break; - case 131: + case 131: #line 828 "lev_comp.y" /* yacc.c:1646 */ { - add_opcode(splev, SPO_EXIT, NULL); - } + add_opcode(splev, SPO_EXIT, NULL); + } #line 3092 "y.tab.c" /* yacc.c:1646 */ break; - case 132: + case 132: #line 834 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 100; - } + (yyval.i) = 100; + } #line 3100 "y.tab.c" /* yacc.c:1646 */ break; - case 133: + case 133: #line 838 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 3108 "y.tab.c" /* yacc.c:1646 */ break; - case 134: + case 134: #line 844 "lev_comp.y" /* yacc.c:1646 */ { - /* val > rn2(100) */ - add_opvars(splev, "iio", - VA_PASS3((long)(yyvsp[0].i), 100, SPO_RN2)); - (yyval.i) = SPO_JG; - } + /* val > rn2(100) */ + add_opvars(splev, "iio", VA_PASS3((long) (yyvsp[0].i), 100, SPO_RN2)); + (yyval.i) = SPO_JG; + } #line 3119 "y.tab.c" /* yacc.c:1646 */ break; - case 135: + case 135: #line 851 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[-2].i); - } + (yyval.i) = (yyvsp[-2].i); + } #line 3127 "y.tab.c" /* yacc.c:1646 */ break; - case 136: + case 136: #line 855 "lev_comp.y" /* yacc.c:1646 */ { - /* boolean, explicit foo != 0 */ - add_opvars(splev, "i", VA_PASS1(0)); - (yyval.i) = SPO_JNE; - } + /* boolean, explicit foo != 0 */ + add_opvars(splev, "i", VA_PASS1(0)); + (yyval.i) = SPO_JNE; + } #line 3137 "y.tab.c" /* yacc.c:1646 */ break; - case 137: + case 137: #line 863 "lev_comp.y" /* yacc.c:1646 */ { - is_inconstant_number = 0; - } + is_inconstant_number = 0; + } #line 3145 "y.tab.c" /* yacc.c:1646 */ break; - case 138: + case 138: #line 867 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *chkjmp; - if (in_switch_statement > 0) - lc_error("Cannot nest switch-statements."); + struct opvar *chkjmp; + if (in_switch_statement > 0) + lc_error("Cannot nest switch-statements."); - in_switch_statement++; + in_switch_statement++; - n_switch_case_list = 0; - switch_default_case = NULL; + n_switch_case_list = 0; + switch_default_case = NULL; - if (!is_inconstant_number) - add_opvars(splev, "o", VA_PASS1(SPO_RN2)); - is_inconstant_number = 0; + if (!is_inconstant_number) + add_opvars(splev, "o", VA_PASS1(SPO_RN2)); + is_inconstant_number = 0; - chkjmp = New(struct opvar); - set_opvar_int(chkjmp, splev->n_opcodes+1); - switch_check_jump = chkjmp; - add_opcode(splev, SPO_PUSH, chkjmp); - add_opcode(splev, SPO_JMP, NULL); - break_stmt_start(); - } + chkjmp = New(struct opvar); + set_opvar_int(chkjmp, splev->n_opcodes + 1); + switch_check_jump = chkjmp; + add_opcode(splev, SPO_PUSH, chkjmp); + add_opcode(splev, SPO_JMP, NULL); + break_stmt_start(); + } #line 3171 "y.tab.c" /* yacc.c:1646 */ break; - case 139: + case 139: #line 889 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *endjump = New(struct opvar); - int i; + struct opvar *endjump = New(struct opvar); + int i; - set_opvar_int(endjump, splev->n_opcodes+1); + set_opvar_int(endjump, splev->n_opcodes + 1); - add_opcode(splev, SPO_PUSH, endjump); - add_opcode(splev, SPO_JMP, NULL); + add_opcode(splev, SPO_PUSH, endjump); + add_opcode(splev, SPO_JMP, NULL); - set_opvar_int(switch_check_jump, - splev->n_opcodes - switch_check_jump->vardata.l); + set_opvar_int(switch_check_jump, + splev->n_opcodes - switch_check_jump->vardata.l); - for (i = 0; i < n_switch_case_list; i++) { - add_opvars(splev, "oio", - VA_PASS3(SPO_COPY, - switch_case_value[i], SPO_CMP)); - set_opvar_int(switch_case_list[i], - switch_case_list[i]->vardata.l - splev->n_opcodes-1); - add_opcode(splev, SPO_PUSH, switch_case_list[i]); - add_opcode(splev, SPO_JE, NULL); - } + for (i = 0; i < n_switch_case_list; i++) { + add_opvars(splev, "oio", + VA_PASS3(SPO_COPY, switch_case_value[i], SPO_CMP)); + set_opvar_int(switch_case_list[i], switch_case_list[i]->vardata.l + - splev->n_opcodes - 1); + add_opcode(splev, SPO_PUSH, switch_case_list[i]); + add_opcode(splev, SPO_JE, NULL); + } - if (switch_default_case) { - set_opvar_int(switch_default_case, - switch_default_case->vardata.l - splev->n_opcodes-1); - add_opcode(splev, SPO_PUSH, switch_default_case); - add_opcode(splev, SPO_JMP, NULL); - } + if (switch_default_case) { + set_opvar_int(switch_default_case, switch_default_case->vardata.l + - splev->n_opcodes - 1); + add_opcode(splev, SPO_PUSH, switch_default_case); + add_opcode(splev, SPO_JMP, NULL); + } - set_opvar_int(endjump, splev->n_opcodes - endjump->vardata.l); + set_opvar_int(endjump, splev->n_opcodes - endjump->vardata.l); - break_stmt_end(splev); + break_stmt_end(splev); - add_opcode(splev, SPO_POP, NULL); /* get rid of the value in stack */ - in_switch_statement--; + add_opcode(splev, SPO_POP, NULL); /* get rid of the value in stack */ + in_switch_statement--; - - } + } #line 3214 "y.tab.c" /* yacc.c:1646 */ break; - case 142: + case 142: #line 934 "lev_comp.y" /* yacc.c:1646 */ { - if (n_switch_case_list < MAX_SWITCH_CASES) { - struct opvar *tmppush = New(struct opvar); - set_opvar_int(tmppush, splev->n_opcodes); - switch_case_value[n_switch_case_list] = (yyvsp[-1].i); - switch_case_list[n_switch_case_list++] = tmppush; - } else lc_error("Too many cases in a switch."); - } + if (n_switch_case_list < MAX_SWITCH_CASES) { + struct opvar *tmppush = New(struct opvar); + set_opvar_int(tmppush, splev->n_opcodes); + switch_case_value[n_switch_case_list] = (yyvsp[-1].i); + switch_case_list[n_switch_case_list++] = tmppush; + } else + lc_error("Too many cases in a switch."); + } #line 3227 "y.tab.c" /* yacc.c:1646 */ break; - case 143: + case 143: #line 943 "lev_comp.y" /* yacc.c:1646 */ { - } + } #line 3234 "y.tab.c" /* yacc.c:1646 */ break; - case 144: + case 144: #line 946 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *tmppush = New(struct opvar); + struct opvar *tmppush = New(struct opvar); - if (switch_default_case) - lc_error("Switch default case already used."); + if (switch_default_case) + lc_error("Switch default case already used."); - set_opvar_int(tmppush, splev->n_opcodes); - switch_default_case = tmppush; - } + set_opvar_int(tmppush, splev->n_opcodes); + switch_default_case = tmppush; + } #line 3248 "y.tab.c" /* yacc.c:1646 */ break; - case 145: + case 145: #line 956 "lev_comp.y" /* yacc.c:1646 */ { - } + } #line 3255 "y.tab.c" /* yacc.c:1646 */ break; - case 146: + case 146: #line 961 "lev_comp.y" /* yacc.c:1646 */ { - if (!allow_break_statements) - lc_error("Cannot use BREAK outside a statement block."); - else { - break_stmt_new(splev, splev->n_opcodes); - } - } + if (!allow_break_statements) + lc_error("Cannot use BREAK outside a statement block."); + else { + break_stmt_new(splev, splev->n_opcodes); + } + } #line 3267 "y.tab.c" /* yacc.c:1646 */ break; - case 149: + case 149: #line 975 "lev_comp.y" /* yacc.c:1646 */ { - char buf[256], buf2[256]; + char buf[256], buf2[256]; - if (n_forloops >= MAX_NESTED_IFS) { - lc_error("FOR: Too deeply nested loops."); - n_forloops = MAX_NESTED_IFS - 1; - } + if (n_forloops >= MAX_NESTED_IFS) { + lc_error("FOR: Too deeply nested loops."); + n_forloops = MAX_NESTED_IFS - 1; + } - /* first, define a variable for the for-loop end value */ - snprintf(buf, 255, "%s end", (yyvsp[-4].map)); - /* the value of which is already in stack (the 2nd math_expr) */ - add_opvars(splev, "iso", VA_PASS3(0, buf, SPO_VAR_INIT)); + /* first, define a variable for the for-loop end value */ + snprintf(buf, 255, "%s end", (yyvsp[-4].map)); + /* the value of which is already in stack (the 2nd math_expr) */ + add_opvars(splev, "iso", VA_PASS3(0, buf, SPO_VAR_INIT)); - variable_definitions = add_vardef_type(variable_definitions, - (yyvsp[-4].map), SPOVAR_INT); - /* define the for-loop variable. value is in stack (1st math_expr) */ - add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); + variable_definitions = add_vardef_type(variable_definitions, + (yyvsp[-4].map), SPOVAR_INT); + /* define the for-loop variable. value is in stack (1st math_expr) */ + add_opvars(splev, "iso", VA_PASS3(0, (yyvsp[-4].map), SPO_VAR_INIT)); - /* calculate value for the loop "step" variable */ - snprintf(buf2, 255, "%s step", (yyvsp[-4].map)); - /* end - start */ - add_opvars(splev, "vvo", - VA_PASS3(buf, (yyvsp[-4].map), SPO_MATH_SUB)); - /* sign of that */ - add_opvars(splev, "o", VA_PASS1(SPO_MATH_SIGN)); - /* save the sign into the step var */ - add_opvars(splev, "iso", - VA_PASS3(0, buf2, SPO_VAR_INIT)); + /* calculate value for the loop "step" variable */ + snprintf(buf2, 255, "%s step", (yyvsp[-4].map)); + /* end - start */ + add_opvars(splev, "vvo", + VA_PASS3(buf, (yyvsp[-4].map), SPO_MATH_SUB)); + /* sign of that */ + add_opvars(splev, "o", VA_PASS1(SPO_MATH_SIGN)); + /* save the sign into the step var */ + add_opvars(splev, "iso", VA_PASS3(0, buf2, SPO_VAR_INIT)); - forloop_list[n_forloops].varname = strdup((yyvsp[-4].map)); - forloop_list[n_forloops].jmp_point = splev->n_opcodes; + forloop_list[n_forloops].varname = strdup((yyvsp[-4].map)); + forloop_list[n_forloops].jmp_point = splev->n_opcodes; - n_forloops++; - Free((yyvsp[-4].map)); - } + n_forloops++; + Free((yyvsp[-4].map)); + } #line 3307 "y.tab.c" /* yacc.c:1646 */ break; - case 150: + case 150: #line 1013 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - break_stmt_start(); - } + /* nothing */ + break_stmt_start(); + } #line 3316 "y.tab.c" /* yacc.c:1646 */ break; - case 151: + case 151: #line 1018 "lev_comp.y" /* yacc.c:1646 */ { - char buf[256], buf2[256]; - n_forloops--; - snprintf(buf, 255, "%s step", forloop_list[n_forloops].varname); - snprintf(buf2, 255, "%s end", forloop_list[n_forloops].varname); - /* compare for-loop var to end value */ - add_opvars(splev, "vvo", - VA_PASS3(forloop_list[n_forloops].varname, - buf2, SPO_CMP)); - /* var + step */ - add_opvars(splev, "vvo", - VA_PASS3(buf, forloop_list[n_forloops].varname, - SPO_MATH_ADD)); - /* for-loop var = (for-loop var + step) */ - add_opvars(splev, "iso", - VA_PASS3(0, forloop_list[n_forloops].varname, - SPO_VAR_INIT)); - /* jump back if compared values were not equal */ - add_opvars(splev, "io", - VA_PASS2( - forloop_list[n_forloops].jmp_point - splev->n_opcodes - 1, - SPO_JNE)); - Free(forloop_list[n_forloops].varname); - break_stmt_end(splev); - } + char buf[256], buf2[256]; + n_forloops--; + snprintf(buf, 255, "%s step", forloop_list[n_forloops].varname); + snprintf(buf2, 255, "%s end", forloop_list[n_forloops].varname); + /* compare for-loop var to end value */ + add_opvars(splev, "vvo", + VA_PASS3(forloop_list[n_forloops].varname, buf2, SPO_CMP)); + /* var + step */ + add_opvars( + splev, "vvo", + VA_PASS3(buf, forloop_list[n_forloops].varname, SPO_MATH_ADD)); + /* for-loop var = (for-loop var + step) */ + add_opvars(splev, "iso", VA_PASS3(0, forloop_list[n_forloops].varname, + SPO_VAR_INIT)); + /* jump back if compared values were not equal */ + add_opvars(splev, "io", VA_PASS2(forloop_list[n_forloops].jmp_point + - splev->n_opcodes - 1, + SPO_JNE)); + Free(forloop_list[n_forloops].varname); + break_stmt_end(splev); + } #line 3346 "y.tab.c" /* yacc.c:1646 */ break; - case 152: + case 152: #line 1046 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *tmppush = New(struct opvar); + struct opvar *tmppush = New(struct opvar); - if (n_if_list >= MAX_NESTED_IFS) { - lc_error("LOOP: Too deeply nested conditionals."); - n_if_list = MAX_NESTED_IFS - 1; - } - set_opvar_int(tmppush, splev->n_opcodes); - if_list[n_if_list++] = tmppush; + if (n_if_list >= MAX_NESTED_IFS) { + lc_error("LOOP: Too deeply nested conditionals."); + n_if_list = MAX_NESTED_IFS - 1; + } + set_opvar_int(tmppush, splev->n_opcodes); + if_list[n_if_list++] = tmppush; - add_opvars(splev, "o", VA_PASS1(SPO_DEC)); - break_stmt_start(); - } + add_opvars(splev, "o", VA_PASS1(SPO_DEC)); + break_stmt_start(); + } #line 3364 "y.tab.c" /* yacc.c:1646 */ break; - case 153: + case 153: #line 1060 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *tmppush; + struct opvar *tmppush; - add_opvars(splev, "oio", VA_PASS3(SPO_COPY, 0, SPO_CMP)); + add_opvars(splev, "oio", VA_PASS3(SPO_COPY, 0, SPO_CMP)); - tmppush = (struct opvar *) if_list[--n_if_list]; - set_opvar_int(tmppush, tmppush->vardata.l - splev->n_opcodes-1); - add_opcode(splev, SPO_PUSH, tmppush); - add_opcode(splev, SPO_JG, NULL); - add_opcode(splev, SPO_POP, NULL); /* get rid of the count value in stack */ - break_stmt_end(splev); - } + tmppush = (struct opvar *) if_list[--n_if_list]; + set_opvar_int(tmppush, tmppush->vardata.l - splev->n_opcodes - 1); + add_opcode(splev, SPO_PUSH, tmppush); + add_opcode(splev, SPO_JG, NULL); + add_opcode(splev, SPO_POP, + NULL); /* get rid of the count value in stack */ + break_stmt_end(splev); + } #line 3381 "y.tab.c" /* yacc.c:1646 */ break; - case 154: + case 154: #line 1075 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *tmppush2 = New(struct opvar); + struct opvar *tmppush2 = New(struct opvar); - if (n_if_list >= MAX_NESTED_IFS) { - lc_error("IF: Too deeply nested conditionals."); - n_if_list = MAX_NESTED_IFS - 1; - } + if (n_if_list >= MAX_NESTED_IFS) { + lc_error("IF: Too deeply nested conditionals."); + n_if_list = MAX_NESTED_IFS - 1; + } - add_opcode(splev, SPO_CMP, NULL); + add_opcode(splev, SPO_CMP, NULL); - set_opvar_int(tmppush2, splev->n_opcodes+1); + set_opvar_int(tmppush2, splev->n_opcodes + 1); - if_list[n_if_list++] = tmppush2; + if_list[n_if_list++] = tmppush2; - add_opcode(splev, SPO_PUSH, tmppush2); + add_opcode(splev, SPO_PUSH, tmppush2); - add_opcode(splev, reverse_jmp_opcode( (yyvsp[-1].i) ), NULL); + add_opcode(splev, reverse_jmp_opcode((yyvsp[-1].i)), NULL); - } + } #line 3405 "y.tab.c" /* yacc.c:1646 */ break; - case 155: + case 155: #line 1095 "lev_comp.y" /* yacc.c:1646 */ { - if (n_if_list > 0) { - struct opvar *tmppush; - tmppush = (struct opvar *) if_list[--n_if_list]; - set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); - } else lc_error("IF: Huh?! No start address?"); - } + if (n_if_list > 0) { + struct opvar *tmppush; + tmppush = (struct opvar *) if_list[--n_if_list]; + set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); + } else + lc_error("IF: Huh?! No start address?"); + } #line 3417 "y.tab.c" /* yacc.c:1646 */ break; - case 156: + case 156: #line 1105 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *tmppush2 = New(struct opvar); + struct opvar *tmppush2 = New(struct opvar); - if (n_if_list >= MAX_NESTED_IFS) { - lc_error("IF: Too deeply nested conditionals."); - n_if_list = MAX_NESTED_IFS - 1; - } + if (n_if_list >= MAX_NESTED_IFS) { + lc_error("IF: Too deeply nested conditionals."); + n_if_list = MAX_NESTED_IFS - 1; + } - add_opcode(splev, SPO_CMP, NULL); + add_opcode(splev, SPO_CMP, NULL); - set_opvar_int(tmppush2, splev->n_opcodes+1); + set_opvar_int(tmppush2, splev->n_opcodes + 1); - if_list[n_if_list++] = tmppush2; + if_list[n_if_list++] = tmppush2; - add_opcode(splev, SPO_PUSH, tmppush2); + add_opcode(splev, SPO_PUSH, tmppush2); - add_opcode(splev, reverse_jmp_opcode( (yyvsp[0].i) ), NULL); + add_opcode(splev, reverse_jmp_opcode((yyvsp[0].i)), NULL); - } + } #line 3441 "y.tab.c" /* yacc.c:1646 */ break; - case 157: + case 157: #line 1125 "lev_comp.y" /* yacc.c:1646 */ { - /* do nothing */ - } + /* do nothing */ + } #line 3449 "y.tab.c" /* yacc.c:1646 */ break; - case 158: + case 158: #line 1131 "lev_comp.y" /* yacc.c:1646 */ { - if (n_if_list > 0) { - struct opvar *tmppush; - tmppush = (struct opvar *) if_list[--n_if_list]; - set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); - } else lc_error("IF: Huh?! No start address?"); - } + if (n_if_list > 0) { + struct opvar *tmppush; + tmppush = (struct opvar *) if_list[--n_if_list]; + set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); + } else + lc_error("IF: Huh?! No start address?"); + } #line 3461 "y.tab.c" /* yacc.c:1646 */ break; - case 159: + case 159: #line 1139 "lev_comp.y" /* yacc.c:1646 */ { - if (n_if_list > 0) { - struct opvar *tmppush = New(struct opvar); - struct opvar *tmppush2; + if (n_if_list > 0) { + struct opvar *tmppush = New(struct opvar); + struct opvar *tmppush2; - set_opvar_int(tmppush, splev->n_opcodes+1); - add_opcode(splev, SPO_PUSH, tmppush); + set_opvar_int(tmppush, splev->n_opcodes + 1); + add_opcode(splev, SPO_PUSH, tmppush); - add_opcode(splev, SPO_JMP, NULL); + add_opcode(splev, SPO_JMP, NULL); - tmppush2 = (struct opvar *) if_list[--n_if_list]; + tmppush2 = (struct opvar *) if_list[--n_if_list]; - set_opvar_int(tmppush2, splev->n_opcodes - tmppush2->vardata.l); - if_list[n_if_list++] = tmppush; - } else lc_error("IF: Huh?! No else-part address?"); - } + set_opvar_int(tmppush2, splev->n_opcodes - tmppush2->vardata.l); + if_list[n_if_list++] = tmppush; + } else + lc_error("IF: Huh?! No else-part address?"); + } #line 3482 "y.tab.c" /* yacc.c:1646 */ break; - case 160: + case 160: #line 1156 "lev_comp.y" /* yacc.c:1646 */ { - if (n_if_list > 0) { - struct opvar *tmppush; - tmppush = (struct opvar *) if_list[--n_if_list]; - set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); - } else lc_error("IF: Huh?! No end address?"); - } + if (n_if_list > 0) { + struct opvar *tmppush; + tmppush = (struct opvar *) if_list[--n_if_list]; + set_opvar_int(tmppush, splev->n_opcodes - tmppush->vardata.l); + } else + lc_error("IF: Huh?! No end address?"); + } #line 3494 "y.tab.c" /* yacc.c:1646 */ break; - case 161: + case 161: #line 1166 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MESSAGE)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MESSAGE)); + } #line 3502 "y.tab.c" /* yacc.c:1646 */ break; - case 162: + case 162: #line 1172 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiio", - VA_PASS7(-1, 0, -1, -1, -1, -1, SPO_CORRIDOR)); - } + add_opvars(splev, "iiiiiio", + VA_PASS7(-1, 0, -1, -1, -1, -1, SPO_CORRIDOR)); + } #line 3511 "y.tab.c" /* yacc.c:1646 */ break; - case 163: + case 163: #line 1177 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiio", - VA_PASS7(-1, (yyvsp[0].i), -1, -1, -1, -1, SPO_CORRIDOR)); - } + add_opvars(splev, "iiiiiio", + VA_PASS7(-1, (yyvsp[0].i), -1, -1, -1, -1, SPO_CORRIDOR)); + } #line 3520 "y.tab.c" /* yacc.c:1646 */ break; - case 164: + case 164: #line 1182 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiio", - VA_PASS7(-1, -1, -1, -1, -1, -1, SPO_CORRIDOR)); - } + add_opvars(splev, "iiiiiio", + VA_PASS7(-1, -1, -1, -1, -1, -1, SPO_CORRIDOR)); + } #line 3529 "y.tab.c" /* yacc.c:1646 */ break; - case 165: + case 165: #line 1189 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiio", - VA_PASS7((yyvsp[-2].corpos).room, (yyvsp[-2].corpos).door, (yyvsp[-2].corpos).wall, - (yyvsp[0].corpos).room, (yyvsp[0].corpos).door, (yyvsp[0].corpos).wall, - SPO_CORRIDOR)); - } + add_opvars(splev, "iiiiiio", + VA_PASS7((yyvsp[-2].corpos).room, (yyvsp[-2].corpos).door, + (yyvsp[-2].corpos).wall, (yyvsp[0].corpos).room, + (yyvsp[0].corpos).door, (yyvsp[0].corpos).wall, + SPO_CORRIDOR)); + } #line 3540 "y.tab.c" /* yacc.c:1646 */ break; - case 166: + case 166: #line 1196 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiiiio", - VA_PASS7((yyvsp[-2].corpos).room, (yyvsp[-2].corpos).door, (yyvsp[-2].corpos).wall, - -1, -1, (long)(yyvsp[0].i), - SPO_CORRIDOR)); - } + add_opvars(splev, "iiiiiio", + VA_PASS7((yyvsp[-2].corpos).room, (yyvsp[-2].corpos).door, + (yyvsp[-2].corpos).wall, -1, -1, + (long) (yyvsp[0].i), SPO_CORRIDOR)); + } #line 3551 "y.tab.c" /* yacc.c:1646 */ break; - case 167: + case 167: #line 1205 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.corpos).room = (yyvsp[-5].i); - (yyval.corpos).wall = (yyvsp[-3].i); - (yyval.corpos).door = (yyvsp[-1].i); - } + (yyval.corpos).room = (yyvsp[-5].i); + (yyval.corpos).wall = (yyvsp[-3].i); + (yyval.corpos).door = (yyvsp[-1].i); + } #line 3561 "y.tab.c" /* yacc.c:1646 */ break; - case 168: + case 168: #line 1213 "lev_comp.y" /* yacc.c:1646 */ { - if (((yyvsp[-2].i) < 100) && ((yyvsp[-3].i) == OROOM)) - lc_error("Only typed rooms can have a chance."); - else { - add_opvars(splev, "iii", - VA_PASS3((long)(yyvsp[-3].i), (long)(yyvsp[-2].i), (long)(yyvsp[0].i))); - } - } + if (((yyvsp[-2].i) < 100) && ((yyvsp[-3].i) == OROOM)) + lc_error("Only typed rooms can have a chance."); + else { + add_opvars(splev, "iii", + VA_PASS3((long) (yyvsp[-3].i), (long) (yyvsp[-2].i), + (long) (yyvsp[0].i))); + } + } #line 3574 "y.tab.c" /* yacc.c:1646 */ break; - case 169: + case 169: #line 1224 "lev_comp.y" /* yacc.c:1646 */ { - long rflags = (yyvsp[0].i); + long rflags = (yyvsp[0].i); - if (rflags == -1) rflags = (1 << 0); - add_opvars(splev, "iiiiiiio", - VA_PASS8(rflags, ERR, ERR, - (yyvsp[-3].crd).x, (yyvsp[-3].crd).y, (yyvsp[-1].sze).width, (yyvsp[-1].sze).height, - SPO_SUBROOM)); - break_stmt_start(); - } + if (rflags == -1) + rflags = (1 << 0); + add_opvars(splev, "iiiiiiio", + VA_PASS8(rflags, ERR, ERR, (yyvsp[-3].crd).x, + (yyvsp[-3].crd).y, (yyvsp[-1].sze).width, + (yyvsp[-1].sze).height, SPO_SUBROOM)); + break_stmt_start(); + } #line 3589 "y.tab.c" /* yacc.c:1646 */ break; - case 170: + case 170: #line 1235 "lev_comp.y" /* yacc.c:1646 */ { - break_stmt_end(splev); - add_opcode(splev, SPO_ENDROOM, NULL); - } + break_stmt_end(splev); + add_opcode(splev, SPO_ENDROOM, NULL); + } #line 3598 "y.tab.c" /* yacc.c:1646 */ break; - case 171: + case 171: #line 1242 "lev_comp.y" /* yacc.c:1646 */ { - long rflags = (yyvsp[-2].i); + long rflags = (yyvsp[-2].i); - if (rflags == -1) rflags = (1 << 0); - add_opvars(splev, "iiiiiiio", - VA_PASS8(rflags, - (yyvsp[-3].crd).x, (yyvsp[-3].crd).y, (yyvsp[-5].crd).x, (yyvsp[-5].crd).y, - (yyvsp[-1].sze).width, (yyvsp[-1].sze).height, SPO_ROOM)); - break_stmt_start(); - } + if (rflags == -1) + rflags = (1 << 0); + add_opvars(splev, "iiiiiiio", + VA_PASS8(rflags, (yyvsp[-3].crd).x, (yyvsp[-3].crd).y, + (yyvsp[-5].crd).x, (yyvsp[-5].crd).y, + (yyvsp[-1].sze).width, (yyvsp[-1].sze).height, + SPO_ROOM)); + break_stmt_start(); + } #line 3613 "y.tab.c" /* yacc.c:1646 */ break; - case 172: + case 172: #line 1253 "lev_comp.y" /* yacc.c:1646 */ { - break_stmt_end(splev); - add_opcode(splev, SPO_ENDROOM, NULL); - } + break_stmt_end(splev); + add_opcode(splev, SPO_ENDROOM, NULL); + } #line 3622 "y.tab.c" /* yacc.c:1646 */ break; - case 173: + case 173: #line 1260 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 1; - } + (yyval.i) = 1; + } #line 3630 "y.tab.c" /* yacc.c:1646 */ break; - case 174: + case 174: #line 1264 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 3638 "y.tab.c" /* yacc.c:1646 */ break; - case 175: + case 175: #line 1270 "lev_comp.y" /* yacc.c:1646 */ { - if ( (yyvsp[-3].i) < 1 || (yyvsp[-3].i) > 5 || - (yyvsp[-1].i) < 1 || (yyvsp[-1].i) > 5 ) { - lc_error("Room positions should be between 1-5: (%li,%li)!", (yyvsp[-3].i), (yyvsp[-1].i)); - } else { - (yyval.crd).x = (yyvsp[-3].i); - (yyval.crd).y = (yyvsp[-1].i); - } - } + if ((yyvsp[-3].i) < 1 || (yyvsp[-3].i) > 5 || (yyvsp[-1].i) < 1 + || (yyvsp[-1].i) > 5) { + lc_error("Room positions should be between 1-5: (%li,%li)!", + (yyvsp[-3].i), (yyvsp[-1].i)); + } else { + (yyval.crd).x = (yyvsp[-3].i); + (yyval.crd).y = (yyvsp[-1].i); + } + } #line 3652 "y.tab.c" /* yacc.c:1646 */ break; - case 176: + case 176: #line 1280 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.crd).x = (yyval.crd).y = ERR; - } + (yyval.crd).x = (yyval.crd).y = ERR; + } #line 3660 "y.tab.c" /* yacc.c:1646 */ break; - case 177: + case 177: #line 1286 "lev_comp.y" /* yacc.c:1646 */ { - if ( (yyvsp[-3].i) < 0 || (yyvsp[-1].i) < 0) { - lc_error("Invalid subroom position (%li,%li)!", (yyvsp[-3].i), (yyvsp[-1].i)); - } else { - (yyval.crd).x = (yyvsp[-3].i); - (yyval.crd).y = (yyvsp[-1].i); - } - } + if ((yyvsp[-3].i) < 0 || (yyvsp[-1].i) < 0) { + lc_error("Invalid subroom position (%li,%li)!", (yyvsp[-3].i), + (yyvsp[-1].i)); + } else { + (yyval.crd).x = (yyvsp[-3].i); + (yyval.crd).y = (yyvsp[-1].i); + } + } #line 3673 "y.tab.c" /* yacc.c:1646 */ break; - case 178: + case 178: #line 1295 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.crd).x = (yyval.crd).y = ERR; - } + (yyval.crd).x = (yyval.crd).y = ERR; + } #line 3681 "y.tab.c" /* yacc.c:1646 */ break; - case 179: + case 179: #line 1301 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.crd).x = (yyvsp[-3].i); - (yyval.crd).y = (yyvsp[-1].i); - } + (yyval.crd).x = (yyvsp[-3].i); + (yyval.crd).y = (yyvsp[-1].i); + } #line 3690 "y.tab.c" /* yacc.c:1646 */ break; - case 180: + case 180: #line 1306 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.crd).x = (yyval.crd).y = ERR; - } + (yyval.crd).x = (yyval.crd).y = ERR; + } #line 3698 "y.tab.c" /* yacc.c:1646 */ break; - case 181: + case 181: #line 1312 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.sze).width = (yyvsp[-3].i); - (yyval.sze).height = (yyvsp[-1].i); - } + (yyval.sze).width = (yyvsp[-3].i); + (yyval.sze).height = (yyvsp[-1].i); + } #line 3707 "y.tab.c" /* yacc.c:1646 */ break; - case 182: + case 182: #line 1317 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.sze).height = (yyval.sze).width = ERR; - } + (yyval.sze).height = (yyval.sze).width = ERR; + } #line 3715 "y.tab.c" /* yacc.c:1646 */ break; - case 183: + case 183: #line 1323 "lev_comp.y" /* yacc.c:1646 */ { - /* ERR means random here */ - if ((yyvsp[-2].i) == ERR && (yyvsp[0].i) != ERR) { - lc_error("If the door wall is random, so must be its pos!"); - } else { - add_opvars(splev, "iiiio", - VA_PASS5((long)(yyvsp[0].i), (long)(yyvsp[-4].i), (long)(yyvsp[-6].i), - (long)(yyvsp[-2].i), SPO_ROOM_DOOR)); - } - } + /* ERR means random here */ + if ((yyvsp[-2].i) == ERR && (yyvsp[0].i) != ERR) { + lc_error("If the door wall is random, so must be its pos!"); + } else { + add_opvars(splev, "iiiio", + VA_PASS5((long) (yyvsp[0].i), (long) (yyvsp[-4].i), + (long) (yyvsp[-6].i), (long) (yyvsp[-2].i), + SPO_ROOM_DOOR)); + } + } #line 3730 "y.tab.c" /* yacc.c:1646 */ break; - case 184: + case 184: #line 1334 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2((long)(yyvsp[-2].i), SPO_DOOR)); - } + add_opvars(splev, "io", VA_PASS2((long) (yyvsp[-2].i), SPO_DOOR)); + } #line 3738 "y.tab.c" /* yacc.c:1646 */ break; - case 189: + case 189: #line 1348 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 3746 "y.tab.c" /* yacc.c:1646 */ break; - case 190: + case 190: #line 1352 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); - } + (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); + } #line 3754 "y.tab.c" /* yacc.c:1646 */ break; - case 193: + case 193: #line 1362 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ciisiio", - VA_PASS7(0, 0, 1, (char *)0, 0, 0, SPO_MAP)); - max_x_map = COLNO-1; - max_y_map = ROWNO; - } + add_opvars(splev, "ciisiio", + VA_PASS7(0, 0, 1, (char *) 0, 0, 0, SPO_MAP)); + max_x_map = COLNO - 1; + max_y_map = ROWNO; + } #line 3765 "y.tab.c" /* yacc.c:1646 */ break; - case 194: + case 194: #line 1369 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "cii", - VA_PASS3(SP_COORD_PACK(((yyvsp[-4].i)),((yyvsp[-2].i))), - 1, (long)(yyvsp[-1].i))); - scan_map((yyvsp[0].map), splev); - Free((yyvsp[0].map)); - } + add_opvars(splev, "cii", + VA_PASS3(SP_COORD_PACK(((yyvsp[-4].i)), ((yyvsp[-2].i))), + 1, (long) (yyvsp[-1].i))); + scan_map((yyvsp[0].map), splev); + Free((yyvsp[0].map)); + } #line 3777 "y.tab.c" /* yacc.c:1646 */ break; - case 195: + case 195: #line 1377 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(2, (long)(yyvsp[-1].i))); - scan_map((yyvsp[0].map), splev); - Free((yyvsp[0].map)); - } + add_opvars(splev, "ii", VA_PASS2(2, (long) (yyvsp[-1].i))); + scan_map((yyvsp[0].map), splev); + Free((yyvsp[0].map)); + } #line 3787 "y.tab.c" /* yacc.c:1646 */ break; - case 200: + case 200: #line 1393 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(0, SPO_MONSTER)); - } + add_opvars(splev, "io", VA_PASS2(0, SPO_MONSTER)); + } #line 3795 "y.tab.c" /* yacc.c:1646 */ break; - case 201: + case 201: #line 1397 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(1, SPO_MONSTER)); - in_container_obj++; - break_stmt_start(); - } + add_opvars(splev, "io", VA_PASS2(1, SPO_MONSTER)); + in_container_obj++; + break_stmt_start(); + } #line 3805 "y.tab.c" /* yacc.c:1646 */ break; - case 202: + case 202: #line 1403 "lev_comp.y" /* yacc.c:1646 */ { - break_stmt_end(splev); - in_container_obj--; - add_opvars(splev, "o", VA_PASS1(SPO_END_MONINVENT)); - } + break_stmt_end(splev); + in_container_obj--; + add_opvars(splev, "o", VA_PASS1(SPO_END_MONINVENT)); + } #line 3815 "y.tab.c" /* yacc.c:1646 */ break; - case 203: + case 203: #line 1411 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 3823 "y.tab.c" /* yacc.c:1646 */ break; - case 204: + case 204: #line 1417 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *stopit = New(struct opvar); - set_opvar_int(stopit, SP_M_V_END); - add_opcode(splev, SPO_PUSH, stopit); - (yyval.i) = 0x0000; - } + struct opvar *stopit = New(struct opvar); + set_opvar_int(stopit, SP_M_V_END); + add_opcode(splev, SPO_PUSH, stopit); + (yyval.i) = 0x0000; + } #line 3834 "y.tab.c" /* yacc.c:1646 */ break; - case 205: + case 205: #line 1424 "lev_comp.y" /* yacc.c:1646 */ { - if (( (yyvsp[-2].i) & (yyvsp[0].i) )) - lc_error("MONSTER extra info defined twice."); - (yyval.i) = ( (yyvsp[-2].i) | (yyvsp[0].i) ); - } + if (((yyvsp[-2].i) & (yyvsp[0].i))) + lc_error("MONSTER extra info defined twice."); + (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); + } #line 3844 "y.tab.c" /* yacc.c:1646 */ break; - case 206: + case 206: #line 1432 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_M_V_NAME)); - (yyval.i) = 0x0001; - } + add_opvars(splev, "i", VA_PASS1(SP_M_V_NAME)); + (yyval.i) = 0x0001; + } #line 3853 "y.tab.c" /* yacc.c:1646 */ break; - case 207: + case 207: #line 1437 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[0].i), SP_M_V_PEACEFUL)); - (yyval.i) = 0x0002; - } + add_opvars(splev, "ii", + VA_PASS2((long) (yyvsp[0].i), SP_M_V_PEACEFUL)); + (yyval.i) = 0x0002; + } #line 3863 "y.tab.c" /* yacc.c:1646 */ break; - case 208: + case 208: #line 1443 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[0].i), SP_M_V_ASLEEP)); - (yyval.i) = 0x0004; - } + add_opvars(splev, "ii", VA_PASS2((long) (yyvsp[0].i), SP_M_V_ASLEEP)); + (yyval.i) = 0x0004; + } #line 3873 "y.tab.c" /* yacc.c:1646 */ break; - case 209: + case 209: #line 1449 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[0].i), SP_M_V_ALIGN)); - (yyval.i) = 0x0008; - } + add_opvars(splev, "ii", VA_PASS2((long) (yyvsp[0].i), SP_M_V_ALIGN)); + (yyval.i) = 0x0008; + } #line 3883 "y.tab.c" /* yacc.c:1646 */ break; - case 210: + case 210: #line 1455 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[-1].i), SP_M_V_APPEAR)); - (yyval.i) = 0x0010; - } + add_opvars(splev, "ii", + VA_PASS2((long) (yyvsp[-1].i), SP_M_V_APPEAR)); + (yyval.i) = 0x0010; + } #line 3893 "y.tab.c" /* yacc.c:1646 */ break; - case 211: + case 211: #line 1461 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_FEMALE)); - (yyval.i) = 0x0020; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_FEMALE)); + (yyval.i) = 0x0020; + } #line 3902 "y.tab.c" /* yacc.c:1646 */ break; - case 212: + case 212: #line 1466 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_INVIS)); - (yyval.i) = 0x0040; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_INVIS)); + (yyval.i) = 0x0040; + } #line 3911 "y.tab.c" /* yacc.c:1646 */ break; - case 213: + case 213: #line 1471 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_CANCELLED)); - (yyval.i) = 0x0080; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_CANCELLED)); + (yyval.i) = 0x0080; + } #line 3920 "y.tab.c" /* yacc.c:1646 */ break; - case 214: + case 214: #line 1476 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_REVIVED)); - (yyval.i) = 0x0100; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_REVIVED)); + (yyval.i) = 0x0100; + } #line 3929 "y.tab.c" /* yacc.c:1646 */ break; - case 215: + case 215: #line 1481 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_AVENGE)); - (yyval.i) = 0x0200; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_AVENGE)); + (yyval.i) = 0x0200; + } #line 3938 "y.tab.c" /* yacc.c:1646 */ break; - case 216: + case 216: #line 1486 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_M_V_FLEEING)); - (yyval.i) = 0x0400; - } + add_opvars(splev, "i", VA_PASS1(SP_M_V_FLEEING)); + (yyval.i) = 0x0400; + } #line 3947 "y.tab.c" /* yacc.c:1646 */ break; - case 217: + case 217: #line 1491 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_M_V_BLINDED)); - (yyval.i) = 0x0800; - } + add_opvars(splev, "i", VA_PASS1(SP_M_V_BLINDED)); + (yyval.i) = 0x0800; + } #line 3956 "y.tab.c" /* yacc.c:1646 */ break; - case 218: + case 218: #line 1496 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_M_V_PARALYZED)); - (yyval.i) = 0x1000; - } + add_opvars(splev, "i", VA_PASS1(SP_M_V_PARALYZED)); + (yyval.i) = 0x1000; + } #line 3965 "y.tab.c" /* yacc.c:1646 */ break; - case 219: + case 219: #line 1501 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_STUNNED)); - (yyval.i) = 0x2000; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_STUNNED)); + (yyval.i) = 0x2000; + } #line 3974 "y.tab.c" /* yacc.c:1646 */ break; - case 220: + case 220: #line 1506 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_CONFUSED)); - (yyval.i) = 0x4000; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_M_V_CONFUSED)); + (yyval.i) = 0x4000; + } #line 3983 "y.tab.c" /* yacc.c:1646 */ break; - case 221: + case 221: #line 1511 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[0].i), SP_M_V_SEENTRAPS)); - (yyval.i) = 0x8000; - } + add_opvars(splev, "ii", + VA_PASS2((long) (yyvsp[0].i), SP_M_V_SEENTRAPS)); + (yyval.i) = 0x8000; + } #line 3993 "y.tab.c" /* yacc.c:1646 */ break; - case 222: + case 222: #line 1519 "lev_comp.y" /* yacc.c:1646 */ { - int token = get_trap_type((yyvsp[0].map)); - if (token == ERR || token == 0) - lc_error("Unknown trap type '%s'!", (yyvsp[0].map)); - (yyval.i) = (1L << (token - 1)); - } + int token = get_trap_type((yyvsp[0].map)); + if (token == ERR || token == 0) + lc_error("Unknown trap type '%s'!", (yyvsp[0].map)); + (yyval.i) = (1L << (token - 1)); + } #line 4004 "y.tab.c" /* yacc.c:1646 */ break; - case 223: + case 223: #line 1526 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (long) ~0; - } + (yyval.i) = (long) ~0; + } #line 4012 "y.tab.c" /* yacc.c:1646 */ break; - case 224: + case 224: #line 1530 "lev_comp.y" /* yacc.c:1646 */ { - int token = get_trap_type((yyvsp[-2].map)); - if (token == ERR || token == 0) - lc_error("Unknown trap type '%s'!", (yyvsp[-2].map)); + int token = get_trap_type((yyvsp[-2].map)); + if (token == ERR || token == 0) + lc_error("Unknown trap type '%s'!", (yyvsp[-2].map)); - if ((1L << (token - 1)) & (yyvsp[0].i)) - lc_error("Monster seen_traps, trap '%s' listed twice.", (yyvsp[-2].map)); + if ((1L << (token - 1)) & (yyvsp[0].i)) + lc_error("Monster seen_traps, trap '%s' listed twice.", + (yyvsp[-2].map)); - (yyval.i) = ((1L << (token - 1)) | (yyvsp[0].i)); - } + (yyval.i) = ((1L << (token - 1)) | (yyvsp[0].i)); + } #line 4027 "y.tab.c" /* yacc.c:1646 */ break; - case 225: + case 225: #line 1543 "lev_comp.y" /* yacc.c:1646 */ { - long cnt = 0; - if (in_container_obj) cnt |= SP_OBJ_CONTENT; - add_opvars(splev, "io", VA_PASS2(cnt, SPO_OBJECT)); - } + long cnt = 0; + if (in_container_obj) + cnt |= SP_OBJ_CONTENT; + add_opvars(splev, "io", VA_PASS2(cnt, SPO_OBJECT)); + } #line 4037 "y.tab.c" /* yacc.c:1646 */ break; - case 226: + case 226: #line 1549 "lev_comp.y" /* yacc.c:1646 */ { - long cnt = SP_OBJ_CONTAINER; - if (in_container_obj) cnt |= SP_OBJ_CONTENT; - add_opvars(splev, "io", VA_PASS2(cnt, SPO_OBJECT)); - in_container_obj++; - break_stmt_start(); - } + long cnt = SP_OBJ_CONTAINER; + if (in_container_obj) + cnt |= SP_OBJ_CONTENT; + add_opvars(splev, "io", VA_PASS2(cnt, SPO_OBJECT)); + in_container_obj++; + break_stmt_start(); + } #line 4049 "y.tab.c" /* yacc.c:1646 */ break; - case 227: + case 227: #line 1557 "lev_comp.y" /* yacc.c:1646 */ { - break_stmt_end(splev); - in_container_obj--; - add_opcode(splev, SPO_POP_CONTAINER, NULL); - } + break_stmt_end(splev); + in_container_obj--; + add_opcode(splev, SPO_POP_CONTAINER, NULL); + } #line 4059 "y.tab.c" /* yacc.c:1646 */ break; - case 228: + case 228: #line 1565 "lev_comp.y" /* yacc.c:1646 */ { - if (( (yyvsp[0].i) & 0x4000) && in_container_obj) lc_error("Object cannot have a coord when contained."); - else if (!( (yyvsp[0].i) & 0x4000) && !in_container_obj) lc_error("Object needs a coord when not contained."); - } + if (((yyvsp[0].i) & 0x4000) && in_container_obj) + lc_error("Object cannot have a coord when contained."); + else if (!((yyvsp[0].i) & 0x4000) && !in_container_obj) + lc_error("Object needs a coord when not contained."); + } #line 4068 "y.tab.c" /* yacc.c:1646 */ break; - case 229: + case 229: #line 1572 "lev_comp.y" /* yacc.c:1646 */ { - struct opvar *stopit = New(struct opvar); - set_opvar_int(stopit, SP_O_V_END); - add_opcode(splev, SPO_PUSH, stopit); - (yyval.i) = 0x00; - } + struct opvar *stopit = New(struct opvar); + set_opvar_int(stopit, SP_O_V_END); + add_opcode(splev, SPO_PUSH, stopit); + (yyval.i) = 0x00; + } #line 4079 "y.tab.c" /* yacc.c:1646 */ break; - case 230: + case 230: #line 1579 "lev_comp.y" /* yacc.c:1646 */ { - if (( (yyvsp[-2].i) & (yyvsp[0].i) )) - lc_error("OBJECT extra info '%s' defined twice.", curr_token); - (yyval.i) = ( (yyvsp[-2].i) | (yyvsp[0].i) ); - } + if (((yyvsp[-2].i) & (yyvsp[0].i))) + lc_error("OBJECT extra info '%s' defined twice.", curr_token); + (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); + } #line 4089 "y.tab.c" /* yacc.c:1646 */ break; - case 231: + case 231: #line 1587 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", - VA_PASS2((long)(yyvsp[0].i), SP_O_V_CURSE)); - (yyval.i) = 0x0001; - } + add_opvars(splev, "ii", VA_PASS2((long) (yyvsp[0].i), SP_O_V_CURSE)); + (yyval.i) = 0x0001; + } #line 4099 "y.tab.c" /* yacc.c:1646 */ break; - case 232: + case 232: #line 1593 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_CORPSENM)); - (yyval.i) = 0x0002; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_CORPSENM)); + (yyval.i) = 0x0002; + } #line 4108 "y.tab.c" /* yacc.c:1646 */ break; - case 233: + case 233: #line 1598 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_SPE)); - (yyval.i) = 0x0004; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_SPE)); + (yyval.i) = 0x0004; + } #line 4117 "y.tab.c" /* yacc.c:1646 */ break; - case 234: + case 234: #line 1603 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_NAME)); - (yyval.i) = 0x0008; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_NAME)); + (yyval.i) = 0x0008; + } #line 4126 "y.tab.c" /* yacc.c:1646 */ break; - case 235: + case 235: #line 1608 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_QUAN)); - (yyval.i) = 0x0010; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_QUAN)); + (yyval.i) = 0x0010; + } #line 4135 "y.tab.c" /* yacc.c:1646 */ break; - case 236: + case 236: #line 1613 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_BURIED)); - (yyval.i) = 0x0020; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_BURIED)); + (yyval.i) = 0x0020; + } #line 4144 "y.tab.c" /* yacc.c:1646 */ break; - case 237: + case 237: #line 1618 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2((long)(yyvsp[0].i), SP_O_V_LIT)); - (yyval.i) = 0x0040; - } + add_opvars(splev, "ii", VA_PASS2((long) (yyvsp[0].i), SP_O_V_LIT)); + (yyval.i) = 0x0040; + } #line 4153 "y.tab.c" /* yacc.c:1646 */ break; - case 238: + case 238: #line 1623 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_ERODED)); - (yyval.i) = 0x0080; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_ERODED)); + (yyval.i) = 0x0080; + } #line 4162 "y.tab.c" /* yacc.c:1646 */ break; - case 239: + case 239: #line 1628 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(-1, SP_O_V_ERODED)); - (yyval.i) = 0x0080; - } + add_opvars(splev, "ii", VA_PASS2(-1, SP_O_V_ERODED)); + (yyval.i) = 0x0080; + } #line 4171 "y.tab.c" /* yacc.c:1646 */ break; - case 240: + case 240: #line 1633 "lev_comp.y" /* yacc.c:1646 */ { - if ((yyvsp[0].i) == D_LOCKED) { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_LOCKED)); - (yyval.i) = 0x0100; - } else if ((yyvsp[0].i) == D_BROKEN) { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_BROKEN)); - (yyval.i) = 0x0200; - } else - lc_error("DOOR state can only be locked or broken."); - } + if ((yyvsp[0].i) == D_LOCKED) { + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_LOCKED)); + (yyval.i) = 0x0100; + } else if ((yyvsp[0].i) == D_BROKEN) { + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_BROKEN)); + (yyval.i) = 0x0200; + } else + lc_error("DOOR state can only be locked or broken."); + } #line 4186 "y.tab.c" /* yacc.c:1646 */ break; - case 241: + case 241: #line 1644 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_TRAPPED)); - (yyval.i) = 0x0400; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_TRAPPED)); + (yyval.i) = 0x0400; + } #line 4195 "y.tab.c" /* yacc.c:1646 */ break; - case 242: + case 242: #line 1649 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_RECHARGED)); - (yyval.i) = 0x0800; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_RECHARGED)); + (yyval.i) = 0x0800; + } #line 4204 "y.tab.c" /* yacc.c:1646 */ break; - case 243: + case 243: #line 1654 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_INVIS)); - (yyval.i) = 0x1000; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_INVIS)); + (yyval.i) = 0x1000; + } #line 4213 "y.tab.c" /* yacc.c:1646 */ break; - case 244: + case 244: #line 1659 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_GREASED)); - (yyval.i) = 0x2000; - } + add_opvars(splev, "ii", VA_PASS2(1, SP_O_V_GREASED)); + (yyval.i) = 0x2000; + } #line 4222 "y.tab.c" /* yacc.c:1646 */ break; - case 245: + case 245: #line 1664 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1(SP_O_V_COORD)); - (yyval.i) = 0x4000; - } + add_opvars(splev, "i", VA_PASS1(SP_O_V_COORD)); + (yyval.i) = 0x4000; + } #line 4231 "y.tab.c" /* yacc.c:1646 */ break; - case 246: + case 246: #line 1671 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2((long)(yyvsp[-2].i), SPO_TRAP)); - } + add_opvars(splev, "io", VA_PASS2((long) (yyvsp[-2].i), SPO_TRAP)); + } #line 4239 "y.tab.c" /* yacc.c:1646 */ break; - case 247: + case 247: #line 1677 "lev_comp.y" /* yacc.c:1646 */ { - long dir, state = 0; + long dir, state = 0; - /* convert dir from a DIRECTION to a DB_DIR */ - dir = (yyvsp[-2].i); - switch (dir) { - case W_NORTH: dir = DB_NORTH; break; - case W_SOUTH: dir = DB_SOUTH; break; - case W_EAST: dir = DB_EAST; break; - case W_WEST: dir = DB_WEST; break; - default: - lc_error("Invalid drawbridge direction."); - break; - } + /* convert dir from a DIRECTION to a DB_DIR */ + dir = (yyvsp[-2].i); + switch (dir) { + case W_NORTH: + dir = DB_NORTH; + break; + case W_SOUTH: + dir = DB_SOUTH; + break; + case W_EAST: + dir = DB_EAST; + break; + case W_WEST: + dir = DB_WEST; + break; + default: + lc_error("Invalid drawbridge direction."); + break; + } - if ( (yyvsp[0].i) == D_ISOPEN ) - state = 1; - else if ( (yyvsp[0].i) == D_CLOSED ) - state = 0; - else if ( (yyvsp[0].i) == -1 ) - state = -1; - else - lc_error("A drawbridge can only be open, closed or random!"); - add_opvars(splev, "iio", - VA_PASS3(state, dir, SPO_DRAWBRIDGE)); - } + if ((yyvsp[0].i) == D_ISOPEN) + state = 1; + else if ((yyvsp[0].i) == D_CLOSED) + state = 0; + else if ((yyvsp[0].i) == -1) + state = -1; + else + lc_error("A drawbridge can only be open, closed or random!"); + add_opvars(splev, "iio", VA_PASS3(state, dir, SPO_DRAWBRIDGE)); + } #line 4270 "y.tab.c" /* yacc.c:1646 */ break; - case 248: + case 248: #line 1706 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiio", - VA_PASS4((long)(yyvsp[0].i), 1, 0, SPO_MAZEWALK)); - } + add_opvars(splev, "iiio", + VA_PASS4((long) (yyvsp[0].i), 1, 0, SPO_MAZEWALK)); + } #line 4279 "y.tab.c" /* yacc.c:1646 */ break; - case 249: + case 249: #line 1711 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiio", - VA_PASS4((long)(yyvsp[-3].i), (long)(yyvsp[-1].i), - (long)(yyvsp[0].i), SPO_MAZEWALK)); - } + add_opvars(splev, "iiio", + VA_PASS4((long) (yyvsp[-3].i), (long) (yyvsp[-1].i), + (long) (yyvsp[0].i), SPO_MAZEWALK)); + } #line 4289 "y.tab.c" /* yacc.c:1646 */ break; - case 250: + case 250: #line 1719 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "rio", - VA_PASS3(SP_REGION_PACK(-1,-1,-1,-1), - 0, SPO_WALLIFY)); - } + add_opvars(splev, "rio", + VA_PASS3(SP_REGION_PACK(-1, -1, -1, -1), 0, SPO_WALLIFY)); + } #line 4299 "y.tab.c" /* yacc.c:1646 */ break; - case 251: + case 251: #line 1725 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(1, SPO_WALLIFY)); - } + add_opvars(splev, "io", VA_PASS2(1, SPO_WALLIFY)); + } #line 4307 "y.tab.c" /* yacc.c:1646 */ break; - case 252: + case 252: #line 1731 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2((long)(yyvsp[0].i), SPO_LADDER)); - } + add_opvars(splev, "io", VA_PASS2((long) (yyvsp[0].i), SPO_LADDER)); + } #line 4316 "y.tab.c" /* yacc.c:1646 */ break; - case 253: + case 253: #line 1738 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2((long)(yyvsp[0].i), SPO_STAIR)); - } + add_opvars(splev, "io", VA_PASS2((long) (yyvsp[0].i), SPO_STAIR)); + } #line 4325 "y.tab.c" /* yacc.c:1646 */ break; - case 254: + case 254: #line 1745 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiii iiiii iiso", - VA_PASS14((yyvsp[-4].lregn).x1, (yyvsp[-4].lregn).y1, (yyvsp[-4].lregn).x2, (yyvsp[-4].lregn).y2, (yyvsp[-4].lregn).area, - (yyvsp[-2].lregn).x1, (yyvsp[-2].lregn).y1, (yyvsp[-2].lregn).x2, (yyvsp[-2].lregn).y2, (yyvsp[-2].lregn).area, - (long)(((yyvsp[0].i)) ? LR_UPSTAIR : LR_DOWNSTAIR), - 0, (char *)0, SPO_LEVREGION)); - } + add_opvars( + splev, "iiiii iiiii iiso", + VA_PASS14((yyvsp[-4].lregn).x1, (yyvsp[-4].lregn).y1, + (yyvsp[-4].lregn).x2, (yyvsp[-4].lregn).y2, + (yyvsp[-4].lregn).area, (yyvsp[-2].lregn).x1, + (yyvsp[-2].lregn).y1, (yyvsp[-2].lregn).x2, + (yyvsp[-2].lregn).y2, (yyvsp[-2].lregn).area, + (long) (((yyvsp[0].i)) ? LR_UPSTAIR : LR_DOWNSTAIR), 0, + (char *) 0, SPO_LEVREGION)); + } #line 4337 "y.tab.c" /* yacc.c:1646 */ break; - case 255: + case 255: #line 1755 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiii iiiii iiso", - VA_PASS14((yyvsp[-4].lregn).x1, (yyvsp[-4].lregn).y1, (yyvsp[-4].lregn).x2, (yyvsp[-4].lregn).y2, (yyvsp[-4].lregn).area, - (yyvsp[-2].lregn).x1, (yyvsp[-2].lregn).y1, (yyvsp[-2].lregn).x2, (yyvsp[-2].lregn).y2, (yyvsp[-2].lregn).area, - LR_PORTAL, 0, (yyvsp[0].map), SPO_LEVREGION)); - Free((yyvsp[0].map)); - } + add_opvars(splev, "iiiii iiiii iiso", + VA_PASS14((yyvsp[-4].lregn).x1, (yyvsp[-4].lregn).y1, + (yyvsp[-4].lregn).x2, (yyvsp[-4].lregn).y2, + (yyvsp[-4].lregn).area, (yyvsp[-2].lregn).x1, + (yyvsp[-2].lregn).y1, (yyvsp[-2].lregn).x2, + (yyvsp[-2].lregn).y2, (yyvsp[-2].lregn).area, + LR_PORTAL, 0, (yyvsp[0].map), SPO_LEVREGION)); + Free((yyvsp[0].map)); + } #line 4349 "y.tab.c" /* yacc.c:1646 */ break; - case 256: + case 256: #line 1765 "lev_comp.y" /* yacc.c:1646 */ { - long rtyp = 0; - switch((yyvsp[0].i)) { - case -1: rtyp = LR_TELE; break; - case 0: rtyp = LR_DOWNTELE; break; - case 1: rtyp = LR_UPTELE; break; - } - add_opvars(splev, "iiiii iiiii iiso", - VA_PASS14((yyvsp[-3].lregn).x1, (yyvsp[-3].lregn).y1, (yyvsp[-3].lregn).x2, (yyvsp[-3].lregn).y2, (yyvsp[-3].lregn).area, - (yyvsp[-1].lregn).x1, (yyvsp[-1].lregn).y1, (yyvsp[-1].lregn).x2, (yyvsp[-1].lregn).y2, (yyvsp[-1].lregn).area, - rtyp, 0, (char *)0, SPO_LEVREGION)); - } + long rtyp = 0; + switch ((yyvsp[0].i)) { + case -1: + rtyp = LR_TELE; + break; + case 0: + rtyp = LR_DOWNTELE; + break; + case 1: + rtyp = LR_UPTELE; + break; + } + add_opvars(splev, "iiiii iiiii iiso", + VA_PASS14((yyvsp[-3].lregn).x1, (yyvsp[-3].lregn).y1, + (yyvsp[-3].lregn).x2, (yyvsp[-3].lregn).y2, + (yyvsp[-3].lregn).area, (yyvsp[-1].lregn).x1, + (yyvsp[-1].lregn).y1, (yyvsp[-1].lregn).x2, + (yyvsp[-1].lregn).y2, (yyvsp[-1].lregn).area, + rtyp, 0, (char *) 0, SPO_LEVREGION)); + } #line 4366 "y.tab.c" /* yacc.c:1646 */ break; - case 257: + case 257: #line 1780 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiii iiiii iiso", - VA_PASS14((yyvsp[-2].lregn).x1, (yyvsp[-2].lregn).y1, (yyvsp[-2].lregn).x2, (yyvsp[-2].lregn).y2, (yyvsp[-2].lregn).area, - (yyvsp[0].lregn).x1, (yyvsp[0].lregn).y1, (yyvsp[0].lregn).x2, (yyvsp[0].lregn).y2, (yyvsp[0].lregn).area, - (long)LR_BRANCH, 0, - (char *)0, SPO_LEVREGION)); - } + add_opvars(splev, "iiiii iiiii iiso", + VA_PASS14((yyvsp[-2].lregn).x1, (yyvsp[-2].lregn).y1, + (yyvsp[-2].lregn).x2, (yyvsp[-2].lregn).y2, + (yyvsp[-2].lregn).area, (yyvsp[0].lregn).x1, + (yyvsp[0].lregn).y1, (yyvsp[0].lregn).x2, + (yyvsp[0].lregn).y2, (yyvsp[0].lregn).area, + (long) LR_BRANCH, 0, (char *) 0, SPO_LEVREGION)); + } #line 4378 "y.tab.c" /* yacc.c:1646 */ break; - case 258: + case 258: #line 1790 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 4386 "y.tab.c" /* yacc.c:1646 */ break; - case 259: + case 259: #line 1794 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 4394 "y.tab.c" /* yacc.c:1646 */ break; - case 260: + case 260: #line 1800 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_FOUNTAIN)); - } + add_opvars(splev, "o", VA_PASS1(SPO_FOUNTAIN)); + } #line 4402 "y.tab.c" /* yacc.c:1646 */ break; - case 261: + case 261: #line 1806 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SINK)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SINK)); + } #line 4410 "y.tab.c" /* yacc.c:1646 */ break; - case 262: + case 262: #line 1812 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_POOL)); - } + add_opvars(splev, "o", VA_PASS1(SPO_POOL)); + } #line 4418 "y.tab.c" /* yacc.c:1646 */ break; - case 263: + case 263: #line 1818 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.terr).lit = -2; - (yyval.terr).ter = what_map_char((char) (yyvsp[0].i)); - } + (yyval.terr).lit = -2; + (yyval.terr).ter = what_map_char((char) (yyvsp[0].i)); + } #line 4427 "y.tab.c" /* yacc.c:1646 */ break; - case 264: + case 264: #line 1823 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.terr).lit = (yyvsp[-1].i); - (yyval.terr).ter = what_map_char((char) (yyvsp[-3].i)); - } + (yyval.terr).lit = (yyvsp[-1].i); + (yyval.terr).ter = what_map_char((char) (yyvsp[-3].i)); + } #line 4436 "y.tab.c" /* yacc.c:1646 */ break; - case 265: + case 265: #line 1830 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2((yyvsp[0].i), SPO_REPLACETERRAIN)); - } + add_opvars(splev, "io", VA_PASS2((yyvsp[0].i), SPO_REPLACETERRAIN)); + } #line 4445 "y.tab.c" /* yacc.c:1646 */ break; - case 266: + case 266: #line 1837 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_TERRAIN)); - } + add_opvars(splev, "o", VA_PASS1(SPO_TERRAIN)); + } #line 4453 "y.tab.c" /* yacc.c:1646 */ break; - case 267: + case 267: #line 1843 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_NON_DIGGABLE)); - } + add_opvars(splev, "o", VA_PASS1(SPO_NON_DIGGABLE)); + } #line 4461 "y.tab.c" /* yacc.c:1646 */ break; - case 268: + case 268: #line 1849 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_NON_PASSWALL)); - } + add_opvars(splev, "o", VA_PASS1(SPO_NON_PASSWALL)); + } #line 4469 "y.tab.c" /* yacc.c:1646 */ break; - case 269: + case 269: #line 1855 "lev_comp.y" /* yacc.c:1646 */ { - long irr; - long rt = (yyvsp[-1].i); - long rflags = (yyvsp[0].i); + long irr; + long rt = (yyvsp[-1].i); + long rflags = (yyvsp[0].i); - if (rflags == -1) rflags = (1 << 0); - if (!(rflags & 1)) rt += MAXRTYPE+1; - irr = ((rflags & 2) != 0); - add_opvars(splev, "iiio", - VA_PASS4((long)(yyvsp[-3].i), rt, rflags, SPO_REGION)); - (yyval.i) = (irr || (rflags & 1) || rt != OROOM); - break_stmt_start(); - } + if (rflags == -1) + rflags = (1 << 0); + if (!(rflags & 1)) + rt += MAXRTYPE + 1; + irr = ((rflags & 2) != 0); + add_opvars(splev, "iiio", + VA_PASS4((long) (yyvsp[-3].i), rt, rflags, SPO_REGION)); + (yyval.i) = (irr || (rflags & 1) || rt != OROOM); + break_stmt_start(); + } #line 4487 "y.tab.c" /* yacc.c:1646 */ break; - case 270: + case 270: #line 1869 "lev_comp.y" /* yacc.c:1646 */ { - break_stmt_end(splev); - if ( (yyvsp[-1].i) ) { - add_opcode(splev, SPO_ENDROOM, NULL); - } else if ( (yyvsp[0].i) ) - lc_error("Cannot use lev statements in non-permanent REGION"); - } + break_stmt_end(splev); + if ((yyvsp[-1].i)) { + add_opcode(splev, SPO_ENDROOM, NULL); + } else if ((yyvsp[0].i)) + lc_error("Cannot use lev statements in non-permanent REGION"); + } #line 4499 "y.tab.c" /* yacc.c:1646 */ break; - case 271: + case 271: #line 1879 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = 0; - } + (yyval.i) = 0; + } #line 4507 "y.tab.c" /* yacc.c:1646 */ break; - case 272: + case 272: #line 1883 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 4515 "y.tab.c" /* yacc.c:1646 */ break; - case 273: + case 273: #line 1889 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iio", - VA_PASS3((long)(yyvsp[0].i), (long)(yyvsp[-2].i), SPO_ALTAR)); - } + add_opvars(splev, "iio", VA_PASS3((long) (yyvsp[0].i), + (long) (yyvsp[-2].i), SPO_ALTAR)); + } #line 4524 "y.tab.c" /* yacc.c:1646 */ break; - case 274: + case 274: #line 1896 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(2, SPO_GRAVE)); - } + add_opvars(splev, "io", VA_PASS2(2, SPO_GRAVE)); + } #line 4532 "y.tab.c" /* yacc.c:1646 */ break; - case 275: + case 275: #line 1900 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "sio", - VA_PASS3((char *)0, 1, SPO_GRAVE)); - } + add_opvars(splev, "sio", VA_PASS3((char *) 0, 1, SPO_GRAVE)); + } #line 4541 "y.tab.c" /* yacc.c:1646 */ break; - case 276: + case 276: #line 1905 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "sio", - VA_PASS3((char *)0, 0, SPO_GRAVE)); - } + add_opvars(splev, "sio", VA_PASS3((char *) 0, 0, SPO_GRAVE)); + } #line 4550 "y.tab.c" /* yacc.c:1646 */ break; - case 277: + case 277: #line 1912 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_GOLD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_GOLD)); + } #line 4558 "y.tab.c" /* yacc.c:1646 */ break; - case 278: + case 278: #line 1918 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2((long)(yyvsp[-2].i), SPO_ENGRAVING)); - } + add_opvars(splev, "io", + VA_PASS2((long) (yyvsp[-2].i), SPO_ENGRAVING)); + } #line 4567 "y.tab.c" /* yacc.c:1646 */ break; - case 279: + case 279: #line 1925 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MINERALIZE)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MINERALIZE)); + } #line 4575 "y.tab.c" /* yacc.c:1646 */ break; - case 280: + case 280: #line 1929 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iiiio", - VA_PASS5(-1L, -1L, -1L, -1L, SPO_MINERALIZE)); - } + add_opvars(splev, "iiiio", + VA_PASS5(-1L, -1L, -1L, -1L, SPO_MINERALIZE)); + } #line 4584 "y.tab.c" /* yacc.c:1646 */ break; - case 281: + case 281: #line 1936 "lev_comp.y" /* yacc.c:1646 */ { - int token = get_trap_type((yyvsp[0].map)); - if (token == ERR) - lc_error("Unknown trap type '%s'!", (yyvsp[0].map)); - (yyval.i) = token; - Free((yyvsp[0].map)); - } + int token = get_trap_type((yyvsp[0].map)); + if (token == ERR) + lc_error("Unknown trap type '%s'!", (yyvsp[0].map)); + (yyval.i) = token; + Free((yyvsp[0].map)); + } #line 4596 "y.tab.c" /* yacc.c:1646 */ break; - case 283: + case 283: #line 1947 "lev_comp.y" /* yacc.c:1646 */ { - int token = get_room_type((yyvsp[0].map)); - if (token == ERR) { - lc_warning("Unknown room type \"%s\"! Making ordinary room...", (yyvsp[0].map)); - (yyval.i) = OROOM; - } else - (yyval.i) = token; - Free((yyvsp[0].map)); - } + int token = get_room_type((yyvsp[0].map)); + if (token == ERR) { + lc_warning("Unknown room type \"%s\"! Making ordinary room...", + (yyvsp[0].map)); + (yyval.i) = OROOM; + } else + (yyval.i) = token; + Free((yyvsp[0].map)); + } #line 4610 "y.tab.c" /* yacc.c:1646 */ break; - case 285: + case 285: #line 1960 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 4618 "y.tab.c" /* yacc.c:1646 */ break; - case 286: + case 286: #line 1964 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 4626 "y.tab.c" /* yacc.c:1646 */ break; - case 287: + case 287: #line 1970 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 4634 "y.tab.c" /* yacc.c:1646 */ break; - case 288: + case 288: #line 1974 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[-2].i) | (yyvsp[0].i); - } + (yyval.i) = (yyvsp[-2].i) | (yyvsp[0].i); + } #line 4642 "y.tab.c" /* yacc.c:1646 */ break; - case 289: + case 289: #line 1981 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = ((yyvsp[0].i) << 0); - } + (yyval.i) = ((yyvsp[0].i) << 0); + } #line 4650 "y.tab.c" /* yacc.c:1646 */ break; - case 290: + case 290: #line 1985 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = ((yyvsp[0].i) << 1); - } + (yyval.i) = ((yyvsp[0].i) << 1); + } #line 4658 "y.tab.c" /* yacc.c:1646 */ break; - case 291: + case 291: #line 1989 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = ((yyvsp[0].i) << 2); - } + (yyval.i) = ((yyvsp[0].i) << 2); + } #line 4666 "y.tab.c" /* yacc.c:1646 */ break; - case 298: + case 298: #line 2005 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = - MAX_REGISTERS - 1; - } + (yyval.i) = -MAX_REGISTERS - 1; + } #line 4674 "y.tab.c" /* yacc.c:1646 */ break; - case 301: + case 301: #line 2013 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = - MAX_REGISTERS - 1; - } + (yyval.i) = -MAX_REGISTERS - 1; + } #line 4682 "y.tab.c" /* yacc.c:1646 */ break; - case 304: + case 304: #line 2023 "lev_comp.y" /* yacc.c:1646 */ { - if ( (yyvsp[-1].i) >= 3 ) - lc_error("Register Index overflow!"); - else - (yyval.i) = - (yyvsp[-1].i) - 1; - } + if ((yyvsp[-1].i) >= 3) + lc_error("Register Index overflow!"); + else + (yyval.i) = -(yyvsp[-1].i) - 1; + } #line 4693 "y.tab.c" /* yacc.c:1646 */ break; - case 305: + case 305: #line 2032 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "s", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + add_opvars(splev, "s", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4702 "y.tab.c" /* yacc.c:1646 */ break; - case 306: + case 306: #line 2037 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_STRING); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), + SPOVAR_STRING); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4713 "y.tab.c" /* yacc.c:1646 */ break; - case 307: + case 307: #line 2044 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_STRING|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_STRING | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 4724 "y.tab.c" /* yacc.c:1646 */ break; - case 308: + case 308: #line 2054 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 4732 "y.tab.c" /* yacc.c:1646 */ break; - case 309: + case 309: #line 2060 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "c", VA_PASS1((yyvsp[0].i))); + } #line 4740 "y.tab.c" /* yacc.c:1646 */ break; - case 310: + case 310: #line 2064 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_RNDCOORD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_RNDCOORD)); + } #line 4748 "y.tab.c" /* yacc.c:1646 */ break; - case 311: + case 311: #line 2068 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_COORD); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_COORD); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4759 "y.tab.c" /* yacc.c:1646 */ break; - case 312: + case 312: #line 2075 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_COORD|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_COORD | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 4770 "y.tab.c" /* yacc.c:1646 */ break; - case 313: + case 313: #line 2084 "lev_comp.y" /* yacc.c:1646 */ { - if ((yyvsp[-3].i) < 0 || (yyvsp[-1].i) < 0 || (yyvsp[-3].i) >= COLNO || (yyvsp[-1].i) >= ROWNO) - lc_error("Coordinates (%li,%li) out of map range!", (yyvsp[-3].i), (yyvsp[-1].i)); - (yyval.i) = SP_COORD_PACK((yyvsp[-3].i), (yyvsp[-1].i)); - } + if ((yyvsp[-3].i) < 0 || (yyvsp[-1].i) < 0 || (yyvsp[-3].i) >= COLNO + || (yyvsp[-1].i) >= ROWNO) + lc_error("Coordinates (%li,%li) out of map range!", (yyvsp[-3].i), + (yyvsp[-1].i)); + (yyval.i) = SP_COORD_PACK((yyvsp[-3].i), (yyvsp[-1].i)); + } #line 4780 "y.tab.c" /* yacc.c:1646 */ break; - case 314: + case 314: #line 2090 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = SP_COORD_PACK_RANDOM(0); - } + (yyval.i) = SP_COORD_PACK_RANDOM(0); + } #line 4788 "y.tab.c" /* yacc.c:1646 */ break; - case 315: + case 315: #line 2094 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = SP_COORD_PACK_RANDOM( (yyvsp[-1].i) ); - } + (yyval.i) = SP_COORD_PACK_RANDOM((yyvsp[-1].i)); + } #line 4796 "y.tab.c" /* yacc.c:1646 */ break; - case 316: + case 316: #line 2100 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (yyvsp[0].i); - } + (yyval.i) = (yyvsp[0].i); + } #line 4804 "y.tab.c" /* yacc.c:1646 */ break; - case 317: + case 317: #line 2104 "lev_comp.y" /* yacc.c:1646 */ { - if (((yyvsp[-2].i) & (yyvsp[0].i))) - lc_warning("Humidity flag used twice."); - (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); - } + if (((yyvsp[-2].i) & (yyvsp[0].i))) + lc_warning("Humidity flag used twice."); + (yyval.i) = ((yyvsp[-2].i) | (yyvsp[0].i)); + } #line 4814 "y.tab.c" /* yacc.c:1646 */ break; - case 318: + case 318: #line 2112 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 4822 "y.tab.c" /* yacc.c:1646 */ break; - case 319: + case 319: #line 2116 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_REGION); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), + SPOVAR_REGION); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4833 "y.tab.c" /* yacc.c:1646 */ break; - case 320: + case 320: #line 2123 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_REGION|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_REGION | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 4844 "y.tab.c" /* yacc.c:1646 */ break; - case 321: + case 321: #line 2132 "lev_comp.y" /* yacc.c:1646 */ { - long r = SP_REGION_PACK((yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - if ( (yyvsp[-7].i) > (yyvsp[-3].i) || (yyvsp[-5].i) > (yyvsp[-1].i) ) - lc_error("Region start > end: (%li,%li,%li,%li)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); + long r = SP_REGION_PACK((yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + if ((yyvsp[-7].i) > (yyvsp[-3].i) || (yyvsp[-5].i) > (yyvsp[-1].i)) + lc_error("Region start > end: (%li,%li,%li,%li)!", (yyvsp[-7].i), + (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - add_opvars(splev, "r", VA_PASS1(r)); - (yyval.i) = r; - } + add_opvars(splev, "r", VA_PASS1(r)); + (yyval.i) = r; + } #line 4857 "y.tab.c" /* yacc.c:1646 */ break; - case 322: + case 322: #line 2143 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "m", VA_PASS1((yyvsp[0].i))); + } #line 4865 "y.tab.c" /* yacc.c:1646 */ break; - case 323: + case 323: #line 2147 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_MAPCHAR); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), + SPOVAR_MAPCHAR); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4876 "y.tab.c" /* yacc.c:1646 */ break; - case 324: + case 324: #line 2154 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_MAPCHAR|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_MAPCHAR | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 4887 "y.tab.c" /* yacc.c:1646 */ break; - case 325: + case 325: #line 2163 "lev_comp.y" /* yacc.c:1646 */ { - if (what_map_char((char) (yyvsp[0].i)) != INVALID_TYPE) - (yyval.i) = SP_MAPCHAR_PACK(what_map_char((char) (yyvsp[0].i)), -2); - else { - lc_error("Unknown map char type '%c'!", (yyvsp[0].i)); - (yyval.i) = SP_MAPCHAR_PACK(STONE, -2); - } - } + if (what_map_char((char) (yyvsp[0].i)) != INVALID_TYPE) + (yyval.i) = + SP_MAPCHAR_PACK(what_map_char((char) (yyvsp[0].i)), -2); + else { + lc_error("Unknown map char type '%c'!", (yyvsp[0].i)); + (yyval.i) = SP_MAPCHAR_PACK(STONE, -2); + } + } #line 4900 "y.tab.c" /* yacc.c:1646 */ break; - case 326: + case 326: #line 2172 "lev_comp.y" /* yacc.c:1646 */ { - if (what_map_char((char) (yyvsp[-3].i)) != INVALID_TYPE) - (yyval.i) = SP_MAPCHAR_PACK(what_map_char((char) (yyvsp[-3].i)), (yyvsp[-1].i)); - else { - lc_error("Unknown map char type '%c'!", (yyvsp[-3].i)); - (yyval.i) = SP_MAPCHAR_PACK(STONE, (yyvsp[-1].i)); - } - } + if (what_map_char((char) (yyvsp[-3].i)) != INVALID_TYPE) + (yyval.i) = SP_MAPCHAR_PACK(what_map_char((char) (yyvsp[-3].i)), + (yyvsp[-1].i)); + else { + lc_error("Unknown map char type '%c'!", (yyvsp[-3].i)); + (yyval.i) = SP_MAPCHAR_PACK(STONE, (yyvsp[-1].i)); + } + } #line 4913 "y.tab.c" /* yacc.c:1646 */ break; - case 327: + case 327: #line 2183 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "M", VA_PASS1((yyvsp[0].i))); + } #line 4921 "y.tab.c" /* yacc.c:1646 */ break; - case 328: + case 328: #line 2187 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_MONST); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_MONST); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 4932 "y.tab.c" /* yacc.c:1646 */ break; - case 329: + case 329: #line 2194 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_MONST|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_MONST | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 4943 "y.tab.c" /* yacc.c:1646 */ break; - case 330: + case 330: #line 2203 "lev_comp.y" /* yacc.c:1646 */ { - long m = get_monster_id((yyvsp[0].map), (char)0); - if (m == ERR) { - lc_error("Unknown monster \"%s\"!", (yyvsp[0].map)); - (yyval.i) = -1; - } else - (yyval.i) = SP_MONST_PACK(m, def_monsyms[(int)mons[m].mlet].sym); - } + long m = get_monster_id((yyvsp[0].map), (char) 0); + if (m == ERR) { + lc_error("Unknown monster \"%s\"!", (yyvsp[0].map)); + (yyval.i) = -1; + } else + (yyval.i) = SP_MONST_PACK(m, def_monsyms[(int) mons[m].mlet].sym); + } #line 4956 "y.tab.c" /* yacc.c:1646 */ break; - case 331: + case 331: #line 2212 "lev_comp.y" /* yacc.c:1646 */ { - if (check_monster_char((char) (yyvsp[0].i))) - (yyval.i) = SP_MONST_PACK(-1, (yyvsp[0].i)); - else { - lc_error("Unknown monster class '%c'!", (yyvsp[0].i)); - (yyval.i) = -1; - } - } + if (check_monster_char((char) (yyvsp[0].i))) + (yyval.i) = SP_MONST_PACK(-1, (yyvsp[0].i)); + else { + lc_error("Unknown monster class '%c'!", (yyvsp[0].i)); + (yyval.i) = -1; + } + } #line 4969 "y.tab.c" /* yacc.c:1646 */ break; - case 332: + case 332: #line 2221 "lev_comp.y" /* yacc.c:1646 */ { - long m = get_monster_id((yyvsp[-1].map), (char) (yyvsp[-3].i)); - if (m == ERR) { - lc_error("Unknown monster ('%c', \"%s\")!", (yyvsp[-3].i), (yyvsp[-1].map)); - (yyval.i) = -1; - } else - (yyval.i) = SP_MONST_PACK(m, (yyvsp[-3].i)); - } + long m = get_monster_id((yyvsp[-1].map), (char) (yyvsp[-3].i)); + if (m == ERR) { + lc_error("Unknown monster ('%c', \"%s\")!", (yyvsp[-3].i), + (yyvsp[-1].map)); + (yyval.i) = -1; + } else + (yyval.i) = SP_MONST_PACK(m, (yyvsp[-3].i)); + } #line 4982 "y.tab.c" /* yacc.c:1646 */ break; - case 333: + case 333: #line 2230 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 4990 "y.tab.c" /* yacc.c:1646 */ break; - case 334: + case 334: #line 2236 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "O", VA_PASS1((yyvsp[0].i))); + } #line 4998 "y.tab.c" /* yacc.c:1646 */ break; - case 335: + case 335: #line 2240 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_OBJ); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_OBJ); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 5009 "y.tab.c" /* yacc.c:1646 */ break; - case 336: + case 336: #line 2247 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[-3].map), SPOVAR_OBJ|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_OBJ | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + } #line 5020 "y.tab.c" /* yacc.c:1646 */ break; - case 337: + case 337: #line 2256 "lev_comp.y" /* yacc.c:1646 */ { - long m = get_object_id((yyvsp[0].map), (char)0); - if (m == ERR) { - lc_error("Unknown object \"%s\"!", (yyvsp[0].map)); - (yyval.i) = -1; - } else - (yyval.i) = SP_OBJ_PACK(m, 1); /* obj class != 0 to force generation of a specific item */ + long m = get_object_id((yyvsp[0].map), (char) 0); + if (m == ERR) { + lc_error("Unknown object \"%s\"!", (yyvsp[0].map)); + (yyval.i) = -1; + } else + (yyval.i) = SP_OBJ_PACK(m, 1); /* obj class != 0 to force + generation of a specific item */ - } + } #line 5034 "y.tab.c" /* yacc.c:1646 */ break; - case 338: + case 338: #line 2266 "lev_comp.y" /* yacc.c:1646 */ { - if (check_object_char((char) (yyvsp[0].i))) - (yyval.i) = SP_OBJ_PACK(-1, (yyvsp[0].i)); - else { - lc_error("Unknown object class '%c'!", (yyvsp[0].i)); - (yyval.i) = -1; - } - } + if (check_object_char((char) (yyvsp[0].i))) + (yyval.i) = SP_OBJ_PACK(-1, (yyvsp[0].i)); + else { + lc_error("Unknown object class '%c'!", (yyvsp[0].i)); + (yyval.i) = -1; + } + } #line 5047 "y.tab.c" /* yacc.c:1646 */ break; - case 339: + case 339: #line 2275 "lev_comp.y" /* yacc.c:1646 */ { - long m = get_object_id((yyvsp[-1].map), (char) (yyvsp[-3].i)); - if (m == ERR) { - lc_error("Unknown object ('%c', \"%s\")!", (yyvsp[-3].i), (yyvsp[-1].map)); - (yyval.i) = -1; - } else - (yyval.i) = SP_OBJ_PACK(m, (yyvsp[-3].i)); - } + long m = get_object_id((yyvsp[-1].map), (char) (yyvsp[-3].i)); + if (m == ERR) { + lc_error("Unknown object ('%c', \"%s\")!", (yyvsp[-3].i), + (yyvsp[-1].map)); + (yyval.i) = -1; + } else + (yyval.i) = SP_OBJ_PACK(m, (yyvsp[-3].i)); + } #line 5060 "y.tab.c" /* yacc.c:1646 */ break; - case 340: + case 340: #line 2284 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = -1; - } + (yyval.i) = -1; + } #line 5068 "y.tab.c" /* yacc.c:1646 */ break; - case 341: + case 341: #line 2290 "lev_comp.y" /* yacc.c:1646 */ - { } + { + } #line 5074 "y.tab.c" /* yacc.c:1646 */ break; - case 342: + case 342: #line 2292 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_ADD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_ADD)); + } #line 5082 "y.tab.c" /* yacc.c:1646 */ break; - case 343: + case 343: #line 2298 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); + } #line 5090 "y.tab.c" /* yacc.c:1646 */ break; - case 344: + case 344: #line 2302 "lev_comp.y" /* yacc.c:1646 */ { - is_inconstant_number = 1; - } + is_inconstant_number = 1; + } #line 5098 "y.tab.c" /* yacc.c:1646 */ break; - case 345: + case 345: #line 2306 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1((yyvsp[-1].i))); - } + add_opvars(splev, "i", VA_PASS1((yyvsp[-1].i))); + } #line 5106 "y.tab.c" /* yacc.c:1646 */ break; - case 346: + case 346: #line 2310 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_INT); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - is_inconstant_number = 1; - } + check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_INT); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + is_inconstant_number = 1; + } #line 5118 "y.tab.c" /* yacc.c:1646 */ break; - case 347: + case 347: #line 2318 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, - (yyvsp[-3].map), SPOVAR_INT|SPOVAR_ARRAY); - vardef_used(variable_definitions, (yyvsp[-3].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); - Free((yyvsp[-3].map)); - is_inconstant_number = 1; - } + check_vardef_type(variable_definitions, (yyvsp[-3].map), + SPOVAR_INT | SPOVAR_ARRAY); + vardef_used(variable_definitions, (yyvsp[-3].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[-3].map))); + Free((yyvsp[-3].map)); + is_inconstant_number = 1; + } #line 5131 "y.tab.c" /* yacc.c:1646 */ break; - case 348: + case 348: #line 2327 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_ADD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_ADD)); + } #line 5139 "y.tab.c" /* yacc.c:1646 */ break; - case 349: + case 349: #line 2331 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_SUB)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_SUB)); + } #line 5147 "y.tab.c" /* yacc.c:1646 */ break; - case 350: + case 350: #line 2335 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_MUL)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_MUL)); + } #line 5155 "y.tab.c" /* yacc.c:1646 */ break; - case 351: + case 351: #line 2339 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_DIV)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_DIV)); + } #line 5163 "y.tab.c" /* yacc.c:1646 */ break; - case 352: + case 352: #line 2343 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_MATH_MOD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_MATH_MOD)); + } #line 5171 "y.tab.c" /* yacc.c:1646 */ break; - case 353: + case 353: #line 2346 "lev_comp.y" /* yacc.c:1646 */ - { } + { + } #line 5177 "y.tab.c" /* yacc.c:1646 */ break; - case 354: + case 354: #line 2350 "lev_comp.y" /* yacc.c:1646 */ { - if (!strcmp("int", (yyvsp[0].map)) || !strcmp("integer", (yyvsp[0].map))) { - (yyval.i) = (int)'i'; - } else - lc_error("Unknown function parameter type '%s'", (yyvsp[0].map)); - } + if (!strcmp("int", (yyvsp[0].map)) + || !strcmp("integer", (yyvsp[0].map))) { + (yyval.i) = (int) 'i'; + } else + lc_error("Unknown function parameter type '%s'", (yyvsp[0].map)); + } #line 5188 "y.tab.c" /* yacc.c:1646 */ break; - case 355: + case 355: #line 2357 "lev_comp.y" /* yacc.c:1646 */ { - if (!strcmp("str", (yyvsp[0].map)) || !strcmp("string", (yyvsp[0].map))) { - (yyval.i) = (int)'s'; - } else - lc_error("Unknown function parameter type '%s'", (yyvsp[0].map)); - } + if (!strcmp("str", (yyvsp[0].map)) + || !strcmp("string", (yyvsp[0].map))) { + (yyval.i) = (int) 's'; + } else + lc_error("Unknown function parameter type '%s'", (yyvsp[0].map)); + } #line 5199 "y.tab.c" /* yacc.c:1646 */ break; - case 356: + case 356: #line 2366 "lev_comp.y" /* yacc.c:1646 */ { - struct lc_funcdefs_parm *tmp = New(struct lc_funcdefs_parm); + struct lc_funcdefs_parm *tmp = New(struct lc_funcdefs_parm); - if (!curr_function) { - lc_error("Function parameters outside function definition."); - } else if (!tmp) { - lc_error("Could not alloc function params."); - } else { - long vt; - tmp->name = strdup((yyvsp[-2].map)); - tmp->parmtype = (char) (yyvsp[0].i); - tmp->next = curr_function->params; - curr_function->params = tmp; - curr_function->n_params++; - switch (tmp->parmtype) { - case 'i': vt = SPOVAR_INT; break; - case 's': vt = SPOVAR_STRING; break; - default: lc_error("Unknown func param conversion."); break; - } - variable_definitions = add_vardef_type( - variable_definitions, - (yyvsp[-2].map), vt); - } - Free((yyvsp[-2].map)); - } + if (!curr_function) { + lc_error("Function parameters outside function definition."); + } else if (!tmp) { + lc_error("Could not alloc function params."); + } else { + long vt; + tmp->name = strdup((yyvsp[-2].map)); + tmp->parmtype = (char) (yyvsp[0].i); + tmp->next = curr_function->params; + curr_function->params = tmp; + curr_function->n_params++; + switch (tmp->parmtype) { + case 'i': + vt = SPOVAR_INT; + break; + case 's': + vt = SPOVAR_STRING; + break; + default: + lc_error("Unknown func param conversion."); + break; + } + variable_definitions = + add_vardef_type(variable_definitions, (yyvsp[-2].map), vt); + } + Free((yyvsp[-2].map)); + } #line 5229 "y.tab.c" /* yacc.c:1646 */ break; - case 361: + case 361: #line 2402 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (int)'i'; - } + (yyval.i) = (int) 'i'; + } #line 5237 "y.tab.c" /* yacc.c:1646 */ break; - case 362: + case 362: #line 2406 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.i) = (int)'s'; - } + (yyval.i) = (int) 's'; + } #line 5245 "y.tab.c" /* yacc.c:1646 */ break; - case 363: + case 363: #line 2413 "lev_comp.y" /* yacc.c:1646 */ { - char tmpbuf[2]; - tmpbuf[0] = (char) (yyvsp[0].i); - tmpbuf[1] = '\0'; - (yyval.map) = strdup(tmpbuf); - } + char tmpbuf[2]; + tmpbuf[0] = (char) (yyvsp[0].i); + tmpbuf[1] = '\0'; + (yyval.map) = strdup(tmpbuf); + } #line 5256 "y.tab.c" /* yacc.c:1646 */ break; - case 364: + case 364: #line 2420 "lev_comp.y" /* yacc.c:1646 */ { - long len = strlen( (yyvsp[-2].map) ); - char *tmp = (char *)alloc(len + 2); - sprintf(tmp, "%c%s", (char) (yyvsp[0].i), (yyvsp[-2].map) ); - Free( (yyvsp[-2].map) ); - (yyval.map) = tmp; - } + long len = strlen((yyvsp[-2].map)); + char *tmp = (char *) alloc(len + 2); + sprintf(tmp, "%c%s", (char) (yyvsp[0].i), (yyvsp[-2].map)); + Free((yyvsp[-2].map)); + (yyval.map) = tmp; + } #line 5268 "y.tab.c" /* yacc.c:1646 */ break; - case 365: + case 365: #line 2430 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.map) = strdup(""); - } + (yyval.map) = strdup(""); + } #line 5276 "y.tab.c" /* yacc.c:1646 */ break; - case 366: + case 366: #line 2434 "lev_comp.y" /* yacc.c:1646 */ { - char *tmp = strdup( (yyvsp[0].map) ); - Free( (yyvsp[0].map) ); - (yyval.map) = tmp; - } + char *tmp = strdup((yyvsp[0].map)); + Free((yyvsp[0].map)); + (yyval.map) = tmp; + } #line 5286 "y.tab.c" /* yacc.c:1646 */ break; - case 367: + case 367: #line 2442 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_POINT)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_POINT)); + } #line 5294 "y.tab.c" /* yacc.c:1646 */ break; - case 368: + case 368: #line 2446 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_RECT)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_RECT)); + } #line 5302 "y.tab.c" /* yacc.c:1646 */ break; - case 369: + case 369: #line 2450 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_FILLRECT)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_FILLRECT)); + } #line 5310 "y.tab.c" /* yacc.c:1646 */ break; - case 370: + case 370: #line 2454 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_LINE)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_LINE)); + } #line 5318 "y.tab.c" /* yacc.c:1646 */ break; - case 371: + case 371: #line 2458 "lev_comp.y" /* yacc.c:1646 */ { - /* randline (x1,y1),(x2,y2), roughness */ - add_opvars(splev, "o", VA_PASS1(SPO_SEL_RNDLINE)); - } + /* randline (x1,y1),(x2,y2), roughness */ + add_opvars(splev, "o", VA_PASS1(SPO_SEL_RNDLINE)); + } #line 5327 "y.tab.c" /* yacc.c:1646 */ break; - case 372: + case 372: #line 2463 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(W_ANY, SPO_SEL_GROW)); - } + add_opvars(splev, "io", VA_PASS2(W_ANY, SPO_SEL_GROW)); + } #line 5335 "y.tab.c" /* yacc.c:1646 */ break; - case 373: + case 373: #line 2467 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2((yyvsp[-3].i), SPO_SEL_GROW)); - } + add_opvars(splev, "io", VA_PASS2((yyvsp[-3].i), SPO_SEL_GROW)); + } #line 5343 "y.tab.c" /* yacc.c:1646 */ break; - case 374: + case 374: #line 2471 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iio", - VA_PASS3((yyvsp[-3].i), SPOFILTER_PERCENT, SPO_SEL_FILTER)); - } + add_opvars(splev, "iio", VA_PASS3((yyvsp[-3].i), SPOFILTER_PERCENT, + SPO_SEL_FILTER)); + } #line 5352 "y.tab.c" /* yacc.c:1646 */ break; - case 375: + case 375: #line 2476 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2(SPOFILTER_SELECTION, SPO_SEL_FILTER)); - } + add_opvars(splev, "io", + VA_PASS2(SPOFILTER_SELECTION, SPO_SEL_FILTER)); + } #line 5361 "y.tab.c" /* yacc.c:1646 */ break; - case 376: + case 376: #line 2481 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", - VA_PASS2(SPOFILTER_MAPCHAR, SPO_SEL_FILTER)); - } + add_opvars(splev, "io", VA_PASS2(SPOFILTER_MAPCHAR, SPO_SEL_FILTER)); + } #line 5370 "y.tab.c" /* yacc.c:1646 */ break; - case 377: + case 377: #line 2486 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_FLOOD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_FLOOD)); + } #line 5378 "y.tab.c" /* yacc.c:1646 */ break; - case 378: + case 378: #line 2490 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "oio", - VA_PASS3(SPO_COPY, 1, SPO_SEL_ELLIPSE)); - } + add_opvars(splev, "oio", VA_PASS3(SPO_COPY, 1, SPO_SEL_ELLIPSE)); + } #line 5387 "y.tab.c" /* yacc.c:1646 */ break; - case 379: + case 379: #line 2495 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "oio", - VA_PASS3(SPO_COPY, (yyvsp[-1].i), SPO_SEL_ELLIPSE)); - } + add_opvars(splev, "oio", + VA_PASS3(SPO_COPY, (yyvsp[-1].i), SPO_SEL_ELLIPSE)); + } #line 5396 "y.tab.c" /* yacc.c:1646 */ break; - case 380: + case 380: #line 2500 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2(1, SPO_SEL_ELLIPSE)); - } + add_opvars(splev, "io", VA_PASS2(1, SPO_SEL_ELLIPSE)); + } #line 5404 "y.tab.c" /* yacc.c:1646 */ break; - case 381: + case 381: #line 2504 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "io", VA_PASS2((yyvsp[-1].i), SPO_SEL_ELLIPSE)); - } + add_opvars(splev, "io", VA_PASS2((yyvsp[-1].i), SPO_SEL_ELLIPSE)); + } #line 5412 "y.tab.c" /* yacc.c:1646 */ break; - case 382: + case 382: #line 2508 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iio", - VA_PASS3((yyvsp[-5].i), (yyvsp[-11].i), SPO_SEL_GRADIENT)); - } + add_opvars(splev, "iio", + VA_PASS3((yyvsp[-5].i), (yyvsp[-11].i), SPO_SEL_GRADIENT)); + } #line 5421 "y.tab.c" /* yacc.c:1646 */ break; - case 383: + case 383: #line 2513 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_COMPLEMENT)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_COMPLEMENT)); + } #line 5429 "y.tab.c" /* yacc.c:1646 */ break; - case 384: + case 384: #line 2517 "lev_comp.y" /* yacc.c:1646 */ { - check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_SEL); - vardef_used(variable_definitions, (yyvsp[0].map)); - add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); - Free((yyvsp[0].map)); - } + check_vardef_type(variable_definitions, (yyvsp[0].map), SPOVAR_SEL); + vardef_used(variable_definitions, (yyvsp[0].map)); + add_opvars(splev, "v", VA_PASS1((yyvsp[0].map))); + Free((yyvsp[0].map)); + } #line 5440 "y.tab.c" /* yacc.c:1646 */ break; - case 385: + case 385: #line 2524 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 5448 "y.tab.c" /* yacc.c:1646 */ break; - case 386: + case 386: #line 2530 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 5456 "y.tab.c" /* yacc.c:1646 */ break; - case 387: + case 387: #line 2534 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "o", VA_PASS1(SPO_SEL_ADD)); - } + add_opvars(splev, "o", VA_PASS1(SPO_SEL_ADD)); + } #line 5464 "y.tab.c" /* yacc.c:1646 */ break; - case 388: + case 388: #line 2540 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "iio", - VA_PASS3((yyvsp[0].dice).num, (yyvsp[0].dice).die, SPO_DICE)); - } + add_opvars(splev, "iio", VA_PASS3((yyvsp[0].dice).num, + (yyvsp[0].dice).die, SPO_DICE)); + } #line 5473 "y.tab.c" /* yacc.c:1646 */ break; - case 392: + case 392: #line 2552 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); + } #line 5481 "y.tab.c" /* yacc.c:1646 */ break; - case 393: + case 393: #line 2556 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); + } #line 5489 "y.tab.c" /* yacc.c:1646 */ break; - case 394: + case 394: #line 2560 "lev_comp.y" /* yacc.c:1646 */ { - add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); - } + add_opvars(splev, "i", VA_PASS1((yyvsp[0].i))); + } #line 5497 "y.tab.c" /* yacc.c:1646 */ break; - case 395: + case 395: #line 2564 "lev_comp.y" /* yacc.c:1646 */ { - /* nothing */ - } + /* nothing */ + } #line 5505 "y.tab.c" /* yacc.c:1646 */ break; - case 404: + case 404: #line 2586 "lev_comp.y" /* yacc.c:1646 */ { - (yyval.lregn) = (yyvsp[0].lregn); - } + (yyval.lregn) = (yyvsp[0].lregn); + } #line 5513 "y.tab.c" /* yacc.c:1646 */ break; - case 405: + case 405: #line 2590 "lev_comp.y" /* yacc.c:1646 */ { - if ((yyvsp[-7].i) <= 0 || (yyvsp[-7].i) >= COLNO) - lc_error("Region (%li,%li,%li,%li) out of level range (x1)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-5].i) < 0 || (yyvsp[-5].i) >= ROWNO) - lc_error("Region (%li,%li,%li,%li) out of level range (y1)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-3].i) <= 0 || (yyvsp[-3].i) >= COLNO) - lc_error("Region (%li,%li,%li,%li) out of level range (x2)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-1].i) < 0 || (yyvsp[-1].i) >= ROWNO) - lc_error("Region (%li,%li,%li,%li) out of level range (y2)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - (yyval.lregn).x1 = (yyvsp[-7].i); - (yyval.lregn).y1 = (yyvsp[-5].i); - (yyval.lregn).x2 = (yyvsp[-3].i); - (yyval.lregn).y2 = (yyvsp[-1].i); - (yyval.lregn).area = 1; - } + if ((yyvsp[-7].i) <= 0 || (yyvsp[-7].i) >= COLNO) + lc_error("Region (%li,%li,%li,%li) out of level range (x1)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-5].i) < 0 || (yyvsp[-5].i) >= ROWNO) + lc_error("Region (%li,%li,%li,%li) out of level range (y1)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-3].i) <= 0 || (yyvsp[-3].i) >= COLNO) + lc_error("Region (%li,%li,%li,%li) out of level range (x2)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-1].i) < 0 || (yyvsp[-1].i) >= ROWNO) + lc_error("Region (%li,%li,%li,%li) out of level range (y2)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + (yyval.lregn).x1 = (yyvsp[-7].i); + (yyval.lregn).y1 = (yyvsp[-5].i); + (yyval.lregn).x2 = (yyvsp[-3].i); + (yyval.lregn).y2 = (yyvsp[-1].i); + (yyval.lregn).area = 1; + } #line 5533 "y.tab.c" /* yacc.c:1646 */ break; - case 406: + case 406: #line 2608 "lev_comp.y" /* yacc.c:1646 */ { -/* This series of if statements is a hack for MSC 5.1. It seems that its - tiny little brain cannot compile if these are all one big if statement. */ - if ((yyvsp[-7].i) < 0 || (yyvsp[-7].i) > (int)max_x_map) - lc_error("Region (%li,%li,%li,%li) out of map range (x1)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-5].i) < 0 || (yyvsp[-5].i) > (int)max_y_map) - lc_error("Region (%li,%li,%li,%li) out of map range (y1)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-3].i) < 0 || (yyvsp[-3].i) > (int)max_x_map) - lc_error("Region (%li,%li,%li,%li) out of map range (x2)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - else if ((yyvsp[-1].i) < 0 || (yyvsp[-1].i) > (int)max_y_map) - lc_error("Region (%li,%li,%li,%li) out of map range (y2)!", (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), (yyvsp[-1].i)); - (yyval.lregn).area = 0; - (yyval.lregn).x1 = (yyvsp[-7].i); - (yyval.lregn).y1 = (yyvsp[-5].i); - (yyval.lregn).x2 = (yyvsp[-3].i); - (yyval.lregn).y2 = (yyvsp[-1].i); - } + /* This series of if statements is a hack for MSC 5.1. It seems that + its + tiny little brain cannot compile if these are all one big if + statement. */ + if ((yyvsp[-7].i) < 0 || (yyvsp[-7].i) > (int) max_x_map) + lc_error("Region (%li,%li,%li,%li) out of map range (x1)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-5].i) < 0 || (yyvsp[-5].i) > (int) max_y_map) + lc_error("Region (%li,%li,%li,%li) out of map range (y1)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-3].i) < 0 || (yyvsp[-3].i) > (int) max_x_map) + lc_error("Region (%li,%li,%li,%li) out of map range (x2)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + else if ((yyvsp[-1].i) < 0 || (yyvsp[-1].i) > (int) max_y_map) + lc_error("Region (%li,%li,%li,%li) out of map range (y2)!", + (yyvsp[-7].i), (yyvsp[-5].i), (yyvsp[-3].i), + (yyvsp[-1].i)); + (yyval.lregn).area = 0; + (yyval.lregn).x1 = (yyvsp[-7].i); + (yyval.lregn).y1 = (yyvsp[-5].i); + (yyval.lregn).x2 = (yyvsp[-3].i); + (yyval.lregn).y2 = (yyvsp[-1].i); + } #line 5555 "y.tab.c" /* yacc.c:1646 */ break; - #line 5559 "y.tab.c" /* yacc.c:1646 */ - default: break; + default: + break; } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YYPOPSTACK(yylen); + yylen = 0; + YY_STACK_PRINT(yyss, yyssp); - *++yyvsp = yyval; + *++yyvsp = yyval; - /* Now 'shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ - yyn = yyr1[yyn]; + yyn = yyr1[yyn]; - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + goto yynewstate; /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) { + ++yynerrs; +#if !YYERROR_VERBOSE + yyerror(YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; +#define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR + else if (yysyntax_error_status == 1) { + if (yymsg != yymsgbuf) + YYSTACK_FREE(yymsg); + yymsg = (char *) YYSTACK_ALLOC(yymsg_alloc); + if (!yymsg) { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } else { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror(yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +#undef YYSYNTAX_ERROR #endif } + if (yyerrstatus == 3) { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; + if (yychar <= YYEOF) { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else { + yydestruct("Error: discarding", yytoken, &yylval); + yychar = YYEMPTY; } } - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK(yylen); + yylen = 0; + YY_STACK_PRINT(yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; + for (;;) { + yyn = yypact[yystate]; + if (!yypact_value_is_default(yyn)) { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { + yyn = yytable[yyn]; + if (0 < yyn) + break; } } - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; - - yydestruct ("Error: popping", - yystos[yystate], yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); + yydestruct("Error: popping", yystos[yystate], yyvsp); + YYPOPSTACK(1); + yystate = *yyssp; + YY_STACK_PRINT(yyss, yyssp); } - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + /* Shift the error token. */ + YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - + yystate = yyn; + goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: - yyresult = 0; - goto yyreturn; + yyresult = 0; + goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: - yyresult = 1; - goto yyreturn; + yyresult = 1; + goto yyreturn; #if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ + yyerror(YY_("memory exhausted")); + yyresult = 2; +/* Fall through. */ #endif yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); + if (yychar != YYEMPTY) { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE(yychar); + yydestruct("Cleanup: discarding lookahead", yytoken, &yylval); } - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); - YYPOPSTACK (1); + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK(yylen); + YY_STACK_PRINT(yyss, yyssp); + while (yyssp != yyss) { + yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp); + YYPOPSTACK(1); } #ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); + if (yyss != yyssa) + YYSTACK_FREE(yyss); #endif #if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); + if (yymsg != yymsgbuf) + YYSTACK_FREE(yymsg); #endif - return yyresult; + return yyresult; } #line 2628 "lev_comp.y" /* yacc.c:1906 */ - /*lev_comp.y*/ diff --git a/sys/share/nhlan.c b/sys/share/nhlan.c index 65f0af7cd..54c67a3b5 100644 --- a/sys/share/nhlan.c +++ b/sys/share/nhlan.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 nhlan.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 nhlan.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 nhlan.c $Date: 2009/05/06 10:50:26 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)nhlan.c 3.5 1999/11/21 */ /* Copyright (c) Michael Allison, 1997 */ @@ -19,9 +19,10 @@ #ifdef LAN_FEATURES -void init_lan_features() +void +init_lan_features() { - lan_username(); + lan_username(); } /* * The get_lan_username() call is a required call, since some of @@ -31,14 +32,16 @@ void init_lan_features() char lusername[MAX_LAN_USERNAME]; int lusername_size = MAX_LAN_USERNAME; -char *lan_username() +char * +lan_username() { - char *lu; - lu = get_username(&lusername_size); - if (lu) { - Strcpy(lusername, lu); - return lusername; - } else return (char *)0; + char *lu; + lu = get_username(&lusername_size); + if (lu) { + Strcpy(lusername, lu); + return lusername; + } else + return (char *) 0; } #endif /*LAN_FEATURES*/ /*nhlan.c*/ diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index d545431e2..3a227d45d 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pcmain.c $NHDT-Date: 1427337317 2015/03/26 02:35:17 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.52 $ */ +/* NetHack 3.6 pcmain.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */ /* NetHack 3.6 pcmain.c $Date: 2012/01/20 03:41:31 $ $Revision: 1.48 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,45 +17,45 @@ #if !defined(AMIGA) && !defined(GNUDOS) #include #else -# ifdef GNUDOS +#ifdef GNUDOS #include -# endif +#endif #endif #ifdef WIN32 -#include "win32api.h" /* for GetModuleFileName */ +#include "win32api.h" /* for GetModuleFileName */ #endif #ifdef __DJGPP__ -#include /* for getcwd() prototype */ +#include /* for getcwd() prototype */ #endif -char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */ +char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */ #ifdef TOS -boolean run_from_desktop = TRUE; /* should we pause before exiting?? */ -# ifdef __GNUC__ -long _stksize = 16*1024; -# endif +boolean run_from_desktop = TRUE; /* should we pause before exiting?? */ +#ifdef __GNUC__ +long _stksize = 16 * 1024; +#endif #endif #ifdef AMIGA extern int bigscreen; -void NDECL( preserve_icon ); +void NDECL(preserve_icon); #endif -STATIC_DCL void FDECL(process_options,(int argc,char **argv)); +STATIC_DCL void FDECL(process_options, (int argc, char **argv)); STATIC_DCL void NDECL(nhusage); #if defined(MICRO) || defined(WIN32) || defined(OS2) -extern void FDECL(nethack_exit,(int)); +extern void FDECL(nethack_exit, (int)); #else #define nethack_exit exit #endif #ifdef WIN32 -extern boolean getreturn_enabled; /* from sys/share/pcsys.c */ -extern int redirect_stdout; /* from sys/share/pcsys.c */ +extern boolean getreturn_enabled; /* from sys/share/pcsys.c */ +extern int redirect_stdout; /* from sys/share/pcsys.c */ char *NDECL(exename); char default_window_sys[] = "mswin"; #endif @@ -65,75 +65,74 @@ extern void NDECL(mswin_destroy_reg); #endif #ifdef EXEPATH -STATIC_DCL char *FDECL(exepath,(char *)); +STATIC_DCL char *FDECL(exepath, (char *)); #endif -int FDECL(main, (int,char **)); - -extern boolean FDECL(pcmain, (int,char **)); +int FDECL(main, (int, char **)); +extern boolean FDECL(pcmain, (int, char **)); #if defined(__BORLANDC__) && !defined(_WIN32) -void NDECL( startup ); +void NDECL(startup); unsigned _stklen = STKSIZ; #endif /* If the graphics version is built, we don't need a main; it is skipped - * to help MinGW decide which entry point to choose. If both main and + * to help MinGW decide which entry point to choose. If both main and * WinMain exist, the resulting executable won't work correctly. */ #ifndef __MINGW32__ int -main(argc,argv) +main(argc, argv) int argc; char *argv[]; { - boolean resuming; + boolean resuming; - sys_early_init(); + sys_early_init(); #ifdef WIN32 - Strcpy(default_window_sys, "tty"); + Strcpy(default_window_sys, "tty"); #endif - resuming = pcmain(argc,argv); + resuming = pcmain(argc, argv); #ifdef LAN_FEATURES - init_lan_features(); + init_lan_features(); #endif - moveloop(resuming); - nethack_exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + moveloop(resuming); + nethack_exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } #endif boolean -pcmain(argc,argv) +pcmain(argc, argv) int argc; char *argv[]; { - register int fd; register char *dir; #if defined(WIN32) - char* envp = NULL; - char* sptr = NULL; + char *envp = NULL; + char *sptr = NULL; char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ]; boolean save_getreturn_status = getreturn_enabled; #endif #ifdef NOCWD_ASSUMPTIONS char failbuf[BUFSZ]; #endif - boolean resuming = FALSE; /* assume new game */ + boolean resuming = FALSE; /* assume new game */ #ifdef _MSC_VER /* set these appropriately for VS debugging */ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); /* | _CRTDBG_MODE_FILE);*/ + _CrtSetReportMode(_CRT_ERROR, + _CRTDBG_MODE_DEBUG); /* | _CRTDBG_MODE_FILE);*/ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); - /*| _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);*/ - /* use STDERR by default - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ +/*| _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);*/ +/* use STDERR by default +_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); +_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ #endif #if defined(__BORLANDC__) && !defined(_WIN32) @@ -142,12 +141,12 @@ char *argv[]; #ifdef TOS long clock_time; - if (*argv[0]) { /* only a CLI can give us argv[0] */ + if (*argv[0]) { /* only a CLI can give us argv[0] */ hname = argv[0]; run_from_desktop = FALSE; } else #endif - hname = "NetHack"; /* used for syntax messages */ + hname = "NetHack"; /* used for syntax messages */ #ifndef WIN32 choose_windows(DEFAULT_WINDOW_SYS); @@ -159,73 +158,79 @@ char *argv[]; /* Save current directory and make sure it gets restored when * the game is exited. */ - if (getcwd(orgdir, sizeof orgdir) == (char *)0) + if (getcwd(orgdir, sizeof orgdir) == (char *) 0) error("NetHack: current directory path too long"); -# ifndef NO_SIGNAL - signal(SIGINT, (SIG_RET_TYPE) nethack_exit); /* restore original directory */ -# endif +#ifndef NO_SIGNAL + signal(SIGINT, + (SIG_RET_TYPE) nethack_exit); /* restore original directory */ +#endif #endif /* !AMIGA && !GNUDOS */ dir = nh_getenv("NETHACKDIR"); - if (dir == (char *)0) + if (dir == (char *) 0) dir = nh_getenv("HACKDIR"); #ifdef EXEPATH - if (dir == (char *)0) + if (dir == (char *) 0) dir = exepath(argv[0]); #endif - if (dir != (char *)0) { + if (dir != (char *) 0) { (void) strncpy(hackdir, dir, PATHLEN - 1); - hackdir[PATHLEN-1] = '\0'; + hackdir[PATHLEN - 1] = '\0'; #ifdef NOCWD_ASSUMPTIONS { int prefcnt; - fqn_prefix[0] = (char *)alloc(strlen(hackdir)+2); + fqn_prefix[0] = (char *) alloc(strlen(hackdir) + 2); Strcpy(fqn_prefix[0], hackdir); append_slash(fqn_prefix[0]); for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) - fqn_prefix[prefcnt] = fqn_prefix[0]; + fqn_prefix[prefcnt] = fqn_prefix[0]; -# if defined(WIN32) || defined(MSDOS) +#if defined(WIN32) || defined(MSDOS) /* sysconf should be searched for in this location */ envp = nh_getenv("COMMONPROGRAMFILES"); if (envp) { - if ((sptr = index(envp, ';')) != 0) *sptr = '\0'; + if ((sptr = index(envp, ';')) != 0) + *sptr = '\0'; if (strlen(envp) > 0) { - fqn_prefix[SYSCONFPREFIX] = (char *)alloc(strlen(envp) + 10); + fqn_prefix[SYSCONFPREFIX] = + (char *) alloc(strlen(envp) + 10); Strcpy(fqn_prefix[SYSCONFPREFIX], envp); append_slash(fqn_prefix[SYSCONFPREFIX]); Strcat(fqn_prefix[SYSCONFPREFIX], "NetHack\\"); } } - - /* user's home directory should default to this - unless overridden */ + + /* user's home directory should default to this - unless + * overridden */ envp = nh_getenv("USERPROFILE"); if (envp) { - if ((sptr = index(envp, ';')) != 0) *sptr = '\0'; + if ((sptr = index(envp, ';')) != 0) + *sptr = '\0'; if (strlen(envp) > 0) { - fqn_prefix[CONFIGPREFIX] = (char *)alloc(strlen(envp)+2); + fqn_prefix[CONFIGPREFIX] = + (char *) alloc(strlen(envp) + 2); Strcpy(fqn_prefix[CONFIGPREFIX], envp); append_slash(fqn_prefix[CONFIGPREFIX]); } } -# endif +#endif } #endif #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx (dir, 1); + chdirx(dir, 1); #endif } #ifdef AMIGA -# ifdef CHDIR +#ifdef CHDIR /* * If we're dealing with workbench, change the directory. Otherwise * we could get "Insert disk in drive 0" messages. (Must be done * before initoptions()).... */ - if(argc == 0) + if (argc == 0) chdirx(HACKDIR, 1); -# endif +#endif ami_wininit_data(); #endif #ifdef WIN32 @@ -238,8 +243,8 @@ char *argv[]; #ifdef NOCWD_ASSUMPTIONS if (!validate_prefix_locations(failbuf)) { raw_printf("Some invalid directory locations were specified:\n\t%s\n", - failbuf); - nethack_exit(EXIT_FAILURE); + failbuf); + nethack_exit(EXIT_FAILURE); } #endif @@ -253,114 +258,116 @@ char *argv[]; #else Strcpy(hackdir, HACKDIR); #endif - if(argc > 1) { + if (argc > 1) { if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { - /* avoid matching "-dec" for DECgraphics; since the man page - * says -d directory, hope nobody's using -desomething_else - */ - argc--; - argv++; - dir = argv[0]+2; - if(*dir == '=' || *dir == ':') dir++; - if(!*dir && argc > 1) { + /* avoid matching "-dec" for DECgraphics; since the man page + * says -d directory, hope nobody's using -desomething_else + */ argc--; argv++; - dir = argv[0]; - } - if(!*dir) - error("Flag -d must be followed by a directory name."); - Strcpy(hackdir, dir); + dir = argv[0] + 2; + if (*dir == '=' || *dir == ':') + dir++; + if (!*dir && argc > 1) { + argc--; + argv++; + dir = argv[0]; + } + if (!*dir) + error("Flag -d must be followed by a directory name."); + Strcpy(hackdir, dir); } if (argc > 1) { - - /* - * Now we know the directory containing 'record' and - * may do a prscore(). - */ - if (!strncmp(argv[1], "-s", 2)) { + /* + * Now we know the directory containing 'record' and + * may do a prscore(). + */ + if (!strncmp(argv[1], "-s", 2)) { #if defined(WIN32) - int sfd = (int)_fileno(stdout); - redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0; + int sfd = (int) _fileno(stdout); + redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0; - if (!redirect_stdout) { - raw_printf("-s is not supported for the Graphical Interface\n"); - nethack_exit(EXIT_SUCCESS); - } + if (!redirect_stdout) { + raw_printf( + "-s is not supported for the Graphical Interface\n"); + nethack_exit(EXIT_SUCCESS); + } #endif #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(hackdir,0); + chdirx(hackdir, 0); #endif #ifdef SYSCF - initoptions(); + initoptions(); #endif - prscore(argc, argv); - nethack_exit(EXIT_SUCCESS); - } + prscore(argc, argv); + nethack_exit(EXIT_SUCCESS); + } #ifdef MSWIN_GRAPHICS - if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */ - mswin_destroy_reg(); - nethack_exit(EXIT_SUCCESS); - } + if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */ + mswin_destroy_reg(); + nethack_exit(EXIT_SUCCESS); + } #endif - /* Don't initialize the window system just to print usage */ - if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) { - nhusage(); - nethack_exit(EXIT_SUCCESS); - } + /* Don't initialize the window system just to print usage */ + if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) { + nhusage(); + nethack_exit(EXIT_SUCCESS); + } } } #ifdef WIN32 getreturn_enabled = save_getreturn_status; #endif - /* - * It seems you really want to play. - */ +/* + * It seems you really want to play. + */ #ifdef TOS - if (comp_times((long)time(&clock_time))) + if (comp_times((long) time(&clock_time))) error("Your clock is incorrectly set!"); #endif if (!dlb_init()) { pline( - "%s\n%s\n%s\n%s\n\nNetHack was unable to open the required file \"%s\".%s", - copyright_banner_line(1), copyright_banner_line(2), - copyright_banner_line(3), copyright_banner_line(4), DLBFILE, + "%s\n%s\n%s\n%s\n\nNetHack was unable to open the required file " + "\"%s\".%s", + copyright_banner_line(1), copyright_banner_line(2), + copyright_banner_line(3), copyright_banner_line(4), DLBFILE, #ifdef WIN32 - "\nAre you perhaps trying to run NetHack within a zip utility?"); + "\nAre you perhaps trying to run NetHack within a zip utility?"); #else - ""); + ""); #endif error("dlb_init failure."); } - u.uhp = 1; /* prevent RIP on early quits */ - u.ux = 0; /* prevent flush_screen() */ + u.uhp = 1; /* prevent RIP on early quits */ + u.ux = 0; /* prevent flush_screen() */ - /* chdir shouldn't be called before this point to keep the - * code parallel to other ports. - */ +/* chdir shouldn't be called before this point to keep the + * code parallel to other ports. + */ #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(hackdir,1); + chdirx(hackdir, 1); #endif -#if defined(MSDOS) || defined (WIN32) +#if defined(MSDOS) || defined(WIN32) /* In 3.6.0, several ports process options before they init * the window port. This allows settings that impact window * ports to be specified or read from the sys or user config files. */ process_options(argc, argv); -# ifdef WIN32 -/* - if (!strncmpi(windowprocs.name, "mswin", 5)) - NHWinMainInit(); - else -*/ +#ifdef WIN32 + /* + if (!strncmpi(windowprocs.name, "mswin", 5)) + NHWinMainInit(); + else + */ if (!strncmpi(windowprocs.name, "tty", 3)) - nttty_open(1); -# endif + nttty_open(1); +#endif #endif #if defined(MSDOS) || defined(WIN32) @@ -374,27 +381,27 @@ char *argv[]; #endif #if defined(MSDOS) || defined(WIN32) - init_nhwindows(&argc,argv); + init_nhwindows(&argc, argv); #else - init_nhwindows(&argc,argv); + init_nhwindows(&argc, argv); process_options(argc, argv); #endif #ifdef WIN32 - toggle_mouse_support(); /* must come after process_options */ + toggle_mouse_support(); /* must come after process_options */ #endif #ifdef MFLOPPY set_lock_and_bones(); -# ifndef AMIGA +#ifndef AMIGA copybones(FROMPERM); -# endif +#endif #endif /* strip role,race,&c suffix; calls askname() if plname[] is empty or holds a generic user name like "player" or "games" */ plnamesuffix(); - set_playmode(); /* sets plname to "wizard" for wizard mode */ + set_playmode(); /* sets plname to "wizard" for wizard mode */ #if 0 /* unlike Unix where the game might be invoked with a script which forces a particular character name for each player @@ -402,57 +409,59 @@ char *argv[]; the character during role/race/&c selection */ iflags.renameallowed = TRUE; #else - /* until the getlock code is resolved, override askname()'s - setting of renameallowed; when False, player_selection() - won't resent renaming as an option */ - iflags.renameallowed = FALSE; + /* until the getlock code is resolved, override askname()'s + setting of renameallowed; when False, player_selection() + won't resent renaming as an option */ + iflags.renameallowed = FALSE; #endif #if defined(PC_LOCKING) - /* 3.3.0 added this to support detection of multiple games - * under the same plname on the same machine in a windowed - * or multitasking environment. - * - * That allows user confirmation prior to overwriting the - * level files of a game in progress. - * - * Also prevents an aborted game's level files from being - * overwritten without confirmation when a user starts up - * another game with the same player name. - */ -# if defined(WIN32) +/* 3.3.0 added this to support detection of multiple games + * under the same plname on the same machine in a windowed + * or multitasking environment. + * + * That allows user confirmation prior to overwriting the + * level files of a game in progress. + * + * Also prevents an aborted game's level files from being + * overwritten without confirmation when a user starts up + * another game with the same player name. + */ +#if defined(WIN32) /* Obtain the name of the logged on user and incorporate * it into the name. */ Sprintf(fnamebuf, "%s-%s", get_username(0), plname); - (void)fname_encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", - '%', fnamebuf, encodedfnamebuf, BUFSZ); - Sprintf(lock, "%s",encodedfnamebuf); + (void) fname_encode( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%', + fnamebuf, encodedfnamebuf, BUFSZ); + Sprintf(lock, "%s", encodedfnamebuf); /* regularize(lock); */ /* we encode now, rather than substitute */ -# else - Strcpy(lock,plname); +#else + Strcpy(lock, plname); regularize(lock); -# endif +#endif getlock(); -#else /* What follows is !PC_LOCKING */ -# ifdef AMIGA /* We'll put the bones & levels in the user specified directory -jhsa */ - Strcat(lock,plname); - Strcat(lock,".99"); -# else -# ifndef MFLOPPY +#else /* What follows is !PC_LOCKING */ +#ifdef AMIGA /* We'll put the bones & levels in the user specified directory \ + -jhsa */ + Strcat(lock, plname); + Strcat(lock, ".99"); +#else +#ifndef MFLOPPY /* I'm not sure what, if anything, is left here, but MFLOPPY has * conflicts with set_lock_and_bones() in files.c. */ - Strcpy(lock,plname); - Strcat(lock,".99"); - regularize(lock); /* is this necessary? */ - /* not compatible with full path a la AMIGA */ -# endif -# endif -#endif /* PC_LOCKING */ + Strcpy(lock, plname); + Strcat(lock, ".99"); + regularize(lock); /* is this necessary? */ + /* not compatible with full path a la AMIGA */ +#endif +#endif +#endif /* PC_LOCKING */ /* Set up level 0 file to keep the game state. */ - fd = create_levelfile(0, (char *)0); + fd = create_levelfile(0, (char *) 0); if (fd < 0) { raw_print("Cannot create lock file"); } else { @@ -462,7 +471,7 @@ char *argv[]; hackpid = 1; #endif write(fd, (genericptr_t) &hackpid, sizeof(hackpid)); - nhclose(fd); + nhclose(fd); } #ifdef MFLOPPY level_info[0].where = ACTIVE; @@ -479,34 +488,34 @@ char *argv[]; getreturn_enabled = TRUE; #endif - /* - * First, try to find and restore a save file for specified character. - * We'll return here if new game player_selection() renames the hero. - */ - attempt_restore: +/* + * First, try to find and restore a save file for specified character. + * We'll return here if new game player_selection() renames the hero. + */ +attempt_restore: if ((fd = restore_saved_game()) >= 0) { #ifndef NO_SIGNAL (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif #ifdef NEWS - if(iflags.news){ + if (iflags.news) { display_file(NEWS, FALSE); iflags.news = FALSE; } #endif pline("Restoring save file..."); - mark_synch(); /* flush output */ + mark_synch(); /* flush output */ if (dorecover(fd)) { - resuming = TRUE; /* not starting new game */ + resuming = TRUE; /* not starting new game */ if (discover) - You("are in non-scoring discovery mode."); + You("are in non-scoring discovery mode."); if (discover || wizard) { - if(yn("Do you want to keep the save file?") == 'n') - (void) delete_savefile(); - else { - nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); - } + if (yn("Do you want to keep the save file?") == 'n') + (void) delete_savefile(); + else { + nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); + } } } } @@ -519,14 +528,14 @@ char *argv[]; if (!iflags.renameinprogress) { player_selection(); if (iflags.renameinprogress) { - /* player has renamed the hero while selecting role; - discard current lock file and create another for - the new character name */ -#if 0 /* this needs to be reconciled with the getlock mess above... */ +/* player has renamed the hero while selecting role; + discard current lock file and create another for + the new character name */ +#if 0 /* this needs to be reconciled with the getlock mess above... */ delete_levelfile(0); /* remove empty lock file */ getlock(); #endif - goto attempt_restore; + goto attempt_restore; } } newgame(); @@ -550,14 +559,13 @@ char *argv[]; { int i; - /* * Process options. */ - while(argc > 1 && argv[1][0] == '-'){ + while (argc > 1 && argv[1][0] == '-') { argv++; argc--; - switch(argv[0][1]){ + switch (argv[0][1]) { case 'a': if (argv[0][2]) { if ((i = str2align(&argv[0][2])) >= 0) @@ -581,19 +589,19 @@ char *argv[]; break; #endif case 'u': - if(argv[0][2]) - (void) strncpy(plname, argv[0]+2, sizeof(plname)-1); - else if(argc > 1) { - argc--; - argv++; - (void) strncpy(plname, argv[0], sizeof(plname)-1); + if (argv[0][2]) + (void) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); + else if (argc > 1) { + argc--; + argv++; + (void) strncpy(plname, argv[0], sizeof(plname) - 1); } else raw_print("Player name expected after -u"); break; #ifndef AMIGA case 'I': case 'i': - if (!strncmpi(argv[0]+1, "IBM", 3)) { + if (!strncmpi(argv[0] + 1, "IBM", 3)) { load_symset("IBMGraphics", PRIMARY); load_symset("RogueIBM", ROGUESET); switch_symbols(TRUE); @@ -601,7 +609,7 @@ char *argv[]; break; /* case 'D': */ case 'd': - if (!strncmpi(argv[0]+1, "DEC", 3)) { + if (!strncmpi(argv[0] + 1, "DEC", 3)) { load_symset("DECGraphics", PRIMARY); switch_symbols(TRUE); } @@ -641,16 +649,16 @@ char *argv[]; } break; #ifdef MFLOPPY -# ifndef AMIGA +#ifndef AMIGA /* Player doesn't want to use a RAM disk */ case 'R': ramdisk = FALSE; break; -# endif +#endif #endif #ifdef AMIGA - /* interlaced and non-interlaced screens */ + /* interlaced and non-interlaced screens */ case 'L': bigscreen = 1; break; @@ -660,14 +668,14 @@ char *argv[]; #endif #ifdef WIN32 case 'w': /* windowtype */ - if (strncmpi(&argv[0][2],"tty", 3)) { + if (strncmpi(&argv[0][2], "tty", 3)) { nttty_open(1); } -/* - else { - NHWinMainInit(); - } -*/ + /* + else { + NHWinMainInit(); + } + */ choose_windows(&argv[0][2]); break; #endif @@ -678,8 +686,9 @@ char *argv[]; if ((i = str2role(&argv[0][1])) >= 0) { flags.initrole = i; break; - } else raw_printf("\nUnknown switch: %s", argv[0]); - /* FALL THROUGH */ + } else + raw_printf("\nUnknown switch: %s", argv[0]); + /* FALL THROUGH */ case '?': nhusage(); nethack_exit(EXIT_SUCCESS); @@ -687,7 +696,7 @@ char *argv[]; } } -STATIC_OVL void +STATIC_OVL void nhusage() { char buf1[BUFSZ], buf2[BUFSZ], *bufptr; @@ -695,18 +704,20 @@ nhusage() buf1[0] = '\0'; bufptr = buf1; -#define ADD_USAGE(s) if ((strlen(buf1) + strlen(s)) < (BUFSZ - 1)) Strcat(bufptr, s); +#define ADD_USAGE(s) \ + if ((strlen(buf1) + strlen(s)) < (BUFSZ - 1)) \ + Strcat(bufptr, s); /* -role still works for those cases which aren't already taken, but * is deprecated and will not be listed here. */ - (void) Sprintf(buf2, -"\nUsage:\n%s [-d dir] -s [-r race] [-p profession] [maxrank] [name]...\n or", - hname); + (void) Sprintf(buf2, "\nUsage:\n%s [-d dir] -s [-r race] [-p profession] " + "[maxrank] [name]...\n or", + hname); ADD_USAGE(buf2); - (void) Sprintf(buf2, - "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]", + (void) Sprintf( + buf2, "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]", hname); ADD_USAGE(buf2); #ifdef NEWS @@ -716,17 +727,17 @@ nhusage() ADD_USAGE(" [-I] [-i] [-d]"); #endif #ifdef MFLOPPY -# ifndef AMIGA +#ifndef AMIGA ADD_USAGE(" [-R]"); -# endif +#endif #endif #ifdef AMIGA ADD_USAGE(" [-[lL]]"); #endif if (!iflags.window_inited) - raw_printf("%s\n",buf1); + raw_printf("%s\n", buf1); else - (void) printf("%s\n",buf1); + (void) printf("%s\n", buf1); #undef ADD_USAGE } @@ -736,57 +747,58 @@ chdirx(dir, wr) char *dir; boolean wr; { -# ifdef AMIGA +#ifdef AMIGA static char thisdir[] = ""; -# else +#else static char thisdir[] = "."; -# endif - if(dir && chdir(dir) < 0) { +#endif + if (dir && chdir(dir) < 0) { error("Cannot chdir to %s.", dir); } -# ifndef AMIGA +#ifndef AMIGA /* Change the default drive as well. */ chdrive(dir); -# endif +#endif /* warn the player if we can't write the record file */ /* perhaps we should also test whether . is writable */ /* unfortunately the access system-call is worthless */ - if (wr) check_recordfile(dir ? dir : thisdir); + if (wr) + check_recordfile(dir ? dir : thisdir); } #endif /* CHDIR */ #ifdef PORT_HELP -# if defined(MSDOS) || defined(WIN32) +#if defined(MSDOS) || defined(WIN32) void port_help() { /* display port specific help file */ - display_file( PORT_HELP, 1 ); + display_file(PORT_HELP, 1); } -# endif /* MSDOS || WIN32 */ +#endif /* MSDOS || WIN32 */ #endif /* PORT_HELP */ /* validate wizard mode if player has requested access to it */ boolean authorize_wizard_mode() { - if (!strcmp(plname, WIZARD_NAME)) return TRUE; + if (!strcmp(plname, WIZARD_NAME)) + return TRUE; return FALSE; } #ifdef EXEPATH -# ifdef __DJGPP__ +#ifdef __DJGPP__ #define PATH_SEPARATOR '/' -# else +#else #define PATH_SEPARATOR '\\' -# endif - +#endif #ifdef WIN32 -static char exenamebuf[PATHLEN]; +static char exenamebuf[PATHLEN]; char * exename() @@ -794,17 +806,18 @@ exename() int bsize = PATHLEN; char *tmp = exenamebuf, *tmp2; -# ifdef UNICODE +#ifdef UNICODE { TCHAR wbuf[PATHLEN * 4]; - GetModuleFileName((HANDLE)0, wbuf, PATHLEN * 4); + GetModuleFileName((HANDLE) 0, wbuf, PATHLEN * 4); WideCharToMultiByte(CP_ACP, 0, wbuf, -1, tmp, bsize, NULL, NULL); } -# else - *(tmp + GetModuleFileName((HANDLE)0, tmp, bsize)) = '\0'; -# endif +#else + *(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0'; +#endif tmp2 = strrchr(tmp, PATH_SEPARATOR); - if (tmp2) *tmp2 = '\0'; + if (tmp2) + *tmp2 = '\0'; tmp2++; return tmp2; } @@ -813,30 +826,33 @@ exename() #define EXEPATHBUFSZ 256 char exepathbuf[EXEPATHBUFSZ]; -char *exepath(str) +char * +exepath(str) char *str; { char *tmp, *tmp2; int bsize; - if (!str) return (char *)0; + if (!str) + return (char *) 0; bsize = EXEPATHBUFSZ; tmp = exepathbuf; -# ifndef WIN32 - Strcpy (tmp, str); -# else - #ifdef UNICODE +#ifndef WIN32 + Strcpy(tmp, str); +#else +#ifdef UNICODE { TCHAR wbuf[BUFSZ]; - GetModuleFileName((HANDLE)0, wbuf, BUFSZ); + GetModuleFileName((HANDLE) 0, wbuf, BUFSZ); WideCharToMultiByte(CP_ACP, 0, wbuf, -1, tmp, bsize, NULL, NULL); } - #else - *(tmp + GetModuleFileName((HANDLE)0, tmp, bsize)) = '\0'; - #endif -# endif +#else + *(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0'; +#endif +#endif tmp2 = strrchr(tmp, PATH_SEPARATOR); - if (tmp2) *tmp2 = '\0'; + if (tmp2) + *tmp2 = '\0'; return tmp; } #endif /* EXEPATH */ diff --git a/sys/share/pcsys.c b/sys/share/pcsys.c index c1da279ac..45f9fb6ff 100644 --- a/sys/share/pcsys.c +++ b/sys/share/pcsys.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pcsys.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 pcsys.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */ /* NetHack 3.6 pcsys.c $Date: 2012/01/22 06:33:47 $ $Revision: 1.18 $ */ /* SCCS Id: @(#)pcsys.c 3.5 2002/01/22 */ /* NetHack may be freely redistributed. See license for details. */ @@ -13,12 +13,12 @@ #include #include -#if !defined(MSDOS) && !defined(WIN_CE) /* already done */ +#if !defined(MSDOS) && !defined(WIN_CE) /* already done */ #include #endif #ifdef __GO32__ -#define P_WAIT 0 -#define P_NOWAIT 1 +#define P_WAIT 0 +#define P_NOWAIT 1 #endif #ifdef TOS #include @@ -29,33 +29,31 @@ #define filesize filesize_nh #endif - #if defined(MICRO) || defined(WIN32) || defined(OS2) -void FDECL(nethack_exit,(int)); +void FDECL(nethack_exit, (int)); #else #define nethack_exit exit #endif STATIC_DCL void NDECL(msexit); - #ifdef MOVERLAY -extern void __far __cdecl _movepause( void ); -extern void __far __cdecl _moveresume( void ); +extern void __far __cdecl _movepause(void); +extern void __far __cdecl _moveresume(void); extern unsigned short __far __cdecl _movefpause; extern unsigned short __far __cdecl _movefpaused; -#define __MOVE_PAUSE_DISK 2 /* Represents the executable file */ -#define __MOVE_PAUSE_CACHE 4 /* Represents the cache memory */ -#endif /* MOVERLAY */ +#define __MOVE_PAUSE_DISK 2 /* Represents the executable file */ +#define __MOVE_PAUSE_CACHE 4 /* Represents the cache memory */ +#endif /* MOVERLAY */ #ifdef MFLOPPY STATIC_DCL boolean NDECL(record_exists); -# ifndef TOS +#ifndef TOS STATIC_DCL boolean NDECL(comspec_exists); -# endif +#endif #endif #ifdef WIN32 -extern int GUILaunched; /* from nttty.c */ +extern int GUILaunched; /* from nttty.c */ #endif #if defined(MICRO) || defined(WIN32) @@ -63,98 +61,100 @@ extern int GUILaunched; /* from nttty.c */ void flushout() { - (void) fflush(stdout); - return; + (void) fflush(stdout); + return; } static const char *COMSPEC = -# ifdef TOS -"SHELL"; -# else -"COMSPEC"; -# endif +#ifdef TOS + "SHELL"; +#else + "COMSPEC"; +#endif #define getcomspec() nh_getenv(COMSPEC) -# ifdef SHELL +#ifdef SHELL int dosh() { - extern char orgdir[]; - char *comspec; -# ifndef __GO32__ - int spawnstat; -# endif -#if defined(MSDOS) && defined(NO_TERMS) - int grmode = iflags.grmode; + extern char orgdir[]; + char *comspec; +#ifndef __GO32__ + int spawnstat; +#endif +#if defined(MSDOS) && defined(NO_TERMS) + int grmode = iflags.grmode; +#endif + if ((comspec = getcomspec())) { +#ifndef TOS /* TOS has a variety of shells */ + suspend_nhwindows( + "To return to NetHack, enter \"exit\" at the system prompt.\n"); +#else +#if defined(MSDOS) && defined(NO_TERMS) + grmode = iflags.grmode; +#endif + suspend_nhwindows((char *) 0); +#endif /* TOS */ +#ifndef NOCWD_ASSUMPTIONS + chdirx(orgdir, 0); +#endif +#ifdef __GO32__ + if (system(comspec) < 0) { /* wsu@eecs.umich.edu */ +#else +#ifdef MOVERLAY + /* Free the cache memory used by overlays, close .exe */ + _movefpause |= __MOVE_PAUSE_DISK; + _movefpause |= __MOVE_PAUSE_CACHE; + _movepause(); +#endif + spawnstat = spawnl(P_WAIT, comspec, comspec, (char *) 0); +#ifdef MOVERLAY + _moveresume(); #endif - if ((comspec = getcomspec())) { -# ifndef TOS /* TOS has a variety of shells */ - suspend_nhwindows("To return to NetHack, enter \"exit\" at the system prompt.\n"); -# else -# if defined(MSDOS) && defined(NO_TERMS) - grmode = iflags.grmode; -# endif - suspend_nhwindows((char *)0); -# endif /* TOS */ -# ifndef NOCWD_ASSUMPTIONS - chdirx(orgdir, 0); -# endif -# ifdef __GO32__ - if (system(comspec) < 0) { /* wsu@eecs.umich.edu */ -# else -# ifdef MOVERLAY - /* Free the cache memory used by overlays, close .exe */ - _movefpause |= __MOVE_PAUSE_DISK; - _movefpause |= __MOVE_PAUSE_CACHE; - _movepause(); -# endif - spawnstat = spawnl(P_WAIT, comspec, comspec, (char *)0); -# ifdef MOVERLAY - _moveresume(); -# endif - if ( spawnstat < 0) { -# endif - raw_printf("Can't spawn \"%s\"!", comspec); - getreturn("to continue"); - } -# ifdef TOS -/* Some shells (e.g. Gulam) turn the cursor off when they exit */ - if (iflags.BIOS) - (void)Cursconf(1, -1); -# endif -# ifndef NOCWD_ASSUMPTIONS - chdirx(hackdir, 0); -# endif - get_scr_size(); /* maybe the screen mode changed (TH) */ -# if defined(MSDOS) && defined(NO_TERMS) - if (grmode) gr_init(); -# endif - resume_nhwindows(); - } else - pline("Can't find %s.",COMSPEC); - return 0; + if (spawnstat < 0) { +#endif + raw_printf("Can't spawn \"%s\"!", comspec); + getreturn("to continue"); + } +#ifdef TOS + /* Some shells (e.g. Gulam) turn the cursor off when they exit */ + if (iflags.BIOS) + (void) Cursconf(1, -1); +#endif +#ifndef NOCWD_ASSUMPTIONS + chdirx(hackdir, 0); +#endif + get_scr_size(); /* maybe the screen mode changed (TH) */ +#if defined(MSDOS) && defined(NO_TERMS) + if (grmode) + gr_init(); +#endif + resume_nhwindows(); + } else + pline("Can't find %s.", COMSPEC); + return 0; } -# endif /* SHELL */ +#endif /* SHELL */ -# ifdef MFLOPPY +#ifdef MFLOPPY void eraseall(path, files) const char *path, *files; { - char buf[PATHLEN]; - char *foundfile; + char buf[PATHLEN]; + char *foundfile; - foundfile = foundfile_buffer(); - Sprintf(buf, "%s%s", path, files); - if (findfirst(buf)) - do { - Sprintf(buf, "%s%s", path, foundfile); - (void) unlink(buf); - } while (findnext()); - return; + foundfile = foundfile_buffer(); + Sprintf(buf, "%s%s", path, files); + if (findfirst(buf)) + do { + Sprintf(buf, "%s%s", path, foundfile); + (void) unlink(buf); + } while (findnext()); + return; } /* @@ -164,210 +164,212 @@ void copybones(mode) int mode; { - char from[PATHLEN], to[PATHLEN], last[13]; - char *frompath, *topath; - char *foundfile; -# ifndef TOS - int status; - char copy[8], *comspec; -# endif + char from[PATHLEN], to[PATHLEN], last[13]; + char *frompath, *topath; + char *foundfile; +#ifndef TOS + int status; + char copy[8], *comspec; +#endif - if (!ramdisk) - return; + if (!ramdisk) + return; - /* Find the name of the last file to be transferred - */ - frompath = (mode != TOPERM) ? permbones : levels; - foundfile = foundfile_buffer(); - last[0] = '\0'; - Sprintf(from, "%s%s", frompath, allbones); - topath = (mode == TOPERM) ? permbones : levels; -# ifdef TOS - eraseall(topath, allbones); -# endif - if (findfirst(from)) - do { -# ifdef TOS - Sprintf(from, "%s%s", frompath, foundfile); - Sprintf(to, "%s%s", topath, foundfile); - if (_copyfile(from, to)) - goto error_copying; -# endif - Strcpy(last, foundfile); - } while (findnext()); -# ifdef TOS - else - return; -# else - if (last[0]) { - Sprintf(copy, "%cC copy",switchar()); + /* Find the name of the last file to be transferred + */ + frompath = (mode != TOPERM) ? permbones : levels; + foundfile = foundfile_buffer(); + last[0] = '\0'; + Sprintf(from, "%s%s", frompath, allbones); + topath = (mode == TOPERM) ? permbones : levels; +#ifdef TOS + eraseall(topath, allbones); +#endif + if (findfirst(from)) + do { +#ifdef TOS + Sprintf(from, "%s%s", frompath, foundfile); + Sprintf(to, "%s%s", topath, foundfile); + if (_copyfile(from, to)) + goto error_copying; +#endif + Strcpy(last, foundfile); + } while (findnext()); +#ifdef TOS + else + return; +#else + if (last[0]) { + Sprintf(copy, "%cC copy", switchar()); - /* Remove any bones files in `to' directory. - */ - eraseall(topath, allbones); + /* Remove any bones files in `to' directory. + */ + eraseall(topath, allbones); - /* Copy `from' to `to' */ - Sprintf(to, "%s%s", topath, allbones); - comspec = getcomspec(); - status =spawnl(P_WAIT, comspec, comspec, copy, from, - to, "> nul", (char *)0); - } else - return; -# endif /* TOS */ + /* Copy `from' to `to' */ + Sprintf(to, "%s%s", topath, allbones); + comspec = getcomspec(); + status = spawnl(P_WAIT, comspec, comspec, copy, from, to, "> nul", + (char *) 0); + } else + return; +#endif /* TOS */ - /* See if the last file got there. If so, remove the ramdisk bones - * files. - */ - Sprintf(to, "%s%s", topath, last); - if (findfirst(to)) { - if (mode == TOPERM) - eraseall(frompath, allbones); - return; - } + /* See if the last file got there. If so, remove the ramdisk bones + * files. + */ + Sprintf(to, "%s%s", topath, last); + if (findfirst(to)) { + if (mode == TOPERM) + eraseall(frompath, allbones); + return; + } -# ifdef TOS +#ifdef TOS error_copying: -# endif - /* Last file didn't get there. - */ - Sprintf(to, "%s%s", topath, allbones); - msmsg("Can't copy \"%s\" to \"%s\" -- ", from, to); -# ifndef TOS - if (status < 0) - msmsg("can't spawn \"%s\"!", comspec); - else -# endif - msmsg((freediskspace(topath) < filesize(from)) ? - "insufficient disk space." : "bad path(s)?"); - if (mode == TOPERM) { - msmsg("Bones will be left in \"%s\"\n", - *levels ? levels : hackdir); - } else { - /* Remove all bones files on the RAMdisk */ - eraseall(levels, allbones); - playwoRAMdisk(); - } - return; +#endif + /* Last file didn't get there. + */ + Sprintf(to, "%s%s", topath, allbones); + msmsg("Can't copy \"%s\" to \"%s\" -- ", from, to); +#ifndef TOS + if (status < 0) + msmsg("can't spawn \"%s\"!", comspec); + else +#endif + msmsg((freediskspace(topath) < filesize(from)) + ? "insufficient disk space." + : "bad path(s)?"); + if (mode == TOPERM) { + msmsg("Bones will be left in \"%s\"\n", *levels ? levels : hackdir); + } else { + /* Remove all bones files on the RAMdisk */ + eraseall(levels, allbones); + playwoRAMdisk(); + } + return; } void playwoRAMdisk() { - int c; + int c; - msmsg("Do you wish to play without a RAMdisk? [yn] (n)"); + msmsg("Do you wish to play without a RAMdisk? [yn] (n)"); - /* Set ramdisk false *before* exit-ing (because msexit calls - * copybones) - */ - ramdisk = FALSE; - c = tgetch(); if (c == 'Y') c = 'y'; - if (c != 'y') { - settty("Be seeing you...\n"); - nethack_exit(EXIT_SUCCESS); - } - set_lock_and_bones(); - return; + /* Set ramdisk false *before* exit-ing (because msexit calls + * copybones) + */ + ramdisk = FALSE; + c = tgetch(); + if (c == 'Y') + c = 'y'; + if (c != 'y') { + settty("Be seeing you...\n"); + nethack_exit(EXIT_SUCCESS); + } + set_lock_and_bones(); + return; } int saveDiskPrompt(start) int start; { - char buf[BUFSIZ], *bp; - char qbuf[QBUFSZ]; + char buf[BUFSIZ], *bp; + char qbuf[QBUFSZ]; - int fd; + int fd; - if (sysflags.asksavedisk) { - /* Don't prompt if you can find the save file */ - if ((fd = open_savefile()) >= 0) { - (void) nhclose(fd); - return 1; - } - clear_nhwindow(WIN_MESSAGE); - pline("If save file is on a save disk, insert that disk now."); - mark_synch(); - Sprintf(qbuf,"File name (default \"%s\"%s) ?", SAVEF, - start ? "" : ", cancels save"); - getlin(qbuf, buf); - clear_nhwindow(WIN_MESSAGE); - if (!start && *buf == '\033') - return 0; + if (sysflags.asksavedisk) { + /* Don't prompt if you can find the save file */ + if ((fd = open_savefile()) >= 0) { + (void) nhclose(fd); + return 1; + } + clear_nhwindow(WIN_MESSAGE); + pline("If save file is on a save disk, insert that disk now."); + mark_synch(); + Sprintf(qbuf, "File name (default \"%s\"%s) ?", SAVEF, + start ? "" : ", cancels save"); + getlin(qbuf, buf); + clear_nhwindow(WIN_MESSAGE); + if (!start && *buf == '\033') + return 0; - /* Strip any whitespace. Also, if nothing was entered except - * whitespace, do not change the value of SAVEF. - */ - for (bp = buf; *bp; bp++) - if (!isspace(*bp)) { - strncpy(SAVEF, bp, PATHLEN); - break; - } - } - return 1; + /* Strip any whitespace. Also, if nothing was entered except + * whitespace, do not change the value of SAVEF. + */ + for (bp = buf; *bp; bp++) + if (!isspace(*bp)) { + strncpy(SAVEF, bp, PATHLEN); + break; + } + } + return 1; } /* Return 1 if the record file was found */ STATIC_OVL boolean record_exists() { - FILE *fp; + FILE *fp; - fp = fopen_datafile(RECORD, "r", TRUE); - if (fp) { - fclose(fp); - return TRUE; - } - return FALSE; + fp = fopen_datafile(RECORD, "r", TRUE); + if (fp) { + fclose(fp); + return TRUE; + } + return FALSE; } #endif /* MFLOPPY */ -# ifdef TOS +#ifdef TOS #define comspec_exists() 1 -# else -# ifdef MFLOPPY +#else +#ifdef MFLOPPY /* Return 1 if the comspec was found */ STATIC_OVL boolean comspec_exists() { - int fd; - char *comspec; + int fd; + char *comspec; - if ((comspec = getcomspec())) - if ((fd = open(comspec, O_RDONLY)) >= 0) { - (void) nhclose(fd); - return TRUE; - } - return FALSE; + if ((comspec = getcomspec())) + if ((fd = open(comspec, O_RDONLY)) >= 0) { + (void) nhclose(fd); + return TRUE; + } + return FALSE; } -# endif /* MFLOPPY */ -# endif +#endif /* MFLOPPY */ +#endif - -# ifdef MFLOPPY +#ifdef MFLOPPY /* Prompt for game disk, then check for record file. */ void gameDiskPrompt() { - if (sysflags.asksavedisk) { - if (record_exists() && comspec_exists()) - return; - (void) putchar('\n'); - getreturn("when the game disk has been inserted"); - } - if (comspec_exists() && record_exists()) - return; + if (sysflags.asksavedisk) { + if (record_exists() && comspec_exists()) + return; + (void) putchar('\n'); + getreturn("when the game disk has been inserted"); + } + if (comspec_exists() && record_exists()) + return; - if (!comspec_exists()) - msmsg("\n\nWARNING: can't find command processor \"%s\"!\n", getcomspec()); - if (!record_exists()) - msmsg("\n\nWARNING: can't find record file \"%s\"!\n", RECORD); - msmsg("If the game disk is not in, insert it now.\n"); - getreturn("to continue"); - return; + if (!comspec_exists()) + msmsg("\n\nWARNING: can't find command processor \"%s\"!\n", + getcomspec()); + if (!record_exists()) + msmsg("\n\nWARNING: can't find record file \"%s\"!\n", RECORD); + msmsg("If the game disk is not in, insert it now.\n"); + getreturn("to continue"); + return; } -# endif /* MFLOPPY */ +#endif /* MFLOPPY */ #endif /* MICRO */ /* @@ -378,16 +380,16 @@ void append_slash(name) char *name; { - char *ptr; + char *ptr; - if (!*name) - return; - ptr = name + (strlen(name) - 1); - if (*ptr != '\\' && *ptr != '/' && *ptr != ':') { - *++ptr = '\\'; - *++ptr = '\0'; - } - return; + if (!*name) + return; + ptr = name + (strlen(name) - 1); + if (*ptr != '\\' && *ptr != '/' && *ptr != ':') { + *++ptr = '\\'; + *++ptr = '\0'; + } + return; } #ifdef WIN32 @@ -400,30 +402,32 @@ getreturn(str) const char *str; { #ifdef WIN32 - if (!getreturn_enabled) return; + if (!getreturn_enabled) + return; #endif #ifdef TOS - msmsg("Hit %s.", str); + msmsg("Hit %s.", str); #else - msmsg("Hit %s.", str); + msmsg("Hit %s.", str); #endif - while (pgetchar() != '\n') ; - return; + while (pgetchar() != '\n') + ; + return; } #ifndef WIN32 -void -msmsg VA_DECL(const char *, fmt) - VA_START(fmt); - VA_INIT(fmt, const char *); -# if defined(MSDOS) && defined(NO_TERMS) - if (iflags.grmode) - gr_finish(); -# endif - Vprintf(fmt, VA_ARGS); - flushout(); - VA_END(); - return; +void msmsg +VA_DECL(const char *, fmt) + VA_START(fmt); + VA_INIT(fmt, const char *); +#if defined(MSDOS) && defined(NO_TERMS) + if (iflags.grmode) + gr_finish(); +#endif + Vprintf(fmt, VA_ARGS); + flushout(); + VA_END(); + return; } #endif @@ -431,11 +435,11 @@ msmsg VA_DECL(const char *, fmt) * Follow the PATH, trying to fopen the file. */ #ifdef TOS -# ifdef __MINT__ +#ifdef __MINT__ #define PATHSEP ':' -# else +#else #define PATHSEP ',' -# endif +#endif #else #define PATHSEP ';' #endif @@ -444,101 +448,105 @@ FILE * fopenp(name, mode) const char *name, *mode; { - char buf[BUFSIZ], *bp, *pp, lastch = 0; - FILE *fp; + char buf[BUFSIZ], *bp, *pp, lastch = 0; + FILE *fp; - /* Try the default directory first. Then look along PATH. - */ - (void) strncpy(buf, name, BUFSIZ - 1); - buf[BUFSIZ-1] = '\0'; - if ((fp = fopen(buf, mode))) - return fp; - else { - int ccnt = 0; - pp = getenv("PATH"); - while (pp && *pp) { - bp = buf; - while (*pp && *pp != PATHSEP) { - lastch = *bp++ = *pp++; - ccnt++; - } - if (lastch != '\\' && lastch != '/') { - *bp++ = '\\'; - ccnt++; - } - (void) strncpy(bp, name, (BUFSIZ - ccnt) - 2); - bp[BUFSIZ - ccnt - 1] = '\0'; - if ((fp = fopen(buf, mode))) - return fp; - if (*pp) - pp++; - } - } + /* Try the default directory first. Then look along PATH. + */ + (void) strncpy(buf, name, BUFSIZ - 1); + buf[BUFSIZ - 1] = '\0'; + if ((fp = fopen(buf, mode))) + return fp; + else { + int ccnt = 0; + pp = getenv("PATH"); + while (pp && *pp) { + bp = buf; + while (*pp && *pp != PATHSEP) { + lastch = *bp++ = *pp++; + ccnt++; + } + if (lastch != '\\' && lastch != '/') { + *bp++ = '\\'; + ccnt++; + } + (void) strncpy(bp, name, (BUFSIZ - ccnt) - 2); + bp[BUFSIZ - ccnt - 1] = '\0'; + if ((fp = fopen(buf, mode))) + return fp; + if (*pp) + pp++; + } + } #ifdef OS2_CODEVIEW /* one more try for hackdir */ - (void) strncpy(buf, hackdir, BUFSZ); - buf[BUFSZ-1] = '\0'; - if ((strlen(name) + 1 + strlen(buf)) < BUFSZ - 1) { - append_slash(buf); - Strcat(buf,name); - } else - impossible("fopenp() buffer too small for complete filename!"); - if(fp = fopen(buf,mode)) - return fp; + (void) strncpy(buf, hackdir, BUFSZ); + buf[BUFSZ - 1] = '\0'; + if ((strlen(name) + 1 + strlen(buf)) < BUFSZ - 1) { + append_slash(buf); + Strcat(buf, name); + } else + impossible("fopenp() buffer too small for complete filename!"); + if (fp = fopen(buf, mode)) + return fp; #endif - return (FILE *)0; + return (FILE *) 0; } #if defined(MICRO) || defined(WIN32) || defined(OS2) -void nethack_exit(code) +void +nethack_exit(code) int code; { - msexit(); - exit(code); + msexit(); + exit(code); } /* Chdir back to original directory */ #ifdef TOS -extern boolean run_from_desktop; /* set in pcmain.c */ +extern boolean run_from_desktop; /* set in pcmain.c */ #endif -STATIC_OVL void msexit() +STATIC_OVL void +msexit() { #ifdef CHDIR - extern char orgdir[]; + extern char orgdir[]; #endif - flushout(); + flushout(); #ifndef TOS -# ifndef WIN32 - enable_ctrlP(); /* in case this wasn't done */ -# endif +#ifndef WIN32 + enable_ctrlP(); /* in case this wasn't done */ +#endif #endif #ifdef MFLOPPY - if (ramdisk) copybones(TOPERM); + if (ramdisk) + copybones(TOPERM); #endif #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdir(orgdir); /* chdir, not chdirx */ - chdrive(orgdir); + chdir(orgdir); /* chdir, not chdirx */ + chdrive(orgdir); #endif #ifdef TOS - if (run_from_desktop) - getreturn("to continue"); /* so the user can read the score list */ -# ifdef TEXTCOLOR - if (colors_changed) - restore_colors(); -# endif + if (run_from_desktop) + getreturn("to continue"); /* so the user can read the score list */ +#ifdef TEXTCOLOR + if (colors_changed) + restore_colors(); +#endif #endif #ifdef WIN32 - /* Only if we started from the GUI, not the command prompt, - * we need to get one last return, so the score board does - * not vanish instantly after being created. - * GUILaunched is defined and set in nttty.c. - */ - synch_cursor(); - if (GUILaunched) getreturn("to end"); - synch_cursor(); + /* Only if we started from the GUI, not the command prompt, + * we need to get one last return, so the score board does + * not vanish instantly after being created. + * GUILaunched is defined and set in nttty.c. + */ + synch_cursor(); + if (GUILaunched) + getreturn("to end"); + synch_cursor(); #endif - return; + return; } #endif /* MICRO || WIN32 || OS2 */ diff --git a/sys/share/pctty.c b/sys/share/pctty.c index 3f689e163..34982d840 100644 --- a/sys/share/pctty.c +++ b/sys/share/pctty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pctty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 pctty.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 pctty.c $Date: 2009/05/06 10:50:30 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)pctty.c 3.5 1990/22/02 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -6,7 +6,8 @@ /* tty.c - (PC) version */ -#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */ +#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers \ + */ #include "hack.h" #include "wintty.h" @@ -18,15 +19,16 @@ char erase_char, kill_char; * Called by startup() in termcap.c and after returning from ! or ^Z */ void -gettty(){ - erase_char = '\b'; - kill_char = 21; /* cntl-U */ - iflags.cbreak = TRUE; -#if !defined(TOS) - disable_ctrlP(); /* turn off ^P processing */ +gettty() +{ + erase_char = '\b'; + kill_char = 21; /* cntl-U */ + iflags.cbreak = TRUE; +#if !defined(TOS) + disable_ctrlP(); /* turn off ^P processing */ #endif #if defined(MSDOS) && defined(NO_TERMS) - gr_init(); + gr_init(); #endif } @@ -36,21 +38,21 @@ settty(s) const char *s; { #if defined(MSDOS) && defined(NO_TERMS) - gr_finish(); + gr_finish(); #endif - end_screen(); - if(s) raw_print(s); + end_screen(); + if (s) + raw_print(s); #if !defined(TOS) - enable_ctrlP(); /* turn on ^P processing */ + enable_ctrlP(); /* turn on ^P processing */ #endif - } /* called by init_nhwindows() and resume_nhwindows() */ void setftty() { - start_screen(); + start_screen(); } #if defined(TIMED_DELAY) && defined(_MSC_VER) @@ -58,30 +60,31 @@ void msleep(mseconds) unsigned mseconds; { - /* now uses clock() which is ANSI C */ - clock_t goal; + /* now uses clock() which is ANSI C */ + clock_t goal; - goal = mseconds + clock(); - while ( goal > clock()) { - /* do nothing */ - } + goal = mseconds + clock(); + while (goal > clock()) { + /* do nothing */ + } } #endif /* fatal error */ /*VARARGS1*/ -void -error VA_DECL(const char *,s) - VA_START(s); - VA_INIT(s, const char *); - /* error() may get called before tty is initialized */ - if (iflags.window_inited) end_screen(); - putchar('\n'); - Vprintf(s,VA_ARGS); - putchar('\n'); - VA_END(); - exit(EXIT_FAILURE); +void error +VA_DECL(const char *, s) + VA_START(s); + VA_INIT(s, const char *); + /* error() may get called before tty is initialized */ + if (iflags.window_inited) + end_screen(); + putchar('\n'); + Vprintf(s, VA_ARGS); + putchar('\n'); + VA_END(); + exit(EXIT_FAILURE); } /*pctty.c*/ diff --git a/sys/share/pcunix.c b/sys/share/pcunix.c index 9ed51454c..ea89b72a0 100644 --- a/sys/share/pcunix.c +++ b/sys/share/pcunix.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pcunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 pcunix.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */ /* NetHack 3.6 pcunix.c $Date: 2009/05/06 10:50:30 $ $Revision: 1.27 $ */ /* SCCS Id: @(#)pcunix.c 3.5 1994/11/07 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -9,16 +9,16 @@ #include "hack.h" #include "wintty.h" -#include +#include #if defined(WIN32) || defined(MSDOS) -#include +#include #endif #if defined(WIN32) || defined(MSDOS) extern char orgdir[]; -# ifdef WIN32 +#ifdef WIN32 extern void NDECL(backsp); -# endif +#endif extern void NDECL(clear_screen); #endif @@ -26,9 +26,9 @@ extern void NDECL(clear_screen); static struct stat buf; #endif -# ifdef WANT_GETHDATE +#ifdef WANT_GETHDATE static struct stat hbuf; -# endif +#endif #ifdef PC_LOCKING static int NDECL(eraseoldlocks); @@ -39,7 +39,7 @@ int uptodate(fd) int fd; { -# ifdef WANT_GETHDATE +#ifdef WANT_GETHDATE if(fstat(fd, &buf)) { pline("Cannot get status of saved level? "); return(0); @@ -48,8 +48,8 @@ int fd; pline("Saved level is out of date. "); return(0); } -# else -# if (defined(MICRO) || defined(WIN32)) && !defined(NO_FSTAT) +#else +#if (defined(MICRO) || defined(WIN32)) && !defined(NO_FSTAT) if(fstat(fd, &buf)) { if(moves > 1) pline("Cannot get status of saved level? "); else pline("Cannot get status of saved game."); @@ -61,14 +61,14 @@ int fd; /* This problem occurs enough times we need to give the player * some more information about what causes it, and how to fix. */ -# ifdef MSDOS +#ifdef MSDOS pline("Make sure that your system's date and time are correct."); pline("They must be more current than NetHack.EXE's date/time stamp."); -# endif /* MSDOS */ +#endif /* MSDOS */ return(0); } -# endif /* MICRO */ -# endif /* WANT_GETHDATE */ +#endif /* MICRO */ +#endif /* WANT_GETHDATE */ return(1); } #endif @@ -77,193 +77,200 @@ int fd; static int eraseoldlocks() { - register int i; + register int i; - /* cannot use maxledgerno() here, because we need to find a lock name - * before starting everything (including the dungeon initialization - * that sets astral_level, needed for maxledgerno()) up - */ - for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) { - /* try to remove all */ - set_levelfile_name(lock, i); - (void) unlink(fqname(lock, LEVELPREFIX, 0)); - } - set_levelfile_name(lock, 0); + /* cannot use maxledgerno() here, because we need to find a lock name + * before starting everything (including the dungeon initialization + * that sets astral_level, needed for maxledgerno()) up + */ + for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { + /* try to remove all */ + set_levelfile_name(lock, i); + (void) unlink(fqname(lock, LEVELPREFIX, 0)); + } + set_levelfile_name(lock, 0); #ifdef HOLD_LOCKFILE_OPEN - really_close(); + really_close(); #endif - if(unlink(fqname(lock, LEVELPREFIX, 0))) - return 0; /* cannot remove it */ - return(1); /* success! */ + if (unlink(fqname(lock, LEVELPREFIX, 0))) + return 0; /* cannot remove it */ + return (1); /* success! */ } void getlock() { - register int fd, c, ci, ct, ern; - int fcmask = FCMASK; - char tbuf[BUFSZ]; - const char *fq_lock; -# if defined(MSDOS) && defined(NO_TERMS) - int grmode = iflags.grmode; -# endif - /* we ignore QUIT and INT at this point */ - if (!lock_file(HLOCK, LOCKPREFIX, 10)) { - wait_synch(); -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("Quitting."); - } + register int fd, c, ci, ct, ern; + int fcmask = FCMASK; + char tbuf[BUFSZ]; + const char *fq_lock; +#if defined(MSDOS) && defined(NO_TERMS) + int grmode = iflags.grmode; +#endif + /* we ignore QUIT and INT at this point */ + if (!lock_file(HLOCK, LOCKPREFIX, 10)) { + wait_synch(); +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("Quitting."); + } - /* regularize(lock); */ /* already done in pcmain */ - Sprintf(tbuf,"%s",fqname(lock, LEVELPREFIX, 0)); - set_levelfile_name(lock, 0); - fq_lock = fqname(lock, LEVELPREFIX, 1); - if((fd = open(fq_lock,0)) == -1) { - if(errno == ENOENT) goto gotlock; /* no such file */ -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif -# if defined(WIN32) || defined(HOLD_LOCKFILE_OPEN) -# if defined(HOLD_LOCKFILE_OPEN) - if(errno == EACCES) { + /* regularize(lock); */ /* already done in pcmain */ + Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); + set_levelfile_name(lock, 0); + fq_lock = fqname(lock, LEVELPREFIX, 1); + if ((fd = open(fq_lock, 0)) == -1) { + if (errno == ENOENT) + goto gotlock; /* no such file */ +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif +#if defined(WIN32) || defined(HOLD_LOCKFILE_OPEN) +#if defined(HOLD_LOCKFILE_OPEN) + if (errno == EACCES) { #define OOPS_BUFSZ 512 - char oops[OOPS_BUFSZ]; - Strcpy(oops, - "\nThere are files from a game in progress under your name."); - Strcat(oops, "\nThe files are locked or inaccessible."); - Strcat(oops, " Is the other game still running?\n"); - if (strlen(fq_lock) < ((OOPS_BUFSZ -16) - strlen(oops))) - Sprintf(eos(oops), "Cannot open %s", fq_lock); - Strcat(oops, "\n"); - unlock_file(HLOCK); - error(oops); - } else -# endif - error("Bad directory or name: %s\n%s\n", - fq_lock, strerror(errno)); -# else - perror(fq_lock); -# endif - unlock_file(HLOCK); - error("Cannot open %s", fq_lock); - } + char oops[OOPS_BUFSZ]; + Strcpy( + oops, + "\nThere are files from a game in progress under your name."); + Strcat(oops, "\nThe files are locked or inaccessible."); + Strcat(oops, " Is the other game still running?\n"); + if (strlen(fq_lock) < ((OOPS_BUFSZ - 16) - strlen(oops))) + Sprintf(eos(oops), "Cannot open %s", fq_lock); + Strcat(oops, "\n"); + unlock_file(HLOCK); + error(oops); + } else +#endif + error("Bad directory or name: %s\n%s\n", fq_lock, + strerror(errno)); +#else + perror(fq_lock); +#endif + unlock_file(HLOCK); + error("Cannot open %s", fq_lock); + } - (void) nhclose(fd); + (void) nhclose(fd); - if(iflags.window_inited) { -# ifdef SELF_RECOVER - c = yn("There are files from a game in progress under your name. Recover?"); -# else - pline("There is already a game in progress under your name."); - pline("You may be able to use \"recover %s\" to get it back.\n",tbuf); - c = yn("Do you want to destroy the old game?"); -# endif - } else { -# if defined(MSDOS) && defined(NO_TERMS) - grmode = iflags.grmode; - if (grmode) gr_finish(); -# endif - c = 'n'; - ct = 0; -# ifdef SELF_RECOVER - msmsg( - "There are files from a game in progress under your name. Recover? [yn]"); -# else - msmsg("\nThere is already a game in progress under your name.\n"); - msmsg("If this is unexpected, you may be able to use \n"); - msmsg("\"recover %s\" to get it back.",tbuf); - msmsg("\nDo you want to destroy the old game? [yn] "); -# endif - while ((ci=nhgetch()) != '\n') { - if (ct > 0) { - msmsg("\b \b"); - ct = 0; - c = 'n'; - } - if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') { - ct = 1; - c = ci; - msmsg("%c",c); - } - } - } - if(c == 'y' || c == 'Y') -# ifndef SELF_RECOVER - if(eraseoldlocks()) { -# if defined(WIN32) - if (!strncmpi(windowprocs.name, "tty", 3)) - clear_screen(); /* display gets fouled up otherwise */ -# endif - goto gotlock; - } else { - unlock_file(HLOCK); -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("Couldn't destroy old game."); - } -# else /*SELF_RECOVER*/ - if(recover_savefile()) { -# if defined(WIN32) - if (!strncmpi(windowprocs.name, "tty", 3)) - clear_screen(); /* display gets fouled up otherwise */ -# endif - goto gotlock; - } else { - unlock_file(HLOCK); -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("Couldn't recover old game."); - } -# endif /*SELF_RECOVER*/ - else { - unlock_file(HLOCK); -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("%s", "Cannot start a new game."); - } + if (iflags.window_inited) { +#ifdef SELF_RECOVER + c = yn("There are files from a game in progress under your name. " + "Recover?"); +#else + pline("There is already a game in progress under your name."); + pline("You may be able to use \"recover %s\" to get it back.\n", + tbuf); + c = yn("Do you want to destroy the old game?"); +#endif + } else { +#if defined(MSDOS) && defined(NO_TERMS) + grmode = iflags.grmode; + if (grmode) + gr_finish(); +#endif + c = 'n'; + ct = 0; +#ifdef SELF_RECOVER + msmsg("There are files from a game in progress under your name. " + "Recover? [yn]"); +#else + msmsg("\nThere is already a game in progress under your name.\n"); + msmsg("If this is unexpected, you may be able to use \n"); + msmsg("\"recover %s\" to get it back.", tbuf); + msmsg("\nDo you want to destroy the old game? [yn] "); +#endif + while ((ci = nhgetch()) != '\n') { + if (ct > 0) { + msmsg("\b \b"); + ct = 0; + c = 'n'; + } + if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') { + ct = 1; + c = ci; + msmsg("%c", c); + } + } + } + if (c == 'y' || c == 'Y') +#ifndef SELF_RECOVER + if (eraseoldlocks()) { +#if defined(WIN32) + if (!strncmpi(windowprocs.name, "tty", 3)) + clear_screen(); /* display gets fouled up otherwise */ +#endif + goto gotlock; + } else { + unlock_file(HLOCK); +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("Couldn't destroy old game."); + } +#else /*SELF_RECOVER*/ + if (recover_savefile()) { +#if defined(WIN32) + if (!strncmpi(windowprocs.name, "tty", 3)) + clear_screen(); /* display gets fouled up otherwise */ +#endif + goto gotlock; + } else { + unlock_file(HLOCK); +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("Couldn't recover old game."); + } +#endif /*SELF_RECOVER*/ + else { + unlock_file(HLOCK); +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("%s", "Cannot start a new game."); + } gotlock: - fd = creat(fq_lock, fcmask); - if (fd == -1) ern = errno; - unlock_file(HLOCK); - if(fd == -1) { -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif -# if defined(WIN32) - error("cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", - fq_lock, strerror(ern), " Are you sure that the directory", - fqn_prefix[LEVELPREFIX]); -# else - error("cannot creat file (%s.)", fq_lock); -# endif - } else { - if(write(fd, (char *) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("cannot write lock (%s)", fq_lock); - } - if(nhclose(fd) == -1) { -# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) - chdirx(orgdir, 0); -# endif - error("cannot close lock (%s)", fq_lock); - } - } -# if defined(MSDOS) && defined(NO_TERMS) - if (grmode) gr_init(); -# endif -} + fd = creat(fq_lock, fcmask); + if (fd == -1) + ern = errno; + unlock_file(HLOCK); + if (fd == -1) { +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif +#if defined(WIN32) + error("cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock, + strerror(ern), " Are you sure that the directory", + fqn_prefix[LEVELPREFIX]); +#else + error("cannot creat file (%s.)", fq_lock); +#endif + } else { + if (write(fd, (char *) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("cannot write lock (%s)", fq_lock); + } + if (nhclose(fd) == -1) { +#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) + chdirx(orgdir, 0); +#endif + error("cannot close lock (%s)", fq_lock); + } + } +#if defined(MSDOS) && defined(NO_TERMS) + if (grmode) + gr_init(); +#endif +} #endif /* PC_LOCKING */ -# ifndef WIN32 +#ifndef WIN32 void regularize(s) /* @@ -272,19 +279,23 @@ regularize(s) */ register char *s; { - register char *lp; + register char *lp; - for (lp = s; *lp; lp++) - if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',') || - *lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') || -# ifdef OS2 - *lp == '&' || *lp == '(' || *lp == ')' || -# endif - *lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']')) - *lp = '_'; + for (lp = s; *lp; lp++) + if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',') + || *lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') || +#ifdef OS2 + *lp == '&' || *lp == '(' || *lp == ')' || +#endif + *lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']')) + *lp = '_'; } -# endif /* WIN32 */ +#endif /* WIN32 */ #ifdef __EMX__ -void seteuid(int i){;} +void +seteuid(int i) +{ + ; +} #endif diff --git a/sys/share/posixregex.c b/sys/share/posixregex.c index 8c346208c..ea7dbd5fe 100644 --- a/sys/share/posixregex.c +++ b/sys/share/posixregex.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 posixregex.c $NHDT-Date: 1428970913 2015/04/14 00:21:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */ +/* NetHack 3.6 posixregex.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.2 $ */ /* Copyright (c) Sean Hunt 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -45,49 +45,59 @@ */ struct nhregex { - regex_t re; - int err; + regex_t re; + int err; }; -struct nhregex *regex_init() { - return (struct nhregex *)alloc(sizeof (struct nhregex)); +struct nhregex * +regex_init() +{ + return (struct nhregex *) alloc(sizeof(struct nhregex)); } -boolean regex_compile(const char *s, struct nhregex *re) { - if (!re) - return FALSE; - if ((re->err = regcomp(&re->re, s, REG_EXTENDED | REG_NOSUB))) - return FALSE; - return TRUE; +boolean +regex_compile(const char *s, struct nhregex *re) +{ + if (!re) + return FALSE; + if ((re->err = regcomp(&re->re, s, REG_EXTENDED | REG_NOSUB))) + return FALSE; + return TRUE; } -const char *regex_error_desc(struct nhregex *re) { - static char buf[BUFSZ]; +const char * +regex_error_desc(struct nhregex *re) +{ + static char buf[BUFSZ]; - if (!re || !re->err) - return (const char *)0; + if (!re || !re->err) + return (const char *) 0; - /* FIXME: Using a static buffer here is not ideal, but avoids memory - * leaks. Consider the allocation more carefully. */ - regerror(re->err, &re->re, buf, BUFSZ); + /* FIXME: Using a static buffer here is not ideal, but avoids memory + * leaks. Consider the allocation more carefully. */ + regerror(re->err, &re->re, buf, BUFSZ); - return buf; + return buf; } -boolean regex_match(const char *s, struct nhregex *re) { - int result; +boolean +regex_match(const char *s, struct nhregex *re) +{ + int result; - if (!re) - return FALSE; + if (!re) + return FALSE; - if ((result = regexec(&re->re, s, 0, (genericptr_t)0, 0))) { - if (result != REG_NOMATCH) - re->err = result; - return FALSE; - } - return TRUE; + if ((result = regexec(&re->re, s, 0, (genericptr_t) 0, 0))) { + if (result != REG_NOMATCH) + re->err = result; + return FALSE; + } + return TRUE; } -void regex_free(struct nhregex *re) { - free(re); +void +regex_free(struct nhregex *re) +{ + free(re); } diff --git a/sys/share/random.c b/sys/share/random.c index ba1937bb4..3a8f42a1f 100644 --- a/sys/share/random.c +++ b/sys/share/random.c @@ -33,16 +33,16 @@ * - cast result of pointer subtraction to long since ptrdiff_t could * be bigger than that and trigger warnings when assigning to long * - * $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ + * $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ * $Date: 2007/12/23 00:59:25 $ $Revision: 1.2 $ */ #include "hack.h" #ifdef LIBC_SCCS -# ifndef lint +#ifndef lint static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; -# endif +#endif #endif /* LIBC_SCCS and not lint */ /* @@ -50,11 +50,13 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; * An improved random number generation package. In addition to the standard * rand()/srand() like interface, this package also has a special state info * interface. The initstate() routine is called with a seed, an array of - * bytes, and a count of how many bytes are being passed in; this array is then + * bytes, and a count of how many bytes are being passed in; this array is + * then * initialized to contain information for random number generation with that * much state information. Good sizes for the amount of state information are * 32, 64, 128, and 256 bytes. The state can be switched by calling the - * setstate() routine with the same array as was initiallized with initstate(). + * setstate() routine with the same array as was initiallized with + * initstate(). * By default, the package runs with 128 bytes of state information and * generates far better random numbers than a linear congruential generator. * If the amount of state information is less than 32 bytes, a simple linear @@ -63,7 +65,7 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; * zeroeth element of the array is the type of R.N.G. being used (small * integer); the remainder of the array is the state information for the * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of - * state information, which will allow a degree seven polynomial. (Note: the + * state information, which will allow a degree seven polynomial. (Note: the * zeroeth word of state information also has some other information stored * in it -- see setstate() for details). * The random number generation technique is a linear feedback shift register @@ -82,8 +84,6 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; * predicted by this formula. */ - - /* * For each of the currently supported random number generators, we have a * break value on the amount of state information (you need at least this @@ -92,46 +92,41 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; * the separation between the two lower order coefficients of the trinomial. */ -#define TYPE_0 0 /* linear congruential */ -#define BREAK_0 8 -#define DEG_0 0 -#define SEP_0 0 +#define TYPE_0 0 /* linear congruential */ +#define BREAK_0 8 +#define DEG_0 0 +#define SEP_0 0 -#define TYPE_1 1 /* x**7 + x**3 + 1 */ -#define BREAK_1 32 -#define DEG_1 7 -#define SEP_1 3 +#define TYPE_1 1 /* x**7 + x**3 + 1 */ +#define BREAK_1 32 +#define DEG_1 7 +#define SEP_1 3 -#define TYPE_2 2 /* x**15 + x + 1 */ -#define BREAK_2 64 -#define DEG_2 15 -#define SEP_2 1 +#define TYPE_2 2 /* x**15 + x + 1 */ +#define BREAK_2 64 +#define DEG_2 15 +#define SEP_2 1 -#define TYPE_3 3 /* x**31 + x**3 + 1 */ -#define BREAK_3 128 -#define DEG_3 31 -#define SEP_3 3 - -#define TYPE_4 4 /* x**63 + x + 1 */ -#define BREAK_4 256 -#define DEG_4 63 -#define SEP_4 1 +#define TYPE_3 3 /* x**31 + x**3 + 1 */ +#define BREAK_3 128 +#define DEG_3 31 +#define SEP_3 3 +#define TYPE_4 4 /* x**63 + x + 1 */ +#define BREAK_4 256 +#define DEG_4 63 +#define SEP_4 1 /* * Array versions of the above information to make code run faster -- relies * on fact that TYPE_i == i. */ -#define MAX_TYPES 5 /* max number of types above */ - -static int degrees[ MAX_TYPES ] = { DEG_0, DEG_1, DEG_2, - DEG_3, DEG_4 }; - -static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2, - SEP_3, SEP_4 }; +#define MAX_TYPES 5 /* max number of types above */ +static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; +static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; /* * Initially, everything is set up as if from : @@ -144,21 +139,23 @@ static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2, * MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3. */ -static long randtbl[ DEG_3 + 1 ] = { TYPE_3, - 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, - 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, - 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, - 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, - 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, - 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, - 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, - 0xf5ad9d0e, 0x8999220b, 0x27fb47b9 }; +static long randtbl[DEG_3 + 1] = { + TYPE_3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, + 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, + 0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, + 0x1588ca88, 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, + 0xac94efdc, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, + 0x8999220b, 0x27fb47b9 +}; /* * fptr and rptr are two pointers into the state info, a front and a rear - * pointer. These two pointers are always rand_sep places aparts, as they cycle - * cyclically through the state information. (Yes, this does mean we could get - * away with just one pointer, but the code for random() is more efficient this + * pointer. These two pointers are always rand_sep places aparts, as they + *cycle + * cyclically through the state information. (Yes, this does mean we could + *get + * away with just one pointer, but the code for random() is more efficient + *this * way). The pointers are left positioned as they would be from the call * initstate( 1, randtbl, 128 ) * (The position of the rear pointer, rptr, is really 0 (as explained above @@ -166,10 +163,8 @@ static long randtbl[ DEG_3 + 1 ] = { TYPE_3, * to point to randtbl[1] (as explained below). */ -static long *fptr = &randtbl[ SEP_3 + 1 ]; -static long *rptr = &randtbl[ 1 ]; - - +static long *fptr = &randtbl[SEP_3 + 1]; +static long *rptr = &randtbl[1]; /* * The following things are the pointer to the state information table, @@ -183,15 +178,13 @@ static long *rptr = &randtbl[ 1 ]; * the front and rear pointers have wrapped. */ -static long *state = &randtbl[ 1 ]; - -static int rand_type = TYPE_3; -static int rand_deg = DEG_3; -static int rand_sep = SEP_3; - -static long *end_ptr = &randtbl[ DEG_3 + 1 ]; +static long *state = &randtbl[1]; +static int rand_type = TYPE_3; +static int rand_deg = DEG_3; +static int rand_sep = SEP_3; +static long *end_ptr = &randtbl[DEG_3 + 1]; /* * srandom: @@ -207,28 +200,26 @@ static long *end_ptr = &randtbl[ DEG_3 + 1 ]; */ void -srandom( x ) +srandom(x) - unsigned x; +unsigned x; { - register int i; + register int i; - if( rand_type == TYPE_0 ) { - state[ 0 ] = x; - } - else { - state[ 0 ] = x; - for( i = 1; i < rand_deg; i++ ) { - state[i] = 1103515245*state[i - 1] + 12345; - } - fptr = &state[ rand_sep ]; - rptr = &state[ 0 ]; - for( i = 0; i < 10*rand_deg; i++ ) random(); - } + if (rand_type == TYPE_0) { + state[0] = x; + } else { + state[0] = x; + for (i = 1; i < rand_deg; i++) { + state[i] = 1103515245 * state[i - 1] + 12345; + } + fptr = &state[rand_sep]; + rptr = &state[0]; + for (i = 0; i < 10 * rand_deg; i++) + random(); + } } - - /* * initstate: * Initialize the state information in the given array of n bytes for @@ -245,63 +236,62 @@ srandom( x ) * Returns a pointer to the old state. */ -char * -initstate( seed, arg_state, n ) +char * +initstate(seed, arg_state, n) - unsigned seed; /* seed for R. N. G. */ - char *arg_state; /* pointer to state array */ - int n; /* # bytes of state info */ +unsigned seed; /* seed for R. N. G. */ +char *arg_state; /* pointer to state array */ +int n; /* # bytes of state info */ { - register char *ostate = (char *)( &state[ -1 ] ); + register char *ostate = (char *) (&state[-1]); - if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; - else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type); - if( n < BREAK_1 ) { - if( n < BREAK_0 ) { - impossible( - "initstate: not enough state (%d bytes) with which to do jack; ignored.", n); - return (char *)0; - } - rand_type = TYPE_0; - rand_deg = DEG_0; - rand_sep = SEP_0; - } - else { - if( n < BREAK_2 ) { - rand_type = TYPE_1; - rand_deg = DEG_1; - rand_sep = SEP_1; - } - else { - if( n < BREAK_3 ) { - rand_type = TYPE_2; - rand_deg = DEG_2; - rand_sep = SEP_2; - } - else { - if( n < BREAK_4 ) { - rand_type = TYPE_3; - rand_deg = DEG_3; - rand_sep = SEP_3; - } - else { - rand_type = TYPE_4; - rand_deg = DEG_4; - rand_sep = SEP_4; - } - } - } - } - state = &( ( (long *)arg_state )[1] ); /* first location */ - end_ptr = &state[ rand_deg ]; /* must set end_ptr before srandom */ - srandom( seed ); - if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; - else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type); - return( ostate ); + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type); + if (n < BREAK_1) { + if (n < BREAK_0) { + impossible("initstate: not enough state (%d bytes) with which to " + "do jack; ignored.", + n); + return (char *) 0; + } + rand_type = TYPE_0; + rand_deg = DEG_0; + rand_sep = SEP_0; + } else { + if (n < BREAK_2) { + rand_type = TYPE_1; + rand_deg = DEG_1; + rand_sep = SEP_1; + } else { + if (n < BREAK_3) { + rand_type = TYPE_2; + rand_deg = DEG_2; + rand_sep = SEP_2; + } else { + if (n < BREAK_4) { + rand_type = TYPE_3; + rand_deg = DEG_3; + rand_sep = SEP_3; + } else { + rand_type = TYPE_4; + rand_deg = DEG_4; + rand_sep = SEP_4; + } + } + } + } + state = &(((long *) arg_state)[1]); /* first location */ + end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ + srandom(seed); + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type); + return (ostate); } - - /* * setstate: * Restore the state from the given state array. @@ -314,44 +304,45 @@ initstate( seed, arg_state, n ) * Returns a pointer to the old state information. */ -char * -setstate( arg_state ) +char * +setstate(arg_state) - char *arg_state; +char *arg_state; { - register long *new_state = (long *)arg_state; - register int type = new_state[0]%MAX_TYPES; - register int rear = new_state[0]/MAX_TYPES; - char *ostate = (char *)( &state[ -1 ] ); + register long *new_state = (long *) arg_state; + register int type = new_state[0] % MAX_TYPES; + register int rear = new_state[0] / MAX_TYPES; + char *ostate = (char *) (&state[-1]); - if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; - else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type); - switch( type ) { - case TYPE_0: - case TYPE_1: - case TYPE_2: - case TYPE_3: - case TYPE_4: - rand_type = type; - rand_deg = degrees[ type ]; - rand_sep = seps[ type ]; - break; + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type); + switch (type) { + case TYPE_0: + case TYPE_1: + case TYPE_2: + case TYPE_3: + case TYPE_4: + rand_type = type; + rand_deg = degrees[type]; + rand_sep = seps[type]; + break; - default: - impossible("setstate: state info has been munged (%d); not changed.", type); - break; - } - state = &new_state[ 1 ]; - if( rand_type != TYPE_0 ) { - rptr = &state[ rear ]; - fptr = &state[ (rear + rand_sep)%rand_deg ]; - } - end_ptr = &state[ rand_deg ]; /* set end_ptr too */ - return( ostate ); + default: + impossible("setstate: state info has been munged (%d); not changed.", + type); + break; + } + state = &new_state[1]; + if (rand_type != TYPE_0) { + rptr = &state[rear]; + fptr = &state[(rear + rand_sep) % rand_deg]; + } + end_ptr = &state[rand_deg]; /* set end_ptr too */ + return (ostate); } - - /* * random: * If we are using the trivial TYPE_0 R.N.G., just do the old linear @@ -370,22 +361,20 @@ setstate( arg_state ) long random() { - long i; - - if( rand_type == TYPE_0 ) { - i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff; - } - else { - *fptr += *rptr; - i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */ - if( ++fptr >= end_ptr ) { - fptr = state; - ++rptr; - } - else { - if( ++rptr >= end_ptr ) rptr = state; - } - } - return( i ); -} + long i; + if (rand_type == TYPE_0) { + i = state[0] = (state[0] * 1103515245 + 12345) & 0x7fffffff; + } else { + *fptr += *rptr; + i = (*fptr >> 1) & 0x7fffffff; /* chucking least random bit */ + if (++fptr >= end_ptr) { + fptr = state; + ++rptr; + } else { + if (++rptr >= end_ptr) + rptr = state; + } + } + return (i); +} diff --git a/sys/share/tclib.c b/sys/share/tclib.c index 12ebf1368..01dc641e3 100644 --- a/sys/share/tclib.c +++ b/sys/share/tclib.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tclib.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 tclib.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 tclib.c $Date: 2009/05/06 10:50:31 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)tclib.c 3.5 1996/02/25 */ /* Copyright (c) Robert Patrick Rankin, 1995 */ @@ -8,28 +8,28 @@ #include "config.h" -#ifndef TERMCAP /* name of default termcap file */ +#ifndef TERMCAP /* name of default termcap file */ #define TERMCAP "/etc/termcap" #endif -#ifndef TCBUFSIZ /* size of tgetent buffer; Unix man page says 1024 */ +#ifndef TCBUFSIZ /* size of tgetent buffer; Unix man page says 1024 */ #define TCBUFSIZ 1024 #endif -#define ESC '\033' /* termcap's '\E' */ -#define BEL '\007' /* ANSI C's '\a' (we assume ASCII here...) */ +#define ESC '\033' /* termcap's '\E' */ +#define BEL '\007' /* ANSI C's '\a' (we assume ASCII here...) */ /* exported variables, as per man page */ -char PC; +char PC; char *BC, *UP; short ospeed; /* exported routines */ -int FDECL(tgetent, (char *,const char *)); -int FDECL(tgetflag, (const char *)); -int FDECL(tgetnum, (const char *)); -char *FDECL(tgetstr, (const char *,char **)); -char *FDECL(tgoto, (const char *,int,int)); -char *FDECL(tparam, (const char *,char *,int,int,int,int,int)); -void FDECL(tputs, (const char *,int,int (*)())); +int FDECL(tgetent, (char *, const char *)); +int FDECL(tgetflag, (const char *)); +int FDECL(tgetnum, (const char *)); +char *FDECL(tgetstr, (const char *, char **)); +char *FDECL(tgoto, (const char *, int, int)); +char *FDECL(tparam, (const char *, char *, int, int, int, int, int)); +void FDECL(tputs, (const char *, int, int (*)())); /* local support data */ static char *tc_entry; @@ -37,34 +37,34 @@ static char bc_up_buf[24]; #ifndef NO_DELAY_PADDING /* `ospeed' to baud rate conversion table, adapted from GNU termcap-1.2 */ static short baud_rates[] = { - 0, 50, 75, 110, 135, 150, -# ifdef VMS - 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, -# else /* assume Unix */ - 200, 300, 600, 1200, 1800, 2400, 4800, -# endif - 9600, -192, -384, /* negative is used as `100 * abs(entry)' */ -# ifdef VMS - -576, -768, -1152, -# endif + 0, 50, 75, 110, 135, 150, +#ifdef VMS + 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, +#else /* assume Unix */ + 200, 300, 600, 1200, 1800, 2400, 4800, +#endif + 9600, -192, -384, /* negative is used as `100 * abs(entry)' */ +#ifdef VMS + -576, -768, -1152, +#endif }; -#endif /* !NO_DELAY_PADDING */ +#endif /* !NO_DELAY_PADDING */ /* local support code */ -static int FDECL(tc_store, (const char *,const char *)); -static char *FDECL(tc_find, (FILE *,const char *,char *,int)); -static char *FDECL(tc_name, (const char *,char *)); -static const char *FDECL(tc_field, (const char *,const char **)); +static int FDECL(tc_store, (const char *, const char *)); +static char *FDECL(tc_find, (FILE *, const char *, char *, int)); +static char *FDECL(tc_name, (const char *, char *)); +static const char *FDECL(tc_field, (const char *, const char **)); #ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) #endif /* retrieve the specified terminal entry and return it in `entbuf' */ int tgetent(entbuf, term) - char *entbuf; /* size must be at least [TCBUFSIZ] */ - const char *term; +char *entbuf; /* size must be at least [TCBUFSIZ] */ +const char *term; { int result; FILE *fp; @@ -72,25 +72,26 @@ tgetent(entbuf, term) tc_entry = entbuf; if (!entbuf || !term) - return -1; + return -1; /* if ${TERMCAP} is found as a file, it's not an inline termcap entry */ if ((fp = fopen(tc ? tc : TERMCAP, "r")) != 0) - tc = 0; - /* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP} */ + tc = 0; + /* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP} + */ if (tc) { - char *tm = getenv("TERM"); - if (tm && strcmp(tm, term) == 0) - return tc_store(term, tc); - fp = fopen(TERMCAP, "r"); + char *tm = getenv("TERM"); + if (tm && strcmp(tm, term) == 0) + return tc_store(term, tc); + fp = fopen(TERMCAP, "r"); } /* otherwise, look `term' up in the file */ if (fp) { - char wrkbuf[TCBUFSIZ]; - tc = tc_find(fp, term, wrkbuf, (int)(sizeof wrkbuf - strlen(term))); - result = tc_store(term, tc); - (void) fclose(fp); + char wrkbuf[TCBUFSIZ]; + tc = tc_find(fp, term, wrkbuf, (int) (sizeof wrkbuf - strlen(term))); + result = tc_store(term, tc); + (void) fclose(fp); } else { - result = -1; + result = -1; } return result; } @@ -98,7 +99,7 @@ tgetent(entbuf, term) /* copy the entry into the output buffer */ static int tc_store(trm, ent) - const char *trm, *ent; +const char *trm, *ent; { const char *bar, *col; char *s; @@ -106,31 +107,32 @@ tc_store(trm, ent) int k; if (!ent || !*ent || !trm || !*trm || (col = index(ent, ':')) == 0) - return 0; + return 0; (void) strcpy(tc_entry, trm); if (((bar = index(ent, '|')) != 0 && bar < col) - || ((long)(n = strlen(trm)) == (long)(col - ent) - && strncmp(ent, trm, n) == 0)) - (void) strcat(tc_entry, col); + || ((long) (n = strlen(trm)) == (long) (col - ent) + && strncmp(ent, trm, n) == 0)) + (void) strcat(tc_entry, col); else if (*ent == ':') - (void) strcat(tc_entry, ent); + (void) strcat(tc_entry, ent); else - (void) strcat(strcat(tc_entry, ":"), ent); + (void) strcat(strcat(tc_entry, ":"), ent); /* initialize global variables */ k = tgetnum("pc"); - PC = (k == -1) ? '\0' : (char)k; + PC = (k == -1) ? '\0' : (char) k; BC = s = bc_up_buf; - if (!tgetstr("bc", &s)) (void)strcpy(s, "\b"), s += 2; + if (!tgetstr("bc", &s)) + (void) strcpy(s, "\b"), s += 2; UP = s; - (void)tgetstr("up", &s); + (void) tgetstr("up", &s); #ifndef NO_DELAY_PADDING /* caller must set `ospeed' */ - if ((int)ospeed >= (int)SIZE(baud_rates)) - ospeed = (short)(SIZE(baud_rates) - 1); + if ((int) ospeed >= (int) SIZE(baud_rates)) + ospeed = (short) (SIZE(baud_rates) - 1); else if (ospeed < 0) - ospeed = 0; -#endif /* !NO_DELAY_PADDING */ + ospeed = 0; +#endif /* !NO_DELAY_PADDING */ return 1; } @@ -138,56 +140,60 @@ tc_store(trm, ent) /* search for an entry in the termcap file */ static char * tc_find(fp, term, buffer, bufsiz) - FILE *fp; - const char *term; - char *buffer; - int bufsiz; +FILE *fp; +const char *term; +char *buffer; +int bufsiz; { int in, len, first, skip; char *ip, *op, *tc_fetch, tcbuf[TCBUFSIZ]; buffer[0] = '\0'; do { - ip = tcbuf, in = min(bufsiz,TCBUFSIZ); - first = 1, skip = 0; - /* load entire next entry, including any continuations */ - do { - if (!fgets(ip, min(in,BUFSIZ), fp)) break; - if (first) skip = (*ip == '#'), first = 0; - len = (int)strlen(ip); - if (!skip && len > 1 - && *(ip + len - 1) == '\n' && *(ip + len - 2) == '\\') - len -= 2; - ip += len, in -= len; - } while (*(ip - 1) != '\n' && in > 0); - if (ferror(fp) || ip == buffer || *(ip - 1) != '\n') - return (char *)0; - *--ip = '\0'; /* strip newline */ - if (!skip) ip = tc_name(term, tcbuf); + ip = tcbuf, in = min(bufsiz, TCBUFSIZ); + first = 1, skip = 0; + /* load entire next entry, including any continuations */ + do { + if (!fgets(ip, min(in, BUFSIZ), fp)) + break; + if (first) + skip = (*ip == '#'), first = 0; + len = (int) strlen(ip); + if (!skip && len > 1 && *(ip + len - 1) == '\n' + && *(ip + len - 2) == '\\') + len -= 2; + ip += len, in -= len; + } while (*(ip - 1) != '\n' && in > 0); + if (ferror(fp) || ip == buffer || *(ip - 1) != '\n') + return (char *) 0; + *--ip = '\0'; /* strip newline */ + if (!skip) + ip = tc_name(term, tcbuf); } while (skip || !ip); /* we have the desired entry; strip cruft and look for :tc=other: */ tc_fetch = 0; for (op = buffer; *ip; ip++) { - if (op == buffer || *(op - 1) != ':' - || (*ip != ' ' && *ip != '\t' && *ip != ':')) - *op++ = *ip, bufsiz -= 1; - if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') { - tc_fetch = &ip[4]; - if ((ip = index(tc_fetch, ':')) != 0) *ip = '\0'; - break; - } + if (op == buffer || *(op - 1) != ':' + || (*ip != ' ' && *ip != '\t' && *ip != ':')) + *op++ = *ip, bufsiz -= 1; + if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') { + tc_fetch = &ip[4]; + if ((ip = index(tc_fetch, ':')) != 0) + *ip = '\0'; + break; + } } *op = '\0'; if (tc_fetch) { - rewind(fp); - tc_fetch = tc_find(fp, tc_fetch, tcbuf, min(bufsiz,TCBUFSIZ)); - if (!tc_fetch) - return (char *)0; - if (op > buffer && *(op - 1) == ':' && *tc_fetch == ':') - ++tc_fetch; - strcpy(op, tc_fetch); + rewind(fp); + tc_fetch = tc_find(fp, tc_fetch, tcbuf, min(bufsiz, TCBUFSIZ)); + if (!tc_fetch) + return (char *) 0; + if (op > buffer && *(op - 1) == ':' && *tc_fetch == ':') + ++tc_fetch; + strcpy(op, tc_fetch); } return buffer; } @@ -195,37 +201,39 @@ tc_find(fp, term, buffer, bufsiz) /* check whether `ent' contains `nam'; return start of field entries */ static char * tc_name(nam, ent) - const char *nam; - char *ent; +const char *nam; +char *ent; { char *nxt, *lst, *p = ent; size_t n = strlen(nam); - if ((lst = index(p, ':')) == 0) lst = p + strlen(p); + if ((lst = index(p, ':')) == 0) + lst = p + strlen(p); while (p < lst) { - if ((nxt = index(p, '|')) == 0 || nxt > lst) nxt = lst; - if ((long)(nxt - p) == (long)n && strncmp(p, nam, n) == 0) - return lst; - p = nxt + 1; + if ((nxt = index(p, '|')) == 0 || nxt > lst) + nxt = lst; + if ((long) (nxt - p) == (long) n && strncmp(p, nam, n) == 0) + return lst; + p = nxt + 1; } - return (char *)0; + return (char *) 0; } /* look up a numeric entry */ int tgetnum(which) - const char *which; +const char *which; { const char *q, *p = tc_field(which, &q); char numbuf[32]; size_t n; if (!p || p[2] != '#') - return -1; + return -1; p += 3; if ((n = (size_t)(q - p)) >= sizeof numbuf) - return -1; + return -1; (void) strncpy(numbuf, p, n); numbuf[n] = '\0'; return atoi(numbuf); @@ -234,9 +242,9 @@ tgetnum(which) /* look up a boolean entry */ int tgetflag(which) - const char *which; +const char *which; { - const char *p = tc_field(which, (const char **)0); + const char *p = tc_field(which, (const char **) 0); return (!p || p[2] != ':') ? 0 : 1; } @@ -244,48 +252,74 @@ tgetflag(which) /* look up a string entry; update `*outptr' */ char * tgetstr(which, outptr) - const char *which; - char **outptr; +const char *which; +char **outptr; { int n; char c, *r, *result; const char *q, *p = tc_field(which, &q); if (!p || p[2] != '=') - return (char *)0; + return (char *) 0; p += 3; - if ((q = index(p, ':')) == 0) q = p + strlen(p); + if ((q = index(p, ':')) == 0) + q = p + strlen(p); r = result = *outptr; while (p < q) { - switch ((*r = *p++)) { - case '\\': - switch ((c = *p++)) { - case 'E': *r = ESC; break; - case 'a': *r = BEL; break; - case 'b': *r = '\b'; break; - case 'f': *r = '\f'; break; - case 'n': *r = '\n'; break; - case 'r': *r = '\r'; break; - case 't': *r = '\t'; break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - n = c - '0'; - if (*p >= '0' && *p <= '7') n = 8 * n + (*p++ - '0'); - if (*p >= '0' && *p <= '7') n = 8 * n + (*p++ - '0'); - *r = (char)n; - break; - /* case '^': case '\\': */ - default: *r = c; break; - } - break; - case '^': - *r = (*p++ & 037); - if (!*r) *r = (char)'\200'; - break; - default: - break; - } - ++r; + switch ((*r = *p++)) { + case '\\': + switch ((c = *p++)) { + case 'E': + *r = ESC; + break; + case 'a': + *r = BEL; + break; + case 'b': + *r = '\b'; + break; + case 'f': + *r = '\f'; + break; + case 'n': + *r = '\n'; + break; + case 'r': + *r = '\r'; + break; + case 't': + *r = '\t'; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + n = c - '0'; + if (*p >= '0' && *p <= '7') + n = 8 * n + (*p++ - '0'); + if (*p >= '0' && *p <= '7') + n = 8 * n + (*p++ - '0'); + *r = (char) n; + break; + /* case '^': case '\\': */ + default: + *r = c; + break; + } + break; + case '^': + *r = (*p++ & 037); + if (!*r) + *r = (char) '\200'; + break; + default: + break; + } + ++r; } *r++ = '\0'; *outptr = r; @@ -295,26 +329,27 @@ tgetstr(which, outptr) /* look for a particular field name */ static const char * tc_field(field, tc_end) - const char *field; - const char **tc_end; +const char *field; +const char **tc_end; { const char *end, *q, *p = tc_entry; end = p + strlen(p); while (p < end) { - if ((p = index(p, ':')) == 0) - break; - ++p; - if (p[0] == field[0] && p[1] == field[1] - && (p[2] == ':' || p[2] == '=' || p[2] == '#' || p[2] == '@')) - break; + if ((p = index(p, ':')) == 0) + break; + ++p; + if (p[0] == field[0] && p[1] == field[1] + && (p[2] == ':' || p[2] == '=' || p[2] == '#' || p[2] == '@')) + break; } if (tc_end) { - if (p) { - if ((q = index(p + 2, ':')) == 0) q = end; - } else - q = 0; - *tc_end = q; + if (p) { + if ((q = index(p + 2, ':')) == 0) + q = end; + } else + q = 0; + *tc_end = q; } return p; } @@ -324,19 +359,19 @@ static char cmbuf[64]; /* produce a string which will position the cursor at if output */ char * tgoto(cm, col, row) - const char *cm; - int col, row; +const char *cm; +int col, row; { - return tparam(cm, cmbuf, (int)(sizeof cmbuf), row, col, 0, 0); + return tparam(cm, cmbuf, (int) (sizeof cmbuf), row, col, 0, 0); } /* format a parameterized string, ala sprintf */ char * tparam(ctl, buf, buflen, row, col, row2, col2) - const char *ctl; /* parameter control string */ - char *buf; /* output buffer */ - int buflen; /* ought to have been `size_t'... */ - int row, col, row2, col2; +const char *ctl; /* parameter control string */ +char *buf; /* output buffer */ +int buflen; /* ought to have been `size_t'... */ +int row, col, row2, col2; { int atmp, ac, av[5]; char c, *r, *z, *bufend, numbuf[32]; @@ -345,138 +380,176 @@ tparam(ctl, buf, buflen, row, col, row2, col2) int bc = 0, up = 0; #endif - av[0] = row, av[1] = col, av[2] = row2, av[3] = col2, av[4] = 0; + av[0] = row, av[1] = col, av[2] = row2, av[3] = col2, av[4] = 0; ac = 0; - r = buf, bufend = r + buflen - 1; + r = buf, bufend = r + buflen - 1; while (*ctl) { - if ((*r = *ctl++) == '%') { - if (ac > 4) ac = 4; - fmt = 0; - switch ((c = *ctl++)) { - case '%': break; /* '%' already copied */ - case 'd': fmt = "%d"; break; - case '2': fmt = "%02d"; break; - case '3': fmt = "%03d"; break; - case '+': /*FALLTHRU*/ - case '.': *r = (char)av[ac++]; - if (c == '+') *r += *ctl++; - if (!*r) { - *r = (char)'\200'; - } else { + if ((*r = *ctl++) == '%') { + if (ac > 4) + ac = 4; + fmt = 0; + switch ((c = *ctl++)) { + case '%': + break; /* '%' already copied */ + case 'd': + fmt = "%d"; + break; + case '2': + fmt = "%02d"; + break; + case '3': + fmt = "%03d"; + break; + case '+': /*FALLTHRU*/ + case '.': + *r = (char) av[ac++]; + if (c == '+') + *r += *ctl++; + if (!*r) { + *r = (char) '\200'; + } else { #ifndef NO_SPECIAL_CHARS_FIXUP - /* avoid terminal driver intervention for - various control characters, to prevent - LF from becoming CR+LF, for instance; only - makes sense if this is a cursor positioning - sequence, but we have no way to check that */ - while (index("\004\t\n\013\f\r", *r)) { - if (ac & 1) { /* row */ - if (!UP || !*UP) break; /* can't fix */ - ++up; /* incr row now, later move up */ - } else { /* column */ - if (!BC || !*BC) break; /* can't fix */ - ++bc; /* incr column, later backspace */ - } - (*r)++; - } -#endif /* !NO_SPECIAL_CHARS_FIXUP */ - } break; - case '>': if (av[ac] > (*ctl++ & 0377)) - av[ac] += *ctl; - ++ctl; break; - case 'r': atmp = av[0]; av[0] = av[1]; av[1] = atmp; - atmp = av[2]; av[2] = av[3]; av[3] = atmp; - --r; break; - case 'i': ++av[0]; ++av[1]; ++av[2]; ++av[3]; - --r; break; - case 'n': av[0] ^= 0140; av[1] ^= 0140; - av[2] ^= 0140; av[3] ^= 0140; - --r; break; - case 'B': av[0] = ((av[0] / 10) << 4) + (av[0] % 10); - av[1] = ((av[1] / 10) << 4) + (av[1] % 10); - av[2] = ((av[2] / 10) << 4) + (av[2] % 10); - av[3] = ((av[3] / 10) << 4) + (av[3] % 10); - --r; break; - case 'D': av[0] -= (av[0] & 15) << 1; - av[1] -= (av[1] & 15) << 1; - av[2] -= (av[2] & 15) << 1; - av[3] -= (av[3] & 15) << 1; - --r; break; - default: *++r = c; break; /* erroneous entry... */ - } - if (fmt) { - (void) sprintf(numbuf, fmt, av[ac++]); - for (z = numbuf; *z && r <= bufend; z++) - *r++ = *z; - --r; /* will be re-incremented below */ - } - } - if (++r > bufend) - return (char *)0; + /* avoid terminal driver intervention for + various control characters, to prevent + LF from becoming CR+LF, for instance; only + makes sense if this is a cursor positioning + sequence, but we have no way to check that */ + while (index("\004\t\n\013\f\r", *r)) { + if (ac & 1) { /* row */ + if (!UP || !*UP) + break; /* can't fix */ + ++up; /* incr row now, later move up */ + } else { /* column */ + if (!BC || !*BC) + break; /* can't fix */ + ++bc; /* incr column, later backspace */ + } + (*r)++; + } +#endif /* !NO_SPECIAL_CHARS_FIXUP */ + } + break; + case '>': + if (av[ac] > (*ctl++ & 0377)) + av[ac] += *ctl; + ++ctl; + break; + case 'r': + atmp = av[0]; + av[0] = av[1]; + av[1] = atmp; + atmp = av[2]; + av[2] = av[3]; + av[3] = atmp; + --r; + break; + case 'i': + ++av[0]; + ++av[1]; + ++av[2]; + ++av[3]; + --r; + break; + case 'n': + av[0] ^= 0140; + av[1] ^= 0140; + av[2] ^= 0140; + av[3] ^= 0140; + --r; + break; + case 'B': + av[0] = ((av[0] / 10) << 4) + (av[0] % 10); + av[1] = ((av[1] / 10) << 4) + (av[1] % 10); + av[2] = ((av[2] / 10) << 4) + (av[2] % 10); + av[3] = ((av[3] / 10) << 4) + (av[3] % 10); + --r; + break; + case 'D': + av[0] -= (av[0] & 15) << 1; + av[1] -= (av[1] & 15) << 1; + av[2] -= (av[2] & 15) << 1; + av[3] -= (av[3] & 15) << 1; + --r; + break; + default: + *++r = c; + break; /* erroneous entry... */ + } + if (fmt) { + (void) sprintf(numbuf, fmt, av[ac++]); + for (z = numbuf; *z && r <= bufend; z++) + *r++ = *z; + --r; /* will be re-incremented below */ + } + } + if (++r > bufend) + return (char *) 0; } #ifndef NO_SPECIAL_CHARS_FIXUP if (bc || up) { - while (--bc >= 0) - for (z = BC; *z && r <= bufend; z++) - *r++ = *z; - while (--up >= 0) - for (z = UP; *z && r <= bufend; z++) - *r++ = *z; - if (r > bufend) - return (char *)0; + while (--bc >= 0) + for (z = BC; *z && r <= bufend; z++) + *r++ = *z; + while (--up >= 0) + for (z = UP; *z && r <= bufend; z++) + *r++ = *z; + if (r > bufend) + return (char *) 0; } -#endif /* !NO_SPECIAL_CHARS_FIXUP */ +#endif /* !NO_SPECIAL_CHARS_FIXUP */ *r = '\0'; return buf; } /* send a string to the terminal, possibly padded with trailing NULs */ void -tputs( string, range, output_func ) -const char *string; /* characters to output */ -int range; /* number of lines affected, used for `*' delays */ -int (*output_func)(); /* actual output routine; return value ignored */ +tputs(string, range, output_func) +const char *string; /* characters to output */ +int range; /* number of lines affected, used for `*' delays */ +int (*output_func)(); /* actual output routine; return value ignored */ { register int c, num = 0; register const char *p = string; if (!p || !*p) - return; + return; /* pick out padding prefix, if any */ if (*p >= '0' && *p <= '9') { - do { /* note: scale `num' by 10 to accommodate fraction */ - num += (*p++ - '0'), num *= 10; - } while (*p >= '0' && *p <= '9'); - if (*p == '.') - ++p, num += (*p >= '0' && *p <= '9') ? (*p++ - '0') : 0; - if (*p == '*') - ++p, num *= range; + do { /* note: scale `num' by 10 to accommodate fraction */ + num += (*p++ - '0'), num *= 10; + } while (*p >= '0' && *p <= '9'); + if (*p == '.') + ++p, num += (*p >= '0' && *p <= '9') ? (*p++ - '0') : 0; + if (*p == '*') + ++p, num *= range; } /* output the string */ while ((c = *p++) != '\0') { - if (c == '\200') c = '\0'; /* undo tgetstr's encoding */ - (void) (*output_func)(c); + if (c == '\200') + c = '\0'; /* undo tgetstr's encoding */ + (void) (*output_func)(c); } #ifndef NO_DELAY_PADDING /* perform padding */ if (num) { - long pad; + long pad; - /* figure out how many chars needed to produce desired elapsed time */ - pad = (long)baud_rates[ospeed]; - if (pad < 0) pad *= -100L; - pad *= (long)num; - /* 100000 == 10 bits/char * (1000 millisec/sec scaled by 10) */ - num = (int)(pad / 100000L); /* number of characters */ + /* figure out how many chars needed to produce desired elapsed time */ + pad = (long) baud_rates[ospeed]; + if (pad < 0) + pad *= -100L; + pad *= (long) num; + /* 100000 == 10 bits/char * (1000 millisec/sec scaled by 10) */ + num = (int) (pad / 100000L); /* number of characters */ - c = PC; /* assume output_func isn't allowed to change PC */ - while (--num >= 0) - (void) (*output_func)(c); + c = PC; /* assume output_func isn't allowed to change PC */ + while (--num >= 0) + (void) (*output_func)(c); } -#endif /* !NO_DELAY_PADDING */ +#endif /* !NO_DELAY_PADDING */ return; } diff --git a/sys/share/unixtty.c b/sys/share/unixtty.c index b3e6598e3..006649328 100644 --- a/sys/share/unixtty.c +++ b/sys/share/unixtty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 unixtty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 unixtty.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ /* NetHack 3.6 unixtty.c $Date: 2012/01/23 07:11:09 $ $Revision: 1.10 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,124 +17,126 @@ * BSD still has the old sgttyb structure, but SYSV has termio. Thus: */ #if (defined(BSD) || defined(ULTRIX)) && !defined(POSIX_TYPES) -# define V7 +#define V7 #else -# define USG +#define USG #endif #ifdef USG -# ifdef POSIX_TYPES -# include -# include -# define termstruct termios -# else -# include -# if defined(TCSETS) && !defined(AIX_31) -# define termstruct termios -# else -# define termstruct termio -# endif -# endif /* POSIX_TYPES */ -# ifdef LINUX -# include -# undef delay_output /* curses redefines this */ -# include -# endif -# define kill_sym c_cc[VKILL] -# define erase_sym c_cc[VERASE] -# define intr_sym c_cc[VINTR] -# ifdef TAB3 /* not a POSIX flag, but some have it anyway */ -# define EXTABS TAB3 -# else -# define EXTABS 0 -# endif -# define tabflgs c_oflag -# define echoflgs c_lflag -# define cbrkflgs c_lflag -# define CBRKMASK ICANON -# define CBRKON ! /* reverse condition */ -# ifdef POSIX_TYPES -# define OSPEED(x) (speednum(cfgetospeed(&x))) -# else -# ifndef CBAUD -# define CBAUD _CBAUD /* for POSIX nitpickers (like RS/6000 cc) */ -# endif -# define OSPEED(x) ((x).c_cflag & CBAUD) -# endif -# define IS_7BIT(x) ((x).c_cflag & CS7) -# define inputflags c_iflag -# define STRIPHI ISTRIP -# ifdef POSIX_TYPES -# define GTTY(x) (tcgetattr(0, x)) -# define STTY(x) (tcsetattr(0, TCSADRAIN, x)) -# else -# if defined(TCSETS) && !defined(AIX_31) -# define GTTY(x) (ioctl(0, TCGETS, x)) -# define STTY(x) (ioctl(0, TCSETSW, x)) -# else -# define GTTY(x) (ioctl(0, TCGETA, x)) -# define STTY(x) (ioctl(0, TCSETAW, x)) -# endif -# endif /* POSIX_TYPES */ -# define GTTY2(x) 1 -# define STTY2(x) 1 -# ifdef POSIX_TYPES -# if defined(BSD) && !defined(__DGUX__) -# define nonesuch _POSIX_VDISABLE -# else -# define nonesuch (fpathconf(0, _PC_VDISABLE)) -# endif -# else -# define nonesuch 0 -# endif -# define inittyb2 inittyb -# define curttyb2 curttyb +#ifdef POSIX_TYPES +#include +#include +#define termstruct termios +#else +#include +#if defined(TCSETS) && !defined(AIX_31) +#define termstruct termios +#else +#define termstruct termio +#endif +#endif /* POSIX_TYPES */ +#ifdef LINUX +#include +#undef delay_output /* curses redefines this */ +#include +#endif +#define kill_sym c_cc[VKILL] +#define erase_sym c_cc[VERASE] +#define intr_sym c_cc[VINTR] +#ifdef TAB3 /* not a POSIX flag, but some have it anyway */ +#define EXTABS TAB3 +#else +#define EXTABS 0 +#endif +#define tabflgs c_oflag +#define echoflgs c_lflag +#define cbrkflgs c_lflag +#define CBRKMASK ICANON +#define CBRKON !/* reverse condition */ +#ifdef POSIX_TYPES +#define OSPEED(x) (speednum(cfgetospeed(&x))) +#else +#ifndef CBAUD +#define CBAUD _CBAUD /* for POSIX nitpickers (like RS/6000 cc) */ +#endif +#define OSPEED(x) ((x).c_cflag & CBAUD) +#endif +#define IS_7BIT(x) ((x).c_cflag & CS7) +#define inputflags c_iflag +#define STRIPHI ISTRIP +#ifdef POSIX_TYPES +#define GTTY(x) (tcgetattr(0, x)) +#define STTY(x) (tcsetattr(0, TCSADRAIN, x)) +#else +#if defined(TCSETS) && !defined(AIX_31) +#define GTTY(x) (ioctl(0, TCGETS, x)) +#define STTY(x) (ioctl(0, TCSETSW, x)) +#else +#define GTTY(x) (ioctl(0, TCGETA, x)) +#define STTY(x) (ioctl(0, TCSETAW, x)) +#endif +#endif /* POSIX_TYPES */ +#define GTTY2(x) 1 +#define STTY2(x) 1 +#ifdef POSIX_TYPES +#if defined(BSD) && !defined(__DGUX__) +#define nonesuch _POSIX_VDISABLE +#else +#define nonesuch (fpathconf(0, _PC_VDISABLE)) +#endif +#else +#define nonesuch 0 +#endif +#define inittyb2 inittyb +#define curttyb2 curttyb -#else /* V7 */ +#else /* V7 */ -# include -# define termstruct sgttyb -# define kill_sym sg_kill -# define erase_sym sg_erase -# define intr_sym t_intrc -# define EXTABS XTABS -# define tabflgs sg_flags -# define echoflgs sg_flags -# define cbrkflgs sg_flags -# define CBRKMASK CBREAK -# define CBRKON /* empty */ -# define inputflags sg_flags /* don't know how enabling meta bits */ -# define IS_7BIT(x) (FALSE) -# define STRIPHI 0 /* should actually be done on BSD */ -# define OSPEED(x) (x).sg_ospeed -# if defined(bsdi) || defined(__386BSD) || defined(SUNOS4) -# define GTTY(x) (ioctl(0, TIOCGETP, (char *)x)) -# define STTY(x) (ioctl(0, TIOCSETP, (char *)x)) -# else -# define GTTY(x) (gtty(0, x)) -# define STTY(x) (stty(0, x)) -# endif -# define GTTY2(x) (ioctl(0, TIOCGETC, (char *)x)) -# define STTY2(x) (ioctl(0, TIOCSETC, (char *)x)) -# define nonesuch -1 +#include +#define termstruct sgttyb +#define kill_sym sg_kill +#define erase_sym sg_erase +#define intr_sym t_intrc +#define EXTABS XTABS +#define tabflgs sg_flags +#define echoflgs sg_flags +#define cbrkflgs sg_flags +#define CBRKMASK CBREAK +#define CBRKON /* empty */ +#define inputflags sg_flags /* don't know how enabling meta bits */ +#define IS_7BIT(x) (FALSE) +#define STRIPHI 0 /* should actually be done on BSD */ +#define OSPEED(x) (x).sg_ospeed +#if defined(bsdi) || defined(__386BSD) || defined(SUNOS4) +#define GTTY(x) (ioctl(0, TIOCGETP, (char *) x)) +#define STTY(x) (ioctl(0, TIOCSETP, (char *) x)) +#else +#define GTTY(x) (gtty(0, x)) +#define STTY(x) (stty(0, x)) +#endif +#define GTTY2(x) (ioctl(0, TIOCGETC, (char *) x)) +#define STTY2(x) (ioctl(0, TIOCSETC, (char *) x)) +#define nonesuch -1 struct tchars inittyb2, curttyb2; -#endif /* V7 */ +#endif /* V7 */ -#if defined(TTY_GRAPHICS) && ((!defined(SYSV) && !defined(HPUX)) || defined(UNIXPC) || defined(SVR4)) -# ifndef LINT -extern /* it is defined in libtermlib (libtermcap) */ -# endif - short ospeed; /* terminal baudrate; set by gettty */ +#if defined(TTY_GRAPHICS) && ((!defined(SYSV) && !defined(HPUX)) \ + || defined(UNIXPC) || defined(SVR4)) +#ifndef LINT +extern /* it is defined in libtermlib (libtermcap) */ +#endif + short ospeed; /* terminal baudrate; set by gettty */ #else -short ospeed = 0; /* gets around "not defined" error message */ +short ospeed = 0; /* gets around "not defined" error message */ #endif #if defined(POSIX_TYPES) && defined(BSD) unsigned #endif - char erase_char, intr_char, kill_char; + char erase_char, + intr_char, kill_char; static boolean settty_needed = FALSE; struct termstruct inittyb, curttyb; @@ -143,34 +145,50 @@ static int speednum(speed) speed_t speed; { - switch (speed) { - case B0: return 0; - case B50: return 1; - case B75: return 2; - case B110: return 3; - case B134: return 4; - case B150: return 5; - case B200: return 6; - case B300: return 7; - case B600: return 8; - case B1200: return 9; - case B1800: return 10; - case B2400: return 11; - case B4800: return 12; - case B9600: return 13; - case B19200: return 14; - case B38400: return 15; - } + switch (speed) { + case B0: + return 0; + case B50: + return 1; + case B75: + return 2; + case B110: + return 3; + case B134: + return 4; + case B150: + return 5; + case B200: + return 6; + case B300: + return 7; + case B600: + return 8; + case B1200: + return 9; + case B1800: + return 10; + case B2400: + return 11; + case B4800: + return 12; + case B9600: + return 13; + case B19200: + return 14; + case B38400: + return 15; + } - return 0; + return 0; } #endif static void setctty() { - if(STTY(&curttyb) < 0 || STTY2(&curttyb2) < 0) - perror("NetHack (setctty)"); + if (STTY(&curttyb) < 0 || STTY2(&curttyb2) < 0) + perror("NetHack (setctty)"); } /* @@ -181,22 +199,22 @@ setctty() void gettty() { - if(GTTY(&inittyb) < 0 || GTTY2(&inittyb2) < 0) - perror("NetHack (gettty)"); - curttyb = inittyb; - curttyb2 = inittyb2; - ospeed = OSPEED(inittyb); - erase_char = inittyb.erase_sym; - kill_char = inittyb.kill_sym; - intr_char = inittyb2.intr_sym; - getioctls(); + if (GTTY(&inittyb) < 0 || GTTY2(&inittyb2) < 0) + perror("NetHack (gettty)"); + curttyb = inittyb; + curttyb2 = inittyb2; + ospeed = OSPEED(inittyb); + erase_char = inittyb.erase_sym; + kill_char = inittyb.kill_sym; + intr_char = inittyb2.intr_sym; + getioctls(); - /* do not expand tabs - they might be needed inside a cm sequence */ - if(curttyb.tabflgs & EXTABS) { - curttyb.tabflgs &= ~EXTABS; - setctty(); - } - settty_needed = TRUE; + /* do not expand tabs - they might be needed inside a cm sequence */ + if (curttyb.tabflgs & EXTABS) { + curttyb.tabflgs &= ~EXTABS; + setctty(); + } + settty_needed = TRUE; } /* reset terminal to original state */ @@ -204,115 +222,115 @@ void settty(s) const char *s; { - end_screen(); - if(s) raw_print(s); - if(STTY(&inittyb) < 0 || STTY2(&inittyb2) < 0) - perror("NetHack (settty)"); - iflags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF; - iflags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF; - curttyb.inputflags |= STRIPHI; - setioctls(); + end_screen(); + if (s) + raw_print(s); + if (STTY(&inittyb) < 0 || STTY2(&inittyb2) < 0) + perror("NetHack (settty)"); + iflags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF; + iflags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF; + curttyb.inputflags |= STRIPHI; + setioctls(); } void setftty() { - unsigned ef, cf; - int change = 0; + unsigned ef, cf; + int change = 0; - ef = 0; /* desired value of flags & ECHO */ - cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */ - iflags.cbreak = ON; - iflags.echo = OFF; - /* Should use (ECHO|CRMOD) here instead of ECHO */ - if ((unsigned)(curttyb.echoflgs & ECHO) != ef) { - curttyb.echoflgs &= ~ECHO; -/* curttyb.echoflgs |= ef; */ - change++; - } - if ((unsigned)(curttyb.cbrkflgs & CBRKMASK) != cf) { - curttyb.cbrkflgs &= ~CBRKMASK; - curttyb.cbrkflgs |= cf; + ef = 0; /* desired value of flags & ECHO */ + cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */ + iflags.cbreak = ON; + iflags.echo = OFF; + /* Should use (ECHO|CRMOD) here instead of ECHO */ + if ((unsigned) (curttyb.echoflgs & ECHO) != ef) { + curttyb.echoflgs &= ~ECHO; + /* curttyb.echoflgs |= ef; */ + change++; + } + if ((unsigned) (curttyb.cbrkflgs & CBRKMASK) != cf) { + curttyb.cbrkflgs &= ~CBRKMASK; + curttyb.cbrkflgs |= cf; #ifdef USG - /* be satisfied with one character; no timeout */ - curttyb.c_cc[VMIN] = 1; /* was VEOF */ - curttyb.c_cc[VTIME] = 0; /* was VEOL */ -# ifdef POSIX_JOB_CONTROL - /* turn off system suspend character - * due to differences in structure layout, this has to be - * here instead of in ioctl.c:getioctls() with the BSD - * equivalent - */ -# ifdef VSUSP /* real POSIX */ - curttyb.c_cc[VSUSP] = nonesuch; -# else /* other later SYSV */ - curttyb.c_cc[VSWTCH] = nonesuch; -# endif -# endif -# ifdef VDSUSP /* SunOS Posix extensions */ - curttyb.c_cc[VDSUSP] = nonesuch; -# endif -# ifdef VREPRINT - curttyb.c_cc[VREPRINT] = nonesuch; -# endif -# ifdef VDISCARD - curttyb.c_cc[VDISCARD] = nonesuch; -# endif -# ifdef VWERASE - curttyb.c_cc[VWERASE] = nonesuch; -# endif -# ifdef VLNEXT - curttyb.c_cc[VLNEXT] = nonesuch; -# endif + /* be satisfied with one character; no timeout */ + curttyb.c_cc[VMIN] = 1; /* was VEOF */ + curttyb.c_cc[VTIME] = 0; /* was VEOL */ +#ifdef POSIX_JOB_CONTROL +/* turn off system suspend character + * due to differences in structure layout, this has to be + * here instead of in ioctl.c:getioctls() with the BSD + * equivalent + */ +#ifdef VSUSP /* real POSIX */ + curttyb.c_cc[VSUSP] = nonesuch; +#else /* other later SYSV */ + curttyb.c_cc[VSWTCH] = nonesuch; #endif - change++; - } - if(!IS_7BIT(inittyb)) curttyb.inputflags &=~ STRIPHI; - /* If an interrupt character is used, it will be overriden and - * set to ^C. - */ - if(intr_char != nonesuch && curttyb2.intr_sym != '\003') { - curttyb2.intr_sym = '\003'; - change++; - } +#endif +#ifdef VDSUSP /* SunOS Posix extensions */ + curttyb.c_cc[VDSUSP] = nonesuch; +#endif +#ifdef VREPRINT + curttyb.c_cc[VREPRINT] = nonesuch; +#endif +#ifdef VDISCARD + curttyb.c_cc[VDISCARD] = nonesuch; +#endif +#ifdef VWERASE + curttyb.c_cc[VWERASE] = nonesuch; +#endif +#ifdef VLNEXT + curttyb.c_cc[VLNEXT] = nonesuch; +#endif +#endif + change++; + } + if (!IS_7BIT(inittyb)) + curttyb.inputflags &= ~STRIPHI; + /* If an interrupt character is used, it will be overriden and + * set to ^C. + */ + if (intr_char != nonesuch && curttyb2.intr_sym != '\003') { + curttyb2.intr_sym = '\003'; + change++; + } - if(change) setctty(); - start_screen(); + if (change) + setctty(); + start_screen(); } -void -intron() /* enable kbd interupts if enabled when game started */ +void intron() /* enable kbd interupts if enabled when game started */ { #ifdef TTY_GRAPHICS - /* Ugly hack to keep from changing tty modes for non-tty games -dlc */ - if (!strcmp(windowprocs.name, "tty") && - intr_char != nonesuch && curttyb2.intr_sym != '\003') { - curttyb2.intr_sym = '\003'; - setctty(); - } + /* Ugly hack to keep from changing tty modes for non-tty games -dlc */ + if (!strcmp(windowprocs.name, "tty") && intr_char != nonesuch + && curttyb2.intr_sym != '\003') { + curttyb2.intr_sym = '\003'; + setctty(); + } #endif } -void -introff() /* disable kbd interrupts if required*/ +void introff() /* disable kbd interrupts if required*/ { #ifdef TTY_GRAPHICS - /* Ugly hack to keep from changing tty modes for non-tty games -dlc */ - if (!strcmp(windowprocs.name, "tty") && - curttyb2.intr_sym != nonesuch) { - curttyb2.intr_sym = nonesuch; - setctty(); - } + /* Ugly hack to keep from changing tty modes for non-tty games -dlc */ + if (!strcmp(windowprocs.name, "tty") && curttyb2.intr_sym != nonesuch) { + curttyb2.intr_sym = nonesuch; + setctty(); + } #endif } -#ifdef _M_UNIX /* SCO UNIX (3.2.4), from Andreas Arens */ -# include +#ifdef _M_UNIX /* SCO UNIX (3.2.4), from Andreas Arens */ +#include -# define BSIZE (E_TABSZ*2) -# define LDIOC ('D'<<8) /* POSIX prevents definition */ +#define BSIZE (E_TABSZ * 2) +#define LDIOC ('D' << 8) /* POSIX prevents definition */ -# include +#include int sco_flag_console = 0; int sco_map_valid = -1; @@ -326,60 +344,59 @@ void NDECL(init_sco_cons); void sco_mapon() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { - if (sco_map_valid != -1) { - ioctl(0,LDSMAP,sco_chanmap_buf); - } - sco_map_valid = -1; - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { + if (sco_map_valid != -1) { + ioctl(0, LDSMAP, sco_chanmap_buf); + } + sco_map_valid = -1; + } +#endif } void sco_mapoff() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { - sco_map_valid = ioctl(0,LDGMAP,sco_chanmap_buf); - if (sco_map_valid != -1) { - ioctl(0,LDNMAP,(char *)0); - } - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { + sco_map_valid = ioctl(0, LDGMAP, sco_chanmap_buf); + if (sco_map_valid != -1) { + ioctl(0, LDNMAP, (char *) 0); + } + } +#endif } void check_sco_console() { - if (isatty(0) && ioctl(0,CONS_GET,0) != -1) { - sco_flag_console = 1; - } + if (isatty(0) && ioctl(0, CONS_GET, 0) != -1) { + sco_flag_console = 1; + } } void init_sco_cons() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { - atexit(sco_mapon); - sco_mapoff(); - load_symset("IBMGraphics", PRIMARY); - load_symset("RogueIBM", ROGUESET); - switch_symbols(TRUE); -# ifdef TEXTCOLOR - if (has_colors()) - iflags.use_color = TRUE; -# endif - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && sco_flag_console) { + atexit(sco_mapon); + sco_mapoff(); + load_symset("IBMGraphics", PRIMARY); + load_symset("RogueIBM", ROGUESET); + switch_symbols(TRUE); +#ifdef TEXTCOLOR + if (has_colors()) + iflags.use_color = TRUE; +#endif + } +#endif } -#endif /* _M_UNIX */ +#endif /* _M_UNIX */ - -#ifdef __linux__ /* via Jesse Thilo and Ben Gertzfield */ -# include -# include +#ifdef __linux__ /* via Jesse Thilo and Ben Gertzfield */ +#include +#include int linux_flag_console = 0; @@ -391,62 +408,61 @@ void NDECL(init_linux_cons); void linux_mapon() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { - write(1, "\033(B", 3); - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { + write(1, "\033(B", 3); + } +#endif } void linux_mapoff() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { - write(1, "\033(U", 3); - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { + write(1, "\033(U", 3); + } +#endif } void check_linux_console() { - struct vt_mode vtm; + struct vt_mode vtm; - if (isatty(0) && ioctl(0,VT_GETMODE,&vtm) >= 0) { - linux_flag_console = 1; - } + if (isatty(0) && ioctl(0, VT_GETMODE, &vtm) >= 0) { + linux_flag_console = 1; + } } void init_linux_cons() { -# ifdef TTY_GRAPHICS - if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { - atexit(linux_mapon); - linux_mapoff(); -# ifdef TEXTCOLOR - if (has_colors()) - iflags.use_color = TRUE; -# endif - } -# endif +#ifdef TTY_GRAPHICS + if (!strcmp(windowprocs.name, "tty") && linux_flag_console) { + atexit(linux_mapon); + linux_mapoff(); +#ifdef TEXTCOLOR + if (has_colors()) + iflags.use_color = TRUE; +#endif + } +#endif } -#endif /* __linux__ */ +#endif /* __linux__ */ - -#ifndef __begui__ /* the Be GUI will define its own error proc */ +#ifndef __begui__ /* the Be GUI will define its own error proc */ /* fatal error */ /*VARARGS1*/ -void -error VA_DECL(const char *,s) - VA_START(s); - VA_INIT(s, const char *); - if(settty_needed) - settty((char *)0); - Vprintf(s,VA_ARGS); - (void) putchar('\n'); - VA_END(); - exit(EXIT_FAILURE); +void error +VA_DECL(const char *, s) + VA_START(s); + VA_INIT(s, const char *); + if (settty_needed) + settty((char *) 0); + Vprintf(s, VA_ARGS); + (void) putchar('\n'); + VA_END(); + exit(EXIT_FAILURE); } #endif /* !__begui__ */ diff --git a/sys/share/uudecode.c b/sys/share/uudecode.c index 440bcaf14..5575f0c1f 100644 --- a/sys/share/uudecode.c +++ b/sys/share/uudecode.c @@ -32,7 +32,7 @@ * but other programs such as zoo or arc may or may not require the file * to be "BILFed" (or "unBILFed" or whatever). Also, unlike the other * flavors, VMS files don't get overwritten (a higher version is created). - * + * * Modified 13 April 1991 by Gary Mussar to be forgiving of systems that * appear to be stripping trailing blanks. * @@ -41,7 +41,7 @@ * Modified 08 July 2006 to cast strlen() result to int to suppress a * warning on platforms where size_t > sizeof(int). * - * $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ + * $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ * $Date: 2006/07/09 16:42:21 $ $Revision: 1.4 $ */ @@ -49,7 +49,7 @@ static char sccsid[] = "@(#)uudecode.c 5.5 (Berkeley) 7/6/88"; #endif /* not lint */ -#ifdef __MSDOS__ /* For Turbo C */ +#ifdef __MSDOS__ /* For Turbo C */ #define MSDOS 1 #endif @@ -70,108 +70,110 @@ static char sccsid[] = "@(#)uudecode.c 5.5 (Berkeley) 7/6/88"; #include #ifdef VMS -# include -# include +#include +#include #else -# if !defined(MSDOS) && !defined(WIN32) -# include -# endif -# include /* MSDOS, WIN32, or UNIX */ -# include -# include -# include +#if !defined(MSDOS) && !defined(WIN32) +#include +#endif +#include /* MSDOS, WIN32, or UNIX */ +#include +#include +#include #endif static void decode(FILE *, FILE *); static void outdec(char *, FILE *, int); /* single-character decode */ -#define DEC(c) (((c) - ' ') & 077) +#define DEC(c) (((c) - ' ') & 077) -int main(argc, argv) +int +main(argc, argv) int argc; char **argv; { - FILE *in, *out; - int mode; - char dest[128]; - char buf[80]; + FILE *in, *out; + int mode; + char dest[128]; + char buf[80]; - /* optional input arg */ - if (argc > 1) { - if ((in = fopen(argv[1], "r")) == NULL) { - perror(argv[1]); - exit(1); - } - argv++; argc--; - } else - in = stdin; + /* optional input arg */ + if (argc > 1) { + if ((in = fopen(argv[1], "r")) == NULL) { + perror(argv[1]); + exit(1); + } + argv++; + argc--; + } else + in = stdin; - if (argc != 1) { - printf("Usage: uudecode [infile]\n"); - exit(2); - } + if (argc != 1) { + printf("Usage: uudecode [infile]\n"); + exit(2); + } - /* search for header line */ - for (;;) { - if (fgets(buf, sizeof buf, in) == NULL) { - fprintf(stderr, "No begin line\n"); - exit(3); - } - if (strncmp(buf, "begin ", 6) == 0) - break; - } - (void)sscanf(buf, "begin %o %s", &mode, dest); + /* search for header line */ + for (;;) { + if (fgets(buf, sizeof buf, in) == NULL) { + fprintf(stderr, "No begin line\n"); + exit(3); + } + if (strncmp(buf, "begin ", 6) == 0) + break; + } + (void) sscanf(buf, "begin %o %s", &mode, dest); #if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) - /* handle ~user/file format */ - if (dest[0] == '~') { - char *sl; - struct passwd *getpwnam(); - struct passwd *user; - char dnbuf[100], *index(), *strcat(), *strcpy(); + /* handle ~user/file format */ + if (dest[0] == '~') { + char *sl; + struct passwd *getpwnam(); + struct passwd *user; + char dnbuf[100], *index(), *strcat(), *strcpy(); - sl = index(dest, '/'); - if (sl == NULL) { - fprintf(stderr, "Illegal ~user\n"); - exit(3); - } - *sl++ = 0; - user = getpwnam(dest+1); - if (user == NULL) { - fprintf(stderr, "No such user as %s\n", dest); - exit(4); - } - strcpy(dnbuf, user->pw_dir); - strcat(dnbuf, "/"); - strcat(dnbuf, sl); - strcpy(dest, dnbuf); - } -#endif /* !defined(MSDOS) && !defined(VMS) */ + sl = index(dest, '/'); + if (sl == NULL) { + fprintf(stderr, "Illegal ~user\n"); + exit(3); + } + *sl++ = 0; + user = getpwnam(dest + 1); + if (user == NULL) { + fprintf(stderr, "No such user as %s\n", dest); + exit(4); + } + strcpy(dnbuf, user->pw_dir); + strcat(dnbuf, "/"); + strcat(dnbuf, sl); + strcpy(dest, dnbuf); + } +#endif /* !defined(MSDOS) && !defined(VMS) */ - /* create output file */ +/* create output file */ #if defined(MSDOS) || defined(WIN32) - out = fopen(dest, "wb"); /* Binary file */ + out = fopen(dest, "wb"); /* Binary file */ #else - out = fopen(dest, "w"); + out = fopen(dest, "w"); #endif - if (out == NULL) { - perror(dest); - exit(4); - } -#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) /* i.e., UNIX */ - chmod(dest, mode); + if (out == NULL) { + perror(dest); + exit(4); + } +#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) /* i.e., UNIX */ + chmod(dest, mode); #endif - decode(in, out); + decode(in, out); - if (fgets(buf, sizeof buf, in) == NULL || strcmp(buf, "end\n")) { - fprintf(stderr, "No end line\n"); - exit(5); - } - exit(0); - /*NOTREACHED*/ - return 0; + if (fgets(buf, sizeof buf, in) == NULL || strcmp(buf, "end\n")) { + fprintf(stderr, "No end line\n"); + exit(5); + } + exit(0); + /*NOTREACHED*/ + return 0; } /* @@ -182,31 +184,32 @@ decode(in, out) FILE *in; FILE *out; { - char buf[80]; - char *bp; - int n, i, expected; + char buf[80]; + char *bp; + int n, i, expected; - for (;;) { - /* for each input line */ - if (fgets(buf, sizeof buf, in) == NULL) { - printf("Short file\n"); - exit(10); - } - n = DEC(buf[0]); - if ((n <= 0) || (buf[0] == '\n')) - break; + for (;;) { + /* for each input line */ + if (fgets(buf, sizeof buf, in) == NULL) { + printf("Short file\n"); + exit(10); + } + n = DEC(buf[0]); + if ((n <= 0) || (buf[0] == '\n')) + break; - /* Calculate expected # of chars and pad if necessary */ - expected = ((n+2)/3)<<2; - for (i = (int)strlen(buf)-1; i <= expected; i++) buf[i] = ' '; + /* Calculate expected # of chars and pad if necessary */ + expected = ((n + 2) / 3) << 2; + for (i = (int) strlen(buf) - 1; i <= expected; i++) + buf[i] = ' '; - bp = &buf[1]; - while (n > 0) { - outdec(bp, out, n); - bp += 4; - n -= 3; - } - } + bp = &buf[1]; + while (n > 0) { + outdec(bp, out, n); + bp += 4; + n -= 3; + } + } } /* @@ -221,17 +224,17 @@ char *p; FILE *f; int n; { - int c1, c2, c3; + int c1, c2, c3; - c1 = DEC(*p) << 2 | DEC(p[1]) >> 4; - c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2; - c3 = DEC(p[2]) << 6 | DEC(p[3]); - if (n >= 1) - putc(c1, f); - if (n >= 2) - putc(c2, f); - if (n >= 3) - putc(c3, f); + c1 = DEC(*p) << 2 | DEC(p[1]) >> 4; + c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2; + c3 = DEC(p[2]) << 6 | DEC(p[3]); + if (n >= 1) + putc(c1, f); + if (n >= 2) + putc(c2, f); + if (n >= 3) + putc(c3, f); } #if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) @@ -241,18 +244,17 @@ int n; */ #ifndef NULL -#define NULL 0 +#define NULL 0 #endif char * index(sp, c) register char *sp, c; { - do { - if (*sp == c) - return(sp); - } while (*sp++); - return(NULL); + do { + if (*sp == c) + return (sp); + } while (*sp++); + return (NULL); } #endif - diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index f9faf5120..a588989a5 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 unixmain.c $NHDT-Date: 1427074144 2015/03/23 01:29:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.45 $ */ +/* NetHack 3.6 unixmain.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.51 $ */ /* NetHack 3.6 unixmain.c $Date: 2012/01/27 20:15:31 $ $Revision: 1.42 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,17 +17,17 @@ #endif #if !defined(_BULL_SOURCE) && !defined(__sgi) && !defined(_M_UNIX) -# if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) -# if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) -extern struct passwd *FDECL(getpwuid,(uid_t)); -# else -extern struct passwd *FDECL(getpwuid,(int)); -# endif -# endif +#if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) +#if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) +extern struct passwd *FDECL(getpwuid, (uid_t)); +#else +extern struct passwd *FDECL(getpwuid, (int)); #endif -extern struct passwd *FDECL(getpwnam,(const char *)); +#endif +#endif +extern struct passwd *FDECL(getpwnam, (const char *)); #ifdef CHDIR -static void FDECL(chdirx, (const char *,BOOLEAN_P)); +static void FDECL(chdirx, (const char *, BOOLEAN_P)); #endif /* CHDIR */ static boolean NDECL(whoami); static void FDECL(process_options, (int, char **)); @@ -46,277 +46,281 @@ static boolean wiz_error_flag = FALSE; static struct passwd *NDECL(get_unix_pw); int -main(argc,argv) +main(argc, argv) int argc; char *argv[]; { - register int fd; + register int fd; #ifdef CHDIR - register char *dir; + register char *dir; #endif - boolean exact_username; - boolean resuming = FALSE; /* assume new game */ + boolean exact_username; + boolean resuming = FALSE; /* assume new game */ - sys_early_init(); + sys_early_init(); #if defined(__APPLE__) - { - /* special hack to change working directory to a resource fork when - running from finder --sam */ + { +/* special hack to change working directory to a resource fork when + running from finder --sam */ #define MAC_PATH_VALUE ".app/Contents/MacOS/" - char mac_cwd[1024], *mac_exe = argv[0], *mac_tmp; - int arg0_len = strlen(mac_exe), mac_tmp_len, mac_lhs_len=0; - getcwd(mac_cwd, 1024); - if(mac_exe[0] == '/' && !strcmp(mac_cwd, "/")) { - if((mac_exe = strrchr(mac_exe, '/'))) - mac_exe++; - else - mac_exe = argv[0]; - mac_tmp_len = (strlen(mac_exe) * 2) + strlen(MAC_PATH_VALUE); - if(mac_tmp_len <= arg0_len) { - mac_tmp = malloc(mac_tmp_len + 1); - sprintf(mac_tmp, "%s%s%s", mac_exe, MAC_PATH_VALUE, mac_exe); - if(!strcmp(argv[0] + (arg0_len - mac_tmp_len), mac_tmp)) { - mac_lhs_len = (arg0_len - mac_tmp_len) + strlen(mac_exe) + 5; - if(mac_lhs_len > mac_tmp_len - 1) - mac_tmp = realloc(mac_tmp, mac_lhs_len); - strncpy(mac_tmp, argv[0], mac_lhs_len); - mac_tmp[mac_lhs_len] = '\0'; - chdir(mac_tmp); - } - free(mac_tmp); - } - } - } + char mac_cwd[1024], *mac_exe = argv[0], *mac_tmp; + int arg0_len = strlen(mac_exe), mac_tmp_len, mac_lhs_len = 0; + getcwd(mac_cwd, 1024); + if (mac_exe[0] == '/' && !strcmp(mac_cwd, "/")) { + if ((mac_exe = strrchr(mac_exe, '/'))) + mac_exe++; + else + mac_exe = argv[0]; + mac_tmp_len = (strlen(mac_exe) * 2) + strlen(MAC_PATH_VALUE); + if (mac_tmp_len <= arg0_len) { + mac_tmp = malloc(mac_tmp_len + 1); + sprintf(mac_tmp, "%s%s%s", mac_exe, MAC_PATH_VALUE, mac_exe); + if (!strcmp(argv[0] + (arg0_len - mac_tmp_len), mac_tmp)) { + mac_lhs_len = + (arg0_len - mac_tmp_len) + strlen(mac_exe) + 5; + if (mac_lhs_len > mac_tmp_len - 1) + mac_tmp = realloc(mac_tmp, mac_lhs_len); + strncpy(mac_tmp, argv[0], mac_lhs_len); + mac_tmp[mac_lhs_len] = '\0'; + chdir(mac_tmp); + } + free(mac_tmp); + } + } + } #endif - hname = argv[0]; - hackpid = getpid(); - (void) umask(0777 & ~FCMASK); + hname = argv[0]; + hackpid = getpid(); + (void) umask(0777 & ~FCMASK); - choose_windows(DEFAULT_WINDOW_SYS); + choose_windows(DEFAULT_WINDOW_SYS); -#ifdef CHDIR /* otherwise no chdir() */ - /* - * See if we must change directory to the playground. - * (Perhaps hack runs suid and playground is inaccessible - * for the player.) - * The environment variable HACKDIR is overridden by a - * -d command line option (must be the first option given) - */ - dir = nh_getenv("NETHACKDIR"); - if (!dir) dir = nh_getenv("HACKDIR"); +#ifdef CHDIR /* otherwise no chdir() */ + /* + * See if we must change directory to the playground. + * (Perhaps hack runs suid and playground is inaccessible + * for the player.) + * The environment variable HACKDIR is overridden by a + * -d command line option (must be the first option given) + */ + dir = nh_getenv("NETHACKDIR"); + if (!dir) + dir = nh_getenv("HACKDIR"); #endif - if(argc > 1) { + if (argc > 1) { #ifdef CHDIR - if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { - /* avoid matching "-dec" for DECgraphics; since the man page - * says -d directory, hope nobody's using -desomething_else - */ - argc--; - argv++; - dir = argv[0]+2; - if(*dir == '=' || *dir == ':') dir++; - if(!*dir && argc > 1) { - argc--; - argv++; - dir = argv[0]; - } - if(!*dir) - error("Flag -d must be followed by a directory name."); - } - if (argc > 1) + if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { + /* avoid matching "-dec" for DECgraphics; since the man page + * says -d directory, hope nobody's using -desomething_else + */ + argc--; + argv++; + dir = argv[0] + 2; + if (*dir == '=' || *dir == ':') + dir++; + if (!*dir && argc > 1) { + argc--; + argv++; + dir = argv[0]; + } + if (!*dir) + error("Flag -d must be followed by a directory name."); + } + if (argc > 1) #endif /* CHDIR */ - /* - * Now we know the directory containing 'record' and - * may do a prscore(). Exclude `-style' - it's a Qt option. - */ - if (!strncmp(argv[1], "-s", 2) && strncmp(argv[1], "-style", 6)) { + /* + * Now we know the directory containing 'record' and + * may do a prscore(). Exclude `-style' - it's a Qt option. + */ + if (!strncmp(argv[1], "-s", 2) && strncmp(argv[1], "-style", 6)) { #ifdef CHDIR - chdirx(dir,0); + chdirx(dir, 0); #endif #ifdef SYSCF - initoptions(); + initoptions(); #endif #ifdef PANICTRACE - ARGV0 = argv[0]; /* save for possible stack trace */ -# ifndef NO_SIGNAL - panictrace_setsignals(TRUE); -# endif -#endif - prscore(argc, argv); - exit(EXIT_SUCCESS); - } - } - - /* - * Change directories before we initialize the window system so - * we can find the tile file. - */ -#ifdef CHDIR - chdirx(dir,1); -#endif - -#ifdef _M_UNIX - check_sco_console(); -#endif -#ifdef __linux__ - check_linux_console(); -#endif - initoptions(); -#ifdef PANICTRACE - ARGV0 = argv[0]; /* save for possible stack trace */ -# ifndef NO_SIGNAL - panictrace_setsignals(TRUE); -# endif -#endif - exact_username = whoami(); - - /* - * It seems you really want to play. - */ - u.uhp = 1; /* prevent RIP on early quits */ - program_state.preserve_locks = 1; + ARGV0 = argv[0]; /* save for possible stack trace */ #ifndef NO_SIGNAL - sethanguphandler((SIG_RET_TYPE)hangup); + panictrace_setsignals(TRUE); +#endif +#endif + prscore(argc, argv); + exit(EXIT_SUCCESS); + } + } + +/* + * Change directories before we initialize the window system so + * we can find the tile file. + */ +#ifdef CHDIR + chdirx(dir, 1); #endif - process_options(argc, argv); /* command line options */ -#ifdef WINCHAIN - commit_windowchain(); -#endif - init_nhwindows(&argc, argv); /* now we can set up window system */ #ifdef _M_UNIX - init_sco_cons(); + check_sco_console(); #endif #ifdef __linux__ - init_linux_cons(); + check_linux_console(); +#endif + initoptions(); +#ifdef PANICTRACE + ARGV0 = argv[0]; /* save for possible stack trace */ +#ifndef NO_SIGNAL + panictrace_setsignals(TRUE); +#endif +#endif + exact_username = whoami(); + + /* + * It seems you really want to play. + */ + u.uhp = 1; /* prevent RIP on early quits */ + program_state.preserve_locks = 1; +#ifndef NO_SIGNAL + sethanguphandler((SIG_RET_TYPE) hangup); +#endif + + process_options(argc, argv); /* command line options */ +#ifdef WINCHAIN + commit_windowchain(); +#endif + init_nhwindows(&argc, argv); /* now we can set up window system */ +#ifdef _M_UNIX + init_sco_cons(); +#endif +#ifdef __linux__ + init_linux_cons(); #endif #ifdef DEF_PAGER - if(!(catmore = nh_getenv("HACKPAGER")) && !(catmore = nh_getenv("PAGER"))) - catmore = DEF_PAGER; + if (!(catmore = nh_getenv("HACKPAGER")) + && !(catmore = nh_getenv("PAGER"))) + catmore = DEF_PAGER; #endif #ifdef MAIL - getmailstatus(); + getmailstatus(); #endif - /* wizard mode access is deferred until here */ - set_playmode(); /* sets plname to "wizard" for wizard mode */ - if (exact_username) { - /* - * FIXME: this no longer works, ever since 3.3.0 - * when plnamesuffix() was changed to find - * Name-Role-Race-Gender-Alignment. It removes - * all dashes rather than just the last one, - * regardless of whether whatever follows each - * dash matches role, race, gender, or alignment. - */ - /* guard against user names with hyphens in them */ - int len = strlen(plname); - /* append the current role, if any, so that last dash is ours */ - if (++len < (int)sizeof plname) - (void)strncat(strcat(plname, "-"), - pl_character, sizeof plname - len - 1); - } - /* strip role,race,&c suffix; calls askname() if plname[] is empty - or holds a generic user name like "player" or "games" */ - plnamesuffix(); + /* wizard mode access is deferred until here */ + set_playmode(); /* sets plname to "wizard" for wizard mode */ + if (exact_username) { + /* + * FIXME: this no longer works, ever since 3.3.0 + * when plnamesuffix() was changed to find + * Name-Role-Race-Gender-Alignment. It removes + * all dashes rather than just the last one, + * regardless of whether whatever follows each + * dash matches role, race, gender, or alignment. + */ + /* guard against user names with hyphens in them */ + int len = strlen(plname); + /* append the current role, if any, so that last dash is ours */ + if (++len < (int) sizeof plname) + (void) strncat(strcat(plname, "-"), pl_character, + sizeof plname - len - 1); + } + /* strip role,race,&c suffix; calls askname() if plname[] is empty + or holds a generic user name like "player" or "games" */ + plnamesuffix(); - if (wizard) { - /* use character name rather than lock letter for file names */ - locknum = 0; - } else { - /* suppress interrupts while processing lock file */ - (void) signal(SIGQUIT,SIG_IGN); - (void) signal(SIGINT,SIG_IGN); - } - /* - * getlock() complains and quits if there is already a game - * in progress for current character name (when locknum == 0) - * or if there are too many active games (when locknum > 0). - * When proceeding, it creates an empty .0 file to - * designate the current game. - * getlock() constructs based on the character - * name (for !locknum) or on first available of alock, block, - * clock, &c not currently in use in the playground directory - * (for locknum > 0). - */ - getlock(); - program_state.preserve_locks = 0; /* after getlock() */ + if (wizard) { + /* use character name rather than lock letter for file names */ + locknum = 0; + } else { + /* suppress interrupts while processing lock file */ + (void) signal(SIGQUIT, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + } + /* + * getlock() complains and quits if there is already a game + * in progress for current character name (when locknum == 0) + * or if there are too many active games (when locknum > 0). + * When proceeding, it creates an empty .0 file to + * designate the current game. + * getlock() constructs based on the character + * name (for !locknum) or on first available of alock, block, + * clock, &c not currently in use in the playground directory + * (for locknum > 0). + */ + getlock(); + program_state.preserve_locks = 0; /* after getlock() */ - dlb_init(); /* must be before newgame() */ + dlb_init(); /* must be before newgame() */ - /* - * Initialize the vision system. This must be before mklev() on a - * new game or before a level restore on a saved game. - */ - vision_init(); + /* + * Initialize the vision system. This must be before mklev() on a + * new game or before a level restore on a saved game. + */ + vision_init(); - display_gamewindows(); + display_gamewindows(); - /* - * First, try to find and restore a save file for specified character. - * We'll return here if new game player_selection() renames the hero. - */ - attempt_restore: - if ((fd = restore_saved_game()) >= 0) { - const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); +/* + * First, try to find and restore a save file for specified character. + * We'll return here if new game player_selection() renames the hero. + */ +attempt_restore: + if ((fd = restore_saved_game()) >= 0) { + const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); - (void) chmod(fq_save,0); /* disallow parallel restores */ + (void) chmod(fq_save, 0); /* disallow parallel restores */ #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); + (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif #ifdef NEWS - if(iflags.news) { - display_file(NEWS, FALSE); - iflags.news = FALSE; /* in case dorecover() fails */ - } + if (iflags.news) { + display_file(NEWS, FALSE); + iflags.news = FALSE; /* in case dorecover() fails */ + } #endif - pline("Restoring save file..."); - mark_synch(); /* flush output */ - if (dorecover(fd)) { - resuming = TRUE; /* not starting new game */ - wd_message(); - if (discover || wizard) { - if(yn("Do you want to keep the save file?") == 'n') - (void) delete_savefile(); - else { - (void) chmod(fq_save,FCMASK); /* back to readable */ - nh_compress(fq_save); - } - } - } - } + pline("Restoring save file..."); + mark_synch(); /* flush output */ + if (dorecover(fd)) { + resuming = TRUE; /* not starting new game */ + wd_message(); + if (discover || wizard) { + if (yn("Do you want to keep the save file?") == 'n') + (void) delete_savefile(); + else { + (void) chmod(fq_save, FCMASK); /* back to readable */ + nh_compress(fq_save); + } + } + } + } - if (!resuming) { - /* new game: start by choosing role, race, etc; - player might change the hero's name while doing that, - in which case we try to restore under the new name - and skip selection this time if that didn't succeed */ - if (!iflags.renameinprogress) { - player_selection(); - if (iflags.renameinprogress) { - /* player has renamed the hero while selecting role; - if locking alphabetically, the existing lock file - can still be used; otherwise, discard current one - and create another for the new character name */ - if (!locknum) { - delete_levelfile(0); /* remove empty lock file */ - getlock(); - } - goto attempt_restore; - } - } - newgame(); - wd_message(); - } + if (!resuming) { + /* new game: start by choosing role, race, etc; + player might change the hero's name while doing that, + in which case we try to restore under the new name + and skip selection this time if that didn't succeed */ + if (!iflags.renameinprogress) { + player_selection(); + if (iflags.renameinprogress) { + /* player has renamed the hero while selecting role; + if locking alphabetically, the existing lock file + can still be used; otherwise, discard current one + and create another for the new character name */ + if (!locknum) { + delete_levelfile(0); /* remove empty lock file */ + getlock(); + } + goto attempt_restore; + } + } + newgame(); + wd_message(); + } - moveloop(resuming); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return(0); + moveloop(resuming); + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return (0); } static void @@ -324,110 +328,111 @@ process_options(argc, argv) int argc; char *argv[]; { - int i, l; + int i, l; - /* - * Process options. - */ - while(argc > 1 && argv[1][0] == '-'){ - argv++; - argc--; - l = (int)strlen(*argv); - /* must supply at least 4 chars to match "-XXXgraphics" */ - if (l < 4) l = 4; + /* + * Process options. + */ + while (argc > 1 && argv[1][0] == '-') { + argv++; + argc--; + l = (int) strlen(*argv); + /* must supply at least 4 chars to match "-XXXgraphics" */ + if (l < 4) + l = 4; - switch(argv[0][1]){ - case 'D': - case 'd': - if ((argv[0][1] == 'D' && !argv[0][2]) - || !strcmpi(*argv, "-debug")) { - wizard = TRUE, discover = FALSE; - } else if (!strncmpi(*argv, "-DECgraphics", l)) { - load_symset("DECGraphics", PRIMARY); - switch_symbols(TRUE); - } else { - raw_printf("Unknown option: %s", *argv); - } - break; - case 'X': + switch (argv[0][1]) { + case 'D': + case 'd': + if ((argv[0][1] == 'D' && !argv[0][2]) + || !strcmpi(*argv, "-debug")) { + wizard = TRUE, discover = FALSE; + } else if (!strncmpi(*argv, "-DECgraphics", l)) { + load_symset("DECGraphics", PRIMARY); + switch_symbols(TRUE); + } else { + raw_printf("Unknown option: %s", *argv); + } + break; + case 'X': - discover = TRUE, wizard = FALSE; - break; + discover = TRUE, wizard = FALSE; + break; #ifdef NEWS - case 'n': - iflags.news = FALSE; - break; + case 'n': + iflags.news = FALSE; + break; #endif - case 'u': - if(argv[0][2]) - (void) strncpy(plname, argv[0]+2, sizeof(plname)-1); - else if(argc > 1) { - argc--; - argv++; - (void) strncpy(plname, argv[0], sizeof(plname)-1); - } else - raw_print("Player name expected after -u"); - break; - case 'I': - case 'i': - if (!strncmpi(*argv, "-IBMgraphics", l)) { - load_symset("IBMGraphics", PRIMARY); - load_symset("RogueIBM", ROGUESET); - switch_symbols(TRUE); - } else { - raw_printf("Unknown option: %s", *argv); - } - break; - case 'p': /* profession (role) */ - if (argv[0][2]) { - if ((i = str2role(&argv[0][2])) >= 0) - flags.initrole = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2role(argv[0])) >= 0) - flags.initrole = i; - } - break; - case 'r': /* race */ - if (argv[0][2]) { - if ((i = str2race(&argv[0][2])) >= 0) - flags.initrace = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2race(argv[0])) >= 0) - flags.initrace = i; - } - break; - case 'w': /* windowtype */ - choose_windows(&argv[0][2]); - break; - case '@': - flags.randomall = 1; - break; - default: - if ((i = str2role(&argv[0][1])) >= 0) { - flags.initrole = i; - break; - } - /* else raw_printf("Unknown option: %s", *argv); */ - } - } + case 'u': + if (argv[0][2]) + (void) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); + else if (argc > 1) { + argc--; + argv++; + (void) strncpy(plname, argv[0], sizeof(plname) - 1); + } else + raw_print("Player name expected after -u"); + break; + case 'I': + case 'i': + if (!strncmpi(*argv, "-IBMgraphics", l)) { + load_symset("IBMGraphics", PRIMARY); + load_symset("RogueIBM", ROGUESET); + switch_symbols(TRUE); + } else { + raw_printf("Unknown option: %s", *argv); + } + break; + case 'p': /* profession (role) */ + if (argv[0][2]) { + if ((i = str2role(&argv[0][2])) >= 0) + flags.initrole = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2role(argv[0])) >= 0) + flags.initrole = i; + } + break; + case 'r': /* race */ + if (argv[0][2]) { + if ((i = str2race(&argv[0][2])) >= 0) + flags.initrace = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2race(argv[0])) >= 0) + flags.initrace = i; + } + break; + case 'w': /* windowtype */ + choose_windows(&argv[0][2]); + break; + case '@': + flags.randomall = 1; + break; + default: + if ((i = str2role(&argv[0][1])) >= 0) { + flags.initrole = i; + break; + } + /* else raw_printf("Unknown option: %s", *argv); */ + } + } - /* XXX This is deprecated in favor of SYSCF with MAXPLAYERS. Make - * an error in next release. */ - if(argc > 1) - locknum = atoi(argv[1]); + /* XXX This is deprecated in favor of SYSCF with MAXPLAYERS. Make + * an error in next release. */ + if (argc > 1) + locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS - /* limit to compile-time limit */ - if(!locknum || locknum > MAX_NR_OF_PLAYERS) - locknum = MAX_NR_OF_PLAYERS; + /* limit to compile-time limit */ + if (!locknum || locknum > MAX_NR_OF_PLAYERS) + locknum = MAX_NR_OF_PLAYERS; #endif #ifdef SYSCF - /* let syscf override compile-time limit */ - if(!locknum || (sysopt.maxplayers && locknum > sysopt.maxplayers)) - locknum = sysopt.maxplayers; + /* let syscf override compile-time limit */ + if (!locknum || (sysopt.maxplayers && locknum > sysopt.maxplayers)) + locknum = sysopt.maxplayers; #endif } @@ -437,55 +442,55 @@ chdirx(dir, wr) const char *dir; boolean wr; { - if (dir /* User specified directory? */ -# ifdef HACKDIR - && strcmp(dir, HACKDIR) /* and not the default? */ -# endif - ) { -# ifdef SECURE - (void) setgid(getgid()); - (void) setuid(getuid()); /* Ron Wessels */ -# endif - } else { - /* non-default data files is a sign that scores may not be - * compatible, or perhaps that a binary not fitting this - * system's layout is being used. - */ -# ifdef VAR_PLAYGROUND - int len = strlen(VAR_PLAYGROUND); + if (dir /* User specified directory? */ +#ifdef HACKDIR + && strcmp(dir, HACKDIR) /* and not the default? */ +#endif + ) { +#ifdef SECURE + (void) setgid(getgid()); + (void) setuid(getuid()); /* Ron Wessels */ +#endif + } else { +/* non-default data files is a sign that scores may not be + * compatible, or perhaps that a binary not fitting this + * system's layout is being used. + */ +#ifdef VAR_PLAYGROUND + int len = strlen(VAR_PLAYGROUND); - fqn_prefix[SCOREPREFIX] = (char *)alloc(len+2); - Strcpy(fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND); - if (fqn_prefix[SCOREPREFIX][len-1] != '/') { - fqn_prefix[SCOREPREFIX][len] = '/'; - fqn_prefix[SCOREPREFIX][len+1] = '\0'; - } -# endif - } + fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2); + Strcpy(fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND); + if (fqn_prefix[SCOREPREFIX][len - 1] != '/') { + fqn_prefix[SCOREPREFIX][len] = '/'; + fqn_prefix[SCOREPREFIX][len + 1] = '\0'; + } +#endif + } -# ifdef HACKDIR - if (dir == (const char *)0) - dir = HACKDIR; -# endif +#ifdef HACKDIR + if (dir == (const char *) 0) + dir = HACKDIR; +#endif - if (dir && chdir(dir) < 0) { - perror(dir); - error("Cannot chdir to %s.", dir); - } + if (dir && chdir(dir) < 0) { + perror(dir); + error("Cannot chdir to %s.", dir); + } - /* warn the player if we can't write the record file */ - /* perhaps we should also test whether . is writable */ - /* unfortunately the access system-call is worthless */ - if (wr) { -# ifdef VAR_PLAYGROUND - fqn_prefix[LEVELPREFIX] = fqn_prefix[SCOREPREFIX]; - fqn_prefix[SAVEPREFIX] = fqn_prefix[SCOREPREFIX]; - fqn_prefix[BONESPREFIX] = fqn_prefix[SCOREPREFIX]; - fqn_prefix[LOCKPREFIX] = fqn_prefix[SCOREPREFIX]; - fqn_prefix[TROUBLEPREFIX] = fqn_prefix[SCOREPREFIX]; -# endif - check_recordfile(dir); - } + /* warn the player if we can't write the record file */ + /* perhaps we should also test whether . is writable */ + /* unfortunately the access system-call is worthless */ + if (wr) { +#ifdef VAR_PLAYGROUND + fqn_prefix[LEVELPREFIX] = fqn_prefix[SCOREPREFIX]; + fqn_prefix[SAVEPREFIX] = fqn_prefix[SCOREPREFIX]; + fqn_prefix[BONESPREFIX] = fqn_prefix[SCOREPREFIX]; + fqn_prefix[LOCKPREFIX] = fqn_prefix[SCOREPREFIX]; + fqn_prefix[TROUBLEPREFIX] = fqn_prefix[SCOREPREFIX]; +#endif + check_recordfile(dir); + } } #endif /* CHDIR */ @@ -493,28 +498,31 @@ boolean wr; static boolean whoami() { - /* - * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS - * 2. Use $USER or $LOGNAME (if 1. fails) - * 3. Use getlogin() (if 2. fails) - * The resulting name is overridden by command line options. - * If everything fails, or if the resulting name is some generic - * account like "games", "play", "player", "hack" then eventually - * we'll ask him. - * Note that we trust the user here; it is possible to play under - * somebody else's name. - */ + /* + * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS + * 2. Use $USER or $LOGNAME (if 1. fails) + * 3. Use getlogin() (if 2. fails) + * The resulting name is overridden by command line options. + * If everything fails, or if the resulting name is some generic + * account like "games", "play", "player", "hack" then eventually + * we'll ask him. + * Note that we trust the user here; it is possible to play under + * somebody else's name. + */ if (!*plname) { - register const char *s; + register const char *s; - s = nh_getenv("USER"); - if (!s || !*s) s = nh_getenv("LOGNAME"); - if (!s || !*s) s = getlogin(); + s = nh_getenv("USER"); + if (!s || !*s) + s = nh_getenv("LOGNAME"); + if (!s || !*s) + s = getlogin(); - if (s && *s) { - (void) strncpy(plname, s, sizeof plname - 1); - if (index(plname, '-')) return TRUE; - } + if (s && *s) { + (void) strncpy(plname, s, sizeof plname - 1); + if (index(plname, '-')) + return TRUE; + } } return FALSE; } @@ -524,25 +532,25 @@ sethanguphandler(handler) void FDECL((*handler), (int)); { #ifdef SA_RESTART - /* don't want reads to restart. If SA_RESTART is defined, we know - * sigaction exists and can be used to ensure reads won't restart. - * If it's not defined, assume reads do not restart. If reads restart - * and a signal occurs, the game won't do anything until the read - * succeeds (or the stream returns EOF, which might not happen if - * reading from, say, a window manager). */ - struct sigaction sact; + /* don't want reads to restart. If SA_RESTART is defined, we know + * sigaction exists and can be used to ensure reads won't restart. + * If it's not defined, assume reads do not restart. If reads restart + * and a signal occurs, the game won't do anything until the read + * succeeds (or the stream returns EOF, which might not happen if + * reading from, say, a window manager). */ + struct sigaction sact; - (void) memset((genericptr_t)&sact, 0, sizeof sact); - sact.sa_handler = (SIG_RET_TYPE)handler; - (void) sigaction(SIGHUP, &sact, (struct sigaction *)0); -# ifdef SIGXCPU - (void) sigaction(SIGXCPU, &sact, (struct sigaction *)0); -# endif + (void) memset((genericptr_t) &sact, 0, sizeof sact); + sact.sa_handler = (SIG_RET_TYPE) handler; + (void) sigaction(SIGHUP, &sact, (struct sigaction *) 0); +#ifdef SIGXCPU + (void) sigaction(SIGXCPU, &sact, (struct sigaction *) 0); +#endif #else /* !SA_RESTART */ - (void) signal(SIGHUP, (SIG_RET_TYPE)handler); -# ifdef SIGXCPU - (void) signal(SIGXCPU, (SIG_RET_TYPE)handler); -# endif + (void) signal(SIGHUP, (SIG_RET_TYPE) handler); +#ifdef SIGXCPU + (void) signal(SIGXCPU, (SIG_RET_TYPE) handler); +#endif #endif /* ?SA_RESTART */ } @@ -550,11 +558,11 @@ void FDECL((*handler), (int)); void port_help() { - /* - * Display unix-specific help. Just show contents of the helpfile - * named by PORT_HELP. - */ - display_file(PORT_HELP, TRUE); + /* + * Display unix-specific help. Just show contents of the helpfile + * named by PORT_HELP. + */ + display_file(PORT_HELP, TRUE); } #endif @@ -562,28 +570,29 @@ port_help() boolean authorize_wizard_mode() { - struct passwd *pw = get_unix_pw(); - if (pw && sysopt.wizards && sysopt.wizards[0]) { - if(check_user_string(sysopt.wizards)) return TRUE; - } - wiz_error_flag = TRUE; /* not being allowed into wizard mode */ - return FALSE; + struct passwd *pw = get_unix_pw(); + if (pw && sysopt.wizards && sysopt.wizards[0]) { + if (check_user_string(sysopt.wizards)) + return TRUE; + } + wiz_error_flag = TRUE; /* not being allowed into wizard mode */ + return FALSE; } static void wd_message() { - if (wiz_error_flag) { - if (sysopt.wizards && sysopt.wizards[0]) { - char *tmp = build_english_list(sysopt.wizards); - pline("Only user%s %s may access debug (wizard) mode.", - index(sysopt.wizards, ' ')?"s":"", tmp); - free(tmp); - } else - pline("Entering explore/discovery mode instead."); - wizard = 0, discover = 1; /* (paranoia) */ - } else if (discover) - You("are in non-scoring explore/discovery mode."); + if (wiz_error_flag) { + if (sysopt.wizards && sysopt.wizards[0]) { + char *tmp = build_english_list(sysopt.wizards); + pline("Only user%s %s may access debug (wizard) mode.", + index(sysopt.wizards, ' ') ? "s" : "", tmp); + free(tmp); + } else + pline("Entering explore/discovery mode instead."); + wizard = 0, discover = 1; /* (paranoia) */ + } else if (discover) + You("are in non-scoring explore/discovery mode."); } /* @@ -594,67 +603,78 @@ void append_slash(name) char *name; { - char *ptr; + char *ptr; - if (!*name) - return; - ptr = name + (strlen(name) - 1); - if (*ptr != '/') { - *++ptr = '/'; - *++ptr = '\0'; - } - return; + if (!*name) + return; + ptr = name + (strlen(name) - 1); + if (*ptr != '/') { + *++ptr = '/'; + *++ptr = '\0'; + } + return; } boolean check_user_string(optstr) char *optstr; { - struct passwd *pw = get_unix_pw(); - int pwlen; - char *eop, *w; - if(optstr[0] == '*') return TRUE; /* allow any user */ - if(!pw) return FALSE; - pwlen = strlen(pw->pw_name); - eop = eos(optstr); - w = optstr; - while( w+pwlen <= eop ){ - if( ! *w ) break; - if( isspace(*w) ){ w++; continue;} - if( !strncmp(w, pw->pw_name, pwlen) ){ - if( !w[pwlen] || isspace(w[pwlen]) ) return TRUE; - } - while( *w && !isspace(*w) ) w++; - } - return FALSE; + struct passwd *pw = get_unix_pw(); + int pwlen; + char *eop, *w; + if (optstr[0] == '*') + return TRUE; /* allow any user */ + if (!pw) + return FALSE; + pwlen = strlen(pw->pw_name); + eop = eos(optstr); + w = optstr; + while (w + pwlen <= eop) { + if (!*w) + break; + if (isspace(*w)) { + w++; + continue; + } + if (!strncmp(w, pw->pw_name, pwlen)) { + if (!w[pwlen] || isspace(w[pwlen])) + return TRUE; + } + while (*w && !isspace(*w)) + w++; + } + return FALSE; } static struct passwd * get_unix_pw() { - char *user; - unsigned uid; - static struct passwd *pw = (struct passwd *)0; + char *user; + unsigned uid; + static struct passwd *pw = (struct passwd *) 0; - if(pw) return pw; /* cache answer */ + if (pw) + return pw; /* cache answer */ - uid = (unsigned)getuid(); - user = getlogin(); - if (user) { - pw = getpwnam(user); - if (pw && ((unsigned)pw->pw_uid != uid)) pw = 0; - } - if (pw == 0) { - user = nh_getenv("USER"); - if (user) { - pw = getpwnam(user); - if (pw && ((unsigned)pw->pw_uid != uid)) pw = 0; - } - if (pw == 0) { - pw = getpwuid(uid); - } - } - return pw; + uid = (unsigned) getuid(); + user = getlogin(); + if (user) { + pw = getpwnam(user); + if (pw && ((unsigned) pw->pw_uid != uid)) + pw = 0; + } + if (pw == 0) { + user = nh_getenv("USER"); + if (user) { + pw = getpwnam(user); + if (pw && ((unsigned) pw->pw_uid != uid)) + pw = 0; + } + if (pw == 0) { + pw = getpwuid(uid); + } + } + return pw; } /*unixmain.c*/ diff --git a/sys/unix/unixres.c b/sys/unix/unixres.c index 0ad99e8eb..6b192668f 100644 --- a/sys/unix/unixres.c +++ b/sys/unix/unixres.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 unixres.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 unixres.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 unixres.c $Date: 2009/05/06 10:50:57 $ $Revision: 1.8 $ */ /* SCCS Id: @(#)unixres.c 3.5 2001/07/08 */ /* Copyright (c) Slash'EM development team, 2001. */ @@ -20,7 +20,7 @@ #ifdef GETRES_SUPPORT -# if defined(LINUX) +#if defined(LINUX) /* requires dynamic linking with libc */ #include @@ -32,7 +32,8 @@ uid_t *ruid, *euid, *suid; int (*f)(uid_t *, uid_t *, uid_t *); /* getresuid signature */ f = dlsym(RTLD_NEXT, "getresuid"); - if (!f) return -1; + if (!f) + return -1; return f(ruid, euid, suid); } @@ -44,15 +45,16 @@ gid_t *rgid, *egid, *sgid; int (*f)(gid_t *, gid_t *, gid_t *); /* getresgid signature */ f = dlsym(RTLD_NEXT, "getresgid"); - if (!f) return -1; + if (!f) + return -1; return f(rgid, egid, sgid); } -# else -# if defined(BSD) || defined(SVR4) +#else +#if defined(BSD) || defined(SVR4) -# ifdef SYS_getresuid +#ifdef SYS_getresuid static int real_getresuid(ruid, euid, suid) @@ -61,7 +63,7 @@ uid_t *ruid, *euid, *suid; return syscall(SYS_getresuid, ruid, euid, suid); } -# else /* SYS_getresuid */ +#else /* SYS_getresuid */ #ifdef SVR4 #include @@ -75,21 +77,21 @@ uid_t *ruid, *euid, *suid; int pfd[2]; struct stat st; if (pipe(pfd)) - return -1; + return -1; retval = fstat(pfd[0], &st); close(pfd[0]); close(pfd[1]); if (!retval) { - *euid = st.st_uid; - *ruid = syscall(SYS_getuid); - *suid = *ruid; /* Not supported under SVR4 */ + *euid = st.st_uid; + *ruid = syscall(SYS_getuid); + *suid = *ruid; /* Not supported under SVR4 */ } return retval; } -# endif /* SYS_getresuid */ +#endif /* SYS_getresuid */ -# ifdef SYS_getresgid +#ifdef SYS_getresgid static int real_getresgid(rgid, egid, sgid) @@ -98,7 +100,7 @@ gid_t *rgid, *egid, *sgid; return syscall(SYS_getresgid, rgid, egid, sgid); } -# else /* SYS_getresgid */ +#else /* SYS_getresgid */ static int real_getresgid(rgid, egid, sgid) @@ -108,21 +110,21 @@ gid_t *rgid, *egid, *sgid; int pfd[2]; struct stat st; if (pipe(pfd)) - return -1; + return -1; retval = fstat(pfd[0], &st); close(pfd[0]); close(pfd[1]); if (!retval) { - *egid = st.st_gid; - *rgid = syscall(SYS_getgid); - *sgid = *rgid; /* Not supported under SVR4 */ + *egid = st.st_gid; + *rgid = syscall(SYS_getgid); + *sgid = *rgid; /* Not supported under SVR4 */ } return retval; } -# endif /* SYS_getresgid */ -# endif /* BSD || SVR4 */ -# endif /* LINUX */ +#endif /* SYS_getresgid */ +#endif /* BSD || SVR4 */ +#endif /* LINUX */ static unsigned int hiding_privileges = 0; @@ -135,9 +137,9 @@ hide_privileges(flag) boolean flag; { if (flag) - hiding_privileges++; + hiding_privileges++; else if (hiding_privileges) - hiding_privileges--; + hiding_privileges--; return hiding_privileges; } @@ -147,7 +149,7 @@ uid_t *ruid, *euid, *suid; { int retval = real_getresuid(ruid, euid, suid); if (!retval && hiding_privileges) - *euid = *suid = *ruid; + *euid = *suid = *ruid; return retval; } @@ -165,7 +167,7 @@ nh_geteuid() uid_t ruid, euid, suid; (void) real_getresuid(&ruid, &euid, &suid); if (hiding_privileges) - euid = ruid; + euid = ruid; return euid; } @@ -175,7 +177,7 @@ gid_t *rgid, *egid, *sgid; { int retval = real_getresgid(rgid, egid, sgid); if (!retval && hiding_privileges) - *egid = *sgid = *rgid; + *egid = *sgid = *rgid; return retval; } @@ -193,19 +195,19 @@ nh_getegid() gid_t rgid, egid, sgid; (void) real_getresgid(&rgid, &egid, &sgid); if (hiding_privileges) - egid = rgid; + egid = rgid; return egid; } -#else /* GETRES_SUPPORT */ +#else /* GETRES_SUPPORT */ -# ifdef GNOME_GRAPHICS +#ifdef GNOME_GRAPHICS int hide_privileges(flag) boolean flag; { return 0; } -# endif +#endif -#endif /* GETRES_SUPPORT */ +#endif /* GETRES_SUPPORT */ diff --git a/sys/unix/unixunix.c b/sys/unix/unixunix.c index 2849abe9a..c17948ded 100644 --- a/sys/unix/unixunix.c +++ b/sys/unix/unixunix.c @@ -1,11 +1,11 @@ -/* NetHack 3.6 unixunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 unixunix.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */ /* NetHack 3.6 unixunix.c $Date: 2012/01/27 20:15:31 $ $Revision: 1.16 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ /* This file collects some Unix dependencies */ -#include "hack.h" /* mainly for index() which depends on BSD */ +#include "hack.h" /* mainly for index() which depends on BSD */ #include #include @@ -34,200 +34,208 @@ static int veryold(fd) int fd; { - time_t date; + time_t date; - if(fstat(fd, &buf)) return(0); /* cannot get status */ + if (fstat(fd, &buf)) + return (0); /* cannot get status */ #ifndef INSURANCE - if(buf.st_size != sizeof(int)) return(0); /* not an xlock file */ + if (buf.st_size != sizeof(int)) + return (0); /* not an xlock file */ #endif #if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *)(&date)); + (void) time((long *) (&date)); #else - (void) time(&date); + (void) time(&date); #endif - if(date - buf.st_mtime < 3L*24L*60L*60L) { /* recent */ - int lockedpid; /* should be the same size as hackpid */ + if (date - buf.st_mtime < 3L * 24L * 60L * 60L) { /* recent */ + int lockedpid; /* should be the same size as hackpid */ - if(read(fd, (genericptr_t)&lockedpid, sizeof(lockedpid)) != - sizeof(lockedpid)) - /* strange ... */ - return(0); + if (read(fd, (genericptr_t) &lockedpid, sizeof(lockedpid)) + != sizeof(lockedpid)) + /* strange ... */ + return (0); - /* From: Rick Adams */ - /* This will work on 4.1cbsd, 4.2bsd and system 3? & 5. */ - /* It will do nothing on V7 or 4.1bsd. */ +/* From: Rick Adams */ +/* This will work on 4.1cbsd, 4.2bsd and system 3? & 5. */ +/* It will do nothing on V7 or 4.1bsd. */ #ifndef NETWORK - /* It will do a VERY BAD THING if the playground is shared - by more than one machine! -pem */ - if(!(kill(lockedpid, 0) == -1 && errno == ESRCH)) + /* It will do a VERY BAD THING if the playground is shared + by more than one machine! -pem */ + if (!(kill(lockedpid, 0) == -1 && errno == ESRCH)) #endif - return(0); - } - (void) close(fd); - return(1); + return (0); + } + (void) close(fd); + return (1); } static int eraseoldlocks() { - register int i; + register int i; - program_state.preserve_locks = 0; /* not required but shows intent */ - /* cannot use maxledgerno() here, because we need to find a lock name - * before starting everything (including the dungeon initialization - * that sets astral_level, needed for maxledgerno()) up - */ - for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) { - /* try to remove all */ - set_levelfile_name(lock, i); - (void) unlink(fqname(lock, LEVELPREFIX, 0)); - } - set_levelfile_name(lock, 0); - if (unlink(fqname(lock, LEVELPREFIX, 0))) - return(0); /* cannot remove it */ - return(1); /* success! */ + program_state.preserve_locks = 0; /* not required but shows intent */ + /* cannot use maxledgerno() here, because we need to find a lock name + * before starting everything (including the dungeon initialization + * that sets astral_level, needed for maxledgerno()) up + */ + for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { + /* try to remove all */ + set_levelfile_name(lock, i); + (void) unlink(fqname(lock, LEVELPREFIX, 0)); + } + set_levelfile_name(lock, 0); + if (unlink(fqname(lock, LEVELPREFIX, 0))) + return (0); /* cannot remove it */ + return (1); /* success! */ } void getlock() { - register int i = 0, fd, c; - const char *fq_lock; + register int i = 0, fd, c; + const char *fq_lock; #ifdef TTY_GRAPHICS - /* idea from rpick%ucqais@uccba.uc.edu - * prevent automated rerolling of characters - * test input (fd0) so that tee'ing output to get a screen dump still - * works - * also incidentally prevents development of any hack-o-matic programs - */ - /* added check for window-system type -dlc */ - if (!strcmp(windowprocs.name, "tty")) - if (!isatty(0)) - error("You must play from a terminal."); + /* idea from rpick%ucqais@uccba.uc.edu + * prevent automated rerolling of characters + * test input (fd0) so that tee'ing output to get a screen dump still + * works + * also incidentally prevents development of any hack-o-matic programs + */ + /* added check for window-system type -dlc */ + if (!strcmp(windowprocs.name, "tty")) + if (!isatty(0)) + error("You must play from a terminal."); #endif - /* we ignore QUIT and INT at this point */ - if (!lock_file(HLOCK, LOCKPREFIX, 10)) { - wait_synch(); - error("%s", ""); - } + /* we ignore QUIT and INT at this point */ + if (!lock_file(HLOCK, LOCKPREFIX, 10)) { + wait_synch(); + error("%s", ""); + } - /* default value of lock[] is "1lock" where '1' gets changed to - 'a','b',&c below; override the default and use - if we aren't restricting the number of simultaneous games */ - if (!locknum) - Sprintf(lock, "%u%s", (unsigned)getuid(), plname); + /* default value of lock[] is "1lock" where '1' gets changed to + 'a','b',&c below; override the default and use + if we aren't restricting the number of simultaneous games */ + if (!locknum) + Sprintf(lock, "%u%s", (unsigned) getuid(), plname); - regularize(lock); - set_levelfile_name(lock, 0); + regularize(lock); + set_levelfile_name(lock, 0); - if(locknum) { - if(locknum > 25) locknum = 25; + if (locknum) { + if (locknum > 25) + locknum = 25; - do { - lock[0] = 'a' + i++; - fq_lock = fqname(lock, LEVELPREFIX, 0); + do { + lock[0] = 'a' + i++; + fq_lock = fqname(lock, LEVELPREFIX, 0); - if((fd = open(fq_lock, 0)) == -1) { - if(errno == ENOENT) goto gotlock; /* no such file */ - perror(fq_lock); - unlock_file(HLOCK); - error("Cannot open %s", fq_lock); - } + if ((fd = open(fq_lock, 0)) == -1) { + if (errno == ENOENT) + goto gotlock; /* no such file */ + perror(fq_lock); + unlock_file(HLOCK); + error("Cannot open %s", fq_lock); + } - if(veryold(fd) /* closes fd if true */ - && eraseoldlocks()) - goto gotlock; - (void) close(fd); - } while(i < locknum); + if (veryold(fd) /* closes fd if true */ + && eraseoldlocks()) + goto gotlock; + (void) close(fd); + } while (i < locknum); - unlock_file(HLOCK); - error("Too many hacks running now."); - } else { - fq_lock = fqname(lock, LEVELPREFIX, 0); - if((fd = open(fq_lock, 0)) == -1) { - if(errno == ENOENT) goto gotlock; /* no such file */ - perror(fq_lock); - unlock_file(HLOCK); - error("Cannot open %s", fq_lock); - } + unlock_file(HLOCK); + error("Too many hacks running now."); + } else { + fq_lock = fqname(lock, LEVELPREFIX, 0); + if ((fd = open(fq_lock, 0)) == -1) { + if (errno == ENOENT) + goto gotlock; /* no such file */ + perror(fq_lock); + unlock_file(HLOCK); + error("Cannot open %s", fq_lock); + } - if(veryold(fd) /* closes fd if true */ && eraseoldlocks()) - goto gotlock; - (void) close(fd); + if (veryold(fd) /* closes fd if true */ && eraseoldlocks()) + goto gotlock; + (void) close(fd); - if(iflags.window_inited) { - c = yn("There is already a game in progress under your name. Destroy old game?"); - } else { - (void) printf("\nThere is already a game in progress under your name."); - (void) printf(" Destroy old game? [yn] "); - (void) fflush(stdout); - if ((c = getchar()) != EOF) { - int tmp; + if (iflags.window_inited) { + c = yn("There is already a game in progress under your name. " + "Destroy old game?"); + } else { + (void) printf( + "\nThere is already a game in progress under your name."); + (void) printf(" Destroy old game? [yn] "); + (void) fflush(stdout); + if ((c = getchar()) != EOF) { + int tmp; - (void) putchar(c); - (void) fflush(stdout); - while ((tmp = getchar()) != '\n' && tmp != EOF) - ; /* eat rest of line and newline */ - } - } - if(c == 'y' || c == 'Y') { - if(eraseoldlocks()) - goto gotlock; - else { - unlock_file(HLOCK); - error("Couldn't destroy old game."); - } - } else { - unlock_file(HLOCK); - error("%s", ""); - } - } + (void) putchar(c); + (void) fflush(stdout); + while ((tmp = getchar()) != '\n' && tmp != EOF) + ; /* eat rest of line and newline */ + } + } + if (c == 'y' || c == 'Y') { + if (eraseoldlocks()) + goto gotlock; + else { + unlock_file(HLOCK); + error("Couldn't destroy old game."); + } + } else { + unlock_file(HLOCK); + error("%s", ""); + } + } gotlock: - fd = creat(fq_lock, FCMASK); - unlock_file(HLOCK); - if(fd == -1) { - error("cannot creat lock file (%s).", fq_lock); - } else { - if(write(fd, (genericptr_t) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ - error("cannot write lock (%s)", fq_lock); - } - if(close(fd) == -1) { - error("cannot close lock (%s)", fq_lock); - } - } + fd = creat(fq_lock, FCMASK); + unlock_file(HLOCK); + if (fd == -1) { + error("cannot creat lock file (%s).", fq_lock); + } else { + if (write(fd, (genericptr_t) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { + error("cannot write lock (%s)", fq_lock); + } + if (close(fd) == -1) { + error("cannot close lock (%s)", fq_lock); + } + } } -void -regularize(s) /* normalize file name - we don't like .'s, /'s, spaces */ +void regularize(s) /* normalize file name - we don't like .'s, /'s, spaces */ register char *s; { - register char *lp; + register char *lp; - while((lp=index(s, '.')) || (lp=index(s, '/')) || (lp=index(s,' '))) - *lp = '_'; -#if defined(SYSV) && !defined(AIX_31) && !defined(SVR4) && !defined(LINUX) && !defined(__APPLE__) - /* avoid problems with 14 character file name limit */ -# ifdef COMPRESS - /* leave room for .e from error and .Z from compress appended to - * save files */ - { -# ifdef COMPRESS_EXTENSION - int i = 12 - strlen(COMPRESS_EXTENSION); -# else - int i = 10; /* should never happen... */ -# endif - if(strlen(s) > i) - s[i] = '\0'; - } -# else - if(strlen(s) > 11) - /* leave room for .nn appended to level files */ - s[11] = '\0'; -# endif + while ((lp = index(s, '.')) || (lp = index(s, '/')) + || (lp = index(s, ' '))) + *lp = '_'; +#if defined(SYSV) && !defined(AIX_31) && !defined(SVR4) && !defined(LINUX) \ + && !defined(__APPLE__) +/* avoid problems with 14 character file name limit */ +#ifdef COMPRESS + /* leave room for .e from error and .Z from compress appended to + * save files */ + { +#ifdef COMPRESS_EXTENSION + int i = 12 - strlen(COMPRESS_EXTENSION); +#else + int i = 10; /* should never happen... */ +#endif + if (strlen(s) > i) + s[i] = '\0'; + } +#else + if (strlen(s) > 11) + /* leave room for .nn appended to level files */ + s[11] = '\0'; +#endif #endif } @@ -236,13 +244,14 @@ register char *s; void msleep(msec) -unsigned msec; /* milliseconds */ +unsigned msec; /* milliseconds */ { - struct pollfd unused; - int msecs = msec; /* poll API is signed */ + struct pollfd unused; + int msecs = msec; /* poll API is signed */ - if (msecs < 0) msecs = 0; /* avoid infinite sleep */ - (void) poll(&unused, (unsigned long)0, msecs); + if (msecs < 0) + msecs = 0; /* avoid infinite sleep */ + (void) poll(&unused, (unsigned long) 0, msecs); } #endif /* TIMED_DELAY for SYSV */ @@ -250,25 +259,23 @@ unsigned msec; /* milliseconds */ int dosh() { - register char *str; -# ifdef SYSCF - if( !sysopt.shellers - || !sysopt.shellers[0] - || !check_user_string(sysopt.shellers) - ){ - Norep("Unknown command '!'."); - return 0; - } -# endif - if(child(0)) { - if((str = getenv("SHELL")) != (char*)0) - (void) execl(str, str, (char *)0); - else - (void) execl("/bin/sh", "sh", (char *)0); - raw_print("sh: cannot execute."); - exit(EXIT_FAILURE); - } - return 0; + register char *str; +#ifdef SYSCF + if (!sysopt.shellers || !sysopt.shellers[0] + || !check_user_string(sysopt.shellers)) { + Norep("Unknown command '!'."); + return 0; + } +#endif + if (child(0)) { + if ((str = getenv("SHELL")) != (char *) 0) + (void) execl(str, str, (char *) 0); + else + (void) execl("/bin/sh", "sh", (char *) 0); + raw_print("sh: cannot execute."); + exit(EXIT_FAILURE); + } + return 0; } #endif /* SHELL */ @@ -277,48 +284,49 @@ int child(wt) int wt; { - register int f; - suspend_nhwindows((char *)0); /* also calls end_screen() */ + register int f; + suspend_nhwindows((char *) 0); /* also calls end_screen() */ #ifdef _M_UNIX - sco_mapon(); + sco_mapon(); #endif #ifdef __linux__ - linux_mapon(); + linux_mapon(); #endif - if((f = fork()) == 0){ /* child */ - (void) setgid(getgid()); - (void) setuid(getuid()); + if ((f = fork()) == 0) { /* child */ + (void) setgid(getgid()); + (void) setuid(getuid()); #ifdef CHDIR - (void) chdir(getenv("HOME")); + (void) chdir(getenv("HOME")); #endif - return(1); - } - if(f == -1) { /* cannot fork */ - pline("Fork failed. Try again."); - return(0); - } - /* fork succeeded; wait for child to exit */ + return (1); + } + if (f == -1) { /* cannot fork */ + pline("Fork failed. Try again."); + return (0); + } +/* fork succeeded; wait for child to exit */ #ifndef NO_SIGNAL - (void) signal(SIGINT,SIG_IGN); - (void) signal(SIGQUIT,SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGQUIT, SIG_IGN); #endif - (void) wait( (int *) 0); + (void) wait((int *) 0); #ifdef _M_UNIX - sco_mapoff(); + sco_mapoff(); #endif #ifdef __linux__ - linux_mapoff(); + linux_mapoff(); #endif #ifndef NO_SIGNAL - (void) signal(SIGINT, (SIG_RET_TYPE) done1); - if(wizard) (void) signal(SIGQUIT,SIG_DFL); + (void) signal(SIGINT, (SIG_RET_TYPE) done1); + if (wizard) + (void) signal(SIGQUIT, SIG_DFL); #endif - if(wt) { - raw_print(""); - wait_synch(); - } - resume_nhwindows(); - return(0); + if (wt) { + raw_print(""); + wait_synch(); + } + resume_nhwindows(); + return (0); } #endif @@ -331,57 +339,52 @@ extern int FDECL(nh_getresgid, (gid_t *, gid_t *, gid_t *)); extern gid_t NDECL(nh_getgid); extern gid_t NDECL(nh_getegid); -int -(getresuid)(ruid, euid, suid) +int(getresuid)(ruid, euid, suid) uid_t *ruid, *euid, *suid; { return nh_getresuid(ruid, euid, suid); } -uid_t -(getuid)() +uid_t(getuid)() { return nh_getuid(); } -uid_t -(geteuid)() +uid_t(geteuid)() { return nh_geteuid(); } -int -(getresgid)(rgid, egid, sgid) +int(getresgid)(rgid, egid, sgid) gid_t *rgid, *egid, *sgid; { return nh_getresgid(rgid, egid, sgid); } -gid_t -(getgid)() +gid_t(getgid)() { return nh_getgid(); } -gid_t -(getegid)() +gid_t(getegid)() { return nh_getegid(); } -#endif /* GETRES_SUPPORT */ +#endif /* GETRES_SUPPORT */ /* XXX should be ifdef PANICTRACE_GDB, but there's no such symbol yet */ #ifdef PANICTRACE boolean -file_exists(const char *path){ - /* Just see if it's there - trying to figure out if we can actually - * execute it in all cases is too hard - we really just want to - * catch typos in SYSCF. */ - struct stat sb; - if(stat(path, &sb)){ - return FALSE; - } - return TRUE; +file_exists(const char *path) +{ + /* Just see if it's there - trying to figure out if we can actually + * execute it in all cases is too hard - we really just want to + * catch typos in SYSCF. */ + struct stat sb; + if (stat(path, &sb)) { + return FALSE; + } + return TRUE; } #endif diff --git a/sys/vms/oldcrtl.c b/sys/vms/oldcrtl.c index c77390eb2..14d53babd 100644 --- a/sys/vms/oldcrtl.c +++ b/sys/vms/oldcrtl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 oldcrtl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 oldcrtl.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 oldcrtl.c $Date: 2009/05/06 10:51:24 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)oldcrtl.c 3.5 1995/06/01 */ /* Pat Rankin May'90 */ @@ -24,169 +24,186 @@ /* void *memset(void *, int, size_t) -- fill chunk of memory. */ -char *memset( dst, fil, cnt ) +char * +memset(dst, fil, cnt) REG char *dst; -REG char fil; -REG int cnt; +REG char fil; +REG int cnt; { char *dst_p = dst; - while ( --cnt >= 0 ) - *dst++ = fil; + while (--cnt >= 0) + *dst++ = fil; return dst_p; } /* void *memcpy(void *, const void *, size_t) -- copy chunk of memory. */ -char *memcpy( dst, src, cnt ) -REG char *dst; +char * +memcpy(dst, src, cnt) +REG char *dst; REG const char *src; -REG int cnt; +REG int cnt; { char *dst_p = dst; - while ( --cnt >= 0 ) - *dst++ = *src++; + while (--cnt >= 0) + *dst++ = *src++; return dst_p; } -/* void *memmove(void *, const void *, size_t) -- copy possibly overlapping mem. +/* void *memmove(void *, const void *, size_t) -- copy possibly overlapping + * mem. */ -char *memmove( dst, src, cnt ) -REG char *dst; +char * +memmove(dst, src, cnt) +REG char *dst; REG const char *src; -REG int cnt; +REG int cnt; { char *dst_p = dst; - if ( src == dst || cnt <= 0 ) { - ; /* do nothing */ - } else if ( dst < src || dst >= src + cnt ) { - while ( --cnt >= 0 ) - *dst++ = *src++; - } else { /* work backwards */ - dst += cnt, src += cnt; - while ( --cnt >= 0 ) - *--dst = *--src; + if (src == dst || cnt <= 0) { + ; /* do nothing */ + } else if (dst < src || dst >= src + cnt) { + while (--cnt >= 0) + *dst++ = *src++; + } else { /* work backwards */ + dst += cnt, src += cnt; + while (--cnt >= 0) + *--dst = *--src; } return dst_p; } /* void *memchr(const void *, int, size_t) -- search for a byte. */ -char *memchr( buf, byt, len ) +char * +memchr(buf, byt, len) REG const char *buf; -REG char byt; -REG int len; +REG char byt; +REG int len; { - while ( --len >= 0 ) - if ( *buf++ == byt ) /* found */ - return (char *)--buf; - return (char *)0; /* not found */ + while (--len >= 0) + if (*buf++ == byt) /* found */ + return (char *) --buf; + return (char *) 0; /* not found */ } /* int memcmp(const void *, const void *, size_t) -- compare two chunks. */ -int memcmp( buf1, buf2, len ) +int +memcmp(buf1, buf2, len) REG const char *buf1; REG const char *buf2; -REG int len; +REG int len; { - while ( --len >= 0 ) - if ( *buf1++ != *buf2++ ) - return (*--buf1 - *--buf2); - return 0; /* buffers matched */ + while (--len >= 0) + if (*buf1++ != *buf2++) + return (*--buf1 - *--buf2); + return 0; /* buffers matched */ } #endif /*!SUPPRESS_MEM_FUNCS*/ - #ifndef SUPPRESS_ATEXIT /* int atexit(void (*)(void)) -- register an exit handler. */ -#define MAX_EXIT_FUNCS 32 /* arbitrary (32 matches VAX C v3.x docs) */ -struct ex_hndlr { long reserved, (*routine)(), arg_count, *arg1_addr; }; -static int ex_cnt = 0; /* number of handlers registered so far */ -static struct { long dummy_arg; struct ex_hndlr handler; /*(black box)*/ - } ex_data[MAX_EXIT_FUNCS]; /* static handler data */ +#define MAX_EXIT_FUNCS 32 /* arbitrary (32 matches VAX C v3.x docs) */ +struct ex_hndlr { + long reserved, (*routine)(), arg_count, *arg1_addr; +}; +static int ex_cnt = 0; /* number of handlers registered so far */ +static struct { + long dummy_arg; + struct ex_hndlr handler; /*(black box)*/ +} ex_data[MAX_EXIT_FUNCS]; /* static handler data */ extern unsigned long sys$dclexh(); -int atexit( function ) - void (*function)(); /* note: actually gets called with 1 arg */ +int +atexit(function) +void (*function)(); /* note: actually gets called with 1 arg */ { - if ( ex_cnt < MAX_EXIT_FUNCS ) { - ex_data[ex_cnt].dummy_arg = 0; /* ultimately receives exit reason */ - ex_data[ex_cnt].handler.reserved = 0; - ex_data[ex_cnt].handler.routine = (long (*)()) function; - ex_data[ex_cnt].handler.arg_count = 1; /*(required)*/ - ex_data[ex_cnt].handler.arg1_addr = &ex_data[ex_cnt].dummy_arg; - (void)sys$dclexh(&ex_data[ex_cnt].handler); /* declare exit handler */ - return ++ex_cnt; /*(non-zero)*/ + if (ex_cnt < MAX_EXIT_FUNCS) { + ex_data[ex_cnt].dummy_arg = 0; /* ultimately receives exit reason */ + ex_data[ex_cnt].handler.reserved = 0; + ex_data[ex_cnt].handler.routine = (long (*) ()) function; + ex_data[ex_cnt].handler.arg_count = 1; /*(required)*/ + ex_data[ex_cnt].handler.arg1_addr = &ex_data[ex_cnt].dummy_arg; + (void) sys$dclexh( + &ex_data[ex_cnt].handler); /* declare exit handler */ + return ++ex_cnt; /*(non-zero)*/ } else - return 0; + return 0; } #endif /*!SUPPRESS_ATEXIT*/ - #ifndef SUPPRESS_RENAME /* int rename(const char *, const char *) -- rename a file (on same device). */ #ifndef EVMSERR #include -#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status)) +#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status)) #endif extern unsigned long lib$rename_file(); -int rename( old_name, new_name ) - const char *old_name; - const char *new_name; +int +rename(old_name, new_name) +const char *old_name; +const char *new_name; { - struct dsc { unsigned short len, mbz; const char *adr; } old_dsc, new_dsc; + struct dsc { + unsigned short len, mbz; + const char *adr; + } old_dsc, new_dsc; unsigned long status; /* put strings into descriptors and call run-time library routine */ - new_dsc.mbz = old_dsc.mbz = 0; /* type and class unspecified */ - old_dsc.len = strlen( old_dsc.adr = old_name ); - new_dsc.len = strlen( new_dsc.adr = new_name ); - status = lib$rename_file(&old_dsc, &new_dsc); /* omit optional args */ - if ( !(status & 1) ) { /* even => failure */ - C$$TRANSLATE(status); - return -1; - } else /* odd => success */ - return 0; + new_dsc.mbz = old_dsc.mbz = 0; /* type and class unspecified */ + old_dsc.len = strlen(old_dsc.adr = old_name); + new_dsc.len = strlen(new_dsc.adr = new_name); + status = lib$rename_file(&old_dsc, &new_dsc); /* omit optional args */ + if (!(status & 1)) { /* even => failure */ + C$$TRANSLATE(status); + return -1; + } else /* odd => success */ + return 0; } #endif /*!SUPPRESS_RENAME*/ - #ifndef SUPPRESS_QSORT /* void qsort(void *, size_t, size_t, int (*)()) -- sort arbitrary collection. */ -extern char *malloc(); /* assume no alloca() available */ +extern char *malloc(); /* assume no alloca() available */ extern void free(); -void qsort( base, count, size, compare ) - char *base; - int count; -REG int size; - int (*compare)(); +void +qsort(base, count, size, compare) +char *base; +int count; +REG int size; +int (*compare)(); { -REG int i, cmp; -REG char *next, *prev, *tmp = 0; - char wrk_buf[512]; + REG int i, cmp; + REG char *next, *prev, *tmp = 0; + char wrk_buf[512]; /* just use a shuffle sort (tradeoff between efficiency & simplicity) */ /* [Optimal if already sorted; worst case when initially reversed.] */ - for ( next = base, i = 1; i < count; i++ ) { - prev = next, next += size; /* increment front pointer */ - if ( (cmp = (*compare)( next, prev)) < 0 ) { - /* found element out of order; move other(s) up then re-insert it */ - if ( !tmp ) tmp = size > (int)(sizeof wrk_buf) ? malloc(size) : wrk_buf; - memcpy( tmp, next, size); /* save smaller element */ - while ( cmp < 0 ) { - memcpy( prev + size, prev, size); /* move larger elem. up */ - prev -= size; /* decrement back pointer */ - cmp = (prev >= base ? (*compare)( tmp, prev) : 0); - } - memcpy( prev + size, tmp, size); /* restore small element */ - } + for (next = base, i = 1; i < count; i++) { + prev = next, next += size; /* increment front pointer */ + if ((cmp = (*compare)(next, prev)) < 0) { + /* found element out of order; move other(s) up then re-insert it + */ + if (!tmp) + tmp = size > (int) (sizeof wrk_buf) ? malloc(size) : wrk_buf; + memcpy(tmp, next, size); /* save smaller element */ + while (cmp < 0) { + memcpy(prev + size, prev, size); /* move larger elem. up */ + prev -= size; /* decrement back pointer */ + cmp = (prev >= base ? (*compare)(tmp, prev) : 0); + } + memcpy(prev + size, tmp, size); /* restore small element */ + } } - if ( tmp != 0 && tmp != wrk_buf ) free(tmp); + if (tmp != 0 && tmp != wrk_buf) + free(tmp); return; } #endif /*!SUPPRESS_QSORT*/ diff --git a/sys/vms/vmsfiles.c b/sys/vms/vmsfiles.c index 2b22beae2..c77885d89 100644 --- a/sys/vms/vmsfiles.c +++ b/sys/vms/vmsfiles.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmsfiles.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmsfiles.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 vmsfiles.c $Date: 2009/05/06 10:51:25 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)vmsfiles.c 3.5 2007/10/27 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -12,30 +12,31 @@ #include /* lint supression due to lack of extern.h */ -int FDECL(vms_link, (const char *,const char *)); +int FDECL(vms_link, (const char *, const char *)); int FDECL(vms_unlink, (const char *)); -int FDECL(vms_creat, (const char *,unsigned int)); -boolean FDECL(same_dir, (const char *,const char *)); +int FDECL(vms_creat, (const char *, unsigned int)); +boolean FDECL(same_dir, (const char *, const char *)); int FDECL(c__translate, (int)); #include #if 0 #include #else -#define PSL$C_EXEC 1 /* executive mode, for priv'd logical name handling */ +#define PSL$C_EXEC 1 /* executive mode, for priv'd logical name handling */ #endif #include -#ifndef C$$TRANSLATE /* don't rely on VAXCRTL's internal routine */ -#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status)) +#ifndef C$$TRANSLATE /* don't rely on VAXCRTL's internal routine */ +#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status)) #endif extern unsigned long sys$parse(), sys$search(), sys$enter(), sys$remove(); -extern int VDECL(lib$match_cond, (int,int,...)); +extern int VDECL(lib$match_cond, (int, int, ...)); -#define vms_success(sts) ((sts)&1) /* odd, */ -#define vms_failure(sts) (!vms_success(sts)) /* even */ +#define vms_success(sts) ((sts) &1) /* odd, */ +#define vms_failure(sts) (!vms_success(sts)) /* even */ /* vms_link() -- create an additional directory for an existing file */ -int vms_link(file, new) +int +vms_link(file, new) const char *file, *new; { struct FAB fab; @@ -43,7 +44,7 @@ const char *file, *new; unsigned short fid[3]; char esa[NAM$C_MAXRSS]; - fab = cc$rms_fab; /* set block ID and length, zero the rest */ + fab = cc$rms_fab; /* set block ID and length, zero the rest */ fab.fab$l_fop = FAB$M_OFP; fab.fab$l_fna = (char *) file; fab.fab$b_fns = strlen(file); @@ -53,28 +54,28 @@ const char *file, *new; nam.nam$b_ess = sizeof esa; if (vms_success(sys$parse(&fab)) && vms_success(sys$search(&fab))) { - fid[0] = nam.nam$w_fid[0]; - fid[1] = nam.nam$w_fid[1]; - fid[2] = nam.nam$w_fid[2]; - fab.fab$l_fna = (char *) new; - fab.fab$b_fns = strlen(new); + fid[0] = nam.nam$w_fid[0]; + fid[1] = nam.nam$w_fid[1]; + fid[2] = nam.nam$w_fid[2]; + fab.fab$l_fna = (char *) new; + fab.fab$b_fns = strlen(new); - if (vms_success(sys$parse(&fab))) { - nam.nam$w_fid[0] = fid[0]; - nam.nam$w_fid[1] = fid[1]; - nam.nam$w_fid[2] = fid[2]; - nam.nam$l_esa = nam.nam$l_name; - nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver; + if (vms_success(sys$parse(&fab))) { + nam.nam$w_fid[0] = fid[0]; + nam.nam$w_fid[1] = fid[1]; + nam.nam$w_fid[2] = fid[2]; + nam.nam$l_esa = nam.nam$l_name; + nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver; - (void) sys$enter(&fab); - } + (void) sys$enter(&fab); + } } if (vms_failure(fab.fab$l_sts)) { - C$$TRANSLATE(fab.fab$l_sts); - return -1; + C$$TRANSLATE(fab.fab$l_sts); + return -1; } - return 0; /* success */ + return 0; /* success */ } /* @@ -82,14 +83,15 @@ const char *file, *new; for files which have had extra directory entries added, not for deletion (because the file won't be deleted, just made inaccessible!). */ -int vms_unlink(file) +int +vms_unlink(file) const char *file; { struct FAB fab; struct NAM nam; char esa[NAM$C_MAXRSS]; - fab = cc$rms_fab; /* set block ID and length, zero the rest */ + fab = cc$rms_fab; /* set block ID and length, zero the rest */ fab.fab$l_fop = FAB$M_DLT; fab.fab$l_fna = (char *) file; fab.fab$b_fns = strlen(file); @@ -99,8 +101,8 @@ const char *file; nam.nam$b_ess = sizeof esa; if (vms_failure(sys$parse(&fab)) || vms_failure(sys$remove(&fab))) { - C$$TRANSLATE(fab.fab$l_sts); - return -1; + C$$TRANSLATE(fab.fab$l_sts); + return -1; } return 0; } @@ -118,17 +120,17 @@ vms_creat(file, mode) const char *file; unsigned int mode; { - char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ + char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ if (index(file, ';')) { - /* assumes remove or delete, not vms_unlink */ - if (!unlink(file)) { - (void)sleep(1); - (void)unlink(file); - } + /* assumes remove or delete, not vms_unlink */ + if (!unlink(file)) { + (void) sleep(1); + (void) unlink(file); + } } else if (!index(file, '.')) { - /* force some punctuation to be present */ - file = strcat(strcpy(filnambuf, file), "."); + /* force some punctuation to be present */ + file = strcat(strcpy(filnambuf, file), "."); } return creat(file, mode, "shr=nil", "mbc=32", "mbf=2", "rop=wbh"); } @@ -145,18 +147,18 @@ const char *file; int flags; unsigned int mode; { - char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ + char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ int fd; if (!index(file, '.') && !index(file, ';')) { - /* force some punctuation to be present to make sure that - the file name can't accidentally match a logical name */ - file = strcat(strcpy(filnambuf, file), ";0"); + /* force some punctuation to be present to make sure that + the file name can't accidentally match a logical name */ + file = strcat(strcpy(filnambuf, file), ";0"); } fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah"); if (fd < 0 && errno == EVMSERR && lib$match_cond(vaxc$errno, RMS$_FLK)) { - (void)sleep(1); - fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah"); + (void) sleep(1); + fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah"); } return fd; } @@ -167,18 +169,18 @@ FILE * vms_fopen(file, mode) const char *file, *mode; { - char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ + char filnambuf[BUFSIZ]; /*(not BUFSZ)*/ FILE *fp; if (!index(file, '.') && !index(file, ';')) { - /* force some punctuation to be present to make sure that - the file name can't accidentally match a logical name */ - file = strcat(strcpy(filnambuf, file), ";0"); + /* force some punctuation to be present to make sure that + the file name can't accidentally match a logical name */ + file = strcat(strcpy(filnambuf, file), ";0"); } fp = fopen(file, mode, "mbc=32", "mbf=2", "rop=rah"); if (!fp && errno == EVMSERR && lib$match_cond(vaxc$errno, RMS$_FLK)) { - (void)sleep(1); - fp = fopen(file, mode, "mbc=32", "mbf=2", "rop=rah"); + (void) sleep(1); + fp = fopen(file, mode, "mbc=32", "mbf=2", "rop=rah"); } return fp; } @@ -194,32 +196,33 @@ same_dir(d1, d2) const char *d1, *d2; { if (!d1 || !*d1 || !d2 || !*d2) - return FALSE; - else if (!strcmp(d1, d2)) /* strcmpi() would be better, but that leads */ - return TRUE; /* to linking problems for the utilities */ + return FALSE; + else if (!strcmp(d1, d2)) /* strcmpi() would be better, but that leads */ + return TRUE; /* to linking problems for the utilities */ else { - struct FAB f1, f2; - struct NAM n1, n2; + struct FAB f1, f2; + struct NAM n1, n2; - f1 = f2 = cc$rms_fab; /* initialize file access block */ - n1 = n2 = cc$rms_nam; /* initialize name block */ - f1.fab$b_acmodes = PSL$C_EXEC << FAB$V_LNM_MODE; - f1.fab$b_fns = strlen( f1.fab$l_fna = (char *)d1 ); - f2.fab$b_fns = strlen( f2.fab$l_fna = (char *)d2 ); - f1.fab$l_nam = (genericptr_t)&n1; /* link nam to fab */ - f2.fab$l_nam = (genericptr_t)&n2; - n1.nam$b_nop = n2.nam$b_nop = NAM$M_NOCONCEAL; /* want true device name */ + f1 = f2 = cc$rms_fab; /* initialize file access block */ + n1 = n2 = cc$rms_nam; /* initialize name block */ + f1.fab$b_acmodes = PSL$C_EXEC << FAB$V_LNM_MODE; + f1.fab$b_fns = strlen(f1.fab$l_fna = (char *) d1); + f2.fab$b_fns = strlen(f2.fab$l_fna = (char *) d2); + f1.fab$l_nam = (genericptr_t) &n1; /* link nam to fab */ + f2.fab$l_nam = (genericptr_t) &n2; + n1.nam$b_nop = n2.nam$b_nop = + NAM$M_NOCONCEAL; /* want true device name */ - return (vms_success(sys$parse(&f1)) && vms_success(sys$parse(&f2)) - && n1.nam$t_dvi[0] == n2.nam$t_dvi[0] - && !strncmp(&n1.nam$t_dvi[1], &n2.nam$t_dvi[1], n1.nam$t_dvi[0]) - && !memcmp((genericptr_t)n1.nam$w_did, - (genericptr_t)n2.nam$w_did, - sizeof n1.nam$w_did)); /*{ short nam$w_did[3]; }*/ + return ( + vms_success(sys$parse(&f1)) && vms_success(sys$parse(&f2)) + && n1.nam$t_dvi[0] == n2.nam$t_dvi[0] + && !strncmp(&n1.nam$t_dvi[1], &n2.nam$t_dvi[1], n1.nam$t_dvi[0]) + && !memcmp((genericptr_t) n1.nam$w_did, + (genericptr_t) n2.nam$w_did, + sizeof n1.nam$w_did)); /*{ short nam$w_did[3]; }*/ } } - /* * c__translate -- substitute for VAXCRTL routine C$$TRANSLATE. * @@ -238,62 +241,60 @@ const char *d1, *d2; /* #include */ /* #include */ -#define VALUE(U) trans = U; break -#define CASE1(V) case (V >> 3) -#define CASE2(V,W) CASE1(V): CASE1(W) +#define VALUE(U) \ + trans = U; \ + break +#define CASE1(V) case (V >> 3) +#define CASE2(V, W) CASE1(V) : CASE1(W) -int c__translate(code) - int code; +int +c__translate(code) +int code; { register int trans; - switch ((code & 0x0FFFFFF8) >> 3) { /* strip upper 4 and bottom 3 bits */ - CASE2(RMS$_PRV,SS$_NOPRIV): - VALUE(EPERM); /* not owner */ - CASE2(RMS$_DNF,RMS$_DIR): - CASE2(RMS$_FNF,RMS$_FND): - CASE1(SS$_NOSUCHFILE): - VALUE(ENOENT); /* no such file or directory */ - CASE2(RMS$_IFI,RMS$_ISI): - VALUE(EIO); /* i/o error */ - CASE1(RMS$_DEV): - CASE2(SS$_NOSUCHDEV,SS$_DEVNOTMOUNT): - VALUE(ENXIO); /* no such device or address codes */ - CASE1(RMS$_DME): - /* CASE1(LIB$INSVIRMEM): */ - CASE2(SS$_VASFULL,SS$_INSFWSL): - VALUE(ENOMEM); /* not enough core */ - CASE1(SS$_ACCVIO): - VALUE(EFAULT); /* bad address */ - CASE2(RMS$_DNR,SS$_DEVASSIGN): - CASE2(SS$_DEVALLOC,SS$_DEVALRALLOC): - CASE2(SS$_DEVMOUNT,SS$_DEVACTIVE): - VALUE(EBUSY); /* mount device busy codes to name a few */ - CASE2(RMS$_FEX,SS$_FILALRACC): - VALUE(EEXIST); /* file exists */ - CASE2(RMS$_IDR,SS$_BADIRECTORY): - VALUE(ENOTDIR); /* not a directory */ - CASE1(SS$_NOIOCHAN): - VALUE(EMFILE); /* too many open files */ - CASE1(RMS$_FUL): - CASE2(SS$_DEVICEFULL,SS$_EXDISKQUOTA): - VALUE(ENOSPC); /* no space left on disk codes */ - CASE2(RMS$_WLK,SS$_WRITLCK): - VALUE(EROFS); /* read-only file system */ - default: - VALUE(EVMSERR); + switch ((code & 0x0FFFFFF8) >> 3) { /* strip upper 4 and bottom 3 bits */ + CASE2(RMS$_PRV, SS$_NOPRIV) : VALUE(EPERM); /* not owner */ + CASE2(RMS$_DNF, RMS$_DIR) + : CASE2(RMS$_FNF, RMS$_FND) + : CASE1(SS$_NOSUCHFILE) + : VALUE(ENOENT); /* no such file or directory */ + CASE2(RMS$_IFI, RMS$_ISI) : VALUE(EIO); /* i/o error */ + CASE1(RMS$_DEV) + : CASE2(SS$_NOSUCHDEV, SS$_DEVNOTMOUNT) + : VALUE(ENXIO); /* no such device or address codes */ + CASE1(RMS$_DME) + : /* CASE1(LIB$INSVIRMEM): */ + CASE2(SS$_VASFULL, SS$_INSFWSL) + : VALUE(ENOMEM); /* not enough core */ + CASE1(SS$_ACCVIO) : VALUE(EFAULT); /* bad address */ + CASE2(RMS$_DNR, SS$_DEVASSIGN) + : CASE2(SS$_DEVALLOC, SS$_DEVALRALLOC) + : CASE2(SS$_DEVMOUNT, SS$_DEVACTIVE) + : VALUE(EBUSY); /* mount device busy codes to name a few */ + CASE2(RMS$_FEX, SS$_FILALRACC) : VALUE(EEXIST); /* file exists */ + CASE2(RMS$_IDR, SS$_BADIRECTORY) + : VALUE(ENOTDIR); /* not a directory */ + CASE1(SS$_NOIOCHAN) : VALUE(EMFILE); /* too many open files */ + CASE1(RMS$_FUL) + : CASE2(SS$_DEVICEFULL, SS$_EXDISKQUOTA) + : VALUE(ENOSPC); /* no space left on disk codes */ + CASE2(RMS$_WLK, SS$_WRITLCK) + : VALUE(EROFS); /* read-only file system */ + default: + VALUE(EVMSERR); }; errno = trans; vaxc$errno = code; - return code; /* (not very useful) */ + return code; /* (not very useful) */ } #undef VALUE #undef CASE1 #undef CASE2 -static char base_name[NAM$C_MAXRSS+1]; +static char base_name[NAM$C_MAXRSS + 1]; /* return a copy of the 'base' portion of a filename */ char * @@ -305,15 +306,20 @@ const char *name; register const char *name_p; /* skip directory/path */ - if ((name_p = strrchr(name, ']')) != 0) name = name_p + 1; - if ((name_p = strrchr(name, '>')) != 0) name = name_p + 1; - if ((name_p = strrchr(name, ':')) != 0) name = name_p + 1; - if ((name_p = strrchr(name, '/')) != 0) name = name_p + 1; - if (!*name) name = "."; /* this should never happen */ + if ((name_p = strrchr(name, ']')) != 0) + name = name_p + 1; + if ((name_p = strrchr(name, '>')) != 0) + name = name_p + 1; + if ((name_p = strrchr(name, ':')) != 0) + name = name_p + 1; + if ((name_p = strrchr(name, '/')) != 0) + name = name_p + 1; + if (!*name) + name = "."; /* this should never happen */ /* find extension/version and derive length of basename */ if ((name_p = strchr(name, '.')) == 0 || name_p == name) - name_p = strchr(name, ';'); + name_p = strchr(name, ';'); len = (name_p && name_p > name) ? name_p - name : strlen(name); /* return a lowercase copy of the name in a private static buffer */ @@ -321,7 +327,8 @@ const char *name; base[len] = '\0'; /* we don't use lcase() so that utilities won't need hacklib.c */ for (base_p = base; base_p < &base[len]; base_p++) - if (isupper(*base_p)) *base_p = tolower(*base_p); + if (isupper(*base_p)) + *base_p = tolower(*base_p); return base; } diff --git a/sys/vms/vmsmail.c b/sys/vms/vmsmail.c index 9279fd799..89be094d0 100644 --- a/sys/vms/vmsmail.c +++ b/sys/vms/vmsmail.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmsmail.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmsmail.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 vmsmail.c $Date: 2009/05/06 10:51:25 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)vmsmail.c 3.5 2006/04/14 */ /* Copyright (c) Robert Patrick Rankin, 1991. */ @@ -19,37 +19,34 @@ struct mail_info *NDECL(parse_next_broadcast); #include #include #include -# ifndef __GNUC__ +#ifndef __GNUC__ #include -# else -# define MSG$_TRMHANGUP 6 -# define MSG$_TRMBRDCST 83 -# endif /*__GNUC__*/ +#else +#define MSG$_TRMHANGUP 6 +#define MSG$_TRMBRDCST 83 +#endif /*__GNUC__*/ #include /* #include */ -# define vms_ok(sts) ((sts)&1) +#define vms_ok(sts) ((sts) &1) static struct mail_info *FDECL(parse_brdcst, (char *)); static void FDECL(filter_brdcst, (char *)); static void NDECL(flush_broadcasts); static void FDECL(broadcast_ast, (int)); extern char *FDECL(eos, (char *)); -extern char *FDECL(strstri, (const char *,const char *)); -extern int FDECL(strncmpi, (const char *,const char *,int)); +extern char *FDECL(strstri, (const char *, const char *)); +extern int FDECL(strncmpi, (const char *, const char *, int)); -extern size_t FDECL(strspn, (const char *,const char *)); +extern size_t FDECL(strspn, (const char *, const char *)); #ifndef __DECC -extern int VDECL(sscanf, (const char *,const char *,...)); +extern int VDECL(sscanf, (const char *, const char *, ...)); #endif -extern unsigned long - smg$create_pasteboard(), - smg$get_broadcast_message(), - smg$set_broadcast_trapping(), - smg$disable_broadcast_trapping(); +extern unsigned long smg$create_pasteboard(), smg$get_broadcast_message(), + smg$set_broadcast_trapping(), smg$disable_broadcast_trapping(); -extern volatile int broadcasts; /* defining declaration in mail.c */ +extern volatile int broadcasts; /* defining declaration in mail.c */ -static long pasteboard_id = 0; /* SMG's magic cookie */ +static long pasteboard_id = 0; /* SMG's magic cookie */ /* * Mail (et al) overview: @@ -104,202 +101,227 @@ static long pasteboard_id = 0; /* SMG's magic cookie */ * Link it with hacklib.obj or nethack.olb/incl=hacklib (not nethack/lib). */ -static struct mail_info msg; /* parse_*()'s return buffer */ -static char nam_buf[63], /* maximum onamelth, size of ONAME(object) */ - cmd_buf[99], /* arbitrary */ - txt_buf[255+1]; /* same size as used for message buf[] */ +static struct mail_info msg; /* parse_*()'s return buffer */ +static char nam_buf[63], /* maximum onamelth, size of ONAME(object) */ + cmd_buf[99], /* arbitrary */ + txt_buf[255 + 1]; /* same size as used for message buf[] */ /* try to decipher and categorize broadcast message text */ static struct mail_info * -parse_brdcst(buf) /* called by parse_next_broadcast() */ -char *buf; /* input: filtered broadcast text */ +parse_brdcst(buf) /* called by parse_next_broadcast() */ +char *buf; /* input: filtered broadcast text */ { int typ; char *txt; const char *nam, *cmd; -# ifdef SHELL /* only parse if spawned commands are enabled */ +#ifdef SHELL /* only parse if spawned commands are enabled */ register char *p, *q; boolean is_jnet_send; - char user[127+1], node[127+1], sentinel; + char user[127 + 1], node[127 + 1], sentinel; /* Check these first; otherwise, their arbitrary text would enable - easy spoofing of some other message patterns. Unfortunately, - any home-grown broadcast delivery program poses a similar risk. */ - if (!strncmpi(buf, "reply received", 14)) goto other; + easy spoofing of some other message patterns. Unfortunately, + any home-grown broadcast delivery program poses a similar risk. */ + if (!strncmpi(buf, "reply received", 14)) + goto other; is_jnet_send = (sscanf(buf, "(%[^)])%s -%c", node, user, &sentinel) == 3); - if (is_jnet_send) goto jnet_send; + if (is_jnet_send) + goto jnet_send; /* scan the text more or less by brute force */ - if ((q = strstri(buf, " mail")) != 0 || /* all known mail broadcasts */ - !strncmpi(q = buf, "mail ", 5)) { /* unexpected alternative */ - typ = MSG_MAIL; - p = strstri(q, " from"); - txt = p ? strcat(strcpy(txt_buf, "Mail for you"), p) : (char *) 0; + if ((q = strstri(buf, " mail")) != 0 || /* all known mail broadcasts */ + !strncmpi(q = buf, "mail ", 5)) { /* unexpected alternative */ + typ = MSG_MAIL; + p = strstri(q, " from"); + txt = p ? strcat(strcpy(txt_buf, "Mail for you"), p) : (char *) 0; - if (!strncmpi(buf, "new mail", 8)) { -/* -New mail [on node FOO] from [SPAM::]BAR [\"personal_name\"] [\(HH:MM:SS\)] -*/ - nam = "VMSmail"; /* assume VMSmail */ - cmd = "MAIL"; - if (txt && (p = strrchr(txt, '(')) > txt && /* discard time */ - (--p, strspn(p, "0123456789( :.)") == strlen(p))) *p = '\0'; - } else if (!strncmpi(buf, "new all-in-1", 12)) { - int i; -/* -New ALL-IN-1 MAIL message [on node FOO] from Personal Name \(BAR@SPAM\) [\(DD-MMM-YYYY HH:MM:SS\)] -*/ - nam = "A1mail"; - cmd = "A1M"; - if (txt && (p = strrchr(txt, '(')) > txt && /* discard date+time */ - sscanf(p-1," (%*d-%*[^-]-%*d %*d:%*d:%d) %c",&i,&sentinel) == 1) - *--p = '\0'; - } else if (!strncmpi(buf, "software tools", 14)) { -/* -Software Tools mail has arrived on FOO from \'BAR\' [in SPAM] -*/ - nam = "STmail"; - cmd = "MSG"; - if (txt && (p = strstri(p, " in ")) != 0) /* specific folder */ - cmd = strcat(strcpy(cmd_buf, "MSG +"), p + 4); - } else if (q - 2 >= buf && !strncmpi(q - 2, "mm", 2)) { -/* -{MultiNet\ |PMDF\/}MM mail has arrived on FOO from BAR\n -[Subject: subject_text] (PMDF only) -*/ - nam = "MMmail"; /* MultiNet's version of MM */ - cmd = "MM"; /*{ perhaps "MM READ"? }*/ - } else if (!strncmpi(buf, "wpmail:", 7)) { -/* -WPmail: New mail from BAR. subject_text -*/ - nam = "WPmail"; /* WordPerfect [sic] Office */ - cmd = "OFFICE/MAIL"; - } else if (!strncmpi(buf, "**m400 mail", 7)) { -/* -**M400 mail waiting** -*/ - nam = "M400mail"; /* Messenger 400 [not seen] */ - cmd = "M400"; - } else { - /* not recognized, but presumed to be mail */ - nam = "unknown mail"; - cmd = "SPAWN"; /* generic escape back to DCL */ - txt = (char *) 0; /* don't rely on "from" info here */ - } + if (!strncmpi(buf, "new mail", 8)) { + /* + New mail [on node FOO] from [SPAM::]BAR [\"personal_name\"] + [\(HH:MM:SS\)] + */ + nam = "VMSmail"; /* assume VMSmail */ + cmd = "MAIL"; + if (txt && (p = strrchr(txt, '(')) > txt && /* discard time */ + (--p, strspn(p, "0123456789( :.)") == strlen(p))) + *p = '\0'; + } else if (!strncmpi(buf, "new all-in-1", 12)) { + int i; + /* + New ALL-IN-1 MAIL message [on node FOO] from Personal Name + \(BAR@SPAM\) [\(DD-MMM-YYYY HH:MM:SS\)] + */ + nam = "A1mail"; + cmd = "A1M"; + if (txt && (p = strrchr(txt, '(')) > txt + && /* discard date+time */ + sscanf(p - 1, " (%*d-%*[^-]-%*d %*d:%*d:%d) %c", &i, + &sentinel) == 1) + *--p = '\0'; + } else if (!strncmpi(buf, "software tools", 14)) { + /* + Software Tools mail has arrived on FOO from \'BAR\' [in SPAM] + */ + nam = "STmail"; + cmd = "MSG"; + if (txt && (p = strstri(p, " in ")) != 0) /* specific folder */ + cmd = strcat(strcpy(cmd_buf, "MSG +"), p + 4); + } else if (q - 2 >= buf && !strncmpi(q - 2, "mm", 2)) { + /* + {MultiNet\ |PMDF\/}MM mail has arrived on FOO from BAR\n + [Subject: subject_text] (PMDF only) + */ + nam = "MMmail"; /* MultiNet's version of MM */ + cmd = "MM"; /*{ perhaps "MM READ"? }*/ + } else if (!strncmpi(buf, "wpmail:", 7)) { + /* + WPmail: New mail from BAR. subject_text + */ + nam = "WPmail"; /* WordPerfect [sic] Office */ + cmd = "OFFICE/MAIL"; + } else if (!strncmpi(buf, "**m400 mail", 7)) { + /* + **M400 mail waiting** + */ + nam = "M400mail"; /* Messenger 400 [not seen] */ + cmd = "M400"; + } else { + /* not recognized, but presumed to be mail */ + nam = "unknown mail"; + cmd = "SPAWN"; /* generic escape back to DCL */ + txt = (char *) 0; /* don't rely on "from" info here */ + } - if (!txt) txt = strcat(strcpy(txt_buf, "Mail for you: "), buf); - /* - : end of mail recognition; now check for call-type interruptions... - */ + if (!txt) + txt = strcat(strcpy(txt_buf, "Mail for you: "), buf); + /* + : end of mail recognition; now check for call-type + interruptions... + */ } else if ((q = strstri(buf, " phoning")) != 0) { -/* -BAR is phoning you [on FOO] \(HH:MM:SS\) -*/ - typ = MSG_CALL; - nam = "Phone call"; - cmd = "PHONE ANSWER"; - if (!strncmpi(q + 8, " you", 4)) q += (8 + 4), *q = '\0'; - txt = strcat(strcpy(txt_buf, "Do you hear ringing? "), buf); - } else if ((q = strstri(buf, " talk-daemon")) != 0 || - (q = strstri(buf, " talk_daemon")) != 0) { -/* -Message from TALK-DAEMON@FOO at HH:MM:SS\n -Connection request by BAR@SPAM\n -\[Respond with: TALK[/OLD] BAR@SPAM\] -*/ - typ = MSG_CALL; - nam = "Talk request"; /* MultiNet's TALK and/or TALK/OLD */ - cmd = "TALK"; - if ((p = strstri(q, " by ")) != 0) { - txt = strcat(strcpy(txt_buf, "Talk request from"), p + 3); - if ((p = strstri(p, "respond with")) != 0) { - if (*(p-1) == '[') *(p-1) = '\0'; else *p = '\0'; /* terminate */ - p += (sizeof "respond with" - sizeof ""); - if (*p == ':') p++; - if (*p == ' ') p++; - cmd = strcpy(cmd_buf, p); /* "TALK[/OLD] bar@spam" */ - p = eos(cmd_buf); - if (*--p == ']') *p = '\0'; - } - } else - txt = strcat(strcpy(txt_buf, "Pardon the interruption: "), buf); - } else if (is_jnet_send) { /* sscanf(,"(%[^)])%s -%c",,,)==3 */ -jnet_send: -/* -\(SPAM\)BAR - arbitrary_message_text (from BAR@SPAM) -*/ - typ = MSG_CALL; - nam = "Bitnet noise"; /* RSCS/NJE message received via JNET */ - Sprintf(cmd_buf, "XYZZY %s@%s", user, node); - cmd = cmd_buf; - /*{ perhaps just vanilla SEND instead of XYZZY? }*/ - Sprintf(txt_buf, "Message from %s@%s:%s", user, node, - &buf[1+strlen(node)+1+strlen(user)+2-1]); /* "(node)user -" */ - txt = txt_buf; - /* - : end of call recognition; anything else is none-of-the-above... - */ + /* + BAR is phoning you [on FOO] \(HH:MM:SS\) + */ + typ = MSG_CALL; + nam = "Phone call"; + cmd = "PHONE ANSWER"; + if (!strncmpi(q + 8, " you", 4)) + q += (8 + 4), *q = '\0'; + txt = strcat(strcpy(txt_buf, "Do you hear ringing? "), buf); + } else if ((q = strstri(buf, " talk-daemon")) != 0 + || (q = strstri(buf, " talk_daemon")) != 0) { + /* + Message from TALK-DAEMON@FOO at HH:MM:SS\n + Connection request by BAR@SPAM\n + \[Respond with: TALK[/OLD] BAR@SPAM\] + */ + typ = MSG_CALL; + nam = "Talk request"; /* MultiNet's TALK and/or TALK/OLD */ + cmd = "TALK"; + if ((p = strstri(q, " by ")) != 0) { + txt = strcat(strcpy(txt_buf, "Talk request from"), p + 3); + if ((p = strstri(p, "respond with")) != 0) { + if (*(p - 1) == '[') + *(p - 1) = '\0'; + else + *p = '\0'; /* terminate */ + p += (sizeof "respond with" - sizeof ""); + if (*p == ':') + p++; + if (*p == ' ') + p++; + cmd = strcpy(cmd_buf, p); /* "TALK[/OLD] bar@spam" */ + p = eos(cmd_buf); + if (*--p == ']') + *p = '\0'; + } + } else + txt = strcat(strcpy(txt_buf, "Pardon the interruption: "), buf); + } else if (is_jnet_send) { /* sscanf(,"(%[^)])%s -%c",,,)==3 */ + jnet_send: + /* + \(SPAM\)BAR - arbitrary_message_text (from BAR@SPAM) + */ + typ = MSG_CALL; + nam = "Bitnet noise"; /* RSCS/NJE message received via JNET */ + Sprintf(cmd_buf, "XYZZY %s@%s", user, node); + cmd = cmd_buf; + /*{ perhaps just vanilla SEND instead of XYZZY? }*/ + Sprintf(txt_buf, "Message from %s@%s:%s", user, node, + &buf[1 + strlen(node) + 1 + strlen(user) + 2 + - 1]); /* "(node)user -" */ + txt = txt_buf; + /* + : end of call recognition; anything else is none-of-the-above... + */ } else { -other: -# endif /* SHELL */ -/* arbitrary broadcast: batch job completed, system shutdown imminent, &c */ - typ = MSG_OTHER; - nam = (char *) 0; /*"captured broadcast message"*/ - cmd = (char *) 0; - txt = strcat(strcpy(txt_buf, "Message for you: "), buf); -# ifdef SHELL + other: +#endif /* SHELL */ + /* arbitrary broadcast: batch job completed, system shutdown imminent, + * &c */ + typ = MSG_OTHER; + nam = (char *) 0; /*"captured broadcast message"*/ + cmd = (char *) 0; + txt = strcat(strcpy(txt_buf, "Message for you: "), buf); +#ifdef SHELL } /* Daemon in newmail() will append period when the text is displayed */ - if ((p = eos(txt)) > txt && *--p == '.') *p = '\0'; + if ((p = eos(txt)) > txt && *--p == '.') + *p = '\0'; /* newmail() and readmail() used to assume that nam and cmd are concatenated but that is no longer the case */ if (nam && nam != nam_buf) { - (void) strncpy(nam_buf, nam, sizeof nam_buf - 1); - nam_buf[sizeof nam_buf - 1] = '\0'; + (void) strncpy(nam_buf, nam, sizeof nam_buf - 1); + nam_buf[sizeof nam_buf - 1] = '\0'; } - if (cmd && cmd != cmd_buf) { - (void) strncpy(cmd_buf, cmd, sizeof cmd_buf - 1); - cmd_buf[sizeof cmd_buf - 1] = '\0'; + if (cmd && cmd != cmd_buf) { + (void) strncpy(cmd_buf, cmd, sizeof cmd_buf - 1); + cmd_buf[sizeof cmd_buf - 1] = '\0'; } -# endif /* SHELL */ +#endif /* SHELL */ /* truncate really long messages to prevent verbalize() from blowing up */ - if (txt && strlen(txt) > BUFSZ - 50) txt[BUFSZ - 50] = '\0'; + if (txt && strlen(txt) > BUFSZ - 50) + txt[BUFSZ - 50] = '\0'; - msg.message_typ = typ; /* simple index */ - msg.display_txt = txt; /* text for daemon to pline() */ - msg.object_nam = nam; /* 'name' for mail scroll */ - msg.response_cmd = cmd; /* command to spawn when scroll read */ + msg.message_typ = typ; /* simple index */ + msg.display_txt = txt; /* text for daemon to pline() */ + msg.object_nam = nam; /* 'name' for mail scroll */ + msg.response_cmd = cmd; /* command to spawn when scroll read */ return &msg; } /* filter out non-printable characters and redundant noise */ -static void -filter_brdcst(buf) /* called by parse_next_broadcast() */ -register char *buf; /* in: original text; out: filtered text */ +static void filter_brdcst(buf) /* called by parse_next_broadcast() */ +register char *buf; /* in: original text; out: filtered text */ { register char c, *p, *buf_p; /* filter the text; restrict consecutive spaces or dots to just two */ for (p = buf_p = buf; *buf_p; buf_p++) { - c = *buf_p & '\177'; - if (c == ' ' || c == '\t' || c == '\n') - if (p == buf || /* ignore leading whitespace */ - (p >= buf+2 && *(p-1) == ' ' && *(p-2) == ' ')) continue; - else c = ' '; - else if (c == '.' || c < ' ' || c == '\177') - if (p == buf || /* skip leading beeps & such */ - (p >= buf+2 && *(p-1) == '.' && *(p-2) == '.')) continue; - else c = '.'; - else if (c == '%' && /* trim %%% OPCOM verbosity %%% */ - p >= buf+2 && *(p-1) == '%' && *(p-2) == '%') continue; - *p++ = c; + c = *buf_p & '\177'; + if (c == ' ' || c == '\t' || c == '\n') + if (p == buf || /* ignore leading whitespace */ + (p >= buf + 2 && *(p - 1) == ' ' && *(p - 2) == ' ')) + continue; + else + c = ' '; + else if (c == '.' || c < ' ' || c == '\177') + if (p == buf || /* skip leading beeps & such */ + (p >= buf + 2 && *(p - 1) == '.' && *(p - 2) == '.')) + continue; + else + c = '.'; + else if (c == '%' && /* trim %%% OPCOM verbosity %%% */ + p >= buf + 2 && *(p - 1) == '%' && *(p - 2) == '%') + continue; + *p++ = c; } - *p = '\0'; /* terminate, then strip trailing junk */ - while (p > buf && (*--p == ' ' || *p == '.')) *p = '\0'; + *p = '\0'; /* terminate, then strip trailing junk */ + while (p > buf && (*--p == ' ' || *p == '.')) + *p = '\0'; return; } @@ -307,180 +329,221 @@ static char empty_string[] = ""; /* fetch the text of a captured broadcast, then mangle and decipher it */ -struct mail_info * -parse_next_broadcast() /* called by ckmailstatus(mail.c) */ +struct mail_info *parse_next_broadcast() /* called by ckmailstatus(mail.c) */ { short length, msg_type; - $DESCRIPTOR(message, empty_string); /* string descriptor for buf[] */ + $DESCRIPTOR(message, empty_string); /* string descriptor for buf[] */ struct mail_info *result = 0; /* messages could actually be longer; let long ones be truncated */ - char buf[255+1]; + char buf[255 + 1]; - message.dsc$a_pointer = buf, message.dsc$w_length = sizeof buf - 1; + message.dsc$a_pointer = buf, message.dsc$w_length = sizeof buf - 1; msg_type = length = 0; smg$get_broadcast_message(&pasteboard_id, &message, &length, &msg_type); if (msg_type == MSG$_TRMBRDCST) { - buf[length] = '\0'; - filter_brdcst(buf); /* mask non-printable characters */ - result = parse_brdcst(buf); /* do the real work */ + buf[length] = '\0'; + filter_brdcst(buf); /* mask non-printable characters */ + result = parse_brdcst(buf); /* do the real work */ } else if (msg_type == MSG$_TRMHANGUP) { - (void) gsignal(SIGHUP); + (void) gsignal(SIGHUP); } return result; } /* spit out any pending broadcast messages whenever we leave */ -static void -flush_broadcasts() /* called from disable_broadcast_trapping() */ +static void flush_broadcasts() /* called from disable_broadcast_trapping() */ { if (broadcasts > 0) { - short len, typ; - $DESCRIPTOR(msg_dsc, empty_string); - char buf[512+1]; + short len, typ; + $DESCRIPTOR(msg_dsc, empty_string); + char buf[512 + 1]; - msg_dsc.dsc$a_pointer = buf, msg_dsc.dsc$w_length = sizeof buf - 1; - raw_print(""); /* print at least one line for wait_synch() */ - do { - typ = len = 0; - smg$get_broadcast_message(&pasteboard_id, &msg_dsc, &len, &typ); - if (typ == MSG$_TRMBRDCST) buf[len] = '\0', raw_print(buf); - } while (--broadcasts); - wait_synch(); /* prompt with "Hit return to continue: " */ + msg_dsc.dsc$a_pointer = buf, msg_dsc.dsc$w_length = sizeof buf - 1; + raw_print(""); /* print at least one line for wait_synch() */ + do { + typ = len = 0; + smg$get_broadcast_message(&pasteboard_id, &msg_dsc, &len, &typ); + if (typ == MSG$_TRMBRDCST) + buf[len] = '\0', raw_print(buf); + } while (--broadcasts); + wait_synch(); /* prompt with "Hit return to continue: " */ } } -/* AST routine called when the terminal's associated mailbox receives a message +/* AST routine called when the terminal's associated mailbox receives a + * message */ /*ARGSUSED*/ static void -broadcast_ast(dummy) /* called asynchronously by terminal driver */ -int dummy; /* not used */ +broadcast_ast(dummy) /* called asynchronously by terminal driver */ +int dummy; /* not used */ { broadcasts++; } /* initialize the broadcast manipulation code; SMG makes this easy */ -unsigned long init_broadcast_trapping() /* called by setftty() [once only] */ +unsigned long init_broadcast_trapping() /* called by setftty() [once only] */ { unsigned long sts, preserve_screen_flag = 1; - /* we need a pasteboard to pass to the broadcast setup/teardown routines */ - sts = smg$create_pasteboard(&pasteboard_id, 0, 0, 0, &preserve_screen_flag); + /* we need a pasteboard to pass to the broadcast setup/teardown routines + */ + sts = + smg$create_pasteboard(&pasteboard_id, 0, 0, 0, &preserve_screen_flag); if (!vms_ok(sts)) { - errno = EVMSERR, vaxc$errno = sts; - raw_print(""); - perror("?can't create SMG pasteboard for broadcast trapping"); - wait_synch(); - broadcasts = -1; /* flag that trapping is currently broken */ + errno = EVMSERR, vaxc$errno = sts; + raw_print(""); + perror("?can't create SMG pasteboard for broadcast trapping"); + wait_synch(); + broadcasts = -1; /* flag that trapping is currently broken */ } return sts; } /* set up the terminal driver to deliver $brkthru data to a mailbox device */ -unsigned long enable_broadcast_trapping() /* called by setftty() */ +unsigned long enable_broadcast_trapping() /* called by setftty() */ { unsigned long sts = 1; - if (broadcasts >= 0) { /* (-1 => no pasteboard, so don't even try) */ - /* register callback routine to be triggered when broadcasts arrive */ - /* Note side effect: also intercepts hangup notification. */ - /* Another note: TMPMBX privilege is required. */ - sts = smg$set_broadcast_trapping(&pasteboard_id, broadcast_ast, 0); - if (!vms_ok(sts)) { - errno = EVMSERR, vaxc$errno = sts; - raw_print(""); - perror("?can't enable broadcast trapping"); - wait_synch(); - } + if (broadcasts >= 0) { /* (-1 => no pasteboard, so don't even try) */ + /* register callback routine to be triggered when broadcasts arrive */ + /* Note side effect: also intercepts hangup notification. */ + /* Another note: TMPMBX privilege is required. */ + sts = smg$set_broadcast_trapping(&pasteboard_id, broadcast_ast, 0); + if (!vms_ok(sts)) { + errno = EVMSERR, vaxc$errno = sts; + raw_print(""); + perror("?can't enable broadcast trapping"); + wait_synch(); + } } return sts; } /* return to 'normal'; $brkthru data goes straight to the terminal */ -unsigned long disable_broadcast_trapping() /* called by settty() */ +unsigned long disable_broadcast_trapping() /* called by settty() */ { unsigned long sts = 1; if (broadcasts >= 0) { - /* disable trapping; releases associated MBX so that SPAWN can work */ - sts = smg$disable_broadcast_trapping(&pasteboard_id); - if (!vms_ok(sts)) errno = EVMSERR, vaxc$errno = sts; - flush_broadcasts(); /* don't hold on to any buffered ones */ + /* disable trapping; releases associated MBX so that SPAWN can work */ + sts = smg$disable_broadcast_trapping(&pasteboard_id); + if (!vms_ok(sts)) + errno = EVMSERR, vaxc$errno = sts; + flush_broadcasts(); /* don't hold on to any buffered ones */ } return sts; } -#else /* MAIL */ - /* simple stubs for non-mail configuration */ -unsigned long init_broadcast_trapping() { return 1; } -unsigned long enable_broadcast_trapping() { return 1; } -unsigned long disable_broadcast_trapping() { return 1; } -struct mail_info *parse_next_broadcast() { return 0; } -#endif /* MAIL */ +#else /* MAIL */ +/* simple stubs for non-mail configuration */ +unsigned long +init_broadcast_trapping() +{ + return 1; +} +unsigned long +enable_broadcast_trapping() +{ + return 1; +} +unsigned long +disable_broadcast_trapping() +{ + return 1; +} +struct mail_info * +parse_next_broadcast() +{ + return 0; +} +#endif /* MAIL */ /*----------------------------------------------------------------------*/ #ifdef TEST_DRIVER - /* (Take parse_next_broadcast for a spin. :-) */ +/* (Take parse_next_broadcast for a spin. :-) */ volatile int broadcasts = 0; -void newmail(foo) +void +newmail(foo) struct mail_info *foo; { -# define STRING(s) ((s) ? (s) : "") +#define STRING(s) ((s) ? (s) : "") printf("\n\ message type = %d\n\ display text = \"%s\"\n\ object name = \"%.*s\"\n\ response cmd = \"%s\"\n\ -", foo->message_typ, STRING(foo->display_txt), - (foo->object_nam && foo->response_cmd) ? - (foo->response_cmd - foo->object_nam - 1) : - strlen(STRING(foo->object_nam)), - STRING(foo->object_nam), STRING(foo->response_cmd)); -# undef STRING +", + foo->message_typ, STRING(foo->display_txt), + (foo->object_nam && foo->response_cmd) + ? (foo->response_cmd - foo->object_nam - 1) + : strlen(STRING(foo->object_nam)), + STRING(foo->object_nam), STRING(foo->response_cmd)); +#undef STRING } -void ckmailstatus() +void +ckmailstatus() { struct mail_info *brdcst, *parse_next_broadcast(); - while (broadcasts > 0) { /* process all trapped broadcasts [until] */ - broadcasts--; - if ((brdcst = parse_next_broadcast()) != 0) { - newmail(brdcst); - break; /* only handle one real message at a time */ - } else - printf("\n--< non-broadcast encountered >--\n"); + while (broadcasts > 0) { /* process all trapped broadcasts [until] */ + broadcasts--; + if ((brdcst = parse_next_broadcast()) != 0) { + newmail(brdcst); + break; /* only handle one real message at a time */ + } else + printf("\n--< non-broadcast encountered >--\n"); } } -int main() +int +main() { char dummy[BUFSIZ]; init_broadcast_trapping(); enable_broadcast_trapping(); for (;;) { - ckmailstatus(); - printf("> "), fflush(stdout); /* issue a prompt */ - if (!gets(dummy)) break; /* wait for a response */ + ckmailstatus(); + printf("> "), fflush(stdout); /* issue a prompt */ + if (!gets(dummy)) + break; /* wait for a response */ } disable_broadcast_trapping(); return 1; } -void panic(s) char *s; { raw_print(s); exit(EXIT_FAILURE); } - -void raw_print(s) char *s; { puts(s); fflush(stdout); } - -void wait_synch() { char dummy[BUFSIZ]; - printf("\nPress to continue: "); fflush(stdout); (void) gets(dummy); +void +panic(s) +char *s; +{ + raw_print(s); + exit(EXIT_FAILURE); } -#endif /* TEST_DRIVER */ + +void +raw_print(s) +char *s; +{ + puts(s); + fflush(stdout); +} + +void +wait_synch() +{ + char dummy[BUFSIZ]; + printf("\nPress to continue: "); + fflush(stdout); + (void) gets(dummy); +} +#endif /* TEST_DRIVER */ /*vmsmail.c*/ diff --git a/sys/vms/vmsmain.c b/sys/vms/vmsmain.c index af08bf559..2205de8f2 100644 --- a/sys/vms/vmsmain.c +++ b/sys/vms/vmsmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmsmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmsmain.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.30 $ */ /* NetHack 3.6 vmsmain.c $Date: 2011/04/23 01:51:01 $ $Revision: 1.22 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -13,217 +13,220 @@ static void NDECL(whoami); static void FDECL(process_options, (int, char **)); static void NDECL(byebye); #ifndef SAVE_ON_FATAL_ERROR -# ifndef __DECC -# define vms_handler_type int -# else -# define vms_handler_type unsigned int -# endif -extern void FDECL(VAXC$ESTABLISH, (vms_handler_type (*)(genericptr_t,genericptr_t))); -static vms_handler_type FDECL(vms_handler, (genericptr_t,genericptr_t)); -#include /* system service status codes */ +#ifndef __DECC +#define vms_handler_type int +#else +#define vms_handler_type unsigned int +#endif +extern void FDECL(VAXC$ESTABLISH, + (vms_handler_type (*) (genericptr_t, genericptr_t))); +static vms_handler_type FDECL(vms_handler, (genericptr_t, genericptr_t)); +#include /* system service status codes */ #endif static void NDECL(wd_message); static boolean wiz_error_flag = FALSE; int -main(argc,argv) +main(argc, argv) int argc; char *argv[]; { - register int fd; + register int fd; #ifdef CHDIR - register char *dir; + register char *dir; #endif - boolean resuming = FALSE; /* assume new game */ + boolean resuming = FALSE; /* assume new game */ -#ifdef SECURE /* this should be the very first code executed */ - privoff(); - fflush((FILE *)0); /* force stdio to init itself */ - privon(); +#ifdef SECURE /* this should be the very first code executed */ + privoff(); + fflush((FILE *) 0); /* force stdio to init itself */ + privon(); #endif - sys_early_init(); + sys_early_init(); - atexit(byebye); - hname = argv[0]; - hname = vms_basename(hname); /* name used in 'usage' type messages */ - hackpid = getpid(); - (void) umask(0); + atexit(byebye); + hname = argv[0]; + hname = vms_basename(hname); /* name used in 'usage' type messages */ + hackpid = getpid(); + (void) umask(0); - choose_windows(DEFAULT_WINDOW_SYS); + choose_windows(DEFAULT_WINDOW_SYS); -#ifdef CHDIR /* otherwise no chdir() */ - /* - * See if we must change directory to the playground. - * (Perhaps hack is installed with privs and playground is - * inaccessible for the player.) - * The logical name HACKDIR is overridden by a - * -d command line option (must be the first option given) - */ - dir = nh_getenv("NETHACKDIR"); - if (!dir) dir = nh_getenv("HACKDIR"); +#ifdef CHDIR /* otherwise no chdir() */ + /* + * See if we must change directory to the playground. + * (Perhaps hack is installed with privs and playground is + * inaccessible for the player.) + * The logical name HACKDIR is overridden by a + * -d command line option (must be the first option given) + */ + dir = nh_getenv("NETHACKDIR"); + if (!dir) + dir = nh_getenv("HACKDIR"); #endif - if(argc > 1) { + if (argc > 1) { #ifdef CHDIR - if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { - /* avoid matching "-dec" for DECgraphics; since the man page - * says -d directory, hope nobody's using -desomething_else - */ - argc--; - argv++; - dir = argv[0]+2; - if(*dir == '=' || *dir == ':') dir++; - if(!*dir && argc > 1) { - argc--; - argv++; - dir = argv[0]; - } - if(!*dir) - error("Flag -d must be followed by a directory name."); - } - if (argc > 1) + if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { + /* avoid matching "-dec" for DECgraphics; since the man page + * says -d directory, hope nobody's using -desomething_else + */ + argc--; + argv++; + dir = argv[0] + 2; + if (*dir == '=' || *dir == ':') + dir++; + if (!*dir && argc > 1) { + argc--; + argv++; + dir = argv[0]; + } + if (!*dir) + error("Flag -d must be followed by a directory name."); + } + if (argc > 1) #endif /* CHDIR */ - /* - * Now we know the directory containing 'record' and - * may do a prscore(). - */ - if (!strncmp(argv[1], "-s", 2)) { + /* + * Now we know the directory containing 'record' and + * may do a prscore(). + */ + if (!strncmp(argv[1], "-s", 2)) { #ifdef CHDIR - chdirx(dir, FALSE); + chdirx(dir, FALSE); #endif #ifdef SYSCF - initoptions(); + initoptions(); #endif - prscore(argc, argv); - exit(EXIT_SUCCESS); - } - } + prscore(argc, argv); + exit(EXIT_SUCCESS); + } + } #ifdef CHDIR - /* move to the playground directory; 'termcap' might be found there */ - chdirx(dir, TRUE); + /* move to the playground directory; 'termcap' might be found there */ + chdirx(dir, TRUE); #endif #ifdef SECURE - /* disable installed privs while loading nethack.cnf and termcap, - and also while initializing terminal [$assign("TT:")]. */ - privoff(); + /* disable installed privs while loading nethack.cnf and termcap, + and also while initializing terminal [$assign("TT:")]. */ + privoff(); #endif - initoptions(); - init_nhwindows(&argc, argv); - whoami(); + initoptions(); + init_nhwindows(&argc, argv); + whoami(); #ifdef SECURE - privon(); + privon(); #endif - /* - * It seems you really want to play. - */ - u.uhp = 1; /* prevent RIP on early quits */ + /* + * It seems you really want to play. + */ + u.uhp = 1; /* prevent RIP on early quits */ #ifndef SAVE_ON_FATAL_ERROR - /* used to clear hangup stuff while still giving standard traceback */ - VAXC$ESTABLISH(vms_handler); + /* used to clear hangup stuff while still giving standard traceback */ + VAXC$ESTABLISH(vms_handler); #endif - sethanguphandler(hangup); + sethanguphandler(hangup); - process_options(argc, argv); /* command line options */ + process_options(argc, argv); /* command line options */ - /* wizard mode access is deferred until here */ - set_playmode(); /* sets plname to "wizard" for wizard mode */ - /* strip role,race,&c suffix; calls askname() if plname[] is empty - or holds a generic user name like "player" or "games" */ - plnamesuffix(); + /* wizard mode access is deferred until here */ + set_playmode(); /* sets plname to "wizard" for wizard mode */ + /* strip role,race,&c suffix; calls askname() if plname[] is empty + or holds a generic user name like "player" or "games" */ + plnamesuffix(); - if (wizard) { - /* use character name rather than lock letter for file names */ - locknum = 0; - } else { - /* suppress interrupts while processing lock file */ - (void) signal(SIGQUIT, SIG_IGN); - (void) signal(SIGINT, SIG_IGN); - } - /* - * getlock() complains and quits if there is already a game - * in progress for current character name (when locknum == 0) - * or if there are too many active games (when locknum > 0). - * When proceeding, it creates an empty .0 file to - * designate the current game. - * getlock() constructs based on the character - * name (for !locknum) or on first available of alock, block, - * clock, &c not currently in use in the playground directory - * (for locknum > 0). - */ - getlock(); + if (wizard) { + /* use character name rather than lock letter for file names */ + locknum = 0; + } else { + /* suppress interrupts while processing lock file */ + (void) signal(SIGQUIT, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + } + /* + * getlock() complains and quits if there is already a game + * in progress for current character name (when locknum == 0) + * or if there are too many active games (when locknum > 0). + * When proceeding, it creates an empty .0 file to + * designate the current game. + * getlock() constructs based on the character + * name (for !locknum) or on first available of alock, block, + * clock, &c not currently in use in the playground directory + * (for locknum > 0). + */ + getlock(); - dlb_init(); /* must be before newgame() */ + dlb_init(); /* must be before newgame() */ - /* - * Initialize the vision system. This must be before mklev() on a - * new game or before a level restore on a saved game. - */ - vision_init(); + /* + * Initialize the vision system. This must be before mklev() on a + * new game or before a level restore on a saved game. + */ + vision_init(); - display_gamewindows(); + display_gamewindows(); - /* - * First, try to find and restore a save file for specified character. - * We'll return here if new game player_selection() renames the hero. - */ - attempt_restore: - if ((fd = restore_saved_game()) >= 0) { - const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); +/* + * First, try to find and restore a save file for specified character. + * We'll return here if new game player_selection() renames the hero. + */ +attempt_restore: + if ((fd = restore_saved_game()) >= 0) { + const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); - (void) chmod(fq_save,0); /* disallow parallel restores */ - (void) signal(SIGINT, (SIG_RET_TYPE) done1); + (void) chmod(fq_save, 0); /* disallow parallel restores */ + (void) signal(SIGINT, (SIG_RET_TYPE) done1); #ifdef NEWS - if(iflags.news) { - display_file(NEWS, FALSE); - iflags.news = FALSE; /* in case dorecover() fails */ - } + if (iflags.news) { + display_file(NEWS, FALSE); + iflags.news = FALSE; /* in case dorecover() fails */ + } #endif - pline("Restoring save file..."); - mark_synch(); /* flush output */ - if (dorecover(fd)) { - resuming = TRUE; /* not starting new game */ - wd_message(); - if (discover || wizard) { - if (yn("Do you want to keep the save file?") == 'n') - (void) delete_savefile(); - else - (void) chmod(fq_save,FCMASK); /* back to readable */ - } - } - } + pline("Restoring save file..."); + mark_synch(); /* flush output */ + if (dorecover(fd)) { + resuming = TRUE; /* not starting new game */ + wd_message(); + if (discover || wizard) { + if (yn("Do you want to keep the save file?") == 'n') + (void) delete_savefile(); + else + (void) chmod(fq_save, FCMASK); /* back to readable */ + } + } + } - if (!resuming) { - /* new game: start by choosing role, race, etc; - player might change the hero's name while doing that, - in which case we try to restore under the new name - and skip selection this time if that didn't succeed */ - if (!iflags.renameinprogress) { - player_selection(); - if (iflags.renameinprogress) { - /* player has renamed the hero while selecting role; - if locking alphabetically, the existing lock file - can still be used; otherwise, discard current one - and create another for the new character name */ - if (!locknum) { - delete_levelfile(0); /* remove empty lock file */ - getlock(); - } - goto attempt_restore; - } - } - newgame(); - wd_message(); - } + if (!resuming) { + /* new game: start by choosing role, race, etc; + player might change the hero's name while doing that, + in which case we try to restore under the new name + and skip selection this time if that didn't succeed */ + if (!iflags.renameinprogress) { + player_selection(); + if (iflags.renameinprogress) { + /* player has renamed the hero while selecting role; + if locking alphabetically, the existing lock file + can still be used; otherwise, discard current one + and create another for the new character name */ + if (!locknum) { + delete_levelfile(0); /* remove empty lock file */ + getlock(); + } + goto attempt_restore; + } + } + newgame(); + wd_message(); + } - moveloop(resuming); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return(0); + moveloop(resuming); + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return (0); } static void @@ -231,92 +234,91 @@ process_options(argc, argv) int argc; char *argv[]; { - int i; + int i; - - /* - * Process options. - */ - while(argc > 1 && argv[1][0] == '-'){ - argv++; - argc--; - switch(argv[0][1]){ - case 'D': - wizard = TRUE, discover = FALSE; - break; - case 'X': - case 'x': - discover = TRUE, wizard = FALSE; - break; + /* + * Process options. + */ + while (argc > 1 && argv[1][0] == '-') { + argv++; + argc--; + switch (argv[0][1]) { + case 'D': + wizard = TRUE, discover = FALSE; + break; + case 'X': + case 'x': + discover = TRUE, wizard = FALSE; + break; #ifdef NEWS - case 'n': - iflags.news = FALSE; - break; + case 'n': + iflags.news = FALSE; + break; #endif - case 'u': - if(argv[0][2]) - (void) strncpy(plname, argv[0]+2, sizeof(plname)-1); - else if(argc > 1) { - argc--; - argv++; - (void) strncpy(plname, argv[0], sizeof(plname)-1); - } else - raw_print("Player name expected after -u"); - break; - case 'I': - case 'i': - if (!strncmpi(argv[0]+1, "IBM", 3)) { - load_symset("IBMGraphics", PRIMARY); - load_symset("RogueIBM", ROGUESET); - switch_symbols(TRUE); - } - break; - /* case 'D': */ - case 'd': - if (!strncmpi(argv[0]+1, "DEC", 3)) { - load_symset("DECGraphics", PRIMARY); - switch_symbols(TRUE); - } - break; - case 'p': /* profession (role) */ - if (argv[0][2]) { - if ((i = str2role(&argv[0][2])) >= 0) - flags.initrole = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2role(argv[0])) >= 0) - flags.initrole = i; - } - break; - case 'r': /* race */ - if (argv[0][2]) { - if ((i = str2race(&argv[0][2])) >= 0) - flags.initrace = i; - } else if (argc > 1) { - argc--; - argv++; - if ((i = str2race(argv[0])) >= 0) - flags.initrace = i; - } - break; - case '@': - flags.randomall = 1; - break; - default: - if ((i = str2role(&argv[0][1])) >= 0) { - flags.initrole = i; - break; - } - /* else raw_printf("Unknown option: %s", *argv); */ - } - } + case 'u': + if (argv[0][2]) + (void) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); + else if (argc > 1) { + argc--; + argv++; + (void) strncpy(plname, argv[0], sizeof(plname) - 1); + } else + raw_print("Player name expected after -u"); + break; + case 'I': + case 'i': + if (!strncmpi(argv[0] + 1, "IBM", 3)) { + load_symset("IBMGraphics", PRIMARY); + load_symset("RogueIBM", ROGUESET); + switch_symbols(TRUE); + } + break; + /* case 'D': */ + case 'd': + if (!strncmpi(argv[0] + 1, "DEC", 3)) { + load_symset("DECGraphics", PRIMARY); + switch_symbols(TRUE); + } + break; + case 'p': /* profession (role) */ + if (argv[0][2]) { + if ((i = str2role(&argv[0][2])) >= 0) + flags.initrole = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2role(argv[0])) >= 0) + flags.initrole = i; + } + break; + case 'r': /* race */ + if (argv[0][2]) { + if ((i = str2race(&argv[0][2])) >= 0) + flags.initrace = i; + } else if (argc > 1) { + argc--; + argv++; + if ((i = str2race(argv[0])) >= 0) + flags.initrace = i; + } + break; + case '@': + flags.randomall = 1; + break; + default: + if ((i = str2role(&argv[0][1])) >= 0) { + flags.initrole = i; + break; + } + /* else raw_printf("Unknown option: %s", *argv); */ + } + } - if(argc > 1) - locknum = atoi(argv[1]); + if (argc > 1) + locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS - if(!locknum || locknum > MAX_NR_OF_PLAYERS) - locknum = MAX_NR_OF_PLAYERS; + if (!locknum || locknum > MAX_NR_OF_PLAYERS) + locknum = MAX_NR_OF_PLAYERS; #endif } @@ -326,68 +328,72 @@ chdirx(dir, wr) const char *dir; boolean wr; { -# ifndef HACKDIR - static const char *defdir = "."; -# else - static const char *defdir = HACKDIR; +#ifndef HACKDIR + static const char *defdir = "."; +#else + static const char *defdir = HACKDIR; - if(dir == (const char *)0) - dir = defdir; - else if (wr && !same_dir(HACKDIR, dir)) - /* If we're playing anywhere other than HACKDIR, turn off any - privs we may have been installed with. */ - privoff(); -# endif + if (dir == (const char *) 0) + dir = defdir; + else if (wr && !same_dir(HACKDIR, dir)) + /* If we're playing anywhere other than HACKDIR, turn off any + privs we may have been installed with. */ + privoff(); +#endif - if(dir && chdir(dir) < 0) { - perror(dir); - error("Cannot chdir to %s.", dir); - } + if (dir && chdir(dir) < 0) { + perror(dir); + error("Cannot chdir to %s.", dir); + } - /* warn the player if we can't write the record file */ - if (wr) check_recordfile(dir); + /* warn the player if we can't write the record file */ + if (wr) + check_recordfile(dir); - defdir = dir; + defdir = dir; } #endif /* CHDIR */ static void whoami() { - /* - * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS - * 2. Use lowercase of $USER (if 1. fails) - * The resulting name is overridden by command line options. - * If everything fails, or if the resulting name is some generic - * account like "games" then eventually we'll ask him. - * Note that we trust the user here; it is possible to play under - * somebody else's name. - */ - register char *s; + /* + * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS + * 2. Use lowercase of $USER (if 1. fails) + * The resulting name is overridden by command line options. + * If everything fails, or if the resulting name is some generic + * account like "games" then eventually we'll ask him. + * Note that we trust the user here; it is possible to play under + * somebody else's name. + */ + register char *s; - if (!*plname && (s = nh_getenv("USER"))) - (void) lcase(strncpy(plname, s, sizeof(plname)-1)); + if (!*plname && (s = nh_getenv("USER"))) + (void) lcase(strncpy(plname, s, sizeof(plname) - 1)); } static void byebye() { - void FDECL((*hup), (int)); + void FDECL((*hup), (int) ); #ifdef SHELL extern unsigned long dosh_pid, mail_pid; - extern unsigned long FDECL(sys$delprc,(unsigned long *,const genericptr_t)); + extern unsigned long FDECL(sys$delprc, + (unsigned long *, const genericptr_t)); - /* clean up any subprocess we've spawned that may still be hanging around */ - if (dosh_pid) (void) sys$delprc(&dosh_pid, (genericptr_t)0), dosh_pid = 0; - if (mail_pid) (void) sys$delprc(&mail_pid, (genericptr_t)0), mail_pid = 0; + /* clean up any subprocess we've spawned that may still be hanging around + */ + if (dosh_pid) + (void) sys$delprc(&dosh_pid, (genericptr_t) 0), dosh_pid = 0; + if (mail_pid) + (void) sys$delprc(&mail_pid, (genericptr_t) 0), mail_pid = 0; #endif /* SIGHUP doesn't seem to do anything on VMS, so we fudge it here... */ - hup = (void FDECL((*),(int))) signal(SIGHUP, SIG_IGN); - if (!program_state.exiting++ && - hup != (void FDECL((*),(int))) SIG_DFL && - hup != (void FDECL((*),(int))) SIG_IGN) { - (*hup)(SIGHUP); + hup = (void FDECL((*), (int) )) signal(SIGHUP, SIG_IGN); + if (!program_state.exiting++ && hup != (void FDECL((*), (int) )) SIG_DFL + && hup != (void FDECL((*), (int) )) SIG_IGN) { + (*hup)(SIGHUP); } #ifdef CHDIR @@ -399,20 +405,20 @@ byebye() /* Condition handler to prevent byebye's hangup simulation from saving the game after a fatal error has occurred. */ /*ARGSUSED*/ -static vms_handler_type /* should be `unsigned long', but the -*/ -vms_handler(sigargs, mechargs) /*+ prototype in is screwed */ -genericptr_t sigargs, mechargs; /* [0] is argc, [1..argc] are the real args */ +static vms_handler_type /* should be `unsigned long', but the -*/ + vms_handler(sigargs, mechargs) /*+ prototype in is screwed */ +genericptr_t sigargs, mechargs; /* [0] is argc, [1..argc] are the real args */ { - unsigned long condition = ((unsigned long *)sigargs)[1]; + unsigned long condition = ((unsigned long *) sigargs)[1]; - if (condition == SS$_ACCVIO /* access violation */ - || (condition >= SS$_ASTFLT && condition <= SS$_TBIT) - || (condition >= SS$_ARTRES && condition <= SS$_INHCHME)) { - program_state.done_hup = TRUE; /* pretend hangup has been attempted */ -# ifndef BETA - if (wizard) -# endif /* !BETA */ - abort(); /* enter the debugger */ + if (condition == SS$_ACCVIO /* access violation */ + || (condition >= SS$_ASTFLT && condition <= SS$_TBIT) + || (condition >= SS$_ARTRES && condition <= SS$_INHCHME)) { + program_state.done_hup = TRUE; /* pretend hangup has been attempted */ +#ifndef BETA + if (wizard) +#endif /* !BETA */ + abort(); /* enter the debugger */ } return SS$_RESIGNAL; } @@ -422,18 +428,18 @@ void sethanguphandler(handler) void FDECL((*handler), (int)); { - (void)signal(SIGHUP, (SIG_RET_TYPE)handler); + (void) signal(SIGHUP, (SIG_RET_TYPE) handler); } #ifdef PORT_HELP void port_help() { - /* - * Display VMS-specific help. Just show contents of the helpfile - * named by PORT_HELP. - */ - display_file(PORT_HELP, TRUE); + /* + * Display VMS-specific help. Just show contents of the helpfile + * named by PORT_HELP. + */ + display_file(PORT_HELP, TRUE); } #endif /* PORT_HELP */ @@ -445,21 +451,22 @@ port_help() boolean authorize_wizard_mode() { - if (!strcmpi(nh_getenv("USER"), WIZARD_NAME)) return TRUE; - wiz_error_flag = TRUE; /* not being allowed into wizard mode */ - return FALSE; + if (!strcmpi(nh_getenv("USER"), WIZARD_NAME)) + return TRUE; + wiz_error_flag = TRUE; /* not being allowed into wizard mode */ + return FALSE; } static void wd_message() { - if (wiz_error_flag) { - pline("Only user \"%s\" may access debug (wizard) mode.", - WIZARD_NAME); - pline("Entering explore/discovery mode instead."); - wizard = 0, discover = 1; /* (paranoia) */ - } else if (discover) - You("are in non-scoring explore/discovery mode."); + if (wiz_error_flag) { + pline("Only user \"%s\" may access debug (wizard) mode.", + WIZARD_NAME); + pline("Entering explore/discovery mode instead."); + wizard = 0, discover = 1; /* (paranoia) */ + } else if (discover) + You("are in non-scoring explore/discovery mode."); } /*vmsmain.c*/ diff --git a/sys/vms/vmsmisc.c b/sys/vms/vmsmisc.c index 54cf142a0..0408fb7cb 100644 --- a/sys/vms/vmsmisc.c +++ b/sys/vms/vmsmisc.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmsmisc.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmsmisc.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 vmsmisc.c $Date: 2011/09/01 01:47:00 $ $Revision: 1.6 $ */ /* NetHack may be freely redistributed. See license for details. */ @@ -7,13 +7,13 @@ #include #include -int debuggable = 0; /* 1 if we can debug or show a call trace */ +int debuggable = 0; /* 1 if we can debug or show a call trace */ void FDECL(vms_exit, (int)); void NDECL(vms_abort); /* first arg should be unsigned long but has unsigned int */ -extern void VDECL(lib$signal, (unsigned,...)); +extern void VDECL(lib$signal, (unsigned, ...)); /* terminate, converting Unix-style exit code into VMS status code */ void @@ -30,17 +30,17 @@ void vms_abort() { if (debuggable) - lib$signal(SS$_DEBUG); + lib$signal(SS$_DEBUG); /* we'll get here if the debugger isn't available, or if the user uses GO to resume execution instead of EXIT to quit */ - vms_exit(2); /* don't return to caller (2==arbitrary non-zero) */ + vms_exit(2); /* don't return to caller (2==arbitrary non-zero) */ /* NOT REACHED */ } - /* - * Caveat: the VERYOLD_VMS configuration hasn't been tested in many years. - */ +/* + * Caveat: the VERYOLD_VMS configuration hasn't been tested in many years. + */ #ifdef VERYOLD_VMS #include "oldcrtl.c" #endif diff --git a/sys/vms/vmstty.c b/sys/vms/vmstty.c index 3e8f71985..4795ada27 100644 --- a/sys/vms/vmstty.c +++ b/sys/vms/vmstty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmstty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmstty.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 vmstty.c $Date: 2011/04/13 01:48:13 $ $Revision: 1.10 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -15,17 +15,17 @@ #include #include #include -#else /* values needed from missing include files */ -# define SMG$K_TRM_UP 274 -# define SMG$K_TRM_DOWN 275 -# define SMG$K_TRM_LEFT 276 -# define SMG$K_TRM_RIGHT 277 -# define TT$M_MECHTAB 0x00000100 /* hardware tab support */ -# define TT$M_MECHFORM 0x00080000 /* hardware form-feed support */ -# define TT$M_NOBRDCST 0x00020000 /* disable broadcast messages, but */ -# define TT2$M_BRDCSTMBX 0x00000010 /* catch them in associated mailbox */ -# define TT2$M_APP_KEYPAD 0x00800000 /* application vs numeric keypad mode */ -#endif /* __GNUC__ */ +#else /* values needed from missing include files */ +#define SMG$K_TRM_UP 274 +#define SMG$K_TRM_DOWN 275 +#define SMG$K_TRM_LEFT 276 +#define SMG$K_TRM_RIGHT 277 +#define TT$M_MECHTAB 0x00000100 /* hardware tab support */ +#define TT$M_MECHFORM 0x00080000 /* hardware form-feed support */ +#define TT$M_NOBRDCST 0x00020000 /* disable broadcast messages, but */ +#define TT2$M_BRDCSTMBX 0x00000010 /* catch them in associated mailbox */ +#define TT2$M_APP_KEYPAD 0x00800000 /* application vs numeric keypad mode */ +#endif /* __GNUC__ */ #ifdef USE_QIO_INPUT #include #endif @@ -36,72 +36,72 @@ unsigned long lib$disable_ctrl(), lib$enable_ctrl(); unsigned long sys$assign(), sys$dassgn(), sys$qiow(); #ifndef USE_QIO_INPUT unsigned long smg$create_virtual_keyboard(), smg$delete_virtual_keyboard(), - smg$read_keystroke(), smg$cancel_input(); + smg$read_keystroke(), smg$cancel_input(); #else static short FDECL(parse_function_key, (int)); #endif static void NDECL(setctty); static void NDECL(resettty); -#define vms_ok(sts) ((sts)&1) -#define META(c) ((c)|0x80) /* 8th bit */ -#define CTRL(c) ((c)&0x1F) -#define CMASK(c) (1< 0) - altprefix = *nhalthack; + /* one-time init */ + nhalthack = nh_getenv("NH_ALTHACK"); + althack = nhalthack ? 1 : -1; + if (althack > 0) + altprefix = *nhalthack; } -# define vms_getchar nh_vms_getchar +#define vms_getchar nh_vms_getchar res = vms_getchar(); if (althack > 0 && res == altprefix) { - res = vms_getchar(); - if (res != ESC) res = META(res); + res = vms_getchar(); + if (res != ESC) + res = META(res); } return res; } @@ -141,120 +142,144 @@ vms_getchar() struct _rd_iosb iosb; unsigned long sts; unsigned char kb_buf; -#else /* SMG input */ - static volatile int recurse = 0; /* SMG is not AST re-entrant! */ +#else /* SMG input */ + static volatile int recurse = 0; /* SMG is not AST re-entrant! */ #endif if (program_state.done_hup) { - /* hangup has occurred; do not attempt to get further user input */ - return ESC; + /* hangup has occurred; do not attempt to get further user input */ + return ESC; } #ifdef USE_QIO_INPUT if (inc > 0) { - /* we have buffered character(s) from previous read */ - kb_buf = *inp++; - --inc; - sts = SS$_NORMAL; + /* we have buffered character(s) from previous read */ + kb_buf = *inp++; + --inc; + sts = SS$_NORMAL; } else { - sts = sys$qiow(0, tt_chan, QIO_FUNC, &iosb, (void(*)())0, 0, - &kb_buf, sizeof kb_buf, 0, 0, 0, 0); + sts = sys$qiow(0, tt_chan, QIO_FUNC, &iosb, (void (*) ()) 0, 0, + &kb_buf, sizeof kb_buf, 0, 0, 0, 0); } if (vms_ok(sts)) { - if (kb_buf == CTRL('C')) { - if (intr_char) gsignal(SIGINT); - key = (short)kb_buf; - } else if (kb_buf == '\r') { /* */ - key = (short)'\n'; - } else if (kb_buf == ESC || kb_buf == CSI || kb_buf == SS3) { - switch(parse_function_key((int)kb_buf)) { - case SMG$K_TRM_UP: key = Cmd.move_N; break; - case SMG$K_TRM_DOWN: key = Cmd.move_S; break; - case SMG$K_TRM_LEFT: key = Cmd.move_W; break; - case SMG$K_TRM_RIGHT: key = Cmd.move_E; break; - default: key = ESC; break; - } - } else { - key = (short)kb_buf; - } + if (kb_buf == CTRL('C')) { + if (intr_char) + gsignal(SIGINT); + key = (short) kb_buf; + } else if (kb_buf == '\r') { /* */ + key = (short) '\n'; + } else if (kb_buf == ESC || kb_buf == CSI || kb_buf == SS3) { + switch (parse_function_key((int) kb_buf)) { + case SMG$K_TRM_UP: + key = Cmd.move_N; + break; + case SMG$K_TRM_DOWN: + key = Cmd.move_S; + break; + case SMG$K_TRM_LEFT: + key = Cmd.move_W; + break; + case SMG$K_TRM_RIGHT: + key = Cmd.move_E; + break; + default: + key = ESC; + break; + } + } else { + key = (short) kb_buf; + } } else if (sts == SS$_HANGUP || iosb.status == SS$_HANGUP - || sts == SS$_DEVOFFLINE) { - gsignal(SIGHUP); - key = ESC; - } else /*(this should never happen)*/ - key = getchar(); + || sts == SS$_DEVOFFLINE) { + gsignal(SIGHUP); + key = ESC; + } else /*(this should never happen)*/ + key = getchar(); -#else /*!USE_QIO_INPUT*/ +#else /*!USE_QIO_INPUT*/ if (recurse++ == 0 && kb != 0) { - smg$read_keystroke(&kb, &key); - switch (key) { - case SMG$K_TRM_UP: key = Cmd.move_N; break; - case SMG$K_TRM_DOWN: key = Cmd.move_S; break; - case SMG$K_TRM_LEFT: key = Cmd.move_W; break; - case SMG$K_TRM_RIGHT: key = Cmd.move_E; break; - case '\r': key = '\n'; break; - default: if (key > 255) key = ESC; - break; - } + smg$read_keystroke(&kb, &key); + switch (key) { + case SMG$K_TRM_UP: + key = Cmd.move_N; + break; + case SMG$K_TRM_DOWN: + key = Cmd.move_S; + break; + case SMG$K_TRM_LEFT: + key = Cmd.move_W; + break; + case SMG$K_TRM_RIGHT: + key = Cmd.move_E; + break; + case '\r': + key = '\n'; + break; + default: + if (key > 255) + key = ESC; + break; + } } else { - /* abnormal input--either SMG didn't initialize properly or - vms_getchar() has been called recursively (via SIGINT handler). - */ - if (kb != 0) /* must have been a recursive call */ - smg$cancel_input(&kb); /* from an interrupt handler */ - key = getchar(); + /* abnormal input--either SMG didn't initialize properly or + vms_getchar() has been called recursively (via SIGINT handler). + */ + if (kb != 0) /* must have been a recursive call */ + smg$cancel_input(&kb); /* from an interrupt handler */ + key = getchar(); } --recurse; -#endif /* USE_QIO_INPUT */ +#endif /* USE_QIO_INPUT */ - return (int)key; + return (int) key; } #ifdef USE_QIO_INPUT - /* - * We've just gotten an character. Do a timed read to - * get any other characters, then try to parse them as an escape - * sequence. This isn't perfect, since there's no guarantee - * that a full escape sequence will be available, or even if one - * is, it might actually by regular input from a fast typist or - * a stalled input connection. {For packetized environments, - * cross plural(body_part(FINGER)) and hope for best. :-} - * - * This is needed to preserve compatability with SMG interface - * for two reasons: - * 1) retain support for arrow keys, and - * 2) treat other VTxxx function keys as for aborting - * various NetHack prompts. - * The second reason is compelling; otherwise remaining chars of - * an escape sequence get treated as inappropriate user commands. - * - * SMG code values for these key sequences fall in the range of - * 256 thru 3xx. The assignments are not particularly intuitive. - */ +/* + * We've just gotten an character. Do a timed read to + * get any other characters, then try to parse them as an escape + * sequence. This isn't perfect, since there's no guarantee + * that a full escape sequence will be available, or even if one + * is, it might actually by regular input from a fast typist or + * a stalled input connection. {For packetized environments, + * cross plural(body_part(FINGER)) and hope for best. :-} + * + * This is needed to preserve compatability with SMG interface + * for two reasons: + * 1) retain support for arrow keys, and + * 2) treat other VTxxx function keys as for aborting + * various NetHack prompts. + * The second reason is compelling; otherwise remaining chars of + * an escape sequence get treated as inappropriate user commands. + * + * SMG code values for these key sequences fall in the range of + * 256 thru 3xx. The assignments are not particularly intuitive. + */ /*= -- Summary of VTxxx-style keyboards and transmitted escape sequences. -- Keypad codes are prefixed by 7 bit (\033 O) or 8 bit SS3: - keypad: PF1 PF2 PF3 PF4 codes: P Q R S - 7 8 9 - w x y m - 4 5 6 . t u v n - 1 2 3 :en-: q r s : : - ...0... , :ter: ...p... l :M: + keypad: PF1 PF2 PF3 PF4 codes: P Q R S + 7 8 9 - w x y m + 4 5 6 . t u v n + 1 2 3 :en-: q r s : : + ...0... , :ter: ...p... l :M: Arrows are prefixed by either SS3 or CSI (either 7 or 8 bit), depending on whether the terminal is in application or numeric mode (ditto for PF keys): - arrows: A B D C -Additional function keys (vk201/vk401) generate CSI nn ~ (nn is 1 or 2 digits): + arrows: A B D C +Additional function keys (vk201/vk401) generate CSI nn ~ (nn is 1 or 2 +digits): vk201 keys: F6 F7 F8 F9 F10 F11 F12 F13 F14 Help Do F17 F18 F19 F20 'nn' digits: 17 18 19 20 21 23 24 25 26 28 29 31 32 33 34 alternate: ^C ^[ ^H ^J (when in VT100 mode) edit keypad: digits: 1 2 3 - 4 5 6 + 4 5 6 VT52 mode: arrows and PF keys send ESCx where x is in A-D or P-S. =*/ -static const char *arrow_or_PF = "ABCDPQRS", /* suffix char */ - *smg_keypad_codes = "PQRSpqrstuvwxyMmlnABDC"; - /* PF1..PF4,KP0..KP9,enter,dash,comma,dot,up-arrow,down,left,right */ - /* Ultimate return value is (index into smg_keypad_codes[] + 256). */ +static const char *arrow_or_PF = "ABCDPQRS", /* suffix char */ + *smg_keypad_codes = "PQRSpqrstuvwxyMmlnABDC"; +/* PF1..PF4,KP0..KP9,enter,dash,comma,dot,up-arrow,down,left,right */ +/* Ultimate return value is (index into smg_keypad_codes[] + 256). */ static short parse_function_key(c) @@ -262,8 +287,8 @@ register int c; { struct _rd_iosb iosb; unsigned long sts; - char seq_buf[15+1]; /* plenty room for escape sequence + slop */ - short result = ESC; /* translate to by default */ + char seq_buf[15 + 1]; /* plenty room for escape sequence + slop */ + short result = ESC; /* translate to by default */ /* * Read whatever we can from type-ahead buffer (1 second timeout). @@ -273,49 +298,60 @@ register int c; * We might already have [at least some of] an escape sequence from a * previous read, particularly if user holds down the arrow keys... */ - if (inc > 0) strncpy(seq_buf, inp, inc); - if (inc < (int)(sizeof seq_buf) - 1) { - sts = sys$qiow(0, tt_chan, QIO_FUNC|IO$M_TIMED, &iosb, (void(*)())0, 0, - seq_buf + inc, sizeof seq_buf - 1 - inc, 1, 0, 0, 0); - if (vms_ok(sts)) sts = iosb.status; + if (inc > 0) + strncpy(seq_buf, inp, inc); + if (inc < (int) (sizeof seq_buf) - 1) { + sts = sys$qiow(0, tt_chan, QIO_FUNC | IO$M_TIMED, &iosb, + (void (*) ()) 0, 0, seq_buf + inc, + sizeof seq_buf - 1 - inc, 1, 0, 0, 0); + if (vms_ok(sts)) + sts = iosb.status; } else - sts = SS$_NORMAL; + sts = SS$_NORMAL; if (vms_ok(sts) || sts == SS$_TIMEOUT) { - register int cnt = iosb.trm_offset + iosb.trm_siz + inc; - register char *p = seq_buf; - if (c == ESC) /* check for 7-bit vt100/ANSI, or vt52 */ - if (*p == '[' || *p == 'O') c = META(CTRL(*p++)), cnt--; - else if (strchr(arrow_or_PF, *p)) c = SS3; /*CSI*/ - if (cnt > 0 && (c == SS3 || (c == CSI && strchr(arrow_or_PF, *p)))) { - register char *q = strchr(smg_keypad_codes, *p); - if (q) result = 256 + (q - smg_keypad_codes); - p++, --cnt; /* one more char consumed */ - } else if (cnt > 1 && c == CSI) { - static short /* "CSI nn ~" -> F_keys[nn] */ - F_keys[35] = { ESC, /*(filler)*/ - 311, 312, 313, 314, 315, 316, /* E1-E6 */ - ESC, ESC, ESC, ESC, /*(more filler)*/ - 281, 282, 283, 284, 285, ESC, /* F1-F5 */ - 286, 287, 288, 289, 290, ESC, /* F6-F10*/ - 291, 292, 293, 294, ESC, /*F11-F14*/ - 295, 296, ESC, /*,, aka F15,F16*/ - 297, 298, 299, 300 /*F17-F20*/ - }; /* note: there are several missing nn in CSI nn ~ values */ - int nn; char *q; - *(p + cnt) = '\0'; /* terminate string */ - q = strchr(p, '~'); - if (q && sscanf(p, "%d~", &nn) == 1) { - if (nn > 0 && nn < SIZE(F_keys)) result = F_keys[nn]; - cnt -= (++q - p); - p = q; - } - } - if (cnt > 0) strncpy((inp = inputbuf), p, (inc = cnt)); - else inc = 0, inp = 0; + register int cnt = iosb.trm_offset + iosb.trm_siz + inc; + register char *p = seq_buf; + if (c == ESC) /* check for 7-bit vt100/ANSI, or vt52 */ + if (*p == '[' || *p == 'O') + c = META(CTRL(*p++)), cnt--; + else if (strchr(arrow_or_PF, *p)) + c = SS3; /*CSI*/ + if (cnt > 0 && (c == SS3 || (c == CSI && strchr(arrow_or_PF, *p)))) { + register char *q = strchr(smg_keypad_codes, *p); + if (q) + result = 256 + (q - smg_keypad_codes); + p++, --cnt; /* one more char consumed */ + } else if (cnt > 1 && c == CSI) { + static short /* "CSI nn ~" -> F_keys[nn] */ + F_keys[35] = { + ESC, /*(filler)*/ + 311, 312, 313, 314, 315, 316, /* E1-E6 */ + ESC, ESC, ESC, ESC, /*(more filler)*/ + 281, 282, 283, 284, 285, ESC, /* F1-F5 */ + 286, 287, 288, 289, 290, ESC, /* F6-F10*/ + 291, 292, 293, 294, ESC, /*F11-F14*/ + 295, 296, ESC, /*,, aka F15,F16*/ + 297, 298, 299, 300 /*F17-F20*/ + }; /* note: there are several missing nn in CSI nn ~ values */ + int nn; + char *q; + *(p + cnt) = '\0'; /* terminate string */ + q = strchr(p, '~'); + if (q && sscanf(p, "%d~", &nn) == 1) { + if (nn > 0 && nn < SIZE(F_keys)) + result = F_keys[nn]; + cnt -= (++q - p); + p = q; + } + } + if (cnt > 0) + strncpy((inp = inputbuf), p, (inc = cnt)); + else + inc = 0, inp = 0; } return result; } -#endif /* USE_QIO_INPUT */ +#endif /* USE_QIO_INPUT */ static void setctty() @@ -323,28 +359,28 @@ setctty() struct _sm_iosb iosb; unsigned long status; - status = sys$qiow(0, tt_chan, IO$_SETMODE, &iosb, (void(*)())0, 0, - &sg.sm, sizeof sg.sm, 0, 0, 0, 0); - if (vms_ok(status)) status = iosb.status; + status = sys$qiow(0, tt_chan, IO$_SETMODE, &iosb, (void (*) ()) 0, 0, + &sg.sm, sizeof sg.sm, 0, 0, 0, 0); + if (vms_ok(status)) + status = iosb.status; if (vms_ok(status)) { - /* try to force terminal into synch with TTDRIVER's setting */ - number_pad((sg.sm.tt2_char & TT2$M_APP_KEYPAD) ? -1 : 1); + /* try to force terminal into synch with TTDRIVER's setting */ + number_pad((sg.sm.tt2_char & TT2$M_APP_KEYPAD) ? -1 : 1); } else { - raw_print(""); - errno = EVMSERR, vaxc$errno = status; - perror("NetHack(setctty: setmode)"); - wait_synch(); + raw_print(""); + errno = EVMSERR, vaxc$errno = status; + perror("NetHack(setctty: setmode)"); + wait_synch(); } } -static void -resettty() /* atexit() routine */ +static void resettty() /* atexit() routine */ { if (settty_needed) { - bombing = TRUE; /* don't clear screen; preserve traceback info */ - settty((char *)0); + bombing = TRUE; /* don't clear screen; preserve traceback info */ + settty((char *) 0); } - (void) sys$dassgn(tt_chan), tt_chan = 0; + (void) sys$dassgn(tt_chan), tt_chan = 0; } /* @@ -361,44 +397,46 @@ gettty() int err = 0; unsigned long status, zero = 0; - if (tt_chan == 0) { /* do this stuff once only */ - iflags.cbreak = OFF, iflags.echo = ON; /* until setup is complete */ - status = sys$assign(&tty_dsc, &tt_chan, 0, 0); - if (!vms_ok(status)) { - raw_print(""), err++; - errno = EVMSERR, vaxc$errno = status; - perror("NetHack(gettty: $assign)"); - } - atexit(resettty); /* register an exit handler to reset things */ + if (tt_chan == 0) { /* do this stuff once only */ + iflags.cbreak = OFF, iflags.echo = ON; /* until setup is complete */ + status = sys$assign(&tty_dsc, &tt_chan, 0, 0); + if (!vms_ok(status)) { + raw_print(""), err++; + errno = EVMSERR, vaxc$errno = status; + perror("NetHack(gettty: $assign)"); + } + atexit(resettty); /* register an exit handler to reset things */ } - status = sys$qiow(0, tt_chan, IO$_SENSEMODE, &sg.io, (void(*)())0, 0, - &sg.sm, sizeof sg.sm, 0, 0, 0, 0); - if (vms_ok(status)) status = sg.io.status; + status = sys$qiow(0, tt_chan, IO$_SENSEMODE, &sg.io, (void (*) ()) 0, 0, + &sg.sm, sizeof sg.sm, 0, 0, 0, 0); + if (vms_ok(status)) + status = sg.io.status; if (!vms_ok(status)) { - raw_print(""), err++; - errno = EVMSERR, vaxc$errno = status; - perror("NetHack(gettty: sensemode)"); + raw_print(""), err++; + errno = EVMSERR, vaxc$errno = status; + perror("NetHack(gettty: sensemode)"); } ospeed = sg.io.xmt_speed; - erase_char = '\177'; /* , aka */ + erase_char = '\177'; /* , aka */ kill_char = CTRL('U'); intr_char = CTRL('C'); (void) lib$enable_ctrl(&zero, &ctrl_mask); /* Use the systems's values for lines and columns if it has any idea. */ if (sg.sm.page_length) - LI = sg.sm.page_length; + LI = sg.sm.page_length; if (sg.sm.page_width) - CO = sg.sm.page_width; + CO = sg.sm.page_width; /* suppress tab and form-feed expansion, in case termcap uses them */ - tt_char_restore = sg.sm.tt_char; - tt_char_active = sg.sm.tt_char |= TT_SPECIAL_HANDLING; + tt_char_restore = sg.sm.tt_char; + tt_char_active = sg.sm.tt_char |= TT_SPECIAL_HANDLING; tt2_char_restore = sg.sm.tt2_char; - tt2_char_active = sg.sm.tt2_char |= TT2_SPECIAL_HANDLING; -#if 0 /*[ defer until setftty() ]*/ + tt2_char_active = sg.sm.tt2_char |= TT2_SPECIAL_HANDLING; +#if 0 /*[ defer until setftty() ]*/ setctty(); #endif - if (err) wait_synch(); + if (err) + wait_synch(); } /* reset terminal to original state */ @@ -406,24 +444,26 @@ void settty(s) const char *s; { - if (!bombing) end_screen(); - if (s) raw_print(s); + if (!bombing) + end_screen(); + if (s) + raw_print(s); if (settty_needed) { - disable_broadcast_trapping(); -#if 0 /* let SMG's exit handler do the cleanup (as per doc) */ + disable_broadcast_trapping(); +#if 0 /* let SMG's exit handler do the cleanup (as per doc) */ /* #ifndef USE_QIO_INPUT */ if (kb) smg$delete_virtual_keyboard(&kb), kb = 0; -#endif /* 0 (!USE_QIO_INPUT) */ - if (ctrl_mask) - (void) lib$enable_ctrl(&ctrl_mask, 0); - iflags.echo = ON; - iflags.cbreak = OFF; - /* reset original tab, form-feed, broadcast settings */ - sg.sm.tt_char = tt_char_restore; - sg.sm.tt2_char = tt2_char_restore; - setctty(); +#endif /* 0 (!USE_QIO_INPUT) */ + if (ctrl_mask) + (void) lib$enable_ctrl(&ctrl_mask, 0); + iflags.echo = ON; + iflags.cbreak = OFF; + /* reset original tab, form-feed, broadcast settings */ + sg.sm.tt_char = tt_char_restore; + sg.sm.tt2_char = tt2_char_restore; + setctty(); - settty_needed = FALSE; + settty_needed = FALSE; } } @@ -432,94 +472,92 @@ void shuttty(s) const char *s; { - bombing = TRUE; - settty(s); - bombing = FALSE; + bombing = TRUE; + settty(s); + bombing = FALSE; } void setftty() { - unsigned long mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY; + unsigned long mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY; - (void) lib$disable_ctrl(&mask, 0); - if (kb == 0) { /* do this stuff once only */ + (void) lib$disable_ctrl(&mask, 0); + if (kb == 0) { /* do this stuff once only */ #ifdef USE_QIO_INPUT - kb = tt_chan; -#else /*!USE_QIO_INPUT*/ - smg$create_virtual_keyboard(&kb); -#endif /*USE_QIO_INPUT*/ - init_broadcast_trapping(); - } - enable_broadcast_trapping(); /* no-op if !defined(MAIL) */ - iflags.cbreak = (kb != 0) ? ON : OFF; - iflags.echo = (kb != 0) ? OFF : ON; - /* disable tab & form-feed expansion; prepare for broadcast trapping */ - sg.sm.tt_char = tt_char_active; - sg.sm.tt2_char = tt2_char_active; - setctty(); + kb = tt_chan; +#else /*!USE_QIO_INPUT*/ + smg$create_virtual_keyboard(&kb); +#endif /*USE_QIO_INPUT*/ + init_broadcast_trapping(); + } + enable_broadcast_trapping(); /* no-op if !defined(MAIL) */ + iflags.cbreak = (kb != 0) ? ON : OFF; + iflags.echo = (kb != 0) ? OFF : ON; + /* disable tab & form-feed expansion; prepare for broadcast trapping */ + sg.sm.tt_char = tt_char_active; + sg.sm.tt2_char = tt2_char_active; + setctty(); - start_screen(); - settty_needed = TRUE; + start_screen(); + settty_needed = TRUE; } -void -intron() /* enable kbd interupts if enabled when game started */ +void intron() /* enable kbd interupts if enabled when game started */ { - intr_char = CTRL('C'); + intr_char = CTRL('C'); } -void -introff() /* disable kbd interrupts if required*/ +void introff() /* disable kbd interrupts if required*/ { - intr_char = 0; + intr_char = 0; } #ifdef TIMED_DELAY -extern unsigned long - FDECL(lib$emul, (const long *,const long *,const long *,long *)); +extern unsigned long FDECL(lib$emul, (const long *, const long *, + const long *, long *)); extern unsigned long sys$schdwk(), sys$hiber(); -#define VMS_UNITS_PER_SECOND 10000000L /* hundreds of nanoseconds, 1e-7 */ +#define VMS_UNITS_PER_SECOND 10000000L /* hundreds of nanoseconds, 1e-7 */ /* constant for conversion from milliseconds to VMS delta time (negative) */ static const long mseconds_to_delta = VMS_UNITS_PER_SECOND / 1000L * -1L; /* sleep for specified number of milliseconds (note: the timer used generally only has 10-millisecond resolution at the hardware level...) */ -void msleep(mseconds) -unsigned mseconds; /* milliseconds */ +void +msleep(mseconds) +unsigned mseconds; /* milliseconds */ { long pid = 0L, zero = 0L, msec, qtime[2]; msec = (long) mseconds; if (msec > 0 && - /* qtime{0:63} = msec{0:31} * mseconds_to_delta{0:31} + zero{0:31} */ - vms_ok(lib$emul(&msec, &mseconds_to_delta, &zero, qtime))) { - /* schedule a wake-up call, then go to sleep */ - if (vms_ok(sys$schdwk(&pid, (genericptr_t)0, qtime, (long *)0))) - (void)sys$hiber(); + /* qtime{0:63} = msec{0:31} * mseconds_to_delta{0:31} + zero{0:31} */ + vms_ok(lib$emul(&msec, &mseconds_to_delta, &zero, qtime))) { + /* schedule a wake-up call, then go to sleep */ + if (vms_ok(sys$schdwk(&pid, (genericptr_t) 0, qtime, (long *) 0))) + (void) sys$hiber(); } } -#endif /* TIMED_DELAY */ - +#endif /* TIMED_DELAY */ /* fatal error */ /*VARARGS1*/ -void -error VA_DECL(const char *,s) - VA_START(s); - VA_INIT(s, const char *); +void error +VA_DECL(const char *, s) + VA_START(s); + VA_INIT(s, const char *); - if (settty_needed) - settty((char *)0); - Vprintf(s,VA_ARGS); - (void) putchar('\n'); - VA_END(); + if (settty_needed) + settty((char *) 0); + Vprintf(s, VA_ARGS); + (void) putchar('\n'); + VA_END(); #ifndef SAVE_ON_FATAL_ERROR - /* prevent vmsmain's exit handler byebye() from calling hangup() */ - sethanguphandler((void FDECL((*),(int)))SIG_DFL); + /* prevent vmsmain's exit handler byebye() from calling hangup() */ + sethanguphandler((void FDECL((*), (int) )) SIG_DFL); #endif - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } diff --git a/sys/vms/vmsunix.c b/sys/vms/vmsunix.c index a0202c56b..8b9cd8f46 100644 --- a/sys/vms/vmsunix.c +++ b/sys/vms/vmsunix.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vmsunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 vmsunix.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 vmsunix.c $Date: 2011/09/01 01:47:00 $ $Revision: 1.8 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,29 +17,29 @@ #ifdef GNUC #include #else -# define umask hide_umask_dummy /* DEC C: avoid conflict with system.h */ +#define umask hide_umask_dummy /* DEC C: avoid conflict with system.h */ #include -# undef umask +#undef umask #endif #include -extern int debuggable; /* defined in vmsmisc.c */ +extern int debuggable; /* defined in vmsmisc.c */ -extern void VDECL(lib$signal, (unsigned,...)); +extern void VDECL(lib$signal, (unsigned, ...)); extern unsigned long sys$setprv(); extern unsigned long lib$getdvi(), lib$getjpi(), lib$spawn(), lib$attach(); extern unsigned long smg$init_term_table_by_type(), smg$del_term_table(); -#define vms_ok(sts) ((sts) & 1) /* odd => success */ +#define vms_ok(sts) ((sts) &1) /* odd => success */ /* this could be static; it's only used within this file; it won't be used at all if C_LIB$INTIALIZE gets commented out below, so make it global so that compiler won't complain that it's not used */ -int FDECL(vmsexeini, (const void *,const void *,const unsigned char *)); +int FDECL(vmsexeini, (const void *, const void *, const unsigned char *)); static int FDECL(veryold, (int)); static char *NDECL(verify_term); #if defined(SHELL) || defined(SUSPEND) -static void FDECL(hack_escape, (BOOLEAN_P,const char *)); +static void FDECL(hack_escape, (BOOLEAN_P, const char *)); static void FDECL(hack_resume, (BOOLEAN_P)); #endif @@ -47,116 +47,121 @@ static int veryold(fd) int fd; { - register int i; - time_t date; - struct stat buf; + register int i; + time_t date; + struct stat buf; - if(fstat(fd, &buf)) return(0); /* cannot get status */ + if (fstat(fd, &buf)) + return (0); /* cannot get status */ #ifndef INSURANCE - if(buf.st_size != sizeof(int)) return(0); /* not an xlock file */ + if (buf.st_size != sizeof(int)) + return (0); /* not an xlock file */ #endif - (void) time(&date); - if(date - buf.st_mtime < 3L*24L*60L*60L) { /* recent */ - int lockedpid; /* should be the same size as hackpid */ - unsigned long status, dummy, code = JPI$_PID; + (void) time(&date); + if (date - buf.st_mtime < 3L * 24L * 60L * 60L) { /* recent */ + int lockedpid; /* should be the same size as hackpid */ + unsigned long status, dummy, code = JPI$_PID; - if (read(fd, (genericptr_t)&lockedpid, sizeof(lockedpid)) != - sizeof(lockedpid)) /* strange ... */ - return 0; - status = lib$getjpi(&code, &lockedpid, 0, &dummy); - if (vms_ok(status) || status != SS$_NONEXPR) - return 0; - } - (void) close(fd); + if (read(fd, (genericptr_t) &lockedpid, sizeof(lockedpid)) + != sizeof(lockedpid)) /* strange ... */ + return 0; + status = lib$getjpi(&code, &lockedpid, 0, &dummy); + if (vms_ok(status) || status != SS$_NONEXPR) + return 0; + } + (void) close(fd); - /* cannot use maxledgerno() here, because we need to find a lock name - * before starting everything (including the dungeon initialization - * that sets astral_level, needed for maxledgerno()) up - */ - for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) { - /* try to remove all */ - set_levelfile_name(lock, i); - (void) delete(lock); - } - set_levelfile_name(lock, 0); - if(delete(lock)) return(0); /* cannot remove it */ - return(1); /* success! */ + /* cannot use maxledgerno() here, because we need to find a lock name + * before starting everything (including the dungeon initialization + * that sets astral_level, needed for maxledgerno()) up + */ + for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { + /* try to remove all */ + set_levelfile_name(lock, i); + (void) delete (lock); + } + set_levelfile_name(lock, 0); + if (delete (lock)) + return (0); /* cannot remove it */ + return (1); /* success! */ } void getlock() { - register int i = 0, fd; + register int i = 0, fd; - /* idea from rpick%ucqais@uccba.uc.edu - * prevent automated rerolling of characters - * test input (fd0) so that tee'ing output to get a screen dump still - * works - * also incidentally prevents development of any hack-o-matic programs - */ - if (isatty(0) <= 0) - error("You must play from a terminal."); + /* idea from rpick%ucqais@uccba.uc.edu + * prevent automated rerolling of characters + * test input (fd0) so that tee'ing output to get a screen dump still + * works + * also incidentally prevents development of any hack-o-matic programs + */ + if (isatty(0) <= 0) + error("You must play from a terminal."); - /* we ignore QUIT and INT at this point */ - if (!lock_file(HLOCK, LOCKPREFIX, 10)) { - wait_synch(); - error("Quitting."); - } + /* we ignore QUIT and INT at this point */ + if (!lock_file(HLOCK, LOCKPREFIX, 10)) { + wait_synch(); + error("Quitting."); + } - /* default value of lock[] is "1lock" where '1' gets changed to - 'a','b',&c below; override the default and use - if we aren't restricting the number of simultaneous games */ - if (!locknum) - Sprintf(lock, "_%u%s", (unsigned)getuid(), plname); + /* default value of lock[] is "1lock" where '1' gets changed to + 'a','b',&c below; override the default and use + if we aren't restricting the number of simultaneous games */ + if (!locknum) + Sprintf(lock, "_%u%s", (unsigned) getuid(), plname); - regularize(lock); - set_levelfile_name(lock, 0); - if(locknum > 25) locknum = 25; + regularize(lock); + set_levelfile_name(lock, 0); + if (locknum > 25) + locknum = 25; - do { - if(locknum) lock[0] = 'a' + i++; + do { + if (locknum) + lock[0] = 'a' + i++; - if((fd = open(lock, 0, 0)) == -1) { - if(errno == ENOENT) goto gotlock; /* no such file */ - perror(lock); - unlock_file(HLOCK); - error("Cannot open %s", lock); - } + if ((fd = open(lock, 0, 0)) == -1) { + if (errno == ENOENT) + goto gotlock; /* no such file */ + perror(lock); + unlock_file(HLOCK); + error("Cannot open %s", lock); + } - if(veryold(fd)) /* if true, this closes fd and unlinks lock */ - goto gotlock; - (void) close(fd); - } while(i < locknum); + if (veryold(fd)) /* if true, this closes fd and unlinks lock */ + goto gotlock; + (void) close(fd); + } while (i < locknum); - unlock_file(HLOCK); - error(locknum ? "Too many hacks running now." - : "There is a game in progress under your name."); + unlock_file(HLOCK); + error(locknum ? "Too many hacks running now." + : "There is a game in progress under your name."); gotlock: - fd = creat(lock, FCMASK); - unlock_file(HLOCK); - if(fd == -1) { - error("cannot creat lock file."); - } else { - if(write(fd, (char *) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ - error("cannot write lock"); - } - if(close(fd) == -1) { - error("cannot close lock"); - } - } -} + fd = creat(lock, FCMASK); + unlock_file(HLOCK); + if (fd == -1) { + error("cannot creat lock file."); + } else { + if (write(fd, (char *) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { + error("cannot write lock"); + } + if (close(fd) == -1) { + error("cannot close lock"); + } + } +} -void -regularize(s) /* normalize file name */ +void regularize(s) /* normalize file name */ register char *s; { - register char *lp; + register char *lp; - for (lp = s; *lp; lp++) /* note: '-' becomes '_' */ - if (!(isalpha(*lp) || isdigit(*lp) || *lp == '$')) - *lp = '_'; + for (lp = s; *lp; lp++) /* note: '-' becomes '_' */ + if (!(isalpha(*lp) || isdigit(*lp) || *lp == '$')) + *lp = '_'; } #undef getuid @@ -177,9 +182,10 @@ int fd; int rfm; struct stat buf; - if (fstat(fd, &buf)) return FALSE; /* cannot get status? */ + if (fstat(fd, &buf)) + return FALSE; /* cannot get status? */ -#ifdef stat_alignment_fix /* gcc-vms alignment kludge */ +#ifdef stat_alignment_fix /* gcc-vms alignment kludge */ rfm = stat_alignment_fix(&buf)->st_fab_rfm; #else rfm = buf.st_fab_rfm; @@ -189,13 +195,13 @@ int fd; /*------*/ #ifndef LNM$_STRING -#include /* logical name definitions */ +#include /* logical name definitions */ #endif -#define ENVSIZ LNM$C_NAMLENGTH /*255*/ +#define ENVSIZ LNM$C_NAMLENGTH /*255*/ -#define ENV_USR 0 /* user-mode */ -#define ENV_SUP 1 /* supervisor-mode */ -#define ENV_JOB 2 /* job-wide entry */ +#define ENV_USR 0 /* user-mode */ +#define ENV_SUP 1 /* supervisor-mode */ +#define ENV_JOB 2 /* job-wide entry */ /* vms_define() - assign a value to a logical name */ int @@ -204,36 +210,43 @@ const char *name; const char *value; int flag; { - struct dsc { unsigned short len, mbz; const char *adr; }; /* descriptor */ - struct itm3 { short buflen, itmcode; const char *bufadr; short *retlen; }; - static struct itm3 itm_lst[] = { {0,LNM$_STRING,0,0}, {0,0} }; + struct dsc { + unsigned short len, mbz; + const char *adr; + }; /* descriptor */ + struct itm3 { + short buflen, itmcode; + const char *bufadr; + short *retlen; + }; + static struct itm3 itm_lst[] = { { 0, LNM$_STRING, 0, 0 }, { 0, 0 } }; struct dsc nam_dsc, val_dsc, tbl_dsc; unsigned long result, sys$crelnm(), lib$set_logical(); /* set up string descriptors */ nam_dsc.mbz = val_dsc.mbz = tbl_dsc.mbz = 0; - nam_dsc.len = strlen( nam_dsc.adr = name ); - val_dsc.len = strlen( val_dsc.adr = value ); - tbl_dsc.len = strlen( tbl_dsc.adr = "LNM$PROCESS" ); + nam_dsc.len = strlen(nam_dsc.adr = name); + val_dsc.len = strlen(val_dsc.adr = value); + tbl_dsc.len = strlen(tbl_dsc.adr = "LNM$PROCESS"); switch (flag) { - case ENV_JOB: /* job logical name */ - tbl_dsc.len = strlen( tbl_dsc.adr = "LNM$JOB" ); - /*FALLTHRU*/ - case ENV_SUP: /* supervisor-mode process logical name */ - result = lib$set_logical(&nam_dsc, &val_dsc, &tbl_dsc); - break; - case ENV_USR: /* user-mode process logical name */ - itm_lst[0].buflen = val_dsc.len; - itm_lst[0].bufadr = val_dsc.adr; - result = sys$crelnm(0, &tbl_dsc, &nam_dsc, 0, itm_lst); - break; - default: /*[ bad input ]*/ - result = 0; - break; + case ENV_JOB: /* job logical name */ + tbl_dsc.len = strlen(tbl_dsc.adr = "LNM$JOB"); + /*FALLTHRU*/ + case ENV_SUP: /* supervisor-mode process logical name */ + result = lib$set_logical(&nam_dsc, &val_dsc, &tbl_dsc); + break; + case ENV_USR: /* user-mode process logical name */ + itm_lst[0].buflen = val_dsc.len; + itm_lst[0].bufadr = val_dsc.adr; + result = sys$crelnm(0, &tbl_dsc, &nam_dsc, 0, itm_lst); + break; + default: /*[ bad input ]*/ + result = 0; + break; } - result &= 1; /* odd => success (== 1), even => failure (== 0) */ - return !result; /* 0 == success, 1 == failure */ + result &= 1; /* odd => success (== 1), even => failure (== 0) */ + return !result; /* 0 == success, 1 == failure */ } /* vms_putenv() - create or modify an environment value */ @@ -241,15 +254,16 @@ int vms_putenv(string) const char *string; { - char name[ENVSIZ+1], value[ENVSIZ+1], *p; /* [255+1] */ + char name[ENVSIZ + 1], value[ENVSIZ + 1], *p; /* [255+1] */ p = strchr(string, '='); - if (p > string && p < string + sizeof name && strlen(p+1) < sizeof value) { - (void)strncpy(name, string, p - string), name[p - string] = '\0'; - (void)strcpy(value, p+1); - return vms_define(name, value, ENV_USR); + if (p > string && p < string + sizeof name + && strlen(p + 1) < sizeof value) { + (void) strncpy(name, string, p - string), name[p - string] = '\0'; + (void) strcpy(value, p + 1); + return vms_define(name, value, ENV_USR); } else - return 1; /* failure */ + return 1; /* failure */ } /* @@ -262,33 +276,37 @@ const char *string; Called by verify_termcap() for convenience. */ -static -char *verify_term() +static char * +verify_term() { - char *term = getenv("NETHACK_TERM"); - if (!term) term = getenv("HACK_TERM"); - if (!term) term = getenv("EMACS_TERM"); - if (!term) term = getenv("TERM"); - if (!term || !*term - || !strcmpi(term, "undefined") || !strcmpi(term, "unknown")) { - static char smgdevtyp[31+1]; /* size is somewhat arbitrary */ - static char dev_tty[] = "TT:"; - static $DESCRIPTOR(smgdsc, smgdevtyp); - static $DESCRIPTOR(tt, dev_tty); - unsigned short dvicode = DVI$_DEVTYPE; - unsigned long devtype = 0L, termtab = 0L; + char *term = getenv("NETHACK_TERM"); + if (!term) + term = getenv("HACK_TERM"); + if (!term) + term = getenv("EMACS_TERM"); + if (!term) + term = getenv("TERM"); + if (!term || !*term || !strcmpi(term, "undefined") + || !strcmpi(term, "unknown")) { + static char smgdevtyp[31 + 1]; /* size is somewhat arbitrary */ + static char dev_tty[] = "TT:"; + static $DESCRIPTOR(smgdsc, smgdevtyp); + static $DESCRIPTOR(tt, dev_tty); + unsigned short dvicode = DVI$_DEVTYPE; + unsigned long devtype = 0L, termtab = 0L; - (void)lib$getdvi(&dvicode, (unsigned short *)0, &tt, &devtype, - (genericptr_t)0, (unsigned short *)0); + (void) lib$getdvi(&dvicode, (unsigned short *) 0, &tt, &devtype, + (genericptr_t) 0, (unsigned short *) 0); - if (devtype && - vms_ok(smg$init_term_table_by_type(&devtype, &termtab, &smgdsc))) { - register char *p = &smgdevtyp[smgdsc.dsc$w_length]; - /* strip trailing blanks */ - while (p > smgdevtyp && *--p == ' ') *p = '\0'; - /* (void)smg$del_term_table(); */ - term = smgdevtyp; - } + if (devtype && vms_ok(smg$init_term_table_by_type(&devtype, &termtab, + &smgdsc))) { + register char *p = &smgdevtyp[smgdsc.dsc$w_length]; + /* strip trailing blanks */ + while (p > smgdevtyp && *--p == ' ') + *p = '\0'; + /* (void)smg$del_term_table(); */ + term = smgdevtyp; + } } return term; } @@ -300,33 +318,38 @@ char *verify_term() */ #define GNU_DEFAULT_TERMCAP "emacs_library:[etc]termcap.dat" #define NETHACK_DEF_TERMCAP "nethackdir:termcap" -#define HACK_DEF_TERMCAP "hackdir:termcap" +#define HACK_DEF_TERMCAP "hackdir:termcap" -char * -verify_termcap() /* called from startup(src/termcap.c) */ +char *verify_termcap() /* called from startup(src/termcap.c) */ { struct stat dummy; const char *tc = getenv("TERMCAP"); - if (tc) return verify_term(); /* no termcap fixups needed */ - if (!tc && !stat(NETHACK_DEF_TERMCAP, &dummy)) tc = NETHACK_DEF_TERMCAP; - if (!tc && !stat(HACK_DEF_TERMCAP, &dummy)) tc = HACK_DEF_TERMCAP; - if (!tc && !stat(GNU_DEFAULT_TERMCAP, &dummy)) tc = GNU_DEFAULT_TERMCAP; - if (!tc && !stat("[]termcap", &dummy)) tc = "[]termcap"; /* current dir */ - if (!tc && !stat("$TERMCAP", &dummy)) tc = "$TERMCAP"; /* alt environ */ + if (tc) + return verify_term(); /* no termcap fixups needed */ + if (!tc && !stat(NETHACK_DEF_TERMCAP, &dummy)) + tc = NETHACK_DEF_TERMCAP; + if (!tc && !stat(HACK_DEF_TERMCAP, &dummy)) + tc = HACK_DEF_TERMCAP; + if (!tc && !stat(GNU_DEFAULT_TERMCAP, &dummy)) + tc = GNU_DEFAULT_TERMCAP; + if (!tc && !stat("[]termcap", &dummy)) + tc = "[]termcap"; /* current dir */ + if (!tc && !stat("$TERMCAP", &dummy)) + tc = "$TERMCAP"; /* alt environ */ if (tc) { - /* putenv(strcat(strcpy(buffer,"TERMCAP="),tc)); */ - vms_define("TERMCAP", tc, ENV_USR); + /* putenv(strcat(strcpy(buffer,"TERMCAP="),tc)); */ + vms_define("TERMCAP", tc, ENV_USR); } else { - /* perhaps someday we'll construct a termcap entry string */ + /* perhaps someday we'll construct a termcap entry string */ } return verify_term(); } /*------*/ #ifdef SHELL -# ifndef CLI$M_NOWAIT -# define CLI$M_NOWAIT 1 -# endif +#ifndef CLI$M_NOWAIT +#define CLI$M_NOWAIT 1 +#endif #endif #if defined(CHDIR) || defined(SHELL) || defined(SECURE) @@ -335,20 +358,20 @@ static unsigned long oprv[2]; void privoff() { - unsigned long pid = 0, prv[2] = { ~0, ~0 }; - unsigned short code = JPI$_PROCPRIV; + unsigned long pid = 0, prv[2] = { ~0, ~0 }; + unsigned short code = JPI$_PROCPRIV; - (void) sys$setprv(0, prv, 0, oprv); - (void) lib$getjpi(&code, &pid, (genericptr_t)0, prv); - (void) sys$setprv(1, prv, 0, (unsigned long *)0); + (void) sys$setprv(0, prv, 0, oprv); + (void) lib$getjpi(&code, &pid, (genericptr_t) 0, prv); + (void) sys$setprv(1, prv, 0, (unsigned long *) 0); } void privon() { - (void) sys$setprv(1, oprv, 0, (unsigned long *)0); + (void) sys$setprv(1, oprv, 0, (unsigned long *) 0); } -#endif /* CHDIR || SHELL || SECURE */ +#endif /* CHDIR || SHELL || SECURE */ #if defined(SHELL) || defined(SUSPEND) static void @@ -356,98 +379,108 @@ hack_escape(screen_manip, msg_str) boolean screen_manip; const char *msg_str; { - if (screen_manip) - suspend_nhwindows(msg_str); /* clear screen, reset terminal, &c */ - (void) signal(SIGQUIT,SIG_IGN); /* ignore ^Y */ - (void) signal(SIGINT,SIG_DFL); /* don't trap ^C (implct cnvrs to ^Y) */ + if (screen_manip) + suspend_nhwindows(msg_str); /* clear screen, reset terminal, &c */ + (void) signal(SIGQUIT, SIG_IGN); /* ignore ^Y */ + (void) signal(SIGINT, SIG_DFL); /* don't trap ^C (implct cnvrs to ^Y) */ } static void hack_resume(screen_manip) boolean screen_manip; { - (void) signal(SIGINT, (SIG_RET_TYPE) done1); - if (wizard) (void) signal(SIGQUIT,SIG_DFL); - if (screen_manip) - resume_nhwindows(); /* setup terminal modes, redraw screen, &c */ + (void) signal(SIGINT, (SIG_RET_TYPE) done1); + if (wizard) + (void) signal(SIGQUIT, SIG_DFL); + if (screen_manip) + resume_nhwindows(); /* setup terminal modes, redraw screen, &c */ } -#endif /* SHELL || SUSPEND */ +#endif /* SHELL || SUSPEND */ #ifdef SHELL -unsigned long dosh_pid = 0, /* this should cover any interactive escape */ - mail_pid = 0; /* this only covers the last mail or phone; */ -/*(mail & phone commands aren't expected to leave any process hanging around)*/ +unsigned long dosh_pid = 0, /* this should cover any interactive escape */ + mail_pid = 0; /* this only covers the last mail or phone; */ +/*(mail & phone commands aren't expected to leave any process hanging + * around)*/ -int dosh() +int +dosh() { - return vms_doshell("", TRUE); /* call for interactive child process */ + return vms_doshell("", TRUE); /* call for interactive child process */ } /* vms_doshell -- called by dosh() and readmail() */ -/* If execstring is not a null string, then it will be executed in a spawned */ -/* subprocess, which will then return. It is for handling mail or phone */ -/* interactive commands, which are only available if both MAIL and SHELL are */ -/* #defined, but we don't bother making the support code conditionalized on */ -/* MAIL here, just on SHELL being enabled. */ +/* If execstring is not a null string, then it will be executed in a spawned + */ +/* subprocess, which will then return. It is for handling mail or phone */ +/* interactive commands, which are only available if both MAIL and SHELL are + */ +/* #defined, but we don't bother making the support code conditionalized on */ +/* MAIL here, just on SHELL being enabled. */ -/* Normally, all output from this interaction will be 'piped' to the user's */ -/* screen (SYS$OUTPUT). However, if 'screenoutput' is set to FALSE, output */ -/* will be piped into oblivion. Used for silent phone call rejection. */ +/* Normally, all output from this interaction will be 'piped' to the user's */ +/* screen (SYS$OUTPUT). However, if 'screenoutput' is set to FALSE, output */ +/* will be piped into oblivion. Used for silent phone call rejection. */ int vms_doshell(execstring, screenoutput) const char *execstring; boolean screenoutput; { - unsigned long status, new_pid, spawnflags = 0; - struct dsc$descriptor_s comstring, *command, *inoutfile = 0; - static char dev_null[] = "_NLA0:"; - static $DESCRIPTOR(nulldevice, dev_null); + unsigned long status, new_pid, spawnflags = 0; + struct dsc$descriptor_s comstring, *command, *inoutfile = 0; + static char dev_null[] = "_NLA0:"; + static $DESCRIPTOR(nulldevice, dev_null); - /* Is this an interactive shell spawn, or do we have a command to do? */ - if (execstring && *execstring) { - comstring.dsc$w_length = strlen(execstring); - comstring.dsc$b_dtype = DSC$K_DTYPE_T; - comstring.dsc$b_class = DSC$K_CLASS_S; - comstring.dsc$a_pointer = (char *)execstring; - command = &comstring; - } else - command = 0; + /* Is this an interactive shell spawn, or do we have a command to do? */ + if (execstring && *execstring) { + comstring.dsc$w_length = strlen(execstring); + comstring.dsc$b_dtype = DSC$K_DTYPE_T; + comstring.dsc$b_class = DSC$K_CLASS_S; + comstring.dsc$a_pointer = (char *) execstring; + command = &comstring; + } else + command = 0; - /* use asynch subprocess and suppress output iff one-shot command */ - if (!screenoutput) { - spawnflags = CLI$M_NOWAIT; - inoutfile = &nulldevice; - } + /* use asynch subprocess and suppress output iff one-shot command */ + if (!screenoutput) { + spawnflags = CLI$M_NOWAIT; + inoutfile = &nulldevice; + } - hack_escape(screenoutput, command ? (const char *) 0 : - " \"Escaping\" into a subprocess; LOGOUT to reconnect and resume play. "); + hack_escape(screenoutput, + command ? (const char *) 0 : " \"Escaping\" into a " + "subprocess; LOGOUT to " + "reconnect and resume play. "); - if (command || !dosh_pid || !vms_ok(status = lib$attach(&dosh_pid))) { -# ifdef CHDIR - (void) chdir(getenv("PATH")); -# endif - privoff(); - new_pid = 0; - status = lib$spawn(command, inoutfile, inoutfile, &spawnflags, - (struct dsc$descriptor_s *) 0, &new_pid); - if (!command) dosh_pid = new_pid; else mail_pid = new_pid; - privon(); -# ifdef CHDIR - chdirx((char *) 0, 0); -# endif - } + if (command || !dosh_pid || !vms_ok(status = lib$attach(&dosh_pid))) { +#ifdef CHDIR + (void) chdir(getenv("PATH")); +#endif + privoff(); + new_pid = 0; + status = lib$spawn(command, inoutfile, inoutfile, &spawnflags, + (struct dsc$descriptor_s *) 0, &new_pid); + if (!command) + dosh_pid = new_pid; + else + mail_pid = new_pid; + privon(); +#ifdef CHDIR + chdirx((char *) 0, 0); +#endif + } - hack_resume(screenoutput); + hack_resume(screenoutput); - if (!vms_ok(status)) { - pline(" Spawn failed. (%%x%08lX) ", status); - mark_synch(); - } - return 0; + if (!vms_ok(status)) { + pline(" Spawn failed. (%%x%08lX) ", status); + mark_synch(); + } + return 0; } -#endif /* SHELL */ +#endif /* SHELL */ #ifdef SUSPEND /* dosuspend() -- if we're a subprocess, attach to our parent; @@ -456,39 +489,39 @@ boolean screenoutput; int dosuspend() { - static long owner_pid = -1; - unsigned long status; + static long owner_pid = -1; + unsigned long status; - if (owner_pid == -1) /* need to check for parent */ - owner_pid = getppid(); - if (owner_pid == 0) { - pline( - " No parent process. Use '!' to Spawn, 'S' to Save, or 'Q' to Quit. "); - mark_synch(); - return 0; - } + if (owner_pid == -1) /* need to check for parent */ + owner_pid = getppid(); + if (owner_pid == 0) { + pline(" No parent process. Use '!' to Spawn, 'S' to Save, or 'Q' " + "to Quit. "); + mark_synch(); + return 0; + } - /* restore normal tty environment & clear screen */ - hack_escape(1, - " Attaching to parent process; use the ATTACH command to resume play. "); + /* restore normal tty environment & clear screen */ + hack_escape(1, " Attaching to parent process; use the ATTACH command to " + "resume play. "); - status = lib$attach(&owner_pid); /* connect to parent */ + status = lib$attach(&owner_pid); /* connect to parent */ - hack_resume(1); /* resume game tty environment & refresh screen */ + hack_resume(1); /* resume game tty environment & refresh screen */ - if (!vms_ok(status)) { - pline(" Unable to attach to parent. (%%x%08lX) ", status); - mark_synch(); - } - return 0; + if (!vms_ok(status)) { + pline(" Unable to attach to parent. (%%x%08lX) ", status); + mark_synch(); + } + return 0; } -#endif /* SUSPEND */ +#endif /* SUSPEND */ #ifdef SELECTSAVED /* this would fit better in vmsfiles.c except that that gets linked with the utility programs and we don't want this code there */ -static void FDECL(savefile, (const char *,int,int *,char ***)); +static void FDECL(savefile, (const char *, int, int *, char ***)); static void savefile(name, indx, asize, array) @@ -501,21 +534,26 @@ char ***array; /* (asize - 1) guarantees that [indx + 1] will exist and be set to null */ while (indx >= *asize - 1) { - oldsize = *asize; - *asize += 5; - newarray = (char **)alloc(*asize * sizeof (char *)); - /* poor man's realloc() */ - for (i = 0; i < *asize; ++i) - newarray[i] = (i < oldsize) ? (*array)[i] : 0; - if (*array) free((genericptr_t)*array); - *array = newarray; + oldsize = *asize; + *asize += 5; + newarray = (char **) alloc(*asize * sizeof(char *)); + /* poor man's realloc() */ + for (i = 0; i < *asize; ++i) + newarray[i] = (i < oldsize) ? (*array)[i] : 0; + if (*array) + free((genericptr_t) *array); + *array = newarray; } - (*array)[indx] = strcpy((char *)alloc(strlen(name) + 1), name); + (*array)[indx] = strcpy((char *) alloc(strlen(name) + 1), name); } -struct dsc { unsigned short len, mbz; char *adr; }; /* descriptor */ -typedef unsigned long vmscond; /* vms condition value */ -vmscond FDECL(lib$find_file, (const struct dsc *,struct dsc *,genericptr *)); +struct dsc { + unsigned short len, mbz; + char *adr; +}; /* descriptor */ +typedef unsigned long vmscond; /* vms condition value */ +vmscond FDECL(lib$find_file, + (const struct dsc *, struct dsc *, genericptr *)); vmscond FDECL(lib$find_file_end, (void **)); /* collect a list of character names from all save files for this player */ @@ -527,67 +565,74 @@ char ***outarray; struct dsc in, out; unsigned short l; int count, asize; - char *charname, wildcard[255+1], filename[255+1]; + char *charname, wildcard[255 + 1], filename[255 + 1]; genericptr_t context = 0; - Strcpy(wildcard, savetemplate); /* plname_from_file overwrites SAVEF */ - in.mbz = 0; /* class and type; leave them unspecified */ - in.len = (unsigned short)strlen(wildcard); + Strcpy(wildcard, savetemplate); /* plname_from_file overwrites SAVEF */ + in.mbz = 0; /* class and type; leave them unspecified */ + in.len = (unsigned short) strlen(wildcard); in.adr = wildcard; out.mbz = 0; - out.len = (unsigned short)(sizeof filename - 1); + out.len = (unsigned short) (sizeof filename - 1); out.adr = filename; *outarray = 0; count = asize = 0; /* note: only works as intended if savetemplate is a wildcard filespec */ while (lib$find_file(&in, &out, &context) & 1) { - /* strip trailing blanks */ - for (l = out.len; l > 0; --l) if (filename[l - 1] != ' ') break; - filename[l] = '\0'; - if ((charname = plname_from_file(filename)) != 0) - savefile(charname, count++, &asize, outarray); + /* strip trailing blanks */ + for (l = out.len; l > 0; --l) + if (filename[l - 1] != ' ') + break; + filename[l] = '\0'; + if ((charname = plname_from_file(filename)) != 0) + savefile(charname, count++, &asize, outarray); } - (void)lib$find_file_end(&context); + (void) lib$find_file_end(&context); return count; } -#endif /* SELECTSAVED */ +#endif /* SELECTSAVED */ #ifdef PANICTRACE -/* nethack has detected an internal error; try to give a trace of call stack */ +/* nethack has detected an internal error; try to give a trace of call stack + */ void vms_traceback(how) -int how; /* 1: exit after traceback; 2: stay in debugger */ +int how; /* 1: exit after traceback; 2: stay in debugger */ { /* assumes that a static initializer applies to the first union field and that no padding will be placed between len and str */ union dbgcmd { - struct ascic { - unsigned char len; /* 8-bit length prefix */ - char str[79]; /* could be up to 255, but we don't need that much */ - } cmd_fields; - char cmd[1+79]; + struct ascic { + unsigned char len; /* 8-bit length prefix */ + char + str[79]; /* could be up to 255, but we don't need that much */ + } cmd_fields; + char cmd[1 + 79]; }; -#define DBGCMD(arg) { (unsigned char)(sizeof arg - sizeof ""), arg } +#define DBGCMD(arg) \ + { \ + (unsigned char)(sizeof arg - sizeof ""), arg \ + } static union dbgcmd dbg[3] = { - /* prologue for less verbose feedback (when combined with - $ define/User_mode dbg$output _NL: ) */ - DBGCMD("set Log SYS$OUTPUT: ; set Output Log,noTerminal,noVerify"), - /* enable modules with calls present on stack, then show those calls; - limit traceback to 18 stack frames to avoid scrolling off screen - (could check termcap LI and maybe give more, but we're operating - in a last-gasp environment so apply the KISS principle...) */ - DBGCMD("set Module/Calls ; show Calls 18"), - /* epilogue; "exit" ends the sequence it's part of, but it doesn't - seem able to cause program termination end when used separately; - instead of relying on it, we'll redirect debugger input to come - from the null device so that it'll get an end-of-input condition - when it tries to get a command from the user */ - DBGCMD("exit"), + /* prologue for less verbose feedback (when combined with + $ define/User_mode dbg$output _NL: ) */ + DBGCMD("set Log SYS$OUTPUT: ; set Output Log,noTerminal,noVerify"), + /* enable modules with calls present on stack, then show those calls; + limit traceback to 18 stack frames to avoid scrolling off screen + (could check termcap LI and maybe give more, but we're operating + in a last-gasp environment so apply the KISS principle...) */ + DBGCMD("set Module/Calls ; show Calls 18"), + /* epilogue; "exit" ends the sequence it's part of, but it doesn't + seem able to cause program termination end when used separately; + instead of relying on it, we'll redirect debugger input to come + from the null device so that it'll get an end-of-input condition + when it tries to get a command from the user */ + DBGCMD("exit"), }; #undef DBGCMD - + /* * If we've been linked /noTraceback then we can't provide any * trace of the call stack. Linking that way is required if @@ -595,43 +640,43 @@ int how; /* 1: exit after traceback; 2: stay in debugger */ * SECURE configuration usually won't have any trace feedback. */ if (!debuggable) { - ; /* debugger not available to catch lib$signal(SS$_DEBUG) */ + ; /* debugger not available to catch lib$signal(SS$_DEBUG) */ } else if (how == 2) { - /* omit prologue and epilogue (dbg[0] and dbg[2]) */ - (void)lib$signal(SS$_DEBUG, 1, dbg[1].cmd); + /* omit prologue and epilogue (dbg[0] and dbg[2]) */ + (void) lib$signal(SS$_DEBUG, 1, dbg[1].cmd); } else if (how == 1) { - /* - * Suppress most of debugger's initial feedback to avoid scaring - * users (and scrolling panic message off the screen). Also control - * debugging environment to try to prevent unexpected complications. - */ - /* start up with output going to /dev/null instead of stdout; - once started, output is sent to log file that's actually stdout */ - (void)vms_define("DBG$OUTPUT", "_NL:", 0); - /* take input from null device so debugger will see end-on-input - and quit if/when it tries to get a command from the user */ - (void)vms_define("DBG$INPUT", "_NL:", 0); - /* bypass any debugger initialization file the user might have */ - (void)vms_define("DBG$INIT", "_NL:", 0); - /* force tty interface by suppressing DECwindows/Motif interface */ - (void)vms_define("DBG$DECW$DISPLAY", " ", 0); - /* raise an exception for the debugger to catch */ - (void)lib$signal(SS$_DEBUG, 3, dbg[0].cmd, dbg[1].cmd, dbg[2].cmd); + /* + * Suppress most of debugger's initial feedback to avoid scaring + * users (and scrolling panic message off the screen). Also control + * debugging environment to try to prevent unexpected complications. + */ + /* start up with output going to /dev/null instead of stdout; + once started, output is sent to log file that's actually stdout */ + (void) vms_define("DBG$OUTPUT", "_NL:", 0); + /* take input from null device so debugger will see end-on-input + and quit if/when it tries to get a command from the user */ + (void) vms_define("DBG$INPUT", "_NL:", 0); + /* bypass any debugger initialization file the user might have */ + (void) vms_define("DBG$INIT", "_NL:", 0); + /* force tty interface by suppressing DECwindows/Motif interface */ + (void) vms_define("DBG$DECW$DISPLAY", " ", 0); + /* raise an exception for the debugger to catch */ + (void) lib$signal(SS$_DEBUG, 3, dbg[0].cmd, dbg[1].cmd, dbg[2].cmd); } - vms_exit(2); /* don't return to caller (2==arbitrary non-zero) */ + vms_exit(2); /* don't return to caller (2==arbitrary non-zero) */ /* NOT REACHED */ } -#endif /* PANICTRACE */ +#endif /* PANICTRACE */ - /* - * Play Hunt the Wumpus to see whether the debugger lurks nearby. - * It all takes place before nethack even starts, and sets up - * `debuggable' to control possible use of lib$signal(SS$_DEBUG). - */ -typedef unsigned FDECL((*condition_handler), (unsigned *,unsigned *)); +/* + * Play Hunt the Wumpus to see whether the debugger lurks nearby. + * It all takes place before nethack even starts, and sets up + * `debuggable' to control possible use of lib$signal(SS$_DEBUG). + */ +typedef unsigned FDECL((*condition_handler), (unsigned *, unsigned *)); extern condition_handler FDECL(lib$establish, (condition_handler)); -extern unsigned FDECL(lib$sig_to_ret, (unsigned *,unsigned *)); +extern unsigned FDECL(lib$sig_to_ret, (unsigned *, unsigned *)); /* SYS$IMGSTA() is not documented: if called at image startup, it controls access to the debugger; fortunately, the linker knows now to find it @@ -647,59 +692,59 @@ extern unsigned FDECL(sys$imgsta, ()); * without ugly unions. Contents derived from Bliss32 definitions * in lib.req and/or Macro32 definitions in lib.mlb. */ -struct ihd { /* (vax) image header, $IHDDEF */ +struct ihd { /* (vax) image header, $IHDDEF */ unsigned short size, activoff; - unsigned char otherstuff[512-4]; + unsigned char otherstuff[512 - 4]; }; -struct eihd { /* extended image header, $EIHDDEF */ +struct eihd { /* extended image header, $EIHDDEF */ unsigned long majorid, minorid, size, isdoff, activoff; - unsigned char otherstuff[512-20]; + unsigned char otherstuff[512 - 20]; }; -struct iha { /* (vax) image header activation block, $IHADEF */ +struct iha { /* (vax) image header activation block, $IHADEF */ unsigned long trnadr1, trnadr2, trnadr3; unsigned long fill_, inishr; }; -struct eiha { /* extended image header activation block, $EIHADEF */ +struct eiha { /* extended image header activation block, $EIHADEF */ unsigned long size, spare; unsigned long trnadr1[2], trnadr2[2], trnadr3[2], trnadr4[2], inishr[2]; }; - /* - * We're going to use lib$initialize, not because we need or - * want to be called before main(), but because one of the - * arguments passed to a lib$initialize callback is a pointer - * to the image header (somewhat complex data structure which - * includes the memory location(s) of where to start executing) - * of the program being initialized. It comes in two flavors, - * one used by VAX and the other by Alpha and IA64. - * - * An image can have up to three transfer addresses; one of them - * decides whether to run under debugger control (RUN/Debug, or - * LINK/Debug + plain RUN), another handles lib$initialize calls - * if that's used, and the last is to start the program itself - * (a jacket built around main() for code compiled with DEC C). - * They aren't always all present; some might be zero/null. - * A shareable image (pre-linked library) usually won't have any, - * but can have a separate initializer (not of interest here). - * - * The transfer targets don't have fixed slots but do occur in a - * particular order: - * link link lib$initialize lib$initialize - * sharable /noTrace /Trace + /noTrace + /Traceback - * 1: (none) main debugger init-handler debugger - * 2: main main init-handler - * 3: main - * - * We check whether the first transfer address is SYS$IMGSTA(). - * If it is, the debugger should be available to catch SS$_DEBUG - * exception even when we don't start up under debugger control. - * One extra complication: if we *do* start up under debugger - * control, the first address in the in-memory copy of the image - * header will be changed from sys$imgsta() to a value in system - * space. [I don't know how to reference that one symbolically, - * so I'm going to treat any address in system space as meaning - * that the debugger is available. pr] - */ +/* + * We're going to use lib$initialize, not because we need or + * want to be called before main(), but because one of the + * arguments passed to a lib$initialize callback is a pointer + * to the image header (somewhat complex data structure which + * includes the memory location(s) of where to start executing) + * of the program being initialized. It comes in two flavors, + * one used by VAX and the other by Alpha and IA64. + * + * An image can have up to three transfer addresses; one of them + * decides whether to run under debugger control (RUN/Debug, or + * LINK/Debug + plain RUN), another handles lib$initialize calls + * if that's used, and the last is to start the program itself + * (a jacket built around main() for code compiled with DEC C). + * They aren't always all present; some might be zero/null. + * A shareable image (pre-linked library) usually won't have any, + * but can have a separate initializer (not of interest here). + * + * The transfer targets don't have fixed slots but do occur in a + * particular order: + * link link lib$initialize lib$initialize + * sharable /noTrace /Trace + /noTrace + /Traceback + * 1: (none) main debugger init-handler debugger + * 2: main main init-handler + * 3: main + * + * We check whether the first transfer address is SYS$IMGSTA(). + * If it is, the debugger should be available to catch SS$_DEBUG + * exception even when we don't start up under debugger control. + * One extra complication: if we *do* start up under debugger + * control, the first address in the in-memory copy of the image + * header will be changed from sys$imgsta() to a value in system + * space. [I don't know how to reference that one symbolically, + * so I'm going to treat any address in system space as meaning + * that the debugger is available. pr] + */ /* called via lib$initialize during image activation: before main() and with magic arguments; C run-time library won't be initialized yet */ @@ -709,44 +754,45 @@ vmsexeini(inirtn_unused, clirtn_unused, imghdr) const void *inirtn_unused, *clirtn_unused; const unsigned char *imghdr; { - const struct ihd *vax_hdr; + const struct ihd *vax_hdr; const struct eihd *axp_hdr; - const struct iha *vax_xfr; + const struct iha *vax_xfr; const struct eiha *axp_xfr; unsigned long trnadr1; - (void)lib$establish(lib$sig_to_ret); /* set up condition handler */ - /* - * Check the first of three transfer addresses to see whether - * it is SYS$IMGSTA(). Note that they come from a file, - * where they reside as longword or quadword integers rather - * than function pointers. (Basically just a C type issue; - * casting back and forth between integer and pointer doesn't - * change any bits for the architectures VMS runs on.) - */ + (void) lib$establish(lib$sig_to_ret); /* set up condition handler */ + /* + * Check the first of three transfer addresses to see whether + * it is SYS$IMGSTA(). Note that they come from a file, + * where they reside as longword or quadword integers rather + * than function pointers. (Basically just a C type issue; + * casting back and forth between integer and pointer doesn't + * change any bits for the architectures VMS runs on.) + */ debuggable = 0; /* start with a guess rather than bothering to figure out architecture */ - vax_hdr = (struct ihd *)imghdr; + vax_hdr = (struct ihd *) imghdr; if (vax_hdr->size >= 512) { - /* this is a VAX-specific header; addresses are longwords */ - vax_xfr = (struct iha *)(imghdr + vax_hdr->activoff); - trnadr1 = vax_xfr->trnadr1; + /* this is a VAX-specific header; addresses are longwords */ + vax_xfr = (struct iha *) (imghdr + vax_hdr->activoff); + trnadr1 = vax_xfr->trnadr1; } else { - /* the guess above was wrong; imghdr's first word is not - the size field, it's a version number component */ - axp_hdr = (struct eihd *)imghdr; - /* this is an Alpha or IA64 header; addresses are quadwords - but we ignore the upper half which will be all 0's or 0xF's - (we hope; if not, assume it still won't matter for this test) */ - axp_xfr = (struct eiha *)(imghdr + axp_hdr->activoff); - trnadr1 = axp_xfr->trnadr1[0]; + /* the guess above was wrong; imghdr's first word is not + the size field, it's a version number component */ + axp_hdr = (struct eihd *) imghdr; + /* this is an Alpha or IA64 header; addresses are quadwords + but we ignore the upper half which will be all 0's or 0xF's + (we hope; if not, assume it still won't matter for this test) */ + axp_xfr = (struct eiha *) (imghdr + axp_hdr->activoff); + trnadr1 = axp_xfr->trnadr1[0]; } - if ((unsigned (*)())trnadr1 == sys$imgsta || - /* check whether first transfer address points to system space - [we want (trnadr1 >= 0x80000000UL) but really old compilers - don't support the UL suffix, so do a signed compare instead] */ - (long)trnadr1 < 0L) debuggable = 1; - return 1; /* success (return value here doesn't actually matter) */ + if ((unsigned (*) ()) trnadr1 == sys$imgsta || + /* check whether first transfer address points to system space + [we want (trnadr1 >= 0x80000000UL) but really old compilers + don't support the UL suffix, so do a signed compare instead] */ + (long) trnadr1 < 0L) + debuggable = 1; + return 1; /* success (return value here doesn't actually matter) */ } /* @@ -790,23 +836,23 @@ const unsigned char *imghdr; * will be avoided even when its use is viable. But the program will * still work correctly.] */ -#define C_LIB$INITIALIZE /* comment out if this won't compile... */ - /* (then `debuggable' will always stay 0) */ +#define C_LIB$INITIALIZE /* comment out if this won't compile... */ +/* (then `debuggable' will always stay 0) */ #ifdef C_LIB$INITIALIZE -# ifdef __DECC -# pragma extern_model save /* push current mode */ -# pragma extern_model common_block /* set new mode */ -# endif +#ifdef __DECC +#pragma extern_model save /* push current mode */ +#pragma extern_model common_block /* set new mode */ +#endif /* values are 32-bit function addresses; pointers might be 64 so avoid them */ -extern const unsigned long lib$initialize[1]; /* size is actually variable */ -const unsigned long lib$initialize[] = { (unsigned long)(void *)vmsexeini }; -# ifdef __DECC -# pragma extern_model restore /* pop previous mode */ -# endif +extern const unsigned long lib$initialize[1]; /* size is actually variable */ +const unsigned long lib$initialize[] = { (unsigned long) (void *) vmsexeini }; +#ifdef __DECC +#pragma extern_model restore /* pop previous mode */ +#endif /* We also need to link against a linker options file containing: sys$library:starlet.olb/Include=(lib$initialize) psect_attr=lib$initialize, Con,Usr,noPic,Rel,Gbl,noShr,noExe,Rd,noWrt,Long */ -#endif /* C_LIB$INITIALIZE */ - /* End of debugger hackery. */ +#endif /* C_LIB$INITIALIZE */ +/* End of debugger hackery. */ /*vmsunix.c*/ diff --git a/sys/wince/celib.c b/sys/wince/celib.c index 1b8166a26..167716e53 100644 --- a/sys/wince/celib.c +++ b/sys/wince/celib.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 celib.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 celib.c $NHDT-Date: 1431192789 2015/05/09 17:33:09 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 celib.c $Date: 2009/10/22 02:59:30 $ $Revision: 1.6 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,77 +9,81 @@ // #include "wceconf.h" static union { - time_t t_val; - struct time_pack { - unsigned int ss:6; - unsigned int mm:6; - unsigned int dd:5; - unsigned int hh:6; - unsigned int mo:4; - unsigned int yr:10; - unsigned int wd:3; - } tm_val; + time_t t_val; + struct time_pack { + unsigned int ss : 6; + unsigned int mm : 6; + unsigned int dd : 5; + unsigned int hh : 6; + unsigned int mo : 4; + unsigned int yr : 10; + unsigned int wd : 3; + } tm_val; } _t_cnv; -#define IS_LEAP(yr) (((yr)%4==0 || (yr)%100==0) && !(yr)%400==0) -static char _day_mo_leap[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +#define IS_LEAP(yr) (((yr) % 4 == 0 || (yr) % 100 == 0) && !(yr) % 400 == 0) +static char _day_mo_leap[12] = { 31, 29, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31 }; static char _day_mo[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; -struct tm * __cdecl localtime ( const time_t *ptime ) +struct tm *__cdecl localtime(const time_t *ptime) { - static struct tm ptm; - int i; - if( !ptime ) return NULL; + static struct tm ptm; + int i; + if (!ptime) + return NULL; - _t_cnv.t_val = *ptime; + _t_cnv.t_val = *ptime; - ptm.tm_sec = _t_cnv.tm_val.ss ; /* seconds after the minute - [0,59] */ - ptm.tm_min = _t_cnv.tm_val.mm; /* minutes after the hour - [0,59] */ - ptm.tm_hour = _t_cnv.tm_val.hh; /* hours since midnight - [0,23] */ - ptm.tm_mday = _t_cnv.tm_val.dd; /* day of the month - [1,31] */ - ptm.tm_mon = _t_cnv.tm_val.mo-1; /* months since January - [0,11] */ - ptm.tm_year = _t_cnv.tm_val.yr; /* years since 1900 */ - ptm.tm_wday = _t_cnv.tm_val.wd; /* days since Sunday - [0,6] */ + ptm.tm_sec = _t_cnv.tm_val.ss; /* seconds after the minute - [0,59] */ + ptm.tm_min = _t_cnv.tm_val.mm; /* minutes after the hour - [0,59] */ + ptm.tm_hour = _t_cnv.tm_val.hh; /* hours since midnight - [0,23] */ + ptm.tm_mday = _t_cnv.tm_val.dd; /* day of the month - [1,31] */ + ptm.tm_mon = _t_cnv.tm_val.mo - 1; /* months since January - [0,11] */ + ptm.tm_year = _t_cnv.tm_val.yr; /* years since 1900 */ + ptm.tm_wday = _t_cnv.tm_val.wd; /* days since Sunday - [0,6] */ - ptm.tm_yday = _t_cnv.tm_val.dd; /* days since January 1 - [0,365] */ - for( i=0; itm_year; - _t_cnv.tm_val.mo = tb->tm_mon; - _t_cnv.tm_val.dd = tb->tm_mday; - _t_cnv.tm_val.hh = tb->tm_hour; - _t_cnv.tm_val.mm = tb->tm_min; - _t_cnv.tm_val.ss = tb->tm_sec; - _t_cnv.tm_val.wd = tb->tm_wday; + _t_cnv.tm_val.yr = tb->tm_year; + _t_cnv.tm_val.mo = tb->tm_mon; + _t_cnv.tm_val.dd = tb->tm_mday; + _t_cnv.tm_val.hh = tb->tm_hour; + _t_cnv.tm_val.mm = tb->tm_min; + _t_cnv.tm_val.ss = tb->tm_sec; + _t_cnv.tm_val.wd = tb->tm_wday; - return _t_cnv.t_val; + return _t_cnv.t_val; } /*------------------------------------------------------------------------------*/ @@ -87,274 +91,279 @@ time_t __cdecl mktime(struct tm * tb) /* Hack io.h function with stdio.h functions */ /* ASSUMPTION : int can hold FILE* */ static TCHAR _nh_cwd[MAX_PATH]; -const int MAGIC_OFFSET=5; -#define FILE_TABLE_SIZE 256 +const int MAGIC_OFFSET = 5; +#define FILE_TABLE_SIZE 256 static HANDLE _nh_file_table[FILE_TABLE_SIZE]; static int file_pointer = -1; -static HANDLE get_file_handle(int i) +static HANDLE +get_file_handle(int i) { - i -= MAGIC_OFFSET; - if( i>=0 && i=FILE_TABLE_SIZE ) return -1; - retval = (CloseHandle(_nh_file_table[f])? 0 : -1); - _nh_file_table[f] = INVALID_HANDLE_VALUE; - return retval; + i -= MAGIC_OFFSET; + if (i >= 0 && i < FILE_TABLE_SIZE) + return _nh_file_table[i]; + else + return INVALID_HANDLE_VALUE; } -int __cdecl creat(const char *fname , int mode) +static int +alloc_file_handle(HANDLE h) { - HANDLE f; - TCHAR wbuf[MAX_PATH+1]; - ZeroMemory(wbuf, sizeof(wbuf)); - NH_A2W(fname, wbuf, MAX_PATH); + int i; + if (file_pointer == -1) { + file_pointer = 0; + for (i = 0; i < FILE_TABLE_SIZE; i++) + _nh_file_table[i] = INVALID_HANDLE_VALUE; + } - f = CreateFile( - wbuf, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); + i = (file_pointer + 1) % FILE_TABLE_SIZE; + while (_nh_file_table[i] != INVALID_HANDLE_VALUE) { + if (i == file_pointer) { + MessageBox(NULL, _T("Ran out of file handles."), + _T("Fatal Error"), MB_OK); + abort(); + } + i = (i + 1) % FILE_TABLE_SIZE; + } - if( f==INVALID_HANDLE_VALUE ) return -1; - else return alloc_file_handle(f); + file_pointer = i; + _nh_file_table[file_pointer] = h; + return file_pointer + MAGIC_OFFSET; +} + +int __cdecl close(int f) +{ + int retval; + f -= MAGIC_OFFSET; + if (f < 0 || f >= FILE_TABLE_SIZE) + return -1; + retval = (CloseHandle(_nh_file_table[f]) ? 0 : -1); + _nh_file_table[f] = INVALID_HANDLE_VALUE; + return retval; +} + +int __cdecl creat(const char *fname, int mode) +{ + HANDLE f; + TCHAR wbuf[MAX_PATH + 1]; + ZeroMemory(wbuf, sizeof(wbuf)); + NH_A2W(fname, wbuf, MAX_PATH); + + f = CreateFile(wbuf, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + + if (f == INVALID_HANDLE_VALUE) + return -1; + else + return alloc_file_handle(f); } int __cdecl eof(int f) { - DWORD fpos, fsize; - HANDLE p = get_file_handle(f); + DWORD fpos, fsize; + HANDLE p = get_file_handle(f); - if( f==-1 ) return -1; + if (f == -1) + return -1; - fpos = SetFilePointer(p, 0, NULL, FILE_CURRENT); - fsize = SetFilePointer(p, 0, NULL, FILE_END); - if( fpos==0xFFFFFFFF || fsize==0xFFFFFFFF ) return -1; - if( fpos==fsize ) return 1; - else { - SetFilePointer(p, fpos, NULL, FILE_BEGIN); - return 0; - } + fpos = SetFilePointer(p, 0, NULL, FILE_CURRENT); + fsize = SetFilePointer(p, 0, NULL, FILE_END); + if (fpos == 0xFFFFFFFF || fsize == 0xFFFFFFFF) + return -1; + if (fpos == fsize) + return 1; + else { + SetFilePointer(p, fpos, NULL, FILE_BEGIN); + return 0; + } } -long __cdecl lseek( int f, long offset, int origin ) +long __cdecl lseek(int f, long offset, int origin) { - HANDLE p = get_file_handle(f); - DWORD fpos; - switch(origin) { - case SEEK_SET: - fpos = SetFilePointer(p, offset, NULL, FILE_BEGIN); - break; - case SEEK_CUR: - fpos = SetFilePointer(p, offset, NULL, FILE_CURRENT); - break; - case SEEK_END: - fpos = SetFilePointer(p, offset, NULL, FILE_END); - break; - default: - fpos = 0xFFFFFFFF; - break; - } - if( fpos==0xFFFFFFFF ) return -1; - else return (long)fpos; + HANDLE p = get_file_handle(f); + DWORD fpos; + switch (origin) { + case SEEK_SET: + fpos = SetFilePointer(p, offset, NULL, FILE_BEGIN); + break; + case SEEK_CUR: + fpos = SetFilePointer(p, offset, NULL, FILE_CURRENT); + break; + case SEEK_END: + fpos = SetFilePointer(p, offset, NULL, FILE_END); + break; + default: + fpos = 0xFFFFFFFF; + break; + } + if (fpos == 0xFFFFFFFF) + return -1; + else + return (long) fpos; } -int __cdecl open( const char *filename, int oflag, ... ) +int __cdecl open(const char *filename, int oflag, ...) { - TCHAR fname[MAX_PATH+1]; - TCHAR path[MAX_PATH+1]; - HANDLE f; - DWORD fileaccess; - DWORD filecreate; + TCHAR fname[MAX_PATH + 1]; + TCHAR path[MAX_PATH + 1]; + HANDLE f; + DWORD fileaccess; + DWORD filecreate; - /* O_TEXT is not supported */ + /* O_TEXT is not supported */ /* * decode the access flags */ - switch( oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR) ) { - - case _O_RDONLY: /* read access */ - fileaccess = GENERIC_READ; - break; - case _O_WRONLY: /* write access */ - fileaccess = GENERIC_READ | GENERIC_WRITE; - break; - case _O_RDWR: /* read and write access */ - fileaccess = GENERIC_READ | GENERIC_WRITE; - break; - default: /* error, bad oflag */ - return -1; + switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) { + case _O_RDONLY: /* read access */ + fileaccess = GENERIC_READ; + break; + case _O_WRONLY: /* write access */ + fileaccess = GENERIC_READ | GENERIC_WRITE; + break; + case _O_RDWR: /* read and write access */ + fileaccess = GENERIC_READ | GENERIC_WRITE; + break; + default: /* error, bad oflag */ + return -1; } /* * decode open/create method flags */ - switch ( oflag & (_O_CREAT | _O_EXCL | _O_TRUNC) ) { - case 0: - case _O_EXCL: // ignore EXCL w/o CREAT - filecreate = OPEN_EXISTING; - break; + switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) { + case 0: + case _O_EXCL: // ignore EXCL w/o CREAT + filecreate = OPEN_EXISTING; + break; - case _O_CREAT: - filecreate = OPEN_ALWAYS; - break; + case _O_CREAT: + filecreate = OPEN_ALWAYS; + break; - case _O_CREAT | _O_EXCL: - case _O_CREAT | _O_TRUNC | _O_EXCL: - filecreate = CREATE_NEW; - break; + case _O_CREAT | _O_EXCL: + case _O_CREAT | _O_TRUNC | _O_EXCL: + filecreate = CREATE_NEW; + break; - case _O_TRUNC: - case _O_TRUNC | _O_EXCL: // ignore EXCL w/o CREAT - filecreate = TRUNCATE_EXISTING; - break; + case _O_TRUNC: + case _O_TRUNC | _O_EXCL: // ignore EXCL w/o CREAT + filecreate = TRUNCATE_EXISTING; + break; - case _O_CREAT | _O_TRUNC: - filecreate = CREATE_ALWAYS; - break; + case _O_CREAT | _O_TRUNC: + filecreate = CREATE_ALWAYS; + break; - default: - return -1; + default: + return -1; } - /* assemple the file name */ - ZeroMemory(fname, sizeof(fname)); - ZeroMemory(path, sizeof(path)); - NH_A2W(filename, fname, MAX_PATH); - if( *filename!='\\' && *filename!='/' ) { - _tcscpy(path, _nh_cwd); - _tcsncat(path, _T("\\"), MAX_PATH - _tcslen(path)); - } - _tcsncat(path, fname, MAX_PATH - _tcslen(path)); + /* assemple the file name */ + ZeroMemory(fname, sizeof(fname)); + ZeroMemory(path, sizeof(path)); + NH_A2W(filename, fname, MAX_PATH); + if (*filename != '\\' && *filename != '/') { + _tcscpy(path, _nh_cwd); + _tcsncat(path, _T("\\"), MAX_PATH - _tcslen(path)); + } + _tcsncat(path, fname, MAX_PATH - _tcslen(path)); /* * try to open/create the file */ - if ( (f = CreateFile( path, - fileaccess, - 0, - NULL, - filecreate, - FILE_ATTRIBUTE_NORMAL, - NULL )) - == INVALID_HANDLE_VALUE ) - { + if ((f = CreateFile(path, fileaccess, 0, NULL, filecreate, + FILE_ATTRIBUTE_NORMAL, NULL)) + == INVALID_HANDLE_VALUE) { return -1; } - if( !(oflag & O_APPEND) ) SetFilePointer(f, 0, NULL, FILE_BEGIN); - return alloc_file_handle(f); + if (!(oflag & O_APPEND)) + SetFilePointer(f, 0, NULL, FILE_BEGIN); + return alloc_file_handle(f); } -int __cdecl read( int f, void *buffer, unsigned int count ) +int __cdecl read(int f, void *buffer, unsigned int count) { - HANDLE p = get_file_handle(f); - DWORD bytes_read; - if( !ReadFile(p, buffer, count, &bytes_read, NULL) ) - return -1; - else - return (int)bytes_read; + HANDLE p = get_file_handle(f); + DWORD bytes_read; + if (!ReadFile(p, buffer, count, &bytes_read, NULL)) + return -1; + else + return (int) bytes_read; } -int __cdecl unlink(const char * filename) +int __cdecl unlink(const char *filename) { - TCHAR wbuf[MAX_PATH+1]; - TCHAR fname[MAX_PATH+1]; - - ZeroMemory(wbuf, sizeof(wbuf)); - ZeroMemory(fname, sizeof(fname)); - NH_A2W(filename, wbuf, MAX_PATH); - if( *filename!='\\' && *filename!='/' ) { - _tcscpy(fname, _nh_cwd); - _tcsncat(fname, _T("\\"), MAX_PATH - _tcslen(fname)); - } - _tcsncat(fname, wbuf, MAX_PATH - _tcslen(fname)); + TCHAR wbuf[MAX_PATH + 1]; + TCHAR fname[MAX_PATH + 1]; - return !DeleteFileW(fname); + ZeroMemory(wbuf, sizeof(wbuf)); + ZeroMemory(fname, sizeof(fname)); + NH_A2W(filename, wbuf, MAX_PATH); + if (*filename != '\\' && *filename != '/') { + _tcscpy(fname, _nh_cwd); + _tcsncat(fname, _T("\\"), MAX_PATH - _tcslen(fname)); + } + _tcsncat(fname, wbuf, MAX_PATH - _tcslen(fname)); + + return !DeleteFileW(fname); } -int __cdecl write( int f, const void *buffer, unsigned int count ) +int __cdecl write(int f, const void *buffer, unsigned int count) { - HANDLE p = get_file_handle(f); - DWORD bytes_written; - if( !WriteFile(p, buffer, count, &bytes_written, NULL) ) - return -1; - else - return (int)bytes_written; + HANDLE p = get_file_handle(f); + DWORD bytes_written; + if (!WriteFile(p, buffer, count, &bytes_written, NULL)) + return -1; + else + return (int) bytes_written; } -int __cdecl rename( const char *oldname, const char *newname ) +int __cdecl rename(const char *oldname, const char *newname) { - WCHAR f1[MAX_PATH+1]; - WCHAR f2[MAX_PATH+1]; - ZeroMemory(f1, sizeof(f1)); - ZeroMemory(f2, sizeof(f2)); - MultiByteToWideChar(CP_ACP, 0, oldname, -1, f1, MAX_PATH); - MultiByteToWideChar(CP_ACP, 0, newname, -1, f2, MAX_PATH); - return !MoveFile(f1, f2); + WCHAR f1[MAX_PATH + 1]; + WCHAR f2[MAX_PATH + 1]; + ZeroMemory(f1, sizeof(f1)); + ZeroMemory(f2, sizeof(f2)); + MultiByteToWideChar(CP_ACP, 0, oldname, -1, f1, MAX_PATH); + MultiByteToWideChar(CP_ACP, 0, newname, -1, f2, MAX_PATH); + return !MoveFile(f1, f2); } -int __cdecl access( const char *path, int mode ) +int __cdecl access(const char *path, int mode) { - DWORD attr; - WCHAR f[MAX_PATH+1]; - ZeroMemory(f, sizeof(f)); - MultiByteToWideChar(CP_ACP, 0, path, -1, f, MAX_PATH); - - attr = GetFileAttributes(f); - if( attr == (DWORD)-1 ) return -1; + DWORD attr; + WCHAR f[MAX_PATH + 1]; + ZeroMemory(f, sizeof(f)); + MultiByteToWideChar(CP_ACP, 0, path, -1, f, MAX_PATH); - if ( (attr & FILE_ATTRIBUTE_READONLY) && (mode & 2) ) - return -1; - else + attr = GetFileAttributes(f); + if (attr == (DWORD) -1) + return -1; + + if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & 2)) + return -1; + else return 0; } -int chdir( const char *dirname ) +int +chdir(const char *dirname) { - ZeroMemory(_nh_cwd, sizeof(_nh_cwd)); - NH_A2W(dirname, _nh_cwd, MAX_PATH); - return 0; + ZeroMemory(_nh_cwd, sizeof(_nh_cwd)); + NH_A2W(dirname, _nh_cwd, MAX_PATH); + return 0; } -char *getcwd( char *buffer, int maxlen ) +char * +getcwd(char *buffer, int maxlen) { - if( maxlen<(int)_tcslen(_nh_cwd) ) return NULL; - else return NH_W2A(_nh_cwd, buffer, maxlen); + if (maxlen < (int) _tcslen(_nh_cwd)) + return NULL; + else + return NH_W2A(_nh_cwd, buffer, maxlen); } /*------------------------------------------------------------------------------*/ @@ -368,101 +377,104 @@ int errno; void chdrive(char *str) { - return; + return; } /* * This is used in nhlan.c to implement some of the LAN_FEATURES. */ -char *get_username(lan_username_size) +char * +get_username(lan_username_size) int *lan_username_size; { - static char username_buffer[BUFSZ]; - strcpy(username_buffer, "nhsave"); - return username_buffer; + static char username_buffer[BUFSZ]; + strcpy(username_buffer, "nhsave"); + return username_buffer; } -void Delay(int ms) +void +Delay(int ms) { - (void)Sleep(ms); + (void) Sleep(ms); } -void more() +void +more() { - } -int isatty(int f) +int +isatty(int f) { - return 0; + return 0; } - #if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO) int __cdecl isupper(int c) { - char str[2]; - WCHAR wstr[2]; - str[0] = c; - str[1] = 0; + char str[2]; + WCHAR wstr[2]; + str[0] = c; + str[1] = 0; - NH_A2W(str, wstr, 1); - return iswupper(wstr[0]); + NH_A2W(str, wstr, 1); + return iswupper(wstr[0]); } int __cdecl isdigit(int c) { - return ('0' <= c && c <= '9'); + return ('0' <= c && c <= '9'); } int __cdecl isxdigit(int c) { - return (('0' <= c && c <= '9') || - ('a' <= c && c <= 'f') || - ('A' <= c && c <= 'F')); + return (('0' <= c && c <= '9') || ('a' <= c && c <= 'f') + || ('A' <= c && c <= 'F')); } int __cdecl isspace(int c) { - char str[2]; - WCHAR wstr[2]; - str[0] = c; - str[1] = 0; + char str[2]; + WCHAR wstr[2]; + str[0] = c; + str[1] = 0; - NH_A2W(str, wstr, 1); - return iswspace(wstr[0]); + NH_A2W(str, wstr, 1); + return iswspace(wstr[0]); } int __cdecl isprint(int c) { - char str[2]; - WCHAR wstr[2]; - str[0] = c; - str[1] = 0; + char str[2]; + WCHAR wstr[2]; + str[0] = c; + str[1] = 0; - NH_A2W(str, wstr, 1); - return iswprint(wstr[0]); + NH_A2W(str, wstr, 1); + return iswprint(wstr[0]); } -char* __cdecl _strdup(const char* s) +char *__cdecl _strdup(const char *s) { - char* p; - p = malloc(strlen(s)+1); - return strcpy(p, s); + char *p; + p = malloc(strlen(s) + 1); + return strcpy(p, s); } -char* __cdecl strrchr( const char *s, int c ) +char *__cdecl strrchr(const char *s, int c) { - WCHAR wstr[1024]; - WCHAR *w; - w = wcsrchr(NH_A2W(s, wstr, 1024), c); - if(w) return (char*)(s + (w - wstr)); - else return NULL; + WCHAR wstr[1024]; + WCHAR *w; + w = wcsrchr(NH_A2W(s, wstr, 1024), c); + if (w) + return (char *) (s + (w - wstr)); + else + return NULL; } -int __cdecl _stricmp(const char* a, const char* b) +int __cdecl _stricmp(const char *a, const char *b) { - return strncmpi(a, b, 65535u); + return strncmpi(a, b, 65535u); } #endif @@ -470,9 +482,9 @@ int __cdecl _stricmp(const char* a, const char* b) #if defined(WIN_CE_PS2xx) /* stdio.h functions are missing from PAlm Size PC SDK 1.2 (SH3 and MIPS) */ -#pragma warning(disable:4273) +#pragma warning(disable : 4273) -FILE * __cdecl fopen(const char* filename, const char *mode) +FILE *__cdecl fopen(const char *filename, const char *mode) { int modeflag; int whileflag; @@ -481,361 +493,415 @@ FILE * __cdecl fopen(const char* filename, const char *mode) /* First mode character must be 'r', 'w', or 'a'. */ switch (*mode) { case 'r': - modeflag = _O_RDONLY; - break; + modeflag = _O_RDONLY; + break; case 'w': - modeflag = _O_WRONLY | _O_CREAT | _O_TRUNC; - break; + modeflag = _O_WRONLY | _O_CREAT | _O_TRUNC; + break; case 'a': - modeflag = _O_WRONLY | _O_CREAT | _O_APPEND; - break; + modeflag = _O_WRONLY | _O_CREAT | _O_APPEND; + break; default: - return NULL; + return NULL; } - whileflag=1; - while(*++mode && whileflag) - switch(*mode) { - - case '+': - if (modeflag & _O_RDWR) - whileflag=0; - else { - modeflag |= _O_RDWR; - modeflag &= ~(_O_RDONLY | _O_WRONLY); - } - break; - - case 'b': - if (modeflag & (_O_TEXT | _O_BINARY)) - whileflag=0; - else - modeflag |= _O_BINARY; - break; - - case 't': /* not supported */ - whileflag=0; - break; - - default: - whileflag=0; - break; + whileflag = 1; + while (*++mode && whileflag) + switch (*mode) { + case '+': + if (modeflag & _O_RDWR) + whileflag = 0; + else { + modeflag |= _O_RDWR; + modeflag &= ~(_O_RDONLY | _O_WRONLY); } + break; - if ((filedes = open(filename, modeflag))==-1) return NULL; + case 'b': + if (modeflag & (_O_TEXT | _O_BINARY)) + whileflag = 0; + else + modeflag |= _O_BINARY; + break; - return (FILE*)filedes; + case 't': /* not supported */ + whileflag = 0; + break; + + default: + whileflag = 0; + break; + } + + if ((filedes = open(filename, modeflag)) == -1) + return NULL; + + return (FILE *) filedes; } -int __cdecl fscanf(FILE *f , const char *format, ...) +int __cdecl fscanf(FILE *f, const char *format, ...) { - /* Format spec: %[*] [width] [l] type ] */ - int ch; - int sch; - int matched = 0; - int width = 65535; - int modifier = -1; - int skip_flag = 0; - int n_read = 0; - char buf[BUFSZ]; - TCHAR wbuf[BUFSZ]; - char* p; - va_list args; + /* Format spec: %[*] [width] [l] type ] */ + int ch; + int sch; + int matched = 0; + int width = 65535; + int modifier = -1; + int skip_flag = 0; + int n_read = 0; + char buf[BUFSZ]; + TCHAR wbuf[BUFSZ]; + char *p; + va_list args; -#define RETURN_SCANF(i) { va_end(args); return i; } +#define RETURN_SCANF(i) \ + { \ + va_end(args); \ + return i; \ + } #define NEXT_CHAR(f) (n_read++, fgetc(f)) - va_start(args, format); + va_start(args, format); - ch = *format++; - sch = NEXT_CHAR(f); - while( ch && sch!=EOF ) { - if( isspace(ch) ) { - while( ch && isspace(ch) ) ch = *format++; - while( sch!=EOF && isspace(sch) ) sch = NEXT_CHAR(f); - format--; - goto next_spec; - } + ch = *format++; + sch = NEXT_CHAR(f); + while (ch && sch != EOF) { + if (isspace(ch)) { + while (ch && isspace(ch)) + ch = *format++; + while (sch != EOF && isspace(sch)) + sch = NEXT_CHAR(f); + format--; + goto next_spec; + } - /* read % */ - if( ch!='%' ) { - if( sch!=ch ) RETURN_SCANF(matched); - sch = NEXT_CHAR(f); - goto next_spec; - } else { - /* process '%%' */ - ch = *format++; - if( ch=='%' ) { - if( sch!='%' ) RETURN_SCANF(matched); - sch = NEXT_CHAR(f); - goto next_spec; - } - - if( ch=='*' ) { - /* read skip flag - '*' */ - skip_flag=1; - ch = *format++; - } + /* read % */ + if (ch != '%') { + if (sch != ch) + RETURN_SCANF(matched); + sch = NEXT_CHAR(f); + goto next_spec; + } else { + /* process '%%' */ + ch = *format++; + if (ch == '%') { + if (sch != '%') + RETURN_SCANF(matched); + sch = NEXT_CHAR(f); + goto next_spec; + } - /* get width */ - if( isdigit(ch) ) { - width = 0; - while(ch && isdigit(ch)) { - width = width*10 + (ch-'0'); - ch = *format++; - } - } + if (ch == '*') { + /* read skip flag - '*' */ + skip_flag = 1; + ch = *format++; + } - /* get modifier */ - if( ch=='l' ) { - modifier = 'l'; - ch = *format++; - } + /* get width */ + if (isdigit(ch)) { + width = 0; + while (ch && isdigit(ch)) { + width = width * 10 + (ch - '0'); + ch = *format++; + } + } - /* get type */ - switch(ch) { - case 'c': - if( !skip_flag ) { - *(va_arg(args, char*))=sch; - matched++; - } - sch = NEXT_CHAR(f); - goto next_spec; - case 'd': - p = buf; - /* skip space */ - while(sch!=EOF && isspace(sch)) sch=NEXT_CHAR(f); - while(sch!=EOF && isdigit(sch) && --width>=0) { *p++ = sch; sch=NEXT_CHAR(f); } - *p = '\x0'; - if( !skip_flag ) { - matched++; - if( modifier=='l' ) { - *(va_arg(args, long*))=wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 10); - } else { - *(va_arg(args, int*))=wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 10); - } - } - goto next_spec; - case 'x': - p = buf; - while(sch!=EOF && isspace(sch)) sch=NEXT_CHAR(f); - while(sch!=EOF && isxdigit(sch) && --width>=0) { *p++ = sch; sch=NEXT_CHAR(f); } - *p = '\x0'; - if( !skip_flag ) { - matched++; - if( modifier=='l' ) { - *(va_arg(args, long*))=wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 16); - } else { - *(va_arg(args, int*))=wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 16); - } - } - goto next_spec; - case 'n': - *(va_arg(args, int*)) = n_read; - matched++; - goto next_spec; - case 's': - if( skip_flag ) { - while(sch!=EOF && !isspace(sch) && --width>=0) { sch=NEXT_CHAR(f); } - } else { - p = va_arg(args, char*); - while(sch!=EOF && !isspace(sch) && --width>=0) { *p++ = sch; sch=NEXT_CHAR(f); } - *p = '\x0'; - matched++; - } - goto next_spec; - case '[': { - char pattern[256]; - int start, end; - int negate; + /* get modifier */ + if (ch == 'l') { + modifier = 'l'; + ch = *format++; + } - ZeroMemory(pattern, sizeof(pattern)); - p = pattern; - - /* try to parse '^' modifier */ - ch = *format++; - if( ch=='^' ) { negate=1; ch=*format++; } - else { negate=0; } - if( ch==0 ) RETURN_SCANF(EOF); + /* get type */ + switch (ch) { + case 'c': + if (!skip_flag) { + *(va_arg(args, char *) ) = sch; + matched++; + } + sch = NEXT_CHAR(f); + goto next_spec; + case 'd': + p = buf; + /* skip space */ + while (sch != EOF && isspace(sch)) + sch = NEXT_CHAR(f); + while (sch != EOF && isdigit(sch) && --width >= 0) { + *p++ = sch; + sch = NEXT_CHAR(f); + } + *p = '\x0'; + if (!skip_flag) { + matched++; + if (modifier == 'l') { + *(va_arg(args, long *) ) = + wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 10); + } else { + *(va_arg(args, int *) ) = + wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 10); + } + } + goto next_spec; + case 'x': + p = buf; + while (sch != EOF && isspace(sch)) + sch = NEXT_CHAR(f); + while (sch != EOF && isxdigit(sch) && --width >= 0) { + *p++ = sch; + sch = NEXT_CHAR(f); + } + *p = '\x0'; + if (!skip_flag) { + matched++; + if (modifier == 'l') { + *(va_arg(args, long *) ) = + wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 16); + } else { + *(va_arg(args, int *) ) = + wcstol(NH_A2W(buf, wbuf, BUFSZ), NULL, 16); + } + } + goto next_spec; + case 'n': + *(va_arg(args, int *) ) = n_read; + matched++; + goto next_spec; + case 's': + if (skip_flag) { + while (sch != EOF && !isspace(sch) && --width >= 0) { + sch = NEXT_CHAR(f); + } + } else { + p = va_arg(args, char *); + while (sch != EOF && !isspace(sch) && --width >= 0) { + *p++ = sch; + sch = NEXT_CHAR(f); + } + *p = '\x0'; + matched++; + } + goto next_spec; + case '[': { + char pattern[256]; + int start, end; + int negate; - for( ; ch && ch!=']'; ch = *format++ ) { - /* try to parse range: a-z */ - if( format[0]=='-' && - format[1] && format[1]!=']' ) { - start = ch; - format++; - end = *format++; - while(start<=end) { - if(!strchr(pattern, (char)start)) - *p++ = (char)start; - start++; - } - } else { - if(!strchr(pattern, (char)ch)) *p++ = (char)ch; - } - } + ZeroMemory(pattern, sizeof(pattern)); + p = pattern; - if( skip_flag ) { - while(sch!=EOF && strchr(pattern, sch) && --width>=0) { sch=NEXT_CHAR(f); } - } else { - p = va_arg(args, char*); - if( negate ) - while(sch!=EOF && !strchr(pattern, sch) && --width>=0) { *p++ = sch; sch=NEXT_CHAR(f); } - else - while(sch!=EOF && strchr(pattern, sch) && --width>=0) { *p++ = sch; sch=NEXT_CHAR(f); } - *p = '\x0'; - matched++; - } - } goto next_spec; - default: - RETURN_SCANF(EOF); - } - } + /* try to parse '^' modifier */ + ch = *format++; + if (ch == '^') { + negate = 1; + ch = *format++; + } else { + negate = 0; + } + if (ch == 0) + RETURN_SCANF(EOF); -next_spec: - width = 65535; - modifier = -1; - skip_flag = 0; - ch = *format++; - } - fseek(f, -1, SEEK_CUR); - RETURN_SCANF(matched); + for (; ch && ch != ']'; ch = *format++) { + /* try to parse range: a-z */ + if (format[0] == '-' && format[1] && format[1] != ']') { + start = ch; + format++; + end = *format++; + while (start <= end) { + if (!strchr(pattern, (char) start)) + *p++ = (char) start; + start++; + } + } else { + if (!strchr(pattern, (char) ch)) + *p++ = (char) ch; + } + } + + if (skip_flag) { + while (sch != EOF && strchr(pattern, sch) + && --width >= 0) { + sch = NEXT_CHAR(f); + } + } else { + p = va_arg(args, char *); + if (negate) + while (sch != EOF && !strchr(pattern, sch) + && --width >= 0) { + *p++ = sch; + sch = NEXT_CHAR(f); + } + else + while (sch != EOF && strchr(pattern, sch) + && --width >= 0) { + *p++ = sch; + sch = NEXT_CHAR(f); + } + *p = '\x0'; + matched++; + } + } + goto next_spec; + default: + RETURN_SCANF(EOF); + } + } + + next_spec: + width = 65535; + modifier = -1; + skip_flag = 0; + ch = *format++; + } + fseek(f, -1, SEEK_CUR); + RETURN_SCANF(matched); #undef RETURN_SCANF #undef NEXT_CHAR } -int __cdecl fprintf(FILE *f , const char *format, ...) +int __cdecl fprintf(FILE *f, const char *format, ...) { - int retval; - va_list args; + int retval; + va_list args; - if( !f || !format ) return 0; + if (!f || !format) + return 0; - va_start(args, format); - retval = vfprintf(f, format, args); - va_end(args); - - return retval; + va_start(args, format); + retval = vfprintf(f, format, args); + va_end(args); + + return retval; } -int __cdecl vfprintf(FILE* f, const char *format, va_list args) +int __cdecl vfprintf(FILE *f, const char *format, va_list args) { - char buf[4096]; - int retval; + char buf[4096]; + int retval; - if( !f || !format ) return 0; + if (!f || !format) + return 0; - retval = vsprintf(buf, format, args); + retval = vsprintf(buf, format, args); - write((int)f, buf, strlen(buf)); - - return retval; + write((int) f, buf, strlen(buf)); + + return retval; } -int __cdecl fgetc(FILE * f) +int __cdecl fgetc(FILE *f) { - char c; - int fh = (int)f; + char c; + int fh = (int) f; - if( !f ) return EOF; - if( read(fh, &c, 1)==1 ) return c; - else return EOF; + if (!f) + return EOF; + if (read(fh, &c, 1) == 1) + return c; + else + return EOF; } -char * __cdecl fgets(char *s, int size, FILE *f) +char *__cdecl fgets(char *s, int size, FILE *f) { - /* not the best performance but it will do for now...*/ - char c; - if( !f || !s || size==0 ) return NULL; - while( --size>0 ) { - if( (c = fgetc(f))==EOF ) return NULL; + /* not the best performance but it will do for now...*/ + char c; + if (!f || !s || size == 0) + return NULL; + while (--size > 0) { + if ((c = fgetc(f)) == EOF) + return NULL; - *s++ = c; - if( c=='\n' ) break; - } - *s = '\x0'; - return s; + *s++ = c; + if (c == '\n') + break; + } + *s = '\x0'; + return s; } -int __cdecl printf(const char *format, ...) +int __cdecl printf(const char *format, ...) { - int retval; - va_list args; + int retval; + va_list args; - if( !format ) return 0; + if (!format) + return 0; - va_start(args, format); - retval = vprintf(format, args); - va_end(args); + va_start(args, format); + retval = vprintf(format, args); + va_end(args); - return retval; + return retval; } -int __cdecl vprintf(const char *format, va_list args) +int __cdecl vprintf(const char *format, va_list args) { - char buf[4096]; - int retval; + char buf[4096]; + int retval; - retval = vsprintf(buf, format, args); - puts(buf); - return retval; + retval = vsprintf(buf, format, args); + puts(buf); + return retval; } // int __cdecl putchar(int); -int __cdecl puts(const char * s) +int __cdecl puts(const char *s) { - TCHAR wbuf[4096]; - NH_A2W(s, wbuf, 4096); - MessageBox(NULL, wbuf, _T("stdout"), MB_OK); - return 0; + TCHAR wbuf[4096]; + NH_A2W(s, wbuf, 4096); + MessageBox(NULL, wbuf, _T("stdout"), MB_OK); + return 0; } -FILE* __cdecl _getstdfilex(int desc) +FILE *__cdecl _getstdfilex(int desc) { - return NULL; + return NULL; } -int __cdecl fclose(FILE * f) +int __cdecl fclose(FILE *f) { - if(!f) return EOF; - return close((int)f)==-1? EOF : 0; + if (!f) + return EOF; + return close((int) f) == -1 ? EOF : 0; } size_t __cdecl fread(void *p, size_t size, size_t count, FILE *f) { - int read_bytes; - if(!f || !p || size==0 || count==0) return 0; - read_bytes = read((int)f, p, size*count); - return read_bytes>0? (read_bytes/size) : 0; + int read_bytes; + if (!f || !p || size == 0 || count == 0) + return 0; + read_bytes = read((int) f, p, size * count); + return read_bytes > 0 ? (read_bytes / size) : 0; } -size_t __cdecl fwrite(const void *p, size_t size, size_t count, FILE * f) +size_t __cdecl fwrite(const void *p, size_t size, size_t count, FILE *f) { - int write_bytes; - if(!f || !p || size==0 || count==0) return 0; - write_bytes = write((int)f, p, size*count); - return write_bytes>0? write_bytes/size : 0; + int write_bytes; + if (!f || !p || size == 0 || count == 0) + return 0; + write_bytes = write((int) f, p, size * count); + return write_bytes > 0 ? write_bytes / size : 0; } -int __cdecl fflush(FILE *f) -{ - return 0; -} - -int __cdecl feof(FILE *f) +int __cdecl fflush(FILE *f) { - return (f && eof((int)f)==0)? 0 : 1; + return 0; } -int __cdecl fseek(FILE *f, long offset, int from) +int __cdecl feof(FILE *f) { - return (f && lseek((int)f, offset, from)>=0)? 0 : 1; + return (f && eof((int) f) == 0) ? 0 : 1; } -long __cdecl ftell(FILE * f) +int __cdecl fseek(FILE *f, long offset, int from) { - return f? lseek((int)f, 0, SEEK_CUR) : -1; + return (f && lseek((int) f, offset, from) >= 0) ? 0 : 1; } -#endif +long __cdecl ftell(FILE *f) +{ + return f ? lseek((int) f, 0, SEEK_CUR) : -1; +} + +#endif diff --git a/sys/wince/cesound.c b/sys/wince/cesound.c index 63784dd8b..186802d68 100644 --- a/sys/wince/cesound.c +++ b/sys/wince/cesound.c @@ -1,13 +1,13 @@ -/* NetHack 3.6 cesound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 cesound.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */ /* NetHack 3.6 cesound.c $Date: 2009/05/06 10:52:00 $ $Revision: 1.4 $ */ -/* SCCS Id: @(#)cesound.c 3.5 $NHDT-Date$ */ -/* SCCS Id: @(#)cesound.c 3.5 $Date: 2009/05/06 10:52:00 $ */ +/* SCCS Id: @(#)cesound.c 3.5 $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ */ +/* SCCS Id: @(#)cesound.c 3.5 $Date: 2009/05/06 10:52:00 $ */ /* Copyright (c) NetHack PC Development Team 1993 */ /* NetHack may be freely redistributed. See license for details. */ /* */ /* * cesound.c - Windows CE NetHack sound support - * + * * */ @@ -16,14 +16,16 @@ #ifdef USER_SOUNDS -void play_usersound(filename, volume) -const char* filename; +void +play_usersound(filename, volume) +const char *filename; int volume; { - TCHAR wbuf[MAX_PATH+1]; -/* pline("play_usersound: %s (%d).", filename, volume); */ - ZeroMemory(wbuf, sizeof(wbuf)); - (void)sndPlaySound(NH_A2W(filename, wbuf, MAX_PATH), SND_ASYNC | SND_NODEFAULT); + TCHAR wbuf[MAX_PATH + 1]; + /* pline("play_usersound: %s (%d).", filename, volume); */ + ZeroMemory(wbuf, sizeof(wbuf)); + (void) sndPlaySound(NH_A2W(filename, wbuf, MAX_PATH), + SND_ASYNC | SND_NODEFAULT); } #endif /*USER_SOUNDS*/ diff --git a/sys/wince/mhaskyn.c b/sys/wince/mhaskyn.c index e3fddb694..0876f5ca8 100644 --- a/sys/wince/mhaskyn.c +++ b/sys/wince/mhaskyn.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhaskyn.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhaskyn.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 mhaskyn.c $Date: 2009/05/06 10:52:00 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)mhaskyn.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -8,8 +8,8 @@ #include "winMS.h" #include "mhaskyn.h" -int mswin_yes_no_dialog( const char *question, const char *choices, int def) +int +mswin_yes_no_dialog(const char *question, const char *choices, int def) { - return '\032'; + return '\032'; } - diff --git a/sys/wince/mhcmd.c b/sys/wince/mhcmd.c index c260d6195..34761d903 100644 --- a/sys/wince/mhcmd.c +++ b/sys/wince/mhcmd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhcmd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhcmd.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 mhcmd.c $Date: 2009/10/22 02:59:30 $ $Revision: 1.8 $ */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,136 +11,144 @@ static TCHAR szNHCmdWindowClass[] = TEXT("MSNethackCmdWndClass"); #ifndef C -# define C(c) (0x1f & (c)) +#define C(c) (0x1f & (c)) #endif /* cell status 0 */ -#define NH_CST_CHECKED 1 +#define NH_CST_CHECKED 1 /* fonts */ -#define NH_CMDPAD_FONT_NORMAL 0 -#define NH_CMDPAD_FONT_MAX 0 +#define NH_CMDPAD_FONT_NORMAL 0 +#define NH_CMDPAD_FONT_MAX 0 /* type of the cell */ -#define NH_CELL_REG 0 -#define NH_CELL_CTRL 1 -#define NH_CELL_CAP 2 -#define NH_CELL_SHIFT 3 -#define NH_CELL_LAYOUT_NEW 4 -#define NH_CELL_LAYOUT_MENU 5 +#define NH_CELL_REG 0 +#define NH_CELL_CTRL 1 +#define NH_CELL_CAP 2 +#define NH_CELL_SHIFT 3 +#define NH_CELL_LAYOUT_NEW 4 +#define NH_CELL_LAYOUT_MENU 5 -#define NH_CMDSET_MAXSIZE 64 +#define NH_CMDSET_MAXSIZE 64 -/* Keypad cell information - - NHCmdPadCell.cell_type NHCmdPadCell.data - ----------- ---------- - NH_CELL_REG (int)>=0 - index in the current keypad layout set (loads a new layout) - -1 - restore default (saved) layout - NH_CELL_CTRL not used - NH_CELL_CAP not used - NH_CELL_SHIFT not used - NH_CELL_LAYOUT_NEW pointer to the new keypad layout layout (NHCmdLayout*) - NH_CELL_LAYOUT_MENU pointer to the layout set (NHCmdSet* - if NULL then nhcmdset_default is used) +/* Keypad cell information + + NHCmdPadCell.cell_type NHCmdPadCell.data + ----------- ---------- + NH_CELL_REG (int)>=0 - index in the + current keypad layout set (loads a new layout) + -1 - restore default (saved) layout + NH_CELL_CTRL not used + NH_CELL_CAP not used + NH_CELL_SHIFT not used + NH_CELL_LAYOUT_NEW pointer to the new keypad layout + layout (NHCmdLayout*) + NH_CELL_LAYOUT_MENU pointer to the layout set (NHCmdSet* - if + NULL then nhcmdset_default is used) */ typedef struct t_NHCmdPadCell { - UINT cmd_code; /* Windows command code (menu processing - not implemented - set to -1) */ - char f_char[16]; /* nethack char */ - char text[16]; /* display text */ - int image; /* >0 - image ID in IDB_KEYPAD bitmap - <=0 - absolute index of the font table */ - int type; /* cell type */ - int mult; /* cell width multiplier */ - void* data; /* internal data for the cell type */ + UINT cmd_code; /* Windows command code (menu processing - not implemented + - set to -1) */ + char f_char[16]; /* nethack char */ + char text[16]; /* display text */ + int image; /* >0 - image ID in IDB_KEYPAD bitmap + <=0 - absolute index of the font table */ + int type; /* cell type */ + int mult; /* cell width multiplier */ + void *data; /* internal data for the cell type */ } NHCmdPadCell, *PNHCmdPadCell; /* command layout */ typedef struct t_NHCmdLayout { - char name[64]; - int rows; - int columns; - NHCmdPadCell cells[]; + char name[64]; + int rows; + int columns; + NHCmdPadCell cells[]; } NHCmdLayout, *PNHCmdLayout; /* set of command layouts */ typedef struct t_NHCmdSet { - int count; - struct t_NHCmdSetElem { - PNHCmdLayout layout; - BOOL free_on_destroy; - } elements[NH_CMDSET_MAXSIZE]; + int count; + struct t_NHCmdSetElem { + PNHCmdLayout layout; + BOOL free_on_destroy; + } elements[NH_CMDSET_MAXSIZE]; } NHCmdSet, *PNHCmdSet; /* display cell layout */ typedef struct t_NHCmdPadLayoutCell { - POINT orig; /* origin of the cell rect */ - BYTE type; /* cell type */ - int state; /* cell state */ + POINT orig; /* origin of the cell rect */ + BYTE type; /* cell type */ + int state; /* cell state */ } NHCmdPadLayoutCell, *PNHCmdPadLayoutCell; /* command window data */ typedef struct mswin_nethack_cmd_window { - SIZE cell_size; /* cell size */ - HFONT font[NH_CMDPAD_FONT_MAX+1]; /* fonts for cell text */ - HBITMAP images; /* key images map */ - int active_cell; /* current active cell */ + SIZE cell_size; /* cell size */ + HFONT font[NH_CMDPAD_FONT_MAX + 1]; /* fonts for cell text */ + HBITMAP images; /* key images map */ + int active_cell; /* current active cell */ - boolean is_caps; /* is CAPS selected */ - boolean is_ctrl; /* is CRTL selected */ - boolean is_shift; /* is SHIFT selected */ + boolean is_caps; /* is CAPS selected */ + boolean is_ctrl; /* is CRTL selected */ + boolean is_shift; /* is SHIFT selected */ - PNHCmdLayout layout_current; /* current layout */ - PNHCmdLayout layout_save; /* saved layout */ - PNHCmdPadLayoutCell cells; /* display cells */ + PNHCmdLayout layout_current; /* current layout */ + PNHCmdLayout layout_save; /* saved layout */ + PNHCmdPadLayoutCell cells; /* display cells */ #if defined(WIN_CE_SMARTPHONE) - PNHCmdLayout layout_selected; /* since we use - layout command for menu also - we need to store the layout - that was selected by a user - */ + PNHCmdLayout layout_selected; /* since we use + layout + command for menu also + we need to store the layout + that was + selected by a user + */ #endif } NHCmdWindow, *PNHCmdWindow; - LRESULT CALLBACK NHCommandWndProc(HWND, UINT, WPARAM, LPARAM); static void register_command_window_class(); static void LayoutCmdWindow(HWND hWnd); static void SetCmdWindowLayout(HWND hWnd, PNHCmdLayout layout); -static int CellFromPoint(PNHCmdWindow data, POINT pt ); +static int CellFromPoint(PNHCmdWindow data, POINT pt); static void CalculateCellSize(HWND hWnd, LPSIZE pSize, LPSIZE windowSize); static void HighlightCell(HWND hWnd, int cell, BOOL isSelected); static void ActivateCell(HWND hWnd, int cell); -static void PushNethackCommand( const char* cmd_char_str, int is_ctrl ); +static void PushNethackCommand(const char *cmd_char_str, int is_ctrl); /*------------------- keyboard keys layout functions -----------------------*/ -PNHCmdLayout nhcmdlayout_create( const char* name, int rows, int columns ); -void nhcmdlayout_init( PNHCmdLayout p, PNHCmdPadCell cells ); -#define nhcmdlayout_rows(p) ((p)->rows) -#define nhcmdlayout_columns(p) ((p)->columns) -#define nhcmdlayout_row(p, x) (&((p)->cells[(p)->columns*(x)])) -#define nhcmdlayout_cell(p, x, y) (&((p)->cells[(p)->columns*(x)+(y)])) -#define nhcmdlayout_cell_direct(p, i) (&((p)->cells[(i)])) -void nhcmdlayout_destroy(PNHCmdLayout p); +PNHCmdLayout nhcmdlayout_create(const char *name, int rows, int columns); +void nhcmdlayout_init(PNHCmdLayout p, PNHCmdPadCell cells); +#define nhcmdlayout_rows(p) ((p)->rows) +#define nhcmdlayout_columns(p) ((p)->columns) +#define nhcmdlayout_row(p, x) (&((p)->cells[(p)->columns * (x)])) +#define nhcmdlayout_cell(p, x, y) (&((p)->cells[(p)->columns * (x) + (y)])) +#define nhcmdlayout_cell_direct(p, i) (&((p)->cells[(i)])) +void nhcmdlayout_destroy(PNHCmdLayout p); /*----------------- keyboard keys layout set functions ---------------------*/ -PNHCmdSet nhcmdset_create(); -int nhcmdset_count( PNHCmdSet p ); -PNHCmdLayout nhcmdset_get( PNHCmdSet p, int index ); -const char* nhcmdset_get_name( PNHCmdSet p, int index ); -void nhcmdset_add( PNHCmdSet p, PNHCmdLayout layout ); -void nhcmdset_destroy( PNHCmdSet p); +PNHCmdSet nhcmdset_create(); +int nhcmdset_count(PNHCmdSet p); +PNHCmdLayout nhcmdset_get(PNHCmdSet p, int index); +const char *nhcmdset_get_name(PNHCmdSet p, int index); +void nhcmdset_add(PNHCmdSet p, PNHCmdLayout layout); +void nhcmdset_destroy(PNHCmdSet p); /*-------------------- message handlers -----------------------------------*/ -static void onPaint(HWND hWnd); // on WM_PAINT -static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); // on WM_CREATE -static void onMouseDown(HWND hWnd, WPARAM wParam, LPARAM lParam); // on WM_LBUTTONDOWN -static void onMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam); // on WM_MOUSEMOVE -static void onMouseUp(HWND hWnd, WPARAM wParam, LPARAM lParam); // on WM_LBUTTONUP +static void onPaint(HWND hWnd); // on WM_PAINT +static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); // on WM_CREATE +static void onMouseDown(HWND hWnd, WPARAM wParam, + LPARAM lParam); // on WM_LBUTTONDOWN +static void onMouseMove(HWND hWnd, WPARAM wParam, + LPARAM lParam); // on WM_MOUSEMOVE +static void onMouseUp(HWND hWnd, WPARAM wParam, + LPARAM lParam); // on WM_LBUTTONUP /*----------------------- static data -------------------------------------*/ -static PNHCmdSet nhcmdset_current = 0; -static PNHCmdSet nhcmdset_default = 0; +static PNHCmdSet nhcmdset_current = 0; +static PNHCmdSet nhcmdset_default = 0; /*---------------------- Pre-definde keyboard layouts --------------------*/ #ifdef WIN_CE_SMARTPHONE @@ -148,169 +156,178 @@ static PNHCmdSet nhcmdset_default = 0; /* dimensions of the command pad */ #define NH_CMDPAD_ROWS 4 #define NH_CMDPAD_COLS 3 -#define NH_CMDPAD_CELLNUM (NH_CMDPAD_COLS*NH_CMDPAD_ROWS) +#define NH_CMDPAD_CELLNUM (NH_CMDPAD_COLS * NH_CMDPAD_ROWS) /* layout indexes */ -#define NH_LAYOUT_GENERAL 0 -#define NH_LAYOUT_MOVEMENT 1 -#define NH_LAYOUT_ATTACK 2 -#define NH_LAYOUT_ITEM_HANDLING 3 -#define NH_LAYOUT_CONTROLS 4 -#define NH_LAYOUT_ADV_MOVEMENT 5 -#define NH_LAYOUT_ITEM_LOOKUP 6 -#define NH_LAYOUT_WIZARD 7 +#define NH_LAYOUT_GENERAL 0 +#define NH_LAYOUT_MOVEMENT 1 +#define NH_LAYOUT_ATTACK 2 +#define NH_LAYOUT_ITEM_HANDLING 3 +#define NH_LAYOUT_CONTROLS 4 +#define NH_LAYOUT_ADV_MOVEMENT 5 +#define NH_LAYOUT_ITEM_LOOKUP 6 +#define NH_LAYOUT_WIZARD 7 /* template menu layout */ -NHCmdPadCell cells_layout_menu[NH_CMDPAD_CELLNUM] = -{ - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", "<<", -NH_CMDPAD_FONT_NORMAL, NH_CELL_LAYOUT_NEW, 1 , NULL }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1 , (void*)-1 }, - { -1, "", ">>", -NH_CMDPAD_FONT_NORMAL, NH_CELL_LAYOUT_NEW, 1 , NULL } +NHCmdPadCell cells_layout_menu[NH_CMDPAD_CELLNUM] = { + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "<<", -NH_CMDPAD_FONT_NORMAL, NH_CELL_LAYOUT_NEW, 1, NULL }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", ">>", -NH_CMDPAD_FONT_NORMAL, NH_CELL_LAYOUT_NEW, 1, NULL } }; /* movement layout */ -NHCmdPadCell cells_layout_movement[NH_CMDPAD_CELLNUM] = -{ - { -1, "7", "7", 1, NH_CELL_REG, 1, (void*)-1 }, - { -1, "8", "8", 2, NH_CELL_REG, 1, (void*)-1 }, - { -1, "9", "9", 3, NH_CELL_REG, 1, (void*)-1 }, - { -1, "4", "4", 4, NH_CELL_REG, 1, (void*)-1 }, - { -1, ".", ".", 5, NH_CELL_REG, 1, (void*)-1 }, - { -1, "6", "6", 6, NH_CELL_REG, 1, (void*)-1 }, - { -1, "1", "1", 7, NH_CELL_REG, 1, (void*)-1 }, - { -1, "2", "2", 8, NH_CELL_REG, 1, (void*)-1 }, - { -1, "3", "3", 9, NH_CELL_REG, 1, (void*)-1 }, - { -1, "<", "<", 10, NH_CELL_REG, 1, (void*)-1 }, - { -1, ">", ">", 12, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } +NHCmdPadCell cells_layout_movement[NH_CMDPAD_CELLNUM] = { + { -1, "7", "7", 1, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "8", "8", 2, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "9", "9", 3, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "4", "4", 4, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ".", ".", 5, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "6", "6", 6, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "1", "1", 7, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "2", "2", 8, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "3", "3", 9, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "<", "<", 10, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ">", ">", 12, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* attack layout */ -NHCmdPadCell cells_layout_attack[NH_CMDPAD_CELLNUM] = -{ - { -1, "t", "t", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "w", "w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "x", "x", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "f", "f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "z", "z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "Z", "Z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "r", "r", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "a", "a", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x04", "^D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "F", "F", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)NH_LAYOUT_MOVEMENT }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_attack[NH_CMDPAD_CELLNUM] = { + { -1, "t", "t", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "w", "w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "x", "x", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "f", "f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "z", "z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "Z", "Z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "r", "r", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "a", "a", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x04", "^D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "F", "F", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) NH_LAYOUT_MOVEMENT }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* item handling layout */ -NHCmdPadCell cells_layout_item_handling[NH_CMDPAD_CELLNUM] = -{ - { -1, "W", "W", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "P", "P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "d", "d", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "T", "T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "R", "R", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "D", "D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "i", "i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "Q", "Q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "A", "A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "I", "I", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_item_handling[NH_CMDPAD_CELLNUM] = { + { -1, "W", "W", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "P", "P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "d", "d", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "T", "T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "R", "R", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "D", "D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "i", "i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "Q", "Q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "A", "A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "I", "I", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* General */ -NHCmdPadCell cells_layout_general[NH_CMDPAD_CELLNUM] = -{ - { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "e", "e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "l", "l", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "s", "s", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "E", "E", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x01", "^A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "c", "c", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "o", "o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "p", "p", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ":", ":", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ",", ",", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_general[NH_CMDPAD_CELLNUM] = { + { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "e", "e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "l", "l", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "s", "s", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "E", "E", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x01", "^A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "c", "c", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "o", "o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "p", "p", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ":", ":", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ",", ",", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* game controls layout */ -NHCmdPadCell cells_layout_game[NH_CMDPAD_CELLNUM] = -{ - { -1, "S", "S", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "h", "h", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "C", "C", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "@", "@", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\\", "\\", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "O", "O", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "&", "&", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x18", "^X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x10", "^P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_game[NH_CMDPAD_CELLNUM] = { + { -1, "S", "S", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "h", "h", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "C", "C", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "@", "@", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\\", "\\", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "O", "O", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "&", "&", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x18", "^X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x10", "^P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "X", "X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* advanced movement layout */ -NHCmdPadCell cells_layout_adv_movement[NH_CMDPAD_CELLNUM] = -{ - { -1, "g", "g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)NH_LAYOUT_MOVEMENT }, - { -1, "G", "G", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)NH_LAYOUT_MOVEMENT }, - { -1, "m", "m", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)NH_LAYOUT_MOVEMENT }, - { -1, "M", "M", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)NH_LAYOUT_MOVEMENT }, - { -1, "_", "_", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x14", "^T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "j", "j", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "<", "<", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ">", ">", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_adv_movement[NH_CMDPAD_CELLNUM] = { + { -1, "g", "g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) NH_LAYOUT_MOVEMENT }, + { -1, "G", "G", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) NH_LAYOUT_MOVEMENT }, + { -1, "m", "m", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) NH_LAYOUT_MOVEMENT }, + { -1, "M", "M", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) NH_LAYOUT_MOVEMENT }, + { -1, "_", "_", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x14", "^T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "j", "j", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "<", "<", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ">", ">", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* item lookup layout */ -NHCmdPadCell cells_layout_lookup[NH_CMDPAD_CELLNUM] = -{ - { -1, ";", ";", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "]", "]", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ")", ")", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "(", "(", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\"", "\"", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "$", "$", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "+", "+", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_lookup[NH_CMDPAD_CELLNUM] = { + { -1, ";", ";", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "]", "]", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ")", ")", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "(", "(", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\"", "\"", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "$", "$", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "+", "+", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; /* wizard mode layout */ -NHCmdPadCell cells_layout_wizard[NH_CMDPAD_CELLNUM] = -{ - { -1, "\x05", "^e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x06", "^f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x07", "^g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x09", "^i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x0f", "^o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x16", "^v", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x17", "^w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x14", "^T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1 , 0 } +NHCmdPadCell cells_layout_wizard[NH_CMDPAD_CELLNUM] = { + { -1, "\x05", "^e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x06", "^f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x07", "^g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x09", "^i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x0f", "^o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x16", "^v", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x17", "^w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "\x14", "^T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, + (void *) - 1 }, + { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", 13, NH_CELL_LAYOUT_MENU, 1, 0 } }; #else /* !WIN_CE_SMARTPHONE */ @@ -318,910 +335,983 @@ NHCmdPadCell cells_layout_wizard[NH_CMDPAD_CELLNUM] = /* dimensions of the command pad */ #define NH_CMDPAD_ROWS 4 #define NH_CMDPAD_COLS 14 -#define NH_CMDPAD_CELLNUM (NH_CMDPAD_COLS*NH_CMDPAD_ROWS) +#define NH_CMDPAD_CELLNUM (NH_CMDPAD_COLS * NH_CMDPAD_ROWS) /* lowercase layout */ -NHCmdPadCell cells_layout_mod1[NH_CMDPAD_ROWS*NH_CMDPAD_COLS] = -{ - { -1, "7", "7", 1, NH_CELL_REG, 1, (void*)-1 }, - { -1, "8", "8", 2, NH_CELL_REG, 1, (void*)-1 }, - { -1, "9", "9", 3, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x1b", "Esc", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for ESC */ - { -1, "?", "?", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ",", ",", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "/", "/", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ":", ":", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ";", ";", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "-", "-", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, +NHCmdPadCell cells_layout_mod1[NH_CMDPAD_ROWS * NH_CMDPAD_COLS] = { + { -1, "7", "7", 1, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "8", "8", 2, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "9", "9", 3, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x1b", "Esc", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for ESC */ + { -1, "?", "?", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ",", ",", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "/", "/", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ":", ":", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ";", ";", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "-", "-", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "#", "#", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "^", "^", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "4", "4", 4, NH_CELL_REG, 1, (void*)-1 }, - { -1, "5", "5", 5, NH_CELL_REG, 1, (void*)-1 }, - { -1, "6", "6", 6, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "CAP", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CAP, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for CAPS */ - { -1, "a", "a", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "b", "b", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "c", "c", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "d", "d", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "e", "e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "f", "f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "g", "g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "h", "h", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "i", "i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, + { -1, "4", "4", 4, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "5", "5", 5, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "6", "6", 6, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "CAP", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CAP, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for CAPS */ + { -1, "a", "a", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "b", "b", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "c", "c", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "d", "d", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "e", "e", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "f", "f", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "g", "g", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "h", "h", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "i", "i", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "1", "1", 7, NH_CELL_REG, 1, (void*)-1 }, - { -1, "2", "2", 8, NH_CELL_REG, 1, (void*)-1 }, - { -1, "3", "3", 9, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "Shft", -NH_CMDPAD_FONT_NORMAL, NH_CELL_SHIFT, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for shift */ - { -1, "j", "j", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "k", "k", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "l", "l", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "m", "m", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "n", "n", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "o", "o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "p", "p", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "r", "r", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, + { -1, "1", "1", 7, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "2", "2", 8, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "3", "3", 9, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "Shft", -NH_CMDPAD_FONT_NORMAL, NH_CELL_SHIFT, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for shift */ + { -1, "j", "j", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "k", "k", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "l", "l", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "m", "m", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "n", "n", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "o", "o", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "p", "p", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "q", "q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "r", "r", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "<", "<", 10, NH_CELL_REG, 1, (void*)-1 }, - { -1, ".", ".", 11, NH_CELL_REG, 1, (void*)-1 }, - { -1, ">", ">", 12, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "Ctrl", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CTRL, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for CTRL */ - { -1, "s", "s", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "t", "t", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "u", "u", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "v", "v", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "w", "w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "x", "x", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "y", "y", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "z", "z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\\", "\\", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 } + { -1, "<", "<", 10, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ".", ".", 11, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ">", ">", 12, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "Ctrl", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CTRL, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for CTRL */ + { -1, "s", "s", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "t", "t", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "u", "u", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "v", "v", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "w", "w", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "x", "x", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "y", "y", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "z", "z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\\", "\\", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 } }; /* uppercase layout */ -NHCmdPadCell cells_layout_mod2[-NH_CMDPAD_ROWS*-NH_CMDPAD_COLS] = -{ - { -1, "7", "7", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "8", "8", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "9", "9", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\x1b", "Esc", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for ESC */ - { -1, "?", "?", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "[", "[", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "(", "(", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ")", ")", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "+", "+", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "\"", "\"", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "$", "$", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, +NHCmdPadCell cells_layout_mod2[-NH_CMDPAD_ROWS * -NH_CMDPAD_COLS] = { + { -1, "7", "7", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "8", "8", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "9", "9", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\x1b", "Esc", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for ESC */ + { -1, "?", "?", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "*", "*", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "[", "[", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "(", "(", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ")", ")", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "+", "+", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "=", "=", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "\"", "\"", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "$", "$", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "4", "4", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "5", "5", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "6", "6", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "CAP", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CAP, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for CAPS */ - { -1, "A", "A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "B", "B", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "C", "C", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "D", "D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "E", "E", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "F", "F", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "G", "G", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "H", "H", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "I", "I", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, + { -1, "4", "4", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "5", "5", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "6", "6", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "CAP", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CAP, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for CAPS */ + { -1, "A", "A", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "B", "B", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "C", "C", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "D", "D", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "E", "E", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "F", "F", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "G", "G", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "H", "H", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "I", "I", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "1", "1", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "2", "2", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "3", "3", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "Shft", -NH_CMDPAD_FONT_NORMAL, NH_CELL_SHIFT, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for shift */ - { -1, "J", "J", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "K", "K", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "L", "L", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "M", "M", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "N", "N", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "O", "O", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "P", "P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "Q", "Q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "R", "R", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, + { -1, "1", "1", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "2", "2", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "3", "3", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "Shft", -NH_CMDPAD_FONT_NORMAL, NH_CELL_SHIFT, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for shift */ + { -1, "J", "J", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "K", "K", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "L", "L", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "M", "M", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "N", "N", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "O", "O", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "P", "P", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "Q", "Q", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "R", "R", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, - { -1, "<", "<", 10, NH_CELL_REG, 1, (void*)-1 }, - { -1, "0", "0", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, ">", ">", 12, NH_CELL_REG, 1, (void*)-1 }, - { -1, " ", "Ctrl", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CTRL, 2 , NULL }, - { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0 , NULL }, /* complement for CTRL */ - { -1, "S", "S", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "T", "T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "U", "U", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "V", "V", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "W", "W", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "X", "X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "Y", "Y", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "Z", "Z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 }, - { -1, "@", "@", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void*)-1 } + { -1, "<", "<", 10, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "0", "0", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, ">", ">", 12, NH_CELL_REG, 1, (void *) - 1 }, + { -1, " ", "Ctrl", -NH_CMDPAD_FONT_NORMAL, NH_CELL_CTRL, 2, NULL }, + { -1, " ", "", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 0, + NULL }, /* complement for CTRL */ + { -1, "S", "S", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "T", "T", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "U", "U", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "V", "V", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "W", "W", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "X", "X", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "Y", "Y", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "Z", "Z", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 }, + { -1, "@", "@", -NH_CMDPAD_FONT_NORMAL, NH_CELL_REG, 1, (void *) - 1 } }; #endif /* !WIN_CE_SMARTPHONE */ /*-------------------------------------------------------------------------*/ -HWND mswin_init_command_window () { - static int run_once = 0; - HWND ret; +HWND +mswin_init_command_window() +{ + static int run_once = 0; + HWND ret; - /* register window class */ - if( !run_once ) { - register_command_window_class(); - run_once = 1; - } + /* register window class */ + if (!run_once) { + register_command_window_class(); + run_once = 1; + } - /* create window */ - ret = CreateWindow( - szNHCmdWindowClass, /* registered class name */ - NULL, /* window name */ - WS_CHILD | WS_CLIPSIBLINGS, /* window style */ - 0, /* horizontal position of window - set it later */ - 0, /* vertical position of window - set it later */ - 0, /* window width - set it later */ - 0, /* window height - set it later*/ - GetNHApp()->hMainWnd, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL ); /* window-creation data */ - if( !ret ) { - panic("Cannot create command window"); - } - return ret; + /* create window */ + ret = CreateWindow( + szNHCmdWindowClass, /* registered class name */ + NULL, /* window name */ + WS_CHILD | WS_CLIPSIBLINGS, /* window style */ + 0, /* horizontal position of window - set it later */ + 0, /* vertical position of window - set it later */ + 0, /* window width - set it later */ + 0, /* window height - set it later*/ + GetNHApp()->hMainWnd, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL); /* window-creation data */ + if (!ret) { + panic("Cannot create command window"); + } + return ret; } /*-------------------------------------------------------------------------*/ /* calculate mimimum window size */ -void mswin_command_window_size (HWND hwnd, LPSIZE sz) +void +mswin_command_window_size(HWND hwnd, LPSIZE sz) { - SIZE cell_size; - PNHCmdWindow data; - data = (PNHCmdWindow)GetWindowLong(hwnd, GWL_USERDATA); - if( !data ) { - sz->cx = sz->cy = 0; - } else { - CalculateCellSize(hwnd, &cell_size, sz); - sz->cx = max( - cell_size.cx*nhcmdlayout_columns(data->layout_current)+2*GetSystemMetrics(SM_CXBORDER), - sz->cx - ); - sz->cy = max( - cell_size.cy*nhcmdlayout_rows(data->layout_current)+2*GetSystemMetrics(SM_CYBORDER), - sz->cy - ); - } + SIZE cell_size; + PNHCmdWindow data; + data = (PNHCmdWindow) GetWindowLong(hwnd, GWL_USERDATA); + if (!data) { + sz->cx = sz->cy = 0; + } else { + CalculateCellSize(hwnd, &cell_size, sz); + sz->cx = max(cell_size.cx * nhcmdlayout_columns(data->layout_current) + + 2 * GetSystemMetrics(SM_CXBORDER), + sz->cx); + sz->cy = max(cell_size.cy * nhcmdlayout_rows(data->layout_current) + + 2 * GetSystemMetrics(SM_CYBORDER), + sz->cy); + } } /*-------------------------------------------------------------------------*/ -void register_command_window_class() +void +register_command_window_class() { - WNDCLASS wcex; - PNHCmdLayout plt; - ZeroMemory( &wcex, sizeof(wcex)); + WNDCLASS wcex; + PNHCmdLayout plt; + ZeroMemory(&wcex, sizeof(wcex)); - /* window class */ - wcex.style = CS_NOCLOSE; - wcex.lpfnWndProc = (WNDPROC)NHCommandWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = mswin_get_brush(NHW_KEYPAD, MSWIN_COLOR_BG); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szNHCmdWindowClass; + /* window class */ + wcex.style = CS_NOCLOSE; + wcex.lpfnWndProc = (WNDPROC) NHCommandWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = mswin_get_brush(NHW_KEYPAD, MSWIN_COLOR_BG); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szNHCmdWindowClass; - if( !RegisterClass(&wcex) ) { - panic("cannot register Map window class"); - } + if (!RegisterClass(&wcex)) { + panic("cannot register Map window class"); + } - /* create default command set */ - nhcmdset_current = nhcmdset_default = nhcmdset_create(); + /* create default command set */ + nhcmdset_current = nhcmdset_default = nhcmdset_create(); #ifdef WIN_CE_SMARTPHONE - plt = nhcmdlayout_create("General", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_general); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("General", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_general); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("Movement", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_movement); - nhcmdset_add(nhcmdset_current, plt ); + plt = nhcmdlayout_create("Movement", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_movement); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("Attack", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_attack); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("Attack", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_attack); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("Item Handling", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_item_handling); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("Item Handling", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_item_handling); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("Game Controls", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_game); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("Game Controls", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_game); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("Advanced Movement", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_adv_movement); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("Advanced Movement", NH_CMDPAD_ROWS, + NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_adv_movement); + nhcmdset_add(nhcmdset_current, plt); plt = nhcmdlayout_create("Item Lookup", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_lookup); - nhcmdset_add(nhcmdset_current, plt); + nhcmdlayout_init(plt, cells_layout_lookup); + nhcmdset_add(nhcmdset_current, plt); - if( wizard ) { - plt = nhcmdlayout_create("Wizard Mode", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_wizard); - nhcmdset_add(nhcmdset_current, plt); - } + if (wizard) { + plt = + nhcmdlayout_create("Wizard Mode", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_wizard); + nhcmdset_add(nhcmdset_current, plt); + } -#else /* ! WIN_CE_SMARTPHONE */ - plt = nhcmdlayout_create("lowercase", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_mod1); - nhcmdset_add(nhcmdset_current, plt); +#else /* ! WIN_CE_SMARTPHONE */ + plt = nhcmdlayout_create("lowercase", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_mod1); + nhcmdset_add(nhcmdset_current, plt); - plt = nhcmdlayout_create("uppercase", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(plt, cells_layout_mod2); - nhcmdset_add(nhcmdset_current, plt); + plt = nhcmdlayout_create("uppercase", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); + nhcmdlayout_init(plt, cells_layout_mod2); + nhcmdset_add(nhcmdset_current, plt); #endif /* WIN_CE_SMARTPHONE */ } /*-------------------------------------------------------------------------*/ -LRESULT CALLBACK NHCommandWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHCommandWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHCmdWindow data; - int i; + PNHCmdWindow data; + int i; - switch (message) - { - case WM_CREATE: - onCreate( hWnd, wParam, lParam ); - break; + switch (message) { + case WM_CREATE: + onCreate(hWnd, wParam, lParam); + break; - case WM_PAINT: - onPaint(hWnd); - break; + case WM_PAINT: + onPaint(hWnd); + break; case WM_SIZE: - LayoutCmdWindow(hWnd); - break; + LayoutCmdWindow(hWnd); + break; - case WM_LBUTTONDOWN: - onMouseDown(hWnd, wParam, lParam); - return 0; + case WM_LBUTTONDOWN: + onMouseDown(hWnd, wParam, lParam); + return 0; - case WM_MOUSEMOVE: - /* proceed only if if have mouse focus (set in onMouseDown() - - left mouse button is pressed) */ - if( GetCapture()==hWnd ) { - onMouseMove(hWnd, wParam, lParam); - return 0; - } else { - return 1; - } - break; - - case WM_LBUTTONUP: - /* proceed only if if have mouse focus (set in onMouseDown()) */ - if( GetCapture()==hWnd ) { - onMouseUp(hWnd, wParam, lParam); - return 0; - } else { - return 1; - } - break; + case WM_MOUSEMOVE: + /* proceed only if if have mouse focus (set in onMouseDown() - + left mouse button is pressed) */ + if (GetCapture() == hWnd) { + onMouseMove(hWnd, wParam, lParam); + return 0; + } else { + return 1; + } + break; - case WM_DESTROY: - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - for(i=0; i<=NH_CMDPAD_FONT_MAX; i++ ) - if( data->font[i] ) DeleteObject(data->font[i]); - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - break; + case WM_LBUTTONUP: + /* proceed only if if have mouse focus (set in onMouseDown()) */ + if (GetCapture() == hWnd) { + onMouseUp(hWnd, wParam, lParam); + return 0; + } else { + return 1; + } + break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return FALSE; + case WM_DESTROY: + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + for (i = 0; i <= NH_CMDPAD_FONT_MAX; i++) + if (data->font[i]) + DeleteObject(data->font[i]); + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return FALSE; } /*-------------------------------------------------------------------------*/ -void onPaint(HWND hWnd) +void +onPaint(HWND hWnd) { - PNHCmdWindow data; - PAINTSTRUCT ps; - HDC hDC; - int x, y; - TCHAR wbuf[BUFSZ]; - HGDIOBJ saveFont; - BITMAP bm; - int cell_index; + PNHCmdWindow data; + PAINTSTRUCT ps; + HDC hDC; + int x, y; + TCHAR wbuf[BUFSZ]; + HGDIOBJ saveFont; + BITMAP bm; + int cell_index; - /* get window data */ - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); + /* get window data */ + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); - hDC = BeginPaint(hWnd, &ps); + hDC = BeginPaint(hWnd, &ps); - if( !IsRectEmpty(&ps.rcPaint) ) { - HGDIOBJ oldBr; - HBRUSH hbrPattern; - COLORREF OldBg, OldFg; - HPEN hPen; - HGDIOBJ hOldPen; + if (!IsRectEmpty(&ps.rcPaint)) { + HGDIOBJ oldBr; + HBRUSH hbrPattern; + COLORREF OldBg, OldFg; + HPEN hPen; + HGDIOBJ hOldPen; - saveFont = SelectObject(hDC, data->font[NH_CMDPAD_FONT_NORMAL]); - OldBg = SetBkColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_BG)); - OldFg = SetTextColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); + saveFont = SelectObject(hDC, data->font[NH_CMDPAD_FONT_NORMAL]); + OldBg = SetBkColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_BG)); + OldFg = + SetTextColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); - GetObject(data->images, sizeof(BITMAP), (LPVOID)&bm); + GetObject(data->images, sizeof(BITMAP), (LPVOID) &bm); - hbrPattern = CreatePatternBrush(data->images); - hPen = CreatePen(PS_SOLID, 1, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); + hbrPattern = CreatePatternBrush(data->images); + hPen = CreatePen(PS_SOLID, 1, + mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); - for( x=0, cell_index = 0; xlayout_current); x++ ) - for( y=0; ylayout_current); y++, cell_index++ ) { - RECT cell_rt; - POINT pt[5]; - PNHCmdPadCell p_cell_data; + for (x = 0, cell_index = 0; + x < nhcmdlayout_rows(data->layout_current); x++) + for (y = 0; y < nhcmdlayout_columns(data->layout_current); + y++, cell_index++) { + RECT cell_rt; + POINT pt[5]; + PNHCmdPadCell p_cell_data; - p_cell_data = nhcmdlayout_cell_direct(data->layout_current, cell_index); + p_cell_data = + nhcmdlayout_cell_direct(data->layout_current, cell_index); - /* calculate the cell rectangle */ - cell_rt.left = data->cells[cell_index].orig.x; - cell_rt.top = data->cells[cell_index].orig.y; - cell_rt.right = data->cells[cell_index].orig.x + data->cell_size.cx*p_cell_data->mult; - cell_rt.bottom = data->cells[cell_index].orig.y + data->cell_size.cy; + /* calculate the cell rectangle */ + cell_rt.left = data->cells[cell_index].orig.x; + cell_rt.top = data->cells[cell_index].orig.y; + cell_rt.right = data->cells[cell_index].orig.x + + data->cell_size.cx * p_cell_data->mult; + cell_rt.bottom = + data->cells[cell_index].orig.y + data->cell_size.cy; - /* draw border */ - hOldPen = SelectObject(hDC, hPen); - pt[0].x = cell_rt.left; - pt[0].y = cell_rt.top; - pt[1].x = cell_rt.right; - pt[1].y = cell_rt.top; - pt[2].x = cell_rt.right; - pt[2].y = cell_rt.bottom; - pt[3].x = cell_rt.left; - pt[3].y = cell_rt.bottom; - pt[4].x = cell_rt.left; - pt[4].y = cell_rt.top; - Polyline(hDC, pt, 5); - SelectObject(hDC, hOldPen); + /* draw border */ + hOldPen = SelectObject(hDC, hPen); + pt[0].x = cell_rt.left; + pt[0].y = cell_rt.top; + pt[1].x = cell_rt.right; + pt[1].y = cell_rt.top; + pt[2].x = cell_rt.right; + pt[2].y = cell_rt.bottom; + pt[3].x = cell_rt.left; + pt[3].y = cell_rt.bottom; + pt[4].x = cell_rt.left; + pt[4].y = cell_rt.top; + Polyline(hDC, pt, 5); + SelectObject(hDC, hOldPen); - /* calculate clipping rectangle for the text */ - cell_rt.left++; - cell_rt.top ++; - cell_rt.right--; - cell_rt.bottom--; + /* calculate clipping rectangle for the text */ + cell_rt.left++; + cell_rt.top++; + cell_rt.right--; + cell_rt.bottom--; - /* draw the cell text */ - if( p_cell_data->image<=0 ) { - SelectObject(hDC, data->font[ -p_cell_data->image ]); - DrawText(hDC, - NH_A2W(p_cell_data->text, wbuf, BUFSZ), - strlen(p_cell_data->text), - &cell_rt, - DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX - ); - } else { - /* draw bitmap */ - int bmOffset; - RECT bitmap_rt; + /* draw the cell text */ + if (p_cell_data->image <= 0) { + SelectObject(hDC, data->font[-p_cell_data->image]); + DrawText(hDC, NH_A2W(p_cell_data->text, wbuf, BUFSZ), + strlen(p_cell_data->text), &cell_rt, + DT_CENTER | DT_VCENTER | DT_SINGLELINE + | DT_NOPREFIX); + } else { + /* draw bitmap */ + int bmOffset; + RECT bitmap_rt; - bmOffset = (p_cell_data->image - 1)*bm.bmHeight; + bmOffset = (p_cell_data->image - 1) * bm.bmHeight; - bitmap_rt.left = ((cell_rt.left+cell_rt.right) - min(bm.bmHeight, (cell_rt.right-cell_rt.left)))/2; - bitmap_rt.top = ((cell_rt.bottom+cell_rt.top) - min(bm.bmHeight, (cell_rt.bottom-cell_rt.top)))/2; - bitmap_rt.right = bitmap_rt.left + min(bm.bmHeight, (cell_rt.right-cell_rt.left)); - bitmap_rt.bottom = bitmap_rt.top + min(bm.bmHeight, (cell_rt.bottom-cell_rt.top)); + bitmap_rt.left = + ((cell_rt.left + cell_rt.right) + - min(bm.bmHeight, (cell_rt.right - cell_rt.left))) + / 2; + bitmap_rt.top = + ((cell_rt.bottom + cell_rt.top) + - min(bm.bmHeight, (cell_rt.bottom - cell_rt.top))) + / 2; + bitmap_rt.right = + bitmap_rt.left + + min(bm.bmHeight, (cell_rt.right - cell_rt.left)); + bitmap_rt.bottom = + bitmap_rt.top + + min(bm.bmHeight, (cell_rt.bottom - cell_rt.top)); - SetBrushOrgEx(hDC, bitmap_rt.left-bmOffset, bitmap_rt.top, NULL); - oldBr = SelectObject(hDC, hbrPattern); - PatBlt( - hDC, - bitmap_rt.left, - bitmap_rt.top, - bitmap_rt.right-bitmap_rt.left, - bitmap_rt.bottom-bitmap_rt.top, - PATCOPY); - SelectObject(hDC, oldBr); - } + SetBrushOrgEx(hDC, bitmap_rt.left - bmOffset, + bitmap_rt.top, NULL); + oldBr = SelectObject(hDC, hbrPattern); + PatBlt(hDC, bitmap_rt.left, bitmap_rt.top, + bitmap_rt.right - bitmap_rt.left, + bitmap_rt.bottom - bitmap_rt.top, PATCOPY); + SelectObject(hDC, oldBr); + } - /* invert the cell if it is selected */ - if( data->cells[cell_index].state == NH_CST_CHECKED ) { - IntersectRect( &cell_rt, &cell_rt, &ps.rcPaint); - PatBlt( hDC, - cell_rt.left, - cell_rt.top, - cell_rt.right - cell_rt.left, - cell_rt.bottom - cell_rt.top, - DSTINVERT - ); - } - } + /* invert the cell if it is selected */ + if (data->cells[cell_index].state == NH_CST_CHECKED) { + IntersectRect(&cell_rt, &cell_rt, &ps.rcPaint); + PatBlt(hDC, cell_rt.left, cell_rt.top, + cell_rt.right - cell_rt.left, + cell_rt.bottom - cell_rt.top, DSTINVERT); + } + } - SetTextColor(hDC, OldFg); - SetBkColor(hDC, OldBg); - SelectObject(hDC, saveFont); - DeleteObject(hbrPattern); - DeleteObject(hPen); - } - EndPaint(hWnd, &ps); + SetTextColor(hDC, OldFg); + SetBkColor(hDC, OldBg); + SelectObject(hDC, saveFont); + DeleteObject(hbrPattern); + DeleteObject(hPen); + } + EndPaint(hWnd, &ps); } /*-------------------------------------------------------------------------*/ -void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHCmdWindow data; + PNHCmdWindow data; - /* set window data */ - data = (PNHCmdWindow)malloc(sizeof(NHCmdWindow)); - if( !data ) panic("out of memory"); + /* set window data */ + data = (PNHCmdWindow) malloc(sizeof(NHCmdWindow)); + if (!data) + panic("out of memory"); - ZeroMemory(data, sizeof(NHCmdWindow)); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + ZeroMemory(data, sizeof(NHCmdWindow)); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); - data->active_cell = -1; + data->active_cell = -1; - /* load images bitmap */ - data->images = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_KEYPAD)); - if( !data->images ) panic("cannot load keypad bitmap"); + /* load images bitmap */ + data->images = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_KEYPAD)); + if (!data->images) + panic("cannot load keypad bitmap"); - /* create default layouts */ - data->layout_current = 0; - data->layout_save = 0; - data->cells = 0; + /* create default layouts */ + data->layout_current = 0; + data->layout_save = 0; + data->cells = 0; #if defined(WIN_CE_SMARTPHONE) - data->layout_selected = nhcmdset_get(nhcmdset_current, 0); + data->layout_selected = nhcmdset_get(nhcmdset_current, 0); #endif - /* set default layout */ - SetCmdWindowLayout(hWnd, nhcmdset_get(nhcmdset_current, 0)); + /* set default layout */ + SetCmdWindowLayout(hWnd, nhcmdset_get(nhcmdset_current, 0)); } /*-------------------------------------------------------------------------*/ -void LayoutCmdWindow(HWND hWnd) +void +LayoutCmdWindow(HWND hWnd) { - RECT clrt; - SIZE windowSize; - PNHCmdWindow data; - int i, j; - int x, y; - LOGFONT lgfnt; - int index; + RECT clrt; + SIZE windowSize; + PNHCmdWindow data; + int i, j; + int x, y; + LOGFONT lgfnt; + int index; - GetClientRect(hWnd, &clrt); - if( IsRectEmpty(&clrt) ) return; + GetClientRect(hWnd, &clrt); + if (IsRectEmpty(&clrt)) + return; - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( !data->layout_current ) return; + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (!data->layout_current) + return; - /* calculate cell size */ - windowSize.cx = clrt.right-clrt.left; - windowSize.cy = clrt.bottom-clrt.top; - CalculateCellSize(hWnd, &data->cell_size, &windowSize); - - /* initialize display cells aray */ - x = 0; - y = 0; - for( i=0, index=0; ilayout_current); i++ ) { - for( j=0; jlayout_current); j++, index++ ) { - data->cells[index].orig.x = x; - data->cells[index].orig.y = y; - data->cells[index].type = nhcmdlayout_cell_direct(data->layout_current, index)->type; + /* calculate cell size */ + windowSize.cx = clrt.right - clrt.left; + windowSize.cy = clrt.bottom - clrt.top; + CalculateCellSize(hWnd, &data->cell_size, &windowSize); - switch(data->cells[index].type) { - case NH_CELL_CTRL: - data->cells[index].state = data->is_ctrl? NH_CST_CHECKED : 0; - break; - case NH_CELL_CAP: - data->cells[index].state = data->is_caps? NH_CST_CHECKED : 0; - break; - case NH_CELL_SHIFT: - data->cells[index].state = data->is_shift? NH_CST_CHECKED : 0; - break; - default: - data->cells[index].state = 0; - } + /* initialize display cells aray */ + x = 0; + y = 0; + for (i = 0, index = 0; i < nhcmdlayout_rows(data->layout_current); i++) { + for (j = 0; j < nhcmdlayout_columns(data->layout_current); + j++, index++) { + data->cells[index].orig.x = x; + data->cells[index].orig.y = y; + data->cells[index].type = + nhcmdlayout_cell_direct(data->layout_current, index)->type; - x += data->cell_size.cx * nhcmdlayout_cell_direct(data->layout_current, index)->mult; - } - x = 0; - y += data->cell_size.cy; - } + switch (data->cells[index].type) { + case NH_CELL_CTRL: + data->cells[index].state = data->is_ctrl ? NH_CST_CHECKED : 0; + break; + case NH_CELL_CAP: + data->cells[index].state = data->is_caps ? NH_CST_CHECKED : 0; + break; + case NH_CELL_SHIFT: + data->cells[index].state = + data->is_shift ? NH_CST_CHECKED : 0; + break; + default: + data->cells[index].state = 0; + } - /* create font for display cell text */ - for(i=0; i<=NH_CMDPAD_FONT_MAX; i++ ) - if( data->font[i] ) DeleteObject(data->font[i]); + x += data->cell_size.cx + * nhcmdlayout_cell_direct(data->layout_current, index)->mult; + } + x = 0; + y += data->cell_size.cy; + } - ZeroMemory( &lgfnt, sizeof(lgfnt) ); - lgfnt.lfHeight = data->cell_size.cy; // height of font - lgfnt.lfWidth = 0; // average character width - lgfnt.lfEscapement = 0; // angle of escapement - lgfnt.lfOrientation = 0; // base-line orientation angle - lgfnt.lfWeight = FW_NORMAL; // font weight - lgfnt.lfItalic = FALSE; // italic attribute option - lgfnt.lfUnderline = FALSE; // underline attribute option - lgfnt.lfStrikeOut = FALSE; // strikeout attribute option - lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier - lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision - lgfnt.lfClipPrecision = CLIP_CHARACTER_PRECIS; // clipping precision - lgfnt.lfQuality = DEFAULT_QUALITY; // output quality - if( iflags.wc_font_message && - *iflags.wc_font_message ) { - lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family - NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE); - } else { - lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family - } - data->font[NH_CMDPAD_FONT_NORMAL] = CreateFontIndirect(&lgfnt); + /* create font for display cell text */ + for (i = 0; i <= NH_CMDPAD_FONT_MAX; i++) + if (data->font[i]) + DeleteObject(data->font[i]); - InvalidateRect(hWnd, NULL, TRUE); + ZeroMemory(&lgfnt, sizeof(lgfnt)); + lgfnt.lfHeight = data->cell_size.cy; // height of font + lgfnt.lfWidth = 0; // average character width + lgfnt.lfEscapement = 0; // angle of escapement + lgfnt.lfOrientation = 0; // base-line orientation angle + lgfnt.lfWeight = FW_NORMAL; // font weight + lgfnt.lfItalic = FALSE; // italic attribute option + lgfnt.lfUnderline = FALSE; // underline attribute option + lgfnt.lfStrikeOut = FALSE; // strikeout attribute option + lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier + lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision + lgfnt.lfClipPrecision = CLIP_CHARACTER_PRECIS; // clipping precision + lgfnt.lfQuality = DEFAULT_QUALITY; // output quality + if (iflags.wc_font_message && *iflags.wc_font_message) { + lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family + NH_A2W(iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE); + } else { + lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family + } + data->font[NH_CMDPAD_FONT_NORMAL] = CreateFontIndirect(&lgfnt); + + InvalidateRect(hWnd, NULL, TRUE); } /*-------------------------------------------------------------------------*/ -void SetCmdWindowLayout(HWND hWnd, PNHCmdLayout layout) +void +SetCmdWindowLayout(HWND hWnd, PNHCmdLayout layout) { - PNHCmdWindow data; - int size; + PNHCmdWindow data; + int size; - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( data->layout_current == layout ) return; + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data->layout_current == layout) + return; - data->layout_current = layout; - size = sizeof(NHCmdPadLayoutCell)*nhcmdlayout_rows(layout)*nhcmdlayout_columns(layout); - data->cells = (PNHCmdPadLayoutCell)realloc(data->cells, size); - ZeroMemory(data->cells, size); - LayoutCmdWindow(hWnd); + data->layout_current = layout; + size = sizeof(NHCmdPadLayoutCell) * nhcmdlayout_rows(layout) + * nhcmdlayout_columns(layout); + data->cells = (PNHCmdPadLayoutCell) realloc(data->cells, size); + ZeroMemory(data->cells, size); + LayoutCmdWindow(hWnd); } /*-------------------------------------------------------------------------*/ -void onMouseDown(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMouseDown(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHCmdWindow data; - POINT mpt; + PNHCmdWindow data; + POINT mpt; - /* get mouse coordinates */ - mpt.x = LOWORD(lParam); - mpt.y = HIWORD(lParam); + /* get mouse coordinates */ + mpt.x = LOWORD(lParam); + mpt.y = HIWORD(lParam); - /* map mouse coordinates to the display cell */ - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - data->active_cell = CellFromPoint(data, mpt); - if( data->active_cell==-1 ) return; + /* map mouse coordinates to the display cell */ + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + data->active_cell = CellFromPoint(data, mpt); + if (data->active_cell == -1) + return; - /* set mouse focus to the current window */ - SetCapture(hWnd); + /* set mouse focus to the current window */ + SetCapture(hWnd); - /* invert the selection */ - HighlightCell(hWnd, data->active_cell, (data->cells[data->active_cell].state!=NH_CST_CHECKED) ); + /* invert the selection */ + HighlightCell(hWnd, data->active_cell, + (data->cells[data->active_cell].state != NH_CST_CHECKED)); } /*-------------------------------------------------------------------------*/ -void onMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHCmdWindow data; - POINT mpt; - int newActiveCell; + PNHCmdWindow data; + POINT mpt; + int newActiveCell; - /* get mouse coordinates */ - mpt.x = LOWORD(lParam); - mpt.y = HIWORD(lParam); + /* get mouse coordinates */ + mpt.x = LOWORD(lParam); + mpt.y = HIWORD(lParam); - /* map mouse coordinates to the display cell */ - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - newActiveCell = CellFromPoint(data, mpt); - if( data->active_cell == -1 ) return; + /* map mouse coordinates to the display cell */ + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + newActiveCell = CellFromPoint(data, mpt); + if (data->active_cell == -1) + return; - /* if mouse is within orginal display cell - select the cell otherwise - clear the selection */ - switch( nhcmdlayout_cell_direct(data->layout_current, data->active_cell)->type ) { - case NH_CELL_REG: - HighlightCell(hWnd, data->active_cell, - (newActiveCell==data->active_cell) ); - break; + /* if mouse is within orginal display cell - select the cell otherwise + clear the selection */ + switch (nhcmdlayout_cell_direct(data->layout_current, data->active_cell) + ->type) { + case NH_CELL_REG: + HighlightCell(hWnd, data->active_cell, + (newActiveCell == data->active_cell)); + break; - case NH_CELL_CTRL: - HighlightCell(hWnd, data->active_cell, - ((newActiveCell==data->active_cell)? !data->is_ctrl : data->is_ctrl) ); - break; + case NH_CELL_CTRL: + HighlightCell(hWnd, data->active_cell, + ((newActiveCell == data->active_cell) ? !data->is_ctrl + : data->is_ctrl)); + break; - case NH_CELL_CAP: - HighlightCell(hWnd, data->active_cell, - ((newActiveCell==data->active_cell)? !data->is_caps : data->is_caps) ); - break; - } + case NH_CELL_CAP: + HighlightCell(hWnd, data->active_cell, + ((newActiveCell == data->active_cell) ? !data->is_caps + : data->is_caps)); + break; + } } /*-------------------------------------------------------------------------*/ -void onMouseUp(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMouseUp(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHCmdWindow data; + PNHCmdWindow data; - /* release mouse capture */ - ReleaseCapture(); + /* release mouse capture */ + ReleaseCapture(); - /* get active display cell */ - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( data->active_cell == -1 ) return; + /* get active display cell */ + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data->active_cell == -1) + return; - ActivateCell(hWnd, data->active_cell); + ActivateCell(hWnd, data->active_cell); - data->active_cell = -1; + data->active_cell = -1; } /*-------------------------------------------------------------------------*/ -void ActivateCell(HWND hWnd, int cell) +void +ActivateCell(HWND hWnd, int cell) { - PNHCmdWindow data; - PNHCmdPadCell p_cell_data; - int i; + PNHCmdWindow data; + PNHCmdPadCell p_cell_data; + int i; - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( !data ) return; - p_cell_data = nhcmdlayout_cell_direct(data->layout_current, cell); + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (!data) + return; + p_cell_data = nhcmdlayout_cell_direct(data->layout_current, cell); - /* act depending on the cell type: - CAPS - change layout - CTRL - modify CTRL status - REG - place keyboard event on the nethack input queue - */ - switch( p_cell_data->type ) { - case NH_CELL_REG: - if( data->is_ctrl ) { - PushNethackCommand(p_cell_data->f_char, 1); + /* act depending on the cell type: + CAPS - change layout + CTRL - modify CTRL status + REG - place keyboard event on the nethack input queue + */ + switch (p_cell_data->type) { + case NH_CELL_REG: + if (data->is_ctrl) { + PushNethackCommand(p_cell_data->f_char, 1); - data->is_ctrl = 0; - for( i=0; ilayout_current)*nhcmdlayout_columns(data->layout_current); i++ ) { - if( nhcmdlayout_cell_direct(data->layout_current, i)->type == NH_CELL_CTRL ) { - HighlightCell(hWnd, i, data->is_ctrl); - } - } - } else { - PushNethackCommand(p_cell_data->f_char, 0); - } - HighlightCell(hWnd, cell, FALSE); + data->is_ctrl = 0; + for (i = 0; i < nhcmdlayout_rows(data->layout_current) + * nhcmdlayout_columns(data->layout_current); + i++) { + if (nhcmdlayout_cell_direct(data->layout_current, i)->type + == NH_CELL_CTRL) { + HighlightCell(hWnd, i, data->is_ctrl); + } + } + } else { + PushNethackCommand(p_cell_data->f_char, 0); + } + HighlightCell(hWnd, cell, FALSE); - // select a new layout if present - i = (int)p_cell_data->data; - if( i==-1 ) { - if( data->layout_save ) SetCmdWindowLayout(hWnd, data->layout_save); - data->layout_save = NULL; - } else { - if( !data->layout_save ) data->layout_save = data->layout_current; - SetCmdWindowLayout(hWnd, nhcmdset_get(nhcmdset_current, i)); - } + // select a new layout if present + i = (int) p_cell_data->data; + if (i == -1) { + if (data->layout_save) + SetCmdWindowLayout(hWnd, data->layout_save); + data->layout_save = NULL; + } else { + if (!data->layout_save) + data->layout_save = data->layout_current; + SetCmdWindowLayout(hWnd, nhcmdset_get(nhcmdset_current, i)); + } - if( !data->is_shift ) break; - // else fall through and reset the shift + if (!data->is_shift) + break; + // else fall through and reset the shift - case NH_CELL_SHIFT: - data->is_shift = !data->is_shift; - SetCmdWindowLayout( - hWnd, - (data->is_shift ^ data->is_caps)? nhcmdset_get(nhcmdset_current, 1) : nhcmdset_get(nhcmdset_current, 0) - ); - data->cells[cell].state = data->is_shift? NH_CST_CHECKED : 0; - InvalidateRect(hWnd, NULL, TRUE); - break; + case NH_CELL_SHIFT: + data->is_shift = !data->is_shift; + SetCmdWindowLayout(hWnd, (data->is_shift ^ data->is_caps) + ? nhcmdset_get(nhcmdset_current, 1) + : nhcmdset_get(nhcmdset_current, 0)); + data->cells[cell].state = data->is_shift ? NH_CST_CHECKED : 0; + InvalidateRect(hWnd, NULL, TRUE); + break; - case NH_CELL_CTRL: - data->is_ctrl = !data->is_ctrl; - HighlightCell(hWnd, cell, data->is_ctrl); - break; + case NH_CELL_CTRL: + data->is_ctrl = !data->is_ctrl; + HighlightCell(hWnd, cell, data->is_ctrl); + break; - case NH_CELL_CAP: - data->is_caps = !data->is_caps; - SetCmdWindowLayout( - hWnd, - (data->is_shift ^ data->is_caps)? nhcmdset_get(nhcmdset_current, 1) : nhcmdset_get(nhcmdset_current, 0) - ); - data->cells[cell].state = data->is_caps? NH_CST_CHECKED : 0; - InvalidateRect(hWnd, NULL, TRUE); - break; + case NH_CELL_CAP: + data->is_caps = !data->is_caps; + SetCmdWindowLayout(hWnd, (data->is_shift ^ data->is_caps) + ? nhcmdset_get(nhcmdset_current, 1) + : nhcmdset_get(nhcmdset_current, 0)); + data->cells[cell].state = data->is_caps ? NH_CST_CHECKED : 0; + InvalidateRect(hWnd, NULL, TRUE); + break; - case NH_CELL_LAYOUT_NEW: { - PNHCmdLayout pLayout; + case NH_CELL_LAYOUT_NEW: { + PNHCmdLayout pLayout; - HighlightCell(hWnd, cell, FALSE); + HighlightCell(hWnd, cell, FALSE); - pLayout = (PNHCmdLayout)p_cell_data->data; - if( pLayout ) { - SetCmdWindowLayout(hWnd, pLayout); - } - } break; - - case NH_CELL_LAYOUT_MENU: { - winid wid; - int i; - anything any; - menu_item* selected = 0; - PNHCmdSet pSet; + pLayout = (PNHCmdLayout) p_cell_data->data; + if (pLayout) { + SetCmdWindowLayout(hWnd, pLayout); + } + } break; - HighlightCell(hWnd, cell, FALSE); + case NH_CELL_LAYOUT_MENU: { + winid wid; + int i; + anything any; + menu_item *selected = 0; + PNHCmdSet pSet; - pSet = (PNHCmdSet)p_cell_data->data; - if( !pSet ) pSet = nhcmdset_default; + HighlightCell(hWnd, cell, FALSE); - wid = mswin_create_nhwindow(NHW_MENU); - mswin_start_menu(wid); - for( i=0; idata; + if (!pSet) + pSet = nhcmdset_default; - if( i==1 ) { + wid = mswin_create_nhwindow(NHW_MENU); + mswin_start_menu(wid); + for (i = 0; i < nhcmdset_count(pSet); i++) { + any.a_void = nhcmdset_get(pSet, i); + mswin_add_menu(wid, NO_GLYPH, &any, 'a' + i, 0, ATR_NONE, + nhcmdset_get_name(pSet, i), FALSE); + } + mswin_end_menu(wid, "Select keypad layout"); + i = select_menu(wid, PICK_ONE, &selected); + mswin_destroy_nhwindow(wid); + + if (i == 1) { #if defined(WIN_CE_SMARTPHONE) - data->layout_selected = (PNHCmdLayout)selected[0].item.a_void; + data->layout_selected = (PNHCmdLayout) selected[0].item.a_void; #endif - SetCmdWindowLayout(hWnd, (PNHCmdLayout)selected[0].item.a_void ); - } - } break; - - } + SetCmdWindowLayout(hWnd, (PNHCmdLayout) selected[0].item.a_void); + } + } break; + } } /*-------------------------------------------------------------------------*/ -int CellFromPoint(PNHCmdWindow data, POINT pt ) +int +CellFromPoint(PNHCmdWindow data, POINT pt) { - int i; - for( i=0; ilayout_current)*nhcmdlayout_columns(data->layout_current); i++ ) { - RECT cell_rt; - cell_rt.left = data->cells[i].orig.x; - cell_rt.top = data->cells[i].orig.y; - cell_rt.right = data->cells[i].orig.x + data->cell_size.cx*nhcmdlayout_cell_direct(data->layout_current, i)->mult; - cell_rt.bottom = data->cells[i].orig.y + data->cell_size.cy; - if( PtInRect(&cell_rt, pt) ) return i; - } - return -1; + int i; + for (i = 0; i < nhcmdlayout_rows(data->layout_current) + * nhcmdlayout_columns(data->layout_current); + i++) { + RECT cell_rt; + cell_rt.left = data->cells[i].orig.x; + cell_rt.top = data->cells[i].orig.y; + cell_rt.right = + data->cells[i].orig.x + + data->cell_size.cx + * nhcmdlayout_cell_direct(data->layout_current, i)->mult; + cell_rt.bottom = data->cells[i].orig.y + data->cell_size.cy; + if (PtInRect(&cell_rt, pt)) + return i; + } + return -1; } /*-------------------------------------------------------------------------*/ -void CalculateCellSize(HWND hWnd, LPSIZE pSize, LPSIZE pWindowSize) +void +CalculateCellSize(HWND hWnd, LPSIZE pSize, LPSIZE pWindowSize) { - HDC hdc; - PNHCmdWindow data; - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( !data ) return; + HDC hdc; + PNHCmdWindow data; + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (!data) + return; - hdc = GetDC(hWnd); - - /* if windows size is specified - attempt ro stretch cells across - the the window size. If not - make default cell size based on - 10 points font. Make sure that cell cesize does not exceeds 20 points */ - if( pWindowSize->cx>0 ) - pSize->cx = pWindowSize->cx/nhcmdlayout_columns(data->layout_current); - else - pSize->cx = 10*GetDeviceCaps(hdc, LOGPIXELSX)/72; - pSize->cx = min(pSize->cx, 20*GetDeviceCaps(hdc, LOGPIXELSX)/72 ); + hdc = GetDC(hWnd); - if( pWindowSize->cy>0 ) - pSize->cy = pWindowSize->cy/nhcmdlayout_rows(data->layout_current); - else - pSize->cy = 10*GetDeviceCaps(hdc, LOGPIXELSY)/72; - pSize->cy = min(pSize->cy, 20*GetDeviceCaps(hdc, LOGPIXELSY)/72 ); + /* if windows size is specified - attempt ro stretch cells across + the the window size. If not - make default cell size based on + 10 points font. Make sure that cell cesize does not exceeds 20 points + */ + if (pWindowSize->cx > 0) + pSize->cx = + pWindowSize->cx / nhcmdlayout_columns(data->layout_current); + else + pSize->cx = 10 * GetDeviceCaps(hdc, LOGPIXELSX) / 72; + pSize->cx = min(pSize->cx, 20 * GetDeviceCaps(hdc, LOGPIXELSX) / 72); - ReleaseDC(hWnd, hdc); + if (pWindowSize->cy > 0) + pSize->cy = pWindowSize->cy / nhcmdlayout_rows(data->layout_current); + else + pSize->cy = 10 * GetDeviceCaps(hdc, LOGPIXELSY) / 72; + pSize->cy = min(pSize->cy, 20 * GetDeviceCaps(hdc, LOGPIXELSY) / 72); + + ReleaseDC(hWnd, hdc); } /*-------------------------------------------------------------------------*/ -void HighlightCell(HWND hWnd, int cell, BOOL isSelected) +void +HighlightCell(HWND hWnd, int cell, BOOL isSelected) { - HDC hDC; - PNHCmdWindow data; - int prevState; + HDC hDC; + PNHCmdWindow data; + int prevState; - data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); - prevState = data->cells[cell].state; - data->cells[cell].state = (isSelected)? NH_CST_CHECKED : 0; + data = (PNHCmdWindow) GetWindowLong(hWnd, GWL_USERDATA); + prevState = data->cells[cell].state; + data->cells[cell].state = (isSelected) ? NH_CST_CHECKED : 0; - if( prevState!=data->cells[cell].state ) { - hDC = GetDC(hWnd); - PatBlt( hDC, - data->cells[cell].orig.x+1, - data->cells[cell].orig.y+1, - data->cell_size.cx*nhcmdlayout_cell_direct(data->layout_current, cell)->mult - 2, - data->cell_size.cy - 2, - DSTINVERT - ); - ReleaseDC(hWnd, hDC); - } + if (prevState != data->cells[cell].state) { + hDC = GetDC(hWnd); + PatBlt(hDC, data->cells[cell].orig.x + 1, + data->cells[cell].orig.y + 1, + data->cell_size.cx + * nhcmdlayout_cell_direct(data->layout_current, cell) + ->mult + - 2, + data->cell_size.cy - 2, DSTINVERT); + ReleaseDC(hWnd, hDC); + } } /*-------------------------------------------------------------------------*/ -void PushNethackCommand( const char* cmd_char_str, int is_ctrl ) +void +PushNethackCommand(const char *cmd_char_str, int is_ctrl) { - while( *cmd_char_str ) { - if( is_ctrl ) { NHEVENT_KBD( C(*cmd_char_str) ); } - else { NHEVENT_KBD( *cmd_char_str ); } - cmd_char_str++; - } + while (*cmd_char_str) { + if (is_ctrl) { + NHEVENT_KBD(C(*cmd_char_str)); + } else { + NHEVENT_KBD(*cmd_char_str); + } + cmd_char_str++; + } } /*-------------------------------------------------------------------------*/ /*------------------- keyboard keys layout functions ----------------------*/ /*-------------------------------------------------------------------------*/ -PNHCmdLayout nhcmdlayout_create(const char* name, int rows, int columns) +PNHCmdLayout +nhcmdlayout_create(const char *name, int rows, int columns) { - PNHCmdLayout p; - int i; + PNHCmdLayout p; + int i; - i = sizeof(NHCmdLayout)+rows*columns*sizeof(NHCmdPadCell); - p = (PNHCmdLayout)malloc(i); - ZeroMemory(p, i); - p->rows = rows; - p->columns = columns; - strncpy(p->name, name, sizeof(p->name)-1); - for(i=0; icells[i].cmd_code = -1; - p->cells[i].image = -NH_CMDPAD_FONT_NORMAL; - p->cells[i].type = 1; - p->cells[i].mult = 1; - } - return p; + i = sizeof(NHCmdLayout) + rows * columns * sizeof(NHCmdPadCell); + p = (PNHCmdLayout) malloc(i); + ZeroMemory(p, i); + p->rows = rows; + p->columns = columns; + strncpy(p->name, name, sizeof(p->name) - 1); + for (i = 0; i < rows * columns; i++) { + p->cells[i].cmd_code = -1; + p->cells[i].image = -NH_CMDPAD_FONT_NORMAL; + p->cells[i].type = 1; + p->cells[i].mult = 1; + } + return p; } /*-------------------------------------------------------------------------*/ -void nhcmdlayout_init( PNHCmdLayout p, PNHCmdPadCell cells ) +void +nhcmdlayout_init(PNHCmdLayout p, PNHCmdPadCell cells) { - memcpy(p->cells, cells, p->rows*p->columns*sizeof(NHCmdPadCell)); + memcpy(p->cells, cells, p->rows * p->columns * sizeof(NHCmdPadCell)); } -void nhcmdlayout_destroy(PNHCmdLayout p) +void +nhcmdlayout_destroy(PNHCmdLayout p) { - free(p); + free(p); } /*-------------------------------------------------------------------------*/ /*----------------- keyboard keys layout set functions --------------------*/ /*-------------------------------------------------------------------------*/ -PNHCmdSet nhcmdset_create() +PNHCmdSet +nhcmdset_create() { - PNHCmdSet p; - p = (PNHCmdSet)malloc(sizeof(NHCmdSet)); - ZeroMemory(p, sizeof(NHCmdSet)); - return p; + PNHCmdSet p; + p = (PNHCmdSet) malloc(sizeof(NHCmdSet)); + ZeroMemory(p, sizeof(NHCmdSet)); + return p; } /*-------------------------------------------------------------------------*/ -int nhcmdset_count(PNHCmdSet p) +int +nhcmdset_count(PNHCmdSet p) { - assert(p); - return p->count; + assert(p); + return p->count; } /*-------------------------------------------------------------------------*/ -PNHCmdLayout nhcmdset_get( PNHCmdSet p, int index ) +PNHCmdLayout +nhcmdset_get(PNHCmdSet p, int index) { - assert(p); - assert(index>=0 && indexcount); - return p->elements[index].layout; + assert(p); + assert(index >= 0 && index < p->count); + return p->elements[index].layout; } /*-------------------------------------------------------------------------*/ -const char* nhcmdset_get_name( PNHCmdSet p, int index ) +const char * +nhcmdset_get_name(PNHCmdSet p, int index) { - assert(p); - assert(index>=0 && indexcount); - return p->elements[index].layout->name; + assert(p); + assert(index >= 0 && index < p->count); + return p->elements[index].layout->name; } /*-------------------------------------------------------------------------*/ -void nhcmdset_add( PNHCmdSet p, PNHCmdLayout layout ) +void +nhcmdset_add(PNHCmdSet p, PNHCmdLayout layout) { - assert(p); - assert(p->countelements[p->count].layout = layout; - p->elements[p->count].free_on_destroy = 0; - p->count++; + assert(p); + assert(p->count < NH_CMDSET_MAXSIZE); + p->elements[p->count].layout = layout; + p->elements[p->count].free_on_destroy = 0; + p->count++; } /*-------------------------------------------------------------------------*/ -void nhcmdset_destroy(PNHCmdSet p) +void +nhcmdset_destroy(PNHCmdSet p) { - int i=0; - assert(p); - for(i=0; icount; i++) { - if( p->elements[i].free_on_destroy ) { - nhcmdlayout_destroy( p->elements[i].layout ); - } - } - free(p); + int i = 0; + assert(p); + for (i = 0; i < p->count; i++) { + if (p->elements[i].free_on_destroy) { + nhcmdlayout_destroy(p->elements[i].layout); + } + } + free(p); } /*-------------------------------------------------------------------------*/ - #if defined(WIN_CE_SMARTPHONE) /* special keypad input handling for SmartPhone the phone keypad maps to VK_* as shown below. @@ -1241,187 +1331,202 @@ void nhcmdset_destroy(PNHCmdSet p) VK_TPOWER, VK_TVOLUMEUP, VK_TVOLUMEDOWN VK_TFLIP */ -BOOL NHSPhoneTranslateKbdMessage(WPARAM wParam, LPARAM lParam, BOOL keyDown) +BOOL +NHSPhoneTranslateKbdMessage(WPARAM wParam, LPARAM lParam, BOOL keyDown) { - PNHCmdWindow data; - int index = -1; + PNHCmdWindow data; + int index = -1; - /* get window data */ - data = (PNHCmdWindow)GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); - if( !data ) return FALSE; + /* get window data */ + data = (PNHCmdWindow) GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); + if (!data) + return FALSE; - switch (wParam) { - case VK_T0: - index = 10; - break; + switch (wParam) { + case VK_T0: + index = 10; + break; - case VK_T1: - index = 0; - break; + case VK_T1: + index = 0; + break; - case VK_T2: - index = 1; - break; + case VK_T2: + index = 1; + break; - case VK_T3: - index = 2; - break; + case VK_T3: + index = 2; + break; - case VK_T4: - index = 3; - break; + case VK_T4: + index = 3; + break; - case VK_T5: - index = 4; - break; + case VK_T5: + index = 4; + break; - case VK_T6: - index = 5; - break; + case VK_T6: + index = 5; + break; - case VK_T7: - index = 6; - break; + case VK_T7: + index = 6; + break; - case VK_T8: - index = 7; - break; + case VK_T8: + index = 7; + break; - case VK_T9: - index = 8; - break; + case VK_T9: + index = 8; + break; - case VK_TSTAR: - index = 9; - break; - - case VK_TPOUND: - index = 11; - break; - } + case VK_TSTAR: + index = 9; + break; - if( index>=0 ) { - HighlightCell(GetNHApp()->hCmdWnd, index, keyDown); - if( keyDown ) ActivateCell(GetNHApp()->hCmdWnd, index); - return TRUE; - } else { - return FALSE; - } + case VK_TPOUND: + index = 11; + break; + } + + if (index >= 0) { + HighlightCell(GetNHApp()->hCmdWnd, index, keyDown); + if (keyDown) + ActivateCell(GetNHApp()->hCmdWnd, index); + return TRUE; + } else { + return FALSE; + } } /*-------------------------------------------------------------------------*/ -void NHSPhoneSetKeypadFromString(const char* str) +void +NHSPhoneSetKeypadFromString(const char *str) { - PNHCmdWindow data; - PNHCmdSet p = 0; - PNHCmdLayout layout_prev = 0; - PNHCmdLayout layout_cur = 0; - char buf[2][BUFSZ]; - int i, lcount; - char *s; + PNHCmdWindow data; + PNHCmdSet p = 0; + PNHCmdLayout layout_prev = 0; + PNHCmdLayout layout_cur = 0; + char buf[2][BUFSZ]; + int i, lcount; + char *s; - assert(NH_CMDPAD_ROWS==4); + assert(NH_CMDPAD_ROWS == 4); - data = (PNHCmdWindow)GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); - if( !data ) return; + data = (PNHCmdWindow) GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); + if (!data) + return; - p = nhcmdset_create(); + p = nhcmdset_create(); - ZeroMemory(buf, sizeof(buf)); - if( sscanf(str, "%s or %s", buf[1], buf[0])!=2 ) { - ZeroMemory(buf, sizeof(buf)); - strncpy(buf[0], str, sizeof(buf[0])-1); - } + ZeroMemory(buf, sizeof(buf)); + if (sscanf(str, "%s or %s", buf[1], buf[0]) != 2) { + ZeroMemory(buf, sizeof(buf)); + strncpy(buf[0], str, sizeof(buf[0]) - 1); + } - lcount = 10; /* create new layout on the first iteration */ - for(i=0; i<2; i++) { - s = buf[i]; - while( *s ) { - char c_start, c_end, c_char; + lcount = 10; /* create new layout on the first iteration */ + for (i = 0; i < 2; i++) { + s = buf[i]; + while (*s) { + char c_start, c_end, c_char; - /* parse character ranges */ - if( isalnum( (c_start=s[0]) ) && - s[1]=='-' && - isalnum( (c_end=s[2]) ) ) { - s += 2; - } else { - c_start = c_end = *s; - } - - for( c_char=c_start; c_char<=c_end; c_char++ ) { - if( lcount>=10 ) { - /* create layout */ - lcount = 0; - layout_prev = layout_cur; - layout_cur = nhcmdlayout_create("noname", NH_CMDPAD_ROWS, NH_CMDPAD_COLS); - nhcmdlayout_init(layout_cur, cells_layout_menu); + /* parse character ranges */ + if (isalnum((c_start = s[0])) && s[1] == '-' + && isalnum((c_end = s[2]))) { + s += 2; + } else { + c_start = c_end = *s; + } - nhcmdlayout_cell(layout_cur, 3, 0)->data = layout_prev; - nhcmdlayout_cell(layout_cur, 3, 2)->data = 0; + for (c_char = c_start; c_char <= c_end; c_char++) { + if (lcount >= 10) { + /* create layout */ + lcount = 0; + layout_prev = layout_cur; + layout_cur = nhcmdlayout_create("noname", NH_CMDPAD_ROWS, + NH_CMDPAD_COLS); + nhcmdlayout_init(layout_cur, cells_layout_menu); - nhcmdset_add( p, layout_cur ); - p->elements[p->count-1].free_on_destroy = 1; + nhcmdlayout_cell(layout_cur, 3, 0)->data = layout_prev; + nhcmdlayout_cell(layout_cur, 3, 2)->data = 0; - if( layout_prev ) { - nhcmdlayout_cell(layout_prev, 3, 2)->data = layout_cur; - } - } + nhcmdset_add(p, layout_cur); + p->elements[p->count - 1].free_on_destroy = 1; - if( lcount==9 ) lcount=10; // skip '#' - nhcmdlayout_cell_direct(layout_cur, lcount)->f_char[0] = c_char; - if( c_char == '\033' ) { - strcpy(nhcmdlayout_cell_direct(layout_cur, lcount)->text, "esc"); - nhcmdlayout_cell_direct(layout_cur, lcount)->image = 14; /* 14 is a ESC symbol in IDB_KEYPAD */ - } else { - nhcmdlayout_cell_direct(layout_cur, lcount)->text[0] = c_char; - nhcmdlayout_cell_direct(layout_cur, lcount)->text[1] = '\x0'; - } + if (layout_prev) { + nhcmdlayout_cell(layout_prev, 3, 2)->data = + layout_cur; + } + } - /* increment character count in the current layout */ - lcount++; - } + if (lcount == 9) + lcount = 10; // skip '#' + nhcmdlayout_cell_direct(layout_cur, lcount)->f_char[0] = + c_char; + if (c_char == '\033') { + strcpy(nhcmdlayout_cell_direct(layout_cur, lcount)->text, + "esc"); + nhcmdlayout_cell_direct(layout_cur, lcount)->image = + 14; /* 14 is a ESC symbol in IDB_KEYPAD */ + } else { + nhcmdlayout_cell_direct(layout_cur, lcount)->text[0] = + c_char; + nhcmdlayout_cell_direct(layout_cur, lcount)->text[1] = + '\x0'; + } - /* prepareg next charcter from the source string */ - s++; - } - } + /* increment character count in the current layout */ + lcount++; + } - /* install the new set */ - if( nhcmdset_current!=nhcmdset_default ) nhcmdset_destroy( nhcmdset_current ); - nhcmdset_current = p; - SetCmdWindowLayout( - GetNHApp()->hCmdWnd, - nhcmdset_get(nhcmdset_current, 0) - ); + /* prepareg next charcter from the source string */ + s++; + } + } + + /* install the new set */ + if (nhcmdset_current != nhcmdset_default) + nhcmdset_destroy(nhcmdset_current); + nhcmdset_current = p; + SetCmdWindowLayout(GetNHApp()->hCmdWnd, + nhcmdset_get(nhcmdset_current, 0)); } /*-------------------------------------------------------------------------*/ -void NHSPhoneSetKeypadDirection() +void +NHSPhoneSetKeypadDirection() { - PNHCmdWindow data; + PNHCmdWindow data; - data = (PNHCmdWindow)GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); - if( !data ) return; + data = (PNHCmdWindow) GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); + if (!data) + return; - if( nhcmdset_current!=nhcmdset_default ) nhcmdset_destroy( nhcmdset_current ); - nhcmdset_current = nhcmdset_default; - SetCmdWindowLayout( - GetNHApp()->hCmdWnd, - nhcmdset_get(nhcmdset_current, NH_LAYOUT_MOVEMENT) - ); + if (nhcmdset_current != nhcmdset_default) + nhcmdset_destroy(nhcmdset_current); + nhcmdset_current = nhcmdset_default; + SetCmdWindowLayout(GetNHApp()->hCmdWnd, + nhcmdset_get(nhcmdset_current, NH_LAYOUT_MOVEMENT)); } /*-------------------------------------------------------------------------*/ -void NHSPhoneSetKeypadDefault() +void +NHSPhoneSetKeypadDefault() { - PNHCmdWindow data; + PNHCmdWindow data; - data = (PNHCmdWindow)GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); - if( !data ) return; + data = (PNHCmdWindow) GetWindowLong(GetNHApp()->hCmdWnd, GWL_USERDATA); + if (!data) + return; - if( nhcmdset_current!=nhcmdset_default ) nhcmdset_destroy( nhcmdset_current ); - nhcmdset_current = nhcmdset_default; - SetCmdWindowLayout( - GetNHApp()->hCmdWnd, - data->layout_selected ? data->layout_selected : nhcmdset_get(nhcmdset_current, 0) - ); + if (nhcmdset_current != nhcmdset_default) + nhcmdset_destroy(nhcmdset_current); + nhcmdset_current = nhcmdset_default; + SetCmdWindowLayout(GetNHApp()->hCmdWnd, + data->layout_selected + ? data->layout_selected + : nhcmdset_get(nhcmdset_current, 0)); } #endif /* defined (WIN_CE_SMARTHPONE) */ diff --git a/sys/wince/mhcolor.c b/sys/wince/mhcolor.c index 29f3e4454..04bb2223e 100644 --- a/sys/wince/mhcolor.c +++ b/sys/wince/mhcolor.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhcolor.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhcolor.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 mhcolor.c $Date: 2009/05/06 10:52:03 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)mhcolor.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -9,41 +9,40 @@ #include "winMS.h" #include "mhcolor.h" -#define TOTAL_BRUSHES 10 -#define NHBRUSH_CODE(win, type) ((((win)&0xFF)<<8)|((type)&0xFF)) +#define TOTAL_BRUSHES 10 +#define NHBRUSH_CODE(win, type) ((((win) &0xFF) << 8) | ((type) &0xFF)) struct t_brush_table { - int code; - HBRUSH brush; - COLORREF color; + int code; + HBRUSH brush; + COLORREF color; }; static struct t_brush_table brush_table[TOTAL_BRUSHES]; static int max_brush = 0; -static struct t_brush_table default_brush_table[] = -{ - { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, - { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, - { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, - { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, - { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, - { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_FG), NULL, RGB(96, 96, 96) }, +static struct t_brush_table default_brush_table[] = { + { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, + { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, + { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, + { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, + { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) }, + { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_FG), NULL, RGB(96, 96, 96) }, - { NHBRUSH_CODE(NHW_MENU, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, - { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, - { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, - { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, - { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, - { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, - { -1, NULL, RGB(0, 0, 0) } + { NHBRUSH_CODE(NHW_MENU, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, + { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, + { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, + { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, + { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) }, + { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) }, + { -1, NULL, RGB(0, 0, 0) } }; -static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr); +static void mswin_color_from_string(char *colorstring, HBRUSH *brushptr, + COLORREF *colorptr); -typedef struct ctv -{ - const char *colorstring; - COLORREF colorvalue; +typedef struct ctv { + const char *colorstring; + COLORREF colorvalue; } color_table_value; /* @@ -53,168 +52,184 @@ typedef struct ctv */ static color_table_value color_table[] = { -/* NetHack colors */ - { "black", RGB(0x55, 0x55, 0x55)}, - { "red", RGB(0xFF, 0x00, 0x00)}, - { "green", RGB(0x00, 0x80, 0x00)}, - { "brown", RGB(0xA5, 0x2A, 0x2A)}, - { "blue", RGB(0x00, 0x00, 0xFF)}, - { "magenta", RGB(0xFF, 0x00, 0xFF)}, - { "cyan", RGB(0x00, 0xFF, 0xFF)}, - { "orange", RGB(0xFF, 0xA5, 0x00)}, - { "brightgreen", RGB(0x00, 0xFF, 0x00)}, - { "yellow", RGB(0xFF, 0xFF, 0x00)}, - { "brightblue", RGB(0x00, 0xC0, 0xFF)}, - { "brightmagenta", RGB(0xFF, 0x80, 0xFF)}, - { "brightcyan", RGB(0x80, 0xFF, 0xFF)}, - { "white", RGB(0xFF, 0xFF, 0xFF)}, -/* Remaining HTML colors */ - { "trueblack", RGB(0x00, 0x00, 0x00)}, - { "gray", RGB(0x80, 0x80, 0x80)}, - { "grey", RGB(0x80, 0x80, 0x80)}, - { "purple", RGB(0x80, 0x00, 0x80)}, - { "silver", RGB(0xC0, 0xC0, 0xC0)}, - { "maroon", RGB(0x80, 0x00, 0x00)}, - { "fuchsia", RGB(0xFF, 0x00, 0xFF)}, /* = NetHack magenta */ - { "lime", RGB(0x00, 0xFF, 0x00)}, /* = NetHack bright green */ - { "olive", RGB(0x80, 0x80, 0x00)}, - { "navy", RGB(0x00, 0x00, 0x80)}, - { "teal", RGB(0x00, 0x80, 0x80)}, - { "aqua", RGB(0x00, 0xFF, 0xFF)}, /* = NetHack cyan */ - { "", RGB(0x00, 0x00, 0x00)}, + /* NetHack colors */ + { "black", RGB(0x55, 0x55, 0x55) }, + { "red", RGB(0xFF, 0x00, 0x00) }, + { "green", RGB(0x00, 0x80, 0x00) }, + { "brown", RGB(0xA5, 0x2A, 0x2A) }, + { "blue", RGB(0x00, 0x00, 0xFF) }, + { "magenta", RGB(0xFF, 0x00, 0xFF) }, + { "cyan", RGB(0x00, 0xFF, 0xFF) }, + { "orange", RGB(0xFF, 0xA5, 0x00) }, + { "brightgreen", RGB(0x00, 0xFF, 0x00) }, + { "yellow", RGB(0xFF, 0xFF, 0x00) }, + { "brightblue", RGB(0x00, 0xC0, 0xFF) }, + { "brightmagenta", RGB(0xFF, 0x80, 0xFF) }, + { "brightcyan", RGB(0x80, 0xFF, 0xFF) }, + { "white", RGB(0xFF, 0xFF, 0xFF) }, + /* Remaining HTML colors */ + { "trueblack", RGB(0x00, 0x00, 0x00) }, + { "gray", RGB(0x80, 0x80, 0x80) }, + { "grey", RGB(0x80, 0x80, 0x80) }, + { "purple", RGB(0x80, 0x00, 0x80) }, + { "silver", RGB(0xC0, 0xC0, 0xC0) }, + { "maroon", RGB(0x80, 0x00, 0x00) }, + { "fuchsia", RGB(0xFF, 0x00, 0xFF) }, /* = NetHack magenta */ + { "lime", RGB(0x00, 0xFF, 0x00) }, /* = NetHack bright green */ + { "olive", RGB(0x80, 0x80, 0x00) }, + { "navy", RGB(0x00, 0x00, 0x80) }, + { "teal", RGB(0x00, 0x80, 0x80) }, + { "aqua", RGB(0x00, 0xFF, 0xFF) }, /* = NetHack cyan */ + { "", RGB(0x00, 0x00, 0x00) }, }; -typedef struct ctbv -{ - char *colorstring; - int syscolorvalue; +typedef struct ctbv { + char *colorstring; + int syscolorvalue; } color_table_brush_value; static color_table_brush_value color_table_brush[] = { - { "activeborder", COLOR_ACTIVEBORDER }, - { "activecaption", COLOR_ACTIVECAPTION }, - { "appworkspace", COLOR_APPWORKSPACE }, - { "background", COLOR_BACKGROUND }, - { "btnface", COLOR_BTNFACE }, - { "btnshadow", COLOR_BTNSHADOW }, - { "btntext", COLOR_BTNTEXT }, - { "captiontext", COLOR_CAPTIONTEXT }, - { "graytext", COLOR_GRAYTEXT }, - { "greytext", COLOR_GRAYTEXT }, - { "highlight", COLOR_HIGHLIGHT }, - { "highlighttext", COLOR_HIGHLIGHTTEXT }, - { "inactiveborder", COLOR_INACTIVEBORDER }, - { "inactivecaption", COLOR_INACTIVECAPTION }, - { "menu", COLOR_MENU }, - { "menutext", COLOR_MENUTEXT }, - { "scrollbar", COLOR_SCROLLBAR }, - { "window", COLOR_WINDOW }, - { "windowframe", COLOR_WINDOWFRAME }, - { "windowtext", COLOR_WINDOWTEXT }, - { "", -1 }, + { "activeborder", COLOR_ACTIVEBORDER }, + { "activecaption", COLOR_ACTIVECAPTION }, + { "appworkspace", COLOR_APPWORKSPACE }, + { "background", COLOR_BACKGROUND }, + { "btnface", COLOR_BTNFACE }, + { "btnshadow", COLOR_BTNSHADOW }, + { "btntext", COLOR_BTNTEXT }, + { "captiontext", COLOR_CAPTIONTEXT }, + { "graytext", COLOR_GRAYTEXT }, + { "greytext", COLOR_GRAYTEXT }, + { "highlight", COLOR_HIGHLIGHT }, + { "highlighttext", COLOR_HIGHLIGHTTEXT }, + { "inactiveborder", COLOR_INACTIVEBORDER }, + { "inactivecaption", COLOR_INACTIVECAPTION }, + { "menu", COLOR_MENU }, + { "menutext", COLOR_MENUTEXT }, + { "scrollbar", COLOR_SCROLLBAR }, + { "window", COLOR_WINDOW }, + { "windowframe", COLOR_WINDOWFRAME }, + { "windowtext", COLOR_WINDOWTEXT }, + { "", -1 }, }; -void mswin_init_color_table() +void +mswin_init_color_table() { - int i; - struct t_brush_table* p; + int i; + struct t_brush_table *p; - /* cleanup */ - for( i=0; icode != -1; p++ ) { - if( p->code==brush_table[i].code ) { - brush_table[i].brush = CreateSolidBrush(p->color); - brush_table[i].color = p->color; - } - } - } - } + /* go through the values and fill in "blanks" (use default values) */ + for (i = 0; i < max_brush; i++) { + if (!brush_table[i].brush) { + for (p = default_brush_table; p->code != -1; p++) { + if (p->code == brush_table[i].code) { + brush_table[i].brush = CreateSolidBrush(p->color); + brush_table[i].color = p->color; + } + } + } + } } -HBRUSH mswin_get_brush(int win_type, int color_index) +HBRUSH +mswin_get_brush(int win_type, int color_index) { - int i; - for(i=0; icolorstring && _stricmp(ctv_ptr->colorstring, colorstring)) - ++ctv_ptr; - if (*ctv_ptr->colorstring) { - *colorptr = ctv_ptr->colorvalue; - } else { - while (*ctbv_ptr->colorstring && _stricmp(ctbv_ptr->colorstring, colorstring)) - ++ctbv_ptr; - if (*ctbv_ptr->colorstring) { - *brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue); - *colorptr = GetSysColor(ctbv_ptr->syscolorvalue); - } - } - } - if (max_brush > TOTAL_BRUSHES) panic("Too many colors!"); - *brushptr = CreateSolidBrush(*colorptr); + *colorptr = RGB(red_value, blue_value, green_value); + } else { + while (*ctv_ptr->colorstring + && _stricmp(ctv_ptr->colorstring, colorstring)) + ++ctv_ptr; + if (*ctv_ptr->colorstring) { + *colorptr = ctv_ptr->colorvalue; + } else { + while (*ctbv_ptr->colorstring + && _stricmp(ctbv_ptr->colorstring, colorstring)) + ++ctbv_ptr; + if (*ctbv_ptr->colorstring) { + *brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue); + *colorptr = GetSysColor(ctbv_ptr->syscolorvalue); + } + } + } + if (max_brush > TOTAL_BRUSHES) + panic("Too many colors!"); + *brushptr = CreateSolidBrush(*colorptr); } diff --git a/sys/wince/mhdlg.c b/sys/wince/mhdlg.c index 14c1cdf4c..700d014a2 100644 --- a/sys/wince/mhdlg.c +++ b/sys/wince/mhdlg.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhdlg.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhdlg.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ /* NetHack 3.6 mhdlg.c $Date: 2009/10/13 01:55:10 $ $Revision: 1.8 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,779 +11,816 @@ #include "mhdlg.h" #include "mhmain.h" -#define CheckDlgButton(dlg, btn_id, st) SendDlgItemMessage((dlg), (btn_id), BM_SETCHECK, (WPARAM)(st), 0) - +#define CheckDlgButton(dlg, btn_id, st) \ + SendDlgItemMessage((dlg), (btn_id), BM_SETCHECK, (WPARAM)(st), 0) /*---------------------------------------------------------------*/ /* data for getlin dialog */ struct getlin_data { - const char* question; - char* result; - size_t result_size; + const char *question; + char *result; + size_t result_size; }; -LRESULT CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); -int mswin_getlin_window ( - const char *question, - char *result, - size_t result_size -) +int +mswin_getlin_window(const char *question, char *result, size_t result_size) { - int ret; - struct getlin_data data; + int ret; + struct getlin_data data; - /* initilize dialog data */ - ZeroMemory(&data, sizeof(data)); - data.question = question; - data.result = result; - data.result_size = result_size; + /* initilize dialog data */ + ZeroMemory(&data, sizeof(data)); + data.question = question; + data.result = result; + data.result_size = result_size; - /* create modal dialog window */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_GETLIN), - GetNHApp()->hMainWnd, - GetlinDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create getlin window"); - - return ret; + /* create modal dialog window */ + ret = DialogBoxParam(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_GETLIN), + GetNHApp()->hMainWnd, GetlinDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create getlin window"); + + return ret; } - -LRESULT CALLBACK GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +LRESULT CALLBACK +GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - struct getlin_data* data; - RECT main_rt, text_rt, dlg_rt, edit_rt; - SIZE dlg_sz; - TCHAR wbuf[BUFSZ]; - HDC hdc; - HWND control; - HWND hwndMap; + struct getlin_data *data; + RECT main_rt, text_rt, dlg_rt, edit_rt; + SIZE dlg_sz; + TCHAR wbuf[BUFSZ]; + HDC hdc; + HWND control; + HWND hwndMap; #if defined(WIN_CE_POCKETPC) - SHInputDialog(hWnd, message, wParam); + SHInputDialog(hWnd, message, wParam); #endif - switch (message) - { - case WM_INITDIALOG: - data = (struct getlin_data*)lParam; - SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf))); - SetWindowLong(hWnd, GWL_USERDATA, lParam); + switch (message) { + case WM_INITDIALOG: + data = (struct getlin_data *) lParam; + SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf))); + SetWindowLong(hWnd, GWL_USERDATA, lParam); - /* get title text width */ - SetRect(&text_rt, 0, 0, 100, 50); - hdc = GetWindowDC(hWnd); - DrawText(hdc, wbuf, _tcslen(wbuf), &text_rt, - DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX | DT_LEFT | DT_VCENTER ); - ReleaseDC(hWnd, hdc); + /* get title text width */ + SetRect(&text_rt, 0, 0, 100, 50); + hdc = GetWindowDC(hWnd); + DrawText(hdc, wbuf, _tcslen(wbuf), &text_rt, + DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX | DT_LEFT + | DT_VCENTER); + ReleaseDC(hWnd, hdc); - /* center dialog in the main window */ - GetWindowRect(hWnd, &dlg_rt); - hwndMap = mswin_hwnd_from_winid(WIN_MAP); - GetWindowRect( IsWindow(hwndMap)? hwndMap : GetNHApp()->hMainWnd, &main_rt); - dlg_sz.cx = max(dlg_rt.right-dlg_rt.left, - min( text_rt.right-text_rt.left+GetSystemMetrics(SM_CXICON), - main_rt.right-main_rt.left ) ); - dlg_sz.cy = min(dlg_rt.bottom - dlg_rt.top, main_rt.bottom - main_rt.top); - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + /* center dialog in the main window */ + GetWindowRect(hWnd, &dlg_rt); + hwndMap = mswin_hwnd_from_winid(WIN_MAP); + GetWindowRect(IsWindow(hwndMap) ? hwndMap : GetNHApp()->hMainWnd, + &main_rt); + dlg_sz.cx = max( + dlg_rt.right - dlg_rt.left, + min(text_rt.right - text_rt.left + GetSystemMetrics(SM_CXICON), + main_rt.right - main_rt.left)); + dlg_sz.cy = + min(dlg_rt.bottom - dlg_rt.top, main_rt.bottom - main_rt.top); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - /* change layout of controls */ - GetClientRect(hWnd, &dlg_rt); + /* change layout of controls */ + GetClientRect(hWnd, &dlg_rt); - control = GetDlgItem(hWnd, IDC_GETLIN_EDIT); - GetWindowRect(control, &edit_rt); - MoveWindow( control, - 0, - 0, - dlg_rt.right - dlg_rt.left, - edit_rt.bottom - edit_rt.top, - TRUE ); + control = GetDlgItem(hWnd, IDC_GETLIN_EDIT); + GetWindowRect(control, &edit_rt); + MoveWindow(control, 0, 0, dlg_rt.right - dlg_rt.left, + edit_rt.bottom - edit_rt.top, TRUE); - control = GetDlgItem(hWnd, IDOK); - GetWindowRect(control, &text_rt); - MoveWindow( control, - 0, - edit_rt.bottom - edit_rt.top, - (dlg_rt.right-dlg_rt.left)/2, - text_rt.bottom - text_rt.top, - TRUE ); + control = GetDlgItem(hWnd, IDOK); + GetWindowRect(control, &text_rt); + MoveWindow(control, 0, edit_rt.bottom - edit_rt.top, + (dlg_rt.right - dlg_rt.left) / 2, + text_rt.bottom - text_rt.top, TRUE); - control = GetDlgItem(hWnd, IDCANCEL); - GetWindowRect(control, &text_rt); - MoveWindow( control, - (dlg_rt.right-dlg_rt.left)/2, - edit_rt.bottom - edit_rt.top, - (dlg_rt.right-dlg_rt.left)/2, - text_rt.bottom - text_rt.top, - TRUE ); + control = GetDlgItem(hWnd, IDCANCEL); + GetWindowRect(control, &text_rt); + MoveWindow(control, (dlg_rt.right - dlg_rt.left) / 2, + edit_rt.bottom - edit_rt.top, + (dlg_rt.right - dlg_rt.left) / 2, + text_rt.bottom - text_rt.top, TRUE); #if defined(WIN_CE_SMARTPHONE) - NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, TRUE, FALSE); + NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, TRUE, FALSE); #endif - /* set focus to the edit control */ - SetFocus(GetDlgItem(hWnd, IDC_GETLIN_EDIT)); + /* set focus to the edit control */ + SetFocus(GetDlgItem(hWnd, IDC_GETLIN_EDIT)); - /* tell windows that we've set the focus */ - return FALSE; - break; + /* tell windows that we've set the focus */ + return FALSE; + break; - case WM_COMMAND: - { - TCHAR wbuf[BUFSZ]; + case WM_COMMAND: { + TCHAR wbuf[BUFSZ]; - switch (LOWORD(wParam)) - { - /* OK button was pressed */ - case IDOK: - data = (struct getlin_data*)GetWindowLong(hWnd, GWL_USERDATA); - SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, (WPARAM)sizeof(wbuf), (LPARAM)wbuf ); - NH_W2A(wbuf, data->result, data->result_size); + switch (LOWORD(wParam)) { + /* OK button was pressed */ + case IDOK: + data = (struct getlin_data *) GetWindowLong(hWnd, GWL_USERDATA); + SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, + (WPARAM) sizeof(wbuf), (LPARAM) wbuf); + NH_W2A(wbuf, data->result, data->result_size); - /* Fall through. */ + /* Fall through. */ - /* cancel button was pressed */ - case IDCANCEL: - EndDialog(hWnd, wParam); - return TRUE; - } - } break; + /* cancel button was pressed */ + case IDCANCEL: + EndDialog(hWnd, wParam); + return TRUE; + } + } break; #if defined(WIN_CE_SMARTPHONE) - case WM_HOTKEY: - if(VK_TBACK == HIWORD(lParam)) { - SHSendBackToFocusWindow(message, wParam, lParam); - } - break; + case WM_HOTKEY: + if (VK_TBACK == HIWORD(lParam)) { + SHSendBackToFocusWindow(message, wParam, lParam); + } + break; #endif - } /* end switch (message) */ - return FALSE; + } /* end switch (message) */ + return FALSE; } - /*---------------------------------------------------------------*/ /* dialog data for the list of extended commands */ struct extcmd_data { - int* selection; + int *selection; }; -LRESULT CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM); -int mswin_ext_cmd_window (int* selection) +int +mswin_ext_cmd_window(int *selection) { - int ret; - struct extcmd_data data; - - /* init dialog data */ - ZeroMemory(&data, sizeof(data)); - *selection = -1; - data.selection = selection; + int ret; + struct extcmd_data data; - /* create modal dialog window */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_EXTCMD), - GetNHApp()->hMainWnd, - ExtCmdDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create extcmd window"); - return ret; + /* init dialog data */ + ZeroMemory(&data, sizeof(data)); + *selection = -1; + data.selection = selection; + + /* create modal dialog window */ + ret = DialogBoxParam(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_EXTCMD), + GetNHApp()->hMainWnd, ExtCmdDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create extcmd window"); + return ret; } - -LRESULT CALLBACK ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +LRESULT CALLBACK +ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - struct extcmd_data* data; - RECT main_rt, dlg_rt; - SIZE dlg_sz; - int i; - const char *ptr; - TCHAR wbuf[255]; + struct extcmd_data *data; + RECT main_rt, dlg_rt; + SIZE dlg_sz; + int i; + const char *ptr; + TCHAR wbuf[255]; - switch (message) - { - case WM_INITDIALOG: - data = (struct extcmd_data*)lParam; - SetWindowLong(hWnd, GWL_USERDATA, lParam); + switch (message) { + case WM_INITDIALOG: + data = (struct extcmd_data *) lParam; + SetWindowLong(hWnd, GWL_USERDATA, lParam); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hWnd, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hWnd, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - /* fill combobox with extended commands */ - for(i=0; (ptr=extcmdlist[i].ef_txt); i++) { - SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(ptr, wbuf, sizeof(wbuf)) ); - } + /* fill combobox with extended commands */ + for (i = 0; (ptr = extcmdlist[i].ef_txt); i++) { + SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, + (WPARAM) 0, + (LPARAM) NH_A2W(ptr, wbuf, sizeof(wbuf))); + } #if defined(WIN_CE_SMARTPHONE) - NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, FALSE); + NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, FALSE); - GetClientRect(hWnd, &dlg_rt); - MoveWindow(GetDlgItem(hWnd, IDC_EXTCMD_LIST), - dlg_rt.left, dlg_rt.top, - dlg_rt.right-dlg_rt.left, dlg_rt.bottom-dlg_rt.top, - TRUE); + GetClientRect(hWnd, &dlg_rt); + MoveWindow(GetDlgItem(hWnd, IDC_EXTCMD_LIST), dlg_rt.left, dlg_rt.top, + dlg_rt.right - dlg_rt.left, dlg_rt.bottom - dlg_rt.top, + TRUE); #endif - /* set focus to the list control */ - SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST)); + /* set focus to the list control */ + SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST)); - /* tell windows we set the focus */ - return FALSE; - break; + /* tell windows we set the focus */ + return FALSE; + break; - case WM_COMMAND: - data = (struct extcmd_data*)GetWindowLong(hWnd, GWL_USERDATA); - switch (LOWORD(wParam)) - { - /* OK button ws clicked */ - case IDOK: - *data->selection = SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); - if( *data->selection==LB_ERR ) - *data->selection = -1; - /* Fall through. */ + case WM_COMMAND: + data = (struct extcmd_data *) GetWindowLong(hWnd, GWL_USERDATA); + switch (LOWORD(wParam)) { + /* OK button ws clicked */ + case IDOK: + *data->selection = SendDlgItemMessage( + hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + if (*data->selection == LB_ERR) + *data->selection = -1; + /* Fall through. */ - /* CANCEL button ws clicked */ - case IDCANCEL: - EndDialog(hWnd, wParam); - return TRUE; + /* CANCEL button ws clicked */ + case IDCANCEL: + EndDialog(hWnd, wParam); + return TRUE; - /* list control events */ - case IDC_EXTCMD_LIST: - switch(HIWORD(wParam)) { - - case LBN_DBLCLK: - /* double click within the list - wParam - The low-order word is the list box identifier. - The high-order word is the notification message. - lParam - Handle to the list box - */ - *data->selection = SendMessage((HWND)lParam, LB_GETCURSEL, (WPARAM)0, (LPARAM)0); - if( *data->selection==LB_ERR ) - *data->selection = -1; - EndDialog(hWnd, IDOK); - return TRUE; - } - break; - } - } - return FALSE; + /* list control events */ + case IDC_EXTCMD_LIST: + switch (HIWORD(wParam)) { + case LBN_DBLCLK: + /* double click within the list + wParam + The low-order word is the list box identifier. + The high-order word is the notification message. + lParam + Handle to the list box + */ + *data->selection = SendMessage((HWND) lParam, LB_GETCURSEL, + (WPARAM) 0, (LPARAM) 0); + if (*data->selection == LB_ERR) + *data->selection = -1; + EndDialog(hWnd, IDOK); + return TRUE; + } + break; + } + } + return FALSE; } /*---------------------------------------------------------------*/ /* player selector dialog data */ struct plsel_data { - int* selection; + int *selection; }; -BOOL CALLBACK PlayerSelectorDlgProc(HWND, UINT, WPARAM, LPARAM); -static void plselInitDialog(HWND hWnd); -static void plselAdjustLists(HWND hWnd, int changed_opt); -static int plselFinalSelection(HWND hWnd, int* selection); +BOOL CALLBACK PlayerSelectorDlgProc(HWND, UINT, WPARAM, LPARAM); +static void plselInitDialog(HWND hWnd); +static void plselAdjustLists(HWND hWnd, int changed_opt); +static int plselFinalSelection(HWND hWnd, int *selection); -int mswin_player_selection_window ( int* selection ) +int +mswin_player_selection_window(int *selection) { - int ret; - struct plsel_data data; + int ret; + struct plsel_data data; - /* init dialog data */ - ZeroMemory(&data, sizeof(data)); - data.selection = selection; + /* init dialog data */ + ZeroMemory(&data, sizeof(data)); + data.selection = selection; - /* create modal dialog */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_PLAYER_SELECTOR), - GetNHApp()->hMainWnd, - PlayerSelectorDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create getlin window"); - - return ret; + /* create modal dialog */ + ret = DialogBoxParam( + GetNHApp()->hApp, MAKEINTRESOURCE(IDD_PLAYER_SELECTOR), + GetNHApp()->hMainWnd, PlayerSelectorDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create getlin window"); + + return ret; } -BOOL CALLBACK PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK +PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - struct plsel_data* data; - RECT main_rt, dlg_rt; - SIZE dlg_sz; + struct plsel_data *data; + RECT main_rt, dlg_rt; + SIZE dlg_sz; - switch (message) - { - case WM_INITDIALOG: - data = (struct plsel_data*)lParam; - SetWindowLong(hWnd, GWL_USERDATA, lParam); + switch (message) { + case WM_INITDIALOG: + data = (struct plsel_data *) lParam; + SetWindowLong(hWnd, GWL_USERDATA, lParam); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hWnd, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hWnd, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - /* init dialog */ - plselInitDialog(hWnd); + /* init dialog */ + plselInitDialog(hWnd); #if defined(WIN_CE_SMARTPHONE) - NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, FALSE); + NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, FALSE); #endif - /* set focus on the role checkbox (random) field */ - SetFocus(GetDlgItem(hWnd, IDC_PLSEL_ROLE_RANDOM)); + /* set focus on the role checkbox (random) field */ + SetFocus(GetDlgItem(hWnd, IDC_PLSEL_ROLE_RANDOM)); - /* tell windows we set the focus */ - return FALSE; - break; + /* tell windows we set the focus */ + return FALSE; + break; - case WM_COMMAND: - data = (struct plsel_data*)GetWindowLong(hWnd, GWL_USERDATA); - switch (LOWORD(wParam)) { + case WM_COMMAND: + data = (struct plsel_data *) GetWindowLong(hWnd, GWL_USERDATA); + switch (LOWORD(wParam)) { + /* OK button was clicked */ + case IDOK: + if (plselFinalSelection(hWnd, data->selection)) { + EndDialog(hWnd, wParam); + } else { + MessageBox( + hWnd, TEXT("Cannot match this role. Try something else."), + TEXT("STOP"), MB_OK); + } + return TRUE; - /* OK button was clicked */ - case IDOK: - if( plselFinalSelection(hWnd, data->selection) ) { - EndDialog(hWnd, wParam); - } else { - MessageBox(hWnd, TEXT("Cannot match this role. Try something else."), TEXT("STOP"), MB_OK ); - } - return TRUE; + /* CANCEL button was clicked */ + case IDCANCEL: + *data->selection = -1; + EndDialog(hWnd, wParam); + return TRUE; - /* CANCEL button was clicked */ - case IDCANCEL: - *data->selection = -1; - EndDialog(hWnd, wParam); - return TRUE; + /* following are events from dialog controls: + "random" checkboxes send BN_CLICKED messages; + role/race/... combo-boxes send CBN_SELENDOK + if something was selected; + */ + case IDC_PLSEL_ROLE_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + /* enable corresponding list window if "random" + checkbox was "unchecked" */ + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - /* following are events from dialog controls: - "random" checkboxes send BN_CLICKED messages; - role/race/... combo-boxes send CBN_SELENDOK - if something was selected; - */ - case IDC_PLSEL_ROLE_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - /* enable corresponding list window if "random" - checkbox was "unchecked" */ - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_RACE_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_RACE_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_GENDER_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_GENDER_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_ALIGN_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_ALIGN_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_ROLE_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + /* filter out invalid options if + the selection was made */ + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_ROLE_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - /* filter out invalid options if - the selection was made */ - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; + case IDC_PLSEL_RACE_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_RACE_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; + case IDC_PLSEL_GENDER_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_GENDER_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; - - case IDC_PLSEL_ALIGN_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; - } - break; - } - return FALSE; + case IDC_PLSEL_ALIGN_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; + } + break; + } + return FALSE; } -void setComboBoxValue(HWND hWnd, int combo_box, int value) +void +setComboBoxValue(HWND hWnd, int combo_box, int value) { - int index_max = SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); - int index; - int value_to_set = LB_ERR; - for (index = 0; index < index_max; index++) { - if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, (WPARAM)index, 0) == value) { - value_to_set = index; - break; - } - } - SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM)value_to_set, 0); + int index_max = SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); + int index; + int value_to_set = LB_ERR; + for (index = 0; index < index_max; index++) { + if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, + (WPARAM) index, 0) == value) { + value_to_set = index; + break; + } + } + SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM) value_to_set, + 0); } /* initialize player selector dialog */ -void plselInitDialog(HWND hWnd) +void +plselInitDialog(HWND hWnd) { - TCHAR wbuf[BUFSZ]; + TCHAR wbuf[BUFSZ]; - /* set player name */ - SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf))); + /* set player name */ + SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf))); - /* check flags for consistency */ - if( flags.initrole>=0 ) { - if (flags.initrace>=0 && !validrace(flags.initrole, flags.initrace)) { - flags.initrace = ROLE_NONE; - } + /* check flags for consistency */ + if (flags.initrole >= 0) { + if (flags.initrace >= 0 + && !validrace(flags.initrole, flags.initrace)) { + flags.initrace = ROLE_NONE; + } - if (flags.initgend>=0 && !validgend(flags.initrole, flags.initrace, flags.initgend)) { - flags.initgend = ROLE_NONE; - } + if (flags.initgend >= 0 + && !validgend(flags.initrole, flags.initrace, flags.initgend)) { + flags.initgend = ROLE_NONE; + } - if (flags.initalign>=0 && !validalign(flags.initrole, flags.initrace, flags.initalign)) { - flags.initalign = ROLE_NONE; - } - } + if (flags.initalign >= 0 + && !validalign(flags.initrole, flags.initrace, flags.initalign)) { + flags.initalign = ROLE_NONE; + } + } - /* populate select boxes */ - plselAdjustLists(hWnd, -1); + /* populate select boxes */ + plselAdjustLists(hWnd, -1); - /* intialize roles list */ - if( flags.initrole<0 || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) { - CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); - } + /* intialize roles list */ + if (flags.initrole < 0 + || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); + } - /* intialize races list */ - if( flags.initrace<0 || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE) ) { - CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); - } + /* intialize races list */ + if (flags.initrace < 0 + || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); + } - /* intialize genders list */ - if( flags.initgend<0 || !ok_gend(flags.initrole, flags.initrace, flags.initgend, ROLE_NONE)) { - CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); - } + /* intialize genders list */ + if (flags.initgend < 0 + || !ok_gend(flags.initrole, flags.initrace, flags.initgend, + ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); + } - /* intialize alignments list */ - if( flags.initalign<0 || !ok_align(flags.initrole, flags.initrace, flags.initgend, flags.initalign) ) { - CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); - } + /* intialize alignments list */ + if (flags.initalign < 0 + || !ok_align(flags.initrole, flags.initrace, flags.initgend, + flags.initalign)) { + CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); + } } /* adjust role/race/alignment/gender list - filter out - invalid combinations + invalid combinations changed_sel points to the list where selection occured (-1 if unknown) */ -void plselAdjustLists(HWND hWnd, int changed_sel) +void +plselAdjustLists(HWND hWnd, int changed_sel) { - HWND control_role, control_race, control_gender, control_align; - int initrole, initrace, initgend, initalign; - int i; - int ind; - int valid_opt; - TCHAR wbuf[255]; + HWND control_role, control_race, control_gender, control_align; + int initrole, initrace, initgend, initalign; + int i; + int ind; + int valid_opt; + TCHAR wbuf[255]; - /* get control handles */ - control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST); - control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST); - control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST); - control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST); + /* get control handles */ + control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST); + control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST); + control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST); + control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST); - /* get current selections */ - ind = SendMessage(control_role, CB_GETCURSEL, 0, 0); - initrole = (ind==LB_ERR)? flags.initrole : SendMessage(control_role, CB_GETITEMDATA, ind, 0); + /* get current selections */ + ind = SendMessage(control_role, CB_GETCURSEL, 0, 0); + initrole = (ind == LB_ERR) + ? flags.initrole + : SendMessage(control_role, CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_race, CB_GETCURSEL, 0, 0); - initrace = (ind==LB_ERR)? flags.initrace : SendMessage(control_race, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_race, CB_GETCURSEL, 0, 0); + initrace = (ind == LB_ERR) + ? flags.initrace + : SendMessage(control_race, CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0); - initgend = (ind==LB_ERR)? flags.initgend : SendMessage(control_gender, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0); + initgend = (ind == LB_ERR) + ? flags.initgend + : SendMessage(control_gender, CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_align, CB_GETCURSEL, 0, 0); - initalign = (ind==LB_ERR)? flags.initalign : SendMessage(control_align, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_align, CB_GETCURSEL, 0, 0); + initalign = (ind == LB_ERR) + ? flags.initalign + : SendMessage(control_align, CB_GETITEMDATA, ind, 0); - /* intialize roles list */ - if( changed_sel==-1 ) { - valid_opt = 0; + /* intialize roles list */ + if (changed_sel == -1) { + valid_opt = 0; - /* reset content and populate the list */ - SendMessage(control_role, CB_RESETCONTENT, 0, 0); - for (i = 0; roles[i].name.m; i++) { - if (ok_role(i, initrace, initgend, initalign)) { - if (initgend>=0 && flags.female && roles[i].name.f) - ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) ); - else - ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) ); + /* reset content and populate the list */ + SendMessage(control_role, CB_RESETCONTENT, 0, 0); + for (i = 0; roles[i].name.m; i++) { + if (ok_role(i, initrace, initgend, initalign)) { + if (initgend >= 0 && flags.female && roles[i].name.f) + ind = SendMessage( + control_role, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf))); + else + ind = SendMessage( + control_role, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf))); - SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initrole ) { - SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } - } - - /* set selection to the previously selected role - if it is still valid */ - if( !valid_opt ) { - initrole = ROLE_NONE; - initrace = ROLE_NONE; - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_role, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + SendMessage(control_role, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initrole) { + SendMessage(control_role, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } + } - /* trigger change of the races list */ - changed_sel=IDC_PLSEL_ROLE_LIST; - } + /* set selection to the previously selected role + if it is still valid */ + if (!valid_opt) { + initrole = ROLE_NONE; + initrace = ROLE_NONE; + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_role, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } - /* intialize races list */ - if( changed_sel==IDC_PLSEL_ROLE_LIST ) { - valid_opt = 0; + /* trigger change of the races list */ + changed_sel = IDC_PLSEL_ROLE_LIST; + } - /* reset content and populate the list */ - SendMessage(control_race, CB_RESETCONTENT, 0, 0); - for (i = 0; races[i].noun; i++) - if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) { - ind = SendMessage(control_race, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(races[i].noun, wbuf, sizeof(wbuf)) ); - SendMessage(control_race, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initrace ) { - SendMessage(control_race, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize races list */ + if (changed_sel == IDC_PLSEL_ROLE_LIST) { + valid_opt = 0; - /* set selection to the previously selected race - if it is still valid */ - if( !valid_opt ) { - initrace = ROLE_NONE; - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_race, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + /* reset content and populate the list */ + SendMessage(control_race, CB_RESETCONTENT, 0, 0); + for (i = 0; races[i].noun; i++) + if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) { + ind = SendMessage( + control_race, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(races[i].noun, wbuf, sizeof(wbuf))); + SendMessage(control_race, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initrace) { + SendMessage(control_race, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } - /* trigger change of the genders list */ - changed_sel=IDC_PLSEL_RACE_LIST; - } + /* set selection to the previously selected race + if it is still valid */ + if (!valid_opt) { + initrace = ROLE_NONE; + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_race, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } - /* intialize genders list */ - if( changed_sel==IDC_PLSEL_RACE_LIST ) { - valid_opt = 0; + /* trigger change of the genders list */ + changed_sel = IDC_PLSEL_RACE_LIST; + } - /* reset content and populate the list */ - SendMessage(control_gender, CB_RESETCONTENT, 0, 0); - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(initrole, initrace, i, ROLE_NONE)) { - ind = SendMessage(control_gender, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(genders[i].adj, wbuf, sizeof(wbuf)) ); - SendMessage(control_gender, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initgend ) { - SendMessage(control_gender, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize genders list */ + if (changed_sel == IDC_PLSEL_RACE_LIST) { + valid_opt = 0; - /* set selection to the previously selected gender - if it is still valid */ - if( !valid_opt ) { - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_gender, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + /* reset content and populate the list */ + SendMessage(control_gender, CB_RESETCONTENT, 0, 0); + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(initrole, initrace, i, ROLE_NONE)) { + ind = SendMessage( + control_gender, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(genders[i].adj, wbuf, sizeof(wbuf))); + SendMessage(control_gender, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initgend) { + SendMessage(control_gender, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } - /* trigger change of the alignments list */ - changed_sel=IDC_PLSEL_GENDER_LIST; - } + /* set selection to the previously selected gender + if it is still valid */ + if (!valid_opt) { + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_gender, CB_SETCURSEL, (WPARAM) -1, + (LPARAM) 0); + } - /* intialize alignments list */ - if( changed_sel==IDC_PLSEL_GENDER_LIST ) { - valid_opt = 0; + /* trigger change of the alignments list */ + changed_sel = IDC_PLSEL_GENDER_LIST; + } - /* reset content and populate the list */ - SendMessage(control_align, CB_RESETCONTENT, 0, 0); - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(initrole, initrace, initgend, i)) { - ind = SendMessage(control_align, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf)) ); - SendMessage(control_align, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initalign ) { - SendMessage(control_align, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize alignments list */ + if (changed_sel == IDC_PLSEL_GENDER_LIST) { + valid_opt = 0; - /* set selection to the previously selected alignment - if it is still valid */ - if( !valid_opt ) { - initalign = ROLE_NONE; - SendMessage(control_align, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } - } + /* reset content and populate the list */ + SendMessage(control_align, CB_RESETCONTENT, 0, 0); + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(initrole, initrace, initgend, i)) { + ind = SendMessage( + control_align, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf))); + SendMessage(control_align, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initalign) { + SendMessage(control_align, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } + + /* set selection to the previously selected alignment + if it is still valid */ + if (!valid_opt) { + initalign = ROLE_NONE; + SendMessage(control_align, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } + } } -/* player made up his mind - get final selection here */ -int plselFinalSelection(HWND hWnd, int* selection) +/* player made up his mind - get final selection here */ +int +plselFinalSelection(HWND hWnd, int *selection) { - int ind; + int ind; - /* get current selections */ - if( SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initrole = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETCURSEL, 0, 0); - flags.initrole = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETITEMDATA, ind, 0); - } + /* get current selections */ + if (SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initrole = ROLE_RANDOM; + } else { + ind = + SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETCURSEL, 0, 0); + flags.initrole = (ind == LB_ERR) + ? ROLE_RANDOM + : SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initrace = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETCURSEL, 0, 0); - flags.initrace = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETITEMDATA, ind, 0); - } + if (SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initrace = ROLE_RANDOM; + } else { + ind = + SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETCURSEL, 0, 0); + flags.initrace = (ind == LB_ERR) + ? ROLE_RANDOM + : SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initgend = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETCURSEL, 0, 0); - flags.initgend = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETITEMDATA, ind, 0); - } + if (SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initgend = ROLE_RANDOM; + } else { + ind = SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETCURSEL, 0, + 0); + flags.initgend = (ind == LB_ERR) + ? ROLE_RANDOM + : SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initalign = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETCURSEL, 0, 0); - flags.initalign = (ind==LB_ERR)? ROLE_RANDOM : SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETITEMDATA, ind, 0); - } - + if (SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initalign = ROLE_RANDOM; + } else { + ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETCURSEL, 0, + 0); + flags.initalign = (ind == LB_ERR) + ? ROLE_RANDOM + : SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, + CB_GETITEMDATA, ind, 0); + } - /* check the role */ - if( flags.initrole==ROLE_RANDOM ) { - flags.initrole = pick_role(flags.initrace, flags.initgend, flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - MessageBox(hWnd, TEXT("Incompatible role!"), TEXT("STOP"), MB_OK); - return FALSE; - } - } + /* check the role */ + if (flags.initrole == ROLE_RANDOM) { + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + MessageBox(hWnd, TEXT("Incompatible role!"), TEXT("STOP"), MB_OK); + return FALSE; + } + } - /* Select a race, if necessary */ - /* force compatibility with role */ - if (flags.initrace==ROLE_RANDOM || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (flags.initrace == ROLE_RANDOM) { - flags.initrace = pick_race(flags.initrole, flags.initgend, flags.initalign, PICK_RANDOM); - } - - if (flags.initrace < 0) { - MessageBox(hWnd, TEXT("Incompatible race!"), TEXT("STOP"), MB_OK); - return FALSE; - } - } + /* Select a race, if necessary */ + /* force compatibility with role */ + if (flags.initrace == ROLE_RANDOM + || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (flags.initrace == ROLE_RANDOM) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + } - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || - !validgend(flags.initrole, flags.initrace, flags.initgend)) { - /* pre-selected gender not valid */ - if (flags.initgend == ROLE_RANDOM) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, flags.initalign, PICK_RANDOM); - } - - if (flags.initgend < 0) { - MessageBox(hWnd, TEXT("Incompatible gender!"), TEXT("STOP"), MB_OK); - return FALSE; - } - } + if (flags.initrace < 0) { + MessageBox(hWnd, TEXT("Incompatible race!"), TEXT("STOP"), MB_OK); + return FALSE; + } + } - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || - !validalign(flags.initrole, flags.initrace, flags.initalign)) { - /* pre-selected alignment not valid */ - if (flags.initalign == ROLE_RANDOM) { - flags.initalign = pick_align(flags.initrole, flags.initrace, flags.initgend, PICK_RANDOM); - } else { - MessageBox(hWnd, TEXT("Incompatible alignment!"), TEXT("STOP"), MB_OK); - return FALSE; - } - } + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (flags.initgend == ROLE_RANDOM) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + } - return TRUE; + if (flags.initgend < 0) { + MessageBox(hWnd, TEXT("Incompatible gender!"), TEXT("STOP"), + MB_OK); + return FALSE; + } + } + + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (flags.initalign == ROLE_RANDOM) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + } else { + MessageBox(hWnd, TEXT("Incompatible alignment!"), TEXT("STOP"), + MB_OK); + return FALSE; + } + } + + return TRUE; } - diff --git a/sys/wince/mhfont.c b/sys/wince/mhfont.c index 56f6573fb..5f66ce90c 100644 --- a/sys/wince/mhfont.c +++ b/sys/wince/mhfont.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhfont.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhfont.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ /* NetHack 3.6 mhfont.c $Date: 2009/05/06 10:52:08 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)mhfont.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -8,173 +8,190 @@ #include "mhfont.h" -#define MAXFONTS 64 +#define MAXFONTS 64 /* font table - 64 fonts ought to be enough */ static struct font_table_entry { - int code; - HFONT hFont; -} font_table[MAXFONTS] ; + int code; + HFONT hFont; +} font_table[MAXFONTS]; static int font_table_size = 0; HFONT version_splash_font; HFONT extrainfo_splash_font; -#define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF)) +#define NHFONT_CODE(win, attr) (((attr & 0xFF) << 8) | (win_type & 0xFF)) static void __cdecl font_table_cleanup(void); /* create font based on window type, charater attributes and window device context */ -HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) +HGDIOBJ +mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) { - HFONT fnt = NULL; - LOGFONT lgfnt; - int font_size; - int font_index; - static BOOL once = FALSE; + HFONT fnt = NULL; + LOGFONT lgfnt; + int font_size; + int font_index; + static BOOL once = FALSE; - if( !once ) { - once = TRUE; - atexit(font_table_cleanup); - } + if (!once) { + once = TRUE; + atexit(font_table_cleanup); + } - ZeroMemory( &lgfnt, sizeof(lgfnt) ); + ZeroMemory(&lgfnt, sizeof(lgfnt)); - /* try find font in the table */ - for(font_index=0; font_index=MAXFONTS ) panic( "font table overflow!" ); - font_table_size++; - } else { - DeleteObject(font_table[font_index].hFont); - } + /* add font to the table */ + if (font_index == font_table_size) { + if (font_table_size >= MAXFONTS) + panic("font table overflow!"); + font_table_size++; + } else { + DeleteObject(font_table[font_index].hFont); + } - font_table[font_index].code = NHFONT_CODE(win_type, attr); - font_table[font_index].hFont = fnt; - return fnt; + font_table[font_index].code = NHFONT_CODE(win_type, attr); + font_table[font_index].hFont = fnt; + return fnt; } -UINT mswin_charset() +UINT +mswin_charset() { - CHARSETINFO cis; - if( SYMHANDLING(H_IBM) ) - if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) ) - return cis.ciCharset; - else - return OEM_CHARSET; - else - if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) ) - return cis.ciCharset; - else - return ANSI_CHARSET; + CHARSETINFO cis; + if (SYMHANDLING(H_IBM)) + if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE)) + return cis.ciCharset; + else + return OEM_CHARSET; + else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE)) + return cis.ciCharset; + else + return ANSI_CHARSET; } void __cdecl font_table_cleanup(void) { - int i; - for(i=0; ihApp, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - register_main_window_class( ); - run_once = 1; - } - - /* create the main window */ - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + /* register window class */ + if (!run_once) { + LoadString(GetNHApp()->hApp, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + register_main_window_class(); + run_once = 1; + } - ret = CreateWindow( - szMainWindowClass, /* registered class name */ - szTitle, /* window name */ - WS_CLIPCHILDREN, /* window style */ - rc.left, /* horizontal position of window */ - rc.top, /* vertical position of window */ - rc.right - rc.left, /* window width */ - rc.bottom - rc.top, /* window height */ - NULL, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL /* window-creation data */ - ); + /* create the main window */ + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - if( !ret ) panic("Cannot create main window"); - return ret; + ret = CreateWindow(szMainWindowClass, /* registered class name */ + szTitle, /* window name */ + WS_CLIPCHILDREN, /* window style */ + rc.left, /* horizontal position of window */ + rc.top, /* vertical position of window */ + rc.right - rc.left, /* window width */ + rc.bottom - rc.top, /* window height */ + NULL, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL /* window-creation data */ + ); + + if (!ret) + panic("Cannot create main window"); + return ret; } -void register_main_window_class() +void +register_main_window_class() { - WNDCLASS wcex; - - ZeroMemory(&wcex, sizeof(wcex)); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = (WNDPROC)MainWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = LoadIcon(GetNHApp()->hApp, (LPCTSTR)IDI_WINHACK); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szMainWindowClass; + WNDCLASS wcex; - RegisterClass(&wcex); + ZeroMemory(&wcex, sizeof(wcex)); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = (WNDPROC) MainWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = LoadIcon(GetNHApp()->hApp, (LPCTSTR) IDI_WINHACK); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szMainWindowClass; + + RegisterClass(&wcex); } /* @@ -94,463 +97,443 @@ void register_main_window_class() */ enum KEY_INDEXES { -KEY_NW, KEY_N, KEY_NE, KEY_MINUS, -KEY_W, KEY_GOINTERESTING, KEY_E, KEY_PLUS, -KEY_SW, KEY_S, KEY_SE, -KEY_INV, KEY_WAITLOOK, -KEY_LAST}; + KEY_NW, + KEY_N, + KEY_NE, + KEY_MINUS, + KEY_W, + KEY_GOINTERESTING, + KEY_E, + KEY_PLUS, + KEY_SW, + KEY_S, + KEY_SE, + KEY_INV, + KEY_WAITLOOK, + KEY_LAST +}; static const unsigned char -/* normal, shift, control */ -keypad[KEY_LAST][3] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, -numpad[KEY_LAST][3] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + /* normal, shift, control */ + keypad[KEY_LAST][3] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[KEY_LAST][3] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; #define STATEON(x) ((GetKeyState(x) & 0xFFFE) != 0) #define KEYTABLE_REGULAR(x) ((iflags.num_pad ? numpad : keypad)[x][0]) #define KEYTABLE_SHIFT(x) ((iflags.num_pad ? numpad : keypad)[x][1]) -#define KEYTABLE(x) (STATEON(VK_SHIFT) ? KEYTABLE_SHIFT(x) : KEYTABLE_REGULAR(x)) +#define KEYTABLE(x) \ + (STATEON(VK_SHIFT) ? KEYTABLE_SHIFT(x) : KEYTABLE_REGULAR(x)) /* map mode macros */ -#define IS_MAP_FIT_TO_SCREEN(mode) ((mode)==MAP_MODE_ASCII_FIT_TO_SCREEN || \ - (mode)==MAP_MODE_TILES_FIT_TO_SCREEN ) - -#define IS_MAP_ASCII(mode) ((mode)!=MAP_MODE_TILES && (mode)!=MAP_MODE_TILES_FIT_TO_SCREEN) +#define IS_MAP_FIT_TO_SCREEN(mode) \ + ((mode) == MAP_MODE_ASCII_FIT_TO_SCREEN \ + || (mode) == MAP_MODE_TILES_FIT_TO_SCREEN) + +#define IS_MAP_ASCII(mode) \ + ((mode) != MAP_MODE_TILES && (mode) != MAP_MODE_TILES_FIT_TO_SCREEN) - /* // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. */ -LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMainWindow data; + PNHMainWindow data; - switch (message) - { - /*-----------------------------------------------------------------------*/ - case WM_CREATE: { + switch (message) { + /*-----------------------------------------------------------------------*/ + case WM_CREATE: { #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - SHMENUBARINFO menubar; + SHMENUBARINFO menubar; #endif - /* set window data */ - data = (PNHMainWindow)malloc(sizeof(NHMainWindow)); - if( !data ) panic("out of memory"); - ZeroMemory(data, sizeof(NHMainWindow)); - data->mapAcsiiModeSave = MAP_MODE_ASCII12x16; - SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + /* set window data */ + data = (PNHMainWindow) malloc(sizeof(NHMainWindow)); + if (!data) + panic("out of memory"); + ZeroMemory(data, sizeof(NHMainWindow)); + data->mapAcsiiModeSave = MAP_MODE_ASCII12x16; + SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); - GetNHApp()->hMainWnd = hWnd; + GetNHApp()->hMainWnd = hWnd; - /* create menu bar */ +/* create menu bar */ #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - ZeroMemory(&menubar, sizeof(menubar)); - menubar.cbSize = sizeof(menubar); - menubar.hwndParent = hWnd; - menubar.dwFlags = 0; - menubar.nToolBarId = IDC_WINHACK; - menubar.hInstRes = GetNHApp()->hApp; -# if defined(WIN_CE_POCKETPC) - menubar.nBmpId = IDB_MENUBAR; - menubar.cBmpImages = 2; -# else - menubar.nBmpId = 0; - menubar.cBmpImages = 0; -# endif - if( !SHCreateMenuBar(&menubar) ) panic("cannot create menu"); - GetNHApp()->hMenuBar = menubar.hwndMB; + ZeroMemory(&menubar, sizeof(menubar)); + menubar.cbSize = sizeof(menubar); + menubar.hwndParent = hWnd; + menubar.dwFlags = 0; + menubar.nToolBarId = IDC_WINHACK; + menubar.hInstRes = GetNHApp()->hApp; +#if defined(WIN_CE_POCKETPC) + menubar.nBmpId = IDB_MENUBAR; + menubar.cBmpImages = 2; #else - GetNHApp()->hMenuBar = CommandBar_Create(GetNHApp()->hApp, hWnd, 1); - if( !GetNHApp()->hMenuBar ) panic("cannot create menu"); - CommandBar_InsertMenubar( - GetNHApp()->hMenuBar, GetNHApp()->hApp, - IDC_WINHACK, 0 ); + menubar.nBmpId = 0; + menubar.cBmpImages = 0; #endif - CheckMenuItem( - _get_main_menu(ID_VIEW), - IDM_VIEW_KEYPAD, - MF_BYCOMMAND | - (GetNHApp()->bCmdPad? MF_CHECKED : MF_UNCHECKED) - ); + if (!SHCreateMenuBar(&menubar)) + panic("cannot create menu"); + GetNHApp()->hMenuBar = menubar.hwndMB; +#else + GetNHApp()->hMenuBar = CommandBar_Create(GetNHApp()->hApp, hWnd, 1); + if (!GetNHApp()->hMenuBar) + panic("cannot create menu"); + CommandBar_InsertMenubar(GetNHApp()->hMenuBar, GetNHApp()->hApp, + IDC_WINHACK, 0); +#endif + CheckMenuItem( + _get_main_menu(ID_VIEW), IDM_VIEW_KEYPAD, + MF_BYCOMMAND | (GetNHApp()->bCmdPad ? MF_CHECKED : MF_UNCHECKED)); - } break; + } break; - /*-----------------------------------------------------------------------*/ - - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + /*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_KEYDOWN: - data = (PNHMainWindow)GetWindowLong(hWnd, GWL_USERDATA); + /*-----------------------------------------------------------------------*/ - /* translate arrow keys into nethack commands */ - switch (wParam) - { - case VK_LEFT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line left */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_LINEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_W)); - } - return 0; + case WM_KEYDOWN: + data = (PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA); - case VK_RIGHT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line right */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_LINEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_E)); - } - return 0; + /* translate arrow keys into nethack commands */ + switch (wParam) { + case VK_LEFT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line left */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_W)); + } + return 0; - case VK_UP: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line up */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_LINEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_N)); - } - return 0; + case VK_RIGHT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line right */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_E)); + } + return 0; - case VK_DOWN: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line down */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_LINEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_S)); - } - return 0; + case VK_UP: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line up */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_N)); + } + return 0; - case VK_HOME: - if( STATEON(VK_CONTROL) ) { - /* scroll map window to upper left corner */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_THUMBTRACK, 0), - (LPARAM)NULL - ); + case VK_DOWN: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line down */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_S)); + } + return 0; - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_THUMBTRACK, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_NW)); - } - return 0; + case VK_HOME: + if (STATEON(VK_CONTROL)) { + /* scroll map window to upper left corner */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); - case VK_END: - if( STATEON(VK_CONTROL) ) { - /* scroll map window to lower right corner */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_THUMBTRACK, ROWNO), - (LPARAM)NULL - ); + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_NW)); + } + return 0; - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_THUMBTRACK, COLNO), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_SW)); - } - return 0; + case VK_END: + if (STATEON(VK_CONTROL)) { + /* scroll map window to lower right corner */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_THUMBTRACK, ROWNO), (LPARAM) NULL); - case VK_PRIOR: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one page up */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_PAGEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_NE)); - } - return 0; + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_THUMBTRACK, COLNO), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_SW)); + } + return 0; - case VK_NEXT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one page down */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_PAGEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_SE)); - } - return 0; + case VK_PRIOR: + if (STATEON(VK_CONTROL)) { + /* scroll map window one page up */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_PAGEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_NE)); + } + return 0; - case VK_DECIMAL: - case VK_DELETE: - NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK)); - return 0; + case VK_NEXT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one page down */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_PAGEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_SE)); + } + return 0; - case VK_INSERT: - NHEVENT_KBD(KEYTABLE(KEY_INV)); - return 0; + case VK_DECIMAL: + case VK_DELETE: + NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK)); + return 0; - case VK_SUBTRACT: - NHEVENT_KBD(KEYTABLE(KEY_MINUS)); - return 0; + case VK_INSERT: + NHEVENT_KBD(KEYTABLE(KEY_INV)); + return 0; - case VK_ADD: - NHEVENT_KBD(KEYTABLE(KEY_PLUS)); - return 0; + case VK_SUBTRACT: + NHEVENT_KBD(KEYTABLE(KEY_MINUS)); + return 0; - case VK_CLEAR: /* This is the '5' key */ - NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING)); - return 0; + case VK_ADD: + NHEVENT_KBD(KEYTABLE(KEY_PLUS)); + return 0; - case VK_F4: - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - data->mapAcsiiModeSave : - MAP_MODE_TILES - ); - } else { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - MAP_MODE_ASCII_FIT_TO_SCREEN : - MAP_MODE_TILES_FIT_TO_SCREEN - ); - } - return 0; + case VK_CLEAR: /* This is the '5' key */ + NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING)); + return 0; - case VK_F5: - if( IS_MAP_ASCII(iflags.wc_map_mode) ) { - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode(MAP_MODE_TILES_FIT_TO_SCREEN); - } else { - mswin_select_map_mode(MAP_MODE_TILES); - } - } else { - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode(MAP_MODE_ASCII_FIT_TO_SCREEN); - } else { - mswin_select_map_mode(data->mapAcsiiModeSave); - } - } - return 0; + case VK_F4: + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? data->mapAcsiiModeSave + : MAP_MODE_TILES); + } else { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? MAP_MODE_ASCII_FIT_TO_SCREEN + : MAP_MODE_TILES_FIT_TO_SCREEN); + } + return 0; - case VK_RETURN: { - int x, y; - if( WIN_MAP!=WIN_ERR ) { - mswin_map_get_cursor(mswin_hwnd_from_winid(WIN_MAP), &x, &y); - } else { - x = u.ux; - y = u.uy; - } - NHEVENT_MS(CLICK_1, x, y); - } - return 0; - } + case VK_F5: + if (IS_MAP_ASCII(iflags.wc_map_mode)) { + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(MAP_MODE_TILES_FIT_TO_SCREEN); + } else { + mswin_select_map_mode(MAP_MODE_TILES); + } + } else { + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(MAP_MODE_ASCII_FIT_TO_SCREEN); + } else { + mswin_select_map_mode(data->mapAcsiiModeSave); + } + } + return 0; + + case VK_RETURN: { + int x, y; + if (WIN_MAP != WIN_ERR) { + mswin_map_get_cursor(mswin_hwnd_from_winid(WIN_MAP), &x, &y); + } else { + x = u.ux; + y = u.uy; + } + NHEVENT_MS(CLICK_1, x, y); + } + return 0; + } #if defined(WIN_CE_SMARTPHONE) - if( GetNHApp()->bCmdPad && NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE) ) return 0; + if (GetNHApp()->bCmdPad + && NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE)) + return 0; #endif - return 1; /* end of WM_KEYDOWN */ + return 1; /* end of WM_KEYDOWN */ - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ #if defined(WIN_CE_SMARTPHONE) - case WM_KEYUP: - if( GetNHApp()->bCmdPad && NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE) ) return 0; - return 1; /* end of WM_KEYUP */ + case WM_KEYUP: + if (GetNHApp()->bCmdPad + && NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE)) + return 0; + return 1; /* end of WM_KEYUP */ #endif - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_CHAR: + case WM_CHAR: #if defined(WIN_CE_SMARTPHONE) - /* if smartphone cmdpad is up then translation happens - disable WM_CHAR processing - to avoid double input */ - if( GetNHApp()->bCmdPad ) { - return 1; - } + /* if smartphone cmdpad is up then translation happens - disable + WM_CHAR processing + to avoid double input */ + if (GetNHApp()->bCmdPad) { + return 1; + } #endif - if( wParam=='\n' || wParam=='\r' || wParam==C('M') ) return 0; /* we already processed VK_RETURN */ + if (wParam == '\n' || wParam == '\r' || wParam == C('M')) + return 0; /* we already processed VK_RETURN */ - /* all characters go to nethack except Ctrl-P that scrolls message window up */ - if( wParam==C('P') || wParam==C('p') ) { - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); - } else { - NHEVENT_KBD( (lParam & 1<<29)? M(tolower(wParam)) : wParam ); - } - return 0; + /* all characters go to nethack except Ctrl-P that scrolls message + * window up */ + if (wParam == C('P') || wParam == C('p')) { + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD((lParam & 1 << 29) ? M(tolower(wParam)) : wParam); + } + return 0; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_COMMAND: - /* process commands - menu commands mostly */ - if( IsWindow(GetNHApp()->hPopupWnd) ) { - return SendMessage(GetNHApp()->hPopupWnd, message, wParam, lParam); - } else if( onWMCommand(hWnd, wParam, lParam) ) - return DefWindowProc(hWnd, message, wParam, lParam); - else - return 0; + case WM_COMMAND: + /* process commands - menu commands mostly */ + if (IsWindow(GetNHApp()->hPopupWnd)) { + return SendMessage(GetNHApp()->hPopupWnd, message, wParam, + lParam); + } else if (onWMCommand(hWnd, wParam, lParam)) + return DefWindowProc(hWnd, message, wParam, lParam); + else + return 0; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_ACTIVATE: - if( LOWORD(wParam)!=WA_INACTIVE ) { + case WM_ACTIVATE: + if (LOWORD(wParam) != WA_INACTIVE) { #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - if( GetNHApp()->bFullScreen ) - SHFullScreen(GetNHApp()->hMainWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); - else - SHFullScreen(GetNHApp()->hMainWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); + if (GetNHApp()->bFullScreen) + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); + else + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); #endif - mswin_layout_main_window(NULL); - } - break; + mswin_layout_main_window(NULL); + } + break; - case WM_SETTINGCHANGE: + case WM_SETTINGCHANGE: #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - if( GetNHApp()->bFullScreen ) - SHFullScreen(GetNHApp()->hMainWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); - else - SHFullScreen(GetNHApp()->hMainWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); + if (GetNHApp()->bFullScreen) + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); + else + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); #endif - mswin_layout_main_window(NULL); - break; + mswin_layout_main_window(NULL); + break; - case WM_SIZE: - mswin_layout_main_window(NULL); - break; + case WM_SIZE: + mswin_layout_main_window(NULL); + break; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_SETFOCUS: - /* if there is a menu window out there - - transfer input focus to it */ - if( IsWindow( GetNHApp()->hPopupWnd ) ) { - SetFocus( GetNHApp()->hPopupWnd ); - } - break; + case WM_SETFOCUS: + /* if there is a menu window out there - + transfer input focus to it */ + if (IsWindow(GetNHApp()->hPopupWnd)) { + SetFocus(GetNHApp()->hPopupWnd); + } + break; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_CLOSE: - { - /* exit gracefully */ + case WM_CLOSE: { +/* exit gracefully */ #ifdef SAFERHANGUP - /* destroy popup window - it has its own loop and we need to - return control to NetHack core at this point */ - if( IsWindow( GetNHApp()->hPopupWnd ) ) - SendMessage( GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, 0); + /* destroy popup window - it has its own loop and we need to + return control to NetHack core at this point */ + if (IsWindow(GetNHApp()->hPopupWnd)) + SendMessage(GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, 0); - /* tell NetHack core that "hangup" is requested */ - hangup(1); + /* tell NetHack core that "hangup" is requested */ + hangup(1); #else - dosave0(); - terminate(EXIT_SUCCESS); + dosave0(); + terminate(EXIT_SUCCESS); #endif - } return 0; + } + return 0; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - case WM_DESTROY: { - /* apparently we never get here - TODO: work on exit routines - need to send - WM_QUIT somehow */ + case WM_DESTROY: { + /* apparently we never get here + TODO: work on exit routines - need to send + WM_QUIT somehow */ - /* clean up */ - free( (PNHMainWindow)GetWindowLong(hWnd, GWL_USERDATA) ); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); + /* clean up */ + free((PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA)); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); - terminate(EXIT_SUCCESS); - } break; + terminate(EXIT_SUCCESS); + } break; - /*-----------------------------------------------------------------------*/ + /*-----------------------------------------------------------------------*/ - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - switch(wParam) { + switch (wParam) { + /* new window was just added */ + case MSNH_MSG_ADDWND: { + PMSNHMsgAddWnd msg_param = (PMSNHMsgAddWnd) lParam; + HWND child = GetNHApp()->windowlist[msg_param->wid].win; - /* new window was just added */ - case MSNH_MSG_ADDWND: { - PMSNHMsgAddWnd msg_param = (PMSNHMsgAddWnd)lParam; - HWND child = GetNHApp()->windowlist[msg_param->wid].win; + if (GetNHApp()->windowlist[msg_param->wid].type == NHW_MAP) + mswin_select_map_mode(iflags.wc_map_mode); - if( GetNHApp()->windowlist[msg_param->wid].type == NHW_MAP ) - mswin_select_map_mode(iflags.wc_map_mode); - - if( child ) mswin_layout_main_window(child); - } break; - - } + if (child) + mswin_layout_main_window(child); + } break; + } } -/* adjust windows to fit main window layout +/* adjust windows to fit main window layout --------------------------- | Status | +-------------------------+ @@ -559,637 +542,611 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) | MAP | | | | | - +-------------------------+ + +-------------------------+ | Command pad | +-------------------------+ | Messages | --------------------------- */ -void mswin_layout_main_window(HWND changed_child) +void +mswin_layout_main_window(HWND changed_child) { - winid i; - RECT client_rt, wnd_rect; - POINT status_org; - SIZE status_size; - POINT msg_org; - SIZE msg_size; - POINT map_org; - SIZE map_size; - POINT cmd_org; - SIZE cmd_size; - HWND wnd_status, wnd_msg; - PNHMainWindow data; + winid i; + RECT client_rt, wnd_rect; + POINT status_org; + SIZE status_size; + POINT msg_org; + SIZE msg_size; + POINT map_org; + SIZE map_size; + POINT cmd_org; + SIZE cmd_size; + HWND wnd_status, wnd_msg; + PNHMainWindow data; #if defined(WIN_CE_POCKETPC) - SIPINFO sip; - RECT menu_bar; - RECT visible_rt; - POINT pt; + SIPINFO sip; + RECT menu_bar; + RECT visible_rt; + POINT pt; #endif - GetClientRect(GetNHApp()->hMainWnd, &client_rt); + GetClientRect(GetNHApp()->hMainWnd, &client_rt); -#if defined(WIN_CE_POCKETPC) - ZeroMemory(&sip, sizeof(sip)); - sip.cbSize = sizeof(sip); - SHSipInfo(SPI_GETSIPINFO, 0, &sip, 0); - if( GetNHApp()->bFullScreen ) sip.rcVisibleDesktop.top = 0; +#if defined(WIN_CE_POCKETPC) + ZeroMemory(&sip, sizeof(sip)); + sip.cbSize = sizeof(sip); + SHSipInfo(SPI_GETSIPINFO, 0, &sip, 0); + if (GetNHApp()->bFullScreen) + sip.rcVisibleDesktop.top = 0; - /* adjust client rectangle size */ - GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); - client_rt.bottom -= menu_bar.bottom-menu_bar.top; + /* adjust client rectangle size */ + GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); + client_rt.bottom -= menu_bar.bottom - menu_bar.top; - /* calcuate visible rect in client coordinates */ - pt.x = sip.rcVisibleDesktop.left; - pt.y = sip.rcVisibleDesktop.top; - ScreenToClient(GetNHApp()->hMainWnd, &pt); - SetRect(&wnd_rect, - pt.x, - pt.y, - pt.x+sip.rcVisibleDesktop.right-sip.rcVisibleDesktop.left, - pt.y+sip.rcVisibleDesktop.bottom-sip.rcVisibleDesktop.top ); - IntersectRect(&visible_rt, &client_rt, &wnd_rect); + /* calcuate visible rect in client coordinates */ + pt.x = sip.rcVisibleDesktop.left; + pt.y = sip.rcVisibleDesktop.top; + ScreenToClient(GetNHApp()->hMainWnd, &pt); + SetRect(&wnd_rect, pt.x, pt.y, + pt.x + sip.rcVisibleDesktop.right - sip.rcVisibleDesktop.left, + pt.y + sip.rcVisibleDesktop.bottom - sip.rcVisibleDesktop.top); + IntersectRect(&visible_rt, &client_rt, &wnd_rect); #else -# if !defined(WIN_CE_SMARTPHONE) - client_rt.top += CommandBar_Height(GetNHApp()->hMenuBar); -# else - /* Smartphone only */ - if( GetNHApp()->bFullScreen ) { - RECT menu_bar; - GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); - client_rt.bottom -= menu_bar.bottom-menu_bar.top; - } -# endif +#if !defined(WIN_CE_SMARTPHONE) + client_rt.top += CommandBar_Height(GetNHApp()->hMenuBar); +#else + /* Smartphone only */ + if (GetNHApp()->bFullScreen) { + RECT menu_bar; + GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); + client_rt.bottom -= menu_bar.bottom - menu_bar.top; + } +#endif #endif - /* get window data */ - data = (PNHMainWindow)GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); + /* get window data */ + data = (PNHMainWindow) GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); - /* get sizes of child windows */ - wnd_status = mswin_hwnd_from_winid(WIN_STATUS); - if( IsWindow(wnd_status) ) { - mswin_status_window_size(wnd_status, &status_size); - } else { - status_size.cx = status_size.cy = 0; - } + /* get sizes of child windows */ + wnd_status = mswin_hwnd_from_winid(WIN_STATUS); + if (IsWindow(wnd_status)) { + mswin_status_window_size(wnd_status, &status_size); + } else { + status_size.cx = status_size.cy = 0; + } - wnd_msg = mswin_hwnd_from_winid(WIN_MESSAGE); - if( IsWindow(wnd_msg) ) { - mswin_message_window_size(wnd_msg, &msg_size); - } else { - msg_size.cx = msg_size.cy = 0; - } + wnd_msg = mswin_hwnd_from_winid(WIN_MESSAGE); + if (IsWindow(wnd_msg)) { + mswin_message_window_size(wnd_msg, &msg_size); + } else { + msg_size.cx = msg_size.cy = 0; + } - cmd_size.cx = cmd_size.cy = 0; - if( GetNHApp()->bCmdPad && IsWindow(GetNHApp()->hCmdWnd) ) { - mswin_command_window_size(GetNHApp()->hCmdWnd, &cmd_size); - } + cmd_size.cx = cmd_size.cy = 0; + if (GetNHApp()->bCmdPad && IsWindow(GetNHApp()->hCmdWnd)) { + mswin_command_window_size(GetNHApp()->hCmdWnd, &cmd_size); + } - /* set window positions */ +/* set window positions */ - /* calculate the application windows size */ +/* calculate the application windows size */ #if defined(WIN_CE_POCKETPC) - SetRect(&wnd_rect, visible_rt.left, visible_rt.top, visible_rt.right, visible_rt.bottom); - if( sip.fdwFlags & SIPF_ON ) - cmd_size.cx = cmd_size.cy = 0; /* hide keypad window */ + SetRect(&wnd_rect, visible_rt.left, visible_rt.top, visible_rt.right, + visible_rt.bottom); + if (sip.fdwFlags & SIPF_ON) + cmd_size.cx = cmd_size.cy = 0; /* hide keypad window */ #else - SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom); + SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, + client_rt.bottom); #endif #if !defined(WIN_CE_SMARTPHONE) - /* other ports have it at the bottom of the screen */ - cmd_size.cx = (wnd_rect.right-wnd_rect.left); - cmd_org.x = wnd_rect.left; - cmd_org.y = wnd_rect.bottom - cmd_size.cy; - wnd_rect.bottom -= cmd_size.cy; + /* other ports have it at the bottom of the screen */ + cmd_size.cx = (wnd_rect.right - wnd_rect.left); + cmd_org.x = wnd_rect.left; + cmd_org.y = wnd_rect.bottom - cmd_size.cy; + wnd_rect.bottom -= cmd_size.cy; #endif - /* status window */ - switch(iflags.wc_align_status) { - case ALIGN_LEFT: - status_size.cx = (wnd_rect.right-wnd_rect.left)/4; - status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.top; - wnd_rect.left += status_size.cx; - break; + /* status window */ + switch (iflags.wc_align_status) { + case ALIGN_LEFT: + status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + status_size.cy = + (wnd_rect.bottom - wnd_rect.top); // that won't look good + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.top; + wnd_rect.left += status_size.cx; + break; - case ALIGN_RIGHT: - status_size.cx = (wnd_rect.right-wnd_rect.left)/4; - status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good - status_org.x = wnd_rect.right - status_size.cx; - status_org.y = wnd_rect.top; - wnd_rect.right -= status_size.cx; - break; + case ALIGN_RIGHT: + status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + status_size.cy = + (wnd_rect.bottom - wnd_rect.top); // that won't look good + status_org.x = wnd_rect.right - status_size.cx; + status_org.y = wnd_rect.top; + wnd_rect.right -= status_size.cx; + break; - case ALIGN_TOP: - status_size.cx = (wnd_rect.right-wnd_rect.left); - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.top; - wnd_rect.top += status_size.cy; - break; + case ALIGN_TOP: + status_size.cx = (wnd_rect.right - wnd_rect.left); + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.top; + wnd_rect.top += status_size.cy; + break; - case ALIGN_BOTTOM: - default: - status_size.cx = (wnd_rect.right-wnd_rect.left); - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.bottom - status_size.cy; - wnd_rect.bottom -= status_size.cy; - break; - } + case ALIGN_BOTTOM: + default: + status_size.cx = (wnd_rect.right - wnd_rect.left); + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.bottom - status_size.cy; + wnd_rect.bottom -= status_size.cy; + break; + } - /* message window */ - switch(iflags.wc_align_message) { - case ALIGN_LEFT: + /* message window */ + switch (iflags.wc_align_message) { + case ALIGN_LEFT: #if defined(WIN_CE_SMARTPHONE) - /* smartphone has a keypad window on the right (bottom) side of the message window */ - msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); - msg_size.cy = (wnd_rect.bottom-wnd_rect.top) - cmd_size.cy; - msg_org.x = cmd_org.x = wnd_rect.left; - msg_org.y = wnd_rect.top; - cmd_org.y = msg_org.y + msg_size.cy; + /* smartphone has a keypad window on the right (bottom) side of the + * message window */ + msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); + msg_size.cy = (wnd_rect.bottom - wnd_rect.top) - cmd_size.cy; + msg_org.x = cmd_org.x = wnd_rect.left; + msg_org.y = wnd_rect.top; + cmd_org.y = msg_org.y + msg_size.cy; #else - msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; - msg_size.cy = (wnd_rect.bottom-wnd_rect.top); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.top; + msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + msg_size.cy = (wnd_rect.bottom - wnd_rect.top); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.top; #endif - wnd_rect.left += msg_size.cx; + wnd_rect.left += msg_size.cx; - break; + break; - case ALIGN_RIGHT: + case ALIGN_RIGHT: #if defined(WIN_CE_SMARTPHONE) - /* smartphone has a keypad window on the right (bottom) side of the message window */ - msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); - msg_size.cy = (wnd_rect.bottom-wnd_rect.top) - cmd_size.cy; - msg_org.x = cmd_org.x = wnd_rect.right - msg_size.cx; - msg_org.y = wnd_rect.top; - cmd_org.y = msg_org.y + msg_size.cy; + /* smartphone has a keypad window on the right (bottom) side of the + * message window */ + msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); + msg_size.cy = (wnd_rect.bottom - wnd_rect.top) - cmd_size.cy; + msg_org.x = cmd_org.x = wnd_rect.right - msg_size.cx; + msg_org.y = wnd_rect.top; + cmd_org.y = msg_org.y + msg_size.cy; #else - msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; - msg_size.cy = (wnd_rect.bottom-wnd_rect.top); - msg_org.x = wnd_rect.right - msg_size.cx; - msg_org.y = wnd_rect.top; + msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + msg_size.cy = (wnd_rect.bottom - wnd_rect.top); + msg_org.x = wnd_rect.right - msg_size.cx; + msg_org.y = wnd_rect.top; #endif - - wnd_rect.right -= msg_size.cx; - break; - case ALIGN_TOP: + wnd_rect.right -= msg_size.cx; + break; + + case ALIGN_TOP: #if defined(WIN_CE_SMARTPHONE) - /* smartphone has a keypad window on the right side of the message window */ - msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); - msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; - msg_org.x = wnd_rect.left; - cmd_org.x = msg_org.x + msg_size.cx; - msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; + /* smartphone has a keypad window on the right side of the message + * window */ + msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); + msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; + msg_org.x = wnd_rect.left; + cmd_org.x = msg_org.x + msg_size.cx; + msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; #else - msg_size.cx = (wnd_rect.right-wnd_rect.left); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.top; + msg_size.cx = (wnd_rect.right - wnd_rect.left); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.top; #endif - wnd_rect.top += msg_size.cy; - break; + wnd_rect.top += msg_size.cy; + break; - case ALIGN_BOTTOM: - default: + case ALIGN_BOTTOM: + default: #if defined(WIN_CE_SMARTPHONE) - /* smartphone has a keypad window on the right side of the message window */ - msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); - msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; - msg_org.x = wnd_rect.left; - cmd_org.x = msg_org.x + msg_size.cx; - msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; + /* smartphone has a keypad window on the right side of the message + * window */ + msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); + msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; + msg_org.x = wnd_rect.left; + cmd_org.x = msg_org.x + msg_size.cx; + msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; #else - msg_size.cx = (wnd_rect.right-wnd_rect.left); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.bottom - msg_size.cy; + msg_size.cx = (wnd_rect.right - wnd_rect.left); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.bottom - msg_size.cy; #endif - wnd_rect.bottom -= msg_size.cy; - break; - } + wnd_rect.bottom -= msg_size.cy; + break; + } - map_org.x = wnd_rect.left; - map_org.y = wnd_rect.top; - map_size.cx = wnd_rect.right - wnd_rect.left; - map_size.cy = wnd_rect.bottom - wnd_rect.top; + map_org.x = wnd_rect.left; + map_org.y = wnd_rect.top; + map_size.cx = wnd_rect.right - wnd_rect.left; + map_size.cy = wnd_rect.bottom - wnd_rect.top; - /* go through the windows list and adjust sizes */ - for( i=0; iwindowlist[i].win && !GetNHApp()->windowlist[i].dead) { - switch( GetNHApp()->windowlist[i].type ) { - case NHW_MESSAGE: - MoveWindow(GetNHApp()->windowlist[i].win, - msg_org.x, - msg_org.y, - msg_size.cx, - msg_size.cy, - TRUE ); - break; - case NHW_MAP: - MoveWindow(GetNHApp()->windowlist[i].win, - map_org.x, - map_org.y, - map_size.cx, - map_size.cy, - TRUE ); - break; - case NHW_STATUS: - MoveWindow(GetNHApp()->windowlist[i].win, - status_org.x, - status_org.y, - status_size.cx, - status_size.cy, - TRUE ); - break; + /* go through the windows list and adjust sizes */ + for (i = 0; i < MAXWINDOWS; i++) { + if (GetNHApp()->windowlist[i].win + && !GetNHApp()->windowlist[i].dead) { + switch (GetNHApp()->windowlist[i].type) { + case NHW_MESSAGE: + MoveWindow(GetNHApp()->windowlist[i].win, msg_org.x, + msg_org.y, msg_size.cx, msg_size.cy, TRUE); + break; + case NHW_MAP: + MoveWindow(GetNHApp()->windowlist[i].win, map_org.x, + map_org.y, map_size.cx, map_size.cy, TRUE); + break; + case NHW_STATUS: + MoveWindow(GetNHApp()->windowlist[i].win, status_org.x, + status_org.y, status_size.cx, status_size.cy, + TRUE); + break; - case NHW_TEXT: - case NHW_MENU: - case NHW_RIP: - { - POINT menu_org; - SIZE menu_size; + case NHW_TEXT: + case NHW_MENU: + case NHW_RIP: { + POINT menu_org; + SIZE menu_size; - menu_org.x = client_rt.left; - menu_org.y = client_rt.top; + menu_org.x = client_rt.left; + menu_org.y = client_rt.top; #if defined(WIN_CE_POCKETPC) - menu_size.cx = min(sip.rcVisibleDesktop.right-sip.rcVisibleDesktop.left, - client_rt.right - client_rt.left); - menu_size.cy = min(sip.rcVisibleDesktop.bottom-sip.rcVisibleDesktop.top, - client_rt.bottom - client_rt.top); + menu_size.cx = min(sip.rcVisibleDesktop.right + - sip.rcVisibleDesktop.left, + client_rt.right - client_rt.left); + menu_size.cy = min(sip.rcVisibleDesktop.bottom + - sip.rcVisibleDesktop.top, + client_rt.bottom - client_rt.top); #else - menu_size.cx = client_rt.right - client_rt.left; - menu_size.cy = client_rt.bottom - client_rt.top; + menu_size.cx = client_rt.right - client_rt.left; + menu_size.cy = client_rt.bottom - client_rt.top; #endif #if defined(WIN_CE_SMARTPHONE) - /* leave room for the command window */ - if( GetNHApp()->windowlist[i].type == NHW_MENU ) { - menu_size.cy -= cmd_size.cy; - } + /* leave room for the command window */ + if (GetNHApp()->windowlist[i].type == NHW_MENU) { + menu_size.cy -= cmd_size.cy; + } - /* dialogs are popup windows unde SmartPhone so we need - to convert to screen coordinates */ - ClientToScreen(GetNHApp()->hMainWnd, &menu_org); + /* dialogs are popup windows unde SmartPhone so we need + to convert to screen coordinates */ + ClientToScreen(GetNHApp()->hMainWnd, &menu_org); #endif - MoveWindow(GetNHApp()->windowlist[i].win, - menu_org.x, - menu_org.y, - menu_size.cx, - menu_size.cy, - TRUE ); - } break; - } - ShowWindow(GetNHApp()->windowlist[i].win, SW_SHOW); - InvalidateRect(GetNHApp()->windowlist[i].win, NULL, TRUE); - } - } + MoveWindow(GetNHApp()->windowlist[i].win, menu_org.x, + menu_org.y, menu_size.cx, menu_size.cy, TRUE); + } break; + } + ShowWindow(GetNHApp()->windowlist[i].win, SW_SHOW); + InvalidateRect(GetNHApp()->windowlist[i].win, NULL, TRUE); + } + } - if( IsWindow(GetNHApp()->hCmdWnd) ) { - /* show command window only if it exists and - the game is ready (plname is set) */ - if( GetNHApp()->bCmdPad && cmd_size.cx>0 && cmd_size.cy>0 && *plname) { - MoveWindow(GetNHApp()->hCmdWnd, - cmd_org.x, - cmd_org.y, - cmd_size.cx, - cmd_size.cy, - TRUE ); - ShowWindow(GetNHApp()->hCmdWnd, SW_SHOW); - } else { - ShowWindow(GetNHApp()->hCmdWnd, SW_HIDE); - } - } + if (IsWindow(GetNHApp()->hCmdWnd)) { + /* show command window only if it exists and + the game is ready (plname is set) */ + if (GetNHApp()->bCmdPad && cmd_size.cx > 0 && cmd_size.cy > 0 + && *plname) { + MoveWindow(GetNHApp()->hCmdWnd, cmd_org.x, cmd_org.y, cmd_size.cx, + cmd_size.cy, TRUE); + ShowWindow(GetNHApp()->hCmdWnd, SW_SHOW); + } else { + ShowWindow(GetNHApp()->hCmdWnd, SW_HIDE); + } + } } -LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +LRESULT +onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; - PNHMainWindow data; + int wmId, wmEvent; + PNHMainWindow data; - data = (PNHMainWindow)GetWindowLong(hWnd, GWL_USERDATA); - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); + data = (PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA); + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); - // process the menu selections: - switch (wmId) - { - case IDM_ABOUT: - DialogBox(GetNHApp()->hApp, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); - break; + // process the menu selections: + switch (wmId) { + case IDM_ABOUT: + DialogBox(GetNHApp()->hApp, (LPCTSTR) IDD_ABOUTBOX, hWnd, + (DLGPROC) About); + break; - case IDM_EXIT: - done2(); - break; + case IDM_EXIT: + done2(); + break; - case IDM_SAVE: - dosave(); - break; - - case IDM_MAP_TILES: - case IDM_MAP_ASCII4X6: - case IDM_MAP_ASCII6X8: - case IDM_MAP_ASCII8X8: - case IDM_MAP_ASCII16X8: - case IDM_MAP_ASCII7X12: - case IDM_MAP_ASCII8X12: - case IDM_MAP_ASCII12X16: - case IDM_MAP_ASCII16X12: - case IDM_MAP_ASCII10X18: - mswin_select_map_mode(menuid2mapmode(wmId)); - break; + case IDM_SAVE: + dosave(); + break; - case IDM_MAP_FIT_TO_SCREEN: - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - data->mapAcsiiModeSave : - MAP_MODE_TILES - ); - } else { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - MAP_MODE_ASCII_FIT_TO_SCREEN : - MAP_MODE_TILES_FIT_TO_SCREEN - ); - } - break; + case IDM_MAP_TILES: + case IDM_MAP_ASCII4X6: + case IDM_MAP_ASCII6X8: + case IDM_MAP_ASCII8X8: + case IDM_MAP_ASCII16X8: + case IDM_MAP_ASCII7X12: + case IDM_MAP_ASCII8X12: + case IDM_MAP_ASCII12X16: + case IDM_MAP_ASCII16X12: + case IDM_MAP_ASCII10X18: + mswin_select_map_mode(menuid2mapmode(wmId)); + break; - case IDM_VIEW_KEYPAD: - GetNHApp()->bCmdPad = !GetNHApp()->bCmdPad; - CheckMenuItem( - _get_main_menu(ID_VIEW), - IDM_VIEW_KEYPAD, - MF_BYCOMMAND | - (GetNHApp()->bCmdPad? MF_CHECKED : MF_UNCHECKED) - ); - mswin_layout_main_window(GetNHApp()->hCmdWnd); - break; + case IDM_MAP_FIT_TO_SCREEN: + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? data->mapAcsiiModeSave + : MAP_MODE_TILES); + } else { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? MAP_MODE_ASCII_FIT_TO_SCREEN + : MAP_MODE_TILES_FIT_TO_SCREEN); + } + break; - case IDM_VIEW_OPTIONS: - doset(); - break; + case IDM_VIEW_KEYPAD: + GetNHApp()->bCmdPad = !GetNHApp()->bCmdPad; + CheckMenuItem( + _get_main_menu(ID_VIEW), IDM_VIEW_KEYPAD, + MF_BYCOMMAND | (GetNHApp()->bCmdPad ? MF_CHECKED : MF_UNCHECKED)); + mswin_layout_main_window(GetNHApp()->hCmdWnd); + break; - case IDM_DIRECT_COMMAND: /* SmartPhone: display dialog to type in arbitary command text */ - mswin_direct_command(); - break; + case IDM_VIEW_OPTIONS: + doset(); + break; - case IDM_HELP_LONG: - display_file(HELP, TRUE); - break; - - case IDM_HELP_COMMANDS: - display_file(SHELP, TRUE); - break; - - case IDM_HELP_HISTORY: - (void) dohistory(); - break; - - case IDM_HELP_INFO_CHAR: - (void) dowhatis(); - break; - - case IDM_HELP_INFO_KEY: - (void) dowhatdoes(); - break; - - case IDM_HELP_OPTIONS: - option_help(); - break; - - case IDM_HELP_OPTIONS_LONG: - display_file(OPTIONFILE, TRUE); - break; - - case IDM_HELP_EXTCMD: - (void) doextlist(); - break; - - case IDM_HELP_LICENSE: - display_file(LICENSE, TRUE); - break; + case IDM_DIRECT_COMMAND: /* SmartPhone: display dialog to type in arbitary + command text */ + mswin_direct_command(); + break; - case IDM_HELP_MENU: - dohelp(); - break; + case IDM_HELP_LONG: + display_file(HELP, TRUE); + break; - default: - return 1; - } - return 0; + case IDM_HELP_COMMANDS: + display_file(SHELP, TRUE); + break; + + case IDM_HELP_HISTORY: + (void) dohistory(); + break; + + case IDM_HELP_INFO_CHAR: + (void) dowhatis(); + break; + + case IDM_HELP_INFO_KEY: + (void) dowhatdoes(); + break; + + case IDM_HELP_OPTIONS: + option_help(); + break; + + case IDM_HELP_OPTIONS_LONG: + display_file(OPTIONFILE, TRUE); + break; + + case IDM_HELP_EXTCMD: + (void) doextlist(); + break; + + case IDM_HELP_LICENSE: + display_file(LICENSE, TRUE); + break; + + case IDM_HELP_MENU: + dohelp(); + break; + + default: + return 1; + } + return 0; } // Mesage handler for about box. -LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - char buf[BUFSZ]; - TCHAR wbuf[NHSTR_BUFSIZE]; - RECT main_rt, dlg_rt; - SIZE dlg_sz; + char buf[BUFSZ]; + TCHAR wbuf[NHSTR_BUFSIZE]; + RECT main_rt, dlg_rt; + SIZE dlg_sz; - switch (message) - { - case WM_INITDIALOG: - getversionstring(buf); - SetDlgItemText(hDlg, IDC_ABOUT_VERSION, NH_A2W(buf, wbuf, NHSTR_BUFSIZE)); + switch (message) { + case WM_INITDIALOG: + getversionstring(buf); + SetDlgItemText(hDlg, IDC_ABOUT_VERSION, + NH_A2W(buf, wbuf, NHSTR_BUFSIZE)); - SetDlgItemText(hDlg, IDC_ABOUT_COPYRIGHT, - NH_A2W( - COPYRIGHT_BANNER_A "\n" - COPYRIGHT_BANNER_B "\n" - COPYRIGHT_BANNER_C "\n" - COPYRIGHT_BANNER_D, - wbuf, - NHSTR_BUFSIZE - ) ); - + SetDlgItemText(hDlg, IDC_ABOUT_COPYRIGHT, + NH_A2W(COPYRIGHT_BANNER_A "\n" COPYRIGHT_BANNER_B + "\n" COPYRIGHT_BANNER_C + "\n" COPYRIGHT_BANNER_D, + wbuf, NHSTR_BUFSIZE)); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hDlg, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hDlg, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hDlg, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hDlg, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - return TRUE; + return TRUE; - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } - break; - } + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + break; + } return FALSE; } - /* Set map display mode */ -void mswin_select_map_mode(int mode) +void +mswin_select_map_mode(int mode) { - HMENU hmenuMap; - PNHMainWindow data; - winid map_id; + HMENU hmenuMap; + PNHMainWindow data; + winid map_id; - map_id = WIN_MAP; - data = (PNHMainWindow)GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); + map_id = WIN_MAP; + data = (PNHMainWindow) GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); #if defined(WIN_CE_SMARTPHONE) - /* Smartphone manu has only 2 items */ - hmenuMap = _get_main_menu(ID_VIEW); + /* Smartphone manu has only 2 items */ + hmenuMap = _get_main_menu(ID_VIEW); #else - hmenuMap = _get_main_menu(ID_MAP); + hmenuMap = _get_main_menu(ID_MAP); #endif - /* override for Rogue level */ - if( Is_rogue_level(&u.uz) && !IS_MAP_ASCII(mode) ) return; + /* override for Rogue level */ + if (Is_rogue_level(&u.uz) && !IS_MAP_ASCII(mode)) + return; - /* set map mode menu mark */ - if( IS_MAP_ASCII(mode) ) { - CheckMenuRadioItem( - hmenuMap, - IDM_MAP_TILES, - IDM_MAP_FIT_TO_SCREEN, - mapmode2menuid( IS_MAP_FIT_TO_SCREEN(mode)? data->mapAcsiiModeSave : mode ), - MF_BYCOMMAND); - } else { - CheckMenuRadioItem( - hmenuMap, - IDM_MAP_TILES, - IDM_MAP_FIT_TO_SCREEN, - mapmode2menuid( MAP_MODE_TILES ), - MF_BYCOMMAND); - } + /* set map mode menu mark */ + if (IS_MAP_ASCII(mode)) { + CheckMenuRadioItem(hmenuMap, IDM_MAP_TILES, IDM_MAP_FIT_TO_SCREEN, + mapmode2menuid(IS_MAP_FIT_TO_SCREEN(mode) + ? data->mapAcsiiModeSave + : mode), + MF_BYCOMMAND); + } else { + CheckMenuRadioItem(hmenuMap, IDM_MAP_TILES, IDM_MAP_FIT_TO_SCREEN, + mapmode2menuid(MAP_MODE_TILES), MF_BYCOMMAND); + } #if defined(WIN_CE_SMARTPHONE) - /* update "Fit To Screen" item text */ - { - TCHAR wbuf[BUFSZ]; - TBBUTTONINFO tbbi; + /* update "Fit To Screen" item text */ + { + TCHAR wbuf[BUFSZ]; + TBBUTTONINFO tbbi; - ZeroMemory( wbuf, sizeof(wbuf) ); - if( !LoadString( - GetNHApp()->hApp, - (IS_MAP_FIT_TO_SCREEN(mode)? IDS_CAP_NORMALMAP : IDS_CAP_ENTIREMAP), - wbuf, - BUFSZ) ) { - panic("cannot load main menu strings"); - } + ZeroMemory(wbuf, sizeof(wbuf)); + if (!LoadString(GetNHApp()->hApp, + (IS_MAP_FIT_TO_SCREEN(mode) ? IDS_CAP_NORMALMAP + : IDS_CAP_ENTIREMAP), + wbuf, BUFSZ)) { + panic("cannot load main menu strings"); + } - ZeroMemory( &tbbi, sizeof(tbbi) ); - tbbi.cbSize = sizeof(tbbi); - tbbi.dwMask = TBIF_TEXT; - tbbi.pszText = wbuf; - if( !SendMessage( - GetNHApp()->hMenuBar, - TB_SETBUTTONINFO, - IDM_MAP_FIT_TO_SCREEN, - (LPARAM)&tbbi) ) { - error( "Cannot update IDM_MAP_FIT_TO_SCREEN menu item." ); - } - } + ZeroMemory(&tbbi, sizeof(tbbi)); + tbbi.cbSize = sizeof(tbbi); + tbbi.dwMask = TBIF_TEXT; + tbbi.pszText = wbuf; + if (!SendMessage(GetNHApp()->hMenuBar, TB_SETBUTTONINFO, + IDM_MAP_FIT_TO_SCREEN, (LPARAM) &tbbi)) { + error("Cannot update IDM_MAP_FIT_TO_SCREEN menu item."); + } + } #else - /* set fit-to-screen mode mark */ - CheckMenuItem( - hmenuMap, - IDM_MAP_FIT_TO_SCREEN, - MF_BYCOMMAND | - (IS_MAP_FIT_TO_SCREEN(mode)? MF_CHECKED : MF_UNCHECKED) - ); + /* set fit-to-screen mode mark */ + CheckMenuItem(hmenuMap, IDM_MAP_FIT_TO_SCREEN, + MF_BYCOMMAND | (IS_MAP_FIT_TO_SCREEN(mode) ? MF_CHECKED + : MF_UNCHECKED)); #endif - if( IS_MAP_ASCII(iflags.wc_map_mode) && !IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { - data->mapAcsiiModeSave = iflags.wc_map_mode; - } + if (IS_MAP_ASCII(iflags.wc_map_mode) + && !IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + data->mapAcsiiModeSave = iflags.wc_map_mode; + } - iflags.wc_map_mode = mode; - - /* - ** first, check if WIN_MAP has been inialized. - ** If not - attempt to retrieve it by type, then check it again - */ - if( WIN_MAP!=WIN_ERR ) - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), mode); + iflags.wc_map_mode = mode; + + /* + ** first, check if WIN_MAP has been inialized. + ** If not - attempt to retrieve it by type, then check it again + */ + if (WIN_MAP != WIN_ERR) + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), mode); } static struct t_menu2mapmode { - int menuID; - int mapMode; -} _menu2mapmode[] = -{ - { IDM_MAP_TILES, MAP_MODE_TILES }, - { IDM_MAP_ASCII4X6, MAP_MODE_ASCII4x6 }, - { IDM_MAP_ASCII6X8, MAP_MODE_ASCII6x8 }, - { IDM_MAP_ASCII8X8, MAP_MODE_ASCII8x8 }, - { IDM_MAP_ASCII16X8, MAP_MODE_ASCII16x8 }, - { IDM_MAP_ASCII7X12, MAP_MODE_ASCII7x12 }, - { IDM_MAP_ASCII8X12, MAP_MODE_ASCII8x12 }, - { IDM_MAP_ASCII12X16, MAP_MODE_ASCII12x16 }, - { IDM_MAP_ASCII16X12, MAP_MODE_ASCII16x12 }, - { IDM_MAP_ASCII10X18, MAP_MODE_ASCII10x18 }, - { IDM_MAP_FIT_TO_SCREEN, MAP_MODE_ASCII_FIT_TO_SCREEN }, - { -1, -1 } -}; + int menuID; + int mapMode; +} _menu2mapmode[] = { { IDM_MAP_TILES, MAP_MODE_TILES }, + { IDM_MAP_ASCII4X6, MAP_MODE_ASCII4x6 }, + { IDM_MAP_ASCII6X8, MAP_MODE_ASCII6x8 }, + { IDM_MAP_ASCII8X8, MAP_MODE_ASCII8x8 }, + { IDM_MAP_ASCII16X8, MAP_MODE_ASCII16x8 }, + { IDM_MAP_ASCII7X12, MAP_MODE_ASCII7x12 }, + { IDM_MAP_ASCII8X12, MAP_MODE_ASCII8x12 }, + { IDM_MAP_ASCII12X16, MAP_MODE_ASCII12x16 }, + { IDM_MAP_ASCII16X12, MAP_MODE_ASCII16x12 }, + { IDM_MAP_ASCII10X18, MAP_MODE_ASCII10x18 }, + { IDM_MAP_FIT_TO_SCREEN, MAP_MODE_ASCII_FIT_TO_SCREEN }, + { -1, -1 } }; -int menuid2mapmode(int menuid) +int +menuid2mapmode(int menuid) { - struct t_menu2mapmode* p; - for( p = _menu2mapmode; p->mapMode!=-1; p++ ) - if(p->menuID==menuid ) return p->mapMode; - return -1; + struct t_menu2mapmode *p; + for (p = _menu2mapmode; p->mapMode != -1; p++) + if (p->menuID == menuid) + return p->mapMode; + return -1; } -int mapmode2menuid(int map_mode) +int +mapmode2menuid(int map_mode) { - struct t_menu2mapmode* p; - for( p = _menu2mapmode; p->mapMode!=-1; p++ ) - if(p->mapMode==map_mode ) return p->menuID; - return -1; + struct t_menu2mapmode *p; + for (p = _menu2mapmode; p->mapMode != -1; p++) + if (p->mapMode == map_mode) + return p->menuID; + return -1; } -HMENU _get_main_menu(UINT menu_id) +HMENU +_get_main_menu(UINT menu_id) { - HMENU hmenuMap; + HMENU hmenuMap; #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - TBBUTTONINFO tbbi; + TBBUTTONINFO tbbi; #endif #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - tbbi.cbSize = sizeof(tbbi); - tbbi.dwMask = TBIF_LPARAM; - SendMessage( GetNHApp()->hMenuBar, TB_GETBUTTONINFO, menu_id, (LPARAM)&tbbi); - hmenuMap = (HMENU)tbbi.lParam; + tbbi.cbSize = sizeof(tbbi); + tbbi.dwMask = TBIF_LPARAM; + SendMessage(GetNHApp()->hMenuBar, TB_GETBUTTONINFO, menu_id, + (LPARAM) &tbbi); + hmenuMap = (HMENU) tbbi.lParam; #else - hmenuMap = CommandBar_GetMenu(GetNHApp()->hMenuBar, 0); + hmenuMap = CommandBar_GetMenu(GetNHApp()->hMenuBar, 0); #endif - return hmenuMap; + return hmenuMap; } /* SmartPhone: display dialog to type arbitrary command text */ -void mswin_direct_command() +void +mswin_direct_command() { - char cmd[BUFSZ]; - ZeroMemory(cmd, sizeof(cmd)); - mswin_getlin("Type cmd text", cmd); - if( cmd[0] ) { - /* feed command to nethack */ - char *p = cmd; - cmd[32] = '\x0'; /* truncate at 32 chars */ - while(*p) { - NHEVENT_KBD(*p); - p++; - } - if( cmd[0]!='\033' ) mswin_putstr(WIN_MESSAGE, ATR_NONE, cmd); - } + char cmd[BUFSZ]; + ZeroMemory(cmd, sizeof(cmd)); + mswin_getlin("Type cmd text", cmd); + if (cmd[0]) { + /* feed command to nethack */ + char *p = cmd; + cmd[32] = '\x0'; /* truncate at 32 chars */ + while (*p) { + NHEVENT_KBD(*p); + p++; + } + if (cmd[0] != '\033') + mswin_putstr(WIN_MESSAGE, ATR_NONE, cmd); + } } diff --git a/sys/wince/mhmap.c b/sys/wince/mhmap.c index f9ba88299..b97e7d4c9 100644 --- a/sys/wince/mhmap.c +++ b/sys/wince/mhmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhmap.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhmap.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */ /* NetHack 3.6 mhmap.c $Date: 2009/10/13 01:55:11 $ $Revision: 1.10 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -18,22 +18,22 @@ extern short glyph2tile[]; /* map window data */ typedef struct mswin_nethack_map_window { - int map[COLNO][ROWNO]; /* glyph map */ + int map[COLNO][ROWNO]; /* glyph map */ - int mapMode; /* current map mode */ - boolean bAsciiMode; /* switch ASCII/tiled mode */ - boolean bFitToScreenMode; /* switch Fit map to screen mode on/off */ - int xPos, yPos; /* scroll position */ - int xPageSize, yPageSize; /* scroll page size */ - int xCur, yCur; /* position of the cursor */ - int xScrTile, yScrTile; /* size of display tile */ - POINT map_orig; /* map origin point */ - HFONT hMapFont; /* font for ASCII mode */ - int xLastMouseClick, yLastMouseClick; /* last mouse click */ + int mapMode; /* current map mode */ + boolean bAsciiMode; /* switch ASCII/tiled mode */ + boolean bFitToScreenMode; /* switch Fit map to screen mode on/off */ + int xPos, yPos; /* scroll position */ + int xPageSize, yPageSize; /* scroll page size */ + int xCur, yCur; /* position of the cursor */ + int xScrTile, yScrTile; /* size of display tile */ + POINT map_orig; /* map origin point */ + HFONT hMapFont; /* font for ASCII mode */ + int xLastMouseClick, yLastMouseClick; /* last mouse click */ } NHMapWindow, *PNHMapWindow; static TCHAR szNHMapWindowClass[] = TEXT("MSNethackMapWndClass"); -LRESULT CALLBACK MapWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK MapWndProc(HWND, UINT, WPARAM, LPARAM); static void register_map_window_class(void); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -42,812 +42,838 @@ static void onPaint(HWND hWnd); static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); static void nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) -static void nhglyph2charcolor(short glyph, uchar* ch, int* color); +static void nhglyph2charcolor(short glyph, uchar *ch, int *color); #endif static COLORREF nhcolor_to_RGB(int c); -HWND mswin_init_map_window () { - static int run_once = 0; - HWND ret; - DWORD styles; +HWND +mswin_init_map_window() +{ + static int run_once = 0; + HWND ret; + DWORD styles; - if( !run_once ) { - register_map_window_class(); - run_once = 1; - } - - styles = WS_CHILD | WS_CLIPSIBLINGS; - if( !GetNHApp()->bHideScrollBars ) styles |= WS_HSCROLL | WS_VSCROLL; - ret = CreateWindow( - szNHMapWindowClass, /* registered class name */ - NULL, /* window name */ - styles, /* window style */ - 0, /* horizontal position of window - set it later */ - 0, /* vertical position of window - set it later */ - 0, /* window width - set it later */ - 0, /* window height - set it later*/ - GetNHApp()->hMainWnd, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL ); /* window-creation data */ - if( !ret ) { - panic("Cannot create map window"); - } - return ret; + if (!run_once) { + register_map_window_class(); + run_once = 1; + } + + styles = WS_CHILD | WS_CLIPSIBLINGS; + if (!GetNHApp()->bHideScrollBars) + styles |= WS_HSCROLL | WS_VSCROLL; + ret = CreateWindow( + szNHMapWindowClass, /* registered class name */ + NULL, /* window name */ + styles, /* window style */ + 0, /* horizontal position of window - set it later */ + 0, /* vertical position of window - set it later */ + 0, /* window width - set it later */ + 0, /* window height - set it later*/ + GetNHApp()->hMainWnd, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL); /* window-creation data */ + if (!ret) { + panic("Cannot create map window"); + } + return ret; } -void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) +void +mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) { - PNHMapWindow data; - RECT client_rt; - SCROLLINFO si; - SIZE wnd_size; - LOGFONT lgfnt; + PNHMapWindow data; + RECT client_rt; + SCROLLINFO si; + SIZE wnd_size; + LOGFONT lgfnt; - /* check arguments */ - if( !IsWindow(hWnd) || - !lpsz || - lpsz->cx<=0 || - lpsz->cy<=0 ) return; + /* check arguments */ + if (!IsWindow(hWnd) || !lpsz || lpsz->cx <= 0 || lpsz->cy <= 0) + return; - /* calculate window size */ - GetClientRect(hWnd, &client_rt); - wnd_size.cx = client_rt.right - client_rt.left; - wnd_size.cy = client_rt.bottom - client_rt.top; - - /* set new screen tile size */ - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - data->xScrTile = - max(1, (data->bFitToScreenMode? wnd_size.cx : lpsz->cx) / COLNO); - data->yScrTile = - max(1, (data->bFitToScreenMode? wnd_size.cy : lpsz->cy) / ROWNO); + /* calculate window size */ + GetClientRect(hWnd, &client_rt); + wnd_size.cx = client_rt.right - client_rt.left; + wnd_size.cy = client_rt.bottom - client_rt.top; - /* set map origin point */ - data->map_orig.x = max(0, client_rt.left + (wnd_size.cx - data->xScrTile*COLNO)/2 ); - data->map_orig.y = max(0, client_rt.top + (wnd_size.cy - data->yScrTile*ROWNO)/2 ); + /* set new screen tile size */ + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); + data->xScrTile = + max(1, (data->bFitToScreenMode ? wnd_size.cx : lpsz->cx) / COLNO); + data->yScrTile = + max(1, (data->bFitToScreenMode ? wnd_size.cy : lpsz->cy) / ROWNO); - data->map_orig.x -= data->map_orig.x % data->xScrTile; - data->map_orig.y -= data->map_orig.y % data->yScrTile; + /* set map origin point */ + data->map_orig.x = + max(0, client_rt.left + (wnd_size.cx - data->xScrTile * COLNO) / 2); + data->map_orig.y = + max(0, client_rt.top + (wnd_size.cy - data->yScrTile * ROWNO) / 2); - /* adjust horizontal scroll bar */ - if( data->bFitToScreenMode ) - data->xPageSize = COLNO+1; /* disable scroll bar */ - else - data->xPageSize = wnd_size.cx/data->xScrTile; + data->map_orig.x -= data->map_orig.x % data->xScrTile; + data->map_orig.y -= data->map_orig.y % data->yScrTile; - if( data->xPageSize >= COLNO ) { - data->xPos = 0; - GetNHApp()->bNoHScroll = TRUE; - } else { - GetNHApp()->bNoHScroll = FALSE; - data->xPos = max(0, min(COLNO-data->xPageSize+1, u.ux - data->xPageSize/2)); - } + /* adjust horizontal scroll bar */ + if (data->bFitToScreenMode) + data->xPageSize = COLNO + 1; /* disable scroll bar */ + else + data->xPageSize = wnd_size.cx / data->xScrTile; - if( !GetNHApp()->bHideScrollBars ) { - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = COLNO; - si.nPage = data->xPageSize; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); - } + if (data->xPageSize >= COLNO) { + data->xPos = 0; + GetNHApp()->bNoHScroll = TRUE; + } else { + GetNHApp()->bNoHScroll = FALSE; + data->xPos = max( + 0, min(COLNO - data->xPageSize + 1, u.ux - data->xPageSize / 2)); + } - /* adjust vertical scroll bar */ - if( data->bFitToScreenMode ) - data->yPageSize = ROWNO+1; /* disable scroll bar */ - else - data->yPageSize = wnd_size.cy/data->yScrTile; + if (!GetNHApp()->bHideScrollBars) { + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = COLNO; + si.nPage = data->xPageSize; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + } - if( data->yPageSize >= ROWNO ) { - data->yPos = 0; - GetNHApp()->bNoVScroll = TRUE; - } else { - GetNHApp()->bNoVScroll = FALSE; - data->yPos = max(0, min(ROWNO-data->yPageSize+1, u.uy - data->yPageSize/2)); - } + /* adjust vertical scroll bar */ + if (data->bFitToScreenMode) + data->yPageSize = ROWNO + 1; /* disable scroll bar */ + else + data->yPageSize = wnd_size.cy / data->yScrTile; - if( !GetNHApp()->bHideScrollBars ) { - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = ROWNO; - si.nPage = data->yPageSize; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - } + if (data->yPageSize >= ROWNO) { + data->yPos = 0; + GetNHApp()->bNoVScroll = TRUE; + } else { + GetNHApp()->bNoVScroll = FALSE; + data->yPos = max( + 0, min(ROWNO - data->yPageSize + 1, u.uy - data->yPageSize / 2)); + } - /* create font */ - if( data->hMapFont ) DeleteObject(data->hMapFont); - ZeroMemory(&lgfnt, sizeof(lgfnt)); - lgfnt.lfHeight = -data->yScrTile; // height of font - lgfnt.lfWidth = -data->xScrTile; // average character width - lgfnt.lfEscapement = 0; // angle of escapement - lgfnt.lfOrientation = 0; // base-line orientation angle - lgfnt.lfWeight = FW_NORMAL; // font weight - lgfnt.lfItalic = FALSE; // italic attribute option - lgfnt.lfUnderline = FALSE; // underline attribute option - lgfnt.lfStrikeOut = FALSE; // strikeout attribute option - lgfnt.lfCharSet = mswin_charset(); // character set identifier - lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision - lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision - lgfnt.lfQuality = DEFAULT_QUALITY; // output quality - if( iflags.wc_font_map && - *iflags.wc_font_map ) { - lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family - NH_A2W(iflags.wc_font_map, lgfnt.lfFaceName, LF_FACESIZE); - } else { - lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family - _tcsncpy(lgfnt.lfFaceName, NHMAP_FONT_NAME, LF_FACESIZE); - } - data->hMapFont = CreateFontIndirect(&lgfnt); + if (!GetNHApp()->bHideScrollBars) { + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = ROWNO; + si.nPage = data->yPageSize; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + } - mswin_cliparound(data->xCur, data->yCur); + /* create font */ + if (data->hMapFont) + DeleteObject(data->hMapFont); + ZeroMemory(&lgfnt, sizeof(lgfnt)); + lgfnt.lfHeight = -data->yScrTile; // height of font + lgfnt.lfWidth = -data->xScrTile; // average character width + lgfnt.lfEscapement = 0; // angle of escapement + lgfnt.lfOrientation = 0; // base-line orientation angle + lgfnt.lfWeight = FW_NORMAL; // font weight + lgfnt.lfItalic = FALSE; // italic attribute option + lgfnt.lfUnderline = FALSE; // underline attribute option + lgfnt.lfStrikeOut = FALSE; // strikeout attribute option + lgfnt.lfCharSet = mswin_charset(); // character set identifier + lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision + lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision + lgfnt.lfQuality = DEFAULT_QUALITY; // output quality + if (iflags.wc_font_map && *iflags.wc_font_map) { + lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family + NH_A2W(iflags.wc_font_map, lgfnt.lfFaceName, LF_FACESIZE); + } else { + lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family + _tcsncpy(lgfnt.lfFaceName, NHMAP_FONT_NAME, LF_FACESIZE); + } + data->hMapFont = CreateFontIndirect(&lgfnt); - if(redraw) InvalidateRect(hWnd, NULL, TRUE); + mswin_cliparound(data->xCur, data->yCur); + + if (redraw) + InvalidateRect(hWnd, NULL, TRUE); } /* set map mode */ -int mswin_map_mode(HWND hWnd, int mode) +int +mswin_map_mode(HWND hWnd, int mode) { - PNHMapWindow data; - int oldMode; - SIZE mapSize; + PNHMapWindow data; + int oldMode; + SIZE mapSize; - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( mode == data->mapMode ) return mode; - - oldMode = data->mapMode; - data->mapMode = mode; + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (mode == data->mapMode) + return mode; - switch( data->mapMode ) { + oldMode = data->mapMode; + data->mapMode = mode; - case MAP_MODE_ASCII4x6: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 4*COLNO; - mapSize.cy = 6*ROWNO; - break; + switch (data->mapMode) { + case MAP_MODE_ASCII4x6: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 4 * COLNO; + mapSize.cy = 6 * ROWNO; + break; - case MAP_MODE_ASCII6x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 6*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII6x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 6 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII8x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 8*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII8x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 8 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII16x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 16*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII16x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 16 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII7x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 7*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII7x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 7 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII8x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 8*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII8x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 8 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII16x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 16*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII16x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 16 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII12x16: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 12*COLNO; - mapSize.cy = 16*ROWNO; - break; + case MAP_MODE_ASCII12x16: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 12 * COLNO; + mapSize.cy = 16 * ROWNO; + break; - case MAP_MODE_ASCII10x18: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 10*COLNO; - mapSize.cy = 18*ROWNO; - break; + case MAP_MODE_ASCII10x18: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 10 * COLNO; + mapSize.cy = 18 * ROWNO; + break; - case MAP_MODE_ASCII_FIT_TO_SCREEN: { - RECT client_rt; - GetClientRect(hWnd, &client_rt); - mapSize.cx = client_rt.right - client_rt.left; - mapSize.cy = client_rt.bottom - client_rt.top; + case MAP_MODE_ASCII_FIT_TO_SCREEN: { + RECT client_rt; + GetClientRect(hWnd, &client_rt); + mapSize.cx = client_rt.right - client_rt.left; + mapSize.cy = client_rt.bottom - client_rt.top; - data->bAsciiMode = TRUE; - data->bFitToScreenMode = TRUE; - } break; + data->bAsciiMode = TRUE; + data->bFitToScreenMode = TRUE; + } break; - case MAP_MODE_TILES_FIT_TO_SCREEN: { - RECT client_rt; - GetClientRect(hWnd, &client_rt); - mapSize.cx = client_rt.right - client_rt.left; - mapSize.cy = client_rt.bottom - client_rt.top; + case MAP_MODE_TILES_FIT_TO_SCREEN: { + RECT client_rt; + GetClientRect(hWnd, &client_rt); + mapSize.cx = client_rt.right - client_rt.left; + mapSize.cy = client_rt.bottom - client_rt.top; - data->bAsciiMode = FALSE; - data->bFitToScreenMode = TRUE; - } break; + data->bAsciiMode = FALSE; + data->bFitToScreenMode = TRUE; + } break; - case MAP_MODE_TILES: - default: - data->bAsciiMode = FALSE; - data->bFitToScreenMode = FALSE; - mapSize.cx = GetNHApp()->mapTile_X*COLNO; - mapSize.cy = GetNHApp()->mapTile_Y*ROWNO; - break; - } + case MAP_MODE_TILES: + default: + data->bAsciiMode = FALSE; + data->bFitToScreenMode = FALSE; + mapSize.cx = GetNHApp()->mapTile_X * COLNO; + mapSize.cy = GetNHApp()->mapTile_Y * ROWNO; + break; + } - mswin_map_stretch(hWnd, &mapSize, TRUE); + mswin_map_stretch(hWnd, &mapSize, TRUE); - return oldMode; + return oldMode; } /* retrieve cursor position */ -void mswin_map_get_cursor(HWND hWnd, int* x, int* y) +void +mswin_map_get_cursor(HWND hWnd, int *x, int *y) { - PNHMapWindow data; + PNHMapWindow data; - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( !data ) panic("mswin_map_get_cursor: no window data"); - if( x ) *x = data->xCur; - if( y ) *y = data->yCur; + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (!data) + panic("mswin_map_get_cursor: no window data"); + if (x) + *x = data->xCur; + if (y) + *y = data->yCur; } /* register window class for map window */ -void register_map_window_class() +void +register_map_window_class() { - WNDCLASS wcex; - ZeroMemory( &wcex, sizeof(wcex)); + WNDCLASS wcex; + ZeroMemory(&wcex, sizeof(wcex)); - /* window class */ - wcex.style = CS_NOCLOSE | CS_DBLCLKS; - wcex.lpfnWndProc = (WNDPROC)MapWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); /* set backgroup here */ - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szNHMapWindowClass; + /* window class */ + wcex.style = CS_NOCLOSE | CS_DBLCLKS; + wcex.lpfnWndProc = (WNDPROC) MapWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = + CreateSolidBrush(RGB(0, 0, 0)); /* set backgroup here */ + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szNHMapWindowClass; - if( !RegisterClass(&wcex) ) { - panic("cannot register Map window class"); - } + if (!RegisterClass(&wcex)) { + panic("cannot register Map window class"); + } } - -/* map window procedure */ -LRESULT CALLBACK MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +/* map window procedure */ +LRESULT CALLBACK +MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - int x, y; - - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch (message) - { - case WM_CREATE: - onCreate( hWnd, wParam, lParam ); - break; + PNHMapWindow data; + int x, y; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (message) { + case WM_CREATE: + onCreate(hWnd, wParam, lParam); + break; - case WM_PAINT: - onPaint(hWnd); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SETFOCUS: - /* transfer focus back to the main window */ - SetFocus(GetNHApp()->hMainWnd); - break; + case WM_PAINT: + onPaint(hWnd); + break; - case WM_HSCROLL: - onMSNH_HScroll(hWnd, wParam, lParam); - break; + case WM_SETFOCUS: + /* transfer focus back to the main window */ + SetFocus(GetNHApp()->hMainWnd); + break; - case WM_VSCROLL: - onMSNH_VScroll(hWnd, wParam, lParam); - break; + case WM_HSCROLL: + onMSNH_HScroll(hWnd, wParam, lParam); + break; - case WM_SIZE: - { - SIZE size; + case WM_VSCROLL: + onMSNH_VScroll(hWnd, wParam, lParam); + break; - if( data->bFitToScreenMode ) { - size.cx = LOWORD(lParam); - size.cy = HIWORD(lParam); - } else { - /* mapping factor is unchaged we just need to adjust scroll bars */ - size.cx = data->xScrTile*COLNO; - size.cy = data->yScrTile*ROWNO; - } - mswin_map_stretch(hWnd, &size, TRUE); - } - break; + case WM_SIZE: { + SIZE size; - case WM_LBUTTONDOWN: - x = max(0, min(COLNO, data->xPos + (LOWORD(lParam)-data->map_orig.x)/data->xScrTile)); - y = max(0, min(ROWNO, data->yPos + (HIWORD(lParam)-data->map_orig.y)/data->yScrTile)); + if (data->bFitToScreenMode) { + size.cx = LOWORD(lParam); + size.cy = HIWORD(lParam); + } else { + /* mapping factor is unchaged we just need to adjust scroll bars + */ + size.cx = data->xScrTile * COLNO; + size.cy = data->yScrTile * ROWNO; + } + mswin_map_stretch(hWnd, &size, TRUE); + } break; - NHEVENT_MS( CLICK_1, x, y); + case WM_LBUTTONDOWN: + x = max(0, min(COLNO, data->xPos + + (LOWORD(lParam) - data->map_orig.x) + / data->xScrTile)); + y = max(0, min(ROWNO, data->yPos + + (HIWORD(lParam) - data->map_orig.y) + / data->yScrTile)); - data->xLastMouseClick = x; - data->yLastMouseClick = y; - return 0; + NHEVENT_MS(CLICK_1, x, y); - case WM_LBUTTONDBLCLK: - x = max(0, min(COLNO, data->xPos + (LOWORD(lParam)-data->map_orig.x)/data->xScrTile)); - y = max(0, min(ROWNO, data->yPos + (HIWORD(lParam)-data->map_orig.y)/data->yScrTile)); + data->xLastMouseClick = x; + data->yLastMouseClick = y; + return 0; - /* if map has scrolled since the last mouse click - ignore double-click message */ - if( data->xLastMouseClick == x && data->yLastMouseClick == y ) { - NHEVENT_MS( CLICK_1, x, y); - } - return 0; + case WM_LBUTTONDBLCLK: + x = max(0, min(COLNO, data->xPos + + (LOWORD(lParam) - data->map_orig.x) + / data->xScrTile)); + y = max(0, min(ROWNO, data->yPos + + (HIWORD(lParam) - data->map_orig.y) + / data->yScrTile)); - case WM_DESTROY: - if( data->hMapFont ) DeleteObject(data->hMapFont); - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - break; + /* if map has scrolled since the last mouse click - ignore + * double-click message */ + if (data->xLastMouseClick == x && data->yLastMouseClick == y) { + NHEVENT_MS(CLICK_1, x, y); + } + return 0; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + case WM_DESTROY: + if (data->hMapFont) + DeleteObject(data->hMapFont); + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; } /* on WM_COMMAND */ -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - RECT rt; + PNHMapWindow data; + RECT rt; - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch(wParam) { - case MSNH_MSG_PRINT_GLYPH: - { - PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph)lParam; - data->map[msg_data->x][msg_data->y] = msg_data->glyph; + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (wParam) { + case MSNH_MSG_PRINT_GLYPH: { + PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam; + data->map[msg_data->x][msg_data->y] = msg_data->glyph; - /* invalidate the update area */ - nhcoord2display(data, msg_data->x, msg_data->y, &rt); - InvalidateRect(hWnd, &rt, TRUE); - } - break; + /* invalidate the update area */ + nhcoord2display(data, msg_data->x, msg_data->y, &rt); + InvalidateRect(hWnd, &rt, TRUE); + } break; - case MSNH_MSG_CLIPAROUND: - { - PMSNHMsgClipAround msg_data = (PMSNHMsgClipAround)lParam; - int x, y; - BOOL scroll_x, scroll_y; - int mcam = iflags.wc_scroll_margin; + case MSNH_MSG_CLIPAROUND: { + PMSNHMsgClipAround msg_data = (PMSNHMsgClipAround) lParam; + int x, y; + BOOL scroll_x, scroll_y; + int mcam = iflags.wc_scroll_margin; - /* calculate if you should clip around */ - scroll_x = - !GetNHApp()->bNoHScroll && - ( msg_data->x<(data->xPos+mcam) || - msg_data->x>(data->xPos+data->xPageSize-mcam) ); - scroll_y = - !GetNHApp()->bNoVScroll && - ( msg_data->y<(data->yPos+mcam) || - msg_data->y>(data->yPos+data->yPageSize-mcam) ); - - mcam += iflags.wc_scroll_amount - 1; - /* get page size and center horizontally on x-position */ - if( scroll_x ) { - if( data->xPageSize<=2*mcam ) { - x = max(0, min(COLNO, msg_data->x - data->xPageSize/2)); - } else if( msg_data->x < data->xPos+data->xPageSize/2 ) { - x = max(0, min(COLNO, msg_data->x - mcam)); - } else { - x = max(0, min(COLNO, msg_data->x - data->xPageSize + mcam)); - } - SendMessage( hWnd, WM_HSCROLL, (WPARAM)MAKELONG(SB_THUMBTRACK, x), (LPARAM)NULL ); - } + /* calculate if you should clip around */ + scroll_x = + !GetNHApp()->bNoHScroll + && (msg_data->x < (data->xPos + mcam) + || msg_data->x > (data->xPos + data->xPageSize - mcam)); + scroll_y = + !GetNHApp()->bNoVScroll + && (msg_data->y < (data->yPos + mcam) + || msg_data->y > (data->yPos + data->yPageSize - mcam)); - /* get page size and center vertically on y-position */ - if( scroll_y ) { - if( data->yPageSize<=2*mcam ) { - y = max(0, min(ROWNO, msg_data->y - data->yPageSize/2)); - } else if( msg_data->y < data->yPos+data->yPageSize/2 ) { - y = max(0, min(ROWNO, msg_data->y - mcam)); - } else { - y = max(0, min(ROWNO, msg_data->y - data->yPageSize + mcam)); - } - SendMessage( hWnd, WM_VSCROLL, (WPARAM)MAKELONG(SB_THUMBTRACK, y), (LPARAM)NULL ); - } - } - break; + mcam += iflags.wc_scroll_amount - 1; + /* get page size and center horizontally on x-position */ + if (scroll_x) { + if (data->xPageSize <= 2 * mcam) { + x = max(0, min(COLNO, msg_data->x - data->xPageSize / 2)); + } else if (msg_data->x < data->xPos + data->xPageSize / 2) { + x = max(0, min(COLNO, msg_data->x - mcam)); + } else { + x = max(0, min(COLNO, msg_data->x - data->xPageSize + mcam)); + } + SendMessage(hWnd, WM_HSCROLL, (WPARAM) MAKELONG(SB_THUMBTRACK, x), + (LPARAM) NULL); + } - case MSNH_MSG_CLEAR_WINDOW: - { - int i, j; - for(i=0; imap[i][j] = -1; - } - InvalidateRect(hWnd, NULL, TRUE); - } break; + /* get page size and center vertically on y-position */ + if (scroll_y) { + if (data->yPageSize <= 2 * mcam) { + y = max(0, min(ROWNO, msg_data->y - data->yPageSize / 2)); + } else if (msg_data->y < data->yPos + data->yPageSize / 2) { + y = max(0, min(ROWNO, msg_data->y - mcam)); + } else { + y = max(0, min(ROWNO, msg_data->y - data->yPageSize + mcam)); + } + SendMessage(hWnd, WM_VSCROLL, (WPARAM) MAKELONG(SB_THUMBTRACK, y), + (LPARAM) NULL); + } + } break; - case MSNH_MSG_CURSOR: - { - PMSNHMsgCursor msg_data = (PMSNHMsgCursor)lParam; - HDC hdc; - RECT rt; + case MSNH_MSG_CLEAR_WINDOW: { + int i, j; + for (i = 0; i < COLNO; i++) + for (j = 0; j < ROWNO; j++) { + data->map[i][j] = -1; + } + InvalidateRect(hWnd, NULL, TRUE); + } break; - /* move focus rectangle at the cursor postion */ - hdc = GetDC(hWnd); + case MSNH_MSG_CURSOR: { + PMSNHMsgCursor msg_data = (PMSNHMsgCursor) lParam; + HDC hdc; + RECT rt; - nhcoord2display(data, data->xCur, data->yCur, &rt); - if( data->bAsciiMode ) { - PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, DSTINVERT); - } else { - DrawFocusRect(hdc, &rt); - } - - data->xCur = msg_data->x; - data->yCur = msg_data->y; + /* move focus rectangle at the cursor postion */ + hdc = GetDC(hWnd); - nhcoord2display(data, data->xCur, data->yCur, &rt); - if( data->bAsciiMode ) { - PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, DSTINVERT); - } else { - DrawFocusRect(hdc, &rt); - } + nhcoord2display(data, data->xCur, data->yCur, &rt); + if (data->bAsciiMode) { + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, DSTINVERT); + } else { + DrawFocusRect(hdc, &rt); + } - ReleaseDC(hWnd, hdc); - } break; - } + data->xCur = msg_data->x; + data->yCur = msg_data->y; + + nhcoord2display(data, data->xCur, data->yCur, &rt); + if (data->bAsciiMode) { + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, DSTINVERT); + } else { + DrawFocusRect(hdc, &rt); + } + + ReleaseDC(hWnd, hdc); + } break; + } } /* on WM_CREATE */ -void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - int i,j; + PNHMapWindow data; + int i, j; - /* set window data */ - data = (PNHMapWindow)malloc(sizeof(NHMapWindow)); - if( !data ) panic("out of memory"); + /* set window data */ + data = (PNHMapWindow) malloc(sizeof(NHMapWindow)); + if (!data) + panic("out of memory"); - ZeroMemory(data, sizeof(NHMapWindow)); - for(i=0; imap[i][j] = -1; - } + ZeroMemory(data, sizeof(NHMapWindow)); + for (i = 0; i < COLNO; i++) + for (j = 0; j < ROWNO; j++) { + data->map[i][j] = -1; + } - data->bAsciiMode = FALSE; + data->bAsciiMode = FALSE; - data->xScrTile = GetNHApp()->mapTile_X; - data->yScrTile = GetNHApp()->mapTile_Y; + data->xScrTile = GetNHApp()->mapTile_X; + data->yScrTile = GetNHApp()->mapTile_Y; - data->xLastMouseClick = data->yLastMouseClick = -1; + data->xLastMouseClick = data->yLastMouseClick = -1; - SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); } /* on WM_PAINT */ -void onPaint(HWND hWnd) +void +onPaint(HWND hWnd) { - PNHMapWindow data; - PAINTSTRUCT ps; - HDC hDC; - HDC tileDC; - HGDIOBJ saveBmp; - RECT paint_rt; - int i, j; + PNHMapWindow data; + PAINTSTRUCT ps; + HDC hDC; + HDC tileDC; + HGDIOBJ saveBmp; + RECT paint_rt; + int i, j; - /* get window data */ - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); + /* get window data */ + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); - hDC = BeginPaint(hWnd, &ps); + hDC = BeginPaint(hWnd, &ps); - /* calculate paint rectangle */ - if( !IsRectEmpty(&ps.rcPaint) ) { - /* calculate paint rectangle */ - paint_rt.left = max(data->xPos + (ps.rcPaint.left - data->map_orig.x)/data->xScrTile, 0); - paint_rt.top = max(data->yPos + (ps.rcPaint.top - data->map_orig.y)/data->yScrTile, 0); - paint_rt.right = min(data->xPos + (ps.rcPaint.right - data->map_orig.x)/data->xScrTile+1, COLNO); - paint_rt.bottom = min(data->yPos + (ps.rcPaint.bottom - data->map_orig.y)/data->yScrTile+1, ROWNO); + /* calculate paint rectangle */ + if (!IsRectEmpty(&ps.rcPaint)) { + /* calculate paint rectangle */ + paint_rt.left = + max(data->xPos + + (ps.rcPaint.left - data->map_orig.x) / data->xScrTile, + 0); + paint_rt.top = max( + data->yPos + (ps.rcPaint.top - data->map_orig.y) / data->yScrTile, + 0); + paint_rt.right = min( + data->xPos + + (ps.rcPaint.right - data->map_orig.x) / data->xScrTile + 1, + COLNO); + paint_rt.bottom = min( + data->yPos + + (ps.rcPaint.bottom - data->map_orig.y) / data->yScrTile + 1, + ROWNO); - if(data->bAsciiMode || Is_rogue_level(&u.uz)) { - /* You enter a VERY primitive world! */ - HGDIOBJ oldFont; + if (data->bAsciiMode || Is_rogue_level(&u.uz)) { + /* You enter a VERY primitive world! */ + HGDIOBJ oldFont; - oldFont = SelectObject(hDC, data->hMapFont); - SetBkMode(hDC, TRANSPARENT); + oldFont = SelectObject(hDC, data->hMapFont); + SetBkMode(hDC, TRANSPARENT); - /* draw the map */ - for(i=paint_rt.left; imap[i][j]>=0) { - char ch; - TCHAR wch; - RECT glyph_rect; - int color; - unsigned special; - int mgch; - HBRUSH back_brush; - COLORREF OldFg; + /* draw the map */ + for (i = paint_rt.left; i < paint_rt.right; i++) + for (j = paint_rt.top; j < paint_rt.bottom; j++) + if (data->map[i][j] >= 0) { + char ch; + TCHAR wch; + RECT glyph_rect; + int color; + unsigned special; + int mgch; + HBRUSH back_brush; + COLORREF OldFg; - nhcoord2display(data, i, j, &glyph_rect); + nhcoord2display(data, i, j, &glyph_rect); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) - nhglyph2charcolor(data->map[i][j], &ch, &color); - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); + nhglyph2charcolor(data->map[i][j], &ch, &color); + OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); #else - /* rely on NetHack core helper routine */ - (void)mapglyph(data->map[i][j], &mgch, &color, - &special, i, j); - ch = (char)mgch; - if (((special & MG_PET) && iflags.hilite_pet) || - ((special & MG_DETECT) && iflags.use_inverse)) { - back_brush = CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); - FillRect (hDC, &glyph_rect, back_brush); - DeleteObject (back_brush); - switch (color) - { - case CLR_GRAY: - case CLR_WHITE: - OldFg = SetTextColor( hDC, nhcolor_to_RGB(CLR_BLACK)); - break; - default: - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); - } - } else { - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); - } + /* rely on NetHack core helper routine */ + (void) mapglyph(data->map[i][j], &mgch, &color, + &special, i, j); + ch = (char) mgch; + if (((special & MG_PET) && iflags.hilite_pet) + || ((special & MG_DETECT) + && iflags.use_inverse)) { + back_brush = + CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); + FillRect(hDC, &glyph_rect, back_brush); + DeleteObject(back_brush); + switch (color) { + case CLR_GRAY: + case CLR_WHITE: + OldFg = SetTextColor( + hDC, nhcolor_to_RGB(CLR_BLACK)); + break; + default: + OldFg = + SetTextColor(hDC, nhcolor_to_RGB(color)); + } + } else { + OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); + } #endif - DrawText(hDC, - NH_A2W(&ch, &wch, 1), - 1, - &glyph_rect, - DT_CENTER | DT_VCENTER | DT_NOPREFIX - ); - SetTextColor (hDC, OldFg); - } - SelectObject(hDC, oldFont); - } else { - /* prepare tiles DC for mapping */ - tileDC = CreateCompatibleDC(hDC); - saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); + DrawText(hDC, NH_A2W(&ch, &wch, 1), 1, &glyph_rect, + DT_CENTER | DT_VCENTER | DT_NOPREFIX); + SetTextColor(hDC, OldFg); + } + SelectObject(hDC, oldFont); + } else { + /* prepare tiles DC for mapping */ + tileDC = CreateCompatibleDC(hDC); + saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); - /* draw the map */ - for(i=paint_rt.left; imap[i][j]>=0) { - short ntile; - int t_x, t_y; - RECT glyph_rect; + /* draw the map */ + for (i = paint_rt.left; i < paint_rt.right; i++) + for (j = paint_rt.top; j < paint_rt.bottom; j++) + if (data->map[i][j] >= 0) { + short ntile; + int t_x, t_y; + RECT glyph_rect; - ntile = glyph2tile[ data->map[i][j] ]; - t_x = (ntile % GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_X; - t_y = (ntile / GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_Y; - - nhcoord2display(data, i, j, &glyph_rect); + ntile = glyph2tile[data->map[i][j]]; + t_x = (ntile % GetNHApp()->mapTilesPerLine) + * GetNHApp()->mapTile_X; + t_y = (ntile / GetNHApp()->mapTilesPerLine) + * GetNHApp()->mapTile_Y; - StretchBlt( - hDC, - glyph_rect.left, - glyph_rect.top, - data->xScrTile, - data->yScrTile, - tileDC, - t_x, - t_y, - GetNHApp()->mapTile_X, - GetNHApp()->mapTile_Y, - SRCCOPY - ); - if( glyph_is_pet(data->map[i][j]) && iflags.wc_hilite_pet ) { - /* apply pet mark transparently over - pet image */ - HDC hdcPetMark; - HBITMAP bmPetMarkOld; + nhcoord2display(data, i, j, &glyph_rect); - /* this is DC for petmark bitmap */ - hdcPetMark = CreateCompatibleDC(hDC); - bmPetMarkOld = SelectObject(hdcPetMark, GetNHApp()->bmpPetMark); + StretchBlt(hDC, glyph_rect.left, glyph_rect.top, + data->xScrTile, data->yScrTile, tileDC, + t_x, t_y, GetNHApp()->mapTile_X, + GetNHApp()->mapTile_Y, SRCCOPY); + if (glyph_is_pet(data->map[i][j]) + && iflags.wc_hilite_pet) { + /* apply pet mark transparently over + pet image */ + HDC hdcPetMark; + HBITMAP bmPetMarkOld; - nhapply_image_transparent( - hDC, - glyph_rect.left, - glyph_rect.top, - data->xScrTile, - data->yScrTile, - hdcPetMark, - 0, - 0, - TILE_X, - TILE_Y, - TILE_BK_COLOR - ); - SelectObject(hdcPetMark, bmPetMarkOld); - DeleteDC(hdcPetMark); - } - } - SelectObject(tileDC, saveBmp); - DeleteDC(tileDC); - } + /* this is DC for petmark bitmap */ + hdcPetMark = CreateCompatibleDC(hDC); + bmPetMarkOld = SelectObject( + hdcPetMark, GetNHApp()->bmpPetMark); - /* draw focus rect */ - nhcoord2display(data, data->xCur, data->yCur, &paint_rt); - if( data->bAsciiMode ) { - PatBlt( hDC, - paint_rt.left, paint_rt.top, - paint_rt.right-paint_rt.left, paint_rt.bottom-paint_rt.top, - DSTINVERT ); - } else { - DrawFocusRect(hDC, &paint_rt); - } - } - EndPaint(hWnd, &ps); + nhapply_image_transparent( + hDC, glyph_rect.left, glyph_rect.top, + data->xScrTile, data->yScrTile, hdcPetMark, 0, + 0, TILE_X, TILE_Y, TILE_BK_COLOR); + SelectObject(hdcPetMark, bmPetMarkOld); + DeleteDC(hdcPetMark); + } + } + SelectObject(tileDC, saveBmp); + DeleteDC(tileDC); + } + + /* draw focus rect */ + nhcoord2display(data, data->xCur, data->yCur, &paint_rt); + if (data->bAsciiMode) { + PatBlt(hDC, paint_rt.left, paint_rt.top, + paint_rt.right - paint_rt.left, + paint_rt.bottom - paint_rt.top, DSTINVERT); + } else { + DrawFocusRect(hDC, &paint_rt); + } + } + EndPaint(hWnd, &ps); } /* on WM_VSCROLL */ -void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - SCROLLINFO si; - int yNewPos; - int yDelta; - - /* get window data */ - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); + PNHMapWindow data; + SCROLLINFO si; + int yNewPos; + int yDelta; - switch(LOWORD (wParam)) - { - /* User clicked shaft left of the scroll box. */ - case SB_PAGEUP: - yNewPos = data->yPos-data->yPageSize; - break; + /* get window data */ + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); - /* User clicked shaft right of the scroll box. */ - case SB_PAGEDOWN: - yNewPos = data->yPos+data->yPageSize; - break; + switch (LOWORD(wParam)) { + /* User clicked shaft left of the scroll box. */ + case SB_PAGEUP: + yNewPos = data->yPos - data->yPageSize; + break; - /* User clicked the left arrow. */ - case SB_LINEUP: - yNewPos = data->yPos-1; - break; + /* User clicked shaft right of the scroll box. */ + case SB_PAGEDOWN: + yNewPos = data->yPos + data->yPageSize; + break; - /* User clicked the right arrow. */ - case SB_LINEDOWN: - yNewPos = data->yPos+1; - break; + /* User clicked the left arrow. */ + case SB_LINEUP: + yNewPos = data->yPos - 1; + break; - /* User dragged the scroll box. */ - case SB_THUMBTRACK: - yNewPos = HIWORD(wParam); - break; + /* User clicked the right arrow. */ + case SB_LINEDOWN: + yNewPos = data->yPos + 1; + break; - default: - yNewPos = data->yPos; - } + /* User dragged the scroll box. */ + case SB_THUMBTRACK: + yNewPos = HIWORD(wParam); + break; - yNewPos = max(0, min(ROWNO-data->yPageSize+1, yNewPos)); - if( yNewPos == data->yPos ) return; - - yDelta = yNewPos - data->yPos; - data->yPos = yNewPos; + default: + yNewPos = data->yPos; + } - ScrollWindowEx (hWnd, 0, -data->yScrTile * yDelta, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + yNewPos = max(0, min(ROWNO - data->yPageSize + 1, yNewPos)); + if (yNewPos == data->yPos) + return; - if( !GetNHApp()->bHideScrollBars ) { - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - } + yDelta = yNewPos - data->yPos; + data->yPos = yNewPos; + + ScrollWindowEx(hWnd, 0, -data->yScrTile * yDelta, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + if (!GetNHApp()->bHideScrollBars) { + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + } } /* on WM_HSCROLL */ -void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - SCROLLINFO si; - int xNewPos; - int xDelta; - - /* get window data */ - data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - - switch(LOWORD (wParam)) - { - /* User clicked shaft left of the scroll box. */ - case SB_PAGEUP: - xNewPos = data->xPos-data->xPageSize; - break; + PNHMapWindow data; + SCROLLINFO si; + int xNewPos; + int xDelta; - /* User clicked shaft right of the scroll box. */ - case SB_PAGEDOWN: - xNewPos = data->xPos+data->xPageSize; - break; + /* get window data */ + data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); - /* User clicked the left arrow. */ - case SB_LINEUP: - xNewPos = data->xPos-1; - break; + switch (LOWORD(wParam)) { + /* User clicked shaft left of the scroll box. */ + case SB_PAGEUP: + xNewPos = data->xPos - data->xPageSize; + break; - /* User clicked the right arrow. */ - case SB_LINEDOWN: - xNewPos = data->xPos+1; - break; + /* User clicked shaft right of the scroll box. */ + case SB_PAGEDOWN: + xNewPos = data->xPos + data->xPageSize; + break; - /* User dragged the scroll box. */ - case SB_THUMBTRACK: - xNewPos = HIWORD(wParam); - break; + /* User clicked the left arrow. */ + case SB_LINEUP: + xNewPos = data->xPos - 1; + break; - default: - xNewPos = data->xPos; - } + /* User clicked the right arrow. */ + case SB_LINEDOWN: + xNewPos = data->xPos + 1; + break; - xNewPos = max(0, min(COLNO-data->xPageSize+1, xNewPos)); - if( xNewPos == data->xPos ) return; - - xDelta = xNewPos - data->xPos; - data->xPos = xNewPos; + /* User dragged the scroll box. */ + case SB_THUMBTRACK: + xNewPos = HIWORD(wParam); + break; - ScrollWindowEx (hWnd, -data->xScrTile * xDelta, 0, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + default: + xNewPos = data->xPos; + } - if( !GetNHApp()->bHideScrollBars ) { - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); - } + xNewPos = max(0, min(COLNO - data->xPageSize + 1, xNewPos)); + if (xNewPos == data->xPos) + return; + + xDelta = xNewPos - data->xPos; + data->xPos = xNewPos; + + ScrollWindowEx(hWnd, -data->xScrTile * xDelta, 0, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + if (!GetNHApp()->bHideScrollBars) { + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + } } /* map nethack map coordinates to the screen location */ -void nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut) +void +nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut) { - lpOut->left = (x - data->xPos)*data->xScrTile + data->map_orig.x; - lpOut->top = (y - data->yPos)*data->yScrTile + data->map_orig.y; - lpOut->right = lpOut->left + data->xScrTile; - lpOut->bottom = lpOut->top + data->yScrTile; + lpOut->left = (x - data->xPos) * data->xScrTile + data->map_orig.x; + lpOut->top = (y - data->yPos) * data->yScrTile + data->map_orig.y; + lpOut->right = lpOut->left + data->xScrTile; + lpOut->bottom = lpOut->top + data->yScrTile; } #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) /* map glyph to character/color combination */ -void nhglyph2charcolor(short g, uchar* ch, int* color) +void +nhglyph2charcolor(short g, uchar *ch, int *color) { - int offset; + int offset; #ifdef TEXTCOLOR -#define zap_color(n) *color = iflags.use_color ? zapcolors[n] : NO_COLOR +#define zap_color(n) *color = iflags.use_color ? zapcolors[n] : NO_COLOR #define cmap_color(n) *color = iflags.use_color ? defsyms[n].color : NO_COLOR -#define obj_color(n) *color = iflags.use_color ? objects[n].oc_color : NO_COLOR -#define mon_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR -#define pet_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR -#define warn_color(n) *color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR +#define obj_color(n) \ + *color = iflags.use_color ? objects[n].oc_color : NO_COLOR +#define mon_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define pet_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define warn_color(n) \ + *color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR -# else /* no text color */ +#else /* no text color */ #define zap_color(n) #define cmap_color(n) @@ -855,76 +881,89 @@ void nhglyph2charcolor(short g, uchar* ch, int* color) #define mon_color(n) #define pet_color(c) #define warn_color(c) - *color = CLR_WHITE; + *color = CLR_WHITE; #endif - if ((offset = (g - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ - *ch = showsyms[offset + SYM_OFF_W]; - warn_color(offset); - } else if ((offset = (g - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ - /* see swallow_to_glyph() in display.c */ - *ch = (uchar) showsyms[(S_sw_tl + (offset & 0x7)) + SYM_OFF_P]; - mon_color(offset >> 3); - } else if ((offset = (g - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ - /* see zapdir_to_glyph() in display.c */ - *ch = showsyms[(S_vbeam + (offset & 0x3)) + SYM_OFF_P]; - zap_color((offset >> 2)); - } else if ((offset = (g - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ - *ch = showsyms[offset + SYM_OFF_P]; - cmap_color(offset); - } else if ((offset = (g - GLYPH_OBJ_OFF)) >= 0) { /* object */ - *ch = showsyms[(int)objects[offset].oc_class + SYM_OFF_O]; - obj_color(offset); - } else if ((offset = (g - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ - *ch = showsyms[(int)objects[CORPSE].oc_class + SYM_OFF_O]; - mon_color(offset); - } else if ((offset = (g - GLYPH_PET_OFF)) >= 0) { /* a pet */ - *ch = showsyms[(int)mons[offset].mlet + SYM_OFF_M]; - pet_color(offset); - } else { /* a monster */ - *ch = showsyms[(int)mons[g].mlet + SYM_OFF_M]; - mon_color(g); - } - // end of wintty code + if ((offset = (g - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ + *ch = showsyms[offset + SYM_OFF_W]; + warn_color(offset); + } else if ((offset = (g - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ + /* see swallow_to_glyph() in display.c */ + *ch = (uchar) showsyms[(S_sw_tl + (offset & 0x7)) + SYM_OFF_P]; + mon_color(offset >> 3); + } else if ((offset = (g - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ + /* see zapdir_to_glyph() in display.c */ + *ch = showsyms[(S_vbeam + (offset & 0x3)) + SYM_OFF_P]; + zap_color((offset >> 2)); + } else if ((offset = (g - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ + *ch = showsyms[offset + SYM_OFF_P]; + cmap_color(offset); + } else if ((offset = (g - GLYPH_OBJ_OFF)) >= 0) { /* object */ + *ch = showsyms[(int) objects[offset].oc_class + SYM_OFF_O]; + obj_color(offset); + } else if ((offset = (g - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ + *ch = showsyms[(int) objects[CORPSE].oc_class + SYM_OFF_O]; + mon_color(offset); + } else if ((offset = (g - GLYPH_PET_OFF)) >= 0) { /* a pet */ + *ch = showsyms[(int) mons[offset].mlet + SYM_OFF_M]; + pet_color(offset); + } else { /* a monster */ + *ch = showsyms[(int) mons[g].mlet + SYM_OFF_M]; + mon_color(g); + } + // end of wintty code } #endif /* map nethack color to RGB */ -COLORREF nhcolor_to_RGB(int c) +COLORREF +nhcolor_to_RGB(int c) { - switch(c) { - case CLR_BLACK: return RGB(0x55, 0x55, 0x55); - case CLR_RED: return RGB(0xFF, 0x00, 0x00); - case CLR_GREEN: return RGB(0x00, 0x80, 0x00); - case CLR_BROWN: return RGB(0xA5, 0x2A, 0x2A); - case CLR_BLUE: return RGB(0x00, 0x00, 0xFF); - case CLR_MAGENTA: return RGB(0xFF, 0x00, 0xFF); - case CLR_CYAN: return RGB(0x00, 0xFF, 0xFF); - case CLR_GRAY: return RGB(0xC0, 0xC0, 0xC0); - case NO_COLOR: return RGB(0xFF, 0xFF, 0xFF); - case CLR_ORANGE: return RGB(0xFF, 0xA5, 0x00); - case CLR_BRIGHT_GREEN: return RGB(0x00, 0xFF, 0x00); - case CLR_YELLOW: return RGB(0xFF, 0xFF, 0x00); - case CLR_BRIGHT_BLUE: return RGB(0x00, 0xC0, 0xFF); - case CLR_BRIGHT_MAGENTA: return RGB(0xFF, 0x80, 0xFF); - case CLR_BRIGHT_CYAN: return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */ - case CLR_WHITE: return RGB(0xFF, 0xFF, 0xFF); - default: return RGB(0x00, 0x00, 0x00); /* black */ - } + switch (c) { + case CLR_BLACK: + return RGB(0x55, 0x55, 0x55); + case CLR_RED: + return RGB(0xFF, 0x00, 0x00); + case CLR_GREEN: + return RGB(0x00, 0x80, 0x00); + case CLR_BROWN: + return RGB(0xA5, 0x2A, 0x2A); + case CLR_BLUE: + return RGB(0x00, 0x00, 0xFF); + case CLR_MAGENTA: + return RGB(0xFF, 0x00, 0xFF); + case CLR_CYAN: + return RGB(0x00, 0xFF, 0xFF); + case CLR_GRAY: + return RGB(0xC0, 0xC0, 0xC0); + case NO_COLOR: + return RGB(0xFF, 0xFF, 0xFF); + case CLR_ORANGE: + return RGB(0xFF, 0xA5, 0x00); + case CLR_BRIGHT_GREEN: + return RGB(0x00, 0xFF, 0x00); + case CLR_YELLOW: + return RGB(0xFF, 0xFF, 0x00); + case CLR_BRIGHT_BLUE: + return RGB(0x00, 0xC0, 0xFF); + case CLR_BRIGHT_MAGENTA: + return RGB(0xFF, 0x80, 0xFF); + case CLR_BRIGHT_CYAN: + return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */ + case CLR_WHITE: + return RGB(0xFF, 0xFF, 0xFF); + default: + return RGB(0x00, 0x00, 0x00); /* black */ + } } -/* apply bitmap pointed by sourceDc transparently over +/* apply bitmap pointed by sourceDc transparently over bitmap pointed by hDC */ -void nhapply_image_transparent( - HDC hDC, int x, int y, int width, int height, - HDC sourceDC, int s_x, int s_y, int s_width, int s_height, - COLORREF cTransparent -) +void +nhapply_image_transparent(HDC hDC, int x, int y, int width, int height, + HDC sourceDC, int s_x, int s_y, int s_width, + int s_height, COLORREF cTransparent) { - TransparentImage( - hDC, x, y, width, height, - sourceDC, s_x, s_y, s_width, s_height, - cTransparent - ); + TransparentImage(hDC, x, y, width, height, sourceDC, s_x, s_y, s_width, + s_height, cTransparent); } - diff --git a/sys/wince/mhmenu.c b/sys/wince/mhmenu.c index 658622b84..4637b3e11 100644 --- a/sys/wince/mhmenu.c +++ b/sys/wince/mhmenu.c @@ -11,50 +11,50 @@ #include "mhcolor.h" #include "mhtxtbuf.h" -#define MENU_MARGIN 0 -#define NHMENU_STR_SIZE BUFSZ -#define MIN_TABSTOP_SIZE 0 -#define NUMTABS 15 -#define TAB_SEPARATION 10 /* pixels between each tab stop */ +#define MENU_MARGIN 0 +#define NHMENU_STR_SIZE BUFSZ +#define MIN_TABSTOP_SIZE 0 +#define NUMTABS 15 +#define TAB_SEPARATION 10 /* pixels between each tab stop */ typedef struct mswin_menu_item { - int glyph; - ANY_P identifier; - CHAR_P accelerator; - CHAR_P group_accel; - int attr; - char str[NHMENU_STR_SIZE]; - BOOLEAN_P presel; - int count; - BOOL has_focus; - BOOL has_tab; + int glyph; + ANY_P identifier; + CHAR_P accelerator; + CHAR_P group_accel; + int attr; + char str[NHMENU_STR_SIZE]; + BOOLEAN_P presel; + int count; + BOOL has_focus; + BOOL has_tab; } NHMenuItem, *PNHMenuItem; typedef struct mswin_nethack_menu_window { - int type; /* MENU_TYPE_TEXT or MENU_TYPE_MENU */ - int how; /* for menus: PICK_NONE, PICK_ONE, PICK_ANY */ + int type; /* MENU_TYPE_TEXT or MENU_TYPE_MENU */ + int how; /* for menus: PICK_NONE, PICK_ONE, PICK_ANY */ - union { - struct menu_list { - int size; /* number of items in items[] */ - int allocated; /* number of allocated slots in items[] */ - PNHMenuItem items; /* menu items */ - char gacc[QBUFSZ]; /* group accelerators */ - BOOL counting; /* counting flag */ - char prompt[QBUFSZ]; /* menu prompt */ - int tab_stop_size[NUMTABS];/* tabstops to align option values */ - } menu; + union { + struct menu_list { + int size; /* number of items in items[] */ + int allocated; /* number of allocated slots in items[] */ + PNHMenuItem items; /* menu items */ + char gacc[QBUFSZ]; /* group accelerators */ + BOOL counting; /* counting flag */ + char prompt[QBUFSZ]; /* menu prompt */ + int tab_stop_size[NUMTABS]; /* tabstops to align option values */ + } menu; - struct menu_text { - PNHTextBuffer text; - } text; - }; - int result; - int done; + struct menu_text { + PNHTextBuffer text; + } text; + }; + int result; + int done; - HBITMAP bmpChecked; - HBITMAP bmpCheckedCount; - HBITMAP bmpNotChecked; + HBITMAP bmpChecked; + HBITMAP bmpCheckedCount; + HBITMAP bmpNotChecked; } NHMenuWindow, *PNHMenuWindow; extern short glyph2tile[]; @@ -62,13 +62,14 @@ extern short glyph2tile[]; static WNDPROC wndProcListViewOrig = NULL; static WNDPROC editControlWndProc = NULL; -#define NHMENU_IS_SELECTABLE(item) ((item).identifier.a_obj!=NULL) -#define NHMENU_IS_SELECTED(item) ((item).count!=0) +#define NHMENU_IS_SELECTABLE(item) ((item).identifier.a_obj != NULL) +#define NHMENU_IS_SELECTED(item) ((item).count != 0) -LRESULT CALLBACK MenuWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHMenuListWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHMenuTextWndProc(HWND, UINT, WPARAM, LPARAM); -static void CheckInputDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK MenuWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMenuListWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMenuTextWndProc(HWND, UINT, WPARAM, LPARAM); +static void CheckInputDialog(HWND hWnd, UINT message, WPARAM wParam, + LPARAM lParam); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static LRESULT onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam); static LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -76,1497 +77,1535 @@ static void LayoutMenu(HWND hwnd); static void SetMenuType(HWND hwnd, int type); static void SetMenuListType(HWND hwnd, int now); static HWND GetMenuControl(HWND hwnd); -static void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count); +static void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, + int count); static void reset_menu_count(HWND hwndList, PNHMenuWindow data); static LRESULT onListChar(HWND hWnd, HWND hwndList, WORD ch); -static char* parse_menu_str(char* dest, const char* src, size_t size); +static char *parse_menu_str(char *dest, const char *src, size_t size); -HWND mswin_init_menu_window (int type) { - HWND ret; +HWND +mswin_init_menu_window(int type) +{ + HWND ret; - ret = CreateDialog( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_MENU), - GetNHApp()->hMainWnd, - MenuWndProc - ); - if( !ret ) { - panic("Cannot create menu window"); - } - - SetMenuType(ret, type); - return ret; + ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_MENU), + GetNHApp()->hMainWnd, MenuWndProc); + if (!ret) { + panic("Cannot create menu window"); + } + + SetMenuType(ret, type); + return ret; } - -int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected) +int +mswin_menu_window_select_menu(HWND hWnd, int how, MENU_ITEM_P **_selected) { - PNHMenuWindow data; - int ret_val; + PNHMenuWindow data; + int ret_val; MENU_ITEM_P *selected = NULL; - int i; - char* ap; - char accell_str[256]; + int i; + char *ap; + char accell_str[256]; - assert( _selected!=NULL ); - *_selected = NULL; - ret_val = -1; + assert(_selected != NULL); + *_selected = NULL; + ret_val = -1; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); - /* set menu type */ - SetMenuListType(hWnd, how); + /* set menu type */ + SetMenuListType(hWnd, how); - /* Ok, now give items a unique accelerators */ - ZeroMemory(accell_str, sizeof(accell_str)); - ap = accell_str; + /* Ok, now give items a unique accelerators */ + ZeroMemory(accell_str, sizeof(accell_str)); + ap = accell_str; #if defined(WIN_CE_SMARTPHONE) - if( data->menu.size>10 ) { - *ap++ = MENU_FIRST_PAGE; - *ap++ = MENU_LAST_PAGE; - *ap++ = MENU_NEXT_PAGE; - *ap++ = MENU_PREVIOUS_PAGE; - if( data->how == PICK_ANY ) { - *ap++ = MENU_SELECT_ALL; - *ap++ = MENU_UNSELECT_ALL; - *ap++ = MENU_INVERT_ALL; - *ap++ = MENU_SELECT_PAGE; - *ap++ = MENU_UNSELECT_PAGE; - *ap++ = MENU_INVERT_PAGE; - } - *ap++ = MENU_SEARCH; - } + if (data->menu.size > 10) { + *ap++ = MENU_FIRST_PAGE; + *ap++ = MENU_LAST_PAGE; + *ap++ = MENU_NEXT_PAGE; + *ap++ = MENU_PREVIOUS_PAGE; + if (data->how == PICK_ANY) { + *ap++ = MENU_SELECT_ALL; + *ap++ = MENU_UNSELECT_ALL; + *ap++ = MENU_INVERT_ALL; + *ap++ = MENU_SELECT_PAGE; + *ap++ = MENU_UNSELECT_PAGE; + *ap++ = MENU_INVERT_PAGE; + } + *ap++ = MENU_SEARCH; + } #endif - if( data->type == MENU_TYPE_MENU ) { - char next_char = 'a'; + if (data->type == MENU_TYPE_MENU) { + char next_char = 'a'; - for( i=0; imenu.size; i++) { - if( data->menu.items[i].accelerator!=0 ) { - *ap++ = data->menu.items[i].accelerator; - next_char = (char)(data->menu.items[i].accelerator+1); - } else if( NHMENU_IS_SELECTABLE(data->menu.items[i]) ) { - if ( (next_char>='a' && next_char<='z') || - (next_char>='A' && next_char<='Z') ) { - data->menu.items[i].accelerator = next_char; - *ap++ = data->menu.items[i].accelerator; - } else { - if( next_char > 'z' ) next_char = 'A'; - else if ( next_char > 'Z' ) break; + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator != 0) { + *ap++ = data->menu.items[i].accelerator; + next_char = (char) (data->menu.items[i].accelerator + 1); + } else if (NHMENU_IS_SELECTABLE(data->menu.items[i])) { + if ((next_char >= 'a' && next_char <= 'z') + || (next_char >= 'A' && next_char <= 'Z')) { + data->menu.items[i].accelerator = next_char; + *ap++ = data->menu.items[i].accelerator; + } else { + if (next_char > 'z') + next_char = 'A'; + else if (next_char > 'Z') + break; - data->menu.items[i].accelerator = next_char; - *ap++ = data->menu.items[i].accelerator; - } + data->menu.items[i].accelerator = next_char; + *ap++ = data->menu.items[i].accelerator; + } - next_char ++; - } - } + next_char++; + } + } - /* collect group accelerators */ - data->menu.gacc[0] = '\0'; - ap = data->menu.gacc; - if( data->how != PICK_NONE ) { - for( i=0; imenu.size; i++) { - if( data->menu.items[i].group_accel && - !strchr(data->menu.gacc, data->menu.items[i].group_accel) ) { - *ap++ = data->menu.items[i].group_accel; - *ap = '\x0'; - } - } - } + /* collect group accelerators */ + data->menu.gacc[0] = '\0'; + ap = data->menu.gacc; + if (data->how != PICK_NONE) { + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].group_accel + && !strchr(data->menu.gacc, + data->menu.items[i].group_accel)) { + *ap++ = data->menu.items[i].group_accel; + *ap = '\x0'; + } + } + } - reset_menu_count(NULL, data); - } + reset_menu_count(NULL, data); + } #if defined(WIN_CE_SMARTPHONE) - if( data->type==MENU_TYPE_MENU ) NHSPhoneSetKeypadFromString( accell_str ); + if (data->type == MENU_TYPE_MENU) + NHSPhoneSetKeypadFromString(accell_str); #endif - mswin_popup_display(hWnd, &data->done); + mswin_popup_display(hWnd, &data->done); - /* get the result */ - if( data->result != -1 ) { - if(how==PICK_NONE) { - if(data->result>=0) ret_val=0; - else ret_val=-1; - } else if(how==PICK_ONE || how==PICK_ANY) { - /* count selected items */ - ret_val = 0; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - NHMENU_IS_SELECTED(data->menu.items[i]) ) { - ret_val++; - } - } - if( ret_val > 0 ) { - int sel_ind; + /* get the result */ + if (data->result != -1) { + if (how == PICK_NONE) { + if (data->result >= 0) + ret_val = 0; + else + ret_val = -1; + } else if (how == PICK_ONE || how == PICK_ANY) { + /* count selected items */ + ret_val = 0; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && NHMENU_IS_SELECTED(data->menu.items[i])) { + ret_val++; + } + } + if (ret_val > 0) { + int sel_ind; - selected = (MENU_ITEM_P*)malloc(ret_val*sizeof(MENU_ITEM_P)); - if( !selected ) panic("out of memory"); + selected = + (MENU_ITEM_P *) malloc(ret_val * sizeof(MENU_ITEM_P)); + if (!selected) + panic("out of memory"); - sel_ind = 0; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - NHMENU_IS_SELECTED(data->menu.items[i]) ) { - selected[sel_ind].item = data->menu.items[i].identifier; - selected[sel_ind].count = data->menu.items[i].count; - sel_ind++; - } - } - ret_val = sel_ind; - *_selected = selected; - } - } - } + sel_ind = 0; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && NHMENU_IS_SELECTED(data->menu.items[i])) { + selected[sel_ind].item = + data->menu.items[i].identifier; + selected[sel_ind].count = data->menu.items[i].count; + sel_ind++; + } + } + ret_val = sel_ind; + *_selected = selected; + } + } + } - mswin_popup_destroy(hWnd); + mswin_popup_destroy(hWnd); #if defined(WIN_CE_SMARTPHONE) - if( data->type==MENU_TYPE_MENU ) NHSPhoneSetKeypadDefault(); + if (data->type == MENU_TYPE_MENU) + NHSPhoneSetKeypadDefault(); #endif - return ret_val; + return ret_val; } - -LRESULT CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +LRESULT CALLBACK +MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMenuWindow data; - - CheckInputDialog(hWnd, message, wParam, lParam); + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch (message) - { - case WM_INITDIALOG: { - HWND text_control; - HDC hDC; + CheckInputDialog(hWnd, message, wParam, lParam); - text_control = GetDlgItem(hWnd, IDC_MENU_TEXT); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (message) { + case WM_INITDIALOG: { + HWND text_control; + HDC hDC; - data = (PNHMenuWindow)malloc(sizeof(NHMenuWindow)); - ZeroMemory(data, sizeof(NHMenuWindow)); - data->type = MENU_TYPE_TEXT; - data->how = PICK_NONE; - data->result = 0; - data->done = 0; - data->bmpChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL)); - data->bmpCheckedCount = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL_COUNT)); - data->bmpNotChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + text_control = GetDlgItem(hWnd, IDC_MENU_TEXT); - /* subclass edit control */ - editControlWndProc = (WNDPROC)GetWindowLong(text_control, GWL_WNDPROC); - SetWindowLong(text_control, GWL_WNDPROC, (LONG)NHMenuTextWndProc); + data = (PNHMenuWindow) malloc(sizeof(NHMenuWindow)); + ZeroMemory(data, sizeof(NHMenuWindow)); + data->type = MENU_TYPE_TEXT; + data->how = PICK_NONE; + data->result = 0; + data->done = 0; + data->bmpChecked = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL)); + data->bmpCheckedCount = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL_COUNT)); + data->bmpNotChecked = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); - /* set text window font */ - hDC = GetDC(text_control); - SendMessage( - text_control, - WM_SETFONT, - (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hDC, FALSE), - (LPARAM)0 - ); - ReleaseDC(text_control, hDC); + /* subclass edit control */ + editControlWndProc = + (WNDPROC) GetWindowLong(text_control, GWL_WNDPROC); + SetWindowLong(text_control, GWL_WNDPROC, (LONG) NHMenuTextWndProc); + + /* set text window font */ + hDC = GetDC(text_control); + SendMessage(text_control, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hDC, FALSE), + (LPARAM) 0); + ReleaseDC(text_control, hDC); #if defined(WIN_CE_SMARTPHONE) - /* special initialization for SmartPhone dialogs */ - NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, GetNHApp()->bFullScreen); + /* special initialization for SmartPhone dialogs */ + NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, + GetNHApp()->bFullScreen); #endif - } break; + } break; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SIZE: - LayoutMenu(hWnd); - return FALSE; + case WM_SIZE: + LayoutMenu(hWnd); + return FALSE; - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDCANCEL: - if( data->type == MENU_TYPE_MENU && - (data->how==PICK_ONE || data->how==PICK_ANY) && - data->menu.counting) { - HWND list; - int i; + case WM_COMMAND: { + switch (LOWORD(wParam)) { + case IDCANCEL: + if (data->type == MENU_TYPE_MENU + && (data->how == PICK_ONE || data->how == PICK_ANY) + && data->menu.counting) { + HWND list; + int i; - /* reset counter if counting is in progress */ - list = GetMenuControl(hWnd); - i = ListView_GetNextItem(list, -1, LVNI_FOCUSED); - if( i>=0 ) { - SelectMenuItem(list, data, i, 0); - } - return FALSE; - } else { - data->result = -1; - data->done = 1; - } - return FALSE; + /* reset counter if counting is in progress */ + list = GetMenuControl(hWnd); + i = ListView_GetNextItem(list, -1, LVNI_FOCUSED); + if (i >= 0) { + SelectMenuItem(list, data, i, 0); + } + return FALSE; + } else { + data->result = -1; + data->done = 1; + } + return FALSE; - case IDOK: - data->done = 1; - data->result = 0; - return FALSE; - } - } break; + case IDOK: + data->done = 1; + data->result = 0; + return FALSE; + } + } break; - case WM_NOTIFY: - { - LPNMHDR lpnmhdr = (LPNMHDR)lParam; - switch (LOWORD(wParam)) { - case IDC_MENU_LIST: - { - if( !data || data->type!=MENU_TYPE_MENU ) break; + case WM_NOTIFY: { + LPNMHDR lpnmhdr = (LPNMHDR) lParam; + switch (LOWORD(wParam)) { + case IDC_MENU_LIST: { + if (!data || data->type != MENU_TYPE_MENU) + break; - switch(lpnmhdr->code) { - case LVN_ITEMACTIVATE: - { - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; - if(data->how==PICK_ONE) { - if( lpnmlv->iItem>=0 && - lpnmlv->iItemmenu.size && - NHMENU_IS_SELECTABLE(data->menu.items[lpnmlv->iItem]) ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - -1 - ); - data->done = 1; - data->result = 0; - return TRUE; - } - } else if( data->how==PICK_ANY ) { - if( lpnmlv->iItem>=0 && - lpnmlv->iItemmenu.size && - NHMENU_IS_SELECTABLE(data->menu.items[lpnmlv->iItem]) ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - NHMENU_IS_SELECTED(data->menu.items[lpnmlv->iItem])? 0 : -1 - ); - } - } - } break; + switch (lpnmhdr->code) { + case LVN_ITEMACTIVATE: { + LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; + if (data->how == PICK_ONE) { + if (lpnmlv->iItem >= 0 && lpnmlv->iItem < data->menu.size + && NHMENU_IS_SELECTABLE( + data->menu.items[lpnmlv->iItem])) { + SelectMenuItem(lpnmlv->hdr.hwndFrom, data, + lpnmlv->iItem, -1); + data->done = 1; + data->result = 0; + return TRUE; + } + } else if (data->how == PICK_ANY) { + if (lpnmlv->iItem >= 0 && lpnmlv->iItem < data->menu.size + && NHMENU_IS_SELECTABLE( + data->menu.items[lpnmlv->iItem])) { + SelectMenuItem(lpnmlv->hdr.hwndFrom, data, + lpnmlv->iItem, + NHMENU_IS_SELECTED( + data->menu.items[lpnmlv->iItem]) + ? 0 + : -1); + } + } + } break; - case NM_CLICK: { - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; - if( lpnmlv->iItem==-1 ) return 0; - if( data->how==PICK_ANY ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - NHMENU_IS_SELECTED(data->menu.items[lpnmlv->iItem])? 0 : -1 - ); - } - } break; + case NM_CLICK: { + LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; + if (lpnmlv->iItem == -1) + return 0; + if (data->how == PICK_ANY) { + SelectMenuItem( + lpnmlv->hdr.hwndFrom, data, lpnmlv->iItem, + NHMENU_IS_SELECTED(data->menu.items[lpnmlv->iItem]) + ? 0 + : -1); + } + } break; - case LVN_ITEMCHANGED: - { - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; - if( lpnmlv->iItem==-1 ) return 0; - if( !(lpnmlv->uChanged & LVIF_STATE) ) return 0; + case LVN_ITEMCHANGED: { + LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; + if (lpnmlv->iItem == -1) + return 0; + if (!(lpnmlv->uChanged & LVIF_STATE)) + return 0; - /* update item that has the focus */ - data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); - ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); + /* update item that has the focus */ + data->menu.items[lpnmlv->iItem].has_focus = + !!(lpnmlv->uNewState & LVIS_FOCUSED); + ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, + lpnmlv->iItem); - /* update count for single-selection menu (follow the listview selection) */ - if( data->how==PICK_ONE ) { - if( lpnmlv->uNewState & LVIS_SELECTED ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - -1 - ); - } - } + /* update count for single-selection menu (follow the listview + * selection) */ + if (data->how == PICK_ONE) { + if (lpnmlv->uNewState & LVIS_SELECTED) { + SelectMenuItem(lpnmlv->hdr.hwndFrom, data, + lpnmlv->iItem, -1); + } + } - /* check item focus */ - data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); - ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); - } break; + /* check item focus */ + data->menu.items[lpnmlv->iItem].has_focus = + !!(lpnmlv->uNewState & LVIS_FOCUSED); + ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, + lpnmlv->iItem); + } break; - case NM_KILLFOCUS: - reset_menu_count(lpnmhdr->hwndFrom, data); - break; + case NM_KILLFOCUS: + reset_menu_count(lpnmhdr->hwndFrom, data); + break; + } + } break; + } + } break; - } - } break; - } - } break; + case WM_SETFOCUS: + if (hWnd != GetNHApp()->hPopupWnd) { + SetFocus(GetNHApp()->hPopupWnd); + return 0; + } + break; - case WM_SETFOCUS: - if( hWnd!=GetNHApp()->hPopupWnd ) { - SetFocus(GetNHApp()->hPopupWnd ); - return 0; - } - break; - - case WM_MEASUREITEM: - if( wParam==IDC_MENU_LIST ) - return onMeasureItem(hWnd, wParam, lParam); - else - return FALSE; + case WM_MEASUREITEM: + if (wParam == IDC_MENU_LIST) + return onMeasureItem(hWnd, wParam, lParam); + else + return FALSE; case WM_DRAWITEM: - if( wParam==IDC_MENU_LIST ) - return onDrawItem(hWnd, wParam, lParam); - else - return FALSE; + if (wParam == IDC_MENU_LIST) + return onDrawItem(hWnd, wParam, lParam); + else + return FALSE; - case WM_CTLCOLORBTN: - case WM_CTLCOLOREDIT: - case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ - HDC hdcEdit = (HDC) wParam; - HWND hwndEdit = (HWND) lParam; - if( hwndEdit == GetDlgItem(hWnd, IDC_MENU_TEXT) ) { - SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); - SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); - return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); - } - } return FALSE; + case WM_CTLCOLORBTN: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ + HDC hdcEdit = (HDC) wParam; + HWND hwndEdit = (HWND) lParam; + if (hwndEdit == GetDlgItem(hWnd, IDC_MENU_TEXT)) { + SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); + SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); + return (BOOL) mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); + } + } + return FALSE; - case WM_DESTROY: - if( data ) { - DeleteObject(data->bmpChecked); - DeleteObject(data->bmpCheckedCount); - DeleteObject(data->bmpNotChecked); - if( data->type == MENU_TYPE_TEXT ) { - if( data->text.text ) { - mswin_free_text_buffer(data->text.text); - data->text.text = NULL; - } - } - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - } - return TRUE; - } - return FALSE; + case WM_DESTROY: + if (data) { + DeleteObject(data->bmpChecked); + DeleteObject(data->bmpCheckedCount); + DeleteObject(data->bmpNotChecked); + if (data->type == MENU_TYPE_TEXT) { + if (data->text.text) { + mswin_free_text_buffer(data->text.text); + data->text.text = NULL; + } + } + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + } + return TRUE; + } + return FALSE; } -void CheckInputDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +void +CheckInputDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { #if defined(WIN_CE_POCKETPC) - PNHMenuWindow data; + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); - if( !( data && - data->type==MENU_TYPE_MENU && - (data->how==PICK_ONE || data->how==PICK_ANY) ) ) return; - - switch(message) { - case WM_SETFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_UP); - return; + if (!(data && data->type == MENU_TYPE_MENU + && (data->how == PICK_ONE || data->how == PICK_ANY))) + return; - case WM_DESTROY: - case WM_KILLFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_DOWN); - return; + switch (message) { + case WM_SETFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_UP); + return; - case WM_NOTIFY: - { - LPNMHDR lpnmhdr = (LPNMHDR)lParam; - switch(lpnmhdr->code) { - case NM_SETFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_UP); - break; - case NM_KILLFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_DOWN); - break; - } - } return; + case WM_DESTROY: + case WM_KILLFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_DOWN); + return; - case WM_COMMAND: - switch(HIWORD(wParam)) { - case BN_SETFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_UP); - break; - case BN_KILLFOCUS: - if( GetNHApp()->bUseSIP ) SHSipPreference(hWnd, SIP_DOWN); - break; - } - return; + case WM_NOTIFY: { + LPNMHDR lpnmhdr = (LPNMHDR) lParam; + switch (lpnmhdr->code) { + case NM_SETFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_UP); + break; + case NM_KILLFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_DOWN); + break; + } + } + return; - } /* end switch */ + case WM_COMMAND: + switch (HIWORD(wParam)) { + case BN_SETFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_UP); + break; + case BN_KILLFOCUS: + if (GetNHApp()->bUseSIP) + SHSipPreference(hWnd, SIP_DOWN); + break; + } + return; + + } /* end switch */ #endif } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMenuWindow data; + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: - { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - HWND text_view; + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + HWND text_view; - if( data->type!=MENU_TYPE_TEXT ) - SetMenuType(hWnd, MENU_TYPE_TEXT); + if (data->type != MENU_TYPE_TEXT) + SetMenuType(hWnd, MENU_TYPE_TEXT); - if( !data->text.text ) { - data->text.text = mswin_init_text_buffer( - program_state.gameover? FALSE : GetNHApp()->bWrapText - ); - if( !data->text.text ) break; - } - - mswin_add_text(data->text.text, msg_data->attr, msg_data->text); - - text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); - if( !text_view ) panic("cannot get text view window"); - mswin_render_text(data->text.text, text_view); - } break; + if (!data->text.text) { + data->text.text = mswin_init_text_buffer( + program_state.gameover ? FALSE : GetNHApp()->bWrapText); + if (!data->text.text) + break; + } - case MSNH_MSG_STARTMENU: - { - int i; + mswin_add_text(data->text.text, msg_data->attr, msg_data->text); - if( data->type!=MENU_TYPE_MENU ) - SetMenuType(hWnd, MENU_TYPE_MENU); + text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); + if (!text_view) + panic("cannot get text view window"); + mswin_render_text(data->text.text, text_view); + } break; - if( data->menu.items ) free(data->menu.items); - data->how = PICK_NONE; - data->menu.items = NULL; - data->menu.size = 0; - data->menu.allocated = 0; - data->done = 0; - data->result = 0; - for (i = 0; i < NUMTABS; ++i) - data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; - } break; + case MSNH_MSG_STARTMENU: { + int i; - case MSNH_MSG_ADDMENU: - { - PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu)lParam; - char *p, *p1; - int new_item; - HDC hDC; - int column; - HFONT saveFont; - - if( data->type!=MENU_TYPE_MENU ) break; - if( strlen(msg_data->str)==0 ) break; + if (data->type != MENU_TYPE_MENU) + SetMenuType(hWnd, MENU_TYPE_MENU); - if( data->menu.size==data->menu.allocated ) { - data->menu.allocated += 10; - data->menu.items = (PNHMenuItem)realloc(data->menu.items, data->menu.allocated*sizeof(NHMenuItem)); - } + if (data->menu.items) + free(data->menu.items); + data->how = PICK_NONE; + data->menu.items = NULL; + data->menu.size = 0; + data->menu.allocated = 0; + data->done = 0; + data->result = 0; + for (i = 0; i < NUMTABS; ++i) + data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; + } break; - new_item = data->menu.size; - ZeroMemory( &data->menu.items[new_item], sizeof(data->menu.items[new_item])); - data->menu.items[new_item].glyph = msg_data->glyph; - data->menu.items[new_item].identifier = *msg_data->identifier; - data->menu.items[new_item].accelerator = msg_data->accelerator; - data->menu.items[new_item].group_accel = msg_data->group_accel; - data->menu.items[new_item].attr = msg_data->attr; - parse_menu_str(data->menu.items[new_item].str, msg_data->str, NHMENU_STR_SIZE); - data->menu.items[new_item].presel = msg_data->presel; + case MSNH_MSG_ADDMENU: { + PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu) lParam; + char *p, *p1; + int new_item; + HDC hDC; + int column; + HFONT saveFont; - /* calculate tabstop size */ - p = strchr(data->menu.items[new_item].str, '\t'); - if( p ) { - data->menu.items[new_item].has_tab = TRUE; - hDC = GetDC(hWnd); - saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); - p1 = data->menu.items[new_item].str; - column = 0; - for (;;) { - TCHAR wbuf[BUFSZ]; - RECT drawRect; - SetRect ( &drawRect, 0, 0, 1, 1 ); - if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ - DrawText(hDC, - NH_A2W(p1, wbuf, BUFSZ), - strlen(p1), - &drawRect, - DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS | DT_SINGLELINE - ); - data->menu.tab_stop_size[column] = - max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left ); - if (p != NULL) *p = '\t'; - else /* last string so, */ break; + if (data->type != MENU_TYPE_MENU) + break; + if (strlen(msg_data->str) == 0) + break; - ++column; - p1 = p + 1; - p = strchr(p1, '\t'); - } - SelectObject(hDC, saveFont); - ReleaseDC(hWnd, hDC); - } else { - data->menu.items[new_item].has_tab = FALSE; - } + if (data->menu.size == data->menu.allocated) { + data->menu.allocated += 10; + data->menu.items = (PNHMenuItem) realloc( + data->menu.items, data->menu.allocated * sizeof(NHMenuItem)); + } - /* increment size */ - data->menu.size++; - } break; + new_item = data->menu.size; + ZeroMemory(&data->menu.items[new_item], + sizeof(data->menu.items[new_item])); + data->menu.items[new_item].glyph = msg_data->glyph; + data->menu.items[new_item].identifier = *msg_data->identifier; + data->menu.items[new_item].accelerator = msg_data->accelerator; + data->menu.items[new_item].group_accel = msg_data->group_accel; + data->menu.items[new_item].attr = msg_data->attr; + parse_menu_str(data->menu.items[new_item].str, msg_data->str, + NHMENU_STR_SIZE); + data->menu.items[new_item].presel = msg_data->presel; - case MSNH_MSG_ENDMENU: - { - PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu)lParam; - if( msg_data->text ) { - strncpy( data->menu.prompt, msg_data->text, sizeof(data->menu.prompt)-1 ); - } else { - ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); - } - } break; + /* calculate tabstop size */ + p = strchr(data->menu.items[new_item].str, '\t'); + if (p) { + data->menu.items[new_item].has_tab = TRUE; + hDC = GetDC(hWnd); + saveFont = SelectObject( + hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); + p1 = data->menu.items[new_item].str; + column = 0; + for (;;) { + TCHAR wbuf[BUFSZ]; + RECT drawRect; + SetRect(&drawRect, 0, 0, 1, 1); + if (p != NULL) + *p = '\0'; /* for time being, view tab field as zstring */ + DrawText(hDC, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), &drawRect, + DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS + | DT_SINGLELINE); + data->menu.tab_stop_size[column] = + max(data->menu.tab_stop_size[column], + drawRect.right - drawRect.left); + if (p != NULL) + *p = '\t'; + else /* last string so, */ + break; - } /* end switch */ + ++column; + p1 = p + 1; + p = strchr(p1, '\t'); + } + SelectObject(hDC, saveFont); + ReleaseDC(hWnd, hDC); + } else { + data->menu.items[new_item].has_tab = FALSE; + } + + /* increment size */ + data->menu.size++; + } break; + + case MSNH_MSG_ENDMENU: { + PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu) lParam; + if (msg_data->text) { + strncpy(data->menu.prompt, msg_data->text, + sizeof(data->menu.prompt) - 1); + } else { + ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); + } + } break; + + } /* end switch */ } -void LayoutMenu(HWND hWnd) +void +LayoutMenu(HWND hWnd) { - PNHMenuWindow data; - HWND menu_ok; - HWND menu_cancel; - RECT clrt, rt; - POINT pt_elem, pt_ok, pt_cancel; - SIZE sz_elem, sz_ok, sz_cancel; + PNHMenuWindow data; + HWND menu_ok; + HWND menu_cancel; + RECT clrt, rt; + POINT pt_elem, pt_ok, pt_cancel; + SIZE sz_elem, sz_ok, sz_cancel; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - menu_ok = GetDlgItem(hWnd, IDOK); - menu_cancel = GetDlgItem(hWnd, IDCANCEL); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + menu_ok = GetDlgItem(hWnd, IDOK); + menu_cancel = GetDlgItem(hWnd, IDCANCEL); - /* get window coordinates */ - GetClientRect(hWnd, &clrt ); - - /* set window placements */ - if( IsWindow(menu_ok) ) { - GetWindowRect(menu_ok, &rt); - sz_ok.cx = (clrt.right - clrt.left)/2 - 2*MENU_MARGIN; - sz_ok.cy = rt.bottom-rt.top; - pt_ok.x = clrt.left + MENU_MARGIN; - pt_ok.y = clrt.bottom - MENU_MARGIN - sz_ok.cy; - MoveWindow(menu_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE ); - } else { - pt_ok.x = 0; - pt_ok.y = clrt.bottom; - sz_ok.cx = sz_ok.cy = 0; - } - - if( IsWindow(menu_cancel) ) { - GetWindowRect(menu_cancel, &rt); - sz_cancel.cx = (clrt.right - clrt.left)/2 - 2*MENU_MARGIN; - sz_cancel.cy = rt.bottom-rt.top; - pt_cancel.x = (clrt.left + clrt.right)/2 + MENU_MARGIN; - pt_cancel.y = clrt.bottom - MENU_MARGIN - sz_cancel.cy; - MoveWindow(menu_cancel, pt_cancel.x, pt_cancel.y, sz_cancel.cx, sz_cancel.cy, TRUE ); - } else { - pt_cancel.x = 0; - pt_cancel.y = clrt.bottom; - sz_cancel.cx = sz_cancel.cy = 0; - } + /* get window coordinates */ + GetClientRect(hWnd, &clrt); - pt_elem.x = clrt.left + MENU_MARGIN; - pt_elem.y = clrt.top + MENU_MARGIN; - sz_elem.cx = (clrt.right - clrt.left) - 2*MENU_MARGIN; - sz_elem.cy = min(pt_cancel.y, pt_ok.y) - MENU_MARGIN - pt_elem.y; - MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); + /* set window placements */ + if (IsWindow(menu_ok)) { + GetWindowRect(menu_ok, &rt); + sz_ok.cx = (clrt.right - clrt.left) / 2 - 2 * MENU_MARGIN; + sz_ok.cy = rt.bottom - rt.top; + pt_ok.x = clrt.left + MENU_MARGIN; + pt_ok.y = clrt.bottom - MENU_MARGIN - sz_ok.cy; + MoveWindow(menu_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); + } else { + pt_ok.x = 0; + pt_ok.y = clrt.bottom; + sz_ok.cx = sz_ok.cy = 0; + } - /* reformat text for the text menu */ - if( data && - data->type==MENU_TYPE_TEXT && - data->text.text ) - mswin_render_text(data->text.text, GetMenuControl(hWnd)); + if (IsWindow(menu_cancel)) { + GetWindowRect(menu_cancel, &rt); + sz_cancel.cx = (clrt.right - clrt.left) / 2 - 2 * MENU_MARGIN; + sz_cancel.cy = rt.bottom - rt.top; + pt_cancel.x = (clrt.left + clrt.right) / 2 + MENU_MARGIN; + pt_cancel.y = clrt.bottom - MENU_MARGIN - sz_cancel.cy; + MoveWindow(menu_cancel, pt_cancel.x, pt_cancel.y, sz_cancel.cx, + sz_cancel.cy, TRUE); + } else { + pt_cancel.x = 0; + pt_cancel.y = clrt.bottom; + sz_cancel.cx = sz_cancel.cy = 0; + } + + pt_elem.x = clrt.left + MENU_MARGIN; + pt_elem.y = clrt.top + MENU_MARGIN; + sz_elem.cx = (clrt.right - clrt.left) - 2 * MENU_MARGIN; + sz_elem.cy = min(pt_cancel.y, pt_ok.y) - MENU_MARGIN - pt_elem.y; + MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, + sz_elem.cy, TRUE); + + /* reformat text for the text menu */ + if (data && data->type == MENU_TYPE_TEXT && data->text.text) + mswin_render_text(data->text.text, GetMenuControl(hWnd)); } -void SetMenuType(HWND hWnd, int type) +void +SetMenuType(HWND hWnd, int type) { - PNHMenuWindow data; - HWND list, text; + PNHMenuWindow data; + HWND list, text; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); - data->type = type; - - text = GetDlgItem(hWnd, IDC_MENU_TEXT); - list = GetDlgItem(hWnd, IDC_MENU_LIST); - if(data->type==MENU_TYPE_TEXT) { - ShowWindow(list, SW_HIDE); - EnableWindow(list, FALSE); - EnableWindow(text, TRUE); - ShowWindow(text, SW_SHOW); - SetFocus(text); - } else { - ShowWindow(text, SW_HIDE); - EnableWindow(text, FALSE); - EnableWindow(list, TRUE); - ShowWindow(list, SW_SHOW); - SetFocus(list); - } - LayoutMenu(hWnd); + data->type = type; + + text = GetDlgItem(hWnd, IDC_MENU_TEXT); + list = GetDlgItem(hWnd, IDC_MENU_LIST); + if (data->type == MENU_TYPE_TEXT) { + ShowWindow(list, SW_HIDE); + EnableWindow(list, FALSE); + EnableWindow(text, TRUE); + ShowWindow(text, SW_SHOW); + SetFocus(text); + } else { + ShowWindow(text, SW_HIDE); + EnableWindow(text, FALSE); + EnableWindow(list, TRUE); + ShowWindow(list, SW_SHOW); + SetFocus(list); + } + LayoutMenu(hWnd); } -void SetMenuListType(HWND hWnd, int how) +void +SetMenuListType(HWND hWnd, int how) { - PNHMenuWindow data; - RECT rt; - DWORD dwStyles; - char buf[BUFSZ]; - TCHAR wbuf[BUFSZ]; - int nItem; - int i; - HWND control; - LVCOLUMN lvcol; - LRESULT fnt; - SIZE wnd_size; + PNHMenuWindow data; + RECT rt; + DWORD dwStyles; + char buf[BUFSZ]; + TCHAR wbuf[BUFSZ]; + int nItem; + int i; + HWND control; + LVCOLUMN lvcol; + LRESULT fnt; + SIZE wnd_size; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( data->type != MENU_TYPE_MENU ) return; + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data->type != MENU_TYPE_MENU) + return; - data->how = how; + data->how = how; - switch(how) { - case PICK_NONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - case PICK_ONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - case PICK_ANY: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - default: panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY"); - }; - if( strlen(data->menu.prompt)==0 ) { - dwStyles |= LVS_NOCOLUMNHEADER ; - } + switch (how) { + case PICK_NONE: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + case PICK_ONE: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + case PICK_ANY: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + default: + panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY"); + }; + if (strlen(data->menu.prompt) == 0) { + dwStyles |= LVS_NOCOLUMNHEADER; + } - GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt); - DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST)); - control = CreateWindow(WC_LISTVIEW, NULL, - dwStyles, - rt.left, - rt.top, - rt.right - rt.left, - rt.bottom - rt.top, - hWnd, - (HMENU)IDC_MENU_LIST, - GetNHApp()->hApp, - NULL ); - if( !control ) panic( "cannot create menu control" ); - - /* install the hook for the control window procedure */ - wndProcListViewOrig = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); - SetWindowLong(control, GWL_WNDPROC, (LONG)NHMenuListWndProc); + GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt); + DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST)); + control = CreateWindow(WC_LISTVIEW, NULL, dwStyles, rt.left, rt.top, + rt.right - rt.left, rt.bottom - rt.top, hWnd, + (HMENU) IDC_MENU_LIST, GetNHApp()->hApp, NULL); + if (!control) + panic("cannot create menu control"); - /* set control font */ - fnt = SendMessage(hWnd, WM_GETFONT, (WPARAM)0, (LPARAM)0); - SendMessage(control, WM_SETFONT, (WPARAM)fnt, (LPARAM)0); + /* install the hook for the control window procedure */ + wndProcListViewOrig = (WNDPROC) GetWindowLong(control, GWL_WNDPROC); + SetWindowLong(control, GWL_WNDPROC, (LONG) NHMenuListWndProc); - /* set control colors */ - ListView_SetBkColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); - ListView_SetTextBkColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); - ListView_SetTextColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); + /* set control font */ + fnt = SendMessage(hWnd, WM_GETFONT, (WPARAM) 0, (LPARAM) 0); + SendMessage(control, WM_SETFONT, (WPARAM) fnt, (LPARAM) 0); - /* add column to the list view */ - mswin_menu_window_size(hWnd, &wnd_size); + /* set control colors */ + ListView_SetBkColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); + ListView_SetTextBkColor(control, + mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); + ListView_SetTextColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); - ZeroMemory(&lvcol, sizeof(lvcol)); - lvcol.mask = LVCF_WIDTH | LVCF_TEXT; - lvcol.cx = max( wnd_size.cx, GetSystemMetrics(SM_CXSCREEN)); - lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ); - ListView_InsertColumn(control, 0, &lvcol); + /* add column to the list view */ + mswin_menu_window_size(hWnd, &wnd_size); - /* add items to the list view */ - for(i=0; imenu.size; i++ ) { - LVITEM lvitem; - ZeroMemory( &lvitem, sizeof(lvitem) ); - sprintf(buf, "%c - %s", max(data->menu.items[i].accelerator, ' '), data->menu.items[i].str ); + ZeroMemory(&lvcol, sizeof(lvcol)); + lvcol.mask = LVCF_WIDTH | LVCF_TEXT; + lvcol.cx = max(wnd_size.cx, GetSystemMetrics(SM_CXSCREEN)); + lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ); + ListView_InsertColumn(control, 0, &lvcol); - lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT; - lvitem.iItem = i; - lvitem.iSubItem = 0; - lvitem.state = data->menu.items[i].presel? LVIS_SELECTED : 0; - lvitem.pszText = NH_A2W(buf, wbuf, BUFSZ); - lvitem.lParam = (LPARAM)&data->menu.items[i]; - nItem = SendMessage(control, LB_ADDSTRING, (WPARAM)0, (LPARAM) buf); - if( ListView_InsertItem(control, &lvitem)==-1 ) { - panic("cannot insert menu item"); - } - } - SetFocus(control); + /* add items to the list view */ + for (i = 0; i < data->menu.size; i++) { + LVITEM lvitem; + ZeroMemory(&lvitem, sizeof(lvitem)); + sprintf(buf, "%c - %s", max(data->menu.items[i].accelerator, ' '), + data->menu.items[i].str); + + lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT; + lvitem.iItem = i; + lvitem.iSubItem = 0; + lvitem.state = data->menu.items[i].presel ? LVIS_SELECTED : 0; + lvitem.pszText = NH_A2W(buf, wbuf, BUFSZ); + lvitem.lParam = (LPARAM) &data->menu.items[i]; + nItem = SendMessage(control, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buf); + if (ListView_InsertItem(control, &lvitem) == -1) { + panic("cannot insert menu item"); + } + } + SetFocus(control); } - -HWND GetMenuControl(HWND hWnd) +HWND +GetMenuControl(HWND hWnd) { - PNHMenuWindow data; + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); - if(data->type==MENU_TYPE_TEXT) { - return GetDlgItem(hWnd, IDC_MENU_TEXT); - } else { - return GetDlgItem(hWnd, IDC_MENU_LIST); - } + if (data->type == MENU_TYPE_TEXT) { + return GetDlgItem(hWnd, IDC_MENU_TEXT); + } else { + return GetDlgItem(hWnd, IDC_MENU_LIST); + } } - -LRESULT onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam) +LRESULT +onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { - LPMEASUREITEMSTRUCT lpmis; + LPMEASUREITEMSTRUCT lpmis; TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC hdc; - PNHMenuWindow data; - RECT list_rect; + HGDIOBJ saveFont; + HDC hdc; + PNHMenuWindow data; + RECT list_rect; - lpmis = (LPMEASUREITEMSTRUCT) lParam; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - GetClientRect(GetMenuControl(hWnd), &list_rect); + lpmis = (LPMEASUREITEMSTRUCT) lParam; + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + GetClientRect(GetMenuControl(hWnd), &list_rect); - hdc = GetDC(GetMenuControl(hWnd)); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, FALSE)); - GetTextMetrics(hdc, &tm); + hdc = GetDC(GetMenuControl(hWnd)); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); /* Set the height of the list box items. */ - lpmis->itemHeight = max(tm.tmHeight, TILE_Y)+2; - lpmis->itemWidth = list_rect.right - list_rect.left; + lpmis->itemHeight = max(tm.tmHeight, TILE_Y) + 2; + lpmis->itemWidth = list_rect.right - list_rect.left; - SelectObject(hdc, saveFont); - ReleaseDC(GetMenuControl(hWnd), hdc); - return TRUE; + SelectObject(hdc, saveFont); + ReleaseDC(GetMenuControl(hWnd), hdc); + return TRUE; } -LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) +LRESULT +onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { - LPDRAWITEMSTRUCT lpdis; - PNHMenuItem item; - PNHMenuWindow data; + LPDRAWITEMSTRUCT lpdis; + PNHMenuItem item; + PNHMenuWindow data; TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC tileDC; - short ntile; - int t_x, t_y; - int x, y; - TCHAR wbuf[BUFSZ]; - RECT drawRect; - COLORREF OldBg, OldFg, NewBg; - char *p, *p1; - int column; + HGDIOBJ saveFont; + HDC tileDC; + short ntile; + int t_x, t_y; + int x, y; + TCHAR wbuf[BUFSZ]; + RECT drawRect; + COLORREF OldBg, OldFg, NewBg; + char *p, *p1; + int column; - lpdis = (LPDRAWITEMSTRUCT) lParam; + lpdis = (LPDRAWITEMSTRUCT) lParam; /* If there are no list box items, skip this message. */ - if (lpdis->itemID == -1) return FALSE; + if (lpdis->itemID == -1) + return FALSE; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); item = &data->menu.items[lpdis->itemID]; - tileDC = CreateCompatibleDC(lpdis->hDC); - saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); - NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG); - OldBg = SetBkColor(lpdis->hDC, NewBg); - OldFg = SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); + tileDC = CreateCompatibleDC(lpdis->hDC); + saveFont = SelectObject( + lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); + NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG); + OldBg = SetBkColor(lpdis->hDC, NewBg); + OldFg = + SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); GetTextMetrics(lpdis->hDC, &tm); - x = lpdis->rcItem.left + 1; + x = lpdis->rcItem.left + 1; - /* print check mark if it is a "selectable" menu */ - if( data->how!=PICK_NONE ) { - if( NHMENU_IS_SELECTABLE(*item) ) { - HGDIOBJ saveBrush; - HBRUSH hbrCheckMark; - char buf[2]; + /* print check mark if it is a "selectable" menu */ + if (data->how != PICK_NONE) { + if (NHMENU_IS_SELECTABLE(*item)) { + HGDIOBJ saveBrush; + HBRUSH hbrCheckMark; + char buf[2]; - switch(item->count) { - case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break; - case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break; - default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break; - } + switch (item->count) { + case -1: + hbrCheckMark = CreatePatternBrush(data->bmpChecked); + break; + case 0: + hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); + break; + default: + hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); + break; + } - y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; - SetBrushOrgEx(lpdis->hDC, x, y, NULL); - saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); - PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); - SelectObject(lpdis->hDC, saveBrush); - DeleteObject(hbrCheckMark); + y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; + SetBrushOrgEx(lpdis->hDC, x, y, NULL); + saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); + PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); + SelectObject(lpdis->hDC, saveBrush); + DeleteObject(hbrCheckMark); - x += TILE_X + 5; + x += TILE_X + 5; - if(item->accelerator!=0) { - buf[0] = item->accelerator; - buf[1] = '\x0'; + if (item->accelerator != 0) { + buf[0] = item->accelerator; + buf[1] = '\x0'; - SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom ); - DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); - } - x += tm.tmAveCharWidth + tm.tmOverhang + 5; - } else { - x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10; - } - } + SetRect(&drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, + lpdis->rcItem.bottom); + DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, + DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + } + x += tm.tmAveCharWidth + tm.tmOverhang + 5; + } else { + x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10; + } + } - /* print glyph if present */ - if( item->glyph != NO_GLYPH ) { - HGDIOBJ saveBmp; + /* print glyph if present */ + if (item->glyph != NO_GLYPH) { + HGDIOBJ saveBmp; - saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); - ntile = glyph2tile[ item->glyph ]; - t_x = (ntile % TILES_PER_LINE)*TILE_X; - t_y = (ntile / TILES_PER_LINE)*TILE_Y; + saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); + ntile = glyph2tile[item->glyph]; + t_x = (ntile % TILES_PER_LINE) * TILE_X; + t_y = (ntile / TILES_PER_LINE) * TILE_Y; - y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; + y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; - nhapply_image_transparent( - lpdis->hDC, x, y, TILE_X, TILE_Y, - tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR ); - SelectObject(tileDC, saveBmp); - } + nhapply_image_transparent(lpdis->hDC, x, y, TILE_X, TILE_Y, tileDC, + t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR); + SelectObject(tileDC, saveBmp); + } - x += TILE_X + 5; + x += TILE_X + 5; - /* draw item text */ - if( item->has_tab ) { - p1 = item->str; - p = strchr(item->str, '\t'); - column = 0; - SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), - lpdis->rcItem.bottom ); - for (;;) { - TCHAR wbuf[BUFSZ]; - if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ - DrawText(lpdis->hDC, - NH_A2W(p1, wbuf, BUFSZ), - strlen(p1), - &drawRect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE - ); - if (p != NULL) *p = '\t'; - else /* last string so, */ break; + /* draw item text */ + if (item->has_tab) { + p1 = item->str; + p = strchr(item->str, '\t'); + column = 0; + SetRect(&drawRect, x, lpdis->rcItem.top, + min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), + lpdis->rcItem.bottom); + for (;;) { + TCHAR wbuf[BUFSZ]; + if (p != NULL) + *p = '\0'; /* for time being, view tab field as zstring */ + DrawText(lpdis->hDC, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), + &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE); + if (p != NULL) + *p = '\t'; + else /* last string so, */ + break; - p1 = p + 1; - p = strchr(p1, '\t'); - drawRect.left = drawRect.right + TAB_SEPARATION; - ++column; - drawRect.right = min (drawRect.left + data->menu.tab_stop_size[column], lpdis->rcItem.right); - } - } else { - TCHAR wbuf[BUFSZ]; - SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom); - DrawText(lpdis->hDC, - NH_A2W(item->str, wbuf, BUFSZ), - strlen(item->str), - &drawRect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE - ); - } + p1 = p + 1; + p = strchr(p1, '\t'); + drawRect.left = drawRect.right + TAB_SEPARATION; + ++column; + drawRect.right = + min(drawRect.left + data->menu.tab_stop_size[column], + lpdis->rcItem.right); + } + } else { + TCHAR wbuf[BUFSZ]; + SetRect(&drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, + lpdis->rcItem.bottom); + DrawText(lpdis->hDC, NH_A2W(item->str, wbuf, BUFSZ), + strlen(item->str), &drawRect, + DT_LEFT | DT_VCENTER | DT_SINGLELINE); + } - /* draw focused item */ - if( item->has_focus ) { - RECT client_rt; - HBRUSH bkBrush; + /* draw focused item */ + if (item->has_focus) { + RECT client_rt; + HBRUSH bkBrush; - GetClientRect(lpdis->hwndItem, &client_rt); - if( NHMENU_IS_SELECTABLE(*item) && - data->menu.items[lpdis->itemID].count>0 && - item->glyph != NO_GLYPH ) { - if( data->menu.items[lpdis->itemID].count==-1 ) { - _stprintf(wbuf, TEXT("Count: All") ); - } else { - _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); - } + GetClientRect(lpdis->hwndItem, &client_rt); + if (NHMENU_IS_SELECTABLE(*item) + && data->menu.items[lpdis->itemID].count > 0 + && item->glyph != NO_GLYPH) { + if (data->menu.items[lpdis->itemID].count == -1) { + _stprintf(wbuf, TEXT("Count: All")); + } else { + _stprintf(wbuf, TEXT("Count: %d"), + data->menu.items[lpdis->itemID].count); + } - SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); + SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, + lpdis->hDC, FALSE)); - /* calculate text rectangle */ - SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); - DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, - DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); - - /* erase text rectangle */ - drawRect.left = max(client_rt.left+1, client_rt.right - (drawRect.right - drawRect.left) - 10); - drawRect.right = client_rt.right-1; - drawRect.top = lpdis->rcItem.top; - drawRect.bottom = lpdis->rcItem.bottom; - bkBrush = CreateSolidBrush( GetBkColor(lpdis->hDC) ); - FillRect(lpdis->hDC, &drawRect, bkBrush ); - DeleteObject( bkBrush ); + /* calculate text rectangle */ + SetRect(&drawRect, client_rt.left, lpdis->rcItem.top, + client_rt.right, lpdis->rcItem.bottom); + DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, + DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE + | DT_NOPREFIX); - /* draw text */ - DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, - DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); - } + /* erase text rectangle */ + drawRect.left = + max(client_rt.left + 1, + client_rt.right - (drawRect.right - drawRect.left) - 10); + drawRect.right = client_rt.right - 1; + drawRect.top = lpdis->rcItem.top; + drawRect.bottom = lpdis->rcItem.bottom; + bkBrush = CreateSolidBrush(GetBkColor(lpdis->hDC)); + FillRect(lpdis->hDC, &drawRect, bkBrush); + DeleteObject(bkBrush); - /* draw focus rect */ - SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); - DrawFocusRect(lpdis->hDC, &drawRect); - } + /* draw text */ + DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, + DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + } - SetTextColor (lpdis->hDC, OldFg); - SetBkColor (lpdis->hDC, OldBg); - SelectObject(lpdis->hDC, saveFont); - DeleteDC(tileDC); - return TRUE; + /* draw focus rect */ + SetRect(&drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, + lpdis->rcItem.bottom); + DrawFocusRect(lpdis->hDC, &drawRect); + } + + SetTextColor(lpdis->hDC, OldFg); + SetBkColor(lpdis->hDC, OldBg); + SelectObject(lpdis->hDC, saveFont); + DeleteDC(tileDC); + return TRUE; } -BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) +BOOL +onListChar(HWND hWnd, HWND hwndList, WORD ch) { - int i = 0; - PNHMenuWindow data; - int curIndex, topIndex, pageSize; - boolean is_accelerator = FALSE; + int i = 0; + PNHMenuWindow data; + int curIndex, topIndex, pageSize; + boolean is_accelerator = FALSE; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); - switch( ch ) { - case MENU_FIRST_PAGE: - i = 0; - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + switch (ch) { + case MENU_FIRST_PAGE: + i = 0; + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_LAST_PAGE: - i = max(0, data->menu.size-1); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + case MENU_LAST_PAGE: + i = max(0, data->menu.size - 1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_NEXT_PAGE: - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + case MENU_NEXT_PAGE: + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); /* Focus down one page */ - i = min(curIndex+pageSize, data->menu.size-1); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + i = min(curIndex + pageSize, data->menu.size - 1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); /* Scrollpos down one page */ - i = min(topIndex+(2*pageSize - 1), data->menu.size-1); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + i = min(topIndex + (2 * pageSize - 1), data->menu.size - 1); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_PREVIOUS_PAGE: - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + case MENU_PREVIOUS_PAGE: + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); /* Focus up one page */ - i = max(curIndex-pageSize, 0); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + i = max(curIndex - pageSize, 0); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); /* Scrollpos up one page */ - i = max(topIndex-pageSize, 0); - ListView_EnsureVisible(hwndList, i, FALSE); - break; + i = max(topIndex - pageSize, 0); + ListView_EnsureVisible(hwndList, i, FALSE); + break; - case MENU_SELECT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem(hwndList, data, i, -1); - } - return -2; - } - break; + case MENU_SELECT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, -1); + } + return -2; + } + break; - case MENU_UNSELECT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem(hwndList, data, i, 0); - } - return -2; - } - break; + case MENU_UNSELECT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, 0); + } + return -2; + } + break; - case MENU_INVERT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } - return -2; - } - break; + case MENU_INVERT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } + return -2; + } + break; - case MENU_SELECT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; ihow == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, -1); + } + return -2; + } + break; - case MENU_UNSELECT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; ihow == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, 0); + } + return -2; + } + break; - case MENU_INVERT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; imenu.items[i])? 0 : -1 - ); - } - return -2; - } - break; + case MENU_INVERT_PAGE: + if (data->how == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } + return -2; + } + break; - case MENU_SEARCH: - if( data->how==PICK_ANY || data->how==PICK_ONE ) { - char buf[BUFSZ]; - int selected_item; - - reset_menu_count(hwndList, data); - mswin_getlin("Search for:", buf); - if (!*buf || *buf == '\033') return -2; - selected_item = -1; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) - && strstr(data->menu.items[i].str, buf) ) { - if (data->how == PICK_ANY) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - /* save the first item - we will move focus to it */ - if( selected_item == -1 ) selected_item = i; - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - selected_item = i; - break; - } - } - } + case MENU_SEARCH: + if (data->how == PICK_ANY || data->how == PICK_ONE) { + char buf[BUFSZ]; + int selected_item; - if( selected_item>0 ) { - ListView_SetItemState(hwndList, selected_item, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, selected_item, FALSE); - } - } else { - mswin_nhbell(); - } - return -2; + reset_menu_count(hwndList, data); + mswin_getlin("Search for:", buf); + if (!*buf || *buf == '\033') + return -2; + selected_item = -1; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && strstr(data->menu.items[i].str, buf)) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 : -1); + /* save the first item - we will move focus to it */ + if (selected_item == -1) + selected_item = i; + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + selected_item = i; + break; + } + } + } - case ' ': - /* ends menu for PICK_ONE/PICK_NONE - select item for PICK_ANY */ - if( data->how==PICK_ONE || data->how==PICK_NONE ) { - data->done = 1; - data->result = 0; - return -2; - } else if( data->how==PICK_ANY ) { - i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); - if( i>=0 ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } - return -2; - } - break; + if (selected_item > 0) { + ListView_SetItemState(hwndList, selected_item, LVIS_FOCUSED, + LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, selected_item, FALSE); + } + } else { + mswin_nhbell(); + } + return -2; - default: - if( strchr(data->menu.gacc, ch) && - !(ch=='0' && data->menu.counting) ) { - /* matched a group accelerator */ - if (data->how == PICK_ANY || data->how == PICK_ONE) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - data->menu.items[i].group_accel == ch ) { - if( data->how == PICK_ANY ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - data->result = 0; - data->done = 1; - return -2; - } - } - } - return -2; - } else { - mswin_nhbell(); - return -2; - } - } + case ' ': + /* ends menu for PICK_ONE/PICK_NONE + select item for PICK_ANY */ + if (data->how == PICK_ONE || data->how == PICK_NONE) { + data->done = 1; + data->result = 0; + return -2; + } else if (data->how == PICK_ANY) { + i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + if (i >= 0) { + SelectMenuItem(hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } + return -2; + } + break; - if (isdigit(ch)) { - int count; - i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); - if( i>=0 ) { - count = data->menu.items[i].count; - if( count==-1 ) count=0; - count *= 10L; - count += (int)(ch - '0'); - if (count != 0) /* ignore leading zeros */ { - data->menu.counting = TRUE; - data->menu.items[i].count = min(100000, count); - ListView_RedrawItems( hwndList, i, i ); /* update count mark */ - } - } - return -2; - } + default: + if (strchr(data->menu.gacc, ch) + && !(ch == '0' && data->menu.counting)) { + /* matched a group accelerator */ + if (data->how == PICK_ANY || data->how == PICK_ONE) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && data->menu.items[i].group_accel == ch) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + data->result = 0; + data->done = 1; + return -2; + } + } + } + return -2; + } else { + mswin_nhbell(); + return -2; + } + } - is_accelerator = FALSE; - for(i=0; imenu.size; i++) { - if( data->menu.items[i].accelerator == ch ) { - is_accelerator = TRUE; - break; - } - } + if (isdigit(ch)) { + int count; + i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + if (i >= 0) { + count = data->menu.items[i].count; + if (count == -1) + count = 0; + count *= 10L; + count += (int) (ch - '0'); + if (count != 0) /* ignore leading zeros */ { + data->menu.counting = TRUE; + data->menu.items[i].count = min(100000, count); + ListView_RedrawItems(hwndList, i, + i); /* update count mark */ + } + } + return -2; + } - if( (ch>='a' && ch<='z') || - (ch>='A' && ch<='Z') || is_accelerator) { - if (data->how == PICK_ANY || data->how == PICK_ONE) { - for(i=0; imenu.size; i++ ) { - if( data->menu.items[i].accelerator == ch ) { - if( data->how == PICK_ANY ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - data->result = 0; - data->done = 1; - return -2; - } - } - } - } - } - break; - } + is_accelerator = FALSE; + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator == ch) { + is_accelerator = TRUE; + break; + } + } - reset_menu_count(hwndList, data); - return -1; + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') + || is_accelerator) { + if (data->how == PICK_ANY || data->how == PICK_ONE) { + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator == ch) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, + LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + data->result = 0; + data->done = 1; + return -2; + } + } + } + } + } + break; + } + + reset_menu_count(hwndList, data); + return -1; } -void mswin_menu_window_size (HWND hWnd, LPSIZE sz) +void +mswin_menu_window_size(HWND hWnd, LPSIZE sz) { TEXTMETRIC tm; - HWND control; - HGDIOBJ saveFont; - HDC hdc; - PNHMenuWindow data; - int i; - RECT rt, wrt; - int extra_cx; + HWND control; + HGDIOBJ saveFont; + HDC hdc; + PNHMenuWindow data; + int i; + RECT rt, wrt; + int extra_cx; - GetClientRect(hWnd, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + GetClientRect(hWnd, &rt); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; - GetWindowRect(hWnd, &wrt); - extra_cx = (wrt.right-wrt.left) - sz->cx; + GetWindowRect(hWnd, &wrt); + extra_cx = (wrt.right - wrt.left) - sz->cx; - data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - if(data) { - control = GetMenuControl(hWnd); - hdc = GetDC(control); + data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data) { + control = GetMenuControl(hWnd); + hdc = GetDC(control); - if( data->type==MENU_TYPE_MENU ) { - /* Calculate the width of the list box. */ - saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); - GetTextMetrics(hdc, &tm); - for(i=0; imenu.size; i++ ) { - LONG menuitemwidth = 0; - int column; - char *p, *p1; + if (data->type == MENU_TYPE_MENU) { + /* Calculate the width of the list box. */ + saveFont = SelectObject( + hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); + for (i = 0; i < data->menu.size; i++) { + LONG menuitemwidth = 0; + int column; + char *p, *p1; - p1 = data->menu.items[i].str; - p = strchr(data->menu.items[i].str, '\t'); - column = 0; - for (;;) { - TCHAR wbuf[BUFSZ]; - RECT tabRect; - SetRect ( &tabRect, 0, 0, 1, 1 ); - if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ - DrawText(hdc, - NH_A2W(p1, wbuf, BUFSZ), - strlen(p1), - &tabRect, - DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE - ); - /* it probably isn't necessary to recompute the tab width now, but do so - * just in case, honoring the previously computed value - */ - menuitemwidth += max(data->menu.tab_stop_size[column], - tabRect.right - tabRect.left); - if (p != NULL) *p = '\t'; - else /* last string so, */ break; - /* add the separation only when not the last item */ - /* in the last item, we break out of the loop, in the statement just above */ - menuitemwidth += TAB_SEPARATION; - ++column; - p1 = p + 1; - p = strchr(p1, '\t'); - } + p1 = data->menu.items[i].str; + p = strchr(data->menu.items[i].str, '\t'); + column = 0; + for (;;) { + TCHAR wbuf[BUFSZ]; + RECT tabRect; + SetRect(&tabRect, 0, 0, 1, 1); + if (p != NULL) + *p = '\0'; /* for time being, view tab field as + zstring */ + DrawText(hdc, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), + &tabRect, DT_CALCRECT | DT_LEFT | DT_VCENTER + | DT_SINGLELINE); + /* it probably isn't necessary to recompute the tab width + * now, but do so + * just in case, honoring the previously computed value + */ + menuitemwidth += max(data->menu.tab_stop_size[column], + tabRect.right - tabRect.left); + if (p != NULL) + *p = '\t'; + else /* last string so, */ + break; + /* add the separation only when not the last item */ + /* in the last item, we break out of the loop, in the + * statement just above */ + menuitemwidth += TAB_SEPARATION; + ++column; + p1 = p + 1; + p = strchr(p1, '\t'); + } - sz->cx = max(sz->cx, - (LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang)); - } - SelectObject(hdc, saveFont); - } else { - /* do not change size for text output - the text will be formatted to - fit any window */ - } - sz->cx += extra_cx; + sz->cx = max(sz->cx, (LONG)(2 * TILE_X + menuitemwidth + + tm.tmAveCharWidth * 12 + + tm.tmOverhang)); + } + SelectObject(hdc, saveFont); + } else { + /* do not change size for text output - the text will be formatted + to + fit any window */ + } + sz->cx += extra_cx; - ReleaseDC(control, hdc); - } + ReleaseDC(control, hdc); + } } -void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count) +void +SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count) { - int i; + int i; - if( item<0 || item>=data->menu.size ) return; + if (item < 0 || item >= data->menu.size) + return; - if( data->how==PICK_ONE && count!=0 ) { - for(i=0; imenu.size; i++) - if( item!=i && data->menu.items[i].count!=0 ) { - data->menu.items[i].count = 0; - ListView_RedrawItems( hwndList, i, i ); - }; - } + if (data->how == PICK_ONE && count != 0) { + for (i = 0; i < data->menu.size; i++) + if (item != i && data->menu.items[i].count != 0) { + data->menu.items[i].count = 0; + ListView_RedrawItems(hwndList, i, i); + }; + } - data->menu.items[item].count = count; - ListView_RedrawItems( hwndList, item, item ); - reset_menu_count(hwndList, data); + data->menu.items[item].count = count; + ListView_RedrawItems(hwndList, item, item); + reset_menu_count(hwndList, data); } -void reset_menu_count(HWND hwndList, PNHMenuWindow data) +void +reset_menu_count(HWND hwndList, PNHMenuWindow data) { - int i; - data->menu.counting = FALSE; - if( IsWindow(hwndList) ) { - i = ListView_GetNextItem((hwndList), -1, LVNI_FOCUSED); - if( i>=0 ) ListView_RedrawItems( hwndList, i, i ); - } + int i; + data->menu.counting = FALSE; + if (IsWindow(hwndList)) { + i = ListView_GetNextItem((hwndList), -1, LVNI_FOCUSED); + if (i >= 0) + ListView_RedrawItems(hwndList, i, i); + } } /* List window Proc */ -LRESULT CALLBACK NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - BOOL bUpdateFocusItem = FALSE; + BOOL bUpdateFocusItem = FALSE; - switch(message) { - - /* filter keyboard input for the control */ + switch (message) { +/* filter keyboard input for the control */ #if !defined(WIN_CE_SMARTPHONE) - case WM_KEYDOWN: - case WM_KEYUP: { - MSG msg; + case WM_KEYDOWN: + case WM_KEYUP: { + MSG msg; - if( PeekMessage(&msg, hWnd, WM_CHAR, WM_CHAR, PM_REMOVE) ) { - if( onListChar(GetParent(hWnd), hWnd, (char)msg.wParam)==-2 ) { - return 0; - } - } + if (PeekMessage(&msg, hWnd, WM_CHAR, WM_CHAR, PM_REMOVE)) { + if (onListChar(GetParent(hWnd), hWnd, (char) msg.wParam) == -2) { + return 0; + } + } - if( wParam==VK_LEFT || wParam==VK_RIGHT ) - bUpdateFocusItem = TRUE; - } break; + if (wParam == VK_LEFT || wParam == VK_RIGHT) + bUpdateFocusItem = TRUE; + } break; + + /* tell Windows not to process arrow keys */ + case WM_GETDLGCODE: + return DLGC_WANTARROWS; - /* tell Windows not to process arrow keys */ - case WM_GETDLGCODE: - return DLGC_WANTARROWS; - #else /* defined(WIN_CE_SMARTPHONE) */ - case WM_KEYDOWN: - if( wParam==VK_TACTION ) { - if( onListChar(GetParent(hWnd), hWnd, ' ')==-2 ) { - return 0; - } - } else if( NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE) ) { - PMSNHEvent evt; - BOOL processed = FALSE; - if( mswin_have_input() ) { - evt = mswin_input_pop(); - if( evt->type==NHEVENT_CHAR && - onListChar(GetParent(hWnd), hWnd, evt->kbd.ch)==-2 ) { - processed = TRUE; - } + case WM_KEYDOWN: + if (wParam == VK_TACTION) { + if (onListChar(GetParent(hWnd), hWnd, ' ') == -2) { + return 0; + } + } else if (NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE)) { + PMSNHEvent evt; + BOOL processed = FALSE; + if (mswin_have_input()) { + evt = mswin_input_pop(); + if (evt->type == NHEVENT_CHAR + && onListChar(GetParent(hWnd), hWnd, evt->kbd.ch) == -2) { + processed = TRUE; + } - /* eat the rest of the events */ - if( mswin_have_input() ) mswin_input_pop(); - } - if( processed ) return 0; - } + /* eat the rest of the events */ + if (mswin_have_input()) + mswin_input_pop(); + } + if (processed) + return 0; + } - if( wParam==VK_LEFT || wParam==VK_RIGHT ) - bUpdateFocusItem = TRUE; - break; + if (wParam == VK_LEFT || wParam == VK_RIGHT) + bUpdateFocusItem = TRUE; + break; - case WM_KEYUP: - /* translate SmartPhone keyboard message */ - if( NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE) ) - return 0; - break; + case WM_KEYUP: + /* translate SmartPhone keyboard message */ + if (NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE)) + return 0; + break; - /* tell Windows not to process default button on VK_RETURN */ - case WM_GETDLGCODE: - return DLGC_DEFPUSHBUTTON | DLGC_WANTALLKEYS | - (wndProcListViewOrig? - CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, lParam) - : 0 ); + /* tell Windows not to process default button on VK_RETURN */ + case WM_GETDLGCODE: + return DLGC_DEFPUSHBUTTON | DLGC_WANTALLKEYS + | (wndProcListViewOrig + ? CallWindowProc(wndProcListViewOrig, hWnd, message, + wParam, lParam) + : 0); #endif - case WM_SIZE: - case WM_HSCROLL: - bUpdateFocusItem = TRUE; - break; + case WM_SIZE: + case WM_HSCROLL: + bUpdateFocusItem = TRUE; + break; + } - } + if (bUpdateFocusItem) { + int i; + RECT rt; - if( bUpdateFocusItem ) { - int i; - RECT rt; + /* invalidate the focus rectangle */ + i = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); + if (i != -1) { + ListView_GetItemRect(hWnd, i, &rt, LVIR_BOUNDS); + InvalidateRect(hWnd, &rt, TRUE); + } + } - /* invalidate the focus rectangle */ - i = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); - if( i!=-1 ) { - ListView_GetItemRect(hWnd, i, &rt, LVIR_BOUNDS); - InvalidateRect(hWnd, &rt, TRUE); - } - } - - if( wndProcListViewOrig ) - return CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, lParam); - else - return 0; + if (wndProcListViewOrig) + return CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, + lParam); + else + return 0; } /* Text control window proc - implements close on space */ -LRESULT CALLBACK NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_KEYUP: - switch( wParam ) { - case VK_SPACE: - case VK_RETURN: - /* close on space */ - PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); - return 0; - - case VK_UP: - /* scoll up */ - PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); - return 0; + switch (message) { + case WM_KEYUP: + switch (wParam) { + case VK_SPACE: + case VK_RETURN: + /* close on space */ + PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); + return 0; - case VK_DOWN: - /* scoll down */ - PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM)NULL); - return 0; + case VK_UP: + /* scoll up */ + PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), + (LPARAM) NULL); + return 0; - case VK_LEFT: - /* scoll left */ - PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), (LPARAM)NULL); - return 0; + case VK_DOWN: + /* scoll down */ + PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), + (LPARAM) NULL); + return 0; - case VK_RIGHT: - /* scoll right */ - PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0), (LPARAM)NULL); - return 0; - } - break; /* case WM_KEYUP: */ - } + case VK_LEFT: + /* scoll left */ + PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), + (LPARAM) NULL); + return 0; - if( editControlWndProc ) - return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam); - else - return 0; + case VK_RIGHT: + /* scoll right */ + PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0), + (LPARAM) NULL); + return 0; + } + break; /* case WM_KEYUP: */ + } + + if (editControlWndProc) + return CallWindowProc(editControlWndProc, hWnd, message, wParam, + lParam); + else + return 0; } /*----------------------------------------------------------------------------*/ -char* parse_menu_str(char* dest, const char* src, size_t size) +char * +parse_menu_str(char *dest, const char *src, size_t size) { - char *p1, *p2; - if( !dest || size==0 ) return NULL; + char *p1, *p2; + if (!dest || size == 0) + return NULL; - strncpy(dest, src, size); - dest[size-1] = '\x0'; + strncpy(dest, src, size); + dest[size - 1] = '\x0'; - /* replace "[ ]*\[" with "\t\[" */ - p1 = p2 = strstr(dest, " ["); - if( p1 ) { - while( p1!=dest && *p1==' ') p1--; - p1++; /* backup to space */ - *p2 = '\t'; - memmove(p1, p2, strlen(p2)); - p1[strlen(p2)] = '\x0'; - } - return dest; + /* replace "[ ]*\[" with "\t\[" */ + p1 = p2 = strstr(dest, " ["); + if (p1) { + while (p1 != dest && *p1 == ' ') + p1--; + p1++; /* backup to space */ + *p2 = '\t'; + memmove(p1, p2, strlen(p2)); + p1[strlen(p2)] = '\x0'; + } + return dest; } diff --git a/sys/wince/mhmsgwnd.c b/sys/wince/mhmsgwnd.c index 648b2e343..09a671a12 100644 --- a/sys/wince/mhmsgwnd.c +++ b/sys/wince/mhmsgwnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhmsgwnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhmsgwnd.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.19 $ */ /* NetHack 3.6 mhmsgwnd.c $Date: 2009/10/13 01:55:12 $ $Revision: 1.7 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,36 +10,36 @@ #include "mhfont.h" #include "mhcolor.h" -#define MSG_WRAP_TEXT +#define MSG_WRAP_TEXT -#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 2) -#define MAX_MSG_LINES 32 -#define MSG_LINES (int)min(iflags.msg_history, MAX_MSG_LINES) -#define MAXWINDOWTEXT 200 +#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 2) +#define MAX_MSG_LINES 32 +#define MSG_LINES (int) min(iflags.msg_history, MAX_MSG_LINES) +#define MAXWINDOWTEXT 200 struct window_line { - int attr; - char text[MAXWINDOWTEXT]; + int attr; + char text[MAXWINDOWTEXT]; }; typedef struct mswin_nethack_message_window { - size_t max_text; - struct window_line window_text[MAX_MSG_LINES]; + size_t max_text; + struct window_line window_text[MAX_MSG_LINES]; - int xChar; /* horizontal scrolling unit */ - int yChar; /* vertical scrolling unit */ - int xUpper; /* average width of uppercase letters */ - int xPos; /* current horizontal scrolling position */ - int yPos; /* current vertical scrolling position */ - int xMax; /* maximum horizontal scrolling position */ - int yMax; /* maximum vertical scrolling position */ - int xPage; /* page size of horizontal scroll bar */ - int lines_last_turn; /* lines added during the last turn */ - int dont_care; /* flag the the user does not care if messages are lost */ - } NHMessageWindow, *PNHMessageWindow; + int xChar; /* horizontal scrolling unit */ + int yChar; /* vertical scrolling unit */ + int xUpper; /* average width of uppercase letters */ + int xPos; /* current horizontal scrolling position */ + int yPos; /* current vertical scrolling position */ + int xMax; /* maximum horizontal scrolling position */ + int yMax; /* maximum vertical scrolling position */ + int xPage; /* page size of horizontal scroll bar */ + int lines_last_turn; /* lines added during the last turn */ + int dont_care; /* flag the the user does not care if messages are lost */ +} NHMessageWindow, *PNHMessageWindow; static TCHAR szMessageWindowClass[] = TEXT("MSNHMessageWndClass"); -LRESULT CALLBACK NHMessageWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMessageWndProc(HWND, UINT, WPARAM, LPARAM); static void register_message_window_class(); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -51,552 +51,570 @@ static void onPaint(HWND hWnd); static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); #ifdef USER_SOUNDS -extern void play_sound_for_message(const char* str); +extern void play_sound_for_message(const char *str); #endif -HWND mswin_init_message_window () { - static int run_once = 0; - HWND ret; - DWORD style; - - if( !run_once ) { - register_message_window_class( ); - run_once = 1; - } - -#ifdef MSG_WRAP_TEXT - style = WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL; -#else - style = WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL; -#endif - - ret = CreateWindow( - szMessageWindowClass, /* registered class name */ - NULL, /* window name */ - style, /* window style */ - 0, /* horizontal position of window */ - 0, /* vertical position of window */ - 0, /* window width */ - 0, /* window height - set it later */ - GetNHApp()->hMainWnd, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL ); /* window-creation data */ - - if( !ret ) panic("Cannot create message window"); - - return ret; -} - -void register_message_window_class() +HWND +mswin_init_message_window() { - WNDCLASS wcex; - ZeroMemory( &wcex, sizeof(wcex)); - - wcex.style = CS_NOCLOSE; - wcex.lpfnWndProc = (WNDPROC)NHMessageWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = mswin_get_brush(NHW_MESSAGE, MSWIN_COLOR_BG); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szMessageWindowClass; - - RegisterClass(&wcex); -} - -LRESULT CALLBACK NHMessageWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_CREATE: - onCreate( hWnd, wParam, lParam ); - break; - - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; - - case WM_PAINT: - onPaint(hWnd); - break; - - case WM_SETFOCUS: - SetFocus(GetNHApp()->hMainWnd); - break; - -#ifndef MSG_WRAP_TEXT - case WM_HSCROLL: - onMSNH_HScroll(hWnd, wParam, lParam); - break; -#endif - - case WM_VSCROLL: - onMSNH_VScroll(hWnd, wParam, lParam); - break; - - case WM_DESTROY: - { - PNHMessageWindow data; - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - } break; - - case WM_SIZE: - { - SCROLLINFO si; - int xNewSize; - int yNewSize; - PNHMessageWindow data; - - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - - xNewSize = LOWORD(lParam); - yNewSize = HIWORD(lParam); - - if( xNewSize>0 || yNewSize>0 ) { - -#ifndef MSG_WRAP_TEXT - data->xPage = xNewSize/data->xChar; - data->xMax = max(0, (int)(1 + data->max_text - data->xPage)); - data->xPos = min(data->xPos, data->xMax); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = data->max_text; - si.nPage = data->xPage; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); -#endif - - data->yMax = MSG_LINES-1; - data->yPos = min(data->yPos, data->yMax); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = MSG_VISIBLE_LINES; - si.nMax = data->yMax + MSG_VISIBLE_LINES - 1; - si.nPage = MSG_VISIBLE_LINES; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - } - } - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} - -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: - { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - SCROLLINFO si; - char* p; - - if( msg_data->append ) { - strncat(data->window_text[MSG_LINES-1].text, msg_data->text, - MAXWINDOWTEXT - strlen(data->window_text[MSG_LINES-1].text)); - } else { - /* check if the string is empty */ - for(p = data->window_text[MSG_LINES-1].text; *p && isspace(*p); p++); - - if( *p ) { - /* last string is not empty - scroll up */ - memmove(&data->window_text[0], - &data->window_text[1], - (MSG_LINES-1)*sizeof(data->window_text[0])); - } - - /* append new text to the end of the array */ - data->window_text[MSG_LINES-1].attr = msg_data->attr; - strncpy(data->window_text[MSG_LINES-1].text, msg_data->text, MAXWINDOWTEXT); - } - - /* reset V-scroll position to display new text */ - data->yPos = data->yMax; - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - - /* deal with overflows */ - data->lines_last_turn++; - if( !data->dont_care && data->lines_last_turn>=MSG_LINES-2 ) { - char c; - BOOL done; - - /* append "--More--" to the message window text (cannot call putstr - here - infinite recursion) */ - memmove(&data->window_text[0], - &data->window_text[1], - (MSG_LINES-1)*sizeof(data->window_text[0])); - data->window_text[MSG_LINES-1].attr = ATR_NONE; - strncpy(data->window_text[MSG_LINES-1].text, "--More--", MAXWINDOWTEXT); - - /* update window content */ - InvalidateRect(hWnd, NULL, TRUE); - -#if defined(WIN_CE_SMARTPHONE) - NHSPhoneSetKeypadFromString( "\033- <>" ); -#endif - - done = FALSE; - while( !done ) { - int x, y, mod; - c = mswin_nh_poskey(&x, &y, &mod); - switch (c) { - /* ESC indicates that we can safely discard any further messages during this turn */ - case '\033': - data->dont_care = 1; - done = TRUE; - break; - - case '<': - SendMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); - break; - - case '>': - SendMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM)NULL); - break; - - /* continue scrolling on any key */ - default: - data->lines_last_turn = 0; - done = TRUE; - break; - } - } - -#if defined(WIN_CE_SMARTPHONE) - NHSPhoneSetKeypadDefault(); -#endif - /* remove "--More--" from the message window text */ - data->window_text[MSG_LINES-1].attr = ATR_NONE; - strncpy(data->window_text[MSG_LINES-1].text, " ", MAXWINDOWTEXT); - } - - /* update window content */ - InvalidateRect(hWnd, NULL, TRUE); - -#ifdef USER_SOUNDS - play_sound_for_message(msg_data->text); -#endif - } - break; - - case MSNH_MSG_CLEAR_WINDOW: - data->lines_last_turn = 0; - data->dont_care = 0; - break; - } -} - -void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - SCROLLINFO si; - int yInc; - - /* get window data */ - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE | SIF_POS; - GetScrollInfo(hWnd, SB_VERT, &si); - - switch(LOWORD (wParam)) - { - // User clicked the shaft above the scroll box. - - case SB_PAGEUP: - yInc = -(int)si.nPage; - break; - - // User clicked the shaft below the scroll box. - - case SB_PAGEDOWN: - yInc = si.nPage; - break; - - // User clicked the top arrow. - - case SB_LINEUP: - yInc = -1; - break; - - // User clicked the bottom arrow. - - case SB_LINEDOWN: - yInc = 1; - break; - - // User dragged the scroll box. - - case SB_THUMBTRACK: - yInc = HIWORD(wParam) - data->yPos; - break; - - default: - yInc = 0; - } - - // If applying the vertical scrolling increment does not - // take the scrolling position out of the scrolling range, - // increment the scrolling position, adjust the position - // of the scroll box, and update the window. UpdateWindow - // sends the WM_PAINT message. - - if (yInc = max( MSG_VISIBLE_LINES - data->yPos, - min(yInc, data->yMax - data->yPos))) - { - data->yPos += yInc; - /* ScrollWindowEx(hWnd, 0, -data->yChar * yInc, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); - */ - InvalidateRect(hWnd, NULL, TRUE); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - - UpdateWindow (hWnd); - } -} - -#ifndef MSG_WRAP_TEXT -void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - SCROLLINFO si; - int xInc; - - /* get window data */ - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE; - GetScrollInfo(hWnd, SB_HORZ, &si); - - switch(LOWORD (wParam)) - { - // User clicked shaft left of the scroll box. - - case SB_PAGEUP: - xInc = - (int)si.nPage; - break; - - // User clicked shaft right of the scroll box. - - case SB_PAGEDOWN: - xInc = si.nPage; - break; - - // User clicked the left arrow. - - case SB_LINEUP: - xInc = -1; - break; - - // User clicked the right arrow. - - case SB_LINEDOWN: - xInc = 1; - break; - - // User dragged the scroll box. - - case SB_THUMBTRACK: - xInc = HIWORD(wParam) - data->xPos; - break; - - default: - xInc = 0; + static int run_once = 0; + HWND ret; + DWORD style; + if (!run_once) { + register_message_window_class(); + run_once = 1; } - - // If applying the horizontal scrolling increment does not - // take the scrolling position out of the scrolling range, - // increment the scrolling position, adjust the position - // of the scroll box, and update the window. +#ifdef MSG_WRAP_TEXT + style = WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL; +#else + style = WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL; +#endif - if (xInc = max (-data->xPos, min (xInc, data->xMax - data->xPos))) - { - data->xPos += xInc; - ScrollWindowEx (hWnd, -data->xChar * xInc, 0, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + ret = CreateWindow( + szMessageWindowClass, /* registered class name */ + NULL, /* window name */ + style, /* window style */ + 0, /* horizontal position of window */ + 0, /* vertical position of window */ + 0, /* window width */ + 0, /* window height - set it later */ + GetNHApp()->hMainWnd, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL); /* window-creation data */ - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); - UpdateWindow (hWnd); - } + if (!ret) + panic("Cannot create message window"); + + return ret; +} + +void +register_message_window_class() +{ + WNDCLASS wcex; + ZeroMemory(&wcex, sizeof(wcex)); + + wcex.style = CS_NOCLOSE; + wcex.lpfnWndProc = (WNDPROC) NHMessageWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = mswin_get_brush(NHW_MESSAGE, MSWIN_COLOR_BG); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szMessageWindowClass; + + RegisterClass(&wcex); +} + +LRESULT CALLBACK +NHMessageWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_CREATE: + onCreate(hWnd, wParam, lParam); + break; + + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; + + case WM_PAINT: + onPaint(hWnd); + break; + + case WM_SETFOCUS: + SetFocus(GetNHApp()->hMainWnd); + break; + +#ifndef MSG_WRAP_TEXT + case WM_HSCROLL: + onMSNH_HScroll(hWnd, wParam, lParam); + break; +#endif + + case WM_VSCROLL: + onMSNH_VScroll(hWnd, wParam, lParam); + break; + + case WM_DESTROY: { + PNHMessageWindow data; + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + } break; + + case WM_SIZE: { + SCROLLINFO si; + int xNewSize; + int yNewSize; + PNHMessageWindow data; + + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + + xNewSize = LOWORD(lParam); + yNewSize = HIWORD(lParam); + + if (xNewSize > 0 || yNewSize > 0) { +#ifndef MSG_WRAP_TEXT + data->xPage = xNewSize / data->xChar; + data->xMax = max(0, (int) (1 + data->max_text - data->xPage)); + data->xPos = min(data->xPos, data->xMax); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = data->max_text; + si.nPage = data->xPage; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); +#endif + + data->yMax = MSG_LINES - 1; + data->yPos = min(data->yPos, data->yMax); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = MSG_VISIBLE_LINES; + si.nMax = data->yMax + MSG_VISIBLE_LINES - 1; + si.nPage = MSG_VISIBLE_LINES; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + } + } break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + SCROLLINFO si; + char *p; + + if (msg_data->append) { + strncat(data->window_text[MSG_LINES - 1].text, msg_data->text, + MAXWINDOWTEXT + - strlen(data->window_text[MSG_LINES - 1].text)); + } else { + /* check if the string is empty */ + for (p = data->window_text[MSG_LINES - 1].text; *p && isspace(*p); + p++) + ; + + if (*p) { + /* last string is not empty - scroll up */ + memmove(&data->window_text[0], &data->window_text[1], + (MSG_LINES - 1) * sizeof(data->window_text[0])); + } + + /* append new text to the end of the array */ + data->window_text[MSG_LINES - 1].attr = msg_data->attr; + strncpy(data->window_text[MSG_LINES - 1].text, msg_data->text, + MAXWINDOWTEXT); + } + + /* reset V-scroll position to display new text */ + data->yPos = data->yMax; + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + + /* deal with overflows */ + data->lines_last_turn++; + if (!data->dont_care && data->lines_last_turn >= MSG_LINES - 2) { + char c; + BOOL done; + + /* append "--More--" to the message window text (cannot call + putstr + here - infinite recursion) */ + memmove(&data->window_text[0], &data->window_text[1], + (MSG_LINES - 1) * sizeof(data->window_text[0])); + data->window_text[MSG_LINES - 1].attr = ATR_NONE; + strncpy(data->window_text[MSG_LINES - 1].text, "--More--", + MAXWINDOWTEXT); + + /* update window content */ + InvalidateRect(hWnd, NULL, TRUE); + +#if defined(WIN_CE_SMARTPHONE) + NHSPhoneSetKeypadFromString("\033- <>"); +#endif + + done = FALSE; + while (!done) { + int x, y, mod; + c = mswin_nh_poskey(&x, &y, &mod); + switch (c) { + /* ESC indicates that we can safely discard any further + * messages during this turn */ + case '\033': + data->dont_care = 1; + done = TRUE; + break; + + case '<': + SendMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), + (LPARAM) NULL); + break; + + case '>': + SendMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), + (LPARAM) NULL); + break; + + /* continue scrolling on any key */ + default: + data->lines_last_turn = 0; + done = TRUE; + break; + } + } + +#if defined(WIN_CE_SMARTPHONE) + NHSPhoneSetKeypadDefault(); +#endif + /* remove "--More--" from the message window text */ + data->window_text[MSG_LINES - 1].attr = ATR_NONE; + strncpy(data->window_text[MSG_LINES - 1].text, " ", + MAXWINDOWTEXT); + } + + /* update window content */ + InvalidateRect(hWnd, NULL, TRUE); + +#ifdef USER_SOUNDS + play_sound_for_message(msg_data->text); +#endif + } break; + + case MSNH_MSG_CLEAR_WINDOW: + data->lines_last_turn = 0; + data->dont_care = 0; + break; + } +} + +void +onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + SCROLLINFO si; + int yInc; + + /* get window data */ + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE | SIF_POS; + GetScrollInfo(hWnd, SB_VERT, &si); + + switch (LOWORD(wParam)) { + // User clicked the shaft above the scroll box. + + case SB_PAGEUP: + yInc = -(int) si.nPage; + break; + + // User clicked the shaft below the scroll box. + + case SB_PAGEDOWN: + yInc = si.nPage; + break; + + // User clicked the top arrow. + + case SB_LINEUP: + yInc = -1; + break; + + // User clicked the bottom arrow. + + case SB_LINEDOWN: + yInc = 1; + break; + + // User dragged the scroll box. + + case SB_THUMBTRACK: + yInc = HIWORD(wParam) - data->yPos; + break; + + default: + yInc = 0; + } + + // If applying the vertical scrolling increment does not + // take the scrolling position out of the scrolling range, + // increment the scrolling position, adjust the position + // of the scroll box, and update the window. UpdateWindow + // sends the WM_PAINT message. + + if (yInc = max(MSG_VISIBLE_LINES - data->yPos, + min(yInc, data->yMax - data->yPos))) { + data->yPos += yInc; + /* ScrollWindowEx(hWnd, 0, -data->yChar * yInc, + (CONST RECT *) NULL, (CONST RECT *) NULL, + (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + */ + InvalidateRect(hWnd, NULL, TRUE); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + + UpdateWindow(hWnd); + } +} + +#ifndef MSG_WRAP_TEXT +void +onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + SCROLLINFO si; + int xInc; + + /* get window data */ + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE; + GetScrollInfo(hWnd, SB_HORZ, &si); + + switch (LOWORD(wParam)) { + // User clicked shaft left of the scroll box. + + case SB_PAGEUP: + xInc = -(int) si.nPage; + break; + + // User clicked shaft right of the scroll box. + + case SB_PAGEDOWN: + xInc = si.nPage; + break; + + // User clicked the left arrow. + + case SB_LINEUP: + xInc = -1; + break; + + // User clicked the right arrow. + + case SB_LINEDOWN: + xInc = 1; + break; + + // User dragged the scroll box. + + case SB_THUMBTRACK: + xInc = HIWORD(wParam) - data->xPos; + break; + + default: + xInc = 0; + } + + // If applying the horizontal scrolling increment does not + // take the scrolling position out of the scrolling range, + // increment the scrolling position, adjust the position + // of the scroll box, and update the window. + + if (xInc = max(-data->xPos, min(xInc, data->xMax - data->xPos))) { + data->xPos += xInc; + ScrollWindowEx(hWnd, -data->xChar * xInc, 0, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + UpdateWindow(hWnd); + } } #endif // MSG_WRAP_TEXT -COLORREF setMsgTextColor(HDC hdc, int gray) +COLORREF +setMsgTextColor(HDC hdc, int gray) { COLORREF fg, color1, color2; if (gray) { - color1 = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_BG); - color2 = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_FG); - /* Make a "gray" color by taking the average of the individual R,G,B - components of two colors. Thanks to Jonathan del Strother */ - fg = RGB((GetRValue(color1)+GetRValue(color2))/2, - (GetGValue(color1)+GetGValue(color2))/2, - (GetBValue(color1)+GetBValue(color2))/2); + color1 = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_BG); + color2 = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_FG); + /* Make a "gray" color by taking the average of the individual R,G,B + components of two colors. Thanks to Jonathan del Strother */ + fg = RGB((GetRValue(color1) + GetRValue(color2)) / 2, + (GetGValue(color1) + GetGValue(color2)) / 2, + (GetBValue(color1) + GetBValue(color2)) / 2); } else { - fg = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_FG); + fg = mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_FG); } return SetTextColor(hdc, fg); } -void onPaint(HWND hWnd) +void +onPaint(HWND hWnd) { - PAINTSTRUCT ps; - HDC hdc; - PNHMessageWindow data; - RECT client_rt, draw_rt; - int FirstLine, LastLine; - int i, x, y; - HGDIOBJ oldFont; - TCHAR wbuf[MAXWINDOWTEXT+2]; - size_t wlen; - COLORREF OldBg, OldFg; + PAINTSTRUCT ps; + HDC hdc; + PNHMessageWindow data; + RECT client_rt, draw_rt; + int FirstLine, LastLine; + int i, x, y; + HGDIOBJ oldFont; + TCHAR wbuf[MAXWINDOWTEXT + 2]; + size_t wlen; + COLORREF OldBg, OldFg; - hdc = BeginPaint(hWnd, &ps); + hdc = BeginPaint(hWnd, &ps); - OldBg = SetBkColor(hdc, mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_BG)); - OldFg = setMsgTextColor(hdc, 0); + OldBg = SetBkColor(hdc, mswin_get_color(NHW_MESSAGE, MSWIN_COLOR_BG)); + OldFg = setMsgTextColor(hdc, 0); - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); - GetClientRect(hWnd, &client_rt); + GetClientRect(hWnd, &client_rt); - if( !IsRectEmpty(&ps.rcPaint) ) { - FirstLine = max (0, data->yPos - (client_rt.bottom - ps.rcPaint.top)/data->yChar + 1); - LastLine = min (MSG_LINES-1, data->yPos - (client_rt.bottom - ps.rcPaint.bottom)/data->yChar); - y = min( ps.rcPaint.bottom, client_rt.bottom - 2); - for (i=LastLine; i>=FirstLine; i--) { - if( i==MSG_LINES-1 ) { - x = data->xChar * (2 - data->xPos); - } else { - x = data->xChar * (4 - data->xPos); - } + if (!IsRectEmpty(&ps.rcPaint)) { + FirstLine = max( + 0, data->yPos - (client_rt.bottom - ps.rcPaint.top) / data->yChar + + 1); + LastLine = + min(MSG_LINES - 1, + data->yPos + - (client_rt.bottom - ps.rcPaint.bottom) / data->yChar); + y = min(ps.rcPaint.bottom, client_rt.bottom - 2); + for (i = LastLine; i >= FirstLine; i--) { + if (i == MSG_LINES - 1) { + x = data->xChar * (2 - data->xPos); + } else { + x = data->xChar * (4 - data->xPos); + } + if (strlen(data->window_text[i].text) > 0) { + /* convert to UNICODE */ + NH_A2W(data->window_text[i].text, wbuf, sizeof(wbuf)); + wlen = _tcslen(wbuf); - if( strlen(data->window_text[i].text)>0 ) { - /* convert to UNICODE */ - NH_A2W(data->window_text[i].text, wbuf, sizeof(wbuf)); - wlen = _tcslen(wbuf); + /* calculate text height */ + draw_rt.left = x; + draw_rt.right = client_rt.right; + draw_rt.top = y - data->yChar; + draw_rt.bottom = y; - /* calculate text height */ - draw_rt.left = x; - draw_rt.right = client_rt.right; - draw_rt.top = y - data->yChar; - draw_rt.bottom = y; + oldFont = SelectObject( + hdc, + mswin_get_font(NHW_MESSAGE, data->window_text[i].attr, + hdc, FALSE)); - oldFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, data->window_text[i].attr, hdc, FALSE)); - - setMsgTextColor(hdc, i < (MSG_LINES - data->lines_last_turn)); -#ifdef MSG_WRAP_TEXT - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); - draw_rt.top = y - (draw_rt.bottom - draw_rt.top); - draw_rt.bottom = y; - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK); + setMsgTextColor(hdc, i < (MSG_LINES - data->lines_last_turn)); +#ifdef MSG_WRAP_TEXT + DrawText(hdc, wbuf, wlen, &draw_rt, + DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); + draw_rt.top = y - (draw_rt.bottom - draw_rt.top); + draw_rt.bottom = y; + DrawText(hdc, wbuf, wlen, &draw_rt, + DT_NOPREFIX | DT_WORDBREAK); #else - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX ); + DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX); #endif - SelectObject(hdc, oldFont); + SelectObject(hdc, oldFont); - y -= draw_rt.bottom - draw_rt.top; - } else { - y -= data->yChar; - } - } - } + y -= draw_rt.bottom - draw_rt.top; + } else { + y -= data->yChar; + } + } + } - SetTextColor (hdc, OldFg); - SetBkColor (hdc, OldBg); - EndPaint(hWnd, &ps); + SetTextColor(hdc, OldFg); + SetBkColor(hdc, OldBg); + EndPaint(hWnd, &ps); } -void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - HDC hdc; - TEXTMETRIC tm; - PNHMessageWindow data; - HGDIOBJ saveFont; + HDC hdc; + TEXTMETRIC tm; + PNHMessageWindow data; + HGDIOBJ saveFont; - /* set window data */ - data = (PNHMessageWindow)malloc(sizeof(NHMessageWindow)); - if( !data ) panic("out of memory"); - ZeroMemory(data, sizeof(NHMessageWindow)); - data->max_text = MAXWINDOWTEXT; - SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + /* set window data */ + data = (PNHMessageWindow) malloc(sizeof(NHMessageWindow)); + if (!data) + panic("out of memory"); + ZeroMemory(data, sizeof(NHMessageWindow)); + data->max_text = MAXWINDOWTEXT; + SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); /* Get the handle to the client area's device context. */ - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); + hdc = GetDC(hWnd); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); /* Extract font dimensions from the text metrics. */ - GetTextMetrics (hdc, &tm); - data->xChar = tm.tmAveCharWidth; - data->xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * data->xChar/2; - data->yChar = tm.tmHeight + tm.tmExternalLeading; - data->xPage = 1; + GetTextMetrics(hdc, &tm); + data->xChar = tm.tmAveCharWidth; + data->xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * data->xChar / 2; + data->yChar = tm.tmHeight + tm.tmExternalLeading; + data->xPage = 1; /* Free the device context. */ - SelectObject(hdc, saveFont); - ReleaseDC (hWnd, hdc); + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); - /* create command pad (keyboard emulator) */ - if( !GetNHApp()->hCmdWnd ) - GetNHApp()->hCmdWnd = mswin_init_command_window(); + /* create command pad (keyboard emulator) */ + if (!GetNHApp()->hCmdWnd) + GetNHApp()->hCmdWnd = mswin_init_command_window(); } -void mswin_message_window_size (HWND hWnd, LPSIZE sz) +void +mswin_message_window_size(HWND hWnd, LPSIZE sz) { - PNHMessageWindow data; - RECT rt, client_rt; + PNHMessageWindow data; + RECT rt, client_rt; - GetWindowRect(hWnd, &rt); + GetWindowRect(hWnd, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - if(data) { - /* set size to accomodate MSG_VISIBLE_LINES, highligh rectangle and - horizontal scroll bar (difference between window rect and client rect */ - GetClientRect(hWnd, &client_rt); - sz->cy = sz->cy-(client_rt.bottom - client_rt.top) + - data->yChar * MSG_VISIBLE_LINES + 4; - } + data = (PNHMessageWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data) { + /* set size to accomodate MSG_VISIBLE_LINES, highligh rectangle and + horizontal scroll bar (difference between window rect and client + rect */ + GetClientRect(hWnd, &client_rt); + sz->cy = sz->cy - (client_rt.bottom - client_rt.top) + + data->yChar * MSG_VISIBLE_LINES + 4; + } } - diff --git a/sys/wince/mhrip.c b/sys/wince/mhrip.c index 304bfef33..33cd6cd60 100644 --- a/sys/wince/mhrip.c +++ b/sys/wince/mhrip.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhrip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhrip.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 mhrip.c $Date: 2009/05/06 10:52:26 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)mhrip.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -8,13 +8,14 @@ #include "mhrip.h" #include "mhtext.h" -HWND mswin_init_RIP_window () +HWND +mswin_init_RIP_window() { - return mswin_init_text_window(); + return mswin_init_text_window(); } -void mswin_display_RIP_window (HWND hWnd) +void +mswin_display_RIP_window(HWND hWnd) { - mswin_display_text_window(hWnd); + mswin_display_text_window(hWnd); } - diff --git a/sys/wince/mhstatus.c b/sys/wince/mhstatus.c index 11fca8c7e..adea818c7 100644 --- a/sys/wince/mhstatus.c +++ b/sys/wince/mhstatus.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhstatus.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ +/* NetHack 3.6 mhstatus.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ /* NetHack 3.6 mhstatus.c $Date: 2009/05/06 10:52:28 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)mhstatus.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -12,259 +12,271 @@ #define MAXWINDOWTEXT 255 -#define NHSTAT_LINES_2 2 -#define NHSTAT_LINES_4 4 +#define NHSTAT_LINES_2 2 +#define NHSTAT_LINES_4 4 typedef struct mswin_nethack_status_window { - int nhstat_format; - char window_text[MAXWINDOWTEXT]; + int nhstat_format; + char window_text[MAXWINDOWTEXT]; } NHStatusWindow, *PNHStatusWindow; static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass"); -LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM); static void register_status_window_class(void); -static void FormatStatusString(char* text, int format); +static void FormatStatusString(char *text, int format); -HWND mswin_init_status_window () { - static int run_once = 0; - HWND ret; - NHStatusWindow* data; - - if( !run_once ) { - register_status_window_class( ); - run_once = 1; - } - - ret = CreateWindow( - szStatusWindowClass, - NULL, - WS_CHILD | WS_DISABLED | WS_CLIPSIBLINGS, - 0, /* x position */ - 0, /* y position */ - 0, /* x-size - we will set it later */ - 0, /* y-size - we will set it later */ - GetNHApp()->hMainWnd, - NULL, - GetNHApp()->hApp, - NULL ); - if( !ret ) panic("Cannot create status window"); - - EnableWindow(ret, FALSE); - - data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow)); - if( !data ) panic("out of memory"); - - ZeroMemory(data, sizeof(NHStatusWindow)); - data->nhstat_format = NHSTAT_LINES_4; - SetWindowLong(ret, GWL_USERDATA, (LONG)data); - return ret; -} - -void register_status_window_class() +HWND +mswin_init_status_window() { - WNDCLASS wcex; - - ZeroMemory( &wcex, sizeof(wcex)); - wcex.style = CS_NOCLOSE; - wcex.lpfnWndProc = (WNDPROC)StatusWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = mswin_get_brush(NHW_STATUS, MSWIN_COLOR_BG); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szStatusWindowClass; + static int run_once = 0; + HWND ret; + NHStatusWindow *data; - RegisterClass(&wcex); + if (!run_once) { + register_status_window_class(); + run_once = 1; + } + + ret = CreateWindow(szStatusWindowClass, NULL, + WS_CHILD | WS_DISABLED | WS_CLIPSIBLINGS, + 0, /* x position */ + 0, /* y position */ + 0, /* x-size - we will set it later */ + 0, /* y-size - we will set it later */ + GetNHApp()->hMainWnd, NULL, GetNHApp()->hApp, NULL); + if (!ret) + panic("Cannot create status window"); + + EnableWindow(ret, FALSE); + + data = (PNHStatusWindow) malloc(sizeof(NHStatusWindow)); + if (!data) + panic("out of memory"); + + ZeroMemory(data, sizeof(NHStatusWindow)); + data->nhstat_format = NHSTAT_LINES_4; + SetWindowLong(ret, GWL_USERDATA, (LONG) data); + return ret; } - - -LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +void +register_status_window_class() { - RECT rt; - PAINTSTRUCT ps; - HDC hdc; - PNHStatusWindow data; - - data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch (message) - { - case WM_MSNH_COMMAND: { - switch( wParam ) { - - case MSNH_MSG_PUTSTR: - case MSNH_MSG_CLEAR_WINDOW: - ZeroMemory(data->window_text, sizeof(data->window_text)); - FormatStatusString(data->window_text, data->nhstat_format); - break; + WNDCLASS wcex; - case MSNH_MSG_CURSOR: { - PMSNHMsgCursor msg_data = (PMSNHMsgCursor)lParam; - if( msg_data->y==0 ) { - InvalidateRect(hWnd, NULL, TRUE); - } - } break; - } - } break; + ZeroMemory(&wcex, sizeof(wcex)); + wcex.style = CS_NOCLOSE; + wcex.lpfnWndProc = (WNDPROC) StatusWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = mswin_get_brush(NHW_STATUS, MSWIN_COLOR_BG); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szStatusWindowClass; - case WM_PAINT: { - HGDIOBJ oldFont; - TCHAR wbuf[MAXWINDOWTEXT]; - COLORREF OldBg, OldFg; - - hdc = BeginPaint(hWnd, &ps); - GetClientRect(hWnd, &rt); - - oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); - OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG)); - OldFg = SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG)); - - DrawText(hdc, - NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT), - strlen(data->window_text), - &rt, - DT_LEFT | DT_NOPREFIX); - - SetTextColor (hdc, OldFg); - SetBkColor (hdc, OldBg); - SelectObject(hdc, oldFont); - EndPaint(hWnd, &ps); - } break; - - case WM_DESTROY: - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - break; - - case WM_SETFOCUS: - SetFocus(GetNHApp()->hMainWnd); - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + RegisterClass(&wcex); } -void mswin_status_window_size (HWND hWnd, LPSIZE sz) +LRESULT CALLBACK +StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT rt; + PAINTSTRUCT ps; + HDC hdc; + PNHStatusWindow data; + + data = (PNHStatusWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (message) { + case WM_MSNH_COMMAND: { + switch (wParam) { + case MSNH_MSG_PUTSTR: + case MSNH_MSG_CLEAR_WINDOW: + ZeroMemory(data->window_text, sizeof(data->window_text)); + FormatStatusString(data->window_text, data->nhstat_format); + break; + + case MSNH_MSG_CURSOR: { + PMSNHMsgCursor msg_data = (PMSNHMsgCursor) lParam; + if (msg_data->y == 0) { + InvalidateRect(hWnd, NULL, TRUE); + } + } break; + } + } break; + + case WM_PAINT: { + HGDIOBJ oldFont; + TCHAR wbuf[MAXWINDOWTEXT]; + COLORREF OldBg, OldFg; + + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rt); + + oldFont = SelectObject( + hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); + OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG)); + OldFg = + SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG)); + + DrawText(hdc, NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT), + strlen(data->window_text), &rt, DT_LEFT | DT_NOPREFIX); + + SetTextColor(hdc, OldFg); + SetBkColor(hdc, OldBg); + SelectObject(hdc, oldFont); + EndPaint(hWnd, &ps); + } break; + + case WM_DESTROY: + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + break; + + case WM_SETFOCUS: + SetFocus(GetNHApp()->hMainWnd); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +void +mswin_status_window_size(HWND hWnd, LPSIZE sz) { TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC hdc; - PNHStatusWindow data; - RECT rt; - GetWindowRect(hWnd, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + HGDIOBJ saveFont; + HDC hdc; + PNHStatusWindow data; + RECT rt; + GetWindowRect(hWnd, &rt); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; - data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA); - if(data) { - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); - GetTextMetrics(hdc, &tm); + data = (PNHStatusWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data) { + hdc = GetDC(hWnd); + saveFont = SelectObject( + hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); - /* see if the status window can fit 80 characters per line */ - if( (80*tm.tmMaxCharWidth)>=sz->cx ) data->nhstat_format = NHSTAT_LINES_4; - else data->nhstat_format = NHSTAT_LINES_2; + /* see if the status window can fit 80 characters per line */ + if ((80 * tm.tmMaxCharWidth) >= sz->cx) + data->nhstat_format = NHSTAT_LINES_4; + else + data->nhstat_format = NHSTAT_LINES_2; - /* set height of the status box */ - sz->cy = tm.tmHeight * data->nhstat_format; + /* set height of the status box */ + sz->cy = tm.tmHeight * data->nhstat_format; - SelectObject(hdc, saveFont); - ReleaseDC(hWnd, hdc); - } + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); + } } -extern const char *hu_stat[]; /* defined in eat.c */ +extern const char *hu_stat[]; /* defined in eat.c */ extern const char *enc_stat[]; /* define in botl.c */ -void FormatStatusString(char* text, int format) +void +FormatStatusString(char *text, int format) { - register char *nb; - int hp, hpmax; - int cap = near_capacity(); + register char *nb; + int hp, hpmax; + int cap = near_capacity(); - Strcpy(text, plname); - if('a' <= text[0] && text[0] <= 'z') text[0] += 'A'-'a'; - text[10] = 0; - Sprintf(nb = eos(text)," the "); + Strcpy(text, plname); + if ('a' <= text[0] && text[0] <= 'z') + text[0] += 'A' - 'a'; + text[10] = 0; + Sprintf(nb = eos(text), " the "); - if (Upolyd) { - char mbot[BUFSZ]; - int k = 0; + if (Upolyd) { + char mbot[BUFSZ]; + int k = 0; - Strcpy(mbot, mons[u.umonnum].mname); - while(mbot[k] != 0) { - if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) && - 'a' <= mbot[k] && mbot[k] <= 'z') - mbot[k] += 'A' - 'a'; - k++; - } - Sprintf(nb = eos(nb), mbot); - } else - Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female)); + Strcpy(mbot, mons[u.umonnum].mname); + while (mbot[k] != 0) { + if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k] + && mbot[k] <= 'z') + mbot[k] += 'A' - 'a'; + k++; + } + Sprintf(nb = eos(nb), mbot); + } else + Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female)); - if( format==NHSTAT_LINES_4 ) Sprintf(nb = eos(nb),"\r\n"); + if (format == NHSTAT_LINES_4) + Sprintf(nb = eos(nb), "\r\n"); - if (ACURR(A_STR) > 18) { - if (ACURR(A_STR) > STR18(100)) - Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100); - else if (ACURR(A_STR) < STR18(100)) - Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18); - else - Sprintf(nb = eos(nb),"St:18/** "); - } else - Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR)); - Sprintf(nb = eos(nb), - "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", - ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA)); - Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? " Chaotic" : - (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful"); + if (ACURR(A_STR) > 18) { + if (ACURR(A_STR) > STR18(100)) + Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100); + else if (ACURR(A_STR) < STR18(100)) + Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18); + else + Sprintf(nb = eos(nb), "St:18/** "); + } else + Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR)); + Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", + ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), + ACURR(A_CHA)); + Sprintf(nb = eos(nb), + (u.ualign.type == A_CHAOTIC) + ? " Chaotic" + : (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful"); #ifdef SCORE_ON_BOTL - if (flags.showscore) - Sprintf(nb = eos(nb), " S:%ld", botl_score()); + if (flags.showscore) + Sprintf(nb = eos(nb), " S:%ld", botl_score()); #endif - if( format==NHSTAT_LINES_4 || - format==NHSTAT_LINES_2 ) strcat(text, "\r\n"); + if (format == NHSTAT_LINES_4 || format == NHSTAT_LINES_2) + strcat(text, "\r\n"); - /* third line */ - hp = Upolyd ? u.mh : u.uhp; - hpmax = Upolyd ? u.mhmax : u.uhpmax; + /* third line */ + hp = Upolyd ? u.mh : u.uhp; + hpmax = Upolyd ? u.mhmax : u.uhpmax; - if(hp < 0) hp = 0; - (void) describe_level(nb=eos(nb)); - Sprintf(nb = eos(nb), - "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", showsyms[COIN_CLASS + SYM_OFF_O], - money_cnt(invent), - hp, hpmax, u.uen, u.uenmax, u.uac); + if (hp < 0) + hp = 0; + (void) describe_level(nb = eos(nb)); + Sprintf(nb = eos(nb), "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", + showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(invent), hp, hpmax, + u.uen, u.uenmax, u.uac); - if (Upolyd) - Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel); - else if(flags.showexp) - Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp); - else - Sprintf(nb = eos(nb), " Exp:%u", u.ulevel); - if( format==NHSTAT_LINES_4 ) strcat(text, "\r\n"); - else strcat(text, " "); + if (Upolyd) + Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel); + else if (flags.showexp) + Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp); + else + Sprintf(nb = eos(nb), " Exp:%u", u.ulevel); + if (format == NHSTAT_LINES_4) + strcat(text, "\r\n"); + else + strcat(text, " "); - /* forth line */ - if(flags.time) - Sprintf(nb = eos(nb), "T:%ld ", moves); + /* forth line */ + if (flags.time) + Sprintf(nb = eos(nb), "T:%ld ", moves); - if(strcmp(hu_stat[u.uhs], " ")) { - Strcat(text, hu_stat[u.uhs]); - Sprintf(nb = eos(nb), " "); - } - if(Confusion) Sprintf(nb = eos(nb), "Conf"); - if(Sick) { - if (u.usick_type & SICK_VOMITABLE) - Sprintf(nb = eos(nb), " FoodPois"); - if (u.usick_type & SICK_NONVOMITABLE) - Sprintf(nb = eos(nb), " Ill"); - } - if(Blind) Sprintf(nb = eos(nb), " Blind"); - if(Stunned) Sprintf(nb = eos(nb), " Stun"); - if(Hallucination) Sprintf(nb = eos(nb), " Hallu"); - if(Slimed) Sprintf(nb = eos(nb), " Slime"); - if(cap > UNENCUMBERED) - Sprintf(nb = eos(nb), " %s", enc_stat[cap]); + if (strcmp(hu_stat[u.uhs], " ")) { + Strcat(text, hu_stat[u.uhs]); + Sprintf(nb = eos(nb), " "); + } + if (Confusion) + Sprintf(nb = eos(nb), "Conf"); + if (Sick) { + if (u.usick_type & SICK_VOMITABLE) + Sprintf(nb = eos(nb), " FoodPois"); + if (u.usick_type & SICK_NONVOMITABLE) + Sprintf(nb = eos(nb), " Ill"); + } + if (Blind) + Sprintf(nb = eos(nb), " Blind"); + if (Stunned) + Sprintf(nb = eos(nb), " Stun"); + if (Hallucination) + Sprintf(nb = eos(nb), " Hallu"); + if (Slimed) + Sprintf(nb = eos(nb), " Slime"); + if (cap > UNENCUMBERED) + Sprintf(nb = eos(nb), " %s", enc_stat[cap]); } - diff --git a/sys/wince/mhtext.c b/sys/wince/mhtext.c index 3db774412..c358c7ff4 100644 --- a/sys/wince/mhtext.c +++ b/sys/wince/mhtext.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhtext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhtext.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */ /* NetHack 3.6 mhtext.c $Date: 2009/10/22 02:59:34 $ $Revision: 1.8 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -11,292 +11,296 @@ #include "mhtxtbuf.h" typedef struct mswin_nethack_text_window { - PNHTextBuffer window_text; - int done; + PNHTextBuffer window_text; + int done; } NHTextWindow, *PNHTextWindow; static WNDPROC editControlWndProc = NULL; -LRESULT CALLBACK TextWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHTextControlWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK TextWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHTextControlWndProc(HWND, UINT, WPARAM, LPARAM); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void LayoutText(HWND hwnd); static void ToggleWrapStatus(HWND hDlg, BOOL bWrap); -HWND mswin_init_text_window () { - HWND ret; - PNHTextWindow data; +HWND +mswin_init_text_window() +{ + HWND ret; + PNHTextWindow data; - ret = CreateDialog( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_NHTEXT), - GetNHApp()->hMainWnd, - TextWndProc - ); - if( !ret ) panic("Cannot create text window"); + ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHTEXT), + GetNHApp()->hMainWnd, TextWndProc); + if (!ret) + panic("Cannot create text window"); - data = (PNHTextWindow)malloc(sizeof(NHTextWindow)); - if( !data ) panic("out of memory"); + data = (PNHTextWindow) malloc(sizeof(NHTextWindow)); + if (!data) + panic("out of memory"); - ZeroMemory(data, sizeof(NHTextWindow)); - data->window_text = mswin_init_text_buffer( - program_state.gameover? FALSE : GetNHApp()->bWrapText - ); - SetWindowLong(ret, GWL_USERDATA, (LONG)data); - return ret; + ZeroMemory(data, sizeof(NHTextWindow)); + data->window_text = mswin_init_text_buffer( + program_state.gameover ? FALSE : GetNHApp()->bWrapText); + SetWindowLong(ret, GWL_USERDATA, (LONG) data); + return ret; } -void mswin_display_text_window (HWND hWnd) +void +mswin_display_text_window(HWND hWnd) { - PNHTextWindow data; - - data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA); - if( data ) { - ToggleWrapStatus(hWnd, mswin_get_text_wrap(data->window_text)); - data->done = 0; - mswin_popup_display(hWnd, &data->done); - mswin_popup_destroy(hWnd); - } -} - -LRESULT CALLBACK TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND control; - HDC hdc; - PNHTextWindow data; - - data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch (message) - { - case WM_INITDIALOG: - /* set text control font */ - control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); - if( !control ) { - panic("cannot get text view window"); - } + PNHTextWindow data; - hdc = GetDC(control); - SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); - ReleaseDC(control, hdc); + data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA); + if (data) { + ToggleWrapStatus(hWnd, mswin_get_text_wrap(data->window_text)); + data->done = 0; + mswin_popup_display(hWnd, &data->done); + mswin_popup_destroy(hWnd); + } +} + +LRESULT CALLBACK +TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND control; + HDC hdc; + PNHTextWindow data; + + data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (message) { + case WM_INITDIALOG: + /* set text control font */ + control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); + if (!control) { + panic("cannot get text view window"); + } + + hdc = GetDC(control); + SendMessage(control, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), + 0); + ReleaseDC(control, hdc); #if defined(WIN_CE_SMARTPHONE) - /* special initialization for SmartPhone dialogs */ - NHSPhoneDialogSetup(hWnd, IDC_SPHONE_TEXTDIALOGBAR, FALSE, GetNHApp()->bFullScreen); + /* special initialization for SmartPhone dialogs */ + NHSPhoneDialogSetup(hWnd, IDC_SPHONE_TEXTDIALOGBAR, FALSE, + GetNHApp()->bFullScreen); #endif - /* subclass edit control */ - editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); - SetWindowLong(control, GWL_WNDPROC, (LONG)NHTextControlWndProc); + /* subclass edit control */ + editControlWndProc = (WNDPROC) GetWindowLong(control, GWL_WNDPROC); + SetWindowLong(control, GWL_WNDPROC, (LONG) NHTextControlWndProc); - SetFocus(control); - return FALSE; + SetFocus(control); + return FALSE; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SIZE: - LayoutText(hWnd); - return FALSE; + case WM_SIZE: + LayoutText(hWnd); + return FALSE; - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - case IDCANCEL: - data->done = 1; - return TRUE; - case IDC_TEXT_TOGGLE_WRAP: - ToggleWrapStatus(hWnd, !mswin_get_text_wrap(data->window_text)); - return TRUE; - } - break; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + case IDCANCEL: + data->done = 1; + return TRUE; + case IDC_TEXT_TOGGLE_WRAP: + ToggleWrapStatus(hWnd, !mswin_get_text_wrap(data->window_text)); + return TRUE; + } + break; - case WM_CTLCOLORBTN: - case WM_CTLCOLOREDIT: - case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ - HDC hdcEdit = (HDC) wParam; - HWND hwndEdit = (HWND) lParam; - if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) { - SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); - SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); - return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); - } - } return FALSE; + case WM_CTLCOLORBTN: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ + HDC hdcEdit = (HDC) wParam; + HWND hwndEdit = (HWND) lParam; + if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) { + SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); + SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); + return (BOOL) mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); + } + } + return FALSE; - case WM_DESTROY: - if( data ) { - mswin_free_text_buffer(data->window_text); - free(data); - SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); - } - break; - - } - return FALSE; + case WM_DESTROY: + if (data) { + mswin_free_text_buffer(data->window_text); + free(data); + SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); + } + break; + } + return FALSE; } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHTextWindow data; - - data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - mswin_add_text(data->window_text, msg_data->attr, msg_data->text); - break; - } - } + PNHTextWindow data; + + data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + mswin_add_text(data->window_text, msg_data->attr, msg_data->text); + break; + } + } } -void ToggleWrapStatus(HWND hDlg, BOOL bWrap) +void +ToggleWrapStatus(HWND hDlg, BOOL bWrap) { - DWORD styles; - PNHTextWindow data; - HWND control; - TCHAR wbuf[BUFSZ]; - - data = (PNHTextWindow)GetWindowLong(hDlg, GWL_USERDATA); + DWORD styles; + PNHTextWindow data; + HWND control; + TCHAR wbuf[BUFSZ]; - control = GetDlgItem(hDlg, IDC_TEXT_CONTROL); - if( !control ) { - panic("cannot get text view window"); - } + data = (PNHTextWindow) GetWindowLong(hDlg, GWL_USERDATA); - /* set horizontal scrollbar status */ - styles = GetWindowLong(control, GWL_STYLE); - if( styles ) { - SetWindowLong(control, GWL_STYLE, (bWrap? (styles & (~WS_HSCROLL)) : (styles | WS_HSCROLL))); - SetWindowPos(control, NULL, 0, 0, 0, 0, - SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE ); - } + control = GetDlgItem(hDlg, IDC_TEXT_CONTROL); + if (!control) { + panic("cannot get text view window"); + } - /* set text wrap mode */ - mswin_set_text_wrap(data->window_text, bWrap); - mswin_render_text(data->window_text, control); + /* set horizontal scrollbar status */ + styles = GetWindowLong(control, GWL_STYLE); + if (styles) { + SetWindowLong(control, GWL_STYLE, (bWrap ? (styles & (~WS_HSCROLL)) + : (styles | WS_HSCROLL))); + SetWindowPos(control, NULL, 0, 0, 0, 0, + SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE + | SWP_NOSIZE); + } - /* change button status */ - ZeroMemory( wbuf, sizeof(wbuf) ); - if( !LoadString( - GetNHApp()->hApp, - (bWrap? IDS_TEXT_UNWRAP : IDS_TEXT_WRAP), - wbuf, - BUFSZ) ) { - panic("cannot load text window strings"); - } + /* set text wrap mode */ + mswin_set_text_wrap(data->window_text, bWrap); + mswin_render_text(data->window_text, control); + + /* change button status */ + ZeroMemory(wbuf, sizeof(wbuf)); + if (!LoadString(GetNHApp()->hApp, + (bWrap ? IDS_TEXT_UNWRAP : IDS_TEXT_WRAP), wbuf, BUFSZ)) { + panic("cannot load text window strings"); + } #if defined(WIN_CE_SMARTPHONE) - { - TBBUTTONINFO tbbi; + { + TBBUTTONINFO tbbi; - ZeroMemory( &tbbi, sizeof(tbbi) ); - tbbi.cbSize = sizeof(tbbi); - tbbi.dwMask = TBIF_TEXT; - tbbi.pszText = wbuf; - if( !SendMessage( - SHFindMenuBar(hDlg), - TB_SETBUTTONINFO, - IDC_TEXT_TOGGLE_WRAP, - (LPARAM)&tbbi) ) { - error( "Cannot update IDC_TEXT_TOGGLE_WRAP menu item." ); - } - } + ZeroMemory(&tbbi, sizeof(tbbi)); + tbbi.cbSize = sizeof(tbbi); + tbbi.dwMask = TBIF_TEXT; + tbbi.pszText = wbuf; + if (!SendMessage(SHFindMenuBar(hDlg), TB_SETBUTTONINFO, + IDC_TEXT_TOGGLE_WRAP, (LPARAM) &tbbi)) { + error("Cannot update IDC_TEXT_TOGGLE_WRAP menu item."); + } + } #else - SendDlgItemMessage( - hDlg, - IDC_TEXT_TOGGLE_WRAP, - WM_SETTEXT, - (WPARAM)0, - (LPARAM)wbuf - ); + SendDlgItemMessage(hDlg, IDC_TEXT_TOGGLE_WRAP, WM_SETTEXT, (WPARAM) 0, + (LPARAM) wbuf); #endif } -void LayoutText(HWND hWnd) +void +LayoutText(HWND hWnd) { - HWND btn_ok, btn_wrap; - HWND text; - RECT clrt, rt; - POINT pt_elem, pt_ok, pt_wrap; - SIZE sz_elem, sz_ok, sz_wrap; + HWND btn_ok, btn_wrap; + HWND text; + RECT clrt, rt; + POINT pt_elem, pt_ok, pt_wrap; + SIZE sz_elem, sz_ok, sz_wrap; - text = GetDlgItem(hWnd, IDC_TEXT_CONTROL); - btn_ok = GetDlgItem(hWnd, IDOK); - btn_wrap = GetDlgItem(hWnd, IDC_TEXT_TOGGLE_WRAP); + text = GetDlgItem(hWnd, IDC_TEXT_CONTROL); + btn_ok = GetDlgItem(hWnd, IDOK); + btn_wrap = GetDlgItem(hWnd, IDC_TEXT_TOGGLE_WRAP); - /* get window coordinates */ - GetClientRect(hWnd, &clrt ); - - /* set window placements */ - if( IsWindow(btn_ok) ) { - GetWindowRect(btn_ok, &rt); - sz_ok.cx = (clrt.right - clrt.left)/2; - sz_ok.cy = rt.bottom-rt.top; - pt_ok.x = clrt.left; - pt_ok.y = clrt.bottom - sz_ok.cy; - MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE ); + /* get window coordinates */ + GetClientRect(hWnd, &clrt); - sz_wrap.cx = (clrt.right - clrt.left)/2; - sz_wrap.cy = rt.bottom-rt.top; - pt_wrap.x = clrt.left + sz_ok.cx; - pt_wrap.y = clrt.bottom - sz_ok.cy; - MoveWindow(btn_wrap, pt_wrap.x, pt_wrap.y, sz_wrap.cx, sz_wrap.cy, TRUE ); + /* set window placements */ + if (IsWindow(btn_ok)) { + GetWindowRect(btn_ok, &rt); + sz_ok.cx = (clrt.right - clrt.left) / 2; + sz_ok.cy = rt.bottom - rt.top; + pt_ok.x = clrt.left; + pt_ok.y = clrt.bottom - sz_ok.cy; + MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); - pt_elem.x = clrt.left; - pt_elem.y = clrt.top; - sz_elem.cx = clrt.right - clrt.left; - sz_elem.cy = pt_ok.y; - MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); - } else { - pt_elem.x = clrt.left; - pt_elem.y = clrt.top; - sz_elem.cx = clrt.right - clrt.left; - sz_elem.cy = clrt.bottom - clrt.top; - MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); - } + sz_wrap.cx = (clrt.right - clrt.left) / 2; + sz_wrap.cy = rt.bottom - rt.top; + pt_wrap.x = clrt.left + sz_ok.cx; + pt_wrap.y = clrt.bottom - sz_ok.cy; + MoveWindow(btn_wrap, pt_wrap.x, pt_wrap.y, sz_wrap.cx, sz_wrap.cy, + TRUE); + + pt_elem.x = clrt.left; + pt_elem.y = clrt.top; + sz_elem.cx = clrt.right - clrt.left; + sz_elem.cy = pt_ok.y; + MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE); + } else { + pt_elem.x = clrt.left; + pt_elem.y = clrt.top; + sz_elem.cx = clrt.right - clrt.left; + sz_elem.cy = clrt.bottom - clrt.top; + MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE); + } } -/* Text control window proc - implements close on space and scrolling on arrows */ -LRESULT CALLBACK NHTextControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +/* Text control window proc - implements close on space and scrolling on + * arrows */ +LRESULT CALLBACK +NHTextControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - /* tell Windows not to process arrow keys (we want them) */ - case WM_GETDLGCODE: - return DLGC_WANTARROWS; + switch (message) { + /* tell Windows not to process arrow keys (we want them) */ + case WM_GETDLGCODE: + return DLGC_WANTARROWS; - case WM_KEYDOWN: - switch( wParam ) { - case VK_SPACE: - case VK_RETURN: - /* close on space */ - PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); - return 0; - - case VK_UP: - /* scoll up */ - PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); - return 0; + case WM_KEYDOWN: + switch (wParam) { + case VK_SPACE: + case VK_RETURN: + /* close on space */ + PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); + return 0; - case VK_DOWN: - /* scoll down */ - PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM)NULL); - return 0; + case VK_UP: + /* scoll up */ + PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), + (LPARAM) NULL); + return 0; - case VK_LEFT: - /* scoll left */ - PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), (LPARAM)NULL); - return 0; + case VK_DOWN: + /* scoll down */ + PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), + (LPARAM) NULL); + return 0; - case VK_RIGHT: - /* scoll right */ - PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0), (LPARAM)NULL); - return 0; - } - break; /* case WM_KEYDOWN: */ - } + case VK_LEFT: + /* scoll left */ + PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), + (LPARAM) NULL); + return 0; - if( editControlWndProc ) - return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam); - else - return 0; + case VK_RIGHT: + /* scoll right */ + PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0), + (LPARAM) NULL); + return 0; + } + break; /* case WM_KEYDOWN: */ + } + + if (editControlWndProc) + return CallWindowProc(editControlWndProc, hWnd, message, wParam, + lParam); + else + return 0; } diff --git a/sys/wince/mhtxtbuf.c b/sys/wince/mhtxtbuf.c index ae2d0454d..e9eb02e15 100644 --- a/sys/wince/mhtxtbuf.c +++ b/sys/wince/mhtxtbuf.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhtxtbuf.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhtxtbuf.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 mhtxtbuf.c $Date: 2009/10/13 01:55:12 $ $Revision: 1.6 $ */ /* Copyright (C) 2003 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,7 +10,7 @@ Recognize formatted lines as having more that 4 consecutive. spaces inside the string. Strip leading and trailing spaces. - Always break at the original line end (do not merge text that comes + Always break at the original line end (do not merge text that comes from NetHack engine) */ @@ -18,235 +18,253 @@ #define NHTEXT_BUFFER_INCREMENT 10 /*----------------------------------------------------------------*/ struct text_buffer_line { - int attr; - short beg_padding; - short end_padding; - BOOL formatted; - char* text; + int attr; + short beg_padding; + short end_padding; + BOOL formatted; + char *text; }; /*----------------------------------------------------------------*/ typedef struct mswin_nethack_text_buffer { - BOOL b_wrap_text; - int n_size; - int n_used; - struct text_buffer_line *text_buffer_line; + BOOL b_wrap_text; + int n_size; + int n_used; + struct text_buffer_line *text_buffer_line; } NHTextBuffer, *PNHTextBuffer; /*----------------------------------------------------------------*/ -#define NHTextLine(pb,i) ((pb)->text_buffer_line[(i)]) -static TCHAR* nh_append( TCHAR* s, int* size, const char* ap ); +#define NHTextLine(pb, i) ((pb)->text_buffer_line[(i)]) +static TCHAR *nh_append(TCHAR *s, int *size, const char *ap); /*----------------------------------------------------------------*/ -PNHTextBuffer mswin_init_text_buffer(BOOL wrap_text) +PNHTextBuffer +mswin_init_text_buffer(BOOL wrap_text) { - PNHTextBuffer pb = (PNHTextBuffer)malloc(sizeof(NHTextBuffer)); - if( !pb ) panic("Out of memory"); - - ZeroMemory(pb, sizeof(NHTextBuffer)); - pb->b_wrap_text = wrap_text; - pb->n_size = 0; - pb->n_used = 0; - pb->text_buffer_line = NULL; - return pb; + PNHTextBuffer pb = (PNHTextBuffer) malloc(sizeof(NHTextBuffer)); + if (!pb) + panic("Out of memory"); + + ZeroMemory(pb, sizeof(NHTextBuffer)); + pb->b_wrap_text = wrap_text; + pb->n_size = 0; + pb->n_used = 0; + pb->text_buffer_line = NULL; + return pb; } /*----------------------------------------------------------------*/ -void mswin_free_text_buffer(PNHTextBuffer pb) +void +mswin_free_text_buffer(PNHTextBuffer pb) { - int i; - - if( !pb ) return; + int i; - for(i=0; in_used; i++ ) { - free(pb->text_buffer_line[i].text); - } - free( pb->text_buffer_line ); - free( pb ); + if (!pb) + return; + + for (i = 0; i < pb->n_used; i++) { + free(pb->text_buffer_line[i].text); + } + free(pb->text_buffer_line); + free(pb); } /*----------------------------------------------------------------*/ -void mswin_add_text(PNHTextBuffer pb, int attr, const char* text) +void +mswin_add_text(PNHTextBuffer pb, int attr, const char *text) { - char* p; - struct text_buffer_line* new_line; + char *p; + struct text_buffer_line *new_line; - /* grow buffer */ - if( pb->n_used >= pb->n_size ) { - pb->n_size += NHTEXT_BUFFER_INCREMENT; - pb->text_buffer_line = - (struct text_buffer_line*)realloc( pb->text_buffer_line, pb->n_size*sizeof(struct text_buffer_line) ); - if( !pb->text_buffer_line ) panic("Memory allocation error"); - } + /* grow buffer */ + if (pb->n_used >= pb->n_size) { + pb->n_size += NHTEXT_BUFFER_INCREMENT; + pb->text_buffer_line = (struct text_buffer_line *) realloc( + pb->text_buffer_line, + pb->n_size * sizeof(struct text_buffer_line)); + if (!pb->text_buffer_line) + panic("Memory allocation error"); + } - /* analyze the new line of text */ - new_line = &NHTextLine(pb, pb->n_used); - new_line->attr = attr; - new_line->beg_padding = 0; - new_line->text = strdup(text); - for( p = new_line->text; *p && isspace(*p); p++ ) { - new_line->beg_padding++; - } - if( *p ) { - memmove(new_line->text, - new_line->text + new_line->beg_padding, - strlen(new_line->text) - new_line->beg_padding + 1 - ); - for( p = new_line->text+strlen(new_line->text); - p>=new_line->text && isspace(*p); - p-- ) { - new_line->end_padding++; - *p = 0; - } + /* analyze the new line of text */ + new_line = &NHTextLine(pb, pb->n_used); + new_line->attr = attr; + new_line->beg_padding = 0; + new_line->text = strdup(text); + for (p = new_line->text; *p && isspace(*p); p++) { + new_line->beg_padding++; + } + if (*p) { + memmove(new_line->text, new_line->text + new_line->beg_padding, + strlen(new_line->text) - new_line->beg_padding + 1); + for (p = new_line->text + strlen(new_line->text); + p >= new_line->text && isspace(*p); p--) { + new_line->end_padding++; + *p = 0; + } - /* if there are 3 (or more) consecutive spaces inside the string - consider it formatted */ - new_line->formatted = - (strstr(new_line->text, " ")!=NULL) - || (new_line->beg_padding>8); - } else { - new_line->end_padding = 0; - new_line->text[0] = 0; - new_line->formatted = FALSE; - } - pb->n_used++; + /* if there are 3 (or more) consecutive spaces inside the string + consider it formatted */ + new_line->formatted = (strstr(new_line->text, " ") != NULL) + || (new_line->beg_padding > 8); + } else { + new_line->end_padding = 0; + new_line->text[0] = 0; + new_line->formatted = FALSE; + } + pb->n_used++; } /*----------------------------------------------------------------*/ -void mswin_set_text_wrap(PNHTextBuffer pb, BOOL wrap_text) +void +mswin_set_text_wrap(PNHTextBuffer pb, BOOL wrap_text) { - pb->b_wrap_text = wrap_text; + pb->b_wrap_text = wrap_text; } /*----------------------------------------------------------------*/ -BOOL mswin_get_text_wrap(PNHTextBuffer pb) +BOOL +mswin_get_text_wrap(PNHTextBuffer pb) { - return pb->b_wrap_text; + return pb->b_wrap_text; } /*----------------------------------------------------------------*/ -static TCHAR* nh_append( TCHAR* s, int* size, const char* ap ) +static TCHAR * +nh_append(TCHAR *s, int *size, const char *ap) { - int tlen, tnewlen; + int tlen, tnewlen; - if( !(ap && *ap) ) return s; + if (!(ap && *ap)) + return s; - /* append the calculated line to the text buffer */ - tlen = s? _tcslen(s) : 0; - tnewlen = tlen+strlen(ap); - if( tnewlen>=*size ) { - *size = max(tnewlen, *size + BUFSZ); - s = (TCHAR*)realloc(s, *size * sizeof(TCHAR)); - if( !s ) panic("Out of memory"); - ZeroMemory(s+tlen, (*size-tlen)*sizeof(TCHAR)); - } - if( strcmp(ap, "\r\n")==0 ) { - _tcscat(s, TEXT("\r\n")); - } else { - NH_A2W(ap, s+tlen, strlen(ap)); - s[tnewlen] = 0; - } - return s; + /* append the calculated line to the text buffer */ + tlen = s ? _tcslen(s) : 0; + tnewlen = tlen + strlen(ap); + if (tnewlen >= *size) { + *size = max(tnewlen, *size + BUFSZ); + s = (TCHAR *) realloc(s, *size * sizeof(TCHAR)); + if (!s) + panic("Out of memory"); + ZeroMemory(s + tlen, (*size - tlen) * sizeof(TCHAR)); + } + if (strcmp(ap, "\r\n") == 0) { + _tcscat(s, TEXT("\r\n")); + } else { + NH_A2W(ap, s + tlen, strlen(ap)); + s[tnewlen] = 0; + } + return s; } /*----------------------------------------------------------------*/ -void mswin_render_text(PNHTextBuffer pb, HWND edit_control) +void +mswin_render_text(PNHTextBuffer pb, HWND edit_control) { - RECT rt_client; /* boundaries of the client area of the edit control */ - SIZE size_text; /* size of the edit control */ - RECT rt_text; /* calculated text rectangle for the visible line */ - char buf[BUFSZ]; /* buffer for the visible line */ - TCHAR tbuf[BUFSZ]; /* temp buffer for DrawText */ - TCHAR* pText = NULL; /* resulting text (formatted) */ - int pTextSize = 0; /* resulting text size */ - char* p_cur = NULL; /* current position in the NHTextBuffer->text_buffer_line->text */ - char* p_buf_cur = NULL; /* current position in the visible line buffer */ - int i; - HDC hdcEdit; /* device context for the edit control */ - HFONT hFont, hOldFont; /* edit control font */ + RECT rt_client; /* boundaries of the client area of the edit control */ + SIZE size_text; /* size of the edit control */ + RECT rt_text; /* calculated text rectangle for the visible line */ + char buf[BUFSZ]; /* buffer for the visible line */ + TCHAR tbuf[BUFSZ]; /* temp buffer for DrawText */ + TCHAR *pText = NULL; /* resulting text (formatted) */ + int pTextSize = 0; /* resulting text size */ + char *p_cur = NULL; /* current position in the + NHTextBuffer->text_buffer_line->text */ + char *p_buf_cur = NULL; /* current position in the visible line buffer */ + int i; + HDC hdcEdit; /* device context for the edit control */ + HFONT hFont, hOldFont; /* edit control font */ - GetClientRect(edit_control, &rt_client ); - size_text.cx = rt_client.right - rt_client.left; - size_text.cy = rt_client.bottom - rt_client.top; - size_text.cx -= GetSystemMetrics(SM_CXVSCROLL); /* add a slight right margin - the text looks better that way */ - hdcEdit = GetDC(edit_control); - hFont = (HFONT)SendMessage(edit_control, WM_GETFONT, 0, 0); - if( hFont ) hOldFont = SelectObject(hdcEdit, hFont); + GetClientRect(edit_control, &rt_client); + size_text.cx = rt_client.right - rt_client.left; + size_text.cy = rt_client.bottom - rt_client.top; + size_text.cx -= + GetSystemMetrics(SM_CXVSCROLL); /* add a slight right margin - the + text looks better that way */ + hdcEdit = GetDC(edit_control); + hFont = (HFONT) SendMessage(edit_control, WM_GETFONT, 0, 0); + if (hFont) + hOldFont = SelectObject(hdcEdit, hFont); - /* loop through each line (outer loop) and wrap it around (inner loop) */ - ZeroMemory(buf, sizeof(buf)); - p_buf_cur = buf; - for( i=0; in_used; i++ ) { - if( pb->b_wrap_text ) { - p_cur = NHTextLine(pb,i).text; + /* loop through each line (outer loop) and wrap it around (inner loop) */ + ZeroMemory(buf, sizeof(buf)); + p_buf_cur = buf; + for (i = 0; i < pb->n_used; i++) { + if (pb->b_wrap_text) { + p_cur = NHTextLine(pb, i).text; - /* insert an line break for the empty string */ - if( !NHTextLine(pb,i).text[0] ) { - pText = nh_append(pText, &pTextSize, "\r\n"); - continue; - } + /* insert an line break for the empty string */ + if (!NHTextLine(pb, i).text[0]) { + pText = nh_append(pText, &pTextSize, "\r\n"); + continue; + } - /* add margin to the "formatted" line of text */ - if( NHTextLine(pb,i).formatted ) { - strcpy(buf, " "); - p_buf_cur += 3; - } + /* add margin to the "formatted" line of text */ + if (NHTextLine(pb, i).formatted) { + strcpy(buf, " "); + p_buf_cur += 3; + } - /* scroll thourgh the current line of text and wrap it - so it fits to width of the edit control */ - while( *p_cur ) { - char *p_word_pos = p_buf_cur; + /* scroll thourgh the current line of text and wrap it + so it fits to width of the edit control */ + while (*p_cur) { + char *p_word_pos = p_buf_cur; - /* copy one word into the buffer */ - while( *p_cur && isspace(*p_cur) ) - if( p_buf_cur!=buf ) *p_buf_cur++ = *p_cur++; - else p_cur++; + /* copy one word into the buffer */ + while (*p_cur && isspace(*p_cur)) + if (p_buf_cur != buf) + *p_buf_cur++ = *p_cur++; + else + p_cur++; - while( *p_cur && !isspace(*p_cur) ) - *p_buf_cur++ = *p_cur++; + while (*p_cur && !isspace(*p_cur)) + *p_buf_cur++ = *p_cur++; - /* check if it fits */ - SetRect( &rt_text, 0, 0, size_text.cx, size_text.cy ); - DrawText(hdcEdit, NH_A2W(buf, tbuf, p_buf_cur-buf), p_buf_cur-buf, &rt_text, DT_CALCRECT | DT_LEFT | DT_SINGLELINE | DT_NOCLIP); - if( (rt_text.right - rt_text.left)>=size_text.cx ) { - /* Backtrack. - Only backtrack if the last word caused the overflow - - do not backtrack if the entire current line does not fit the visible area. - Otherwise it is a infinite loop. - */ - if( p_word_pos>buf ) { - p_cur -= (p_buf_cur-p_word_pos); - p_buf_cur = p_word_pos; - } - *p_buf_cur = 0; /* break the line */ + /* check if it fits */ + SetRect(&rt_text, 0, 0, size_text.cx, size_text.cy); + DrawText(hdcEdit, NH_A2W(buf, tbuf, p_buf_cur - buf), + p_buf_cur - buf, &rt_text, + DT_CALCRECT | DT_LEFT | DT_SINGLELINE | DT_NOCLIP); + if ((rt_text.right - rt_text.left) >= size_text.cx) { + /* Backtrack. + Only backtrack if the last word caused the overflow - + do not backtrack if the entire current line does not + fit the visible area. + Otherwise it is a infinite loop. + */ + if (p_word_pos > buf) { + p_cur -= (p_buf_cur - p_word_pos); + p_buf_cur = p_word_pos; + } + *p_buf_cur = 0; /* break the line */ - /* append the calculated line to the text buffer */ - pText = nh_append(pText, &pTextSize, buf); - pText = nh_append(pText, &pTextSize, "\r\n"); - ZeroMemory(buf, sizeof(buf)); - p_buf_cur = buf; - } - } + /* append the calculated line to the text buffer */ + pText = nh_append(pText, &pTextSize, buf); + pText = nh_append(pText, &pTextSize, "\r\n"); + ZeroMemory(buf, sizeof(buf)); + p_buf_cur = buf; + } + } - /* always break the line at the end of the buffer text */ - if( p_buf_cur != buf ) { - /* flush the current buffrer */ - *p_buf_cur = 0; /* break the line */ - pText = nh_append(pText, &pTextSize, buf); - pText = nh_append(pText, &pTextSize, "\r\n"); - ZeroMemory(buf, sizeof(buf)); - p_buf_cur = buf; - } - } else { /* do not wrap text */ - int j; - for( j=0; jNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_status = NHFONT_STATUS_DEFAULT_SIZE; + if (iflags.wc_fontsiz_status < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_status > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_status = NHFONT_STATUS_DEFAULT_SIZE; - if( iflags.wc_fontsiz_messageNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_message < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_message > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_textNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_text < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_text > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_menuNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_menu < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_menu > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; - if( iflags.wc_align_message==0 ) iflags.wc_align_message = ALIGN_BOTTOM; - if( iflags.wc_align_status==0 ) iflags.wc_align_status = ALIGN_TOP; - if( iflags.wc_scroll_margin==0 ) iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; - if( iflags.wc_tile_width==0 ) iflags.wc_tile_width = TILE_X; - if( iflags.wc_tile_height==0 ) iflags.wc_tile_height = TILE_Y; + if (iflags.wc_align_message == 0) + iflags.wc_align_message = ALIGN_BOTTOM; + if (iflags.wc_align_status == 0) + iflags.wc_align_status = ALIGN_TOP; + if (iflags.wc_scroll_margin == 0) + iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; + if (iflags.wc_tile_width == 0) + iflags.wc_tile_width = TILE_X; + if (iflags.wc_tile_height == 0) + iflags.wc_tile_height = TILE_Y; - if( iflags.wc_vary_msgcount==0 ) iflags.wc_vary_msgcount = 3; + if (iflags.wc_vary_msgcount == 0) + iflags.wc_vary_msgcount = 3; - /* force tabs in menus */ - iflags.menu_tab_sep = 1; + /* force tabs in menus */ + iflags.menu_tab_sep = 1; - /* force toptenwin to be true. toptenwin is the option that decides whether to - * write output to a window or stdout. stdout doesn't make sense on Windows - * non-console applications - */ - iflags.toptenwin = 1; - set_option_mod_status("toptenwin", SET_IN_FILE); + /* force toptenwin to be true. toptenwin is the option that decides + * whether to + * write output to a window or stdout. stdout doesn't make sense on + * Windows + * non-console applications + */ + iflags.toptenwin = 1; + set_option_mod_status("toptenwin", SET_IN_FILE); - /* initialize map tiles bitmap */ - initMapTiles(); + /* initialize map tiles bitmap */ + initMapTiles(); - /* set tile-related options to readonly */ - set_wc_option_mod_status( - WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE, - DISP_IN_GAME); + /* set tile-related options to readonly */ + set_wc_option_mod_status(WC_TILE_WIDTH | WC_TILE_HEIGHT | WC_TILE_FILE, + DISP_IN_GAME); - /* init color table */ - mswin_init_color_table(); + /* init color table */ + mswin_init_color_table(); - /* set font-related options to change in the game */ - set_wc_option_mod_status( - WC_HILITE_PET | - WC_ALIGN_MESSAGE | - WC_ALIGN_STATUS | - WC_SCROLL_MARGIN | - WC_MAP_MODE | - WC_FONT_MESSAGE | - WC_FONT_STATUS | - WC_FONT_MENU | - WC_FONT_TEXT | - WC_FONTSIZ_MESSAGE | - WC_FONTSIZ_STATUS | - WC_FONTSIZ_MENU | - WC_FONTSIZ_TEXT | - WC_VARY_MSGCOUNT, - SET_IN_GAME - ); + /* set font-related options to change in the game */ + set_wc_option_mod_status( + WC_HILITE_PET | WC_ALIGN_MESSAGE | WC_ALIGN_STATUS | WC_SCROLL_MARGIN + | WC_MAP_MODE | WC_FONT_MESSAGE | WC_FONT_STATUS | WC_FONT_MENU + | WC_FONT_TEXT | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS + | WC_FONTSIZ_MENU | WC_FONTSIZ_TEXT | WC_VARY_MSGCOUNT, + SET_IN_GAME); - /* WC2 options */ - set_wc2_option_mod_status( - WC2_FULLSCREEN| - WC2_SOFTKEYBOARD, - SET_IN_FILE - ); - GetNHApp()->bFullScreen = iflags.wc2_fullscreen; - GetNHApp()->bUseSIP = iflags.wc2_softkeyboard; - - set_wc2_option_mod_status( - WC2_WRAPTEXT, - SET_IN_GAME - ); - GetNHApp()->bWrapText = iflags.wc2_wraptext; + /* WC2 options */ + set_wc2_option_mod_status(WC2_FULLSCREEN | WC2_SOFTKEYBOARD, SET_IN_FILE); + GetNHApp()->bFullScreen = iflags.wc2_fullscreen; + GetNHApp()->bUseSIP = iflags.wc2_softkeyboard; - /* create the main nethack window */ - hWnd = mswin_init_main_window(); - if (!hWnd) panic( "Cannot create the main window." ); - ShowWindow(hWnd, GetNHApp()->nCmdShow); - UpdateWindow(hWnd); - GetNHApp()->hMainWnd = hWnd; + set_wc2_option_mod_status(WC2_WRAPTEXT, SET_IN_GAME); + GetNHApp()->bWrapText = iflags.wc2_wraptext; - /* set Full screen if requested */ - mswin_set_fullscreen(GetNHApp()->bFullScreen); + /* create the main nethack window */ + hWnd = mswin_init_main_window(); + if (!hWnd) + panic("Cannot create the main window."); + ShowWindow(hWnd, GetNHApp()->nCmdShow); + UpdateWindow(hWnd); + GetNHApp()->hMainWnd = hWnd; - /* let nethack code know that the window subsystem is ready */ - iflags.window_inited = TRUE; + /* set Full screen if requested */ + mswin_set_fullscreen(GetNHApp()->bFullScreen); + + /* let nethack code know that the window subsystem is ready */ + iflags.window_inited = TRUE; } - /* Do a window-port specific player type selection. If player_selection() offers a Quit option, it is its responsibility to clean up and terminate the process. You need to fill in pl_character[0]. */ -void mswin_player_selection(void) +void +mswin_player_selection(void) { - logDebug("mswin_player_selection()\n"); + logDebug("mswin_player_selection()\n"); #if defined(WIN_CE_SMARTPHONE) - /* SmartPhone does not supprt combo-boxes therefor we cannot - use dialog for player selection */ + /* SmartPhone does not supprt combo-boxes therefor we cannot + use dialog for player selection */ prompt_for_player_selection(); #else - if (iflags.wc_player_selection == VIA_DIALOG) { - int nRole; + if (iflags.wc_player_selection == VIA_DIALOG) { + int nRole; - /* pick player type randomly (use pre-selected role/race/gender/alignment) */ - if( flags.randomall ) { - if (flags.initrole < 0) { - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - raw_print("Incompatible role!"); - flags.initrole = randrole(); - } - } + /* pick player type randomly (use pre-selected + * role/race/gender/alignment) */ + if (flags.randomall) { + if (flags.initrole < 0) { + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + raw_print("Incompatible role!"); + flags.initrole = randrole(); + } + } - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - raw_print("Incompatible race!"); - flags.initrace = randrace(flags.initrole); - } - } + if (flags.initrace < 0 + || !validrace(flags.initrole, flags.initrace)) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + raw_print("Incompatible race!"); + flags.initrace = randrace(flags.initrole); + } + } - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - raw_print("Incompatible gender!"); - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, + flags.initgend)) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + raw_print("Incompatible gender!"); + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - raw_print("Incompatible alignment!"); - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } - } else { - /* select a role */ - if( mswin_player_selection_window( &nRole ) == IDCANCEL ) { - bail(0); - } - } - } else { /* iflags.wc_player_selection == VIA_PROMPTS */ - prompt_for_player_selection(); - } + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, + flags.initalign)) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + raw_print("Incompatible alignment!"); + flags.initalign = + randalign(flags.initrole, flags.initrace); + } + } + } else { + /* select a role */ + if (mswin_player_selection_window(&nRole) == IDCANCEL) { + bail(0); + } + } + } else { /* iflags.wc_player_selection == VIA_PROMPTS */ + prompt_for_player_selection(); + } #endif /* defined(WIN_CE_SMARTPHONE) */ } -void prompt_for_player_selection(void) +void +prompt_for_player_selection(void) { - int i, k, n; - char pick4u = 'n', thisch, lastch = 0; - char pbuf[QBUFSZ], plbuf[QBUFSZ]; - winid win; - anything any; - menu_item *selected = 0; - int box_result; - TCHAR wbuf[BUFSZ]; + int i, k, n; + char pick4u = 'n', thisch, lastch = 0; + char pbuf[QBUFSZ], plbuf[QBUFSZ]; + winid win; + anything any; + menu_item *selected = 0; + int box_result; + TCHAR wbuf[BUFSZ]; - logDebug("prompt_for_player_selection()\n"); + logDebug("prompt_for_player_selection()\n"); - /* prevent an unnecessary prompt */ - rigid_role_checks(); + /* prevent an unnecessary prompt */ + rigid_role_checks(); - /* Should we randomly pick for the player? */ - if (!flags.randomall && - (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE || - flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { - /* int echoline; */ - char *prompt = build_plselection_prompt(pbuf, QBUFSZ, flags.initrole, - flags.initrace, flags.initgend, flags.initalign); + /* Should we randomly pick for the player? */ + if (!flags.randomall + && (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE + || flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { + /* int echoline; */ + char *prompt = build_plselection_prompt( + pbuf, QBUFSZ, flags.initrole, flags.initrace, flags.initgend, + flags.initalign); - /* tty_putstr(BASE_WINDOW, 0, ""); */ - /* echoline = wins[BASE_WINDOW]->cury; */ - box_result = MessageBox(NULL, - NH_A2W(prompt, wbuf, BUFSZ), - TEXT("NetHack for Windows"), + /* tty_putstr(BASE_WINDOW, 0, ""); */ + /* echoline = wins[BASE_WINDOW]->cury; */ + box_result = MessageBox(NULL, NH_A2W(prompt, wbuf, BUFSZ), + TEXT("NetHack for Windows"), #if defined(WIN_CE_SMARTPHONE) - MB_YESNO | MB_DEFBUTTON1 -#else - MB_YESNOCANCEL | MB_DEFBUTTON1 + MB_YESNO | MB_DEFBUTTON1 +#else + MB_YESNOCANCEL | MB_DEFBUTTON1 #endif - ); + ); - pick4u = (box_result == IDYES) ? 'y' : (box_result == IDNO) ? 'n' : '\033'; - /* tty_putstr(BASE_WINDOW, 0, prompt); */ - do { - /* pick4u = lowc(readchar()); */ - if (index(quitchars, pick4u)) pick4u = 'y'; - } while(!index(ynqchars, pick4u)); - if ((int)strlen(prompt) + 1 < CO) { - /* Echo choice and move back down line */ - /* tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline, pick4u); */ - /* tty_putstr(BASE_WINDOW, 0, ""); */ - } else - /* Otherwise it's hard to tell where to echo, and things are - * wrapping a bit messily anyway, so (try to) make sure the next - * question shows up well and doesn't get wrapped at the - * bottom of the window. - */ - /* tty_clear_nhwindow(BASE_WINDOW) */ ; - - if (pick4u != 'y' && pick4u != 'n') { -give_up: /* Quit */ - if (selected) free((genericptr_t) selected); - bail((char *)0); - /*NOTREACHED*/ - return; - } - } + pick4u = + (box_result == IDYES) ? 'y' : (box_result == IDNO) ? 'n' : '\033'; + /* tty_putstr(BASE_WINDOW, 0, prompt); */ + do { + /* pick4u = lowc(readchar()); */ + if (index(quitchars, pick4u)) + pick4u = 'y'; + } while (!index(ynqchars, pick4u)); + if ((int) strlen(prompt) + 1 < CO) { + /* Echo choice and move back down line */ + /* tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline, + * pick4u); */ + /* tty_putstr(BASE_WINDOW, 0, ""); */ + } else + /* Otherwise it's hard to tell where to echo, and things are + * wrapping a bit messily anyway, so (try to) make sure the next + * question shows up well and doesn't get wrapped at the + * bottom of the window. + */ + /* tty_clear_nhwindow(BASE_WINDOW) */; - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + if (pick4u != 'y' && pick4u != 'n') { + give_up: /* Quit */ + if (selected) + free((genericptr_t) selected); + bail((char *) 0); + /*NOTREACHED*/ + return; + } + } - /* Select a role, if necessary */ - /* we'll try to be compatible with pre-selected race/gender/alignment, - * but may not succeed */ - if (flags.initrole < 0) { - char rolenamebuf[QBUFSZ]; - /* Process the choice */ - if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) { - /* Pick a random role */ - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); */ - flags.initrole = randrole(); - } - } else { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Character's Role"); */ - /* Prompt for a role */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; roles[i].name.m; i++) { - if (ok_role(i, flags.initrace, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - thisch = lowc(roles[i].name.m[0]); - if (thisch == lastch) thisch = highc(thisch); - if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) { - if (flags.initgend == 1 && roles[i].name.f) - Strcpy(rolenamebuf, roles[i].name.f); - else - Strcpy(rolenamebuf, roles[i].name.m); - } else { - if (roles[i].name.f) { - Strcpy(rolenamebuf, roles[i].name.m); - Strcat(rolenamebuf, "/"); - Strcat(rolenamebuf, roles[i].name.f); - } else - Strcpy(rolenamebuf, roles[i].name.m); - } - add_menu(win, NO_GLYPH, &any, thisch, - 0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED); - lastch = thisch; - } - } - any.a_int = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrole()+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick a role for your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); - /* Process the choice */ - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + /* Select a role, if necessary */ + /* we'll try to be compatible with pre-selected race/gender/alignment, + * but may not succeed */ + if (flags.initrole < 0) { + char rolenamebuf[QBUFSZ]; + /* Process the choice */ + if (pick4u == 'y' || flags.initrole == ROLE_RANDOM + || flags.randomall) { + /* Pick a random role */ + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); */ + flags.initrole = randrole(); + } + } else { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Character's Role"); */ + /* Prompt for a role */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; roles[i].name.m; i++) { + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + thisch = lowc(roles[i].name.m[0]); + if (thisch == lastch) + thisch = highc(thisch); + if (flags.initgend != ROLE_NONE + && flags.initgend != ROLE_RANDOM) { + if (flags.initgend == 1 && roles[i].name.f) + Strcpy(rolenamebuf, roles[i].name.f); + else + Strcpy(rolenamebuf, roles[i].name.m); + } else { + if (roles[i].name.f) { + Strcpy(rolenamebuf, roles[i].name.m); + Strcat(rolenamebuf, "/"); + Strcat(rolenamebuf, roles[i].name.f); + } else + Strcpy(rolenamebuf, roles[i].name.m); + } + add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE, + an(rolenamebuf), MENU_UNSELECTED); + lastch = thisch; + } + } + any.a_int = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrole() + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick a role for your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); - flags.initrole = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } - - /* Select a race, if necessary */ - /* force compatibility with role, try for compatibility with - * pre-selected gender/alignment */ - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); */ - flags.initrace = randrace(flags.initrole); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid races */ - n = 0; /* number valid */ - k = 0; /* valid race */ - for (i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; races[i].noun; i++) { - if (validrace(flags.initrole, i)) { - n++; - k = i; - } - } - } + /* Process the choice */ + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Race"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; races[i].noun; i++) - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any, races[i].noun[0], - 0, ATR_NONE, races[i].noun, MENU_UNSELECTED); - } - any.a_int = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrace(flags.initrole)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the race of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + flags.initrole = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initrace = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } + /* Select a race, if necessary */ + /* force compatibility with role, try for compatibility with + * pre-selected gender/alignment */ + if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (pick4u == 'y' || flags.initrace == ROLE_RANDOM + || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); */ + flags.initrace = randrace(flags.initrole); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid races */ + n = 0; /* number valid */ + k = 0; /* valid race */ + for (i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; races[i].noun; i++) { + if (validrace(flags.initrole, i)) { + n++; + k = i; + } + } + } - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - /* pre-selected gender not valid */ - if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */ - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid genders */ - n = 0; /* number valid */ - k = 0; /* valid gender */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) { - if (validgend(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Race"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; races[i].noun; i++) + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0, + ATR_NONE, races[i].noun, MENU_UNSELECTED); + } + any.a_int = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrace(flags.initrole) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the race of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Gender"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, genders[i].adj[0], - 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randgend(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the gender of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initrace = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initgend = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (pick4u == 'y' || flags.initgend == ROLE_RANDOM + || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */ + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid genders */ + n = 0; /* number valid */ + k = 0; /* valid gender */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) { + if (validgend(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - /* pre-selected alignment not valid */ - if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */ - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid alignments */ - n = 0; /* number valid */ - k = 0; /* valid alignment */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, flags.initrace, flags.initgend, - i)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) { - if (validalign(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Gender"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, genders[i].adj[0], 0, + ATR_NONE, genders[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randgend(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the gender of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Alignment"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(flags.initrole, flags.initrace, - flags.initgend, i)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], - 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randalign(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the alignment of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initgend = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initalign = k; - } - } - /* Success! */ - /* tty_display_nhwindow(BASE_WINDOW, FALSE); */ + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (pick4u == 'y' || flags.initalign == ROLE_RANDOM + || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */ + flags.initalign = randalign(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid alignments */ + n = 0; /* number valid */ + k = 0; /* valid alignment */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) { + if (validalign(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Alignment"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(flags.initrole, flags.initrace, + flags.initgend, i)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0, + ATR_NONE, aligns[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randalign(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the alignment of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initalign = k; + } + } + /* Success! */ + /* tty_display_nhwindow(BASE_WINDOW, FALSE); */ } /* Ask the user for a player name. */ -void mswin_askname(void) +void +mswin_askname(void) { - logDebug("mswin_askname()\n"); + logDebug("mswin_askname()\n"); - if( mswin_getlin_window("who are you?", plname, PL_NSIZ)==IDCANCEL ) { - bail("bye-bye"); - /* not reached */ - } + if (mswin_getlin_window("who are you?", plname, PL_NSIZ) == IDCANCEL) { + bail("bye-bye"); + /* not reached */ + } } - /* Does window event processing (e.g. exposure events). A noop for the tty and X window-ports. */ -void mswin_get_nh_event(void) +void +mswin_get_nh_event(void) { - logDebug("mswin_get_nh_event()\n"); - return; + logDebug("mswin_get_nh_event()\n"); + return; } /* Exits the window system. This should dismiss all windows, except the "window" used for raw_print(). str is printed if possible. */ -void mswin_exit_nhwindows(const char *str) +void +mswin_exit_nhwindows(const char *str) { - logDebug("mswin_exit_nhwindows(%s)\n", str); + logDebug("mswin_exit_nhwindows(%s)\n", str); /* Write Window settings to the registry */ mswin_write_reg(); - // Don't do any of this (?) - exit_nhwindows does not terminate - // the application - // DestroyWindow(GetNHApp()->hMainWnd); - // terminate(EXIT_SUCCESS); + // Don't do any of this (?) - exit_nhwindows does not terminate + // the application + // DestroyWindow(GetNHApp()->hMainWnd); + // terminate(EXIT_SUCCESS); } /* Prepare the window to be suspended. */ -void mswin_suspend_nhwindows(const char *str) +void +mswin_suspend_nhwindows(const char *str) { - logDebug("mswin_suspend_nhwindows(%s)\n", str); - return; + logDebug("mswin_suspend_nhwindows(%s)\n", str); + return; } - /* Restore the windows after being suspended. */ -void mswin_resume_nhwindows() +void +mswin_resume_nhwindows() { - logDebug("mswin_resume_nhwindows()\n"); - return; + logDebug("mswin_resume_nhwindows()\n"); + return; } -/* Create a window of type "type" which can be +/* Create a window of type "type" which can be NHW_MESSAGE (top line) NHW_STATUS (bottom lines) NHW_MAP (main dungeon) NHW_MENU (inventory or other "corner" windows) NHW_TEXT (help/text, full screen paged window) */ -winid +winid mswin_create_nhwindow(int type) { - winid i = 0; - MSNHMsgAddWnd data; + winid i = 0; + MSNHMsgAddWnd data; - logDebug("mswin_create_nhwindow(%d)\n", type); + logDebug("mswin_create_nhwindow(%d)\n", type); - /* Return the next available winid - */ + /* Return the next available winid + */ - for (i=1; iwindowlist[i].win == NULL && - !GetNHApp()->windowlist[i].dead) - break; - if (i == MAXWINDOWS) - panic ("ERROR: No windows available...\n"); + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].win == NULL + && !GetNHApp()->windowlist[i].dead) + break; + if (i == MAXWINDOWS) + panic("ERROR: No windows available...\n"); switch (type) { - case NHW_MAP: - { - GetNHApp()->windowlist[i].win = mswin_init_map_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_MESSAGE: - { - GetNHApp()->windowlist[i].win = mswin_init_message_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_STATUS: - { - GetNHApp()->windowlist[i].win = mswin_init_status_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_MENU: - { - GetNHApp()->windowlist[i].win = NULL; //will create later - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 1; - break; - } - case NHW_TEXT: - { - GetNHApp()->windowlist[i].win = mswin_init_text_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - } + case NHW_MAP: { + GetNHApp()->windowlist[i].win = mswin_init_map_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_MESSAGE: { + GetNHApp()->windowlist[i].win = mswin_init_message_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_STATUS: { + GetNHApp()->windowlist[i].win = mswin_init_status_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_MENU: { + GetNHApp()->windowlist[i].win = NULL; // will create later + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 1; + break; + } + case NHW_TEXT: { + GetNHApp()->windowlist[i].win = mswin_init_text_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + } - ZeroMemory(&data, sizeof(data) ); - data.wid = i; - SendMessage( GetNHApp()->hMainWnd, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ADDWND, (LPARAM)&data ); - return i; + ZeroMemory(&data, sizeof(data)); + data.wid = i; + SendMessage(GetNHApp()->hMainWnd, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ADDWND, (LPARAM) &data); + return i; } /* Clear the given window, when asked to. */ -void mswin_clear_nhwindow(winid wid) +void +mswin_clear_nhwindow(winid wid) { - logDebug("mswin_clear_nhwindow(%d)\n", wid); + logDebug("mswin_clear_nhwindow(%d)\n", wid); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - if( GetNHApp()->windowlist[wid].type == NHW_MAP ) { - if( Is_rogue_level(&u.uz) ) - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), ROGUE_LEVEL_MAP_MODE); - else - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), iflags.wc_map_mode); - } + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + if (GetNHApp()->windowlist[wid].type == NHW_MAP) { + if (Is_rogue_level(&u.uz)) + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), + ROGUE_LEVEL_MAP_MODE); + else + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), + iflags.wc_map_mode); + } - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLEAR_WINDOW, (LPARAM)NULL ); + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CLEAR_WINDOW, (LPARAM) NULL); } } @@ -815,91 +796,98 @@ void mswin_clear_nhwindow(winid wid) -- Calling display_nhwindow(WIN_MESSAGE,???) will do a --more--, if necessary, in the tty window-port. */ -void mswin_display_nhwindow(winid wid, BOOLEAN_P block) +void +mswin_display_nhwindow(winid wid, BOOLEAN_P block) { - logDebug("mswin_display_nhwindow(%d, %d)\n", wid, block); - if (GetNHApp()->windowlist[wid].win != NULL) - { - if (GetNHApp()->windowlist[wid].type == NHW_MENU) { - MENU_ITEM_P* p; - mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, PICK_NONE, &p); - } if (GetNHApp()->windowlist[wid].type == NHW_TEXT) { - mswin_display_text_window(GetNHApp()->windowlist[wid].win); - } if (GetNHApp()->windowlist[wid].type == NHW_RIP) { - mswin_display_RIP_window(GetNHApp()->windowlist[wid].win); - } else { - if( !block ) { - UpdateWindow(GetNHApp()->windowlist[wid].win); - } else { - if ( GetNHApp()->windowlist[wid].type == NHW_MAP ) { - (void) mswin_nhgetch(); - } - } - } - SetFocus(GetNHApp()->hMainWnd); - } + logDebug("mswin_display_nhwindow(%d, %d)\n", wid, block); + if (GetNHApp()->windowlist[wid].win != NULL) { + if (GetNHApp()->windowlist[wid].type == NHW_MENU) { + MENU_ITEM_P *p; + mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, + PICK_NONE, &p); + } + if (GetNHApp()->windowlist[wid].type == NHW_TEXT) { + mswin_display_text_window(GetNHApp()->windowlist[wid].win); + } + if (GetNHApp()->windowlist[wid].type == NHW_RIP) { + mswin_display_RIP_window(GetNHApp()->windowlist[wid].win); + } else { + if (!block) { + UpdateWindow(GetNHApp()->windowlist[wid].win); + } else { + if (GetNHApp()->windowlist[wid].type == NHW_MAP) { + (void) mswin_nhgetch(); + } + } + } + SetFocus(GetNHApp()->hMainWnd); + } } - -HWND mswin_hwnd_from_winid(winid wid) +HWND +mswin_hwnd_from_winid(winid wid) { - if( wid>=0 && widwindowlist[wid].win; - } else { - return NULL; - } + if (wid >= 0 && wid < MAXWINDOWS) { + return GetNHApp()->windowlist[wid].win; + } else { + return NULL; + } } -winid mswin_winid_from_handle(HWND hWnd) +winid +mswin_winid_from_handle(HWND hWnd) { - winid i = 0; + winid i = 0; - for (i=1; iwindowlist[i].win == hWnd) - return i; - return -1; + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].win == hWnd) + return i; + return -1; } -winid mswin_winid_from_type(int type) +winid +mswin_winid_from_type(int type) { - winid i = 0; + winid i = 0; - for (i=1; iwindowlist[i].type == type) - return i; - return -1; + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].type == type) + return i; + return -1; } -void mswin_window_mark_dead(winid wid) +void +mswin_window_mark_dead(winid wid) { - if( wid>=0 && widwindowlist[wid].win = NULL; - GetNHApp()->windowlist[wid].dead = 1; - } + if (wid >= 0 && wid < MAXWINDOWS) { + GetNHApp()->windowlist[wid].win = NULL; + GetNHApp()->windowlist[wid].dead = 1; + } } -/* Destroy will dismiss the window if the window has not +/* Destroy will dismiss the window if the window has not * already been dismissed. */ -void mswin_destroy_nhwindow(winid wid) +void +mswin_destroy_nhwindow(winid wid) { - logDebug("mswin_destroy_nhwindow(%d)\n", wid); + logDebug("mswin_destroy_nhwindow(%d)\n", wid); - if ((GetNHApp()->windowlist[wid].type == NHW_MAP) || - (GetNHApp()->windowlist[wid].type == NHW_MESSAGE) || - (GetNHApp()->windowlist[wid].type == NHW_STATUS)) { - /* main windows is going to take care of those */ - return; + if ((GetNHApp()->windowlist[wid].type == NHW_MAP) + || (GetNHApp()->windowlist[wid].type == NHW_MESSAGE) + || (GetNHApp()->windowlist[wid].type == NHW_STATUS)) { + /* main windows is going to take care of those */ + return; } if (wid != -1) { - if( !GetNHApp()->windowlist[wid].dead && - GetNHApp()->windowlist[wid].win != NULL ) - DestroyWindow(GetNHApp()->windowlist[wid].win); - GetNHApp()->windowlist[wid].win = NULL; - GetNHApp()->windowlist[wid].type = 0; - GetNHApp()->windowlist[wid].dead = 0; - } + if (!GetNHApp()->windowlist[wid].dead + && GetNHApp()->windowlist[wid].win != NULL) + DestroyWindow(GetNHApp()->windowlist[wid].win); + GetNHApp()->windowlist[wid].win = NULL; + GetNHApp()->windowlist[wid].type = 0; + GetNHApp()->windowlist[wid].dead = 0; + } } /* Next output to window will start at (x,y), also moves @@ -907,20 +895,18 @@ void mswin_destroy_nhwindow(winid wid) 1 <= x < cols, 0 <= y < rows, where cols and rows are the size of window. */ -void mswin_curs(winid wid, int x, int y) +void +mswin_curs(winid wid, int x, int y) { - logDebug("mswin_curs(%d, %d, %d)\n", wid, x, y); + logDebug("mswin_curs(%d, %d, %d)\n", wid, x, y); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgCursor data; - data.x = x; - data.y = y; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CURSOR, (LPARAM)&data ); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgCursor data; + data.x = x; + data.y = y; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CURSOR, (LPARAM) &data); } } @@ -947,72 +933,75 @@ Attributes then the second. In the tty port, pline() achieves this by calling more() or displaying both on the same line. */ -void mswin_putstr(winid wid, int attr, const char *text) +void +mswin_putstr(winid wid, int attr, const char *text) { - logDebug("mswin_putstr(%d, %d, %s)\n", wid, attr, text); + logDebug("mswin_putstr(%d, %d, %s)\n", wid, attr, text); - mswin_putstr_ex(wid, attr, text, 0); + mswin_putstr_ex(wid, attr, text, 0); } -void mswin_putstr_ex(winid wid, int attr, const char *text, boolean app) +void +mswin_putstr_ex(winid wid, int attr, const char *text, boolean app) { - if( (wid >= 0) && - (wid < MAXWINDOWS) ) - { - if( GetNHApp()->windowlist[wid].win==NULL && - GetNHApp()->windowlist[wid].type==NHW_MENU ) { - GetNHApp()->windowlist[wid].win = mswin_init_menu_window(MENU_TYPE_TEXT); - GetNHApp()->windowlist[wid].dead = 0; - } + if ((wid >= 0) && (wid < MAXWINDOWS)) { + if (GetNHApp()->windowlist[wid].win == NULL + && GetNHApp()->windowlist[wid].type == NHW_MENU) { + GetNHApp()->windowlist[wid].win = + mswin_init_menu_window(MENU_TYPE_TEXT); + GetNHApp()->windowlist[wid].dead = 0; + } - if (GetNHApp()->windowlist[wid].win != NULL) - { - MSNHMsgPutstr data; - ZeroMemory(&data, sizeof(data)); - data.attr = attr; - data.text = text; - data.append = app; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_PUTSTR, (LPARAM)&data ); - } - } + if (GetNHApp()->windowlist[wid].win != NULL) { + MSNHMsgPutstr data; + ZeroMemory(&data, sizeof(data)); + data.attr = attr; + data.text = text; + data.append = app; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_PUTSTR, (LPARAM) &data); + } + } } /* Display the file named str. Complain about missing files iff complain is TRUE. */ -void mswin_display_file(const char *filename,BOOLEAN_P must_exist) +void +mswin_display_file(const char *filename, BOOLEAN_P must_exist) { - dlb *f; - TCHAR wbuf[BUFSZ]; + dlb *f; + TCHAR wbuf[BUFSZ]; - logDebug("mswin_display_file(%s, %d)\n", filename, must_exist); + logDebug("mswin_display_file(%s, %d)\n", filename, must_exist); - f = dlb_fopen(filename, RDTMODE); - if (!f) { - if (must_exist) { - TCHAR message[90]; - _stprintf(message, TEXT("Warning! Could not find file: %s\n"), NH_A2W(filename, wbuf, sizeof(wbuf))); - MessageBox(GetNHApp()->hMainWnd, message, TEXT("ERROR"), MB_OK | MB_ICONERROR ); - } - } else { - winid text; - char line[LLEN]; + f = dlb_fopen(filename, RDTMODE); + if (!f) { + if (must_exist) { + TCHAR message[90]; + _stprintf(message, TEXT("Warning! Could not find file: %s\n"), + NH_A2W(filename, wbuf, sizeof(wbuf))); + MessageBox(GetNHApp()->hMainWnd, message, TEXT("ERROR"), + MB_OK | MB_ICONERROR); + } + } else { + winid text; + char line[LLEN]; - text = mswin_create_nhwindow(NHW_TEXT); + text = mswin_create_nhwindow(NHW_TEXT); - while (dlb_fgets(line, LLEN, f)) { - size_t len; - len = strlen(line); - if( line[len-1]=='\n' ) line[len-1]='\x0'; - mswin_putstr(text, ATR_NONE, line); - } - (void) dlb_fclose(f); + while (dlb_fgets(line, LLEN, f)) { + size_t len; + len = strlen(line); + if (line[len - 1] == '\n') + line[len - 1] = '\x0'; + mswin_putstr(text, ATR_NONE, line); + } + (void) dlb_fclose(f); - mswin_display_nhwindow(text, 1); - mswin_destroy_nhwindow(text); - } + mswin_display_nhwindow(text, 1); + mswin_destroy_nhwindow(text); + } } /* Start using window as a menu. You must call start_menu() @@ -1020,31 +1009,31 @@ void mswin_display_file(const char *filename,BOOLEAN_P must_exist) putstr() to the window. Only windows of type NHW_MENU may be used for menus. */ -void mswin_start_menu(winid wid) +void +mswin_start_menu(winid wid) { - logDebug("mswin_start_menu(%d)\n", wid); - if( (wid >= 0) && - (wid < MAXWINDOWS) ) { - if( GetNHApp()->windowlist[wid].win==NULL && - GetNHApp()->windowlist[wid].type==NHW_MENU ) { - GetNHApp()->windowlist[wid].win = mswin_init_menu_window(MENU_TYPE_MENU); - GetNHApp()->windowlist[wid].dead = 0; - } + logDebug("mswin_start_menu(%d)\n", wid); + if ((wid >= 0) && (wid < MAXWINDOWS)) { + if (GetNHApp()->windowlist[wid].win == NULL + && GetNHApp()->windowlist[wid].type == NHW_MENU) { + GetNHApp()->windowlist[wid].win = + mswin_init_menu_window(MENU_TYPE_MENU); + GetNHApp()->windowlist[wid].dead = 0; + } - if(GetNHApp()->windowlist[wid].win != NULL) { - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_STARTMENU, (LPARAM)NULL - ); - } - } + if (GetNHApp()->windowlist[wid].win != NULL) { + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_STARTMENU, (LPARAM) NULL); + } + } } /* add_menu(windid window, int glyph, const anything identifier, char accelerator, char groupacc, int attr, char *str, boolean preselected) - -- Add a text line str to the given menu window. If identifier + -- Add a text line str to the given menu window. If +identifier is 0, then the line cannot be selected (e.g. a title). Otherwise, identifier is the value returned if the line is selected. Accelerator is a keyboard key that can be used @@ -1071,32 +1060,29 @@ add_menu(windid window, int glyph, const anything identifier, -- If you want this choice to be preselected when the menu is displayed, set preselected to TRUE. */ -void mswin_add_menu(winid wid, int glyph, const ANY_P * identifier, - CHAR_P accelerator, CHAR_P group_accel, int attr, - const char *str, BOOLEAN_P presel) +void +mswin_add_menu(winid wid, int glyph, const ANY_P *identifier, + CHAR_P accelerator, CHAR_P group_accel, int attr, + const char *str, BOOLEAN_P presel) { - logDebug("mswin_add_menu(%d, %d, %p, %c, %c, %d, %s, %d)\n", - wid, glyph, identifier, (char)accelerator, (char)group_accel, - attr, str, presel); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgAddMenu data; - ZeroMemory(&data, sizeof(data)); - data.glyph = glyph; - data.identifier = identifier; - data.accelerator = accelerator; - data.group_accel = group_accel; - data.attr = attr; - data.str = str; - data.presel = presel; + logDebug("mswin_add_menu(%d, %d, %p, %c, %c, %d, %s, %d)\n", wid, glyph, + identifier, (char) accelerator, (char) group_accel, attr, str, + presel); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgAddMenu data; + ZeroMemory(&data, sizeof(data)); + data.glyph = glyph; + data.identifier = identifier; + data.accelerator = accelerator; + data.group_accel = group_accel; + data.attr = attr; + data.str = str; + data.presel = presel; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ADDMENU, (LPARAM)&data - ); - } + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ADDMENU, (LPARAM) &data); + } } /* @@ -1108,22 +1094,19 @@ end_menu(window, prompt) ** This probably shouldn't flush the window any more (if ** it ever did). That should be select_menu's job. -dean */ -void mswin_end_menu(winid wid, const char *prompt) +void +mswin_end_menu(winid wid, const char *prompt) { - logDebug("mswin_end_menu(%d, %s)\n", wid, prompt); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgEndMenu data; - ZeroMemory(&data, sizeof(data)); - data.text = prompt; + logDebug("mswin_end_menu(%d, %s)\n", wid, prompt); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgEndMenu data; + ZeroMemory(&data, sizeof(data)); + data.text = prompt; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ENDMENU, (LPARAM)&data - ); - } + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ENDMENU, (LPARAM) &data); + } } /* @@ -1151,29 +1134,30 @@ int select_menu(windid window, int how, menu_item **selected) select_menu() will be called for the window at create_nhwindow() time. */ -int mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected) +int +mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected) { - int nReturned = -1; + int nReturned = -1; - logDebug("mswin_select_menu(%d, %d)\n", wid, how); + logDebug("mswin_select_menu(%d, %d)\n", wid, how); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - nReturned = mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, how, selected); - } + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + nReturned = mswin_menu_window_select_menu( + GetNHApp()->windowlist[wid].win, how, selected); + } return nReturned; } /* -- Indicate to the window port that the inventory has been changed. - -- Merely calls display_inventory() for window-ports that leave the - window up, otherwise empty. + -- Merely calls display_inventory() for window-ports that leave the + window up, otherwise empty. */ -void mswin_update_inventory() +void +mswin_update_inventory() { - logDebug("mswin_update_inventory()\n"); + logDebug("mswin_update_inventory()\n"); } /* @@ -1181,9 +1165,10 @@ mark_synch() -- Don't go beyond this point in I/O on any channel until all channels are caught up to here. Can be an empty call for the moment */ -void mswin_mark_synch() +void +mswin_mark_synch() { - logDebug("mswin_mark_synch()\n"); + logDebug("mswin_mark_synch()\n"); } /* @@ -1192,9 +1177,10 @@ wait_synch() -- Wait until all pending output is complete (*flush*() for -- May also deal with exposure events etc. so that the display is OK when return from wait_synch(). */ -void mswin_wait_synch() +void +mswin_wait_synch() { - logDebug("mswin_wait_synch()\n"); + logDebug("mswin_wait_synch()\n"); } /* @@ -1202,22 +1188,20 @@ cliparound(x, y)-- Make sure that the user is more-or-less centered on the screen if the playing area is larger than the screen. -- This function is only defined if CLIPPING is defined. */ -void mswin_cliparound(int x, int y) +void +mswin_cliparound(int x, int y) { - winid wid = WIN_MAP; + winid wid = WIN_MAP; - logDebug("mswin_cliparound(%d, %d)\n", x, y); + logDebug("mswin_cliparound(%d, %d)\n", x, y); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgClipAround data; - data.x = x; - data.y = y; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLIPAROUND, (LPARAM)&data ); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgClipAround data; + data.x = x; + data.y = y; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CLIPAROUND, (LPARAM) &data); } } @@ -1228,23 +1212,22 @@ print_glyph(window, x, y, glyph) port wants (symbol, font, color, attributes, ...there's a 1-1 map between glyphs and distinct things on the map). */ -void mswin_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph) +void +mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph) { logDebug("mswin_print_glyph(%d, %d, %d, %d)\n", wid, x, y, glyph); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgPrintGlyph data; + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgPrintGlyph data; - ZeroMemory(&data, sizeof(data) ); - data.x = x; - data.y = y; - data.glyph = glyph; - SendMessage( GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_PRINT_GLYPH, (LPARAM)&data ); - } + ZeroMemory(&data, sizeof(data)); + data.x = x; + data.y = y; + data.glyph = glyph; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_PRINT_GLYPH, (LPARAM) &data); + } } /* @@ -1256,12 +1239,14 @@ raw_print(str) -- Print directly to a screen, or otherwise guarantee that for error messages, and maybe other "msg" uses. E.g. updating status for micros (i.e, "saving"). */ -void mswin_raw_print(const char *str) +void +mswin_raw_print(const char *str) { - TCHAR wbuf[255]; + TCHAR wbuf[255]; logDebug("mswin_raw_print(%s)\n", str); - if( str && *str) - MessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), TEXT("NetHack"), MB_OK ); + if (str && *str) + MessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), + TEXT("NetHack"), MB_OK); } /* @@ -1269,12 +1254,14 @@ raw_print_bold(str) -- Like raw_print(), but prints in bold/standout (if possible). */ -void mswin_raw_print_bold(const char *str) +void +mswin_raw_print_bold(const char *str) { - TCHAR wbuf[255]; + TCHAR wbuf[255]; logDebug("mswin_raw_print_bold(%s)\n", str); - if( str && *str) - MessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), TEXT("NetHack"), MB_OK ); + if (str && *str) + MessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), + TEXT("NetHack"), MB_OK); } /* @@ -1283,19 +1270,18 @@ int nhgetch() -- Returns a single character input from the user. will be the routine the OS provides to read a character. Returned character _must_ be non-zero. */ -int mswin_nhgetch() +int +mswin_nhgetch() { - PMSNHEvent event; + PMSNHEvent event; int key = 0; - logDebug("mswin_nhgetch()\n"); - + logDebug("mswin_nhgetch()\n"); - while( (event = mswin_input_pop()) == NULL || - event->type != NHEVENT_CHAR ) - mswin_main_loop(); + while ((event = mswin_input_pop()) == NULL || event->type != NHEVENT_CHAR) + mswin_main_loop(); - key = event->kbd.ch; + key = event->kbd.ch; return (key); } @@ -1307,40 +1293,44 @@ int nh_poskey(int *x, int *y, int *mod) a position in the MAP window is returned in x, y and mod. mod may be one of - CLICK_1 -- mouse click type 1 - CLICK_2 -- mouse click type 2 + CLICK_1 -- mouse click type 1 + CLICK_2 -- mouse click type 2 The different click types can map to whatever the hardware supports. If no mouse is supported, this routine always returns a non-zero character. */ -int mswin_nh_poskey(int *x, int *y, int *mod) +int +mswin_nh_poskey(int *x, int *y, int *mod) { - PMSNHEvent event; - int key; + PMSNHEvent event; + int key; - logDebug("mswin_nh_poskey()\n"); + logDebug("mswin_nh_poskey()\n"); - while( (event = mswin_input_pop())==NULL ) mswin_main_loop(); + while ((event = mswin_input_pop()) == NULL) + mswin_main_loop(); - if( event->type==NHEVENT_MOUSE ) { - *mod = event->ms.mod; - *x = event->ms.x; - *y = event->ms.y; - key = 0; - } else { - key = event->kbd.ch; - } - return (key); + if (event->type == NHEVENT_MOUSE) { + *mod = event->ms.mod; + *x = event->ms.x; + *y = event->ms.y; + key = 0; + } else { + key = event->kbd.ch; + } + return (key); } /* nhbell() -- Beep at user. [This will exist at least until sounds are - redone, since sounds aren't attributable to windows anyway.] + redone, since sounds aren't attributable to windows +anyway.] */ -void mswin_nhbell() +void +mswin_nhbell() { - logDebug("mswin_nhbell()\n"); + logDebug("mswin_nhbell()\n"); } /* @@ -1348,10 +1338,12 @@ doprev_message() -- Display previous messages. Used by the ^P command. -- On the tty-port this scrolls WIN_MESSAGE back one line. */ -int mswin_doprev_message() +int +mswin_doprev_message() { logDebug("mswin_doprev_message()\n"); - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); return 0; } @@ -1374,354 +1366,364 @@ char yn_function(const char *ques, const char *choices, char default) -- This uses the top line in the tty window-port, other ports might use a popup. */ -char mswin_yn_function(const char *question, const char *choices, - CHAR_P def) +char +mswin_yn_function(const char *question, const char *choices, CHAR_P def) { - int result=-1; + int result = -1; char ch; - char yn_esc_map='\033'; + char yn_esc_map = '\033'; char message[BUFSZ]; - char res_ch[2]; + char res_ch[2]; - logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); + logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); if (choices) { - char *cb, choicebuf[QBUFSZ]; - Strcpy(choicebuf, choices); - if ((cb = index(choicebuf, '\033')) != 0) { - /* anything beyond is hidden */ - *cb = '\0'; - } - (void)strncpy(message, question, QBUFSZ-1); - message[QBUFSZ-1] = '\0'; - sprintf(eos(message), " [%s]", choicebuf); - if (def) sprintf(eos(message), " (%c)", def); - Strcat(message, " "); - /* escape maps to 'q' or 'n' or default, in that order */ - yn_esc_map = (index(choices, 'q') ? 'q' : - (index(choices, 'n') ? 'n' : def)); - } else { - Strcpy(message, question); + char *cb, choicebuf[QBUFSZ]; + Strcpy(choicebuf, choices); + if ((cb = index(choicebuf, '\033')) != 0) { + /* anything beyond is hidden */ + *cb = '\0'; + } + (void) strncpy(message, question, QBUFSZ - 1); + message[QBUFSZ - 1] = '\0'; + sprintf(eos(message), " [%s]", choicebuf); + if (def) + sprintf(eos(message), " (%c)", def); + Strcat(message, " "); + /* escape maps to 'q' or 'n' or default, in that order */ + yn_esc_map = + (index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def)); + } else { + Strcpy(message, question); } #if defined(WIN_CE_SMARTPHONE) - { - char buf[BUFSZ]; - ZeroMemory(buf, sizeof(buf)); - if( choices ) { - if( !index(choices, '\033') ) buf[0]='\033'; /* make sure ESC is always available */ - strncat( buf, choices, sizeof(buf)-2); - NHSPhoneSetKeypadFromString( buf ); - } else { - /* sometimes choices are included in the message itself, e.g. "what? [abcd]" */ - char *p1, *p2; - p1 = strchr(question, '['); - p2 = strrchr(question, ']'); - if( p1 && p2 && p1= 0) && (wid < MAXWINDOWS) ) { - DestroyWindow(GetNHApp()->windowlist[wid].win); - GetNHApp()->windowlist[wid].win = mswin_init_RIP_window(); - GetNHApp()->windowlist[wid].type = NHW_RIP; - GetNHApp()->windowlist[wid].dead = 0; - } + logDebug("mswin_outrip(%d, %d, %ld)\n", wid, how, (long) when); + if ((wid >= 0) && (wid < MAXWINDOWS)) { + DestroyWindow(GetNHApp()->windowlist[wid].win); + GetNHApp()->windowlist[wid].win = mswin_init_RIP_window(); + GetNHApp()->windowlist[wid].type = NHW_RIP; + GetNHApp()->windowlist[wid].dead = 0; + } genl_outrip(wid, how, when); } /* handle options updates here */ -void mswin_preference_update(const char *pref) +void +mswin_preference_update(const char *pref) { - HDC hdc; + HDC hdc; - if( _stricmp( pref, "font_menu")==0 || - _stricmp( pref, "font_size_menu")==0 ) { - if( iflags.wc_fontsiz_menuNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; + if (_stricmp(pref, "font_menu") == 0 + || _stricmp(pref, "font_size_menu") == 0) { + if (iflags.wc_fontsiz_menu < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_menu > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_MENU, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_MENU, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - mswin_layout_main_window(NULL); - return; - } + mswin_layout_main_window(NULL); + return; + } - if( _stricmp( pref, "font_status")==0 || - _stricmp( pref, "font_size_status")==0 ) { + if (_stricmp(pref, "font_status") == 0 + || _stricmp(pref, "font_size_status") == 0) { + if (iflags.wc_fontsiz_status < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_status > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_statusNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_STATUS, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_STATUS, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + mswin_layout_main_window(NULL); + return; + } - mswin_layout_main_window(NULL); - return; - } + if (_stricmp(pref, "font_message") == 0 + || _stricmp(pref, "font_size_message") == 0) { + if (iflags.wc_fontsiz_message < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_message > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; - if( _stricmp( pref, "font_message")==0 || - _stricmp( pref, "font_size_message")==0 ) { + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - if( iflags.wc_fontsiz_messageNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; + mswin_layout_main_window(NULL); + return; + } - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + if (_stricmp(pref, "font_text") == 0 + || _stricmp(pref, "font_size_text") == 0) { + if (iflags.wc_fontsiz_text < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_text > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; - mswin_layout_main_window(NULL); - return; - } + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_TEXT, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - if( _stricmp( pref, "font_text")==0 || - _stricmp( pref, "font_size_text")==0 ) { + mswin_layout_main_window(NULL); + return; + } - if( iflags.wc_fontsiz_textNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; + if (_stricmp(pref, "scroll_margin") == 0) { + mswin_cliparound(u.ux, u.uy); + return; + } - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_TEXT, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + if (_stricmp(pref, "map_mode") == 0) { + mswin_select_map_mode(iflags.wc_map_mode); + return; + } - mswin_layout_main_window(NULL); - return; - } + if (_stricmp(pref, "hilite_pet") == 0) { + InvalidateRect(mswin_hwnd_from_winid(WIN_MAP), NULL, TRUE); + return; + } - if( _stricmp( pref, "scroll_margin")==0 ) { - mswin_cliparound(u.ux, u.uy); - return; - } + if (_stricmp(pref, "align_message") == 0 + || _stricmp(pref, "align_status") == 0) { + mswin_layout_main_window(NULL); + return; + } - if( _stricmp( pref, "map_mode")==0 ) { - mswin_select_map_mode( iflags.wc_map_mode ); - return; - } + if (_stricmp(pref, "vary_msgcount") == 0) { + InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); + mswin_layout_main_window(NULL); + return; + } - if( _stricmp( pref, "hilite_pet")==0 ) { - InvalidateRect(mswin_hwnd_from_winid(WIN_MAP), NULL, TRUE); - return; - } + if (_stricmp(pref, "fullscreen") == 0) { + mswin_set_fullscreen(iflags.wc2_fullscreen); + return; + } - if( _stricmp( pref, "align_message")==0 || - _stricmp( pref, "align_status")==0 ) { - mswin_layout_main_window(NULL); - return; - } - - if( _stricmp( pref, "vary_msgcount")==0 ) { - InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); - mswin_layout_main_window(NULL); - return; - } - - if( _stricmp( pref, "fullscreen")==0 ) { - mswin_set_fullscreen(iflags.wc2_fullscreen); - return; - } - - if( _stricmp( pref, "softkeyboard")==0 ) { - GetNHApp()->bUseSIP = iflags.wc2_softkeyboard; - return; - } - - if( _stricmp( pref, "wraptext")==0 ) { - GetNHApp()->bWrapText = iflags.wc2_wraptext; - return; - } + if (_stricmp(pref, "softkeyboard") == 0) { + GetNHApp()->bUseSIP = iflags.wc2_softkeyboard; + return; + } + if (_stricmp(pref, "wraptext") == 0) { + GetNHApp()->bWrapText = iflags.wc2_wraptext; + return; + } } -void mswin_main_loop() +void +mswin_main_loop() { - MSG msg; + MSG msg; - while( !mswin_have_input() && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + while (!mswin_have_input() && GetMessage(&msg, NULL, 0, 0) != 0) { + if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } } /* clean up and quit */ -void bail(const char *mesg) +void +bail(const char *mesg) { clearlocks(); mswin_exit_nhwindows(mesg); @@ -1729,253 +1731,253 @@ void bail(const char *mesg) /*NOTREACHED*/ } -BOOL initMapTiles(void) +BOOL +initMapTiles(void) { - HBITMAP hBmp; - BITMAP bm; - TCHAR wbuf[MAX_PATH]; - int tl_num; - SIZE map_size; - extern int total_tiles_used; + HBITMAP hBmp; + BITMAP bm; + TCHAR wbuf[MAX_PATH]; + int tl_num; + SIZE map_size; + extern int total_tiles_used; - /* no file - no tile */ - if( !(iflags.wc_tile_file && *iflags.wc_tile_file) ) - return TRUE; + /* no file - no tile */ + if (!(iflags.wc_tile_file && *iflags.wc_tile_file)) + return TRUE; - /* load bitmap */ - hBmp = SHLoadDIBitmap(NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH)); - if( hBmp==NULL ) { - raw_print("Cannot load tiles from the file. Reverting back to default."); - return FALSE; - } + /* load bitmap */ + hBmp = SHLoadDIBitmap(NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH)); + if (hBmp == NULL) { + raw_print( + "Cannot load tiles from the file. Reverting back to default."); + return FALSE; + } - /* calculate tile dimensions */ - GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bm); - if( bm.bmWidth%iflags.wc_tile_width || - bm.bmHeight%iflags.wc_tile_height ) { - DeleteObject(hBmp); - raw_print("Tiles bitmap does not match tile_width and tile_height options. Reverting back to default."); - return FALSE; - } + /* calculate tile dimensions */ + GetObject(hBmp, sizeof(BITMAP), (LPVOID) &bm); + if (bm.bmWidth % iflags.wc_tile_width + || bm.bmHeight % iflags.wc_tile_height) { + DeleteObject(hBmp); + raw_print("Tiles bitmap does not match tile_width and tile_height " + "options. Reverting back to default."); + return FALSE; + } - tl_num = (bm.bmWidth/iflags.wc_tile_width)* - (bm.bmHeight/iflags.wc_tile_height); - if( tl_numbmpMapTiles!=GetNHApp()->bmpTiles ) { - DeleteObject(GetNHApp()->bmpMapTiles); - } + /* set the tile information */ + if (GetNHApp()->bmpMapTiles != GetNHApp()->bmpTiles) { + DeleteObject(GetNHApp()->bmpMapTiles); + } - GetNHApp()->bmpMapTiles = hBmp; - GetNHApp()->mapTile_X = iflags.wc_tile_width; - GetNHApp()->mapTile_Y = iflags.wc_tile_height; - GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; + GetNHApp()->bmpMapTiles = hBmp; + GetNHApp()->mapTile_X = iflags.wc_tile_width; + GetNHApp()->mapTile_Y = iflags.wc_tile_height; + GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; - map_size.cx = GetNHApp()->mapTile_X * COLNO; - map_size.cy = GetNHApp()->mapTile_Y * ROWNO; - mswin_map_stretch( - mswin_hwnd_from_winid(WIN_MAP), - &map_size, - TRUE - ); - return TRUE; + map_size.cx = GetNHApp()->mapTile_X * COLNO; + map_size.cy = GetNHApp()->mapTile_Y * ROWNO; + mswin_map_stretch(mswin_hwnd_from_winid(WIN_MAP), &map_size, TRUE); + return TRUE; } -void mswin_popup_display(HWND hWnd, int* done_indicator) +void +mswin_popup_display(HWND hWnd, int *done_indicator) { - MSG msg; - HWND hChild; + MSG msg; + HWND hChild; - /* activate the menu window */ - GetNHApp()->hPopupWnd = hWnd; + /* activate the menu window */ + GetNHApp()->hPopupWnd = hWnd; - mswin_layout_main_window(hWnd); + mswin_layout_main_window(hWnd); - /* disable game windows */ - for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD); - hChild; - hChild = GetWindow(hChild, GW_HWNDNEXT) ) { - if( hChild!=hWnd ) EnableWindow(hChild, FALSE); - } + /* disable game windows */ + for (hChild = GetWindow(GetNHApp()->hMainWnd, GW_CHILD); hChild; + hChild = GetWindow(hChild, GW_HWNDNEXT)) { + if (hChild != hWnd) + EnableWindow(hChild, FALSE); + } #if defined(WIN_CE_SMARTPHONE) - ShowWindow(GetNHApp()->hMenuBar, SW_HIDE); - ShowWindow(SHFindMenuBar(hWnd), SW_SHOW); + ShowWindow(GetNHApp()->hMenuBar, SW_HIDE); + ShowWindow(SHFindMenuBar(hWnd), SW_SHOW); #else - EnableWindow(GetNHApp()->hMenuBar, FALSE); + EnableWindow(GetNHApp()->hMenuBar, FALSE); #endif - /* bring menu window on top */ - SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + /* bring menu window on top */ + SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); - /* go into message loop */ - if( done_indicator ) *done_indicator = 0; - while( IsWindow(hWnd) && - (done_indicator==NULL || !*done_indicator) && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if( !IsDialogMessage(hWnd, &msg) ) { - if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - } + /* go into message loop */ + if (done_indicator) + *done_indicator = 0; + while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator) + && GetMessage(&msg, NULL, 0, 0) != 0) { + if (!IsDialogMessage(hWnd, &msg)) { + if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, + &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } } -void mswin_popup_destroy(HWND hWnd) +void +mswin_popup_destroy(HWND hWnd) { - HWND hChild; + HWND hChild; - /* enable game windows */ - for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD); - hChild; - hChild = GetWindow(hChild, GW_HWNDNEXT) ) { - if( hChild!= hWnd) { - EnableWindow(hChild, TRUE); - } - } + /* enable game windows */ + for (hChild = GetWindow(GetNHApp()->hMainWnd, GW_CHILD); hChild; + hChild = GetWindow(hChild, GW_HWNDNEXT)) { + if (hChild != hWnd) { + EnableWindow(hChild, TRUE); + } + } #if defined(WIN_CE_SMARTPHONE) - ShowWindow(SHFindMenuBar(hWnd), SW_HIDE); - ShowWindow(GetNHApp()->hMenuBar, SW_SHOW); + ShowWindow(SHFindMenuBar(hWnd), SW_HIDE); + ShowWindow(GetNHApp()->hMenuBar, SW_SHOW); #else - EnableWindow(GetNHApp()->hMenuBar, TRUE); + EnableWindow(GetNHApp()->hMenuBar, TRUE); #endif - SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); - GetNHApp()->hPopupWnd = NULL; - mswin_window_mark_dead( mswin_winid_from_handle(hWnd) ); - DestroyWindow(hWnd); + SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); + GetNHApp()->hPopupWnd = NULL; + mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); + DestroyWindow(hWnd); - mswin_layout_main_window(hWnd); + mswin_layout_main_window(hWnd); - SetFocus(GetNHApp()->hMainWnd ); + SetFocus(GetNHApp()->hMainWnd); } -void mswin_set_fullscreen(BOOL is_fullscreen) +void +mswin_set_fullscreen(BOOL is_fullscreen) { #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - SetForegroundWindow(GetNHApp()->hMainWnd); - if( is_fullscreen ) { - SHFullScreen(GetNHApp()->hMainWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); - MoveWindow( - GetNHApp()->hMainWnd, - 0, - 0, - GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN), - FALSE - ); - } else { - RECT rc; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - SHFullScreen(GetNHApp()->hMainWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); - MoveWindow( - GetNHApp()->hMainWnd, - rc.left, - rc.top, - rc.right - rc.left, - rc.bottom - rc.top, - FALSE - ); - } - GetNHApp()->bFullScreen = is_fullscreen; + SetForegroundWindow(GetNHApp()->hMainWnd); + if (is_fullscreen) { + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); + MoveWindow(GetNHApp()->hMainWnd, 0, 0, GetSystemMetrics(SM_CXSCREEN), + GetSystemMetrics(SM_CYSCREEN), FALSE); + } else { + RECT rc; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + SHFullScreen(GetNHApp()->hMainWnd, + SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); + MoveWindow(GetNHApp()->hMainWnd, rc.left, rc.top, rc.right - rc.left, + rc.bottom - rc.top, FALSE); + } + GetNHApp()->bFullScreen = is_fullscreen; #else - GetNHApp()->bFullScreen = FALSE; + GetNHApp()->bFullScreen = FALSE; #endif } #if defined(WIN_CE_SMARTPHONE) -void NHSPhoneDialogSetup(HWND hDlg, UINT nToolBarId, BOOL is_edit, BOOL is_fullscreen) +void +NHSPhoneDialogSetup(HWND hDlg, UINT nToolBarId, BOOL is_edit, + BOOL is_fullscreen) { SHMENUBARINFO mbi; - HWND hOK, hCancel; - RECT rtOK, rtDlg; + HWND hOK, hCancel; + RECT rtOK, rtDlg; - // Create our MenuBar + // Create our MenuBar ZeroMemory(&mbi, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(mbi); mbi.hwndParent = hDlg; mbi.nToolBarId = nToolBarId; mbi.hInstRes = GetNHApp()->hApp; - if(!SHCreateMenuBar(&mbi)) { - error("cannot create dialog menu"); - } + if (!SHCreateMenuBar(&mbi)) { + error("cannot create dialog menu"); + } - if(is_fullscreen) { - SHINITDLGINFO shidi; - RECT main_wnd_rect; - shidi.dwMask = SHIDIM_FLAGS; - shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; - shidi.hDlg = hDlg; - SHInitDialog(&shidi); + if (is_fullscreen) { + SHINITDLGINFO shidi; + RECT main_wnd_rect; + shidi.dwMask = SHIDIM_FLAGS; + shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; + shidi.hDlg = hDlg; + SHInitDialog(&shidi); - GetWindowRect(GetNHApp()->hMainWnd, &main_wnd_rect); - MoveWindow( - hDlg, - main_wnd_rect.left, - main_wnd_rect.top, - main_wnd_rect.right - main_wnd_rect.left, - main_wnd_rect.bottom - main_wnd_rect.top, - FALSE - ); - } + GetWindowRect(GetNHApp()->hMainWnd, &main_wnd_rect); + MoveWindow(hDlg, main_wnd_rect.left, main_wnd_rect.top, + main_wnd_rect.right - main_wnd_rect.left, + main_wnd_rect.bottom - main_wnd_rect.top, FALSE); + } - /* hide OK and CANCEL buttons */ - hOK = GetDlgItem(hDlg, IDOK); - hCancel = GetDlgItem(hDlg, IDCANCEL); + /* hide OK and CANCEL buttons */ + hOK = GetDlgItem(hDlg, IDOK); + hCancel = GetDlgItem(hDlg, IDCANCEL); - if( IsWindow(hCancel) ) ShowWindow(hCancel, SW_HIDE); - if( IsWindow(hOK) ) { - GetWindowRect(hOK, &rtOK); - GetWindowRect(hDlg, &rtDlg); + if (IsWindow(hCancel)) + ShowWindow(hCancel, SW_HIDE); + if (IsWindow(hOK)) { + GetWindowRect(hOK, &rtOK); + GetWindowRect(hDlg, &rtDlg); - rtDlg.bottom -= rtOK.bottom-rtOK.top; - ShowWindow(hOK, SW_HIDE); - SetWindowPos( hDlg, HWND_TOP, - 0, 0, - rtDlg.right-rtDlg.left, rtDlg.bottom-rtDlg.top, - SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER ); - } + rtDlg.bottom -= rtOK.bottom - rtOK.top; + ShowWindow(hOK, SW_HIDE); + SetWindowPos(hDlg, HWND_TOP, 0, 0, rtDlg.right - rtDlg.left, + rtDlg.bottom - rtDlg.top, + SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER); + } - /* override "Back" button for edit box dialogs */ - if( is_edit ) - SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY)); + /* override "Back" button for edit box dialogs */ + if (is_edit) + SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, + MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, + SHMBOF_NODEFAULT | SHMBOF_NOTIFY)); } #endif /* defined(WIN_CE_SMARTPHONE) */ -void mswin_read_reg(void) +void +mswin_read_reg(void) { } -void mswin_destroy_reg(void) +void +mswin_destroy_reg(void) { } -void mswin_write_reg(void) +void +mswin_write_reg(void) { } -/* check HKCU\Software\\Microsoft\\Shell\HasKeyboard for keyboard presence, +/* check HKCU\Software\\Microsoft\\Shell\HasKeyboard for keyboard presence, if the key is not there assume older device and no keyboard */ -BOOL mswin_has_keyboard(void) +BOOL +mswin_has_keyboard(void) { - DWORD dwHasKB = 0; + DWORD dwHasKB = 0; #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) - HKEY hKey; - DWORD dwType; - DWORD dwSize = sizeof(dwHasKB); - if( RegOpenKeyEx(HKEY_CURRENT_USER , _T("Software\\Microsoft\\Shell"), 0, 0, &hKey)==ERROR_SUCCESS) { - if( RegQueryValueEx(hKey, _T("HasKeyboard"), NULL, &dwType, (LPBYTE)&dwHasKB, &dwSize)!=ERROR_SUCCESS) { - dwHasKB = 0; - } - RegCloseKey(hKey); - } + HKEY hKey; + DWORD dwType; + DWORD dwSize = sizeof(dwHasKB); + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Shell"), 0, + 0, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueEx(hKey, _T("HasKeyboard"), NULL, &dwType, + (LPBYTE) &dwHasKB, &dwSize) != ERROR_SUCCESS) { + dwHasKB = 0; + } + RegCloseKey(hKey); + } #endif - return (dwHasKB==1); + return (dwHasKB == 1); } #ifdef _DEBUG @@ -1984,17 +1986,16 @@ BOOL mswin_has_keyboard(void) void logDebug(const char *fmt, ...) { - FILE *dfp = fopen("nhtrace.log", "a"); + FILE *dfp = fopen("nhtrace.log", "a"); - if (dfp) { - va_list args; + if (dfp) { + va_list args; - va_start(args, fmt); - vfprintf(dfp, fmt, args); - va_end(args); - fclose(dfp); - } + va_start(args, fmt); + vfprintf(dfp, fmt, args); + va_end(args); + fclose(dfp); + } } #endif - diff --git a/sys/wince/winhack.c b/sys/wince/winhack.c index 5b3c02b47..187ca032e 100644 --- a/sys/wince/winhack.c +++ b/sys/wince/winhack.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winhack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winhack.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */ /* NetHack 3.6 winhack.c $Date: 2009/10/22 02:59:35 $ $Revision: 1.11 $ */ /* Copyright (C) 2001 by Alex Kompel */ // winhack.cpp : Defines the entry point for the application. @@ -10,125 +10,128 @@ #include "mhmain.h" #include "mhmap.h" -extern char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */ +extern char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */ -extern void FDECL(nethack_exit,(int)); -static TCHAR* _get_cmd_arg(TCHAR* pCmdLine); +extern void FDECL(nethack_exit, (int)); +static TCHAR *_get_cmd_arg(TCHAR *pCmdLine); // Global Variables: NHWinApp _nethack_app; // Foward declarations of functions included in this code module: -BOOL InitInstance(HINSTANCE, int); +BOOL InitInstance(HINSTANCE, int); static void win_hack_init(int, char **); static void __cdecl mswin_moveloop(void *); -static BOOL setMapTiles(const char* fname); +static BOOL setMapTiles(const char *fname); -extern boolean FDECL(pcmain, (int,char **)); +extern boolean FDECL(pcmain, (int, char **)); #define MAX_CMDLINE_PARAM 255 -int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPWSTR lpCmdLine, - int nCmdShow) +int APIENTRY +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, + int nCmdShow) { - INITCOMMONCONTROLSEX InitCtrls; - HWND nethackWnd; - int argc; - char* argv[MAX_CMDLINE_PARAM]; - size_t len; - TCHAR* p; - TCHAR wbuf[NHSTR_BUFSIZE]; - char buf[NHSTR_BUFSIZE]; + INITCOMMONCONTROLSEX InitCtrls; + HWND nethackWnd; + int argc; + char *argv[MAX_CMDLINE_PARAM]; + size_t len; + TCHAR *p; + TCHAR wbuf[NHSTR_BUFSIZE]; + char buf[NHSTR_BUFSIZE]; boolean resuming; - sys_early_init(); + sys_early_init(); - /* ensure that we don't access violate on a panic() */ - windowprocs.win_raw_print = mswin_raw_print; - windowprocs.win_raw_print_bold = mswin_raw_print_bold; + /* ensure that we don't access violate on a panic() */ + windowprocs.win_raw_print = mswin_raw_print; + windowprocs.win_raw_print_bold = mswin_raw_print_bold; - /* init applicatio structure */ - _nethack_app.hApp = hInstance; - _nethack_app.nCmdShow = nCmdShow; - _nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINHACK); - _nethack_app.hMainWnd = NULL; - _nethack_app.hPopupWnd = NULL; - _nethack_app.hMenuBar = NULL; - _nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES)); - if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap"); - _nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK)); - if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap"); - _nethack_app.bmpMapTiles = _nethack_app.bmpTiles; - _nethack_app.mapTile_X = TILE_X; - _nethack_app.mapTile_Y = TILE_Y; - _nethack_app.mapTilesPerLine = TILES_PER_LINE; - _nethack_app.bNoHScroll = FALSE; - _nethack_app.bNoVScroll = FALSE; + /* init applicatio structure */ + _nethack_app.hApp = hInstance; + _nethack_app.nCmdShow = nCmdShow; + _nethack_app.hAccelTable = + LoadAccelerators(hInstance, (LPCTSTR) IDC_WINHACK); + _nethack_app.hMainWnd = NULL; + _nethack_app.hPopupWnd = NULL; + _nethack_app.hMenuBar = NULL; + _nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES)); + if (_nethack_app.bmpTiles == NULL) + panic("cannot load tiles bitmap"); + _nethack_app.bmpPetMark = + LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK)); + if (_nethack_app.bmpPetMark == NULL) + panic("cannot load pet mark bitmap"); + _nethack_app.bmpMapTiles = _nethack_app.bmpTiles; + _nethack_app.mapTile_X = TILE_X; + _nethack_app.mapTile_Y = TILE_Y; + _nethack_app.mapTilesPerLine = TILES_PER_LINE; + _nethack_app.bNoHScroll = FALSE; + _nethack_app.bNoVScroll = FALSE; - _nethack_app.bCmdPad = !mswin_has_keyboard(); + _nethack_app.bCmdPad = !mswin_has_keyboard(); - _nethack_app.bWrapText = TRUE; - _nethack_app.bFullScreen = TRUE; + _nethack_app.bWrapText = TRUE; + _nethack_app.bFullScreen = TRUE; #if defined(WIN_CE_SMARTPHONE) - _nethack_app.bHideScrollBars = TRUE; + _nethack_app.bHideScrollBars = TRUE; #else - _nethack_app.bHideScrollBars = FALSE; + _nethack_app.bHideScrollBars = FALSE; #endif - _nethack_app.bUseSIP = TRUE; + _nethack_app.bUseSIP = TRUE; - // check for running nethack programs - nethackWnd = FindWindow(szMainWindowClass, NULL); - if( nethackWnd ) { - // bring on top - SetForegroundWindow(nethackWnd); - return FALSE; - } + // check for running nethack programs + nethackWnd = FindWindow(szMainWindowClass, NULL); + if (nethackWnd) { + // bring on top + SetForegroundWindow(nethackWnd); + return FALSE; + } - // init controls - ZeroMemory(&InitCtrls, sizeof(InitCtrls)); - InitCtrls.dwSize = sizeof(InitCtrls); - InitCtrls.dwICC = ICC_LISTVIEW_CLASSES; - if( !InitCommonControlsEx(&InitCtrls) ) { - MessageBox(NULL, TEXT("Cannot init common controls"), TEXT("ERROR"), MB_OK | MB_ICONSTOP); - return FALSE; - } + // init controls + ZeroMemory(&InitCtrls, sizeof(InitCtrls)); + InitCtrls.dwSize = sizeof(InitCtrls); + InitCtrls.dwICC = ICC_LISTVIEW_CLASSES; + if (!InitCommonControlsEx(&InitCtrls)) { + MessageBox(NULL, TEXT("Cannot init common controls"), TEXT("ERROR"), + MB_OK | MB_ICONSTOP); + return FALSE; + } - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { - return FALSE; - } + // Perform application initialization: + if (!InitInstance(hInstance, nCmdShow)) { + return FALSE; + } - /* get command line parameters */ - p = _get_cmd_arg( + /* get command line parameters */ + p = _get_cmd_arg( #if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO) - lpCmdLine + lpCmdLine #else - GetCommandLine() + GetCommandLine() #endif - ); - for( argc = 1; p && argc0 ) { - argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) ); - } else { - argv[argc] = ""; - } - p = _get_cmd_arg(NULL); - } - GetModuleFileName(NULL, wbuf, BUFSZ); - argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); + ); + for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) { + len = _tcslen(p); + if (len > 0) { + argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ)); + } else { + argv[argc] = ""; + } + p = _get_cmd_arg(NULL); + } + GetModuleFileName(NULL, wbuf, BUFSZ); + argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); - resuming = pcmain(argc,argv); + resuming = pcmain(argc, argv); - moveloop(resuming); + moveloop(resuming); - return 0; + return 0; } // @@ -138,218 +141,214 @@ int APIENTRY WinMain(HINSTANCE hInstance, // // COMMENTS: // -// In this function, we save the instance handle in a global variable and +// In this function, we save the instance handle in a global variable +// and // create and display the main program window. // -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +BOOL +InitInstance(HINSTANCE hInstance, int nCmdShow) { - return TRUE; + return TRUE; } -PNHWinApp GetNHApp() +PNHWinApp +GetNHApp() { - return &_nethack_app; + return &_nethack_app; } static int eraseoldlocks() { - register int i; + register int i; - /* cannot use maxledgerno() here, because we need to find a lock name - * before starting everything (including the dungeon initialization - * that sets astral_level, needed for maxledgerno()) up - */ - for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) { - /* try to remove all */ - set_levelfile_name(lock, i); - (void) unlink(fqname(lock, LEVELPREFIX, 0)); - } - set_levelfile_name(lock, 0); - if(unlink(fqname(lock, LEVELPREFIX, 0))) - return 0; /* cannot remove it */ - return(1); /* success! */ + /* cannot use maxledgerno() here, because we need to find a lock name + * before starting everything (including the dungeon initialization + * that sets astral_level, needed for maxledgerno()) up + */ + for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { + /* try to remove all */ + set_levelfile_name(lock, i); + (void) unlink(fqname(lock, LEVELPREFIX, 0)); + } + set_levelfile_name(lock, 0); + if (unlink(fqname(lock, LEVELPREFIX, 0))) + return 0; /* cannot remove it */ + return (1); /* success! */ } void getlock() { - const char *fq_lock; - char tbuf[BUFSZ]; - TCHAR wbuf[BUFSZ]; - HANDLE f; - int fd; - int choice; + const char *fq_lock; + char tbuf[BUFSZ]; + TCHAR wbuf[BUFSZ]; + HANDLE f; + int fd; + int choice; - /* regularize(lock); */ /* already done in pcmain */ - Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); - set_levelfile_name(lock, 0); - fq_lock = fqname(lock, LEVELPREFIX, 1); + /* regularize(lock); */ /* already done in pcmain */ + Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); + set_levelfile_name(lock, 0); + fq_lock = fqname(lock, LEVELPREFIX, 1); - f = CreateFile( - NH_A2W(fq_lock, wbuf, BUFSZ), - GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if( f==INVALID_HANDLE_VALUE ) { - if(GetLastError()==ERROR_FILE_NOT_FOUND) goto gotlock; /* no such file */ - error("Cannot open %s", fq_lock); - } + f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (f == INVALID_HANDLE_VALUE) { + if (GetLastError() == ERROR_FILE_NOT_FOUND) + goto gotlock; /* no such file */ + error("Cannot open %s", fq_lock); + } - CloseHandle(f); + CloseHandle(f); - /* prompt user that the game alredy exist */ - choice = MessageBox( - GetNHApp()->hMainWnd, - TEXT("There are files from a game in progress under your name. Recover?"), - TEXT("Nethack"), - MB_YESNO | MB_DEFBUTTON1 - ); - switch(choice) { - case IDYES: - if(recover_savefile()) { - goto gotlock; - } else { - error("Couldn't recover old game."); - } - break; + /* prompt user that the game alredy exist */ + choice = MessageBox(GetNHApp()->hMainWnd, + TEXT("There are files from a game in progress under " + "your name. Recover?"), + TEXT("Nethack"), MB_YESNO | MB_DEFBUTTON1); + switch (choice) { + case IDYES: + if (recover_savefile()) { + goto gotlock; + } else { + error("Couldn't recover old game."); + } + break; - case IDNO: - unlock_file(HLOCK); - error("%s", "Cannot start a new game."); - break; - }; + case IDNO: + unlock_file(HLOCK); + error("%s", "Cannot start a new game."); + break; + }; gotlock: - fd = creat(fq_lock, FCMASK); - if(fd == -1) { - error("cannot creat lock file (%s.)", fq_lock); - } else { - if(write(fd, (char *) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ - error("cannot write lock (%s)", fq_lock); - } - if(close(fd) == -1) { - error("cannot close lock (%s)", fq_lock); - } - } + fd = creat(fq_lock, FCMASK); + if (fd == -1) { + error("cannot creat lock file (%s.)", fq_lock); + } else { + if (write(fd, (char *) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { + error("cannot write lock (%s)", fq_lock); + } + if (close(fd) == -1) { + error("cannot close lock (%s)", fq_lock); + } + } } /* misc functions */ -void -error VA_DECL(const char *,s) - TCHAR wbuf[1024]; - char buf[1024]; - DWORD last_error = GetLastError(); +void error +VA_DECL(const char *, s) + TCHAR wbuf[1024]; + char buf[1024]; + DWORD last_error = GetLastError(); - VA_START(s); - VA_INIT(s, const char *); - /* error() may get called before tty is initialized */ - if (iflags.window_inited) end_screen(); - - vsprintf(buf, s, VA_ARGS); - NH_A2W(buf, wbuf, sizeof(wbuf)/sizeof(wbuf[0])); - if( last_error>0 ) { - LPVOID lpMsgBuf; - if( FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - last_error, - 0, // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ) - ) - { - - _tcsncat(wbuf, TEXT("\nSystem Error: "), sizeof(wbuf)/sizeof(wbuf[0]) - _tcslen(wbuf) ); - _tcsncat(wbuf, lpMsgBuf, sizeof(wbuf)/sizeof(wbuf[0]) - _tcslen(wbuf) ); + VA_START(s); + VA_INIT(s, const char *); + /* error() may get called before tty is initialized */ + if (iflags.window_inited) + end_screen(); - // Free the buffer. - LocalFree( lpMsgBuf ); - } - } - VA_END(); + vsprintf(buf, s, VA_ARGS); + NH_A2W(buf, wbuf, sizeof(wbuf) / sizeof(wbuf[0])); + if (last_error > 0) { + LPVOID lpMsgBuf; + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, last_error, + 0, // Default language + (LPTSTR) &lpMsgBuf, 0, NULL)) { + _tcsncat(wbuf, TEXT("\nSystem Error: "), + sizeof(wbuf) / sizeof(wbuf[0]) - _tcslen(wbuf)); + _tcsncat(wbuf, lpMsgBuf, + sizeof(wbuf) / sizeof(wbuf[0]) - _tcslen(wbuf)); - MessageBox( NULL, wbuf, TEXT("Error"), MB_OK | MB_ICONERROR ); - - exit(EXIT_FAILURE); + // Free the buffer. + LocalFree(lpMsgBuf); + } + } + VA_END(); + + MessageBox(NULL, wbuf, TEXT("Error"), MB_OK | MB_ICONERROR); + + exit(EXIT_FAILURE); } -TCHAR* _get_cmd_arg(TCHAR* pCmdLine) +TCHAR * +_get_cmd_arg(TCHAR *pCmdLine) { - static TCHAR* pArgs = NULL; - TCHAR *pRetArg; - BOOL bQuoted; + static TCHAR *pArgs = NULL; + TCHAR *pRetArg; + BOOL bQuoted; - if( !pCmdLine && !pArgs ) return NULL; - if( !pArgs ) pArgs = pCmdLine; + if (!pCmdLine && !pArgs) + return NULL; + if (!pArgs) + pArgs = pCmdLine; /* skip whitespace */ - for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg)); - if( !*pRetArg ) { - pArgs = NULL; - return NULL; - } + for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); + pRetArg = CharNext(pRetArg)) + ; + if (!*pRetArg) { + pArgs = NULL; + return NULL; + } /* check for quote */ - if( *pRetArg==TEXT('"') ) { - bQuoted = TRUE; - pRetArg = CharNext(pRetArg); - pArgs = _tcschr(pRetArg, TEXT('"')); - } else { - /* skip to whitespace */ - for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs)); - } - - if( pArgs && *pArgs ) { - TCHAR* p; - p = pArgs; - pArgs = CharNext(pArgs); - *p = (TCHAR)0; - } else { - pArgs = NULL; - } + if (*pRetArg == TEXT('"')) { + bQuoted = TRUE; + pRetArg = CharNext(pRetArg); + pArgs = _tcschr(pRetArg, TEXT('"')); + } else { + /* skip to whitespace */ + for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs); + pArgs = CharNext(pArgs)) + ; + } - return pRetArg; + if (pArgs && *pArgs) { + TCHAR *p; + p = pArgs; + pArgs = CharNext(pArgs); + *p = (TCHAR) 0; + } else { + pArgs = NULL; + } + + return pRetArg; } -/* +/* * Strip out troublesome file system characters. */ -void -nt_regularize(s) /* normalize file name */ +void nt_regularize(s) /* normalize file name */ register char *s; { - register unsigned char *lp; + register unsigned char *lp; - for (lp = s; *lp; lp++) - if ( *lp == '?' || *lp == '"' || *lp == '\\' || - *lp == '/' || *lp == '>' || *lp == '<' || - *lp == '*' || *lp == '|' || *lp == ':' || (*lp > 127)) - *lp = '_'; + for (lp = s; *lp; lp++) + if (*lp == '?' || *lp == '"' || *lp == '\\' || *lp == '/' + || *lp == '>' || *lp == '<' || *lp == '*' || *lp == '|' + || *lp == ':' || (*lp > 127)) + *lp = '_'; } -void win32_abort() +void +win32_abort() { - - if (wizard) - DebugBreak(); - abort(); + if (wizard) + DebugBreak(); + abort(); } void append_port_id(buf) char *buf; { - char *portstr = PORT_CE_PLATFORM " " PORT_CE_CPU; - Sprintf(eos(buf), " %s", portstr); + char *portstr = PORT_CE_PLATFORM " " PORT_CE_CPU; + Sprintf(eos(buf), " %s", portstr); } - diff --git a/sys/wince/winmain.c b/sys/wince/winmain.c index 1d1a29a4b..c4e6a49dd 100644 --- a/sys/wince/winmain.c +++ b/sys/wince/winmain.c @@ -1,6 +1,6 @@ // winmain.cpp : Defines the entry point for the application. // -// $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ +// $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ // $Date: 2002/12/18 03:51:34 $ $Revision: 1.2 $ #include "winMS.h" @@ -8,106 +8,113 @@ #define MAX_CMDLINE_PARAM 255 -extern int FDECL (main, (int,char **)); -static TCHAR* _get_cmd_arg(TCHAR* pCmdLine); +extern int FDECL(main, (int, char **)); +static TCHAR *_get_cmd_arg(TCHAR *pCmdLine); -int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPWSTR lpCmdLine, - int nCmdShow) +int APIENTRY +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, + int nCmdShow) { - int argc; - char* argv[MAX_CMDLINE_PARAM]; - size_t len; - TCHAR* p; - TCHAR wbuf[NHSTR_BUFSIZE]; - char buf[NHSTR_BUFSIZE]; + int argc; + char *argv[MAX_CMDLINE_PARAM]; + size_t len; + TCHAR *p; + TCHAR wbuf[NHSTR_BUFSIZE]; + char buf[NHSTR_BUFSIZE]; - /* get command line parameters */ - p = _get_cmd_arg( + /* get command line parameters */ + p = _get_cmd_arg( #if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO) - lpCmdLine + lpCmdLine #else - GetCommandLine() + GetCommandLine() #endif - ); - for( argc = 1; p && argc0 ) { - argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) ); - } else { - argv[argc] = ""; - } - p = _get_cmd_arg(NULL); - } - GetModuleFileName(NULL, wbuf, BUFSZ); - argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); + ); + for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) { + len = _tcslen(p); + if (len > 0) { + argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ)); + } else { + argv[argc] = ""; + } + p = _get_cmd_arg(NULL); + } + GetModuleFileName(NULL, wbuf, BUFSZ); + argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); - main(argc, argv); + main(argc, argv); - return 0; + return 0; } -TCHAR* _get_cmd_arg(TCHAR* pCmdLine) +TCHAR * +_get_cmd_arg(TCHAR *pCmdLine) { - static TCHAR* pArgs = NULL; - TCHAR *pRetArg; - BOOL bQuoted; + static TCHAR *pArgs = NULL; + TCHAR *pRetArg; + BOOL bQuoted; - if( !pCmdLine && !pArgs ) return NULL; - if( !pArgs ) pArgs = pCmdLine; + if (!pCmdLine && !pArgs) + return NULL; + if (!pArgs) + pArgs = pCmdLine; /* skip whitespace */ - for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg)); - if( !*pRetArg ) { - pArgs = NULL; - return NULL; - } + for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); + pRetArg = CharNext(pRetArg)) + ; + if (!*pRetArg) { + pArgs = NULL; + return NULL; + } /* check for quote */ - if( *pRetArg==TEXT('"') ) { + if (*pRetArg == TEXT('"')) { bQuoted = TRUE; pRetArg = CharNext(pRetArg); - pArgs = _tcschr(pRetArg, TEXT('"')); - } else { - /* skip to whitespace */ - for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs)); - } - - if( pArgs && *pArgs ) { - TCHAR* p; - p = pArgs; - pArgs = CharNext(pArgs); - *p = (TCHAR)0; - } else { - pArgs = NULL; - } + pArgs = _tcschr(pRetArg, TEXT('"')); + } else { + /* skip to whitespace */ + for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs); + pArgs = CharNext(pArgs)) + ; + } - return pRetArg; + if (pArgs && *pArgs) { + TCHAR *p; + p = pArgs; + pArgs = CharNext(pArgs); + *p = (TCHAR) 0; + } else { + pArgs = NULL; + } + + return pRetArg; } #ifndef STRNCMPI -char -lowc(c) /* force 'c' into lowercase */ - char c; +char lowc(c) /* force 'c' into lowercase */ +char c; { - return((char)(('A' <= c && c <= 'Z') ? (c | 040) : c)); + return ((char) (('A' <= c && c <= 'Z') ? (c | 040) : c)); } -int -strncmpi(s1, s2, n) /* case insensitive counted string comparison */ - register const char *s1, *s2; - register int n; /*(should probably be size_t, which is usually unsigned)*/ -{ /*{ aka strncasecmp }*/ +int strncmpi(s1, s2, n) /* case insensitive counted string comparison */ +register const char *s1, *s2; +register int n; /*(should probably be size_t, which is usually unsigned)*/ +{ /*{ aka strncasecmp }*/ register char t1, t2; while (n--) { - if (!*s2) return (*s1 != 0); /* s1 >= s2 */ - else if (!*s1) return -1; /* s1 < s2 */ - t1 = lowc(*s1++); - t2 = lowc(*s2++); - if (t1 != t2) return (t1 > t2) ? 1 : -1; + if (!*s2) + return (*s1 != 0); /* s1 >= s2 */ + else if (!*s1) + return -1; /* s1 < s2 */ + t1 = lowc(*s1++); + t2 = lowc(*s2++); + if (t1 != t2) + return (t1 > t2) ? 1 : -1; } - return 0; /* s1 == s2 */ + return 0; /* s1 == s2 */ } -#endif /* STRNCMPI */ +#endif /* STRNCMPI */ diff --git a/sys/winnt/nh340key.c b/sys/winnt/nh340key.c index c1ac1bd09..fbc733935 100644 --- a/sys/winnt/nh340key.c +++ b/sys/winnt/nh340key.c @@ -1,6 +1,6 @@ -/* NetHack 3.6 nh340key.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 nh340key.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 nh340key.c $Date: 2009/05/06 10:53:29 $ $Revision: 1.7 $ */ -/* SCCS Id: @(#)nh340key.c 3.5 $NHDT-Date$ */ +/* SCCS Id: @(#)nh340key.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */ /* SCCS Id: @(#)nh340key.c 3.5 $Date: 2009/05/06 10:53:29 $ */ /* Copyright (c) NetHack PC Development Team 2003 */ /* NetHack may be freely redistributed. See license for details. */ @@ -25,22 +25,23 @@ extern INPUT_RECORD ir; char dllname[512]; char *shortdllname; -int FDECL(__declspec(dllexport) __stdcall -ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir, - boolean *valid, BOOLEAN_P numberpad, int portdebug)); +int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke, + (HANDLE hConIn, INPUT_RECORD *ir, boolean *valid, + BOOLEAN_P numberpad, int portdebug)); -int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) +int WINAPI +DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { - char dlltmpname[512]; - char *tmp = dlltmpname, *tmp2; - *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; - (void)strcpy(dllname, tmp); - tmp2 = strrchr(dllname, '\\'); - if (tmp2) { - tmp2++; - shortdllname = tmp2; - } - return TRUE; + char dlltmpname[512]; + char *tmp = dlltmpname, *tmp2; + *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; + (void) strcpy(dllname, tmp); + tmp2 = strrchr(dllname, '\\'); + if (tmp2) { + tmp2++; + shortdllname = tmp2; + } + return TRUE; } /* @@ -48,11 +49,11 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) * (Adopted from the MSDOS port) */ -#define KEYPADLO 0x47 -#define KEYPADHI 0x53 +#define KEYPADLO 0x47 +#define KEYPADHI 0x53 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -61,250 +62,258 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) */ static const struct pad { - uchar normal, shift, cntrl; -} keypad[PADKEYS] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + uchar normal, shift, cntrl; +} keypad[PADKEYS] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; -#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') +#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') -int __declspec(dllexport) __stdcall -ProcessKeystroke(hConIn, ir, valid, numberpad, portdebug) +int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid, + numberpad, portdebug) HANDLE hConIn; INPUT_RECORD *ir; boolean *valid; boolean numberpad; int portdebug; { - int metaflags = 0, k = 0; - int keycode, vk; - unsigned char ch, pre_ch, mk = 0; - unsigned short int scan; - unsigned long shiftstate; - int altseq = 0; - const struct pad *kpad; + int metaflags = 0, k = 0; + int keycode, vk; + unsigned char ch, pre_ch, mk = 0; + unsigned short int scan; + unsigned long shiftstate; + int altseq = 0; + const struct pad *kpad; - shiftstate = 0L; - ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - shiftstate = ir->Event.KeyEvent.dwControlKeyState; + shiftstate = 0L; + ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + shiftstate = ir->Event.KeyEvent.dwControlKeyState; - if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || (iskeypad(scan)) || (altseq > 0)) - *valid = TRUE; - /* if (!valid) return 0; */ - /* - * shiftstate can be checked to see if various special - * keys were pressed at the same time as the key. - * Currently we are using the ALT & SHIFT & CONTROLS. - * - * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, - * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, - * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, - * CAPSLOCK_ON, ENHANCED_KEY - * - * are all valid bit masks to use on shiftstate. - * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the - * left control key was pressed with the keystroke. - */ - if (iskeypad(scan)) { - kpad = numberpad ? numpad : keypad; - if (shiftstate & SHIFT_PRESSED) { - ch = kpad[scan - KEYPADLO].shift; - } - else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { - ch = kpad[scan - KEYPADLO].cntrl; - } - else { - ch = kpad[scan - KEYPADLO].normal; - } + if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || (iskeypad(scan)) || (altseq > 0)) + *valid = TRUE; + /* if (!valid) return 0; */ + /* + * shiftstate can be checked to see if various special + * keys were pressed at the same time as the key. + * Currently we are using the ALT & SHIFT & CONTROLS. + * + * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, + * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, + * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, + * CAPSLOCK_ON, ENHANCED_KEY + * + * are all valid bit masks to use on shiftstate. + * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the + * left control key was pressed with the keystroke. + */ + if (iskeypad(scan)) { + kpad = numberpad ? numpad : keypad; + if (shiftstate & SHIFT_PRESSED) { + ch = kpad[scan - KEYPADLO].shift; + } else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { + ch = kpad[scan - KEYPADLO].cntrl; + } else { + ch = kpad[scan - KEYPADLO].normal; } - else if (altseq > 0) { /* ALT sequence */ - if (vk == 0xBF) ch = M('?'); - else ch = M(tolower(keycode)); - } - if (ch == '\r') ch = '\n'; + } else if (altseq > 0) { /* ALT sequence */ + if (vk == 0xBF) + ch = M('?'); + else + ch = M(tolower(keycode)); + } + if (ch == '\r') + ch = '\n'; #ifdef PORT_DEBUG - if (portdebug) { - char buf[BUFSZ]; - Sprintf(buf, - "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, sh=0x%X (ESC to end)", - shortdllname, ch, scan, vk, shiftstate); - fprintf(stdout, "\n%s", buf); - } + if (portdebug) { + char buf[BUFSZ]; + Sprintf(buf, + "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, sh=0x%X (ESC to end)", + shortdllname, ch, scan, vk, shiftstate); + fprintf(stdout, "\n%s", buf); + } #endif - return ch; + return ch; } -int __declspec(dllexport) __stdcall -NHkbhit(hConIn, ir) +int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir) HANDLE hConIn; INPUT_RECORD *ir; { - int done = 0; /* true = "stop searching" */ - int retval; /* true = "we had a match" */ - DWORD count; - unsigned short int scan; - unsigned char ch; - unsigned long shiftstate; - int altseq = 0, keycode, vk; - done = 0; - retval = 0; - while (!done) - { - count = 0; - PeekConsoleInput(hConIn,ir,1,&count); - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - shiftstate = ir->Event.KeyEvent.dwControlKeyState; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || iskeypad(scan) || altseq) { - done = 1; /* Stop looking */ - retval = 1; /* Found what we sought */ - } else { - /* Strange Key event; let's purge it to avoid trouble */ - ReadConsoleInput(hConIn,ir,1,&count); - } + int done = 0; /* true = "stop searching" */ + int retval; /* true = "we had a match" */ + DWORD count; + unsigned short int scan; + unsigned char ch; + unsigned long shiftstate; + int altseq = 0, keycode, vk; + done = 0; + retval = 0; + while (!done) { + count = 0; + PeekConsoleInput(hConIn, ir, 1, &count); + if (count > 0) { + if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { + ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + shiftstate = ir->Event.KeyEvent.dwControlKeyState; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || iskeypad(scan) || altseq) { + done = 1; /* Stop looking */ + retval = 1; /* Found what we sought */ + } else { + /* Strange Key event; let's purge it to avoid trouble */ + ReadConsoleInput(hConIn, ir, 1, &count); + } - } - else if ((ir->EventType == MOUSE_EVENT && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) { - done = 1; - retval = 1; - } + } else if ((ir->EventType == MOUSE_EVENT + && (ir->Event.MouseEvent.dwButtonState + & MOUSEMASK))) { + done = 1; + retval = 1; + } - else /* Discard it, it's an insignificant event */ - ReadConsoleInput(hConIn,ir,1,&count); - } else /* There are no events in console event queue */ { - done = 1; /* Stop looking */ - retval = 0; - } - } - return retval; + else /* Discard it, it's an insignificant event */ + ReadConsoleInput(hConIn, ir, 1, &count); + } else /* There are no events in console event queue */ { + done = 1; /* Stop looking */ + retval = 0; + } + } + return retval; } -int __declspec(dllexport) __stdcall -CheckInput(hConIn, ir, count, numpad, mode, mod, cc) +int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad, + mode, mod, cc) HANDLE hConIn; INPUT_RECORD *ir; -DWORD *count; +DWORD *count; boolean numpad; int mode; int *mod; coord *cc; { #if defined(SAFERHANGUP) - DWORD dwWait; + DWORD dwWait; #endif - int ch; - boolean valid = 0, done = 0; - while (!done) { + int ch; + boolean valid = 0, done = 0; + while (!done) { #if defined(SAFERHANGUP) - dwWait = WaitForSingleObjectEx( - hConIn, // event object to wait for - INFINITE, // waits indefinitely - TRUE); // alertable wait enabled - if (dwWait == WAIT_FAILED) return '\033'; + dwWait = WaitForSingleObjectEx(hConIn, // event object to wait for + INFINITE, // waits indefinitely + TRUE); // alertable wait enabled + if (dwWait == WAIT_FAILED) + return '\033'; #endif - ReadConsoleInput(hConIn,ir,1,count); - if (mode == 0) { - if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { - ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); - done = valid; - } - } else { - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); - if (valid) return ch; - } else if (ir->EventType == MOUSE_EVENT) { - if ((ir->Event.MouseEvent.dwEventFlags == 0) && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) { - cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1; - cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1; + ReadConsoleInput(hConIn, ir, 1, count); + if (mode == 0) { + if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { + ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); + done = valid; + } + } else { + if (count > 0) { + if (ir->EventType == KEY_EVENT + && ir->Event.KeyEvent.bKeyDown) { + ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); + if (valid) + return ch; + } else if (ir->EventType == MOUSE_EVENT) { + if ((ir->Event.MouseEvent.dwEventFlags == 0) + && (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) { + cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1; + cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1; - if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON) - *mod = CLICK_1; - else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON) - *mod = CLICK_2; -#if 0 /* middle button */ + if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON) + *mod = CLICK_1; + else if (ir->Event.MouseEvent.dwButtonState + & RIGHTBUTTON) + *mod = CLICK_2; +#if 0 /* middle button */ else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON) *mod = CLICK_3; -#endif - return 0; - } - } - } else - done = 1; - } - } - return mode ? 0 : ch; +#endif + return 0; + } + } + } else + done = 1; + } + } + return mode ? 0 : ch; } -int __declspec(dllexport) __stdcall -SourceWhere(buf) +int __declspec(dllexport) __stdcall SourceWhere(buf) char **buf; { - if (!buf) return 0; - *buf = where_to_get_source; - return 1; + if (!buf) + return 0; + *buf = where_to_get_source; + return 1; } -int __declspec(dllexport) __stdcall -SourceAuthor(buf) +int __declspec(dllexport) __stdcall SourceAuthor(buf) char **buf; { - if (!buf) return 0; - *buf = author; - return 1; + if (!buf) + return 0; + *buf = author; + return 1; } -int __declspec(dllexport) __stdcall -KeyHandlerName(buf, full) +int __declspec(dllexport) __stdcall KeyHandlerName(buf, full) char **buf; int full; { - if (!buf) return 0; - if (full) *buf = dllname; - else *buf = shortdllname; - return 1; + if (!buf) + return 0; + if (full) + *buf = dllname; + else + *buf = shortdllname; + return 1; } - diff --git a/sys/winnt/nhdefkey.c b/sys/winnt/nhdefkey.c index f82c30a1a..c2f4b4e26 100644 --- a/sys/winnt/nhdefkey.c +++ b/sys/winnt/nhdefkey.c @@ -1,6 +1,6 @@ -/* NetHack 3.6 nhdefkey.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 nhdefkey.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 nhdefkey.c $Date: 2009/05/06 10:53:29 $ $Revision: 1.10 $ */ -/* SCCS Id: @(#)nhdefkey.c 3.5 $NHDT-Date$ */ +/* SCCS Id: @(#)nhdefkey.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */ /* SCCS Id: @(#)nhdefkey.c 3.5 $Date: 2009/05/06 10:53:29 $ */ /* Copyright (c) NetHack PC Development Team 2003 */ /* NetHack may be freely redistributed. See license for details. */ @@ -33,22 +33,23 @@ extern struct sinfo program_state; char dllname[512]; char *shortdllname; -int FDECL(__declspec(dllexport) __stdcall -ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir, - boolean *valid, BOOLEAN_P numberpad, int portdebug)); +int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke, + (HANDLE hConIn, INPUT_RECORD *ir, boolean *valid, + BOOLEAN_P numberpad, int portdebug)); -int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) +int WINAPI +DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { - char dlltmpname[512]; - char *tmp = dlltmpname, *tmp2; - *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; - (void)strcpy(dllname, tmp); - tmp2 = strrchr(dllname, '\\'); - if (tmp2) { - tmp2++; - shortdllname = tmp2; - } - return TRUE; + char dlltmpname[512]; + char *tmp = dlltmpname, *tmp2; + *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; + (void) strcpy(dllname, tmp); + tmp2 = strrchr(dllname, '\\'); + if (tmp2) { + tmp2++; + shortdllname = tmp2; + } + return TRUE; } /* @@ -56,11 +57,11 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) * (Adopted from the MSDOS port) */ -#define KEYPADLO 0x47 -#define KEYPADHI 0x53 +#define KEYPADLO 0x47 +#define KEYPADHI 0x53 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -69,277 +70,283 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) */ static const struct pad { - uchar normal, shift, cntrl; -} keypad[PADKEYS] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'5', M('5'), '5'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'0', M('0'), '0'}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + uchar normal, shift, cntrl; +} keypad[PADKEYS] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { '5', M('5'), '5' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { '0', M('0'), '0' }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; -#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') +#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') static BYTE KeyState[256]; -int __declspec(dllexport) __stdcall -ProcessKeystroke(hConIn,ir, valid, numberpad, portdebug) +int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid, + numberpad, portdebug) HANDLE hConIn; INPUT_RECORD *ir; boolean *valid; boolean numberpad; int portdebug; { - int metaflags = 0, k = 0; - int keycode, vk; - unsigned char ch, pre_ch, mk = 0; - unsigned short int scan; - unsigned long shiftstate; - int altseq = 0; - const struct pad *kpad; + int metaflags = 0, k = 0; + int keycode, vk; + unsigned char ch, pre_ch, mk = 0; + unsigned short int scan; + unsigned long shiftstate; + int altseq = 0; + const struct pad *kpad; - shiftstate = 0L; - ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - shiftstate = ir->Event.KeyEvent.dwControlKeyState; - KeyState[VK_SHIFT] = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0; - KeyState[VK_CONTROL] = (shiftstate & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) ? - 0x81 : 0; - KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0; + shiftstate = 0L; + ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + shiftstate = ir->Event.KeyEvent.dwControlKeyState; + KeyState[VK_SHIFT] = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0; + KeyState[VK_CONTROL] = + (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) ? 0x81 : 0; + KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0; - if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || (iskeypad(scan)) || (altseq > 0)) - *valid = TRUE; - /* if (!valid) return 0; */ - /* - * shiftstate can be checked to see if various special - * keys were pressed at the same time as the key. - * Currently we are using the ALT & SHIFT & CONTROLS. - * - * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, - * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, - * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, - * CAPSLOCK_ON, ENHANCED_KEY - * - * are all valid bit masks to use on shiftstate. - * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the - * left control key was pressed with the keystroke. - */ - if (iskeypad(scan)) { - kpad = numberpad ? numpad : keypad; - if (shiftstate & SHIFT_PRESSED) { - ch = kpad[scan - KEYPADLO].shift; - } - else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { - ch = kpad[scan - KEYPADLO].cntrl; - } - else { - ch = kpad[scan - KEYPADLO].normal; - } + if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || (iskeypad(scan)) || (altseq > 0)) + *valid = TRUE; + /* if (!valid) return 0; */ + /* + * shiftstate can be checked to see if various special + * keys were pressed at the same time as the key. + * Currently we are using the ALT & SHIFT & CONTROLS. + * + * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, + * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, + * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, + * CAPSLOCK_ON, ENHANCED_KEY + * + * are all valid bit masks to use on shiftstate. + * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the + * left control key was pressed with the keystroke. + */ + if (iskeypad(scan)) { + kpad = numberpad ? numpad : keypad; + if (shiftstate & SHIFT_PRESSED) { + ch = kpad[scan - KEYPADLO].shift; + } else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { + ch = kpad[scan - KEYPADLO].cntrl; + } else { + ch = kpad[scan - KEYPADLO].normal; } - else if (altseq > 0) { /* ALT sequence */ - if (vk == 0xBF) ch = M('?'); - else ch = M(tolower(keycode)); - } - /* Attempt to work better with international keyboards. */ - else { - WORD chr[2]; - k = ToAscii(vk, scan, KeyState, chr, 0); - if (k <= 2) - switch(k) { - case 2: /* two characters */ - ch = (unsigned char)chr[1]; - *valid = TRUE; - break; - case 1: /* one character */ - ch = (unsigned char)chr[0]; - *valid = TRUE; - break; - case 0: /* no translation */ - default: /* negative */ - *valid = FALSE; - } - } - if (ch == '\r') ch = '\n'; + } else if (altseq > 0) { /* ALT sequence */ + if (vk == 0xBF) + ch = M('?'); + else + ch = M(tolower(keycode)); + } + /* Attempt to work better with international keyboards. */ + else { + WORD chr[2]; + k = ToAscii(vk, scan, KeyState, chr, 0); + if (k <= 2) + switch (k) { + case 2: /* two characters */ + ch = (unsigned char) chr[1]; + *valid = TRUE; + break; + case 1: /* one character */ + ch = (unsigned char) chr[0]; + *valid = TRUE; + break; + case 0: /* no translation */ + default: /* negative */ + *valid = FALSE; + } + } + if (ch == '\r') + ch = '\n'; #ifdef PORT_DEBUG - if (portdebug) { - char buf[BUFSZ]; - Sprintf(buf, - "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, ta=%d (ESC to end)", - shortdllname, ch, scan, vk, pre_ch, shiftstate, k); - fprintf(stdout, "\n%s", buf); - } + if (portdebug) { + char buf[BUFSZ]; + Sprintf(buf, "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, " + "ta=%d (ESC to end)", + shortdllname, ch, scan, vk, pre_ch, shiftstate, k); + fprintf(stdout, "\n%s", buf); + } #endif - return ch; + return ch; } - -int __declspec(dllexport) __stdcall -NHkbhit(hConIn, ir) +int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir) HANDLE hConIn; INPUT_RECORD *ir; { - int done = 0; /* true = "stop searching" */ - int retval; /* true = "we had a match" */ - DWORD count; - unsigned short int scan; - unsigned char ch; - unsigned long shiftstate; - int altseq = 0, keycode, vk; - done = 0; - retval = 0; - while (!done) - { - count = 0; - PeekConsoleInput(hConIn,ir,1,&count); - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - shiftstate = ir->Event.KeyEvent.dwControlKeyState; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || iskeypad(scan) || altseq) { - done = 1; /* Stop looking */ - retval = 1; /* Found what we sought */ - } else { - /* Strange Key event; let's purge it to avoid trouble */ - ReadConsoleInput(hConIn,ir,1,&count); - } + int done = 0; /* true = "stop searching" */ + int retval; /* true = "we had a match" */ + DWORD count; + unsigned short int scan; + unsigned char ch; + unsigned long shiftstate; + int altseq = 0, keycode, vk; + done = 0; + retval = 0; + while (!done) { + count = 0; + PeekConsoleInput(hConIn, ir, 1, &count); + if (count > 0) { + if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { + ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + shiftstate = ir->Event.KeyEvent.dwControlKeyState; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || iskeypad(scan) || altseq) { + done = 1; /* Stop looking */ + retval = 1; /* Found what we sought */ + } else { + /* Strange Key event; let's purge it to avoid trouble */ + ReadConsoleInput(hConIn, ir, 1, &count); + } - } - else if ((ir->EventType == MOUSE_EVENT && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) { - done = 1; - retval = 1; - } + } else if ((ir->EventType == MOUSE_EVENT + && (ir->Event.MouseEvent.dwButtonState + & MOUSEMASK))) { + done = 1; + retval = 1; + } - else /* Discard it, it's an insignificant event */ - ReadConsoleInput(hConIn,ir,1,&count); - } else /* There are no events in console event queue */ { - done = 1; /* Stop looking */ - retval = 0; - } - } - return retval; + else /* Discard it, it's an insignificant event */ + ReadConsoleInput(hConIn, ir, 1, &count); + } else /* There are no events in console event queue */ { + done = 1; /* Stop looking */ + retval = 0; + } + } + return retval; } -int __declspec(dllexport) __stdcall -CheckInput(hConIn, ir, count, numpad, mode, mod, cc) +int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad, + mode, mod, cc) HANDLE hConIn; INPUT_RECORD *ir; -DWORD *count; +DWORD *count; boolean numpad; int mode; int *mod; coord *cc; { #if defined(SAFERHANGUP) - DWORD dwWait; + DWORD dwWait; #endif - int ch; - boolean valid = 0, done = 0; - while (!done) { - + int ch; + boolean valid = 0, done = 0; + while (!done) { #if defined(SAFERHANGUP) - dwWait = WaitForSingleObjectEx( - hConIn, // event object to wait for - INFINITE, // waits indefinitely - TRUE); // alertable wait enabled - if (dwWait == WAIT_FAILED) return '\033'; + dwWait = WaitForSingleObjectEx(hConIn, // event object to wait for + INFINITE, // waits indefinitely + TRUE); // alertable wait enabled + if (dwWait == WAIT_FAILED) + return '\033'; #endif - ReadConsoleInput(hConIn,ir,1,count); - if (mode == 0) { - if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { - ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); - done = valid; - } - } else { - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); - if (valid) return ch; - } else if (ir->EventType == MOUSE_EVENT) { - if ((ir->Event.MouseEvent.dwEventFlags == 0) && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) { - cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1; - cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1; + ReadConsoleInput(hConIn, ir, 1, count); + if (mode == 0) { + if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { + ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); + done = valid; + } + } else { + if (count > 0) { + if (ir->EventType == KEY_EVENT + && ir->Event.KeyEvent.bKeyDown) { + ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0); + if (valid) + return ch; + } else if (ir->EventType == MOUSE_EVENT) { + if ((ir->Event.MouseEvent.dwEventFlags == 0) + && (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) { + cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1; + cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1; - if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON) - *mod = CLICK_1; - else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON) - *mod = CLICK_2; -#if 0 /* middle button */ + if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON) + *mod = CLICK_1; + else if (ir->Event.MouseEvent.dwButtonState + & RIGHTBUTTON) + *mod = CLICK_2; +#if 0 /* middle button */ else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON) *mod = CLICK_3; -#endif - return 0; - } - } - } else - done = 1; - } - } - return mode ? 0 : ch; +#endif + return 0; + } + } + } else + done = 1; + } + } + return mode ? 0 : ch; } -int __declspec(dllexport) __stdcall -SourceWhere(buf) +int __declspec(dllexport) __stdcall SourceWhere(buf) char **buf; { - if (!buf) return 0; - *buf = where_to_get_source; - return 1; + if (!buf) + return 0; + *buf = where_to_get_source; + return 1; } -int __declspec(dllexport) __stdcall -SourceAuthor(buf) +int __declspec(dllexport) __stdcall SourceAuthor(buf) char **buf; { - if (!buf) return 0; - *buf = author; - return 1; + if (!buf) + return 0; + *buf = author; + return 1; } -int __declspec(dllexport) __stdcall -KeyHandlerName(buf, full) +int __declspec(dllexport) __stdcall KeyHandlerName(buf, full) char **buf; int full; { - if (!buf) return 0; - if (full) *buf = dllname; - else *buf = shortdllname; - return 1; + if (!buf) + return 0; + if (full) + *buf = dllname; + else + *buf = shortdllname; + return 1; } - diff --git a/sys/winnt/nhraykey.c b/sys/winnt/nhraykey.c index 5053f03ad..2449ec1b2 100644 --- a/sys/winnt/nhraykey.c +++ b/sys/winnt/nhraykey.c @@ -1,6 +1,6 @@ -/* NetHack 3.6 nhraykey.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 nhraykey.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 nhraykey.c $Date: 2009/05/06 10:53:31 $ $Revision: 1.8 $ */ -/* SCCS Id: @(#)nhraykey.c 3.5 $NHDT-Date$ */ +/* SCCS Id: @(#)nhraykey.c 3.5 $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ */ /* SCCS Id: @(#)nhraykey.c 3.5 $Date: 2009/05/06 10:53:31 $ */ /* Copyright (c) NetHack PC Development Team 2003 */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,156 +8,156 @@ /* * Keystroke handling contributed by Ray Chason. * The following text was written by Ray Chason. - * + * * The problem * =========== - * + * * The console-mode Nethack wants both keyboard and mouse input. The * problem is that the Windows API provides no easy way to get mouse input * and also keyboard input properly translated according to the user's * chosen keyboard layout. - * + * * The ReadConsoleInput function returns a stream of keyboard and mouse * events. Nethack is interested in those events that represent a key * pressed, or a click on a mouse button. The keyboard events from * ReadConsoleInput are not translated according to the keyboard layout, * and do not take into account the shift, control, or alt keys. - * + * * The PeekConsoleInput function works similarly to ReadConsoleInput, * except that it does not remove an event from the queue and it returns * instead of blocking when the queue is empty. - * + * * A program can also use ReadConsole to get a properly translated stream * of characters. Unfortunately, ReadConsole does not return mouse events, * does not distinguish the keypad from the main keyboard, does not return * keys shifted with Alt, and does not even return the ESC key when - * pressed. - * + * pressed. + * * We want both the functionality of ReadConsole and the functionality of * ReadConsoleInput. But Microsoft didn't seem to think of that. - * - * + * + * * The solution, in the original code * ================================== - * + * * The original 3.4.1 distribution tries to get proper keyboard translation * by passing keyboard events to the ToAscii function. This works, to some * extent -- it takes the shift key into account, and it processes dead * keys properly. But it doesn't take non-US keyboards into account. It * appears that ToAscii is meant for windowed applications, and does not * have enough information to do its job properly in a console application. - * - * + * + * * The Finnish keyboard patch * ========================== - * + * * This patch adds the "subkeyvalue" option to the defaults.nh file. The * user can then add OPTIONS=sukeyvalue:171/92, for instance, to replace * the 171 character with 92, which is \. This works, once properly * configured, but places too much burden on the user. It also bars the * use of the substituted characters in naming objects or monsters. - * - * + * + * * The solution presented here * =========================== - * + * * The best way I could find to combine the functionality of ReadConsole * with that of ReadConsoleInput is simple in concept. First, call * PeekConsoleInput to get the first event. If it represents a key press, * call ReadConsole to retrieve the key. Otherwise, pop it off the queue * with ReadConsoleInput and, if it's a mouse click, return it as such. - * + * * But the Devil, as they say, is in the details. The problem is in * recognizing an event that ReadConsole will return as a key. We don't * want to call ReadConsole unless we know that it will immediately return: * if it blocks, the mouse and the Alt sequences will cease to function * until it returns. - * + * * Separating process_keystroke into two functions, one for commands and a * new one, process_keystroke2, for answering prompts, makes the job a lot * easier. process_keystroke2 doesn't have to worry about mouse events or - * Alt sequences, and so the consequences are minor if ReadConsole blocks. + * Alt sequences, and so the consequences are minor if ReadConsole blocks. * process_keystroke, OTOH, never needs to return a non-ASCII character * that was read from ReadConsole; it returns bytes with the high bit set * only in response to an Alt sequence. - * + * * So in process_keystroke, before calling ReadConsole, a bogus key event * is pushed on the queue. This event causes ReadConsole to return, even * if there was no other character available. Because the bogus key has * the eighth bit set, it is filtered out. This is not done in * process_keystroke2, because that would render dead keys unusable. - * + * * A separate process_keystroke2 can also process the numeric keypad in a * way that makes sense for prompts: just return the corresponding symbol, * and pay no mind to number_pad or the num lock key. - * + * * The recognition of Alt sequences is modified, to support the use of * characters generated with the AltGr key. A keystroke is an Alt sequence * if an Alt key is seen that can't be an AltGr (since an AltGr sequence * could be a character, and in some layouts it could even be an ASCII * character). This recognition is different on NT-based and 95-based * Windows: - * + * * * On NT-based Windows, AltGr signals as right Alt and left Ctrl * together. So an Alt sequence is recognized if either Alt key is * pressed and if right Alt and left Ctrl are not both present. This * is true even if the keyboard in use does not have an AltGr key, and * uses right Alt for AltGr. - * + * * * On 95-based Windows, with a keyboard that lacks the AltGr key, the * right Alt key is used instead. But it still signals as right Alt, * without left Ctrl. There is no way for the application to know * whether right Alt is Alt or AltGr, and so it is always assumed * to be AltGr. This means that Alt sequences must be formed with * left Alt. - * + * * So the patch processes keystrokes as follows: - * + * * * If the scan and virtual key codes are both 0, it's the bogus key, * and we ignore it. - * + * * * Keys on the numeric keypad are processed for commands as in the * unpatched Nethack, and for prompts by returning the ASCII * character, even if the num lock is off. - * + * * * Alt sequences are processed for commands as in the unpatched * Nethack, and ignored for prompts. - * + * * * Control codes are returned as received, because ReadConsole will * not return the ESC key. - * + * * * Other key-down events are passed to ReadConsole. The use of * ReadConsole is different for commands than for prompts: - * + * * o For commands, the bogus key is pushed onto the queue before * ReadConsole is called. On return, non-ASCII characters are * filtered, so they are not mistaken for Alt sequences; this also * filters the bogus key. - * + * * o For prompts, the bogus key is not used, because that would * interfere with dead keys. Eight bit characters may be returned, * and are coded in the configured code page. - * - * + * + * * Possible improvements * ===================== - * + * * Some possible improvements remain: - * + * * * Integrate the existing Finnish keyboard patch, for use with non- * QWERTY layouts such as the German QWERTZ keyboard or Dvorak. - * + * * * Fix the keyboard glitches in the graphical version. Namely, dead * keys don't work, and input comes in as ISO-8859-1 but is displayed * as code page 437 if IBMgraphics is set on startup. - * + * * * Transform incoming text to ISO-8859-1, for full compatibility with * the graphical version. - * + * * * After pushing the bogus key and calling ReadConsole, check to see * if we got the bogus key; if so, and an Alt is pressed, process the * event as an Alt sequence. - * + * */ static char where_to_get_source[] = "http://www.nethack.org/"; @@ -172,33 +172,34 @@ extern INPUT_RECORD ir; char dllname[512]; char *shortdllname; -int FDECL(__declspec(dllexport) __stdcall -ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir, - boolean *valid, BOOLEAN_P numberpad, int portdebug)); +int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke, + (HANDLE hConIn, INPUT_RECORD *ir, boolean *valid, + BOOLEAN_P numberpad, int portdebug)); static INPUT_RECORD bogus_key; -int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) +int WINAPI +DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { - char dlltmpname[512]; - char *tmp = dlltmpname, *tmp2; - *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; - (void)strcpy(dllname, tmp); - tmp2 = strrchr(dllname, '\\'); - if (tmp2) { - tmp2++; - shortdllname = tmp2; - } - /* A bogus key that will be filtered when received, to keep ReadConsole - * from blocking */ - bogus_key.EventType = KEY_EVENT; - bogus_key.Event.KeyEvent.bKeyDown = 1; - bogus_key.Event.KeyEvent.wRepeatCount = 1; - bogus_key.Event.KeyEvent.wVirtualKeyCode = 0; - bogus_key.Event.KeyEvent.wVirtualScanCode = 0; - bogus_key.Event.KeyEvent.uChar.AsciiChar = (uchar)0x80; - bogus_key.Event.KeyEvent.dwControlKeyState = 0; - return TRUE; + char dlltmpname[512]; + char *tmp = dlltmpname, *tmp2; + *(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0'; + (void) strcpy(dllname, tmp); + tmp2 = strrchr(dllname, '\\'); + if (tmp2) { + tmp2++; + shortdllname = tmp2; + } + /* A bogus key that will be filtered when received, to keep ReadConsole + * from blocking */ + bogus_key.EventType = KEY_EVENT; + bogus_key.Event.KeyEvent.bKeyDown = 1; + bogus_key.Event.KeyEvent.wRepeatCount = 1; + bogus_key.Event.KeyEvent.wVirtualKeyCode = 0; + bogus_key.Event.KeyEvent.wVirtualScanCode = 0; + bogus_key.Event.KeyEvent.uChar.AsciiChar = (uchar) 0x80; + bogus_key.Event.KeyEvent.dwControlKeyState = 0; + return TRUE; } /* @@ -206,12 +207,13 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) * (Adopted from the MSDOS port) */ -#define KEYPADLO 0x47 -#define KEYPADHI 0x53 +#define KEYPADLO 0x47 +#define KEYPADHI 0x53 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) -#define isnumkeypad(x) (KEYPADLO <= (x) && (x) <= 0x51 && (x) != 0x4A && (x) != 0x4E) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define isnumkeypad(x) \ + (KEYPADLO <= (x) && (x) <= 0x51 && (x) != 0x4A && (x) != 0x4E) /* * Keypad keys are translated to the normal values below. @@ -220,42 +222,45 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) */ static const struct pad { - uchar normal, shift, cntrl; -} keypad[PADKEYS] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + uchar normal, shift, cntrl; +} keypad[PADKEYS] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; -#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') +#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2') /* Use process_keystroke for key commands, process_keystroke2 for prompts */ -/* int FDECL(process_keystroke, (INPUT_RECORD *ir, boolean *valid, int portdebug)); */ -int FDECL(process_keystroke2, (HANDLE,INPUT_RECORD *ir, boolean *valid)); +/* int FDECL(process_keystroke, (INPUT_RECORD *ir, boolean *valid, int + * portdebug)); */ +int FDECL(process_keystroke2, (HANDLE, INPUT_RECORD *ir, boolean *valid)); static int FDECL(is_altseq, (unsigned long shiftstate)); static int @@ -267,190 +272,195 @@ unsigned long shiftstate; * on 95-based Windows, AltGr signals as right Alt only. * So on NT, we signal Alt if either Alt is pressed and left Ctrl is not, * and on 95, we signal Alt for left Alt only. */ - switch (shiftstate & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) { - case LEFT_ALT_PRESSED: - case LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED: - return 1; + switch (shiftstate + & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) { + case LEFT_ALT_PRESSED: + case LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED: + return 1; - case RIGHT_ALT_PRESSED: - case RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED: - return (GetVersion() & 0x80000000) == 0; + case RIGHT_ALT_PRESSED: + case RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED: + return (GetVersion() & 0x80000000) == 0; - default: - return 0; + default: + return 0; } } -int __declspec(dllexport) __stdcall -ProcessKeystroke(hConIn, ir, valid, numberpad, portdebug) +int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid, + numberpad, portdebug) HANDLE hConIn; INPUT_RECORD *ir; boolean *valid; boolean numberpad; int portdebug; { - int metaflags = 0, k = 0; - int keycode, vk; - unsigned char ch, pre_ch, mk = 0; - unsigned short int scan; - unsigned long shiftstate; - int altseq = 0; - const struct pad *kpad; - DWORD count; + int metaflags = 0, k = 0; + int keycode, vk; + unsigned char ch, pre_ch, mk = 0; + unsigned short int scan; + unsigned long shiftstate; + int altseq = 0; + const struct pad *kpad; + DWORD count; - shiftstate = 0L; - ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - shiftstate = ir->Event.KeyEvent.dwControlKeyState; - if (scan == 0 && vk == 0) { - /* It's the bogus_key */ - ReadConsoleInput(hConIn,ir,1,&count); - *valid = FALSE; - return 0; - } + shiftstate = 0L; + ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + shiftstate = ir->Event.KeyEvent.dwControlKeyState; + if (scan == 0 && vk == 0) { + /* It's the bogus_key */ + ReadConsoleInput(hConIn, ir, 1, &count); + *valid = FALSE; + return 0; + } - if (is_altseq(shiftstate)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || (iskeypad(scan)) || (altseq > 0)) - *valid = TRUE; - /* if (!valid) return 0; */ - /* - * shiftstate can be checked to see if various special - * keys were pressed at the same time as the key. - * Currently we are using the ALT & SHIFT & CONTROLS. - * - * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, - * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, - * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, - * CAPSLOCK_ON, ENHANCED_KEY - * - * are all valid bit masks to use on shiftstate. - * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the - * left control key was pressed with the keystroke. - */ - if (iskeypad(scan)) { - ReadConsoleInput(hConIn,ir,1,&count); - kpad = numberpad ? numpad : keypad; - if (shiftstate & SHIFT_PRESSED) { - ch = kpad[scan - KEYPADLO].shift; - } - else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { - ch = kpad[scan - KEYPADLO].cntrl; - } - else { - ch = kpad[scan - KEYPADLO].normal; - } + if (is_altseq(shiftstate)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || (iskeypad(scan)) || (altseq > 0)) + *valid = TRUE; + /* if (!valid) return 0; */ + /* + * shiftstate can be checked to see if various special + * keys were pressed at the same time as the key. + * Currently we are using the ALT & SHIFT & CONTROLS. + * + * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, + * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, + * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, + * CAPSLOCK_ON, ENHANCED_KEY + * + * are all valid bit masks to use on shiftstate. + * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the + * left control key was pressed with the keystroke. + */ + if (iskeypad(scan)) { + ReadConsoleInput(hConIn, ir, 1, &count); + kpad = numberpad ? numpad : keypad; + if (shiftstate & SHIFT_PRESSED) { + ch = kpad[scan - KEYPADLO].shift; + } else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { + ch = kpad[scan - KEYPADLO].cntrl; + } else { + ch = kpad[scan - KEYPADLO].normal; } - else if (altseq > 0) { /* ALT sequence */ - ReadConsoleInput(hConIn,ir,1,&count); - if (vk == 0xBF) ch = M('?'); - else ch = M(tolower(keycode)); - } - else if (ch < 32 && !isnumkeypad(scan)) { - /* Control code; ReadConsole seems to filter some of these, - * including ESC */ - ReadConsoleInput(hConIn,ir,1,&count); - } - /* Attempt to work better with international keyboards. */ - else { - CHAR ch2; - DWORD written; - /* The bogus_key guarantees that ReadConsole will return, - * and does not itself do anything */ - WriteConsoleInput(hConIn, &bogus_key, 1, &written); - ReadConsole(hConIn,&ch2,1,&count,NULL); - /* Prevent high characters from being interpreted as alt - * sequences; also filter the bogus_key */ - if (ch2 & 0x80) - *valid = FALSE; - else - ch = ch2; - if (ch == 0) *valid = FALSE; - } - if (ch == '\r') ch = '\n'; + } else if (altseq > 0) { /* ALT sequence */ + ReadConsoleInput(hConIn, ir, 1, &count); + if (vk == 0xBF) + ch = M('?'); + else + ch = M(tolower(keycode)); + } else if (ch < 32 && !isnumkeypad(scan)) { + /* Control code; ReadConsole seems to filter some of these, + * including ESC */ + ReadConsoleInput(hConIn, ir, 1, &count); + } + /* Attempt to work better with international keyboards. */ + else { + CHAR ch2; + DWORD written; + /* The bogus_key guarantees that ReadConsole will return, + * and does not itself do anything */ + WriteConsoleInput(hConIn, &bogus_key, 1, &written); + ReadConsole(hConIn, &ch2, 1, &count, NULL); + /* Prevent high characters from being interpreted as alt + * sequences; also filter the bogus_key */ + if (ch2 & 0x80) + *valid = FALSE; + else + ch = ch2; + if (ch == 0) + *valid = FALSE; + } + if (ch == '\r') + ch = '\n'; #ifdef PORT_DEBUG - if (portdebug) { - char buf[BUFSZ]; - Sprintf(buf, - "PORTDEBUG: ch=%u, scan=%u, vk=%d, pre=%d, shiftstate=0x%X (ESC to end)\n", - ch, scan, vk, pre_ch, shiftstate); - fprintf(stdout, "\n%s", buf); - } + if (portdebug) { + char buf[BUFSZ]; + Sprintf(buf, "PORTDEBUG: ch=%u, scan=%u, vk=%d, pre=%d, " + "shiftstate=0x%X (ESC to end)\n", + ch, scan, vk, pre_ch, shiftstate); + fprintf(stdout, "\n%s", buf); + } #endif - return ch; + return ch; } -int process_keystroke2(hConIn, ir, valid) +int +process_keystroke2(hConIn, ir, valid) HANDLE hConIn; INPUT_RECORD *ir; boolean *valid; { - /* Use these values for the numeric keypad */ - static const char keypad_nums[] = "789-456+1230."; + /* Use these values for the numeric keypad */ + static const char keypad_nums[] = "789-456+1230."; - unsigned char ch; - int vk; - unsigned short int scan; - unsigned long shiftstate; - int altseq; - DWORD count; + unsigned char ch; + int vk; + unsigned short int scan; + unsigned long shiftstate; + int altseq; + DWORD count; - ch = ir->Event.KeyEvent.uChar.AsciiChar; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - scan = ir->Event.KeyEvent.wVirtualScanCode; - shiftstate = ir->Event.KeyEvent.dwControlKeyState; + ch = ir->Event.KeyEvent.uChar.AsciiChar; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + scan = ir->Event.KeyEvent.wVirtualScanCode; + shiftstate = ir->Event.KeyEvent.dwControlKeyState; - if (scan == 0 && vk == 0) { - /* It's the bogus_key */ - ReadConsoleInput(hConIn,ir,1,&count); - *valid = FALSE; - return 0; - } + if (scan == 0 && vk == 0) { + /* It's the bogus_key */ + ReadConsoleInput(hConIn, ir, 1, &count); + *valid = FALSE; + return 0; + } - altseq = is_altseq(shiftstate); - if (ch || (iskeypad(scan)) || altseq) - *valid = TRUE; - /* if (!valid) return 0; */ - /* - * shiftstate can be checked to see if various special - * keys were pressed at the same time as the key. - * Currently we are using the ALT & SHIFT & CONTROLS. - * - * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, - * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, - * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, - * CAPSLOCK_ON, ENHANCED_KEY - * - * are all valid bit masks to use on shiftstate. - * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the - * left control key was pressed with the keystroke. - */ - if (iskeypad(scan) && !altseq) { - ReadConsoleInput(hConIn,ir,1,&count); - ch = keypad_nums[scan - KEYPADLO]; - } - else if (ch < 32 && !isnumkeypad(scan)) { - /* Control code; ReadConsole seems to filter some of these, - * including ESC */ - ReadConsoleInput(hConIn,ir,1,&count); - } - /* Attempt to work better with international keyboards. */ - else { - CHAR ch2; - ReadConsole(hConIn,&ch2,1,&count,NULL); - ch = ch2 & 0xFF; - if (ch == 0) *valid = FALSE; - } - if (ch == '\r') ch = '\n'; - return ch; + altseq = is_altseq(shiftstate); + if (ch || (iskeypad(scan)) || altseq) + *valid = TRUE; + /* if (!valid) return 0; */ + /* + * shiftstate can be checked to see if various special + * keys were pressed at the same time as the key. + * Currently we are using the ALT & SHIFT & CONTROLS. + * + * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, + * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, + * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, + * CAPSLOCK_ON, ENHANCED_KEY + * + * are all valid bit masks to use on shiftstate. + * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the + * left control key was pressed with the keystroke. + */ + if (iskeypad(scan) && !altseq) { + ReadConsoleInput(hConIn, ir, 1, &count); + ch = keypad_nums[scan - KEYPADLO]; + } else if (ch < 32 && !isnumkeypad(scan)) { + /* Control code; ReadConsole seems to filter some of these, + * including ESC */ + ReadConsoleInput(hConIn, ir, 1, &count); + } + /* Attempt to work better with international keyboards. */ + else { + CHAR ch2; + ReadConsole(hConIn, &ch2, 1, &count, NULL); + ch = ch2 & 0xFF; + if (ch == 0) + *valid = FALSE; + } + if (ch == '\r') + ch = '\n'; + return ch; } -int __declspec(dllexport) __stdcall -CheckInput(hConIn, ir, count, numpad, mode, mod, cc) +int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad, + mode, mod, cc) HANDLE hConIn; INPUT_RECORD *ir; DWORD *count; @@ -459,53 +469,61 @@ boolean numpad; coord *cc; { #if defined(SAFERHANGUP) - DWORD dwWait; + DWORD dwWait; #endif - int ch; - boolean valid = 0, done = 0; - while (!done) { - *count = 0; - dwWait = WaitForSingleObject(hConIn, INFINITE); + int ch; + boolean valid = 0, done = 0; + while (!done) { + *count = 0; + dwWait = WaitForSingleObject(hConIn, INFINITE); #if defined(SAFERHANGUP) - if (dwWait == WAIT_FAILED) return '\033'; + if (dwWait == WAIT_FAILED) + return '\033'; #endif - PeekConsoleInput(hConIn,ir,1,count); - if (mode == 0) { - if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { - ch = process_keystroke2(hConIn, ir, &valid); - done = valid; - } else - ReadConsoleInput(hConIn,ir,1,count); - } else { - ch = 0; - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ProcessKeystroke(hConIn, ir, &valid, numpad, + PeekConsoleInput(hConIn, ir, 1, count); + if (mode == 0) { + if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { + ch = process_keystroke2(hConIn, ir, &valid); + done = valid; + } else + ReadConsoleInput(hConIn, ir, 1, count); + } else { + ch = 0; + if (count > 0) { + if (ir->EventType == KEY_EVENT + && ir->Event.KeyEvent.bKeyDown) { + ch = ProcessKeystroke(hConIn, ir, &valid, numpad, #ifdef PORTDEBUG - 1); + 1); #else - 0); + 0); #endif - if (valid) return ch; - } else { - ReadConsoleInput(hConIn,ir,1,count); - if (ir->EventType == MOUSE_EVENT) { - if ((ir->Event.MouseEvent.dwEventFlags == 0) && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) { - cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1; - cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1; + if (valid) + return ch; + } else { + ReadConsoleInput(hConIn, ir, 1, count); + if (ir->EventType == MOUSE_EVENT) { + if ((ir->Event.MouseEvent.dwEventFlags == 0) + && (ir->Event.MouseEvent.dwButtonState + & MOUSEMASK)) { + cc->x = + ir->Event.MouseEvent.dwMousePosition.X + 1; + cc->y = + ir->Event.MouseEvent.dwMousePosition.Y - 1; - if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON) - *mod = CLICK_1; - else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON) - *mod = CLICK_2; -#if 0 /* middle button */ + if (ir->Event.MouseEvent.dwButtonState + & LEFTBUTTON) + *mod = CLICK_1; + else if (ir->Event.MouseEvent.dwButtonState + & RIGHTBUTTON) + *mod = CLICK_2; +#if 0 /* middle button */ else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON) *mod = CLICK_3; -#endif - return 0; - } - } +#endif + return 0; + } + } #if 0 /* We ignore these types of console events */ else if (ir->EventType == FOCUS_EVENT) { @@ -513,96 +531,96 @@ coord *cc; else if (ir->EventType == MENU_EVENT) { } #endif - } - } else - done = 1; - } - } - *mod = 0; - return ch; + } + } else + done = 1; + } + } + *mod = 0; + return ch; } -int __declspec(dllexport) __stdcall -NHkbhit(hConIn, ir) +int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir) HANDLE hConIn; INPUT_RECORD *ir; { - int done = 0; /* true = "stop searching" */ - int retval; /* true = "we had a match" */ - DWORD count; - unsigned short int scan; - unsigned char ch; - unsigned long shiftstate; - int altseq = 0, keycode, vk; - done = 0; - retval = 0; - while (!done) - { - count = 0; - PeekConsoleInput(hConIn,ir,1,&count); - if (count > 0) { - if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { - ch = ir->Event.KeyEvent.uChar.AsciiChar; - scan = ir->Event.KeyEvent.wVirtualScanCode; - shiftstate = ir->Event.KeyEvent.dwControlKeyState; - vk = ir->Event.KeyEvent.wVirtualKeyCode; - keycode = MapVirtualKey(vk, 2); - if (is_altseq(shiftstate)) { - if (ch || inmap(keycode,vk)) altseq = 1; - else altseq = -1; /* invalid altseq */ - } - if (ch || iskeypad(scan) || altseq) { - done = 1; /* Stop looking */ - retval = 1; /* Found what we sought */ - } else { - /* Strange Key event; let's purge it to avoid trouble */ - ReadConsoleInput(hConIn,ir,1,&count); - } + int done = 0; /* true = "stop searching" */ + int retval; /* true = "we had a match" */ + DWORD count; + unsigned short int scan; + unsigned char ch; + unsigned long shiftstate; + int altseq = 0, keycode, vk; + done = 0; + retval = 0; + while (!done) { + count = 0; + PeekConsoleInput(hConIn, ir, 1, &count); + if (count > 0) { + if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { + ch = ir->Event.KeyEvent.uChar.AsciiChar; + scan = ir->Event.KeyEvent.wVirtualScanCode; + shiftstate = ir->Event.KeyEvent.dwControlKeyState; + vk = ir->Event.KeyEvent.wVirtualKeyCode; + keycode = MapVirtualKey(vk, 2); + if (is_altseq(shiftstate)) { + if (ch || inmap(keycode, vk)) + altseq = 1; + else + altseq = -1; /* invalid altseq */ + } + if (ch || iskeypad(scan) || altseq) { + done = 1; /* Stop looking */ + retval = 1; /* Found what we sought */ + } else { + /* Strange Key event; let's purge it to avoid trouble */ + ReadConsoleInput(hConIn, ir, 1, &count); + } - } - else if ((ir->EventType == MOUSE_EVENT && - (ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) { - done = 1; - retval = 1; - } + } else if ((ir->EventType == MOUSE_EVENT + && (ir->Event.MouseEvent.dwButtonState + & MOUSEMASK))) { + done = 1; + retval = 1; + } - else /* Discard it, it's an insignificant event */ - ReadConsoleInput(hConIn,ir,1,&count); - } else /* There are no events in console event queue */ { - done = 1; /* Stop looking */ - retval = 0; - } - } - return retval; + else /* Discard it, it's an insignificant event */ + ReadConsoleInput(hConIn, ir, 1, &count); + } else /* There are no events in console event queue */ { + done = 1; /* Stop looking */ + retval = 0; + } + } + return retval; } - -int __declspec(dllexport) __stdcall -SourceWhere(buf) +int __declspec(dllexport) __stdcall SourceWhere(buf) char **buf; { - if (!buf) return 0; - *buf = where_to_get_source; - return 1; + if (!buf) + return 0; + *buf = where_to_get_source; + return 1; } -int __declspec(dllexport) __stdcall -SourceAuthor(buf) +int __declspec(dllexport) __stdcall SourceAuthor(buf) char **buf; { - if (!buf) return 0; - *buf = author; - return 1; + if (!buf) + return 0; + *buf = author; + return 1; } -int __declspec(dllexport) __stdcall -KeyHandlerName(buf, full) +int __declspec(dllexport) __stdcall KeyHandlerName(buf, full) char **buf; int full; { - if (!buf) return 0; - if (full) *buf = dllname; - else *buf = shortdllname; - return 1; + if (!buf) + return 0; + if (full) + *buf = dllname; + else + *buf = shortdllname; + return 1; } - diff --git a/sys/winnt/ntsound.c b/sys/winnt/ntsound.c index 4da10b390..7af194fab 100644 --- a/sys/winnt/ntsound.c +++ b/sys/winnt/ntsound.c @@ -1,13 +1,13 @@ -/* NetHack 3.6 ntsound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 ntsound.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 ntsound.c $Date: 2009/05/06 10:53:33 $ $Revision: 1.7 $ */ -/* SCCS Id: @(#)ntsound.c 3.5 $NHDT-Date$ */ -/* SCCS Id: @(#)ntsound.c 3.5 $Date: 2009/05/06 10:53:33 $ */ +/* SCCS Id: @(#)ntsound.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */ +/* SCCS Id: @(#)ntsound.c 3.5 $Date: 2009/05/06 10:53:33 $ */ /* Copyright (c) NetHack PC Development Team 1993 */ /* NetHack may be freely redistributed. See license for details. */ /* */ /* * ntsound.c - Windows NT NetHack sound support - * + * *Edit History: * Initial Creation 93/12/11 * @@ -19,12 +19,13 @@ #ifdef USER_SOUNDS -void play_usersound(filename, volume) -const char* filename; +void +play_usersound(filename, volume) +const char *filename; int volume; { -/* pline("play_usersound: %s (%d).", filename, volume); */ - (void)sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT); + /* pline("play_usersound: %s (%d).", filename, volume); */ + (void) sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT); } #endif /*USER_SOUNDS*/ diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 10b0749bf..39e6ba178 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -1,11 +1,11 @@ -/* NetHack 3.6 nttty.c $NHDT-Date: 1430988888 2015/05/07 08:54:48 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.61 $ */ +/* NetHack 3.6 nttty.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.62 $ */ /* Copyright (c) NetHack PC Development Team 1993 */ /* NetHack may be freely redistributed. See license for details. */ /* tty.c - (Windows NT) version */ -/* - * Initial Creation M. Allison 1993/01/31 +/* + * Initial Creation M. Allison 1993/01/31 * Switch to low level console output routines M. Allison 2003/10/01 * Restrict cursor movement until input pending M. Lehotay 2003/10/02 * Call Unicode version of output API on NT R. Chason 2005/10/28 @@ -22,8 +22,8 @@ void FDECL(cmov, (int, int)); void FDECL(nocmov, (int, int)); -int FDECL(process_keystroke, (INPUT_RECORD *, boolean *, - BOOLEAN_P numberpad, int portdebug)); +int FDECL(process_keystroke, + (INPUT_RECORD *, boolean *, BOOLEAN_P numberpad, int portdebug)); /* * The following WIN32 Console API routines are used in this file. @@ -55,7 +55,7 @@ INPUT_RECORD ir; * a final RETURN at the end of the game when launched from the GUI * to prevent the scoreboard (or panic message :-|) from vanishing * immediately after it is displayed, yet not bother when started - * from the command line. + * from the command line. */ int GUILaunched; extern int redirect_stdout; @@ -68,44 +68,22 @@ static boolean has_unicode; static boolean display_cursor_info = FALSE; #endif -extern boolean getreturn_enabled; /* from sys/share/pcsys.c */ +extern boolean getreturn_enabled; /* from sys/share/pcsys.c */ /* dynamic keystroke handling .DLL support */ -typedef int (__stdcall * PROCESS_KEYSTROKE)( - HANDLE, - INPUT_RECORD *, - boolean *, - BOOLEAN_P, - int -); +typedef int(__stdcall *PROCESS_KEYSTROKE)(HANDLE, INPUT_RECORD *, boolean *, + BOOLEAN_P, int); -typedef int (__stdcall * NHKBHIT)( - HANDLE, - INPUT_RECORD * -); +typedef int(__stdcall *NHKBHIT)(HANDLE, INPUT_RECORD *); -typedef int (__stdcall * CHECKINPUT)( - HANDLE, - INPUT_RECORD *, - DWORD *, - BOOLEAN_P, - int, - int *, - coord * -); +typedef int(__stdcall *CHECKINPUT)(HANDLE, INPUT_RECORD *, DWORD *, BOOLEAN_P, + int, int *, coord *); -typedef int (__stdcall * SOURCEWHERE)( - char ** -); +typedef int(__stdcall *SOURCEWHERE)(char **); -typedef int (__stdcall * SOURCEAUTHOR)( - char ** -); +typedef int(__stdcall *SOURCEAUTHOR)(char **); -typedef int (__stdcall * KEYHANDLERNAME)( - char **, - int -); +typedef int(__stdcall *KEYHANDLERNAME)(char **, int); HANDLE hLibrary; PROCESS_KEYSTROKE pProcessKeystroke; @@ -118,46 +96,45 @@ KEYHANDLERNAME pKeyHandlerName; #ifdef CHANGE_COLOR static void NDECL(adjust_palette); static int FDECL(match_color_name, (const char *)); -typedef HWND (WINAPI *GETCONSOLEWINDOW)(); +typedef HWND(WINAPI *GETCONSOLEWINDOW)(); static HWND GetConsoleHandle(void); static HWND GetConsoleHwnd(void); static boolean altered_palette; static COLORREF UserDefinedColors[CLR_MAX]; static COLORREF NetHackColors[CLR_MAX] = { - 0x00000000,0x00c80000,0x0000c850,0x00b4b432, - 0x000000d2,0x00800080,0x000064b4,0x00c0c0c0, - 0x00646464,0x00f06464,0x0000ff00,0x00ffff00, - 0x000000ff,0x00ff00ff,0x0000ffff,0x00ffffff - }; + 0x00000000, 0x00c80000, 0x0000c850, 0x00b4b432, 0x000000d2, 0x00800080, + 0x000064b4, 0x00c0c0c0, 0x00646464, 0x00f06464, 0x0000ff00, 0x00ffff00, + 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff +}; static COLORREF DefaultColors[CLR_MAX] = { - 0x00000000, 0x00800000, 0x00008000, 0x00808000, - 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0, - 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00, - 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff - }; + 0x00000000, 0x00800000, 0x00008000, 0x00808000, 0x00000080, 0x00800080, + 0x00008080, 0x00c0c0c0, 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00, + 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff +}; #endif #ifndef CLR_MAX #define CLR_MAX 16 #endif int ttycolors[CLR_MAX]; -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR static void NDECL(init_ttycolor); -# endif +#endif static void NDECL(really_move_cursor); -#define MAX_OVERRIDES 256 +#define MAX_OVERRIDES 256 unsigned char key_overrides[MAX_OVERRIDES]; static char nullstr[] = ""; -char erase_char,kill_char; +char erase_char, kill_char; -#define DEFTEXTCOLOR ttycolors[7] +#define DEFTEXTCOLOR ttycolors[7] static WORD background = 0; -static WORD foreground = (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED); -static WORD attr = (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED); +static WORD foreground = + (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); +static WORD attr = (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); static DWORD ccount, acount; -static COORD cursor = {0,0}; +static COORD cursor = { 0, 0 }; /* * Called after returning from ! or ^Z @@ -166,16 +143,16 @@ void gettty() { #ifndef TEXTCOLOR - int k; + int k; #endif - erase_char = '\b'; - kill_char = 21; /* cntl-U */ - iflags.cbreak = TRUE; + erase_char = '\b'; + kill_char = 21; /* cntl-U */ + iflags.cbreak = TRUE; #ifdef TEXTCOLOR - init_ttycolor(); + init_ttycolor(); #else - for(k=0; k < CLR_MAX; ++k) - ttycolors[k] = 7; + for (k = 0; k < CLR_MAX; ++k) + ttycolors[k] = 7; #endif } @@ -184,9 +161,10 @@ void settty(s) const char *s; { - cmov(ttyDisplay->curx, ttyDisplay->cury); - end_screen(); - if(s) raw_print(s); + cmov(ttyDisplay->curx, ttyDisplay->cury); + end_screen(); + if (s) + raw_print(s); } /* called by init_nhwindows() and resume_nhwindows() */ @@ -194,22 +172,24 @@ void setftty() { #ifdef CHANGE_COLOR - if (altered_palette) adjust_palette(); + if (altered_palette) + adjust_palette(); #endif - start_screen(); - has_unicode = ((GetVersion() & 0x80000000) == 0); + start_screen(); + has_unicode = ((GetVersion() & 0x80000000) == 0); } void tty_startup(wid, hgt) int *wid, *hgt; { - int twid = origcsbi.srWindow.Right - origcsbi.srWindow.Left + 1; + int twid = origcsbi.srWindow.Right - origcsbi.srWindow.Left + 1; - if (twid > 80) twid = 80; - *wid = twid; - *hgt = origcsbi.srWindow.Bottom - origcsbi.srWindow.Top + 1; - set_option_mod_status("mouse_support", SET_IN_GAME); + if (twid > 80) + twid = 80; + *wid = twid; + *hgt = origcsbi.srWindow.Bottom - origcsbi.srWindow.Top + 1; + set_option_mod_status("mouse_support", SET_IN_GAME); } void @@ -221,53 +201,52 @@ int state; void tty_start_screen() { - if (iflags.num_pad) tty_number_pad(1); /* make keypad send digits */ + if (iflags.num_pad) + tty_number_pad(1); /* make keypad send digits */ } void tty_end_screen() { - clear_screen(); - really_move_cursor(); - if (GetConsoleScreenBufferInfo(hConOut,&csbi)) - { - DWORD ccnt; - COORD newcoord; - - newcoord.X = 0; - newcoord.Y = 0; - FillConsoleOutputAttribute(hConOut, - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, - csbi.dwSize.X * csbi.dwSize.Y, - newcoord, &ccnt); - FillConsoleOutputCharacter(hConOut,' ', - csbi.dwSize.X * csbi.dwSize.Y, - newcoord, &ccnt); - } - FlushConsoleInputBuffer(hConIn); + clear_screen(); + really_move_cursor(); + if (GetConsoleScreenBufferInfo(hConOut, &csbi)) { + DWORD ccnt; + COORD newcoord; + + newcoord.X = 0; + newcoord.Y = 0; + FillConsoleOutputAttribute( + hConOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, + csbi.dwSize.X * csbi.dwSize.Y, newcoord, &ccnt); + FillConsoleOutputCharacter( + hConOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, newcoord, &ccnt); + } + FlushConsoleInputBuffer(hConIn); } -static BOOL CtrlHandler(ctrltype) +static BOOL +CtrlHandler(ctrltype) DWORD ctrltype; { - switch(ctrltype) { - /* case CTRL_C_EVENT: */ - case CTRL_BREAK_EVENT: - clear_screen(); - case CTRL_CLOSE_EVENT: - case CTRL_LOGOFF_EVENT: - case CTRL_SHUTDOWN_EVENT: - getreturn_enabled = FALSE; + switch (ctrltype) { + /* case CTRL_C_EVENT: */ + case CTRL_BREAK_EVENT: + clear_screen(); + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + getreturn_enabled = FALSE; #ifndef NOSAVEONHANGUP - hangup(0); + hangup(0); #endif #if defined(SAFERHANGUP) - CloseHandle(hConIn); /* trigger WAIT_FAILED */ - return TRUE; + CloseHandle(hConIn); /* trigger WAIT_FAILED */ + return TRUE; #endif - default: - return FALSE; - } + default: + return FALSE; + } } /* called by init_tty in wintty.c for WIN32 port only */ @@ -275,49 +254,52 @@ void nttty_open(mode) int mode; { - HANDLE hStdOut; - DWORD cmode; - long mask; + HANDLE hStdOut; + DWORD cmode; + long mask; -try: - /* The following lines of code were suggested by + try : + /* The following lines of code were suggested by * Bob Landau of Microsoft WIN32 Developer support, * as the only current means of determining whether * we were launched from the command prompt, or from * the NT program manager. M. Allison */ - hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); - if (hStdOut) { - GetConsoleScreenBufferInfo(hStdOut, &origcsbi); - GUILaunched = ((origcsbi.dwCursorPosition.X == 0) && - (origcsbi.dwCursorPosition.Y == 0)); - if ((origcsbi.dwSize.X <= 0) || (origcsbi.dwSize.Y <= 0)) - GUILaunched = 0; - } else if (mode) { - HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); - HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); + hStdOut + = GetStdHandle(STD_OUTPUT_HANDLE); + if (hStdOut) { + GetConsoleScreenBufferInfo(hStdOut, &origcsbi); + GUILaunched = ((origcsbi.dwCursorPosition.X == 0) + && (origcsbi.dwCursorPosition.Y == 0)); + if ((origcsbi.dwSize.X <= 0) || (origcsbi.dwSize.Y <= 0)) + GUILaunched = 0; + } else if (mode) { + HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); - if (!hStdOut && !hStdIn) { - /* Bool rval; */ - AllocConsole(); - AttachConsole(GetCurrentProcessId()); - /* rval = SetStdHandle(STD_OUTPUT_HANDLE, hWrite); */ - freopen("CON", "w", stdout); - freopen("CON", "r", stdin); - } - mode = 0; - goto try; - } else return; + if (!hStdOut && !hStdIn) { + /* Bool rval; */ + AllocConsole(); + AttachConsole(GetCurrentProcessId()); + /* rval = SetStdHandle(STD_OUTPUT_HANDLE, hWrite); */ + freopen("CON", "w", stdout); + freopen("CON", "r", stdin); + } + mode = 0; + goto try + ; + } else + return; - load_keyboard_handler(); - /* Initialize the function pointer that points to - * the kbhit() equivalent, in this TTY case nttty_kbhit() - */ - nt_kbhit = nttty_kbhit; + load_keyboard_handler(); + /* Initialize the function pointer that points to + * the kbhit() equivalent, in this TTY case nttty_kbhit() + */ + nt_kbhit = nttty_kbhit; /* Obtain handles for the standard Console I/O devices */ - hConIn = GetStdHandle(STD_INPUT_HANDLE); - hConOut = GetStdHandle(STD_OUTPUT_HANDLE); + hConIn = GetStdHandle(STD_INPUT_HANDLE); + hConOut = GetStdHandle(STD_OUTPUT_HANDLE); #if 0 hConIn = CreateFile("CONIN$", GENERIC_READ |GENERIC_WRITE, @@ -327,210 +309,201 @@ try: GENERIC_READ |GENERIC_WRITE, FILE_SHARE_READ |FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0); -#endif +#endif - GetConsoleMode(hConIn,&cmode); + GetConsoleMode(hConIn, &cmode); #ifdef NO_MOUSE_ALLOWED - mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | - ENABLE_MOUSE_INPUT | ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT; + mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_MOUSE_INPUT + | ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT; #else - mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | - ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT; + mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT + | ENABLE_WINDOW_INPUT; #endif - /* Turn OFF the settings specified in the mask */ - cmode &= ~mask; + /* Turn OFF the settings specified in the mask */ + cmode &= ~mask; #ifndef NO_MOUSE_ALLOWED - cmode |= ENABLE_MOUSE_INPUT; + cmode |= ENABLE_MOUSE_INPUT; #endif - SetConsoleMode(hConIn,cmode); - if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE)) { - /* Unable to set control handler */ - cmode = 0; /* just to have a statement to break on for debugger */ - } - get_scr_size(); - cursor.X = cursor.Y = 0; - really_move_cursor(); + SetConsoleMode(hConIn, cmode); + if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) { + /* Unable to set control handler */ + cmode = 0; /* just to have a statement to break on for debugger */ + } + get_scr_size(); + cursor.X = cursor.Y = 0; + really_move_cursor(); } -int process_keystroke(ir, valid, numberpad, portdebug) +int +process_keystroke(ir, valid, numberpad, portdebug) INPUT_RECORD *ir; boolean *valid; boolean numberpad; int portdebug; { - int ch = pProcessKeystroke(hConIn, ir, valid, numberpad, portdebug); - /* check for override */ - if (ch && ch < MAX_OVERRIDES && key_overrides[ch]) - ch = key_overrides[ch]; - return ch; + int ch = pProcessKeystroke(hConIn, ir, valid, numberpad, portdebug); + /* check for override */ + if (ch && ch < MAX_OVERRIDES && key_overrides[ch]) + ch = key_overrides[ch]; + return ch; } int nttty_kbhit() { - return pNHkbhit(hConIn, &ir); + return pNHkbhit(hConIn, &ir); } - void get_scr_size() { - GetConsoleScreenBufferInfo(hConOut, &csbi); - - LI = csbi.srWindow.Bottom - (csbi.srWindow.Top + 1); - CO = csbi.srWindow.Right - (csbi.srWindow.Left + 1); + GetConsoleScreenBufferInfo(hConOut, &csbi); - if ( (LI < 25) || (CO < 80) ) { - COORD newcoord; - - LI = 25; - CO = 80; + LI = csbi.srWindow.Bottom - (csbi.srWindow.Top + 1); + CO = csbi.srWindow.Right - (csbi.srWindow.Left + 1); - newcoord.Y = LI; - newcoord.X = CO; + if ((LI < 25) || (CO < 80)) { + COORD newcoord; - SetConsoleScreenBufferSize( hConOut, newcoord ); - } + LI = 25; + CO = 80; + + newcoord.Y = LI; + newcoord.X = CO; + + SetConsoleScreenBufferSize(hConOut, newcoord); + } } int tgetch() { - int mod; - coord cc; - DWORD count; - really_move_cursor(); - return (program_state.done_hup) ? - '\033' : - pCheckInput(hConIn, &ir, &count, iflags.num_pad, 0, &mod, &cc); + int mod; + coord cc; + DWORD count; + really_move_cursor(); + return (program_state.done_hup) + ? '\033' + : pCheckInput(hConIn, &ir, &count, iflags.num_pad, 0, &mod, + &cc); } int ntposkey(x, y, mod) int *x, *y, *mod; { - int ch; - coord cc; - DWORD count; - really_move_cursor(); - ch = (program_state.done_hup) ? - '\033' : - pCheckInput(hConIn, &ir, &count, iflags.num_pad, 1, mod, &cc); - if (!ch) { - *x = cc.x; - *y = cc.y; - } - return ch; + int ch; + coord cc; + DWORD count; + really_move_cursor(); + ch = (program_state.done_hup) + ? '\033' + : pCheckInput(hConIn, &ir, &count, iflags.num_pad, 1, mod, &cc); + if (!ch) { + *x = cc.x; + *y = cc.y; + } + return ch; } static void really_move_cursor() { #ifdef PORT_DEBUG - char oldtitle[BUFSZ], newtitle[BUFSZ]; - if (display_cursor_info && wizard) { - oldtitle[0] = '\0'; - if (GetConsoleTitle(oldtitle, BUFSZ)) { - oldtitle[39] = '\0'; - } - Sprintf(newtitle, "%-55s tty=(%02d,%02d) nttty=(%02d,%02d)", - oldtitle, ttyDisplay->curx, ttyDisplay->cury, - cursor.X, cursor.Y); - (void)SetConsoleTitle(newtitle); - } + char oldtitle[BUFSZ], newtitle[BUFSZ]; + if (display_cursor_info && wizard) { + oldtitle[0] = '\0'; + if (GetConsoleTitle(oldtitle, BUFSZ)) { + oldtitle[39] = '\0'; + } + Sprintf(newtitle, "%-55s tty=(%02d,%02d) nttty=(%02d,%02d)", oldtitle, + ttyDisplay->curx, ttyDisplay->cury, cursor.X, cursor.Y); + (void) SetConsoleTitle(newtitle); + } #endif - if (ttyDisplay) { - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - } - SetConsoleCursorPosition(hConOut, cursor); + if (ttyDisplay) { + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + } + SetConsoleCursorPosition(hConOut, cursor); } void cmov(x, y) register int x, y; { - ttyDisplay->cury = y; - ttyDisplay->curx = x; - cursor.X = x; - cursor.Y = y; + ttyDisplay->cury = y; + ttyDisplay->curx = x; + cursor.X = x; + cursor.Y = y; } void nocmov(x, y) -int x,y; +int x, y; { - cursor.X = x; - cursor.Y = y; - ttyDisplay->curx = x; - ttyDisplay->cury = y; + cursor.X = x; + cursor.Y = y; + ttyDisplay->curx = x; + ttyDisplay->cury = y; } void xputc_core(ch) char ch; { - switch(ch) { - case '\n': - cursor.Y++; - /* fall through */ - case '\r': - cursor.X = 1; - break; - case '\b': - cursor.X--; - break; - default: - WriteConsoleOutputAttribute(hConOut,&attr,1, - cursor,&acount); - if (has_unicode) { - /* Avoid bug in ANSI API on WinNT */ - WCHAR c2[2]; - int rc; - rc = MultiByteToWideChar( - GetConsoleOutputCP(), - 0, - &ch, 1, - c2, 2); - WriteConsoleOutputCharacterW(hConOut,c2,rc, - cursor,&ccount); - } - else { - WriteConsoleOutputCharacterA(hConOut,&ch,1, - cursor,&ccount); - } - cursor.X++; - } + switch (ch) { + case '\n': + cursor.Y++; + /* fall through */ + case '\r': + cursor.X = 1; + break; + case '\b': + cursor.X--; + break; + default: + WriteConsoleOutputAttribute(hConOut, &attr, 1, cursor, &acount); + if (has_unicode) { + /* Avoid bug in ANSI API on WinNT */ + WCHAR c2[2]; + int rc; + rc = MultiByteToWideChar(GetConsoleOutputCP(), 0, &ch, 1, c2, 2); + WriteConsoleOutputCharacterW(hConOut, c2, rc, cursor, &ccount); + } else { + WriteConsoleOutputCharacterA(hConOut, &ch, 1, cursor, &ccount); + } + cursor.X++; + } } void xputc(ch) char ch; { - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - xputc_core(ch); + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + xputc_core(ch); } void xputs(s) const char *s; { - int k; - int slen = strlen(s); + int k; + int slen = strlen(s); - if (ttyDisplay) { - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - } + if (ttyDisplay) { + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + } - if (s) { - for (k=0; k < slen && s[k]; ++k) - xputc_core(s[k]); - } + if (s) { + for (k = 0; k < slen && s[k]; ++k) + xputc_core(s[k]); + } } - /* * Overrides wintty.c function of the same name * for win32. It is used for glyphs only, not text. @@ -539,154 +512,147 @@ void g_putch(in_ch) int in_ch; { - /* CP437 to Unicode mapping according to the Unicode Consortium */ - static const WCHAR cp437[] = - { - 0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, - 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, - 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, - 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, - 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, - 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, - 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, - 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, - 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, - 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, - 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, - 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, - 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, - 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, - 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, - 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302, - 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, - 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, - 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, - 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, - 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, - 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, - 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, - 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, - 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, - 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, - 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, - 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, - 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, - 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, - 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, - 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0 - }; - unsigned char ch = (unsigned char)in_ch; + /* CP437 to Unicode mapping according to the Unicode Consortium */ + static const WCHAR cp437[] = { + 0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, + 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, + 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, + 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, + 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, + 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, + 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, + 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, + 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, + 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, + 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, + 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, + 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, + 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, + 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302, + 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, + 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, + 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, + 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, + 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, + 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, + 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, + 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, + 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, + 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, + 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, + 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, + 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0 + }; + unsigned char ch = (unsigned char) in_ch; - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - WriteConsoleOutputAttribute(hConOut,&attr,1,cursor,&acount); - if (has_unicode) - WriteConsoleOutputCharacterW(hConOut,&cp437[ch],1,cursor,&ccount); - else - WriteConsoleOutputCharacterA(hConOut,&ch,1,cursor,&ccount); + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + WriteConsoleOutputAttribute(hConOut, &attr, 1, cursor, &acount); + if (has_unicode) + WriteConsoleOutputCharacterW(hConOut, &cp437[ch], 1, cursor, &ccount); + else + WriteConsoleOutputCharacterA(hConOut, &ch, 1, cursor, &ccount); } void cl_end() { - int cx; - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - cx = CO - cursor.X; - FillConsoleOutputAttribute(hConOut, DEFTEXTCOLOR, cx, cursor, &acount); - FillConsoleOutputCharacter(hConOut,' ', cx, cursor,&ccount); - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, - (int)ttyDisplay->cury); + int cx; + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + cx = CO - cursor.X; + FillConsoleOutputAttribute(hConOut, DEFTEXTCOLOR, cx, cursor, &acount); + FillConsoleOutputCharacter(hConOut, ' ', cx, cursor, &ccount); + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury); } - void raw_clear_screen() { - if (GetConsoleScreenBufferInfo(hConOut,&csbi)) { - DWORD ccnt; - COORD newcoord; - - newcoord.X = 0; - newcoord.Y = 0; - FillConsoleOutputAttribute(hConOut, - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, - csbi.dwSize.X * csbi.dwSize.Y, - newcoord, &ccnt); - FillConsoleOutputCharacter(hConOut,' ', - csbi.dwSize.X * csbi.dwSize.Y, - newcoord, &ccnt); - } + if (GetConsoleScreenBufferInfo(hConOut, &csbi)) { + DWORD ccnt; + COORD newcoord; + + newcoord.X = 0; + newcoord.Y = 0; + FillConsoleOutputAttribute( + hConOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, + csbi.dwSize.X * csbi.dwSize.Y, newcoord, &ccnt); + FillConsoleOutputCharacter( + hConOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, newcoord, &ccnt); + } } void clear_screen() { - raw_clear_screen(); - home(); + raw_clear_screen(); + home(); } - void home() { - cursor.X = cursor.Y = 0; - ttyDisplay->curx = ttyDisplay->cury = 0; + cursor.X = cursor.Y = 0; + ttyDisplay->curx = ttyDisplay->cury = 0; } - void backsp() { - cursor.X = ttyDisplay->curx; - cursor.Y = ttyDisplay->cury; - xputc_core('\b'); + cursor.X = ttyDisplay->curx; + cursor.Y = ttyDisplay->cury; + xputc_core('\b'); } void cl_eos() { - int cy = ttyDisplay->cury+1; - if (GetConsoleScreenBufferInfo(hConOut,&csbi)) { - DWORD ccnt; - COORD newcoord; - - newcoord.X = ttyDisplay->curx; - newcoord.Y = ttyDisplay->cury; - FillConsoleOutputAttribute(hConOut, - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, - csbi.dwSize.X * csbi.dwSize.Y - cy, - newcoord, &ccnt); - FillConsoleOutputCharacter(hConOut,' ', - csbi.dwSize.X * csbi.dwSize.Y - cy, - newcoord, &ccnt); - } - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, (int)ttyDisplay->cury); + int cy = ttyDisplay->cury + 1; + if (GetConsoleScreenBufferInfo(hConOut, &csbi)) { + DWORD ccnt; + COORD newcoord; + + newcoord.X = ttyDisplay->curx; + newcoord.Y = ttyDisplay->cury; + FillConsoleOutputAttribute( + hConOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, + csbi.dwSize.X * csbi.dwSize.Y - cy, newcoord, &ccnt); + FillConsoleOutputCharacter(hConOut, ' ', + csbi.dwSize.X * csbi.dwSize.Y - cy, + newcoord, &ccnt); + } + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury); } void tty_nhbell() { - if (flags.silent) return; - Beep(8000,500); + if (flags.silent) + return; + Beep(8000, 500); } -volatile int junk; /* prevent optimizer from eliminating loop below */ +volatile int junk; /* prevent optimizer from eliminating loop below */ void tty_delay_output() { - /* delay 50 ms - uses ANSI C clock() function now */ - clock_t goal; - int k; + /* delay 50 ms - uses ANSI C clock() function now */ + clock_t goal; + int k; - goal = 50 + clock(); - while (goal > clock()) { - k = junk; /* Do nothing */ - } + goal = 50 + clock(); + while (goal > clock()) { + k = junk; /* Do nothing */ + } } -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR /* * CLR_BLACK 0 * CLR_RED 1 @@ -711,67 +677,70 @@ tty_delay_output() static void init_ttycolor() { - ttycolors[CLR_BLACK] = FOREGROUND_INTENSITY; /* fix by Quietust */ - ttycolors[CLR_RED] = FOREGROUND_RED; - ttycolors[CLR_GREEN] = FOREGROUND_GREEN; - ttycolors[CLR_BROWN] = FOREGROUND_GREEN|FOREGROUND_RED; - ttycolors[CLR_BLUE] = FOREGROUND_BLUE; - ttycolors[CLR_MAGENTA] = FOREGROUND_BLUE|FOREGROUND_RED; - ttycolors[CLR_CYAN] = FOREGROUND_GREEN|FOREGROUND_BLUE; - ttycolors[CLR_GRAY] = FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE; - ttycolors[BRIGHT] = FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|\ - FOREGROUND_INTENSITY; - ttycolors[CLR_ORANGE] = FOREGROUND_RED|FOREGROUND_INTENSITY; - ttycolors[CLR_BRIGHT_GREEN] = FOREGROUND_GREEN|FOREGROUND_INTENSITY; - ttycolors[CLR_YELLOW] = FOREGROUND_GREEN|FOREGROUND_RED|\ - FOREGROUND_INTENSITY; - ttycolors[CLR_BRIGHT_BLUE] = FOREGROUND_BLUE|FOREGROUND_INTENSITY; - ttycolors[CLR_BRIGHT_MAGENTA] = FOREGROUND_BLUE|FOREGROUND_RED|\ - FOREGROUND_INTENSITY; - ttycolors[CLR_BRIGHT_CYAN] = FOREGROUND_GREEN|FOREGROUND_BLUE|\ - FOREGROUND_INTENSITY; - ttycolors[CLR_WHITE] = FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|\ - FOREGROUND_INTENSITY; + ttycolors[CLR_BLACK] = FOREGROUND_INTENSITY; /* fix by Quietust */ + ttycolors[CLR_RED] = FOREGROUND_RED; + ttycolors[CLR_GREEN] = FOREGROUND_GREEN; + ttycolors[CLR_BROWN] = FOREGROUND_GREEN | FOREGROUND_RED; + ttycolors[CLR_BLUE] = FOREGROUND_BLUE; + ttycolors[CLR_MAGENTA] = FOREGROUND_BLUE | FOREGROUND_RED; + ttycolors[CLR_CYAN] = FOREGROUND_GREEN | FOREGROUND_BLUE; + ttycolors[CLR_GRAY] = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; + ttycolors[BRIGHT] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED + | FOREGROUND_INTENSITY; + ttycolors[CLR_ORANGE] = FOREGROUND_RED | FOREGROUND_INTENSITY; + ttycolors[CLR_BRIGHT_GREEN] = FOREGROUND_GREEN | FOREGROUND_INTENSITY; + ttycolors[CLR_YELLOW] = + FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY; + ttycolors[CLR_BRIGHT_BLUE] = FOREGROUND_BLUE | FOREGROUND_INTENSITY; + ttycolors[CLR_BRIGHT_MAGENTA] = + FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY; + ttycolors[CLR_BRIGHT_CYAN] = + FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; + ttycolors[CLR_WHITE] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED + | FOREGROUND_INTENSITY; } -# endif /* TEXTCOLOR */ +#endif /* TEXTCOLOR */ int has_color(int color) { -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR return 1; -# else +#else if (color == CLR_BLACK) - return 1; + return 1; else if (color == CLR_WHITE) - return 1; + return 1; else - return 0; -# endif + return 0; +#endif } void term_start_attr(int attrib) { - switch(attrib){ - case ATR_INVERSE: - if (iflags.wc_inverse) { - /* Suggestion by Lee Berger */ - if ((foreground & (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED)) == - (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED)) - foreground &= ~(FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED); - background = (BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN); - break; - } - /*FALLTHRU*/ - case ATR_ULINE: - case ATR_BLINK: - case ATR_BOLD: - foreground |= FOREGROUND_INTENSITY; - break; - default: - foreground &= ~FOREGROUND_INTENSITY; - break; + switch (attrib) { + case ATR_INVERSE: + if (iflags.wc_inverse) { + /* Suggestion by Lee Berger */ + if ((foreground + & (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)) + == (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)) + foreground &= + ~(FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); + background = + (BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN); + break; + } + /*FALLTHRU*/ + case ATR_ULINE: + case ATR_BLINK: + case ATR_BOLD: + foreground |= FOREGROUND_INTENSITY; + break; + default: + foreground &= ~FOREGROUND_INTENSITY; + break; } attr = (foreground | background); } @@ -779,19 +748,20 @@ term_start_attr(int attrib) void term_end_attr(int attrib) { - switch(attrib){ - - case ATR_INVERSE: - if ((foreground & (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED)) == 0) - foreground |= (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED); - background = 0; - break; - case ATR_ULINE: - case ATR_BLINK: - case ATR_BOLD: - foreground &= ~FOREGROUND_INTENSITY; - break; - } + switch (attrib) { + case ATR_INVERSE: + if ((foreground + & (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)) == 0) + foreground |= + (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); + background = 0; + break; + case ATR_ULINE: + case ATR_BLINK: + case ATR_BOLD: + foreground &= ~FOREGROUND_INTENSITY; + break; + } attr = (foreground | background); } @@ -811,33 +781,33 @@ void term_start_color(int color) { #ifdef TEXTCOLOR - if (color >= 0 && color < CLR_MAX) { - foreground = (background != 0 && (color == CLR_GRAY || color == CLR_WHITE)) ? - ttycolors[0] : ttycolors[color]; - } + if (color >= 0 && color < CLR_MAX) { + foreground = + (background != 0 && (color == CLR_GRAY || color == CLR_WHITE)) + ? ttycolors[0] + : ttycolors[color]; + } #else - foreground = DEFTEXTCOLOR; + foreground = DEFTEXTCOLOR; #endif - attr = (foreground | background); + attr = (foreground | background); } void term_end_color(void) { #ifdef TEXTCOLOR - foreground = DEFTEXTCOLOR; + foreground = DEFTEXTCOLOR; #endif - attr = (foreground | background); + attr = (foreground | background); } - void standoutbeg() { term_start_attr(ATR_BOLD); } - void standoutend() { @@ -848,76 +818,78 @@ standoutend() void toggle_mouse_support() { - DWORD cmode; - GetConsoleMode(hConIn,&cmode); - if (iflags.wc_mouse_support) - cmode |= ENABLE_MOUSE_INPUT; - else - cmode &= ~ENABLE_MOUSE_INPUT; - SetConsoleMode(hConIn,cmode); + DWORD cmode; + GetConsoleMode(hConIn, &cmode); + if (iflags.wc_mouse_support) + cmode |= ENABLE_MOUSE_INPUT; + else + cmode &= ~ENABLE_MOUSE_INPUT; + SetConsoleMode(hConIn, cmode); } #endif /* handle tty options updates here */ -void nttty_preference_update(pref) +void +nttty_preference_update(pref) const char *pref; { - if( stricmp( pref, "mouse_support")==0) { + if (stricmp(pref, "mouse_support") == 0) { #ifndef NO_MOUSE_ALLOWED - toggle_mouse_support(); + toggle_mouse_support(); #endif - } - return; + } + return; } #ifdef PORT_DEBUG void win32con_debug_keystrokes() { - DWORD count; - boolean valid = 0; - int ch; - xputs("\n"); - while (!valid || ch != 27) { - nocmov(ttyDisplay->curx, ttyDisplay->cury); - ReadConsoleInput(hConIn,&ir,1,&count); - if ((ir.EventType == KEY_EVENT) && ir.Event.KeyEvent.bKeyDown) - ch = process_keystroke(&ir, &valid, iflags.num_pad, 1); - } - (void)doredraw(); + DWORD count; + boolean valid = 0; + int ch; + xputs("\n"); + while (!valid || ch != 27) { + nocmov(ttyDisplay->curx, ttyDisplay->cury); + ReadConsoleInput(hConIn, &ir, 1, &count); + if ((ir.EventType == KEY_EVENT) && ir.Event.KeyEvent.bKeyDown) + ch = process_keystroke(&ir, &valid, iflags.num_pad, 1); + } + (void) doredraw(); } void win32con_handler_info() { - char *buf; - int ci; - if (!pSourceAuthor && !pSourceWhere) - pline("Keyboard handler source info and author unavailable."); - else { - if (pKeyHandlerName && pKeyHandlerName(&buf, 1)) { - xputs("\n"); - xputs("Keystroke handler loaded: \n "); - xputs(buf); - } - if (pSourceAuthor && pSourceAuthor(&buf)) { - xputs("\n"); - xputs("Keystroke handler Author: \n "); - xputs(buf); - } - if (pSourceWhere && pSourceWhere(&buf)) { - xputs("\n"); - xputs("Keystroke handler source code available at:\n "); - xputs(buf); - } - xputs("\nPress any key to resume."); - ci=nhgetch(); - (void)doredraw(); - } + char *buf; + int ci; + if (!pSourceAuthor && !pSourceWhere) + pline("Keyboard handler source info and author unavailable."); + else { + if (pKeyHandlerName && pKeyHandlerName(&buf, 1)) { + xputs("\n"); + xputs("Keystroke handler loaded: \n "); + xputs(buf); + } + if (pSourceAuthor && pSourceAuthor(&buf)) { + xputs("\n"); + xputs("Keystroke handler Author: \n "); + xputs(buf); + } + if (pSourceWhere && pSourceWhere(&buf)) { + xputs("\n"); + xputs("Keystroke handler source code available at:\n "); + xputs(buf); + } + xputs("\nPress any key to resume."); + ci = nhgetch(); + (void) doredraw(); + } } -void win32con_toggle_cursor_info() +void +win32con_toggle_cursor_info() { - display_cursor_info = !display_cursor_info; + display_cursor_info = !display_cursor_info; } #endif @@ -925,228 +897,235 @@ void map_subkeyvalue(op) register char *op; { - char digits[] = "0123456789"; - int length, i, idx, val; - char *kp; + char digits[] = "0123456789"; + int length, i, idx, val; + char *kp; - idx = -1; - val = -1; - kp = index(op, '/'); - if (kp) { - *kp = '\0'; - kp++; - length = strlen(kp); - if (length < 1 || length > 3) return; - for (i = 0; i < length; i++) - if (!index(digits, kp[i])) return; - val = atoi(kp); - length = strlen(op); - if (length < 1 || length > 3) return; - for (i = 0; i < length; i++) - if (!index(digits, op[i])) return; - idx = atoi(op); - } - if (idx >= MAX_OVERRIDES || idx < 0 || val >= MAX_OVERRIDES || val < 1) - return; - key_overrides[idx] = val; + idx = -1; + val = -1; + kp = index(op, '/'); + if (kp) { + *kp = '\0'; + kp++; + length = strlen(kp); + if (length < 1 || length > 3) + return; + for (i = 0; i < length; i++) + if (!index(digits, kp[i])) + return; + val = atoi(kp); + length = strlen(op); + if (length < 1 || length > 3) + return; + for (i = 0; i < length; i++) + if (!index(digits, op[i])) + return; + idx = atoi(op); + } + if (idx >= MAX_OVERRIDES || idx < 0 || val >= MAX_OVERRIDES || val < 1) + return; + key_overrides[idx] = val; } void load_keyboard_handler() { - char suffx[] = ".dll"; - char *truncspot; + char suffx[] = ".dll"; + char *truncspot; #define MAX_DLLNAME 25 - char kh[MAX_ALTKEYHANDLER]; - if (iflags.altkeyhandler[0]) { - if (hLibrary) { /* already one loaded apparently */ - FreeLibrary(hLibrary); - hLibrary = (HANDLE)0; - pNHkbhit = (NHKBHIT)0; - pCheckInput = (CHECKINPUT)0; - pSourceWhere = (SOURCEWHERE)0; - pSourceAuthor = (SOURCEAUTHOR)0; - pKeyHandlerName = (KEYHANDLERNAME)0; - pProcessKeystroke = (PROCESS_KEYSTROKE)0; - } - if ((truncspot = strstri(iflags.altkeyhandler, suffx)) != 0) - *truncspot = '\0'; - (void) strncpy(kh, iflags.altkeyhandler, - (MAX_ALTKEYHANDLER - sizeof suffx) - 1); - kh[(MAX_ALTKEYHANDLER - sizeof suffx) - 1] = '\0'; - Strcat(kh, suffx); - Strcpy(iflags.altkeyhandler, kh); - hLibrary = LoadLibrary(kh); - if (hLibrary) { - pProcessKeystroke = - (PROCESS_KEYSTROKE) GetProcAddress (hLibrary, TEXT ("ProcessKeystroke")); - pNHkbhit = - (NHKBHIT) GetProcAddress (hLibrary, TEXT ("NHkbhit")); - pCheckInput = - (CHECKINPUT) GetProcAddress (hLibrary, TEXT ("CheckInput")); - pSourceWhere = - (SOURCEWHERE) GetProcAddress (hLibrary, TEXT ("SourceWhere")); - pSourceAuthor = - (SOURCEAUTHOR) GetProcAddress (hLibrary, TEXT ("SourceAuthor")); - pKeyHandlerName = - (KEYHANDLERNAME) GetProcAddress (hLibrary, TEXT ("KeyHandlerName")); - } - } - if (!pProcessKeystroke || !pNHkbhit || !pCheckInput) { - if (hLibrary) { - FreeLibrary(hLibrary); - hLibrary = (HANDLE)0; - pNHkbhit = (NHKBHIT)0; - pCheckInput = (CHECKINPUT)0; - pSourceWhere = (SOURCEWHERE)0; - pSourceAuthor = (SOURCEAUTHOR)0; - pKeyHandlerName = (KEYHANDLERNAME)0; - pProcessKeystroke = (PROCESS_KEYSTROKE)0; - } - (void)strncpy(kh, "nhdefkey.dll", (MAX_ALTKEYHANDLER - sizeof suffx) - 1); - kh[(MAX_ALTKEYHANDLER - sizeof suffx) - 1] = '\0'; - Strcpy(iflags.altkeyhandler, kh); - hLibrary = LoadLibrary(kh); - if (hLibrary) { - pProcessKeystroke = - (PROCESS_KEYSTROKE) GetProcAddress (hLibrary, TEXT ("ProcessKeystroke")); - pCheckInput = - (CHECKINPUT) GetProcAddress (hLibrary, TEXT ("CheckInput")); - pNHkbhit = - (NHKBHIT) GetProcAddress (hLibrary, TEXT ("NHkbhit")); - pSourceWhere = - (SOURCEWHERE) GetProcAddress (hLibrary, TEXT ("SourceWhere")); - pSourceAuthor = - (SOURCEAUTHOR) GetProcAddress (hLibrary, TEXT ("SourceAuthor")); - pKeyHandlerName = - (KEYHANDLERNAME) GetProcAddress (hLibrary, TEXT ("KeyHandlerName")); - } - } - if (!pProcessKeystroke || !pNHkbhit || !pCheckInput) { - if (!hLibrary) - raw_printf("\nNetHack was unable to load keystroke handler.\n"); - else { - FreeLibrary(hLibrary); - hLibrary = (HANDLE)0; - raw_printf("\nNetHack keystroke handler is invalid.\n"); - } - exit(EXIT_FAILURE); - } + char kh[MAX_ALTKEYHANDLER]; + if (iflags.altkeyhandler[0]) { + if (hLibrary) { /* already one loaded apparently */ + FreeLibrary(hLibrary); + hLibrary = (HANDLE) 0; + pNHkbhit = (NHKBHIT) 0; + pCheckInput = (CHECKINPUT) 0; + pSourceWhere = (SOURCEWHERE) 0; + pSourceAuthor = (SOURCEAUTHOR) 0; + pKeyHandlerName = (KEYHANDLERNAME) 0; + pProcessKeystroke = (PROCESS_KEYSTROKE) 0; + } + if ((truncspot = strstri(iflags.altkeyhandler, suffx)) != 0) + *truncspot = '\0'; + (void) strncpy(kh, iflags.altkeyhandler, + (MAX_ALTKEYHANDLER - sizeof suffx) - 1); + kh[(MAX_ALTKEYHANDLER - sizeof suffx) - 1] = '\0'; + Strcat(kh, suffx); + Strcpy(iflags.altkeyhandler, kh); + hLibrary = LoadLibrary(kh); + if (hLibrary) { + pProcessKeystroke = (PROCESS_KEYSTROKE) GetProcAddress( + hLibrary, TEXT("ProcessKeystroke")); + pNHkbhit = (NHKBHIT) GetProcAddress(hLibrary, TEXT("NHkbhit")); + pCheckInput = + (CHECKINPUT) GetProcAddress(hLibrary, TEXT("CheckInput")); + pSourceWhere = + (SOURCEWHERE) GetProcAddress(hLibrary, TEXT("SourceWhere")); + pSourceAuthor = + (SOURCEAUTHOR) GetProcAddress(hLibrary, TEXT("SourceAuthor")); + pKeyHandlerName = (KEYHANDLERNAME) GetProcAddress( + hLibrary, TEXT("KeyHandlerName")); + } + } + if (!pProcessKeystroke || !pNHkbhit || !pCheckInput) { + if (hLibrary) { + FreeLibrary(hLibrary); + hLibrary = (HANDLE) 0; + pNHkbhit = (NHKBHIT) 0; + pCheckInput = (CHECKINPUT) 0; + pSourceWhere = (SOURCEWHERE) 0; + pSourceAuthor = (SOURCEAUTHOR) 0; + pKeyHandlerName = (KEYHANDLERNAME) 0; + pProcessKeystroke = (PROCESS_KEYSTROKE) 0; + } + (void) strncpy(kh, "nhdefkey.dll", + (MAX_ALTKEYHANDLER - sizeof suffx) - 1); + kh[(MAX_ALTKEYHANDLER - sizeof suffx) - 1] = '\0'; + Strcpy(iflags.altkeyhandler, kh); + hLibrary = LoadLibrary(kh); + if (hLibrary) { + pProcessKeystroke = (PROCESS_KEYSTROKE) GetProcAddress( + hLibrary, TEXT("ProcessKeystroke")); + pCheckInput = + (CHECKINPUT) GetProcAddress(hLibrary, TEXT("CheckInput")); + pNHkbhit = (NHKBHIT) GetProcAddress(hLibrary, TEXT("NHkbhit")); + pSourceWhere = + (SOURCEWHERE) GetProcAddress(hLibrary, TEXT("SourceWhere")); + pSourceAuthor = + (SOURCEAUTHOR) GetProcAddress(hLibrary, TEXT("SourceAuthor")); + pKeyHandlerName = (KEYHANDLERNAME) GetProcAddress( + hLibrary, TEXT("KeyHandlerName")); + } + } + if (!pProcessKeystroke || !pNHkbhit || !pCheckInput) { + if (!hLibrary) + raw_printf("\nNetHack was unable to load keystroke handler.\n"); + else { + FreeLibrary(hLibrary); + hLibrary = (HANDLE) 0; + raw_printf("\nNetHack keystroke handler is invalid.\n"); + } + exit(EXIT_FAILURE); + } } /* this is used as a printf() replacement when the window * system isn't initialized yet */ -void -msmsg VA_DECL(const char *, fmt) - char buf[ROWNO * COLNO]; /* worst case scenario */ - VA_START(fmt); - VA_INIT(fmt, const char *); - Vsprintf(buf, fmt, VA_ARGS); - VA_END(); - if (redirect_stdout) - fprintf(stdout,"%s",buf); - else { - xputs(buf); - if (ttyDisplay) curs(BASE_WINDOW, cursor.X+1, cursor.Y); - } - return; +void msmsg +VA_DECL(const char *, fmt) + char buf[ROWNO * COLNO]; /* worst case scenario */ + VA_START(fmt); + VA_INIT(fmt, const char *); + Vsprintf(buf, fmt, VA_ARGS); + VA_END(); + if (redirect_stdout) + fprintf(stdout, "%s", buf); + else { + xputs(buf); + if (ttyDisplay) + curs(BASE_WINDOW, cursor.X + 1, cursor.Y); + } + return; } /* fatal error */ /*VARARGS1*/ -void -nttty_error VA_DECL(const char *,s) - char buf[BUFSZ]; - VA_START(s); - VA_INIT(s, const char *); - /* error() may get called before tty is initialized */ - if (iflags.window_inited) end_screen(); - buf[0] = '\n'; - (void) vsprintf(&buf[1], s, VA_ARGS); - VA_END(); - msmsg(buf); - really_move_cursor(); - exit(EXIT_FAILURE); +void nttty_error +VA_DECL(const char *, s) + char buf[BUFSZ]; + VA_START(s); + VA_INIT(s, const char *); + /* error() may get called before tty is initialized */ + if (iflags.window_inited) + end_screen(); + buf[0] = '\n'; + (void) vsprintf(&buf[1], s, VA_ARGS); + VA_END(); + msmsg(buf); + really_move_cursor(); + exit(EXIT_FAILURE); } void synch_cursor() { - really_move_cursor(); + really_move_cursor(); } -# ifdef CHANGE_COLOR -void tty_change_color(color_number, rgb, reverse) +#ifdef CHANGE_COLOR +void +tty_change_color(color_number, rgb, reverse) int color_number, reverse; long rgb; { - /* Map NetHack color index to NT Console palette index */ - int idx, win32_color_number[] = { - 0, /* CLR_BLACK 0 */ - 4, /* CLR_RED 1 */ - 2, /* CLR_GREEN 2 */ - 6, /* CLR_BROWN 3 */ - 1, /* CLR_BLUE 4 */ - 5, /* CLR_MAGENTA 5 */ - 3, /* CLR_CYAN 6 */ - 7, /* CLR_GRAY 7 */ - 8, /* NO_COLOR 8 */ - 12, /* CLR_ORANGE 9 */ - 10, /* CLR_BRIGHT_GREEN 10 */ - 14, /* CLR_YELLOW 11 */ - 9, /* CLR_BRIGHT_BLUE 12 */ - 13, /* CLR_BRIGHT_MAGENTA 13 */ - 11, /* CLR_BRIGHT_CYAN 14 */ - 15 /* CLR_WHITE 15 */ - }; - int k; - if (color_number < 0) { /* indicates OPTIONS=palette with no value */ - /* copy the NetHack palette into UserDefinedColors */ - for (k=0; k < CLR_MAX; k++) - UserDefinedColors[k] = NetHackColors[k]; - } else if (color_number >= 0 && color_number < CLR_MAX) { - if (!altered_palette) { - /* make sure a full suite is available */ - for (k=0; k < CLR_MAX; k++) - UserDefinedColors[k] = DefaultColors[k]; - } - idx = win32_color_number[color_number]; - UserDefinedColors[idx] = rgb; - } - altered_palette = TRUE; + /* Map NetHack color index to NT Console palette index */ + int idx, win32_color_number[] = { + 0, /* CLR_BLACK 0 */ + 4, /* CLR_RED 1 */ + 2, /* CLR_GREEN 2 */ + 6, /* CLR_BROWN 3 */ + 1, /* CLR_BLUE 4 */ + 5, /* CLR_MAGENTA 5 */ + 3, /* CLR_CYAN 6 */ + 7, /* CLR_GRAY 7 */ + 8, /* NO_COLOR 8 */ + 12, /* CLR_ORANGE 9 */ + 10, /* CLR_BRIGHT_GREEN 10 */ + 14, /* CLR_YELLOW 11 */ + 9, /* CLR_BRIGHT_BLUE 12 */ + 13, /* CLR_BRIGHT_MAGENTA 13 */ + 11, /* CLR_BRIGHT_CYAN 14 */ + 15 /* CLR_WHITE 15 */ + }; + int k; + if (color_number < 0) { /* indicates OPTIONS=palette with no value */ + /* copy the NetHack palette into UserDefinedColors */ + for (k = 0; k < CLR_MAX; k++) + UserDefinedColors[k] = NetHackColors[k]; + } else if (color_number >= 0 && color_number < CLR_MAX) { + if (!altered_palette) { + /* make sure a full suite is available */ + for (k = 0; k < CLR_MAX; k++) + UserDefinedColors[k] = DefaultColors[k]; + } + idx = win32_color_number[color_number]; + UserDefinedColors[idx] = rgb; + } + altered_palette = TRUE; } -char *tty_get_color_string() +char * +tty_get_color_string() { - return ""; + return ""; } int match_color_name(c) const char *c; { - const struct others { - int idx; - const char *colorname; - } othernames[] = { - {CLR_MAGENTA, "purple"}, - {CLR_BRIGHT_MAGENTA, "bright purple"}, - {NO_COLOR, "dark gray"}, - {NO_COLOR, "dark grey"}, - {CLR_GRAY, "grey"}, - }; + const struct others { + int idx; + const char *colorname; + } othernames[] = { + { CLR_MAGENTA, "purple" }, + { CLR_BRIGHT_MAGENTA, "bright purple" }, + { NO_COLOR, "dark gray" }, + { NO_COLOR, "dark grey" }, + { CLR_GRAY, "grey" }, + }; - int cnt; - for (cnt = 0; cnt < CLR_MAX; ++cnt) { - if (!strcmpi(c, c_obj_colors[cnt])) - return cnt; - } - for (cnt = 0; cnt < SIZE(othernames); ++cnt) { - if (!strcmpi(c, othernames[cnt].colorname)) - return othernames[cnt].idx; - } - return -1; + int cnt; + for (cnt = 0; cnt < CLR_MAX; ++cnt) { + if (!strcmpi(c, c_obj_colors[cnt])) + return cnt; + } + for (cnt = 0; cnt < SIZE(othernames); ++cnt) { + if (!strcmpi(c, othernames[cnt].colorname)) + return othernames[cnt].idx; + } + return -1; } /* @@ -1155,93 +1134,97 @@ const char *c; int alternative_palette(op) char *op; -{ - /* - * palette:color-R-G-B - * OPTIONS=palette:green-4-3-1, palette:0-0-0-0 - */ - int fieldcnt, color_number, rgb, red, green, blue; - char *fields[4], *cp; +{ + /* + * palette:color-R-G-B + * OPTIONS=palette:green-4-3-1, palette:0-0-0-0 + */ + int fieldcnt, color_number, rgb, red, green, blue; + char *fields[4], *cp; - if (!op) { - change_color(-1,0,0); /* indicates palette option with - no value meaning "load an entire - hard-coded NetHack palette." */ - return 1; - } + if (!op) { + change_color(-1, 0, 0); /* indicates palette option with + no value meaning "load an entire + hard-coded NetHack palette." */ + return 1; + } - cp = fields[0] = op; - for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) { - cp = index(cp, '-'); - if (!cp) return 0; - fields[fieldcnt] = cp; - cp++; - } - for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) { - *(fields[fieldcnt]) = '\0'; - ++fields[fieldcnt]; - } - rgb = 0; - for (fieldcnt = 0; fieldcnt < 4; ++fieldcnt) { - if (fieldcnt == 0 && isalpha(*(fields[0]))) { - color_number = match_color_name(fields[0]); - if (color_number == -1) return 0; - } else { - int dcount = 0, cval = 0; - cp = fields[fieldcnt]; - if (*cp == '\\' && index("0123456789xXoO", cp[1])) { - const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; + cp = fields[0] = op; + for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) { + cp = index(cp, '-'); + if (!cp) + return 0; + fields[fieldcnt] = cp; + cp++; + } + for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) { + *(fields[fieldcnt]) = '\0'; + ++fields[fieldcnt]; + } + rgb = 0; + for (fieldcnt = 0; fieldcnt < 4; ++fieldcnt) { + if (fieldcnt == 0 && isalpha(*(fields[0]))) { + color_number = match_color_name(fields[0]); + if (color_number == -1) + return 0; + } else { + int dcount = 0, cval = 0; + cp = fields[fieldcnt]; + if (*cp == '\\' && index("0123456789xXoO", cp[1])) { + const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; - cp++; - if (*cp == 'x' || *cp == 'X') - for (++cp; (dp = index(hex, *cp)) && (dcount++ < 2); cp++) - cval = (int)((cval * 16) + (dp - hex) / 2); - else if (*cp == 'o' || *cp == 'O') - for (++cp; (index("01234567",*cp)) && (dcount++ < 3); cp++) - cval = (cval * 8) + (*cp - '0'); - else - return 0; - } else { - for (; *cp && (index("0123456789",*cp)) && (dcount++ < 3); cp++) - cval = (cval * 10) + (*cp - '0'); - } - switch(fieldcnt) { - case 0: - color_number = cval; - break; - case 1: - red = cval; - break; - case 2: - green = cval; - break; - case 3: - blue = cval; - break; - } - } - } - rgb = RGB(red,green,blue); - if (color_number >= 0 && color_number < CLR_MAX) - change_color(color_number, rgb, 0); - return 1; + cp++; + if (*cp == 'x' || *cp == 'X') + for (++cp; (dp = index(hex, *cp)) && (dcount++ < 2); cp++) + cval = (int) ((cval * 16) + (dp - hex) / 2); + else if (*cp == 'o' || *cp == 'O') + for (++cp; (index("01234567", *cp)) && (dcount++ < 3); + cp++) + cval = (cval * 8) + (*cp - '0'); + else + return 0; + } else { + for (; *cp && (index("0123456789", *cp)) && (dcount++ < 3); + cp++) + cval = (cval * 10) + (*cp - '0'); + } + switch (fieldcnt) { + case 0: + color_number = cval; + break; + case 1: + red = cval; + break; + case 2: + green = cval; + break; + case 3: + blue = cval; + break; + } + } + } + rgb = RGB(red, green, blue); + if (color_number >= 0 && color_number < CLR_MAX) + change_color(color_number, rgb, 0); + return 1; } -/* +/* * This uses an undocumented method to set console attributes * at runtime including console palette - * + * * VOID WINAPI SetConsolePalette(COLORREF palette[16]) - * + * * Author: James Brown at www.catch22.net - * + * * Set palette of current console. * Palette should be of the form: * - * COLORREF DefaultColors[CLR_MAX] = + * COLORREF DefaultColors[CLR_MAX] = * { * 0x00000000, 0x00800000, 0x00008000, 0x00808000, - * 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0, + * 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0, * 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00, * 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff * }; @@ -1251,38 +1234,37 @@ char *op; /* * Structure to send console via WM_SETCONSOLEINFO - */ -typedef struct _CONSOLE_INFO -{ - ULONG Length; - COORD ScreenBufferSize; - COORD WindowSize; - ULONG WindowPosX; - ULONG WindowPosY; + */ +typedef struct _CONSOLE_INFO { + ULONG Length; + COORD ScreenBufferSize; + COORD WindowSize; + ULONG WindowPosX; + ULONG WindowPosY; - COORD FontSize; - ULONG FontFamily; - ULONG FontWeight; - WCHAR FaceName[32]; + COORD FontSize; + ULONG FontFamily; + ULONG FontWeight; + WCHAR FaceName[32]; - ULONG CursorSize; - ULONG FullScreen; - ULONG QuickEdit; - ULONG AutoPosition; - ULONG InsertMode; - - USHORT ScreenColors; - USHORT PopupColors; - ULONG HistoryNoDup; - ULONG HistoryBufferSize; - ULONG NumberOfHistoryBuffers; - - COLORREF ColorTable[16]; + ULONG CursorSize; + ULONG FullScreen; + ULONG QuickEdit; + ULONG AutoPosition; + ULONG InsertMode; - ULONG CodePage; - HWND Hwnd; + USHORT ScreenColors; + USHORT PopupColors; + ULONG HistoryNoDup; + ULONG HistoryBufferSize; + ULONG NumberOfHistoryBuffers; - WCHAR ConsoleTitle[0x100]; + COLORREF ColorTable[16]; + + ULONG CodePage; + HWND Hwnd; + + WCHAR ConsoleTitle[0x100]; } CONSOLE_INFO; #pragma pack(pop) @@ -1293,8 +1275,8 @@ VOID WINAPI SetConsolePalette(COLORREF crPalette[16]); void adjust_palette(VOID_ARGS) -{ - SetConsolePalette(UserDefinedColors); +{ + SetConsolePalette(UserDefinedColors); altered_palette = 0; } @@ -1303,48 +1285,48 @@ adjust_palette(VOID_ARGS) /* HWND WINAPI GetConsoleWindow(); */ /* Undocumented console message */ -#define WM_SETCONSOLEINFO (WM_USER+201) +#define WM_SETCONSOLEINFO (WM_USER + 201) - -VOID WINAPI SetConsolePalette(COLORREF palette[16]) +VOID WINAPI +SetConsolePalette(COLORREF palette[16]) { - CONSOLE_INFO ci = { sizeof(ci) }; - int i; - HWND hwndConsole = GetConsoleHandle(); + CONSOLE_INFO ci = { sizeof(ci) }; + int i; + HWND hwndConsole = GetConsoleHandle(); - /* get current size/position settings rather than using defaults.. */ - GetConsoleSizeInfo(&ci); + /* get current size/position settings rather than using defaults.. */ + GetConsoleSizeInfo(&ci); - /* set these to zero to keep current settings */ - ci.FontSize.X = 0; /* def = 8 */ - ci.FontSize.Y = 0; /* def = 12 */ - ci.FontFamily = 0; /* def = 0x30 = FF_MODERN|FIXED_PITCH */ - ci.FontWeight = 0; /* 0x400; */ - /* lstrcpyW(ci.FaceName, L"Terminal"); */ - ci.FaceName[0] = L'\0'; + /* set these to zero to keep current settings */ + ci.FontSize.X = 0; /* def = 8 */ + ci.FontSize.Y = 0; /* def = 12 */ + ci.FontFamily = 0; /* def = 0x30 = FF_MODERN|FIXED_PITCH */ + ci.FontWeight = 0; /* 0x400; */ + /* lstrcpyW(ci.FaceName, L"Terminal"); */ + ci.FaceName[0] = L'\0'; - ci.CursorSize = 25; - ci.FullScreen = FALSE; - ci.QuickEdit = TRUE; - ci.AutoPosition = 0x10000; - ci.InsertMode = TRUE; - ci.ScreenColors = MAKEWORD(0x7, 0x0); - ci.PopupColors = MAKEWORD(0x5, 0xf); - - ci.HistoryNoDup = FALSE; - ci.HistoryBufferSize = 50; - ci.NumberOfHistoryBuffers = 4; + ci.CursorSize = 25; + ci.FullScreen = FALSE; + ci.QuickEdit = TRUE; + ci.AutoPosition = 0x10000; + ci.InsertMode = TRUE; + ci.ScreenColors = MAKEWORD(0x7, 0x0); + ci.PopupColors = MAKEWORD(0x5, 0xf); - // colour table - for(i = 0; i < 16; i++) - ci.ColorTable[i] = palette[i]; + ci.HistoryNoDup = FALSE; + ci.HistoryBufferSize = 50; + ci.NumberOfHistoryBuffers = 4; - ci.CodePage = GetConsoleOutputCP(); - ci.Hwnd = hwndConsole; + // colour table + for (i = 0; i < 16; i++) + ci.ColorTable[i] = palette[i]; - lstrcpyW(ci.ConsoleTitle, L""); + ci.CodePage = GetConsoleOutputCP(); + ci.Hwnd = hwndConsole; - SetConsoleInfo(hwndConsole, &ci); + lstrcpyW(ci.ConsoleTitle, L""); + + SetConsoleInfo(hwndConsole, &ci); } /* @@ -1352,112 +1334,116 @@ VOID WINAPI SetConsolePalette(COLORREF palette[16]) * necessary section (file-mapping) object in the context of the * process which owns the console, before posting the message */ -BOOL SetConsoleInfo(HWND hwndConsole, CONSOLE_INFO *pci) +BOOL +SetConsoleInfo(HWND hwndConsole, CONSOLE_INFO *pci) { - DWORD dwConsoleOwnerPid; - HANDLE hProcess; - HANDLE hSection, hDupSection; - PVOID ptrView = 0; - HANDLE hThread; - - /* - * Open the process which "owns" the console - */ - GetWindowThreadProcessId(hwndConsole, &dwConsoleOwnerPid); - hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwConsoleOwnerPid); + DWORD dwConsoleOwnerPid; + HANDLE hProcess; + HANDLE hSection, hDupSection; + PVOID ptrView = 0; + HANDLE hThread; - /* - * Create a SECTION object backed by page-file, then map a view of - * this section into the owner process so we can write the contents - * of the CONSOLE_INFO buffer into it - */ - hSection = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, pci->Length, 0); + /* + * Open the process which "owns" the console + */ + GetWindowThreadProcessId(hwndConsole, &dwConsoleOwnerPid); + hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwConsoleOwnerPid); - /* - * Copy our console structure into the section-object - */ - ptrView = MapViewOfFile(hSection, FILE_MAP_WRITE|FILE_MAP_READ, 0, 0, pci->Length); - memcpy(ptrView, pci, pci->Length); - UnmapViewOfFile(ptrView); + /* + * Create a SECTION object backed by page-file, then map a view of + * this section into the owner process so we can write the contents + * of the CONSOLE_INFO buffer into it + */ + hSection = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, + pci->Length, 0); - /* - * Map the memory into owner process - */ - DuplicateHandle(GetCurrentProcess(), hSection, hProcess, &hDupSection, - 0, FALSE, DUPLICATE_SAME_ACCESS); + /* + * Copy our console structure into the section-object + */ + ptrView = MapViewOfFile(hSection, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, + pci->Length); + memcpy(ptrView, pci, pci->Length); + UnmapViewOfFile(ptrView); - /* Send console window the "update" message */ - SendMessage(hwndConsole, WM_SETCONSOLEINFO, (WPARAM)hDupSection, 0); + /* + * Map the memory into owner process + */ + DuplicateHandle(GetCurrentProcess(), hSection, hProcess, &hDupSection, 0, + FALSE, DUPLICATE_SAME_ACCESS); - /* - * clean up - */ - hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE)CloseHandle, - hDupSection, 0, 0); + /* Send console window the "update" message */ + SendMessage(hwndConsole, WM_SETCONSOLEINFO, (WPARAM) hDupSection, 0); - CloseHandle(hThread); - CloseHandle(hSection); - CloseHandle(hProcess); + /* + * clean up + */ + hThread = CreateRemoteThread(hProcess, 0, 0, + (LPTHREAD_START_ROUTINE) CloseHandle, + hDupSection, 0, 0); - return TRUE; + CloseHandle(hThread); + CloseHandle(hSection); + CloseHandle(hProcess); + + return TRUE; } /* * Fill the CONSOLE_INFO structure with information * about the current console window */ -static void GetConsoleSizeInfo(CONSOLE_INFO *pci) +static void +GetConsoleSizeInfo(CONSOLE_INFO *pci) { - CONSOLE_SCREEN_BUFFER_INFO csbi; + CONSOLE_SCREEN_BUFFER_INFO csbi; - HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); - GetConsoleScreenBufferInfo(hConsoleOut, &csbi); + GetConsoleScreenBufferInfo(hConsoleOut, &csbi); - pci->ScreenBufferSize = csbi.dwSize; - pci->WindowSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; - pci->WindowSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; - pci->WindowPosX = csbi.srWindow.Left; - pci->WindowPosY = csbi.srWindow.Top; + pci->ScreenBufferSize = csbi.dwSize; + pci->WindowSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; + pci->WindowSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; + pci->WindowPosX = csbi.srWindow.Left; + pci->WindowPosY = csbi.srWindow.Top; } static HWND GetConsoleHandle(void) { - HMODULE hMod = GetModuleHandle("kernel32.dll"); - GETCONSOLEWINDOW pfnGetConsoleWindow = - (GETCONSOLEWINDOW) GetProcAddress(hMod, "GetConsoleWindow"); - if (pfnGetConsoleWindow) - return pfnGetConsoleWindow(); - else - return GetConsoleHwnd(); + HMODULE hMod = GetModuleHandle("kernel32.dll"); + GETCONSOLEWINDOW pfnGetConsoleWindow = + (GETCONSOLEWINDOW) GetProcAddress(hMod, "GetConsoleWindow"); + if (pfnGetConsoleWindow) + return pfnGetConsoleWindow(); + else + return GetConsoleHwnd(); } static HWND GetConsoleHwnd(void) { - int iterations = 0; - HWND hwndFound = 0; - char OldTitle[1024],NewTitle[1024], TestTitle[1024]; + int iterations = 0; + HWND hwndFound = 0; + char OldTitle[1024], NewTitle[1024], TestTitle[1024]; - /* Get current window title */ - GetConsoleTitle(OldTitle, sizeof OldTitle); + /* Get current window title */ + GetConsoleTitle(OldTitle, sizeof OldTitle); - (void)sprintf(NewTitle,"NETHACK%d/%d", - GetTickCount(), + (void) sprintf(NewTitle, "NETHACK%d/%d", GetTickCount(), GetCurrentProcessId()); - SetConsoleTitle(NewTitle); + SetConsoleTitle(NewTitle); - GetConsoleTitle(TestTitle, sizeof TestTitle); - while(strcmp(TestTitle,NewTitle) != 0) { - iterations++; - /* sleep(0); */ - GetConsoleTitle(TestTitle, sizeof TestTitle); - } - hwndFound=FindWindow(NULL, NewTitle); - SetConsoleTitle(OldTitle); -/* printf("%d iterations\n", iterations); */ - return hwndFound; + GetConsoleTitle(TestTitle, sizeof TestTitle); + while (strcmp(TestTitle, NewTitle) != 0) { + iterations++; + /* sleep(0); */ + GetConsoleTitle(TestTitle, sizeof TestTitle); + } + hwndFound = FindWindow(NULL, NewTitle); + SetConsoleTitle(OldTitle); + /* printf("%d iterations\n", iterations); */ + return hwndFound; } -# endif /*CHANGE_COLOR*/ +#endif /*CHANGE_COLOR*/ #endif /* WIN32 */ diff --git a/sys/winnt/stubs.c b/sys/winnt/stubs.c index 6b899a03e..ccff931d6 100644 --- a/sys/winnt/stubs.c +++ b/sys/winnt/stubs.c @@ -1,41 +1,41 @@ #include "hack.h" #ifdef GUISTUB -# ifdef TTYSTUB -# error You can't compile this with both GUISTUB and TTYSTUB defined. -# endif +#ifdef TTYSTUB +#error You can't compile this with both GUISTUB and TTYSTUB defined. +#endif int GUILaunched; -struct window_procs mswin_procs = {"guistubs"}; +struct window_procs mswin_procs = { "guistubs" }; void mswin_destroy_reg() { - return; + return; } /* MINGW32 has trouble with both a main() and WinMain() * so we move main for the MINGW tty version into this stub * so that it is out of sight for the gui linkage. */ -# ifdef __MINGW32__ +#ifdef __MINGW32__ extern char default_window_sys[]; int -main(argc,argv) +main(argc, argv) int argc; char *argv[]; { - boolean resuming; + boolean resuming; - sys_early_init(); - Strcpy(default_window_sys, "tty"); - resuming = pcmain(argc,argv); - moveloop(resuming); - nethack_exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + sys_early_init(); + Strcpy(default_window_sys, "tty"); + resuming = pcmain(argc, argv); + moveloop(resuming); + nethack_exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } -# endif +#endif #endif /* GUISTUB */ /* =============================================== */ @@ -45,7 +45,7 @@ char *argv[]; #include "hack.h" int GUILaunched; -struct window_procs tty_procs = {"ttystubs"}; +struct window_procs tty_procs = { "ttystubs" }; void win_tty_init(dir) @@ -58,45 +58,44 @@ void nttty_open(mode) int mode; { - return; + return; } void xputc(ch) char ch; { - return; + return; } void xputs(s) const char *s; { - return; + return; } void raw_clear_screen() { - return; + return; } void clear_screen() { - return; + return; } void backsp() { - return; + return; } int has_color(int color) { - return 1; } @@ -104,7 +103,7 @@ has_color(int color) void toggle_mouse_support() { - return; + return; } #endif @@ -112,12 +111,12 @@ toggle_mouse_support() void win32con_debug_keystrokes() { - return; + return; } void win32con_handler_info() { - return; + return; } #endif @@ -125,45 +124,45 @@ void map_subkeyvalue(op) register char *op; { - return; + return; } void load_keyboard_handler() { - return; + return; } /* this is used as a printf() replacement when the window * system isn't initialized yet */ -void -msmsg VA_DECL(const char *, fmt) - VA_START(fmt); - VA_INIT(fmt, const char *); - VA_END(); - return; +void msmsg +VA_DECL(const char *, fmt) + VA_START(fmt); + VA_INIT(fmt, const char *); + VA_END(); + return; } /*VARARGS1*/ -void -nttty_error VA_DECL(const char *,s) - VA_START(s); - VA_INIT(s, const char *); - VA_END(); - return; +void nttty_error +VA_DECL(const char *, s) + VA_START(s); + VA_INIT(s, const char *); + VA_END(); + return; } void synch_cursor() { - return; + return; } -void more() +void +more() { - return; + return; } #endif /* TTYSTUBS */ - diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 4e27f63d8..c7ab7dfd3 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winnt.c $NHDT-Date: 1430988900 2015/05/07 08:55:00 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.24 $ */ +/* NetHack 3.6 winnt.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */ /* Copyright (c) NetHack PC Development Team 1993, 1994 */ /* NetHack may be freely redistributed. See license for details. */ @@ -20,7 +20,6 @@ #include "wintty.h" #ifdef WIN32 - /* * The following WIN32 API routines are used in this file. * @@ -33,9 +32,8 @@ * */ - /* globals required within here */ -HANDLE ffhandle = (HANDLE)0; +HANDLE ffhandle = (HANDLE) 0; WIN32_FIND_DATA ffd; /* The function pointer nt_kbhit contains a kbhit() equivalent @@ -51,30 +49,27 @@ int (*nt_kbhit)() = def_kbhit; char switchar() { - /* Could not locate a WIN32 API call for this- MJA */ - return '-'; + /* Could not locate a WIN32 API call for this- MJA */ + return '-'; } long freediskspace(path) char *path; { - char tmppath[4]; - DWORD SectorsPerCluster = 0; - DWORD BytesPerSector = 0; - DWORD FreeClusters = 0; - DWORD TotalClusters = 0; + char tmppath[4]; + DWORD SectorsPerCluster = 0; + DWORD BytesPerSector = 0; + DWORD FreeClusters = 0; + DWORD TotalClusters = 0; - tmppath[0] = *path; - tmppath[1] = ':'; - tmppath[2] = '\\'; - tmppath[3] = '\0'; - GetDiskFreeSpace(tmppath, &SectorsPerCluster, - &BytesPerSector, - &FreeClusters, - &TotalClusters); - return (long)(SectorsPerCluster * BytesPerSector * - FreeClusters); + tmppath[0] = *path; + tmppath[1] = ':'; + tmppath[2] = '\\'; + tmppath[3] = '\0'; + GetDiskFreeSpace(tmppath, &SectorsPerCluster, &BytesPerSector, + &FreeClusters, &TotalClusters); + return (long) (SectorsPerCluster * BytesPerSector * FreeClusters); } /* @@ -84,35 +79,34 @@ int findfirst(path) char *path; { - if (ffhandle){ - FindClose(ffhandle); - ffhandle = (HANDLE)0; - } - ffhandle = FindFirstFile(path,&ffd); - return - (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1; + if (ffhandle) { + FindClose(ffhandle); + ffhandle = (HANDLE) 0; + } + ffhandle = FindFirstFile(path, &ffd); + return (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1; } int -findnext() +findnext() { - return FindNextFile(ffhandle,&ffd) ? 1 : 0; + return FindNextFile(ffhandle, &ffd) ? 1 : 0; } char * foundfile_buffer() { - return &ffd.cFileName[0]; + return &ffd.cFileName[0]; } long filesize(file) char *file; { - if (findfirst(file)) { - return ((long)ffd.nFileSizeLow); - } else - return -1L; + if (findfirst(file)) { + return ((long) ffd.nFileSizeLow); + } else + return -1L; } /* @@ -122,69 +116,73 @@ void chdrive(str) char *str; { - char *ptr; - char drive; - if ((ptr = index(str, ':')) != (char *)0) - { - drive = toupper(*(ptr - 1)); - _chdrive((drive - 'A') + 1); - } + char *ptr; + char drive; + if ((ptr = index(str, ':')) != (char *) 0) { + drive = toupper(*(ptr - 1)); + _chdrive((drive - 'A') + 1); + } } static int max_filename() { - DWORD maxflen; - int status=0; - - status = GetVolumeInformation((LPTSTR)0,(LPTSTR)0, 0 - ,(LPDWORD)0,&maxflen,(LPDWORD)0,(LPTSTR)0,0); - if (status) return maxflen; - else return 0; + DWORD maxflen; + int status = 0; + + status = GetVolumeInformation((LPTSTR) 0, (LPTSTR) 0, 0, (LPDWORD) 0, + &maxflen, (LPDWORD) 0, (LPTSTR) 0, 0); + if (status) + return maxflen; + else + return 0; } int def_kbhit() { - return 0; + return 0; } -/* +/* * Strip out troublesome file system characters. */ -void -nt_regularize(s) /* normalize file name */ +void nt_regularize(s) /* normalize file name */ register char *s; { - register unsigned char *lp; + register unsigned char *lp; - for (lp = s; *lp; lp++) - if ( *lp == '?' || *lp == '"' || *lp == '\\' || - *lp == '/' || *lp == '>' || *lp == '<' || - *lp == '*' || *lp == '|' || *lp == ':' || (*lp > 127)) - *lp = '_'; + for (lp = s; *lp; lp++) + if (*lp == '?' || *lp == '"' || *lp == '\\' || *lp == '/' + || *lp == '>' || *lp == '<' || *lp == '*' || *lp == '|' + || *lp == ':' || (*lp > 127)) + *lp = '_'; } /* * This is used in nhlan.c to implement some of the LAN_FEATURES. */ -char *get_username(lan_username_size) +char * +get_username(lan_username_size) int *lan_username_size; { - static TCHAR username_buffer[BUFSZ]; - unsigned int status; - DWORD i = BUFSZ - 1; + static TCHAR username_buffer[BUFSZ]; + unsigned int status; + DWORD i = BUFSZ - 1; - /* i gets updated with actual size */ - status = GetUserName(username_buffer, &i); - if (status) username_buffer[i] = '\0'; - else Strcpy(username_buffer, "NetHack"); - if (lan_username_size) *lan_username_size = strlen(username_buffer); - return username_buffer; + /* i gets updated with actual size */ + status = GetUserName(username_buffer, &i); + if (status) + username_buffer[i] = '\0'; + else + Strcpy(username_buffer, "NetHack"); + if (lan_username_size) + *lan_username_size = strlen(username_buffer); + return username_buffer; } -# if 0 +#if 0 char *getxxx() { char szFullPath[MAX_PATH] = ""; @@ -193,66 +191,68 @@ HMODULE hInst = NULL; /* NULL gets the filename of this module */ GetModuleFileName(hInst, szFullPath, sizeof(szFullPath)); return &szFullPath[0]; } -# endif - +#endif /* fatal error */ /*VARARGS1*/ -void -error VA_DECL(const char *,s) - char buf[BUFSZ]; - VA_START(s); - VA_INIT(s, const char *); - /* error() may get called before tty is initialized */ - if (iflags.window_inited) end_screen(); - if (!strncmpi(windowprocs.name, "tty", 3)) { - buf[0] = '\n'; - (void) vsprintf(&buf[1], s, VA_ARGS); - Strcat(buf, "\n"); - msmsg(buf); - } else { - (void) vsprintf(buf, s, VA_ARGS); - Strcat(buf, "\n"); - raw_printf(buf); - } - VA_END(); - exit(EXIT_FAILURE); +void error +VA_DECL(const char *, s) + char buf[BUFSZ]; + VA_START(s); + VA_INIT(s, const char *); + /* error() may get called before tty is initialized */ + if (iflags.window_inited) + end_screen(); + if (!strncmpi(windowprocs.name, "tty", 3)) { + buf[0] = '\n'; + (void) vsprintf(&buf[1], s, VA_ARGS); + Strcat(buf, "\n"); + msmsg(buf); + } else { + (void) vsprintf(buf, s, VA_ARGS); + Strcat(buf, "\n"); + raw_printf(buf); + } + VA_END(); + exit(EXIT_FAILURE); } -void Delay(int ms) +void +Delay(int ms) { - (void)Sleep(ms); + (void) Sleep(ms); } extern void NDECL(backsp); -void win32_abort() +void +win32_abort() { - if (wizard) { - int c, ci, ct; + if (wizard) { + int c, ci, ct; - if (!iflags.window_inited) - c = 'n'; - ct = 0; - msmsg("Execute debug breakpoint wizard?"); - while ((ci=nhgetch()) != '\n') { - if (ct > 0) { - backsp(); /* \b is visible on NT */ - (void) putchar(' '); - backsp(); - ct = 0; - c = 'n'; - } - if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') { - ct = 1; - c = ci; - msmsg("%c",c); - } - } - if (c == 'y') - DebugBreak(); - } - abort(); + if (!iflags.window_inited) + c = 'n'; + ct = 0; + msmsg("Execute debug breakpoint wizard?"); + while ((ci = nhgetch()) != '\n') { + if (ct > 0) { + backsp(); /* \b is visible on NT */ + (void) putchar(' '); + backsp(); + ct = 0; + c = 'n'; + } + if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') { + ct = 1; + c = ci; + msmsg("%c", c); + } + } + if (c == 'y') + DebugBreak(); + } + abort(); } static char interjection_buf[INTERJECTION_TYPES][1024]; @@ -265,81 +265,85 @@ int interjection_type; genericptr_t ptr1; genericptr_t ptr2; { - switch(num) { - case 1: { - char *panicmsg = (char *)ptr1; - char *datadir = (char *)ptr2; - char *tempdir = nh_getenv("TEMP"); - interjection_type = INTERJECT_PANIC; - interjection[INTERJECT_PANIC] = 1; - /* - * ptr1 = the panic message about to be delivered. - * ptr2 = the directory prefix of the dungeon file - * that failed to open. - * Check to see if datadir matches tempdir or a - * common windows temp location. If it does, inform - * the user that they are probably trying to run the - * game from within their unzip utility, so the required - * files really don't exist at the location. Instruct - * them to unpack them first. - */ - if (panicmsg && datadir) { - if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15) || - strstri(datadir, "TEMP") || - (tempdir && strstri(datadir, tempdir))) { - (void)strncpy(interjection_buf[INTERJECT_PANIC], - "\nOne common cause of this error is attempting to execute\n" - "the game by double-clicking on it while it is displayed\n" - "inside an unzip utility.\n\n" - "You have to unzip the contents of the zip file into a\n" - "folder on your system, and then run \"NetHack.exe\" or \n" - "\"NetHackW.exe\" from there.\n\n" - "If that is not the situation, you are encouraged to\n" - "report the error as shown above.\n\n", 1023); - } - } - } - break; - } + switch (num) { + case 1: { + char *panicmsg = (char *) ptr1; + char *datadir = (char *) ptr2; + char *tempdir = nh_getenv("TEMP"); + interjection_type = INTERJECT_PANIC; + interjection[INTERJECT_PANIC] = 1; + /* + * ptr1 = the panic message about to be delivered. + * ptr2 = the directory prefix of the dungeon file + * that failed to open. + * Check to see if datadir matches tempdir or a + * common windows temp location. If it does, inform + * the user that they are probably trying to run the + * game from within their unzip utility, so the required + * files really don't exist at the location. Instruct + * them to unpack them first. + */ + if (panicmsg && datadir) { + if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15) + || strstri(datadir, "TEMP") + || (tempdir && strstri(datadir, tempdir))) { + (void) strncpy( + interjection_buf[INTERJECT_PANIC], + "\nOne common cause of this error is attempting to " + "execute\n" + "the game by double-clicking on it while it is " + "displayed\n" + "inside an unzip utility.\n\n" + "You have to unzip the contents of the zip file into a\n" + "folder on your system, and then run \"NetHack.exe\" or " + "\n" + "\"NetHackW.exe\" from there.\n\n" + "If that is not the situation, you are encouraged to\n" + "report the error as shown above.\n\n", + 1023); + } + } + } break; + } } - void interject(interjection_type) int interjection_type; { - if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES) - msmsg(interjection_buf[interjection_type]); + if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES) + msmsg(interjection_buf[interjection_type]); } -# ifdef RUNTIME_PORT_ID +#ifdef RUNTIME_PORT_ID /* - * _M_IX86 is Defined for x86 processors. This is not defined for x64 processors. + * _M_IX86 is Defined for x86 processors. This is not defined for x64 + * processors. * _M_X64 is Defined for x64 processors. * _M_IA64 is Defined for Itanium Processor Family 64-bit processors. * _WIN64 is Defined for applications for Win64. */ -# ifndef _M_IX86 -# ifdef _M_X64 -# define TARGET_PORT "(x64) " -# endif -# ifdef _M_IA64 -# define TARGET_PORT "(IA64) " -# endif -# endif +#ifndef _M_IX86 +#ifdef _M_X64 +#define TARGET_PORT "(x64) " +#endif +#ifdef _M_IA64 +#define TARGET_PORT "(IA64) " +#endif +#endif -# ifndef TARGET_PORT -# define TARGET_PORT "(x86) " -# endif +#ifndef TARGET_PORT +#define TARGET_PORT "(x86) " +#endif void append_port_id(buf) char *buf; { - char *portstr = TARGET_PORT; - Sprintf(eos(buf), " %s", portstr); + char *portstr = TARGET_PORT; + Sprintf(eos(buf), " %s", portstr); } -# endif /* RUNTIME_PORT_ID */ +#endif /* RUNTIME_PORT_ID */ #endif /* WIN32 */ diff --git a/util/dgn_main.c b/util/dgn_main.c index b7d470b55..c6aca60d9 100644 --- a/util/dgn_main.c +++ b/util/dgn_main.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dgn_main.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dgn_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 dgn_main.c $Date: 2009/05/06 10:54:27 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)dgn_main.c 3.5 1994/09/23 */ /* Copyright (c) 1989 by Jean-Christophe Collet */ @@ -15,41 +15,41 @@ /* Macintosh-specific code */ #if defined(__APPLE__) && defined(__MACH__) - /* MacOS X has Unix-style files and processes */ -# undef MAC +/* MacOS X has Unix-style files and processes */ +#undef MAC #endif #ifdef MAC -# if defined(__SC__) || defined(__MRC__) -# define MPWTOOL +#if defined(__SC__) || defined(__MRC__) +#define MPWTOOL #include -# else - /* put dungeon file in library location */ -# define PREFIX ":lib:" -# endif +#else +/* put dungeon file in library location */ +#define PREFIX ":lib:" +#endif #endif #ifndef MPWTOOL -# define SpinCursor(x) +#define SpinCursor(x) #endif -#define MAX_ERRORS 25 +#define MAX_ERRORS 25 -extern int NDECL (yyparse); +extern int NDECL(yyparse); extern int nh_line_number; const char *fname = "(stdin)"; int fatal_error = 0; -int FDECL (main, (int,char **)); -void FDECL (yyerror, (const char *)); -void FDECL (yywarning, (const char *)); -int NDECL (yywrap); -void FDECL (init_yyin, (FILE *)); -void FDECL (init_yyout, (FILE *)); +int FDECL(main, (int, char **)); +void FDECL(yyerror, (const char *)); +void FDECL(yywarning, (const char *)); +int NDECL(yywrap); +void FDECL(init_yyin, (FILE *)); +void FDECL(init_yyout, (FILE *)); #ifdef AZTEC_36 -FILE *FDECL (freopen, (char *,char *,FILE *)); +FILE *FDECL(freopen, (char *, char *, FILE *)); #endif -#define Fprintf (void)fprintf +#define Fprintf (void) fprintf #if defined(__BORLANDC__) && !defined(_WIN32) extern unsigned _stklen = STKSIZ; @@ -59,99 +59,98 @@ main(argc, argv) int argc; char **argv; { - char infile[64], outfile[64], basename[64]; - FILE *fin, *fout; - int i, len; - boolean errors_encountered = FALSE; + char infile[64], outfile[64], basename[64]; + FILE *fin, *fout; + int i, len; + boolean errors_encountered = FALSE; #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__)) - char *mark; - static char *mac_argv[] = { "dgn_comp", /* dummy argv[0] */ - ":dat:dungeon.pdf" - }; + char *mark; + static char *mac_argv[] = { "dgn_comp", /* dummy argv[0] */ + ":dat:dungeon.pdf" }; - argc = SIZE(mac_argv); - argv = mac_argv; + argc = SIZE(mac_argv); + argv = mac_argv; #endif - Strcpy(infile, "(stdin)"); - fin = stdin; - Strcpy(outfile, "(stdout)"); - fout = stdout; + Strcpy(infile, "(stdin)"); + fin = stdin; + Strcpy(outfile, "(stdout)"); + fout = stdout; - if (argc == 1) { /* Read standard input */ - init_yyin(fin); - init_yyout(fout); - (void) yyparse(); - if (fatal_error > 0) - errors_encountered = TRUE; - } else { /* Otherwise every argument is a filename */ - for(i=1; i 0) + errors_encountered = TRUE; + } else { /* Otherwise every argument is a filename */ + for (i = 1; i < argc; i++) { + fname = strcpy(infile, argv[i]); + /* the input file had better be a .pdf file */ + len = strlen(fname) - 4; /* length excluding suffix */ + if (len < 0 || strncmp(".pdf", fname + len, 4)) { + Fprintf(stderr, "Error - file name \"%s\" in wrong format.\n", + fname); + errors_encountered = TRUE; + continue; + } - /* build output file name */ +/* build output file name */ #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__)) - /* extract basename from path to infile */ - mark = strrchr(infile, ':'); - strcpy(basename, mark ? mark+1 : infile); - mark = strchr(basename, '.'); - if (mark) *mark = '\0'; + /* extract basename from path to infile */ + mark = strrchr(infile, ':'); + strcpy(basename, mark ? mark + 1 : infile); + mark = strchr(basename, '.'); + if (mark) + *mark = '\0'; #else - /* Use the whole name - strip off the last 3 or 4 chars. */ +/* Use the whole name - strip off the last 3 or 4 chars. */ -#ifdef VMS /* avoid possible interaction with logical name */ - len++; /* retain "." as trailing punctuation */ +#ifdef VMS /* avoid possible interaction with logical name */ + len++; /* retain "." as trailing punctuation */ #endif - (void) strncpy(basename, infile, len); - basename[len] = '\0'; + (void) strncpy(basename, infile, len); + basename[len] = '\0'; #endif - outfile[0] = '\0'; + outfile[0] = '\0'; #ifdef PREFIX - (void) strcat(outfile, PREFIX); + (void) strcat(outfile, PREFIX); #endif - (void) strcat(outfile, basename); + (void) strcat(outfile, basename); - fin = freopen(infile, "r", stdin); - if (!fin) { - Fprintf(stderr, "Can't open %s for input.\n", infile); - perror(infile); - errors_encountered = TRUE; - continue; - } - fout = freopen(outfile, WRBMODE, stdout); - if (!fout) { - Fprintf(stderr, "Can't open %s for output.\n", outfile); - perror(outfile); - errors_encountered = TRUE; - continue; - } - init_yyin(fin); - init_yyout(fout); - (void) yyparse(); - nh_line_number = 1; - if (fatal_error > 0) { - errors_encountered = TRUE; - fatal_error = 0; - } - } - } - if (fout && fclose(fout) < 0) { - Fprintf(stderr, "Can't finish output file."); - perror(outfile); - errors_encountered = TRUE; - } - exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + fin = freopen(infile, "r", stdin); + if (!fin) { + Fprintf(stderr, "Can't open %s for input.\n", infile); + perror(infile); + errors_encountered = TRUE; + continue; + } + fout = freopen(outfile, WRBMODE, stdout); + if (!fout) { + Fprintf(stderr, "Can't open %s for output.\n", outfile); + perror(outfile); + errors_encountered = TRUE; + continue; + } + init_yyin(fin); + init_yyout(fout); + (void) yyparse(); + nh_line_number = 1; + if (fatal_error > 0) { + errors_encountered = TRUE; + fatal_error = 0; + } + } + } + if (fout && fclose(fout) < 0) { + Fprintf(stderr, "Can't finish output file."); + perror(outfile); + errors_encountered = TRUE; + } + exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } /* @@ -160,32 +159,37 @@ char **argv; * MAX_ERRORS wouldn't be reasonable. */ -void yyerror(s) +void +yyerror(s) const char *s; { - (void) fprintf(stderr,"%s : line %d : %s\n",fname,nh_line_number, s); - if (++fatal_error > MAX_ERRORS) { - (void) fprintf(stderr,"Too many errors, good bye!\n"); - exit(EXIT_FAILURE); - } + (void) fprintf(stderr, "%s : line %d : %s\n", fname, nh_line_number, s); + if (++fatal_error > MAX_ERRORS) { + (void) fprintf(stderr, "Too many errors, good bye!\n"); + exit(EXIT_FAILURE); + } } /* * Just display a warning (that is : a non fatal error) */ -void yywarning(s) +void +yywarning(s) const char *s; { - (void) fprintf(stderr,"%s : line %d : WARNING : %s\n",fname,nh_line_number,s); + (void) fprintf(stderr, "%s : line %d : WARNING : %s\n", fname, + nh_line_number, s); } -int yywrap() +int +yywrap() { - SpinCursor(3); /* Don't know if this is a good place to put it ? - Is it called for our grammar ? Often enough ? - Too often ? -- h+ */ - return 1; + SpinCursor(3); /* Don't know if this is a good place to put it ? + Is it called for our grammar ? + Often enough ? + Too often ? -- h+ */ + return 1; } /*dgn_main.c*/ diff --git a/util/dlb_main.c b/util/dlb_main.c index 12d83bf3b..7ab970b41 100644 --- a/util/dlb_main.c +++ b/util/dlb_main.c @@ -1,9 +1,10 @@ -/* NetHack 3.6 dlb_main.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 dlb_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 dlb_main.c $Date: 2012/01/16 03:56:08 $ $Revision: 1.6 $ */ /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */ /* NetHack may be freely redistributed. See license for details. */ -/* data librarian; only useful if you are making the library version, DLBLIB */ +/* data librarian; only useful if you are making the library version, DLBLIB + */ #include "config.h" #include "dlb.h" @@ -14,26 +15,27 @@ #include #endif -static void FDECL(grow_ld, (libdir **,int *,int)); +static void FDECL(grow_ld, (libdir **, int *, int)); static void FDECL(xexit, (int)); #ifdef DLB #ifdef DLBLIB -#define DLB_DIRECTORY "Directory" /* name of lib directory */ -#define LIBLISTFILE "dlb.lst" /* default list file */ +#define DLB_DIRECTORY "Directory" /* name of lib directory */ +#define LIBLISTFILE "dlb.lst" /* default list file */ /* library functions (from dlb.c) */ -extern boolean FDECL(open_library,(const char *,library *)); -extern void FDECL(close_library,(library *)); +extern boolean FDECL(open_library, (const char *, library *)); +extern void FDECL(close_library, (library *)); -char *FDECL(eos, (char *)); /* also used by dlb.c */ -FILE *FDECL(fopen_datafile, (const char *,const char *)); +char *FDECL(eos, (char *)); /* also used by dlb.c */ +FILE *FDECL(fopen_datafile, (const char *, const char *)); -static void FDECL(Write, (int,char *,long)); +static void FDECL(Write, (int, char *, long)); static void NDECL(usage); static void NDECL(verbose_help); -static void FDECL(write_dlb_directory, (int,int,libdir *,long,long,long)); +static void FDECL(write_dlb_directory, + (int, int, libdir *, long, long, long)); static char default_progname[] = "dlb"; static char *progname = default_progname; @@ -43,23 +45,22 @@ static const char *library_file = DLBFILE; static const char *list_file = LIBLISTFILE; #ifdef AMIGA -static char origdir[255]=""; +static char origdir[255] = ""; #endif #ifndef O_BINARY #define O_BINARY 0 #endif -#define DLB_FILES_ALLOC 200 /* initial # of files we'll handle; can grow */ -#define DLB_VERS 1 /* version of dlb file we will write */ +#define DLB_FILES_ALLOC 200 /* initial # of files we'll handle; can grow */ +#define DLB_VERS 1 /* version of dlb file we will write */ /* * How the file is encoded within the library. Don't use a space * because (at least) the SunOS 4.1.3 C library will eat the white * space instead of preserving it like the man page says it should. */ -#define ENC_NORMAL 'n' /* normal: not compressed in any way */ - +#define ENC_NORMAL 'n' /* normal: not compressed in any way */ /* * If you know tar, you have a small clue how to use this (note: - does @@ -90,63 +91,56 @@ static void verbose_help() { static const char *long_help[] = { - "", - "dlb COMMANDoptions args... files...", - " commands:", - " dlb ? print this text", - " dlb h ditto", - " dlb x extract all files", - " dlb c create the archive", - " dlb t list table of contents", - " options:", - " v verbose operation", - " f file specify archive file name", - " I file specify file for list of file names", - " C dir change directory before processing any files", - "", - (char *)0 + "", "dlb COMMANDoptions args... files...", " commands:", + " dlb ? print this text", " dlb h ditto", + " dlb x extract all files", " dlb c create the archive", + " dlb t list table of contents", " options:", + " v verbose operation", + " f file specify archive file name", + " I file specify file for list of file names", + " C dir change directory before processing any files", "", + (char *) 0 }; const char **str; for (str = long_help; *str; str++) - (void) printf("%s\n", *str); + (void) printf("%s\n", *str); usage(); } static void -Write(out,buf,len) - int out; - char *buf; - long len; +Write(out, buf, len) +int out; +char *buf; +long len; { #if defined(MSDOS) && !defined(__DJGPP__) unsigned short slen; if (len > 65534) { - printf("%d Length specified for write() too large for 16 bit env.", - len); - xexit(EXIT_FAILURE); + printf("%d Length specified for write() too large for 16 bit env.", + len); + xexit(EXIT_FAILURE); } - slen = (unsigned short)len; - if (write(out,buf,slen) != slen) { + slen = (unsigned short) len; + if (write(out, buf, slen) != slen) { #else - if (write(out,buf,len) != len) { + if (write(out, buf, len) != len) { #endif - printf("Write Error in '%s'\n",library_file); - xexit(EXIT_FAILURE); + printf("Write Error in '%s'\n", library_file); + xexit(EXIT_FAILURE); } } - char * eos(s) - char *s; +char *s; { - while (*s) s++; + while (*s) + s++; return s; } - /* open_library(dlb.c) needs this (which normally comes from src/files.c) */ FILE * fopen_datafile(filename, mode) @@ -155,311 +149,322 @@ const char *filename, *mode; return fopen(filename, mode); } -#endif /* DLBLIB */ -#endif /* DLB */ +#endif /* DLBLIB */ +#endif /* DLB */ int main(argc, argv) - int argc; - char **argv; +int argc; +char **argv; { #ifdef DLB #ifdef DLBLIB int i, r; - int ap=2; /* argument pointer */ - int cp; /* command pointer */ - int iseen=0, fseen=0, verbose=0; /* flags */ - char action=' '; + int ap = 2; /* argument pointer */ + int cp; /* command pointer */ + int iseen = 0, fseen = 0, verbose = 0; /* flags */ + char action = ' '; library lib; - if (argc > 0 && argv[0] && *argv[0]) progname = argv[0]; + if (argc > 0 && argv[0] && *argv[0]) + progname = argv[0]; #ifdef VMS progname = vms_basename(progname); #endif - if (argc<2) { - usage(); - /* doesn't return */ + if (argc < 2) { + usage(); + /* doesn't return */ } - for(cp=0;argv[1][cp];cp++){ - switch(argv[1][cp]){ - default: - usage(); /* doesn't return */ - case '-': /* silently ignore */ - break; - case '?': - case 'h': - verbose_help(); - break; - case 'I': - if (ap == argc) usage(); - list_file=argv[ap++]; - if(iseen) - printf("Warning: multiple I options. Previous ignored.\n"); - iseen=1; - break; - case 'f': - if (ap == argc) usage(); - library_file=argv[ap++]; - if(fseen) - printf("Warning: multiple f options. Previous ignored.\n"); - fseen=1; - break; - case 'C': - if (ap == argc) usage(); + for (cp = 0; argv[1][cp]; cp++) { + switch (argv[1][cp]) { + default: + usage(); /* doesn't return */ + case '-': /* silently ignore */ + break; + case '?': + case 'h': + verbose_help(); + break; + case 'I': + if (ap == argc) + usage(); + list_file = argv[ap++]; + if (iseen) + printf("Warning: multiple I options. Previous ignored.\n"); + iseen = 1; + break; + case 'f': + if (ap == argc) + usage(); + library_file = argv[ap++]; + if (fseen) + printf("Warning: multiple f options. Previous ignored.\n"); + fseen = 1; + break; + case 'C': + if (ap == argc) + usage(); #ifdef AMIGA - if(!getcwd(origdir,sizeof(origdir))){ - printf("Can't get current directory.\n"); - xexit(EXIT_FAILURE); - } + if (!getcwd(origdir, sizeof(origdir))) { + printf("Can't get current directory.\n"); + xexit(EXIT_FAILURE); + } #endif - if(chdir(argv[ap++])){ - printf("Can't chdir to %s\n",argv[--ap]); - xexit(EXIT_FAILURE); - } - break; - case 'v': - verbose=1; - break; - case 't': - case 'c': - case 'x': - if(action != ' '){ - printf("Only one of t,x,c may be specified.\n"); - usage(); - } - action=argv[1][cp]; - break; - } + if (chdir(argv[ap++])) { + printf("Can't chdir to %s\n", argv[--ap]); + xexit(EXIT_FAILURE); + } + break; + case 'v': + verbose = 1; + break; + case 't': + case 'c': + case 'x': + if (action != ' ') { + printf("Only one of t,x,c may be specified.\n"); + usage(); + } + action = argv[1][cp]; + break; + } } - if(argv[ap] && iseen){ - printf("Too many arguments.\n"); - xexit(EXIT_FAILURE); + if (argv[ap] && iseen) { + printf("Too many arguments.\n"); + xexit(EXIT_FAILURE); } - switch(action){ + switch (action) { default: - printf("Internal error - action.\n"); - xexit(EXIT_FAILURE); - break; - case 't': /* list archive */ - if (!open_library(library_file, &lib)) { - printf("Can't open dlb file\n"); - xexit(EXIT_FAILURE); - } + printf("Internal error - action.\n"); + xexit(EXIT_FAILURE); + break; + case 't': /* list archive */ + if (!open_library(library_file, &lib)) { + printf("Can't open dlb file\n"); + xexit(EXIT_FAILURE); + } - for (i = 0; i < lib.nentries; i++) { - if (verbose) - printf("%-14s %6ld %6ld\n", - lib.dir[i].fname, lib.dir[i].foffset, lib.dir[i].fsize); - else - printf("%s\n", lib.dir[i].fname); - } + for (i = 0; i < lib.nentries; i++) { + if (verbose) + printf("%-14s %6ld %6ld\n", lib.dir[i].fname, + lib.dir[i].foffset, lib.dir[i].fsize); + else + printf("%s\n", lib.dir[i].fname); + } - if (verbose) - printf("Revision:%ld File count:%ld String size:%ld\n", - lib.rev, lib.nentries, lib.strsize); + if (verbose) + printf("Revision:%ld File count:%ld String size:%ld\n", lib.rev, + lib.nentries, lib.strsize); - close_library(&lib); - xexit(EXIT_SUCCESS); + close_library(&lib); + xexit(EXIT_SUCCESS); - case 'x': { /* extract archive contents */ - int f, n; - long remainder, total_read; - char buf[BUFSIZ]; + case 'x': { /* extract archive contents */ + int f, n; + long remainder, total_read; + char buf[BUFSIZ]; - if (!open_library(library_file, &lib)) { - printf("Can't open dlb file\n"); - xexit(EXIT_FAILURE); - } + if (!open_library(library_file, &lib)) { + printf("Can't open dlb file\n"); + xexit(EXIT_FAILURE); + } - for (i = 0; i < lib.nentries; i++) { - if (argv[ap]) { - /* if files are listed, see if current is wanted */ - int c; - for (c = ap; c < argc; c++) - if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) break; - if (c == argc) continue; /* skip */ - } else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) { - /* - * Don't extract the directory unless the user - * specifically asks for it. - * - * Perhaps we should never extract the directory??? - */ - continue; - } - fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET); + for (i = 0; i < lib.nentries; i++) { + if (argv[ap]) { + /* if files are listed, see if current is wanted */ + int c; + for (c = ap; c < argc; c++) + if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) + break; + if (c == argc) + continue; /* skip */ + } else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) { + /* + * Don't extract the directory unless the user + * specifically asks for it. + * + * Perhaps we should never extract the directory??? + */ + continue; + } + fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET); - f = open(lib.dir[i].fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT, 0640); - if (f < 0) { - printf("Can't create '%s'\n", lib.dir[i].fname); - xexit(EXIT_FAILURE); - } + f = open(lib.dir[i].fname, + O_WRONLY | O_TRUNC | O_BINARY | O_CREAT, 0640); + if (f < 0) { + printf("Can't create '%s'\n", lib.dir[i].fname); + xexit(EXIT_FAILURE); + } - /* read chunks from library and write them out */ - total_read = 0; - do { - remainder = lib.dir[i].fsize - total_read; - if (remainder > (long) sizeof(buf)) - r = (int) sizeof(buf); - else - r = remainder; + /* read chunks from library and write them out */ + total_read = 0; + do { + remainder = lib.dir[i].fsize - total_read; + if (remainder > (long) sizeof(buf)) + r = (int) sizeof(buf); + else + r = remainder; - n = fread(buf, 1, r, lib.fdata); - if (n != r) { - printf("Read Error in '%s'\n", lib.dir[i].fname); - xexit(EXIT_FAILURE); - } - if (write(f, buf, n) != n) { - printf("Write Error in '%s'\n", lib.dir[i].fname); - xexit(EXIT_FAILURE); - } + n = fread(buf, 1, r, lib.fdata); + if (n != r) { + printf("Read Error in '%s'\n", lib.dir[i].fname); + xexit(EXIT_FAILURE); + } + if (write(f, buf, n) != n) { + printf("Write Error in '%s'\n", lib.dir[i].fname); + xexit(EXIT_FAILURE); + } - total_read += n; - } while (total_read != lib.dir[i].fsize); + total_read += n; + } while (total_read != lib.dir[i].fsize); - (void) close(f); + (void) close(f); - if (verbose) printf("x %s\n", lib.dir[i].fname); - } + if (verbose) + printf("x %s\n", lib.dir[i].fname); + } - close_library(&lib); - xexit(EXIT_SUCCESS); - } - - case 'c': /* create archive */ - { - libdir *ld = 0; - int ldlimit = 0; - char buf[BUFSIZ]; - int fd, out, nfiles = 0; - long dir_size, slen, flen, fsiz; - boolean rewrite_directory = FALSE; - - /* - * Get names from either/both an argv list and a file - * list. This does not do any duplicate checking - */ - - grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC); - - /* get file name in argv list */ - if (argv[ap]) { - for ( ; ap < argc; ap++, nfiles++) { - if (nfiles == ldlimit) - grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5); - ld[nfiles].fname = (char *) alloc(strlen(argv[ap]) + 1); - Strcpy(ld[nfiles].fname, argv[ap]); - } - } - - if (iseen) { - /* want to do a list file */ - FILE *list = fopen(list_file, "r"); - if (!list) { - printf("Can't open %s\n",list_file); - xexit(EXIT_FAILURE); - } - - /* get file names, one per line */ - for ( ; fgets(buf, sizeof(buf), list); nfiles++) { - if (nfiles == ldlimit) - grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5); - *(eos(buf)-1) = '\0'; /* strip newline */ - ld[nfiles].fname = (char *) alloc(strlen(buf) + 1); - Strcpy(ld[nfiles].fname, buf); - } - fclose(list); - } - - if (nfiles == 0) { - printf("No files to archive\n"); - xexit(EXIT_FAILURE); - } - - - /* - * Get file sizes and name string length. Don't include - * the directory information yet. - */ - for (i = 0, slen = 0, flen = 0; i < nfiles; i++) { - fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0); - if (fd < 0) { - printf("Can't open %s\n", ld[i].fname); - xexit(EXIT_FAILURE); - } - ld[i].fsize = lseek(fd, 0, SEEK_END); - ld[i].foffset = flen; - - slen += strlen(ld[i].fname); /* don't add null (yet) */ - flen += ld[i].fsize; - close(fd); - } - - /* open output file */ - out = open(library_file, O_RDWR|O_TRUNC|O_BINARY|O_CREAT, FCMASK); - if (out < 0) { - printf("Can't open %s for output\n", library_file); - xexit(EXIT_FAILURE); - } - - /* caculate directory size */ - dir_size = 40 /* header line (see below) */ - + ((nfiles+1)*11) /* handling+file offset+SP+newline */ - + slen+strlen(DLB_DIRECTORY); /* file names */ - - /* write directory */ - write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); - - flen = 0L; - /* write each file */ - for (i = 0; i < nfiles; i++) { - fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0); - if (fd < 0) { - printf("Can't open input file '%s'\n", ld[i].fname); - xexit(EXIT_FAILURE); - } - if (verbose) printf("%s\n",ld[i].fname); - - fsiz = 0L; - while ((r = read(fd, buf, sizeof buf)) != 0) { - if (r == -1) { - printf("Read Error in '%s'\n", ld[i].fname); - xexit(EXIT_FAILURE); - } - if (write(out, buf, r) != r) { - printf("Write Error in '%s'\n", ld[i].fname); - xexit(EXIT_FAILURE); - } - fsiz += r; - } - (void) close(fd); - if (fsiz != ld[i].fsize) rewrite_directory = TRUE; - /* in case directory rewrite is needed */ - ld[i].fsize = fsiz; - ld[i].foffset = flen; - flen += fsiz; - } - - if (rewrite_directory) { - if (verbose) printf("(rewriting dlb directory info)\n"); - (void) lseek(out, 0, SEEK_SET); /* rewind */ - write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); - } - - for (i = 0; i < nfiles; i++) - free((genericptr_t) ld[i].fname), ld[i].fname = 0; - free((genericptr_t)ld), ldlimit = 0; - - (void) close(out); - xexit(EXIT_SUCCESS); - } + close_library(&lib); + xexit(EXIT_SUCCESS); } -#endif /* DLBLIB */ -#endif /* DLB */ + + case 'c': /* create archive */ + { + libdir *ld = 0; + int ldlimit = 0; + char buf[BUFSIZ]; + int fd, out, nfiles = 0; + long dir_size, slen, flen, fsiz; + boolean rewrite_directory = FALSE; + + /* + * Get names from either/both an argv list and a file + * list. This does not do any duplicate checking + */ + + grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC); + + /* get file name in argv list */ + if (argv[ap]) { + for (; ap < argc; ap++, nfiles++) { + if (nfiles == ldlimit) + grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5); + ld[nfiles].fname = (char *) alloc(strlen(argv[ap]) + 1); + Strcpy(ld[nfiles].fname, argv[ap]); + } + } + + if (iseen) { + /* want to do a list file */ + FILE *list = fopen(list_file, "r"); + if (!list) { + printf("Can't open %s\n", list_file); + xexit(EXIT_FAILURE); + } + + /* get file names, one per line */ + for (; fgets(buf, sizeof(buf), list); nfiles++) { + if (nfiles == ldlimit) + grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5); + *(eos(buf) - 1) = '\0'; /* strip newline */ + ld[nfiles].fname = (char *) alloc(strlen(buf) + 1); + Strcpy(ld[nfiles].fname, buf); + } + fclose(list); + } + + if (nfiles == 0) { + printf("No files to archive\n"); + xexit(EXIT_FAILURE); + } + + /* + * Get file sizes and name string length. Don't include + * the directory information yet. + */ + for (i = 0, slen = 0, flen = 0; i < nfiles; i++) { + fd = open(ld[i].fname, O_RDONLY | O_BINARY, 0); + if (fd < 0) { + printf("Can't open %s\n", ld[i].fname); + xexit(EXIT_FAILURE); + } + ld[i].fsize = lseek(fd, 0, SEEK_END); + ld[i].foffset = flen; + + slen += strlen(ld[i].fname); /* don't add null (yet) */ + flen += ld[i].fsize; + close(fd); + } + + /* open output file */ + out = + open(library_file, O_RDWR | O_TRUNC | O_BINARY | O_CREAT, FCMASK); + if (out < 0) { + printf("Can't open %s for output\n", library_file); + xexit(EXIT_FAILURE); + } + + /* caculate directory size */ + dir_size = 40 /* header line (see below) */ + + ((nfiles + 1) * 11) /* handling+file offset+SP+newline */ + + slen + strlen(DLB_DIRECTORY); /* file names */ + + /* write directory */ + write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); + + flen = 0L; + /* write each file */ + for (i = 0; i < nfiles; i++) { + fd = open(ld[i].fname, O_RDONLY | O_BINARY, 0); + if (fd < 0) { + printf("Can't open input file '%s'\n", ld[i].fname); + xexit(EXIT_FAILURE); + } + if (verbose) + printf("%s\n", ld[i].fname); + + fsiz = 0L; + while ((r = read(fd, buf, sizeof buf)) != 0) { + if (r == -1) { + printf("Read Error in '%s'\n", ld[i].fname); + xexit(EXIT_FAILURE); + } + if (write(out, buf, r) != r) { + printf("Write Error in '%s'\n", ld[i].fname); + xexit(EXIT_FAILURE); + } + fsiz += r; + } + (void) close(fd); + if (fsiz != ld[i].fsize) + rewrite_directory = TRUE; + /* in case directory rewrite is needed */ + ld[i].fsize = fsiz; + ld[i].foffset = flen; + flen += fsiz; + } + + if (rewrite_directory) { + if (verbose) + printf("(rewriting dlb directory info)\n"); + (void) lseek(out, 0, SEEK_SET); /* rewind */ + write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); + } + + for (i = 0; i < nfiles; i++) + free((genericptr_t) ld[i].fname), ld[i].fname = 0; + free((genericptr_t) ld), ldlimit = 0; + + (void) close(out); + xexit(EXIT_SUCCESS); + } + } +#endif /* DLBLIB */ +#endif /* DLB */ xexit(EXIT_SUCCESS); /*NOTREACHED*/ @@ -477,14 +482,16 @@ int alloc_incr; { static libdir zerolibdir; int i = 0, newlimit = *ldlimit_p + alloc_incr; - libdir *newld = (libdir *)alloc(newlimit * sizeof *newld); + libdir *newld = (libdir *) alloc(newlimit * sizeof *newld); if (*ld_p) { - for ( ; i < *ldlimit_p; ++i) newld[i] = (*ld_p)[i]; - free((genericptr_t)*ld_p); + for (; i < *ldlimit_p; ++i) + newld[i] = (*ld_p)[i]; + free((genericptr_t) *ld_p); } - *ld_p = newld, *ldlimit_p = newlimit; - for ( ; i < *ldlimit_p; ++i) (*ld_p)[i] = zerolibdir; + *ld_p = newld, *ldlimit_p = newlimit; + for (; i < *ldlimit_p; ++i) + (*ld_p)[i] = zerolibdir; } static void @@ -496,44 +503,43 @@ long slen, dir_size, flen; char buf[BUFSIZ]; int i; - sprintf(buf,"%3ld %8ld %8ld %8ld %8ld\n", - (long) DLB_VERS, /* version of dlb file */ - (long) nfiles+1, /* # of entries (includes directory) */ - /* string length + room for nulls */ - (long) slen+strlen(DLB_DIRECTORY)+nfiles+1, - (long) dir_size, /* start of first file */ - (long) flen+dir_size); /* total file size */ + sprintf(buf, "%3ld %8ld %8ld %8ld %8ld\n", + (long) DLB_VERS, /* version of dlb file */ + (long) nfiles + 1, /* # of entries (includes directory) */ + /* string length + room for nulls */ + (long) slen + strlen(DLB_DIRECTORY) + nfiles + 1, + (long) dir_size, /* start of first file */ + (long) flen + dir_size); /* total file size */ Write(out, buf, strlen(buf)); - /* write each file entry */ +/* write each file entry */ #define ENTRY_FORMAT "%c%s %8ld\n" sprintf(buf, ENTRY_FORMAT, ENC_NORMAL, DLB_DIRECTORY, (long) 0); Write(out, buf, strlen(buf)); for (i = 0; i < nfiles; i++) { - sprintf(buf, ENTRY_FORMAT, - ENC_NORMAL, /* encoding */ - ld[i].fname, /* name */ - ld[i].foffset + dir_size); /* offset */ - Write(out, buf, strlen(buf)); + sprintf(buf, ENTRY_FORMAT, ENC_NORMAL, /* encoding */ + ld[i].fname, /* name */ + ld[i].foffset + dir_size); /* offset */ + Write(out, buf, strlen(buf)); } } -#endif /* DLBLIB */ -#endif /* DLB */ +#endif /* DLBLIB */ +#endif /* DLB */ static void xexit(retcd) - int retcd; +int retcd; { #ifdef DLB #ifdef AMIGA - if (origdir[0]) chdir(origdir); + if (origdir[0]) + chdir(origdir); #endif #endif exit(retcd); } - #ifdef AMIGA #include "date.h" const char amiga_version_string[] = AMIGA_VERSION_STRING; diff --git a/util/lev_main.c b/util/lev_main.c index c41085c39..a0827bb3d 100644 --- a/util/lev_main.c +++ b/util/lev_main.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 lev_main.c $NHDT-Date: 1428655166 2015/04/10 08:39:26 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ +/* NetHack 3.6 lev_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.38 $ */ /* NetHack 3.6 lev_main.c $Date: 2012/01/12 04:48:12 $ $Revision: 1.20 $ */ /* SCCS Id: @(#)lev_main.c 3.5 2007/01/17 */ /* Copyright (c) 1989 by Jean-Christophe Collet */ @@ -8,7 +8,7 @@ * This file contains the main function for the parser * and some useful functions needed by yacc */ -#define SPEC_LEV /* for USE_OLDARGS (sp_lev.h) and for MPW (macconf.h) */ +#define SPEC_LEV /* for USE_OLDARGS (sp_lev.h) and for MPW (macconf.h) */ #define NEED_VARARGS #include "hack.h" @@ -20,15 +20,15 @@ #include #ifdef MAC -# if defined(__SC__) || defined(__MRC__) -# define MPWTOOL -# define PREFIX ":dungeon:" /* place output files here */ -# include -# else -# if !defined(__MACH__) -# define PREFIX ":lib:" /* place output files here */ -# endif -# endif +#if defined(__SC__) || defined(__MRC__) +#define MPWTOOL +#define PREFIX ":dungeon:" /* place output files here */ +#include +#else +#if !defined(__MACH__) +#define PREFIX ":lib:" /* place output files here */ +#endif +#endif #endif #ifdef WIN_CE @@ -36,72 +36,77 @@ #endif #ifndef MPWTOOL -# define SpinCursor(x) +#define SpinCursor(x) #endif #if defined(AMIGA) && defined(DLB) -# define PREFIX "NH:slib/" +#define PREFIX "NH:slib/" #endif #ifndef O_WRONLY #include #endif -#ifndef O_CREAT /* some older BSD systems do not define O_CREAT in */ +#ifndef O_CREAT /* some older BSD systems do not define O_CREAT in \ + */ #include #endif -#ifndef O_BINARY /* used for micros, no-op for others */ -# define O_BINARY 0 +#ifndef O_BINARY /* used for micros, no-op for others */ +#define O_BINARY 0 #endif #if defined(MICRO) || defined(WIN32) -# define OMASK FCMASK +#define OMASK FCMASK #else -# define OMASK 0644 +#define OMASK 0644 #endif -#define ERR (-1) +#define ERR (-1) -#define NewTab(type, size) (type **) alloc(sizeof(type *) * size) -#define Free(ptr) if(ptr) free((genericptr_t) (ptr)) - /* write() returns a signed value but its size argument is unsigned; - types might be int and unsigned or ssize_t and size_t; casting - to long should be safe for all permutations (even if size_t is - bigger, since the values involved won't be too big for long) */ -#define Write(fd, item, size) if ((long)write(fd, (genericptr_t)(item), size) \ - != (long)(size)) return FALSE; +#define NewTab(type, size) (type **) alloc(sizeof(type *) * size) +#define Free(ptr) \ + if (ptr) \ + free((genericptr_t)(ptr)) +/* write() returns a signed value but its size argument is unsigned; + types might be int and unsigned or ssize_t and size_t; casting + to long should be safe for all permutations (even if size_t is + bigger, since the values involved won't be too big for long) */ +#define Write(fd, item, size) \ + if ((long) write(fd, (genericptr_t)(item), size) != (long) (size)) \ + return FALSE; #if defined(__BORLANDC__) && !defined(_WIN32) extern unsigned _stklen = STKSIZ; #endif -#define MAX_ERRORS 25 +#define MAX_ERRORS 25 -extern int NDECL(yyparse); +extern int NDECL(yyparse); extern void FDECL(init_yyin, (FILE *)); extern void FDECL(init_yyout, (FILE *)); -int FDECL(main, (int, char **)); +int FDECL(main, (int, char **)); void FDECL(yyerror, (const char *)); void FDECL(yywarning, (const char *)); -int NDECL(yywrap); +int NDECL(yywrap); int FDECL(get_floor_type, (CHAR_P)); int FDECL(get_room_type, (char *)); int FDECL(get_trap_type, (char *)); -int FDECL(get_monster_id, (char *,CHAR_P)); -int FDECL(get_object_id, (char *,CHAR_P)); +int FDECL(get_monster_id, (char *, CHAR_P)); +int FDECL(get_object_id, (char *, CHAR_P)); boolean FDECL(check_monster_char, (CHAR_P)); boolean FDECL(check_object_char, (CHAR_P)); char FDECL(what_map_char, (CHAR_P)); void FDECL(scan_map, (char *, sp_lev *)); boolean NDECL(check_subrooms); -boolean FDECL(write_level_file, (char *,sp_lev *)); +boolean FDECL(write_level_file, (char *, sp_lev *)); -struct lc_funcdefs *FDECL(funcdef_new,(long,char *)); -void FDECL(funcdef_free_all,(struct lc_funcdefs *)); -struct lc_funcdefs *FDECL(funcdef_defined,(struct lc_funcdefs *,char *, int)); +struct lc_funcdefs *FDECL(funcdef_new, (long, char *)); +void FDECL(funcdef_free_all, (struct lc_funcdefs *)); +struct lc_funcdefs *FDECL(funcdef_defined, + (struct lc_funcdefs *, char *, int)); -struct lc_vardefs *FDECL(vardef_new,(long,char *)); -void FDECL(vardef_free_all,(struct lc_vardefs *)); -struct lc_vardefs *FDECL(vardef_defined,(struct lc_vardefs *,char *, int)); +struct lc_vardefs *FDECL(vardef_new, (long, char *)); +void FDECL(vardef_free_all, (struct lc_vardefs *)); +struct lc_vardefs *FDECL(vardef_defined, (struct lc_vardefs *, char *, int)); void FDECL(splev_add_from, (sp_lev *, sp_lev *)); @@ -112,23 +117,23 @@ extern void NDECL(decl_init); void FDECL(add_opcode, (sp_lev *, int, genericptr_t)); static boolean FDECL(write_common_data, (int)); -static boolean FDECL(write_maze, (int,sp_lev *)); +static boolean FDECL(write_maze, (int, sp_lev *)); static void NDECL(init_obj_classes); static int FDECL(case_insensitive_comp, (const char *, const char *)); void VDECL(lc_pline, (const char *, ...)); void VDECL(lc_error, (const char *, ...)); void VDECL(lc_warning, (const char *, ...)); -char * FDECL(decode_parm_chr, (CHAR_P)); -char * FDECL(decode_parm_str, (char *)); -struct opvar * FDECL(set_opvar_int, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_coord, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_region, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_mapchar, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_monst, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_obj, (struct opvar *, long)); -struct opvar * FDECL(set_opvar_str, (struct opvar *, const char *)); -struct opvar * FDECL(set_opvar_var, (struct opvar *, const char *)); +char *FDECL(decode_parm_chr, (CHAR_P)); +char *FDECL(decode_parm_str, (char *)); +struct opvar *FDECL(set_opvar_int, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_coord, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_region, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_mapchar, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_monst, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_obj, (struct opvar *, long)); +struct opvar *FDECL(set_opvar_str, (struct opvar *, const char *)); +struct opvar *FDECL(set_opvar_var, (struct opvar *, const char *)); void VDECL(add_opvars, (sp_lev *, const char *, ...)); void NDECL(break_stmt_start); void FDECL(break_stmt_end, (sp_lev *)); @@ -137,73 +142,71 @@ char *FDECL(funcdef_paramtypes, (struct lc_funcdefs *)); const char *FDECL(spovar2str, (long)); void FDECL(vardef_used, (struct lc_vardefs *, char *)); void FDECL(check_vardef_type, (struct lc_vardefs *, char *, long)); -struct lc_vardefs * FDECL(add_vardef_type, (struct lc_vardefs *, char *, long)); +struct lc_vardefs *FDECL(add_vardef_type, + (struct lc_vardefs *, char *, long)); int FDECL(reverse_jmp_opcode, (int)); -struct opvar * FDECL(opvar_clone, (struct opvar *)); +struct opvar *FDECL(opvar_clone, (struct opvar *)); void FDECL(start_level_def, (sp_lev **, char *)); +static struct { + const char *name; + int type; +} trap_types[] = { { "arrow", ARROW_TRAP }, + { "dart", DART_TRAP }, + { "falling rock", ROCKTRAP }, + { "board", SQKY_BOARD }, + { "bear", BEAR_TRAP }, + { "land mine", LANDMINE }, + { "rolling boulder", ROLLING_BOULDER_TRAP }, + { "sleep gas", SLP_GAS_TRAP }, + { "rust", RUST_TRAP }, + { "fire", FIRE_TRAP }, + { "pit", PIT }, + { "spiked pit", SPIKED_PIT }, + { "hole", HOLE }, + { "trap door", TRAPDOOR }, + { "teleport", TELEP_TRAP }, + { "level teleport", LEVEL_TELEP }, + { "magic portal", MAGIC_PORTAL }, + { "web", WEB }, + { "statue", STATUE_TRAP }, + { "magic", MAGIC_TRAP }, + { "anti magic", ANTI_MAGIC }, + { "polymorph", POLY_TRAP }, + { 0, 0 } }; static struct { - const char *name; - int type; -} trap_types[] = { - { "arrow", ARROW_TRAP }, - { "dart", DART_TRAP }, - { "falling rock", ROCKTRAP }, - { "board", SQKY_BOARD }, - { "bear", BEAR_TRAP }, - { "land mine", LANDMINE }, - { "rolling boulder", ROLLING_BOULDER_TRAP }, - { "sleep gas", SLP_GAS_TRAP }, - { "rust", RUST_TRAP }, - { "fire", FIRE_TRAP }, - { "pit", PIT }, - { "spiked pit", SPIKED_PIT }, - { "hole", HOLE }, - { "trap door", TRAPDOOR }, - { "teleport", TELEP_TRAP }, - { "level teleport", LEVEL_TELEP }, - { "magic portal", MAGIC_PORTAL }, - { "web", WEB }, - { "statue", STATUE_TRAP }, - { "magic", MAGIC_TRAP }, - { "anti magic", ANTI_MAGIC }, - { "polymorph", POLY_TRAP }, - { 0, 0 } -}; - -static struct { - const char *name; - int type; + const char *name; + int type; } room_types[] = { - /* for historical reasons, room types are not contiguous numbers */ - /* (type 1 is skipped) */ - { "ordinary", OROOM }, - { "throne", COURT }, - { "swamp", SWAMP }, - { "vault", VAULT }, - { "beehive", BEEHIVE }, - { "morgue", MORGUE }, - { "barracks", BARRACKS }, - { "zoo", ZOO }, - { "delphi", DELPHI }, - { "temple", TEMPLE }, - { "anthole", ANTHOLE }, - { "cocknest", COCKNEST }, - { "leprehall", LEPREHALL }, - { "shop", SHOPBASE }, - { "armor shop", ARMORSHOP }, - { "scroll shop", SCROLLSHOP }, - { "potion shop", POTIONSHOP }, - { "weapon shop", WEAPONSHOP }, - { "food shop", FOODSHOP }, - { "ring shop", RINGSHOP }, - { "wand shop", WANDSHOP }, - { "tool shop", TOOLSHOP }, - { "book shop", BOOKSHOP }, - { "health food shop", FODDERSHOP }, - { "candle shop", CANDLESHOP }, - { 0, 0 } + /* for historical reasons, room types are not contiguous numbers */ + /* (type 1 is skipped) */ + { "ordinary", OROOM }, + { "throne", COURT }, + { "swamp", SWAMP }, + { "vault", VAULT }, + { "beehive", BEEHIVE }, + { "morgue", MORGUE }, + { "barracks", BARRACKS }, + { "zoo", ZOO }, + { "delphi", DELPHI }, + { "temple", TEMPLE }, + { "anthole", ANTHOLE }, + { "cocknest", COCKNEST }, + { "leprehall", LEPREHALL }, + { "shop", SHOPBASE }, + { "armor shop", ARMORSHOP }, + { "scroll shop", SCROLLSHOP }, + { "potion shop", POTIONSHOP }, + { "weapon shop", WEAPONSHOP }, + { "food shop", FOODSHOP }, + { "ring shop", RINGSHOP }, + { "wand shop", WANDSHOP }, + { "tool shop", TOOLSHOP }, + { "book shop", BOOKSHOP }, + { "health food shop", FODDERSHOP }, + { "candle shop", CANDLESHOP }, + { 0, 0 } }; const char *fname = "(stdin)"; @@ -235,83 +238,68 @@ main(argc, argv) int argc; char **argv; { - FILE *fin; - int i; - boolean errors_encountered = FALSE; + FILE *fin; + int i; + boolean errors_encountered = FALSE; #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__)) - static char *mac_argv[] = { "lev_comp", /* dummy argv[0] */ - ":dat:Arch.des", - ":dat:Barb.des", - ":dat:Caveman.des", - ":dat:Healer.des", - ":dat:Knight.des", - ":dat:Monk.des", - ":dat:Priest.des", - ":dat:Ranger.des", - ":dat:Rogue.des", - ":dat:Samurai.des", - ":dat:Tourist.des", - ":dat:Valkyrie.des", - ":dat:Wizard.des", - ":dat:bigroom.des", - ":dat:castle.des", - ":dat:endgame.des", - ":dat:gehennom.des", - ":dat:knox.des", - ":dat:medusa.des", - ":dat:mines.des", - ":dat:oracle.des", - ":dat:sokoban.des", - ":dat:tower.des", - ":dat:yendor.des" - }; + static char *mac_argv[] = { + "lev_comp", /* dummy argv[0] */ + ":dat:Arch.des", ":dat:Barb.des", ":dat:Caveman.des", + ":dat:Healer.des", ":dat:Knight.des", ":dat:Monk.des", + ":dat:Priest.des", ":dat:Ranger.des", ":dat:Rogue.des", + ":dat:Samurai.des", ":dat:Tourist.des", ":dat:Valkyrie.des", + ":dat:Wizard.des", ":dat:bigroom.des", ":dat:castle.des", + ":dat:endgame.des", ":dat:gehennom.des", ":dat:knox.des", + ":dat:medusa.des", ":dat:mines.des", ":dat:oracle.des", + ":dat:sokoban.des", ":dat:tower.des", ":dat:yendor.des" + }; - argc = SIZE(mac_argv); - argv = mac_argv; + argc = SIZE(mac_argv); + argv = mac_argv; #endif - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_init(); - objects_init(); - decl_init(); - /* this one does something... */ - init_obj_classes(); + /* Note: these initializers don't do anything except guarantee that + we're linked properly. + */ + monst_init(); + objects_init(); + decl_init(); + /* this one does something... */ + init_obj_classes(); - init_yyout(stdout); - if (argc == 1) { /* Read standard input */ - init_yyin(stdin); - (void) yyparse(); - if (fatal_error > 0) { - errors_encountered = TRUE; - } - } else { /* Otherwise every argument is a filename */ - for(i=1; i 0 || got_errors > 0) { - errors_encountered = TRUE; - fatal_error = 0; - } - } - } - } - exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + init_yyout(stdout); + if (argc == 1) { /* Read standard input */ + init_yyin(stdin); + (void) yyparse(); + if (fatal_error > 0) { + errors_encountered = TRUE; + } + } else { /* Otherwise every argument is a filename */ + for (i = 1; i < argc; i++) { + fname = argv[i]; + if (!strcmp(fname, "-v")) { + be_verbose++; + continue; + } + fin = freopen(fname, "r", stdin); + if (!fin) { + lc_pline("Can't open \"%s\" for input.\n", fname); + perror(fname); + errors_encountered = TRUE; + } else { + fname_counter = 1; + init_yyin(fin); + (void) yyparse(); + nh_line_number = 1; + if (fatal_error > 0 || got_errors > 0) { + errors_encountered = TRUE; + fatal_error = 0; + } + } + } + } + exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } /* @@ -326,19 +314,18 @@ void yyerror(s) const char *s; { - char *e = ((char *)s + strlen(s) - 1); + char *e = ((char *) s + strlen(s) - 1); - (void) fprintf(stderr, "%s: line %d, pos %d: %s", - fname, nh_line_number, - token_start_pos - (int)strlen(curr_token), s); - if (*e != '.' && *e != '!') - (void) fprintf(stderr, " at \"%s\"", curr_token); - (void) fprintf(stderr, "\n"); + (void) fprintf(stderr, "%s: line %d, pos %d: %s", fname, nh_line_number, + token_start_pos - (int) strlen(curr_token), s); + if (*e != '.' && *e != '!') + (void) fprintf(stderr, " at \"%s\"", curr_token); + (void) fprintf(stderr, "\n"); - if (++fatal_error > MAX_ERRORS) { - (void) fprintf(stderr,"Too many errors, good bye!\n"); - exit(EXIT_FAILURE); - } + if (++fatal_error > MAX_ERRORS) { + (void) fprintf(stderr, "Too many errors, good bye!\n"); + exit(EXIT_FAILURE); + } } /* @@ -348,8 +335,8 @@ void yywarning(s) const char *s; { - (void) fprintf(stderr, "%s: line %d : WARNING : %s\n", - fname, nh_line_number, s); + (void) fprintf(stderr, "%s: line %d : WARNING : %s\n", fname, + nh_line_number, s); } /* @@ -358,7 +345,7 @@ const char *s; int yywrap() { - return 1; + return 1; } /* @@ -368,80 +355,90 @@ yywrap() * * Using state for message/warning/error mode simplifies calling interface. */ -#define LC_PLINE_MESSAGE 0 -#define LC_PLINE_WARNING 1 -#define LC_PLINE_ERROR 2 +#define LC_PLINE_MESSAGE 0 +#define LC_PLINE_WARNING 1 +#define LC_PLINE_ERROR 2 static int lc_pline_mode = LC_PLINE_MESSAGE; #if defined(USE_STDARG) || defined(USE_VARARGS) static void FDECL(lc_vpline, (const char *, va_list)); -void -lc_pline VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, char *); - lc_vpline(line, VA_ARGS); - VA_END(); +void lc_pline +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, char *); + lc_vpline(line, VA_ARGS); + VA_END(); } -# ifdef USE_STDARG +#ifdef USE_STDARG static void -lc_vpline(const char *line, va_list the_args) { -# else +lc_vpline(const char *line, va_list the_args) +{ +#else static void -lc_vpline(line, the_args) const char *line; va_list the_args; { -# endif +lc_vpline(line, the_args) +const char *line; +va_list the_args; +{ +#endif -#else /* USE_STDARG | USE_VARARG */ +#else /* USE_STDARG | USE_VARARG */ #define lc_vpline lc_pline -void -lc_pline VA_DECL(const char *, line) -#endif /* USE_STDARG | USE_VARARG */ +void lc_pline +VA_DECL(const char *, line) +#endif /* USE_STDARG | USE_VARARG */ - char pbuf[3*BUFSZ]; - static char nomsg[] = "(no message)"; -/* Do NOT use VA_START and VA_END in here... see above */ + char pbuf[3 * BUFSZ]; + static char nomsg[] = "(no message)"; + /* Do NOT use VA_START and VA_END in here... see above */ - if (!line || !*line) line = nomsg; /* shouldn't happen */ - if (index(line, '%')) { - Vsprintf(pbuf, line, VA_ARGS); - pbuf[BUFSZ-1] = '\0'; /* truncate if long */ - line = pbuf; - } - switch (lc_pline_mode) { - case LC_PLINE_ERROR: yyerror(line); break; - case LC_PLINE_WARNING: yywarning(line); break; - default: (void)fprintf(stderr, "%s\n", line); break; - } - lc_pline_mode = LC_PLINE_MESSAGE; /* reset to default */ - return; + if (!line || !*line) + line = nomsg; /* shouldn't happen */ + if (index(line, '%')) { + Vsprintf(pbuf, line, VA_ARGS); + pbuf[BUFSZ - 1] = '\0'; /* truncate if long */ + line = pbuf; + } + switch (lc_pline_mode) { + case LC_PLINE_ERROR: + yyerror(line); + break; + case LC_PLINE_WARNING: + yywarning(line); + break; + default: + (void) fprintf(stderr, "%s\n", line); + break; + } + lc_pline_mode = LC_PLINE_MESSAGE; /* reset to default */ + return; } /*VARARGS1*/ -void -lc_error VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, const char *); - lc_pline_mode = LC_PLINE_ERROR; - lc_vpline(line, VA_ARGS); - VA_END(); - return; +void lc_error +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, const char *); + lc_pline_mode = LC_PLINE_ERROR; + lc_vpline(line, VA_ARGS); + VA_END(); + return; } /*VARARGS1*/ -void -lc_warning VA_DECL(const char *, line) - VA_START(line); - VA_INIT(line, const char *); - lc_pline_mode = LC_PLINE_WARNING; - lc_vpline(line, VA_ARGS); - VA_END(); - return; +void lc_warning +VA_DECL(const char *, line) + VA_START(line); + VA_INIT(line, const char *); + lc_pline_mode = LC_PLINE_WARNING; + lc_vpline(line, VA_ARGS); + VA_END(); + return; } - char * decode_parm_chr(chr) char chr; @@ -449,15 +446,33 @@ char chr; static char buf[32]; switch (chr) { - default: Strcpy(buf, "unknown"); break; - case 'i': Strcpy(buf, "int"); break; - case 'r': Strcpy(buf, "region"); break; - case 's': Strcpy(buf, "str"); break; - case 'O': Strcpy(buf, "obj"); break; - case 'c': Strcpy(buf, "coord"); break; - case ' ': Strcpy(buf, "nothing"); break; - case 'm': Strcpy(buf, "mapchar"); break; - case 'M': Strcpy(buf, "monster"); break; + default: + Strcpy(buf, "unknown"); + break; + case 'i': + Strcpy(buf, "int"); + break; + case 'r': + Strcpy(buf, "region"); + break; + case 's': + Strcpy(buf, "str"); + break; + case 'O': + Strcpy(buf, "obj"); + break; + case 'c': + Strcpy(buf, "coord"); + break; + case ' ': + Strcpy(buf, "nothing"); + break; + case 'm': + Strcpy(buf, "mapchar"); + break; + case 'M': + Strcpy(buf, "monster"); + break; } return buf; } @@ -470,19 +485,19 @@ char *str; char *p = str; tmpbuf[0] = '\0'; if (str) { - for ( ; *p; p++) { - Strcat(tmpbuf, decode_parm_chr(*p)); - if (*(p + 1)) Strcat(tmpbuf, ", "); - } + for (; *p; p++) { + Strcat(tmpbuf, decode_parm_chr(*p)); + if (*(p + 1)) + Strcat(tmpbuf, ", "); + } } return tmpbuf; } - struct opvar * set_opvar_int(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_INT; @@ -494,7 +509,7 @@ long val; struct opvar * set_opvar_coord(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_COORD; @@ -506,7 +521,7 @@ long val; struct opvar * set_opvar_region(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_REGION; @@ -518,7 +533,7 @@ long val; struct opvar * set_opvar_mapchar(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_MAPCHAR; @@ -530,7 +545,7 @@ long val; struct opvar * set_opvar_monst(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_MONST; @@ -542,7 +557,7 @@ long val; struct opvar * set_opvar_obj(ov, val) struct opvar *ov; -long val; +long val; { if (ov) { ov->spovartyp = SPOVAR_OBJ; @@ -558,7 +573,7 @@ const char *val; { if (ov) { ov->spovartyp = SPOVAR_STRING; - ov->vardata.str = (val) ? strdup(val) : NULL; + ov->vardata.str = (val) ? strdup(val) : NULL; } return ov; } @@ -570,116 +585,122 @@ const char *val; { if (ov) { ov->spovartyp = SPOVAR_VARIABLE; - ov->vardata.str = (val) ? strdup(val) : NULL; + ov->vardata.str = (val) ? strdup(val) : NULL; } return ov; } -#define New(type) \ - (type *) memset((genericptr_t)alloc(sizeof(type)), 0, sizeof(type)) +#define New(type) \ + (type *) memset((genericptr_t) alloc(sizeof(type)), 0, sizeof(type)) #if defined(USE_STDARG) || defined(USE_VARARGS) static void FDECL(vadd_opvars, (sp_lev *, const char *, va_list)); -void -add_opvars VA_DECL2(sp_lev *, sp, const char *, fmt) - VA_START(fmt); - VA_INIT(fmt, char *); - vadd_opvars(sp, fmt, VA_ARGS); - VA_END(); +void add_opvars +VA_DECL2(sp_lev *, sp, const char *, fmt) + VA_START(fmt); + VA_INIT(fmt, char *); + vadd_opvars(sp, fmt, VA_ARGS); + VA_END(); } -# ifdef USE_STDARG +#ifdef USE_STDARG static void -vadd_opvars(sp_lev *sp, const char *fmt, va_list the_args) { -# else +vadd_opvars(sp_lev *sp, const char *fmt, va_list the_args) +{ +#else static void -vadd_opvars(sp, fmt, the_args) sp_lev *sp; const char *fmt; va_list the_args; { -# endif +vadd_opvars(sp, fmt, the_args) +sp_lev *sp; +const char *fmt; +va_list the_args; +{ +#endif -#else /* USE_STDARG | USE_VARARG */ +#else /* USE_STDARG | USE_VARARG */ #define vadd_opvars add_opvars -void -add_opvars VA_DECL2(sp_lev *, sp, const char *, fmt) -#endif /* USE_STDARG | USE_VARARG */ +void add_opvars +VA_DECL2(sp_lev *, sp, const char *, fmt) +#endif /* USE_STDARG | USE_VARARG */ const char *p, *lp; long la; -/* Do NOT use VA_START and VA_END in here... see above */ + /* Do NOT use VA_START and VA_END in here... see above */ - for(p = fmt; *p != '\0'; p++) { - switch(*p) { - case ' ': break; - case 'i': /* integer */ - { - struct opvar *ov = New(struct opvar); - set_opvar_int(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'c': /* coordinate */ - { - struct opvar *ov = New(struct opvar); - set_opvar_coord(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'r': /* region */ - { - struct opvar *ov = New(struct opvar); - set_opvar_region(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'm': /* mapchar */ - { - struct opvar *ov = New(struct opvar); - set_opvar_mapchar(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'M': /* monster */ - { - struct opvar *ov = New(struct opvar); - set_opvar_monst(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'O': /* object */ - { - struct opvar *ov = New(struct opvar); - set_opvar_obj(ov, VA_NEXT(la, long)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 's': /* string */ - { - struct opvar *ov = New(struct opvar); - set_opvar_str(ov, VA_NEXT(lp, const char *)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'v': /* variable */ - { - struct opvar *ov = New(struct opvar); - set_opvar_var(ov, VA_NEXT(lp, const char *)); - add_opcode(sp, SPO_PUSH, ov); - break; - } - case 'o': /* opcode */ - { - long i = VA_NEXT(la, int); - if (i < 0 || i >= MAX_SP_OPCODES) - lc_pline("add_opvars: unknown opcode '%ld'.", i); - add_opcode(sp, i, NULL); - break; - } - default: - lc_pline("add_opvars: illegal format character '%c'.", *p); - break; - } + for (p = fmt; *p != '\0'; p++) { + switch (*p) { + case ' ': + break; + case 'i': /* integer */ + { + struct opvar *ov = New(struct opvar); + set_opvar_int(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'c': /* coordinate */ + { + struct opvar *ov = New(struct opvar); + set_opvar_coord(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'r': /* region */ + { + struct opvar *ov = New(struct opvar); + set_opvar_region(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'm': /* mapchar */ + { + struct opvar *ov = New(struct opvar); + set_opvar_mapchar(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'M': /* monster */ + { + struct opvar *ov = New(struct opvar); + set_opvar_monst(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'O': /* object */ + { + struct opvar *ov = New(struct opvar); + set_opvar_obj(ov, VA_NEXT(la, long) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 's': /* string */ + { + struct opvar *ov = New(struct opvar); + set_opvar_str(ov, VA_NEXT(lp, const char *) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'v': /* variable */ + { + struct opvar *ov = New(struct opvar); + set_opvar_var(ov, VA_NEXT(lp, const char *) ); + add_opcode(sp, SPO_PUSH, ov); + break; + } + case 'o': /* opcode */ + { + long i = VA_NEXT(la, int); + if (i < 0 || i >= MAX_SP_OPCODES) + lc_pline("add_opvars: unknown opcode '%ld'.", i); + add_opcode(sp, i, NULL); + break; + } + default: + lc_pline("add_opvars: illegal format character '%c'.", *p); + break; + } } return; } @@ -692,31 +713,34 @@ break_stmt_start() void break_stmt_end(splev) - sp_lev *splev; +sp_lev *splev; { struct lc_breakdef *tmp = break_list; struct lc_breakdef *prv = NULL; while (tmp) { - if (tmp->break_depth == allow_break_statements) { - struct lc_breakdef *nxt = tmp->next; - set_opvar_int(tmp->breakpoint, splev->n_opcodes - tmp->breakpoint->vardata.l-1); - tmp->next = NULL; - Free(tmp); - if (!prv) break_list = NULL; - else prv->next = nxt; - tmp = nxt; - } else { - prv = tmp; - tmp = tmp->next; - } + if (tmp->break_depth == allow_break_statements) { + struct lc_breakdef *nxt = tmp->next; + set_opvar_int(tmp->breakpoint, + splev->n_opcodes - tmp->breakpoint->vardata.l - 1); + tmp->next = NULL; + Free(tmp); + if (!prv) + break_list = NULL; + else + prv->next = nxt; + tmp = nxt; + } else { + prv = tmp; + tmp = tmp->next; + } } allow_break_statements--; } void -break_stmt_new(splev,i) - sp_lev *splev; - long i; +break_stmt_new(splev, i) +sp_lev *splev; +long i; { struct lc_breakdef *tmp = New(struct lc_breakdef); tmp->breakpoint = New(struct opvar); @@ -730,13 +754,13 @@ break_stmt_new(splev,i) struct lc_funcdefs * funcdef_new(addr, name) - long addr; - char *name; +long addr; +char *name; { struct lc_funcdefs *f = New(struct lc_funcdefs); if (!f) { - lc_error("Could not alloc function definition for '%s'.", name); - return NULL; + lc_error("Could not alloc function definition for '%s'.", name); + return NULL; } f->next = NULL; f->addr = addr; @@ -751,37 +775,37 @@ funcdef_new(addr, name) void funcdef_free_all(fchain) - struct lc_funcdefs *fchain; +struct lc_funcdefs *fchain; { struct lc_funcdefs *tmp = fchain; struct lc_funcdefs *nxt; struct lc_funcdefs_parm *tmpparam; while (tmp) { - nxt = tmp->next; - Free(tmp->name); - while (tmp->params) { - tmpparam = tmp->params->next; - Free(tmp->params->name); - tmp->params = tmpparam; - } - /* FIXME: free tmp->code */ - Free(tmp); - tmp = nxt; + nxt = tmp->next; + Free(tmp->name); + while (tmp->params) { + tmpparam = tmp->params->next; + Free(tmp->params->name); + tmp->params = tmpparam; + } + /* FIXME: free tmp->code */ + Free(tmp); + tmp = nxt; } } - char * funcdef_paramtypes(f) - struct lc_funcdefs *f; +struct lc_funcdefs *f; { int i = 0; struct lc_funcdefs_parm *fp = f->params; - char *tmp = (char *)alloc((f->n_params) + 1); - if (!tmp) return NULL; + char *tmp = (char *) alloc((f->n_params) + 1); + if (!tmp) + return NULL; while (fp) { - tmp[i++] = fp->parmtype; - fp = fp->next; + tmp[i++] = fp->parmtype; + fp = fp->next; } tmp[i] = '\0'; return tmp; @@ -789,31 +813,32 @@ funcdef_paramtypes(f) struct lc_funcdefs * funcdef_defined(f, name, casesense) - struct lc_funcdefs *f; - char *name; - int casesense; +struct lc_funcdefs *f; +char *name; +int casesense; { while (f) { - if (casesense) { - if (!strcmp(name, f->name)) return f; - } else { - if (!case_insensitive_comp(name, f->name)) return f; - } - f = f->next; + if (casesense) { + if (!strcmp(name, f->name)) + return f; + } else { + if (!case_insensitive_comp(name, f->name)) + return f; + } + f = f->next; } return NULL; } - struct lc_vardefs * vardef_new(typ, name) - long typ; - char *name; +long typ; +char *name; { struct lc_vardefs *f = New(struct lc_vardefs); if (!f) { - lc_error("Could not alloc variable definition for '%s'.", name); - return NULL; + lc_error("Could not alloc variable definition for '%s'.", name); + return NULL; } f->next = NULL; f->var_type = typ; @@ -824,40 +849,42 @@ vardef_new(typ, name) void vardef_free_all(fchain) - struct lc_vardefs *fchain; +struct lc_vardefs *fchain; { struct lc_vardefs *tmp = fchain; struct lc_vardefs *nxt; while (tmp) { - if (be_verbose && (tmp->n_used == 0)) - lc_warning("Unused variable '%s'", tmp->name); - nxt = tmp->next; - Free(tmp->name); - Free(tmp); - tmp = nxt; + if (be_verbose && (tmp->n_used == 0)) + lc_warning("Unused variable '%s'", tmp->name); + nxt = tmp->next; + Free(tmp->name); + Free(tmp); + tmp = nxt; } } struct lc_vardefs * vardef_defined(f, name, casesense) - struct lc_vardefs *f; - char *name; - int casesense; +struct lc_vardefs *f; +char *name; +int casesense; { while (f) { - if (casesense) { - if (!strcmp(name, f->name)) return f; - } else { - if (!case_insensitive_comp(name, f->name)) return f; - } - f = f->next; + if (casesense) { + if (!strcmp(name, f->name)) + return f; + } else { + if (!case_insensitive_comp(name, f->name)) + return f; + } + f = f->next; } return NULL; } const char * spovar2str(spovar) - long spovar; +long spovar; { static int togl = 0; static char buf[2][128]; @@ -866,15 +893,33 @@ spovar2str(spovar) spovar &= ~SPOVAR_ARRAY; switch (spovar) { - default: lc_error("spovar2str(%ld)", spovar); break; - case SPOVAR_INT: n = "integer"; break; - case SPOVAR_STRING: n = "string"; break; - case SPOVAR_VARIABLE: n = "variable"; break; - case SPOVAR_COORD: n = "coordinate"; break; - case SPOVAR_REGION: n = "region"; break; - case SPOVAR_MAPCHAR: n = "mapchar"; break; - case SPOVAR_MONST: n = "monster"; break; - case SPOVAR_OBJ: n = "object"; break; + default: + lc_error("spovar2str(%ld)", spovar); + break; + case SPOVAR_INT: + n = "integer"; + break; + case SPOVAR_STRING: + n = "string"; + break; + case SPOVAR_VARIABLE: + n = "variable"; + break; + case SPOVAR_COORD: + n = "coordinate"; + break; + case SPOVAR_REGION: + n = "region"; + break; + case SPOVAR_MAPCHAR: + n = "mapchar"; + break; + case SPOVAR_MONST: + n = "monster"; + break; + case SPOVAR_OBJ: + n = "object"; + break; } togl = ((togl + 1) % 2); @@ -885,115 +930,120 @@ spovar2str(spovar) void vardef_used(vd, varname) - struct lc_vardefs *vd; - char *varname; +struct lc_vardefs *vd; +char *varname; { struct lc_vardefs *tmp; - if ((tmp = vardef_defined(vd, varname, 1))) tmp->n_used++; + if ((tmp = vardef_defined(vd, varname, 1))) + tmp->n_used++; } void check_vardef_type(vd, varname, vartype) - struct lc_vardefs *vd; - char *varname; - long vartype; +struct lc_vardefs *vd; +char *varname; +long vartype; { struct lc_vardefs *tmp; if ((tmp = vardef_defined(vd, varname, 1))) { - if (tmp->var_type != vartype) - lc_error("Trying to use variable '%s' as %s, when it is %s.", - varname, spovar2str(vartype), spovar2str(tmp->var_type)); - } else lc_error("Variable '%s' not defined.", varname); + if (tmp->var_type != vartype) + lc_error("Trying to use variable '%s' as %s, when it is %s.", + varname, spovar2str(vartype), spovar2str(tmp->var_type)); + } else + lc_error("Variable '%s' not defined.", varname); } struct lc_vardefs * add_vardef_type(vd, varname, vartype) - struct lc_vardefs *vd; - char *varname; - long vartype; +struct lc_vardefs *vd; +char *varname; +long vartype; { struct lc_vardefs *tmp; if ((tmp = vardef_defined(vd, varname, 1))) { - if (tmp->var_type != vartype) - lc_error("Trying to redefine variable '%s' as %s, when it is %s.", - varname, spovar2str(vartype), spovar2str(tmp->var_type)); + if (tmp->var_type != vartype) + lc_error("Trying to redefine variable '%s' as %s, when it is %s.", + varname, spovar2str(vartype), spovar2str(tmp->var_type)); } else { - tmp = vardef_new(vartype, varname); - tmp->next = vd; - return tmp; + tmp = vardef_new(vartype, varname); + tmp->next = vd; + return tmp; } return vd; } int reverse_jmp_opcode(opcode) - int opcode; +int opcode; { switch (opcode) { - case SPO_JE: return SPO_JNE; - case SPO_JNE: return SPO_JE; - case SPO_JL: return SPO_JGE; - case SPO_JG: return SPO_JLE; - case SPO_JLE: return SPO_JG; - case SPO_JGE: return SPO_JL; - default: lc_error("Cannot reverse comparison jmp opcode %d.", opcode); return SPO_NULL; + case SPO_JE: + return SPO_JNE; + case SPO_JNE: + return SPO_JE; + case SPO_JL: + return SPO_JGE; + case SPO_JG: + return SPO_JLE; + case SPO_JLE: + return SPO_JG; + case SPO_JGE: + return SPO_JL; + default: + lc_error("Cannot reverse comparison jmp opcode %d.", opcode); + return SPO_NULL; } } /* basically copied from src/sp_lev.c */ struct opvar * opvar_clone(ov) - struct opvar *ov; +struct opvar *ov; { if (ov) { - struct opvar *tmpov = (struct opvar *)alloc(sizeof(struct opvar)); - if (!tmpov) panic("could not alloc opvar struct"); - switch (ov->spovartyp) { - case SPOVAR_COORD: - case SPOVAR_REGION: - case SPOVAR_MAPCHAR: - case SPOVAR_MONST: - case SPOVAR_OBJ: - case SPOVAR_INT: - { - tmpov->spovartyp = ov->spovartyp; - tmpov->vardata.l = ov->vardata.l; - } - break; - case SPOVAR_VARIABLE: - case SPOVAR_STRING: - { - int len = strlen(ov->vardata.str); - tmpov->spovartyp = ov->spovartyp; - tmpov->vardata.str = (char *)alloc(len+1); - (void)memcpy((genericptr_t)tmpov->vardata.str, - (genericptr_t)ov->vardata.str, len); - tmpov->vardata.str[len] = '\0'; - } - break; - default: - { - lc_error("Unknown opvar_clone value type (%d)!", ov->spovartyp); - } - } - return tmpov; + struct opvar *tmpov = (struct opvar *) alloc(sizeof(struct opvar)); + if (!tmpov) + panic("could not alloc opvar struct"); + switch (ov->spovartyp) { + case SPOVAR_COORD: + case SPOVAR_REGION: + case SPOVAR_MAPCHAR: + case SPOVAR_MONST: + case SPOVAR_OBJ: + case SPOVAR_INT: { + tmpov->spovartyp = ov->spovartyp; + tmpov->vardata.l = ov->vardata.l; + } break; + case SPOVAR_VARIABLE: + case SPOVAR_STRING: { + int len = strlen(ov->vardata.str); + tmpov->spovartyp = ov->spovartyp; + tmpov->vardata.str = (char *) alloc(len + 1); + (void) memcpy((genericptr_t) tmpov->vardata.str, + (genericptr_t) ov->vardata.str, len); + tmpov->vardata.str[len] = '\0'; + } break; + default: { + lc_error("Unknown opvar_clone value type (%d)!", ov->spovartyp); + } + } + return tmpov; } return NULL; } - void splev_add_from(splev, from_splev) - sp_lev *splev; - sp_lev *from_splev; +sp_lev *splev; +sp_lev *from_splev; { int i; if (splev && from_splev) - for (i = 0; i < from_splev->n_opcodes; i++) - add_opcode(splev, from_splev->opcodes[i].opcode, opvar_clone(from_splev->opcodes[i].opdat)); + for (i = 0; i < from_splev->n_opcodes; i++) + add_opcode(splev, from_splev->opcodes[i].opcode, + opvar_clone(from_splev->opcodes[i].opdat)); } - void start_level_def(splev, ldfname) sp_lev **splev; @@ -1001,15 +1051,15 @@ char *ldfname; { struct lc_funcdefs *f; if (index(ldfname, '.')) - lc_error("Invalid dot ('.') in level name '%s'.", ldfname); + lc_error("Invalid dot ('.') in level name '%s'.", ldfname); if ((int) strlen(ldfname) > 14) - lc_error("Level names limited to 14 characters ('%s').", ldfname); + lc_error("Level names limited to 14 characters ('%s').", ldfname); f = function_definitions; while (f) { - f->n_called = 0; - f = f->next; + f->n_called = 0; + f = f->next; } - *splev = (sp_lev *)alloc(sizeof(sp_lev)); + *splev = (sp_lev *) alloc(sizeof(sp_lev)); (*splev)->n_opcodes = 0; (*splev)->opcodes = NULL; @@ -1017,7 +1067,6 @@ char *ldfname; variable_definitions = NULL; } - /* * Find the type of floor, knowing its char representation. */ @@ -1025,15 +1074,15 @@ int get_floor_type(c) char c; { - int val; + int val; - SpinCursor(3); - val = what_map_char(c); - if(val == INVALID_TYPE) { - val = ERR; - yywarning("Invalid fill character in MAZE declaration"); - } - return val; + SpinCursor(3); + val = what_map_char(c); + if (val == INVALID_TYPE) { + val = ERR; + yywarning("Invalid fill character in MAZE declaration"); + } + return val; } /* @@ -1043,13 +1092,13 @@ int get_room_type(s) char *s; { - register int i; + register int i; - SpinCursor(3); - for(i=0; room_types[i].name; i++) - if (!strcmp(s, room_types[i].name)) - return ((int) room_types[i].type); - return ERR; + SpinCursor(3); + for (i = 0; room_types[i].name; i++) + if (!strcmp(s, room_types[i].name)) + return ((int) room_types[i].type); + return ERR; } /* @@ -1059,13 +1108,13 @@ int get_trap_type(s) char *s; { - register int i; + register int i; - SpinCursor(3); - for (i=0; trap_types[i].name; i++) - if(!strcmp(s,trap_types[i].name)) - return trap_types[i].type; - return ERR; + SpinCursor(3); + for (i = 0; trap_types[i].name; i++) + if (!strcmp(s, trap_types[i].name)) + return trap_types[i].type; + return ERR; } /* @@ -1076,24 +1125,27 @@ get_monster_id(s, c) char *s; char c; { - register int i, class; + register int i, class; - SpinCursor(3); - class = c ? def_char_to_monclass(c) : 0; - if (class == MAXMCLASSES) return ERR; + SpinCursor(3); + class = c ? def_char_to_monclass(c) : 0; + if (class == MAXMCLASSES) + return ERR; - for (i = LOW_PM; i < NUMMONS; i++) - if (!class || class == mons[i].mlet) - if (!strcmp(s, mons[i].mname)) return i; - /* didn't find it; lets try case insensitive search */ - for (i = LOW_PM; i < NUMMONS; i++) - if (!class || class == mons[i].mlet) - if (!case_insensitive_comp(s, mons[i].mname)) { - if (be_verbose) - lc_warning("Monster type \"%s\" matches \"%s\".", s, mons[i].mname); - return i; - } - return ERR; + for (i = LOW_PM; i < NUMMONS; i++) + if (!class || class == mons[i].mlet) + if (!strcmp(s, mons[i].mname)) + return i; + /* didn't find it; lets try case insensitive search */ + for (i = LOW_PM; i < NUMMONS; i++) + if (!class || class == mons[i].mlet) + if (!case_insensitive_comp(s, mons[i].mname)) { + if (be_verbose) + lc_warning("Monster type \"%s\" matches \"%s\".", s, + mons[i].mname); + return i; + } + return ERR; } /* @@ -1102,46 +1154,49 @@ char c; int get_object_id(s, c) char *s; -char c; /* class */ +char c; /* class */ { - int i, class; - const char *objname; + int i, class; + const char *objname; - SpinCursor(3); - class = (c > 0) ? def_char_to_objclass(c) : 0; - if (class == MAXOCLASSES) return ERR; + SpinCursor(3); + class = (c > 0) ? def_char_to_objclass(c) : 0; + if (class == MAXOCLASSES) + return ERR; - for (i = class ? bases[class] : 0; i < NUM_OBJECTS; i++) { - if (class && objects[i].oc_class != class) break; - objname = obj_descr[i].oc_name; - if (objname && !strcmp(s, objname)) - return i; - } - for (i = class ? bases[class] : 0; i < NUM_OBJECTS; i++) { - if (class && objects[i].oc_class != class) break; - objname = obj_descr[i].oc_name; - if (objname && !case_insensitive_comp(s, objname)) { - if (be_verbose) - lc_warning("Object type \"%s\" matches \"%s\".", s, objname); - return i; - } - } - return ERR; + for (i = class ? bases[class] : 0; i < NUM_OBJECTS; i++) { + if (class && objects[i].oc_class != class) + break; + objname = obj_descr[i].oc_name; + if (objname && !strcmp(s, objname)) + return i; + } + for (i = class ? bases[class] : 0; i < NUM_OBJECTS; i++) { + if (class && objects[i].oc_class != class) + break; + objname = obj_descr[i].oc_name; + if (objname && !case_insensitive_comp(s, objname)) { + if (be_verbose) + lc_warning("Object type \"%s\" matches \"%s\".", s, objname); + return i; + } + } + return ERR; } static void init_obj_classes() { - int i, class, prev_class; + int i, class, prev_class; - prev_class = -1; - for (i = 0; i < NUM_OBJECTS; i++) { - class = objects[i].oc_class; - if (class != prev_class) { - bases[class] = i; - prev_class = class; - } - } + prev_class = -1; + for (i = 0; i < NUM_OBJECTS; i++) { + class = objects[i].oc_class; + if (class != prev_class) { + bases[class] = i; + prev_class = class; + } + } } /* @@ -1151,7 +1206,7 @@ boolean check_monster_char(c) char c; { - return (def_char_to_monclass(c) != MAXMCLASSES); + return (def_char_to_monclass(c) != MAXMCLASSES); } /* @@ -1161,7 +1216,7 @@ boolean check_object_char(c) char c; { - return (def_char_to_objclass(c) != MAXOCLASSES); + return (def_char_to_objclass(c) != MAXOCLASSES); } /* @@ -1171,32 +1226,54 @@ char what_map_char(c) char c; { - SpinCursor(3); - switch(c) { - case ' ' : return(STONE); - case '#' : return(CORR); - case '.' : return(ROOM); - case '-' : return(HWALL); - case '|' : return(VWALL); - case '+' : return(DOOR); - case 'A' : return(AIR); - case 'B' : return(CROSSWALL); /* hack: boundary location */ - case 'C' : return(CLOUD); - case 'S' : return(SDOOR); - case 'H' : return(SCORR); - case '{' : return(FOUNTAIN); - case '\\' : return(THRONE); - case 'K' : return(SINK); - case '}' : return(MOAT); - case 'P' : return(POOL); - case 'L' : return(LAVAPOOL); - case 'I' : return(ICE); - case 'W' : return(WATER); - case 'T' : return (TREE); - case 'F' : return (IRONBARS); /* Fe = iron */ - case 'x' : return(MAX_TYPE); /* "see-through" */ - } - return(INVALID_TYPE); + SpinCursor(3); + switch (c) { + case ' ': + return (STONE); + case '#': + return (CORR); + case '.': + return (ROOM); + case '-': + return (HWALL); + case '|': + return (VWALL); + case '+': + return (DOOR); + case 'A': + return (AIR); + case 'B': + return (CROSSWALL); /* hack: boundary location */ + case 'C': + return (CLOUD); + case 'S': + return (SDOOR); + case 'H': + return (SCORR); + case '{': + return (FOUNTAIN); + case '\\': + return (THRONE); + case 'K': + return (SINK); + case '}': + return (MOAT); + case 'P': + return (POOL); + case 'L': + return (LAVAPOOL); + case 'I': + return (ICE); + case 'W': + return (WATER); + case 'T': + return (TREE); + case 'F': + return (IRONBARS); /* Fe = iron */ + case 'x': + return (MAX_TYPE); /* "see-through" */ + } + return (INVALID_TYPE); } void @@ -1205,28 +1282,27 @@ sp_lev *sp; int opc; genericptr_t dat; { - long nop = sp->n_opcodes; - _opcode *tmp; + long nop = sp->n_opcodes; + _opcode *tmp; - if ((opc < 0) || (opc >= MAX_SP_OPCODES)) - lc_error("Unknown opcode '%d'", opc); + if ((opc < 0) || (opc >= MAX_SP_OPCODES)) + lc_error("Unknown opcode '%d'", opc); - tmp = (_opcode *)alloc(sizeof(_opcode)*(nop+1)); - if (sp->opcodes && nop) { - (void) memcpy(tmp, sp->opcodes, sizeof(_opcode)*nop); - free(sp->opcodes); - } else if (!tmp) - lc_error("Could not alloc opcode space"); + tmp = (_opcode *) alloc(sizeof(_opcode) * (nop + 1)); + if (sp->opcodes && nop) { + (void) memcpy(tmp, sp->opcodes, sizeof(_opcode) * nop); + free(sp->opcodes); + } else if (!tmp) + lc_error("Could not alloc opcode space"); - sp->opcodes = tmp; + sp->opcodes = tmp; - sp->opcodes[nop].opcode = opc; - sp->opcodes[nop].opdat = dat; + sp->opcodes[nop].opcode = opc; + sp->opcodes[nop].opdat = dat; - sp->n_opcodes++; + sp->n_opcodes++; } - /* * Yep! LEX gives us the map in a raw mode. * Just analyze it here. @@ -1236,82 +1312,84 @@ scan_map(map, sp) char *map; sp_lev *sp; { - register int i, len; - register char *s1, *s2; - int max_len = 0; - int max_hig = 0; - char *tmpmap[ROWNO]; - int dx,dy; - char *mbuf; + register int i, len; + register char *s1, *s2; + int max_len = 0; + int max_hig = 0; + char *tmpmap[ROWNO]; + int dx, dy; + char *mbuf; - /* First, strip out digits 0-9 (line numbering) */ - for (s1 = s2 = map; *s1; s1++) - if (*s1 < '0' || *s1 > '9') - *s2++ = *s1; - *s2 = '\0'; + /* First, strip out digits 0-9 (line numbering) */ + for (s1 = s2 = map; *s1; s1++) + if (*s1 < '0' || *s1 > '9') + *s2++ = *s1; + *s2 = '\0'; - /* Second, find the max width of the map */ - s1 = map; - while (s1 && *s1) { - s2 = index(s1, '\n'); - if (s2) { - len = (int) (s2 - s1); - s1 = s2 + 1; - } else { - len = (int) strlen(s1); - s1 = (char *) 0; - } - if (len > max_len) max_len = len; - } + /* Second, find the max width of the map */ + s1 = map; + while (s1 && *s1) { + s2 = index(s1, '\n'); + if (s2) { + len = (int) (s2 - s1); + s1 = s2 + 1; + } else { + len = (int) strlen(s1); + s1 = (char *) 0; + } + if (len > max_len) + max_len = len; + } - /* Then parse it now */ - while (map && *map) { - tmpmap[max_hig] = (char *) alloc(max_len); - s1 = index(map, '\n'); - if (s1) { - len = (int) (s1 - map); - s1++; - } else { - len = (int) strlen(map); - s1 = map + len; - } - for(i=0; i MAP_X_LIM || max_hig > MAP_Y_LIM) { - lc_error("Map too large at (%d x %d), max is (%d x %d)", max_len, max_hig, MAP_X_LIM, MAP_Y_LIM); - } + if (max_len > MAP_X_LIM || max_hig > MAP_Y_LIM) { + lc_error("Map too large at (%d x %d), max is (%d x %d)", max_len, + max_hig, MAP_X_LIM, MAP_Y_LIM); + } - mbuf = (char *) alloc(((max_hig-1) * max_len) + (max_len-1) + 2); - for (dy = 0; dy < max_hig; dy++) - for (dx = 0; dx < max_len; dx++) - mbuf[(dy * max_len) + dx] = (tmpmap[dy][dx] + 1); + mbuf = (char *) alloc(((max_hig - 1) * max_len) + (max_len - 1) + 2); + for (dy = 0; dy < max_hig; dy++) + for (dx = 0; dx < max_len; dx++) + mbuf[(dy * max_len) + dx] = (tmpmap[dy][dx] + 1); - mbuf[((max_hig-1) * max_len) + (max_len-1) + 1] = '\0'; + mbuf[((max_hig - 1) * max_len) + (max_len - 1) + 1] = '\0'; - add_opvars(sp, "siio", VA_PASS4(mbuf, max_hig, max_len, SPO_MAP)); + add_opvars(sp, "siio", VA_PASS4(mbuf, max_hig, max_len, SPO_MAP)); - for (dy = 0; dy < max_hig; dy++) - Free(tmpmap[dy]); - Free(mbuf); + for (dy = 0; dy < max_hig; dy++) + Free(tmpmap[dy]); + Free(mbuf); } - - - /* * Output some info common to all special levels. */ @@ -1319,13 +1397,13 @@ static boolean write_common_data(fd) int fd; { - static struct version_info version_data = { - VERSION_NUMBER, VERSION_FEATURES, - VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3 - }; + static struct version_info version_data = { + VERSION_NUMBER, VERSION_FEATURES, VERSION_SANITY1, VERSION_SANITY2, + VERSION_SANITY3 + }; - Write(fd, &version_data, sizeof version_data); - return TRUE; + Write(fd, &version_data, sizeof version_data); + return TRUE; } /* @@ -1337,72 +1415,74 @@ write_maze(fd, maze) int fd; sp_lev *maze; { - int i; + int i; - if (!write_common_data(fd)) - return FALSE; + if (!write_common_data(fd)) + return FALSE; - Write(fd, &(maze->n_opcodes), sizeof(maze->n_opcodes)); + Write(fd, &(maze->n_opcodes), sizeof(maze->n_opcodes)); - for (i = 0; i < maze->n_opcodes; i++) { - _opcode tmpo = maze->opcodes[i]; + for (i = 0; i < maze->n_opcodes; i++) { + _opcode tmpo = maze->opcodes[i]; - Write(fd, &(tmpo.opcode), sizeof(tmpo.opcode)); + Write(fd, &(tmpo.opcode), sizeof(tmpo.opcode)); - if (tmpo.opcode < SPO_NULL || tmpo.opcode >= MAX_SP_OPCODES) - panic("write_maze: unknown opcode (%d).", tmpo.opcode); + if (tmpo.opcode < SPO_NULL || tmpo.opcode >= MAX_SP_OPCODES) + panic("write_maze: unknown opcode (%d).", tmpo.opcode); - if (tmpo.opcode == SPO_PUSH) { - genericptr_t opdat = tmpo.opdat; - if (opdat) { - struct opvar *ov = (struct opvar *)opdat; - int size; - Write(fd, &(ov->spovartyp), sizeof(ov->spovartyp)); - switch (ov->spovartyp) { - case SPOVAR_NULL: break; - case SPOVAR_COORD: - case SPOVAR_REGION: - case SPOVAR_MAPCHAR: - case SPOVAR_MONST: - case SPOVAR_OBJ: - case SPOVAR_INT: - Write(fd, &(ov->vardata.l), sizeof(ov->vardata.l)); - break; - case SPOVAR_VARIABLE: - case SPOVAR_STRING: - if (ov->vardata.str) - size = strlen(ov->vardata.str); - else size = 0; - Write(fd, &size, sizeof(size)); - if (size) { - Write(fd, ov->vardata.str, size); - Free(ov->vardata.str); - } - break; - default: panic("write_maze: unknown data type (%d).", ov->spovartyp); - } - } else panic("write_maze: PUSH with no data."); - } else { - /* sanity check */ - genericptr_t opdat = tmpo.opdat; - if (opdat) - panic("write_maze: opcode (%d) has data.", tmpo.opcode); - } + if (tmpo.opcode == SPO_PUSH) { + genericptr_t opdat = tmpo.opdat; + if (opdat) { + struct opvar *ov = (struct opvar *) opdat; + int size; + Write(fd, &(ov->spovartyp), sizeof(ov->spovartyp)); + switch (ov->spovartyp) { + case SPOVAR_NULL: + break; + case SPOVAR_COORD: + case SPOVAR_REGION: + case SPOVAR_MAPCHAR: + case SPOVAR_MONST: + case SPOVAR_OBJ: + case SPOVAR_INT: + Write(fd, &(ov->vardata.l), sizeof(ov->vardata.l)); + break; + case SPOVAR_VARIABLE: + case SPOVAR_STRING: + if (ov->vardata.str) + size = strlen(ov->vardata.str); + else + size = 0; + Write(fd, &size, sizeof(size)); + if (size) { + Write(fd, ov->vardata.str, size); + Free(ov->vardata.str); + } + break; + default: + panic("write_maze: unknown data type (%d).", + ov->spovartyp); + } + } else + panic("write_maze: PUSH with no data."); + } else { + /* sanity check */ + genericptr_t opdat = tmpo.opdat; + if (opdat) + panic("write_maze: opcode (%d) has data.", tmpo.opcode); + } - Free(tmpo.opdat); + Free(tmpo.opdat); + } + /* clear the struct for next user */ + Free(maze->opcodes); + maze->opcodes = NULL; + /*(void) memset((genericptr_t) &maze->init_lev, 0, sizeof + * maze->init_lev);*/ - } - /* clear the struct for next user */ - Free(maze->opcodes); - maze->opcodes = NULL; - /*(void) memset((genericptr_t) &maze->init_lev, 0, sizeof maze->init_lev);*/ - - return TRUE; + return TRUE; } - - - /* * Open and write maze or rooms file, based on which pointer is non-null. * Return TRUE on success, FALSE on failure. @@ -1412,34 +1492,36 @@ write_level_file(filename, lvl) char *filename; sp_lev *lvl; { - int fout; - char lbuf[60]; + int fout; + char lbuf[60]; - lbuf[0] = '\0'; + lbuf[0] = '\0'; #ifdef PREFIX - Strcat(lbuf, PREFIX); + Strcat(lbuf, PREFIX); #endif - Strcat(lbuf, filename); - Strcat(lbuf, LEV_EXT); + Strcat(lbuf, filename); + Strcat(lbuf, LEV_EXT); #if defined(MAC) && (defined(__SC__) || defined(__MRC__)) - fout = open(lbuf, O_WRONLY|O_CREAT|O_BINARY); + fout = open(lbuf, O_WRONLY | O_CREAT | O_BINARY); #else - fout = open(lbuf, O_WRONLY|O_CREAT|O_BINARY, OMASK); + fout = open(lbuf, O_WRONLY | O_CREAT | O_BINARY, OMASK); #endif - if (fout < 0) return FALSE; + if (fout < 0) + return FALSE; - if (!lvl) panic("write_level_file"); + if (!lvl) + panic("write_level_file"); - if (be_verbose) - fprintf(stdout, "File: '%s', opcodes: %ld\n", lbuf, lvl->n_opcodes); + if (be_verbose) + fprintf(stdout, "File: '%s', opcodes: %ld\n", lbuf, lvl->n_opcodes); - if (!write_maze(fout, lvl)) - return FALSE; + if (!write_maze(fout, lvl)) + return FALSE; - (void) close(fout); + (void) close(fout); - return TRUE; + return TRUE; } static int @@ -1449,17 +1531,16 @@ const char *s2; { unsigned char u1, u2; - for ( ; ; s1++, s2++) { - u1 = tolower((unsigned char) *s1); - u2 = tolower((unsigned char) *s2); - if ((u1 == '\0') || (u1 != u2)) { - break; - } + for (;; s1++, s2++) { + u1 = tolower((unsigned char) *s1); + u2 = tolower((unsigned char) *s2); + if ((u1 == '\0') || (u1 != u2)) { + break; + } } - return u1-u2; + return u1 - u2; } - #ifdef STRICT_REF_DEF /* * Any globals declared in hack.h and descendents which aren't defined @@ -1474,54 +1555,55 @@ struct attribs attrmax, attrmin; const char *configfile; char lock[ARBITRARY_SIZE]; char SAVEF[ARBITRARY_SIZE]; -# ifdef MICRO +#ifdef MICRO char SAVEP[ARBITRARY_SIZE]; -# endif +#endif /* termcap.c */ struct tc_lcl_data tc_lcl_data; -# ifdef TEXTCOLOR -# ifdef TOS +#ifdef TEXTCOLOR +#ifdef TOS const char *hilites[CLR_MAX]; -# else +#else char NEARDATA *hilites[CLR_MAX]; -# endif -# endif +#endif +#endif /* trap.c */ const char *traps[TRAPNUM]; /* window.c */ -# ifdef HANGUPHANDLING +#ifdef HANGUPHANDLING volatile -# endif -struct window_procs windowprocs; +#endif + struct window_procs windowprocs; /* xxxtty.c */ -# ifdef DEFINE_OSPEED +#ifdef DEFINE_OSPEED short ospeed; -# endif -# ifndef STRNCMPI -char -lowc(c) /* force 'c' into lowercase */ - char c; +#endif +#ifndef STRNCMPI +char lowc(c) /* force 'c' into lowercase */ +char c; { - return((char)(('A' <= c && c <= 'Z') ? (c | 040) : c)); + return ((char) (('A' <= c && c <= 'Z') ? (c | 040) : c)); } -int -strncmpi(s1, s2, n) /* case insensitive counted string comparison */ - register const char *s1, *s2; - register int n; /*(should probably be size_t, which is usually unsigned)*/ -{ /*{ aka strncasecmp }*/ +int strncmpi(s1, s2, n) /* case insensitive counted string comparison */ +register const char *s1, *s2; +register int n; /*(should probably be size_t, which is usually unsigned)*/ +{ /*{ aka strncasecmp }*/ register char t1, t2; while (n--) { - if (!*s2) return (*s1 != 0); /* s1 >= s2 */ - else if (!*s1) return -1; /* s1 < s2 */ - t1 = lowc(*s1++); - t2 = lowc(*s2++); - if (t1 != t2) return (t1 > t2) ? 1 : -1; + if (!*s2) + return (*s1 != 0); /* s1 >= s2 */ + else if (!*s1) + return -1; /* s1 < s2 */ + t1 = lowc(*s1++); + t2 = lowc(*s2++); + if (t1 != t2) + return (t1 > t2) ? 1 : -1; } - return 0; /* s1 == s2 */ + return 0; /* s1 == s2 */ } -# endif /* STRNCMPI */ -#endif /* STRICT_REF_DEF */ +#endif /* STRNCMPI */ +#endif /* STRICT_REF_DEF */ /*lev_main.c*/ diff --git a/util/makedefs.c b/util/makedefs.c index 2a77c91f7..f8e0cacde 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -1,11 +1,11 @@ -/* NetHack 3.6 makedefs.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */ +/* NetHack 3.6 makedefs.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.93 $ */ /* NetHack 3.6 makedefs.c $Date: 2012/01/15 09:27:03 $ $Revision: 1.50 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) M. Stephenson, 1990, 1991. */ /* Copyright (c) Dean Luick, 1990. */ /* NetHack may be freely redistributed. See license for details. */ -#define MAKEDEFS_C /* use to conditionally include file sections */ +#define MAKEDEFS_C /* use to conditionally include file sections */ #include "config.h" #include "permonst.h" @@ -29,102 +29,102 @@ #include #ifdef MAC -# if defined(__SC__) || defined(__MRC__) /* MPW compilers */ -# define MPWTOOL +#if defined(__SC__) || defined(__MRC__) /* MPW compilers */ +#define MPWTOOL #include #include -# else /* MAC without MPWTOOL */ -# define MACsansMPWTOOL -# endif +#else /* MAC without MPWTOOL */ +#define MACsansMPWTOOL +#endif #endif /* MAC */ #ifndef MPWTOOL -# define SpinCursor(x) +#define SpinCursor(x) #endif -#define Fprintf (void) fprintf -#define Fclose (void) fclose -#define Unlink (void) unlink +#define Fprintf (void) fprintf +#define Fclose (void) fclose +#define Unlink (void) unlink #if !defined(AMIGA) || defined(AZTEC_C) -#define rewind(fp) fseek((fp),0L,SEEK_SET) /* guarantee a return value */ +#define rewind(fp) fseek((fp), 0L, SEEK_SET) /* guarantee a return value */ #endif #if defined(UNIX) && !defined(LINT) && !defined(GCC_WARN) -static const char SCCS_Id[] = "@(#)makedefs.c\t3.5\t2004/02/01"; +static const char SCCS_Id[] = "@(#)makedefs.c\t3.5\t2004/02/01"; #endif - /* names of files to be generated */ -#define DATE_FILE "date.h" -#define MONST_FILE "pm.h" -#define ONAME_FILE "onames.h" +/* names of files to be generated */ +#define DATE_FILE "date.h" +#define MONST_FILE "pm.h" +#define ONAME_FILE "onames.h" #ifndef OPTIONS_FILE -#define OPTIONS_FILE "options" +#define OPTIONS_FILE "options" #endif -#define ORACLE_FILE "oracles" -#define DATA_FILE "data" -#define RUMOR_FILE "rumors" -#define DGN_I_FILE "dungeon.def" -#define DGN_O_FILE "dungeon.pdf" -#define MON_STR_C "monstr.c" -#define QTXT_I_FILE "quest.txt" -#define QTXT_O_FILE "quest.dat" -#define VIS_TAB_H "vis_tab.h" -#define VIS_TAB_C "vis_tab.c" - /* locations for those files */ +#define ORACLE_FILE "oracles" +#define DATA_FILE "data" +#define RUMOR_FILE "rumors" +#define DGN_I_FILE "dungeon.def" +#define DGN_O_FILE "dungeon.pdf" +#define MON_STR_C "monstr.c" +#define QTXT_I_FILE "quest.txt" +#define QTXT_O_FILE "quest.dat" +#define VIS_TAB_H "vis_tab.h" +#define VIS_TAB_C "vis_tab.c" +/* locations for those files */ #ifdef AMIGA -# define FILE_PREFIX -# define INCLUDE_TEMPLATE "NH:include/t.%s" -# define SOURCE_TEMPLATE "NH:src/%s" -# define DGN_TEMPLATE "NH:dat/%s" /* where dungeon.pdf file goes */ -# define DATA_TEMPLATE "NH:slib/%s" -# define DATA_IN_TEMPLATE "NH:dat/%s" +#define FILE_PREFIX +#define INCLUDE_TEMPLATE "NH:include/t.%s" +#define SOURCE_TEMPLATE "NH:src/%s" +#define DGN_TEMPLATE "NH:dat/%s" /* where dungeon.pdf file goes */ +#define DATA_TEMPLATE "NH:slib/%s" +#define DATA_IN_TEMPLATE "NH:dat/%s" #else /* not AMIGA */ -# if defined(MAC) && !defined(__MACH__) - /* MacOS 9 or earlier */ -# define INCLUDE_TEMPLATE ":include:%s" -# define SOURCE_TEMPLATE ":src:%s" -# define DGN_TEMPLATE ":dat:%s" /* where dungeon.pdf file goes */ -# if __SC__ || __MRC__ -# define DATA_TEMPLATE ":Dungeon:%s" -# else -# define DATA_TEMPLATE ":lib:%s" -# endif /* __SC__ || __MRC__ */ -# define DATA_IN_TEMPLATE ":dat:%s" -# else /* neither AMIGA nor MAC */ -# ifdef OS2 -# define INCLUDE_TEMPLATE "..\\include\\%s" -# define SOURCE_TEMPLATE "..\\src\\%s" -# define DGN_TEMPLATE "..\\dat\\%s" /* where dungeon.pdf file goes */ -# define DATA_TEMPLATE "..\\dat\\%s" -# define DATA_IN_TEMPLATE "..\\dat\\%s" -# else /* not AMIGA, MAC, or OS2 */ -# define INCLUDE_TEMPLATE "../include/%s" -# define SOURCE_TEMPLATE "../src/%s" -# define DGN_TEMPLATE "../dat/%s" /* where dungeon.pdf file goes */ -# define DATA_TEMPLATE "../dat/%s" -# define DATA_IN_TEMPLATE "../dat/%s" -# endif /* else !OS2 */ -# endif /* else !MAC */ -#endif /* else !AMIGA */ +#if defined(MAC) && !defined(__MACH__) +/* MacOS 9 or earlier */ +#define INCLUDE_TEMPLATE ":include:%s" +#define SOURCE_TEMPLATE ":src:%s" +#define DGN_TEMPLATE ":dat:%s" /* where dungeon.pdf file goes */ +#if __SC__ || __MRC__ +#define DATA_TEMPLATE ":Dungeon:%s" +#else +#define DATA_TEMPLATE ":lib:%s" +#endif /* __SC__ || __MRC__ */ +#define DATA_IN_TEMPLATE ":dat:%s" +#else /* neither AMIGA nor MAC */ +#ifdef OS2 +#define INCLUDE_TEMPLATE "..\\include\\%s" +#define SOURCE_TEMPLATE "..\\src\\%s" +#define DGN_TEMPLATE "..\\dat\\%s" /* where dungeon.pdf file goes */ +#define DATA_TEMPLATE "..\\dat\\%s" +#define DATA_IN_TEMPLATE "..\\dat\\%s" +#else /* not AMIGA, MAC, or OS2 */ +#define INCLUDE_TEMPLATE "../include/%s" +#define SOURCE_TEMPLATE "../src/%s" +#define DGN_TEMPLATE "../dat/%s" /* where dungeon.pdf file goes */ +#define DATA_TEMPLATE "../dat/%s" +#define DATA_IN_TEMPLATE "../dat/%s" +#endif /* else !OS2 */ +#endif /* else !MAC */ +#endif /* else !AMIGA */ static const char *Dont_Edit_Code = - "/* This source file is generated by 'makedefs'. Do not edit. */\n", + "/* This source file is generated by 'makedefs'. Do not edit. */\n", *Dont_Edit_Data = - "#\tThis data file is generated by 'makedefs'. Do not edit. \n"; + "#\tThis data file is generated by 'makedefs'. Do not edit. \n"; static struct version_info version; /* definitions used for vision tables */ -#define TEST_WIDTH COLNO +#define TEST_WIDTH COLNO #define TEST_HEIGHT ROWNO #define BLOCK_WIDTH (TEST_WIDTH + 10) -#define BLOCK_HEIGHT TEST_HEIGHT /* don't need extra spaces */ +#define BLOCK_HEIGHT TEST_HEIGHT /* don't need extra spaces */ #define MAX_ROW (BLOCK_HEIGHT + TEST_HEIGHT) #define MAX_COL (BLOCK_WIDTH + TEST_WIDTH) /* Use this as an out-of-bound value in the close table. */ -#define CLOSE_OFF_TABLE_STRING "99" /* for the close table */ -#define FAR_OFF_TABLE_STRING "0xff" /* for the far table */ +#define CLOSE_OFF_TABLE_STRING "99" /* for the close table */ +#define FAR_OFF_TABLE_STRING "0xff" /* for the far table */ #define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0)) #ifdef VISION_TABLES @@ -132,19 +132,19 @@ static char xclear[MAX_ROW][MAX_COL]; #endif /*-end of vision defs-*/ -static char in_line[256], filename[600]; +static char in_line[256], filename[600]; #ifdef FILE_PREFIX - /* if defined, a first argument not starting with - is - * taken as a text string to be prepended to any - * output filename generated */ -char *file_prefix=""; +/* if defined, a first argument not starting with - is + * taken as a text string to be prepended to any + * output filename generated */ +char *file_prefix = ""; #endif #ifdef MACsansMPWTOOL int FDECL(main, (void)); #else -int FDECL(main, (int,char **)); +int FDECL(main, (int, char **)); #endif void FDECL(do_makedefs, (char *)); void NDECL(do_objs); @@ -159,32 +159,32 @@ void NDECL(do_rumors); void NDECL(do_oracles); void NDECL(do_vision); -extern void NDECL(monst_init); /* monst.c */ -extern void NDECL(objects_init); /* objects.c */ +extern void NDECL(monst_init); /* monst.c */ +extern void NDECL(objects_init); /* objects.c */ static void NDECL(make_version); static char *FDECL(version_string, (char *, const char *)); -static char *FDECL(version_id_string, (char *,const char *)); -static char *FDECL(bannerc_string, (char *,const char *)); +static char *FDECL(version_id_string, (char *, const char *)); +static char *FDECL(bannerc_string, (char *, const char *)); static char *FDECL(xcrypt, (const char *)); static unsigned long FDECL(read_rumors_file, - (const char *,int *,long *,unsigned long)); + (const char *, int *, long *, unsigned long)); static void FDECL(do_rnd_access_file, (const char *)); static boolean FDECL(d_filter, (char *)); static boolean FDECL(h_filter, (char *)); -static boolean FDECL(ranged_attk,(struct permonst*)); -static int FDECL(mstrength,(struct permonst *)); +static boolean FDECL(ranged_attk, (struct permonst *)); +static int FDECL(mstrength, (struct permonst *)); static void NDECL(build_savebones_compat_string); -static void FDECL(do_ext_makedefs,(int , char **)); +static void FDECL(do_ext_makedefs, (int, char **)); static void NDECL(windowing_sanity); static boolean FDECL(qt_comment, (char *)); static boolean FDECL(qt_control, (char *)); static int FDECL(get_hdr, (char *)); static boolean FDECL(new_id, (char *)); -static boolean FDECL(known_msg, (int,int)); -static void FDECL(new_msg, (char *,int,int)); -static char *FDECL(valid_qt_summary, (char *,BOOLEAN_P)); +static boolean FDECL(known_msg, (int, int)); +static void FDECL(new_msg, (char *, int, int)); +static char *FDECL(valid_qt_summary, (char *, BOOLEAN_P)); static void FDECL(do_qt_control, (char *)); static void FDECL(do_qt_text, (char *)); static void NDECL(adjust_qt_hdrs); @@ -195,11 +195,11 @@ static void NDECL(H_close_gen); static void NDECL(H_far_gen); static void NDECL(C_close_gen); static void NDECL(C_far_gen); -static int FDECL(clear_path, (int,int,int,int)); +static int FDECL(clear_path, (int, int, int, int)); #endif static char *FDECL(tmpdup, (const char *)); -static char *FDECL(limit, (char *,int)); +static char *FDECL(limit, (char *, int)); static char *FDECL(eos, (char *)); /* input, output, tmp */ @@ -209,7 +209,6 @@ static FILE *ifp, *ofp, *tfp; extern unsigned _stklen = STKSIZ; #endif - #ifdef MACsansMPWTOOL int main(void) @@ -223,17 +222,17 @@ main(void) fgets(buf, 100, stdin); len = strlen(buf); if (len <= 1) - Strcpy(buf, def_options); + Strcpy(buf, def_options); else - buf[len-1] = 0; /* remove return */ + buf[len - 1] = 0; /* remove return */ - if(buf[0]=='-' && buf[1]=='-'){ + if (buf[0] == '-' && buf[1] == '-') { #if 0 split up buf into words do_ext_makedefs(fakeargc, fakeargv); #else - printf("extended makedefs not implemented for Mac OS9\n"); - exit(EXIT_FAILURE); + printf("extended makedefs not implemented for Mac OS9\n"); + exit(EXIT_FAILURE); #endif } @@ -246,146 +245,157 @@ main(void) int main(argc, argv) -int argc; -char *argv[]; +int argc; +char *argv[]; { - if ( (argc != 2) + if ((argc != 2) #ifdef FILE_PREFIX - && (argc != 3) + && (argc != 3) #endif - && !(argv[1][0]=='-' && argv[1][1]=='-') - ) { - Fprintf(stderr, "Bad arg count (%d).\n", argc-1); - (void) fflush(stderr); - return 1; - } + && !(argv[1][0] == '-' && argv[1][1] == '-')) { + Fprintf(stderr, "Bad arg count (%d).\n", argc - 1); + (void) fflush(stderr); + return 1; + } #ifdef FILE_PREFIX - if(argc >=2 && argv[1][0]!='-'){ - file_prefix=argv[1]; - argc--;argv++; - } + if (argc >= 2 && argv[1][0] != '-') { + file_prefix = argv[1]; + argc--; + argv++; + } #endif - if(argv[1][0]=='-' && argv[1][1]=='-'){ - do_ext_makedefs(argc, argv); - } else { - do_makedefs(&argv[1][1]); - } - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + if (argv[1][0] == '-' && argv[1][1] == '-') { + do_ext_makedefs(argc, argv); + } else { + do_makedefs(&argv[1][1]); + } + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } #endif static void -link_sanity_check(){ - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_init(); - objects_init(); +link_sanity_check() +{ + /* Note: these initializers don't do anything except guarantee that + we're linked properly. + */ + monst_init(); + objects_init(); } void do_makedefs(options) -char *options; +char *options; { - boolean more_than_one; + boolean more_than_one; - link_sanity_check(); + link_sanity_check(); - /* construct the current version number */ - make_version(); + /* construct the current version number */ + make_version(); - more_than_one = strlen(options) > 1; - while (*options) { - if (more_than_one) - Fprintf(stderr, "makedefs -%c\n", *options); + more_than_one = strlen(options) > 1; + while (*options) { + if (more_than_one) + Fprintf(stderr, "makedefs -%c\n", *options); - switch (*options) { - case 'o': - case 'O': do_objs(); - break; - case 'd': - case 'D': do_data(); - break; - case 'e': - case 'E': do_dungeon(); - break; - case 'm': - case 'M': do_monstr(); - break; - case 'v': - case 'V': do_date(); - do_options(); - break; - case 'p': - case 'P': do_permonst(); - break; - case 'q': - case 'Q': do_questtxt(); - break; - case 'r': - case 'R': do_rumors(); - break; - case 's': - case 'S': do_rnd_access_file(EPITAPHFILE); - do_rnd_access_file(ENGRAVEFILE); - do_rnd_access_file(BOGUSMONFILE); - break; - case 'h': - case 'H': do_oracles(); - break; - case 'z': - case 'Z': do_vision(); - break; - - default: Fprintf(stderr, "Unknown option '%c'.\n", - *options); - (void) fflush(stderr); - exit(EXIT_FAILURE); - - } - options++; - } - if (more_than_one) Fprintf(stderr, "Completed.\n"); /* feedback */ + switch (*options) { + case 'o': + case 'O': + do_objs(); + break; + case 'd': + case 'D': + do_data(); + break; + case 'e': + case 'E': + do_dungeon(); + break; + case 'm': + case 'M': + do_monstr(); + break; + case 'v': + case 'V': + do_date(); + do_options(); + break; + case 'p': + case 'P': + do_permonst(); + break; + case 'q': + case 'Q': + do_questtxt(); + break; + case 'r': + case 'R': + do_rumors(); + break; + case 's': + case 'S': + do_rnd_access_file(EPITAPHFILE); + do_rnd_access_file(ENGRAVEFILE); + do_rnd_access_file(BOGUSMONFILE); + break; + case 'h': + case 'H': + do_oracles(); + break; + case 'z': + case 'Z': + do_vision(); + break; + default: + Fprintf(stderr, "Unknown option '%c'.\n", *options); + (void) fflush(stderr); + exit(EXIT_FAILURE); + } + options++; + } + if (more_than_one) + Fprintf(stderr, "Completed.\n"); /* feedback */ } static char namebuf[1000]; static char * name_file(template, tag) - char *template; - char *tag; +char *template; +char *tag; { - Sprintf(namebuf, template, tag); - return namebuf; + Sprintf(namebuf, template, tag); + return namebuf; } static void delete_file(template, tag) - char *template; - char *tag; +char *template; +char *tag; { - char *name = name_file(template, tag); - Unlink(name); + char *name = name_file(template, tag); + Unlink(name); } static FILE * getfp(template, tag, mode) - char *template; - char *tag; - char *mode; +char *template; +char *tag; +char *mode; { - char *name = name_file(template, tag); - FILE *rv = fopen(name, mode); - if(!rv){ - Fprintf(stderr, "Can't open '%s'.\n", name); - exit(EXIT_FAILURE); - } - return rv; + char *name = name_file(template, tag); + FILE *rv = fopen(name, mode); + if (!rv) { + Fprintf(stderr, "Can't open '%s'.\n", name); + exit(EXIT_FAILURE); + } + return rv; } static boolean debug = FALSE; @@ -394,8 +404,8 @@ static FILE *inputfp; static FILE *outputfp; struct grep_var { - const char *name; - int is_defined; /* 0 undef; 1 defined */ + const char *name; + int is_defined; /* 0 undef; 1 defined */ }; /* struct grep_var grep_vars[] and TODO_* constants in include file: */ #include "mdgrep.h" @@ -406,133 +416,154 @@ static struct grep_var *FDECL(grepsearch, (char *)); static int grep_trace = 0; static void -do_ext_makedefs(int argc, char **argv){ - int todo = 0; +do_ext_makedefs(int argc, char **argv) +{ + int todo = 0; - link_sanity_check(); + link_sanity_check(); - argc--; argv++; /* skip program name */ + argc--; + argv++; /* skip program name */ - while(argc){ - if(argv[0][0] != '-') break; - if(argv[0][1] != '-'){ - Fprintf(stderr, "Can't mix - and -- options.\n"); - exit(EXIT_FAILURE); - } -#define IS_OPTION(str) if(!strcmp(&argv[0][2], str)) -#define CONTINUE argv++, argc--; continue -#define CONSUME \ - argv++, argc--; \ - if(argc==0){Fprintf(stderr, "missing option\n"); exit(EXIT_FAILURE);} - IS_OPTION("svs"){ - /* short version string for packaging - note - * no \n */ - char buf[100]; - char delim[10]; - argv++; /* not CONSUME */ - delim[0] = '\0'; - if(argv[0]) strcpy(delim, argv[0]); - Fprintf(stdout, "%s", version_string(buf, delim)); - exit(EXIT_SUCCESS); - } - IS_OPTION("debug"){ - debug = TRUE; - CONTINUE; - } - IS_OPTION("make"){ - CONSUME; - do_makedefs(argv[0]); - exit(EXIT_SUCCESS); - } - IS_OPTION("input"){ - CONSUME; - if(!strcmp(argv[0], "-")){ - inputfp = stdin; - } else { - inputfp = fopen(argv[0], RDTMODE); - if(!inputfp){ - Fprintf(stderr, "Can't open '%s'.\n", argv[0]); - exit(EXIT_FAILURE); - } - } - CONTINUE; - } - IS_OPTION("output"){ - CONSUME; - if(!strcmp(argv[0], "-")){ - outputfp = stdout; - } else { - outputfp = fopen(argv[0], WRTMODE); - if(!outputfp){ - Fprintf(stderr, "Can't open '%s'.\n", argv[0]); - exit(EXIT_FAILURE); - } - } - CONTINUE; - } - IS_OPTION("grep"){ - if(todo){ - Fprintf(stderr, "Can't do grep and something else.\n"); - exit(EXIT_FAILURE); - } - todo = TODO_GREP; - CONTINUE; - } - IS_OPTION("grep-showvars"){ - do_grep_showvars(); - exit(EXIT_SUCCESS); - } - IS_OPTION("grep-trace"){ - grep_trace = 1; - CONTINUE; - } - IS_OPTION("grep-define"){ - struct grep_var *p; - CONSUME; - p = grepsearch(argv[0]); - if(p){ - p->is_defined = 1; - } else { - Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]); - exit(EXIT_FAILURE); - } - CONTINUE; - } - IS_OPTION("grep-undef"){ - struct grep_var *p; - CONSUME; - p = grepsearch(argv[0]); - if(p){ - p->is_defined = 0; - } else { - Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]); - exit(EXIT_FAILURE); - } - CONTINUE; - } + while (argc) { + if (argv[0][0] != '-') + break; + if (argv[0][1] != '-') { + Fprintf(stderr, "Can't mix - and -- options.\n"); + exit(EXIT_FAILURE); + } +#define IS_OPTION(str) if (!strcmp(&argv[0][2], str)) +#define CONTINUE \ + argv++, argc--; \ + continue +#define CONSUME \ + argv++, argc--; \ + if (argc == 0) { \ + Fprintf(stderr, "missing option\n"); \ + exit(EXIT_FAILURE); \ + } + IS_OPTION("svs") + { + /* short version string for packaging - note + * no \n */ + char buf[100]; + char delim[10]; + argv++; /* not CONSUME */ + delim[0] = '\0'; + if (argv[0]) + strcpy(delim, argv[0]); + Fprintf(stdout, "%s", version_string(buf, delim)); + exit(EXIT_SUCCESS); + } + IS_OPTION("debug") + { + debug = TRUE; + CONTINUE; + } + IS_OPTION("make") + { + CONSUME; + do_makedefs(argv[0]); + exit(EXIT_SUCCESS); + } + IS_OPTION("input") + { + CONSUME; + if (!strcmp(argv[0], "-")) { + inputfp = stdin; + } else { + inputfp = fopen(argv[0], RDTMODE); + if (!inputfp) { + Fprintf(stderr, "Can't open '%s'.\n", argv[0]); + exit(EXIT_FAILURE); + } + } + CONTINUE; + } + IS_OPTION("output") + { + CONSUME; + if (!strcmp(argv[0], "-")) { + outputfp = stdout; + } else { + outputfp = fopen(argv[0], WRTMODE); + if (!outputfp) { + Fprintf(stderr, "Can't open '%s'.\n", argv[0]); + exit(EXIT_FAILURE); + } + } + CONTINUE; + } + IS_OPTION("grep") + { + if (todo) { + Fprintf(stderr, "Can't do grep and something else.\n"); + exit(EXIT_FAILURE); + } + todo = TODO_GREP; + CONTINUE; + } + IS_OPTION("grep-showvars") + { + do_grep_showvars(); + exit(EXIT_SUCCESS); + } + IS_OPTION("grep-trace") + { + grep_trace = 1; + CONTINUE; + } + IS_OPTION("grep-define") + { + struct grep_var *p; + CONSUME; + p = grepsearch(argv[0]); + if (p) { + p->is_defined = 1; + } else { + Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]); + exit(EXIT_FAILURE); + } + CONTINUE; + } + IS_OPTION("grep-undef") + { + struct grep_var *p; + CONSUME; + p = grepsearch(argv[0]); + if (p) { + p->is_defined = 0; + } else { + Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]); + exit(EXIT_FAILURE); + } + CONTINUE; + } #ifdef notyet - IS_OPTION("help"){ - } + IS_OPTION("help") + { + } #endif #undef IS_OPTION - Fprintf(stderr, "Unknown option '%s'.\n", argv[0]); - exit(EXIT_FAILURE); - } - if(argc){ - Fprintf(stderr, "unexpected argument '%s'.\n", argv[0]); - exit(EXIT_FAILURE); - } + Fprintf(stderr, "Unknown option '%s'.\n", argv[0]); + exit(EXIT_FAILURE); + } + if (argc) { + Fprintf(stderr, "unexpected argument '%s'.\n", argv[0]); + exit(EXIT_FAILURE); + } - switch(todo){ - default: - Fprintf(stderr, "Confused about what to do?\n"); - exit(EXIT_FAILURE); - case 0: - Fprintf(stderr, "Nothing to do?\n"); - exit(EXIT_FAILURE); - case TODO_GREP: - do_grep(); break; - } + switch (todo) { + default: + Fprintf(stderr, "Confused about what to do?\n"); + exit(EXIT_FAILURE); + case 0: + Fprintf(stderr, "Nothing to do?\n"); + exit(EXIT_FAILURE); + case TODO_GREP: + do_grep(); + break; + } } /* @@ -551,7 +582,8 @@ do_ext_makedefs(int argc, char **argv){ processing to continue past the unknown identifier (note that "#undef" is different than unknown). - Any line starting with a caret is a control line; as in C, zero or more spaces + Any line starting with a caret is a control line; as in C, zero or more + spaces may be embedded in the line almost anywhere; the caret MUST be in column 1. (XXX for the moment, no white space is allowed after the caret because existing lines in the docs look like that) @@ -564,264 +596,268 @@ do_ext_makedefs(int argc, char **argv){ ^: else ^. endif -*/ +*/ #define GREP_MAGIC '^' #define GREP_STACK_SIZE 100 #ifdef notyet -static int grep_rewrite = 0; /* need to (possibly) rewrite lines */ +static int grep_rewrite = 0; /* need to (possibly) rewrite lines */ #endif -static int grep_writing = 1; /* need to copy lines to output */ +static int grep_writing = 1; /* need to copy lines to output */ static int grep_errors = 0; static int grep_sp = 0; -#define ST_LD(old,opp) (!!(old) | (!!(opp)<<1)) -#define ST_OLD(v) ((v) & 1) -#define ST_OPP(v) !!((v) & 2) +#define ST_LD(old, opp) (!!(old) | (!!(opp) << 1)) +#define ST_OLD(v) ((v) &1) +#define ST_OPP(v) !!((v) &2) #define ST_ELSE 4 -static int grep_stack[GREP_STACK_SIZE] = {ST_LD(1,0)}; +static int grep_stack[GREP_STACK_SIZE] = { ST_LD(1, 0) }; static int grep_lineno = 0; static void -do_grep_showvars(){ - int x; - for(x=0;xis_defined, id); - } - return rv->is_defined; - } + struct grep_var *rv; + while (*id && isspace(*id)) + id++; + if (!*id) { + Fprintf(stderr, "missing identifier in line %d", grep_lineno); + grep_errors++; + return 0; + } + rv = grepsearch(id); + if (rv) { + if (grep_trace) { + Fprintf(outputfp, "ID %d %s\n", rv->is_defined, id); + } + return rv->is_defined; + } - if(grep_trace){ - Fprintf(outputfp, "ID U %s\n", id); - } - Fprintf(stderr, "unknown identifier '%s' in line %d.\n", id, - grep_lineno); - grep_errors++; - return 2; /* So new features can be checked before makedefs - * is rebuilt. */ + if (grep_trace) { + Fprintf(outputfp, "ID U %s\n", id); + } + Fprintf(stderr, "unknown identifier '%s' in line %d.\n", id, grep_lineno); + grep_errors++; + return 2; /* So new features can be checked before makedefs + * is rebuilt. */ } static void grep_show_wstack(tag) - char *tag; +char *tag; { - int x; + int x; - if(!grep_trace) return; + if (!grep_trace) + return; - Fprintf(outputfp, "%s w=%d sp=%d\t",tag,grep_writing, grep_sp); - for(x=grep_sp; x>=0 && x>grep_sp-6;x--){ - Fprintf(outputfp, "[%d]=%d ", x, grep_stack[x]); - } - Fprintf(outputfp, "\n"); + Fprintf(outputfp, "%s w=%d sp=%d\t", tag, grep_writing, grep_sp); + for (x = grep_sp; x >= 0 && x > grep_sp - 6; x--) { + Fprintf(outputfp, "[%d]=%d ", x, grep_stack[x]); + } + Fprintf(outputfp, "\n"); } static char * do_grep_control(buf) - char *buf; +char *buf; { - int isif = 1; - char *buf0 = buf; + int isif = 1; + char *buf0 = buf; #if 1 - if(isspace(buf[0])) return &buf[-1]; /* XXX see docs above */ + if (isspace(buf[0])) + return &buf[-1]; /* XXX see docs above */ #else - while(buf[0] && isspace(buf[0])) buf++; + while (buf[0] && isspace(buf[0])) + buf++; #endif - switch(buf[0]){ - case '#': /* comment */ - break; - case '.': /* end of if level */ - if(grep_sp==0){ - Fprintf(stderr, "unmatched ^. (endif) at line %d.\n", - grep_lineno); - grep_errors++; - } else { - grep_writing = ST_OLD(grep_stack[grep_sp--]); - grep_show_wstack("pop"); - } - break; - case '!': /* if not ID */ - isif = 0; - /* FALLTHROUGH */ - case '?': /* if ID */ - if(grep_sp == GREP_STACK_SIZE-2){ - Fprintf(stderr, "stack overflow at line %d.", - grep_lineno); - exit(EXIT_FAILURE); - } - if(grep_writing){ - isif = grep_check_id(&buf[1])?isif:!isif; - grep_stack[++grep_sp] = ST_LD(grep_writing, !isif); - grep_writing = isif; - } else { - grep_stack[++grep_sp] = ST_LD(0, 0); - /* grep_writing = 0; */ - } - grep_show_wstack("push"); - break; - case ':': /* else */ - if(ST_ELSE & grep_stack[grep_sp]){ - Fprintf(stderr, -"multiple : for same conditional at line %d.\n", grep_lineno); - grep_errors++; - } - grep_writing = ST_OPP(grep_stack[grep_sp]); - grep_stack[grep_sp] |= ST_ELSE; - break; + switch (buf[0]) { + case '#': /* comment */ + break; + case '.': /* end of if level */ + if (grep_sp == 0) { + Fprintf(stderr, "unmatched ^. (endif) at line %d.\n", + grep_lineno); + grep_errors++; + } else { + grep_writing = ST_OLD(grep_stack[grep_sp--]); + grep_show_wstack("pop"); + } + break; + case '!': /* if not ID */ + isif = 0; + /* FALLTHROUGH */ + case '?': /* if ID */ + if (grep_sp == GREP_STACK_SIZE - 2) { + Fprintf(stderr, "stack overflow at line %d.", grep_lineno); + exit(EXIT_FAILURE); + } + if (grep_writing) { + isif = grep_check_id(&buf[1]) ? isif : !isif; + grep_stack[++grep_sp] = ST_LD(grep_writing, !isif); + grep_writing = isif; + } else { + grep_stack[++grep_sp] = ST_LD(0, 0); + /* grep_writing = 0; */ + } + grep_show_wstack("push"); + break; + case ':': /* else */ + if (ST_ELSE & grep_stack[grep_sp]) { + Fprintf(stderr, "multiple : for same conditional at line %d.\n", + grep_lineno); + grep_errors++; + } + grep_writing = ST_OPP(grep_stack[grep_sp]); + grep_stack[grep_sp] |= ST_ELSE; + break; #if defined(notyet) - case '(': /* start of expression */ + case '(': /* start of expression */ #endif - case GREP_MAGIC: /* ^^ -> ^ */ - return buf0; - default: - { - char str[10]; - if(isprint(buf[0])){ - str[0] = buf[0]; str[1] = '\0'; - } else { - sprintf(str, "0x%02x", buf[0]); - } - Fprintf(stderr, "unknown control ^%s at line %d.\n", - str, grep_lineno); - grep_errors++; - } - break; - } - return NULL; + case GREP_MAGIC: /* ^^ -> ^ */ + return buf0; + default: { + char str[10]; + if (isprint(buf[0])) { + str[0] = buf[0]; + str[1] = '\0'; + } else { + sprintf(str, "0x%02x", buf[0]); + } + Fprintf(stderr, "unknown control ^%s at line %d.\n", str, + grep_lineno); + grep_errors++; + } break; + } + return NULL; } #ifdef notyet static void do_grep_rewrite(buf) - char *buf; +char *buf; { - /* no language features use this yet */ - return; + /* no language features use this yet */ + return; } #endif static void grep0(FILE *, FILE *); static void -do_grep(){ - if(!inputfp){ - Fprintf(stderr,"--grep requires --input\n"); - } - if(!outputfp){ - Fprintf(stderr,"--grep requires --output\n"); - } - if(!inputfp || !outputfp){ - exit(EXIT_FAILURE); - } +do_grep() +{ + if (!inputfp) { + Fprintf(stderr, "--grep requires --input\n"); + } + if (!outputfp) { + Fprintf(stderr, "--grep requires --output\n"); + } + if (!inputfp || !outputfp) { + exit(EXIT_FAILURE); + } - grep0(inputfp, outputfp); + grep0(inputfp, outputfp); } static void grep0(inputfp0, outputfp0) - FILE *inputfp0; - FILE *outputfp0; +FILE *inputfp0; +FILE *outputfp0; { - char buf[16384]; /* looong, just in case */ + char buf[16384]; /* looong, just in case */ - while(!feof(inputfp0) && !ferror(inputfp0)){ - char *tmp; - char *buf1; + while (!feof(inputfp0) && !ferror(inputfp0)) { + char *tmp; + char *buf1; - if(fgets(buf, sizeof(buf), inputfp0) == 0) break; - if( (tmp=strchr(buf,'\n')) ) *tmp = '\0'; - grep_lineno++; - if(grep_trace){ - Fprintf(outputfp0, "%04d %c >%s\n", - grep_lineno, - grep_writing?' ':'#', - buf - ); - } + if (fgets(buf, sizeof(buf), inputfp0) == 0) + break; + if ((tmp = strchr(buf, '\n'))) + *tmp = '\0'; + grep_lineno++; + if (grep_trace) { + Fprintf(outputfp0, "%04d %c >%s\n", grep_lineno, + grep_writing ? ' ' : '#', buf); + } - if(buf[0] == GREP_MAGIC){ - buf1 = do_grep_control(&buf[1]); - if(!buf1) continue; - } else { - buf1 = buf; - } + if (buf[0] == GREP_MAGIC) { + buf1 = do_grep_control(&buf[1]); + if (!buf1) + continue; + } else { + buf1 = buf; + } #ifdef notyet - if(grep_rewrite) - do_grep_rewrite(buf1); + if (grep_rewrite) + do_grep_rewrite(buf1); #endif - if(grep_writing) - Fprintf(outputfp0, "%s\n", buf1); - } - if(ferror(inputfp0)){ - Fprintf(stderr, "read error!\n"); - exit(EXIT_FAILURE); - } - if(ferror(outputfp0)){ - Fprintf(stderr, "write error!\n"); - exit(EXIT_FAILURE); - } - fclose(inputfp0); - fclose(outputfp0); - if(grep_sp){ - Fprintf(stderr, "%d unterminated conditional level%s\n", - grep_sp, grep_sp==1?"":"s"); - grep_errors++; - } - if(grep_errors){ - Fprintf(stderr, "%d error%s detected.\n", grep_errors, - grep_errors==1?"":"s"); - exit(EXIT_FAILURE); - } + if (grep_writing) + Fprintf(outputfp0, "%s\n", buf1); + } + if (ferror(inputfp0)) { + Fprintf(stderr, "read error!\n"); + exit(EXIT_FAILURE); + } + if (ferror(outputfp0)) { + Fprintf(stderr, "write error!\n"); + exit(EXIT_FAILURE); + } + fclose(inputfp0); + fclose(outputfp0); + if (grep_sp) { + Fprintf(stderr, "%d unterminated conditional level%s\n", grep_sp, + grep_sp == 1 ? "" : "s"); + grep_errors++; + } + if (grep_errors) { + Fprintf(stderr, "%d error%s detected.\n", grep_errors, + grep_errors == 1 ? "" : "s"); + exit(EXIT_FAILURE); + } } - /* trivial text encryption routine which can't be broken with `tr' */ -static -char *xcrypt(str) +static char * +xcrypt(str) const char *str; -{ /* duplicated in src/hacklib.c */ - static char buf[BUFSZ]; - register const char *p; - register char *q; - register int bitmask; +{ /* duplicated in src/hacklib.c */ + static char buf[BUFSZ]; + register const char *p; + register char *q; + register int bitmask; - for (bitmask = 1, p = str, q = buf; *p; q++) { - *q = *p++; - if (*q & (32|64)) *q ^= bitmask; - if ((bitmask <<= 1) >= 32) bitmask = 1; - } - *q = '\0'; - return buf; + for (bitmask = 1, p = str, q = buf; *p; q++) { + *q = *p++; + if (*q & (32 | 64)) + *q ^= bitmask; + if ((bitmask <<= 1) >= 32) + bitmask = 1; + } + *q = '\0'; + return buf; } #define PAD_RUMORS_TO 60 @@ -839,44 +875,43 @@ unsigned long old_rumor_offset; Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE); Strcat(infile, file_ext); if (!(ifp = fopen(infile, RDTMODE))) { - perror(infile); - return 0L; + perror(infile); + return 0L; } /* copy the rumors */ while (fgets(in_line, sizeof in_line, ifp) != 0) { #ifdef PAD_RUMORS_TO - int len = strlen(in_line); - if(len <= PAD_RUMORS_TO){ /* XXX enforce min len? */ - char *base = index(in_line, '\n'); - while(len++tm_mday, tm->tm_mon+1, tm->tm_year+1900); - } + { + struct tm *tm = localtime((time_t *) &clocktim); + Fprintf(ofp, "#define AMIGA_VERSION_STRING "); + Fprintf(ofp, "\"\\0$VER: NetHack %d.%d.%d (%d.%d.%d)\"\n", + VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, tm->tm_mday, + tm->tm_mon + 1, tm->tm_year + 1900); + } #endif - Fclose(ofp); - return; + Fclose(ofp); + return; } static char save_bones_compat_buf[BUFSZ]; @@ -1233,309 +1275,314 @@ static void build_savebones_compat_string() { #ifdef VERSION_COMPATIBILITY - unsigned long uver = VERSION_COMPATIBILITY; + unsigned long uver = VERSION_COMPATIBILITY; #endif - Strcpy(save_bones_compat_buf, - "save and bones files accepted from version"); + Strcpy(save_bones_compat_buf, + "save and bones files accepted from version"); #ifdef VERSION_COMPATIBILITY - Sprintf(eos(save_bones_compat_buf), "s %lu.%lu.%lu through %d.%d.%d", - ((uver & 0xFF000000L) >> 24), ((uver & 0x00FF0000L) >> 16), - ((uver & 0x0000FF00L) >> 8), - VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); + Sprintf(eos(save_bones_compat_buf), "s %lu.%lu.%lu through %d.%d.%d", + ((uver & 0xFF000000L) >> 24), ((uver & 0x00FF0000L) >> 16), + ((uver & 0x0000FF00L) >> 8), VERSION_MAJOR, VERSION_MINOR, + PATCHLEVEL); #else - Sprintf(eos(save_bones_compat_buf), " %d.%d.%d only", - VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); + Sprintf(eos(save_bones_compat_buf), " %d.%d.%d only", VERSION_MAJOR, + VERSION_MINOR, PATCHLEVEL); #endif } static const char *build_opts[] = { #ifdef AMIGA_WBENCH - "Amiga WorkBench support", + "Amiga WorkBench support", #endif #ifdef ANSI_DEFAULT - "ANSI default terminal", + "ANSI default terminal", #endif #ifdef TEXTCOLOR - "color", + "color", #endif #ifdef COM_COMPL - "command line completion", + "command line completion", #endif #ifdef LIFE - "Conway's Game of Life", + "Conway's Game of Life", #endif #ifdef COMPRESS - "data file compression", + "data file compression", #endif #ifdef ZLIB_COMP - "ZLIB data file compression", + "ZLIB data file compression", #endif #ifdef DLB - "data librarian", + "data librarian", #endif #ifdef MFLOPPY - "floppy drive support", + "floppy drive support", #endif #ifdef INSURANCE - "insurance files for recovering from crashes", + "insurance files for recovering from crashes", #endif #ifdef HOLD_LOCKFILE_OPEN - "exclusive lock on level 0 file", + "exclusive lock on level 0 file", #endif #ifdef LOGFILE - "log file", + "log file", #endif #ifdef MAIL - "mail daemon", + "mail daemon", #endif #ifdef GNUDOS - "MSDOS protected mode", + "MSDOS protected mode", #endif #ifdef NEWS - "news file", + "news file", #endif #ifdef MENU_COLOR_REGEX - "menu colors via regular expressions", + "menu colors via regular expressions", #else - "menu colors via pmatch", + "menu colors via pmatch", #endif #ifdef OVERLAY -# ifdef MOVERLAY - "MOVE overlays", -# else -# ifdef VROOMM - "VROOMM overlays", -# else - "overlays", -# endif -# endif +#ifdef MOVERLAY + "MOVE overlays", +#else +#ifdef VROOMM + "VROOMM overlays", +#else + "overlays", +#endif +#endif #endif #ifdef SELECTSAVED - "restore saved games via menu", + "restore saved games via menu", #endif #ifdef SCORE_ON_BOTL - "score on status line", + "score on status line", #endif #ifdef CLIPPING - "screen clipping", + "screen clipping", #endif #ifdef NO_TERMS -# ifdef MAC - "screen control via mactty", -# endif -# ifdef SCREEN_BIOS - "screen control via BIOS", -# endif -# ifdef SCREEN_DJGPPFAST - "screen control via DJGPP fast", -# endif -# ifdef SCREEN_VGA - "screen control via VGA graphics", -# endif -# ifdef WIN32CON - "screen control via WIN32 console I/O", -# endif +#ifdef MAC + "screen control via mactty", +#endif +#ifdef SCREEN_BIOS + "screen control via BIOS", +#endif +#ifdef SCREEN_DJGPPFAST + "screen control via DJGPP fast", +#endif +#ifdef SCREEN_VGA + "screen control via VGA graphics", +#endif +#ifdef WIN32CON + "screen control via WIN32 console I/O", +#endif #endif #ifdef SHELL - "shell command", + "shell command", #endif #ifdef SUSPEND - "suspend command", + "suspend command", #endif #ifdef TERMINFO - "terminal info library", + "terminal info library", #else -# if defined(TERMLIB) || ((!defined(MICRO) && !defined(WIN32)) && defined(TTY_GRAPHICS)) - "terminal capability library", -# endif +#if defined(TERMLIB) \ + || ((!defined(MICRO) && !defined(WIN32)) && defined(TTY_GRAPHICS)) + "terminal capability library", +#endif #endif #ifdef TIMED_DELAY - "timed wait for display effects", + "timed wait for display effects", #endif #ifdef USER_SOUNDS -# ifdef USER_SOUNDS_REGEX - "user sounds via regular expressions", -# else - "user sounds via pmatch", -# endif +#ifdef USER_SOUNDS_REGEX + "user sounds via regular expressions", +#else + "user sounds via pmatch", +#endif #endif #ifdef PREFIXES_IN_USE - "variable playground", + "variable playground", #endif #ifdef VISION_TABLES - "vision tables", + "vision tables", #endif #ifdef ZEROCOMP - "zero-compressed save files", + "zero-compressed save files", #endif #ifdef RLECOMP - "run-length compression of map in save files", + "run-length compression of map in save files", #endif #ifdef SYSCF - "system configuration at run-time", + "system configuration at run-time", #endif - save_bones_compat_buf, - "and basic NetHack features" - }; + save_bones_compat_buf, "and basic NetHack features" +}; struct win_info { - const char *id, /* DEFAULT_WINDOW_SYS string */ - *name; /* description, often same as id */ + const char *id, /* DEFAULT_WINDOW_SYS string */ + *name; /* description, often same as id */ }; static struct win_info window_opts[] = { #ifdef TTY_GRAPHICS - { "tty", "traditional tty-based graphics" }, + { "tty", "traditional tty-based graphics" }, #endif #ifdef X11_GRAPHICS - { "X11", "X11" }, + { "X11", "X11" }, #endif #ifdef QT_GRAPHICS - { "Qt", "Qt" }, + { "Qt", "Qt" }, #endif #ifdef GNOME_GRAPHICS - { "Gnome", "Gnome" }, + { "Gnome", "Gnome" }, #endif #ifdef MAC - { "mac", "Mac" }, + { "mac", "Mac" }, #endif #ifdef AMIGA_INTUITION - { "amii", "Amiga Intuition" }, + { "amii", "Amiga Intuition" }, #endif #ifdef GEM_GRAPHICS - { "Gem", "Gem" }, + { "Gem", "Gem" }, #endif #ifdef MSWIN_GRAPHICS - { "mswin", "mswin" }, + { "mswin", "mswin" }, #endif #ifdef BEOS_GRAPHICS - { "BeOS", "BeOS InterfaceKit" }, + { "BeOS", "BeOS InterfaceKit" }, #endif - { 0, 0 } - }; + { 0, 0 } +}; static void windowing_sanity() { #ifndef DEFAULT_WINDOW_SYS - /* pre-standard compilers didn't support #error; wait til run-time */ - Fprintf(stderr, - "Configuration error: DEFAULT_WINDOW_SYS is not defined.\n"); - exit(EXIT_FAILURE); - /*NOTREACHED*/ + /* pre-standard compilers didn't support #error; wait til run-time */ + Fprintf(stderr, + "Configuration error: DEFAULT_WINDOW_SYS is not defined.\n"); + exit(EXIT_FAILURE); +/*NOTREACHED*/ - /* put in a dummy value so that do_options() will compile and makedefs - will build, otherwise the message above won't ever get delivered */ -# define DEFAULT_WINDOW_SYS "" -#else /*DEFAULT_WINDOW_SYS*/ +/* put in a dummy value so that do_options() will compile and makedefs + will build, otherwise the message above won't ever get delivered */ +#define DEFAULT_WINDOW_SYS "" +#else /*DEFAULT_WINDOW_SYS*/ - if (!window_opts[0].id) { - Fprintf(stderr, - "Configuration error: no windowing systems (TTY_GRAPHICS, &c) enabled.\n"); - exit(EXIT_FAILURE); - } + if (!window_opts[0].id) { + Fprintf(stderr, "Configuration error: no windowing systems " + "(TTY_GRAPHICS, &c) enabled.\n"); + exit(EXIT_FAILURE); + } { - int i; + int i; - for (i = 0; window_opts[i].id; ++i) - if (!strcmp(window_opts[i].id, DEFAULT_WINDOW_SYS)) break; - if (!window_opts[i].id) { /* went through whole list without a match */ - Fprintf(stderr, - "Configuration error: DEFAULT_WINDOW_SYS (%s)\n", DEFAULT_WINDOW_SYS); - Fprintf(stderr, - " does not match any enabled windowing system (%s%s).\n", - window_opts[0].id, - window_opts[1].id ? ", &c" : ""); - exit(EXIT_FAILURE); - } + for (i = 0; window_opts[i].id; ++i) + if (!strcmp(window_opts[i].id, DEFAULT_WINDOW_SYS)) + break; + if (!window_opts[i] + .id) { /* went through whole list without a match */ + Fprintf(stderr, "Configuration error: DEFAULT_WINDOW_SYS (%s)\n", + DEFAULT_WINDOW_SYS); + Fprintf(stderr, + " does not match any enabled windowing system (%s%s).\n", + window_opts[0].id, window_opts[1].id ? ", &c" : ""); + exit(EXIT_FAILURE); + } } -#endif /*DEFAULT_WINDOW_SYS*/ +#endif /*DEFAULT_WINDOW_SYS*/ } void do_options() { - static const char indent[] = " "; - const char *str, *sep; - char *word, buf[BUFSZ]; - int i, length, winsyscnt; + static const char indent[] = " "; + const char *str, *sep; + char *word, buf[BUFSZ]; + int i, length, winsyscnt; - windowing_sanity(); + windowing_sanity(); - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename,file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), DATA_TEMPLATE, OPTIONS_FILE); - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } + Sprintf(eos(filename), DATA_TEMPLATE, OPTIONS_FILE); + if (!(ofp = fopen(filename, WRTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } - build_savebones_compat_string(); - Fprintf(ofp, + build_savebones_compat_string(); + Fprintf(ofp, #ifdef BETA - "\n NetHack version %d.%d.%d [beta]\n", + "\n NetHack version %d.%d.%d [beta]\n", #else - "\n NetHack version %d.%d.%d\n", + "\n NetHack version %d.%d.%d\n", #endif - VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); + VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); - Fprintf(ofp,"\nOptions compiled into this edition:\n"); - length = COLNO + 1; /* force 1st item onto new line */ - for (i = 0; i < SIZE(build_opts); i++) { - str = strcpy(buf, build_opts[i]); - while (*str) { - word = index(str, ' '); - if (word) *word = '\0'; - if (length + strlen(str) > COLNO - 5) - Fprintf(ofp,"\n%s", indent), length = strlen(indent); - else - Fprintf(ofp," "), length++; - Fprintf(ofp,"%s", str), length += strlen(str); - str += strlen(str) + (word ? 1 : 0); - } - Fprintf(ofp,(i < SIZE(build_opts) - 1) ? "," : "."), length++; - } + Fprintf(ofp, "\nOptions compiled into this edition:\n"); + length = COLNO + 1; /* force 1st item onto new line */ + for (i = 0; i < SIZE(build_opts); i++) { + str = strcpy(buf, build_opts[i]); + while (*str) { + word = index(str, ' '); + if (word) + *word = '\0'; + if (length + strlen(str) > COLNO - 5) + Fprintf(ofp, "\n%s", indent), length = strlen(indent); + else + Fprintf(ofp, " "), length++; + Fprintf(ofp, "%s", str), length += strlen(str); + str += strlen(str) + (word ? 1 : 0); + } + Fprintf(ofp, (i < SIZE(build_opts) - 1) ? "," : "."), length++; + } - winsyscnt = SIZE(window_opts) - 1; - Fprintf(ofp, "\n\nSupported windowing system%s:\n", - (winsyscnt > 1) ? "s" : ""); - length = COLNO + 1; /* force 1st item onto new line */ - for (i = 0; i < winsyscnt; i++) { - str = window_opts[i].name; - if (length + strlen(str) > COLNO - 5) - Fprintf(ofp,"\n%s", indent), length = strlen(indent); - else - Fprintf(ofp," "), length++; - Fprintf(ofp,"%s", str), length += strlen(str); - sep = (winsyscnt == 1) ? "." : - (winsyscnt == 2) ? ((i == 0) ? " and" : "") : - (i < winsyscnt - 2) ? "," : - ((i == winsyscnt - 2) ? ", and" : ""); - Fprintf(ofp, "%s", sep), length += strlen(sep); - } - if (winsyscnt > 1) - Fprintf(ofp, "\n%swith a default of %s.", - indent, DEFAULT_WINDOW_SYS); - Fprintf(ofp,"\n\n"); + winsyscnt = SIZE(window_opts) - 1; + Fprintf(ofp, "\n\nSupported windowing system%s:\n", + (winsyscnt > 1) ? "s" : ""); + length = COLNO + 1; /* force 1st item onto new line */ + for (i = 0; i < winsyscnt; i++) { + str = window_opts[i].name; + if (length + strlen(str) > COLNO - 5) + Fprintf(ofp, "\n%s", indent), length = strlen(indent); + else + Fprintf(ofp, " "), length++; + Fprintf(ofp, "%s", str), length += strlen(str); + sep = (winsyscnt == 1) + ? "." + : (winsyscnt == 2) + ? ((i == 0) ? " and" : "") + : (i < winsyscnt - 2) + ? "," + : ((i == winsyscnt - 2) ? ", and" : ""); + Fprintf(ofp, "%s", sep), length += strlen(sep); + } + if (winsyscnt > 1) + Fprintf(ofp, "\n%swith a default of %s.", indent, DEFAULT_WINDOW_SYS); + Fprintf(ofp, "\n\n"); - Fclose(ofp); - return; + Fclose(ofp); + return; } /* routine to decide whether to discard something from data.base */ static boolean d_filter(line) - char *line; +char *line; { - if (*line == '#') return TRUE; /* ignore comment lines */ + if (*line == '#') + return TRUE; /* ignore comment lines */ return FALSE; } - /* - * - New format (v3.1) of 'data' file which allows much faster lookups [pr] +/* + * + New format (v3.1) of 'data' file which allows much faster lookups [pr] "do not edit" first record is a comment line 01234567 hexadecimal formatted offset to text area name-a first name of interest @@ -1552,135 +1599,140 @@ text-a text-b/text-c 7 lines of text for names-b and -c text-b/text-c at fseek(0x01234567L + 456L) ... - * - */ + * + */ void do_data() { - char infile[60], tempfile[60]; - boolean ok; - long txt_offset; - int entry_cnt, line_cnt; + char infile[60], tempfile[60]; + boolean ok; + long txt_offset; + int entry_cnt, line_cnt; - Sprintf(tempfile, DATA_TEMPLATE, "database.tmp"); - filename[0]='\0'; + Sprintf(tempfile, DATA_TEMPLATE, "database.tmp"); + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename,file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), DATA_TEMPLATE, DATA_FILE); - Sprintf(infile, DATA_IN_TEMPLATE, DATA_FILE); + Sprintf(eos(filename), DATA_TEMPLATE, DATA_FILE); + Sprintf(infile, DATA_IN_TEMPLATE, DATA_FILE); #ifdef SHORT_FILENAMES - Strcat(infile, ".bas"); + Strcat(infile, ".bas"); #else - Strcat(infile, ".base"); + Strcat(infile, ".base"); #endif - if (!(ifp = fopen(infile, RDTMODE))) { /* data.base */ - perror(infile); - exit(EXIT_FAILURE); - } - if (!(ofp = fopen(filename, WRTMODE))) { /* data */ - perror(filename); - Fclose(ifp); - exit(EXIT_FAILURE); - } - if (!(tfp = fopen(tempfile, WRTMODE))) { /* database.tmp */ - perror(tempfile); - Fclose(ifp); - Fclose(ofp); - Unlink(filename); - exit(EXIT_FAILURE); - } + if (!(ifp = fopen(infile, RDTMODE))) { /* data.base */ + perror(infile); + exit(EXIT_FAILURE); + } + if (!(ofp = fopen(filename, WRTMODE))) { /* data */ + perror(filename); + Fclose(ifp); + exit(EXIT_FAILURE); + } + if (!(tfp = fopen(tempfile, WRTMODE))) { /* database.tmp */ + perror(tempfile); + Fclose(ifp); + Fclose(ofp); + Unlink(filename); + exit(EXIT_FAILURE); + } - /* output a dummy header record; we'll rewind and overwrite it later */ - Fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, 0L); + /* output a dummy header record; we'll rewind and overwrite it later */ + Fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, 0L); - entry_cnt = line_cnt = 0; - /* read through the input file and split it into two sections */ - while (fgets(in_line, sizeof in_line, ifp)) { - if (d_filter(in_line)) continue; - if (*in_line > ' ') { /* got an entry name */ - /* first finish previous entry */ - if (line_cnt) Fprintf(ofp, "%d\n", line_cnt), line_cnt = 0; - /* output the entry name */ - (void) fputs(in_line, ofp); - entry_cnt++; /* update number of entries */ - } else if (entry_cnt) { /* got some descriptive text */ - /* update previous entry with current text offset */ - if (!line_cnt) Fprintf(ofp, "%ld,", ftell(tfp)); - /* save the text line in the scratch file */ - (void) fputs(in_line, tfp); - line_cnt++; /* update line counter */ - } - } - /* output an end marker and then record the current position */ - if (line_cnt) Fprintf(ofp, "%d\n", line_cnt); - Fprintf(ofp, ".\n%ld,%d\n", ftell(tfp), 0); - txt_offset = ftell(ofp); - Fclose(ifp); /* all done with original input file */ + entry_cnt = line_cnt = 0; + /* read through the input file and split it into two sections */ + while (fgets(in_line, sizeof in_line, ifp)) { + if (d_filter(in_line)) + continue; + if (*in_line > ' ') { /* got an entry name */ + /* first finish previous entry */ + if (line_cnt) + Fprintf(ofp, "%d\n", line_cnt), line_cnt = 0; + /* output the entry name */ + (void) fputs(in_line, ofp); + entry_cnt++; /* update number of entries */ + } else if (entry_cnt) { /* got some descriptive text */ + /* update previous entry with current text offset */ + if (!line_cnt) + Fprintf(ofp, "%ld,", ftell(tfp)); + /* save the text line in the scratch file */ + (void) fputs(in_line, tfp); + line_cnt++; /* update line counter */ + } + } + /* output an end marker and then record the current position */ + if (line_cnt) + Fprintf(ofp, "%d\n", line_cnt); + Fprintf(ofp, ".\n%ld,%d\n", ftell(tfp), 0); + txt_offset = ftell(ofp); + Fclose(ifp); /* all done with original input file */ - /* reprocess the scratch file; 1st format an error msg, just in case */ - Sprintf(in_line, "rewind of \"%s\"", tempfile); - if (rewind(tfp) != 0) goto dead_data; - /* copy all lines of text from the scratch file into the output file */ - while (fgets(in_line, sizeof in_line, tfp)) - (void) fputs(in_line, ofp); + /* reprocess the scratch file; 1st format an error msg, just in case */ + Sprintf(in_line, "rewind of \"%s\"", tempfile); + if (rewind(tfp) != 0) + goto dead_data; + /* copy all lines of text from the scratch file into the output file */ + while (fgets(in_line, sizeof in_line, tfp)) + (void) fputs(in_line, ofp); - /* finished with scratch file */ - Fclose(tfp); - Unlink(tempfile); /* remove it */ + /* finished with scratch file */ + Fclose(tfp); + Unlink(tempfile); /* remove it */ - /* update the first record of the output file; prepare error msg 1st */ - Sprintf(in_line, "rewind of \"%s\"", filename); - ok = (rewind(ofp) == 0); - if (ok) { - Sprintf(in_line, "header rewrite of \"%s\"", filename); - ok = (fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, - (unsigned long)txt_offset) >= 0); - } - if (!ok) { -dead_data: perror(in_line); /* report the problem */ - /* close and kill the aborted output file, then give up */ - Fclose(ofp); - Unlink(filename); - exit(EXIT_FAILURE); - } + /* update the first record of the output file; prepare error msg 1st */ + Sprintf(in_line, "rewind of \"%s\"", filename); + ok = (rewind(ofp) == 0); + if (ok) { + Sprintf(in_line, "header rewrite of \"%s\"", filename); + ok = (fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, + (unsigned long) txt_offset) >= 0); + } + if (!ok) { + dead_data: + perror(in_line); /* report the problem */ + /* close and kill the aborted output file, then give up */ + Fclose(ofp); + Unlink(filename); + exit(EXIT_FAILURE); + } - /* all done */ - Fclose(ofp); + /* all done */ + Fclose(ofp); - return; + return; } /* routine to decide whether to discard something from oracles.txt */ static boolean h_filter(line) - char *line; +char *line; { static boolean skip = FALSE; char tag[sizeof in_line]; SpinCursor(3); - if (*line == '#') return TRUE; /* ignore comment lines */ + if (*line == '#') + return TRUE; /* ignore comment lines */ if (sscanf(line, "----- %s", tag) == 1) { - skip = FALSE; + skip = FALSE; } else if (skip && !strncmp(line, "-----", 5)) - skip = FALSE; + skip = FALSE; return skip; } static const char *special_oracle[] = { - "\"...it is rather disconcerting to be confronted with the", - "following theorem from [Baker, Gill, and Solovay, 1975].", - "", - "Theorem 7.18 There exist recursive languages A and B such that", - " (1) P(A) == NP(A), and", - " (2) P(B) != NP(B)", - "", - "This provides impressive evidence that the techniques that are", - "currently available will not suffice for proving that P != NP or ", - "that P == NP.\" [Garey and Johnson, p. 185.]" + "\"...it is rather disconcerting to be confronted with the", + "following theorem from [Baker, Gill, and Solovay, 1975].", "", + "Theorem 7.18 There exist recursive languages A and B such that", + " (1) P(A) == NP(A), and", " (2) P(B) != NP(B)", "", + "This provides impressive evidence that the techniques that are", + "currently available will not suffice for proving that P != NP or " + " ", + "that P == NP.\" [Garey and Johnson, p. 185.]" }; /* @@ -1694,194 +1746,205 @@ static const char *special_oracle[] = { void do_oracles() { - char infile[60], tempfile[60]; - boolean in_oracle, ok; - long fpos; - unsigned long txt_offset, offset; - int oracle_cnt; - register int i; + char infile[60], tempfile[60]; + boolean in_oracle, ok; + long fpos; + unsigned long txt_offset, offset; + int oracle_cnt; + register int i; - Sprintf(tempfile, DATA_TEMPLATE, "oracles.tmp"); - filename[0]='\0'; + Sprintf(tempfile, DATA_TEMPLATE, "oracles.tmp"); + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename, file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), DATA_TEMPLATE, ORACLE_FILE); - Sprintf(infile, DATA_IN_TEMPLATE, ORACLE_FILE); - Strcat(infile, ".txt"); - if (!(ifp = fopen(infile, RDTMODE))) { - perror(infile); - exit(EXIT_FAILURE); - } - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - Fclose(ifp); - exit(EXIT_FAILURE); - } - if (!(tfp = fopen(tempfile, WRTMODE))) { /* oracles.tmp */ - perror(tempfile); - Fclose(ifp); - Fclose(ofp); - Unlink(filename); - exit(EXIT_FAILURE); - } + Sprintf(eos(filename), DATA_TEMPLATE, ORACLE_FILE); + Sprintf(infile, DATA_IN_TEMPLATE, ORACLE_FILE); + Strcat(infile, ".txt"); + if (!(ifp = fopen(infile, RDTMODE))) { + perror(infile); + exit(EXIT_FAILURE); + } + if (!(ofp = fopen(filename, WRTMODE))) { + perror(filename); + Fclose(ifp); + exit(EXIT_FAILURE); + } + if (!(tfp = fopen(tempfile, WRTMODE))) { /* oracles.tmp */ + perror(tempfile); + Fclose(ifp); + Fclose(ofp); + Unlink(filename); + exit(EXIT_FAILURE); + } - /* output a dummy header record; we'll rewind and overwrite it later */ - Fprintf(ofp, "%s%5d\n", Dont_Edit_Data, 0); + /* output a dummy header record; we'll rewind and overwrite it later */ + Fprintf(ofp, "%s%5d\n", Dont_Edit_Data, 0); - /* handle special oracle; it must come first */ - (void) fputs("---\n", tfp); - offset = (unsigned long)ftell(tfp); - Fprintf(ofp, "%05lx\n", offset); /* start pos of special oracle */ - for (i = 0; i < SIZE(special_oracle); i++) { - (void) fputs(xcrypt(special_oracle[i]), tfp); - (void) fputc('\n', tfp); - } - SpinCursor(3); + /* handle special oracle; it must come first */ + (void) fputs("---\n", tfp); + offset = (unsigned long) ftell(tfp); + Fprintf(ofp, "%05lx\n", offset); /* start pos of special oracle */ + for (i = 0; i < SIZE(special_oracle); i++) { + (void) fputs(xcrypt(special_oracle[i]), tfp); + (void) fputc('\n', tfp); + } + SpinCursor(3); - oracle_cnt = 1; - (void) fputs("---\n", tfp); - offset = (unsigned long)ftell(tfp); - Fprintf(ofp, "%05lx\n", offset); /* start pos of first oracle */ - in_oracle = FALSE; + oracle_cnt = 1; + (void) fputs("---\n", tfp); + offset = (unsigned long) ftell(tfp); + Fprintf(ofp, "%05lx\n", offset); /* start pos of first oracle */ + in_oracle = FALSE; - while (fgets(in_line, sizeof in_line, ifp)) { - SpinCursor(3); + while (fgets(in_line, sizeof in_line, ifp)) { + SpinCursor(3); - if (h_filter(in_line)) continue; - if (!strncmp(in_line, "-----", 5)) { - if (!in_oracle) continue; - in_oracle = FALSE; - oracle_cnt++; - (void) fputs("---\n", tfp); - offset = (unsigned long)ftell(tfp); - Fprintf(ofp, "%05lx\n", offset); /* start pos of this oracle */ - } else { - in_oracle = TRUE; - (void) fputs(xcrypt(in_line), tfp); - } - } + if (h_filter(in_line)) + continue; + if (!strncmp(in_line, "-----", 5)) { + if (!in_oracle) + continue; + in_oracle = FALSE; + oracle_cnt++; + (void) fputs("---\n", tfp); + offset = (unsigned long) ftell(tfp); + Fprintf(ofp, "%05lx\n", offset); /* start pos of this oracle */ + } else { + in_oracle = TRUE; + (void) fputs(xcrypt(in_line), tfp); + } + } - if (in_oracle) { /* need to terminate last oracle */ - oracle_cnt++; - (void) fputs("---\n", tfp); - offset = (unsigned long)ftell(tfp); - Fprintf(ofp, "%05lx\n", offset); /* eof position */ - } + if (in_oracle) { /* need to terminate last oracle */ + oracle_cnt++; + (void) fputs("---\n", tfp); + offset = (unsigned long) ftell(tfp); + Fprintf(ofp, "%05lx\n", offset); /* eof position */ + } - /* record the current position */ - txt_offset = (unsigned long)ftell(ofp); - Fclose(ifp); /* all done with original input file */ + /* record the current position */ + txt_offset = (unsigned long) ftell(ofp); + Fclose(ifp); /* all done with original input file */ - /* reprocess the scratch file; 1st format an error msg, just in case */ - Sprintf(in_line, "rewind of \"%s\"", tempfile); - if (rewind(tfp) != 0) goto dead_data; - /* copy all lines of text from the scratch file into the output file */ - while (fgets(in_line, sizeof in_line, tfp)) - (void) fputs(in_line, ofp); + /* reprocess the scratch file; 1st format an error msg, just in case */ + Sprintf(in_line, "rewind of \"%s\"", tempfile); + if (rewind(tfp) != 0) + goto dead_data; + /* copy all lines of text from the scratch file into the output file */ + while (fgets(in_line, sizeof in_line, tfp)) + (void) fputs(in_line, ofp); - /* finished with scratch file */ - Fclose(tfp); - Unlink(tempfile); /* remove it */ + /* finished with scratch file */ + Fclose(tfp); + Unlink(tempfile); /* remove it */ - /* update the first record of the output file; prepare error msg 1st */ - Sprintf(in_line, "rewind of \"%s\"", filename); - ok = (rewind(ofp) == 0); - if (ok) { - Sprintf(in_line, "header rewrite of \"%s\"", filename); - ok = (fprintf(ofp, "%s%5d\n", Dont_Edit_Data, oracle_cnt) >=0); - } - if (ok) { - Sprintf(in_line, "data rewrite of \"%s\"", filename); - for (i = 0; i <= oracle_cnt; i++) { -#ifndef VMS /* alpha/vms v1.0; this fflush seems to confuse ftell */ - if (!(ok = (fflush(ofp) == 0))) break; + /* update the first record of the output file; prepare error msg 1st */ + Sprintf(in_line, "rewind of \"%s\"", filename); + ok = (rewind(ofp) == 0); + if (ok) { + Sprintf(in_line, "header rewrite of \"%s\"", filename); + ok = (fprintf(ofp, "%s%5d\n", Dont_Edit_Data, oracle_cnt) >= 0); + } + if (ok) { + Sprintf(in_line, "data rewrite of \"%s\"", filename); + for (i = 0; i <= oracle_cnt; i++) { +#ifndef VMS /* alpha/vms v1.0; this fflush seems to confuse ftell */ + if (!(ok = (fflush(ofp) == 0))) + break; #endif - if (!(ok = (fpos = ftell(ofp)) >= 0)) break; - if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break; - if (!(ok = (fscanf(ofp, "%5lx", &offset) == 1))) break; + if (!(ok = (fpos = ftell(ofp)) >= 0)) + break; + if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) + break; + if (!(ok = (fscanf(ofp, "%5lx", &offset) == 1))) + break; #ifdef MAC -# ifdef __MWERKS__ - /* - MetroWerks CodeWarrior Pro 1's (AKA CW12) version of MSL - (ANSI C Libraries) needs this rewind or else the fprintf - stops working. This may also be true for CW11, but has - never been checked. - */ - rewind(ofp); -# endif +#ifdef __MWERKS__ + /* + MetroWerks CodeWarrior Pro 1's (AKA CW12) version of MSL + (ANSI C Libraries) needs this rewind or else the fprintf + stops working. This may also be true for CW11, but has + never been checked. + */ + rewind(ofp); #endif - if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break; - offset += txt_offset; - if (!(ok = (fprintf(ofp, "%05lx\n", offset) >= 0))) break; - } - } - if (!ok) { -dead_data: perror(in_line); /* report the problem */ - /* close and kill the aborted output file, then give up */ - Fclose(ofp); - Unlink(filename); - exit(EXIT_FAILURE); - } +#endif + if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) + break; + offset += txt_offset; + if (!(ok = (fprintf(ofp, "%05lx\n", offset) >= 0))) + break; + } + } + if (!ok) { + dead_data: + perror(in_line); /* report the problem */ + /* close and kill the aborted output file, then give up */ + Fclose(ofp); + Unlink(filename); + exit(EXIT_FAILURE); + } - /* all done */ - Fclose(ofp); + /* all done */ + Fclose(ofp); - return; + return; } void do_dungeon() { - int rcnt = 0; + int rcnt = 0; - Sprintf(filename, DATA_IN_TEMPLATE, DGN_I_FILE); - if (!(ifp = fopen(filename, RDTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } - filename[0]='\0'; + Sprintf(filename, DATA_IN_TEMPLATE, DGN_I_FILE); + if (!(ifp = fopen(filename, RDTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename, file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), DGN_TEMPLATE, DGN_O_FILE); - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } - Fprintf(ofp,"%s",Dont_Edit_Data); + Sprintf(eos(filename), DGN_TEMPLATE, DGN_O_FILE); + if (!(ofp = fopen(filename, WRTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } + Fprintf(ofp, "%s", Dont_Edit_Data); - tfp = getfp(DATA_TEMPLATE, "grep.tmp", WRTMODE); - grep0(ifp, tfp); - ifp = getfp(DATA_TEMPLATE, "grep.tmp", RDTMODE); - - while (fgets(in_line, sizeof in_line, ifp) != 0) { - SpinCursor(3); + tfp = getfp(DATA_TEMPLATE, "grep.tmp", WRTMODE); + grep0(ifp, tfp); + ifp = getfp(DATA_TEMPLATE, "grep.tmp", RDTMODE); - rcnt++; - if(in_line[0] == '#') continue; /* discard comments */ - (void) fputs(in_line,ofp); - } - Fclose(ifp); - Fclose(ofp); + while (fgets(in_line, sizeof in_line, ifp) != 0) { + SpinCursor(3); - delete_file(DATA_TEMPLATE, "grep.tmp"); - return; + rcnt++; + if (in_line[0] == '#') + continue; /* discard comments */ + (void) fputs(in_line, ofp); + } + Fclose(ifp); + Fclose(ofp); + + delete_file(DATA_TEMPLATE, "grep.tmp"); + return; } static boolean -ranged_attk(ptr) /* returns TRUE if monster can attack at range */ - register struct permonst *ptr; +ranged_attk(ptr) /* returns TRUE if monster can attack at range */ +register struct permonst *ptr; { - register int i, j; - register int atk_mask = (1<mattk[i].aatyp) >= AT_WEAP || (atk_mask & (1<mattk[i].aatyp) >= AT_WEAP || (atk_mask & (1 << j))) + return TRUE; + } - return(FALSE); + return (FALSE); } /* This routine is designed to return an integer value which represents @@ -1892,55 +1955,60 @@ static int mstrength(ptr) struct permonst *ptr; { - int i, tmp2, n, tmp = ptr->mlevel; + int i, tmp2, n, tmp = ptr->mlevel; - if(tmp > 49) /* special fixed hp monster */ - tmp = 2*(tmp - 6) / 4; + if (tmp > 49) /* special fixed hp monster */ + tmp = 2 * (tmp - 6) / 4; -/* For creation in groups */ - n = (!!(ptr->geno & G_SGROUP)); - n += (!!(ptr->geno & G_LGROUP)) << 1; + /* For creation in groups */ + n = (!!(ptr->geno & G_SGROUP)); + n += (!!(ptr->geno & G_LGROUP)) << 1; -/* For ranged attacks */ - if (ranged_attk(ptr)) n++; + /* For ranged attacks */ + if (ranged_attk(ptr)) + n++; -/* For higher ac values */ - n += (ptr->ac < 4); - n += (ptr->ac < 0); + /* For higher ac values */ + n += (ptr->ac < 4); + n += (ptr->ac < 0); -/* For very fast monsters */ - n += (ptr->mmove >= 18); + /* For very fast monsters */ + n += (ptr->mmove >= 18); -/* For each attack and "special" attack */ - for(i = 0; i < NATTK; i++) { + /* For each attack and "special" attack */ + for (i = 0; i < NATTK; i++) { + tmp2 = ptr->mattk[i].aatyp; + n += (tmp2 > 0); + n += (tmp2 == AT_MAGC); + n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG)); + } - tmp2 = ptr->mattk[i].aatyp; - n += (tmp2 > 0); - n += (tmp2 == AT_MAGC); - n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG)); - } + /* For each "special" damage type */ + for (i = 0; i < NATTK; i++) { + tmp2 = ptr->mattk[i].adtyp; + if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST) + || (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE)) + n += 2; + else if (strcmp(ptr->mname, "grid bug")) + n += (tmp2 != AD_PHYS); + n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23); + } -/* For each "special" damage type */ - for(i = 0; i < NATTK; i++) { + /* Leprechauns are special cases. They have many hit dice so they + can hit and are hard to kill, but they don't really do much + damage. */ + if (!strcmp(ptr->mname, "leprechaun")) + n -= 2; - tmp2 = ptr->mattk[i].adtyp; - if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST) - || (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE)) - n += 2; - else if (strcmp(ptr->mname, "grid bug")) n += (tmp2 != AD_PHYS); - n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23); - } + /* Finally, adjust the monster level 0 <= n <= 24 (approx.) */ + if (n == 0) + tmp--; + else if (n >= 6) + tmp += (n / 2); + else + tmp += (n / 3 + 1); -/* Leprechauns are special cases. They have many hit dice so they - can hit and are hard to kill, but they don't really do much damage. */ - if (!strcmp(ptr->mname, "leprechaun")) n -= 2; - -/* Finally, adjust the monster level 0 <= n <= 24 (approx.) */ - if(n == 0) tmp--; - else if(n >= 6) tmp += ( n / 2 ); - else tmp += ( n / 3 + 1); - - return((tmp >= 0) ? tmp : 0); + return ((tmp >= 0) ? tmp : 0); } void @@ -1952,35 +2020,34 @@ do_monstr() /* * create the source file, "monstr.c" */ - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX Strcat(filename, file_prefix); #endif Sprintf(eos(filename), SOURCE_TEMPLATE, MON_STR_C); if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); + perror(filename); + exit(EXIT_FAILURE); } - Fprintf(ofp,"%s",Dont_Edit_Code); - Fprintf(ofp,"#include \"config.h\"\n"); - Fprintf(ofp,"\nconst int monstr[] = {\n"); + Fprintf(ofp, "%s", Dont_Edit_Code); + Fprintf(ofp, "#include \"config.h\"\n"); + Fprintf(ofp, "\nconst int monstr[] = {\n"); for (ptr = &mons[0], j = 0; ptr->mlet; ptr++) { + SpinCursor(3); - SpinCursor(3); - - i = mstrength(ptr); - Fprintf(ofp,"%2d,%c", i, (++j & 15) ? ' ' : '\n'); + i = mstrength(ptr); + Fprintf(ofp, "%2d,%c", i, (++j & 15) ? ' ' : '\n'); } /* might want to insert a final 0 entry here instead of just newline */ - Fprintf(ofp,"%s};\n", (j & 15) ? "\n" : ""); + Fprintf(ofp, "%s};\n", (j & 15) ? "\n" : ""); - Fprintf(ofp,"\nvoid NDECL(monstr_init);\n"); - Fprintf(ofp,"\nvoid\n"); - Fprintf(ofp,"monstr_init()\n"); - Fprintf(ofp,"{\n"); - Fprintf(ofp," return;\n"); - Fprintf(ofp,"}\n"); - Fprintf(ofp,"\n/*monstr.c*/\n"); + Fprintf(ofp, "\nvoid NDECL(monstr_init);\n"); + Fprintf(ofp, "\nvoid\n"); + Fprintf(ofp, "monstr_init()\n"); + Fprintf(ofp, "{\n"); + Fprintf(ofp, " return;\n"); + Fprintf(ofp, "}\n"); + Fprintf(ofp, "\n/*monstr.c*/\n"); Fclose(ofp); return; @@ -1989,509 +2056,540 @@ do_monstr() void do_permonst() { - int i; - char *c, *nam; + int i; + char *c, *nam; - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename, file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), INCLUDE_TEMPLATE, MONST_FILE); - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } - Fprintf(ofp,"/*\tSCCS Id: @(#)pm.h\t3.5\t2004/02/01 */\n\n"); - Fprintf(ofp,"%s",Dont_Edit_Code); - Fprintf(ofp,"#ifndef PM_H\n#define PM_H\n"); + Sprintf(eos(filename), INCLUDE_TEMPLATE, MONST_FILE); + if (!(ofp = fopen(filename, WRTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } + Fprintf(ofp, "/*\tSCCS Id: @(#)pm.h\t3.5\t2004/02/01 */\n\n"); + Fprintf(ofp, "%s", Dont_Edit_Code); + Fprintf(ofp, "#ifndef PM_H\n#define PM_H\n"); - if (strcmp(mons[0].mname, "playermon") != 0) - Fprintf(ofp,"\n#define\tPM_PLAYERMON\t(-1)"); + if (strcmp(mons[0].mname, "playermon") != 0) + Fprintf(ofp, "\n#define\tPM_PLAYERMON\t(-1)"); - for (i = 0; mons[i].mlet; i++) { - SpinCursor(3); + for (i = 0; mons[i].mlet; i++) { + SpinCursor(3); - Fprintf(ofp,"\n#define\tPM_"); - if (mons[i].mlet == S_HUMAN && - !strncmp(mons[i].mname, "were", 4)) - Fprintf(ofp, "HUMAN_"); - for (nam = c = tmpdup(mons[i].mname); *c; c++) - if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A'); - else if (*c < 'A' || *c > 'Z') *c = '_'; - Fprintf(ofp,"%s\t%d", nam, i); - } - Fprintf(ofp,"\n\n#define\tNUMMONS\t%d\n", i); - Fprintf(ofp,"\n#endif /* PM_H */\n"); - Fclose(ofp); - return; + Fprintf(ofp, "\n#define\tPM_"); + if (mons[i].mlet == S_HUMAN && !strncmp(mons[i].mname, "were", 4)) + Fprintf(ofp, "HUMAN_"); + for (nam = c = tmpdup(mons[i].mname); *c; c++) + if (*c >= 'a' && *c <= 'z') + *c -= (char) ('a' - 'A'); + else if (*c < 'A' || *c > 'Z') + *c = '_'; + Fprintf(ofp, "%s\t%d", nam, i); + } + Fprintf(ofp, "\n\n#define\tNUMMONS\t%d\n", i); + Fprintf(ofp, "\n#endif /* PM_H */\n"); + Fclose(ofp); + return; } - /* Start of Quest text file processing. */ #include "qtext.h" -static struct qthdr qt_hdr; -static struct msghdr msg_hdr[N_HDR]; -static struct qtmsg *curr_msg; +static struct qthdr qt_hdr; +static struct msghdr msg_hdr[N_HDR]; +static struct qtmsg *curr_msg; -static int qt_line; +static int qt_line; -static boolean in_msg; -#define NO_MSG 1 /* strlen of a null line returned by fgets() */ +static boolean in_msg; +#define NO_MSG 1 /* strlen of a null line returned by fgets() */ static boolean qt_comment(s) - char *s; +char *s; { - if(s[0] == '#') return(TRUE); - return((boolean)(!in_msg && strlen(s) == NO_MSG)); + if (s[0] == '#') + return (TRUE); + return ((boolean)(!in_msg && strlen(s) == NO_MSG)); } static boolean qt_control(s) - char *s; +char *s; { - return((boolean)(s[0] == '%' && (s[1] == 'C' || s[1] == 'E'))); + return ((boolean)(s[0] == '%' && (s[1] == 'C' || s[1] == 'E'))); } static int -get_hdr (code) - char *code; +get_hdr(code) +char *code; { - int i; + int i; - for(i = 0; i < qt_hdr.n_hdr; i++) - if(!strncmp(code, qt_hdr.id[i], LEN_HDR)) return (++i); + for (i = 0; i < qt_hdr.n_hdr; i++) + if (!strncmp(code, qt_hdr.id[i], LEN_HDR)) + return (++i); - return(0); + return (0); } static boolean -new_id (code) - char *code; +new_id(code) +char *code; { - if(qt_hdr.n_hdr >= N_HDR) { - Fprintf(stderr, OUT_OF_HEADERS, qt_line); - return(FALSE); - } + if (qt_hdr.n_hdr >= N_HDR) { + Fprintf(stderr, OUT_OF_HEADERS, qt_line); + return (FALSE); + } - strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR); - msg_hdr[qt_hdr.n_hdr].n_msg = 0; - qt_hdr.offset[qt_hdr.n_hdr++] = 0L; - return(TRUE); + strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR); + msg_hdr[qt_hdr.n_hdr].n_msg = 0; + qt_hdr.offset[qt_hdr.n_hdr++] = 0L; + return (TRUE); } static boolean known_msg(num, id) - int num, id; +int num, id; { - int i; + int i; - for(i = 0; i < msg_hdr[num].n_msg; i++) - if(msg_hdr[num].qt_msg[i].msgnum == id) return(TRUE); + for (i = 0; i < msg_hdr[num].n_msg; i++) + if (msg_hdr[num].qt_msg[i].msgnum == id) + return (TRUE); - return(FALSE); + return (FALSE); } - static void new_msg(s, num, id) - char *s; - int num, id; +char *s; +int num, id; { - struct qtmsg *qt_msg; + struct qtmsg *qt_msg; - if(msg_hdr[num].n_msg >= N_MSG) { - Fprintf(stderr, OUT_OF_MESSAGES, qt_line); - } else { - qt_msg = &(msg_hdr[num].qt_msg[msg_hdr[num].n_msg++]); - qt_msg->msgnum = id; - qt_msg->delivery = s[2]; - qt_msg->offset = qt_msg->size = qt_msg->summary_size = 0L; + if (msg_hdr[num].n_msg >= N_MSG) { + Fprintf(stderr, OUT_OF_MESSAGES, qt_line); + } else { + qt_msg = &(msg_hdr[num].qt_msg[msg_hdr[num].n_msg++]); + qt_msg->msgnum = id; + qt_msg->delivery = s[2]; + qt_msg->offset = qt_msg->size = qt_msg->summary_size = 0L; - curr_msg = qt_msg; - } + curr_msg = qt_msg; + } } /* check %E record for "[summary text]" that nethack can stuff into the message history buffer when delivering text via window instead of pline */ static char * valid_qt_summary(s, parsing) -char *s; /* end record: "%E" optionally followed by " [summary]" */ -boolean parsing; /* curr_msg is valid iff this is True */ +char *s; /* end record: "%E" optionally followed by " [summary]" */ +boolean parsing; /* curr_msg is valid iff this is True */ { static char summary[BUFSZ]; char *p; - if (*s != '%' || *(s + 1) != 'E') return (char *)0; - if ((p = index(s, '[')) == 0) return (char *)0; + if (*s != '%' || *(s + 1) != 'E') + return (char *) 0; + if ((p = index(s, '[')) == 0) + return (char *) 0; /* note: opening '[' and closing ']' will be retained in the output; anything after ']' will be discarded by putting a newline there */ Strcpy(summary, p); - /* have an opening bracket; summary[] holds it and all text that follows */ + /* have an opening bracket; summary[] holds it and all text that follows + */ p = eos(summary); /* find closing bracket */ - while (p > summary && *(p - 1) != ']') --p; + while (p > summary && *(p - 1) != ']') + --p; if (p == summary) { - /* we backed up all the way to the start without finding a bracket */ - if (parsing) /* malformed summary */ - Fprintf(stderr, MAL_SUM, qt_line); + /* we backed up all the way to the start without finding a bracket */ + if (parsing) /* malformed summary */ + Fprintf(stderr, MAL_SUM, qt_line); } else if (p == summary + 1) { - ; /* ignore empty [] */ - } else { /* got something */ - /* p points one spot past ']', usually to '\n'; - we need to include the \n as part of the size */ - if (parsing) { - /* during the writing pass we won't be able to recheck - delivery, so any useless summary for a pline mode - message has to be carried along to the output file */ - if (curr_msg->delivery == 'p') - Fprintf(stderr, DUMB_SUM, qt_line); - /* +1 is for terminating newline */ - curr_msg->summary_size = (long)(p - summary) + 1L; - } else { - /* caller is writing rather than just parsing; - force newline after the closing bracket */ - Strcpy(p, "\n"); - } - return summary; + ; /* ignore empty [] */ + } else { /* got something */ + /* p points one spot past ']', usually to '\n'; + we need to include the \n as part of the size */ + if (parsing) { + /* during the writing pass we won't be able to recheck + delivery, so any useless summary for a pline mode + message has to be carried along to the output file */ + if (curr_msg->delivery == 'p') + Fprintf(stderr, DUMB_SUM, qt_line); + /* +1 is for terminating newline */ + curr_msg->summary_size = (long) (p - summary) + 1L; + } else { + /* caller is writing rather than just parsing; + force newline after the closing bracket */ + Strcpy(p, "\n"); + } + return summary; } - return (char *)0; + return (char *) 0; } static void do_qt_control(s) - char *s; +char *s; { - char code[BUFSZ]; - int num, id = 0; + char code[BUFSZ]; + int num, id = 0; - if (!index(s, '\n')) - Fprintf(stderr, CTRL_TRUNC, qt_line); + if (!index(s, '\n')) + Fprintf(stderr, CTRL_TRUNC, qt_line); - switch(s[1]) { + switch (s[1]) { + case 'C': + if (in_msg) { + Fprintf(stderr, CREC_IN_MSG, qt_line); + break; + } else { + in_msg = TRUE; + if (sscanf(&s[4], "%s %5d", code, &id) != 2) { + Fprintf(stderr, UNREC_CREC, qt_line); + break; + } + num = get_hdr(code); + if (!num && !new_id(code)) + break; + num = get_hdr(code) - 1; + if (known_msg(num, id)) + Fprintf(stderr, DUP_MSG, qt_line); + else + new_msg(s, num, id); + } + break; - case 'C': if(in_msg) { - Fprintf(stderr, CREC_IN_MSG, qt_line); - break; - } else { - in_msg = TRUE; - if (sscanf(&s[4], "%s %5d", code, &id) != 2) { - Fprintf(stderr, UNREC_CREC, qt_line); - break; - } - num = get_hdr(code); - if (!num && !new_id(code)) - break; - num = get_hdr(code)-1; - if(known_msg(num, id)) - Fprintf(stderr, DUP_MSG, qt_line); - else new_msg(s, num, id); - } - break; + case 'E': + if (!in_msg) { + Fprintf(stderr, END_NOT_IN_MSG, qt_line); + } else { + /* sets curr_msg->summary_size if applicable */ + (void) valid_qt_summary(s, TRUE); + in_msg = FALSE; + } + break; - case 'E': if(!in_msg) { - Fprintf(stderr, END_NOT_IN_MSG, qt_line); - } else { - /* sets curr_msg->summary_size if applicable */ - (void) valid_qt_summary(s, TRUE); - in_msg = FALSE; - } - break; - - default: Fprintf(stderr, UNREC_CREC, qt_line); - break; - } + default: + Fprintf(stderr, UNREC_CREC, qt_line); + break; + } } static void do_qt_text(s) - char *s; +char *s; { - if (!in_msg) { - Fprintf(stderr, TEXT_NOT_IN_MSG, qt_line); - } else if (!index(s, '\n')) { - Fprintf(stderr, TEXT_TRUNC, qt_line); - } + if (!in_msg) { + Fprintf(stderr, TEXT_NOT_IN_MSG, qt_line); + } else if (!index(s, '\n')) { + Fprintf(stderr, TEXT_TRUNC, qt_line); + } - curr_msg->size += strlen(s); - return; + curr_msg->size += strlen(s); + return; } static void adjust_qt_hdrs() { - int i, j; - long count = 0L, hdr_offset = sizeof(int) + - (sizeof(char)*LEN_HDR + sizeof(long)) * qt_hdr.n_hdr; + int i, j; + long count = 0L, hdr_offset = sizeof(int) + + (sizeof(char) * LEN_HDR + sizeof(long)) + * qt_hdr.n_hdr; - for(i = 0; i < qt_hdr.n_hdr; i++) { - qt_hdr.offset[i] = hdr_offset; - hdr_offset += sizeof(int) + sizeof(struct qtmsg) * msg_hdr[i].n_msg; - } + for (i = 0; i < qt_hdr.n_hdr; i++) { + qt_hdr.offset[i] = hdr_offset; + hdr_offset += sizeof(int) + sizeof(struct qtmsg) * msg_hdr[i].n_msg; + } - for(i = 0; i < qt_hdr.n_hdr; i++) - for(j = 0; j < msg_hdr[i].n_msg; j++) { - - msg_hdr[i].qt_msg[j].offset = hdr_offset + count; - count += msg_hdr[i].qt_msg[j].size - + msg_hdr[i].qt_msg[j].summary_size; - } - return; + for (i = 0; i < qt_hdr.n_hdr; i++) + for (j = 0; j < msg_hdr[i].n_msg; j++) { + msg_hdr[i].qt_msg[j].offset = hdr_offset + count; + count += + msg_hdr[i].qt_msg[j].size + msg_hdr[i].qt_msg[j].summary_size; + } + return; } static void put_qt_hdrs() { - int i; + int i; - /* - * The main header record. - */ - if (debug) Fprintf(stderr, "%ld: header info.\n", ftell(ofp)); - (void) fwrite((genericptr_t)&(qt_hdr.n_hdr), sizeof(int), 1, ofp); - (void) fwrite((genericptr_t)&(qt_hdr.id[0][0]), sizeof(char)*LEN_HDR, - qt_hdr.n_hdr, ofp); - (void) fwrite((genericptr_t)&(qt_hdr.offset[0]), sizeof(long), - qt_hdr.n_hdr, ofp); - if (debug) { - for(i = 0; i < qt_hdr.n_hdr; i++) - Fprintf(stderr, "%s @ %ld, ", qt_hdr.id[i], qt_hdr.offset[i]); - Fprintf(stderr, "\n"); - } + /* + * The main header record. + */ + if (debug) + Fprintf(stderr, "%ld: header info.\n", ftell(ofp)); + (void) fwrite((genericptr_t) & (qt_hdr.n_hdr), sizeof(int), 1, ofp); + (void) fwrite((genericptr_t) & (qt_hdr.id[0][0]), sizeof(char) * LEN_HDR, + qt_hdr.n_hdr, ofp); + (void) fwrite((genericptr_t) & (qt_hdr.offset[0]), sizeof(long), + qt_hdr.n_hdr, ofp); + if (debug) { + for (i = 0; i < qt_hdr.n_hdr; i++) + Fprintf(stderr, "%s @ %ld, ", qt_hdr.id[i], qt_hdr.offset[i]); + Fprintf(stderr, "\n"); + } - /* - * The individual class headers. - */ - for(i = 0; i < qt_hdr.n_hdr; i++) { - - if (debug) Fprintf(stderr, "%ld: %s header info.\n", ftell(ofp), - qt_hdr.id[i]); - (void) fwrite((genericptr_t)&(msg_hdr[i].n_msg), sizeof(int), - 1, ofp); - (void) fwrite((genericptr_t)&(msg_hdr[i].qt_msg[0]), - sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp); - if (debug) { int j; - for(j = 0; j < msg_hdr[i].n_msg; j++) { - Fprintf(stderr, "msg %d @ %ld (%ld)", - msg_hdr[i].qt_msg[j].msgnum, - msg_hdr[i].qt_msg[j].offset, - msg_hdr[i].qt_msg[j].size); - if (msg_hdr[i].qt_msg[j].summary_size) - Fprintf(stderr, " [%ld]", - msg_hdr[i].qt_msg[j].summary_size); - Fprintf(stderr, "\n"); - } - } - } + /* + * The individual class headers. + */ + for (i = 0; i < qt_hdr.n_hdr; i++) { + if (debug) + Fprintf(stderr, "%ld: %s header info.\n", ftell(ofp), + qt_hdr.id[i]); + (void) fwrite((genericptr_t) & (msg_hdr[i].n_msg), sizeof(int), 1, + ofp); + (void) fwrite((genericptr_t) & (msg_hdr[i].qt_msg[0]), + sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp); + if (debug) { + int j; + for (j = 0; j < msg_hdr[i].n_msg; j++) { + Fprintf( + stderr, "msg %d @ %ld (%ld)", msg_hdr[i].qt_msg[j].msgnum, + msg_hdr[i].qt_msg[j].offset, msg_hdr[i].qt_msg[j].size); + if (msg_hdr[i].qt_msg[j].summary_size) + Fprintf(stderr, " [%ld]", + msg_hdr[i].qt_msg[j].summary_size); + Fprintf(stderr, "\n"); + } + } + } } void do_questtxt() { - Sprintf(filename, DATA_IN_TEMPLATE, QTXT_I_FILE); - if(!(ifp = fopen(filename, RDTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } + Sprintf(filename, DATA_IN_TEMPLATE, QTXT_I_FILE); + if (!(ifp = fopen(filename, RDTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename, file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), DATA_TEMPLATE, QTXT_O_FILE); - if(!(ofp = fopen(filename, WRBMODE))) { - perror(filename); - Fclose(ifp); - exit(EXIT_FAILURE); - } + Sprintf(eos(filename), DATA_TEMPLATE, QTXT_O_FILE); + if (!(ofp = fopen(filename, WRBMODE))) { + perror(filename); + Fclose(ifp); + exit(EXIT_FAILURE); + } - qt_hdr.n_hdr = 0; - qt_line = 0; - in_msg = FALSE; + qt_hdr.n_hdr = 0; + qt_line = 0; + in_msg = FALSE; - while (fgets(in_line, QTEXT_IN_SIZ, ifp) != 0) { - SpinCursor (3); + while (fgets(in_line, QTEXT_IN_SIZ, ifp) != 0) { + SpinCursor(3); - qt_line++; - if(qt_control(in_line)) do_qt_control(in_line); - else if(qt_comment(in_line)) continue; - else do_qt_text(in_line); - } + qt_line++; + if (qt_control(in_line)) + do_qt_control(in_line); + else if (qt_comment(in_line)) + continue; + else + do_qt_text(in_line); + } - (void) rewind(ifp); - in_msg = FALSE; - adjust_qt_hdrs(); - put_qt_hdrs(); - while (fgets(in_line, QTEXT_IN_SIZ, ifp) != 0) { + (void) rewind(ifp); + in_msg = FALSE; + adjust_qt_hdrs(); + put_qt_hdrs(); + while (fgets(in_line, QTEXT_IN_SIZ, ifp) != 0) { + if (qt_control(in_line)) { + char *summary_p = 0; - if(qt_control(in_line)) { - char *summary_p = 0; - - in_msg = (in_line[1] == 'C'); - if (!in_msg) summary_p = valid_qt_summary(in_line, FALSE); - /* don't write anything unless we've got a summary */ - if (!summary_p) continue; - /* we have summary text; replace raw %E record with it */ - Strcpy(in_line, summary_p); /* (guaranteed to fit) */ - } else if(qt_comment(in_line)) continue; - if (debug) Fprintf(stderr, "%ld: %s", ftell(stdout), in_line); - (void) fputs(xcrypt(in_line), ofp); - } - Fclose(ifp); - Fclose(ofp); - return; + in_msg = (in_line[1] == 'C'); + if (!in_msg) + summary_p = valid_qt_summary(in_line, FALSE); + /* don't write anything unless we've got a summary */ + if (!summary_p) + continue; + /* we have summary text; replace raw %E record with it */ + Strcpy(in_line, summary_p); /* (guaranteed to fit) */ + } else if (qt_comment(in_line)) + continue; + if (debug) + Fprintf(stderr, "%ld: %s", ftell(stdout), in_line); + (void) fputs(xcrypt(in_line), ofp); + } + Fclose(ifp); + Fclose(ofp); + return; } +static char temp[32]; -static char temp[32]; - -static char * -limit(name,pref) /* limit a name to 30 characters length */ -char *name; -int pref; +static char *limit(name, pref) /* limit a name to 30 characters length */ +char *name; +int pref; { - (void) strncpy(temp, name, pref ? 26 : 30); - temp[pref ? 26 : 30] = 0; - return temp; + (void) strncpy(temp, name, pref ? 26 : 30); + temp[pref ? 26 : 30] = 0; + return temp; } void do_objs() { - int i, sum = 0; - char *c, *objnam; - int nspell = 0; - int prefix = 0; - char class = '\0'; - boolean sumerr = FALSE; + int i, sum = 0; + char *c, *objnam; + int nspell = 0; + int prefix = 0; + char class = '\0'; + boolean sumerr = FALSE; - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX - Strcat(filename, file_prefix); + Strcat(filename, file_prefix); #endif - Sprintf(eos(filename), INCLUDE_TEMPLATE, ONAME_FILE); - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); - } - Fprintf(ofp,"/*\tSCCS Id: @(#)onames.h\t3.5\t2004/02/01 */\n\n"); - Fprintf(ofp,"%s",Dont_Edit_Code); - Fprintf(ofp,"#ifndef ONAMES_H\n#define ONAMES_H\n\n"); + Sprintf(eos(filename), INCLUDE_TEMPLATE, ONAME_FILE); + if (!(ofp = fopen(filename, WRTMODE))) { + perror(filename); + exit(EXIT_FAILURE); + } + Fprintf(ofp, "/*\tSCCS Id: @(#)onames.h\t3.5\t2004/02/01 */\n\n"); + Fprintf(ofp, "%s", Dont_Edit_Code); + Fprintf(ofp, "#ifndef ONAMES_H\n#define ONAMES_H\n\n"); - for(i = 0; !i || objects[i].oc_class != ILLOBJ_CLASS; i++) { - SpinCursor(3); + for (i = 0; !i || objects[i].oc_class != ILLOBJ_CLASS; i++) { + SpinCursor(3); - objects[i].oc_name_idx = objects[i].oc_descr_idx = i; /* init */ - if (!(objnam = tmpdup(OBJ_NAME(objects[i])))) continue; + objects[i].oc_name_idx = objects[i].oc_descr_idx = i; /* init */ + if (!(objnam = tmpdup(OBJ_NAME(objects[i])))) + continue; - /* make sure probabilities add up to 1000 */ - if(objects[i].oc_class != class) { - if (sum && sum != 1000) { - Fprintf(stderr, "prob error for class %d (%d%%)", - class, sum); - (void) fflush(stderr); - sumerr = TRUE; - } - class = objects[i].oc_class; - sum = 0; - } + /* make sure probabilities add up to 1000 */ + if (objects[i].oc_class != class) { + if (sum && sum != 1000) { + Fprintf(stderr, "prob error for class %d (%d%%)", class, sum); + (void) fflush(stderr); + sumerr = TRUE; + } + class = objects[i].oc_class; + sum = 0; + } - for (c = objnam; *c; c++) - if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A'); - else if (*c < 'A' || *c > 'Z') *c = '_'; + for (c = objnam; *c; c++) + if (*c >= 'a' && *c <= 'z') + *c -= (char) ('a' - 'A'); + else if (*c < 'A' || *c > 'Z') + *c = '_'; - switch (class) { - case WAND_CLASS: - Fprintf(ofp,"#define\tWAN_"); prefix = 1; break; - case RING_CLASS: - Fprintf(ofp,"#define\tRIN_"); prefix = 1; break; - case POTION_CLASS: - Fprintf(ofp,"#define\tPOT_"); prefix = 1; break; - case SPBOOK_CLASS: - Fprintf(ofp,"#define\tSPE_"); prefix = 1; nspell++; break; - case SCROLL_CLASS: - Fprintf(ofp,"#define\tSCR_"); prefix = 1; break; - case AMULET_CLASS: - /* avoid trouble with stupid C preprocessors */ - Fprintf(ofp,"#define\t"); - if(objects[i].oc_material == PLASTIC) { - Fprintf(ofp,"FAKE_AMULET_OF_YENDOR\t%d\n", i); - prefix = -1; - break; - } - break; - case GEM_CLASS: - /* avoid trouble with stupid C preprocessors */ - if(objects[i].oc_material == GLASS) { - Fprintf(ofp,"/* #define\t%s\t%d */\n", - objnam, i); - prefix = -1; - break; - } - default: - Fprintf(ofp,"#define\t"); - } - if (prefix >= 0) - Fprintf(ofp,"%s\t%d\n", limit(objnam, prefix), i); - prefix = 0; + switch (class) { + case WAND_CLASS: + Fprintf(ofp, "#define\tWAN_"); + prefix = 1; + break; + case RING_CLASS: + Fprintf(ofp, "#define\tRIN_"); + prefix = 1; + break; + case POTION_CLASS: + Fprintf(ofp, "#define\tPOT_"); + prefix = 1; + break; + case SPBOOK_CLASS: + Fprintf(ofp, "#define\tSPE_"); + prefix = 1; + nspell++; + break; + case SCROLL_CLASS: + Fprintf(ofp, "#define\tSCR_"); + prefix = 1; + break; + case AMULET_CLASS: + /* avoid trouble with stupid C preprocessors */ + Fprintf(ofp, "#define\t"); + if (objects[i].oc_material == PLASTIC) { + Fprintf(ofp, "FAKE_AMULET_OF_YENDOR\t%d\n", i); + prefix = -1; + break; + } + break; + case GEM_CLASS: + /* avoid trouble with stupid C preprocessors */ + if (objects[i].oc_material == GLASS) { + Fprintf(ofp, "/* #define\t%s\t%d */\n", objnam, i); + prefix = -1; + break; + } + default: + Fprintf(ofp, "#define\t"); + } + if (prefix >= 0) + Fprintf(ofp, "%s\t%d\n", limit(objnam, prefix), i); + prefix = 0; - sum += objects[i].oc_prob; - } + sum += objects[i].oc_prob; + } - /* check last set of probabilities */ - if (sum && sum != 1000) { - Fprintf(stderr, "prob error for class %d (%d%%)", class, sum); - (void) fflush(stderr); - sumerr = TRUE; - } + /* check last set of probabilities */ + if (sum && sum != 1000) { + Fprintf(stderr, "prob error for class %d (%d%%)", class, sum); + (void) fflush(stderr); + sumerr = TRUE; + } - Fprintf(ofp,"#define\tLAST_GEM\t(JADE)\n"); - Fprintf(ofp,"#define\tMAXSPELL\t%d\n", nspell+1); - Fprintf(ofp,"#define\tNUM_OBJECTS\t%d\n", i); + Fprintf(ofp, "#define\tLAST_GEM\t(JADE)\n"); + Fprintf(ofp, "#define\tMAXSPELL\t%d\n", nspell + 1); + Fprintf(ofp, "#define\tNUM_OBJECTS\t%d\n", i); - Fprintf(ofp, "\n/* Artifacts (unique objects) */\n\n"); + Fprintf(ofp, "\n/* Artifacts (unique objects) */\n\n"); - for (i = 1; artifact_names[i]; i++) { - SpinCursor(3); + for (i = 1; artifact_names[i]; i++) { + SpinCursor(3); - for (c = objnam = tmpdup(artifact_names[i]); *c; c++) - if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A'); - else if (*c < 'A' || *c > 'Z') *c = '_'; + for (c = objnam = tmpdup(artifact_names[i]); *c; c++) + if (*c >= 'a' && *c <= 'z') + *c -= (char) ('a' - 'A'); + else if (*c < 'A' || *c > 'Z') + *c = '_'; - if (!strncmp(objnam, "THE_", 4)) - objnam += 4; - /* fudge _platinum_ YENDORIAN EXPRESS CARD */ - if (!strncmp(objnam, "PLATINUM_", 9)) - objnam += 9; - Fprintf(ofp,"#define\tART_%s\t%d\n", limit(objnam, 1), i); - } + if (!strncmp(objnam, "THE_", 4)) + objnam += 4; + /* fudge _platinum_ YENDORIAN EXPRESS CARD */ + if (!strncmp(objnam, "PLATINUM_", 9)) + objnam += 9; + Fprintf(ofp, "#define\tART_%s\t%d\n", limit(objnam, 1), i); + } - Fprintf(ofp, "#define\tNROFARTIFACTS\t%d\n", i-1); - Fprintf(ofp,"\n#endif /* ONAMES_H */\n"); - Fclose(ofp); - if (sumerr) exit(EXIT_FAILURE); - return; + Fprintf(ofp, "#define\tNROFARTIFACTS\t%d\n", i - 1); + Fprintf(ofp, "\n#endif /* ONAMES_H */\n"); + Fclose(ofp); + if (sumerr) + exit(EXIT_FAILURE); + return; } static char * tmpdup(str) const char *str; { - static char buf[128]; + static char buf[128]; - if (!str) return (char *)0; - (void)strncpy(buf, str, 127); - return buf; + if (!str) + return (char *) 0; + (void) strncpy(buf, str, 127); + return buf; } static char * eos(str) char *str; { - while (*str) str++; + while (*str) + str++; return str; } @@ -2510,11 +2608,11 @@ do_vision() * Block the upper left corner (BLOCK_HEIGHTxBLOCK_WIDTH) */ for (i = 0; i < MAX_ROW; i++) - for (j = 0; j < MAX_COL; j++) - if (i < BLOCK_HEIGHT && j < BLOCK_WIDTH) - xclear[i][j] = '\000'; - else - xclear[i][j] = '\001'; + for (j = 0; j < MAX_COL; j++) + if (i < BLOCK_HEIGHT && j < BLOCK_WIDTH) + xclear[i][j] = '\000'; + else + xclear[i][j] = '\001'; #endif /* VISION_TABLES */ SpinCursor(3); @@ -2522,22 +2620,22 @@ do_vision() /* * create the include file, "vis_tab.h" */ - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX Strcat(filename, file_prefix); #endif Sprintf(filename, INCLUDE_TEMPLATE, VIS_TAB_H); if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - exit(EXIT_FAILURE); + perror(filename); + exit(EXIT_FAILURE); } - Fprintf(ofp,"%s",Dont_Edit_Code); - Fprintf(ofp,"#ifdef VISION_TABLES\n"); + Fprintf(ofp, "%s", Dont_Edit_Code); + Fprintf(ofp, "#ifdef VISION_TABLES\n"); #ifdef VISION_TABLES H_close_gen(); H_far_gen(); #endif /* VISION_TABLES */ - Fprintf(ofp,"\n#endif /* VISION_TABLES */\n"); + Fprintf(ofp, "\n#endif /* VISION_TABLES */\n"); Fclose(ofp); SpinCursor(3); @@ -2545,34 +2643,34 @@ do_vision() /* * create the source file, "vis_tab.c" */ - filename[0]='\0'; + filename[0] = '\0'; #ifdef FILE_PREFIX Strcat(filename, file_prefix); #endif Sprintf(filename, SOURCE_TEMPLATE, VIS_TAB_C); if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - Sprintf(filename, INCLUDE_TEMPLATE, VIS_TAB_H); - Unlink(filename); - exit(EXIT_FAILURE); + perror(filename); + Sprintf(filename, INCLUDE_TEMPLATE, VIS_TAB_H); + Unlink(filename); + exit(EXIT_FAILURE); } - Fprintf(ofp,"%s",Dont_Edit_Code); - Fprintf(ofp,"#include \"config.h\"\n"); - Fprintf(ofp,"#ifdef VISION_TABLES\n"); - Fprintf(ofp,"#include \"vis_tab.h\"\n"); + Fprintf(ofp, "%s", Dont_Edit_Code); + Fprintf(ofp, "#include \"config.h\"\n"); + Fprintf(ofp, "#ifdef VISION_TABLES\n"); + Fprintf(ofp, "#include \"vis_tab.h\"\n"); SpinCursor(3); #ifdef VISION_TABLES C_close_gen(); C_far_gen(); - Fprintf(ofp,"\nvoid vis_tab_init() { return; }\n"); + Fprintf(ofp, "\nvoid vis_tab_init() { return; }\n"); #endif /* VISION_TABLES */ SpinCursor(3); - Fprintf(ofp,"\n#endif /* VISION_TABLES */\n"); - Fprintf(ofp,"\n/*vis_tab.c*/\n"); + Fprintf(ofp, "\n#endif /* VISION_TABLES */\n"); + Fprintf(ofp, "\n/*vis_tab.c*/\n"); Fclose(ofp); return; @@ -2635,93 +2733,100 @@ do_vision() static void H_close_gen() { - Fprintf(ofp,"\n/* Close */\n"); - Fprintf(ofp,"#define CLOSE_MAX_SB_DY %2d\t/* |src row - block row| - 1\t*/\n", - TEST_HEIGHT-1); - Fprintf(ofp,"#define CLOSE_MAX_SB_DX %2d\t/* |src col - block col|\t*/\n", - TEST_WIDTH); - Fprintf(ofp,"#define CLOSE_MAX_BC_DY %2d\t/* |block row - check row|\t*/\n", - TEST_HEIGHT); - Fprintf(ofp,"typedef struct {\n"); - Fprintf(ofp," unsigned char close[CLOSE_MAX_SB_DX][CLOSE_MAX_BC_DY];\n"); - Fprintf(ofp,"} close2d;\n"); - Fprintf(ofp,"extern close2d close_table[CLOSE_MAX_SB_DY];\n"); + Fprintf(ofp, "\n/* Close */\n"); + Fprintf(ofp, + "#define CLOSE_MAX_SB_DY %2d\t/* |src row - block row| - 1\t*/\n", + TEST_HEIGHT - 1); + Fprintf(ofp, + "#define CLOSE_MAX_SB_DX %2d\t/* |src col - block col|\t*/\n", + TEST_WIDTH); + Fprintf(ofp, + "#define CLOSE_MAX_BC_DY %2d\t/* |block row - check row|\t*/\n", + TEST_HEIGHT); + Fprintf(ofp, "typedef struct {\n"); + Fprintf(ofp, + " unsigned char close[CLOSE_MAX_SB_DX][CLOSE_MAX_BC_DY];\n"); + Fprintf(ofp, "} close2d;\n"); + Fprintf(ofp, "extern close2d close_table[CLOSE_MAX_SB_DY];\n"); return; } static void H_far_gen() { - Fprintf(ofp,"\n/* Far */\n"); - Fprintf(ofp,"#define FAR_MAX_SB_DY %2d\t/* |src row - block row|\t*/\n", - TEST_HEIGHT); - Fprintf(ofp,"#define FAR_MAX_SB_DX %2d\t/* |src col - block col| - 1\t*/\n", - TEST_WIDTH-1); - Fprintf(ofp,"#define FAR_MAX_BC_DY %2d\t/* |block row - check row| - 1\t*/\n", - TEST_HEIGHT-1); - Fprintf(ofp,"typedef struct {\n"); - Fprintf(ofp," unsigned char far_q[FAR_MAX_SB_DX][FAR_MAX_BC_DY];\n"); - Fprintf(ofp,"} far2d;\n"); - Fprintf(ofp,"extern far2d far_table[FAR_MAX_SB_DY];\n"); + Fprintf(ofp, "\n/* Far */\n"); + Fprintf(ofp, "#define FAR_MAX_SB_DY %2d\t/* |src row - block row|\t*/\n", + TEST_HEIGHT); + Fprintf(ofp, + "#define FAR_MAX_SB_DX %2d\t/* |src col - block col| - 1\t*/\n", + TEST_WIDTH - 1); + Fprintf(ofp, + "#define FAR_MAX_BC_DY %2d\t/* |block row - check row| - 1\t*/\n", + TEST_HEIGHT - 1); + Fprintf(ofp, "typedef struct {\n"); + Fprintf(ofp, " unsigned char far_q[FAR_MAX_SB_DX][FAR_MAX_BC_DY];\n"); + Fprintf(ofp, "} far2d;\n"); + Fprintf(ofp, "extern far2d far_table[FAR_MAX_SB_DY];\n"); return; } static void C_close_gen() { - int i,dx,dy; - int src_row, src_col; /* source */ - int block_row, block_col; /* block */ + int i, dx, dy; + int src_row, src_col; /* source */ + int block_row, block_col; /* block */ int this_row; int no_more; const char *delim; - block_row = BLOCK_HEIGHT-1; - block_col = BLOCK_WIDTH-1; + block_row = BLOCK_HEIGHT - 1; + block_col = BLOCK_WIDTH - 1; - Fprintf(ofp,"\n#ifndef FAR_TABLE_ONLY\n"); - Fprintf(ofp,"\nclose2d close_table[CLOSE_MAX_SB_DY] = {\n"); + Fprintf(ofp, "\n#ifndef FAR_TABLE_ONLY\n"); + Fprintf(ofp, "\nclose2d close_table[CLOSE_MAX_SB_DY] = {\n"); #ifndef no_vision_progress - Fprintf(stderr,"\nclose:"); + Fprintf(stderr, "\nclose:"); #endif for (dy = 1; dy < TEST_HEIGHT; dy++) { - src_row = block_row + dy; - Fprintf(ofp, "/* DY = %2d (- 1)*/\n {{\n", dy); + src_row = block_row + dy; + Fprintf(ofp, "/* DY = %2d (- 1)*/\n {{\n", dy); #ifndef no_vision_progress - Fprintf(stderr," %2d",dy), (void)fflush(stderr); + Fprintf(stderr, " %2d", dy), (void) fflush(stderr); #endif - for (dx = 0; dx < TEST_WIDTH; dx++) { - src_col = block_col - dx; - Fprintf(ofp, " /*%2d*/ {", dx); + for (dx = 0; dx < TEST_WIDTH; dx++) { + src_col = block_col - dx; + Fprintf(ofp, " /*%2d*/ {", dx); - no_more = 0; - for (this_row = 0; this_row < TEST_HEIGHT; this_row++) { - delim = (this_row < TEST_HEIGHT - 1) ? "," : ""; - if (no_more) { - Fprintf(ofp, "%s%s", CLOSE_OFF_TABLE_STRING, delim); - continue; - } - SpinCursor(3); + no_more = 0; + for (this_row = 0; this_row < TEST_HEIGHT; this_row++) { + delim = (this_row < TEST_HEIGHT - 1) ? "," : ""; + if (no_more) { + Fprintf(ofp, "%s%s", CLOSE_OFF_TABLE_STRING, delim); + continue; + } + SpinCursor(3); - /* Find the first column that we can see. */ - for (i = block_col+1; i < MAX_COL; i++) { - if (clear_path(src_row,src_col,block_row-this_row,i)) - break; - } + /* Find the first column that we can see. */ + for (i = block_col + 1; i < MAX_COL; i++) { + if (clear_path(src_row, src_col, block_row - this_row, i)) + break; + } - if (i == MAX_COL) no_more = 1; - Fprintf(ofp, "%2d%s", i - block_col, delim); - } - Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n"); - } - Fprintf(ofp," }},\n"); + if (i == MAX_COL) + no_more = 1; + Fprintf(ofp, "%2d%s", i - block_col, delim); + } + Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n"); + } + Fprintf(ofp, " }},\n"); } - Fprintf(ofp,"}; /* close_table[] */\n"); /* closing brace for table */ - Fprintf(ofp,"#endif /* !FAR_TABLE_ONLY */\n"); + Fprintf(ofp, "}; /* close_table[] */\n"); /* closing brace for table */ + Fprintf(ofp, "#endif /* !FAR_TABLE_ONLY */\n"); #ifndef no_vision_progress - Fprintf(stderr,"\n"); + Fprintf(stderr, "\n"); #endif return; } @@ -2729,55 +2834,56 @@ C_close_gen() static void C_far_gen() { - int i,dx,dy; - int src_row, src_col; /* source */ - int block_row, block_col; /* block */ + int i, dx, dy; + int src_row, src_col; /* source */ + int block_row, block_col; /* block */ int this_row; const char *delim; - block_row = BLOCK_HEIGHT-1; - block_col = BLOCK_WIDTH-1; + block_row = BLOCK_HEIGHT - 1; + block_col = BLOCK_WIDTH - 1; - Fprintf(ofp,"\n#ifndef CLOSE_TABLE_ONLY\n"); - Fprintf(ofp,"\nfar2d far_table[FAR_MAX_SB_DY] = {\n"); + Fprintf(ofp, "\n#ifndef CLOSE_TABLE_ONLY\n"); + Fprintf(ofp, "\nfar2d far_table[FAR_MAX_SB_DY] = {\n"); #ifndef no_vision_progress - Fprintf(stderr,"\n_far_:"); + Fprintf(stderr, "\n_far_:"); #endif for (dy = 0; dy < TEST_HEIGHT; dy++) { - src_row = block_row - dy; - Fprintf(ofp, "/* DY = %2d */\n {{\n", dy); + src_row = block_row - dy; + Fprintf(ofp, "/* DY = %2d */\n {{\n", dy); #ifndef no_vision_progress - Fprintf(stderr," %2d",dy), (void)fflush(stderr); + Fprintf(stderr, " %2d", dy), (void) fflush(stderr); #endif - for (dx = 1; dx < TEST_WIDTH; dx++) { - src_col = block_col + dx; - Fprintf(ofp, " /*%2d(-1)*/ {", dx); + for (dx = 1; dx < TEST_WIDTH; dx++) { + src_col = block_col + dx; + Fprintf(ofp, " /*%2d(-1)*/ {", dx); - for (this_row = block_row+1; this_row < block_row+TEST_HEIGHT; - this_row++) { - delim = (this_row < block_row + TEST_HEIGHT - 1) ? "," : ""; + for (this_row = block_row + 1; this_row < block_row + TEST_HEIGHT; + this_row++) { + delim = (this_row < block_row + TEST_HEIGHT - 1) ? "," : ""; - SpinCursor(3); - /* Find first col that we can see. */ - for (i = 0; i <= block_col; i++) { - if (clear_path(src_row,src_col,this_row,i)) break; - } + SpinCursor(3); + /* Find first col that we can see. */ + for (i = 0; i <= block_col; i++) { + if (clear_path(src_row, src_col, this_row, i)) + break; + } - if (block_col-i < 0) - Fprintf(ofp, "%s%s", FAR_OFF_TABLE_STRING, delim); - else - Fprintf(ofp, "%2d%s", block_col - i, delim); - } - Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n"); - } - Fprintf(ofp," }},\n"); + if (block_col - i < 0) + Fprintf(ofp, "%s%s", FAR_OFF_TABLE_STRING, delim); + else + Fprintf(ofp, "%2d%s", block_col - i, delim); + } + Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n"); + } + Fprintf(ofp, " }},\n"); } - Fprintf(ofp,"}; /* far_table[] */\n"); /* closing brace for table */ - Fprintf(ofp,"#endif /* !CLOSE_TABLE_ONLY */\n"); + Fprintf(ofp, "}; /* far_table[] */\n"); /* closing brace for table */ + Fprintf(ofp, "#endif /* !CLOSE_TABLE_ONLY */\n"); #ifndef no_vision_progress - Fprintf(stderr,"\n"); + Fprintf(stderr, "\n"); #endif return; } @@ -2797,61 +2903,70 @@ C_far_gen() * same row as the hero. */ static int -clear_path(you_row,you_col,y2,x2) - int you_row, you_col, y2, x2; +clear_path(you_row, you_col, y2, x2) +int you_row, you_col, y2, x2; { int dx, dy, s1, s2; register int i, error, x, y, dxs, dys; - x = you_col; y = you_row; - dx = abs(x2-you_col); dy = abs(y2-you_row); - s1 = sign(x2-you_col); s2 = sign(y2-you_row); + x = you_col; + y = you_row; + dx = abs(x2 - you_col); + dy = abs(y2 - you_row); + s1 = sign(x2 - you_col); + s2 = sign(y2 - you_row); - if (s1 == 0) { /* same column */ - if (s2 == 1) { /* below (larger y2 value) */ - for (i = you_row+1; i < y2; i++) - if (!xclear[i][you_col]) return 0; - } else { /* above (smaller y2 value) */ - for (i = y2+1; i < you_row; i++) - if (!xclear[i][you_col]) return 0; - } - return 1; + if (s1 == 0) { /* same column */ + if (s2 == 1) { /* below (larger y2 value) */ + for (i = you_row + 1; i < y2; i++) + if (!xclear[i][you_col]) + return 0; + } else { /* above (smaller y2 value) */ + for (i = y2 + 1; i < you_row; i++) + if (!xclear[i][you_col]) + return 0; + } + return 1; } /* * Lines at 0 and 90 degrees have been weeded out. */ if (dy > dx) { - error = dx; dx = dy; dy = error; /* swap the values */ - dxs = dx << 1; /* save the shifted values */ - dys = dy << 1; - error = dys - dx; /* NOTE: error is used as a temporary above */ + error = dx; + dx = dy; + dy = error; /* swap the values */ + dxs = dx << 1; /* save the shifted values */ + dys = dy << 1; + error = dys - dx; /* NOTE: error is used as a temporary above */ - for (i = 0; i < dx; i++) { - if (!xclear[y][x]) return 0; /* plot point */ + for (i = 0; i < dx; i++) { + if (!xclear[y][x]) + return 0; /* plot point */ - while (error >= 0) { - x += s1; - error -= dxs; - } - y += s2; - error += dys; - } + while (error >= 0) { + x += s1; + error -= dxs; + } + y += s2; + error += dys; + } } else { - dxs = dx << 1; /* save the shifted values */ - dys = dy << 1; - error = dys - dx; + dxs = dx << 1; /* save the shifted values */ + dys = dy << 1; + error = dys - dx; - for (i = 0; i < dx; i++) { - if (!xclear[y][x]) return 0; /* plot point */ + for (i = 0; i < dx; i++) { + if (!xclear[y][x]) + return 0; /* plot point */ - while (error >= 0) { - y += s2; - error -= dxs; - } - x += s1; - error += dys; - } + while (error >= 0) { + y += s2; + error -= dxs; + } + x += s1; + error += dys; + } } return 1; } @@ -2859,9 +2974,9 @@ clear_path(you_row,you_col,y2,x2) #ifdef STRICT_REF_DEF NEARDATA struct flag flags; -# ifdef ATTRIB_H +#ifdef ATTRIB_H struct attribs attrmax, attrmin; -# endif +#endif #endif /* STRICT_REF_DEF */ /*makedefs.c*/ diff --git a/util/panic.c b/util/panic.c index 577438800..84c6d3fd1 100644 --- a/util/panic.c +++ b/util/panic.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 panic.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 panic.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 panic.c $Date: 2009/05/06 10:54:39 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)panic.c 3.5 1994/03/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -21,30 +21,30 @@ extern void NDECL(vms_abort); /*VARARGS1*/ boolean panicking; -void VDECL(panic, (char *,...)); +void VDECL(panic, (char *, ...)); -void -panic VA_DECL(char *,str) - VA_START(str); - VA_INIT(str, char *); - if(panicking++) +void panic +VA_DECL(char *, str) + VA_START(str); + VA_INIT(str, char *); + if (panicking++) #ifdef SYSV - (void) + (void) #endif - abort(); /* avoid loops - this should never happen*/ + abort(); /* avoid loops - this should never happen*/ - (void) fputs(" ERROR: ", stderr); - Vfprintf(stderr, str, VA_ARGS); - (void) fflush(stderr); + (void) fputs(" ERROR: ", stderr); + Vfprintf(stderr, str, VA_ARGS); + (void) fflush(stderr); #if defined(UNIX) || defined(VMS) -# ifdef SYSV - (void) -# endif - abort(); /* generate core dump */ +#ifdef SYSV + (void) #endif - VA_END(); - exit(EXIT_FAILURE); /* redundant */ - return; + abort(); /* generate core dump */ +#endif + VA_END(); + exit(EXIT_FAILURE); /* redundant */ + return; } #ifdef ALLOCA_HACK @@ -53,10 +53,11 @@ panic VA_DECL(char *,str) * have it then just use malloc() instead. This may not work on some * systems, but they should either use yacc or get a real alloca routine. */ -long *alloca(cnt) +long * +alloca(cnt) unsigned cnt; { - return cnt ? alloc(cnt) : (long *)0; + return cnt ? alloc(cnt) : (long *) 0; } #endif diff --git a/util/recover.c b/util/recover.c index 07e691003..f2de9b293 100644 --- a/util/recover.c +++ b/util/recover.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 recover.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 recover.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 recover.c $Date: 2009/05/06 10:54:40 $ $Revision: 1.11 $ */ /* SCCS Id: @(#)recover.c 3.5 1999/10/23 */ /* Copyright (c) Janet Walz, 1992. */ @@ -19,37 +19,37 @@ #endif #ifdef VMS -extern int FDECL(vms_creat, (const char *,unsigned)); -extern int FDECL(vms_open, (const char *,int,unsigned)); -#endif /* VMS */ +extern int FDECL(vms_creat, (const char *, unsigned)); +extern int FDECL(vms_open, (const char *, int, unsigned)); +#endif /* VMS */ int FDECL(restore_savefile, (char *)); void FDECL(set_levelfile_name, (int)); int FDECL(open_levelfile, (int)); int NDECL(create_savefile); -void FDECL(copy_bytes, (int,int)); +void FDECL(copy_bytes, (int, int)); #ifndef WIN_CE -#define Fprintf (void)fprintf +#define Fprintf (void) fprintf #else -#define Fprintf (void)nhce_message -static void nhce_message(FILE*, const char*, ...); +#define Fprintf (void) nhce_message +static void nhce_message(FILE *, const char *, ...); #endif -#define Close (void)close +#define Close (void) close #ifdef UNIX -#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */ +#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */ #else -# ifdef VMS -#define SAVESIZE (PL_NSIZ + 22) /* [.save]player.e;1 */ -# else -# ifdef WIN32 -#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */ -# else -#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */ -# endif -# endif +#ifdef VMS +#define SAVESIZE (PL_NSIZ + 22) /* [.save]player.e;1 */ +#else +#ifdef WIN32 +#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */ +#else +#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */ +#endif +#endif #endif #if defined(EXEPATH) @@ -59,89 +59,96 @@ char *FDECL(exepath, (char *)); #if defined(__BORLANDC__) && !defined(_WIN32) extern unsigned _stklen = STKSIZ; #endif -char savename[SAVESIZE]; /* holds relative path of save file from playground */ - +char + savename[SAVESIZE]; /* holds relative path of save file from playground */ int main(argc, argv) int argc; char *argv[]; { - int argno; - const char *dir = (char *)0; + int argno; + const char *dir = (char *) 0; #ifdef AMIGA - char *startdir = (char *)0; + char *startdir = (char *) 0; #endif - - if (!dir) dir = getenv("NETHACKDIR"); - if (!dir) dir = getenv("HACKDIR"); + if (!dir) + dir = getenv("NETHACKDIR"); + if (!dir) + dir = getenv("HACKDIR"); #if defined(EXEPATH) - if (!dir) dir = exepath(argv[0]); + if (!dir) + dir = exepath(argv[0]); #endif - if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) { - Fprintf(stderr, - "Usage: %s [ -d directory ] base1 [ base2 ... ]\n", argv[0]); + if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) { + Fprintf(stderr, "Usage: %s [ -d directory ] base1 [ base2 ... ]\n", + argv[0]); #if defined(WIN32) || defined(MSDOS) - if (dir) { - Fprintf(stderr, "\t(Unless you override it with -d, recover will look \n"); - Fprintf(stderr, "\t in the %s directory on your system)\n", dir); - } + if (dir) { + Fprintf( + stderr, + "\t(Unless you override it with -d, recover will look \n"); + Fprintf(stderr, "\t in the %s directory on your system)\n", dir); + } #endif - exit(EXIT_FAILURE); - } + exit(EXIT_FAILURE); + } - argno = 1; - if (!strncmp(argv[argno], "-d", 2)) { - dir = argv[argno]+2; - if (*dir == '=' || *dir == ':') dir++; - if (!*dir && argc > argno) { - argno++; - dir = argv[argno]; - } - if (!*dir) { - Fprintf(stderr, - "%s: flag -d must be followed by a directory name.\n", - argv[0]); - exit(EXIT_FAILURE); - } - argno++; - } + argno = 1; + if (!strncmp(argv[argno], "-d", 2)) { + dir = argv[argno] + 2; + if (*dir == '=' || *dir == ':') + dir++; + if (!*dir && argc > argno) { + argno++; + dir = argv[argno]; + } + if (!*dir) { + Fprintf(stderr, + "%s: flag -d must be followed by a directory name.\n", + argv[0]); + exit(EXIT_FAILURE); + } + argno++; + } #if defined(SECURE) && !defined(VMS) - if (dir -# ifdef HACKDIR - && strcmp(dir, HACKDIR) -# endif - ) { - (void) setgid(getgid()); - (void) setuid(getuid()); - } -#endif /* SECURE && !VMS */ + if (dir +#ifdef HACKDIR + && strcmp(dir, HACKDIR) +#endif + ) { + (void) setgid(getgid()); + (void) setuid(getuid()); + } +#endif /* SECURE && !VMS */ #ifdef HACKDIR - if (!dir) dir = HACKDIR; + if (!dir) + dir = HACKDIR; #endif #ifdef AMIGA - startdir = getcwd(0,255); + startdir = getcwd(0, 255); #endif - if (dir && chdir((char *) dir) < 0) { - Fprintf(stderr, "%s: cannot chdir to %s.\n", argv[0], dir); - exit(EXIT_FAILURE); - } + if (dir && chdir((char *) dir) < 0) { + Fprintf(stderr, "%s: cannot chdir to %s.\n", argv[0], dir); + exit(EXIT_FAILURE); + } - while (argc > argno) { - if (restore_savefile(argv[argno]) == 0) - Fprintf(stderr, "recovered \"%s\" to %s\n", - argv[argno], savename); - argno++; - } + while (argc > argno) { + if (restore_savefile(argv[argno]) == 0) + Fprintf(stderr, "recovered \"%s\" to %s\n", argv[argno], + savename); + argno++; + } #ifdef AMIGA - if (startdir) (void)chdir(startdir); + if (startdir) + (void) chdir(startdir); #endif - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } static char lock[256]; @@ -150,13 +157,14 @@ void set_levelfile_name(lev) int lev; { - char *tf; + char *tf; - tf = rindex(lock, '.'); - if (!tf) tf = lock + strlen(lock); - (void) sprintf(tf, ".%d", lev); + tf = rindex(lock, '.'); + if (!tf) + tf = lock + strlen(lock); + (void) sprintf(tf, ".%d", lev); #ifdef VMS - (void) strcat(tf, ";1"); + (void) strcat(tf, ";1"); #endif } @@ -164,200 +172,197 @@ int open_levelfile(lev) int lev; { - int fd; + int fd; - set_levelfile_name(lev); + set_levelfile_name(lev); #if defined(MICRO) || defined(WIN32) || defined(MSDOS) - fd = open(lock, O_RDONLY | O_BINARY); + fd = open(lock, O_RDONLY | O_BINARY); #else - fd = open(lock, O_RDONLY, 0); + fd = open(lock, O_RDONLY, 0); #endif - return fd; + return fd; } int create_savefile() { - int fd; + int fd; #if defined(MICRO) || defined(WIN32) || defined(MSDOS) - fd = open(savename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); + fd = open(savename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); #else - fd = creat(savename, FCMASK); + fd = creat(savename, FCMASK); #endif - return fd; + return fd; } void copy_bytes(ifd, ofd) int ifd, ofd; { - char buf[BUFSIZ]; - int nfrom, nto; + char buf[BUFSIZ]; + int nfrom, nto; - do { - nfrom = read(ifd, buf, BUFSIZ); - nto = write(ofd, buf, nfrom); - if (nto != nfrom) { - Fprintf(stderr, "file copy failed!\n"); - exit(EXIT_FAILURE); - } - } while (nfrom == BUFSIZ); + do { + nfrom = read(ifd, buf, BUFSIZ); + nto = write(ofd, buf, nfrom); + if (nto != nfrom) { + Fprintf(stderr, "file copy failed!\n"); + exit(EXIT_FAILURE); + } + } while (nfrom == BUFSIZ); } int restore_savefile(basename) char *basename; { - int gfd, lfd, sfd; - int lev, savelev, hpid, pltmpsiz; - xchar levc; - struct version_info version_data; - struct savefile_info sfi; - char plbuf[PL_NSIZ]; + int gfd, lfd, sfd; + int lev, savelev, hpid, pltmpsiz; + xchar levc; + struct version_info version_data; + struct savefile_info sfi; + char plbuf[PL_NSIZ]; - /* level 0 file contains: - * pid of creating process (ignored here) - * level number for current level of save file - * name of save file nethack would have created - * savefile info - * player name - * and game state - */ - (void) strcpy(lock, basename); - gfd = open_levelfile(0); - if (gfd < 0) { + /* level 0 file contains: + * pid of creating process (ignored here) + * level number for current level of save file + * name of save file nethack would have created + * savefile info + * player name + * and game state + */ + (void) strcpy(lock, basename); + gfd = open_levelfile(0); + if (gfd < 0) { #if defined(WIN32) && !defined(WIN_CE) - if(errno == EACCES) { - Fprintf(stderr, - "\nThere are files from a game in progress under your name."); - Fprintf(stderr,"\nThe files are locked or inaccessible."); - Fprintf(stderr,"\nPerhaps the other game is still running?\n"); - } else - Fprintf(stderr, - "\nTrouble accessing level 0 (errno = %d).\n", errno); + if (errno == EACCES) { + Fprintf( + stderr, + "\nThere are files from a game in progress under your name."); + Fprintf(stderr, "\nThe files are locked or inaccessible."); + Fprintf(stderr, "\nPerhaps the other game is still running?\n"); + } else + Fprintf(stderr, "\nTrouble accessing level 0 (errno = %d).\n", + errno); #endif - Fprintf(stderr, "Cannot open level 0 for %s.\n", basename); - return(-1); - } - if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) { - Fprintf(stderr, "%s\n%s%s%s\n", - "Checkpoint data incompletely written or subsequently clobbered;", - "recovery for \"", basename, "\" impossible."); - Close(gfd); - return(-1); - } - if (read(gfd, (genericptr_t) &savelev, sizeof(savelev)) - != sizeof(savelev)) { - Fprintf(stderr, - "Checkpointing was not in effect for %s -- recovery impossible.\n", - basename); - Close(gfd); - return(-1); - } - if ((read(gfd, (genericptr_t) savename, sizeof savename) - != sizeof savename) || - (read(gfd, (genericptr_t) &version_data, sizeof version_data) - != sizeof version_data) || - (read(gfd, (genericptr_t) &sfi, sizeof sfi) - != sizeof sfi) || - (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) - != sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ) || - (read(gfd, (genericptr_t) &plbuf, pltmpsiz) - != pltmpsiz)) { - Fprintf(stderr, "Error reading %s -- can't recover.\n", lock); - Close(gfd); - return(-1); - } + Fprintf(stderr, "Cannot open level 0 for %s.\n", basename); + return (-1); + } + if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) { + Fprintf( + stderr, "%s\n%s%s%s\n", + "Checkpoint data incompletely written or subsequently clobbered;", + "recovery for \"", basename, "\" impossible."); + Close(gfd); + return (-1); + } + if (read(gfd, (genericptr_t) &savelev, sizeof(savelev)) + != sizeof(savelev)) { + Fprintf(stderr, "Checkpointing was not in effect for %s -- recovery " + "impossible.\n", + basename); + Close(gfd); + return (-1); + } + if ((read(gfd, (genericptr_t) savename, sizeof savename) + != sizeof savename) + || (read(gfd, (genericptr_t) &version_data, sizeof version_data) + != sizeof version_data) + || (read(gfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi) + || (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) + != sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ) + || (read(gfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz)) { + Fprintf(stderr, "Error reading %s -- can't recover.\n", lock); + Close(gfd); + return (-1); + } - /* save file should contain: - * version info - * savefile info - * player name - * current level (including pets) - * (non-level-based) game state - * other levels - */ - sfd = create_savefile(); - if (sfd < 0) { - Fprintf(stderr, "Cannot create savefile %s.\n", savename); - Close(gfd); - return(-1); - } + /* save file should contain: + * version info + * savefile info + * player name + * current level (including pets) + * (non-level-based) game state + * other levels + */ + sfd = create_savefile(); + if (sfd < 0) { + Fprintf(stderr, "Cannot create savefile %s.\n", savename); + Close(gfd); + return (-1); + } - lfd = open_levelfile(savelev); - if (lfd < 0) { - Fprintf(stderr, "Cannot open level of save for %s.\n", basename); - Close(gfd); - Close(sfd); - return(-1); - } + lfd = open_levelfile(savelev); + if (lfd < 0) { + Fprintf(stderr, "Cannot open level of save for %s.\n", basename); + Close(gfd); + Close(sfd); + return (-1); + } - if (write(sfd, (genericptr_t) &version_data, sizeof version_data) - != sizeof version_data) { - Fprintf(stderr, "Error writing %s; recovery failed.\n", savename); - Close(gfd); - Close(sfd); - return(-1); - } + if (write(sfd, (genericptr_t) &version_data, sizeof version_data) + != sizeof version_data) { + Fprintf(stderr, "Error writing %s; recovery failed.\n", savename); + Close(gfd); + Close(sfd); + return (-1); + } - if (write(sfd, (genericptr_t) &sfi, sizeof sfi) - != sizeof sfi) { - Fprintf(stderr, - "Error writing %s; recovery failed (savefile_info).\n", - savename); - Close(gfd); - Close(sfd); - return(-1); - } + if (write(sfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi) { + Fprintf(stderr, + "Error writing %s; recovery failed (savefile_info).\n", + savename); + Close(gfd); + Close(sfd); + return (-1); + } - if (write(sfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) - != sizeof pltmpsiz) { - Fprintf(stderr, - "Error writing %s; recovery failed (player name size).\n", - savename); - Close(gfd); - Close(sfd); - return(-1); - } + if (write(sfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz) + != sizeof pltmpsiz) { + Fprintf(stderr, + "Error writing %s; recovery failed (player name size).\n", + savename); + Close(gfd); + Close(sfd); + return (-1); + } - if (write(sfd, (genericptr_t) &plbuf, pltmpsiz) - != pltmpsiz) { - Fprintf(stderr, - "Error writing %s; recovery failed (player name).\n", - savename); - Close(gfd); - Close(sfd); - return(-1); - } + if (write(sfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz) { + Fprintf(stderr, "Error writing %s; recovery failed (player name).\n", + savename); + Close(gfd); + Close(sfd); + return (-1); + } - copy_bytes(lfd, sfd); - Close(lfd); - (void) unlink(lock); + copy_bytes(lfd, sfd); + Close(lfd); + (void) unlink(lock); - copy_bytes(gfd, sfd); - Close(gfd); - set_levelfile_name(0); - (void) unlink(lock); + copy_bytes(gfd, sfd); + Close(gfd); + set_levelfile_name(0); + (void) unlink(lock); - for (lev = 1; lev < 256; lev++) { - /* level numbers are kept in xchars in save.c, so the - * maximum level number (for the endlevel) must be < 256 - */ - if (lev != savelev) { - lfd = open_levelfile(lev); - if (lfd >= 0) { - /* any or all of these may not exist */ - levc = (xchar) lev; - write(sfd, (genericptr_t) &levc, sizeof(levc)); - copy_bytes(lfd, sfd); - Close(lfd); - (void) unlink(lock); - } - } - } + for (lev = 1; lev < 256; lev++) { + /* level numbers are kept in xchars in save.c, so the + * maximum level number (for the endlevel) must be < 256 + */ + if (lev != savelev) { + lfd = open_levelfile(lev); + if (lfd >= 0) { + /* any or all of these may not exist */ + levc = (xchar) lev; + write(sfd, (genericptr_t) &levc, sizeof(levc)); + copy_bytes(lfd, sfd); + Close(lfd); + (void) unlink(lock); + } + } + } - Close(sfd); + Close(sfd); #if 0 /* OBSOLETE, HackWB is no longer in use */ #ifdef AMIGA @@ -379,44 +384,47 @@ char *basename; } #endif #endif - return(0); + return (0); } #ifdef EXEPATH -# ifdef __DJGPP__ +#ifdef __DJGPP__ #define PATH_SEPARATOR '/' -# else +#else #define PATH_SEPARATOR '\\' -# endif +#endif #define EXEPATHBUFSZ 256 char exepathbuf[EXEPATHBUFSZ]; -char *exepath(str) +char * +exepath(str) char *str; { - char *tmp, *tmp2; - int bsize; + char *tmp, *tmp2; + int bsize; - if (!str) return (char *)0; - bsize = EXEPATHBUFSZ; - tmp = exepathbuf; + if (!str) + return (char *) 0; + bsize = EXEPATHBUFSZ; + tmp = exepathbuf; #if !defined(WIN32) - strcpy (tmp, str); + strcpy(tmp, str); #else -# if defined(WIN_CE) - { - TCHAR wbuf[EXEPATHBUFSZ]; - GetModuleFileName((HANDLE)0, wbuf, EXEPATHBUFSZ); - NH_W2A(wbuf, tmp, bsize); - } -# else - *(tmp + GetModuleFileName((HANDLE)0, tmp, bsize)) = '\0'; -# endif +#if defined(WIN_CE) + { + TCHAR wbuf[EXEPATHBUFSZ]; + GetModuleFileName((HANDLE) 0, wbuf, EXEPATHBUFSZ); + NH_W2A(wbuf, tmp, bsize); + } +#else + *(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0'; #endif - tmp2 = strrchr(tmp, PATH_SEPARATOR); - if (tmp2) *tmp2 = '\0'; - return tmp; +#endif + tmp2 = strrchr(tmp, PATH_SEPARATOR); + if (tmp2) + *tmp2 = '\0'; + return tmp; } #endif /* EXEPATH */ @@ -426,17 +434,19 @@ const char amiga_version_string[] = AMIGA_VERSION_STRING; #endif #ifdef WIN_CE -void nhce_message(FILE* f, const char* str, ...) +void +nhce_message(FILE *f, const char *str, ...) { va_list ap; - TCHAR wbuf[NHSTR_BUFSIZE]; - char buf[NHSTR_BUFSIZE]; + TCHAR wbuf[NHSTR_BUFSIZE]; + char buf[NHSTR_BUFSIZE]; va_start(ap, str); - vsprintf(buf, str, ap); + vsprintf(buf, str, ap); va_end(ap); - MessageBox(NULL, NH_A2W(buf, wbuf, NHSTR_BUFSIZE), TEXT("Recover"), MB_OK); + MessageBox(NULL, NH_A2W(buf, wbuf, NHSTR_BUFSIZE), TEXT("Recover"), + MB_OK); } #endif diff --git a/win/X11/Window.c b/win/X11/Window.c index 8b9c0bba3..2360f09b5 100644 --- a/win/X11/Window.c +++ b/win/X11/Window.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 Window.c $NHDT-Date: 1430899134 2015/05/06 07:58:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ +/* NetHack 3.6 Window.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 Window.c $Date: 2009/05/06 10:55:43 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)Window.c 3.5 1993/02/02 */ /* Copyright (c) Dean Luick, 1992 */ @@ -10,10 +10,10 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif -#ifdef MSDOS /* from compiler */ +#ifdef MSDOS /* from compiler */ #define SHORT_FILENAMES #endif @@ -25,10 +25,10 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #include "xwindowp.h" @@ -40,60 +40,63 @@ static XtResource resources[] = { #define offset(field) XtOffset(WindowWidget, window.field) /* {name, class, type, size, offset, default_type, default_addr}, */ { nhStr(XtNrows), nhStr(XtCRows), XtRDimension, sizeof(Dimension), - offset(rows), XtRImmediate, (XtPointer) 21}, + offset(rows), XtRImmediate, (XtPointer) 21 }, { nhStr(XtNcolumns), nhStr(XtCColumns), XtRDimension, sizeof(Dimension), - offset(columns), XtRImmediate, (XtPointer) 80}, + offset(columns), XtRImmediate, (XtPointer) 80 }, { nhStr(XtNforeground), XtCForeground, XtRPixel, sizeof(Pixel), - offset(foreground), XtRString, (XtPointer) XtDefaultForeground }, + offset(foreground), XtRString, (XtPointer) XtDefaultForeground }, - { nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel), - offset(black), XtRString, (XtPointer) "black"}, - { nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel), - offset(red), XtRString, (XtPointer) "red" }, - { nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel), - offset(green), XtRString, (XtPointer) "pale green" }, - { nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel), - offset(brown), XtRString, (XtPointer) "brown" }, - { nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel), - offset(blue), XtRString, (XtPointer) "blue" }, - { nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel), - offset(magenta), XtRString, (XtPointer) "magenta" }, - { nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel), - offset(cyan), XtRString, (XtPointer) "light cyan" }, - { nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel), - offset(gray), XtRString, (XtPointer) "gray" }, - { nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel), - offset(orange), XtRString, (XtPointer) "orange" }, + { nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel), offset(black), + XtRString, (XtPointer) "black" }, + { nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel), offset(red), + XtRString, (XtPointer) "red" }, + { nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel), offset(green), + XtRString, (XtPointer) "pale green" }, + { nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel), offset(brown), + XtRString, (XtPointer) "brown" }, + { nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel), offset(blue), + XtRString, (XtPointer) "blue" }, + { nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel), offset(magenta), + XtRString, (XtPointer) "magenta" }, + { nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel), offset(cyan), + XtRString, (XtPointer) "light cyan" }, + { nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel), offset(gray), + XtRString, (XtPointer) "gray" }, + { nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel), offset(orange), + XtRString, (XtPointer) "orange" }, { nhStr(XtNbright_green), XtCColor, XtRPixel, sizeof(Pixel), - offset(bright_green), XtRString, (XtPointer) "green" }, - { nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel), - offset(yellow), XtRString, (XtPointer) "yellow" }, + offset(bright_green), XtRString, (XtPointer) "green" }, + { nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel), offset(yellow), + XtRString, (XtPointer) "yellow" }, { nhStr(XtNbright_blue), XtCColor, XtRPixel, sizeof(Pixel), - offset(bright_blue), XtRString, (XtPointer) "royal blue" }, + offset(bright_blue), XtRString, (XtPointer) "royal blue" }, { nhStr(XtNbright_magenta), XtCColor, XtRPixel, sizeof(Pixel), - offset(bright_magenta), XtRString, (XtPointer) "violet" }, + offset(bright_magenta), XtRString, (XtPointer) "violet" }, { nhStr(XtNbright_cyan), XtCColor, XtRPixel, sizeof(Pixel), - offset(bright_cyan), XtRString, (XtPointer) "cyan" }, - { nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel), - offset(white), XtRString, (XtPointer) "white" }, + offset(bright_cyan), XtRString, (XtPointer) "cyan" }, + { nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel), offset(white), + XtRString, (XtPointer) "white" }, { nhStr(XtNfont), XtCFont, XtRFontStruct, sizeof(XFontStruct *), - offset(font), XtRString, (XtPointer) XtDefaultFont }, - { nhStr(XtNexposeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList), - offset(expose_callback), XtRCallback, (char *)0 }, + offset(font), XtRString, (XtPointer) XtDefaultFont }, + { nhStr(XtNexposeCallback), XtCCallback, XtRCallback, + sizeof(XtCallbackList), offset(expose_callback), XtRCallback, + (char *) 0 }, { nhStr(XtNcallback), XtCCallback, XtRCallback, sizeof(XtCallbackList), - offset(input_callback), XtRCallback, (char *)0 }, - { nhStr(XtNresizeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList), - offset(resize_callback), XtRCallback, (char *)0 }, + offset(input_callback), XtRCallback, (char *) 0 }, + { nhStr(XtNresizeCallback), XtCCallback, XtRCallback, + sizeof(XtCallbackList), offset(resize_callback), XtRCallback, + (char *) 0 }, #undef offset }; /* ARGSUSED */ -static void no_op(w, event, params, num_params) - Widget w; /* unused */ - XEvent *event; /* unused */ - String *params; /* unused */ - Cardinal *num_params; /* unused */ +static void +no_op(w, event, params, num_params) +Widget w; /* unused */ +XEvent *event; /* unused */ +String *params; /* unused */ +Cardinal *num_params; /* unused */ { nhUse(w); nhUse(event); @@ -103,20 +106,19 @@ static void no_op(w, event, params, num_params) return; } -static XtActionsRec actions[] = -{ - { nhStr("no-op"), no_op }, +static XtActionsRec actions[] = { + { nhStr("no-op"), no_op }, }; -static char translations[] = -": input() \ +static char translations[] = ": input() \ "; /* ARGSUSED */ -static void Redisplay(w, event, region) - Widget w; - XEvent *event; - Region region; /* unused */ +static void +Redisplay(w, event, region) +Widget w; +XEvent *event; +Region region; /* unused */ { nhUse(region); @@ -125,57 +127,63 @@ static void Redisplay(w, event, region) } /* ARGSUSED */ -static void Resize(w) - Widget w; +static void +Resize(w) +Widget w; { XtCallCallbacks(w, XtNresizeCallback, (caddr_t) 0); } - WindowClassRec windowClassRec = { - { /* core fields */ - /* superclass */ (WidgetClass) &widgetClassRec, - /* class_name */ nhStr("Window"), - /* widget_size */ sizeof(WindowRec), - /* class_initialize */ 0, - /* class_part_initialize */ 0, - /* class_inited */ FALSE, - /* initialize */ 0, - /* initialize_hook */ 0, - /* realize */ XtInheritRealize, - /* actions */ actions, - /* num_actions */ XtNumber(actions), - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ 0, - /* resize */ Resize, - /* expose */ Redisplay, - /* set_values */ 0, - /* set_values_hook */ 0, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ 0, - /* accept_focus */ 0, - /* version */ XtVersion, - /* callback_private */ 0, - /* tm_table */ translations, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ 0 - }, - { /* window fields */ - /* empty */ 0 - } + { /* core fields */ + /* superclass */ (WidgetClass) &widgetClassRec, + /* class_name */ nhStr("Window"), + /* widget_size */ sizeof(WindowRec), + /* class_initialize */ 0, + /* class_part_initialize */ 0, + /* class_inited */ FALSE, + /* initialize */ 0, + /* initialize_hook */ 0, + /* realize */ XtInheritRealize, + /* actions */ actions, + /* num_actions */ XtNumber(actions), + /* resources */ resources, + /* num_resources */ XtNumber(resources), + /* xrm_class */ NULLQUARK, + /* compress_motion */ TRUE, + /* compress_exposure */ TRUE, + /* compress_enterleave */ TRUE, + /* visible_interest */ FALSE, + /* destroy */ 0, + /* resize */ Resize, + /* expose */ Redisplay, + /* set_values */ 0, + /* set_values_hook */ 0, + /* set_values_almost */ XtInheritSetValuesAlmost, + /* get_values_hook */ 0, + /* accept_focus */ 0, + /* version */ XtVersion, + /* callback_private */ 0, + /* tm_table */ translations, + /* query_geometry */ XtInheritQueryGeometry, + /* display_accelerator */ XtInheritDisplayAccelerator, + /* extension */ 0 }, + { /* window fields */ + /* empty */ 0 } }; -WidgetClass windowWidgetClass = (WidgetClass)&windowClassRec; +WidgetClass windowWidgetClass = (WidgetClass) &windowClassRec; Font -WindowFont(w) Widget w; { return ((WindowWidget)w)->window.font->fid; } +WindowFont(w) +Widget w; +{ + return ((WindowWidget) w)->window.font->fid; +} XFontStruct * -WindowFontStruct(w) Widget w; { return ((WindowWidget)w)->window.font; } +WindowFontStruct(w) +Widget w; +{ + return ((WindowWidget) w)->window.font; +} diff --git a/win/X11/dialogs.c b/win/X11/dialogs.c index 65732556b..915ea838b 100644 --- a/win/X11/dialogs.c +++ b/win/X11/dialogs.c @@ -14,7 +14,8 @@ * * THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE FOR + * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE + *FOR * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN @@ -48,12 +49,12 @@ * target type" issued by 'gcc -Wwrite-strings' as used by nethack. * (For this file, always the second parameter to XtSetArg().) * - * $NHDT-Date: 1430899133 2015/05/06 07:58:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $ + * $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ * $Date: 2002/03/31 17:11:23 $ $Revision: 1.2 $ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -66,26 +67,23 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif -#include "config.h" /* #define for const for non __STDC__ compilers */ -#include "lint.h" /* for nethack's nhStr() macro */ +#include "config.h" /* #define for const for non __STDC__ compilers */ +#include "lint.h" /* for nethack's nhStr() macro */ /* ":" added to both translations below to allow limited redefining of * keysyms before testing for keysym values -- dlc */ -static const char okay_accelerators[] = - "#override\n\ +static const char okay_accelerators[] = "#override\n\ :Return: set() notify() unset()\n"; -static const char cancel_accelerators[] = - "#override\n\ +static const char cancel_accelerators[] = "#override\n\ :Escape: set() notify() unset()\n\ - :[: set() notify() unset()\n"; /* for keyboards w/o an ESC */ - + :[: set() notify() unset()\n"; /* for keyboards w/o an ESC */ /* Create a dialog widget. It is just a form widget with * a label prompt @@ -95,99 +93,139 @@ static const char cancel_accelerators[] = */ Widget CreateDialog(parent, name, okay_callback, cancel_callback) - Widget parent; - String name; - XtCallbackProc okay_callback; - XtCallbackProc cancel_callback; +Widget parent; +String name; +XtCallbackProc okay_callback; +XtCallbackProc cancel_callback; { Widget form, prompt, response, okay, cancel; Arg args[20]; Cardinal num_args; - num_args = 0; + num_args = 0; #ifdef SPECIAL_CMAP if (special_cmap) { - XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++; + XtSetArg(args[num_args], nhStr(XtNbackground), white); + num_args++; } #endif - form = XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args); + form = + XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args); - num_args = 0; + num_args = 0; #ifdef SPECIAL_CMAP if (special_cmap) { - XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++; - XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++; + XtSetArg(args[num_args], nhStr(XtNforeground), black); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbackground), white); + num_args++; } #endif - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNborderWidth), 0); num_args++; - prompt = XtCreateManagedWidget("prompt", labelWidgetClass, - form, args, num_args); + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNborderWidth), 0); + num_args++; + prompt = XtCreateManagedWidget("prompt", labelWidgetClass, form, args, + num_args); - num_args = 0; + num_args = 0; #ifdef SPECIAL_CMAP if (special_cmap) { - XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++; - XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++; + XtSetArg(args[num_args], nhStr(XtNforeground), black); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbackground), white); + num_args++; } #endif - XtSetArg(args[num_args], nhStr(XtNfromVert), prompt); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit); num_args++; - XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth); num_args++; - XtSetArg(args[num_args], nhStr(XtNstring), ""); num_args++; - response = XtCreateManagedWidget("response", asciiTextWidgetClass, - form, args, num_args); + XtSetArg(args[num_args], nhStr(XtNfromVert), prompt); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth); + num_args++; + XtSetArg(args[num_args], nhStr(XtNstring), ""); + num_args++; + response = XtCreateManagedWidget("response", asciiTextWidgetClass, form, + args, num_args); - num_args = 0; + num_args = 0; #ifdef SPECIAL_CMAP if (special_cmap) { - XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++; - XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++; + XtSetArg(args[num_args], nhStr(XtNforeground), black); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbackground), white); + num_args++; } #endif - XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), response); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; XtSetArg(args[num_args], nhStr(XtNaccelerators), - XtParseAcceleratorTable(okay_accelerators)); num_args++; - okay = XtCreateManagedWidget("okay", commandWidgetClass, - form, args, num_args); + XtParseAcceleratorTable(okay_accelerators)); + num_args++; + okay = XtCreateManagedWidget("okay", commandWidgetClass, form, args, + num_args); XtAddCallback(okay, XtNcallback, okay_callback, form); /* Only create cancel button if there is a callback for it. */ if (cancel_callback) { - num_args = 0; + num_args = 0; #ifdef SPECIAL_CMAP - if (special_cmap) { - XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++; - XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++; - } + if (special_cmap) { + XtSetArg(args[num_args], nhStr(XtNforeground), black); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbackground), white); + num_args++; + } #endif - XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNaccelerators), - XtParseAcceleratorTable(cancel_accelerators)); num_args++; - cancel = XtCreateManagedWidget("cancel", commandWidgetClass, - form, args, num_args); - XtAddCallback(cancel, XtNcallback, cancel_callback, form); - XtInstallAccelerators(response, cancel); + XtSetArg(args[num_args], nhStr(XtNfromVert), response); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNaccelerators), + XtParseAcceleratorTable(cancel_accelerators)); + num_args++; + cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form, + args, num_args); + XtAddCallback(cancel, XtNcallback, cancel_callback, form); + XtInstallAccelerators(response, cancel); } XtInstallAccelerators(response, okay); @@ -217,8 +255,8 @@ GetDialogPrompt(w) /* set the prompt. This is used to put error information in the prompt */ void SetDialogPrompt(w, newprompt) - Widget w; - String newprompt; +Widget w; +String newprompt; { Arg args[1]; Widget label; @@ -231,7 +269,7 @@ SetDialogPrompt(w, newprompt) /* get what the user typed; caller must free the response */ String GetDialogResponse(w) - Widget w; +Widget w; { Arg args[1]; Widget response; @@ -243,12 +281,12 @@ GetDialogResponse(w) return XtNewString(s); } -#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) /* set the default reponse */ void SetDialogResponse(w, s) - Widget w; - String s; +Widget w; +String s; { Arg args[4]; Widget response; @@ -262,9 +300,9 @@ SetDialogResponse(w, s) XtSetArg(args[3], nhStr(XtNwidth), &width); XtGetValues(response, args, FOUR); /* width includes margins as per Xaw documentation */ - nwidth = (font->max_bounds.width * strlen(s))+leftMargin+rightMargin; + nwidth = (font->max_bounds.width * strlen(s)) + leftMargin + rightMargin; if (nwidth < width) - nwidth = width; + nwidth = width; XtSetArg(args[0], nhStr(XtNstring), s); XtSetArg(args[1], nhStr(XtNwidth), nwidth); @@ -288,14 +326,14 @@ ClearDialogResponse(w) } #endif - -/* Not a part of the original dialogs.c from ghostview --------------------- */ +/* Not a part of the original dialogs.c from ghostview --------------------- + */ /* position popup window under the cursor */ void positionpopup(w, bottom) - Widget w; - boolean bottom; /* position y on bottom? */ +Widget w; +boolean bottom; /* position y on bottom? */ { Arg args[3]; Cardinal num_args; @@ -310,38 +348,47 @@ positionpopup(w, bottom) /* following line deals with a race condition w/brain-damaged WM's -dlc */ XtUnrealizeWidget(w); - XQueryPointer(XtDisplay(toplevel), XtWindow(toplevel), &root, &child, - &x, &y, &dummyx, &dummyy, &dummymask); + XQueryPointer(XtDisplay(toplevel), XtWindow(toplevel), &root, &child, &x, + &y, &dummyx, &dummyy, &dummymask); num_args = 0; - XtSetArg(args[num_args], XtNwidth, &width); num_args++; - XtSetArg(args[num_args], XtNheight, &height); num_args++; - XtSetArg(args[num_args], XtNborderWidth, &b_width); num_args++; + XtSetArg(args[num_args], XtNwidth, &width); + num_args++; + XtSetArg(args[num_args], XtNheight, &height); + num_args++; + XtSetArg(args[num_args], XtNborderWidth, &b_width); + num_args++; XtGetValues(w, args, num_args); /* position so that the cursor is center,center or center,bottom */ width += 2 * b_width; - x -= ( (Position) width/2 ); - if (x < 0) x = 0; - if ( x > (max_x = (Position) (XtScreen(w)->width - width)) ) x = max_x; + x -= ((Position) width / 2); + if (x < 0) + x = 0; + if (x > (max_x = (Position)(XtScreen(w)->width - width))) + x = max_x; if (bottom) { - y -= (height+b_width-1); - height += 2 * b_width; + y -= (height + b_width - 1); + height += 2 * b_width; } else { - height += 2 * b_width; - y -= ( (Position) height/2 ); + height += 2 * b_width; + y -= ((Position) height / 2); } - if (y < 0) y = 0; - if ( y > (max_y = (Position) (XtScreen(w)->height - height)) ) y = max_y; - + if (y < 0) + y = 0; + if (y > (max_y = (Position)(XtScreen(w)->height - height))) + y = max_y; num_args = 0; - XtSetArg(args[num_args], XtNx, x); num_args++; - XtSetArg(args[num_args], XtNy, y); num_args++; + XtSetArg(args[num_args], XtNx, x); + num_args++; + XtSetArg(args[num_args], XtNy, y); + num_args++; XtSetValues(w, args, num_args); /* Some older window managers ignore XtN{x,y}; hint the same values */ - /* The {x,y} are not used by newer window managers; older ones need them */ + /* The {x,y} are not used by newer window managers; older ones need them + */ XtRealizeWidget(w); hints = XAllocSizeHints(); hints->flags = USPosition; diff --git a/win/X11/tile2x11.c b/win/X11/tile2x11.c index 52d6e2896..5db1d9ff0 100644 --- a/win/X11/tile2x11.c +++ b/win/X11/tile2x11.c @@ -1,4 +1,4 @@ -/* $NHDT-Date: 1430640199 2015/05/03 08:03:19 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $ */ +/* $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* $Date: 2002/03/17 20:02:47 $ $Revision: 1.2 $ */ /* @@ -9,47 +9,44 @@ * + Two dimensional byte arrays are in row order and are not padded * between rows (x11_colormap[][]). */ -#include "hack.h" /* for MAX_GLYPH */ +#include "hack.h" /* for MAX_GLYPH */ #include "tile.h" -#include "tile2x11.h" /* x11 output file header structure */ +#include "tile2x11.h" /* x11 output file header structure */ -#define OUTNAME "x11tiles" /* output file name */ -/* #define PRINT_COLORMAP */ /* define to print the colormap */ - - -x11_header header; -unsigned char tile_bytes[TILE_X*TILE_Y*(MAX_GLYPH+TILES_PER_ROW)]; -unsigned char *curr_tb = tile_bytes; -unsigned char x11_colormap[MAXCOLORMAPSIZE][3]; +#define OUTNAME "x11tiles" /* output file name */ +/* #define PRINT_COLORMAP */ /* define to print the colormap */ +x11_header header; +unsigned char tile_bytes[TILE_X * TILE_Y * (MAX_GLYPH + TILES_PER_ROW)]; +unsigned char *curr_tb = tile_bytes; +unsigned char x11_colormap[MAXCOLORMAPSIZE][3]; /* Look up the given pixel and return its colormap index. */ static unsigned char pix_to_colormap(pix) - pixel pix; +pixel pix; { unsigned i; for (i = 0; i < header.ncolors; i++) { - if (pix.r == ColorMap[CM_RED][i] && - pix.g == ColorMap[CM_GREEN][i] && - pix.b == ColorMap[CM_BLUE][i]) - break; + if (pix.r == ColorMap[CM_RED][i] && pix.g == ColorMap[CM_GREEN][i] + && pix.b == ColorMap[CM_BLUE][i]) + break; } if (i == header.ncolors) { - Fprintf(stderr, "can't find color: [%u,%u,%u]\n", pix.r, pix.g, pix.b); - exit(1); + Fprintf(stderr, "can't find color: [%u,%u,%u]\n", pix.r, pix.g, + pix.b); + exit(1); } return (unsigned char) (i & 0xFF); } - /* Convert the tiles in the file to our format of bytes. */ static unsigned long convert_tiles(tb_ptr, total) - unsigned char **tb_ptr; /* pointer to a tile byte pointer */ - unsigned long total; /* total tiles so far */ +unsigned char **tb_ptr; /* pointer to a tile byte pointer */ +unsigned long total; /* total tiles so far */ { unsigned char *tb = *tb_ptr; unsigned long count = 0; @@ -57,69 +54,67 @@ convert_tiles(tb_ptr, total) int x, y; while (read_text_tile(tile)) { - count++; - total++; - for (y = 0; y < TILE_Y; y++) { - for (x = 0; x < TILE_X; x++) - tb[x] = pix_to_colormap(tile[y][x]); - tb += TILE_X * header.per_row; - } + count++; + total++; + for (y = 0; y < TILE_Y; y++) { + for (x = 0; x < TILE_X; x++) + tb[x] = pix_to_colormap(tile[y][x]); + tb += TILE_X * header.per_row; + } - /* repoint at the upper-left corner of the next tile */ - *tb_ptr += TILE_X; - if (header.per_row == 1 || (total % header.per_row) == 0) - *tb_ptr += TILE_X * (TILE_Y - 1) * header.per_row; - tb = *tb_ptr; + /* repoint at the upper-left corner of the next tile */ + *tb_ptr += TILE_X; + if (header.per_row == 1 || (total % header.per_row) == 0) + *tb_ptr += TILE_X * (TILE_Y - 1) * header.per_row; + tb = *tb_ptr; } return count; } - /* Merge the current text colormap (ColorMap) with ours (x11_colormap). */ static void merge_text_colormap() { unsigned i, j; - for (i = 0; i < (unsigned)colorsinmap; i++) { - for (j = 0; j < header.ncolors; j++) - if (x11_colormap[j][CM_RED] == ColorMap[CM_RED][i] && - x11_colormap[j][CM_GREEN] == ColorMap[CM_GREEN][i] && - x11_colormap[j][CM_BLUE] == ColorMap[CM_BLUE][i]) - break; + for (i = 0; i < (unsigned) colorsinmap; i++) { + for (j = 0; j < header.ncolors; j++) + if (x11_colormap[j][CM_RED] == ColorMap[CM_RED][i] + && x11_colormap[j][CM_GREEN] == ColorMap[CM_GREEN][i] + && x11_colormap[j][CM_BLUE] == ColorMap[CM_BLUE][i]) + break; - if (j >= MAXCOLORMAPSIZE) { - Fprintf(stderr, "colormap overflow\n"); - exit(1); - } + if (j >= MAXCOLORMAPSIZE) { + Fprintf(stderr, "colormap overflow\n"); + exit(1); + } - if (j == header.ncolors) { /* couldn't find it */ + if (j == header.ncolors) { /* couldn't find it */ #ifdef PRINT_COLORMAP - printf("color %2d: %3d %3d %3d\n", header.ncolors, - ColorMap[CM_RED][i], ColorMap[CM_GREEN][i], - ColorMap[CM_BLUE][i]); + printf("color %2d: %3d %3d %3d\n", header.ncolors, + ColorMap[CM_RED][i], ColorMap[CM_GREEN][i], + ColorMap[CM_BLUE][i]); #endif - x11_colormap[j][CM_RED] = ColorMap[CM_RED][i]; - x11_colormap[j][CM_GREEN] = ColorMap[CM_GREEN][i]; - x11_colormap[j][CM_BLUE] = ColorMap[CM_BLUE][i]; - header.ncolors++; - } + x11_colormap[j][CM_RED] = ColorMap[CM_RED][i]; + x11_colormap[j][CM_GREEN] = ColorMap[CM_GREEN][i]; + x11_colormap[j][CM_BLUE] = ColorMap[CM_BLUE][i]; + header.ncolors++; + } } } - /* Open the given file, read & merge the colormap, convert the tiles. */ static void process_file(fname) - char *fname; +char *fname; { unsigned long count; if (!fopen_text_file(fname, RDTMODE)) { - Fprintf(stderr, "can't open file \"%s\"\n", fname); - exit(1); + Fprintf(stderr, "can't open file \"%s\"\n", fname); + exit(1); } merge_text_colormap(); count = convert_tiles(&curr_tb, header.ntiles); @@ -128,7 +123,6 @@ process_file(fname) fclose_text_file(); } - #ifdef USE_XPM static int xpm_write(fp) @@ -137,99 +131,96 @@ FILE *fp; int i, j, n; if (header.ncolors > 64) { - Fprintf(stderr, "Sorry, only configured for up to 64 colors\n"); - exit(1); - /* All you need to do is add more char per color - below */ + Fprintf(stderr, "Sorry, only configured for up to 64 colors\n"); + exit(1); + /* All you need to do is add more char per color - below */ } Fprintf(fp, "/* XPM */\n"); Fprintf(fp, "static char* nhtiles[] = {\n"); - Fprintf(fp, "\"%lu %lu %lu %d\",\n", - header.tile_width*header.per_row, - (header.tile_height*header.ntiles)/header.per_row, - header.ncolors, - 1 /* char per color */); + Fprintf(fp, "\"%lu %lu %lu %d\",\n", header.tile_width * header.per_row, + (header.tile_height * header.ntiles) / header.per_row, + header.ncolors, 1 /* char per color */); for (i = 0; i < header.ncolors; i++) - Fprintf(fp, "\"%c c #%02x%02x%02x\",\n", - i+'0', /* just one char per color */ - x11_colormap[i][0], - x11_colormap[i][1], - x11_colormap[i][2]); + Fprintf(fp, "\"%c c #%02x%02x%02x\",\n", + i + '0', /* just one char per color */ + x11_colormap[i][0], x11_colormap[i][1], x11_colormap[i][2]); n = 0; - for (i = 0; i < (header.tile_height*header.ntiles)/header.per_row; i++) { - Fprintf(fp, "\""); - for (j = 0; j < header.tile_width*header.per_row; j++) { - /* just one char per color */ - fputc(tile_bytes[n++]+'0', fp); - } + for (i = 0; i < (header.tile_height * header.ntiles) / header.per_row; + i++) { + Fprintf(fp, "\""); + for (j = 0; j < header.tile_width * header.per_row; j++) { + /* just one char per color */ + fputc(tile_bytes[n++] + '0', fp); + } - Fprintf(fp, "\",\n"); + Fprintf(fp, "\",\n"); } return fprintf(fp, "};\n") >= 0; } -#endif /* USE_XPM */ +#endif /* USE_XPM */ int main(argc, argv) - int argc; - char **argv; +int argc; +char **argv; { FILE *fp; int i; - header.version = 2; /* version 1 had no per_row field */ - header.ncolors = 0; - header.tile_width = TILE_X; - header.tile_height = TILE_Y; - header.ntiles = 0; /* updated as we read in files */ - header.per_row = TILES_PER_ROW; + header.version = 2; /* version 1 had no per_row field */ + header.ncolors = 0; + header.tile_width = TILE_X; + header.tile_height = TILE_Y; + header.ntiles = 0; /* updated as we read in files */ + header.per_row = TILES_PER_ROW; if (argc == 1) { - Fprintf(stderr, "usage: %s txt_file1 [txt_file2 ...]\n", argv[0]); - exit(1); + Fprintf(stderr, "usage: %s txt_file1 [txt_file2 ...]\n", argv[0]); + exit(1); } fp = fopen(OUTNAME, "w"); if (!fp) { - Fprintf(stderr, "can't open output file\n"); - exit(1); + Fprintf(stderr, "can't open output file\n"); + exit(1); } /* don't leave garbage at end of partial row */ - (void) memset((genericptr_t)tile_bytes, 0, sizeof(tile_bytes)); + (void) memset((genericptr_t) tile_bytes, 0, sizeof(tile_bytes)); for (i = 1; i < argc; i++) - process_file(argv[i]); + process_file(argv[i]); Fprintf(stderr, "Total tiles: %ld\n", header.ntiles); /* round size up to the end of the row */ if ((header.ntiles % header.per_row) != 0) { - header.ntiles += header.per_row - (header.ntiles % header.per_row); + header.ntiles += header.per_row - (header.ntiles % header.per_row); } #ifdef USE_XPM if (xpm_write(fp) == 0) { - Fprintf(stderr, "can't write XPM file\n"); - exit(1); + Fprintf(stderr, "can't write XPM file\n"); + exit(1); } #else - if (fwrite((char *)&header, sizeof(x11_header), 1, fp) == 0) { - Fprintf(stderr, "can't open output header\n"); - exit(1); + if (fwrite((char *) &header, sizeof(x11_header), 1, fp) == 0) { + Fprintf(stderr, "can't open output header\n"); + exit(1); } - if (fwrite((char *)x11_colormap, 1, header.ncolors*3, fp) == 0) { - Fprintf(stderr, "can't write output colormap\n"); - exit(1); + if (fwrite((char *) x11_colormap, 1, header.ncolors * 3, fp) == 0) { + Fprintf(stderr, "can't write output colormap\n"); + exit(1); } - if (fwrite((char *)tile_bytes, 1, - (int) header.ntiles*header.tile_width*header.tile_height, fp) == 0) { - - Fprintf(stderr, "can't write tile bytes\n"); - exit(1); + if (fwrite((char *) tile_bytes, 1, + (int) header.ntiles * header.tile_width * header.tile_height, + fp) == 0) { + Fprintf(stderr, "can't write tile bytes\n"); + exit(1); } #endif diff --git a/win/X11/winX.c b/win/X11/winX.c index 0a2ba729b..eae71d5c2 100644 --- a/win/X11/winX.c +++ b/win/X11/winX.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winX.c $NHDT-Date: 1430899139 2015/05/06 07:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */ +/* NetHack 3.6 winX.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */ /* NetHack 3.6 winX.c $Date: 2012/01/24 04:26:26 $ $Revision: 1.27 $ */ /* Copyright (c) Dean Luick, 1992 */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,10 +10,10 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif -#ifdef MSDOS /* from compiler */ +#ifdef MSDOS /* from compiler */ #define SHORT_FILENAMES #endif @@ -37,14 +37,14 @@ #endif #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #ifdef SHORT_FILENAMES -#undef SHORT_FILENAMES /* hack.h will reset via global.h if necessary */ +#undef SHORT_FILENAMES /* hack.h will reset via global.h if necessary */ #endif #include "hack.h" @@ -68,31 +68,29 @@ #include "../win/X11/nh32icon" static struct icon_info { - const char *name; - unsigned char *bits; - unsigned width, height; -} icon_data[] = { - { "nh72", nh72icon_bits, nh72icon_width, nh72icon_height }, - { "nh56", nh56icon_bits, nh56icon_width, nh56icon_height }, - { "nh32", nh32icon_bits, nh32icon_width, nh32icon_height }, - { (const char *)0, (unsigned char *)0, 0, 0 } -}; + const char *name; + unsigned char *bits; + unsigned width, height; +} icon_data[] = { { "nh72", nh72icon_bits, nh72icon_width, nh72icon_height }, + { "nh56", nh56icon_bits, nh56icon_width, nh56icon_height }, + { "nh32", nh32icon_bits, nh32icon_width, nh32icon_height }, + { (const char *) 0, (unsigned char *) 0, 0, 0 } }; /* * Private global variables (shared among the window port files). */ struct xwindow window_list[MAX_WINDOWS]; AppResources appResources; -void FDECL((*input_func), (Widget,XEvent *,String *,Cardinal *)); -int click_x, click_y, click_button; /* Click position on a map window */ - /* (filled by set_button_values()). */ +void FDECL((*input_func), (Widget, XEvent *, String *, Cardinal *)); +int click_x, click_y, click_button; /* Click position on a map window */ + /* (filled by set_button_values()). */ int updated_inventory; #if !defined(NO_SIGNAL) && defined(SAFERHANGUP) -# if XtSpecificationRelease >= 6 +#if XtSpecificationRelease >= 6 #define X11_HANGUP_SIGNAL static XtSignalId X11_sig_id; -# endif +#endif #endif /* this is only needed until X11_status_* routines are written */ @@ -100,104 +98,71 @@ extern NEARDATA winid WIN_STATUS; /* Interface definition, for windows.c */ struct window_procs X11_procs = { - "X11", - WC_COLOR|WC_HILITE_PET|WC_TILED_MAP, - 0L, - X11_init_nhwindows, - X11_player_selection, - X11_askname, - X11_get_nh_event, - X11_exit_nhwindows, - X11_suspend_nhwindows, - X11_resume_nhwindows, - X11_create_nhwindow, - X11_clear_nhwindow, - X11_display_nhwindow, - X11_destroy_nhwindow, - X11_curs, - X11_putstr, - genl_putmixed, - X11_display_file, - X11_start_menu, - X11_add_menu, - X11_end_menu, - X11_select_menu, - genl_message_menu, /* no need for X-specific handling */ - X11_update_inventory, - X11_mark_synch, - X11_wait_synch, + "X11", WC_COLOR | WC_HILITE_PET | WC_TILED_MAP, 0L, X11_init_nhwindows, + X11_player_selection, X11_askname, X11_get_nh_event, X11_exit_nhwindows, + X11_suspend_nhwindows, X11_resume_nhwindows, X11_create_nhwindow, + X11_clear_nhwindow, X11_display_nhwindow, X11_destroy_nhwindow, X11_curs, + X11_putstr, genl_putmixed, X11_display_file, X11_start_menu, X11_add_menu, + X11_end_menu, X11_select_menu, + genl_message_menu, /* no need for X-specific handling */ + X11_update_inventory, X11_mark_synch, X11_wait_synch, #ifdef CLIPPING X11_cliparound, #endif #ifdef POSITIONBAR donull, #endif - X11_print_glyph, - X11_raw_print, - X11_raw_print_bold, - X11_nhgetch, - X11_nh_poskey, - X11_nhbell, - X11_doprev_message, - X11_yn_function, - X11_getlin, - X11_get_ext_cmd, - X11_number_pad, - X11_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - donull, - donull, + X11_print_glyph, X11_raw_print, X11_raw_print_bold, X11_nhgetch, + X11_nh_poskey, X11_nhbell, X11_doprev_message, X11_yn_function, + X11_getlin, X11_get_ext_cmd, X11_number_pad, X11_delay_output, +#ifdef CHANGE_COLOR /* only a Mac option currently */ + donull, donull, #endif /* other defs that really should go away (they're tty specific) */ - X11_start_screen, - X11_end_screen, + X11_start_screen, X11_end_screen, #ifdef GRAPHIC_TOMBSTONE X11_outrip, #else genl_outrip, #endif - X11_preference_update, - genl_getmsghistory, - genl_putmsghistory, + X11_preference_update, genl_getmsghistory, genl_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, + genl_status_init, genl_status_finish, genl_status_enablefield, genl_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES genl_status_threshold, -# endif #endif - genl_can_suspend_no, /* XXX may not always be correct */ +#endif + genl_can_suspend_no, /* XXX may not always be correct */ }; /* * Local functions. */ -static void FDECL(dismiss_file, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(delete_file, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(yn_key, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(yn_delete, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(askname_delete, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(getline_delete, (Widget, XEvent*, String*, Cardinal*)); -static void FDECL(X11_hangup, (Widget, XEvent*, String*, Cardinal*)); +static void FDECL(dismiss_file, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(delete_file, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(yn_key, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(yn_delete, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(askname_delete, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(getline_delete, (Widget, XEvent *, String *, Cardinal *)); +static void FDECL(X11_hangup, (Widget, XEvent *, String *, Cardinal *)); static int FDECL(input_event, (int)); -static void FDECL(win_visible, (Widget,XtPointer,XEvent *,Boolean *)); +static void FDECL(win_visible, (Widget, XtPointer, XEvent *, Boolean *)); static void NDECL(init_standard_windows); #ifdef X11_HANGUP_SIGNAL static void FDECL(X11_sig, (int)); -static void FDECL(X11_sig_cb, (XtPointer, XtSignalId*)); +static void FDECL(X11_sig_cb, (XtPointer, XtSignalId *)); #endif /* * Local variables. */ -static boolean x_inited = FALSE; /* TRUE if window system is set up. */ -static winid message_win = WIN_ERR, /* These are the winids of the */ - map_win = WIN_ERR, /* message, map, and status */ - status_win = WIN_ERR; /* windows, when they are created */ - /* in init_windows(). */ -static Pixmap icon_pixmap = None; /* Pixmap for icon. */ +static boolean x_inited = FALSE; /* TRUE if window system is set up. */ +static winid message_win = WIN_ERR, /* These are the winids of the */ + map_win = WIN_ERR, /* message, map, and status */ + status_win = WIN_ERR; /* windows, when they are created */ + /* in init_windows(). */ +static Pixmap icon_pixmap = None; /* Pixmap for icon. */ /* * Find the window structure that corresponds to the given widget. Note @@ -205,7 +170,7 @@ static Pixmap icon_pixmap = None; /* Pixmap for icon. */ */ struct xwindow * find_widget(w) - Widget w; +Widget w; { int windex; struct xwindow *wp; @@ -213,12 +178,13 @@ find_widget(w) /* Search to find the corresponding window. Look at the main widget, */ /* popup, the parent of the main widget, then parent of the widget. */ for (windex = 0, wp = window_list; windex < MAX_WINDOWS; windex++, wp++) - if (wp->type != NHW_NONE && - (wp->w == w || wp->popup == w || (wp->w && (XtParent(wp->w)) == w) - || (wp->popup == XtParent(w)))) - break; + if (wp->type != NHW_NONE && (wp->w == w || wp->popup == w + || (wp->w && (XtParent(wp->w)) == w) + || (wp->popup == XtParent(w)))) + break; - if (windex == MAX_WINDOWS) panic("find_widget: can't match widget"); + if (windex == MAX_WINDOWS) + panic("find_widget: can't match widget"); return wp; } @@ -231,11 +197,13 @@ find_free_window() int windex; struct xwindow *wp; - for (windex = 0, wp = &window_list[0]; windex < MAX_WINDOWS; windex++, wp++) - if (wp->type == NHW_NONE) break; + for (windex = 0, wp = &window_list[0]; windex < MAX_WINDOWS; + windex++, wp++) + if (wp->type == NHW_NONE) + break; if (windex == MAX_WINDOWS) - panic("find_free_window: no free windows!"); + panic("find_free_window: no free windows!"); return (winid) windex; } @@ -246,28 +214,28 @@ find_free_window() * This is an attempt to find some close readonly cell and use it. */ XtConvertArgRec const nhcolorConvertArgs[] = { - {XtWidgetBaseOffset, (XtPointer)XtOffset(Widget, core.screen), - sizeof(Screen *)}, - {XtWidgetBaseOffset, (XtPointer)XtOffset(Widget, core.colormap), - sizeof(Colormap)} + { XtWidgetBaseOffset, (XtPointer) XtOffset(Widget, core.screen), + sizeof(Screen *) }, + { XtWidgetBaseOffset, (XtPointer) XtOffset(Widget, core.colormap), + sizeof(Colormap) } }; -#define done(type, value) \ - { \ - if (toVal->addr != 0) { \ - if (toVal->size < sizeof(type)) { \ - toVal->size = sizeof(type); \ - return False; \ - } \ - *(type*)(toVal->addr) = (value); \ - } else { \ - static type static_val; \ - static_val = (value); \ - toVal->addr = (genericptr_t)&static_val; \ - } \ - toVal->size = sizeof(type); \ - return True; \ - } +#define done(type, value) \ + { \ + if (toVal->addr != 0) { \ + if (toVal->size < sizeof(type)) { \ + toVal->size = sizeof(type); \ + return False; \ + } \ + *(type *)(toVal->addr) = (value); \ + } else { \ + static type static_val; \ + static_val = (value); \ + toVal->addr = (genericptr_t) &static_val; \ + } \ + toVal->size = sizeof(type); \ + return True; \ + } /* * Find a color that approximates the color named in "str". The "str" color @@ -278,61 +246,65 @@ XtConvertArgRec const nhcolorConvertArgs[] = { */ Boolean nhApproxColor(screen, colormap, str, color) -Screen *screen; /* screen to use */ -Colormap colormap; /* the colormap to use */ -char *str; /* color name */ -XColor *color; /* the X color structure; changed only if successful */ +Screen *screen; /* screen to use */ +Colormap colormap; /* the colormap to use */ +char *str; /* color name */ +XColor *color; /* the X color structure; changed only if successful */ { - int ncells; - long cdiff = 16777216; /* 2^24; hopefully our map is smaller */ - XColor tmp; - static XColor *table = 0; + int ncells; + long cdiff = 16777216; /* 2^24; hopefully our map is smaller */ + XColor tmp; + static XColor *table = 0; register int i, j; register long tdiff; /* if the screen doesn't have a big colormap, don't waste our time */ /* or if it's huge, and _some_ match should have been possible */ - if((ncells = CellsOfScreen(screen)) < 256 || ncells > 4096) - return False; + if ((ncells = CellsOfScreen(screen)) < 256 || ncells > 4096) + return False; - if (str != (char *)0) { - if (!XParseColor(DisplayOfScreen(screen), colormap, str, &tmp)) - return False; + if (str != (char *) 0) { + if (!XParseColor(DisplayOfScreen(screen), colormap, str, &tmp)) + return False; } else { - tmp = *color; - tmp.flags = 7; /* force to use all 3 of RGB */ + tmp = *color; + tmp.flags = 7; /* force to use all 3 of RGB */ } if (!table) { - table = (XColor *) XtCalloc(ncells, sizeof(XColor)); - for(i=0; iaddr; - XColor screenColor; - XColor exactColor; - Screen *screen; - XtAppContext app = XtDisplayToApplicationContext(dpy); - Colormap colormap; - Status status; - String params[1]; - Cardinal num_params=1; + String str = (String) fromVal->addr; + XColor screenColor; + XColor exactColor; + Screen *screen; + XtAppContext app = XtDisplayToApplicationContext(dpy); + Colormap colormap; + Status status; + String params[1]; + Cardinal num_params = 1; if (*num_args != 2) { - XtAppWarningMsg(app, "wrongParameters", "cvtStringToPixel", - "XtToolkitError", - "String to pixel conversion needs screen and colormap arguments", - (String *)0, (Cardinal *)0); - return False; + XtAppWarningMsg( + app, "wrongParameters", "cvtStringToPixel", "XtToolkitError", + "String to pixel conversion needs screen and colormap arguments", + (String *) 0, (Cardinal *) 0); + return False; } screen = *((Screen **) args[0].addr); colormap = *((Colormap *) args[1].addr); - /* If Xt colors, use the Xt routine and hope for the best */ +/* If Xt colors, use the Xt routine and hope for the best */ #if (XtSpecificationRelease >= 5) - if ((strcmpi(str, XtDefaultBackground) == 0) || - (strcmpi(str, XtDefaultForeground) == 0)) { - return - XtCvtStringToPixel(dpy, args, num_args, fromVal, toVal, closure_ret); + if ((strcmpi(str, XtDefaultBackground) == 0) + || (strcmpi(str, XtDefaultForeground) == 0)) { + return XtCvtStringToPixel(dpy, args, num_args, fromVal, toVal, + closure_ret); } #else if (strcmpi(str, XtDefaultBackground) == 0) { - *closure_ret = (char*)False; - done(Pixel, WhitePixelOfScreen(screen)); + *closure_ret = (char *) False; + done(Pixel, WhitePixelOfScreen(screen)); } if (strcmpi(str, XtDefaultForeground) == 0) { - *closure_ret = (char*)False; - done(Pixel, BlackPixelOfScreen(screen)); + *closure_ret = (char *) False; + done(Pixel, BlackPixelOfScreen(screen)); } #endif - status = XAllocNamedColor(DisplayOfScreen(screen), colormap, - (char*)str, &screenColor, &exactColor); + status = XAllocNamedColor(DisplayOfScreen(screen), colormap, (char *) str, + &screenColor, &exactColor); if (status == 0) { - String msg, type; + String msg, type; - /* some versions of XAllocNamedColor don't allow #xxyyzz names */ - if (str[0] == '#' && - XParseColor(DisplayOfScreen(screen), colormap, str, &exactColor) && - XAllocColor(DisplayOfScreen(screen), colormap, &exactColor)) { - *closure_ret = (char*)True; - done(Pixel, exactColor.pixel); - } + /* some versions of XAllocNamedColor don't allow #xxyyzz names */ + if (str[0] == '#' && XParseColor(DisplayOfScreen(screen), colormap, + str, &exactColor) + && XAllocColor(DisplayOfScreen(screen), colormap, &exactColor)) { + *closure_ret = (char *) True; + done(Pixel, exactColor.pixel); + } - params[0] = str; - /* Server returns a specific error code but Xlib discards it. Ugh */ - if (XLookupColor(DisplayOfScreen(screen), colormap, (char*)str, - &exactColor, &screenColor)) { - /* try to find another color that will do */ - if (nhApproxColor(screen, colormap, (char*) str, &screenColor)) { - *closure_ret = (char*)True; - done(Pixel, screenColor.pixel); - } - type = nhStr("noColormap"); - msg = nhStr("Cannot allocate colormap entry for \"%s\""); - } else { - /* some versions of XLookupColor also don't allow #xxyyzz names */ - if(str[0] == '#' && - (nhApproxColor(screen, colormap, (char*) str, &screenColor))) { - *closure_ret = (char*)True; - done(Pixel, screenColor.pixel); - } - type = nhStr("badValue"); - msg = nhStr("Color name \"%s\" is not defined"); - } + params[0] = str; + /* Server returns a specific error code but Xlib discards it. Ugh */ + if (XLookupColor(DisplayOfScreen(screen), colormap, (char *) str, + &exactColor, &screenColor)) { + /* try to find another color that will do */ + if (nhApproxColor(screen, colormap, (char *) str, &screenColor)) { + *closure_ret = (char *) True; + done(Pixel, screenColor.pixel); + } + type = nhStr("noColormap"); + msg = nhStr("Cannot allocate colormap entry for \"%s\""); + } else { + /* some versions of XLookupColor also don't allow #xxyyzz names */ + if (str[0] == '#' + && (nhApproxColor(screen, colormap, (char *) str, + &screenColor))) { + *closure_ret = (char *) True; + done(Pixel, screenColor.pixel); + } + type = nhStr("badValue"); + msg = nhStr("Color name \"%s\" is not defined"); + } - XtAppWarningMsg(app, type, "cvtStringToPixel", - "XtToolkitError", msg, params, &num_params); - *closure_ret = False; - return False; + XtAppWarningMsg(app, type, "cvtStringToPixel", "XtToolkitError", msg, + params, &num_params); + *closure_ret = False; + return False; } else { - *closure_ret = (char*)True; - done(Pixel, screenColor.pixel); + *closure_ret = (char *) True; + done(Pixel, screenColor.pixel); } } /* ARGSUSED */ static void nhFreePixel(app, toVal, closure, args, num_args) -XtAppContext app; -XrmValuePtr toVal; -XtPointer closure; -XrmValuePtr args; -Cardinal *num_args; +XtAppContext app; +XrmValuePtr toVal; +XtPointer closure; +XrmValuePtr args; +Cardinal *num_args; { - Screen *screen; - Colormap colormap; + Screen *screen; + Colormap colormap; if (*num_args != 2) { - XtAppWarningMsg(app, "wrongParameters", - "freePixel", "XtToolkitError", - "Freeing a pixel requires screen and colormap arguments", - (String *)0, (Cardinal *)0); - return; + XtAppWarningMsg( + app, "wrongParameters", "freePixel", "XtToolkitError", + "Freeing a pixel requires screen and colormap arguments", + (String *) 0, (Cardinal *) 0); + return; } screen = *((Screen **) args[0].addr); colormap = *((Colormap *) args[1].addr); if (closure) { - XFreeColors( DisplayOfScreen(screen), colormap, - (unsigned long*)toVal->addr, 1, (unsigned long)0 - ); + XFreeColors(DisplayOfScreen(screen), colormap, + (unsigned long *) toVal->addr, 1, (unsigned long) 0); } } /* [ALI] Utility function to ask Xaw for font height, since the previous * assumption of ascent + descent is not always valid. */ -Dimension -nhFontHeight(w) -Widget w; +Dimension nhFontHeight(w) Widget w; #ifdef _XawTextSink_h { Widget sink; @@ -503,35 +473,36 @@ Widget w; } #endif -/* Global Functions ======================================================== */ +/* Global Functions ======================================================== + */ void X11_raw_print(str) - const char *str; +const char *str; { (void) puts(str); } void X11_raw_print_bold(str) - const char *str; +const char *str; { (void) puts(str); } void X11_curs(window, x, y) - winid window; - int x, y; +winid window; +int x, y; { check_winid(window); if (x < 0 || x >= COLNO) { - impossible("curs: bad x value [%d]", x); - x = 0; + impossible("curs: bad x value [%d]", x); + x = 0; } if (y < 0 || y >= ROWNO) { - impossible("curs: bad y value [%d]", y); - y = 0; + impossible("curs: bad y value [%d]", y); + y = 0; } window_list[window].cursx = x; @@ -540,9 +511,9 @@ X11_curs(window, x, y) void X11_putstr(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { winid new_win; struct xwindow *wp; @@ -551,44 +522,46 @@ X11_putstr(window, attr, str) wp = &window_list[window]; switch (wp->type) { - case NHW_MESSAGE: - (void) strncpy(toplines, str, TBUFSZ); /* for Norep(). */ - toplines[TBUFSZ - 1] = 0; - append_message(wp, str); - break; - case NHW_STATUS: - adjust_status(wp, str); - break; - case NHW_MAP: - impossible("putstr: called on map window \"%s\"", str); - break; - case NHW_MENU: - if (wp->menu_information->is_menu) { - impossible( - "putstr: called on a menu window, \"%s\" discarded", - str); - break; - } - /* - * Change this menu window into a text window by creating a - * new text window, then copying it to this winid. - */ - new_win = X11_create_nhwindow(NHW_TEXT); - X11_destroy_nhwindow(window); - *wp = window_list[new_win]; - window_list[new_win].type = NHW_NONE; /* allow re-use */ - /* fall though to add text */ - case NHW_TEXT: - add_to_text_window(wp, attr, str); - break; - default: - impossible("putstr: unknown window type [%d] \"%s\"", - wp->type, str); + case NHW_MESSAGE: + (void) strncpy(toplines, str, TBUFSZ); /* for Norep(). */ + toplines[TBUFSZ - 1] = 0; + append_message(wp, str); + break; + case NHW_STATUS: + adjust_status(wp, str); + break; + case NHW_MAP: + impossible("putstr: called on map window \"%s\"", str); + break; + case NHW_MENU: + if (wp->menu_information->is_menu) { + impossible("putstr: called on a menu window, \"%s\" discarded", + str); + break; + } + /* + * Change this menu window into a text window by creating a + * new text window, then copying it to this winid. + */ + new_win = X11_create_nhwindow(NHW_TEXT); + X11_destroy_nhwindow(window); + *wp = window_list[new_win]; + window_list[new_win].type = NHW_NONE; /* allow re-use */ + /* fall though to add text */ + case NHW_TEXT: + add_to_text_window(wp, attr, str); + break; + default: + impossible("putstr: unknown window type [%d] \"%s\"", wp->type, str); } } /* We do event processing as a callback, so this is a null routine. */ -void X11_get_nh_event() { return; } +void +X11_get_nh_event() +{ + return; +} int X11_nhgetch() @@ -596,55 +569,53 @@ X11_nhgetch() return input_event(EXIT_ON_KEY_PRESS); } - int X11_nh_poskey(x, y, mod) - int *x, *y, *mod; +int *x, *y, *mod; { int val = input_event(EXIT_ON_KEY_OR_BUTTON_PRESS); - if (val == 0) { /* user clicked on a map window */ - *x = click_x; - *y = click_y; - *mod = click_button; + if (val == 0) { /* user clicked on a map window */ + *x = click_x; + *y = click_y; + *mod = click_button; } return val; } - winid X11_create_nhwindow(type) - int type; +int type; { winid window; struct xwindow *wp; if (!x_inited) - panic("create_nhwindow: windows not initialized"); + panic("create_nhwindow: windows not initialized"); #ifdef X11_HANGUP_SIGNAL /* set up our own signal handlers on the first call. Can't do this in * X11_init_nhwindows because unixmain sets its handler after calling * all the init routines. */ if (X11_sig_id == 0) { - X11_sig_id = XtAppAddSignal(app_context, X11_sig_cb, (XtPointer)0); -# ifdef SA_RESTART - { - struct sigaction sact; + X11_sig_id = XtAppAddSignal(app_context, X11_sig_cb, (XtPointer) 0); +#ifdef SA_RESTART + { + struct sigaction sact; - (void) memset((char*) &sact, 0, sizeof(struct sigaction)); - sact.sa_handler = (SIG_RET_TYPE)X11_sig; - (void) sigaction(SIGHUP, &sact, (struct sigaction*)0); -# ifdef SIGXCPU - (void) sigaction(SIGXCPU, &sact, (struct sigaction*)0); -# endif - } -# else - (void) signal(SIGHUP, (SIG_RET_TYPE) X11_sig); -# ifdef SIGXCPU - (void) signal(SIGXCPU, (SIG_RET_TYPE) X11_sig); -# endif -# endif + (void) memset((char *) &sact, 0, sizeof(struct sigaction)); + sact.sa_handler = (SIG_RET_TYPE) X11_sig; + (void) sigaction(SIGHUP, &sact, (struct sigaction *) 0); +#ifdef SIGXCPU + (void) sigaction(SIGXCPU, &sact, (struct sigaction *) 0); +#endif + } +#else + (void) signal(SIGHUP, (SIG_RET_TYPE) X11_sig); +#ifdef SIGXCPU + (void) signal(SIGXCPU, (SIG_RET_TYPE) X11_sig); +#endif +#endif } #endif @@ -657,55 +628,55 @@ X11_create_nhwindow(type) * has already defined these three windows. */ if (type == NHW_MAP && map_win != WIN_ERR) { - window = map_win; - map_win = WIN_ERR; - return window; + window = map_win; + map_win = WIN_ERR; + return window; } if (type == NHW_MESSAGE && message_win != WIN_ERR) { - window = message_win; - message_win = WIN_ERR; - return window; + window = message_win; + message_win = WIN_ERR; + return window; } if (type == NHW_STATUS && status_win != WIN_ERR) { - window = status_win; - status_win = WIN_ERR; - return window; + window = status_win; + status_win = WIN_ERR; + return window; } window = find_free_window(); wp = &window_list[window]; /* The create routines will set type, popup, w, and Win_info. */ - wp->prevx = wp->prevy = wp->cursx = wp->cursy = - wp->pixel_width = wp->pixel_height = 0; + wp->prevx = wp->prevy = wp->cursx = wp->cursy = wp->pixel_width = + wp->pixel_height = 0; wp->keep_window = FALSE; switch (type) { - case NHW_MAP: - create_map_window(wp, TRUE, (Widget) 0); - break; - case NHW_MESSAGE: - create_message_window(wp, TRUE, (Widget) 0); - break; - case NHW_STATUS: - create_status_window(wp, TRUE, (Widget) 0); - break; - case NHW_MENU: - create_menu_window(wp); - break; - case NHW_TEXT: - create_text_window(wp); - break; - default: - panic("create_nhwindow: unknown type [%d]", type); - break; + case NHW_MAP: + create_map_window(wp, TRUE, (Widget) 0); + break; + case NHW_MESSAGE: + create_message_window(wp, TRUE, (Widget) 0); + break; + case NHW_STATUS: + create_status_window(wp, TRUE, (Widget) 0); + break; + case NHW_MENU: + create_menu_window(wp); + break; + case NHW_TEXT: + create_text_window(wp); + break; + default: + panic("create_nhwindow: unknown type [%d]", type); + break; } return window; } void X11_clear_nhwindow(window) - winid window; +winid window; { struct xwindow *wp; @@ -713,23 +684,27 @@ X11_clear_nhwindow(window) wp = &window_list[window]; switch (wp->type) { - case NHW_MAP: clear_map_window(wp); break; - case NHW_TEXT: clear_text_window(wp); break; - case NHW_STATUS: - case NHW_MENU: - case NHW_MESSAGE: - /* do nothing for these window types */ - break; - default: - panic("clear_nhwindow: unknown window type [%d]", wp->type); - break; + case NHW_MAP: + clear_map_window(wp); + break; + case NHW_TEXT: + clear_text_window(wp); + break; + case NHW_STATUS: + case NHW_MENU: + case NHW_MESSAGE: + /* do nothing for these window types */ + break; + default: + panic("clear_nhwindow: unknown window type [%d]", wp->type); + break; } } void X11_display_nhwindow(window, blocking) - winid window; - boolean blocking; +winid window; +boolean blocking; { struct xwindow *wp; @@ -737,61 +712,61 @@ X11_display_nhwindow(window, blocking) wp = &window_list[window]; switch (wp->type) { - case NHW_MAP: - if (wp->popup) - nh_XtPopup(wp->popup, (int)XtGrabNone, wp->w); - display_map_window(wp); /* flush map */ - /* - * We need to flush the message window here due to the way the tty - * port is set up. To flush a window, you need to call this - * routine. However, the tty port _pauses_ with a --more-- if we - * do a display_nhwindow(WIN_MESSAGE, FALSE). Thus, we can't call - * display_nhwindow(WIN_MESSAGE,FALSE) in parse() because then we - * get a --more-- after every line. - * - * Perhaps the window document should mention that when the map - * is flushed, everything on the three main windows should be - * flushed. Note: we don't need to flush the status window - * because we don't buffer changes. - */ - if (WIN_MESSAGE != WIN_ERR) - display_message_window(&window_list[WIN_MESSAGE]); - if (blocking) - (void) x_event(EXIT_ON_KEY_OR_BUTTON_PRESS); - break; - case NHW_MESSAGE: - if (wp->popup) - nh_XtPopup(wp->popup, (int)XtGrabNone, wp->w); - display_message_window(wp); /* flush messages */ - break; - case NHW_STATUS: - if (wp->popup) - nh_XtPopup(wp->popup, (int)XtGrabNone, wp->w); - break; /* no flushing necessary */ - case NHW_MENU: { - int n; - menu_item *selected; + case NHW_MAP: + if (wp->popup) + nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w); + display_map_window(wp); /* flush map */ + /* + * We need to flush the message window here due to the way the tty + * port is set up. To flush a window, you need to call this + * routine. However, the tty port _pauses_ with a --more-- if we + * do a display_nhwindow(WIN_MESSAGE, FALSE). Thus, we can't call + * display_nhwindow(WIN_MESSAGE,FALSE) in parse() because then we + * get a --more-- after every line. + * + * Perhaps the window document should mention that when the map + * is flushed, everything on the three main windows should be + * flushed. Note: we don't need to flush the status window + * because we don't buffer changes. + */ + if (WIN_MESSAGE != WIN_ERR) + display_message_window(&window_list[WIN_MESSAGE]); + if (blocking) + (void) x_event(EXIT_ON_KEY_OR_BUTTON_PRESS); + break; + case NHW_MESSAGE: + if (wp->popup) + nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w); + display_message_window(wp); /* flush messages */ + break; + case NHW_STATUS: + if (wp->popup) + nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w); + break; /* no flushing necessary */ + case NHW_MENU: { + int n; + menu_item *selected; - /* pop up menu */ - n = X11_select_menu(window, PICK_NONE, &selected); - if (n) { - impossible("perminvent: %d selected??", n); - free((genericptr_t)selected); - } - break; - } - case NHW_TEXT: - display_text_window(wp, blocking); /* pop up text window */ - break; - default: - panic("display_nhwindow: unknown window type [%d]", wp->type); - break; + /* pop up menu */ + n = X11_select_menu(window, PICK_NONE, &selected); + if (n) { + impossible("perminvent: %d selected??", n); + free((genericptr_t) selected); + } + break; + } + case NHW_TEXT: + display_text_window(wp, blocking); /* pop up text window */ + break; + default: + panic("display_nhwindow: unknown window type [%d]", wp->type); + break; } } void X11_destroy_nhwindow(window) - winid window; +winid window; { struct xwindow *wp; @@ -804,39 +779,39 @@ X11_destroy_nhwindow(window) * roots that the DECWindow wm creates. */ if (window == WIN_MESSAGE) { - wp->keep_window = TRUE; - WIN_MESSAGE = WIN_ERR; - iflags.window_inited = 0; + wp->keep_window = TRUE; + WIN_MESSAGE = WIN_ERR; + iflags.window_inited = 0; } else if (window == WIN_MAP) { - wp->keep_window = TRUE; - WIN_MAP = WIN_ERR; + wp->keep_window = TRUE; + WIN_MAP = WIN_ERR; } else if (window == WIN_STATUS) { - wp->keep_window = TRUE; - WIN_STATUS = WIN_ERR; + wp->keep_window = TRUE; + WIN_STATUS = WIN_ERR; } else if (window == WIN_INVEN) { - /* don't need to keep this one */ - WIN_INVEN = WIN_ERR; + /* don't need to keep this one */ + WIN_INVEN = WIN_ERR; } switch (wp->type) { - case NHW_MAP: - destroy_map_window(wp); - break; - case NHW_MENU: - destroy_menu_window(wp); - break; - case NHW_TEXT: - destroy_text_window(wp); - break; - case NHW_STATUS: - destroy_status_window(wp); - break; - case NHW_MESSAGE: - destroy_message_window(wp); - break; - default: - panic("destroy_nhwindow: unknown window type [%d]", wp->type); - break; + case NHW_MAP: + destroy_map_window(wp); + break; + case NHW_MENU: + destroy_menu_window(wp); + break; + case NHW_TEXT: + destroy_text_window(wp); + break; + case NHW_STATUS: + destroy_status_window(wp); + break; + case NHW_MESSAGE: + destroy_message_window(wp); + break; + default: + panic("destroy_nhwindow: unknown window type [%d]", wp->type); + break; } } @@ -844,48 +819,62 @@ void X11_update_inventory() { if (x_inited && window_list[WIN_INVEN].menu_information->is_up) { - updated_inventory = 1; /* hack to avoid mapping&raising window */ - (void) display_inventory((char *)0, FALSE); - updated_inventory = 0; + updated_inventory = 1; /* hack to avoid mapping&raising window */ + (void) display_inventory((char *) 0, FALSE); + updated_inventory = 0; } } /* The current implementation has all of the saved lines on the screen. */ -int X11_doprev_message() { return 0; } +int +X11_doprev_message() +{ + return 0; +} void X11_nhbell() { /* We can't use XBell until toplevel has been initialized. */ if (x_inited) - XBell(XtDisplay(toplevel), 0); + XBell(XtDisplay(toplevel), 0); /* else print ^G ?? */ } -void X11_mark_synch() +void +X11_mark_synch() { if (x_inited) { - /* - * The window document is unclear about the status of text - * that has been pline()d but not displayed w/display_nhwindow(). - * Both the main and tty code assume that a pline() followed - * by mark_synch() results in the text being seen, even if - * display_nhwindow() wasn't called. Duplicate this behavior. - */ - if (WIN_MESSAGE != WIN_ERR) - display_message_window(&window_list[WIN_MESSAGE]); - XSync(XtDisplay(toplevel), False); + /* + * The window document is unclear about the status of text + * that has been pline()d but not displayed w/display_nhwindow(). + * Both the main and tty code assume that a pline() followed + * by mark_synch() results in the text being seen, even if + * display_nhwindow() wasn't called. Duplicate this behavior. + */ + if (WIN_MESSAGE != WIN_ERR) + display_message_window(&window_list[WIN_MESSAGE]); + XSync(XtDisplay(toplevel), False); } } -void X11_wait_synch() { if (x_inited) XFlush(XtDisplay(toplevel)); } - +void +X11_wait_synch() +{ + if (x_inited) + XFlush(XtDisplay(toplevel)); +} /* Both resume_ and suspend_ are called from ioctl.c and unixunix.c. */ -void X11_resume_nhwindows() { return; } +void +X11_resume_nhwindows() +{ + return; +} /* ARGSUSED */ -void X11_suspend_nhwindows(str) - const char *str; +void +X11_suspend_nhwindows(str) +const char *str; { nhUse(str); @@ -894,22 +883,31 @@ void X11_suspend_nhwindows(str) /* Under X, we don't need to initialize the number pad. */ /* ARGSUSED */ -void X11_number_pad(state) /* called from options.c */ - int state; +void X11_number_pad(state) /* called from options.c */ +int state; { nhUse(state); return; } -void X11_start_screen() { return; } /* called from setftty() in unixtty.c */ -void X11_end_screen() { return; } /* called from settty() in unixtty.c */ +void +X11_start_screen() +{ + return; +} /* called from setftty() in unixtty.c */ +void +X11_end_screen() +{ + return; +} /* called from settty() in unixtty.c */ #ifdef GRAPHIC_TOMBSTONE -void X11_outrip(window, how, when) - winid window; - int how; - time_t when; +void +X11_outrip(window, how, when) +winid window; +int how; +time_t when; { struct xwindow *wp; @@ -917,89 +915,90 @@ void X11_outrip(window, how, when) wp = &window_list[window]; if (wp->type == NHW_TEXT) { - wp->text_information->is_rip = TRUE; + wp->text_information->is_rip = TRUE; } else { - panic("ripout on non-text window (window type [%d])", wp->type); + panic("ripout on non-text window (window type [%d])", wp->type); } calculate_rip_text(how, when); } #endif -/* init and exit nhwindows ------------------------------------------------- */ +/* init and exit nhwindows ------------------------------------------------- + */ -XtAppContext app_context; /* context of application */ -Widget toplevel = (Widget) 0; /* toplevel widget */ -Atom wm_delete_window; /* pop down windows */ +XtAppContext app_context; /* context of application */ +Widget toplevel = (Widget) 0; /* toplevel widget */ +Atom wm_delete_window; /* pop down windows */ static XtActionsRec actions[] = { - {nhStr("dismiss_file"), dismiss_file}, /* file viewing widget */ - {nhStr("delete_file"), delete_file}, /* file delete-window */ - {nhStr("dismiss_text"), dismiss_text}, /* text widget button action */ - {nhStr("delete_text"), delete_text}, /* text widget delete action */ - {nhStr("key_dismiss_text"), key_dismiss_text}, /* text widget key action */ + { nhStr("dismiss_file"), dismiss_file }, /* file viewing widget */ + { nhStr("delete_file"), delete_file }, /* file delete-window */ + { nhStr("dismiss_text"), dismiss_text }, /* text widget button action */ + { nhStr("delete_text"), delete_text }, /* text widget delete action */ + { nhStr("key_dismiss_text"), + key_dismiss_text }, /* text widget key action */ #ifdef GRAPHIC_TOMBSTONE - {nhStr("rip_dismiss_text"), rip_dismiss_text}, /* rip in text widget */ + { nhStr("rip_dismiss_text"), rip_dismiss_text }, /* rip in text widget */ #endif - {nhStr("menu_key"), menu_key}, /* menu accelerators */ - {nhStr("yn_key"), yn_key}, /* yn accelerators */ - {nhStr("yn_delete"), yn_delete}, /* yn delete-window */ - {nhStr("askname_delete"), askname_delete}, /* askname delete-window */ - {nhStr("getline_delete"), getline_delete}, /* getline delete-window */ - {nhStr("menu_delete"), menu_delete}, /* menu delete-window */ - {nhStr("ec_key"), ec_key}, /* extended commands */ - {nhStr("ec_delete"), ec_delete}, /* ext-com menu delete */ - {nhStr("ps_key"), ps_key}, /* player selection */ - {nhStr("race_key"), race_key}, /* race selection */ - {nhStr("gend_key"), gend_key}, /* gender selection */ - {nhStr("algn_key"), algn_key}, /* alignment selection */ - {nhStr("X11_hangup"), X11_hangup}, /* delete of top-level */ - {nhStr("input"), map_input}, /* key input */ - {nhStr("scroll"), nh_keyscroll}, /* scrolling by keys */ + { nhStr("menu_key"), menu_key }, /* menu accelerators */ + { nhStr("yn_key"), yn_key }, /* yn accelerators */ + { nhStr("yn_delete"), yn_delete }, /* yn delete-window */ + { nhStr("askname_delete"), askname_delete }, /* askname delete-window */ + { nhStr("getline_delete"), getline_delete }, /* getline delete-window */ + { nhStr("menu_delete"), menu_delete }, /* menu delete-window */ + { nhStr("ec_key"), ec_key }, /* extended commands */ + { nhStr("ec_delete"), ec_delete }, /* ext-com menu delete */ + { nhStr("ps_key"), ps_key }, /* player selection */ + { nhStr("race_key"), race_key }, /* race selection */ + { nhStr("gend_key"), gend_key }, /* gender selection */ + { nhStr("algn_key"), algn_key }, /* alignment selection */ + { nhStr("X11_hangup"), X11_hangup }, /* delete of top-level */ + { nhStr("input"), map_input }, /* key input */ + { nhStr("scroll"), nh_keyscroll }, /* scrolling by keys */ }; static XtResource resources[] = { { nhStr("slow"), nhStr("Slow"), XtRBoolean, sizeof(Boolean), - XtOffset(AppResources *,slow), XtRString, nhStr("True") }, + XtOffset(AppResources *, slow), XtRString, nhStr("True") }, { nhStr("autofocus"), nhStr("AutoFocus"), XtRBoolean, sizeof(Boolean), - XtOffset(AppResources *,autofocus), XtRString, nhStr("False") }, + XtOffset(AppResources *, autofocus), XtRString, nhStr("False") }, { nhStr("message_line"), nhStr("Message_line"), XtRBoolean, - sizeof(Boolean), - XtOffset(AppResources *,message_line), XtRString, nhStr("False") }, + sizeof(Boolean), XtOffset(AppResources *, message_line), XtRString, + nhStr("False") }, { nhStr("double_tile_size"), nhStr("Double_tile_size"), XtRBoolean, - sizeof(Boolean), - XtOffset(AppResources *,double_tile_size), XtRString, nhStr("False") }, + sizeof(Boolean), XtOffset(AppResources *, double_tile_size), XtRString, + nhStr("False") }, { nhStr("tile_file"), nhStr("Tile_file"), XtRString, sizeof(String), - XtOffset(AppResources *,tile_file), XtRString, nhStr("x11tiles") }, + XtOffset(AppResources *, tile_file), XtRString, nhStr("x11tiles") }, { nhStr("icon"), nhStr("Icon"), XtRString, sizeof(String), - XtOffset(AppResources *,icon), XtRString, nhStr("nh72") }, + XtOffset(AppResources *, icon), XtRString, nhStr("nh72") }, { nhStr("message_lines"), nhStr("Message_lines"), XtRInt, sizeof(int), - XtOffset(AppResources *,message_lines), XtRString, nhStr("12") }, + XtOffset(AppResources *, message_lines), XtRString, nhStr("12") }, { nhStr("pet_mark_bitmap"), nhStr("Pet_mark_bitmap"), XtRString, - sizeof(String), - XtOffset(AppResources *,pet_mark_bitmap), XtRString, - nhStr("pet_mark.xbm") }, + sizeof(String), XtOffset(AppResources *, pet_mark_bitmap), XtRString, + nhStr("pet_mark.xbm") }, { nhStr("pet_mark_color"), nhStr("Pet_mark_color"), XtRPixel, - sizeof(XtRPixel), - XtOffset(AppResources *,pet_mark_color), XtRString, nhStr("Red") }, + sizeof(XtRPixel), XtOffset(AppResources *, pet_mark_color), XtRString, + nhStr("Red") }, #ifdef GRAPHIC_TOMBSTONE { nhStr("tombstone"), "Tombstone", XtRString, sizeof(String), - XtOffset(AppResources *,tombstone), XtRString, "rip.xpm" }, + XtOffset(AppResources *, tombstone), XtRString, "rip.xpm" }, { nhStr("tombtext_x"), "Tombtext_x", XtRInt, sizeof(int), - XtOffset(AppResources *,tombtext_x), XtRString, "155" }, + XtOffset(AppResources *, tombtext_x), XtRString, "155" }, { nhStr("tombtext_y"), "Tombtext_y", XtRInt, sizeof(int), - XtOffset(AppResources *,tombtext_y), XtRString, "78" }, + XtOffset(AppResources *, tombtext_y), XtRString, "78" }, { nhStr("tombtext_dx"), "Tombtext_dx", XtRInt, sizeof(int), - XtOffset(AppResources *,tombtext_dx), XtRString, "0" }, + XtOffset(AppResources *, tombtext_dx), XtRString, "0" }, { nhStr("tombtext_dy"), "Tombtext_dy", XtRInt, sizeof(int), - XtOffset(AppResources *,tombtext_dy), XtRString, "13" }, + XtOffset(AppResources *, tombtext_dy), XtRString, "13" }, #endif }; void -X11_init_nhwindows(argcp,argv) -int* argcp; -char** argv; +X11_init_nhwindows(argcp, argv) +int *argcp; +char **argv; { int i; Cardinal num_args; @@ -1008,7 +1007,7 @@ char** argv; /* Init windows to nothing. */ for (i = 0; i < MAX_WINDOWS; i++) - window_list[i].type = NHW_NONE; + window_list[i].type = NHW_NONE; /* add another option that can be set */ set_wc_option_mod_status(WC_TILED_MAP, SET_IN_GAME); @@ -1026,103 +1025,103 @@ char** argv; XSetIOErrorHandler((XIOErrorHandler) hangup); num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; - toplevel = XtAppInitialize( - &app_context, - "NetHack", /* application class */ - (XrmOptionDescList)0, 0, /* options list */ - argcp, (String *)argv, /* command line args */ - (String *)0, /* fallback resources */ - (ArgList)args, num_args); - XtOverrideTranslations(toplevel, - XtParseTranslationTable("WM_PROTOCOLS: X11_hangup()")); + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; + toplevel = + XtAppInitialize(&app_context, "NetHack", /* application class */ + (XrmOptionDescList) 0, 0, /* options list */ + argcp, (String *) argv, /* command line args */ + (String *) 0, /* fallback resources */ + (ArgList) args, num_args); + XtOverrideTranslations( + toplevel, + XtParseTranslationTable("WM_PROTOCOLS: X11_hangup()")); - /* We don't need to realize the top level widget. */ +/* We don't need to realize the top level widget. */ #ifdef TEXTCOLOR /* add new color converter to deal with overused colormaps */ XtSetTypeConverter(XtRString, XtRPixel, nhCvtStringToPixel, - (XtConvertArgList)nhcolorConvertArgs, - XtNumber(nhcolorConvertArgs), - XtCacheByDisplay, nhFreePixel); + (XtConvertArgList) nhcolorConvertArgs, + XtNumber(nhcolorConvertArgs), XtCacheByDisplay, + nhFreePixel); #endif /* TEXTCOLOR */ /* Register the actions mentioned in "actions". */ XtAppAddActions(app_context, actions, XtNumber(actions)); /* Get application-wide resources */ - XtGetApplicationResources(toplevel, (XtPointer)&appResources, - resources, XtNumber(resources), - (ArgList)0, ZERO); + XtGetApplicationResources(toplevel, (XtPointer) &appResources, resources, + XtNumber(resources), (ArgList) 0, ZERO); /* Initialize other things. */ init_standard_windows(); /* Give the window manager an icon to use; toplevel must be realized. */ if (appResources.icon && *appResources.icon) { - struct icon_info *ip; + struct icon_info *ip; - for (ip = icon_data; ip->name; ip++) - if (!strcmp(appResources.icon, ip->name)) { - icon_pixmap = XCreateBitmapFromData(XtDisplay(toplevel), - XtWindow(toplevel), - (genericptr_t)ip->bits, ip->width, ip->height); - if (icon_pixmap != None) { - XWMHints hints; + for (ip = icon_data; ip->name; ip++) + if (!strcmp(appResources.icon, ip->name)) { + icon_pixmap = XCreateBitmapFromData( + XtDisplay(toplevel), XtWindow(toplevel), + (genericptr_t) ip->bits, ip->width, ip->height); + if (icon_pixmap != None) { + XWMHints hints; - (void) memset((genericptr_t)&hints, 0, sizeof(XWMHints)); - hints.flags = IconPixmapHint; - hints.icon_pixmap = icon_pixmap; - XSetWMHints(XtDisplay(toplevel), - XtWindow(toplevel), &hints); - } - break; - } + (void) memset((genericptr_t) &hints, 0, sizeof(XWMHints)); + hints.flags = IconPixmapHint; + hints.icon_pixmap = icon_pixmap; + XSetWMHints(XtDisplay(toplevel), XtWindow(toplevel), + &hints); + } + break; + } } /* end of setuid hack: reset uid back to the "games" uid */ (void) seteuid(savuid); - x_inited = TRUE; /* X is now initialized */ + x_inited = TRUE; /* X is now initialized */ /* Display the startup banner in the message window. */ for (i = 1; i <= 4 + 2; ++i) /* (values beyond 4 yield blank lines) */ - X11_putstr(WIN_MESSAGE, 0, copyright_banner_line(i)); + X11_putstr(WIN_MESSAGE, 0, copyright_banner_line(i)); } /* * All done. */ /* ARGSUSED */ -void X11_exit_nhwindows(dummy) - const char *dummy; +void +X11_exit_nhwindows(dummy) +const char *dummy; { - extern Pixmap tile_pixmap; /* from winmap.c */ + extern Pixmap tile_pixmap; /* from winmap.c */ nhUse(dummy); /* explicitly free the icon and tile pixmaps */ if (icon_pixmap != None) { - XFreePixmap(XtDisplay(toplevel), icon_pixmap); - icon_pixmap = None; + XFreePixmap(XtDisplay(toplevel), icon_pixmap); + icon_pixmap = None; } if (tile_pixmap != None) { - XFreePixmap(XtDisplay(toplevel), tile_pixmap); - tile_pixmap = None; + XFreePixmap(XtDisplay(toplevel), tile_pixmap); + tile_pixmap = None; } if (WIN_INVEN != WIN_ERR) - X11_destroy_nhwindow(WIN_INVEN); + X11_destroy_nhwindow(WIN_INVEN); if (WIN_STATUS != WIN_ERR) - X11_destroy_nhwindow(WIN_STATUS); + X11_destroy_nhwindow(WIN_STATUS); if (WIN_MAP != WIN_ERR) - X11_destroy_nhwindow(WIN_MAP); + X11_destroy_nhwindow(WIN_MAP); if (WIN_MESSAGE != WIN_ERR) - X11_destroy_nhwindow(WIN_MESSAGE); + X11_destroy_nhwindow(WIN_MESSAGE); } #ifdef X11_HANGUP_SIGNAL -static void -X11_sig(sig) /* Unix signal handler */ +static void X11_sig(sig) /* Unix signal handler */ int sig; { XtNoticeSignal(X11_sig_id); @@ -1131,8 +1130,8 @@ int sig; static void X11_sig_cb(not_used, id) - XtPointer not_used; - XtSignalId* id; +XtPointer not_used; +XtSignalId *id; { XEvent event; XClientMessageEvent *mesg; @@ -1147,14 +1146,13 @@ X11_sig_cb(not_used, id) mesg->format = 8; XSendEvent(XtDisplay(window_list[WIN_MAP].w), - XtWindow(window_list[WIN_MAP].w), - False, - NoEventMask, - (XEvent*) mesg); + XtWindow(window_list[WIN_MAP].w), False, NoEventMask, + (XEvent *) mesg); } #endif -/* delay_output ------------------------------------------------------------ */ +/* delay_output ------------------------------------------------------------ + */ /* * Timeout callback for delay_output(). Send a fake message to the map @@ -1163,8 +1161,8 @@ X11_sig_cb(not_used, id) /* ARGSUSED */ static void d_timeout(client_data, id) - XtPointer client_data; - XtIntervalId *id; +XtPointer client_data; +XtIntervalId *id; { XEvent event; XClientMessageEvent *mesg; @@ -1178,10 +1176,8 @@ d_timeout(client_data, id) mesg->message_type = XA_STRING; mesg->format = 8; XSendEvent(XtDisplay(window_list[WIN_MAP].w), - XtWindow(window_list[WIN_MAP].w), - False, - NoEventMask, - (XEvent*) mesg); + XtWindow(window_list[WIN_MAP].w), False, NoEventMask, + (XEvent *) mesg); } /* @@ -1193,7 +1189,8 @@ d_timeout(client_data, id) void X11_delay_output() { - if (!x_inited) return; + if (!x_inited) + return; (void) XtAppAddTimeOut(app_context, 30L, d_timeout, (XtPointer) 0); @@ -1201,39 +1198,41 @@ X11_delay_output() (void) x_event(EXIT_ON_SENT_EVENT); } -/* X11_hangup -------------------------------------------------------------- */ +/* X11_hangup -------------------------------------------------------------- + */ /* ARGSUSED */ static void X11_hangup(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(w); nhUse(event); nhUse(params); nhUse(num_params); - hangup(1); /* 1 is commonly SIGHUP, but ignored anyway */ + hangup(1); /* 1 is commonly SIGHUP, but ignored anyway */ exit_x_event = TRUE; } -/* askname ----------------------------------------------------------------- */ +/* askname ----------------------------------------------------------------- + */ /* ARGSUSED */ static void askname_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(event); nhUse(params); nhUse(num_params); nh_XtPopdown(w); - (void) strcpy(plname, "Mumbles"); /* give them a name... ;-) */ + (void) strcpy(plname, "Mumbles"); /* give them a name... ;-) */ exit_x_event = TRUE; } @@ -1241,9 +1240,9 @@ askname_delete(w, event, params, num_params) /* ARGSUSED */ static void askname_done(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; +Widget w; +XtPointer client_data; +XtPointer call_data; { int len; char *s; @@ -1256,13 +1255,13 @@ askname_done(w, client_data, call_data) len = (int) strlen(s); if (len == 0) { - X11_nhbell(); - return; + X11_nhbell(); + return; } /* Truncate name if necessary */ - if (len >= (int) sizeof(plname)-1) - len = (int) sizeof(plname)-1; + if (len >= (int) sizeof(plname) - 1) + len = (int) sizeof(plname) - 1; (void) strncpy(plname, s, len); plname[len] = '\0'; @@ -1280,28 +1279,29 @@ X11_askname() XtSetArg(args[0], XtNallowShellResize, True); - popup = XtCreatePopupShell("askname", transientShellWidgetClass, - toplevel, args, ONE); - XtOverrideTranslations(popup, - XtParseTranslationTable("WM_PROTOCOLS: askname_delete()")); + popup = XtCreatePopupShell("askname", transientShellWidgetClass, toplevel, + args, ONE); + XtOverrideTranslations( + popup, + XtParseTranslationTable("WM_PROTOCOLS: askname_delete()")); - dialog = CreateDialog(popup, nhStr("dialog"), - askname_done, (XtCallbackProc) 0); + dialog = CreateDialog(popup, nhStr("dialog"), askname_done, + (XtCallbackProc) 0); - SetDialogPrompt(dialog, nhStr("What is your name?")); /* set prompt */ - SetDialogResponse(dialog, nhStr("")); /* set default answer */ + SetDialogPrompt(dialog, nhStr("What is your name?")); /* set prompt */ + SetDialogResponse(dialog, nhStr("")); /* set default answer */ XtRealizeWidget(popup); - positionpopup(popup, TRUE); /* center,bottom */ + positionpopup(popup, TRUE); /* center,bottom */ - nh_XtPopup(popup, (int)XtGrabExclusive, dialog); + nh_XtPopup(popup, (int) XtGrabExclusive, dialog); /* The callback will enable the event loop exit. */ (void) x_event(EXIT_ON_EXIT); } - -/* getline ----------------------------------------------------------------- */ +/* getline ----------------------------------------------------------------- + */ /* This uses Tim Theisen's dialog widget set (from GhostView). */ static Widget getline_popup, getline_dialog; @@ -1309,14 +1309,13 @@ static Widget getline_popup, getline_dialog; #define CANCEL_STR "\033" static char *getline_input; - /* Callback for getline dialog widget. */ /* ARGSUSED */ static void done_button(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; +Widget w; +XtPointer client_data; +XtPointer call_data; { int len; char *s; @@ -1329,7 +1328,8 @@ done_button(w, client_data, call_data) len = strlen(s); /* Truncate input if necessary */ - if (len >= BUFSZ) len = BUFSZ - 1; + if (len >= BUFSZ) + len = BUFSZ - 1; (void) strncpy(getline_input, s, len); getline_input[len] = '\0'; @@ -1342,10 +1342,10 @@ done_button(w, client_data, call_data) /* ARGSUSED */ static void getline_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(event); nhUse(params); @@ -1360,9 +1360,9 @@ getline_delete(w, event, params, num_params) /* ARGSUSED */ static void abort_button(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; +Widget w; +XtPointer client_data; +XtPointer call_data; { Widget dialog = (Widget) client_data; @@ -1374,11 +1374,10 @@ abort_button(w, client_data, call_data) exit_x_event = TRUE; } - void X11_getlin(question, input) - const char *question; - char *input; +const char *question; +char *input; { static boolean need_to_init = True; @@ -1386,51 +1385,50 @@ X11_getlin(question, input) flush_screen(1); if (need_to_init) { - Arg args[1]; + Arg args[1]; - need_to_init = False; + need_to_init = False; - XtSetArg(args[0], XtNallowShellResize, True); + XtSetArg(args[0], XtNallowShellResize, True); - getline_popup = XtCreatePopupShell("getline",transientShellWidgetClass, - toplevel, args, ONE); - XtOverrideTranslations(getline_popup, - XtParseTranslationTable("WM_PROTOCOLS: getline_delete()")); + getline_popup = XtCreatePopupShell( + "getline", transientShellWidgetClass, toplevel, args, ONE); + XtOverrideTranslations( + getline_popup, XtParseTranslationTable( + "WM_PROTOCOLS: getline_delete()")); - getline_dialog = CreateDialog(getline_popup, nhStr("dialog"), - done_button, abort_button); + getline_dialog = CreateDialog(getline_popup, nhStr("dialog"), + done_button, abort_button); - XtRealizeWidget(getline_popup); - XSetWMProtocols(XtDisplay(getline_popup), XtWindow(getline_popup), - &wm_delete_window, 1); + XtRealizeWidget(getline_popup); + XSetWMProtocols(XtDisplay(getline_popup), XtWindow(getline_popup), + &wm_delete_window, 1); } - SetDialogPrompt(getline_dialog, (String)question); /* set prompt */ - SetDialogResponse(getline_dialog, nhStr("")); /* set default answer */ - positionpopup(getline_popup, TRUE); /* center,bottom */ + SetDialogPrompt(getline_dialog, (String) question); /* set prompt */ + SetDialogResponse(getline_dialog, nhStr("")); /* set default answer */ + positionpopup(getline_popup, TRUE); /* center,bottom */ - nh_XtPopup(getline_popup, (int)XtGrabExclusive, getline_dialog); + nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog); /* The callback will enable the event loop exit. */ (void) x_event(EXIT_ON_EXIT); } - -/* Display file ------------------------------------------------------------ */ -static const char display_translations[] = - "#override\n\ +/* Display file ------------------------------------------------------------ + */ +static const char display_translations[] = "#override\n\ q: dismiss_file()\n\ Escape: dismiss_file()\n\ : dismiss_file()"; - /* WM_DELETE_WINDOW callback for file dismissal. */ /*ARGSUSED*/ static void delete_file(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(event); nhUse(params); @@ -1444,10 +1442,10 @@ delete_file(w, event, params, num_params) /*ARGSUSED*/ static void dismiss_file(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { Widget popup = XtParent(w); @@ -1461,8 +1459,8 @@ dismiss_file(w, event, params, num_params) void X11_display_file(str, complain) - const char *str; - boolean complain; +const char *str; +boolean complain; { dlb *fp; Arg args[12]; @@ -1481,9 +1479,10 @@ X11_display_file(str, complain) fp = dlb_fopen(str, RDTMODE); if (!fp) { - if(complain) pline("Cannot open %s. Sorry.", str); + if (complain) + pline("Cannot open %s. Sorry.", str); - return; /* it doesn't exist, ignore */ + return; /* it doesn't exist, ignore */ } /* @@ -1492,18 +1491,19 @@ X11_display_file(str, complain) num_lines = 0; charcount = 1; while (dlb_fgets(line, LLEN, fp)) { - num_lines++; - charcount += strlen(line); + num_lines++; + charcount += strlen(line); } (void) dlb_fclose(fp); /* Ignore empty files */ - if (num_lines == 0) return; + if (num_lines == 0) + return; /* If over the max window size, truncate the window size to the max */ if (num_lines >= DISPLAY_FILE_SIZE) - num_lines = DISPLAY_FILE_SIZE; + num_lines = DISPLAY_FILE_SIZE; /* * Re-open the file and read the data into a buffer. Cannot use @@ -1515,83 +1515,94 @@ X11_display_file(str, complain) fp = dlb_fopen(str, RDTMODE); while (dlb_fgets(line, LLEN, fp)) { - (void) strcat(textlines, line); + (void) strcat(textlines, line); } (void) dlb_fclose(fp); num_args = 0; - XtSetArg(args[num_args], nhStr(XtNtitle), str); num_args++; + XtSetArg(args[num_args], nhStr(XtNtitle), str); + num_args++; popup = XtCreatePopupShell("display_file", topLevelShellWidgetClass, - toplevel, args, num_args); - XtOverrideTranslations(popup, - XtParseTranslationTable("WM_PROTOCOLS: delete_file()")); + toplevel, args, num_args); + XtOverrideTranslations( + popup, + XtParseTranslationTable("WM_PROTOCOLS: delete_file()")); num_args = 0; XtSetArg(args[num_args], nhStr(XtNscrollHorizontal), - XawtextScrollWhenNeeded); num_args++; - XtSetArg(args[num_args], nhStr(XtNscrollVertical), - XawtextScrollAlways); num_args++; - XtSetArg(args[num_args], nhStr(XtNtype), XawAsciiString); num_args++; - XtSetArg(args[num_args], nhStr(XtNstring), textlines); num_args++; - XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++; + XawtextScrollWhenNeeded); + num_args++; + XtSetArg(args[num_args], nhStr(XtNscrollVertical), XawtextScrollAlways); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtype), XawAsciiString); + num_args++; + XtSetArg(args[num_args], nhStr(XtNstring), textlines); + num_args++; + XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); + num_args++; XtSetArg(args[num_args], nhStr(XtNtranslations), - XtParseTranslationTable(display_translations)); num_args++; + XtParseTranslationTable(display_translations)); + num_args++; - dispfile = XtCreateManagedWidget( - "text", /* name */ - asciiTextWidgetClass, - popup, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + dispfile = + XtCreateManagedWidget("text", /* name */ + asciiTextWidgetClass, popup, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ /* Get font and border information. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfont), &fs); num_args++; - XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottomMargin), - &bottom_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin); num_args++; + XtSetArg(args[num_args], nhStr(XtNfont), &fs); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin); + num_args++; XtGetValues(dispfile, args, num_args); /* * The data files are currently set up assuming an 80 char wide window * and a fixed width font. Soo.. */ - new_height = num_lines * nhFontHeight(dispfile) + - top_margin + bottom_margin; - new_width = 80 * fs->max_bounds.width + left_margin + right_margin; + new_height = + num_lines * nhFontHeight(dispfile) + top_margin + bottom_margin; + new_width = 80 * fs->max_bounds.width + left_margin + right_margin; /* Set the new width and height. */ num_args = 0; - XtSetArg(args[num_args], XtNwidth, new_width); num_args++; - XtSetArg(args[num_args], XtNheight, new_height); num_args++; + XtSetArg(args[num_args], XtNwidth, new_width); + num_args++; + XtSetArg(args[num_args], XtNheight, new_height); + num_args++; XtSetValues(dispfile, args, num_args); - nh_XtPopup(popup, (int)XtGrabNone, (Widget)0); + nh_XtPopup(popup, (int) XtGrabNone, (Widget) 0); free(textlines); } - -/* yn_function ------------------------------------------------------------- */ +/* yn_function ------------------------------------------------------------- + */ /* (not threaded) */ static const char *yn_quitchars = " \n\r"; -static const char *yn_choices; /* string of acceptable input */ +static const char *yn_choices; /* string of acceptable input */ static char yn_def; -static char yn_return; /* return value */ -static char yn_esc_map; /* ESC maps to this char. */ -static Widget yn_popup; /* popup for the yn fuction (created once) */ -static Widget yn_label; /* label for yn function (created once) */ -static boolean yn_getting_num; /* TRUE if accepting digits */ +static char yn_return; /* return value */ +static char yn_esc_map; /* ESC maps to this char. */ +static Widget yn_popup; /* popup for the yn fuction (created once) */ +static Widget yn_label; /* label for yn function (created once) */ +static boolean yn_getting_num; /* TRUE if accepting digits */ static boolean yn_preserve_case; /* default is to force yn to lower case */ -static int yn_ndigits; /* digit count */ -static long yn_val; /* accumulated value */ +static int yn_ndigits; /* digit count */ +static long yn_val; /* accumulated value */ -static const char yn_translations[] = - "#override\n\ +static const char yn_translations[] = "#override\n\ : yn_key()"; /* @@ -1601,17 +1612,18 @@ static const char yn_translations[] = */ char key_event_to_char(key) - XKeyEvent *key; +XKeyEvent *key; { char keystring[MAX_KEY_STRING]; int nbytes; boolean meta = !!(key->state & Mod1Mask); - nbytes = XLookupString(key, keystring, MAX_KEY_STRING, - (KeySym *)0, (XComposeStatus *)0); + nbytes = XLookupString(key, keystring, MAX_KEY_STRING, (KeySym *) 0, + (XComposeStatus *) 0); /* Modifier keys return a zero lengh string when pressed. */ - if (nbytes == 0) return '\0'; + if (nbytes == 0) + return '\0'; return (char) (((int) keystring[0]) + (meta ? 0x80 : 0)); } @@ -1622,10 +1634,10 @@ key_event_to_char(key) /* ARGSUSED */ static void yn_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(w); nhUse(event); @@ -1635,7 +1647,7 @@ yn_delete(w, event, params, num_params) yn_getting_num = FALSE; /* Only use yn_esc_map if we have choices. Otherwise, return ESC. */ yn_return = yn_choices ? yn_esc_map : '\033'; - exit_x_event = TRUE; /* exit our event handler */ + exit_x_event = TRUE; /* exit our event handler */ } /* @@ -1644,88 +1656,90 @@ yn_delete(w, event, params, num_params) /* ARGSUSED */ static void yn_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch; - if(appResources.slow && !input_func) - map_input(w, event, params, num_params); + if (appResources.slow && !input_func) + map_input(w, event, params, num_params); ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char or modifier event */ - /* no bell */ - return; + if (ch == '\0') { /* don't accept nul char or modifier event */ + /* no bell */ + return; } - if (!yn_choices) { /* accept any input */ - yn_return = ch; + if (!yn_choices) { /* accept any input */ + yn_return = ch; } else { - if (!yn_preserve_case) - ch = lowc(ch); /* move to lower case */ + if (!yn_preserve_case) + ch = lowc(ch); /* move to lower case */ - if (ch == '\033') { - yn_getting_num = FALSE; - yn_return = yn_esc_map; - } else if (index(yn_quitchars, ch)) { - yn_return = yn_def; - } else if (index(yn_choices, ch)) { - if (ch == '#') { - if (yn_getting_num) { /* don't select again */ - X11_nhbell(); - return; - } - yn_getting_num = TRUE; - yn_ndigits = 0; - yn_val = 0; - return; /* wait for more input */ - } - yn_return = ch; - if (ch != 'y') yn_getting_num = FALSE; - } else { - if (yn_getting_num) { - if (digit(ch)) { - yn_ndigits++; - yn_val = (yn_val * 10) + (long) (ch - '0'); - return; /* wait for more input */ - } - if (yn_ndigits && (ch == '\b' || ch == 127/*DEL*/)) { - yn_ndigits--; - yn_val = yn_val/ 10; - return; /* wait for more input */ - } - } - X11_nhbell(); /* no match */ - return; - } + if (ch == '\033') { + yn_getting_num = FALSE; + yn_return = yn_esc_map; + } else if (index(yn_quitchars, ch)) { + yn_return = yn_def; + } else if (index(yn_choices, ch)) { + if (ch == '#') { + if (yn_getting_num) { /* don't select again */ + X11_nhbell(); + return; + } + yn_getting_num = TRUE; + yn_ndigits = 0; + yn_val = 0; + return; /* wait for more input */ + } + yn_return = ch; + if (ch != 'y') + yn_getting_num = FALSE; + } else { + if (yn_getting_num) { + if (digit(ch)) { + yn_ndigits++; + yn_val = (yn_val * 10) + (long) (ch - '0'); + return; /* wait for more input */ + } + if (yn_ndigits && (ch == '\b' || ch == 127 /*DEL*/)) { + yn_ndigits--; + yn_val = yn_val / 10; + return; /* wait for more input */ + } + } + X11_nhbell(); /* no match */ + return; + } - if (yn_getting_num) { - yn_return = '#'; - if (yn_val < 0) yn_val = 0; - yn_number = yn_val; /* assign global */ - } + if (yn_getting_num) { + yn_return = '#'; + if (yn_val < 0) + yn_val = 0; + yn_number = yn_val; /* assign global */ + } } - exit_x_event = TRUE; /* exit our event handler */ + exit_x_event = TRUE; /* exit our event handler */ } - char X11_yn_function(ques, choices, def) - const char *ques; - const char *choices; - char def; +const char *ques; +const char *choices; +char def; { static Boolean need_to_init = True; char buf[BUFSZ]; Arg args[4]; Cardinal num_args; - yn_choices = choices; /* set up globals for callback to use */ - yn_def = def; - yn_preserve_case = !choices; /* preserve when arbitrary response allowed */ + yn_choices = choices; /* set up globals for callback to use */ + yn_def = def; + yn_preserve_case = + !choices; /* preserve when arbitrary response allowed */ /* * This is sort of a kludge. There are quite a few places in the main @@ -1735,93 +1749,97 @@ X11_yn_function(ques, choices, def) * up for us! Solution: do our own flush. */ if (WIN_MESSAGE != WIN_ERR) - display_message_window(&window_list[WIN_MESSAGE]); + display_message_window(&window_list[WIN_MESSAGE]); if (choices) { - char *cb, choicebuf[QBUFSZ]; + char *cb, choicebuf[QBUFSZ]; - Strcpy(choicebuf, choices); /* anything beyond is hidden */ - /* default when choices are present is to force yn answer to - lowercase unless one or more choices are explicitly uppercase; - check this before stripping the hidden choices */ - for (cb = choicebuf; *cb; ++cb) - if ('A' <= *cb && *cb <= 'Z') { - yn_preserve_case = TRUE; - break; - } - if ((cb = index(choicebuf, '\033')) != 0) *cb = '\0'; - /* ques [choices] (def) */ - if ((int)(1 + strlen(ques) + 2 + strlen(choicebuf) + 4) >= BUFSZ) - panic("X11_yn_function: question too long"); - (void)strncpy(buf, ques, QBUFSZ-1); - buf[QBUFSZ-1] = '\0'; - Sprintf(eos(buf), " [%s]", choicebuf); - if (def) Sprintf(eos(buf), " (%c)", def); - Strcat(buf, " "); + Strcpy(choicebuf, choices); /* anything beyond is hidden */ + /* default when choices are present is to force yn answer to + lowercase unless one or more choices are explicitly uppercase; + check this before stripping the hidden choices */ + for (cb = choicebuf; *cb; ++cb) + if ('A' <= *cb && *cb <= 'Z') { + yn_preserve_case = TRUE; + break; + } + if ((cb = index(choicebuf, '\033')) != 0) + *cb = '\0'; + /* ques [choices] (def) */ + if ((int) (1 + strlen(ques) + 2 + strlen(choicebuf) + 4) >= BUFSZ) + panic("X11_yn_function: question too long"); + (void) strncpy(buf, ques, QBUFSZ - 1); + buf[QBUFSZ - 1] = '\0'; + Sprintf(eos(buf), " [%s]", choicebuf); + if (def) + Sprintf(eos(buf), " (%c)", def); + Strcat(buf, " "); - /* escape maps to 'q' or 'n' or default, in that order */ - yn_esc_map = (index(choices, 'q') ? 'q' : - (index(choices, 'n') ? 'n' : - def)); + /* escape maps to 'q' or 'n' or default, in that order */ + yn_esc_map = + (index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def)); } else { - if ((int)(1 + strlen(ques) + 1) >= BUFSZ) - panic("X11_yn_function: question too long"); - Strcpy(buf, ques); - Strcat(buf, " "); + if ((int) (1 + strlen(ques) + 1) >= BUFSZ) + panic("X11_yn_function: question too long"); + Strcpy(buf, ques); + Strcat(buf, " "); } if (!appResources.slow && need_to_init) { - need_to_init = False; + need_to_init = False; - XtSetArg(args[0], XtNallowShellResize, True); - yn_popup = XtCreatePopupShell("query", transientShellWidgetClass, - toplevel, args, ONE); - XtOverrideTranslations(yn_popup, - XtParseTranslationTable("WM_PROTOCOLS: yn_delete()")); + XtSetArg(args[0], XtNallowShellResize, True); + yn_popup = XtCreatePopupShell("query", transientShellWidgetClass, + toplevel, args, ONE); + XtOverrideTranslations( + yn_popup, + XtParseTranslationTable("WM_PROTOCOLS: yn_delete()")); - num_args = 0; - XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(yn_translations)); num_args++; - yn_label = XtCreateManagedWidget("yn_label", - labelWidgetClass, - yn_popup, - args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNtranslations, + XtParseTranslationTable(yn_translations)); + num_args++; + yn_label = XtCreateManagedWidget("yn_label", labelWidgetClass, + yn_popup, args, num_args); - XtRealizeWidget(yn_popup); - XSetWMProtocols(XtDisplay(yn_popup), XtWindow(yn_popup), - &wm_delete_window, 1); + XtRealizeWidget(yn_popup); + XSetWMProtocols(XtDisplay(yn_popup), XtWindow(yn_popup), + &wm_delete_window, 1); } - if(appResources.slow) - input_func = yn_key; + if (appResources.slow) + input_func = yn_key; num_args = 0; - XtSetArg(args[num_args], XtNlabel, buf); num_args++; + XtSetArg(args[num_args], XtNlabel, buf); + num_args++; XtSetValues(yn_label, args, num_args); - if(!appResources.slow) { - /* - * Due to some kind of weird bug in the X11R4 and X11R5 shell, we - * need to set the label twice to get the size to change. - */ - num_args = 0; - XtSetArg(args[num_args], XtNlabel, buf); num_args++; - XtSetValues(yn_label, args, num_args); + if (!appResources.slow) { + /* + * Due to some kind of weird bug in the X11R4 and X11R5 shell, we + * need to set the label twice to get the size to change. + */ + num_args = 0; + XtSetArg(args[num_args], XtNlabel, buf); + num_args++; + XtSetValues(yn_label, args, num_args); - positionpopup(yn_popup, TRUE); - nh_XtPopup(yn_popup, (int)XtGrabExclusive, yn_label); + positionpopup(yn_popup, TRUE); + nh_XtPopup(yn_popup, (int) XtGrabExclusive, yn_label); } yn_getting_num = FALSE; (void) x_event(EXIT_ON_EXIT); - if(appResources.slow) { - input_func = 0; - num_args = 0; - XtSetArg(args[num_args], XtNlabel, " "); num_args++; - XtSetValues(yn_label, args, num_args); + if (appResources.slow) { + input_func = 0; + num_args = 0; + XtSetArg(args[num_args], XtNlabel, " "); + num_args++; + XtSetValues(yn_label, args, num_args); } else { - nh_XtPopdown(yn_popup); /* this removes the event grab */ + nh_XtPopdown(yn_popup); /* this removes the event grab */ } return yn_return; @@ -1830,15 +1848,16 @@ X11_yn_function(ques, choices, def) /*ARGSUSED*/ void X11_preference_update(pref) - const char *pref; +const char *pref; { if (!strcmp(pref, "tiled_map")) { - if (WIN_MAP != WIN_ERR) - display_map_window(&window_list[WIN_MAP]); + if (WIN_MAP != WIN_ERR) + display_map_window(&window_list[WIN_MAP]); } } -/* End global functions ==================================================== */ +/* End global functions ==================================================== + */ /* * Before we wait for input via nhgetch() and nh_poskey(), we need to @@ -1846,53 +1865,51 @@ X11_preference_update(pref) */ static int input_event(exit_condition) - int exit_condition; +int exit_condition; { - if (WIN_STATUS != WIN_ERR) /* hilighting on the fancy status window */ - check_turn_events(); - if (WIN_MAP != WIN_ERR) /* make sure cursor is not clipped */ - check_cursor_visibility(&window_list[WIN_MAP]); - if (WIN_MESSAGE != WIN_ERR) /* reset pause line */ - set_last_pause(&window_list[WIN_MESSAGE]); + if (WIN_STATUS != WIN_ERR) /* hilighting on the fancy status window */ + check_turn_events(); + if (WIN_MAP != WIN_ERR) /* make sure cursor is not clipped */ + check_cursor_visibility(&window_list[WIN_MAP]); + if (WIN_MESSAGE != WIN_ERR) /* reset pause line */ + set_last_pause(&window_list[WIN_MESSAGE]); return x_event(exit_condition); } - /*ARGSUSED*/ void msgkey(w, data, event) - Widget w; - XtPointer data; - XEvent *event; +Widget w; +XtPointer data; +XEvent *event; { Cardinal num = 0; nhUse(w); nhUse(data); - map_input(window_list[WIN_MAP].w, event, (String*) 0, &num); + map_input(window_list[WIN_MAP].w, event, (String *) 0, &num); } /*ARGSUSED*/ -static void -win_visible(w, data, event, flag) /* only called for autofocus */ - Widget w; - XtPointer data; /* client_data not used */ - XEvent *event; - Boolean *flag; /* continue_to_dispatch flag not used */ +static void win_visible(w, data, event, flag) /* only called for autofocus */ +Widget w; +XtPointer data; /* client_data not used */ +XEvent *event; +Boolean *flag; /* continue_to_dispatch flag not used */ { - XVisibilityEvent *vis_event = (XVisibilityEvent *)event; + XVisibilityEvent *vis_event = (XVisibilityEvent *) event; nhUse(data); nhUse(flag); if (vis_event->state != VisibilityFullyObscured) { - /* one-time operation; cancel ourself */ - XtRemoveEventHandler(toplevel, VisibilityChangeMask, False, - win_visible, (XtPointer) 0); - /* grab initial input focus */ - XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToNone, CurrentTime); + /* one-time operation; cancel ourself */ + XtRemoveEventHandler(toplevel, VisibilityChangeMask, False, + win_visible, (XtPointer) 0); + /* grab initial input focus */ + XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToNone, CurrentTime); } } @@ -1910,19 +1927,18 @@ init_standard_windows() int map_vp_hd, status_hd; struct xwindow *wp; - num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; - form = XtCreateManagedWidget("nethack", - panedWidgetClass, - toplevel, args, num_args); + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; + form = XtCreateManagedWidget("nethack", panedWidgetClass, toplevel, args, + num_args); - XtAddEventHandler(form, KeyPressMask, False, - (XtEventHandler) msgkey, (XtPointer) 0); + XtAddEventHandler(form, KeyPressMask, False, (XtEventHandler) msgkey, + (XtPointer) 0); if (appResources.autofocus) - XtAddEventHandler(toplevel, VisibilityChangeMask, False, - win_visible, (XtPointer) 0); + XtAddEventHandler(toplevel, VisibilityChangeMask, False, win_visible, + (XtPointer) 0); /* * Create message window. @@ -1934,30 +1950,33 @@ init_standard_windows() create_message_window(wp, FALSE, form); message_viewport = XtParent(wp->w); - /* Tell the form that contains it that resizes are OK. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; XtSetValues(message_viewport, args, num_args); - if(appResources.slow) { - num_args = 0; - XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(yn_translations)); num_args++; - yn_label = XtCreateManagedWidget("yn_label", - labelWidgetClass, - form, - args, num_args); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), - message_viewport); num_args++; - XtSetArg(args[num_args], nhStr(XtNjustify), - XtJustifyLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNlabel), " "); num_args++; - XtSetValues(yn_label, args, num_args); + if (appResources.slow) { + num_args = 0; + XtSetArg(args[num_args], XtNtranslations, + XtParseTranslationTable(yn_translations)); + num_args++; + yn_label = XtCreateManagedWidget("yn_label", labelWidgetClass, form, + args, num_args); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), message_viewport); + num_args++; + XtSetArg(args[num_args], nhStr(XtNjustify), XtJustifyLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNresizable), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNlabel), " "); + num_args++; + XtSetValues(yn_label, args, num_args); } /* @@ -1973,13 +1992,15 @@ init_standard_windows() /* Chain beneath message_viewport or yn window. */ num_args = 0; - if(appResources.slow) { - XtSetArg(args[num_args], nhStr(XtNfromVert), yn_label); num_args++; + if (appResources.slow) { + XtSetArg(args[num_args], nhStr(XtNfromVert), yn_label); + num_args++; } else { - XtSetArg(args[num_args], nhStr(XtNfromVert), - message_viewport); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), message_viewport); + num_args++; } - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); + num_args++; XtSetValues(map_viewport, args, num_args); /* Create the status window, with the form as it's parent. */ @@ -1998,14 +2019,18 @@ init_standard_windows() * will never expand or contract. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), map_viewport); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainBottom); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), map_viewport); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainBottom); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); + num_args++; XtSetValues(status, args, num_args); - /* * Realize the popup so that the status widget knows it's size. * @@ -2015,10 +2040,10 @@ init_standard_windows() */ /* XtSetMappedWhenManaged(toplevel, False); */ XtRealizeWidget(toplevel); - wm_delete_window = XInternAtom(XtDisplay(toplevel), - "WM_DELETE_WINDOW", False); + wm_delete_window = + XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False); XSetWMProtocols(XtDisplay(toplevel), XtWindow(toplevel), - &wm_delete_window, 1); + &wm_delete_window, 1); /* * Resize to at most full-screen. @@ -2026,25 +2051,25 @@ init_standard_windows() { #define TITLEBAR_SPACE 18 /* Leave SOME screen for window decorations */ - int screen_width = WidthOfScreen(XtScreen(wp->w)); - int screen_height = HeightOfScreen(XtScreen(wp->w)) - TITLEBAR_SPACE; - Dimension form_width, form_height; + int screen_width = WidthOfScreen(XtScreen(wp->w)); + int screen_height = HeightOfScreen(XtScreen(wp->w)) - TITLEBAR_SPACE; + Dimension form_width, form_height; - XtSetArg(args[0], XtNwidth, &form_width); - XtSetArg(args[1], XtNheight, &form_height); - XtGetValues(toplevel, args, TWO); - - if (form_width > screen_width || form_height > screen_height) { - XtSetArg(args[0], XtNwidth, min(form_width,screen_width)); - XtSetArg(args[1], XtNheight, min(form_height,screen_height)); - XtSetValues(toplevel, args, TWO); - XMoveWindow(XtDisplay(toplevel),XtWindow(toplevel), - 0, TITLEBAR_SPACE); - } + XtSetArg(args[0], XtNwidth, &form_width); + XtSetArg(args[1], XtNheight, &form_height); + XtGetValues(toplevel, args, TWO); + + if (form_width > screen_width || form_height > screen_height) { + XtSetArg(args[0], XtNwidth, min(form_width, screen_width)); + XtSetArg(args[1], XtNheight, min(form_height, screen_height)); + XtSetValues(toplevel, args, TWO); + XMoveWindow(XtDisplay(toplevel), XtWindow(toplevel), 0, + TITLEBAR_SPACE); + } #undef TITLEBAR_SPACE } - post_process_tiles(); /* after toplevel is realized */ + post_process_tiles(); /* after toplevel is realized */ /* * Now get the default widths of the windows. @@ -2064,20 +2089,20 @@ init_standard_windows() * their horizDistance. */ if (map_vp_width < status_width || map_vp_width < message_vp_width) { - if (status_width > message_vp_width) { - XtSetArg(args[0], nhStr(XtNwidth), status_width); - XtSetValues(message_viewport, args, ONE); - max_width = status_width; - } else { - max_width = message_vp_width; - } - XtSetArg(args[0], nhStr(XtNhorizDistance), - map_vp_hd + ((int)(max_width - map_vp_width) / 2)); - XtSetValues(map_viewport, args, ONE); + if (status_width > message_vp_width) { + XtSetArg(args[0], nhStr(XtNwidth), status_width); + XtSetValues(message_viewport, args, ONE); + max_width = status_width; + } else { + max_width = message_vp_width; + } + XtSetArg(args[0], nhStr(XtNhorizDistance), + map_vp_hd + ((int) (max_width - map_vp_width) / 2)); + XtSetValues(map_viewport, args, ONE); - } else { /* map is widest */ - XtSetArg(args[0], nhStr(XtNwidth), map_vp_width); - XtSetValues(message_viewport, args, ONE); + } else { /* map is widest */ + XtSetArg(args[0], nhStr(XtNwidth), map_vp_width); + XtSetValues(message_viewport, args, ONE); } /* * Clear all data values on the fancy status widget so that the values @@ -2103,31 +2128,33 @@ init_standard_windows() iflags.window_inited = 1; } - void nh_XtPopup(w, g, childwid) - Widget w; /* widget */ - int g; /* type of grab */ - Widget childwid; /* child to recieve focus (can be None) */ +Widget w; /* widget */ +int g; /* type of grab */ +Widget childwid; /* child to recieve focus (can be None) */ { - XtPopup(w, (XtGrabKind)g); + XtPopup(w, (XtGrabKind) g); XSetWMProtocols(XtDisplay(w), XtWindow(w), &wm_delete_window, 1); - if (appResources.autofocus) XtSetKeyboardFocus(toplevel, childwid); + if (appResources.autofocus) + XtSetKeyboardFocus(toplevel, childwid); } void nh_XtPopdown(w) - Widget w; +Widget w; { XtPopdown(w); - if (appResources.autofocus) XtSetKeyboardFocus(toplevel, None); + if (appResources.autofocus) + XtSetKeyboardFocus(toplevel, None); } void win_X11_init(dir) - int dir; +int dir; { - if(dir != WININIT) return; + if (dir != WININIT) + return; #ifdef OPENWINBUG /* With the OpenWindows 3.0 libraries and the SunOS 4.1.2 ld, these @@ -2138,9 +2165,9 @@ win_X11_init(dir) * static linking, we do this. */ if (rn2(2) > 2) { - /* i.e., FALSE that an optimizer probably can't find */ - get_wmShellWidgetClass(); - get_applicationShellWidgetClass(); + /* i.e., FALSE that an optimizer probably can't find */ + get_wmShellWidgetClass(); + get_applicationShellWidgetClass(); } #endif return; @@ -2152,10 +2179,10 @@ win_X11_init(dir) /*ARGSUSED*/ void nh_keyscroll(viewport, event, params, num_params) - Widget viewport; - XEvent *event; - String *params; - Cardinal *num_params; +Widget viewport; +XEvent *event; +String *params; +Cardinal *num_params; { Arg arg[2]; Widget horiz_sb, vert_sb; @@ -2166,70 +2193,88 @@ nh_keyscroll(viewport, event, params, num_params) nhUse(event); - if (in_nparams != 1) return; /* bad translation */ + if (in_nparams != 1) + return; /* bad translation */ - direction=atoi(params[0]); + direction = atoi(params[0]); horiz_sb = XtNameToWidget(viewport, "*horizontal"); - vert_sb = XtNameToWidget(viewport, "*vertical"); + vert_sb = XtNameToWidget(viewport, "*vertical"); if (!horiz_sb && !vert_sb) { - /* Perhaps the widget enclosing this has scrollbars (could use while) */ - Widget parent=XtParent(viewport); - if (parent) { - horiz_sb = XtNameToWidget(parent, "horizontal"); - vert_sb = XtNameToWidget(parent, "vertical"); - } + /* Perhaps the widget enclosing this has scrollbars (could use while) + */ + Widget parent = XtParent(viewport); + if (parent) { + horiz_sb = XtNameToWidget(parent, "horizontal"); + vert_sb = XtNameToWidget(parent, "vertical"); + } } -#define H_DELTA 0.25 /* distance of horiz shift */ - /* vert shift is half of curr distance */ -/* The V_DELTA is 1/2 the value of shown. */ +#define H_DELTA 0.25 /* distance of horiz shift */ + /* vert shift is half of curr distance */ + /* The V_DELTA is 1/2 the value of shown. */ if (horiz_sb) { - XtSetArg(arg[0], nhStr(XtNshown), &shown); - XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); - XtGetValues(horiz_sb, arg, TWO); + XtSetArg(arg[0], nhStr(XtNshown), &shown); + XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); + XtGetValues(horiz_sb, arg, TWO); - do_call = True; + do_call = True; - switch (direction) { - case 1: case 4: case 7: - top -= H_DELTA; - if (top < 0.0) top = 0.0; - break; case 3: case 6: case 9: - top += H_DELTA; - if (top + shown > 1.0) top = 1.0 - shown; - break; default: - do_call = False; - } + switch (direction) { + case 1: + case 4: + case 7: + top -= H_DELTA; + if (top < 0.0) + top = 0.0; + break; + case 3: + case 6: + case 9: + top += H_DELTA; + if (top + shown > 1.0) + top = 1.0 - shown; + break; + default: + do_call = False; + } - if (do_call) { - XtCallCallbacks(horiz_sb, XtNjumpProc, &top); - } + if (do_call) { + XtCallCallbacks(horiz_sb, XtNjumpProc, &top); + } } if (vert_sb) { - XtSetArg(arg[0], nhStr(XtNshown), &shown); - XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); - XtGetValues(vert_sb, arg, TWO); + XtSetArg(arg[0], nhStr(XtNshown), &shown); + XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); + XtGetValues(vert_sb, arg, TWO); - do_call = True; + do_call = True; - switch (direction) { - case 7: case 8: case 9: - top -= shown / 2.0; - if (top < 0.0) top = 0; - break; case 1: case 2: case 3: - top += shown / 2.0; - if (top + shown > 1.0) top = 1.0 - shown; - break; default: - do_call = False; - } + switch (direction) { + case 7: + case 8: + case 9: + top -= shown / 2.0; + if (top < 0.0) + top = 0; + break; + case 1: + case 2: + case 3: + top += shown / 2.0; + if (top + shown > 1.0) + top = 1.0 - shown; + break; + default: + do_call = False; + } - if (do_call) { - XtCallCallbacks(vert_sb, XtNjumpProc, &top); - } + if (do_call) { + XtCallCallbacks(vert_sb, XtNjumpProc, &top); + } } } diff --git a/win/X11/winmap.c b/win/X11/winmap.c index 67c81fefa..61e5f9c31 100644 --- a/win/X11/winmap.c +++ b/win/X11/winmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winmap.c $NHDT-Date: 1430899135 2015/05/06 07:58:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */ +/* NetHack 3.6 winmap.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */ /* NetHack 3.6 winmap.c $Date: 2009/05/06 10:55:49 $ $Revision: 1.14 $ */ /* SCCS Id: @(#)winmap.c 3.5 2005/11/12 */ /* Copyright (c) Dean Luick, 1992 */ @@ -18,7 +18,7 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -30,13 +30,13 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif -#include "xwindow.h" /* map widget declarations */ +#include "xwindow.h" /* map widget declarations */ #include "hack.h" #include "dlb.h" @@ -46,92 +46,96 @@ #include #endif - /* from tile.c */ extern short glyph2tile[]; extern int total_tiles_used; /* Define these if you really want a lot of junk on your screen. */ -/* #define VERBOSE */ /* print various info & events as they happen */ -/* #define VERBOSE_UPDATE */ /* print screen update bounds */ -/* #define VERBOSE_INPUT */ /* print input events */ - - -#define USE_WHITE /* almost always use white as a tile cursor border */ +/* #define VERBOSE */ /* print various info & events as they happen */ +/* #define VERBOSE_UPDATE */ /* print screen update bounds */ +/* #define VERBOSE_INPUT */ /* print input events */ +#define USE_WHITE /* almost always use white as a tile cursor border */ static boolean FDECL(init_tiles, (struct xwindow *)); -static void FDECL(set_button_values, (Widget,int,int,unsigned)); +static void FDECL(set_button_values, (Widget, int, int, unsigned)); static void FDECL(map_check_size_change, (struct xwindow *)); -static void FDECL(map_update, (struct xwindow *,int,int,int,int,BOOLEAN_P)); +static void FDECL(map_update, + (struct xwindow *, int, int, int, int, BOOLEAN_P)); static void FDECL(init_text, (struct xwindow *)); -static void FDECL(map_exposed, (Widget,XtPointer,XtPointer)); -static void FDECL(set_gc, (Widget,Font,const char *,Pixel,GC *,GC *)); -static void FDECL(get_text_gc, (struct xwindow *,Font)); +static void FDECL(map_exposed, (Widget, XtPointer, XtPointer)); +static void FDECL(set_gc, (Widget, Font, const char *, Pixel, GC *, GC *)); +static void FDECL(get_text_gc, (struct xwindow *, Font)); static void FDECL(get_char_info, (struct xwindow *)); static void FDECL(display_cursor, (struct xwindow *)); -/* Global functions ======================================================== */ +/* Global functions ======================================================== + */ void X11_print_glyph(window, x, y, glyph) - winid window; - xchar x, y; - int glyph; +winid window; +xchar x, y; +int glyph; { struct map_info_t *map_info; boolean update_bbox = FALSE; check_winid(window); if (window_list[window].type != NHW_MAP) { - impossible("print_glyph: can (currently) only print to map windows"); - return; + impossible("print_glyph: can (currently) only print to map windows"); + return; } map_info = window_list[window].map_information; /* update both the tile and text backing stores */ { - unsigned short *t_ptr = &map_info->tile_map.glyphs[y][x]; + unsigned short *t_ptr = &map_info->tile_map.glyphs[y][x]; - if (*t_ptr != glyph) { - *t_ptr = glyph; - if (map_info->is_tile) update_bbox = TRUE; - } + if (*t_ptr != glyph) { + *t_ptr = glyph; + if (map_info->is_tile) + update_bbox = TRUE; + } } { - uchar ch; - register unsigned char *ch_ptr; - int color,och; - unsigned special; + uchar ch; + register unsigned char *ch_ptr; + int color, och; + unsigned special; #ifdef TEXTCOLOR - register unsigned char *co_ptr; + register unsigned char *co_ptr; #endif - /* map glyph to character and color */ - (void)mapglyph(glyph, &och, &color, &special, x, y); - ch = (uchar)och; - - /* Only update if we need to. */ - ch_ptr = &map_info->text_map.text[y][x]; + /* map glyph to character and color */ + (void) mapglyph(glyph, &och, &color, &special, x, y); + ch = (uchar) och; + + /* Only update if we need to. */ + ch_ptr = &map_info->text_map.text[y][x]; #ifdef TEXTCOLOR - co_ptr = &map_info->text_map.colors[y][x]; - if (*ch_ptr != ch || *co_ptr != color) + co_ptr = &map_info->text_map.colors[y][x]; + if (*ch_ptr != ch || *co_ptr != color) #else - if (*ch_ptr != ch) + if (*ch_ptr != ch) #endif - { - *ch_ptr = ch; + { + *ch_ptr = ch; #ifdef TEXTCOLOR - if ((special & MG_PET) && iflags.hilite_pet) color += CLR_MAX; - *co_ptr = color; + if ((special & MG_PET) && iflags.hilite_pet) + color += CLR_MAX; + *co_ptr = color; #endif - if (!map_info->is_tile) update_bbox = TRUE; - } + if (!map_info->is_tile) + update_bbox = TRUE; + } } - if (update_bbox) { /* update row bbox */ - if ((uchar) x < map_info->t_start[y]) map_info->t_start[y] = x; - if ((uchar) x > map_info->t_stop[y]) map_info->t_stop[y] = x; + if (update_bbox) { /* update row bbox */ + if ((uchar) x < map_info->t_start[y]) + map_info->t_start[y] = x; + if ((uchar) x > map_info->t_stop[y]) + map_info->t_stop[y] = x; } } @@ -141,10 +145,15 @@ X11_print_glyph(window, x, y, glyph) * on this being defined. */ /*ARGSUSED*/ -void X11_cliparound(x, y) int x, y; { } +void +X11_cliparound(x, y) +int x, y; +{ +} #endif /* CLIPPING */ -/* End global functions ==================================================== */ +/* End global functions ==================================================== + */ #include "tile2x11.h" @@ -180,12 +189,13 @@ Pixel colorpixel; { Display *dpy = XtDisplay(toplevel); - if (0!=XReadBitmapFile(dpy, XtWindow(toplevel), filename, - &annotation->width, &annotation->height, &annotation->bitmap, - &annotation->hotx, &annotation->hoty)) { - char buf[BUFSZ]; - Sprintf(buf, "Failed to load %s", filename); - X11_raw_print(buf); + if (0 != XReadBitmapFile(dpy, XtWindow(toplevel), filename, + &annotation->width, &annotation->height, + &annotation->bitmap, &annotation->hotx, + &annotation->hoty)) { + char buf[BUFSZ]; + Sprintf(buf, "Failed to load %s", filename); + X11_raw_print(buf); } annotation->foreground = colorpixel; @@ -206,49 +216,44 @@ post_process_tiles() Display *dpy = XtDisplay(toplevel); unsigned int width, height; - if (tile_image == 0) return; /* no tiles */ + if (tile_image == 0) + return; /* no tiles */ height = tile_image->height; - width = tile_image->width; + width = tile_image->width; - tile_pixmap = XCreatePixmap(dpy, XtWindow(toplevel), - width, - height, - DefaultDepth(dpy, DefaultScreen(dpy))); + tile_pixmap = XCreatePixmap(dpy, XtWindow(toplevel), width, height, + DefaultDepth(dpy, DefaultScreen(dpy))); - XPutImage(dpy, tile_pixmap, - DefaultGC(dpy, DefaultScreen(dpy)), - tile_image, - 0,0, 0,0, /* src, dest top left */ - width, - height); + XPutImage(dpy, tile_pixmap, DefaultGC(dpy, DefaultScreen(dpy)), + tile_image, 0, 0, 0, 0, /* src, dest top left */ + width, height); - XDestroyImage(tile_image); /* data bytes free'd also */ + XDestroyImage(tile_image); /* data bytes free'd also */ tile_image = 0; - init_annotation(&pet_annotation, - appResources.pet_mark_bitmap, appResources.pet_mark_color); + init_annotation(&pet_annotation, appResources.pet_mark_bitmap, + appResources.pet_mark_color); } - /* * Open and read the tile file. Return TRUE if there were no problems. * Return FALSE otherwise. */ static boolean init_tiles(wp) - struct xwindow *wp; +struct xwindow *wp; { #ifdef USE_XPM XpmAttributes attributes; int errorcode; #else - FILE *fp = (FILE *)0; + FILE *fp = (FILE *) 0; x11_header header; - unsigned char *cp, *colormap = (unsigned char *)0; - unsigned char *tb, *tile_bytes = (unsigned char *)0; + unsigned char *cp, *colormap = (unsigned char *) 0; + unsigned char *tb, *tile_bytes = (unsigned char *) 0; int size; - XColor *colors = (XColor *)0; + XColor *colors = (XColor *) 0; unsigned i; int x, y; int bitmap_pad; @@ -257,70 +262,73 @@ init_tiles(wp) char buf[BUFSZ]; Display *dpy = XtDisplay(toplevel); Screen *screen = DefaultScreenOfDisplay(dpy); - struct map_info_t *map_info = (struct map_info_t *)0; - struct tile_map_info_t *tile_info = (struct tile_map_info_t *)0; + struct map_info_t *map_info = (struct map_info_t *) 0; + struct tile_map_info_t *tile_info = (struct tile_map_info_t *) 0; unsigned int image_height = 0, image_width = 0; boolean result = TRUE; XGCValues values; XtGCMask mask; /* already have tile information */ - if (tile_pixmap != None) goto tiledone; + if (tile_pixmap != None) + goto tiledone; map_info = wp->map_information; tile_info = &map_info->tile_map; - (void) memset((genericptr_t)tile_info, 0, sizeof(struct tile_map_info_t)); + (void) memset((genericptr_t) tile_info, 0, + sizeof(struct tile_map_info_t)); /* no tile file name, no tile information */ if (!appResources.tile_file[0]) { - result = FALSE; - goto tiledone; + result = FALSE; + goto tiledone; } #ifdef USE_XPM attributes.valuemask = XpmCloseness; attributes.closeness = 25000; - errorcode = XpmReadFileToImage(dpy, appResources.tile_file, - &tile_image, 0, &attributes); + errorcode = XpmReadFileToImage(dpy, appResources.tile_file, &tile_image, + 0, &attributes); if (errorcode == XpmColorFailed) { - Sprintf(buf, "Insufficient colors available to load %s.", - appResources.tile_file); - X11_raw_print(buf); - X11_raw_print("Try closing other colorful applications and restart."); - X11_raw_print("Attempting to load with inferior colors."); - attributes.closeness = 50000; - errorcode = XpmReadFileToImage(dpy, appResources.tile_file, - &tile_image, 0, &attributes); + Sprintf(buf, "Insufficient colors available to load %s.", + appResources.tile_file); + X11_raw_print(buf); + X11_raw_print("Try closing other colorful applications and restart."); + X11_raw_print("Attempting to load with inferior colors."); + attributes.closeness = 50000; + errorcode = XpmReadFileToImage(dpy, appResources.tile_file, + &tile_image, 0, &attributes); } if (errorcode != XpmSuccess) { - if (errorcode == XpmColorFailed) { - Sprintf(buf, "Insufficient colors available to load %s.", - appResources.tile_file); - X11_raw_print(buf); - } else { - Sprintf(buf, "Failed to load %s: %s", appResources.tile_file, - XpmGetErrorString(errorcode)); - X11_raw_print(buf); - } - result = FALSE; - X11_raw_print("Switching to text-based mode."); - goto tiledone; + if (errorcode == XpmColorFailed) { + Sprintf(buf, "Insufficient colors available to load %s.", + appResources.tile_file); + X11_raw_print(buf); + } else { + Sprintf(buf, "Failed to load %s: %s", appResources.tile_file, + XpmGetErrorString(errorcode)); + X11_raw_print(buf); + } + result = FALSE; + X11_raw_print("Switching to text-based mode."); + goto tiledone; } /* assume a fixed number of tiles per row */ - if (tile_image->width % TILES_PER_ROW != 0 || - tile_image->width <= TILES_PER_ROW) { - Sprintf(buf, - "%s is not a multiple of %d (number of tiles/row) pixels wide", - appResources.tile_file, TILES_PER_ROW); - X11_raw_print(buf); - XDestroyImage(tile_image); - tile_image = 0; - result = FALSE; - goto tiledone; + if (tile_image->width % TILES_PER_ROW != 0 + || tile_image->width <= TILES_PER_ROW) { + Sprintf( + buf, + "%s is not a multiple of %d (number of tiles/row) pixels wide", + appResources.tile_file, TILES_PER_ROW); + X11_raw_print(buf); + XDestroyImage(tile_image); + tile_image = 0; + result = FALSE; + goto tiledone; } /* infer tile dimensions from image size and TILES_PER_ROW */ @@ -329,7 +337,7 @@ init_tiles(wp) tile_count = total_tiles_used; if ((tile_count % TILES_PER_ROW) != 0) { - tile_count += TILES_PER_ROW - (tile_count % TILES_PER_ROW); + tile_count += TILES_PER_ROW - (tile_count % TILES_PER_ROW); } tile_width = image_width / TILES_PER_ROW; tile_height = image_height / (tile_count / TILES_PER_ROW); @@ -337,68 +345,66 @@ init_tiles(wp) /* any less than 16 colours makes tiles useless */ ddepth = DefaultDepthOfScreen(screen); if (ddepth < 4) { - X11_raw_print("need a screen depth of at least 4"); - result = FALSE; - goto tiledone; + X11_raw_print("need a screen depth of at least 4"); + result = FALSE; + goto tiledone; } fp = fopen_datafile(appResources.tile_file, RDBMODE, FALSE); if (!fp) { - X11_raw_print("can't open tile file"); - result = FALSE; - goto tiledone; + X11_raw_print("can't open tile file"); + result = FALSE; + goto tiledone; } if ((int) fread((char *) &header, sizeof(header), 1, fp) != 1) { - X11_raw_print("read of header failed"); - result = FALSE; - goto tiledone; + X11_raw_print("read of header failed"); + result = FALSE; + goto tiledone; } if (header.version != 2) { - Sprintf(buf, "Wrong tile file version, expected 2, got %lu", - header.version); - X11_raw_print(buf); - result = FALSE; - goto tiledone; + Sprintf(buf, "Wrong tile file version, expected 2, got %lu", + header.version); + X11_raw_print(buf); + result = FALSE; + goto tiledone; } -# ifdef VERBOSE - fprintf(stderr, "X11 tile file:\n version %ld\n ncolors %ld\n tile width %ld\n tile height %ld\n per row %ld\n ntiles %ld\n", - header.version, - header.ncolors, - header.tile_width, - header.tile_height, - header.per_row, - header.ntiles); -# endif +#ifdef VERBOSE + fprintf(stderr, "X11 tile file:\n version %ld\n ncolors %ld\n " + "tile width %ld\n tile height %ld\n per row %ld\n " + " ntiles %ld\n", + header.version, header.ncolors, header.tile_width, + header.tile_height, header.per_row, header.ntiles); +#endif - size = 3*header.ncolors; - colormap = (unsigned char *) alloc((unsigned)size); + size = 3 * header.ncolors; + colormap = (unsigned char *) alloc((unsigned) size); if ((int) fread((char *) colormap, 1, size, fp) != size) { - X11_raw_print("read of colormap failed"); - result = FALSE; - goto tiledone; + X11_raw_print("read of colormap failed"); + result = FALSE; + goto tiledone; } - colors = (XColor *) alloc(sizeof(XColor) * (unsigned)header.ncolors); + colors = (XColor *) alloc(sizeof(XColor) * (unsigned) header.ncolors); for (i = 0; i < header.ncolors; i++) { - cp = colormap + (3 * i); - colors[i].red = cp[0] * 256; - colors[i].green = cp[1] * 256; - colors[i].blue = cp[2] * 256; - colors[i].flags = 0; - colors[i].pixel = 0; + cp = colormap + (3 * i); + colors[i].red = cp[0] * 256; + colors[i].green = cp[1] * 256; + colors[i].blue = cp[2] * 256; + colors[i].flags = 0; + colors[i].pixel = 0; - if (!XAllocColor(dpy, DefaultColormapOfScreen(screen), &colors[i]) && - !nhApproxColor(screen, DefaultColormapOfScreen(screen), - (char *)0, &colors[i])) { - Sprintf(buf, "%dth out of %ld color allocation failed", - i, header.ncolors); - X11_raw_print(buf); - result = FALSE; - goto tiledone; - } + if (!XAllocColor(dpy, DefaultColormapOfScreen(screen), &colors[i]) + && !nhApproxColor(screen, DefaultColormapOfScreen(screen), + (char *) 0, &colors[i])) { + Sprintf(buf, "%dth out of %ld color allocation failed", i, + header.ncolors); + X11_raw_print(buf); + result = FALSE; + goto tiledone; + } } size = header.tile_height * header.tile_width; @@ -408,98 +414,97 @@ init_tiles(wp) */ tile_count = header.ntiles; if ((tile_count % header.per_row) != 0) { - tile_count += header.per_row - (tile_count % header.per_row); + tile_count += header.per_row - (tile_count % header.per_row); } - tile_bytes = (unsigned char *) alloc((unsigned)tile_count*size); - if ((int) fread((char *) tile_bytes, size, tile_count, fp) != tile_count) { - X11_raw_print("read of tile bytes failed"); - result = FALSE; - goto tiledone; + tile_bytes = (unsigned char *) alloc((unsigned) tile_count * size); + if ((int) fread((char *) tile_bytes, size, tile_count, fp) + != tile_count) { + X11_raw_print("read of tile bytes failed"); + result = FALSE; + goto tiledone; } if (header.ntiles < (unsigned) total_tiles_used) { - Sprintf(buf, "tile file incomplete, expecting %d tiles, found %lu", - total_tiles_used, header.ntiles); - X11_raw_print(buf); - result = FALSE; - goto tiledone; + Sprintf(buf, "tile file incomplete, expecting %d tiles, found %lu", + total_tiles_used, header.ntiles); + X11_raw_print(buf); + result = FALSE; + goto tiledone; } - if (appResources.double_tile_size) { - tile_width = 2*header.tile_width; - tile_height = 2*header.tile_height; + tile_width = 2 * header.tile_width; + tile_height = 2 * header.tile_height; } else { - tile_width = header.tile_width; - tile_height = header.tile_height; + tile_width = header.tile_width; + tile_height = header.tile_height; } image_height = tile_height * tile_count / header.per_row; - image_width = tile_width * header.per_row; + image_width = tile_width * header.per_row; /* calculate bitmap_pad */ if (ddepth > 16) - bitmap_pad = 32; + bitmap_pad = 32; else if (ddepth > 8) - bitmap_pad = 16; + bitmap_pad = 16; else - bitmap_pad = 8; + bitmap_pad = 8; - tile_image = XCreateImage(dpy, DefaultVisualOfScreen(screen), - ddepth, /* depth */ - ZPixmap, /* format */ - 0, /* offset */ - 0, /* data */ - image_width, /* width */ - image_height, /* height */ - bitmap_pad, /* bit pad */ - 0); /* bytes_per_line */ + tile_image = + XCreateImage(dpy, DefaultVisualOfScreen(screen), ddepth, /* depth */ + ZPixmap, /* format */ + 0, /* offset */ + 0, /* data */ + image_width, /* width */ + image_height, /* height */ + bitmap_pad, /* bit pad */ + 0); /* bytes_per_line */ if (!tile_image) - impossible("init_tiles: insufficient memory to create image"); + impossible("init_tiles: insufficient memory to create image"); /* now we know the physical memory requirements, we can allocate space */ tile_image->data = - (char *) alloc((unsigned)tile_image->bytes_per_line * image_height); + (char *) alloc((unsigned) tile_image->bytes_per_line * image_height); if (appResources.double_tile_size) { - unsigned long *expanded_row = - (unsigned long *)alloc(sizeof (unsigned long) * image_width); + unsigned long *expanded_row = + (unsigned long *) alloc(sizeof(unsigned long) * image_width); - tb = tile_bytes; - for (y = 0; y < (int) image_height; y++) { - for (x = 0; x < (int) image_width / 2; x++) - expanded_row[2*x] = - expanded_row[(2*x)+1] = colors[*tb++].pixel; + tb = tile_bytes; + for (y = 0; y < (int) image_height; y++) { + for (x = 0; x < (int) image_width / 2; x++) + expanded_row[2 * x] = expanded_row[(2 * x) + 1] = + colors[*tb++].pixel; - for (x = 0; x < (int) image_width; x++) - XPutPixel(tile_image, x, y, expanded_row[x]); + for (x = 0; x < (int) image_width; x++) + XPutPixel(tile_image, x, y, expanded_row[x]); - y++; /* duplicate row */ - for (x = 0; x < (int) image_width; x++) - XPutPixel(tile_image, x, y, expanded_row[x]); - } - free((genericptr_t)expanded_row); + y++; /* duplicate row */ + for (x = 0; x < (int) image_width; x++) + XPutPixel(tile_image, x, y, expanded_row[x]); + } + free((genericptr_t) expanded_row); } else { - - for (tb = tile_bytes, y = 0; y < (int) image_height; y++) - for (x = 0; x < (int) image_width; x++, tb++) - XPutPixel(tile_image, x, y, colors[*tb].pixel); + for (tb = tile_bytes, y = 0; y < (int) image_height; y++) + for (x = 0; x < (int) image_width; x++, tb++) + XPutPixel(tile_image, x, y, colors[*tb].pixel); } #endif /* USE_XPM */ - /* fake an inverted tile by drawing a border around the edges */ +/* fake an inverted tile by drawing a border around the edges */ #ifdef USE_WHITE /* use white or black as the border */ mask = GCFunction | GCForeground | GCGraphicsExposures; values.graphics_exposures = False; values.foreground = WhitePixelOfScreen(screen); - values.function = GXcopy; + values.function = GXcopy; tile_info->white_gc = XtGetGC(wp->w, mask, &values); values.graphics_exposures = False; values.foreground = BlackPixelOfScreen(screen); - values.function = GXcopy; + values.function = GXcopy; tile_info->black_gc = XtGetGC(wp->w, mask, &values); #else /* @@ -509,8 +514,10 @@ init_tiles(wp) */ mask = GCFunction | GCForeground | GCGraphicsExposures; values.graphics_exposures = False; - values.foreground = WhitePixelOfScreen(screen) ^ - XGetPixel(tile_image, 0, tile_height*glyph2tile[cmap_to_glyph(S_corr)]); + values.foreground = + WhitePixelOfScreen(screen) + ^ XGetPixel(tile_image, 0, + tile_height * glyph2tile[cmap_to_glyph(S_corr)]); values.function = GXxor; tile_info->white_gc = XtGetGC(wp->w, mask, &values); @@ -522,31 +529,34 @@ init_tiles(wp) tiledone: #ifndef USE_XPM - if (fp) (void) fclose(fp); - if (colormap) free((genericptr_t)colormap); - if (tile_bytes) free((genericptr_t)tile_bytes); - if (colors) free((genericptr_t)colors); + if (fp) + (void) fclose(fp); + if (colormap) + free((genericptr_t) colormap); + if (tile_bytes) + free((genericptr_t) tile_bytes); + if (colors) + free((genericptr_t) colors); #endif - if (result) { /* succeeded */ - tile_info->square_height = tile_height; - tile_info->square_width = tile_width; - tile_info->square_ascent = 0; - tile_info->square_lbearing = 0; - tile_info->image_width = image_width; - tile_info->image_height = image_height; + if (result) { /* succeeded */ + tile_info->square_height = tile_height; + tile_info->square_width = tile_width; + tile_info->square_ascent = 0; + tile_info->square_lbearing = 0; + tile_info->image_width = image_width; + tile_info->image_height = image_height; } return result; } - /* * Make sure the map's cursor is always visible. */ void check_cursor_visibility(wp) - struct xwindow *wp; +struct xwindow *wp; { Arg arg[2]; Widget viewport, horiz_sb, vert_sb; @@ -558,135 +568,147 @@ check_cursor_visibility(wp) viewport = XtParent(wp->w); horiz_sb = XtNameToWidget(viewport, "horizontal"); - vert_sb = XtNameToWidget(viewport, "vertical"); + vert_sb = XtNameToWidget(viewport, "vertical"); /* All values are relative to currently visible area */ -#define V_BORDER 0.25 /* if this far from vert edge, shift */ -#define H_BORDER 0.25 /* if this from from horiz edge, shift */ +#define V_BORDER 0.25 /* if this far from vert edge, shift */ +#define H_BORDER 0.25 /* if this from from horiz edge, shift */ -#define H_DELTA 0.25 /* distance of horiz shift */ -#define V_DELTA 0.25 /* distance of vert shift */ +#define H_DELTA 0.25 /* distance of horiz shift */ +#define V_DELTA 0.25 /* distance of vert shift */ if (horiz_sb) { - XtSetArg(arg[0], XtNshown, &shown); - XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); - XtGetValues(horiz_sb, arg, TWO); + XtSetArg(arg[0], XtNshown, &shown); + XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); + XtGetValues(horiz_sb, arg, TWO); - /* [ALI] Don't assume map widget is the same size as actual map */ - if (wp->map_information->is_tile) - cursor_middle = wp->map_information->tile_map.square_width; - else - cursor_middle = wp->map_information->text_map.square_width; - cursor_middle = (wp->cursx + 0.5) * cursor_middle / wp->pixel_width; - do_call = True; + /* [ALI] Don't assume map widget is the same size as actual map */ + if (wp->map_information->is_tile) + cursor_middle = wp->map_information->tile_map.square_width; + else + cursor_middle = wp->map_information->text_map.square_width; + cursor_middle = (wp->cursx + 0.5) * cursor_middle / wp->pixel_width; + do_call = True; #ifdef VERBOSE - if (cursor_middle < top) { - s = " outside left"; - } else if (cursor_middle < top + shown*H_BORDER) { - s = " close to left"; - } else if (cursor_middle > (top + shown)) { - s = " outside right"; - } else if (cursor_middle > (top + shown - shown*H_BORDER)) { - s = " close to right"; - } else { - s = ""; - } - printf("Horiz: shown = %3.2f, top = %3.2f%s", shown, top, s); + if (cursor_middle < top) { + s = " outside left"; + } else if (cursor_middle < top + shown * H_BORDER) { + s = " close to left"; + } else if (cursor_middle > (top + shown)) { + s = " outside right"; + } else if (cursor_middle > (top + shown - shown * H_BORDER)) { + s = " close to right"; + } else { + s = ""; + } + printf("Horiz: shown = %3.2f, top = %3.2f%s", shown, top, s); #endif - if (cursor_middle < top) { - top = cursor_middle - shown*H_DELTA; - if (top < 0.0) top = 0.0; - } else if (cursor_middle < top + shown*H_BORDER) { - top -= shown*H_DELTA; - if (top < 0.0) top = 0.0; - } else if (cursor_middle > (top + shown)) { - top = cursor_middle - shown*H_DELTA; - if (top < 0.0) top = 0.0; - if (top + shown > 1.0) top = 1.0 - shown; - } else if (cursor_middle > (top + shown - shown*H_BORDER)) { - top += shown*H_DELTA; - if (top + shown > 1.0) top = 1.0 - shown; - } else { - do_call = False; - } + if (cursor_middle < top) { + top = cursor_middle - shown * H_DELTA; + if (top < 0.0) + top = 0.0; + } else if (cursor_middle < top + shown * H_BORDER) { + top -= shown * H_DELTA; + if (top < 0.0) + top = 0.0; + } else if (cursor_middle > (top + shown)) { + top = cursor_middle - shown * H_DELTA; + if (top < 0.0) + top = 0.0; + if (top + shown > 1.0) + top = 1.0 - shown; + } else if (cursor_middle > (top + shown - shown * H_BORDER)) { + top += shown * H_DELTA; + if (top + shown > 1.0) + top = 1.0 - shown; + } else { + do_call = False; + } - if (do_call) { - XtCallCallbacks(horiz_sb, XtNjumpProc, &top); - adjusted = True; - } + if (do_call) { + XtCallCallbacks(horiz_sb, XtNjumpProc, &top); + adjusted = True; + } } if (vert_sb) { - XtSetArg(arg[0], XtNshown, &shown); - XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); - XtGetValues(vert_sb, arg, TWO); + XtSetArg(arg[0], XtNshown, &shown); + XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); + XtGetValues(vert_sb, arg, TWO); - if (wp->map_information->is_tile) - cursor_middle = wp->map_information->tile_map.square_height; - else - cursor_middle = wp->map_information->text_map.square_height; - cursor_middle = (wp->cursy + 0.5) * cursor_middle / wp->pixel_height; - do_call = True; + if (wp->map_information->is_tile) + cursor_middle = wp->map_information->tile_map.square_height; + else + cursor_middle = wp->map_information->text_map.square_height; + cursor_middle = (wp->cursy + 0.5) * cursor_middle / wp->pixel_height; + do_call = True; #ifdef VERBOSE - if (cursor_middle < top) { - s = " above top"; - } else if (cursor_middle < top + shown*V_BORDER) { - s = " close to top"; - } else if (cursor_middle > (top + shown)) { - s = " below bottom"; - } else if (cursor_middle > (top + shown - shown*V_BORDER)) { - s = " close to bottom"; - } else { - s = ""; - } - printf("%sVert: shown = %3.2f, top = %3.2f%s", - horiz_sb ? "; " : "", shown, top, s); + if (cursor_middle < top) { + s = " above top"; + } else if (cursor_middle < top + shown * V_BORDER) { + s = " close to top"; + } else if (cursor_middle > (top + shown)) { + s = " below bottom"; + } else if (cursor_middle > (top + shown - shown * V_BORDER)) { + s = " close to bottom"; + } else { + s = ""; + } + printf("%sVert: shown = %3.2f, top = %3.2f%s", horiz_sb ? "; " : "", + shown, top, s); #endif - if (cursor_middle < top) { - top = cursor_middle - shown*V_DELTA; - if (top < 0.0) top = 0.0; - } else if (cursor_middle < top + shown*V_BORDER) { - top -= shown*V_DELTA; - if (top < 0.0) top = 0.0; - } else if (cursor_middle > (top + shown)) { - top = cursor_middle - shown*V_DELTA; - if (top < 0.0) top = 0.0; - if (top + shown > 1.0) top = 1.0 - shown; - } else if (cursor_middle > (top + shown - shown*V_BORDER)) { - top += shown*V_DELTA; - if (top + shown > 1.0) top = 1.0 - shown; - } else { - do_call = False; - } + if (cursor_middle < top) { + top = cursor_middle - shown * V_DELTA; + if (top < 0.0) + top = 0.0; + } else if (cursor_middle < top + shown * V_BORDER) { + top -= shown * V_DELTA; + if (top < 0.0) + top = 0.0; + } else if (cursor_middle > (top + shown)) { + top = cursor_middle - shown * V_DELTA; + if (top < 0.0) + top = 0.0; + if (top + shown > 1.0) + top = 1.0 - shown; + } else if (cursor_middle > (top + shown - shown * V_BORDER)) { + top += shown * V_DELTA; + if (top + shown > 1.0) + top = 1.0 - shown; + } else { + do_call = False; + } - if (do_call) { - XtCallCallbacks(vert_sb, XtNjumpProc, &top); - adjusted = True; - } + if (do_call) { + XtCallCallbacks(vert_sb, XtNjumpProc, &top); + adjusted = True; + } } /* make sure cursor is displayed during dowhatis.. */ - if (adjusted) display_cursor(wp); + if (adjusted) + display_cursor(wp); #ifdef VERBOSE - if (horiz_sb || vert_sb) printf("\n"); + if (horiz_sb || vert_sb) + printf("\n"); #endif } - /* - * Check to see if the viewport has grown smaller. If so, then we want to make + * Check to see if the viewport has grown smaller. If so, then we want to + * make * sure that the cursor is still on the screen. We do this to keep the cursor * on the screen when the user resizes the nethack window. */ static void map_check_size_change(wp) - struct xwindow *wp; +struct xwindow *wp; { struct map_info_t *map_info = wp->map_information; Arg arg[2]; @@ -695,34 +717,34 @@ map_check_size_change(wp) viewport = XtParent(wp->w); - XtSetArg(arg[0], XtNwidth, &new_width); + XtSetArg(arg[0], XtNwidth, &new_width); XtSetArg(arg[1], XtNheight, &new_height); XtGetValues(viewport, arg, TWO); /* Only do cursor check if new size is smaller. */ if (new_width < map_info->viewport_width - || new_height < map_info->viewport_height) { - /* [ALI] If the viewport was larger than the map (and so the map - * widget was contrained to be larger than the actual map) then we - * may be able to shrink the map widget as the viewport shrinks. - */ - if (map_info->is_tile) { - wp->pixel_width = map_info->tile_map.square_width * COLNO; - wp->pixel_height = map_info->tile_map.square_height * ROWNO; - } else { - wp->pixel_width = map_info->text_map.square_width * COLNO; - wp->pixel_height = map_info->text_map.square_height * ROWNO; - } + || new_height < map_info->viewport_height) { + /* [ALI] If the viewport was larger than the map (and so the map + * widget was contrained to be larger than the actual map) then we + * may be able to shrink the map widget as the viewport shrinks. + */ + if (map_info->is_tile) { + wp->pixel_width = map_info->tile_map.square_width * COLNO; + wp->pixel_height = map_info->tile_map.square_height * ROWNO; + } else { + wp->pixel_width = map_info->text_map.square_width * COLNO; + wp->pixel_height = map_info->text_map.square_height * ROWNO; + } - if (wp->pixel_width < new_width) - wp->pixel_width = new_width; - if (wp->pixel_height < new_height) - wp->pixel_height = new_height; - XtSetArg(arg[0], XtNwidth, wp->pixel_width); - XtSetArg(arg[1], XtNheight, wp->pixel_height); - XtSetValues(wp->w, arg, TWO); + if (wp->pixel_width < new_width) + wp->pixel_width = new_width; + if (wp->pixel_height < new_height) + wp->pixel_height = new_height; + XtSetArg(arg[0], XtNwidth, wp->pixel_width); + XtSetArg(arg[1], XtNheight, wp->pixel_height); + XtSetValues(wp->w, arg, TWO); - check_cursor_visibility(wp); + check_cursor_visibility(wp); } map_info->viewport_width = new_width; @@ -741,11 +763,11 @@ map_check_size_change(wp) */ static void set_gc(w, font, resource_name, bgpixel, regular, inverse) - Widget w; - Font font; - const char *resource_name; - Pixel bgpixel; - GC *regular, *inverse; +Widget w; +Font font; +const char *resource_name; +Pixel bgpixel; +GC *regular, *inverse; { XGCValues values; XtGCMask mask = GCFunction | GCForeground | GCBackground | GCFont; @@ -757,13 +779,13 @@ set_gc(w, font, resource_name, bgpixel, regular, inverse) values.foreground = curpixel; values.background = bgpixel; - values.function = GXcopy; - values.font = font; + values.function = GXcopy; + values.font = font; *regular = XtGetGC(w, mask, &values); values.foreground = bgpixel; values.background = curpixel; - values.function = GXcopy; - values.font = font; + values.function = GXcopy; + values.font = font; *inverse = XtGetGC(w, mask, &values); } @@ -776,8 +798,8 @@ set_gc(w, font, resource_name, bgpixel, regular, inverse) */ static void get_text_gc(wp, font) - struct xwindow *wp; - Font font; +struct xwindow *wp; +Font font; { struct map_info_t *map_info = wp->map_information; Pixel bgpixel; @@ -788,92 +810,90 @@ get_text_gc(wp, font) XtGetValues(wp->w, arg, ONE); #ifdef TEXTCOLOR -#define set_color_gc(nh_color, resource_name) \ - set_gc(wp->w, font, resource_name, bgpixel, \ - &map_info->text_map.color_gcs[nh_color], \ - &map_info->text_map.inv_color_gcs[nh_color]); +#define set_color_gc(nh_color, resource_name) \ + set_gc(wp->w, font, resource_name, bgpixel, \ + &map_info->text_map.color_gcs[nh_color], \ + &map_info->text_map.inv_color_gcs[nh_color]); - set_color_gc(CLR_BLACK, XtNblack); - set_color_gc(CLR_RED, XtNred); - set_color_gc(CLR_GREEN, XtNgreen); - set_color_gc(CLR_BROWN, XtNbrown); - set_color_gc(CLR_BLUE, XtNblue); - set_color_gc(CLR_MAGENTA, XtNmagenta); - set_color_gc(CLR_CYAN, XtNcyan); - set_color_gc(CLR_GRAY, XtNgray); - set_color_gc(NO_COLOR, XtNforeground); - set_color_gc(CLR_ORANGE, XtNorange); + set_color_gc(CLR_BLACK, XtNblack); + set_color_gc(CLR_RED, XtNred); + set_color_gc(CLR_GREEN, XtNgreen); + set_color_gc(CLR_BROWN, XtNbrown); + set_color_gc(CLR_BLUE, XtNblue); + set_color_gc(CLR_MAGENTA, XtNmagenta); + set_color_gc(CLR_CYAN, XtNcyan); + set_color_gc(CLR_GRAY, XtNgray); + set_color_gc(NO_COLOR, XtNforeground); + set_color_gc(CLR_ORANGE, XtNorange); set_color_gc(CLR_BRIGHT_GREEN, XtNbright_green); - set_color_gc(CLR_YELLOW, XtNyellow); + set_color_gc(CLR_YELLOW, XtNyellow); set_color_gc(CLR_BRIGHT_BLUE, XtNbright_blue); set_color_gc(CLR_BRIGHT_MAGENTA, XtNbright_magenta); set_color_gc(CLR_BRIGHT_CYAN, XtNbright_cyan); - set_color_gc(CLR_WHITE, XtNwhite); + set_color_gc(CLR_WHITE, XtNwhite); #else - set_gc(wp->w, font, XtNforeground, bgpixel, - &map_info->text_map.copy_gc, - &map_info->text_map.inv_copy_gc); + set_gc(wp->w, font, XtNforeground, bgpixel, &map_info->text_map.copy_gc, + &map_info->text_map.inv_copy_gc); #endif } - /* * Display the cursor on the map window. */ static void display_cursor(wp) - struct xwindow *wp; +struct xwindow *wp; { /* Redisplay the cursor location inverted. */ map_update(wp, wp->cursy, wp->cursy, wp->cursx, wp->cursx, TRUE); } - /* * Check if there are any changed characters. If so, then plaster them on * the screen. */ void display_map_window(wp) - struct xwindow *wp; +struct xwindow *wp; { register int row; struct map_info_t *map_info = wp->map_information; - if ((Is_rogue_level(&u.uz) ? map_info->is_tile : - (map_info->is_tile != iflags.wc_tiled_map)) && - map_info->tile_map.image_width) { - /* changed map display mode, re-display the full map */ - (void) memset((genericptr_t) map_info->t_start, (char) 0, - sizeof(map_info->t_start)); - (void) memset((genericptr_t) map_info->t_stop, (char) COLNO-1, - sizeof(map_info->t_stop)); - map_info->is_tile = iflags.wc_tiled_map && !Is_rogue_level(&u.uz); - XClearWindow(XtDisplay(wp->w), XtWindow(wp->w)); - set_map_size(wp, COLNO, ROWNO); - check_cursor_visibility(wp); + if ((Is_rogue_level(&u.uz) ? map_info->is_tile + : (map_info->is_tile != iflags.wc_tiled_map)) + && map_info->tile_map.image_width) { + /* changed map display mode, re-display the full map */ + (void) memset((genericptr_t) map_info->t_start, (char) 0, + sizeof(map_info->t_start)); + (void) memset((genericptr_t) map_info->t_stop, (char) COLNO - 1, + sizeof(map_info->t_stop)); + map_info->is_tile = iflags.wc_tiled_map && !Is_rogue_level(&u.uz); + XClearWindow(XtDisplay(wp->w), XtWindow(wp->w)); + set_map_size(wp, COLNO, ROWNO); + check_cursor_visibility(wp); } else if (wp->prevx != wp->cursx || wp->prevy != wp->cursy) { - register unsigned int x = wp->prevx, y = wp->prevy; + register unsigned int x = wp->prevx, y = wp->prevy; - /* - * Previous cursor position is not the same as the current - * cursor position, update the old cursor position. - */ - if (x < map_info->t_start[y]) map_info->t_start[y] = x; - if (x > map_info->t_stop[y]) map_info->t_stop[y] = x; + /* + * Previous cursor position is not the same as the current + * cursor position, update the old cursor position. + */ + if (x < map_info->t_start[y]) + map_info->t_start[y] = x; + if (x > map_info->t_stop[y]) + map_info->t_stop[y] = x; } for (row = 0; row < ROWNO; row++) { - if (map_info->t_start[row] <= map_info->t_stop[row]) { - map_update(wp, row, row, - (int) map_info->t_start[row], - (int) map_info->t_stop[row], FALSE); - map_info->t_start[row] = COLNO-1; - map_info->t_stop[row] = 0; - } + if (map_info->t_start[row] <= map_info->t_stop[row]) { + map_update(wp, row, row, (int) map_info->t_start[row], + (int) map_info->t_stop[row], FALSE); + map_info->t_start[row] = COLNO - 1; + map_info->t_stop[row] = 0; + } } display_cursor(wp); - wp->prevx = wp->cursx; /* adjust old cursor position */ + wp->prevx = wp->cursx; /* adjust old cursor position */ wp->prevy = wp->cursy; } @@ -889,8 +909,8 @@ struct map_info_t *map_info; stone = cmap_to_glyph(S_stone); for (sp = (unsigned short *) map_info->tile_map.glyphs, i = 0; - i < ROWNO*COLNO; sp++, i++) { - *sp = stone; + i < ROWNO * COLNO; sp++, i++) { + *sp = stone; } } @@ -902,7 +922,7 @@ struct map_info_t *map_info; */ void clear_map_window(wp) - struct xwindow *wp; +struct xwindow *wp; { struct map_info_t *map_info = wp->map_information; @@ -910,17 +930,17 @@ clear_map_window(wp) map_all_stone(map_info); (void) memset((genericptr_t) map_info->text_map.text, ' ', - sizeof(map_info->text_map.text)); + sizeof(map_info->text_map.text)); #ifdef TEXTCOLOR (void) memset((genericptr_t) map_info->text_map.colors, NO_COLOR, - sizeof(map_info->text_map.colors)); + sizeof(map_info->text_map.colors)); #endif /* force a full update */ (void) memset((genericptr_t) map_info->t_start, (char) 0, - sizeof(map_info->t_start)); - (void) memset((genericptr_t) map_info->t_stop, (char) COLNO-1, - sizeof(map_info->t_stop)); + sizeof(map_info->t_start)); + (void) memset((genericptr_t) map_info->t_stop, (char) COLNO - 1, + sizeof(map_info->t_stop)); display_map_window(wp); } @@ -930,39 +950,39 @@ clear_map_window(wp) */ static void get_char_info(wp) - struct xwindow *wp; +struct xwindow *wp; { XFontStruct *fs; struct map_info_t *map_info = wp->map_information; struct text_map_info_t *text_map = &map_info->text_map; fs = WindowFontStruct(wp->w); - text_map->square_width = fs->max_bounds.width; - text_map->square_height = fs->max_bounds.ascent + fs->max_bounds.descent; - text_map->square_ascent = fs->max_bounds.ascent; + text_map->square_width = fs->max_bounds.width; + text_map->square_height = fs->max_bounds.ascent + fs->max_bounds.descent; + text_map->square_ascent = fs->max_bounds.ascent; text_map->square_lbearing = -fs->min_bounds.lbearing; #ifdef VERBOSE printf("Font information:\n"); printf("fid = %ld, direction = %d\n", fs->fid, fs->direction); - printf("first = %d, last = %d\n", - fs->min_char_or_byte2, fs->max_char_or_byte2); - printf("all chars exist? %s\n", fs->all_chars_exist?"yes":"no"); + printf("first = %d, last = %d\n", fs->min_char_or_byte2, + fs->max_char_or_byte2); + printf("all chars exist? %s\n", fs->all_chars_exist ? "yes" : "no"); printf("min_bounds:lb=%d rb=%d width=%d asc=%d des=%d attr=%d\n", - fs->min_bounds.lbearing, fs->min_bounds.rbearing, - fs->min_bounds.width, fs->min_bounds.ascent, - fs->min_bounds.descent, fs->min_bounds.attributes); + fs->min_bounds.lbearing, fs->min_bounds.rbearing, + fs->min_bounds.width, fs->min_bounds.ascent, + fs->min_bounds.descent, fs->min_bounds.attributes); printf("max_bounds:lb=%d rb=%d width=%d asc=%d des=%d attr=%d\n", - fs->max_bounds.lbearing, fs->max_bounds.rbearing, - fs->max_bounds.width, fs->max_bounds.ascent, - fs->max_bounds.descent, fs->max_bounds.attributes); + fs->max_bounds.lbearing, fs->max_bounds.rbearing, + fs->max_bounds.width, fs->max_bounds.ascent, + fs->max_bounds.descent, fs->max_bounds.attributes); printf("per_char = 0x%lx\n", (unsigned long) fs->per_char); - printf("Text: (max) width = %d, height = %d\n", - text_map->square_width, text_map->square_height); + printf("Text: (max) width = %d, height = %d\n", text_map->square_width, + text_map->square_height); #endif if (fs->min_bounds.width != fs->max_bounds.width) - X11_raw_print("Warning: map font is not monospaced!"); + X11_raw_print("Warning: map font is not monospaced!"); } /* @@ -971,18 +991,17 @@ get_char_info(wp) #define INBUF_SIZE 64 int inbuf[INBUF_SIZE]; int incount = 0; -int inptr = 0; /* points to valid data */ - +int inptr = 0; /* points to valid data */ /* * Keyboard and button event handler for map window. */ void map_input(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { XKeyEvent *key; XButtonEvent *button; @@ -993,96 +1012,93 @@ map_input(w, event, params, num_params) char keystring[MAX_KEY_STRING]; switch (event->type) { - case ButtonPress: - button = (XButtonEvent *) event; + case ButtonPress: + button = (XButtonEvent *) event; #ifdef VERBOSE_INPUT - printf("button press\n"); + printf("button press\n"); #endif - if (in_nparams > 0 && - (nbytes = strlen(params[0])) < MAX_KEY_STRING) { - Strcpy(keystring, params[0]); - key = (XKeyEvent *) event; /* just in case */ - goto key_events; - } - if (w != window_list[WIN_MAP].w) { + if (in_nparams > 0 && (nbytes = strlen(params[0])) < MAX_KEY_STRING) { + Strcpy(keystring, params[0]); + key = (XKeyEvent *) event; /* just in case */ + goto key_events; + } + if (w != window_list[WIN_MAP].w) { #ifdef VERBOSE_INPUT - printf("map_input called from wrong window\n"); + printf("map_input called from wrong window\n"); #endif - X11_nhbell(); - return; - } - set_button_values(w, button->x, button->y, button->button); - break; - case KeyPress: + X11_nhbell(); + return; + } + set_button_values(w, button->x, button->y, button->button); + break; + case KeyPress: #ifdef VERBOSE_INPUT - printf("key: "); + printf("key: "); #endif - if(appResources.slow && input_func) { - (*input_func)(w, event, params, num_params); - break; - } + if (appResources.slow && input_func) { + (*input_func)(w, event, params, num_params); + break; + } - /* - * Don't use key_event_to_char() because we want to be able - * to allow keys mapped to multiple characters. - */ - key = (XKeyEvent *) event; - if (in_nparams > 0 && - (nbytes = strlen(params[0])) < MAX_KEY_STRING) { - Strcpy(keystring, params[0]); - } else { - /* - * Assume that mod1 is really the meta key. - */ - meta = !!(key->state & Mod1Mask); - nbytes = - XLookupString(key, keystring, MAX_KEY_STRING, - (KeySym *)0, (XComposeStatus *)0); - } - key_events: - /* Modifier keys return a zero length string when pressed. */ - if (nbytes) { + /* + * Don't use key_event_to_char() because we want to be able + * to allow keys mapped to multiple characters. + */ + key = (XKeyEvent *) event; + if (in_nparams > 0 && (nbytes = strlen(params[0])) < MAX_KEY_STRING) { + Strcpy(keystring, params[0]); + } else { + /* + * Assume that mod1 is really the meta key. + */ + meta = !!(key->state & Mod1Mask); + nbytes = XLookupString(key, keystring, MAX_KEY_STRING, + (KeySym *) 0, (XComposeStatus *) 0); + } + key_events: + /* Modifier keys return a zero length string when pressed. */ + if (nbytes) { #ifdef VERBOSE_INPUT - printf("\""); + printf("\""); #endif - for (i = 0; i < nbytes; i++) { - c = keystring[i]; + for (i = 0; i < nbytes; i++) { + c = keystring[i]; - if (incount < INBUF_SIZE) { - inbuf[(inptr+incount)%INBUF_SIZE] = - ((int) c) + (meta ? 0x80 : 0); - incount++; - } else { - X11_nhbell(); - } + if (incount < INBUF_SIZE) { + inbuf[(inptr + incount) % INBUF_SIZE] = + ((int) c) + (meta ? 0x80 : 0); + incount++; + } else { + X11_nhbell(); + } #ifdef VERBOSE_INPUT - if (meta) /* meta will print as M */ - (void) putchar('M'); - if (c < ' ') { /* ctrl will print as ^ */ - (void) putchar('^'); - c += '@'; - } - (void) putchar(c); + if (meta) /* meta will print as M */ + (void) putchar('M'); + if (c < ' ') { /* ctrl will print as ^ */ + (void) putchar('^'); + c += '@'; + } + (void) putchar(c); #endif - } + } #ifdef VERBOSE_INPUT - printf("\" [%d bytes]\n", nbytes); + printf("\" [%d bytes]\n", nbytes); #endif - } - break; + } + break; - default: - impossible("unexpected X event, type = %d\n", (int) event->type); - break; + default: + impossible("unexpected X event, type = %d\n", (int) event->type); + break; } } static void set_button_values(w, x, y, button) - Widget w; - int x; - int y; - unsigned int button; +Widget w; +int x; +int y; +unsigned int button; { struct xwindow *wp; struct map_info_t *map_info; @@ -1091,17 +1107,19 @@ set_button_values(w, x, y, button) map_info = wp->map_information; if (map_info->is_tile) { - click_x = x / map_info->tile_map.square_width; - click_y = y / map_info->tile_map.square_height; + click_x = x / map_info->tile_map.square_width; + click_y = y / map_info->tile_map.square_height; } else { - click_x = x / map_info->text_map.square_width; - click_y = y / map_info->text_map.square_height; + click_x = x / map_info->text_map.square_width; + click_y = y / map_info->text_map.square_height; } /* The values can be out of range if the map window has been resized */ /* to be larger than the max size. */ - if (click_x >= COLNO) click_x = COLNO-1; - if (click_y >= ROWNO) click_y = ROWNO-1; + if (click_x >= COLNO) + click_x = COLNO - 1; + if (click_y >= ROWNO) + click_y = ROWNO - 1; /* Map all buttons but the first to the second click */ click_button = (button == Button1) ? CLICK_1 : CLICK_2; @@ -1113,9 +1131,9 @@ set_button_values(w, x, y, button) /*ARGSUSED*/ static void map_exposed(w, client_data, widget_data) - Widget w; - XtPointer client_data; /* unused */ - XtPointer widget_data; /* expose event from Window widget */ +Widget w; +XtPointer client_data; /* unused */ +XtPointer widget_data; /* expose event from Window widget */ { int x, y; struct xwindow *wp; @@ -1123,65 +1141,68 @@ map_exposed(w, client_data, widget_data) unsigned width, height; int start_row, stop_row, start_col, stop_col; XExposeEvent *event = (XExposeEvent *) widget_data; - int t_height, t_width; /* tile/text height & width */ + int t_height, t_width; /* tile/text height & width */ nhUse(client_data); - if (!XtIsRealized(w) || event->count > 0) return; + if (!XtIsRealized(w) || event->count > 0) + return; wp = find_widget(w); map_info = wp->map_information; - if (wp->keep_window && !map_info) return; + if (wp->keep_window && !map_info) + return; /* * The map is sent an expose event when the viewport resizes. Make sure * that the cursor is still in the viewport after the resize. */ map_check_size_change(wp); - if (event) { /* called from button-event */ - x = event->x; - y = event->y; - width = event->width; - height = event->height; + if (event) { /* called from button-event */ + x = event->x; + y = event->y; + width = event->width; + height = event->height; } else { - x = 0; - y = 0; - width = wp->pixel_width; - height= wp->pixel_height; + x = 0; + y = 0; + width = wp->pixel_width; + height = wp->pixel_height; } /* * Convert pixels into INCLUSIVE text rows and columns. */ if (map_info->is_tile) { - t_height = map_info->tile_map.square_height; - t_width = map_info->tile_map.square_width; + t_height = map_info->tile_map.square_height; + t_width = map_info->tile_map.square_width; } else { - t_height = map_info->text_map.square_height; - t_width = map_info->text_map.square_width; + t_height = map_info->text_map.square_height; + t_width = map_info->text_map.square_width; } start_row = y / t_height; - stop_row = ((y + height) / t_height) + - ((((y + height) % t_height) == 0) ? 0 : 1) - 1; + stop_row = ((y + height) / t_height) + + ((((y + height) % t_height) == 0) ? 0 : 1) - 1; start_col = x / t_width; - stop_col = ((x + width) / t_width) + - ((((x + width) % t_width) == 0) ? 0 : 1) - 1; + stop_col = ((x + width) / t_width) + + ((((x + width) % t_width) == 0) ? 0 : 1) - 1; #ifdef VERBOSE - printf("map_exposed: x = %d, y = %d, width = %d, height = %d\n", - x, y, width, height); - printf("chars %d x %d, rows %d to %d, columns %d to %d\n", - t_height, t_width, - start_row, stop_row, start_col, stop_col); + printf("map_exposed: x = %d, y = %d, width = %d, height = %d\n", x, y, + width, height); + printf("chars %d x %d, rows %d to %d, columns %d to %d\n", t_height, + t_width, start_row, stop_row, start_col, stop_col); #endif /* Out of range values are possible if the map window is resized to be */ /* bigger than the largest expected value. */ - if (stop_row >= ROWNO) stop_row = ROWNO-1; - if (stop_col >= COLNO) stop_col = COLNO-1; + if (stop_row >= ROWNO) + stop_row = ROWNO - 1; + if (stop_col >= COLNO) + stop_col = COLNO - 1; map_update(wp, start_row, stop_row, start_col, stop_col, FALSE); - display_cursor(wp); /* make sure cursor shows up */ + display_cursor(wp); /* make sure cursor shows up */ } /* @@ -1196,9 +1217,9 @@ map_exposed(w, client_data, widget_data) */ static void map_update(wp, start_row, stop_row, start_col, stop_col, inverted) - struct xwindow *wp; - int start_row, stop_row, start_col, stop_col; - boolean inverted; +struct xwindow *wp; +int start_row, stop_row, start_col, stop_col; +boolean inverted; { int win_start_row, win_start_col; struct map_info_t *map_info = wp->map_information; @@ -1206,177 +1227,169 @@ map_update(wp, start_row, stop_row, start_col, stop_col, inverted) register int count; if (start_row < 0 || stop_row >= ROWNO) { - impossible("map_update: bad row range %d-%d\n", start_row, stop_row); - return; + impossible("map_update: bad row range %d-%d\n", start_row, stop_row); + return; } - if (start_col < 0 || stop_col >=COLNO) { - impossible("map_update: bad col range %d-%d\n", start_col, stop_col); - return; + if (start_col < 0 || stop_col >= COLNO) { + impossible("map_update: bad col range %d-%d\n", start_col, stop_col); + return; } #ifdef VERBOSE_UPDATE - printf("update: [0x%x] %d %d %d %d\n", - (int) wp->w, start_row, stop_row, start_col, stop_col); + printf("update: [0x%x] %d %d %d %d\n", (int) wp->w, start_row, stop_row, + start_col, stop_col); #endif win_start_row = start_row; win_start_col = start_col; if (map_info->is_tile) { - struct tile_map_info_t *tile_map = &map_info->tile_map; - int cur_col; - Display* dpy = XtDisplay(wp->w); - Screen* screen = DefaultScreenOfDisplay(dpy); + struct tile_map_info_t *tile_map = &map_info->tile_map; + int cur_col; + Display *dpy = XtDisplay(wp->w); + Screen *screen = DefaultScreenOfDisplay(dpy); - for (row = start_row; row <= stop_row; row++) { - for (cur_col = start_col; cur_col <= stop_col; cur_col++) { - int glyph = tile_map->glyphs[row][cur_col]; - int tile = glyph2tile[glyph]; - int src_x, src_y; - int dest_x = cur_col * tile_map->square_width; - int dest_y = row * tile_map->square_height; + for (row = start_row; row <= stop_row; row++) { + for (cur_col = start_col; cur_col <= stop_col; cur_col++) { + int glyph = tile_map->glyphs[row][cur_col]; + int tile = glyph2tile[glyph]; + int src_x, src_y; + int dest_x = cur_col * tile_map->square_width; + int dest_y = row * tile_map->square_height; - src_x = (tile % TILES_PER_ROW) * tile_width; - src_y = (tile / TILES_PER_ROW) * tile_height; - XCopyArea(dpy, tile_pixmap, XtWindow(wp->w), - tile_map->black_gc, /* no grapics_expose */ - src_x, src_y, - tile_width, tile_height, - dest_x, dest_y); + src_x = (tile % TILES_PER_ROW) * tile_width; + src_y = (tile / TILES_PER_ROW) * tile_height; + XCopyArea(dpy, tile_pixmap, XtWindow(wp->w), + tile_map->black_gc, /* no grapics_expose */ + src_x, src_y, tile_width, tile_height, dest_x, + dest_y); - if (glyph_is_pet(glyph) && iflags.hilite_pet) { - /* draw pet annotation (a heart) */ - XSetForeground(dpy, tile_map->black_gc, - pet_annotation.foreground); - XSetClipOrigin(dpy, tile_map->black_gc, dest_x, dest_y); - XSetClipMask(dpy, tile_map->black_gc, - pet_annotation.bitmap); - XCopyPlane( - dpy, - pet_annotation.bitmap, - XtWindow(wp->w), - tile_map->black_gc, - 0,0, - pet_annotation.width,pet_annotation.height, - dest_x,dest_y, - 1); - XSetClipOrigin(dpy, tile_map->black_gc, 0, 0); - XSetClipMask(dpy, tile_map->black_gc, None); - XSetForeground(dpy, tile_map->black_gc, - BlackPixelOfScreen(screen)); - } - } - } + if (glyph_is_pet(glyph) && iflags.hilite_pet) { + /* draw pet annotation (a heart) */ + XSetForeground(dpy, tile_map->black_gc, + pet_annotation.foreground); + XSetClipOrigin(dpy, tile_map->black_gc, dest_x, dest_y); + XSetClipMask(dpy, tile_map->black_gc, + pet_annotation.bitmap); + XCopyPlane(dpy, pet_annotation.bitmap, XtWindow(wp->w), + tile_map->black_gc, 0, 0, pet_annotation.width, + pet_annotation.height, dest_x, dest_y, 1); + XSetClipOrigin(dpy, tile_map->black_gc, 0, 0); + XSetClipMask(dpy, tile_map->black_gc, None); + XSetForeground(dpy, tile_map->black_gc, + BlackPixelOfScreen(screen)); + } + } + } - if (inverted) { - XDrawRectangle(XtDisplay(wp->w), XtWindow(wp->w), + if (inverted) { + XDrawRectangle( + XtDisplay(wp->w), XtWindow(wp->w), #ifdef USE_WHITE - /* kludge for white square... */ - tile_map->glyphs[start_row][start_col] == - cmap_to_glyph(S_ice) ? - tile_map->black_gc : tile_map->white_gc, + /* kludge for white square... */ + tile_map->glyphs[start_row][start_col] == cmap_to_glyph(S_ice) + ? tile_map->black_gc + : tile_map->white_gc, #else - tile_map->white_gc, + tile_map->white_gc, #endif - start_col * tile_map->square_width, - start_row * tile_map->square_height, - tile_map->square_width-1, - tile_map->square_height-1); - } + start_col * tile_map->square_width, + start_row * tile_map->square_height, + tile_map->square_width - 1, tile_map->square_height - 1); + } } else { - struct text_map_info_t *text_map = &map_info->text_map; + struct text_map_info_t *text_map = &map_info->text_map; #ifdef TEXTCOLOR - if (iflags.use_color) { - register char *c_ptr; - char *t_ptr; - int cur_col, color, win_ystart; - boolean cur_inv; + if (iflags.use_color) { + register char *c_ptr; + char *t_ptr; + int cur_col, color, win_ystart; + boolean cur_inv; - for (row = start_row; row <= stop_row; row++) { - win_ystart = text_map->square_ascent + - (row * text_map->square_height); + for (row = start_row; row <= stop_row; row++) { + win_ystart = + text_map->square_ascent + (row * text_map->square_height); - t_ptr = (char *) &(text_map->text[row][start_col]); - c_ptr = (char *) &(text_map->colors[row][start_col]); - cur_col = start_col; - while (cur_col <= stop_col) { - color = *c_ptr++; - cur_inv = inverted; - count = 1; - while ((cur_col + count) <= stop_col && *c_ptr == color) { - count++; - c_ptr++; - } - if (color >= CLR_MAX) { - color -= CLR_MAX; - cur_inv = !cur_inv; - } + t_ptr = (char *) &(text_map->text[row][start_col]); + c_ptr = (char *) &(text_map->colors[row][start_col]); + cur_col = start_col; + while (cur_col <= stop_col) { + color = *c_ptr++; + cur_inv = inverted; + count = 1; + while ((cur_col + count) <= stop_col && *c_ptr == color) { + count++; + c_ptr++; + } + if (color >= CLR_MAX) { + color -= CLR_MAX; + cur_inv = !cur_inv; + } - XDrawImageString(XtDisplay(wp->w), XtWindow(wp->w), - cur_inv ? text_map->inv_color_gcs[color] : - text_map->color_gcs[color], - text_map->square_lbearing + - (text_map->square_width * cur_col), - win_ystart, - t_ptr, count); + XDrawImageString(XtDisplay(wp->w), XtWindow(wp->w), + cur_inv ? text_map->inv_color_gcs[color] + : text_map->color_gcs[color], + text_map->square_lbearing + + (text_map->square_width * cur_col), + win_ystart, t_ptr, count); - /* move text pointer and column count */ - t_ptr += count; - cur_col += count; - } /* col loop */ - } /* row loop */ - } else + /* move text pointer and column count */ + t_ptr += count; + cur_col += count; + } /* col loop */ + } /* row loop */ + } else #endif /* TEXTCOLOR */ - { - int win_row, win_xstart; + { + int win_row, win_xstart; - /* We always start at the same x window position and have */ - /* the same character count. */ - win_xstart = text_map->square_lbearing + - (win_start_col * text_map->square_width); - count = stop_col - start_col + 1; + /* We always start at the same x window position and have */ + /* the same character count. */ + win_xstart = text_map->square_lbearing + + (win_start_col * text_map->square_width); + count = stop_col - start_col + 1; - for (row = start_row, win_row = win_start_row; - row <= stop_row; row++, win_row++) { - - XDrawImageString(XtDisplay(wp->w), XtWindow(wp->w), - inverted ? text_map->inv_copy_gc : text_map->copy_gc, - win_xstart, - text_map->square_ascent + - (win_row * text_map->square_height), - (char *) &(text_map->text[row][start_col]), count); - } - } + for (row = start_row, win_row = win_start_row; row <= stop_row; + row++, win_row++) { + XDrawImageString( + XtDisplay(wp->w), XtWindow(wp->w), + inverted ? text_map->inv_copy_gc : text_map->copy_gc, + win_xstart, text_map->square_ascent + + (win_row * text_map->square_height), + (char *) &(text_map->text[row][start_col]), count); + } + } } } /* Adjust the number of rows and columns on the given map window */ void set_map_size(wp, cols, rows) - struct xwindow *wp; - Dimension cols, rows; +struct xwindow *wp; +Dimension cols, rows; { Arg args[4]; Cardinal num_args; if (wp->map_information->is_tile) { - wp->pixel_width = wp->map_information->tile_map.square_width * cols; - wp->pixel_height = wp->map_information->tile_map.square_height * rows; + wp->pixel_width = wp->map_information->tile_map.square_width * cols; + wp->pixel_height = wp->map_information->tile_map.square_height * rows; } else { - wp->pixel_width = wp->map_information->text_map.square_width * cols; - wp->pixel_height = wp->map_information->text_map.square_height * rows; + wp->pixel_width = wp->map_information->text_map.square_width * cols; + wp->pixel_height = wp->map_information->text_map.square_height * rows; } num_args = 0; - XtSetArg(args[num_args], XtNwidth, wp->pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, wp->pixel_height); num_args++; + XtSetArg(args[num_args], XtNwidth, wp->pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, wp->pixel_height); + num_args++; XtSetValues(wp->w, args, num_args); } - static void init_text(wp) - struct xwindow *wp; +struct xwindow *wp; { struct map_info_t *map_info = wp->map_information; struct text_map_info_t *text_map = &map_info->text_map; @@ -1384,15 +1397,14 @@ init_text(wp) (void) memset((genericptr_t) text_map->text, ' ', sizeof(text_map->text)); #ifdef TEXTCOLOR (void) memset((genericptr_t) text_map->colors, NO_COLOR, - sizeof(text_map->colors)); + sizeof(text_map->colors)); #endif get_char_info(wp); get_text_gc(wp, WindowFont(wp->w)); } -static char map_translations[] = -"#override\n\ +static char map_translations[] = "#override\n\ Left: scroll(4)\n\ Right: scroll(6)\n\ Up: scroll(8)\n\ @@ -1405,11 +1417,11 @@ static char map_translations[] = */ void create_map_window(wp, create_popup, parent) - struct xwindow *wp; - boolean create_popup; /* parent is a popup shell that we create */ - Widget parent; +struct xwindow *wp; +boolean create_popup; /* parent is a popup shell that we create */ +Widget parent; { - struct map_info_t *map_info; /* map info pointer */ + struct map_info_t *map_info; /* map info pointer */ Widget map, viewport; Arg args[16]; Cardinal num_args; @@ -1421,34 +1433,38 @@ create_map_window(wp, create_popup, parent) wp->type = NHW_MAP; if (create_popup) { - /* - * Create a popup that accepts key and button events. - */ - num_args = 0; - XtSetArg(args[num_args], XtNinput, False); num_args++; + /* + * Create a popup that accepts key and button events. + */ + num_args = 0; + XtSetArg(args[num_args], XtNinput, False); + num_args++; - wp->popup = parent = XtCreatePopupShell("nethack", - topLevelShellWidgetClass, - toplevel, args, num_args); - /* - * If we're here, then this is an auxiliary map window. If we're - * cancelled via a delete window message, we should just pop down. - */ + wp->popup = parent = XtCreatePopupShell( + "nethack", topLevelShellWidgetClass, toplevel, args, num_args); + /* + * If we're here, then this is an auxiliary map window. If we're + * cancelled via a delete window message, we should just pop down. + */ } num_args = 0; - XtSetArg(args[num_args], XtNallowHoriz, True); num_args++; - XtSetArg(args[num_args], XtNallowVert, True); num_args++; + XtSetArg(args[num_args], XtNallowHoriz, True); + num_args++; + XtSetArg(args[num_args], XtNallowVert, True); + num_args++; /* XtSetArg(args[num_args], XtNforceBars, True); num_args++; */ - XtSetArg(args[num_args], XtNuseBottom, True); num_args++; + XtSetArg(args[num_args], XtNuseBottom, True); + num_args++; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(map_translations)); num_args++; + XtParseTranslationTable(map_translations)); + num_args++; viewport = XtCreateManagedWidget( - "map_viewport", /* name */ - viewportWidgetClass, /* widget class from Window.h */ - parent, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + "map_viewport", /* name */ + viewportWidgetClass, /* widget class from Window.h */ + parent, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ /* * Create a map window. We need to set the width and height to some @@ -1456,30 +1472,33 @@ create_map_window(wp, create_popup, parent) * later */ num_args = 0; - XtSetArg(args[num_args], XtNwidth, 100); num_args++; - XtSetArg(args[num_args], XtNheight, 100); num_args++; + XtSetArg(args[num_args], XtNwidth, 100); + num_args++; + XtSetArg(args[num_args], XtNheight, 100); + num_args++; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(map_translations)); num_args++; + XtParseTranslationTable(map_translations)); + num_args++; wp->w = map = XtCreateManagedWidget( - "map", /* name */ - windowWidgetClass, /* widget class from Window.h */ - viewport, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + "map", /* name */ + windowWidgetClass, /* widget class from Window.h */ + viewport, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ XtAddCallback(map, XtNexposeCallback, map_exposed, (XtPointer) 0); map_info = wp->map_information = - (struct map_info_t *) alloc(sizeof(struct map_info_t)); + (struct map_info_t *) alloc(sizeof(struct map_info_t)); map_info->viewport_width = map_info->viewport_height = 0; /* reset the "new entry" indicators */ (void) memset((genericptr_t) map_info->t_start, (char) COLNO, - sizeof(map_info->t_start)); + sizeof(map_info->t_start)); (void) memset((genericptr_t) map_info->t_stop, (char) 0, - sizeof(map_info->t_stop)); + sizeof(map_info->t_stop)); /* we probably want to restrict this to the 1st map window only */ map_info->is_tile = (init_tiles(wp) && iflags.wc_tiled_map); @@ -1492,13 +1511,17 @@ create_map_window(wp, create_popup, parent) * realized, then the map can resize to its normal size. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNrows), &rows); num_args++; - XtSetArg(args[num_args], nhStr(XtNcolumns), &columns); num_args++; + XtSetArg(args[num_args], nhStr(XtNrows), &rows); + num_args++; + XtSetArg(args[num_args], nhStr(XtNcolumns), &columns); + num_args++; XtGetValues(wp->w, args, num_args); /* Don't bother with windows larger than ROWNOxCOLNO. */ - if (columns > COLNO) columns = COLNO; - if (rows > ROWNO) rows = ROWNO; + if (columns > COLNO) + columns = COLNO; + if (rows > ROWNO) + rows = ROWNO; set_map_size(wp, columns, rows); @@ -1507,10 +1530,10 @@ create_map_window(wp, create_popup, parent) * viewport is also realized. Then resize the map window. */ if (create_popup) { - XtRealizeWidget(wp->popup); - XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), - &wm_delete_window, 1); - set_map_size(wp, COLNO, ROWNO); + XtRealizeWidget(wp->popup); + XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), + &wm_delete_window, 1); + set_map_size(wp, COLNO, ROWNO); } map_all_stone(map_info); @@ -1521,47 +1544,46 @@ create_map_window(wp, create_popup, parent) */ void destroy_map_window(wp) - struct xwindow *wp; +struct xwindow *wp; { struct map_info_t *map_info = wp->map_information; if (wp->popup) - nh_XtPopdown(wp->popup); + nh_XtPopdown(wp->popup); if (map_info) { - struct text_map_info_t *text_map = &map_info->text_map; + struct text_map_info_t *text_map = &map_info->text_map; - /* Free allocated GCs. */ +/* Free allocated GCs. */ #ifdef TEXTCOLOR - int i; + int i; - for (i = 0; i < CLR_MAX; i++) { - XtReleaseGC(wp->w, text_map->color_gcs[i]); - XtReleaseGC(wp->w, text_map->inv_color_gcs[i]); - } + for (i = 0; i < CLR_MAX; i++) { + XtReleaseGC(wp->w, text_map->color_gcs[i]); + XtReleaseGC(wp->w, text_map->inv_color_gcs[i]); + } #else - XtReleaseGC(wp->w, text_map->copy_gc); - XtReleaseGC(wp->w, text_map->inv_copy_gc); + XtReleaseGC(wp->w, text_map->copy_gc); + XtReleaseGC(wp->w, text_map->inv_copy_gc); #endif - /* Free malloc'ed space. */ - free((genericptr_t)map_info); - wp->map_information = 0; + /* Free malloc'ed space. */ + free((genericptr_t) map_info); + wp->map_information = 0; } - /* Destroy map widget. */ + /* Destroy map widget. */ if (wp->popup && !wp->keep_window) - XtDestroyWidget(wp->popup), wp->popup = (Widget)0; + XtDestroyWidget(wp->popup), wp->popup = (Widget) 0; if (wp->keep_window) - XtRemoveCallback(wp->w, XtNexposeCallback, map_exposed, (XtPointer)0); + XtRemoveCallback(wp->w, XtNexposeCallback, map_exposed, + (XtPointer) 0); else - wp->type = NHW_NONE; /* allow re-use */ + wp->type = NHW_NONE; /* allow re-use */ } - - -boolean exit_x_event; /* exit condition for the event loop */ +boolean exit_x_event; /* exit condition for the event loop */ /******* pkey(k) int k; @@ -1576,85 +1598,85 @@ pkey(k) */ int x_event(exit_condition) - int exit_condition; +int exit_condition; { - XEvent event; - int retval = 0; + XEvent event; + int retval = 0; boolean keep_going = TRUE; /* Hold globals so function is re-entrant */ boolean hold_exit_x_event = exit_x_event; - click_button = NO_CLICK; /* reset click exit condition */ - exit_x_event = FALSE; /* reset callback exit condition */ + click_button = NO_CLICK; /* reset click exit condition */ + exit_x_event = FALSE; /* reset callback exit condition */ /* * Loop until we get a sent event, callback exit, or are accepting key * press and button press events and we receive one. */ - if((exit_condition == EXIT_ON_KEY_PRESS || - exit_condition == EXIT_ON_KEY_OR_BUTTON_PRESS) && incount) - goto try_test; + if ((exit_condition == EXIT_ON_KEY_PRESS + || exit_condition == EXIT_ON_KEY_OR_BUTTON_PRESS) && incount) + goto try_test; do { - XtAppNextEvent(app_context, &event); - XtDispatchEvent(&event); + XtAppNextEvent(app_context, &event); + XtDispatchEvent(&event); - /* See if we can exit. */ + /* See if we can exit. */ try_test: - switch (exit_condition) { - case EXIT_ON_SENT_EVENT: { - XAnyEvent *any = (XAnyEvent *) &event; - if (any->send_event) { - retval = 0; - keep_going = FALSE; - } - break; - } - case EXIT_ON_EXIT: - if (exit_x_event) { - incount = 0; - retval = 0; - keep_going = FALSE; - } - break; - case EXIT_ON_KEY_PRESS: - if (incount != 0) { - /* get first pressed key */ - --incount; - retval = inbuf[inptr]; - inptr = (inptr+1) % INBUF_SIZE; - /* pkey(retval); */ - keep_going = FALSE; - } else if (program_state.done_hup) { - retval = '\033'; - inptr = (inptr+1) % INBUF_SIZE; - keep_going = FALSE; - } - break; - case EXIT_ON_KEY_OR_BUTTON_PRESS: - if (incount != 0 || click_button != NO_CLICK) { - if (click_button != NO_CLICK) { /* button press */ - /* click values are already set */ - retval = 0; - } else { /* key press */ - /* get first pressed key */ - --incount; - retval = inbuf[inptr]; - inptr = (inptr+1) % INBUF_SIZE; - /* pkey(retval); */ - } - keep_going = FALSE; - } else if (program_state.done_hup) { - retval = '\033'; - inptr = (inptr+1) % INBUF_SIZE; - keep_going = FALSE; - } - break; - default: - panic("x_event: unknown exit condition %d", exit_condition); - break; - } + switch (exit_condition) { + case EXIT_ON_SENT_EVENT: { + XAnyEvent *any = (XAnyEvent *) &event; + if (any->send_event) { + retval = 0; + keep_going = FALSE; + } + break; + } + case EXIT_ON_EXIT: + if (exit_x_event) { + incount = 0; + retval = 0; + keep_going = FALSE; + } + break; + case EXIT_ON_KEY_PRESS: + if (incount != 0) { + /* get first pressed key */ + --incount; + retval = inbuf[inptr]; + inptr = (inptr + 1) % INBUF_SIZE; + /* pkey(retval); */ + keep_going = FALSE; + } else if (program_state.done_hup) { + retval = '\033'; + inptr = (inptr + 1) % INBUF_SIZE; + keep_going = FALSE; + } + break; + case EXIT_ON_KEY_OR_BUTTON_PRESS: + if (incount != 0 || click_button != NO_CLICK) { + if (click_button != NO_CLICK) { /* button press */ + /* click values are already set */ + retval = 0; + } else { /* key press */ + /* get first pressed key */ + --incount; + retval = inbuf[inptr]; + inptr = (inptr + 1) % INBUF_SIZE; + /* pkey(retval); */ + } + keep_going = FALSE; + } else if (program_state.done_hup) { + retval = '\033'; + inptr = (inptr + 1) % INBUF_SIZE; + keep_going = FALSE; + } + break; + default: + panic("x_event: unknown exit condition %d", exit_condition); + break; + } } while (keep_going); /* Restore globals */ diff --git a/win/X11/winmenu.c b/win/X11/winmenu.c index ef7090a4d..8a4aba341 100644 --- a/win/X11/winmenu.c +++ b/win/X11/winmenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winmenu.c $NHDT-Date: 1430899135 2015/05/06 07:58:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ +/* NetHack 3.6 winmenu.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 winmenu.c $Date: 2009/05/06 10:55:53 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)winmenu.c 3.5 1996/08/15 */ /* Copyright (c) Dean Luick, 1992 */ @@ -9,10 +9,10 @@ * * + Global functions: start_menu, add_menu, end_menu, select_menu */ -/*#define USE_FWF*/ /* use FWF's list widget */ +/*#define USE_FWF*/ /* use FWF's list widget */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -32,19 +32,19 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #include "hack.h" #include "winX.h" #include - static void FDECL(menu_select, (Widget, XtPointer, XtPointer)); -static void FDECL(invert_line, (struct xwindow *,x11_menu_item *,int,long)); +static void FDECL(invert_line, + (struct xwindow *, x11_menu_item *, int, long)); static void FDECL(menu_ok, (Widget, XtPointer, XtPointer)); static void FDECL(menu_cancel, (Widget, XtPointer, XtPointer)); static void FDECL(menu_all, (Widget, XtPointer, XtPointer)); @@ -53,9 +53,9 @@ static void FDECL(menu_invert, (Widget, XtPointer, XtPointer)); static void FDECL(menu_search, (Widget, XtPointer, XtPointer)); static void FDECL(select_all, (struct xwindow *)); static void FDECL(select_none, (struct xwindow *)); -static void FDECL(select_match, (struct xwindow *, char*)); +static void FDECL(select_match, (struct xwindow *, char *)); static void FDECL(invert_all, (struct xwindow *)); -static void FDECL(invert_match, (struct xwindow *, char*)); +static void FDECL(invert_match, (struct xwindow *, char *)); static void FDECL(menu_popdown, (struct xwindow *)); #ifdef USE_FWF static void FDECL(sync_selected, (struct menu_info_t *, int, int *)); @@ -67,11 +67,9 @@ static void FDECL(reset_menu_to_default, (struct menu *)); static void FDECL(clear_old_menu, (struct xwindow *)); static char *FDECL(copy_of, (const char *)); -#define reset_menu_count(mi) ((mi)->counting = FALSE, (mi)->menu_count = 0L) +#define reset_menu_count(mi) ((mi)->counting = FALSE, (mi)->menu_count = 0L) - -static const char menu_translations[] = - "#override\n\ +static const char menu_translations[] = "#override\n\ Left: scroll(4)\n\ Right: scroll(6)\n\ Up: scroll(8)\n\ @@ -84,8 +82,8 @@ static const char menu_translations[] = /* ARGSUSED */ static void menu_select(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { struct xwindow *wp; struct menu_info_t *menu_info; @@ -101,51 +99,52 @@ menu_select(w, client_data, call_data) nhUse(client_data); wp = find_widget(w); - menu_info = wp->menu_information; + menu_info = wp->menu_information; how_many = menu_info->counting ? menu_info->menu_count : -1L; reset_menu_count(menu_info); #ifdef USE_FWF /* if we've reached here, we've found our selected item */ switch (lrs->action) { - case XfwfMultiListActionNothing: - pline("menu_select: nothing action?"); - break; - case XfwfMultiListActionStatus: - pline("menu_select: status action?"); - break; - case XfwfMultiListActionHighlight: - case XfwfMultiListActionUnhighlight: - sync_selected(menu_info,lrs->num_selected,lrs->selected_items); - break; + case XfwfMultiListActionNothing: + pline("menu_select: nothing action?"); + break; + case XfwfMultiListActionStatus: + pline("menu_select: status action?"); + break; + case XfwfMultiListActionHighlight: + case XfwfMultiListActionUnhighlight: + sync_selected(menu_info, lrs->num_selected, lrs->selected_items); + break; } #else for (i = 0, curr = menu_info->curr_menu.base; i < lrs->list_index; i++) { - if (!curr) panic("menu_select: out of menu items!"); - curr = curr->next; + if (!curr) + panic("menu_select: out of menu items!"); + curr = curr->next; } - XawListUnhighlight(w); /* unhilight item */ + XawListUnhighlight(w); /* unhilight item */ /* if the menu is not active or don't have an identifier, try again */ if (!menu_info->is_active || curr->identifier.a_void == 0) { - X11_nhbell(); - return; + X11_nhbell(); + return; } /* if we've reached here, we've found our selected item */ curr->selected = !curr->selected; if (curr->selected) { - curr->str[2] = (how_many != -1L) ? '#' : '+'; - curr->pick_count = how_many; + curr->str[2] = (how_many != -1L) ? '#' : '+'; + curr->pick_count = how_many; } else { - curr->str[2] = '-'; - curr->pick_count = -1L; + curr->str[2] = '-'; + curr->pick_count = -1L; } XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, True); #endif if (menu_info->how == PICK_ONE) - menu_popdown(wp); + menu_popdown(wp); } /* @@ -154,16 +153,16 @@ menu_select(w, client_data, call_data) /* ARGSUSED */ void menu_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(event); nhUse(params); nhUse(num_params); - menu_cancel((Widget)None, (XtPointer) find_widget(w), (XtPointer) 0); + menu_cancel((Widget) None, (XtPointer) find_widget(w), (XtPointer) 0); } /* @@ -172,10 +171,10 @@ menu_delete(w, event, params, num_params) /*ARGSUSED*/ static void invert_line(wp, curr, which, how_many) - struct xwindow *wp; - x11_menu_item *curr; - int which; - long how_many; +struct xwindow *wp; +x11_menu_item *curr; +int which; +long how_many; { #ifndef USE_FWF nhUse(which); @@ -184,18 +183,18 @@ invert_line(wp, curr, which, how_many) curr->selected = !curr->selected; if (curr->selected) { #ifdef USE_FWF - XfwfMultiListHighlightItem((XfwfMultiListWidget)wp->w, which); + XfwfMultiListHighlightItem((XfwfMultiListWidget) wp->w, which); #else - curr->str[2] = (how_many != -1) ? '#' : '+'; + curr->str[2] = (how_many != -1) ? '#' : '+'; #endif - curr->pick_count = how_many; + curr->pick_count = how_many; } else { #ifdef USE_FWF - XfwfMultiListUnhighlightItem((XfwfMultiListWidget)wp->w, which); + XfwfMultiListUnhighlightItem((XfwfMultiListWidget) wp->w, which); #else - curr->str[2] = '-'; + curr->str[2] = '-'; #endif - curr->pick_count = -1L; + curr->pick_count = -1L; } } @@ -205,10 +204,10 @@ invert_line(wp, curr, which, how_many) /* ARGSUSED */ void menu_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { struct menu_info_t *menu_info; x11_menu_item *curr; @@ -225,136 +224,142 @@ menu_key(w, event, params, num_params) ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } - if (menu_info->is_active) { /* waiting for input */ - /* first check for an explicit selector match, so that it won't be - overridden if it happens to duplicate a mapped menu command (':' - to look inside a container vs ':' to select via search string) */ - for (curr = menu_info->curr_menu.base; curr; curr = curr->next) - if (curr->identifier.a_void != 0 && curr->selector == ch) - goto make_selection; + if (menu_info->is_active) { /* waiting for input */ + /* first check for an explicit selector match, so that it won't be + overridden if it happens to duplicate a mapped menu command (':' + to look inside a container vs ':' to select via search string) */ + for (curr = menu_info->curr_menu.base; curr; curr = curr->next) + if (curr->identifier.a_void != 0 && curr->selector == ch) + goto make_selection; - ch = map_menu_cmd(ch); - if (ch == '\033') { /* quit */ - if (menu_info->counting) { - /* when there's a count in progress, ESC discards it - rather than dismissing the whole menu */ - reset_menu_count(menu_info); - return; - } - select_none(wp); - } else if (ch == '\n' || ch == '\r') { - ; /* accept */ - } else if (isdigit(ch)) { - /* special case: '0' is also the default ball class */ - if (ch == '0' && !menu_info->counting && - index(menu_info->curr_menu.gacc, ch)) - goto group_accel; - menu_info->menu_count *= 10L; - menu_info->menu_count += (long)(ch - '0'); - if (menu_info->menu_count != 0L) /* ignore leading zeros */ - menu_info->counting = TRUE; - return; - } else if (ch == MENU_SEARCH) { /* search */ - if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) { - char buf[BUFSZ+2], tmpbuf[BUFSZ]; + ch = map_menu_cmd(ch); + if (ch == '\033') { /* quit */ + if (menu_info->counting) { + /* when there's a count in progress, ESC discards it + rather than dismissing the whole menu */ + reset_menu_count(menu_info); + return; + } + select_none(wp); + } else if (ch == '\n' || ch == '\r') { + ; /* accept */ + } else if (isdigit(ch)) { + /* special case: '0' is also the default ball class */ + if (ch == '0' && !menu_info->counting + && index(menu_info->curr_menu.gacc, ch)) + goto group_accel; + menu_info->menu_count *= 10L; + menu_info->menu_count += (long) (ch - '0'); + if (menu_info->menu_count != 0L) /* ignore leading zeros */ + menu_info->counting = TRUE; + return; + } else if (ch == MENU_SEARCH) { /* search */ + if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) { + char buf[BUFSZ + 2], tmpbuf[BUFSZ]; - X11_getlin("Search for:", tmpbuf); - if (!*tmpbuf || *tmpbuf == '\033') return; - /* convert "string" into "*string*" for use with pmatch() */ - Sprintf(buf, "*%s*", tmpbuf); + X11_getlin("Search for:", tmpbuf); + if (!*tmpbuf || *tmpbuf == '\033') + return; + /* convert "string" into "*string*" for use with pmatch() */ + Sprintf(buf, "*%s*", tmpbuf); - if (menu_info->how == PICK_ANY) { - invert_match(wp, buf); - return; - } else { - select_match(wp, buf); - } - } else { - X11_nhbell(); - return; - } - } else if (ch == MENU_SELECT_ALL) { /* select all */ - if (menu_info->how == PICK_ANY) - select_all(wp); - else - X11_nhbell(); - return; - } else if (ch == MENU_UNSELECT_ALL) { /* unselect all */ - if (menu_info->how == PICK_ANY) - select_none(wp); - else - X11_nhbell(); - return; - } else if (ch == MENU_INVERT_ALL) { /* invert all */ - if (menu_info->how == PICK_ANY) - invert_all(wp); - else - X11_nhbell(); - return; - } else if (index(menu_info->curr_menu.gacc, ch)) { - group_accel: - /* matched a group accelerator */ - if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) { - for (count = 0, curr = menu_info->curr_menu.base; curr; - curr = curr->next, count++) { - if (curr->identifier.a_void != 0 && curr->gselector == ch) { - invert_line(wp, curr, count, -1L); - /* for PICK_ONE, a group accelerator will - only be included in gacc[] if it matches - exactly one entry, so this must be it... */ - if (menu_info->how == PICK_ONE) - goto menu_done; /* pop down */ - } - } + if (menu_info->how == PICK_ANY) { + invert_match(wp, buf); + return; + } else { + select_match(wp, buf); + } + } else { + X11_nhbell(); + return; + } + } else if (ch == MENU_SELECT_ALL) { /* select all */ + if (menu_info->how == PICK_ANY) + select_all(wp); + else + X11_nhbell(); + return; + } else if (ch == MENU_UNSELECT_ALL) { /* unselect all */ + if (menu_info->how == PICK_ANY) + select_none(wp); + else + X11_nhbell(); + return; + } else if (ch == MENU_INVERT_ALL) { /* invert all */ + if (menu_info->how == PICK_ANY) + invert_all(wp); + else + X11_nhbell(); + return; + } else if (index(menu_info->curr_menu.gacc, ch)) { + group_accel: + /* matched a group accelerator */ + if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) { + for (count = 0, curr = menu_info->curr_menu.base; curr; + curr = curr->next, count++) { + if (curr->identifier.a_void != 0 + && curr->gselector == ch) { + invert_line(wp, curr, count, -1L); + /* for PICK_ONE, a group accelerator will + only be included in gacc[] if it matches + exactly one entry, so this must be it... */ + if (menu_info->how == PICK_ONE) + goto menu_done; /* pop down */ + } + } #ifndef USE_FWF - XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, True); + XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, + True); #endif - } else - X11_nhbell(); - return; - } else { - make_selection: - selected_something = FALSE; - for (count = 0, curr = menu_info->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0 && curr->selector == ch) break; + } else + X11_nhbell(); + return; + } else { + make_selection: + selected_something = FALSE; + for (count = 0, curr = menu_info->curr_menu.base; curr; + curr = curr->next, count++) + if (curr->identifier.a_void != 0 && curr->selector == ch) + break; - if (curr) { - invert_line(wp, curr, count, - menu_info->counting ? menu_info->menu_count : -1L); + if (curr) { + invert_line(wp, curr, count, menu_info->counting + ? menu_info->menu_count + : -1L); #ifndef USE_FWF - XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, True); + XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, + True); #endif - selected_something = curr->selected; - } else { - X11_nhbell(); /* no match */ - } - if (!(selected_something && menu_info->how == PICK_ONE)) - return; /* keep going */ - } - /* pop down */ - } else { /* permanent inventory window */ - if (ch != '\033') { - X11_nhbell(); - return; - } - /* pop down on ESC */ + selected_something = curr->selected; + } else { + X11_nhbell(); /* no match */ + } + if (!(selected_something && menu_info->how == PICK_ONE)) + return; /* keep going */ + } + /* pop down */ + } else { /* permanent inventory window */ + if (ch != '\033') { + X11_nhbell(); + return; + } + /* pop down on ESC */ } - menu_done: +menu_done: menu_popdown(wp); } /* ARGSUSED */ static void menu_ok(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { struct xwindow *wp = (struct xwindow *) client_data; @@ -367,8 +372,8 @@ menu_ok(w, client_data, call_data) /* ARGSUSED */ static void menu_cancel(w, client_data, call_data) - Widget w; /* don't use - may be None */ - XtPointer client_data, call_data; +Widget w; /* don't use - may be None */ +XtPointer client_data, call_data; { struct xwindow *wp = (struct xwindow *) client_data; @@ -376,8 +381,8 @@ menu_cancel(w, client_data, call_data) nhUse(call_data); if (wp->menu_information->is_active) { - select_none(wp); - wp->menu_information->cancelled = TRUE; + select_none(wp); + wp->menu_information->cancelled = TRUE; } menu_popdown(wp); } @@ -385,8 +390,8 @@ menu_cancel(w, client_data, call_data) /* ARGSUSED */ static void menu_all(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(call_data); @@ -397,8 +402,8 @@ menu_all(w, client_data, call_data) /* ARGSUSED */ static void menu_none(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(call_data); @@ -409,8 +414,8 @@ menu_none(w, client_data, call_data) /* ARGSUSED */ static void menu_invert(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(call_data); @@ -421,33 +426,34 @@ menu_invert(w, client_data, call_data) /* ARGSUSED */ static void menu_search(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { struct xwindow *wp = (struct xwindow *) client_data; struct menu_info_t *menu_info = wp->menu_information; - char buf[BUFSZ+2], tmpbuf[BUFSZ]; + char buf[BUFSZ + 2], tmpbuf[BUFSZ]; nhUse(w); nhUse(call_data); X11_getlin("Search for:", tmpbuf); - if (!*tmpbuf || *tmpbuf == '\033') return; + if (!*tmpbuf || *tmpbuf == '\033') + return; /* convert "string" into "*string*" for use with pmatch() */ Sprintf(buf, "*%s*", tmpbuf); if (menu_info->how == PICK_ANY) - invert_match(wp, buf); + invert_match(wp, buf); else - select_match(wp, buf); + select_match(wp, buf); if (menu_info->how == PICK_ONE) - menu_popdown(wp); + menu_popdown(wp); } static void select_all(wp) - struct xwindow *wp; +struct xwindow *wp; { x11_menu_item *curr; int count; @@ -455,23 +461,23 @@ select_all(wp) reset_menu_count(wp->menu_information); for (count = 0, curr = wp->menu_information->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0) - if (!curr->selected) { - invert_line(wp, curr, count, -1L); - changed = TRUE; - } + curr = curr->next, count++) + if (curr->identifier.a_void != 0) + if (!curr->selected) { + invert_line(wp, curr, count, -1L); + changed = TRUE; + } #ifndef USE_FWF if (changed) - XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, - 0, 0, True); + XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, 0, + 0, True); #endif } static void select_none(wp) - struct xwindow *wp; +struct xwindow *wp; { x11_menu_item *curr; int count; @@ -479,43 +485,43 @@ select_none(wp) reset_menu_count(wp->menu_information); for (count = 0, curr = wp->menu_information->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0) - if (curr->selected) { - invert_line(wp, curr, count, -1L); - changed = TRUE; - } + curr = curr->next, count++) + if (curr->identifier.a_void != 0) + if (curr->selected) { + invert_line(wp, curr, count, -1L); + changed = TRUE; + } #ifndef USE_FWF if (changed) - XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, - 0, 0, True); + XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, 0, + 0, True); #endif } static void invert_all(wp) - struct xwindow *wp; +struct xwindow *wp; { x11_menu_item *curr; int count; reset_menu_count(wp->menu_information); for (count = 0, curr = wp->menu_information->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0) - invert_line(wp, curr, count, -1L); + curr = curr->next, count++) + if (curr->identifier.a_void != 0) + invert_line(wp, curr, count, -1L); #ifndef USE_FWF - XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, - 0, 0, True); + XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, 0, 0, + True); #endif } static void invert_match(wp, match) - struct xwindow *wp; - char *match; /* wildcard pattern for pmatch() */ +struct xwindow *wp; +char *match; /* wildcard pattern for pmatch() */ { x11_menu_item *curr; int count; @@ -523,41 +529,41 @@ invert_match(wp, match) reset_menu_count(wp->menu_information); for (count = 0, curr = wp->menu_information->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) { - invert_line(wp, curr, count, -1L); - changed = TRUE; - } + curr = curr->next, count++) + if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) { + invert_line(wp, curr, count, -1L); + changed = TRUE; + } #ifndef USE_FWF if (changed) - XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, - 0, 0, True); + XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer, 0, + 0, True); #endif } static void select_match(wp, match) - struct xwindow *wp; - char *match; /* wildcard pattern for pmatch() */ +struct xwindow *wp; +char *match; /* wildcard pattern for pmatch() */ { x11_menu_item *curr; int count; reset_menu_count(wp->menu_information); for (count = 0, curr = wp->menu_information->curr_menu.base; curr; - curr = curr->next, count++) - if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) { - if (!curr->selected) { - invert_line(wp, curr, count, -1L); + curr = curr->next, count++) + if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) { + if (!curr->selected) { + invert_line(wp, curr, count, -1L); #ifndef USE_FWF - XawListChange(wp->w, - wp->menu_information->curr_menu.list_pointer, - 0, 0, True); + XawListChange(wp->w, + wp->menu_information->curr_menu.list_pointer, 0, + 0, True); #endif - } - return; - } + } + return; + } /* no match */ X11_nhbell(); @@ -565,12 +571,12 @@ select_match(wp, match) static void menu_popdown(wp) - struct xwindow *wp; +struct xwindow *wp; { - nh_XtPopdown(wp->popup); /* remove the event grab */ + nh_XtPopdown(wp->popup); /* remove the event grab */ if (wp->menu_information->is_active) - exit_x_event = TRUE; /* exit our event handler */ - wp->menu_information->is_up = FALSE; /* menu is down */ + exit_x_event = TRUE; /* exit our event handler */ + wp->menu_information->is_up = FALSE; /* menu is down */ } #ifdef USE_FWF @@ -583,38 +589,39 @@ menu_popdown(wp) */ static void sync_selected(menu_info, num_selected, items) - struct menu_info_t *menu_info; - int num_selected; - int *items; +struct menu_info_t *menu_info; +int num_selected; +int *items; { int i, j, *ip; x11_menu_item *curr; Boolean found; - for (i=0, curr = menu_info->curr_menu.base; curr; i++, curr = curr->next) { - found = False; - for (j = 0, ip = items; j < num_selected; j++, ip++) - if (*ip == i) { - found = True; - break; - } + for (i = 0, curr = menu_info->curr_menu.base; curr; + i++, curr = curr->next) { + found = False; + for (j = 0, ip = items; j < num_selected; j++, ip++) + if (*ip == i) { + found = True; + break; + } #if 0 if (curr->selected && !found) printf("sync: deselecting %s\n", curr->str); else if (!curr->selected && found) printf("sync: selecting %s\n", curr->str); #endif - curr->selected = found ? TRUE : FALSE; + curr->selected = found ? TRUE : FALSE; } } #endif /* USE_FWF */ - -/* Global functions ======================================================== */ +/* Global functions ======================================================== + */ void X11_start_menu(window) - winid window; +winid window; { struct xwindow *wp; check_winid(window); @@ -622,84 +629,84 @@ X11_start_menu(window) wp = &window_list[window]; if (wp->menu_information->is_menu) { - /* make sure we'ere starting with a clean slate */ - free_menu(&wp->menu_information->new_menu); + /* make sure we'ere starting with a clean slate */ + free_menu(&wp->menu_information->new_menu); } else { - wp->menu_information->is_menu = TRUE; + wp->menu_information->is_menu = TRUE; } } /*ARGSUSED*/ void X11_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) - winid window; - int glyph; /* unused (for now) */ - const anything *identifier; - char ch; - char gch; /* group accelerator (0 = no group) */ - int attr; - const char *str; - boolean preselected; +winid window; +int glyph; /* unused (for now) */ +const anything *identifier; +char ch; +char gch; /* group accelerator (0 = no group) */ +int attr; +const char *str; +boolean preselected; { x11_menu_item *item; struct menu_info_t *menu_info; nhUse(glyph); - nhUse(preselected); /*FIXME*/ + nhUse(preselected); /*FIXME*/ check_winid(window); menu_info = window_list[window].menu_information; if (!menu_info->is_menu) { - impossible("add_menu: called before start_menu"); - return; + impossible("add_menu: called before start_menu"); + return; } - item = (x11_menu_item *) alloc((unsigned)sizeof(x11_menu_item)); + item = (x11_menu_item *) alloc((unsigned) sizeof(x11_menu_item)); item->next = (x11_menu_item *) 0; item->identifier = *identifier; item->attr = attr; -/* item->selected = preselected; */ + /* item->selected = preselected; */ item->selected = FALSE; item->pick_count = -1L; if (identifier->a_void) { - char buf[4+BUFSZ]; - int len = strlen(str); + char buf[4 + BUFSZ]; + int len = strlen(str); - if (!ch) { - /* Supply a keyboard accelerator. Only the first 52 get one. */ + if (!ch) { + /* Supply a keyboard accelerator. Only the first 52 get one. */ - if (menu_info->new_menu.curr_selector) { - ch = menu_info->new_menu.curr_selector++; - if (ch == 'z') - menu_info->new_menu.curr_selector = 'A'; - else if (ch == 'Z') - menu_info->new_menu.curr_selector = 0; /* out */ - } - } + if (menu_info->new_menu.curr_selector) { + ch = menu_info->new_menu.curr_selector++; + if (ch == 'z') + menu_info->new_menu.curr_selector = 'A'; + else if (ch == 'Z') + menu_info->new_menu.curr_selector = 0; /* out */ + } + } - if (len >= BUFSZ) { - /* We *think* everything's coming in off at most BUFSZ bufs... */ - impossible("Menu item too long (%d).", len); - len = BUFSZ - 1; - } - Sprintf(buf, "%c - ", ch ? ch : ' '); - (void) strncpy(buf+4, str, len); - buf[4+len] = '\0'; - item->str = copy_of(buf); + if (len >= BUFSZ) { + /* We *think* everything's coming in off at most BUFSZ bufs... */ + impossible("Menu item too long (%d).", len); + len = BUFSZ - 1; + } + Sprintf(buf, "%c - ", ch ? ch : ' '); + (void) strncpy(buf + 4, str, len); + buf[4 + len] = '\0'; + item->str = copy_of(buf); } else { - /* no keyboard accelerator */ - item->str = copy_of(str); - ch = 0; + /* no keyboard accelerator */ + item->str = copy_of(str); + ch = 0; } item->selector = ch; item->gselector = gch; if (menu_info->new_menu.last) { - menu_info->new_menu.last->next = item; + menu_info->new_menu.last->next = item; } else { - menu_info->new_menu.base = item; + menu_info->new_menu.base = item; } menu_info->new_menu.last = item; menu_info->new_menu.count++; @@ -707,25 +714,25 @@ X11_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) void X11_end_menu(window, query) - winid window; - const char *query; +winid window; +const char *query; { struct menu_info_t *menu_info; check_winid(window); menu_info = window_list[window].menu_information; if (!menu_info->is_menu) { - impossible("end_menu: called before start_menu"); - return; + impossible("end_menu: called before start_menu"); + return; } menu_info->new_menu.query = copy_of(query); } int X11_select_menu(window, how, menu_list) - winid window; - int how; - menu_item **menu_list; +winid window; +int how; +menu_item **menu_list; { x11_menu_item *curr; struct xwindow *wp; @@ -736,7 +743,8 @@ X11_select_menu(window, how, menu_list) int retval; Dimension v_pixel_width, v_pixel_height; boolean labeled; - Widget viewport_widget, form, label, ok, cancel, all, none, invert, search; + Widget viewport_widget, form, label, ok, cancel, all, none, invert, + search; Boolean sens; #ifdef USE_FWF Boolean *boolp; @@ -748,8 +756,8 @@ X11_select_menu(window, how, menu_list) wp = &window_list[window]; menu_info = wp->menu_information; if (!menu_info->is_menu) { - impossible("select_menu: called before start_menu"); - return 0; + impossible("select_menu: called before start_menu"); + return 0; } menu_info->how = (short) how; @@ -759,25 +767,26 @@ X11_select_menu(window, how, menu_list) accepted; for PICK_ANY, those which match any entry are okay */ gacc[0] = '\0'; if (menu_info->how != PICK_NONE) { - int i, n, gcnt[128]; -#define GSELIDX(c) ((c) & 127) /* guard against `signed char' */ + int i, n, gcnt[128]; +#define GSELIDX(c) ((c) &127) /* guard against `signed char' */ - for (i = 0; i < SIZE(gcnt); i++) gcnt[i] = 0; - for (n = 0, curr = menu_info->new_menu.base; curr; curr = curr->next) - if (curr->gselector && curr->gselector != curr->selector) { - ++n; - ++gcnt[GSELIDX(curr->gselector)]; - } + for (i = 0; i < SIZE(gcnt); i++) + gcnt[i] = 0; + for (n = 0, curr = menu_info->new_menu.base; curr; curr = curr->next) + if (curr->gselector && curr->gselector != curr->selector) { + ++n; + ++gcnt[GSELIDX(curr->gselector)]; + } - if (n > 0) /* at least one group accelerator found */ - for (ap = gacc, curr = menu_info->new_menu.base; - curr; curr = curr->next) - if (curr->gselector && !index(gacc, curr->gselector) && - (menu_info->how == PICK_ANY || - gcnt[GSELIDX(curr->gselector)] == 1)) { - *ap++ = curr->gselector; - *ap = '\0'; /* re-terminate for index() */ - } + if (n > 0) /* at least one group accelerator found */ + for (ap = gacc, curr = menu_info->new_menu.base; curr; + curr = curr->next) + if (curr->gselector && !index(gacc, curr->gselector) + && (menu_info->how == PICK_ANY + || gcnt[GSELIDX(curr->gselector)] == 1)) { + *ap++ = curr->gselector; + *ap = '\0'; /* re-terminate for index() */ + } } menu_info->new_menu.gacc = copy_of(gacc); reset_menu_count(menu_info); @@ -785,22 +794,23 @@ X11_select_menu(window, how, menu_list) /* * Create a string and sensitive list for the new menu. */ - menu_info->new_menu.list_pointer = ptr = (String *) - alloc((unsigned) (sizeof(String) * (menu_info->new_menu.count+1))); + menu_info->new_menu.list_pointer = ptr = (String *) alloc( + (unsigned) (sizeof(String) * (menu_info->new_menu.count + 1))); for (curr = menu_info->new_menu.base; curr; ptr++, curr = curr->next) - *ptr = (String) curr->str; - *ptr = 0; /* terminate list with null */ + *ptr = (String) curr->str; + *ptr = 0; /* terminate list with null */ #ifdef USE_FWF - menu_info->new_menu.sensitive = boolp = (Boolean *) - alloc((unsigned) (sizeof(Boolean) * (menu_info->new_menu.count))); + menu_info->new_menu.sensitive = boolp = (Boolean *) alloc( + (unsigned) (sizeof(Boolean) * (menu_info->new_menu.count))); for (curr = menu_info->new_menu.base; curr; boolp++, curr = curr->next) - *boolp = (curr->identifier.a_void != 0); + *boolp = (curr->identifier.a_void != 0); #else menu_info->new_menu.sensitive = (Boolean *) 0; #endif labeled = (menu_info->new_menu.query && *(menu_info->new_menu.query)) - ? TRUE : FALSE; + ? TRUE + : FALSE; /* * Menus don't appear to size components correctly, except @@ -808,294 +818,353 @@ X11_select_menu(window, how, menu_list) * each time. */ if (menu_info->valid_widgets - && (window != WIN_INVEN || !flags.perm_invent)) { - XtDestroyWidget(wp->popup); - menu_info->valid_widgets = FALSE; - menu_info->is_up = FALSE; + && (window != WIN_INVEN || !flags.perm_invent)) { + XtDestroyWidget(wp->popup); + menu_info->valid_widgets = FALSE; + menu_info->is_up = FALSE; } if (!menu_info->valid_widgets) { - Dimension row_spacing; + Dimension row_spacing; - num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; - wp->popup = XtCreatePopupShell( - window == WIN_INVEN ? "inventory" : "menu", - how == PICK_NONE ? topLevelShellWidgetClass: - transientShellWidgetClass, - toplevel, args, num_args); - XtOverrideTranslations(wp->popup, - XtParseTranslationTable("WM_PROTOCOLS: menu_delete()")); + num_args = 0; + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; + wp->popup = + XtCreatePopupShell(window == WIN_INVEN ? "inventory" : "menu", + how == PICK_NONE ? topLevelShellWidgetClass + : transientShellWidgetClass, + toplevel, args, num_args); + XtOverrideTranslations( + wp->popup, + XtParseTranslationTable("WM_PROTOCOLS: menu_delete()")); + num_args = 0; + XtSetArg(args[num_args], XtNtranslations, + XtParseTranslationTable(menu_translations)); + num_args++; + form = XtCreateManagedWidget("mform", formWidgetClass, wp->popup, + args, num_args); - num_args = 0; - XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(menu_translations)); num_args++; - form = XtCreateManagedWidget("mform", - formWidgetClass, - wp->popup, - args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; - num_args = 0; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; + if (labeled) + label = + XtCreateManagedWidget(menu_info->new_menu.query, + labelWidgetClass, form, args, num_args); + else + label = NULL; - if (labeled) - label = XtCreateManagedWidget(menu_info->new_menu.query, - labelWidgetClass, - form, - args, num_args); - else label = NULL; + /* + * Create ok, cancel, all, none, invert, and search buttons.. + */ + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + ok = XtCreateManagedWidget("OK", commandWidgetClass, form, args, + num_args); + XtAddCallback(ok, XtNcallback, menu_ok, (XtPointer) wp); - /* - * Create ok, cancel, all, none, invert, and search buttons.. - */ - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - ok = XtCreateManagedWidget("OK", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(ok, XtNcallback, menu_ok, (XtPointer) wp); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), ok); + num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitive), how != PICK_NONE); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form, + args, num_args); + XtAddCallback(cancel, XtNcallback, menu_cancel, (XtPointer) wp); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), ok); num_args++; - XtSetArg(args[num_args], nhStr(XtNsensitive), - how != PICK_NONE); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - cancel = XtCreateManagedWidget("cancel", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(cancel, XtNcallback, menu_cancel, (XtPointer) wp); + sens = (how == PICK_ANY); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), cancel); + num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitive), sens); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + all = XtCreateManagedWidget("all", commandWidgetClass, form, args, + num_args); + XtAddCallback(all, XtNcallback, menu_all, (XtPointer) wp); - sens = (how == PICK_ANY); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), cancel); num_args++; - XtSetArg(args[num_args], nhStr(XtNsensitive), sens); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - all = XtCreateManagedWidget("all", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(all, XtNcallback, menu_all, (XtPointer) wp); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), all); + num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitive), sens); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + none = XtCreateManagedWidget("none", commandWidgetClass, form, args, + num_args); + XtAddCallback(none, XtNcallback, menu_none, (XtPointer) wp); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), all); num_args++; - XtSetArg(args[num_args], nhStr(XtNsensitive), sens); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - none = XtCreateManagedWidget("none", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(none, XtNcallback, menu_none, (XtPointer) wp); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), none); + num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitive), sens); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + invert = XtCreateManagedWidget("invert", commandWidgetClass, form, + args, num_args); + XtAddCallback(invert, XtNcallback, menu_invert, (XtPointer) wp); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), none); num_args++; - XtSetArg(args[num_args], nhStr(XtNsensitive), sens); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - invert = XtCreateManagedWidget("invert", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(invert, XtNcallback, menu_invert, (XtPointer) wp); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), invert); + num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitive), how != PICK_NONE); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); + num_args++; + search = XtCreateManagedWidget("search", commandWidgetClass, form, + args, num_args); + XtAddCallback(search, XtNcallback, menu_search, (XtPointer) wp); - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), invert); num_args++; - XtSetArg(args[num_args], nhStr(XtNsensitive), - how != PICK_NONE); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++; - search = XtCreateManagedWidget("search", - commandWidgetClass, - form, - args, num_args); - XtAddCallback(search, XtNcallback, menu_search, (XtPointer) wp); + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNallowVert), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNallowHoriz), False); + num_args++; + XtSetArg(args[num_args], nhStr(XtNuseBottom), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNuseRight), True); + num_args++; + /* + XtSetArg(args[num_args], nhStr(XtNforceBars), True); + num_args++; + */ + XtSetArg(args[num_args], nhStr(XtNfromVert), all); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); + num_args++; + XtSetArg(args[num_args], nhStr(XtNright), XtChainRight); + num_args++; + viewport_widget = XtCreateManagedWidget( + "menu_viewport", /* name */ + viewportWidgetClass, form, /* parent widget */ + args, num_args); /* values, and number of values */ - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNallowVert), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNallowHoriz), False); num_args++; - XtSetArg(args[num_args], nhStr(XtNuseBottom), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNuseRight), True); num_args++; -/* - XtSetArg(args[num_args], nhStr(XtNforceBars), True); num_args++; -*/ - XtSetArg(args[num_args], nhStr(XtNfromVert), all); num_args++; - XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottom), XtChainBottom); num_args++; - XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++; - XtSetArg(args[num_args], nhStr(XtNright), XtChainRight); num_args++; - viewport_widget = XtCreateManagedWidget( - "menu_viewport", /* name */ - viewportWidgetClass, - form, /* parent widget */ - args, num_args); /* values, and number of values */ + /* make new menu the current menu */ + move_menu(&menu_info->new_menu, &menu_info->curr_menu); - /* make new menu the current menu */ - move_menu(&menu_info->new_menu, &menu_info->curr_menu); - - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNforceColumns), True); num_args++; - XtSetArg(args[num_args], nhStr(XtNcolumnSpacing), 1); num_args++; - XtSetArg(args[num_args], nhStr(XtNdefaultColumns), 1); num_args++; - XtSetArg(args[num_args], nhStr(XtNlist), - menu_info->curr_menu.list_pointer); num_args++; + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNforceColumns), True); + num_args++; + XtSetArg(args[num_args], nhStr(XtNcolumnSpacing), 1); + num_args++; + XtSetArg(args[num_args], nhStr(XtNdefaultColumns), 1); + num_args++; + XtSetArg(args[num_args], nhStr(XtNlist), + menu_info->curr_menu.list_pointer); + num_args++; #ifdef USE_FWF - XtSetArg(args[num_args], nhStr(XtNsensitiveArray), - menu_info->curr_menu.sensitive); num_args++; - XtSetArg(args[num_args], nhStr(XtNmaxSelectable), - menu_info->curr_menu.count); num_args++; + XtSetArg(args[num_args], nhStr(XtNsensitiveArray), + menu_info->curr_menu.sensitive); + num_args++; + XtSetArg(args[num_args], nhStr(XtNmaxSelectable), + menu_info->curr_menu.count); + num_args++; #endif - wp->w = XtCreateManagedWidget( - "menu_list", /* name */ + wp->w = XtCreateManagedWidget("menu_list", /* name */ #ifdef USE_FWF - xfwfMultiListWidgetClass, + xfwfMultiListWidgetClass, #else - listWidgetClass, + listWidgetClass, #endif - viewport_widget, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + viewport_widget, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ - XtAddCallback(wp->w, XtNcallback, menu_select, (XtPointer) 0); + XtAddCallback(wp->w, XtNcallback, menu_select, (XtPointer) 0); - /* Get the font and margin information. */ - num_args = 0; - XtSetArg(args[num_args], XtNfont, &menu_info->fs); num_args++; - XtSetArg(args[num_args], XtNinternalHeight, - &menu_info->internal_height); num_args++; - XtSetArg(args[num_args], XtNinternalWidth, - &menu_info->internal_width); num_args++; - XtSetArg(args[num_args], nhStr(XtNrowSpacing), - &row_spacing); num_args++; - XtGetValues(wp->w, args, num_args); + /* Get the font and margin information. */ + num_args = 0; + XtSetArg(args[num_args], XtNfont, &menu_info->fs); + num_args++; + XtSetArg(args[num_args], XtNinternalHeight, + &menu_info->internal_height); + num_args++; + XtSetArg(args[num_args], XtNinternalWidth, + &menu_info->internal_width); + num_args++; + XtSetArg(args[num_args], nhStr(XtNrowSpacing), &row_spacing); + num_args++; + XtGetValues(wp->w, args, num_args); - /* font height is ascent + descent */ - menu_info->line_height = - menu_info->fs->max_bounds.ascent + - menu_info->fs->max_bounds.descent + row_spacing; + /* font height is ascent + descent */ + menu_info->line_height = menu_info->fs->max_bounds.ascent + + menu_info->fs->max_bounds.descent + + row_spacing; - menu_info->valid_widgets = TRUE; + menu_info->valid_widgets = TRUE; - num_args = 0; - XtSetArg(args[num_args], XtNwidth, &v_pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, &v_pixel_height); num_args++; - XtGetValues(wp->w, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNwidth, &v_pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, &v_pixel_height); + num_args++; + XtGetValues(wp->w, args, num_args); } else { - Dimension len; + Dimension len; - viewport_widget = XtParent(wp->w); + viewport_widget = XtParent(wp->w); - /* get the longest string on new menu */ - v_pixel_width = 0; - for (ptr = menu_info->new_menu.list_pointer; *ptr; ptr++) { - len = XTextWidth(menu_info->fs, *ptr, strlen(*ptr)); - if (len > v_pixel_width) v_pixel_width = len; - } + /* get the longest string on new menu */ + v_pixel_width = 0; + for (ptr = menu_info->new_menu.list_pointer; *ptr; ptr++) { + len = XTextWidth(menu_info->fs, *ptr, strlen(*ptr)); + if (len > v_pixel_width) + v_pixel_width = len; + } - /* add viewport internal border */ - v_pixel_width += 2 * menu_info->internal_width; - v_pixel_height = (2 * menu_info->internal_height) + - (menu_info->new_menu.count * menu_info->line_height); + /* add viewport internal border */ + v_pixel_width += 2 * menu_info->internal_width; + v_pixel_height = + (2 * menu_info->internal_height) + + (menu_info->new_menu.count * menu_info->line_height); - /* make new menu the current menu */ - move_menu(&menu_info->new_menu, &menu_info->curr_menu); + /* make new menu the current menu */ + move_menu(&menu_info->new_menu, &menu_info->curr_menu); #ifdef USE_FWF - XfwfMultiListSetNewData((XfwfMultiListWidget)wp->w, - menu_info->curr_menu.list_pointer, 0, 0, TRUE, - menu_info->curr_menu.sensitive); + XfwfMultiListSetNewData((XfwfMultiListWidget) wp->w, + menu_info->curr_menu.list_pointer, 0, 0, TRUE, + menu_info->curr_menu.sensitive); #else - XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, TRUE); + XawListChange(wp->w, menu_info->curr_menu.list_pointer, 0, 0, TRUE); #endif } /* if viewport will be bigger than the screen, limit its height */ num_args = 0; - XtSetArg(args[num_args], XtNwidth, &v_pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, &v_pixel_height); num_args++; + XtSetArg(args[num_args], XtNwidth, &v_pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, &v_pixel_height); + num_args++; XtGetValues(wp->w, args, num_args); if ((Dimension) XtScreen(wp->w)->height * 5 / 6 < v_pixel_height) { - /* scrollbar is 14 pixels wide. Widen the form to accommodate it. */ - v_pixel_width += 14; + /* scrollbar is 14 pixels wide. Widen the form to accommodate it. */ + v_pixel_width += 14; - /* shrink to fit vertically */ - v_pixel_height = XtScreen(wp->w)->height * 5 / 6; + /* shrink to fit vertically */ + v_pixel_height = XtScreen(wp->w)->height * 5 / 6; - num_args = 0; - XtSetArg(args[num_args], XtNwidth, v_pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, v_pixel_height); num_args++; - XtSetValues(wp->w, args, num_args); + num_args = 0; + XtSetArg(args[num_args], XtNwidth, v_pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, v_pixel_height); + num_args++; + XtSetValues(wp->w, args, num_args); } - XtRealizeWidget(wp->popup); /* need to realize before we position */ + XtRealizeWidget(wp->popup); /* need to realize before we position */ /* if menu is not up, position it */ - if (!menu_info->is_up) positionpopup(wp->popup, FALSE); + if (!menu_info->is_up) + positionpopup(wp->popup, FALSE); menu_info->is_up = TRUE; if (window == WIN_INVEN && how == PICK_NONE) { - /* cant use nh_XtPopup() because it may try to grab the focus */ - XtPopup(wp->popup, (int)XtGrabNone); - if (!updated_inventory) - XMapRaised(XtDisplay(wp->popup), XtWindow(wp->popup)); - XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), - &wm_delete_window, 1); - retval = 0; + /* cant use nh_XtPopup() because it may try to grab the focus */ + XtPopup(wp->popup, (int) XtGrabNone); + if (!updated_inventory) + XMapRaised(XtDisplay(wp->popup), XtWindow(wp->popup)); + XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), + &wm_delete_window, 1); + retval = 0; } else { - menu_info->is_active = TRUE; /* waiting for user response */ - menu_info->cancelled = FALSE; - nh_XtPopup(wp->popup, (int)XtGrabExclusive, wp->w); - (void) x_event(EXIT_ON_EXIT); - menu_info->is_active = FALSE; - if (menu_info->cancelled) - return -1; + menu_info->is_active = TRUE; /* waiting for user response */ + menu_info->cancelled = FALSE; + nh_XtPopup(wp->popup, (int) XtGrabExclusive, wp->w); + (void) x_event(EXIT_ON_EXIT); + menu_info->is_active = FALSE; + if (menu_info->cancelled) + return -1; - retval = 0; - for (curr = menu_info->curr_menu.base; curr; curr = curr->next) - if (curr->selected) retval++; + retval = 0; + for (curr = menu_info->curr_menu.base; curr; curr = curr->next) + if (curr->selected) + retval++; - if (retval) { - menu_item *mi; + if (retval) { + menu_item *mi; - *menu_list = mi = (menu_item *) alloc(retval * sizeof(menu_item)); - for (curr = menu_info->curr_menu.base; curr; curr = curr->next) - if (curr->selected) { - mi->item = curr->identifier; - mi->count = curr->pick_count; - mi++; - } - } + *menu_list = mi = (menu_item *) alloc(retval * sizeof(menu_item)); + for (curr = menu_info->curr_menu.base; curr; curr = curr->next) + if (curr->selected) { + mi->item = curr->identifier; + mi->count = curr->pick_count; + mi++; + } + } } return retval; } -/* End global functions ==================================================== */ +/* End global functions ==================================================== + */ /* * Allocate a copy of the given string. If null, return a string of @@ -1105,58 +1174,61 @@ X11_select_menu(window, how, menu_list) */ static char * copy_of(s) - const char *s; +const char *s; { - if (!s) s = ""; + if (!s) + s = ""; return strcpy((char *) alloc((unsigned) (strlen(s) + 1)), s); } - static void move_menu(src_menu, dest_menu) - struct menu *src_menu, *dest_menu; +struct menu *src_menu, *dest_menu; { - free_menu(dest_menu); /* toss old menu */ - *dest_menu = *src_menu; /* make new menu current */ - /* leave no dangling ptrs */ + free_menu(dest_menu); /* toss old menu */ + *dest_menu = *src_menu; /* make new menu current */ + /* leave no dangling ptrs */ reset_menu_to_default(src_menu); } - static void free_menu(mp) - struct menu *mp; +struct menu *mp; { while (mp->base) { - mp->last = mp->base; - mp->base = mp->base->next; + mp->last = mp->base; + mp->base = mp->base->next; - free((genericptr_t)mp->last->str); - free((genericptr_t)mp->last); + free((genericptr_t) mp->last->str); + free((genericptr_t) mp->last); } - if (mp->query) free((genericptr_t) mp->query); - if (mp->gacc) free((genericptr_t) mp->gacc); - if (mp->list_pointer) free((genericptr_t) mp->list_pointer); - if (mp->sensitive) free((genericptr_t) mp->sensitive); + if (mp->query) + free((genericptr_t) mp->query); + if (mp->gacc) + free((genericptr_t) mp->gacc); + if (mp->list_pointer) + free((genericptr_t) mp->list_pointer); + if (mp->sensitive) + free((genericptr_t) mp->sensitive); reset_menu_to_default(mp); } static void reset_menu_to_default(mp) - struct menu *mp; +struct menu *mp; { - mp->base = mp->last = (x11_menu_item *)0; - mp->query = (const char *)0; - mp->gacc = (const char *)0; + mp->base = mp->last = (x11_menu_item *) 0; + mp->query = (const char *) 0; + mp->gacc = (const char *) 0; mp->count = 0; - mp->list_pointer = (String *)0; - mp->sensitive = (Boolean *)0; - mp->curr_selector = 'a'; /* first accelerator */ + mp->list_pointer = (String *) 0; + mp->sensitive = (Boolean *) 0; + mp->curr_selector = 'a'; /* first accelerator */ } static void clear_old_menu(wp) - struct xwindow *wp; +struct xwindow *wp; { struct menu_info_t *menu_info = wp->menu_information; @@ -1164,23 +1236,23 @@ clear_old_menu(wp) free_menu(&menu_info->new_menu); if (menu_info->valid_widgets) { - nh_XtPopdown(wp->popup); - menu_info->is_up = FALSE; - XtDestroyWidget(wp->popup); - menu_info->valid_widgets = FALSE; - wp->w = wp->popup = (Widget) 0; + nh_XtPopdown(wp->popup); + menu_info->is_up = FALSE; + XtDestroyWidget(wp->popup); + menu_info->valid_widgets = FALSE; + wp->w = wp->popup = (Widget) 0; } } void create_menu_window(wp) - struct xwindow *wp; +struct xwindow *wp; { wp->type = NHW_MENU; wp->menu_information = - (struct menu_info_t *) alloc(sizeof(struct menu_info_t)); + (struct menu_info_t *) alloc(sizeof(struct menu_info_t)); (void) memset((genericptr_t) wp->menu_information, '\0', - sizeof(struct menu_info_t)); + sizeof(struct menu_info_t)); reset_menu_to_default(&wp->menu_information->curr_menu); reset_menu_to_default(&wp->menu_information->new_menu); reset_menu_count(wp->menu_information); @@ -1189,12 +1261,12 @@ create_menu_window(wp) void destroy_menu_window(wp) - struct xwindow *wp; +struct xwindow *wp; { - clear_old_menu(wp); /* this will also destroy the widgets */ + clear_old_menu(wp); /* this will also destroy the widgets */ free((genericptr_t) wp->menu_information); wp->menu_information = (struct menu_info_t *) 0; - wp->type = NHW_NONE; /* allow re-use */ + wp->type = NHW_NONE; /* allow re-use */ } /*winmenu.c*/ diff --git a/win/X11/winmesg.c b/win/X11/winmesg.c index 1ba12052a..a43740245 100644 --- a/win/X11/winmesg.c +++ b/win/X11/winmesg.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winmesg.c $NHDT-Date: 1430899136 2015/05/06 07:58:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ +/* NetHack 3.6 winmesg.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 winmesg.c $Date: 2009/05/06 10:55:57 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)winmesg.c 3.5 1996/04/05 */ /* Copyright (c) Dean Luick, 1992 */ @@ -15,7 +15,7 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -26,36 +26,35 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif -#include "xwindow.h" /* Window widget declarations */ +#include "xwindow.h" /* Window widget declarations */ #include "hack.h" #include "winX.h" static struct line_element *FDECL(get_previous, (struct line_element *)); -static void FDECL(set_circle_buf, (struct mesg_info_t *,int)); -static char *FDECL(split, (char *,XFontStruct *,DIMENSION_P)); -static void FDECL(add_line, (struct mesg_info_t *,const char *)); +static void FDECL(set_circle_buf, (struct mesg_info_t *, int)); +static char *FDECL(split, (char *, XFontStruct *, DIMENSION_P)); +static void FDECL(add_line, (struct mesg_info_t *, const char *)); static void FDECL(redraw_message_window, (struct xwindow *)); static void FDECL(mesg_check_size_change, (struct xwindow *)); -static void FDECL(mesg_exposed, (Widget,XtPointer,XtPointer)); -static void FDECL(get_gc, (Widget,struct mesg_info_t *)); -static void FDECL(mesg_resized, (Widget,XtPointer,XtPointer)); +static void FDECL(mesg_exposed, (Widget, XtPointer, XtPointer)); +static void FDECL(get_gc, (Widget, struct mesg_info_t *)); +static void FDECL(mesg_resized, (Widget, XtPointer, XtPointer)); -static char mesg_translations[] = -"#override\n\ +static char mesg_translations[] = "#override\n\ : input() \ "; /* Move the message window's vertical scrollbar's slider to the bottom. */ void set_message_slider(wp) - struct xwindow *wp; +struct xwindow *wp; { Widget scrollbar; float top; @@ -63,17 +62,16 @@ set_message_slider(wp) scrollbar = XtNameToWidget(XtParent(wp->w), "vertical"); if (scrollbar) { - top = 1.0; - XtCallCallbacks(scrollbar, XtNjumpProc, &top); + top = 1.0; + XtCallCallbacks(scrollbar, XtNjumpProc, &top); } } - void create_message_window(wp, create_popup, parent) - struct xwindow *wp; /* window pointer */ - boolean create_popup; - Widget parent; +struct xwindow *wp; /* window pointer */ +boolean create_popup; +Widget parent; { Arg args[8]; Cardinal num_args; @@ -83,34 +81,35 @@ create_message_window(wp, create_popup, parent) wp->type = NHW_MESSAGE; wp->mesg_information = mesg_info = - (struct mesg_info_t *) alloc(sizeof(struct mesg_info_t)); + (struct mesg_info_t *) alloc(sizeof(struct mesg_info_t)); mesg_info->fs = 0; mesg_info->num_lines = 0; mesg_info->head = mesg_info->line_here = mesg_info->last_pause = - mesg_info->last_pause_head = (struct line_element *) 0; + mesg_info->last_pause_head = (struct line_element *) 0; mesg_info->dirty = False; mesg_info->viewport_width = mesg_info->viewport_height = 0; if (iflags.msg_history < (unsigned) appResources.message_lines) - iflags.msg_history = (unsigned) appResources.message_lines; - if (iflags.msg_history > MAX_HISTORY) /* a sanity check */ - iflags.msg_history = MAX_HISTORY; + iflags.msg_history = (unsigned) appResources.message_lines; + if (iflags.msg_history > MAX_HISTORY) /* a sanity check */ + iflags.msg_history = MAX_HISTORY; set_circle_buf(mesg_info, (int) iflags.msg_history); /* Create a popup that becomes the parent. */ if (create_popup) { - num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; + num_args = 0; + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; - wp->popup = parent = XtCreatePopupShell("message_popup", - topLevelShellWidgetClass, - toplevel, args, num_args); - /* - * If we're here, then this is an auxiliary message window. If we're - * cancelled via a delete window message, we should just pop down. - */ + wp->popup = parent = + XtCreatePopupShell("message_popup", topLevelShellWidgetClass, + toplevel, args, num_args); + /* + * If we're here, then this is an auxiliary message window. If we're + * cancelled via a delete window message, we should just pop down. + */ } /* @@ -119,13 +118,14 @@ create_message_window(wp, create_popup, parent) * always be visible, due to the stupid way the Athena viewport operates. */ num_args = 0; - XtSetArg(args[num_args], XtNallowVert, True); num_args++; + XtSetArg(args[num_args], XtNallowVert, True); + num_args++; viewport = XtCreateManagedWidget( - "mesg_viewport", /* name */ - viewportWidgetClass, /* widget class from Window.h */ - parent, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + "mesg_viewport", /* name */ + viewportWidgetClass, /* widget class from Window.h */ + parent, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ /* * Create a message window. We will change the width and height once @@ -133,15 +133,16 @@ create_message_window(wp, create_popup, parent) */ num_args = 0; if (!create_popup) { - XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(mesg_translations)); num_args++; + XtSetArg(args[num_args], XtNtranslations, + XtParseTranslationTable(mesg_translations)); + num_args++; } wp->w = XtCreateManagedWidget( - "message", /* name */ - windowWidgetClass, /* widget class from Window.h */ - viewport, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + "message", /* name */ + windowWidgetClass, /* widget class from Window.h */ + viewport, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ XtAddCallback(wp->w, XtNexposeCallback, mesg_exposed, (XtPointer) 0); @@ -152,39 +153,43 @@ create_message_window(wp, create_popup, parent) /* Get the font information. */ num_args = 0; - XtSetArg(args[num_args], XtNfont, &mesg_info->fs); num_args++; + XtSetArg(args[num_args], XtNfont, &mesg_info->fs); + num_args++; XtGetValues(wp->w, args, num_args); /* Save character information for fast use later. */ - mesg_info->char_width = mesg_info->fs->max_bounds.width; - mesg_info->char_height = mesg_info->fs->max_bounds.ascent + - mesg_info->fs->max_bounds.descent; - mesg_info->char_ascent = mesg_info->fs->max_bounds.ascent; + mesg_info->char_width = mesg_info->fs->max_bounds.width; + mesg_info->char_height = + mesg_info->fs->max_bounds.ascent + mesg_info->fs->max_bounds.descent; + mesg_info->char_ascent = mesg_info->fs->max_bounds.ascent; mesg_info->char_lbearing = -mesg_info->fs->min_bounds.lbearing; get_gc(wp->w, mesg_info); - wp->pixel_height = ((int)iflags.msg_history) * mesg_info->char_height; + wp->pixel_height = ((int) iflags.msg_history) * mesg_info->char_height; /* If a variable spaced font, only use 2/3 of the default size */ if (mesg_info->fs->min_bounds.width != mesg_info->fs->max_bounds.width) { - wp->pixel_width = ((2*DEFAULT_MESSAGE_WIDTH)/3) * - mesg_info->fs->max_bounds.width; + wp->pixel_width = ((2 * DEFAULT_MESSAGE_WIDTH) / 3) + * mesg_info->fs->max_bounds.width; } else - wp->pixel_width = (DEFAULT_MESSAGE_WIDTH * - mesg_info->fs->max_bounds.width); + wp->pixel_width = + (DEFAULT_MESSAGE_WIDTH * mesg_info->fs->max_bounds.width); /* Set the new width and height. */ num_args = 0; - XtSetArg(args[num_args], XtNwidth, wp->pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, wp->pixel_height); num_args++; + XtSetArg(args[num_args], XtNwidth, wp->pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, wp->pixel_height); + num_args++; XtSetValues(wp->w, args, num_args); /* make sure viewport height makes sense before realizing it */ num_args = 0; mesg_info->viewport_height = - appResources.message_lines * mesg_info->char_height; - XtSetArg(args[num_args], XtNheight, mesg_info->viewport_height);num_args++; + appResources.message_lines * mesg_info->char_height; + XtSetArg(args[num_args], XtNheight, mesg_info->viewport_height); + num_args++; XtSetValues(viewport, args, num_args); XtAddCallback(wp->w, XtNresizeCallback, mesg_resized, (XtPointer) 0); @@ -194,66 +199,67 @@ create_message_window(wp, create_popup, parent) * viewport is also realized. */ if (create_popup) { - XtRealizeWidget(wp->popup); - XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), - &wm_delete_window, 1); + XtRealizeWidget(wp->popup); + XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), + &wm_delete_window, 1); } } - void destroy_message_window(wp) - struct xwindow *wp; +struct xwindow *wp; { if (wp->popup) { - nh_XtPopdown(wp->popup); - if (!wp->keep_window) - XtDestroyWidget(wp->popup), wp->popup = (Widget)0; + nh_XtPopdown(wp->popup); + if (!wp->keep_window) + XtDestroyWidget(wp->popup), wp->popup = (Widget) 0; } if (wp->mesg_information) { - set_circle_buf(wp->mesg_information, 0); /* free buffer list */ - free((genericptr_t)wp->mesg_information), wp->mesg_information = 0; + set_circle_buf(wp->mesg_information, 0); /* free buffer list */ + free((genericptr_t) wp->mesg_information), wp->mesg_information = 0; } if (wp->keep_window) - XtRemoveCallback(wp->w, XtNexposeCallback, mesg_exposed, (XtPointer)0); + XtRemoveCallback(wp->w, XtNexposeCallback, mesg_exposed, + (XtPointer) 0); else - wp->type = NHW_NONE; + wp->type = NHW_NONE; } - /* Redraw message window if new lines have been added. */ void display_message_window(wp) - struct xwindow *wp; +struct xwindow *wp; { - if (wp->mesg_information->dirty) redraw_message_window(wp); + if (wp->mesg_information->dirty) + redraw_message_window(wp); } - /* * Append a line of text to the message window. Split the line if the * rendering of the text is too long for the window. */ void append_message(wp, str) - struct xwindow *wp; - const char *str; +struct xwindow *wp; +const char *str; { char *mark, *remainder, buf[BUFSZ]; - if (!str) return; + if (!str) + return; - Strcpy(buf, str); /* we might mark it up */ + Strcpy(buf, str); /* we might mark it up */ remainder = buf; do { - mark = remainder; - remainder = split(mark, wp->mesg_information->fs, wp->pixel_width); - add_line(wp->mesg_information, mark); + mark = remainder; + remainder = split(mark, wp->mesg_information->fs, wp->pixel_width); + add_line(wp->mesg_information, mark); } while (remainder); } -/* private functions ======================================================= */ +/* private functions ======================================================= + */ /* * Return the element in the circular linked list just before the given @@ -261,18 +267,18 @@ append_message(wp, str) */ static struct line_element * get_previous(mark) - struct line_element *mark; +struct line_element *mark; { struct line_element *curr; - if (!mark) return (struct line_element *) 0; + if (!mark) + return (struct line_element *) 0; for (curr = mark; curr->next != mark; curr = curr->next) - ; + ; return curr; } - /* * Set the information buffer size to count lines. We do this by creating * a circular linked list of elements, each of which represents a line of @@ -281,67 +287,70 @@ get_previous(mark) */ static void set_circle_buf(mesg_info, count) - struct mesg_info_t *mesg_info; - int count; +struct mesg_info_t *mesg_info; +int count; { int i; struct line_element *tail, *curr, *head; - if (count < 0) panic("set_circle_buf: bad count [= %d]", count); - if (count == mesg_info->num_lines) return; /* no change in size */ + if (count < 0) + panic("set_circle_buf: bad count [= %d]", count); + if (count == mesg_info->num_lines) + return; /* no change in size */ if (count < mesg_info->num_lines) { - /* - * Toss num_lines - count line entries from our circular list. - * - * We lose lines from the front (top) of the list. We _know_ - * the list is non_empty. - */ - tail = get_previous(mesg_info->head); - for (i = mesg_info->num_lines - count; i > 0; i--) { - curr = mesg_info->head; - mesg_info->head = curr->next; - if (curr->line) free((genericptr_t)curr->line); - free((genericptr_t)curr); - } - if (count == 0) { - /* make sure we don't have a dangling pointer */ - mesg_info->head = (struct line_element *) 0; - } else { - tail->next = mesg_info->head; /* link the tail to the head */ - } + /* + * Toss num_lines - count line entries from our circular list. + * + * We lose lines from the front (top) of the list. We _know_ + * the list is non_empty. + */ + tail = get_previous(mesg_info->head); + for (i = mesg_info->num_lines - count; i > 0; i--) { + curr = mesg_info->head; + mesg_info->head = curr->next; + if (curr->line) + free((genericptr_t) curr->line); + free((genericptr_t) curr); + } + if (count == 0) { + /* make sure we don't have a dangling pointer */ + mesg_info->head = (struct line_element *) 0; + } else { + tail->next = mesg_info->head; /* link the tail to the head */ + } } else { - /* - * Add count - num_lines blank lines to the head of the list. - * - * Create a separate list, keeping track of the tail. - */ - for (head = tail = 0, i = 0; i < count - mesg_info->num_lines; i++) { - curr = (struct line_element *) alloc(sizeof(struct line_element)); - curr->line = 0; - curr->buf_length = 0; - curr->str_length = 0; - if (tail) { - tail->next = curr; - tail = curr; - } else { - head = tail = curr; - } - } - /* - * Complete the circle by making the new tail point to the old head - * and the old tail point to the new head. If our line count was - * zero, then make the new list circular. - */ - if (mesg_info->num_lines) { - curr = get_previous(mesg_info->head);/* get end of old list */ + /* + * Add count - num_lines blank lines to the head of the list. + * + * Create a separate list, keeping track of the tail. + */ + for (head = tail = 0, i = 0; i < count - mesg_info->num_lines; i++) { + curr = (struct line_element *) alloc(sizeof(struct line_element)); + curr->line = 0; + curr->buf_length = 0; + curr->str_length = 0; + if (tail) { + tail->next = curr; + tail = curr; + } else { + head = tail = curr; + } + } + /* + * Complete the circle by making the new tail point to the old head + * and the old tail point to the new head. If our line count was + * zero, then make the new list circular. + */ + if (mesg_info->num_lines) { + curr = get_previous(mesg_info->head); /* get end of old list */ - tail->next = mesg_info->head; /* new tail -> old head */ - curr->next = head; /* old tail -> new head */ - } else { - tail->next = head; - } - mesg_info->head = head; + tail->next = mesg_info->head; /* new tail -> old head */ + curr->next = head; /* old tail -> new head */ + } else { + tail->next = head; + } + mesg_info->head = head; } mesg_info->num_lines = count; @@ -349,33 +358,33 @@ set_circle_buf(mesg_info, count) mesg_info->last_pause = (struct line_element *) 0; } - /* * Make sure the given string is shorter than the given pixel width. If * not, back up from the end by words until we find a place to split. */ static char * split(s, fs, pixel_width) - char *s; - XFontStruct *fs; /* Font for the window. */ - Dimension pixel_width; +char *s; +XFontStruct *fs; /* Font for the window. */ +Dimension pixel_width; { char save, *end, *remainder; save = '\0'; remainder = 0; - end = eos(s); /* point to null at end of string */ + end = eos(s); /* point to null at end of string */ /* assume that if end == s, XXXXXX returns 0) */ while ((Dimension) XTextWidth(fs, s, (int) strlen(s)) > pixel_width) { - *end-- = save; - while (*end != ' ') { - if (end == s) panic("split: eos!"); - --end; - } - save = *end; - *end = '\0'; - remainder = end + 1; + *end-- = save; + while (*end != ' ') { + if (end == s) + panic("split: eos!"); + --end; + } + save = *end; + *end = '\0'; + remainder = end + 1; } return remainder; } @@ -388,27 +397,27 @@ split(s, fs, pixel_width) */ static void add_line(mesg_info, s) - struct mesg_info_t *mesg_info; - const char *s; +struct mesg_info_t *mesg_info; +const char *s; { register struct line_element *curr = mesg_info->head; register int new_line_length = strlen(s); if (new_line_length + 1 > curr->buf_length) { - if (curr->line) free(curr->line); /* free old line */ + if (curr->line) + free(curr->line); /* free old line */ - curr->buf_length = new_line_length + 1; - curr->line = (char *) alloc((unsigned)curr->buf_length); + curr->buf_length = new_line_length + 1; + curr->line = (char *) alloc((unsigned) curr->buf_length); } - Strcpy(curr->line, s); /* copy info */ - curr->str_length = new_line_length; /* save string length */ + Strcpy(curr->line, s); /* copy info */ + curr->str_length = new_line_length; /* save string length */ - mesg_info->head = mesg_info->head->next; /* move head to next line */ - mesg_info->dirty = True; /* we have undrawn lines */ + mesg_info->head = mesg_info->head->next; /* move head to next line */ + mesg_info->dirty = True; /* we have undrawn lines */ } - /* * Save a position in the text buffer so we can draw a line to seperate * text from the last time this function was called. @@ -419,7 +428,7 @@ add_line(mesg_info, s) */ void set_last_pause(wp) - struct xwindow *wp; +struct xwindow *wp; { register struct mesg_info_t *mesg_info = wp->mesg_information; @@ -429,26 +438,25 @@ set_last_pause(wp) * don't try to erase the line again. */ if (!mesg_info->last_pause - && mesg_info->last_pause_head == mesg_info->head) - return; + && mesg_info->last_pause_head == mesg_info->head) + return; if (mesg_info->last_pause == mesg_info->head) { - /* No new messages in last turn. Redraw window to erase line. */ - mesg_info->last_pause = (struct line_element *) 0; - mesg_info->last_pause_head = mesg_info->head; - redraw_message_window(wp); + /* No new messages in last turn. Redraw window to erase line. */ + mesg_info->last_pause = (struct line_element *) 0; + mesg_info->last_pause_head = mesg_info->head; + redraw_message_window(wp); } else { #endif - mesg_info->last_pause = mesg_info->head; + mesg_info->last_pause = mesg_info->head; #ifdef ERASE_LINE } #endif } - static void redraw_message_window(wp) - struct xwindow *wp; +struct xwindow *wp; { struct mesg_info_t *mesg_info = wp->mesg_information; register struct line_element *curr; @@ -464,43 +472,36 @@ redraw_message_window(wp) * Only need to clear if window has new text. */ if (mesg_info->dirty) { - XClearWindow(XtDisplay(wp->w), XtWindow(wp->w)); - mesg_info->line_here = mesg_info->last_pause; + XClearWindow(XtDisplay(wp->w), XtWindow(wp->w)); + mesg_info->line_here = mesg_info->last_pause; } /* For now, just update the whole shootn' match. */ - for (y_base = row = 0, curr = mesg_info->head; - row < mesg_info->num_lines; - row++, y_base += mesg_info->char_height, curr = curr->next) { - - XDrawString(XtDisplay(wp->w), XtWindow(wp->w), - mesg_info->gc, - mesg_info->char_lbearing, - mesg_info->char_ascent + y_base, - curr->line, - curr->str_length); - /* - * This draws a line at the _top_ of the line of text pointed to by - * mesg_info->last_pause. - */ - if (appResources.message_line && curr == mesg_info->line_here) { - XDrawLine(XtDisplay(wp->w), XtWindow(wp->w), - mesg_info->gc, - 0, y_base, wp->pixel_width, y_base); - } + for (y_base = row = 0, curr = mesg_info->head; row < mesg_info->num_lines; + row++, y_base += mesg_info->char_height, curr = curr->next) { + XDrawString(XtDisplay(wp->w), XtWindow(wp->w), mesg_info->gc, + mesg_info->char_lbearing, mesg_info->char_ascent + y_base, + curr->line, curr->str_length); + /* + * This draws a line at the _top_ of the line of text pointed to by + * mesg_info->last_pause. + */ + if (appResources.message_line && curr == mesg_info->line_here) { + XDrawLine(XtDisplay(wp->w), XtWindow(wp->w), mesg_info->gc, 0, + y_base, wp->pixel_width, y_base); + } } mesg_info->dirty = False; } - /* * Check the size of the viewport. If it has shrunk, then we want to * move the vertical slider to the bottom. */ static void mesg_check_size_change(wp) - struct xwindow *wp; +struct xwindow *wp; { struct mesg_info_t *mesg_info = wp->mesg_information; Arg arg[2]; @@ -509,59 +510,59 @@ mesg_check_size_change(wp) viewport = XtParent(wp->w); - XtSetArg(arg[0], XtNwidth, &new_width); + XtSetArg(arg[0], XtNwidth, &new_width); XtSetArg(arg[1], XtNheight, &new_height); XtGetValues(viewport, arg, TWO); /* Only move slider to bottom if new size is smaller. */ if (new_width < mesg_info->viewport_width - || new_height < mesg_info->viewport_height) { - set_message_slider(wp); + || new_height < mesg_info->viewport_height) { + set_message_slider(wp); } mesg_info->viewport_width = new_width; mesg_info->viewport_height = new_height; } - /* Event handler for message window expose events. */ /*ARGSUSED*/ static void mesg_exposed(w, client_data, widget_data) - Widget w; - XtPointer client_data; /* unused */ - XtPointer widget_data; /* expose event from Window widget */ +Widget w; +XtPointer client_data; /* unused */ +XtPointer widget_data; /* expose event from Window widget */ { XExposeEvent *event = (XExposeEvent *) widget_data; nhUse(client_data); if (XtIsRealized(w) && event->count == 0) { - struct xwindow *wp; - Display *dpy; - Window win; - XEvent evt; + struct xwindow *wp; + Display *dpy; + Window win; + XEvent evt; - /* - * Drain all pending expose events for the message window; - * we'll redraw the whole thing at once. - */ - dpy = XtDisplay(w); - win = XtWindow(w); - while (XCheckTypedWindowEvent(dpy, win, Expose, &evt)) continue; + /* + * Drain all pending expose events for the message window; + * we'll redraw the whole thing at once. + */ + dpy = XtDisplay(w); + win = XtWindow(w); + while (XCheckTypedWindowEvent(dpy, win, Expose, &evt)) + continue; - wp = find_widget(w); - if (wp->keep_window && !wp->mesg_information) return; - mesg_check_size_change(wp); - redraw_message_window(wp); + wp = find_widget(w); + if (wp->keep_window && !wp->mesg_information) + return; + mesg_check_size_change(wp); + redraw_message_window(wp); } } - static void get_gc(w, mesg_info) - Widget w; - struct mesg_info_t *mesg_info; +Widget w; +struct mesg_info_t *mesg_info; { XGCValues values; XtGCMask mask = GCFunction | GCForeground | GCBackground | GCFont; @@ -574,8 +575,8 @@ get_gc(w, mesg_info) values.foreground = fgpixel; values.background = bgpixel; - values.function = GXcopy; - values.font = WindowFont(w); + values.function = GXcopy; + values.font = WindowFont(w); mesg_info->gc = XtGetGC(w, mask, &values); } @@ -592,8 +593,8 @@ get_gc(w, mesg_info) /* ARGSUSED */ static void mesg_resized(w, client_data, call_data) - Widget w; - XtPointer call_data, client_data; +Widget w; +XtPointer call_data, client_data; { Arg args[4]; Cardinal num_args; @@ -602,30 +603,32 @@ mesg_resized(w, client_data, call_data) #ifdef VERBOSE int old_lines; - old_lines = wp->mesg_information->num_lines;; + old_lines = wp->mesg_information->num_lines; + ; #endif nhUse(call_data); nhUse(client_data); num_args = 0; - XtSetArg(args[num_args], XtNwidth, &pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, &pixel_height); num_args++; + XtSetArg(args[num_args], XtNwidth, &pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, &pixel_height); + num_args++; XtGetValues(w, args, num_args); wp = find_widget(w); - wp->pixel_width = pixel_width; + wp->pixel_width = pixel_width; wp->pixel_height = pixel_height; set_circle_buf(wp->mesg_information, - (int) pixel_height / wp->mesg_information->char_height); + (int) pixel_height / wp->mesg_information->char_height); #ifdef VERBOSE - printf("Message resize. Pixel: width = %d, height = %d; Lines: old = %d, new = %d\n", - pixel_width, - pixel_height, - old_lines, - wp->mesg_information->num_lines); + printf("Message resize. Pixel: width = %d, height = %d; Lines: old = " + "%d, new = %d\n", + pixel_width, pixel_height, old_lines, + wp->mesg_information->num_lines); #endif } diff --git a/win/X11/winmisc.c b/win/X11/winmisc.c index 84e5830d6..9e4b02f8f 100644 --- a/win/X11/winmisc.c +++ b/win/X11/winmisc.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winmisc.c $NHDT-Date: 1430899137 2015/05/06 07:58:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ +/* NetHack 3.6 winmisc.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 winmisc.c $Date: 2009/05/06 10:55:57 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)winmisc.c 3.5 2000/05/21 */ /* Copyright (c) Dean Luick, 1992 */ @@ -11,7 +11,7 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -21,28 +21,27 @@ #include #include #include -#include /* for index() */ +#include /* for index() */ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #include "hack.h" #include "func_tab.h" #include "winX.h" - static Widget extended_command_popup = 0; static Widget extended_command_form; static Widget *extended_commands = 0; -static int extended_command_selected; /* index of the selected command; */ -static int ps_selected; /* index of selected role */ +static int extended_command_selected; /* index of the selected command; */ +static int ps_selected; /* index of selected role */ #define PS_RANDOM (-50) -#define PS_QUIT (-75) +#define PS_QUIT (-75) static const char ps_randchars[] = "*@"; static const char ps_quitchars[] = "\033qQ"; @@ -52,85 +51,79 @@ static int ec_nchars = 0; static char ec_chars[EC_NCHARS]; static Time ec_time; -static const char extended_command_translations[] = - "#override\n\ +static const char extended_command_translations[] = "#override\n\ : ec_key()"; -static const char player_select_translations[] = - "#override\n\ +static const char player_select_translations[] = "#override\n\ : ps_key()"; -static const char race_select_translations[] = - "#override\n\ +static const char race_select_translations[] = "#override\n\ : race_key()"; -static const char gend_select_translations[] = - "#override\n\ +static const char gend_select_translations[] = "#override\n\ : gend_key()"; -static const char algn_select_translations[] = - "#override\n\ +static const char algn_select_translations[] = "#override\n\ : algn_key()"; -static void FDECL(popup_delete, (Widget, XEvent*, String*, Cardinal*)); +static void FDECL(popup_delete, (Widget, XEvent *, String *, Cardinal *)); static void NDECL(ec_dismiss); -static Widget FDECL(make_menu, (const char *,const char *,const char *, - const char *,XtCallbackProc, - const char *,XtCallbackProc, - int,const char **, Widget **, - XtCallbackProc,Widget *)); +static Widget FDECL(make_menu, + (const char *, const char *, const char *, const char *, + XtCallbackProc, const char *, XtCallbackProc, int, + const char **, Widget **, XtCallbackProc, Widget *)); static void NDECL(init_extended_commands_popup); -static void FDECL(ps_quit, (Widget,XtPointer,XtPointer)); -static void FDECL(ps_random, (Widget,XtPointer,XtPointer)); -static void FDECL(ps_select, (Widget,XtPointer,XtPointer)); +static void FDECL(ps_quit, (Widget, XtPointer, XtPointer)); +static void FDECL(ps_random, (Widget, XtPointer, XtPointer)); +static void FDECL(ps_select, (Widget, XtPointer, XtPointer)); - -/* Player Selection -------------------------------------------------------- */ +/* Player Selection -------------------------------------------------------- + */ /* ARGSUSED */ static void ps_quit(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(client_data); nhUse(call_data); ps_selected = PS_QUIT; - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } /* ARGSUSED */ static void ps_random(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(client_data); nhUse(call_data); ps_selected = PS_RANDOM; - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } /* ARGSUSED */ static void ps_select(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(call_data); ps_selected = (int) client_data; - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } /* ARGSUSED */ void ps_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch, *mark; char rolechars[QBUFSZ]; @@ -140,43 +133,47 @@ ps_key(w, event, params, num_params) nhUse(params); nhUse(num_params); - (void)memset(rolechars, '\0', sizeof rolechars); /* for index() */ + (void) memset(rolechars, '\0', sizeof rolechars); /* for index() */ for (i = 0; roles[i].name.m; ++i) { - ch = lowc(*roles[i].name.m); - /* if (flags.female && roles[i].name.f) ch = lowc(*roles[i].name.f); */ - /* this supports at most two roles with the same first letter */ - if (index(rolechars, ch)) ch = highc(ch); - rolechars[i] = ch; + ch = lowc(*roles[i].name.m); + /* if (flags.female && roles[i].name.f) ch = lowc(*roles[i].name.f); + */ + /* this supports at most two roles with the same first letter */ + if (index(rolechars, ch)) + ch = highc(ch); + rolechars[i] = ch; } ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } mark = index(rolechars, ch); - if (!mark) mark = index(rolechars, lowc(ch)); - if (!mark) mark = index(rolechars, highc(ch)); + if (!mark) + mark = index(rolechars, lowc(ch)); + if (!mark) + mark = index(rolechars, highc(ch)); if (!mark) { - if (index(ps_randchars, ch)) - ps_selected = PS_RANDOM; - else if (index(ps_quitchars, ch)) - ps_selected = PS_QUIT; - else { - X11_nhbell(); /* no such class */ - return; - } + if (index(ps_randchars, ch)) + ps_selected = PS_RANDOM; + else if (index(ps_quitchars, ch)) + ps_selected = PS_QUIT; + else { + X11_nhbell(); /* no such class */ + return; + } } else - ps_selected = (int)(mark - rolechars); + ps_selected = (int) (mark - rolechars); exit_x_event = TRUE; } /* ARGSUSED */ void race_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch, *mark; char racechars[QBUFSZ]; @@ -186,42 +183,45 @@ race_key(w, event, params, num_params) nhUse(params); nhUse(num_params); - (void)memset(racechars, '\0', sizeof racechars); /* for index() */ + (void) memset(racechars, '\0', sizeof racechars); /* for index() */ for (i = 0; races[i].noun; ++i) { - ch = lowc(*races[i].noun); - /* this supports at most two races with the same first letter */ - if (index(racechars, ch)) ch = highc(ch); - racechars[i] = ch; + ch = lowc(*races[i].noun); + /* this supports at most two races with the same first letter */ + if (index(racechars, ch)) + ch = highc(ch); + racechars[i] = ch; } ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } mark = index(racechars, ch); - if (!mark) mark = index(racechars, lowc(ch)); - if (!mark) mark = index(racechars, highc(ch)); + if (!mark) + mark = index(racechars, lowc(ch)); + if (!mark) + mark = index(racechars, highc(ch)); if (!mark) { - if (index(ps_randchars, ch)) - ps_selected = PS_RANDOM; - else if (index(ps_quitchars, ch)) - ps_selected = PS_QUIT; - else { - X11_nhbell(); /* no such race */ - return; - } + if (index(ps_randchars, ch)) + ps_selected = PS_RANDOM; + else if (index(ps_quitchars, ch)) + ps_selected = PS_QUIT; + else { + X11_nhbell(); /* no such race */ + return; + } } else - ps_selected = (int)(mark - racechars); + ps_selected = (int) (mark - racechars); exit_x_event = TRUE; } /* ARGSUSED */ void gend_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch, *mark; static char gendchars[] = "mf"; @@ -231,33 +231,34 @@ gend_key(w, event, params, num_params) nhUse(num_params); ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } mark = index(gendchars, ch); - if (!mark) mark = index(gendchars, lowc(ch)); + if (!mark) + mark = index(gendchars, lowc(ch)); if (!mark) { - if (index(ps_randchars, ch)) - ps_selected = PS_RANDOM; - else if (index(ps_quitchars, ch)) - ps_selected = PS_QUIT; - else { - X11_nhbell(); /* no such gender */ - return; - } + if (index(ps_randchars, ch)) + ps_selected = PS_RANDOM; + else if (index(ps_quitchars, ch)) + ps_selected = PS_QUIT; + else { + X11_nhbell(); /* no such gender */ + return; + } } else - ps_selected = (int)(mark - gendchars); + ps_selected = (int) (mark - gendchars); exit_x_event = TRUE; } /* ARGSUSED */ void algn_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch, *mark; static char algnchars[] = "LNC"; @@ -267,32 +268,33 @@ algn_key(w, event, params, num_params) nhUse(num_params); ch = key_event_to_char((XKeyEvent *) event); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } mark = index(algnchars, ch); - if (!mark) mark = index(algnchars, highc(ch)); + if (!mark) + mark = index(algnchars, highc(ch)); if (!mark) { - if (index(ps_randchars, ch)) - ps_selected = PS_RANDOM; - else if (index(ps_quitchars, ch)) - ps_selected = PS_QUIT; - else { - X11_nhbell(); /* no such alignment */ - return; - } + if (index(ps_randchars, ch)) + ps_selected = PS_RANDOM; + else if (index(ps_quitchars, ch)) + ps_selected = PS_QUIT; + else { + X11_nhbell(); /* no such alignment */ + return; + } } else - ps_selected = (int)(mark - algnchars); + ps_selected = (int) (mark - algnchars); exit_x_event = TRUE; } -/* Global functions ========================================================= */ +/* Global functions ========================================================= + */ void X11_player_selection() { - int num_roles, num_races, num_gends, num_algns, - i, availcount, availindex; + int num_roles, num_races, num_gends, num_algns, i, availcount, availindex; Widget popup, player_form; const char **choices; char qbuf[QBUFSZ], plbuf[QBUFSZ]; @@ -300,280 +302,296 @@ X11_player_selection() /* avoid unnecessary prompts further down */ rigid_role_checks(); - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); while (flags.initrole < 0) { - if (flags.initrole == ROLE_RANDOM || flags.randomall) { - flags.initrole = pick_role(flags.initrace, - flags.initgend, flags.initalign, PICK_RANDOM); - break; - } + if (flags.initrole == ROLE_RANDOM || flags.randomall) { + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + break; + } - /* select a role */ - for (num_roles = 0; roles[num_roles].name.m; ++num_roles) continue; - choices = (const char **)alloc(sizeof(char *) * num_roles); - for (;;) { - availcount = 0; - for (i = 0; i < num_roles; i++) { - choices[i] = 0; - if (ok_role(i, flags.initrace, - flags.initgend, flags.initalign)) { - choices[i] = roles[i].name.m; - if (flags.initgend >= 0 && flags.female && roles[i].name.f) - choices[i] = roles[i].name.f; - ++availcount; - } - } - if (availcount > 0) break; - else if (flags.initalign >= 0) flags.initalign = -1; /* reset */ - else if (flags.initgend >= 0) flags.initgend = -1; - else if (flags.initrace >= 0) flags.initrace = -1; - else panic("no available ROLE+race+gender+alignment combinations"); - } - Sprintf(qbuf, "Choose your %s Role", s_suffix(plbuf)); - popup = make_menu("player_selection", qbuf, - player_select_translations, - "quit", ps_quit, - "random", ps_random, - num_roles, choices, (Widget **)0, ps_select, &player_form); + /* select a role */ + for (num_roles = 0; roles[num_roles].name.m; ++num_roles) + continue; + choices = (const char **) alloc(sizeof(char *) * num_roles); + for (;;) { + availcount = 0; + for (i = 0; i < num_roles; i++) { + choices[i] = 0; + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + choices[i] = roles[i].name.m; + if (flags.initgend >= 0 && flags.female + && roles[i].name.f) + choices[i] = roles[i].name.f; + ++availcount; + } + } + if (availcount > 0) + break; + else if (flags.initalign >= 0) + flags.initalign = -1; /* reset */ + else if (flags.initgend >= 0) + flags.initgend = -1; + else if (flags.initrace >= 0) + flags.initrace = -1; + else + panic("no available ROLE+race+gender+alignment combinations"); + } + Sprintf(qbuf, "Choose your %s Role", s_suffix(plbuf)); + popup = + make_menu("player_selection", qbuf, player_select_translations, + "quit", ps_quit, "random", ps_random, num_roles, + choices, (Widget **) 0, ps_select, &player_form); - ps_selected = -1; - positionpopup(popup, FALSE); - nh_XtPopup(popup, (int)XtGrabExclusive, player_form); + ps_selected = -1; + positionpopup(popup, FALSE); + nh_XtPopup(popup, (int) XtGrabExclusive, player_form); - /* The callbacks will enable the event loop exit. */ - (void) x_event(EXIT_ON_EXIT); + /* The callbacks will enable the event loop exit. */ + (void) x_event(EXIT_ON_EXIT); - nh_XtPopdown(popup); - XtDestroyWidget(popup); - free((genericptr_t)choices), choices = 0; + nh_XtPopdown(popup); + XtDestroyWidget(popup); + free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { - clearlocks(); - X11_exit_nhwindows((char *)0); - terminate(0); - } else if (ps_selected == PS_RANDOM) { - flags.initrole = ROLE_RANDOM; - } else if (ps_selected < 0 || ps_selected >= num_roles) { - panic("player_selection: bad role select value %d", ps_selected); - } else { - flags.initrole = ps_selected; - } + if (ps_selected == PS_QUIT || program_state.done_hup) { + clearlocks(); + X11_exit_nhwindows((char *) 0); + terminate(0); + } else if (ps_selected == PS_RANDOM) { + flags.initrole = ROLE_RANDOM; + } else if (ps_selected < 0 || ps_selected >= num_roles) { + panic("player_selection: bad role select value %d", ps_selected); + } else { + flags.initrole = ps_selected; + } } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); while (!validrace(flags.initrole, flags.initrace)) { - if (flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, - flags.initgend, flags.initalign, PICK_RANDOM); - break; - } - /* select a race */ - for (num_races = 0; races[num_races].noun; ++num_races) continue; - choices = (const char **)alloc(sizeof(char *) * num_races); - for (;;) { - availcount = availindex = 0; - for (i = 0; i < num_races; i++) { - choices[i] = 0; - if (ok_race(flags.initrole, i, - flags.initgend, flags.initalign)) { - choices[i] = races[i].noun; - ++availcount; - availindex = i; /* used iff only one */ - } - } - if (availcount > 0) break; - else if (flags.initalign >= 0) flags.initalign = -1; /* reset */ - else if (flags.initgend >= 0) flags.initgend = -1; - else panic("no available role+RACE+gender+alignment combinations"); - } + if (flags.initrace == ROLE_RANDOM || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + break; + } + /* select a race */ + for (num_races = 0; races[num_races].noun; ++num_races) + continue; + choices = (const char **) alloc(sizeof(char *) * num_races); + for (;;) { + availcount = availindex = 0; + for (i = 0; i < num_races; i++) { + choices[i] = 0; + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + choices[i] = races[i].noun; + ++availcount; + availindex = i; /* used iff only one */ + } + } + if (availcount > 0) + break; + else if (flags.initalign >= 0) + flags.initalign = -1; /* reset */ + else if (flags.initgend >= 0) + flags.initgend = -1; + else + panic("no available role+RACE+gender+alignment combinations"); + } - if (availcount == 1) { - flags.initrace = availindex; - free((genericptr_t)choices), choices = 0; - } else { - Sprintf(qbuf, "Pick your %s race", s_suffix(plbuf)); - popup = make_menu("race_selection", qbuf, - race_select_translations, - "quit", ps_quit, - "random", ps_random, - num_races, choices, (Widget **)0, - ps_select, &player_form); + if (availcount == 1) { + flags.initrace = availindex; + free((genericptr_t) choices), choices = 0; + } else { + Sprintf(qbuf, "Pick your %s race", s_suffix(plbuf)); + popup = + make_menu("race_selection", qbuf, race_select_translations, + "quit", ps_quit, "random", ps_random, num_races, + choices, (Widget **) 0, ps_select, &player_form); - ps_selected = -1; - positionpopup(popup, FALSE); - nh_XtPopup(popup, (int)XtGrabExclusive, player_form); + ps_selected = -1; + positionpopup(popup, FALSE); + nh_XtPopup(popup, (int) XtGrabExclusive, player_form); - /* The callbacks will enable the event loop exit. */ - (void) x_event(EXIT_ON_EXIT); + /* The callbacks will enable the event loop exit. */ + (void) x_event(EXIT_ON_EXIT); - nh_XtPopdown(popup); - XtDestroyWidget(popup); - free((genericptr_t)choices), choices = 0; + nh_XtPopdown(popup); + XtDestroyWidget(popup); + free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { - clearlocks(); - X11_exit_nhwindows((char *)0); - terminate(0); - } else if (ps_selected == PS_RANDOM) { - flags.initrace = ROLE_RANDOM; - } else if (ps_selected < 0 || ps_selected >= num_races) { - panic("player_selection: bad race select value %d", ps_selected); - } else { - flags.initrace = ps_selected; - } - } /* more than one race choice available */ + if (ps_selected == PS_QUIT || program_state.done_hup) { + clearlocks(); + X11_exit_nhwindows((char *) 0); + terminate(0); + } else if (ps_selected == PS_RANDOM) { + flags.initrace = ROLE_RANDOM; + } else if (ps_selected < 0 || ps_selected >= num_races) { + panic("player_selection: bad race select value %d", + ps_selected); + } else { + flags.initrace = ps_selected; + } + } /* more than one race choice available */ } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); while (!validgend(flags.initrole, flags.initrace, flags.initgend)) { - if (flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - break; - } - /* select a gender */ - num_gends = 2; /* genders[2] isn't allowed */ - choices = (const char **)alloc(sizeof(char *) * num_gends); - for (;;) { - availcount = availindex = 0; - for (i = 0; i < num_gends; i++) { - choices[i] = 0; - if (ok_gend(flags.initrole, flags.initrace, - i, flags.initalign)) { - choices[i] = genders[i].adj; - ++availcount; - availindex = i; /* used iff only one */ - } - } - if (availcount > 0) break; - else if (flags.initalign >= 0) flags.initalign = -1; /* reset */ - else panic("no available role+race+GENDER+alignment combinations"); - } + if (flags.initgend == ROLE_RANDOM || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + break; + } + /* select a gender */ + num_gends = 2; /* genders[2] isn't allowed */ + choices = (const char **) alloc(sizeof(char *) * num_gends); + for (;;) { + availcount = availindex = 0; + for (i = 0; i < num_gends; i++) { + choices[i] = 0; + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + choices[i] = genders[i].adj; + ++availcount; + availindex = i; /* used iff only one */ + } + } + if (availcount > 0) + break; + else if (flags.initalign >= 0) + flags.initalign = -1; /* reset */ + else + panic("no available role+race+GENDER+alignment combinations"); + } - if (availcount == 1) { - flags.initgend = availindex; - free((genericptr_t)choices), choices = 0; - } else { - Sprintf(qbuf, "Your %s gender?", s_suffix(plbuf)); - popup = make_menu("gender_selection", qbuf, - gend_select_translations, - "quit", ps_quit, - "random", ps_random, - num_gends, choices, (Widget **)0, - ps_select, &player_form); + if (availcount == 1) { + flags.initgend = availindex; + free((genericptr_t) choices), choices = 0; + } else { + Sprintf(qbuf, "Your %s gender?", s_suffix(plbuf)); + popup = + make_menu("gender_selection", qbuf, gend_select_translations, + "quit", ps_quit, "random", ps_random, num_gends, + choices, (Widget **) 0, ps_select, &player_form); - ps_selected = -1; - positionpopup(popup, FALSE); - nh_XtPopup(popup, (int)XtGrabExclusive, player_form); + ps_selected = -1; + positionpopup(popup, FALSE); + nh_XtPopup(popup, (int) XtGrabExclusive, player_form); - /* The callbacks will enable the event loop exit. */ - (void) x_event(EXIT_ON_EXIT); + /* The callbacks will enable the event loop exit. */ + (void) x_event(EXIT_ON_EXIT); - nh_XtPopdown(popup); - XtDestroyWidget(popup); - free((genericptr_t)choices), choices = 0; + nh_XtPopdown(popup); + XtDestroyWidget(popup); + free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { - clearlocks(); - X11_exit_nhwindows((char *)0); - terminate(0); - } else if (ps_selected == PS_RANDOM) { - flags.initgend = ROLE_RANDOM; - } else if (ps_selected < 0 || ps_selected >= num_gends) { - panic("player_selection: bad gender select value %d", ps_selected); - } else { - flags.initgend = ps_selected; - } - } /* more than one gender choice available */ + if (ps_selected == PS_QUIT || program_state.done_hup) { + clearlocks(); + X11_exit_nhwindows((char *) 0); + terminate(0); + } else if (ps_selected == PS_RANDOM) { + flags.initgend = ROLE_RANDOM; + } else if (ps_selected < 0 || ps_selected >= num_gends) { + panic("player_selection: bad gender select value %d", + ps_selected); + } else { + flags.initgend = ps_selected; + } + } /* more than one gender choice available */ } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); while (!validalign(flags.initrole, flags.initrace, flags.initalign)) { - if (flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - break; - } - /* select an alignment */ - num_algns = 3; /* aligns[3] isn't allowed */ - choices = (const char **)alloc(sizeof(char *) * num_algns); - for (;;) { - availcount = availindex = 0; - for (i = 0; i < num_algns; i++) { - choices[i] = 0; - if (ok_align(flags.initrole, flags.initrace, - flags.initgend, i)) { - choices[i] = aligns[i].adj; - ++availcount; - availindex = i; /* used iff only one */ - } - } - if (availcount > 0) break; - else panic("no available role+race+gender+ALIGNMENT combinations"); - } + if (flags.initalign == ROLE_RANDOM || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + break; + } + /* select an alignment */ + num_algns = 3; /* aligns[3] isn't allowed */ + choices = (const char **) alloc(sizeof(char *) * num_algns); + for (;;) { + availcount = availindex = 0; + for (i = 0; i < num_algns; i++) { + choices[i] = 0; + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) { + choices[i] = aligns[i].adj; + ++availcount; + availindex = i; /* used iff only one */ + } + } + if (availcount > 0) + break; + else + panic("no available role+race+gender+ALIGNMENT combinations"); + } - if (availcount == 1) { - flags.initalign = availindex; - free((genericptr_t)choices), choices = 0; - } else { - Sprintf(qbuf, "Your %s alignment?", s_suffix(plbuf)); - popup = make_menu("alignment_selection", qbuf, - algn_select_translations, - "quit", ps_quit, - "random", ps_random, - num_algns, choices, (Widget **)0, - ps_select, &player_form); + if (availcount == 1) { + flags.initalign = availindex; + free((genericptr_t) choices), choices = 0; + } else { + Sprintf(qbuf, "Your %s alignment?", s_suffix(plbuf)); + popup = make_menu("alignment_selection", qbuf, + algn_select_translations, "quit", ps_quit, + "random", ps_random, num_algns, choices, + (Widget **) 0, ps_select, &player_form); - ps_selected = -1; - positionpopup(popup, FALSE); - nh_XtPopup(popup, (int)XtGrabExclusive, player_form); + ps_selected = -1; + positionpopup(popup, FALSE); + nh_XtPopup(popup, (int) XtGrabExclusive, player_form); - /* The callbacks will enable the event loop exit. */ - (void) x_event(EXIT_ON_EXIT); + /* The callbacks will enable the event loop exit. */ + (void) x_event(EXIT_ON_EXIT); - nh_XtPopdown(popup); - XtDestroyWidget(popup); - free((genericptr_t)choices), choices = 0; + nh_XtPopdown(popup); + XtDestroyWidget(popup); + free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { - clearlocks(); - X11_exit_nhwindows((char *)0); - terminate(0); - } else if (ps_selected == PS_RANDOM) { - flags.initalign = ROLE_RANDOM; - } else if (ps_selected < 0 || ps_selected >= num_algns) { - panic("player_selection: bad alignment select value %d", ps_selected); - } else { - flags.initalign = ps_selected; - } - } /* more than one alignment choice available */ + if (ps_selected == PS_QUIT || program_state.done_hup) { + clearlocks(); + X11_exit_nhwindows((char *) 0); + terminate(0); + } else if (ps_selected == PS_RANDOM) { + flags.initalign = ROLE_RANDOM; + } else if (ps_selected < 0 || ps_selected >= num_algns) { + panic("player_selection: bad alignment select value %d", + ps_selected); + } else { + flags.initalign = ps_selected; + } + } /* more than one alignment choice available */ } } - int X11_get_ext_cmd() { static Boolean initialized = False; if (!initialized) { - init_extended_commands_popup(); - initialized = True; + init_extended_commands_popup(); + initialized = True; } - extended_command_selected = -1; /* reset selected value */ + extended_command_selected = -1; /* reset selected value */ positionpopup(extended_command_popup, FALSE); /* center on cursor */ - nh_XtPopup(extended_command_popup, (int)XtGrabExclusive, - extended_command_form); + nh_XtPopup(extended_command_popup, (int) XtGrabExclusive, + extended_command_form); /* The callbacks will enable the event loop exit. */ (void) x_event(EXIT_ON_EXIT); @@ -581,14 +599,16 @@ X11_get_ext_cmd() return extended_command_selected; } -/* End global functions ===================================================== */ +/* End global functions ===================================================== + */ -/* Extended Command -------------------------------------------------------- */ +/* Extended Command -------------------------------------------------------- + */ /* ARGSUSED */ static void extend_select(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { int selected = (int) client_data; @@ -596,27 +616,27 @@ extend_select(w, client_data, call_data) nhUse(call_data); if (extended_command_selected != selected) { - /* visibly deselect old one */ - if (extended_command_selected >= 0) - swap_fg_bg(extended_commands[extended_command_selected]); + /* visibly deselect old one */ + if (extended_command_selected >= 0) + swap_fg_bg(extended_commands[extended_command_selected]); - /* select new one */ - swap_fg_bg(extended_commands[selected]); - extended_command_selected = selected; + /* select new one */ + swap_fg_bg(extended_commands[selected]); + extended_command_selected = selected; } nh_XtPopdown(extended_command_popup); /* reset colors while popped down */ swap_fg_bg(extended_commands[extended_command_selected]); ec_active = FALSE; - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } /* ARGSUSED */ static void extend_dismiss(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(client_data); @@ -628,8 +648,8 @@ extend_dismiss(w, client_data, call_data) /* ARGSUSED */ static void extend_help(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +Widget w; +XtPointer client_data, call_data; { nhUse(w); nhUse(client_data); @@ -642,25 +662,25 @@ extend_help(w, client_data, call_data) /* ARGSUSED */ void ec_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { if (w == extended_command_popup) { - ec_dismiss(); + ec_dismiss(); } else { - popup_delete(w, event, params, num_params); + popup_delete(w, event, params, num_params); } } /* ARGSUSED */ static void popup_delete(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { nhUse(event); nhUse(params); @@ -668,7 +688,7 @@ popup_delete(w, event, params, num_params) ps_selected = PS_QUIT; nh_XtPopdown(w); - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } static void @@ -676,20 +696,20 @@ ec_dismiss() { /* unselect while still visible */ if (extended_command_selected >= 0) - swap_fg_bg(extended_commands[extended_command_selected]); - extended_command_selected = -1; /* dismiss */ + swap_fg_bg(extended_commands[extended_command_selected]); + extended_command_selected = -1; /* dismiss */ nh_XtPopdown(extended_command_popup); ec_active = FALSE; - exit_x_event = TRUE; /* leave event loop */ + exit_x_event = TRUE; /* leave event loop */ } /* ARGSUSED */ void ec_key(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch; int i; @@ -701,55 +721,56 @@ ec_key(w, event, params, num_params) ch = key_event_to_char(xkey); - if (ch == '\0') { /* don't accept nul char/modifier event */ - /* don't beep */ - return; + if (ch == '\0') { /* don't accept nul char/modifier event */ + /* don't beep */ + return; } else if (index("\033\n\r", ch)) { - if (ch == '\033') { - /* unselect while still visible */ - if (extended_command_selected >= 0) - swap_fg_bg(extended_commands[extended_command_selected]); - extended_command_selected = -1; /* dismiss */ - } + if (ch == '\033') { + /* unselect while still visible */ + if (extended_command_selected >= 0) + swap_fg_bg(extended_commands[extended_command_selected]); + extended_command_selected = -1; /* dismiss */ + } - nh_XtPopdown(extended_command_popup); - /* unselect while invisible */ - if (extended_command_selected >= 0) - swap_fg_bg(extended_commands[extended_command_selected]); + nh_XtPopdown(extended_command_popup); + /* unselect while invisible */ + if (extended_command_selected >= 0) + swap_fg_bg(extended_commands[extended_command_selected]); - exit_x_event = TRUE; /* leave event loop */ - ec_active = FALSE; - return; + exit_x_event = TRUE; /* leave event loop */ + ec_active = FALSE; + return; } /* too much time has elapsed */ if ((xkey->time - ec_time) > 500) - ec_active = FALSE; + ec_active = FALSE; if (!ec_active) { - ec_nchars = 0; - ec_active = TRUE; + ec_nchars = 0; + ec_active = TRUE; } ec_time = xkey->time; ec_chars[ec_nchars++] = ch; if (ec_nchars >= EC_NCHARS) - ec_nchars = EC_NCHARS-1; /* don't overflow */ + ec_nchars = EC_NCHARS - 1; /* don't overflow */ for (i = 0; extcmdlist[i].ef_txt; i++) { - if (extcmdlist[i].ef_txt[0] == '?') continue; + if (extcmdlist[i].ef_txt[0] == '?') + continue; - if (!strncmp(ec_chars, extcmdlist[i].ef_txt, ec_nchars)) { - if (extended_command_selected != i) { - /* I should use set() and unset() actions, but how do */ - /* I send the an action to the widget? */ - if (extended_command_selected >= 0) - swap_fg_bg(extended_commands[extended_command_selected]); - extended_command_selected = i; - swap_fg_bg(extended_commands[extended_command_selected]); - } - break; - } + if (!strncmp(ec_chars, extcmdlist[i].ef_txt, ec_nchars)) { + if (extended_command_selected != i) { + /* I should use set() and unset() actions, but how do */ + /* I send the an action to the widget? */ + if (extended_command_selected >= 0) + swap_fg_bg(extended_commands[extended_command_selected]); + extended_command_selected = i; + swap_fg_bg(extended_commands[extended_command_selected]); + } + break; + } } } @@ -765,30 +786,29 @@ init_extended_commands_popup() /* count commands */ for (num_commands = 0; extcmdlist[num_commands].ef_txt; num_commands++) - ; /* do nothing */ + ; /* do nothing */ /* If the last entry is "help", don't use it. */ - if (strcmp(extcmdlist[num_commands-1].ef_txt, "?") == 0) - --num_commands; + if (strcmp(extcmdlist[num_commands - 1].ef_txt, "?") == 0) + --num_commands; command_list = - (const char **) alloc((unsigned)num_commands * sizeof(char *)); + (const char **) alloc((unsigned) num_commands * sizeof(char *)); for (i = 0; i < num_commands; i++) - command_list[i] = extcmdlist[i].ef_txt; + command_list[i] = extcmdlist[i].ef_txt; - extended_command_popup = make_menu("extended_commands", - "Extended Commands", - extended_command_translations, - "dismiss", extend_dismiss, - "help", extend_help, - num_commands, command_list, &extended_commands, - extend_select, &extended_command_form); + extended_command_popup = + make_menu("extended_commands", "Extended Commands", + extended_command_translations, "dismiss", extend_dismiss, + "help", extend_help, num_commands, command_list, + &extended_commands, extend_select, &extended_command_form); - free((char *)command_list); + free((char *) command_list); } -/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- + */ /* * Create a popup widget of the following form: @@ -810,22 +830,21 @@ init_extended_commands_popup() * ------------------------ */ static Widget -make_menu(popup_name, popup_label, popup_translations, - left_name, left_callback, - right_name, right_callback, - num_names, widget_names, command_widgets, name_callback, formp) - const char *popup_name; - const char *popup_label; - const char *popup_translations; - const char *left_name; - XtCallbackProc left_callback; - const char *right_name; - XtCallbackProc right_callback; - int num_names; - const char **widget_names; /* return array of command widgets */ - Widget **command_widgets; - XtCallbackProc name_callback; - Widget *formp; /* return */ +make_menu(popup_name, popup_label, popup_translations, left_name, + left_callback, right_name, right_callback, num_names, widget_names, + command_widgets, name_callback, formp) +const char *popup_name; +const char *popup_label; +const char *popup_translations; +const char *left_name; +XtCallbackProc left_callback; +const char *right_name; +XtCallbackProc right_callback; +int num_names; +const char **widget_names; /* return array of command widgets */ +Widget **command_widgets; +XtCallbackProc name_callback; +Widget *formp; /* return */ { Widget popup, form, label, above, left, right; Widget *commands, *curr; @@ -835,73 +854,70 @@ make_menu(popup_name, popup_label, popup_translations, Dimension width, max_width; int distance, skip; - - commands = (Widget *) alloc((unsigned)num_names * sizeof(Widget)); - + commands = (Widget *) alloc((unsigned) num_names * sizeof(Widget)); num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; - popup = XtCreatePopupShell(popup_name, - transientShellWidgetClass, - toplevel, args, num_args); - XtOverrideTranslations(popup, - XtParseTranslationTable("WM_PROTOCOLS: ec_delete()")); + popup = XtCreatePopupShell(popup_name, transientShellWidgetClass, + toplevel, args, num_args); + XtOverrideTranslations( + popup, XtParseTranslationTable("WM_PROTOCOLS: ec_delete()")); num_args = 0; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(popup_translations)); num_args++; - *formp = form = XtCreateManagedWidget("menuform", - formWidgetClass, - popup, - args, num_args); + XtParseTranslationTable(popup_translations)); + num_args++; + *formp = form = XtCreateManagedWidget("menuform", formWidgetClass, popup, + args, num_args); /* Get the default distance between objects in the form widget. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNdefaultDistance), &distance); num_args++; + XtSetArg(args[num_args], nhStr(XtNdefaultDistance), &distance); + num_args++; XtGetValues(form, args, num_args); /* * Create the label. */ num_args = 0; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - label = XtCreateManagedWidget(popup_label, - labelWidgetClass, - form, - args, num_args); + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + label = XtCreateManagedWidget(popup_label, labelWidgetClass, form, args, + num_args); /* * Create the left button. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; -/* - XtSetArg(args[num_args], nhStr(XtNshapeStyle), - XmuShapeRoundedRectangle); num_args++; -*/ - left = XtCreateManagedWidget(left_name, - commandWidgetClass, - form, - args, num_args); + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + /* + XtSetArg(args[num_args], nhStr(XtNshapeStyle), + XmuShapeRoundedRectangle); num_args++; + */ + left = XtCreateManagedWidget(left_name, commandWidgetClass, form, args, + num_args); XtAddCallback(left, XtNcallback, left_callback, (XtPointer) 0); - skip = 3*distance; /* triple the spacing */ - if(!skip) skip = 3; + skip = 3 * distance; /* triple the spacing */ + if (!skip) + skip = 3; /* * Create right button. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromVert), label); num_args++; -/* - XtSetArg(args[num_args], nhStr(XtNshapeStyle), - XmuShapeRoundedRectangle); num_args++; -*/ - right = XtCreateManagedWidget(right_name, - commandWidgetClass, - form, - args, num_args); + XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), label); + num_args++; + /* + XtSetArg(args[num_args], nhStr(XtNshapeStyle), + XmuShapeRoundedRectangle); num_args++; + */ + right = XtCreateManagedWidget(right_name, commandWidgetClass, form, args, + num_args); XtAddCallback(right, XtNcallback, right_callback, (XtPointer) 0); XtInstallAccelerators(form, left); @@ -911,20 +927,21 @@ make_menu(popup_name, popup_label, popup_translations, * Create and place the command widgets. */ for (i = 0, above = left, curr = commands; i < num_names; i++) { - if (!widget_names[i]) continue; - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), above); num_args++; - if (above == left) { - /* if first, we are farther apart */ - XtSetArg(args[num_args], nhStr(XtNvertDistance), skip); num_args++; - } + if (!widget_names[i]) + continue; + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), above); + num_args++; + if (above == left) { + /* if first, we are farther apart */ + XtSetArg(args[num_args], nhStr(XtNvertDistance), skip); + num_args++; + } - *curr = XtCreateManagedWidget(widget_names[i], - commandWidgetClass, - form, - args, num_args); - XtAddCallback(*curr, XtNcallback, name_callback, (XtPointer) i); - above = *curr++; + *curr = XtCreateManagedWidget(widget_names[i], commandWidgetClass, + form, args, num_args); + XtAddCallback(*curr, XtNcallback, name_callback, (XtPointer) i); + above = *curr++; } /* @@ -940,15 +957,18 @@ make_menu(popup_name, popup_label, popup_translations, /* Next, the title. */ XtSetArg(args[0], XtNwidth, &width); XtGetValues(label, args, ONE); - if (width > max_width) max_width = width; + if (width > max_width) + max_width = width; /* Finally, the commands. */ for (i = 0, curr = commands; i < num_names; i++) { - if (!widget_names[i]) continue; - XtSetArg(args[0], XtNwidth, &width); - XtGetValues(*curr, args, ONE); - if (width > max_width) max_width = width; - curr++; + if (!widget_names[i]) + continue; + XtSetArg(args[0], XtNwidth, &width); + XtGetValues(*curr, args, ONE); + if (width > max_width) + max_width = width; + curr++; } /* @@ -958,16 +978,17 @@ make_menu(popup_name, popup_label, popup_translations, XtSetValues(label, args, ONE); for (i = 0, curr = commands; i < num_names; i++) { - if (!widget_names[i]) continue; - XtSetArg(args[0], XtNwidth, max_width); - XtSetValues(*curr, args, ONE); - curr++; + if (!widget_names[i]) + continue; + XtSetArg(args[0], XtNwidth, max_width); + XtSetValues(*curr, args, ONE); + curr++; } if (command_widgets) - *command_widgets = commands; + *command_widgets = commands; else - free((char *) commands); + free((char *) commands); XtRealizeWidget(popup); XSetWMProtocols(XtDisplay(popup), XtWindow(popup), &wm_delete_window, 1); diff --git a/win/X11/winstat.c b/win/X11/winstat.c index f76f26970..b09a74bff 100644 --- a/win/X11/winstat.c +++ b/win/X11/winstat.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winstat.c $NHDT-Date: 1430899137 2015/05/06 07:58:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ +/* NetHack 3.6 winstat.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 winstat.c $Date: 2009/05/06 10:55:59 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)winstat.c 3.5 1996/04/05 */ /* Copyright (c) Dean Luick, 1992 */ @@ -13,7 +13,7 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -27,27 +27,27 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #include "hack.h" #include "winX.h" -extern const char *hu_stat[]; /* from eat.c */ +extern const char *hu_stat[]; /* from eat.c */ extern const char *enc_stat[]; /* from botl.c */ static void FDECL(update_fancy_status, (struct xwindow *)); -static Widget FDECL(create_fancy_status, (Widget,Widget)); +static Widget FDECL(create_fancy_status, (Widget, Widget)); static void FDECL(destroy_fancy_status, (struct xwindow *)); void create_status_window(wp, create_popup, parent) - struct xwindow *wp; /* window pointer */ - boolean create_popup; - Widget parent; +struct xwindow *wp; /* window pointer */ +boolean create_popup; +Widget parent; { XFontStruct *fs; Arg args[8]; @@ -57,47 +57,50 @@ create_status_window(wp, create_popup, parent) wp->type = NHW_STATUS; if (!create_popup) { - /* - * If we are not creating a popup, then we must be the "main" status - * window. - */ - if (!parent) - panic("create_status_window: no parent for fancy status"); - wp->status_information = 0; - wp->w = create_fancy_status(parent, (Widget) 0); - return; + /* + * If we are not creating a popup, then we must be the "main" status + * window. + */ + if (!parent) + panic("create_status_window: no parent for fancy status"); + wp->status_information = 0; + wp->w = create_fancy_status(parent, (Widget) 0); + return; } wp->status_information = - (struct status_info_t *) alloc(sizeof(struct status_info_t)); + (struct status_info_t *) alloc(sizeof(struct status_info_t)); init_text_buffer(&wp->status_information->text); num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, False); num_args++; - XtSetArg(args[num_args], XtNinput, False); num_args++; + XtSetArg(args[num_args], XtNallowShellResize, False); + num_args++; + XtSetArg(args[num_args], XtNinput, False); + num_args++; - wp->popup = parent = XtCreatePopupShell("status_popup", - topLevelShellWidgetClass, - toplevel, args, num_args); + wp->popup = parent = XtCreatePopupShell( + "status_popup", topLevelShellWidgetClass, toplevel, args, num_args); /* * If we're here, then this is an auxiliary status window. If we're * cancelled via a delete window message, we should just pop down. */ num_args = 0; - XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++; + XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); + num_args++; XtSetArg(args[num_args], nhStr(XtNscrollHorizontal), - XawtextScrollWhenNeeded); num_args++; + XawtextScrollWhenNeeded); + num_args++; XtSetArg(args[num_args], nhStr(XtNscrollVertical), - XawtextScrollWhenNeeded); num_args++; + XawtextScrollWhenNeeded); + num_args++; - wp->w = XtCreateManagedWidget( - "status", /* name */ - asciiTextWidgetClass, - parent, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + wp->w = XtCreateManagedWidget("status", /* name */ + asciiTextWidgetClass, + parent, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ /* * Adjust the height and width of the message window so that it @@ -106,49 +109,51 @@ create_status_window(wp, create_popup, parent) /* Get the font and margin information. */ num_args = 0; - XtSetArg(args[num_args], XtNfont, &fs); num_args++; - XtSetArg(args[num_args], nhStr(XtNtopMargin), - &top_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottomMargin), - &bottom_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNleftMargin), - &left_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNrightMargin), - &right_margin); num_args++; + XtSetArg(args[num_args], XtNfont, &fs); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin); + num_args++; XtGetValues(wp->w, args, num_args); wp->pixel_height = 2 * nhFontHeight(wp->w) + top_margin + bottom_margin; - wp->pixel_width = COLNO * fs->max_bounds.width + - left_margin + right_margin; + wp->pixel_width = + COLNO * fs->max_bounds.width + left_margin + right_margin; /* Set the new width and height. */ num_args = 0; - XtSetArg(args[num_args], XtNwidth, wp->pixel_width); num_args++; - XtSetArg(args[num_args], XtNheight, wp->pixel_height); num_args++; + XtSetArg(args[num_args], XtNwidth, wp->pixel_width); + num_args++; + XtSetArg(args[num_args], XtNheight, wp->pixel_height); + num_args++; XtSetValues(wp->w, args, num_args); } void destroy_status_window(wp) - struct xwindow *wp; +struct xwindow *wp; { /* If status_information is defined, then it a "text" status window. */ if (wp->status_information) { - if (wp->popup) { - nh_XtPopdown(wp->popup); - if (!wp->keep_window) - XtDestroyWidget(wp->popup), wp->popup = (Widget)0; - } - free((genericptr_t)wp->status_information); - wp->status_information = 0; + if (wp->popup) { + nh_XtPopdown(wp->popup); + if (!wp->keep_window) + XtDestroyWidget(wp->popup), wp->popup = (Widget) 0; + } + free((genericptr_t) wp->status_information); + wp->status_information = 0; } else { - destroy_fancy_status(wp); + destroy_fancy_status(wp); } if (!wp->keep_window) - wp->type = NHW_NONE; + wp->type = NHW_NONE; } - /* * This assumes several things: * + Status has only 2 lines @@ -157,93 +162,94 @@ destroy_status_window(wp) */ void adjust_status(wp, str) - struct xwindow *wp; - const char *str; +struct xwindow *wp; +const char *str; { Arg args[2]; Cardinal num_args; if (!wp->status_information) { - update_fancy_status(wp); - return; + update_fancy_status(wp); + return; } if (wp->cursy == 0) { - clear_text_buffer(&wp->status_information->text); - append_text_buffer(&wp->status_information->text, str, FALSE); - return; + clear_text_buffer(&wp->status_information->text); + append_text_buffer(&wp->status_information->text, str, FALSE); + return; } append_text_buffer(&wp->status_information->text, str, FALSE); /* Set new buffer as text. */ num_args = 0; XtSetArg(args[num_args], XtNstring, wp->status_information->text.text); - num_args++; + num_args++; XtSetValues(wp->w, args, num_args); } - -/* Fancy Status -------------------------------------------------------------*/ -static int hilight_time = 1; /* number of turns to hilight a changed value */ +/* Fancy Status + * -------------------------------------------------------------*/ +static int hilight_time = 1; /* number of turns to hilight a changed value */ struct X_status_value { /* we have to cast away 'const' when assigning new names */ - const char *name; /* text name */ - int type; /* status type */ - Widget w; /* widget of name/value pair */ - long last_value; /* value displayed */ - int turn_count; /* last time the value changed */ - boolean set; /* if hilighed */ - boolean after_init; /* don't hilight on first change (init) */ + const char *name; /* text name */ + int type; /* status type */ + Widget w; /* widget of name/value pair */ + long last_value; /* value displayed */ + int turn_count; /* last time the value changed */ + boolean set; /* if hilighed */ + boolean after_init; /* don't hilight on first change (init) */ }; /* valid type values */ -#define SV_VALUE 0 /* displays a label:value pair */ -#define SV_LABEL 1 /* displays a changable label */ -#define SV_NAME 2 /* displays an unchangeable name */ +#define SV_VALUE 0 /* displays a label:value pair */ +#define SV_LABEL 1 /* displays a changable label */ +#define SV_NAME 2 /* displays an unchangeable name */ static void FDECL(hilight_label, (Widget)); -static void FDECL(update_val, (struct X_status_value *,long)); +static void FDECL(update_val, (struct X_status_value *, long)); static const char *FDECL(width_string, (int)); -static void FDECL(create_widget, (Widget,struct X_status_value *,int)); -static void FDECL(get_widths, (struct X_status_value *,int *,int *)); -static void FDECL(set_widths, (struct X_status_value *,int,int)); -static Widget FDECL(init_column, (const char *,Widget,Widget,Widget,int *)); -static Widget FDECL(init_info_form, (Widget,Widget,Widget)); +static void FDECL(create_widget, (Widget, struct X_status_value *, int)); +static void FDECL(get_widths, (struct X_status_value *, int *, int *)); +static void FDECL(set_widths, (struct X_status_value *, int, int)); +static Widget FDECL(init_column, + (const char *, Widget, Widget, Widget, int *)); +static Widget FDECL(init_info_form, (Widget, Widget, Widget)); /* * Form entry storage indices. */ -#define F_STR 0 -#define F_DEX 1 -#define F_CON 2 -#define F_INT 3 -#define F_WIS 4 -#define F_CHA 5 +#define F_STR 0 +#define F_DEX 1 +#define F_CON 2 +#define F_INT 3 +#define F_WIS 4 +#define F_CHA 5 -#define F_NAME 6 -#define F_DLEVEL 7 -#define F_GOLD 8 -#define F_HP 9 -#define F_MAXHP 10 -#define F_POWER 11 +#define F_NAME 6 +#define F_DLEVEL 7 +#define F_GOLD 8 +#define F_HP 9 +#define F_MAXHP 10 +#define F_POWER 11 #define F_MAXPOWER 12 -#define F_AC 13 -#define F_LEVEL 14 -#define F_EXP 15 -#define F_ALIGN 16 -#define F_TIME 17 -#define F_SCORE 18 +#define F_AC 13 +#define F_LEVEL 14 +#define F_EXP 15 +#define F_ALIGN 16 +#define F_TIME 17 +#define F_SCORE 18 -#define F_HUNGER 19 +#define F_HUNGER 19 #define F_CONFUSED 20 -#define F_SICK 21 -#define F_BLIND 22 -#define F_STUNNED 23 -#define F_HALLU 24 +#define F_SICK 21 +#define F_BLIND 22 +#define F_STUNNED 23 +#define F_HALLU 24 #define F_ENCUMBER 25 -#define NUM_STATS 26 +#define NUM_STATS 26 /* * Notes: @@ -252,37 +258,36 @@ static Widget FDECL(init_info_form, (Widget,Widget,Widget)); * + Blank value is 0 and should never change. */ static struct X_status_value shown_stats[NUM_STATS] = { - { "Strength", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /* 0*/ - { "Dexterity", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Constitution", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Intelligence", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Wisdom", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Charisma", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /* 5*/ + { "Strength", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /* 0*/ + { "Dexterity", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Constitution", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Intelligence", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Wisdom", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Charisma", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /* 5*/ - { "", SV_LABEL, (Widget) 0, -1, 0, FALSE, FALSE }, /* name */ - { "", SV_LABEL, (Widget) 0, -1, 0, FALSE, FALSE }, /* dlvl */ - { "Gold", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Hit Points", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Max HP", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /*10*/ - { "Power", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Max Power", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Armor Class", SV_VALUE, (Widget) 0,256, 0, FALSE, FALSE }, - { "Level", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Experience", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /*15*/ - { "Alignment", SV_VALUE, (Widget) 0, -2, 0, FALSE, FALSE }, - { "Time", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "Score", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "", SV_LABEL, (Widget) 0, -1, 0, FALSE, FALSE }, /* name */ + { "", SV_LABEL, (Widget) 0, -1, 0, FALSE, FALSE }, /* dlvl */ + { "Gold", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Hit Points", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Max HP", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /*10*/ + { "Power", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Max Power", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Armor Class", SV_VALUE, (Widget) 0, 256, 0, FALSE, FALSE }, + { "Level", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Experience", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, /*15*/ + { "Alignment", SV_VALUE, (Widget) 0, -2, 0, FALSE, FALSE }, + { "Time", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, + { "Score", SV_VALUE, (Widget) 0, -1, 0, FALSE, FALSE }, - { "", SV_NAME, (Widget) 0, -1, 0, FALSE, TRUE }, /* hunger*/ - { "Confused", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /*20*/ - { "", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /* sick */ - { "Blind", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, - { "Stunned", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, - { "Hallucinating", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, - { "", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /*encumbr*/ + { "", SV_NAME, (Widget) 0, -1, 0, FALSE, TRUE }, /* hunger*/ + { "Confused", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /*20*/ + { "", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /* sick */ + { "Blind", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, + { "Stunned", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, + { "Hallucinating", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, + { "", SV_NAME, (Widget) 0, 0, 0, FALSE, TRUE }, /*encumbr*/ }; - /* * Set all widget values to a null string. This is used after all spacings * have been calculated so that when the window is popped up we don't get all @@ -296,28 +301,28 @@ null_out_status() Arg args[1]; for (i = 0, sv = shown_stats; i < NUM_STATS; i++, sv++) { - switch (sv->type) { - case SV_VALUE: - set_value(sv->w, ""); - break; + switch (sv->type) { + case SV_VALUE: + set_value(sv->w, ""); + break; - case SV_LABEL: - case SV_NAME: - XtSetArg(args[0], XtNlabel, ""); - XtSetValues(sv->w, args, ONE); - break; + case SV_LABEL: + case SV_NAME: + XtSetArg(args[0], XtNlabel, ""); + XtSetValues(sv->w, args, ONE); + break; - default: - impossible("null_out_status: unknown type %d\n", sv->type); - break; - } + default: + impossible("null_out_status: unknown type %d\n", sv->type); + break; + } } } /* This is almost an exact duplicate of hilight_value() */ static void hilight_label(w) - Widget w; /* label widget */ +Widget w; /* label widget */ { Arg args[2]; Pixel fg, bg; @@ -331,201 +336,204 @@ hilight_label(w) XtSetValues(w, args, TWO); } - static void update_val(attr_rec, new_value) - struct X_status_value *attr_rec; - long new_value; +struct X_status_value *attr_rec; +long new_value; { char buf[BUFSZ]; Arg args[4]; if (attr_rec->type == SV_LABEL) { + if (attr_rec == &shown_stats[F_NAME]) { + Strcpy(buf, plname); + if ('a' <= buf[0] && buf[0] <= 'z') + buf[0] += 'A' - 'a'; + Strcat(buf, " the "); + if (u.mtimedone) { + char mname[BUFSZ]; + int k = 0; - if (attr_rec == &shown_stats[F_NAME]) { + Strcpy(mname, mons[u.umonnum].mname); + while (mname[k] != 0) { + if ((k == 0 || (k > 0 && mname[k - 1] == ' ')) + && 'a' <= mname[k] && mname[k] <= 'z') + mname[k] += 'A' - 'a'; + k++; + } + Strcat(buf, mname); + } else + Strcat(buf, rank_of(u.ulevel, pl_character[0], flags.female)); - Strcpy(buf, plname); - if ('a' <= buf[0] && buf[0] <= 'z') buf[0] += 'A'-'a'; - Strcat(buf, " the "); - if (u.mtimedone) { - char mname[BUFSZ]; - int k = 0; + } else if (attr_rec == &shown_stats[F_DLEVEL]) { + if (!describe_level(buf)) { + Strcpy(buf, dungeons[u.uz.dnum].dname); + Sprintf(eos(buf), ", level %d", depth(&u.uz)); + } + } else { + impossible("update_val: unknown label type \"%s\"", + attr_rec->name); + return; + } - Strcpy(mname, mons[u.umonnum].mname); - while(mname[k] != 0) { - if ((k == 0 || (k > 0 && mname[k-1] == ' ')) && - 'a' <= mname[k] && mname[k] <= 'z') - mname[k] += 'A' - 'a'; - k++; - } - Strcat(buf, mname); - } else - Strcat(buf, rank_of(u.ulevel, pl_character[0], flags.female)); + if (strcmp(buf, attr_rec->name) == 0) + return; /* same */ - } else if (attr_rec == &shown_stats[F_DLEVEL]) { - if (!describe_level(buf)) { - Strcpy(buf, dungeons[u.uz.dnum].dname); - Sprintf(eos(buf), ", level %d", depth(&u.uz)); - } - } else { - impossible("update_val: unknown label type \"%s\"", - attr_rec->name); - return; - } - - if (strcmp(buf, attr_rec->name) == 0) return; /* same */ - - /* Set the label. 'name' field is const for most entries; - we need to cast away that const for this assignment */ - Strcpy((char *) attr_rec->name, buf); - XtSetArg(args[0], XtNlabel, buf); - XtSetValues(attr_rec->w, args, ONE); + /* Set the label. 'name' field is const for most entries; + we need to cast away that const for this assignment */ + Strcpy((char *) attr_rec->name, buf); + XtSetArg(args[0], XtNlabel, buf); + XtSetValues(attr_rec->w, args, ONE); } else if (attr_rec->type == SV_NAME) { + if (attr_rec->last_value == new_value) + return; /* no change */ - if (attr_rec->last_value == new_value) return; /* no change */ + attr_rec->last_value = new_value; - attr_rec->last_value = new_value; + /* special cases: hunger, encumbrance, sickness */ + if (attr_rec == &shown_stats[F_HUNGER]) { + XtSetArg(args[0], XtNlabel, hu_stat[new_value]); + } else if (attr_rec == &shown_stats[F_ENCUMBER]) { + XtSetArg(args[0], XtNlabel, enc_stat[new_value]); + } else if (attr_rec == &shown_stats[F_SICK]) { + buf[0] = 0; + if (Sick) { + if (u.usick_type & SICK_VOMITABLE) + Strcat(buf, "FoodPois"); + if (u.usick_type & SICK_NONVOMITABLE) { + if (u.usick_type & SICK_VOMITABLE) + Strcat(buf, " "); + Strcat(buf, "Ill"); + } + } + XtSetArg(args[0], XtNlabel, buf); + } else if (new_value) { + XtSetArg(args[0], XtNlabel, attr_rec->name); + } else { + XtSetArg(args[0], XtNlabel, ""); + } + XtSetValues(attr_rec->w, args, ONE); - /* special cases: hunger, encumbrance, sickness */ - if (attr_rec == &shown_stats[F_HUNGER]) { - XtSetArg(args[0], XtNlabel, hu_stat[new_value]); - } else if (attr_rec == &shown_stats[F_ENCUMBER]) { - XtSetArg(args[0], XtNlabel, enc_stat[new_value]); - } else if (attr_rec == &shown_stats[F_SICK]) { - buf[0] = 0; - if (Sick) { - if (u.usick_type & SICK_VOMITABLE) - Strcat(buf, "FoodPois"); - if (u.usick_type & SICK_NONVOMITABLE) { - if (u.usick_type & SICK_VOMITABLE) - Strcat(buf, " "); - Strcat(buf, "Ill"); - } - } - XtSetArg(args[0], XtNlabel, buf); - } else if (new_value) { - XtSetArg(args[0], XtNlabel, attr_rec->name); - } else { - XtSetArg(args[0], XtNlabel, ""); - } - XtSetValues(attr_rec->w, args, ONE); + } else { /* a value pair */ + boolean force_update = FALSE; - } else { /* a value pair */ - boolean force_update = FALSE; + /* special case: time can be enabled & disabled */ + if (attr_rec == &shown_stats[F_TIME]) { + static boolean flagtime = TRUE; - /* special case: time can be enabled & disabled */ - if (attr_rec == &shown_stats[F_TIME]) { - static boolean flagtime = TRUE; + if (flags.time && !flagtime) { + set_name(attr_rec->w, shown_stats[F_TIME].name); + force_update = TRUE; + flagtime = flags.time; + } else if (!flags.time && flagtime) { + set_name(attr_rec->w, ""); + set_value(attr_rec->w, ""); + flagtime = flags.time; + } + if (!flagtime) + return; + } - if(flags.time && !flagtime) { - set_name(attr_rec->w, shown_stats[F_TIME].name); - force_update = TRUE; - flagtime = flags.time; - } else if(!flags.time && flagtime) { - set_name(attr_rec->w, ""); - set_value(attr_rec->w, ""); - flagtime = flags.time; - } - if(!flagtime) return; - } + /* special case: exp can be enabled & disabled */ + else if (attr_rec == &shown_stats[F_EXP]) { + static boolean flagexp = TRUE; - /* special case: exp can be enabled & disabled */ - else if (attr_rec == &shown_stats[F_EXP]) { - static boolean flagexp = TRUE; + if (flags.showexp && !flagexp) { + set_name(attr_rec->w, shown_stats[F_EXP].name); + force_update = TRUE; + flagexp = flags.showexp; + } else if (!flags.showexp && flagexp) { + set_name(attr_rec->w, ""); + set_value(attr_rec->w, ""); + flagexp = flags.showexp; + } + if (!flagexp) + return; + } - if (flags.showexp && !flagexp) { - set_name(attr_rec->w, shown_stats[F_EXP].name); - force_update = TRUE; - flagexp = flags.showexp; - } else if(!flags.showexp && flagexp) { - set_name(attr_rec->w, ""); - set_value(attr_rec->w, ""); - flagexp = flags.showexp; - } - if (!flagexp) return; - } - - /* special case: score can be enabled & disabled */ - else if (attr_rec == &shown_stats[F_SCORE]) { - static boolean flagscore = TRUE; + /* special case: score can be enabled & disabled */ + else if (attr_rec == &shown_stats[F_SCORE]) { + static boolean flagscore = TRUE; #ifdef SCORE_ON_BOTL - if(flags.showscore && !flagscore) { - set_name(attr_rec->w, shown_stats[F_SCORE].name); - force_update = TRUE; - flagscore = flags.showscore; - } else if(!flags.showscore && flagscore) { - set_name(attr_rec->w, ""); - set_value(attr_rec->w, ""); - flagscore = flags.showscore; - } - if(!flagscore) return; + if (flags.showscore && !flagscore) { + set_name(attr_rec->w, shown_stats[F_SCORE].name); + force_update = TRUE; + flagscore = flags.showscore; + } else if (!flags.showscore && flagscore) { + set_name(attr_rec->w, ""); + set_value(attr_rec->w, ""); + flagscore = flags.showscore; + } + if (!flagscore) + return; #else - if (flagscore) { - set_name(attr_rec->w, ""); - set_value(attr_rec->w, ""); - flagscore = FALSE; - } - return; + if (flagscore) { + set_name(attr_rec->w, ""); + set_value(attr_rec->w, ""); + flagscore = FALSE; + } + return; #endif - } + } - /* special case: when polymorphed, show "HD", disable exp */ - else if (attr_rec == &shown_stats[F_LEVEL]) { - static boolean lev_was_poly = FALSE; + /* special case: when polymorphed, show "HD", disable exp */ + else if (attr_rec == &shown_stats[F_LEVEL]) { + static boolean lev_was_poly = FALSE; - if (u.mtimedone && !lev_was_poly) { - force_update = TRUE; - set_name(attr_rec->w, "HD"); - lev_was_poly = TRUE; - } else if (!u.mtimedone && lev_was_poly) { - force_update = TRUE; - set_name(attr_rec->w, shown_stats[F_LEVEL].name); - lev_was_poly = FALSE; - } - } else if (attr_rec == &shown_stats[F_EXP]) { - static boolean exp_was_poly = FALSE; + if (u.mtimedone && !lev_was_poly) { + force_update = TRUE; + set_name(attr_rec->w, "HD"); + lev_was_poly = TRUE; + } else if (!u.mtimedone && lev_was_poly) { + force_update = TRUE; + set_name(attr_rec->w, shown_stats[F_LEVEL].name); + lev_was_poly = FALSE; + } + } else if (attr_rec == &shown_stats[F_EXP]) { + static boolean exp_was_poly = FALSE; - if (u.mtimedone && !exp_was_poly) { - force_update = TRUE; - set_name(attr_rec->w, ""); - set_value(attr_rec->w, ""); - exp_was_poly = TRUE; - } else if (!u.mtimedone && exp_was_poly) { - force_update = TRUE; - set_name(attr_rec->w, shown_stats[F_EXP].name); - exp_was_poly = FALSE; - } - if (u.mtimedone) return; /* no display for exp when poly */ - } + if (u.mtimedone && !exp_was_poly) { + force_update = TRUE; + set_name(attr_rec->w, ""); + set_value(attr_rec->w, ""); + exp_was_poly = TRUE; + } else if (!u.mtimedone && exp_was_poly) { + force_update = TRUE; + set_name(attr_rec->w, shown_stats[F_EXP].name); + exp_was_poly = FALSE; + } + if (u.mtimedone) + return; /* no display for exp when poly */ + } - if (attr_rec->last_value == new_value && !force_update) /* same */ - return; + if (attr_rec->last_value == new_value && !force_update) /* same */ + return; - attr_rec->last_value = new_value; + attr_rec->last_value = new_value; - /* Special cases: strength, alignment and "clear". */ - if (attr_rec == &shown_stats[F_STR]) { - if(new_value > 18) { - if (new_value > 118) - Sprintf(buf,"%ld", new_value-100); - else if(new_value < 118) - Sprintf(buf, "18/%02ld", new_value-18); - else - Strcpy(buf, "18/**"); - } else { - Sprintf(buf, "%ld", new_value); - } - } else if (attr_rec == &shown_stats[F_ALIGN]) { - - Strcpy(buf, (new_value == A_CHAOTIC) ? "Chaotic" : - (new_value == A_NEUTRAL) ? "Neutral" : - "Lawful" ); - } else { - Sprintf(buf, "%ld", new_value); - } - set_value(attr_rec->w, buf); + /* Special cases: strength, alignment and "clear". */ + if (attr_rec == &shown_stats[F_STR]) { + if (new_value > 18) { + if (new_value > 118) + Sprintf(buf, "%ld", new_value - 100); + else if (new_value < 118) + Sprintf(buf, "18/%02ld", new_value - 18); + else + Strcpy(buf, "18/**"); + } else { + Sprintf(buf, "%ld", new_value); + } + } else if (attr_rec == &shown_stats[F_ALIGN]) { + Strcpy(buf, + (new_value == A_CHAOTIC) + ? "Chaotic" + : (new_value == A_NEUTRAL) ? "Neutral" : "Lawful"); + } else { + Sprintf(buf, "%ld", new_value); + } + set_value(attr_rec->w, buf); } /* @@ -534,18 +542,18 @@ update_val(attr_rec, new_value) * it again. */ if (attr_rec->type != SV_NAME && attr_rec != &shown_stats[F_TIME]) { - if (attr_rec->after_init) { - if(!attr_rec->set) { - if (attr_rec->type == SV_LABEL) - hilight_label(attr_rec->w); - else - hilight_value(attr_rec->w); - attr_rec->set = TRUE; - } - attr_rec->turn_count = 0; - } else { - attr_rec->after_init = TRUE; - } + if (attr_rec->after_init) { + if (!attr_rec->set) { + if (attr_rec->type == SV_LABEL) + hilight_label(attr_rec->w); + else + hilight_value(attr_rec->w); + attr_rec->set = TRUE; + } + attr_rec->turn_count = 0; + } else { + attr_rec->after_init = TRUE; + } } } @@ -565,79 +573,128 @@ update_val(attr_rec, new_value) */ static void update_fancy_status(wp) - struct xwindow *wp; +struct xwindow *wp; { struct X_status_value *sv; long val; int i; - if (wp->cursy != 0) return; /* do a complete update when line 0 is done */ + if (wp->cursy != 0) + return; /* do a complete update when line 0 is done */ for (i = 0, sv = shown_stats; i < NUM_STATS; i++, sv++) { - switch (i) { - case F_STR: val = (long) ACURR(A_STR); break; - case F_DEX: val = (long) ACURR(A_DEX); break; - case F_CON: val = (long) ACURR(A_CON); break; - case F_INT: val = (long) ACURR(A_INT); break; - case F_WIS: val = (long) ACURR(A_WIS); break; - case F_CHA: val = (long) ACURR(A_CHA); break; - /* - * Label stats. With the exceptions of hunger, encumbrance, sick - * these are either on or off. Pleae leave the ternary operators - * the way they are. I want to specify 0 or 1, not a boolean. - */ - case F_HUNGER: val = (long) u.uhs; break; - case F_CONFUSED: val = (long) Confusion ? 1L : 0L; break; - case F_SICK: val = (long) Sick ? (long)u.usick_type - : 0L; break; - case F_BLIND: val = (long) Blind ? 1L : 0L; break; - case F_STUNNED: val = (long) Stunned ? 1L : 0L; break; - case F_HALLU: val = (long) Hallucination ? 1L : 0L; break; - case F_ENCUMBER: val = (long) near_capacity(); break; + switch (i) { + case F_STR: + val = (long) ACURR(A_STR); + break; + case F_DEX: + val = (long) ACURR(A_DEX); + break; + case F_CON: + val = (long) ACURR(A_CON); + break; + case F_INT: + val = (long) ACURR(A_INT); + break; + case F_WIS: + val = (long) ACURR(A_WIS); + break; + case F_CHA: + val = (long) ACURR(A_CHA); + break; + /* + * Label stats. With the exceptions of hunger, encumbrance, sick + * these are either on or off. Pleae leave the ternary operators + * the way they are. I want to specify 0 or 1, not a boolean. + */ + case F_HUNGER: + val = (long) u.uhs; + break; + case F_CONFUSED: + val = (long) Confusion ? 1L : 0L; + break; + case F_SICK: + val = (long) Sick ? (long) u.usick_type : 0L; + break; + case F_BLIND: + val = (long) Blind ? 1L : 0L; + break; + case F_STUNNED: + val = (long) Stunned ? 1L : 0L; + break; + case F_HALLU: + val = (long) Hallucination ? 1L : 0L; + break; + case F_ENCUMBER: + val = (long) near_capacity(); + break; - case F_NAME: val = (long) 0L; break; /* special */ - case F_DLEVEL: val = (long) 0L; break; /* special */ - case F_GOLD: val = money_cnt(invent); break; - case F_HP: val = (long) (u.mtimedone ? - (u.mh > 0 ? u.mh : 0): - (u.uhp > 0 ? u.uhp : 0)); break; - case F_MAXHP: val = (long) (u.mtimedone ? u.mhmax : - u.uhpmax); break; - case F_POWER: val = (long) u.uen; break; - case F_MAXPOWER: val = (long) u.uenmax; break; - case F_AC: val = (long) u.uac; break; - case F_LEVEL: val = (long) (u.mtimedone ? - mons[u.umonnum].mlevel : - u.ulevel); break; - case F_EXP: val = flags.showexp ? u.uexp : 0L; break; - case F_ALIGN: val = (long) u.ualign.type; break; - case F_TIME: val = flags.time ? (long) moves : 0L; break; + case F_NAME: + val = (long) 0L; + break; /* special */ + case F_DLEVEL: + val = (long) 0L; + break; /* special */ + case F_GOLD: + val = money_cnt(invent); + break; + case F_HP: + val = (long) (u.mtimedone ? (u.mh > 0 ? u.mh : 0) + : (u.uhp > 0 ? u.uhp : 0)); + break; + case F_MAXHP: + val = (long) (u.mtimedone ? u.mhmax : u.uhpmax); + break; + case F_POWER: + val = (long) u.uen; + break; + case F_MAXPOWER: + val = (long) u.uenmax; + break; + case F_AC: + val = (long) u.uac; + break; + case F_LEVEL: + val = (long) (u.mtimedone ? mons[u.umonnum].mlevel : u.ulevel); + break; + case F_EXP: + val = flags.showexp ? u.uexp : 0L; + break; + case F_ALIGN: + val = (long) u.ualign.type; + break; + case F_TIME: + val = flags.time ? (long) moves : 0L; + break; #ifdef SCORE_ON_BOTL - case F_SCORE: val = flags.showscore ? botl_score():0L; break; + case F_SCORE: + val = flags.showscore ? botl_score() : 0L; + break; #else - case F_SCORE: val = 0L; break; + case F_SCORE: + val = 0L; + break; #endif - default: - { - /* - * There is a possible infinite loop that occurs with: - * - * impossible->pline->flush_screen->bot->bot{1,2}-> - * putstr->adjust_status->update_other->impossible - * - * Break out with this. - */ - static boolean active = FALSE; - if (!active) { - active = TRUE; - impossible("update_other: unknown shown value"); - active = FALSE; - } - val = 0; - break; - } - } - update_val(sv, val); + default: { + /* + * There is a possible infinite loop that occurs with: + * + * impossible->pline->flush_screen->bot->bot{1,2}-> + * putstr->adjust_status->update_other->impossible + * + * Break out with this. + */ + static boolean active = FALSE; + if (!active) { + active = TRUE; + impossible("update_other: unknown shown value"); + active = FALSE; + } + val = 0; + break; + } + } + update_val(sv, val); } } @@ -651,54 +708,74 @@ check_turn_events() struct X_status_value *sv; for (sv = shown_stats, i = 0; i < NUM_STATS; i++, sv++) { - if (!sv->set) continue; + if (!sv->set) + continue; - if (sv->turn_count++ >= hilight_time) { - if (sv->type == SV_LABEL) - hilight_label(sv->w); - else - hilight_value(sv->w); - sv->set = FALSE; - } + if (sv->turn_count++ >= hilight_time) { + if (sv->type == SV_LABEL) + hilight_label(sv->w); + else + hilight_value(sv->w); + sv->set = FALSE; + } } } -/* Initialize alternate status ============================================= */ +/* Initialize alternate status ============================================= + */ /* Return a string for the initial width. */ static const char * width_string(sv_index) - int sv_index; +int sv_index; { switch (sv_index) { - case F_STR: return "018/**"; - case F_DEX: - case F_CON: - case F_INT: - case F_WIS: - case F_CHA: return "088"; /* all but str never get bigger */ + case F_STR: + return "018/**"; + case F_DEX: + case F_CON: + case F_INT: + case F_WIS: + case F_CHA: + return "088"; /* all but str never get bigger */ - case F_HUNGER: return shown_stats[F_HUNGER].name; - case F_CONFUSED:return shown_stats[F_CONFUSED].name; - case F_SICK: return shown_stats[F_SICK].name; - case F_BLIND: return shown_stats[F_BLIND].name; - case F_STUNNED: return shown_stats[F_STUNNED].name; - case F_HALLU: return shown_stats[F_HALLU].name; - case F_ENCUMBER:return shown_stats[F_ENCUMBER].name; + case F_HUNGER: + return shown_stats[F_HUNGER].name; + case F_CONFUSED: + return shown_stats[F_CONFUSED].name; + case F_SICK: + return shown_stats[F_SICK].name; + case F_BLIND: + return shown_stats[F_BLIND].name; + case F_STUNNED: + return shown_stats[F_STUNNED].name; + case F_HALLU: + return shown_stats[F_HALLU].name; + case F_ENCUMBER: + return shown_stats[F_ENCUMBER].name; - case F_NAME: - case F_DLEVEL: return ""; - case F_HP: - case F_MAXHP: return "9999"; - case F_POWER: - case F_MAXPOWER:return "999"; - case F_AC: return "-99"; - case F_LEVEL: return "99"; - case F_GOLD: - case F_EXP: return "4294967295"; /* max ulong */ - case F_ALIGN: return "Neutral"; - case F_TIME: return "4294967295"; /* max ulong */ - case F_SCORE: return "4294967295"; /* max ulong */ + case F_NAME: + case F_DLEVEL: + return ""; + case F_HP: + case F_MAXHP: + return "9999"; + case F_POWER: + case F_MAXPOWER: + return "999"; + case F_AC: + return "-99"; + case F_LEVEL: + return "99"; + case F_GOLD: + case F_EXP: + return "4294967295"; /* max ulong */ + case F_ALIGN: + return "Neutral"; + case F_TIME: + return "4294967295"; /* max ulong */ + case F_SCORE: + return "4294967295"; /* max ulong */ } impossible("width_string: unknown index %d\n", sv_index); return ""; @@ -706,44 +783,44 @@ width_string(sv_index) static void create_widget(parent, sv, sv_index) - Widget parent; - struct X_status_value *sv; - int sv_index; +Widget parent; +struct X_status_value *sv; +int sv_index; { Arg args[4]; Cardinal num_args; switch (sv->type) { - case SV_VALUE: - sv->w = create_value(parent, sv->name); - set_value(sv->w, width_string(sv_index)); - break; - case SV_LABEL: - /* Labels get their own buffer. */ - sv->name = (char *) alloc(BUFSZ); - /* we need to cast away 'const' when assigning a value */ - *(char *)(sv->name) = '\0'; + case SV_VALUE: + sv->w = create_value(parent, sv->name); + set_value(sv->w, width_string(sv_index)); + break; + case SV_LABEL: + /* Labels get their own buffer. */ + sv->name = (char *) alloc(BUFSZ); + /* we need to cast away 'const' when assigning a value */ + *(char *) (sv->name) = '\0'; - num_args = 0; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++; - sv->w = XtCreateManagedWidget( - sv_index == F_NAME ? "name" : "dlevel", - labelWidgetClass, - parent, - args, num_args); - break; - case SV_NAME: - num_args = 0; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++; - sv->w = XtCreateManagedWidget(sv->name, - labelWidgetClass, - parent, - args, num_args); - break; - default: - panic("create_widget: unknown type %d", sv->type); + num_args = 0; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], XtNinternalHeight, 0); + num_args++; + sv->w = + XtCreateManagedWidget(sv_index == F_NAME ? "name" : "dlevel", + labelWidgetClass, parent, args, num_args); + break; + case SV_NAME: + num_args = 0; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], XtNinternalHeight, 0); + num_args++; + sv->w = XtCreateManagedWidget(sv->name, labelWidgetClass, parent, + args, num_args); + break; + default: + panic("create_widget: unknown type %d", sv->type); } } @@ -752,56 +829,56 @@ create_widget(parent, sv, sv_index) */ static void get_widths(sv, width1p, width2p) - struct X_status_value *sv; - int *width1p, *width2p; +struct X_status_value *sv; +int *width1p, *width2p; { Arg args[1]; Dimension width; switch (sv->type) { - case SV_VALUE: - *width1p = get_name_width(sv->w); - *width2p = get_value_width(sv->w); - break; - case SV_LABEL: - case SV_NAME: - XtSetArg(args[0], XtNwidth, &width); - XtGetValues(sv->w, args, ONE); - *width1p = width; - *width2p = 0; - break; - default: - panic("get_widths: unknown type %d", sv->type); + case SV_VALUE: + *width1p = get_name_width(sv->w); + *width2p = get_value_width(sv->w); + break; + case SV_LABEL: + case SV_NAME: + XtSetArg(args[0], XtNwidth, &width); + XtGetValues(sv->w, args, ONE); + *width1p = width; + *width2p = 0; + break; + default: + panic("get_widths: unknown type %d", sv->type); } } static void set_widths(sv, width1, width2) - struct X_status_value *sv; - int width1, width2; +struct X_status_value *sv; +int width1, width2; { Arg args[1]; switch (sv->type) { - case SV_VALUE: - set_name_width(sv->w, width1); - set_value_width(sv->w, width2); - break; - case SV_LABEL: - case SV_NAME: - XtSetArg(args[0], XtNwidth, (width1+width2)); - XtSetValues(sv->w, args, ONE); - break; - default: - panic("set_widths: unknown type %d", sv->type); + case SV_VALUE: + set_name_width(sv->w, width1); + set_value_width(sv->w, width2); + break; + case SV_LABEL: + case SV_NAME: + XtSetArg(args[0], XtNwidth, (width1 + width2)); + XtSetValues(sv->w, args, ONE); + break; + default: + panic("set_widths: unknown type %d", sv->type); } } static Widget init_column(name, parent, top, left, col_indices) - const char *name; - Widget parent, top, left; - int *col_indices; +const char *name; +Widget parent, top, left; +int *col_indices; { Widget form; Arg args[4]; @@ -812,32 +889,37 @@ init_column(name, parent, top, left, col_indices) num_args = 0; if (top != (Widget) 0) { - XtSetArg(args[num_args], nhStr(XtNfromVert), top); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), top); + num_args++; } if (left != (Widget) 0) { - XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); + num_args++; } - XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); num_args++; - form = XtCreateManagedWidget(name, - formWidgetClass, - parent, args, num_args); + XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); + num_args++; + form = + XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args); max_width1 = max_width2 = 0; for (ip = col_indices; *ip >= 0; ip++) { - sv = &shown_stats[*ip]; - create_widget(form, sv, *ip); /* will set init width */ - if (ip != col_indices) { /* not first */ - num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), - shown_stats[*(ip-1)].w); num_args++; - XtSetValues(sv->w, args, num_args); - } - get_widths(sv, &width1, &width2); - if (width1 > max_width1) max_width1 = width1; - if (width2 > max_width2) max_width2 = width2; + sv = &shown_stats[*ip]; + create_widget(form, sv, *ip); /* will set init width */ + if (ip != col_indices) { /* not first */ + num_args = 0; + XtSetArg(args[num_args], nhStr(XtNfromVert), + shown_stats[*(ip - 1)].w); + num_args++; + XtSetValues(sv->w, args, num_args); + } + get_widths(sv, &width1, &width2); + if (width1 > max_width1) + max_width1 = width1; + if (width2 > max_width2) + max_width2 = width2; } - for (ip = col_indices; *ip >= 0 ; ip++) { - set_widths(&shown_stats[*ip], max_width1, max_width2); + for (ip = col_indices; *ip >= 0; ip++) { + set_widths(&shown_stats[*ip], max_width1, max_width2); } /* There is room behind the end marker for the two widths. */ @@ -852,15 +934,16 @@ init_column(name, parent, top, left, col_indices) * indicates the end of the column. The two numbers after that are used * to store widths that are calculated at run-time. */ -static int attrib_indices[] = { F_STR,F_DEX,F_CON,F_INT,F_WIS,F_CHA, -1,0,0 }; -static int status_indices[] = { F_HUNGER, F_CONFUSED, F_SICK, F_BLIND, - F_STUNNED, F_HALLU, F_ENCUMBER, -1,0,0 }; +static int attrib_indices[] = { F_STR, F_DEX, F_CON, F_INT, F_WIS, + F_CHA, -1, 0, 0 }; +static int status_indices[] = { F_HUNGER, F_CONFUSED, F_SICK, F_BLIND, + F_STUNNED, F_HALLU, F_ENCUMBER, -1, + 0, 0 }; static int col2_indices[] = { F_MAXHP, F_ALIGN, F_TIME, F_EXP, - F_MAXPOWER, -1,0,0 }; -static int col1_indices[] = { F_HP, F_AC, F_GOLD, F_LEVEL, - F_POWER, F_SCORE, -1,0,0 }; - + F_MAXPOWER, -1, 0, 0 }; +static int col1_indices[] = { F_HP, F_AC, F_GOLD, F_LEVEL, F_POWER, + F_SCORE, -1, 0, 0 }; /* * Produce a form that looks like the following: @@ -875,7 +958,7 @@ static int col1_indices[] = { F_HP, F_AC, F_GOLD, F_LEVEL, */ static Widget init_info_form(parent, top, left) - Widget parent, top, left; +Widget parent, top, left; { Widget form, col1; struct X_status_value *sv_name, *sv_dlevel; @@ -885,16 +968,17 @@ init_info_form(parent, top, left) num_args = 0; if (top != (Widget) 0) { - XtSetArg(args[num_args], nhStr(XtNfromVert), top); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), top); + num_args++; } if (left != (Widget) 0) { - XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), left); + num_args++; } - XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); num_args++; - form = XtCreateManagedWidget("status_info", - formWidgetClass, - parent, - args, num_args); + XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); + num_args++; + form = XtCreateManagedWidget("status_info", formWidgetClass, parent, args, + num_args); /* top of form */ sv_name = &shown_stats[F_NAME]; @@ -905,27 +989,27 @@ init_info_form(parent, top, left) create_widget(form, sv_dlevel, F_DLEVEL); num_args = 0; - XtSetArg(args[num_args], nhStr(XtNfromVert), sv_name->w); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), sv_name->w); + num_args++; XtSetValues(sv_dlevel->w, args, num_args); /* two columns beneath */ - col1 = init_column("name_col1", form, sv_dlevel->w, - (Widget) 0, col1_indices); - (void) init_column("name_col2", form, sv_dlevel->w, - col1, col2_indices); + col1 = init_column("name_col1", form, sv_dlevel->w, (Widget) 0, + col1_indices); + (void) init_column("name_col2", form, sv_dlevel->w, col1, col2_indices); /* Add calculated widths. */ for (ip = col1_indices; *ip >= 0; ip++) - ; /* skip to end */ + ; /* skip to end */ total_width = *++ip; total_width += *++ip; for (ip = col2_indices; *ip >= 0; ip++) - ; /* skip to end */ + ; /* skip to end */ total_width += *++ip; total_width += *++ip; XtSetArg(args[0], XtNwidth, total_width); - XtSetValues(sv_name->w, args, ONE); + XtSetValues(sv_name->w, args, ONE); XtSetArg(args[0], XtNwidth, total_width); XtSetValues(sv_dlevel->w, args, ONE); @@ -938,28 +1022,31 @@ init_info_form(parent, top, left) */ static Widget create_fancy_status(parent, top) - Widget parent, top; +Widget parent, top; { - Widget form; /* The form that surrounds everything. */ + Widget form; /* The form that surrounds everything. */ Widget w; Arg args[8]; Cardinal num_args; num_args = 0; if (top != (Widget) 0) { - XtSetArg(args[num_args], nhStr(XtNfromVert), top); num_args++; + XtSetArg(args[num_args], nhStr(XtNfromVert), top); + num_args++; } - XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], XtNorientation, XtorientHorizontal); num_args++; - form = XtCreateManagedWidget("fancy_status", - panedWidgetClass, - parent, - args, num_args); + XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); + num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], XtNorientation, XtorientHorizontal); + num_args++; + form = XtCreateManagedWidget("fancy_status", panedWidgetClass, parent, + args, num_args); w = init_info_form(form, (Widget) 0, (Widget) 0); - w = init_column("status_attributes",form, (Widget) 0, w, attrib_indices); - (void) init_column("status_condition", form, (Widget) 0, w, status_indices); + w = init_column("status_attributes", form, (Widget) 0, w, attrib_indices); + (void) init_column("status_condition", form, (Widget) 0, w, + status_indices); return form; } @@ -971,13 +1058,13 @@ struct xwindow *wp; struct X_status_value *sv; if (!wp->keep_window) - XtDestroyWidget(wp->w), wp->w = (Widget)0; + XtDestroyWidget(wp->w), wp->w = (Widget) 0; for (i = 0, sv = shown_stats; i < NUM_STATS; i++, sv++) - if (sv->type == SV_LABEL) { - free((genericptr_t)sv->name); - sv->name = 0; - } + if (sv->type == SV_LABEL) { + free((genericptr_t) sv->name); + sv->name = 0; + } } /*winstat.c*/ diff --git a/win/X11/wintext.c b/win/X11/wintext.c index 68f05ead8..502a1f584 100644 --- a/win/X11/wintext.c +++ b/win/X11/wintext.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wintext.c $NHDT-Date: 1430899138 2015/05/06 07:58:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ +/* NetHack 3.6 wintext.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */ /* NetHack 3.6 wintext.c $Date: 2012/01/24 04:26:27 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)wintext.c 3.5 1996/04/05 */ /* Copyright (c) Dean Luick, 1992 */ @@ -11,7 +11,7 @@ */ #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -24,10 +24,10 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif #include "hack.h" @@ -38,17 +38,15 @@ #include #endif +#define TRANSIENT_TEXT /* text window is a transient window (no positioning) \ + */ -#define TRANSIENT_TEXT /* text window is a transient window (no positioning) */ - -static const char text_translations[] = - "#override\n\ +static const char text_translations[] = "#override\n\ : dismiss_text()\n\ : key_dismiss_text()"; #ifdef GRAPHIC_TOMBSTONE -static const char rip_translations[] = - "#override\n\ +static const char rip_translations[] = "#override\n\ : rip_dismiss_text()\n\ : rip_dismiss_text()"; @@ -58,10 +56,10 @@ static Widget FDECL(create_ripout_widget, (Widget)); /*ARGSUSED*/ void delete_text(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { struct xwindow *wp; struct text_info_t *text_info; @@ -76,9 +74,9 @@ delete_text(w, event, params, num_params) nh_XtPopdown(wp->popup); if (text_info->blocked) { - exit_x_event = TRUE; + exit_x_event = TRUE; } else if (text_info->destroy_on_ack) { - destroy_text_window(wp); + destroy_text_window(wp); } } @@ -90,10 +88,10 @@ delete_text(w, event, params, num_params) /*ARGSUSED*/ void dismiss_text(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { struct xwindow *wp; struct text_info_t *text_info; @@ -108,44 +106,44 @@ dismiss_text(w, event, params, num_params) nh_XtPopdown(wp->popup); if (text_info->blocked) { - exit_x_event = TRUE; + exit_x_event = TRUE; } else if (text_info->destroy_on_ack) { - destroy_text_window(wp); + destroy_text_window(wp); } } /* Dismiss when a non-modifier key pressed. */ void key_dismiss_text(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { char ch = key_event_to_char((XKeyEvent *) event); - if (ch) dismiss_text(w, event, params, num_params); + if (ch) + dismiss_text(w, event, params, num_params); } #ifdef GRAPHIC_TOMBSTONE /* Dismiss from clicking on rip image. */ void rip_dismiss_text(w, event, params, num_params) - Widget w; - XEvent *event; - String *params; - Cardinal *num_params; +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; { dismiss_text(XtParent(w), event, params, num_params); } #endif - /* ARGSUSED */ void add_to_text_window(wp, attr, str) - struct xwindow *wp; - int attr; /* currently unused */ - const char *str; +struct xwindow *wp; +int attr; /* currently unused */ +const char *str; { struct text_info_t *text_info = wp->text_information; int width; @@ -157,13 +155,13 @@ add_to_text_window(wp, attr, str) /* Calculate text width and save longest line */ width = XTextWidth(text_info->fs, str, (int) strlen(str)); if (width > text_info->max_width) - text_info->max_width = width; + text_info->max_width = width; } void display_text_window(wp, blocking) - struct xwindow *wp; - boolean blocking; +struct xwindow *wp; +boolean blocking; { struct text_info_t *text_info; Arg args[8]; @@ -172,7 +170,7 @@ display_text_window(wp, blocking) int nlines; text_info = wp->text_information; - width = text_info->max_width + text_info->extra_width; + width = text_info->max_width + text_info->extra_width; text_info->blocked = blocking; text_info->destroy_on_ack = FALSE; font_height = nhFontHeight(wp->w); @@ -185,74 +183,83 @@ display_text_window(wp, blocking) * _some_ lines. Finally, use the number of lines in the text if * there are fewer than the max. */ - nlines = (XtScreen(wp->w)->height - text_info->extra_height) / font_height; + nlines = + (XtScreen(wp->w)->height - text_info->extra_height) / font_height; nlines -= 4; if (nlines > text_info->text.num_lines) - nlines = text_info->text.num_lines; - if (nlines <= 0) nlines = 1; + nlines = text_info->text.num_lines; + if (nlines <= 0) + nlines = 1; height = nlines * font_height + text_info->extra_height; num_args = 0; if (nlines < text_info->text.num_lines) { - /* add on width of scrollbar. Really should look this up, - * but can't until the window is realized. Chicken-and-egg problem. - */ - width += 20; + /* add on width of scrollbar. Really should look this up, + * but can't until the window is realized. Chicken-and-egg problem. + */ + width += 20; } #ifdef GRAPHIC_TOMBSTONE if (text_info->is_rip) { - Widget rip = create_ripout_widget(XtParent(wp->w)); - XtSetArg(args[num_args], XtNfromVert, rip); num_args++; + Widget rip = create_ripout_widget(XtParent(wp->w)); + XtSetArg(args[num_args], XtNfromVert, rip); + num_args++; } #endif - if (width > (Dimension) XtScreen(wp->w)->width) { /* too wide for screen */ - /* Back off some amount - we really need to back off the scrollbar */ - /* width plus some extra. */ - width = XtScreen(wp->w)->width - 20; + if (width + > (Dimension) XtScreen(wp->w)->width) { /* too wide for screen */ + /* Back off some amount - we really need to back off the scrollbar */ + /* width plus some extra. */ + width = XtScreen(wp->w)->width - 20; } - XtSetArg(args[num_args], XtNstring, text_info->text.text); num_args++; - XtSetArg(args[num_args], XtNwidth, width); num_args++; - XtSetArg(args[num_args], XtNheight, height); num_args++; + XtSetArg(args[num_args], XtNstring, text_info->text.text); + num_args++; + XtSetArg(args[num_args], XtNwidth, width); + num_args++; + XtSetArg(args[num_args], XtNheight, height); + num_args++; XtSetValues(wp->w, args, num_args); #ifdef TRANSIENT_TEXT XtRealizeWidget(wp->popup); XSetWMProtocols(XtDisplay(wp->popup), XtWindow(wp->popup), - &wm_delete_window, 1); + &wm_delete_window, 1); positionpopup(wp->popup, FALSE); #endif - nh_XtPopup(wp->popup, (int)XtGrabNone, wp->w); + nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w); /* Kludge alert. Scrollbars are not sized correctly by the Text widget */ /* if added before the window is displayed, so do it afterward. */ num_args = 0; - if (nlines < text_info->text.num_lines) { /* add vert scrollbar */ - XtSetArg(args[num_args], nhStr(XtNscrollVertical), - XawtextScrollAlways); num_args++; + if (nlines < text_info->text.num_lines) { /* add vert scrollbar */ + XtSetArg(args[num_args], nhStr(XtNscrollVertical), + XawtextScrollAlways); + num_args++; } - if (width >= (Dimension) (XtScreen(wp->w)->width-20)) { /* too wide */ - XtSetArg(args[num_args], nhStr(XtNscrollHorizontal), - XawtextScrollAlways); num_args++; + if (width >= (Dimension)(XtScreen(wp->w)->width - 20)) { /* too wide */ + XtSetArg(args[num_args], nhStr(XtNscrollHorizontal), + XawtextScrollAlways); + num_args++; } - if (num_args) XtSetValues(wp->w, args, num_args); + if (num_args) + XtSetValues(wp->w, args, num_args); /* We want the user to acknowlege. */ if (blocking) { - (void) x_event(EXIT_ON_EXIT); - nh_XtPopdown(wp->popup); + (void) x_event(EXIT_ON_EXIT); + nh_XtPopdown(wp->popup); } } - void create_text_window(wp) - struct xwindow *wp; +struct xwindow *wp; { struct text_info_t *text_info; Arg args[8]; @@ -263,72 +270,80 @@ create_text_window(wp) wp->type = NHW_TEXT; wp->text_information = text_info = - (struct text_info_t *) alloc(sizeof(struct text_info_t)); + (struct text_info_t *) alloc(sizeof(struct text_info_t)); init_text_buffer(&text_info->text); - text_info->max_width = 0; - text_info->extra_width = 0; - text_info->extra_height = 0; - text_info->blocked = FALSE; - text_info->destroy_on_ack = TRUE; /* Ok to destroy before display */ + text_info->max_width = 0; + text_info->extra_width = 0; + text_info->extra_height = 0; + text_info->blocked = FALSE; + text_info->destroy_on_ack = TRUE; /* Ok to destroy before display */ #ifdef GRAPHIC_TOMBSTONE - text_info->is_rip = FALSE; + text_info->is_rip = FALSE; #endif num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(text_translations)); num_args++; + XtParseTranslationTable(text_translations)); + num_args++; #ifdef TRANSIENT_TEXT wp->popup = XtCreatePopupShell("text", transientShellWidgetClass, - toplevel, args, num_args); + toplevel, args, num_args); #else - wp->popup = XtCreatePopupShell("text", topLevelShellWidgetClass, - toplevel, args, num_args); + wp->popup = XtCreatePopupShell("text", topLevelShellWidgetClass, toplevel, + args, num_args); #endif - XtOverrideTranslations(wp->popup, - XtParseTranslationTable("WM_PROTOCOLS: delete_text()")); + XtOverrideTranslations( + wp->popup, + XtParseTranslationTable("WM_PROTOCOLS: delete_text()")); num_args = 0; - XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; - form = XtCreateManagedWidget("form", formWidgetClass, wp->popup, - args, num_args); + XtSetArg(args[num_args], XtNallowShellResize, True); + num_args++; + form = XtCreateManagedWidget("form", formWidgetClass, wp->popup, args, + num_args); num_args = 0; - XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++; - XtSetArg(args[num_args], XtNresize, XawtextResizeBoth); num_args++; + XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); + num_args++; + XtSetArg(args[num_args], XtNresize, XawtextResizeBoth); + num_args++; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(text_translations)); num_args++; + XtParseTranslationTable(text_translations)); + num_args++; - wp->w = XtCreateManagedWidget( - killer.name[0] && WIN_MAP == WIN_ERR ? - "tombstone" : "text_text", /* name */ - asciiTextWidgetClass, - form, /* parent widget */ - args, /* set some values */ - num_args); /* number of values to set */ + wp->w = XtCreateManagedWidget(killer.name[0] && WIN_MAP == WIN_ERR + ? "tombstone" + : "text_text", /* name */ + asciiTextWidgetClass, + form, /* parent widget */ + args, /* set some values */ + num_args); /* number of values to set */ /* Get the font and margin information. */ num_args = 0; - XtSetArg(args[num_args], XtNfont, &text_info->fs); num_args++; - XtSetArg(args[num_args], nhStr(XtNtopMargin), - &top_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNbottomMargin), - &bottom_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNleftMargin), - &left_margin); num_args++; - XtSetArg(args[num_args], nhStr(XtNrightMargin), - &right_margin); num_args++; + XtSetArg(args[num_args], XtNfont, &text_info->fs); + num_args++; + XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin); + num_args++; + XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin); + num_args++; XtGetValues(wp->w, args, num_args); - text_info->extra_width = left_margin + right_margin; + text_info->extra_width = left_margin + right_margin; text_info->extra_height = top_margin + bottom_margin; } void destroy_text_window(wp) - struct xwindow *wp; +struct xwindow *wp; { /* Don't need to pop down, this only called from dismiss_text(). */ @@ -341,78 +356,81 @@ destroy_text_window(wp) * press. */ if (text_info->blocked || text_info->destroy_on_ack) { - XtDestroyWidget(wp->popup); - free_text_buffer(&text_info->text); - free((genericptr_t)text_info), wp->text_information = 0; - wp->type = NHW_NONE; /* allow reuse */ + XtDestroyWidget(wp->popup); + free_text_buffer(&text_info->text); + free((genericptr_t) text_info), wp->text_information = 0; + wp->type = NHW_NONE; /* allow reuse */ } else { - text_info->destroy_on_ack = TRUE; /* destroy on next ACK */ + text_info->destroy_on_ack = TRUE; /* destroy on next ACK */ } } void clear_text_window(wp) - struct xwindow *wp; +struct xwindow *wp; { clear_text_buffer(&wp->text_information->text); } - -/* text buffer routines ---------------------------------------------------- */ +/* text buffer routines ---------------------------------------------------- + */ /* Append a line to the text buffer. */ void append_text_buffer(tb, str, concat) - struct text_buffer *tb; - const char *str; - boolean concat; +struct text_buffer *tb; +const char *str; +boolean concat; { char *copy; int length; - if (!tb->text) panic("append_text_buffer: null text buffer"); + if (!tb->text) + panic("append_text_buffer: null text buffer"); if (str) { - length = strlen(str); + length = strlen(str); } else { - length = 0; + length = 0; } if (length + tb->text_last + 1 >= tb->text_size) { - /* we need to go to a bigger buffer! */ +/* we need to go to a bigger buffer! */ #ifdef VERBOSE - printf("append_text_buffer: text buffer growing from %d to %d bytes\n", - tb->text_size, 2*tb->text_size); + printf( + "append_text_buffer: text buffer growing from %d to %d bytes\n", + tb->text_size, 2 * tb->text_size); #endif - copy = (char *) alloc((unsigned)tb->text_size*2); - (void) memcpy(copy, tb->text, tb->text_last); - free(tb->text); - tb->text = copy; - tb->text_size *= 2; + copy = (char *) alloc((unsigned) tb->text_size * 2); + (void) memcpy(copy, tb->text, tb->text_last); + free(tb->text); + tb->text = copy; + tb->text_size *= 2; } - if (tb->num_lines) { /* not first --- append a newline */ - char appchar = '\n'; + if (tb->num_lines) { /* not first --- append a newline */ + char appchar = '\n'; - if(concat && !index("!.?'\")", tb->text[tb->text_last-1])) { - appchar = ' '; - tb->num_lines--; /* offset increment at end of function */ - } + if (concat && !index("!.?'\")", tb->text[tb->text_last - 1])) { + appchar = ' '; + tb->num_lines--; /* offset increment at end of function */ + } - *(tb->text + tb->text_last) = appchar; - tb->text_last++; + *(tb->text + tb->text_last) = appchar; + tb->text_last++; } if (str) { - (void) memcpy((tb->text+tb->text_last), str, length+1); - if(length) { - /* Remove all newlines. Otherwise we have a confused line count. */ - copy = (tb->text+tb->text_last); - while ((copy = index(copy, '\n')) != (char*)0) - *copy = ' '; - } + (void) memcpy((tb->text + tb->text_last), str, length + 1); + if (length) { + /* Remove all newlines. Otherwise we have a confused line count. + */ + copy = (tb->text + tb->text_last); + while ((copy = index(copy, '\n')) != (char *) 0) + *copy = ' '; + } - tb->text_last += length; + tb->text_last += length; } tb->text[tb->text_last] = '\0'; tb->num_lines++; @@ -421,10 +439,10 @@ append_text_buffer(tb, str, concat) /* Initialize text buffer. */ void init_text_buffer(tb) - struct text_buffer *tb; +struct text_buffer *tb; { - tb->text = (char *) alloc(START_SIZE); - tb->text[0] = '\0'; + tb->text = (char *) alloc(START_SIZE); + tb->text[0] = '\0'; tb->text_size = START_SIZE; tb->text_last = 0; tb->num_lines = 0; @@ -433,17 +451,17 @@ init_text_buffer(tb) /* Empty the text buffer */ void clear_text_buffer(tb) - struct text_buffer *tb; +struct text_buffer *tb; { tb->text_last = 0; - tb->text[0] = '\0'; + tb->text[0] = '\0'; tb->num_lines = 0; } /* Free up allocated memory. */ void free_text_buffer(tb) - struct text_buffer *tb; +struct text_buffer *tb; { free(tb->text); tb->text = (char *) 0; @@ -452,100 +470,95 @@ free_text_buffer(tb) tb->num_lines = 0; } - #ifdef GRAPHIC_TOMBSTONE -static void FDECL(rip_exposed, (Widget,XtPointer,XtPointer)); +static void FDECL(rip_exposed, (Widget, XtPointer, XtPointer)); -static XImage* rip_image=0; +static XImage *rip_image = 0; +#define STONE_LINE_LEN 16 /* # chars that fit on one line */ +#define NAME_LINE 0 /* line # for player name */ +#define GOLD_LINE 1 /* line # for amount of gold */ +#define DEATH_LINE 2 /* line # for death description */ +#define YEAR_LINE 6 /* line # for year */ -#define STONE_LINE_LEN 16 /* # chars that fit on one line */ -#define NAME_LINE 0 /* line # for player name */ -#define GOLD_LINE 1 /* line # for amount of gold */ -#define DEATH_LINE 2 /* line # for death description */ -#define YEAR_LINE 6 /* line # for year */ - -static char rip_line[YEAR_LINE+1][STONE_LINE_LEN+1]; +static char rip_line[YEAR_LINE + 1][STONE_LINE_LEN + 1]; void calculate_rip_text(int how, time_t when) { - /* Follows same algorithm as genl_outrip() */ + /* Follows same algorithm as genl_outrip() */ - char buf[BUFSZ]; - char *dpx; - int line; - long year; + char buf[BUFSZ]; + char *dpx; + int line; + long year; - /* Put name on stone */ - Sprintf(rip_line[NAME_LINE], "%s", plname); + /* Put name on stone */ + Sprintf(rip_line[NAME_LINE], "%s", plname); - /* Put $ on stone */ - Sprintf(rip_line[GOLD_LINE], "%ld Au", - done_money); - /* Put together death description */ - formatkiller(buf, sizeof buf, how); + /* Put $ on stone */ + Sprintf(rip_line[GOLD_LINE], "%ld Au", done_money); + /* Put together death description */ + formatkiller(buf, sizeof buf, how); - /* Put death type on stone */ - for (line=DEATH_LINE, dpx = buf; line STONE_LINE_LEN) { - for(i = STONE_LINE_LEN; - ((i0 > STONE_LINE_LEN) && i); i--) - if(dpx[i] == ' ') i0 = i; - if(!i) i0 = STONE_LINE_LEN; - } - tmpchar = dpx[i0]; - dpx[i0] = 0; - strcpy(rip_line[line], dpx); - if (tmpchar != ' ') { - dpx[i0] = tmpchar; - dpx= &dpx[i0]; - } else dpx= &dpx[i0+1]; - } + if ((i0 = strlen(dpx)) > STONE_LINE_LEN) { + for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--) + if (dpx[i] == ' ') + i0 = i; + if (!i) + i0 = STONE_LINE_LEN; + } + tmpchar = dpx[i0]; + dpx[i0] = 0; + strcpy(rip_line[line], dpx); + if (tmpchar != ' ') { + dpx[i0] = tmpchar; + dpx = &dpx[i0]; + } else + dpx = &dpx[i0 + 1]; + } - /* Put year on stone */ - year = yyyymmdd(when) / 10000L; - Sprintf(rip_line[YEAR_LINE], "%4ld", year); + /* Put year on stone */ + year = yyyymmdd(when) / 10000L; + Sprintf(rip_line[YEAR_LINE], "%4ld", year); } - /* * RIP image expose callback. */ /*ARGSUSED*/ static void rip_exposed(w, client_data, widget_data) - Widget w; - XtPointer client_data; /* unused */ - XtPointer widget_data; /* expose event from Window widget */ +Widget w; +XtPointer client_data; /* unused */ +XtPointer widget_data; /* expose event from Window widget */ { XExposeEvent *event = (XExposeEvent *) widget_data; - Display* dpy=XtDisplay(w); + Display *dpy = XtDisplay(w); Arg args[8]; XGCValues values; XtGCMask mask; GC gc; - static Pixmap rip_pixmap=None; + static Pixmap rip_pixmap = None; int i, x, y; - if (!XtIsRealized(w) || event->count > 0) return; + if (!XtIsRealized(w) || event->count > 0) + return; if (rip_pixmap == None && rip_image) { - rip_pixmap = XCreatePixmap(dpy, XtWindow(w), - rip_image->width, - rip_image->height, - DefaultDepth(dpy, DefaultScreen(dpy))); - XPutImage(dpy, rip_pixmap, - DefaultGC(dpy, DefaultScreen(dpy)), - rip_image, - 0,0, 0,0, /* src, dest top left */ - rip_image->width, - rip_image->height); - XDestroyImage(rip_image); /* data bytes free'd also */ + rip_pixmap = XCreatePixmap(dpy, XtWindow(w), rip_image->width, + rip_image->height, + DefaultDepth(dpy, DefaultScreen(dpy))); + XPutImage(dpy, rip_pixmap, DefaultGC(dpy, DefaultScreen(dpy)), + rip_image, 0, 0, 0, 0, /* src, dest top left */ + rip_image->width, rip_image->height); + XDestroyImage(rip_image); /* data bytes free'd also */ } mask = GCFunction | GCForeground | GCGraphicsExposures | GCFont; @@ -557,21 +570,19 @@ rip_exposed(w, client_data, widget_data) gc = XtGetGC(w, mask, &values); if (rip_pixmap != None) { - XCopyArea(dpy, rip_pixmap, XtWindow(w), gc, - event->x, event->y, event->width, event->height, - event->x, event->y); + XCopyArea(dpy, rip_pixmap, XtWindow(w), gc, event->x, event->y, + event->width, event->height, event->x, event->y); } - x=appResources.tombtext_x; - y=appResources.tombtext_y; - for (i=0; i<=YEAR_LINE; i++) { - int len=strlen(rip_line[i]); - XFontStruct* font=WindowFontStruct(w); - int width=XTextWidth(font, rip_line[i], len); - XDrawString(dpy, XtWindow(w), gc, - x-width/2, y, rip_line[i], len); - x+=appResources.tombtext_dx; - y+=appResources.tombtext_dy; + x = appResources.tombtext_x; + y = appResources.tombtext_y; + for (i = 0; i <= YEAR_LINE; i++) { + int len = strlen(rip_line[i]); + XFontStruct *font = WindowFontStruct(w); + int width = XTextWidth(font, rip_line[i], len); + XDrawString(dpy, XtWindow(w), gc, x - width / 2, y, rip_line[i], len); + x += appResources.tombtext_dx; + y += appResources.tombtext_dy; } XtReleaseGC(w, gc); @@ -590,30 +601,35 @@ create_ripout_widget(Widget parent) static int rip_width, rip_height; if (!rip_image) { - XpmAttributes attributes; - int errorcode; + XpmAttributes attributes; + int errorcode; - attributes.valuemask = XpmCloseness; - attributes.closeness = 65535; /* Try anything */ - errorcode = XpmReadFileToImage(XtDisplay(parent), appResources.tombstone, &rip_image, 0, &attributes); - if (errorcode != XpmSuccess) { - char buf[BUFSZ]; - Sprintf(buf, "Failed to load %s: %s", appResources.tombstone, - XpmGetErrorString(errorcode)); - X11_raw_print(buf); - } - rip_width = rip_image->width; - rip_height = rip_image->height; + attributes.valuemask = XpmCloseness; + attributes.closeness = 65535; /* Try anything */ + errorcode = + XpmReadFileToImage(XtDisplay(parent), appResources.tombstone, + &rip_image, 0, &attributes); + if (errorcode != XpmSuccess) { + char buf[BUFSZ]; + Sprintf(buf, "Failed to load %s: %s", appResources.tombstone, + XpmGetErrorString(errorcode)); + X11_raw_print(buf); + } + rip_width = rip_image->width; + rip_height = rip_image->height; } num_args = 0; - XtSetArg(args[num_args], XtNwidth, rip_width); num_args++; - XtSetArg(args[num_args], XtNheight, rip_height); num_args++; + XtSetArg(args[num_args], XtNwidth, rip_width); + num_args++; + XtSetArg(args[num_args], XtNheight, rip_height); + num_args++; XtSetArg(args[num_args], XtNtranslations, - XtParseTranslationTable(rip_translations)); num_args++; + XtParseTranslationTable(rip_translations)); + num_args++; - imageport = XtCreateManagedWidget("rip", windowWidgetClass, - parent, args, num_args); + imageport = XtCreateManagedWidget("rip", windowWidgetClass, parent, args, + num_args); XtAddCallback(imageport, XtNexposeCallback, rip_exposed, (XtPointer) 0); diff --git a/win/X11/winval.c b/win/X11/winval.c index 0e8408ca9..44622881d 100644 --- a/win/X11/winval.c +++ b/win/X11/winval.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winval.c $NHDT-Date: 1430899139 2015/05/06 07:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ +/* NetHack 3.6 winval.c $NHDT-Date: 1431192774 2015/05/09 17:32:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 winval.c $Date: 2009/05/06 10:56:06 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)winval.c 3.5 1992/3/7 */ /* Copyright (c) Dean Luick, 1992 */ @@ -11,7 +11,7 @@ #include #ifndef SYSV -#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ +#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */ #endif #include @@ -21,59 +21,65 @@ #include #ifdef PRESERVE_NO_SYSV -# ifdef SYSV -# undef SYSV -# endif -# undef PRESERVE_NO_SYSV +#ifdef SYSV +#undef SYSV +#endif +#undef PRESERVE_NO_SYSV #endif -#include "hack.h" /* #define for const for non __STDC__ compilers */ +#include "hack.h" /* #define for const for non __STDC__ compilers */ #include "winX.h" #define WNAME "name" #define WVALUE "value" - Widget create_value(parent, name_value) - Widget parent; - const char *name_value; +Widget parent; +const char *name_value; { Widget form, name; Arg args[8]; Cardinal num_args; num_args = 0; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); num_args++; - form = XtCreateManagedWidget(name_value, - formWidgetClass, - parent, args, num_args); + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0); + num_args++; + form = XtCreateManagedWidget(name_value, formWidgetClass, parent, args, + num_args); num_args = 0; - XtSetArg(args[num_args], XtNjustify, XtJustifyRight); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], XtNlabel, name_value); num_args++; - XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++; - name = XtCreateManagedWidget(WNAME, - labelWidgetClass, - form, args, num_args); + XtSetArg(args[num_args], XtNjustify, XtJustifyRight); + num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], XtNlabel, name_value); + num_args++; + XtSetArg(args[num_args], XtNinternalHeight, 0); + num_args++; + name = + XtCreateManagedWidget(WNAME, labelWidgetClass, form, args, num_args); num_args = 0; - XtSetArg(args[num_args], XtNjustify, XtJustifyRight); num_args++; - XtSetArg(args[num_args], XtNborderWidth, 0); num_args++; - XtSetArg(args[num_args], nhStr(XtNfromHoriz), name); num_args++; - XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++; - (void) XtCreateManagedWidget(WVALUE, - labelWidgetClass, - form, args, num_args); + XtSetArg(args[num_args], XtNjustify, XtJustifyRight); + num_args++; + XtSetArg(args[num_args], XtNborderWidth, 0); + num_args++; + XtSetArg(args[num_args], nhStr(XtNfromHoriz), name); + num_args++; + XtSetArg(args[num_args], XtNinternalHeight, 0); + num_args++; + (void) XtCreateManagedWidget(WVALUE, labelWidgetClass, form, args, + num_args); return form; } void set_name(w, new_label) - Widget w; - const char *new_label; +Widget w; +const char *new_label; { Arg args[1]; Widget name; @@ -85,8 +91,8 @@ set_name(w, new_label) void set_name_width(w, new_width) - Widget w; - int new_width; +Widget w; +int new_width; { Arg args[1]; Widget name; @@ -98,7 +104,7 @@ set_name_width(w, new_width) int get_name_width(w) - Widget w; +Widget w; { Arg args[1]; Dimension width; @@ -110,11 +116,10 @@ get_name_width(w) return (int) width; } - void set_value(w, new_value) - Widget w; - const char *new_value; +Widget w; +const char *new_value; { Arg args[1]; Widget val; @@ -126,8 +131,8 @@ set_value(w, new_value) void set_value_width(w, new_width) - Widget w; - int new_width; +Widget w; +int new_width; { Arg args[1]; Widget val; @@ -139,7 +144,7 @@ set_value_width(w, new_width) int get_value_width(w) - Widget w; +Widget w; { Arg args[1]; Widget val; @@ -155,7 +160,7 @@ get_value_width(w) /* a label widget, unless I can get some init hook in there). */ void hilight_value(w) - Widget w; +Widget w; { swap_fg_bg(XtNameToWidget(w, WVALUE)); } @@ -163,7 +168,7 @@ hilight_value(w) /* Swap the foreground and background colors of the given widget */ void swap_fg_bg(w) - Widget w; +Widget w; { Arg args[2]; Pixel fg, bg; @@ -176,4 +181,3 @@ swap_fg_bg(w) XtSetArg(args[1], XtNbackground, fg); XtSetValues(w, args, TWO); } - diff --git a/win/chain/wc_chainin.c b/win/chain/wc_chainin.c index 6b564f1a8..e6042b38b 100644 --- a/win/chain/wc_chainin.c +++ b/win/chain/wc_chainin.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wc_chainin.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wc_chainin.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* NetHack 3.6 wc_chainin.c $Date: 2012/01/23 10:45:31 $ $Revision: 1.2 $ */ /* Copyright (c) Kenneth Lorber, 2012 */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,10 +9,10 @@ #include "hack.h" struct chainin_data { - struct chain_procs *nprocs; - void *ndata; + struct chain_procs *nprocs; + void *ndata; - int linknum; + int linknum; }; /* Normally, a processor gets this information from the first parm of each @@ -22,35 +22,35 @@ static struct chainin_data *cibase; void * chainin_procs_chain(cmd, n, me, nextprocs, nextdata) - int cmd; - int n; - void *me; - void *nextprocs; - void *nextdata; +int cmd; +int n; +void *me; +void *nextprocs; +void *nextdata; { - switch(cmd){ - case WINCHAIN_ALLOC: { - struct chainin_data *tdp = calloc(1, sizeof(struct chainin_data)); - tdp->linknum = n; - cibase = tdp; - return tdp; - } - case WINCHAIN_INIT: { - struct chainin_data *tdp = me; - tdp->nprocs = nextprocs; - tdp->ndata = nextdata; - return tdp; - } - default: - raw_printf("chainin_procs_chain: bad cmd\n"); - exit(EXIT_FAILURE); - } + switch (cmd) { + case WINCHAIN_ALLOC: { + struct chainin_data *tdp = calloc(1, sizeof(struct chainin_data)); + tdp->linknum = n; + cibase = tdp; + return tdp; + } + case WINCHAIN_INIT: { + struct chainin_data *tdp = me; + tdp->nprocs = nextprocs; + tdp->ndata = nextdata; + return tdp; + } + default: + raw_printf("chainin_procs_chain: bad cmd\n"); + exit(EXIT_FAILURE); + } } /* XXX if we don't need this, take it out of the table */ void chainin_procs_init(dir) - int dir UNUSED; +int dir UNUSED; { } @@ -60,358 +60,357 @@ chainin_procs_init(dir) void chainin_init_nhwindows(argcp, argv) - int *argcp; - char **argv; +int *argcp; +char **argv; { - (*cibase->nprocs->win_init_nhwindows)(cibase->ndata, argcp, argv); + (*cibase->nprocs->win_init_nhwindows)(cibase->ndata, argcp, argv); } - void chainin_player_selection() { - (*cibase->nprocs->win_player_selection)(cibase->ndata); + (*cibase->nprocs->win_player_selection)(cibase->ndata); } void chainin_askname() { - (*cibase->nprocs->win_askname)(cibase->ndata); + (*cibase->nprocs->win_askname)(cibase->ndata); } void chainin_get_nh_event() { - (*cibase->nprocs->win_get_nh_event)(cibase->ndata); + (*cibase->nprocs->win_get_nh_event)(cibase->ndata); } void chainin_exit_nhwindows(str) - const char *str; +const char *str; { - (*cibase->nprocs->win_exit_nhwindows)(cibase->ndata, str); + (*cibase->nprocs->win_exit_nhwindows)(cibase->ndata, str); } void chainin_suspend_nhwindows(str) - const char *str; +const char *str; { - (*cibase->nprocs->win_suspend_nhwindows)(cibase->ndata, str); + (*cibase->nprocs->win_suspend_nhwindows)(cibase->ndata, str); } void chainin_resume_nhwindows() { - (*cibase->nprocs->win_resume_nhwindows)(cibase->ndata); + (*cibase->nprocs->win_resume_nhwindows)(cibase->ndata); } winid chainin_create_nhwindow(type) - int type; +int type; { - winid rv; + winid rv; - rv = (*cibase->nprocs->win_create_nhwindow)(cibase->ndata, type); + rv = (*cibase->nprocs->win_create_nhwindow)(cibase->ndata, type); - return rv; + return rv; } void chainin_clear_nhwindow(window) - winid window; +winid window; { - (*cibase->nprocs->win_clear_nhwindow)(cibase->ndata, window); + (*cibase->nprocs->win_clear_nhwindow)(cibase->ndata, window); } void chainin_display_nhwindow(window, blocking) - winid window; - BOOLEAN_P blocking; +winid window; +BOOLEAN_P blocking; { - (*cibase->nprocs->win_display_nhwindow)(cibase->ndata, window, blocking); + (*cibase->nprocs->win_display_nhwindow)(cibase->ndata, window, blocking); } void chainin_destroy_nhwindow(window) - winid window; +winid window; { - (*cibase->nprocs->win_destroy_nhwindow)(cibase->ndata, window); + (*cibase->nprocs->win_destroy_nhwindow)(cibase->ndata, window); } void chainin_curs(window, x, y) - winid window; - int x; - int y; +winid window; +int x; +int y; { - (*cibase->nprocs->win_curs)(cibase->ndata, window, x, y); + (*cibase->nprocs->win_curs)(cibase->ndata, window, x, y); } void chainin_putstr(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { - (*cibase->nprocs->win_putstr)(cibase->ndata, window, attr, str); + (*cibase->nprocs->win_putstr)(cibase->ndata, window, attr, str); } void chainin_putmixed(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { - (*cibase->nprocs->win_putmixed)(cibase->ndata, window, attr, str); + (*cibase->nprocs->win_putmixed)(cibase->ndata, window, attr, str); } void chainin_display_file(fname, complain) - const char *fname; - boolean complain; +const char *fname; +boolean complain; { - (*cibase->nprocs->win_display_file)(cibase->ndata, fname, complain); + (*cibase->nprocs->win_display_file)(cibase->ndata, fname, complain); } void chainin_start_menu(window) - winid window; +winid window; { - (*cibase->nprocs->win_start_menu)(cibase->ndata, window); + (*cibase->nprocs->win_start_menu)(cibase->ndata, window); } void chainin_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) - winid window; /* window to use, must be of type NHW_MENU */ - int glyph; /* glyph to display with item (unused) */ - const anything *identifier; /* what to return if selected */ - char ch; /* keyboard accelerator (0 = pick our own) */ - char gch; /* group accelerator (0 = no group) */ - int attr; /* attribute for string (like tty_putstr()) */ - const char *str; /* menu string */ - boolean preselected; /* item is marked as selected */ +winid window; /* window to use, must be of type NHW_MENU */ +int glyph; /* glyph to display with item (unused) */ +const anything *identifier; /* what to return if selected */ +char ch; /* keyboard accelerator (0 = pick our own) */ +char gch; /* group accelerator (0 = no group) */ +int attr; /* attribute for string (like tty_putstr()) */ +const char *str; /* menu string */ +boolean preselected; /* item is marked as selected */ { - (*cibase->nprocs->win_add_menu)(cibase->ndata, window, glyph, identifier, - ch, gch, attr, str, preselected); + (*cibase->nprocs->win_add_menu)(cibase->ndata, window, glyph, identifier, + ch, gch, attr, str, preselected); } void chainin_end_menu(window, prompt) - winid window; - const char *prompt; +winid window; +const char *prompt; { - (*cibase->nprocs->win_end_menu)(cibase->ndata, window, prompt); + (*cibase->nprocs->win_end_menu)(cibase->ndata, window, prompt); } int chainin_select_menu(window, how, menu_list) - winid window; - int how; - menu_item **menu_list; +winid window; +int how; +menu_item **menu_list; { - int rv; + int rv; - rv = (*cibase->nprocs->win_select_menu)(cibase->ndata, window, how, - (void *)menu_list); + rv = (*cibase->nprocs->win_select_menu)(cibase->ndata, window, how, + (void *) menu_list); - return rv; + return rv; } char chainin_message_menu(let, how, mesg) - char let; - int how; - const char *mesg; +char let; +int how; +const char *mesg; { - char rv; + char rv; - rv = (*cibase->nprocs->win_message_menu)(cibase->ndata, let, how, mesg); + rv = (*cibase->nprocs->win_message_menu)(cibase->ndata, let, how, mesg); - return rv; + return rv; } void chainin_update_inventory() { - (*cibase->nprocs->win_update_inventory)(cibase->ndata); + (*cibase->nprocs->win_update_inventory)(cibase->ndata); } void chainin_mark_synch() { - (*cibase->nprocs->win_mark_synch)(cibase->ndata); + (*cibase->nprocs->win_mark_synch)(cibase->ndata); } void chainin_wait_synch() { - (*cibase->nprocs->win_wait_synch)(cibase->ndata); + (*cibase->nprocs->win_wait_synch)(cibase->ndata); } #ifdef CLIPPING void chainin_cliparound(x, y) - int x; - int y; +int x; +int y; { - (*cibase->nprocs->win_cliparound)(cibase->ndata, x, y); + (*cibase->nprocs->win_cliparound)(cibase->ndata, x, y); } #endif #ifdef POSITIONBAR void chainin_update_positionbar(posbar) - char *posbar; +char *posbar; { - (*cibase->nprocs->win_update_positionbar)(cibase->ndata, posbar); + (*cibase->nprocs->win_update_positionbar)(cibase->ndata, posbar); } #endif /* XXX can we decode the glyph in a meaningful way? */ void chainin_print_glyph(window, x, y, glyph) - winid window; - xchar x, y; - int glyph; +winid window; +xchar x, y; +int glyph; { - (*cibase->nprocs->win_print_glyph)(cibase->ndata, window, x, y, glyph); + (*cibase->nprocs->win_print_glyph)(cibase->ndata, window, x, y, glyph); } void chainin_raw_print(str) - const char *str; +const char *str; { - (*cibase->nprocs->win_raw_print)(cibase->ndata, str); + (*cibase->nprocs->win_raw_print)(cibase->ndata, str); } void chainin_raw_print_bold(str) - const char *str; +const char *str; { - (*cibase->nprocs->win_raw_print_bold)(cibase->ndata, str); + (*cibase->nprocs->win_raw_print_bold)(cibase->ndata, str); } int chainin_nhgetch() { - int rv; + int rv; - rv = (*cibase->nprocs->win_nhgetch)(cibase->ndata); + rv = (*cibase->nprocs->win_nhgetch)(cibase->ndata); - return rv; + return rv; } int chainin_nh_poskey(x, y, mod) - int *x; - int *y; - int *mod; +int *x; +int *y; +int *mod; { - int rv; + int rv; - rv = (*cibase->nprocs->win_nh_poskey)(cibase->ndata, x, y, mod); + rv = (*cibase->nprocs->win_nh_poskey)(cibase->ndata, x, y, mod); - return rv; + return rv; } void chainin_nhbell() { - (*cibase->nprocs->win_nhbell)(cibase->ndata); + (*cibase->nprocs->win_nhbell)(cibase->ndata); } int chainin_doprev_message() { - int rv; + int rv; - rv = (*cibase->nprocs->win_doprev_message)(cibase->ndata); + rv = (*cibase->nprocs->win_doprev_message)(cibase->ndata); - return rv; + return rv; } char chainin_yn_function(query, resp, def) - const char *query, *resp; - char def; +const char *query, *resp; +char def; { - int rv; + int rv; - rv = (*cibase->nprocs->win_yn_function)(cibase->ndata, query, resp, def); + rv = (*cibase->nprocs->win_yn_function)(cibase->ndata, query, resp, def); - return rv; + return rv; } - void chainin_getlin(query, bufp) - const char *query; - char *bufp; +const char *query; +char *bufp; { - (*cibase->nprocs->win_getlin)(cibase->ndata, query, bufp); + (*cibase->nprocs->win_getlin)(cibase->ndata, query, bufp); } int chainin_get_ext_cmd() { - int rv; + int rv; - rv = (*cibase->nprocs->win_get_ext_cmd)(cibase->ndata); + rv = (*cibase->nprocs->win_get_ext_cmd)(cibase->ndata); - return rv; + return rv; } void chainin_number_pad(state) - int state; +int state; { - (*cibase->nprocs->win_number_pad)(cibase->ndata, state); + (*cibase->nprocs->win_number_pad)(cibase->ndata, state); } void chainin_delay_output() { - (*cibase->nprocs->win_delay_output)(cibase->ndata); + (*cibase->nprocs->win_delay_output)(cibase->ndata); } #ifdef CHANGE_COLOR void chainin_change_color(color, value, reverse) - int color; - long value; - int reverse; +int color; +long value; +int reverse; { - (*cibase->nprocs->win_change_color)(cibase->ndata, color, value, reverse); + (*cibase->nprocs->win_change_color)(cibase->ndata, color, value, reverse); } #ifdef MAC void chainin_change_background(bw) - int bw; +int bw; { - (*cibase->nprocs->win_change_background)(cibase->ndata, bw); + (*cibase->nprocs->win_change_background)(cibase->ndata, bw); } short chainin_set_font_name(window, font) - winid window; - char *font; +winid window; +char *font; { - short rv; + short rv; - rv = (*cibase->nprocs->win_set_font_name)(cibase->ndata, window, font); + rv = (*cibase->nprocs->win_set_font_name)(cibase->ndata, window, font); - return rv; + return rv; } #endif -char *trace_get_color_string() +char * +trace_get_color_string() { - char *rv; + char *rv; - rv = (*cibase->nprocs->win_get_color_string)(cibase->ndata); + rv = (*cibase->nprocs->win_get_color_string)(cibase->ndata); - return rv; + return rv; } #endif @@ -420,41 +419,40 @@ char *trace_get_color_string() void chainin_start_screen() { - (*cibase->nprocs->win_start_screen)(cibase->ndata); + (*cibase->nprocs->win_start_screen)(cibase->ndata); } void chainin_end_screen() { - (*cibase->nprocs->win_end_screen)(cibase->ndata); + (*cibase->nprocs->win_end_screen)(cibase->ndata); } void chainin_outrip(tmpwin, how, when) - winid tmpwin; - int how; - time_t when; +winid tmpwin; +int how; +time_t when; { - (*cibase->nprocs->win_outrip)(cibase->ndata, tmpwin, how, when); + (*cibase->nprocs->win_outrip)(cibase->ndata, tmpwin, how, when); } void chainin_preference_update(pref) - const char *pref; +const char *pref; { - (*cibase->nprocs->win_preference_update)(cibase->ndata, pref); + (*cibase->nprocs->win_preference_update)(cibase->ndata, pref); } - char * chainin_getmsghistory(init) boolean init; { - char *rv; + char *rv; - rv = (*cibase->nprocs->win_getmsghistory)(cibase->ndata,init); + rv = (*cibase->nprocs->win_getmsghistory)(cibase->ndata, init); - return rv; + return rv; } void @@ -462,20 +460,20 @@ chainin_putmsghistory(msg, is_restoring) const char *msg; boolean is_restoring; { - (*cibase->nprocs->win_putmsghistory)(cibase->ndata, msg, is_restoring); + (*cibase->nprocs->win_putmsghistory)(cibase->ndata, msg, is_restoring); } #ifdef STATUS_VIA_WINDOWPORT void chainin_status_init() { - (*cibase->nprocs->win_status_init)(cibase->ndata); + (*cibase->nprocs->win_status_init)(cibase->ndata); } void chainin_status_finish() { - (*cibase->nprocs->win_status_finish)(cibase->ndata); + (*cibase->nprocs->win_status_finish)(cibase->ndata); } void @@ -485,8 +483,8 @@ const char *nm; const char *fmt; boolean enable; { - (*cibase->nprocs->win_status_enablefield)(cibase->ndata, fieldidx, nm, - fmt, enable); + (*cibase->nprocs->win_status_enablefield)(cibase->ndata, fieldidx, nm, + fmt, enable); } void @@ -494,107 +492,82 @@ chainin_status_update(idx, ptr, chg, percent) int idx, chg, percent; genericptr_t ptr; { - (*cibase->nprocs->win_status_update)(cibase->ndata, idx, ptr, chg, percent); + (*cibase->nprocs->win_status_update)(cibase->ndata, idx, ptr, chg, + percent); } -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES void -chainin_status_threshold(fldidx, thresholdtype, threshold, behavior, under, over) -int fldidx,thresholdtype; +chainin_status_threshold(fldidx, thresholdtype, threshold, behavior, under, + over) +int fldidx, thresholdtype; int behavior, under, over; anything threshold; { - (*cibase->nprocs->win_status_threshold)(cibase->ndata,fldidx, thresholdtype, - threshold, behavior, under, over); + (*cibase->nprocs->win_status_threshold)(cibase->ndata, fldidx, + thresholdtype, threshold, + behavior, under, over); } -# endif +#endif #endif boolean chainin_can_suspend() { - boolean rv; + boolean rv; - rv = (*cibase->nprocs->win_can_suspend)(cibase->ndata); + rv = (*cibase->nprocs->win_can_suspend)(cibase->ndata); - return rv; + return rv; } struct window_procs chainin_procs = { - "-chainin", - 0, /* wincap */ - 0, /* wincap2 */ -/* -XXX problem - the above need to come from the real window port, possibly -modified. May need to do something to call an additional init fn later -or if this is the only place like this the choose_windows fn can do the fixup -(but not if the value can be modified by the stack?) TBD -*/ + "-chainin", 0, /* wincap */ + 0, /* wincap2 */ + /* + XXX problem - the above need to come from the real window port, possibly + modified. May need to do something to call an additional init fn later + or if this is the only place like this the choose_windows fn can do the + fixup + (but not if the value can be modified by the stack?) TBD + */ chainin_init_nhwindows, - chainin_player_selection, - chainin_askname, - chainin_get_nh_event, - chainin_exit_nhwindows, - chainin_suspend_nhwindows, - chainin_resume_nhwindows, - chainin_create_nhwindow, - chainin_clear_nhwindow, - chainin_display_nhwindow, - chainin_destroy_nhwindow, - chainin_curs, - chainin_putstr, - chainin_putmixed, - chainin_display_file, - chainin_start_menu, - chainin_add_menu, - chainin_end_menu, - chainin_select_menu, - chainin_message_menu, - chainin_update_inventory, - chainin_mark_synch, - chainin_wait_synch, + chainin_player_selection, chainin_askname, chainin_get_nh_event, + chainin_exit_nhwindows, chainin_suspend_nhwindows, + chainin_resume_nhwindows, chainin_create_nhwindow, chainin_clear_nhwindow, + chainin_display_nhwindow, chainin_destroy_nhwindow, chainin_curs, + chainin_putstr, chainin_putmixed, chainin_display_file, + chainin_start_menu, chainin_add_menu, chainin_end_menu, + chainin_select_menu, chainin_message_menu, chainin_update_inventory, + chainin_mark_synch, chainin_wait_synch, #ifdef CLIPPING chainin_cliparound, #endif #ifdef POSITIONBAR chainin_update_positionbar, #endif - chainin_print_glyph, - chainin_raw_print, - chainin_raw_print_bold, - chainin_nhgetch, - chainin_nh_poskey, - chainin_nhbell, - chainin_doprev_message, - chainin_yn_function, - chainin_getlin, - chainin_get_ext_cmd, - chainin_number_pad, - chainin_delay_output, + chainin_print_glyph, chainin_raw_print, chainin_raw_print_bold, + chainin_nhgetch, chainin_nh_poskey, chainin_nhbell, + chainin_doprev_message, chainin_yn_function, chainin_getlin, + chainin_get_ext_cmd, chainin_number_pad, chainin_delay_output, #ifdef CHANGE_COLOR chainin_change_color, #ifdef MAC - chainin_change_background, - chainin_set_font_name, + chainin_change_background, chainin_set_font_name, #endif chainin_get_color_string, #endif - chainin_start_screen, - chainin_end_screen, + chainin_start_screen, chainin_end_screen, - chainin_outrip, - chainin_preference_update, - chainin_getmsghistory, + chainin_outrip, chainin_preference_update, chainin_getmsghistory, chainin_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - chainin_status_init, - chainin_status_finish, - chainin_status_enablefield, + chainin_status_init, chainin_status_finish, chainin_status_enablefield, chainin_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES chainin_status_threshold, -# endif +#endif #endif chainin_can_suspend, }; diff --git a/win/chain/wc_chainout.c b/win/chain/wc_chainout.c index 8b40cb16d..1a27c3d2b 100644 --- a/win/chain/wc_chainout.c +++ b/win/chain/wc_chainout.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wc_chainout.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wc_chainout.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* NetHack 3.6 wc_chainout.c $Date: 2012/01/23 10:45:31 $ $Revision: 1.2 $ */ /* Copyright (c) Kenneth Lorber, 2012 */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,43 +9,43 @@ #include "hack.h" struct chainout_data { - struct window_procs *nprocs; + struct window_procs *nprocs; #if 0 void *ndata; #endif - int linknum; + int linknum; }; void * chainout_procs_chain(cmd, n, me, nextprocs, nextdata) - int cmd; - int n; - void *me; - void *nextprocs; - void *nextdata UNUSED; +int cmd; +int n; +void *me; +void *nextprocs; +void *nextdata UNUSED; { - switch(cmd){ - case WINCHAIN_ALLOC: { - struct chainout_data *tdp = calloc(1, sizeof(struct chainout_data)); - tdp->linknum = n; - return tdp; - } - case WINCHAIN_INIT: { - struct chainout_data *tdp = me; - tdp->nprocs = nextprocs; - return tdp; - } - default: - raw_printf("chainout_procs_chain: bad cmd\n"); - exit(EXIT_FAILURE); - } + switch (cmd) { + case WINCHAIN_ALLOC: { + struct chainout_data *tdp = calloc(1, sizeof(struct chainout_data)); + tdp->linknum = n; + return tdp; + } + case WINCHAIN_INIT: { + struct chainout_data *tdp = me; + tdp->nprocs = nextprocs; + return tdp; + } + default: + raw_printf("chainout_procs_chain: bad cmd\n"); + exit(EXIT_FAILURE); + } } /* XXX if we don't need this, take it out of the table */ void chainout_procs_init(dir) - int dir UNUSED; +int dir UNUSED; { } @@ -55,469 +55,469 @@ chainout_procs_init(dir) void chainout_init_nhwindows(vp, argcp, argv) - void *vp; - int *argcp; - char **argv; +void *vp; +int *argcp; +char **argv; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_init_nhwindows)(argcp, argv); + (*tdp->nprocs->win_init_nhwindows)(argcp, argv); } - void chainout_player_selection(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_player_selection)(); + (*tdp->nprocs->win_player_selection)(); } void chainout_askname(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_askname)(); + (*tdp->nprocs->win_askname)(); } void chainout_get_nh_event(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_get_nh_event)(); + (*tdp->nprocs->win_get_nh_event)(); } void chainout_exit_nhwindows(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_exit_nhwindows)(str); + (*tdp->nprocs->win_exit_nhwindows)(str); } void chainout_suspend_nhwindows(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_suspend_nhwindows)(str); + (*tdp->nprocs->win_suspend_nhwindows)(str); } void chainout_resume_nhwindows(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_resume_nhwindows)(); + (*tdp->nprocs->win_resume_nhwindows)(); } winid chainout_create_nhwindow(vp, type) - void *vp; - int type; +void *vp; +int type; { - struct chainout_data *tdp = vp; - winid rv; + struct chainout_data *tdp = vp; + winid rv; - rv = (*tdp->nprocs->win_create_nhwindow)(type); + rv = (*tdp->nprocs->win_create_nhwindow)(type); - return rv; + return rv; } void chainout_clear_nhwindow(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_clear_nhwindow)(window); + (*tdp->nprocs->win_clear_nhwindow)(window); } void chainout_display_nhwindow(vp, window, blocking) - void *vp; - winid window; - BOOLEAN_P blocking; +void *vp; +winid window; +BOOLEAN_P blocking; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_display_nhwindow)(window, blocking); + (*tdp->nprocs->win_display_nhwindow)(window, blocking); } void chainout_destroy_nhwindow(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_destroy_nhwindow)(window); + (*tdp->nprocs->win_destroy_nhwindow)(window); } void chainout_curs(vp, window, x, y) - void *vp; - winid window; - int x; - int y; +void *vp; +winid window; +int x; +int y; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_curs)(window, x, y); + (*tdp->nprocs->win_curs)(window, x, y); } void chainout_putstr(vp, window, attr, str) - void *vp; - winid window; - int attr; - const char *str; +void *vp; +winid window; +int attr; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_putstr)(window, attr, str); + (*tdp->nprocs->win_putstr)(window, attr, str); } void chainout_putmixed(vp, window, attr, str) - void *vp; - winid window; - int attr; - const char *str; +void *vp; +winid window; +int attr; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_putmixed)(window, attr, str); + (*tdp->nprocs->win_putmixed)(window, attr, str); } void chainout_display_file(vp, fname, complain) - void *vp; - const char *fname; - boolean complain; +void *vp; +const char *fname; +boolean complain; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_display_file)(fname, complain); + (*tdp->nprocs->win_display_file)(fname, complain); } void chainout_start_menu(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_start_menu)(window); + (*tdp->nprocs->win_start_menu)(window); } void -chainout_add_menu(vp, window, glyph, identifier, ch, gch, attr, str, preselected) - void *vp; - winid window; /* window to use, must be of type NHW_MENU */ - int glyph; /* glyph to display with item (unused) */ - const anything *identifier; /* what to return if selected */ - char ch; /* keyboard accelerator (0 = pick our own) */ - char gch; /* group accelerator (0 = no group) */ - int attr; /* attribute for string (like tty_putstr()) */ - const char *str; /* menu string */ - boolean preselected; /* item is marked as selected */ +chainout_add_menu(vp, window, glyph, identifier, ch, gch, attr, str, + preselected) +void *vp; +winid window; /* window to use, must be of type NHW_MENU */ +int glyph; /* glyph to display with item (unused) */ +const anything *identifier; /* what to return if selected */ +char ch; /* keyboard accelerator (0 = pick our own) */ +char gch; /* group accelerator (0 = no group) */ +int attr; /* attribute for string (like tty_putstr()) */ +const char *str; /* menu string */ +boolean preselected; /* item is marked as selected */ { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_add_menu)(window, glyph, identifier, - ch, gch, attr, str, preselected); + (*tdp->nprocs->win_add_menu)(window, glyph, identifier, ch, gch, attr, + str, preselected); } void chainout_end_menu(vp, window, prompt) - void *vp; - winid window; - const char *prompt; +void *vp; +winid window; +const char *prompt; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_end_menu)(window, prompt); + (*tdp->nprocs->win_end_menu)(window, prompt); } int chainout_select_menu(vp, window, how, menu_list) - void *vp; - winid window; - int how; - menu_item **menu_list; +void *vp; +winid window; +int how; +menu_item **menu_list; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_select_menu)(window, how, (void *)menu_list); + rv = (*tdp->nprocs->win_select_menu)(window, how, (void *) menu_list); - return rv; + return rv; } char chainout_message_menu(vp, let, how, mesg) - void *vp; - char let; - int how; - const char *mesg; +void *vp; +char let; +int how; +const char *mesg; { - struct chainout_data *tdp = vp; - char rv; + struct chainout_data *tdp = vp; + char rv; - rv = (*tdp->nprocs->win_message_menu)(let, how, mesg); + rv = (*tdp->nprocs->win_message_menu)(let, how, mesg); - return rv; + return rv; } void chainout_update_inventory(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_update_inventory)(); + (*tdp->nprocs->win_update_inventory)(); } void chainout_mark_synch(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_mark_synch)(); + (*tdp->nprocs->win_mark_synch)(); } void chainout_wait_synch(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_wait_synch)(); + (*tdp->nprocs->win_wait_synch)(); } #ifdef CLIPPING void chainout_cliparound(vp, x, y) - void *vp; - int x; - int y; +void *vp; +int x; +int y; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_cliparound)(x, y); + (*tdp->nprocs->win_cliparound)(x, y); } #endif #ifdef POSITIONBAR void chainout_update_positionbar(vp, posbar) - void *vp; - char *posbar; +void *vp; +char *posbar; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_update_positionbar)(posbar); + (*tdp->nprocs->win_update_positionbar)(posbar); } #endif void chainout_print_glyph(vp, window, x, y, glyph) - void *vp; - winid window; - xchar x, y; - int glyph; +void *vp; +winid window; +xchar x, y; +int glyph; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_print_glyph)(window, x, y, glyph); + (*tdp->nprocs->win_print_glyph)(window, x, y, glyph); } void chainout_raw_print(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_raw_print)(str); + (*tdp->nprocs->win_raw_print)(str); } void chainout_raw_print_bold(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_raw_print_bold)(str); + (*tdp->nprocs->win_raw_print_bold)(str); } int chainout_nhgetch(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_nhgetch)(); + rv = (*tdp->nprocs->win_nhgetch)(); - return rv; + return rv; } int chainout_nh_poskey(vp, x, y, mod) - void *vp; - int *x; - int *y; - int *mod; +void *vp; +int *x; +int *y; +int *mod; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_nh_poskey)(x, y, mod); + rv = (*tdp->nprocs->win_nh_poskey)(x, y, mod); - return rv; + return rv; } void chainout_nhbell(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_nhbell)(); + (*tdp->nprocs->win_nhbell)(); } int chainout_doprev_message(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_doprev_message)(); + rv = (*tdp->nprocs->win_doprev_message)(); - return rv; + return rv; } char chainout_yn_function(vp, query, resp, def) - void *vp; - const char *query, *resp; - char def; +void *vp; +const char *query, *resp; +char def; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_yn_function)(query, resp, def); + rv = (*tdp->nprocs->win_yn_function)(query, resp, def); - return rv; + return rv; } void chainout_getlin(vp, query, bufp) - void *vp; - const char *query; - char *bufp; +void *vp; +const char *query; +char *bufp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_getlin)(query, bufp); + (*tdp->nprocs->win_getlin)(query, bufp); } - int chainout_get_ext_cmd(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; - int rv; + struct chainout_data *tdp = vp; + int rv; - rv = (*tdp->nprocs->win_get_ext_cmd)(); + rv = (*tdp->nprocs->win_get_ext_cmd)(); - return rv; + return rv; } void chainout_number_pad(vp, state) - void *vp; - int state; +void *vp; +int state; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_number_pad)(state); + (*tdp->nprocs->win_number_pad)(state); } void chainout_delay_output(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_delay_output)(); + (*tdp->nprocs->win_delay_output)(); } #ifdef CHANGE_COLOR void chainout_change_color(vp, color, value, reverse) - void *vp; - int color; - long value; - int reverse; +void *vp; +int color; +long value; +int reverse; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_change_color)(color, value, reverse); + (*tdp->nprocs->win_change_color)(color, value, reverse); } #ifdef MAC void chainout_change_background(vp, bw) - void *vp; - int bw; +void *vp; +int bw; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_change_background)(bw); + (*tdp->nprocs->win_change_background)(bw); } short chainout_set_font_name(vp, window, font) - void *vp; - winid window; - char *font; +void *vp; +winid window; +char *font; { - struct chainout_data *tdp = vp; - short rv; + struct chainout_data *tdp = vp; + short rv; - rv = (*tdp->nprocs->win_set_font_name)(window, font); + rv = (*tdp->nprocs->win_set_font_name)(window, font); - return rv; + return rv; } #endif -char *trace_get_color_string(vp) - void *vp; +char * +trace_get_color_string(vp) +void *vp; { - struct chainout_data *tdp = vp; - char *rv; + struct chainout_data *tdp = vp; + char *rv; - rv = (*tdp->nprocs->win_get_color_string)(); + rv = (*tdp->nprocs->win_get_color_string)(); - return rv; + return rv; } #endif @@ -525,172 +525,159 @@ char *trace_get_color_string(vp) /* other defs that really should go away (they're tty specific) */ void chainout_start_screen(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_start_screen)(); + (*tdp->nprocs->win_start_screen)(); } void chainout_end_screen(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_end_screen)(); + (*tdp->nprocs->win_end_screen)(); } void chainout_outrip(vp, tmpwin, how, when) - void *vp; - winid tmpwin; - int how; - time_t when; +void *vp; +winid tmpwin; +int how; +time_t when; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_outrip)(tmpwin, how, when); + (*tdp->nprocs->win_outrip)(tmpwin, how, when); } void chainout_preference_update(vp, pref) - void *vp; - const char *pref; +void *vp; +const char *pref; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_preference_update)(pref); + (*tdp->nprocs->win_preference_update)(pref); } - char * chainout_getmsghistory(vp, init) - void *vp; +void *vp; boolean init; { - struct chainout_data *tdp = vp; - char *rv; + struct chainout_data *tdp = vp; + char *rv; - rv = (*tdp->nprocs->win_getmsghistory)(init); + rv = (*tdp->nprocs->win_getmsghistory)(init); - return rv; + return rv; } void chainout_putmsghistory(vp, msg, is_restoring) - void *vp; +void *vp; const char *msg; boolean is_restoring; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_putmsghistory)(msg, is_restoring); + (*tdp->nprocs->win_putmsghistory)(msg, is_restoring); } #ifdef STATUS_VIA_WINDOWPORT void chainout_status_init(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_status_init)(); + (*tdp->nprocs->win_status_init)(); } void chainout_status_finish(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_status_finish)(); + (*tdp->nprocs->win_status_finish)(); } void chainout_status_enablefield(vp, fieldidx, nm, fmt, enable) - void *vp; +void *vp; int fieldidx; const char *nm; const char *fmt; boolean enable; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_status_enablefield)(fieldidx, nm, fmt, enable); + (*tdp->nprocs->win_status_enablefield)(fieldidx, nm, fmt, enable); } void chainout_status_update(vp, idx, ptr, chg, percent) - void *vp; +void *vp; int idx, chg, percent; genericptr_t ptr; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_status_update)(idx, ptr, chg, percent); + (*tdp->nprocs->win_status_update)(idx, ptr, chg, percent); } -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES void -chainout_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, under, over) - void *vp; -int fldidx,thresholdtype; +chainout_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, + under, over) +void *vp; +int fldidx, thresholdtype; int behavior, under, over; anything threshold; { - struct chainout_data *tdp = vp; + struct chainout_data *tdp = vp; - (*tdp->nprocs->win_status_threshold)(fldidx, thresholdtype, - threshold, behavior, under, over); + (*tdp->nprocs->win_status_threshold)(fldidx, thresholdtype, threshold, + behavior, under, over); } -# endif +#endif #endif boolean chainout_can_suspend(vp) - void *vp; +void *vp; { - struct chainout_data *tdp = vp; - boolean rv; + struct chainout_data *tdp = vp; + boolean rv; - rv = (*tdp->nprocs->win_can_suspend)(); + rv = (*tdp->nprocs->win_can_suspend)(); - return rv; + return rv; } struct chain_procs chainout_procs = { - "-chainout", - 0, /* wincap */ - 0, /* wincap2 */ -/* -XXX problem - the above need to come from the real window port, possibly -modified. May need to do something to call an additional init fn later -or if this is the only place like this the choose_windows fn can do the fixup -(but not if the value can be modified by the stack?) TBD -*/ + "-chainout", 0, /* wincap */ + 0, /* wincap2 */ + /* + XXX problem - the above need to come from the real window port, possibly + modified. May need to do something to call an additional init fn later + or if this is the only place like this the choose_windows fn can do the + fixup + (but not if the value can be modified by the stack?) TBD + */ chainout_init_nhwindows, - chainout_player_selection, - chainout_askname, - chainout_get_nh_event, - chainout_exit_nhwindows, - chainout_suspend_nhwindows, - chainout_resume_nhwindows, - chainout_create_nhwindow, - chainout_clear_nhwindow, - chainout_display_nhwindow, - chainout_destroy_nhwindow, - chainout_curs, - chainout_putstr, - chainout_putmixed, - chainout_display_file, - chainout_start_menu, - chainout_add_menu, - chainout_end_menu, - chainout_select_menu, - chainout_message_menu, - chainout_update_inventory, - chainout_mark_synch, + chainout_player_selection, chainout_askname, chainout_get_nh_event, + chainout_exit_nhwindows, chainout_suspend_nhwindows, + chainout_resume_nhwindows, chainout_create_nhwindow, + chainout_clear_nhwindow, chainout_display_nhwindow, + chainout_destroy_nhwindow, chainout_curs, chainout_putstr, + chainout_putmixed, chainout_display_file, chainout_start_menu, + chainout_add_menu, chainout_end_menu, chainout_select_menu, + chainout_message_menu, chainout_update_inventory, chainout_mark_synch, chainout_wait_synch, #ifdef CLIPPING chainout_cliparound, @@ -698,42 +685,28 @@ or if this is the only place like this the choose_windows fn can do the fixup #ifdef POSITIONBAR chainout_update_positionbar, #endif - chainout_print_glyph, - chainout_raw_print, - chainout_raw_print_bold, - chainout_nhgetch, - chainout_nh_poskey, - chainout_nhbell, - chainout_doprev_message, - chainout_yn_function, - chainout_getlin, - chainout_get_ext_cmd, - chainout_number_pad, - chainout_delay_output, + chainout_print_glyph, chainout_raw_print, chainout_raw_print_bold, + chainout_nhgetch, chainout_nh_poskey, chainout_nhbell, + chainout_doprev_message, chainout_yn_function, chainout_getlin, + chainout_get_ext_cmd, chainout_number_pad, chainout_delay_output, #ifdef CHANGE_COLOR chainout_change_color, #ifdef MAC - chainout_change_background, - chainout_set_font_name, + chainout_change_background, chainout_set_font_name, #endif chainout_get_color_string, #endif - chainout_start_screen, - chainout_end_screen, + chainout_start_screen, chainout_end_screen, - chainout_outrip, - chainout_preference_update, - chainout_getmsghistory, + chainout_outrip, chainout_preference_update, chainout_getmsghistory, chainout_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - chainout_status_init, - chainout_status_finish, - chainout_status_enablefield, + chainout_status_init, chainout_status_finish, chainout_status_enablefield, chainout_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES chainout_status_threshold, -# endif +#endif #endif chainout_can_suspend, }; diff --git a/win/chain/wc_trace.c b/win/chain/wc_trace.c index e888e53c2..43fa3a32d 100644 --- a/win/chain/wc_trace.c +++ b/win/chain/wc_trace.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wc_trace.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wc_trace.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* NetHack 3.6 wc_trace.c $Date: 2012/01/23 10:45:31 $ $Revision: 1.2 $ */ /* Copyright (c) Kenneth Lorber, 2012 */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,84 +10,84 @@ #include #include -FILE *wc_tracelogf; /* Should be static, but it's just too useful to have - * access to this logfile from arbitrary other files. */ -static unsigned int indent_level; /* Some winfuncs call other winfuncs, so - * we need to support nesting. */ +FILE *wc_tracelogf; /* Should be static, but it's just too useful to have + * access to this logfile from arbitrary other files. */ +static unsigned int indent_level; /* Some winfuncs call other winfuncs, so + * we need to support nesting. */ static char indentdata[10] = " "; #define ISCALE 1 #if 1 -#define INDENT &indentdata[ \ - ((indent_level*ISCALE)<(sizeof(indentdata))) \ - ? ((sizeof(indentdata)-1)-(indent_level*ISCALE)) \ - : 0 \ - ] +#define INDENT \ + &indentdata[((indent_level * ISCALE) < (sizeof(indentdata))) \ + ? ((sizeof(indentdata) - 1) - (indent_level * ISCALE)) \ + : 0] #else /* for debugging this file */ -#define INDENT \ - ({ \ - static char buf[50]; \ - sprintf(buf, "[%s:%d %d]\t", __func__,__LINE__,indent_level); \ - buf; \ - }) +#define INDENT \ + ({ \ + static char buf[50]; \ + sprintf(buf, "[%s:%d %d]\t", __func__, __LINE__, indent_level); \ + buf; \ + }) #endif #define PRE indent_level++ #define POST indent_level-- struct trace_data { - struct chain_procs *nprocs; - void *ndata; + struct chain_procs *nprocs; + void *ndata; - int linknum; + int linknum; }; void * trace_procs_chain(cmd, n, me, nextprocs, nextdata) - int cmd; - int n; - void *me; - void *nextprocs; - void *nextdata; +int cmd; +int n; +void *me; +void *nextprocs; +void *nextdata; { - switch(cmd){ - case WINCHAIN_ALLOC: { - struct trace_data *tdp = calloc(1, sizeof(struct trace_data)); - tdp->linknum = n; - return tdp; - } - case WINCHAIN_INIT: { - struct trace_data *tdp = me; - tdp->nprocs = nextprocs; - tdp->ndata = nextdata; - return tdp; - } - default: - raw_printf("trace_procs_chain: bad cmd\n"); - exit(EXIT_FAILURE); - } + switch (cmd) { + case WINCHAIN_ALLOC: { + struct trace_data *tdp = calloc(1, sizeof(struct trace_data)); + tdp->linknum = n; + return tdp; + } + case WINCHAIN_INIT: { + struct trace_data *tdp = me; + tdp->nprocs = nextprocs; + tdp->ndata = nextdata; + return tdp; + } + default: + raw_printf("trace_procs_chain: bad cmd\n"); + exit(EXIT_FAILURE); + } } void trace_procs_init(dir) - int dir; +int dir; { - char fname[200]; + char fname[200]; - /* processors shouldn't need this test, but just in case */ - if(dir != WININIT) return; + /* processors shouldn't need this test, but just in case */ + if (dir != WININIT) + return; - sprintf(fname, "%s/tlog.%d", HACKDIR, getpid()); - wc_tracelogf = fopen(fname, "w"); - if(wc_tracelogf == NULL){ - fprintf(stderr, "Can't open trace log file %s: %s\n", - fname, strerror(errno)); - exit(EXIT_FAILURE); - } - setvbuf(wc_tracelogf, (char *)NULL, _IONBF, 0); - fprintf(wc_tracelogf, "Trace log started for pid %d\n", getpid()); + sprintf(fname, "%s/tlog.%d", HACKDIR, getpid()); + wc_tracelogf = fopen(fname, "w"); + if (wc_tracelogf == NULL) { + fprintf(stderr, "Can't open trace log file %s: %s\n", fname, + strerror(errno)); + exit(EXIT_FAILURE); + } + setvbuf(wc_tracelogf, (char *) NULL, _IONBF, 0); + fprintf(wc_tracelogf, "Trace log started for pid %d\n", getpid()); - indent_level = 0; + indent_level = 0; } /*** @@ -96,466 +96,476 @@ trace_procs_init(dir) void trace_init_nhwindows(vp, argcp, argv) - void *vp; - int *argcp; - char **argv; +void *vp; +int *argcp; +char **argv; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sinit_nhwindows(%d,*)\n", INDENT, *argcp); + fprintf(wc_tracelogf, "%sinit_nhwindows(%d,*)\n", INDENT, *argcp); - PRE; - (*tdp->nprocs->win_init_nhwindows)(tdp->ndata, argcp, argv); - POST; + PRE; + (*tdp->nprocs->win_init_nhwindows)(tdp->ndata, argcp, argv); + POST; } - void trace_player_selection(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%splayer_selection()\n", INDENT); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%splayer_selection()\n", INDENT); - PRE; - (*tdp->nprocs->win_player_selection)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_player_selection)(tdp->ndata); + POST; } void trace_askname(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%saskname()\n", INDENT); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%saskname()\n", INDENT); - PRE; - (*tdp->nprocs->win_askname)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_askname)(tdp->ndata); + POST; } void trace_get_nh_event(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sget_nh_event()\n", INDENT); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%sget_nh_event()\n", INDENT); - PRE; - (*tdp->nprocs->win_get_nh_event)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_get_nh_event)(tdp->ndata); + POST; } void trace_exit_nhwindows(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sexit_nhwindows(%s)\n", INDENT, str); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%sexit_nhwindows(%s)\n", INDENT, str); - PRE; - (*tdp->nprocs->win_exit_nhwindows)(tdp->ndata, str); - POST; + PRE; + (*tdp->nprocs->win_exit_nhwindows)(tdp->ndata, str); + POST; } void trace_suspend_nhwindows(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%ssuspend_nhwindows(%s)\n", INDENT, str); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%ssuspend_nhwindows(%s)\n", INDENT, str); - PRE; - (*tdp->nprocs->win_suspend_nhwindows)(tdp->ndata, str); - POST; + PRE; + (*tdp->nprocs->win_suspend_nhwindows)(tdp->ndata, str); + POST; } void trace_resume_nhwindows(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sresume_nhwindows()\n", INDENT); + struct trace_data *tdp = vp; + fprintf(wc_tracelogf, "%sresume_nhwindows()\n", INDENT); - PRE; - (*tdp->nprocs->win_resume_nhwindows)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_resume_nhwindows)(tdp->ndata); + POST; } static const char * NHWname(type) - int type; +int type; { - switch(type){ - case NHW_MESSAGE: return "MESSAGE"; - case NHW_STATUS: return "STATUS"; - case NHW_MAP: return "MAP"; - case NHW_MENU: return "MENU"; - case NHW_TEXT: return "TEXT"; - case NHW_BASE: return "BASE"; - default: { - static char b[20]; - sprintf(b, "(%d)",type); - return b; - } - } + switch (type) { + case NHW_MESSAGE: + return "MESSAGE"; + case NHW_STATUS: + return "STATUS"; + case NHW_MAP: + return "MAP"; + case NHW_MENU: + return "MENU"; + case NHW_TEXT: + return "TEXT"; + case NHW_BASE: + return "BASE"; + default: { + static char b[20]; + sprintf(b, "(%d)", type); + return b; + } + } } winid trace_create_nhwindow(vp, type) - void *vp; - int type; +void *vp; +int type; { - struct trace_data *tdp = vp; - const char *typestring = NHWname(type); - winid rv; + struct trace_data *tdp = vp; + const char *typestring = NHWname(type); + winid rv; - fprintf(wc_tracelogf, "%screate_nhwindow(%s)\n", INDENT, typestring); + fprintf(wc_tracelogf, "%screate_nhwindow(%s)\n", INDENT, typestring); - PRE; - rv = (*tdp->nprocs->win_create_nhwindow)(tdp->ndata, type); - POST; + PRE; + rv = (*tdp->nprocs->win_create_nhwindow)(tdp->ndata, type); + POST; - fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); - return rv; + fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); + return rv; } void trace_clear_nhwindow(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sclear_nhwindow(%d)\n", INDENT, window); + fprintf(wc_tracelogf, "%sclear_nhwindow(%d)\n", INDENT, window); - PRE; - (*tdp->nprocs->win_clear_nhwindow)(tdp->ndata, window); - POST; + PRE; + (*tdp->nprocs->win_clear_nhwindow)(tdp->ndata, window); + POST; } void trace_display_nhwindow(vp, window, blocking) - void *vp; - winid window; - BOOLEAN_P blocking; +void *vp; +winid window; +BOOLEAN_P blocking; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sdisplay_nhwindow(%d, %d)\n", INDENT, window, blocking); + fprintf(wc_tracelogf, "%sdisplay_nhwindow(%d, %d)\n", INDENT, window, + blocking); - PRE; - (*tdp->nprocs->win_display_nhwindow)(tdp->ndata, window, blocking); - POST; + PRE; + (*tdp->nprocs->win_display_nhwindow)(tdp->ndata, window, blocking); + POST; } void trace_destroy_nhwindow(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sdestroy_nhwindow(%d)\n", INDENT, window); + fprintf(wc_tracelogf, "%sdestroy_nhwindow(%d)\n", INDENT, window); - PRE; - (*tdp->nprocs->win_destroy_nhwindow)(tdp->ndata, window); - POST; + PRE; + (*tdp->nprocs->win_destroy_nhwindow)(tdp->ndata, window); + POST; } void trace_curs(vp, window, x, y) - void *vp; - winid window; - int x; - int y; +void *vp; +winid window; +int x; +int y; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%scurs(%d, %d, %d)\n", INDENT, window, x, y); + fprintf(wc_tracelogf, "%scurs(%d, %d, %d)\n", INDENT, window, x, y); - PRE; - (*tdp->nprocs->win_curs)(tdp->ndata, window, x, y); - POST; + PRE; + (*tdp->nprocs->win_curs)(tdp->ndata, window, x, y); + POST; } void trace_putstr(vp, window, attr, str) - void *vp; - winid window; - int attr; - const char *str; +void *vp; +winid window; +int attr; +const char *str; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(str){ - fprintf(wc_tracelogf, "%sputstr(%d, %d, '%s'(%d))\n", INDENT, window, attr, str, - (int)strlen(str)); - } else { - fprintf(wc_tracelogf, "%sputstr(%d, %d, NULL)\n", INDENT, window, attr); - } + if (str) { + fprintf(wc_tracelogf, "%sputstr(%d, %d, '%s'(%d))\n", INDENT, window, + attr, str, (int) strlen(str)); + } else { + fprintf(wc_tracelogf, "%sputstr(%d, %d, NULL)\n", INDENT, window, + attr); + } - PRE; - (*tdp->nprocs->win_putstr)(tdp->ndata, window, attr, str); - POST; + PRE; + (*tdp->nprocs->win_putstr)(tdp->ndata, window, attr, str); + POST; } void trace_putmixed(vp, window, attr, str) - void *vp; - winid window; - int attr; - const char *str; +void *vp; +winid window; +int attr; +const char *str; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(str){ - fprintf(wc_tracelogf, "%sputmixed(%d, %d, '%s'(%d))\n", INDENT, window, attr, - str, (int)strlen(str)); - } else { - fprintf(wc_tracelogf, "%sputmixed(%d, %d, NULL)\n", INDENT, window, attr); - } + if (str) { + fprintf(wc_tracelogf, "%sputmixed(%d, %d, '%s'(%d))\n", INDENT, + window, attr, str, (int) strlen(str)); + } else { + fprintf(wc_tracelogf, "%sputmixed(%d, %d, NULL)\n", INDENT, window, + attr); + } - PRE; - (*tdp->nprocs->win_putmixed)(tdp->ndata, window, attr, str); - POST; + PRE; + (*tdp->nprocs->win_putmixed)(tdp->ndata, window, attr, str); + POST; } void trace_display_file(vp, fname, complain) - void *vp; - const char *fname; - boolean complain; +void *vp; +const char *fname; +boolean complain; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(fname){ - fprintf(wc_tracelogf, "%sdisplay_file('%s'(%d), %d)\n", INDENT, - fname, (int)strlen(fname), complain); - } else { - fprintf(wc_tracelogf, "%sdisplay_file(NULL, %d)\n", INDENT, complain); - } + if (fname) { + fprintf(wc_tracelogf, "%sdisplay_file('%s'(%d), %d)\n", INDENT, fname, + (int) strlen(fname), complain); + } else { + fprintf(wc_tracelogf, "%sdisplay_file(NULL, %d)\n", INDENT, complain); + } - PRE; - (*tdp->nprocs->win_display_file)(tdp->ndata, fname, complain); - POST; + PRE; + (*tdp->nprocs->win_display_file)(tdp->ndata, fname, complain); + POST; } void trace_start_menu(vp, window) - void *vp; - winid window; +void *vp; +winid window; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstart_menu(%d)\n", INDENT, window); + fprintf(wc_tracelogf, "%sstart_menu(%d)\n", INDENT, window); - PRE; - (*tdp->nprocs->win_start_menu)(tdp->ndata, window); - POST; + PRE; + (*tdp->nprocs->win_start_menu)(tdp->ndata, window); + POST; } void trace_add_menu(vp, window, glyph, identifier, ch, gch, attr, str, preselected) - void *vp; - winid window; /* window to use, must be of type NHW_MENU */ - int glyph; /* glyph to display with item (unused) */ - const anything *identifier; /* what to return if selected */ - char ch; /* keyboard accelerator (0 = pick our own) */ - char gch; /* group accelerator (0 = no group) */ - int attr; /* attribute for string (like tty_putstr()) */ - const char *str; /* menu string */ - boolean preselected; /* item is marked as selected */ +void *vp; +winid window; /* window to use, must be of type NHW_MENU */ +int glyph; /* glyph to display with item (unused) */ +const anything *identifier; /* what to return if selected */ +char ch; /* keyboard accelerator (0 = pick our own) */ +char gch; /* group accelerator (0 = no group) */ +int attr; /* attribute for string (like tty_putstr()) */ +const char *str; /* menu string */ +boolean preselected; /* item is marked as selected */ { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - char buf_ch[10]; - char buf_gch[10]; + char buf_ch[10]; + char buf_gch[10]; - if(isprint(ch)){ - sprintf(buf_ch, "'%c'(%d)", ch, ch); - } else { - sprintf(buf_ch, "(%d)", ch); - } + if (isprint(ch)) { + sprintf(buf_ch, "'%c'(%d)", ch, ch); + } else { + sprintf(buf_ch, "(%d)", ch); + } - if(isprint(gch)){ - sprintf(buf_gch, "'%c'(%d)", gch, gch); - } else { - sprintf(buf_gch, "(%d)", gch); - } + if (isprint(gch)) { + sprintf(buf_gch, "'%c'(%d)", gch, gch); + } else { + sprintf(buf_gch, "(%d)", gch); + } - if(str){ - fprintf(wc_tracelogf, "%sadd_menu(%d, %d, %p, %s, %s, %d, '%s'(%d), %d)\n", INDENT, - window, glyph, (void *)identifier, buf_ch, - buf_gch, attr, str, (int)strlen(str), preselected); - } else { - fprintf(wc_tracelogf, "%sadd_menu(%d, %d, %p, %s, %s, %d, NULL, %d)\n", INDENT, - window, glyph, (void *)identifier, buf_ch, - buf_gch, attr, preselected); - } + if (str) { + fprintf(wc_tracelogf, + "%sadd_menu(%d, %d, %p, %s, %s, %d, '%s'(%d), %d)\n", INDENT, + window, glyph, (void *) identifier, buf_ch, buf_gch, attr, + str, (int) strlen(str), preselected); + } else { + fprintf(wc_tracelogf, + "%sadd_menu(%d, %d, %p, %s, %s, %d, NULL, %d)\n", INDENT, + window, glyph, (void *) identifier, buf_ch, buf_gch, attr, + preselected); + } - PRE; - (*tdp->nprocs->win_add_menu)(tdp->ndata, window, glyph, identifier, - ch, gch, attr, str, preselected); - POST; + PRE; + (*tdp->nprocs->win_add_menu)(tdp->ndata, window, glyph, identifier, ch, + gch, attr, str, preselected); + POST; } void trace_end_menu(vp, window, prompt) - void *vp; - winid window; - const char *prompt; +void *vp; +winid window; +const char *prompt; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(prompt){ - fprintf(wc_tracelogf, "%send_menu(%d, '%s'(%d))\n", INDENT, window, - prompt, (int)strlen(prompt)); - } else { - fprintf(wc_tracelogf, "%send_menu(%d, NULL)\n", INDENT, window); - } + if (prompt) { + fprintf(wc_tracelogf, "%send_menu(%d, '%s'(%d))\n", INDENT, window, + prompt, (int) strlen(prompt)); + } else { + fprintf(wc_tracelogf, "%send_menu(%d, NULL)\n", INDENT, window); + } - PRE; - (*tdp->nprocs->win_end_menu)(tdp->ndata, window, prompt); - POST; + PRE; + (*tdp->nprocs->win_end_menu)(tdp->ndata, window, prompt); + POST; } int trace_select_menu(vp, window, how, menu_list) - void *vp; - winid window; - int how; - menu_item **menu_list; +void *vp; +winid window; +int how; +menu_item **menu_list; { - struct trace_data *tdp = vp; - int rv; + struct trace_data *tdp = vp; + int rv; - fprintf(wc_tracelogf, "%sselect_menu(%d, %d, %p)\n", INDENT, window, how, - (void *)menu_list); + fprintf(wc_tracelogf, "%sselect_menu(%d, %d, %p)\n", INDENT, window, how, + (void *) menu_list); - PRE; - rv = (*tdp->nprocs->win_select_menu)(tdp->ndata, window, how, - (void *)menu_list); - POST; + PRE; + rv = (*tdp->nprocs->win_select_menu)(tdp->ndata, window, how, + (void *) menu_list); + POST; - fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); - return rv; + fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); + return rv; } char trace_message_menu(vp, let, how, mesg) - void *vp; - char let; - int how; - const char *mesg; +void *vp; +char let; +int how; +const char *mesg; { - struct trace_data *tdp = vp; - char buf_let[10]; - char rv; + struct trace_data *tdp = vp; + char buf_let[10]; + char rv; - if(isprint(let)){ - sprintf(buf_let, "'%c'(%d)", let, let); - } else { - sprintf(buf_let, "(%d)", let); - } + if (isprint(let)) { + sprintf(buf_let, "'%c'(%d)", let, let); + } else { + sprintf(buf_let, "(%d)", let); + } - if(mesg){ - fprintf(wc_tracelogf, "%smessage_menu(%s, %d, '%s'(%d))\n", INDENT, - buf_let, how, mesg, (int)strlen(mesg)); - } else { - fprintf(wc_tracelogf, "%smessage_menu(%s, %d, NULL)\n", INDENT, - buf_let, how); - } + if (mesg) { + fprintf(wc_tracelogf, "%smessage_menu(%s, %d, '%s'(%d))\n", INDENT, + buf_let, how, mesg, (int) strlen(mesg)); + } else { + fprintf(wc_tracelogf, "%smessage_menu(%s, %d, NULL)\n", INDENT, + buf_let, how); + } - PRE; - rv = (*tdp->nprocs->win_message_menu)(tdp->ndata, let, how, mesg); - POST; + PRE; + rv = (*tdp->nprocs->win_message_menu)(tdp->ndata, let, how, mesg); + POST; - if(isprint(rv)){ - sprintf(buf_let, "'%c'(%d)", rv, rv); - } else { - sprintf(buf_let, "(%d)", rv); - } - fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf_let); + if (isprint(rv)) { + sprintf(buf_let, "'%c'(%d)", rv, rv); + } else { + sprintf(buf_let, "(%d)", rv); + } + fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf_let); - return rv; + return rv; } void trace_update_inventory(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%supdate_inventory()\n", INDENT); + fprintf(wc_tracelogf, "%supdate_inventory()\n", INDENT); - PRE; - (*tdp->nprocs->win_update_inventory)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_update_inventory)(tdp->ndata); + POST; } void trace_mark_synch(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%smark_synch()\n", INDENT); + fprintf(wc_tracelogf, "%smark_synch()\n", INDENT); - PRE; - (*tdp->nprocs->win_mark_synch)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_mark_synch)(tdp->ndata); + POST; } void trace_wait_synch(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%swait_synch()\n", INDENT); + fprintf(wc_tracelogf, "%swait_synch()\n", INDENT); - PRE; - (*tdp->nprocs->win_wait_synch)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_wait_synch)(tdp->ndata); + POST; } #ifdef CLIPPING void trace_cliparound(vp, x, y) - void *vp; - int x; - int y; +void *vp; +int x; +int y; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%scliparound(%d, %d)\n", INDENT, x, y); + fprintf(wc_tracelogf, "%scliparound(%d, %d)\n", INDENT, x, y); - PRE; - (*tdp->nprocs->win_cliparound)(tdp->ndata, x, y); - POST; + PRE; + (*tdp->nprocs->win_cliparound)(tdp->ndata, x, y); + POST; } #endif #ifdef POSITIONBAR void trace_update_positionbar(vp, posbar) - void *vp; - char *posbar; +void *vp; +char *posbar; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(posbar){ - fprintf(wc_tracelogf, "%supdate_positionbar('%s'(%d))\n", INDENT, - posbar, (int)strlen(posbar)); - } else { - fprintf(wc_tracelogf, "%supdate_positionbar(NULL)\n"); - } - PRE; - (*tdp->nprocs->win_update_positionbar)(tdp->ndata, posbar); - POST; + if (posbar) { + fprintf(wc_tracelogf, "%supdate_positionbar('%s'(%d))\n", INDENT, + posbar, (int) strlen(posbar)); + } else { + fprintf(wc_tracelogf, "%supdate_positionbar(NULL)\n"); + } + PRE; + (*tdp->nprocs->win_update_positionbar)(tdp->ndata, posbar); + POST; } #endif @@ -563,340 +573,349 @@ trace_update_positionbar(vp, posbar) genl_putmixed? */ void trace_print_glyph(vp, window, x, y, glyph) - void *vp; - winid window; - xchar x, y; - int glyph; +void *vp; +winid window; +xchar x, y; +int glyph; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sprint_glyph(%d, %d, %d, %d)\n", INDENT, window, x, y, glyph); + fprintf(wc_tracelogf, "%sprint_glyph(%d, %d, %d, %d)\n", INDENT, window, + x, y, glyph); - PRE; - (*tdp->nprocs->win_print_glyph)(tdp->ndata, window, x, y, glyph); - POST; + PRE; + (*tdp->nprocs->win_print_glyph)(tdp->ndata, window, x, y, glyph); + POST; } void trace_raw_print(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(str){ - fprintf(wc_tracelogf, "%sraw_print('%s'(%d))\n", INDENT, str, (int)strlen(str)); - } else { - fprintf(wc_tracelogf, "%sraw_print(NULL)\n", INDENT); - } + if (str) { + fprintf(wc_tracelogf, "%sraw_print('%s'(%d))\n", INDENT, str, + (int) strlen(str)); + } else { + fprintf(wc_tracelogf, "%sraw_print(NULL)\n", INDENT); + } - PRE; - (*tdp->nprocs->win_raw_print)(tdp->ndata, str); - POST; + PRE; + (*tdp->nprocs->win_raw_print)(tdp->ndata, str); + POST; } void trace_raw_print_bold(vp, str) - void *vp; - const char *str; +void *vp; +const char *str; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(str){ - fprintf(wc_tracelogf, "%sraw_print_bold('%s'(%d))\n", INDENT, str, (int)strlen(str)); - } else { - fprintf(wc_tracelogf, "%sraw_print_bold(NULL)\n", INDENT); - } + if (str) { + fprintf(wc_tracelogf, "%sraw_print_bold('%s'(%d))\n", INDENT, str, + (int) strlen(str)); + } else { + fprintf(wc_tracelogf, "%sraw_print_bold(NULL)\n", INDENT); + } - PRE; - (*tdp->nprocs->win_raw_print_bold)(tdp->ndata, str); - POST; + PRE; + (*tdp->nprocs->win_raw_print_bold)(tdp->ndata, str); + POST; } int trace_nhgetch(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - int rv; - char buf[10]; + struct trace_data *tdp = vp; + int rv; + char buf[10]; - fprintf(wc_tracelogf, "%snhgetch()\n", INDENT); + fprintf(wc_tracelogf, "%snhgetch()\n", INDENT); - PRE; - rv = (*tdp->nprocs->win_nhgetch)(tdp->ndata); - POST; + PRE; + rv = (*tdp->nprocs->win_nhgetch)(tdp->ndata); + POST; - if(rv > 0 && rv < 256 && isprint(rv)){ - sprintf(buf, "'%c'(%d)", rv, rv); - } else { - sprintf(buf, "(%d)", rv); - } - fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf); + if (rv > 0 && rv < 256 && isprint(rv)) { + sprintf(buf, "'%c'(%d)", rv, rv); + } else { + sprintf(buf, "(%d)", rv); + } + fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf); - return rv; + return rv; } int trace_nh_poskey(vp, x, y, mod) - void *vp; - int *x; - int *y; - int *mod; +void *vp; +int *x; +int *y; +int *mod; { - struct trace_data *tdp = vp; - int rv; - char buf[10]; + struct trace_data *tdp = vp; + int rv; + char buf[10]; - fprintf(wc_tracelogf, "%snh_poskey(%d, %d, %d)\n", INDENT, *x, *y, *mod); + fprintf(wc_tracelogf, "%snh_poskey(%d, %d, %d)\n", INDENT, *x, *y, *mod); - PRE; - rv = (*tdp->nprocs->win_nh_poskey)(tdp->ndata, x, y, mod); - POST; - if(rv > 0 && rv < 256 && isprint(rv)){ - sprintf(buf, "'%c'(%d)", rv, rv); - } else { - sprintf(buf, "(%d)", rv); - } - fprintf(wc_tracelogf, "%s=> %s (%d, %d, %d)\n", INDENT, buf, *x, *y, *mod); + PRE; + rv = (*tdp->nprocs->win_nh_poskey)(tdp->ndata, x, y, mod); + POST; + if (rv > 0 && rv < 256 && isprint(rv)) { + sprintf(buf, "'%c'(%d)", rv, rv); + } else { + sprintf(buf, "(%d)", rv); + } + fprintf(wc_tracelogf, "%s=> %s (%d, %d, %d)\n", INDENT, buf, *x, *y, + *mod); - return rv; + return rv; } void trace_nhbell(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%snhbell()\n", INDENT); + fprintf(wc_tracelogf, "%snhbell()\n", INDENT); - PRE; - (*tdp->nprocs->win_nhbell)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_nhbell)(tdp->ndata); + POST; } int trace_doprev_message(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - int rv; + struct trace_data *tdp = vp; + int rv; - fprintf(wc_tracelogf, "%sdoprev_message()\n", INDENT); + fprintf(wc_tracelogf, "%sdoprev_message()\n", INDENT); - PRE; - rv = (*tdp->nprocs->win_doprev_message)(tdp->ndata); - POST; + PRE; + rv = (*tdp->nprocs->win_doprev_message)(tdp->ndata); + POST; - fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); + fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); - return rv; + return rv; } char trace_yn_function(vp, query, resp, def) - void *vp; - const char *query, *resp; - char def; +void *vp; +const char *query, *resp; +char def; { - struct trace_data *tdp = vp; - char rv; - char buf[10]; + struct trace_data *tdp = vp; + char rv; + char buf[10]; - if(query){ - fprintf(wc_tracelogf, "%syn_function('%s'(%d), ", INDENT, - query, (int)strlen(query)); - } else { - fprintf(wc_tracelogf, "%syn_function(NULL, ", INDENT); - } + if (query) { + fprintf(wc_tracelogf, "%syn_function('%s'(%d), ", INDENT, query, + (int) strlen(query)); + } else { + fprintf(wc_tracelogf, "%syn_function(NULL, ", INDENT); + } - if(resp){ - fprintf(wc_tracelogf, "'%s'(%d), ", resp, (int)strlen(resp)); - } else { - fprintf(wc_tracelogf, "NULL, "); - } + if (resp) { + fprintf(wc_tracelogf, "'%s'(%d), ", resp, (int) strlen(resp)); + } else { + fprintf(wc_tracelogf, "NULL, "); + } - if(isprint(def)){ - sprintf(buf, "'%c'(%d)", def, def); - } else { - sprintf(buf, "(%d)", def); - } + if (isprint(def)) { + sprintf(buf, "'%c'(%d)", def, def); + } else { + sprintf(buf, "(%d)", def); + } - fprintf(wc_tracelogf, "%s)\n", buf); + fprintf(wc_tracelogf, "%s)\n", buf); - PRE; - rv = (*tdp->nprocs->win_yn_function)(tdp->ndata, query, resp, def); - POST; + PRE; + rv = (*tdp->nprocs->win_yn_function)(tdp->ndata, query, resp, def); + POST; - if(isprint(rv)){ - sprintf(buf, "'%c'(%d)", rv, rv); - } else { - sprintf(buf, "(%d)", rv); - } + if (isprint(rv)) { + sprintf(buf, "'%c'(%d)", rv, rv); + } else { + sprintf(buf, "(%d)", rv); + } - fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf); + fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf); - return rv; + return rv; } void trace_getlin(vp, query, bufp) - void *vp; - const char *query; - char *bufp; +void *vp; +const char *query; +char *bufp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(query){ - fprintf(wc_tracelogf, "%sgetlin('%s'(%d), ", INDENT, - query, (int)strlen(query)); - } else { - fprintf(wc_tracelogf, "%sgetlin(NULL, ", INDENT); - } + if (query) { + fprintf(wc_tracelogf, "%sgetlin('%s'(%d), ", INDENT, query, + (int) strlen(query)); + } else { + fprintf(wc_tracelogf, "%sgetlin(NULL, ", INDENT); + } - if(bufp){ - fprintf(wc_tracelogf, "%p)\n", bufp); - } else { - fprintf(wc_tracelogf, "NULL)\n"); - } + if (bufp) { + fprintf(wc_tracelogf, "%p)\n", bufp); + } else { + fprintf(wc_tracelogf, "NULL)\n"); + } - PRE; - (*tdp->nprocs->win_getlin)(tdp->ndata, query, bufp); - POST; + PRE; + (*tdp->nprocs->win_getlin)(tdp->ndata, query, bufp); + POST; } int trace_get_ext_cmd(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - int rv; - int ecl_size; + struct trace_data *tdp = vp; + int rv; + int ecl_size; - /* this is ugly, but the size isn't exposed */ - const struct ext_func_tab *efp; - for(efp = extcmdlist; efp->ef_txt; efp++) ecl_size++; + /* this is ugly, but the size isn't exposed */ + const struct ext_func_tab *efp; + for (efp = extcmdlist; efp->ef_txt; efp++) + ecl_size++; - fprintf(wc_tracelogf, "%sget_ext_cmd()\n", INDENT); + fprintf(wc_tracelogf, "%sget_ext_cmd()\n", INDENT); - PRE; - rv = (*tdp->nprocs->win_get_ext_cmd)(tdp->ndata); - POST; + PRE; + rv = (*tdp->nprocs->win_get_ext_cmd)(tdp->ndata); + POST; - if(rv < 0 || rv >= ecl_size){ - fprintf(wc_tracelogf, "%s=> (%d)\n", INDENT, rv); - } else { - fprintf(wc_tracelogf, "%s=> %d/%s\n", INDENT, rv, extcmdlist[rv].ef_txt); - } + if (rv < 0 || rv >= ecl_size) { + fprintf(wc_tracelogf, "%s=> (%d)\n", INDENT, rv); + } else { + fprintf(wc_tracelogf, "%s=> %d/%s\n", INDENT, rv, + extcmdlist[rv].ef_txt); + } - return rv; + return rv; } void trace_number_pad(vp, state) - void *vp; - int state; +void *vp; +int state; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%snumber_pad(%d)\n", INDENT, state); + fprintf(wc_tracelogf, "%snumber_pad(%d)\n", INDENT, state); - PRE; - (*tdp->nprocs->win_number_pad)(tdp->ndata, state); - POST; + PRE; + (*tdp->nprocs->win_number_pad)(tdp->ndata, state); + POST; } void trace_delay_output(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sdelay_output()\n", INDENT); + fprintf(wc_tracelogf, "%sdelay_output()\n", INDENT); - PRE; - (*tdp->nprocs->win_delay_output)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_delay_output)(tdp->ndata); + POST; } #ifdef CHANGE_COLOR void trace_change_color(vp, color, value, reverse) - void *vp; - int color; - long value; - int reverse; +void *vp; +int color; +long value; +int reverse; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%schange_color(%d, $%lx, %d)\n", INDENT, color, value, reverse); + fprintf(wc_tracelogf, "%schange_color(%d, $%lx, %d)\n", INDENT, color, + value, reverse); - PRE; - (*tdp->nprocs->win_change_color)(tdp->ndata, color, value, reverse); - POST; + PRE; + (*tdp->nprocs->win_change_color)(tdp->ndata, color, value, reverse); + POST; } #ifdef MAC void trace_change_background(vp, bw) - void *vp; - int bw; +void *vp; +int bw; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%schange_background(%d)\n", INDENT, bw); + fprintf(wc_tracelogf, "%schange_background(%d)\n", INDENT, bw); - PRE; - (*tdp->nprocs->win_change_background)(tdp->ndata, bw); - POST; + PRE; + (*tdp->nprocs->win_change_background)(tdp->ndata, bw); + POST; } short trace_set_font_name(vp, window, font) - void *vp; - winid window; - char *font; +void *vp; +winid window; +char *font; { - struct trace_data *tdp = vp; - short rv; + struct trace_data *tdp = vp; + short rv; - if(font){ - fprintf(wc_tracelogf, "%sset_font_name(%d, '%s'(%d))\n", INDENT, - window, font, (int)(strlen(font))); - } else { - fprintf(wc_tracelogf, "%sset_font_name(%d, NULL)\n", INDENT, window); - } + if (font) { + fprintf(wc_tracelogf, "%sset_font_name(%d, '%s'(%d))\n", INDENT, + window, font, (int) (strlen(font))); + } else { + fprintf(wc_tracelogf, "%sset_font_name(%d, NULL)\n", INDENT, window); + } - PRE; - rv = (*tdp->nprocs->win_set_font_name)(tdp->ndata, window, font); - POST; + PRE; + rv = (*tdp->nprocs->win_set_font_name)(tdp->ndata, window, font); + POST; - fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); + fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); - return rv; + return rv; } #endif -char *trace_get_color_string(vp) - void *vp; +char * +trace_get_color_string(vp) +void *vp; { - struct trace_data *tdp = vp; - char *rv; + struct trace_data *tdp = vp; + char *rv; - fprintf(wc_tracelogf, "%sget_color_string()\n"); + fprintf(wc_tracelogf, "%sget_color_string()\n"); - PRE; - rv = (*tdp->nprocs->win_get_color_string)(tdp->ndata); - POST; + PRE; + rv = (*tdp->nprocs->win_get_color_string)(tdp->ndata); + POST; - if(rv){ - fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv, (int)strlen(rv)); - } else { - fprintf(wc_tracelogf, "%s=> NULL\n"); - } + if (rv) { + fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv, + (int) strlen(rv)); + } else { + fprintf(wc_tracelogf, "%s=> NULL\n"); + } - return rv; + return rv; } #endif @@ -904,297 +923,269 @@ char *trace_get_color_string(vp) /* other defs that really should go away (they're tty specific) */ void trace_start_screen(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstart_screen()\n", INDENT); + fprintf(wc_tracelogf, "%sstart_screen()\n", INDENT); - PRE; - (*tdp->nprocs->win_start_screen)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_start_screen)(tdp->ndata); + POST; } void trace_end_screen(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%send_screen()\n", INDENT); + fprintf(wc_tracelogf, "%send_screen()\n", INDENT); - PRE; - (*tdp->nprocs->win_end_screen)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_end_screen)(tdp->ndata); + POST; } void trace_outrip(vp, tmpwin, how, when) - void *vp; - winid tmpwin; - int how; - time_t when; +void *vp; +winid tmpwin; +int how; +time_t when; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%soutrip(%d, %d, %ld)\n", - INDENT, (int)tmpwin, how, (long)when); + fprintf(wc_tracelogf, "%soutrip(%d, %d, %ld)\n", INDENT, (int) tmpwin, + how, (long) when); - PRE; - (*tdp->nprocs->win_outrip)(tdp->ndata, tmpwin, how, when); - POST; + PRE; + (*tdp->nprocs->win_outrip)(tdp->ndata, tmpwin, how, when); + POST; } void trace_preference_update(vp, pref) - void *vp; - const char *pref; +void *vp; +const char *pref; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(pref){ - fprintf(wc_tracelogf, "%spreference_update('%s'(%d))\n", INDENT, - pref, (int)strlen(pref)); - } else { - fprintf(wc_tracelogf, "%spreference_update(NULL)\n", INDENT); - } + if (pref) { + fprintf(wc_tracelogf, "%spreference_update('%s'(%d))\n", INDENT, pref, + (int) strlen(pref)); + } else { + fprintf(wc_tracelogf, "%spreference_update(NULL)\n", INDENT); + } - PRE; - (*tdp->nprocs->win_preference_update)(tdp->ndata, pref); - POST; + PRE; + (*tdp->nprocs->win_preference_update)(tdp->ndata, pref); + POST; } - char * trace_getmsghistory(vp, init) - void *vp; +void *vp; boolean init; { - struct trace_data *tdp = vp; - char *rv; + struct trace_data *tdp = vp; + char *rv; - fprintf(wc_tracelogf, "%sgetmsghistory(%d)\n", INDENT, init); + fprintf(wc_tracelogf, "%sgetmsghistory(%d)\n", INDENT, init); - PRE; - rv = (*tdp->nprocs->win_getmsghistory)(tdp->ndata,init); - POST; + PRE; + rv = (*tdp->nprocs->win_getmsghistory)(tdp->ndata, init); + POST; - if(rv){ - fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv, (int)strlen(rv)); - } else { - fprintf(wc_tracelogf, "%s=> NULL\n", INDENT); - } + if (rv) { + fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv, + (int) strlen(rv)); + } else { + fprintf(wc_tracelogf, "%s=> NULL\n", INDENT); + } - return rv; + return rv; } void trace_putmsghistory(vp, msg, is_restoring) - void *vp; +void *vp; const char *msg; boolean is_restoring; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - if(msg){ - fprintf(wc_tracelogf, "%sputmsghistory('%s'(%d), %d)\n", INDENT, - msg, (int)strlen(msg), is_restoring); - } else { - fprintf(wc_tracelogf, "%sputmghistory(NULL, %d)\n", INDENT, is_restoring); - } + if (msg) { + fprintf(wc_tracelogf, "%sputmsghistory('%s'(%d), %d)\n", INDENT, msg, + (int) strlen(msg), is_restoring); + } else { + fprintf(wc_tracelogf, "%sputmghistory(NULL, %d)\n", INDENT, + is_restoring); + } - PRE; - (*tdp->nprocs->win_putmsghistory)(tdp->ndata, msg, is_restoring); - POST; + PRE; + (*tdp->nprocs->win_putmsghistory)(tdp->ndata, msg, is_restoring); + POST; } #ifdef STATUS_VIA_WINDOWPORT void trace_status_init(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstatus_init()\n", INDENT); + fprintf(wc_tracelogf, "%sstatus_init()\n", INDENT); - PRE; - (*tdp->nprocs->win_status_init)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_status_init)(tdp->ndata); + POST; } void trace_status_finish(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstatus_finish()\n", INDENT); + fprintf(wc_tracelogf, "%sstatus_finish()\n", INDENT); - PRE; - (*tdp->nprocs->win_status_finish)(tdp->ndata); - POST; + PRE; + (*tdp->nprocs->win_status_finish)(tdp->ndata); + POST; } void trace_status_enablefield(vp, fieldidx, nm, fmt, enable) - void *vp; +void *vp; int fieldidx; const char *nm; const char *fmt; boolean enable; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstatus_enablefield(%d, ", INDENT, fieldidx); - if(nm){ - fprintf(wc_tracelogf, "'%s'(%d), ", nm, (int)strlen(nm)); - } else { - fprintf(wc_tracelogf, "NULL, "); - } - if(fmt){ - fprintf(wc_tracelogf, "'%s'(%d), ", fmt, (int)strlen(fmt)); - } else { - fprintf(wc_tracelogf, "NULL, "); - } - fprintf(wc_tracelogf, "%d)\n", enable); + fprintf(wc_tracelogf, "%sstatus_enablefield(%d, ", INDENT, fieldidx); + if (nm) { + fprintf(wc_tracelogf, "'%s'(%d), ", nm, (int) strlen(nm)); + } else { + fprintf(wc_tracelogf, "NULL, "); + } + if (fmt) { + fprintf(wc_tracelogf, "'%s'(%d), ", fmt, (int) strlen(fmt)); + } else { + fprintf(wc_tracelogf, "NULL, "); + } + fprintf(wc_tracelogf, "%d)\n", enable); - PRE; - (*tdp->nprocs->win_status_enablefield)(tdp->ndata, fieldidx, nm, - fmt, enable); - POST; + PRE; + (*tdp->nprocs->win_status_enablefield)(tdp->ndata, fieldidx, nm, fmt, + enable); + POST; } void trace_status_update(vp, idx, ptr, chg, percent) - void *vp; +void *vp; int idx, chg, percent; genericptr_t ptr; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - fprintf(wc_tracelogf, "%sstatus_update(%d, %p, %d, %d)\n", INDENT, idx, ptr, chg, - percent); + fprintf(wc_tracelogf, "%sstatus_update(%d, %p, %d, %d)\n", INDENT, idx, + ptr, chg, percent); - PRE; - (*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent); - POST; + PRE; + (*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent); + POST; } -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES void -trace_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, under, over) - void *vp; -int fldidx,thresholdtype; +trace_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, under, + over) +void *vp; +int fldidx, thresholdtype; int behavior, under, over; anything threshold; { - struct trace_data *tdp = vp; + struct trace_data *tdp = vp; - /* XXX how do we print an anything? We don't. */ - fprintf(wc_tracelogf, "%sstatus_threshold(%d, %d, -, %d, %d, %d)\n", INDENT, - fldidx, thresholdtype, behavior, under, over); + /* XXX how do we print an anything? We don't. */ + fprintf(wc_tracelogf, "%sstatus_threshold(%d, %d, -, %d, %d, %d)\n", + INDENT, fldidx, thresholdtype, behavior, under, over); - PRE; - (*tdp->nprocs->win_status_threshold)(tdp->ndata,fldidx, thresholdtype, - threshold, behavior, under, over); - POST; + PRE; + (*tdp->nprocs->win_status_threshold)(tdp->ndata, fldidx, thresholdtype, + threshold, behavior, under, over); + POST; } -# endif +#endif #endif boolean trace_can_suspend(vp) - void *vp; +void *vp; { - struct trace_data *tdp = vp; - boolean rv; + struct trace_data *tdp = vp; + boolean rv; - fprintf(wc_tracelogf, "%scan_suspend()\n", INDENT); + fprintf(wc_tracelogf, "%scan_suspend()\n", INDENT); - PRE; - rv = (*tdp->nprocs->win_can_suspend)(tdp->ndata); - POST; + PRE; + rv = (*tdp->nprocs->win_can_suspend)(tdp->ndata); + POST; - fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); + fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv); - return rv; + return rv; } struct chain_procs trace_procs = { - "+trace", - 0, /* wincap */ - 0, /* wincap2 */ -/* -XXX problem - the above need to come from the real window port, possibly -modified. May need to do something to call an additional init fn later -or if this is the only place like this the choose_windows fn can do the fixup -(but not if the value can be modified by the stack?) TBD -*/ + "+trace", 0, /* wincap */ + 0, /* wincap2 */ + /* + XXX problem - the above need to come from the real window port, possibly + modified. May need to do something to call an additional init fn later + or if this is the only place like this the choose_windows fn can do the + fixup + (but not if the value can be modified by the stack?) TBD + */ trace_init_nhwindows, - trace_player_selection, - trace_askname, - trace_get_nh_event, - trace_exit_nhwindows, - trace_suspend_nhwindows, - trace_resume_nhwindows, - trace_create_nhwindow, - trace_clear_nhwindow, - trace_display_nhwindow, - trace_destroy_nhwindow, - trace_curs, - trace_putstr, - trace_putmixed, - trace_display_file, - trace_start_menu, - trace_add_menu, - trace_end_menu, - trace_select_menu, - trace_message_menu, - trace_update_inventory, - trace_mark_synch, - trace_wait_synch, + trace_player_selection, trace_askname, trace_get_nh_event, + trace_exit_nhwindows, trace_suspend_nhwindows, trace_resume_nhwindows, + trace_create_nhwindow, trace_clear_nhwindow, trace_display_nhwindow, + trace_destroy_nhwindow, trace_curs, trace_putstr, trace_putmixed, + trace_display_file, trace_start_menu, trace_add_menu, trace_end_menu, + trace_select_menu, trace_message_menu, trace_update_inventory, + trace_mark_synch, trace_wait_synch, #ifdef CLIPPING trace_cliparound, #endif #ifdef POSITIONBAR trace_update_positionbar, #endif - trace_print_glyph, - trace_raw_print, - trace_raw_print_bold, - trace_nhgetch, - trace_nh_poskey, - trace_nhbell, - trace_doprev_message, - trace_yn_function, - trace_getlin, - trace_get_ext_cmd, - trace_number_pad, - trace_delay_output, + trace_print_glyph, trace_raw_print, trace_raw_print_bold, trace_nhgetch, + trace_nh_poskey, trace_nhbell, trace_doprev_message, trace_yn_function, + trace_getlin, trace_get_ext_cmd, trace_number_pad, trace_delay_output, #ifdef CHANGE_COLOR trace_change_color, #ifdef MAC - trace_change_background, - trace_set_font_name, + trace_change_background, trace_set_font_name, #endif trace_get_color_string, #endif - trace_start_screen, - trace_end_screen, + trace_start_screen, trace_end_screen, - trace_outrip, - trace_preference_update, - trace_getmsghistory, + trace_outrip, trace_preference_update, trace_getmsghistory, trace_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - trace_status_init, - trace_status_finish, - trace_status_enablefield, + trace_status_init, trace_status_finish, trace_status_enablefield, trace_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES trace_status_threshold, -# endif +#endif #endif trace_can_suspend, }; diff --git a/win/gem/bitmfile.c b/win/gem/bitmfile.c index fe6ccf5f4..a688a4332 100644 --- a/win/gem/bitmfile.c +++ b/win/gem/bitmfile.c @@ -8,7 +8,7 @@ * -> Programmcode * \****************************/ /* - * $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ + * $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $ * $Date: 2002/01/05 21:06:00 $ $Revision: 1.1 $ */ @@ -24,321 +24,316 @@ #define IMG_COMPRESSED -typedef struct - { - UWORD img_version; - UWORD img_headlen; - UWORD img_nplanes; - UWORD img_patlen; - UWORD img_pixw; - UWORD img_pixh; - UWORD img_w; - UWORD img_h; - } IMG_HEADER; +typedef struct { + UWORD img_version; + UWORD img_headlen; + UWORD img_nplanes; + UWORD img_patlen; + UWORD img_pixw; + UWORD img_pixh; + UWORD img_w; + UWORD img_h; +} IMG_HEADER; -typedef enum {NONE, SOLID0, SOLID1, PATRUN, BITSTR} IMG_MODE; +typedef enum { NONE, SOLID0, SOLID1, PATRUN, BITSTR } IMG_MODE; typedef UBYTE IMG_SOLID; -typedef enum { RGB=0, CMY=1, Pantone=2 } XIMG_COLMODEL; +typedef enum { RGB = 0, CMY = 1, Pantone = 2 } XIMG_COLMODEL; -typedef struct - { - ULONG img_ximg; - XIMG_COLMODEL img_colmodel; - } XIMG_HEADER; +typedef struct { + ULONG img_ximg; + XIMG_COLMODEL img_colmodel; +} XIMG_HEADER; typedef struct RGB XIMG_RGB; +int +bitmap_to_img(FILE_TYP typ, int ww, int wh, unsigned int pixw, + unsigned int pixh, unsigned int planes, unsigned int colors, + const char *filename, + void (*get_color)(unsigned int colind, struct RGB *rgb), + void (*get_pixel)(int x, int y, unsigned int *colind)) +{ + int file, error, cnt; + IMG_HEADER header; + XIMG_HEADER xheader; + XIMG_RGB xrgb; + IMG_MODE mode; + UBYTE *line_buf, *write_buf; + register UBYTE *startpnt, *bufpnt; + unsigned int colind, line_len, line, bit; + register unsigned int byte; + register UBYTE count; -int bitmap_to_img(FILE_TYP typ, int ww, int wh, - unsigned int pixw, unsigned int pixh, - unsigned int planes, unsigned int colors, - const char *filename, - void(*get_color)(unsigned int colind, struct RGB *rgb), - void(*get_pixel)(int x, int y, unsigned int *colind) ) - { - int file, error, cnt; - IMG_HEADER header; - XIMG_HEADER xheader; - XIMG_RGB xrgb; - IMG_MODE mode; - UBYTE *line_buf, *write_buf; - register UBYTE *startpnt, *bufpnt; - unsigned int colind, line_len, line, bit; - register unsigned int byte; - register UBYTE count; + /* fill in (X) IMG-Header */ - /* fill in (X) IMG-Header */ + header.img_version = 1; + header.img_headlen = (UWORD) sizeof(header) / 2; + if (typ == XIMG) + header.img_headlen += + (UWORD)(sizeof(xheader) + colors * sizeof(xrgb)) / 2; - header.img_version = 1; - header.img_headlen = (UWORD) sizeof(header) /2; - if (typ == XIMG) - header.img_headlen += (UWORD)(sizeof(xheader)+colors*sizeof(xrgb))/2; + header.img_nplanes = planes; + header.img_patlen = 2; + header.img_pixw = pixw; + header.img_pixh = pixh; + header.img_w = ww; + header.img_h = wh; - header.img_nplanes = planes; - header.img_patlen = 2; - header.img_pixw = pixw; - header.img_pixh = pixh; - header.img_w = ww; - header.img_h = wh; + xheader.img_ximg = XIMG_MAGIC; + xheader.img_colmodel = RGB; - xheader.img_ximg = XIMG_MAGIC; - xheader.img_colmodel= RGB; + /* calculate linelength, allocate buffer. */ - /* calculate linelength, allocate buffer. */ + line_len = (ww + 7) / 8; - line_len = (ww+7)/8; + line_buf = malloc((size_t) planes * line_len); + if (line_buf == NULL) + return (ENOMEM); - line_buf = malloc((size_t)planes*line_len); - if (line_buf == NULL) - return(ENOMEM); + /* Worst case: the bufferd line could grow to max. 3 times the length */ + /* of the original! + */ - /* Worst case: the bufferd line could grow to max. 3 times the length */ - /* of the original! */ + write_buf = malloc((size_t) 3 * line_len); + if (write_buf == NULL) { + free(line_buf); + return (ENOMEM); + }; - write_buf = malloc((size_t)3*line_len); - if (write_buf == NULL) - { - free(line_buf); - return(ENOMEM); - }; + /* open file */ - /* open file */ + file = open(filename, O_WRONLY | O_CREAT | O_TRUNC); + if (file < 0) { + error = errno; + free(line_buf); + free(write_buf); + return (error); + }; - file = open(filename, O_WRONLY | O_CREAT | O_TRUNC); - if (file<0) - { - error = errno; - free(line_buf); - free(write_buf); - return(error); - }; + /* write Header */ - /* write Header */ + if (write(file, &header, sizeof(header)) != sizeof(header) + || (typ == XIMG + && write(file, &xheader, sizeof(xheader)) != sizeof(xheader))) { + error = errno; + close(file); + free(line_buf); + free(write_buf); + return (error); + }; - if (write (file, &header, sizeof(header)) != sizeof(header) || - (typ == XIMG && write (file, &xheader, sizeof(xheader) ) != sizeof(xheader))) - { - error = errno; - close(file); - free(line_buf); - free(write_buf); - return(error); - }; + /* save the colortable if possible */ - /* save the colortable if possible */ + if (typ == XIMG) + for (cnt = 0; cnt < colors; cnt++) { + get_color(cnt, &xrgb); + if (write(file, &xrgb, sizeof(xrgb)) != sizeof(xrgb)) { + error = errno; + close(file); + free(line_buf); + free(write_buf); + return (error); + }; + }; - if ( typ == XIMG ) - for (cnt=0; cnt>= 1; + }; + }; + }; - for (cnt=0; cnt>= 1; - }; - }; - }; + /* compress bitstrings in buffer */ + /* and write it to file */ - /* compress bitstrings in buffer */ - /* and write it to file */ + for (cnt = 0; cnt < planes; cnt++) { + /* Bitstringpointer to start of plane */ - for (cnt=0; cnt 0; count--) + *(bufpnt++) = *(startpnt++); + break; + }; + }; - case BITSTR: - *(bufpnt++) = 0x80; - while ( !(((startpnt+count)<&line_buf[(cnt+1)*line_len-1])&& - (((*(startpnt+count)==0xFF) && (*(startpnt+count+1)==0xFF))|| - ((*(startpnt+count)==0x00) && (*(startpnt+count+1)==0x00)))) && - !(((startpnt+count)<&line_buf[(cnt+1)*line_len-5])&& - (*(startpnt+count) == *(startpnt+count+2))&& - (*(startpnt+count+1) == *(startpnt+count+3))&& - (*(startpnt+count) == *(startpnt+count+4))&& - (*(startpnt+count+1) == *(startpnt+count+5))) && - (count < 0xFF) && - ((startpnt+count) < &line_buf[(cnt+1)*line_len]) ) - count++; - *(bufpnt++) = count; - for(; count>0; count--) - *(bufpnt++) = *(startpnt++); - break; - }; - }; + if (write(file, write_buf, bufpnt - write_buf) + != (bufpnt - write_buf)) { + error = errno; + close(file); + free(line_buf); + free(write_buf); + return (error); + }; + }; + }; - if (write(file,write_buf,bufpnt-write_buf) != (bufpnt-write_buf)) - { - error = errno; - close(file); - free(line_buf); - free(write_buf); - return(error); - }; - - }; - }; - - /*close file, free buffer. */ - - close(file); - free(line_buf); - free(write_buf); - return(0); + /*close file, free buffer. */ + close(file); + free(line_buf); + free(write_buf); + return (0); } /*---filetype-dispatcher--------------------*/ -const char *get_file_ext(FILE_TYP typ) - { - switch (typ) - { - case IMG: - case XIMG: - return("IMG"); - default: - return(""); - }; +const char * +get_file_ext(FILE_TYP typ) +{ + switch (typ) { + case IMG: + case XIMG: + return ("IMG"); + default: + return (""); + }; } - -int bitmap_to_file(FILE_TYP typ, int ww, int wh, - unsigned int pwx, unsigned int pwy, - unsigned int planes, unsigned int colors, - const char *filename, - void (*get_color)(unsigned int colind, struct RGB *rgb), - void (*get_pixel)(int x, int y, unsigned int *colind)) - { - - switch (typ) - { - case IMG: - case XIMG: - return(bitmap_to_img(typ,ww,wh,pwx,pwy,planes,colors,filename,get_color,get_pixel)); - default: - return(-1); - }; +int +bitmap_to_file(FILE_TYP typ, int ww, int wh, unsigned int pwx, + unsigned int pwy, unsigned int planes, unsigned int colors, + const char *filename, + void (*get_color)(unsigned int colind, struct RGB *rgb), + void (*get_pixel)(int x, int y, unsigned int *colind)) +{ + switch (typ) { + case IMG: + case XIMG: + return (bitmap_to_img(typ, ww, wh, pwx, pwy, planes, colors, filename, + get_color, get_pixel)); + default: + return (-1); + }; } - diff --git a/win/gem/gr_rect.c b/win/gem/gr_rect.c index 6c52da571..8b7e5cfa2 100644 --- a/win/gem/gr_rect.c +++ b/win/gem/gr_rect.c @@ -1,7 +1,8 @@ -/* NetHack 3.6 gr_rect.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gr_rect.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 gr_rect.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.3 $ */ -/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10 */ -/* Copyright (c) Christian Bressler, 2001 */ +/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10 + */ +/* Copyright (c) Christian Bressler, 2001 */ /* NetHack may be freely redistributed. See license for details. */ /* This is an almost exact copy of qt_clust.cpp */ /* gr_rect.c */ @@ -9,175 +10,197 @@ #include #include #include "gr_rect.h" -dirty_rect *new_dirty_rect(int size){ - dirty_rect *new=NULL; - if(size>0){ - new=(dirty_rect *)calloc(1L,sizeof(dirty_rect)); - if(new){ - new->rects=(GRECT *)calloc((long)size,sizeof(GRECT)); - if(new->rects==NULL){ - free(new); - return(NULL); - } - new->max=size; - } - } - return(new); +dirty_rect * +new_dirty_rect(int size) +{ + dirty_rect *new = NULL; + if (size > 0) { + new = (dirty_rect *) calloc(1L, sizeof(dirty_rect)); + if (new) { + new->rects = (GRECT *) calloc((long) size, sizeof(GRECT)); + if (new->rects == NULL) { + free(new); + return (NULL); + } + new->max = size; + } + } + return (new); } -void delete_dirty_rect(dirty_rect *this){ - if(this==NULL) - return; - if(this->rects) - free(this->rects); - /* In case the Pointer is reused wrongly */ - this->rects=NULL; - this->max=0; - this->used=0; - free(this); +void +delete_dirty_rect(dirty_rect *this) +{ + if (this == NULL) + return; + if (this->rects) + free(this->rects); + /* In case the Pointer is reused wrongly */ + this->rects = NULL; + this->max = 0; + this->used = 0; + free(this); } -static int gc_inside(GRECT *frame,GRECT *test); -static int gc_touch(GRECT *frame,GRECT *test); -static void gc_combine(GRECT *frame,GRECT *test); +static int gc_inside(GRECT *frame, GRECT *test); +static int gc_touch(GRECT *frame, GRECT *test); +static void gc_combine(GRECT *frame, GRECT *test); static long gc_area(GRECT *area); -int add_dirty_rect(dirty_rect *dr,GRECT *area){ - int cursor; - long lowestcost=9999999L; - int cheapest=-1; - int cheapestmerge1=-1; - int cheapestmerge2=-1; - int merge1; - int merge2; - for (cursor=0; cursorused; cursor++) { - if (gc_inside(&dr->rects[cursor],area)) { - /* Wholly contained already. */ - return(TRUE); - } - } - for (cursor=0; cursorused; cursor++) { - if (gc_touch(&dr->rects[cursor],area)) { - GRECT larger=dr->rects[cursor]; - long cost; - gc_combine(&larger,area); - cost=gc_area(&larger)-gc_area(&dr->rects[cursor]); - if (cost < lowestcost) { - int bad=FALSE,c; - for (c=0; cused && !bad; c++) { - bad=gc_touch(&dr->rects[c],&larger) && c!=cursor; - } - if (!bad) { - cheapest=cursor; - lowestcost=cost; - } - } - } - } - if (cheapest>=0) { - gc_combine(&dr->rects[cheapest],area); - return(TRUE); - } - if (dr->used < dr->max) { - dr->rects[dr->used++]=*area; - return(TRUE); - } - // Do cheapest of: - // add to closest cluster - // do cheapest cluster merge, add to new cluster - lowestcost=9999999L; - cheapest=-1; - for (cursor=0; cursorused; cursor++) { - GRECT larger=dr->rects[cursor]; - long cost; - gc_combine(&larger,area); - cost=gc_area(&larger)-gc_area(&dr->rects[cursor]); - if (cost < lowestcost) { - int bad=FALSE, c; - for (c=0; cused && !bad; c++) { - bad=gc_touch(&dr->rects[c],&larger) && c!=cursor; - } - if (!bad) { - cheapest=cursor; - lowestcost=cost; - } - } - } - // XXX could make an heuristic guess as to whether we - // XXX need to bother looking for a cheap merge. - for (merge1=0; merge1used; merge1++) { - for (merge2=0; merge2used; merge2++) { - if (merge1!=merge2) { - GRECT larger=dr->rects[merge1]; - long cost; - gc_combine(&larger,&dr->rects[merge2]); - cost=gc_area(&larger)-gc_area(&dr->rects[merge1])-gc_area(&dr->rects[merge2]); - if (cost < lowestcost) { - int bad=FALSE, c; - for (c=0; cused && !bad; c++) { - bad=gc_touch(&dr->rects[c],&larger) && c!=cursor; - } - if (!bad) { - cheapestmerge1=merge1; - cheapestmerge2=merge2; - lowestcost=cost; - } - } - } - } - } - if (cheapestmerge1>=0) { - gc_combine(&dr->rects[cheapestmerge1],&dr->rects[cheapestmerge2]); - dr->rects[cheapestmerge2]=dr->rects[dr->used-1]; - dr->rects[dr->used-1]=*area; - } else { - gc_combine(&dr->rects[cheapest],area); - } - // NB: clusters do not intersect (or intersection will - // overwrite). This is a result of the above algorithm, - // given the assumption that (x,y) are ordered topleft - // to bottomright. - return(TRUE); +int +add_dirty_rect(dirty_rect *dr, GRECT *area) +{ + int cursor; + long lowestcost = 9999999L; + int cheapest = -1; + int cheapestmerge1 = -1; + int cheapestmerge2 = -1; + int merge1; + int merge2; + for (cursor = 0; cursor < dr->used; cursor++) { + if (gc_inside(&dr->rects[cursor], area)) { + /* Wholly contained already. */ + return (TRUE); + } + } + for (cursor = 0; cursor < dr->used; cursor++) { + if (gc_touch(&dr->rects[cursor], area)) { + GRECT larger = dr->rects[cursor]; + long cost; + gc_combine(&larger, area); + cost = gc_area(&larger) - gc_area(&dr->rects[cursor]); + if (cost < lowestcost) { + int bad = FALSE, c; + for (c = 0; c < dr->used && !bad; c++) { + bad = gc_touch(&dr->rects[c], &larger) && c != cursor; + } + if (!bad) { + cheapest = cursor; + lowestcost = cost; + } + } + } + } + if (cheapest >= 0) { + gc_combine(&dr->rects[cheapest], area); + return (TRUE); + } + if (dr->used < dr->max) { + dr->rects[dr->used++] = *area; + return (TRUE); + } + // Do cheapest of: + // add to closest cluster + // do cheapest cluster merge, add to new cluster + lowestcost = 9999999L; + cheapest = -1; + for (cursor = 0; cursor < dr->used; cursor++) { + GRECT larger = dr->rects[cursor]; + long cost; + gc_combine(&larger, area); + cost = gc_area(&larger) - gc_area(&dr->rects[cursor]); + if (cost < lowestcost) { + int bad = FALSE, c; + for (c = 0; c < dr->used && !bad; c++) { + bad = gc_touch(&dr->rects[c], &larger) && c != cursor; + } + if (!bad) { + cheapest = cursor; + lowestcost = cost; + } + } + } + // XXX could make an heuristic guess as to whether we + // XXX need to bother looking for a cheap merge. + for (merge1 = 0; merge1 < dr->used; merge1++) { + for (merge2 = 0; merge2 < dr->used; merge2++) { + if (merge1 != merge2) { + GRECT larger = dr->rects[merge1]; + long cost; + gc_combine(&larger, &dr->rects[merge2]); + cost = gc_area(&larger) - gc_area(&dr->rects[merge1]) + - gc_area(&dr->rects[merge2]); + if (cost < lowestcost) { + int bad = FALSE, c; + for (c = 0; c < dr->used && !bad; c++) { + bad = gc_touch(&dr->rects[c], &larger) && c != cursor; + } + if (!bad) { + cheapestmerge1 = merge1; + cheapestmerge2 = merge2; + lowestcost = cost; + } + } + } + } + } + if (cheapestmerge1 >= 0) { + gc_combine(&dr->rects[cheapestmerge1], &dr->rects[cheapestmerge2]); + dr->rects[cheapestmerge2] = dr->rects[dr->used - 1]; + dr->rects[dr->used - 1] = *area; + } else { + gc_combine(&dr->rects[cheapest], area); + } + // NB: clusters do not intersect (or intersection will + // overwrite). This is a result of the above algorithm, + // given the assumption that (x,y) are ordered topleft + // to bottomright. + return (TRUE); } -int get_dirty_rect(dirty_rect* dr,GRECT *area){ - if(dr==NULL || area==NULL || dr->rects==NULL || dr->used<=0 || dr->max<=0) - return(FALSE); - *area=dr->rects[--dr->used]; - return(TRUE); +int +get_dirty_rect(dirty_rect *dr, GRECT *area) +{ + if (dr == NULL || area == NULL || dr->rects == NULL || dr->used <= 0 + || dr->max <= 0) + return (FALSE); + *area = dr->rects[--dr->used]; + return (TRUE); } -int clear_dirty_rect(dirty_rect *dr){ - if(dr) - dr->used=0; - return(TRUE); +int +clear_dirty_rect(dirty_rect *dr) +{ + if (dr) + dr->used = 0; + return (TRUE); } -int resize_dirty_rect(dirty_rect *dr,int new_size){ - return(FALSE); +int +resize_dirty_rect(dirty_rect *dr, int new_size) +{ + return (FALSE); } -static int gc_inside(GRECT *frame,GRECT *test){ - if(frame && test && frame->g_x<=test->g_x && frame->g_y<=test->g_y && - frame->g_x+frame->g_w>=test->g_x+test->g_w && - frame->g_y+frame->g_h>=test->g_y+test->g_h - ) - return(TRUE); - return(FALSE); +static int +gc_inside(GRECT *frame, GRECT *test) +{ + if (frame && test && frame->g_x <= test->g_x && frame->g_y <= test->g_y + && frame->g_x + frame->g_w >= test->g_x + test->g_w + && frame->g_y + frame->g_h >= test->g_y + test->g_h) + return (TRUE); + return (FALSE); } -static int gc_touch(GRECT *frame,GRECT *test){ - GRECT tmp={test->g_x-1,test->g_y-1,test->g_w+2,test->g_h+2}; - return(rc_intersect(frame,&tmp)); +static int +gc_touch(GRECT *frame, GRECT *test) +{ + GRECT tmp = { test->g_x - 1, test->g_y - 1, test->g_w + 2, + test->g_h + 2 }; + return (rc_intersect(frame, &tmp)); } -static void gc_combine(GRECT *frame,GRECT *test){ - if(!frame || !test) - return; - if(frame->g_x>test->g_x){ - frame->g_w+=frame->g_x-test->g_x; - frame->g_x=test->g_x; - } - if(frame->g_y>test->g_y){ - frame->g_h+=frame->g_y-test->g_y; - frame->g_y=test->g_y; - } - if(frame->g_x+frame->g_wg_x+test->g_w) - frame->g_w=test->g_x+test->g_w-frame->g_x; - if(frame->g_y+frame->g_hg_y+test->g_h) - frame->g_h=test->g_y+test->g_h-frame->g_y; +static void +gc_combine(GRECT *frame, GRECT *test) +{ + if (!frame || !test) + return; + if (frame->g_x > test->g_x) { + frame->g_w += frame->g_x - test->g_x; + frame->g_x = test->g_x; + } + if (frame->g_y > test->g_y) { + frame->g_h += frame->g_y - test->g_y; + frame->g_y = test->g_y; + } + if (frame->g_x + frame->g_w < test->g_x + test->g_w) + frame->g_w = test->g_x + test->g_w - frame->g_x; + if (frame->g_y + frame->g_h < test->g_y + test->g_h) + frame->g_h = test->g_y + test->g_h - frame->g_y; } -static long gc_area(GRECT *area){ - return((long)area->g_h*(long)area->g_w); +static long +gc_area(GRECT *area) +{ + return ((long) area->g_h * (long) area->g_w); } diff --git a/win/gem/load_img.c b/win/gem/load_img.c index fe995d6f5..cd793bff2 100644 --- a/win/gem/load_img.c +++ b/win/gem/load_img.c @@ -1,5 +1,5 @@ /* - * $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ + * $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ * $Date: 2002/03/20 03:45:03 $ $Revision: 1.2 $ */ #define __TCC_COMPAT__ @@ -15,279 +15,308 @@ #ifndef FALSE #define FALSE 0 -#define TRUE !FALSE +#define TRUE !FALSE #endif /* VDI <-> Device palette order conversion matrixes: */ /* Four-plane vdi-device */ -int vdi2dev4[]={0,15,1,2,4,6,3,5,7,8,9,10,12,14,11,13}; +int vdi2dev4[] = { 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 }; /* Two-plane vdi-device */ -int vdi2dev2[]={0,3,1,2}; +int vdi2dev2[] = { 0, 3, 1, 2 }; -void get_colors(int handle, short *palette, int col){ - int i, idx; +void +get_colors(int handle, short *palette, int col) +{ + int i, idx; - /* get current color palette */ - for(i=0; i < col; i ++){ - /* device->vdi->device palette order */ - switch(planes){ - case 1: - idx=i;break; - case 2: - idx=vdi2dev2[i];break; - case 4: - idx=vdi2dev4[i];break; - default: - if(i<16) - idx=vdi2dev4[i]; - else - idx= i==255 ? 1 : i; - } - vq_color(handle, i, 0, (int *)palette + idx * 3); - } -} - -void img_set_colors(int handle, short *palette, int col){ - int i, idx, end; - - /* set color palette */ - end=min(1<vdi->device palette order */ + switch (planes) { + case 1: + idx = i; + break; + case 2: + idx = vdi2dev2[i]; + break; + case 4: + idx = vdi2dev4[i]; + break; + default: + if (i < 16) + idx = vdi2dev4[i]; + else + idx = i == 255 ? 1 : i; + } + vq_color(handle, i, 0, (int *) palette + idx * 3); } - vs_color(handle, i, (int *)palette + idx * 3); - } } -int convert(MFDB *image, long size){ - int plane, mplanes; - char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr, *screen_addr; - MFDB dev_form, tmp; - long new_size; +void +img_set_colors(int handle, short *palette, int col) +{ + int i, idx, end; - /* convert size from words to bytes */ - size <<= 1; - - /* memory for the device raster */ - new_size=size*(long)planes; - if((new_addr=(char *) calloc(1,new_size)) == NULL) - return(FALSE); - - /* initialize MFDBs */ - tmp=*image; - tmp.fd_nplanes=planes; - tmp.fd_addr=new_addr; - tmp.fd_stand=1; /* standard format */ - dev_form=tmp; - screen_addr=new_addr; - dev_form.fd_stand=0; /* device format */ - image_addr=(char *)image->fd_addr; - - /* initialize some variables and zero temp. line buffer */ - mplanes=min(image->fd_nplanes, planes); - /* convert image */ - line_addr=image_addr; - buf_addr=screen_addr; - if(mplanes>1){ - /* cut/pad color planes into temp buf */ - for(plane=0; planefd_addr); - /* convert image line in temp into current device raster format */ - if((new1_addr=(char *) calloc(1,new_size)) == NULL) - return(FALSE); - dev_form.fd_addr=new1_addr; - vr_trnfm(x_handle, &tmp, &dev_form); - free(new_addr); - - /* change image description */ - image->fd_stand=0; /* device format */ - image->fd_addr=new1_addr; - image->fd_nplanes=planes; - return(TRUE); + /* set color palette */ + end = min(1 << col, 1 << planes); + for (i = 0; i < end; i++) { + switch (planes) { /* MAR -- war col 10.01.2001 */ + case 1: + idx = i; + break; + case 2: + idx = vdi2dev2[i]; + break; + case 4: + idx = vdi2dev4[i]; + break; + default: + if (i < 16) + idx = vdi2dev4[i]; + else + idx = i == 255 ? 1 : i; + } + vs_color(handle, i, (int *) palette + idx * 3); + } } -int transform_img(MFDB *image){ /* return FALSE if transform_img fails */ - int success; - long size; +int +convert(MFDB *image, long size) +{ + int plane, mplanes; + char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr, + *screen_addr; + MFDB dev_form, tmp; + long new_size; - if(!image->fd_addr) - return(FALSE); + /* convert size from words to bytes */ + size <<= 1; - size=(long)((long)image->fd_wdwidth * (long)image->fd_h); - success=convert(image, size); /* Use vr_trfm(), which needs quite a lot memory. */ - if(success) return(TRUE); -/* else show_error(ERR_ALLOC); */ - return(FALSE); + /* memory for the device raster */ + new_size = size * (long) planes; + if ((new_addr = (char *) calloc(1, new_size)) == NULL) + return (FALSE); + + /* initialize MFDBs */ + tmp = *image; + tmp.fd_nplanes = planes; + tmp.fd_addr = new_addr; + tmp.fd_stand = 1; /* standard format */ + dev_form = tmp; + screen_addr = new_addr; + dev_form.fd_stand = 0; /* device format */ + image_addr = (char *) image->fd_addr; + + /* initialize some variables and zero temp. line buffer */ + mplanes = min(image->fd_nplanes, planes); + /* convert image */ + line_addr = image_addr; + buf_addr = screen_addr; + if (mplanes > 1) { + /* cut/pad color planes into temp buf */ + for (plane = 0; plane < mplanes; plane++) { + memcpy(buf_addr, line_addr, size); + line_addr += size; + buf_addr += size; + } + } else { + /* fill temp line bitplanes with a b&w line */ + for (plane = 0; plane < planes; plane++) { + memcpy(buf_addr, line_addr, size); + buf_addr += size; + } + } + free(image->fd_addr); + /* convert image line in temp into current device raster format */ + if ((new1_addr = (char *) calloc(1, new_size)) == NULL) + return (FALSE); + dev_form.fd_addr = new1_addr; + vr_trnfm(x_handle, &tmp, &dev_form); + free(new_addr); + + /* change image description */ + image->fd_stand = 0; /* device format */ + image->fd_addr = new1_addr; + image->fd_nplanes = planes; + return (TRUE); } +int +transform_img(MFDB *image) +{ /* return FALSE if transform_img fails */ + int success; + long size; + + if (!image->fd_addr) + return (FALSE); + + size = (long) ((long) image->fd_wdwidth * (long) image->fd_h); + success = convert( + image, size); /* Use vr_trfm(), which needs quite a lot memory. */ + if (success) + return (TRUE); + /* else show_error(ERR_ALLOC); */ + return (FALSE); +} /* Loads & depacks IMG (0 if succeded, else error). */ /* Bitplanes are one after another in address IMG_HEADER.addr. */ -int depack_img(char *name, IMG_header *pic){ - int b, line, plane, width, word_aligned, opcode, patt_len, pal_size, - byte_repeat, patt_repeat, scan_repeat, error = FALSE; - char *pattern, *to, *endline, *puffer, sol_pat; - long size; - FILE *fp; +int +depack_img(char *name, IMG_header *pic) +{ + int b, line, plane, width, word_aligned, opcode, patt_len, pal_size, + byte_repeat, patt_repeat, scan_repeat, error = FALSE; + char *pattern, *to, *endline, *puffer, sol_pat; + long size; + FILE *fp; - if((fp = fopen(name, "rb")) == NULL) - return(ERR_FILE); + if ((fp = fopen(name, "rb")) == NULL) + return (ERR_FILE); - setvbuf(fp,NULL,_IOLBF,BUFSIZ); + setvbuf(fp, NULL, _IOLBF, BUFSIZ); - /* read header info (bw & ximg) into image structure */ - fread((char *)&(pic->version), 2, 8 + 3, fp); + /* read header info (bw & ximg) into image structure */ + fread((char *) &(pic->version), 2, 8 + 3, fp); - /* only 2-256 color imgs */ - if(pic->planes < 1 || pic->planes > 8){ - error = ERR_COLOR; - goto end_depack; - } + /* only 2-256 color imgs */ + if (pic->planes < 1 || pic->planes > 8) { + error = ERR_COLOR; + goto end_depack; + } - /* if XIMG, read info */ - if(pic->magic == XIMG && pic->paltype == 0){ - pal_size = (1 << pic->planes) * 3 * 2; - if((pic->palette = (short *)calloc(1,pal_size))){ - fread((char *)pic->palette, 1, pal_size, fp); - } - }else{ - pic->palette = NULL; - } + /* if XIMG, read info */ + if (pic->magic == XIMG && pic->paltype == 0) { + pal_size = (1 << pic->planes) * 3 * 2; + if ((pic->palette = (short *) calloc(1, pal_size))) { + fread((char *) pic->palette, 1, pal_size, fp); + } + } else { + pic->palette = NULL; + } - /* width in bytes word aliged */ - word_aligned = (pic->img_w + 15) >> 4; - word_aligned <<= 1; + /* width in bytes word aliged */ + word_aligned = (pic->img_w + 15) >> 4; + word_aligned <<= 1; - /* width byte aligned */ - width = (pic->img_w + 7) >> 3; + /* width byte aligned */ + width = (pic->img_w + 7) >> 3; - /* allocate memory for the picture */ - free(pic->addr); - size = (long)((long)word_aligned * (long)pic->img_h * (long)pic->planes); /*MAR*/ + /* allocate memory for the picture */ + free(pic->addr); + size = (long) ((long) word_aligned * (long) pic->img_h + * (long) pic->planes); /*MAR*/ - /* check for header validity & malloc long... */ - if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0 && pic->img_h > 0){ - if(!(pic->addr=(char *)calloc(1,size))){ - error = ERR_ALLOC; - goto end_depack; - } - }else{ - error = ERR_HEADER; - goto end_depack; - } + /* check for header validity & malloc long... */ + if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0 + && pic->img_h > 0) { + if (!(pic->addr = (char *) calloc(1, size))) { + error = ERR_ALLOC; + goto end_depack; + } + } else { + error = ERR_HEADER; + goto end_depack; + } - patt_len = pic->pat_len; + patt_len = pic->pat_len; - /* jump over the header and possible (XIMG) info */ - fseek(fp, (long) pic->length * 2L, SEEK_SET); + /* jump over the header and possible (XIMG) info */ + fseek(fp, (long) pic->length * 2L, SEEK_SET); - for(line=0,to=pic->addr; lineimg_h; line+=scan_repeat){ /* depack whole img */ - for(plane=0,scan_repeat=1; planeplanes; plane++){ /* depack one scan line */ - puffer=to=pic->addr+(long)(line+plane*pic->img_h)*(long)word_aligned; - endline=puffer+width; - do{ /* depack one line in one bitplane */ - switch((opcode= fgetc(fp))){ - case 0: /* pattern or scan repeat */ - if((patt_repeat=fgetc(fp))){ /* repeat a pattern */ - fread(to,patt_len,1,fp); - pattern=to; - to+=patt_len; - while(--patt_repeat){ /* copy pattern */ - memcpy(to,pattern,patt_len); - to+=patt_len; - } - }else{ /* repeat a line */ - if(fgetc(fp)==0xFF) - scan_repeat=fgetc(fp); - else{ - error = ERR_DEPACK; - goto end_depack; - } - } - break; - case 0x80: /* Literal */ - byte_repeat=fgetc(fp); - fread(to,byte_repeat,1,fp); - to+=byte_repeat; - break; - default: /* Solid run */ - byte_repeat = opcode & 0x7F; - sol_pat = opcode&0x80 ? 0xFF : 0x00; - while(byte_repeat--) *to++=sol_pat; - } - }while(toaddr; line < pic->img_h; + line += scan_repeat) { /* depack whole img */ + for (plane = 0, scan_repeat = 1; plane < pic->planes; + plane++) { /* depack one scan line */ + puffer = to = + pic->addr + + (long) (line + plane * pic->img_h) * (long) word_aligned; + endline = puffer + width; + do { /* depack one line in one bitplane */ + switch ((opcode = fgetc(fp))) { + case 0: /* pattern or scan repeat */ + if ((patt_repeat = fgetc(fp))) { /* repeat a pattern */ + fread(to, patt_len, 1, fp); + pattern = to; + to += patt_len; + while (--patt_repeat) { /* copy pattern */ + memcpy(to, pattern, patt_len); + to += patt_len; + } + } else { /* repeat a line */ + if (fgetc(fp) == 0xFF) + scan_repeat = fgetc(fp); + else { + error = ERR_DEPACK; + goto end_depack; + } + } + break; + case 0x80: /* Literal */ + byte_repeat = fgetc(fp); + fread(to, byte_repeat, 1, fp); + to += byte_repeat; + break; + default: /* Solid run */ + byte_repeat = opcode & 0x7F; + sol_pat = opcode & 0x80 ? 0xFF : 0x00; + while (byte_repeat--) + *to++ = sol_pat; + } + } while (to < endline); - if(to == endline){ - /* ensure that lines aren't repeated past the end of the img */ - if(line + scan_repeat > pic->img_h) - scan_repeat = pic->img_h - line; - /* copy line to image buffer */ - if(scan_repeat>1){ - /* calculate address of a current line in a current bitplane */ -/* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/ - for(b=scan_repeat-1; b; --b){ - memcpy(to, puffer, width); - to+=word_aligned; - } - } - }else{ - error = ERR_DEPACK; - goto end_depack; - } - } - } + if (to == endline) { + /* ensure that lines aren't repeated past the end of the img + */ + if (line + scan_repeat > pic->img_h) + scan_repeat = pic->img_h - line; + /* copy line to image buffer */ + if (scan_repeat > 1) { + /* calculate address of a current line in a current + * bitplane */ + /* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/ + for (b = scan_repeat - 1; b; --b) { + memcpy(to, puffer, width); + to += word_aligned; + } + } + } else { + error = ERR_DEPACK; + goto end_depack; + } + } + } - end_depack: - fclose(fp); - return(error); +end_depack: + fclose(fp); + return (error); } -int half_img(MFDB *s, MFDB *d){ - int pxy[8], i, j; - MFDB tmp; +int +half_img(MFDB *s, MFDB *d) +{ + int pxy[8], i, j; + MFDB tmp; - mfdb(&tmp,NULL,s->fd_w/2,s->fd_h,s->fd_stand,s->fd_nplanes); - tmp.fd_w=s->fd_w/2; - tmp.fd_addr=calloc(1,mfdb_size(&tmp)); - if(!tmp.fd_addr) - return(FALSE); + mfdb(&tmp, NULL, s->fd_w / 2, s->fd_h, s->fd_stand, s->fd_nplanes); + tmp.fd_w = s->fd_w / 2; + tmp.fd_addr = calloc(1, mfdb_size(&tmp)); + if (!tmp.fd_addr) + return (FALSE); - pxy[1]=pxy[5]=0; - pxy[3]=pxy[7]=s->fd_h-1; - for(i=0;ifd_w/2;i++){ - pxy[0]=pxy[2]=2*i; - pxy[4]=pxy[6]=i; - vro_cpyfm(x_handle,S_ONLY,pxy,s,&tmp); - } - pxy[0]=pxy[4]=0; - pxy[2]=pxy[6]=s->fd_w/2-1; - for(j=0;jfd_h/2;j++){ - pxy[1]=pxy[3]=2*j; - pxy[5]=pxy[7]=j; - vro_cpyfm(x_handle,S_ONLY,pxy,&tmp,d); - } - free(tmp.fd_addr); - return(TRUE); + pxy[1] = pxy[5] = 0; + pxy[3] = pxy[7] = s->fd_h - 1; + for (i = 0; i < s->fd_w / 2; i++) { + pxy[0] = pxy[2] = 2 * i; + pxy[4] = pxy[6] = i; + vro_cpyfm(x_handle, S_ONLY, pxy, s, &tmp); + } + pxy[0] = pxy[4] = 0; + pxy[2] = pxy[6] = s->fd_w / 2 - 1; + for (j = 0; j < s->fd_h / 2; j++) { + pxy[1] = pxy[3] = 2 * j; + pxy[5] = pxy[7] = j; + vro_cpyfm(x_handle, S_ONLY, pxy, &tmp, d); + } + free(tmp.fd_addr); + return (TRUE); } diff --git a/win/gem/tile2img.c b/win/gem/tile2img.c index 090d15f35..683101f56 100644 --- a/win/gem/tile2img.c +++ b/win/gem/tile2img.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tile2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 tile2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* NetHack 3.6 tile2img.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.2 $ */ /* SCCS Id: @(#)tile2bmp.c 3.2 95/09/06 */ /* Copyright (c) NetHack PC Development Team 1995 */ @@ -18,16 +18,15 @@ #include "bitmfile.h" /* #define COLORS_IN_USE MAXCOLORMAPSIZE /* 256 colors */ -#define COLORS_IN_USE 16 /* 16 colors */ - +#define COLORS_IN_USE 16 /* 16 colors */ extern char *FDECL(tilename, (int, int)); -static void FDECL(build_ximgtile,(pixel (*)[TILE_X])); +static void FDECL(build_ximgtile, (pixel(*) [TILE_X])); void get_color(unsigned int colind, struct RGB *rgb); void get_pixel(int x, int y, unsigned int *colind); -#if COLORS_IN_USE==16 -#define MAX_X 320 /* 2 per byte, 4 bits per pixel */ +#if COLORS_IN_USE == 16 +#define MAX_X 320 /* 2 per byte, 4 bits per pixel */ #else #define MAX_X 640 #endif @@ -37,9 +36,9 @@ FILE *tibfile2; pixel tilepixels[TILE_Y][TILE_X]; -char *tilefiles[] = { "..\\win\\share\\monsters.txt", - "..\\win\\share\\objects.txt", - "..\\win\\share\\other.txt"}; +char *tilefiles[] = { "..\\win\\share\\monsters.txt", + "..\\win\\share\\objects.txt", + "..\\win\\share\\other.txt" }; unsigned int **Bild_daten; int num_colors = 0; @@ -48,7 +47,7 @@ int max_tiles_in_row = 40; int tiles_in_row; int filenum; int initflag; -int yoffset,xoffset; +int yoffset, xoffset; char bmpname[128]; FILE *fp; @@ -57,102 +56,106 @@ main(argc, argv) int argc; char *argv[]; { - int i; + int i; - if (argc != 2) { - Fprintf(stderr, "usage: tile2img outfile.img\n"); - exit(EXIT_FAILURE); - } else - strcpy(bmpname, argv[1]); + if (argc != 2) { + Fprintf(stderr, "usage: tile2img outfile.img\n"); + exit(EXIT_FAILURE); + } else + strcpy(bmpname, argv[1]); #ifdef OBSOLETE - bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); - if (bmpfile2 == (FILE *)0) { - Fprintf(stderr, "Unable to open output file %s\n", - NETHACK_PACKED_TILEFILE); - exit(EXIT_FAILURE); - } + bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); + if (bmpfile2 == (FILE *) 0) { + Fprintf(stderr, "Unable to open output file %s\n", + NETHACK_PACKED_TILEFILE); + exit(EXIT_FAILURE); + } #endif - tilecount = 0; - xoffset = yoffset = 0; - initflag = 0; - filenum = 0; - fp = fopen(bmpname,"wb"); - if (!fp) { - printf("Error creating tile file %s, aborting.\n",bmpname); - exit(1); - } - fclose(fp); + tilecount = 0; + xoffset = yoffset = 0; + initflag = 0; + filenum = 0; + fp = fopen(bmpname, "wb"); + if (!fp) { + printf("Error creating tile file %s, aborting.\n", bmpname); + exit(1); + } + fclose(fp); - Bild_daten=(unsigned int **)malloc(MAX_Y*sizeof(unsigned int *)); - for(i=0;i 62) { - Fprintf(stderr, "too many colors (%d)\n", num_colors); - exit(EXIT_FAILURE); - } - while (read_text_tile(tilepixels)) { - build_ximgtile(tilepixels); - tilecount++; - xoffset += TILE_X; - if (xoffset >= MAX_X) { - yoffset += TILE_Y; - xoffset = 0; - } - } - (void) fclose_text_file(); - ++filenum; - } - Fprintf(stderr, "Total of %d tiles in memory.\n",tilecount); + while (filenum < 3) { + if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { + Fprintf(stderr, "usage: tile2img (from the util directory)\n"); + exit(EXIT_FAILURE); + } + num_colors = colorsinmap; + if (num_colors > 62) { + Fprintf(stderr, "too many colors (%d)\n", num_colors); + exit(EXIT_FAILURE); + } + while (read_text_tile(tilepixels)) { + build_ximgtile(tilepixels); + tilecount++; + xoffset += TILE_X; + if (xoffset >= MAX_X) { + yoffset += TILE_Y; + xoffset = 0; + } + } + (void) fclose_text_file(); + ++filenum; + } + Fprintf(stderr, "Total of %d tiles in memory.\n", tilecount); - bitmap_to_file(XIMG, MAX_X, (tilecount/20+1)*16, 372, 372, 4, 16, bmpname, get_color, get_pixel ) ; + bitmap_to_file(XIMG, MAX_X, (tilecount / 20 + 1) * 16, 372, 372, 4, 16, + bmpname, get_color, get_pixel); - Fprintf(stderr, "Total of %d tiles written to %s.\n",tilecount, bmpname); + Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } -void get_color(unsigned int colind, struct RGB *rgb){ - rgb->r=(1000L*(long)ColorMap[CM_RED][colind])/0xFF; - rgb->g=(1000L*(long)ColorMap[CM_GREEN][colind])/0xFF; - rgb->b=(1000L*(long)ColorMap[CM_BLUE][colind])/0xFF; +void +get_color(unsigned int colind, struct RGB *rgb) +{ + rgb->r = (1000L * (long) ColorMap[CM_RED][colind]) / 0xFF; + rgb->g = (1000L * (long) ColorMap[CM_GREEN][colind]) / 0xFF; + rgb->b = (1000L * (long) ColorMap[CM_BLUE][colind]) / 0xFF; } -void get_pixel(int x, int y, unsigned int *colind){ - *colind=Bild_daten[y][x]; +void +get_pixel(int x, int y, unsigned int *colind) +{ + *colind = Bild_daten[y][x]; } static void build_ximgtile(pixels) pixel (*pixels)[TILE_X]; { - int cur_x, cur_y, cur_color; - int x,y; + int cur_x, cur_y, cur_color; + int x, y; - for (cur_y = 0; cur_y < TILE_Y; cur_y++) { - for (cur_x = 0; cur_x < TILE_X; cur_x++) { - for (cur_color = 0; cur_color < num_colors; cur_color++) { - if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r && - ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g && - ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b) - break; - } - if (cur_color >= num_colors) - Fprintf(stderr, "color not in colormap!\n"); - y = cur_y + yoffset; - x = cur_x + xoffset; - Bild_daten[y][x] =cur_color; - } - } + for (cur_y = 0; cur_y < TILE_Y; cur_y++) { + for (cur_x = 0; cur_x < TILE_X; cur_x++) { + for (cur_color = 0; cur_color < num_colors; cur_color++) { + if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r + && ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g + && ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b) + break; + } + if (cur_color >= num_colors) + Fprintf(stderr, "color not in colormap!\n"); + y = cur_y + yoffset; + x = cur_x + xoffset; + Bild_daten[y][x] = cur_color; + } + } } diff --git a/win/gem/wingem.c b/win/gem/wingem.c index 4e3885663..8bd78f937 100644 --- a/win/gem/wingem.c +++ b/win/gem/wingem.c @@ -1,6 +1,6 @@ -/* NetHack 3.6 wingem.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wingem.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */ /* NetHack 3.6 wingem.c $Date: 2012/01/24 04:26:29 $ $Revision: 1.16 $ */ -/* Copyright (c) Christian Bressler, 1999 */ +/* Copyright (c) Christian Bressler, 1999 */ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" @@ -20,10 +20,10 @@ static char nullstr[] = "", winpanicstr[] = "Bad window id %d"; static int curr_status_line; static char *FDECL(copy_of, (const char *)); -static void FDECL(bail, (const char *)); /* __attribute__((noreturn)) */ +static void FDECL(bail, (const char *)); /* __attribute__((noreturn)) */ extern int mar_set_tile_mode(int); -extern void mar_set_font(int,const char*,int); +extern void mar_set_font(int, const char *, int); extern void mar_set_margin(int); extern void mar_set_msg_visible(int); extern void mar_set_status_align(int); @@ -31,85 +31,52 @@ extern void mar_set_msg_align(int); extern void mar_set_tilefile(char *); extern void mar_set_tilex(int); extern void mar_set_tiley(int); -extern short glyph2tile[MAX_GLYPH]; /* from tile.c */ -extern void mar_display_nhwindow(winid); /* from wingem1.c */ +extern short glyph2tile[MAX_GLYPH]; /* from tile.c */ +extern void mar_display_nhwindow(winid); /* from wingem1.c */ -void Gem_outrip(winid,int,time_t); +void Gem_outrip(winid, int, time_t); void Gem_preference_update(const char *); /* Interface definition, for windows.c */ struct window_procs Gem_procs = { "Gem", - WC_COLOR|WC_HILITE_PET|WC_ALIGN_MESSAGE|WC_ALIGN_STATUS| - WC_INVERSE|WC_SCROLL_MARGIN| - WC_FONT_MESSAGE|WC_FONT_STATUS|WC_FONT_MENU|WC_FONT_TEXT|WC_FONT_MAP| - WC_FONTSIZ_MESSAGE|WC_FONTSIZ_STATUS|WC_FONTSIZ_MENU|WC_FONTSIZ_TEXT|WC_FONTSIZ_MAP| - WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE|WC_VARY_MSGCOUNT|WC_ASCII_MAP, - 0L, - Gem_init_nhwindows, - Gem_player_selection, - Gem_askname, - Gem_get_nh_event, - Gem_exit_nhwindows, - Gem_suspend_nhwindows, - Gem_resume_nhwindows, - Gem_create_nhwindow, - Gem_clear_nhwindow, - Gem_display_nhwindow, - Gem_destroy_nhwindow, - Gem_curs, - Gem_putstr, - genl_putmixed, - Gem_display_file, - Gem_start_menu, - Gem_add_menu, - Gem_end_menu, - Gem_select_menu, - genl_message_menu, - Gem_update_inventory, - Gem_mark_synch, - Gem_wait_synch, + WC_COLOR | WC_HILITE_PET | WC_ALIGN_MESSAGE | WC_ALIGN_STATUS | WC_INVERSE + | WC_SCROLL_MARGIN | WC_FONT_MESSAGE | WC_FONT_STATUS | WC_FONT_MENU + | WC_FONT_TEXT | WC_FONT_MAP | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS + | WC_FONTSIZ_MENU | WC_FONTSIZ_TEXT | WC_FONTSIZ_MAP | WC_TILE_WIDTH + | WC_TILE_HEIGHT | WC_TILE_FILE | WC_VARY_MSGCOUNT | WC_ASCII_MAP, + 0L, Gem_init_nhwindows, Gem_player_selection, Gem_askname, + Gem_get_nh_event, Gem_exit_nhwindows, Gem_suspend_nhwindows, + Gem_resume_nhwindows, Gem_create_nhwindow, Gem_clear_nhwindow, + Gem_display_nhwindow, Gem_destroy_nhwindow, Gem_curs, Gem_putstr, + genl_putmixed, Gem_display_file, Gem_start_menu, Gem_add_menu, + Gem_end_menu, Gem_select_menu, genl_message_menu, Gem_update_inventory, + Gem_mark_synch, Gem_wait_synch, #ifdef CLIPPING Gem_cliparound, #endif #ifdef POSITIONBAR Gem_update_positionbar, #endif - Gem_print_glyph, - Gem_raw_print, - Gem_raw_print_bold, - Gem_nhgetch, - Gem_nh_poskey, - Gem_nhbell, - Gem_doprev_message, - Gem_yn_function, - Gem_getlin, - Gem_get_ext_cmd, - Gem_number_pad, - Gem_delay_output, -#ifdef CHANGE_COLOR /* the Mac uses a palette device */ + Gem_print_glyph, Gem_raw_print, Gem_raw_print_bold, Gem_nhgetch, + Gem_nh_poskey, Gem_nhbell, Gem_doprev_message, Gem_yn_function, + Gem_getlin, Gem_get_ext_cmd, Gem_number_pad, Gem_delay_output, +#ifdef CHANGE_COLOR /* the Mac uses a palette device */ Gem_change_color, #ifdef MAC - Gem_change_background, - Gem_set_font_name, + Gem_change_background, Gem_set_font_name, #endif Gem_get_color_string, #endif /* other defs that really should go away (they're tty specific) */ - Gem_start_screen, - Gem_end_screen, - Gem_outrip, - Gem_preference_update, - genl_getmsghistory, - genl_putmsghistory + Gem_start_screen, Gem_end_screen, Gem_outrip, Gem_preference_update, + genl_getmsghistory, genl_putmsghistory #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, - genl_status_update, -# ifdef STATUS_HILITES + genl_status_init, + genl_status_finish, genl_status_enablefield, genl_status_update, +#ifdef STATUS_HILITES genl_status_threshold, -# endif +#endif #endif genl_can_suspend_no, }; @@ -118,39 +85,43 @@ struct window_procs Gem_procs = { void * Gem_change_background(dummy) int dummy; -{} +{ +} short * -Gem_set_font_name(foo,bar) +Gem_set_font_name(foo, bar) winid foo; char *bar; -{} +{ +} #endif /*************************** Proceduren *************************************/ -int mar_hp_query(void){ - if(Upolyd) - return(u.mh ? u.mhmax/u.mh : -1); - return(u.uhp ? u.uhpmax/u.uhp : -1); +int +mar_hp_query(void) +{ + if (Upolyd) + return (u.mh ? u.mhmax / u.mh : -1); + return (u.uhp ? u.uhpmax / u.uhp : -1); } int mar_iflags_numpad() { - return(iflags.num_pad ? 1 : 0); + return (iflags.num_pad ? 1 : 0); } int mar_get_msg_history() { - return(iflags.msg_history); + return (iflags.msg_history); } int mar_get_msg_visible() { - return(iflags.wc_vary_msgcount); + return (iflags.wc_vary_msgcount); } /* clean up and quit */ static void @@ -164,366 +135,364 @@ const char *mesg; } /*$$$*/ -#define DEF_CLIPAROUND_MARGIN -1 +#define DEF_CLIPAROUND_MARGIN -1 #ifndef TILE_X #define TILE_X 16 #endif #define TILE_Y 16 -#define TILES_PER_LINE 20 +#define TILES_PER_LINE 20 #define NHFONT_DEFAULT_SIZE 10 #define NHFONT_SIZE_MIN 3 #define NHFONT_SIZE_MAX 20 /*$$$*/ /*ARGSUSED*/ void -Gem_init_nhwindows(argcp,argv) -int* argcp; -char** argv; +Gem_init_nhwindows(argcp, argv) +int *argcp; +char **argv; { - argv=argv, argcp=argcp; - colors_changed=TRUE; + argv = argv, argcp = argcp; + colors_changed = TRUE; - set_wc_option_mod_status( - WC_ALIGN_MESSAGE | - WC_ALIGN_STATUS | - WC_TILE_WIDTH | - WC_TILE_HEIGHT | - WC_TILE_FILE, - DISP_IN_GAME); - set_wc_option_mod_status( - WC_HILITE_PET | - WC_SCROLL_MARGIN | - WC_FONT_MESSAGE | - WC_FONT_MAP | - WC_FONT_STATUS | - WC_FONT_MENU | - WC_FONT_TEXT | - WC_FONTSIZ_MESSAGE | - WC_FONTSIZ_MAP | - WC_FONTSIZ_STATUS | - WC_FONTSIZ_MENU | - WC_FONTSIZ_TEXT | - WC_VARY_MSGCOUNT, - SET_IN_GAME - ); - if( iflags.wc_align_message==0 ) iflags.wc_align_message = ALIGN_TOP; - if( iflags.wc_align_status==0 ) iflags.wc_align_status = ALIGN_BOTTOM; - if( iflags.wc_scroll_margin==0 ) iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; - if( iflags.wc_tile_width==0 ) iflags.wc_tile_width = TILE_X; - if( iflags.wc_tile_height==0 ) iflags.wc_tile_height = TILE_Y; - if(iflags.wc_tile_file && *iflags.wc_tile_file) - mar_set_tilefile(iflags.wc_tile_file); - if( iflags.wc_vary_msgcount==0 ) iflags.wc_vary_msgcount = 3; - mar_set_tile_mode(!iflags.wc_ascii_map); /* MAR -- 17.Mar 2002 True is tiles */ - mar_set_tilex(iflags.wc_tile_width); - mar_set_tiley(iflags.wc_tile_height); - mar_set_msg_align(iflags.wc_align_message-ALIGN_BOTTOM); - mar_set_status_align(iflags.wc_align_status-ALIGN_BOTTOM); - if(mar_gem_init()==0){ - bail((char *)0); - /*NOTREACHED*/ - } - iflags.window_inited = TRUE; + set_wc_option_mod_status(WC_ALIGN_MESSAGE | WC_ALIGN_STATUS + | WC_TILE_WIDTH | WC_TILE_HEIGHT + | WC_TILE_FILE, + DISP_IN_GAME); + set_wc_option_mod_status( + WC_HILITE_PET | WC_SCROLL_MARGIN | WC_FONT_MESSAGE | WC_FONT_MAP + | WC_FONT_STATUS | WC_FONT_MENU | WC_FONT_TEXT + | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_MAP | WC_FONTSIZ_STATUS + | WC_FONTSIZ_MENU | WC_FONTSIZ_TEXT | WC_VARY_MSGCOUNT, + SET_IN_GAME); + if (iflags.wc_align_message == 0) + iflags.wc_align_message = ALIGN_TOP; + if (iflags.wc_align_status == 0) + iflags.wc_align_status = ALIGN_BOTTOM; + if (iflags.wc_scroll_margin == 0) + iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; + if (iflags.wc_tile_width == 0) + iflags.wc_tile_width = TILE_X; + if (iflags.wc_tile_height == 0) + iflags.wc_tile_height = TILE_Y; + if (iflags.wc_tile_file && *iflags.wc_tile_file) + mar_set_tilefile(iflags.wc_tile_file); + if (iflags.wc_vary_msgcount == 0) + iflags.wc_vary_msgcount = 3; + mar_set_tile_mode( + !iflags.wc_ascii_map); /* MAR -- 17.Mar 2002 True is tiles */ + mar_set_tilex(iflags.wc_tile_width); + mar_set_tiley(iflags.wc_tile_height); + mar_set_msg_align(iflags.wc_align_message - ALIGN_BOTTOM); + mar_set_status_align(iflags.wc_align_status - ALIGN_BOTTOM); + if (mar_gem_init() == 0) { + bail((char *) 0); + /*NOTREACHED*/ + } + iflags.window_inited = TRUE; - CO=80; /* MAR -- whatsoever */ - LI=25; + CO = 80; /* MAR -- whatsoever */ + LI = 25; - add_menu_cmd_alias(' ', MENU_NEXT_PAGE); - mar_set_no_glyph(NO_GLYPH); + add_menu_cmd_alias(' ', MENU_NEXT_PAGE); + mar_set_no_glyph(NO_GLYPH); } void Gem_player_selection() { - int i, k, n; - char pick4u = 'n', pbuf[QBUFSZ], lastch=0, currch; - winid win; - anything any; - menu_item *selected=NULL; + int i, k, n; + char pick4u = 'n', pbuf[QBUFSZ], lastch = 0, currch; + winid win; + anything any; + menu_item *selected = NULL; - /* avoid unnecessary prompts further down */ - rigid_role_checks(); + /* avoid unnecessary prompts further down */ + rigid_role_checks(); - /* Should we randomly pick for the player? */ - if (!flags.randomall && - (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE || - flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { -/* pick4u = yn_function("Shall I pick a character for you? [ynq]",ynqchars,'n');*/ - pick4u = yn_function( - build_plselection_prompt(pbuf, QBUFSZ, flags.initrole,flags.initrace, - flags.initgend, flags.initalign) - ,ynqchars,'n' - ); - if(pick4u=='q'){ -give_up: /* Just quit */ - if (selected) free((genericptr_t) selected); - bail((char *)0); - /*NOTREACHED*/ - return; - } - } + /* Should we randomly pick for the player? */ + if (!flags.randomall + && (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE + || flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { + /* pick4u = yn_function("Shall I pick a character for you? + * [ynq]",ynqchars,'n');*/ + pick4u = yn_function(build_plselection_prompt( + pbuf, QBUFSZ, flags.initrole, flags.initrace, + flags.initgend, flags.initalign), + ynqchars, 'n'); + if (pick4u == 'q') { + give_up: /* Just quit */ + if (selected) + free((genericptr_t) selected); + bail((char *) 0); + /*NOTREACHED*/ + return; + } + } - /* Select a role, if necessary */ - if (flags.initrole < 0) { + /* Select a role, if necessary */ + if (flags.initrole < 0) { + /* Process the choice */ + if (pick4u == 'y' || flags.initrole == ROLE_RANDOM + || flags.randomall) { + /* Pick a random role */ + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + mar_add_message("Incompatible role!"); + mar_display_nhwindow(WIN_MESSAGE); + flags.initrole = randrole(); + } + } else { + /* Prompt for a role */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; roles[i].name.m; i++) { + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + currch = lowc(roles[i].name.m[0]); + if (currch == lastch) + currch = highc(currch); + add_menu(win, roles[i].malenum, &any, currch, 0, ATR_NONE, + an(roles[i].name.m), MENU_UNSELECTED); + lastch = currch; + } + } + any.a_int = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrole() + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + end_menu(win, "Pick a role"); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); - /* Process the choice */ - if(pick4u=='y' || flags.initrole == ROLE_RANDOM || flags.randomall) { - /* Pick a random role */ - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - mar_add_message("Incompatible role!"); - mar_display_nhwindow(WIN_MESSAGE); - flags.initrole = randrole(); - } - }else{ - /* Prompt for a role */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; roles[i].name.m; i++) { - if (ok_role(i, flags.initrace, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - currch = lowc(roles[i].name.m[0]); - if(currch == lastch) - currch = highc(currch); - add_menu(win, roles[i].malenum, &any, currch, - 0, ATR_NONE, an(roles[i].name.m), MENU_UNSELECTED); - lastch = currch; - } - } - any.a_int = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrole()+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - end_menu(win, "Pick a role"); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); + /* Process the choice */ + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Process the choice */ - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + flags.initrole = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + } - flags.initrole = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - } + /* Select a race, if necessary */ + /* force compatibility with role, try for compatibility with + * pre-selected gender/alignment */ + if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (pick4u == 'y' || flags.initrace == ROLE_RANDOM + || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + mar_add_message("Incompatible race!"); + mar_display_nhwindow(WIN_MESSAGE); + flags.initrace = randrace(flags.initrole); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid races */ + n = 0; /* number valid */ + k = 0; /* valid race */ + for (i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; races[i].noun; i++) { + if (validrace(flags.initrole, i)) { + n++; + k = i; + } + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; races[i].noun; i++) + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0, + ATR_NONE, races[i].noun, MENU_UNSELECTED); + } + any.a_int = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrace(flags.initrole) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the race of your %s", + roles[flags.initrole].name.m); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initrace = k; + } + } - /* Select a race, if necessary */ - /* force compatibility with role, try for compatibility with - * pre-selected gender/alignment */ - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - mar_add_message("Incompatible race!"); - mar_display_nhwindow(WIN_MESSAGE); - flags.initrace = randrace(flags.initrole); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid races */ - n = 0; /* number valid */ - k = 0; /* valid race */ - for (i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; races[i].noun; i++) { - if (validrace(flags.initrole, i)) { - n++; - k = i; - } - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; races[i].noun; i++) - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any, races[i].noun[0], - 0, ATR_NONE, races[i].noun, MENU_UNSELECTED); - } - any.a_int = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrace(flags.initrole)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the race of your %s", - roles[flags.initrole].name.m); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initrace = k; - } - } + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (pick4u == 'y' || flags.initgend == ROLE_RANDOM + || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + mar_add_message("Incompatible gender!"); + mar_display_nhwindow(WIN_MESSAGE); + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid genders */ + n = 0; /* number valid */ + k = 0; /* valid gender */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) { + if (validgend(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, genders[i].adj[0], 0, + ATR_NONE, genders[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randgend(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the gender of your %s %s", + races[flags.initrace].adj, + roles[flags.initrole].name.m); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initgend = k; + } + } - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - /* pre-selected gender not valid */ - if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - mar_add_message("Incompatible gender!"); - mar_display_nhwindow(WIN_MESSAGE); - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid genders */ - n = 0; /* number valid */ - k = 0; /* valid gender */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) { - if (validgend(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, genders[i].adj[0], - 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randgend(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the gender of your %s %s", - races[flags.initrace].adj, - roles[flags.initrole].name.m); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initgend = k; - } - } + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (pick4u == 'y' || flags.initalign == ROLE_RANDOM + || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + mar_add_message("Incompatible alignment!"); + mar_display_nhwindow(WIN_MESSAGE); + flags.initalign = randalign(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid alignments */ + n = 0; /* number valid */ + k = 0; /* valid alignment */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) { + if (validalign(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + win = create_nhwindow(NHW_MENU); + start_menu(win); + any.a_void = 0; /* zero out all bits */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(flags.initrole, flags.initrace, + flags.initgend, i)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0, + ATR_NONE, aligns[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randalign(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the alignment of your %s %s %s", + genders[flags.initgend].adj, + races[flags.initrace].adj, + (flags.initgend && roles[flags.initrole].name.f) + ? roles[flags.initrole].name.f + : roles[flags.initrole].name.m); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initalign = k; + } + } - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - /* pre-selected alignment not valid */ - if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - mar_add_message("Incompatible alignment!"); - mar_display_nhwindow(WIN_MESSAGE); - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid alignments */ - n = 0; /* number valid */ - k = 0; /* valid alignment */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, flags.initrace, flags.initgend, - i)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) { - if (validalign(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - win = create_nhwindow(NHW_MENU); - start_menu(win); - any.a_void = 0; /* zero out all bits */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(flags.initrole, flags.initrace, - flags.initgend, i)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], - 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randalign(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the alignment of your %s %s %s", - genders[flags.initgend].adj, - races[flags.initrace].adj, - (flags.initgend && roles[flags.initrole].name.f) ? - roles[flags.initrole].name.f : - roles[flags.initrole].name.m); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initalign = k; - } - } - - /* Success! */ - return; + /* Success! */ + return; } /* @@ -536,108 +505,116 @@ give_up: /* Just quit */ void Gem_askname() { - strncpy(plname,mar_ask_name(),PL_NSIZ); + strncpy(plname, mar_ask_name(), PL_NSIZ); } void Gem_get_nh_event() -{} +{ +} void Gem_suspend_nhwindows(str) - const char *str; +const char *str; { - const char *foo; + const char *foo; - foo=str; /* MAR -- And the compiler whines no more ... */ + foo = str; /* MAR -- And the compiler whines no more ... */ } void Gem_resume_nhwindows() -{} +{ +} void Gem_end_screen() -{} +{ +} void Gem_start_screen() -{} +{ +} extern void mar_exit_nhwindows(void); extern boolean run_from_desktop; void Gem_exit_nhwindows(str) - const char *str; +const char *str; { - if(str) Gem_raw_print(str); - mar_exit_nhwindows(); - if(iflags.toptenwin) - run_from_desktop=FALSE; - iflags.window_inited = 0; + if (str) + Gem_raw_print(str); + mar_exit_nhwindows(); + if (iflags.toptenwin) + run_from_desktop = FALSE; + iflags.window_inited = 0; } winid Gem_create_nhwindow(type) - int type; +int type; { - winid newid; + winid newid; - switch(type) { - case NHW_MESSAGE: - if(iflags.msg_history < 20) iflags.msg_history = 20; - else if(iflags.msg_history > 60) iflags.msg_history = 60; - break; - case NHW_STATUS: - case NHW_MAP: - case NHW_MENU: - case NHW_TEXT: - break; - default: - panic("Tried to create window type %d\n", (int) type); - return WIN_ERR; - } + switch (type) { + case NHW_MESSAGE: + if (iflags.msg_history < 20) + iflags.msg_history = 20; + else if (iflags.msg_history > 60) + iflags.msg_history = 60; + break; + case NHW_STATUS: + case NHW_MAP: + case NHW_MENU: + case NHW_TEXT: + break; + default: + panic("Tried to create window type %d\n", (int) type); + return WIN_ERR; + } - newid=mar_create_window(type); + newid = mar_create_window(type); - if(newid == MAXWIN) { - panic("No window slots!"); - /* NOTREACHED */ - } + if (newid == MAXWIN) { + panic("No window slots!"); + /* NOTREACHED */ + } - return newid; + return newid; } void Gem_nhbell() { - if (flags.silent) return; - putchar('\007'); - fflush(stdout); + if (flags.silent) + return; + putchar('\007'); + fflush(stdout); } extern void mar_clear_map(void); void Gem_clear_nhwindow(window) - winid window; +winid window; { - if(window == WIN_ERR) - panic(winpanicstr, window); + if (window == WIN_ERR) + panic(winpanicstr, window); - switch(mar_hol_win_type(window)) { - case NHW_MESSAGE: - mar_clear_messagewin(); - break; - case NHW_MAP: - mar_clear_map(); - break; - case NHW_STATUS: - case NHW_MENU: - case NHW_TEXT: - break; - } + switch (mar_hol_win_type(window)) { + case NHW_MESSAGE: + mar_clear_messagewin(); + break; + case NHW_MAP: + mar_clear_map(); + break; + case NHW_STATUS: + case NHW_MENU: + case NHW_TEXT: + break; + } } extern void mar_more(void); @@ -645,53 +622,55 @@ extern void mar_more(void); /*ARGSUSED*/ void Gem_display_nhwindow(window, blocking) - winid window; - boolean blocking; +winid window; +boolean blocking; { - if(window == WIN_ERR) - panic(winpanicstr, window); + if (window == WIN_ERR) + panic(winpanicstr, window); - mar_display_nhwindow(window); + mar_display_nhwindow(window); - switch(mar_hol_win_type(window)){ - case NHW_MESSAGE: - if(blocking) mar_more(); - break; - case NHW_MAP: - if(blocking) Gem_display_nhwindow(WIN_MESSAGE, TRUE); - break; - case NHW_STATUS: - case NHW_TEXT: - case NHW_MENU: - default: - break; - } + switch (mar_hol_win_type(window)) { + case NHW_MESSAGE: + if (blocking) + mar_more(); + break; + case NHW_MAP: + if (blocking) + Gem_display_nhwindow(WIN_MESSAGE, TRUE); + break; + case NHW_STATUS: + case NHW_TEXT: + case NHW_MENU: + default: + break; + } } void Gem_destroy_nhwindow(window) - winid window; +winid window; { - if(window == WIN_ERR) /* MAR -- test existence */ - panic(winpanicstr, window); + if (window == WIN_ERR) /* MAR -- test existence */ + panic(winpanicstr, window); - mar_destroy_nhwindow(window); + mar_destroy_nhwindow(window); } -extern void mar_curs(int,int); /* mar_curs is only for map */ +extern void mar_curs(int, int); /* mar_curs is only for map */ void Gem_curs(window, x, y) winid window; register int x, y; { - if(window == WIN_ERR) /* MAR -- test existence */ - panic(winpanicstr, window); + if (window == WIN_ERR) /* MAR -- test existence */ + panic(winpanicstr, window); - if(window==WIN_MAP) - mar_curs(x-1,y); /*$$$*/ - else if(window==WIN_STATUS) - curr_status_line=y; + if (window == WIN_MAP) + mar_curs(x - 1, y); /*$$$*/ + else if (window == WIN_STATUS) + curr_status_line = y; } extern void mar_add_status_str(const char *, int); @@ -699,48 +678,48 @@ extern void mar_putstr_text(winid, int, const char *); void Gem_putstr(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { - int win_type; + int win_type; - if(window == WIN_ERR) { - Gem_raw_print(str); - return; - } + if (window == WIN_ERR) { + Gem_raw_print(str); + return; + } - if(str == (const char*)0) - return; + if (str == (const char *) 0) + return; - switch((win_type=mar_hol_win_type(window))) { - case NHW_MESSAGE: - mar_add_message(str); - break; + switch ((win_type = mar_hol_win_type(window))) { + case NHW_MESSAGE: + mar_add_message(str); + break; - case NHW_STATUS: - mar_status_dirty(); - mar_add_status_str(str,curr_status_line); - if(curr_status_line) - mar_display_nhwindow(WIN_STATUS); - break; + case NHW_STATUS: + mar_status_dirty(); + mar_add_status_str(str, curr_status_line); + if (curr_status_line) + mar_display_nhwindow(WIN_STATUS); + break; - case NHW_MAP: - if(strcmp(str,".")) - Gem_putstr(WIN_MESSAGE,0,str); - else - mar_map_curs_weiter(); - mar_display_nhwindow(WIN_MESSAGE); - mar_display_nhwindow(WIN_STATUS); - break; + case NHW_MAP: + if (strcmp(str, ".")) + Gem_putstr(WIN_MESSAGE, 0, str); + else + mar_map_curs_weiter(); + mar_display_nhwindow(WIN_MESSAGE); + mar_display_nhwindow(WIN_STATUS); + break; - case NHW_MENU: - mar_change_menu_2_text(window); - /* Fallthru */ - case NHW_TEXT: - mar_putstr_text(window,attr,str); - break; - } /* endswitch win_type */ + case NHW_MENU: + mar_change_menu_2_text(window); + /* Fallthru */ + case NHW_TEXT: + mar_putstr_text(window, attr, str); + break; + } /* endswitch win_type */ } void @@ -748,27 +727,29 @@ Gem_display_file(fname, complain) const char *fname; boolean complain; { - dlb *f; - char buf[BUFSZ]; - char *cr; + dlb *f; + char buf[BUFSZ]; + char *cr; - f = dlb_fopen(fname, "r"); - if (!f) { - if(complain) - pline("Cannot open \"%s\".", fname); - } else { - winid datawin; + f = dlb_fopen(fname, "r"); + if (!f) { + if (complain) + pline("Cannot open \"%s\".", fname); + } else { + winid datawin; - datawin = Gem_create_nhwindow(NHW_TEXT); - while (dlb_fgets(buf, BUFSZ, f)) { - if ((cr = index(buf, '\n')) != 0) *cr = 0; - if (index(buf, '\t') != 0) (void) tabexpand(buf); - Gem_putstr(datawin, 0, buf); - } - (void) dlb_fclose(f); - Gem_display_nhwindow(datawin, FALSE); - Gem_destroy_nhwindow(datawin); - } + datawin = Gem_create_nhwindow(NHW_TEXT); + while (dlb_fgets(buf, BUFSZ, f)) { + if ((cr = index(buf, '\n')) != 0) + *cr = 0; + if (index(buf, '\t') != 0) + (void) tabexpand(buf); + Gem_putstr(datawin, 0, buf); + } + (void) dlb_fclose(f); + Gem_display_nhwindow(datawin, FALSE); + Gem_destroy_nhwindow(datawin); + } } /*ARGSUSED*/ @@ -778,41 +759,41 @@ boolean complain; */ void Gem_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) - winid window; /* window to use, must be of type NHW_MENU */ - int glyph; /* glyph to display with item (unused) */ - const anything *identifier; /* what to return if selected */ - char ch; /* keyboard accelerator (0 = pick our own) */ - char gch; /* group accelerator (0 = no group) */ - int attr; /* attribute for string (like Gem_putstr()) */ - const char *str; /* menu string */ - boolean preselected; /* item is marked as selected */ +winid window; /* window to use, must be of type NHW_MENU */ +int glyph; /* glyph to display with item (unused) */ +const anything *identifier; /* what to return if selected */ +char ch; /* keyboard accelerator (0 = pick our own) */ +char gch; /* group accelerator (0 = no group) */ +int attr; /* attribute for string (like Gem_putstr()) */ +const char *str; /* menu string */ +boolean preselected; /* item is marked as selected */ { - Gem_menu_item *G_item; - const char *newstr; - char buf[QBUFSZ]; + Gem_menu_item *G_item; + const char *newstr; + char buf[QBUFSZ]; - if (str == (const char*) 0) - return; + if (str == (const char *) 0) + return; - if (window == WIN_ERR) /* MAR -- test existence */ - panic(winpanicstr, window); + if (window == WIN_ERR) /* MAR -- test existence */ + panic(winpanicstr, window); - if (identifier->a_void) - Sprintf(buf, "%c - %s", ch ? ch : '?', str); - else - Sprintf(buf, "%s", str); - newstr = buf; + if (identifier->a_void) + Sprintf(buf, "%c - %s", ch ? ch : '?', str); + else + Sprintf(buf, "%s", str); + newstr = buf; - G_item = (Gem_menu_item *) alloc(sizeof(Gem_menu_item)); - G_item->Gmi_identifier = (long)identifier->a_void; - G_item->Gmi_glyph = glyph!=NO_GLYPH ? glyph2tile[glyph] : NO_GLYPH; - G_item->Gmi_count = -1L; - G_item->Gmi_selected = preselected ? 1 : 0; - G_item->Gmi_accelerator = ch; - G_item->Gmi_groupacc = gch; - G_item->Gmi_attr = attr; - G_item->Gmi_str = copy_of(newstr); - mar_add_menu(window, G_item); + G_item = (Gem_menu_item *) alloc(sizeof(Gem_menu_item)); + G_item->Gmi_identifier = (long) identifier->a_void; + G_item->Gmi_glyph = glyph != NO_GLYPH ? glyph2tile[glyph] : NO_GLYPH; + G_item->Gmi_count = -1L; + G_item->Gmi_selected = preselected ? 1 : 0; + G_item->Gmi_accelerator = ch; + G_item->Gmi_groupacc = gch; + G_item->Gmi_attr = attr; + G_item->Gmi_str = copy_of(newstr); + mar_add_menu(window, G_item); } /* @@ -821,72 +802,75 @@ Gem_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) */ void Gem_end_menu(window, prompt) - winid window; /* menu to use */ - const char *prompt; /* prompt to for menu */ +winid window; /* menu to use */ +const char *prompt; /* prompt to for menu */ { - if(window == WIN_ERR || mar_hol_win_type(window) != NHW_MENU) - panic(winpanicstr, window); + if (window == WIN_ERR || mar_hol_win_type(window) != NHW_MENU) + panic(winpanicstr, window); - /* Reverse the list so that items are in correct order. */ - mar_reverse_menu(); + /* Reverse the list so that items are in correct order. */ + mar_reverse_menu(); - /* Put the prompt at the beginning of the menu. */ - mar_set_menu_title(prompt); + /* Put the prompt at the beginning of the menu. */ + mar_set_menu_title(prompt); - mar_set_accelerators(); + mar_set_accelerators(); } int Gem_select_menu(window, how, menu_list) - winid window; - int how; - menu_item **menu_list; +winid window; +int how; +menu_item **menu_list; { - Gem_menu_item *Gmit; - menu_item *mi; - int n; + Gem_menu_item *Gmit; + menu_item *mi; + int n; - if(window == WIN_ERR || mar_hol_win_type(window) != NHW_MENU) - panic(winpanicstr, window); + if (window == WIN_ERR || mar_hol_win_type(window) != NHW_MENU) + panic(winpanicstr, window); - *menu_list = (menu_item *) 0; - mar_set_menu_type(how); - Gem_display_nhwindow(window, TRUE); + *menu_list = (menu_item *) 0; + mar_set_menu_type(how); + Gem_display_nhwindow(window, TRUE); - for (n = 0, Gmit = mar_hol_inv(); Gmit; Gmit = Gmit->Gmi_next) - if (Gmit->Gmi_selected) n++; + for (n = 0, Gmit = mar_hol_inv(); Gmit; Gmit = Gmit->Gmi_next) + if (Gmit->Gmi_selected) + n++; - if (n > 0) { - *menu_list = (menu_item *) alloc(n * sizeof(menu_item)); - for (mi = *menu_list, Gmit = mar_hol_inv(); Gmit; Gmit = Gmit->Gmi_next) - if (Gmit->Gmi_selected) { - mi->item = (anything)(genericptr_t)Gmit->Gmi_identifier; - mi->count = Gmit->Gmi_count; - mi++; - } - } + if (n > 0) { + *menu_list = (menu_item *) alloc(n * sizeof(menu_item)); + for (mi = *menu_list, Gmit = mar_hol_inv(); Gmit; + Gmit = Gmit->Gmi_next) + if (Gmit->Gmi_selected) { + mi->item = (anything)(genericptr_t) Gmit->Gmi_identifier; + mi->count = Gmit->Gmi_count; + mi++; + } + } - return n; + return n; } void Gem_update_inventory() -{} +{ +} void Gem_mark_synch() { - mar_display_nhwindow(WIN_MESSAGE); - mar_display_nhwindow(WIN_MAP); - mar_display_nhwindow(WIN_STATUS); + mar_display_nhwindow(WIN_MESSAGE); + mar_display_nhwindow(WIN_MAP); + mar_display_nhwindow(WIN_STATUS); } void Gem_wait_synch() { - mar_display_nhwindow(WIN_MESSAGE); - mar_display_nhwindow(WIN_MAP); - mar_display_nhwindow(WIN_STATUS); + mar_display_nhwindow(WIN_MESSAGE); + mar_display_nhwindow(WIN_MAP); + mar_display_nhwindow(WIN_STATUS); } #ifdef CLIPPING @@ -895,8 +879,8 @@ void Gem_cliparound(x, y) int x, y; { - mar_curs(x-1,y); - mar_cliparound(); + mar_curs(x - 1, y); + mar_cliparound(); } #endif /* CLIPPING */ @@ -909,57 +893,58 @@ int x, y; * position and glyph are always correct (checked there)! */ -void mar_print_gl_char(winid,xchar,xchar,int); +void mar_print_gl_char(winid, xchar, xchar, int); extern int mar_set_rogue(int); -extern void mar_add_pet_sign(winid,int,int); +extern void mar_add_pet_sign(winid, int, int); void Gem_print_glyph(window, x, y, glyph) - winid window; - xchar x, y; - int glyph; +winid window; +xchar x, y; +int glyph; { /* Move the cursor. */ - Gem_curs(window, x,y); + Gem_curs(window, x, y); - mar_set_rogue(Is_rogue_level(&u.uz) ? TRUE : FALSE); + mar_set_rogue(Is_rogue_level(&u.uz) ? TRUE : FALSE); - x--; /* MAR -- because x ranges from 1 to COLNO */ - if(mar_set_tile_mode(-1)){ - mar_print_glyph(window,x,y,glyph2tile[glyph]); - if( + x--; /* MAR -- because x ranges from 1 to COLNO */ + if (mar_set_tile_mode(-1)) { + mar_print_glyph(window, x, y, glyph2tile[glyph]); + if ( #ifdef TEXTCOLOR - iflags.hilite_pet && + iflags.hilite_pet && #endif - glyph_is_pet(glyph) - ) - mar_add_pet_sign(window,x,y); - }else - mar_print_gl_char(window,x,y,glyph); + glyph_is_pet(glyph)) + mar_add_pet_sign(window, x, y); + } else + mar_print_gl_char(window, x, y, glyph); } -void mar_print_char(winid,xchar,xchar,char,int); +void mar_print_char(winid, xchar, xchar, char, int); -void mar_print_gl_char(window, x, y, glyph) - winid window; - xchar x, y; - int glyph; +void +mar_print_gl_char(window, x, y, glyph) +winid window; +xchar x, y; +int glyph; { - int ch; - int color; + int ch; + int color; unsigned special; /* map glyph to character and color */ - (void)mapglyph(glyph, &ch, &color, &special, x, y); + (void) mapglyph(glyph, &ch, &color, &special, x, y); #ifdef TEXTCOLOR /* Turn off color if rogue level. */ - if (Is_rogue_level(&u.uz)) color = NO_COLOR; + if (Is_rogue_level(&u.uz)) + color = NO_COLOR; #endif /* TEXTCOLOR */ - mar_print_char(window,x,y,ch,color); + mar_print_char(window, x, y, ch, color); } extern void mar_raw_print(const char *); @@ -967,97 +952,106 @@ extern void mar_raw_print_bold(const char *); void Gem_raw_print(str) - const char *str; +const char *str; { - if(str && *str){ - if(iflags.window_inited) mar_raw_print(str); - else printf("%s\n",str); - } + if (str && *str) { + if (iflags.window_inited) + mar_raw_print(str); + else + printf("%s\n", str); + } } void Gem_raw_print_bold(str) - const char *str; +const char *str; { - if(str && *str){ - if(iflags.window_inited) mar_raw_print_bold(str); - else printf("%s\n",str); - } + if (str && *str) { + if (iflags.window_inited) + mar_raw_print_bold(str); + else + printf("%s\n", str); + } } -extern void mar_update_value(void); /* wingem1.c */ +extern void mar_update_value(void); /* wingem1.c */ int Gem_nhgetch() { int i; - mar_update_value(); - i = tgetch(); - if (!i) i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ + mar_update_value(); + i = tgetch(); + if (!i) + i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ return i; } /* Get a extended command in windowport specific way. - returns index of the ext_cmd or -1. - called after '#'. - It's a menu with all the possibilities. */ + returns index of the ext_cmd or -1. + called after '#'. + It's a menu with all the possibilities. */ int Gem_get_ext_cmd() { - winid wind; - int i, count, what,too_much=FALSE; - menu_item *selected=NULL; - anything any; - char accelerator=0, tmp_acc=0; - const char *ptr; + winid wind; + int i, count, what, too_much = FALSE; + menu_item *selected = NULL; + anything any; + char accelerator = 0, tmp_acc = 0; + const char *ptr; - wind=Gem_create_nhwindow(NHW_MENU); - Gem_start_menu(wind); - for(i=0;(ptr=extcmdlist[i].ef_txt);i++){ - any.a_int=i; - accelerator=*ptr; - if(tmp_acc==accelerator){ - if(too_much) - accelerator='&'; /* MAR -- poor choice, anyone? */ - else - accelerator+='A'-'a'; - too_much=TRUE; - }else - too_much=FALSE; - tmp_acc=*ptr; - Gem_add_menu(wind,NO_GLYPH,&any,accelerator,0,ATR_NONE,ptr,FALSE); - } - Gem_end_menu(wind,"What extended command?"); - count=Gem_select_menu(wind,PICK_ONE,&selected); - what = count ? selected->item.a_int : -1; - if(selected) free(selected); - Gem_destroy_nhwindow(wind); - return(what); + wind = Gem_create_nhwindow(NHW_MENU); + Gem_start_menu(wind); + for (i = 0; (ptr = extcmdlist[i].ef_txt); i++) { + any.a_int = i; + accelerator = *ptr; + if (tmp_acc == accelerator) { + if (too_much) + accelerator = '&'; /* MAR -- poor choice, anyone? */ + else + accelerator += 'A' - 'a'; + too_much = TRUE; + } else + too_much = FALSE; + tmp_acc = *ptr; + Gem_add_menu(wind, NO_GLYPH, &any, accelerator, 0, ATR_NONE, ptr, + FALSE); + } + Gem_end_menu(wind, "What extended command?"); + count = Gem_select_menu(wind, PICK_ONE, &selected); + what = count ? selected->item.a_int : -1; + if (selected) + free(selected); + Gem_destroy_nhwindow(wind); + return (what); } void Gem_number_pad(state) int state; { - state=state; + state = state; } void win_Gem_init() -{} +{ +} #ifdef POSITIONBAR void Gem_update_positionbar(posbar) char *posbar; -{} +{ +} #endif /** Gem_outrip **/ void mar_set_text_to_rip(winid); -char** rip_line=0; +char **rip_line = 0; void Gem_outrip(w, how, when) @@ -1066,159 +1060,163 @@ int how; time_t when; { /* Code from X11 windowport */ -#define STONE_LINE_LEN 15 /* # chars that fit on one line */ -#define NAME_LINE 0 /* line # for player name */ -#define GOLD_LINE 1 /* line # for amount of gold */ -#define DEATH_LINE 2 /* line # for death description */ -#define YEAR_LINE 6 /* line # for year */ - char buf[BUFSZ]; - char *dpx; - int line; - long year; +#define STONE_LINE_LEN 15 /* # chars that fit on one line */ +#define NAME_LINE 0 /* line # for player name */ +#define GOLD_LINE 1 /* line # for amount of gold */ +#define DEATH_LINE 2 /* line # for death description */ +#define YEAR_LINE 6 /* line # for year */ + char buf[BUFSZ]; + char *dpx; + int line; + long year; - if (!rip_line) { - int i; - rip_line= (char **)malloc((YEAR_LINE+1)*sizeof(char *)); - for (i=0; i STONE_LINE_LEN) { - for(i = STONE_LINE_LEN; - ((i0 > STONE_LINE_LEN) && i); i--) - if(dpx[i] == ' ') i0 = i; - if(!i) i0 = STONE_LINE_LEN; - } - tmpchar = dpx[i0]; - dpx[i0] = 0; - strcpy(rip_line[line], dpx); - if (tmpchar != ' ') { - dpx[i0] = tmpchar; - dpx= &dpx[i0]; - } else dpx= &dpx[i0+1]; - } - /* Put year on stone */ - year = yyyymmdd(when) / 10000L; - Sprintf(rip_line[YEAR_LINE], "%4ld", year); + /* Put death type on stone */ + for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) { + register int i, i0; + char tmpchar; + if ((i0 = strlen(dpx)) > STONE_LINE_LEN) { + for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--) + if (dpx[i] == ' ') + i0 = i; + if (!i) + i0 = STONE_LINE_LEN; + } + tmpchar = dpx[i0]; + dpx[i0] = 0; + strcpy(rip_line[line], dpx); + if (tmpchar != ' ') { + dpx[i0] = tmpchar; + dpx = &dpx[i0]; + } else + dpx = &dpx[i0 + 1]; + } + /* Put year on stone */ + year = yyyymmdd(when) / 10000L; + Sprintf(rip_line[YEAR_LINE], "%4ld", year); - mar_set_text_to_rip(w); - for(line=0;line<13;line++) - putstr(w, 0, ""); + mar_set_text_to_rip(w); + for (line = 0; line < 13; line++) + putstr(w, 0, ""); } void -mar_get_font(type,p_fname,psize) +mar_get_font(type, p_fname, psize) int type; char **p_fname; int *psize; { - switch(type){ - case NHW_MESSAGE: - *p_fname=iflags.wc_font_message; - *psize=iflags.wc_fontsiz_message; - break; - case NHW_MAP: - *p_fname=iflags.wc_font_map; - *psize=iflags.wc_fontsiz_map; - break; - case NHW_STATUS: - *p_fname=iflags.wc_font_status; - *psize=iflags.wc_fontsiz_status; - break; - case NHW_MENU: - *p_fname=iflags.wc_font_menu; - *psize=iflags.wc_fontsiz_menu; - break; - case NHW_TEXT: - *p_fname=iflags.wc_font_text; - *psize=iflags.wc_fontsiz_text; - break; - default: - break; - } + switch (type) { + case NHW_MESSAGE: + *p_fname = iflags.wc_font_message; + *psize = iflags.wc_fontsiz_message; + break; + case NHW_MAP: + *p_fname = iflags.wc_font_map; + *psize = iflags.wc_fontsiz_map; + break; + case NHW_STATUS: + *p_fname = iflags.wc_font_status; + *psize = iflags.wc_fontsiz_status; + break; + case NHW_MENU: + *p_fname = iflags.wc_font_menu; + *psize = iflags.wc_fontsiz_menu; + break; + case NHW_TEXT: + *p_fname = iflags.wc_font_text; + *psize = iflags.wc_fontsiz_text; + break; + default: + break; + } } void Gem_preference_update(pref) const char *pref; { - if( stricmp( pref, "font_message")==0 || - stricmp( pref, "font_size_message")==0 ) { - if( iflags.wc_fontsiz_messageNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; - mar_set_font(NHW_MESSAGE,iflags.wc_font_message,iflags.wc_fontsiz_message); - return; - } - if( stricmp( pref, "font_map")==0 || - stricmp( pref, "font_size_map")==0 ) { - if( iflags.wc_fontsiz_mapNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_map = NHFONT_DEFAULT_SIZE; - mar_set_font(NHW_MAP,iflags.wc_font_map,iflags.wc_fontsiz_map); - return; - } - if( stricmp( pref, "font_status")==0 || - stricmp( pref, "font_size_status")==0 ) { - if( iflags.wc_fontsiz_statusNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; - mar_set_font(NHW_STATUS,iflags.wc_font_status,iflags.wc_fontsiz_status); - return; - } - if( stricmp( pref, "font_menu")==0 || - stricmp( pref, "font_size_menu")==0 ) { - if( iflags.wc_fontsiz_menuNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; - mar_set_font(NHW_MENU,iflags.wc_font_menu,iflags.wc_fontsiz_menu); - return; - } - if( stricmp( pref, "font_text")==0 || - stricmp( pref, "font_size_text")==0 ) { - if( iflags.wc_fontsiz_textNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; - mar_set_font(NHW_TEXT,iflags.wc_font_text,iflags.wc_fontsiz_text); - return; - } - if( stricmp( pref, "scroll_margin")==0 ) { - mar_set_margin(iflags.wc_scroll_margin); - Gem_cliparound(u.ux, u.uy); - return; - } - if( stricmp( pref, "ascii_map")==0 ) { - mar_set_tile_mode(!iflags.wc_ascii_map); - doredraw(); - return; - } - if( stricmp( pref, "hilite_pet")==0 ){ - /* MAR -- works without doing something here. */ - return; - } - if( stricmp( pref, "align_message")==0){ - mar_set_msg_align(iflags.wc_align_message-ALIGN_BOTTOM); - return; - } - if(stricmp( pref, "align_status")==0 ){ - mar_set_status_align(iflags.wc_align_status-ALIGN_BOTTOM); - return; - } - if( stricmp( pref, "vary_msgcount")==0 ){ - mar_set_msg_visible(iflags.wc_vary_msgcount); - return; - } + if (stricmp(pref, "font_message") == 0 + || stricmp(pref, "font_size_message") == 0) { + if (iflags.wc_fontsiz_message < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_message > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; + mar_set_font(NHW_MESSAGE, iflags.wc_font_message, + iflags.wc_fontsiz_message); + return; + } + if (stricmp(pref, "font_map") == 0 + || stricmp(pref, "font_size_map") == 0) { + if (iflags.wc_fontsiz_map < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_map > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_map = NHFONT_DEFAULT_SIZE; + mar_set_font(NHW_MAP, iflags.wc_font_map, iflags.wc_fontsiz_map); + return; + } + if (stricmp(pref, "font_status") == 0 + || stricmp(pref, "font_size_status") == 0) { + if (iflags.wc_fontsiz_status < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_status > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; + mar_set_font(NHW_STATUS, iflags.wc_font_status, + iflags.wc_fontsiz_status); + return; + } + if (stricmp(pref, "font_menu") == 0 + || stricmp(pref, "font_size_menu") == 0) { + if (iflags.wc_fontsiz_menu < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_menu > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; + mar_set_font(NHW_MENU, iflags.wc_font_menu, iflags.wc_fontsiz_menu); + return; + } + if (stricmp(pref, "font_text") == 0 + || stricmp(pref, "font_size_text") == 0) { + if (iflags.wc_fontsiz_text < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_text > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; + mar_set_font(NHW_TEXT, iflags.wc_font_text, iflags.wc_fontsiz_text); + return; + } + if (stricmp(pref, "scroll_margin") == 0) { + mar_set_margin(iflags.wc_scroll_margin); + Gem_cliparound(u.ux, u.uy); + return; + } + if (stricmp(pref, "ascii_map") == 0) { + mar_set_tile_mode(!iflags.wc_ascii_map); + doredraw(); + return; + } + if (stricmp(pref, "hilite_pet") == 0) { + /* MAR -- works without doing something here. */ + return; + } + if (stricmp(pref, "align_message") == 0) { + mar_set_msg_align(iflags.wc_align_message - ALIGN_BOTTOM); + return; + } + if (stricmp(pref, "align_status") == 0) { + mar_set_status_align(iflags.wc_align_status - ALIGN_BOTTOM); + return; + } + if (stricmp(pref, "vary_msgcount") == 0) { + mar_set_msg_visible(iflags.wc_vary_msgcount); + return; + } } /* * Allocate a copy of the given string. If null, return a string of @@ -1228,12 +1226,13 @@ const char *pref; */ static char * copy_of(s) - const char *s; +const char *s; { - if (!s) s = nullstr; + if (!s) + s = nullstr; return strcpy((char *) alloc((unsigned) (strlen(s) + 1)), s); } -#endif /* GEM_GRAPHICS - +#endif /* GEM_GRAPHICS \ + \ /*wingem.c*/ diff --git a/win/gem/wingem1.c b/win/gem/wingem1.c index 471a595c3..a2c0c24ed 100644 --- a/win/gem/wingem1.c +++ b/win/gem/wingem1.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wingem1.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 wingem1.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */ /* NetHack 3.6 wingem1.c $Date: 2009/05/06 10:56:42 $ $Revision: 1.8 $ */ /* SCCS Id: @(#)wingem1.c 3.5 1999/12/10 */ /* Copyright (c) Christian Bressler 1999 */ @@ -6,8 +6,8 @@ #define __TCC_COMPAT__ -#include -#include +#include +#include #include #include #include @@ -23,8 +23,8 @@ typedef signed char schar; #include "wintype.h" #undef genericptr_t -#define NDECL(f) f(void) -#define FDECL(f,p) f p +#define NDECL(f) f(void) +#define FDECL(f, p) f p #define CHAR_P char #define SCHAR_P schar #define UCHAR_P uchar @@ -32,7 +32,7 @@ typedef signed char schar; #define SHORT_P short #define BOOLEAN_P boolean #define ALIGNTYP_P aligntyp -typedef signed char xchar; +typedef signed char xchar; #include "wingem.h" #undef CHAR_P #undef SCHAR_P @@ -44,7 +44,8 @@ typedef signed char xchar; #undef NDECL #undef FDECL -static char nullstr[]="", md[]="NetHack 3.6.0", strCancel[]="Cancel", strOk[]="Ok", strText[]="Text"; +static char nullstr[] = "", md[] = "NetHack 3.6.0", strCancel[] = "Cancel", + strOk[] = "Ok", strText[] = "Text"; extern winid WIN_MESSAGE, WIN_MAP, WIN_STATUS, WIN_INVEN; @@ -53,20 +54,22 @@ extern winid WIN_MESSAGE, WIN_MAP, WIN_STATUS, WIN_INVEN; #define COLNO 80 #define MSGLEN 100 -#define MAP_GADGETS NAME|MOVER|CLOSER|FULLER|LFARROW|RTARROW|UPARROW|DNARROW|VSLIDE|HSLIDE|SIZER|SMALLER -#define DIALOG_MODE AUTO_DIAL|MODAL|NO_ICONIFY +#define MAP_GADGETS \ + NAME | MOVER | CLOSER | FULLER | LFARROW | RTARROW | UPARROW | DNARROW \ + | VSLIDE | HSLIDE | SIZER | SMALLER +#define DIALOG_MODE AUTO_DIAL | MODAL | NO_ICONIFY /* * Keyboard translation tables. */ -#define C(c) (0x1f & (c)) -#define M(c) (0x80 | (c)) +#define C(c) (0x1f & (c)) +#define M(c) (0x80 | (c)) -#define KEYPADLO 0x61 -#define KEYPADHI 0x71 +#define KEYPADLO 0x61 +#define KEYPADHI 0x71 -#define PADKEYS (KEYPADHI - KEYPADLO + 1) -#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) +#define PADKEYS (KEYPADHI - KEYPADLO + 1) +#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI) /* * Keypad keys are translated to the normal values below. @@ -74,785 +77,896 @@ extern winid WIN_MESSAGE, WIN_MAP, WIN_STATUS, WIN_INVEN; * shift values below. */ static const struct pad { - char normal, shift, cntrl; -} keypad[PADKEYS] = { - {C('['), 'Q', C('[')}, /* UNDO */ - {'?', '/', '?'}, /* HELP */ - {'(', 'a', '('}, /* ( */ - {')', 'w', ')'}, /* ) */ - {'/', '/', '/'}, /* / */ - {C('p'), '$', C('p')}, /* * */ - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'h', 'H', C('h')}, /* 4 */ - {'.', '.', '.'}, - {'l', 'L', C('l')}, /* 6 */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, numpad[PADKEYS] = { - {C('['), 'Q', C('[')} , /* UNDO */ - {'?', '/', '?'}, /* HELP */ - {'(', 'a', '('}, /* ( */ - {')', 'w', ')'}, /* ) */ - {'/', '/', '/'}, /* / */ - {C('p'), '$', C('p')}, /* * */ - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'4', M('4'), '4'}, /* 4 */ - {'.', '.', '.'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + char normal, shift, cntrl; +} keypad[PADKEYS] = + { + { C('['), 'Q', C('[') }, /* UNDO */ + { '?', '/', '?' }, /* HELP */ + { '(', 'a', '(' }, /* ( */ + { ')', 'w', ')' }, /* ) */ + { '/', '/', '/' }, /* / */ + { C('p'), '$', C('p') }, /* * */ + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'h', 'H', C('h') }, /* 4 */ + { '.', '.', '.' }, + { 'l', 'L', C('l') }, /* 6 */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[PADKEYS] = { + { C('['), 'Q', C('[') }, /* UNDO */ + { '?', '/', '?' }, /* HELP */ + { '(', 'a', '(' }, /* ( */ + { ')', 'w', ')' }, /* ) */ + { '/', '/', '/' }, /* / */ + { C('p'), '$', C('p') }, /* * */ + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { '4', M('4'), '4' }, /* 4 */ + { '.', '.', '.' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; #define TBUFSZ 300 #define BUFSZ 256 -extern int yn_number; /* from decl.c */ -extern char toplines[TBUFSZ]; /* from decl.c */ -extern char mapped_menu_cmds[]; /* from options.c */ -extern int mar_iflags_numpad(void); /* from wingem.c */ -extern void Gem_raw_print(const char *); /* from wingem.c */ -extern int mar_hp_query(void); /* from wingem.c */ -extern int mar_get_msg_history(void); /* from wingem.c */ -extern int mar_get_msg_visible(void); /* from wingem.c */ -extern void mar_get_font(int,char **,int *);/* from wingem.c */ -extern int vdi2dev4[]; /* from load_img.c */ +extern int yn_number; /* from decl.c */ +extern char toplines[TBUFSZ]; /* from decl.c */ +extern char mapped_menu_cmds[]; /* from options.c */ +extern int mar_iflags_numpad(void); /* from wingem.c */ +extern void Gem_raw_print(const char *); /* from wingem.c */ +extern int mar_hp_query(void); /* from wingem.c */ +extern int mar_get_msg_history(void); /* from wingem.c */ +extern int mar_get_msg_visible(void); /* from wingem.c */ +extern void mar_get_font(int, char **, int *); /* from wingem.c */ +extern int vdi2dev4[]; /* from load_img.c */ -void recalc_msg_win(GRECT*); -void recalc_status_win(GRECT*); +void recalc_msg_win(GRECT *); +void recalc_status_win(GRECT *); void calc_std_winplace(int, GRECT *); -int (*v_mtext)(int,int,int,char*); -static int no_glyph; /* the int indicating there is no glyph */ +int (*v_mtext)(int, int, int, char *); +static int no_glyph; /* the int indicating there is no glyph */ IMG_header tile_image, titel_image, rip_image; -MFDB Tile_bilder, Map_bild, Titel_bild, Rip_bild, Black_bild, Pet_Mark, FontCol_Bild; -static int Tile_width=16, Tile_heigth=16, Tiles_per_line=20; -char *Tilefile=NULL; +MFDB Tile_bilder, Map_bild, Titel_bild, Rip_bild, Black_bild, Pet_Mark, + FontCol_Bild; +static int Tile_width = 16, Tile_heigth = 16, Tiles_per_line = 20; +char *Tilefile = NULL; /* pet_mark Design by Warwick Allison warwick@troll.no */ -static int pet_mark_data[]={0x0000,0x3600,0x7F00,0x7F00,0x3E00,0x1C00,0x0800}; -static short *normal_palette=NULL; +static int pet_mark_data[] = { 0x0000, 0x3600, 0x7F00, 0x7F00, + 0x3E00, 0x1C00, 0x0800 }; +static short *normal_palette = NULL; -static struct gw{ - WIN *gw_window; - int gw_type, gw_dirty; - GRECT gw_place; +static struct gw { + WIN *gw_window; + int gw_type, gw_dirty; + GRECT gw_place; } Gem_nhwindow[MAXWIN]; typedef struct { - int id; - int size; - int cw, ch; - int prop; + int id; + int size; + int cw, ch; + int prop; } NHGEM_FONT; /*struct gemmapdata {*/ - GRECT dirty_map_area={COLNO-1,ROWNO,0,0}; - int map_cursx=0, map_cursy=0, curs_col=WHITE; - int draw_cursor=TRUE, scroll_margin=-1; - NHGEM_FONT map_font; - SCROLL scroll_map; - char **map_glyphs=NULL; - dirty_rect *dr_map; +GRECT dirty_map_area = { COLNO - 1, ROWNO, 0, 0 }; +int map_cursx = 0, map_cursy = 0, curs_col = WHITE; +int draw_cursor = TRUE, scroll_margin = -1; +NHGEM_FONT map_font; +SCROLL scroll_map; +char **map_glyphs = NULL; +dirty_rect *dr_map; /*};*/ /*struct gemstatusdata{*/ - char **status_line; - int Anz_status_lines, status_w, status_align=FALSE; - NHGEM_FONT status_font; - dirty_rect *dr_stat; +char **status_line; +int Anz_status_lines, status_w, status_align = FALSE; +NHGEM_FONT status_font; +dirty_rect *dr_stat; /*};*/ /*struct gemmessagedata{*/ - int mar_message_pause=TRUE; - int mar_esc_pressed=FALSE; - int messages_pro_zug=0; - char **message_line; - int *message_age; - int msg_pos=0, msg_max=0, msg_anz=0, msg_width=0, msg_vis=3, msg_align=TRUE; - NHGEM_FONT msg_font; - dirty_rect *dr_msg; +int mar_message_pause = TRUE; +int mar_esc_pressed = FALSE; +int messages_pro_zug = 0; +char **message_line; +int *message_age; +int msg_pos = 0, msg_max = 0, msg_anz = 0, msg_width = 0, msg_vis = 3, + msg_align = TRUE; +NHGEM_FONT msg_font; +dirty_rect *dr_msg; /*};*/ /*struct geminvdata {*/ - SCROLL scroll_menu; - Gem_menu_item *invent_list; - int Anz_inv_lines=0, Inv_breite=16; - NHGEM_FONT menu_font; - int Inv_how; +SCROLL scroll_menu; +Gem_menu_item *invent_list; +int Anz_inv_lines = 0, Inv_breite = 16; +NHGEM_FONT menu_font; +int Inv_how; /*};*/ /*struct gemtextdata{*/ - char **text_lines; - int Anz_text_lines=0, text_width; - NHGEM_FONT text_font; - int use_rip=FALSE; - extern char** rip_line; +char **text_lines; +int Anz_text_lines = 0, text_width; +NHGEM_FONT text_font; +int use_rip = FALSE; +extern char **rip_line; /*};*/ -static OBJECT *zz_oblist[NHICON+1]; +static OBJECT *zz_oblist[NHICON + 1]; -MITEM scroll_keys[]={ -/* menu, key, state, mode, msg */ - {FAIL,key(CTRLLEFT,0),K_CTRL,PAGE_LEFT,FAIL}, - {FAIL,key(CTRLRIGHT,0),K_CTRL,PAGE_RIGHT,FAIL}, - {FAIL,key(SCANUP,0),K_SHIFT,PAGE_UP,FAIL}, - {FAIL,key(SCANDOWN,0),K_SHIFT,PAGE_DOWN,FAIL}, - {FAIL,key(SCANLEFT,0),0,LINE_LEFT,FAIL}, - {FAIL,key(SCANRIGHT,0),0,LINE_RIGHT,FAIL}, - {FAIL,key(SCANUP,0),0,LINE_UP,FAIL}, - {FAIL,key(SCANDOWN,0),0,LINE_DOWN,FAIL}, - {FAIL,key(SCANLEFT,0),K_SHIFT,LINE_START,FAIL}, - {FAIL,key(SCANRIGHT,0),K_SHIFT,LINE_END,FAIL}, - {FAIL,key(SCANUP,0),K_CTRL,WIN_START,FAIL}, - {FAIL,key(SCANDOWN,0),K_CTRL,WIN_END,FAIL}, - {FAIL,key(SCANHOME,0),K_SHIFT,WIN_END,FAIL}, - {FAIL,key(SCANHOME,0),0,WIN_START,FAIL} +MITEM scroll_keys[] = { + /* menu, key, state, mode, msg */ + { FAIL, key(CTRLLEFT, 0), K_CTRL, PAGE_LEFT, FAIL }, + { FAIL, key(CTRLRIGHT, 0), K_CTRL, PAGE_RIGHT, FAIL }, + { FAIL, key(SCANUP, 0), K_SHIFT, PAGE_UP, FAIL }, + { FAIL, key(SCANDOWN, 0), K_SHIFT, PAGE_DOWN, FAIL }, + { FAIL, key(SCANLEFT, 0), 0, LINE_LEFT, FAIL }, + { FAIL, key(SCANRIGHT, 0), 0, LINE_RIGHT, FAIL }, + { FAIL, key(SCANUP, 0), 0, LINE_UP, FAIL }, + { FAIL, key(SCANDOWN, 0), 0, LINE_DOWN, FAIL }, + { FAIL, key(SCANLEFT, 0), K_SHIFT, LINE_START, FAIL }, + { FAIL, key(SCANRIGHT, 0), K_SHIFT, LINE_END, FAIL }, + { FAIL, key(SCANUP, 0), K_CTRL, WIN_START, FAIL }, + { FAIL, key(SCANDOWN, 0), K_CTRL, WIN_END, FAIL }, + { FAIL, key(SCANHOME, 0), K_SHIFT, WIN_END, FAIL }, + { FAIL, key(SCANHOME, 0), 0, WIN_START, FAIL } }; -#define SCROLL_KEYS 14 +#define SCROLL_KEYS 14 static DIAINFO *Inv_dialog; -#define null_free(ptr) free(ptr), (ptr)=NULL -#define test_free(ptr) if(ptr) null_free(ptr) +#define null_free(ptr) free(ptr), (ptr) = NULL +#define test_free(ptr) \ + if (ptr) \ + null_free(ptr) -static char *Menu_title=NULL; +static char *Menu_title = NULL; void mar_display_nhwindow(winid); -void mar_check_hilight_status(void){} /* to be filled :-) */ +void +mar_check_hilight_status(void) +{ +} /* to be filled :-) */ static char *mar_copy_of(const char *); extern void panic(const char *, ...); -void *m_alloc(size_t amt){ - void *ptr; +void * +m_alloc(size_t amt) +{ + void *ptr; - ptr=malloc(amt); - if (!ptr) panic("Memory allocation failure; cannot get %lu bytes", amt); - return(ptr); + ptr = malloc(amt); + if (!ptr) + panic("Memory allocation failure; cannot get %lu bytes", amt); + return (ptr); } -void mar_clear_messagewin(void){ - int i, *ptr=message_age; +void +mar_clear_messagewin(void) +{ + int i, *ptr = message_age; - if(WIN_MESSAGE==WIN_ERR) return; - for(i=msg_anz;--i>=0;ptr++){ - if(*ptr) - Gem_nhwindow[WIN_MESSAGE].gw_dirty=TRUE; - *ptr=FALSE; - } - mar_message_pause=FALSE; + if (WIN_MESSAGE == WIN_ERR) + return; + for (i = msg_anz; --i >= 0; ptr++) { + if (*ptr) + Gem_nhwindow[WIN_MESSAGE].gw_dirty = TRUE; + *ptr = FALSE; + } + mar_message_pause = FALSE; - mar_display_nhwindow(WIN_MESSAGE); + mar_display_nhwindow(WIN_MESSAGE); } -void clipbrd_save(void *data,int cnt,boolean append,boolean is_inv){ - char path[MAX_PATH],*text,*crlf="\r\n"; - long handle; - int i; +void +clipbrd_save(void *data, int cnt, boolean append, boolean is_inv) +{ + char path[MAX_PATH], *text, *crlf = "\r\n"; + long handle; + int i; - if (data && cnt>0 && scrp_path(path,"scrap.txt") && (handle = append ? Fopen(path,1) : Fcreate(path,0))>0){ - if (append) - Fseek(0L,(int) handle,SEEK_END); - if(is_inv){ - Gem_menu_item *it=(Gem_menu_item *)data; + if (data && cnt > 0 && scrp_path(path, "scrap.txt") + && (handle = append ? Fopen(path, 1) : Fcreate(path, 0)) > 0) { + if (append) + Fseek(0L, (int) handle, SEEK_END); + if (is_inv) { + Gem_menu_item *it = (Gem_menu_item *) data; - for(;it;it=it->Gmi_next){ - text=it->Gmi_str; - Fwrite((int) handle,strlen(text),text); - Fwrite((int) handle,2L,crlf); - } - }else{ - for(i=0;iGmi_next) { + text = it->Gmi_str; + Fwrite((int) handle, strlen(text), text); + Fwrite((int) handle, 2L, crlf); + } + } else { + for (i = 0; i < cnt; i++) { + text = ((char **) data)[i] + 1; + Fwrite((int) handle, strlen(text), text); + Fwrite((int) handle, 2L, crlf); + } + } + Fclose((int) handle); - scrp_changed(SCF_TEXT,0x2e545854l); /* .TXT */ - } + scrp_changed(SCF_TEXT, 0x2e545854l); /* .TXT */ + } } -void move_win(WIN *z_win){ - GRECT frame=desk; +void +move_win(WIN *z_win) +{ + GRECT frame = desk; - v_set_mode(MD_XOR); - v_set_line(BLACK,1,1,0,0); - frame.g_w<<=1, frame.g_h<<=1; - if(graf_rt_dragbox(FALSE,&z_win->curr,&frame,&z_win->curr.g_x,&z_win->curr.g_y,NULL)) - window_size(z_win,&z_win->curr); - else - window_top(z_win); + v_set_mode(MD_XOR); + v_set_line(BLACK, 1, 1, 0, 0); + frame.g_w <<= 1, frame.g_h <<= 1; + if (graf_rt_dragbox(FALSE, &z_win->curr, &frame, &z_win->curr.g_x, + &z_win->curr.g_y, NULL)) + window_size(z_win, &z_win->curr); + else + window_top(z_win); } -void message_handler(int x, int y){ - switch(objc_find(zz_oblist[MSGWIN],ROOT,MAX_DEPTH,x,y)){ - case UPMSG: - if(msg_pos>msg_vis-1){ - msg_pos--; - Gem_nhwindow[WIN_MESSAGE].gw_dirty=TRUE; - mar_display_nhwindow(WIN_MESSAGE); - } - Event_Timer(50,0,TRUE); - break; - case DNMSG: - if(msg_pos msg_vis - 1) { + msg_pos--; + Gem_nhwindow[WIN_MESSAGE].gw_dirty = TRUE; + mar_display_nhwindow(WIN_MESSAGE); + } + Event_Timer(50, 0, TRUE); + break; + case DNMSG: + if (msg_pos < msg_max) { + msg_pos++; + Gem_nhwindow[WIN_MESSAGE].gw_dirty = TRUE; + mar_display_nhwindow(WIN_MESSAGE); + } + Event_Timer(50, 0, TRUE); + break; + case GRABMSGWIN: + default: + move_win(Gem_nhwindow[WIN_MESSAGE].gw_window); + break; + case -1: + break; + } } -int mar_ob_mapcenter(OBJECT *p_obj){ - WIN *p_w= WIN_MAP!=WIN_ERR ? Gem_nhwindow[WIN_MAP].gw_window : NULL; +int +mar_ob_mapcenter(OBJECT *p_obj) +{ + WIN *p_w = WIN_MAP != WIN_ERR ? Gem_nhwindow[WIN_MAP].gw_window : NULL; - if(p_obj && p_w){ - p_obj->ob_x=p_w->work.g_x+p_w->work.g_w/2-p_obj->ob_width/2; - p_obj->ob_y=p_w->work.g_y+p_w->work.g_h/2-p_obj->ob_height/2; - return(DIA_LASTPOS); - } - return(DIA_CENTERED); + if (p_obj && p_w) { + p_obj->ob_x = p_w->work.g_x + p_w->work.g_w / 2 - p_obj->ob_width / 2; + p_obj->ob_y = + p_w->work.g_y + p_w->work.g_h / 2 - p_obj->ob_height / 2; + return (DIA_LASTPOS); + } + return (DIA_CENTERED); } -/****************************** set_no_glyph *************************************/ +/****************************** set_no_glyph + * *************************************/ void mar_set_no_glyph(ng) int ng; { - no_glyph=ng; + no_glyph = ng; } void mar_set_tilefile(name) -char* name; +char *name; { - Tilefile=name; + Tilefile = name; } void mar_set_tilex(value) int value; { - Min(&value,32); - Max(&value,1); - Tile_width=value; + Min(&value, 32); + Max(&value, 1); + Tile_width = value; } void mar_set_tiley(value) int value; { - Min(&value,32); - Max(&value,1); - Tile_heigth=value; + Min(&value, 32); + Max(&value, 1); + Tile_heigth = value; } -/****************************** userdef_draw *************************************/ +/****************************** userdef_draw + * *************************************/ void rearrange_windows(void); -void mar_set_status_align(int sa){ - if(status_align!=sa){ - status_align=sa; - rearrange_windows(); - } +void +mar_set_status_align(int sa) +{ + if (status_align != sa) { + status_align = sa; + rearrange_windows(); + } } -void mar_set_msg_align(int ma){ - if(msg_align!=ma){ - msg_align=ma; - rearrange_windows(); - } +void +mar_set_msg_align(int ma) +{ + if (msg_align != ma) { + msg_align = ma; + rearrange_windows(); + } } -void mar_set_msg_visible(int mv){ - if(mv!=msg_vis){ - Max(&mv,1); - Min(&mv,min(msg_anz,20)); - Min(&mv,desk.g_h/msg_font.ch/2); - msg_vis=mv; - rearrange_windows(); - } +void +mar_set_msg_visible(int mv) +{ + if (mv != msg_vis) { + Max(&mv, 1); + Min(&mv, min(msg_anz, 20)); + Min(&mv, desk.g_h / msg_font.ch / 2); + msg_vis = mv; + rearrange_windows(); + } } /* size<0 cellheight; size>0 points */ -void mar_set_fontbyid(int type, int id, int size){ - int chardim[4]; - if(id<=0) - id=ibm_font_id; - if((size>-3 && size<3) || size<-20 || size>20) - size=-ibm_font; - /* MAR -- 17.Mar 2002 For now allow FNT_PROP only with NHW_TEXT */ - if(type!=NHW_TEXT && (FontInfo(id)->type & (FNT_PROP|FNT_ASCII))) - id=ibm_font_id; - switch(type){ - case NHW_MESSAGE: - if(msg_font.size==-size && msg_font.id==id) - break; - msg_font.size=-size; - msg_font.id=id; - msg_font.prop=FontInfo(id)->type & (FNT_PROP|FNT_ASCII); - v_set_text(msg_font.id,msg_font.size,BLACK,0,0,chardim); - msg_font.ch=chardim[3] ? chardim[3] : 1; - msg_font.cw=chardim[2] ? chardim[2] : 1; - msg_width=min(max_w/msg_font.cw-3,MSGLEN); - rearrange_windows(); - break; - case NHW_MAP: - if(map_font.size!=-size || map_font.id!=id){ - MFDB mtmp; - map_font.size=-size; - map_font.id=id; - map_font.prop=FontInfo(id)->type & (FNT_PROP|FNT_ASCII); - v_set_text(map_font.id,map_font.size,BLACK,0,0,chardim); - map_font.ch=chardim[3] ? chardim[3] : 1; - map_font.cw=chardim[2] ? chardim[2] : 1; - mfdb(&mtmp,NULL,(COLNO-1)*map_font.cw, ROWNO*map_font.ch, 0, planes); - if(mfdb_size(&mtmp)>mfdb_size(&FontCol_Bild) && mfdb_size(&mtmp)>mfdb_size(&Map_bild)){ - FontCol_Bild.fd_addr=Map_bild.fd_addr=(int *)realloc(Map_bild.fd_addr,mfdb_size(&mtmp)); - if(!Map_bild.fd_addr) /* FIXME -- Not really neccessary since the former space is still valid */ - panic("Not enough Space for the map."); - } - mfdb(&FontCol_Bild,FontCol_Bild.fd_addr,(COLNO-1)*map_font.cw, ROWNO*map_font.ch, 0, planes); - rearrange_windows(); - } - break; - case NHW_STATUS: - if(status_font.size==-size && status_font.id==id) - break; - status_font.size=-size; - status_font.id=id; - status_font.prop=FontInfo(id)->type & (FNT_PROP|FNT_ASCII); - v_set_text(status_font.id,status_font.size,BLACK,0,0,chardim); - status_font.ch=chardim[3] ? chardim[3] : 1; - status_font.cw=chardim[2] ? chardim[2] : 1; - rearrange_windows(); - break; - case NHW_MENU: - if(menu_font.size==-size && menu_font.id==id) - break; - menu_font.size=-size; - menu_font.id=id; - menu_font.prop=FontInfo(id)->type & (FNT_PROP|FNT_ASCII); - v_set_text(menu_font.id,menu_font.size,BLACK,0,0,chardim); - menu_font.ch=chardim[3] ? chardim[3] : 1; - menu_font.cw=chardim[2] ? chardim[2] : 1; - break; - case NHW_TEXT: - if(text_font.size==-size && text_font.id==id) - break; - text_font.size=-size; - text_font.id=id; - text_font.prop=FontInfo(id)->type & (FNT_PROP|FNT_ASCII); - v_set_text(text_font.id,text_font.size,BLACK,0,0,chardim); - text_font.ch=chardim[3] ? chardim[3] : 1; - text_font.cw=chardim[2] ? chardim[2] : 1; - break; - default: - break; - } +void +mar_set_fontbyid(int type, int id, int size) +{ + int chardim[4]; + if (id <= 0) + id = ibm_font_id; + if ((size > -3 && size < 3) || size < -20 || size > 20) + size = -ibm_font; + /* MAR -- 17.Mar 2002 For now allow FNT_PROP only with NHW_TEXT */ + if (type != NHW_TEXT && (FontInfo(id)->type & (FNT_PROP | FNT_ASCII))) + id = ibm_font_id; + switch (type) { + case NHW_MESSAGE: + if (msg_font.size == -size && msg_font.id == id) + break; + msg_font.size = -size; + msg_font.id = id; + msg_font.prop = FontInfo(id)->type & (FNT_PROP | FNT_ASCII); + v_set_text(msg_font.id, msg_font.size, BLACK, 0, 0, chardim); + msg_font.ch = chardim[3] ? chardim[3] : 1; + msg_font.cw = chardim[2] ? chardim[2] : 1; + msg_width = min(max_w / msg_font.cw - 3, MSGLEN); + rearrange_windows(); + break; + case NHW_MAP: + if (map_font.size != -size || map_font.id != id) { + MFDB mtmp; + map_font.size = -size; + map_font.id = id; + map_font.prop = FontInfo(id)->type & (FNT_PROP | FNT_ASCII); + v_set_text(map_font.id, map_font.size, BLACK, 0, 0, chardim); + map_font.ch = chardim[3] ? chardim[3] : 1; + map_font.cw = chardim[2] ? chardim[2] : 1; + mfdb(&mtmp, NULL, (COLNO - 1) * map_font.cw, ROWNO * map_font.ch, + 0, planes); + if (mfdb_size(&mtmp) > mfdb_size(&FontCol_Bild) + && mfdb_size(&mtmp) > mfdb_size(&Map_bild)) { + FontCol_Bild.fd_addr = Map_bild.fd_addr = + (int *) realloc(Map_bild.fd_addr, mfdb_size(&mtmp)); + if (!Map_bild.fd_addr) /* FIXME -- Not really neccessary since + the former space is still valid */ + panic("Not enough Space for the map."); + } + mfdb(&FontCol_Bild, FontCol_Bild.fd_addr, + (COLNO - 1) * map_font.cw, ROWNO * map_font.ch, 0, planes); + rearrange_windows(); + } + break; + case NHW_STATUS: + if (status_font.size == -size && status_font.id == id) + break; + status_font.size = -size; + status_font.id = id; + status_font.prop = FontInfo(id)->type & (FNT_PROP | FNT_ASCII); + v_set_text(status_font.id, status_font.size, BLACK, 0, 0, chardim); + status_font.ch = chardim[3] ? chardim[3] : 1; + status_font.cw = chardim[2] ? chardim[2] : 1; + rearrange_windows(); + break; + case NHW_MENU: + if (menu_font.size == -size && menu_font.id == id) + break; + menu_font.size = -size; + menu_font.id = id; + menu_font.prop = FontInfo(id)->type & (FNT_PROP | FNT_ASCII); + v_set_text(menu_font.id, menu_font.size, BLACK, 0, 0, chardim); + menu_font.ch = chardim[3] ? chardim[3] : 1; + menu_font.cw = chardim[2] ? chardim[2] : 1; + break; + case NHW_TEXT: + if (text_font.size == -size && text_font.id == id) + break; + text_font.size = -size; + text_font.id = id; + text_font.prop = FontInfo(id)->type & (FNT_PROP | FNT_ASCII); + v_set_text(text_font.id, text_font.size, BLACK, 0, 0, chardim); + text_font.ch = chardim[3] ? chardim[3] : 1; + text_font.cw = chardim[2] ? chardim[2] : 1; + break; + default: + break; + } } -void mar_set_font(int type, const char *font_name, int size){ - int id=0; - /* MAR -- 17.Mar 2002 usual Gem behavior, use the Font-ID */ - if(font_name && *font_name){ - id=atoi(font_name); - if(id<=0){ - int i, tid; - char name[32]; - for(i=fonts_loaded;--i>=0;){ - tid=vqt_name(x_handle,i,name); - if(!stricmp(name,font_name)){ - id=tid; - break; - } - } - } - } - mar_set_fontbyid(type,id,size); +void +mar_set_font(int type, const char *font_name, int size) +{ + int id = 0; + /* MAR -- 17.Mar 2002 usual Gem behavior, use the Font-ID */ + if (font_name && *font_name) { + id = atoi(font_name); + if (id <= 0) { + int i, tid; + char name[32]; + for (i = fonts_loaded; --i >= 0;) { + tid = vqt_name(x_handle, i, name); + if (!stricmp(name, font_name)) { + id = tid; + break; + } + } + } + } + mar_set_fontbyid(type, id, size); } -void rearrange_windows(void){ - GRECT area; - int todo=TRUE; - if(WIN_MAP != WIN_ERR && Gem_nhwindow[WIN_MAP].gw_window){ - scroll_map.px_hline=mar_set_tile_mode(FAIL)?Tile_width:map_font.cw; - scroll_map.px_vline=mar_set_tile_mode(FAIL)?Tile_heigth:map_font.ch; - if(todo){ - calc_std_winplace(FAIL,&area); - todo=FALSE; - } - calc_std_winplace(NHW_MAP,&area); - Gem_nhwindow[WIN_MAP].gw_window->max.g_w=area.g_w; - Gem_nhwindow[WIN_MAP].gw_window->max.g_h=area.g_h; - Gem_nhwindow[WIN_MAP].gw_window->max.g_w=area.g_w; - window_reinit(Gem_nhwindow[WIN_MAP].gw_window,md,md,NULL,FALSE,FALSE); - { - int buf[8]; - buf[3]=K_CTRL; - buf[4]=C('L'); - AvSendMsg(ap_id,AV_SENDKEY,buf); - } - } - if(WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window){ - if(todo){ - calc_std_winplace(FAIL,&area); - todo=FALSE; - } - calc_std_winplace(NHW_MESSAGE,&area); - Gem_nhwindow[WIN_MESSAGE].gw_window->min_h=area.g_h; - window_size(Gem_nhwindow[WIN_MESSAGE].gw_window,&area); - redraw_window(Gem_nhwindow[WIN_MESSAGE].gw_window,NULL); - } - if(WIN_STATUS != WIN_ERR && Gem_nhwindow[WIN_STATUS].gw_window){ - if(todo){ - calc_std_winplace(FAIL,&area); - todo=FALSE; - } - calc_std_winplace(NHW_STATUS,&area); - Gem_nhwindow[WIN_STATUS].gw_window->min_h=area.g_h; - window_size(Gem_nhwindow[WIN_STATUS].gw_window,&area); - redraw_window(Gem_nhwindow[WIN_STATUS].gw_window,NULL); - } +void +rearrange_windows(void) +{ + GRECT area; + int todo = TRUE; + if (WIN_MAP != WIN_ERR && Gem_nhwindow[WIN_MAP].gw_window) { + scroll_map.px_hline = + mar_set_tile_mode(FAIL) ? Tile_width : map_font.cw; + scroll_map.px_vline = + mar_set_tile_mode(FAIL) ? Tile_heigth : map_font.ch; + if (todo) { + calc_std_winplace(FAIL, &area); + todo = FALSE; + } + calc_std_winplace(NHW_MAP, &area); + Gem_nhwindow[WIN_MAP].gw_window->max.g_w = area.g_w; + Gem_nhwindow[WIN_MAP].gw_window->max.g_h = area.g_h; + Gem_nhwindow[WIN_MAP].gw_window->max.g_w = area.g_w; + window_reinit(Gem_nhwindow[WIN_MAP].gw_window, md, md, NULL, FALSE, + FALSE); + { + int buf[8]; + buf[3] = K_CTRL; + buf[4] = C('L'); + AvSendMsg(ap_id, AV_SENDKEY, buf); + } + } + if (WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) { + if (todo) { + calc_std_winplace(FAIL, &area); + todo = FALSE; + } + calc_std_winplace(NHW_MESSAGE, &area); + Gem_nhwindow[WIN_MESSAGE].gw_window->min_h = area.g_h; + window_size(Gem_nhwindow[WIN_MESSAGE].gw_window, &area); + redraw_window(Gem_nhwindow[WIN_MESSAGE].gw_window, NULL); + } + if (WIN_STATUS != WIN_ERR && Gem_nhwindow[WIN_STATUS].gw_window) { + if (todo) { + calc_std_winplace(FAIL, &area); + todo = FALSE; + } + calc_std_winplace(NHW_STATUS, &area); + Gem_nhwindow[WIN_STATUS].gw_window->min_h = area.g_h; + window_size(Gem_nhwindow[WIN_STATUS].gw_window, &area); + redraw_window(Gem_nhwindow[WIN_STATUS].gw_window, NULL); + } } -void my_color_area(GRECT *area, int col){ - int pxy[4]; +void +my_color_area(GRECT *area, int col) +{ + int pxy[4]; - v_set_fill(col,1,IP_SOLID,0); - rc_grect_to_array(area,pxy); - v_bar(x_handle,pxy); + v_set_fill(col, 1, IP_SOLID, 0); + rc_grect_to_array(area, pxy); + v_bar(x_handle, pxy); } -void my_clear_area(GRECT *area){ - my_color_area(area, WHITE); +void +my_clear_area(GRECT *area) +{ + my_color_area(area, WHITE); } int mar_set_tile_mode(int); -static void win_draw_map(int first, WIN *win, GRECT *area){ - int pla[8], w=area->g_w-1, h=area->g_h-1; - int i, x, y; - GRECT back=*area; +static void +win_draw_map(int first, WIN *win, GRECT *area) +{ + int pla[8], w = area->g_w - 1, h = area->g_h - 1; + int i, x, y; + GRECT back = *area; - first=first; + first = first; - if(!mar_set_tile_mode(FAIL)){ - int start=(area->g_x-win->work.g_x)/map_font.cw+scroll_map.hpos; - int stop=(area->g_x+area->g_w+map_font.cw-1-win->work.g_x)/map_font.cw+scroll_map.hpos; - int starty=(area->g_y-win->work.g_y)/map_font.ch+scroll_map.vpos; - int stopy=min((area->g_y+area->g_h+map_font.ch-1-win->work.g_y)/map_font.ch+scroll_map.vpos,ROWNO); - char tmp; - v_set_text(map_font.id,map_font.size,WHITE,0,0,NULL); - v_set_mode(MD_TRANS); + if (!mar_set_tile_mode(FAIL)) { + int start = + (area->g_x - win->work.g_x) / map_font.cw + scroll_map.hpos; + int stop = (area->g_x + area->g_w + map_font.cw - 1 - win->work.g_x) + / map_font.cw + + scroll_map.hpos; + int starty = + (area->g_y - win->work.g_y) / map_font.ch + scroll_map.vpos; + int stopy = min((area->g_y + area->g_h + map_font.ch - 1 + - win->work.g_y) / map_font.ch + + scroll_map.vpos, + ROWNO); + char tmp; + v_set_text(map_font.id, map_font.size, WHITE, 0, 0, NULL); + v_set_mode(MD_TRANS); - x=win->work.g_x-scroll_map.px_hpos+start*map_font.cw; - y=win->work.g_y-scroll_map.px_vpos+starty*map_font.ch; - pla[2]=pla[0]=scroll_map.px_hpos+area->g_x-win->work.g_x; - pla[3]=pla[1]=starty*map_font.ch; - pla[2]+=w; - pla[3]+=map_font.ch-1; - pla[6]=pla[4]=area->g_x; /* x_wert to */ - pla[7]=pla[5]=y; /* y_wert to */ - pla[6]+=w; - pla[7]+=map_font.ch-1; - back.g_h=map_font.ch; - for(i=starty;ig_x-win->work.g_x; - pla[3]=pla[1]=scroll_map.px_vpos+area->g_y-win->work.g_y; - pla[2]+=w; - pla[3]+=h; - pla[6]=pla[4]=area->g_x; /* x_wert to */ - pla[7]=pla[5]=area->g_y; /* y_wert to */ - pla[6]+=w; - pla[7]+=h; - vro_cpyfm(x_handle, S_ONLY, pla, &Map_bild, screen); - } + x = win->work.g_x - scroll_map.px_hpos + start * map_font.cw; + y = win->work.g_y - scroll_map.px_vpos + starty * map_font.ch; + pla[2] = pla[0] = scroll_map.px_hpos + area->g_x - win->work.g_x; + pla[3] = pla[1] = starty * map_font.ch; + pla[2] += w; + pla[3] += map_font.ch - 1; + pla[6] = pla[4] = area->g_x; /* x_wert to */ + pla[7] = pla[5] = y; /* y_wert to */ + pla[6] += w; + pla[7] += map_font.ch - 1; + back.g_h = map_font.ch; + for (i = starty; i < stopy; i++, y += map_font.ch, + pla[1] += map_font.ch, pla[3] += map_font.ch, + pla[5] += map_font.ch, pla[7] += map_font.ch) { + back.g_y = y; + my_color_area(&back, BLACK); + tmp = map_glyphs[i][stop]; + map_glyphs[i][stop] = 0; + (*v_mtext)(x_handle, x, y, &map_glyphs[i][start]); + map_glyphs[i][stop] = tmp; + vro_cpyfm(x_handle, S_OR_D, pla, &FontCol_Bild, screen); + } + } else { + v_set_mode(MD_REPLACE); + pla[2] = pla[0] = scroll_map.px_hpos + area->g_x - win->work.g_x; + pla[3] = pla[1] = scroll_map.px_vpos + area->g_y - win->work.g_y; + pla[2] += w; + pla[3] += h; + pla[6] = pla[4] = area->g_x; /* x_wert to */ + pla[7] = pla[5] = area->g_y; /* y_wert to */ + pla[6] += w; + pla[7] += h; + vro_cpyfm(x_handle, S_ONLY, pla, &Map_bild, screen); + } - if(draw_cursor){ - v_set_line(curs_col,1,1,0,0); - pla[0]=pla[2]=win->work.g_x+scroll_map.px_hline*(map_cursx-scroll_map.hpos); - pla[1]=pla[3]=win->work.g_y+scroll_map.px_vline*(map_cursy-scroll_map.vpos); - pla[2]+=scroll_map.px_hline-1; - pla[3]+=scroll_map.px_vline-1; - v_rect(pla[0],pla[1],pla[2],pla[3]); - } + if (draw_cursor) { + v_set_line(curs_col, 1, 1, 0, 0); + pla[0] = pla[2] = + win->work.g_x + + scroll_map.px_hline * (map_cursx - scroll_map.hpos); + pla[1] = pla[3] = + win->work.g_y + + scroll_map.px_vline * (map_cursy - scroll_map.vpos); + pla[2] += scroll_map.px_hline - 1; + pla[3] += scroll_map.px_vline - 1; + v_rect(pla[0], pla[1], pla[2], pla[3]); + } } -static int draw_titel(PARMBLK *pb){ - static int pla[8]; - GRECT work=*(GRECT *) &pb->pb_x; +static int +draw_titel(PARMBLK *pb) +{ + static int pla[8]; + GRECT work = *(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&work)){ - pla[0]=pla[1]=0; - pla[2]=pb->pb_w-1; - pla[3]=pb->pb_h-1; - pla[6]=pla[4]=pb->pb_x; /* x_wert to */ - pla[7]=pla[5]=pb->pb_y; /* y_wert to */ - pla[6]+=pb->pb_w-1; - pla[7]+=pb->pb_h-1; + if (rc_intersect((GRECT *) &pb->pb_xc, &work)) { + pla[0] = pla[1] = 0; + pla[2] = pb->pb_w - 1; + pla[3] = pb->pb_h - 1; + pla[6] = pla[4] = pb->pb_x; /* x_wert to */ + pla[7] = pla[5] = pb->pb_y; /* y_wert to */ + pla[6] += pb->pb_w - 1; + pla[7] += pb->pb_h - 1; - vro_cpyfm(x_handle, S_ONLY, pla, &Titel_bild, screen); - } + vro_cpyfm(x_handle, S_ONLY, pla, &Titel_bild, screen); + } - return(0); + return (0); } -static int draw_lines(PARMBLK *pb){ - GRECT area=*(GRECT *) &pb->pb_x; +static int +draw_lines(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - char **ptr; - int x=pb->pb_x,y=pb->pb_y,start_line=(area.g_y-y); + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + char **ptr; + int x = pb->pb_x, y = pb->pb_y, start_line = (area.g_y - y); - v_set_mode((text_font.cw&7)==0 && text_font.prop==0 ? MD_REPLACE : MD_TRANS); + v_set_mode((text_font.cw & 7) == 0 && text_font.prop == 0 ? MD_REPLACE + : MD_TRANS); -/* void v_set_text(int font,int height,int color,int effect,int rotate,int out[4]) */ - v_set_text(text_font.id,text_font.size,BLACK,0,0,NULL); - start_line /= text_font.ch; - y+=start_line*text_font.ch; - x-=(int)scroll_menu.px_hpos; - ptr=&text_lines[start_line+=scroll_menu.vpos]; - start_line = min((area.g_y-y+area.g_h+text_font.ch-1)/text_font.ch,Anz_text_lines-start_line); - area.g_h=text_font.ch; - Vsync(); -/* x=(x+7) & ~7;*/ - for(;--start_line>=0;y+=text_font.ch){ - area.g_y=y; - my_clear_area(&area); - if(**ptr-1){ - v_set_text(FAIL,0,BLUE,0x01,0,NULL); - (*v_mtext)(x_handle,x,y,(*ptr++)+1); - v_set_text(FAIL,0,BLACK,0x00,0,NULL); - }else - (*v_mtext)(x_handle,x,y,(*ptr++)+1); - } - } - return(0); + /* void v_set_text(int font,int height,int color,int effect,int + * rotate,int out[4]) */ + v_set_text(text_font.id, text_font.size, BLACK, 0, 0, NULL); + start_line /= text_font.ch; + y += start_line * text_font.ch; + x -= (int) scroll_menu.px_hpos; + ptr = &text_lines[start_line += scroll_menu.vpos]; + start_line = + min((area.g_y - y + area.g_h + text_font.ch - 1) / text_font.ch, + Anz_text_lines - start_line); + area.g_h = text_font.ch; + Vsync(); + /* x=(x+7) & ~7;*/ + for (; --start_line >= 0; y += text_font.ch) { + area.g_y = y; + my_clear_area(&area); + if (**ptr - 1) { + v_set_text(FAIL, 0, BLUE, 0x01, 0, NULL); + (*v_mtext)(x_handle, x, y, (*ptr++) + 1); + v_set_text(FAIL, 0, BLACK, 0x00, 0, NULL); + } else + (*v_mtext)(x_handle, x, y, (*ptr++) + 1); + } + } + return (0); } -static int draw_rip(PARMBLK *pb){ - GRECT area=*(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - char **ptr; - int x=pb->pb_x,y=pb->pb_y,start_line=(area.g_y-y), chardim[4], pla[8],i; - v_set_mode(MD_REPLACE); -/* void v_set_text(int font,int height,int color,int effect,int rotate,int out[4]) */ - v_set_text(text_font.id,text_font.size,BLACK,0,0,chardim); - start_line /= text_font.ch; - y+=start_line*text_font.ch; - x-=scroll_menu.px_hpos; - ptr=&text_lines[start_line+=scroll_menu.vpos]; - start_line = min((area.g_y-y+area.g_h+text_font.ch-1)/text_font.ch,Anz_text_lines-start_line); - area.g_h=text_font.ch; - Vsync(); - x=(x+7) & ~7; - for(;--start_line>=0;y+=text_font.ch){ - area.g_y=y; - my_clear_area(&area); - if(**ptr-1){ - v_set_text(FAIL,0,BLUE,0x01,0,NULL); - (*v_mtext)(x_handle,x,y,(*ptr++)+1); - v_set_text(FAIL,0,BLACK,0x00,0,NULL); - }else - (*v_mtext)(x_handle,x,y,(*ptr++)+1); - } - pla[0]=pla[1]=0; - pla[2]=min(pb->pb_w-1,Rip_bild.fd_w-1); - pla[3]=min(pb->pb_h-1,Rip_bild.fd_h-1); - pla[6]=pla[4]=pb->pb_x+(pb->pb_w-Rip_bild.fd_w)/2; /* x_wert to */ - pla[7]=pla[5]=pb->pb_y; /* y_wert to */ - pla[6]+=pla[2]; - pla[7]+=pla[3]; - vro_cpyfm(x_handle, S_ONLY, pla, &Rip_bild, screen); - v_set_mode(MD_TRANS); - vst_alignment(x_handle,1,5,&i,&i); - pla[5]+=64; - for(i=0;i<7;i++,pla[5]+=chardim[3]){ - v_set_text(text_font.id,(i==0 || i==6) ? text_font.size : 12,WHITE,1,0,chardim); - (*v_mtext)(x_handle,pla[4]+157,pla[5],rip_line[i]); - v_set_text(text_font.id,(i==0 || i==6) ? text_font.size : 12,BLACK,0,0,chardim); - (*v_mtext)(x_handle,pla[4]+157,pla[5],rip_line[i]); - } - vst_alignment(x_handle,0,5,&i,&i); - } - return(0); +static int +draw_rip(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + char **ptr; + int x = pb->pb_x, y = pb->pb_y, start_line = (area.g_y - y), + chardim[4], pla[8], i; + v_set_mode(MD_REPLACE); + /* void v_set_text(int font,int height,int color,int effect,int + * rotate,int out[4]) */ + v_set_text(text_font.id, text_font.size, BLACK, 0, 0, chardim); + start_line /= text_font.ch; + y += start_line * text_font.ch; + x -= scroll_menu.px_hpos; + ptr = &text_lines[start_line += scroll_menu.vpos]; + start_line = + min((area.g_y - y + area.g_h + text_font.ch - 1) / text_font.ch, + Anz_text_lines - start_line); + area.g_h = text_font.ch; + Vsync(); + x = (x + 7) & ~7; + for (; --start_line >= 0; y += text_font.ch) { + area.g_y = y; + my_clear_area(&area); + if (**ptr - 1) { + v_set_text(FAIL, 0, BLUE, 0x01, 0, NULL); + (*v_mtext)(x_handle, x, y, (*ptr++) + 1); + v_set_text(FAIL, 0, BLACK, 0x00, 0, NULL); + } else + (*v_mtext)(x_handle, x, y, (*ptr++) + 1); + } + pla[0] = pla[1] = 0; + pla[2] = min(pb->pb_w - 1, Rip_bild.fd_w - 1); + pla[3] = min(pb->pb_h - 1, Rip_bild.fd_h - 1); + pla[6] = pla[4] = + pb->pb_x + (pb->pb_w - Rip_bild.fd_w) / 2; /* x_wert to */ + pla[7] = pla[5] = pb->pb_y; /* y_wert to */ + pla[6] += pla[2]; + pla[7] += pla[3]; + vro_cpyfm(x_handle, S_ONLY, pla, &Rip_bild, screen); + v_set_mode(MD_TRANS); + vst_alignment(x_handle, 1, 5, &i, &i); + pla[5] += 64; + for (i = 0; i < 7; i++, pla[5] += chardim[3]) { + v_set_text(text_font.id, (i == 0 || i == 6) ? text_font.size : 12, + WHITE, 1, 0, chardim); + (*v_mtext)(x_handle, pla[4] + 157, pla[5], rip_line[i]); + v_set_text(text_font.id, (i == 0 || i == 6) ? text_font.size : 12, + BLACK, 0, 0, chardim); + (*v_mtext)(x_handle, pla[4] + 157, pla[5], rip_line[i]); + } + vst_alignment(x_handle, 0, 5, &i, &i); + } + return (0); } -static int draw_msgline(PARMBLK *pb){ - GRECT area=*(GRECT *) &pb->pb_x; +static int +draw_msgline(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - int x=pb->pb_x, y=pb->pb_y+(msg_vis-1)*msg_font.ch, foo, i; - char **ptr=&message_line[msg_pos], tmp; - int startx, stopx, starty, stopy; + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + int x = pb->pb_x, y = pb->pb_y + (msg_vis - 1) * msg_font.ch, foo, i; + char **ptr = &message_line[msg_pos], tmp; + int startx, stopx, starty, stopy; - x=(x+7) & ~7; /* Byte alignment speeds output up */ + x = (x + 7) & ~7; /* Byte alignment speeds output up */ - v_set_mode(MD_REPLACE); + v_set_mode(MD_REPLACE); -/* void v_set_text(int font,int height,int color,int effect,int rotate,int out[4]) */ - v_set_text(msg_font.id,msg_font.size,FAIL, FAIL,0,NULL); - vst_alignment(x_handle,0,5,&foo,&foo); - stopy=min(msg_pos,msg_vis); -/* Vsync();*/ - startx=(area.g_x-x)/msg_font.cw-1; /* MAR 06.02.2001 -- because italic covers the next char */ - Max(&startx,0); - stopx=(area.g_x+area.g_w+msg_font.cw-x-1)/msg_font.cw; - x+=startx*msg_font.cw; - for(i=0;ipb_x; +static int +draw_status(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; - area.g_x+=2*status_font.cw-2; - area.g_w-=2*status_font.cw-2; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - int x=pb->pb_x, y=pb->pb_y, startx, stopx, starty, stopy, i; - char tmp; + area.g_x += 2 * status_font.cw - 2; + area.g_w -= 2 * status_font.cw - 2; + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + int x = pb->pb_x, y = pb->pb_y, startx, stopx, starty, stopy, i; + char tmp; -/* void v_set_text(int font,int height,int color,int effect,int rotate,int out[4]) */ - v_set_mode(MD_REPLACE); - v_set_text(status_font.id,status_font.size,BLACK,0,0,NULL); - x = (x+2*status_font.cw+6) & ~7; + /* void v_set_text(int font,int height,int color,int effect,int + * rotate,int out[4]) */ + v_set_mode(MD_REPLACE); + v_set_text(status_font.id, status_font.size, BLACK, 0, 0, NULL); + x = (x + 2 * status_font.cw + 6) & ~7; - startx=(area.g_x-x)/status_font.cw; - starty=(area.g_y-y)/status_font.ch; - stopx=(area.g_x+area.g_w+status_font.ch-1-x)/status_font.cw; - stopy=(area.g_y+area.g_h+status_font.ch-1-y)/status_font.ch; - Max(&startx,0); /* MAR -- Hmm, area.g_x could end up 1 below x */ - Max(&stopx,0); - x+=startx*status_font.cw; - y+=starty*status_font.ch; -/* Vsync();*/ - area.g_h=status_font.ch; - for(i=starty;ipb_x; +static int +draw_inventory(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - int gl, i, x=pb->pb_x, y=pb->pb_y,start_line=area.g_y-y; - Gem_menu_item *it; + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + int gl, i, x = pb->pb_x, y = pb->pb_y, start_line = area.g_y - y; + Gem_menu_item *it; - v_set_mode(MD_REPLACE); - v_set_text(menu_font.id,menu_font.size,BLACK,0,0,NULL); + v_set_mode(MD_REPLACE); + v_set_text(menu_font.id, menu_font.size, BLACK, 0, 0, NULL); - start_line /= menu_font.ch; - y+=start_line*menu_font.ch; - x-=scroll_menu.px_hpos; - start_line+=scroll_menu.vpos; + start_line /= menu_font.ch; + y += start_line * menu_font.ch; + x -= scroll_menu.px_hpos; + start_line += scroll_menu.vpos; - for(it=invent_list,i=start_line; --i>=0 && it; it=it->Gmi_next); + for (it = invent_list, i = start_line; --i >= 0 && it; + it = it->Gmi_next) + ; - i = min((area.g_y-y+area.g_h+menu_font.ch-1)/menu_font.ch,Anz_inv_lines-start_line); + i = min((area.g_y - y + area.g_h + menu_font.ch - 1) / menu_font.ch, + Anz_inv_lines - start_line); - Vsync(); - area.g_h=menu_font.ch; + Vsync(); + area.g_h = menu_font.ch; - for(;(--i>=0) && it;it=it->Gmi_next,y+=menu_font.ch){ - if(it->Gmi_attr) - v_set_text(FAIL,FALSE,BLUE,1,FAIL,NULL); /* Bold */ - else - v_set_text(FAIL,FALSE,BLACK,0,FAIL,NULL); + for (; (--i >= 0) && it; it = it->Gmi_next, y += menu_font.ch) { + if (it->Gmi_attr) + v_set_text(FAIL, FALSE, BLUE, 1, FAIL, NULL); /* Bold */ + else + v_set_text(FAIL, FALSE, BLACK, 0, FAIL, NULL); - area.g_y=y; - my_clear_area(&area); - if((gl=it->Gmi_glyph) != no_glyph){ - int pla[8], h=min(menu_font.ch,Tile_heigth)-1; + area.g_y = y; + my_clear_area(&area); + if ((gl = it->Gmi_glyph) != no_glyph) { + int pla[8], h = min(menu_font.ch, Tile_heigth) - 1; - pla[0]=pla[2]=(gl%Tiles_per_line)*Tile_width; /* x_wert from */ - pla[1]=pla[3]=(gl/Tiles_per_line)*Tile_heigth; /* y_wert from */ - pla[4]=pla[6]=x; /* x_wert to */ - pla[5]=pla[7]=y; /* y_wert to */ - pla[2]+=Tile_width-1; - pla[3]+=h; - pla[6]+=Tile_heigth-1; - pla[7]+=h; + pla[0] = pla[2] = + (gl % Tiles_per_line) * Tile_width; /* x_wert from */ + pla[1] = pla[3] = + (gl / Tiles_per_line) * Tile_heigth; /* y_wert from */ + pla[4] = pla[6] = x; /* x_wert to */ + pla[5] = pla[7] = y; /* y_wert to */ + pla[2] += Tile_width - 1; + pla[3] += h; + pla[6] += Tile_heigth - 1; + pla[7] += h; - vro_cpyfm(x_handle,S_ONLY,pla,&Tile_bilder,screen); - } - if(it->Gmi_identifier) - it->Gmi_str[2]=it->Gmi_selected ? (it->Gmi_count == -1L ? '+' : '#') : '-'; - (*v_mtext)(x_handle,(x+23) & ~7,y,it->Gmi_str); - } - } - return(0); + vro_cpyfm(x_handle, S_ONLY, pla, &Tile_bilder, screen); + } + if (it->Gmi_identifier) + it->Gmi_str[2] = it->Gmi_selected + ? (it->Gmi_count == -1L ? '+' : '#') + : '-'; + (*v_mtext)(x_handle, (x + 23) & ~7, y, it->Gmi_str); + } + } + return (0); } -static int draw_prompt(PARMBLK *pb){ - GRECT area=*(GRECT *) &pb->pb_x; +static int +draw_prompt(PARMBLK *pb) +{ + GRECT area = *(GRECT *) &pb->pb_x; - if(rc_intersect((GRECT *)&pb->pb_xc,&area)){ - char **ptr=(char **)pb->pb_parm; - int x=pb->pb_x, y=pb->pb_y, chardim[4]; + if (rc_intersect((GRECT *) &pb->pb_xc, &area)) { + char **ptr = (char **) pb->pb_parm; + int x = pb->pb_x, y = pb->pb_y, chardim[4]; -/* void v_set_text(int font,int height,int color,int effect,int rotate,int out[4]) */ - v_set_mode(MD_TRANS); - v_set_text(ibm_font_id,ibm_font,WHITE,0,0,chardim); - Vsync(); - if(planes<4){ - int pxy[4]; - v_set_fill(BLACK,2,4,0); - rc_grect_to_array(&area,pxy); - v_bar(x_handle,pxy); - }else - my_color_area(&area,LWHITE); - (*v_mtext)(x_handle,x,y,*(ptr++)); - if(*ptr) - (*v_mtext)(x_handle,x,y+chardim[3],*ptr); - } - return(0); + /* void v_set_text(int font,int height,int color,int effect,int + * rotate,int out[4]) */ + v_set_mode(MD_TRANS); + v_set_text(ibm_font_id, ibm_font, WHITE, 0, 0, chardim); + Vsync(); + if (planes < 4) { + int pxy[4]; + v_set_fill(BLACK, 2, 4, 0); + rc_grect_to_array(&area, pxy); + v_bar(x_handle, pxy); + } else + my_color_area(&area, LWHITE); + (*v_mtext)(x_handle, x, y, *(ptr++)); + if (*ptr) + (*v_mtext)(x_handle, x, y + chardim[3], *ptr); + } + return (0); } -static USERBLK ub_lines={draw_lines, 0L}, ub_msg={draw_msgline, 0L}, - ub_inventory={draw_inventory, 0L}, ub_titel={draw_titel, 0L}, - ub_status={draw_status, 0L}, ub_prompt={draw_prompt, 0L}; +static USERBLK ub_lines = { draw_lines, 0L }, ub_msg = { draw_msgline, 0L }, + ub_inventory = { draw_inventory, 0L }, + ub_titel = { draw_titel, 0L }, ub_status = { draw_status, 0L }, + ub_prompt = { draw_prompt, 0L }; /**************************** rsc_funktionen *****************************/ -void my_close_dialog(DIAINFO *dialog,boolean shrink_box){ - close_dialog(dialog,shrink_box); - Event_Timer(0,0,TRUE); +void +my_close_dialog(DIAINFO *dialog, boolean shrink_box) +{ + close_dialog(dialog, shrink_box); + Event_Timer(0, 0, TRUE); } void @@ -860,8 +974,8 @@ mar_get_rsc_tree(obj_number, z_ob_obj) int obj_number; OBJECT **z_ob_obj; { - rsrc_gaddr( R_TREE, obj_number, z_ob_obj ); - fix_objects(*z_ob_obj,SCALING,0,0); + rsrc_gaddr(R_TREE, obj_number, z_ob_obj); + fix_objects(*z_ob_obj, SCALING, 0, 0); } void mar_clear_map(void); @@ -870,213 +984,241 @@ void img_error(errnumber) int errnumber; { - char buf[BUFSZ]; + char buf[BUFSZ]; - switch(errnumber){ - case ERR_HEADER : - sprintf(buf,"%s","[1][ Image Header | corrupt. ][ Oops ]"); - break; - case ERR_ALLOC : - sprintf(buf,"%s","[1][ Not enough | memory for | an image. ][ Oops ]"); - break; - case ERR_FILE : - sprintf(buf,"%s","[1][ The Image-file | is not available ][ Oops ]"); - break; - case ERR_DEPACK : - sprintf(buf,"%s","[1][ The Image-file | is corrupt ][ Oops ]"); - break; - case ERR_COLOR : - sprintf(buf,"%s","[1][ Number of colors | not supported ][ Oops ]"); - break; - default: - sprintf(buf,"[1][ img_error | strange error | number: %i ][ Hmm ]",errnumber); - break; - } - form_alert(1,buf); + switch (errnumber) { + case ERR_HEADER: + sprintf(buf, "%s", "[1][ Image Header | corrupt. ][ Oops ]"); + break; + case ERR_ALLOC: + sprintf(buf, "%s", + "[1][ Not enough | memory for | an image. ][ Oops ]"); + break; + case ERR_FILE: + sprintf(buf, "%s", + "[1][ The Image-file | is not available ][ Oops ]"); + break; + case ERR_DEPACK: + sprintf(buf, "%s", "[1][ The Image-file | is corrupt ][ Oops ]"); + break; + case ERR_COLOR: + sprintf(buf, "%s", "[1][ Number of colors | not supported ][ Oops ]"); + break; + default: + sprintf(buf, "[1][ img_error | strange error | number: %i ][ Hmm ]", + errnumber); + break; + } + form_alert(1, buf); } -void mar_change_button_char(OBJECT *z_ob, int nr, char ch){ - *ob_get_text(z_ob,nr,0)=ch; - ob_set_hotkey(z_ob,nr,ch); +void +mar_change_button_char(OBJECT *z_ob, int nr, char ch) +{ + *ob_get_text(z_ob, nr, 0) = ch; + ob_set_hotkey(z_ob, nr, ch); } void mar_set_dir_keys() { - static int mi_numpad=FAIL; - char mcmd[]="bjnh.lyku", npcmd[]="123456789", *p_cmd; + static int mi_numpad = FAIL; + char mcmd[] = "bjnh.lyku", npcmd[] = "123456789", *p_cmd; - if(mi_numpad!=mar_iflags_numpad()){ - OBJECT *z_ob=zz_oblist[DIRECTION]; - int i; - mi_numpad=mar_iflags_numpad(); - ob_set_hotkey(z_ob,DIRDOWN,'>'); - ob_set_hotkey(z_ob,DIRUP,'<'); - p_cmd= mi_numpad ? npcmd : mcmd; - for(i=0;i<9;i++) - mar_change_button_char(z_ob,DIR1+2*i,p_cmd[i]); - } + if (mi_numpad != mar_iflags_numpad()) { + OBJECT *z_ob = zz_oblist[DIRECTION]; + int i; + mi_numpad = mar_iflags_numpad(); + ob_set_hotkey(z_ob, DIRDOWN, '>'); + ob_set_hotkey(z_ob, DIRUP, '<'); + p_cmd = mi_numpad ? npcmd : mcmd; + for (i = 0; i < 9; i++) + mar_change_button_char(z_ob, DIR1 + 2 * i, p_cmd[i]); + } } -extern int total_tiles_used; /* tile.c */ +extern int total_tiles_used; /* tile.c */ int mar_gem_init() { - int i, bild_fehler=FALSE, fsize; - char *fname; - static MITEM wish_workaround= {FAIL,key(0,'J'),K_CTRL,W_CYCLE,FAIL}; - OBJECT *z_ob; + int i, bild_fehler = FALSE, fsize; + char *fname; + static MITEM wish_workaround = { FAIL, key(0, 'J'), K_CTRL, W_CYCLE, + FAIL }; + OBJECT *z_ob; - if((i=open_rsc("gem_rsc.rsc",NULL,md,md,md,0,0,0))<=0){ - graf_mouse(M_OFF,NULL); - if(i<0) - form_alert(1,"[3][| Fatal Error | File: GEM_RSC.RSC | not found. ][ grumble ]"); - else - form_alert(1,"[3][| Fatal Error | GEM initialisation | failed. ][ a pity ]"); - return(0); - } - if(planes<1 || planes>8){ - form_alert(1,"[3][ Color-depth | not supported, | try 2-256 colors. ][ Ok ]"); - return(0); - } - MouseBee(); + if ((i = open_rsc("gem_rsc.rsc", NULL, md, md, md, 0, 0, 0)) <= 0) { + graf_mouse(M_OFF, NULL); + if (i < 0) + form_alert(1, "[3][| Fatal Error | File: GEM_RSC.RSC | not " + "found. ][ grumble ]"); + else + form_alert(1, "[3][| Fatal Error | GEM initialisation | failed. " + "][ a pity ]"); + return (0); + } + if (planes < 1 || planes > 8) { + form_alert( + 1, + "[3][ Color-depth | not supported, | try 2-256 colors. ][ Ok ]"); + return (0); + } + MouseBee(); - /* MAR -- 17.Mar 2002 NVDI 3.0 or better uses v_ftext */ - v_mtext= speedo==3 ? &v_ftext : &v_gtext; - for(i=0;i0 && planes<9){ - normal_palette=(short *)m_alloc(3*colors*sizeof(short)); - get_colors(x_handle,normal_palette, colors); - } + if (planes > 0 && planes < 9) { + normal_palette = (short *) m_alloc(3 * colors * sizeof(short)); + get_colors(x_handle, normal_palette, colors); + } loadimg: - bild_fehler=depack_img(Tilefile?Tilefile:(planes>=4)?"NH16.IMG":"NH2.IMG",&tile_image); - if(bild_fehler){ - z_ob=zz_oblist[ABOUT]; - ob_undraw_dialog(z_ob,0,0,0,0); - ob_hide(z_ob,OKABOUT,FALSE); - img_error(bild_fehler); - return(0); - } - if(tile_image.img_w%Tile_width || tile_image.img_h%Tile_heigth){ - Tilefile=NULL; - Tile_width=Tile_heigth=16; - printf("size didn't match.\n"); - goto loadimg; - } - if((tile_image.img_w/Tile_width)*(tile_image.img_h/Tile_heigth)= 4) ? "NH16.IMG" + : "NH2.IMG", + &tile_image); + if (bild_fehler) { + z_ob = zz_oblist[ABOUT]; + ob_undraw_dialog(z_ob, 0, 0, 0, 0); + ob_hide(z_ob, OKABOUT, FALSE); + img_error(bild_fehler); + return (0); + } + if (tile_image.img_w % Tile_width || tile_image.img_h % Tile_heigth) { + Tilefile = NULL; + Tile_width = Tile_heigth = 16; + printf("size didn't match.\n"); + goto loadimg; + } + if ((tile_image.img_w / Tile_width) * (tile_image.img_h / Tile_heigth) + < total_tiles_used) { + Tilefile = NULL; + Tile_width = Tile_heigth = 16; + printf("Too few Tiles in Image.\n"); + goto loadimg; + } + Tiles_per_line = tile_image.img_w / Tile_width; - if(planes>=4){ - if(tile_image.planes>1) - img_set_colors(x_handle, tile_image.palette, tile_image.planes); + if (planes >= 4) { + if (tile_image.planes > 1) + img_set_colors(x_handle, tile_image.palette, tile_image.planes); #if 0 else{ int mypalette[]={}; img_set_colors(x_handle, mypalette, 4); } #endif - } + } - mfdb(&Tile_bilder, (int *)tile_image.addr, tile_image.img_w, tile_image.img_h, 1, tile_image.planes); - transform_img(&Tile_bilder); + mfdb(&Tile_bilder, (int *) tile_image.addr, tile_image.img_w, + tile_image.img_h, 1, tile_image.planes); + transform_img(&Tile_bilder); - mfdb(&Map_bild,NULL,(COLNO-1)*Tile_width, ROWNO*Tile_heigth, 0, planes); - mfdb(&FontCol_Bild,NULL,(COLNO-1)*map_font.cw, ROWNO*map_font.ch, 0, planes); - Map_bild.fd_addr=(int *)m_alloc(mfdb_size(&Map_bild)>mfdb_size(&FontCol_Bild)?mfdb_size(&Map_bild):mfdb_size(&FontCol_Bild)); - FontCol_Bild.fd_addr=Map_bild.fd_addr; + mfdb(&Map_bild, NULL, (COLNO - 1) * Tile_width, ROWNO * Tile_heigth, 0, + planes); + mfdb(&FontCol_Bild, NULL, (COLNO - 1) * map_font.cw, ROWNO * map_font.ch, + 0, planes); + Map_bild.fd_addr = + (int *) m_alloc(mfdb_size(&Map_bild) > mfdb_size(&FontCol_Bild) + ? mfdb_size(&Map_bild) + : mfdb_size(&FontCol_Bild)); + FontCol_Bild.fd_addr = Map_bild.fd_addr; - mfdb(&Pet_Mark,pet_mark_data,8, 7, 1, 1); - vr_trnfm(x_handle,&Pet_Mark,&Pet_Mark); + mfdb(&Pet_Mark, pet_mark_data, 8, 7, 1, 1); + vr_trnfm(x_handle, &Pet_Mark, &Pet_Mark); - mfdb(&Black_bild,NULL,16, 32, 1, 1); /* MAR -- 17.Mar 2002 that should cover the biggest map-font */ - Black_bild.fd_addr=(int *)m_alloc(mfdb_size(&Black_bild)); - memset(Black_bild.fd_addr,255,mfdb_size(&Black_bild)); - vr_trnfm(x_handle,&Black_bild,&Black_bild); + mfdb(&Black_bild, NULL, 16, 32, 1, + 1); /* MAR -- 17.Mar 2002 that should cover the biggest map-font */ + Black_bild.fd_addr = (int *) m_alloc(mfdb_size(&Black_bild)); + memset(Black_bild.fd_addr, 255, mfdb_size(&Black_bild)); + vr_trnfm(x_handle, &Black_bild, &Black_bild); - for(i=0;i=0;) - if(Gem_nhwindow[i].gw_type) - mar_destroy_nhwindow(i); + for (i = MAXWIN; --i >= 0;) + if (Gem_nhwindow[i].gw_type) + mar_destroy_nhwindow(i); - if(normal_palette){ - img_set_colors(x_handle,normal_palette,tile_image.planes); - null_free(normal_palette); - } - test_free(tile_image.palette); - test_free(tile_image.addr); - test_free(titel_image.palette); - test_free(titel_image.addr); + if (normal_palette) { + img_set_colors(x_handle, normal_palette, tile_image.planes); + null_free(normal_palette); + } + test_free(tile_image.palette); + test_free(tile_image.addr); + test_free(titel_image.palette); + test_free(titel_image.addr); } /************************* mar_curs *******************************/ void -mar_curs(x,y) +mar_curs(x, y) int x, y; { - Min(&dirty_map_area.g_x,x); - Min(&dirty_map_area.g_y,y); - Max(&dirty_map_area.g_w,x); - Max(&dirty_map_area.g_h,y); - Min(&dirty_map_area.g_x,map_cursx); - Min(&dirty_map_area.g_y,map_cursy); - Max(&dirty_map_area.g_w,map_cursx); - Max(&dirty_map_area.g_h,map_cursy); + Min(&dirty_map_area.g_x, x); + Min(&dirty_map_area.g_y, y); + Max(&dirty_map_area.g_w, x); + Max(&dirty_map_area.g_h, y); + Min(&dirty_map_area.g_x, map_cursx); + Min(&dirty_map_area.g_y, map_cursy); + Max(&dirty_map_area.g_w, map_cursx); + Max(&dirty_map_area.g_h, map_cursy); - map_cursx=x; - map_cursy=y; + map_cursx = x; + map_cursy = y; - if(WIN_MAP!=WIN_ERR) - Gem_nhwindow[WIN_MAP].gw_dirty=TRUE; + if (WIN_MAP != WIN_ERR) + Gem_nhwindow[WIN_MAP].gw_dirty = TRUE; } void mar_cliparound(void); -void mar_map_curs_weiter(void) +void +mar_map_curs_weiter(void) { - static int once=TRUE; + static int once = TRUE; - if(once){ - redraw_window(Gem_nhwindow[WIN_STATUS].gw_window,NULL); - redraw_window(Gem_nhwindow[WIN_MESSAGE].gw_window,NULL); - once=FALSE; - } - mar_curs(map_cursx+1,map_cursy); - mar_cliparound(); + if (once) { + redraw_window(Gem_nhwindow[WIN_STATUS].gw_window, NULL); + redraw_window(Gem_nhwindow[WIN_MESSAGE].gw_window, NULL); + once = FALSE; + } + mar_curs(map_cursx + 1, map_cursy); + mar_cliparound(); } /************************* about *******************************/ @@ -1141,8 +1284,9 @@ void mar_map_curs_weiter(void) void mar_about() { - xdialog(zz_oblist[ABOUT], md, NULL, NULL, DIA_CENTERED, FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); + xdialog(zz_oblist[ABOUT], md, NULL, NULL, DIA_CENTERED, FALSE, + DIALOG_MODE); + Event_Timer(0, 0, TRUE); } /************************* ask_name *******************************/ @@ -1150,28 +1294,30 @@ mar_about() char * mar_ask_name() { - OBJECT *z_ob=zz_oblist[NAMEGET]; - int bild_fehler; - char who_are_you[] = "Who are you? "; + OBJECT *z_ob = zz_oblist[NAMEGET]; + int bild_fehler; + char who_are_you[] = "Who are you? "; - bild_fehler=depack_img(planes<4 ? "TITLE2.IMG" : "TITLE.IMG", &titel_image); - if(bild_fehler ){ /* MAR -- this isn't lethal */ - ob_set_text(z_ob,NETHACKPICTURE,"missing title.img."); - }else{ - mfdb(&Titel_bild, (int *)titel_image.addr, titel_image.img_w, titel_image.img_h, 1, titel_image.planes); - transform_img(&Titel_bild); - z_ob[NETHACKPICTURE].ob_type=G_USERDEF; - z_ob[NETHACKPICTURE].ob_spec.userblk=&ub_titel; - } + bild_fehler = + depack_img(planes < 4 ? "TITLE2.IMG" : "TITLE.IMG", &titel_image); + if (bild_fehler) { /* MAR -- this isn't lethal */ + ob_set_text(z_ob, NETHACKPICTURE, "missing title.img."); + } else { + mfdb(&Titel_bild, (int *) titel_image.addr, titel_image.img_w, + titel_image.img_h, 1, titel_image.planes); + transform_img(&Titel_bild); + z_ob[NETHACKPICTURE].ob_type = G_USERDEF; + z_ob[NETHACKPICTURE].ob_spec.userblk = &ub_titel; + } - ob_clear_edit(z_ob); - xdialog(z_ob,who_are_you, NULL, NULL, DIA_CENTERED, FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); + ob_clear_edit(z_ob); + xdialog(z_ob, who_are_you, NULL, NULL, DIA_CENTERED, FALSE, DIALOG_MODE); + Event_Timer(0, 0, TRUE); - test_free(titel_image.palette); - test_free(titel_image.addr); - test_free(Titel_bild.fd_addr); - return(ob_get_text(z_ob,PLNAME,0)); + test_free(titel_image.palette); + test_free(titel_image.addr); + test_free(Titel_bild.fd_addr); + return (ob_get_text(z_ob, PLNAME, 0)); } /************************* more *******************************/ @@ -1179,44 +1325,44 @@ mar_ask_name() void send_key(int key) { - int buf[8]; + int buf[8]; - buf[3]=0; /* No Shift/Ctrl/Alt */ - buf[4]=key; - AvSendMsg(ap_id,AV_SENDKEY,buf); + buf[3] = 0; /* No Shift/Ctrl/Alt */ + buf[4] = key; + AvSendMsg(ap_id, AV_SENDKEY, buf); } void send_return() { - send_key(key(SCANRET,0)); + send_key(key(SCANRET, 0)); } int -K_Init(xev,availiable) +K_Init(xev, availiable) XEVENT *xev; int availiable; { - xev=xev; - return(MU_KEYBD&availiable); + xev = xev; + return (MU_KEYBD & availiable); } int -KM_Init(xev,availiable) +KM_Init(xev, availiable) XEVENT *xev; int availiable; { - xev=xev; - return((MU_KEYBD|MU_MESAG)&availiable); + xev = xev; + return ((MU_KEYBD | MU_MESAG) & availiable); } int -M_Init(xev,availiable) +M_Init(xev, availiable) XEVENT *xev; int availiable; { - xev=xev; - return(MU_MESAG&availiable); + xev = xev; + return (MU_MESAG & availiable); } #define More_Init K_Init @@ -1225,53 +1371,58 @@ int More_Handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; + int ev = xev->ev_mwich; - if(ev&MU_KEYBD){ - char ch=(char)(xev->ev_mkreturn&0x00FF); - DIAINFO *dinf; - WIN *w; + if (ev & MU_KEYBD) { + char ch = (char) (xev->ev_mkreturn & 0x00FF); + DIAINFO *dinf; + WIN *w; - switch(ch){ - case '\033': /* no more more more */ - case ' ': - if((w=get_top_window()) && (dinf=(DIAINFO *)w->dialog) && dinf->di_tree==zz_oblist[PAGER]){ - if(ch=='\033') - mar_esc_pressed=TRUE; - send_return(); - break; - } - /* Fall thru */ - default: - ev &= ~MU_KEYBD; /* unknown key */ - break; - } - } - return(ev); + switch (ch) { + case '\033': /* no more more more */ + case ' ': + if ((w = get_top_window()) && (dinf = (DIAINFO *) w->dialog) + && dinf->di_tree == zz_oblist[PAGER]) { + if (ch == '\033') + mar_esc_pressed = TRUE; + send_return(); + break; + } + /* Fall thru */ + default: + ev &= ~MU_KEYBD; /* unknown key */ + break; + } + } + return (ev); } void mar_more() { - if(!mar_esc_pressed){ - OBJECT *z_ob=zz_oblist[PAGER]; - WIN *p_w; + if (!mar_esc_pressed) { + OBJECT *z_ob = zz_oblist[PAGER]; + WIN *p_w; - Event_Handler(More_Init,More_Handler); - dial_colors(7,RED,BLACK,RED,RED,BLACK,BLACK,BLACK,BLACK,WHITE,WHITE,WHITE,WHITE,TRUE,TRUE); - if(WIN_MESSAGE!=WIN_ERR && (p_w=Gem_nhwindow[WIN_MESSAGE].gw_window)){ - z_ob->ob_x=p_w->work.g_x; - z_ob->ob_y=p_w->curr.g_y+p_w->curr.g_h+gr_ch; - } - xdialog(z_ob,NULL, NULL, NULL, DIA_LASTPOS, FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); - Event_Handler(NULL,NULL); + Event_Handler(More_Init, More_Handler); + dial_colors(7, RED, BLACK, RED, RED, BLACK, BLACK, BLACK, BLACK, + WHITE, WHITE, WHITE, WHITE, TRUE, TRUE); + if (WIN_MESSAGE != WIN_ERR + && (p_w = Gem_nhwindow[WIN_MESSAGE].gw_window)) { + z_ob->ob_x = p_w->work.g_x; + z_ob->ob_y = p_w->curr.g_y + p_w->curr.g_h + gr_ch; + } + xdialog(z_ob, NULL, NULL, NULL, DIA_LASTPOS, FALSE, DIALOG_MODE); + Event_Timer(0, 0, TRUE); + Event_Handler(NULL, NULL); - if(planes<4) - dial_colors(4,BLACK,WHITE,RED,RED,WHITE,BLACK,BLACK,BLACK,FAIL,FAIL,FAIL,FAIL,TRUE,TRUE); - else - dial_colors(7,LWHITE,BLACK,RED,RED,BLACK,BLACK,BLACK,BLACK,WHITE,WHITE,WHITE,WHITE,TRUE,TRUE); - } + if (planes < 4) + dial_colors(4, BLACK, WHITE, RED, RED, WHITE, BLACK, BLACK, BLACK, + FAIL, FAIL, FAIL, FAIL, TRUE, TRUE); + else + dial_colors(7, LWHITE, BLACK, RED, RED, BLACK, BLACK, BLACK, + BLACK, WHITE, WHITE, WHITE, WHITE, TRUE, TRUE); + } } /************************* Gem_start_menu *******************************/ @@ -1279,19 +1430,19 @@ void Gem_start_menu(win) winid win; { - win=win; - if(invent_list){ - Gem_menu_item *curr, *next; + win = win; + if (invent_list) { + Gem_menu_item *curr, *next; - for(curr=invent_list;curr;curr=next){ - next=curr->Gmi_next; - free(curr->Gmi_str); - free(curr); - } - } - invent_list=NULL; - Anz_inv_lines=0; - Inv_breite=16; + for (curr = invent_list; curr; curr = next) { + next = curr->Gmi_next; + free(curr->Gmi_str); + free(curr); + } + } + invent_list = NULL; + Anz_inv_lines = 0; + Inv_breite = 16; } /************************* mar_add_menu *******************************/ @@ -1301,140 +1452,150 @@ mar_add_menu(win, item) winid win; Gem_menu_item *item; { - win=win; - item->Gmi_next = invent_list; - invent_list = item; - Anz_inv_lines++; + win = win; + item->Gmi_next = invent_list; + invent_list = item; + Anz_inv_lines++; } void mar_reverse_menu() { - Gem_menu_item *next, *head = 0, *curr=invent_list; + Gem_menu_item *next, *head = 0, *curr = invent_list; - while (curr) { - next = curr->Gmi_next; - curr->Gmi_next = head; - head = curr; - curr = next; - } - invent_list=head; + while (curr) { + next = curr->Gmi_next; + curr->Gmi_next = head; + head = curr; + curr = next; + } + invent_list = head; } void mar_set_accelerators() { - char ch='a'; - Gem_menu_item *curr; + char ch = 'a'; + Gem_menu_item *curr; - for(curr=invent_list;curr;curr=curr->Gmi_next){ - int extent[8]; - v_set_text(menu_font.id,menu_font.size,BLACK,0,0,NULL); - vqt_extent(x_handle,curr->Gmi_str,extent); - Max(&Inv_breite,extent[4]+Tile_width+menu_font.cw); - if(ch && curr->Gmi_accelerator==0 && curr->Gmi_identifier){ - curr->Gmi_accelerator=ch; - curr->Gmi_str[0]=ch; - if(ch=='z') ch='A'; - else if(ch=='Z') ch=0; - else ch++; - } - } + for (curr = invent_list; curr; curr = curr->Gmi_next) { + int extent[8]; + v_set_text(menu_font.id, menu_font.size, BLACK, 0, 0, NULL); + vqt_extent(x_handle, curr->Gmi_str, extent); + Max(&Inv_breite, extent[4] + Tile_width + menu_font.cw); + if (ch && curr->Gmi_accelerator == 0 && curr->Gmi_identifier) { + curr->Gmi_accelerator = ch; + curr->Gmi_str[0] = ch; + if (ch == 'z') + ch = 'A'; + else if (ch == 'Z') + ch = 0; + else + ch++; + } + } } Gem_menu_item * mar_hol_inv() { - return(invent_list); + return (invent_list); } /************************* mar_putstr_text *********************/ void mar_raw_print(const char *); -void mar_set_text_to_rip(winid w){ - use_rip=TRUE; +void +mar_set_text_to_rip(winid w) +{ + use_rip = TRUE; } void mar_putstr_text(winid window, int attr, const char *str) { - static int zeilen_frei=0; - int breite; - char *ptr; + static int zeilen_frei = 0; + int breite; + char *ptr; - window=window; - if(!text_lines){ - text_lines=(char **)m_alloc(12*sizeof(char *)); - zeilen_frei=12; - } - if(!zeilen_frei){ - text_lines=(char **)realloc(text_lines,(Anz_text_lines+12)*sizeof(char *)); - zeilen_frei=12; - } - if(!text_lines){ - mar_raw_print("No room for Text"); - return; - } + window = window; + if (!text_lines) { + text_lines = (char **) m_alloc(12 * sizeof(char *)); + zeilen_frei = 12; + } + if (!zeilen_frei) { + text_lines = (char **) realloc(text_lines, (Anz_text_lines + 12) + * sizeof(char *)); + zeilen_frei = 12; + } + if (!text_lines) { + mar_raw_print("No room for Text"); + return; + } - if(str) - breite=strlen(str); - Min(&breite,80); - ptr=text_lines[Anz_text_lines]=(char *)m_alloc(breite*sizeof(char)+2); - *ptr=(char)(attr+1); /* avoid 0 */ - strncpy(ptr+1,str,breite); - ptr[breite+1]=0; - Anz_text_lines++; - zeilen_frei--; + if (str) + breite = strlen(str); + Min(&breite, 80); + ptr = text_lines[Anz_text_lines] = + (char *) m_alloc(breite * sizeof(char) + 2); + *ptr = (char) (attr + 1); /* avoid 0 */ + strncpy(ptr + 1, str, breite); + ptr[breite + 1] = 0; + Anz_text_lines++; + zeilen_frei--; } int mar_set_inv_win(Anzahl, Breite) int Anzahl, Breite; { - OBJECT *z_ob=zz_oblist[LINES]; - int retval=WIN_DIAL|MODAL|NO_ICONIFY; + OBJECT *z_ob = zz_oblist[LINES]; + int retval = WIN_DIAL | MODAL | NO_ICONIFY; - scroll_menu.hsize=0; - scroll_menu.vpage= (desk.g_h-3*gr_ch)/scroll_menu.px_vline; - if(Anzahl>scroll_menu.vpage){ - retval |= WD_VSLIDER; - if(Breite>max_w-3*scroll_menu.px_hline){ - retval|=WD_HSLIDER; - scroll_menu.hpage=(max_w-3*scroll_menu.px_hline)/scroll_menu.px_hline; - scroll_menu.hpos=0; - scroll_menu.hsize=Breite/scroll_menu.px_hline; - scroll_menu.vpage=(desk.g_h-4*gr_ch-1)/scroll_menu.px_vline; - } - Anzahl=scroll_menu.vpage; - }else{ - if(Breite>max_w-scroll_menu.px_hline){ - retval|=WD_HSLIDER; - scroll_menu.hpage=(max_w-scroll_menu.px_hline)/scroll_menu.px_hline; - scroll_menu.hpos=0; - scroll_menu.hsize=Breite/scroll_menu.px_hline; - scroll_menu.vpage= (desk.g_h-4*gr_ch-1)/scroll_menu.px_vline; - if(Anzahl>scroll_menu.vpage){ - retval |= WD_VSLIDER; - Anzahl=scroll_menu.vpage; - } - } - scroll_menu.vpage=Anzahl; - } - if((scroll_menu.hmax=scroll_menu.hsize-scroll_menu.hpage)<0) - scroll_menu.hmax=0; - if((scroll_menu.vmax=scroll_menu.vsize-scroll_menu.vpage)<0) - scroll_menu.vmax=0; + scroll_menu.hsize = 0; + scroll_menu.vpage = (desk.g_h - 3 * gr_ch) / scroll_menu.px_vline; + if (Anzahl > scroll_menu.vpage) { + retval |= WD_VSLIDER; + if (Breite > max_w - 3 * scroll_menu.px_hline) { + retval |= WD_HSLIDER; + scroll_menu.hpage = + (max_w - 3 * scroll_menu.px_hline) / scroll_menu.px_hline; + scroll_menu.hpos = 0; + scroll_menu.hsize = Breite / scroll_menu.px_hline; + scroll_menu.vpage = + (desk.g_h - 4 * gr_ch - 1) / scroll_menu.px_vline; + } + Anzahl = scroll_menu.vpage; + } else { + if (Breite > max_w - scroll_menu.px_hline) { + retval |= WD_HSLIDER; + scroll_menu.hpage = + (max_w - scroll_menu.px_hline) / scroll_menu.px_hline; + scroll_menu.hpos = 0; + scroll_menu.hsize = Breite / scroll_menu.px_hline; + scroll_menu.vpage = + (desk.g_h - 4 * gr_ch - 1) / scroll_menu.px_vline; + if (Anzahl > scroll_menu.vpage) { + retval |= WD_VSLIDER; + Anzahl = scroll_menu.vpage; + } + } + scroll_menu.vpage = Anzahl; + } + if ((scroll_menu.hmax = scroll_menu.hsize - scroll_menu.hpage) < 0) + scroll_menu.hmax = 0; + if ((scroll_menu.vmax = scroll_menu.vsize - scroll_menu.vpage) < 0) + scroll_menu.vmax = 0; - /* left/right/up 2 pixel border down 2gr_ch toolbar */ - z_ob[ROOT].ob_width=z_ob[LINESLIST].ob_width=Breite; - z_ob[ROOT].ob_height= - z_ob[QLINE].ob_y= - z_ob[LINESLIST].ob_height=scroll_menu.px_vline*Anzahl; - z_ob[QLINE].ob_y+=gr_ch/2; - z_ob[ROOT].ob_width+=4; - z_ob[ROOT].ob_height+=2*gr_ch+2; + /* left/right/up 2 pixel border down 2gr_ch toolbar */ + z_ob[ROOT].ob_width = z_ob[LINESLIST].ob_width = Breite; + z_ob[ROOT].ob_height = z_ob[QLINE].ob_y = z_ob[LINESLIST].ob_height = + scroll_menu.px_vline * Anzahl; + z_ob[QLINE].ob_y += gr_ch / 2; + z_ob[ROOT].ob_width += 4; + z_ob[ROOT].ob_height += 2 * gr_ch + 2; - return(retval); + return (retval); } /************************* mar_status_dirty *******************************/ @@ -1442,15 +1603,20 @@ int Anzahl, Breite; void mar_status_dirty() { - int ccol; + int ccol; - ccol=mar_hp_query(); + ccol = mar_hp_query(); - if(ccol<2) curs_col=WHITE; /* 50-100% : 0 */ - else if(ccol<3) curs_col=YELLOW; /* 33-50% : 6 */ - else if(ccol<5) curs_col=LYELLOW; /* 20-33% : 14*/ - else if(ccol<10) curs_col=RED; /* 10-20% : 2 */ - else curs_col=MAGENTA; /* <10% : 7*/ + if (ccol < 2) + curs_col = WHITE; /* 50-100% : 0 */ + else if (ccol < 3) + curs_col = YELLOW; /* 33-50% : 6 */ + else if (ccol < 5) + curs_col = LYELLOW; /* 20-33% : 14*/ + else if (ccol < 10) + curs_col = RED; /* 10-20% : 2 */ + else + curs_col = MAGENTA; /* <10% : 7*/ } /************************* mar_add_message *******************************/ @@ -1459,91 +1625,98 @@ void mar_add_message(str) const char *str; { - int i, mesg_hist=mar_get_msg_history(); - char *tmp, *rest, buf[TBUFSZ]; + int i, mesg_hist = mar_get_msg_history(); + char *tmp, *rest, buf[TBUFSZ]; - if(WIN_MESSAGE == WIN_ERR) - return; + if (WIN_MESSAGE == WIN_ERR) + return; - if(!mar_message_pause){ - mar_message_pause=TRUE; - messages_pro_zug=0; - msg_pos=msg_max; - } + if (!mar_message_pause) { + mar_message_pause = TRUE; + messages_pro_zug = 0; + msg_pos = msg_max; + } - if(msg_max>mesg_hist-2){ - msg_max=mesg_hist-2; - msg_pos--; - if(msg_pos<0) msg_pos=0; - tmp=message_line[0]; - for(i=0;i mesg_hist - 2) { + msg_max = mesg_hist - 2; + msg_pos--; + if (msg_pos < 0) + msg_pos = 0; + tmp = message_line[0]; + for (i = 0; i < mesg_hist - 1; i++) { + message_line[i] = message_line[i + 1]; + message_age[i] = message_age[i + 1]; + } + message_line[mesg_hist - 1] = tmp; + } + strcpy(toplines, str); + messages_pro_zug++; + msg_max++; - if((int)strlen(toplines)>=msg_width){ - int pos=msg_width; - tmp=toplines+msg_width; - while(*tmp!=' ' && pos>=0){ - tmp--; - pos--; - } - if(pos<=0) pos=msg_width; /* Mar -- Oops, what a word :-) */ - message_age[msg_max]=TRUE; - strncpy(message_line[msg_max],toplines,pos); - message_line[msg_max][pos]=0; - rest=strcpy(buf,toplines+pos); - }else{ - message_age[msg_max]=TRUE; - strncpy(message_line[msg_max],toplines,msg_width); - rest=0; - } + if ((int) strlen(toplines) >= msg_width) { + int pos = msg_width; + tmp = toplines + msg_width; + while (*tmp != ' ' && pos >= 0) { + tmp--; + pos--; + } + if (pos <= 0) + pos = msg_width; /* Mar -- Oops, what a word :-) */ + message_age[msg_max] = TRUE; + strncpy(message_line[msg_max], toplines, pos); + message_line[msg_max][pos] = 0; + rest = strcpy(buf, toplines + pos); + } else { + message_age[msg_max] = TRUE; + strncpy(message_line[msg_max], toplines, msg_width); + rest = 0; + } - Gem_nhwindow[WIN_MESSAGE].gw_dirty=TRUE; - if(messages_pro_zug>=mesg_hist){ /* MAR -- Greater then should never happen */ - messages_pro_zug=mesg_hist; - mar_display_nhwindow(WIN_MESSAGE); - } + Gem_nhwindow[WIN_MESSAGE].gw_dirty = TRUE; + if (messages_pro_zug + >= mesg_hist) { /* MAR -- Greater then should never happen */ + messages_pro_zug = mesg_hist; + mar_display_nhwindow(WIN_MESSAGE); + } - if(rest) - mar_add_message(rest); + if (rest) + mar_add_message(rest); } /************************* mar_add_status_str *******************************/ void -mar_add_status_str(str,line) +mar_add_status_str(str, line) const char *str; int line; { - int i,last_diff=-1; - GRECT area={0,line*status_font.ch,status_font.cw,status_font.ch}; - for(i=0;(i=0){ - add_dirty_rect(dr_stat,&area); - last_diff=-1; - area.g_w=status_font.cw; - } - for(;i=0) - add_dirty_rect(dr_stat,&area); + int i, last_diff = -1; + GRECT area = { 0, line * status_font.ch, status_font.cw, status_font.ch }; + for (i = 0; (i < status_w - 2) && str[i]; i++) + if (str[i] != status_line[line][i]) { + if (last_diff == -1) + area.g_x = i * status_font.cw; + else + area.g_w += status_font.cw; + last_diff = i; + status_line[line][i] = str[i]; + } else if (last_diff >= 0) { + add_dirty_rect(dr_stat, &area); + last_diff = -1; + area.g_w = status_font.cw; + } + for (; i < status_w - 1; i++) { + if (status_line[line][i]) { + if (last_diff == -1) + area.g_x = i * status_font.cw; + else + area.g_w += status_font.cw; + last_diff = i; + } + status_line[line][i] = 0; + } + if (last_diff >= 0) + add_dirty_rect(dr_stat, &area); } /************************* mar_set_menu_title *******************************/ @@ -1552,8 +1725,8 @@ void mar_set_menu_title(str) const char *str; { - test_free(Menu_title); /* just in case */ - Menu_title=mar_copy_of(str ? str : nullstr); + test_free(Menu_title); /* just in case */ + Menu_title = mar_copy_of(str ? str : nullstr); } /************************* mar_set_menu_type *******************************/ @@ -1562,7 +1735,7 @@ void mar_set_menu_type(how) int how; { - Inv_how=how; + Inv_how = how; } /************************* Inventory Utils *******************************/ @@ -1571,32 +1744,34 @@ void set_all_on_page(start, page) int start, page; { - Gem_menu_item *curr; + Gem_menu_item *curr; - if(start<0 || page<0) - return; + if (start < 0 || page < 0) + return; - for(curr=invent_list; start--&&curr; curr=curr->Gmi_next); - for(; page--&&curr; curr=curr->Gmi_next) - if (curr->Gmi_identifier && !curr->Gmi_selected) - curr->Gmi_selected = TRUE; + for (curr = invent_list; start-- && curr; curr = curr->Gmi_next) + ; + for (; page-- && curr; curr = curr->Gmi_next) + if (curr->Gmi_identifier && !curr->Gmi_selected) + curr->Gmi_selected = TRUE; } void unset_all_on_page(start, page) int start, page; { - Gem_menu_item *curr; + Gem_menu_item *curr; - if(start<0 || page<0) - return; + if (start < 0 || page < 0) + return; - for(curr=invent_list; start--&&curr; curr=curr->Gmi_next); - for(; page--&&curr; curr=curr->Gmi_next) - if (curr->Gmi_identifier && curr->Gmi_selected) { - curr->Gmi_selected = FALSE; - curr->Gmi_count = -1L; - } + for (curr = invent_list; start-- && curr; curr = curr->Gmi_next) + ; + for (; page-- && curr; curr = curr->Gmi_next) + if (curr->Gmi_identifier && curr->Gmi_selected) { + curr->Gmi_selected = FALSE; + curr->Gmi_count = -1L; + } } void @@ -1604,54 +1779,59 @@ invert_all_on_page(start, page, acc) int start, page; char acc; { - Gem_menu_item *curr; + Gem_menu_item *curr; - if(start<0 || page<0) - return; + if (start < 0 || page < 0) + return; - for(curr=invent_list; start--&&curr; curr=curr->Gmi_next); - for(; page--&&curr; curr=curr->Gmi_next) - if (curr->Gmi_identifier && (acc == 0 || curr->Gmi_groupacc == acc)) { - if (curr->Gmi_selected) { - curr->Gmi_selected = FALSE; - curr->Gmi_count = -1L; - } else - curr->Gmi_selected = TRUE; - } + for (curr = invent_list; start-- && curr; curr = curr->Gmi_next) + ; + for (; page-- && curr; curr = curr->Gmi_next) + if (curr->Gmi_identifier && (acc == 0 || curr->Gmi_groupacc == acc)) { + if (curr->Gmi_selected) { + curr->Gmi_selected = FALSE; + curr->Gmi_count = -1L; + } else + curr->Gmi_selected = TRUE; + } } -/************************* Inv_Handler and Inv_Init *******************************/ +/************************* Inv_Handler and Inv_Init + * *******************************/ -int scroll_top_dialog(char ch){ - WIN *w; - DIAINFO *dinf; +int +scroll_top_dialog(char ch) +{ + WIN *w; + DIAINFO *dinf; - if((w=get_top_window()) && (dinf=(DIAINFO *)w->dialog) && dinf->di_tree==zz_oblist[LINES]){ - switch(ch){ - case ' ': - if(scroll_menu.vpos==scroll_menu.vmax){ - send_return(); - break; - } - /* Fall thru */ - case MENU_NEXT_PAGE: - scroll_window(w,PAGE_DOWN,NULL); - break; - case MENU_PREVIOUS_PAGE: - scroll_window(w,PAGE_UP,NULL); - break; - case MENU_FIRST_PAGE: - scroll_window(w,WIN_START,NULL); - break; - case MENU_LAST_PAGE: - scroll_window(w,WIN_END,NULL); - break; - default: - return(FALSE); - } - return(TRUE); - } - return(FALSE); + if ((w = get_top_window()) && (dinf = (DIAINFO *) w->dialog) + && dinf->di_tree == zz_oblist[LINES]) { + switch (ch) { + case ' ': + if (scroll_menu.vpos == scroll_menu.vmax) { + send_return(); + break; + } + /* Fall thru */ + case MENU_NEXT_PAGE: + scroll_window(w, PAGE_DOWN, NULL); + break; + case MENU_PREVIOUS_PAGE: + scroll_window(w, PAGE_UP, NULL); + break; + case MENU_FIRST_PAGE: + scroll_window(w, WIN_START, NULL); + break; + case MENU_LAST_PAGE: + scroll_window(w, WIN_END, NULL); + break; + default: + return (FALSE); + } + return (TRUE); + } + return (FALSE); } #define Text_Init KM_Init @@ -1660,603 +1840,676 @@ int Text_Handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; + int ev = xev->ev_mwich; - if(ev&MU_MESAG){ - int *buf=xev->ev_mmgpbuf, y_wo, i; - if(*buf==FONT_CHANGED){ - if(buf[3]>=0){ - mar_set_fontbyid(NHW_TEXT,buf[4],buf[5]); - FontAck(buf[1],1); - } - } - } - if(ev&MU_KEYBD){ - char ch=(char)(xev->ev_mkreturn&0x00FF); + if (ev & MU_MESAG) { + int *buf = xev->ev_mmgpbuf, y_wo, i; + if (*buf == FONT_CHANGED) { + if (buf[3] >= 0) { + mar_set_fontbyid(NHW_TEXT, buf[4], buf[5]); + FontAck(buf[1], 1); + } + } + } + if (ev & MU_KEYBD) { + char ch = (char) (xev->ev_mkreturn & 0x00FF); - if(!scroll_top_dialog(ch)) - switch(ch){ - case '\033': - send_return(); /* just closes the textwin */ - break; - case C('c'): - clipbrd_save(text_lines,Anz_text_lines,xev->ev_mmokstate&K_SHIFT,FALSE); - break; - default: - ev &= ~MU_KEYBD; /* unknown key */ - break; - } - } - return(ev); + if (!scroll_top_dialog(ch)) + switch (ch) { + case '\033': + send_return(); /* just closes the textwin */ + break; + case C('c'): + clipbrd_save(text_lines, Anz_text_lines, + xev->ev_mmokstate & K_SHIFT, FALSE); + break; + default: + ev &= ~MU_KEYBD; /* unknown key */ + break; + } + } + return (ev); } #define Inv_Init KM_Init -static long count=0; +static long count = 0; int Inv_Handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; - Gem_menu_item *it; - GRECT area; - OBJECT *z_ob=zz_oblist[LINES]; + int ev = xev->ev_mwich; + Gem_menu_item *it; + GRECT area; + OBJECT *z_ob = zz_oblist[LINES]; - ob_pos(z_ob,LINESLIST,&area); - if(ev&MU_MESAG){ - int *buf=xev->ev_mmgpbuf, y_wo, i; + ob_pos(z_ob, LINESLIST, &area); + if (ev & MU_MESAG) { + int *buf = xev->ev_mmgpbuf, y_wo, i; - if(*buf==FONT_CHANGED){ - if(buf[3]>=0){ - mar_set_fontbyid(NHW_MENU,buf[4],buf[5]); - FontAck(buf[1],1); - } - }else - if(*buf==OBJC_CHANGED && buf[3]==LINESLIST){ - ob_undostate(z_ob,LINESLIST,SELECTED); - mouse(NULL,&y_wo); - y_wo=(y_wo-area.g_y)/menu_font.ch+scroll_menu.vpos; - for(it=invent_list,i=0;iGmi_next,i++); - if(it->Gmi_identifier){ - it->Gmi_selected=!it->Gmi_selected; - it->Gmi_count= count==0L ? -1L : count; - count = 0L; - if(Inv_how!=PICK_ANY){ - /*my_close_dialog(Inv_dialog,TRUE);*/ - send_return(); - }else{ - area.g_x=(area.g_x+23+2*menu_font.cw) & ~7; - area.g_w=menu_font.cw; - area.g_h=menu_font.ch; - area.g_y+=(y_wo-scroll_menu.vpos)*menu_font.ch; - ob_draw_chg(Inv_dialog,LINESLIST,&area,FAIL); - } /* how != PICK_ANY */ - } /* identifier */ - }else /* LINESLIST changed */ - ev &= ~MU_MESAG; /* unknown message not used */ - } /* MU_MESAG */ + if (*buf == FONT_CHANGED) { + if (buf[3] >= 0) { + mar_set_fontbyid(NHW_MENU, buf[4], buf[5]); + FontAck(buf[1], 1); + } + } else if (*buf == OBJC_CHANGED && buf[3] == LINESLIST) { + ob_undostate(z_ob, LINESLIST, SELECTED); + mouse(NULL, &y_wo); + y_wo = (y_wo - area.g_y) / menu_font.ch + scroll_menu.vpos; + for (it = invent_list, i = 0; i < y_wo && it; + it = it->Gmi_next, i++) + ; + if (it->Gmi_identifier) { + it->Gmi_selected = !it->Gmi_selected; + it->Gmi_count = count == 0L ? -1L : count; + count = 0L; + if (Inv_how != PICK_ANY) { + /*my_close_dialog(Inv_dialog,TRUE);*/ + send_return(); + } else { + area.g_x = (area.g_x + 23 + 2 * menu_font.cw) & ~7; + area.g_w = menu_font.cw; + area.g_h = menu_font.ch; + area.g_y += (y_wo - scroll_menu.vpos) * menu_font.ch; + ob_draw_chg(Inv_dialog, LINESLIST, &area, FAIL); + } /* how != PICK_ANY */ + } /* identifier */ + } else /* LINESLIST changed */ + ev &= ~MU_MESAG; /* unknown message not used */ + } /* MU_MESAG */ - if(ev&MU_KEYBD){ - char ch=(char)(xev->ev_mkreturn&0x00FF); + if (ev & MU_KEYBD) { + char ch = (char) (xev->ev_mkreturn & 0x00FF); - if(!scroll_top_dialog(ch)){ - switch(ch){ - case '0': /* special 0 is also groupaccelerator for balls */ - if(count<=0) - goto find_acc; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if(Inv_how==PICK_NONE) - goto find_acc; - count = (count * 10L) + (long) (ch - '0'); - break; - case '\033': /* cancel - from counting or loop */ - if(count>0L) - count=0L; - else{ - unset_all_on_page(0, (int)scroll_menu.vsize); - my_close_dialog(Inv_dialog,TRUE); - return(ev); - } - break; - case '\0': /* finished (commit) */ - case '\n': - case '\r': - break; - case MENU_SELECT_PAGE: - if(Inv_how==PICK_NONE) - goto find_acc; - if (Inv_how == PICK_ANY) - set_all_on_page((int)scroll_menu.vpos, scroll_menu.vpage); - break; - case MENU_SELECT_ALL: - if(Inv_how==PICK_NONE) - goto find_acc; - if (Inv_how == PICK_ANY) - set_all_on_page(0, (int)scroll_menu.vsize); - break; - case MENU_UNSELECT_PAGE: - unset_all_on_page((int)scroll_menu.vpos, scroll_menu.vpage); - break; - case MENU_UNSELECT_ALL: - unset_all_on_page(0, (int)scroll_menu.vsize); - break; - case MENU_INVERT_PAGE: - if(Inv_how==PICK_NONE) - goto find_acc; - if (Inv_how == PICK_ANY) - invert_all_on_page((int)scroll_menu.vpos, scroll_menu.vpage, 0); - break; - case MENU_INVERT_ALL: - if(Inv_how==PICK_NONE) - goto find_acc; - if (Inv_how == PICK_ANY) - invert_all_on_page(0, (int)scroll_menu.vsize, 0); - break; - case MENU_SEARCH: - if(Inv_how!=PICK_NONE){ - char buf[BUFSZ]; - Gem_getlin("Search for:",buf); - if(!*buf || buf[0]=='\033') - break; - for(it=invent_list;it;it=it->Gmi_next){ - if(it->Gmi_identifier && strstr(it->Gmi_str,buf)){ - it->Gmi_selected=TRUE; - if(Inv_how!=PICK_ANY){ - my_close_dialog(Inv_dialog,FALSE); - break; - } - } - } - } - break; - case C('c'): - clipbrd_save(invent_list,Anz_inv_lines,xev->ev_mmokstate&K_SHIFT,TRUE); - break; - default: - find_acc: - if(Inv_how==PICK_NONE) - my_close_dialog(Inv_dialog,TRUE); - else - for(it=invent_list;it;it=it->Gmi_next){ - if(it->Gmi_identifier && (it->Gmi_accelerator==ch || it->Gmi_groupacc==ch)){ - it->Gmi_selected=!it->Gmi_selected; - it->Gmi_count= count==0L ? -1L : count; - count = 0L; - if(Inv_how!=PICK_ANY) - my_close_dialog(Inv_dialog,TRUE); - } - } - break; - } /* end switch(ch) */ - if(Inv_how==PICK_ANY){ - area.g_x=(area.g_x+23+2*menu_font.cw) & ~7; - area.g_w=menu_font.cw; - ob_draw_chg(Inv_dialog,LINESLIST,&area,FAIL); - } - } /* !scroll_Inv_dialog */ - } /* MU_KEYBD */ + if (!scroll_top_dialog(ch)) { + switch (ch) { + case '0': /* special 0 is also groupaccelerator for balls */ + if (count <= 0) + goto find_acc; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (Inv_how == PICK_NONE) + goto find_acc; + count = (count * 10L) + (long) (ch - '0'); + break; + case '\033': /* cancel - from counting or loop */ + if (count > 0L) + count = 0L; + else { + unset_all_on_page(0, (int) scroll_menu.vsize); + my_close_dialog(Inv_dialog, TRUE); + return (ev); + } + break; + case '\0': /* finished (commit) */ + case '\n': + case '\r': + break; + case MENU_SELECT_PAGE: + if (Inv_how == PICK_NONE) + goto find_acc; + if (Inv_how == PICK_ANY) + set_all_on_page((int) scroll_menu.vpos, + scroll_menu.vpage); + break; + case MENU_SELECT_ALL: + if (Inv_how == PICK_NONE) + goto find_acc; + if (Inv_how == PICK_ANY) + set_all_on_page(0, (int) scroll_menu.vsize); + break; + case MENU_UNSELECT_PAGE: + unset_all_on_page((int) scroll_menu.vpos, scroll_menu.vpage); + break; + case MENU_UNSELECT_ALL: + unset_all_on_page(0, (int) scroll_menu.vsize); + break; + case MENU_INVERT_PAGE: + if (Inv_how == PICK_NONE) + goto find_acc; + if (Inv_how == PICK_ANY) + invert_all_on_page((int) scroll_menu.vpos, + scroll_menu.vpage, 0); + break; + case MENU_INVERT_ALL: + if (Inv_how == PICK_NONE) + goto find_acc; + if (Inv_how == PICK_ANY) + invert_all_on_page(0, (int) scroll_menu.vsize, 0); + break; + case MENU_SEARCH: + if (Inv_how != PICK_NONE) { + char buf[BUFSZ]; + Gem_getlin("Search for:", buf); + if (!*buf || buf[0] == '\033') + break; + for (it = invent_list; it; it = it->Gmi_next) { + if (it->Gmi_identifier && strstr(it->Gmi_str, buf)) { + it->Gmi_selected = TRUE; + if (Inv_how != PICK_ANY) { + my_close_dialog(Inv_dialog, FALSE); + break; + } + } + } + } + break; + case C('c'): + clipbrd_save(invent_list, Anz_inv_lines, + xev->ev_mmokstate & K_SHIFT, TRUE); + break; + default: + find_acc: + if (Inv_how == PICK_NONE) + my_close_dialog(Inv_dialog, TRUE); + else + for (it = invent_list; it; it = it->Gmi_next) { + if (it->Gmi_identifier + && (it->Gmi_accelerator == ch + || it->Gmi_groupacc == ch)) { + it->Gmi_selected = !it->Gmi_selected; + it->Gmi_count = count == 0L ? -1L : count; + count = 0L; + if (Inv_how != PICK_ANY) + my_close_dialog(Inv_dialog, TRUE); + } + } + break; + } /* end switch(ch) */ + if (Inv_how == PICK_ANY) { + area.g_x = (area.g_x + 23 + 2 * menu_font.cw) & ~7; + area.g_w = menu_font.cw; + ob_draw_chg(Inv_dialog, LINESLIST, &area, FAIL); + } + } /* !scroll_Inv_dialog */ + } /* MU_KEYBD */ - if(Inv_how==PICK_ANY){ - ob_set_text(Inv_dialog->di_tree,QLINE,strCancel); - for(it=invent_list;it;it=it->Gmi_next) - if(it->Gmi_identifier && it->Gmi_selected){ - ob_set_text(Inv_dialog->di_tree,QLINE,strOk); - break; - } - ob_draw_chg(Inv_dialog,QLINE,NULL,FAIL); - } - return(ev); + if (Inv_how == PICK_ANY) { + ob_set_text(Inv_dialog->di_tree, QLINE, strCancel); + for (it = invent_list; it; it = it->Gmi_next) + if (it->Gmi_identifier && it->Gmi_selected) { + ob_set_text(Inv_dialog->di_tree, QLINE, strOk); + break; + } + ob_draw_chg(Inv_dialog, QLINE, NULL, FAIL); + } + return (ev); } /************************* draw_window *******************************/ static void -mar_draw_window( first, win, area) +mar_draw_window(first, win, area) int first; WIN *win; GRECT *area; { - OBJECT *obj=(OBJECT *)win->para; + OBJECT *obj = (OBJECT *) win->para; - if(obj){ - if(first){ - obj->ob_x=win->work.g_x; - obj->ob_y=win->work.g_y; - } - if(area==NULL) - area=&(win->work); - objc_draw(obj, ROOT, MAX_DEPTH, area->g_x, area->g_y, area->g_w, area->g_h); - } + if (obj) { + if (first) { + obj->ob_x = win->work.g_x; + obj->ob_y = win->work.g_y; + } + if (area == NULL) + area = &(win->work); + objc_draw(obj, ROOT, MAX_DEPTH, area->g_x, area->g_y, area->g_w, + area->g_h); + } } -/************************* mar_display_nhwindow *******************************/ +/************************* mar_display_nhwindow + * *******************************/ -void redraw_winwork(WIN *w,GRECT *area){ - area->g_x+=w->work.g_x; - area->g_y+=w->work.g_y; - redraw_window(w,area); +void +redraw_winwork(WIN *w, GRECT *area) +{ + area->g_x += w->work.g_x; + area->g_y += w->work.g_y; + redraw_window(w, area); } -void mar_menu_set_slider(WIN *p_win){ - if(p_win){ - SCROLL *sc=p_win->scroll; +void +mar_menu_set_slider(WIN *p_win) +{ + if (p_win) { + SCROLL *sc = p_win->scroll; - if(!sc) - return; + if (!sc) + return; - if(p_win->gadgets&HSLIDE){ - long hsize=1000l; + if (p_win->gadgets & HSLIDE) { + long hsize = 1000l; - if(sc->hsize>0 && sc->hpage>0){ - hsize *= sc->hpage; - hsize /= sc->hsize; - } - window_slider(p_win,HOR_SLIDER,0,(int)hsize); - } - if(p_win->gadgets&VSLIDE){ - long vsize=1000l; + if (sc->hsize > 0 && sc->hpage > 0) { + hsize *= sc->hpage; + hsize /= sc->hsize; + } + window_slider(p_win, HOR_SLIDER, 0, (int) hsize); + } + if (p_win->gadgets & VSLIDE) { + long vsize = 1000l; - if(sc->vsize>0 && sc->vpage>0){ - vsize *= sc->vpage; - vsize /= sc->vsize; - } - window_slider(p_win,VERT_SLIDER,0,(int)vsize); - } - } + if (sc->vsize > 0 && sc->vpage > 0) { + vsize *= sc->vpage; + vsize /= sc->vsize; + } + window_slider(p_win, VERT_SLIDER, 0, (int) vsize); + } + } } -void recalc_msg_win(GRECT *area){ - OBJECT *z_ob; - z_ob=zz_oblist[MSGWIN]; - z_ob[MSGLINES].ob_spec.userblk=&ub_msg; - z_ob[MSGLINES].ob_width= - z_ob[ROOT].ob_width= (msg_width+3)*msg_font.cw; - z_ob[MSGLINES].ob_width-=z_ob[UPMSG].ob_width; - z_ob[ROOT].ob_height= - z_ob[GRABMSGWIN].ob_height= - z_ob[MSGLINES].ob_height=msg_vis*msg_font.ch; - z_ob[DNMSG].ob_y=z_ob[GRABMSGWIN].ob_height-z_ob[DNMSG].ob_height; - window_border(0,0,0,z_ob->ob_width,z_ob->ob_height, area); +void +recalc_msg_win(GRECT *area) +{ + OBJECT *z_ob; + z_ob = zz_oblist[MSGWIN]; + z_ob[MSGLINES].ob_spec.userblk = &ub_msg; + z_ob[MSGLINES].ob_width = z_ob[ROOT].ob_width = + (msg_width + 3) * msg_font.cw; + z_ob[MSGLINES].ob_width -= z_ob[UPMSG].ob_width; + z_ob[ROOT].ob_height = z_ob[GRABMSGWIN].ob_height = + z_ob[MSGLINES].ob_height = msg_vis * msg_font.ch; + z_ob[DNMSG].ob_y = z_ob[GRABMSGWIN].ob_height - z_ob[DNMSG].ob_height; + window_border(0, 0, 0, z_ob->ob_width, z_ob->ob_height, area); } -void recalc_status_win(GRECT *area){ - OBJECT *z_ob; - z_ob=zz_oblist[STATUSLINE]; - z_ob[ROOT].ob_type=G_USERDEF; - z_ob[ROOT].ob_spec.userblk=&ub_status; - z_ob[ROOT].ob_width=(status_w+2)*status_font.cw; - z_ob[ROOT].ob_height= - z_ob[GRABSTATUS].ob_height=2*status_font.ch; - z_ob[GRABSTATUS].ob_width=2*status_font.cw-2; - window_border(0,0,0,z_ob->ob_width,z_ob->ob_height,area); +void +recalc_status_win(GRECT *area) +{ + OBJECT *z_ob; + z_ob = zz_oblist[STATUSLINE]; + z_ob[ROOT].ob_type = G_USERDEF; + z_ob[ROOT].ob_spec.userblk = &ub_status; + z_ob[ROOT].ob_width = (status_w + 2) * status_font.cw; + z_ob[ROOT].ob_height = z_ob[GRABSTATUS].ob_height = 2 * status_font.ch; + z_ob[GRABSTATUS].ob_width = 2 * status_font.cw - 2; + window_border(0, 0, 0, z_ob->ob_width, z_ob->ob_height, area); } -void calc_std_winplace(int which, GRECT *place){ - static int todo=TRUE; - static GRECT me, ma, st; +void +calc_std_winplace(int which, GRECT *place) +{ + static int todo = TRUE; + static GRECT me, ma, st; - if(todo || which<0){ - OBJECT *z_ob; - int map_h_off, foo; + if (todo || which < 0) { + OBJECT *z_ob; + int map_h_off, foo; - /* First the messagewin */ - recalc_msg_win(&me); + /* First the messagewin */ + recalc_msg_win(&me); - /* Now the map */ - wind_calc(WC_BORDER,MAP_GADGETS,0,0,scroll_map.px_hline*(COLNO-1),scroll_map.px_vline*ROWNO,&foo,&foo,&foo,&map_h_off); - map_h_off-=scroll_map.px_vline*ROWNO; - window_border(MAP_GADGETS,0,0,scroll_map.px_hline*(COLNO-1),scroll_map.px_vline*ROWNO, &ma); + /* Now the map */ + wind_calc(WC_BORDER, MAP_GADGETS, 0, 0, + scroll_map.px_hline * (COLNO - 1), + scroll_map.px_vline * ROWNO, &foo, &foo, &foo, &map_h_off); + map_h_off -= scroll_map.px_vline * ROWNO; + window_border(MAP_GADGETS, 0, 0, scroll_map.px_hline * (COLNO - 1), + scroll_map.px_vline * ROWNO, &ma); - /* Next the statuswin */ - recalc_status_win(&st); + /* Next the statuswin */ + recalc_status_win(&st); - /* And last but not least a final test */ - ma.g_h=map_h_off+scroll_map.px_vline*ROWNO; - while(me.g_h+ma.g_h+st.g_h>=desk.g_h) - ma.g_h-=scroll_map.px_vline; - /* stack the windows */ - ma.g_y=me.g_y=st.g_y=desk.g_y; - if(status_align){ - ma.g_y+=st.g_h; - if(msg_align){ - st.g_y+=me.g_h; - ma.g_y+=me.g_h; - }else{ - me.g_y+=st.g_h+ma.g_h; - } - }else{ - if(msg_align){ - ma.g_y+=me.g_h; - }else{ - me.g_y+=ma.g_h; - } - st.g_y+=me.g_h+ma.g_h; - } + /* And last but not least a final test */ + ma.g_h = map_h_off + scroll_map.px_vline * ROWNO; + while (me.g_h + ma.g_h + st.g_h >= desk.g_h) + ma.g_h -= scroll_map.px_vline; + /* stack the windows */ + ma.g_y = me.g_y = st.g_y = desk.g_y; + if (status_align) { + ma.g_y += st.g_h; + if (msg_align) { + st.g_y += me.g_h; + ma.g_y += me.g_h; + } else { + me.g_y += st.g_h + ma.g_h; + } + } else { + if (msg_align) { + ma.g_y += me.g_h; + } else { + me.g_y += ma.g_h; + } + st.g_y += me.g_h + ma.g_h; + } - if(which) todo=FALSE; - } - switch(which){ - case NHW_MESSAGE: - *place=me; - break; - case NHW_MAP: - *place=ma; - break; - case NHW_STATUS: - *place=st; - break; - default: - break; - } + if (which) + todo = FALSE; + } + switch (which) { + case NHW_MESSAGE: + *place = me; + break; + case NHW_MAP: + *place = ma; + break; + case NHW_STATUS: + *place = st; + break; + default: + break; + } } void mar_display_nhwindow(wind) winid wind; { - DIAINFO *dlg_info; - OBJECT *z_ob; - int d_exit=W_ABANDON, i, breite, mar_di_mode, tmp_magx=magx; - GRECT g_mapmax, area; - char *tmp_button; - struct gw *p_Gw; + DIAINFO *dlg_info; + OBJECT *z_ob; + int d_exit = W_ABANDON, i, breite, mar_di_mode, tmp_magx = magx; + GRECT g_mapmax, area; + char *tmp_button; + struct gw *p_Gw; - if(wind == WIN_ERR) return; + if (wind == WIN_ERR) + return; - p_Gw=&Gem_nhwindow[wind]; - switch(p_Gw->gw_type){ - case NHW_TEXT: - if(WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) - mar_display_nhwindow(WIN_MESSAGE); - z_ob=zz_oblist[LINES]; - scroll_menu.vsize=Anz_text_lines; - scroll_menu.vpos=0; - if(use_rip){ - if(!depack_img(planes<4 ? "RIP2.IMG" : "RIP.IMG", &rip_image)){ - mfdb(&Rip_bild, (int *)rip_image.addr, rip_image.img_w, rip_image.img_h, 1, rip_image.planes); - transform_img(&Rip_bild); - } - ub_lines.ub_code=draw_rip; - }else - ub_lines.ub_code=draw_lines; - z_ob[LINESLIST].ob_spec.userblk=&ub_lines; - breite=16; - v_set_text(text_font.id,text_font.size,BLACK,0,0,NULL); - for(i=0;idi_win; + p_Gw = &Gem_nhwindow[wind]; + switch (p_Gw->gw_type) { + case NHW_TEXT: + if (WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) + mar_display_nhwindow(WIN_MESSAGE); + z_ob = zz_oblist[LINES]; + scroll_menu.vsize = Anz_text_lines; + scroll_menu.vpos = 0; + if (use_rip) { + if (!depack_img(planes < 4 ? "RIP2.IMG" : "RIP.IMG", + &rip_image)) { + mfdb(&Rip_bild, (int *) rip_image.addr, rip_image.img_w, + rip_image.img_h, 1, rip_image.planes); + transform_img(&Rip_bild); + } + ub_lines.ub_code = draw_rip; + } else + ub_lines.ub_code = draw_lines; + z_ob[LINESLIST].ob_spec.userblk = &ub_lines; + breite = 16; + v_set_text(text_font.id, text_font.size, BLACK, 0, 0, NULL); + for (i = 0; i < Anz_text_lines; i++) { + int eout[8]; + vqt_extent(x_handle, text_lines[i], eout); + Max(&breite, eout[4]); + } + scroll_menu.px_vline = text_font.ch; + scroll_menu.px_hline = text_font.cw; + mar_di_mode = mar_set_inv_win(Anz_text_lines, breite); + tmp_button = ob_get_text(z_ob, QLINE, 0); + ob_set_text(z_ob, QLINE, strOk); + ob_undoflag(z_ob, LINESLIST, TOUCHEXIT); + Event_Handler(Text_Init, Text_Handler); + if ((dlg_info = open_dialog(z_ob, strText, NULL, NULL, + mar_ob_mapcenter(z_ob), FALSE, + mar_di_mode, FAIL, NULL, NULL)) != NULL) { + WIN *ptr_win = dlg_info->di_win; - ptr_win->scroll=&scroll_menu; - mar_menu_set_slider(ptr_win); - WindowItems(ptr_win,SCROLL_KEYS,scroll_keys); - if((d_exit=X_Form_Do(NULL))!=W_ABANDON){ - my_close_dialog(dlg_info,FALSE); - if(d_exit!=W_CLOSED) - ob_undostate(z_ob,d_exit&NO_CLICK,SELECTED); - } - } - Event_Handler(NULL,NULL); - ob_set_text(z_ob,QLINE,tmp_button); - break; - case NHW_MENU: - if(WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) - mar_display_nhwindow(WIN_MESSAGE); - z_ob=zz_oblist[LINES]; - scroll_menu.vsize=Anz_inv_lines; - scroll_menu.vpos=0; - z_ob[LINESLIST].ob_spec.userblk=&ub_inventory; - if((Menu_title)&&(wind!=WIN_INVEN)) /* because I sets no Menu_title */ - Max(&Inv_breite,gr_cw*strlen(Menu_title)+16); - scroll_menu.px_vline=menu_font.ch; - scroll_menu.px_hline=menu_font.cw; - mar_di_mode=mar_set_inv_win(Anz_inv_lines, Inv_breite, NHW_MENU); - tmp_button=ob_get_text(z_ob,QLINE,0); - ob_set_text(z_ob,QLINE,Inv_how!=PICK_NONE ? strCancel : strOk ); - ob_doflag(z_ob,LINESLIST,TOUCHEXIT); - Event_Handler(Inv_Init, Inv_Handler); - if((Inv_dialog=open_dialog(z_ob,(wind==WIN_INVEN) ? "Inventory" : (Menu_title ? Menu_title : "Staun"), NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, mar_di_mode, FAIL, NULL, NULL))!=NULL){ - WIN *ptr_win=Inv_dialog->di_win; + ptr_win->scroll = &scroll_menu; + mar_menu_set_slider(ptr_win); + WindowItems(ptr_win, SCROLL_KEYS, scroll_keys); + if ((d_exit = X_Form_Do(NULL)) != W_ABANDON) { + my_close_dialog(dlg_info, FALSE); + if (d_exit != W_CLOSED) + ob_undostate(z_ob, d_exit & NO_CLICK, SELECTED); + } + } + Event_Handler(NULL, NULL); + ob_set_text(z_ob, QLINE, tmp_button); + break; + case NHW_MENU: + if (WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) + mar_display_nhwindow(WIN_MESSAGE); + z_ob = zz_oblist[LINES]; + scroll_menu.vsize = Anz_inv_lines; + scroll_menu.vpos = 0; + z_ob[LINESLIST].ob_spec.userblk = &ub_inventory; + if ((Menu_title) + && (wind != WIN_INVEN)) /* because I sets no Menu_title */ + Max(&Inv_breite, gr_cw * strlen(Menu_title) + 16); + scroll_menu.px_vline = menu_font.ch; + scroll_menu.px_hline = menu_font.cw; + mar_di_mode = mar_set_inv_win(Anz_inv_lines, Inv_breite, NHW_MENU); + tmp_button = ob_get_text(z_ob, QLINE, 0); + ob_set_text(z_ob, QLINE, Inv_how != PICK_NONE ? strCancel : strOk); + ob_doflag(z_ob, LINESLIST, TOUCHEXIT); + Event_Handler(Inv_Init, Inv_Handler); + if ((Inv_dialog = + open_dialog(z_ob, (wind == WIN_INVEN) + ? "Inventory" + : (Menu_title ? Menu_title : "Staun"), + NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, + mar_di_mode, FAIL, NULL, NULL)) != NULL) { + WIN *ptr_win = Inv_dialog->di_win; - ptr_win->scroll=&scroll_menu; - mar_menu_set_slider(ptr_win); - WindowItems(ptr_win,SCROLL_KEYS,scroll_keys); - do{ - int y_wo,x_wo,ru_w=1,ru_h=1; - GRECT oarea; - Gem_menu_item *it; - d_exit=X_Form_Do(NULL); - if((d_exit&NO_CLICK)==LINESLIST){ - ob_pos(z_ob,LINESLIST,&oarea); - if(mouse(&x_wo,&y_wo) && Inv_how==PICK_ANY){ - graf_rt_rubberbox(FALSE,x_wo,y_wo,FAIL,FAIL,&oarea,&ru_w,&ru_h,NULL); - invert_all_on_page((int)((y_wo-oarea.g_y)/menu_font.ch+scroll_menu.vpos),(ru_h+menu_font.ch-1)/menu_font.ch,0); - }else{ - for(it=invent_list,i=0;i<((y_wo-oarea.g_y)/menu_font.ch+scroll_menu.vpos) && it;it=it->Gmi_next,i++); - if(it && it->Gmi_identifier){ - it->Gmi_selected=!it->Gmi_selected; - it->Gmi_count= count==0L ? -1L : count; - count = 0L; - if(Inv_how!=PICK_ANY) - break; - } /* identifier */ - } - oarea.g_x=(oarea.g_x+23+2*menu_font.cw) & ~7; - oarea.g_y=y_wo-(y_wo-oarea.g_y)%menu_font.ch; - oarea.g_w=menu_font.cw; - oarea.g_h=((ru_h+menu_font.ch-1)/menu_font.ch)*menu_font.ch; - ob_draw_chg(Inv_dialog,LINESLIST,&oarea,FAIL); - } - if(Inv_how==PICK_ANY){ - ob_set_text(Inv_dialog->di_tree,QLINE,strCancel); - for(it=invent_list;it;it=it->Gmi_next) - if(it->Gmi_identifier && it->Gmi_selected){ - ob_set_text(Inv_dialog->di_tree,QLINE,strOk); - break; - } - ob_draw_chg(Inv_dialog,QLINE,NULL,FAIL); - } - }while((d_exit&NO_CLICK)==LINESLIST); - if(d_exit!=W_ABANDON){ - my_close_dialog(Inv_dialog,FALSE); - if(d_exit!=W_CLOSED) - ob_undostate(z_ob,d_exit&NO_CLICK,SELECTED); - } - } - Event_Handler(NULL,NULL); - ob_set_text(z_ob,QLINE,tmp_button); - break; - case NHW_MAP: - if(p_Gw->gw_window==NULL){ - calc_std_winplace(NHW_MAP,&p_Gw->gw_place); - window_border(MAP_GADGETS,0,0,Tile_width*(COLNO-1),Tile_heigth*ROWNO, &g_mapmax); - p_Gw->gw_window=open_window(md, md, NULL, zz_oblist[NHICON], MAP_GADGETS, TRUE, 128, 128, &g_mapmax, &p_Gw->gw_place, &scroll_map, win_draw_map, NULL, XM_TOP|XM_BOTTOM|XM_SIZE); - WindowItems(p_Gw->gw_window,SCROLL_KEYS-1,scroll_keys); /* ClrHome centers on u */ - mar_clear_map(); - } - if(p_Gw->gw_dirty){ - area.g_x=p_Gw->gw_window->work.g_x+scroll_map.px_hline*(dirty_map_area.g_x-scroll_map.hpos); - area.g_y=p_Gw->gw_window->work.g_y+scroll_map.px_vline*(dirty_map_area.g_y-scroll_map.vpos); - area.g_w=(dirty_map_area.g_w-dirty_map_area.g_x+1)*scroll_map.px_hline; - area.g_h=(dirty_map_area.g_h-dirty_map_area.g_y+1)*scroll_map.px_vline; + ptr_win->scroll = &scroll_menu; + mar_menu_set_slider(ptr_win); + WindowItems(ptr_win, SCROLL_KEYS, scroll_keys); + do { + int y_wo, x_wo, ru_w = 1, ru_h = 1; + GRECT oarea; + Gem_menu_item *it; + d_exit = X_Form_Do(NULL); + if ((d_exit & NO_CLICK) == LINESLIST) { + ob_pos(z_ob, LINESLIST, &oarea); + if (mouse(&x_wo, &y_wo) && Inv_how == PICK_ANY) { + graf_rt_rubberbox(FALSE, x_wo, y_wo, FAIL, FAIL, + &oarea, &ru_w, &ru_h, NULL); + invert_all_on_page( + (int) ((y_wo - oarea.g_y) / menu_font.ch + + scroll_menu.vpos), + (ru_h + menu_font.ch - 1) / menu_font.ch, 0); + } else { + for (it = invent_list, i = 0; + i < ((y_wo - oarea.g_y) / menu_font.ch + + scroll_menu.vpos) + && it; + it = it->Gmi_next, i++) + ; + if (it && it->Gmi_identifier) { + it->Gmi_selected = !it->Gmi_selected; + it->Gmi_count = count == 0L ? -1L : count; + count = 0L; + if (Inv_how != PICK_ANY) + break; + } /* identifier */ + } + oarea.g_x = (oarea.g_x + 23 + 2 * menu_font.cw) & ~7; + oarea.g_y = y_wo - (y_wo - oarea.g_y) % menu_font.ch; + oarea.g_w = menu_font.cw; + oarea.g_h = ((ru_h + menu_font.ch - 1) / menu_font.ch) + * menu_font.ch; + ob_draw_chg(Inv_dialog, LINESLIST, &oarea, FAIL); + } + if (Inv_how == PICK_ANY) { + ob_set_text(Inv_dialog->di_tree, QLINE, strCancel); + for (it = invent_list; it; it = it->Gmi_next) + if (it->Gmi_identifier && it->Gmi_selected) { + ob_set_text(Inv_dialog->di_tree, QLINE, strOk); + break; + } + ob_draw_chg(Inv_dialog, QLINE, NULL, FAIL); + } + } while ((d_exit & NO_CLICK) == LINESLIST); + if (d_exit != W_ABANDON) { + my_close_dialog(Inv_dialog, FALSE); + if (d_exit != W_CLOSED) + ob_undostate(z_ob, d_exit & NO_CLICK, SELECTED); + } + } + Event_Handler(NULL, NULL); + ob_set_text(z_ob, QLINE, tmp_button); + break; + case NHW_MAP: + if (p_Gw->gw_window == NULL) { + calc_std_winplace(NHW_MAP, &p_Gw->gw_place); + window_border(MAP_GADGETS, 0, 0, Tile_width * (COLNO - 1), + Tile_heigth * ROWNO, &g_mapmax); + p_Gw->gw_window = open_window( + md, md, NULL, zz_oblist[NHICON], MAP_GADGETS, TRUE, 128, 128, + &g_mapmax, &p_Gw->gw_place, &scroll_map, win_draw_map, NULL, + XM_TOP | XM_BOTTOM | XM_SIZE); + WindowItems(p_Gw->gw_window, SCROLL_KEYS - 1, + scroll_keys); /* ClrHome centers on u */ + mar_clear_map(); + } + if (p_Gw->gw_dirty) { + area.g_x = p_Gw->gw_window->work.g_x + + scroll_map.px_hline + * (dirty_map_area.g_x - scroll_map.hpos); + area.g_y = p_Gw->gw_window->work.g_y + + scroll_map.px_vline + * (dirty_map_area.g_y - scroll_map.vpos); + area.g_w = (dirty_map_area.g_w - dirty_map_area.g_x + 1) + * scroll_map.px_hline; + area.g_h = (dirty_map_area.g_h - dirty_map_area.g_y + 1) + * scroll_map.px_vline; - redraw_window(p_Gw->gw_window,&area); + redraw_window(p_Gw->gw_window, &area); - dirty_map_area.g_x=COLNO-1; - dirty_map_area.g_y=ROWNO; - dirty_map_area.g_w= - dirty_map_area.g_h=0; - } - break; - case NHW_MESSAGE: - if(p_Gw->gw_window==NULL){ - calc_std_winplace(NHW_MESSAGE,&p_Gw->gw_place); - z_ob=zz_oblist[MSGWIN]; - magx=0; /* MAR -- Fake E_GEM to remove Backdropper */ - p_Gw->gw_window=open_window(NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, &p_Gw->gw_place, NULL, mar_draw_window, z_ob, XM_TOP|XM_BOTTOM|XM_SIZE); - magx=tmp_magx; - window_size(p_Gw->gw_window,&p_Gw->gw_window->curr); - p_Gw->gw_dirty=TRUE; - } + dirty_map_area.g_x = COLNO - 1; + dirty_map_area.g_y = ROWNO; + dirty_map_area.g_w = dirty_map_area.g_h = 0; + } + break; + case NHW_MESSAGE: + if (p_Gw->gw_window == NULL) { + calc_std_winplace(NHW_MESSAGE, &p_Gw->gw_place); + z_ob = zz_oblist[MSGWIN]; + magx = 0; /* MAR -- Fake E_GEM to remove Backdropper */ + p_Gw->gw_window = open_window( + NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, &p_Gw->gw_place, + NULL, mar_draw_window, z_ob, XM_TOP | XM_BOTTOM | XM_SIZE); + magx = tmp_magx; + window_size(p_Gw->gw_window, &p_Gw->gw_window->curr); + p_Gw->gw_dirty = TRUE; + } - if(p_Gw->gw_dirty){ - ob_pos(zz_oblist[MSGWIN],MSGLINES,&area); - while(messages_pro_zug>3){ - messages_pro_zug-=3; - msg_pos+=3; - redraw_window(p_Gw->gw_window,&area); - mar_more(); - } - msg_pos+=messages_pro_zug; - messages_pro_zug=0; - if(msg_pos>msg_max) msg_pos=msg_max; - redraw_window(p_Gw->gw_window,&area); - mar_message_pause=FALSE; - } - break; - case NHW_STATUS: - if(p_Gw->gw_window==NULL){ - z_ob=zz_oblist[STATUSLINE]; - calc_std_winplace(NHW_STATUS,&p_Gw->gw_place); - magx=0; /* MAR -- Fake E_GEM to remove Backdropper */ - p_Gw->gw_window=open_window(NULL, NULL, NULL, NULL, 0, FALSE, 0, 0, NULL, &p_Gw->gw_place, NULL, mar_draw_window, z_ob, XM_TOP|XM_BOTTOM|XM_SIZE); - magx=tmp_magx; - /* Because 2*status_font.ch is smaller then e_gem expects the minimum win_height */ - p_Gw->gw_window->min_h=z_ob[ROOT].ob_height; - window_size(p_Gw->gw_window,&p_Gw->gw_place); - p_Gw->gw_dirty=TRUE; - add_dirty_rect(dr_stat,&p_Gw->gw_place); - } - while(get_dirty_rect(dr_stat,&area)){ - area.g_x=(area.g_x+p_Gw->gw_window->work.g_x+2*status_font.cw+6)&~7; - area.g_y+=p_Gw->gw_window->work.g_y; - redraw_window(p_Gw->gw_window,&area); - } - break; - default: - if(p_Gw->gw_dirty) - redraw_window(p_Gw->gw_window,NULL); - } - p_Gw->gw_dirty=FALSE; + if (p_Gw->gw_dirty) { + ob_pos(zz_oblist[MSGWIN], MSGLINES, &area); + while (messages_pro_zug > 3) { + messages_pro_zug -= 3; + msg_pos += 3; + redraw_window(p_Gw->gw_window, &area); + mar_more(); + } + msg_pos += messages_pro_zug; + messages_pro_zug = 0; + if (msg_pos > msg_max) + msg_pos = msg_max; + redraw_window(p_Gw->gw_window, &area); + mar_message_pause = FALSE; + } + break; + case NHW_STATUS: + if (p_Gw->gw_window == NULL) { + z_ob = zz_oblist[STATUSLINE]; + calc_std_winplace(NHW_STATUS, &p_Gw->gw_place); + magx = 0; /* MAR -- Fake E_GEM to remove Backdropper */ + p_Gw->gw_window = open_window( + NULL, NULL, NULL, NULL, 0, FALSE, 0, 0, NULL, &p_Gw->gw_place, + NULL, mar_draw_window, z_ob, XM_TOP | XM_BOTTOM | XM_SIZE); + magx = tmp_magx; + /* Because 2*status_font.ch is smaller then e_gem expects the + * minimum win_height */ + p_Gw->gw_window->min_h = z_ob[ROOT].ob_height; + window_size(p_Gw->gw_window, &p_Gw->gw_place); + p_Gw->gw_dirty = TRUE; + add_dirty_rect(dr_stat, &p_Gw->gw_place); + } + while (get_dirty_rect(dr_stat, &area)) { + area.g_x = (area.g_x + p_Gw->gw_window->work.g_x + + 2 * status_font.cw + 6) & ~7; + area.g_y += p_Gw->gw_window->work.g_y; + redraw_window(p_Gw->gw_window, &area); + } + break; + default: + if (p_Gw->gw_dirty) + redraw_window(p_Gw->gw_window, NULL); + } + p_Gw->gw_dirty = FALSE; } /************************* create_window *******************************/ -int mar_hol_win_type(window) -winid window; +int +mar_hol_win_type(window) +winid window; { - return(Gem_nhwindow[window].gw_type); + return (Gem_nhwindow[window].gw_type); } winid mar_create_window(type) int type; { - winid newid; - static char name[]="Gem"; - int i; - struct gw *p_Gw=&Gem_nhwindow[0]; + winid newid; + static char name[] = "Gem"; + int i; + struct gw *p_Gw = &Gem_nhwindow[0]; - for(newid = 0; p_Gw->gw_type && newid < MAXWIN; newid++, p_Gw++); + for (newid = 0; p_Gw->gw_type && newid < MAXWIN; newid++, p_Gw++) + ; - switch(type){ - case NHW_MESSAGE: - message_line=(char **)m_alloc(msg_anz*sizeof(char *)); - message_age=(int *)m_alloc(msg_anz*sizeof(int)); - for(i=0;igw_window=open_window("Sonst", name, NULL, NULL, NAME|MOVER|CLOSER, 0, 0, 0, NULL, &p_Gw->gw_place, NULL, NULL, NULL, XM_TOP|XM_BOTTOM|XM_SIZE); - break; - } + mar_clear_map(); + break; + case NHW_MENU: + case NHW_TEXT: /* They are no more treated as dialog */ + break; + default: + p_Gw->gw_window = open_window( + "Sonst", name, NULL, NULL, NAME | MOVER | CLOSER, 0, 0, 0, NULL, + &p_Gw->gw_place, NULL, NULL, NULL, XM_TOP | XM_BOTTOM | XM_SIZE); + break; + } - p_Gw->gw_type=type; + p_Gw->gw_type = type; - return(newid); + return (newid); } void mar_change_menu_2_text(win) winid win; { - Gem_nhwindow[win].gw_type=NHW_TEXT; + Gem_nhwindow[win].gw_type = NHW_TEXT; } /************************* mar_clear_map *******************************/ @@ -2264,17 +2517,20 @@ winid win; void mar_clear_map() { - int pla[8]; - int x,y; + int pla[8]; + int x, y; - pla[0]=pla[1]=pla[4]=pla[5]=0; - pla[2]=pla[6]=scroll_map.px_hline*(COLNO-1)-1; - pla[3]=pla[7]=scroll_map.px_vline*ROWNO-1; - for(y=0;y0 ? scroll_margin : max(scroll_map.hpage/4,1), - hoehe=scroll_margin>0 ? scroll_margin : max(scroll_map.vpage/4,1), - adjust_needed; - adjust_needed=FALSE; - if ((map_cursx < scroll_map.hpos + breite) || (map_cursx >= scroll_map.hpos + scroll_map.hpage - breite)){ - scroll_map.hpos=map_cursx - scroll_map.hpage/2; - adjust_needed=TRUE; - } - if ((map_cursy < scroll_map.vpos + hoehe) || (map_cursy >= scroll_map.vpos + scroll_map.vpage - hoehe)){ - scroll_map.vpos=map_cursy - scroll_map.vpage/2; - adjust_needed=TRUE; - } - if(adjust_needed) - scroll_window(Gem_nhwindow[WIN_MAP].gw_window,WIN_SCROLL,NULL); - } + if (WIN_MAP != WIN_ERR && Gem_nhwindow[WIN_MAP].gw_window) { + int breite = scroll_margin > 0 ? scroll_margin + : max(scroll_map.hpage / 4, 1), + hoehe = scroll_margin > 0 ? scroll_margin + : max(scroll_map.vpage / 4, 1), + adjust_needed; + adjust_needed = FALSE; + if ((map_cursx < scroll_map.hpos + breite) + || (map_cursx >= scroll_map.hpos + scroll_map.hpage - breite)) { + scroll_map.hpos = map_cursx - scroll_map.hpage / 2; + adjust_needed = TRUE; + } + if ((map_cursy < scroll_map.vpos + hoehe) + || (map_cursy >= scroll_map.vpos + scroll_map.vpage - hoehe)) { + scroll_map.vpos = map_cursy - scroll_map.vpage / 2; + adjust_needed = TRUE; + } + if (adjust_needed) + scroll_window(Gem_nhwindow[WIN_MAP].gw_window, WIN_SCROLL, NULL); + } } void mar_update_value() { - if(WIN_MESSAGE!=WIN_ERR){ - mar_message_pause=FALSE; - mar_esc_pressed=FALSE; - mar_display_nhwindow(WIN_MESSAGE); - } + if (WIN_MESSAGE != WIN_ERR) { + mar_message_pause = FALSE; + mar_esc_pressed = FALSE; + mar_display_nhwindow(WIN_MESSAGE); + } - if(WIN_MAP!=WIN_ERR) - mar_cliparound(); + if (WIN_MAP != WIN_ERR) + mar_cliparound(); - if(WIN_STATUS!=WIN_ERR){ - mar_check_hilight_status(); - mar_display_nhwindow(WIN_STATUS); - } + if (WIN_STATUS != WIN_ERR) { + mar_check_hilight_status(); + mar_display_nhwindow(WIN_STATUS); + } } int -Main_Init(xev,availiable) +Main_Init(xev, availiable) XEVENT *xev; int availiable; { - xev->ev_mb1mask= - xev->ev_mb1state=1; - xev->ev_mb1clicks= - xev->ev_mb2clicks= - xev->ev_mb2mask= - xev->ev_mb2state=2; - return((MU_KEYBD|MU_BUTTON1|MU_BUTTON2|MU_MESAG)&availiable); + xev->ev_mb1mask = xev->ev_mb1state = 1; + xev->ev_mb1clicks = xev->ev_mb2clicks = xev->ev_mb2mask = + xev->ev_mb2state = 2; + return ((MU_KEYBD | MU_BUTTON1 | MU_BUTTON2 | MU_MESAG) & availiable); } /* @@ -2398,178 +2658,191 @@ int availiable; /*ARGSUSED*/ int mar_nh_poskey(x, y, mod) - int *x, *y, *mod; +int *x, *y, *mod; { - static XEVENT xev; - int retval, ev; + static XEVENT xev; + int retval, ev; - xev.ev_mflags=Main_Init(&xev,0xFFFF); - ev=Event_Multi(&xev); + xev.ev_mflags = Main_Init(&xev, 0xFFFF); + ev = Event_Multi(&xev); - retval=FAIL; + retval = FAIL; - if(ev&MU_KEYBD){ - char ch = xev.ev_mkreturn&0x00FF; - char scan = (xev.ev_mkreturn & 0xff00) >> 8; - int shift = xev.ev_mmokstate; - const struct pad *kpad; + if (ev & MU_KEYBD) { + char ch = xev.ev_mkreturn & 0x00FF; + char scan = (xev.ev_mkreturn & 0xff00) >> 8; + int shift = xev.ev_mmokstate; + const struct pad *kpad; - /* Translate keypad keys */ - if (iskeypad(scan)) { - kpad = mar_iflags_numpad()==1 ? numpad : keypad; - if (shift & K_SHIFT) - ch = kpad[scan - KEYPADLO].shift; - else if (shift & K_CTRL){ - if(scan>=0x67 && scan<=0x6f && scan!=0x6b){ - send_key(kpad[scan - KEYPADLO].normal); - ch = 'g'; - }else{ - ch = kpad[scan - KEYPADLO].cntrl; - } - }else - ch = kpad[scan - KEYPADLO].normal; - } - if(scan==SCANHOME) - mar_cliparound(); - else if(scan == SCANF1) - retval='h'; - else if(scan == SCANF2){ - mar_set_tile_mode(!mar_set_tile_mode(FAIL)); - retval=C('l'); /* trigger full-redraw */ - }else if(scan == SCANF3){ - draw_cursor=!draw_cursor; - mar_curs(map_cursx,map_cursy); - mar_display_nhwindow(WIN_MAP); - }else if(scan == SCANF4){ /* Font-Selector */ - if(!CallFontSelector(0,FAIL,FAIL,FAIL,FAIL)){ - xalert(1,1,X_ICN_ALERT,NULL,SYS_MODAL,BUTTONS_RIGHT,TRUE,"Hello","Fontselector not available!",NULL); - } - }else if(!ch && shift&K_CTRL && scan==-57){ - /* MAR -- nothing ignore Ctrl-Alt-Clr/Home == MagiC's restore screen */ - }else{ - if(!ch) - ch=(char)M(tolower(scan_2_ascii(xev.ev_mkreturn,shift))); - if(((int)ch)==-128) - ch='\033'; - retval=ch; - } - } + /* Translate keypad keys */ + if (iskeypad(scan)) { + kpad = mar_iflags_numpad() == 1 ? numpad : keypad; + if (shift & K_SHIFT) + ch = kpad[scan - KEYPADLO].shift; + else if (shift & K_CTRL) { + if (scan >= 0x67 && scan <= 0x6f && scan != 0x6b) { + send_key(kpad[scan - KEYPADLO].normal); + ch = 'g'; + } else { + ch = kpad[scan - KEYPADLO].cntrl; + } + } else + ch = kpad[scan - KEYPADLO].normal; + } + if (scan == SCANHOME) + mar_cliparound(); + else if (scan == SCANF1) + retval = 'h'; + else if (scan == SCANF2) { + mar_set_tile_mode(!mar_set_tile_mode(FAIL)); + retval = C('l'); /* trigger full-redraw */ + } else if (scan == SCANF3) { + draw_cursor = !draw_cursor; + mar_curs(map_cursx, map_cursy); + mar_display_nhwindow(WIN_MAP); + } else if (scan == SCANF4) { /* Font-Selector */ + if (!CallFontSelector(0, FAIL, FAIL, FAIL, FAIL)) { + xalert(1, 1, X_ICN_ALERT, NULL, SYS_MODAL, BUTTONS_RIGHT, + TRUE, "Hello", "Fontselector not available!", NULL); + } + } else if (!ch && shift & K_CTRL && scan == -57) { + /* MAR -- nothing ignore Ctrl-Alt-Clr/Home == MagiC's restore + * screen */ + } else { + if (!ch) + ch = (char) M(tolower(scan_2_ascii(xev.ev_mkreturn, shift))); + if (((int) ch) == -128) + ch = '\033'; + retval = ch; + } + } - if(ev&MU_BUTTON1 || ev&MU_BUTTON2){ - int ex=xev.ev_mmox, ey=xev.ev_mmoy; - WIN *akt_win=window_find(ex,ey); + if (ev & MU_BUTTON1 || ev & MU_BUTTON2) { + int ex = xev.ev_mmox, ey = xev.ev_mmoy; + WIN *akt_win = window_find(ex, ey); - if(WIN_MAP != WIN_ERR && akt_win==Gem_nhwindow[WIN_MAP].gw_window){ - *x=max(min((ex-akt_win->work.g_x)/scroll_map.px_hline+scroll_map.hpos,COLNO-1),0)+1; - *y=max(min((ey-akt_win->work.g_y)/scroll_map.px_vline+scroll_map.vpos,ROWNO),0); - *mod=xev.ev_mmobutton; - retval=0; - }else if(WIN_STATUS != WIN_ERR && akt_win==Gem_nhwindow[WIN_STATUS].gw_window){ - move_win(akt_win); - }else if(WIN_MESSAGE != WIN_ERR && akt_win==Gem_nhwindow[WIN_MESSAGE].gw_window){ - message_handler(ex,ey); - } - } + if (WIN_MAP != WIN_ERR + && akt_win == Gem_nhwindow[WIN_MAP].gw_window) { + *x = max(min((ex - akt_win->work.g_x) / scroll_map.px_hline + + scroll_map.hpos, + COLNO - 1), + 0) + 1; + *y = max(min((ey - akt_win->work.g_y) / scroll_map.px_vline + + scroll_map.vpos, + ROWNO), + 0); + *mod = xev.ev_mmobutton; + retval = 0; + } else if (WIN_STATUS != WIN_ERR + && akt_win == Gem_nhwindow[WIN_STATUS].gw_window) { + move_win(akt_win); + } else if (WIN_MESSAGE != WIN_ERR + && akt_win == Gem_nhwindow[WIN_MESSAGE].gw_window) { + message_handler(ex, ey); + } + } - if(ev&MU_MESAG){ - int *buf=xev.ev_mmgpbuf; - char *str; - OBJECT *z_ob=zz_oblist[MENU]; + if (ev & MU_MESAG) { + int *buf = xev.ev_mmgpbuf; + char *str; + OBJECT *z_ob = zz_oblist[MENU]; - switch(*buf) { - case MN_SELECTED : - menu_tnormal(z_ob,buf[3],TRUE); /* unselect menu header */ - str=ob_get_text(z_ob,buf[4],0); - str+=strlen(str)-2; - switch(*str){ - case ' ': /* just that command */ - retval=str[1]; - break; - case '\005': /* Alt command */ - case '\007': - retval=M(str[1]); - break; - case '^': /* Ctrl command */ - retval=C(str[1]); - break; - case 'f': /* Func Key */ - switch(str[1]){ - case '1': - retval='h'; - break; - case '2': - mar_set_tile_mode(!mar_set_tile_mode(FAIL)); - retval=C('l'); /* trigger full-redraw */ - break; - case '3': - draw_cursor=!draw_cursor; - mar_curs(map_cursx,map_cursy); - mar_display_nhwindow(WIN_MAP); - break; - default: - } - break; - default: - mar_about(); - break; - } - break; /* MN_SELECTED */ - case WM_CLOSED: - WindowHandler(W_ICONIFYALL,NULL,NULL); - break; - case AP_TERM: - retval='S'; - break; - case FONT_CHANGED: - if(buf[3]>=0){ - if(buf[3]==Gem_nhwindow[WIN_MESSAGE].gw_window->handle){ - mar_set_fontbyid(NHW_MESSAGE,buf[4],buf[5]); - mar_display_nhwindow(WIN_MESSAGE); - }else if(buf[3]==Gem_nhwindow[WIN_MAP].gw_window->handle){ - mar_set_fontbyid(NHW_MAP,buf[4],buf[5]); - mar_display_nhwindow(WIN_MAP); - }else if(buf[3]==Gem_nhwindow[WIN_STATUS].gw_window->handle){ - mar_set_fontbyid(NHW_STATUS,buf[4],buf[5]); - mar_display_nhwindow(WIN_STATUS); - } - FontAck(buf[1],1); - } - break; - default: - break; - } - } /* MU_MESAG */ + switch (*buf) { + case MN_SELECTED: + menu_tnormal(z_ob, buf[3], TRUE); /* unselect menu header */ + str = ob_get_text(z_ob, buf[4], 0); + str += strlen(str) - 2; + switch (*str) { + case ' ': /* just that command */ + retval = str[1]; + break; + case '\005': /* Alt command */ + case '\007': + retval = M(str[1]); + break; + case '^': /* Ctrl command */ + retval = C(str[1]); + break; + case 'f': /* Func Key */ + switch (str[1]) { + case '1': + retval = 'h'; + break; + case '2': + mar_set_tile_mode(!mar_set_tile_mode(FAIL)); + retval = C('l'); /* trigger full-redraw */ + break; + case '3': + draw_cursor = !draw_cursor; + mar_curs(map_cursx, map_cursy); + mar_display_nhwindow(WIN_MAP); + break; + default: + } + break; + default: + mar_about(); + break; + } + break; /* MN_SELECTED */ + case WM_CLOSED: + WindowHandler(W_ICONIFYALL, NULL, NULL); + break; + case AP_TERM: + retval = 'S'; + break; + case FONT_CHANGED: + if (buf[3] >= 0) { + if (buf[3] == Gem_nhwindow[WIN_MESSAGE].gw_window->handle) { + mar_set_fontbyid(NHW_MESSAGE, buf[4], buf[5]); + mar_display_nhwindow(WIN_MESSAGE); + } else if (buf[3] + == Gem_nhwindow[WIN_MAP].gw_window->handle) { + mar_set_fontbyid(NHW_MAP, buf[4], buf[5]); + mar_display_nhwindow(WIN_MAP); + } else if (buf[3] + == Gem_nhwindow[WIN_STATUS].gw_window->handle) { + mar_set_fontbyid(NHW_STATUS, buf[4], buf[5]); + mar_display_nhwindow(WIN_STATUS); + } + FontAck(buf[1], 1); + } + break; + default: + break; + } + } /* MU_MESAG */ - if(retval==FAIL) - retval=mar_nh_poskey(x,y,mod); + if (retval == FAIL) + retval = mar_nh_poskey(x, y, mod); - return(retval); + return (retval); } int Gem_nh_poskey(x, y, mod) - int *x, *y, *mod; +int *x, *y, *mod; { - mar_update_value(); - return(mar_nh_poskey(x, y, mod)); + mar_update_value(); + return (mar_nh_poskey(x, y, mod)); } void Gem_delay_output() { - Event_Timer(50,0,FALSE); /* wait 50ms */ + Event_Timer(50, 0, FALSE); /* wait 50ms */ } int Gem_doprev_message() { - if(msg_pos>2){ - msg_pos--; - if(WIN_MESSAGE != WIN_ERR) - Gem_nhwindow[WIN_MESSAGE].gw_dirty=TRUE; - mar_display_nhwindow(WIN_MESSAGE); - } - return(0); + if (msg_pos > 2) { + msg_pos--; + if (WIN_MESSAGE != WIN_ERR) + Gem_nhwindow[WIN_MESSAGE].gw_dirty = TRUE; + mar_display_nhwindow(WIN_MESSAGE); + } + return (0); } /************************* print_glyph *******************************/ @@ -2580,67 +2853,70 @@ int mar_set_tile_mode(tiles) int tiles; { - static int tile_mode=TRUE; - static GRECT prev; - WIN *z_w=WIN_MAP!=WIN_ERR ? Gem_nhwindow[WIN_MAP].gw_window : NULL; + static int tile_mode = TRUE; + static GRECT prev; + WIN *z_w = WIN_MAP != WIN_ERR ? Gem_nhwindow[WIN_MAP].gw_window : NULL; - if(tiles<0) - return(tile_mode); - else if(!z_w) - tile_mode=tiles; - else if(tile_mode==tiles || (mar_set_rogue(FAIL) && tiles)) - return(FAIL); - else{ - GRECT tmp; + if (tiles < 0) + return (tile_mode); + else if (!z_w) + tile_mode = tiles; + else if (tile_mode == tiles || (mar_set_rogue(FAIL) && tiles)) + return (FAIL); + else { + GRECT tmp; - tile_mode=tiles; - scroll_map.px_hline= tiles ? Tile_width : map_font.cw; - scroll_map.px_vline= tiles ? Tile_heigth : map_font.ch; - window_border(MAP_GADGETS,0,0,scroll_map.px_hline*(COLNO-1),scroll_map.px_vline*ROWNO, &tmp); - z_w->max.g_w=tmp.g_w; - z_w->max.g_h=tmp.g_h; - if(tiles) - z_w->curr=prev; - else - prev=z_w->curr; + tile_mode = tiles; + scroll_map.px_hline = tiles ? Tile_width : map_font.cw; + scroll_map.px_vline = tiles ? Tile_heigth : map_font.ch; + window_border(MAP_GADGETS, 0, 0, scroll_map.px_hline * (COLNO - 1), + scroll_map.px_vline * ROWNO, &tmp); + z_w->max.g_w = tmp.g_w; + z_w->max.g_h = tmp.g_h; + if (tiles) + z_w->curr = prev; + else + prev = z_w->curr; - window_reinit(z_w,md,md,NULL,FALSE,FALSE); - } - return(FAIL); + window_reinit(z_w, md, md, NULL, FALSE, FALSE); + } + return (FAIL); } int mar_set_rogue(what) int what; { - static int rogue=FALSE, prev_mode=TRUE; + static int rogue = FALSE, prev_mode = TRUE; - if(what<0) return(rogue); - if(what!=rogue){ - rogue=what; - if(rogue){ - prev_mode=mar_set_tile_mode(FAIL); - mar_set_tile_mode(FALSE); - }else - mar_set_tile_mode(prev_mode); - } - return(FAIL); + if (what < 0) + return (rogue); + if (what != rogue) { + rogue = what; + if (rogue) { + prev_mode = mar_set_tile_mode(FAIL); + mar_set_tile_mode(FALSE); + } else + mar_set_tile_mode(prev_mode); + } + return (FAIL); } void -mar_add_pet_sign(window,x,y) +mar_add_pet_sign(window, x, y) winid window; int x, y; { - if(window != WIN_ERR && window==WIN_MAP){ - static int pla[8]={0,0,7,7,0,0,0,0}, colindex[2]={RED,WHITE}; + if (window != WIN_ERR && window == WIN_MAP) { + static int pla[8] = { 0, 0, 7, 7, 0, 0, 0, 0 }, + colindex[2] = { RED, WHITE }; - pla[4]=pla[6]=scroll_map.px_hline*x; - pla[5]=pla[7]=scroll_map.px_vline*y; - pla[6]+=7; - pla[7]+=6; - vrt_cpyfm(x_handle,MD_TRANS,pla,&Pet_Mark,&Map_bild,colindex); - } + pla[4] = pla[6] = scroll_map.px_hline * x; + pla[5] = pla[7] = scroll_map.px_vline * y; + pla[6] += 7; + pla[7] += 6; + vrt_cpyfm(x_handle, MD_TRANS, pla, &Pet_Mark, &Map_bild, colindex); + } } void @@ -2648,21 +2924,22 @@ mar_print_glyph(window, x, y, gl) winid window; int x, y, gl; { - if(window != WIN_ERR && window==WIN_MAP){ - static int pla[8]; + if (window != WIN_ERR && window == WIN_MAP) { + static int pla[8]; - pla[2]=pla[0]=(gl%Tiles_per_line)*Tile_width; - pla[3]=pla[1]=(gl/Tiles_per_line)*Tile_heigth; - pla[2]+=Tile_width-1; - pla[3]+=Tile_heigth-1; - pla[6]=pla[4]=Tile_width*x; /* x_wert to */ - pla[7]=pla[5]=Tile_heigth*y; /* y_wert to */ - pla[6]+=Tile_width-1; - pla[7]+=Tile_heigth-1; + pla[2] = pla[0] = (gl % Tiles_per_line) * Tile_width; + pla[3] = pla[1] = (gl / Tiles_per_line) * Tile_heigth; + pla[2] += Tile_width - 1; + pla[3] += Tile_heigth - 1; + pla[6] = pla[4] = Tile_width * x; /* x_wert to */ + pla[7] = pla[5] = Tile_heigth * y; /* y_wert to */ + pla[6] += Tile_width - 1; + pla[7] += Tile_heigth - 1; - vro_cpyfm(x_handle, gl!=-1 ? S_ONLY : ALL_BLACK, pla, &Tile_bilder, &Map_bild); - } - } + vro_cpyfm(x_handle, gl != -1 ? S_ONLY : ALL_BLACK, pla, &Tile_bilder, + &Map_bild); + } +} void mar_print_char(window, x, y, ch, col) @@ -2671,24 +2948,25 @@ int x, y; char ch; int col; { - if(window != WIN_ERR && window==WIN_MAP){ - static int gem_color[16]={ 9, 2,11,10, 4, 7, 8, 15,0,14, 3, 6, 5, 13,15, 0}; - int pla[8], colindex[2]; + if (window != WIN_ERR && window == WIN_MAP) { + static int gem_color[16] = { 9, 2, 11, 10, 4, 7, 8, 15, + 0, 14, 3, 6, 5, 13, 15, 0 }; + int pla[8], colindex[2]; - map_glyphs[y][x]=ch; + map_glyphs[y][x] = ch; - pla[0]= - pla[1]=0; - pla[2]=map_font.cw-1; - pla[3]=map_font.ch-1; - pla[6]=pla[4]=map_font.cw*x; - pla[7]=pla[5]=map_font.ch*y; - pla[6]+=map_font.cw-1; - pla[7]+=map_font.ch-1; - colindex[0]=gem_color[col]; - colindex[1]=WHITE; - vrt_cpyfm(x_handle,MD_REPLACE,pla,&Black_bild,&FontCol_Bild,colindex); - } + pla[0] = pla[1] = 0; + pla[2] = map_font.cw - 1; + pla[3] = map_font.ch - 1; + pla[6] = pla[4] = map_font.cw * x; + pla[7] = pla[5] = map_font.ch * y; + pla[6] += map_font.cw - 1; + pla[7] += map_font.ch - 1; + colindex[0] = gem_color[col]; + colindex[1] = WHITE; + vrt_cpyfm(x_handle, MD_REPLACE, pla, &Black_bild, &FontCol_Bild, + colindex); + } } /************************* getlin *******************************/ @@ -2698,42 +2976,45 @@ Gem_getlin(ques, input) const char *ques; char *input; { - OBJECT *z_ob=zz_oblist[LINEGET]; - int d_exit, length; - char *pr[2], *tmp; + OBJECT *z_ob = zz_oblist[LINEGET]; + int d_exit, length; + char *pr[2], *tmp; - if(WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) - mar_display_nhwindow(WIN_MESSAGE); + if (WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) + mar_display_nhwindow(WIN_MESSAGE); - z_ob[LGPROMPT].ob_type=G_USERDEF; - z_ob[LGPROMPT].ob_spec.userblk=&ub_prompt; - z_ob[LGPROMPT].ob_height=2*gr_ch; + z_ob[LGPROMPT].ob_type = G_USERDEF; + z_ob[LGPROMPT].ob_spec.userblk = &ub_prompt; + z_ob[LGPROMPT].ob_height = 2 * gr_ch; - length=z_ob[LGPROMPT].ob_width/gr_cw; - if(strlen(ques)>length){ - tmp=ques+length; - while(*tmp!=' ' && tmp>=ques){ - tmp--; - } - if(tmp<=ques) tmp=ques+length; /* Mar -- Oops, what a word :-) */ - pr[0]=ques; - *tmp=0; - pr[1]=++tmp; - }else{ - pr[0]=ques; - pr[1]=NULL; - } - ub_prompt.ub_parm=(long)pr; + length = z_ob[LGPROMPT].ob_width / gr_cw; + if (strlen(ques) > length) { + tmp = ques + length; + while (*tmp != ' ' && tmp >= ques) { + tmp--; + } + if (tmp <= ques) + tmp = ques + length; /* Mar -- Oops, what a word :-) */ + pr[0] = ques; + *tmp = 0; + pr[1] = ++tmp; + } else { + pr[0] = ques; + pr[1] = NULL; + } + ub_prompt.ub_parm = (long) pr; - ob_clear_edit(z_ob); - d_exit=xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); + ob_clear_edit(z_ob); + d_exit = xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, + DIALOG_MODE); + Event_Timer(0, 0, TRUE); - if(d_exit==W_CLOSED || d_exit==W_ABANDON || (d_exit&NO_CLICK)==QLG){ - *input='\033'; - input[1]=0; - }else - strncpy(input,ob_get_text(z_ob,LGREPLY, 0),length); + if (d_exit == W_CLOSED || d_exit == W_ABANDON + || (d_exit & NO_CLICK) == QLG) { + *input = '\033'; + input[1] = 0; + } else + strncpy(input, ob_get_text(z_ob, LGREPLY, 0), length); } /************************* ask_direction *******************************/ @@ -2744,93 +3025,94 @@ int Dia_Handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; - char ch=(char)(xev->ev_mkreturn&0x00FF); + int ev = xev->ev_mwich; + char ch = (char) (xev->ev_mkreturn & 0x00FF); - if(ev&MU_KEYBD){ - WIN *w; - DIAINFO *dinf; + if (ev & MU_KEYBD) { + WIN *w; + DIAINFO *dinf; - switch(ch){ - case 's': - send_key((int)(mar_iflags_numpad() ? '5' : '.')); - break; - case '.': - send_key('5'); /* MAR -- '.' is a button if numpad isn't set */ - break; - case '\033': /*ESC*/ - if((w=get_top_window()) && (dinf=(DIAINFO *)w->dialog) && dinf->di_tree==zz_oblist[DIRECTION]){ - my_close_dialog(dinf,FALSE); - break; - } - /* Fall thru */ - default: - ev &= ~MU_KEYBD; /* let the dialog handle it */ - break; - } - } - return(ev); + switch (ch) { + case 's': + send_key((int) (mar_iflags_numpad() ? '5' : '.')); + break; + case '.': + send_key('5'); /* MAR -- '.' is a button if numpad isn't set */ + break; + case '\033': /*ESC*/ + if ((w = get_top_window()) && (dinf = (DIAINFO *) w->dialog) + && dinf->di_tree == zz_oblist[DIRECTION]) { + my_close_dialog(dinf, FALSE); + break; + } + /* Fall thru */ + default: + ev &= ~MU_KEYBD; /* let the dialog handle it */ + break; + } + } + return (ev); } int mar_ask_direction() { - int d_exit; - OBJECT *z_ob=zz_oblist[DIRECTION]; + int d_exit; + OBJECT *z_ob = zz_oblist[DIRECTION]; - Event_Handler(Dia_Init,Dia_Handler); - mar_set_dir_keys(); - d_exit=xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); - Event_Handler(NULL,NULL); + Event_Handler(Dia_Init, Dia_Handler); + mar_set_dir_keys(); + d_exit = xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, + DIALOG_MODE); + Event_Timer(0, 0, TRUE); + Event_Handler(NULL, NULL); - if(d_exit==W_CLOSED || d_exit==W_ABANDON) - return('\033'); - if((d_exit&NO_CLICK)==DIRDOWN) - return('>'); - if((d_exit&NO_CLICK)==DIRUP) - return('<'); - if((d_exit&NO_CLICK)==(DIR1+8)) /* 5 or . */ - return('.'); - return(*ob_get_text(z_ob,d_exit&NO_CLICK,0)); + if (d_exit == W_CLOSED || d_exit == W_ABANDON) + return ('\033'); + if ((d_exit & NO_CLICK) == DIRDOWN) + return ('>'); + if ((d_exit & NO_CLICK) == DIRUP) + return ('<'); + if ((d_exit & NO_CLICK) == (DIR1 + 8)) /* 5 or . */ + return ('.'); + return (*ob_get_text(z_ob, d_exit & NO_CLICK, 0)); } /************************* yn_function *******************************/ - #define any_init M_Init static int any_handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; + int ev = xev->ev_mwich; - if(ev&MU_MESAG){ - int *buf=xev->ev_mmgpbuf; + if (ev & MU_MESAG) { + int *buf = xev->ev_mmgpbuf; - if(*buf==OBJC_EDITED) - my_close_dialog(*(DIAINFO **)&buf[4], FALSE); - else - ev &= ~MU_MESAG; - } - return(ev); + if (*buf == OBJC_EDITED) + my_close_dialog(*(DIAINFO **) &buf[4], FALSE); + else + ev &= ~MU_MESAG; + } + return (ev); } int send_yn_esc(char ch) { - static char esc_char=0; + static char esc_char = 0; - if(ch<0){ - if(esc_char){ - send_key((int)esc_char); - return(TRUE); - } - return(FALSE); - }else - esc_char=ch; - return(TRUE); + if (ch < 0) { + if (esc_char) { + send_key((int) esc_char); + return (TRUE); + } + return (FALSE); + } else + esc_char = ch; + return (TRUE); } #define single_init K_Init @@ -2839,126 +3121,136 @@ static int single_handler(xev) XEVENT *xev; { - int ev=xev->ev_mwich; + int ev = xev->ev_mwich; - if(ev&MU_KEYBD){ - char ch=(char)xev->ev_mkreturn&0x00FF; - WIN *w; - DIAINFO *dinf; + if (ev & MU_KEYBD) { + char ch = (char) xev->ev_mkreturn & 0x00FF; + WIN *w; + DIAINFO *dinf; - switch(ch){ - case ' ': - send_return(); - break; - case '\033': - if((w=get_top_window()) && (dinf=(DIAINFO *)w->dialog) && dinf->di_tree==zz_oblist[YNCHOICE]){ - if(!send_yn_esc(FAIL)) - my_close_dialog(dinf,FALSE); - break; - } - /* Fall thru */ - default: - ev &= ~MU_MESAG; - } - } - return(ev); + switch (ch) { + case ' ': + send_return(); + break; + case '\033': + if ((w = get_top_window()) && (dinf = (DIAINFO *) w->dialog) + && dinf->di_tree == zz_oblist[YNCHOICE]) { + if (!send_yn_esc(FAIL)) + my_close_dialog(dinf, FALSE); + break; + } + /* Fall thru */ + default: + ev &= ~MU_MESAG; + } + } + return (ev); } char -Gem_yn_function(query,resp, def) -const char *query,*resp; +Gem_yn_function(query, resp, def) +const char *query, *resp; char def; { - OBJECT *z_ob=zz_oblist[YNCHOICE]; - int d_exit, i, len; - long anzahl; - char *tmp; - const char *ptr; + OBJECT *z_ob = zz_oblist[YNCHOICE]; + int d_exit, i, len; + long anzahl; + char *tmp; + const char *ptr; - if(WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) - mar_display_nhwindow(WIN_MESSAGE); + if (WIN_MESSAGE != WIN_ERR && Gem_nhwindow[WIN_MESSAGE].gw_window) + mar_display_nhwindow(WIN_MESSAGE); - /* if query for direction the special dialog */ - if(strstr(query,"irect")) - return(mar_ask_direction()); + /* if query for direction the special dialog */ + if (strstr(query, "irect")) + return (mar_ask_direction()); - len=min(strlen(query),(max_w-8*gr_cw)/gr_cw); - z_ob[ROOT].ob_width=(len+8)*gr_cw; - z_ob[YNPROMPT].ob_width=gr_cw*len+8; - tmp=ob_get_text(z_ob,YNPROMPT,0); - ob_set_text(z_ob,YNPROMPT,mar_copy_of(query)); + len = min(strlen(query), (max_w - 8 * gr_cw) / gr_cw); + z_ob[ROOT].ob_width = (len + 8) * gr_cw; + z_ob[YNPROMPT].ob_width = gr_cw * len + 8; + tmp = ob_get_text(z_ob, YNPROMPT, 0); + ob_set_text(z_ob, YNPROMPT, mar_copy_of(query)); - if(resp){ /* single inputs */ - ob_hide(z_ob,SOMECHARS,FALSE); - ob_hide(z_ob,ANYCHAR,TRUE); + if (resp) { /* single inputs */ + ob_hide(z_ob, SOMECHARS, FALSE); + ob_hide(z_ob, ANYCHAR, TRUE); - if(strchr(resp,'q')) send_yn_esc('q'); - else if(strchr(resp,'n')) send_yn_esc('n'); - else send_yn_esc(def); /* strictly def should be returned, but in trad. I it's 0 */ + if (strchr(resp, 'q')) + send_yn_esc('q'); + else if (strchr(resp, 'n')) + send_yn_esc('n'); + else + send_yn_esc( + def); /* strictly def should be returned, but in trad. I it's + 0 */ - if(strchr(resp,'#')){ /* count possible */ - ob_hide(z_ob,YNOK,FALSE); - ob_hide(z_ob,COUNT,FALSE); - }else{ /* no count */ - ob_hide(z_ob,YNOK,TRUE); - ob_hide(z_ob,COUNT,TRUE); - } + if (strchr(resp, '#')) { /* count possible */ + ob_hide(z_ob, YNOK, FALSE); + ob_hide(z_ob, COUNT, FALSE); + } else { /* no count */ + ob_hide(z_ob, YNOK, TRUE); + ob_hide(z_ob, COUNT, TRUE); + } - if((anzahl=(long)strchr(resp,'\033'))){ - anzahl-=(long)resp; - }else{ - anzahl=strlen(resp); - } - for(i=0,ptr=resp;i<2*anzahl;i+=2,ptr++){ - ob_hide(z_ob,YN1+i,FALSE); - mar_change_button_char(z_ob,YN1+i,*ptr); - ob_undoflag(z_ob,YN1+i,DEFAULT); - if(*ptr==def) - ob_doflag(z_ob,YN1+i,DEFAULT); - } + if ((anzahl = (long) strchr(resp, '\033'))) { + anzahl -= (long) resp; + } else { + anzahl = strlen(resp); + } + for (i = 0, ptr = resp; i < 2 * anzahl; i += 2, ptr++) { + ob_hide(z_ob, YN1 + i, FALSE); + mar_change_button_char(z_ob, YN1 + i, *ptr); + ob_undoflag(z_ob, YN1 + i, DEFAULT); + if (*ptr == def) + ob_doflag(z_ob, YN1 + i, DEFAULT); + } - z_ob[SOMECHARS].ob_width=z_ob[YN1+i].ob_x+8; - z_ob[SOMECHARS].ob_height=z_ob[YN1+i].ob_y+gr_ch+gr_ch/2; - Max((int *)&z_ob[ROOT].ob_width,z_ob[SOMECHARS].ob_width+4*gr_cw); - z_ob[ROOT].ob_height=z_ob[SOMECHARS].ob_height+4*gr_ch; - if(strchr(resp,'#')) - z_ob[ROOT].ob_height=z_ob[YNOK].ob_y+2*gr_ch; + z_ob[SOMECHARS].ob_width = z_ob[YN1 + i].ob_x + 8; + z_ob[SOMECHARS].ob_height = z_ob[YN1 + i].ob_y + gr_ch + gr_ch / 2; + Max((int *) &z_ob[ROOT].ob_width, + z_ob[SOMECHARS].ob_width + 4 * gr_cw); + z_ob[ROOT].ob_height = z_ob[SOMECHARS].ob_height + 4 * gr_ch; + if (strchr(resp, '#')) + z_ob[ROOT].ob_height = z_ob[YNOK].ob_y + 2 * gr_ch; - for(i+=YN1;i<(YNN+1);i+=2){ - ob_hide(z_ob,i,TRUE); - } - Event_Handler(single_init,single_handler); - }else{ /* any input */ - ob_hide(z_ob,SOMECHARS,TRUE); - ob_hide(z_ob,ANYCHAR,FALSE); - ob_hide(z_ob,YNOK,TRUE); - ob_hide(z_ob,COUNT,TRUE); - z_ob[ANYCHAR].ob_height=2*gr_ch; - z_ob[CHOSENCH].ob_y= - z_ob[CHOSENCH+1].ob_y=gr_ch/2; - z_ob[ROOT].ob_width=max(z_ob[YNPROMPT].ob_width+z_ob[YNPROMPT].ob_x,z_ob[ANYCHAR].ob_width+z_ob[ANYCHAR].ob_x)+2*gr_cw; - z_ob[ROOT].ob_height=z_ob[ANYCHAR].ob_height+z_ob[ANYCHAR].ob_y+gr_ch/2; - *ob_get_text(z_ob,CHOSENCH,0)='?'; - Event_Handler(any_init,any_handler); - } + for (i += YN1; i < (YNN + 1); i += 2) { + ob_hide(z_ob, i, TRUE); + } + Event_Handler(single_init, single_handler); + } else { /* any input */ + ob_hide(z_ob, SOMECHARS, TRUE); + ob_hide(z_ob, ANYCHAR, FALSE); + ob_hide(z_ob, YNOK, TRUE); + ob_hide(z_ob, COUNT, TRUE); + z_ob[ANYCHAR].ob_height = 2 * gr_ch; + z_ob[CHOSENCH].ob_y = z_ob[CHOSENCH + 1].ob_y = gr_ch / 2; + z_ob[ROOT].ob_width = + max(z_ob[YNPROMPT].ob_width + z_ob[YNPROMPT].ob_x, + z_ob[ANYCHAR].ob_width + z_ob[ANYCHAR].ob_x) + 2 * gr_cw; + z_ob[ROOT].ob_height = + z_ob[ANYCHAR].ob_height + z_ob[ANYCHAR].ob_y + gr_ch / 2; + *ob_get_text(z_ob, CHOSENCH, 0) = '?'; + Event_Handler(any_init, any_handler); + } - d_exit=xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, DIALOG_MODE); - Event_Timer(0,0,TRUE); - Event_Handler(NULL,NULL); - /* display of count is missing (through the core too) */ + d_exit = xdialog(z_ob, nullstr, NULL, NULL, mar_ob_mapcenter(z_ob), FALSE, + DIALOG_MODE); + Event_Timer(0, 0, TRUE); + Event_Handler(NULL, NULL); + /* display of count is missing (through the core too) */ - free(ob_get_text(z_ob,YNPROMPT,0)); - ob_set_text(z_ob,YNPROMPT,tmp); + free(ob_get_text(z_ob, YNPROMPT, 0)); + ob_set_text(z_ob, YNPROMPT, tmp); - if(resp && (d_exit==W_CLOSED || d_exit==W_ABANDON)) - return('\033'); - if((d_exit&NO_CLICK)==YNOK){ - yn_number=atol(ob_get_text(z_ob,COUNT,0)); - return('#'); - } - if(!resp) - return(*ob_get_text(z_ob,CHOSENCH,0)); - return(*ob_get_text(z_ob,d_exit&NO_CLICK,0)); + if (resp && (d_exit == W_CLOSED || d_exit == W_ABANDON)) + return ('\033'); + if ((d_exit & NO_CLICK) == YNOK) { + yn_number = atol(ob_get_text(z_ob, COUNT, 0)); + return ('#'); + } + if (!resp) + return (*ob_get_text(z_ob, CHOSENCH, 0)); + return (*ob_get_text(z_ob, d_exit & NO_CLICK, 0)); } /* @@ -2969,29 +3261,32 @@ char def; */ static char * mar_copy_of(s) - const char *s; +const char *s; { - if (!s) s = nullstr; + if (!s) + s = nullstr; return strcpy((char *) m_alloc((unsigned) (strlen(s) + 1)), s); } -const char *strRP="raw_print", *strRPB="raw_print_bold"; +const char *strRP = "raw_print", *strRPB = "raw_print_bold"; void mar_raw_print(str) const char *str; { - xalert(1,FAIL,X_ICN_INFO,NULL,APPL_MODAL,BUTTONS_CENTERED,TRUE,strRP,str,NULL); + xalert(1, FAIL, X_ICN_INFO, NULL, APPL_MODAL, BUTTONS_CENTERED, TRUE, + strRP, str, NULL); } void mar_raw_print_bold(str) const char *str; { - char buf[BUFSZ]; + char buf[BUFSZ]; - sprintf(buf,"!%s",str); - xalert(1,FAIL,X_ICN_INFO,NULL,APPL_MODAL,BUTTONS_CENTERED,TRUE,strRPB,buf,NULL); + sprintf(buf, "!%s", str); + xalert(1, FAIL, X_ICN_INFO, NULL, APPL_MODAL, BUTTONS_CENTERED, TRUE, + strRPB, buf, NULL); } /*wingem1.c*/ diff --git a/win/gem/xpm2img.c b/win/gem/xpm2img.c index f3e5dafea..c2608fb4a 100644 --- a/win/gem/xpm2img.c +++ b/win/gem/xpm2img.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 xpm2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 xpm2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ /* NetHack 3.6 xpm2img.c $Date: 2009/05/06 10:56:48 $ $Revision: 1.3 $ */ /* SCCS Id: @(#)xpm2img.c 3.5 2002/03/17 */ /* Copyright (c) Christian Bressler 2002 */ @@ -16,13 +16,13 @@ char *xpmgetline(); unsigned int **Bild_daten; /* translation table from xpm characters to RGB and colormap slots */ struct Ttable { - char flag; - struct RGB col; - int slot; /* output colortable index */ -}ttable[256]; + char flag; + struct RGB col; + int slot; /* output colortable index */ +} ttable[256]; struct RGB *ColorMap; int num_colors = 0; -int width=0, height=0; +int width = 0, height = 0; int initflag; FILE *fp; int @@ -30,66 +30,73 @@ main(argc, argv) int argc; char *argv[]; { - int i; - int row, col, planeno; - int farben, planes; - if (argc != 3) { - fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n"); - exit(EXIT_FAILURE); - } - initflag = 0; - fp = fopen(argv[2],"wb"); - if (!fp) { - printf("Error creating IMG-file %s, aborting.\n",argv[2]); - exit(EXIT_FAILURE); - } - fclose(fp); - if(fopen_xpm_file(argv[1],"r")!=TRUE){ - printf("Error reading xpm-file %s, aborting.\n",argv[1]); - exit(EXIT_FAILURE); - } - Bild_daten=(unsigned int **)malloc((long)height*sizeof(unsigned int *)); - for(i=0;i256){ - fprintf(stderr,"ERROR: zuviele Farben\n"); - exit(EXIT_FAILURE); - }else if(num_colors>16){ - farben=256; - planes=8; - }else if(num_colors>2){ - farben=16; - planes=4; - }else{ - farben=2; - planes=1; - } - bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2], get_color, get_pixel ); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + int i; + int row, col, planeno; + int farben, planes; + if (argc != 3) { + fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n"); + exit(EXIT_FAILURE); + } + initflag = 0; + fp = fopen(argv[2], "wb"); + if (!fp) { + printf("Error creating IMG-file %s, aborting.\n", argv[2]); + exit(EXIT_FAILURE); + } + fclose(fp); + if (fopen_xpm_file(argv[1], "r") != TRUE) { + printf("Error reading xpm-file %s, aborting.\n", argv[1]); + exit(EXIT_FAILURE); + } + Bild_daten = + (unsigned int **) malloc((long) height * sizeof(unsigned int *)); + for (i = 0; i < height; i++) + Bild_daten[i] = + (unsigned int *) malloc((long) width * sizeof(unsigned int)); + for (row = 0; row < height; row++) { + char *xb = xpmgetline(); + int plane_offset; + if (xb == 0) { + printf("Error to few lines in xpm-file %s, aborting.\n", argv[1]); + exit(EXIT_FAILURE); + } + for (col = 0; col < width; col++) { + int color = xb[col]; + if (!ttable[color].flag) + fprintf(stderr, "Bad image data\n"); + Bild_daten[row][col] = ttable[color].slot; + } + } + if (num_colors > 256) { + fprintf(stderr, "ERROR: zuviele Farben\n"); + exit(EXIT_FAILURE); + } else if (num_colors > 16) { + farben = 256; + planes = 8; + } else if (num_colors > 2) { + farben = 16; + planes = 4; + } else { + farben = 2; + planes = 1; + } + bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2], + get_color, get_pixel); + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } -void get_color(unsigned int colind, struct RGB *rgb){ - rgb->r=(1000L*(long)ColorMap[colind].r)/0xFF; - rgb->g=(1000L*(long)ColorMap[colind].g)/0xFF; - rgb->b=(1000L*(long)ColorMap[colind].b)/0xFF; +void +get_color(unsigned int colind, struct RGB *rgb) +{ + rgb->r = (1000L * (long) ColorMap[colind].r) / 0xFF; + rgb->g = (1000L * (long) ColorMap[colind].g) / 0xFF; + rgb->b = (1000L * (long) ColorMap[colind].b) / 0xFF; } -void get_pixel(int x, int y, unsigned int *colind){ - *colind=Bild_daten[y][x]; +void +get_pixel(int x, int y, unsigned int *colind) +{ + *colind = Bild_daten[y][x]; } FILE *xpmfh = 0; char initbuf[200]; @@ -97,70 +104,83 @@ char *xpmbuf = initbuf; /* version 1. Reads the raw xpm file, NOT the compiled version. This is * not a particularly good idea but I don't have time to do the right thing * at this point, even if I was absolutely sure what that was. */ -fopen_xpm_file(const char *fn, const char *mode){ - int temp; - char *xb; - if(strcmp(mode, "r"))return FALSE; /* no choice now */ - if(xpmfh)return FALSE; /* one file at a time */ - xpmfh = fopen(fn, mode); - if(!xpmfh)return FALSE; /* I'm hard to please */ - /* read the header */ - xb = xpmgetline(); - if(xb == 0)return FALSE; - if(4 != sscanf(xb,"%d %d %d %d", - &width, &height,&num_colors, &temp)) - return FALSE; /* bad header */ - /* replace the original buffer with one big enough for - * the real data - */ -/* XXX */ - xpmbuf = malloc(width * 2); - if(!xpmbuf){ - fprintf(stderr,"ERROR: Can't allocate line buffer\n"); - exit(1); - } - if(temp != 1)return FALSE; /* limitation of this code */ - { - /* read the colormap and translation table */ - int ccount = -1; - ColorMap = (struct RGB *)malloc((long)num_colors*sizeof(struct RGB)); - while(ccount++ < (num_colors-1)){ - char index; - int r, g, b; - xb = xpmgetline(); - if(xb==0)return FALSE; - if(4 != sscanf(xb,"%c c #%2x%2x%2x",&index,&r,&g,&b)){ - fprintf(stderr,"Bad color entry: %s\n",xb); - return FALSE; - } - ttable[index].flag = 1; /* this color is valid */ - ttable[index].col.r = r; - ttable[index].col.g = g; - ttable[index].col.b = b; - ttable[index].slot = ccount; - ColorMap[ccount].r=r; - ColorMap[ccount].g=g; - ColorMap[ccount].b=b; - } - } - return TRUE; +fopen_xpm_file(const char *fn, const char *mode) +{ + int temp; + char *xb; + if (strcmp(mode, "r")) + return FALSE; /* no choice now */ + if (xpmfh) + return FALSE; /* one file at a time */ + xpmfh = fopen(fn, mode); + if (!xpmfh) + return FALSE; /* I'm hard to please */ + /* read the header */ + xb = xpmgetline(); + if (xb == 0) + return FALSE; + if (4 != sscanf(xb, "%d %d %d %d", &width, &height, &num_colors, &temp)) + return FALSE; /* bad header */ + /* replace the original buffer with one big enough for + * the real data + */ + /* XXX */ + xpmbuf = malloc(width * 2); + if (!xpmbuf) { + fprintf(stderr, "ERROR: Can't allocate line buffer\n"); + exit(1); + } + if (temp != 1) + return FALSE; /* limitation of this code */ + { + /* read the colormap and translation table */ + int ccount = -1; + ColorMap = + (struct RGB *) malloc((long) num_colors * sizeof(struct RGB)); + while (ccount++ < (num_colors - 1)) { + char index; + int r, g, b; + xb = xpmgetline(); + if (xb == 0) + return FALSE; + if (4 != sscanf(xb, "%c c #%2x%2x%2x", &index, &r, &g, &b)) { + fprintf(stderr, "Bad color entry: %s\n", xb); + return FALSE; + } + ttable[index].flag = 1; /* this color is valid */ + ttable[index].col.r = r; + ttable[index].col.g = g; + ttable[index].col.b = b; + ttable[index].slot = ccount; + ColorMap[ccount].r = r; + ColorMap[ccount].g = g; + ColorMap[ccount].b = b; + } + } + return TRUE; } /* This deserves better. Don't read it too closely - you'll get ill. */ #define bufsz 2048 char buf[bufsz]; char * -xpmgetline(){ - char *bp; - do { - if(fgets(buf, bufsz, xpmfh) == 0)return 0; - } while(buf[0] != '"'); - /* strip off the trailing <",> if any */ - for(bp = buf;*bp;bp++); - bp--; - while(isspace(*bp))bp--; - if(*bp==',')bp--; - if(*bp=='"')bp--; - bp++; - *bp = '\0'; - return &buf[1]; +xpmgetline() +{ + char *bp; + do { + if (fgets(buf, bufsz, xpmfh) == 0) + return 0; + } while (buf[0] != '"'); + /* strip off the trailing <",> if any */ + for (bp = buf; *bp; bp++) + ; + bp--; + while (isspace(*bp)) + bp--; + if (*bp == ',') + bp--; + if (*bp == '"') + bp--; + bp++; + *bp = '\0'; + return &buf[1]; } diff --git a/win/gnome/gnaskstr.c b/win/gnome/gnaskstr.c index 150728a15..412929278 100644 --- a/win/gnome/gnaskstr.c +++ b/win/gnome/gnaskstr.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnaskstr.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnaskstr.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 gnaskstr.c $Date: 2009/05/06 10:57:24 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)gnaskstr.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -8,56 +8,52 @@ #include "gnmain.h" #include - -static -void ghack_ask_string_callback(gchar * string, gpointer data) +static void +ghack_ask_string_callback(gchar *string, gpointer data) { - char **user_text = (char **) data; + char **user_text = (char **) data; - g_assert(user_text != NULL); + g_assert(user_text != NULL); - *user_text = string; /* note - value must be g_free'd */ + *user_text = string; /* note - value must be g_free'd */ } - -int ghack_ask_string_dialog(const char *szMessageStr, - const char *szDefaultStr, const char *szTitleStr, - char *buffer) +int +ghack_ask_string_dialog(const char *szMessageStr, const char *szDefaultStr, + const char *szTitleStr, char *buffer) { int i; - GtkWidget* dialog; - gchar *user_text = NULL; + GtkWidget *dialog; + gchar *user_text = NULL; - dialog = gnome_request_dialog(FALSE, szMessageStr, - szDefaultStr, 0, - ghack_ask_string_callback, - &user_text, NULL); + dialog = + gnome_request_dialog(FALSE, szMessageStr, szDefaultStr, 0, + ghack_ask_string_callback, &user_text, NULL); g_assert(dialog != NULL); gtk_window_set_title(GTK_WINDOW(dialog), szTitleStr); - gnome_dialog_set_default( GNOME_DIALOG(dialog), 0); - gtk_window_set_modal( GTK_WINDOW(dialog), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), - GTK_WINDOW (ghack_get_main_window ()) ); + gnome_dialog_set_default(GNOME_DIALOG(dialog), 0); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gnome_dialog_set_parent(GNOME_DIALOG(dialog), + GTK_WINDOW(ghack_get_main_window())); + + i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog)); - i = gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - /* Quit */ - if ( i != 0 || user_text == NULL ) { - if (user_text) - g_free(user_text); - return -1; + if (i != 0 || user_text == NULL) { + if (user_text) + g_free(user_text); + return -1; } - if ( *user_text == 0 ) { - g_free(user_text); - return -1; + if (*user_text == 0) { + g_free(user_text); + return -1; } g_assert(strlen(user_text) > 0); - strcpy (buffer, user_text); + strcpy(buffer, user_text); g_free(user_text); return 0; } - diff --git a/win/gnome/gnbind.c b/win/gnome/gnbind.c index 0d980b131..8a5c75269 100644 --- a/win/gnome/gnbind.c +++ b/win/gnome/gnbind.c @@ -1,11 +1,11 @@ -/* NetHack 3.6 gnbind.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnbind.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.30 $ */ /* NetHack 3.6 gnbind.c $Date: 2012/01/24 04:26:31 $ $Revision: 1.25 $ */ /* Copyright (C) 1998 by Erik Andersen */ /* NetHack may be freely redistributed. See license for details. */ /* * This file implements the interface between the window port specific - * code in the Gnome port and the rest of the nethack game engine. + * code in the Gnome port and the rest of the nethack game engine. */ #include "gnbind.h" @@ -23,77 +23,43 @@ extern void tty_raw_print_bold(const char *); /* this is only needed until gnome_status_* routines are written */ extern NEARDATA winid WIN_STATUS; - /* Interface definition, for windows.c */ struct window_procs Gnome_procs = { - "Gnome", - WC_COLOR|WC_HILITE_PET|WC_INVERSE, - 0L, - gnome_init_nhwindows, - gnome_player_selection, - gnome_askname, - gnome_get_nh_event, - gnome_exit_nhwindows, - gnome_suspend_nhwindows, - gnome_resume_nhwindows, - gnome_create_nhwindow, - gnome_clear_nhwindow, - gnome_display_nhwindow, - gnome_destroy_nhwindow, - gnome_curs, - gnome_putstr, - genl_putmixed, - gnome_display_file, - gnome_start_menu, - gnome_add_menu, - gnome_end_menu, + "Gnome", WC_COLOR | WC_HILITE_PET | WC_INVERSE, 0L, gnome_init_nhwindows, + gnome_player_selection, gnome_askname, gnome_get_nh_event, + gnome_exit_nhwindows, gnome_suspend_nhwindows, gnome_resume_nhwindows, + gnome_create_nhwindow, gnome_clear_nhwindow, gnome_display_nhwindow, + gnome_destroy_nhwindow, gnome_curs, gnome_putstr, genl_putmixed, + gnome_display_file, gnome_start_menu, gnome_add_menu, gnome_end_menu, gnome_select_menu, - genl_message_menu, /* no need for X-specific handling */ - gnome_update_inventory, - gnome_mark_synch, - gnome_wait_synch, + genl_message_menu, /* no need for X-specific handling */ + gnome_update_inventory, gnome_mark_synch, gnome_wait_synch, #ifdef CLIPPING gnome_cliparound, #endif #ifdef POSITIONBAR donull, #endif - gnome_print_glyph, - gnome_raw_print, - gnome_raw_print_bold, - gnome_nhgetch, - gnome_nh_poskey, - gnome_nhbell, - gnome_doprev_message, - gnome_yn_function, - gnome_getlin, - gnome_get_ext_cmd, - gnome_number_pad, - gnome_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - donull, - donull, + gnome_print_glyph, gnome_raw_print, gnome_raw_print_bold, gnome_nhgetch, + gnome_nh_poskey, gnome_nhbell, gnome_doprev_message, gnome_yn_function, + gnome_getlin, gnome_get_ext_cmd, gnome_number_pad, gnome_delay_output, +#ifdef CHANGE_COLOR /* only a Mac option currently */ + donull, donull, #endif /* other defs that really should go away (they're tty specific) */ - gnome_start_screen, - gnome_end_screen, - gnome_outrip, - genl_preference_update, - genl_getmsghistory, - genl_putmsghistory, + gnome_start_screen, gnome_end_screen, gnome_outrip, + genl_preference_update, genl_getmsghistory, genl_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, + genl_status_init, genl_status_finish, genl_status_enablefield, genl_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES genl_status_threshold, -# endif +#endif #endif genl_can_suspend_yes, }; -/* +/* init_nhwindows(int* argcp, char** argv) -- Initialize the windows used by NetHack. This can also create the standard windows listed at the top, but does @@ -107,20 +73,21 @@ init_nhwindows(int* argcp, char** argv) ** Why not have init_nhwindows() create all of the "standard" ** windows? Or at least all but WIN_INFO? -dean */ -void gnome_init_nhwindows(int* argc, char** argv) +void +gnome_init_nhwindows(int *argc, char **argv) { /* Main window */ - ghack_init_main_window( *argc, argv); - ghack_init_signals( ); + ghack_init_main_window(*argc, argv); + ghack_init_signals(); #ifdef HACKDIR - //if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm")) + // if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm")) if (ghack_init_glyphs(HACKDIR "/x11tiles")) - g_error ("ERROR: Could not initialize glyphs.\n"); + g_error("ERROR: Could not initialize glyphs.\n"); #else -# error HACKDIR is not defined! +#error HACKDIR is not defined! #endif - + // gnome/gtk is not reentrant set_option_mod_status("ignintr", DISP_IN_GAME); flags.ignintr = TRUE; @@ -131,7 +98,6 @@ void gnome_init_nhwindows(int* argc, char** argv) WIN_WORN = gnome_create_nhwindow(NHW_WORN); } - /* Do a window-port specific player type selection. If player_selection() offers a Quit option, it is its responsibility to clean up and terminate the process. You need to fill in pl_character[0]. @@ -140,54 +106,66 @@ void gnome_player_selection() { int n, i, sel; - const char** choices; - int* pickmap; + const char **choices; + int *pickmap; /* prevent an unnecessary prompt */ rigid_role_checks(); if (!flags.randomall && flags.initrole < 0) { + /* select a role */ + for (n = 0; roles[n].name.m; n++) + continue; + choices = (const char **) alloc(sizeof(char *) * (n + 1)); + pickmap = (int *) alloc(sizeof(int) * (n + 1)); + for (;;) { + for (n = 0, i = 0; roles[i].name.m; i++) { + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + if (flags.initgend >= 0 && flags.female + && roles[i].name.f) + choices[n] = roles[i].name.f; + else + choices[n] = roles[i].name.m; + pickmap[n++] = i; + } + } + if (n > 0) + break; + else if (flags.initalign >= 0) + flags.initalign = -1; /* reset */ + else if (flags.initgend >= 0) + flags.initgend = -1; + else if (flags.initrace >= 0) + flags.initrace = -1; + else + panic("no available ROLE+race+gender+alignment combinations"); + } + choices[n] = (const char *) 0; + if (n > 1) + sel = ghack_player_sel_dialog( + choices, _("Player selection"), + _("Choose one of the following roles:")); + else + sel = 0; + if (sel >= 0) + sel = pickmap[sel]; + else if (sel == ROLE_NONE) { /* Quit */ + clearlocks(); + gtk_exit(0); + } + free(choices); + free(pickmap); + } else if (flags.initrole < 0) + sel = ROLE_RANDOM; + else + sel = flags.initrole; - /* select a role */ - for (n = 0; roles[n].name.m; n++) continue; - choices = (const char **)alloc(sizeof(char *) * (n+1)); - pickmap = (int*)alloc(sizeof(int) * (n+1)); - for (;;) { - for (n = 0, i = 0; roles[i].name.m; i++) { - if (ok_role(i, flags.initrace, - flags.initgend, flags.initalign)) { - if (flags.initgend >= 0 && flags.female && roles[i].name.f) - choices[n] = roles[i].name.f; - else - choices[n] = roles[i].name.m; - pickmap[n++] = i; - } - } - if (n > 0) break; - else if (flags.initalign >= 0) flags.initalign = -1; /* reset */ - else if (flags.initgend >= 0) flags.initgend = -1; - else if (flags.initrace >= 0) flags.initrace = -1; - else panic("no available ROLE+race+gender+alignment combinations"); - } - choices[n] = (const char *) 0; - if (n > 1) - sel = ghack_player_sel_dialog(choices, - _("Player selection"), _("Choose one of the following roles:")); - else sel = 0; - if (sel >= 0) sel = pickmap[sel]; - else if (sel == ROLE_NONE) { /* Quit */ - clearlocks(); - gtk_exit(0); - } - free(choices); - free(pickmap); - } else if (flags.initrole < 0) sel = ROLE_RANDOM; - else sel = flags.initrole; - - if (sel == ROLE_RANDOM) { /* Random role */ - sel = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (sel < 0) sel = randrole(); + if (sel == ROLE_RANDOM) { /* Random role */ + sel = pick_role(flags.initrace, flags.initgend, flags.initalign, + PICK_RANDOM); + if (sel < 0) + sel = randrole(); } flags.initrole = sel; @@ -196,310 +174,325 @@ gnome_player_selection() /* force compatibility with role, try for compatibility with * pre-selected gender/alignment */ if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - if (flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) flags.initrace = randrace(flags.initrole); - } else { - /* Count the number of valid races */ - n = 0; /* number valid */ - for (i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, flags.initalign)) - n++; - } - if (n == 0) { - for (i = 0; races[i].noun; i++) { - if (validrace(flags.initrole, i)) n++; - } - } + if (flags.initrace == ROLE_RANDOM || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) + flags.initrace = randrace(flags.initrole); + } else { + /* Count the number of valid races */ + n = 0; /* number valid */ + for (i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) + n++; + } + if (n == 0) { + for (i = 0; races[i].noun; i++) { + if (validrace(flags.initrole, i)) + n++; + } + } - choices = (const char **)alloc(sizeof(char *) * (n+1)); - pickmap = (int*)alloc(sizeof(int) * (n + 1)); - for (n = 0, i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - choices[n] = races[i].noun; - pickmap[n++] = i; - } - } - choices[n] = (const char *) 0; - /* Permit the user to pick, if there is more than one */ - if (n > 1) - sel = ghack_player_sel_dialog(choices, _("Race selection"), - _("Choose one of the following races:")); - else sel = 0; - if (sel >= 0) sel = pickmap[sel]; - else if (sel == ROLE_NONE) { /* Quit */ - clearlocks(); - gtk_exit(0); - } - flags.initrace = sel; - free(choices); - free(pickmap); - } - if (flags.initrace == ROLE_RANDOM) { /* Random role */ - sel = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (sel < 0) sel = randrace(flags.initrole); - flags.initrace = sel; - } + choices = (const char **) alloc(sizeof(char *) * (n + 1)); + pickmap = (int *) alloc(sizeof(int) * (n + 1)); + for (n = 0, i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + choices[n] = races[i].noun; + pickmap[n++] = i; + } + } + choices[n] = (const char *) 0; + /* Permit the user to pick, if there is more than one */ + if (n > 1) + sel = ghack_player_sel_dialog( + choices, _("Race selection"), + _("Choose one of the following races:")); + else + sel = 0; + if (sel >= 0) + sel = pickmap[sel]; + else if (sel == ROLE_NONE) { /* Quit */ + clearlocks(); + gtk_exit(0); + } + flags.initrace = sel; + free(choices); + free(pickmap); + } + if (flags.initrace == ROLE_RANDOM) { /* Random role */ + sel = pick_race(flags.initrole, flags.initgend, flags.initalign, + PICK_RANDOM); + if (sel < 0) + sel = randrace(flags.initrole); + flags.initrace = sel; + } } /* Select a gender, if necessary */ /* force compatibility with role/race, try for compatibility with * pre-selected alignment */ - if (flags.initgend < 0 || - !validgend(flags.initrole, flags.initrace, flags.initgend)) { - if (flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) - flags.initgend = randgend(flags.initrole, flags.initrace); - } else { - /* Count the number of valid genders */ - n = 0; /* number valid */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, flags.initalign)) - n++; - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) { - if (validgend(flags.initrole, flags.initrace, i)) n++; - } - } + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + if (flags.initgend == ROLE_RANDOM || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) + flags.initgend = randgend(flags.initrole, flags.initrace); + } else { + /* Count the number of valid genders */ + n = 0; /* number valid */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) + n++; + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) { + if (validgend(flags.initrole, flags.initrace, i)) + n++; + } + } - choices = (const char **)alloc(sizeof(char *) * (n+1)); - pickmap = (int*)alloc(sizeof(int) * (n + 1)); - for (n = 0, i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - choices[n] = genders[i].adj; - pickmap[n++] = i; - } - } - choices[n] = (const char *) 0; - /* Permit the user to pick, if there is more than one */ - if (n > 1) - sel = ghack_player_sel_dialog(choices, _("Gender selection"), - _("Choose one of the following genders:")); - else sel = 0; - if (sel >= 0) sel = pickmap[sel]; - else if (sel == ROLE_NONE) { /* Quit */ - clearlocks(); - gtk_exit(0); - } - flags.initgend = sel; - free(choices); - free(pickmap); - } - if (flags.initgend == ROLE_RANDOM) { /* Random gender */ - sel = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (sel < 0) sel = randgend(flags.initrole, flags.initrace); - flags.initgend = sel; - } + choices = (const char **) alloc(sizeof(char *) * (n + 1)); + pickmap = (int *) alloc(sizeof(int) * (n + 1)); + for (n = 0, i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + choices[n] = genders[i].adj; + pickmap[n++] = i; + } + } + choices[n] = (const char *) 0; + /* Permit the user to pick, if there is more than one */ + if (n > 1) + sel = ghack_player_sel_dialog( + choices, _("Gender selection"), + _("Choose one of the following genders:")); + else + sel = 0; + if (sel >= 0) + sel = pickmap[sel]; + else if (sel == ROLE_NONE) { /* Quit */ + clearlocks(); + gtk_exit(0); + } + flags.initgend = sel; + free(choices); + free(pickmap); + } + if (flags.initgend == ROLE_RANDOM) { /* Random gender */ + sel = pick_gend(flags.initrole, flags.initrace, flags.initalign, + PICK_RANDOM); + if (sel < 0) + sel = randgend(flags.initrole, flags.initrace); + flags.initgend = sel; + } } /* Select an alignment, if necessary */ /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || - !validalign(flags.initrole, flags.initrace, flags.initalign)) { - if (flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) - flags.initalign = randalign(flags.initrole, flags.initrace); - } else { - /* Count the number of valid alignments */ - n = 0; /* number valid */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, flags.initrace, flags.initgend, i)) - n++; - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) - if (validalign(flags.initrole, flags.initrace, i)) n++; - } + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + if (flags.initalign == ROLE_RANDOM || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) + flags.initalign = randalign(flags.initrole, flags.initrace); + } else { + /* Count the number of valid alignments */ + n = 0; /* number valid */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) + n++; + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) + if (validalign(flags.initrole, flags.initrace, i)) + n++; + } - choices = (const char **)alloc(sizeof(char *) * (n+1)); - pickmap = (int*)alloc(sizeof(int) * (n + 1)); - for (n = 0, i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, - flags.initrace, flags.initgend, i)) { - choices[n] = aligns[i].adj; - pickmap[n++] = i; - } - } - choices[n] = (const char *) 0; - /* Permit the user to pick, if there is more than one */ - if (n > 1) - sel = ghack_player_sel_dialog(choices, _("Alignment selection"), - _("Choose one of the following alignments:")); - else sel = 0; - if (sel >= 0) sel = pickmap[sel]; - else if (sel == ROLE_NONE) { /* Quit */ - clearlocks(); - gtk_exit(0); - } - flags.initalign = sel; - free(choices); - free(pickmap); - } - if (flags.initalign == ROLE_RANDOM) { - sel = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (sel < 0) sel = randalign(flags.initrole, flags.initrace); - flags.initalign = sel; - } + choices = (const char **) alloc(sizeof(char *) * (n + 1)); + pickmap = (int *) alloc(sizeof(int) * (n + 1)); + for (n = 0, i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) { + choices[n] = aligns[i].adj; + pickmap[n++] = i; + } + } + choices[n] = (const char *) 0; + /* Permit the user to pick, if there is more than one */ + if (n > 1) + sel = ghack_player_sel_dialog( + choices, _("Alignment selection"), + _("Choose one of the following alignments:")); + else + sel = 0; + if (sel >= 0) + sel = pickmap[sel]; + else if (sel == ROLE_NONE) { /* Quit */ + clearlocks(); + gtk_exit(0); + } + flags.initalign = sel; + free(choices); + free(pickmap); + } + if (flags.initalign == ROLE_RANDOM) { + sel = pick_align(flags.initrole, flags.initrace, flags.initgend, + PICK_RANDOM); + if (sel < 0) + sel = randalign(flags.initrole, flags.initrace); + flags.initalign = sel; + } } } - /* Ask the user for a player name. */ -void gnome_askname() +void +gnome_askname() { int ret; g_message("Asking name...."); /* Ask for a name and stuff the response into plname, a nethack global */ - ret = ghack_ask_string_dialog("What is your name?", "gandalf", - "GnomeHack", plname); + ret = ghack_ask_string_dialog("What is your name?", "gandalf", + "GnomeHack", plname); /* Quit if they want to quit... */ - if (ret==-1) { - clearlocks(); - gtk_exit(0); + if (ret == -1) { + clearlocks(); + gtk_exit(0); } } - /* Does window event processing (e.g. exposure events). A noop for the tty and X window-ports. */ -void gnome_get_nh_event() +void +gnome_get_nh_event() { - /* We handle our own events. */ - return; + /* We handle our own events. */ + return; } /* Exits the window system. This should dismiss all windows, except the "window" used for raw_print(). str is printed if possible. */ -void gnome_exit_nhwindows(const char *str) +void +gnome_exit_nhwindows(const char *str) { - /* gtk cannot do this without exiting the program, do nothing */ + /* gtk cannot do this without exiting the program, do nothing */ } /* Prepare the window to be suspended. */ -void gnome_suspend_nhwindows(const char *str) +void +gnome_suspend_nhwindows(const char *str) { - /* I don't think we need to do anything here... */ - return; + /* I don't think we need to do anything here... */ + return; } - /* Restore the windows after being suspended. */ -void gnome_resume_nhwindows() +void +gnome_resume_nhwindows() { - /* Do Nothing. Un-necessary since the GUI will refresh itself. */ - return; + /* Do Nothing. Un-necessary since the GUI will refresh itself. */ + return; } -/* Create a window of type "type" which can be +/* Create a window of type "type" which can be NHW_MESSAGE (top line) NHW_STATUS (bottom lines) NHW_MAP (main dungeon) NHW_MENU (inventory or other "corner" windows) NHW_TEXT (help/text, full screen paged window) */ -winid +winid gnome_create_nhwindow(int type) { winid i = 0; /* Return the next available winid */ - for (i=0; i= 0) && - (wid < MAXWINDOWS) && - (gnome_windowlist[wid].win != NULL)) - { - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_PUTSTR], - (guint) attr, - text); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (gnome_windowlist[wid].win != NULL)) { + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_PUTSTR], (guint) attr, text); } } /* Display the file named str. Complain about missing files iff complain is TRUE. */ -void gnome_display_file(const char *filename,BOOLEAN_P must_exist) +void +gnome_display_file(const char *filename, BOOLEAN_P must_exist) { - /* Strange -- for some reason it makes us create a new text window - * instead of reusing any existing ones -- perhaps we can work out - * some way to reuse stuff -- but for now just make and destroy new - * ones each time */ - - dlb *f; - - f = dlb_fopen(filename, "r"); - if (!f) { - if (must_exist) { - GtkWidget *box; + /* Strange -- for some reason it makes us create a new text window + * instead of reusing any existing ones -- perhaps we can work out + * some way to reuse stuff -- but for now just make and destroy new + * ones each time */ + + dlb *f; + + f = dlb_fopen(filename, "r"); + if (!f) { + if (must_exist) { + GtkWidget *box; char message[90]; - sprintf(message, "Warning! Could not find file: %s\n",filename); + sprintf(message, "Warning! Could not find file: %s\n", filename); - box = gnome_message_box_new (_(message), - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, - NULL); - gnome_dialog_set_default( GNOME_DIALOG(box), 0); - gnome_dialog_set_parent (GNOME_DIALOG (box), - GTK_WINDOW (ghack_get_main_window ()) ); - gtk_window_set_modal( GTK_WINDOW(box), TRUE); - gtk_widget_show (box); - } + box = gnome_message_box_new(_(message), GNOME_MESSAGE_BOX_ERROR, + GNOME_STOCK_BUTTON_OK, NULL); + gnome_dialog_set_default(GNOME_DIALOG(box), 0); + gnome_dialog_set_parent(GNOME_DIALOG(box), + GTK_WINDOW(ghack_get_main_window())); + gtk_window_set_modal(GTK_WINDOW(box), TRUE); + gtk_widget_show(box); } - else { - GtkWidget *txtwin, *gless, *frametxt; + } else { + GtkWidget *txtwin, *gless, *frametxt; #define LLEN 128 - char line[LLEN], *textlines; - int num_lines, charcount; + char line[LLEN], *textlines; + int num_lines, charcount; - txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, - NULL); - gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400); - gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE); - gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window"); - gnome_dialog_set_default( GNOME_DIALOG(txtwin), 0); - gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE); - frametxt = gtk_frame_new (""); - gtk_widget_show (frametxt); + txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL); + gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400); + gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE); + gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window"); + gnome_dialog_set_default(GNOME_DIALOG(txtwin), 0); + gtk_window_set_modal(GTK_WINDOW(txtwin), TRUE); + frametxt = gtk_frame_new(""); + gtk_widget_show(frametxt); - /* - * Count the number of lines and characters in the file. - */ - num_lines = 0; - charcount = 1; - while (dlb_fgets(line, LLEN, f)) { - num_lines++; - charcount += strlen(line); - } - (void) dlb_fclose(f); - - /* Ignore empty files */ - if (num_lines == 0) return; - - /* - * Re-open the file and read the data into a buffer. - */ - textlines = (char *) alloc((unsigned int) charcount); - textlines[0] = '\0'; - f = dlb_fopen( filename, RDTMODE); - - while (dlb_fgets(line, LLEN, f)) { - (void) strcat(textlines, line); - } - (void) dlb_fclose(f); - - gless = gnome_less_new (); - gnome_less_show_string (GNOME_LESS (gless), textlines); - gtk_container_add (GTK_CONTAINER (frametxt), gless); - gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (txtwin)->vbox), frametxt, - TRUE, TRUE, 0); - gtk_widget_show_all( txtwin); - gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (txtwin), - GTK_WINDOW (ghack_get_main_window ()) ); - gnome_dialog_run_and_close (GNOME_DIALOG (txtwin)); - free(textlines); + /* + * Count the number of lines and characters in the file. + */ + num_lines = 0; + charcount = 1; + while (dlb_fgets(line, LLEN, f)) { + num_lines++; + charcount += strlen(line); } + (void) dlb_fclose(f); + + /* Ignore empty files */ + if (num_lines == 0) + return; + + /* + * Re-open the file and read the data into a buffer. + */ + textlines = (char *) alloc((unsigned int) charcount); + textlines[0] = '\0'; + f = dlb_fopen(filename, RDTMODE); + + while (dlb_fgets(line, LLEN, f)) { + (void) strcat(textlines, line); + } + (void) dlb_fclose(f); + + gless = gnome_less_new(); + gnome_less_show_string(GNOME_LESS(gless), textlines); + gtk_container_add(GTK_CONTAINER(frametxt), gless); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(txtwin)->vbox), frametxt, + TRUE, TRUE, 0); + gtk_widget_show_all(txtwin); + gtk_window_set_modal(GTK_WINDOW(txtwin), TRUE); + gnome_dialog_set_parent(GNOME_DIALOG(txtwin), + GTK_WINDOW(ghack_get_main_window())); + gnome_dialog_run_and_close(GNOME_DIALOG(txtwin)); + free(textlines); + } } /* Start using window as a menu. You must call start_menu() @@ -685,16 +669,16 @@ void gnome_display_file(const char *filename,BOOLEAN_P must_exist) putstr() to the window. Only windows of type NHW_MENU may be used for menus. */ -void gnome_start_menu(winid wid) +void +gnome_start_menu(winid wid) { - if (wid != -1) - { - if (gnome_windowlist[wid].win == NULL && gnome_windowlist[wid].type != 0) - { - gnome_create_nhwindow_by_id(gnome_windowlist[wid].type, wid); - } - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_START_MENU]); + if (wid != -1) { + if (gnome_windowlist[wid].win == NULL + && gnome_windowlist[wid].type != 0) { + gnome_create_nhwindow_by_id(gnome_windowlist[wid].type, wid); + } + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_START_MENU]); } } @@ -702,7 +686,8 @@ void gnome_start_menu(winid wid) add_menu(windid window, int glyph, const anything identifier, char accelerator, char groupacc, int attr, char *str, boolean preselected) - -- Add a text line str to the given menu window. If identifier + -- Add a text line str to the given menu window. If +identifier is 0, then the line cannot be selected (e.g. a title). Otherwise, identifier is the value returned if the line is selected. Accelerator is a keyboard key that can be used @@ -729,24 +714,23 @@ add_menu(windid window, int glyph, const anything identifier, -- If you want this choice to be preselected when the menu is displayed, set preselected to TRUE. */ -void gnome_add_menu(winid wid, int glyph, const ANY_P * identifier, - CHAR_P accelerator, CHAR_P group_accel, int attr, - const char *str, BOOLEAN_P presel) +void +gnome_add_menu(winid wid, int glyph, const ANY_P *identifier, + CHAR_P accelerator, CHAR_P group_accel, int attr, + const char *str, BOOLEAN_P presel) { - GHackMenuItem item; - item.glyph = glyph; - item.identifier = identifier; - item.accelerator = accelerator; - item.group_accel = group_accel; - item.attr = attr; - item.str = str; - item.presel = presel; + GHackMenuItem item; + item.glyph = glyph; + item.identifier = identifier; + item.accelerator = accelerator; + item.group_accel = group_accel; + item.attr = attr; + item.str = str; + item.presel = presel; - if (wid != -1 && gnome_windowlist[wid].win != NULL) - { - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_ADD_MENU], - &item); + if (wid != -1 && gnome_windowlist[wid].win != NULL) { + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_ADD_MENU], &item); } } @@ -759,14 +743,13 @@ end_menu(window, prompt) ** This probably shouldn't flush the window any more (if ** it ever did). That should be select_menu's job. -dean */ -void gnome_end_menu(winid wid, const char *prompt) +void +gnome_end_menu(winid wid, const char *prompt) { - if (wid != -1 && gnome_windowlist[wid].win != NULL) - { - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_END_MENU], - prompt); - } + if (wid != -1 && gnome_windowlist[wid].win != NULL) { + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_END_MENU], prompt); + } } /* @@ -794,26 +777,27 @@ int select_menu(windid window, int how, menu_item **selected) select_menu() will be called for the window at create_nhwindow() time. */ -int gnome_select_menu(winid wid, int how, MENU_ITEM_P **selected) +int +gnome_select_menu(winid wid, int how, MENU_ITEM_P **selected) { int nReturned = -1; - if (wid != -1 && gnome_windowlist[wid].win != NULL && - gnome_windowlist[wid].type == NHW_MENU) - { - nReturned=ghack_menu_window_select_menu (gnome_windowlist[wid].win, - selected, how); - } + if (wid != -1 && gnome_windowlist[wid].win != NULL + && gnome_windowlist[wid].type == NHW_MENU) { + nReturned = ghack_menu_window_select_menu(gnome_windowlist[wid].win, + selected, how); + } return nReturned; } /* -- Indicate to the window port that the inventory has been changed. - -- Merely calls display_inventory() for window-ports that leave the - window up, otherwise empty. + -- Merely calls display_inventory() for window-ports that leave the + window up, otherwise empty. */ -void gnome_update_inventory() +void +gnome_update_inventory() { ghack_main_window_update_inventory(); } @@ -823,9 +807,10 @@ mark_synch() -- Don't go beyond this point in I/O on any channel until all channels are caught up to here. Can be an empty call for the moment */ -void gnome_mark_synch() +void +gnome_mark_synch() { - /* Do nothing */ + /* Do nothing */ } /* @@ -834,9 +819,10 @@ wait_synch() -- Wait until all pending output is complete (*flush*() for -- May also deal with exposure events etc. so that the display is OK when return from wait_synch(). */ -void gnome_wait_synch() +void +gnome_wait_synch() { - /* Do nothing */ + /* Do nothing */ } /* @@ -844,23 +830,23 @@ cliparound(x, y)-- Make sure that the user is more-or-less centered on the screen if the playing area is larger than the screen. -- This function is only defined if CLIPPING is defined. */ -void gnome_cliparound(int x, int y) +void +gnome_cliparound(int x, int y) { - /* FIXME!!! winid should be a parameter!!! - * Call a function that Does The Right Thing(tm). - */ - gnome_cliparound_proper(WIN_MAP,x,y); + /* FIXME!!! winid should be a parameter!!! + * Call a function that Does The Right Thing(tm). + */ + gnome_cliparound_proper(WIN_MAP, x, y); } -void gnome_cliparound_proper(winid wid, int x, int y) +void +gnome_cliparound_proper(winid wid, int x, int y) { - if (wid != -1 && gnome_windowlist[wid].win != NULL) - { - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_CLIPAROUND], - (guint) x, - (guint) y); - } + if (wid != -1 && gnome_windowlist[wid].win != NULL) { + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_CLIPAROUND], (guint) x, + (guint) y); + } } /* @@ -870,20 +856,17 @@ print_glyph(window, x, y, glyph) port wants (symbol, font, color, attributes, ...there's a 1-1 map between glyphs and distinct things on the map). */ -void gnome_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph) +void +gnome_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph) { - if (wid != -1 && gnome_windowlist[wid].win != NULL) - { - GdkImlibImage *im; + if (wid != -1 && gnome_windowlist[wid].win != NULL) { + GdkImlibImage *im; - im = ghack_image_from_glyph( glyph, FALSE); + im = ghack_image_from_glyph(glyph, FALSE); - gtk_signal_emit (GTK_OBJECT (gnome_windowlist[wid].win), - ghack_signals[GHSIG_PRINT_GLYPH], - (guint) x, - (guint) y, - im, - NULL); + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[wid].win), + ghack_signals[GHSIG_PRINT_GLYPH], (guint) x, + (guint) y, im, NULL); } } @@ -896,7 +879,8 @@ raw_print(str) -- Print directly to a screen, or otherwise guarantee that for error messages, and maybe other "msg" uses. E.g. updating status for micros (i.e, "saving"). */ -void gnome_raw_print(const char *str) +void +gnome_raw_print(const char *str) { tty_raw_print(str); } @@ -906,7 +890,8 @@ raw_print_bold(str) -- Like raw_print(), but prints in bold/standout (if possible). */ -void gnome_raw_print_bold(const char *str) +void +gnome_raw_print_bold(const char *str) { tty_raw_print_bold(str); } @@ -917,27 +902,29 @@ int nhgetch() -- Returns a single character input from the user. will be the routine the OS provides to read a character. Returned character _must_ be non-zero. */ -int gnome_nhgetch() +int +gnome_nhgetch() { int key; GList *theFirst; - gtk_signal_emit (GTK_OBJECT (gnome_windowlist[WIN_STATUS].win), - ghack_signals[GHSIG_FADE_HIGHLIGHT]); + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[WIN_STATUS].win), + ghack_signals[GHSIG_FADE_HIGHLIGHT]); g_askingQuestion = 1; /* Process events until a key press event arrives. */ - while ( g_numKeys == 0 ) { - if (program_state.done_hup) return '\033'; - gtk_main_iteration(); + while (g_numKeys == 0) { + if (program_state.done_hup) + return '\033'; + gtk_main_iteration(); } - - theFirst = g_list_first( g_keyBuffer); + + theFirst = g_list_first(g_keyBuffer); g_keyBuffer = g_list_remove_link(g_keyBuffer, theFirst); - key = GPOINTER_TO_INT( theFirst->data); - g_list_free_1( theFirst); + key = GPOINTER_TO_INT(theFirst->data); + g_list_free_1(theFirst); g_numKeys--; g_askingQuestion = 0; - return ( key); + return (key); } /* @@ -948,58 +935,61 @@ int nh_poskey(int *x, int *y, int *mod) a position in the MAP window is returned in x, y and mod. mod may be one of - CLICK_1 -- mouse click type 1 - CLICK_2 -- mouse click type 2 + CLICK_1 -- mouse click type 1 + CLICK_2 -- mouse click type 2 The different click types can map to whatever the hardware supports. If no mouse is supported, this routine always returns a non-zero character. */ -int gnome_nh_poskey(int *x, int *y, int *mod) +int +gnome_nh_poskey(int *x, int *y, int *mod) { - gtk_signal_emit (GTK_OBJECT (gnome_windowlist[WIN_STATUS].win), - ghack_signals[GHSIG_FADE_HIGHLIGHT]); - + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[WIN_STATUS].win), + ghack_signals[GHSIG_FADE_HIGHLIGHT]); + g_askingQuestion = 0; /* Process events until a key or map-click arrives. */ - while ( g_numKeys == 0 && g_numClicks == 0 ) { - if (program_state.done_hup) return '\033'; - gtk_main_iteration(); + while (g_numKeys == 0 && g_numClicks == 0) { + if (program_state.done_hup) + return '\033'; + gtk_main_iteration(); } - + if (g_numKeys > 0) { - int key; - GList *theFirst; - - theFirst = g_list_first( g_keyBuffer); - g_keyBuffer = g_list_remove_link(g_keyBuffer, theFirst); - key = GPOINTER_TO_INT( theFirst->data); - g_list_free_1( theFirst); - g_numKeys--; - return ( key); - } - else { - GHClick *click; - GList *theFirst; - - theFirst = g_list_first( g_clickBuffer); - g_clickBuffer = g_list_remove_link(g_clickBuffer, theFirst); - click = (GHClick*) theFirst->data; - *x=click->x; - *y=click->y; - *mod=click->mod; - g_free( click); - g_list_free_1( theFirst); - g_numClicks--; - return ( 0); + int key; + GList *theFirst; + + theFirst = g_list_first(g_keyBuffer); + g_keyBuffer = g_list_remove_link(g_keyBuffer, theFirst); + key = GPOINTER_TO_INT(theFirst->data); + g_list_free_1(theFirst); + g_numKeys--; + return (key); + } else { + GHClick *click; + GList *theFirst; + + theFirst = g_list_first(g_clickBuffer); + g_clickBuffer = g_list_remove_link(g_clickBuffer, theFirst); + click = (GHClick *) theFirst->data; + *x = click->x; + *y = click->y; + *mod = click->mod; + g_free(click); + g_list_free_1(theFirst); + g_numClicks--; + return (0); } } /* nhbell() -- Beep at user. [This will exist at least until sounds are - redone, since sounds aren't attributable to windows anyway.] + redone, since sounds aren't attributable to windows +anyway.] */ -void gnome_nhbell() +void +gnome_nhbell() { /* FIXME!!! Play a cool GNOME sound instead */ gdk_beep(); @@ -1010,7 +1000,8 @@ doprev_message() -- Display previous messages. Used by the ^P command. -- On the tty-port this scrolls WIN_MESSAGE back one line. */ -int gnome_doprev_message() +int +gnome_doprev_message() { /* Do Nothing. They can read old messages using the scrollbar. */ return 0; @@ -1035,153 +1026,158 @@ char yn_function(const char *ques, const char *choices, char default) -- This uses the top line in the tty window-port, other ports might use a popup. */ -char gnome_yn_function(const char *question, const char *choices, - CHAR_P def) +char +gnome_yn_function(const char *question, const char *choices, CHAR_P def) { int ch; - int result=-1; + int result = -1; char message[BUFSZ]; - char yn_esc_map='\033'; + char yn_esc_map = '\033'; GtkWidget *mainWnd = ghack_get_main_window(); - - + if (choices) { - char *cb, choicebuf[QBUFSZ]; - Strcpy(choicebuf, choices); - if ((cb = index(choicebuf, '\033')) != 0) { - /* anything beyond is hidden */ - *cb = '\0'; - } - (void)strncpy(message, question, QBUFSZ-1); - message[QBUFSZ-1] = '\0'; - sprintf(eos(message), " [%s]", choicebuf); - if (def) sprintf(eos(message), " (%c)", def); - Strcat(message, " "); - /* escape maps to 'q' or 'n' or default, in that order */ - yn_esc_map = (index(choices, 'q') ? 'q' : - (index(choices, 'n') ? 'n' : def)); + char *cb, choicebuf[QBUFSZ]; + Strcpy(choicebuf, choices); + if ((cb = index(choicebuf, '\033')) != 0) { + /* anything beyond is hidden */ + *cb = '\0'; + } + (void) strncpy(message, question, QBUFSZ - 1); + message[QBUFSZ - 1] = '\0'; + sprintf(eos(message), " [%s]", choicebuf); + if (def) + sprintf(eos(message), " (%c)", def); + Strcat(message, " "); + /* escape maps to 'q' or 'n' or default, in that order */ + yn_esc_map = + (index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def)); } else { - Strcpy(message, question); + Strcpy(message, question); } - - + gnome_putstr(WIN_MESSAGE, ATR_BOLD, message); - if (mainWnd != NULL && choices && !index(choices,ch)) { - return(ghack_yes_no_dialog( question, choices, def)); + if (mainWnd != NULL && choices && !index(choices, ch)) { + return (ghack_yes_no_dialog(question, choices, def)); } /* Only here if main window is not present */ - while (result<0) { - ch=gnome_nhgetch(); - if (ch=='\033') { - result=yn_esc_map; - } else if (choices && !index(choices,ch)) { - /* FYI: ch==-115 is for KP_ENTER */ - if (def && (ch==' ' || ch=='\r' || ch=='\n' || ch==-115)) { - result=def; - } else { - gnome_nhbell(); - /* and try again... */ - } - } else { - result=ch; - } + while (result < 0) { + ch = gnome_nhgetch(); + if (ch == '\033') { + result = yn_esc_map; + } else if (choices && !index(choices, ch)) { + /* FYI: ch==-115 is for KP_ENTER */ + if (def + && (ch == ' ' || ch == '\r' || ch == '\n' || ch == -115)) { + result = def; + } else { + gnome_nhbell(); + /* and try again... */ + } + } else { + result = ch; + } } return result; } /* getlin(const char *ques, char *input) - -- Prints ques as a prompt and reads a single line of text, - up to a newline. The string entered is returned without the - newline. ESC is used to cancel, in which case the string - "\033\000" is returned. - -- getlin() must call flush_screen(1) before doing anything. - -- This uses the top line in the tty window-port, other - ports might use a popup. + -- Prints ques as a prompt and reads a single line of text, + up to a newline. The string entered is returned without the + newline. ESC is used to cancel, in which case the string + "\033\000" is returned. + -- getlin() must call flush_screen(1) before doing anything. + -- This uses the top line in the tty window-port, other + ports might use a popup. */ -void gnome_getlin(const char *question, char *input) +void +gnome_getlin(const char *question, char *input) { int ret; ret = ghack_ask_string_dialog(question, "", "nethack", input); if (ret == -1) - input[0] = 0; + input[0] = 0; } /* int get_ext_cmd(void) - -- Get an extended command in a window-port specific way. - An index into extcmdlist[] is returned on a successful - selection, -1 otherwise. + -- Get an extended command in a window-port specific way. + An index into extcmdlist[] is returned on a successful + selection, -1 otherwise. */ -int gnome_get_ext_cmd() +int +gnome_get_ext_cmd() { return ghack_menu_ext_cmd(); } - /* number_pad(state) - -- Initialize the number pad to the given state. + -- Initialize the number pad to the given state. */ -void gnome_number_pad(int state) +void +gnome_number_pad(int state) { /* Do Nothing */ } /* delay_output() -- Causes a visible delay of 50ms in the output. - Conceptually, this is similar to wait_synch() followed - by a nap(50ms), but allows asynchronous operation. + Conceptually, this is similar to wait_synch() followed + by a nap(50ms), but allows asynchronous operation. */ -void gnome_delay_output() +void +gnome_delay_output() { if (gnome_windowlist[WIN_MESSAGE].win != NULL) { - gtk_signal_emit( GTK_OBJECT (gnome_windowlist[WIN_MESSAGE].win), - ghack_signals[GHSIG_DELAY], - (guint) 50); + gtk_signal_emit(GTK_OBJECT(gnome_windowlist[WIN_MESSAGE].win), + ghack_signals[GHSIG_DELAY], (guint) 50); } } /* start_screen() -- Only used on Unix tty ports, but must be declared for - completeness. Sets up the tty to work in full-screen - graphics mode. Look at win/tty/termcap.c for an - example. If your window-port does not need this function - just declare an empty function. + completeness. Sets up the tty to work in full-screen + graphics mode. Look at win/tty/termcap.c for an + example. If your window-port does not need this function + just declare an empty function. */ -void gnome_start_screen() +void +gnome_start_screen() { /* Do Nothing */ } /* end_screen() -- Only used on Unix tty ports, but must be declared for - completeness. The complement of start_screen(). + completeness. The complement of start_screen(). */ -void gnome_end_screen() +void +gnome_end_screen() { /* Do Nothing */ } /* outrip(winid, int, when) - -- The tombstone code. If you want the traditional code use - genl_outrip for the value and check the #if in rip.c. + -- The tombstone code. If you want the traditional code use + genl_outrip for the value and check the #if in rip.c. */ -void gnome_outrip(winid wid, int how, time_t when) +void +gnome_outrip(winid wid, int how, time_t when) { /* Follows roughly the same algorithm as genl_outrip() */ char buf[BUFSZ]; - char ripString[BUFSZ]="\0"; + char ripString[BUFSZ] = "\0"; long year; - + /* Put name on stone */ Sprintf(buf, "%s\n", plname); Strcat(ripString, buf); - + /* Put $ on stone */ Sprintf(buf, "%ld Au\n", done_money); Strcat(ripString, buf); @@ -1198,5 +1194,5 @@ void gnome_outrip(winid wid, int how, time_t when) Sprintf(buf, "%4ld\n", year); Strcat(ripString, buf); - ghack_text_window_rip_string( ripString); + ghack_text_window_rip_string(ripString); } diff --git a/win/gnome/gnglyph.c b/win/gnome/gnglyph.c index 440d85c01..9a0d07872 100644 --- a/win/gnome/gnglyph.c +++ b/win/gnome/gnglyph.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnglyph.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnglyph.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 gnglyph.c $Date: 2009/05/06 10:57:29 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)gnglyph.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -10,8 +10,8 @@ /* from tile.c */ extern int total_tiles_used; -static GHackGlyphs ghack_glyphs; -static GdkImlibImage** ghack_tiles = NULL; +static GHackGlyphs ghack_glyphs; +static GdkImlibImage **ghack_tiles = NULL; /* NAME: * ghack_init_glyphs(char* xpm_file) @@ -53,47 +53,46 @@ int ghack_init_glyphs(const char *xpmFile) { ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile); - if ( ! ghack_glyphs.im ) { - g_error("Couldn't load required xpmFile!"); - return -1; + if (!ghack_glyphs.im) { + g_error("Couldn't load required xpmFile!"); + return -1; } gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width, - ghack_glyphs.im->rgb_height); + ghack_glyphs.im->rgb_height); - if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0 || - ghack_glyphs.im->rgb_width <= TILES_PER_ROW) { - g_error("%s is not a multiple of %d (number of tiles/row) pixels wide", - xpmFile, TILES_PER_ROW); - return -1; + if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0 + || ghack_glyphs.im->rgb_width <= TILES_PER_ROW) { + g_error( + "%s is not a multiple of %d (number of tiles/row) pixels wide", + xpmFile, TILES_PER_ROW); + return -1; } ghack_glyphs.count = total_tiles_used; if ((ghack_glyphs.count % TILES_PER_ROW) != 0) { - ghack_glyphs.count += - TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW); + ghack_glyphs.count += + TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW); } ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW; ghack_glyphs.height = - ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW); - + ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW); /* Assume the tiles are organized in rows of TILES_PER_ROW */ - ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count ); + ghack_tiles = g_new0(GdkImlibImage *, ghack_glyphs.count); return (ghack_tiles == NULL) ? -1 : 0; } void -ghack_free_glyphs( ) +ghack_free_glyphs() { int i; - for ( i=0 ; i= ghack_glyphs.count || tile < 0 ) - { - g_warning("Aiiee! I've was asked for a tile outside the allowed range!\n" - "Email this to other-gnomehack@lists.debian.org"); - g_warning("Max tile: %d Tile asked for: %d", - ghack_glyphs.count, tile); - return NULL; + if (tile >= ghack_glyphs.count || tile < 0) { + g_warning( + "Aiiee! I've was asked for a tile outside the allowed range!\n" + "Email this to other-gnomehack@lists.debian.org"); + g_warning("Max tile: %d Tile asked for: %d", ghack_glyphs.count, + tile); + return NULL; } - if (ghack_glyphs.im == NULL) - { - g_warning("Aiiee! I've been asked to clone from a null image.\n" - "Email this to other-gnomehack@lists.debian.org"); - g_warning( "making image from tile %d, force=%s\n", tile, - (force==TRUE)? "TRUE": "FALSE"); + if (ghack_glyphs.im == NULL) { + g_warning("Aiiee! I've been asked to clone from a null image.\n" + "Email this to other-gnomehack@lists.debian.org"); + g_warning("making image from tile %d, force=%s\n", tile, + (force == TRUE) ? "TRUE" : "FALSE"); } - if (force == TRUE) - { - g_warning("Aiiee! I've been asked to force rendering.\n" - "Email this to other-gnomehack@lists.debian.org"); - g_warning( "making image from tile %d, force=%s\n", tile, - (force==TRUE)? "TRUE" : "FALSE"); + if (force == TRUE) { + g_warning("Aiiee! I've been asked to force rendering.\n" + "Email this to other-gnomehack@lists.debian.org"); + g_warning("making image from tile %d, force=%s\n", tile, + (force == TRUE) ? "TRUE" : "FALSE"); } - if (!ghack_tiles[tile] || force) { - int src_x, src_y; + if (!ghack_tiles[tile] || force) { + int src_x, src_y; #if 0 fprintf( stderr, "crop_and_clone: glyph=%d, tile=%d, ptr=%p, x=%d, y=%d, w=%d, h=%d\n", glyph, tile, (void*)&(ghack_tiles[tile]), 0, @@ -207,26 +201,23 @@ ghack_image_from_glyph( int glyph, gboolean force ) ghack_glyphs.height, ghack_glyphs.width); #endif - if (ghack_glyphs.im->pixmap == NULL) - g_warning( "Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n"); - src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width; - src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height; - ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im, - src_x, src_y, - ghack_glyphs.width, - ghack_glyphs.height); - } + if (ghack_glyphs.im->pixmap == NULL) + g_warning("Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n"); + src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width; + src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height; + ghack_tiles[tile] = gdk_imlib_crop_and_clone_image( + ghack_glyphs.im, src_x, src_y, ghack_glyphs.width, + ghack_glyphs.height); + } - if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force)) - { - if ( gdk_imlib_render(ghack_tiles[tile], - ghack_tiles[tile]->rgb_width, - ghack_tiles[tile]->rgb_height) == 0) { - g_error("GLYPH: couldn't create tile # %d", tile); - } - if ( !ghack_tiles[tile]->pixmap ) - g_error("Strange, tile # %d didn't get rendered???", tile); - } + if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force)) { + if (gdk_imlib_render(ghack_tiles[tile], ghack_tiles[tile]->rgb_width, + ghack_tiles[tile]->rgb_height) == 0) { + g_error("GLYPH: couldn't create tile # %d", tile); + } + if (!ghack_tiles[tile]->pixmap) + g_error("Strange, tile # %d didn't get rendered???", tile); + } - return ghack_tiles[tile]; + return ghack_tiles[tile]; } diff --git a/win/gnome/gnmain.c b/win/gnome/gnmain.c index 0e67f3129..6129db6fa 100644 --- a/win/gnome/gnmain.c +++ b/win/gnome/gnmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnmain.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 gnmain.c $Date: 2009/05/06 10:57:32 $ $Revision: 1.9 $ */ /* SCCS Id: @(#)gnmain.c 3.5 2008/01/30 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -17,125 +17,126 @@ #include "hack.h" #include "date.h" -static GtkWidget* mainWindow=NULL; -static GtkWidget *about=NULL; -static GtkWidget* hBoxFirstRow; -static GtkWidget* vBoxMain; +static GtkWidget *mainWindow = NULL; +static GtkWidget *about = NULL; +static GtkWidget *hBoxFirstRow; +static GtkWidget *vBoxMain; int restarted = 0; int os_x = 0, os_y = 0, os_w = 0, os_h = 0; - static GnomeClient *session_id; -static -void ghack_quit_game(GtkWidget *widget, int button) +static void +ghack_quit_game(GtkWidget *widget, int button) { gtk_widget_hide(widget); if (button == 0) { - gnome_exit_nhwindows(0); - gtk_object_unref(GTK_OBJECT(session_id)); - clearlocks(); - gtk_exit(0); + gnome_exit_nhwindows(0); + gtk_object_unref(GTK_OBJECT(session_id)); + clearlocks(); + gtk_exit(0); } } -static -void ghack_quit_game_cb(GtkWidget *widget, gpointer data) +static void +ghack_quit_game_cb(GtkWidget *widget, gpointer data) { GtkWidget *box; - box = gnome_message_box_new(_("Do you really want to quit?"), - GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, NULL); - gnome_dialog_set_default( GNOME_DIALOG(box), 1); - gnome_dialog_set_parent (GNOME_DIALOG (box), - GTK_WINDOW (ghack_get_main_window ()) ); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0); + box = gnome_message_box_new( + _("Do you really want to quit?"), GNOME_MESSAGE_BOX_QUESTION, + GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, NULL); + gnome_dialog_set_default(GNOME_DIALOG(box), 1); + gnome_dialog_set_parent(GNOME_DIALOG(box), + GTK_WINDOW(ghack_get_main_window())); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 1, 'n', 0); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'y', 0); - gtk_window_set_modal( GTK_WINDOW(box), TRUE); - gtk_signal_connect( GTK_OBJECT(box), "clicked", - (GtkSignalFunc)ghack_quit_game, NULL); - gtk_widget_show(box); -} - -static -void ghack_save_game(GtkWidget *widget, int button) -{ - gtk_widget_hide(widget); - if (button == 0) { - if(dosave0()) { - /* make sure they see the Saving message */ - display_nhwindow(WIN_MESSAGE, TRUE); - gnome_exit_nhwindows("Be seeing you..."); - clearlocks(); - gtk_exit(0); - } else (void)doredraw(); - } -} - -void ghack_save_game_cb(GtkWidget *widget, gpointer data) -{ - GtkWidget *box; - box = gnome_message_box_new(_("Quit and save the current game?"), - GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, NULL); - gnome_dialog_set_default( GNOME_DIALOG(box), 1); - gnome_dialog_set_parent (GNOME_DIALOG (box), - GTK_WINDOW (ghack_get_main_window ()) ); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0); - - gtk_window_set_modal( GTK_WINDOW(box), TRUE); - gtk_signal_connect( GTK_OBJECT(box), "clicked", - (GtkSignalFunc)ghack_save_game, NULL); - gtk_widget_show(box); -} - -static -void ghack_new_game(GtkWidget *widget, int button) -{ - if (button == 0) { - g_message("This feature is not yet implemented. Sorry."); - } -} - -static -void ghack_new_game_cb(GtkWidget *widget, gpointer data) -{ - GtkWidget *box; - box = gnome_message_box_new(_("Start a new game?"), - GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, NULL); - gnome_dialog_set_default( GNOME_DIALOG(box), 1); - gnome_dialog_set_parent (GNOME_DIALOG (box), - GTK_WINDOW (ghack_get_main_window ()) ); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0); - gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0); - - gtk_window_set_modal( GTK_WINDOW(box), TRUE); - gtk_signal_connect( GTK_OBJECT(box), "clicked", - (GtkSignalFunc)ghack_new_game, NULL); + gtk_window_set_modal(GTK_WINDOW(box), TRUE); + gtk_signal_connect(GTK_OBJECT(box), "clicked", + (GtkSignalFunc) ghack_quit_game, NULL); gtk_widget_show(box); } static void -about_destroy_callback (void) +ghack_save_game(GtkWidget *widget, int button) +{ + gtk_widget_hide(widget); + if (button == 0) { + if (dosave0()) { + /* make sure they see the Saving message */ + display_nhwindow(WIN_MESSAGE, TRUE); + gnome_exit_nhwindows("Be seeing you..."); + clearlocks(); + gtk_exit(0); + } else + (void) doredraw(); + } +} + +void +ghack_save_game_cb(GtkWidget *widget, gpointer data) +{ + GtkWidget *box; + box = gnome_message_box_new( + _("Quit and save the current game?"), GNOME_MESSAGE_BOX_QUESTION, + GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, NULL); + gnome_dialog_set_default(GNOME_DIALOG(box), 1); + gnome_dialog_set_parent(GNOME_DIALOG(box), + GTK_WINDOW(ghack_get_main_window())); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 1, 'n', 0); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'y', 0); + + gtk_window_set_modal(GTK_WINDOW(box), TRUE); + gtk_signal_connect(GTK_OBJECT(box), "clicked", + (GtkSignalFunc) ghack_save_game, NULL); + gtk_widget_show(box); +} + +static void +ghack_new_game(GtkWidget *widget, int button) +{ + if (button == 0) { + g_message("This feature is not yet implemented. Sorry."); + } +} + +static void +ghack_new_game_cb(GtkWidget *widget, gpointer data) +{ + GtkWidget *box; + box = gnome_message_box_new( + _("Start a new game?"), GNOME_MESSAGE_BOX_QUESTION, + GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, NULL); + gnome_dialog_set_default(GNOME_DIALOG(box), 1); + gnome_dialog_set_parent(GNOME_DIALOG(box), + GTK_WINDOW(ghack_get_main_window())); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 1, 'n', 0); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'y', 0); + + gtk_window_set_modal(GTK_WINDOW(box), TRUE); + gtk_signal_connect(GTK_OBJECT(box), "clicked", + (GtkSignalFunc) ghack_new_game, NULL); + gtk_widget_show(box); +} + +static void +about_destroy_callback(void) { about = NULL; } -static void +static void ghack_about_cb(GtkWidget *widget, gpointer data) { - char buf[BUFSZ]="\0"; - char buf1[BUFSZ]="\0"; - const gchar *authors[] = {"Erik Andersen", "Anthony Taylor", - "Jeff Garzik", "The Nethack Dev Team", NULL}; + char buf[BUFSZ] = "\0"; + char buf1[BUFSZ] = "\0"; + const gchar *authors[] = { "Erik Andersen", "Anthony Taylor", + "Jeff Garzik", "The Nethack Dev Team", NULL }; if (about) { - gdk_window_raise (about->window); - return; + gdk_window_raise(about->window); + return; } getversionstring(buf); @@ -157,515 +158,357 @@ ghack_about_cb(GtkWidget *widget, gpointer data) ! strcat(buf, str2); free(str) below #else - strcat( buf1, VERSION_STRING); - strcat( buf, - _("\nSend comments and bug reports to: nethack-bugs@nethack.org\n" - "This game is free software. See License for details.")); + strcat(buf1, VERSION_STRING); + strcat(buf, + _("\nSend comments and bug reports to: nethack-bugs@nethack.org\n" + "This game is free software. See License for details.")); #endif - about = gnome_about_new(_("Nethack"), - buf1, "Copyright (C) 1985-2002 Mike Stephenson", - (const char **)authors, buf, - NULL); + about = gnome_about_new(_("Nethack"), buf1, + "Copyright (C) 1985-2002 Mike Stephenson", + (const char **) authors, buf, NULL); + + gtk_signal_connect(GTK_OBJECT(about), "destroy", + (GtkSignalFunc) about_destroy_callback, NULL); - gtk_signal_connect (GTK_OBJECT (about), "destroy", - (GtkSignalFunc) about_destroy_callback, NULL); - gtk_widget_show(about); } -static void +static void ghack_settings_cb(GtkWidget *widget, gpointer data) { ghack_settings_dialog(); } -static void -ghack_accelerator_selected (GtkWidget *widget, gpointer data) +static void +ghack_accelerator_selected(GtkWidget *widget, gpointer data) { GdkEventKey event; - int key = GPOINTER_TO_INT( data); + int key = GPOINTER_TO_INT(data); /* g_message("An accelerator for \"%c\" was selected", key); */ /* stuff a key directly into the keybuffer */ - event.state=0; - event.keyval=key; + event.state = 0; + event.keyval = key; ghack_handle_key_press(NULL, &event, NULL); } #ifndef M -# ifndef NHSTDC -# define M(c) (0x80 | (c)) -# else -# define M(c) ((c) - 128) -# endif /* NHSTDC */ +#ifndef NHSTDC +#define M(c) (0x80 | (c)) +#else +#define M(c) ((c) -128) +#endif /* NHSTDC */ #endif #ifndef C -#define C(c) (0x1f & (c)) +#define C(c) (0x1f & (c)) #endif - -GnomeUIInfo game_tree[] = -{ - { - GNOME_APP_UI_ITEM, N_ ("_Change Settings..."), - N_("Change Game Settings"), ghack_settings_cb, NULL, NULL, - GNOME_APP_PIXMAP_NONE, NULL, 0,0, NULL - }, +GnomeUIInfo game_tree[] = { + { GNOME_APP_UI_ITEM, N_("_Change Settings..."), + N_("Change Game Settings"), ghack_settings_cb, NULL, NULL, + GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL }, GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Version"), NULL, - ghack_accelerator_selected, GINT_TO_POINTER('v'), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'v',0 - }, - { - GNOME_APP_UI_ITEM, N_("History..."), NULL, - ghack_accelerator_selected, GINT_TO_POINTER('V'), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'V',GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Compilation..."), NULL, - ghack_accelerator_selected, GINT_TO_POINTER(M('v')), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT,'v',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Options..."), NULL, - ghack_accelerator_selected, GINT_TO_POINTER('O'), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_PREF, 'O', GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Explore Mode..."), NULL, - ghack_accelerator_selected, GINT_TO_POINTER('X'), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_QUIT, 'X', GDK_SHIFT_MASK - }, + { GNOME_APP_UI_ITEM, N_("Version"), NULL, ghack_accelerator_selected, + GINT_TO_POINTER('v'), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, 'v', 0 }, + { GNOME_APP_UI_ITEM, N_("History..."), NULL, ghack_accelerator_selected, + GINT_TO_POINTER('V'), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, 'V', GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Compilation..."), NULL, + ghack_accelerator_selected, GINT_TO_POINTER(M('v')), NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'v', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Options..."), NULL, ghack_accelerator_selected, + GINT_TO_POINTER('O'), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_PREF, 'O', GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Explore Mode..."), NULL, + ghack_accelerator_selected, GINT_TO_POINTER('X'), NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_QUIT, 'X', GDK_SHIFT_MASK }, GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_MENU_NEW_GAME_ITEM(ghack_new_game_cb, NULL), GNOMEUIINFO_MENU_SAVE_ITEM(ghack_save_game_cb, NULL), - { - GNOME_APP_UI_ITEM, N_("Exit"), NULL, - ghack_quit_game_cb, GINT_TO_POINTER(M('Q')), NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'Q', GDK_MOD1_MASK - }, + { GNOME_APP_UI_ITEM, N_("Exit"), NULL, ghack_quit_game_cb, + GINT_TO_POINTER(M('Q')), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, 'Q', GDK_MOD1_MASK }, GNOMEUIINFO_END }; - - GnomeUIInfo edit_menu[] = { - { - GNOME_APP_UI_ITEM, N_("Inventory"), - N_("Edit/View your Inventory"), ghack_accelerator_selected, - GINT_TO_POINTER('i'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'i', 0 - }, - { - GNOME_APP_UI_ITEM, N_("Discoveries"), - N_("Edit/View your Discoveries"), - ghack_accelerator_selected, - GINT_TO_POINTER('\\'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '\\',0 - }, - { - GNOME_APP_UI_ITEM, N_("List/reorder your spells"), - N_("List/reorder your spells"), ghack_accelerator_selected, - GINT_TO_POINTER('x'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'x', 0 - }, - { - GNOME_APP_UI_ITEM, N_("Adjust letters"), - N_("Adjust letter for items in your Inventory"), ghack_accelerator_selected, - GINT_TO_POINTER(M('a')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'a', GDK_MOD1_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Name object"), - N_("Assign a name to an object"), ghack_accelerator_selected, - GINT_TO_POINTER(M('n')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'n', GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Name creature"), - N_("Assign a name to a creature"), ghack_accelerator_selected, - GINT_TO_POINTER('C'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'C', GDK_SHIFT_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Qualifications"), - N_("Edit your Qualifications"), ghack_accelerator_selected, - GINT_TO_POINTER(M('e')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'e',GDK_MOD1_MASK - }, - GNOMEUIINFO_END + { GNOME_APP_UI_ITEM, N_("Inventory"), N_("Edit/View your Inventory"), + ghack_accelerator_selected, GINT_TO_POINTER('i'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'i', 0 }, + { GNOME_APP_UI_ITEM, N_("Discoveries"), N_("Edit/View your Discoveries"), + ghack_accelerator_selected, GINT_TO_POINTER('\\'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, '\\', 0 }, + { GNOME_APP_UI_ITEM, N_("List/reorder your spells"), + N_("List/reorder your spells"), ghack_accelerator_selected, + GINT_TO_POINTER('x'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'x', 0 }, + { GNOME_APP_UI_ITEM, N_("Adjust letters"), + N_("Adjust letter for items in your Inventory"), + ghack_accelerator_selected, GINT_TO_POINTER(M('a')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'a', GDK_MOD1_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Name object"), N_("Assign a name to an object"), + ghack_accelerator_selected, GINT_TO_POINTER(M('n')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'n', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Name creature"), + N_("Assign a name to a creature"), ghack_accelerator_selected, + GINT_TO_POINTER('C'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'C', + GDK_SHIFT_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Qualifications"), N_("Edit your Qualifications"), + ghack_accelerator_selected, GINT_TO_POINTER(M('e')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'e', GDK_MOD1_MASK }, + GNOMEUIINFO_END }; - GnomeUIInfo apparel_menu[] = { - { - GNOME_APP_UI_ITEM, N_("Wield Weapon"), - N_("Select a weapon to fight with"), - ghack_accelerator_selected, - GINT_TO_POINTER('w'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'w',0 - }, - { - GNOME_APP_UI_ITEM, N_("Remove Apparel..."), - N_("Remove apparel dialog bog"), ghack_accelerator_selected, - GINT_TO_POINTER('A'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'A',GDK_SHIFT_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Wear Armor"), - N_("Put on armor"), ghack_accelerator_selected, - GINT_TO_POINTER('W'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'W',GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Take off Armor"), - N_("Take off armor you are wearing"), ghack_accelerator_selected, - GINT_TO_POINTER('T'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'T',GDK_SHIFT_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Put on non-armor"), - N_("Put on non-armor apparel"), ghack_accelerator_selected, - GINT_TO_POINTER('P'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'P',GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Remove non-armor"), - N_("Remove non-armor apparel you are wearing"), ghack_accelerator_selected, - GINT_TO_POINTER('R'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'R',GDK_SHIFT_MASK - }, - GNOMEUIINFO_END + { GNOME_APP_UI_ITEM, N_("Wield Weapon"), + N_("Select a weapon to fight with"), ghack_accelerator_selected, + GINT_TO_POINTER('w'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'w', 0 }, + { GNOME_APP_UI_ITEM, N_("Remove Apparel..."), + N_("Remove apparel dialog bog"), ghack_accelerator_selected, + GINT_TO_POINTER('A'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'A', + GDK_SHIFT_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Wear Armor"), N_("Put on armor"), + ghack_accelerator_selected, GINT_TO_POINTER('W'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'W', GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Take off Armor"), + N_("Take off armor you are wearing"), ghack_accelerator_selected, + GINT_TO_POINTER('T'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'T', + GDK_SHIFT_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Put on non-armor"), + N_("Put on non-armor apparel"), ghack_accelerator_selected, + GINT_TO_POINTER('P'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'P', + GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Remove non-armor"), + N_("Remove non-armor apparel you are wearing"), + ghack_accelerator_selected, GINT_TO_POINTER('R'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'R', GDK_SHIFT_MASK }, + GNOMEUIINFO_END }; GnomeUIInfo action_menu[] = { - { - GNOME_APP_UI_ITEM, N_("Get"), - N_("Pick up things at the current location"), - ghack_accelerator_selected, - GINT_TO_POINTER(','), NULL, GNOME_APP_PIXMAP_NONE, NULL, ',',0 - }, - { - GNOME_APP_UI_ITEM, N_("Loot"), - N_("loot a box on the floor"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('l')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'l',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Sit"), - N_("sit down"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('s')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 's',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Force"), - N_("force a lock"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('f')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'f',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Kick"), - N_("kick something (usually a door)"), - ghack_accelerator_selected, - GINT_TO_POINTER(C('d')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',GDK_CONTROL_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Jump"), - N_("jump to another location"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('j')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'j',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Ride"), - N_("Ride (or stop riding) a monster"), - doride, - GINT_TO_POINTER(M('r')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'R',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Wipe face"), - N_("wipe off your face"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('w')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'w',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Throw/Shoot"), - N_("throw or shoot a weapon"), - ghack_accelerator_selected, - GINT_TO_POINTER('t'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',0 - }, - { - GNOME_APP_UI_ITEM, N_("Quiver/Ready"), - N_("ready or quiver some ammunition"), - ghack_accelerator_selected, - GINT_TO_POINTER('Q'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'Q',GDK_SHIFT_MASK, - }, - { - GNOME_APP_UI_ITEM, N_("Open Door"), - N_("open a door"), - ghack_accelerator_selected, - GINT_TO_POINTER('o'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'o',0 - }, - { - GNOME_APP_UI_ITEM, N_("Close Door"), - N_("open a door"), - ghack_accelerator_selected, - GINT_TO_POINTER('c'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'c',0 - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Drop"), - N_("drop an object"), - ghack_accelerator_selected, - GINT_TO_POINTER('d'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',0 - }, - { - GNOME_APP_UI_ITEM, N_("Drop Many"), - N_("drop selected types of objects"), - ghack_accelerator_selected, - GINT_TO_POINTER('D'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'D',GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Eat"), - N_("eat something"), - ghack_accelerator_selected, - GINT_TO_POINTER('e'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'e',0 - }, - { - GNOME_APP_UI_ITEM, N_("Engrave"), - N_("write a message in the dust on the floor"), - ghack_accelerator_selected, - GINT_TO_POINTER('E'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'E',GDK_SHIFT_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Apply"), - N_("apply or use a tool (pick-axe, key, camera, etc.)"), - ghack_accelerator_selected, - GINT_TO_POINTER('a'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'a',0 - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Up"), - N_("go up the stairs"), - ghack_accelerator_selected, - GINT_TO_POINTER('<'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '<',0 - }, - { - GNOME_APP_UI_ITEM, N_("Down"), - N_("go down the stairs"), - ghack_accelerator_selected, - GINT_TO_POINTER('>'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '>',0 - }, - { - GNOME_APP_UI_ITEM, N_("Rest"), - N_("wait for a moment"), - ghack_accelerator_selected, - GINT_TO_POINTER('.'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '.',0 - }, - { - GNOME_APP_UI_ITEM, N_("Search"), - N_("search for secret doors, hidden traps and monsters"), - ghack_accelerator_selected, - GINT_TO_POINTER('s'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 's',0 - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Chat"), - N_("talk to someone"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('c')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'c',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Pay"), - N_("pay your bill to the shopkeeper"), - ghack_accelerator_selected, - GINT_TO_POINTER('p'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'p',0 - }, - GNOMEUIINFO_END + { GNOME_APP_UI_ITEM, N_("Get"), + N_("Pick up things at the current location"), + ghack_accelerator_selected, GINT_TO_POINTER(','), NULL, + GNOME_APP_PIXMAP_NONE, NULL, ',', 0 }, + { GNOME_APP_UI_ITEM, N_("Loot"), N_("loot a box on the floor"), + ghack_accelerator_selected, GINT_TO_POINTER(M('l')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'l', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Sit"), N_("sit down"), + ghack_accelerator_selected, GINT_TO_POINTER(M('s')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 's', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Force"), N_("force a lock"), + ghack_accelerator_selected, GINT_TO_POINTER(M('f')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'f', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Kick"), N_("kick something (usually a door)"), + ghack_accelerator_selected, GINT_TO_POINTER(C('d')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'd', GDK_CONTROL_MASK }, + { GNOME_APP_UI_ITEM, N_("Jump"), N_("jump to another location"), + ghack_accelerator_selected, GINT_TO_POINTER(M('j')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'j', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Ride"), N_("Ride (or stop riding) a monster"), + doride, GINT_TO_POINTER(M('r')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'R', + GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Wipe face"), N_("wipe off your face"), + ghack_accelerator_selected, GINT_TO_POINTER(M('w')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'w', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Throw/Shoot"), N_("throw or shoot a weapon"), + ghack_accelerator_selected, GINT_TO_POINTER('t'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 't', 0 }, + { + GNOME_APP_UI_ITEM, N_("Quiver/Ready"), + N_("ready or quiver some ammunition"), ghack_accelerator_selected, + GINT_TO_POINTER('Q'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'Q', + GDK_SHIFT_MASK, + }, + { GNOME_APP_UI_ITEM, N_("Open Door"), N_("open a door"), + ghack_accelerator_selected, GINT_TO_POINTER('o'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'o', 0 }, + { GNOME_APP_UI_ITEM, N_("Close Door"), N_("open a door"), + ghack_accelerator_selected, GINT_TO_POINTER('c'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'c', 0 }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Drop"), N_("drop an object"), + ghack_accelerator_selected, GINT_TO_POINTER('d'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'd', 0 }, + { GNOME_APP_UI_ITEM, N_("Drop Many"), + N_("drop selected types of objects"), ghack_accelerator_selected, + GINT_TO_POINTER('D'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'D', + GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Eat"), N_("eat something"), + ghack_accelerator_selected, GINT_TO_POINTER('e'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'e', 0 }, + { GNOME_APP_UI_ITEM, N_("Engrave"), + N_("write a message in the dust on the floor"), + ghack_accelerator_selected, GINT_TO_POINTER('E'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'E', GDK_SHIFT_MASK }, + { GNOME_APP_UI_ITEM, N_("Apply"), + N_("apply or use a tool (pick-axe, key, camera, etc.)"), + ghack_accelerator_selected, GINT_TO_POINTER('a'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'a', 0 }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Up"), N_("go up the stairs"), + ghack_accelerator_selected, GINT_TO_POINTER('<'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, '<', 0 }, + { GNOME_APP_UI_ITEM, N_("Down"), N_("go down the stairs"), + ghack_accelerator_selected, GINT_TO_POINTER('>'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, '>', 0 }, + { GNOME_APP_UI_ITEM, N_("Rest"), N_("wait for a moment"), + ghack_accelerator_selected, GINT_TO_POINTER('.'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, '.', 0 }, + { GNOME_APP_UI_ITEM, N_("Search"), + N_("search for secret doors, hidden traps and monsters"), + ghack_accelerator_selected, GINT_TO_POINTER('s'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 's', 0 }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Chat"), N_("talk to someone"), + ghack_accelerator_selected, GINT_TO_POINTER(M('c')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'c', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Pay"), N_("pay your bill to the shopkeeper"), + ghack_accelerator_selected, GINT_TO_POINTER('p'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'p', 0 }, + GNOMEUIINFO_END }; GnomeUIInfo magic_menu[] = { - { - GNOME_APP_UI_ITEM, N_("Quaff potion"), - N_("drink a potion"), - ghack_accelerator_selected, - GINT_TO_POINTER('q'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'q',0 - }, - { - GNOME_APP_UI_ITEM, N_("Read Book/Scroll"), - N_("read a spell book or a scroll"), - ghack_accelerator_selected, - GINT_TO_POINTER('r'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'r',0 - }, - { - GNOME_APP_UI_ITEM, N_("Zap Wand"), - N_("zap a wand"), - ghack_accelerator_selected, - GINT_TO_POINTER('z'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'z',0 - }, - { - GNOME_APP_UI_ITEM, N_("Zap Spell"), - N_("cast a spell"), - ghack_accelerator_selected, - GINT_TO_POINTER('Z'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'Z',GDK_SHIFT_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Dip"), - N_("dip an object into something"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('d')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Rub"), - N_("Rub something (i.e. a lamp)"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('r')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'r',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Invoke"), - N_("invoke an object's special powers"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('i')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'i',GDK_MOD1_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Offer"), - N_("offer a sacrifice to the gods"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('o')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'o',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Pray"), - N_("pray to the gods for help"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('p')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'p',GDK_MOD1_MASK - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("Teleport"), - N_("teleport (if you can)"), - ghack_accelerator_selected, - GINT_TO_POINTER(C('t')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',GDK_CONTROL_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Monster Action"), - N_("use a monster's special ability"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('m')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'm',GDK_MOD1_MASK - }, - { - GNOME_APP_UI_ITEM, N_("Turn Undead"), - N_("turn undead"), - ghack_accelerator_selected, - GINT_TO_POINTER(M('t')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',GDK_MOD1_MASK - }, - GNOMEUIINFO_END + { GNOME_APP_UI_ITEM, N_("Quaff potion"), N_("drink a potion"), + ghack_accelerator_selected, GINT_TO_POINTER('q'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'q', 0 }, + { GNOME_APP_UI_ITEM, N_("Read Book/Scroll"), + N_("read a spell book or a scroll"), ghack_accelerator_selected, + GINT_TO_POINTER('r'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'r', 0 }, + { GNOME_APP_UI_ITEM, N_("Zap Wand"), N_("zap a wand"), + ghack_accelerator_selected, GINT_TO_POINTER('z'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'z', 0 }, + { GNOME_APP_UI_ITEM, N_("Zap Spell"), N_("cast a spell"), + ghack_accelerator_selected, GINT_TO_POINTER('Z'), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'Z', GDK_SHIFT_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Dip"), N_("dip an object into something"), + ghack_accelerator_selected, GINT_TO_POINTER(M('d')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'd', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Rub"), N_("Rub something (i.e. a lamp)"), + ghack_accelerator_selected, GINT_TO_POINTER(M('r')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'r', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Invoke"), + N_("invoke an object's special powers"), ghack_accelerator_selected, + GINT_TO_POINTER(M('i')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'i', + GDK_MOD1_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Offer"), N_("offer a sacrifice to the gods"), + ghack_accelerator_selected, GINT_TO_POINTER(M('o')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'o', GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Pray"), N_("pray to the gods for help"), + ghack_accelerator_selected, GINT_TO_POINTER(M('p')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 'p', GDK_MOD1_MASK }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("Teleport"), N_("teleport (if you can)"), + ghack_accelerator_selected, GINT_TO_POINTER(C('t')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 't', GDK_CONTROL_MASK }, + { GNOME_APP_UI_ITEM, N_("Monster Action"), + N_("use a monster's special ability"), ghack_accelerator_selected, + GINT_TO_POINTER(M('m')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'm', + GDK_MOD1_MASK }, + { GNOME_APP_UI_ITEM, N_("Turn Undead"), N_("turn undead"), + ghack_accelerator_selected, GINT_TO_POINTER(M('t')), NULL, + GNOME_APP_PIXMAP_NONE, NULL, 't', GDK_MOD1_MASK }, + GNOMEUIINFO_END }; GnomeUIInfo help_menu[] = { - { - GNOME_APP_UI_ITEM, N_("About..."), - N_("About GnomeHack"), ghack_about_cb, NULL, NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 0, 0, NULL - }, - { - GNOME_APP_UI_ITEM, N_("Help"), NULL, - ghack_accelerator_selected, - GINT_TO_POINTER('?'), NULL, GNOME_APP_PIXMAP_STOCK, - GNOME_STOCK_MENU_ABOUT, '?', 0 - }, - GNOMEUIINFO_SEPARATOR, - { - GNOME_APP_UI_ITEM, N_("What is here"), - N_("Check what items occupy the current location"), - ghack_accelerator_selected, - GINT_TO_POINTER(':'), NULL, GNOME_APP_PIXMAP_STOCK, - GNOME_STOCK_MENU_ABOUT, ':',0 - }, - { - GNOME_APP_UI_ITEM, N_("What is that"), - N_("Identify an object"), - ghack_accelerator_selected, - GINT_TO_POINTER(';'), NULL, GNOME_APP_PIXMAP_STOCK, - GNOME_STOCK_MENU_ABOUT, ';',0 - }, - { - GNOME_APP_UI_ITEM, N_("Identify a map symbol"), - N_("Identify a map symbol"), - ghack_accelerator_selected, - GINT_TO_POINTER('/'), NULL, GNOME_APP_PIXMAP_STOCK, - GNOME_STOCK_MENU_ABOUT, '/',0 - }, - GNOMEUIINFO_END -}; - -GnomeUIInfo mainmenu[] = { - GNOMEUIINFO_MENU_GAME_TREE(game_tree), - GNOMEUIINFO_MENU_EDIT_TREE(edit_menu), - { GNOME_APP_UI_SUBTREE, N_("Apparel"), NULL, apparel_menu, NULL, - NULL, 0, NULL, 0, 0, NULL }, - { GNOME_APP_UI_SUBTREE, N_("Action"), NULL, action_menu, NULL, - NULL, 0, NULL, 0, 0, NULL }, - { GNOME_APP_UI_SUBTREE, N_("Magic"), NULL, magic_menu, NULL, - NULL, 0, NULL, 0, 0, NULL }, - GNOMEUIINFO_MENU_HELP_TREE(help_menu), - GNOMEUIINFO_END + { GNOME_APP_UI_ITEM, N_("About..."), N_("About GnomeHack"), + ghack_about_cb, NULL, NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, 0, 0, NULL }, + { GNOME_APP_UI_ITEM, N_("Help"), NULL, ghack_accelerator_selected, + GINT_TO_POINTER('?'), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, '?', 0 }, + GNOMEUIINFO_SEPARATOR, + { GNOME_APP_UI_ITEM, N_("What is here"), + N_("Check what items occupy the current location"), + ghack_accelerator_selected, GINT_TO_POINTER(':'), NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, ':', 0 }, + { GNOME_APP_UI_ITEM, N_("What is that"), N_("Identify an object"), + ghack_accelerator_selected, GINT_TO_POINTER(';'), NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, ';', 0 }, + { GNOME_APP_UI_ITEM, N_("Identify a map symbol"), + N_("Identify a map symbol"), ghack_accelerator_selected, + GINT_TO_POINTER('/'), NULL, GNOME_APP_PIXMAP_STOCK, + GNOME_STOCK_MENU_ABOUT, '/', 0 }, + GNOMEUIINFO_END }; +GnomeUIInfo mainmenu[] = { GNOMEUIINFO_MENU_GAME_TREE(game_tree), + GNOMEUIINFO_MENU_EDIT_TREE(edit_menu), + { GNOME_APP_UI_SUBTREE, N_("Apparel"), NULL, + apparel_menu, NULL, NULL, 0, NULL, 0, 0, NULL }, + { GNOME_APP_UI_SUBTREE, N_("Action"), NULL, + action_menu, NULL, NULL, 0, NULL, 0, 0, NULL }, + { GNOME_APP_UI_SUBTREE, N_("Magic"), NULL, + magic_menu, NULL, NULL, 0, NULL, 0, 0, NULL }, + GNOMEUIINFO_MENU_HELP_TREE(help_menu), + GNOMEUIINFO_END }; + static void -ghack_main_window_key_press(GtkWidget *widget, GdkEventKey *event, - gpointer data) +ghack_main_window_key_press(GtkWidget *widget, GdkEventKey *event, + gpointer data) { /* First, turn off the key press propogation. We've got the * key, but we don't wan't the underlying Gtk widgets to get it, * since they do the wrong thing with the arrow keys (shift focus)... */ - gtk_signal_emit_stop_by_name( GTK_OBJECT(mainWindow), "key_press_event"); - + gtk_signal_emit_stop_by_name(GTK_OBJECT(mainWindow), "key_press_event"); + /* stuff the key event into the keybuffer */ ghack_handle_key_press(widget, event, data); } - /* parsing args */ void -parse_args (int argc, char *argv[]) +parse_args(int argc, char *argv[]) { - gint ch; + gint ch; - struct option options[] = { - /* Default args */ - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, + struct option options[] = { /* Default args */ + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, - { NULL, 0, NULL, 0 } - }; + { NULL, 0, NULL, 0 } + }; - gchar *id = NULL; + gchar *id = NULL; - /* initialize getopt */ - optarg = NULL; - optind = 0; - optopt = 0; + /* initialize getopt */ + optarg = NULL; + optind = 0; + optopt = 0; - while( (ch = getopt_long(argc, argv, "hv", options, NULL)) != EOF ) - { - switch(ch) - { - case 'h': - g_print ( - _("%s: A gnomified 'Hello World' program\n\n" - "Usage: %s [--help] [--version]\n\n" - "Options:\n" - " --help display this help and exit\n" - " --version output version information and exit\n"), - argv[0], argv[0]); - exit(0); - break; - case 'v': - g_print (_("NetHack %s.\n"), VERSION_STRING); - exit(0); - break; - case ':': - case '?': - g_print (_("Options error\n")); - exit(0); - break; + while ((ch = getopt_long(argc, argv, "hv", options, NULL)) != EOF) { + switch (ch) { + case 'h': + g_print( + _("%s: A gnomified 'Hello World' program\n\n" + "Usage: %s [--help] [--version]\n\n" + "Options:\n" + " --help display this help and exit\n" + " --version output version information and exit\n"), + argv[0], argv[0]); + exit(0); + break; + case 'v': + g_print(_("NetHack %s.\n"), VERSION_STRING); + exit(0); + break; + case ':': + case '?': + g_print(_("Options error\n")); + exit(0); + break; + } } - } - /* SM stuff */ - session_id = gnome_client_new (); + /* SM stuff */ + session_id = gnome_client_new(); #if 0 session_id = gnome_client_new ( /* callback to save the state and parameter for it */ @@ -675,11 +518,11 @@ parse_args (int argc, char *argv[]) /* id from the previous session if restarted, NULL otherwise */ id); #endif - /* set the program name */ - gnome_client_set_program (session_id, argv[0]); - g_free(id); + /* set the program name */ + gnome_client_set_program(session_id, argv[0]); + g_free(id); - return; + return; } /* @@ -695,13 +538,14 @@ static struct { int signum; void (*handler)(int); } ghack_chain[] = { - {SIGBUS}, - {SIGFPE}, - {SIGSEGV}, - {SIGILL} /* Not currently handled by Gnome */ + { SIGBUS }, + { SIGFPE }, + { SIGSEGV }, + { SIGILL } /* Not currently handled by Gnome */ }; -static void ghack_sig_handler(int signum) +static void +ghack_sig_handler(int signum) { int i; uid_t uid, euid; @@ -711,24 +555,25 @@ static void ghack_sig_handler(int signum) gid = getgid(); egid = getegid(); if (gid != egid) - setgid(gid); + setgid(gid); if (uid != euid) - setuid(uid); - for(i = SIZE(ghack_chain) - 1; i >= 0; i--) - if (ghack_chain[i].signum == signum) { - ghack_chain[i].handler(signum); - break; - } + setuid(uid); + for (i = SIZE(ghack_chain) - 1; i >= 0; i--) + if (ghack_chain[i].signum == signum) { + ghack_chain[i].handler(signum); + break; + } if (i < 0) - impossible("Unhandled ghack signal"); + impossible("Unhandled ghack signal"); if (uid != euid) - setuid(euid); + setuid(euid); if (gid != egid) - setgid(egid); + setgid(egid); } /* initialize gnome and fir up the main window */ -void ghack_init_main_window( int argc, char** argv) +void +ghack_init_main_window(int argc, char **argv) { int i; struct timeval tv; @@ -748,64 +593,65 @@ void ghack_init_main_window( int argc, char** argv) uid = getuid(); euid = geteuid(); if (uid != euid) - setuid(uid); + setuid(uid); hide_privileges(TRUE); /* XXX gnome_init must print nethack options for --help, but does not */ - gnome_init ("nethack", VERSION_STRING, argc, argv); + gnome_init("nethack", VERSION_STRING, argc, argv); hide_privileges(FALSE); - parse_args (argc, argv); + parse_args(argc, argv); - /* Initialize the i18n stuff (not that gnomehack supperts it yet...) */ +/* Initialize the i18n stuff (not that gnomehack supperts it yet...) */ #if 0 textdomain (PACKAGE); #endif gdk_imlib_init(); /* Main window */ - mainWindow = gnome_app_new((char *) "nethack", - (char *) N_("Nethack for Gnome")); + mainWindow = + gnome_app_new((char *) "nethack", (char *) N_("Nethack for Gnome")); gtk_widget_realize(mainWindow); if (restarted) { - gtk_widget_set_uposition (mainWindow, os_x, os_y); - gtk_widget_set_usize (mainWindow, os_w, os_h); + gtk_widget_set_uposition(mainWindow, os_x, os_y); + gtk_widget_set_usize(mainWindow, os_w, os_h); } - gtk_window_set_default_size( GTK_WINDOW(mainWindow), 800, 600); + gtk_window_set_default_size(GTK_WINDOW(mainWindow), 800, 600); gtk_window_set_policy(GTK_WINDOW(mainWindow), FALSE, TRUE, TRUE); gnome_app_create_menus(GNOME_APP(mainWindow), mainmenu); - gtk_signal_connect(GTK_OBJECT(mainWindow), "key_press_event", - GTK_SIGNAL_FUNC(ghack_main_window_key_press), NULL); - gtk_signal_connect(GTK_OBJECT(mainWindow), "delete_event", - GTK_SIGNAL_FUNC(ghack_quit_game_cb), NULL); + gtk_signal_connect(GTK_OBJECT(mainWindow), "key_press_event", + GTK_SIGNAL_FUNC(ghack_main_window_key_press), NULL); + gtk_signal_connect(GTK_OBJECT(mainWindow), "delete_event", + GTK_SIGNAL_FUNC(ghack_quit_game_cb), NULL); /* Put some stuff into our main window */ - vBoxMain = gtk_vbox_new (FALSE, 0); - hBoxFirstRow = gtk_hbox_new (FALSE, 0); - + vBoxMain = gtk_vbox_new(FALSE, 0); + hBoxFirstRow = gtk_hbox_new(FALSE, 0); + /* pack Boxes into other boxes to produce the right structure */ - gtk_box_pack_start (GTK_BOX (vBoxMain), hBoxFirstRow, FALSE, TRUE, 0); - + gtk_box_pack_start(GTK_BOX(vBoxMain), hBoxFirstRow, FALSE, TRUE, 0); + /* pack vBoxMain which contains all our widgets into the main window. */ gnome_app_set_contents(GNOME_APP(mainWindow), vBoxMain); - + /* DONT show the main window yet, due to a Gtk bug that causes it - * to not refresh the window when adding widgets after the window + * to not refresh the window when adding widgets after the window * has already been shown */ if (uid != euid) - setuid(euid); - for(i = 0; i < SIZE(ghack_chain); i++) - ghack_chain[i].handler = - signal(ghack_chain[i].signum, ghack_sig_handler); + setuid(euid); + for (i = 0; i < SIZE(ghack_chain); i++) + ghack_chain[i].handler = + signal(ghack_chain[i].signum, ghack_sig_handler); } -void ghack_main_window_add_map_window(GtkWidget* win) +void +ghack_main_window_add_map_window(GtkWidget *win) { GtkWidget *vBox; - - vBox= gtk_vbox_new (TRUE, 0); - gtk_box_pack_start (GTK_BOX (vBox), win, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vBoxMain), vBox, TRUE, TRUE, 2); + + vBox = gtk_vbox_new(TRUE, 0); + gtk_box_pack_start(GTK_BOX(vBox), win, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(vBoxMain), vBox, TRUE, TRUE, 2); gtk_widget_show_all(vBox); - /* Ok, now show the main window -- now that we have added in + /* Ok, now show the main window -- now that we have added in * all the windows (relys on nethack displaying the map window last * (This is an ugly kludge, BTW) */ @@ -813,50 +659,50 @@ void ghack_main_window_add_map_window(GtkWidget* win) } void -ghack_main_window_add_message_window(GtkWidget* win) +ghack_main_window_add_message_window(GtkWidget *win) { - gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(hBoxFirstRow), win, TRUE, TRUE, 2); gtk_widget_show_all(win); } void -ghack_main_window_add_status_window(GtkWidget* win) +ghack_main_window_add_status_window(GtkWidget *win) { - gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(hBoxFirstRow), win, FALSE, TRUE, 2); gtk_widget_show_all(win); } void -ghack_main_window_add_worn_window(GtkWidget* win) +ghack_main_window_add_worn_window(GtkWidget *win) { - gtk_box_pack_end (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2); + gtk_box_pack_end(GTK_BOX(hBoxFirstRow), win, FALSE, TRUE, 2); gtk_widget_show_all(win); } void ghack_main_window_add_text_window(GtkWidget *win) { - g_warning("Fixme!!! AddTextWindow is not yet implemented"); + g_warning("Fixme!!! AddTextWindow is not yet implemented"); } void ghack_main_window_remove_window(GtkWidget *win) { - g_warning("Fixme!!! RemoveWindow is not yet implemented"); + g_warning("Fixme!!! RemoveWindow is not yet implemented"); } void ghack_main_window_update_inventory() { -/* For now, do very little. Eventually we may allow the inv. window - to stay active. When we do this, we'll need to implement this... - g_warning("Fixme!!! updateInventory is not yet implemented"); -*/ - gnome_display_nhwindow(WIN_WORN, FALSE); + /* For now, do very little. Eventually we may allow the inv. window + to stay active. When we do this, we'll need to implement this... + g_warning("Fixme!!! updateInventory is not yet implemented"); + */ + gnome_display_nhwindow(WIN_WORN, FALSE); } -GtkWidget* +GtkWidget * ghack_get_main_window() { - return( GTK_WIDGET(mainWindow) ); + return (GTK_WIDGET(mainWindow)); } diff --git a/win/gnome/gnmap.c b/win/gnome/gnmap.c index 11bd9b13a..279fd6973 100644 --- a/win/gnome/gnmap.c +++ b/win/gnome/gnmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnmap.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnmap.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 gnmap.c $Date: 2009/05/06 10:57:34 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)gnmap.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -17,29 +17,30 @@ /* globals static to this file go here */ struct { - GnomeCanvas *canvas; - GnomeCanvasImage *map[(ROWNO + 1) * COLNO]; - GnomeCanvasImage *overlay[(ROWNO + 1) * COLNO]; - double zoom; - GtkWidget *frame; + GnomeCanvas *canvas; + GnomeCanvasImage *map[(ROWNO + 1) * COLNO]; + GnomeCanvasImage *overlay[(ROWNO + 1) * COLNO]; + double zoom; + GtkWidget *frame; } ghack_map; - + static GdkImlibImage *background; static GdkImlibImage *petmark; static GnomeCanvasGroup *myCanvasGroup; /* static function declarations -- local to this file go here */ -void ghack_map_cursor_to( GtkWidget *win, int x, int y, gpointer data); -void ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data); -void ghack_map_print_glyph( GtkObject *win, guint x, guint y, GdkImlibImage *im, gpointer data); -void ghack_map_clear( GtkWidget *win, gpointer data); -static void ghack_map_display( GtkWidget *win, boolean block, gpointer data); -static void ghack_map_cliparound( GtkWidget *win, int x, int y, gpointer data); -static void ghack_map_window_zoom( GtkAdjustment *adj, gpointer data); - +void ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data); +void ghack_map_putstr(GtkWidget *win, int attr, const char *text, + gpointer data); +void ghack_map_print_glyph(GtkObject *win, guint x, guint y, + GdkImlibImage *im, gpointer data); +void ghack_map_clear(GtkWidget *win, gpointer data); +static void ghack_map_display(GtkWidget *win, boolean block, gpointer data); +static void ghack_map_cliparound(GtkWidget *win, int x, int y, gpointer data); +static void ghack_map_window_zoom(GtkAdjustment *adj, gpointer data); /* The following XPM is the artwork of Warwick Allison - * . It has been borrowed from + * . It has been borrowed from * the most excellent NetHackQt, until such time as * we can come up with something better. * @@ -49,23 +50,16 @@ static void ghack_map_window_zoom( GtkAdjustment *adj, gpointer data); /* XPM */ static char *pet_mark_xpm[] = { -/* width height ncolors chars_per_pixel */ -"8 7 2 1", -/* colors */ -". c None", -" c #FF0000", -/* pixels */ -"........", -".. . .", -". ", -". ", -".. .", -"... ..", -".... ..." + /* width height ncolors chars_per_pixel */ + "8 7 2 1", + /* colors */ + ". c None", " c #FF0000", + /* pixels */ + "........", ".. . .", ". ", ". ", + ".. .", "... ..", ".... ..." }; - -/* NAME: +/* NAME: * ghack_init_map_window( ) * * ARGUMENTS: @@ -81,234 +75,191 @@ static char *pet_mark_xpm[] = { * to behave properly. */ -GtkWidget* -ghack_init_map_window ( ) +GtkWidget * +ghack_init_map_window() { - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *table; - GtkWidget *frame; - GtkWidget *w; - GtkWidget *hSeparator; - GtkAdjustment *adj; - GnomeCanvasImage *bg; - double width, height, x, y; - int i; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *table; + GtkWidget *frame; + GtkWidget *w; + GtkWidget *hSeparator; + GtkAdjustment *adj; + GnomeCanvasImage *bg; + double width, height, x, y; + int i; - width = COLNO * ghack_glyph_width(); - height = ROWNO * ghack_glyph_height(); + width = COLNO * ghack_glyph_width(); + height = ROWNO * ghack_glyph_height(); - vbox = gtk_vbox_new (FALSE, 4); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); - gtk_widget_show (vbox); - - /* Add in a horiz seperator */ - hSeparator = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (vbox), hSeparator, FALSE, FALSE, 2); - gtk_widget_show ( hSeparator); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); + vbox = gtk_vbox_new(FALSE, 4); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); + gtk_widget_show(vbox); - /* Create the Zoom spinbutton. - */ - ghack_map.zoom = 1.0; - w = gtk_label_new ("Zoom:"); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.00, 0.5, 3.00, 0.05, 0.50, 0.50)); - w = gtk_spin_button_new (adj, 0.5, 2); - gtk_widget_set_usize (w, 50, 0); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); + /* Add in a horiz seperator */ + hSeparator = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox), hSeparator, FALSE, FALSE, 2); + gtk_widget_show(hSeparator); - /* Canvas and scrollbars - */ - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new()); - //gtk_widget_push_visual(gdk_rgb_get_visual()); - //gtk_widget_push_colormap(gdk_rgb_get_cmap()); - //ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new_aa()); + hbox = gtk_hbox_new(FALSE, 4); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show(hbox); - gtk_widget_pop_colormap(); - gtk_widget_pop_visual(); - gtk_widget_show (GTK_WIDGET(ghack_map.canvas)); + /* Create the Zoom spinbutton. + */ + ghack_map.zoom = 1.0; + w = gtk_label_new("Zoom:"); + gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0); + gtk_widget_show(w); + adj = + GTK_ADJUSTMENT(gtk_adjustment_new(1.00, 0.5, 3.00, 0.05, 0.50, 0.50)); + w = gtk_spin_button_new(adj, 0.5, 2); + gtk_widget_set_usize(w, 50, 0); + gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0); + gtk_widget_show(w); - table = gtk_table_new (2, 2, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_table_set_col_spacings (GTK_TABLE (table), 4); - gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0); - gtk_widget_show (table); - - frame = gtk_frame_new (NULL); - ghack_map.frame = frame; - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); - gtk_table_attach (GTK_TABLE (table), frame, - 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (frame); + /* Canvas and scrollbars + */ + gtk_widget_push_visual(gdk_imlib_get_visual()); + gtk_widget_push_colormap(gdk_imlib_get_colormap()); + ghack_map.canvas = GNOME_CANVAS(gnome_canvas_new()); + // gtk_widget_push_visual(gdk_rgb_get_visual()); + // gtk_widget_push_colormap(gdk_rgb_get_cmap()); + // ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new_aa()); - gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET(ghack_map.canvas)); - gnome_canvas_set_scroll_region (GNOME_CANVAS(ghack_map.canvas), 0, 0, - width+2*ghack_glyph_width(), height+2*ghack_glyph_height()); + gtk_widget_pop_colormap(); + gtk_widget_pop_visual(); + gtk_widget_show(GTK_WIDGET(ghack_map.canvas)); - gnome_canvas_set_pixels_per_unit (GNOME_CANVAS(ghack_map.canvas), 1.0); + table = gtk_table_new(2, 2, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(table), 4); + gtk_table_set_col_spacings(GTK_TABLE(table), 4); + gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); + gtk_widget_show(table); - w = gtk_hscrollbar_new (GTK_LAYOUT (ghack_map.canvas)->hadjustment); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL, - 0, 0); - gtk_widget_show (w); + frame = gtk_frame_new(NULL); + ghack_map.frame = frame; + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); + gtk_widget_show(frame); - w = gtk_vscrollbar_new (GTK_LAYOUT (ghack_map.canvas)->vadjustment); - gtk_table_attach (GTK_TABLE (table), w, - 1, 2, 0, 1, GTK_FILL, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - myCanvasGroup = GNOME_CANVAS_GROUP ( gnome_canvas_item_new ( - gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)), - gnome_canvas_group_get_type (), - "x", 0.0, - "y", 0.0, - NULL) ); + gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(ghack_map.canvas)); + gnome_canvas_set_scroll_region(GNOME_CANVAS(ghack_map.canvas), 0, 0, + width + 2 * ghack_glyph_width(), + height + 2 * ghack_glyph_height()); - /* Tile the map background with a pretty image */ - background = gdk_imlib_load_image((char *) "mapbg.xpm"); - if (background == NULL) { - g_warning("Bummer! Failed to load the map background image (mapbg.xpm)!"); - } - else { - gdk_imlib_render(background, background->rgb_width, - background->rgb_height); + gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(ghack_map.canvas), 1.0); - /* Tile the map background */ - for (y = 0; y < height+background->rgb_height; y+=background->rgb_height) - { - for (x = 0; x < width+background->rgb_width; x+=background->rgb_width) - { - bg = GNOME_CANVAS_IMAGE( gnome_canvas_item_new ( - myCanvasGroup, gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) background->rgb_width, - "height", (double) background->rgb_height, - "image", background, - "anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, - NULL) ); - gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM( bg)); - } - } - } + w = gtk_hscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->hadjustment); + gtk_table_attach(GTK_TABLE(table), w, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0); + gtk_widget_show(w); - /* ghack_map.map is an array of canvas images. Each cell of - * the array will contain one tile. Here, we create the - * space for the cells and then create the cells for easy - * access later. - */ - for (i=0, y = 0; y < height; y+=ghack_glyph_height()) - { - for (x = 0; x < width; x+=ghack_glyph_width()) - { - ghack_map.map[i++] = GNOME_CANVAS_IMAGE( - gnome_canvas_item_new ( - myCanvasGroup, - gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) ghack_glyph_width(), - "height", (double) ghack_glyph_height(), - "anchor", GTK_ANCHOR_NORTH_WEST, - NULL) ); - } + w = gtk_vscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->vadjustment); + gtk_table_attach(GTK_TABLE(table), w, 1, 2, 0, 1, GTK_FILL, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); + gtk_widget_show(w); + + myCanvasGroup = GNOME_CANVAS_GROUP(gnome_canvas_item_new( + gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)), + gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL)); + + /* Tile the map background with a pretty image */ + background = gdk_imlib_load_image((char *) "mapbg.xpm"); + if (background == NULL) { + g_warning( + "Bummer! Failed to load the map background image (mapbg.xpm)!"); + } else { + gdk_imlib_render(background, background->rgb_width, + background->rgb_height); + + /* Tile the map background */ + for (y = 0; y < height + background->rgb_height; + y += background->rgb_height) { + for (x = 0; x < width + background->rgb_width; + x += background->rgb_width) { + bg = GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", + (double) x, "y", (double) y, "width", + (double) background->rgb_width, "height", + (double) background->rgb_height, "image", background, + "anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, NULL)); + gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(bg)); + } + } } - /* Set up the pet mark image */ - petmark = gdk_imlib_create_image_from_xpm_data( pet_mark_xpm); - if (petmark == NULL) { - g_warning("Bummer! Failed to load the pet_mark image!"); - } - else { - gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height); + /* ghack_map.map is an array of canvas images. Each cell of + * the array will contain one tile. Here, we create the + * space for the cells and then create the cells for easy + * access later. + */ + for (i = 0, y = 0; y < height; y += ghack_glyph_height()) { + for (x = 0; x < width; x += ghack_glyph_width()) { + ghack_map.map[i++] = GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", (double) x, + "y", (double) y, "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", + GTK_ANCHOR_NORTH_WEST, NULL)); + } + } - /* ghack_map.overlay is an array of canvas images used to - * overlay tile images... - */ - for (i=0, y = 0; y < height; y+=ghack_glyph_height()) - { - for (x = 0; x < width; x+=ghack_glyph_width()) - { - ghack_map.overlay[i] = GNOME_CANVAS_IMAGE( - gnome_canvas_item_new ( - myCanvasGroup, - gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) petmark->rgb_width, - "height", (double) petmark->rgb_height, - "image", petmark, - "anchor", GTK_ANCHOR_NORTH_WEST, - NULL) ); - gnome_canvas_item_lower_to_bottom ( - GNOME_CANVAS_ITEM( ghack_map.overlay[i++])); - } - } - } + /* Set up the pet mark image */ + petmark = gdk_imlib_create_image_from_xpm_data(pet_mark_xpm); + if (petmark == NULL) { + g_warning("Bummer! Failed to load the pet_mark image!"); + } else { + gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height); - /* Resize the canvas when the spinbutton changes - */ - gtk_signal_connect (GTK_OBJECT (adj), - "value_changed", - (GtkSignalFunc) ghack_map_window_zoom, - ghack_map.canvas); + /* ghack_map.overlay is an array of canvas images used to + * overlay tile images... + */ + for (i = 0, y = 0; y < height; y += ghack_glyph_height()) { + for (x = 0; x < width; x += ghack_glyph_width()) { + ghack_map.overlay[i] = + GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", + (double) x, "y", (double) y, "width", + (double) petmark->rgb_width, "height", + (double) petmark->rgb_height, "image", petmark, + "anchor", GTK_ANCHOR_NORTH_WEST, NULL)); + gnome_canvas_item_lower_to_bottom( + GNOME_CANVAS_ITEM(ghack_map.overlay[i++])); + } + } + } - /* Game signals - */ - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_curs", - GTK_SIGNAL_FUNC (ghack_map_cursor_to), - NULL); - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_putstr", - GTK_SIGNAL_FUNC (ghack_map_putstr), - NULL); - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_print_glyph", - GTK_SIGNAL_FUNC (ghack_map_print_glyph), - NULL); - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_clear", - GTK_SIGNAL_FUNC (ghack_map_clear), - NULL); - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_display", - GTK_SIGNAL_FUNC (ghack_map_display), - NULL); - gtk_signal_connect (GTK_OBJECT (vbox), - "ghack_cliparound", - GTK_SIGNAL_FUNC (ghack_map_cliparound), - NULL); - gtk_signal_connect (GTK_OBJECT (ghack_map.canvas), - "button_press_event", - GTK_SIGNAL_FUNC (ghack_handle_button_press), - NULL); - gtk_signal_connect(GTK_OBJECT (ghack_map.canvas), - "gnome_delay_output", - GTK_SIGNAL_FUNC(ghack_delay), - NULL); - - return GTK_WIDGET(vbox); + /* Resize the canvas when the spinbutton changes + */ + gtk_signal_connect(GTK_OBJECT(adj), "value_changed", + (GtkSignalFunc) ghack_map_window_zoom, + ghack_map.canvas); + + /* Game signals + */ + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_curs", + GTK_SIGNAL_FUNC(ghack_map_cursor_to), NULL); + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_putstr", + GTK_SIGNAL_FUNC(ghack_map_putstr), NULL); + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_print_glyph", + GTK_SIGNAL_FUNC(ghack_map_print_glyph), NULL); + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_clear", + GTK_SIGNAL_FUNC(ghack_map_clear), NULL); + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_display", + GTK_SIGNAL_FUNC(ghack_map_display), NULL); + gtk_signal_connect(GTK_OBJECT(vbox), "ghack_cliparound", + GTK_SIGNAL_FUNC(ghack_map_cliparound), NULL); + gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "button_press_event", + GTK_SIGNAL_FUNC(ghack_handle_button_press), NULL); + gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "gnome_delay_output", + GTK_SIGNAL_FUNC(ghack_delay), NULL); + + return GTK_WIDGET(vbox); } - -/* NAME: +/* NAME: * ghack_map_window_zoom * * ARGUMENTS: @@ -324,67 +275,59 @@ ghack_init_map_window ( ) */ static void -ghack_map_window_zoom( GtkAdjustment *adj, gpointer data) +ghack_map_window_zoom(GtkAdjustment *adj, gpointer data) { - if ( adj->value > 3.0 ) - adj->value = 3.0; - if ( adj->value < 0.5 ) - adj->value = 0.5; - ghack_map.zoom = adj->value; - gnome_canvas_set_pixels_per_unit (data, adj->value); + if (adj->value > 3.0) + adj->value = 3.0; + if (adj->value < 0.5) + adj->value = 0.5; + ghack_map.zoom = adj->value; + gnome_canvas_set_pixels_per_unit(data, adj->value); } - - void -ghack_map_cursor_to( GtkWidget *win, int x, int y, gpointer data) +ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data) { - GnomeCanvasGroup *group; - static GnomeCanvasRE *cursor = NULL; + GnomeCanvasGroup *group; + static GnomeCanvasRE *cursor = NULL; - double x1, y1, x2, y2; - float hp; - guint r, g, b; + double x1, y1, x2, y2; + float hp; + guint r, g, b; - x1 = x * ghack_glyph_width() - 1; - y1 = y * ghack_glyph_height() - 1; - x2 = x1 + ghack_glyph_width() + 2; - y2 = y1 + ghack_glyph_height() + 2; - hp = u.mtimedone - ? (u.mhmax ? (float)u.mh/u.mhmax : 1) - : (u.uhpmax ? (float)u.uhp/u.uhpmax : 1); + x1 = x * ghack_glyph_width() - 1; + y1 = y * ghack_glyph_height() - 1; + x2 = x1 + ghack_glyph_width() + 2; + y2 = y1 + ghack_glyph_height() + 2; + hp = u.mtimedone ? (u.mhmax ? (float) u.mh / u.mhmax : 1) + : (u.uhpmax ? (float) u.uhp / u.uhpmax : 1); - r = 255; - g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255*2*(hp-0.25) : 0); - b = (hp >= 0.75) ? 255*4*(hp-0.75) : (hp >= 0.25 ? 0 : 255*4*(0.25-hp)); + r = 255; + g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255 * 2 * (hp - 0.25) : 0); + b = (hp >= 0.75) ? 255 * 4 * (hp - 0.75) + : (hp >= 0.25 ? 0 : 255 * 4 * (0.25 - hp)); - group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); + group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); - if (!cursor) { - cursor = GNOME_CANVAS_RE (gnome_canvas_item_new (group, - gnome_canvas_rect_get_type (), - "width_units", 1.0, NULL)); - } - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cursor), - "outline_color_rgba", GNOME_CANVAS_COLOR(r, g, b), - "x1", x1, - "y1", y1, - "x2", x2, - "y2", y2, - NULL); + if (!cursor) { + cursor = GNOME_CANVAS_RE(gnome_canvas_item_new( + group, gnome_canvas_rect_get_type(), "width_units", 1.0, NULL)); + } + gnome_canvas_item_set(GNOME_CANVAS_ITEM(cursor), "outline_color_rgba", + GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1, + "x2", x2, "y2", y2, NULL); - gnome_canvas_item_raise_to_top( GNOME_CANVAS_ITEM( cursor)); - gnome_canvas_item_show( GNOME_CANVAS_ITEM(cursor)); + gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(cursor)); + gnome_canvas_item_show(GNOME_CANVAS_ITEM(cursor)); } - void -ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data) +ghack_map_putstr(GtkWidget *win, int attr, const char *text, gpointer data) { g_warning("Fixme!!! ghack_map_putstr is not implemented"); } -/* NAME: +/* NAME: * ghack_map_print_glyph( ) * * ARGUMENTS: @@ -399,43 +342,37 @@ ghack_map_putstr( GtkWidget *win, int attr, const char* text, gpointer data) */ void -ghack_map_print_glyph( GtkObject *win, - guint x, - guint y, - GdkImlibImage *im, - gpointer data) +ghack_map_print_glyph(GtkObject *win, guint x, guint y, GdkImlibImage *im, + gpointer data) { - GnomeCanvasGroup *group; - int i = y * COLNO + x; - int glyph = glyph_at(x,y); - GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE( ghack_map.map[i]); + GnomeCanvasGroup *group; + int i = y * COLNO + x; + int glyph = glyph_at(x, y); + GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE(ghack_map.map[i]); - group = gnome_canvas_root (GNOME_CANVAS (ghack_map.canvas)); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM ( canvas_image), - "image", im, NULL); - gnome_canvas_item_show( GNOME_CANVAS_ITEM( canvas_image)); + group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); - canvas_image = GNOME_CANVAS_IMAGE( ghack_map.overlay[i]); + gnome_canvas_item_set(GNOME_CANVAS_ITEM(canvas_image), "image", im, NULL); + gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image)); - if (x==u.ux && y==u.uy) - ghack_map_cliparound(NULL, x, y, NULL); + canvas_image = GNOME_CANVAS_IMAGE(ghack_map.overlay[i]); - if (glyph_is_pet(glyph) + if (x == u.ux && y == u.uy) + ghack_map_cliparound(NULL, x, y, NULL); + + if (glyph_is_pet(glyph) #ifdef TEXTCOLOR - && iflags.hilite_pet + && iflags.hilite_pet #endif - ) { - gnome_canvas_item_raise_to_top( GNOME_CANVAS_ITEM( canvas_image)); - gnome_canvas_item_show( GNOME_CANVAS_ITEM( canvas_image)); - } - else { - gnome_canvas_item_hide( GNOME_CANVAS_ITEM( canvas_image)); - } + ) { + gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(canvas_image)); + gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image)); + } else { + gnome_canvas_item_hide(GNOME_CANVAS_ITEM(canvas_image)); + } } - -/* NAME: +/* NAME: * ghack_map_clear( ) * * ARGUMENTS: @@ -449,173 +386,146 @@ ghack_map_print_glyph( GtkObject *win, */ void -ghack_map_clear( GtkWidget *win, gpointer data) +ghack_map_clear(GtkWidget *win, gpointer data) { - int i; + int i; - for (i = 0; i < ROWNO * COLNO; i++) - { - if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i])) - { - gnome_canvas_item_hide( GNOME_CANVAS_ITEM (ghack_map.map[i])); - } - if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i])) - { - gnome_canvas_item_hide( GNOME_CANVAS_ITEM (ghack_map.overlay[i])); - } + for (i = 0; i < ROWNO * COLNO; i++) { + if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i])) { + gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.map[i])); + } + if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i])) { + gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.overlay[i])); + } } - gnome_canvas_update_now ( GNOME_CANVAS(ghack_map.canvas)); + gnome_canvas_update_now(GNOME_CANVAS(ghack_map.canvas)); } - void -ghack_map_display( GtkWidget *win, boolean block, gpointer data) +ghack_map_display(GtkWidget *win, boolean block, gpointer data) { - gtk_widget_show_all( GTK_WIDGET(win)); + gtk_widget_show_all(GTK_WIDGET(win)); } - void -ghack_map_cliparound( GtkWidget *win, - int x, - int y, - gpointer data) +ghack_map_cliparound(GtkWidget *win, int x, int y, gpointer data) { - int map_width, map_height; - int to_x, to_y; - int cur_x, cur_y; - int width, height, half_width, half_height; + int map_width, map_height; + int to_x, to_y; + int cur_x, cur_y; + int width, height, half_width, half_height; - x *= ghack_glyph_width() * ghack_map.zoom; - y *= ghack_glyph_height() * ghack_map.zoom; - map_width = COLNO * ghack_glyph_width() * ghack_map.zoom; - map_height = ROWNO * ghack_glyph_height() * ghack_map.zoom; + x *= ghack_glyph_width() * ghack_map.zoom; + y *= ghack_glyph_height() * ghack_map.zoom; + map_width = COLNO * ghack_glyph_width() * ghack_map.zoom; + map_height = ROWNO * ghack_glyph_height() * ghack_map.zoom; - gdk_window_get_size( GTK_LAYOUT (ghack_map.canvas)->bin_window, - &width, &height); - gnome_canvas_get_scroll_offsets( ghack_map.canvas, &cur_x, &cur_y); + gdk_window_get_size(GTK_LAYOUT(ghack_map.canvas)->bin_window, &width, + &height); + gnome_canvas_get_scroll_offsets(ghack_map.canvas, &cur_x, &cur_y); - half_width = width * 0.5; - half_height = height * 0.5; + half_width = width * 0.5; + half_height = height * 0.5; - if ( ((x - cur_x) < (width * 0.25) ) || ( (x - cur_x) > (width * 0.75) ) ) { - to_x = ((x-half_width) > 0)? x - half_width : 0; - to_x = ((x+half_width) > map_width)? map_width - 2 * half_width : to_x; - } - else { - to_x = cur_x; - } - - if ( ((y - cur_y) < (height * 0.25) ) || ( (y - cur_y) > (height * 0.75) ) ) { - to_y = ((y-half_height) > 0)? y - half_height : 0; - to_y = ((y+half_height) > map_height)? map_height - 2 * half_height : to_y; - } - else { - to_y = cur_y; - } - - if (to_x != cur_x || to_y != cur_y) - gnome_canvas_scroll_to( ghack_map.canvas, to_x, to_y); - //gnome_canvas_update_now ( ghack_map.canvas); - -} - - - -void -ghack_reinit_map_window ( ) -{ - GnomeCanvasImage *bg; - double width, height, x, y; - int i; - - /* ghack_map_clear(NULL, NULL); */ - - width = COLNO * ghack_glyph_width(); - height = ROWNO * ghack_glyph_height(); - - gnome_canvas_set_scroll_region (GNOME_CANVAS(ghack_map.canvas), 0, 0, - width+2*ghack_glyph_width(), height+2*ghack_glyph_height()); - - /* remove everything currently in the canvas map */ - gtk_object_destroy( GTK_OBJECT (myCanvasGroup)); - - /* Put some groups back */ - myCanvasGroup = GNOME_CANVAS_GROUP ( gnome_canvas_item_new ( - gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)), - gnome_canvas_group_get_type (), - "x", 0.0, - "y", 0.0, - NULL) ); - - /* Tile the map background with a pretty image */ - if (background != NULL) { - /* Tile the map background */ - for (y = 0; y < height+background->rgb_height; y+=background->rgb_height) - { - for (x = 0; x < width+background->rgb_width; x+=background->rgb_width) - { - bg = GNOME_CANVAS_IMAGE( gnome_canvas_item_new ( - myCanvasGroup, gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) background->rgb_width, - "height", (double) background->rgb_height, - "image", background, - "anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, - NULL) ); - gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM( bg)); - } + if (((x - cur_x) < (width * 0.25)) || ((x - cur_x) > (width * 0.75))) { + to_x = ((x - half_width) > 0) ? x - half_width : 0; + to_x = ((x + half_width) > map_width) ? map_width - 2 * half_width + : to_x; + } else { + to_x = cur_x; } - } - /* ghack_map.map is an array of canvas images. Each cell of - * the array will contain one tile. Here, we create the - * space for the cells and then create the cells for easy - * access later. - */ - for (i=0, y = 0; y < height; y+=ghack_glyph_height()) { - for (x = 0; x < width; x+=ghack_glyph_width()) { - ghack_map.map[i++] = GNOME_CANVAS_IMAGE( - gnome_canvas_item_new ( - myCanvasGroup, - gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) ghack_glyph_width(), - "height", (double) ghack_glyph_height(), - "anchor", GTK_ANCHOR_NORTH_WEST, - NULL) ); - } - } - - if (petmark != NULL) { - /* ghack_map.overlay is an array of canvas images used to - * overlay tile images... - */ - for (i=0, y = 0; y < height; y+=ghack_glyph_height()) { - for (x = 0; x < width; x+=ghack_glyph_width()) { - ghack_map.overlay[i] = GNOME_CANVAS_IMAGE( - gnome_canvas_item_new ( - myCanvasGroup, - gnome_canvas_image_get_type (), - "x", (double) x, - "y", (double) y, - "width", (double) petmark->rgb_width, - "height", (double) petmark->rgb_height, - "image", petmark, - "anchor", GTK_ANCHOR_NORTH_WEST, - NULL) ); - gnome_canvas_item_lower_to_bottom ( - GNOME_CANVAS_ITEM( ghack_map.overlay[i++])); - } - } - } + if (((y - cur_y) < (height * 0.25)) || ((y - cur_y) > (height * 0.75))) { + to_y = ((y - half_height) > 0) ? y - half_height : 0; + to_y = ((y + half_height) > map_height) ? map_height - 2 * half_height + : to_y; + } else { + to_y = cur_y; + } - ghack_map_cliparound(NULL, u.ux, u.uy, NULL); - ghack_map_cursor_to(NULL, u.ux, u.uy, NULL); - gnome_canvas_update_now ( ghack_map.canvas); - doredraw(); + if (to_x != cur_x || to_y != cur_y) + gnome_canvas_scroll_to(ghack_map.canvas, to_x, to_y); + // gnome_canvas_update_now ( ghack_map.canvas); } +void +ghack_reinit_map_window() +{ + GnomeCanvasImage *bg; + double width, height, x, y; + int i; + /* ghack_map_clear(NULL, NULL); */ + + width = COLNO * ghack_glyph_width(); + height = ROWNO * ghack_glyph_height(); + + gnome_canvas_set_scroll_region(GNOME_CANVAS(ghack_map.canvas), 0, 0, + width + 2 * ghack_glyph_width(), + height + 2 * ghack_glyph_height()); + + /* remove everything currently in the canvas map */ + gtk_object_destroy(GTK_OBJECT(myCanvasGroup)); + + /* Put some groups back */ + myCanvasGroup = GNOME_CANVAS_GROUP(gnome_canvas_item_new( + gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)), + gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL)); + + /* Tile the map background with a pretty image */ + if (background != NULL) { + /* Tile the map background */ + for (y = 0; y < height + background->rgb_height; + y += background->rgb_height) { + for (x = 0; x < width + background->rgb_width; + x += background->rgb_width) { + bg = GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", + (double) x, "y", (double) y, "width", + (double) background->rgb_width, "height", + (double) background->rgb_height, "image", background, + "anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, NULL)); + gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(bg)); + } + } + } + + /* ghack_map.map is an array of canvas images. Each cell of + * the array will contain one tile. Here, we create the + * space for the cells and then create the cells for easy + * access later. + */ + for (i = 0, y = 0; y < height; y += ghack_glyph_height()) { + for (x = 0; x < width; x += ghack_glyph_width()) { + ghack_map.map[i++] = GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", (double) x, + "y", (double) y, "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", + GTK_ANCHOR_NORTH_WEST, NULL)); + } + } + + if (petmark != NULL) { + /* ghack_map.overlay is an array of canvas images used to + * overlay tile images... + */ + for (i = 0, y = 0; y < height; y += ghack_glyph_height()) { + for (x = 0; x < width; x += ghack_glyph_width()) { + ghack_map.overlay[i] = + GNOME_CANVAS_IMAGE(gnome_canvas_item_new( + myCanvasGroup, gnome_canvas_image_get_type(), "x", + (double) x, "y", (double) y, "width", + (double) petmark->rgb_width, "height", + (double) petmark->rgb_height, "image", petmark, + "anchor", GTK_ANCHOR_NORTH_WEST, NULL)); + gnome_canvas_item_lower_to_bottom( + GNOME_CANVAS_ITEM(ghack_map.overlay[i++])); + } + } + } + + ghack_map_cliparound(NULL, u.ux, u.uy, NULL); + ghack_map_cursor_to(NULL, u.ux, u.uy, NULL); + gnome_canvas_update_now(ghack_map.canvas); + doredraw(); +} diff --git a/win/gnome/gnmenu.c b/win/gnome/gnmenu.c index 70b59cace..097275852 100644 --- a/win/gnome/gnmenu.c +++ b/win/gnome/gnmenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnmenu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnmenu.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 gnmenu.c $Date: 2009/05/06 10:57:36 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)gnmenu.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -12,633 +12,618 @@ #include "gnbind.h" #include "func_tab.h" -typedef enum { - MenuUnknown = 0, - MenuText, - MenuMenu -} MenuWinType; +typedef enum { MenuUnknown = 0, MenuText, MenuMenu } MenuWinType; typedef struct { - ANY_P identifier; - gchar accelerator[BUFSZ]; - int itemNumber; - int selected; + ANY_P identifier; + gchar accelerator[BUFSZ]; + int itemNumber; + int selected; } menuItem; typedef struct { - int curItem; - int numRows; - int charIdx; - guint32 lastTime; + int curItem; + int numRows; + int charIdx; + guint32 lastTime; } extMenu; static GdkColor color_blue = { 0, 0, 0, 0xffff }; - static void ghack_menu_window_key(GtkWidget *menuWin, GdkEventKey *event, gpointer data) { int i, numRows; - menuItem* item; + menuItem *item; MenuWinType isMenu; - isMenu = (MenuWinType) GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); + isMenu = (MenuWinType) GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(menuWin), "isMenu")); if (isMenu == MenuMenu) { - GtkWidget *clist; - gint selection_mode; + GtkWidget *clist; + gint selection_mode; - clist = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); - g_assert (clist != NULL); - numRows = GPOINTER_TO_INT - (gtk_object_get_data(GTK_OBJECT(clist), "numRows")); - selection_mode = GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT(clist), "selection_mode")); - for (i = 0; i <= numRows; ++i) { - item = (menuItem*) gtk_clist_get_row_data(GTK_CLIST(clist), i); - if (item == NULL) continue; - if (!strcmp(item->accelerator, "")) continue; + clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist")); + g_assert(clist != NULL); + numRows = GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(clist), "numRows")); + selection_mode = GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(clist), "selection_mode")); + for (i = 0; i <= numRows; ++i) { + item = (menuItem *) gtk_clist_get_row_data(GTK_CLIST(clist), i); + if (item == NULL) + continue; + if (!strcmp(item->accelerator, "")) + continue; - if ((!strcmp(item->accelerator, event->string)) || - ((selection_mode == GTK_SELECTION_MULTIPLE) && - (event->keyval == ','))) { - if (item->selected) { - gtk_clist_unselect_row( GTK_CLIST (clist), - item->itemNumber, 0); - item->selected = FALSE; - } else { - gtk_clist_select_row(GTK_CLIST (clist), - item->itemNumber, 0); - if (gtk_clist_row_is_visible(GTK_CLIST(clist), - item->itemNumber) != GTK_VISIBILITY_FULL) - gtk_clist_moveto(GTK_CLIST(clist), - item->itemNumber, 0, 0.5, 0); - item->selected = TRUE; - } - } - } + if ((!strcmp(item->accelerator, event->string)) + || ((selection_mode == GTK_SELECTION_MULTIPLE) + && (event->keyval == ','))) { + if (item->selected) { + gtk_clist_unselect_row(GTK_CLIST(clist), item->itemNumber, + 0); + item->selected = FALSE; + } else { + gtk_clist_select_row(GTK_CLIST(clist), item->itemNumber, + 0); + if (gtk_clist_row_is_visible(GTK_CLIST(clist), + item->itemNumber) + != GTK_VISIBILITY_FULL) + gtk_clist_moveto(GTK_CLIST(clist), item->itemNumber, + 0, 0.5, 0); + item->selected = TRUE; + } + } + } } } - static void -ghack_menu_row_selected (GtkCList *clist, int row, int col, GdkEvent *event) +ghack_menu_row_selected(GtkCList *clist, int row, int col, GdkEvent *event) { /* FIXME: Do something */ } - void ghack_menu_window_clear(GtkWidget *menuWin, gpointer data) { MenuWinType isMenu; int i, numRows; - menuItem* item; + menuItem *item; - isMenu = (MenuWinType) GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); + isMenu = (MenuWinType) GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(menuWin), "isMenu")); if (isMenu == MenuMenu) { - GtkWidget *clist; + GtkWidget *clist; - clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); - g_assert (clist != NULL); + clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist")); + g_assert(clist != NULL); - /* destroy existing menu data, if any */ - if (clist) { - /* destroy all the row_data we stored in the clist */ - numRows = GPOINTER_TO_INT( gtk_object_get_data( - GTK_OBJECT(clist), "numRows") ); - for( i=0; itext), 0, 0); + gtk_editable_delete_text(GTK_EDITABLE(gless->text), 0, 0); } - } void ghack_menu_window_display(GtkWidget *menuWin, gboolean blocking, gpointer data) { - //if(blocking) { - gnome_dialog_close_hides (GNOME_DIALOG (menuWin), TRUE); - gnome_dialog_set_close (GNOME_DIALOG (menuWin), TRUE); - gnome_dialog_run_and_close(GNOME_DIALOG (menuWin)); + // if(blocking) { + gnome_dialog_close_hides(GNOME_DIALOG(menuWin), TRUE); + gnome_dialog_set_close(GNOME_DIALOG(menuWin), TRUE); + gnome_dialog_run_and_close(GNOME_DIALOG(menuWin)); //} - //else { - //gtk_widget_show(menuWin); + // else { + // gtk_widget_show(menuWin); //} } gint -ghack_menu_hide( GtkWidget *menuWin, GdkEvent *event, gpointer data ) +ghack_menu_hide(GtkWidget *menuWin, GdkEvent *event, gpointer data) { - gtk_widget_hide (menuWin); + gtk_widget_hide(menuWin); return FALSE; /* FIXME: what is correct result here? */ } - -void -ghack_menu_window_start_menu (GtkWidget *menuWin, gpointer data) +void +ghack_menu_window_start_menu(GtkWidget *menuWin, gpointer data) { GtkWidget *frame1, *swin, *clist; MenuWinType isMenu; - - g_assert (menuWin != NULL); - g_assert (data == NULL); + + g_assert(menuWin != NULL); + g_assert(data == NULL); /* destroy existing menu data, if any */ - frame1 = gtk_object_get_data (GTK_OBJECT (menuWin), "frame1"); + frame1 = gtk_object_get_data(GTK_OBJECT(menuWin), "frame1"); if (frame1) - gtk_widget_destroy (frame1); - + gtk_widget_destroy(frame1); + isMenu = MenuMenu; - gtk_object_set_data (GTK_OBJECT (menuWin), "isMenu", - GINT_TO_POINTER (isMenu)); + gtk_object_set_data(GTK_OBJECT(menuWin), "isMenu", + GINT_TO_POINTER(isMenu)); - gtk_widget_set_usize (GTK_WIDGET (menuWin), 500, 400); - gtk_window_set_policy (GTK_WINDOW (menuWin), TRUE, TRUE, FALSE); + gtk_widget_set_usize(GTK_WIDGET(menuWin), 500, 400); + gtk_window_set_policy(GTK_WINDOW(menuWin), TRUE, TRUE, FALSE); - frame1 = gtk_frame_new ("Make your selection"); - g_assert (frame1 != NULL); - gtk_object_set_data (GTK_OBJECT(menuWin), "frame1", frame1); - gtk_widget_show (GTK_WIDGET (frame1)); - gtk_container_set_border_width (GTK_CONTAINER (frame1), 5); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG(menuWin)->vbox), frame1, - TRUE, TRUE, 0); - - swin = gtk_scrolled_window_new (NULL, NULL); - g_assert (swin != NULL); - gtk_object_set_data (GTK_OBJECT(menuWin), "swin", swin); - gtk_widget_show (GTK_WIDGET (swin)); - gtk_container_add (GTK_CONTAINER (frame1), swin); + frame1 = gtk_frame_new("Make your selection"); + g_assert(frame1 != NULL); + gtk_object_set_data(GTK_OBJECT(menuWin), "frame1", frame1); + gtk_widget_show(GTK_WIDGET(frame1)); + gtk_container_set_border_width(GTK_CONTAINER(frame1), 5); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(menuWin)->vbox), frame1, TRUE, + TRUE, 0); - clist = gtk_clist_new (4); - g_assert (clist != NULL); - gtk_object_set_data (GTK_OBJECT(menuWin), "clist", clist); - gtk_widget_show (GTK_WIDGET (clist)); - gtk_container_add (GTK_CONTAINER (swin), clist); + swin = gtk_scrolled_window_new(NULL, NULL); + g_assert(swin != NULL); + gtk_object_set_data(GTK_OBJECT(menuWin), "swin", swin); + gtk_widget_show(GTK_WIDGET(swin)); + gtk_container_add(GTK_CONTAINER(frame1), swin); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + clist = gtk_clist_new(4); + g_assert(clist != NULL); + gtk_object_set_data(GTK_OBJECT(menuWin), "clist", clist); + gtk_widget_show(GTK_WIDGET(clist)); + gtk_container_add(GTK_CONTAINER(swin), clist); - gtk_signal_connect (GTK_OBJECT (clist), "select_row", - GTK_SIGNAL_FUNC (ghack_menu_row_selected), NULL); - gtk_object_set_data (GTK_OBJECT (clist), "numItems", - GINT_TO_POINTER (-1)); -} + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); - -int -ghack_menu_window_select_menu (GtkWidget *menuWin, - MENU_ITEM_P **_selected, gint how) + gtk_signal_connect(GTK_OBJECT(clist), "select_row", + GTK_SIGNAL_FUNC(ghack_menu_row_selected), NULL); + gtk_object_set_data(GTK_OBJECT(clist), "numItems", GINT_TO_POINTER(-1)); +} + +int +ghack_menu_window_select_menu(GtkWidget *menuWin, MENU_ITEM_P **_selected, + gint how) { - gint rc; - guint num_sel, i, idx; - GtkWidget *clist; - GList *cur; - MENU_ITEM_P *selected = NULL; - menuItem* item; + gint rc; + guint num_sel, i, idx; + GtkWidget *clist; + GList *cur; + MENU_ITEM_P *selected = NULL; + menuItem *item; - g_assert (_selected != NULL); - *_selected = NULL; + g_assert(_selected != NULL); + *_selected = NULL; + if (how == PICK_NONE) { + gnome_dialog_close_hides(GNOME_DIALOG(menuWin), TRUE); + rc = gnome_dialog_run_and_close(GNOME_DIALOG(menuWin)); + return (rc == 1 ? -1 : 0); + } - if (how == PICK_NONE) { - gnome_dialog_close_hides (GNOME_DIALOG (menuWin), TRUE); - rc = gnome_dialog_run_and_close (GNOME_DIALOG (menuWin)); - return( rc == 1 ? -1 : 0); - } + clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist")); + g_assert(clist != NULL); - clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); - g_assert (clist != NULL); + gtk_object_set_data(GTK_OBJECT(clist), "selection_mode", + GINT_TO_POINTER((how == PICK_ANY) + ? GTK_SELECTION_MULTIPLE + : GTK_SELECTION_SINGLE)); + gtk_clist_set_selection_mode(GTK_CLIST(clist), + (how == PICK_ANY) ? GTK_SELECTION_MULTIPLE + : GTK_SELECTION_SINGLE); + gnome_dialog_close_hides(GNOME_DIALOG(menuWin), TRUE); + rc = gnome_dialog_run_and_close(GNOME_DIALOG(menuWin)); + if ((rc == 1) || (GTK_CLIST(clist)->selection == NULL)) { + return (-1); + } - gtk_object_set_data (GTK_OBJECT (clist), "selection_mode", - GINT_TO_POINTER ((how == PICK_ANY)? - GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE)); - gtk_clist_set_selection_mode (GTK_CLIST (clist), - (how == PICK_ANY)? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); - gnome_dialog_close_hides (GNOME_DIALOG (menuWin), TRUE); - rc = gnome_dialog_run_and_close (GNOME_DIALOG (menuWin)); - if ((rc == 1) || (GTK_CLIST (clist)->selection == NULL)) { - return(-1); - } + num_sel = g_list_length(GTK_CLIST(clist)->selection); + if (num_sel < 1) { + return (-1); + } - num_sel = g_list_length (GTK_CLIST (clist)->selection); - if (num_sel < 1) { - return(-1); - } + /* fill in array with selections from clist */ + selected = g_new0(MENU_ITEM_P, num_sel); + g_assert(selected != NULL); + cur = GTK_CLIST(clist)->selection; + i = 0; + while (cur) { + g_assert(i < num_sel); - /* fill in array with selections from clist */ - selected = g_new0( MENU_ITEM_P, num_sel); - g_assert (selected != NULL); - cur = GTK_CLIST (clist)->selection; - i = 0; - while (cur) { - g_assert (i < num_sel); + /* grab row number from clist selection list */ + idx = GPOINTER_TO_INT(cur->data); - /* grab row number from clist selection list */ - idx = GPOINTER_TO_INT (cur->data); + item = (menuItem *) gtk_clist_get_row_data(GTK_CLIST(clist), idx); + selected[i].item = item->identifier; + selected[i].count = -1; + cur = g_list_next(cur); + i++; + } - item = (menuItem*) gtk_clist_get_row_data( GTK_CLIST (clist), idx); - selected[i].item = item->identifier; - selected[i].count = -1; - cur = g_list_next(cur); - i++; - } + *_selected = selected; - *_selected = selected; + return ((int) num_sel); +} - return( (int) num_sel); -} - -void -ghack_menu_window_add_menu( GtkWidget *menuWin, gpointer menu_item, - gpointer data) +void +ghack_menu_window_add_menu(GtkWidget *menuWin, gpointer menu_item, + gpointer data) { - GHackMenuItem* item; - GtkWidget *clist; - gchar buf[BUFSZ]="", accelBuf[BUFSZ]=""; + GHackMenuItem *item; + GtkWidget *clist; + gchar buf[BUFSZ] = "", accelBuf[BUFSZ] = ""; gchar *pbuf; char *text[4] = { buf, NULL, NULL, NULL }; gint nCurrentRow = -1, numItems = -1; MenuWinType isMenu; GtkStyle *bigStyle = NULL; gboolean item_selectable; - GdkImlibImage* image; + GdkImlibImage *image; static gboolean special; - g_assert (menu_item != NULL); - item = (GHackMenuItem*) menu_item; - item_selectable = ( item->identifier->a_int == 0)? FALSE : TRUE; - isMenu = (MenuWinType) GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); + g_assert(menu_item != NULL); + item = (GHackMenuItem *) menu_item; + item_selectable = (item->identifier->a_int == 0) ? FALSE : TRUE; + isMenu = (MenuWinType) GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(menuWin), "isMenu")); - clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); - g_assert (clist != NULL); - /* This is a special kludge to make the special hidden help menu item work as designed */ - if ( special==TRUE ) { - special=FALSE; - item_selectable=TRUE; + clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist")); + g_assert(clist != NULL); + /* This is a special kludge to make the special hidden help menu item work + * as designed */ + if (special == TRUE) { + special = FALSE; + item_selectable = TRUE; } - if ( ! strcmp( item->str, "The NetHack license.")) { - special=TRUE; + if (!strcmp(item->str, "The NetHack license.")) { + special = TRUE; } - + if (item->str) { + /* First, make a new blank entry in the clist */ + nCurrentRow = gtk_clist_append(GTK_CLIST(clist), text); - /* First, make a new blank entry in the clist */ - nCurrentRow = gtk_clist_append (GTK_CLIST (clist), text); + if (item->glyph != NO_GLYPH) { + image = ghack_image_from_glyph(item->glyph, FALSE); + if (image == NULL || image->pixmap == NULL) { + g_warning("Bummer -- having to force rendering for glyph %d!", + item->glyph); + /* wierd -- pixmap is NULL so retry rendering it */ + image = ghack_image_from_glyph(item->glyph, TRUE); + } + if (image == NULL || image->pixmap == NULL) { + g_error("Aiiee! glyph is still NULL for item\n\"%s\"", + item->str); + } else + gtk_clist_set_pixmap(GTK_CLIST(clist), nCurrentRow, 1, + gdk_imlib_move_image(image), + gdk_imlib_move_mask(image)); + } + if (item->accelerator) { + /* FIXME: handle accelerator, */ + g_snprintf(accelBuf, sizeof(accelBuf), "%c ", item->accelerator); + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); + g_snprintf(buf, sizeof(buf), "%s", item->str); + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 2, buf); + } else { + if (item->group_accel) { + /* FIXME: maybe some day I should try to handle + * group accelerators... */ + } + if (((item->attr == 0) && (item->identifier->a_int != 0)) + || (special == TRUE)) { + numItems = GPOINTER_TO_INT(gtk_object_get_data( + GTK_OBJECT(clist), "numItems")) + 1; - if (item->glyph != NO_GLYPH) { - image = ghack_image_from_glyph( item->glyph, FALSE); - if (image==NULL || image->pixmap==NULL) { - g_warning("Bummer -- having to force rendering for glyph %d!", item->glyph); - /* wierd -- pixmap is NULL so retry rendering it */ - image = ghack_image_from_glyph( item->glyph, TRUE); - } - if (image==NULL || image->pixmap==NULL) { - g_error("Aiiee! glyph is still NULL for item\n\"%s\"", - item->str); - } - else - gtk_clist_set_pixmap (GTK_CLIST (clist), - nCurrentRow, 1, - gdk_imlib_move_image( image), - gdk_imlib_move_mask( image)); - } - if (item->accelerator) { - /* FIXME: handle accelerator, */ - g_snprintf(accelBuf, sizeof(accelBuf), "%c ", item->accelerator); - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 0, accelBuf); - g_snprintf(buf, sizeof(buf), "%s", item->str); - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); - } else { - if (item->group_accel) { - /* FIXME: maybe some day I should try to handle - * group accelerators... */ - } - if (( (item->attr == 0) && (item->identifier->a_int != 0)) || (special ==TRUE) ) { - numItems = GPOINTER_TO_INT( gtk_object_get_data( - GTK_OBJECT(clist), "numItems") )+1; + /* Ok, now invent a unique accelerator */ + if (('a' + numItems) <= 'z') { + g_snprintf(accelBuf, sizeof(accelBuf), "%c ", + 'a' + numItems); + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, + accelBuf); + } else if (('A' + numItems - 26) <= 'Z') { + g_snprintf(accelBuf, sizeof(accelBuf), "%c ", + 'A' + numItems - 26); + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, + accelBuf); + } else { + accelBuf[0] = buf[0] = 0; + } + g_snprintf(buf, sizeof(buf), "%s", item->str); + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 2, buf); + gtk_object_set_data(GTK_OBJECT(clist), "numItems", + GINT_TO_POINTER(numItems)); - /* Ok, now invent a unique accelerator */ - if ( ('a'+numItems) <= 'z' ) { - g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'a'+numItems); - gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); - } - else if ( ('A'+numItems-26)<='Z') { - g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'A'+numItems-26); - gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); - } else { - accelBuf[0] = buf[0] = 0; - } - g_snprintf(buf, sizeof(buf), "%s", item->str); - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); - gtk_object_set_data (GTK_OBJECT (clist), "numItems", - GINT_TO_POINTER (numItems)); + /* This junk is to specially handle the options menu */ + pbuf = strstr(buf, " ["); + if (pbuf == NULL) { + pbuf = strstr(buf, "\t["); + } + if (pbuf != NULL) { + *pbuf = 0; + pbuf++; + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 3, + pbuf); + } + } + /* FIXME: handle more than 26*2 accelerators (but how? + * since I only have so many keys to work with???) + else + { + foo(); + } + */ + else { + g_snprintf(buf, sizeof(buf), "%s", item->str); + pbuf = strstr(buf, " ["); + if (pbuf == NULL) { + pbuf = strstr(buf, "\t["); + } + if (pbuf != NULL) { + *pbuf = 0; + pbuf++; + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 3, + pbuf); + } + gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 2, buf); + } + } - /* This junk is to specially handle the options menu */ - pbuf = strstr( buf, " ["); - if (pbuf == NULL) { - pbuf = strstr( buf, "\t["); - } - if (pbuf != NULL) { - *pbuf=0; - pbuf++; - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); - } - } - /* FIXME: handle more than 26*2 accelerators (but how? - * since I only have so many keys to work with???) - else - { - foo(); - } - */ - else { - g_snprintf(buf, sizeof(buf), "%s", item->str); - pbuf = strstr( buf, " ["); - if (pbuf == NULL) { - pbuf = strstr( buf, "\t["); - } - if (pbuf != NULL) { - *pbuf=0; - pbuf++; - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); - } - gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); - - } - } + if (item->attr) { + switch (item->attr) { + case ATR_ULINE: + case ATR_BOLD: + case ATR_BLINK: + case ATR_INVERSE: + bigStyle = gtk_style_copy(GTK_WIDGET(clist)->style); + g_assert(bigStyle != NULL); + gdk_font_unref(bigStyle->font); + bigStyle->font = + gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); + bigStyle->fg[GTK_STATE_NORMAL] = color_blue; + gtk_clist_set_cell_style(GTK_CLIST(clist), nCurrentRow, 2, + bigStyle); + item_selectable = FALSE; + } + } - if (item->attr) { - switch(item->attr) { - case ATR_ULINE: - case ATR_BOLD: - case ATR_BLINK: - case ATR_INVERSE: - bigStyle = gtk_style_copy (GTK_WIDGET (clist)->style); - g_assert (bigStyle != NULL); - gdk_font_unref (bigStyle->font); - bigStyle->font = gdk_font_load ( - "-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); - bigStyle->fg[GTK_STATE_NORMAL] = color_blue; - gtk_clist_set_cell_style (GTK_CLIST (clist), - nCurrentRow, 2, bigStyle); - item_selectable = FALSE; - } - } + g_assert(nCurrentRow >= 0); + gtk_clist_set_selectable(GTK_CLIST(clist), nCurrentRow, + item_selectable); + if (item_selectable == TRUE && item->presel == TRUE) { + /* pre-select this item */ + gtk_clist_select_row(GTK_CLIST(clist), nCurrentRow, 0); + } - g_assert (nCurrentRow >= 0); - gtk_clist_set_selectable (GTK_CLIST (clist), nCurrentRow, - item_selectable); + gtk_object_set_data(GTK_OBJECT(clist), "numRows", + GINT_TO_POINTER(nCurrentRow)); - if ( item_selectable==TRUE && item->presel== TRUE) { - /* pre-select this item */ - gtk_clist_select_row( GTK_CLIST (clist), nCurrentRow, 0); - } - - gtk_object_set_data (GTK_OBJECT (clist), "numRows", - GINT_TO_POINTER (nCurrentRow)); - - /* We have to allocate memory here, since the menu_item currently - * lives on the stack, and will otherwise go to the great bit bucket - * in the sky as soon as this function exits, which would leave a - * pointer to crap in the row_data. Use g_memdup to make a private, - * persistant copy of the item identifier. - * - * We need to arrange to blow away this memory somewhere (like - * ghack_menu_destroy and ghack_menu_window_clear for example). - * - * -Erik - */ - { - menuItem newItem; - menuItem *pNewItem; - - newItem.identifier = *item->identifier; - newItem.itemNumber=nCurrentRow; - newItem.selected=FALSE; - newItem.accelerator[0]=0; - /* only copy 1 char, since accel keys are by definition 1 char */ - if (accelBuf[0]) { - strncpy(newItem.accelerator, accelBuf, 1); - } - newItem.accelerator[1]=0; + /* We have to allocate memory here, since the menu_item currently + * lives on the stack, and will otherwise go to the great bit bucket + * in the sky as soon as this function exits, which would leave a + * pointer to crap in the row_data. Use g_memdup to make a private, + * persistant copy of the item identifier. + * + * We need to arrange to blow away this memory somewhere (like + * ghack_menu_destroy and ghack_menu_window_clear for example). + * + * -Erik + */ + { + menuItem newItem; + menuItem *pNewItem; - pNewItem = g_memdup(&newItem, sizeof( menuItem)); - gtk_clist_set_row_data (GTK_CLIST (clist), nCurrentRow, - (gpointer) pNewItem); - } + newItem.identifier = *item->identifier; + newItem.itemNumber = nCurrentRow; + newItem.selected = FALSE; + newItem.accelerator[0] = 0; + /* only copy 1 char, since accel keys are by definition 1 char */ + if (accelBuf[0]) { + strncpy(newItem.accelerator, accelBuf, 1); + } + newItem.accelerator[1] = 0; + + pNewItem = g_memdup(&newItem, sizeof(menuItem)); + gtk_clist_set_row_data(GTK_CLIST(clist), nCurrentRow, + (gpointer) pNewItem); + } } /* Now adjust the column widths to match the contents */ - gtk_clist_columns_autosize (GTK_CLIST (clist)); + gtk_clist_columns_autosize(GTK_CLIST(clist)); } void -ghack_menu_window_end_menu (GtkWidget *menuWin, gpointer data) +ghack_menu_window_end_menu(GtkWidget *menuWin, gpointer data) { - const char* p = (const char*) data; + const char *p = (const char *) data; - if ((p) && (*p)) { - GtkWidget *frame1 = gtk_object_get_data (GTK_OBJECT (menuWin), "frame1"); - g_assert (frame1 != NULL); - - gtk_frame_set_label (GTK_FRAME(frame1), p); - } + if ((p) && (*p)) { + GtkWidget *frame1 = + gtk_object_get_data(GTK_OBJECT(menuWin), "frame1"); + g_assert(frame1 != NULL); + gtk_frame_set_label(GTK_FRAME(frame1), p); + } } - -void ghack_menu_window_put_string(GtkWidget *menuWin, int attr, - const char* text, gpointer data) +void +ghack_menu_window_put_string(GtkWidget *menuWin, int attr, const char *text, + gpointer data) { GnomeLess *gless; MenuWinType isMenu; if (text == NULL) return; - - isMenu = (MenuWinType) GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); + + isMenu = (MenuWinType) GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(menuWin), "isMenu")); if (isMenu == MenuText) { - gless = GNOME_LESS (gtk_object_get_data (GTK_OBJECT (menuWin), "gless")); - g_assert (gless != NULL); - g_assert (gless->text != NULL); - g_assert (GTK_IS_TEXT (gless->text)); + gless = GNOME_LESS(gtk_object_get_data(GTK_OBJECT(menuWin), "gless")); + g_assert(gless != NULL); + g_assert(gless->text != NULL); + g_assert(GTK_IS_TEXT(gless->text)); - /* Don't bother with attributes yet */ - gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, text, -1); - gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1); + /* Don't bother with attributes yet */ + gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, text, -1); + gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, "\n", -1); } else if (isMenu == MenuUnknown) { - isMenu = MenuText; - gtk_object_set_data (GTK_OBJECT (menuWin), "isMenu", - GINT_TO_POINTER (isMenu)); + isMenu = MenuText; + gtk_object_set_data(GTK_OBJECT(menuWin), "isMenu", + GINT_TO_POINTER(isMenu)); - gtk_widget_set_usize (GTK_WIDGET (menuWin), 500, 400); - gtk_window_set_policy (GTK_WINDOW (menuWin), TRUE, TRUE, FALSE); - - gless = GNOME_LESS (gnome_less_new ()); - g_assert (gless != NULL); - gtk_object_set_data (GTK_OBJECT (menuWin), "gless", gless); - gtk_widget_show (GTK_WIDGET (gless)); + gtk_widget_set_usize(GTK_WIDGET(menuWin), 500, 400); + gtk_window_set_policy(GTK_WINDOW(menuWin), TRUE, TRUE, FALSE); - gnome_less_show_string (gless, text); - gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1); + gless = GNOME_LESS(gnome_less_new()); + g_assert(gless != NULL); + gtk_object_set_data(GTK_OBJECT(menuWin), "gless", gless); + gtk_widget_show(GTK_WIDGET(gless)); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (menuWin)->vbox), - GTK_WIDGET (gless), TRUE, TRUE, 0); + gnome_less_show_string(gless, text); + gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, "\n", -1); + + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(menuWin)->vbox), + GTK_WIDGET(gless), TRUE, TRUE, 0); } } - void -ghack_menu_destroy (GtkWidget *menuWin, gpointer data) +ghack_menu_destroy(GtkWidget *menuWin, gpointer data) { MenuWinType isMenu; - isMenu = (MenuWinType) GPOINTER_TO_INT - (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); + isMenu = (MenuWinType) GPOINTER_TO_INT( + gtk_object_get_data(GTK_OBJECT(menuWin), "isMenu")); if (isMenu == MenuText) { - GnomeLess *gless; + GnomeLess *gless; - gless = GNOME_LESS (gtk_object_get_data (GTK_OBJECT (menuWin), "gless")); - g_assert (gless != NULL); - g_assert (gless->text != NULL); - g_assert (GTK_IS_TEXT (gless->text)); - gtk_widget_destroy(GTK_WIDGET(gless)); + gless = GNOME_LESS(gtk_object_get_data(GTK_OBJECT(menuWin), "gless")); + g_assert(gless != NULL); + g_assert(gless->text != NULL); + g_assert(GTK_IS_TEXT(gless->text)); + gtk_widget_destroy(GTK_WIDGET(gless)); } else if (isMenu == MenuMenu) { - GtkWidget *frame1, *swin, *clist; + GtkWidget *frame1, *swin, *clist; - /* destroy existing menu data, if any */ - clist = gtk_object_get_data (GTK_OBJECT (menuWin), "clist"); - if (clist) { - /* destroy all the row_data we stored in the clist */ - int i, numRows; - menuItem* item; - numRows = GPOINTER_TO_INT( gtk_object_get_data( - GTK_OBJECT(clist), "numRows") ); - for( i=0; istring[0]; @@ -646,38 +631,39 @@ ghack_ext_key_hit(GtkWidget *menuWin, GdkEventKey *event, gpointer data) g_assert(clist != NULL); /* if too long between keystrokes, reset to initial state */ - if (event->time - info->lastTime > 500) goto init_state; + if (event->time - info->lastTime > 500) + goto init_state; /* see if current item continue to match */ if (info->charIdx > 0) { - if (extcmdlist[info->curItem].ef_txt[info->charIdx] == c) { - ++info->charIdx; - goto found; - } + if (extcmdlist[info->curItem].ef_txt[info->charIdx] == c) { + ++info->charIdx; + goto found; + } } /* see if the prefix matches a later command in the list */ if (info->curItem >= 0) { - for (i = info->curItem + 1; i < info->numRows; ++i) { - if (!strncmp(extcmdlist[info->curItem].ef_txt, - extcmdlist[i].ef_txt, info->charIdx)) { - if (extcmdlist[i].ef_txt[info->charIdx] == c) { - ++info->charIdx; - info->curItem = i; - goto found; - } - } - } + for (i = info->curItem + 1; i < info->numRows; ++i) { + if (!strncmp(extcmdlist[info->curItem].ef_txt, + extcmdlist[i].ef_txt, info->charIdx)) { + if (extcmdlist[i].ef_txt[info->charIdx] == c) { + ++info->charIdx; + info->curItem = i; + goto found; + } + } + } } - + init_state: /* reset to initial state, look for matching 1st character */ for (i = 0; i < info->numRows; ++i) { - if (extcmdlist[i].ef_txt[0] == c) { - info->charIdx = 1; - info->curItem = i; - goto found; - } + if (extcmdlist[i].ef_txt[0] == c) { + info->charIdx = 1; + info->curItem = i; + goto found; + } } /* no match: leave prior, if any selection in place */ @@ -686,28 +672,26 @@ init_state: found: info->lastTime = event->time; gtk_clist_select_row(GTK_CLIST(clist), info->curItem, 0); - if (gtk_clist_row_is_visible(GTK_CLIST(clist), - info->curItem) != GTK_VISIBILITY_FULL) - gtk_clist_moveto(GTK_CLIST(clist), info->curItem, 0, 0.5, 0); + if (gtk_clist_row_is_visible(GTK_CLIST(clist), info->curItem) + != GTK_VISIBILITY_FULL) + gtk_clist_moveto(GTK_CLIST(clist), info->curItem, 0, 0.5, 0); } int ghack_menu_ext_cmd(void) { int n; - GtkWidget* dialog; - GtkWidget* swin; - GtkWidget* frame1; - GtkWidget* clist; + GtkWidget *dialog; + GtkWidget *swin; + GtkWidget *frame1; + GtkWidget *clist; extMenu info; - dialog = gnome_dialog_new("Extended Commands", - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); + dialog = gnome_dialog_new("Extended Commands", GNOME_STOCK_BUTTON_OK, + GNOME_STOCK_BUTTON_CANCEL, NULL); gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE); gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event", - GTK_SIGNAL_FUNC(ghack_ext_key_hit), &info); + GTK_SIGNAL_FUNC(ghack_ext_key_hit), &info); frame1 = gtk_frame_new("Make your selection"); gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1); @@ -720,18 +704,20 @@ ghack_menu_ext_cmd(void) gtk_widget_set_usize(clist, 500, 400); gtk_container_add(GTK_CONTAINER(swin), clist); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); gtk_signal_connect(GTK_OBJECT(clist), "select_row", - GTK_SIGNAL_FUNC(ghack_menu_row_selected), NULL); + GTK_SIGNAL_FUNC(ghack_menu_row_selected), NULL); gtk_container_add(GTK_CONTAINER(frame1), swin); gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1); /* Add the extended commands into the list here... */ for (n = 0; extcmdlist[n].ef_txt; ++n) { - const char *text[3]={extcmdlist[n].ef_txt,extcmdlist[n].ef_desc,NULL}; - gtk_clist_insert(GTK_CLIST(clist), n, (char**) text); + const char *text[3] = { extcmdlist[n].ef_txt, extcmdlist[n].ef_desc, + NULL }; + gtk_clist_insert(GTK_CLIST(clist), n, (char **) text); } /* fill in starting info fields */ @@ -747,7 +733,7 @@ ghack_menu_ext_cmd(void) gnome_dialog_set_default(GNOME_DIALOG(dialog), 0); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gnome_dialog_set_parent(GNOME_DIALOG(dialog), - GTK_WINDOW(ghack_get_main_window())); + GTK_WINDOW(ghack_get_main_window())); /* Run the dialog -- returning whichever button was pressed */ n = gnome_dialog_run_and_close(GNOME_DIALOG(dialog)); diff --git a/win/gnome/gnmesg.c b/win/gnome/gnmesg.c index c469911fa..a1c7133b7 100644 --- a/win/gnome/gnmesg.c +++ b/win/gnome/gnmesg.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnmesg.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnmesg.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 gnmesg.c $Date: 2009/05/06 10:57:39 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)gnmesg.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -7,69 +7,71 @@ #include "gnmesg.h" #include "gnsignal.h" -/* Pick an arbitrary number of chars such as 80 col X 40 rows text = 3200 chars */ -#define nCharsBeforeDeletingStuff 3200 +/* Pick an arbitrary number of chars such as 80 col X 40 rows text = 3200 + * chars */ +#define nCharsBeforeDeletingStuff 3200 /* Message Window widgets */ GtkWidget *MW_table; GtkWidget *MW_text; GtkWidget *MW_scrollbar; - -void ghack_message_window_clear(GtkWidget *widget, gpointer data) +void +ghack_message_window_clear(GtkWidget *widget, gpointer data) { /* Seems nethack calls this after every move -- we don't want * to really clear the window at all though. Ignore the request */ gint len; len = gtk_text_get_length(GTK_TEXT(MW_text)); - - if(len < nCharsBeforeDeletingStuff) + + if (len < nCharsBeforeDeletingStuff) return; - + gtk_text_freeze(GTK_TEXT(MW_text)); gtk_text_set_point(GTK_TEXT(MW_text), 0); - gtk_text_forward_delete(GTK_TEXT(MW_text), len-((guint)(nCharsBeforeDeletingStuff*0.5))); - gtk_text_set_point(GTK_TEXT(MW_text), (guint)(nCharsBeforeDeletingStuff*0.5)); + gtk_text_forward_delete(GTK_TEXT(MW_text), + len - ((guint)(nCharsBeforeDeletingStuff * 0.5))); + gtk_text_set_point(GTK_TEXT(MW_text), + (guint)(nCharsBeforeDeletingStuff * 0.5)); gtk_text_thaw(GTK_TEXT(MW_text)); } -void ghack_message_window_destroy( GtkWidget *win, gpointer data) +void +ghack_message_window_destroy(GtkWidget *win, gpointer data) { - } -void ghack_message_window_display(GtkWidget *widget, boolean block, - gpointer data) +void +ghack_message_window_display(GtkWidget *widget, boolean block, gpointer data) { - } -void ghack_message_window_put_string(GtkWidget *widget, int attr, - const char* text, gpointer data) +void +ghack_message_window_put_string(GtkWidget *widget, int attr, const char *text, + gpointer data) { - - if(text == NULL) + if (text == NULL) return; - + /* Don't bother with attributes yet */ gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, text, -1); gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, "\n", -1); } -void ghack_message_window_use_RIP(int how) +void +ghack_message_window_use_RIP(int how) { - } -void ghack_message_window_scroll(int dx, int dy) +void +ghack_message_window_scroll(int dx, int dy) { - } -GtkWidget* ghack_init_message_window(void) +GtkWidget * +ghack_init_message_window(void) { - MW_table = gtk_table_new(2, 1, FALSE); gtk_table_set_row_spacing(GTK_TABLE(MW_table), 0, 2); @@ -77,28 +79,23 @@ GtkWidget* ghack_init_message_window(void) gtk_text_set_editable(GTK_TEXT(MW_text), FALSE); gtk_text_set_word_wrap(GTK_TEXT(MW_text), TRUE); gtk_table_attach(GTK_TABLE(MW_table), MW_text, 0, 1, 0, 1, - (GTK_EXPAND | GTK_FILL), - (GTK_EXPAND | GTK_FILL), - 0, 0); + (GTK_EXPAND | GTK_FILL), (GTK_EXPAND | GTK_FILL), 0, 0); MW_scrollbar = gtk_vscrollbar_new(GTK_TEXT(MW_text)->vadj); - gtk_table_attach(GTK_TABLE(MW_table), MW_scrollbar, 1, 2, 0, 1, - GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0); - + gtk_table_attach(GTK_TABLE(MW_table), MW_scrollbar, 1, 2, 0, 1, GTK_FILL, + (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_putstr", - GTK_SIGNAL_FUNC(ghack_message_window_put_string), - NULL); + GTK_SIGNAL_FUNC(ghack_message_window_put_string), + NULL); gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_clear", - GTK_SIGNAL_FUNC(ghack_message_window_clear), - NULL); - + GTK_SIGNAL_FUNC(ghack_message_window_clear), NULL); + gtk_signal_connect(GTK_OBJECT(MW_table), "gnome_delay_output", - GTK_SIGNAL_FUNC(ghack_delay), NULL); + GTK_SIGNAL_FUNC(ghack_delay), NULL); gtk_widget_show_all(MW_table); return GTK_WIDGET(MW_table); } - - diff --git a/win/gnome/gnopts.c b/win/gnome/gnopts.c index a8b708e59..49843e767 100644 --- a/win/gnome/gnopts.c +++ b/win/gnome/gnopts.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnopts.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnopts.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 gnopts.c $Date: 2009/05/06 10:57:40 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)gnopts.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -13,19 +13,19 @@ #include "hack.h" static gint tileset; -static GtkWidget* clist; -const char* tilesets[] = { "Traditional (16x16)", "Big (32x32)", 0 }; +static GtkWidget *clist; +const char *tilesets[] = { "Traditional (16x16)", "Big (32x32)", 0 }; static void opt_sel_key_hit(GtkWidget *widget, GdkEventKey *event, gpointer data) { - int i; - for (i = 0; tilesets[i] != 0; ++i) { - if (tilesets[i][0] == toupper(event->keyval)) { - tileset = i; - gtk_clist_select_row( GTK_CLIST (clist), i, 0); - } - } + int i; + for (i = 0; tilesets[i] != 0; ++i) { + if (tilesets[i][0] == toupper(event->keyval)) { + tileset = i; + gtk_clist_select_row(GTK_CLIST(clist), i, 0); + } + } } static void @@ -38,82 +38,79 @@ void ghack_settings_dialog() { int i; - static GtkWidget* dialog; - static GtkWidget* swin; - static GtkWidget* frame1; + static GtkWidget *dialog; + static GtkWidget *swin; + static GtkWidget *frame1; - dialog = gnome_dialog_new (_("GnomeHack Settings"), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE); - gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event", - GTK_SIGNAL_FUNC (opt_sel_key_hit), tilesets ); + dialog = gnome_dialog_new(_("GnomeHack Settings"), GNOME_STOCK_BUTTON_OK, + GNOME_STOCK_BUTTON_CANCEL, NULL); + gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE); + gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event", + GTK_SIGNAL_FUNC(opt_sel_key_hit), tilesets); - frame1 = gtk_frame_new (_("Choose one of the following tilesets:")); - gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1); - gtk_widget_show (frame1); - gtk_container_border_width (GTK_CONTAINER (frame1), 3); + frame1 = gtk_frame_new(_("Choose one of the following tilesets:")); + gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1); + gtk_widget_show(frame1); + gtk_container_border_width(GTK_CONTAINER(frame1), 3); - swin = gtk_scrolled_window_new (NULL, NULL); - clist = gtk_clist_new (2); - gtk_clist_column_titles_hide (GTK_CLIST (clist)); - gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180); - gtk_container_add (GTK_CONTAINER (swin), clist); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + swin = gtk_scrolled_window_new(NULL, NULL); + clist = gtk_clist_new(2); + gtk_clist_column_titles_hide(GTK_CLIST(clist)); + gtk_widget_set_usize(GTK_WIDGET(clist), 100, 180); + gtk_container_add(GTK_CONTAINER(swin), clist); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); - gtk_signal_connect (GTK_OBJECT (clist), "select_row", - GTK_SIGNAL_FUNC (opt_sel_row_selected), NULL ); + gtk_signal_connect(GTK_OBJECT(clist), "select_row", + GTK_SIGNAL_FUNC(opt_sel_row_selected), NULL); - gtk_container_add (GTK_CONTAINER (frame1), swin); - gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1); + gtk_container_add(GTK_CONTAINER(frame1), swin); + gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1); /* Add the tilesets into the list here... */ - for (i=0; tilesets[i]; i++) { - gchar accelBuf[BUFSZ]; - const char *text[3]={accelBuf, tilesets[i],NULL}; - sprintf( accelBuf, "%c ", tolower(tilesets[i][0])); - gtk_clist_insert (GTK_CLIST (clist), i, (char**)text); + for (i = 0; tilesets[i]; i++) { + gchar accelBuf[BUFSZ]; + const char *text[3] = { accelBuf, tilesets[i], NULL }; + sprintf(accelBuf, "%c ", tolower(tilesets[i][0])); + gtk_clist_insert(GTK_CLIST(clist), i, (char **) text); } - - gtk_clist_columns_autosize (GTK_CLIST (clist)); - gtk_widget_show_all (swin); + gtk_clist_columns_autosize(GTK_CLIST(clist)); + gtk_widget_show_all(swin); /* Center the dialog over over parent */ - gnome_dialog_set_default( GNOME_DIALOG(dialog), 0); - gtk_window_set_modal( GTK_WINDOW(dialog), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), - GTK_WINDOW (ghack_get_main_window ()) ); + gnome_dialog_set_default(GNOME_DIALOG(dialog), 0); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gnome_dialog_set_parent(GNOME_DIALOG(dialog), + GTK_WINDOW(ghack_get_main_window())); /* Run the dialog -- returning whichever button was pressed */ - i = gnome_dialog_run (GNOME_DIALOG (dialog)); - gnome_dialog_close (GNOME_DIALOG (dialog)); + i = gnome_dialog_run(GNOME_DIALOG(dialog)); + gnome_dialog_close(GNOME_DIALOG(dialog)); /* They hit Quit or error */ - if (i != 0 ) { - return; + if (i != 0) { + return; } switch (tileset) { - case 0: - /* They selected traditional */ - ghack_free_glyphs(); - if (ghack_init_glyphs(HACKDIR "/x11tiles")) - g_error ("ERROR: Could not initialize glyphs.\n"); - ghack_reinit_map_window(); - break; - case 1: - ghack_free_glyphs(); - if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm")) - g_error ("ERROR: Could not initialize glyphs.\n"); - ghack_reinit_map_window(); + case 0: + /* They selected traditional */ + ghack_free_glyphs(); + if (ghack_init_glyphs(HACKDIR "/x11tiles")) + g_error("ERROR: Could not initialize glyphs.\n"); + ghack_reinit_map_window(); + break; + case 1: + ghack_free_glyphs(); + if (ghack_init_glyphs(HACKDIR "/t32-1024.xpm")) + g_error("ERROR: Could not initialize glyphs.\n"); + ghack_reinit_map_window(); - /* They selected big */ - break; - default: - /* This shouldn't happen */ - g_warning("This shouldn't happen\n"); + /* They selected big */ + break; + default: + /* This shouldn't happen */ + g_warning("This shouldn't happen\n"); } } - diff --git a/win/gnome/gnplayer.c b/win/gnome/gnplayer.c index becd7ed00..8a84efb83 100644 --- a/win/gnome/gnplayer.c +++ b/win/gnome/gnplayer.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnplayer.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnplayer.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 gnplayer.c $Date: 2009/05/06 10:57:42 $ $Revision: 1.6 $ */ /* SCCS Id: @(#)gnplayer.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -11,95 +11,92 @@ #include "hack.h" static gint role_number; -static GtkWidget* clist; +static GtkWidget *clist; static void -player_sel_key_hit (GtkWidget *widget, GdkEventKey *event, gpointer data) +player_sel_key_hit(GtkWidget *widget, GdkEventKey *event, gpointer data) { - const char** roles = data; + const char **roles = data; int i; for (i = 0; roles[i] != 0; ++i) { - if (tolower(roles[i][0]) == tolower(event->keyval)) { - role_number = i; - gtk_clist_select_row( GTK_CLIST (clist), i, 0); - if (gtk_clist_row_is_visible(GTK_CLIST(clist), - i) != GTK_VISIBILITY_FULL) - gtk_clist_moveto(GTK_CLIST(clist), i, 0, 0.5, 0); - } + if (tolower(roles[i][0]) == tolower(event->keyval)) { + role_number = i; + gtk_clist_select_row(GTK_CLIST(clist), i, 0); + if (gtk_clist_row_is_visible(GTK_CLIST(clist), i) + != GTK_VISIBILITY_FULL) + gtk_clist_moveto(GTK_CLIST(clist), i, 0, 0.5, 0); + } } } static void -player_sel_row_selected (GtkCList *clist, int row, int col, GdkEvent *event) +player_sel_row_selected(GtkCList *clist, int row, int col, GdkEvent *event) { role_number = row; } int -ghack_player_sel_dialog(const char** choices, - const gchar* title, - const gchar* prompt) +ghack_player_sel_dialog(const char **choices, const gchar *title, + const gchar *prompt) { int i; - static GtkWidget* dialog; - static GtkWidget* swin; - static GtkWidget* frame1; + static GtkWidget *dialog; + static GtkWidget *swin; + static GtkWidget *frame1; - dialog = gnome_dialog_new(title, - GNOME_STOCK_BUTTON_OK, - _("Random"), - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE); - gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event", - GTK_SIGNAL_FUNC (player_sel_key_hit), choices ); + dialog = gnome_dialog_new(title, GNOME_STOCK_BUTTON_OK, _("Random"), + GNOME_STOCK_BUTTON_CANCEL, NULL); + gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE); + gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event", + GTK_SIGNAL_FUNC(player_sel_key_hit), choices); frame1 = gtk_frame_new(prompt); - gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1); - gtk_widget_show (frame1); - gtk_container_border_width (GTK_CONTAINER (frame1), 3); + gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1); + gtk_widget_show(frame1); + gtk_container_border_width(GTK_CONTAINER(frame1), 3); - swin = gtk_scrolled_window_new (NULL, NULL); - clist = gtk_clist_new (2); - gtk_clist_column_titles_hide (GTK_CLIST (clist)); - gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180); - gtk_container_add (GTK_CONTAINER (swin), clist); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + swin = gtk_scrolled_window_new(NULL, NULL); + clist = gtk_clist_new(2); + gtk_clist_column_titles_hide(GTK_CLIST(clist)); + gtk_widget_set_usize(GTK_WIDGET(clist), 100, 180); + gtk_container_add(GTK_CONTAINER(swin), clist); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); - gtk_signal_connect (GTK_OBJECT (clist), "select_row", - GTK_SIGNAL_FUNC (player_sel_row_selected), NULL ); + gtk_signal_connect(GTK_OBJECT(clist), "select_row", + GTK_SIGNAL_FUNC(player_sel_row_selected), NULL); - gtk_container_add (GTK_CONTAINER (frame1), swin); - gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1); + gtk_container_add(GTK_CONTAINER(frame1), swin); + gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1); /* Add the roles into the list here... */ - for (i=0; choices[i]; i++) { - gchar accelBuf[BUFSZ]; - const char *text[3]={accelBuf, choices[i],NULL}; - sprintf( accelBuf, "%c ", tolower(choices[i][0])); - gtk_clist_insert (GTK_CLIST (clist), i, (char**)text); + for (i = 0; choices[i]; i++) { + gchar accelBuf[BUFSZ]; + const char *text[3] = { accelBuf, choices[i], NULL }; + sprintf(accelBuf, "%c ", tolower(choices[i][0])); + gtk_clist_insert(GTK_CLIST(clist), i, (char **) text); } - gtk_clist_columns_autosize (GTK_CLIST (clist)); - gtk_widget_show_all (swin); + gtk_clist_columns_autosize(GTK_CLIST(clist)); + gtk_widget_show_all(swin); /* Center the dialog over over parent */ - gnome_dialog_set_default( GNOME_DIALOG(dialog), 0); - gtk_window_set_modal( GTK_WINDOW(dialog), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), - GTK_WINDOW (ghack_get_main_window ()) ); + gnome_dialog_set_default(GNOME_DIALOG(dialog), 0); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gnome_dialog_set_parent(GNOME_DIALOG(dialog), + GTK_WINDOW(ghack_get_main_window())); /* Run the dialog -- returning whichever button was pressed */ i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog)); /* Quit on button 2 or error */ - if (i < 0 || i > 1) { - return(ROLE_NONE); + if (i < 0 || i > 1) { + return (ROLE_NONE); } /* Random is button 1*/ - if (i == 1 ) { - return(ROLE_RANDOM); + if (i == 1) { + return (ROLE_RANDOM); } - return ( role_number); + return (role_number); } diff --git a/win/gnome/gnsignal.c b/win/gnome/gnsignal.c index 5bcc5ee6b..4123b1f6b 100644 --- a/win/gnome/gnsignal.c +++ b/win/gnome/gnsignal.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnsignal.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnsignal.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 gnsignal.c $Date: 2009/05/06 10:57:45 $ $Revision: 1.7 $ */ /* SCCS Id: @(#)gnsignal.c 3.5 2005/11/19 */ /* Copyright (C) 1998 by Anthony Taylor */ @@ -10,10 +10,10 @@ GList *g_keyBuffer; GList *g_clickBuffer; -int g_numKeys=0; -int g_numClicks=0; -int g_askingQuestion=0; -static int s_done=FALSE; +int g_numKeys = 0; +int g_numClicks = 0; +int g_askingQuestion = 0; +static int s_done = FALSE; /* * ghack_init_signals @@ -59,161 +59,102 @@ static int s_done=FALSE; */ void -ghack_init_signals( void) +ghack_init_signals(void) { - ghack_signals[GHSIG_CURS] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_curs", - GTK_RUN_FIRST, - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, - 2, - GTK_TYPE_INT, - GTK_TYPE_INT); + ghack_signals[GHSIG_CURS] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_curs", GTK_RUN_FIRST, + gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE, 2, GTK_TYPE_INT, + GTK_TYPE_INT); - ghack_signals[GHSIG_PUTSTR] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_putstr", - GTK_RUN_FIRST, - gtk_marshal_NONE__INT_POINTER, - GTK_TYPE_NONE, - 2, - GTK_TYPE_INT, - GTK_TYPE_POINTER); + ghack_signals[GHSIG_PUTSTR] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_putstr", GTK_RUN_FIRST, + gtk_marshal_NONE__INT_POINTER, GTK_TYPE_NONE, 2, GTK_TYPE_INT, + GTK_TYPE_POINTER); - ghack_signals[GHSIG_PRINT_GLYPH] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_print_glyph", - GTK_RUN_FIRST, - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, - 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_POINTER); + ghack_signals[GHSIG_PRINT_GLYPH] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_print_glyph", + GTK_RUN_FIRST, gtk_marshal_NONE__INT_INT_POINTER, GTK_TYPE_NONE, 3, + GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - ghack_signals[GHSIG_CLEAR] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_clear", - GTK_RUN_FIRST, - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, - 0); - - ghack_signals[GHSIG_DISPLAY] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_display", - GTK_RUN_FIRST, - gtk_marshal_NONE__BOOL, - GTK_TYPE_NONE, - 1, - GTK_TYPE_BOOL); - - ghack_signals[GHSIG_START_MENU] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_start_menu", - GTK_RUN_FIRST, - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, - 0); - - ghack_signals[GHSIG_ADD_MENU] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_add_menu", - GTK_RUN_FIRST, - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, - 1, - GTK_TYPE_POINTER); - - ghack_signals[GHSIG_END_MENU] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_end_menu", - GTK_RUN_FIRST, - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, - 1, - GTK_TYPE_POINTER); - - ghack_signals[GHSIG_SELECT_MENU] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_select_menu", - GTK_RUN_FIRST, - gtk_marshal_NONE__POINTER_INT_POINTER, - GTK_TYPE_NONE, - 3, - GTK_TYPE_POINTER, - GTK_TYPE_INT, - GTK_TYPE_POINTER); - - ghack_signals[GHSIG_CLIPAROUND] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_cliparound", - GTK_RUN_FIRST, - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, - 2, - GTK_TYPE_INT, - GTK_TYPE_INT); + ghack_signals[GHSIG_CLEAR] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_clear", GTK_RUN_FIRST, + gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); - ghack_signals[GHSIG_FADE_HIGHLIGHT] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "ghack_fade_highlight", - GTK_RUN_FIRST, - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, - 0); - - ghack_signals[GHSIG_DELAY] = - gtk_object_class_user_signal_new (gtk_type_class (gtk_widget_get_type ()), - "gnome_delay_output", - GTK_RUN_FIRST, - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, - 1, - GTK_TYPE_INT); - + ghack_signals[GHSIG_DISPLAY] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_display", GTK_RUN_FIRST, + gtk_marshal_NONE__BOOL, GTK_TYPE_NONE, 1, GTK_TYPE_BOOL); + + ghack_signals[GHSIG_START_MENU] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_start_menu", + GTK_RUN_FIRST, gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); + + ghack_signals[GHSIG_ADD_MENU] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_add_menu", + GTK_RUN_FIRST, gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, + GTK_TYPE_POINTER); + + ghack_signals[GHSIG_END_MENU] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_end_menu", + GTK_RUN_FIRST, gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, + GTK_TYPE_POINTER); + + ghack_signals[GHSIG_SELECT_MENU] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_select_menu", + GTK_RUN_FIRST, gtk_marshal_NONE__POINTER_INT_POINTER, GTK_TYPE_NONE, + 3, GTK_TYPE_POINTER, GTK_TYPE_INT, GTK_TYPE_POINTER); + + ghack_signals[GHSIG_CLIPAROUND] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_cliparound", + GTK_RUN_FIRST, gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_INT); + + ghack_signals[GHSIG_FADE_HIGHLIGHT] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "ghack_fade_highlight", + GTK_RUN_FIRST, gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); + + ghack_signals[GHSIG_DELAY] = gtk_object_class_user_signal_new( + gtk_type_class(gtk_widget_get_type()), "gnome_delay_output", + GTK_RUN_FIRST, gtk_marshal_NONE__INT, GTK_TYPE_NONE, 1, GTK_TYPE_INT); } /* For want of a better place, I'm putting the delay output stuff here * -Erik */ -static gint timeout_callback(gpointer data) +static gint +timeout_callback(gpointer data) { - s_done=TRUE; + s_done = TRUE; return FALSE; } void -ghack_delay( GtkWidget *win, int numMillisecs, gpointer data) +ghack_delay(GtkWidget *win, int numMillisecs, gpointer data) { - s_done=FALSE; - gtk_timeout_add( (unsigned int) numMillisecs, - timeout_callback, NULL); - while( s_done==FALSE) - gtk_main_iteration(); + s_done = FALSE; + gtk_timeout_add((unsigned int) numMillisecs, timeout_callback, NULL); + while (s_done == FALSE) + gtk_main_iteration(); } - -void -ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event, - gpointer data) +void +ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event, + gpointer data) { GHClick *click; double x1, y1; if (event->type != GDK_BUTTON_PRESS) - return; - - gnome_canvas_window_to_world( GNOME_CANVAS( widget), event->x, - event->y, &x1, &y1); -/* - g_message("I got a click at %f,%f with button %d \n", - x1, y1, event->button); -*/ + return; + + gnome_canvas_window_to_world(GNOME_CANVAS(widget), event->x, event->y, + &x1, &y1); + /* + g_message("I got a click at %f,%f with button %d \n", + x1, y1, event->button); + */ /* We allocate storage here, so we need to remember if (g_numClicks>0) - * to blow this away when closing the app using something like + * to blow this away when closing the app using something like * while (g_clickBuffer) * { * g_free((GHClick)g_clickBuffer->data); @@ -222,32 +163,31 @@ ghack_handle_button_press(GtkWidget *widget, GdkEventButton *event, * g_list_free( g_clickBuffer ); * */ - click = g_new( GHClick, 1); - - click->x=(int)x1/ghack_glyph_width(); - click->y=(int)y1/ghack_glyph_height(); - click->mod=(event->button == 1)? CLICK_1 : CLICK_2; - - g_clickBuffer = g_list_prepend (g_clickBuffer, click); + click = g_new(GHClick, 1); + + click->x = (int) x1 / ghack_glyph_width(); + click->y = (int) y1 / ghack_glyph_height(); + click->mod = (event->button == 1) ? CLICK_1 : CLICK_2; + + g_clickBuffer = g_list_prepend(g_clickBuffer, click); /* Could use g_list_length(), but it is stupid and just - * traverses the list while counting, so we'll just do + * traverses the list while counting, so we'll just do * the counting ourselves in advance. */ g_numClicks++; } #ifndef M -# ifndef NHSTDC -# define M(c) (0x80 | (c)) -# else -# define M(c) ((c) - 128) -# endif /* NHSTDC */ +#ifndef NHSTDC +#define M(c) (0x80 | (c)) +#else +#define M(c) ((c) -128) +#endif /* NHSTDC */ #endif #ifndef C -#define C(c) (0x1f & (c)) +#define C(c) (0x1f & (c)) #endif - -void +void ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) { static int was_pound = 0; @@ -255,7 +195,7 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) int ctl = GDK_CONTROL_MASK; int alt = GDK_MOD1_MASK; - /* Turn this on to debug key events */ +/* Turn this on to debug key events */ #if 0 g_message("I got a \"%s\" key (%d) %s%s", gdk_keyval_name (event->keyval), event->keyval, @@ -263,118 +203,136 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) #endif switch (event->keyval) { - /* special keys to do stuff with */ + /* special keys to do stuff with */ - /* Set up the direction keys */ + /* Set up the direction keys */ - /* First handle the arrow keys -- these always mean move */ + /* First handle the arrow keys -- these always mean move */ case GDK_Right: case GDK_rightarrow: - key = Cmd.move_E; break; + key = Cmd.move_E; + break; case GDK_Left: case GDK_leftarrow: - key = Cmd.move_W; break; + key = Cmd.move_W; + break; case GDK_Up: case GDK_uparrow: - key = Cmd.move_N; break; + key = Cmd.move_N; + break; case GDK_Down: case GDK_downarrow: - key = Cmd.move_S; break; + key = Cmd.move_S; + break; case GDK_Home: - key = Cmd.move_NW; break; + key = Cmd.move_NW; + break; case GDK_End: - key = Cmd.move_SW; break; + key = Cmd.move_SW; + break; case GDK_Page_Down: - key = Cmd.move_SE; break; + key = Cmd.move_SE; + break; case GDK_Page_Up: - key = Cmd.move_NE; break; - case ' ': key='.'; break; + key = Cmd.move_NE; + break; + case ' ': + key = '.'; + break; - /* Now, handle the numberpad (move or numbers) */ + /* Now, handle the numberpad (move or numbers) */ case GDK_KP_Right: case GDK_KP_6: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_6; - else - key='6'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_6; + else + key = '6'; + break; case GDK_KP_Left: case GDK_KP_4: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_4; - else - key='4'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_4; + else + key = '4'; + break; case GDK_KP_Up: case GDK_KP_8: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_8; - else - key='8'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_8; + else + key = '8'; + break; case GDK_KP_Down: case GDK_KP_2: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_2; - else - key='2'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_2; + else + key = '2'; + break; - /* Move Top-Left */ + /* Move Top-Left */ case GDK_KP_Home: case GDK_KP_7: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_7; - else - key='7'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_7; + else + key = '7'; + break; case GDK_KP_Page_Up: case GDK_KP_9: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_9; - else - key='9'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_9; + else + key = '9'; + break; case GDK_KP_End: case GDK_KP_1: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_1; - else - key='1'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_1; + else + key = '1'; + break; case GDK_KP_Page_Down: case GDK_KP_3: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_3; - else - key='3'; - break; - - + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_3; + else + key = '3'; + break; + case GDK_KP_5: - if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && iflags.num_pad) - key = GDK_KP_5; - else - key='5'; - break; + if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) + && iflags.num_pad) + key = GDK_KP_5; + else + key = '5'; + break; case GDK_KP_Delete: case GDK_KP_Decimal: - key='.'; - break; + key = '.'; + break; - /* can't just ignore "#", it's a core feature */ + /* can't just ignore "#", it's a core feature */ case GDK_numbersign: - key='#'; - break; + key = '#'; + break; - /* We will probably want to do something with these later... */ + /* We will probably want to do something with these later... */ case GDK_KP_Begin: case GDK_KP_F1: case GDK_F1: @@ -392,8 +350,8 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) case GDK_F10: case GDK_F11: case GDK_F12: - break; - /* various keys to ignore */ + break; + /* various keys to ignore */ case GDK_KP_Insert: case GDK_Insert: case GDK_Delete: @@ -414,31 +372,30 @@ ghack_handle_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) case GDK_Meta_R: case GDK_Mode_switch: case GDK_Multi_key: - return; + return; default: - key = event->keyval; - break; + key = event->keyval; + break; } if ((event->state & alt) || was_pound) { - key=M(event->keyval); + key = M(event->keyval); } else if (event->state & ctl) { - key=C(event->keyval); + key = C(event->keyval); } if (was_pound) { - was_pound = 0; + was_pound = 0; } - + /* Ok, here is where we do clever stuff to overide the default * game behavior */ if (g_askingQuestion == 0) { - - if (key == 'S' || key == M('S') || key == C('S')) { - ghack_save_game_cb( NULL, NULL); - return; - } + if (key == 'S' || key == M('S') || key == C('S')) { + ghack_save_game_cb(NULL, NULL); + return; + } } - g_keyBuffer = g_list_prepend (g_keyBuffer, GINT_TO_POINTER( key)); + g_keyBuffer = g_list_prepend(g_keyBuffer, GINT_TO_POINTER(key)); g_numKeys++; } diff --git a/win/gnome/gnstatus.c b/win/gnome/gnstatus.c index b3a800460..8d0a54d4e 100644 --- a/win/gnome/gnstatus.c +++ b/win/gnome/gnstatus.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnstatus.c $NHDT-Date: 1425083083 2015/02/28 00:24:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */ +/* NetHack 3.6 gnstatus.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* NetHack 3.6 gnstatus.c $Date: 2009/05/06 10:57:54 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)gnstatus.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -9,84 +9,84 @@ #include "gn_xpms.h" #include "gnomeprv.h" - -extern const char *hu_stat[]; /* from eat.c */ +extern const char *hu_stat[]; /* from eat.c */ extern const char *enc_stat[]; /* from botl.c */ void ghack_status_window_update_stats(); void ghack_status_window_clear(GtkWidget *win, gpointer data); void ghack_status_window_destroy(GtkWidget *win, gpointer data); -void ghack_status_window_display(GtkWidget *win, boolean block, gpointer data); -void ghack_status_window_cursor_to(GtkWidget *win, int x, int y, gpointer data); -void ghack_status_window_put_string(GtkWidget *win, int attr, const char* text, gpointer data); +void ghack_status_window_display(GtkWidget *win, boolean block, + gpointer data); +void ghack_status_window_cursor_to(GtkWidget *win, int x, int y, + gpointer data); +void ghack_status_window_put_string(GtkWidget *win, int attr, + const char *text, gpointer data); static void ghack_fade_highlighting(); -static void ghack_highlight_widget( GtkWidget* widget, GtkStyle* oldStyle, - GtkStyle* newStyle); +static void ghack_highlight_widget(GtkWidget *widget, GtkStyle *oldStyle, + GtkStyle *newStyle); /* some junk to handle when to fade the highlighting */ -#define NUM_TURNS_HIGHLIGHTED 3 +#define NUM_TURNS_HIGHLIGHTED 3 -static GList *s_HighLightList; +static GList *s_HighLightList; typedef struct { - GtkWidget* widget; - GtkStyle* oldStyle; - int nTurnsLeft; + GtkWidget *widget; + GtkStyle *oldStyle; + int nTurnsLeft; } Highlight; - /* Ok, now for a LONG list of widgets... */ -static GtkWidget* statTable = NULL; -static GtkWidget* titleLabel = NULL; -static GtkWidget* dgnLevelLabel = NULL; -static GtkWidget* strPix = NULL; -static GtkWidget* strLabel = NULL; -static GtkWidget* dexPix = NULL; -static GtkWidget* dexLabel = NULL; -static GtkWidget* intPix = NULL; -static GtkWidget* intLabel = NULL; -static GtkWidget* wisPix = NULL; -static GtkWidget* wisLabel = NULL; -static GtkWidget* conPix = NULL; -static GtkWidget* conLabel = NULL; -static GtkWidget* chaPix = NULL; -static GtkWidget* chaLabel = NULL; -static GtkWidget* goldLabel = NULL; -static GtkWidget* hpLabel = NULL; -static GtkWidget* powLabel = NULL; -static GtkWidget* acLabel = NULL; -static GtkWidget* levlLabel = NULL; -static GtkWidget* expLabel = NULL; -static GtkWidget* timeLabel = NULL; -static GtkWidget* scoreLabel = NULL; -static GtkWidget* alignPix = NULL; -static GtkWidget* alignLabel = NULL; -static GtkWidget* hungerPix = NULL; -static GtkWidget* hungerLabel = NULL; -static GtkWidget* sickPix = NULL; -static GtkWidget* sickLabel = NULL; -static GtkWidget* blindPix = NULL; -static GtkWidget* blindLabel = NULL; -static GtkWidget* stunPix = NULL; -static GtkWidget* stunLabel = NULL; -static GtkWidget* halluPix = NULL; -static GtkWidget* halluLabel = NULL; -static GtkWidget* confuPix = NULL; -static GtkWidget* confuLabel = NULL; -static GtkWidget* encumbPix = NULL; -static GtkWidget* encumbLabel = NULL; +static GtkWidget *statTable = NULL; +static GtkWidget *titleLabel = NULL; +static GtkWidget *dgnLevelLabel = NULL; +static GtkWidget *strPix = NULL; +static GtkWidget *strLabel = NULL; +static GtkWidget *dexPix = NULL; +static GtkWidget *dexLabel = NULL; +static GtkWidget *intPix = NULL; +static GtkWidget *intLabel = NULL; +static GtkWidget *wisPix = NULL; +static GtkWidget *wisLabel = NULL; +static GtkWidget *conPix = NULL; +static GtkWidget *conLabel = NULL; +static GtkWidget *chaPix = NULL; +static GtkWidget *chaLabel = NULL; +static GtkWidget *goldLabel = NULL; +static GtkWidget *hpLabel = NULL; +static GtkWidget *powLabel = NULL; +static GtkWidget *acLabel = NULL; +static GtkWidget *levlLabel = NULL; +static GtkWidget *expLabel = NULL; +static GtkWidget *timeLabel = NULL; +static GtkWidget *scoreLabel = NULL; +static GtkWidget *alignPix = NULL; +static GtkWidget *alignLabel = NULL; +static GtkWidget *hungerPix = NULL; +static GtkWidget *hungerLabel = NULL; +static GtkWidget *sickPix = NULL; +static GtkWidget *sickLabel = NULL; +static GtkWidget *blindPix = NULL; +static GtkWidget *blindLabel = NULL; +static GtkWidget *stunPix = NULL; +static GtkWidget *stunLabel = NULL; +static GtkWidget *halluPix = NULL; +static GtkWidget *halluLabel = NULL; +static GtkWidget *confuPix = NULL; +static GtkWidget *confuLabel = NULL; +static GtkWidget *encumbPix = NULL; +static GtkWidget *encumbLabel = NULL; - -static GtkStyle* normalStyle = NULL; -static GtkStyle* bigStyle = NULL; -static GtkStyle* redStyle = NULL; -static GtkStyle* greenStyle = NULL; -static GtkStyle* bigRedStyle = NULL; -static GtkStyle* bigGreenStyle = NULL; +static GtkStyle *normalStyle = NULL; +static GtkStyle *bigStyle = NULL; +static GtkStyle *redStyle = NULL; +static GtkStyle *greenStyle = NULL; +static GtkStyle *bigRedStyle = NULL; +static GtkStyle *bigGreenStyle = NULL; /* Pure red */ -static GdkColor color_red = { 0, 0xff00, 0, 0 }; +static GdkColor color_red = { 0, 0xff00, 0, 0 }; /* ForestGreen (looks better than just pure green) */ static GdkColor color_green = { 0, 0x2200, 0x8b00, 0x2200 }; @@ -105,7 +105,7 @@ static int lastPOW; static int lastMPOW; static int lastAC; static int lastExp; -static aligntyp lastAlignment; +static aligntyp lastAlignment; static unsigned lastHungr; static long lastConf; static long lastBlind; @@ -114,45 +114,50 @@ static long lastHalu; static long lastSick; static int lastEncumb; -void ghack_status_window_clear( GtkWidget *win, gpointer data) +void +ghack_status_window_clear(GtkWidget *win, gpointer data) { /* Don't think we need this at all */ } -void ghack_status_window_destroy(GtkWidget *win, gpointer data) +void +ghack_status_window_destroy(GtkWidget *win, gpointer data) { while (s_HighLightList) { - g_free( (Highlight*)s_HighLightList->data); - s_HighLightList = s_HighLightList->next; + g_free((Highlight *) s_HighLightList->data); + s_HighLightList = s_HighLightList->next; } - g_list_free( s_HighLightList ); + g_list_free(s_HighLightList); } -void ghack_status_window_display( GtkWidget *win, boolean block, gpointer data) +void +ghack_status_window_display(GtkWidget *win, boolean block, gpointer data) { - gtk_widget_show_all( GTK_WIDGET(win)); + gtk_widget_show_all(GTK_WIDGET(win)); } -void ghack_status_window_cursor_to( GtkWidget *win, int x, int y, gpointer data) +void +ghack_status_window_cursor_to(GtkWidget *win, int x, int y, gpointer data) { /* Don't think we need this at all */ } -void ghack_status_window_put_string( GtkWidget *win, int attr, const char* text, gpointer data) +void +ghack_status_window_put_string(GtkWidget *win, int attr, const char *text, + gpointer data) { ghack_status_window_update_stats(); } - - -GtkWidget* ghack_init_status_window () +GtkWidget * +ghack_init_status_window() { GtkWidget *horizSep0, *horizSep1, *horizSep2, *horizSep3; GtkWidget *statsHBox, *strVBox, *dexVBox, *intVBox, *statHBox; GtkWidget *wisVBox, *conVBox, *chaVBox; GtkWidget *alignVBox, *hungerVBox, *sickVBox, *blindVBox; GtkWidget *stunVBox, *halluVBox, *confuVBox, *encumbVBox; - + /* Set up a (ridiculous) initial state */ lastDepth = 9999; lastStr = 9999; @@ -169,7 +174,7 @@ GtkWidget* ghack_init_status_window () lastMPOW = 9999; lastAC = 9999; lastExp = 9999; - lastAlignment = A_NEUTRAL; /* start off guessing neutral */ + lastAlignment = A_NEUTRAL; /* start off guessing neutral */ lastHungr = 9999; lastConf = 9999; lastBlind = 9999; @@ -178,277 +183,277 @@ GtkWidget* ghack_init_status_window () lastSick = 9999; lastEncumb = 9999; - statTable = gtk_table_new( 10, 8, FALSE); - gtk_table_set_row_spacings( GTK_TABLE( statTable), 1); - gtk_table_set_col_spacings( GTK_TABLE( statTable), 1); - + statTable = gtk_table_new(10, 8, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(statTable), 1); + gtk_table_set_col_spacings(GTK_TABLE(statTable), 1); /* Begin the first row of the table -- the title */ - titleLabel = gtk_label_new( _("GnomeHack!")); - gtk_table_attach( GTK_TABLE( statTable), titleLabel, - 0, 8, 0, 1, GTK_FILL, 0, 0, 0); + titleLabel = gtk_label_new(_("GnomeHack!")); + gtk_table_attach(GTK_TABLE(statTable), titleLabel, 0, 8, 0, 1, GTK_FILL, + 0, 0, 0); if (!normalStyle) - normalStyle = gtk_style_copy ( - gtk_widget_get_style (GTK_WIDGET (titleLabel))); + normalStyle = + gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(titleLabel))); /* Set up some styles to draw stuff with */ if (!redStyle) { - g_assert (greenStyle == NULL); - g_assert (bigStyle == NULL); - g_assert (bigRedStyle == NULL); - g_assert (bigGreenStyle == NULL); + g_assert(greenStyle == NULL); + g_assert(bigStyle == NULL); + g_assert(bigRedStyle == NULL); + g_assert(bigGreenStyle == NULL); - greenStyle = gtk_style_copy (normalStyle); - redStyle = gtk_style_copy (normalStyle); - bigRedStyle = gtk_style_copy (normalStyle); - bigGreenStyle = gtk_style_copy (normalStyle); - bigStyle = gtk_style_copy (normalStyle); + greenStyle = gtk_style_copy(normalStyle); + redStyle = gtk_style_copy(normalStyle); + bigRedStyle = gtk_style_copy(normalStyle); + bigGreenStyle = gtk_style_copy(normalStyle); + bigStyle = gtk_style_copy(normalStyle); - greenStyle->fg[GTK_STATE_NORMAL] = color_green; - redStyle->fg[GTK_STATE_NORMAL] = color_red; - bigRedStyle->fg[GTK_STATE_NORMAL] = color_red; - bigGreenStyle->fg[GTK_STATE_NORMAL] = color_green; + greenStyle->fg[GTK_STATE_NORMAL] = color_green; + redStyle->fg[GTK_STATE_NORMAL] = color_red; + bigRedStyle->fg[GTK_STATE_NORMAL] = color_red; + bigGreenStyle->fg[GTK_STATE_NORMAL] = color_green; - gdk_font_unref (bigRedStyle->font); - gdk_font_unref (bigGreenStyle->font); - bigRedStyle->font = gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); - bigGreenStyle->font = gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); + gdk_font_unref(bigRedStyle->font); + gdk_font_unref(bigGreenStyle->font); + bigRedStyle->font = + gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); + bigGreenStyle->font = + gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); - gdk_font_unref (bigStyle->font); - bigStyle->font = gdk_font_load ("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); + gdk_font_unref(bigStyle->font); + bigStyle->font = + gdk_font_load("-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); } - gtk_widget_set_style (GTK_WIDGET (titleLabel), bigStyle); - - /* Begin the second row */ - dgnLevelLabel = gtk_label_new (_ ("Nethack for Gnome")); - gtk_table_attach (GTK_TABLE (statTable), dgnLevelLabel, - 0, 8, 1, 2, GTK_FILL, 0, 0, 0); - gtk_widget_set_style (GTK_WIDGET (dgnLevelLabel), bigStyle); - - /* Begin the third row */ - horizSep0 = gtk_hseparator_new (); - gtk_table_attach (GTK_TABLE (statTable), horizSep0, - 0, 8, 2, 3, GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_set_style(GTK_WIDGET(titleLabel), bigStyle); + /* Begin the second row */ + dgnLevelLabel = gtk_label_new(_("Nethack for Gnome")); + gtk_table_attach(GTK_TABLE(statTable), dgnLevelLabel, 0, 8, 1, 2, + GTK_FILL, 0, 0, 0); + gtk_widget_set_style(GTK_WIDGET(dgnLevelLabel), bigStyle); + + /* Begin the third row */ + horizSep0 = gtk_hseparator_new(); + gtk_table_attach(GTK_TABLE(statTable), horizSep0, 0, 8, 2, 3, GTK_FILL, + GTK_FILL, 0, 0); /* Begin the fourth row */ - statsHBox = gtk_hbox_new (TRUE, 0); + statsHBox = gtk_hbox_new(TRUE, 0); - strVBox = gtk_vbox_new (FALSE, 0); - strPix = gnome_pixmap_new_from_xpm_d( str_xpm); - strLabel = gtk_label_new( "STR: "); - gtk_box_pack_start (GTK_BOX (strVBox), strPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (strVBox), strLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(strVBox), TRUE, TRUE, 2); + strVBox = gtk_vbox_new(FALSE, 0); + strPix = gnome_pixmap_new_from_xpm_d(str_xpm); + strLabel = gtk_label_new("STR: "); + gtk_box_pack_start(GTK_BOX(strVBox), strPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(strVBox), strLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(strVBox), TRUE, TRUE, + 2); - dexVBox = gtk_vbox_new (FALSE, 0); - dexPix = gnome_pixmap_new_from_xpm_d( dex_xpm); - dexLabel = gtk_label_new( "DEX: "); - gtk_box_pack_start (GTK_BOX (dexVBox), dexPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (dexVBox), dexLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(dexVBox), TRUE, TRUE, 2); + dexVBox = gtk_vbox_new(FALSE, 0); + dexPix = gnome_pixmap_new_from_xpm_d(dex_xpm); + dexLabel = gtk_label_new("DEX: "); + gtk_box_pack_start(GTK_BOX(dexVBox), dexPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(dexVBox), dexLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(dexVBox), TRUE, TRUE, + 2); - conVBox = gtk_vbox_new (FALSE, 0); - conPix = gnome_pixmap_new_from_xpm_d( cns_xpm); - conLabel = gtk_label_new( "CON: "); - gtk_box_pack_start (GTK_BOX (conVBox), conPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (conVBox), conLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(conVBox), TRUE, TRUE, 2); + conVBox = gtk_vbox_new(FALSE, 0); + conPix = gnome_pixmap_new_from_xpm_d(cns_xpm); + conLabel = gtk_label_new("CON: "); + gtk_box_pack_start(GTK_BOX(conVBox), conPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(conVBox), conLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(conVBox), TRUE, TRUE, + 2); - intVBox = gtk_vbox_new (FALSE, 0); - intPix = gnome_pixmap_new_from_xpm_d( int_xpm); - intLabel = gtk_label_new( "INT: "); - gtk_box_pack_start (GTK_BOX (intVBox), intPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (intVBox), intLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(intVBox), TRUE, TRUE, 2); + intVBox = gtk_vbox_new(FALSE, 0); + intPix = gnome_pixmap_new_from_xpm_d(int_xpm); + intLabel = gtk_label_new("INT: "); + gtk_box_pack_start(GTK_BOX(intVBox), intPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(intVBox), intLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(intVBox), TRUE, TRUE, + 2); + wisVBox = gtk_vbox_new(FALSE, 0); + wisPix = gnome_pixmap_new_from_xpm_d(wis_xpm); + wisLabel = gtk_label_new("WIS: "); + gtk_box_pack_start(GTK_BOX(wisVBox), wisPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(wisVBox), wisLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(wisVBox), TRUE, TRUE, + 2); - wisVBox = gtk_vbox_new (FALSE, 0); - wisPix = gnome_pixmap_new_from_xpm_d( wis_xpm); - wisLabel = gtk_label_new( "WIS: "); - gtk_box_pack_start (GTK_BOX (wisVBox), wisPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (wisVBox), wisLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(wisVBox), TRUE, TRUE, 2); + chaVBox = gtk_vbox_new(FALSE, 0); + chaPix = gnome_pixmap_new_from_xpm_d(cha_xpm); + chaLabel = gtk_label_new("CHA: "); + gtk_box_pack_start(GTK_BOX(chaVBox), chaPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(chaVBox), chaLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statsHBox), GTK_WIDGET(chaVBox), TRUE, TRUE, + 2); - - chaVBox = gtk_vbox_new (FALSE, 0); - chaPix = gnome_pixmap_new_from_xpm_d( cha_xpm); - chaLabel = gtk_label_new( "CHA: "); - gtk_box_pack_start (GTK_BOX (chaVBox), chaPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (chaVBox), chaLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statsHBox), GTK_WIDGET(chaVBox), TRUE, TRUE, 2); - - gtk_table_attach( GTK_TABLE( statTable), GTK_WIDGET(statsHBox), - 0, 8, 3, 4, GTK_FILL, 0, 0, 0); + gtk_table_attach(GTK_TABLE(statTable), GTK_WIDGET(statsHBox), 0, 8, 3, 4, + GTK_FILL, 0, 0, 0); /* Begin the fifth row */ - horizSep1 = gtk_hseparator_new(); - gtk_table_attach( GTK_TABLE( statTable), horizSep1, - 0, 8, 4, 5, GTK_FILL, GTK_FILL, 0, 0); + horizSep1 = gtk_hseparator_new(); + gtk_table_attach(GTK_TABLE(statTable), horizSep1, 0, 8, 4, 5, GTK_FILL, + GTK_FILL, 0, 0); /* Begin the sixth row */ - hpLabel = gtk_label_new( "HP: "); - gtk_table_attach( GTK_TABLE( statTable), hpLabel, - 0, 1, 5, 6, GTK_FILL, 0, 0, 0); - - acLabel = gtk_label_new( "AC: "); - gtk_table_attach( GTK_TABLE( statTable), acLabel, - 2, 3, 5, 6, GTK_FILL, 0, 0, 0); - - powLabel = gtk_label_new( "Power: "); - gtk_table_attach( GTK_TABLE( statTable), powLabel, - 4, 5, 5, 6, GTK_FILL, 0, 0, 0); - - goldLabel = gtk_label_new( "Au: "); - gtk_table_attach( GTK_TABLE( statTable), goldLabel, - 6, 7, 5, 6, GTK_FILL, 0, 0, 0); - + hpLabel = gtk_label_new("HP: "); + gtk_table_attach(GTK_TABLE(statTable), hpLabel, 0, 1, 5, 6, GTK_FILL, 0, + 0, 0); + + acLabel = gtk_label_new("AC: "); + gtk_table_attach(GTK_TABLE(statTable), acLabel, 2, 3, 5, 6, GTK_FILL, 0, + 0, 0); + + powLabel = gtk_label_new("Power: "); + gtk_table_attach(GTK_TABLE(statTable), powLabel, 4, 5, 5, 6, GTK_FILL, 0, + 0, 0); + + goldLabel = gtk_label_new("Au: "); + gtk_table_attach(GTK_TABLE(statTable), goldLabel, 6, 7, 5, 6, GTK_FILL, 0, + 0, 0); /* Begin the seventh row */ - horizSep2 = gtk_hseparator_new(); - gtk_table_attach( GTK_TABLE( statTable), horizSep2, - 0, 8, 6, 7, GTK_FILL, GTK_FILL, 0, 0); + horizSep2 = gtk_hseparator_new(); + gtk_table_attach(GTK_TABLE(statTable), horizSep2, 0, 8, 6, 7, GTK_FILL, + GTK_FILL, 0, 0); - /* Begin the eigth row */ - levlLabel = gtk_label_new( "Level: "); - gtk_table_attach( GTK_TABLE( statTable), levlLabel, - 0, 1, 7, 8, GTK_FILL, 0, 0, 0); - - expLabel = gtk_label_new( "Exp: "); - gtk_table_attach( GTK_TABLE( statTable), expLabel, - 2, 3, 7, 8, GTK_FILL, 0, 0, 0); - - timeLabel = gtk_label_new( "Time: "); - gtk_table_attach( GTK_TABLE( statTable), timeLabel, - 4, 5, 7, 8, GTK_FILL, 0, 0, 0); - - scoreLabel = gtk_label_new( "Score: "); - gtk_table_attach( GTK_TABLE( statTable), scoreLabel, - 6, 7, 7, 8, GTK_FILL, 0, 0, 0); - + levlLabel = gtk_label_new("Level: "); + gtk_table_attach(GTK_TABLE(statTable), levlLabel, 0, 1, 7, 8, GTK_FILL, 0, + 0, 0); + + expLabel = gtk_label_new("Exp: "); + gtk_table_attach(GTK_TABLE(statTable), expLabel, 2, 3, 7, 8, GTK_FILL, 0, + 0, 0); + + timeLabel = gtk_label_new("Time: "); + gtk_table_attach(GTK_TABLE(statTable), timeLabel, 4, 5, 7, 8, GTK_FILL, 0, + 0, 0); + + scoreLabel = gtk_label_new("Score: "); + gtk_table_attach(GTK_TABLE(statTable), scoreLabel, 6, 7, 7, 8, GTK_FILL, + 0, 0, 0); + /* Begin the ninth row */ - horizSep3 = gtk_hseparator_new(); - gtk_table_attach( GTK_TABLE( statTable), horizSep3, - 0, 8, 8, 9, GTK_FILL, GTK_FILL, 0, 0); - + horizSep3 = gtk_hseparator_new(); + gtk_table_attach(GTK_TABLE(statTable), horizSep3, 0, 8, 8, 9, GTK_FILL, + GTK_FILL, 0, 0); + /* Begin the tenth and last row */ - statHBox = gtk_hbox_new (FALSE, 0); + statHBox = gtk_hbox_new(FALSE, 0); - alignVBox = gtk_vbox_new (FALSE, 0); - alignPix = gnome_pixmap_new_from_xpm_d( neutral_xpm); - alignLabel = gtk_label_new( "Neutral"); - gtk_box_pack_start (GTK_BOX (alignVBox), alignPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (alignVBox), alignLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(alignVBox), TRUE, FALSE, 2); - - hungerVBox = gtk_vbox_new (FALSE, 0); - hungerPix = gnome_pixmap_new_from_xpm_d( hungry_xpm); - hungerLabel = gtk_label_new( "Hungry"); - gtk_box_pack_start (GTK_BOX (hungerVBox), hungerPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (hungerVBox), hungerLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(hungerVBox), TRUE, FALSE, 2); - - sickVBox = gtk_vbox_new (FALSE, 0); - sickPix = gnome_pixmap_new_from_xpm_d( sick_fp_xpm); - sickLabel = gtk_label_new( "FoodPois"); - gtk_box_pack_start (GTK_BOX (sickVBox), sickPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (sickVBox), sickLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(sickVBox), TRUE, FALSE, 2); - - blindVBox = gtk_vbox_new (FALSE, 0); - blindPix = gnome_pixmap_new_from_xpm_d( blind_xpm); - blindLabel = gtk_label_new( "Blind"); - gtk_box_pack_start (GTK_BOX (blindVBox), blindPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (blindVBox), blindLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(blindVBox), TRUE, FALSE, 2); - - stunVBox = gtk_vbox_new (FALSE, 0); - stunPix = gnome_pixmap_new_from_xpm_d( stunned_xpm); - stunLabel = gtk_label_new( "Stun"); - gtk_box_pack_start (GTK_BOX (stunVBox), stunPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (stunVBox), stunLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(stunVBox), TRUE, FALSE, 2); - - confuVBox = gtk_vbox_new (FALSE, 0); - confuPix = gnome_pixmap_new_from_xpm_d( confused_xpm); - confuLabel = gtk_label_new( "Confused"); - gtk_box_pack_start (GTK_BOX (confuVBox), confuPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (confuVBox), confuLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(confuVBox), TRUE, FALSE, 2); - - halluVBox = gtk_vbox_new (FALSE, 0); - halluPix = gnome_pixmap_new_from_xpm_d( hallu_xpm); - halluLabel = gtk_label_new( "Hallu"); - gtk_box_pack_start (GTK_BOX (halluVBox), halluPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (halluVBox), halluLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(halluVBox), TRUE, FALSE, 2); - - encumbVBox = gtk_vbox_new (FALSE, 0); - encumbPix = gnome_pixmap_new_from_xpm_d( slt_enc_xpm); - encumbLabel = gtk_label_new( "Burdened"); - gtk_box_pack_start (GTK_BOX (encumbVBox), encumbPix, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (encumbVBox), encumbLabel, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX(statHBox), GTK_WIDGET(encumbVBox), TRUE, FALSE, 2); + alignVBox = gtk_vbox_new(FALSE, 0); + alignPix = gnome_pixmap_new_from_xpm_d(neutral_xpm); + alignLabel = gtk_label_new("Neutral"); + gtk_box_pack_start(GTK_BOX(alignVBox), alignPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(alignVBox), alignLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(alignVBox), TRUE, FALSE, + 2); + + hungerVBox = gtk_vbox_new(FALSE, 0); + hungerPix = gnome_pixmap_new_from_xpm_d(hungry_xpm); + hungerLabel = gtk_label_new("Hungry"); + gtk_box_pack_start(GTK_BOX(hungerVBox), hungerPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(hungerVBox), hungerLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(hungerVBox), TRUE, FALSE, + 2); + + sickVBox = gtk_vbox_new(FALSE, 0); + sickPix = gnome_pixmap_new_from_xpm_d(sick_fp_xpm); + sickLabel = gtk_label_new("FoodPois"); + gtk_box_pack_start(GTK_BOX(sickVBox), sickPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(sickVBox), sickLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(sickVBox), TRUE, FALSE, + 2); + + blindVBox = gtk_vbox_new(FALSE, 0); + blindPix = gnome_pixmap_new_from_xpm_d(blind_xpm); + blindLabel = gtk_label_new("Blind"); + gtk_box_pack_start(GTK_BOX(blindVBox), blindPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(blindVBox), blindLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(blindVBox), TRUE, FALSE, + 2); + + stunVBox = gtk_vbox_new(FALSE, 0); + stunPix = gnome_pixmap_new_from_xpm_d(stunned_xpm); + stunLabel = gtk_label_new("Stun"); + gtk_box_pack_start(GTK_BOX(stunVBox), stunPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(stunVBox), stunLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(stunVBox), TRUE, FALSE, + 2); + + confuVBox = gtk_vbox_new(FALSE, 0); + confuPix = gnome_pixmap_new_from_xpm_d(confused_xpm); + confuLabel = gtk_label_new("Confused"); + gtk_box_pack_start(GTK_BOX(confuVBox), confuPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(confuVBox), confuLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(confuVBox), TRUE, FALSE, + 2); + + halluVBox = gtk_vbox_new(FALSE, 0); + halluPix = gnome_pixmap_new_from_xpm_d(hallu_xpm); + halluLabel = gtk_label_new("Hallu"); + gtk_box_pack_start(GTK_BOX(halluVBox), halluPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(halluVBox), halluLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(halluVBox), TRUE, FALSE, + 2); + + encumbVBox = gtk_vbox_new(FALSE, 0); + encumbPix = gnome_pixmap_new_from_xpm_d(slt_enc_xpm); + encumbLabel = gtk_label_new("Burdened"); + gtk_box_pack_start(GTK_BOX(encumbVBox), encumbPix, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(encumbVBox), encumbLabel, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(statHBox), GTK_WIDGET(encumbVBox), TRUE, FALSE, + 2); + + gtk_table_attach(GTK_TABLE(statTable), GTK_WIDGET(statHBox), 0, 8, 9, 10, + GTK_FILL, GTK_FILL, 0, 0); - gtk_table_attach( GTK_TABLE( statTable), GTK_WIDGET(statHBox), - 0, 8, 9, 10, GTK_FILL, GTK_FILL, 0, 0); - /* Set up the necessary signals */ - gtk_signal_connect (GTK_OBJECT (statTable), - "ghack_fade_highlight", - GTK_SIGNAL_FUNC (ghack_fade_highlighting), - NULL); + gtk_signal_connect(GTK_OBJECT(statTable), "ghack_fade_highlight", + GTK_SIGNAL_FUNC(ghack_fade_highlighting), NULL); - gtk_signal_connect (GTK_OBJECT (statTable), - "ghack_putstr", - GTK_SIGNAL_FUNC (ghack_status_window_put_string), - NULL); + gtk_signal_connect(GTK_OBJECT(statTable), "ghack_putstr", + GTK_SIGNAL_FUNC(ghack_status_window_put_string), NULL); - gtk_signal_connect (GTK_OBJECT (statTable), - "ghack_clear", - GTK_SIGNAL_FUNC (ghack_status_window_clear), - NULL); + gtk_signal_connect(GTK_OBJECT(statTable), "ghack_clear", + GTK_SIGNAL_FUNC(ghack_status_window_clear), NULL); - gtk_signal_connect (GTK_OBJECT (statTable), - "ghack_curs", - GTK_SIGNAL_FUNC (ghack_status_window_cursor_to), - NULL); - gtk_signal_connect(GTK_OBJECT (statTable), - "gnome_delay_output", - GTK_SIGNAL_FUNC(ghack_delay), - NULL); + gtk_signal_connect(GTK_OBJECT(statTable), "ghack_curs", + GTK_SIGNAL_FUNC(ghack_status_window_cursor_to), NULL); + gtk_signal_connect(GTK_OBJECT(statTable), "gnome_delay_output", + GTK_SIGNAL_FUNC(ghack_delay), NULL); /* Lastly, show the status window and everything in it */ - gtk_widget_show_all( statTable); + gtk_widget_show_all(statTable); return GTK_WIDGET(statTable); } - - -void ghack_status_window_update_stats() +void +ghack_status_window_update_stats() { char buf[BUFSZ]; gchar *buf1; - const char* hung; - const char* enc; - static int firstTime=TRUE; + const char *hung; + const char *enc; + static int firstTime = TRUE; long umoney; /* First, fill in the player name and the dungeon level */ strcpy(buf, plname); - if ('a' <= buf[0] && buf[0] <= 'z') buf[0] += 'A'-'a'; + if ('a' <= buf[0] && buf[0] <= 'z') + buf[0] += 'A' - 'a'; strcat(buf, " the "); if (u.mtimedone) { char mname[BUFSZ]; int k = 0; strcpy(mname, mons[u.umonnum].mname); - while(mname[k] != 0) { - if ((k == 0 || (k > 0 && mname[k-1] == ' ')) - && 'a' <= mname[k] && mname[k] <= 'z') - { + while (mname[k] != 0) { + if ((k == 0 || (k > 0 && mname[k - 1] == ' ')) && 'a' <= mname[k] + && mname[k] <= 'z') { mname[k] += 'A' - 'a'; } k++; @@ -457,470 +462,449 @@ void ghack_status_window_update_stats() } else { strcat(buf, rank_of(u.ulevel, pl_character[0], flags.female)); } - gtk_label_get( GTK_LABEL( titleLabel), &buf1); - if (strcmp( buf1, buf) != 0 && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( titleLabel, bigStyle, bigGreenStyle); + gtk_label_get(GTK_LABEL(titleLabel), &buf1); + if (strcmp(buf1, buf) != 0 && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(titleLabel, bigStyle, bigGreenStyle); } - gtk_label_set( GTK_LABEL( titleLabel), buf); - + gtk_label_set(GTK_LABEL(titleLabel), buf); if (In_endgame(&u.uz)) { - strcpy(buf, (Is_astralevel(&u.uz) ? "Astral Plane":"End Game")); + strcpy(buf, (Is_astralevel(&u.uz) ? "Astral Plane" : "End Game")); } else { sprintf(buf, "%s, level %d", dungeons[u.uz.dnum].dname, depth(&u.uz)); } - if (lastDepth > depth(&u.uz) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( dgnLevelLabel, bigStyle, bigRedStyle); - } - else if (lastDepth < depth(&u.uz) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( dgnLevelLabel, bigStyle, bigGreenStyle); + if (lastDepth > depth(&u.uz) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(dgnLevelLabel, bigStyle, bigRedStyle); + } else if (lastDepth < depth(&u.uz) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(dgnLevelLabel, bigStyle, bigGreenStyle); } lastDepth = depth(&u.uz); - gtk_label_set( GTK_LABEL( dgnLevelLabel), buf); + gtk_label_set(GTK_LABEL(dgnLevelLabel), buf); /* Next, fill in the player's stats */ if (ACURR(A_STR) > 118) { - sprintf(buf,"STR:%d",ACURR(A_STR)-100); - } else if (ACURR(A_STR)==118) { - sprintf(buf,"STR:18/**"); - } else if(ACURR(A_STR) > 18) { - sprintf(buf,"STR:18/%02d",ACURR(A_STR)-18); + sprintf(buf, "STR:%d", ACURR(A_STR) - 100); + } else if (ACURR(A_STR) == 118) { + sprintf(buf, "STR:18/**"); + } else if (ACURR(A_STR) > 18) { + sprintf(buf, "STR:18/%02d", ACURR(A_STR) - 18); } else { - sprintf(buf,"STR:%d",ACURR(A_STR)); + sprintf(buf, "STR:%d", ACURR(A_STR)); } - if (lastStr < ACURR(A_STR) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( strLabel, normalStyle, greenStyle); - } - else if (lastStr > ACURR(A_STR) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( strLabel, normalStyle, redStyle); + if (lastStr < ACURR(A_STR) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(strLabel, normalStyle, greenStyle); + } else if (lastStr > ACURR(A_STR) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(strLabel, normalStyle, redStyle); } lastStr = ACURR(A_STR); - gtk_label_set( GTK_LABEL( strLabel), buf); + gtk_label_set(GTK_LABEL(strLabel), buf); - sprintf(buf,"INT:%d",ACURR(A_INT)); - if (lastInt < ACURR(A_INT) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( intLabel, normalStyle, greenStyle); - } - else if (lastInt > ACURR(A_INT) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( intLabel, normalStyle, redStyle); + sprintf(buf, "INT:%d", ACURR(A_INT)); + if (lastInt < ACURR(A_INT) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(intLabel, normalStyle, greenStyle); + } else if (lastInt > ACURR(A_INT) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(intLabel, normalStyle, redStyle); } lastInt = ACURR(A_INT); - gtk_label_set( GTK_LABEL( intLabel), buf); - - sprintf(buf,"WIS:%d",ACURR(A_WIS)); - if (lastWis < ACURR(A_WIS) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( wisLabel, normalStyle, greenStyle); - } - else if (lastWis > ACURR(A_WIS) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( wisLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(intLabel), buf); + + sprintf(buf, "WIS:%d", ACURR(A_WIS)); + if (lastWis < ACURR(A_WIS) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(wisLabel, normalStyle, greenStyle); + } else if (lastWis > ACURR(A_WIS) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(wisLabel, normalStyle, redStyle); } lastWis = ACURR(A_WIS); - gtk_label_set( GTK_LABEL( wisLabel), buf); - - sprintf(buf,"DEX:%d",ACURR(A_DEX)); - if (lastDex < ACURR(A_DEX) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( dexLabel, normalStyle, greenStyle); - } - else if (lastDex > ACURR(A_DEX) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( dexLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(wisLabel), buf); + + sprintf(buf, "DEX:%d", ACURR(A_DEX)); + if (lastDex < ACURR(A_DEX) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(dexLabel, normalStyle, greenStyle); + } else if (lastDex > ACURR(A_DEX) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(dexLabel, normalStyle, redStyle); } lastDex = ACURR(A_DEX); - gtk_label_set( GTK_LABEL( dexLabel), buf); - - sprintf(buf,"CON:%d",ACURR(A_CON)); - if (lastCon < ACURR(A_CON) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( conLabel, normalStyle, greenStyle); - } - else if (lastCon > ACURR(A_CON) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( conLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(dexLabel), buf); + + sprintf(buf, "CON:%d", ACURR(A_CON)); + if (lastCon < ACURR(A_CON) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(conLabel, normalStyle, greenStyle); + } else if (lastCon > ACURR(A_CON) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(conLabel, normalStyle, redStyle); } lastCon = ACURR(A_CON); - gtk_label_set( GTK_LABEL( conLabel), buf); - - sprintf(buf,"CHA:%d",ACURR(A_CHA)); - if (lastCha < ACURR(A_CHA) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( chaLabel, normalStyle, greenStyle); - } - else if (lastCha > ACURR(A_CHA) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( chaLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(conLabel), buf); + + sprintf(buf, "CHA:%d", ACURR(A_CHA)); + if (lastCha < ACURR(A_CHA) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(chaLabel, normalStyle, greenStyle); + } else if (lastCha > ACURR(A_CHA) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(chaLabel, normalStyle, redStyle); } lastCha = ACURR(A_CHA); - gtk_label_set( GTK_LABEL( chaLabel), buf); - + gtk_label_set(GTK_LABEL(chaLabel), buf); + /* Now do the non-pixmaped stats (gold and such) */ umoney = money_cnt(invent); - sprintf(buf,"Au:%ld", umoney); - if (lastAu < umoney && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( goldLabel, normalStyle, greenStyle); - } - else if (lastAu > umoney && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( goldLabel, normalStyle, redStyle); + sprintf(buf, "Au:%ld", umoney); + if (lastAu < umoney && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(goldLabel, normalStyle, greenStyle); + } else if (lastAu > umoney && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(goldLabel, normalStyle, redStyle); } lastAu = umoney; - gtk_label_set( GTK_LABEL( goldLabel), buf); - - if (u.mtimedone) { - /* special case: when polymorphed, show "HD", disable exp */ - sprintf(buf,"HP:%d/%d", ( (u.mh > 0)? u.mh : 0), u.mhmax); - if ((lastHP < u.mh || lastMHP < u.mhmax ) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( hpLabel, normalStyle, greenStyle); - } - else if ((lastHP > u.mh || lastMHP > u.mhmax ) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( hpLabel, normalStyle, redStyle); - } - lastHP = u.mh; - lastMHP = u.mhmax; - } else { - sprintf(buf,"HP:%d/%d", ( (u.uhp > 0)? u.uhp : 0), u.uhpmax); - if ((lastHP < u.uhp || lastMHP < u.uhpmax ) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( hpLabel, normalStyle, greenStyle); - } - else if ((lastHP > u.uhp || lastMHP > u.uhpmax ) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( hpLabel, normalStyle, redStyle); - } - lastHP = u.uhp; - lastMHP = u.uhpmax; - } - gtk_label_set( GTK_LABEL( hpLabel), buf); - - if (u.mtimedone) { - /* special case: when polymorphed, show "HD", disable exp */ - sprintf(buf,"HD:%d", mons[u.umonnum].mlevel); - if (lastLevel < mons[u.umonnum].mlevel && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( levlLabel, normalStyle, greenStyle); - } - else if (lastLevel > mons[u.umonnum].mlevel && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( levlLabel, normalStyle, redStyle); - } - lastLevel = mons[u.umonnum].mlevel; - } else { - sprintf(buf,"Level:%d", u.ulevel); - if (lastLevel < u.ulevel && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( levlLabel, normalStyle, greenStyle); - } - else if (lastLevel > u.ulevel && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( levlLabel, normalStyle, redStyle); - } - lastLevel = u.ulevel; - } - gtk_label_set( GTK_LABEL( levlLabel), buf); + gtk_label_set(GTK_LABEL(goldLabel), buf); - sprintf(buf,"Power:%d/%d", u.uen, u.uenmax); - if ((lastPOW < u.uen || lastMPOW < u.uenmax) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( powLabel, normalStyle, greenStyle); + if (u.mtimedone) { + /* special case: when polymorphed, show "HD", disable exp */ + sprintf(buf, "HP:%d/%d", ((u.mh > 0) ? u.mh : 0), u.mhmax); + if ((lastHP < u.mh || lastMHP < u.mhmax) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(hpLabel, normalStyle, greenStyle); + } else if ((lastHP > u.mh || lastMHP > u.mhmax) + && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(hpLabel, normalStyle, redStyle); + } + lastHP = u.mh; + lastMHP = u.mhmax; + } else { + sprintf(buf, "HP:%d/%d", ((u.uhp > 0) ? u.uhp : 0), u.uhpmax); + if ((lastHP < u.uhp || lastMHP < u.uhpmax) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(hpLabel, normalStyle, greenStyle); + } else if ((lastHP > u.uhp || lastMHP > u.uhpmax) + && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(hpLabel, normalStyle, redStyle); + } + lastHP = u.uhp; + lastMHP = u.uhpmax; } - if ((lastPOW > u.uen || lastMPOW > u.uenmax) && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( powLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(hpLabel), buf); + + if (u.mtimedone) { + /* special case: when polymorphed, show "HD", disable exp */ + sprintf(buf, "HD:%d", mons[u.umonnum].mlevel); + if (lastLevel < mons[u.umonnum].mlevel && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(levlLabel, normalStyle, greenStyle); + } else if (lastLevel > mons[u.umonnum].mlevel && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(levlLabel, normalStyle, redStyle); + } + lastLevel = mons[u.umonnum].mlevel; + } else { + sprintf(buf, "Level:%d", u.ulevel); + if (lastLevel < u.ulevel && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(levlLabel, normalStyle, greenStyle); + } else if (lastLevel > u.ulevel && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(levlLabel, normalStyle, redStyle); + } + lastLevel = u.ulevel; + } + gtk_label_set(GTK_LABEL(levlLabel), buf); + + sprintf(buf, "Power:%d/%d", u.uen, u.uenmax); + if ((lastPOW < u.uen || lastMPOW < u.uenmax) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(powLabel, normalStyle, greenStyle); + } + if ((lastPOW > u.uen || lastMPOW > u.uenmax) && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(powLabel, normalStyle, redStyle); } lastPOW = u.uen; lastMPOW = u.uenmax; - gtk_label_set( GTK_LABEL( powLabel), buf); - - sprintf(buf,"AC:%d", u.uac); - if (lastAC > u.uac && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( acLabel, normalStyle, greenStyle); - } - else if (lastAC < u.uac && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( acLabel, normalStyle, redStyle); + gtk_label_set(GTK_LABEL(powLabel), buf); + + sprintf(buf, "AC:%d", u.uac); + if (lastAC > u.uac && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(acLabel, normalStyle, greenStyle); + } else if (lastAC < u.uac && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(acLabel, normalStyle, redStyle); } lastAC = u.uac; - gtk_label_set( GTK_LABEL( acLabel), buf); - + gtk_label_set(GTK_LABEL(acLabel), buf); + if (flags.showexp) { - sprintf(buf,"Exp:%ld", u.uexp); - if (lastExp < u.uexp && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( expLabel, normalStyle, greenStyle); - } - else if (lastExp > u.uexp && firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( expLabel, normalStyle, redStyle); - } - lastExp = u.uexp; - gtk_label_set( GTK_LABEL( expLabel), buf); - } else - { - gtk_label_set( GTK_LABEL( expLabel), ""); + sprintf(buf, "Exp:%ld", u.uexp); + if (lastExp < u.uexp && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(expLabel, normalStyle, greenStyle); + } else if (lastExp > u.uexp && firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(expLabel, normalStyle, redStyle); + } + lastExp = u.uexp; + gtk_label_set(GTK_LABEL(expLabel), buf); + } else { + gtk_label_set(GTK_LABEL(expLabel), ""); } if (flags.time) { - sprintf(buf,"Time:%ld", moves); - gtk_label_set( GTK_LABEL( timeLabel), buf); - } - else - gtk_label_set( GTK_LABEL( timeLabel), ""); + sprintf(buf, "Time:%ld", moves); + gtk_label_set(GTK_LABEL(timeLabel), buf); + } else + gtk_label_set(GTK_LABEL(timeLabel), ""); #ifdef SCORE_ON_BOTL if (flags.showscore) { - sprintf(buf,"Score:%ld", botl_score()); - gtk_label_set( GTK_LABEL( scoreLabel), buf); + sprintf(buf, "Score:%ld", botl_score()); + gtk_label_set(GTK_LABEL(scoreLabel), buf); } else - gtk_label_set( GTK_LABEL( scoreLabel), ""); + gtk_label_set(GTK_LABEL(scoreLabel), ""); #else { - gtk_label_set( GTK_LABEL( scoreLabel), ""); + gtk_label_set(GTK_LABEL(scoreLabel), ""); } #endif /* See if their alignment has changed */ if (lastAlignment != u.ualign.type) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( alignLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(alignLabel, normalStyle, redStyle); + } - lastAlignment = u.ualign.type; - /* looks like their alignment has changed -- change out the icon */ - if (u.ualign.type==A_CHAOTIC) { - gtk_label_set( GTK_LABEL( alignLabel), "Chaotic"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(alignPix), chaotic_xpm); - } else if (u.ualign.type==A_NEUTRAL) { - gtk_label_set( GTK_LABEL( alignLabel), "Neutral"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(alignPix), neutral_xpm); - } else { - gtk_label_set( GTK_LABEL( alignLabel), "Lawful"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(alignPix), lawful_xpm); - } + lastAlignment = u.ualign.type; + /* looks like their alignment has changed -- change out the icon */ + if (u.ualign.type == A_CHAOTIC) { + gtk_label_set(GTK_LABEL(alignLabel), "Chaotic"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(alignPix), chaotic_xpm); + } else if (u.ualign.type == A_NEUTRAL) { + gtk_label_set(GTK_LABEL(alignLabel), "Neutral"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(alignPix), neutral_xpm); + } else { + gtk_label_set(GTK_LABEL(alignLabel), "Lawful"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(alignPix), lawful_xpm); + } } - - hung=hu_stat[u.uhs]; - if (lastHungr != u.uhs) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( hungerLabel, normalStyle, redStyle); - } - lastHungr = u.uhs; - if (hung[0]==' ') { - gtk_label_set( GTK_LABEL( hungerLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(hungerPix), nothing_xpm); - } else - if (u.uhs == 0 /* SATIATED */) { - gtk_label_set( GTK_LABEL( hungerLabel), hung); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(hungerPix), satiated_xpm); - } else { - gtk_label_set( GTK_LABEL( hungerLabel), hung); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(hungerPix), hungry_xpm); - } + hung = hu_stat[u.uhs]; + if (lastHungr != u.uhs) { + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(hungerLabel, normalStyle, redStyle); + } + + lastHungr = u.uhs; + if (hung[0] == ' ') { + gtk_label_set(GTK_LABEL(hungerLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(hungerPix), nothing_xpm); + } else if (u.uhs == 0 /* SATIATED */) { + gtk_label_set(GTK_LABEL(hungerLabel), hung); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(hungerPix), satiated_xpm); + } else { + gtk_label_set(GTK_LABEL(hungerLabel), hung); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(hungerPix), hungry_xpm); + } } if (lastConf != Confusion) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( confuLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(confuLabel, normalStyle, redStyle); + } - lastConf = Confusion; - if (Confusion) { - gtk_label_set( GTK_LABEL( confuLabel), "Confused"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(confuPix), confused_xpm); - } - else { - gtk_label_set( GTK_LABEL( confuLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(confuPix), nothing_xpm); - } + lastConf = Confusion; + if (Confusion) { + gtk_label_set(GTK_LABEL(confuLabel), "Confused"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(confuPix), confused_xpm); + } else { + gtk_label_set(GTK_LABEL(confuLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(confuPix), nothing_xpm); + } } if (lastBlind != Blind) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( blindLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(blindLabel, normalStyle, redStyle); + } - lastBlind = Blind; - if (Blind) { - gtk_label_set( GTK_LABEL( blindLabel), "Blind"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(blindPix), blind_xpm); - } - else { - gtk_label_set( GTK_LABEL( blindLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(blindPix), nothing_xpm); - } + lastBlind = Blind; + if (Blind) { + gtk_label_set(GTK_LABEL(blindLabel), "Blind"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(blindPix), blind_xpm); + } else { + gtk_label_set(GTK_LABEL(blindLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(blindPix), nothing_xpm); + } } if (lastStun != Stunned) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( stunLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(stunLabel, normalStyle, redStyle); + } - lastStun = Stunned; - if (Stunned) { - gtk_label_set( GTK_LABEL( stunLabel), "Stun"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(stunPix), stunned_xpm); - } - else { - gtk_label_set( GTK_LABEL( stunLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(stunPix), nothing_xpm); - } + lastStun = Stunned; + if (Stunned) { + gtk_label_set(GTK_LABEL(stunLabel), "Stun"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(stunPix), stunned_xpm); + } else { + gtk_label_set(GTK_LABEL(stunLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(stunPix), nothing_xpm); + } } - - if (lastHalu != Hallucination) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( halluLabel, normalStyle, redStyle); - } - lastHalu = Hallucination; - if (Hallucination) { - gtk_label_set( GTK_LABEL( halluLabel), "Hallu"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(halluPix), hallu_xpm); - } - else { - gtk_label_set( GTK_LABEL( halluLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(halluPix), nothing_xpm); - } + if (lastHalu != Hallucination) { + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(halluLabel, normalStyle, redStyle); + } + + lastHalu = Hallucination; + if (Hallucination) { + gtk_label_set(GTK_LABEL(halluLabel), "Hallu"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(halluPix), hallu_xpm); + } else { + gtk_label_set(GTK_LABEL(halluLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(halluPix), nothing_xpm); + } } if (lastSick != Sick) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( sickLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(sickLabel, normalStyle, redStyle); + } - lastSick = Sick; - if (Sick) { - if (u.usick_type & SICK_VOMITABLE) { - gtk_label_set( GTK_LABEL( sickLabel), "FoodPois"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(sickPix), sick_fp_xpm); - } else if (u.usick_type & SICK_NONVOMITABLE) { - gtk_label_set( GTK_LABEL( sickLabel), "Ill"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(sickPix), sick_il_xpm); - } else { - gtk_label_set( GTK_LABEL( sickLabel), "FoodPois"); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(sickPix), sick_fp_xpm); - } - } else { - gtk_label_set( GTK_LABEL( sickLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(sickPix), nothing_xpm); - } + lastSick = Sick; + if (Sick) { + if (u.usick_type & SICK_VOMITABLE) { + gtk_label_set(GTK_LABEL(sickLabel), "FoodPois"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(sickPix), sick_fp_xpm); + } else if (u.usick_type & SICK_NONVOMITABLE) { + gtk_label_set(GTK_LABEL(sickLabel), "Ill"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(sickPix), sick_il_xpm); + } else { + gtk_label_set(GTK_LABEL(sickLabel), "FoodPois"); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(sickPix), sick_fp_xpm); + } + } else { + gtk_label_set(GTK_LABEL(sickLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(sickPix), nothing_xpm); + } } - enc=enc_stat[near_capacity()]; + enc = enc_stat[near_capacity()]; if (lastEncumb != near_capacity()) { - if (firstTime==FALSE) { - /* Ok, this changed so add it to the highlighing list */ - ghack_highlight_widget( encumbLabel, normalStyle, redStyle); - } + if (firstTime == FALSE) { + /* Ok, this changed so add it to the highlighing list */ + ghack_highlight_widget(encumbLabel, normalStyle, redStyle); + } - lastEncumb = near_capacity(); - switch ( lastEncumb ) { - case 0: - gtk_label_set( GTK_LABEL( encumbLabel), " "); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), nothing_xpm); - break; - case 1: - gtk_label_set( GTK_LABEL( encumbLabel), enc); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), slt_enc_xpm); - break; - case 2: - gtk_label_set( GTK_LABEL( encumbLabel), enc); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), mod_enc_xpm); - break; - case 3: - gtk_label_set( GTK_LABEL( encumbLabel), enc); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), hvy_enc_xpm); - break; - case 4: - gtk_label_set( GTK_LABEL( encumbLabel), enc); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), ext_enc_xpm); - break; - case 5: - gtk_label_set( GTK_LABEL( encumbLabel), enc); - gnome_pixmap_load_xpm_d( GNOME_PIXMAP(encumbPix), ovr_enc_xpm); - } + lastEncumb = near_capacity(); + switch (lastEncumb) { + case 0: + gtk_label_set(GTK_LABEL(encumbLabel), " "); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), nothing_xpm); + break; + case 1: + gtk_label_set(GTK_LABEL(encumbLabel), enc); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), slt_enc_xpm); + break; + case 2: + gtk_label_set(GTK_LABEL(encumbLabel), enc); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), mod_enc_xpm); + break; + case 3: + gtk_label_set(GTK_LABEL(encumbLabel), enc); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), hvy_enc_xpm); + break; + case 4: + gtk_label_set(GTK_LABEL(encumbLabel), enc); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), ext_enc_xpm); + break; + case 5: + gtk_label_set(GTK_LABEL(encumbLabel), enc); + gnome_pixmap_load_xpm_d(GNOME_PIXMAP(encumbPix), ovr_enc_xpm); + } } - firstTime=FALSE; + firstTime = FALSE; } -static void ghack_fade_highlighting() +static void +ghack_fade_highlighting() { GList *item; Highlight *highlt; /* Remove any items from the queue if their time is up */ - for (item = g_list_first( s_HighLightList) ; item ; ) { - highlt = (Highlight*) item->data; - if (highlt) { - if ( highlt->nTurnsLeft <= 0) { - gtk_widget_set_style( GTK_WIDGET( highlt->widget), - highlt->oldStyle); - s_HighLightList = g_list_remove_link(s_HighLightList, item); - g_free( highlt); - g_list_free_1( item); - item = g_list_first( s_HighLightList); - continue; - } else - (highlt->nTurnsLeft)--; - } - if (item) - item=item->next; - else - break; + for (item = g_list_first(s_HighLightList); item;) { + highlt = (Highlight *) item->data; + if (highlt) { + if (highlt->nTurnsLeft <= 0) { + gtk_widget_set_style(GTK_WIDGET(highlt->widget), + highlt->oldStyle); + s_HighLightList = g_list_remove_link(s_HighLightList, item); + g_free(highlt); + g_list_free_1(item); + item = g_list_first(s_HighLightList); + continue; + } else + (highlt->nTurnsLeft)--; + } + if (item) + item = item->next; + else + break; } } /* Widget changed, so add it to the highlighing list */ -static void ghack_highlight_widget( GtkWidget* widget, GtkStyle* oldStyle, - GtkStyle* newStyle) +static void +ghack_highlight_widget(GtkWidget *widget, GtkStyle *oldStyle, + GtkStyle *newStyle) { Highlight *highlt; GList *item; - + /* Check if this widget is already in the queue. If so then * remove it, so we will only have the new entry in the queue */ - for (item = g_list_first( s_HighLightList) ; item ; ) { - highlt = (Highlight*) item->data; - if (highlt) { - if ( highlt->widget == widget) { - s_HighLightList = g_list_remove_link(s_HighLightList, item); - g_free( highlt); - g_list_free_1( item); - break; - } - } - if (item) - item=item->next; - else - break; + for (item = g_list_first(s_HighLightList); item;) { + highlt = (Highlight *) item->data; + if (highlt) { + if (highlt->widget == widget) { + s_HighLightList = g_list_remove_link(s_HighLightList, item); + g_free(highlt); + g_list_free_1(item); + break; + } + } + if (item) + item = item->next; + else + break; } - /* Ok, now highlight this widget and add it into the fade + /* Ok, now highlight this widget and add it into the fade * highlighting queue */ - highlt = g_new( Highlight, 1); - highlt->nTurnsLeft=NUM_TURNS_HIGHLIGHTED; - highlt->oldStyle=oldStyle; - highlt->widget=widget; - s_HighLightList = g_list_prepend (s_HighLightList, highlt); - gtk_widget_set_style( GTK_WIDGET( widget), newStyle); - -} - - + highlt = g_new(Highlight, 1); + highlt->nTurnsLeft = NUM_TURNS_HIGHLIGHTED; + highlt->oldStyle = oldStyle; + highlt->widget = widget; + s_HighLightList = g_list_prepend(s_HighLightList, highlt); + gtk_widget_set_style(GTK_WIDGET(widget), newStyle); +} diff --git a/win/gnome/gntext.c b/win/gnome/gntext.c index 439f3a37d..824b1410f 100644 --- a/win/gnome/gntext.c +++ b/win/gnome/gntext.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gntext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gntext.c $NHDT-Date: 1431192772 2015/05/09 17:32:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 gntext.c $Date: 2009/05/06 10:58:00 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)gntext.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -21,8 +21,6 @@ #define RIP_DRAW_X 114 #define RIP_DRAW_Y 69 - - /* Text Window widgets */ GtkWidget *RIP = NULL; GtkWidget *RIPlabel = NULL; @@ -31,130 +29,125 @@ GnomeLess *gless; static int showRIP = 0; - - - -void ghack_text_window_clear(GtkWidget *widget, gpointer data) +void +ghack_text_window_clear(GtkWidget *widget, gpointer data) { - g_assert (gless != NULL); - gtk_editable_delete_text (GTK_EDITABLE (gless->text), 0, 0); + g_assert(gless != NULL); + gtk_editable_delete_text(GTK_EDITABLE(gless->text), 0, 0); } -void ghack_text_window_destroy() +void +ghack_text_window_destroy() { TW_window = NULL; } -void ghack_text_window_display(GtkWidget *widget, boolean block, - gpointer data) +void +ghack_text_window_display(GtkWidget *widget, boolean block, gpointer data) { - if(showRIP == 1) { - gtk_widget_show (GTK_WIDGET ( RIP)); - gtk_window_set_title(GTK_WINDOW( TW_window), "Rest In Peace"); + if (showRIP == 1) { + gtk_widget_show(GTK_WIDGET(RIP)); + gtk_window_set_title(GTK_WINDOW(TW_window), "Rest In Peace"); } - - gtk_signal_connect (GTK_OBJECT (TW_window), "destroy", - (GtkSignalFunc) ghack_text_window_destroy, NULL); + + gtk_signal_connect(GTK_OBJECT(TW_window), "destroy", + (GtkSignalFunc) ghack_text_window_destroy, NULL); if (block) - gnome_dialog_run(GNOME_DIALOG(TW_window)); + gnome_dialog_run(GNOME_DIALOG(TW_window)); else - gnome_dialog_run_and_close(GNOME_DIALOG(TW_window)); - - if(showRIP == 1) { - showRIP = 0; - gtk_widget_hide (GTK_WIDGET ( RIP)); - gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window"); + gnome_dialog_run_and_close(GNOME_DIALOG(TW_window)); + + if (showRIP == 1) { + showRIP = 0; + gtk_widget_hide(GTK_WIDGET(RIP)); + gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window"); } } -void ghack_text_window_put_string(GtkWidget *widget, int attr, - const char* text, gpointer data) +void +ghack_text_window_put_string(GtkWidget *widget, int attr, const char *text, + gpointer data) { - if(text == NULL) + if (text == NULL) return; - + /* Don't bother with attributes yet */ - gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, text, -1); - gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1); + gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, text, -1); + gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, "\n", -1); } - -GtkWidget* ghack_init_text_window ( ) +GtkWidget * +ghack_init_text_window() { GtkWidget *pixmap; - if(TW_window) - return(GTK_WIDGET(TW_window)); - + if (TW_window) + return (GTK_WIDGET(TW_window)); + TW_window = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL); - gtk_window_set_default_size( GTK_WINDOW(TW_window), 500, 400); + gtk_window_set_default_size(GTK_WINDOW(TW_window), 500, 400); gtk_window_set_policy(GTK_WINDOW(TW_window), TRUE, TRUE, FALSE); gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window"); - + /* create GNOME pixmap object */ - pixmap = gnome_pixmap_new_from_xpm_d (rip_xpm); - g_assert (pixmap != NULL); - gtk_widget_show (GTK_WIDGET (pixmap)); + pixmap = gnome_pixmap_new_from_xpm_d(rip_xpm); + g_assert(pixmap != NULL); + gtk_widget_show(GTK_WIDGET(pixmap)); /* create label with our "death message", sized to fit into the * tombstone */ - RIPlabel = gtk_label_new ("RIP"); - g_assert (RIPlabel != NULL); + RIPlabel = gtk_label_new("RIP"); + g_assert(RIPlabel != NULL); /* gtk_label_set_justify is broken? */ - gtk_label_set_justify (GTK_LABEL (RIPlabel), GTK_JUSTIFY_CENTER); - gtk_label_set_line_wrap (GTK_LABEL (RIPlabel), TRUE); - gtk_widget_set_usize (RIPlabel, RIP_DRAW_WIDTH, RIP_DRAW_HEIGHT); - gtk_widget_show (RIPlabel); + gtk_label_set_justify(GTK_LABEL(RIPlabel), GTK_JUSTIFY_CENTER); + gtk_label_set_line_wrap(GTK_LABEL(RIPlabel), TRUE); + gtk_widget_set_usize(RIPlabel, RIP_DRAW_WIDTH, RIP_DRAW_HEIGHT); + gtk_widget_show(RIPlabel); /* create a fixed sized widget for the RIP pixmap */ - RIP = gtk_fixed_new (); - g_assert (RIP != NULL); - gtk_widget_set_usize (RIP, RIP_IMAGE_WIDTH, RIP_IMAGE_HEIGHT); - gtk_fixed_put (GTK_FIXED (RIP), pixmap, 0, 0); - gtk_fixed_put (GTK_FIXED (RIP), RIPlabel, RIP_DRAW_X, RIP_DRAW_Y); - gtk_widget_show (RIP); - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), RIP, - TRUE, TRUE, 0); - + RIP = gtk_fixed_new(); + g_assert(RIP != NULL); + gtk_widget_set_usize(RIP, RIP_IMAGE_WIDTH, RIP_IMAGE_HEIGHT); + gtk_fixed_put(GTK_FIXED(RIP), pixmap, 0, 0); + gtk_fixed_put(GTK_FIXED(RIP), RIPlabel, RIP_DRAW_X, RIP_DRAW_Y); + gtk_widget_show(RIP); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), RIP, TRUE, + TRUE, 0); + /* create a gnome Less widget for the text stuff */ - gless = GNOME_LESS (gnome_less_new ()); - g_assert (gless != NULL); - gtk_widget_show (GTK_WIDGET (gless)); - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), - GTK_WIDGET (gless), TRUE, TRUE, 0); - + gless = GNOME_LESS(gnome_less_new()); + g_assert(gless != NULL); + gtk_widget_show(GTK_WIDGET(gless)); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), + GTK_WIDGET(gless), TRUE, TRUE, 0); + /* Hook up some signals */ gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_putstr", - GTK_SIGNAL_FUNC(ghack_text_window_put_string), - NULL); + GTK_SIGNAL_FUNC(ghack_text_window_put_string), NULL); gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_clear", - GTK_SIGNAL_FUNC(ghack_text_window_clear), - NULL); + GTK_SIGNAL_FUNC(ghack_text_window_clear), NULL); gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_display", - GTK_SIGNAL_FUNC(ghack_text_window_display), - NULL); + GTK_SIGNAL_FUNC(ghack_text_window_display), NULL); /* Center the dialog over over parent */ - gnome_dialog_set_parent( GNOME_DIALOG (TW_window), - GTK_WINDOW(ghack_get_main_window()) ); + gnome_dialog_set_parent(GNOME_DIALOG(TW_window), + GTK_WINDOW(ghack_get_main_window())); - gtk_window_set_modal( GTK_WINDOW(TW_window), TRUE); + gtk_window_set_modal(GTK_WINDOW(TW_window), TRUE); gtk_widget_show_all(TW_window); - gtk_widget_hide (GTK_WIDGET ( RIP)); - gnome_dialog_close_hides (GNOME_DIALOG (TW_window), TRUE); + gtk_widget_hide(GTK_WIDGET(RIP)); + gnome_dialog_close_hides(GNOME_DIALOG(TW_window), TRUE); return GTK_WIDGET(TW_window); - } - -void ghack_text_window_rip_string( const char* string) +void +ghack_text_window_rip_string(const char *string) { /* This is called to specify that the next message window will * be a RIP window, which will include this text */ showRIP = 1; - gtk_label_set( GTK_LABEL( RIPlabel), string); + gtk_label_set(GTK_LABEL(RIPlabel), string); } - diff --git a/win/gnome/gnworn.c b/win/gnome/gnworn.c index 3943695ca..69462d5c4 100644 --- a/win/gnome/gnworn.c +++ b/win/gnome/gnworn.c @@ -1,6 +1,6 @@ /* NetHack 3.6 gnworn.c 2009/05/06 10:58:06 1.3 */ /* - * $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ + * $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ * $Date: 2012/01/10 17:47:38 $ $Revision: 1.4 $ */ /* Copyright (C) 2002, Dylan Alex Simon */ @@ -11,17 +11,21 @@ #include "gnsignal.h" #include "gnomeprv.h" -#define WORN_WIDTH 3 -#define WORN_HEIGHT 6 +#define WORN_WIDTH 3 +#define WORN_HEIGHT 6 -#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \ - { uquiver, uarmh, u.twoweap ? NULL : uswapwep }, \ - { u.twoweap ? uswapwep : NULL, ublindf, uwep }, \ - { uleft, uamul, uright }, \ - { uarms, uarmc, uarmg }, \ - { uarmu, uarm, uskin }, \ - { uball, uarmf, uchain } \ -} +#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ \ + { \ + { \ + uquiver, uarmh, u.twoweap ? NULL : uswapwep \ + } \ + , { u.twoweap ? uswapwep : NULL, ublindf, uwep }, \ + { uleft, uamul, uright }, { uarms, uarmc, uarmg }, \ + { uarmu, uarm, uskin }, \ + { \ + uball, uarmf, uchain \ + } \ + } static GtkWidget *worn_contents[WORN_HEIGHT][WORN_WIDTH]; static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH]; @@ -29,26 +33,27 @@ static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH]; GdkImlibImage *image_of_worn_object(struct obj *o); void ghack_worn_display(GtkWidget *win, boolean block, gpointer data); -GtkWidget* +GtkWidget * ghack_init_worn_window() { GtkWidget *top; GtkWidget *table; GtkWidget *tablealign; GtkWidget *label; - int i,j; + int i, j; top = gtk_vbox_new(FALSE, 2); table = gtk_table_new(WORN_HEIGHT, WORN_WIDTH, TRUE); for (i = 0; i < WORN_HEIGHT; i++) { - for (j = 0; j < WORN_WIDTH; j++) { - worn_contents[i][j] = - gnome_pixmap_new_from_imlib(image_of_worn_object(NULL)); - last_worn_objects[i][j] = NULL; /* a pointer that will never be */ - gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(worn_contents[i][j]), - j, j+1, i, i+1, 0, 0, 0, 0); - } + for (j = 0; j < WORN_WIDTH; j++) { + worn_contents[i][j] = + gnome_pixmap_new_from_imlib(image_of_worn_object(NULL)); + last_worn_objects[i][j] = NULL; /* a pointer that will never be */ + gtk_table_attach(GTK_TABLE(table), + GTK_WIDGET(worn_contents[i][j]), j, j + 1, i, + i + 1, 0, 0, 0, 0); + } } tablealign = gtk_alignment_new(0.5, 0.0, 0.0, 1.0); gtk_box_pack_start(GTK_BOX(top), tablealign, FALSE, FALSE, 0); @@ -59,21 +64,21 @@ ghack_init_worn_window() gtk_box_pack_start(GTK_BOX(top), label, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(top), "ghack_display", - GTK_SIGNAL_FUNC(ghack_worn_display), NULL); + GTK_SIGNAL_FUNC(ghack_worn_display), NULL); return top; } -GdkImlibImage* +GdkImlibImage * image_of_worn_object(struct obj *o) { int glyph; GdkImlibImage *im; if (o) - glyph = obj_to_glyph(o); + glyph = obj_to_glyph(o); else - glyph = cmap_to_glyph(S_stone); + glyph = cmap_to_glyph(S_stone); im = ghack_image_from_glyph(glyph, FALSE); @@ -87,12 +92,13 @@ ghack_worn_display(GtkWidget *win, boolean block, gpointer data) struct obj *worn_objects[WORN_HEIGHT][WORN_WIDTH] = WORN_OBJECT_LIST; for (i = 0; i < WORN_HEIGHT; i++) { - for (j = 0; j < WORN_WIDTH; j++) { - if (worn_objects[i][j] != last_worn_objects[i][j]) { - last_worn_objects[i][j] = worn_objects[i][j]; - gnome_pixmap_load_imlib(GNOME_PIXMAP(worn_contents[i][j]), - image_of_worn_object(worn_objects[i][j])); - } - } + for (j = 0; j < WORN_WIDTH; j++) { + if (worn_objects[i][j] != last_worn_objects[i][j]) { + last_worn_objects[i][j] = worn_objects[i][j]; + gnome_pixmap_load_imlib( + GNOME_PIXMAP(worn_contents[i][j]), + image_of_worn_object(worn_objects[i][j])); + } + } } } diff --git a/win/gnome/gnyesno.c b/win/gnome/gnyesno.c index 881c0dc40..cd8f85fdc 100644 --- a/win/gnome/gnyesno.c +++ b/win/gnome/gnyesno.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 gnyesno.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 gnyesno.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ /* NetHack 3.6 gnyesno.c $Date: 2009/05/06 10:58:06 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)gnyesno.c 3.5 2000/07/16 */ /* Copyright (C) 1998 by Erik Andersen */ @@ -7,47 +7,42 @@ #include "gnbind.h" #include "gnyesno.h" - - -int ghack_yes_no_dialog( const char *question, - const char *choices, int def) +int +ghack_yes_no_dialog(const char *question, const char *choices, int def) { - int i=0, ret; + int i = 0, ret; gchar button_name[BUFSZ]; GtkWidget *box; - GtkWidget* mainWnd=NULL; + GtkWidget *mainWnd = NULL; - box = gnome_message_box_new ( question, GNOME_MESSAGE_BOX_QUESTION, NULL); + box = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION, NULL); /* add buttons for each choice */ if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) { - gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK); - gnome_dialog_set_default( GNOME_DIALOG(box), 0); - gnome_dialog_set_accelerator( GNOME_DIALOG(box), 0, 'o', 0); + gnome_dialog_append_button(GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK); + gnome_dialog_set_default(GNOME_DIALOG(box), 0); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'o', 0); #if 0 g_print("Setting accelerator '%c' for button %d\n", 'o', 0); #endif - } - else { - for( ; choices[i]!='\0'; i++) { - if (choices[i]=='y') { - sprintf( button_name, GNOME_STOCK_BUTTON_YES); - } - else if (choices[i]=='n') { - sprintf( button_name, GNOME_STOCK_BUTTON_NO); - } - else if (choices[i] == 'q') { - sprintf( button_name, "Quit"); - } else { - sprintf( button_name, "%c", choices[i]); - } - if (def==choices[i]) - gnome_dialog_set_default( GNOME_DIALOG(box), i); - gnome_dialog_append_button ( GNOME_DIALOG(box), button_name); - gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0); + } else { + for (; choices[i] != '\0'; i++) { + if (choices[i] == 'y') { + sprintf(button_name, GNOME_STOCK_BUTTON_YES); + } else if (choices[i] == 'n') { + sprintf(button_name, GNOME_STOCK_BUTTON_NO); + } else if (choices[i] == 'q') { + sprintf(button_name, "Quit"); + } else { + sprintf(button_name, "%c", choices[i]); + } + if (def == choices[i]) + gnome_dialog_set_default(GNOME_DIALOG(box), i); + gnome_dialog_append_button(GNOME_DIALOG(box), button_name); + gnome_dialog_set_accelerator(GNOME_DIALOG(box), i, choices[i], 0); #if 0 g_print("Setting accelerator '%c' for button %d\n", choices[i], i); #endif - } + } } #if 0 /* Perhaps add in a quit game button, like this... */ @@ -56,23 +51,22 @@ int ghack_yes_no_dialog( const char *question, g_print("Setting accelerator '%c' for button %d\n", 'Q', i); #endif - gnome_dialog_set_close(GNOME_DIALOG (box), TRUE); - mainWnd = ghack_get_main_window (); - gtk_window_set_modal( GTK_WINDOW(box), TRUE); - gtk_window_set_title( GTK_WINDOW(box), "GnomeHack"); - if ( mainWnd != NULL ) { - gnome_dialog_set_parent (GNOME_DIALOG (box), - GTK_WINDOW ( mainWnd) ); + gnome_dialog_set_close(GNOME_DIALOG(box), TRUE); + mainWnd = ghack_get_main_window(); + gtk_window_set_modal(GTK_WINDOW(box), TRUE); + gtk_window_set_title(GTK_WINDOW(box), "GnomeHack"); + if (mainWnd != NULL) { + gnome_dialog_set_parent(GNOME_DIALOG(box), GTK_WINDOW(mainWnd)); } - ret=gnome_dialog_run_and_close ( GNOME_DIALOG (box)); - + ret = gnome_dialog_run_and_close(GNOME_DIALOG(box)); + #if 0 g_print("You selected button %d\n", ret); #endif - - if (ret==-1) - return( '\033'); + + if (ret == -1) + return ('\033'); else - return( choices[ret]); + return (choices[ret]); } diff --git a/win/share/gifread.c b/win/share/gifread.c index 8147c3380..3fa063d57 100644 --- a/win/share/gifread.c +++ b/win/share/gifread.c @@ -13,7 +13,7 @@ /* +-------------------------------------------------------------------+ */ /* - * $NHDT-Date: 1429464661 2015/04/19 17:31:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.2 $ + * $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ * $Date: 2002/01/05 21:06:02 $ $Revision: 1.1 $ */ @@ -24,167 +24,170 @@ extern long *FDECL(alloc, (unsigned int)); #endif -#define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 ) +#define PPM_ASSIGN(p, red, grn, blu) \ + do { \ + (p).r = (red); \ + (p).g = (grn); \ + (p).b = (blu); \ + } while (0) -#define MAX_LWZ_BITS 12 +#define MAX_LWZ_BITS 12 -#define INTERLACE 0x40 -#define LOCALCOLORMAP 0x80 -#define BitSet(byte, bit) (((byte) & (bit)) == (bit)) +#define INTERLACE 0x40 +#define LOCALCOLORMAP 0x80 +#define BitSet(byte, bit) (((byte) & (bit)) == (bit)) -#define ReadOK(file,buffer,len) (fread((genericptr_t)buffer, (int)len, 1, file) != 0) +#define ReadOK(file, buffer, len) \ + (fread((genericptr_t) buffer, (int) len, 1, file) != 0) -#define LM_to_uint(a,b) (((b)<<8)|(a)) +#define LM_to_uint(a, b) (((b) << 8) | (a)) struct gifscreen { - int Width; - int Height; - int Colors; - int ColorResolution; - int Background; - int AspectRatio; - int Interlace; + int Width; + int Height; + int Colors; + int ColorResolution; + int Background; + int AspectRatio; + int Interlace; } GifScreen; struct { - int transparent; - int delayTime; - int inputFlag; - int disposal; + int transparent; + int delayTime; + int inputFlag; + int disposal; } Gif89 = { -1, -1, -1, 0 }; -int ZeroDataBlock = FALSE; +int ZeroDataBlock = FALSE; static FILE *gif_file; static int tiles_across, tiles_down, curr_tiles_across, curr_tiles_down; static pixel **image; static unsigned char input_code_size; -static int FDECL(GetDataBlock, (FILE *fd, unsigned char *buf)); -static void FDECL(DoExtension, (FILE *fd, int label)); -static boolean FDECL(ReadColorMap, (FILE *fd, int number)); -static void FDECL(read_header, (FILE *fd)); -static int FDECL(GetCode, (FILE *fd, int code_size, int flag)); -static int FDECL(LWZReadByte, (FILE *fd, int flag, int input_code_size)); -static void FDECL(ReadInterleavedImage, (FILE *fd, int len, int height)); -static void FDECL(ReadTileStrip, (FILE *fd, int len)); +static int FDECL(GetDataBlock, (FILE * fd, unsigned char *buf)); +static void FDECL(DoExtension, (FILE * fd, int label)); +static boolean FDECL(ReadColorMap, (FILE * fd, int number)); +static void FDECL(read_header, (FILE * fd)); +static int FDECL(GetCode, (FILE * fd, int code_size, int flag)); +static int FDECL(LWZReadByte, (FILE * fd, int flag, int input_code_size)); +static void FDECL(ReadInterleavedImage, (FILE * fd, int len, int height)); +static void FDECL(ReadTileStrip, (FILE * fd, int len)); /* These should be in gif.h, but there isn't one. */ boolean FDECL(fopen_gif_file, (const char *, const char *)); -boolean FDECL(read_gif_tile, (pixel(*)[TILE_X])); +boolean FDECL(read_gif_tile, (pixel(*) [TILE_X])); int NDECL(fclose_gif_file); static int GetDataBlock(fd, buf) -FILE *fd; -unsigned char *buf; +FILE *fd; +unsigned char *buf; { - unsigned char count; + unsigned char count; - if (!ReadOK(fd,&count,1)) { - Fprintf(stderr, "error in getting DataBlock size\n"); - return -1; - } + if (!ReadOK(fd, &count, 1)) { + Fprintf(stderr, "error in getting DataBlock size\n"); + return -1; + } - ZeroDataBlock = (count == 0); + ZeroDataBlock = (count == 0); - if ((count != 0) && (!ReadOK(fd, buf, count))) { - Fprintf(stderr, "error in reading DataBlock\n"); - return -1; - } + if ((count != 0) && (!ReadOK(fd, buf, count))) { + Fprintf(stderr, "error in reading DataBlock\n"); + return -1; + } - return count; + return count; } static void DoExtension(fd, label) -FILE *fd; -int label; +FILE *fd; +int label; { - static char buf[256]; - char *str; + static char buf[256]; + char *str; - switch (label) { - case 0x01: /* Plain Text Extension */ - str = "Plain Text Extension"; + switch (label) { + case 0x01: /* Plain Text Extension */ + str = "Plain Text Extension"; #ifdef notdef - if (GetDataBlock(fd, (unsigned char*) buf) == 0) - ; + if (GetDataBlock(fd, (unsigned char *) buf) == 0) + ; - lpos = LM_to_uint(buf[0], buf[1]); - tpos = LM_to_uint(buf[2], buf[3]); - width = LM_to_uint(buf[4], buf[5]); - height = LM_to_uint(buf[6], buf[7]); - cellw = buf[8]; - cellh = buf[9]; - foreground = buf[10]; - background = buf[11]; + lpos = LM_to_uint(buf[0], buf[1]); + tpos = LM_to_uint(buf[2], buf[3]); + width = LM_to_uint(buf[4], buf[5]); + height = LM_to_uint(buf[6], buf[7]); + cellw = buf[8]; + cellh = buf[9]; + foreground = buf[10]; + background = buf[11]; - while (GetDataBlock(fd, (unsigned char*) buf) != 0) { - PPM_ASSIGN(image[ypos][xpos], - cmap[CM_RED][v], - cmap[CM_GREEN][v], - cmap[CM_BLUE][v]); - ++index; - } + while (GetDataBlock(fd, (unsigned char *) buf) != 0) { + PPM_ASSIGN(image[ypos][xpos], cmap[CM_RED][v], cmap[CM_GREEN][v], + cmap[CM_BLUE][v]); + ++index; + } - return; + return; #else - break; + break; #endif - case 0xff: /* Application Extension */ - str = "Application Extension"; - break; - case 0xfe: /* Comment Extension */ - str = "Comment Extension"; - while (GetDataBlock(fd, (unsigned char*) buf) != 0) { - Fprintf(stderr, "gif comment: %s\n", buf ); - } - return; - case 0xf9: /* Graphic Control Extension */ - str = "Graphic Control Extension"; - (void) GetDataBlock(fd, (unsigned char*) buf); - Gif89.disposal = (buf[0] >> 2) & 0x7; - Gif89.inputFlag = (buf[0] >> 1) & 0x1; - Gif89.delayTime = LM_to_uint(buf[1],buf[2]); - if ((buf[0] & 0x1) != 0) - Gif89.transparent = buf[3]; + case 0xff: /* Application Extension */ + str = "Application Extension"; + break; + case 0xfe: /* Comment Extension */ + str = "Comment Extension"; + while (GetDataBlock(fd, (unsigned char *) buf) != 0) { + Fprintf(stderr, "gif comment: %s\n", buf); + } + return; + case 0xf9: /* Graphic Control Extension */ + str = "Graphic Control Extension"; + (void) GetDataBlock(fd, (unsigned char *) buf); + Gif89.disposal = (buf[0] >> 2) & 0x7; + Gif89.inputFlag = (buf[0] >> 1) & 0x1; + Gif89.delayTime = LM_to_uint(buf[1], buf[2]); + if ((buf[0] & 0x1) != 0) + Gif89.transparent = buf[3]; - while (GetDataBlock(fd, (unsigned char*) buf) != 0) - ; - return; - default: - str = buf; - Sprintf(buf, "UNKNOWN (0x%02x)", label); - break; - } + while (GetDataBlock(fd, (unsigned char *) buf) != 0) + ; + return; + default: + str = buf; + Sprintf(buf, "UNKNOWN (0x%02x)", label); + break; + } - Fprintf(stderr, "got a '%s' extension\n", str); + Fprintf(stderr, "got a '%s' extension\n", str); - while (GetDataBlock(fd, (unsigned char*) buf) != 0) - ; + while (GetDataBlock(fd, (unsigned char *) buf) != 0) + ; } -static -boolean -ReadColorMap(fd,number) -FILE *fd; -int number; +static boolean +ReadColorMap(fd, number) +FILE *fd; +int number; { - int i; - unsigned char rgb[3]; + int i; + unsigned char rgb[3]; - for (i = 0; i < number; ++i) { - if (!ReadOK(fd, rgb, sizeof(rgb))) { - return(FALSE); - } + for (i = 0; i < number; ++i) { + if (!ReadOK(fd, rgb, sizeof(rgb))) { + return (FALSE); + } - ColorMap[CM_RED][i] = rgb[0] ; - ColorMap[CM_GREEN][i] = rgb[1] ; - ColorMap[CM_BLUE][i] = rgb[2] ; - } - colorsinmap = number; - return TRUE; + ColorMap[CM_RED][i] = rgb[0]; + ColorMap[CM_GREEN][i] = rgb[1]; + ColorMap[CM_BLUE][i] = rgb[2]; + } + colorsinmap = number; + return TRUE; } /* @@ -193,408 +196,406 @@ int number; */ static void read_header(fd) -FILE *fd; +FILE *fd; { - unsigned char buf[16]; - unsigned char c; - char version[4]; + unsigned char buf[16]; + unsigned char c; + char version[4]; - if (!ReadOK(fd,buf,6)) { - Fprintf(stderr, "error reading magic number\n"); - exit(EXIT_FAILURE); - } + if (!ReadOK(fd, buf, 6)) { + Fprintf(stderr, "error reading magic number\n"); + exit(EXIT_FAILURE); + } - if (strncmp((genericptr_t)buf,"GIF",3) != 0) { - Fprintf(stderr, "not a GIF file\n"); - exit(EXIT_FAILURE); - } + if (strncmp((genericptr_t) buf, "GIF", 3) != 0) { + Fprintf(stderr, "not a GIF file\n"); + exit(EXIT_FAILURE); + } - (void) strncpy(version, (char *)buf + 3, 3); - version[3] = '\0'; + (void) strncpy(version, (char *) buf + 3, 3); + version[3] = '\0'; - if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) { - Fprintf(stderr, "bad version number, not '87a' or '89a'\n"); - exit(EXIT_FAILURE); - } + if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) { + Fprintf(stderr, "bad version number, not '87a' or '89a'\n"); + exit(EXIT_FAILURE); + } - if (!ReadOK(fd,buf,7)) { - Fprintf(stderr, "failed to read screen descriptor\n"); - exit(EXIT_FAILURE); - } + if (!ReadOK(fd, buf, 7)) { + Fprintf(stderr, "failed to read screen descriptor\n"); + exit(EXIT_FAILURE); + } - GifScreen.Width = LM_to_uint(buf[0],buf[1]); - GifScreen.Height = LM_to_uint(buf[2],buf[3]); - GifScreen.Colors = 2<<(buf[4]&0x07); - GifScreen.ColorResolution = (((buf[4]&0x70)>>3)+1); - GifScreen.Background = buf[5]; - GifScreen.AspectRatio = buf[6]; + GifScreen.Width = LM_to_uint(buf[0], buf[1]); + GifScreen.Height = LM_to_uint(buf[2], buf[3]); + GifScreen.Colors = 2 << (buf[4] & 0x07); + GifScreen.ColorResolution = (((buf[4] & 0x70) >> 3) + 1); + GifScreen.Background = buf[5]; + GifScreen.AspectRatio = buf[6]; - if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */ - if (!ReadColorMap(fd, GifScreen.Colors)) { - Fprintf(stderr, "error reading global colormap\n"); - exit(EXIT_FAILURE); - } - } + if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */ + if (!ReadColorMap(fd, GifScreen.Colors)) { + Fprintf(stderr, "error reading global colormap\n"); + exit(EXIT_FAILURE); + } + } - if (GifScreen.AspectRatio != 0 && GifScreen.AspectRatio != 49) { - Fprintf(stderr, "warning - non-square pixels\n"); - } + if (GifScreen.AspectRatio != 0 && GifScreen.AspectRatio != 49) { + Fprintf(stderr, "warning - non-square pixels\n"); + } - for (;;) { - if (!ReadOK(fd,&c,1)) { - Fprintf(stderr, "EOF / read error on image data\n"); - exit(EXIT_FAILURE); - } + for (;;) { + if (!ReadOK(fd, &c, 1)) { + Fprintf(stderr, "EOF / read error on image data\n"); + exit(EXIT_FAILURE); + } - if (c == ';') { /* GIF terminator */ - return; - } + if (c == ';') { /* GIF terminator */ + return; + } - if (c == '!') { /* Extension */ - if (!ReadOK(fd,&c,1)) { - Fprintf(stderr, - "EOF / read error on extension function code\n"); - exit(EXIT_FAILURE); - } - DoExtension(fd, (int)c); - continue; - } + if (c == '!') { /* Extension */ + if (!ReadOK(fd, &c, 1)) { + Fprintf(stderr, + "EOF / read error on extension function code\n"); + exit(EXIT_FAILURE); + } + DoExtension(fd, (int) c); + continue; + } - if (c != ',') { /* Not a valid start character */ - Fprintf(stderr, - "bogus character 0x%02x, ignoring\n", (int) c); - continue; - } + if (c != ',') { /* Not a valid start character */ + Fprintf(stderr, "bogus character 0x%02x, ignoring\n", (int) c); + continue; + } - if (!ReadOK(fd,buf,9)) { - Fprintf(stderr, "couldn't read left/top/width/height\n"); - exit(EXIT_FAILURE); - } + if (!ReadOK(fd, buf, 9)) { + Fprintf(stderr, "couldn't read left/top/width/height\n"); + exit(EXIT_FAILURE); + } - if (BitSet(buf[8], LOCALCOLORMAP)) { - /* replace global color map with local */ - GifScreen.Colors = 1<<((buf[8]&0x07)+1); - if (!ReadColorMap(fd, GifScreen.Colors)) { - Fprintf(stderr, "error reading local colormap\n"); - exit(EXIT_FAILURE); - } - - } - if (GifScreen.Width != LM_to_uint(buf[4],buf[5])) { - Fprintf(stderr, "warning: widths don't match\n"); - GifScreen.Width = LM_to_uint(buf[4],buf[5]); - } - if (GifScreen.Height != LM_to_uint(buf[6],buf[7])) { - Fprintf(stderr, "warning: heights don't match\n"); - GifScreen.Height = LM_to_uint(buf[6],buf[7]); - } - GifScreen.Interlace = BitSet(buf[8], INTERLACE); - return; - } + if (BitSet(buf[8], LOCALCOLORMAP)) { + /* replace global color map with local */ + GifScreen.Colors = 1 << ((buf[8] & 0x07) + 1); + if (!ReadColorMap(fd, GifScreen.Colors)) { + Fprintf(stderr, "error reading local colormap\n"); + exit(EXIT_FAILURE); + } + } + if (GifScreen.Width != LM_to_uint(buf[4], buf[5])) { + Fprintf(stderr, "warning: widths don't match\n"); + GifScreen.Width = LM_to_uint(buf[4], buf[5]); + } + if (GifScreen.Height != LM_to_uint(buf[6], buf[7])) { + Fprintf(stderr, "warning: heights don't match\n"); + GifScreen.Height = LM_to_uint(buf[6], buf[7]); + } + GifScreen.Interlace = BitSet(buf[8], INTERLACE); + return; + } } static int GetCode(fd, code_size, flag) -FILE *fd; -int code_size; -int flag; +FILE *fd; +int code_size; +int flag; { - static unsigned char buf[280]; - static int curbit, lastbit, done, last_byte; - int i, j, ret; - unsigned char count; + static unsigned char buf[280]; + static int curbit, lastbit, done, last_byte; + int i, j, ret; + unsigned char count; - if (flag) { - curbit = 0; - lastbit = 0; - done = FALSE; - return 0; - } + if (flag) { + curbit = 0; + lastbit = 0; + done = FALSE; + return 0; + } - if ((curbit+code_size) >= lastbit) { - if (done) { - if (curbit >= lastbit) - Fprintf(stderr, "ran off the end of my bits\n"); - return -1; - } - buf[0] = buf[last_byte-2]; - buf[1] = buf[last_byte-1]; + if ((curbit + code_size) >= lastbit) { + if (done) { + if (curbit >= lastbit) + Fprintf(stderr, "ran off the end of my bits\n"); + return -1; + } + buf[0] = buf[last_byte - 2]; + buf[1] = buf[last_byte - 1]; - if ((count = GetDataBlock(fd, &buf[2])) == 0) - done = TRUE; + if ((count = GetDataBlock(fd, &buf[2])) == 0) + done = TRUE; - last_byte = 2 + count; - curbit = (curbit - lastbit) + 16; - lastbit = (2+count)*8 ; - } + last_byte = 2 + count; + curbit = (curbit - lastbit) + 16; + lastbit = (2 + count) * 8; + } - ret = 0; - for (i = curbit, j = 0; j < code_size; ++i, ++j) - ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j; + ret = 0; + for (i = curbit, j = 0; j < code_size; ++i, ++j) + ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j; - curbit += code_size; + curbit += code_size; - return ret; + return ret; } static int LWZReadByte(fd, flag, input_code_size) -FILE *fd; -int flag; -int input_code_size; +FILE *fd; +int flag; +int input_code_size; { - static int fresh = FALSE; - int code, incode; - static int code_size, set_code_size; - static int max_code, max_code_size; - static int firstcode, oldcode; - static int clear_code, end_code; - static int table[2][(1<< MAX_LWZ_BITS)]; - static int stack[(1<<(MAX_LWZ_BITS))*2], *sp; - register int i; + static int fresh = FALSE; + int code, incode; + static int code_size, set_code_size; + static int max_code, max_code_size; + static int firstcode, oldcode; + static int clear_code, end_code; + static int table[2][(1 << MAX_LWZ_BITS)]; + static int stack[(1 << (MAX_LWZ_BITS)) * 2], *sp; + register int i; - if (flag) { - set_code_size = input_code_size; - code_size = set_code_size+1; - clear_code = 1 << set_code_size ; - end_code = clear_code + 1; - max_code_size = 2*clear_code; - max_code = clear_code+2; + if (flag) { + set_code_size = input_code_size; + code_size = set_code_size + 1; + clear_code = 1 << set_code_size; + end_code = clear_code + 1; + max_code_size = 2 * clear_code; + max_code = clear_code + 2; - (void) GetCode(fd, 0, TRUE); + (void) GetCode(fd, 0, TRUE); - fresh = TRUE; + fresh = TRUE; - for (i = 0; i < clear_code; ++i) { - table[0][i] = 0; - table[1][i] = i; - } - for (; i < (1< stack) - return *--sp; + if (sp > stack) + return *--sp; - while ((code = GetCode(fd, code_size, FALSE)) >= 0) { - if (code == clear_code) { - for (i = 0; i < clear_code; ++i) { - table[0][i] = 0; - table[1][i] = i; - } - for (; i < (1<= 0) { + if (code == clear_code) { + for (i = 0; i < clear_code; ++i) { + table[0][i] = 0; + table[1][i] = i; + } + for (; i < (1 << MAX_LWZ_BITS); ++i) + table[0][i] = table[1][i] = 0; + code_size = set_code_size + 1; + max_code_size = 2 * clear_code; + max_code = clear_code + 2; + sp = stack; + firstcode = oldcode = GetCode(fd, code_size, FALSE); + return firstcode; + } else if (code == end_code) { + int count; + unsigned char buf[260]; - if (ZeroDataBlock) - return -2; + if (ZeroDataBlock) + return -2; - while ((count = GetDataBlock(fd, buf)) > 0) - ; + while ((count = GetDataBlock(fd, buf)) > 0) + ; - if (count != 0) - Fprintf(stderr, - "missing EOD in data stream (common occurrence)\n"); - return -2; - } + if (count != 0) + Fprintf(stderr, + "missing EOD in data stream (common occurrence)\n"); + return -2; + } - incode = code; + incode = code; - if (code >= max_code) { - *sp++ = firstcode; - code = oldcode; - } + if (code >= max_code) { + *sp++ = firstcode; + code = oldcode; + } - while (code >= clear_code) { - *sp++ = table[1][code]; - if (code == table[0][code]) { - Fprintf(stderr, "circular table entry BIG ERROR\n"); - exit(EXIT_FAILURE); - } - code = table[0][code]; - } + while (code >= clear_code) { + *sp++ = table[1][code]; + if (code == table[0][code]) { + Fprintf(stderr, "circular table entry BIG ERROR\n"); + exit(EXIT_FAILURE); + } + code = table[0][code]; + } - *sp++ = firstcode = table[1][code]; + *sp++ = firstcode = table[1][code]; - if ((code = max_code) <(1<= max_code_size) && - (max_code_size < (1<= max_code_size) + && (max_code_size < (1 << MAX_LWZ_BITS))) { + max_code_size *= 2; + ++code_size; + } + } - oldcode = incode; + oldcode = incode; - if (sp > stack) - return *--sp; - } - return code; + if (sp > stack) + return *--sp; + } + return code; } - static void ReadInterleavedImage(fd, len, height) -FILE *fd; -int len, height; +FILE *fd; +int len, height; { - int v; - int xpos = 0, ypos = 0, pass = 0; + int v; + int xpos = 0, ypos = 0, pass = 0; - while ((v = LWZReadByte(fd,FALSE,(int)input_code_size)) >= 0 ) { - PPM_ASSIGN(image[ypos][xpos], ColorMap[CM_RED][v], - ColorMap[CM_GREEN][v], ColorMap[CM_BLUE][v]); + while ((v = LWZReadByte(fd, FALSE, (int) input_code_size)) >= 0) { + PPM_ASSIGN(image[ypos][xpos], ColorMap[CM_RED][v], + ColorMap[CM_GREEN][v], ColorMap[CM_BLUE][v]); - ++xpos; - if (xpos == len) { - xpos = 0; - switch (pass) { - case 0: - case 1: - ypos += 8; break; - case 2: - ypos += 4; break; - case 3: - ypos += 2; break; - } + ++xpos; + if (xpos == len) { + xpos = 0; + switch (pass) { + case 0: + case 1: + ypos += 8; + break; + case 2: + ypos += 4; + break; + case 3: + ypos += 2; + break; + } - if (ypos >= height) { - ++pass; - switch (pass) { - case 1: - ypos = 4; break; - case 2: - ypos = 2; break; - case 3: - ypos = 1; break; - default: - goto fini; - } - } - } - if (ypos >= height) - break; - } + if (ypos >= height) { + ++pass; + switch (pass) { + case 1: + ypos = 4; + break; + case 2: + ypos = 2; + break; + case 3: + ypos = 1; + break; + default: + goto fini; + } + } + } + if (ypos >= height) + break; + } fini: - if (LWZReadByte(fd,FALSE,(int)input_code_size)>=0) - Fprintf(stderr, "too much input data, ignoring extra...\n"); + if (LWZReadByte(fd, FALSE, (int) input_code_size) >= 0) + Fprintf(stderr, "too much input data, ignoring extra...\n"); } -static -void -ReadTileStrip(fd,len) +static void +ReadTileStrip(fd, len) FILE *fd; int len; { - int v; - int xpos = 0, ypos = 0; + int v; + int xpos = 0, ypos = 0; - while ((v = LWZReadByte(fd,FALSE,(int)input_code_size)) >= 0 ) { - PPM_ASSIGN(image[ypos][xpos], ColorMap[CM_RED][v], - ColorMap[CM_GREEN][v], ColorMap[CM_BLUE][v]); + while ((v = LWZReadByte(fd, FALSE, (int) input_code_size)) >= 0) { + PPM_ASSIGN(image[ypos][xpos], ColorMap[CM_RED][v], + ColorMap[CM_GREEN][v], ColorMap[CM_BLUE][v]); - ++xpos; - if (xpos == len) { - xpos = 0; - ++ypos; - } - if (ypos >= TILE_Y) - break; - } + ++xpos; + if (xpos == len) { + xpos = 0; + ++ypos; + } + if (ypos >= TILE_Y) + break; + } } - - - boolean fopen_gif_file(filename, type) const char *filename; const char *type; { - int i; + int i; - if (strcmp(type, RDBMODE)) { - Fprintf(stderr, "using reading routine for non-reading?\n"); - return FALSE; - } - gif_file = fopen(filename, type); - if (gif_file == (FILE *)0) { - Fprintf(stderr, "cannot open gif file %s\n", filename); - return FALSE; - } + if (strcmp(type, RDBMODE)) { + Fprintf(stderr, "using reading routine for non-reading?\n"); + return FALSE; + } + gif_file = fopen(filename, type); + if (gif_file == (FILE *) 0) { + Fprintf(stderr, "cannot open gif file %s\n", filename); + return FALSE; + } - read_header(gif_file); - if (GifScreen.Width % TILE_X) { - Fprintf(stderr, "error: width %d not divisible by %d\n", - GifScreen.Width, TILE_X); - exit(EXIT_FAILURE); - } - tiles_across = GifScreen.Width / TILE_X; - curr_tiles_across = 0; - if (GifScreen.Height % TILE_Y) { - Fprintf(stderr, "error: height %d not divisible by %d\n", - GifScreen.Height, TILE_Y); - /* exit(EXIT_FAILURE) */; - } - tiles_down = GifScreen.Height / TILE_Y; - curr_tiles_down = 0; + read_header(gif_file); + if (GifScreen.Width % TILE_X) { + Fprintf(stderr, "error: width %d not divisible by %d\n", + GifScreen.Width, TILE_X); + exit(EXIT_FAILURE); + } + tiles_across = GifScreen.Width / TILE_X; + curr_tiles_across = 0; + if (GifScreen.Height % TILE_Y) { + Fprintf(stderr, "error: height %d not divisible by %d\n", + GifScreen.Height, TILE_Y); + /* exit(EXIT_FAILURE) */; + } + tiles_down = GifScreen.Height / TILE_Y; + curr_tiles_down = 0; - if (GifScreen.Interlace) { - /* sigh -- hope this doesn't happen on micros */ - image = (pixel **)alloc(GifScreen.Height * sizeof(pixel *)); - for (i = 0; i < GifScreen.Height; i++) { - image[i] = (pixel *) alloc(GifScreen.Width * sizeof(pixel)); - } - } else { - image = (pixel **)alloc(TILE_Y * sizeof(pixel *)); - for (i = 0; i < TILE_Y; i++) { - image[i] = (pixel *) alloc(GifScreen.Width * sizeof(pixel)); - } - } + if (GifScreen.Interlace) { + /* sigh -- hope this doesn't happen on micros */ + image = (pixel **) alloc(GifScreen.Height * sizeof(pixel *)); + for (i = 0; i < GifScreen.Height; i++) { + image[i] = (pixel *) alloc(GifScreen.Width * sizeof(pixel)); + } + } else { + image = (pixel **) alloc(TILE_Y * sizeof(pixel *)); + for (i = 0; i < TILE_Y; i++) { + image[i] = (pixel *) alloc(GifScreen.Width * sizeof(pixel)); + } + } - /* - ** Initialize the Compression routines - */ - if (!ReadOK(gif_file,&input_code_size,1)) { - Fprintf(stderr, "EOF / read error on image data\n"); - exit(EXIT_FAILURE); - } + /* + ** Initialize the Compression routines + */ + if (!ReadOK(gif_file, &input_code_size, 1)) { + Fprintf(stderr, "EOF / read error on image data\n"); + exit(EXIT_FAILURE); + } - if (LWZReadByte(gif_file, TRUE, (int)input_code_size) < 0) { - Fprintf(stderr, "error reading image\n"); - exit(EXIT_FAILURE); - } + if (LWZReadByte(gif_file, TRUE, (int) input_code_size) < 0) { + Fprintf(stderr, "error reading image\n"); + exit(EXIT_FAILURE); + } - /* read first section */ - if (GifScreen.Interlace) { - ReadInterleavedImage(gif_file, - GifScreen.Width,GifScreen.Height); - } else { - ReadTileStrip(gif_file,GifScreen.Width); - } - return TRUE; + /* read first section */ + if (GifScreen.Interlace) { + ReadInterleavedImage(gif_file, GifScreen.Width, GifScreen.Height); + } else { + ReadTileStrip(gif_file, GifScreen.Width); + } + return TRUE; } /* Read a tile. Returns FALSE when there are no more tiles */ @@ -602,109 +603,110 @@ boolean read_gif_tile(pixels) pixel (*pixels)[TILE_X]; { - int i, j; + int i, j; - if (curr_tiles_down >= tiles_down) return FALSE; - if (curr_tiles_across == tiles_across) { - curr_tiles_across = 0; - curr_tiles_down++; - if (curr_tiles_down >= tiles_down) return FALSE; - if (!GifScreen.Interlace) - ReadTileStrip(gif_file,GifScreen.Width); - } - if (GifScreen.Interlace) { - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - pixels[j][i] = image[curr_tiles_down*TILE_Y + j] - [curr_tiles_across*TILE_X + i]; - } - } - } else { - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - pixels[j][i] = image[j][curr_tiles_across*TILE_X + i]; - } - } - } - curr_tiles_across++; + if (curr_tiles_down >= tiles_down) + return FALSE; + if (curr_tiles_across == tiles_across) { + curr_tiles_across = 0; + curr_tiles_down++; + if (curr_tiles_down >= tiles_down) + return FALSE; + if (!GifScreen.Interlace) + ReadTileStrip(gif_file, GifScreen.Width); + } + if (GifScreen.Interlace) { + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + pixels[j][i] = image[curr_tiles_down * TILE_Y + + j][curr_tiles_across * TILE_X + i]; + } + } + } else { + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + pixels[j][i] = image[j][curr_tiles_across * TILE_X + i]; + } + } + } + curr_tiles_across++; - /* check for "filler" tile */ - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X && i < 4; i += 2) { - if (pixels[j][i].r != ColorMap[CM_RED][0] || - pixels[j][i].g != ColorMap[CM_GREEN][0] || - pixels[j][i].b != ColorMap[CM_BLUE][0] || - pixels[j][i+1].r != ColorMap[CM_RED][1] || - pixels[j][i+1].g != ColorMap[CM_GREEN][1] || - pixels[j][i+1].b != ColorMap[CM_BLUE][1]) - return TRUE; - } - } - return FALSE; + /* check for "filler" tile */ + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X && i < 4; i += 2) { + if (pixels[j][i].r != ColorMap[CM_RED][0] + || pixels[j][i].g != ColorMap[CM_GREEN][0] + || pixels[j][i].b != ColorMap[CM_BLUE][0] + || pixels[j][i + 1].r != ColorMap[CM_RED][1] + || pixels[j][i + 1].g != ColorMap[CM_GREEN][1] + || pixels[j][i + 1].b != ColorMap[CM_BLUE][1]) + return TRUE; + } + } + return FALSE; } int fclose_gif_file() { - int i; + int i; - if (GifScreen.Interlace) { - for (i = 0; i < GifScreen.Height; i++) { - free((genericptr_t)image[i]); - } - free((genericptr_t)image); - } else { - for (i = 0; i < TILE_Y; i++) { - free((genericptr_t)image[i]); - } - free((genericptr_t)image); - } - return(fclose(gif_file)); + if (GifScreen.Interlace) { + for (i = 0; i < GifScreen.Height; i++) { + free((genericptr_t) image[i]); + } + free((genericptr_t) image); + } else { + for (i = 0; i < TILE_Y; i++) { + free((genericptr_t) image[i]); + } + free((genericptr_t) image); + } + return (fclose(gif_file)); } #ifndef AMIGA -static char *std_args[] = { "tilemap", /* dummy argv[0] */ - "monsters.gif", "monsters.txt", - "objects.gif", "objects.txt", - "other.gif", "other.txt" }; +static char *std_args[] = { "tilemap", /* dummy argv[0] */ + "monsters.gif", "monsters.txt", "objects.gif", + "objects.txt", "other.gif", "other.txt" }; int main(argc, argv) int argc; char *argv[]; { - pixel pixels[TILE_Y][TILE_X]; + pixel pixels[TILE_Y][TILE_X]; - if (argc == 1) { - argc = SIZE(std_args); - argv = std_args; - } else if (argc != 3) { - Fprintf(stderr, "usage: gif2txt giffile txtfile\n"); - exit(EXIT_FAILURE); - } + if (argc == 1) { + argc = SIZE(std_args); + argv = std_args; + } else if (argc != 3) { + Fprintf(stderr, "usage: gif2txt giffile txtfile\n"); + exit(EXIT_FAILURE); + } - while (argc > 1) { - if (!fopen_gif_file(argv[1], RDBMODE)) - exit(EXIT_FAILURE); + while (argc > 1) { + if (!fopen_gif_file(argv[1], RDBMODE)) + exit(EXIT_FAILURE); - init_colormap(); + init_colormap(); - if (!fopen_text_file(argv[2], WRTMODE)) { - (void) fclose_gif_file(); - exit(EXIT_FAILURE); - } + if (!fopen_text_file(argv[2], WRTMODE)) { + (void) fclose_gif_file(); + exit(EXIT_FAILURE); + } - while (read_gif_tile(pixels)) - (void) write_text_tile(pixels); + while (read_gif_tile(pixels)) + (void) write_text_tile(pixels); - (void) fclose_gif_file(); - (void) fclose_text_file(); + (void) fclose_gif_file(); + (void) fclose_text_file(); - argc -= 2; - argv += 2; - } - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + argc -= 2; + argv += 2; + } + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } #endif diff --git a/win/share/ppmwrite.c b/win/share/ppmwrite.c index 5e7620a3f..a92c06479 100644 --- a/win/share/ppmwrite.c +++ b/win/share/ppmwrite.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 ppmwrite.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 ppmwrite.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */ /* NetHack 3.6 ppmwrite.c $Date: 2009/05/06 10:59:00 $ $Revision: 1.2 $ */ /* this produces a raw ppm file, with a 15-character header of * "P6 3-digit-width 3-digit-height 255\n" @@ -14,8 +14,8 @@ extern long *FDECL(alloc, (unsigned int)); FILE *ppm_file; struct ppmscreen { - int Width; - int Height; + int Width; + int Height; } PpmScreen; static int tiles_across, tiles_down, curr_tiles_across; @@ -27,22 +27,22 @@ static void NDECL(WriteTileStrip); static void write_header() { - (void) fprintf(ppm_file, "P6 %03d %03d 255\n", - PpmScreen.Width, PpmScreen.Height); + (void) fprintf(ppm_file, "P6 %03d %03d 255\n", PpmScreen.Width, + PpmScreen.Height); } static void WriteTileStrip() { - int i, j; + int i, j; - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < PpmScreen.Width; i++) { - (void) fputc((char)image[j][i].r, ppm_file); - (void) fputc((char)image[j][i].g, ppm_file); - (void) fputc((char)image[j][i].b, ppm_file); - } - } + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < PpmScreen.Width; i++) { + (void) fputc((char) image[j][i].r, ppm_file); + (void) fputc((char) image[j][i].g, ppm_file); + (void) fputc((char) image[j][i].b, ppm_file); + } + } } boolean @@ -50,124 +50,123 @@ fopen_ppm_file(filename, type) const char *filename; const char *type; { - int i; + int i; - if (strcmp(type, WRBMODE)) { - Fprintf(stderr, "using writing routine for non-writing?\n"); - return FALSE; - } - ppm_file = fopen(filename, type); - if (ppm_file == (FILE *)0) { - Fprintf(stderr, "cannot open ppm file %s\n", filename); - return FALSE; - } + if (strcmp(type, WRBMODE)) { + Fprintf(stderr, "using writing routine for non-writing?\n"); + return FALSE; + } + ppm_file = fopen(filename, type); + if (ppm_file == (FILE *) 0) { + Fprintf(stderr, "cannot open ppm file %s\n", filename); + return FALSE; + } - if (!colorsinmainmap) { - Fprintf(stderr, "no colormap set yet\n"); - return FALSE; - } + if (!colorsinmainmap) { + Fprintf(stderr, "no colormap set yet\n"); + return FALSE; + } - tiles_across = 20; - curr_tiles_across = 0; - PpmScreen.Width = 20 * TILE_X; + tiles_across = 20; + curr_tiles_across = 0; + PpmScreen.Width = 20 * TILE_X; - tiles_down = 0; - PpmScreen.Height = 0; /* will be rewritten later */ + tiles_down = 0; + PpmScreen.Height = 0; /* will be rewritten later */ - write_header(); + write_header(); - image = (pixel **)alloc(TILE_Y * sizeof(pixel *)); - for (i = 0; i < TILE_Y; i++) { - image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel)); - } + image = (pixel **) alloc(TILE_Y * sizeof(pixel *)); + for (i = 0; i < TILE_Y; i++) { + image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel)); + } - return TRUE; + return TRUE; } boolean write_ppm_tile(pixels) pixel (*pixels)[TILE_X]; { - int i, j; + int i, j; - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - image[j][curr_tiles_across*TILE_X + i] = pixels[j][i]; - } - } - curr_tiles_across++; - if (curr_tiles_across == tiles_across) { - WriteTileStrip(); - curr_tiles_across = 0; - tiles_down++; - } - return TRUE; + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + image[j][curr_tiles_across * TILE_X + i] = pixels[j][i]; + } + } + curr_tiles_across++; + if (curr_tiles_across == tiles_across) { + WriteTileStrip(); + curr_tiles_across = 0; + tiles_down++; + } + return TRUE; } int fclose_ppm_file() { - int i, j; + int i, j; - if (curr_tiles_across) { /* partial row */ - /* fill with checkerboard, for lack of a better idea */ - for (j = 0; j < TILE_Y; j++) { - for (i = curr_tiles_across * TILE_X; - i < PpmScreen.Width; i += 2 ) { - image[j][i].r = MainColorMap[CM_RED][0]; - image[j][i].g = MainColorMap[CM_GREEN][0]; - image[j][i].b = MainColorMap[CM_BLUE][0]; - image[j][i+1].r = MainColorMap[CM_RED][1]; - image[j][i+1].g = MainColorMap[CM_GREEN][1]; - image[j][i+1].b = MainColorMap[CM_BLUE][1]; - } - } - WriteTileStrip(); - curr_tiles_across = 0; - tiles_down++; - } + if (curr_tiles_across) { /* partial row */ + /* fill with checkerboard, for lack of a better idea */ + for (j = 0; j < TILE_Y; j++) { + for (i = curr_tiles_across * TILE_X; i < PpmScreen.Width; + i += 2) { + image[j][i].r = MainColorMap[CM_RED][0]; + image[j][i].g = MainColorMap[CM_GREEN][0]; + image[j][i].b = MainColorMap[CM_BLUE][0]; + image[j][i + 1].r = MainColorMap[CM_RED][1]; + image[j][i + 1].g = MainColorMap[CM_GREEN][1]; + image[j][i + 1].b = MainColorMap[CM_BLUE][1]; + } + } + WriteTileStrip(); + curr_tiles_across = 0; + tiles_down++; + } - for (i = 0; i < TILE_Y; i++) { - free((genericptr_t)image[i]); - } - free((genericptr_t)image); + for (i = 0; i < TILE_Y; i++) { + free((genericptr_t) image[i]); + } + free((genericptr_t) image); - PpmScreen.Height = tiles_down * TILE_Y; - rewind(ppm_file); - write_header(); /* update size */ + PpmScreen.Height = tiles_down * TILE_Y; + rewind(ppm_file); + write_header(); /* update size */ - return(fclose(ppm_file)); + return (fclose(ppm_file)); } - int main(argc, argv) int argc; char *argv[]; { - pixel pixels[TILE_Y][TILE_X]; + pixel pixels[TILE_Y][TILE_X]; - if (argc != 3) { - Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n"); - exit(EXIT_FAILURE); - } + if (argc != 3) { + Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n"); + exit(EXIT_FAILURE); + } - if (!fopen_text_file(argv[1], RDTMODE)) - exit(EXIT_FAILURE); + if (!fopen_text_file(argv[1], RDTMODE)) + exit(EXIT_FAILURE); - init_colormap(); + init_colormap(); - if (!fopen_ppm_file(argv[2], WRBMODE)) { - (void) fclose_text_file(); - exit(EXIT_FAILURE); - } + if (!fopen_ppm_file(argv[2], WRBMODE)) { + (void) fclose_text_file(); + exit(EXIT_FAILURE); + } - while (read_text_tile(pixels)) - (void) write_ppm_tile(pixels); + while (read_text_tile(pixels)) + (void) write_ppm_tile(pixels); - (void) fclose_text_file(); - (void) fclose_ppm_file(); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + (void) fclose_text_file(); + (void) fclose_ppm_file(); + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } diff --git a/win/share/thintile.c b/win/share/thintile.c index 9d5e4c982..caada25e7 100644 --- a/win/share/thintile.c +++ b/win/share/thintile.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 thintile.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 thintile.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.6 thintile.c $Date: 2012/01/10 17:47:40 $ $Revision: 1.5 $ */ /* Copyright (c) NetHack Development Team 1995 */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,13 +14,13 @@ static char pixels[TILE_Y][TILE_X]; -static char *tilefiles[] = { "../win/share/monsters.txt", - "../win/share/objects.txt", - "../win/share/other.txt"}; +static char *tilefiles[] = { "../win/share/monsters.txt", + "../win/share/objects.txt", + "../win/share/other.txt" }; -static char *thinfiles[] = { "../win/share/monthin.txt", - "../win/share/objthin.txt", - "../win/share/oththin.txt"}; +static char *thinfiles[] = { "../win/share/monthin.txt", + "../win/share/objthin.txt", + "../win/share/oththin.txt" }; static FILE *infile, *outfile; static int tilecount; static int tilecount_per_file; @@ -30,101 +30,99 @@ static char comment[BUFSZ]; static void copy_colormap() { - int r, g, b; - char c[2]; + int r, g, b; + char c[2]; - while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b) - == 4) { - Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b); - } + while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b) + == 4) { + Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b); + } } static boolean read_txttile() { - int i, j; - char buf[BUFSZ]; - char buf2[BUFSZ]; + int i, j; + char buf[BUFSZ]; + char buf2[BUFSZ]; - char c[2]; + char c[2]; + if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0) + return FALSE; - if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0) - return FALSE; - - Sprintf(comment,"# tile %d (%s)", i, buf); - - /* look for non-whitespace at each stage */ - if (fscanf(infile, "%1s", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - if (c[0] != '{') { - Fprintf(stderr, "didn't find expected '{'\n"); - return FALSE; - } - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - if (fscanf(infile, "%1s", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - pixels[j][i] = c[0]; - } - } - if (fscanf(infile, "%1s ", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - if (c[0] != '}') { - Fprintf(stderr, "didn't find expected '}'\n"); - return FALSE; - } - return TRUE; + Sprintf(comment, "# tile %d (%s)", i, buf); + + /* look for non-whitespace at each stage */ + if (fscanf(infile, "%1s", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + if (c[0] != '{') { + Fprintf(stderr, "didn't find expected '{'\n"); + return FALSE; + } + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + if (fscanf(infile, "%1s", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + pixels[j][i] = c[0]; + } + } + if (fscanf(infile, "%1s ", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + if (c[0] != '}') { + Fprintf(stderr, "didn't find expected '}'\n"); + return FALSE; + } + return TRUE; } static void write_thintile() { - int i, j; + int i, j; - - Fprintf(outfile, "%s\n", comment); - Fprintf(outfile, "{\n"); - for (j = 0; j < TILE_Y; j++) { - Fprintf(outfile, " "); - for (i = 0; i < TILE_X; i += 2) { - (void) fputc(pixels[j][i], outfile); - } - Fprintf(outfile, "\n"); - } - Fprintf(outfile, "}\n"); + Fprintf(outfile, "%s\n", comment); + Fprintf(outfile, "{\n"); + for (j = 0; j < TILE_Y; j++) { + Fprintf(outfile, " "); + for (i = 0; i < TILE_X; i += 2) { + (void) fputc(pixels[j][i], outfile); + } + Fprintf(outfile, "\n"); + } + Fprintf(outfile, "}\n"); } int main(argc, argv) int argc; char *argv[]; { - while (filenum < 3) { - tilecount_per_file = 0; - infile = fopen(tilefiles[filenum], RDTMODE); - outfile = fopen(thinfiles[filenum], WRTMODE); - copy_colormap(); - while (read_txttile()) { - write_thintile(); - tilecount_per_file++; - tilecount++; - } - fclose(outfile); - fclose(infile); - printf("%d tiles processed from %s\n", - tilecount_per_file, tilefiles[filenum]); - ++filenum; - } - printf("Grand total of %d tiles processed.\n", tilecount); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + while (filenum < 3) { + tilecount_per_file = 0; + infile = fopen(tilefiles[filenum], RDTMODE); + outfile = fopen(thinfiles[filenum], WRTMODE); + copy_colormap(); + while (read_txttile()) { + write_thintile(); + tilecount_per_file++; + tilecount++; + } + fclose(outfile); + fclose(infile); + printf("%d tiles processed from %s\n", tilecount_per_file, + tilefiles[filenum]); + ++filenum; + } + printf("Grand total of %d tiles processed.\n", tilecount); + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } /*thintile.c*/ diff --git a/win/share/tile2bmp.c b/win/share/tile2bmp.c index e63366c0a..00bc76ab9 100644 --- a/win/share/tile2bmp.c +++ b/win/share/tile2bmp.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tile2bmp.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 tile2bmp.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */ /* Copyright (c) NetHack PC Development Team 1995 */ /* NetHack may be freely redistributed. See license for details. */ @@ -18,53 +18,55 @@ #include "win32api.h" #endif -#if (TILE_X==32) +#if (TILE_X == 32) #define COLORS_IN_USE 256 #else -/*#define COLORS_IN_USE 16 */ /* 16 colors */ -#define COLORS_IN_USE 256 /* 256 colors */ +/*#define COLORS_IN_USE 16 */ /* 16 colors */ +#define COLORS_IN_USE 256 /* 256 colors */ #endif #define BITCOUNT 8 extern char *FDECL(tilename, (int, int)); -#define MAGICTILENO (340 + 440 + 231 + 340) +#define MAGICTILENO (340 + 440 + 231 + 340) -#if BITCOUNT==4 -#define MAX_X 320 /* 2 per byte, 4 bits per pixel */ +#if BITCOUNT == 4 +#define MAX_X 320 /* 2 per byte, 4 bits per pixel */ #define MAX_Y 480 #else -# if (TILE_X==32) +#if (TILE_X == 32) #define MAX_X (32 * 40) #define MAX_Y ((MAGICTILENO * 32) / 40) * 2 -# else +#else #define MAX_X (16 * 40) #define MAX_Y ((MAGICTILENO * 16) / 40) * 2 -# endif -#endif +#endif +#endif /* GCC fix by Paolo Bonzini 1999/03/28 */ #ifdef __GNUC__ -#define PACK __attribute__((packed)) +#define PACK __attribute__((packed)) #else #define PACK -#endif +#endif -static short leshort(short x) +static short +leshort(short x) { #ifdef __BIG_ENDIAN__ - return ((x&0xff)<<8)|((x>>8)&0xff); + return ((x & 0xff) << 8) | ((x >> 8) & 0xff); #else return x; #endif } - -static long lelong(long x) +static long +lelong(long x) { #ifdef __BIG_ENDIAN__ - return ((x&0xff)<<24)|((x&0xff00)<<8)|((x>>8)&0xff00)|((x>>24)&0xff); + return ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) + | ((x >> 24) & 0xff); #else return x; #endif @@ -72,63 +74,63 @@ static long lelong(long x) #ifdef __GNUC__ typedef struct tagBMIH { - unsigned long biSize; - long biWidth; - long biHeight; - unsigned short biPlanes; - unsigned short biBitCount; - unsigned long biCompression; - unsigned long biSizeImage; - long biXPelsPerMeter; - long biYPelsPerMeter; - unsigned long biClrUsed; - unsigned long biClrImportant; + unsigned long biSize; + long biWidth; + long biHeight; + unsigned short biPlanes; + unsigned short biBitCount; + unsigned long biCompression; + unsigned long biSizeImage; + long biXPelsPerMeter; + long biYPelsPerMeter; + unsigned long biClrUsed; + unsigned long biClrImportant; } PACK BITMAPINFOHEADER; typedef struct tagBMFH { - unsigned short bfType; - unsigned long bfSize; - unsigned short bfReserved1; - unsigned short bfReserved2; - unsigned long bfOffBits; + unsigned short bfType; + unsigned long bfSize; + unsigned short bfReserved1; + unsigned short bfReserved2; + unsigned long bfOffBits; } PACK BITMAPFILEHEADER; typedef struct tagRGBQ { - unsigned char rgbBlue; - unsigned char rgbGreen; - unsigned char rgbRed; - unsigned char rgbReserved; + unsigned char rgbBlue; + unsigned char rgbGreen; + unsigned char rgbRed; + unsigned char rgbReserved; } PACK RGBQUAD; #define UINT unsigned int #define DWORD unsigned long #define LONG long #define WORD unsigned short -#define BI_RGB 0L -#define BI_RLE8 1L -#define BI_RLE4 2L -#define BI_BITFIELDS 3L +#define BI_RGB 0L +#define BI_RLE8 1L +#define BI_RLE4 2L +#define BI_BITFIELDS 3L #endif /* __GNUC__ */ #pragma pack(1) -struct tagBMP{ +struct tagBMP { BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; -#if BITCOUNT==4 +#if BITCOUNT == 4 #define RGBQUAD_COUNT 16 - RGBQUAD bmaColors[RGBQUAD_COUNT]; + RGBQUAD bmaColors[RGBQUAD_COUNT]; #else -#if (TILE_X==32) +#if (TILE_X == 32) #define RGBQUAD_COUNT 256 #else /*#define RGBQUAD_COUNT 16 */ #define RGBQUAD_COUNT 256 #endif - RGBQUAD bmaColors[RGBQUAD_COUNT]; + RGBQUAD bmaColors[RGBQUAD_COUNT]; #endif -#if (COLORS_IN_USE==16) - uchar packtile[MAX_Y][MAX_X]; +#if (COLORS_IN_USE == 16) + uchar packtile[MAX_Y][MAX_X]; #else - uchar packtile[MAX_Y][MAX_X]; + uchar packtile[MAX_Y][MAX_X]; /* uchar packtile[TILE_Y][TILE_X]; */ #endif } PACK bmp; @@ -140,19 +142,17 @@ FILE *tibfile2; pixel tilepixels[TILE_Y][TILE_X]; -static void FDECL(build_bmfh,(BITMAPFILEHEADER *)); -static void FDECL(build_bmih,(BITMAPINFOHEADER *)); -static void FDECL(build_bmptile,(pixel (*)[TILE_X])); +static void FDECL(build_bmfh, (BITMAPFILEHEADER *)); +static void FDECL(build_bmih, (BITMAPINFOHEADER *)); +static void FDECL(build_bmptile, (pixel(*) [TILE_X])); char *tilefiles[] = { #if (TILE_X == 32) - "../win/share/mon32.txt", - "../win/share/obj32.txt", - "../win/share/oth32.txt", + "../win/share/mon32.txt", "../win/share/obj32.txt", + "../win/share/oth32.txt", #else - "../win/share/monsters.txt", - "../win/share/objects.txt", - "../win/share/other.txt", + "../win/share/monsters.txt", "../win/share/objects.txt", + "../win/share/other.txt", #endif }; @@ -163,7 +163,7 @@ int tiles_in_row; int filenum; int initflag; int pass; -int yoffset,xoffset; +int yoffset, xoffset; char bmpname[128]; FILE *fp; @@ -172,190 +172,189 @@ main(argc, argv) int argc; char *argv[]; { - int i, j; + int i, j; - if (argc != 2) { - Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]); - exit(EXIT_FAILURE); - } else - strcpy(bmpname, argv[1]); + if (argc != 2) { + Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]); + exit(EXIT_FAILURE); + } else + strcpy(bmpname, argv[1]); #ifdef OBSOLETE - bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); - if (bmpfile2 == (FILE *)0) { - Fprintf(stderr, "Unable to open output file %s\n", - NETHACK_PACKED_TILEFILE); - exit(EXIT_FAILURE); - } + bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); + if (bmpfile2 == (FILE *) 0) { + Fprintf(stderr, "Unable to open output file %s\n", + NETHACK_PACKED_TILEFILE); + exit(EXIT_FAILURE); + } #endif - tilecount = 0; - xoffset = yoffset = 0; - initflag = 0; - filenum = 0; - pass = 0; - fp = fopen(bmpname,"wb"); - if (!fp) { - printf("Error creating tile file %s, aborting.\n",bmpname); - exit(1); - } - while (pass < 4) { - filenum =pass % (sizeof(tilefiles) / sizeof(char *)); - if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { - Fprintf(stderr, - "usage: tile2bmp (from the util directory)\n"); - exit(EXIT_FAILURE); - } - num_colors = colorsinmap; - if (num_colors > 62) { - Fprintf(stderr, "too many colors (%d)\n", num_colors); - exit(EXIT_FAILURE); - } - if (!initflag) { - build_bmfh(&bmp.bmfh); - build_bmih(&bmp.bmih); - for (i = 0; i < MAX_Y; ++i) - for (j = 0; j < MAX_X; ++j) - bmp.packtile[i][j] = (uchar)0; - for (i = 0; i < num_colors; i++) { - bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i]; - bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i]; - bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i]; - bmp.bmaColors[i].rgbReserved = 0; - } - initflag = 1; - } -/* printf("Colormap initialized\n"); */ - while (read_text_tile(tilepixels)) { - build_bmptile(tilepixels); - tilecount++; -#if BITCOUNT==4 - xoffset += (TILE_X / 2); + tilecount = 0; + xoffset = yoffset = 0; + initflag = 0; + filenum = 0; + pass = 0; + fp = fopen(bmpname, "wb"); + if (!fp) { + printf("Error creating tile file %s, aborting.\n", bmpname); + exit(1); + } + while (pass < 4) { + filenum = pass % (sizeof(tilefiles) / sizeof(char *)); + if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { + Fprintf(stderr, "usage: tile2bmp (from the util directory)\n"); + exit(EXIT_FAILURE); + } + num_colors = colorsinmap; + if (num_colors > 62) { + Fprintf(stderr, "too many colors (%d)\n", num_colors); + exit(EXIT_FAILURE); + } + if (!initflag) { + build_bmfh(&bmp.bmfh); + build_bmih(&bmp.bmih); + for (i = 0; i < MAX_Y; ++i) + for (j = 0; j < MAX_X; ++j) + bmp.packtile[i][j] = (uchar) 0; + for (i = 0; i < num_colors; i++) { + bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i]; + bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i]; + bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i]; + bmp.bmaColors[i].rgbReserved = 0; + } + initflag = 1; + } + /* printf("Colormap initialized\n"); */ + while (read_text_tile(tilepixels)) { + build_bmptile(tilepixels); + tilecount++; +#if BITCOUNT == 4 + xoffset += (TILE_X / 2); #else - xoffset += TILE_X; + xoffset += TILE_X; #endif - if (xoffset >= MAX_X) { - yoffset += TILE_Y; - xoffset = 0; - } - } - (void) fclose_text_file(); - ++pass; - } - fwrite(&bmp, sizeof(bmp), 1, fp); - fclose(fp); - Fprintf(stderr, "Total of %d tiles written to %s.\n", - tilecount, bmpname); + if (xoffset >= MAX_X) { + yoffset += TILE_Y; + xoffset = 0; + } + } + (void) fclose_text_file(); + ++pass; + } + fwrite(&bmp, sizeof(bmp), 1, fp); + fclose(fp); + Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname); - exit(EXIT_SUCCESS); - /*NOTREACHED*/ - return 0; + exit(EXIT_SUCCESS); + /*NOTREACHED*/ + return 0; } - static void build_bmfh(pbmfh) BITMAPFILEHEADER *pbmfh; { - pbmfh->bfType = leshort(0x4D42); - pbmfh->bfSize = lelong(BMPFILESIZE); - pbmfh->bfReserved1 = (UINT)0; - pbmfh->bfReserved2 = (UINT)0; - pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih) + - (RGBQUAD_COUNT * sizeof(RGBQUAD))); + pbmfh->bfType = leshort(0x4D42); + pbmfh->bfSize = lelong(BMPFILESIZE); + pbmfh->bfReserved1 = (UINT) 0; + pbmfh->bfReserved2 = (UINT) 0; + pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih) + + (RGBQUAD_COUNT * sizeof(RGBQUAD))); } static void build_bmih(pbmih) BITMAPINFOHEADER *pbmih; { - WORD cClrBits; - int w,h; - pbmih->biSize = lelong(sizeof(bmp.bmih)); -#if BITCOUNT==4 - pbmih->biWidth = lelong(w = MAX_X * 2); + WORD cClrBits; + int w, h; + pbmih->biSize = lelong(sizeof(bmp.bmih)); +#if BITCOUNT == 4 + pbmih->biWidth = lelong(w = MAX_X * 2); #else - pbmih->biWidth = lelong(w = MAX_X); + pbmih->biWidth = lelong(w = MAX_X); #endif - pbmih->biHeight = lelong(h = MAX_Y); - pbmih->biPlanes = leshort(1); -#if BITCOUNT==4 - pbmih->biBitCount = leshort(4); - cClrBits = 4; + pbmih->biHeight = lelong(h = MAX_Y); + pbmih->biPlanes = leshort(1); +#if BITCOUNT == 4 + pbmih->biBitCount = leshort(4); + cClrBits = 4; #else - pbmih->biBitCount = leshort(8); - cClrBits = 8; + pbmih->biBitCount = leshort(8); + cClrBits = 8; #endif - if (cClrBits == 1) - cClrBits = 1; - else if (cClrBits <= 4) - cClrBits = 4; - else if (cClrBits <= 8) - cClrBits = 8; - else if (cClrBits <= 16) - cClrBits = 16; - else if (cClrBits <= 24) - cClrBits = 24; - else cClrBits = 32; - pbmih->biCompression = lelong(BI_RGB); - pbmih->biXPelsPerMeter = lelong(0); - pbmih->biYPelsPerMeter = lelong(0); -#if (TILE_X==32) - if (cClrBits < 24) - pbmih->biClrUsed = lelong(1<biCompression = lelong(BI_RGB); + pbmih->biXPelsPerMeter = lelong(0); + pbmih->biYPelsPerMeter = lelong(0); +#if (TILE_X == 32) + if (cClrBits < 24) + pbmih->biClrUsed = lelong(1 << cClrBits); #else - pbmih->biClrUsed = lelong(RGBQUAD_COUNT); + pbmih->biClrUsed = lelong(RGBQUAD_COUNT); #endif -#if (TILE_X==16) - /* pbmih->biSizeImage = lelong(0); */ - pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h); +#if (TILE_X == 16) + /* pbmih->biSizeImage = lelong(0); */ + pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h); #else - pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h); + pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h); #endif - pbmih->biClrImportant = (DWORD)0; + pbmih->biClrImportant = (DWORD) 0; } static int graymappings[] = { -/* . A B C D E F G H I J K L M N O P */ - 0, 1,17,18,19,20,27,22,23,24,25,26,21,15,13,14,14}; + /* . A B C D E F G H I J K L M N O P */ + 0, 1, 17, 18, 19, 20, 27, 22, 23, 24, 25, 26, 21, 15, 13, 14, 14 +}; static void build_bmptile(pixels) pixel (*pixels)[TILE_X]; { - int cur_x, cur_y, cur_color, apply_color; - int x,y; + int cur_x, cur_y, cur_color, apply_color; + int x, y; - for (cur_y = 0; cur_y < TILE_Y; cur_y++) { - for (cur_x = 0; cur_x < TILE_X; cur_x++) { - for (cur_color = 0; cur_color < num_colors; cur_color++) { - if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r && - ColorMap[CM_GREEN][cur_color]== pixels[cur_y][cur_x].g && - ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b) - break; - } - if (cur_color >= num_colors) - Fprintf(stderr, "color not in colormap!\n"); - y = (MAX_Y - 1) - (cur_y + yoffset); - apply_color = cur_color; - if (pass == 3) { - /* map to shades of gray */ - if (cur_color > (SIZE(graymappings)-1)) - Fprintf(stderr, "Gray mapping issue %d %d.\n", - cur_color, SIZE(graymappings)-1); - else - apply_color = graymappings[cur_color]; - } -#if BITCOUNT==4 - x = (cur_x / 2) + xoffset; - bmp.packtile[y][x] = cur_x%2 ? - (uchar)(bmp.packtile[y][x] | cur_color) : - (uchar)(cur_color<<4); + for (cur_y = 0; cur_y < TILE_Y; cur_y++) { + for (cur_x = 0; cur_x < TILE_X; cur_x++) { + for (cur_color = 0; cur_color < num_colors; cur_color++) { + if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r + && ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g + && ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b) + break; + } + if (cur_color >= num_colors) + Fprintf(stderr, "color not in colormap!\n"); + y = (MAX_Y - 1) - (cur_y + yoffset); + apply_color = cur_color; + if (pass == 3) { + /* map to shades of gray */ + if (cur_color > (SIZE(graymappings) - 1)) + Fprintf(stderr, "Gray mapping issue %d %d.\n", cur_color, + SIZE(graymappings) - 1); + else + apply_color = graymappings[cur_color]; + } +#if BITCOUNT == 4 + x = (cur_x / 2) + xoffset; + bmp.packtile[y][x] = cur_x % 2 + ? (uchar)(bmp.packtile[y][x] | cur_color) + : (uchar)(cur_color << 4); #else - x = cur_x + xoffset; - bmp.packtile[y][x] = (uchar)apply_color; + x = cur_x + xoffset; + bmp.packtile[y][x] = (uchar) apply_color; #endif - } - } + } + } } diff --git a/win/share/tilemap.c b/win/share/tilemap.c index 071b58244..5c90fc56d 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tilemap.c $NHDT-Date: 1431183539 2015/05/09 14:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */ +/* NetHack 3.6 tilemap.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */ /* SCCS Id: @(#)tilemap.c 3.5 2000/06/04 */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,7 +10,7 @@ #include "hack.h" -const char * FDECL(tilename, (int, int)); +const char *FDECL(tilename, (int, int)); void NDECL(init_tilemap); void FDECL(process_substitutions, (FILE *)); @@ -27,50 +27,49 @@ extern void FDECL(exit, (int)); #define MON_GLYPH 1 #define OBJ_GLYPH 2 -#define OTH_GLYPH 3 /* fortunately unnecessary */ +#define OTH_GLYPH 3 /* fortunately unnecessary */ /* note that the ifdefs here should be the opposite sense from monst.c/ * objects.c/rm.h */ struct conditionals { - int sequence, predecessor; - const char *name; + int sequence, predecessor; + const char *name; } conditionals[] = { #ifndef CHARON /* not supported yet */ - { MON_GLYPH, PM_HELL_HOUND, "Cerberus" }, + { MON_GLYPH, PM_HELL_HOUND, "Cerberus" }, #endif - /* commented out in monst.c at present */ - { MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" }, - { MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" }, - { MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" }, - { MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" }, - { MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" }, + /* commented out in monst.c at present */ + { MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" }, + { MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" }, + { MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" }, + { MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" }, + { MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" }, #ifndef CHARON /* not supported yet */ - { MON_GLYPH, PM_CROESUS, "Charon" }, + { MON_GLYPH, PM_CROESUS, "Charon" }, #endif #ifndef MAIL - { MON_GLYPH, PM_FAMINE, "mail daemon" }, + { MON_GLYPH, PM_FAMINE, "mail daemon" }, #endif - /* commented out in monst.c at present */ - { MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" }, - { MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" }, - /* commented out in monst.c at present */ - { MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" }, - { MON_GLYPH, PM_NEANDERTHAL, "High-elf" }, - /* objects commented out in objects.c at present */ - { OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" }, - { OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" }, - /* allow slime mold to look like slice of pizza, since we - * don't know what a slime mold should look like when renamed anyway - */ + /* commented out in monst.c at present */ + { MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" }, + { MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" }, + /* commented out in monst.c at present */ + { MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" }, + { MON_GLYPH, PM_NEANDERTHAL, "High-elf" }, + /* objects commented out in objects.c at present */ + { OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" }, + { OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" }, +/* allow slime mold to look like slice of pizza, since we + * don't know what a slime mold should look like when renamed anyway + */ #ifndef MAIL - { OBJ_GLYPH, SCR_STINKING_CLOUD+4, "stamped / mail" }, + { OBJ_GLYPH, SCR_STINKING_CLOUD + 4, "stamped / mail" }, #endif - { 0, 0, 0} + { 0, 0, 0 } }; - /* * Some entries in glyph2tile[] should be substituted for on various levels. * The tiles used for the substitute entries will follow the usual ones in @@ -80,20 +79,17 @@ struct conditionals { * overlap in the future. */ struct substitute { - int first_glyph, last_glyph; - const char *sub_name; /* for explanations */ - const char *level_test; -} substitutes[] = { - { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, - "mine walls", "In_mines(plev)" }, - { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, - "gehennom walls", "In_hell(plev)" }, - { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, - "knox walls", "Is_knox(plev)" }, - { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, - "sokoban walls", "In_sokoban(plev)" } -}; - + int first_glyph, last_glyph; + const char *sub_name; /* for explanations */ + const char *level_test; +} substitutes[] = { { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, + "mine walls", "In_mines(plev)" }, + { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, + "gehennom walls", "In_hell(plev)" }, + { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, + "knox walls", "Is_knox(plev)" }, + { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall, + "sokoban walls", "In_sokoban(plev)" } }; #ifdef TILETEXT @@ -104,140 +100,139 @@ const char * tilename(set, entry) int set, entry; { - int i, j, condnum, tilenum; - static char buf[BUFSZ]; + int i, j, condnum, tilenum; + static char buf[BUFSZ]; - /* Note: these initializers don't do anything except guarantee that - we're linked properly. - */ - monst_init(); - objects_init(); - (void) def_char_to_objclass(']'); + /* Note: these initializers don't do anything except guarantee that + we're linked properly. + */ + monst_init(); + objects_init(); + (void) def_char_to_objclass(']'); - condnum = tilenum = 0; + condnum = tilenum = 0; - for (i = 0; i < NUMMONS; i++) { - if (set == MON_GLYPH && tilenum == entry) - return mons[i].mname; - tilenum++; - while (conditionals[condnum].sequence == MON_GLYPH && - conditionals[condnum].predecessor == i) { - if (set == MON_GLYPH && tilenum == entry) - return conditionals[condnum].name; - condnum++; - tilenum++; - } - } - if (set == MON_GLYPH && tilenum == entry) - return "invisible monster"; + for (i = 0; i < NUMMONS; i++) { + if (set == MON_GLYPH && tilenum == entry) + return mons[i].mname; + tilenum++; + while (conditionals[condnum].sequence == MON_GLYPH + && conditionals[condnum].predecessor == i) { + if (set == MON_GLYPH && tilenum == entry) + return conditionals[condnum].name; + condnum++; + tilenum++; + } + } + if (set == MON_GLYPH && tilenum == entry) + return "invisible monster"; - tilenum = 0; /* set-relative number */ - for (i = 0; i < NUM_OBJECTS; i++) { - /* prefer to give the description - that's all the tile's - * appearance should reveal */ - if (set == OBJ_GLYPH && tilenum == entry) { - if ( !obj_descr[i].oc_descr ) - return obj_descr[i].oc_name; - if ( !obj_descr[i].oc_name ) - return obj_descr[i].oc_descr; + tilenum = 0; /* set-relative number */ + for (i = 0; i < NUM_OBJECTS; i++) { + /* prefer to give the description - that's all the tile's + * appearance should reveal */ + if (set == OBJ_GLYPH && tilenum == entry) { + if (!obj_descr[i].oc_descr) + return obj_descr[i].oc_name; + if (!obj_descr[i].oc_name) + return obj_descr[i].oc_descr; - Sprintf(buf, "%s / %s", - obj_descr[i].oc_descr, - obj_descr[i].oc_name); - return buf; - } + Sprintf(buf, "%s / %s", obj_descr[i].oc_descr, + obj_descr[i].oc_name); + return buf; + } - tilenum++; - while (conditionals[condnum].sequence == OBJ_GLYPH && - conditionals[condnum].predecessor == i) { - if (set == OBJ_GLYPH && tilenum == entry) - return conditionals[condnum].name; - condnum++; - tilenum++; - } - } + tilenum++; + while (conditionals[condnum].sequence == OBJ_GLYPH + && conditionals[condnum].predecessor == i) { + if (set == OBJ_GLYPH && tilenum == entry) + return conditionals[condnum].name; + condnum++; + tilenum++; + } + } - tilenum = 0; /* set-relative number */ - for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) { - if (set == OTH_GLYPH && tilenum == entry) { - if (*defsyms[i].explanation) { - return defsyms[i].explanation; + tilenum = 0; /* set-relative number */ + for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) { + if (set == OTH_GLYPH && tilenum == entry) { + if (*defsyms[i].explanation) { + return defsyms[i].explanation; } else { Sprintf(buf, "cmap %d", tilenum); - return buf; - } - } - tilenum++; - while (conditionals[condnum].sequence == OTH_GLYPH && - conditionals[condnum].predecessor == i) { - if (set == OTH_GLYPH && tilenum == entry) - return conditionals[condnum].name; - condnum++; - tilenum++; - } - } - /* explosions */ - tilenum = MAXPCHARS - MAXEXPCHARS; - i = entry - tilenum; - if (i < (MAXEXPCHARS * EXPL_MAX)) { - if (set == OTH_GLYPH) { - static const char *explosion_types[] = { /* hack.h */ - "dark", "noxious", "muddy", "wet", - "magical", "fiery", "frosty" - }; - Sprintf(buf, "explosion %s %d", - explosion_types[i / MAXEXPCHARS], i % MAXEXPCHARS); - return buf; - } - } - tilenum += (MAXEXPCHARS * EXPL_MAX); + return buf; + } + } + tilenum++; + while (conditionals[condnum].sequence == OTH_GLYPH + && conditionals[condnum].predecessor == i) { + if (set == OTH_GLYPH && tilenum == entry) + return conditionals[condnum].name; + condnum++; + tilenum++; + } + } + /* explosions */ + tilenum = MAXPCHARS - MAXEXPCHARS; + i = entry - tilenum; + if (i < (MAXEXPCHARS * EXPL_MAX)) { + if (set == OTH_GLYPH) { + static const char *explosion_types[] = { + /* hack.h */ + "dark", "noxious", "muddy", "wet", "magical", "fiery", + "frosty" + }; + Sprintf(buf, "explosion %s %d", explosion_types[i / MAXEXPCHARS], + i % MAXEXPCHARS); + return buf; + } + } + tilenum += (MAXEXPCHARS * EXPL_MAX); - i = entry - tilenum; - if (i < (NUM_ZAP << 2)) { - if (set == OTH_GLYPH) { - Sprintf(buf, "zap %d %d", i/4, i%4); - return buf; - } - } - tilenum += (NUM_ZAP << 2); + i = entry - tilenum; + if (i < (NUM_ZAP << 2)) { + if (set == OTH_GLYPH) { + Sprintf(buf, "zap %d %d", i / 4, i % 4); + return buf; + } + } + tilenum += (NUM_ZAP << 2); - i = entry - tilenum; - if (i < WARNCOUNT) { - if (set == OTH_GLYPH) { - Sprintf(buf, "warning %d", i); - return buf; - } - } - tilenum += WARNCOUNT; + i = entry - tilenum; + if (i < WARNCOUNT) { + if (set == OTH_GLYPH) { + Sprintf(buf, "warning %d", i); + return buf; + } + } + tilenum += WARNCOUNT; - for (i = 0; i < SIZE(substitutes); i++) { - j = entry - tilenum; - if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) { - if (set == OTH_GLYPH) { - Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j); - return buf; - } - } - tilenum += substitutes[i].last_glyph - - substitutes[i].first_glyph + 1; - } + for (i = 0; i < SIZE(substitutes); i++) { + j = entry - tilenum; + if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) { + if (set == OTH_GLYPH) { + Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j); + return buf; + } + } + tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; + } - Sprintf(buf, "unknown %d %d", set, entry); - return buf; + Sprintf(buf, "unknown %d %d", set, entry); + return buf; } -#else /* TILETEXT */ +#else /* TILETEXT */ -#define TILE_FILE "tile.c" +#define TILE_FILE "tile.c" #ifdef AMIGA -# define SOURCE_TEMPLATE "NH:src/%s" +#define SOURCE_TEMPLATE "NH:src/%s" #else -# ifdef MAC -# define SOURCE_TEMPLATE ":src:%s" -# else -# define SOURCE_TEMPLATE "../src/%s" -# endif +#ifdef MAC +#define SOURCE_TEMPLATE ":src:%s" +#else +#define SOURCE_TEMPLATE "../src/%s" +#endif #endif short tilemap[MAX_GLYPH]; @@ -264,229 +259,215 @@ int lastmontile, lastobjtile, lastothtile; void init_tilemap() { - int i, j, condnum, tilenum; - int corpsetile, swallowbase; + int i, j, condnum, tilenum; + int corpsetile, swallowbase; - for (i = 0; i < MAX_GLYPH; i++) { - tilemap[i] = -1; - } + for (i = 0; i < MAX_GLYPH; i++) { + tilemap[i] = -1; + } - corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE; - swallowbase= NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl; + corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE; + swallowbase = NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl; - /* add number compiled out */ - for (i = 0; conditionals[i].sequence; i++) { - switch (conditionals[i].sequence) { - case MON_GLYPH: - corpsetile++; - swallowbase++; - break; - case OBJ_GLYPH: - if (conditionals[i].predecessor < CORPSE) - corpsetile++; - swallowbase++; - break; - case OTH_GLYPH: - if (conditionals[i].predecessor < S_sw_tl) - swallowbase++; - break; - } - } + /* add number compiled out */ + for (i = 0; conditionals[i].sequence; i++) { + switch (conditionals[i].sequence) { + case MON_GLYPH: + corpsetile++; + swallowbase++; + break; + case OBJ_GLYPH: + if (conditionals[i].predecessor < CORPSE) + corpsetile++; + swallowbase++; + break; + case OTH_GLYPH: + if (conditionals[i].predecessor < S_sw_tl) + swallowbase++; + break; + } + } - condnum = tilenum = 0; - for (i = 0; i < NUMMONS; i++) { - tilemap[GLYPH_MON_OFF+i] = tilenum; - tilemap[GLYPH_PET_OFF+i] = tilenum; - tilemap[GLYPH_DETECT_OFF+i] = tilenum; - tilemap[GLYPH_RIDDEN_OFF+i] = tilenum; - tilemap[GLYPH_BODY_OFF+i] = corpsetile; - j = GLYPH_SWALLOW_OFF + 8*i; - tilemap[j] = swallowbase; - tilemap[j+1] = swallowbase+1; - tilemap[j+2] = swallowbase+2; - tilemap[j+3] = swallowbase+3; - tilemap[j+4] = swallowbase+4; - tilemap[j+5] = swallowbase+5; - tilemap[j+6] = swallowbase+6; - tilemap[j+7] = swallowbase+7; - tilenum++; - while (conditionals[condnum].sequence == MON_GLYPH && - conditionals[condnum].predecessor == i) { - condnum++; - tilenum++; - } - } - tilemap[GLYPH_INVISIBLE] = tilenum++; - lastmontile = tilenum - 1; + condnum = tilenum = 0; + for (i = 0; i < NUMMONS; i++) { + tilemap[GLYPH_MON_OFF + i] = tilenum; + tilemap[GLYPH_PET_OFF + i] = tilenum; + tilemap[GLYPH_DETECT_OFF + i] = tilenum; + tilemap[GLYPH_RIDDEN_OFF + i] = tilenum; + tilemap[GLYPH_BODY_OFF + i] = corpsetile; + j = GLYPH_SWALLOW_OFF + 8 * i; + tilemap[j] = swallowbase; + tilemap[j + 1] = swallowbase + 1; + tilemap[j + 2] = swallowbase + 2; + tilemap[j + 3] = swallowbase + 3; + tilemap[j + 4] = swallowbase + 4; + tilemap[j + 5] = swallowbase + 5; + tilemap[j + 6] = swallowbase + 6; + tilemap[j + 7] = swallowbase + 7; + tilenum++; + while (conditionals[condnum].sequence == MON_GLYPH + && conditionals[condnum].predecessor == i) { + condnum++; + tilenum++; + } + } + tilemap[GLYPH_INVISIBLE] = tilenum++; + lastmontile = tilenum - 1; - for (i = 0; i < NUM_OBJECTS; i++) { - tilemap[GLYPH_OBJ_OFF+i] = tilenum; - tilenum++; - while (conditionals[condnum].sequence == OBJ_GLYPH && - conditionals[condnum].predecessor == i) { - condnum++; - tilenum++; - } - } - lastobjtile = tilenum - 1; + for (i = 0; i < NUM_OBJECTS; i++) { + tilemap[GLYPH_OBJ_OFF + i] = tilenum; + tilenum++; + while (conditionals[condnum].sequence == OBJ_GLYPH + && conditionals[condnum].predecessor == i) { + condnum++; + tilenum++; + } + } + lastobjtile = tilenum - 1; - for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) { - tilemap[GLYPH_CMAP_OFF+i] = tilenum; - tilenum++; - while (conditionals[condnum].sequence == OTH_GLYPH && - conditionals[condnum].predecessor == i) { - condnum++; - tilenum++; - } - } + for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) { + tilemap[GLYPH_CMAP_OFF + i] = tilenum; + tilenum++; + while (conditionals[condnum].sequence == OTH_GLYPH + && conditionals[condnum].predecessor == i) { + condnum++; + tilenum++; + } + } - for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) { - tilemap[GLYPH_EXPLODE_OFF+i] = tilenum; - tilenum++; - while (conditionals[condnum].sequence == OTH_GLYPH && - conditionals[condnum].predecessor == (i + MAXPCHARS)) { - condnum++; - tilenum++; - } - } + for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) { + tilemap[GLYPH_EXPLODE_OFF + i] = tilenum; + tilenum++; + while (conditionals[condnum].sequence == OTH_GLYPH + && conditionals[condnum].predecessor == (i + MAXPCHARS)) { + condnum++; + tilenum++; + } + } - for (i = 0; i < NUM_ZAP << 2; i++) { - tilemap[GLYPH_ZAP_OFF+i] = tilenum; - tilenum++; - while (conditionals[condnum].sequence == OTH_GLYPH && - conditionals[condnum].predecessor == (i + MAXEXPCHARS)) { - condnum++; - tilenum++; - } - } + for (i = 0; i < NUM_ZAP << 2; i++) { + tilemap[GLYPH_ZAP_OFF + i] = tilenum; + tilenum++; + while (conditionals[condnum].sequence == OTH_GLYPH + && conditionals[condnum].predecessor == (i + MAXEXPCHARS)) { + condnum++; + tilenum++; + } + } - for (i = 0; i < WARNCOUNT; i++) { - tilemap[GLYPH_WARNING_OFF+i] = tilenum; - tilenum++; - } + for (i = 0; i < WARNCOUNT; i++) { + tilemap[GLYPH_WARNING_OFF + i] = tilenum; + tilenum++; + } #ifndef STATUES_LOOK_LIKE_MONSTERS - /* statue patch: statues still use the same glyph as in vanilla */ - - for ( i = 0; i < NUMMONS; i++) { - tilemap[GLYPH_STATUE_OFF+i] = tilemap[GLYPH_OBJ_OFF+STATUE]; - } + /* statue patch: statues still use the same glyph as in vanilla */ + + for (i = 0; i < NUMMONS; i++) { + tilemap[GLYPH_STATUE_OFF + i] = tilemap[GLYPH_OBJ_OFF + STATUE]; + } #endif - lastothtile = tilenum - 1; - + lastothtile = tilenum - 1; + #ifdef STATUES_LOOK_LIKE_MONSTERS - /* skip over the substitutes to get to the grayscale statues */ - for (i = 0; i < SIZE(substitutes); i++) { - tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; - } + /* skip over the substitutes to get to the grayscale statues */ + for (i = 0; i < SIZE(substitutes); i++) { + tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; + } - /* statue patch: statues look more like the monster */ - condnum = 0; /* doing monsters again, so reset */ - for (i = 0; i < NUMMONS; i++) { - tilemap[GLYPH_STATUE_OFF+i] = tilenum; - tilenum++; - while (conditionals[condnum].sequence == MON_GLYPH && - conditionals[condnum].predecessor == i) { - condnum++; - tilenum++; - } - } - laststatuetile = tilenum - 1; + /* statue patch: statues look more like the monster */ + condnum = 0; /* doing monsters again, so reset */ + for (i = 0; i < NUMMONS; i++) { + tilemap[GLYPH_STATUE_OFF + i] = tilenum; + tilenum++; + while (conditionals[condnum].sequence == MON_GLYPH + && conditionals[condnum].predecessor == i) { + condnum++; + tilenum++; + } + } + laststatuetile = tilenum - 1; #endif - } -const char *prolog[] = { - "", - "", - "void", - "substitute_tiles(plev)", - "d_level *plev;", - "{", - "\tint i;", - "" -}; +const char *prolog[] = { "", "", "void", "substitute_tiles(plev)", + "d_level *plev;", "{", "\tint i;", "" }; -const char *epilog[] = { - "}" -}; +const char *epilog[] = { "}" }; /* write out the substitutions in an easily-used form. */ void process_substitutions(ofp) FILE *ofp; { - int i, j, k, span, start; + int i, j, k, span, start; - fprintf(ofp, "\n\n"); + fprintf(ofp, "\n\n"); - j = 0; /* unnecessary */ - span = -1; - for (i = 0; i < SIZE(substitutes); i++) { - if (i == 0 - || substitutes[i].first_glyph != substitutes[j].first_glyph - || substitutes[i].last_glyph != substitutes[j].last_glyph) { - j = i; - span++; - fprintf(ofp, "short std_tiles%d[] = { ", span); - for (k = substitutes[i].first_glyph; - k < substitutes[i].last_glyph; k++) - fprintf(ofp, "%d, ", tilemap[k]); - fprintf(ofp, "%d };\n", - tilemap[substitutes[i].last_glyph]); - } - } + j = 0; /* unnecessary */ + span = -1; + for (i = 0; i < SIZE(substitutes); i++) { + if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph + || substitutes[i].last_glyph != substitutes[j].last_glyph) { + j = i; + span++; + fprintf(ofp, "short std_tiles%d[] = { ", span); + for (k = substitutes[i].first_glyph; + k < substitutes[i].last_glyph; k++) + fprintf(ofp, "%d, ", tilemap[k]); + fprintf(ofp, "%d };\n", tilemap[substitutes[i].last_glyph]); + } + } - for (i = 0; i < SIZE(prolog); i++) { - fprintf(ofp, "%s\n", prolog[i]); - } - j = -1; - span = -1; - start = lastothtile + 1; - for (i = 0; i < SIZE(substitutes); i++) { - if (i == 0 - || substitutes[i].first_glyph != substitutes[j].first_glyph - || substitutes[i].last_glyph != substitutes[j].last_glyph) { - if (i != 0) { /* finish previous span */ - fprintf(ofp, "\t} else {\n"); - fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", - substitutes[j].first_glyph, - substitutes[j].last_glyph); - fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", - span, substitutes[j].first_glyph); - fprintf(ofp, "\t}\n\n"); - } - j = i; - span++; - } - if (i != j) fprintf(ofp, "\t} else "); - fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test); - fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", - substitutes[i].first_glyph, - substitutes[i].last_glyph); - fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n", - start, substitutes[i].first_glyph); - start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; - } - /* finish last span */ - fprintf(ofp, "\t} else {\n"); - fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", - substitutes[j].first_glyph, - substitutes[j].last_glyph); - fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", - span, substitutes[j].first_glyph); - fprintf(ofp, "\t}\n\n"); + for (i = 0; i < SIZE(prolog); i++) { + fprintf(ofp, "%s\n", prolog[i]); + } + j = -1; + span = -1; + start = lastothtile + 1; + for (i = 0; i < SIZE(substitutes); i++) { + if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph + || substitutes[i].last_glyph != substitutes[j].last_glyph) { + if (i != 0) { /* finish previous span */ + fprintf(ofp, "\t} else {\n"); + fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", + substitutes[j].first_glyph, + substitutes[j].last_glyph); + fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", + span, substitutes[j].first_glyph); + fprintf(ofp, "\t}\n\n"); + } + j = i; + span++; + } + if (i != j) + fprintf(ofp, "\t} else "); + fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test); + fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", + substitutes[i].first_glyph, substitutes[i].last_glyph); + fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n", start, + substitutes[i].first_glyph); + start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; + } + /* finish last span */ + fprintf(ofp, "\t} else {\n"); + fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", + substitutes[j].first_glyph, substitutes[j].last_glyph); + fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", span, + substitutes[j].first_glyph); + fprintf(ofp, "\t}\n\n"); - for (i = 0; i < SIZE(epilog); i++) { - fprintf(ofp, "%s\n", epilog[i]); - } + for (i = 0; i < SIZE(epilog); i++) { + fprintf(ofp, "%s\n", epilog[i]); + } - fprintf(ofp, "\nint total_tiles_used = %d;\n", start); - lastothtile = start - 1; + fprintf(ofp, "\nint total_tiles_used = %d;\n", start); + lastothtile = start - 1; } -int main() +int +main() { register int i; char filename[30]; @@ -499,25 +480,26 @@ int main() */ Sprintf(filename, SOURCE_TEMPLATE, TILE_FILE); if (!(ofp = fopen(filename, "w"))) { - perror(filename); - exit(EXIT_FAILURE); + perror(filename); + exit(EXIT_FAILURE); } - fprintf(ofp,"/* This file is automatically generated. Do not edit. */\n"); - fprintf(ofp,"\n#include \"hack.h\"\n\n"); - fprintf(ofp,"short glyph2tile[MAX_GLYPH] = {\n"); + fprintf(ofp, + "/* This file is automatically generated. Do not edit. */\n"); + fprintf(ofp, "\n#include \"hack.h\"\n\n"); + fprintf(ofp, "short glyph2tile[MAX_GLYPH] = {\n"); for (i = 0; i < MAX_GLYPH; i++) { - fprintf(ofp,"%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n'); + fprintf(ofp, "%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n'); } - fprintf(ofp,"%s};\n", (i % 12) ? "\n" : ""); + fprintf(ofp, "%s};\n", (i % 12) ? "\n" : ""); process_substitutions(ofp); - fprintf(ofp,"\n#define MAXMONTILE %d\n", lastmontile); - fprintf(ofp,"#define MAXOBJTILE %d\n", lastobjtile); - fprintf(ofp,"#define MAXOTHTILE %d\n", lastothtile); + fprintf(ofp, "\n#define MAXMONTILE %d\n", lastmontile); + fprintf(ofp, "#define MAXOBJTILE %d\n", lastobjtile); + fprintf(ofp, "#define MAXOTHTILE %d\n", lastothtile); - fprintf(ofp,"\n/*tile.c*/\n"); + fprintf(ofp, "\n/*tile.c*/\n"); fclose(ofp); exit(EXIT_SUCCESS); @@ -525,4 +507,4 @@ int main() return 0; } -#endif /* TILETEXT */ +#endif /* TILETEXT */ diff --git a/win/share/tiletext.c b/win/share/tiletext.c index c109d9162..7cd983226 100644 --- a/win/share/tiletext.c +++ b/win/share/tiletext.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 tiletext.c $NHDT-Date: 1430640200 2015/05/03 08:03:20 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */ +/* NetHack 3.6 tiletext.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */ /* NetHack 3.6 tiletext.c $Date: 2009/05/06 10:59:03 $ $Revision: 1.4 $ */ /* SCCS Id: @(#)tiletext.c 3.5 1999/10/24 */ /* NetHack may be freely redistributed. See license for details. */ @@ -19,41 +19,44 @@ static int placeholder_init = 0; static pixel placeholder[TILE_Y][TILE_X]; static FILE *tile_file; static int tile_set, tile_set_indx; -#if (TILE_X==8) -static const char *text_sets[] = { "monthin.txt", "objthin.txt", "oththin.txt" }; +#if (TILE_X == 8) +static const char *text_sets[] = { "monthin.txt", "objthin.txt", + "oththin.txt" }; #else -static const char *text_sets[] = { "monsters.txt", "objects.txt", "other.txt" }; +static const char *text_sets[] = { "monsters.txt", "objects.txt", + "other.txt" }; #endif extern const char *FDECL(tilename, (int, int)); static void FDECL(read_text_colormap, (FILE *)); static boolean FDECL(write_text_colormap, (FILE *)); -static boolean FDECL(read_txttile, (FILE *, pixel(*)[TILE_X])); -static void FDECL(write_txttile, (FILE *, pixel(*)[TILE_X])); +static boolean FDECL(read_txttile, (FILE *, pixel (*)[TILE_X])); +static void FDECL(write_txttile, (FILE *, pixel (*)[TILE_X])); /* Ugh. DICE doesn't like %[A-Z], so we have to spell it out... */ -#define FORMAT_STRING \ -"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = (%d, %d, %d) " +#define FORMAT_STRING \ + "%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = " \ + "(%d, %d, %d) " static void read_text_colormap(txtfile) FILE *txtfile; { - int i, r, g, b; - char c[2]; + int i, r, g, b; + char c[2]; - for (i = 0; i < MAXCOLORMAPSIZE; i++) - color_index[i] = -1; + for (i = 0; i < MAXCOLORMAPSIZE; i++) + color_index[i] = -1; - num_colors = 0; - while (fscanf(txtfile, FORMAT_STRING, c, &r, &g, &b) == 4) { - color_index[(int) c[0]] = num_colors; - ColorMap[CM_RED][num_colors] = r; - ColorMap[CM_GREEN][num_colors] = g; - ColorMap[CM_BLUE][num_colors] = b; - num_colors++; - } - colorsinmap = num_colors; + num_colors = 0; + while (fscanf(txtfile, FORMAT_STRING, c, &r, &g, &b) == 4) { + color_index[(int) c[0]] = num_colors; + ColorMap[CM_RED][num_colors] = r; + ColorMap[CM_GREEN][num_colors] = g; + ColorMap[CM_BLUE][num_colors] = b; + num_colors++; + } + colorsinmap = num_colors; } #undef FORMAT_STRING @@ -62,26 +65,28 @@ static boolean write_text_colormap(txtfile) FILE *txtfile; { - int i; - char c; + int i; + char c; - num_colors = colorsinmainmap; - if (num_colors > 62) { - Fprintf(stderr, "too many colors (%d)\n", num_colors); - return FALSE; - } - for (i = 0; i < num_colors; i++) { - if (i < 26) c = 'A' + i; - else if (i < 52) c = 'a' + i - 26; - else c = '0' + i - 52; + num_colors = colorsinmainmap; + if (num_colors > 62) { + Fprintf(stderr, "too many colors (%d)\n", num_colors); + return FALSE; + } + for (i = 0; i < num_colors; i++) { + if (i < 26) + c = 'A' + i; + else if (i < 52) + c = 'a' + i - 26; + else + c = '0' + i - 52; - charcolors[i] = c; - Fprintf(txtfile, "%c = (%d, %d, %d)\n", c, - (int)MainColorMap[CM_RED][i], - (int)MainColorMap[CM_GREEN][i], - (int)MainColorMap[CM_BLUE][i]); - } - return TRUE; + charcolors[i] = c; + Fprintf( + txtfile, "%c = (%d, %d, %d)\n", c, (int) MainColorMap[CM_RED][i], + (int) MainColorMap[CM_GREEN][i], (int) MainColorMap[CM_BLUE][i]); + } + return TRUE; } static boolean @@ -89,82 +94,78 @@ read_txttile(txtfile, pixels) FILE *txtfile; pixel (*pixels)[TILE_X]; { - int ph, i, j, k; - char buf[BUFSZ], ttype[BUFSZ]; - const char *p; - char c[2]; + int ph, i, j, k; + char buf[BUFSZ], ttype[BUFSZ]; + const char *p; + char c[2]; - if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0) - return FALSE; - - ph = strcmp(ttype, "placeholder") == 0; + if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0) + return FALSE; - if (!ph && strcmp(ttype,"tile") != 0) - Fprintf(stderr, - "Keyword \"%s\" unexpected for entry %d\n", - ttype, i); + ph = strcmp(ttype, "placeholder") == 0; - if (tile_set != 0) { - /* check tile name, but not relative number, which will - * change when tiles are added - */ - p = tilename(tile_set, tile_set_indx); - if (p && strcmp(p, buf)) { - Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n", - tile_set_indx, i, text_sets[tile_set-1]); - Fprintf(stderr, "\tfound '%s' while expecting '%s'\n", - buf, p); - } - } - tile_set_indx++; - - /* look for non-whitespace at each stage */ - if (fscanf(txtfile, "%1s", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - if (c[0] != '{') { - Fprintf(stderr, "didn't find expected '{'\n"); - return FALSE; - } - for (j = 0; j < TILE_Y; j++) { - for (i = 0; i < TILE_X; i++) { - if (fscanf(txtfile, "%1s", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - k = color_index[(int) c[0]]; - if (k == -1) - Fprintf(stderr, - "color %c not in colormap!\n", c[0]); - else { - pixels[j][i].r = ColorMap[CM_RED][k]; - pixels[j][i].g = ColorMap[CM_GREEN][k]; - pixels[j][i].b = ColorMap[CM_BLUE][k]; - } - } - } - if ( ph ) { - /* remember it for later */ - memcpy( placeholder, pixels, sizeof(placeholder) ); - } - if (fscanf(txtfile, "%1s ", c) < 0) { - Fprintf(stderr, "unexpected EOF\n"); - return FALSE; - } - if (c[0] != '}') { - Fprintf(stderr, "didn't find expected '}'\n"); - return FALSE; - } + if (!ph && strcmp(ttype, "tile") != 0) + Fprintf(stderr, "Keyword \"%s\" unexpected for entry %d\n", ttype, i); + + if (tile_set != 0) { + /* check tile name, but not relative number, which will + * change when tiles are added + */ + p = tilename(tile_set, tile_set_indx); + if (p && strcmp(p, buf)) { + Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n", + tile_set_indx, i, text_sets[tile_set - 1]); + Fprintf(stderr, "\tfound '%s' while expecting '%s'\n", buf, p); + } + } + tile_set_indx++; + + /* look for non-whitespace at each stage */ + if (fscanf(txtfile, "%1s", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + if (c[0] != '{') { + Fprintf(stderr, "didn't find expected '{'\n"); + return FALSE; + } + for (j = 0; j < TILE_Y; j++) { + for (i = 0; i < TILE_X; i++) { + if (fscanf(txtfile, "%1s", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + k = color_index[(int) c[0]]; + if (k == -1) + Fprintf(stderr, "color %c not in colormap!\n", c[0]); + else { + pixels[j][i].r = ColorMap[CM_RED][k]; + pixels[j][i].g = ColorMap[CM_GREEN][k]; + pixels[j][i].b = ColorMap[CM_BLUE][k]; + } + } + } + if (ph) { + /* remember it for later */ + memcpy(placeholder, pixels, sizeof(placeholder)); + } + if (fscanf(txtfile, "%1s ", c) < 0) { + Fprintf(stderr, "unexpected EOF\n"); + return FALSE; + } + if (c[0] != '}') { + Fprintf(stderr, "didn't find expected '}'\n"); + return FALSE; + } #ifdef _DCC - /* DICE again... it doesn't seem to eat whitespace after the } like - * it should, so we have to do so manually. - */ - while ((*c = fgetc(txtfile)) != EOF && isspace(*c)) - ; - ungetc(*c, txtfile); + /* DICE again... it doesn't seem to eat whitespace after the } like + * it should, so we have to do so manually. + */ + while ((*c = fgetc(txtfile)) != EOF && isspace(*c)) + ; + ungetc(*c, txtfile); #endif - return TRUE; + return TRUE; } static void @@ -172,84 +173,84 @@ write_txttile(txtfile, pixels) FILE *txtfile; pixel (*pixels)[TILE_X]; { - const char *p; - const char *type; - int i, j, k; + const char *p; + const char *type; + int i, j, k; - if ( memcmp(placeholder, pixels, sizeof(placeholder)) == 0 ) - type = "placeholder"; - else - type = "tile"; + if (memcmp(placeholder, pixels, sizeof(placeholder)) == 0) + type = "placeholder"; + else + type = "tile"; - if (tile_set == 0) - Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx); - else { - p = tilename(tile_set, tile_set_indx); - if (p) - Fprintf(txtfile, "# %s %d (%s)\n", type, tile_set_indx, p); - else - Fprintf(txtfile, "# %s %d (null)\n", type, tile_set_indx); - } - tile_set_indx++; + if (tile_set == 0) + Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx); + else { + p = tilename(tile_set, tile_set_indx); + if (p) + Fprintf(txtfile, "# %s %d (%s)\n", type, tile_set_indx, p); + else + Fprintf(txtfile, "# %s %d (null)\n", type, tile_set_indx); + } + tile_set_indx++; - Fprintf(txtfile, "{\n"); - for (j = 0; j < TILE_Y; j++) { - Fprintf(txtfile, " "); - for (i = 0; i < TILE_X; i++) { - for (k = 0; k < num_colors; k++) { - if (ColorMap[CM_RED][k] == pixels[j][i].r && - ColorMap[CM_GREEN][k] == pixels[j][i].g && - ColorMap[CM_BLUE][k] == pixels[j][i].b) - break; - } - if (k >= num_colors) - Fprintf(stderr, "color not in colormap!\n"); - (void) fputc(charcolors[k], txtfile); - } - Fprintf(txtfile, "\n"); - } - Fprintf(txtfile, "}\n"); + Fprintf(txtfile, "{\n"); + for (j = 0; j < TILE_Y; j++) { + Fprintf(txtfile, " "); + for (i = 0; i < TILE_X; i++) { + for (k = 0; k < num_colors; k++) { + if (ColorMap[CM_RED][k] == pixels[j][i].r + && ColorMap[CM_GREEN][k] == pixels[j][i].g + && ColorMap[CM_BLUE][k] == pixels[j][i].b) + break; + } + if (k >= num_colors) + Fprintf(stderr, "color not in colormap!\n"); + (void) fputc(charcolors[k], txtfile); + } + Fprintf(txtfile, "\n"); + } + Fprintf(txtfile, "}\n"); } /* initialize main colormap from globally accessed ColorMap */ void init_colormap() { - int i; + int i; - colorsinmainmap = colorsinmap; - for (i = 0; i < colorsinmap; i++) { - MainColorMap[CM_RED][i] = ColorMap[CM_RED][i]; - MainColorMap[CM_GREEN][i] = ColorMap[CM_GREEN][i]; - MainColorMap[CM_BLUE][i] = ColorMap[CM_BLUE][i]; - } + colorsinmainmap = colorsinmap; + for (i = 0; i < colorsinmap; i++) { + MainColorMap[CM_RED][i] = ColorMap[CM_RED][i]; + MainColorMap[CM_GREEN][i] = ColorMap[CM_GREEN][i]; + MainColorMap[CM_BLUE][i] = ColorMap[CM_BLUE][i]; + } } /* merge new colors from ColorMap into MainColorMap */ void merge_colormap() { - int i, j; + int i, j; - for (i = 0; i < colorsinmap; i++) { - for (j = 0; j < colorsinmainmap; j++) { - if (MainColorMap[CM_RED][j] == ColorMap[CM_RED][i] && - MainColorMap[CM_GREEN][j] == ColorMap[CM_GREEN][i] && - MainColorMap[CM_BLUE][j] == ColorMap[CM_BLUE][i]) - break; - } - if (j >= colorsinmainmap) { /* new color */ - if (colorsinmainmap >= MAXCOLORMAPSIZE) { - Fprintf(stderr, - "Too many colors to merge -- excess ignored.\n"); - } - j = colorsinmainmap; - MainColorMap[CM_RED][j] = ColorMap[CM_RED][i]; - MainColorMap[CM_GREEN][j] = ColorMap[CM_GREEN][i]; - MainColorMap[CM_BLUE][j] = ColorMap[CM_BLUE][i]; - colorsinmainmap++; - } - } + for (i = 0; i < colorsinmap; i++) { + for (j = 0; j < colorsinmainmap; j++) { + if (MainColorMap[CM_RED][j] == ColorMap[CM_RED][i] + && MainColorMap[CM_GREEN][j] == ColorMap[CM_GREEN][i] + && MainColorMap[CM_BLUE][j] == ColorMap[CM_BLUE][i]) + break; + } + if (j >= colorsinmainmap) { /* new color */ + if (colorsinmainmap >= MAXCOLORMAPSIZE) { + Fprintf(stderr, + "Too many colors to merge -- excess ignored.\n"); + } + j = colorsinmainmap; + MainColorMap[CM_RED][j] = ColorMap[CM_RED][i]; + MainColorMap[CM_GREEN][j] = ColorMap[CM_GREEN][i]; + MainColorMap[CM_BLUE][j] = ColorMap[CM_BLUE][i]; + colorsinmainmap++; + } + } } boolean @@ -257,78 +258,80 @@ fopen_text_file(filename, type) const char *filename; const char *type; { - const char *p; - int i; + const char *p; + int i; - if (tile_file != (FILE *)0) { - Fprintf(stderr, "can only open one text file at at time\n"); - return FALSE; - } + if (tile_file != (FILE *) 0) { + Fprintf(stderr, "can only open one text file at at time\n"); + return FALSE; + } - tile_file = fopen(filename, type); - if (tile_file == (FILE *)0) { - Fprintf(stderr, "cannot open text file %s\n", filename); - return FALSE; - } + tile_file = fopen(filename, type); + if (tile_file == (FILE *) 0) { + Fprintf(stderr, "cannot open text file %s\n", filename); + return FALSE; + } - p = rindex(filename, '/'); - if (p) p++; - else p = filename; + p = rindex(filename, '/'); + if (p) + p++; + else + p = filename; - tile_set = 0; - for (i = 0; i < SIZE(text_sets); i++) { - if (!strcmp(p, text_sets[i])) - tile_set = i+1; - } - tile_set_indx = 0; + tile_set = 0; + for (i = 0; i < SIZE(text_sets); i++) { + if (!strcmp(p, text_sets[i])) + tile_set = i + 1; + } + tile_set_indx = 0; - if (!strcmp(type, RDTMODE)) { - /* Fill placeholder with noise */ - if ( !placeholder_init ) { - placeholder_init++; - for (i = 0; i < (int)sizeof placeholder; i++) - ((char *)placeholder)[i] = i % 256; - } + if (!strcmp(type, RDTMODE)) { + /* Fill placeholder with noise */ + if (!placeholder_init) { + placeholder_init++; + for (i = 0; i < (int) sizeof placeholder; i++) + ((char *) placeholder)[i] = i % 256; + } - read_text_colormap(tile_file); - if (!colorsinmainmap) - init_colormap(); - else - merge_colormap(); - return TRUE; - } else if (!strcmp(type, WRTMODE)) { - if (!colorsinmainmap) { - Fprintf(stderr, "no colormap set yet\n"); - return FALSE; - } - return(write_text_colormap(tile_file)); - } else { - Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type); - return FALSE; - } + read_text_colormap(tile_file); + if (!colorsinmainmap) + init_colormap(); + else + merge_colormap(); + return TRUE; + } else if (!strcmp(type, WRTMODE)) { + if (!colorsinmainmap) { + Fprintf(stderr, "no colormap set yet\n"); + return FALSE; + } + return (write_text_colormap(tile_file)); + } else { + Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type); + return FALSE; + } } boolean read_text_tile(pixels) pixel (*pixels)[TILE_X]; { - return(read_txttile(tile_file, pixels)); + return (read_txttile(tile_file, pixels)); } boolean write_text_tile(pixels) pixel (*pixels)[TILE_X]; { - write_txttile(tile_file, pixels); - return TRUE; + write_txttile(tile_file, pixels); + return TRUE; } int fclose_text_file() { - int ret; + int ret; - ret = fclose(tile_file); - tile_file = (FILE *)0; - return ret; + ret = fclose(tile_file); + tile_file = (FILE *) 0; + return ret; } diff --git a/win/tty/getline.c b/win/tty/getline.c index 80092ebf3..d8408099a 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 getline.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 getline.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.27 $ */ /* NetHack 3.6 getline.c $Date: 2011/12/11 01:54:56 $ $Revision: 1.18 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,15 +14,16 @@ #include "wintty.h" #include "func_tab.h" -char morc = 0; /* tell the outside world what char you chose */ +char morc = 0; /* tell the outside world what char you chose */ STATIC_DCL boolean FDECL(ext_cmd_getlin_hook, (char *)); typedef boolean FDECL((*getlin_hook_proc), (char *)); -STATIC_DCL void FDECL(hooked_tty_getlin, (const char*,char*,getlin_hook_proc)); -extern int NDECL(extcmd_via_menu); /* cmd.c */ +STATIC_DCL void FDECL(hooked_tty_getlin, + (const char *, char *, getlin_hook_proc)); +extern int NDECL(extcmd_via_menu); /* cmd.c */ -extern char erase_char, kill_char; /* from appropriate tty.c file */ +extern char erase_char, kill_char; /* from appropriate tty.c file */ /* * Read a line closed with '\n' into the array char bufp[BUFSZ]. @@ -44,166 +45,177 @@ const char *query; register char *bufp; getlin_hook_proc hook; { - register char *obufp = bufp; - register int c; - struct WinDesc *cw = wins[WIN_MESSAGE]; - boolean doprev = 0; + register char *obufp = bufp; + register int c; + struct WinDesc *cw = wins[WIN_MESSAGE]; + boolean doprev = 0; - if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); - cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = 3; /* special prompt state */ - ttyDisplay->inread++; - pline("%s ", query); - *obufp = 0; - for(;;) { - (void) fflush(stdout); - Strcat(strcat(strcpy(toplines, query), " "), obufp); - c = pgetchar(); - if (c == '\033' || c == EOF) { - if (c == '\033' && obufp[0] != '\0') { - obufp[0] = '\0'; - bufp = obufp; - tty_clear_nhwindow(WIN_MESSAGE); - cw->maxcol = cw->maxrow; - addtopl(query); - addtopl(" "); - addtopl(obufp); - } else { - obufp[0] = '\033'; - obufp[1] = '\0'; - break; - } - } - if (ttyDisplay->intr) { - ttyDisplay->intr--; - *bufp = 0; - } - if(c == '\020') { /* ctrl-P */ - if (iflags.prevmsg_window != 's') { - int sav = ttyDisplay->inread; - ttyDisplay->inread = 0; - (void) tty_doprev_message(); - ttyDisplay->inread = sav; - tty_clear_nhwindow(WIN_MESSAGE); - cw->maxcol = cw->maxrow; - addtopl(query); - addtopl(" "); - *bufp = 0; - addtopl(obufp); - } else { - if (!doprev) - (void) tty_doprev_message();/* need two initially */ - (void) tty_doprev_message(); - doprev = 1; - continue; - } - } else if (doprev && iflags.prevmsg_window == 's') { - tty_clear_nhwindow(WIN_MESSAGE); - cw->maxcol = cw->maxrow; - doprev = 0; - addtopl(query); - addtopl(" "); - *bufp = 0; - addtopl(obufp); - } - if(c == erase_char || c == '\b') { - if(bufp != obufp) { + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) + more(); + cw->flags &= ~WIN_STOP; + ttyDisplay->toplin = 3; /* special prompt state */ + ttyDisplay->inread++; + pline("%s ", query); + *obufp = 0; + for (;;) { + (void) fflush(stdout); + Strcat(strcat(strcpy(toplines, query), " "), obufp); + c = pgetchar(); + if (c == '\033' || c == EOF) { + if (c == '\033' && obufp[0] != '\0') { + obufp[0] = '\0'; + bufp = obufp; + tty_clear_nhwindow(WIN_MESSAGE); + cw->maxcol = cw->maxrow; + addtopl(query); + addtopl(" "); + addtopl(obufp); + } else { + obufp[0] = '\033'; + obufp[1] = '\0'; + break; + } + } + if (ttyDisplay->intr) { + ttyDisplay->intr--; + *bufp = 0; + } + if (c == '\020') { /* ctrl-P */ + if (iflags.prevmsg_window != 's') { + int sav = ttyDisplay->inread; + ttyDisplay->inread = 0; + (void) tty_doprev_message(); + ttyDisplay->inread = sav; + tty_clear_nhwindow(WIN_MESSAGE); + cw->maxcol = cw->maxrow; + addtopl(query); + addtopl(" "); + *bufp = 0; + addtopl(obufp); + } else { + if (!doprev) + (void) tty_doprev_message(); /* need two initially */ + (void) tty_doprev_message(); + doprev = 1; + continue; + } + } else if (doprev && iflags.prevmsg_window == 's') { + tty_clear_nhwindow(WIN_MESSAGE); + cw->maxcol = cw->maxrow; + doprev = 0; + addtopl(query); + addtopl(" "); + *bufp = 0; + addtopl(obufp); + } + if (c == erase_char || c == '\b') { + if (bufp != obufp) { #ifdef NEWAUTOCOMP - char *i; + char *i; #endif /* NEWAUTOCOMP */ - bufp--; + bufp--; #ifndef NEWAUTOCOMP - putsyms("\b \b");/* putsym converts \b */ -#else /* NEWAUTOCOMP */ - putsyms("\b"); - for (i = bufp; *i; ++i) putsyms(" "); - for (; i > bufp; --i) putsyms("\b"); - *bufp = 0; -#endif /* NEWAUTOCOMP */ - } else tty_nhbell(); + putsyms("\b \b"); /* putsym converts \b */ +#else /* NEWAUTOCOMP */ + putsyms("\b"); + for (i = bufp; *i; ++i) + putsyms(" "); + for (; i > bufp; --i) + putsyms("\b"); + *bufp = 0; +#endif /* NEWAUTOCOMP */ + } else + tty_nhbell(); #if defined(apollo) - } else if(c == '\n' || c == '\r') { + } else if (c == '\n' || c == '\r') { #else - } else if(c == '\n') { + } else if (c == '\n') { #endif #ifndef NEWAUTOCOMP - *bufp = 0; + *bufp = 0; #endif /* not NEWAUTOCOMP */ - break; - } else if(' ' <= (unsigned char) c && c != '\177' && - (bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) { - /* avoid isprint() - some people don't have it - ' ' is not always a printing char */ + break; + } else if (' ' <= (unsigned char) c && c != '\177' + && (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO)) { +/* avoid isprint() - some people don't have it + ' ' is not always a printing char */ #ifdef NEWAUTOCOMP - char *i = eos(bufp); + char *i = eos(bufp); #endif /* NEWAUTOCOMP */ - *bufp = c; - bufp[1] = 0; - putsyms(bufp); - bufp++; - if (hook && (*hook)(obufp)) { - putsyms(bufp); + *bufp = c; + bufp[1] = 0; + putsyms(bufp); + bufp++; + if (hook && (*hook)(obufp)) { + putsyms(bufp); #ifndef NEWAUTOCOMP - bufp = eos(bufp); -#else /* NEWAUTOCOMP */ - /* pointer and cursor left where they were */ - for (i = bufp; *i; ++i) putsyms("\b"); - } else if (i > bufp) { - char *s = i; + bufp = eos(bufp); +#else /* NEWAUTOCOMP */ + /* pointer and cursor left where they were */ + for (i = bufp; *i; ++i) + putsyms("\b"); + } else if (i > bufp) { + char *s = i; - /* erase rest of prior guess */ - for (; i > bufp; --i) putsyms(" "); - for (; s > bufp; --s) putsyms("\b"); + /* erase rest of prior guess */ + for (; i > bufp; --i) + putsyms(" "); + for (; s > bufp; --s) + putsyms("\b"); #endif /* NEWAUTOCOMP */ - } - } else if(c == kill_char || c == '\177') { /* Robert Viduya */ - /* this test last - @ might be the kill_char */ + } + } else if (c == kill_char || c == '\177') { /* Robert Viduya */ +/* this test last - @ might be the kill_char */ #ifndef NEWAUTOCOMP - while(bufp != obufp) { - bufp--; - putsyms("\b \b"); - } -#else /* NEWAUTOCOMP */ - for (; *bufp; ++bufp) putsyms(" "); - for (; bufp != obufp; --bufp) putsyms("\b \b"); - *bufp = 0; + while (bufp != obufp) { + bufp--; + putsyms("\b \b"); + } +#else /* NEWAUTOCOMP */ + for (; *bufp; ++bufp) + putsyms(" "); + for (; bufp != obufp; --bufp) + putsyms("\b \b"); + *bufp = 0; #endif /* NEWAUTOCOMP */ - } else - tty_nhbell(); - } - ttyDisplay->toplin = 2; /* nonempty, no --More-- required */ - ttyDisplay->inread--; - clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */ + } else + tty_nhbell(); + } + ttyDisplay->toplin = 2; /* nonempty, no --More-- required */ + ttyDisplay->inread--; + clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */ } void xwaitforspace(s) -register const char *s; /* chars allowed besides return */ +register const char *s; /* chars allowed besides return */ { register int c, x = ttyDisplay ? (int) ttyDisplay->dismiss_more : '\n'; morc = 0; while ( #ifdef HANGUPHANDLING - !program_state.done_hup && + !program_state.done_hup && #endif - (c = tty_nhgetch()) != EOF) { - if (c == '\n') break; + (c = tty_nhgetch()) != EOF) { + if (c == '\n') + break; - if(iflags.cbreak) { - if (c == '\033') { - if (ttyDisplay) ttyDisplay->dismiss_more = 1; - morc = '\033'; - break; - } - if ((s && index(s,c)) || c == x) { - morc = (char) c; - break; - } - tty_nhbell(); - } + if (iflags.cbreak) { + if (c == '\033') { + if (ttyDisplay) + ttyDisplay->dismiss_more = 1; + morc = '\033'; + break; + } + if ((s && index(s, c)) || c == x) { + morc = (char) c; + break; + } + tty_nhbell(); + } } } @@ -221,25 +233,25 @@ register const char *s; /* chars allowed besides return */ */ STATIC_OVL boolean ext_cmd_getlin_hook(base) - char *base; +char *base; { - int oindex, com_index; + int oindex, com_index; - com_index = -1; - for (oindex = 0; extcmdlist[oindex].ef_txt != (char *)0; oindex++) { - if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) { - if (com_index == -1) /* no matches yet */ - com_index = oindex; - else /* more than 1 match */ - return FALSE; - } - } - if (com_index >= 0) { - Strcpy(base, extcmdlist[com_index].ef_txt); - return TRUE; - } + com_index = -1; + for (oindex = 0; extcmdlist[oindex].ef_txt != (char *) 0; oindex++) { + if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) { + if (com_index == -1) /* no matches yet */ + com_index = oindex; + else /* more than 1 match */ + return FALSE; + } + } + if (com_index >= 0) { + Strcpy(base, extcmdlist[com_index].ef_txt); + return TRUE; + } - return FALSE; /* didn't match anything */ + return FALSE; /* didn't match anything */ } /* @@ -249,33 +261,37 @@ ext_cmd_getlin_hook(base) int tty_get_ext_cmd() { - int i; - char buf[BUFSZ]; + int i; + char buf[BUFSZ]; - if (iflags.extmenu) return extcmd_via_menu(); - /* maybe a runtime option? */ - /* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook : (getlin_hook_proc) 0); */ - hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc)0 - : ext_cmd_getlin_hook); - (void) mungspaces(buf); - if (buf[0] == 0 || buf[0] == '\033') return -1; + if (iflags.extmenu) + return extcmd_via_menu(); + /* maybe a runtime option? */ + /* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook : + * (getlin_hook_proc) 0); */ + hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc) 0 + : ext_cmd_getlin_hook); + (void) mungspaces(buf); + if (buf[0] == 0 || buf[0] == '\033') + return -1; - for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) - if (!strcmpi(buf, extcmdlist[i].ef_txt)) break; + for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++) + if (!strcmpi(buf, extcmdlist[i].ef_txt)) + break; - if (!in_doagain) { - int j; - for (j = 0; buf[j]; j++) - savech(buf[j]); - savech('\n'); - } + if (!in_doagain) { + int j; + for (j = 0; buf[j]; j++) + savech(buf[j]); + savech('\n'); + } - if (extcmdlist[i].ef_txt == (char *)0) { - pline("%s: unknown extended command.", buf); - i = -1; - } + if (extcmdlist[i].ef_txt == (char *) 0) { + pline("%s: unknown extended command.", buf); + i = -1; + } - return i; + return i; } #endif /* TTY_GRAPHICS */ diff --git a/win/tty/termcap.c b/win/tty/termcap.c index 56fa5d127..34e7d4462 100644 --- a/win/tty/termcap.c +++ b/win/tty/termcap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 termcap.c $NHDT-Date: 1427756993 2015/03/30 23:09:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.15 $ */ +/* NetHack 3.6 termcap.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */ /* NetHack 3.6 termcap.c $Date: 2009/05/06 10:59:19 $ $Revision: 1.13 $ */ /* SCCS Id: @(#)termcap.c 3.5 2007/12/12 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ @@ -6,37 +6,36 @@ #include "hack.h" -#if defined (TTY_GRAPHICS) && !defined(NO_TERMS) +#if defined(TTY_GRAPHICS) && !defined(NO_TERMS) #include "wintty.h" #include "tcap.h" - #ifdef MICROPORT_286_BUG -#define Tgetstr(key) (tgetstr(key,tbuf)) +#define Tgetstr(key) (tgetstr(key, tbuf)) #else -#define Tgetstr(key) (tgetstr(key,&tbufptr)) +#define Tgetstr(key) (tgetstr(key, &tbufptr)) #endif /* MICROPORT_286_BUG **/ -static char * FDECL(s_atr2str, (int)); -static char * FDECL(e_atr2str, (int)); +static char *FDECL(s_atr2str, (int)); +static char *FDECL(e_atr2str, (int)); void FDECL(cmov, (int, int)); void FDECL(nocmov, (int, int)); #if defined(TEXTCOLOR) && defined(TERMLIB) -# if !defined(UNIX) || !defined(TERMINFO) -# ifndef TOS +#if !defined(UNIX) || !defined(TERMINFO) +#ifndef TOS static void FDECL(analyze_seq, (char *, int *, int *)); -# endif -# endif +#endif +#endif static void NDECL(init_hilite); static void NDECL(kill_hilite); #endif - /* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE, - ul_hack */ -struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0,0, 0,0, FALSE }; +/* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE, + ul_hack */ +struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE }; STATIC_VAR char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE; STATIC_VAR char *VS, *VE; @@ -48,23 +47,23 @@ STATIC_VAR char *MD; /* may already be in use below */ #endif #ifdef TERMLIB -# ifdef TEXTCOLOR +#ifdef TEXTCOLOR STATIC_VAR char *MD; -# endif +#endif STATIC_VAR int SG; STATIC_OVL char PC = '\0'; STATIC_VAR char tbuf[512]; #endif /*TERMLIB*/ #ifdef TEXTCOLOR -# ifdef TOS -const char *hilites[CLR_MAX]; /* terminal escapes for the various colors */ -# else +#ifdef TOS +const char *hilites[CLR_MAX]; /* terminal escapes for the various colors */ +#else char NEARDATA *hilites[CLR_MAX]; /* terminal escapes for the various colors */ -# endif +#endif #endif -static char *KS = (char *)0, *KE = (char *)0; /* keypad sequences */ +static char *KS = (char *) 0, *KE = (char *) 0; /* keypad sequences */ static char nullstr[] = ""; #if defined(ASCIIGRAPH) && !defined(NO_TERMS) @@ -73,294 +72,305 @@ extern boolean HE_resets_AS; #ifndef TERMLIB STATIC_VAR char tgotobuf[20]; -# ifdef TOS -#define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y+' ', x+' '), tgotobuf) -# else -#define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y+1, x+1), tgotobuf) -# endif +#ifdef TOS +#define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y + ' ', x + ' '), tgotobuf) +#else +#define tgoto(fmt, x, y) (Sprintf(tgotobuf, fmt, y + 1, x + 1), tgotobuf) +#endif #endif /* TERMLIB */ void tty_startup(wid, hgt) int *wid, *hgt; { - register int i; + register int i; #ifdef TERMLIB - register const char *term; - register char *tptr; - char *tbufptr, *pc; + register const char *term; + register char *tptr; + char *tbufptr, *pc; -# ifdef VMS - term = verify_termcap(); - if (!term) -# endif - term = getenv("TERM"); +#ifdef VMS + term = verify_termcap(); + if (!term) +#endif + term = getenv("TERM"); -# if defined(TOS) && defined(__GNUC__) - if (!term) - term = "builtin"; /* library has a default */ -# endif - if (!term) +#if defined(TOS) && defined(__GNUC__) + if (!term) + term = "builtin"; /* library has a default */ +#endif + if (!term) #endif #ifndef ANSI_DEFAULT - error("Can't get TERM."); + error("Can't get TERM."); #else -# ifdef TOS - { - CO = 80; LI = 25; - TI = VS = VE = TE = nullstr; - HO = "\033H"; - CE = "\033K"; /* the VT52 termcap */ - UP = "\033A"; - nh_CM = "\033Y%c%c"; /* used with function tgoto() */ - nh_ND = "\033C"; - XD = "\033B"; - BC = "\033D"; - SO = "\033p"; - SE = "\033q"; - /* HI and HE will be updated in init_hilite if we're using color */ - nh_HI = "\033p"; - nh_HE = "\033q"; - *wid = CO; - *hgt = LI; - CL = "\033E"; /* last thing set */ - return; - } -# else /* TOS */ - { -# ifdef MICRO - get_scr_size(); -# ifdef CLIPPING - if(CO < COLNO || LI < ROWNO+3) - setclipped(); -# endif -# endif - HO = "\033[H"; -/* nh_CD = "\033[J"; */ - CE = "\033[K"; /* the ANSI termcap */ -# ifndef TERMLIB - nh_CM = "\033[%d;%dH"; -# else - nh_CM = "\033[%i%d;%dH"; -# endif - UP = "\033[A"; - nh_ND = "\033[C"; - XD = "\033[B"; -# ifdef MICRO /* backspaces are non-destructive */ - BC = "\b"; -# else - BC = "\033[D"; -# endif - nh_HI = SO = "\033[1m"; - nh_US = "\033[4m"; - MR = "\033[7m"; - TI = nh_HE = ME = SE = nh_UE = "\033[0m"; - /* strictly, SE should be 2, and nh_UE should be 24, - but we can't trust all ANSI emulators to be - that complete. -3. */ -# ifndef MICRO - AS = "\016"; - AE = "\017"; -# endif - TE = VS = VE = nullstr; -# ifdef TEXTCOLOR - for (i = 0; i < CLR_MAX / 2; i++) - if (i != CLR_BLACK) { - hilites[i|BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm")); - Sprintf(hilites[i|BRIGHT], "\033[1;3%dm", i); - if (i != CLR_GRAY) -# ifdef MICRO - if (i == CLR_BLUE) hilites[CLR_BLUE] = hilites[CLR_BLUE|BRIGHT]; - else -# endif - { - hilites[i] = (char *) alloc(sizeof("\033[0;3%dm")); - Sprintf(hilites[i], "\033[0;3%dm", i); - } - } -# endif - *wid = CO; - *hgt = LI; - CL = "\033[2J"; /* last thing set */ - return; - } -# endif /* TOS */ +#ifdef TOS + { + CO = 80; + LI = 25; + TI = VS = VE = TE = nullstr; + HO = "\033H"; + CE = "\033K"; /* the VT52 termcap */ + UP = "\033A"; + nh_CM = "\033Y%c%c"; /* used with function tgoto() */ + nh_ND = "\033C"; + XD = "\033B"; + BC = "\033D"; + SO = "\033p"; + SE = "\033q"; + /* HI and HE will be updated in init_hilite if we're using color */ + nh_HI = "\033p"; + nh_HE = "\033q"; + *wid = CO; + *hgt = LI; + CL = "\033E"; /* last thing set */ + return; + } +#else /* TOS */ + { +#ifdef MICRO + get_scr_size(); +#ifdef CLIPPING + if (CO < COLNO || LI < ROWNO + 3) + setclipped(); +#endif +#endif + HO = "\033[H"; + /* nh_CD = "\033[J"; */ + CE = "\033[K"; /* the ANSI termcap */ +#ifndef TERMLIB + nh_CM = "\033[%d;%dH"; +#else + nh_CM = "\033[%i%d;%dH"; +#endif + UP = "\033[A"; + nh_ND = "\033[C"; + XD = "\033[B"; +#ifdef MICRO /* backspaces are non-destructive */ + BC = "\b"; +#else + BC = "\033[D"; +#endif + nh_HI = SO = "\033[1m"; + nh_US = "\033[4m"; + MR = "\033[7m"; + TI = nh_HE = ME = SE = nh_UE = "\033[0m"; +/* strictly, SE should be 2, and nh_UE should be 24, + but we can't trust all ANSI emulators to be + that complete. -3. */ +#ifndef MICRO + AS = "\016"; + AE = "\017"; +#endif + TE = VS = VE = nullstr; +#ifdef TEXTCOLOR + for (i = 0; i < CLR_MAX / 2; i++) + if (i != CLR_BLACK) { + hilites[i | BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm")); + Sprintf(hilites[i | BRIGHT], "\033[1;3%dm", i); + if (i != CLR_GRAY) +#ifdef MICRO + if (i == CLR_BLUE) + hilites[CLR_BLUE] = hilites[CLR_BLUE | BRIGHT]; + else +#endif + { + hilites[i] = (char *) alloc(sizeof("\033[0;3%dm")); + Sprintf(hilites[i], "\033[0;3%dm", i); + } + } +#endif + *wid = CO; + *hgt = LI; + CL = "\033[2J"; /* last thing set */ + return; + } +#endif /* TOS */ #endif /* ANSI_DEFAULT */ #ifdef TERMLIB - tptr = (char *) alloc(1024); + tptr = (char *) alloc(1024); - tbufptr = tbuf; - if(!strncmp(term, "5620", 4)) - flags.null = FALSE; /* this should be a termcap flag */ - if(tgetent(tptr, term) < 1) { - char buf[BUFSZ]; - (void) strncpy(buf, term, - (BUFSZ - 1) - (sizeof("Unknown terminal type: . "))); - buf[BUFSZ-1] = '\0'; - error("Unknown terminal type: %s.", term); - } - if ((pc = Tgetstr("pc")) != 0) - PC = *pc; + tbufptr = tbuf; + if (!strncmp(term, "5620", 4)) + flags.null = FALSE; /* this should be a termcap flag */ + if (tgetent(tptr, term) < 1) { + char buf[BUFSZ]; + (void) strncpy(buf, term, + (BUFSZ - 1) - (sizeof("Unknown terminal type: . "))); + buf[BUFSZ - 1] = '\0'; + error("Unknown terminal type: %s.", term); + } + if ((pc = Tgetstr("pc")) != 0) + PC = *pc; - if(!(BC = Tgetstr("le"))) /* both termcap and terminfo use le */ -# ifdef TERMINFO - error("Terminal must backspace."); -# else - if(!(BC = Tgetstr("bc"))) { /* termcap also uses bc/bs */ -# ifndef MINIMAL_TERM - if(!tgetflag("bs")) - error("Terminal must backspace."); -# endif - BC = tbufptr; - tbufptr += 2; - *BC = '\b'; - } -# endif + if (!(BC = Tgetstr("le"))) /* both termcap and terminfo use le */ +#ifdef TERMINFO + error("Terminal must backspace."); +#else + if (!(BC = Tgetstr("bc"))) { /* termcap also uses bc/bs */ +#ifndef MINIMAL_TERM + if (!tgetflag("bs")) + error("Terminal must backspace."); +#endif + BC = tbufptr; + tbufptr += 2; + *BC = '\b'; + } +#endif -# ifdef MINIMAL_TERM - HO = (char *)0; -# else - HO = Tgetstr("ho"); -# endif - /* - * LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If - * the kernel has values for either we should use them rather than - * the values from TERMCAP ... - */ -# ifndef MICRO - if (!CO) CO = tgetnum("co"); - if (!LI) LI = tgetnum("li"); -# else -# if defined(TOS) && defined(__GNUC__) - if (!strcmp(term, "builtin")) - get_scr_size(); - else { -# endif - CO = tgetnum("co"); - LI = tgetnum("li"); - if (!LI || !CO) /* if we don't override it */ - get_scr_size(); -# if defined(TOS) && defined(__GNUC__) - } -# endif -# endif -# ifdef CLIPPING - if(CO < COLNO || LI < ROWNO+3) - setclipped(); -# endif - nh_ND = Tgetstr("nd"); - if(tgetflag("os")) - error("NetHack can't have OS."); - if(tgetflag("ul")) - ul_hack = TRUE; - CE = Tgetstr("ce"); - UP = Tgetstr("up"); - /* It seems that xd is no longer supported, and we should use - a linefeed instead; unfortunately this requires resetting - CRMOD, and many output routines will have to be modified - slightly. Let's leave that till the next release. */ - XD = Tgetstr("xd"); -/* not: XD = Tgetstr("do"); */ - if(!(nh_CM = Tgetstr("cm"))) { - if(!UP && !HO) - error("NetHack needs CM or UP or HO."); - tty_raw_print("Playing NetHack on terminals without CM is suspect."); - tty_wait_synch(); - } - SO = Tgetstr("so"); - SE = Tgetstr("se"); - nh_US = Tgetstr("us"); - nh_UE = Tgetstr("ue"); - SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */ - if(!SO || !SE || (SG > 0)) SO = SE = nh_US = nh_UE = nullstr; - TI = Tgetstr("ti"); - TE = Tgetstr("te"); - VS = VE = nullstr; -# ifdef TERMINFO - VS = Tgetstr("eA"); /* enable graphics */ -# endif - KS = Tgetstr("ks"); /* keypad start (special mode) */ - KE = Tgetstr("ke"); /* keypad end (ordinary mode [ie, digits]) */ - MR = Tgetstr("mr"); /* reverse */ -# if 0 +#ifdef MINIMAL_TERM + HO = (char *) 0; +#else + HO = Tgetstr("ho"); +#endif +/* + * LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If + * the kernel has values for either we should use them rather than + * the values from TERMCAP ... + */ +#ifndef MICRO + if (!CO) + CO = tgetnum("co"); + if (!LI) + LI = tgetnum("li"); +#else +#if defined(TOS) && defined(__GNUC__) + if (!strcmp(term, "builtin")) + get_scr_size(); + else { +#endif + CO = tgetnum("co"); + LI = tgetnum("li"); + if (!LI || !CO) /* if we don't override it */ + get_scr_size(); +#if defined(TOS) && defined(__GNUC__) + } +#endif +#endif +#ifdef CLIPPING + if (CO < COLNO || LI < ROWNO + 3) + setclipped(); +#endif + nh_ND = Tgetstr("nd"); + if (tgetflag("os")) + error("NetHack can't have OS."); + if (tgetflag("ul")) + ul_hack = TRUE; + CE = Tgetstr("ce"); + UP = Tgetstr("up"); + /* It seems that xd is no longer supported, and we should use + a linefeed instead; unfortunately this requires resetting + CRMOD, and many output routines will have to be modified + slightly. Let's leave that till the next release. */ + XD = Tgetstr("xd"); + /* not: XD = Tgetstr("do"); */ + if (!(nh_CM = Tgetstr("cm"))) { + if (!UP && !HO) + error("NetHack needs CM or UP or HO."); + tty_raw_print("Playing NetHack on terminals without CM is suspect."); + tty_wait_synch(); + } + SO = Tgetstr("so"); + SE = Tgetstr("se"); + nh_US = Tgetstr("us"); + nh_UE = Tgetstr("ue"); + SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */ + if (!SO || !SE || (SG > 0)) + SO = SE = nh_US = nh_UE = nullstr; + TI = Tgetstr("ti"); + TE = Tgetstr("te"); + VS = VE = nullstr; +#ifdef TERMINFO + VS = Tgetstr("eA"); /* enable graphics */ +#endif + KS = Tgetstr("ks"); /* keypad start (special mode) */ + KE = Tgetstr("ke"); /* keypad end (ordinary mode [ie, digits]) */ + MR = Tgetstr("mr"); /* reverse */ +#if 0 MB = Tgetstr("mb"); /* blink */ MD = Tgetstr("md"); /* boldface */ MH = Tgetstr("mh"); /* dim */ -# endif - ME = Tgetstr("me"); /* turn off all attributes */ - if (!ME || (SE == nullstr)) ME = SE; /* default to SE value */ +#endif + ME = Tgetstr("me"); /* turn off all attributes */ + if (!ME || (SE == nullstr)) + ME = SE; /* default to SE value */ - /* Get rid of padding numbers for nh_HI and nh_HE. Hope they - * aren't really needed!!! nh_HI and nh_HE are outputted to the - * pager as a string - so how can you send it NULs??? - * -jsb - */ - nh_HI = (char *) alloc((unsigned)(strlen(SO)+1)); - nh_HE = (char *) alloc((unsigned)(strlen(ME)+1)); - i = 0; - while (digit(SO[i])) i++; - Strcpy(nh_HI, &SO[i]); - i = 0; - while (digit(ME[i])) i++; - Strcpy(nh_HE, &ME[i]); - AS = Tgetstr("as"); - AE = Tgetstr("ae"); - nh_CD = Tgetstr("cd"); -# ifdef TEXTCOLOR - MD = Tgetstr("md"); -# endif -# ifdef TEXTCOLOR -# if defined(TOS) && defined(__GNUC__) - if (!strcmp(term, "builtin") || !strcmp(term, "tw52") || - !strcmp(term, "st52")) { - init_hilite(); - } -# else - init_hilite(); -# endif -# endif - *wid = CO; - *hgt = LI; - if (!(CL = Tgetstr("cl"))) /* last thing set */ - error("NetHack needs CL."); - if ((int)(tbufptr - tbuf) > (int)(sizeof tbuf)) - error("TERMCAP entry too big...\n"); - free((genericptr_t)tptr); + /* Get rid of padding numbers for nh_HI and nh_HE. Hope they + * aren't really needed!!! nh_HI and nh_HE are outputted to the + * pager as a string - so how can you send it NULs??? + * -jsb + */ + nh_HI = (char *) alloc((unsigned) (strlen(SO) + 1)); + nh_HE = (char *) alloc((unsigned) (strlen(ME) + 1)); + i = 0; + while (digit(SO[i])) + i++; + Strcpy(nh_HI, &SO[i]); + i = 0; + while (digit(ME[i])) + i++; + Strcpy(nh_HE, &ME[i]); + AS = Tgetstr("as"); + AE = Tgetstr("ae"); + nh_CD = Tgetstr("cd"); +#ifdef TEXTCOLOR + MD = Tgetstr("md"); +#endif +#ifdef TEXTCOLOR +#if defined(TOS) && defined(__GNUC__) + if (!strcmp(term, "builtin") || !strcmp(term, "tw52") + || !strcmp(term, "st52")) { + init_hilite(); + } +#else + init_hilite(); +#endif +#endif + *wid = CO; + *hgt = LI; + if (!(CL = Tgetstr("cl"))) /* last thing set */ + error("NetHack needs CL."); + if ((int) (tbufptr - tbuf) > (int) (sizeof tbuf)) + error("TERMCAP entry too big...\n"); + free((genericptr_t) tptr); #endif /* TERMLIB */ } -/* note: at present, this routine is not part of the formal window interface */ +/* note: at present, this routine is not part of the formal window interface + */ /* deallocate resources prior to final termination */ void tty_shutdown() { #if defined(TEXTCOLOR) && defined(TERMLIB) - kill_hilite(); + kill_hilite(); #endif - /* we don't attempt to clean up individual termcap variables [yet?] */ - return; + /* we don't attempt to clean up individual termcap variables [yet?] */ + return; } void tty_number_pad(state) int state; { - switch (state) { - case -1: /* activate keypad mode (escape sequences) */ - if (KS && *KS) xputs(KS); - break; - case 1: /* activate numeric mode for keypad (digits) */ - if (KE && *KE) xputs(KE); - break; - case 0: /* don't need to do anything--leave terminal as-is */ - default: - break; - } + switch (state) { + case -1: /* activate keypad mode (escape sequences) */ + if (KS && *KS) + xputs(KS); + break; + case 1: /* activate numeric mode for keypad (digits) */ + if (KE && *KE) + xputs(KE); + break; + case 0: /* don't need to do anything--leave terminal as-is */ + default: + break; + } } #ifdef TERMLIB -extern void NDECL((*decgraphics_mode_callback)); /* defined in drawing.c */ +extern void NDECL((*decgraphics_mode_callback)); /* defined in drawing.c */ static void NDECL(tty_decgraphics_termcap_fixup); /* @@ -373,59 +383,71 @@ static void NDECL(tty_decgraphics_termcap_fixup); static void tty_decgraphics_termcap_fixup() { - static char ctrlN[] = "\016"; - static char ctrlO[] = "\017"; - static char appMode[] = "\033="; - static char numMode[] = "\033>"; + static char ctrlN[] = "\016"; + static char ctrlO[] = "\017"; + static char appMode[] = "\033="; + static char numMode[] = "\033>"; - /* these values are missing from some termcaps */ - if (!AS) AS = ctrlN; /* ^N (shift-out [graphics font]) */ - if (!AE) AE = ctrlO; /* ^O (shift-in [regular font]) */ - if (!KS) KS = appMode; /* ESC= (application keypad mode) */ - if (!KE) KE = numMode; /* ESC> (numeric keypad mode) */ - /* - * Select the line-drawing character set as the alternate font. - * Do not select NA ASCII as the primary font since people may - * reasonably be using the UK character set. - */ - if (SYMHANDLING(H_DEC)) xputs("\033)0"); + /* these values are missing from some termcaps */ + if (!AS) + AS = ctrlN; /* ^N (shift-out [graphics font]) */ + if (!AE) + AE = ctrlO; /* ^O (shift-in [regular font]) */ + if (!KS) + KS = appMode; /* ESC= (application keypad mode) */ + if (!KE) + KE = numMode; /* ESC> (numeric keypad mode) */ + /* + * Select the line-drawing character set as the alternate font. + * Do not select NA ASCII as the primary font since people may + * reasonably be using the UK character set. + */ + if (SYMHANDLING(H_DEC)) + xputs("\033)0"); #ifdef PC9800 - init_hilite(); + init_hilite(); #endif #if defined(ASCIIGRAPH) && !defined(NO_TERMS) - /* some termcaps suffer from the bizarre notion that resetting - video attributes should also reset the chosen character set */ + /* some termcaps suffer from the bizarre notion that resetting + video attributes should also reset the chosen character set */ { - const char *nh_he = nh_HE, *ae = AE; - int he_limit, ae_length; + const char *nh_he = nh_HE, *ae = AE; + int he_limit, ae_length; - if (digit(*ae)) { /* skip over delay prefix, if any */ - do ++ae; while (digit(*ae)); - if (*ae == '.') { ++ae; if (digit(*ae)) ++ae; } - if (*ae == '*') ++ae; - } - /* can't use nethack's case-insensitive strstri() here, and some old - systems don't have strstr(), so use brute force substring search */ - ae_length = strlen(ae), he_limit = strlen(nh_he); - while (he_limit >= ae_length) { - if (strncmp(nh_he, ae, ae_length) == 0) { - HE_resets_AS = TRUE; - break; - } - ++nh_he, --he_limit; - } + if (digit(*ae)) { /* skip over delay prefix, if any */ + do + ++ae; + while (digit(*ae)); + if (*ae == '.') { + ++ae; + if (digit(*ae)) + ++ae; + } + if (*ae == '*') + ++ae; + } + /* can't use nethack's case-insensitive strstri() here, and some old + systems don't have strstr(), so use brute force substring search */ + ae_length = strlen(ae), he_limit = strlen(nh_he); + while (he_limit >= ae_length) { + if (strncmp(nh_he, ae, ae_length) == 0) { + HE_resets_AS = TRUE; + break; + } + ++nh_he, --he_limit; + } } #endif } -#endif /* TERMLIB */ +#endif /* TERMLIB */ #if defined(ASCIIGRAPH) && defined(PC9800) -extern void NDECL((*ibmgraphics_mode_callback)); /* defined in drawing.c */ +extern void NDECL((*ibmgraphics_mode_callback)); /* defined in drawing.c */ #endif #ifdef PC9800 -extern void NDECL((*ascgraphics_mode_callback)); /* defined in drawing.c */ +extern void NDECL((*ascgraphics_mode_callback)); /* defined in drawing.c */ static void NDECL(tty_ascgraphics_hilite_fixup); static void @@ -434,197 +456,205 @@ tty_ascgraphics_hilite_fixup() register int c; for (c = 0; c < CLR_MAX / 2; c++) - if (c != CLR_BLACK) { - hilites[c|BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm")); - Sprintf(hilites[c|BRIGHT], "\033[1;3%dm", c); - if (c != CLR_GRAY) { - hilites[c] = (char *) alloc(sizeof("\033[0;3%dm")); - Sprintf(hilites[c], "\033[0;3%dm", c); - } - } + if (c != CLR_BLACK) { + hilites[c | BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm")); + Sprintf(hilites[c | BRIGHT], "\033[1;3%dm", c); + if (c != CLR_GRAY) { + hilites[c] = (char *) alloc(sizeof("\033[0;3%dm")); + Sprintf(hilites[c], "\033[0;3%dm", c); + } + } } #endif /* PC9800 */ void tty_start_screen() { - xputs(TI); - xputs(VS); + xputs(TI); + xputs(VS); #ifdef PC9800 if (!SYMHANDLING(H_IBM)) - tty_ascgraphics_hilite_fixup(); + tty_ascgraphics_hilite_fixup(); /* set up callback in case option is not set yet but toggled later */ ascgraphics_mode_callback = tty_ascgraphics_hilite_fixup; -# ifdef ASCIIGRAPH - if (SYMHANDLING(H_IBM)) init_hilite(); +#ifdef ASCIIGRAPH + if (SYMHANDLING(H_IBM)) + init_hilite(); /* set up callback in case option is not set yet but toggled later */ ibmgraphics_mode_callback = init_hilite; -# endif +#endif #endif /* PC9800 */ #ifdef TERMLIB - if (SYMHANDLING(H_DEC)) tty_decgraphics_termcap_fixup(); - /* set up callback in case option is not set yet but toggled later */ - decgraphics_mode_callback = tty_decgraphics_termcap_fixup; + if (SYMHANDLING(H_DEC)) + tty_decgraphics_termcap_fixup(); + /* set up callback in case option is not set yet but toggled later */ + decgraphics_mode_callback = tty_decgraphics_termcap_fixup; #endif - if (Cmd.num_pad) tty_number_pad(1); /* make keypad send digits */ + if (Cmd.num_pad) + tty_number_pad(1); /* make keypad send digits */ } void tty_end_screen() { - clear_screen(); - xputs(VE); - xputs(TE); + clear_screen(); + xputs(VE); + xputs(TE); } /* Cursor movements */ -/* Note to overlay tinkerers. The placement of this overlay controls the location +/* Note to overlay tinkerers. The placement of this overlay controls the + location of the function xputc(). This function is not currently in trampoli.[ch] - files for what is deemed to be performance reasons. If this define is moved + files for what is deemed to be performance reasons. If this define is + moved and or xputc() is taken out of the ROOT overlay, then action must be taken in trampoli.[ch]. */ void nocmov(x, y) -int x,y; +int x, y; { - if ((int) ttyDisplay->cury > y) { - if(UP) { - while ((int) ttyDisplay->cury > y) { /* Go up. */ - xputs(UP); - ttyDisplay->cury--; - } - } else if(nh_CM) { - cmov(x, y); - } else if(HO) { - home(); - tty_curs(BASE_WINDOW, x+1, y); - } /* else impossible("..."); */ - } else if ((int) ttyDisplay->cury < y) { - if(XD) { - while((int) ttyDisplay->cury < y) { - xputs(XD); - ttyDisplay->cury++; - } - } else if(nh_CM) { - cmov(x, y); - } else { - while((int) ttyDisplay->cury < y) { - xputc('\n'); - ttyDisplay->curx = 0; - ttyDisplay->cury++; - } - } - } - if ((int) ttyDisplay->curx < x) { /* Go to the right. */ - if(!nh_ND) cmov(x, y); else /* bah */ - /* should instead print what is there already */ - while ((int) ttyDisplay->curx < x) { - xputs(nh_ND); - ttyDisplay->curx++; - } - } else if ((int) ttyDisplay->curx > x) { - while ((int) ttyDisplay->curx > x) { /* Go to the left. */ - xputs(BC); - ttyDisplay->curx--; - } - } + if ((int) ttyDisplay->cury > y) { + if (UP) { + while ((int) ttyDisplay->cury > y) { /* Go up. */ + xputs(UP); + ttyDisplay->cury--; + } + } else if (nh_CM) { + cmov(x, y); + } else if (HO) { + home(); + tty_curs(BASE_WINDOW, x + 1, y); + } /* else impossible("..."); */ + } else if ((int) ttyDisplay->cury < y) { + if (XD) { + while ((int) ttyDisplay->cury < y) { + xputs(XD); + ttyDisplay->cury++; + } + } else if (nh_CM) { + cmov(x, y); + } else { + while ((int) ttyDisplay->cury < y) { + xputc('\n'); + ttyDisplay->curx = 0; + ttyDisplay->cury++; + } + } + } + if ((int) ttyDisplay->curx < x) { /* Go to the right. */ + if (!nh_ND) + cmov(x, y); + else /* bah */ + /* should instead print what is there already */ + while ((int) ttyDisplay->curx < x) { + xputs(nh_ND); + ttyDisplay->curx++; + } + } else if ((int) ttyDisplay->curx > x) { + while ((int) ttyDisplay->curx > x) { /* Go to the left. */ + xputs(BC); + ttyDisplay->curx--; + } + } } void cmov(x, y) register int x, y; { - xputs(tgoto(nh_CM, x, y)); - ttyDisplay->cury = y; - ttyDisplay->curx = x; + xputs(tgoto(nh_CM, x, y)); + ttyDisplay->cury = y; + ttyDisplay->curx = x; } /* See note above. xputc() is a special function. */ -void -xputc(c) +void xputc(c) #if defined(apollo) -int c; + int c; #else -char c; + char c; #endif { - (void) putchar(c); + (void) putchar(c); } void xputs(s) const char *s; { -# ifndef TERMLIB - (void) fputs(s, stdout); -# else -# if defined(NHSTDC) || defined(ULTRIX_PROTO) - tputs(s, 1, (int (*)())xputc); -# else - tputs(s, 1, xputc); -# endif -# endif +#ifndef TERMLIB + (void) fputs(s, stdout); +#else +#if defined(NHSTDC) || defined(ULTRIX_PROTO) + tputs(s, 1, (int (*) ()) xputc); +#else + tputs(s, 1, xputc); +#endif +#endif } void cl_end() { - if(CE) - xputs(CE); - else { /* no-CE fix - free after Harold Rynes */ - /* this looks terrible, especially on a slow terminal - but is better than nothing */ - register int cx = ttyDisplay->curx+1; + if (CE) + xputs(CE); + else { /* no-CE fix - free after Harold Rynes */ + /* this looks terrible, especially on a slow terminal + but is better than nothing */ + register int cx = ttyDisplay->curx + 1; - while(cx < CO) { - xputc(' '); - cx++; - } - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, - (int)ttyDisplay->cury); - } + while (cx < CO) { + xputc(' '); + cx++; + } + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, + (int) ttyDisplay->cury); + } } void clear_screen() { - /* note: if CL is null, then termcap initialization failed, - so don't attempt screen-oriented I/O during final cleanup. - */ - if (CL) { - xputs(CL); - home(); - } + /* note: if CL is null, then termcap initialization failed, + so don't attempt screen-oriented I/O during final cleanup. + */ + if (CL) { + xputs(CL); + home(); + } } void home() { - if(HO) - xputs(HO); - else if(nh_CM) - xputs(tgoto(nh_CM, 0, 0)); - else - tty_curs(BASE_WINDOW, 1, 0); /* using UP ... */ - ttyDisplay->curx = ttyDisplay->cury = 0; + if (HO) + xputs(HO); + else if (nh_CM) + xputs(tgoto(nh_CM, 0, 0)); + else + tty_curs(BASE_WINDOW, 1, 0); /* using UP ... */ + ttyDisplay->curx = ttyDisplay->cury = 0; } void standoutbeg() { - if(SO) xputs(SO); + if (SO) + xputs(SO); } void standoutend() { - if(SE) xputs(SE); + if (SE) + xputs(SE); } -#if 0 /* if you need one of these, uncomment it (here and in extern.h) */ +#if 0 /* if you need one of these, uncomment it (here and in extern.h) */ void revbeg() { @@ -660,40 +690,46 @@ m_end() void backsp() { - xputs(BC); + xputs(BC); } void tty_nhbell() { - if (flags.silent) return; - (void) putchar('\007'); /* curx does not change */ - (void) fflush(stdout); + if (flags.silent) + return; + (void) putchar('\007'); /* curx does not change */ + (void) fflush(stdout); } #ifdef ASCIIGRAPH void -graph_on() { - if (AS) xputs(AS); +graph_on() +{ + if (AS) + xputs(AS); } void -graph_off() { - if (AE) xputs(AE); +graph_off() +{ + if (AE) + xputs(AE); } #endif #if !defined(MICRO) -# ifdef VMS -static const short tmspc10[] = { /* from termcap */ - 0, 2000, 1333, 909, 743, 666, 333, 166, 83, 55, 50, 41, 27, 20, 13, 10, - 5 +#ifdef VMS +static const short tmspc10[] = { /* from termcap */ + 0, 2000, 1333, 909, 743, 666, 333, 166, 83, + 55, 50, 41, 27, 20, 13, 10, 5 }; -# else -static const short tmspc10[] = { /* from termcap */ - 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5 +#else +static const short tmspc10[] = { /* from termcap */ + 0, 2000, 1333, 909, 743, 666, 500, 333, 166, + 83, 55, 41, 20, 10, 5 }; -# endif +#endif #endif /* delay 50 ms */ @@ -701,75 +737,74 @@ void tty_delay_output() { #if defined(MICRO) - register int i; + register int i; #endif #ifdef TIMED_DELAY - if (flags.nap) { - (void) fflush(stdout); - msleep(50); /* sleep for 50 milliseconds */ - return; - } + if (flags.nap) { + (void) fflush(stdout); + msleep(50); /* sleep for 50 milliseconds */ + return; + } #endif #if defined(MICRO) - /* simulate the delay with "cursor here" */ - for (i = 0; i < 3; i++) { - cmov(ttyDisplay->curx, ttyDisplay->cury); - (void) fflush(stdout); - } + /* simulate the delay with "cursor here" */ + for (i = 0; i < 3; i++) { + cmov(ttyDisplay->curx, ttyDisplay->cury); + (void) fflush(stdout); + } #else /* MICRO */ - /* BUG: if the padding character is visible, as it is on the 5620 - then this looks terrible. */ - if(flags.null) -# ifdef TERMINFO - /* cbosgd!cbcephus!pds for SYS V R2 */ -# ifdef NHSTDC - tputs("$<50>", 1, (int (*)())xputc); -# else - tputs("$<50>", 1, xputc); -# endif -# else -# if defined(NHSTDC) || defined(ULTRIX_PROTO) - tputs("50", 1, (int (*)())xputc); -# else - tputs("50", 1, xputc); -# endif -# endif + /* BUG: if the padding character is visible, as it is on the 5620 + then this looks terrible. */ + if (flags.null) +#ifdef TERMINFO +/* cbosgd!cbcephus!pds for SYS V R2 */ +#ifdef NHSTDC + tputs("$<50>", 1, (int (*) ()) xputc); +#else + tputs("$<50>", 1, xputc); +#endif +#else +#if defined(NHSTDC) || defined(ULTRIX_PROTO) + tputs("50", 1, (int (*) ()) xputc); +#else + tputs("50", 1, xputc); +#endif +#endif - else if(ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) { - /* delay by sending cm(here) an appropriate number of times */ - register int cmlen = strlen(tgoto(nh_CM, ttyDisplay->curx, - ttyDisplay->cury)); - register int i = 500 + tmspc10[ospeed]/2; + else if (ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) { + /* delay by sending cm(here) an appropriate number of times */ + register int cmlen = + strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury)); + register int i = 500 + tmspc10[ospeed] / 2; - while(i > 0) { - cmov((int)ttyDisplay->curx, (int)ttyDisplay->cury); - i -= cmlen*tmspc10[ospeed]; - } - } + while (i > 0) { + cmov((int) ttyDisplay->curx, (int) ttyDisplay->cury); + i -= cmlen * tmspc10[ospeed]; + } + } #endif /* MICRO */ } -void -cl_eos() /* free after Robert Viduya */ -{ /* must only be called with curx = 1 */ +void cl_eos() /* free after Robert Viduya */ +{ /* must only be called with curx = 1 */ - if(nh_CD) - xputs(nh_CD); - else { - register int cy = ttyDisplay->cury+1; - while(cy <= LI-2) { - cl_end(); - xputc('\n'); - cy++; - } - cl_end(); - tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1, - (int)ttyDisplay->cury); - } + if (nh_CD) + xputs(nh_CD); + else { + register int cy = ttyDisplay->cury + 1; + while (cy <= LI - 2) { + cl_end(); + xputc('\n'); + cy++; + } + cl_end(); + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, + (int) ttyDisplay->cury); + } } #if defined(TEXTCOLOR) && defined(TERMLIB) -# if defined(UNIX) && defined(TERMINFO) +#if defined(UNIX) && defined(TERMINFO) /* * Sets up color highlighting, using terminfo(4) escape sequences. * @@ -794,197 +829,196 @@ cl_eos() /* free after Robert Viduya */ * characters on the assumed black background. */ - /* `curses' is aptly named; various versions don't like these - macros used elsewhere within nethack; fortunately they're - not needed beyond this point, so we don't need to worry - about reconstructing them after the header file inclusion. */ +/* `curses' is aptly named; various versions don't like these + macros used elsewhere within nethack; fortunately they're + not needed beyond this point, so we don't need to worry + about reconstructing them after the header file inclusion. */ #undef delay_output #undef TRUE #undef FALSE -#define m_move curses_m_move /* Some curses.h decl m_move(), not used here */ +#define m_move curses_m_move /* Some curses.h decl m_move(), not used here \ + */ #include -#if !defined(LINUX) && !defined(__FreeBSD__) && !defined(NOTPARMDECL) +#if !defined(LINUX) && !defined(__FreeBSD__) && !defined(NOTPARMDECL) extern char *tparm(); #endif -# ifndef COLOR_BLACK /* trust include file */ -# ifndef _M_UNIX /* guess BGR */ -#define COLOR_BLACK 0 -#define COLOR_BLUE 1 -#define COLOR_GREEN 2 -#define COLOR_CYAN 3 -#define COLOR_RED 4 +#ifndef COLOR_BLACK /* trust include file */ +#ifndef _M_UNIX /* guess BGR */ +#define COLOR_BLACK 0 +#define COLOR_BLUE 1 +#define COLOR_GREEN 2 +#define COLOR_CYAN 3 +#define COLOR_RED 4 #define COLOR_MAGENTA 5 -#define COLOR_YELLOW 6 -#define COLOR_WHITE 7 -# else /* guess RGB */ -#define COLOR_BLACK 0 -#define COLOR_RED 1 -#define COLOR_GREEN 2 -#define COLOR_YELLOW 3 -#define COLOR_BLUE 4 +#define COLOR_YELLOW 6 +#define COLOR_WHITE 7 +#else /* guess RGB */ +#define COLOR_BLACK 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_YELLOW 3 +#define COLOR_BLUE 4 #define COLOR_MAGENTA 5 -#define COLOR_CYAN 6 -#define COLOR_WHITE 7 -# endif -# endif +#define COLOR_CYAN 6 +#define COLOR_WHITE 7 +#endif +#endif /* Mapping data for the six terminfo colors that resolve to pairs of nethack * colors. Black and white are handled specially. */ -const struct {int ti_color, nh_color, nh_bright_color;} ti_map[6] = -{ - {COLOR_RED,CLR_RED,CLR_ORANGE}, - {COLOR_GREEN,CLR_GREEN,CLR_BRIGHT_GREEN}, - {COLOR_YELLOW,CLR_BROWN,CLR_YELLOW}, - {COLOR_BLUE,CLR_BLUE,CLR_BRIGHT_BLUE}, - {COLOR_MAGENTA,CLR_MAGENTA,CLR_BRIGHT_MAGENTA}, - {COLOR_CYAN,CLR_CYAN,CLR_BRIGHT_CYAN} -}; +const struct { + int ti_color, nh_color, nh_bright_color; +} ti_map[6] = { { COLOR_RED, CLR_RED, CLR_ORANGE }, + { COLOR_GREEN, CLR_GREEN, CLR_BRIGHT_GREEN }, + { COLOR_YELLOW, CLR_BROWN, CLR_YELLOW }, + { COLOR_BLUE, CLR_BLUE, CLR_BRIGHT_BLUE }, + { COLOR_MAGENTA, CLR_MAGENTA, CLR_BRIGHT_MAGENTA }, + { COLOR_CYAN, CLR_CYAN, CLR_BRIGHT_CYAN } }; static char nilstring[] = ""; static void init_hilite() { - register int c; - char *setf, *scratch; - int md_len; + register int c; + char *setf, *scratch; + int md_len; - if (tgetnum("Co") < 8 - || (MD == NULL) || (strlen(MD) == 0) - || ((setf = tgetstr("AF", (char **)0)) == (char *)0 - && (setf = tgetstr("Sf", (char **)0)) == (char *)0)) - { - /* Fallback when colors not available - * It's arbitrary to collapse all colors except gray - * together, but that's what the previous code did. - */ - hilites[CLR_BLACK] = nh_HI; - hilites[CLR_RED] = nh_HI; - hilites[CLR_GREEN] = nh_HI; - hilites[CLR_BROWN] = nh_HI; - hilites[CLR_BLUE] = nh_HI; - hilites[CLR_MAGENTA] = nh_HI; - hilites[CLR_CYAN] = nh_HI; - hilites[CLR_GRAY] = nilstring; - hilites[NO_COLOR] = nilstring; - hilites[CLR_ORANGE] = nh_HI; - hilites[CLR_BRIGHT_GREEN] = nh_HI; - hilites[CLR_YELLOW] = nh_HI; - hilites[CLR_BRIGHT_BLUE] = nh_HI; - hilites[CLR_BRIGHT_MAGENTA] = nh_HI; - hilites[CLR_BRIGHT_CYAN] = nh_HI; - hilites[CLR_WHITE] = nh_HI; - return; - } + if (tgetnum("Co") < 8 || (MD == NULL) || (strlen(MD) == 0) + || ((setf = tgetstr("AF", (char **) 0)) == (char *) 0 + && (setf = tgetstr("Sf", (char **) 0)) == (char *) 0)) { + /* Fallback when colors not available + * It's arbitrary to collapse all colors except gray + * together, but that's what the previous code did. + */ + hilites[CLR_BLACK] = nh_HI; + hilites[CLR_RED] = nh_HI; + hilites[CLR_GREEN] = nh_HI; + hilites[CLR_BROWN] = nh_HI; + hilites[CLR_BLUE] = nh_HI; + hilites[CLR_MAGENTA] = nh_HI; + hilites[CLR_CYAN] = nh_HI; + hilites[CLR_GRAY] = nilstring; + hilites[NO_COLOR] = nilstring; + hilites[CLR_ORANGE] = nh_HI; + hilites[CLR_BRIGHT_GREEN] = nh_HI; + hilites[CLR_YELLOW] = nh_HI; + hilites[CLR_BRIGHT_BLUE] = nh_HI; + hilites[CLR_BRIGHT_MAGENTA] = nh_HI; + hilites[CLR_BRIGHT_CYAN] = nh_HI; + hilites[CLR_WHITE] = nh_HI; + return; + } - md_len = strlen(MD); + md_len = strlen(MD); - c = 6; - while (c--) { - char *work; - scratch = tparm(setf,ti_map[c].ti_color); - work = (char *) alloc(strlen(scratch) + md_len + 1); - Strcpy(work,MD); - hilites[ti_map[c].nh_bright_color] = work; - work += md_len; - Strcpy(work,scratch); - hilites[ti_map[c].nh_color] = work; - } + c = 6; + while (c--) { + char *work; + scratch = tparm(setf, ti_map[c].ti_color); + work = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(work, MD); + hilites[ti_map[c].nh_bright_color] = work; + work += md_len; + Strcpy(work, scratch); + hilites[ti_map[c].nh_color] = work; + } - scratch = tparm(setf,COLOR_WHITE); - hilites[CLR_WHITE] = (char *) alloc(strlen(scratch) + md_len + 1); - Strcpy(hilites[CLR_WHITE],MD); - Strcat(hilites[CLR_WHITE],scratch); + scratch = tparm(setf, COLOR_WHITE); + hilites[CLR_WHITE] = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(hilites[CLR_WHITE], MD); + Strcat(hilites[CLR_WHITE], scratch); - hilites[CLR_GRAY] = nilstring; - hilites[NO_COLOR] = nilstring; + hilites[CLR_GRAY] = nilstring; + hilites[NO_COLOR] = nilstring; - if (iflags.wc2_darkgray) { - /* On many terminals, esp. those using classic PC CGA/EGA/VGA - * textmode, specifying "hilight" and "black" simultaneously - * produces a dark shade of gray that is visible against a - * black background. We can use it to represent black objects. - */ - scratch = tparm(setf,COLOR_BLACK); - hilites[CLR_BLACK] = (char *) alloc(strlen(scratch) + md_len + 1); - Strcpy(hilites[CLR_BLACK],MD); - Strcat(hilites[CLR_BLACK],scratch); - } else { - /* But it's concievable that hilighted black-on-black could - * still be invisible on many others. We substitute blue for - * black. - */ - hilites[CLR_BLACK] = hilites[CLR_BLUE]; - } + if (iflags.wc2_darkgray) { + /* On many terminals, esp. those using classic PC CGA/EGA/VGA + * textmode, specifying "hilight" and "black" simultaneously + * produces a dark shade of gray that is visible against a + * black background. We can use it to represent black objects. + */ + scratch = tparm(setf, COLOR_BLACK); + hilites[CLR_BLACK] = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(hilites[CLR_BLACK], MD); + Strcat(hilites[CLR_BLACK], scratch); + } else { + /* But it's concievable that hilighted black-on-black could + * still be invisible on many others. We substitute blue for + * black. + */ + hilites[CLR_BLACK] = hilites[CLR_BLUE]; + } } static void kill_hilite() { - /* if colors weren't available, no freeing needed */ - if (hilites[CLR_BLACK] == nh_HI) - return; + /* if colors weren't available, no freeing needed */ + if (hilites[CLR_BLACK] == nh_HI) + return; - if (hilites[CLR_BLACK] != hilites[CLR_BLUE]) - free(hilites[CLR_BLACK]); + if (hilites[CLR_BLACK] != hilites[CLR_BLUE]) + free(hilites[CLR_BLACK]); - /* CLR_BLUE overlaps CLR_BRIGHT_BLUE, do not free */ - /* CLR_GREEN overlaps CLR_BRIGHT_GREEN, do not free */ - /* CLR_CYAN overlaps CLR_BRIGHT_CYAN, do not free */ - /* CLR_RED overlaps CLR_ORANGE, do not free */ - /* CLR_MAGENTA overlaps CLR_BRIGHT_MAGENTA, do not free */ - /* CLR_BROWN overlaps CLR_YELLOW, do not free */ - /* CLR_GRAY is static 'nilstring', do not free */ - /* NO_COLOR is static 'nilstring', do not free */ - free(hilites[CLR_BRIGHT_BLUE]); - free(hilites[CLR_BRIGHT_GREEN]); - free(hilites[CLR_BRIGHT_CYAN]); - free(hilites[CLR_YELLOW]); - free(hilites[CLR_ORANGE]); - free(hilites[CLR_BRIGHT_MAGENTA]); - free(hilites[CLR_WHITE]); + /* CLR_BLUE overlaps CLR_BRIGHT_BLUE, do not free */ + /* CLR_GREEN overlaps CLR_BRIGHT_GREEN, do not free */ + /* CLR_CYAN overlaps CLR_BRIGHT_CYAN, do not free */ + /* CLR_RED overlaps CLR_ORANGE, do not free */ + /* CLR_MAGENTA overlaps CLR_BRIGHT_MAGENTA, do not free */ + /* CLR_BROWN overlaps CLR_YELLOW, do not free */ + /* CLR_GRAY is static 'nilstring', do not free */ + /* NO_COLOR is static 'nilstring', do not free */ + free(hilites[CLR_BRIGHT_BLUE]); + free(hilites[CLR_BRIGHT_GREEN]); + free(hilites[CLR_BRIGHT_CYAN]); + free(hilites[CLR_YELLOW]); + free(hilites[CLR_ORANGE]); + free(hilites[CLR_BRIGHT_MAGENTA]); + free(hilites[CLR_WHITE]); } +#else /* UNIX && TERMINFO */ -# else /* UNIX && TERMINFO */ - -# ifndef TOS +#ifndef TOS /* find the foreground and background colors set by nh_HI or nh_HE */ static void -analyze_seq (str, fg, bg) +analyze_seq(str, fg, bg) char *str; int *fg, *bg; { - register int c, code; - int len; + register int c, code; + int len; -# ifdef MICRO - *fg = CLR_GRAY; *bg = CLR_BLACK; -# else - *fg = *bg = NO_COLOR; -# endif +#ifdef MICRO + *fg = CLR_GRAY; + *bg = CLR_BLACK; +#else + *fg = *bg = NO_COLOR; +#endif - c = (str[0] == '\233') ? 1 : 2; /* index of char beyond esc prefix */ - len = strlen(str) - 1; /* length excluding attrib suffix */ - if ((c != 1 && (str[0] != '\033' || str[1] != '[')) || - (len - c) < 1 || str[len] != 'm') - return; + c = (str[0] == '\233') ? 1 : 2; /* index of char beyond esc prefix */ + len = strlen(str) - 1; /* length excluding attrib suffix */ + if ((c != 1 && (str[0] != '\033' || str[1] != '[')) || (len - c) < 1 + || str[len] != 'm') + return; - while (c < len) { - if ((code = atoi(&str[c])) == 0) { /* reset */ - /* this also catches errors */ -# ifdef MICRO - *fg = CLR_GRAY; *bg = CLR_BLACK; -# else - *fg = *bg = NO_COLOR; -# endif - } else if (code == 1) { /* bold */ - *fg |= BRIGHT; -# if 0 + while (c < len) { + if ((code = atoi(&str[c])) == 0) { /* reset */ +/* this also catches errors */ +#ifdef MICRO + *fg = CLR_GRAY; + *bg = CLR_BLACK; +#else + *fg = *bg = NO_COLOR; +#endif + } else if (code == 1) { /* bold */ + *fg |= BRIGHT; +#if 0 /* I doubt we'll ever resort to using blinking characters, unless we want a pulsing glow for something. But, in case we do... - 3. */ @@ -992,21 +1026,22 @@ int *fg, *bg; *fg |= BLINK; } else if (code == 25) { /* stop blinking */ *fg &= ~BLINK; -# endif - } else if (code == 7 || code == 27) { /* reverse */ - code = *fg & ~BRIGHT; - *fg = *bg | (*fg & BRIGHT); - *bg = code; - } else if (code >= 30 && code <= 37) { /* hi_foreground RGB */ - *fg = code - 30; - } else if (code >= 40 && code <= 47) { /* hi_background RGB */ - *bg = code - 40; - } - while (digit(str[++c])); - c++; - } +#endif + } else if (code == 7 || code == 27) { /* reverse */ + code = *fg & ~BRIGHT; + *fg = *bg | (*fg & BRIGHT); + *bg = code; + } else if (code >= 30 && code <= 37) { /* hi_foreground RGB */ + *fg = code - 30; + } else if (code >= 40 && code <= 47) { /* hi_background RGB */ + *bg = code - 40; + } + while (digit(str[++c])) + ; + c++; + } } -# endif +#endif /* * Sets up highlighting sequences, using ANSI escape sequences (highlight code @@ -1017,104 +1052,105 @@ int *fg, *bg; static void init_hilite() { - register int c; -# ifdef TOS - extern unsigned long tos_numcolors; /* in tos.c */ - static char NOCOL[] = "\033b0", COLHE[] = "\033q\033b0"; + register int c; +#ifdef TOS + extern unsigned long tos_numcolors; /* in tos.c */ + static char NOCOL[] = "\033b0", COLHE[] = "\033q\033b0"; - if (tos_numcolors <= 2) { - return; - } -/* Under TOS, the "bright" and "dim" colors are reversed. Moreover, - * on the Falcon the dim colors are *really* dim; so we make most - * of the colors the bright versions, with a few exceptions where - * the dim ones look OK. - */ - hilites[0] = NOCOL; - for (c = 1; c < SIZE(hilites); c++) { - char *foo; - foo = (char *) alloc(sizeof("\033b0")); - if (tos_numcolors > 4) - Sprintf(foo, "\033b%c", (c&~BRIGHT)+'0'); - else - Strcpy(foo, "\033b0"); - hilites[c] = foo; - } + if (tos_numcolors <= 2) { + return; + } + /* Under TOS, the "bright" and "dim" colors are reversed. Moreover, + * on the Falcon the dim colors are *really* dim; so we make most + * of the colors the bright versions, with a few exceptions where + * the dim ones look OK. + */ + hilites[0] = NOCOL; + for (c = 1; c < SIZE(hilites); c++) { + char *foo; + foo = (char *) alloc(sizeof("\033b0")); + if (tos_numcolors > 4) + Sprintf(foo, "\033b%c", (c & ~BRIGHT) + '0'); + else + Strcpy(foo, "\033b0"); + hilites[c] = foo; + } - if (tos_numcolors == 4) { - TI = "\033b0\033c3\033E\033e"; - TE = "\033b3\033c0\033J"; - nh_HE = COLHE; - hilites[CLR_GREEN] = hilites[CLR_GREEN|BRIGHT] = "\033b2"; - hilites[CLR_RED] = hilites[CLR_RED|BRIGHT] = "\033b1"; - } else { - sprintf(hilites[CLR_BROWN], "\033b%c", (CLR_BROWN^BRIGHT)+'0'); - sprintf(hilites[CLR_GREEN], "\033b%c", (CLR_GREEN^BRIGHT)+'0'); + if (tos_numcolors == 4) { + TI = "\033b0\033c3\033E\033e"; + TE = "\033b3\033c0\033J"; + nh_HE = COLHE; + hilites[CLR_GREEN] = hilites[CLR_GREEN | BRIGHT] = "\033b2"; + hilites[CLR_RED] = hilites[CLR_RED | BRIGHT] = "\033b1"; + } else { + sprintf(hilites[CLR_BROWN], "\033b%c", (CLR_BROWN ^ BRIGHT) + '0'); + sprintf(hilites[CLR_GREEN], "\033b%c", (CLR_GREEN ^ BRIGHT) + '0'); - TI = "\033b0\033c\017\033E\033e"; - TE = "\033b\017\033c0\033J"; - nh_HE = COLHE; - hilites[CLR_WHITE] = hilites[CLR_BLACK] = NOCOL; - hilites[NO_COLOR] = hilites[CLR_GRAY]; - } + TI = "\033b0\033c\017\033E\033e"; + TE = "\033b\017\033c0\033J"; + nh_HE = COLHE; + hilites[CLR_WHITE] = hilites[CLR_BLACK] = NOCOL; + hilites[NO_COLOR] = hilites[CLR_GRAY]; + } -# else /* TOS */ +#else /* TOS */ - int backg, foreg, hi_backg, hi_foreg; + int backg, foreg, hi_backg, hi_foreg; - for (c = 0; c < SIZE(hilites); c++) - hilites[c] = nh_HI; - hilites[CLR_GRAY] = hilites[NO_COLOR] = (char *)0; + for (c = 0; c < SIZE(hilites); c++) + hilites[c] = nh_HI; + hilites[CLR_GRAY] = hilites[NO_COLOR] = (char *) 0; - analyze_seq(nh_HI, &hi_foreg, &hi_backg); - analyze_seq(nh_HE, &foreg, &backg); + analyze_seq(nh_HI, &hi_foreg, &hi_backg); + analyze_seq(nh_HE, &foreg, &backg); - for (c = 0; c < SIZE(hilites); c++) - /* avoid invisibility */ - if ((backg & ~BRIGHT) != c) { -# ifdef MICRO - if (c == CLR_BLUE) continue; -# endif - if (c == foreg) - hilites[c] = (char *)0; - else if (c != hi_foreg || backg != hi_backg) { - hilites[c] = (char *) alloc(sizeof("\033[%d;3%d;4%dm")); - Sprintf(hilites[c], "\033[%d", !!(c & BRIGHT)); - if ((c | BRIGHT) != (foreg | BRIGHT)) - Sprintf(eos(hilites[c]), ";3%d", c & ~BRIGHT); - if (backg != CLR_BLACK) - Sprintf(eos(hilites[c]), ";4%d", backg & ~BRIGHT); - Strcat(hilites[c], "m"); - } - } + for (c = 0; c < SIZE(hilites); c++) + /* avoid invisibility */ + if ((backg & ~BRIGHT) != c) { +#ifdef MICRO + if (c == CLR_BLUE) + continue; +#endif + if (c == foreg) + hilites[c] = (char *) 0; + else if (c != hi_foreg || backg != hi_backg) { + hilites[c] = (char *) alloc(sizeof("\033[%d;3%d;4%dm")); + Sprintf(hilites[c], "\033[%d", !!(c & BRIGHT)); + if ((c | BRIGHT) != (foreg | BRIGHT)) + Sprintf(eos(hilites[c]), ";3%d", c & ~BRIGHT); + if (backg != CLR_BLACK) + Sprintf(eos(hilites[c]), ";4%d", backg & ~BRIGHT); + Strcat(hilites[c], "m"); + } + } -# ifdef MICRO - /* brighten low-visibility colors */ - hilites[CLR_BLUE] = hilites[CLR_BLUE|BRIGHT]; -# endif -# endif /* TOS */ +#ifdef MICRO + /* brighten low-visibility colors */ + hilites[CLR_BLUE] = hilites[CLR_BLUE | BRIGHT]; +#endif +#endif /* TOS */ } static void kill_hilite() { -# ifndef TOS - register int c; +#ifndef TOS + register int c; - for (c = 0; c < CLR_MAX / 2; c++) { - if (hilites[c|BRIGHT] == hilites[c]) hilites[c|BRIGHT] = 0; - if (hilites[c] && (hilites[c] != nh_HI)) - free((genericptr_t) hilites[c]), hilites[c] = 0; - if (hilites[c|BRIGHT] && (hilites[c|BRIGHT] != nh_HI)) - free((genericptr_t) hilites[c|BRIGHT]), hilites[c|BRIGHT] = 0; - } -# endif - return; + for (c = 0; c < CLR_MAX / 2; c++) { + if (hilites[c | BRIGHT] == hilites[c]) + hilites[c | BRIGHT] = 0; + if (hilites[c] && (hilites[c] != nh_HI)) + free((genericptr_t) hilites[c]), hilites[c] = 0; + if (hilites[c | BRIGHT] && (hilites[c | BRIGHT] != nh_HI)) + free((genericptr_t) hilites[c | BRIGHT]), hilites[c | BRIGHT] = 0; + } +#endif + return; } -# endif /* UNIX */ +#endif /* UNIX */ #endif /* TEXTCOLOR */ - static char nulstr[] = ""; static char * @@ -1122,16 +1158,18 @@ s_atr2str(n) int n; { switch (n) { - case ATR_ULINE: - if(nh_US) return nh_US; - case ATR_BOLD: - case ATR_BLINK: + case ATR_ULINE: + if (nh_US) + return nh_US; + case ATR_BOLD: + case ATR_BLINK: #if defined(TERMLIB) && defined(TEXTCOLOR) - if (MD) return MD; + if (MD) + return MD; #endif - return nh_HI; - case ATR_INVERSE: - return MR; + return nh_HI; + case ATR_INVERSE: + return MR; } return nulstr; } @@ -1141,93 +1179,87 @@ e_atr2str(n) int n; { switch (n) { - case ATR_ULINE: - if(nh_UE) return nh_UE; - case ATR_BOLD: - case ATR_BLINK: - return nh_HE; - case ATR_INVERSE: - return ME; + case ATR_ULINE: + if (nh_UE) + return nh_UE; + case ATR_BOLD: + case ATR_BLINK: + return nh_HE; + case ATR_INVERSE: + return ME; } return nulstr; } - void term_start_attr(attr) int attr; { - if (attr) { - xputs(s_atr2str(attr)); - } + if (attr) { + xputs(s_atr2str(attr)); + } } - void term_end_attr(attr) int attr; { - if(attr) { - xputs(e_atr2str(attr)); - } + if (attr) { + xputs(e_atr2str(attr)); + } } - void term_start_raw_bold() { - xputs(nh_HI); + xputs(nh_HI); } - void term_end_raw_bold() { - xputs(nh_HE); + xputs(nh_HE); } - #ifdef TEXTCOLOR void term_end_color() { - xputs(nh_HE); + xputs(nh_HE); } - void term_start_color(color) int color; { - xputs(hilites[color]); + xputs(hilites[color]); } - int has_color(color) int color; { #ifdef X11_GRAPHICS - /* XXX has_color() should be added to windowprocs */ - if (windowprocs.name != NULL && - !strcmpi(windowprocs.name, "X11")) return TRUE; + /* XXX has_color() should be added to windowprocs */ + if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "X11")) + return TRUE; #endif #ifdef GEM_GRAPHICS - /* XXX has_color() should be added to windowprocs */ - if (windowprocs.name != NULL && - !strcmpi(windowprocs.name, "Gem")) return TRUE; + /* XXX has_color() should be added to windowprocs */ + if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "Gem")) + return TRUE; #endif #ifdef QT_GRAPHICS - /* XXX has_color() should be added to windowprocs */ - if (windowprocs.name != NULL && - !strcmpi(windowprocs.name, "Qt")) return TRUE; + /* XXX has_color() should be added to windowprocs */ + if (windowprocs.name != NULL && !strcmpi(windowprocs.name, "Qt")) + return TRUE; #endif #ifdef AMII_GRAPHICS - /* hilites[] not used */ - return iflags.use_color; + /* hilites[] not used */ + return iflags.use_color; #endif - return hilites[color] != (char *)0; + return hilites[color] != (char *) 0; } #endif /* TEXTCOLOR */ diff --git a/win/tty/topl.c b/win/tty/topl.c index c911e45d4..a2e163ac0 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 topl.c $NHDT-Date: 1430040322 2015/04/26 09:25:22 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */ +/* NetHack 3.6 topl.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,11 +10,11 @@ #include "wintty.h" #include -#ifndef C /* this matches src/cmd.c */ -#define C(c) (0x1f & (c)) +#ifndef C /* this matches src/cmd.c */ +#define C(c) (0x1f & (c)) #endif -STATIC_DCL void FDECL(redotoplin, (const char*)); +STATIC_DCL void FDECL(redotoplin, (const char *)); STATIC_DCL void FDECL(topl_putsym, (CHAR_P)); STATIC_DCL void NDECL(remember_topl); STATIC_DCL void FDECL(removetopl, (int)); @@ -28,36 +28,41 @@ tty_doprev_message() winid prevmsg_win; int i; - if ((iflags.prevmsg_window != 's') && !ttyDisplay->inread) { /* not single */ - if(iflags.prevmsg_window == 'f') { /* full */ + if ((iflags.prevmsg_window != 's') + && !ttyDisplay->inread) { /* not single */ + if (iflags.prevmsg_window == 'f') { /* full */ prevmsg_win = create_nhwindow(NHW_MENU); putstr(prevmsg_win, 0, "Message History"); putstr(prevmsg_win, 0, ""); cw->maxcol = cw->maxrow; i = cw->maxcol; do { - if(cw->data[i] && strcmp(cw->data[i], "") ) + if (cw->data[i] && strcmp(cw->data[i], "")) putstr(prevmsg_win, 0, cw->data[i]); i = (i + 1) % cw->rows; } while (i != cw->maxcol); putstr(prevmsg_win, 0, toplines); display_nhwindow(prevmsg_win, TRUE); destroy_nhwindow(prevmsg_win); - } else if (iflags.prevmsg_window == 'c') { /* combination */ + } else if (iflags.prevmsg_window == 'c') { /* combination */ do { morc = 0; if (cw->maxcol == cw->maxrow) { - ttyDisplay->dismiss_more = C('p'); /* allowed at --More-- */ + ttyDisplay->dismiss_more = + C('p'); /* allowed at --More-- */ redotoplin(toplines); cw->maxcol--; - if (cw->maxcol < 0) cw->maxcol = cw->rows-1; + if (cw->maxcol < 0) + cw->maxcol = cw->rows - 1; if (!cw->data[cw->maxcol]) cw->maxcol = cw->maxrow; - } else if (cw->maxcol == (cw->maxrow - 1)){ - ttyDisplay->dismiss_more = C('p'); /* allowed at --More-- */ + } else if (cw->maxcol == (cw->maxrow - 1)) { + ttyDisplay->dismiss_more = + C('p'); /* allowed at --More-- */ redotoplin(cw->data[cw->maxcol]); cw->maxcol--; - if (cw->maxcol < 0) cw->maxcol = cw->rows-1; + if (cw->maxcol < 0) + cw->maxcol = cw->rows - 1; if (!cw->data[cw->maxcol]) cw->maxcol = cw->maxrow; } else { @@ -67,7 +72,7 @@ tty_doprev_message() cw->maxcol = cw->maxrow; i = cw->maxcol; do { - if(cw->data[i] && strcmp(cw->data[i], "") ) + if (cw->data[i] && strcmp(cw->data[i], "")) putstr(prevmsg_win, 0, cw->data[i]); i = (i + 1) % cw->rows; } while (i != cw->maxcol); @@ -84,12 +89,14 @@ tty_doprev_message() putstr(prevmsg_win, 0, "Message History"); putstr(prevmsg_win, 0, ""); putstr(prevmsg_win, 0, toplines); - cw->maxcol=cw->maxrow-1; - if(cw->maxcol < 0) cw->maxcol = cw->rows-1; + cw->maxcol = cw->maxrow - 1; + if (cw->maxcol < 0) + cw->maxcol = cw->rows - 1; do { putstr(prevmsg_win, 0, cw->data[cw->maxcol]); cw->maxcol--; - if (cw->maxcol < 0) cw->maxcol = cw->rows-1; + if (cw->maxcol < 0) + cw->maxcol = cw->rows - 1; if (!cw->data[cw->maxcol]) cw->maxcol = cw->maxrow; } while (cw->maxcol != cw->maxrow); @@ -99,8 +106,8 @@ tty_doprev_message() cw->maxcol = cw->maxrow; ttyDisplay->dismiss_more = 0; } - } else if(iflags.prevmsg_window == 's') { /* single */ - ttyDisplay->dismiss_more = C('p'); /* allowed at --More-- */ + } else if (iflags.prevmsg_window == 's') { /* single */ + ttyDisplay->dismiss_more = C('p'); /* allowed at --More-- */ do { morc = 0; if (cw->maxcol == cw->maxrow) @@ -108,7 +115,8 @@ tty_doprev_message() else if (cw->data[cw->maxcol]) redotoplin(cw->data[cw->maxcol]); cw->maxcol--; - if (cw->maxcol < 0) cw->maxcol = cw->rows-1; + if (cw->maxcol < 0) + cw->maxcol = cw->rows - 1; if (!cw->data[cw->maxcol]) cw->maxcol = cw->maxrow; } while (morc == C('p')); @@ -119,22 +127,22 @@ tty_doprev_message() STATIC_OVL void redotoplin(str) - const char *str; +const char *str; { - int otoplin = ttyDisplay->toplin; - home(); - if(*str & 0x80) { - /* kludge for the / command, the only time we ever want a */ - /* graphics character on the top line */ - g_putch((int)*str++); - ttyDisplay->curx++; - } - end_glyphout(); /* in case message printed during graphics output */ - putsyms(str); - cl_end(); - ttyDisplay->toplin = 1; - if(ttyDisplay->cury && otoplin != 3) - more(); + int otoplin = ttyDisplay->toplin; + home(); + if (*str & 0x80) { + /* kludge for the / command, the only time we ever want a */ + /* graphics character on the top line */ + g_putch((int) *str++); + ttyDisplay->curx++; + } + end_glyphout(); /* in case message printed during graphics output */ + putsyms(str); + cl_end(); + ttyDisplay->toplin = 1; + if (ttyDisplay->cury && otoplin != 3) + more(); } STATIC_OVL void @@ -144,14 +152,15 @@ remember_topl() int idx = cw->maxrow; unsigned len = strlen(toplines) + 1; - if ((cw->flags & WIN_LOCKHISTORY) || !*toplines) return; + if ((cw->flags & WIN_LOCKHISTORY) || !*toplines) + return; - - if (len > (unsigned)cw->datlen[idx]) { - if (cw->data[idx]) free(cw->data[idx]); - len += (8 - (len & 7)); /* pad up to next multiple of 8 */ - cw->data[idx] = (char *)alloc(len); - cw->datlen[idx] = (short)len; + if (len > (unsigned) cw->datlen[idx]) { + if (cw->data[idx]) + free(cw->data[idx]); + len += (8 - (len & 7)); /* pad up to next multiple of 8 */ + cw->data[idx] = (char *) alloc(len); + cw->datlen[idx] = (short) len; } Strcpy(cw->data[idx], toplines); *toplines = '\0'; @@ -164,7 +173,7 @@ const char *s; { register struct WinDesc *cw = wins[WIN_MESSAGE]; - tty_curs(BASE_WINDOW,cw->curx+1,cw->cury); + tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury); putsyms(s); cl_end(); ttyDisplay->toplin = 1; @@ -176,33 +185,34 @@ more() struct WinDesc *cw = wins[WIN_MESSAGE]; /* avoid recursion -- only happens from interrupts */ - if(ttyDisplay->inmore++) - return; + if (ttyDisplay->inmore++) + return; - if(ttyDisplay->toplin) { - tty_curs(BASE_WINDOW, cw->curx+1, cw->cury); - if(cw->curx >= CO - 8) topl_putsym('\n'); + if (ttyDisplay->toplin) { + tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury); + if (cw->curx >= CO - 8) + topl_putsym('\n'); } - if(flags.standout) - standoutbeg(); + if (flags.standout) + standoutbeg(); putsyms(defmorestr); - if(flags.standout) - standoutend(); + if (flags.standout) + standoutend(); xwaitforspace("\033 "); - if(morc == '\033') - cw->flags |= WIN_STOP; + if (morc == '\033') + cw->flags |= WIN_STOP; - if(ttyDisplay->toplin && cw->cury) { - docorner(1, cw->cury+1); - cw->curx = cw->cury = 0; - home(); - } else if(morc == '\033') { - cw->curx = cw->cury = 0; - home(); - cl_end(); + if (ttyDisplay->toplin && cw->cury) { + docorner(1, cw->cury + 1); + cw->curx = cw->cury = 0; + home(); + } else if (morc == '\033') { + cw->curx = cw->cury = 0; + home(); + cl_end(); } ttyDisplay->toplin = 0; ttyDisplay->inmore = 0; @@ -210,88 +220,94 @@ more() void update_topl(bp) - register const char *bp; +register const char *bp; { - register char *tl, *otl; - register int n0; - int notdied = 1; - struct WinDesc *cw = wins[WIN_MESSAGE]; + register char *tl, *otl; + register int n0; + int notdied = 1; + struct WinDesc *cw = wins[WIN_MESSAGE]; - /* If there is room on the line, print message on same line */ - /* But messages like "You die..." deserve their own line */ - n0 = strlen(bp); - if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && - cw->cury == 0 && - n0 + (int)strlen(toplines) + 3 < CO-8 && /* room for --More-- */ - (notdied = strncmp(bp, "You die", 7))) { - Strcat(toplines, " "); - Strcat(toplines, bp); - cw->curx += 2; - if(!(cw->flags & WIN_STOP)) - addtopl(bp); - return; - } else if (!(cw->flags & WIN_STOP)) { - if(ttyDisplay->toplin == 1) more(); - else if(cw->cury) { /* for when flags.toplin == 2 && cury > 1 */ - docorner(1, cw->cury+1); /* reset cury = 0 if redraw screen */ - cw->curx = cw->cury = 0;/* from home--cls() & docorner(1,n) */ - } - } - remember_topl(); - (void) strncpy(toplines, bp, TBUFSZ); - toplines[TBUFSZ - 1] = 0; + /* If there is room on the line, print message on same line */ + /* But messages like "You die..." deserve their own line */ + n0 = strlen(bp); + if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0 + && n0 + (int) strlen(toplines) + 3 < CO - 8 && /* room for --More-- */ + (notdied = strncmp(bp, "You die", 7))) { + Strcat(toplines, " "); + Strcat(toplines, bp); + cw->curx += 2; + if (!(cw->flags & WIN_STOP)) + addtopl(bp); + return; + } else if (!(cw->flags & WIN_STOP)) { + if (ttyDisplay->toplin == 1) + more(); + else if (cw->cury) { /* for when flags.toplin == 2 && cury > 1 */ + docorner(1, cw->cury + 1); /* reset cury = 0 if redraw screen */ + cw->curx = cw->cury = 0; /* from home--cls() & docorner(1,n) */ + } + } + remember_topl(); + (void) strncpy(toplines, bp, TBUFSZ); + toplines[TBUFSZ - 1] = 0; - for(tl = toplines; n0 >= CO; ){ - otl = tl; - for(tl+=CO-1; tl != otl && !isspace(*tl); --tl) ; - if(tl == otl) { - /* Eek! A huge token. Try splitting after it. */ - tl = index(otl, ' '); - if (!tl) break; /* No choice but to spit it out whole. */ - } - *tl++ = '\n'; - n0 = strlen(tl); - } - if(!notdied) cw->flags &= ~WIN_STOP; - if(!(cw->flags & WIN_STOP)) redotoplin(toplines); + for (tl = toplines; n0 >= CO;) { + otl = tl; + for (tl += CO - 1; tl != otl && !isspace(*tl); --tl) + ; + if (tl == otl) { + /* Eek! A huge token. Try splitting after it. */ + tl = index(otl, ' '); + if (!tl) + break; /* No choice but to spit it out whole. */ + } + *tl++ = '\n'; + n0 = strlen(tl); + } + if (!notdied) + cw->flags &= ~WIN_STOP; + if (!(cw->flags & WIN_STOP)) + redotoplin(toplines); } STATIC_OVL void topl_putsym(c) - char c; +char c; { register struct WinDesc *cw = wins[WIN_MESSAGE]; - if(cw == (struct WinDesc *) 0) panic("Putsym window MESSAGE nonexistant"); - - switch(c) { + if (cw == (struct WinDesc *) 0) + panic("Putsym window MESSAGE nonexistant"); + + switch (c) { case '\b': - if(ttyDisplay->curx == 0 && ttyDisplay->cury > 0) - tty_curs(BASE_WINDOW, CO, (int)ttyDisplay->cury-1); - backsp(); - ttyDisplay->curx--; - cw->curx = ttyDisplay->curx; - return; + if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0) + tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1); + backsp(); + ttyDisplay->curx--; + cw->curx = ttyDisplay->curx; + return; case '\n': - cl_end(); - ttyDisplay->curx = 0; - ttyDisplay->cury++; - cw->cury = ttyDisplay->cury; + cl_end(); + ttyDisplay->curx = 0; + ttyDisplay->cury++; + cw->cury = ttyDisplay->cury; #ifdef WIN32CON - (void) putchar(c); + (void) putchar(c); #endif - break; + break; default: - if(ttyDisplay->curx == CO-1) - topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */ + if (ttyDisplay->curx == CO - 1) + topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */ #ifdef WIN32CON - (void) putchar(c); + (void) putchar(c); #endif - ttyDisplay->curx++; + ttyDisplay->curx++; } cw->curx = ttyDisplay->curx; - if(cw->curx == 0) cl_end(); + if (cw->curx == 0) + cl_end(); #ifndef WIN32CON (void) putchar(c); #endif @@ -299,10 +315,10 @@ topl_putsym(c) void putsyms(str) - const char *str; +const char *str; { - while(*str) - topl_putsym(*str++); + while (*str) + topl_putsym(*str++); } STATIC_OVL void @@ -310,14 +326,15 @@ removetopl(n) register int n; { /* assume addtopl() has been done, so ttyDisplay->toplin is already set */ - while (n-- > 0) putsyms("\b \b"); + while (n-- > 0) + putsyms("\b \b"); } -extern char erase_char; /* from xxxtty.c; don't need kill_char */ +extern char erase_char; /* from xxxtty.c; don't need kill_char */ char -tty_yn_function(query,resp, def) -const char *query,*resp; +tty_yn_function(query, resp, def) +const char *query, *resp; char def; /* * Generic yes/no function. 'def' is the default (returned by space or @@ -331,148 +348,163 @@ char def; * be shown in the prompt to the user but will be acceptable as input. */ { - register char q; - char rtmp[40]; - boolean digit_ok, allow_num, preserve_case = FALSE; - struct WinDesc *cw = wins[WIN_MESSAGE]; - boolean doprev = 0; - char prompt[BUFSZ]; + register char q; + char rtmp[40]; + boolean digit_ok, allow_num, preserve_case = FALSE; + struct WinDesc *cw = wins[WIN_MESSAGE]; + boolean doprev = 0; + char prompt[BUFSZ]; - if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); - cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = 3; /* special prompt state */ - ttyDisplay->inread++; - if (resp) { - char *rb, respbuf[QBUFSZ]; + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) + more(); + cw->flags &= ~WIN_STOP; + ttyDisplay->toplin = 3; /* special prompt state */ + ttyDisplay->inread++; + if (resp) { + char *rb, respbuf[QBUFSZ]; - allow_num = (index(resp, '#') != 0); - Strcpy(respbuf, resp); - /* normally we force lowercase, but if any uppercase letters - are present in the allowed response, preserve case; - check this before stripping the hidden choices */ - for (rb = respbuf; *rb; ++rb) - if ('A' <= *rb && *rb <= 'Z') { - preserve_case = TRUE; - break; - } - /* any acceptable responses that follow aren't displayed */ - if ((rb = index(respbuf, '\033')) != 0) *rb = '\0'; - (void)strncpy(prompt, query, QBUFSZ-1); - prompt[QBUFSZ-1] = '\0'; - Sprintf(eos(prompt), " [%s]", respbuf); - if (def) Sprintf(eos(prompt), " (%c)", def); - /* not pline("%s ", prompt); - trailing space is wanted here in case of reprompt */ - Strcat(prompt, " "); - pline("%s", prompt); - } else { - /* no restriction on allowed response, so always preserve case */ - /* preserve_case = TRUE; -- moot since we're jumping to the end */ - pline("%s ", query); - q = readchar(); - goto clean_up; - } + allow_num = (index(resp, '#') != 0); + Strcpy(respbuf, resp); + /* normally we force lowercase, but if any uppercase letters + are present in the allowed response, preserve case; + check this before stripping the hidden choices */ + for (rb = respbuf; *rb; ++rb) + if ('A' <= *rb && *rb <= 'Z') { + preserve_case = TRUE; + break; + } + /* any acceptable responses that follow aren't displayed */ + if ((rb = index(respbuf, '\033')) != 0) + *rb = '\0'; + (void) strncpy(prompt, query, QBUFSZ - 1); + prompt[QBUFSZ - 1] = '\0'; + Sprintf(eos(prompt), " [%s]", respbuf); + if (def) + Sprintf(eos(prompt), " (%c)", def); + /* not pline("%s ", prompt); + trailing space is wanted here in case of reprompt */ + Strcat(prompt, " "); + pline("%s", prompt); + } else { + /* no restriction on allowed response, so always preserve case */ + /* preserve_case = TRUE; -- moot since we're jumping to the end */ + pline("%s ", query); + q = readchar(); + goto clean_up; + } - do { /* loop until we get valid input */ - q = readchar(); - if (!preserve_case) q = lowc(q); - if (q == '\020') { /* ctrl-P */ - if (iflags.prevmsg_window != 's') { - int sav = ttyDisplay->inread; - ttyDisplay->inread = 0; - (void) tty_doprev_message(); - ttyDisplay->inread = sav; - tty_clear_nhwindow(WIN_MESSAGE); - cw->maxcol = cw->maxrow; - addtopl(prompt); - } else { - if(!doprev) - (void) tty_doprev_message(); /* need two initially */ - (void) tty_doprev_message(); - doprev = 1; - } - q = '\0'; /* force another loop iteration */ - continue; - } else if (doprev) { - /* BUG[?]: this probably ought to check whether the - character which has just been read is an acceptable - response; if so, skip the reprompt and use it. */ - tty_clear_nhwindow(WIN_MESSAGE); - cw->maxcol = cw->maxrow; - doprev = 0; - addtopl(prompt); - q = '\0'; /* force another loop iteration */ - continue; - } - digit_ok = allow_num && digit(q); - if (q == '\033') { - if (index(resp, 'q')) - q = 'q'; - else if (index(resp, 'n')) - q = 'n'; - else - q = def; - break; - } else if (index(quitchars, q)) { - q = def; - break; - } - if (!index(resp, q) && !digit_ok) { - tty_nhbell(); - q = (char)0; - } else if (q == '#' || digit_ok) { - char z, digit_string[2]; - int n_len = 0; - long value = 0; - addtopl("#"), n_len++; - digit_string[1] = '\0'; - if (q != '#') { - digit_string[0] = q; - addtopl(digit_string), n_len++; - value = q - '0'; - q = '#'; - } - do { /* loop until we get a non-digit */ - z = readchar(); - if (!preserve_case) z = lowc(z); - if (digit(z)) { - value = (10 * value) + (z - '0'); - if (value < 0) break; /* overflow: try again */ - digit_string[0] = z; - addtopl(digit_string), n_len++; - } else if (z == 'y' || index(quitchars, z)) { - if (z == '\033') value = -1; /* abort */ - z = '\n'; /* break */ - } else if (z == erase_char || z == '\b') { - if (n_len <= 1) { value = -1; break; } - else { value /= 10; removetopl(1), n_len--; } - } else { - value = -1; /* abort */ - tty_nhbell(); - break; - } - } while (z != '\n'); - if (value > 0) yn_number = value; - else if (value == 0) q = 'n'; /* 0 => "no" */ - else { /* remove number from top line, then try again */ - removetopl(n_len), n_len = 0; - q = '\0'; - } - } - } while(!q); + do { /* loop until we get valid input */ + q = readchar(); + if (!preserve_case) + q = lowc(q); + if (q == '\020') { /* ctrl-P */ + if (iflags.prevmsg_window != 's') { + int sav = ttyDisplay->inread; + ttyDisplay->inread = 0; + (void) tty_doprev_message(); + ttyDisplay->inread = sav; + tty_clear_nhwindow(WIN_MESSAGE); + cw->maxcol = cw->maxrow; + addtopl(prompt); + } else { + if (!doprev) + (void) tty_doprev_message(); /* need two initially */ + (void) tty_doprev_message(); + doprev = 1; + } + q = '\0'; /* force another loop iteration */ + continue; + } else if (doprev) { + /* BUG[?]: this probably ought to check whether the + character which has just been read is an acceptable + response; if so, skip the reprompt and use it. */ + tty_clear_nhwindow(WIN_MESSAGE); + cw->maxcol = cw->maxrow; + doprev = 0; + addtopl(prompt); + q = '\0'; /* force another loop iteration */ + continue; + } + digit_ok = allow_num && digit(q); + if (q == '\033') { + if (index(resp, 'q')) + q = 'q'; + else if (index(resp, 'n')) + q = 'n'; + else + q = def; + break; + } else if (index(quitchars, q)) { + q = def; + break; + } + if (!index(resp, q) && !digit_ok) { + tty_nhbell(); + q = (char) 0; + } else if (q == '#' || digit_ok) { + char z, digit_string[2]; + int n_len = 0; + long value = 0; + addtopl("#"), n_len++; + digit_string[1] = '\0'; + if (q != '#') { + digit_string[0] = q; + addtopl(digit_string), n_len++; + value = q - '0'; + q = '#'; + } + do { /* loop until we get a non-digit */ + z = readchar(); + if (!preserve_case) + z = lowc(z); + if (digit(z)) { + value = (10 * value) + (z - '0'); + if (value < 0) + break; /* overflow: try again */ + digit_string[0] = z; + addtopl(digit_string), n_len++; + } else if (z == 'y' || index(quitchars, z)) { + if (z == '\033') + value = -1; /* abort */ + z = '\n'; /* break */ + } else if (z == erase_char || z == '\b') { + if (n_len <= 1) { + value = -1; + break; + } else { + value /= 10; + removetopl(1), n_len--; + } + } else { + value = -1; /* abort */ + tty_nhbell(); + break; + } + } while (z != '\n'); + if (value > 0) + yn_number = value; + else if (value == 0) + q = 'n'; /* 0 => "no" */ + else { /* remove number from top line, then try again */ + removetopl(n_len), n_len = 0; + q = '\0'; + } + } + } while (!q); - if (q != '#') { - Sprintf(rtmp, "%c", q); - addtopl(rtmp); - } - clean_up: - ttyDisplay->inread--; - ttyDisplay->toplin = 2; - if (ttyDisplay->intr) ttyDisplay->intr--; - if(wins[WIN_MESSAGE]->cury) - tty_clear_nhwindow(WIN_MESSAGE); + if (q != '#') { + Sprintf(rtmp, "%c", q); + addtopl(rtmp); + } +clean_up: + ttyDisplay->inread--; + ttyDisplay->toplin = 2; + if (ttyDisplay->intr) + ttyDisplay->intr--; + if (wins[WIN_MESSAGE]->cury) + tty_clear_nhwindow(WIN_MESSAGE); - return q; + return q; } /* shared by tty_getmsghistory() and tty_putmsghistory() */ @@ -482,14 +514,15 @@ static char **snapshot_mesgs = 0; optionally, purge that data from the active circular buffer set as we go */ STATIC_OVL void msghistory_snapshot(purge) -boolean purge; /* clear message history buffer as we copy it */ +boolean purge; /* clear message history buffer as we copy it */ { char *mesg; int i, inidx, outidx; struct WinDesc *cw; /* paranoia (too early or too late panic save attempt?) */ - if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) return; + if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) + return; cw = wins[WIN_MESSAGE]; /* flush toplines[], moving most recent message to history */ @@ -497,49 +530,52 @@ boolean purge; /* clear message history buffer as we copy it */ /* for a passive snapshot, we just copy pointers, so can't allow further history updating to take place because that could clobber them */ - if (!purge) cw->flags |= WIN_LOCKHISTORY; + if (!purge) + cw->flags |= WIN_LOCKHISTORY; - snapshot_mesgs = (char **)alloc((cw->rows + 1) * sizeof (char *)); + snapshot_mesgs = (char **) alloc((cw->rows + 1) * sizeof(char *)); outidx = 0; inidx = cw->maxrow; for (i = 0; i < cw->rows; ++i) { - snapshot_mesgs[i] = (char *)0; - mesg = cw->data[inidx]; - if (mesg && *mesg) { - snapshot_mesgs[outidx++] = mesg; - if (purge) { - /* we're taking this pointer away; subsequest history - updates will eventually allocate a new one to replace it */ - cw->data[inidx] = (char *)0; - cw->datlen[inidx] = 0; - } - } - inidx = (inidx + 1) % cw->rows; + snapshot_mesgs[i] = (char *) 0; + mesg = cw->data[inidx]; + if (mesg && *mesg) { + snapshot_mesgs[outidx++] = mesg; + if (purge) { + /* we're taking this pointer away; subsequest history + updates will eventually allocate a new one to replace it */ + cw->data[inidx] = (char *) 0; + cw->datlen[inidx] = 0; + } + } + inidx = (inidx + 1) % cw->rows; } - snapshot_mesgs[cw->rows] = (char *)0; /* sentinel */ + snapshot_mesgs[cw->rows] = (char *) 0; /* sentinel */ /* for a destructive snapshot, history is now completely empty */ - if (purge) cw->maxcol = cw->maxrow = 0; + if (purge) + cw->maxcol = cw->maxrow = 0; } /* release memory allocated to message history snapshot */ STATIC_OVL void free_msghistory_snapshot(purged) -boolean purged; /* True: took history's pointers, False: just cloned them */ +boolean purged; /* True: took history's pointers, False: just cloned them */ { if (snapshot_mesgs) { - /* snapshot pointers are no longer in use */ - if (purged) { - int i; + /* snapshot pointers are no longer in use */ + if (purged) { + int i; - for (i = 0; snapshot_mesgs[i]; ++i) - free((genericptr_t)snapshot_mesgs[i]); - } + for (i = 0; snapshot_mesgs[i]; ++i) + free((genericptr_t) snapshot_mesgs[i]); + } - free((genericptr_t)snapshot_mesgs), snapshot_mesgs = (char **)0; + free((genericptr_t) snapshot_mesgs), snapshot_mesgs = (char **) 0; - /* history can resume being updated at will now... */ - if (!purged) wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY; + /* history can resume being updated at will now... */ + if (!purged) + wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY; } } @@ -562,17 +598,17 @@ boolean init; char *result = 0; if (init) { - msghistory_snapshot(FALSE); - nxtidx = 0; + msghistory_snapshot(FALSE); + nxtidx = 0; } if (snapshot_mesgs) { - nextmesg = snapshot_mesgs[nxtidx++]; - if (nextmesg) { - result = (char *)nextmesg; - } else { - free_msghistory_snapshot(FALSE); - } + nextmesg = snapshot_mesgs[nxtidx++]; + if (nextmesg) { + result = (char *) nextmesg; + } else { + free_msghistory_snapshot(FALSE); + } } return result; } @@ -603,28 +639,29 @@ boolean restoring_msghist; int idx; if (restoring_msghist && !initd) { - /* we're restoring history from the previous session, but new - messages have already been issued this session ("Restoring...", - for instance); collect current history (ie, those new messages), - and also clear it out so that nothing will be present when the - restored ones are being put into place */ - msghistory_snapshot(TRUE); - initd = TRUE; + /* we're restoring history from the previous session, but new + messages have already been issued this session ("Restoring...", + for instance); collect current history (ie, those new messages), + and also clear it out so that nothing will be present when the + restored ones are being put into place */ + msghistory_snapshot(TRUE); + initd = TRUE; } if (msg) { - /* move most recent message to history, make this become most recent */ - remember_topl(); - Strcpy(toplines, msg); + /* move most recent message to history, make this become most recent + */ + remember_topl(); + Strcpy(toplines, msg); } else if (snapshot_mesgs) { - /* done putting arbitrary messages in; put the snapshot ones back */ - for (idx = 0; snapshot_mesgs[idx]; ++idx) { - remember_topl(); - Strcpy(toplines, snapshot_mesgs[idx]); - } - /* now release the snapshot */ - free_msghistory_snapshot(TRUE); - initd = FALSE; /* reset */ + /* done putting arbitrary messages in; put the snapshot ones back */ + for (idx = 0; snapshot_mesgs[idx]; ++idx) { + remember_topl(); + Strcpy(toplines, snapshot_mesgs[idx]); + } + /* now release the snapshot */ + free_msghistory_snapshot(TRUE); + initd = FALSE; /* reset */ } } diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 4b681a0ea..751a9ff5f 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wintty.c $NHDT-Date: 1428828474 2015/04/12 08:47:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.85 $ */ +/* NetHack 3.6 wintty.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.92 $ */ /* NetHack 3.6 wintty.c $Date: 2012/01/22 06:27:09 $ $Revision: 1.66 $ */ /* Copyright (c) David Cohrs, 1991 */ /* NetHack may be freely redistributed. See license for details. */ @@ -19,12 +19,11 @@ #include "dlb.h" #ifdef MAC -# define MICRO /* The Mac is a MICRO only for this file, not in general! */ -# ifdef THINK_C -extern void msmsg(const char *,...); -# endif +#define MICRO /* The Mac is a MICRO only for this file, not in general! */ +#ifdef THINK_C +extern void msmsg(const char *, ...); +#endif #endif - #ifndef NO_TERMS #include "tcap.h" @@ -32,10 +31,11 @@ extern void msmsg(const char *,...); #include "wintty.h" -#ifdef CLIPPING /* might want SIGWINCH */ -# if defined(BSD) || defined(ULTRIX) || defined(AIX_31) || defined(_BULL_SOURCE) +#ifdef CLIPPING /* might want SIGWINCH */ +#if defined(BSD) || defined(ULTRIX) || defined(AIX_31) \ + || defined(_BULL_SOURCE) #include -# endif +#endif #endif extern char mapped_menu_cmds[]; /* from options.c */ @@ -47,38 +47,22 @@ extern NEARDATA winid WIN_STATUS; struct window_procs tty_procs = { "tty", #ifdef MSDOS - WC_TILED_MAP|WC_ASCII_MAP| + WC_TILED_MAP | WC_ASCII_MAP | #endif #if defined(WIN32CON) - WC_MOUSE_SUPPORT| + WC_MOUSE_SUPPORT | #endif - WC_COLOR|WC_HILITE_PET|WC_INVERSE|WC_EIGHT_BIT_IN, + WC_COLOR | WC_HILITE_PET | WC_INVERSE | WC_EIGHT_BIT_IN, #if defined(SELECTSAVED) - WC2_SELECTSAVED| + WC2_SELECTSAVED | #endif - WC2_DARKGRAY, - tty_init_nhwindows, - tty_player_selection, - tty_askname, - tty_get_nh_event, - tty_exit_nhwindows, - tty_suspend_nhwindows, - tty_resume_nhwindows, - tty_create_nhwindow, - tty_clear_nhwindow, - tty_display_nhwindow, - tty_destroy_nhwindow, - tty_curs, - tty_putstr, - genl_putmixed, - tty_display_file, - tty_start_menu, - tty_add_menu, - tty_end_menu, - tty_select_menu, - tty_message_menu, - tty_update_inventory, - tty_mark_synch, + WC2_DARKGRAY, + tty_init_nhwindows, tty_player_selection, tty_askname, tty_get_nh_event, + tty_exit_nhwindows, tty_suspend_nhwindows, tty_resume_nhwindows, + tty_create_nhwindow, tty_clear_nhwindow, tty_display_nhwindow, + tty_destroy_nhwindow, tty_curs, tty_putstr, genl_putmixed, + tty_display_file, tty_start_menu, tty_add_menu, tty_end_menu, + tty_select_menu, tty_message_menu, tty_update_inventory, tty_mark_synch, tty_wait_synch, #ifdef CLIPPING tty_cliparound, @@ -86,72 +70,57 @@ struct window_procs tty_procs = { #ifdef POSITIONBAR tty_update_positionbar, #endif - tty_print_glyph, - tty_raw_print, - tty_raw_print_bold, - tty_nhgetch, - tty_nh_poskey, - tty_nhbell, - tty_doprev_message, - tty_yn_function, - tty_getlin, - tty_get_ext_cmd, - tty_number_pad, - tty_delay_output, -#ifdef CHANGE_COLOR /* the Mac uses a palette device */ + tty_print_glyph, tty_raw_print, tty_raw_print_bold, tty_nhgetch, + tty_nh_poskey, tty_nhbell, tty_doprev_message, tty_yn_function, + tty_getlin, tty_get_ext_cmd, tty_number_pad, tty_delay_output, +#ifdef CHANGE_COLOR /* the Mac uses a palette device */ tty_change_color, #ifdef MAC - tty_change_background, - set_tty_font_name, + tty_change_background, set_tty_font_name, #endif tty_get_color_string, #endif /* other defs that really should go away (they're tty specific) */ - tty_start_screen, - tty_end_screen, - genl_outrip, + tty_start_screen, tty_end_screen, genl_outrip, #if defined(WIN32) nttty_preference_update, #else genl_preference_update, #endif - tty_getmsghistory, - tty_putmsghistory, + tty_getmsghistory, tty_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - genl_status_init, - genl_status_finish, - genl_status_enablefield, + genl_status_init, genl_status_finish, genl_status_enablefield, genl_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES genl_status_threshold, -# endif +#endif #endif genl_can_suspend_yes, }; -static int maxwin = 0; /* number of windows in use */ +static int maxwin = 0; /* number of windows in use */ winid BASE_WINDOW; struct WinDesc *wins[MAXWIN]; -struct DisplayDesc *ttyDisplay; /* the tty display descriptor */ +struct DisplayDesc *ttyDisplay; /* the tty display descriptor */ -extern void FDECL(cmov, (int,int)); /* from termcap.c */ -extern void FDECL(nocmov, (int,int)); /* from termcap.c */ +extern void FDECL(cmov, (int, int)); /* from termcap.c */ +extern void FDECL(nocmov, (int, int)); /* from termcap.c */ #if defined(UNIX) || defined(VMS) -static char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */ +static char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */ #endif static char winpanicstr[] = "Bad window id %d"; char defmorestr[] = "--More--"; #ifdef CLIPPING -# if defined(USE_TILES) && defined(MSDOS) -boolean clipping = FALSE; /* clipping on? */ +#if defined(USE_TILES) && defined(MSDOS) +boolean clipping = FALSE; /* clipping on? */ int clipx = 0, clipxmax = 0; -# else -static boolean clipping = FALSE; /* clipping on? */ +#else +static boolean clipping = FALSE; /* clipping on? */ static int clipx = 0, clipxmax = 0; -# endif +#endif static int clipy = 0, clipymax = 0; #endif /* CLIPPING */ @@ -161,7 +130,7 @@ extern void FDECL(adjust_cursor_flags, (struct WinDesc *)); #if defined(ASCIIGRAPH) && !defined(NO_TERMS) boolean GFlag = FALSE; -boolean HE_resets_AS; /* see termcap.c */ +boolean HE_resets_AS; /* see termcap.c */ #endif #if defined(MICRO) || defined(WIN32CON) @@ -170,42 +139,38 @@ static const char to_continue[] = "to continue"; #else STATIC_DCL void NDECL(getret); #endif -STATIC_DCL void FDECL(erase_menu_or_text, (winid, struct WinDesc *, BOOLEAN_P)); +STATIC_DCL void FDECL(erase_menu_or_text, + (winid, struct WinDesc *, BOOLEAN_P)); STATIC_DCL void FDECL(free_window_info, (struct WinDesc *, BOOLEAN_P)); -STATIC_DCL void FDECL(dmore,(struct WinDesc *, const char *)); +STATIC_DCL void FDECL(dmore, (struct WinDesc *, const char *)); STATIC_DCL void FDECL(set_item_state, (winid, int, tty_menu_item *)); -STATIC_DCL void FDECL(set_all_on_page, (winid,tty_menu_item *,tty_menu_item *)); -STATIC_DCL void FDECL(unset_all_on_page, (winid,tty_menu_item *,tty_menu_item *)); -STATIC_DCL void FDECL(invert_all_on_page, (winid,tty_menu_item *,tty_menu_item *, CHAR_P)); -STATIC_DCL void FDECL(invert_all, (winid,tty_menu_item *,tty_menu_item *, CHAR_P)); -STATIC_DCL void FDECL(process_menu_window, (winid,struct WinDesc *)); -STATIC_DCL void FDECL(process_text_window, (winid,struct WinDesc *)); +STATIC_DCL void FDECL(set_all_on_page, + (winid, tty_menu_item *, tty_menu_item *)); +STATIC_DCL void FDECL(unset_all_on_page, + (winid, tty_menu_item *, tty_menu_item *)); +STATIC_DCL void FDECL(invert_all_on_page, + (winid, tty_menu_item *, tty_menu_item *, CHAR_P)); +STATIC_DCL void FDECL(invert_all, + (winid, tty_menu_item *, tty_menu_item *, CHAR_P)); +STATIC_DCL void FDECL(process_menu_window, (winid, struct WinDesc *)); +STATIC_DCL void FDECL(process_text_window, (winid, struct WinDesc *)); STATIC_DCL tty_menu_item *FDECL(reverse, (tty_menu_item *)); -STATIC_DCL const char * FDECL(compress_str, (const char *)); +STATIC_DCL const char *FDECL(compress_str, (const char *)); STATIC_DCL void FDECL(tty_putsym, (winid, int, int, CHAR_P)); STATIC_DCL char *FDECL(copy_of, (const char *)); -STATIC_DCL void FDECL(bail, (const char *)); /* __attribute__((noreturn)) */ +STATIC_DCL void FDECL(bail, (const char *)); /* __attribute__((noreturn)) */ /* * A string containing all the default commands -- to add to a list * of acceptable inputs. */ static const char default_menu_cmds[] = { - MENU_FIRST_PAGE, - MENU_LAST_PAGE, - MENU_NEXT_PAGE, - MENU_PREVIOUS_PAGE, - MENU_SELECT_ALL, - MENU_UNSELECT_ALL, - MENU_INVERT_ALL, - MENU_SELECT_PAGE, - MENU_UNSELECT_PAGE, - MENU_INVERT_PAGE, - MENU_SEARCH, - 0 /* null terminator */ + MENU_FIRST_PAGE, MENU_LAST_PAGE, MENU_NEXT_PAGE, + MENU_PREVIOUS_PAGE, MENU_SELECT_ALL, MENU_UNSELECT_ALL, + MENU_INVERT_ALL, MENU_SELECT_PAGE, MENU_UNSELECT_PAGE, + MENU_INVERT_PAGE, MENU_SEARCH, 0 /* null terminator */ }; - /* clean up and quit */ STATIC_OVL void bail(mesg) @@ -224,99 +189,101 @@ winch() int oldLI = LI, oldCO = CO, i; register struct WinDesc *cw; -# ifdef WINCHAIN +#ifdef WINCHAIN { -# define WINCH_MESSAGE "(SIGWINCH)" -if(wc_tracelogf) - (void)write(fileno(wc_tracelogf), WINCH_MESSAGE, strlen(WINCH_MESSAGE)); -# undef WINCH_MESSAGE +#define WINCH_MESSAGE "(SIGWINCH)" + if (wc_tracelogf) + (void) write(fileno(wc_tracelogf), WINCH_MESSAGE, + strlen(WINCH_MESSAGE)); +#undef WINCH_MESSAGE } -# endif - getwindowsz(); - /* For long running events such as multi-page menus and - * display_file(), we note the signal's occurance and - * hope the code there decides to handle the situation - * and reset the flag. There will be race conditions - * when handling this - code handlers so it doesn't matter. - */ -# ifdef notyet - winch_seen = TRUE; -# endif - if((oldLI != LI || oldCO != CO) && ttyDisplay) { - ttyDisplay->rows = LI; - ttyDisplay->cols = CO; - - cw = wins[BASE_WINDOW]; - cw->rows = ttyDisplay->rows; - cw->cols = ttyDisplay->cols; - - if(iflags.window_inited) { - cw = wins[WIN_MESSAGE]; - cw->curx = cw->cury = 0; - - tty_destroy_nhwindow(WIN_STATUS); - WIN_STATUS = tty_create_nhwindow(NHW_STATUS); - - if(u.ux) { -#ifdef CLIPPING - if(CO < COLNO || LI < ROWNO+3) { - setclipped(); - tty_cliparound(u.ux, u.uy); - } else { - clipping = FALSE; - clipx = clipy = 0; - } #endif - i = ttyDisplay->toplin; - ttyDisplay->toplin = 0; - docrt(); - bot(); - ttyDisplay->toplin = i; - flush_screen(1); - if(i) { - addtopl(toplines); - } else - for(i=WIN_INVEN; i < MAXWIN; i++) - if(wins[i] && wins[i]->active) { - /* cop-out */ - addtopl("Press Return to continue: "); - break; - } - (void) fflush(stdout); - if(i < 2) flush_screen(1); - } - } + getwindowsz(); +/* For long running events such as multi-page menus and + * display_file(), we note the signal's occurance and + * hope the code there decides to handle the situation + * and reset the flag. There will be race conditions + * when handling this - code handlers so it doesn't matter. + */ +#ifdef notyet + winch_seen = TRUE; +#endif + if ((oldLI != LI || oldCO != CO) && ttyDisplay) { + ttyDisplay->rows = LI; + ttyDisplay->cols = CO; + + cw = wins[BASE_WINDOW]; + cw->rows = ttyDisplay->rows; + cw->cols = ttyDisplay->cols; + + if (iflags.window_inited) { + cw = wins[WIN_MESSAGE]; + cw->curx = cw->cury = 0; + + tty_destroy_nhwindow(WIN_STATUS); + WIN_STATUS = tty_create_nhwindow(NHW_STATUS); + + if (u.ux) { +#ifdef CLIPPING + if (CO < COLNO || LI < ROWNO + 3) { + setclipped(); + tty_cliparound(u.ux, u.uy); + } else { + clipping = FALSE; + clipx = clipy = 0; + } +#endif + i = ttyDisplay->toplin; + ttyDisplay->toplin = 0; + docrt(); + bot(); + ttyDisplay->toplin = i; + flush_screen(1); + if (i) { + addtopl(toplines); + } else + for (i = WIN_INVEN; i < MAXWIN; i++) + if (wins[i] && wins[i]->active) { + /* cop-out */ + addtopl("Press Return to continue: "); + break; + } + (void) fflush(stdout); + if (i < 2) + flush_screen(1); + } + } } } #endif /*ARGSUSED*/ void -tty_init_nhwindows(argcp,argv) +tty_init_nhwindows(argcp, argv) int *argcp UNUSED; char **argv UNUSED; { - int wid, hgt, i; + int wid, hgt, i; - /* - * Remember tty modes, to be restored on exit. - * - * gettty() must be called before tty_startup() - * due to ordering of LI/CO settings - * tty_startup() must be called before initoptions() - * due to ordering of graphics settings - */ +/* + * Remember tty modes, to be restored on exit. + * + * gettty() must be called before tty_startup() + * due to ordering of LI/CO settings + * tty_startup() must be called before initoptions() + * due to ordering of graphics settings + */ #if defined(UNIX) || defined(VMS) - setbuf(stdout,obuf); + setbuf(stdout, obuf); #endif gettty(); /* to port dependant tty setup */ tty_startup(&wid, &hgt); - setftty(); /* calls start_screen */ + setftty(); /* calls start_screen */ /* set up tty descriptor */ - ttyDisplay = (struct DisplayDesc*) alloc(sizeof(struct DisplayDesc)); + ttyDisplay = (struct DisplayDesc *) alloc(sizeof(struct DisplayDesc)); ttyDisplay->toplin = 0; ttyDisplay->rows = hgt; ttyDisplay->cols = wid; @@ -368,372 +335,400 @@ tty_player_selection() menu_item *selected = 0; if (flags.randomall) { - if (ROLE == ROLE_NONE) ROLE = ROLE_RANDOM; - if (RACE == ROLE_NONE) RACE = ROLE_RANDOM; - if (GEND == ROLE_NONE) GEND = ROLE_RANDOM; - if (ALGN == ROLE_NONE) ALGN = ROLE_RANDOM; + if (ROLE == ROLE_NONE) + ROLE = ROLE_RANDOM; + if (RACE == ROLE_NONE) + RACE = ROLE_RANDOM; + if (GEND == ROLE_NONE) + GEND = ROLE_RANDOM; + if (ALGN == ROLE_NONE) + ALGN = ROLE_RANDOM; } /* prevent an unnecessary prompt */ rigid_role_checks(); /* Should we randomly pick for the player? */ - if (ROLE == ROLE_NONE || RACE == ROLE_NONE || - GEND == ROLE_NONE || ALGN == ROLE_NONE) { - int echoline; - char *prompt = build_plselection_prompt(pbuf, QBUFSZ, - ROLE, RACE, GEND, ALGN); + if (ROLE == ROLE_NONE || RACE == ROLE_NONE || GEND == ROLE_NONE + || ALGN == ROLE_NONE) { + int echoline; + char *prompt = + build_plselection_prompt(pbuf, QBUFSZ, ROLE, RACE, GEND, ALGN); - /* this prompt string ends in "[ynaq]?": - y - game picks role,&c then asks player to confirm; - n - player manually chooses via menu selections; - a - like 'y', but skips confirmation and starts game; - q - quit - */ - tty_putstr(BASE_WINDOW, 0, ""); - echoline = wins[BASE_WINDOW]->cury; - tty_putstr(BASE_WINDOW, 0, prompt); - do { - pick4u = lowc(readchar()); - if (index(quitchars, pick4u)) pick4u = 'y'; - } while (!index(ynaqchars, pick4u)); - if ((int)strlen(prompt) + 1 < CO) { - /* Echo choice and move back down line */ - tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline, pick4u); - tty_putstr(BASE_WINDOW, 0, ""); - } else - /* Otherwise it's hard to tell where to echo, and things are - * wrapping a bit messily anyway, so (try to) make sure the next - * question shows up well and doesn't get wrapped at the - * bottom of the window. - */ - tty_clear_nhwindow(BASE_WINDOW); + /* this prompt string ends in "[ynaq]?": + y - game picks role,&c then asks player to confirm; + n - player manually chooses via menu selections; + a - like 'y', but skips confirmation and starts game; + q - quit + */ + tty_putstr(BASE_WINDOW, 0, ""); + echoline = wins[BASE_WINDOW]->cury; + tty_putstr(BASE_WINDOW, 0, prompt); + do { + pick4u = lowc(readchar()); + if (index(quitchars, pick4u)) + pick4u = 'y'; + } while (!index(ynaqchars, pick4u)); + if ((int) strlen(prompt) + 1 < CO) { + /* Echo choice and move back down line */ + tty_putsym(BASE_WINDOW, (int) strlen(prompt) + 1, echoline, + pick4u); + tty_putstr(BASE_WINDOW, 0, ""); + } else + /* Otherwise it's hard to tell where to echo, and things are + * wrapping a bit messily anyway, so (try to) make sure the next + * question shows up well and doesn't get wrapped at the + * bottom of the window. + */ + tty_clear_nhwindow(BASE_WINDOW); - if (pick4u != 'y' && pick4u != 'a' && pick4u != 'n') goto give_up; + if (pick4u != 'y' && pick4u != 'a' && pick4u != 'n') + goto give_up; } - makepicks: +makepicks: nextpick = RS_ROLE; do { - if (nextpick == RS_ROLE) { - nextpick = RS_RACE; - /* Select a role, if necessary; - we'll try to be compatible with pre-selected - race/gender/alignment, but may not succeed. */ - if (ROLE < 0) { - /* Process the choice */ - if (pick4u == 'y' || pick4u == 'a' || ROLE == ROLE_RANDOM) { - /* Pick a random role */ - k = pick_role(RACE, GEND, ALGN, PICK_RANDOM); - if (k < 0) { - tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); - k = randrole(); - } - } else { - /* Prompt for a role */ - char rolenamebuf[QBUFSZ]; + if (nextpick == RS_ROLE) { + nextpick = RS_RACE; + /* Select a role, if necessary; + we'll try to be compatible with pre-selected + race/gender/alignment, but may not succeed. */ + if (ROLE < 0) { + /* Process the choice */ + if (pick4u == 'y' || pick4u == 'a' || ROLE == ROLE_RANDOM) { + /* Pick a random role */ + k = pick_role(RACE, GEND, ALGN, PICK_RANDOM); + if (k < 0) { + tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); + k = randrole(); + } + } else { + /* Prompt for a role */ + char rolenamebuf[QBUFSZ]; - tty_clear_nhwindow(BASE_WINDOW); - role_selection_prolog(RS_ROLE, BASE_WINDOW); - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; roles[i].name.m; i++) { - if (!ok_role(i, RACE, GEND, ALGN)) continue; - any.a_int = i + 1; /* must be non-zero */ - thisch = lowc(roles[i].name.m[0]); - if (thisch == lastch) thisch = highc(thisch); - Strcpy(rolenamebuf, roles[i].name.m); - if (roles[i].name.f) { - /* role has distinct name for female (C,P) */ - if (GEND == 1) { - /* female already chosen; replace male name */ - Strcpy(rolenamebuf, roles[i].name.f); - } else if (GEND < 0) { - /* not chosen yet; append slash+female name */ - Strcat(rolenamebuf, "/"); - Strcat(rolenamebuf, roles[i].name.f); - } - } - add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE, - an(rolenamebuf), MENU_UNSELECTED); - lastch = thisch; - } - role_menu_extra(ROLE_RANDOM, win); - any.a_int = 0; /* separator, not a choice */ - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - "", MENU_UNSELECTED); - role_menu_extra(RS_RACE, win); - role_menu_extra(RS_GENDER, win); - role_menu_extra(RS_ALGNMNT, win); - role_menu_extra(ROLE_NONE, win); /* quit */ - Strcpy(pbuf, "Pick a role or profession"); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - choice = (n == 1) ? selected[0].item.a_int : ROLE_NONE; - if (selected) free((genericptr_t) selected), selected = 0; - destroy_nhwindow(win); + tty_clear_nhwindow(BASE_WINDOW); + role_selection_prolog(RS_ROLE, BASE_WINDOW); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; roles[i].name.m; i++) { + if (!ok_role(i, RACE, GEND, ALGN)) + continue; + any.a_int = i + 1; /* must be non-zero */ + thisch = lowc(roles[i].name.m[0]); + if (thisch == lastch) + thisch = highc(thisch); + Strcpy(rolenamebuf, roles[i].name.m); + if (roles[i].name.f) { + /* role has distinct name for female (C,P) */ + if (GEND == 1) { + /* female already chosen; replace male name */ + Strcpy(rolenamebuf, roles[i].name.f); + } else if (GEND < 0) { + /* not chosen yet; append slash+female name */ + Strcat(rolenamebuf, "/"); + Strcat(rolenamebuf, roles[i].name.f); + } + } + add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE, + an(rolenamebuf), MENU_UNSELECTED); + lastch = thisch; + } + role_menu_extra(ROLE_RANDOM, win); + any.a_int = 0; /* separator, not a choice */ + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, "", + MENU_UNSELECTED); + role_menu_extra(RS_RACE, win); + role_menu_extra(RS_GENDER, win); + role_menu_extra(RS_ALGNMNT, win); + role_menu_extra(ROLE_NONE, win); /* quit */ + Strcpy(pbuf, "Pick a role or profession"); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + choice = (n == 1) ? selected[0].item.a_int : ROLE_NONE; + if (selected) + free((genericptr_t) selected), selected = 0; + destroy_nhwindow(win); - if (choice == ROLE_NONE) { - goto give_up; /* Selected quit */ - } else if (choice == RS_menu_arg(RS_ALGNMNT)) { - ALGN = k = ROLE_NONE; - nextpick = RS_ALGNMNT; - } else if (choice == RS_menu_arg(RS_GENDER)) { - GEND = k = ROLE_NONE; - nextpick = RS_GENDER; - } else if (choice == RS_menu_arg(RS_RACE)) { - RACE = k = ROLE_NONE; - nextpick = RS_RACE; - } else if (choice == ROLE_RANDOM) { - k = pick_role(RACE, GEND, ALGN, PICK_RANDOM); - if (k < 0) k = randrole(); - } else { - k = choice - 1; - } - } - ROLE = k; - } /* needed role */ - } /* picking role */ + if (choice == ROLE_NONE) { + goto give_up; /* Selected quit */ + } else if (choice == RS_menu_arg(RS_ALGNMNT)) { + ALGN = k = ROLE_NONE; + nextpick = RS_ALGNMNT; + } else if (choice == RS_menu_arg(RS_GENDER)) { + GEND = k = ROLE_NONE; + nextpick = RS_GENDER; + } else if (choice == RS_menu_arg(RS_RACE)) { + RACE = k = ROLE_NONE; + nextpick = RS_RACE; + } else if (choice == ROLE_RANDOM) { + k = pick_role(RACE, GEND, ALGN, PICK_RANDOM); + if (k < 0) + k = randrole(); + } else { + k = choice - 1; + } + } + ROLE = k; + } /* needed role */ + } /* picking role */ - if (nextpick == RS_RACE) { - nextpick = (ROLE < 0) ? RS_ROLE : RS_GENDER; - /* Select a race, if necessary; - force compatibility with role, try for compatibility - with pre-selected gender/alignment. */ - if (RACE < 0 || !validrace(ROLE, RACE)) { - /* no race yet, or pre-selected race not valid */ - if (pick4u == 'y' || pick4u == 'a' || RACE == ROLE_RANDOM) { - k = pick_race(ROLE, GEND, ALGN, PICK_RANDOM); - if (k < 0) { - tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); - k = randrace(ROLE); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid races */ - n = 0; /* number valid */ - k = 0; /* valid race */ - for (i = 0; races[i].noun; i++) - if (ok_race(ROLE, i, GEND, ALGN)) { - n++; - k = i; - } - if (n == 0) { - for (i = 0; races[i].noun; i++) - if (validrace(ROLE, i)) { - n++; - k = i; - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - tty_clear_nhwindow(BASE_WINDOW); - role_selection_prolog(RS_RACE, BASE_WINDOW); - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; races[i].noun; i++) { - if (!ok_race(ROLE, i, GEND, ALGN)) continue; - any.a_int = i + 1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any, races[i].noun[0], - 0, ATR_NONE, races[i].noun, MENU_UNSELECTED); - } - role_menu_extra(ROLE_RANDOM, win); - any.a_int = 0; /* separator, not a choice */ - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - "", MENU_UNSELECTED); - role_menu_extra(RS_ROLE, win); - role_menu_extra(RS_GENDER, win); - role_menu_extra(RS_ALGNMNT, win); - role_menu_extra(ROLE_NONE, win); /* quit */ - Strcpy(pbuf, "Pick a race or species"); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - choice = (n == 1) ? selected[0].item.a_int : ROLE_NONE; - if (selected) free((genericptr_t) selected), selected = 0; - destroy_nhwindow(win); + if (nextpick == RS_RACE) { + nextpick = (ROLE < 0) ? RS_ROLE : RS_GENDER; + /* Select a race, if necessary; + force compatibility with role, try for compatibility + with pre-selected gender/alignment. */ + if (RACE < 0 || !validrace(ROLE, RACE)) { + /* no race yet, or pre-selected race not valid */ + if (pick4u == 'y' || pick4u == 'a' || RACE == ROLE_RANDOM) { + k = pick_race(ROLE, GEND, ALGN, PICK_RANDOM); + if (k < 0) { + tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); + k = randrace(ROLE); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid races */ + n = 0; /* number valid */ + k = 0; /* valid race */ + for (i = 0; races[i].noun; i++) + if (ok_race(ROLE, i, GEND, ALGN)) { + n++; + k = i; + } + if (n == 0) { + for (i = 0; races[i].noun; i++) + if (validrace(ROLE, i)) { + n++; + k = i; + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + tty_clear_nhwindow(BASE_WINDOW); + role_selection_prolog(RS_RACE, BASE_WINDOW); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; races[i].noun; i++) { + if (!ok_race(ROLE, i, GEND, ALGN)) + continue; + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0, + ATR_NONE, races[i].noun, + MENU_UNSELECTED); + } + role_menu_extra(ROLE_RANDOM, win); + any.a_int = 0; /* separator, not a choice */ + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, "", + MENU_UNSELECTED); + role_menu_extra(RS_ROLE, win); + role_menu_extra(RS_GENDER, win); + role_menu_extra(RS_ALGNMNT, win); + role_menu_extra(ROLE_NONE, win); /* quit */ + Strcpy(pbuf, "Pick a race or species"); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + choice = + (n == 1) ? selected[0].item.a_int : ROLE_NONE; + if (selected) + free((genericptr_t) selected), selected = 0; + destroy_nhwindow(win); - if (choice == ROLE_NONE) { - goto give_up; /* Selected quit */ - } else if (choice == RS_menu_arg(RS_ALGNMNT)) { - ALGN = k = ROLE_NONE; - nextpick = RS_ALGNMNT; - } else if (choice == RS_menu_arg(RS_GENDER)) { - GEND = k = ROLE_NONE; - nextpick = RS_GENDER; - } else if (choice == RS_menu_arg(RS_ROLE)) { - ROLE = k = ROLE_NONE; - nextpick = RS_ROLE; - } else if (choice == ROLE_RANDOM) { - k = pick_race(ROLE, GEND, ALGN, PICK_RANDOM); - if (k < 0) k = randrace(ROLE); - } else { - k = choice - 1; - } - } - } - RACE = k; - } /* needed race */ - } /* picking race */ + if (choice == ROLE_NONE) { + goto give_up; /* Selected quit */ + } else if (choice == RS_menu_arg(RS_ALGNMNT)) { + ALGN = k = ROLE_NONE; + nextpick = RS_ALGNMNT; + } else if (choice == RS_menu_arg(RS_GENDER)) { + GEND = k = ROLE_NONE; + nextpick = RS_GENDER; + } else if (choice == RS_menu_arg(RS_ROLE)) { + ROLE = k = ROLE_NONE; + nextpick = RS_ROLE; + } else if (choice == ROLE_RANDOM) { + k = pick_race(ROLE, GEND, ALGN, PICK_RANDOM); + if (k < 0) + k = randrace(ROLE); + } else { + k = choice - 1; + } + } + } + RACE = k; + } /* needed race */ + } /* picking race */ - if (nextpick == RS_GENDER) { - nextpick = (ROLE < 0) ? RS_ROLE : (RACE < 0) ? RS_RACE : RS_ALGNMNT; - /* Select a gender, if necessary; - force compatibility with role/race, try for compatibility - with pre-selected alignment. */ - if (GEND < 0 || !validgend(ROLE, RACE, GEND)) { - /* no gender yet, or pre-selected gender not valid */ - if (pick4u == 'y' || pick4u == 'a' || GEND == ROLE_RANDOM) { - k = pick_gend(ROLE, RACE, ALGN, PICK_RANDOM); - if (k < 0) { - tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); - k = randgend(ROLE, RACE); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid genders */ - n = 0; /* number valid */ - k = 0; /* valid gender */ - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(ROLE, RACE, i, ALGN)) { - n++; - k = i; - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) - if (validgend(ROLE, RACE, i)) { - n++; - k = i; - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - tty_clear_nhwindow(BASE_WINDOW); - role_selection_prolog(RS_GENDER, BASE_WINDOW); - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (!ok_gend(ROLE, RACE, i, ALGN)) continue; - any.a_int = i + 1; /* non-zero */ - add_menu(win, NO_GLYPH, &any, genders[i].adj[0], - 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED); - } - role_menu_extra(ROLE_RANDOM, win); - any.a_int = 0; /* separator, not a choice */ - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - "", MENU_UNSELECTED); - role_menu_extra(RS_ROLE, win); - role_menu_extra(RS_RACE, win); - role_menu_extra(RS_ALGNMNT, win); - role_menu_extra(ROLE_NONE, win); /* quit */ - Strcpy(pbuf, "Pick a gender or sex"); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - choice = (n == 1) ? selected[0].item.a_int : ROLE_NONE; - if (selected) free((genericptr_t) selected), selected = 0; - destroy_nhwindow(win); + if (nextpick == RS_GENDER) { + nextpick = + (ROLE < 0) ? RS_ROLE : (RACE < 0) ? RS_RACE : RS_ALGNMNT; + /* Select a gender, if necessary; + force compatibility with role/race, try for compatibility + with pre-selected alignment. */ + if (GEND < 0 || !validgend(ROLE, RACE, GEND)) { + /* no gender yet, or pre-selected gender not valid */ + if (pick4u == 'y' || pick4u == 'a' || GEND == ROLE_RANDOM) { + k = pick_gend(ROLE, RACE, ALGN, PICK_RANDOM); + if (k < 0) { + tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); + k = randgend(ROLE, RACE); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid genders */ + n = 0; /* number valid */ + k = 0; /* valid gender */ + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(ROLE, RACE, i, ALGN)) { + n++; + k = i; + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) + if (validgend(ROLE, RACE, i)) { + n++; + k = i; + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + tty_clear_nhwindow(BASE_WINDOW); + role_selection_prolog(RS_GENDER, BASE_WINDOW); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (!ok_gend(ROLE, RACE, i, ALGN)) + continue; + any.a_int = i + 1; /* non-zero */ + add_menu(win, NO_GLYPH, &any, genders[i].adj[0], + 0, ATR_NONE, genders[i].adj, + MENU_UNSELECTED); + } + role_menu_extra(ROLE_RANDOM, win); + any.a_int = 0; /* separator, not a choice */ + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, "", + MENU_UNSELECTED); + role_menu_extra(RS_ROLE, win); + role_menu_extra(RS_RACE, win); + role_menu_extra(RS_ALGNMNT, win); + role_menu_extra(ROLE_NONE, win); /* quit */ + Strcpy(pbuf, "Pick a gender or sex"); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + choice = + (n == 1) ? selected[0].item.a_int : ROLE_NONE; + if (selected) + free((genericptr_t) selected), selected = 0; + destroy_nhwindow(win); - if (choice == ROLE_NONE) { - goto give_up; /* Selected quit */ - } else if (choice == RS_menu_arg(RS_ALGNMNT)) { - ALGN = k = ROLE_NONE; - nextpick = RS_ALGNMNT; - } else if (choice == RS_menu_arg(RS_RACE)) { - RACE = k = ROLE_NONE; - nextpick = RS_RACE; - } else if (choice == RS_menu_arg(RS_ROLE)) { - ROLE = k = ROLE_NONE; - nextpick = RS_ROLE; - } else if (choice == ROLE_RANDOM) { - k = pick_gend(ROLE, RACE, ALGN, PICK_RANDOM); - if (k < 0) k = randgend(ROLE, RACE); - } else { - k = choice - 1; - } - } - } - GEND = k; - } /* needed gender */ - } /* picking gender */ + if (choice == ROLE_NONE) { + goto give_up; /* Selected quit */ + } else if (choice == RS_menu_arg(RS_ALGNMNT)) { + ALGN = k = ROLE_NONE; + nextpick = RS_ALGNMNT; + } else if (choice == RS_menu_arg(RS_RACE)) { + RACE = k = ROLE_NONE; + nextpick = RS_RACE; + } else if (choice == RS_menu_arg(RS_ROLE)) { + ROLE = k = ROLE_NONE; + nextpick = RS_ROLE; + } else if (choice == ROLE_RANDOM) { + k = pick_gend(ROLE, RACE, ALGN, PICK_RANDOM); + if (k < 0) + k = randgend(ROLE, RACE); + } else { + k = choice - 1; + } + } + } + GEND = k; + } /* needed gender */ + } /* picking gender */ - if (nextpick == RS_ALGNMNT) { - nextpick = (ROLE < 0) ? RS_ROLE : (RACE < 0) ? RS_RACE : RS_GENDER; - /* Select an alignment, if necessary; - force compatibility with role/race/gender. */ - if (ALGN < 0 || !validalign(ROLE, RACE, ALGN)) { - /* no alignment yet, or pre-selected alignment not valid */ - if (pick4u == 'y' || pick4u == 'a' || ALGN == ROLE_RANDOM) { - k = pick_align(ROLE, RACE, GEND, PICK_RANDOM); - if (k < 0) { - tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); - k = randalign(ROLE, RACE); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid alignments */ - n = 0; /* number valid */ - k = 0; /* valid alignment */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(ROLE, RACE, GEND, i)) { - n++; - k = i; - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) - if (validalign(ROLE, RACE, i)) { - n++; - k = i; - } - } - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - tty_clear_nhwindow(BASE_WINDOW); - role_selection_prolog(RS_ALGNMNT, BASE_WINDOW); - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (!ok_align(ROLE, RACE, GEND, i)) continue; - any.a_int = i + 1; /* non-zero */ - add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], - 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED); - } - role_menu_extra(ROLE_RANDOM, win); - any.a_int = 0; /* separator, not a choice */ - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - "", MENU_UNSELECTED); - role_menu_extra(RS_ROLE, win); - role_menu_extra(RS_RACE, win); - role_menu_extra(RS_GENDER, win); - role_menu_extra(ROLE_NONE, win); /* quit */ - Strcpy(pbuf, "Pick an alignment or creed"); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - choice = (n == 1) ? selected[0].item.a_int : ROLE_NONE; - if (selected) free((genericptr_t) selected), selected = 0; - destroy_nhwindow(win); + if (nextpick == RS_ALGNMNT) { + nextpick = + (ROLE < 0) ? RS_ROLE : (RACE < 0) ? RS_RACE : RS_GENDER; + /* Select an alignment, if necessary; + force compatibility with role/race/gender. */ + if (ALGN < 0 || !validalign(ROLE, RACE, ALGN)) { + /* no alignment yet, or pre-selected alignment not valid */ + if (pick4u == 'y' || pick4u == 'a' || ALGN == ROLE_RANDOM) { + k = pick_align(ROLE, RACE, GEND, PICK_RANDOM); + if (k < 0) { + tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); + k = randalign(ROLE, RACE); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid alignments */ + n = 0; /* number valid */ + k = 0; /* valid alignment */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(ROLE, RACE, GEND, i)) { + n++; + k = i; + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) + if (validalign(ROLE, RACE, i)) { + n++; + k = i; + } + } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + tty_clear_nhwindow(BASE_WINDOW); + role_selection_prolog(RS_ALGNMNT, BASE_WINDOW); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (!ok_align(ROLE, RACE, GEND, i)) + continue; + any.a_int = i + 1; /* non-zero */ + add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0, + ATR_NONE, aligns[i].adj, + MENU_UNSELECTED); + } + role_menu_extra(ROLE_RANDOM, win); + any.a_int = 0; /* separator, not a choice */ + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, "", + MENU_UNSELECTED); + role_menu_extra(RS_ROLE, win); + role_menu_extra(RS_RACE, win); + role_menu_extra(RS_GENDER, win); + role_menu_extra(ROLE_NONE, win); /* quit */ + Strcpy(pbuf, "Pick an alignment or creed"); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + choice = + (n == 1) ? selected[0].item.a_int : ROLE_NONE; + if (selected) + free((genericptr_t) selected), selected = 0; + destroy_nhwindow(win); - if (choice == ROLE_NONE) { - goto give_up; /* Selected quit */ - } else if (choice == RS_menu_arg(RS_GENDER)) { - GEND = k = ROLE_NONE; - nextpick = RS_GENDER; - } else if (choice == RS_menu_arg(RS_RACE)) { - RACE = k = ROLE_NONE; - nextpick = RS_RACE; - } else if (choice == RS_menu_arg(RS_ROLE)) { - ROLE = k = ROLE_NONE; - nextpick = RS_ROLE; - } else if (choice == ROLE_RANDOM) { - k = pick_align(ROLE, RACE, GEND, PICK_RANDOM); - if (k < 0) k = randalign(ROLE, RACE); - } else { - k = choice - 1; - } - } - } - ALGN = k; - } /* needed alignment */ - } /* picking alignment */ + if (choice == ROLE_NONE) { + goto give_up; /* Selected quit */ + } else if (choice == RS_menu_arg(RS_GENDER)) { + GEND = k = ROLE_NONE; + nextpick = RS_GENDER; + } else if (choice == RS_menu_arg(RS_RACE)) { + RACE = k = ROLE_NONE; + nextpick = RS_RACE; + } else if (choice == RS_menu_arg(RS_ROLE)) { + ROLE = k = ROLE_NONE; + nextpick = RS_ROLE; + } else if (choice == ROLE_RANDOM) { + k = pick_align(ROLE, RACE, GEND, PICK_RANDOM); + if (k < 0) + k = randalign(ROLE, RACE); + } else { + k = choice - 1; + } + } + } + ALGN = k; + } /* needed alignment */ + } /* picking alignment */ } while (ROLE < 0 || RACE < 0 || GEND < 0 || ALGN < 0); @@ -756,94 +751,98 @@ tty_player_selection() */ getconfirmation = (pick4u != 'a' && !flags.randomall); while (getconfirmation) { - tty_clear_nhwindow(BASE_WINDOW); - role_selection_prolog(ROLE_NONE, BASE_WINDOW); - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - any.a_int = 0; - if (!roles[ROLE].name.f && - (roles[ROLE].allow & ROLE_GENDMASK) == (ROLE_MALE|ROLE_FEMALE)) - Sprintf(plbuf, " %s", genders[GEND].adj); - else - *plbuf = '\0'; /* omit redundant gender */ - Sprintf(pbuf, "%s, %s%s %s %s", - plname, aligns[ALGN].adj, plbuf, races[RACE].adj, - (GEND == 1 && roles[ROLE].name.f) ? - roles[ROLE].name.f : roles[ROLE].name.m); - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - pbuf, MENU_UNSELECTED); - /* blank separator */ - any.a_int = 0; - add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, - "", MENU_UNSELECTED); - /* [ynaq] menu choices */ - any.a_int = 1; - add_menu(win, NO_GLYPH, &any, 'y', 0, ATR_NONE, - "Yes; start game", MENU_SELECTED); - any.a_int = 2; - add_menu(win, NO_GLYPH, &any, 'n', 0, ATR_NONE, - "No; choose role again", MENU_UNSELECTED); - if (iflags.renameallowed) { - any.a_int = 3; - add_menu(win, NO_GLYPH, &any, 'a', 0, ATR_NONE, - "Not yet; choose another name", MENU_UNSELECTED); - } - any.a_int = -1; - add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Is this ok? [yn%sq]", iflags.renameallowed ? "a" : ""); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - /* [pick-one menus with a preselected entry behave oddly...] */ - choice = (n > 0) ? selected[n - 1].item.a_int : (n == 0) ? 1 : -1; - if (selected) free((genericptr_t) selected), selected = 0; + tty_clear_nhwindow(BASE_WINDOW); + role_selection_prolog(ROLE_NONE, BASE_WINDOW); + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + any.a_int = 0; + if (!roles[ROLE].name.f + && (roles[ROLE].allow & ROLE_GENDMASK) + == (ROLE_MALE | ROLE_FEMALE)) + Sprintf(plbuf, " %s", genders[GEND].adj); + else + *plbuf = '\0'; /* omit redundant gender */ + Sprintf(pbuf, "%s, %s%s %s %s", plname, aligns[ALGN].adj, plbuf, + races[RACE].adj, + (GEND == 1 && roles[ROLE].name.f) ? roles[ROLE].name.f + : roles[ROLE].name.m); + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, pbuf, + MENU_UNSELECTED); + /* blank separator */ + any.a_int = 0; + add_menu(win, NO_GLYPH, &any, ' ', 0, ATR_NONE, "", MENU_UNSELECTED); + /* [ynaq] menu choices */ + any.a_int = 1; + add_menu(win, NO_GLYPH, &any, 'y', 0, ATR_NONE, "Yes; start game", + MENU_SELECTED); + any.a_int = 2; + add_menu(win, NO_GLYPH, &any, 'n', 0, ATR_NONE, + "No; choose role again", MENU_UNSELECTED); + if (iflags.renameallowed) { + any.a_int = 3; + add_menu(win, NO_GLYPH, &any, 'a', 0, ATR_NONE, + "Not yet; choose another name", MENU_UNSELECTED); + } + any.a_int = -1; + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Is this ok? [yn%sq]", iflags.renameallowed ? "a" : ""); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + /* [pick-one menus with a preselected entry behave oddly...] */ + choice = (n > 0) ? selected[n - 1].item.a_int : (n == 0) ? 1 : -1; + if (selected) + free((genericptr_t) selected), selected = 0; - switch (choice) { - default: /* 'q' or ESC */ - goto give_up; /* quit */ - break; - case 3: /* 'a' */ - /* - * TODO: what, if anything, should be done if the name is - * changed to or from "wizard" after port-specific startup - * code has set flags.debug based on the original name? - */ - { - int saveROLE, saveRACE, saveGEND, saveALGN; + switch (choice) { + default: /* 'q' or ESC */ + goto give_up; /* quit */ + break; + case 3: /* 'a' */ + /* + * TODO: what, if anything, should be done if the name is + * changed to or from "wizard" after port-specific startup + * code has set flags.debug based on the original name? + */ + { + int saveROLE, saveRACE, saveGEND, saveALGN; - iflags.renameinprogress = TRUE; - /* plnamesuffix() can change any or all of ROLE, RACE, - GEND, ALGN; we'll override that and honor only the name */ - saveROLE = ROLE, saveRACE = RACE, saveGEND = GEND, saveALGN = ALGN; - *plname = '\0'; - plnamesuffix(); /* calls askname() when plname[] is empty */ - ROLE = saveROLE, RACE = saveRACE, GEND = saveGEND, ALGN = saveALGN; - } - break; /* getconfirmation is still True */ - case 2: /* 'n' */ - /* start fresh, but bypass "shall I pick everything for you?" - step; any partial role selection via config file, command - line, or name suffix is discarded this time */ - pick4u = 'n'; - ROLE = RACE = GEND = ALGN = ROLE_NONE; - goto makepicks; - break; - case 1: /* 'y' or Space or Return/Enter */ - /* success; drop out through end of function */ - getconfirmation = FALSE; - break; - } + iflags.renameinprogress = TRUE; + /* plnamesuffix() can change any or all of ROLE, RACE, + GEND, ALGN; we'll override that and honor only the name */ + saveROLE = ROLE, saveRACE = RACE, saveGEND = GEND, + saveALGN = ALGN; + *plname = '\0'; + plnamesuffix(); /* calls askname() when plname[] is empty */ + ROLE = saveROLE, RACE = saveRACE, GEND = saveGEND, + ALGN = saveALGN; + } + break; /* getconfirmation is still True */ + case 2: /* 'n' */ + /* start fresh, but bypass "shall I pick everything for you?" + step; any partial role selection via config file, command + line, or name suffix is discarded this time */ + pick4u = 'n'; + ROLE = RACE = GEND = ALGN = ROLE_NONE; + goto makepicks; + break; + case 1: /* 'y' or Space or Return/Enter */ + /* success; drop out through end of function */ + getconfirmation = FALSE; + break; + } } /* Success! */ tty_display_nhwindow(BASE_WINDOW, FALSE); return; - give_up: +give_up: /* Quit */ - if (selected) free((genericptr_t) selected); /* [obsolete] */ - bail((char *)0); + if (selected) + free((genericptr_t) selected); /* [obsolete] */ + bail((char *) 0); /*NOTREACHED*/ return; } @@ -867,82 +866,93 @@ tty_askname() #ifdef SELECTSAVED if (iflags.wc2_selectsaved && !iflags.renameinprogress) - switch (restore_menu(BASE_WINDOW)) { - case -1: bail("Until next time then..."); /* quit */ - /*NOTREACHED*/ - case 0: break; /* no game chosen; start new game */ - case 1: return; /* plname[] has been set */ - } + switch (restore_menu(BASE_WINDOW)) { + case -1: + bail("Until next time then..."); /* quit */ + /*NOTREACHED*/ + case 0: + break; /* no game chosen; start new game */ + case 1: + return; /* plname[] has been set */ + } #endif /* SELECTSAVED */ tty_putstr(BASE_WINDOW, 0, ""); do { - if (++tryct > 1) { - if (tryct > 10) bail("Giving up after 10 tries.\n"); - tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1); - tty_putstr(BASE_WINDOW, 0, "Enter a name for your character..."); - /* erase previous prompt (in case of ESC after partial response) */ - tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury), cl_end(); - } - tty_putstr(BASE_WINDOW, 0, who_are_you); - tty_curs(BASE_WINDOW, (int)(sizeof who_are_you), - wins[BASE_WINDOW]->cury - 1); - ct = 0; - while((c = tty_nhgetch()) != '\n') { - if(c == EOF) c = '\033'; - if (c == '\033') { ct = 0; break; } /* continue outer loop */ + if (++tryct > 1) { + if (tryct > 10) + bail("Giving up after 10 tries.\n"); + tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1); + tty_putstr(BASE_WINDOW, 0, "Enter a name for your character..."); + /* erase previous prompt (in case of ESC after partial response) + */ + tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury), cl_end(); + } + tty_putstr(BASE_WINDOW, 0, who_are_you); + tty_curs(BASE_WINDOW, (int) (sizeof who_are_you), + wins[BASE_WINDOW]->cury - 1); + ct = 0; + while ((c = tty_nhgetch()) != '\n') { + if (c == EOF) + c = '\033'; + if (c == '\033') { + ct = 0; + break; + } /* continue outer loop */ #if defined(WIN32CON) - if (c == '\003') bail("^C abort.\n"); + if (c == '\003') + bail("^C abort.\n"); #endif - /* some people get confused when their erase char is not ^H */ - if (c == '\b' || c == '\177') { - if(ct) { - ct--; + /* some people get confused when their erase char is not ^H */ + if (c == '\b' || c == '\177') { + if (ct) { + ct--; #ifdef WIN32CON - ttyDisplay->curx--; + ttyDisplay->curx--; #endif #if defined(MICRO) || defined(WIN32CON) -# if defined(WIN32CON) || defined(MSDOS) - backsp(); /* \b is visible on NT */ - (void) putchar(' '); - backsp(); -# else - msmsg("\b \b"); -# endif +#if defined(WIN32CON) || defined(MSDOS) + backsp(); /* \b is visible on NT */ + (void) putchar(' '); + backsp(); #else - (void) putchar('\b'); - (void) putchar(' '); - (void) putchar('\b'); + msmsg("\b \b"); #endif - } - continue; - } +#else + (void) putchar('\b'); + (void) putchar(' '); + (void) putchar('\b'); +#endif + } + continue; + } #if defined(UNIX) || defined(VMS) - if(c != '-' && c != '@') - if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && - /* reject leading digit but allow digits elsewhere - (avoids ambiguity when character name gets - appended to uid to construct save file name) */ - !(c >= '0' && c <= '9' && ct > 0)) c = '_'; + if (c != '-' && c != '@') + if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && + /* reject leading digit but allow digits elsewhere + (avoids ambiguity when character name gets + appended to uid to construct save file name) */ + !(c >= '0' && c <= '9' && ct > 0)) + c = '_'; #endif - if (ct < (int)(sizeof plname) - 1) { + if (ct < (int) (sizeof plname) - 1) { #if defined(MICRO) -# if defined(MSDOS) - if (iflags.grmode) { - (void) putchar(c); - } else -# endif - msmsg("%c", c); +#if defined(MSDOS) + if (iflags.grmode) { + (void) putchar(c); + } else +#endif + msmsg("%c", c); #else - (void) putchar(c); + (void) putchar(c); #endif - plname[ct++] = c; + plname[ct++] = c; #ifdef WIN32CON - ttyDisplay->curx++; + ttyDisplay->curx++; #endif - } - } - plname[ct] = 0; + } + } + plname[ct] = 0; } while (ct == 0); /* move to next line to simulate echo of user's */ @@ -963,37 +973,38 @@ tty_get_nh_event() STATIC_OVL void getret() { - xputs("\n"); - if(flags.standout) - standoutbeg(); - xputs("Hit "); - xputs(iflags.cbreak ? "space" : "return"); - xputs(" to continue: "); - if(flags.standout) - standoutend(); - xwaitforspace(" "); + xputs("\n"); + if (flags.standout) + standoutbeg(); + xputs("Hit "); + xputs(iflags.cbreak ? "space" : "return"); + xputs(" to continue: "); + if (flags.standout) + standoutend(); + xwaitforspace(" "); } #endif void tty_suspend_nhwindows(str) - const char *str; +const char *str; { - settty(str); /* calls end_screen, perhaps raw_print */ - if (!str) tty_raw_print(""); /* calls fflush(stdout) */ + settty(str); /* calls end_screen, perhaps raw_print */ + if (!str) + tty_raw_print(""); /* calls fflush(stdout) */ } void tty_resume_nhwindows() { gettty(); - setftty(); /* calls start_screen */ + setftty(); /* calls start_screen */ docrt(); } void tty_exit_nhwindows(str) - const char *str; +const char *str; { winid i; @@ -1001,32 +1012,32 @@ tty_exit_nhwindows(str) /* Just forget any windows existed, since we're about to exit anyway. * Disable windows to avoid calls to window routines. */ - for(i=0; itype = type; newwin->flags = 0; newwin->active = FALSE; @@ -1035,90 +1046,93 @@ tty_create_nhwindow(type) newwin->mlist = (tty_menu_item *) 0; newwin->plist = (tty_menu_item **) 0; newwin->npages = newwin->plist_size = newwin->nitems = newwin->how = 0; - switch(type) { + switch (type) { case NHW_BASE: - /* base window, used for absolute movement on the screen */ - newwin->offx = newwin->offy = 0; - newwin->rows = ttyDisplay->rows; - newwin->cols = ttyDisplay->cols; - newwin->maxrow = newwin->maxcol = 0; - break; + /* base window, used for absolute movement on the screen */ + newwin->offx = newwin->offy = 0; + newwin->rows = ttyDisplay->rows; + newwin->cols = ttyDisplay->cols; + newwin->maxrow = newwin->maxcol = 0; + break; case NHW_MESSAGE: - /* message window, 1 line long, very wide, top of screen */ - newwin->offx = newwin->offy = 0; - /* sanity check */ - if(iflags.msg_history < 20) iflags.msg_history = 20; - else if(iflags.msg_history > 60) iflags.msg_history = 60; - newwin->maxrow = newwin->rows = iflags.msg_history; - newwin->maxcol = newwin->cols = 0; - break; + /* message window, 1 line long, very wide, top of screen */ + newwin->offx = newwin->offy = 0; + /* sanity check */ + if (iflags.msg_history < 20) + iflags.msg_history = 20; + else if (iflags.msg_history > 60) + iflags.msg_history = 60; + newwin->maxrow = newwin->rows = iflags.msg_history; + newwin->maxcol = newwin->cols = 0; + break; case NHW_STATUS: - /* status window, 2 lines long, full width, bottom of screen */ - newwin->offx = 0; + /* status window, 2 lines long, full width, bottom of screen */ + newwin->offx = 0; #if defined(USE_TILES) && defined(MSDOS) - if (iflags.grmode) { - newwin->offy = ttyDisplay->rows-2; - } else + if (iflags.grmode) { + newwin->offy = ttyDisplay->rows - 2; + } else #endif - newwin->offy = min((int)ttyDisplay->rows-2, ROWNO+1); - newwin->rows = newwin->maxrow = 2; - newwin->cols = newwin->maxcol = ttyDisplay->cols; - break; + newwin->offy = min((int) ttyDisplay->rows - 2, ROWNO + 1); + newwin->rows = newwin->maxrow = 2; + newwin->cols = newwin->maxcol = ttyDisplay->cols; + break; case NHW_MAP: - /* map window, ROWNO lines long, full width, below message window */ - newwin->offx = 0; - newwin->offy = 1; - newwin->rows = ROWNO; - newwin->cols = COLNO; - newwin->maxrow = 0; /* no buffering done -- let gbuf do it */ - newwin->maxcol = 0; - break; + /* map window, ROWNO lines long, full width, below message window */ + newwin->offx = 0; + newwin->offy = 1; + newwin->rows = ROWNO; + newwin->cols = COLNO; + newwin->maxrow = 0; /* no buffering done -- let gbuf do it */ + newwin->maxcol = 0; + break; case NHW_MENU: case NHW_TEXT: - /* inventory/menu window, variable length, full width, top of screen */ - /* help window, the same, different semantics for display, etc */ - newwin->offx = newwin->offy = 0; - newwin->rows = 0; - newwin->cols = ttyDisplay->cols; - newwin->maxrow = newwin->maxcol = 0; - break; - default: - panic("Tried to create window type %d\n", (int) type); - return WIN_ERR; + /* inventory/menu window, variable length, full width, top of screen + */ + /* help window, the same, different semantics for display, etc */ + newwin->offx = newwin->offy = 0; + newwin->rows = 0; + newwin->cols = ttyDisplay->cols; + newwin->maxrow = newwin->maxcol = 0; + break; + default: + panic("Tried to create window type %d\n", (int) type); + return WIN_ERR; } - for(newid = 0; newidmaxrow) { - newwin->data = - (char **) alloc(sizeof(char *) * (unsigned)newwin->maxrow); - newwin->datlen = - (short *) alloc(sizeof(short) * (unsigned)newwin->maxrow); - if(newwin->maxcol) { - for (i = 0; i < newwin->maxrow; i++) { - newwin->data[i] = (char *) alloc((unsigned)newwin->maxcol); - newwin->datlen[i] = newwin->maxcol; - } - } else { - for (i = 0; i < newwin->maxrow; i++) { - newwin->data[i] = (char *) 0; - newwin->datlen[i] = 0; - } - } - if(newwin->type == NHW_MESSAGE) - newwin->maxrow = 0; + if (newwin->maxrow) { + newwin->data = + (char **) alloc(sizeof(char *) * (unsigned) newwin->maxrow); + newwin->datlen = + (short *) alloc(sizeof(short) * (unsigned) newwin->maxrow); + if (newwin->maxcol) { + for (i = 0; i < newwin->maxrow; i++) { + newwin->data[i] = (char *) alloc((unsigned) newwin->maxcol); + newwin->datlen[i] = newwin->maxcol; + } + } else { + for (i = 0; i < newwin->maxrow; i++) { + newwin->data[i] = (char *) 0; + newwin->datlen[i] = 0; + } + } + if (newwin->type == NHW_MESSAGE) + newwin->maxrow = 0; } else { - newwin->data = (char **)0; - newwin->datlen = (short *)0; + newwin->data = (char **) 0; + newwin->datlen = (short *) 0; } return newid; @@ -1126,110 +1140,112 @@ tty_create_nhwindow(type) STATIC_OVL void erase_menu_or_text(window, cw, clear) - winid window; - struct WinDesc *cw; - boolean clear; +winid window; +struct WinDesc *cw; +boolean clear; { - if(cw->offx == 0) - if(cw->offy) { - tty_curs(window, 1, 0); - cl_eos(); - } else if (clear) - clear_screen(); - else - docrt(); + if (cw->offx == 0) + if (cw->offy) { + tty_curs(window, 1, 0); + cl_eos(); + } else if (clear) + clear_screen(); + else + docrt(); else - docorner((int)cw->offx, cw->maxrow+1); + docorner((int) cw->offx, cw->maxrow + 1); } STATIC_OVL void free_window_info(cw, free_data) - struct WinDesc *cw; - boolean free_data; +struct WinDesc *cw; +boolean free_data; { int i; if (cw->data) { - if (cw == wins[WIN_MESSAGE] && cw->rows > cw->maxrow) - cw->maxrow = cw->rows; /* topl data */ - for(i=0; imaxrow; i++) - if(cw->data[i]) { - free((genericptr_t)cw->data[i]); - cw->data[i] = (char *)0; - if (cw->datlen) cw->datlen[i] = 0; - } - if (free_data) { - free((genericptr_t)cw->data); - cw->data = (char **)0; - if (cw->datlen) free((genericptr_t)cw->datlen); - cw->datlen = (short *)0; - cw->rows = 0; - } + if (cw == wins[WIN_MESSAGE] && cw->rows > cw->maxrow) + cw->maxrow = cw->rows; /* topl data */ + for (i = 0; i < cw->maxrow; i++) + if (cw->data[i]) { + free((genericptr_t) cw->data[i]); + cw->data[i] = (char *) 0; + if (cw->datlen) + cw->datlen[i] = 0; + } + if (free_data) { + free((genericptr_t) cw->data); + cw->data = (char **) 0; + if (cw->datlen) + free((genericptr_t) cw->datlen); + cw->datlen = (short *) 0; + cw->rows = 0; + } } cw->maxrow = cw->maxcol = 0; - if(cw->mlist) { - tty_menu_item *temp; - while ((temp = cw->mlist) != 0) { - cw->mlist = cw->mlist->next; - if (temp->str) free((genericptr_t)temp->str); - free((genericptr_t)temp); - } + if (cw->mlist) { + tty_menu_item *temp; + while ((temp = cw->mlist) != 0) { + cw->mlist = cw->mlist->next; + if (temp->str) + free((genericptr_t) temp->str); + free((genericptr_t) temp); + } } if (cw->plist) { - free((genericptr_t)cw->plist); - cw->plist = 0; + free((genericptr_t) cw->plist); + cw->plist = 0; } cw->plist_size = cw->npages = cw->nitems = cw->how = 0; - if(cw->morestr) { - free((genericptr_t)cw->morestr); - cw->morestr = 0; + if (cw->morestr) { + free((genericptr_t) cw->morestr); + cw->morestr = 0; } } void tty_clear_nhwindow(window) - winid window; +winid window; { register struct WinDesc *cw = 0; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); ttyDisplay->lastwin = window; - switch(cw->type) { + switch (cw->type) { case NHW_MESSAGE: - if(ttyDisplay->toplin) { - home(); - cl_end(); - if(cw->cury) - docorner(1, cw->cury+1); - ttyDisplay->toplin = 0; - } - break; + if (ttyDisplay->toplin) { + home(); + cl_end(); + if (cw->cury) + docorner(1, cw->cury + 1); + ttyDisplay->toplin = 0; + } + break; case NHW_STATUS: - tty_curs(window, 1, 0); - cl_end(); - tty_curs(window, 1, 1); - cl_end(); - break; + tty_curs(window, 1, 0); + cl_end(); + tty_curs(window, 1, 1); + cl_end(); + break; case NHW_MAP: - /* cheap -- clear the whole thing and tell nethack to redraw botl */ - context.botlx = 1; - /* fall into ... */ + /* cheap -- clear the whole thing and tell nethack to redraw botl */ + context.botlx = 1; + /* fall into ... */ case NHW_BASE: - clear_screen(); - break; + clear_screen(); + break; case NHW_MENU: case NHW_TEXT: - if(cw->active) - erase_menu_or_text(window, cw, TRUE); - free_window_info(cw, FALSE); - break; + if (cw->active) + erase_menu_or_text(window, cw, TRUE); + free_window_info(cw, FALSE); + break; } cw->curx = cw->cury = 0; } - boolean toggle_menu_curr(window, curr, lineno, in_view, counting, count) winid window; @@ -1239,57 +1255,61 @@ boolean in_view, counting; long count; { if (curr->selected) { - if (counting && count > 0) { - curr->count = count; - if (in_view) set_item_state(window, lineno, curr); - return TRUE; - } else { /* change state */ - curr->selected = FALSE; - curr->count = -1L; - if (in_view) set_item_state(window, lineno, curr); - return TRUE; - } - } else { /* !selected */ - if (counting && count > 0) { - curr->count = count; - curr->selected = TRUE; - if (in_view) set_item_state(window, lineno, curr); - return TRUE; - } else if (!counting) { - curr->selected = TRUE; - if (in_view) set_item_state(window, lineno, curr); - return TRUE; - } - /* do nothing counting&&count==0 */ + if (counting && count > 0) { + curr->count = count; + if (in_view) + set_item_state(window, lineno, curr); + return TRUE; + } else { /* change state */ + curr->selected = FALSE; + curr->count = -1L; + if (in_view) + set_item_state(window, lineno, curr); + return TRUE; + } + } else { /* !selected */ + if (counting && count > 0) { + curr->count = count; + curr->selected = TRUE; + if (in_view) + set_item_state(window, lineno, curr); + return TRUE; + } else if (!counting) { + curr->selected = TRUE; + if (in_view) + set_item_state(window, lineno, curr); + return TRUE; + } + /* do nothing counting&&count==0 */ } return FALSE; } STATIC_OVL void dmore(cw, s) - register struct WinDesc *cw; - const char *s; /* valid responses */ +register struct WinDesc *cw; +const char *s; /* valid responses */ { const char *prompt = cw->morestr ? cw->morestr : defmorestr; int offset = (cw->type == NHW_TEXT) ? 1 : 2; - tty_curs(BASE_WINDOW, - (int)ttyDisplay->curx + offset, (int)ttyDisplay->cury); - if(flags.standout) - standoutbeg(); + tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + offset, + (int) ttyDisplay->cury); + if (flags.standout) + standoutbeg(); xputs(prompt); ttyDisplay->curx += strlen(prompt); - if(flags.standout) - standoutend(); + if (flags.standout) + standoutend(); xwaitforspace(s); } STATIC_OVL void set_item_state(window, lineno, item) - winid window; - int lineno; - tty_menu_item *item; +winid window; +int lineno; +tty_menu_item *item; { char ch = item->selected ? (item->count == -1L ? '+' : '#') : '-'; tty_curs(window, 4, lineno); @@ -1301,53 +1321,53 @@ set_item_state(window, lineno, item) STATIC_OVL void set_all_on_page(window, page_start, page_end) - winid window; - tty_menu_item *page_start, *page_end; +winid window; +tty_menu_item *page_start, *page_end; { tty_menu_item *curr; int n; for (n = 0, curr = page_start; curr != page_end; n++, curr = curr->next) - if (curr->identifier.a_void && !curr->selected) { - curr->selected = TRUE; - set_item_state(window, n, curr); - } + if (curr->identifier.a_void && !curr->selected) { + curr->selected = TRUE; + set_item_state(window, n, curr); + } } STATIC_OVL void unset_all_on_page(window, page_start, page_end) - winid window; - tty_menu_item *page_start, *page_end; +winid window; +tty_menu_item *page_start, *page_end; { tty_menu_item *curr; int n; for (n = 0, curr = page_start; curr != page_end; n++, curr = curr->next) - if (curr->identifier.a_void && curr->selected) { - curr->selected = FALSE; - curr->count = -1L; - set_item_state(window, n, curr); - } + if (curr->identifier.a_void && curr->selected) { + curr->selected = FALSE; + curr->count = -1L; + set_item_state(window, n, curr); + } } STATIC_OVL void invert_all_on_page(window, page_start, page_end, acc) - winid window; - tty_menu_item *page_start, *page_end; - char acc; /* group accelerator, 0 => all */ +winid window; +tty_menu_item *page_start, *page_end; +char acc; /* group accelerator, 0 => all */ { tty_menu_item *curr; int n; for (n = 0, curr = page_start; curr != page_end; n++, curr = curr->next) - if (curr->identifier.a_void && (acc == 0 || curr->gselector == acc)) { - if (curr->selected) { - curr->selected = FALSE; - curr->count = -1L; - } else - curr->selected = TRUE; - set_item_state(window, n, curr); - } + if (curr->identifier.a_void && (acc == 0 || curr->gselector == acc)) { + if (curr->selected) { + curr->selected = FALSE; + curr->count = -1L; + } else + curr->selected = TRUE; + set_item_state(window, n, curr); + } } /* @@ -1356,31 +1376,31 @@ invert_all_on_page(window, page_start, page_end, acc) */ STATIC_OVL void invert_all(window, page_start, page_end, acc) - winid window; - tty_menu_item *page_start, *page_end; - char acc; /* group accelerator, 0 => all */ +winid window; +tty_menu_item *page_start, *page_end; +char acc; /* group accelerator, 0 => all */ { tty_menu_item *curr; boolean on_curr_page; - struct WinDesc *cw = wins[window]; + struct WinDesc *cw = wins[window]; invert_all_on_page(window, page_start, page_end, acc); /* invert the rest */ for (on_curr_page = FALSE, curr = cw->mlist; curr; curr = curr->next) { - if (curr == page_start) - on_curr_page = TRUE; - else if (curr == page_end) - on_curr_page = FALSE; + if (curr == page_start) + on_curr_page = TRUE; + else if (curr == page_end) + on_curr_page = FALSE; - if (!on_curr_page && curr->identifier.a_void - && (acc == 0 || curr->gselector == acc)) { - if (curr->selected) { - curr->selected = FALSE; - curr->count = -1; - } else - curr->selected = TRUE; - } + if (!on_curr_page && curr->identifier.a_void + && (acc == 0 || curr->gselector == acc)) { + if (curr->selected) { + curr->selected = FALSE; + curr->count = -1; + } else + curr->selected = TRUE; + } } } @@ -1393,14 +1413,13 @@ struct WinDesc *cw; long count; int n, curr_page, page_lines, resp_len; boolean finished, counting, reset_count; - char *cp, *rp, resp[QBUFSZ], gacc[QBUFSZ], - *msave, *morestr, really_morc; -#define MENU_EXPLICIT_CHOICE 0x7f /* pseudo menu manipulation char */ + char *cp, *rp, resp[QBUFSZ], gacc[QBUFSZ], *msave, *morestr, really_morc; +#define MENU_EXPLICIT_CHOICE 0x7f /* pseudo menu manipulation char */ curr_page = page_lines = 0; page_start = page_end = 0; - msave = cw->morestr; /* save the morestr */ - cw->morestr = morestr = (char*) alloc((unsigned) QBUFSZ); + msave = cw->morestr; /* save the morestr */ + cw->morestr = morestr = (char *) alloc((unsigned) QBUFSZ); counting = FALSE; count = 0L; reset_count = TRUE; @@ -1411,316 +1430,333 @@ struct WinDesc *cw; accepted; for PICK_ANY, those which match any entry are okay */ gacc[0] = '\0'; if (cw->how != PICK_NONE) { - int i, gcnt[128]; -#define GSELIDX(c) (c & 127) /* guard against `signed char' */ + int i, gcnt[128]; +#define GSELIDX(c) (c & 127) /* guard against `signed char' */ - for (i = 0; i < SIZE(gcnt); i++) gcnt[i] = 0; - for (n = 0, curr = cw->mlist; curr; curr = curr->next) - if (curr->gselector && curr->gselector != curr->selector) { - ++n; - ++gcnt[GSELIDX(curr->gselector)]; - } + for (i = 0; i < SIZE(gcnt); i++) + gcnt[i] = 0; + for (n = 0, curr = cw->mlist; curr; curr = curr->next) + if (curr->gselector && curr->gselector != curr->selector) { + ++n; + ++gcnt[GSELIDX(curr->gselector)]; + } - if (n > 0) /* at least one group accelerator found */ - for (rp = gacc, curr = cw->mlist; curr; curr = curr->next) - if (curr->gselector && curr->gselector != curr->selector && - !index(gacc, curr->gselector) && - (cw->how == PICK_ANY || - gcnt[GSELIDX(curr->gselector)] == 1)) { - *rp++ = curr->gselector; - *rp = '\0'; /* re-terminate for index() */ - } + if (n > 0) /* at least one group accelerator found */ + for (rp = gacc, curr = cw->mlist; curr; curr = curr->next) + if (curr->gselector && curr->gselector != curr->selector + && !index(gacc, curr->gselector) + && (cw->how == PICK_ANY + || gcnt[GSELIDX(curr->gselector)] == 1)) { + *rp++ = curr->gselector; + *rp = '\0'; /* re-terminate for index() */ + } } /* loop until finished */ while (!finished) { - if (reset_count) { - counting = FALSE; - count = 0; - } else - reset_count = TRUE; + if (reset_count) { + counting = FALSE; + count = 0; + } else + reset_count = TRUE; - if (!page_start) { - /* new page to be displayed */ - if (curr_page < 0 || (cw->npages > 0 && curr_page >= cw->npages)) - panic("bad menu screen page #%d", curr_page); + if (!page_start) { + /* new page to be displayed */ + if (curr_page < 0 || (cw->npages > 0 && curr_page >= cw->npages)) + panic("bad menu screen page #%d", curr_page); - /* clear screen */ - if (!cw->offx) { /* if not corner, do clearscreen */ - if(cw->offy) { - tty_curs(window, 1, 0); - cl_eos(); - } else - clear_screen(); - } + /* clear screen */ + if (!cw->offx) { /* if not corner, do clearscreen */ + if (cw->offy) { + tty_curs(window, 1, 0); + cl_eos(); + } else + clear_screen(); + } - rp = resp; - if (cw->npages > 0) { - /* collect accelerators */ - page_start = cw->plist[curr_page]; - page_end = cw->plist[curr_page + 1]; - for (page_lines = 0, curr = page_start; - curr != page_end; - page_lines++, curr = curr->next) { - int color = NO_COLOR, attr = ATR_NONE; - boolean menucolr = FALSE; - if (curr->selector) - *rp++ = curr->selector; + rp = resp; + if (cw->npages > 0) { + /* collect accelerators */ + page_start = cw->plist[curr_page]; + page_end = cw->plist[curr_page + 1]; + for (page_lines = 0, curr = page_start; curr != page_end; + page_lines++, curr = curr->next) { + int color = NO_COLOR, attr = ATR_NONE; + boolean menucolr = FALSE; + if (curr->selector) + *rp++ = curr->selector; - tty_curs(window, 1, page_lines); - if (cw->offx) cl_end(); + tty_curs(window, 1, page_lines); + if (cw->offx) + cl_end(); - (void) putchar(' '); - ++ttyDisplay->curx; - /* - * Don't use xputs() because (1) under unix it calls - * tputstr() which will interpret a '*' as some kind - * of padding information and (2) it calls xputc to - * actually output the character. We're faster doing - * this. - */ - if (iflags.use_menu_color && - (menucolr = get_menu_coloring(curr->str, &color,&attr))) { - term_start_attr(attr); - if (color != NO_COLOR) term_start_color(color); - } else - term_start_attr(curr->attr); - for (n = 0, cp = curr->str; + (void) putchar(' '); + ++ttyDisplay->curx; + /* + * Don't use xputs() because (1) under unix it calls + * tputstr() which will interpret a '*' as some kind + * of padding information and (2) it calls xputc to + * actually output the character. We're faster doing + * this. + */ + if (iflags.use_menu_color + && (menucolr = get_menu_coloring(curr->str, &color, + &attr))) { + term_start_attr(attr); + if (color != NO_COLOR) + term_start_color(color); + } else + term_start_attr(curr->attr); + for (n = 0, cp = curr->str; #ifndef WIN32CON - *cp && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++) + *cp + && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; + cp++, n++) #else - *cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++, ttyDisplay->curx++) + *cp + && (int) ttyDisplay->curx < (int) ttyDisplay->cols; + cp++, n++, ttyDisplay->curx++) #endif - if (n == 2 && curr->identifier.a_void != 0 && - curr->selected) { - if (curr->count == -1L) - (void) putchar('+'); /* all selected */ - else - (void) putchar('#'); /* count selected */ - } else - (void) putchar(*cp); - if (iflags.use_menu_color && menucolr) { - if (color != NO_COLOR) term_end_color(); - term_end_attr(attr); - } else - term_end_attr(curr->attr); - } - } else { - page_start = 0; - page_end = 0; - page_lines = 0; - } - *rp = 0; - /* remember how many explicit menu choices there are */ - resp_len = (int)strlen(resp); + if (n == 2 && curr->identifier.a_void != 0 + && curr->selected) { + if (curr->count == -1L) + (void) putchar('+'); /* all selected */ + else + (void) putchar('#'); /* count selected */ + } else + (void) putchar(*cp); + if (iflags.use_menu_color && menucolr) { + if (color != NO_COLOR) + term_end_color(); + term_end_attr(attr); + } else + term_end_attr(curr->attr); + } + } else { + page_start = 0; + page_end = 0; + page_lines = 0; + } + *rp = 0; + /* remember how many explicit menu choices there are */ + resp_len = (int) strlen(resp); - /* corner window - clear extra lines from last page */ - if (cw->offx) { - for (n = page_lines + 1; n < cw->maxrow; n++) { - tty_curs(window, 1, n); - cl_end(); - } - } + /* corner window - clear extra lines from last page */ + if (cw->offx) { + for (n = page_lines + 1; n < cw->maxrow; n++) { + tty_curs(window, 1, n); + cl_end(); + } + } - /* set extra chars.. */ - Strcat(resp, default_menu_cmds); - Strcat(resp, "0123456789\033\n\r"); /* counts, quit */ - Strcat(resp, gacc); /* group accelerators */ - Strcat(resp, mapped_menu_cmds); + /* set extra chars.. */ + Strcat(resp, default_menu_cmds); + Strcat(resp, "0123456789\033\n\r"); /* counts, quit */ + Strcat(resp, gacc); /* group accelerators */ + Strcat(resp, mapped_menu_cmds); - if (cw->npages > 1) - Sprintf(cw->morestr, "(%d of %d)", - curr_page + 1, (int) cw->npages); - else if (msave) - Strcpy(cw->morestr, msave); - else - Strcpy(cw->morestr, defmorestr); + if (cw->npages > 1) + Sprintf(cw->morestr, "(%d of %d)", curr_page + 1, + (int) cw->npages); + else if (msave) + Strcpy(cw->morestr, msave); + else + Strcpy(cw->morestr, defmorestr); - tty_curs(window, 1, page_lines); - cl_end(); - dmore(cw, resp); - } else { - /* just put the cursor back... */ - tty_curs(window, (int) strlen(cw->morestr) + 2, page_lines); - xwaitforspace(resp); - } + tty_curs(window, 1, page_lines); + cl_end(); + dmore(cw, resp); + } else { + /* just put the cursor back... */ + tty_curs(window, (int) strlen(cw->morestr) + 2, page_lines); + xwaitforspace(resp); + } - really_morc = morc; /* (only used with MENU_EXPLICIT_CHOICE */ - if ((rp = index(resp, morc)) != 0 && rp < resp + resp_len) - /* explicit menu selection; don't override it if it also - happens to match a mapped menu command (such as ':' to - look inside a container vs ':' to search) */ - morc = MENU_EXPLICIT_CHOICE; - else - morc = map_menu_cmd(morc); + really_morc = morc; /* (only used with MENU_EXPLICIT_CHOICE */ + if ((rp = index(resp, morc)) != 0 && rp < resp + resp_len) + /* explicit menu selection; don't override it if it also + happens to match a mapped menu command (such as ':' to + look inside a container vs ':' to search) */ + morc = MENU_EXPLICIT_CHOICE; + else + morc = map_menu_cmd(morc); - switch (morc) { - case '0': - /* special case: '0' is also the default ball class */ - if (!counting && index(gacc, morc)) goto group_accel; - /* fall through to count the zero */ - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - count = (count * 10L) + (long) (morc - '0'); - /* - * It is debatable whether we should allow 0 to - * start a count. There is no difference if the - * item is selected. If not selected, then - * "0b" could mean: - * - * count starting zero: "zero b's" - * ignore starting zero: "select b" - * - * At present I don't know which is better. - */ - if (count != 0L) { /* ignore leading zeros */ - counting = TRUE; - reset_count = FALSE; - } - break; - case '\033': /* cancel - from counting or loop */ - if (!counting) { - /* deselect everything */ - for (curr = cw->mlist; curr; curr = curr->next) { - curr->selected = FALSE; - curr->count = -1L; - } - cw->flags |= WIN_CANCELLED; - finished = TRUE; - } - /* else only stop count */ - break; - case '\0': /* finished (commit) */ - case '\n': - case '\r': - /* only finished if we are actually picking something */ - if (cw->how != PICK_NONE) { - finished = TRUE; - break; - } - /* else fall through */ - case MENU_NEXT_PAGE: - if (cw->npages > 0 && curr_page != cw->npages - 1) { - curr_page++; - page_start = 0; - } else - finished = TRUE; /* questionable behavior */ - break; - case MENU_PREVIOUS_PAGE: - if (cw->npages > 0 && curr_page != 0) { - --curr_page; - page_start = 0; - } - break; - case MENU_FIRST_PAGE: - if (cw->npages > 0 && curr_page != 0) { - page_start = 0; - curr_page = 0; - } - break; - case MENU_LAST_PAGE: - if (cw->npages > 0 && curr_page != cw->npages - 1) { - page_start = 0; - curr_page = cw->npages - 1; - } - break; - case MENU_SELECT_PAGE: - if (cw->how == PICK_ANY) - set_all_on_page(window, page_start, page_end); - break; - case MENU_UNSELECT_PAGE: - unset_all_on_page(window, page_start, page_end); - break; - case MENU_INVERT_PAGE: - if (cw->how == PICK_ANY) - invert_all_on_page(window, page_start, page_end, 0); - break; - case MENU_SELECT_ALL: - if (cw->how == PICK_ANY) { - set_all_on_page(window, page_start, page_end); - /* set the rest */ - for (curr = cw->mlist; curr; curr = curr->next) - if (curr->identifier.a_void && !curr->selected) - curr->selected = TRUE; - } - break; - case MENU_UNSELECT_ALL: - unset_all_on_page(window, page_start, page_end); - /* unset the rest */ - for (curr = cw->mlist; curr; curr = curr->next) - if (curr->identifier.a_void && curr->selected) { - curr->selected = FALSE; - curr->count = -1; - } - break; - case MENU_INVERT_ALL: - if (cw->how == PICK_ANY) - invert_all(window, page_start, page_end, 0); - break; - case MENU_SEARCH: - if (cw->how == PICK_NONE) { - tty_nhbell(); - break; - } else { - char searchbuf[BUFSZ+2], tmpbuf[BUFSZ]; - boolean on_curr_page = FALSE; - int lineno = 0; + switch (morc) { + case '0': + /* special case: '0' is also the default ball class */ + if (!counting && index(gacc, morc)) + goto group_accel; + /* fall through to count the zero */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + count = (count * 10L) + (long) (morc - '0'); + /* + * It is debatable whether we should allow 0 to + * start a count. There is no difference if the + * item is selected. If not selected, then + * "0b" could mean: + * + * count starting zero: "zero b's" + * ignore starting zero: "select b" + * + * At present I don't know which is better. + */ + if (count != 0L) { /* ignore leading zeros */ + counting = TRUE; + reset_count = FALSE; + } + break; + case '\033': /* cancel - from counting or loop */ + if (!counting) { + /* deselect everything */ + for (curr = cw->mlist; curr; curr = curr->next) { + curr->selected = FALSE; + curr->count = -1L; + } + cw->flags |= WIN_CANCELLED; + finished = TRUE; + } + /* else only stop count */ + break; + case '\0': /* finished (commit) */ + case '\n': + case '\r': + /* only finished if we are actually picking something */ + if (cw->how != PICK_NONE) { + finished = TRUE; + break; + } + /* else fall through */ + case MENU_NEXT_PAGE: + if (cw->npages > 0 && curr_page != cw->npages - 1) { + curr_page++; + page_start = 0; + } else + finished = TRUE; /* questionable behavior */ + break; + case MENU_PREVIOUS_PAGE: + if (cw->npages > 0 && curr_page != 0) { + --curr_page; + page_start = 0; + } + break; + case MENU_FIRST_PAGE: + if (cw->npages > 0 && curr_page != 0) { + page_start = 0; + curr_page = 0; + } + break; + case MENU_LAST_PAGE: + if (cw->npages > 0 && curr_page != cw->npages - 1) { + page_start = 0; + curr_page = cw->npages - 1; + } + break; + case MENU_SELECT_PAGE: + if (cw->how == PICK_ANY) + set_all_on_page(window, page_start, page_end); + break; + case MENU_UNSELECT_PAGE: + unset_all_on_page(window, page_start, page_end); + break; + case MENU_INVERT_PAGE: + if (cw->how == PICK_ANY) + invert_all_on_page(window, page_start, page_end, 0); + break; + case MENU_SELECT_ALL: + if (cw->how == PICK_ANY) { + set_all_on_page(window, page_start, page_end); + /* set the rest */ + for (curr = cw->mlist; curr; curr = curr->next) + if (curr->identifier.a_void && !curr->selected) + curr->selected = TRUE; + } + break; + case MENU_UNSELECT_ALL: + unset_all_on_page(window, page_start, page_end); + /* unset the rest */ + for (curr = cw->mlist; curr; curr = curr->next) + if (curr->identifier.a_void && curr->selected) { + curr->selected = FALSE; + curr->count = -1; + } + break; + case MENU_INVERT_ALL: + if (cw->how == PICK_ANY) + invert_all(window, page_start, page_end, 0); + break; + case MENU_SEARCH: + if (cw->how == PICK_NONE) { + tty_nhbell(); + break; + } else { + char searchbuf[BUFSZ + 2], tmpbuf[BUFSZ]; + boolean on_curr_page = FALSE; + int lineno = 0; - tty_getlin("Search for:", tmpbuf); - if (!tmpbuf[0] || tmpbuf[0] == '\033') break; - Sprintf(searchbuf, "*%s*", tmpbuf); + tty_getlin("Search for:", tmpbuf); + if (!tmpbuf[0] || tmpbuf[0] == '\033') + break; + Sprintf(searchbuf, "*%s*", tmpbuf); - for (curr = cw->mlist; curr; curr = curr->next) { - if (on_curr_page) lineno++; - if (curr == page_start) - on_curr_page = TRUE; - else if (curr == page_end) - on_curr_page = FALSE; - if (curr->identifier.a_void - && pmatchi(searchbuf, curr->str)) { - toggle_menu_curr(window, curr, lineno, - on_curr_page, counting, count); - if (cw->how == PICK_ONE) { - finished = TRUE; - break; - } - } - } - } - break; - case MENU_EXPLICIT_CHOICE: - morc = really_morc; - /*FALLTHRU*/ - default: - if (cw->how == PICK_NONE || !index(resp, morc)) { - /* unacceptable input received */ - tty_nhbell(); - break; - } else if (index(gacc, morc)) { - group_accel: - /* group accelerator; for the PICK_ONE case, we know that - it matches exactly one item in order to be in gacc[] */ - invert_all(window, page_start, page_end, morc); - if (cw->how == PICK_ONE) finished = TRUE; - break; - } - /* find, toggle, and possibly update */ - for (n = 0, curr = page_start; - curr != page_end; - n++, curr = curr->next) - if (morc == curr->selector) { - toggle_menu_curr(window, curr, n, TRUE, counting, count); - if (cw->how == PICK_ONE) finished = TRUE; - break; /* from `for' loop */ - } - break; - } + for (curr = cw->mlist; curr; curr = curr->next) { + if (on_curr_page) + lineno++; + if (curr == page_start) + on_curr_page = TRUE; + else if (curr == page_end) + on_curr_page = FALSE; + if (curr->identifier.a_void + && pmatchi(searchbuf, curr->str)) { + toggle_menu_curr(window, curr, lineno, on_curr_page, + counting, count); + if (cw->how == PICK_ONE) { + finished = TRUE; + break; + } + } + } + } + break; + case MENU_EXPLICIT_CHOICE: + morc = really_morc; + /*FALLTHRU*/ + default: + if (cw->how == PICK_NONE || !index(resp, morc)) { + /* unacceptable input received */ + tty_nhbell(); + break; + } else if (index(gacc, morc)) { + group_accel: + /* group accelerator; for the PICK_ONE case, we know that + it matches exactly one item in order to be in gacc[] */ + invert_all(window, page_start, page_end, morc); + if (cw->how == PICK_ONE) + finished = TRUE; + break; + } + /* find, toggle, and possibly update */ + for (n = 0, curr = page_start; curr != page_end; + n++, curr = curr->next) + if (morc == curr->selector) { + toggle_menu_curr(window, curr, n, TRUE, counting, count); + if (cw->how == PICK_ONE) + finished = TRUE; + break; /* from `for' loop */ + } + break; + } } /* while */ cw->morestr = msave; - free((genericptr_t)morestr); + free((genericptr_t) morestr); } STATIC_OVL void @@ -1732,279 +1768,299 @@ struct WinDesc *cw; register char *cp; for (n = 0, i = 0; i < cw->maxrow; i++) { - if (!cw->offx && (n + cw->offy == ttyDisplay->rows - 1)) { - tty_curs(window, 1, n); - cl_end(); - dmore(cw, quitchars); - if (morc == '\033') { - cw->flags |= WIN_CANCELLED; - break; - } - if (cw->offy) { - tty_curs(window, 1, 0); - cl_eos(); - } else - clear_screen(); - n = 0; - } - tty_curs(window, 1, n++); + if (!cw->offx && (n + cw->offy == ttyDisplay->rows - 1)) { + tty_curs(window, 1, n); + cl_end(); + dmore(cw, quitchars); + if (morc == '\033') { + cw->flags |= WIN_CANCELLED; + break; + } + if (cw->offy) { + tty_curs(window, 1, 0); + cl_eos(); + } else + clear_screen(); + n = 0; + } + tty_curs(window, 1, n++); #ifdef H2344_BROKEN - cl_end(); + cl_end(); #else - if (cw->offx) cl_end(); + if (cw->offx) + cl_end(); #endif - if (cw->data[i]) { - attr = cw->data[i][0] - 1; - if (cw->offx) { - (void) putchar(' '); ++ttyDisplay->curx; - } - term_start_attr(attr); - for (cp = &cw->data[i][1]; + if (cw->data[i]) { + attr = cw->data[i][0] - 1; + if (cw->offx) { + (void) putchar(' '); + ++ttyDisplay->curx; + } + term_start_attr(attr); + for (cp = &cw->data[i][1]; #ifndef WIN32CON - *cp && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; - cp++) + *cp && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; + cp++) #else - *cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, ttyDisplay->curx++) + *cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols; + cp++, ttyDisplay->curx++) #endif - (void) putchar(*cp); - term_end_attr(attr); - } + (void) putchar(*cp); + term_end_attr(attr); + } } if (i == cw->maxrow) { #ifdef H2344_BROKEN - if(cw->type == NHW_TEXT){ - tty_curs(BASE_WINDOW, 1, (int)ttyDisplay->cury+1); - cl_eos(); - } + if (cw->type == NHW_TEXT) { + tty_curs(BASE_WINDOW, 1, (int) ttyDisplay->cury + 1); + cl_eos(); + } #endif - tty_curs(BASE_WINDOW, (int)cw->offx + 1, - (cw->type == NHW_TEXT) ? (int) ttyDisplay->rows - 1 : n); - cl_end(); - dmore(cw, quitchars); - if (morc == '\033') - cw->flags |= WIN_CANCELLED; + tty_curs(BASE_WINDOW, (int) cw->offx + 1, + (cw->type == NHW_TEXT) ? (int) ttyDisplay->rows - 1 : n); + cl_end(); + dmore(cw, quitchars); + if (morc == '\033') + cw->flags |= WIN_CANCELLED; } } /*ARGSUSED*/ void tty_display_nhwindow(window, blocking) - winid window; - boolean blocking; /* with ttys, all windows are blocking */ +winid window; +boolean blocking; /* with ttys, all windows are blocking */ { register struct WinDesc *cw = 0; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); - if(cw->flags & WIN_CANCELLED) - return; + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); + if (cw->flags & WIN_CANCELLED) + return; ttyDisplay->lastwin = window; ttyDisplay->rawprint = 0; - switch(cw->type) { + switch (cw->type) { case NHW_MESSAGE: - if(ttyDisplay->toplin == 1) { - more(); - ttyDisplay->toplin = 1; /* more resets this */ - tty_clear_nhwindow(window); - } else - ttyDisplay->toplin = 0; - cw->curx = cw->cury = 0; - if(!cw->active) - iflags.window_inited = TRUE; - break; + if (ttyDisplay->toplin == 1) { + more(); + ttyDisplay->toplin = 1; /* more resets this */ + tty_clear_nhwindow(window); + } else + ttyDisplay->toplin = 0; + cw->curx = cw->cury = 0; + if (!cw->active) + iflags.window_inited = TRUE; + break; case NHW_MAP: - end_glyphout(); - if(blocking) { - if(!ttyDisplay->toplin) ttyDisplay->toplin = 1; - tty_display_nhwindow(WIN_MESSAGE, TRUE); - return; - } + end_glyphout(); + if (blocking) { + if (!ttyDisplay->toplin) + ttyDisplay->toplin = 1; + tty_display_nhwindow(WIN_MESSAGE, TRUE); + return; + } case NHW_BASE: - (void) fflush(stdout); - break; + (void) fflush(stdout); + break; case NHW_TEXT: - cw->maxcol = ttyDisplay->cols; /* force full-screen mode */ - /*FALLTHRU*/ + cw->maxcol = ttyDisplay->cols; /* force full-screen mode */ + /*FALLTHRU*/ case NHW_MENU: - cw->active = 1; + cw->active = 1; #ifdef H2344_BROKEN - cw->offx = (cw->type==NHW_TEXT) - ? 0 - : min( min(82,ttyDisplay->cols/2), ttyDisplay->cols - cw->maxcol - 1); + cw->offx = (cw->type == NHW_TEXT) + ? 0 + : min(min(82, ttyDisplay->cols / 2), + ttyDisplay->cols - cw->maxcol - 1); #else - /* avoid converting to uchar before calculations are finished */ - cw->offx = (uchar) (int) - max((int) 10, (int) (ttyDisplay->cols - cw->maxcol - 1)); + /* avoid converting to uchar before calculations are finished */ + cw->offx = (uchar)(int) max( + (int) 10, (int) (ttyDisplay->cols - cw->maxcol - 1)); #endif - if(cw->offx < 0) cw->offx = 0; - if(cw->type == NHW_MENU) - cw->offy = 0; - if(ttyDisplay->toplin == 1) - tty_display_nhwindow(WIN_MESSAGE, TRUE); + if (cw->offx < 0) + cw->offx = 0; + if (cw->type == NHW_MENU) + cw->offy = 0; + if (ttyDisplay->toplin == 1) + tty_display_nhwindow(WIN_MESSAGE, TRUE); #ifdef H2344_BROKEN - if(cw->maxrow >= (int) ttyDisplay->rows) + if (cw->maxrow >= (int) ttyDisplay->rows) #else - if(cw->offx == 10 || cw->maxrow >= (int) ttyDisplay->rows) + if (cw->offx == 10 || cw->maxrow >= (int) ttyDisplay->rows) #endif - { - cw->offx = 0; - if(cw->offy) { - tty_curs(window, 1, 0); - cl_eos(); - } else - clear_screen(); - ttyDisplay->toplin = 0; - } else { - if (WIN_MESSAGE != WIN_ERR) - tty_clear_nhwindow(WIN_MESSAGE); - } + { + cw->offx = 0; + if (cw->offy) { + tty_curs(window, 1, 0); + cl_eos(); + } else + clear_screen(); + ttyDisplay->toplin = 0; + } else { + if (WIN_MESSAGE != WIN_ERR) + tty_clear_nhwindow(WIN_MESSAGE); + } - if (cw->data || !cw->maxrow) - process_text_window(window, cw); - else - process_menu_window(window, cw); - break; + if (cw->data || !cw->maxrow) + process_text_window(window, cw); + else + process_menu_window(window, cw); + break; } cw->active = 1; } void tty_dismiss_nhwindow(window) - winid window; +winid window; { register struct WinDesc *cw = 0; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); - switch(cw->type) { + switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin) - tty_display_nhwindow(WIN_MESSAGE, TRUE); - /*FALLTHRU*/ + if (ttyDisplay->toplin) + tty_display_nhwindow(WIN_MESSAGE, TRUE); + /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: case NHW_MAP: - /* - * these should only get dismissed when the game is going away - * or suspending - */ - tty_curs(BASE_WINDOW, 1, (int)ttyDisplay->rows-1); - cw->active = 0; - break; + /* + * these should only get dismissed when the game is going away + * or suspending + */ + tty_curs(BASE_WINDOW, 1, (int) ttyDisplay->rows - 1); + cw->active = 0; + break; case NHW_MENU: case NHW_TEXT: - if(cw->active) { - if (iflags.window_inited) { - /* otherwise dismissing the text endwin after other windows - * are dismissed tries to redraw the map and panics. since - * the whole reason for dismissing the other windows was to - * leave the ending window on the screen, we don't want to - * erase it anyway. - */ - erase_menu_or_text(window, cw, FALSE); - } - cw->active = 0; - } - break; + if (cw->active) { + if (iflags.window_inited) { + /* otherwise dismissing the text endwin after other windows + * are dismissed tries to redraw the map and panics. since + * the whole reason for dismissing the other windows was to + * leave the ending window on the screen, we don't want to + * erase it anyway. + */ + erase_menu_or_text(window, cw, FALSE); + } + cw->active = 0; + } + break; } cw->flags = 0; } void tty_destroy_nhwindow(window) - winid window; +winid window; { register struct WinDesc *cw = 0; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); - if(cw->active) - tty_dismiss_nhwindow(window); - if(cw->type == NHW_MESSAGE) - iflags.window_inited = 0; - if(cw->type == NHW_MAP) - clear_screen(); + if (cw->active) + tty_dismiss_nhwindow(window); + if (cw->type == NHW_MESSAGE) + iflags.window_inited = 0; + if (cw->type == NHW_MAP) + clear_screen(); free_window_info(cw, TRUE); - free((genericptr_t)cw); + free((genericptr_t) cw); wins[window] = 0; } void tty_curs(window, x, y) winid window; -register int x, y; /* not xchar: perhaps xchar is unsigned and - curx-x would be unsigned as well */ +register int x, y; /* not xchar: perhaps xchar is unsigned and + curx-x would be unsigned as well */ { struct WinDesc *cw = 0; int cx = ttyDisplay->curx; int cy = ttyDisplay->cury; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); ttyDisplay->lastwin = window; #if defined(USE_TILES) && defined(MSDOS) adjust_cursor_flags(cw); #endif - cw->curx = --x; /* column 0 is never used */ + cw->curx = --x; /* column 0 is never used */ cw->cury = y; #ifdef DEBUG - if(x<0 || y<0 || y >= cw->rows || x > cw->cols) { - const char *s = "[unknown type]"; - switch(cw->type) { - case NHW_MESSAGE: s = "[topl window]"; break; - case NHW_STATUS: s = "[status window]"; break; - case NHW_MAP: s = "[map window]"; break; - case NHW_MENU: s = "[corner window]"; break; - case NHW_TEXT: s = "[text window]"; break; - case NHW_BASE: s = "[base window]"; break; - } - debugpline4("bad curs positioning win %d %s (%d,%d)", window, s, x, y); - return; + if (x < 0 || y < 0 || y >= cw->rows || x > cw->cols) { + const char *s = "[unknown type]"; + switch (cw->type) { + case NHW_MESSAGE: + s = "[topl window]"; + break; + case NHW_STATUS: + s = "[status window]"; + break; + case NHW_MAP: + s = "[map window]"; + break; + case NHW_MENU: + s = "[corner window]"; + break; + case NHW_TEXT: + s = "[text window]"; + break; + case NHW_BASE: + s = "[base window]"; + break; + } + debugpline4("bad curs positioning win %d %s (%d,%d)", window, s, x, + y); + return; } #endif x += cw->offx; y += cw->offy; #ifdef CLIPPING - if(clipping && window == WIN_MAP) { - x -= clipx; - y -= clipy; + if (clipping && window == WIN_MAP) { + x -= clipx; + y -= clipy; } #endif if (y == cy && x == cx) - return; + return; - if(cw->type == NHW_MAP) - end_glyphout(); + if (cw->type == NHW_MAP) + end_glyphout(); #ifndef NO_TERMS - if(!nh_ND && (cx != x || x <= 3)) { /* Extremely primitive */ - cmov(x, y); /* bunker!wtm */ - return; + if (!nh_ND && (cx != x || x <= 3)) { /* Extremely primitive */ + cmov(x, y); /* bunker!wtm */ + return; } #endif - if((cy -= y) < 0) cy = -cy; - if((cx -= x) < 0) cx = -cx; - if(cy <= 3 && cx <= 3) { - nocmov(x, y); + if ((cy -= y) < 0) + cy = -cy; + if ((cx -= x) < 0) + cx = -cx; + if (cy <= 3 && cx <= 3) { + nocmov(x, y); #ifndef NO_TERMS } else if ((x <= 3 && cy <= 3) || (!nh_CM && x < cx)) { - (void) putchar('\r'); - ttyDisplay->curx = 0; - nocmov(x, y); + (void) putchar('\r'); + ttyDisplay->curx = 0; + nocmov(x, y); } else if (!nh_CM) { - nocmov(x, y); + nocmov(x, y); #endif } else - cmov(x, y); + cmov(x, y); ttyDisplay->curx = x; ttyDisplay->cury = y; @@ -2012,61 +2068,60 @@ register int x, y; /* not xchar: perhaps xchar is unsigned and STATIC_OVL void tty_putsym(window, x, y, ch) - winid window; - int x, y; - char ch; +winid window; +int x, y; +char ch; { register struct WinDesc *cw = 0; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) + panic(winpanicstr, window); - switch(cw->type) { + switch (cw->type) { case NHW_STATUS: case NHW_MAP: case NHW_BASE: - tty_curs(window, x, y); - (void) putchar(ch); - ttyDisplay->curx++; - cw->curx++; - break; + tty_curs(window, x, y); + (void) putchar(ch); + ttyDisplay->curx++; + cw->curx++; + break; case NHW_MESSAGE: case NHW_MENU: case NHW_TEXT: - impossible("Can't putsym to window type %d", cw->type); - break; + impossible("Can't putsym to window type %d", cw->type); + break; } } - -STATIC_OVL const char* +STATIC_OVL const char * compress_str(str) const char *str; { - static char cbuf[BUFSZ]; - /* compress in case line too long */ - if((int)strlen(str) >= CO) { - register const char *bp0 = str; - register char *bp1 = cbuf; + static char cbuf[BUFSZ]; + /* compress in case line too long */ + if ((int) strlen(str) >= CO) { + register const char *bp0 = str; + register char *bp1 = cbuf; - do { + do { #ifdef CLIPPING - if(*bp0 != ' ' || bp0[1] != ' ') + if (*bp0 != ' ' || bp0[1] != ' ') #else - if(*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ') + if (*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ') #endif - *bp1++ = *bp0; - } while(*bp0++); - } else - return str; - return cbuf; + *bp1++ = *bp0; + } while (*bp0++); + } else + return str; + return cbuf; } void tty_putstr(window, attr, str) - winid window; - int attr; - const char *str; +winid window; +int attr; +const char *str; { register struct WinDesc *cw = 0; register char *ob; @@ -2076,228 +2131,243 @@ tty_putstr(window, attr, str) /* Assume there's a real problem if the window is missing -- * probably a panic message */ - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) { - tty_raw_print(str); - return; + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0) { + tty_raw_print(str); + return; } - if(str == (const char*)0 || - ((cw->flags & WIN_CANCELLED) && (cw->type != NHW_MESSAGE))) - return; - if(cw->type != NHW_MESSAGE) - str = compress_str(str); + if (str == (const char *) 0 + || ((cw->flags & WIN_CANCELLED) && (cw->type != NHW_MESSAGE))) + return; + if (cw->type != NHW_MESSAGE) + str = compress_str(str); ttyDisplay->lastwin = window; - switch(cw->type) { + switch (cw->type) { case NHW_MESSAGE: - /* really do this later */ +/* really do this later */ #if defined(USER_SOUNDS) && defined(WIN32CON) - play_sound_for_message(str); + play_sound_for_message(str); #endif - update_topl(str); - break; + update_topl(str); + break; case NHW_STATUS: - ob = &cw->data[cw->cury][j = cw->curx]; - if(context.botlx) *ob = 0; - if(!cw->cury && (int)strlen(str) >= CO) { - /* the characters before "St:" are unnecessary */ - nb = index(str, ':'); - if(nb && nb > str+2) - str = nb - 2; - } - nb = str; - for(i = cw->curx+1, n0 = cw->cols; i < n0; i++, nb++) { - if(!*nb) { - if(*ob || context.botlx) { - /* last char printed may be in middle of line */ - tty_curs(WIN_STATUS, i, cw->cury); - cl_end(); - } - break; - } - if(*ob != *nb) - tty_putsym(WIN_STATUS, i, cw->cury, *nb); - if(*ob) ob++; - } + ob = &cw->data[cw->cury][j = cw->curx]; + if (context.botlx) + *ob = 0; + if (!cw->cury && (int) strlen(str) >= CO) { + /* the characters before "St:" are unnecessary */ + nb = index(str, ':'); + if (nb && nb > str + 2) + str = nb - 2; + } + nb = str; + for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) { + if (!*nb) { + if (*ob || context.botlx) { + /* last char printed may be in middle of line */ + tty_curs(WIN_STATUS, i, cw->cury); + cl_end(); + } + break; + } + if (*ob != *nb) + tty_putsym(WIN_STATUS, i, cw->cury, *nb); + if (*ob) + ob++; + } - (void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1); - cw->data[cw->cury][cw->cols-1] = '\0'; /* null terminate */ - cw->cury = (cw->cury+1) % 2; - cw->curx = 0; - break; + (void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1); + cw->data[cw->cury][cw->cols - 1] = '\0'; /* null terminate */ + cw->cury = (cw->cury + 1) % 2; + cw->curx = 0; + break; case NHW_MAP: - tty_curs(window, cw->curx+1, cw->cury); - term_start_attr(attr); - while(*str && (int) ttyDisplay->curx < (int) ttyDisplay->cols-1) { - (void) putchar(*str); - str++; - ttyDisplay->curx++; - } - cw->curx = 0; - cw->cury++; - term_end_attr(attr); - break; + tty_curs(window, cw->curx + 1, cw->cury); + term_start_attr(attr); + while (*str && (int) ttyDisplay->curx < (int) ttyDisplay->cols - 1) { + (void) putchar(*str); + str++; + ttyDisplay->curx++; + } + cw->curx = 0; + cw->cury++; + term_end_attr(attr); + break; case NHW_BASE: - tty_curs(window, cw->curx+1, cw->cury); - term_start_attr(attr); - while (*str) { - if ((int) ttyDisplay->curx >= (int) ttyDisplay->cols-1) { - cw->curx = 0; - cw->cury++; - tty_curs(window, cw->curx+1, cw->cury); - } - (void) putchar(*str); - str++; - ttyDisplay->curx++; - } - cw->curx = 0; - cw->cury++; - term_end_attr(attr); - break; + tty_curs(window, cw->curx + 1, cw->cury); + term_start_attr(attr); + while (*str) { + if ((int) ttyDisplay->curx >= (int) ttyDisplay->cols - 1) { + cw->curx = 0; + cw->cury++; + tty_curs(window, cw->curx + 1, cw->cury); + } + (void) putchar(*str); + str++; + ttyDisplay->curx++; + } + cw->curx = 0; + cw->cury++; + term_end_attr(attr); + break; case NHW_MENU: case NHW_TEXT: #ifdef H2344_BROKEN - if(cw->type == NHW_TEXT && (cw->cury+cw->offy) == ttyDisplay->rows-1) + if (cw->type == NHW_TEXT + && (cw->cury + cw->offy) == ttyDisplay->rows - 1) #else - if(cw->type == NHW_TEXT && cw->cury == ttyDisplay->rows-1) + if (cw->type == NHW_TEXT && cw->cury == ttyDisplay->rows - 1) #endif - { - /* not a menu, so save memory and output 1 page at a time */ - cw->maxcol = ttyDisplay->cols; /* force full-screen mode */ - tty_display_nhwindow(window, TRUE); - for(i=0; imaxrow; i++) - if(cw->data[i]){ - free((genericptr_t)cw->data[i]); - cw->data[i] = 0; - } - cw->maxrow = cw->cury = 0; - } - /* always grows one at a time, but alloc 12 at a time */ - if(cw->cury >= cw->rows) { - char **tmp; + { + /* not a menu, so save memory and output 1 page at a time */ + cw->maxcol = ttyDisplay->cols; /* force full-screen mode */ + tty_display_nhwindow(window, TRUE); + for (i = 0; i < cw->maxrow; i++) + if (cw->data[i]) { + free((genericptr_t) cw->data[i]); + cw->data[i] = 0; + } + cw->maxrow = cw->cury = 0; + } + /* always grows one at a time, but alloc 12 at a time */ + if (cw->cury >= cw->rows) { + char **tmp; - cw->rows += 12; - tmp = (char **) alloc(sizeof(char *) * (unsigned)cw->rows); - for(i=0; imaxrow; i++) - tmp[i] = cw->data[i]; - if(cw->data) - free((genericptr_t)cw->data); - cw->data = tmp; + cw->rows += 12; + tmp = (char **) alloc(sizeof(char *) * (unsigned) cw->rows); + for (i = 0; i < cw->maxrow; i++) + tmp[i] = cw->data[i]; + if (cw->data) + free((genericptr_t) cw->data); + cw->data = tmp; - for(i=cw->maxrow; irows; i++) - cw->data[i] = 0; - } - if(cw->data[cw->cury]) - free((genericptr_t)cw->data[cw->cury]); - n0 = strlen(str) + 1; - ob = cw->data[cw->cury] = (char *)alloc((unsigned)n0 + 1); - *ob++ = (char)(attr + 1); /* avoid nuls, for convenience */ - Strcpy(ob, str); + for (i = cw->maxrow; i < cw->rows; i++) + cw->data[i] = 0; + } + if (cw->data[cw->cury]) + free((genericptr_t) cw->data[cw->cury]); + n0 = strlen(str) + 1; + ob = cw->data[cw->cury] = (char *) alloc((unsigned) n0 + 1); + *ob++ = (char) (attr + 1); /* avoid nuls, for convenience */ + Strcpy(ob, str); - if(n0 > cw->maxcol) - cw->maxcol = n0; - if(++cw->cury > cw->maxrow) - cw->maxrow = cw->cury; - if(n0 > CO) { - /* attempt to break the line */ - for(i = CO-1; i && str[i] != ' ' && str[i] != '\n';) - i--; - if(i) { - cw->data[cw->cury-1][++i] = '\0'; - tty_putstr(window, attr, &str[i]); - } - } - break; + if (n0 > cw->maxcol) + cw->maxcol = n0; + if (++cw->cury > cw->maxrow) + cw->maxrow = cw->cury; + if (n0 > CO) { + /* attempt to break the line */ + for (i = CO - 1; i && str[i] != ' ' && str[i] != '\n';) + i--; + if (i) { + cw->data[cw->cury - 1][++i] = '\0'; + tty_putstr(window, attr, &str[i]); + } + } + break; } } - void tty_display_file(fname, complain) const char *fname; boolean complain; { -#ifdef DEF_PAGER /* this implies that UNIX is defined */ +#ifdef DEF_PAGER /* this implies that UNIX is defined */ { - /* use external pager; this may give security problems */ - register int fd = open(fname, 0); + /* use external pager; this may give security problems */ + register int fd = open(fname, 0); - if(fd < 0) { - if(complain) pline("Cannot open %s.", fname); - else docrt(); - return; - } - if(child(1)) { - /* Now that child() does a setuid(getuid()) and a chdir(), - we may not be able to open file fname anymore, so make - it stdin. */ - (void) close(0); - if(dup(fd)) { - if(complain) raw_printf("Cannot open %s as stdin.", fname); - } else { - (void) execlp(catmore, "page", (char *)0); - if(complain) raw_printf("Cannot exec %s.", catmore); - } - if(complain) sleep(10); /* want to wait_synch() but stdin is gone */ - terminate(EXIT_FAILURE); - } - (void) close(fd); -# ifdef notyet - winch_seen = 0; -# endif + if (fd < 0) { + if (complain) + pline("Cannot open %s.", fname); + else + docrt(); + return; + } + if (child(1)) { + /* Now that child() does a setuid(getuid()) and a chdir(), + we may not be able to open file fname anymore, so make + it stdin. */ + (void) close(0); + if (dup(fd)) { + if (complain) + raw_printf("Cannot open %s as stdin.", fname); + } else { + (void) execlp(catmore, "page", (char *) 0); + if (complain) + raw_printf("Cannot exec %s.", catmore); + } + if (complain) + sleep(10); /* want to wait_synch() but stdin is gone */ + terminate(EXIT_FAILURE); + } + (void) close(fd); +#ifdef notyet + winch_seen = 0; +#endif } -#else /* DEF_PAGER */ +#else /* DEF_PAGER */ { - dlb *f; - char buf[BUFSZ]; - char *cr; + dlb *f; + char buf[BUFSZ]; + char *cr; - tty_clear_nhwindow(WIN_MESSAGE); - f = dlb_fopen(fname, "r"); - if (!f) { - if(complain) { - home(); tty_mark_synch(); tty_raw_print(""); - perror(fname); tty_wait_synch(); - pline("Cannot open \"%s\".", fname); - } else if(u.ux) docrt(); - } else { - winid datawin = tty_create_nhwindow(NHW_TEXT); - boolean empty = TRUE; + tty_clear_nhwindow(WIN_MESSAGE); + f = dlb_fopen(fname, "r"); + if (!f) { + if (complain) { + home(); + tty_mark_synch(); + tty_raw_print(""); + perror(fname); + tty_wait_synch(); + pline("Cannot open \"%s\".", fname); + } else if (u.ux) + docrt(); + } else { + winid datawin = tty_create_nhwindow(NHW_TEXT); + boolean empty = TRUE; - if(complain + if (complain #ifndef NO_TERMS - && nh_CD + && nh_CD #endif - ) { - /* attempt to scroll text below map window if there's room */ - wins[datawin]->offy = wins[WIN_STATUS]->offy+3; - if((int) wins[datawin]->offy + 12 > (int) ttyDisplay->rows) - wins[datawin]->offy = 0; - } - while (dlb_fgets(buf, BUFSZ, f)) { - if ((cr = index(buf, '\n')) != 0) *cr = 0; + ) { + /* attempt to scroll text below map window if there's room */ + wins[datawin]->offy = wins[WIN_STATUS]->offy + 3; + if ((int) wins[datawin]->offy + 12 > (int) ttyDisplay->rows) + wins[datawin]->offy = 0; + } + while (dlb_fgets(buf, BUFSZ, f)) { + if ((cr = index(buf, '\n')) != 0) + *cr = 0; #ifdef MSDOS - if ((cr = index(buf, '\r')) != 0) *cr = 0; + if ((cr = index(buf, '\r')) != 0) + *cr = 0; #endif - if (index(buf, '\t') != 0) (void) tabexpand(buf); - empty = FALSE; - tty_putstr(datawin, 0, buf); - if(wins[datawin]->flags & WIN_CANCELLED) - break; - } - if (!empty) tty_display_nhwindow(datawin, FALSE); - tty_destroy_nhwindow(datawin); - (void) dlb_fclose(f); - } + if (index(buf, '\t') != 0) + (void) tabexpand(buf); + empty = FALSE; + tty_putstr(datawin, 0, buf); + if (wins[datawin]->flags & WIN_CANCELLED) + break; + } + if (!empty) + tty_display_nhwindow(datawin, FALSE); + tty_destroy_nhwindow(datawin); + (void) dlb_fclose(f); + } } #endif /* DEF_PAGER */ } void tty_start_menu(window) - winid window; +winid window; { tty_clear_nhwindow(window); return; @@ -2310,41 +2380,41 @@ tty_start_menu(window) */ void tty_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) - winid window; /* window to use, must be of type NHW_MENU */ - int glyph UNUSED; /* glyph to display with item (not used) */ - const anything *identifier; /* what to return if selected */ - char ch; /* keyboard accelerator (0 = pick our own) */ - char gch; /* group accelerator (0 = no group) */ - int attr; /* attribute for string (like tty_putstr()) */ - const char *str; /* menu string */ - boolean preselected; /* item is marked as selected */ +winid window; /* window to use, must be of type NHW_MENU */ +int glyph UNUSED; /* glyph to display with item (not used) */ +const anything *identifier; /* what to return if selected */ +char ch; /* keyboard accelerator (0 = pick our own) */ +char gch; /* group accelerator (0 = no group) */ +int attr; /* attribute for string (like tty_putstr()) */ +const char *str; /* menu string */ +boolean preselected; /* item is marked as selected */ { register struct WinDesc *cw = 0; tty_menu_item *item; const char *newstr; - char buf[4+BUFSZ]; + char buf[4 + BUFSZ]; - if (str == (const char*) 0) - return; + if (str == (const char *) 0) + return; if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0 - || cw->type != NHW_MENU) - panic(winpanicstr, window); + || cw->type != NHW_MENU) + panic(winpanicstr, window); cw->nitems++; if (identifier->a_void) { - int len = strlen(str); - if (len >= BUFSZ) { - /* We *think* everything's coming in off at most BUFSZ bufs... */ - impossible("Menu item too long (%d).", len); - len = BUFSZ - 1; - } - Sprintf(buf, "%c - ", ch ? ch : '?'); - (void) strncpy(buf+4, str, len); - buf[4+len] = '\0'; - newstr = buf; + int len = strlen(str); + if (len >= BUFSZ) { + /* We *think* everything's coming in off at most BUFSZ bufs... */ + impossible("Menu item too long (%d).", len); + len = BUFSZ - 1; + } + Sprintf(buf, "%c - ", ch ? ch : '?'); + (void) strncpy(buf + 4, str, len); + buf[4 + len] = '\0'; + newstr = buf; } else - newstr = str; + newstr = str; item = (tty_menu_item *) alloc(sizeof(tty_menu_item)); item->identifier = *identifier; @@ -2362,15 +2432,15 @@ tty_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected) /* Invert the given list, can handle NULL as an input. */ STATIC_OVL tty_menu_item * reverse(curr) - tty_menu_item *curr; +tty_menu_item *curr; { tty_menu_item *next, *head = 0; while (curr) { - next = curr->next; - curr->next = head; - head = curr; - curr = next; + next = curr->next; + curr->next = head; + head = curr; + curr = next; } return head; } @@ -2383,8 +2453,8 @@ reverse(curr) */ void tty_end_menu(window, prompt) - winid window; /* menu to use */ - const char *prompt; /* prompt to for menu */ +winid window; /* menu to use */ +const char *prompt; /* prompt to for menu */ { struct WinDesc *cw = 0; tty_menu_item *curr; @@ -2392,78 +2462,84 @@ tty_end_menu(window, prompt) int lmax, n; char menu_ch; - if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0 || - cw->type != NHW_MENU) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0 + || cw->type != NHW_MENU) + panic(winpanicstr, window); /* Reverse the list so that items are in correct order. */ cw->mlist = reverse(cw->mlist); /* Put the promt at the beginning of the menu. */ if (prompt) { - anything any; + anything any; - any = zeroany; /* not selectable */ - tty_add_menu(window, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); - tty_add_menu(window, NO_GLYPH, &any, 0, 0, ATR_NONE, prompt, MENU_UNSELECTED); + any = zeroany; /* not selectable */ + tty_add_menu(window, NO_GLYPH, &any, 0, 0, ATR_NONE, "", + MENU_UNSELECTED); + tty_add_menu(window, NO_GLYPH, &any, 0, 0, ATR_NONE, prompt, + MENU_UNSELECTED); } - /* XXX another magic number? 52 */ - lmax = min(52, (int)ttyDisplay->rows - 1); /* # lines per page */ - cw->npages = (cw->nitems + (lmax - 1)) / lmax; /* # of pages */ + /* XXX another magic number? 52 */ + lmax = min(52, (int) ttyDisplay->rows - 1); /* # lines per page */ + cw->npages = (cw->nitems + (lmax - 1)) / lmax; /* # of pages */ /* make sure page list is large enough */ - if (cw->plist_size < cw->npages+1 /*need 1 slot beyond last*/) { - if (cw->plist) free((genericptr_t)cw->plist); - cw->plist_size = cw->npages + 1; - cw->plist = (tty_menu_item **) - alloc(cw->plist_size * sizeof(tty_menu_item *)); + if (cw->plist_size < cw->npages + 1 /*need 1 slot beyond last*/) { + if (cw->plist) + free((genericptr_t) cw->plist); + cw->plist_size = cw->npages + 1; + cw->plist = (tty_menu_item **) alloc(cw->plist_size + * sizeof(tty_menu_item *)); } - cw->cols = 0; /* cols is set when the win is initialized... (why?) */ - menu_ch = '?'; /* lint suppression */ + cw->cols = 0; /* cols is set when the win is initialized... (why?) */ + menu_ch = '?'; /* lint suppression */ for (n = 0, curr = cw->mlist; curr; n++, curr = curr->next) { - /* set page boundaries and character accelerators */ - if ((n % lmax) == 0) { - menu_ch = 'a'; - cw->plist[n/lmax] = curr; - } - if (curr->identifier.a_void && !curr->selector) { - curr->str[0] = curr->selector = menu_ch; - if (menu_ch++ == 'z') menu_ch = 'A'; - } + /* set page boundaries and character accelerators */ + if ((n % lmax) == 0) { + menu_ch = 'a'; + cw->plist[n / lmax] = curr; + } + if (curr->identifier.a_void && !curr->selector) { + curr->str[0] = curr->selector = menu_ch; + if (menu_ch++ == 'z') + menu_ch = 'A'; + } - /* cut off any lines that are too long */ - len = strlen(curr->str) + 2; /* extra space at beg & end */ - if (len > (int)ttyDisplay->cols) { - curr->str[ttyDisplay->cols-2] = 0; - len = ttyDisplay->cols; - } - if (len > cw->cols) cw->cols = len; + /* cut off any lines that are too long */ + len = strlen(curr->str) + 2; /* extra space at beg & end */ + if (len > (int) ttyDisplay->cols) { + curr->str[ttyDisplay->cols - 2] = 0; + len = ttyDisplay->cols; + } + if (len > cw->cols) + cw->cols = len; } - cw->plist[cw->npages] = 0; /* plist terminator */ + cw->plist[cw->npages] = 0; /* plist terminator */ /* * If greater than 1 page, morestr is "(x of y) " otherwise, "(end) " */ if (cw->npages > 1) { - char buf[QBUFSZ]; - /* produce the largest demo string */ - Sprintf(buf, "(%ld of %ld) ", cw->npages, cw->npages); - len = strlen(buf); - cw->morestr = copy_of(""); + char buf[QBUFSZ]; + /* produce the largest demo string */ + Sprintf(buf, "(%ld of %ld) ", cw->npages, cw->npages); + len = strlen(buf); + cw->morestr = copy_of(""); } else { - cw->morestr = copy_of("(end) "); - len = strlen(cw->morestr); + cw->morestr = copy_of("(end) "); + len = strlen(cw->morestr); } - if (len > (int)ttyDisplay->cols) { - /* truncate the prompt if it's too long for the screen */ - if (cw->npages <= 1) /* only str in single page case */ - cw->morestr[ttyDisplay->cols] = 0; - len = ttyDisplay->cols; + if (len > (int) ttyDisplay->cols) { + /* truncate the prompt if it's too long for the screen */ + if (cw->npages <= 1) /* only str in single page case */ + cw->morestr[ttyDisplay->cols] = 0; + len = ttyDisplay->cols; } - if (len > cw->cols) cw->cols = len; + if (len > cw->cols) + cw->cols = len; cw->maxcol = cw->cols; @@ -2472,48 +2548,49 @@ tty_end_menu(window, prompt) * maximum size of the window. */ if (cw->npages > 1) - cw->maxrow = cw->rows = lmax + 1; + cw->maxrow = cw->rows = lmax + 1; else - cw->maxrow = cw->rows = cw->nitems + 1; + cw->maxrow = cw->rows = cw->nitems + 1; } int tty_select_menu(window, how, menu_list) - winid window; - int how; - menu_item **menu_list; +winid window; +int how; +menu_item **menu_list; { register struct WinDesc *cw = 0; tty_menu_item *curr; menu_item *mi; int n, cancelled; - if(window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0 - || cw->type != NHW_MENU) - panic(winpanicstr, window); + if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0 + || cw->type != NHW_MENU) + panic(winpanicstr, window); *menu_list = (menu_item *) 0; cw->how = (short) how; morc = 0; tty_display_nhwindow(window, TRUE); cancelled = !!(cw->flags & WIN_CANCELLED); - tty_dismiss_nhwindow(window); /* does not destroy window data */ + tty_dismiss_nhwindow(window); /* does not destroy window data */ if (cancelled) { - n = -1; + n = -1; } else { - for (n = 0, curr = cw->mlist; curr; curr = curr->next) - if (curr->selected) n++; + for (n = 0, curr = cw->mlist; curr; curr = curr->next) + if (curr->selected) + n++; } if (n > 0) { - *menu_list = (menu_item *) alloc(n * sizeof(menu_item)); - for (mi = *menu_list, curr = cw->mlist; curr; curr = curr->next) - if (curr->selected) { - mi->item = curr->identifier; - mi->count = curr->count; - mi++; - } + *menu_list = (menu_item *) alloc(n * sizeof(menu_item)); + for (mi = *menu_list, curr = cw->mlist; curr; curr = curr->next) + if (curr->selected) { + mi->item = curr->identifier; + mi->count = curr->count; + mi++; + } } return n; @@ -2528,8 +2605,8 @@ const char *mesg; { /* "menu" without selection; use ordinary pline, no more() */ if (how == PICK_NONE) { - pline("%s", mesg); - return 0; + pline("%s", mesg); + return 0; } ttyDisplay->dismiss_more = let; @@ -2539,9 +2616,9 @@ const char *mesg; tty_putstr(WIN_MESSAGE, 0, mesg); /* if `mesg' didn't wrap (triggering --More--), force --More-- now */ if (ttyDisplay->toplin == 1) { - more(); - ttyDisplay->toplin = 1; /* more resets this */ - tty_clear_nhwindow(WIN_MESSAGE); + more(); + ttyDisplay->toplin = 1; /* more resets this */ + tty_clear_nhwindow(WIN_MESSAGE); } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should @@ -2568,64 +2645,69 @@ void tty_wait_synch() { /* we just need to make sure all windows are synch'd */ - if(!ttyDisplay || ttyDisplay->rawprint) { - getret(); - if(ttyDisplay) ttyDisplay->rawprint = 0; + if (!ttyDisplay || ttyDisplay->rawprint) { + getret(); + if (ttyDisplay) + ttyDisplay->rawprint = 0; } else { - tty_display_nhwindow(WIN_MAP, FALSE); - if(ttyDisplay->inmore) { - addtopl("--More--"); - (void) fflush(stdout); - } else if(ttyDisplay->inread > program_state.gameover) { - /* this can only happen if we were reading and got interrupted */ - ttyDisplay->toplin = 3; - /* do this twice; 1st time gets the Quit? message again */ - (void) tty_doprev_message(); - (void) tty_doprev_message(); - ttyDisplay->intr++; - (void) fflush(stdout); - } + tty_display_nhwindow(WIN_MAP, FALSE); + if (ttyDisplay->inmore) { + addtopl("--More--"); + (void) fflush(stdout); + } else if (ttyDisplay->inread > program_state.gameover) { + /* this can only happen if we were reading and got interrupted */ + ttyDisplay->toplin = 3; + /* do this twice; 1st time gets the Quit? message again */ + (void) tty_doprev_message(); + (void) tty_doprev_message(); + ttyDisplay->intr++; + (void) fflush(stdout); + } } } void docorner(xmin, ymax) - register int xmin, ymax; +register int xmin, ymax; { register int y; register struct WinDesc *cw = wins[WIN_MAP]; - if (u.uswallow) { /* Can be done more efficiently */ - swallowed(1); - return; + if (u.uswallow) { /* Can be done more efficiently */ + swallowed(1); + return; } #if defined(SIGWINCH) && defined(CLIPPING) - if(ymax > LI) ymax = LI; /* can happen if window gets smaller */ + if (ymax > LI) + ymax = LI; /* can happen if window gets smaller */ #endif for (y = 0; y < ymax; y++) { - tty_curs(BASE_WINDOW, xmin,y); /* move cursor */ - cl_end(); /* clear to end of line */ + tty_curs(BASE_WINDOW, xmin, y); /* move cursor */ + cl_end(); /* clear to end of line */ #ifdef CLIPPING - if (y<(int) cw->offy || y+clipy > ROWNO) - continue; /* only refresh board */ + if (y < (int) cw->offy || y + clipy > ROWNO) + continue; /* only refresh board */ #if defined(USE_TILES) && defined(MSDOS) - if (iflags.tile_view) - row_refresh((xmin/2)+clipx-((int)cw->offx/2),COLNO-1,y+clipy-(int)cw->offy); - else + if (iflags.tile_view) + row_refresh((xmin / 2) + clipx - ((int) cw->offx / 2), COLNO - 1, + y + clipy - (int) cw->offy); + else #endif - row_refresh(xmin+clipx-(int)cw->offx,COLNO-1,y+clipy-(int)cw->offy); + row_refresh(xmin + clipx - (int) cw->offx, COLNO - 1, + y + clipy - (int) cw->offy); #else - if (yoffy || y > ROWNO) continue; /* only refresh board */ - row_refresh(xmin-(int)cw->offx,COLNO-1,y-(int)cw->offy); + if (y < cw->offy || y > ROWNO) + continue; /* only refresh board */ + row_refresh(xmin - (int) cw->offx, COLNO - 1, y - (int) cw->offy); #endif } end_glyphout(); if (ymax >= (int) wins[WIN_STATUS]->offy) { - /* we have wrecked the bottom line */ - context.botlx = 1; - bot(); + /* we have wrecked the bottom line */ + context.botlx = 1; + bot(); } } @@ -2634,14 +2716,14 @@ end_glyphout() { #if defined(ASCIIGRAPH) && !defined(NO_TERMS) if (GFlag) { - GFlag = FALSE; - graph_off(); + GFlag = FALSE; + graph_off(); } #endif #ifdef TEXTCOLOR - if(ttyDisplay->color != NO_COLOR) { - term_end_color(); - ttyDisplay->color = NO_COLOR; + if (ttyDisplay->color != NO_COLOR) { + term_end_color(); + ttyDisplay->color = NO_COLOR; } #endif } @@ -2651,30 +2733,30 @@ void g_putch(in_ch) int in_ch; { - register char ch = (char)in_ch; + register char ch = (char) in_ch; -# if defined(ASCIIGRAPH) && !defined(NO_TERMS) +#if defined(ASCIIGRAPH) && !defined(NO_TERMS) if (SYMHANDLING(H_IBM) || iflags.eight_bit_tty) { - /* IBM-compatible displays don't need other stuff */ - (void) putchar(ch); + /* IBM-compatible displays don't need other stuff */ + (void) putchar(ch); } else if (ch & 0x80) { - if (!GFlag || HE_resets_AS) { - graph_on(); - GFlag = TRUE; - } - (void) putchar((ch ^ 0x80)); /* Strip 8th bit */ + if (!GFlag || HE_resets_AS) { + graph_on(); + GFlag = TRUE; + } + (void) putchar((ch ^ 0x80)); /* Strip 8th bit */ } else { - if (GFlag) { - graph_off(); - GFlag = FALSE; - } - (void) putchar(ch); + if (GFlag) { + graph_off(); + GFlag = FALSE; + } + (void) putchar(ch); } #else (void) putchar(ch); -#endif /* ASCIIGRAPH && !NO_TERMS */ +#endif /* ASCIIGRAPH && !NO_TERMS */ return; } @@ -2684,44 +2766,42 @@ int in_ch; void setclipped() { - clipping = TRUE; - clipx = clipy = 0; - clipxmax = CO; - clipymax = LI - 3; + clipping = TRUE; + clipx = clipy = 0; + clipxmax = CO; + clipymax = LI - 3; } void tty_cliparound(x, y) int x, y; { - extern boolean restoring; - int oldx = clipx, oldy = clipy; + extern boolean restoring; + int oldx = clipx, oldy = clipy; - if (!clipping) return; - if (x < clipx + 5) { - clipx = max(0, x - 20); - clipxmax = clipx + CO; - } - else if (x > clipxmax - 5) { - clipxmax = min(COLNO, clipxmax + 20); - clipx = clipxmax - CO; - } - if (y < clipy + 2) { - clipy = max(0, y - (clipymax - clipy) / 2); - clipymax = clipy + (LI - 3); - } - else if (y > clipymax - 2) { - clipymax = min(ROWNO, clipymax + (clipymax - clipy) / 2); - clipy = clipymax - (LI - 3); - } - if (clipx != oldx || clipy != oldy) { - if (on_level(&u.uz0, &u.uz) && !restoring) - (void) doredraw(); - } + if (!clipping) + return; + if (x < clipx + 5) { + clipx = max(0, x - 20); + clipxmax = clipx + CO; + } else if (x > clipxmax - 5) { + clipxmax = min(COLNO, clipxmax + 20); + clipx = clipxmax - CO; + } + if (y < clipy + 2) { + clipy = max(0, y - (clipymax - clipy) / 2); + clipymax = clipy + (LI - 3); + } else if (y > clipymax - 2) { + clipymax = min(ROWNO, clipymax + (clipymax - clipy) / 2); + clipy = clipymax - (LI - 3); + } + if (clipx != oldx || clipy != oldy) { + if (on_level(&u.uz0, &u.uz) && !restoring) + (void) doredraw(); + } } #endif /* CLIPPING */ - /* * tty_print_glyph * @@ -2733,90 +2813,93 @@ int x, y; void tty_print_glyph(window, x, y, glyph) - winid window; - xchar x, y; - int glyph; +winid window; +xchar x, y; +int glyph; { int ch; boolean reverse_on = FALSE; - int color; + int color; unsigned special; - + #ifdef CLIPPING - if(clipping) { - if(x <= clipx || y < clipy || x >= clipxmax || y >= clipymax) - return; + if (clipping) { + if (x <= clipx || y < clipy || x >= clipxmax || y >= clipymax) + return; } #endif /* map glyph to character and color */ - (void)mapglyph(glyph, &ch, &color, &special, x, y); + (void) mapglyph(glyph, &ch, &color, &special, x, y); /* Move the cursor. */ - tty_curs(window, x,y); + tty_curs(window, x, y); #ifndef NO_TERMS - if (ul_hack && ch == '_') { /* non-destructive underscore */ - (void) putchar((char) ' '); - backsp(); + if (ul_hack && ch == '_') { /* non-destructive underscore */ + (void) putchar((char) ' '); + backsp(); } #endif #ifdef TEXTCOLOR if (color != ttyDisplay->color) { - if(ttyDisplay->color != NO_COLOR) - term_end_color(); - ttyDisplay->color = color; - if(color != NO_COLOR) - term_start_color(color); + if (ttyDisplay->color != NO_COLOR) + term_end_color(); + ttyDisplay->color = color; + if (color != NO_COLOR) + term_start_color(color); } #endif /* TEXTCOLOR */ /* must be after color check; term_end_color may turn off inverse too */ - if (((special & MG_PET) && iflags.hilite_pet) || - ((special & MG_DETECT) && iflags.use_inverse)) { - term_start_attr(ATR_INVERSE); - reverse_on = TRUE; + if (((special & MG_PET) && iflags.hilite_pet) + || ((special & MG_DETECT) && iflags.use_inverse)) { + term_start_attr(ATR_INVERSE); + reverse_on = TRUE; } #if defined(USE_TILES) && defined(MSDOS) if (iflags.grmode && iflags.tile_view) - xputg(glyph,ch,special); + xputg(glyph, ch, special); else #endif - g_putch(ch); /* print the character */ + g_putch(ch); /* print the character */ if (reverse_on) { - term_end_attr(ATR_INVERSE); + term_end_attr(ATR_INVERSE); #ifdef TEXTCOLOR - /* turn off color as well, ATR_INVERSE may have done this already */ - if(ttyDisplay->color != NO_COLOR) { - term_end_color(); - ttyDisplay->color = NO_COLOR; - } + /* turn off color as well, ATR_INVERSE may have done this already */ + if (ttyDisplay->color != NO_COLOR) { + term_end_color(); + ttyDisplay->color = NO_COLOR; + } #endif } - wins[window]->curx++; /* one character over */ - ttyDisplay->curx++; /* the real cursor moved too */ + wins[window]->curx++; /* one character over */ + ttyDisplay->curx++; /* the real cursor moved too */ } void tty_raw_print(str) - const char *str; +const char *str; { - if(ttyDisplay) ttyDisplay->rawprint++; + if (ttyDisplay) + ttyDisplay->rawprint++; #if defined(MICRO) || defined(WIN32CON) msmsg("%s\n", str); #else - puts(str); (void) fflush(stdout); + puts(str); + (void) fflush(stdout); #endif } void tty_raw_print_bold(str) - const char *str; +const char *str; { - if(ttyDisplay) ttyDisplay->rawprint++; + if (ttyDisplay) + ttyDisplay->rawprint++; term_start_raw_bold(); #if defined(MICRO) || defined(WIN32CON) msmsg("%s", str); @@ -2853,19 +2936,22 @@ tty_nhgetch() * here, but validate those pointers just in case... */ if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE]) - wins[WIN_MESSAGE]->flags &= ~WIN_STOP; + wins[WIN_MESSAGE]->flags &= ~WIN_STOP; #ifdef UNIX - i = ((++nesting == 1) ? tgetch() : - (read(fileno(stdin), (genericptr_t)&nestbuf,1) == 1 ? (int)nestbuf : - EOF)); + i = ((++nesting == 1) ? tgetch() : (read(fileno(stdin), + (genericptr_t) &nestbuf, 1) == 1 + ? (int) nestbuf + : EOF)); --nesting; #else i = tgetch(); #endif - if (!i) i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ - else if (i == EOF) i = '\033'; /* same for EOF */ + if (!i) + i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ + else if (i == EOF) + i = '\033'; /* same for EOF */ if (ttyDisplay && ttyDisplay->toplin == 1) - ttyDisplay->toplin = 2; + ttyDisplay->toplin = 2; return i; } @@ -2877,9 +2963,9 @@ tty_nhgetch() /*ARGSUSED*/ int tty_nh_poskey(x, y, mod) - int *x, *y, *mod; +int *x, *y, *mod; { -# if defined(WIN32CON) +#if defined(WIN32CON) int i; (void) fflush(stdout); /* Note: if raw_print() and wait_synch() get called to report terminal @@ -2888,26 +2974,28 @@ tty_nh_poskey(x, y, mod) * here, but validate those pointers just in case... */ if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE]) - wins[WIN_MESSAGE]->flags &= ~WIN_STOP; + wins[WIN_MESSAGE]->flags &= ~WIN_STOP; i = ntposkey(x, y, mod); if (!i && mod && (*mod == 0 || *mod == EOF)) - i = '\033'; /* map NUL or EOF to ESC, nethack doesn't expect either */ + i = '\033'; /* map NUL or EOF to ESC, nethack doesn't expect either */ if (ttyDisplay && ttyDisplay->toplin == 1) - ttyDisplay->toplin = 2; + ttyDisplay->toplin = 2; return i; -# else +#else return tty_nhgetch(); -# endif +#endif } void win_tty_init(dir) int dir; { - if(dir != WININIT) return; -# if defined(WIN32CON) - if (!strncmpi(windowprocs.name, "tty", 3)) nttty_open(0); -# endif + if (dir != WININIT) + return; +#if defined(WIN32CON) + if (!strncmpi(windowprocs.name, "tty", 3)) + nttty_open(0); +#endif return; } @@ -2916,9 +3004,9 @@ void tty_update_positionbar(posbar) char *posbar; { -# ifdef MSDOS - video_update_positionbar(posbar); -# endif +#ifdef MSDOS + video_update_positionbar(posbar); +#endif } #endif @@ -2930,9 +3018,10 @@ char *posbar; */ STATIC_OVL char * copy_of(s) - const char *s; +const char *s; { - if (!s) s = ""; + if (!s) + s = ""; return strcpy((char *) alloc((unsigned) (strlen(s) + 1)), s); } diff --git a/win/win32/mhaskyn.c b/win/win32/mhaskyn.c index d8a60ff3c..9e2987d65 100644 --- a/win/win32/mhaskyn.c +++ b/win/win32/mhaskyn.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhaskyn.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhaskyn.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */ /* NetHack 3.6 mhaskyn.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)mhaskyn.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -8,11 +8,11 @@ #include "winMS.h" #include "mhaskyn.h" -int mswin_yes_no_dialog( const char *question, const char *choices, int def) +int +mswin_yes_no_dialog(const char *question, const char *choices, int def) { - UNREFERENCED_PARAMETER(question); - UNREFERENCED_PARAMETER(choices); - UNREFERENCED_PARAMETER(def); - return '\032'; + UNREFERENCED_PARAMETER(question); + UNREFERENCED_PARAMETER(choices); + UNREFERENCED_PARAMETER(def); + return '\032'; } - diff --git a/win/win32/mhdlg.c b/win/win32/mhdlg.c index 30f43d0fd..0ea47fa75 100644 --- a/win/win32/mhdlg.c +++ b/win/win32/mhdlg.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhdlg.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhdlg.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */ /* NetHack 3.6 mhdlg.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.18 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -14,749 +14,797 @@ /*---------------------------------------------------------------*/ /* data for getlin dialog */ struct getlin_data { - const char* question; - char* result; - size_t result_size; + const char *question; + char *result; + size_t result_size; }; -INT_PTR CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); -int mswin_getlin_window ( - const char *question, - char *result, - size_t result_size -) +int +mswin_getlin_window(const char *question, char *result, size_t result_size) { - INT_PTR ret; - struct getlin_data data; + INT_PTR ret; + struct getlin_data data; - /* initilize dialog data */ - ZeroMemory(&data, sizeof(data)); - data.question = question; - data.result = result; - data.result_size = result_size; + /* initilize dialog data */ + ZeroMemory(&data, sizeof(data)); + data.question = question; + data.result = result; + data.result_size = result_size; - /* create modal dialog window */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_GETLIN), - GetNHApp()->hMainWnd, - GetlinDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create getlin window"); - - return (int)ret; -} - -INT_PTR CALLBACK GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - struct getlin_data* data; - RECT main_rt, dlg_rt; - SIZE dlg_sz; - TCHAR wbuf[BUFSZ]; - HDC WindowDC; - HWND ControlHWND; - SIZE WindowExtents; - SIZE ViewPortExtents; - RECT ControlRect; - RECT ClientRect; - LONG Division; - LONG ButtonOffset; + /* create modal dialog window */ + ret = DialogBoxParam(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_GETLIN), + GetNHApp()->hMainWnd, GetlinDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create getlin window"); - switch (message) - { - case WM_INITDIALOG: - data = (struct getlin_data*)lParam; - SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf))); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); - - /* center dialog in the main window */ - GetWindowRect(hWnd, &dlg_rt); - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - WindowDC = GetWindowDC(hWnd); - - if (!GetWindowExtEx(WindowDC, &WindowExtents) || - !GetViewportExtEx(WindowDC, &ViewPortExtents) || - !GetTextExtentPoint32(GetWindowDC (hWnd), wbuf, _tcslen(wbuf), &dlg_sz)) - { - dlg_sz.cx = 0; - } - else - { - /* I think we need to do the following scaling */ - dlg_sz.cx *= ViewPortExtents.cx; dlg_sz.cx /= WindowExtents.cx; - /* Add the size of the various items in the caption bar */ - dlg_sz.cx += GetSystemMetrics(SM_CXSIZE) + - 2 * (GetSystemMetrics (SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME)); - } - - if (dlg_sz.cx < dlg_rt.right - dlg_rt.left) - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); - - /* set focus and size of the edit control */ - ControlHWND = GetDlgItem(hWnd, IDC_GETLIN_EDIT); - SetFocus(ControlHWND); - GetClientRect (hWnd, &ClientRect); - GetWindowRect (ControlHWND, &ControlRect); - MoveWindow (ControlHWND, 0, 0, - ClientRect.right - ClientRect.left, - ControlRect.bottom - ControlRect.top, TRUE); - ButtonOffset = ControlRect.bottom - ControlRect.top; - - /* Now get the OK and CANCEL buttons */ - ControlHWND = GetDlgItem(hWnd, IDOK); - GetWindowRect (ControlHWND, &ControlRect); - Division = ((ClientRect.right - ClientRect.left) - - 2 * (ControlRect.right - ControlRect.left)) / 3; - MoveWindow (ControlHWND, Division, - ButtonOffset, - ControlRect.right - ControlRect.left, - ControlRect.bottom - ControlRect.top, TRUE); - ControlHWND = GetDlgItem(hWnd, IDCANCEL); - MoveWindow (ControlHWND, - Division * 2 + ControlRect.right - ControlRect.left, - ButtonOffset, - ControlRect.right - ControlRect.left, - ControlRect.bottom - ControlRect.top, TRUE); - - /* tell windows that we've set the focus */ - return FALSE; - break; - - case WM_COMMAND: - { - TCHAR wbuf[BUFSZ]; - - switch (LOWORD(wParam)) - { - /* OK button was pressed */ - case IDOK: - data = (struct getlin_data*)GetWindowLongPtr(hWnd, GWLP_USERDATA); - SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, (WPARAM)sizeof(wbuf), (LPARAM)wbuf ); - NH_W2A(wbuf, data->result, data->result_size); - - /* Fall through. */ - - /* cancel button was pressed */ - case IDCANCEL: - EndDialog(hWnd, wParam); - return TRUE; - } - } break; - - } /* end switch (message) */ - return FALSE; + return (int) ret; } +INT_PTR CALLBACK +GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + struct getlin_data *data; + RECT main_rt, dlg_rt; + SIZE dlg_sz; + TCHAR wbuf[BUFSZ]; + HDC WindowDC; + HWND ControlHWND; + SIZE WindowExtents; + SIZE ViewPortExtents; + RECT ControlRect; + RECT ClientRect; + LONG Division; + LONG ButtonOffset; + + switch (message) { + case WM_INITDIALOG: + data = (struct getlin_data *) lParam; + SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf))); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); + + /* center dialog in the main window */ + GetWindowRect(hWnd, &dlg_rt); + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + WindowDC = GetWindowDC(hWnd); + + if (!GetWindowExtEx(WindowDC, &WindowExtents) + || !GetViewportExtEx(WindowDC, &ViewPortExtents) + || !GetTextExtentPoint32(GetWindowDC(hWnd), wbuf, _tcslen(wbuf), + &dlg_sz)) { + dlg_sz.cx = 0; + } else { + /* I think we need to do the following scaling */ + dlg_sz.cx *= ViewPortExtents.cx; + dlg_sz.cx /= WindowExtents.cx; + /* Add the size of the various items in the caption bar */ + dlg_sz.cx += GetSystemMetrics(SM_CXSIZE) + + 2 * (GetSystemMetrics(SM_CXBORDER) + + GetSystemMetrics(SM_CXFRAME)); + } + + if (dlg_sz.cx < dlg_rt.right - dlg_rt.left) + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); + + /* set focus and size of the edit control */ + ControlHWND = GetDlgItem(hWnd, IDC_GETLIN_EDIT); + SetFocus(ControlHWND); + GetClientRect(hWnd, &ClientRect); + GetWindowRect(ControlHWND, &ControlRect); + MoveWindow(ControlHWND, 0, 0, ClientRect.right - ClientRect.left, + ControlRect.bottom - ControlRect.top, TRUE); + ButtonOffset = ControlRect.bottom - ControlRect.top; + + /* Now get the OK and CANCEL buttons */ + ControlHWND = GetDlgItem(hWnd, IDOK); + GetWindowRect(ControlHWND, &ControlRect); + Division = ((ClientRect.right - ClientRect.left) + - 2 * (ControlRect.right - ControlRect.left)) / 3; + MoveWindow(ControlHWND, Division, ButtonOffset, + ControlRect.right - ControlRect.left, + ControlRect.bottom - ControlRect.top, TRUE); + ControlHWND = GetDlgItem(hWnd, IDCANCEL); + MoveWindow(ControlHWND, + Division * 2 + ControlRect.right - ControlRect.left, + ButtonOffset, ControlRect.right - ControlRect.left, + ControlRect.bottom - ControlRect.top, TRUE); + + /* tell windows that we've set the focus */ + return FALSE; + break; + + case WM_COMMAND: { + TCHAR wbuf[BUFSZ]; + + switch (LOWORD(wParam)) { + /* OK button was pressed */ + case IDOK: + data = + (struct getlin_data *) GetWindowLongPtr(hWnd, GWLP_USERDATA); + SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, + (WPARAM) sizeof(wbuf), (LPARAM) wbuf); + NH_W2A(wbuf, data->result, data->result_size); + + /* Fall through. */ + + /* cancel button was pressed */ + case IDCANCEL: + EndDialog(hWnd, wParam); + return TRUE; + } + } break; + + } /* end switch (message) */ + return FALSE; +} /*---------------------------------------------------------------*/ /* dialog data for the list of extended commands */ struct extcmd_data { - int* selection; + int *selection; }; -INT_PTR CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM); -int mswin_ext_cmd_window (int* selection) +int +mswin_ext_cmd_window(int *selection) { - INT_PTR ret; - struct extcmd_data data; - - /* init dialog data */ - ZeroMemory(&data, sizeof(data)); - *selection = -1; - data.selection = selection; + INT_PTR ret; + struct extcmd_data data; - /* create modal dialog window */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_EXTCMD), - GetNHApp()->hMainWnd, - ExtCmdDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create extcmd window"); - return (int)ret; + /* init dialog data */ + ZeroMemory(&data, sizeof(data)); + *selection = -1; + data.selection = selection; + + /* create modal dialog window */ + ret = DialogBoxParam(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_EXTCMD), + GetNHApp()->hMainWnd, ExtCmdDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create extcmd window"); + return (int) ret; } - -INT_PTR CALLBACK ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +INT_PTR CALLBACK +ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - struct extcmd_data* data; - RECT main_rt, dlg_rt; - SIZE dlg_sz; - int i; - TCHAR wbuf[255]; + struct extcmd_data *data; + RECT main_rt, dlg_rt; + SIZE dlg_sz; + int i; + TCHAR wbuf[255]; - switch (message) - { - case WM_INITDIALOG: - data = (struct extcmd_data*)lParam; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + switch (message) { + case WM_INITDIALOG: + data = (struct extcmd_data *) lParam; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hWnd, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hWnd, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - /* fill combobox with extended commands */ - for(i=0; extcmdlist[i].ef_txt; i++) { - SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(extcmdlist[i].ef_txt, wbuf, sizeof(wbuf)) ); - } + /* fill combobox with extended commands */ + for (i = 0; extcmdlist[i].ef_txt; i++) { + SendDlgItemMessage( + hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(extcmdlist[i].ef_txt, wbuf, sizeof(wbuf))); + } - /* set focus to the list control */ - SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST)); + /* set focus to the list control */ + SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST)); - /* tell windows we set the focus */ - return FALSE; - break; + /* tell windows we set the focus */ + return FALSE; + break; - case WM_COMMAND: - data = (struct extcmd_data*)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (LOWORD(wParam)) - { - /* OK button ws clicked */ - case IDOK: - *data->selection = (int)SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); - if( *data->selection==LB_ERR ) - *data->selection = -1; - /* Fall through. */ + case WM_COMMAND: + data = (struct extcmd_data *) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (LOWORD(wParam)) { + /* OK button ws clicked */ + case IDOK: + *data->selection = (int) SendDlgItemMessage( + hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + if (*data->selection == LB_ERR) + *data->selection = -1; + /* Fall through. */ - /* CANCEL button ws clicked */ - case IDCANCEL: - EndDialog(hWnd, wParam); - return TRUE; + /* CANCEL button ws clicked */ + case IDCANCEL: + EndDialog(hWnd, wParam); + return TRUE; - /* list control events */ - case IDC_EXTCMD_LIST: - switch(HIWORD(wParam)) { - - case LBN_DBLCLK: - /* double click within the list - wParam - The low-order word is the list box identifier. - The high-order word is the notification message. - lParam - Handle to the list box - */ - *data->selection = (int)SendMessage((HWND)lParam, LB_GETCURSEL, (WPARAM)0, (LPARAM)0); - if( *data->selection==LB_ERR ) - *data->selection = -1; - EndDialog(hWnd, IDOK); - return TRUE; - } - break; - } - } - return FALSE; + /* list control events */ + case IDC_EXTCMD_LIST: + switch (HIWORD(wParam)) { + case LBN_DBLCLK: + /* double click within the list + wParam + The low-order word is the list box identifier. + The high-order word is the notification message. + lParam + Handle to the list box + */ + *data->selection = (int) SendMessage( + (HWND) lParam, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + if (*data->selection == LB_ERR) + *data->selection = -1; + EndDialog(hWnd, IDOK); + return TRUE; + } + break; + } + } + return FALSE; } /*---------------------------------------------------------------*/ /* player selector dialog data */ struct plsel_data { - int* selection; + int *selection; }; -INT_PTR CALLBACK PlayerSelectorDlgProc(HWND, UINT, WPARAM, LPARAM); -static void plselInitDialog(HWND hWnd); -static void plselAdjustLists(HWND hWnd, int changed_opt); -static int plselFinalSelection(HWND hWnd, int* selection); +INT_PTR CALLBACK PlayerSelectorDlgProc(HWND, UINT, WPARAM, LPARAM); +static void plselInitDialog(HWND hWnd); +static void plselAdjustLists(HWND hWnd, int changed_opt); +static int plselFinalSelection(HWND hWnd, int *selection); -int mswin_player_selection_window ( int* selection ) +int +mswin_player_selection_window(int *selection) { - INT_PTR ret; - struct plsel_data data; + INT_PTR ret; + struct plsel_data data; - /* init dialog data */ - ZeroMemory(&data, sizeof(data)); - data.selection = selection; + /* init dialog data */ + ZeroMemory(&data, sizeof(data)); + data.selection = selection; - /* create modal dialog */ - ret = DialogBoxParam( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_PLAYER_SELECTOR), - GetNHApp()->hMainWnd, - PlayerSelectorDlgProc, - (LPARAM)&data - ); - if( ret==-1 ) panic("Cannot create getlin window"); - - return (int)ret; + /* create modal dialog */ + ret = DialogBoxParam( + GetNHApp()->hApp, MAKEINTRESOURCE(IDD_PLAYER_SELECTOR), + GetNHApp()->hMainWnd, PlayerSelectorDlgProc, (LPARAM) &data); + if (ret == -1) + panic("Cannot create getlin window"); + + return (int) ret; } -INT_PTR CALLBACK PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK +PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - struct plsel_data* data; - RECT main_rt, dlg_rt; - SIZE dlg_sz; + struct plsel_data *data; + RECT main_rt, dlg_rt; + SIZE dlg_sz; - switch (message) - { - case WM_INITDIALOG: - data = (struct plsel_data*)lParam; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + switch (message) { + case WM_INITDIALOG: + data = (struct plsel_data *) lParam; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hWnd, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hWnd, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hWnd, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - /* init dialog */ - plselInitDialog(hWnd); + /* init dialog */ + plselInitDialog(hWnd); - /* set focus on the role checkbox (random) field */ - SetFocus(GetDlgItem(hWnd, IDC_PLSEL_ROLE_RANDOM)); + /* set focus on the role checkbox (random) field */ + SetFocus(GetDlgItem(hWnd, IDC_PLSEL_ROLE_RANDOM)); - /* tell windows we set the focus */ - return FALSE; - break; + /* tell windows we set the focus */ + return FALSE; + break; - case WM_COMMAND: - data = (struct plsel_data*)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (LOWORD(wParam)) { + case WM_COMMAND: + data = (struct plsel_data *) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (LOWORD(wParam)) { + /* OK button was clicked */ + case IDOK: + if (plselFinalSelection(hWnd, data->selection)) { + EndDialog(hWnd, wParam); + } else { + NHMessageBox( + hWnd, TEXT("Cannot match this role. Try something else."), + MB_ICONSTOP | MB_OK); + } + return TRUE; - /* OK button was clicked */ - case IDOK: - if( plselFinalSelection(hWnd, data->selection) ) { - EndDialog(hWnd, wParam); - } else { - NHMessageBox(hWnd, TEXT("Cannot match this role. Try something else."), MB_ICONSTOP | MB_OK ); - } - return TRUE; + /* CANCEL button was clicked */ + case IDCANCEL: + *data->selection = -1; + EndDialog(hWnd, wParam); + return TRUE; - /* CANCEL button was clicked */ - case IDCANCEL: - *data->selection = -1; - EndDialog(hWnd, wParam); - return TRUE; + /* following are events from dialog controls: + "random" checkboxes send BN_CLICKED messages; + role/race/... combo-boxes send CBN_SELENDOK + if something was selected; + */ + case IDC_PLSEL_ROLE_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + /* enable corresponding list window if "random" + checkbox was "unchecked" */ + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - /* following are events from dialog controls: - "random" checkboxes send BN_CLICKED messages; - role/race/... combo-boxes send CBN_SELENDOK - if something was selected; - */ - case IDC_PLSEL_ROLE_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - /* enable corresponding list window if "random" - checkbox was "unchecked" */ - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_RACE_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_RACE_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_GENDER_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_GENDER_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_ALIGN_RANDOM: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), + SendMessage((HWND) lParam, BM_GETCHECK, 0, 0) + == BST_UNCHECKED); + } + break; - case IDC_PLSEL_ALIGN_RANDOM: - if( HIWORD(wParam)==BN_CLICKED ) { - EnableWindow( - GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), - SendMessage((HWND)lParam, BM_GETCHECK, 0, 0)==BST_UNCHECKED - ); - } - break; + case IDC_PLSEL_ROLE_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + /* filter out invalid options if + the selection was made */ + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_ROLE_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - /* filter out invalid options if - the selection was made */ - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; + case IDC_PLSEL_RACE_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_RACE_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; + case IDC_PLSEL_GENDER_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; - case IDC_PLSEL_GENDER_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; - - case IDC_PLSEL_ALIGN_LIST: - if( HIWORD(wParam)==CBN_SELENDOK ) { - plselAdjustLists( hWnd, LOWORD(wParam) ); - } - break; - } - break; - } - return FALSE; + case IDC_PLSEL_ALIGN_LIST: + if (HIWORD(wParam) == CBN_SELENDOK) { + plselAdjustLists(hWnd, LOWORD(wParam)); + } + break; + } + break; + } + return FALSE; } -void setComboBoxValue(HWND hWnd, int combo_box, int value) +void +setComboBoxValue(HWND hWnd, int combo_box, int value) { - int index_max = (int)SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); - int index; - int value_to_set = LB_ERR; - for (index = 0; index < index_max; index++) { - if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, (WPARAM)index, 0) == value) { - value_to_set = index; - break; - } - } - SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM)value_to_set, 0); + int index_max = + (int) SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); + int index; + int value_to_set = LB_ERR; + for (index = 0; index < index_max; index++) { + if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, + (WPARAM) index, 0) == value) { + value_to_set = index; + break; + } + } + SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM) value_to_set, + 0); } /* initialize player selector dialog */ -void plselInitDialog(HWND hWnd) +void +plselInitDialog(HWND hWnd) { - TCHAR wbuf[BUFSZ]; + TCHAR wbuf[BUFSZ]; - /* set player name */ - SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf))); + /* set player name */ + SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf))); - /* check flags for consistency */ - if( flags.initrole>=0 ) { - if (flags.initrace>=0 && !validrace(flags.initrole, flags.initrace)) { - flags.initrace = ROLE_NONE; - } + /* check flags for consistency */ + if (flags.initrole >= 0) { + if (flags.initrace >= 0 + && !validrace(flags.initrole, flags.initrace)) { + flags.initrace = ROLE_NONE; + } - if (flags.initgend>=0 && !validgend(flags.initrole, flags.initrace, flags.initgend)) { - flags.initgend = ROLE_NONE; - } + if (flags.initgend >= 0 + && !validgend(flags.initrole, flags.initrace, flags.initgend)) { + flags.initgend = ROLE_NONE; + } - if (flags.initalign>=0 && !validalign(flags.initrole, flags.initrace, flags.initalign)) { - flags.initalign = ROLE_NONE; - } - } + if (flags.initalign >= 0 + && !validalign(flags.initrole, flags.initrace, flags.initalign)) { + flags.initalign = ROLE_NONE; + } + } - /* populate select boxes */ - plselAdjustLists(hWnd, -1); + /* populate select boxes */ + plselAdjustLists(hWnd, -1); - /* intialize roles list */ - if( flags.initrole<0 || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) { - CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); - } + /* intialize roles list */ + if (flags.initrole < 0 + || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); + } - /* intialize races list */ - if( flags.initrace<0 || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE) ) { - CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); - } + /* intialize races list */ + if (flags.initrace < 0 + || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); + } - /* intialize genders list */ - if( flags.initgend<0 || !ok_gend(flags.initrole, flags.initrace, flags.initgend, ROLE_NONE)) { - CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); - } + /* intialize genders list */ + if (flags.initgend < 0 + || !ok_gend(flags.initrole, flags.initrace, flags.initgend, + ROLE_NONE)) { + CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); + } - /* intialize alignments list */ - if( flags.initalign<0 || !ok_align(flags.initrole, flags.initrace, flags.initgend, flags.initalign) ) { - CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE); - } else { - CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); - EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); - setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); - } + /* intialize alignments list */ + if (flags.initalign < 0 + || !ok_align(flags.initrole, flags.initrace, flags.initgend, + flags.initalign)) { + CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE); + } else { + CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); + EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); + setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); + } } /* adjust role/race/alignment/gender list - filter out - invalid combinations + invalid combinations changed_sel points to the list where selection occured (-1 if unknown) */ -void plselAdjustLists(HWND hWnd, int changed_sel) +void +plselAdjustLists(HWND hWnd, int changed_sel) { - HWND control_role, control_race, control_gender, control_align; - int initrole, initrace, initgend, initalign; - int i; - LRESULT ind; - int valid_opt; - TCHAR wbuf[255]; + HWND control_role, control_race, control_gender, control_align; + int initrole, initrace, initgend, initalign; + int i; + LRESULT ind; + int valid_opt; + TCHAR wbuf[255]; - /* get control handles */ - control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST); - control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST); - control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST); - control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST); + /* get control handles */ + control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST); + control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST); + control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST); + control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST); - /* get current selections */ - ind = SendMessage(control_role, CB_GETCURSEL, 0, 0); - initrole = (ind==LB_ERR)? flags.initrole : (int)SendMessage(control_role, CB_GETITEMDATA, ind, 0); + /* get current selections */ + ind = SendMessage(control_role, CB_GETCURSEL, 0, 0); + initrole = (ind == LB_ERR) + ? flags.initrole + : (int) SendMessage(control_role, CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_race, CB_GETCURSEL, 0, 0); - initrace = (ind==LB_ERR)? flags.initrace : (int)SendMessage(control_race, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_race, CB_GETCURSEL, 0, 0); + initrace = (ind == LB_ERR) + ? flags.initrace + : (int) SendMessage(control_race, CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0); - initgend = (ind==LB_ERR)? flags.initgend : (int)SendMessage(control_gender, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0); + initgend = (ind == LB_ERR) ? flags.initgend + : (int) SendMessage(control_gender, + CB_GETITEMDATA, ind, 0); - ind = SendMessage(control_align, CB_GETCURSEL, 0, 0); - initalign = (ind==LB_ERR)? flags.initalign : (int)SendMessage(control_align, CB_GETITEMDATA, ind, 0); + ind = SendMessage(control_align, CB_GETCURSEL, 0, 0); + initalign = (ind == LB_ERR) ? flags.initalign + : (int) SendMessage(control_align, + CB_GETITEMDATA, ind, 0); - /* intialize roles list */ - if( changed_sel==-1 ) { - valid_opt = 0; + /* intialize roles list */ + if (changed_sel == -1) { + valid_opt = 0; - /* reset content and populate the list */ - SendMessage(control_role, CB_RESETCONTENT, 0, 0); - for (i = 0; roles[i].name.m; i++) { - if (initgend>=0 && flags.female && roles[i].name.f) - ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) ); - else - ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) ); + /* reset content and populate the list */ + SendMessage(control_role, CB_RESETCONTENT, 0, 0); + for (i = 0; roles[i].name.m; i++) { + if (initgend >= 0 && flags.female && roles[i].name.f) + ind = SendMessage( + control_role, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf))); + else + ind = SendMessage( + control_role, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf))); - SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initrole ) { - SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } - - /* set selection to the previously selected role - if it is still valid */ - if( !valid_opt ) { - initrole = ROLE_NONE; - initrace = ROLE_NONE; - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_role, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + SendMessage(control_role, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initrole) { + SendMessage(control_role, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } - /* trigger change of the races list */ - changed_sel=IDC_PLSEL_ROLE_LIST; - } + /* set selection to the previously selected role + if it is still valid */ + if (!valid_opt) { + initrole = ROLE_NONE; + initrace = ROLE_NONE; + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_role, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } - /* intialize races list */ - if( changed_sel==IDC_PLSEL_ROLE_LIST ) { - valid_opt = 0; + /* trigger change of the races list */ + changed_sel = IDC_PLSEL_ROLE_LIST; + } - /* reset content and populate the list */ - SendMessage(control_race, CB_RESETCONTENT, 0, 0); - for (i = 0; races[i].noun; i++) - if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) { - ind = SendMessage(control_race, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(races[i].noun, wbuf, sizeof(wbuf)) ); - SendMessage(control_race, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initrace ) { - SendMessage(control_race, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize races list */ + if (changed_sel == IDC_PLSEL_ROLE_LIST) { + valid_opt = 0; - /* set selection to the previously selected race - if it is still valid */ - if( !valid_opt ) { - initrace = ROLE_NONE; - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_race, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + /* reset content and populate the list */ + SendMessage(control_race, CB_RESETCONTENT, 0, 0); + for (i = 0; races[i].noun; i++) + if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) { + ind = SendMessage( + control_race, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(races[i].noun, wbuf, sizeof(wbuf))); + SendMessage(control_race, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initrace) { + SendMessage(control_race, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } - /* trigger change of the genders list */ - changed_sel=IDC_PLSEL_RACE_LIST; - } + /* set selection to the previously selected race + if it is still valid */ + if (!valid_opt) { + initrace = ROLE_NONE; + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_race, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } - /* intialize genders list */ - if( changed_sel==IDC_PLSEL_RACE_LIST ) { - valid_opt = 0; + /* trigger change of the genders list */ + changed_sel = IDC_PLSEL_RACE_LIST; + } - /* reset content and populate the list */ - SendMessage(control_gender, CB_RESETCONTENT, 0, 0); - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(initrole, initrace, i, ROLE_NONE)) { - ind = SendMessage(control_gender, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(genders[i].adj, wbuf, sizeof(wbuf)) ); - SendMessage(control_gender, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initgend ) { - SendMessage(control_gender, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize genders list */ + if (changed_sel == IDC_PLSEL_RACE_LIST) { + valid_opt = 0; - /* set selection to the previously selected gender - if it is still valid */ - if( !valid_opt ) { - initgend = ROLE_NONE; - initalign = ROLE_NONE; - SendMessage(control_gender, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } + /* reset content and populate the list */ + SendMessage(control_gender, CB_RESETCONTENT, 0, 0); + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(initrole, initrace, i, ROLE_NONE)) { + ind = SendMessage( + control_gender, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(genders[i].adj, wbuf, sizeof(wbuf))); + SendMessage(control_gender, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initgend) { + SendMessage(control_gender, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } - /* trigger change of the alignments list */ - changed_sel=IDC_PLSEL_GENDER_LIST; - } + /* set selection to the previously selected gender + if it is still valid */ + if (!valid_opt) { + initgend = ROLE_NONE; + initalign = ROLE_NONE; + SendMessage(control_gender, CB_SETCURSEL, (WPARAM) -1, + (LPARAM) 0); + } - /* intialize alignments list */ - if( changed_sel==IDC_PLSEL_GENDER_LIST ) { - valid_opt = 0; + /* trigger change of the alignments list */ + changed_sel = IDC_PLSEL_GENDER_LIST; + } - /* reset content and populate the list */ - SendMessage(control_align, CB_RESETCONTENT, 0, 0); - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(initrole, initrace, initgend, i)) { - ind = SendMessage(control_align, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf)) ); - SendMessage(control_align, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i ); - if( i==initalign ) { - SendMessage(control_align, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 ); - valid_opt = 1; - } - } + /* intialize alignments list */ + if (changed_sel == IDC_PLSEL_GENDER_LIST) { + valid_opt = 0; - /* set selection to the previously selected alignment - if it is still valid */ - if( !valid_opt ) { - initalign = ROLE_NONE; - SendMessage(control_align, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0 ); - } - } + /* reset content and populate the list */ + SendMessage(control_align, CB_RESETCONTENT, 0, 0); + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(initrole, initrace, initgend, i)) { + ind = SendMessage( + control_align, CB_ADDSTRING, (WPARAM) 0, + (LPARAM) NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf))); + SendMessage(control_align, CB_SETITEMDATA, (WPARAM) ind, + (LPARAM) i); + if (i == initalign) { + SendMessage(control_align, CB_SETCURSEL, (WPARAM) ind, + (LPARAM) 0); + valid_opt = 1; + } + } + + /* set selection to the previously selected alignment + if it is still valid */ + if (!valid_opt) { + initalign = ROLE_NONE; + SendMessage(control_align, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + } + } } -/* player made up his mind - get final selection here */ -int plselFinalSelection(HWND hWnd, int* selection) +/* player made up his mind - get final selection here */ +int +plselFinalSelection(HWND hWnd, int *selection) { - LRESULT ind; + LRESULT ind; - UNREFERENCED_PARAMETER(selection); + UNREFERENCED_PARAMETER(selection); - /* get current selections */ - if( SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initrole = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETCURSEL, 0, 0); - flags.initrole = (ind==LB_ERR)? ROLE_RANDOM : (int)SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETITEMDATA, ind, 0); - } + /* get current selections */ + if (SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initrole = ROLE_RANDOM; + } else { + ind = + SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_GETCURSEL, 0, 0); + flags.initrole = + (ind == LB_ERR) + ? ROLE_RANDOM + : (int) SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initrace = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETCURSEL, 0, 0); - flags.initrace = (ind==LB_ERR)? ROLE_RANDOM : (int)SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETITEMDATA, ind, 0); - } + if (SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initrace = ROLE_RANDOM; + } else { + ind = + SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_GETCURSEL, 0, 0); + flags.initrace = + (ind == LB_ERR) + ? ROLE_RANDOM + : (int) SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initgend = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETCURSEL, 0, 0); - flags.initgend = (ind==LB_ERR)? ROLE_RANDOM : (int)SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETITEMDATA, ind, 0); - } + if (SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initgend = ROLE_RANDOM; + } else { + ind = SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_GETCURSEL, 0, + 0); + flags.initgend = + (ind == LB_ERR) + ? ROLE_RANDOM + : (int) SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, + CB_GETITEMDATA, ind, 0); + } - if( SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_RANDOM, BM_GETCHECK, 0, 0)==BST_CHECKED ) { - flags.initalign = ROLE_RANDOM; - } else { - ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETCURSEL, 0, 0); - flags.initalign = (ind==LB_ERR)? ROLE_RANDOM : (int)SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETITEMDATA, ind, 0); - } - + if (SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_RANDOM, BM_GETCHECK, 0, 0) + == BST_CHECKED) { + flags.initalign = ROLE_RANDOM; + } else { + ind = SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_GETCURSEL, 0, + 0); + flags.initalign = + (ind == LB_ERR) + ? ROLE_RANDOM + : (int) SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, + CB_GETITEMDATA, ind, 0); + } - /* check the role */ - if( flags.initrole==ROLE_RANDOM ) { - flags.initrole = pick_role(flags.initrace, flags.initgend, flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - NHMessageBox(hWnd, TEXT("Incompatible role!"), MB_ICONSTOP | MB_OK); - return FALSE; - } - } + /* check the role */ + if (flags.initrole == ROLE_RANDOM) { + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + NHMessageBox(hWnd, TEXT("Incompatible role!"), + MB_ICONSTOP | MB_OK); + return FALSE; + } + } - /* Select a race, if necessary */ - /* force compatibility with role */ - if (flags.initrace==ROLE_RANDOM || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (flags.initrace == ROLE_RANDOM) { - flags.initrace = pick_race(flags.initrole, flags.initgend, flags.initalign, PICK_RANDOM); - } - - if (flags.initrace < 0) { - NHMessageBox(hWnd, TEXT("Incompatible race!"), MB_ICONSTOP | MB_OK); - return FALSE; - } - } + /* Select a race, if necessary */ + /* force compatibility with role */ + if (flags.initrace == ROLE_RANDOM + || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (flags.initrace == ROLE_RANDOM) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + } - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || - !validgend(flags.initrole, flags.initrace, flags.initgend)) { - /* pre-selected gender not valid */ - if (flags.initgend == ROLE_RANDOM) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, flags.initalign, PICK_RANDOM); - } - - if (flags.initgend < 0) { - NHMessageBox(hWnd, TEXT("Incompatible gender!"), MB_ICONSTOP | MB_OK); - return FALSE; - } - } + if (flags.initrace < 0) { + NHMessageBox(hWnd, TEXT("Incompatible race!"), + MB_ICONSTOP | MB_OK); + return FALSE; + } + } - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || - !validalign(flags.initrole, flags.initrace, flags.initalign)) { - /* pre-selected alignment not valid */ - if (flags.initalign == ROLE_RANDOM) { - flags.initalign = pick_align(flags.initrole, flags.initrace, flags.initgend, PICK_RANDOM); - } else { - NHMessageBox(hWnd, TEXT("Incompatible alignment!"), MB_ICONSTOP | MB_OK); - return FALSE; - } - } + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (flags.initgend == ROLE_RANDOM) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + } - return TRUE; + if (flags.initgend < 0) { + NHMessageBox(hWnd, TEXT("Incompatible gender!"), + MB_ICONSTOP | MB_OK); + return FALSE; + } + } + + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (flags.initalign == ROLE_RANDOM) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + } else { + NHMessageBox(hWnd, TEXT("Incompatible alignment!"), + MB_ICONSTOP | MB_OK); + return FALSE; + } + } + + return TRUE; } - diff --git a/win/win32/mhfont.c b/win/win32/mhfont.c index 5b5c79737..ac1a1832e 100644 --- a/win/win32/mhfont.c +++ b/win/win32/mhfont.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhfont.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhfont.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */ /* NetHack 3.6 mhfont.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.17 $ */ /* SCCS Id: @(#)mhfont.c 3.5 2005/01/23 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -8,201 +8,221 @@ #include "mhfont.h" -#define MAXFONTS 64 +#define MAXFONTS 64 /* font table - 64 fonts ought to be enough */ static struct font_table_entry { - int code; - HFONT hFont; -} font_table[MAXFONTS] ; + int code; + HFONT hFont; +} font_table[MAXFONTS]; static int font_table_size = 0; HFONT version_splash_font; -#define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF)) +#define NHFONT_CODE(win, attr) (((attr & 0xFF) << 8) | (win_type & 0xFF)) static void __cdecl font_table_cleanup(void); -void mswin_init_splashfonts(HWND hWnd) +void +mswin_init_splashfonts(HWND hWnd) { - HDC hdc = GetDC(hWnd); - LOGFONT lgfnt; - ZeroMemory( &lgfnt, sizeof(lgfnt) ); - lgfnt.lfHeight = -80; // height of font - lgfnt.lfWidth = 0; // average character width - lgfnt.lfEscapement = 0; // angle of escapement - lgfnt.lfOrientation = 0; // base-line orientation angle - lgfnt.lfWeight = FW_BOLD; // font weight - lgfnt.lfItalic = FALSE; // italic attribute option - lgfnt.lfUnderline = FALSE; // underline attribute option - lgfnt.lfStrikeOut = FALSE; // strikeout attribute option - lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier - lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision - lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision - lgfnt.lfQuality = DEFAULT_QUALITY; // output quality - lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family - NH_A2W( "Times New Roman", lgfnt.lfFaceName, LF_FACESIZE); - version_splash_font = CreateFontIndirect(&lgfnt); - ReleaseDC(hWnd, hdc); + HDC hdc = GetDC(hWnd); + LOGFONT lgfnt; + ZeroMemory(&lgfnt, sizeof(lgfnt)); + lgfnt.lfHeight = -80; // height of font + lgfnt.lfWidth = 0; // average character width + lgfnt.lfEscapement = 0; // angle of escapement + lgfnt.lfOrientation = 0; // base-line orientation angle + lgfnt.lfWeight = FW_BOLD; // font weight + lgfnt.lfItalic = FALSE; // italic attribute option + lgfnt.lfUnderline = FALSE; // underline attribute option + lgfnt.lfStrikeOut = FALSE; // strikeout attribute option + lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier + lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision + lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision + lgfnt.lfQuality = DEFAULT_QUALITY; // output quality + lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family + NH_A2W("Times New Roman", lgfnt.lfFaceName, LF_FACESIZE); + version_splash_font = CreateFontIndirect(&lgfnt); + ReleaseDC(hWnd, hdc); } -void mswin_destroy_splashfonts() +void +mswin_destroy_splashfonts() { - DeleteObject (version_splash_font); + DeleteObject(version_splash_font); } /* create font based on window type, charater attributes and window device context */ -HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) +HGDIOBJ +mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) { - HFONT fnt = NULL; - LOGFONT lgfnt; - int font_size; - int font_index; - static BOOL once = FALSE; + HFONT fnt = NULL; + LOGFONT lgfnt; + int font_size; + int font_index; + static BOOL once = FALSE; - if( !once ) { - once = TRUE; - atexit(font_table_cleanup); - } + if (!once) { + once = TRUE; + atexit(font_table_cleanup); + } - ZeroMemory( &lgfnt, sizeof(lgfnt) ); + ZeroMemory(&lgfnt, sizeof(lgfnt)); - /* try find font in the table */ - for(font_index=0; font_index=MAXFONTS ) panic( "font table overflow!" ); - font_table_size++; - } else { - DeleteObject(font_table[font_index].hFont); - } + /* add font to the table */ + if (font_index == font_table_size) { + if (font_table_size >= MAXFONTS) + panic("font table overflow!"); + font_table_size++; + } else { + DeleteObject(font_table[font_index].hFont); + } - font_table[font_index].code = NHFONT_CODE(win_type, attr); - font_table[font_index].hFont = fnt; - return fnt; + font_table[font_index].code = NHFONT_CODE(win_type, attr); + font_table[font_index].hFont = fnt; + return fnt; } -UINT mswin_charset() +UINT +mswin_charset() { - CHARSETINFO cis; - if( SYMHANDLING(H_IBM) ) - if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) ) - return cis.ciCharset; - else - return OEM_CHARSET; - else - if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) ) - return cis.ciCharset; - else - return ANSI_CHARSET; + CHARSETINFO cis; + if (SYMHANDLING(H_IBM)) + if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE)) + return cis.ciCharset; + else + return OEM_CHARSET; + else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE)) + return cis.ciCharset; + else + return ANSI_CHARSET; } void __cdecl font_table_cleanup(void) { - int i; - for(i=0; ihApp, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - register_main_window_class( ); - run_once = 1; - } - - /* create the main window */ - ret = CreateWindow( - szMainWindowClass, /* registered class name */ - szTitle, /* window name */ - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, /* window style */ - CW_USEDEFAULT, /* horizontal position of window */ - CW_USEDEFAULT, /* vertical position of window */ - CW_USEDEFAULT, /* window width */ - CW_USEDEFAULT, /* window height */ - NULL, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL /* window-creation data */ - ); + /* register window class */ + if (!run_once) { + LoadString(GetNHApp()->hApp, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + register_main_window_class(); + run_once = 1; + } - if( !ret ) panic("Cannot create main window"); + /* create the main window */ + ret = + CreateWindow(szMainWindowClass, /* registered class name */ + szTitle, /* window name */ + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, /* window style */ + CW_USEDEFAULT, /* horizontal position of window */ + CW_USEDEFAULT, /* vertical position of window */ + CW_USEDEFAULT, /* window width */ + CW_USEDEFAULT, /* window height */ + NULL, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL /* window-creation data */ + ); - - if (GetNHApp()->regMainMinX != CW_USEDEFAULT) - { + if (!ret) + panic("Cannot create main window"); + + if (GetNHApp()->regMainMinX != CW_USEDEFAULT) { wp.length = sizeof(wp); wp.showCmd = GetNHApp()->regMainShowState; @@ -83,31 +84,31 @@ HWND mswin_init_main_window () { wp.rcNormalPosition.right = GetNHApp()->regMainRight; wp.rcNormalPosition.bottom = GetNHApp()->regMainBottom; SetWindowPlacement(ret, &wp); - } - else + } else ShowWindow(ret, SW_SHOWDEFAULT); UpdateWindow(ret); - return ret; + return ret; } -void register_main_window_class() +void +register_main_window_class() { - WNDCLASS wcex; - - ZeroMemory(&wcex, sizeof(wcex)); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = (WNDPROC)MainWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = LoadIcon(GetNHApp()->hApp, (LPCTSTR)IDI_NETHACKW); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = (TCHAR*)IDC_NETHACKW; - wcex.lpszClassName = szMainWindowClass; + WNDCLASS wcex; - RegisterClass(&wcex); + ZeroMemory(&wcex, sizeof(wcex)); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = (WNDPROC) MainWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = LoadIcon(GetNHApp()->hApp, (LPCTSTR) IDI_NETHACKW); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = (TCHAR *) IDC_NETHACKW; + wcex.lpszClassName = szMainWindowClass; + + RegisterClass(&wcex); } /* @@ -117,58 +118,71 @@ void register_main_window_class() */ enum KEY_INDEXES { -KEY_NW, KEY_N, KEY_NE, KEY_MINUS, -KEY_W, KEY_GOINTERESTING, KEY_E, KEY_PLUS, -KEY_SW, KEY_S, KEY_SE, -KEY_INV, KEY_WAITLOOK, -KEY_LAST}; + KEY_NW, + KEY_N, + KEY_NE, + KEY_MINUS, + KEY_W, + KEY_GOINTERESTING, + KEY_E, + KEY_PLUS, + KEY_SW, + KEY_S, + KEY_SE, + KEY_INV, + KEY_WAITLOOK, + KEY_LAST +}; static const unsigned char -/* normal, shift, control */ -keypad[KEY_LAST][3] = { - {'y', 'Y', C('y')}, /* 7 */ - {'k', 'K', C('k')}, /* 8 */ - {'u', 'U', C('u')}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'h', 'H', C('h')}, /* 4 */ - {'g', 'G', 'g'}, /* 5 */ - {'l', 'L', C('l')}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'b', 'B', C('b')}, /* 1 */ - {'j', 'J', C('j')}, /* 2 */ - {'n', 'N', C('n')}, /* 3 */ - {'i', 'I', C('i')}, /* Ins */ - {'.', ':', ':'} /* Del */ -}, -numpad[KEY_LAST][3] = { - {'7', M('7'), '7'}, /* 7 */ - {'8', M('8'), '8'}, /* 8 */ - {'9', M('9'), '9'}, /* 9 */ - {'m', C('p'), C('p')}, /* - */ - {'4', M('4'), '4'}, /* 4 */ - {'5', M('5'), '5'}, /* 5 */ - {'6', M('6'), '6'}, /* 6 */ - {'+', 'P', C('p')}, /* + */ - {'1', M('1'), '1'}, /* 1 */ - {'2', M('2'), '2'}, /* 2 */ - {'3', M('3'), '3'}, /* 3 */ - {'0', M('0'), '0'}, /* Ins */ - {'.', ':', ':'} /* Del */ -}; + /* normal, shift, control */ + keypad[KEY_LAST][3] = + { + { 'y', 'Y', C('y') }, /* 7 */ + { 'k', 'K', C('k') }, /* 8 */ + { 'u', 'U', C('u') }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { 'h', 'H', C('h') }, /* 4 */ + { 'g', 'G', 'g' }, /* 5 */ + { 'l', 'L', C('l') }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { 'b', 'B', C('b') }, /* 1 */ + { 'j', 'J', C('j') }, /* 2 */ + { 'n', 'N', C('n') }, /* 3 */ + { 'i', 'I', C('i') }, /* Ins */ + { '.', ':', ':' } /* Del */ + }, + numpad[KEY_LAST][3] = { + { '7', M('7'), '7' }, /* 7 */ + { '8', M('8'), '8' }, /* 8 */ + { '9', M('9'), '9' }, /* 9 */ + { 'm', C('p'), C('p') }, /* - */ + { '4', M('4'), '4' }, /* 4 */ + { '5', M('5'), '5' }, /* 5 */ + { '6', M('6'), '6' }, /* 6 */ + { '+', 'P', C('p') }, /* + */ + { '1', M('1'), '1' }, /* 1 */ + { '2', M('2'), '2' }, /* 2 */ + { '3', M('3'), '3' }, /* 3 */ + { '0', M('0'), '0' }, /* Ins */ + { '.', ':', ':' } /* Del */ + }; #define STATEON(x) ((GetKeyState(x) & 0xFFFE) != 0) #define KEYTABLE_REGULAR(x) ((iflags.num_pad ? numpad : keypad)[x][0]) #define KEYTABLE_SHIFT(x) ((iflags.num_pad ? numpad : keypad)[x][1]) -#define KEYTABLE(x) (STATEON(VK_SHIFT) ? KEYTABLE_SHIFT(x) : KEYTABLE_REGULAR(x)) +#define KEYTABLE(x) \ + (STATEON(VK_SHIFT) ? KEYTABLE_SHIFT(x) : KEYTABLE_REGULAR(x)) static const char *extendedlist = "acdefijlmnopqrstuvw?2"; -#define SCANLO 0x02 -static const char scanmap[] = { /* ... */ - '1','2','3','4','5','6','7','8','9','0',0,0,0,0, - 'q','w','e','r','t','y','u','i','o','p','[',']', '\n', - 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`', - 0, '\\', 'z','x','c','v','b','n','m',',','.','?' /* ... */ +#define SCANLO 0x02 +static const char scanmap[] = { + /* ... */ + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, 0, 'q', 'w', + 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', + 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', '.', '?' /* ... */ }; /* @@ -176,392 +190,343 @@ static const char scanmap[] = { /* ... */ // // PURPOSE: Processes messages for the main window. */ -LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMainWindow data; + PNHMainWindow data; - switch (message) - { - case WM_CREATE: - /* set window data */ - data = (PNHMainWindow)malloc(sizeof(NHMainWindow)); - if( !data ) panic("out of memory"); - ZeroMemory(data, sizeof(NHMainWindow)); - data->mapAcsiiModeSave = MAP_MODE_ASCII12x16; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + switch (message) { + case WM_CREATE: + /* set window data */ + data = (PNHMainWindow) malloc(sizeof(NHMainWindow)); + if (!data) + panic("out of memory"); + ZeroMemory(data, sizeof(NHMainWindow)); + data->mapAcsiiModeSave = MAP_MODE_ASCII12x16; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); - /* update menu items */ - CheckMenuItem( - GetMenu(hWnd), - IDM_SETTING_LOCKWINDOWS, - MF_BYCOMMAND | - (GetNHApp()->bWindowsLocked? MF_CHECKED : MF_UNCHECKED) - ); + /* update menu items */ + CheckMenuItem( + GetMenu(hWnd), IDM_SETTING_LOCKWINDOWS, + MF_BYCOMMAND + | (GetNHApp()->bWindowsLocked ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem( - GetMenu(hWnd), - IDM_SETTING_AUTOLAYOUT, - GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED - ); + CheckMenuItem(GetMenu(hWnd), IDM_SETTING_AUTOLAYOUT, + GetNHApp()->bAutoLayout ? MF_CHECKED : MF_UNCHECKED); - /* store handle to the mane menu in the application record */ - GetNHApp()->hMainWnd = hWnd; - break; - - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; - - case WM_KEYDOWN: - { - data = (PNHMainWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - - /* translate arrow keys into nethack commands */ - switch (wParam) - { - case VK_LEFT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line left */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_LINEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_W)); - } - return 0; - - case VK_RIGHT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line right */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_LINEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_E)); - } - return 0; - - case VK_UP: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line up */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_LINEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_N)); - } - return 0; - - case VK_DOWN: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one line down */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_LINEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_S)); - } - return 0; - - case VK_HOME: - if( STATEON(VK_CONTROL) ) { - /* scroll map window to upper left corner */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_THUMBTRACK, 0), - (LPARAM)NULL - ); - - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_THUMBTRACK, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_NW)); - } - return 0; - - case VK_END: - if( STATEON(VK_CONTROL) ) { - /* scroll map window to lower right corner */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_THUMBTRACK, ROWNO), - (LPARAM)NULL - ); - - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_HSCROLL, - MAKEWPARAM(SB_THUMBTRACK, COLNO), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_SW)); - } - return 0; - - case VK_PRIOR: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one page up */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_PAGEUP, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_NE)); - } - return 0; - - case VK_NEXT: - if( STATEON(VK_CONTROL) ) { - /* scroll map window one page down */ - SendMessage( - mswin_hwnd_from_winid(WIN_MAP), - WM_VSCROLL, - MAKEWPARAM(SB_PAGEDOWN, 0), - (LPARAM)NULL - ); - } else { - NHEVENT_KBD(KEYTABLE(KEY_SE)); - } - return 0; - - case VK_DECIMAL: - case VK_DELETE: - NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK)); - return 0; - - case VK_INSERT: - NHEVENT_KBD(KEYTABLE(KEY_INV)); - return 0; - - case VK_SUBTRACT: - NHEVENT_KBD(KEYTABLE(KEY_MINUS)); - return 0; - - case VK_ADD: - NHEVENT_KBD(KEYTABLE(KEY_PLUS)); - return 0; - - case VK_CLEAR: /* This is the '5' key */ - NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING)); - return 0; - - case VK_F4: - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - data->mapAcsiiModeSave : - MAP_MODE_TILES - ); - } else { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - MAP_MODE_ASCII_FIT_TO_SCREEN : - MAP_MODE_TILES_FIT_TO_SCREEN - ); - } - return 0; - - case VK_F5: - if( IS_MAP_ASCII(iflags.wc_map_mode) ) { - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode(MAP_MODE_TILES_FIT_TO_SCREEN); - } else { - mswin_select_map_mode(MAP_MODE_TILES); - } - } else { - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode(MAP_MODE_ASCII_FIT_TO_SCREEN); - } else { - mswin_select_map_mode(data->mapAcsiiModeSave); - } - } - return 0; - - default: { - WORD c; - BYTE kbd_state[256]; - - c = 0; - ZeroMemory(kbd_state, sizeof(kbd_state)); - GetKeyboardState(kbd_state); - - if( ToAscii( wParam, (lParam>>16)&0xFF, kbd_state, &c, 0) ) { - NHEVENT_KBD( c&0xFF ); - return 0; - } else { - return 1; - } - } - - - } /* end switch */ - } break; - - case WM_SYSCHAR: /* Alt-char pressed */ - { - /* - If not nethackmode, don't handle Alt-keys here. - If no Alt-key pressed it can never be an extended command - */ - if (GetNHApp()->regNetHackMode && ((lParam & 1<<29) != 0)) - { - unsigned char c = (unsigned char)(wParam & 0xFF); - unsigned char scancode = (lParam >> 16) & 0xFF; - if (index(extendedlist, tolower(c)) != 0) - { - NHEVENT_KBD(M(tolower(c))); - } else if (scancode == (SCANLO + SIZE(scanmap)) - 1) { - NHEVENT_KBD(M('?')); - } - return 0; - } - return DefWindowProc(hWnd, message, wParam, lParam); - } + /* store handle to the mane menu in the application record */ + GetNHApp()->hMainWnd = hWnd; break; - case WM_COMMAND: - /* process commands - menu commands mostly */ - if( onWMCommand(hWnd, wParam, lParam) ) - return DefWindowProc(hWnd, message, wParam, lParam); - else - return 0; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_MOVE: - case WM_SIZE: - { - WINDOWPLACEMENT wp; + case WM_KEYDOWN: { + data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - mswin_layout_main_window(NULL); - - wp.length = sizeof(wp); - if (GetWindowPlacement(hWnd, &wp)) { - GetNHApp()->regMainShowState = (wp.showCmd == SW_SHOWMAXIMIZED - ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); - - GetNHApp()->regMainMinX = wp.ptMinPosition.x; - GetNHApp()->regMainMinY = wp.ptMinPosition.y; - - GetNHApp()->regMainMaxX = wp.ptMaxPosition.x; - GetNHApp()->regMainMaxY = wp.ptMaxPosition.y; - - GetNHApp()->regMainLeft = wp.rcNormalPosition.left; - GetNHApp()->regMainTop = wp.rcNormalPosition.top; - GetNHApp()->regMainRight = wp.rcNormalPosition.right; - GetNHApp()->regMainBottom = wp.rcNormalPosition.bottom; + /* translate arrow keys into nethack commands */ + switch (wParam) { + case VK_LEFT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line left */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_W)); + } + return 0; + + case VK_RIGHT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line right */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_E)); + } + return 0; + + case VK_UP: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line up */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_N)); + } + return 0; + + case VK_DOWN: + if (STATEON(VK_CONTROL)) { + /* scroll map window one line down */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_S)); + } + return 0; + + case VK_HOME: + if (STATEON(VK_CONTROL)) { + /* scroll map window to upper left corner */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); + + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_NW)); + } + return 0; + + case VK_END: + if (STATEON(VK_CONTROL)) { + /* scroll map window to lower right corner */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_THUMBTRACK, ROWNO), (LPARAM) NULL); + + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, + MAKEWPARAM(SB_THUMBTRACK, COLNO), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_SW)); + } + return 0; + + case VK_PRIOR: + if (STATEON(VK_CONTROL)) { + /* scroll map window one page up */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_PAGEUP, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_NE)); + } + return 0; + + case VK_NEXT: + if (STATEON(VK_CONTROL)) { + /* scroll map window one page down */ + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, + MAKEWPARAM(SB_PAGEDOWN, 0), (LPARAM) NULL); + } else { + NHEVENT_KBD(KEYTABLE(KEY_SE)); + } + return 0; + + case VK_DECIMAL: + case VK_DELETE: + NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK)); + return 0; + + case VK_INSERT: + NHEVENT_KBD(KEYTABLE(KEY_INV)); + return 0; + + case VK_SUBTRACT: + NHEVENT_KBD(KEYTABLE(KEY_MINUS)); + return 0; + + case VK_ADD: + NHEVENT_KBD(KEYTABLE(KEY_PLUS)); + return 0; + + case VK_CLEAR: /* This is the '5' key */ + NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING)); + return 0; + + case VK_F4: + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? data->mapAcsiiModeSave + : MAP_MODE_TILES); + } else { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? MAP_MODE_ASCII_FIT_TO_SCREEN + : MAP_MODE_TILES_FIT_TO_SCREEN); + } + return 0; + + case VK_F5: + if (IS_MAP_ASCII(iflags.wc_map_mode)) { + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(MAP_MODE_TILES_FIT_TO_SCREEN); + } else { + mswin_select_map_mode(MAP_MODE_TILES); + } + } else { + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(MAP_MODE_ASCII_FIT_TO_SCREEN); + } else { + mswin_select_map_mode(data->mapAcsiiModeSave); + } + } + return 0; + + default: { + WORD c; + BYTE kbd_state[256]; + + c = 0; + ZeroMemory(kbd_state, sizeof(kbd_state)); + GetKeyboardState(kbd_state); + + if (ToAscii(wParam, (lParam >> 16) & 0xFF, kbd_state, &c, 0)) { + NHEVENT_KBD(c & 0xFF); + return 0; + } else { + return 1; } - break; } - case WM_SETFOCUS: - /* if there is a menu window out there - - transfer input focus to it */ - if( IsWindow( GetNHApp()->hPopupWnd ) ) { - SetFocus( GetNHApp()->hPopupWnd ); - } - break; - case WM_CLOSE: - { - /* exit gracefully */ - if (program_state.gameover) - { - /* assume the user really meant this, as the game is already over... */ - /* to make sure we still save bones, just set stop printing flag */ - program_state.stopprint++; - NHEVENT_KBD('\033'); /* and send keyboard input as if user pressed ESC */ - /* additional code for this is done in menu and rip windows */ - } - else if (!program_state.something_worth_saving) - { - /* User exited before the game started, e.g. during splash display */ - /* Just get out. */ - bail((char *)0); - } - else - { - /* prompt user for action */ - switch (NHMessageBox(hWnd, TEXT("Save?"), MB_YESNOCANCEL | MB_ICONQUESTION)) { - case IDYES: + } /* end switch */ + } break; + + case WM_SYSCHAR: /* Alt-char pressed */ + { + /* + If not nethackmode, don't handle Alt-keys here. + If no Alt-key pressed it can never be an extended command + */ + if (GetNHApp()->regNetHackMode && ((lParam & 1 << 29) != 0)) { + unsigned char c = (unsigned char) (wParam & 0xFF); + unsigned char scancode = (lParam >> 16) & 0xFF; + if (index(extendedlist, tolower(c)) != 0) { + NHEVENT_KBD(M(tolower(c))); + } else if (scancode == (SCANLO + SIZE(scanmap)) - 1) { + NHEVENT_KBD(M('?')); + } + return 0; + } + return DefWindowProc(hWnd, message, wParam, lParam); + } break; + + case WM_COMMAND: + /* process commands - menu commands mostly */ + if (onWMCommand(hWnd, wParam, lParam)) + return DefWindowProc(hWnd, message, wParam, lParam); + else + return 0; + + case WM_MOVE: + case WM_SIZE: { + WINDOWPLACEMENT wp; + + mswin_layout_main_window(NULL); + + wp.length = sizeof(wp); + if (GetWindowPlacement(hWnd, &wp)) { + GetNHApp()->regMainShowState = + (wp.showCmd == SW_SHOWMAXIMIZED ? SW_SHOWMAXIMIZED + : SW_SHOWNORMAL); + + GetNHApp()->regMainMinX = wp.ptMinPosition.x; + GetNHApp()->regMainMinY = wp.ptMinPosition.y; + + GetNHApp()->regMainMaxX = wp.ptMaxPosition.x; + GetNHApp()->regMainMaxY = wp.ptMaxPosition.y; + + GetNHApp()->regMainLeft = wp.rcNormalPosition.left; + GetNHApp()->regMainTop = wp.rcNormalPosition.top; + GetNHApp()->regMainRight = wp.rcNormalPosition.right; + GetNHApp()->regMainBottom = wp.rcNormalPosition.bottom; + } + break; + } + case WM_SETFOCUS: + /* if there is a menu window out there - + transfer input focus to it */ + if (IsWindow(GetNHApp()->hPopupWnd)) { + SetFocus(GetNHApp()->hPopupWnd); + } + break; + + case WM_CLOSE: { + /* exit gracefully */ + if (program_state.gameover) { + /* assume the user really meant this, as the game is already + * over... */ + /* to make sure we still save bones, just set stop printing flag + */ + program_state.stopprint++; + NHEVENT_KBD( + '\033'); /* and send keyboard input as if user pressed ESC */ + /* additional code for this is done in menu and rip windows */ + } else if (!program_state.something_worth_saving) { + /* User exited before the game started, e.g. during splash display + */ + /* Just get out. */ + bail((char *) 0); + } else { + /* prompt user for action */ + switch (NHMessageBox(hWnd, TEXT("Save?"), + MB_YESNOCANCEL | MB_ICONQUESTION)) { + case IDYES: #ifdef SAFERHANGUP - /* destroy popup window - it has its own loop and we need to - return control to NetHack core at this point */ - if( IsWindow( GetNHApp()->hPopupWnd ) ) - SendMessage( GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, 0); + /* destroy popup window - it has its own loop and we need to + return control to NetHack core at this point */ + if (IsWindow(GetNHApp()->hPopupWnd)) + SendMessage(GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, + 0); - /* tell NetHack core that "hangup" is requested */ - hangup(1); + /* tell NetHack core that "hangup" is requested */ + hangup(1); #else - NHEVENT_KBD('y'); dosave(); + NHEVENT_KBD('y'); + dosave(); #endif - break; - case IDNO: NHEVENT_KBD('q'); done(QUIT); break; - case IDCANCEL: break; - } - } - } return 0; + break; + case IDNO: + NHEVENT_KBD('q'); + done(QUIT); + break; + case IDCANCEL: + break; + } + } + } + return 0; - case WM_DESTROY: - /* apparently we never get here - TODO: work on exit routines - need to send - WM_QUIT somehow */ + case WM_DESTROY: + /* apparently we never get here + TODO: work on exit routines - need to send + WM_QUIT somehow */ - /* clean up */ - free( (PNHMainWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA) ); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); + /* clean up */ + free((PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA)); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); - // PostQuitMessage(0); - exit(1); - break; + // PostQuitMessage(0); + exit(1); + break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - UNREFERENCED_PARAMETER(hWnd); - UNREFERENCED_PARAMETER(wParam); - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(hWnd); + UNREFERENCED_PARAMETER(wParam); + UNREFERENCED_PARAMETER(lParam); - switch(wParam) { + switch (wParam) { + /* new window was just added */ + case MSNH_MSG_ADDWND: { + PMSNHMsgAddWnd msg_param = (PMSNHMsgAddWnd) lParam; + HWND child; - /* new window was just added */ - case MSNH_MSG_ADDWND: { - PMSNHMsgAddWnd msg_param = (PMSNHMsgAddWnd)lParam; - HWND child; + if (GetNHApp()->windowlist[msg_param->wid].type == NHW_MAP) + mswin_select_map_mode(iflags.wc_map_mode); - if( GetNHApp()->windowlist[msg_param->wid].type == NHW_MAP ) - mswin_select_map_mode(iflags.wc_map_mode); - - child = GetNHApp()->windowlist[msg_param->wid].win; - } break; - - } + child = GetNHApp()->windowlist[msg_param->wid].win; + } break; + } } -/* adjust windows to fit main window layout +/* adjust windows to fit main window layout --------------------------- | Status | +-------------------------+ @@ -574,473 +539,470 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) | Messages | --------------------------- */ -void mswin_layout_main_window(HWND changed_child) +void +mswin_layout_main_window(HWND changed_child) { - winid i; - RECT client_rt, wnd_rect; - POINT status_org; - SIZE status_size; - POINT msg_org; - SIZE msg_size; - POINT map_org; - SIZE map_size; - SIZE menu_size; - HWND wnd_status, wnd_msg; - PNHMainWindow data; + winid i; + RECT client_rt, wnd_rect; + POINT status_org; + SIZE status_size; + POINT msg_org; + SIZE msg_size; + POINT map_org; + SIZE map_size; + SIZE menu_size; + HWND wnd_status, wnd_msg; + PNHMainWindow data; - if( GetNHApp()->bAutoLayout ) { - GetClientRect(GetNHApp()->hMainWnd, &client_rt); - data = (PNHMainWindow)GetWindowLongPtr(GetNHApp()->hMainWnd, GWLP_USERDATA); + if (GetNHApp()->bAutoLayout) { + GetClientRect(GetNHApp()->hMainWnd, &client_rt); + data = (PNHMainWindow) GetWindowLongPtr(GetNHApp()->hMainWnd, + GWLP_USERDATA); - /* get sizes of child windows */ - wnd_status = mswin_hwnd_from_winid(WIN_STATUS); - if( IsWindow(wnd_status) ) { - mswin_status_window_size(wnd_status, &status_size); - } else { - status_size.cx = status_size.cy = 0; - } + /* get sizes of child windows */ + wnd_status = mswin_hwnd_from_winid(WIN_STATUS); + if (IsWindow(wnd_status)) { + mswin_status_window_size(wnd_status, &status_size); + } else { + status_size.cx = status_size.cy = 0; + } - wnd_msg = mswin_hwnd_from_winid(WIN_MESSAGE); - if( IsWindow(wnd_msg) ) { - mswin_message_window_size(wnd_msg, &msg_size); - } else { - msg_size.cx = msg_size.cy = 0; - } + wnd_msg = mswin_hwnd_from_winid(WIN_MESSAGE); + if (IsWindow(wnd_msg)) { + mswin_message_window_size(wnd_msg, &msg_size); + } else { + msg_size.cx = msg_size.cy = 0; + } - /* find all menu windows and calculate the size */ - menu_size.cx = menu_size.cy = 0; - for( i=0; iwindowlist[i].win - && !GetNHApp()->windowlist[i].dead - && GetNHApp()->windowlist[i].type == NHW_MENU ) { - mswin_menu_window_size(GetNHApp()->windowlist[i].win , &tmp_size); - menu_size.cx = max(menu_size.cx, tmp_size.cx); - menu_size.cy = max(menu_size.cy, tmp_size.cy); - } - } + /* find all menu windows and calculate the size */ + menu_size.cx = menu_size.cy = 0; + for (i = 0; i < MAXWINDOWS; i++) { + SIZE tmp_size; + if (GetNHApp()->windowlist[i].win + && !GetNHApp()->windowlist[i].dead + && GetNHApp()->windowlist[i].type == NHW_MENU) { + mswin_menu_window_size(GetNHApp()->windowlist[i].win, + &tmp_size); + menu_size.cx = max(menu_size.cx, tmp_size.cx); + menu_size.cy = max(menu_size.cy, tmp_size.cy); + } + } - /* set window positions */ - SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom); - switch(iflags.wc_align_status) { - case ALIGN_LEFT: - status_size.cx = (wnd_rect.right-wnd_rect.left)/4; - status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.top; - wnd_rect.left += status_size.cx; - break; + /* set window positions */ + SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, + client_rt.bottom); + switch (iflags.wc_align_status) { + case ALIGN_LEFT: + status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + status_size.cy = + (wnd_rect.bottom - wnd_rect.top); // that won't look good + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.top; + wnd_rect.left += status_size.cx; + break; - case ALIGN_RIGHT: - status_size.cx = (wnd_rect.right-wnd_rect.left)/4; - status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good - status_org.x = wnd_rect.right - status_size.cx; - status_org.y = wnd_rect.top; - wnd_rect.right -= status_size.cx; - break; + case ALIGN_RIGHT: + status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + status_size.cy = + (wnd_rect.bottom - wnd_rect.top); // that won't look good + status_org.x = wnd_rect.right - status_size.cx; + status_org.y = wnd_rect.top; + wnd_rect.right -= status_size.cx; + break; - case ALIGN_TOP: - status_size.cx = (wnd_rect.right-wnd_rect.left); - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.top; - wnd_rect.top += status_size.cy; - break; + case ALIGN_TOP: + status_size.cx = (wnd_rect.right - wnd_rect.left); + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.top; + wnd_rect.top += status_size.cy; + break; - case ALIGN_BOTTOM: - default: - status_size.cx = (wnd_rect.right-wnd_rect.left); - status_org.x = wnd_rect.left; - status_org.y = wnd_rect.bottom - status_size.cy; - wnd_rect.bottom -= status_size.cy; - break; - } + case ALIGN_BOTTOM: + default: + status_size.cx = (wnd_rect.right - wnd_rect.left); + status_org.x = wnd_rect.left; + status_org.y = wnd_rect.bottom - status_size.cy; + wnd_rect.bottom -= status_size.cy; + break; + } - switch(iflags.wc_align_message) { - case ALIGN_LEFT: - msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; - msg_size.cy = (wnd_rect.bottom-wnd_rect.top); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.top; - wnd_rect.left += msg_size.cx; - break; + switch (iflags.wc_align_message) { + case ALIGN_LEFT: + msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + msg_size.cy = (wnd_rect.bottom - wnd_rect.top); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.top; + wnd_rect.left += msg_size.cx; + break; - case ALIGN_RIGHT: - msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; - msg_size.cy = (wnd_rect.bottom-wnd_rect.top); - msg_org.x = wnd_rect.right - msg_size.cx; - msg_org.y = wnd_rect.top; - wnd_rect.right -= msg_size.cx; - break; + case ALIGN_RIGHT: + msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; + msg_size.cy = (wnd_rect.bottom - wnd_rect.top); + msg_org.x = wnd_rect.right - msg_size.cx; + msg_org.y = wnd_rect.top; + wnd_rect.right -= msg_size.cx; + break; - case ALIGN_TOP: - msg_size.cx = (wnd_rect.right-wnd_rect.left); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.top; - wnd_rect.top += msg_size.cy; - break; + case ALIGN_TOP: + msg_size.cx = (wnd_rect.right - wnd_rect.left); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.top; + wnd_rect.top += msg_size.cy; + break; - case ALIGN_BOTTOM: - default: - msg_size.cx = (wnd_rect.right-wnd_rect.left); - msg_org.x = wnd_rect.left; - msg_org.y = wnd_rect.bottom - msg_size.cy; - wnd_rect.bottom -= msg_size.cy; - break; - } + case ALIGN_BOTTOM: + default: + msg_size.cx = (wnd_rect.right - wnd_rect.left); + msg_org.x = wnd_rect.left; + msg_org.y = wnd_rect.bottom - msg_size.cy; + wnd_rect.bottom -= msg_size.cy; + break; + } - /* map window */ - map_org.x = wnd_rect.left; - map_org.y = wnd_rect.top; - map_size.cx = wnd_rect.right - wnd_rect.left; - map_size.cy = wnd_rect.bottom - wnd_rect.top; + /* map window */ + map_org.x = wnd_rect.left; + map_org.y = wnd_rect.top; + map_size.cx = wnd_rect.right - wnd_rect.left; + map_size.cy = wnd_rect.bottom - wnd_rect.top; + GetNHApp()->rtStatusWindow.left = status_org.x; + GetNHApp()->rtStatusWindow.top = status_org.y; + GetNHApp()->rtStatusWindow.right = status_org.x + status_size.cx; + GetNHApp()->rtStatusWindow.bottom = status_org.y + status_size.cy; - GetNHApp()->rtStatusWindow.left = status_org.x; - GetNHApp()->rtStatusWindow.top = status_org.y; - GetNHApp()->rtStatusWindow.right = status_org.x + status_size.cx; - GetNHApp()->rtStatusWindow.bottom= status_org.y + status_size.cy; + GetNHApp()->rtTextWindow.left = map_org.x; + GetNHApp()->rtTextWindow.top = map_org.y; + GetNHApp()->rtTextWindow.right = + map_org.x + (wnd_rect.right - wnd_rect.left); + GetNHApp()->rtTextWindow.bottom = map_org.y + map_size.cy; - GetNHApp()->rtTextWindow.left = map_org.x; - GetNHApp()->rtTextWindow.top = map_org.y; - GetNHApp()->rtTextWindow.right = map_org.x + (wnd_rect.right - wnd_rect.left); - GetNHApp()->rtTextWindow.bottom = map_org.y + map_size.cy; + GetNHApp()->rtMapWindow.left = map_org.x; + GetNHApp()->rtMapWindow.top = map_org.y; + GetNHApp()->rtMapWindow.right = map_org.x + map_size.cx; + GetNHApp()->rtMapWindow.bottom = map_org.y + map_size.cy; - GetNHApp()->rtMapWindow.left = map_org.x; - GetNHApp()->rtMapWindow.top = map_org.y; - GetNHApp()->rtMapWindow.right = map_org.x + map_size.cx; - GetNHApp()->rtMapWindow.bottom = map_org.y + map_size.cy; + GetNHApp()->rtMsgWindow.left = msg_org.x; + GetNHApp()->rtMsgWindow.top = msg_org.y; + GetNHApp()->rtMsgWindow.right = msg_org.x + msg_size.cx; + GetNHApp()->rtMsgWindow.bottom = msg_org.y + msg_size.cy; - GetNHApp()->rtMsgWindow.left = msg_org.x; - GetNHApp()->rtMsgWindow.top = msg_org.y; - GetNHApp()->rtMsgWindow.right = msg_org.x + msg_size.cx; - GetNHApp()->rtMsgWindow.bottom = msg_org.y + msg_size.cy; + /* map_width/4 < menu_width < map_width*2/3 */ + GetNHApp()->rtMenuWindow.left = + GetNHApp()->rtMapWindow.right + - min(map_size.cx * 2 / 3, max(map_size.cx / 4, menu_size.cx)); + GetNHApp()->rtMenuWindow.top = GetNHApp()->rtMapWindow.top; + GetNHApp()->rtMenuWindow.right = GetNHApp()->rtMapWindow.right; + GetNHApp()->rtMenuWindow.bottom = GetNHApp()->rtMapWindow.bottom; - /* map_width/4 < menu_width < map_width*2/3 */ - GetNHApp()->rtMenuWindow.left = GetNHApp()->rtMapWindow.right - min(map_size.cx*2/3, max(map_size.cx/4, menu_size.cx)); - GetNHApp()->rtMenuWindow.top = GetNHApp()->rtMapWindow.top; - GetNHApp()->rtMenuWindow.right = GetNHApp()->rtMapWindow.right; - GetNHApp()->rtMenuWindow.bottom = GetNHApp()->rtMapWindow.bottom; + GetNHApp()->rtInvenWindow.left = GetNHApp()->rtMenuWindow.left; + GetNHApp()->rtInvenWindow.top = GetNHApp()->rtMenuWindow.top; + GetNHApp()->rtInvenWindow.right = GetNHApp()->rtMenuWindow.right; + GetNHApp()->rtInvenWindow.bottom = GetNHApp()->rtMenuWindow.bottom; - GetNHApp()->rtInvenWindow.left = GetNHApp()->rtMenuWindow.left; - GetNHApp()->rtInvenWindow.top = GetNHApp()->rtMenuWindow.top; - GetNHApp()->rtInvenWindow.right = GetNHApp()->rtMenuWindow.right; - GetNHApp()->rtInvenWindow.bottom = GetNHApp()->rtMenuWindow.bottom; + /* adjust map window size only if perm_invent is set */ + if (flags.perm_invent) + GetNHApp()->rtMapWindow.right = GetNHApp()->rtMenuWindow.left; + } - /* adjust map window size only if perm_invent is set */ - if( flags.perm_invent ) - GetNHApp()->rtMapWindow.right = GetNHApp()->rtMenuWindow.left; - } + /* go through the windows list and adjust sizes */ + for (i = 0; i < MAXWINDOWS; i++) { + if (GetNHApp()->windowlist[i].win + && !GetNHApp()->windowlist[i].dead) { + RECT rt; + /* kludge - inventory window should have its own type (same as + menu-text + as a matter of fact) */ + if (flags.perm_invent && i == WIN_INVEN) + mswin_get_window_placement(NHW_INVEN, &rt); + else + mswin_get_window_placement(GetNHApp()->windowlist[i].type, + &rt); - /* go through the windows list and adjust sizes */ - for( i=0; iwindowlist[i].win && !GetNHApp()->windowlist[i].dead) { - RECT rt; - /* kludge - inventory window should have its own type (same as menu-text - as a matter of fact) */ - if( flags.perm_invent && i==WIN_INVEN ) - mswin_get_window_placement(NHW_INVEN, &rt); - else - mswin_get_window_placement(GetNHApp()->windowlist[i].type, &rt); - - MoveWindow(GetNHApp()->windowlist[i].win, - rt.left, - rt.top, - rt.right - rt.left, - rt.bottom - rt.top, - TRUE - ); - } - } - if( IsWindow(changed_child) ) - SetForegroundWindow(changed_child); + MoveWindow(GetNHApp()->windowlist[i].win, rt.left, rt.top, + rt.right - rt.left, rt.bottom - rt.top, TRUE); + } + } + if (IsWindow(changed_child)) + SetForegroundWindow(changed_child); } -LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +LRESULT +onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; - PNHMainWindow data; + int wmId, wmEvent; + PNHMainWindow data; - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(lParam); - data = (PNHMainWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); + data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_ABOUT: - mswin_display_splash_window(TRUE); - break; + // Parse the menu selections: + switch (wmId) { + case IDM_ABOUT: + mswin_display_splash_window(TRUE); + break; - case IDM_EXIT: - done2(); - break; + case IDM_EXIT: + done2(); + break; - case IDM_SAVE: - if (!program_state.gameover && !program_state.done_hup) dosave(); - else MessageBeep(0); - break; + case IDM_SAVE: + if (!program_state.gameover && !program_state.done_hup) + dosave(); + else + MessageBeep(0); + break; - case IDM_MAP_TILES: - case IDM_MAP_ASCII4X6: - case IDM_MAP_ASCII6X8: - case IDM_MAP_ASCII8X8: - case IDM_MAP_ASCII16X8: - case IDM_MAP_ASCII7X12: - case IDM_MAP_ASCII8X12: - case IDM_MAP_ASCII12X16: - case IDM_MAP_ASCII16X12: - case IDM_MAP_ASCII10X18: - mswin_select_map_mode(menuid2mapmode(wmId)); - break; + case IDM_MAP_TILES: + case IDM_MAP_ASCII4X6: + case IDM_MAP_ASCII6X8: + case IDM_MAP_ASCII8X8: + case IDM_MAP_ASCII16X8: + case IDM_MAP_ASCII7X12: + case IDM_MAP_ASCII8X12: + case IDM_MAP_ASCII12X16: + case IDM_MAP_ASCII16X12: + case IDM_MAP_ASCII10X18: + mswin_select_map_mode(menuid2mapmode(wmId)); + break; - case IDM_MAP_FIT_TO_SCREEN: - if( IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode) ) { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - data->mapAcsiiModeSave : - MAP_MODE_TILES - ); - } else { - mswin_select_map_mode( - IS_MAP_ASCII(iflags.wc_map_mode)? - MAP_MODE_ASCII_FIT_TO_SCREEN : - MAP_MODE_TILES_FIT_TO_SCREEN - ); - } - break; - - case IDM_SETTING_SCREEN_TO_CLIPBOARD: - { - char* p; - size_t len; - HANDLE hglbCopy; - char* p_copy; - - p = nh_compose_ascii_screenshot(); - if( !p ) return 0; - len = strlen(p); - - if( !OpenClipboard(hWnd) ) { - NHMessageBox(hWnd, TEXT("Cannot open clipboard"), MB_OK | MB_ICONERROR); - return 0; - } - - EmptyClipboard(); - - hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(char)); - if (hglbCopy == NULL) { - CloseClipboard(); - return FALSE; - } - - p_copy = (char*)GlobalLock(hglbCopy); - strncpy(p_copy, p, len); - p_copy[len] = 0; // null character - GlobalUnlock(hglbCopy); - - SetClipboardData(SYMHANDLING(H_IBM)? CF_OEMTEXT : CF_TEXT, hglbCopy); - - CloseClipboard(); - - free(p); - } break; - - case IDM_SETTING_SCREEN_TO_FILE: { - OPENFILENAME ofn; - TCHAR filename[1024]; - TCHAR whackdir[MAX_PATH]; - FILE* pFile; - char* text; - wchar_t* wtext; - int tlen = 0; - - ZeroMemory(filename, sizeof(filename)); - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof (OPENFILENAME); - ofn.hwndOwner = hWnd; - ofn.hInstance = GetNHApp()->hApp; - ofn.lpstrFilter = TEXT("Text Files (*.txt)\x0*.txt\x0") - TEXT("All Files (*.*)\x0*.*\x0") - TEXT("\x0\x0"); - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 1; - ofn.lpstrFile = filename; - ofn.nMaxFile = SIZE(filename); - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NH_A2W(hackdir, whackdir, MAX_PATH); - ofn.lpstrTitle = NULL; - ofn.Flags = OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; - ofn.nFileOffset = 0; - ofn.nFileExtension = 0; - ofn.lpstrDefExt = TEXT("txt"); - ofn.lCustData = 0; - ofn.lpfnHook = 0; - ofn.lpTemplateName = 0; - - if( !GetSaveFileName( &ofn ) ) return FALSE; - - text = nh_compose_ascii_screenshot(); - if( !text ) return FALSE; - - pFile = _tfopen(filename, TEXT("wt+,ccs=UTF-8")); - if( !pFile ) { - TCHAR buf[4096]; - _stprintf(buf, TEXT("Cannot open %s for writing!"), filename); - NHMessageBox(hWnd, buf, MB_OK | MB_ICONERROR); - free(text); - return FALSE; - } - - tlen = strlen(text); - wtext = (wchar_t*)malloc(tlen*sizeof(wchar_t)); - if( !wtext ) panic("out of memory"); - MultiByteToWideChar(NH_CODEPAGE,0,text,-1,wtext,tlen); - fwrite(wtext, tlen*sizeof(wchar_t), 1, pFile); - fclose(pFile); - free(text); - free(wtext); - } break; - - case IDM_NHMODE: - { - GetNHApp()->regNetHackMode = GetNHApp()->regNetHackMode ? 0 : 1; - mswin_menu_check_intf_mode(); - break; + case IDM_MAP_FIT_TO_SCREEN: + if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? data->mapAcsiiModeSave + : MAP_MODE_TILES); + } else { + mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) + ? MAP_MODE_ASCII_FIT_TO_SCREEN + : MAP_MODE_TILES_FIT_TO_SCREEN); } - case IDM_CLEARSETTINGS: - { - mswin_destroy_reg(); - /* Notify the user that windows settings will not be saved this time. */ - NHMessageBox(GetNHApp()->hMainWnd, - TEXT("Your Windows Settings will not be stored when you exit this time."), - MB_OK | MB_ICONINFORMATION); - break; + break; + + case IDM_SETTING_SCREEN_TO_CLIPBOARD: { + char *p; + size_t len; + HANDLE hglbCopy; + char *p_copy; + + p = nh_compose_ascii_screenshot(); + if (!p) + return 0; + len = strlen(p); + + if (!OpenClipboard(hWnd)) { + NHMessageBox(hWnd, TEXT("Cannot open clipboard"), + MB_OK | MB_ICONERROR); + return 0; } - case IDM_SETTING_AUTOLAYOUT: - GetNHApp()->bAutoLayout = !GetNHApp()->bAutoLayout; - mswin_layout_main_window(NULL); + EmptyClipboard(); - /* Update menu item check-mark */ - CheckMenuItem( - GetMenu(GetNHApp()->hMainWnd), - IDM_SETTING_AUTOLAYOUT, - GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED - ); - break; + hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(char)); + if (hglbCopy == NULL) { + CloseClipboard(); + return FALSE; + } - case IDM_SETTING_LOCKWINDOWS: - nhlock_windows( !GetNHApp()->bWindowsLocked ); - break; + p_copy = (char *) GlobalLock(hglbCopy); + strncpy(p_copy, p, len); + p_copy[len] = 0; // null character + GlobalUnlock(hglbCopy); - case IDM_HELP_LONG: - display_file(HELP, TRUE); - break; - - case IDM_HELP_COMMANDS: - display_file(SHELP, TRUE); - break; - - case IDM_HELP_HISTORY: - (void) dohistory(); - break; - - case IDM_HELP_INFO_CHAR: - (void) dowhatis(); - break; - - case IDM_HELP_INFO_KEY: - (void) dowhatdoes(); - break; - - case IDM_HELP_OPTIONS: - option_help(); - break; - - case IDM_HELP_OPTIONS_LONG: - display_file(OPTIONFILE, TRUE); - break; - - case IDM_HELP_EXTCMD: - (void) doextlist(); - break; - - case IDM_HELP_LICENSE: - display_file(LICENSE, TRUE); - break; + SetClipboardData(SYMHANDLING(H_IBM) ? CF_OEMTEXT : CF_TEXT, hglbCopy); - case IDM_HELP_PORTHELP: - display_file(PORT_HELP, TRUE); - break; + CloseClipboard(); - default: - return 1; - } - return 0; + free(p); + } break; + + case IDM_SETTING_SCREEN_TO_FILE: { + OPENFILENAME ofn; + TCHAR filename[1024]; + TCHAR whackdir[MAX_PATH]; + FILE *pFile; + char *text; + wchar_t *wtext; + int tlen = 0; + + ZeroMemory(filename, sizeof(filename)); + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hWnd; + ofn.hInstance = GetNHApp()->hApp; + ofn.lpstrFilter = TEXT("Text Files (*.txt)\x0*.txt\x0") + TEXT("All Files (*.*)\x0*.*\x0") TEXT("\x0\x0"); + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 1; + ofn.lpstrFile = filename; + ofn.nMaxFile = SIZE(filename); + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NH_A2W(hackdir, whackdir, MAX_PATH); + ofn.lpstrTitle = NULL; + ofn.Flags = OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; + ofn.nFileOffset = 0; + ofn.nFileExtension = 0; + ofn.lpstrDefExt = TEXT("txt"); + ofn.lCustData = 0; + ofn.lpfnHook = 0; + ofn.lpTemplateName = 0; + + if (!GetSaveFileName(&ofn)) + return FALSE; + + text = nh_compose_ascii_screenshot(); + if (!text) + return FALSE; + + pFile = _tfopen(filename, TEXT("wt+,ccs=UTF-8")); + if (!pFile) { + TCHAR buf[4096]; + _stprintf(buf, TEXT("Cannot open %s for writing!"), filename); + NHMessageBox(hWnd, buf, MB_OK | MB_ICONERROR); + free(text); + return FALSE; + } + + tlen = strlen(text); + wtext = (wchar_t *) malloc(tlen * sizeof(wchar_t)); + if (!wtext) + panic("out of memory"); + MultiByteToWideChar(NH_CODEPAGE, 0, text, -1, wtext, tlen); + fwrite(wtext, tlen * sizeof(wchar_t), 1, pFile); + fclose(pFile); + free(text); + free(wtext); + } break; + + case IDM_NHMODE: { + GetNHApp()->regNetHackMode = GetNHApp()->regNetHackMode ? 0 : 1; + mswin_menu_check_intf_mode(); + break; + } + case IDM_CLEARSETTINGS: { + mswin_destroy_reg(); + /* Notify the user that windows settings will not be saved this time. + */ + NHMessageBox(GetNHApp()->hMainWnd, + TEXT("Your Windows Settings will not be stored when you " + "exit this time."), + MB_OK | MB_ICONINFORMATION); + break; + } + + case IDM_SETTING_AUTOLAYOUT: + GetNHApp()->bAutoLayout = !GetNHApp()->bAutoLayout; + mswin_layout_main_window(NULL); + + /* Update menu item check-mark */ + CheckMenuItem(GetMenu(GetNHApp()->hMainWnd), IDM_SETTING_AUTOLAYOUT, + GetNHApp()->bAutoLayout ? MF_CHECKED : MF_UNCHECKED); + break; + + case IDM_SETTING_LOCKWINDOWS: + nhlock_windows(!GetNHApp()->bWindowsLocked); + break; + + case IDM_HELP_LONG: + display_file(HELP, TRUE); + break; + + case IDM_HELP_COMMANDS: + display_file(SHELP, TRUE); + break; + + case IDM_HELP_HISTORY: + (void) dohistory(); + break; + + case IDM_HELP_INFO_CHAR: + (void) dowhatis(); + break; + + case IDM_HELP_INFO_KEY: + (void) dowhatdoes(); + break; + + case IDM_HELP_OPTIONS: + option_help(); + break; + + case IDM_HELP_OPTIONS_LONG: + display_file(OPTIONFILE, TRUE); + break; + + case IDM_HELP_EXTCMD: + (void) doextlist(); + break; + + case IDM_HELP_LICENSE: + display_file(LICENSE, TRUE); + break; + + case IDM_HELP_PORTHELP: + display_file(PORT_HELP, TRUE); + break; + + default: + return 1; + } + return 0; } // Mesage handler for about box. -LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - char buf[BUFSZ]; - TCHAR wbuf[BUFSZ]; - RECT main_rt, dlg_rt; - SIZE dlg_sz; + char buf[BUFSZ]; + TCHAR wbuf[BUFSZ]; + RECT main_rt, dlg_rt; + SIZE dlg_sz; - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - getversionstring(buf); - SetDlgItemText(hDlg, IDC_ABOUT_VERSION, NH_A2W(buf, wbuf, sizeof(wbuf))); + switch (message) { + case WM_INITDIALOG: + getversionstring(buf); + SetDlgItemText(hDlg, IDC_ABOUT_VERSION, + NH_A2W(buf, wbuf, sizeof(wbuf))); - SetDlgItemText(hDlg, IDC_ABOUT_COPYRIGHT, - NH_A2W( - COPYRIGHT_BANNER_A "\n" - COPYRIGHT_BANNER_B "\n" - COPYRIGHT_BANNER_C "\n" - COPYRIGHT_BANNER_D, - wbuf, - BUFSZ - ) ); - + SetDlgItemText(hDlg, IDC_ABOUT_COPYRIGHT, + NH_A2W(COPYRIGHT_BANNER_A "\n" COPYRIGHT_BANNER_B + "\n" COPYRIGHT_BANNER_C + "\n" COPYRIGHT_BANNER_D, + wbuf, BUFSZ)); - /* center dialog in the main window */ - GetWindowRect(GetNHApp()->hMainWnd, &main_rt); - GetWindowRect(hDlg, &dlg_rt); - dlg_sz.cx = dlg_rt.right - dlg_rt.left; - dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; + /* center dialog in the main window */ + GetWindowRect(GetNHApp()->hMainWnd, &main_rt); + GetWindowRect(hDlg, &dlg_rt); + dlg_sz.cx = dlg_rt.right - dlg_rt.left; + dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; - dlg_rt.left = (main_rt.left+main_rt.right-dlg_sz.cx)/2; - dlg_rt.right = dlg_rt.left + dlg_sz.cx; - dlg_rt.top = (main_rt.top+main_rt.bottom-dlg_sz.cy)/2; - dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; - MoveWindow( hDlg, - (main_rt.left+main_rt.right-dlg_sz.cx)/2, - (main_rt.top+main_rt.bottom-dlg_sz.cy)/2, - dlg_sz.cx, - dlg_sz.cy, - TRUE ); + dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; + dlg_rt.right = dlg_rt.left + dlg_sz.cx; + dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; + dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; + MoveWindow(hDlg, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, + (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, + dlg_sz.cy, TRUE); - return TRUE; + return TRUE; - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } - break; - } + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + break; + } return FALSE; } -void mswin_menu_check_intf_mode() +void +mswin_menu_check_intf_mode() { HMENU hMenu = GetMenu(GetNHApp()->hMainWnd); @@ -1050,157 +1012,150 @@ void mswin_menu_check_intf_mode() CheckMenuItem(hMenu, IDM_NHMODE, MF_UNCHECKED); } -void mswin_select_map_mode(int mode) +void +mswin_select_map_mode(int mode) { - PNHMainWindow data; - winid map_id; + PNHMainWindow data; + winid map_id; - map_id = WIN_MAP; - data = (PNHMainWindow)GetWindowLongPtr(GetNHApp()->hMainWnd, GWLP_USERDATA); + map_id = WIN_MAP; + data = + (PNHMainWindow) GetWindowLongPtr(GetNHApp()->hMainWnd, GWLP_USERDATA); - /* override for Rogue level */ - if( Is_rogue_level(&u.uz) && !IS_MAP_ASCII(mode) ) return; + /* override for Rogue level */ + if (Is_rogue_level(&u.uz) && !IS_MAP_ASCII(mode)) + return; - /* set map mode menu mark */ - if( IS_MAP_ASCII(mode) ) { - CheckMenuRadioItem( - GetMenu(GetNHApp()->hMainWnd), - IDM_MAP_TILES, - IDM_MAP_ASCII10X18, - mapmode2menuid( IS_MAP_FIT_TO_SCREEN(mode)? data->mapAcsiiModeSave : mode ), - MF_BYCOMMAND); - } else { - CheckMenuRadioItem( - GetMenu(GetNHApp()->hMainWnd), - IDM_MAP_TILES, - IDM_MAP_ASCII10X18, - mapmode2menuid( MAP_MODE_TILES ), - MF_BYCOMMAND); - } + /* set map mode menu mark */ + if (IS_MAP_ASCII(mode)) { + CheckMenuRadioItem( + GetMenu(GetNHApp()->hMainWnd), IDM_MAP_TILES, IDM_MAP_ASCII10X18, + mapmode2menuid(IS_MAP_FIT_TO_SCREEN(mode) ? data->mapAcsiiModeSave + : mode), + MF_BYCOMMAND); + } else { + CheckMenuRadioItem(GetMenu(GetNHApp()->hMainWnd), IDM_MAP_TILES, + IDM_MAP_ASCII10X18, mapmode2menuid(MAP_MODE_TILES), + MF_BYCOMMAND); + } - /* set fit-to-screen mode mark */ - CheckMenuItem( - GetMenu(GetNHApp()->hMainWnd), - IDM_MAP_FIT_TO_SCREEN, - MF_BYCOMMAND | - (IS_MAP_FIT_TO_SCREEN(mode)? MF_CHECKED : MF_UNCHECKED) - ); + /* set fit-to-screen mode mark */ + CheckMenuItem(GetMenu(GetNHApp()->hMainWnd), IDM_MAP_FIT_TO_SCREEN, + MF_BYCOMMAND | (IS_MAP_FIT_TO_SCREEN(mode) ? MF_CHECKED + : MF_UNCHECKED)); - if( IS_MAP_ASCII(iflags.wc_map_mode) && !IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { - data->mapAcsiiModeSave = iflags.wc_map_mode; - } + if (IS_MAP_ASCII(iflags.wc_map_mode) + && !IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { + data->mapAcsiiModeSave = iflags.wc_map_mode; + } - iflags.wc_map_mode = mode; - - /* - ** first, check if WIN_MAP has been inialized. - ** If not - attempt to retrieve it by type, then check it again - */ - if( map_id==WIN_ERR ) - map_id = mswin_winid_from_type(NHW_MAP); - if( map_id!=WIN_ERR ) - mswin_map_mode(mswin_hwnd_from_winid(map_id), mode); + iflags.wc_map_mode = mode; + + /* + ** first, check if WIN_MAP has been inialized. + ** If not - attempt to retrieve it by type, then check it again + */ + if (map_id == WIN_ERR) + map_id = mswin_winid_from_type(NHW_MAP); + if (map_id != WIN_ERR) + mswin_map_mode(mswin_hwnd_from_winid(map_id), mode); } static struct t_menu2mapmode { - int menuID; - int mapMode; -} _menu2mapmode[] = -{ - { IDM_MAP_TILES, MAP_MODE_TILES }, - { IDM_MAP_ASCII4X6, MAP_MODE_ASCII4x6 }, - { IDM_MAP_ASCII6X8, MAP_MODE_ASCII6x8 }, - { IDM_MAP_ASCII8X8, MAP_MODE_ASCII8x8 }, - { IDM_MAP_ASCII16X8, MAP_MODE_ASCII16x8 }, - { IDM_MAP_ASCII7X12, MAP_MODE_ASCII7x12 }, - { IDM_MAP_ASCII8X12, MAP_MODE_ASCII8x12 }, - { IDM_MAP_ASCII12X16, MAP_MODE_ASCII12x16 }, - { IDM_MAP_ASCII16X12, MAP_MODE_ASCII16x12 }, - { IDM_MAP_ASCII10X18, MAP_MODE_ASCII10x18 }, - { IDM_MAP_FIT_TO_SCREEN, MAP_MODE_ASCII_FIT_TO_SCREEN }, - { -1, -1 } -}; + int menuID; + int mapMode; +} _menu2mapmode[] = { { IDM_MAP_TILES, MAP_MODE_TILES }, + { IDM_MAP_ASCII4X6, MAP_MODE_ASCII4x6 }, + { IDM_MAP_ASCII6X8, MAP_MODE_ASCII6x8 }, + { IDM_MAP_ASCII8X8, MAP_MODE_ASCII8x8 }, + { IDM_MAP_ASCII16X8, MAP_MODE_ASCII16x8 }, + { IDM_MAP_ASCII7X12, MAP_MODE_ASCII7x12 }, + { IDM_MAP_ASCII8X12, MAP_MODE_ASCII8x12 }, + { IDM_MAP_ASCII12X16, MAP_MODE_ASCII12x16 }, + { IDM_MAP_ASCII16X12, MAP_MODE_ASCII16x12 }, + { IDM_MAP_ASCII10X18, MAP_MODE_ASCII10x18 }, + { IDM_MAP_FIT_TO_SCREEN, MAP_MODE_ASCII_FIT_TO_SCREEN }, + { -1, -1 } }; -int menuid2mapmode(int menuid) +int +menuid2mapmode(int menuid) { - struct t_menu2mapmode* p; - for( p = _menu2mapmode; p->mapMode!=-1; p++ ) - if(p->menuID==menuid ) return p->mapMode; - return -1; + struct t_menu2mapmode *p; + for (p = _menu2mapmode; p->mapMode != -1; p++) + if (p->menuID == menuid) + return p->mapMode; + return -1; } -int mapmode2menuid(int map_mode) +int +mapmode2menuid(int map_mode) { - struct t_menu2mapmode* p; - for( p = _menu2mapmode; p->mapMode!=-1; p++ ) - if(p->mapMode==map_mode ) return p->menuID; - return -1; + struct t_menu2mapmode *p; + for (p = _menu2mapmode; p->mapMode != -1; p++) + if (p->mapMode == map_mode) + return p->menuID; + return -1; } -void nhlock_windows( BOOL lock ) +void +nhlock_windows(BOOL lock) { - int i; + int i; - /* go through the windows list and adjust sizes */ - for( i=0; iwindowlist[i].win) && !GetNHApp()->windowlist[i].dead) { - DWORD style; - style = GetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE); - if( lock ) style &= ~WS_CAPTION; - else style |= WS_CAPTION; - SetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE, style); - SetWindowPos( - GetNHApp()->windowlist[i].win, - NULL, - 0, - 0, - 0, - 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED - ); - } - } + /* go through the windows list and adjust sizes */ + for (i = 0; i < MAXWINDOWS; i++) { + if (IsWindow(GetNHApp()->windowlist[i].win) + && !GetNHApp()->windowlist[i].dead) { + DWORD style; + style = GetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE); + if (lock) + style &= ~WS_CAPTION; + else + style |= WS_CAPTION; + SetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE, style); + SetWindowPos(GetNHApp()->windowlist[i].win, NULL, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER + | SWP_FRAMECHANGED); + } + } - /* update menu */ - GetNHApp()->bWindowsLocked = lock; - CheckMenuItem( - GetMenu(GetNHApp()->hMainWnd), - IDM_SETTING_LOCKWINDOWS, - MF_BYCOMMAND | - (lock? MF_CHECKED : MF_UNCHECKED) - ); + /* update menu */ + GetNHApp()->bWindowsLocked = lock; + CheckMenuItem(GetMenu(GetNHApp()->hMainWnd), IDM_SETTING_LOCKWINDOWS, + MF_BYCOMMAND | (lock ? MF_CHECKED : MF_UNCHECKED)); } // returns strdup() created pointer - callee assumes the ownership #define TEXT_BUFFER_SIZE 4096 -char* +char * nh_compose_ascii_screenshot() { - char* retval; - PMSNHMsgGetText text; + char *retval; + PMSNHMsgGetText text; - retval = (char*)malloc(3*TEXT_BUFFER_SIZE); + retval = (char *) malloc(3 * TEXT_BUFFER_SIZE); - text = (PMSNHMsgGetText)malloc(sizeof(MSNHMsgGetText) + TEXT_BUFFER_SIZE); - text->max_size = TEXT_BUFFER_SIZE-1; /* make sure we always have 0 at the end of the buffer */ + text = + (PMSNHMsgGetText) malloc(sizeof(MSNHMsgGetText) + TEXT_BUFFER_SIZE); + text->max_size = + TEXT_BUFFER_SIZE + - 1; /* make sure we always have 0 at the end of the buffer */ - ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); - SendMessage( mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_GETTEXT, (LPARAM)text ); - strcpy(retval, text->buffer); + ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_GETTEXT, (LPARAM) text); + strcpy(retval, text->buffer); - ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); - SendMessage( mswin_hwnd_from_winid(WIN_MAP), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_GETTEXT, (LPARAM)text ); - strcat(retval, text->buffer); + ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); + SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_GETTEXT, (LPARAM) text); + strcat(retval, text->buffer); - ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); - SendMessage( mswin_hwnd_from_winid(WIN_STATUS), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_GETTEXT, (LPARAM)text ); - strcat(retval, text->buffer); + ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); + SendMessage(mswin_hwnd_from_winid(WIN_STATUS), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_GETTEXT, (LPARAM) text); + strcat(retval, text->buffer); - free( text ); - return retval; + free(text); + return retval; } - - diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index 8037898dc..9a0420a15 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhmap.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhmap.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.47 $ */ /* NetHack 3.6 mhmap.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.37 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -19,22 +19,22 @@ extern short glyph2tile[]; /* map window data */ typedef struct mswin_nethack_map_window { - int map[COLNO][ROWNO]; /* glyph map */ + int map[COLNO][ROWNO]; /* glyph map */ - int mapMode; /* current map mode */ - boolean bAsciiMode; /* switch ASCII/tiled mode */ - boolean bFitToScreenMode; /* switch Fit map to screen mode on/off */ - int xPos, yPos; /* scroll position */ - int xPageSize, yPageSize; /* scroll page size */ - int xCur, yCur; /* position of the cursor */ - int xScrTile, yScrTile; /* size of display tile */ - POINT map_orig; /* map origin point */ + int mapMode; /* current map mode */ + boolean bAsciiMode; /* switch ASCII/tiled mode */ + boolean bFitToScreenMode; /* switch Fit map to screen mode on/off */ + int xPos, yPos; /* scroll position */ + int xPageSize, yPageSize; /* scroll page size */ + int xCur, yCur; /* position of the cursor */ + int xScrTile, yScrTile; /* size of display tile */ + POINT map_orig; /* map origin point */ - HFONT hMapFont; /* font for ASCII mode */ + HFONT hMapFont; /* font for ASCII mode */ } NHMapWindow, *PNHMapWindow; static TCHAR szNHMapWindowClass[] = TEXT("MSNethackMapWndClass"); -LRESULT CALLBACK MapWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK MapWndProc(HWND, UINT, WPARAM, LPARAM); static void register_map_window_class(void); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -43,850 +43,868 @@ static void onPaint(HWND hWnd); static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); static void nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) -static void nhglyph2charcolor(short glyph, uchar* ch, int* color); +static void nhglyph2charcolor(short glyph, uchar *ch, int *color); #endif -HWND mswin_init_map_window () { - static int run_once = 0; - HWND ret; - RECT rt; +HWND +mswin_init_map_window() +{ + static int run_once = 0; + HWND ret; + RECT rt; - if( !run_once ) { - register_map_window_class(); - run_once = 1; - } + if (!run_once) { + register_map_window_class(); + run_once = 1; + } - /* get window position */ - if( GetNHApp()->bAutoLayout ) { - SetRect( &rt, 0, 0, 0, 0); - } else { - mswin_get_window_placement(NHW_MAP, &rt); - } + /* get window position */ + if (GetNHApp()->bAutoLayout) { + SetRect(&rt, 0, 0, 0, 0); + } else { + mswin_get_window_placement(NHW_MAP, &rt); + } - /* create map window object */ - ret = CreateWindow( - szNHMapWindowClass, /* registered class name */ - NULL, /* window name */ - WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_CLIPSIBLINGS | WS_SIZEBOX, /* window style */ - rt.left, /* horizontal position of window */ - rt.top, /* vertical position of window */ - rt.right - rt.left, /* window width */ - rt.bottom - rt.top, /* window height */ - GetNHApp()->hMainWnd, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL ); /* window-creation data */ - if( !ret ) { - panic("Cannot create map window"); - } + /* create map window object */ + ret = CreateWindow( + szNHMapWindowClass, /* registered class name */ + NULL, /* window name */ + WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_CLIPSIBLINGS + | WS_SIZEBOX, /* window style */ + rt.left, /* horizontal position of window */ + rt.top, /* vertical position of window */ + rt.right - rt.left, /* window width */ + rt.bottom - rt.top, /* window height */ + GetNHApp()->hMainWnd, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL); /* window-creation data */ + if (!ret) { + panic("Cannot create map window"); + } - /* Set window caption */ - SetWindowText(ret, "Map"); + /* Set window caption */ + SetWindowText(ret, "Map"); - return ret; + return ret; } -void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) +void +mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) { - PNHMapWindow data; - RECT client_rt; - SCROLLINFO si; - SIZE wnd_size; - LOGFONT lgfnt; + PNHMapWindow data; + RECT client_rt; + SCROLLINFO si; + SIZE wnd_size; + LOGFONT lgfnt; - /* check arguments */ - if( !IsWindow(hWnd) || - !lpsz || - lpsz->cx<=0 || - lpsz->cy<=0 ) return; + /* check arguments */ + if (!IsWindow(hWnd) || !lpsz || lpsz->cx <= 0 || lpsz->cy <= 0) + return; - /* calculate window size */ - GetClientRect(hWnd, &client_rt); - wnd_size.cx = client_rt.right - client_rt.left; - wnd_size.cy = client_rt.bottom - client_rt.top; - - /* set new screen tile size */ - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - data->xScrTile = - max(1, (data->bFitToScreenMode? wnd_size.cx : lpsz->cx) / COLNO); - data->yScrTile = - max(1, (data->bFitToScreenMode? wnd_size.cy : lpsz->cy) / ROWNO); + /* calculate window size */ + GetClientRect(hWnd, &client_rt); + wnd_size.cx = client_rt.right - client_rt.left; + wnd_size.cy = client_rt.bottom - client_rt.top; - /* set map origin point */ - data->map_orig.x = max(0, client_rt.left + (wnd_size.cx - data->xScrTile*COLNO)/2 ); - data->map_orig.y = max(0, client_rt.top + (wnd_size.cy - data->yScrTile*ROWNO)/2 ); + /* set new screen tile size */ + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + data->xScrTile = + max(1, (data->bFitToScreenMode ? wnd_size.cx : lpsz->cx) / COLNO); + data->yScrTile = + max(1, (data->bFitToScreenMode ? wnd_size.cy : lpsz->cy) / ROWNO); - data->map_orig.x -= data->map_orig.x % data->xScrTile; - data->map_orig.y -= data->map_orig.y % data->yScrTile; + /* set map origin point */ + data->map_orig.x = + max(0, client_rt.left + (wnd_size.cx - data->xScrTile * COLNO) / 2); + data->map_orig.y = + max(0, client_rt.top + (wnd_size.cy - data->yScrTile * ROWNO) / 2); - /* adjust horizontal scroll bar */ - if( data->bFitToScreenMode ) - data->xPageSize = COLNO+1; /* disable scroll bar */ - else - data->xPageSize = wnd_size.cx/data->xScrTile; + data->map_orig.x -= data->map_orig.x % data->xScrTile; + data->map_orig.y -= data->map_orig.y % data->yScrTile; - if( data->xPageSize >= COLNO ) { - data->xPos = 0; - GetNHApp()->bNoHScroll = TRUE; - } else { - GetNHApp()->bNoHScroll = FALSE; - data->xPos = max(0, min(COLNO-data->xPageSize+1, u.ux - data->xPageSize/2)); - } + /* adjust horizontal scroll bar */ + if (data->bFitToScreenMode) + data->xPageSize = COLNO + 1; /* disable scroll bar */ + else + data->xPageSize = wnd_size.cx / data->xScrTile; - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = COLNO; - si.nPage = data->xPageSize; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + if (data->xPageSize >= COLNO) { + data->xPos = 0; + GetNHApp()->bNoHScroll = TRUE; + } else { + GetNHApp()->bNoHScroll = FALSE; + data->xPos = max( + 0, min(COLNO - data->xPageSize + 1, u.ux - data->xPageSize / 2)); + } - /* adjust vertical scroll bar */ - if( data->bFitToScreenMode ) - data->yPageSize = ROWNO+1; /* disable scroll bar */ - else - data->yPageSize = wnd_size.cy/data->yScrTile; + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = COLNO; + si.nPage = data->xPageSize; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); - if( data->yPageSize >= ROWNO ) { - data->yPos = 0; - GetNHApp()->bNoVScroll = TRUE; - } else { - GetNHApp()->bNoVScroll = FALSE; - data->yPos = max(0, min(ROWNO-data->yPageSize+1, u.uy - data->yPageSize/2)); - } + /* adjust vertical scroll bar */ + if (data->bFitToScreenMode) + data->yPageSize = ROWNO + 1; /* disable scroll bar */ + else + data->yPageSize = wnd_size.cy / data->yScrTile; - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = ROWNO; - si.nPage = data->yPageSize; - si.nPos = data->yPos; + if (data->yPageSize >= ROWNO) { + data->yPos = 0; + GetNHApp()->bNoVScroll = TRUE; + } else { + GetNHApp()->bNoVScroll = FALSE; + data->yPos = max( + 0, min(ROWNO - data->yPageSize + 1, u.uy - data->yPageSize / 2)); + } + + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = ROWNO; + si.nPage = data->yPageSize; + si.nPos = data->yPos; SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - /* create font */ - if( data->hMapFont ) DeleteObject(data->hMapFont); - ZeroMemory(&lgfnt, sizeof(lgfnt)); - lgfnt.lfHeight = -data->yScrTile; // height of font - lgfnt.lfWidth = -data->xScrTile; // average character width - lgfnt.lfEscapement = 0; // angle of escapement - lgfnt.lfOrientation = 0; // base-line orientation angle - lgfnt.lfWeight = FW_NORMAL; // font weight - lgfnt.lfItalic = FALSE; // italic attribute option - lgfnt.lfUnderline = FALSE; // underline attribute option - lgfnt.lfStrikeOut = FALSE; // strikeout attribute option - lgfnt.lfCharSet = mswin_charset(); // character set identifier - lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision - lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision - lgfnt.lfQuality = DEFAULT_QUALITY; // output quality - if( iflags.wc_font_map && - *iflags.wc_font_map ) { - lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family - NH_A2W(iflags.wc_font_map, lgfnt.lfFaceName, LF_FACESIZE); - } else { - lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family - NH_A2W(NHMAP_FONT_NAME, lgfnt.lfFaceName, LF_FACESIZE); - } - data->hMapFont = CreateFontIndirect(&lgfnt); + /* create font */ + if (data->hMapFont) + DeleteObject(data->hMapFont); + ZeroMemory(&lgfnt, sizeof(lgfnt)); + lgfnt.lfHeight = -data->yScrTile; // height of font + lgfnt.lfWidth = -data->xScrTile; // average character width + lgfnt.lfEscapement = 0; // angle of escapement + lgfnt.lfOrientation = 0; // base-line orientation angle + lgfnt.lfWeight = FW_NORMAL; // font weight + lgfnt.lfItalic = FALSE; // italic attribute option + lgfnt.lfUnderline = FALSE; // underline attribute option + lgfnt.lfStrikeOut = FALSE; // strikeout attribute option + lgfnt.lfCharSet = mswin_charset(); // character set identifier + lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision + lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision + lgfnt.lfQuality = DEFAULT_QUALITY; // output quality + if (iflags.wc_font_map && *iflags.wc_font_map) { + lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family + NH_A2W(iflags.wc_font_map, lgfnt.lfFaceName, LF_FACESIZE); + } else { + lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family + NH_A2W(NHMAP_FONT_NAME, lgfnt.lfFaceName, LF_FACESIZE); + } + data->hMapFont = CreateFontIndirect(&lgfnt); - mswin_cliparound(data->xCur, data->yCur); + mswin_cliparound(data->xCur, data->yCur); - if(redraw) InvalidateRect(hWnd, NULL, TRUE); + if (redraw) + InvalidateRect(hWnd, NULL, TRUE); } /* set map mode */ -int mswin_map_mode(HWND hWnd, int mode) +int +mswin_map_mode(HWND hWnd, int mode) { - PNHMapWindow data; - int oldMode; - SIZE mapSize; + PNHMapWindow data; + int oldMode; + SIZE mapSize; - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if( mode == data->mapMode ) return mode; - - oldMode = data->mapMode; - data->mapMode = mode; + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (mode == data->mapMode) + return mode; - switch( data->mapMode ) { + oldMode = data->mapMode; + data->mapMode = mode; - case MAP_MODE_ASCII4x6: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 4*COLNO; - mapSize.cy = 6*ROWNO; - break; + switch (data->mapMode) { + case MAP_MODE_ASCII4x6: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 4 * COLNO; + mapSize.cy = 6 * ROWNO; + break; - case MAP_MODE_ASCII6x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 6*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII6x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 6 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII8x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 8*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII8x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 8 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII16x8: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 16*COLNO; - mapSize.cy = 8*ROWNO; - break; + case MAP_MODE_ASCII16x8: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 16 * COLNO; + mapSize.cy = 8 * ROWNO; + break; - case MAP_MODE_ASCII7x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 7*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII7x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 7 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII8x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 8*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII8x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 8 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII16x12: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 16*COLNO; - mapSize.cy = 12*ROWNO; - break; + case MAP_MODE_ASCII16x12: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 16 * COLNO; + mapSize.cy = 12 * ROWNO; + break; - case MAP_MODE_ASCII12x16: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 12*COLNO; - mapSize.cy = 16*ROWNO; - break; + case MAP_MODE_ASCII12x16: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 12 * COLNO; + mapSize.cy = 16 * ROWNO; + break; - case MAP_MODE_ASCII10x18: - data->bAsciiMode = TRUE; - data->bFitToScreenMode = FALSE; - mapSize.cx = 10*COLNO; - mapSize.cy = 18*ROWNO; - break; + case MAP_MODE_ASCII10x18: + data->bAsciiMode = TRUE; + data->bFitToScreenMode = FALSE; + mapSize.cx = 10 * COLNO; + mapSize.cy = 18 * ROWNO; + break; - case MAP_MODE_ASCII_FIT_TO_SCREEN: { - RECT client_rt; - GetClientRect(hWnd, &client_rt); - mapSize.cx = client_rt.right - client_rt.left; - mapSize.cy = client_rt.bottom - client_rt.top; + case MAP_MODE_ASCII_FIT_TO_SCREEN: { + RECT client_rt; + GetClientRect(hWnd, &client_rt); + mapSize.cx = client_rt.right - client_rt.left; + mapSize.cy = client_rt.bottom - client_rt.top; - data->bAsciiMode = TRUE; - data->bFitToScreenMode = TRUE; - } break; + data->bAsciiMode = TRUE; + data->bFitToScreenMode = TRUE; + } break; - case MAP_MODE_TILES_FIT_TO_SCREEN: { - RECT client_rt; - GetClientRect(hWnd, &client_rt); - mapSize.cx = client_rt.right - client_rt.left; - mapSize.cy = client_rt.bottom - client_rt.top; + case MAP_MODE_TILES_FIT_TO_SCREEN: { + RECT client_rt; + GetClientRect(hWnd, &client_rt); + mapSize.cx = client_rt.right - client_rt.left; + mapSize.cy = client_rt.bottom - client_rt.top; - data->bAsciiMode = FALSE; - data->bFitToScreenMode = TRUE; - } break; + data->bAsciiMode = FALSE; + data->bFitToScreenMode = TRUE; + } break; - case MAP_MODE_TILES: - default: - data->bAsciiMode = FALSE; - data->bFitToScreenMode = FALSE; - mapSize.cx = GetNHApp()->mapTile_X*COLNO; - mapSize.cy = GetNHApp()->mapTile_Y*ROWNO; - break; - } + case MAP_MODE_TILES: + default: + data->bAsciiMode = FALSE; + data->bFitToScreenMode = FALSE; + mapSize.cx = GetNHApp()->mapTile_X * COLNO; + mapSize.cy = GetNHApp()->mapTile_Y * ROWNO; + break; + } - mswin_map_stretch(hWnd, &mapSize, TRUE); + mswin_map_stretch(hWnd, &mapSize, TRUE); - mswin_update_inventory(); /* for perm_invent to hide/show tiles */ + mswin_update_inventory(); /* for perm_invent to hide/show tiles */ - return oldMode; + return oldMode; } /* register window class for map window */ -void register_map_window_class() +void +register_map_window_class() { - WNDCLASS wcex; - ZeroMemory( &wcex, sizeof(wcex)); + WNDCLASS wcex; + ZeroMemory(&wcex, sizeof(wcex)); - /* window class */ - wcex.style = CS_NOCLOSE | CS_DBLCLKS; - wcex.lpfnWndProc = (WNDPROC)MapWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); /* set backgroup here */ - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szNHMapWindowClass; + /* window class */ + wcex.style = CS_NOCLOSE | CS_DBLCLKS; + wcex.lpfnWndProc = (WNDPROC) MapWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = + CreateSolidBrush(RGB(0, 0, 0)); /* set backgroup here */ + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szNHMapWindowClass; - if( !RegisterClass(&wcex) ) { - panic("cannot register Map window class"); - } + if (!RegisterClass(&wcex)) { + panic("cannot register Map window class"); + } } - -/* map window procedure */ -LRESULT CALLBACK MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +/* map window procedure */ +LRESULT CALLBACK +MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (message) - { - case WM_CREATE: - onCreate( hWnd, wParam, lParam ); - break; + PNHMapWindow data; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (message) { + case WM_CREATE: + onCreate(hWnd, wParam, lParam); + break; - case WM_PAINT: - onPaint(hWnd); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SETFOCUS: - /* transfer focus back to the main window */ - SetFocus(GetNHApp()->hMainWnd); - break; + case WM_PAINT: + onPaint(hWnd); + break; - case WM_HSCROLL: - onMSNH_HScroll(hWnd, wParam, lParam); - break; + case WM_SETFOCUS: + /* transfer focus back to the main window */ + SetFocus(GetNHApp()->hMainWnd); + break; - case WM_VSCROLL: - onMSNH_VScroll(hWnd, wParam, lParam); - break; + case WM_HSCROLL: + onMSNH_HScroll(hWnd, wParam, lParam); + break; - case WM_SIZE: - { - RECT rt; - SIZE size; + case WM_VSCROLL: + onMSNH_VScroll(hWnd, wParam, lParam); + break; - if( data->bFitToScreenMode ) { - size.cx = LOWORD(lParam); - size.cy = HIWORD(lParam); - } else { - /* mapping factor is unchaged we just need to adjust scroll bars */ - size.cx = data->xScrTile*COLNO; - size.cy = data->yScrTile*ROWNO; - } - mswin_map_stretch(hWnd, &size, TRUE); + case WM_SIZE: { + RECT rt; + SIZE size; - /* update window placement */ - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_MAP, &rt); - } - break; + if (data->bFitToScreenMode) { + size.cx = LOWORD(lParam); + size.cy = HIWORD(lParam); + } else { + /* mapping factor is unchaged we just need to adjust scroll bars + */ + size.cx = data->xScrTile * COLNO; + size.cy = data->yScrTile * ROWNO; + } + mswin_map_stretch(hWnd, &size, TRUE); - case WM_MOVE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_MAP, &rt); - } return FALSE; + /* update window placement */ + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_MAP, &rt); + } break; - case WM_LBUTTONDOWN: - NHEVENT_MS( - CLICK_1, - max(0, min(COLNO, data->xPos + (LOWORD(lParam)-data->map_orig.x)/data->xScrTile)), - max(0, min(ROWNO, data->yPos + (HIWORD(lParam)-data->map_orig.y)/data->yScrTile)) - ); - return 0; + case WM_MOVE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_MAP, &rt); + } + return FALSE; - case WM_LBUTTONDBLCLK : - case WM_RBUTTONDOWN: - NHEVENT_MS( - CLICK_2, - max(0, min(COLNO, data->xPos + (LOWORD(lParam)-data->map_orig.x)/data->xScrTile)), - max(0, min(ROWNO, data->yPos + (HIWORD(lParam)-data->map_orig.y)/data->yScrTile)) - ); - return 0; + case WM_LBUTTONDOWN: + NHEVENT_MS(CLICK_1, + max(0, min(COLNO, data->xPos + + (LOWORD(lParam) - data->map_orig.x) + / data->xScrTile)), + max(0, min(ROWNO, data->yPos + + (HIWORD(lParam) - data->map_orig.y) + / data->yScrTile))); + return 0; - case WM_DESTROY: - if( data->hMapFont ) DeleteObject(data->hMapFont); - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - break; + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: + NHEVENT_MS(CLICK_2, + max(0, min(COLNO, data->xPos + + (LOWORD(lParam) - data->map_orig.x) + / data->xScrTile)), + max(0, min(ROWNO, data->yPos + + (HIWORD(lParam) - data->map_orig.y) + / data->yScrTile))); + return 0; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + case WM_DESTROY: + if (data->hMapFont) + DeleteObject(data->hMapFont); + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; } /* on WM_COMMAND */ -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - RECT rt; + PNHMapWindow data; + RECT rt; - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch(wParam) { - case MSNH_MSG_PRINT_GLYPH: - { - PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph)lParam; - data->map[msg_data->x][msg_data->y] = msg_data->glyph; + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (wParam) { + case MSNH_MSG_PRINT_GLYPH: { + PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam; + data->map[msg_data->x][msg_data->y] = msg_data->glyph; - /* invalidate the update area */ - nhcoord2display(data, msg_data->x, msg_data->y, &rt); - InvalidateRect(hWnd, &rt, TRUE); - } - break; + /* invalidate the update area */ + nhcoord2display(data, msg_data->x, msg_data->y, &rt); + InvalidateRect(hWnd, &rt, TRUE); + } break; - case MSNH_MSG_CLIPAROUND: - { - PMSNHMsgClipAround msg_data = (PMSNHMsgClipAround)lParam; - int x, y; - BOOL scroll_x, scroll_y; - int mcam = iflags.wc_scroll_margin; + case MSNH_MSG_CLIPAROUND: { + PMSNHMsgClipAround msg_data = (PMSNHMsgClipAround) lParam; + int x, y; + BOOL scroll_x, scroll_y; + int mcam = iflags.wc_scroll_margin; - /* calculate if you should clip around */ - scroll_x = - !GetNHApp()->bNoHScroll && - ( msg_data->x<(data->xPos+mcam) || - msg_data->x>(data->xPos+data->xPageSize-mcam) ); - scroll_y = - !GetNHApp()->bNoVScroll && - ( msg_data->y<(data->yPos+mcam) || - msg_data->y>(data->yPos+data->yPageSize-mcam) ); - - mcam += iflags.wc_scroll_amount - 1; - /* get page size and center horizontally on x-position */ - if( scroll_x ) { - if( data->xPageSize<=2*mcam ) { - x = max(0, min(COLNO, msg_data->x - data->xPageSize/2)); - } else if( msg_data->x < data->xPos+data->xPageSize/2 ) { - x = max(0, min(COLNO, msg_data->x - mcam)); - } else { - x = max(0, min(COLNO, msg_data->x - data->xPageSize + mcam)); - } - SendMessage( hWnd, WM_HSCROLL, (WPARAM)MAKELONG(SB_THUMBTRACK, x), (LPARAM)NULL ); - } + /* calculate if you should clip around */ + scroll_x = + !GetNHApp()->bNoHScroll + && (msg_data->x < (data->xPos + mcam) + || msg_data->x > (data->xPos + data->xPageSize - mcam)); + scroll_y = + !GetNHApp()->bNoVScroll + && (msg_data->y < (data->yPos + mcam) + || msg_data->y > (data->yPos + data->yPageSize - mcam)); - /* get page size and center vertically on y-position */ - if( scroll_y ) { - if( data->yPageSize<=2*mcam ) { - y = max(0, min(ROWNO, msg_data->y - data->yPageSize/2)); - } else if( msg_data->y < data->yPos+data->yPageSize/2 ) { - y = max(0, min(ROWNO, msg_data->y - mcam)); - } else { - y = max(0, min(ROWNO, msg_data->y - data->yPageSize + mcam)); - } - SendMessage( hWnd, WM_VSCROLL, (WPARAM)MAKELONG(SB_THUMBTRACK, y), (LPARAM)NULL ); - } - } - break; + mcam += iflags.wc_scroll_amount - 1; + /* get page size and center horizontally on x-position */ + if (scroll_x) { + if (data->xPageSize <= 2 * mcam) { + x = max(0, min(COLNO, msg_data->x - data->xPageSize / 2)); + } else if (msg_data->x < data->xPos + data->xPageSize / 2) { + x = max(0, min(COLNO, msg_data->x - mcam)); + } else { + x = max(0, min(COLNO, msg_data->x - data->xPageSize + mcam)); + } + SendMessage(hWnd, WM_HSCROLL, (WPARAM) MAKELONG(SB_THUMBTRACK, x), + (LPARAM) NULL); + } - case MSNH_MSG_CLEAR_WINDOW: - { - int i, j; - for(i=0; imap[i][j] = -1; - } - InvalidateRect(hWnd, NULL, TRUE); - } break; + /* get page size and center vertically on y-position */ + if (scroll_y) { + if (data->yPageSize <= 2 * mcam) { + y = max(0, min(ROWNO, msg_data->y - data->yPageSize / 2)); + } else if (msg_data->y < data->yPos + data->yPageSize / 2) { + y = max(0, min(ROWNO, msg_data->y - mcam)); + } else { + y = max(0, min(ROWNO, msg_data->y - data->yPageSize + mcam)); + } + SendMessage(hWnd, WM_VSCROLL, (WPARAM) MAKELONG(SB_THUMBTRACK, y), + (LPARAM) NULL); + } + } break; - case MSNH_MSG_CURSOR: - { - PMSNHMsgCursor msg_data = (PMSNHMsgCursor)lParam; - HDC hdc; - RECT rt; + case MSNH_MSG_CLEAR_WINDOW: { + int i, j; + for (i = 0; i < COLNO; i++) + for (j = 0; j < ROWNO; j++) { + data->map[i][j] = -1; + } + InvalidateRect(hWnd, NULL, TRUE); + } break; - /* move focus rectangle at the cursor postion */ - hdc = GetDC(hWnd); + case MSNH_MSG_CURSOR: { + PMSNHMsgCursor msg_data = (PMSNHMsgCursor) lParam; + HDC hdc; + RECT rt; - nhcoord2display(data, data->xCur, data->yCur, &rt); - if( data->bAsciiMode ) { - PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, DSTINVERT); - } else { - DrawFocusRect(hdc, &rt); - } - - data->xCur = msg_data->x; - data->yCur = msg_data->y; + /* move focus rectangle at the cursor postion */ + hdc = GetDC(hWnd); - nhcoord2display(data, data->xCur, data->yCur, &rt); - if( data->bAsciiMode ) { - PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, DSTINVERT); - } else { - DrawFocusRect(hdc, &rt); - } + nhcoord2display(data, data->xCur, data->yCur, &rt); + if (data->bAsciiMode) { + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, DSTINVERT); + } else { + DrawFocusRect(hdc, &rt); + } - ReleaseDC(hWnd, hdc); - } break; + data->xCur = msg_data->x; + data->yCur = msg_data->y; - case MSNH_MSG_GETTEXT: { - PMSNHMsgGetText msg_data = (PMSNHMsgGetText)lParam; - size_t index; - int col, row; - int color; - unsigned special; - int mgch; + nhcoord2display(data, data->xCur, data->yCur, &rt); + if (data->bAsciiMode) { + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, DSTINVERT); + } else { + DrawFocusRect(hdc, &rt); + } - index = 0; - for( row=0; row=msg_data->max_size ) break; - if( data->map[col][row] == -1 ) { - mgch = ' '; - } else { - (void)mapglyph(data->map[col][row], - &mgch, &color, - &special, col, row); - } - msg_data->buffer[index] = mgch; - index++; - } - if( index>=msg_data->max_size-1 ) break; - msg_data->buffer[index++] = '\r'; - msg_data->buffer[index++] = '\n'; - } - } break; + ReleaseDC(hWnd, hdc); + } break; - } /* end switch(wParam) */ + case MSNH_MSG_GETTEXT: { + PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam; + size_t index; + int col, row; + int color; + unsigned special; + int mgch; + + index = 0; + for (row = 0; row < ROWNO; row++) { + for (col = 0; col < COLNO; col++) { + if (index >= msg_data->max_size) + break; + if (data->map[col][row] == -1) { + mgch = ' '; + } else { + (void) mapglyph(data->map[col][row], &mgch, &color, + &special, col, row); + } + msg_data->buffer[index] = mgch; + index++; + } + if (index >= msg_data->max_size - 1) + break; + msg_data->buffer[index++] = '\r'; + msg_data->buffer[index++] = '\n'; + } + } break; + + } /* end switch(wParam) */ } /* on WM_CREATE */ -void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - int i,j; + PNHMapWindow data; + int i, j; - UNREFERENCED_PARAMETER(wParam); - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(wParam); + UNREFERENCED_PARAMETER(lParam); - /* set window data */ - data = (PNHMapWindow)malloc(sizeof(NHMapWindow)); - if( !data ) panic("out of memory"); + /* set window data */ + data = (PNHMapWindow) malloc(sizeof(NHMapWindow)); + if (!data) + panic("out of memory"); - ZeroMemory(data, sizeof(NHMapWindow)); - for(i=0; imap[i][j] = -1; - } + ZeroMemory(data, sizeof(NHMapWindow)); + for (i = 0; i < COLNO; i++) + for (j = 0; j < ROWNO; j++) { + data->map[i][j] = -1; + } - data->bAsciiMode = FALSE; + data->bAsciiMode = FALSE; - data->xScrTile = GetNHApp()->mapTile_X; - data->yScrTile = GetNHApp()->mapTile_Y; + data->xScrTile = GetNHApp()->mapTile_X; + data->yScrTile = GetNHApp()->mapTile_Y; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); } /* on WM_PAINT */ -void onPaint(HWND hWnd) +void +onPaint(HWND hWnd) { - PNHMapWindow data; - PAINTSTRUCT ps; - HDC hDC; - HDC tileDC; - HGDIOBJ saveBmp; - RECT paint_rt; - int i, j; + PNHMapWindow data; + PAINTSTRUCT ps; + HDC hDC; + HDC tileDC; + HGDIOBJ saveBmp; + RECT paint_rt; + int i, j; - /* get window data */ - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + /* get window data */ + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - hDC = BeginPaint(hWnd, &ps); + hDC = BeginPaint(hWnd, &ps); - /* calculate paint rectangle */ - if( !IsRectEmpty(&ps.rcPaint) ) { - /* calculate paint rectangle */ - paint_rt.left = max(data->xPos + (ps.rcPaint.left - data->map_orig.x)/data->xScrTile, 0); - paint_rt.top = max(data->yPos + (ps.rcPaint.top - data->map_orig.y)/data->yScrTile, 0); - paint_rt.right = min(data->xPos + (ps.rcPaint.right - data->map_orig.x)/data->xScrTile+1, COLNO); - paint_rt.bottom = min(data->yPos + (ps.rcPaint.bottom - data->map_orig.y)/data->yScrTile+1, ROWNO); + /* calculate paint rectangle */ + if (!IsRectEmpty(&ps.rcPaint)) { + /* calculate paint rectangle */ + paint_rt.left = + max(data->xPos + + (ps.rcPaint.left - data->map_orig.x) / data->xScrTile, + 0); + paint_rt.top = max( + data->yPos + (ps.rcPaint.top - data->map_orig.y) / data->yScrTile, + 0); + paint_rt.right = min( + data->xPos + + (ps.rcPaint.right - data->map_orig.x) / data->xScrTile + 1, + COLNO); + paint_rt.bottom = min( + data->yPos + + (ps.rcPaint.bottom - data->map_orig.y) / data->yScrTile + 1, + ROWNO); - if( data->bAsciiMode || Is_rogue_level(&u.uz) ) { - /* You enter a VERY primitive world! */ - HGDIOBJ oldFont; + if (data->bAsciiMode || Is_rogue_level(&u.uz)) { + /* You enter a VERY primitive world! */ + HGDIOBJ oldFont; - oldFont = SelectObject(hDC, data->hMapFont); - SetBkMode(hDC, TRANSPARENT); + oldFont = SelectObject(hDC, data->hMapFont); + SetBkMode(hDC, TRANSPARENT); - /* draw the map */ - for(i=paint_rt.left; imap[i][j]>=0) { - char ch; - TCHAR wch; - RECT glyph_rect; - int color; - unsigned special; - int mgch; - HBRUSH back_brush; - COLORREF OldFg; + /* draw the map */ + for (i = paint_rt.left; i < paint_rt.right; i++) + for (j = paint_rt.top; j < paint_rt.bottom; j++) + if (data->map[i][j] >= 0) { + char ch; + TCHAR wch; + RECT glyph_rect; + int color; + unsigned special; + int mgch; + HBRUSH back_brush; + COLORREF OldFg; - nhcoord2display(data, i, j, &glyph_rect); + nhcoord2display(data, i, j, &glyph_rect); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) - nhglyph2charcolor(data->map[i][j], &ch, &color); - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); + nhglyph2charcolor(data->map[i][j], &ch, &color); + OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); #else - /* rely on NetHack core helper routine */ - (void)mapglyph(data->map[i][j], &mgch, &color, - &special, i, j); - ch = (char)mgch; - if (((special & MG_PET) && iflags.hilite_pet) || - ((special & MG_DETECT) && iflags.use_inverse)) { - back_brush = CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); - FillRect (hDC, &glyph_rect, back_brush); - DeleteObject (back_brush); - switch (color) - { - case CLR_GRAY: - case CLR_WHITE: - OldFg = SetTextColor( hDC, nhcolor_to_RGB(CLR_BLACK)); - break; - default: - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); - } - } else { - OldFg = SetTextColor (hDC, nhcolor_to_RGB(color) ); - } + /* rely on NetHack core helper routine */ + (void) mapglyph(data->map[i][j], &mgch, &color, + &special, i, j); + ch = (char) mgch; + if (((special & MG_PET) && iflags.hilite_pet) + || ((special & MG_DETECT) + && iflags.use_inverse)) { + back_brush = + CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); + FillRect(hDC, &glyph_rect, back_brush); + DeleteObject(back_brush); + switch (color) { + case CLR_GRAY: + case CLR_WHITE: + OldFg = SetTextColor( + hDC, nhcolor_to_RGB(CLR_BLACK)); + break; + default: + OldFg = + SetTextColor(hDC, nhcolor_to_RGB(color)); + } + } else { + OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); + } #endif - DrawText(hDC, - NH_A2W(&ch, &wch, 1), - 1, - &glyph_rect, - DT_CENTER | DT_VCENTER | DT_NOPREFIX - ); - SetTextColor (hDC, OldFg); - } - SelectObject(hDC, oldFont); - } else { - /* prepare tiles DC for mapping */ - tileDC = CreateCompatibleDC(hDC); - saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); + DrawText(hDC, NH_A2W(&ch, &wch, 1), 1, &glyph_rect, + DT_CENTER | DT_VCENTER | DT_NOPREFIX); + SetTextColor(hDC, OldFg); + } + SelectObject(hDC, oldFont); + } else { + /* prepare tiles DC for mapping */ + tileDC = CreateCompatibleDC(hDC); + saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); - /* draw the map */ - for(i=paint_rt.left; imap[i][j]>=0) { - short ntile; - int t_x, t_y; - RECT glyph_rect; + /* draw the map */ + for (i = paint_rt.left; i < paint_rt.right; i++) + for (j = paint_rt.top; j < paint_rt.bottom; j++) + if (data->map[i][j] >= 0) { + short ntile; + int t_x, t_y; + RECT glyph_rect; - ntile = glyph2tile[ data->map[i][j] ]; - t_x = (ntile % GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_X; - t_y = (ntile / GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_Y; - - nhcoord2display(data, i, j, &glyph_rect); + ntile = glyph2tile[data->map[i][j]]; + t_x = (ntile % GetNHApp()->mapTilesPerLine) + * GetNHApp()->mapTile_X; + t_y = (ntile / GetNHApp()->mapTilesPerLine) + * GetNHApp()->mapTile_Y; - StretchBlt( - hDC, - glyph_rect.left, - glyph_rect.top, - data->xScrTile, - data->yScrTile, - tileDC, - t_x, - t_y, - GetNHApp()->mapTile_X, - GetNHApp()->mapTile_Y, - SRCCOPY - ); - if( glyph_is_pet(data->map[i][j]) && iflags.wc_hilite_pet ) { - /* apply pet mark transparently over - pet image */ - HDC hdcPetMark; - HBITMAP bmPetMarkOld; + nhcoord2display(data, i, j, &glyph_rect); - /* this is DC for petmark bitmap */ - hdcPetMark = CreateCompatibleDC(hDC); - bmPetMarkOld = SelectObject(hdcPetMark, GetNHApp()->bmpPetMark); + StretchBlt(hDC, glyph_rect.left, glyph_rect.top, + data->xScrTile, data->yScrTile, tileDC, + t_x, t_y, GetNHApp()->mapTile_X, + GetNHApp()->mapTile_Y, SRCCOPY); + if (glyph_is_pet(data->map[i][j]) + && iflags.wc_hilite_pet) { + /* apply pet mark transparently over + pet image */ + HDC hdcPetMark; + HBITMAP bmPetMarkOld; - nhapply_image_transparent( - hDC, - glyph_rect.left, - glyph_rect.top, - data->xScrTile, - data->yScrTile, - hdcPetMark, - 0, - 0, - TILE_X, - TILE_Y, - TILE_BK_COLOR - ); - SelectObject(hdcPetMark, bmPetMarkOld); - DeleteDC(hdcPetMark); - } - } - SelectObject(tileDC, saveBmp); - DeleteDC(tileDC); - } + /* this is DC for petmark bitmap */ + hdcPetMark = CreateCompatibleDC(hDC); + bmPetMarkOld = SelectObject( + hdcPetMark, GetNHApp()->bmpPetMark); - /* draw focus rect */ - nhcoord2display(data, data->xCur, data->yCur, &paint_rt); - if( data->bAsciiMode ) { - PatBlt( hDC, - paint_rt.left, paint_rt.top, - paint_rt.right-paint_rt.left, paint_rt.bottom-paint_rt.top, - DSTINVERT ); - } else { - DrawFocusRect(hDC, &paint_rt); - } - } - EndPaint(hWnd, &ps); + nhapply_image_transparent( + hDC, glyph_rect.left, glyph_rect.top, + data->xScrTile, data->yScrTile, hdcPetMark, 0, + 0, TILE_X, TILE_Y, TILE_BK_COLOR); + SelectObject(hdcPetMark, bmPetMarkOld); + DeleteDC(hdcPetMark); + } + } + SelectObject(tileDC, saveBmp); + DeleteDC(tileDC); + } + + /* draw focus rect */ + nhcoord2display(data, data->xCur, data->yCur, &paint_rt); + if (data->bAsciiMode) { + PatBlt(hDC, paint_rt.left, paint_rt.top, + paint_rt.right - paint_rt.left, + paint_rt.bottom - paint_rt.top, DSTINVERT); + } else { + DrawFocusRect(hDC, &paint_rt); + } + } + EndPaint(hWnd, &ps); } /* on WM_VSCROLL */ -void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - SCROLLINFO si; - int yNewPos; - int yDelta; - - UNREFERENCED_PARAMETER(lParam); + PNHMapWindow data; + SCROLLINFO si; + int yNewPos; + int yDelta; - /* get window data */ - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + UNREFERENCED_PARAMETER(lParam); - switch(LOWORD (wParam)) - { - /* User clicked shaft left of the scroll box. */ - case SB_PAGEUP: - yNewPos = data->yPos-data->yPageSize; - break; + /* get window data */ + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - /* User clicked shaft right of the scroll box. */ - case SB_PAGEDOWN: - yNewPos = data->yPos+data->yPageSize; - break; + switch (LOWORD(wParam)) { + /* User clicked shaft left of the scroll box. */ + case SB_PAGEUP: + yNewPos = data->yPos - data->yPageSize; + break; - /* User clicked the left arrow. */ - case SB_LINEUP: - yNewPos = data->yPos-1; - break; + /* User clicked shaft right of the scroll box. */ + case SB_PAGEDOWN: + yNewPos = data->yPos + data->yPageSize; + break; - /* User clicked the right arrow. */ - case SB_LINEDOWN: - yNewPos = data->yPos+1; - break; + /* User clicked the left arrow. */ + case SB_LINEUP: + yNewPos = data->yPos - 1; + break; - /* User dragged the scroll box. */ - case SB_THUMBTRACK: - yNewPos = HIWORD(wParam); - break; + /* User clicked the right arrow. */ + case SB_LINEDOWN: + yNewPos = data->yPos + 1; + break; - default: - yNewPos = data->yPos; - } + /* User dragged the scroll box. */ + case SB_THUMBTRACK: + yNewPos = HIWORD(wParam); + break; - yNewPos = max(0, min(ROWNO-data->yPageSize+1, yNewPos)); - if( yNewPos == data->yPos ) return; - - yDelta = yNewPos - data->yPos; - data->yPos = yNewPos; + default: + yNewPos = data->yPos; + } - ScrollWindowEx (hWnd, 0, -data->yScrTile * yDelta, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + yNewPos = max(0, min(ROWNO - data->yPageSize + 1, yNewPos)); + if (yNewPos == data->yPos) + return; - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + yDelta = yNewPos - data->yPos; + data->yPos = yNewPos; + + ScrollWindowEx(hWnd, 0, -data->yScrTile * yDelta, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); } /* on WM_HSCROLL */ -void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMapWindow data; - SCROLLINFO si; - int xNewPos; - int xDelta; - - UNREFERENCED_PARAMETER(lParam); + PNHMapWindow data; + SCROLLINFO si; + int xNewPos; + int xDelta; - /* get window data */ - data = (PNHMapWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - - switch(LOWORD (wParam)) - { - /* User clicked shaft left of the scroll box. */ - case SB_PAGEUP: - xNewPos = data->xPos-data->xPageSize; - break; + UNREFERENCED_PARAMETER(lParam); - /* User clicked shaft right of the scroll box. */ - case SB_PAGEDOWN: - xNewPos = data->xPos+data->xPageSize; - break; + /* get window data */ + data = (PNHMapWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - /* User clicked the left arrow. */ - case SB_LINEUP: - xNewPos = data->xPos-1; - break; + switch (LOWORD(wParam)) { + /* User clicked shaft left of the scroll box. */ + case SB_PAGEUP: + xNewPos = data->xPos - data->xPageSize; + break; - /* User clicked the right arrow. */ - case SB_LINEDOWN: - xNewPos = data->xPos+1; - break; + /* User clicked shaft right of the scroll box. */ + case SB_PAGEDOWN: + xNewPos = data->xPos + data->xPageSize; + break; - /* User dragged the scroll box. */ - case SB_THUMBTRACK: - xNewPos = HIWORD(wParam); - break; + /* User clicked the left arrow. */ + case SB_LINEUP: + xNewPos = data->xPos - 1; + break; - default: - xNewPos = data->xPos; - } + /* User clicked the right arrow. */ + case SB_LINEDOWN: + xNewPos = data->xPos + 1; + break; - xNewPos = max(0, min(COLNO-data->xPageSize+1, xNewPos)); - if( xNewPos == data->xPos ) return; - - xDelta = xNewPos - data->xPos; - data->xPos = xNewPos; + /* User dragged the scroll box. */ + case SB_THUMBTRACK: + xNewPos = HIWORD(wParam); + break; - ScrollWindowEx (hWnd, -data->xScrTile * xDelta, 0, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + default: + xNewPos = data->xPos; + } + xNewPos = max(0, min(COLNO - data->xPageSize + 1, xNewPos)); + if (xNewPos == data->xPos) + return; - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + xDelta = xNewPos - data->xPos; + data->xPos = xNewPos; + + ScrollWindowEx(hWnd, -data->xScrTile * xDelta, 0, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); } /* map nethack map coordinates to the screen location */ -void nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut) +void +nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut) { - lpOut->left = (x - data->xPos)*data->xScrTile + data->map_orig.x; - lpOut->top = (y - data->yPos)*data->yScrTile + data->map_orig.y; - lpOut->right = lpOut->left + data->xScrTile; - lpOut->bottom = lpOut->top + data->yScrTile; + lpOut->left = (x - data->xPos) * data->xScrTile + data->map_orig.x; + lpOut->top = (y - data->yPos) * data->yScrTile + data->map_orig.y; + lpOut->right = lpOut->left + data->xScrTile; + lpOut->bottom = lpOut->top + data->yScrTile; } #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) /* map glyph to character/color combination */ -void nhglyph2charcolor(short g, uchar* ch, int* color) +void +nhglyph2charcolor(short g, uchar *ch, int *color) { - int offset; + int offset; #ifdef TEXTCOLOR -#define zap_color(n) *color = iflags.use_color ? zapcolors[n] : NO_COLOR +#define zap_color(n) *color = iflags.use_color ? zapcolors[n] : NO_COLOR #define cmap_color(n) *color = iflags.use_color ? defsyms[n].color : NO_COLOR -#define obj_color(n) *color = iflags.use_color ? objects[n].oc_color : NO_COLOR -#define mon_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR -#define pet_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR -#define warn_color(n) *color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR +#define obj_color(n) \ + *color = iflags.use_color ? objects[n].oc_color : NO_COLOR +#define mon_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define pet_color(n) *color = iflags.use_color ? mons[n].mcolor : NO_COLOR +#define warn_color(n) \ + *color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR -# else /* no text color */ +#else /* no text color */ #define zap_color(n) #define cmap_color(n) @@ -894,148 +912,163 @@ void nhglyph2charcolor(short g, uchar* ch, int* color) #define mon_color(n) #define pet_color(c) #define warn_color(c) - *color = CLR_WHITE; + *color = CLR_WHITE; #endif - if ((offset = (g - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ - *ch = showsyms[offset + SYM_OFF_W]; - warn_color(offset); - } else if ((offset = (g - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ - /* see swallow_to_glyph() in display.c */ - *ch = (uchar) showsyms[(S_sw_tl + (offset & 0x7)) + SYM_OFF_P]; - mon_color(offset >> 3); - } else if ((offset = (g - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ - /* see zapdir_to_glyph() in display.c */ - *ch = showsyms[(S_vbeam + (offset & 0x3)) + SYM_OFF_P]; - zap_color((offset >> 2)); - } else if ((offset = (g - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ - *ch = showsyms[offset + SYM_OFF_P]; - cmap_color(offset); - } else if ((offset = (g - GLYPH_OBJ_OFF)) >= 0) { /* object */ - *ch = showsyms[(int)objects[offset].oc_class + SYM_OFF_O]; - obj_color(offset); - } else if ((offset = (g - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ - *ch = showsyms[(int)objects[CORPSE].oc_class + SYM_OFF_O]; - mon_color(offset); - } else if ((offset = (g - GLYPH_PET_OFF)) >= 0) { /* a pet */ - *ch = showsyms[(int)mons[offset].mlet + SYM_OFF_M]; - pet_color(offset); - } else { /* a monster */ - *ch = showsyms[(int)mons[g].mlet + SYM_OFF_M]; - mon_color(g); - } - // end of wintty code + if ((offset = (g - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ + *ch = showsyms[offset + SYM_OFF_W]; + warn_color(offset); + } else if ((offset = (g - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ + /* see swallow_to_glyph() in display.c */ + *ch = (uchar) showsyms[(S_sw_tl + (offset & 0x7)) + SYM_OFF_P]; + mon_color(offset >> 3); + } else if ((offset = (g - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ + /* see zapdir_to_glyph() in display.c */ + *ch = showsyms[(S_vbeam + (offset & 0x3)) + SYM_OFF_P]; + zap_color((offset >> 2)); + } else if ((offset = (g - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ + *ch = showsyms[offset + SYM_OFF_P]; + cmap_color(offset); + } else if ((offset = (g - GLYPH_OBJ_OFF)) >= 0) { /* object */ + *ch = showsyms[(int) objects[offset].oc_class + SYM_OFF_O]; + obj_color(offset); + } else if ((offset = (g - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ + *ch = showsyms[(int) objects[CORPSE].oc_class + SYM_OFF_O]; + mon_color(offset); + } else if ((offset = (g - GLYPH_PET_OFF)) >= 0) { /* a pet */ + *ch = showsyms[(int) mons[offset].mlet + SYM_OFF_M]; + pet_color(offset); + } else { /* a monster */ + *ch = showsyms[(int) mons[g].mlet + SYM_OFF_M]; + mon_color(g); + } + // end of wintty code } #endif /* map nethack color to RGB */ -COLORREF nhcolor_to_RGB(int c) +COLORREF +nhcolor_to_RGB(int c) { - switch(c) { - case CLR_BLACK: return RGB(0x55, 0x55, 0x55); - case CLR_RED: return RGB(0xFF, 0x00, 0x00); - case CLR_GREEN: return RGB(0x00, 0x80, 0x00); - case CLR_BROWN: return RGB(0xA5, 0x2A, 0x2A); - case CLR_BLUE: return RGB(0x00, 0x00, 0xFF); - case CLR_MAGENTA: return RGB(0xFF, 0x00, 0xFF); - case CLR_CYAN: return RGB(0x00, 0xFF, 0xFF); - case CLR_GRAY: return RGB(0xC0, 0xC0, 0xC0); - case NO_COLOR: return RGB(0xFF, 0xFF, 0xFF); - case CLR_ORANGE: return RGB(0xFF, 0xA5, 0x00); - case CLR_BRIGHT_GREEN: return RGB(0x00, 0xFF, 0x00); - case CLR_YELLOW: return RGB(0xFF, 0xFF, 0x00); - case CLR_BRIGHT_BLUE: return RGB(0x00, 0xC0, 0xFF); - case CLR_BRIGHT_MAGENTA: return RGB(0xFF, 0x80, 0xFF); - case CLR_BRIGHT_CYAN: return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */ - case CLR_WHITE: return RGB(0xFF, 0xFF, 0xFF); - default: return RGB(0x00, 0x00, 0x00); /* black */ - } + switch (c) { + case CLR_BLACK: + return RGB(0x55, 0x55, 0x55); + case CLR_RED: + return RGB(0xFF, 0x00, 0x00); + case CLR_GREEN: + return RGB(0x00, 0x80, 0x00); + case CLR_BROWN: + return RGB(0xA5, 0x2A, 0x2A); + case CLR_BLUE: + return RGB(0x00, 0x00, 0xFF); + case CLR_MAGENTA: + return RGB(0xFF, 0x00, 0xFF); + case CLR_CYAN: + return RGB(0x00, 0xFF, 0xFF); + case CLR_GRAY: + return RGB(0xC0, 0xC0, 0xC0); + case NO_COLOR: + return RGB(0xFF, 0xFF, 0xFF); + case CLR_ORANGE: + return RGB(0xFF, 0xA5, 0x00); + case CLR_BRIGHT_GREEN: + return RGB(0x00, 0xFF, 0x00); + case CLR_YELLOW: + return RGB(0xFF, 0xFF, 0x00); + case CLR_BRIGHT_BLUE: + return RGB(0x00, 0xC0, 0xFF); + case CLR_BRIGHT_MAGENTA: + return RGB(0xFF, 0x80, 0xFF); + case CLR_BRIGHT_CYAN: + return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */ + case CLR_WHITE: + return RGB(0xFF, 0xFF, 0xFF); + default: + return RGB(0x00, 0x00, 0x00); /* black */ + } } -/* apply bitmap pointed by sourceDc transparently over +/* apply bitmap pointed by sourceDc transparently over bitmap pointed by hDC */ -typedef BOOL (WINAPI* LPTRANSPARENTBLT)(HDC, int, int, int, int, HDC, int, int, int, int, UINT); -void nhapply_image_transparent( - HDC hDC, int x, int y, int width, int height, - HDC sourceDC, int s_x, int s_y, int s_width, int s_height, - COLORREF cTransparent -) +typedef BOOL(WINAPI *LPTRANSPARENTBLT)(HDC, int, int, int, int, HDC, int, int, + int, int, UINT); +void +nhapply_image_transparent(HDC hDC, int x, int y, int width, int height, + HDC sourceDC, int s_x, int s_y, int s_width, + int s_height, COLORREF cTransparent) { - /* Don't use TransparentBlt; According to Microsoft, it contains a memory leak in Window 95/98. */ - HDC hdcMem, hdcBack, hdcObject, hdcSave; - COLORREF cColor; - HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; - HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; + /* Don't use TransparentBlt; According to Microsoft, it contains a memory + * leak in Window 95/98. */ + HDC hdcMem, hdcBack, hdcObject, hdcSave; + COLORREF cColor; + HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; + HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; - /* Create some DCs to hold temporary data. */ - hdcBack = CreateCompatibleDC(hDC); - hdcObject = CreateCompatibleDC(hDC); - hdcMem = CreateCompatibleDC(hDC); - hdcSave = CreateCompatibleDC(hDC); + /* Create some DCs to hold temporary data. */ + hdcBack = CreateCompatibleDC(hDC); + hdcObject = CreateCompatibleDC(hDC); + hdcMem = CreateCompatibleDC(hDC); + hdcSave = CreateCompatibleDC(hDC); - /* this is bitmap for our pet image */ - bmSave = CreateCompatibleBitmap(hDC, width, height); + /* this is bitmap for our pet image */ + bmSave = CreateCompatibleBitmap(hDC, width, height); - /* Monochrome DC */ - bmAndBack = CreateBitmap(width, height, 1, 1, NULL); - bmAndObject = CreateBitmap(width, height, 1, 1, NULL); + /* Monochrome DC */ + bmAndBack = CreateBitmap(width, height, 1, 1, NULL); + bmAndObject = CreateBitmap(width, height, 1, 1, NULL); - /* resulting bitmap */ - bmAndMem = CreateCompatibleBitmap(hDC, width, height); + /* resulting bitmap */ + bmAndMem = CreateCompatibleBitmap(hDC, width, height); - /* Each DC must select a bitmap object to store pixel data. */ - bmBackOld = SelectObject(hdcBack, bmAndBack); - bmObjectOld = SelectObject(hdcObject, bmAndObject); - bmMemOld = SelectObject(hdcMem, bmAndMem); - bmSaveOld = SelectObject(hdcSave, bmSave); + /* Each DC must select a bitmap object to store pixel data. */ + bmBackOld = SelectObject(hdcBack, bmAndBack); + bmObjectOld = SelectObject(hdcObject, bmAndObject); + bmMemOld = SelectObject(hdcMem, bmAndMem); + bmSaveOld = SelectObject(hdcSave, bmSave); - /* copy source image because it is going to be overwritten */ - StretchBlt(hdcSave, 0, 0, width, height, sourceDC, s_x, s_y, s_width, s_height, SRCCOPY); + /* copy source image because it is going to be overwritten */ + StretchBlt(hdcSave, 0, 0, width, height, sourceDC, s_x, s_y, s_width, + s_height, SRCCOPY); - /* Set the background color of the source DC to the color. - contained in the parts of the bitmap that should be transparent */ - cColor = SetBkColor(hdcSave, cTransparent); + /* Set the background color of the source DC to the color. + contained in the parts of the bitmap that should be transparent */ + cColor = SetBkColor(hdcSave, cTransparent); - /* Create the object mask for the bitmap by performing a BitBlt - from the source bitmap to a monochrome bitmap. */ - BitBlt(hdcObject, 0, 0, width, height, hdcSave, 0, 0, SRCCOPY); + /* Create the object mask for the bitmap by performing a BitBlt + from the source bitmap to a monochrome bitmap. */ + BitBlt(hdcObject, 0, 0, width, height, hdcSave, 0, 0, SRCCOPY); - /* Set the background color of the source DC back to the original - color. */ - SetBkColor(hdcSave, cColor); + /* Set the background color of the source DC back to the original + color. */ + SetBkColor(hdcSave, cColor); - /* Create the inverse of the object mask. */ - BitBlt(hdcBack, 0, 0, width, height, hdcObject, 0, 0, NOTSRCCOPY); + /* Create the inverse of the object mask. */ + BitBlt(hdcBack, 0, 0, width, height, hdcObject, 0, 0, NOTSRCCOPY); - /* Copy background to the resulting image */ - BitBlt(hdcMem, 0, 0, width, height, hDC, x, y, SRCCOPY); + /* Copy background to the resulting image */ + BitBlt(hdcMem, 0, 0, width, height, hDC, x, y, SRCCOPY); - /* Mask out the places where the source image will be placed. */ - BitBlt(hdcMem, 0, 0, width, height, hdcObject, 0, 0, SRCAND); + /* Mask out the places where the source image will be placed. */ + BitBlt(hdcMem, 0, 0, width, height, hdcObject, 0, 0, SRCAND); - /* Mask out the transparent colored pixels on the source image. */ - BitBlt(hdcSave, 0, 0, width, height, hdcBack, 0, 0, SRCAND); + /* Mask out the transparent colored pixels on the source image. */ + BitBlt(hdcSave, 0, 0, width, height, hdcBack, 0, 0, SRCAND); - /* XOR the source image with the beckground. */ - BitBlt(hdcMem, 0, 0, width, height, hdcSave, 0, 0, SRCPAINT); + /* XOR the source image with the beckground. */ + BitBlt(hdcMem, 0, 0, width, height, hdcSave, 0, 0, SRCPAINT); - /* blt resulting image to the screen */ - BitBlt( - hDC, - x, y, width, height, hdcMem, - 0, 0, SRCCOPY - ); + /* blt resulting image to the screen */ + BitBlt(hDC, x, y, width, height, hdcMem, 0, 0, SRCCOPY); - /* cleanup */ - DeleteObject(SelectObject(hdcBack, bmBackOld)); - DeleteObject(SelectObject(hdcObject, bmObjectOld)); - DeleteObject(SelectObject(hdcMem, bmMemOld)); - DeleteObject(SelectObject(hdcSave, bmSaveOld)); + /* cleanup */ + DeleteObject(SelectObject(hdcBack, bmBackOld)); + DeleteObject(SelectObject(hdcObject, bmObjectOld)); + DeleteObject(SelectObject(hdcMem, bmMemOld)); + DeleteObject(SelectObject(hdcSave, bmSaveOld)); - DeleteDC(hdcMem); - DeleteDC(hdcBack); - DeleteDC(hdcObject); - DeleteDC(hdcSave); + DeleteDC(hdcMem); + DeleteDC(hdcBack); + DeleteDC(hdcObject); + DeleteDC(hdcSave); } - diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 679e44782..6aa5aa073 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhmenu.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhmenu.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.47 $ */ /* NetHack 3.6 mhmenu.c $Date: 2012/01/11 01:53:44 $ $Revision: 1.36 $ */ /* Copyright (c) Alex Kompel, 2002 */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,58 +12,58 @@ #include "mhfont.h" #include "mhdlg.h" -#define MENU_MARGIN 0 -#define NHMENU_STR_SIZE BUFSZ -#define MIN_TABSTOP_SIZE 0 -#define NUMTABS 15 -#define TAB_SEPARATION 10 /* pixels between each tab stop */ +#define MENU_MARGIN 0 +#define NHMENU_STR_SIZE BUFSZ +#define MIN_TABSTOP_SIZE 0 +#define NUMTABS 15 +#define TAB_SEPARATION 10 /* pixels between each tab stop */ -#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW -#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT -#define DEFAULT_COLOR_BG_MENU COLOR_WINDOW -#define DEFAULT_COLOR_FG_MENU COLOR_WINDOWTEXT +#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW +#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT +#define DEFAULT_COLOR_BG_MENU COLOR_WINDOW +#define DEFAULT_COLOR_FG_MENU COLOR_WINDOWTEXT typedef struct mswin_menu_item { - int glyph; - ANY_P identifier; - CHAR_P accelerator; - CHAR_P group_accel; - int attr; - char str[NHMENU_STR_SIZE]; - BOOLEAN_P presel; - int count; - BOOL has_focus; + int glyph; + ANY_P identifier; + CHAR_P accelerator; + CHAR_P group_accel; + int attr; + char str[NHMENU_STR_SIZE]; + BOOLEAN_P presel; + int count; + BOOL has_focus; } NHMenuItem, *PNHMenuItem; typedef struct mswin_nethack_menu_window { - int type; /* MENU_TYPE_TEXT or MENU_TYPE_MENU */ - int how; /* for menus: PICK_NONE, PICK_ONE, PICK_ANY */ + int type; /* MENU_TYPE_TEXT or MENU_TYPE_MENU */ + int how; /* for menus: PICK_NONE, PICK_ONE, PICK_ANY */ - union { - struct menu_list { - int size; /* number of items in items[] */ - int allocated; /* number of allocated slots in items[] */ - PNHMenuItem items; /* menu items */ - char gacc[QBUFSZ]; /* group accelerators */ - BOOL counting; /* counting flag */ - char prompt[QBUFSZ]; /* menu prompt */ - int tab_stop_size[NUMTABS];/* tabstops to align option values */ - int menu_cx; /* menu width */ - } menu; + union { + struct menu_list { + int size; /* number of items in items[] */ + int allocated; /* number of allocated slots in items[] */ + PNHMenuItem items; /* menu items */ + char gacc[QBUFSZ]; /* group accelerators */ + BOOL counting; /* counting flag */ + char prompt[QBUFSZ]; /* menu prompt */ + int tab_stop_size[NUMTABS]; /* tabstops to align option values */ + int menu_cx; /* menu width */ + } menu; - struct menu_text { - TCHAR* text; - SIZE text_box_size; - } text; - }; - int result; - int done; + struct menu_text { + TCHAR *text; + SIZE text_box_size; + } text; + }; + int result; + int done; - HBITMAP bmpChecked; - HBITMAP bmpCheckedCount; - HBITMAP bmpNotChecked; + HBITMAP bmpChecked; + HBITMAP bmpCheckedCount; + HBITMAP bmpNotChecked; - BOOL is_active; + BOOL is_active; } NHMenuWindow, *PNHMenuWindow; extern short glyph2tile[]; @@ -71,13 +71,13 @@ extern short glyph2tile[]; static WNDPROC wndProcListViewOrig = NULL; static WNDPROC editControlWndProc = NULL; -#define NHMENU_IS_SELECTABLE(item) ((item).identifier.a_obj!=NULL) -#define NHMENU_IS_SELECTED(item) ((item).count!=0) -#define NHMENU_HAS_GLYPH(item) ((item).glyph!=NO_GLYPH) +#define NHMENU_IS_SELECTABLE(item) ((item).identifier.a_obj != NULL) +#define NHMENU_IS_SELECTED(item) ((item).count != 0) +#define NHMENU_HAS_GLYPH(item) ((item).glyph != NO_GLYPH) -INT_PTR CALLBACK MenuWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHMenuListWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHMenuTextWndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK MenuWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMenuListWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMenuTextWndProc(HWND, UINT, WPARAM, LPARAM); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static BOOL onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam); static BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -85,1209 +85,1263 @@ static void LayoutMenu(HWND hwnd); static void SetMenuType(HWND hwnd, int type); static void SetMenuListType(HWND hwnd, int now); static HWND GetMenuControl(HWND hwnd); -static void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count); +static void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, + int count); static void reset_menu_count(HWND hwndList, PNHMenuWindow data); static BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch); /*-----------------------------------------------------------------------------*/ -HWND mswin_init_menu_window (int type) { - HWND ret; - RECT rt; +HWND +mswin_init_menu_window(int type) +{ + HWND ret; + RECT rt; - /* get window position */ - if( GetNHApp()->bAutoLayout ) { - SetRect( &rt, 0, 0, 0, 0); - } else { - mswin_get_window_placement(NHW_MENU, &rt); - } + /* get window position */ + if (GetNHApp()->bAutoLayout) { + SetRect(&rt, 0, 0, 0, 0); + } else { + mswin_get_window_placement(NHW_MENU, &rt); + } - /* create menu window object */ - ret = CreateDialog( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_MENU), - GetNHApp()->hMainWnd, - MenuWndProc - ); - if( !ret ) { - panic("Cannot create menu window"); - } + /* create menu window object */ + ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_MENU), + GetNHApp()->hMainWnd, MenuWndProc); + if (!ret) { + panic("Cannot create menu window"); + } - /* move it in the predefined position */ - if( !GetNHApp()->bAutoLayout ) { - MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, TRUE); - } + /* move it in the predefined position */ + if (!GetNHApp()->bAutoLayout) { + MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, TRUE); + } - /* Set window caption */ - SetWindowText(ret, "Menu/Text"); + /* Set window caption */ + SetWindowText(ret, "Menu/Text"); - if( !GetNHApp()->bWindowsLocked ) { - DWORD style; - style = GetWindowLong(ret, GWL_STYLE); - style |= WS_CAPTION; - SetWindowLong(ret, GWL_STYLE, style); - SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - } + if (!GetNHApp()->bWindowsLocked) { + DWORD style; + style = GetWindowLong(ret, GWL_STYLE); + style |= WS_CAPTION; + SetWindowLong(ret, GWL_STYLE, style); + SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE + | SWP_NOZORDER + | SWP_FRAMECHANGED); + } - SetMenuType(ret, type); - return ret; + SetMenuType(ret, type); + return ret; } /*-----------------------------------------------------------------------------*/ -int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected, BOOL activate) +int +mswin_menu_window_select_menu(HWND hWnd, int how, MENU_ITEM_P **_selected, + BOOL activate) { - PNHMenuWindow data; - int ret_val; + PNHMenuWindow data; + int ret_val; MENU_ITEM_P *selected = NULL; - int i; - char* ap; + int i; + char *ap; - assert( _selected!=NULL ); - *_selected = NULL; - ret_val = -1; + assert(_selected != NULL); + *_selected = NULL; + ret_val = -1; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - /* force activate for certain menu types */ - if( data->type == MENU_TYPE_MENU && - (how == PICK_ONE || how == PICK_ANY) ) { - activate = TRUE; - } + /* force activate for certain menu types */ + if (data->type == MENU_TYPE_MENU + && (how == PICK_ONE || how == PICK_ANY)) { + activate = TRUE; + } - data->is_active = activate; + data->is_active = activate; - /* set menu type */ - SetMenuListType(hWnd, how); + /* set menu type */ + SetMenuListType(hWnd, how); - /* Ok, now give items a unique accelerators */ - if( data->type == MENU_TYPE_MENU ) { - char next_char = 'a'; + /* Ok, now give items a unique accelerators */ + if (data->type == MENU_TYPE_MENU) { + char next_char = 'a'; - data->menu.gacc[0] = '\0'; - ap = data->menu.gacc; - for( i=0; imenu.size; i++) { - if( data->menu.items[i].accelerator!=0 ) { - next_char = (char)(data->menu.items[i].accelerator+1); - } else if( NHMENU_IS_SELECTABLE(data->menu.items[i]) ) { - if ( (next_char>='a' && next_char<='z') || - (next_char>='A' && next_char<='Z') ) { - data->menu.items[i].accelerator = next_char; - } else { - if( next_char > 'z' ) next_char = 'A'; - else if ( next_char > 'Z' ) break; + data->menu.gacc[0] = '\0'; + ap = data->menu.gacc; + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator != 0) { + next_char = (char) (data->menu.items[i].accelerator + 1); + } else if (NHMENU_IS_SELECTABLE(data->menu.items[i])) { + if ((next_char >= 'a' && next_char <= 'z') + || (next_char >= 'A' && next_char <= 'Z')) { + data->menu.items[i].accelerator = next_char; + } else { + if (next_char > 'z') + next_char = 'A'; + else if (next_char > 'Z') + break; - data->menu.items[i].accelerator = next_char; - } + data->menu.items[i].accelerator = next_char; + } - next_char ++; - } - } + next_char++; + } + } - /* collect group accelerators */ - for( i=0; imenu.size; i++) { - if( data->how != PICK_NONE ) { - if( data->menu.items[i].group_accel && - !strchr(data->menu.gacc, data->menu.items[i].group_accel) ) { - *ap++ = data->menu.items[i].group_accel; - *ap = '\x0'; - } - } - } + /* collect group accelerators */ + for (i = 0; i < data->menu.size; i++) { + if (data->how != PICK_NONE) { + if (data->menu.items[i].group_accel + && !strchr(data->menu.gacc, + data->menu.items[i].group_accel)) { + *ap++ = data->menu.items[i].group_accel; + *ap = '\x0'; + } + } + } - reset_menu_count(NULL, data); - } + reset_menu_count(NULL, data); + } - LayoutMenu(hWnd); // show dialog buttons + LayoutMenu(hWnd); // show dialog buttons - if( activate ) { - mswin_popup_display(hWnd, &data->done); - } else { - SetFocus(GetNHApp()->hMainWnd); - mswin_layout_main_window(hWnd); - } + if (activate) { + mswin_popup_display(hWnd, &data->done); + } else { + SetFocus(GetNHApp()->hMainWnd); + mswin_layout_main_window(hWnd); + } - /* get the result */ - if( data->result != -1 ) { - if(how==PICK_NONE) { - if(data->result>=0) ret_val=0; - else ret_val=-1; - } else if(how==PICK_ONE || how==PICK_ANY) { - /* count selected items */ - ret_val = 0; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - NHMENU_IS_SELECTED(data->menu.items[i]) ) { - ret_val++; - } - } - if( ret_val > 0 ) { - int sel_ind; + /* get the result */ + if (data->result != -1) { + if (how == PICK_NONE) { + if (data->result >= 0) + ret_val = 0; + else + ret_val = -1; + } else if (how == PICK_ONE || how == PICK_ANY) { + /* count selected items */ + ret_val = 0; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && NHMENU_IS_SELECTED(data->menu.items[i])) { + ret_val++; + } + } + if (ret_val > 0) { + int sel_ind; - selected = (MENU_ITEM_P*)malloc(ret_val*sizeof(MENU_ITEM_P)); - if( !selected ) panic("out of memory"); + selected = + (MENU_ITEM_P *) malloc(ret_val * sizeof(MENU_ITEM_P)); + if (!selected) + panic("out of memory"); - sel_ind = 0; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - NHMENU_IS_SELECTED(data->menu.items[i]) ) { - selected[sel_ind].item = data->menu.items[i].identifier; - selected[sel_ind].count = data->menu.items[i].count; - sel_ind++; - } - } - ret_val = sel_ind; - *_selected = selected; - } - } - } + sel_ind = 0; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && NHMENU_IS_SELECTED(data->menu.items[i])) { + selected[sel_ind].item = + data->menu.items[i].identifier; + selected[sel_ind].count = data->menu.items[i].count; + sel_ind++; + } + } + ret_val = sel_ind; + *_selected = selected; + } + } + } - if( activate ) { - data->is_active = FALSE; - LayoutMenu(hWnd); // hide dialog buttons - mswin_popup_destroy(hWnd); - } - return ret_val; + if (activate) { + data->is_active = FALSE; + LayoutMenu(hWnd); // hide dialog buttons + mswin_popup_destroy(hWnd); + } + return ret_val; } -/*-----------------------------------------------------------------------------*/ -INT_PTR CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +/*-----------------------------------------------------------------------------*/ +INT_PTR CALLBACK +MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHMenuWindow data; - HWND control; - HDC hdc; + PNHMenuWindow data; + HWND control; + HDC hdc; TCHAR title[MAX_LOADSTRING]; + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (message) { + case WM_INITDIALOG: + data = (PNHMenuWindow) malloc(sizeof(NHMenuWindow)); + ZeroMemory(data, sizeof(NHMenuWindow)); + data->type = MENU_TYPE_TEXT; + data->how = PICK_NONE; + data->result = 0; + data->done = 0; + data->bmpChecked = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL)); + data->bmpCheckedCount = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL_COUNT)); + data->bmpNotChecked = + LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); + data->is_active = FALSE; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (message) - { - case WM_INITDIALOG: - data = (PNHMenuWindow)malloc(sizeof(NHMenuWindow)); - ZeroMemory(data, sizeof(NHMenuWindow)); - data->type = MENU_TYPE_TEXT; - data->how = PICK_NONE; - data->result = 0; - data->done = 0; - data->bmpChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL)); - data->bmpCheckedCount = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL_COUNT)); - data->bmpNotChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); - data->is_active = FALSE; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + /* set font for the text cotrol */ + control = GetDlgItem(hWnd, IDC_MENU_TEXT); + hdc = GetDC(control); + SendMessage(control, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE), + (LPARAM) 0); + ReleaseDC(control, hdc); - /* set font for the text cotrol */ - control = GetDlgItem(hWnd, IDC_MENU_TEXT); - hdc = GetDC(control); - SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE), (LPARAM)0); - ReleaseDC(control, hdc); + /* subclass edit control */ + editControlWndProc = + (WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC); + SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHMenuTextWndProc); - /* subclass edit control */ - editControlWndProc = (WNDPROC)GetWindowLongPtr(control, GWLP_WNDPROC); - SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)NHMenuTextWndProc); - - /* Even though the dialog has no caption, you can still set the title + /* Even though the dialog has no caption, you can still set the title which shows on Alt-Tab */ LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING); SetWindowText(hWnd, title); - /* set focus to text control for now */ - SetFocus(control); - return FALSE; + /* set focus to text control for now */ + SetFocus(control); + return FALSE; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SIZE: { - RECT rt; - LayoutMenu(hWnd); - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - if( flags.perm_invent && mswin_winid_from_handle(hWnd)==WIN_INVEN ) - mswin_update_window_placement(NHW_INVEN, &rt); - else - mswin_update_window_placement(NHW_MENU, &rt); - } return FALSE; + case WM_SIZE: { + RECT rt; + LayoutMenu(hWnd); + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + if (flags.perm_invent && mswin_winid_from_handle(hWnd) == WIN_INVEN) + mswin_update_window_placement(NHW_INVEN, &rt); + else + mswin_update_window_placement(NHW_MENU, &rt); + } + return FALSE; - case WM_MOVE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - if( flags.perm_invent && mswin_winid_from_handle(hWnd)==WIN_INVEN ) - mswin_update_window_placement(NHW_INVEN, &rt); - else - mswin_update_window_placement(NHW_MENU, &rt); - } return FALSE; - - case WM_CLOSE: - if (program_state.gameover) { - data->result = -1; - data->done = 1; - program_state.stopprint++; - return TRUE; - } else - return FALSE; + case WM_MOVE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + if (flags.perm_invent && mswin_winid_from_handle(hWnd) == WIN_INVEN) + mswin_update_window_placement(NHW_INVEN, &rt); + else + mswin_update_window_placement(NHW_MENU, &rt); + } + return FALSE; - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDCANCEL: - if( data->type == MENU_TYPE_MENU && - (data->how==PICK_ONE || data->how==PICK_ANY) && - data->menu.counting) { - HWND list; - int i; + case WM_CLOSE: + if (program_state.gameover) { + data->result = -1; + data->done = 1; + program_state.stopprint++; + return TRUE; + } else + return FALSE; - /* reset counter if counting is in progress */ - list = GetMenuControl(hWnd); - i = ListView_GetNextItem(list, -1, LVNI_FOCUSED); - if( i>=0 ) { - SelectMenuItem(list, data, i, 0); - } - return TRUE; - } else { - data->result = -1; - data->done = 1; - } - return TRUE; + case WM_COMMAND: { + switch (LOWORD(wParam)) { + case IDCANCEL: + if (data->type == MENU_TYPE_MENU + && (data->how == PICK_ONE || data->how == PICK_ANY) + && data->menu.counting) { + HWND list; + int i; - case IDOK: - data->done = 1; - data->result = 0; - return TRUE; - } - } break; + /* reset counter if counting is in progress */ + list = GetMenuControl(hWnd); + i = ListView_GetNextItem(list, -1, LVNI_FOCUSED); + if (i >= 0) { + SelectMenuItem(list, data, i, 0); + } + return TRUE; + } else { + data->result = -1; + data->done = 1; + } + return TRUE; - case WM_NOTIFY: - { - LPNMHDR lpnmhdr = (LPNMHDR)lParam; - switch (LOWORD(wParam)) { - case IDC_MENU_LIST: - { - if( !data || data->type!=MENU_TYPE_MENU ) break; + case IDOK: + data->done = 1; + data->result = 0; + return TRUE; + } + } break; - switch(lpnmhdr->code) { - case LVN_ITEMACTIVATE: - { - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; - if(data->how==PICK_ONE) { - if( lpnmlv->iItem>=0 && - lpnmlv->iItemmenu.size && - NHMENU_IS_SELECTABLE(data->menu.items[lpnmlv->iItem]) ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - -1 - ); - data->done = 1; - data->result = 0; - return TRUE; - } - } - } break; + case WM_NOTIFY: { + LPNMHDR lpnmhdr = (LPNMHDR) lParam; + switch (LOWORD(wParam)) { + case IDC_MENU_LIST: { + if (!data || data->type != MENU_TYPE_MENU) + break; - case NM_CLICK: { - LPNMLISTVIEW lpnmitem = (LPNMLISTVIEW) lParam; - if( lpnmitem->iItem==-1 ) return 0; - if( data->how==PICK_ANY ) { - SelectMenuItem( - lpnmitem->hdr.hwndFrom, - data, - lpnmitem->iItem, - NHMENU_IS_SELECTED(data->menu.items[lpnmitem->iItem])? 0 : -1 - ); - } - } break; + switch (lpnmhdr->code) { + case LVN_ITEMACTIVATE: { + LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; + if (data->how == PICK_ONE) { + if (lpnmlv->iItem >= 0 && lpnmlv->iItem < data->menu.size + && NHMENU_IS_SELECTABLE( + data->menu.items[lpnmlv->iItem])) { + SelectMenuItem(lpnmlv->hdr.hwndFrom, data, + lpnmlv->iItem, -1); + data->done = 1; + data->result = 0; + return TRUE; + } + } + } break; - case LVN_ITEMCHANGED: - { - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; - if( lpnmlv->iItem==-1 ) return 0; - if( !(lpnmlv->uChanged & LVIF_STATE) ) return 0; + case NM_CLICK: { + LPNMLISTVIEW lpnmitem = (LPNMLISTVIEW) lParam; + if (lpnmitem->iItem == -1) + return 0; + if (data->how == PICK_ANY) { + SelectMenuItem( + lpnmitem->hdr.hwndFrom, data, lpnmitem->iItem, + NHMENU_IS_SELECTED(data->menu.items[lpnmitem->iItem]) + ? 0 + : -1); + } + } break; - if( data->how==PICK_ONE || data->how==PICK_ANY ) { - data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); - ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); - } + case LVN_ITEMCHANGED: { + LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; + if (lpnmlv->iItem == -1) + return 0; + if (!(lpnmlv->uChanged & LVIF_STATE)) + return 0; - /* update count for single-selection menu (follow the listview selection) */ - if( data->how==PICK_ONE ) { - if( lpnmlv->uNewState & LVIS_SELECTED ) { - SelectMenuItem( - lpnmlv->hdr.hwndFrom, - data, - lpnmlv->iItem, - -1 - ); - } - } + if (data->how == PICK_ONE || data->how == PICK_ANY) { + data->menu.items[lpnmlv->iItem].has_focus = + !!(lpnmlv->uNewState & LVIS_FOCUSED); + ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, + lpnmlv->iItem); + } - /* check item focus */ - if( data->how==PICK_ONE || data->how==PICK_ANY ) { - data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); - ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); - } - } break; + /* update count for single-selection menu (follow the listview + * selection) */ + if (data->how == PICK_ONE) { + if (lpnmlv->uNewState & LVIS_SELECTED) { + SelectMenuItem(lpnmlv->hdr.hwndFrom, data, + lpnmlv->iItem, -1); + } + } - case NM_KILLFOCUS: - reset_menu_count(lpnmhdr->hwndFrom, data); - break; + /* check item focus */ + if (data->how == PICK_ONE || data->how == PICK_ANY) { + data->menu.items[lpnmlv->iItem].has_focus = + !!(lpnmlv->uNewState & LVIS_FOCUSED); + ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, + lpnmlv->iItem); + } + } break; - } - } break; - } - } break; + case NM_KILLFOCUS: + reset_menu_count(lpnmhdr->hwndFrom, data); + break; + } + } break; + } + } break; - case WM_SETFOCUS: - if( hWnd!=GetNHApp()->hPopupWnd) { - SetFocus(GetNHApp()->hMainWnd); - } else { - if( IsWindow(GetMenuControl(hWnd)) ) - SetFocus(GetMenuControl(hWnd)); - } - return FALSE; - - case WM_MEASUREITEM: - if( wParam==IDC_MENU_LIST ) - return onMeasureItem(hWnd, wParam, lParam); - else - return FALSE; + case WM_SETFOCUS: + if (hWnd != GetNHApp()->hPopupWnd) { + SetFocus(GetNHApp()->hMainWnd); + } else { + if (IsWindow(GetMenuControl(hWnd))) + SetFocus(GetMenuControl(hWnd)); + } + return FALSE; + + case WM_MEASUREITEM: + if (wParam == IDC_MENU_LIST) + return onMeasureItem(hWnd, wParam, lParam); + else + return FALSE; case WM_DRAWITEM: - if( wParam==IDC_MENU_LIST ) - return onDrawItem(hWnd, wParam, lParam); - else - return FALSE; + if (wParam == IDC_MENU_LIST) + return onDrawItem(hWnd, wParam, lParam); + else + return FALSE; - case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ - HDC hdcEdit = (HDC) wParam; - HWND hwndEdit = (HWND) lParam; - if( hwndEdit == GetDlgItem(hWnd, IDC_MENU_TEXT) ) { - SetBkColor(hdcEdit, - text_bg_brush ? text_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_TEXT) - ); - SetTextColor(hdcEdit, - text_fg_brush ? text_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_TEXT) - ); - return (INT_PTR)(text_bg_brush - ? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); - } - } return FALSE; + case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ + HDC hdcEdit = (HDC) wParam; + HWND hwndEdit = (HWND) lParam; + if (hwndEdit == GetDlgItem(hWnd, IDC_MENU_TEXT)) { + SetBkColor(hdcEdit, text_bg_brush ? text_bg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_BG_TEXT)); + SetTextColor(hdcEdit, text_fg_brush ? text_fg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_FG_TEXT)); + return (INT_PTR)(text_bg_brush + ? text_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); + } + } + return FALSE; - case WM_DESTROY: - if( data ) { - DeleteObject(data->bmpChecked); - DeleteObject(data->bmpCheckedCount); - DeleteObject(data->bmpNotChecked); - if( data->type == MENU_TYPE_TEXT ) { - if( data->text.text ) free(data->text.text); - } - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - } - return TRUE; - } - return FALSE; + case WM_DESTROY: + if (data) { + DeleteObject(data->bmpChecked); + DeleteObject(data->bmpCheckedCount); + DeleteObject(data->bmpNotChecked); + if (data->type == MENU_TYPE_TEXT) { + if (data->text.text) + free(data->text.text); + } + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + } + return TRUE; + } + return FALSE; } /*-----------------------------------------------------------------------------*/ -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMenuWindow data; + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: - { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - HWND text_view; - TCHAR wbuf[BUFSZ]; - size_t text_size; - RECT text_rt; - HGDIOBJ saveFont; - HDC hdc; + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + HWND text_view; + TCHAR wbuf[BUFSZ]; + size_t text_size; + RECT text_rt; + HGDIOBJ saveFont; + HDC hdc; - if( data->type!=MENU_TYPE_TEXT ) - SetMenuType(hWnd, MENU_TYPE_TEXT); + if (data->type != MENU_TYPE_TEXT) + SetMenuType(hWnd, MENU_TYPE_TEXT); - if( !data->text.text ) { - text_size = strlen(msg_data->text) + 4; - data->text.text = (TCHAR*)malloc(text_size*sizeof(data->text.text[0])); - ZeroMemory(data->text.text, text_size*sizeof(data->text.text[0])); - } else { - text_size = _tcslen(data->text.text) + strlen(msg_data->text) + 4; - data->text.text = (TCHAR*)realloc(data->text.text, text_size*sizeof(data->text.text[0])); - } - if( !data->text.text ) break; - - _tcscat(data->text.text, NH_A2W(msg_data->text, wbuf, BUFSZ)); - _tcscat(data->text.text, TEXT("\r\n")); - - text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); - if( !text_view ) panic("cannot get text view window"); - SetWindowText(text_view, data->text.text); + if (!data->text.text) { + text_size = strlen(msg_data->text) + 4; + data->text.text = + (TCHAR *) malloc(text_size * sizeof(data->text.text[0])); + ZeroMemory(data->text.text, + text_size * sizeof(data->text.text[0])); + } else { + text_size = _tcslen(data->text.text) + strlen(msg_data->text) + 4; + data->text.text = (TCHAR *) realloc( + data->text.text, text_size * sizeof(data->text.text[0])); + } + if (!data->text.text) + break; - /* calculate dimensions of the added line of text */ - hdc = GetDC(text_view); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); - SetRect(&text_rt, 0, 0, 0, 0); - DrawText(hdc, msg_data->text, strlen(msg_data->text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE); - data->text.text_box_size.cx = max(text_rt.right - text_rt.left, data->text.text_box_size.cx); - data->text.text_box_size.cy += text_rt.bottom - text_rt.top; - SelectObject(hdc, saveFont); - ReleaseDC(text_view, hdc); - } break; + _tcscat(data->text.text, NH_A2W(msg_data->text, wbuf, BUFSZ)); + _tcscat(data->text.text, TEXT("\r\n")); - case MSNH_MSG_STARTMENU: - { - int i; - if( data->type!=MENU_TYPE_MENU ) - SetMenuType(hWnd, MENU_TYPE_MENU); + text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); + if (!text_view) + panic("cannot get text view window"); + SetWindowText(text_view, data->text.text); - if( data->menu.items ) free(data->menu.items); - data->how = PICK_NONE; - data->menu.items = NULL; - data->menu.size = 0; - data->menu.allocated = 0; - data->done = 0; - data->result = 0; - for (i = 0; i < NUMTABS; ++i) - data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; - } break; + /* calculate dimensions of the added line of text */ + hdc = GetDC(text_view); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); + SetRect(&text_rt, 0, 0, 0, 0); + DrawText(hdc, msg_data->text, strlen(msg_data->text), &text_rt, + DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX + | DT_SINGLELINE); + data->text.text_box_size.cx = + max(text_rt.right - text_rt.left, data->text.text_box_size.cx); + data->text.text_box_size.cy += text_rt.bottom - text_rt.top; + SelectObject(hdc, saveFont); + ReleaseDC(text_view, hdc); + } break; - case MSNH_MSG_ADDMENU: - { - PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu)lParam; - char *p, *p1; - int new_item; - HDC hDC; - int column; - HFONT saveFont; - LONG menuitemwidth = 0; - TEXTMETRIC tm; - - if( data->type!=MENU_TYPE_MENU ) break; - if( strlen(msg_data->str)==0 ) break; + case MSNH_MSG_STARTMENU: { + int i; + if (data->type != MENU_TYPE_MENU) + SetMenuType(hWnd, MENU_TYPE_MENU); - if( data->menu.size==data->menu.allocated ) { - data->menu.allocated += 10; - data->menu.items = (PNHMenuItem)realloc(data->menu.items, data->menu.allocated*sizeof(NHMenuItem)); - } + if (data->menu.items) + free(data->menu.items); + data->how = PICK_NONE; + data->menu.items = NULL; + data->menu.size = 0; + data->menu.allocated = 0; + data->done = 0; + data->result = 0; + for (i = 0; i < NUMTABS; ++i) + data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; + } break; - new_item = data->menu.size; - ZeroMemory( &data->menu.items[new_item], sizeof(data->menu.items[new_item])); - data->menu.items[new_item].glyph = msg_data->glyph; - data->menu.items[new_item].identifier = *msg_data->identifier; - data->menu.items[new_item].accelerator = msg_data->accelerator; - data->menu.items[new_item].group_accel = msg_data->group_accel; - data->menu.items[new_item].attr = msg_data->attr; - strncpy(data->menu.items[new_item].str, msg_data->str, NHMENU_STR_SIZE); - data->menu.items[new_item].presel = msg_data->presel; + case MSNH_MSG_ADDMENU: { + PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu) lParam; + char *p, *p1; + int new_item; + HDC hDC; + int column; + HFONT saveFont; + LONG menuitemwidth = 0; + TEXTMETRIC tm; - /* calculate tabstop size */ - hDC = GetDC(hWnd); - saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); - GetTextMetrics(hDC, &tm); - p1 = data->menu.items[new_item].str; - p = strchr(data->menu.items[new_item].str, '\t'); - column = 0; - for (;;) { - TCHAR wbuf[BUFSZ]; - RECT drawRect; - SetRect ( &drawRect, 0, 0, 1, 1 ); - if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ - DrawText(hDC, - NH_A2W(p1, wbuf, BUFSZ), - strlen(p1), - &drawRect, - DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS | DT_SINGLELINE - ); - data->menu.tab_stop_size[column] = - max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left ); + if (data->type != MENU_TYPE_MENU) + break; + if (strlen(msg_data->str) == 0) + break; - menuitemwidth += data->menu.tab_stop_size[column]; + if (data->menu.size == data->menu.allocated) { + data->menu.allocated += 10; + data->menu.items = (PNHMenuItem) realloc( + data->menu.items, data->menu.allocated * sizeof(NHMenuItem)); + } - if (p != NULL) *p = '\t'; - else /* last string so, */ break; + new_item = data->menu.size; + ZeroMemory(&data->menu.items[new_item], + sizeof(data->menu.items[new_item])); + data->menu.items[new_item].glyph = msg_data->glyph; + data->menu.items[new_item].identifier = *msg_data->identifier; + data->menu.items[new_item].accelerator = msg_data->accelerator; + data->menu.items[new_item].group_accel = msg_data->group_accel; + data->menu.items[new_item].attr = msg_data->attr; + strncpy(data->menu.items[new_item].str, msg_data->str, + NHMENU_STR_SIZE); + data->menu.items[new_item].presel = msg_data->presel; - /* add the separation only when not the last item */ - /* in the last item, we break out of the loop, in the statement just above */ - menuitemwidth += TAB_SEPARATION; + /* calculate tabstop size */ + hDC = GetDC(hWnd); + saveFont = SelectObject( + hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); + GetTextMetrics(hDC, &tm); + p1 = data->menu.items[new_item].str; + p = strchr(data->menu.items[new_item].str, '\t'); + column = 0; + for (;;) { + TCHAR wbuf[BUFSZ]; + RECT drawRect; + SetRect(&drawRect, 0, 0, 1, 1); + if (p != NULL) + *p = '\0'; /* for time being, view tab field as zstring */ + DrawText(hDC, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), &drawRect, + DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS + | DT_SINGLELINE); + data->menu.tab_stop_size[column] = + max(data->menu.tab_stop_size[column], + drawRect.right - drawRect.left); - ++column; - p1 = p + 1; - p = strchr(p1, '\t'); - } - SelectObject(hDC, saveFont); - ReleaseDC(hWnd, hDC); + menuitemwidth += data->menu.tab_stop_size[column]; - /* calculate new menu width */ - data->menu.menu_cx = max( - data->menu.menu_cx, - 2*TILE_X + menuitemwidth + (tm.tmAveCharWidth+tm.tmOverhang)*12 - ); + if (p != NULL) + *p = '\t'; + else /* last string so, */ + break; - /* increment size */ - data->menu.size++; - } break; + /* add the separation only when not the last item */ + /* in the last item, we break out of the loop, in the statement + * just above */ + menuitemwidth += TAB_SEPARATION; - case MSNH_MSG_ENDMENU: - { - PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu)lParam; - if( msg_data->text ) { - strncpy( data->menu.prompt, msg_data->text, sizeof(data->menu.prompt)-1 ); - } else { - ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); - } - } break; + ++column; + p1 = p + 1; + p = strchr(p1, '\t'); + } + SelectObject(hDC, saveFont); + ReleaseDC(hWnd, hDC); - } + /* calculate new menu width */ + data->menu.menu_cx = + max(data->menu.menu_cx, + 2 * TILE_X + menuitemwidth + + (tm.tmAveCharWidth + tm.tmOverhang) * 12); + + /* increment size */ + data->menu.size++; + } break; + + case MSNH_MSG_ENDMENU: { + PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu) lParam; + if (msg_data->text) { + strncpy(data->menu.prompt, msg_data->text, + sizeof(data->menu.prompt) - 1); + } else { + ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); + } + } break; + } } /*-----------------------------------------------------------------------------*/ -void LayoutMenu(HWND hWnd) +void +LayoutMenu(HWND hWnd) { - PNHMenuWindow data; - HWND menu_ok; - HWND menu_cancel; - RECT clrt, rt; - POINT pt_elem, pt_ok, pt_cancel; - SIZE sz_elem, sz_ok, sz_cancel; + PNHMenuWindow data; + HWND menu_ok; + HWND menu_cancel; + RECT clrt, rt; + POINT pt_elem, pt_ok, pt_cancel; + SIZE sz_elem, sz_ok, sz_cancel; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - menu_ok = GetDlgItem(hWnd, IDOK); - menu_cancel = GetDlgItem(hWnd, IDCANCEL); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + menu_ok = GetDlgItem(hWnd, IDOK); + menu_cancel = GetDlgItem(hWnd, IDCANCEL); - /* get window coordinates */ - GetClientRect(hWnd, &clrt ); + /* get window coordinates */ + GetClientRect(hWnd, &clrt); - // OK button - if( data->is_active ) { - GetWindowRect(menu_ok, &rt); - if( data->type == MENU_TYPE_TEXT || - (data->type == MENU_TYPE_MENU && data->how == PICK_NONE ) ) { - sz_ok.cx = (clrt.right - clrt.left) - 2*MENU_MARGIN; - } else { - sz_ok.cx = (clrt.right - clrt.left)/2 - 2*MENU_MARGIN; - } - sz_ok.cy = rt.bottom-rt.top; - pt_ok.x = clrt.left + MENU_MARGIN; - pt_ok.y = clrt.bottom - MENU_MARGIN - sz_ok.cy; - ShowWindow(menu_ok, SW_SHOW); - MoveWindow(menu_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE ); - } else { - sz_ok.cx = sz_ok.cy = 0; - pt_ok.x = pt_ok.y = 0; - ShowWindow(menu_ok, SW_HIDE); - } + // OK button + if (data->is_active) { + GetWindowRect(menu_ok, &rt); + if (data->type == MENU_TYPE_TEXT + || (data->type == MENU_TYPE_MENU && data->how == PICK_NONE)) { + sz_ok.cx = (clrt.right - clrt.left) - 2 * MENU_MARGIN; + } else { + sz_ok.cx = (clrt.right - clrt.left) / 2 - 2 * MENU_MARGIN; + } + sz_ok.cy = rt.bottom - rt.top; + pt_ok.x = clrt.left + MENU_MARGIN; + pt_ok.y = clrt.bottom - MENU_MARGIN - sz_ok.cy; + ShowWindow(menu_ok, SW_SHOW); + MoveWindow(menu_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); + } else { + sz_ok.cx = sz_ok.cy = 0; + pt_ok.x = pt_ok.y = 0; + ShowWindow(menu_ok, SW_HIDE); + } - // CANCEL button - if( data->is_active && - !( data->type == MENU_TYPE_TEXT || - (data->type == MENU_TYPE_MENU && data->how == PICK_NONE ) ) ) { - GetWindowRect(menu_ok, &rt); - sz_cancel.cx = (clrt.right - clrt.left)/2 - 2*MENU_MARGIN; - pt_cancel.x = (clrt.left + clrt.right)/2 + MENU_MARGIN; - sz_cancel.cy = rt.bottom - rt.top; - pt_cancel.y = clrt.bottom - MENU_MARGIN - sz_cancel.cy; - ShowWindow(menu_cancel, SW_SHOW); - MoveWindow(menu_cancel, pt_cancel.x, pt_cancel.y, sz_cancel.cx, sz_cancel.cy, TRUE ); - } else { - sz_cancel.cx = sz_cancel.cy = 0; - pt_cancel.x = pt_cancel.y = 0; - ShowWindow(menu_cancel, SW_HIDE); - } + // CANCEL button + if (data->is_active + && !(data->type == MENU_TYPE_TEXT + || (data->type == MENU_TYPE_MENU && data->how == PICK_NONE))) { + GetWindowRect(menu_ok, &rt); + sz_cancel.cx = (clrt.right - clrt.left) / 2 - 2 * MENU_MARGIN; + pt_cancel.x = (clrt.left + clrt.right) / 2 + MENU_MARGIN; + sz_cancel.cy = rt.bottom - rt.top; + pt_cancel.y = clrt.bottom - MENU_MARGIN - sz_cancel.cy; + ShowWindow(menu_cancel, SW_SHOW); + MoveWindow(menu_cancel, pt_cancel.x, pt_cancel.y, sz_cancel.cx, + sz_cancel.cy, TRUE); + } else { + sz_cancel.cx = sz_cancel.cy = 0; + pt_cancel.x = pt_cancel.y = 0; + ShowWindow(menu_cancel, SW_HIDE); + } - // main menu control - pt_elem.x = clrt.left + MENU_MARGIN; - pt_elem.y = clrt.top + MENU_MARGIN; - sz_elem.cx = (clrt.right - clrt.left) - 2*MENU_MARGIN; - if( data->is_active ) { - sz_elem.cy = (clrt.bottom - clrt.top) - max(sz_ok.cy, sz_cancel.cy) - 3*MENU_MARGIN; - } else { - sz_elem.cy = (clrt.bottom - clrt.top) - 2*MENU_MARGIN; - } + // main menu control + pt_elem.x = clrt.left + MENU_MARGIN; + pt_elem.y = clrt.top + MENU_MARGIN; + sz_elem.cx = (clrt.right - clrt.left) - 2 * MENU_MARGIN; + if (data->is_active) { + sz_elem.cy = (clrt.bottom - clrt.top) - max(sz_ok.cy, sz_cancel.cy) + - 3 * MENU_MARGIN; + } else { + sz_elem.cy = (clrt.bottom - clrt.top) - 2 * MENU_MARGIN; + } - if( data->type == MENU_TYPE_MENU ) { - ListView_SetColumnWidth( - GetMenuControl(hWnd), - 0, - max(clrt.right - clrt.left - GetSystemMetrics(SM_CXVSCROLL), data->menu.menu_cx ) - ); - } + if (data->type == MENU_TYPE_MENU) { + ListView_SetColumnWidth( + GetMenuControl(hWnd), 0, + max(clrt.right - clrt.left - GetSystemMetrics(SM_CXVSCROLL), + data->menu.menu_cx)); + } - MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); + MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, + sz_elem.cy, TRUE); } /*-----------------------------------------------------------------------------*/ -void SetMenuType(HWND hWnd, int type) +void +SetMenuType(HWND hWnd, int type) { - PNHMenuWindow data; - HWND list, text; + PNHMenuWindow data; + HWND list, text; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - data->type = type; - - text = GetDlgItem(hWnd, IDC_MENU_TEXT); - list = GetDlgItem(hWnd, IDC_MENU_LIST); - if(data->type==MENU_TYPE_TEXT) { - ShowWindow(list, SW_HIDE); - EnableWindow(list, FALSE); - EnableWindow(text, TRUE); - ShowWindow(text, SW_SHOW); - if( data->is_active ) SetFocus(text); - } else { - ShowWindow(text, SW_HIDE); - EnableWindow(text, FALSE); - EnableWindow(list, TRUE); - ShowWindow(list, SW_SHOW); - if( data->is_active ) SetFocus(list); - } - LayoutMenu(hWnd); + data->type = type; + + text = GetDlgItem(hWnd, IDC_MENU_TEXT); + list = GetDlgItem(hWnd, IDC_MENU_LIST); + if (data->type == MENU_TYPE_TEXT) { + ShowWindow(list, SW_HIDE); + EnableWindow(list, FALSE); + EnableWindow(text, TRUE); + ShowWindow(text, SW_SHOW); + if (data->is_active) + SetFocus(text); + } else { + ShowWindow(text, SW_HIDE); + EnableWindow(text, FALSE); + EnableWindow(list, TRUE); + ShowWindow(list, SW_SHOW); + if (data->is_active) + SetFocus(list); + } + LayoutMenu(hWnd); } /*-----------------------------------------------------------------------------*/ -void SetMenuListType(HWND hWnd, int how) +void +SetMenuListType(HWND hWnd, int how) { - PNHMenuWindow data; - RECT rt; - DWORD dwStyles; - char buf[BUFSZ]; - TCHAR wbuf[BUFSZ]; - int nItem; - int i; - HWND control; - LVCOLUMN lvcol; - LRESULT fnt; + PNHMenuWindow data; + RECT rt; + DWORD dwStyles; + char buf[BUFSZ]; + TCHAR wbuf[BUFSZ]; + int nItem; + int i; + HWND control; + LVCOLUMN lvcol; + LRESULT fnt; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if( data->type != MENU_TYPE_MENU ) return; + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (data->type != MENU_TYPE_MENU) + return; - data->how = how; + data->how = how; - switch(how) { - case PICK_NONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - case PICK_ONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - case PICK_ANY: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD - | WS_VSCROLL | WS_HSCROLL | LVS_REPORT - | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; - break; - default: panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY"); - }; + switch (how) { + case PICK_NONE: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + case PICK_ONE: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + case PICK_ANY: + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED + | LVS_SINGLESEL; + break; + default: + panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY"); + }; - if( strlen(data->menu.prompt)==0 ) { - dwStyles |= LVS_NOCOLUMNHEADER ; - } + if (strlen(data->menu.prompt) == 0) { + dwStyles |= LVS_NOCOLUMNHEADER; + } - GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt); - DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST)); - control = CreateWindow(WC_LISTVIEW, NULL, - dwStyles, - rt.left, - rt.top, - rt.right - rt.left, - rt.bottom - rt.top, - hWnd, - (HMENU)IDC_MENU_LIST, - GetNHApp()->hApp, - NULL ); - if( !control ) panic( "cannot create menu control" ); - - /* install the hook for the control window procedure */ - wndProcListViewOrig = (WNDPROC)GetWindowLongPtr(control, GWLP_WNDPROC); - SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)NHMenuListWndProc); + GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt); + DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST)); + control = CreateWindow(WC_LISTVIEW, NULL, dwStyles, rt.left, rt.top, + rt.right - rt.left, rt.bottom - rt.top, hWnd, + (HMENU) IDC_MENU_LIST, GetNHApp()->hApp, NULL); + if (!control) + panic("cannot create menu control"); - /* set control colors */ - ListView_SetBkColor(control, - menu_bg_brush ? menu_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_MENU)); - ListView_SetTextBkColor(control, - menu_bg_brush ? menu_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_MENU)); - ListView_SetTextColor(control, - menu_fg_brush ? menu_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_MENU)); + /* install the hook for the control window procedure */ + wndProcListViewOrig = (WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC); + SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHMenuListWndProc); - /* set control font */ - fnt = SendMessage(hWnd, WM_GETFONT, (WPARAM)0, (LPARAM)0); - SendMessage(control, WM_SETFONT, (WPARAM)fnt, (LPARAM)0); + /* set control colors */ + ListView_SetBkColor(control, menu_bg_brush ? menu_bg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_BG_MENU)); + ListView_SetTextBkColor( + control, menu_bg_brush ? menu_bg_color : (COLORREF) GetSysColor( + DEFAULT_COLOR_BG_MENU)); + ListView_SetTextColor( + control, menu_fg_brush ? menu_fg_color : (COLORREF) GetSysColor( + DEFAULT_COLOR_FG_MENU)); - /* add column to the list view */ - ZeroMemory(&lvcol, sizeof(lvcol)); - lvcol.mask = LVCF_WIDTH | LVCF_TEXT; - lvcol.cx = GetSystemMetrics(SM_CXFULLSCREEN); - lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ); - ListView_InsertColumn(control, 0, &lvcol); + /* set control font */ + fnt = SendMessage(hWnd, WM_GETFONT, (WPARAM) 0, (LPARAM) 0); + SendMessage(control, WM_SETFONT, (WPARAM) fnt, (LPARAM) 0); - /* add items to the list view */ - for(i=0; imenu.size; i++ ) { - LVITEM lvitem; - ZeroMemory( &lvitem, sizeof(lvitem) ); - sprintf(buf, "%c - %s", max(data->menu.items[i].accelerator, ' '), data->menu.items[i].str ); + /* add column to the list view */ + ZeroMemory(&lvcol, sizeof(lvcol)); + lvcol.mask = LVCF_WIDTH | LVCF_TEXT; + lvcol.cx = GetSystemMetrics(SM_CXFULLSCREEN); + lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ); + ListView_InsertColumn(control, 0, &lvcol); - lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT; - lvitem.iItem = i; - lvitem.iSubItem = 0; - lvitem.state = data->menu.items[i].presel? LVIS_SELECTED : 0; - lvitem.pszText = NH_A2W(buf, wbuf, BUFSZ); - lvitem.lParam = (LPARAM)&data->menu.items[i]; - nItem = (int)SendMessage(control, LB_ADDSTRING, (WPARAM)0, (LPARAM) buf); - if( ListView_InsertItem(control, &lvitem)==-1 ) { - panic("cannot insert menu item"); - } - } - if( data->is_active ) SetFocus(control); + /* add items to the list view */ + for (i = 0; i < data->menu.size; i++) { + LVITEM lvitem; + ZeroMemory(&lvitem, sizeof(lvitem)); + sprintf(buf, "%c - %s", max(data->menu.items[i].accelerator, ' '), + data->menu.items[i].str); + + lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT; + lvitem.iItem = i; + lvitem.iSubItem = 0; + lvitem.state = data->menu.items[i].presel ? LVIS_SELECTED : 0; + lvitem.pszText = NH_A2W(buf, wbuf, BUFSZ); + lvitem.lParam = (LPARAM) &data->menu.items[i]; + nItem = (int) SendMessage(control, LB_ADDSTRING, (WPARAM) 0, + (LPARAM) buf); + if (ListView_InsertItem(control, &lvitem) == -1) { + panic("cannot insert menu item"); + } + } + if (data->is_active) + SetFocus(control); } /*-----------------------------------------------------------------------------*/ -HWND GetMenuControl(HWND hWnd) +HWND +GetMenuControl(HWND hWnd) { - PNHMenuWindow data; + PNHMenuWindow data; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - if(data->type==MENU_TYPE_TEXT) { - return GetDlgItem(hWnd, IDC_MENU_TEXT); - } else { - return GetDlgItem(hWnd, IDC_MENU_LIST); - } + if (data->type == MENU_TYPE_TEXT) { + return GetDlgItem(hWnd, IDC_MENU_TEXT); + } else { + return GetDlgItem(hWnd, IDC_MENU_LIST); + } } /*-----------------------------------------------------------------------------*/ -BOOL onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam) +BOOL +onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { - LPMEASUREITEMSTRUCT lpmis; + LPMEASUREITEMSTRUCT lpmis; TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC hdc; - PNHMenuWindow data; - RECT list_rect; - int i; + HGDIOBJ saveFont; + HDC hdc; + PNHMenuWindow data; + RECT list_rect; + int i; UNREFERENCED_PARAMETER(wParam); - lpmis = (LPMEASUREITEMSTRUCT) lParam; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - GetClientRect(GetMenuControl(hWnd), &list_rect); + lpmis = (LPMEASUREITEMSTRUCT) lParam; + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + GetClientRect(GetMenuControl(hWnd), &list_rect); - hdc = GetDC(GetMenuControl(hWnd)); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, FALSE)); - GetTextMetrics(hdc, &tm); + hdc = GetDC(GetMenuControl(hWnd)); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); - /* Set the height of the list box items to max height of the individual items */ - for( i=0; imenu.size; i++) { - if( NHMENU_HAS_GLYPH(data->menu.items[i]) && !IS_MAP_ASCII(iflags.wc_map_mode) ) { - lpmis->itemHeight = max( lpmis->itemHeight, (UINT)max(tm.tmHeight, GetNHApp()->mapTile_Y)+2 ); - } else { - lpmis->itemHeight = max( lpmis->itemHeight, (UINT)max(tm.tmHeight, TILE_Y)+2 ); - } - } + /* Set the height of the list box items to max height of the individual + * items */ + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_HAS_GLYPH(data->menu.items[i]) + && !IS_MAP_ASCII(iflags.wc_map_mode)) { + lpmis->itemHeight = + max(lpmis->itemHeight, + (UINT) max(tm.tmHeight, GetNHApp()->mapTile_Y) + 2); + } else { + lpmis->itemHeight = + max(lpmis->itemHeight, (UINT) max(tm.tmHeight, TILE_Y) + 2); + } + } - /* set width to the window width */ - lpmis->itemWidth = list_rect.right - list_rect.left; + /* set width to the window width */ + lpmis->itemWidth = list_rect.right - list_rect.left; - SelectObject(hdc, saveFont); - ReleaseDC(GetMenuControl(hWnd), hdc); - return TRUE; + SelectObject(hdc, saveFont); + ReleaseDC(GetMenuControl(hWnd), hdc); + return TRUE; } /*-----------------------------------------------------------------------------*/ -BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) +BOOL +onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { - LPDRAWITEMSTRUCT lpdis; - PNHMenuItem item; - PNHMenuWindow data; - TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC tileDC; - short ntile; - int t_x, t_y; - int x, y; - TCHAR wbuf[BUFSZ]; - RECT drawRect; - COLORREF OldBg, OldFg, NewBg; - char *p, *p1; - int column; - int spacing = 0; + LPDRAWITEMSTRUCT lpdis; + PNHMenuItem item; + PNHMenuWindow data; + TEXTMETRIC tm; + HGDIOBJ saveFont; + HDC tileDC; + short ntile; + int t_x, t_y; + int x, y; + TCHAR wbuf[BUFSZ]; + RECT drawRect; + COLORREF OldBg, OldFg, NewBg; + char *p, *p1; + int column; + int spacing = 0; - int color = NO_COLOR, attr; - boolean menucolr = FALSE; + int color = NO_COLOR, attr; + boolean menucolr = FALSE; - UNREFERENCED_PARAMETER(wParam); + UNREFERENCED_PARAMETER(wParam); - lpdis = (LPDRAWITEMSTRUCT) lParam; + lpdis = (LPDRAWITEMSTRUCT) lParam; /* If there are no list box items, skip this message. */ - if (lpdis->itemID == -1) return FALSE; + if (lpdis->itemID == -1) + return FALSE; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); item = &data->menu.items[lpdis->itemID]; - tileDC = CreateCompatibleDC(lpdis->hDC); - saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); - NewBg = menu_bg_brush ? menu_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_MENU); - OldBg = SetBkColor(lpdis->hDC, NewBg); - OldFg = SetTextColor(lpdis->hDC, - menu_fg_brush ? menu_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_MENU)); + tileDC = CreateCompatibleDC(lpdis->hDC); + saveFont = SelectObject( + lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); + NewBg = menu_bg_brush ? menu_bg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_BG_MENU); + OldBg = SetBkColor(lpdis->hDC, NewBg); + OldFg = SetTextColor(lpdis->hDC, + menu_fg_brush + ? menu_fg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_FG_MENU)); GetTextMetrics(lpdis->hDC, &tm); - spacing = tm.tmAveCharWidth; + spacing = tm.tmAveCharWidth; - /* set initial offset */ - x = lpdis->rcItem.left + 1; + /* set initial offset */ + x = lpdis->rcItem.left + 1; /* print check mark and letter */ - if( NHMENU_IS_SELECTABLE(*item) ) { - char buf[2]; - if (data->how != PICK_NONE) { - HGDIOBJ saveBrush; - HBRUSH hbrCheckMark; + if (NHMENU_IS_SELECTABLE(*item)) { + char buf[2]; + if (data->how != PICK_NONE) { + HGDIOBJ saveBrush; + HBRUSH hbrCheckMark; - switch(item->count) { - case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break; - case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break; - default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break; - } + switch (item->count) { + case -1: + hbrCheckMark = CreatePatternBrush(data->bmpChecked); + break; + case 0: + hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); + break; + default: + hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); + break; + } - y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; - SetBrushOrgEx(lpdis->hDC, x, y, NULL); - saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); - PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); - SelectObject(lpdis->hDC, saveBrush); - DeleteObject(hbrCheckMark); + y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; + SetBrushOrgEx(lpdis->hDC, x, y, NULL); + saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); + PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); + SelectObject(lpdis->hDC, saveBrush); + DeleteObject(hbrCheckMark); + } - } + x += TILE_X + spacing; - x += TILE_X + spacing; + if (item->accelerator != 0) { + buf[0] = item->accelerator; + buf[1] = '\x0'; - if(item->accelerator!=0) { - buf[0] = item->accelerator; - buf[1] = '\x0'; + if (iflags.use_menu_color + && (menucolr = get_menu_coloring(item->str, &color, &attr))) { + /* TODO: use attr too */ + if (color != NO_COLOR) + SetTextColor(lpdis->hDC, nhcolor_to_RGB(color)); + } - if (iflags.use_menu_color && - (menucolr = get_menu_coloring(item->str, &color,&attr))) { - /* TODO: use attr too */ - if (color != NO_COLOR) - SetTextColor(lpdis->hDC, nhcolor_to_RGB(color)); - } + SetRect(&drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, + lpdis->rcItem.bottom); + DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, + DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + } + x += tm.tmAveCharWidth + tm.tmOverhang + spacing; + } else { + x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 2 * spacing; + } - SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom ); - DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); - } - x += tm.tmAveCharWidth + tm.tmOverhang + spacing; - } else { - x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 2*spacing; - } + /* print glyph if present */ + if (NHMENU_HAS_GLYPH(*item)) { + if (!IS_MAP_ASCII(iflags.wc_map_mode)) { + HGDIOBJ saveBmp; - /* print glyph if present */ - if( NHMENU_HAS_GLYPH(*item) ) { - if( !IS_MAP_ASCII(iflags.wc_map_mode) ) { - HGDIOBJ saveBmp; + saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); + ntile = glyph2tile[item->glyph]; + t_x = + (ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X; + t_y = + (ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y; - saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); - ntile = glyph2tile[ item->glyph ]; - t_x = (ntile % GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_X; - t_y = (ntile / GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_Y; + y = (lpdis->rcItem.bottom + lpdis->rcItem.top + - GetNHApp()->mapTile_Y) / 2; - y = (lpdis->rcItem.bottom + lpdis->rcItem.top - GetNHApp()->mapTile_Y) / 2; + if (GetNHApp()->bmpMapTiles == GetNHApp()->bmpTiles) { + /* using original nethack tiles - apply image transparently */ + nhapply_image_transparent(lpdis->hDC, x, y, TILE_X, TILE_Y, + tileDC, t_x, t_y, TILE_X, TILE_Y, + TILE_BK_COLOR); + } else { + /* using custom tiles - simple blt */ + BitBlt(lpdis->hDC, x, y, GetNHApp()->mapTile_X, + GetNHApp()->mapTile_Y, tileDC, t_x, t_y, SRCCOPY); + } + SelectObject(tileDC, saveBmp); + x += GetNHApp()->mapTile_X; + } else { + const char *sel_ind; + switch (item->count) { + case -1: + sel_ind = "+"; + break; + case 0: + sel_ind = "-"; + break; + default: + sel_ind = "#"; + break; + } - if( GetNHApp()->bmpMapTiles == GetNHApp()->bmpTiles ) { - /* using original nethack tiles - apply image transparently */ - nhapply_image_transparent( - lpdis->hDC, x, y, TILE_X, TILE_Y, - tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR ); - } else { - /* using custom tiles - simple blt */ - BitBlt( - lpdis->hDC, x, y, GetNHApp()->mapTile_X, GetNHApp()->mapTile_Y, - tileDC, t_x, t_y, SRCCOPY ); - } - SelectObject(tileDC, saveBmp); - x += GetNHApp()->mapTile_X; - } else { - const char *sel_ind; - switch(item->count) { - case -1: sel_ind = "+"; break; - case 0: sel_ind = "-"; break; - default: sel_ind = "#"; break; - } + SetRect(&drawRect, x, lpdis->rcItem.top, + min(x + tm.tmAveCharWidth, lpdis->rcItem.right), + lpdis->rcItem.bottom); + DrawText(lpdis->hDC, NH_A2W(sel_ind, wbuf, BUFSZ), 1, &drawRect, + DT_CENTER | DT_VCENTER | DT_SINGLELINE); + x += tm.tmAveCharWidth; + } + } else { + /* no glyph - need to adjust so help window won't look to cramped */ + x += TILE_X; + } - SetRect( - &drawRect, - x, - lpdis->rcItem.top, - min(x + tm.tmAveCharWidth, lpdis->rcItem.right), - lpdis->rcItem.bottom - ); - DrawText(lpdis->hDC, - NH_A2W(sel_ind, wbuf, BUFSZ), - 1, - &drawRect, - DT_CENTER| DT_VCENTER | DT_SINGLELINE - ); - x += tm.tmAveCharWidth; - } - } else { - /* no glyph - need to adjust so help window won't look to cramped */ - x += TILE_X; - } + x += spacing; - x += spacing; + /* draw item text */ + p1 = item->str; + p = strchr(item->str, '\t'); + column = 0; + SetRect(&drawRect, x, lpdis->rcItem.top, + min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), + lpdis->rcItem.bottom); + for (;;) { + TCHAR wbuf[BUFSZ]; + if (p != NULL) + *p = '\0'; /* for time being, view tab field as zstring */ + DrawText(lpdis->hDC, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), &drawRect, + DT_LEFT | DT_VCENTER | DT_SINGLELINE); + if (p != NULL) + *p = '\t'; + else /* last string so, */ + break; - /* draw item text */ - p1 = item->str; - p = strchr(item->str, '\t'); - column = 0; - SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), - lpdis->rcItem.bottom ); - for (;;) { - TCHAR wbuf[BUFSZ]; - if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ - DrawText(lpdis->hDC, - NH_A2W(p1, wbuf, BUFSZ), - strlen(p1), - &drawRect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE - ); - if (p != NULL) *p = '\t'; - else /* last string so, */ break; + p1 = p + 1; + p = strchr(p1, '\t'); + drawRect.left = drawRect.right + TAB_SEPARATION; + ++column; + drawRect.right = min(drawRect.left + data->menu.tab_stop_size[column], + lpdis->rcItem.right); + } - p1 = p + 1; - p = strchr(p1, '\t'); - drawRect.left = drawRect.right + TAB_SEPARATION; - ++column; - drawRect.right = min (drawRect.left + data->menu.tab_stop_size[column], lpdis->rcItem.right); - } + /* draw focused item */ + if (item->has_focus || (NHMENU_IS_SELECTABLE(*item) + && data->menu.items[lpdis->itemID].count != -1)) { + RECT client_rt; - /* draw focused item */ - if( item->has_focus - || (NHMENU_IS_SELECTABLE(*item) && - data->menu.items[lpdis->itemID].count!=-1)) { - RECT client_rt; + GetClientRect(lpdis->hwndItem, &client_rt); + client_rt.right = min(client_rt.right, lpdis->rcItem.right); + if (NHMENU_IS_SELECTABLE(*item) + && data->menu.items[lpdis->itemID].count != 0 + && item->glyph != NO_GLYPH) { + if (data->menu.items[lpdis->itemID].count == -1) { + _stprintf(wbuf, TEXT("Count: All")); + } else { + _stprintf(wbuf, TEXT("Count: %d"), + data->menu.items[lpdis->itemID].count); + } - GetClientRect(lpdis->hwndItem, &client_rt); - client_rt.right = min(client_rt.right, lpdis->rcItem.right); - if( NHMENU_IS_SELECTABLE(*item) && - data->menu.items[lpdis->itemID].count!=0 && - item->glyph != NO_GLYPH ) { - if( data->menu.items[lpdis->itemID].count==-1 ) { - _stprintf(wbuf, TEXT("Count: All") ); - } else { - _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); - } + SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, + lpdis->hDC, FALSE)); - SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); + /* calculate text rectangle */ + SetRect(&drawRect, client_rt.left, lpdis->rcItem.top, + client_rt.right, lpdis->rcItem.bottom); + DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, + DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE + | DT_NOPREFIX); - /* calculate text rectangle */ - SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); - DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, - DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); - - /* erase text rectangle */ - drawRect.left = max(client_rt.left+1, client_rt.right - (drawRect.right - drawRect.left) - 10); - drawRect.right = client_rt.right-1; - drawRect.top = lpdis->rcItem.top; - drawRect.bottom = lpdis->rcItem.bottom; - FillRect(lpdis->hDC, &drawRect, - menu_bg_brush ? menu_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_MENU)); + /* erase text rectangle */ + drawRect.left = + max(client_rt.left + 1, + client_rt.right - (drawRect.right - drawRect.left) - 10); + drawRect.right = client_rt.right - 1; + drawRect.top = lpdis->rcItem.top; + drawRect.bottom = lpdis->rcItem.bottom; + FillRect(lpdis->hDC, &drawRect, + menu_bg_brush ? menu_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_MENU)); - /* draw text */ - DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, - DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); - } + /* draw text */ + DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, + DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + } } if (item->has_focus) { - /* draw focus rect */ - RECT client_rt; + /* draw focus rect */ + RECT client_rt; - GetClientRect(lpdis->hwndItem, &client_rt); - SetRect( &drawRect, - client_rt.left, - lpdis->rcItem.top, - client_rt.left + ListView_GetColumnWidth(lpdis->hwndItem, 0), - lpdis->rcItem.bottom ); - DrawFocusRect(lpdis->hDC, &drawRect); - } + GetClientRect(lpdis->hwndItem, &client_rt); + SetRect(&drawRect, client_rt.left, lpdis->rcItem.top, + client_rt.left + ListView_GetColumnWidth(lpdis->hwndItem, 0), + lpdis->rcItem.bottom); + DrawFocusRect(lpdis->hDC, &drawRect); + } - SetTextColor (lpdis->hDC, OldFg); - SetBkColor (lpdis->hDC, OldBg); - SelectObject(lpdis->hDC, saveFont); - DeleteDC(tileDC); - return TRUE; + SetTextColor(lpdis->hDC, OldFg); + SetBkColor(lpdis->hDC, OldBg); + SelectObject(lpdis->hDC, saveFont); + DeleteDC(tileDC); + return TRUE; } /*-----------------------------------------------------------------------------*/ -BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) +BOOL +onListChar(HWND hWnd, HWND hwndList, WORD ch) { - int i = 0; - PNHMenuWindow data; - int curIndex, topIndex, pageSize; - boolean is_accelerator = FALSE; + int i = 0; + PNHMenuWindow data; + int curIndex, topIndex, pageSize; + boolean is_accelerator = FALSE; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch( ch ) { - case MENU_FIRST_PAGE: - i = 0; - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + switch (ch) { + case MENU_FIRST_PAGE: + i = 0; + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_LAST_PAGE: - i = max(0, data->menu.size-1); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + case MENU_LAST_PAGE: + i = max(0, data->menu.size - 1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_NEXT_PAGE: - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + case MENU_NEXT_PAGE: + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); /* Focus down one page */ - i = min(curIndex+pageSize, data->menu.size-1); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + i = min(curIndex + pageSize, data->menu.size - 1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); /* Scrollpos down one page */ - i = min(topIndex+(2*pageSize - 1), data->menu.size-1); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + i = min(topIndex + (2 * pageSize - 1), data->menu.size - 1); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; - case MENU_PREVIOUS_PAGE: - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + case MENU_PREVIOUS_PAGE: + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); /* Focus up one page */ - i = max(curIndex-pageSize, 0); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + i = max(curIndex - pageSize, 0); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); /* Scrollpos up one page */ - i = max(topIndex-pageSize, 0); - ListView_EnsureVisible(hwndList, i, FALSE); - break; + i = max(topIndex - pageSize, 0); + ListView_EnsureVisible(hwndList, i, FALSE); + break; - case MENU_SELECT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem(hwndList, data, i, -1); - } - return -2; - } - break; + case MENU_SELECT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, -1); + } + return -2; + } + break; - case MENU_UNSELECT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem(hwndList, data, i, 0); - } - return -2; - } - break; + case MENU_UNSELECT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, 0); + } + return -2; + } + break; - case MENU_INVERT_ALL: - if( data->how == PICK_ANY ) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } - return -2; - } - break; + case MENU_INVERT_ALL: + if (data->how == PICK_ANY) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + SelectMenuItem(hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } + return -2; + } + break; - case MENU_SELECT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; ihow == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, -1); + } + return -2; + } + break; - case MENU_UNSELECT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; ihow == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, 0); + } + return -2; + } + break; - case MENU_INVERT_PAGE: - if( data->how == PICK_ANY ) { - int from, to; - reset_menu_count(hwndList, data); - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - from = max(0, topIndex); - to = min(data->menu.size, from+pageSize); - for(i=from; imenu.items[i])? 0 : -1 - ); - } - return -2; - } - break; + case MENU_INVERT_PAGE: + if (data->how == PICK_ANY) { + int from, to; + reset_menu_count(hwndList, data); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + from = max(0, topIndex); + to = min(data->menu.size, from + pageSize); + for (i = from; i < to; i++) { + SelectMenuItem(hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } + return -2; + } + break; - case MENU_SEARCH: - if( data->how==PICK_ANY || data->how==PICK_ONE ) { - char buf[BUFSZ]; - - reset_menu_count(hwndList, data); - if( mswin_getlin_window("Search for:", buf, BUFSZ)==IDCANCEL ) { - strcpy(buf, "\033"); - } - if( data->is_active ) SetFocus(hwndList); // set focus back to the list control - if (!*buf || *buf == '\033') return -2; - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) - && strstr(data->menu.items[i].str, buf) ) { - if (data->how == PICK_ANY) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - break; - } - } - } - } else { - mswin_nhbell(); - } - return -2; + case MENU_SEARCH: + if (data->how == PICK_ANY || data->how == PICK_ONE) { + char buf[BUFSZ]; - case ' ': - { + reset_menu_count(hwndList, data); + if (mswin_getlin_window("Search for:", buf, BUFSZ) == IDCANCEL) { + strcpy(buf, "\033"); + } + if (data->is_active) + SetFocus(hwndList); // set focus back to the list control + if (!*buf || *buf == '\033') + return -2; + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && strstr(data->menu.items[i].str, buf)) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 : -1); + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, + LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + break; + } + } + } + } else { + mswin_nhbell(); + } + return -2; + + case ' ': { if (GetNHApp()->regNetHackMode) { /* NetHack mode: Scroll down one page, ends menu when on last page. */ @@ -1296,294 +1350,290 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; GetScrollInfo(hwndList, SB_VERT, &si); - if ((si.nPos + (int)si.nPage) > (si.nMax - si.nMin)) { + if ((si.nPos + (int) si.nPage) > (si.nMax - si.nMin)) { /* We're at the bottom: dismiss. */ data->done = 1; - data->result = 0; + data->result = 0; return -2; } /* We're not at the bottom: page down. */ - topIndex = ListView_GetTopIndex( hwndList ); - pageSize = ListView_GetCountPerPage( hwndList ); - curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + topIndex = ListView_GetTopIndex(hwndList); + pageSize = ListView_GetCountPerPage(hwndList); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); /* Focus down one page */ - i = min(curIndex+pageSize, data->menu.size-1); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + i = min(curIndex + pageSize, data->menu.size - 1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); /* Scrollpos down one page */ - i = min(topIndex+(2*pageSize - 1), data->menu.size-1); - ListView_EnsureVisible(hwndList, i, FALSE); + i = min(topIndex + (2 * pageSize - 1), data->menu.size - 1); + ListView_EnsureVisible(hwndList, i, FALSE); - return -2; + return -2; } else { - /* Windows mode: ends menu for PICK_ONE/PICK_NONE - select item for PICK_ANY */ - if( data->how==PICK_ONE || data->how==PICK_NONE ) { - data->done = 1; - data->result = 0; - return -2; - } else if( data->how==PICK_ANY ) { - i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); - if( i>=0 ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } - } + /* Windows mode: ends menu for PICK_ONE/PICK_NONE + select item for PICK_ANY */ + if (data->how == PICK_ONE || data->how == PICK_NONE) { + data->done = 1; + data->result = 0; + return -2; + } else if (data->how == PICK_ANY) { + i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + if (i >= 0) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 : -1); + } + } } + } break; + + default: + if (strchr(data->menu.gacc, ch) + && !(ch == '0' && data->menu.counting)) { + /* matched a group accelerator */ + if (data->how == PICK_ANY || data->how == PICK_ONE) { + reset_menu_count(hwndList, data); + for (i = 0; i < data->menu.size; i++) { + if (NHMENU_IS_SELECTABLE(data->menu.items[i]) + && data->menu.items[i].group_accel == ch) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + data->result = 0; + data->done = 1; + return -2; + } + } + } + return -2; + } else { + mswin_nhbell(); + return -2; + } + } + + if (isdigit(ch)) { + int count; + i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + if (i >= 0) { + count = data->menu.items[i].count; + if (count == -1) + count = 0; + count *= 10L; + count += (int) (ch - '0'); + if (count != 0) /* ignore leading zeros */ { + data->menu.counting = TRUE; + data->menu.items[i].count = min(100000, count); + ListView_RedrawItems(hwndList, i, + i); /* update count mark */ + } + } + return -2; + } + + is_accelerator = FALSE; + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator == ch) { + is_accelerator = TRUE; + break; + } + } + + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') + || is_accelerator) { + if (data->how == PICK_ANY || data->how == PICK_ONE) { + for (i = 0; i < data->menu.size; i++) { + if (data->menu.items[i].accelerator == ch) { + if (data->how == PICK_ANY) { + SelectMenuItem( + hwndList, data, i, + NHMENU_IS_SELECTED(data->menu.items[i]) ? 0 + : -1); + ListView_SetItemState(hwndList, i, LVIS_FOCUSED, + LVIS_FOCUSED); + ListView_EnsureVisible(hwndList, i, FALSE); + return -2; + } else if (data->how == PICK_ONE) { + SelectMenuItem(hwndList, data, i, -1); + data->result = 0; + data->done = 1; + return -2; + } + } + } + } + } + break; } - break; - default: - if( strchr(data->menu.gacc, ch) && - !(ch=='0' && data->menu.counting) ) { - /* matched a group accelerator */ - if (data->how == PICK_ANY || data->how == PICK_ONE) { - reset_menu_count(hwndList, data); - for(i=0; imenu.size; i++ ) { - if( NHMENU_IS_SELECTABLE(data->menu.items[i]) && - data->menu.items[i].group_accel == ch ) { - if( data->how == PICK_ANY ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - data->result = 0; - data->done = 1; - return -2; - } - } - } - return -2; - } else { - mswin_nhbell(); - return -2; - } - } - - if (isdigit(ch)) { - int count; - i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); - if( i>=0 ) { - count = data->menu.items[i].count; - if( count==-1 ) count=0; - count *= 10L; - count += (int)(ch - '0'); - if (count != 0) /* ignore leading zeros */ { - data->menu.counting = TRUE; - data->menu.items[i].count = min(100000, count); - ListView_RedrawItems( hwndList, i, i ); /* update count mark */ - } - } - return -2; - } - - is_accelerator = FALSE; - for(i=0; imenu.size; i++) { - if( data->menu.items[i].accelerator == ch ) { - is_accelerator = TRUE; - break; - } - } - - if( (ch>='a' && ch<='z') || - (ch>='A' && ch<='Z') || is_accelerator) { - if (data->how == PICK_ANY || data->how == PICK_ONE) { - for(i=0; imenu.size; i++ ) { - if( data->menu.items[i].accelerator == ch ) { - if( data->how == PICK_ANY ) { - SelectMenuItem( - hwndList, - data, - i, - NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1 - ); - ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); - ListView_EnsureVisible(hwndList, i, FALSE); - return -2; - } else if( data->how == PICK_ONE ) { - SelectMenuItem( - hwndList, - data, - i, - -1 - ); - data->result = 0; - data->done = 1; - return -2; - } - } - } - } - } - break; - } - - reset_menu_count(hwndList, data); - return -1; + reset_menu_count(hwndList, data); + return -1; } /*-----------------------------------------------------------------------------*/ -void mswin_menu_window_size (HWND hWnd, LPSIZE sz) +void +mswin_menu_window_size(HWND hWnd, LPSIZE sz) { - HWND control; - PNHMenuWindow data; - RECT rt, wrt; - int extra_cx; + HWND control; + PNHMenuWindow data; + RECT rt, wrt; + int extra_cx; - data = (PNHMenuWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if(data) { - control = GetMenuControl(hWnd); + data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (data) { + control = GetMenuControl(hWnd); - /* get the control size */ - GetClientRect(control, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + /* get the control size */ + GetClientRect(control, &rt); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; - /* calculate "extra" space around the control */ - GetWindowRect(hWnd, &wrt); - extra_cx = (wrt.right-wrt.left) - sz->cx; + /* calculate "extra" space around the control */ + GetWindowRect(hWnd, &wrt); + extra_cx = (wrt.right - wrt.left) - sz->cx; - if( data->type==MENU_TYPE_MENU ) { - sz->cx = data->menu.menu_cx + GetSystemMetrics(SM_CXVSCROLL); - } else { - /* Use the width of the text box */ - sz->cx = data->text.text_box_size.cx + 2*GetSystemMetrics(SM_CXVSCROLL); - } - sz->cx += extra_cx; - } else { - /* uninitilized window */ - GetClientRect(hWnd, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; - } + if (data->type == MENU_TYPE_MENU) { + sz->cx = data->menu.menu_cx + GetSystemMetrics(SM_CXVSCROLL); + } else { + /* Use the width of the text box */ + sz->cx = data->text.text_box_size.cx + + 2 * GetSystemMetrics(SM_CXVSCROLL); + } + sz->cx += extra_cx; + } else { + /* uninitilized window */ + GetClientRect(hWnd, &rt); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; + } } /*-----------------------------------------------------------------------------*/ -void SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count) +void +SelectMenuItem(HWND hwndList, PNHMenuWindow data, int item, int count) { - int i; + int i; - if( item<0 || item>=data->menu.size ) return; + if (item < 0 || item >= data->menu.size) + return; - if( data->how==PICK_ONE && count!=0 ) { - for(i=0; imenu.size; i++) - if( item!=i && data->menu.items[i].count!=0 ) { - data->menu.items[i].count = 0; - ListView_RedrawItems( hwndList, i, i ); - }; - } + if (data->how == PICK_ONE && count != 0) { + for (i = 0; i < data->menu.size; i++) + if (item != i && data->menu.items[i].count != 0) { + data->menu.items[i].count = 0; + ListView_RedrawItems(hwndList, i, i); + }; + } - data->menu.items[item].count = count; - ListView_RedrawItems( hwndList, item, item ); - reset_menu_count(hwndList, data); + data->menu.items[item].count = count; + ListView_RedrawItems(hwndList, item, item); + reset_menu_count(hwndList, data); } /*-----------------------------------------------------------------------------*/ -void reset_menu_count(HWND hwndList, PNHMenuWindow data) +void +reset_menu_count(HWND hwndList, PNHMenuWindow data) { - int i; - data->menu.counting = FALSE; - if( IsWindow(hwndList) ) { - i = ListView_GetNextItem((hwndList), -1, LVNI_FOCUSED); - if( i>=0 ) ListView_RedrawItems( hwndList, i, i ); - } + int i; + data->menu.counting = FALSE; + if (IsWindow(hwndList)) { + i = ListView_GetNextItem((hwndList), -1, LVNI_FOCUSED); + if (i >= 0) + ListView_RedrawItems(hwndList, i, i); + } } /*-----------------------------------------------------------------------------*/ /* List window Proc */ -LRESULT CALLBACK NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - BOOL bUpdateFocusItem; + BOOL bUpdateFocusItem; - /* we will redraw focused item whenever horizontal scrolling occurs - since "Count: XXX" indicator is garbled by scrolling */ - bUpdateFocusItem = FALSE; + /* we will redraw focused item whenever horizontal scrolling occurs + since "Count: XXX" indicator is garbled by scrolling */ + bUpdateFocusItem = FALSE; - switch(message) { - case WM_KEYDOWN: - if( wParam==VK_LEFT || wParam==VK_RIGHT ) - bUpdateFocusItem = TRUE; - break; - - case WM_CHAR: /* filter keyboard input for the control */ - if( wParam>0 && wParam<256 && onListChar(GetParent(hWnd), hWnd, (char)wParam)==-2 ) { - return 0; - } else { - return 1; - } - break; + switch (message) { + case WM_KEYDOWN: + if (wParam == VK_LEFT || wParam == VK_RIGHT) + bUpdateFocusItem = TRUE; + break; - case WM_SIZE: - case WM_HSCROLL: - bUpdateFocusItem = TRUE; - break; + case WM_CHAR: /* filter keyboard input for the control */ + if (wParam > 0 && wParam < 256 + && onListChar(GetParent(hWnd), hWnd, (char) wParam) == -2) { + return 0; + } else { + return 1; + } + break; - case WM_SETFOCUS: - if( GetParent(hWnd)!=GetNHApp()->hPopupWnd) { - SetFocus(GetNHApp()->hMainWnd); - } - return FALSE; - } + case WM_SIZE: + case WM_HSCROLL: + bUpdateFocusItem = TRUE; + break; - /* update focused item */ - if( bUpdateFocusItem ) { - int i; - RECT rt; + case WM_SETFOCUS: + if (GetParent(hWnd) != GetNHApp()->hPopupWnd) { + SetFocus(GetNHApp()->hMainWnd); + } + return FALSE; + } - /* invalidate the focus rectangle */ - i = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); - if( i!=-1 ) { - ListView_GetItemRect(hWnd, i, &rt, LVIR_BOUNDS); - InvalidateRect(hWnd, &rt, TRUE); - } - } + /* update focused item */ + if (bUpdateFocusItem) { + int i; + RECT rt; - /* call ListView control window proc */ - if( wndProcListViewOrig ) - return CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, lParam); - else - return 0; + /* invalidate the focus rectangle */ + i = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); + if (i != -1) { + ListView_GetItemRect(hWnd, i, &rt, LVIR_BOUNDS); + InvalidateRect(hWnd, &rt, TRUE); + } + } + + /* call ListView control window proc */ + if (wndProcListViewOrig) + return CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, + lParam); + else + return 0; } /*-----------------------------------------------------------------------------*/ /* Text control window proc - implements scrolling without a cursor */ -LRESULT CALLBACK NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hDC; - RECT rc; + HDC hDC; + RECT rc; - switch(message) { - case WM_ERASEBKGND: - hDC = (HDC) wParam; - GetClientRect(hWnd, &rc); - FillRect(hDC, &rc, text_bg_brush? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); - return 0; + switch (message) { + case WM_ERASEBKGND: + hDC = (HDC) wParam; + GetClientRect(hWnd, &rc); + FillRect(hDC, &rc, text_bg_brush + ? text_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); + return 0; - case WM_KEYDOWN: - switch (wParam) - { - /* close on space in Windows mode + case WM_KEYDOWN: + switch (wParam) { + /* close on space in Windows mode page down on space in NetHack mode */ - case VK_SPACE: - { + case VK_SPACE: { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; GetScrollInfo(hWnd, SB_VERT, &si); /* If nethackmode and not at the end of the list */ - if (GetNHApp()->regNetHackMode && - (si.nPos + (int)si.nPage) <= (si.nMax - si.nMin)) + if (GetNHApp()->regNetHackMode + && (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin)) SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); else - PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); + PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), + 0); return 0; } case VK_NEXT: @@ -1598,21 +1648,19 @@ LRESULT CALLBACK NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case VK_DOWN: SendMessage(hWnd, EM_SCROLL, SB_LINEDOWN, 0); return 0; + } + break; - } - break; + /* edit control needs to know nothing of its focus */ + case WM_SETFOCUS: + HideCaret(hWnd); + return 0; + } - /* edit control needs to know nothing of its focus */ - case WM_SETFOCUS: - HideCaret(hWnd); - return 0; - - } - - if( editControlWndProc ) - return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam); - else - return 0; + if (editControlWndProc) + return CallWindowProc(editControlWndProc, hWnd, message, wParam, + lParam); + else + return 0; } /*-----------------------------------------------------------------------------*/ - diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index acfc70a54..5eafe7409 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhmsgwnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhmsgwnd.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.31 $ */ /* NetHack 3.6 mhmsgwnd.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.25 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,42 +8,43 @@ #include "mhmsg.h" #include "mhfont.h" -#define MSG_WRAP_TEXT +#define MSG_WRAP_TEXT -#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 2) -#define MAX_MSG_LINES 128 -#define MSG_LINES (int)min(iflags.msg_history, MAX_MSG_LINES) -#define MAXWINDOWTEXT TBUFSZ +#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 2) +#define MAX_MSG_LINES 128 +#define MSG_LINES (int) min(iflags.msg_history, MAX_MSG_LINES) +#define MAXWINDOWTEXT TBUFSZ -#define DEFAULT_COLOR_BG_MSG COLOR_WINDOW -#define DEFAULT_COLOR_FG_MSG COLOR_WINDOWTEXT +#define DEFAULT_COLOR_BG_MSG COLOR_WINDOW +#define DEFAULT_COLOR_FG_MSG COLOR_WINDOWTEXT #define MORE "--More--" struct window_line { - int attr; - char text[MAXWINDOWTEXT+1]; + int attr; + char text[MAXWINDOWTEXT + 1]; }; typedef struct mswin_nethack_message_window { - size_t max_text; - struct window_line window_text[MAX_MSG_LINES]; - int lines_last_turn; /* lines added during the last turn */ - int lines_not_seen; /* lines not yet seen by user after last turn or --More-- */ - int nevermore; /* We want no more --More-- prompts */ + size_t max_text; + struct window_line window_text[MAX_MSG_LINES]; + int lines_last_turn; /* lines added during the last turn */ + int lines_not_seen; /* lines not yet seen by user after last turn or + --More-- */ + int nevermore; /* We want no more --More-- prompts */ - int xChar; /* horizontal scrolling unit */ - int yChar; /* vertical scrolling unit */ - int xUpper; /* average width of uppercase letters */ - int xPos; /* current horizontal scrolling position */ - int yPos; /* current vertical scrolling position */ - int xMax; /* maximum horizontal scrolling position */ - int yMax; /* maximum vertical scrolling position */ - int xPage; /* page size of horizontal scroll bar */ - } NHMessageWindow, *PNHMessageWindow; + int xChar; /* horizontal scrolling unit */ + int yChar; /* vertical scrolling unit */ + int xUpper; /* average width of uppercase letters */ + int xPos; /* current horizontal scrolling position */ + int yPos; /* current vertical scrolling position */ + int xMax; /* maximum horizontal scrolling position */ + int yMax; /* maximum vertical scrolling position */ + int xPage; /* page size of horizontal scroll bar */ +} NHMessageWindow, *PNHMessageWindow; static TCHAR szMessageWindowClass[] = TEXT("MSNHMessageWndClass"); -LRESULT CALLBACK NHMessageWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHMessageWndProc(HWND, UINT, WPARAM, LPARAM); static void register_message_window_class(void); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); @@ -53,752 +54,800 @@ static void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); static COLORREF setMsgTextColor(HDC hdc, int gray); static void onPaint(HWND hWnd); static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); -static BOOL can_append_text(HWND hWnd, int attr, const char* text ); - /* check if text can be appended to the last line without wrapping */ +static BOOL can_append_text(HWND hWnd, int attr, const char *text); +/* check if text can be appended to the last line without wrapping */ static BOOL more_prompt_check(HWND hWnd); - /* check if "--more--" promt needs to be displayed */ +/* check if "--more--" promt needs to be displayed */ #ifdef USER_SOUNDS -extern void play_sound_for_message(const char* str); +extern void play_sound_for_message(const char *str); #endif -HWND mswin_init_message_window () { - static int run_once = 0; - HWND ret; - DWORD style; - RECT rt; - - if( !run_once ) { - register_message_window_class( ); - run_once = 1; - } - - /* get window position */ - if( GetNHApp()->bAutoLayout ) { - SetRect( &rt, 0, 0, 0, 0); - } else { - mswin_get_window_placement(NHW_MESSAGE, &rt); - } - -#ifdef MSG_WRAP_TEXT - style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_SIZEBOX; -#else - style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL | WS_SIZEBOX; -#endif - - ret = CreateWindowEx( - WS_EX_CLIENTEDGE, - szMessageWindowClass, /* registered class name */ - NULL, /* window name */ - style, /* window style */ - rt.left, /* horizontal position of window */ - rt.top, /* vertical position of window */ - rt.right - rt.left, /* window width */ - rt.bottom - rt.top, /* window height */ - GetNHApp()->hMainWnd, /* handle to parent or owner window */ - NULL, /* menu handle or child identifier */ - GetNHApp()->hApp, /* handle to application instance */ - NULL ); /* window-creation data */ - - if( !ret ) panic("Cannot create message window"); - - /* Set window caption */ - SetWindowText(ret, "Messages"); - - return ret; -} - -void register_message_window_class() +HWND +mswin_init_message_window() { - WNDCLASS wcex; - ZeroMemory( &wcex, sizeof(wcex)); - - wcex.style = CS_NOCLOSE; - wcex.lpfnWndProc = (WNDPROC)NHMessageWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = message_bg_brush ? message_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_MSG); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szMessageWindowClass; - - RegisterClass(&wcex); -} - -LRESULT CALLBACK NHMessageWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_CREATE: - onCreate( hWnd, wParam, lParam ); - break; - - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; - - case WM_PAINT: - onPaint(hWnd); - break; - - case WM_SETFOCUS: - SetFocus(GetNHApp()->hMainWnd); - break; - -#ifndef MSG_WRAP_TEXT - case WM_HSCROLL: - onMSNH_HScroll(hWnd, wParam, lParam); - break; -#endif - - case WM_VSCROLL: - onMSNH_VScroll(hWnd, wParam, lParam); - break; - - case WM_DESTROY: - { - PNHMessageWindow data; - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - } break; - - case WM_SIZE: - { - SCROLLINFO si; - int xNewSize; - int yNewSize; - PNHMessageWindow data; - RECT rt; - - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - - xNewSize = LOWORD(lParam); - yNewSize = HIWORD(lParam); - - if( xNewSize>0 || yNewSize>0 ) { - -#ifndef MSG_WRAP_TEXT - data->xPage = xNewSize/data->xChar; - data->xMax = max(0, (int)(1 + data->max_text - data->xPage)); - data->xPos = min(data->xPos, data->xMax); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = data->max_text; - si.nPage = data->xPage; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); -#endif - - data->yMax = MSG_LINES-1; - data->yPos = min(data->yPos, data->yMax); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = MSG_VISIBLE_LINES; - si.nMax = data->yMax + MSG_VISIBLE_LINES - 1; - si.nPage = MSG_VISIBLE_LINES; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - } - - /* update NetHack internal window position */ - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_MESSAGE, &rt); - - /* redraw window - it does not handle incremental resizing too well */ - InvalidateRect(hWnd, NULL, TRUE); - } - break; - - case WM_MOVE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_MESSAGE, &rt); - } - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} - -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: - { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - SCROLLINFO si; - char* p; - - if( msg_data->append == 1) { - /* Forcibly append to line, even if we pass the edge */ - strncat(data->window_text[MSG_LINES-1].text, msg_data->text, - MAXWINDOWTEXT - strlen(data->window_text[MSG_LINES-1].text)); - } else if( msg_data->append < 0) { - /* remove that many chars */ - int len = strlen(data->window_text[MSG_LINES-1].text); - int newend = max(len + msg_data->append, 0); - data->window_text[MSG_LINES-1].text[newend] = '\0'; - } else { - if( can_append_text(hWnd, msg_data->attr, msg_data->text ) ) { - strncat(data->window_text[MSG_LINES-1].text, " ", MAXWINDOWTEXT-strlen(data->window_text[MSG_LINES-1].text)); - strncat(data->window_text[MSG_LINES-1].text, msg_data->text, MAXWINDOWTEXT-strlen(data->window_text[MSG_LINES-1].text)); - } else { - /* check for "--more--" */ - if( !data->nevermore && more_prompt_check(hWnd) ) { - int okkey = 0; - int chop; - // @@@ Ok respnses - - /* append more prompt and inticate the update */ - strncat(data->window_text[MSG_LINES-1].text, MORE, MAXWINDOWTEXT - strlen(data->window_text[MSG_LINES-1].text)); - InvalidateRect(hWnd, NULL, TRUE); - - /* get the input */ - while (!okkey) { - int c = mswin_nhgetch(); - - switch (c) - { - /* space or enter */ - case ' ': - case '\015': - okkey = 1; - break; - /* ESC */ - case '\033': - data->nevermore = 1; - okkey = 1; - break; - default: - break; - } - } - - /* erase the "--more--" prompt */ - chop = strlen(data->window_text[MSG_LINES-1].text) - strlen(MORE); - data->window_text[MSG_LINES-1].text[chop] = '\0'; - data->lines_not_seen = 0; - } - - /* check if the string is empty */ - for(p = data->window_text[MSG_LINES-1].text; *p && isspace(*p); p++); - - if( *p ) { - /* last string is not empty - scroll up */ - memmove(&data->window_text[0], - &data->window_text[1], - (MSG_LINES-1)*sizeof(data->window_text[0])); - } - - /* append new text to the end of the array */ - data->window_text[MSG_LINES-1].attr = msg_data->attr; - strncpy(data->window_text[MSG_LINES-1].text, msg_data->text, MAXWINDOWTEXT); - - data->lines_not_seen++; - data->lines_last_turn++; - } - } - - /* reset V-scroll position to display new text */ - data->yPos = data->yMax; - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - - /* update window content */ - InvalidateRect(hWnd, NULL, TRUE); - -#ifdef USER_SOUNDS - if( !GetNHApp()->bNoSounds ) play_sound_for_message(msg_data->text); -#endif - } - break; - - case MSNH_MSG_CLEAR_WINDOW: - { - data->lines_last_turn = 0; - data->lines_not_seen = 0; - data->nevermore = 0; - break; - } - case MSNH_MSG_CARET: - /* Create or destroy a caret */ - if (*(int *)lParam) - CreateCaret(hWnd, NULL, 0, data->yChar); - else { - DestroyCaret(); - /* this means we just did something interactive in this window, so we - don't need a --More-- for the lines above. - */ - data->lines_not_seen = 0; - } - break; - - case MSNH_MSG_GETTEXT: { - PMSNHMsgGetText msg_data = (PMSNHMsgGetText)lParam; - int i; - size_t buflen; - - buflen = 0; - for(i=0; iwindow_text[i].text ) { - strncpy(&msg_data->buffer[buflen], data->window_text[i].text, msg_data->max_size - buflen ); - buflen += strlen(data->window_text[i].text); - if( buflen >= msg_data->max_size ) break; - - strncpy(&msg_data->buffer[buflen], "\r\n", msg_data->max_size - buflen ); - buflen += 2; - if( buflen > msg_data->max_size ) break; - } - } break; - - } /* switch( wParam ) */ -} - -void onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - SCROLLINFO si; - int yInc; - - UNREFERENCED_PARAMETER(lParam); - - /* get window data */ - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE | SIF_POS; - GetScrollInfo(hWnd, SB_VERT, &si); - - switch(LOWORD (wParam)) - { - // User clicked the shaft above the scroll box. - - case SB_PAGEUP: - yInc = -(int)si.nPage; - break; - - // User clicked the shaft below the scroll box. - - case SB_PAGEDOWN: - yInc = si.nPage; - break; - - // User clicked the top arrow. - - case SB_LINEUP: - yInc = -1; - break; - - // User clicked the bottom arrow. - - case SB_LINEDOWN: - yInc = 1; - break; - - // User dragged the scroll box. - - case SB_THUMBTRACK: - yInc = HIWORD(wParam) - data->yPos; - break; - - default: - yInc = 0; - } - - // If applying the vertical scrolling increment does not - // take the scrolling position out of the scrolling range, - // increment the scrolling position, adjust the position - // of the scroll box, and update the window. UpdateWindow - // sends the WM_PAINT message. - - if (yInc = max( MSG_VISIBLE_LINES - data->yPos, - min(yInc, data->yMax - data->yPos))) - { - data->yPos += yInc; - /* ScrollWindowEx(hWnd, 0, -data->yChar * yInc, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); - */ - InvalidateRect(hWnd, NULL, TRUE); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->yPos; - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - - UpdateWindow (hWnd); - } -} - -#ifndef MSG_WRAP_TEXT -void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) -{ - PNHMessageWindow data; - SCROLLINFO si; - int xInc; - - /* get window data */ - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE; - GetScrollInfo(hWnd, SB_HORZ, &si); - - switch(LOWORD (wParam)) - { - // User clicked shaft left of the scroll box. - - case SB_PAGEUP: - xInc = - (int)si.nPage; - break; - - // User clicked shaft right of the scroll box. - - case SB_PAGEDOWN: - xInc = si.nPage; - break; - - // User clicked the left arrow. - - case SB_LINEUP: - xInc = -1; - break; - - // User clicked the right arrow. - - case SB_LINEDOWN: - xInc = 1; - break; - - // User dragged the scroll box. - - case SB_THUMBTRACK: - xInc = HIWORD(wParam) - data->xPos; - break; - - default: - xInc = 0; - + static int run_once = 0; + HWND ret; + DWORD style; + RECT rt; + + if (!run_once) { + register_message_window_class(); + run_once = 1; } - - // If applying the horizontal scrolling increment does not - // take the scrolling position out of the scrolling range, - // increment the scrolling position, adjust the position - // of the scroll box, and update the window. + /* get window position */ + if (GetNHApp()->bAutoLayout) { + SetRect(&rt, 0, 0, 0, 0); + } else { + mswin_get_window_placement(NHW_MESSAGE, &rt); + } - if (xInc = max (-data->xPos, min (xInc, data->xMax - data->xPos))) - { - data->xPos += xInc; - ScrollWindowEx (hWnd, -data->xChar * xInc, 0, - (CONST RECT *) NULL, (CONST RECT *) NULL, - (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); +#ifdef MSG_WRAP_TEXT + style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_SIZEBOX; +#else + style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL | WS_SIZEBOX; +#endif - ZeroMemory(&si, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - si.nPos = data->xPos; - SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); - UpdateWindow (hWnd); - } + ret = CreateWindowEx( + WS_EX_CLIENTEDGE, szMessageWindowClass, /* registered class name */ + NULL, /* window name */ + style, /* window style */ + rt.left, /* horizontal position of window */ + rt.top, /* vertical position of window */ + rt.right - rt.left, /* window width */ + rt.bottom - rt.top, /* window height */ + GetNHApp()->hMainWnd, /* handle to parent or owner window */ + NULL, /* menu handle or child identifier */ + GetNHApp()->hApp, /* handle to application instance */ + NULL); /* window-creation data */ + + if (!ret) + panic("Cannot create message window"); + + /* Set window caption */ + SetWindowText(ret, "Messages"); + + return ret; +} + +void +register_message_window_class() +{ + WNDCLASS wcex; + ZeroMemory(&wcex, sizeof(wcex)); + + wcex.style = CS_NOCLOSE; + wcex.lpfnWndProc = (WNDPROC) NHMessageWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = message_bg_brush + ? message_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_MSG); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szMessageWindowClass; + + RegisterClass(&wcex); +} + +LRESULT CALLBACK +NHMessageWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_CREATE: + onCreate(hWnd, wParam, lParam); + break; + + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; + + case WM_PAINT: + onPaint(hWnd); + break; + + case WM_SETFOCUS: + SetFocus(GetNHApp()->hMainWnd); + break; + +#ifndef MSG_WRAP_TEXT + case WM_HSCROLL: + onMSNH_HScroll(hWnd, wParam, lParam); + break; +#endif + + case WM_VSCROLL: + onMSNH_VScroll(hWnd, wParam, lParam); + break; + + case WM_DESTROY: { + PNHMessageWindow data; + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + } break; + + case WM_SIZE: { + SCROLLINFO si; + int xNewSize; + int yNewSize; + PNHMessageWindow data; + RECT rt; + + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + + xNewSize = LOWORD(lParam); + yNewSize = HIWORD(lParam); + + if (xNewSize > 0 || yNewSize > 0) { +#ifndef MSG_WRAP_TEXT + data->xPage = xNewSize / data->xChar; + data->xMax = max(0, (int) (1 + data->max_text - data->xPage)); + data->xPos = min(data->xPos, data->xMax); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = data->max_text; + si.nPage = data->xPage; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); +#endif + + data->yMax = MSG_LINES - 1; + data->yPos = min(data->yPos, data->yMax); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = MSG_VISIBLE_LINES; + si.nMax = data->yMax + MSG_VISIBLE_LINES - 1; + si.nPage = MSG_VISIBLE_LINES; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + } + + /* update NetHack internal window position */ + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_MESSAGE, &rt); + + /* redraw window - it does not handle incremental resizing too well */ + InvalidateRect(hWnd, NULL, TRUE); + } break; + + case WM_MOVE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_MESSAGE, &rt); + } break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + SCROLLINFO si; + char *p; + + if (msg_data->append == 1) { + /* Forcibly append to line, even if we pass the edge */ + strncat(data->window_text[MSG_LINES - 1].text, msg_data->text, + MAXWINDOWTEXT + - strlen(data->window_text[MSG_LINES - 1].text)); + } else if (msg_data->append < 0) { + /* remove that many chars */ + int len = strlen(data->window_text[MSG_LINES - 1].text); + int newend = max(len + msg_data->append, 0); + data->window_text[MSG_LINES - 1].text[newend] = '\0'; + } else { + if (can_append_text(hWnd, msg_data->attr, msg_data->text)) { + strncat(data->window_text[MSG_LINES - 1].text, " ", + MAXWINDOWTEXT + - strlen(data->window_text[MSG_LINES - 1].text)); + strncat(data->window_text[MSG_LINES - 1].text, msg_data->text, + MAXWINDOWTEXT + - strlen(data->window_text[MSG_LINES - 1].text)); + } else { + /* check for "--more--" */ + if (!data->nevermore && more_prompt_check(hWnd)) { + int okkey = 0; + int chop; + // @@@ Ok respnses + + /* append more prompt and inticate the update */ + strncat( + data->window_text[MSG_LINES - 1].text, MORE, + MAXWINDOWTEXT + - strlen(data->window_text[MSG_LINES - 1].text)); + InvalidateRect(hWnd, NULL, TRUE); + + /* get the input */ + while (!okkey) { + int c = mswin_nhgetch(); + + switch (c) { + /* space or enter */ + case ' ': + case '\015': + okkey = 1; + break; + /* ESC */ + case '\033': + data->nevermore = 1; + okkey = 1; + break; + default: + break; + } + } + + /* erase the "--more--" prompt */ + chop = strlen(data->window_text[MSG_LINES - 1].text) + - strlen(MORE); + data->window_text[MSG_LINES - 1].text[chop] = '\0'; + data->lines_not_seen = 0; + } + + /* check if the string is empty */ + for (p = data->window_text[MSG_LINES - 1].text; + *p && isspace(*p); p++) + ; + + if (*p) { + /* last string is not empty - scroll up */ + memmove(&data->window_text[0], &data->window_text[1], + (MSG_LINES - 1) * sizeof(data->window_text[0])); + } + + /* append new text to the end of the array */ + data->window_text[MSG_LINES - 1].attr = msg_data->attr; + strncpy(data->window_text[MSG_LINES - 1].text, msg_data->text, + MAXWINDOWTEXT); + + data->lines_not_seen++; + data->lines_last_turn++; + } + } + + /* reset V-scroll position to display new text */ + data->yPos = data->yMax; + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + + /* update window content */ + InvalidateRect(hWnd, NULL, TRUE); + +#ifdef USER_SOUNDS + if (!GetNHApp()->bNoSounds) + play_sound_for_message(msg_data->text); +#endif + } break; + + case MSNH_MSG_CLEAR_WINDOW: { + data->lines_last_turn = 0; + data->lines_not_seen = 0; + data->nevermore = 0; + break; + } + case MSNH_MSG_CARET: + /* Create or destroy a caret */ + if (*(int *) lParam) + CreateCaret(hWnd, NULL, 0, data->yChar); + else { + DestroyCaret(); + /* this means we just did something interactive in this window, so + we + don't need a --More-- for the lines above. + */ + data->lines_not_seen = 0; + } + break; + + case MSNH_MSG_GETTEXT: { + PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam; + int i; + size_t buflen; + + buflen = 0; + for (i = 0; i < MSG_LINES; i++) + if (*data->window_text[i].text) { + strncpy(&msg_data->buffer[buflen], data->window_text[i].text, + msg_data->max_size - buflen); + buflen += strlen(data->window_text[i].text); + if (buflen >= msg_data->max_size) + break; + + strncpy(&msg_data->buffer[buflen], "\r\n", + msg_data->max_size - buflen); + buflen += 2; + if (buflen > msg_data->max_size) + break; + } + } break; + + } /* switch( wParam ) */ +} + +void +onMSNH_VScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + SCROLLINFO si; + int yInc; + + UNREFERENCED_PARAMETER(lParam); + + /* get window data */ + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE | SIF_POS; + GetScrollInfo(hWnd, SB_VERT, &si); + + switch (LOWORD(wParam)) { + // User clicked the shaft above the scroll box. + + case SB_PAGEUP: + yInc = -(int) si.nPage; + break; + + // User clicked the shaft below the scroll box. + + case SB_PAGEDOWN: + yInc = si.nPage; + break; + + // User clicked the top arrow. + + case SB_LINEUP: + yInc = -1; + break; + + // User clicked the bottom arrow. + + case SB_LINEDOWN: + yInc = 1; + break; + + // User dragged the scroll box. + + case SB_THUMBTRACK: + yInc = HIWORD(wParam) - data->yPos; + break; + + default: + yInc = 0; + } + + // If applying the vertical scrolling increment does not + // take the scrolling position out of the scrolling range, + // increment the scrolling position, adjust the position + // of the scroll box, and update the window. UpdateWindow + // sends the WM_PAINT message. + + if (yInc = max(MSG_VISIBLE_LINES - data->yPos, + min(yInc, data->yMax - data->yPos))) { + data->yPos += yInc; + /* ScrollWindowEx(hWnd, 0, -data->yChar * yInc, + (CONST RECT *) NULL, (CONST RECT *) NULL, + (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE | SW_ERASE); + */ + InvalidateRect(hWnd, NULL, TRUE); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->yPos; + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); + + UpdateWindow(hWnd); + } +} + +#ifndef MSG_WRAP_TEXT +void +onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + PNHMessageWindow data; + SCROLLINFO si; + int xInc; + + /* get window data */ + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE; + GetScrollInfo(hWnd, SB_HORZ, &si); + + switch (LOWORD(wParam)) { + // User clicked shaft left of the scroll box. + + case SB_PAGEUP: + xInc = -(int) si.nPage; + break; + + // User clicked shaft right of the scroll box. + + case SB_PAGEDOWN: + xInc = si.nPage; + break; + + // User clicked the left arrow. + + case SB_LINEUP: + xInc = -1; + break; + + // User clicked the right arrow. + + case SB_LINEDOWN: + xInc = 1; + break; + + // User dragged the scroll box. + + case SB_THUMBTRACK: + xInc = HIWORD(wParam) - data->xPos; + break; + + default: + xInc = 0; + } + + // If applying the horizontal scrolling increment does not + // take the scrolling position out of the scrolling range, + // increment the scrolling position, adjust the position + // of the scroll box, and update the window. + + if (xInc = max(-data->xPos, min(xInc, data->xMax - data->xPos))) { + data->xPos += xInc; + ScrollWindowEx(hWnd, -data->xChar * xInc, 0, (CONST RECT *) NULL, + (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, + SW_INVALIDATE | SW_ERASE); + + ZeroMemory(&si, sizeof(si)); + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + si.nPos = data->xPos; + SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); + UpdateWindow(hWnd); + } } #endif // MSG_WRAP_TEXT -COLORREF setMsgTextColor(HDC hdc, int gray) +COLORREF +setMsgTextColor(HDC hdc, int gray) { COLORREF fg, color1, color2; if (gray) { - if (message_bg_brush) { - color1 = message_bg_color; - color2 = message_fg_color; - } else { - color1 = (COLORREF)GetSysColor(DEFAULT_COLOR_BG_MSG); - color2 = (COLORREF)GetSysColor(DEFAULT_COLOR_FG_MSG); - } - /* Make a "gray" color by taking the average of the individual R,G,B - components of two colors. Thanks to Jonathan del Strother */ - fg = RGB((GetRValue(color1)+GetRValue(color2))/2, - (GetGValue(color1)+GetGValue(color2))/2, - (GetBValue(color1)+GetBValue(color2))/2); + if (message_bg_brush) { + color1 = message_bg_color; + color2 = message_fg_color; + } else { + color1 = (COLORREF) GetSysColor(DEFAULT_COLOR_BG_MSG); + color2 = (COLORREF) GetSysColor(DEFAULT_COLOR_FG_MSG); + } + /* Make a "gray" color by taking the average of the individual R,G,B + components of two colors. Thanks to Jonathan del Strother */ + fg = RGB((GetRValue(color1) + GetRValue(color2)) / 2, + (GetGValue(color1) + GetGValue(color2)) / 2, + (GetBValue(color1) + GetBValue(color2)) / 2); } else { - fg = message_fg_brush ? message_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_MSG); + fg = message_fg_brush ? message_fg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_FG_MSG); } - return SetTextColor(hdc, fg); } - -void onPaint(HWND hWnd) +void +onPaint(HWND hWnd) { - PAINTSTRUCT ps; - HDC hdc; - PNHMessageWindow data; - RECT client_rt, draw_rt; - int FirstLine, LastLine; - int i, x, y; - HGDIOBJ oldFont; - TCHAR wbuf[MAXWINDOWTEXT+2]; - size_t wlen; - COLORREF OldBg, OldFg; + PAINTSTRUCT ps; + HDC hdc; + PNHMessageWindow data; + RECT client_rt, draw_rt; + int FirstLine, LastLine; + int i, x, y; + HGDIOBJ oldFont; + TCHAR wbuf[MAXWINDOWTEXT + 2]; + size_t wlen; + COLORREF OldBg, OldFg; - hdc = BeginPaint(hWnd, &ps); + hdc = BeginPaint(hWnd, &ps); - OldBg = SetBkColor(hdc, message_bg_brush ? message_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_MSG)); + OldBg = SetBkColor( + hdc, message_bg_brush ? message_bg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_BG_MSG)); OldFg = setMsgTextColor(hdc, 0); - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - GetClientRect(hWnd, &client_rt); + GetClientRect(hWnd, &client_rt); - if( !IsRectEmpty(&ps.rcPaint) ) { - FirstLine = max (0, data->yPos - (client_rt.bottom - ps.rcPaint.top)/data->yChar + 1); - LastLine = min (MSG_LINES-1, data->yPos - (client_rt.bottom - ps.rcPaint.bottom)/data->yChar); - y = min( ps.rcPaint.bottom, client_rt.bottom ); - for (i=LastLine; i>=FirstLine; i--) { - x = data->xChar * (2 - data->xPos); + if (!IsRectEmpty(&ps.rcPaint)) { + FirstLine = max( + 0, data->yPos - (client_rt.bottom - ps.rcPaint.top) / data->yChar + + 1); + LastLine = + min(MSG_LINES - 1, + data->yPos + - (client_rt.bottom - ps.rcPaint.bottom) / data->yChar); + y = min(ps.rcPaint.bottom, client_rt.bottom); + for (i = LastLine; i >= FirstLine; i--) { + x = data->xChar * (2 - data->xPos); - draw_rt.left = x; - draw_rt.right = client_rt.right; - draw_rt.top = y - data->yChar; - draw_rt.bottom = y; + draw_rt.left = x; + draw_rt.right = client_rt.right; + draw_rt.top = y - data->yChar; + draw_rt.bottom = y; - oldFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, data->window_text[i].attr, hdc, FALSE)); + oldFont = SelectObject( + hdc, mswin_get_font(NHW_MESSAGE, data->window_text[i].attr, + hdc, FALSE)); - /* convert to UNICODE */ - NH_A2W(data->window_text[i].text, wbuf, sizeof(wbuf)); - wlen = _tcslen(wbuf); - setMsgTextColor(hdc, i < (MSG_LINES - data->lines_last_turn)); -#ifdef MSG_WRAP_TEXT - /* Find out how large the bounding rectangle of the text is */ - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); - /* move that rectangle up, so that the bottom remains at the same height */ - draw_rt.top = y - (draw_rt.bottom - draw_rt.top); - draw_rt.bottom = y; + /* convert to UNICODE */ + NH_A2W(data->window_text[i].text, wbuf, sizeof(wbuf)); + wlen = _tcslen(wbuf); + setMsgTextColor(hdc, i < (MSG_LINES - data->lines_last_turn)); +#ifdef MSG_WRAP_TEXT + /* Find out how large the bounding rectangle of the text is */ + DrawText(hdc, wbuf, wlen, &draw_rt, + DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); + /* move that rectangle up, so that the bottom remains at the same + * height */ + draw_rt.top = y - (draw_rt.bottom - draw_rt.top); + draw_rt.bottom = y; - /* Now really draw it */ - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK); - - /* Find out the cursor (caret) position */ - if (i == MSG_LINES-1) { - int nnum, numfit; - SIZE size; - TCHAR *nbuf; - int nlen; + /* Now really draw it */ + DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK); - nbuf = wbuf; - nlen = wlen; - while (nlen) { - /* Get the number of characters that fit on the line */ - GetTextExtentExPoint(hdc, nbuf, nlen, draw_rt.right - draw_rt.left, &numfit, NULL, &size); - /* Search back to a space */ - nnum = numfit; - if (numfit < nlen) { - while (nnum > 0 && nbuf[nnum] != ' ') - nnum--; - /* If no space found, break wherever */ - if (nnum == 0) - nnum = numfit; - } - nbuf += nnum; - nlen -= nnum; - if (*nbuf == ' ') { - nbuf++; - nlen--; - } + /* Find out the cursor (caret) position */ + if (i == MSG_LINES - 1) { + int nnum, numfit; + SIZE size; + TCHAR *nbuf; + int nlen; + + nbuf = wbuf; + nlen = wlen; + while (nlen) { + /* Get the number of characters that fit on the line */ + GetTextExtentExPoint(hdc, nbuf, nlen, + draw_rt.right - draw_rt.left, + &numfit, NULL, &size); + /* Search back to a space */ + nnum = numfit; + if (numfit < nlen) { + while (nnum > 0 && nbuf[nnum] != ' ') + nnum--; + /* If no space found, break wherever */ + if (nnum == 0) + nnum = numfit; + } + nbuf += nnum; + nlen -= nnum; + if (*nbuf == ' ') { + nbuf++; + nlen--; } - /* The last size is the size of the last line. Set the caret there. - This will fail automatically if we don't own the caret (i.e., - when not in a question.) - */ - SetCaretPos(draw_rt.left + size.cx, draw_rt.bottom - data->yChar); } + /* The last size is the size of the last line. Set the caret + there. + This will fail automatically if we don't own the caret + (i.e., + when not in a question.) + */ + SetCaretPos(draw_rt.left + size.cx, + draw_rt.bottom - data->yChar); + } #else - DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX ); - SetCaretPos(draw_rt.left + size.cx, draw_rt.bottom - data->yChar); + DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX); + SetCaretPos(draw_rt.left + size.cx, draw_rt.bottom - data->yChar); #endif - SelectObject(hdc, oldFont); - y -= draw_rt.bottom - draw_rt.top; - } - } - SetTextColor (hdc, OldFg); - SetBkColor (hdc, OldBg); - EndPaint(hWnd, &ps); + SelectObject(hdc, oldFont); + y -= draw_rt.bottom - draw_rt.top; + } + } + SetTextColor(hdc, OldFg); + SetBkColor(hdc, OldBg); + EndPaint(hWnd, &ps); } -void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHMessageWindow data; - SIZE dummy; + PNHMessageWindow data; + SIZE dummy; - UNREFERENCED_PARAMETER(wParam); - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(wParam); + UNREFERENCED_PARAMETER(lParam); - /* set window data */ - data = (PNHMessageWindow)malloc(sizeof(NHMessageWindow)); - if( !data ) panic("out of memory"); - ZeroMemory(data, sizeof(NHMessageWindow)); - data->max_text = MAXWINDOWTEXT; - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); + /* set window data */ + data = (PNHMessageWindow) malloc(sizeof(NHMessageWindow)); + if (!data) + panic("out of memory"); + ZeroMemory(data, sizeof(NHMessageWindow)); + data->max_text = MAXWINDOWTEXT; + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data); - /* re-calculate window size (+ font size) */ - mswin_message_window_size(hWnd, &dummy); + /* re-calculate window size (+ font size) */ + mswin_message_window_size(hWnd, &dummy); } -void mswin_message_window_size (HWND hWnd, LPSIZE sz) +void +mswin_message_window_size(HWND hWnd, LPSIZE sz) { - HDC hdc; - HGDIOBJ saveFont; - TEXTMETRIC tm; - PNHMessageWindow data; - RECT rt, client_rt; + HDC hdc; + HGDIOBJ saveFont; + TEXTMETRIC tm; + PNHMessageWindow data; + RECT rt, client_rt; - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if( !data ) return; + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (!data) + return; - /* -- Calculate the font size -- */ + /* -- Calculate the font size -- */ /* Get the handle to the client area's device context. */ - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); + hdc = GetDC(hWnd); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); /* Extract font dimensions from the text metrics. */ - GetTextMetrics (hdc, &tm); - data->xChar = tm.tmAveCharWidth; - data->xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * data->xChar/2; - data->yChar = tm.tmHeight + tm.tmExternalLeading; - data->xPage = 1; + GetTextMetrics(hdc, &tm); + data->xChar = tm.tmAveCharWidth; + data->xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * data->xChar / 2; + data->yChar = tm.tmHeight + tm.tmExternalLeading; + data->xPage = 1; /* Free the device context. */ - SelectObject(hdc, saveFont); - ReleaseDC (hWnd, hdc); - - /* -- calculate window size -- */ - GetWindowRect(hWnd, &rt); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); - /* set size to accomodate MSG_VISIBLE_LINES and - horizontal scroll bar (difference between window rect and client rect */ - GetClientRect(hWnd, &client_rt); - sz->cy = sz->cy - (client_rt.bottom - client_rt.top) + - data->yChar * MSG_VISIBLE_LINES; + /* -- calculate window size -- */ + GetWindowRect(hWnd, &rt); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; + + /* set size to accomodate MSG_VISIBLE_LINES and + horizontal scroll bar (difference between window rect and client rect + */ + GetClientRect(hWnd, &client_rt); + sz->cy = sz->cy - (client_rt.bottom - client_rt.top) + + data->yChar * MSG_VISIBLE_LINES; } /* check if text can be appended to the last line without wrapping */ -BOOL can_append_text(HWND hWnd, int attr, const char* text ) +BOOL +can_append_text(HWND hWnd, int attr, const char *text) { - PNHMessageWindow data; - char tmptext[MAXWINDOWTEXT+1]; - HDC hdc; - HGDIOBJ saveFont; - RECT draw_rt; - BOOL retval = FALSE; + PNHMessageWindow data; + char tmptext[MAXWINDOWTEXT + 1]; + HDC hdc; + HGDIOBJ saveFont; + RECT draw_rt; + BOOL retval = FALSE; - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - /* cannot append if lines_not_seen is 0 (beginning of the new turn */ - if( data->lines_not_seen==0 ) return FALSE; + /* cannot append if lines_not_seen is 0 (beginning of the new turn */ + if (data->lines_not_seen == 0) + return FALSE; - /* cannot append text with different attrbutes */ - if( data->window_text[MSG_LINES-1].attr != attr ) return FALSE; + /* cannot append text with different attrbutes */ + if (data->window_text[MSG_LINES - 1].attr != attr) + return FALSE; - /* check if the maximum string langth will be exceeded */ - if( strlen(data->window_text[MSG_LINES-1].text)+ - 2 + /* space characters */ - strlen(text) + - strlen(MORE) >= MAXWINDOWTEXT ) return FALSE; + /* check if the maximum string langth will be exceeded */ + if (strlen(data->window_text[MSG_LINES - 1].text) + 2 + + /* space characters */ + strlen(text) + strlen(MORE) + >= MAXWINDOWTEXT) + return FALSE; - /* check if the text is goinf to fin into a single line */ - strcpy(tmptext, data->window_text[MSG_LINES-1].text ); - strcat(tmptext, " " ); - strcat(tmptext, text ); - strcat(tmptext, MORE ); + /* check if the text is goinf to fin into a single line */ + strcpy(tmptext, data->window_text[MSG_LINES - 1].text); + strcat(tmptext, " "); + strcat(tmptext, text); + strcat(tmptext, MORE); - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, data->window_text[MSG_LINES-1].attr, hdc, FALSE)); - GetClientRect(hWnd, &draw_rt); - draw_rt.bottom = draw_rt.top; /* we only need width for the DrawText */ - DrawText(hdc, tmptext, strlen(tmptext), &draw_rt, DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); + hdc = GetDC(hWnd); + saveFont = SelectObject( + hdc, + mswin_get_font(NHW_MESSAGE, data->window_text[MSG_LINES - 1].attr, + hdc, FALSE)); + GetClientRect(hWnd, &draw_rt); + draw_rt.bottom = draw_rt.top; /* we only need width for the DrawText */ + DrawText(hdc, tmptext, strlen(tmptext), &draw_rt, + DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); - /* we will check against 1.5 of the font size in order to determine - if the text is single-line or not - just to be on the safe size */ - retval = (draw_rt.bottom-draw_rt.top)<(data->yChar+data->yChar/2); - - /* free device context */ - SelectObject(hdc, saveFont); - ReleaseDC (hWnd, hdc); - return retval; + /* we will check against 1.5 of the font size in order to determine + if the text is single-line or not - just to be on the safe size */ + retval = (draw_rt.bottom - draw_rt.top) < (data->yChar + data->yChar / 2); + + /* free device context */ + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); + return retval; } -/* check if "--more--" promt needs to be displayed - basically, check if the lines not seen are going to find in the message window +/* check if "--more--" promt needs to be displayed + basically, check if the lines not seen are going to find in the message + window */ -BOOL more_prompt_check(HWND hWnd) +BOOL +more_prompt_check(HWND hWnd) { - PNHMessageWindow data; - HDC hdc; - HGDIOBJ saveFont; - RECT client_rt, draw_rt; - int i; - int remaining_height; - char tmptext[MAXWINDOWTEXT+1]; + PNHMessageWindow data; + HDC hdc; + HGDIOBJ saveFont; + RECT client_rt, draw_rt; + int i; + int remaining_height; + char tmptext[MAXWINDOWTEXT + 1]; - data = (PNHMessageWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - if( data->lines_not_seen==0 ) return FALSE; /* don't bother checking - nothig to "more" */ - if( data->lines_not_seen>=MSG_LINES ) return TRUE; /* history size exceeded - always more */ + if (data->lines_not_seen == 0) + return FALSE; /* don't bother checking - nothig to "more" */ + if (data->lines_not_seen >= MSG_LINES) + return TRUE; /* history size exceeded - always more */ - GetClientRect(hWnd, &client_rt); - remaining_height = client_rt.bottom - client_rt.top; + GetClientRect(hWnd, &client_rt); + remaining_height = client_rt.bottom - client_rt.top; - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); - for( i=0; ilines_not_seen; i++ ) { - /* we only need width for the DrawText */ - SetRect(&draw_rt, client_rt.left, client_rt.top, client_rt.right, client_rt.top); - SelectObject(hdc, mswin_get_font(NHW_MESSAGE, data->window_text[MSG_LINES-i-1].attr, hdc, FALSE)); + hdc = GetDC(hWnd); + saveFont = + SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); + for (i = 0; i < data->lines_not_seen; i++) { + /* we only need width for the DrawText */ + SetRect(&draw_rt, client_rt.left, client_rt.top, client_rt.right, + client_rt.top); + SelectObject(hdc, + mswin_get_font(NHW_MESSAGE, + data->window_text[MSG_LINES - i - 1].attr, + hdc, FALSE)); - strcpy(tmptext, data->window_text[MSG_LINES-i-1].text ); - if( i==0 ) strcat(tmptext, MORE ); + strcpy(tmptext, data->window_text[MSG_LINES - i - 1].text); + if (i == 0) + strcat(tmptext, MORE); - remaining_height -= - DrawText( hdc, - tmptext, - strlen(tmptext), - &draw_rt, - DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT - ); - if( remaining_height<=0 ) break; - } - - /* free device context */ - SelectObject(hdc, saveFont); - ReleaseDC (hWnd, hdc); - return (remaining_height<=0); /* TRUE if lines_not_seen take more that window height */ + remaining_height -= + DrawText(hdc, tmptext, strlen(tmptext), &draw_rt, + DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); + if (remaining_height <= 0) + break; + } + + /* free device context */ + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); + return (remaining_height + <= 0); /* TRUE if lines_not_seen take more that window height */ } - diff --git a/win/win32/mhrip.c b/win/win32/mhrip.c index e4b1778d2..4ccbf606d 100644 --- a/win/win32/mhrip.c +++ b/win/win32/mhrip.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhrip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhrip.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */ /* NetHack 3.6 mhrip.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.13 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -9,260 +9,267 @@ #include "mhmsg.h" #include "mhfont.h" -#define RIP_WIDTH 400 -#define RIP_HEIGHT 200 +#define RIP_WIDTH 400 +#define RIP_HEIGHT 200 -#define RIP_GRAVE_HEIGHT 120 -#define RIP_GRAVE_WIDTH 115 -#define RIP_GRAVE_X 90 -#define RIP_GRAVE_Y 60 +#define RIP_GRAVE_HEIGHT 120 +#define RIP_GRAVE_WIDTH 115 +#define RIP_GRAVE_X 90 +#define RIP_GRAVE_Y 60 -#define RIP_OFFSET_X 10 -#define RIP_OFFSET_Y 10 +#define RIP_OFFSET_X 10 +#define RIP_OFFSET_Y 10 PNHWinApp GetNHApp(void); typedef struct mswin_nethack_text_window { - HANDLE rip_bmp; - TCHAR* window_text; - TCHAR* rip_text; + HANDLE rip_bmp; + TCHAR *window_text; + TCHAR *rip_text; } NHRIPWindow, *PNHRIPWindow; INT_PTR CALLBACK NHRIPWndProc(HWND, UINT, WPARAM, LPARAM); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); -HWND mswin_init_RIP_window () { - HWND ret; - PNHRIPWindow data; - - ret = CreateDialog( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_NHRIP), - GetNHApp()->hMainWnd, - NHRIPWndProc - ); - if( !ret ) panic("Cannot create rip window"); - - data = (PNHRIPWindow)malloc(sizeof(NHRIPWindow)); - if( !data ) panic("out of memory"); - - ZeroMemory(data, sizeof(NHRIPWindow)); - SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data); - return ret; -} - -void mswin_display_RIP_window (HWND hWnd) +HWND +mswin_init_RIP_window() { - MSG msg; - RECT rt; - PNHRIPWindow data; - HWND mapWnd; - RECT riprt; - RECT clientrect; - RECT textrect; - HDC hdc; - HFONT OldFont; + HWND ret; + PNHRIPWindow data; - data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHRIP), + GetNHApp()->hMainWnd, NHRIPWndProc); + if (!ret) + panic("Cannot create rip window"); - GetNHApp()->hPopupWnd = hWnd; - mapWnd = mswin_hwnd_from_winid(WIN_MAP); - if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd; - GetWindowRect(mapWnd, &rt); - GetWindowRect(hWnd, &riprt); - GetClientRect (hWnd, &clientrect); - textrect = clientrect; - textrect.top += RIP_OFFSET_Y; - textrect.left += RIP_OFFSET_X; - textrect.right -= RIP_OFFSET_X; - if (data->window_text) - { - hdc = GetDC (hWnd); - OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)); - DrawText (hdc, data->window_text, strlen(data->window_text), &textrect, - DT_LEFT | DT_NOPREFIX | DT_CALCRECT); - SelectObject (hdc, OldFont); - ReleaseDC(hWnd, hdc); - } - if (textrect.right - textrect.left > RIP_WIDTH) - clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right; - else - clientrect.right = textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right; - clientrect.bottom = textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom; - GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect); - textrect.right -= textrect.left; - textrect.bottom -= textrect.top; - clientrect.bottom += textrect.bottom + RIP_OFFSET_Y; - riprt.right -= riprt.left; - riprt.bottom -= riprt.top; - riprt.right += clientrect.right; - riprt.bottom += clientrect.bottom; - rt.left += (rt.right - rt.left - riprt.right) / 2; - rt.top += (rt.bottom - rt.top - riprt.bottom) / 2; + data = (PNHRIPWindow) malloc(sizeof(NHRIPWindow)); + if (!data) + panic("out of memory"); - MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE); - GetClientRect (hWnd, &clientrect); - MoveWindow (GetDlgItem(hWnd, IDOK), - (clientrect.right - clientrect.left - textrect.right) / 2, - clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, textrect.right, textrect.bottom, TRUE); - ShowWindow(hWnd, SW_SHOW); - - while( IsWindow(hWnd) && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if( !IsDialogMessage(hWnd, &msg) ) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - GetNHApp()->hPopupWnd = NULL; + ZeroMemory(data, sizeof(NHRIPWindow)); + SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data); + return ret; } -INT_PTR CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +void +mswin_display_RIP_window(HWND hWnd) { - HDC hdc; - PNHRIPWindow data; + MSG msg; + RECT rt; + PNHRIPWindow data; + HWND mapWnd; + RECT riprt; + RECT clientrect; + RECT textrect; + HDC hdc; + HFONT OldFont; - data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (message) - { - case WM_INITDIALOG: - /* set text control font */ - hdc = GetDC(hWnd); - SendMessage(hWnd, WM_SETFONT, - (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); - ReleaseDC(hWnd, hdc); + data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - SetFocus(GetDlgItem(hWnd, IDOK)); - return FALSE; + GetNHApp()->hPopupWnd = hWnd; + mapWnd = mswin_hwnd_from_winid(WIN_MAP); + if (!IsWindow(mapWnd)) + mapWnd = GetNHApp()->hMainWnd; + GetWindowRect(mapWnd, &rt); + GetWindowRect(hWnd, &riprt); + GetClientRect(hWnd, &clientrect); + textrect = clientrect; + textrect.top += RIP_OFFSET_Y; + textrect.left += RIP_OFFSET_X; + textrect.right -= RIP_OFFSET_X; + if (data->window_text) { + hdc = GetDC(hWnd); + OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)); + DrawText(hdc, data->window_text, strlen(data->window_text), &textrect, + DT_LEFT | DT_NOPREFIX | DT_CALCRECT); + SelectObject(hdc, OldFont); + ReleaseDC(hWnd, hdc); + } + if (textrect.right - textrect.left > RIP_WIDTH) + clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right; + else + clientrect.right = + textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right; + clientrect.bottom = + textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom; + GetWindowRect(GetDlgItem(hWnd, IDOK), &textrect); + textrect.right -= textrect.left; + textrect.bottom -= textrect.top; + clientrect.bottom += textrect.bottom + RIP_OFFSET_Y; + riprt.right -= riprt.left; + riprt.bottom -= riprt.top; + riprt.right += clientrect.right; + riprt.bottom += clientrect.bottom; + rt.left += (rt.right - rt.left - riprt.right) / 2; + rt.top += (rt.bottom - rt.top - riprt.bottom) / 2; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE); + GetClientRect(hWnd, &clientrect); + MoveWindow(GetDlgItem(hWnd, IDOK), + (clientrect.right - clientrect.left - textrect.right) / 2, + clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, + textrect.right, textrect.bottom, TRUE); + ShowWindow(hWnd, SW_SHOW); - case WM_PAINT: - { - int bitmap_offset; - RECT clientrect; - RECT textrect; - HDC hdcBitmap; - HANDLE OldBitmap; - PAINTSTRUCT ps; - HFONT OldFont; + while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) { + if (!IsDialogMessage(hWnd, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } - hdc = BeginPaint (hWnd, &ps); - OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)); - hdcBitmap = CreateCompatibleDC(hdc); - SetBkMode (hdc, TRANSPARENT); - GetClientRect (hWnd, &clientrect); - textrect = clientrect; - textrect.top += RIP_OFFSET_Y; - textrect.left += RIP_OFFSET_X; - textrect.right -= RIP_OFFSET_X; - if (data->window_text) - { - DrawText (hdc, data->window_text, strlen(data->window_text), &textrect, - DT_LEFT | DT_NOPREFIX | DT_CALCRECT); - DrawText (hdc, data->window_text, strlen(data->window_text), &textrect, - DT_LEFT | DT_NOPREFIX); - } - OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip); - SetBkMode (hdc, OPAQUE); - bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2; - BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH, - RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY); - SetBkMode (hdc, TRANSPARENT); - if (data->rip_text) - { - textrect.left += RIP_GRAVE_X + bitmap_offset; - textrect.top = textrect.bottom + RIP_GRAVE_Y; - textrect.right = textrect.left + RIP_GRAVE_WIDTH; - textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT; - DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect, - DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK); - } - SelectObject (hdcBitmap, OldBitmap); - SelectObject (hdc, OldFont); - DeleteDC (hdcBitmap); - EndPaint (hWnd, &ps); - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); - if( GetNHApp()->hMainWnd==hWnd ) - GetNHApp()->hMainWnd=NULL; - DestroyWindow(hWnd); - SetFocus(GetNHApp()->hMainWnd); - return TRUE; - } - break; - - case WM_CLOSE: - /* if we get this here, we saved the bones so we can just force a quit */ - - mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); - if( GetNHApp()->hMainWnd==hWnd ) - GetNHApp()->hMainWnd=NULL; - DestroyWindow(hWnd); - SetFocus(GetNHApp()->hMainWnd); - program_state.stopprint++; - return TRUE; - - case WM_DESTROY: - if( data ) { - if( data->window_text ) free(data->window_text); - if( data->rip_text ) free(data->rip_text); - if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp); - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - } - break; - - } - return FALSE; + GetNHApp()->hPopupWnd = NULL; } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK +NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PNHRIPWindow data; - static int InRipText = 1; - data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - TCHAR wbuf[BUFSZ]; - size_t text_size; + HDC hdc; + PNHRIPWindow data; - if( !data->window_text ) { - text_size = strlen(msg_data->text) + 4; - data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0])); - ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0])); - } else { - text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4; - data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0])); - } - if( !data->window_text ) break; + data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (message) { + case WM_INITDIALOG: + /* set text control font */ + hdc = GetDC(hWnd); + SendMessage(hWnd, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), + 0); + ReleaseDC(hWnd, hdc); - _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ)); - _tcscat(data->window_text, TEXT("\r\n")); - break; - } - case MSNH_MSG_DIED: - { - data->rip_text = data->window_text; - data->window_text = NULL; - break; - } + SetFocus(GetDlgItem(hWnd, IDOK)); + return FALSE; - } + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; + + case WM_PAINT: { + int bitmap_offset; + RECT clientrect; + RECT textrect; + HDC hdcBitmap; + HANDLE OldBitmap; + PAINTSTRUCT ps; + HFONT OldFont; + + hdc = BeginPaint(hWnd, &ps); + OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)); + hdcBitmap = CreateCompatibleDC(hdc); + SetBkMode(hdc, TRANSPARENT); + GetClientRect(hWnd, &clientrect); + textrect = clientrect; + textrect.top += RIP_OFFSET_Y; + textrect.left += RIP_OFFSET_X; + textrect.right -= RIP_OFFSET_X; + if (data->window_text) { + DrawText(hdc, data->window_text, strlen(data->window_text), + &textrect, DT_LEFT | DT_NOPREFIX | DT_CALCRECT); + DrawText(hdc, data->window_text, strlen(data->window_text), + &textrect, DT_LEFT | DT_NOPREFIX); + } + OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip); + SetBkMode(hdc, OPAQUE); + bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2; + BitBlt(hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH, + RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY); + SetBkMode(hdc, TRANSPARENT); + if (data->rip_text) { + textrect.left += RIP_GRAVE_X + bitmap_offset; + textrect.top = textrect.bottom + RIP_GRAVE_Y; + textrect.right = textrect.left + RIP_GRAVE_WIDTH; + textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT; + DrawText(hdc, data->rip_text, strlen(data->rip_text), &textrect, + DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK); + } + SelectObject(hdcBitmap, OldBitmap); + SelectObject(hdc, OldFont); + DeleteDC(hdcBitmap); + EndPaint(hWnd, &ps); + } break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); + if (GetNHApp()->hMainWnd == hWnd) + GetNHApp()->hMainWnd = NULL; + DestroyWindow(hWnd); + SetFocus(GetNHApp()->hMainWnd); + return TRUE; + } + break; + + case WM_CLOSE: + /* if we get this here, we saved the bones so we can just force a quit + */ + + mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); + if (GetNHApp()->hMainWnd == hWnd) + GetNHApp()->hMainWnd = NULL; + DestroyWindow(hWnd); + SetFocus(GetNHApp()->hMainWnd); + program_state.stopprint++; + return TRUE; + + case WM_DESTROY: + if (data) { + if (data->window_text) + free(data->window_text); + if (data->rip_text) + free(data->rip_text); + if (data->rip_bmp != NULL) + DeleteObject(data->rip_bmp); + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + } + break; + } + return FALSE; } -void mswin_finish_rip_text(winid wid) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - SendMessage (mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED, 0); + PNHRIPWindow data; + static int InRipText = 1; + data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + TCHAR wbuf[BUFSZ]; + size_t text_size; + + if (!data->window_text) { + text_size = strlen(msg_data->text) + 4; + data->window_text = + (TCHAR *) malloc(text_size * sizeof(data->window_text[0])); + ZeroMemory(data->window_text, + text_size * sizeof(data->window_text[0])); + } else { + text_size = + _tcslen(data->window_text) + strlen(msg_data->text) + 4; + data->window_text = (TCHAR *) realloc( + data->window_text, text_size * sizeof(data->window_text[0])); + } + if (!data->window_text) + break; + + _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ)); + _tcscat(data->window_text, TEXT("\r\n")); + break; + } + case MSNH_MSG_DIED: { + data->rip_text = data->window_text; + data->window_text = NULL; + break; + } + } } +void +mswin_finish_rip_text(winid wid) +{ + SendMessage(mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED, + 0); +} diff --git a/win/win32/mhsplash.c b/win/win32/mhsplash.c index 21b948ab8..893e22ffb 100644 --- a/win/win32/mhsplash.c +++ b/win/win32/mhsplash.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhsplash.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhsplash.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */ /* NetHack 3.6 mhsplash.c $Date: 2012/01/11 01:15:37 $ $Revision: 1.17 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -18,236 +18,230 @@ PNHWinApp GetNHApp(void); INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM); -#define SPLASH_WIDTH 440 -#define SPLASH_HEIGHT 322 -#define SPLASH_VERSION_X 290 -#define SPLASH_VERSION_Y 10 -#define SPLASH_OFFSET_X 10 -#define SPLASH_OFFSET_Y 10 +#define SPLASH_WIDTH 440 +#define SPLASH_HEIGHT 322 +#define SPLASH_VERSION_X 290 +#define SPLASH_VERSION_Y 10 +#define SPLASH_OFFSET_X 10 +#define SPLASH_OFFSET_Y 10 extern HFONT version_splash_font; -void mswin_display_splash_window (BOOL show_ver) +void +mswin_display_splash_window(BOOL show_ver) { - MSG msg; - int left, top; - RECT splashrt; - RECT clientrt; - RECT controlrt; - HWND hWnd; - int buttop; - int strsize = 0; - int bufsize = BUFSZ; - char *buf = malloc(bufsize); - - if (buf == NULL) - panic("out of memory"); - buf[0] = '\0'; - + MSG msg; + int left, top; + RECT splashrt; + RECT clientrt; + RECT controlrt; + HWND hWnd; + int buttop; + int strsize = 0; + int bufsize = BUFSZ; + char *buf = malloc(bufsize); - hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH), - GetNHApp()->hMainWnd, NHSplashWndProc); - if( !hWnd ) panic("Cannot create Splash window"); - mswin_init_splashfonts(hWnd); - GetNHApp()->hPopupWnd = hWnd; - /* Get control size */ - GetWindowRect (GetDlgItem(hWnd, IDOK), &controlrt); - controlrt.right -= controlrt.left; - controlrt.bottom -= controlrt.top; - /* Get current client area */ - GetClientRect (hWnd, &clientrt); - /* Get window size */ - GetWindowRect(hWnd, &splashrt); - splashrt.right -= splashrt.left; - splashrt.bottom -= splashrt.top; - /* Get difference between requested client area and current value */ - splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right; - splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 - clientrt.bottom; - /* Place the window centered */ - /* On the screen, not on the parent window */ - left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2; - top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2; - MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE); - /* Place the OK control */ - GetClientRect (hWnd, &clientrt); - MoveWindow (GetDlgItem(hWnd, IDOK), - (clientrt.right - clientrt.left - controlrt.right) / 2, - clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y, - controlrt.right, controlrt.bottom, TRUE); - buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y; - /* Place the text control */ - GetWindowRect (GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt); - controlrt.right -= controlrt.left; - controlrt.bottom -= controlrt.top; - GetClientRect (hWnd, &clientrt); - MoveWindow (GetDlgItem(hWnd, IDC_EXTRAINFO), - clientrt.left + SPLASH_OFFSET_X, - buttop - controlrt.bottom - SPLASH_OFFSET_Y, - clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE); + if (buf == NULL) + panic("out of memory"); + buf[0] = '\0'; - /* Fill the text control */ - Sprintf (buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, COPYRIGHT_BANNER_B, - COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D); - strsize = strlen(buf); + hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH), + GetNHApp()->hMainWnd, NHSplashWndProc); + if (!hWnd) + panic("Cannot create Splash window"); + mswin_init_splashfonts(hWnd); + GetNHApp()->hPopupWnd = hWnd; + /* Get control size */ + GetWindowRect(GetDlgItem(hWnd, IDOK), &controlrt); + controlrt.right -= controlrt.left; + controlrt.bottom -= controlrt.top; + /* Get current client area */ + GetClientRect(hWnd, &clientrt); + /* Get window size */ + GetWindowRect(hWnd, &splashrt); + splashrt.right -= splashrt.left; + splashrt.bottom -= splashrt.top; + /* Get difference between requested client area and current value */ + splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right; + splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 + - clientrt.bottom; + /* Place the window centered */ + /* On the screen, not on the parent window */ + left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2; + top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2; + MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE); + /* Place the OK control */ + GetClientRect(hWnd, &clientrt); + MoveWindow(GetDlgItem(hWnd, IDOK), + (clientrt.right - clientrt.left - controlrt.right) / 2, + clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y, + controlrt.right, controlrt.bottom, TRUE); + buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y; + /* Place the text control */ + GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt); + controlrt.right -= controlrt.left; + controlrt.bottom -= controlrt.top; + GetClientRect(hWnd, &clientrt); + MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO), + clientrt.left + SPLASH_OFFSET_X, + buttop - controlrt.bottom - SPLASH_OFFSET_Y, + clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE); - if (show_ver) { - /* Show complete version information */ - dlb *f; + /* Fill the text control */ + Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, + COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D); + strsize = strlen(buf); - getversionstring(buf + strsize); - strcat(buf, "\r\n\r\n"); - strsize = strlen(buf); + if (show_ver) { + /* Show complete version information */ + dlb *f; - /* Add compile options */ - f = dlb_fopen(OPTIONS_USED, RDTMODE); - if (f) { - char line[LLEN + 1]; - - while (dlb_fgets(line, LLEN, f)) { - size_t len; - len = strlen(line); - if (len > 0 && line[len - 1] == '\n') { - line[len - 1] = '\r'; - line[len] = '\n'; - line[len + 1] = '\0'; - len++; - } - if (strsize + (int)len + 1 > bufsize) - { - bufsize += BUFSZ; - buf = realloc(buf, bufsize); - if (buf == NULL) - panic("out of memory"); - } - strcat(buf, line); - strsize += len; - } - (void) dlb_fclose(f); - } - } else { - /* Show news, if any */ - if (iflags.news) { - FILE *nf; + getversionstring(buf + strsize); + strcat(buf, "\r\n\r\n"); + strsize = strlen(buf); - iflags.news = 0; /* prevent newgame() from re-displaying news */ - nf = fopen(NEWS, "r"); - if (nf != NULL) { - char line[LLEN + 1]; - - while (fgets(line, LLEN, nf)) { - size_t len; - len = strlen(line); - if (len > 0 && line[len - 1] == '\n') { - line[len - 1] = '\r'; - line[len] = '\n'; - line[len + 1] = '\0'; - len++; - } - if (strsize + (int)len + 1 > bufsize) - { - bufsize += BUFSZ; - buf = realloc(buf, bufsize); - if (buf == NULL) - panic("out of memory"); - } - strcat(buf, line); - strsize += len; - } - (void) fclose(nf); - } - else - { - strcat(buf, "No news."); - } - } - } - SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf); - free(buf); - ShowWindow(hWnd, SW_SHOW); + /* Add compile options */ + f = dlb_fopen(OPTIONS_USED, RDTMODE); + if (f) { + char line[LLEN + 1]; - while( IsWindow(hWnd) && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if( !IsDialogMessage(hWnd, &msg) ) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - GetNHApp()->hPopupWnd = NULL; - mswin_destroy_splashfonts(); + while (dlb_fgets(line, LLEN, f)) { + size_t len; + len = strlen(line); + if (len > 0 && line[len - 1] == '\n') { + line[len - 1] = '\r'; + line[len] = '\n'; + line[len + 1] = '\0'; + len++; + } + if (strsize + (int) len + 1 > bufsize) { + bufsize += BUFSZ; + buf = realloc(buf, bufsize); + if (buf == NULL) + panic("out of memory"); + } + strcat(buf, line); + strsize += len; + } + (void) dlb_fclose(f); + } + } else { + /* Show news, if any */ + if (iflags.news) { + FILE *nf; + + iflags.news = 0; /* prevent newgame() from re-displaying news */ + nf = fopen(NEWS, "r"); + if (nf != NULL) { + char line[LLEN + 1]; + + while (fgets(line, LLEN, nf)) { + size_t len; + len = strlen(line); + if (len > 0 && line[len - 1] == '\n') { + line[len - 1] = '\r'; + line[len] = '\n'; + line[len + 1] = '\0'; + len++; + } + if (strsize + (int) len + 1 > bufsize) { + bufsize += BUFSZ; + buf = realloc(buf, bufsize); + if (buf == NULL) + panic("out of memory"); + } + strcat(buf, line); + strsize += len; + } + (void) fclose(nf); + } else { + strcat(buf, "No news."); + } + } + } + SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf); + free(buf); + ShowWindow(hWnd, SW_SHOW); + + while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) { + if (!IsDialogMessage(hWnd, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + GetNHApp()->hPopupWnd = NULL; + mswin_destroy_splashfonts(); } -INT_PTR CALLBACK NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK +NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hdc; + HDC hdc; - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - /* set text control font */ - hdc = GetDC(hWnd); - SendMessage(hWnd, WM_SETFONT, - (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); - ReleaseDC(hWnd, hdc); + switch (message) { + case WM_INITDIALOG: + /* set text control font */ + hdc = GetDC(hWnd); + SendMessage(hWnd, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), + 0); + ReleaseDC(hWnd, hdc); - SetFocus(GetDlgItem(hWnd, IDOK)); - return FALSE; + SetFocus(GetDlgItem(hWnd, IDOK)); + return FALSE; - case WM_PAINT: - { - char VersionString[BUFSZ]; - RECT rt; - HDC hdcBitmap; - HANDLE OldBitmap; - HANDLE OldFont; - PAINTSTRUCT ps; + case WM_PAINT: { + char VersionString[BUFSZ]; + RECT rt; + HDC hdcBitmap; + HANDLE OldBitmap; + HANDLE OldFont; + PAINTSTRUCT ps; - hdc = BeginPaint (hWnd, &ps); - /* Show splash graphic */ + hdc = BeginPaint(hWnd, &ps); + /* Show splash graphic */ - hdcBitmap = CreateCompatibleDC(hdc); - SetBkMode (hdc, OPAQUE); - OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash); - nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y, - SPLASH_WIDTH, SPLASH_HEIGHT, - hdcBitmap, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT, - TILE_BK_COLOR); + hdcBitmap = CreateCompatibleDC(hdc); + SetBkMode(hdc, OPAQUE); + OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash); + nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y, + SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0, + 0, SPLASH_WIDTH, SPLASH_HEIGHT, + TILE_BK_COLOR); - SelectObject (hdcBitmap, OldBitmap); - DeleteDC (hdcBitmap); + SelectObject(hdcBitmap, OldBitmap); + DeleteDC(hdcBitmap); - SetBkMode (hdc, TRANSPARENT); - /* Print version number */ + SetBkMode(hdc, TRANSPARENT); + /* Print version number */ - SetTextColor (hdc, RGB(0, 0, 0)); - rt.right = rt.left = SPLASH_VERSION_X; - rt.bottom = rt.top = SPLASH_VERSION_Y; - Sprintf (VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, - PATCHLEVEL); - OldFont = SelectObject(hdc, version_splash_font); - DrawText (hdc, VersionString, strlen(VersionString), &rt, - DT_LEFT | DT_NOPREFIX | DT_CALCRECT); - DrawText (hdc, VersionString, strlen(VersionString), &rt, - DT_LEFT | DT_NOPREFIX); - EndPaint (hWnd, &ps); - } - break; + SetTextColor(hdc, RGB(0, 0, 0)); + rt.right = rt.left = SPLASH_VERSION_X; + rt.bottom = rt.top = SPLASH_VERSION_Y; + Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, + PATCHLEVEL); + OldFont = SelectObject(hdc, version_splash_font); + DrawText(hdc, VersionString, strlen(VersionString), &rt, + DT_LEFT | DT_NOPREFIX | DT_CALCRECT); + DrawText(hdc, VersionString, strlen(VersionString), &rt, + DT_LEFT | DT_NOPREFIX); + EndPaint(hWnd, &ps); + } break; - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); - if( GetNHApp()->hMainWnd==hWnd ) - GetNHApp()->hMainWnd=NULL; - DestroyWindow(hWnd); - SetFocus(GetNHApp()->hMainWnd); - return TRUE; - } - break; - } - return FALSE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); + if (GetNHApp()->hMainWnd == hWnd) + GetNHApp()->hMainWnd = NULL; + DestroyWindow(hWnd); + SetFocus(GetNHApp()->hMainWnd); + return TRUE; + } + break; + } + return FALSE; } - diff --git a/win/win32/mhstatus.c b/win/win32/mhstatus.c index 4e8c23d55..ae05223a7 100644 --- a/win/win32/mhstatus.c +++ b/win/win32/mhstatus.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhstatus.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhstatus.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */ /* NetHack 3.6 mhstatus.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.14 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -8,342 +8,356 @@ #include "mhmsg.h" #include "mhfont.h" -#define NHSW_LINES 2 +#define NHSW_LINES 2 #define MAXWINDOWTEXT BUFSZ -extern COLORREF nhcolor_to_RGB (int c); /* from mhmap */ +extern COLORREF nhcolor_to_RGB(int c); /* from mhmap */ typedef struct mswin_nethack_status_window { - int index; - char window_text[NHSW_LINES][MAXWINDOWTEXT+1]; - int n_fields; - const char** vals; - boolean* activefields; - int* colors; + int index; + char window_text[NHSW_LINES][MAXWINDOWTEXT + 1]; + int n_fields; + const char **vals; + boolean *activefields; + int *colors; } NHStatusWindow, *PNHStatusWindow; #ifdef STATUS_VIA_WINDOWPORT -static int fieldorder1[] = { - BL_TITLE, BL_STR, BL_DX,BL_CO, BL_IN, - BL_WI, BL_CH,BL_ALIGN, BL_SCORE, -1 - }; -static int fieldorder2[] = { - BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, - BL_ENE, BL_ENEMAX, BL_AC, BL_XP, BL_EXP, BL_HD, - BL_TIME, BL_HUNGER,BL_CAP, BL_CONDITION, -1 - }; -static int* fieldorders[] = {fieldorder1, fieldorder2, NULL}; +static int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, + BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 }; +static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, + BL_ENE, BL_ENEMAX, BL_AC, BL_XP, + BL_EXP, BL_HD, BL_TIME, BL_HUNGER, + BL_CAP, BL_CONDITION, -1 }; +static int *fieldorders[] = { fieldorder1, fieldorder2, NULL }; #endif /* STATUS_VIA_WINDOWPORT */ static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass"); -LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM); static void register_status_window_class(void); -static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam); +static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam); -#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW -#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT +#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW +#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT -HWND mswin_init_status_window () { - static int run_once = 0; - HWND ret; - NHStatusWindow* data; - RECT rt; +HWND +mswin_init_status_window() +{ + static int run_once = 0; + HWND ret; + NHStatusWindow *data; + RECT rt; - if( !run_once ) { - register_status_window_class( ); - run_once = 1; - } + if (!run_once) { + register_status_window_class(); + run_once = 1; + } - /* get window position */ - if( GetNHApp()->bAutoLayout ) { - SetRect( &rt, 0, 0, 0, 0); - } else { - mswin_get_window_placement(NHW_STATUS, &rt); - } + /* get window position */ + if (GetNHApp()->bAutoLayout) { + SetRect(&rt, 0, 0, 0, 0); + } else { + mswin_get_window_placement(NHW_STATUS, &rt); + } - /* create status window object */ - ret = CreateWindow( - szStatusWindowClass, - NULL, - WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX, - rt.left, /* horizontal position of window */ - rt.top, /* vertical position of window */ - rt.right - rt.left, /* window width */ - rt.bottom - rt.top, /* window height */ - GetNHApp()->hMainWnd, - NULL, - GetNHApp()->hApp, - NULL ); - if( !ret ) panic("Cannot create status window"); + /* create status window object */ + ret = CreateWindow(szStatusWindowClass, NULL, + WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX, + rt.left, /* horizontal position of window */ + rt.top, /* vertical position of window */ + rt.right - rt.left, /* window width */ + rt.bottom - rt.top, /* window height */ + GetNHApp()->hMainWnd, NULL, GetNHApp()->hApp, NULL); + if (!ret) + panic("Cannot create status window"); - /* Set window caption */ - SetWindowText(ret, "Status"); + /* Set window caption */ + SetWindowText(ret, "Status"); - /* create window data */ - data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow)); - if( !data ) panic("out of memory"); + /* create window data */ + data = (PNHStatusWindow) malloc(sizeof(NHStatusWindow)); + if (!data) + panic("out of memory"); - ZeroMemory(data, sizeof(NHStatusWindow)); - SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data); - return ret; + ZeroMemory(data, sizeof(NHStatusWindow)); + SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data); + return ret; } -void register_status_window_class() +void +register_status_window_class() { - WNDCLASS wcex; - ZeroMemory( &wcex, sizeof(wcex)); + WNDCLASS wcex; + ZeroMemory(&wcex, sizeof(wcex)); - wcex.style = CS_NOCLOSE; - wcex.lpfnWndProc = (WNDPROC)StatusWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetNHApp()->hApp; - wcex.hIcon = NULL; - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = status_bg_brush - ? status_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = szStatusWindowClass; + wcex.style = CS_NOCLOSE; + wcex.lpfnWndProc = (WNDPROC) StatusWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetNHApp()->hApp; + wcex.hIcon = NULL; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = status_bg_brush + ? status_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = szStatusWindowClass; - RegisterClass(&wcex); + RegisterClass(&wcex); } - - -LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - PNHStatusWindow data; - - data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (message) - { - case WM_MSNH_COMMAND: { - switch( wParam ) { - - case MSNH_MSG_PUTSTR: { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - strncpy(data->window_text[data->index], msg_data->text, - MAXWINDOWTEXT); - data->index = (data->index+1) % NHSW_LINES; - InvalidateRect(hWnd, NULL, TRUE); - } break; - - case MSNH_MSG_CLEAR_WINDOW: { - data->index = 0; - ZeroMemory(data->window_text, sizeof(data->window_text)); - InvalidateRect(hWnd, NULL, TRUE); - } break; - case MSNH_MSG_GETTEXT: { - PMSNHMsgGetText msg_data = (PMSNHMsgGetText)lParam; +LRESULT CALLBACK +StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + PNHStatusWindow data; + + data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (message) { + case WM_MSNH_COMMAND: { + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + strncpy(data->window_text[data->index], msg_data->text, + MAXWINDOWTEXT); + data->index = (data->index + 1) % NHSW_LINES; + InvalidateRect(hWnd, NULL, TRUE); + } break; + + case MSNH_MSG_CLEAR_WINDOW: { + data->index = 0; + ZeroMemory(data->window_text, sizeof(data->window_text)); + InvalidateRect(hWnd, NULL, TRUE); + } break; + + case MSNH_MSG_GETTEXT: { + PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam; #ifdef STATUS_VIA_WINDOWPORT - int **fop; - int *f; - msg_data->buffer[0] = '\0'; - if( data->n_fields>0 ) { - for(fop = fieldorders; *fop; fop++) { - for(f=*fop; *f!=-1; f++) { - if (data->activefields[*f]) - strncat(msg_data->buffer, data->vals[*f], msg_data->max_size - strlen(msg_data->buffer)); - } - strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) ); - } - } -#else /* STATUS_VIA_WINDOWPORT */ - strncpy(msg_data->buffer, data->window_text[0], msg_data->max_size); - strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) ); - strncat(msg_data->buffer, data->window_text[1], msg_data->max_size - strlen(msg_data->buffer) ); + int **fop; + int *f; + msg_data->buffer[0] = '\0'; + if (data->n_fields > 0) { + for (fop = fieldorders; *fop; fop++) { + for (f = *fop; *f != -1; f++) { + if (data->activefields[*f]) + strncat(msg_data->buffer, data->vals[*f], + msg_data->max_size + - strlen(msg_data->buffer)); + } + strncat(msg_data->buffer, "\r\n", + msg_data->max_size - strlen(msg_data->buffer)); + } + } +#else /* STATUS_VIA_WINDOWPORT */ + strncpy(msg_data->buffer, data->window_text[0], + msg_data->max_size); + strncat(msg_data->buffer, "\r\n", + msg_data->max_size - strlen(msg_data->buffer)); + strncat(msg_data->buffer, data->window_text[1], + msg_data->max_size - strlen(msg_data->buffer)); #endif /* STATUS_VIA_WINDOWPORT */ - } break; + } break; - case MSNH_MSG_UPDATE_STATUS: { - PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus)lParam; - data->n_fields = msg_data->n_fields; - data->vals = msg_data->vals; - data->activefields = msg_data->activefields; - data->colors = msg_data->colors; - InvalidateRect(hWnd, NULL, TRUE); - } break; - } /* end switch( wParam ) { */ - } break; + case MSNH_MSG_UPDATE_STATUS: { + PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus) lParam; + data->n_fields = msg_data->n_fields; + data->vals = msg_data->vals; + data->activefields = msg_data->activefields; + data->colors = msg_data->colors; + InvalidateRect(hWnd, NULL, TRUE); + } break; + } /* end switch( wParam ) { */ + } break; - case WM_PAINT: - return onWMPaint(hWnd, wParam, lParam); + case WM_PAINT: + return onWMPaint(hWnd, wParam, lParam); - case WM_SIZE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_STATUS, &rt); - } return FALSE; + case WM_SIZE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_STATUS, &rt); + } + return FALSE; - case WM_MOVE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_STATUS, &rt); - } return FALSE; + case WM_MOVE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_STATUS, &rt); + } + return FALSE; - case WM_DESTROY: - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - break; + case WM_DESTROY: + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + break; - case WM_SETFOCUS: - SetFocus(GetNHApp()->hMainWnd); - break; + case WM_SETFOCUS: + SetFocus(GetNHApp()->hMainWnd); + break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; } #ifdef STATUS_VIA_WINDOWPORT -static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) +static LRESULT +onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) { - int* f; - int** fop; - SIZE sz; - HGDIOBJ oldFont, normalFont, boldFont; - TCHAR wbuf[BUFSZ]; - COLORREF OldBg, OldFg, Bg, Fg; - RECT rt; - PAINTSTRUCT ps; - HDC hdc; - PNHStatusWindow data; - - data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + int *f; + int **fop; + SIZE sz; + HGDIOBJ oldFont, normalFont, boldFont; + TCHAR wbuf[BUFSZ]; + COLORREF OldBg, OldFg, Bg, Fg; + RECT rt; + PAINTSTRUCT ps; + HDC hdc; + PNHStatusWindow data; - hdc = BeginPaint(hWnd, &ps); - GetClientRect(hWnd, &rt); - - normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE); - boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE); - oldFont = SelectObject(hdc, normalFont); + data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - Bg = status_bg_brush? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS); - OldBg = SetBkColor(hdc, Bg); - - Fg = status_fg_brush? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS); - OldFg = SetTextColor(hdc, Fg); - - for(fop = fieldorders; *fop; fop++) { - LONG left = rt.left; - LONG cy = 0; - int vlen; - for(f=*fop; *f!=-1; f++) { - if( ((*f)>= data->n_fields) || (!data->activefields[*f])) continue; - vlen = strlen(data->vals[*f]); - NH_A2W(data->vals[*f], wbuf, SIZE(wbuf)); - - if(data->colors[*f]==CLR_MAX || data->colors[*f]==BL_HILITE_NONE) { - SelectObject(hdc, normalFont); - SetBkColor(hdc, Bg); - SetTextColor(hdc, Fg); - } else if(data->colors[*f]>0) { - SelectObject(hdc, normalFont); - SetBkColor(hdc, Bg); - SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f])); - } else if(data->colors[*f]==BL_HILITE_INVERSE) { - SelectObject(hdc, normalFont); - SetBkColor(hdc, Fg); - SetTextColor(hdc, Bg); - } else if(data->colors[*f]==BL_HILITE_BOLD) { - SelectObject(hdc, boldFont); - SetBkColor(hdc, Bg); - SetTextColor(hdc, Fg); - } else { - SelectObject(hdc, normalFont); - SetBkColor(hdc, Bg); - SetTextColor(hdc, Fg); - } - - GetTextExtentPoint32(hdc, wbuf, vlen, &sz); - DrawText(hdc, wbuf, vlen, &rt, DT_LEFT); - - rt.left += sz.cx; - cy = max(cy, sz.cy); - } - rt.left = left; - rt.top += cy; - } + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rt); - SelectObject(hdc, oldFont); - SetTextColor (hdc, OldFg); - SetBkColor (hdc, OldBg); - EndPaint(hWnd, &ps); - - return 0; + normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE); + boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE); + oldFont = SelectObject(hdc, normalFont); + + Bg = status_bg_brush ? status_bg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_BG_STATUS); + OldBg = SetBkColor(hdc, Bg); + + Fg = status_fg_brush ? status_fg_color + : (COLORREF) GetSysColor(DEFAULT_COLOR_FG_STATUS); + OldFg = SetTextColor(hdc, Fg); + + for (fop = fieldorders; *fop; fop++) { + LONG left = rt.left; + LONG cy = 0; + int vlen; + for (f = *fop; *f != -1; f++) { + if (((*f) >= data->n_fields) || (!data->activefields[*f])) + continue; + vlen = strlen(data->vals[*f]); + NH_A2W(data->vals[*f], wbuf, SIZE(wbuf)); + + if (data->colors[*f] == CLR_MAX + || data->colors[*f] == BL_HILITE_NONE) { + SelectObject(hdc, normalFont); + SetBkColor(hdc, Bg); + SetTextColor(hdc, Fg); + } else if (data->colors[*f] > 0) { + SelectObject(hdc, normalFont); + SetBkColor(hdc, Bg); + SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f])); + } else if (data->colors[*f] == BL_HILITE_INVERSE) { + SelectObject(hdc, normalFont); + SetBkColor(hdc, Fg); + SetTextColor(hdc, Bg); + } else if (data->colors[*f] == BL_HILITE_BOLD) { + SelectObject(hdc, boldFont); + SetBkColor(hdc, Bg); + SetTextColor(hdc, Fg); + } else { + SelectObject(hdc, normalFont); + SetBkColor(hdc, Bg); + SetTextColor(hdc, Fg); + } + + GetTextExtentPoint32(hdc, wbuf, vlen, &sz); + DrawText(hdc, wbuf, vlen, &rt, DT_LEFT); + + rt.left += sz.cx; + cy = max(cy, sz.cy); + } + rt.left = left; + rt.top += cy; + } + + SelectObject(hdc, oldFont); + SetTextColor(hdc, OldFg); + SetBkColor(hdc, OldBg); + EndPaint(hWnd, &ps); + + return 0; } #else -static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) +static LRESULT +onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) { - int i; - SIZE sz; - HGDIOBJ oldFont; - TCHAR wbuf[BUFSZ]; - COLORREF OldBg, OldFg; - RECT rt; - PAINTSTRUCT ps; - HDC hdc; - PNHStatusWindow data; - - data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); + int i; + SIZE sz; + HGDIOBJ oldFont; + TCHAR wbuf[BUFSZ]; + COLORREF OldBg, OldFg; + RECT rt; + PAINTSTRUCT ps; + HDC hdc; + PNHStatusWindow data; - hdc = BeginPaint(hWnd, &ps); - GetClientRect(hWnd, &rt); - - oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); + data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); - OldBg = SetBkColor(hdc, status_bg_brush - ? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS)); - OldFg = SetTextColor(hdc, status_fg_brush - ? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS)); - - for(i=0; iwindow_text[i]); - NH_A2W(data->window_text[i], wbuf, SIZE(wbuf)); - GetTextExtentPoint32(hdc, wbuf, wlen, &sz); - DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS); - rt.top += sz.cy; - } + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rt); - SelectObject(hdc, oldFont); - SetTextColor (hdc, OldFg); - SetBkColor (hdc, OldBg); - EndPaint(hWnd, &ps); - - return 0; + oldFont = + SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); + + OldBg = SetBkColor(hdc, status_bg_brush ? status_bg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_BG_STATUS)); + OldFg = SetTextColor(hdc, status_fg_brush ? status_fg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_FG_STATUS)); + + for (i = 0; i < NHSW_LINES; i++) { + int wlen = strlen(data->window_text[i]); + NH_A2W(data->window_text[i], wbuf, SIZE(wbuf)); + GetTextExtentPoint32(hdc, wbuf, wlen, &sz); + DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS); + rt.top += sz.cy; + } + + SelectObject(hdc, oldFont); + SetTextColor(hdc, OldFg); + SetBkColor(hdc, OldBg); + EndPaint(hWnd, &ps); + + return 0; } #endif /*STATUS_VIA_WINDOWPORT*/ -void mswin_status_window_size (HWND hWnd, LPSIZE sz) +void +mswin_status_window_size(HWND hWnd, LPSIZE sz) { TEXTMETRIC tm; - HGDIOBJ saveFont; - HDC hdc; - PNHStatusWindow data; - RECT rt; - SIZE text_sz; - - GetClientRect(hWnd, &rt); + HGDIOBJ saveFont; + HDC hdc; + PNHStatusWindow data; + RECT rt; + SIZE text_sz; - data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if(data) { - hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); - GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz); - GetTextMetrics(hdc, &tm); + GetClientRect(hWnd, &rt); - rt.bottom = rt.top + text_sz.cy*NHSW_LINES; + data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (data) { + hdc = GetDC(hWnd); + saveFont = SelectObject( + hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); + GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz); + GetTextMetrics(hdc, &tm); - SelectObject(hdc, saveFont); - ReleaseDC(hWnd, hdc); - } - AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE); - sz->cx = rt.right - rt.left; - sz->cy = rt.bottom - rt.top; + rt.bottom = rt.top + text_sz.cy * NHSW_LINES; + + SelectObject(hdc, saveFont); + ReleaseDC(hWnd, hdc); + } + AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE); + sz->cx = rt.right - rt.left; + sz->cy = rt.bottom - rt.top; } - diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index e2121ec68..671144f37 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhtext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mhtext.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */ /* NetHack 3.6 mhtext.c $Date: 2012/01/11 01:53:44 $ $Revision: 1.17 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,264 +12,283 @@ PNHWinApp GetNHApp(void); typedef struct mswin_nethack_text_window { - TCHAR* window_text; + TCHAR *window_text; } NHTextWindow, *PNHTextWindow; -static WNDPROC editControlWndProc = 0; -#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW -#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT +static WNDPROC editControlWndProc = 0; +#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW +#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT -INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM); static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam); static void LayoutText(HWND hwnd); -HWND mswin_init_text_window () { - HWND ret; - PNHTextWindow data; - RECT rt; +HWND +mswin_init_text_window() +{ + HWND ret; + PNHTextWindow data; + RECT rt; - /* get window position */ - if( GetNHApp()->bAutoLayout ) { - SetRect( &rt, 0, 0, 0, 0); - } else { - mswin_get_window_placement(NHW_TEXT, &rt); - } + /* get window position */ + if (GetNHApp()->bAutoLayout) { + SetRect(&rt, 0, 0, 0, 0); + } else { + mswin_get_window_placement(NHW_TEXT, &rt); + } - /* create text widnow object */ - ret = CreateDialog( - GetNHApp()->hApp, - MAKEINTRESOURCE(IDD_NHTEXT), - GetNHApp()->hMainWnd, - NHTextWndProc - ); - if( !ret ) panic("Cannot create text window"); + /* create text widnow object */ + ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHTEXT), + GetNHApp()->hMainWnd, NHTextWndProc); + if (!ret) + panic("Cannot create text window"); - /* move it in the predefined position */ - if( !GetNHApp()->bAutoLayout ) { - MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, TRUE); - } + /* move it in the predefined position */ + if (!GetNHApp()->bAutoLayout) { + MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, + rt.bottom - rt.top, TRUE); + } - /* Set window caption */ - SetWindowText(ret, "Text"); - if( !GetNHApp()->bWindowsLocked ) { - DWORD style; - style = GetWindowLong(ret, GWL_STYLE); - style |= WS_CAPTION; - SetWindowLong(ret, GWL_STYLE, style); - SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - } + /* Set window caption */ + SetWindowText(ret, "Text"); + if (!GetNHApp()->bWindowsLocked) { + DWORD style; + style = GetWindowLong(ret, GWL_STYLE); + style |= WS_CAPTION; + SetWindowLong(ret, GWL_STYLE, style); + SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE + | SWP_NOZORDER + | SWP_FRAMECHANGED); + } - /* create and set window data */ - data = (PNHTextWindow)malloc(sizeof(NHTextWindow)); - if( !data ) panic("out of memory"); - ZeroMemory(data, sizeof(NHTextWindow)); - SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data); - return ret; + /* create and set window data */ + data = (PNHTextWindow) malloc(sizeof(NHTextWindow)); + if (!data) + panic("out of memory"); + ZeroMemory(data, sizeof(NHTextWindow)); + SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data); + return ret; } -void mswin_display_text_window (HWND hWnd) +void +mswin_display_text_window(HWND hWnd) { - PNHTextWindow data; - - data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if( data && data->window_text ) { - HWND control; - control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); - SendMessage(control, EM_FMTLINES, 1, 0 ); - SetWindowText(control, data->window_text); - } + PNHTextWindow data; - mswin_popup_display(hWnd, NULL); - mswin_popup_destroy(hWnd); + data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (data && data->window_text) { + HWND control; + control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); + SendMessage(control, EM_FMTLINES, 1, 0); + SetWindowText(control, data->window_text); + } + + mswin_popup_display(hWnd, NULL); + mswin_popup_destroy(hWnd); } - -INT_PTR CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + +INT_PTR CALLBACK +NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HWND control; - HDC hdc; - PNHTextWindow data; + HWND control; + HDC hdc; + PNHTextWindow data; TCHAR title[MAX_LOADSTRING]; - - data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch (message) - { - case WM_INITDIALOG: - /* set text control font */ - control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); - if( !control ) { - panic("cannot get text view window"); - } - hdc = GetDC(control); - SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); - ReleaseDC(control, hdc); + data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (message) { + case WM_INITDIALOG: + /* set text control font */ + control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); + if (!control) { + panic("cannot get text view window"); + } - /* subclass edit control */ - editControlWndProc = (WNDPROC)GetWindowLongPtr(control, GWLP_WNDPROC); - SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)NHEditHookWndProc); + hdc = GetDC(control); + SendMessage(control, WM_SETFONT, + (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), + 0); + ReleaseDC(control, hdc); - SetFocus(control); + /* subclass edit control */ + editControlWndProc = + (WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC); + SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHEditHookWndProc); - /* Even though the dialog has no caption, you can still set the title + SetFocus(control); + + /* Even though the dialog has no caption, you can still set the title which shows on Alt-Tab */ LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING); SetWindowText(hWnd, title); - return FALSE; + return FALSE; - case WM_MSNH_COMMAND: - onMSNHCommand(hWnd, wParam, lParam); - break; + case WM_MSNH_COMMAND: + onMSNHCommand(hWnd, wParam, lParam); + break; - case WM_SIZE: { - RECT rt; + case WM_SIZE: { + RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_TEXT, &rt); + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_TEXT, &rt); - LayoutText(hWnd); - } return FALSE; + LayoutText(hWnd); + } + return FALSE; - case WM_MOVE: { - RECT rt; - GetWindowRect(hWnd, &rt); - ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt); - ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1); - mswin_update_window_placement(NHW_TEXT, &rt); - } return FALSE; + case WM_MOVE: { + RECT rt; + GetWindowRect(hWnd, &rt); + ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); + ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); + mswin_update_window_placement(NHW_TEXT, &rt); + } + return FALSE; - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - case IDCANCEL: - mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); - if( GetNHApp()->hMainWnd==hWnd ) - GetNHApp()->hMainWnd=NULL; - DestroyWindow(hWnd); - SetFocus(GetNHApp()->hMainWnd); - return TRUE; - } - break; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + case IDCANCEL: + mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); + if (GetNHApp()->hMainWnd == hWnd) + GetNHApp()->hMainWnd = NULL; + DestroyWindow(hWnd); + SetFocus(GetNHApp()->hMainWnd); + return TRUE; + } + break; - case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ - HDC hdcEdit = (HDC) wParam; - HWND hwndEdit = (HWND) lParam; - if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) { - SetBkColor(hdcEdit, - text_bg_brush ? text_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_TEXT) - ); - SetTextColor(hdcEdit, - text_fg_brush ? text_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_TEXT) - ); - return (INT_PTR)(text_bg_brush - ? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); - } - } return FALSE; + case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ + HDC hdcEdit = (HDC) wParam; + HWND hwndEdit = (HWND) lParam; + if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) { + SetBkColor(hdcEdit, text_bg_brush ? text_bg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_BG_TEXT)); + SetTextColor(hdcEdit, text_fg_brush ? text_fg_color + : (COLORREF) GetSysColor( + DEFAULT_COLOR_FG_TEXT)); + return (INT_PTR)(text_bg_brush + ? text_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); + } + } + return FALSE; - case WM_DESTROY: - if( data ) { - if( data->window_text ) free(data->window_text); - free(data); - SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); - } - break; - - } - return FALSE; + case WM_DESTROY: + if (data) { + if (data->window_text) + free(data->window_text); + free(data); + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); + } + break; + } + return FALSE; } -void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) +void +onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PNHTextWindow data; - - data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); - switch( wParam ) { - case MSNH_MSG_PUTSTR: { - PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; - TCHAR wbuf[BUFSZ]; - size_t text_size; + PNHTextWindow data; - if( !data->window_text ) { - text_size = strlen(msg_data->text) + 4; - data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0])); - ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0])); - } else { - text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4; - data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0])); - } - if( !data->window_text ) break; - - _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ)); - _tcscat(data->window_text, TEXT("\r\n")); - break; - } - } + data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (wParam) { + case MSNH_MSG_PUTSTR: { + PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam; + TCHAR wbuf[BUFSZ]; + size_t text_size; + + if (!data->window_text) { + text_size = strlen(msg_data->text) + 4; + data->window_text = + (TCHAR *) malloc(text_size * sizeof(data->window_text[0])); + ZeroMemory(data->window_text, + text_size * sizeof(data->window_text[0])); + } else { + text_size = + _tcslen(data->window_text) + strlen(msg_data->text) + 4; + data->window_text = (TCHAR *) realloc( + data->window_text, text_size * sizeof(data->window_text[0])); + } + if (!data->window_text) + break; + + _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ)); + _tcscat(data->window_text, TEXT("\r\n")); + break; + } + } } -void LayoutText(HWND hWnd) +void +LayoutText(HWND hWnd) { - HWND btn_ok; - HWND text; - RECT clrt, rt; - POINT pt_elem, pt_ok; - SIZE sz_elem, sz_ok; + HWND btn_ok; + HWND text; + RECT clrt, rt; + POINT pt_elem, pt_ok; + SIZE sz_elem, sz_ok; - text = GetDlgItem(hWnd, IDC_TEXT_CONTROL); - btn_ok = GetDlgItem(hWnd, IDOK); + text = GetDlgItem(hWnd, IDC_TEXT_CONTROL); + btn_ok = GetDlgItem(hWnd, IDOK); - /* get window coordinates */ - GetClientRect(hWnd, &clrt ); - - /* set window placements */ - GetWindowRect(btn_ok, &rt); - sz_ok.cx = clrt.right - clrt.left; - sz_ok.cy = rt.bottom-rt.top; - pt_ok.x = clrt.left; - pt_ok.y = clrt.bottom - sz_ok.cy; + /* get window coordinates */ + GetClientRect(hWnd, &clrt); - pt_elem.x = clrt.left; - pt_elem.y = clrt.top; - sz_elem.cx = clrt.right - clrt.left; - sz_elem.cy = pt_ok.y; + /* set window placements */ + GetWindowRect(btn_ok, &rt); + sz_ok.cx = clrt.right - clrt.left; + sz_ok.cy = rt.bottom - rt.top; + pt_ok.x = clrt.left; + pt_ok.y = clrt.bottom - sz_ok.cy; - MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); - MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE ); + pt_elem.x = clrt.left; + pt_elem.y = clrt.top; + sz_elem.cx = clrt.right - clrt.left; + sz_elem.cy = pt_ok.y; + + MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE); + MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); } /* Edit box hook */ -LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK +NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hDC; - RECT rc; + HDC hDC; + RECT rc; - switch(message) { - case WM_ERASEBKGND: - hDC = (HDC) wParam; - GetClientRect(hWnd, &rc); - FillRect(hDC, &rc, text_bg_brush? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); - return 1; + switch (message) { + case WM_ERASEBKGND: + hDC = (HDC) wParam; + GetClientRect(hWnd, &rc); + FillRect(hDC, &rc, text_bg_brush + ? text_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); + return 1; - case WM_KEYDOWN: - switch (wParam) - { - /* close on space in Windows mode + case WM_KEYDOWN: + switch (wParam) { + /* close on space in Windows mode page down on space in NetHack mode */ - case VK_SPACE: - { + case VK_SPACE: { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; GetScrollInfo(hWnd, SB_VERT, &si); /* If nethackmode and not at the end of the list */ - if (GetNHApp()->regNetHackMode && - (si.nPos + (int)si.nPage) <= (si.nMax - si.nMin)) + if (GetNHApp()->regNetHackMode + && (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin)) SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); else - PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); + PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), + 0); return 0; } case VK_NEXT: @@ -284,20 +303,19 @@ LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case VK_DOWN: SendMessage(hWnd, EM_SCROLL, SB_LINEDOWN, 0); return 0; + } + break; - } - break; + /* edit control needs to know nothing of focus. We will take care of it + * for it */ + case WM_SETFOCUS: + HideCaret(hWnd); + return 0; + } - /* edit control needs to know nothing of focus. We will take care of it for it */ - case WM_SETFOCUS: - HideCaret(hWnd); - return 0; - } - - - if( editControlWndProc ) - return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam); - else - return 0; + if (editControlWndProc) + return CallWindowProc(editControlWndProc, hWnd, message, wParam, + lParam); + else + return 0; } - diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 947152c6b..7b9cafdc6 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -1,16 +1,16 @@ -/* NetHack 3.6 mswproc.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 mswproc.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.87 $ */ /* NetHack 3.6 mswproc.c $Date: 2012/01/24 04:26:33 $ $Revision: 1.71 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ /* * This file implements the interface between the window port specific - * code in the mswin port and the rest of the nethack game engine. + * code in the mswin port and the rest of the nethack game engine. */ #include "hack.h" #include "dlb.h" -#include "func_tab.h" /* for extended commands */ +#include "func_tab.h" /* for extended commands */ #include "winMS.h" #include #include "mhmap.h" @@ -35,15 +35,19 @@ #ifdef _DEBUG extern void logDebug(const char *fmt, ...); #else -void logDebug(const char *fmt, ...) { } +void +logDebug(const char *fmt, ...) +{ +} #endif static void mswin_main_loop(void); static BOOL initMapTiles(void); -static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr); +static void mswin_color_from_string(char *colorstring, HBRUSH *brushptr, + COLORREF *colorptr); static void prompt_for_player_selection(void); -#define TOTAL_BRUSHES 10 +#define TOTAL_BRUSHES 10 HBRUSH brush_table[TOTAL_BRUSHES]; int max_brush = 0; @@ -68,79 +72,47 @@ COLORREF message_fg_color = RGB(0xFF, 0xFF, 0xFF); /* Interface definition, for windows.c */ struct window_procs mswin_procs = { "MSWIN", - WC_COLOR|WC_HILITE_PET|WC_ALIGN_MESSAGE|WC_ALIGN_STATUS| - WC_INVERSE|WC_SCROLL_AMOUNT|WC_SCROLL_MARGIN|WC_MAP_MODE| - WC_FONT_MESSAGE|WC_FONT_STATUS|WC_FONT_MENU|WC_FONT_TEXT|WC_FONT_MAP| - WC_FONTSIZ_MESSAGE|WC_FONTSIZ_STATUS|WC_FONTSIZ_MENU|WC_FONTSIZ_TEXT| - WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE|WC_VARY_MSGCOUNT| - WC_WINDOWCOLORS|WC_PLAYER_SELECTION|WC_SPLASH_SCREEN|WC_POPUP_DIALOG, - 0L, - mswin_init_nhwindows, - mswin_player_selection, - mswin_askname, - mswin_get_nh_event, - mswin_exit_nhwindows, - mswin_suspend_nhwindows, - mswin_resume_nhwindows, - mswin_create_nhwindow, - mswin_clear_nhwindow, - mswin_display_nhwindow, - mswin_destroy_nhwindow, - mswin_curs, - mswin_putstr, - genl_putmixed, - mswin_display_file, - mswin_start_menu, - mswin_add_menu, - mswin_end_menu, - mswin_select_menu, - genl_message_menu, /* no need for X-specific handling */ - mswin_update_inventory, - mswin_mark_synch, - mswin_wait_synch, + WC_COLOR | WC_HILITE_PET | WC_ALIGN_MESSAGE | WC_ALIGN_STATUS | WC_INVERSE + | WC_SCROLL_AMOUNT | WC_SCROLL_MARGIN | WC_MAP_MODE | WC_FONT_MESSAGE + | WC_FONT_STATUS | WC_FONT_MENU | WC_FONT_TEXT | WC_FONT_MAP + | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS | WC_FONTSIZ_MENU + | WC_FONTSIZ_TEXT | WC_TILE_WIDTH | WC_TILE_HEIGHT | WC_TILE_FILE + | WC_VARY_MSGCOUNT | WC_WINDOWCOLORS | WC_PLAYER_SELECTION + | WC_SPLASH_SCREEN | WC_POPUP_DIALOG, + 0L, mswin_init_nhwindows, mswin_player_selection, mswin_askname, + mswin_get_nh_event, mswin_exit_nhwindows, mswin_suspend_nhwindows, + mswin_resume_nhwindows, mswin_create_nhwindow, mswin_clear_nhwindow, + mswin_display_nhwindow, mswin_destroy_nhwindow, mswin_curs, mswin_putstr, + genl_putmixed, mswin_display_file, mswin_start_menu, mswin_add_menu, + mswin_end_menu, mswin_select_menu, + genl_message_menu, /* no need for X-specific handling */ + mswin_update_inventory, mswin_mark_synch, mswin_wait_synch, #ifdef CLIPPING mswin_cliparound, #endif #ifdef POSITIONBAR donull, #endif - mswin_print_glyph, - mswin_raw_print, - mswin_raw_print_bold, - mswin_nhgetch, - mswin_nh_poskey, - mswin_nhbell, - mswin_doprev_message, - mswin_yn_function, - mswin_getlin, - mswin_get_ext_cmd, - mswin_number_pad, - mswin_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - mswin, - mswin_change_background, + mswin_print_glyph, mswin_raw_print, mswin_raw_print_bold, mswin_nhgetch, + mswin_nh_poskey, mswin_nhbell, mswin_doprev_message, mswin_yn_function, + mswin_getlin, mswin_get_ext_cmd, mswin_number_pad, mswin_delay_output, +#ifdef CHANGE_COLOR /* only a Mac option currently */ + mswin, mswin_change_background, #endif /* other defs that really should go away (they're tty specific) */ - mswin_start_screen, - mswin_end_screen, - mswin_outrip, - mswin_preference_update, - mswin_getmsghistory, - mswin_putmsghistory, + mswin_start_screen, mswin_end_screen, mswin_outrip, + mswin_preference_update, mswin_getmsghistory, mswin_putmsghistory, #ifdef STATUS_VIA_WINDOWPORT - mswin_status_init, - mswin_status_finish, - mswin_status_enablefield, + mswin_status_init, mswin_status_finish, mswin_status_enablefield, mswin_status_update, -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES mswin_status_threshold, -# endif +#endif #endif genl_can_suspend_yes, }; - -/* +/* init_nhwindows(int* argcp, char** argv) -- Initialize the windows used by NetHack. This can also create the standard windows listed at the top, but does @@ -154,26 +126,26 @@ init_nhwindows(int* argcp, char** argv) ** Why not have init_nhwindows() create all of the "standard" ** windows? Or at least all but WIN_INFO? -dean */ -void mswin_init_nhwindows(int* argc, char** argv) +void +mswin_init_nhwindows(int *argc, char **argv) { - UNREFERENCED_PARAMETER(argc); - UNREFERENCED_PARAMETER(argv); + UNREFERENCED_PARAMETER(argc); + UNREFERENCED_PARAMETER(argv); - logDebug("mswin_init_nhwindows()\n"); + logDebug("mswin_init_nhwindows()\n"); #ifdef _DEBUG - if (showdebug(NHTRACE_LOG)) - { - /* truncate trace file */ - FILE *dfp = fopen(NHTRACE_LOG, "w"); - fclose(dfp); - } + if (showdebug(NHTRACE_LOG)) { + /* truncate trace file */ + FILE *dfp = fopen(NHTRACE_LOG, "w"); + fclose(dfp); + } #endif mswin_nh_input_init(); - /* set it to WIN_ERR so we can detect attempts to - use this ID before it is inialized */ - WIN_MAP = WIN_ERR; + /* set it to WIN_ERR so we can detect attempts to + use this ID before it is inialized */ + WIN_MAP = WIN_ERR; /* Read Windows settings from the reqistry */ /* First set safe defaults */ @@ -181,8 +153,7 @@ void mswin_init_nhwindows(int* argc, char** argv) mswin_read_reg(); /* Create the main window */ GetNHApp()->hMainWnd = mswin_init_main_window(); - if (!GetNHApp()->hMainWnd) - { + if (!GetNHApp()->hMainWnd) { panic("Cannot create main window"); } @@ -190,638 +161,663 @@ void mswin_init_nhwindows(int* argc, char** argv) mswin_menu_check_intf_mode(); /* check default values */ - if( iflags.wc_fontsiz_statusNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_status < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_status > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_messageNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_message < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_message > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_textNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_text < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_text > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_menuNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; + if (iflags.wc_fontsiz_menu < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_menu > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; - if( iflags.wc_align_message==0 ) iflags.wc_align_message = ALIGN_TOP; - if( iflags.wc_align_status==0 ) iflags.wc_align_status = ALIGN_BOTTOM; - if( iflags.wc_scroll_margin==0 ) iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; - if( iflags.wc_scroll_amount==0 ) iflags.wc_scroll_amount = DEF_CLIPAROUND_AMOUNT; - if( iflags.wc_tile_width==0 ) iflags.wc_tile_width = TILE_X; - if( iflags.wc_tile_height==0 ) iflags.wc_tile_height = TILE_Y; + if (iflags.wc_align_message == 0) + iflags.wc_align_message = ALIGN_TOP; + if (iflags.wc_align_status == 0) + iflags.wc_align_status = ALIGN_BOTTOM; + if (iflags.wc_scroll_margin == 0) + iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN; + if (iflags.wc_scroll_amount == 0) + iflags.wc_scroll_amount = DEF_CLIPAROUND_AMOUNT; + if (iflags.wc_tile_width == 0) + iflags.wc_tile_width = TILE_X; + if (iflags.wc_tile_height == 0) + iflags.wc_tile_height = TILE_Y; - if( iflags.wc_vary_msgcount==0 ) iflags.wc_vary_msgcount = 4; + if (iflags.wc_vary_msgcount == 0) + iflags.wc_vary_msgcount = 4; - /* force tabs in menus */ - iflags.menu_tab_sep = 1; + /* force tabs in menus */ + iflags.menu_tab_sep = 1; - /* force toptenwin to be true. toptenwin is the option that decides whether to - * write output to a window or stdout. stdout doesn't make sense on Windows - * non-console applications - */ - iflags.toptenwin = 1; - set_option_mod_status("toptenwin", SET_IN_FILE); - set_option_mod_status("perm_invent", SET_IN_FILE); + /* force toptenwin to be true. toptenwin is the option that decides + * whether to + * write output to a window or stdout. stdout doesn't make sense on + * Windows + * non-console applications + */ + iflags.toptenwin = 1; + set_option_mod_status("toptenwin", SET_IN_FILE); + set_option_mod_status("perm_invent", SET_IN_FILE); - /* initialize map tiles bitmap */ - initMapTiles(); + /* initialize map tiles bitmap */ + initMapTiles(); - /* set tile-related options to readonly */ - set_wc_option_mod_status( - WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE, - DISP_IN_GAME); + /* set tile-related options to readonly */ + set_wc_option_mod_status(WC_TILE_WIDTH | WC_TILE_HEIGHT | WC_TILE_FILE, + DISP_IN_GAME); - /* set font-related options to change in the game */ - set_wc_option_mod_status( - WC_HILITE_PET | - WC_ALIGN_MESSAGE | - WC_ALIGN_STATUS | - WC_SCROLL_AMOUNT | - WC_SCROLL_MARGIN | - WC_MAP_MODE | - WC_FONT_MESSAGE | - WC_FONT_STATUS | - WC_FONT_MENU | - WC_FONT_TEXT | - WC_FONTSIZ_MESSAGE | - WC_FONTSIZ_STATUS | - WC_FONTSIZ_MENU | - WC_FONTSIZ_TEXT | - WC_VARY_MSGCOUNT, - SET_IN_GAME - ); + /* set font-related options to change in the game */ + set_wc_option_mod_status( + WC_HILITE_PET | WC_ALIGN_MESSAGE | WC_ALIGN_STATUS | WC_SCROLL_AMOUNT + | WC_SCROLL_MARGIN | WC_MAP_MODE | WC_FONT_MESSAGE + | WC_FONT_STATUS | WC_FONT_MENU | WC_FONT_TEXT + | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS | WC_FONTSIZ_MENU + | WC_FONTSIZ_TEXT | WC_VARY_MSGCOUNT, + SET_IN_GAME); - mswin_color_from_string(iflags.wc_foregrnd_menu, &menu_fg_brush, &menu_fg_color); - mswin_color_from_string(iflags.wc_foregrnd_message, &message_fg_brush, &message_fg_color); - mswin_color_from_string(iflags.wc_foregrnd_status, &status_fg_brush, &status_fg_color); - mswin_color_from_string(iflags.wc_foregrnd_text, &text_fg_brush, &text_fg_color); - mswin_color_from_string(iflags.wc_backgrnd_menu, &menu_bg_brush, &menu_bg_color); - mswin_color_from_string(iflags.wc_backgrnd_message, &message_bg_brush, &message_bg_color); - mswin_color_from_string(iflags.wc_backgrnd_status, &status_bg_brush, &status_bg_color); - mswin_color_from_string(iflags.wc_backgrnd_text, &text_bg_brush, &text_bg_color); + mswin_color_from_string(iflags.wc_foregrnd_menu, &menu_fg_brush, + &menu_fg_color); + mswin_color_from_string(iflags.wc_foregrnd_message, &message_fg_brush, + &message_fg_color); + mswin_color_from_string(iflags.wc_foregrnd_status, &status_fg_brush, + &status_fg_color); + mswin_color_from_string(iflags.wc_foregrnd_text, &text_fg_brush, + &text_fg_color); + mswin_color_from_string(iflags.wc_backgrnd_menu, &menu_bg_brush, + &menu_bg_color); + mswin_color_from_string(iflags.wc_backgrnd_message, &message_bg_brush, + &message_bg_color); + mswin_color_from_string(iflags.wc_backgrnd_status, &status_bg_brush, + &status_bg_color); + mswin_color_from_string(iflags.wc_backgrnd_text, &text_bg_brush, + &text_bg_color); - if (iflags.wc_splash_screen) mswin_display_splash_window(FALSE); - - iflags.window_inited = TRUE; + if (iflags.wc_splash_screen) + mswin_display_splash_window(FALSE); + + iflags.window_inited = TRUE; } - /* Do a window-port specific player type selection. If player_selection() offers a Quit option, it is its responsibility to clean up and terminate the process. You need to fill in pl_character[0]. */ -void mswin_player_selection(void) +void +mswin_player_selection(void) { - int nRole; + int nRole; - logDebug("mswin_player_selection()\n"); + logDebug("mswin_player_selection()\n"); - if (iflags.wc_player_selection == VIA_DIALOG) { - /* pick player type randomly (use pre-selected role/race/gender/alignment) */ - if( flags.randomall ) { - if (flags.initrole < 0) { - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - raw_print("Incompatible role!"); - flags.initrole = randrole(); - } - } + if (iflags.wc_player_selection == VIA_DIALOG) { + /* pick player type randomly (use pre-selected + * role/race/gender/alignment) */ + if (flags.randomall) { + if (flags.initrole < 0) { + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + raw_print("Incompatible role!"); + flags.initrole = randrole(); + } + } - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - raw_print("Incompatible race!"); - flags.initrace = randrace(flags.initrole); - } - } + if (flags.initrace < 0 + || !validrace(flags.initrole, flags.initrace)) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + raw_print("Incompatible race!"); + flags.initrace = randrace(flags.initrole); + } + } - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - raw_print("Incompatible gender!"); - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, + flags.initgend)) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + raw_print("Incompatible gender!"); + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - raw_print("Incompatible alignment!"); - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } - } else { - /* select a role */ - if( mswin_player_selection_window( &nRole ) == IDCANCEL ) { - bail(0); - } - } - } else { /* iflags.wc_player_selection == VIA_PROMPTS */ - prompt_for_player_selection(); - } + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, + flags.initalign)) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + raw_print("Incompatible alignment!"); + flags.initalign = + randalign(flags.initrole, flags.initrace); + } + } + } else { + /* select a role */ + if (mswin_player_selection_window(&nRole) == IDCANCEL) { + bail(0); + } + } + } else { /* iflags.wc_player_selection == VIA_PROMPTS */ + prompt_for_player_selection(); + } } -void prompt_for_player_selection(void) +void +prompt_for_player_selection(void) { - int i, k, n; - char pick4u = 'n', thisch, lastch = 0; - char pbuf[QBUFSZ], plbuf[QBUFSZ]; - winid win; - anything any; - menu_item *selected = 0; - DWORD box_result; + int i, k, n; + char pick4u = 'n', thisch, lastch = 0; + char pbuf[QBUFSZ], plbuf[QBUFSZ]; + winid win; + anything any; + menu_item *selected = 0; + DWORD box_result; - logDebug("prompt_for_player_selection()\n"); + logDebug("prompt_for_player_selection()\n"); - /* prevent an unnecessary prompt */ - rigid_role_checks(); + /* prevent an unnecessary prompt */ + rigid_role_checks(); - /* Should we randomly pick for the player? */ - if (!flags.randomall && - (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE || - flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { - /* int echoline; */ - char *prompt = build_plselection_prompt(pbuf, QBUFSZ, flags.initrole, - flags.initrace, flags.initgend, flags.initalign); + /* Should we randomly pick for the player? */ + if (!flags.randomall + && (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE + || flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) { + /* int echoline; */ + char *prompt = build_plselection_prompt( + pbuf, QBUFSZ, flags.initrole, flags.initrace, flags.initgend, + flags.initalign); - /* tty_putstr(BASE_WINDOW, 0, ""); */ - /* echoline = wins[BASE_WINDOW]->cury; */ - box_result = NHMessageBox(NULL, prompt, - MB_YESNOCANCEL | MB_DEFBUTTON1 | MB_ICONQUESTION); - pick4u = (box_result == IDYES) ? 'y' : (box_result == IDNO) ? 'n' : '\033'; - /* tty_putstr(BASE_WINDOW, 0, prompt); */ - do { - /* pick4u = lowc(readchar()); */ - if (index(quitchars, pick4u)) pick4u = 'y'; - } while(!index(ynqchars, pick4u)); - if ((int)strlen(prompt) + 1 < CO) { - /* Echo choice and move back down line */ - /* tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline, pick4u); */ - /* tty_putstr(BASE_WINDOW, 0, ""); */ - } else - /* Otherwise it's hard to tell where to echo, and things are - * wrapping a bit messily anyway, so (try to) make sure the next - * question shows up well and doesn't get wrapped at the - * bottom of the window. - */ - /* tty_clear_nhwindow(BASE_WINDOW) */ ; - - if (pick4u != 'y' && pick4u != 'n') { -give_up: /* Quit */ - if (selected) free((genericptr_t) selected); - bail((char *)0); - /*NOTREACHED*/ - return; - } - } + /* tty_putstr(BASE_WINDOW, 0, ""); */ + /* echoline = wins[BASE_WINDOW]->cury; */ + box_result = NHMessageBox(NULL, prompt, MB_YESNOCANCEL | MB_DEFBUTTON1 + | MB_ICONQUESTION); + pick4u = + (box_result == IDYES) ? 'y' : (box_result == IDNO) ? 'n' : '\033'; + /* tty_putstr(BASE_WINDOW, 0, prompt); */ + do { + /* pick4u = lowc(readchar()); */ + if (index(quitchars, pick4u)) + pick4u = 'y'; + } while (!index(ynqchars, pick4u)); + if ((int) strlen(prompt) + 1 < CO) { + /* Echo choice and move back down line */ + /* tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline, + * pick4u); */ + /* tty_putstr(BASE_WINDOW, 0, ""); */ + } else + /* Otherwise it's hard to tell where to echo, and things are + * wrapping a bit messily anyway, so (try to) make sure the next + * question shows up well and doesn't get wrapped at the + * bottom of the window. + */ + /* tty_clear_nhwindow(BASE_WINDOW) */; - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); + if (pick4u != 'y' && pick4u != 'n') { + give_up: /* Quit */ + if (selected) + free((genericptr_t) selected); + bail((char *) 0); + /*NOTREACHED*/ + return; + } + } - /* Select a role, if necessary */ - /* we'll try to be compatible with pre-selected race/gender/alignment, - * but may not succeed */ - if (flags.initrole < 0) { - char rolenamebuf[QBUFSZ]; - /* Process the choice */ - if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) { - /* Pick a random role */ - flags.initrole = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrole < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); */ - flags.initrole = randrole(); - } - } else { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Character's Role"); */ - /* Prompt for a role */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; roles[i].name.m; i++) { - if (ok_role(i, flags.initrace, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - thisch = lowc(roles[i].name.m[0]); - if (thisch == lastch) thisch = highc(thisch); - if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) { - if (flags.initgend == 1 && roles[i].name.f) - Strcpy(rolenamebuf, roles[i].name.f); - else - Strcpy(rolenamebuf, roles[i].name.m); - } else { - if (roles[i].name.f) { - Strcpy(rolenamebuf, roles[i].name.m); - Strcat(rolenamebuf, "/"); - Strcat(rolenamebuf, roles[i].name.f); - } else - Strcpy(rolenamebuf, roles[i].name.m); - } - add_menu(win, NO_GLYPH, &any, thisch, - 0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED); - lastch = thisch; - } - } - any.a_int = pick_role(flags.initrace, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrole()+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick a role for your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); - /* Process the choice */ - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + /* Select a role, if necessary */ + /* we'll try to be compatible with pre-selected race/gender/alignment, + * but may not succeed */ + if (flags.initrole < 0) { + char rolenamebuf[QBUFSZ]; + /* Process the choice */ + if (pick4u == 'y' || flags.initrole == ROLE_RANDOM + || flags.randomall) { + /* Pick a random role */ + flags.initrole = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrole < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible role!"); */ + flags.initrole = randrole(); + } + } else { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Character's Role"); */ + /* Prompt for a role */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; roles[i].name.m; i++) { + if (ok_role(i, flags.initrace, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + thisch = lowc(roles[i].name.m[0]); + if (thisch == lastch) + thisch = highc(thisch); + if (flags.initgend != ROLE_NONE + && flags.initgend != ROLE_RANDOM) { + if (flags.initgend == 1 && roles[i].name.f) + Strcpy(rolenamebuf, roles[i].name.f); + else + Strcpy(rolenamebuf, roles[i].name.m); + } else { + if (roles[i].name.f) { + Strcpy(rolenamebuf, roles[i].name.m); + Strcat(rolenamebuf, "/"); + Strcat(rolenamebuf, roles[i].name.f); + } else + Strcpy(rolenamebuf, roles[i].name.m); + } + add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE, + an(rolenamebuf), MENU_UNSELECTED); + lastch = thisch; + } + } + any.a_int = pick_role(flags.initrace, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrole() + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick a role for your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); - flags.initrole = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } - - /* Select a race, if necessary */ - /* force compatibility with role, try for compatibility with - * pre-selected gender/alignment */ - if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { - /* pre-selected race not valid */ - if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) { - flags.initrace = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM); - if (flags.initrace < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); */ - flags.initrace = randrace(flags.initrole); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid races */ - n = 0; /* number valid */ - k = 0; /* valid race */ - for (i = 0; races[i].noun; i++) { - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; races[i].noun; i++) { - if (validrace(flags.initrole, i)) { - n++; - k = i; - } - } - } + /* Process the choice */ + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Race"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; races[i].noun; i++) - if (ok_race(flags.initrole, i, flags.initgend, - flags.initalign)) { - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any, races[i].noun[0], - 0, ATR_NONE, races[i].noun, MENU_UNSELECTED); - } - any.a_int = pick_race(flags.initrole, flags.initgend, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randrace(flags.initrole)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the race of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + flags.initrole = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initrace = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } + /* Select a race, if necessary */ + /* force compatibility with role, try for compatibility with + * pre-selected gender/alignment */ + if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) { + /* pre-selected race not valid */ + if (pick4u == 'y' || flags.initrace == ROLE_RANDOM + || flags.randomall) { + flags.initrace = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM); + if (flags.initrace < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible race!"); */ + flags.initrace = randrace(flags.initrole); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid races */ + n = 0; /* number valid */ + k = 0; /* valid race */ + for (i = 0; races[i].noun; i++) { + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; races[i].noun; i++) { + if (validrace(flags.initrole, i)) { + n++; + k = i; + } + } + } - /* Select a gender, if necessary */ - /* force compatibility with role/race, try for compatibility with - * pre-selected alignment */ - if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace, - flags.initgend)) { - /* pre-selected gender not valid */ - if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) { - flags.initgend = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM); - if (flags.initgend < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */ - flags.initgend = randgend(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid genders */ - n = 0; /* number valid */ - k = 0; /* valid gender */ - for (i = 0; i < ROLE_GENDERS; i++) { - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_GENDERS; i++) { - if (validgend(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Race"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; races[i].noun; i++) + if (ok_race(flags.initrole, i, flags.initgend, + flags.initalign)) { + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0, + ATR_NONE, races[i].noun, MENU_UNSELECTED); + } + any.a_int = pick_race(flags.initrole, flags.initgend, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randrace(flags.initrole) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the race of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Gender"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; i < ROLE_GENDERS; i++) - if (ok_gend(flags.initrole, flags.initrace, i, - flags.initalign)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, genders[i].adj[0], - 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_gend(flags.initrole, flags.initrace, - flags.initalign, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randgend(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the gender of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initrace = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initgend = k; - } - (void) root_plselection_prompt(plbuf, QBUFSZ - 1, - flags.initrole, flags.initrace, flags.initgend, flags.initalign); - } + /* Select a gender, if necessary */ + /* force compatibility with role/race, try for compatibility with + * pre-selected alignment */ + if (flags.initgend < 0 + || !validgend(flags.initrole, flags.initrace, flags.initgend)) { + /* pre-selected gender not valid */ + if (pick4u == 'y' || flags.initgend == ROLE_RANDOM + || flags.randomall) { + flags.initgend = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM); + if (flags.initgend < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */ + flags.initgend = randgend(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid genders */ + n = 0; /* number valid */ + k = 0; /* valid gender */ + for (i = 0; i < ROLE_GENDERS; i++) { + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_GENDERS; i++) { + if (validgend(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } - /* Select an alignment, if necessary */ - /* force compatibility with role/race/gender */ - if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace, - flags.initalign)) { - /* pre-selected alignment not valid */ - if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) { - flags.initalign = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM); - if (flags.initalign < 0) { - /* tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */ - flags.initalign = randalign(flags.initrole, flags.initrace); - } - } else { /* pick4u == 'n' */ - /* Count the number of valid alignments */ - n = 0; /* number valid */ - k = 0; /* valid alignment */ - for (i = 0; i < ROLE_ALIGNS; i++) { - if (ok_align(flags.initrole, flags.initrace, flags.initgend, - i)) { - n++; - k = i; - } - } - if (n == 0) { - for (i = 0; i < ROLE_ALIGNS; i++) { - if (validalign(flags.initrole, flags.initrace, i)) { - n++; - k = i; - } - } - } + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Gender"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; i < ROLE_GENDERS; i++) + if (ok_gend(flags.initrole, flags.initrace, i, + flags.initalign)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, genders[i].adj[0], 0, + ATR_NONE, genders[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_gend(flags.initrole, flags.initrace, + flags.initalign, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randgend(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the gender of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ - /* Permit the user to pick, if there is more than one */ - if (n > 1) { - /* tty_clear_nhwindow(BASE_WINDOW); */ - /* tty_putstr(BASE_WINDOW, 0, "Choosing Alignment"); */ - win = create_nhwindow(NHW_MENU); - start_menu(win); - any = zeroany; /* zero out all bits */ - for (i = 0; i < ROLE_ALIGNS; i++) - if (ok_align(flags.initrole, flags.initrace, - flags.initgend, i)) { - any.a_int = i+1; - add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], - 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED); - } - any.a_int = pick_align(flags.initrole, flags.initrace, - flags.initgend, PICK_RANDOM)+1; - if (any.a_int == 0) /* must be non-zero */ - any.a_int = randalign(flags.initrole, flags.initrace)+1; - add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE, - "Random", MENU_UNSELECTED); - any.a_int = i+1; /* must be non-zero */ - add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE, - "Quit", MENU_UNSELECTED); - Sprintf(pbuf, "Pick the alignment of your %s", plbuf); - end_menu(win, pbuf); - n = select_menu(win, PICK_ONE, &selected); - destroy_nhwindow(win); - if (n != 1 || selected[0].item.a_int == any.a_int) - goto give_up; /* Selected quit */ + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initgend = k; + } + (void) root_plselection_prompt(plbuf, QBUFSZ - 1, flags.initrole, + flags.initrace, flags.initgend, + flags.initalign); + } - k = selected[0].item.a_int - 1; - free((genericptr_t) selected), selected = 0; - } - flags.initalign = k; - } - } - /* Success! */ - /* tty_display_nhwindow(BASE_WINDOW, FALSE); */ + /* Select an alignment, if necessary */ + /* force compatibility with role/race/gender */ + if (flags.initalign < 0 + || !validalign(flags.initrole, flags.initrace, flags.initalign)) { + /* pre-selected alignment not valid */ + if (pick4u == 'y' || flags.initalign == ROLE_RANDOM + || flags.randomall) { + flags.initalign = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM); + if (flags.initalign < 0) { + /* tty_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */ + flags.initalign = randalign(flags.initrole, flags.initrace); + } + } else { /* pick4u == 'n' */ + /* Count the number of valid alignments */ + n = 0; /* number valid */ + k = 0; /* valid alignment */ + for (i = 0; i < ROLE_ALIGNS; i++) { + if (ok_align(flags.initrole, flags.initrace, flags.initgend, + i)) { + n++; + k = i; + } + } + if (n == 0) { + for (i = 0; i < ROLE_ALIGNS; i++) { + if (validalign(flags.initrole, flags.initrace, i)) { + n++; + k = i; + } + } + } + + /* Permit the user to pick, if there is more than one */ + if (n > 1) { + /* tty_clear_nhwindow(BASE_WINDOW); */ + /* tty_putstr(BASE_WINDOW, 0, "Choosing Alignment"); */ + win = create_nhwindow(NHW_MENU); + start_menu(win); + any = zeroany; /* zero out all bits */ + for (i = 0; i < ROLE_ALIGNS; i++) + if (ok_align(flags.initrole, flags.initrace, + flags.initgend, i)) { + any.a_int = i + 1; + add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0, + ATR_NONE, aligns[i].adj, MENU_UNSELECTED); + } + any.a_int = pick_align(flags.initrole, flags.initrace, + flags.initgend, PICK_RANDOM) + 1; + if (any.a_int == 0) /* must be non-zero */ + any.a_int = randalign(flags.initrole, flags.initrace) + 1; + add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random", + MENU_UNSELECTED); + any.a_int = i + 1; /* must be non-zero */ + add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit", + MENU_UNSELECTED); + Sprintf(pbuf, "Pick the alignment of your %s", plbuf); + end_menu(win, pbuf); + n = select_menu(win, PICK_ONE, &selected); + destroy_nhwindow(win); + if (n != 1 || selected[0].item.a_int == any.a_int) + goto give_up; /* Selected quit */ + + k = selected[0].item.a_int - 1; + free((genericptr_t) selected), selected = 0; + } + flags.initalign = k; + } + } + /* Success! */ + /* tty_display_nhwindow(BASE_WINDOW, FALSE); */ } /* Ask the user for a player name. */ -void mswin_askname(void) +void +mswin_askname(void) { - logDebug("mswin_askname()\n"); + logDebug("mswin_askname()\n"); - if( mswin_getlin_window("Who are you?", plname, PL_NSIZ)==IDCANCEL ) { - bail("bye-bye"); - /* not reached */ - } + if (mswin_getlin_window("Who are you?", plname, PL_NSIZ) == IDCANCEL) { + bail("bye-bye"); + /* not reached */ + } } - /* Does window event processing (e.g. exposure events). A noop for the tty and X window-ports. */ -void mswin_get_nh_event(void) +void +mswin_get_nh_event(void) { - MSG msg; + MSG msg; - logDebug("mswin_get_nh_event()\n"); + logDebug("mswin_get_nh_event()\n"); - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)!=0 ) { - if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - return; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) { + if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + return; } /* Exits the window system. This should dismiss all windows, except the "window" used for raw_print(). str is printed if possible. */ -void mswin_exit_nhwindows(const char *str) +void +mswin_exit_nhwindows(const char *str) { - logDebug("mswin_exit_nhwindows(%s)\n", str); + logDebug("mswin_exit_nhwindows(%s)\n", str); /* Write Window settings to the registry */ mswin_write_reg(); - while (max_brush) - DeleteObject(brush_table[--max_brush]); + while (max_brush) + DeleteObject(brush_table[--max_brush]); } /* Prepare the window to be suspended. */ -void mswin_suspend_nhwindows(const char *str) +void +mswin_suspend_nhwindows(const char *str) { - logDebug("mswin_suspend_nhwindows(%s)\n", str); + logDebug("mswin_suspend_nhwindows(%s)\n", str); - return; + return; } - /* Restore the windows after being suspended. */ -void mswin_resume_nhwindows() +void +mswin_resume_nhwindows() { - logDebug("mswin_resume_nhwindows()\n"); + logDebug("mswin_resume_nhwindows()\n"); - return; + return; } -/* Create a window of type "type" which can be +/* Create a window of type "type" which can be NHW_MESSAGE (top line) NHW_STATUS (bottom lines) NHW_MAP (main dungeon) NHW_MENU (inventory or other "corner" windows) NHW_TEXT (help/text, full screen paged window) */ -winid +winid mswin_create_nhwindow(int type) { - winid i = 0; - MSNHMsgAddWnd data; + winid i = 0; + MSNHMsgAddWnd data; - logDebug("mswin_create_nhwindow(%d)\n", type); + logDebug("mswin_create_nhwindow(%d)\n", type); - /* Return the next available winid - */ + /* Return the next available winid + */ - for (i=1; iwindowlist[i].win == NULL && - !GetNHApp()->windowlist[i].dead) - break; - if (i == MAXWINDOWS) - panic ("ERROR: No windows available...\n"); + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].win == NULL + && !GetNHApp()->windowlist[i].dead) + break; + if (i == MAXWINDOWS) + panic("ERROR: No windows available...\n"); switch (type) { - case NHW_MAP: - { - GetNHApp()->windowlist[i].win = mswin_init_map_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_MESSAGE: - { - GetNHApp()->windowlist[i].win = mswin_init_message_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_STATUS: - { - GetNHApp()->windowlist[i].win = mswin_init_status_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - case NHW_MENU: - { - GetNHApp()->windowlist[i].win = NULL; //will create later - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 1; - break; - } - case NHW_TEXT: - { - GetNHApp()->windowlist[i].win = mswin_init_text_window(); - GetNHApp()->windowlist[i].type = type; - GetNHApp()->windowlist[i].dead = 0; - break; - } - } + case NHW_MAP: { + GetNHApp()->windowlist[i].win = mswin_init_map_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_MESSAGE: { + GetNHApp()->windowlist[i].win = mswin_init_message_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_STATUS: { + GetNHApp()->windowlist[i].win = mswin_init_status_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + case NHW_MENU: { + GetNHApp()->windowlist[i].win = NULL; // will create later + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 1; + break; + } + case NHW_TEXT: { + GetNHApp()->windowlist[i].win = mswin_init_text_window(); + GetNHApp()->windowlist[i].type = type; + GetNHApp()->windowlist[i].dead = 0; + break; + } + } - ZeroMemory(&data, sizeof(data) ); - data.wid = i; - SendMessage( GetNHApp()->hMainWnd, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ADDWND, (LPARAM)&data ); - return i; + ZeroMemory(&data, sizeof(data)); + data.wid = i; + SendMessage(GetNHApp()->hMainWnd, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ADDWND, (LPARAM) &data); + return i; } /* Clear the given window, when asked to. */ -void mswin_clear_nhwindow(winid wid) +void +mswin_clear_nhwindow(winid wid) { - logDebug("mswin_clear_nhwindow(%d)\n", wid); + logDebug("mswin_clear_nhwindow(%d)\n", wid); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - if( GetNHApp()->windowlist[wid].type == NHW_MAP ) { - if( Is_rogue_level(&u.uz) ) - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), ROGUE_LEVEL_MAP_MODE); - else - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), iflags.wc_map_mode); - } + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + if (GetNHApp()->windowlist[wid].type == NHW_MAP) { + if (Is_rogue_level(&u.uz)) + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), + ROGUE_LEVEL_MAP_MODE); + else + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), + iflags.wc_map_mode); + } - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLEAR_WINDOW, (LPARAM)NULL ); - } + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CLEAR_WINDOW, (LPARAM) NULL); + } } /* -- Display the window on the screen. If there is data @@ -833,93 +829,100 @@ void mswin_clear_nhwindow(winid wid) -- Calling display_nhwindow(WIN_MESSAGE,???) will do a --more--, if necessary, in the tty window-port. */ -void mswin_display_nhwindow(winid wid, BOOLEAN_P block) +void +mswin_display_nhwindow(winid wid, BOOLEAN_P block) { - logDebug("mswin_display_nhwindow(%d, %d)\n", wid, block); - if (GetNHApp()->windowlist[wid].win != NULL) - { - ShowWindow(GetNHApp()->windowlist[wid].win, SW_SHOW); - mswin_layout_main_window(GetNHApp()->windowlist[wid].win); - if (GetNHApp()->windowlist[wid].type == NHW_MENU) { - MENU_ITEM_P* p; - mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, PICK_NONE, &p, TRUE); - } if (GetNHApp()->windowlist[wid].type == NHW_TEXT) { - mswin_display_text_window(GetNHApp()->windowlist[wid].win); - } if (GetNHApp()->windowlist[wid].type == NHW_RIP) { - mswin_display_RIP_window(GetNHApp()->windowlist[wid].win); - } else { - if( !block ) { - UpdateWindow(GetNHApp()->windowlist[wid].win); - } else { - if ( GetNHApp()->windowlist[wid].type == NHW_MAP ) { - (void) mswin_nhgetch(); - } - } - } - SetFocus(GetNHApp()->hMainWnd); - } + logDebug("mswin_display_nhwindow(%d, %d)\n", wid, block); + if (GetNHApp()->windowlist[wid].win != NULL) { + ShowWindow(GetNHApp()->windowlist[wid].win, SW_SHOW); + mswin_layout_main_window(GetNHApp()->windowlist[wid].win); + if (GetNHApp()->windowlist[wid].type == NHW_MENU) { + MENU_ITEM_P *p; + mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, + PICK_NONE, &p, TRUE); + } + if (GetNHApp()->windowlist[wid].type == NHW_TEXT) { + mswin_display_text_window(GetNHApp()->windowlist[wid].win); + } + if (GetNHApp()->windowlist[wid].type == NHW_RIP) { + mswin_display_RIP_window(GetNHApp()->windowlist[wid].win); + } else { + if (!block) { + UpdateWindow(GetNHApp()->windowlist[wid].win); + } else { + if (GetNHApp()->windowlist[wid].type == NHW_MAP) { + (void) mswin_nhgetch(); + } + } + } + SetFocus(GetNHApp()->hMainWnd); + } } - -HWND mswin_hwnd_from_winid(winid wid) +HWND +mswin_hwnd_from_winid(winid wid) { - if( wid>=0 && widwindowlist[wid].win; - } else { - return NULL; - } + if (wid >= 0 && wid < MAXWINDOWS) { + return GetNHApp()->windowlist[wid].win; + } else { + return NULL; + } } -winid mswin_winid_from_handle(HWND hWnd) +winid +mswin_winid_from_handle(HWND hWnd) { - winid i = 0; + winid i = 0; - for (i=1; iwindowlist[i].win == hWnd) - return i; - return -1; + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].win == hWnd) + return i; + return -1; } -winid mswin_winid_from_type(int type) +winid +mswin_winid_from_type(int type) { - winid i = 0; + winid i = 0; - for (i=1; iwindowlist[i].type == type) - return i; - return -1; + for (i = 1; i < MAXWINDOWS; i++) + if (GetNHApp()->windowlist[i].type == type) + return i; + return -1; } -void mswin_window_mark_dead(winid wid) +void +mswin_window_mark_dead(winid wid) { - if( wid>=0 && widwindowlist[wid].win = NULL; - GetNHApp()->windowlist[wid].dead = 1; - } + if (wid >= 0 && wid < MAXWINDOWS) { + GetNHApp()->windowlist[wid].win = NULL; + GetNHApp()->windowlist[wid].dead = 1; + } } -/* Destroy will dismiss the window if the window has not +/* Destroy will dismiss the window if the window has not * already been dismissed. */ -void mswin_destroy_nhwindow(winid wid) +void +mswin_destroy_nhwindow(winid wid) { - logDebug("mswin_destroy_nhwindow(%d)\n", wid); + logDebug("mswin_destroy_nhwindow(%d)\n", wid); - if ((GetNHApp()->windowlist[wid].type == NHW_MAP) || - (GetNHApp()->windowlist[wid].type == NHW_MESSAGE) || - (GetNHApp()->windowlist[wid].type == NHW_STATUS)) { - /* main windows is going to take care of those */ - return; + if ((GetNHApp()->windowlist[wid].type == NHW_MAP) + || (GetNHApp()->windowlist[wid].type == NHW_MESSAGE) + || (GetNHApp()->windowlist[wid].type == NHW_STATUS)) { + /* main windows is going to take care of those */ + return; } if (wid != -1) { - if( !GetNHApp()->windowlist[wid].dead && - GetNHApp()->windowlist[wid].win != NULL ) - DestroyWindow(GetNHApp()->windowlist[wid].win); - GetNHApp()->windowlist[wid].win = NULL; - GetNHApp()->windowlist[wid].type = 0; - GetNHApp()->windowlist[wid].dead = 0; - } + if (!GetNHApp()->windowlist[wid].dead + && GetNHApp()->windowlist[wid].win != NULL) + DestroyWindow(GetNHApp()->windowlist[wid].win); + GetNHApp()->windowlist[wid].win = NULL; + GetNHApp()->windowlist[wid].type = 0; + GetNHApp()->windowlist[wid].dead = 0; + } } /* Next output to window will start at (x,y), also moves @@ -927,20 +930,18 @@ void mswin_destroy_nhwindow(winid wid) 1 <= x < cols, 0 <= y < rows, where cols and rows are the size of window. */ -void mswin_curs(winid wid, int x, int y) +void +mswin_curs(winid wid, int x, int y) { - logDebug("mswin_curs(%d, %d, %d)\n", wid, x, y); + logDebug("mswin_curs(%d, %d, %d)\n", wid, x, y); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgCursor data; - data.x = x; - data.y = y; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CURSOR, (LPARAM)&data ); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgCursor data; + data.x = x; + data.y = y; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CURSOR, (LPARAM) &data); } } @@ -967,81 +968,83 @@ Attributes then the second. In the tty port, pline() achieves this by calling more() or displaying both on the same line. */ -void mswin_putstr(winid wid, int attr, const char *text) +void +mswin_putstr(winid wid, int attr, const char *text) { - logDebug("mswin_putstr(%d, %d, %s)\n", wid, attr, text); - - mswin_putstr_ex(wid, attr, text, 0); + logDebug("mswin_putstr(%d, %d, %s)\n", wid, attr, text); + + mswin_putstr_ex(wid, attr, text, 0); } -void mswin_putstr_ex(winid wid, int attr, const char *text, int app) +void +mswin_putstr_ex(winid wid, int attr, const char *text, int app) { - if( (wid >= 0) && - (wid < MAXWINDOWS) ) - { - if( GetNHApp()->windowlist[wid].win==NULL && - GetNHApp()->windowlist[wid].type==NHW_MENU ) { - GetNHApp()->windowlist[wid].win = mswin_init_menu_window(MENU_TYPE_TEXT); - GetNHApp()->windowlist[wid].dead = 0; - } + if ((wid >= 0) && (wid < MAXWINDOWS)) { + if (GetNHApp()->windowlist[wid].win == NULL + && GetNHApp()->windowlist[wid].type == NHW_MENU) { + GetNHApp()->windowlist[wid].win = + mswin_init_menu_window(MENU_TYPE_TEXT); + GetNHApp()->windowlist[wid].dead = 0; + } - if (GetNHApp()->windowlist[wid].win != NULL) - { - MSNHMsgPutstr data; - ZeroMemory(&data, sizeof(data)); - data.attr = attr; - data.text = text; - data.append = app; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_PUTSTR, (LPARAM)&data ); - } + if (GetNHApp()->windowlist[wid].win != NULL) { + MSNHMsgPutstr data; + ZeroMemory(&data, sizeof(data)); + data.attr = attr; + data.text = text; + data.append = app; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_PUTSTR, (LPARAM) &data); + } /* yield a bit so it gets done immediately */ mswin_get_nh_event(); - } - else - { - // build text to display later in message box - GetNHApp()->saved_text = realloc(GetNHApp()->saved_text, strlen(text) + - strlen(GetNHApp()->saved_text) + 1); - strcat(GetNHApp()->saved_text, text); - } + } else { + // build text to display later in message box + GetNHApp()->saved_text = + realloc(GetNHApp()->saved_text, + strlen(text) + strlen(GetNHApp()->saved_text) + 1); + strcat(GetNHApp()->saved_text, text); + } } /* Display the file named str. Complain about missing files iff complain is TRUE. */ -void mswin_display_file(const char *filename,BOOLEAN_P must_exist) +void +mswin_display_file(const char *filename, BOOLEAN_P must_exist) { - dlb *f; - TCHAR wbuf[BUFSZ]; + dlb *f; + TCHAR wbuf[BUFSZ]; - logDebug("mswin_display_file(%s, %d)\n", filename, must_exist); + logDebug("mswin_display_file(%s, %d)\n", filename, must_exist); - f = dlb_fopen(filename, RDTMODE); - if (!f) { - if (must_exist) { - TCHAR message[90]; - _stprintf(message, TEXT("Warning! Could not find file: %s\n"), NH_A2W(filename, wbuf, sizeof(wbuf))); - NHMessageBox(GetNHApp()->hMainWnd, message, MB_OK | MB_ICONEXCLAMATION ); - } - } else { - winid text; - char line[LLEN]; + f = dlb_fopen(filename, RDTMODE); + if (!f) { + if (must_exist) { + TCHAR message[90]; + _stprintf(message, TEXT("Warning! Could not find file: %s\n"), + NH_A2W(filename, wbuf, sizeof(wbuf))); + NHMessageBox(GetNHApp()->hMainWnd, message, + MB_OK | MB_ICONEXCLAMATION); + } + } else { + winid text; + char line[LLEN]; - text = mswin_create_nhwindow(NHW_TEXT); + text = mswin_create_nhwindow(NHW_TEXT); - while (dlb_fgets(line, LLEN, f)) { - size_t len; - len = strlen(line); - if( line[len-1]=='\n' ) line[len-1]='\x0'; - mswin_putstr(text, ATR_NONE, line); - } - (void) dlb_fclose(f); + while (dlb_fgets(line, LLEN, f)) { + size_t len; + len = strlen(line); + if (line[len - 1] == '\n') + line[len - 1] = '\x0'; + mswin_putstr(text, ATR_NONE, line); + } + (void) dlb_fclose(f); - mswin_display_nhwindow(text, 1); - mswin_destroy_nhwindow(text); - } + mswin_display_nhwindow(text, 1); + mswin_destroy_nhwindow(text); + } } /* Start using window as a menu. You must call start_menu() @@ -1049,31 +1052,31 @@ void mswin_display_file(const char *filename,BOOLEAN_P must_exist) putstr() to the window. Only windows of type NHW_MENU may be used for menus. */ -void mswin_start_menu(winid wid) +void +mswin_start_menu(winid wid) { - logDebug("mswin_start_menu(%d)\n", wid); - if( (wid >= 0) && - (wid < MAXWINDOWS) ) { - if( GetNHApp()->windowlist[wid].win==NULL && - GetNHApp()->windowlist[wid].type==NHW_MENU ) { - GetNHApp()->windowlist[wid].win = mswin_init_menu_window(MENU_TYPE_MENU); - GetNHApp()->windowlist[wid].dead = 0; - } + logDebug("mswin_start_menu(%d)\n", wid); + if ((wid >= 0) && (wid < MAXWINDOWS)) { + if (GetNHApp()->windowlist[wid].win == NULL + && GetNHApp()->windowlist[wid].type == NHW_MENU) { + GetNHApp()->windowlist[wid].win = + mswin_init_menu_window(MENU_TYPE_MENU); + GetNHApp()->windowlist[wid].dead = 0; + } - if(GetNHApp()->windowlist[wid].win != NULL) { - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_STARTMENU, (LPARAM)NULL - ); - } - } + if (GetNHApp()->windowlist[wid].win != NULL) { + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_STARTMENU, (LPARAM) NULL); + } + } } /* add_menu(windid window, int glyph, const anything identifier, char accelerator, char groupacc, int attr, char *str, boolean preselected) - -- Add a text line str to the given menu window. If identifier + -- Add a text line str to the given menu window. If +identifier is 0, then the line cannot be selected (e.g. a title). Otherwise, identifier is the value returned if the line is selected. Accelerator is a keyboard key that can be used @@ -1100,32 +1103,29 @@ add_menu(windid window, int glyph, const anything identifier, -- If you want this choice to be preselected when the menu is displayed, set preselected to TRUE. */ -void mswin_add_menu(winid wid, int glyph, const ANY_P * identifier, - CHAR_P accelerator, CHAR_P group_accel, int attr, - const char *str, BOOLEAN_P presel) +void +mswin_add_menu(winid wid, int glyph, const ANY_P *identifier, + CHAR_P accelerator, CHAR_P group_accel, int attr, + const char *str, BOOLEAN_P presel) { - logDebug("mswin_add_menu(%d, %d, %p, %c, %c, %d, %s, %d)\n", - wid, glyph, identifier, (char)accelerator, (char)group_accel, - attr, str, presel); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgAddMenu data; - ZeroMemory(&data, sizeof(data)); - data.glyph = glyph; - data.identifier = identifier; - data.accelerator = accelerator; - data.group_accel = group_accel; - data.attr = attr; - data.str = str; - data.presel = presel; + logDebug("mswin_add_menu(%d, %d, %p, %c, %c, %d, %s, %d)\n", wid, glyph, + identifier, (char) accelerator, (char) group_accel, attr, str, + presel); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgAddMenu data; + ZeroMemory(&data, sizeof(data)); + data.glyph = glyph; + data.identifier = identifier; + data.accelerator = accelerator; + data.group_accel = group_accel; + data.attr = attr; + data.str = str; + data.presel = presel; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ADDMENU, (LPARAM)&data - ); - } + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ADDMENU, (LPARAM) &data); + } } /* @@ -1137,22 +1137,19 @@ end_menu(window, prompt) ** This probably shouldn't flush the window any more (if ** it ever did). That should be select_menu's job. -dean */ -void mswin_end_menu(winid wid, const char *prompt) +void +mswin_end_menu(winid wid, const char *prompt) { - logDebug("mswin_end_menu(%d, %s)\n", wid, prompt); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgEndMenu data; - ZeroMemory(&data, sizeof(data)); - data.text = prompt; + logDebug("mswin_end_menu(%d, %s)\n", wid, prompt); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgEndMenu data; + ZeroMemory(&data, sizeof(data)); + data.text = prompt; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ENDMENU, (LPARAM)&data - ); - } + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_ENDMENU, (LPARAM) &data); + } } /* @@ -1180,39 +1177,38 @@ int select_menu(windid window, int how, menu_item **selected) select_menu() will be called for the window at create_nhwindow() time. */ -int mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected) +int +mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected) { - int nReturned = -1; + int nReturned = -1; - logDebug("mswin_select_menu(%d, %d)\n", wid, how); + logDebug("mswin_select_menu(%d, %d)\n", wid, how); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - ShowWindow(GetNHApp()->windowlist[wid].win, SW_SHOW); - nReturned = mswin_menu_window_select_menu( - GetNHApp()->windowlist[wid].win, - how, - selected, - !(flags.perm_invent && wid==WIN_INVEN && how==PICK_NONE) /* don't activate inventory window if perm_invent is on */ - ); - } + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + ShowWindow(GetNHApp()->windowlist[wid].win, SW_SHOW); + nReturned = mswin_menu_window_select_menu( + GetNHApp()->windowlist[wid].win, how, selected, + !(flags.perm_invent && wid == WIN_INVEN + && how == PICK_NONE) /* don't activate inventory window if + perm_invent is on */ + ); + } return nReturned; } /* -- Indicate to the window port that the inventory has been changed. - -- Merely calls display_inventory() for window-ports that leave the - window up, otherwise empty. + -- Merely calls display_inventory() for window-ports that leave the + window up, otherwise empty. */ -void mswin_update_inventory() +void +mswin_update_inventory() { - logDebug("mswin_update_inventory()\n"); - if( flags.perm_invent && - program_state.something_worth_saving && - iflags.window_inited && - WIN_INVEN!=WIN_ERR ) display_inventory(NULL, FALSE); + logDebug("mswin_update_inventory()\n"); + if (flags.perm_invent && program_state.something_worth_saving + && iflags.window_inited && WIN_INVEN != WIN_ERR) + display_inventory(NULL, FALSE); } /* @@ -1220,9 +1216,10 @@ mark_synch() -- Don't go beyond this point in I/O on any channel until all channels are caught up to here. Can be an empty call for the moment */ -void mswin_mark_synch() +void +mswin_mark_synch() { - logDebug("mswin_mark_synch()\n"); + logDebug("mswin_mark_synch()\n"); } /* @@ -1231,9 +1228,10 @@ wait_synch() -- Wait until all pending output is complete (*flush*() for -- May also deal with exposure events etc. so that the display is OK when return from wait_synch(). */ -void mswin_wait_synch() +void +mswin_wait_synch() { - logDebug("mswin_wait_synch()\n"); + logDebug("mswin_wait_synch()\n"); } /* @@ -1241,22 +1239,20 @@ cliparound(x, y)-- Make sure that the user is more-or-less centered on the screen if the playing area is larger than the screen. -- This function is only defined if CLIPPING is defined. */ -void mswin_cliparound(int x, int y) +void +mswin_cliparound(int x, int y) { - winid wid = WIN_MAP; + winid wid = WIN_MAP; - logDebug("mswin_cliparound(%d, %d)\n", x, y); + logDebug("mswin_cliparound(%d, %d)\n", x, y); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgClipAround data; - data.x = x; - data.y = y; - SendMessage( - GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLIPAROUND, (LPARAM)&data ); + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgClipAround data; + data.x = x; + data.y = y; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CLIPAROUND, (LPARAM) &data); } } @@ -1267,23 +1263,22 @@ print_glyph(window, x, y, glyph) port wants (symbol, font, color, attributes, ...there's a 1-1 map between glyphs and distinct things on the map). */ -void mswin_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph) +void +mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph) { logDebug("mswin_print_glyph(%d, %d, %d, %d)\n", wid, x, y, glyph); - if ((wid >= 0) && - (wid < MAXWINDOWS) && - (GetNHApp()->windowlist[wid].win != NULL)) - { - MSNHMsgPrintGlyph data; + if ((wid >= 0) && (wid < MAXWINDOWS) + && (GetNHApp()->windowlist[wid].win != NULL)) { + MSNHMsgPrintGlyph data; - ZeroMemory(&data, sizeof(data) ); - data.x = x; - data.y = y; - data.glyph = glyph; - SendMessage( GetNHApp()->windowlist[wid].win, - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_PRINT_GLYPH, (LPARAM)&data ); - } + ZeroMemory(&data, sizeof(data)); + data.x = x; + data.y = y; + data.glyph = glyph; + SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_PRINT_GLYPH, (LPARAM) &data); + } } /* @@ -1295,17 +1290,20 @@ raw_print(str) -- Print directly to a screen, or otherwise guarantee that for error messages, and maybe other "msg" uses. E.g. updating status for micros (i.e, "saving"). */ -void mswin_raw_print(const char *str) +void +mswin_raw_print(const char *str) { - TCHAR wbuf[255]; + TCHAR wbuf[255]; logDebug("mswin_raw_print(%s)\n", str); - if( str && *str ) { - extern int redirect_stdout; - if (!redirect_stdout) - NHMessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), MB_ICONINFORMATION | MB_OK ); - else - fprintf(stdout,"%s",str); - } + if (str && *str) { + extern int redirect_stdout; + if (!redirect_stdout) + NHMessageBox(GetNHApp()->hMainWnd, + NH_A2W(str, wbuf, sizeof(wbuf)), + MB_ICONINFORMATION | MB_OK); + else + fprintf(stdout, "%s", str); + } } /* @@ -1313,12 +1311,14 @@ raw_print_bold(str) -- Like raw_print(), but prints in bold/standout (if possible). */ -void mswin_raw_print_bold(const char *str) +void +mswin_raw_print_bold(const char *str) { - TCHAR wbuf[255]; + TCHAR wbuf[255]; logDebug("mswin_raw_print_bold(%s)\n", str); - if( str && *str ) - NHMessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), MB_ICONINFORMATION | MB_OK ); + if (str && *str) + NHMessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), + MB_ICONINFORMATION | MB_OK); } /* @@ -1327,19 +1327,18 @@ int nhgetch() -- Returns a single character input from the user. will be the routine the OS provides to read a character. Returned character _must_ be non-zero. */ -int mswin_nhgetch() +int +mswin_nhgetch() { - PMSNHEvent event; + PMSNHEvent event; int key = 0; - logDebug("mswin_nhgetch()\n"); - + logDebug("mswin_nhgetch()\n"); - while( (event = mswin_input_pop()) == NULL || - event->type != NHEVENT_CHAR ) - mswin_main_loop(); + while ((event = mswin_input_pop()) == NULL || event->type != NHEVENT_CHAR) + mswin_main_loop(); - key = event->kbd.ch; + key = event->kbd.ch; return (key); } @@ -1351,40 +1350,44 @@ int nh_poskey(int *x, int *y, int *mod) a position in the MAP window is returned in x, y and mod. mod may be one of - CLICK_1 -- mouse click type 1 - CLICK_2 -- mouse click type 2 + CLICK_1 -- mouse click type 1 + CLICK_2 -- mouse click type 2 The different click types can map to whatever the hardware supports. If no mouse is supported, this routine always returns a non-zero character. */ -int mswin_nh_poskey(int *x, int *y, int *mod) +int +mswin_nh_poskey(int *x, int *y, int *mod) { - PMSNHEvent event; - int key; + PMSNHEvent event; + int key; - logDebug("mswin_nh_poskey()\n"); + logDebug("mswin_nh_poskey()\n"); - while( (event = mswin_input_pop())==NULL ) mswin_main_loop(); + while ((event = mswin_input_pop()) == NULL) + mswin_main_loop(); - if( event->type==NHEVENT_MOUSE ) { - *mod = event->ms.mod; - *x = event->ms.x; - *y = event->ms.y; - key = 0; - } else { - key = event->kbd.ch; - } - return (key); + if (event->type == NHEVENT_MOUSE) { + *mod = event->ms.mod; + *x = event->ms.x; + *y = event->ms.y; + key = 0; + } else { + key = event->kbd.ch; + } + return (key); } /* nhbell() -- Beep at user. [This will exist at least until sounds are - redone, since sounds aren't attributable to windows anyway.] + redone, since sounds aren't attributable to windows +anyway.] */ -void mswin_nhbell() +void +mswin_nhbell() { - logDebug("mswin_nhbell()\n"); + logDebug("mswin_nhbell()\n"); } /* @@ -1392,10 +1395,12 @@ doprev_message() -- Display previous messages. Used by the ^P command. -- On the tty-port this scrolls WIN_MESSAGE back one line. */ -int mswin_doprev_message() +int +mswin_doprev_message() { logDebug("mswin_doprev_message()\n"); - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, + MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); return 0; } @@ -1418,598 +1423,625 @@ char yn_function(const char *ques, const char *choices, char default) -- This uses the top line in the tty window-port, other ports might use a popup. */ -char mswin_yn_function(const char *question, const char *choices, - CHAR_P def) +char +mswin_yn_function(const char *question, const char *choices, CHAR_P def) { char ch; - char yn_esc_map='\033'; + char yn_esc_map = '\033'; char message[BUFSZ]; - char res_ch[2]; + char res_ch[2]; int createcaret; - boolean digit_ok, allow_num; + boolean digit_ok, allow_num; - logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); + logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); if (WIN_MESSAGE == WIN_ERR && choices == ynchars) { - char *text = realloc(strdup(GetNHApp()->saved_text), strlen(question) - + strlen(GetNHApp()->saved_text) + 1); + char *text = + realloc(strdup(GetNHApp()->saved_text), + strlen(question) + strlen(GetNHApp()->saved_text) + 1); DWORD box_result; strcat(text, question); - box_result = NHMessageBox(NULL, - NH_W2A(text, message, sizeof(message)), - MB_ICONQUESTION | MB_YESNOCANCEL | - ((def == 'y') ? MB_DEFBUTTON1 : - (def == 'n') ? MB_DEFBUTTON2 : MB_DEFBUTTON3)); + box_result = + NHMessageBox(NULL, NH_W2A(text, message, sizeof(message)), + MB_ICONQUESTION | MB_YESNOCANCEL + | ((def == 'y') ? MB_DEFBUTTON1 + : (def == 'n') ? MB_DEFBUTTON2 + : MB_DEFBUTTON3)); free(text); - GetNHApp()->saved_text = strdup(""); + GetNHApp()->saved_text = strdup(""); return box_result == IDYES ? 'y' : box_result == IDNO ? 'n' : '\033'; } if (choices) { - char *cb, choicebuf[QBUFSZ]; + char *cb, choicebuf[QBUFSZ]; - allow_num = (index(choices, '#') != 0); + allow_num = (index(choices, '#') != 0); - Strcpy(choicebuf, choices); - if ((cb = index(choicebuf, '\033')) != 0) { - /* anything beyond is hidden */ - *cb = '\0'; - } - (void)strncpy(message, question, QBUFSZ-1); - message[QBUFSZ-1] = '\0'; - sprintf(eos(message), " [%s]", choicebuf); - if (def) sprintf(eos(message), " (%c)", def); - Strcat(message, " "); - /* escape maps to 'q' or 'n' or default, in that order */ - yn_esc_map = (index(choices, 'q') ? 'q' : - (index(choices, 'n') ? 'n' : def)); + Strcpy(choicebuf, choices); + if ((cb = index(choicebuf, '\033')) != 0) { + /* anything beyond is hidden */ + *cb = '\0'; + } + (void) strncpy(message, question, QBUFSZ - 1); + message[QBUFSZ - 1] = '\0'; + sprintf(eos(message), " [%s]", choicebuf); + if (def) + sprintf(eos(message), " (%c)", def); + Strcat(message, " "); + /* escape maps to 'q' or 'n' or default, in that order */ + yn_esc_map = + (index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def)); } else { - Strcpy(message, question); - Strcat(message, " "); + Strcpy(message, question); + Strcat(message, " "); } createcaret = 1; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); mswin_clear_nhwindow(WIN_MESSAGE); mswin_putstr(WIN_MESSAGE, ATR_BOLD, message); /* Only here if main window is not present */ - ch = 0; + ch = 0; do { - ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); - ch=mswin_nhgetch(); - HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); - if (choices) ch = lowc(ch); - else break; /* If choices is NULL, all possible inputs are accepted and returned. */ + ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); + ch = mswin_nhgetch(); + HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); + if (choices) + ch = lowc(ch); + else + break; /* If choices is NULL, all possible inputs are accepted and + returned. */ - digit_ok = allow_num && digit(ch); - if (ch=='\033') { - if (index(choices, 'q')) - ch = 'q'; - else if (index(choices, 'n')) - ch = 'n'; - else - ch = def; - break; - } else if (index(quitchars, ch)) { - ch = def; - break; - } else if (!index(choices, ch) && !digit_ok) { - mswin_nhbell(); - ch = (char)0; - /* and try again... */ - } else if (ch == '#' || digit_ok) { - char z, digit_string[2]; - int n_len = 0; - long value = 0; - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, ("#"), 1); n_len++; - digit_string[1] = '\0'; - if (ch != '#') { - digit_string[0] = ch; - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1); n_len++; - value = ch - '0'; - ch = '#'; - } - do { /* loop until we get a non-digit */ - z = lowc(readchar()); - if (digit(z)) { - value = (10 * value) + (z - '0'); - if (value < 0) break; /* overflow: try again */ - digit_string[0] = z; - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1); - n_len++; - } else if (z == 'y' || index(quitchars, z)) { - if (z == '\033') value = -1; /* abort */ - z = '\n'; /* break */ - } else if (z == '\b') { - if (n_len <= 1) { value = -1; break; } - else { value /= 10; mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, -1); n_len--; } - } else { - value = -1; /* abort */ - mswin_nhbell(); - break; - } - } while (z != '\n'); - if (value > 0) yn_number = value; - else if (value == 0) ch = 'n'; /* 0 => "no" */ - else { /* remove number from top line, then try again */ - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, -n_len); n_len = 0; - ch = (char)0; - } - } - } while( !ch ); + digit_ok = allow_num && digit(ch); + if (ch == '\033') { + if (index(choices, 'q')) + ch = 'q'; + else if (index(choices, 'n')) + ch = 'n'; + else + ch = def; + break; + } else if (index(quitchars, ch)) { + ch = def; + break; + } else if (!index(choices, ch) && !digit_ok) { + mswin_nhbell(); + ch = (char) 0; + /* and try again... */ + } else if (ch == '#' || digit_ok) { + char z, digit_string[2]; + int n_len = 0; + long value = 0; + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, ("#"), 1); + n_len++; + digit_string[1] = '\0'; + if (ch != '#') { + digit_string[0] = ch; + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1); + n_len++; + value = ch - '0'; + ch = '#'; + } + do { /* loop until we get a non-digit */ + z = lowc(readchar()); + if (digit(z)) { + value = (10 * value) + (z - '0'); + if (value < 0) + break; /* overflow: try again */ + digit_string[0] = z; + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1); + n_len++; + } else if (z == 'y' || index(quitchars, z)) { + if (z == '\033') + value = -1; /* abort */ + z = '\n'; /* break */ + } else if (z == '\b') { + if (n_len <= 1) { + value = -1; + break; + } else { + value /= 10; + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, + -1); + n_len--; + } + } else { + value = -1; /* abort */ + mswin_nhbell(); + break; + } + } while (z != '\n'); + if (value > 0) + yn_number = value; + else if (value == 0) + ch = 'n'; /* 0 => "no" */ + else { /* remove number from top line, then try again */ + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, -n_len); + n_len = 0; + ch = (char) 0; + } + } + } while (!ch); createcaret = 0; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); - /* display selection in the message window */ - if( isprint(ch) && ch!='#' ) { - res_ch[0] = ch; - res_ch[1] = '\x0'; - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, res_ch, 1); - } + /* display selection in the message window */ + if (isprint(ch) && ch != '#') { + res_ch[0] = ch; + res_ch[1] = '\x0'; + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, res_ch, 1); + } return ch; } /* getlin(const char *ques, char *input) - -- Prints ques as a prompt and reads a single line of text, - up to a newline. The string entered is returned without the - newline. ESC is used to cancel, in which case the string - "\033\000" is returned. - -- getlin() must call flush_screen(1) before doing anything. - -- This uses the top line in the tty window-port, other - ports might use a popup. + -- Prints ques as a prompt and reads a single line of text, + up to a newline. The string entered is returned without the + newline. ESC is used to cancel, in which case the string + "\033\000" is returned. + -- getlin() must call flush_screen(1) before doing anything. + -- This uses the top line in the tty window-port, other + ports might use a popup. */ -void mswin_getlin(const char *question, char *input) +void +mswin_getlin(const char *question, char *input) { + logDebug("mswin_getlin(%s, %p)\n", question, input); - logDebug("mswin_getlin(%s, %p)\n", question, input); - - if (!iflags.wc_popup_dialog) - { + if (!iflags.wc_popup_dialog) { char c; int len; int done; int createcaret; createcaret = 1; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); - mswin_clear_nhwindow(WIN_MESSAGE); + mswin_clear_nhwindow(WIN_MESSAGE); mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, question, 0); mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, " ", 1); input[0] = '\0'; len = 0; ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); done = FALSE; - while (!done) - { + while (!done) { c = mswin_nhgetch(); - switch (c) - { - case VK_ESCAPE: - strcpy(input, "\033"); - done = TRUE; - break; - case '\n': - case '\r': - case -115: - done = TRUE; - break; - default: - if (input[0]) - mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, input, -len); - if (c == VK_BACK) { - if (len > 0) len--; - input[len] = '\0'; - } else { - - input[len++] = c; - input[len] = '\0'; - } - mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, input, 1); - break; + switch (c) { + case VK_ESCAPE: + strcpy(input, "\033"); + done = TRUE; + break; + case '\n': + case '\r': + case -115: + done = TRUE; + break; + default: + if (input[0]) + mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, input, -len); + if (c == VK_BACK) { + if (len > 0) + len--; + input[len] = '\0'; + } else { + input[len++] = c; + input[len] = '\0'; + } + mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, input, 1); + break; } } HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); createcaret = 0; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); - } - else - { - if( mswin_getlin_window(question, input, BUFSZ)==IDCANCEL ) { - strcpy(input, "\033"); - } + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); + } else { + if (mswin_getlin_window(question, input, BUFSZ) == IDCANCEL) { + strcpy(input, "\033"); + } } } /* int get_ext_cmd(void) - -- Get an extended command in a window-port specific way. - An index into extcmdlist[] is returned on a successful - selection, -1 otherwise. + -- Get an extended command in a window-port specific way. + An index into extcmdlist[] is returned on a successful + selection, -1 otherwise. */ -int mswin_get_ext_cmd() +int +mswin_get_ext_cmd() { - int ret; - logDebug("mswin_get_ext_cmd()\n"); + int ret; + logDebug("mswin_get_ext_cmd()\n"); - if (!iflags.wc_popup_dialog) - { + if (!iflags.wc_popup_dialog) { char c; char cmd[BUFSZ]; int i, len; int createcaret; createcaret = 1; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); cmd[0] = '\0'; i = -2; - mswin_clear_nhwindow(WIN_MESSAGE); + mswin_clear_nhwindow(WIN_MESSAGE); mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, "#", 0); len = 0; ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); - while (i == -2) - { + while (i == -2) { int oindex, com_index; c = mswin_nhgetch(); - switch (c) - { - case VK_ESCAPE: + switch (c) { + case VK_ESCAPE: + i = -1; + break; + case '\n': + case '\r': + case -115: + for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++) + if (!strcmpi(cmd, extcmdlist[i].ef_txt)) + break; + + if (extcmdlist[i].ef_txt == (char *) 0) { + pline("%s: unknown extended command.", cmd); i = -1; - break; - case '\n': - case '\r': - case -115: - for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) - if (!strcmpi(cmd, extcmdlist[i].ef_txt)) break; - - if (extcmdlist[i].ef_txt == (char *)0) { - pline("%s: unknown extended command.", cmd); - i = -1; + } + break; + default: + if (cmd[0]) + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, cmd, + -(int) strlen(cmd)); + if (c == VK_BACK) { + if (len > 0) + len--; + cmd[len] = '\0'; + } else { + cmd[len++] = c; + cmd[len] = '\0'; + /* Find a command with this prefix in extcmdlist */ + com_index = -1; + for (oindex = 0; extcmdlist[oindex].ef_txt != (char *) 0; + oindex++) { + if (!strncmpi(cmd, extcmdlist[oindex].ef_txt, len)) { + if (com_index == -1) /* no matches yet */ + com_index = oindex; + else + com_index = + -2; /* two matches, don't complete */ + } } - break; - default: - if (cmd[0]) - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, cmd, -(int)strlen(cmd)); - if (c == VK_BACK) - { - if (len > 0) len--; - cmd[len] = '\0'; + if (com_index >= 0) { + Strcpy(cmd, extcmdlist[com_index].ef_txt); } - else - { - - cmd[len++] = c; - cmd[len] = '\0'; - /* Find a command with this prefix in extcmdlist */ - com_index = -1; - for (oindex = 0; extcmdlist[oindex].ef_txt != (char *)0; oindex++) { - if (!strncmpi(cmd, extcmdlist[oindex].ef_txt, len)) { - if (com_index == -1) /* no matches yet */ - com_index = oindex; - else - com_index = -2; /* two matches, don't complete */ - } - } - if (com_index >= 0) { - Strcpy(cmd, extcmdlist[com_index].ef_txt); - } - } - mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, cmd, 1); - break; + } + mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, cmd, 1); + break; } } HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); createcaret = 0; - SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); - return i; - } - else - { - if(mswin_ext_cmd_window (&ret) == IDCANCEL) - return -1; - else - return ret; + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret); + return i; + } else { + if (mswin_ext_cmd_window(&ret) == IDCANCEL) + return -1; + else + return ret; } } - /* number_pad(state) - -- Initialize the number pad to the given state. + -- Initialize the number pad to the given state. */ -void mswin_number_pad(int state) +void +mswin_number_pad(int state) { /* Do Nothing */ - logDebug("mswin_number_pad(%d)\n", state); + logDebug("mswin_number_pad(%d)\n", state); } /* delay_output() -- Causes a visible delay of 50ms in the output. - Conceptually, this is similar to wait_synch() followed - by a nap(50ms), but allows asynchronous operation. + Conceptually, this is similar to wait_synch() followed + by a nap(50ms), but allows asynchronous operation. */ -void mswin_delay_output() +void +mswin_delay_output() { - logDebug("mswin_delay_output()\n"); - Sleep(50); + logDebug("mswin_delay_output()\n"); + Sleep(50); } -void mswin_change_color() -{ - logDebug("mswin_change_color()\n"); +void +mswin_change_color() +{ + logDebug("mswin_change_color()\n"); } -char *mswin_get_color_string() -{ - logDebug("mswin_get_color_string()\n"); - return( "" ); +char * +mswin_get_color_string() +{ + logDebug("mswin_get_color_string()\n"); + return (""); } /* start_screen() -- Only used on Unix tty ports, but must be declared for - completeness. Sets up the tty to work in full-screen - graphics mode. Look at win/tty/termcap.c for an - example. If your window-port does not need this function - just declare an empty function. + completeness. Sets up the tty to work in full-screen + graphics mode. Look at win/tty/termcap.c for an + example. If your window-port does not need this function + just declare an empty function. */ -void mswin_start_screen() +void +mswin_start_screen() { /* Do Nothing */ - logDebug("mswin_start_screen()\n"); + logDebug("mswin_start_screen()\n"); } /* end_screen() -- Only used on Unix tty ports, but must be declared for - completeness. The complement of start_screen(). + completeness. The complement of start_screen(). */ -void mswin_end_screen() +void +mswin_end_screen() { /* Do Nothing */ - logDebug("mswin_end_screen()\n"); + logDebug("mswin_end_screen()\n"); } /* outrip(winid, int, when) - -- The tombstone code. If you want the traditional code use - genl_outrip for the value and check the #if in rip.c. + -- The tombstone code. If you want the traditional code use + genl_outrip for the value and check the #if in rip.c. */ -#define STONE_LINE_LEN 16 -void mswin_outrip(winid wid, int how, time_t when) +#define STONE_LINE_LEN 16 +void +mswin_outrip(winid wid, int how, time_t when) { - char buf[BUFSZ]; - long year; + char buf[BUFSZ]; + long year; - logDebug("mswin_outrip(%d, %d, %ld)\n", wid, how, (long)when); - if ((wid >= 0) && (wid < MAXWINDOWS) ) { - DestroyWindow(GetNHApp()->windowlist[wid].win); - GetNHApp()->windowlist[wid].win = mswin_init_RIP_window(); - GetNHApp()->windowlist[wid].type = NHW_RIP; - GetNHApp()->windowlist[wid].dead = 0; - } + logDebug("mswin_outrip(%d, %d, %ld)\n", wid, how, (long) when); + if ((wid >= 0) && (wid < MAXWINDOWS)) { + DestroyWindow(GetNHApp()->windowlist[wid].win); + GetNHApp()->windowlist[wid].win = mswin_init_RIP_window(); + GetNHApp()->windowlist[wid].type = NHW_RIP; + GetNHApp()->windowlist[wid].dead = 0; + } - /* Put name on stone */ - Sprintf(buf, "%s", plname); - buf[STONE_LINE_LEN] = 0; - putstr(wid, 0, buf); + /* Put name on stone */ + Sprintf(buf, "%s", plname); + buf[STONE_LINE_LEN] = 0; + putstr(wid, 0, buf); - /* Put $ on stone */ - Sprintf(buf, "%ld Au", done_money); - buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */ - putstr(wid, 0, buf); + /* Put $ on stone */ + Sprintf(buf, "%ld Au", done_money); + buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */ + putstr(wid, 0, buf); - /* Put together death description */ - formatkiller(buf, sizeof buf, how); + /* Put together death description */ + formatkiller(buf, sizeof buf, how); - /* Put death type on stone */ - putstr(wid, 0, buf); + /* Put death type on stone */ + putstr(wid, 0, buf); - /* Put year on stone */ - year = yyyymmdd(when) / 10000L; - Sprintf(buf, "%4ld", year); - putstr(wid, 0, buf); - mswin_finish_rip_text(wid); + /* Put year on stone */ + year = yyyymmdd(when) / 10000L; + Sprintf(buf, "%4ld", year); + putstr(wid, 0, buf); + mswin_finish_rip_text(wid); } /* handle options updates here */ -void mswin_preference_update(const char *pref) +void +mswin_preference_update(const char *pref) { - HDC hdc; - int i; - - if( stricmp( pref, "font_menu")==0 || - stricmp( pref, "font_size_menu")==0 ) { - if( iflags.wc_fontsiz_menuNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; + HDC hdc; + int i; - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_MENU, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + if (stricmp(pref, "font_menu") == 0 + || stricmp(pref, "font_size_menu") == 0) { + if (iflags.wc_fontsiz_menu < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_menu > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE; - mswin_layout_main_window(NULL); - return; - } + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_MENU, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - if( stricmp( pref, "font_status")==0 || - stricmp( pref, "font_size_status")==0 ) { + mswin_layout_main_window(NULL); + return; + } - if( iflags.wc_fontsiz_statusNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; + if (stricmp(pref, "font_status") == 0 + || stricmp(pref, "font_size_status") == 0) { + if (iflags.wc_fontsiz_status < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_status > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE; - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_STATUS, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_STATUS, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - for (i=1; iwindowlist[i].type == NHW_STATUS - && GetNHApp()->windowlist[i].win != NULL) { - InvalidateRect(GetNHApp()->windowlist[i].win, NULL, TRUE); - } - } - mswin_layout_main_window(NULL); - return; - } + for (i = 1; i < MAXWINDOWS; i++) { + if (GetNHApp()->windowlist[i].type == NHW_STATUS + && GetNHApp()->windowlist[i].win != NULL) { + InvalidateRect(GetNHApp()->windowlist[i].win, NULL, TRUE); + } + } + mswin_layout_main_window(NULL); + return; + } - if( stricmp( pref, "font_message")==0 || - stricmp( pref, "font_size_message")==0 ) { + if (stricmp(pref, "font_message") == 0 + || stricmp(pref, "font_size_message") == 0) { + if (iflags.wc_fontsiz_message < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_message > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; - if( iflags.wc_fontsiz_messageNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE; + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); + mswin_layout_main_window(NULL); + return; + } - InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); - mswin_layout_main_window(NULL); - return; - } + if (stricmp(pref, "font_text") == 0 + || stricmp(pref, "font_size_text") == 0) { + if (iflags.wc_fontsiz_text < NHFONT_SIZE_MIN + || iflags.wc_fontsiz_text > NHFONT_SIZE_MAX) + iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; - if( stricmp( pref, "font_text")==0 || - stricmp( pref, "font_size_text")==0 ) { + hdc = GetDC(GetNHApp()->hMainWnd); + mswin_get_font(NHW_TEXT, ATR_NONE, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_BOLD, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_DIM, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_ULINE, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_BLINK, hdc, TRUE); + mswin_get_font(NHW_TEXT, ATR_INVERSE, hdc, TRUE); + ReleaseDC(GetNHApp()->hMainWnd, hdc); - if( iflags.wc_fontsiz_textNHFONT_SIZE_MAX ) - iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE; + mswin_layout_main_window(NULL); + return; + } - hdc = GetDC(GetNHApp()->hMainWnd); - mswin_get_font(NHW_TEXT, ATR_NONE, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_BOLD, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_DIM, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_ULINE, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_BLINK, hdc, TRUE); - mswin_get_font(NHW_TEXT, ATR_INVERSE, hdc, TRUE); - ReleaseDC(GetNHApp()->hMainWnd, hdc); + if (stricmp(pref, "scroll_amount") == 0) { + mswin_cliparound(u.ux, u.uy); + return; + } - mswin_layout_main_window(NULL); - return; - } + if (stricmp(pref, "scroll_margin") == 0) { + mswin_cliparound(u.ux, u.uy); + return; + } - if( stricmp( pref, "scroll_amount")==0 ) { - mswin_cliparound(u.ux, u.uy); - return; - } + if (stricmp(pref, "map_mode") == 0) { + mswin_select_map_mode(iflags.wc_map_mode); + return; + } - if( stricmp( pref, "scroll_margin")==0 ) { - mswin_cliparound(u.ux, u.uy); - return; - } + if (stricmp(pref, "hilite_pet") == 0) { + InvalidateRect(mswin_hwnd_from_winid(WIN_MAP), NULL, TRUE); + return; + } - if( stricmp( pref, "map_mode")==0 ) { - mswin_select_map_mode( iflags.wc_map_mode ); - return; - } - - if( stricmp( pref, "hilite_pet")==0 ) { - InvalidateRect(mswin_hwnd_from_winid(WIN_MAP), NULL, TRUE); - return; - } - - if( stricmp( pref, "align_message")==0 || - stricmp( pref, "align_status")==0 ) { - mswin_layout_main_window(NULL); - return; - } - - if( stricmp( pref, "vary_msgcount")==0 ) { - InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); - mswin_layout_main_window(NULL); - return; - } + if (stricmp(pref, "align_message") == 0 + || stricmp(pref, "align_status") == 0) { + mswin_layout_main_window(NULL); + return; + } + if (stricmp(pref, "vary_msgcount") == 0) { + InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); + mswin_layout_main_window(NULL); + return; + } } #define TEXT_BUFFER_SIZE 4096 -char *mswin_getmsghistory(BOOLEAN_P init) +char * +mswin_getmsghistory(BOOLEAN_P init) { - static PMSNHMsgGetText text = 0; - static char* next_message = 0; + static PMSNHMsgGetText text = 0; + static char *next_message = 0; - if( init ) { - text = (PMSNHMsgGetText)malloc(sizeof(MSNHMsgGetText) + TEXT_BUFFER_SIZE); - text->max_size = TEXT_BUFFER_SIZE-1; /* make sure we always have 0 at the end of the buffer */ + if (init) { + text = (PMSNHMsgGetText) malloc(sizeof(MSNHMsgGetText) + + TEXT_BUFFER_SIZE); + text->max_size = + TEXT_BUFFER_SIZE + - 1; /* make sure we always have 0 at the end of the buffer */ - ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); - SendMessage( mswin_hwnd_from_winid(WIN_MESSAGE), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_GETTEXT, (LPARAM)text ); - - next_message = text->buffer; - } + ZeroMemory(text->buffer, TEXT_BUFFER_SIZE); + SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_GETTEXT, (LPARAM) text); - if( !(next_message && next_message[0]) ) { - free(text); - next_message = 0; - return (char*)0; - } else { - char* retval = next_message; - char* p; - next_message = p = strchr(next_message, '\n'); - if( next_message ) next_message++; - if( p ) while( p>=retval && isspace(*p) ) *p-- = (char)0; /* delete trailing whitespace */ - return retval; - } + next_message = text->buffer; + } + + if (!(next_message && next_message[0])) { + free(text); + next_message = 0; + return (char *) 0; + } else { + char *retval = next_message; + char *p; + next_message = p = strchr(next_message, '\n'); + if (next_message) + next_message++; + if (p) + while (p >= retval && isspace(*p)) + *p-- = (char) 0; /* delete trailing whitespace */ + return retval; + } } -void mswin_putmsghistory(const char * msg, BOOLEAN_P restoring) +void +mswin_putmsghistory(const char *msg, BOOLEAN_P restoring) { - BOOL save_sound_opt; + BOOL save_sound_opt; - UNREFERENCED_PARAMETER(restoring); + UNREFERENCED_PARAMETER(restoring); - if (!msg) return; /* end of message history restore */ - save_sound_opt = GetNHApp()->bNoSounds; - GetNHApp()->bNoSounds = TRUE; /* disable sounds while restoring message history */ - mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, msg, 0); - clear_nhwindow(WIN_MESSAGE); /* it is in fact end-of-turn indication so each message will print on the new line */ - GetNHApp()->bNoSounds = save_sound_opt; /* restore sounds option */ + if (!msg) + return; /* end of message history restore */ + save_sound_opt = GetNHApp()->bNoSounds; + GetNHApp()->bNoSounds = + TRUE; /* disable sounds while restoring message history */ + mswin_putstr_ex(WIN_MESSAGE, ATR_NONE, msg, 0); + clear_nhwindow(WIN_MESSAGE); /* it is in fact end-of-turn indication so + each message will print on the new line */ + GetNHApp()->bNoSounds = save_sound_opt; /* restore sounds option */ } -void mswin_main_loop() +void +mswin_main_loop() { - MSG msg; + MSG msg; - while( !mswin_have_input() && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if (GetNHApp()->regNetHackMode || - !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + while (!mswin_have_input() && GetMessage(&msg, NULL, 0, 0) != 0) { + if (GetNHApp()->regNetHackMode + || !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, + &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } } /* clean up and quit */ -void bail(const char *mesg) +void +bail(const char *mesg) { clearlocks(); mswin_exit_nhwindows(mesg); @@ -2017,145 +2049,142 @@ void bail(const char *mesg) /*NOTREACHED*/ } -BOOL initMapTiles(void) +BOOL +initMapTiles(void) { - HBITMAP hBmp; - BITMAP bm; - TCHAR wbuf[MAX_PATH]; - int tl_num; - SIZE map_size; - extern int total_tiles_used; + HBITMAP hBmp; + BITMAP bm; + TCHAR wbuf[MAX_PATH]; + int tl_num; + SIZE map_size; + extern int total_tiles_used; - /* no file - no tile */ - if( !(iflags.wc_tile_file && *iflags.wc_tile_file) ) - return TRUE; + /* no file - no tile */ + if (!(iflags.wc_tile_file && *iflags.wc_tile_file)) + return TRUE; - /* load bitmap */ - hBmp = LoadImage( - GetNHApp()->hApp, - NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH), - IMAGE_BITMAP, - 0, - 0, - LR_LOADFROMFILE | LR_DEFAULTSIZE - ); - if( hBmp==NULL ) { - raw_print("Cannot load tiles from the file. Reverting back to default."); - return FALSE; - } + /* load bitmap */ + hBmp = LoadImage(GetNHApp()->hApp, + NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH), + IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE); + if (hBmp == NULL) { + raw_print( + "Cannot load tiles from the file. Reverting back to default."); + return FALSE; + } - /* calculate tile dimensions */ - GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bm); - if( bm.bmWidth%iflags.wc_tile_width || - bm.bmHeight%iflags.wc_tile_height ) { - DeleteObject(hBmp); - raw_print("Tiles bitmap does not match tile_width and tile_height options. Reverting back to default."); - return FALSE; - } + /* calculate tile dimensions */ + GetObject(hBmp, sizeof(BITMAP), (LPVOID) &bm); + if (bm.bmWidth % iflags.wc_tile_width + || bm.bmHeight % iflags.wc_tile_height) { + DeleteObject(hBmp); + raw_print("Tiles bitmap does not match tile_width and tile_height " + "options. Reverting back to default."); + return FALSE; + } - tl_num = (bm.bmWidth/iflags.wc_tile_width)* - (bm.bmHeight/iflags.wc_tile_height); - if( tl_numbmpMapTiles!=GetNHApp()->bmpTiles ) { - DeleteObject(GetNHApp()->bmpMapTiles); - } + /* set the tile information */ + if (GetNHApp()->bmpMapTiles != GetNHApp()->bmpTiles) { + DeleteObject(GetNHApp()->bmpMapTiles); + } - GetNHApp()->bmpMapTiles = hBmp; - GetNHApp()->mapTile_X = iflags.wc_tile_width; - GetNHApp()->mapTile_Y = iflags.wc_tile_height; - GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; + GetNHApp()->bmpMapTiles = hBmp; + GetNHApp()->mapTile_X = iflags.wc_tile_width; + GetNHApp()->mapTile_Y = iflags.wc_tile_height; + GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; - map_size.cx = GetNHApp()->mapTile_X * COLNO; - map_size.cy = GetNHApp()->mapTile_Y * ROWNO; - mswin_map_stretch( - mswin_hwnd_from_winid(WIN_MAP), - &map_size, - TRUE - ); - return TRUE; + map_size.cx = GetNHApp()->mapTile_X * COLNO; + map_size.cy = GetNHApp()->mapTile_Y * ROWNO; + mswin_map_stretch(mswin_hwnd_from_winid(WIN_MAP), &map_size, TRUE); + return TRUE; } -void mswin_popup_display(HWND hWnd, int* done_indicator) +void +mswin_popup_display(HWND hWnd, int *done_indicator) { - MSG msg; - HWND hChild; - HMENU hMenu; - int mi_count; - int i; + MSG msg; + HWND hChild; + HMENU hMenu; + int mi_count; + int i; - /* activate the menu window */ - GetNHApp()->hPopupWnd = hWnd; + /* activate the menu window */ + GetNHApp()->hPopupWnd = hWnd; - mswin_layout_main_window(hWnd); + mswin_layout_main_window(hWnd); - /* disable game windows */ - for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD); - hChild; - hChild = GetWindow(hChild, GW_HWNDNEXT) ) { - if( hChild!= hWnd) EnableWindow(hChild, FALSE); - } + /* disable game windows */ + for (hChild = GetWindow(GetNHApp()->hMainWnd, GW_CHILD); hChild; + hChild = GetWindow(hChild, GW_HWNDNEXT)) { + if (hChild != hWnd) + EnableWindow(hChild, FALSE); + } - /* disable menu */ - hMenu = GetMenu( GetNHApp()->hMainWnd ); - mi_count = GetMenuItemCount( hMenu ); - for( i=0; ihMainWnd ); + /* disable menu */ + hMenu = GetMenu(GetNHApp()->hMainWnd); + mi_count = GetMenuItemCount(hMenu); + for (i = 0; i < mi_count; i++) { + EnableMenuItem(hMenu, i, MF_BYPOSITION | MF_GRAYED); + } + DrawMenuBar(GetNHApp()->hMainWnd); - /* bring menu window on top */ - SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); - SetFocus(hWnd); + /* bring menu window on top */ + SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + SetFocus(hWnd); - /* go into message loop */ - while( IsWindow(hWnd) && - (done_indicator==NULL || !*done_indicator) && - GetMessage(&msg, NULL, 0, 0)!=0 ) { - if( !IsDialogMessage(hWnd, &msg) ) { - if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - } + /* go into message loop */ + while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator) + && GetMessage(&msg, NULL, 0, 0) != 0) { + if (!IsDialogMessage(hWnd, &msg)) { + if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, + &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } } -void mswin_popup_destroy(HWND hWnd) +void +mswin_popup_destroy(HWND hWnd) { - HWND hChild; - HMENU hMenu; - int mi_count; - int i; + HWND hChild; + HMENU hMenu; + int mi_count; + int i; - /* enable game windows */ - for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD); - hChild; - hChild = GetWindow(hChild, GW_HWNDNEXT) ) { - if( hChild!= hWnd) { - EnableWindow(hChild, TRUE); - } - } + /* enable game windows */ + for (hChild = GetWindow(GetNHApp()->hMainWnd, GW_CHILD); hChild; + hChild = GetWindow(hChild, GW_HWNDNEXT)) { + if (hChild != hWnd) { + EnableWindow(hChild, TRUE); + } + } - /* enable menu */ - hMenu = GetMenu( GetNHApp()->hMainWnd ); - mi_count = GetMenuItemCount( hMenu ); - for( i=0; ihMainWnd ); + /* enable menu */ + hMenu = GetMenu(GetNHApp()->hMainWnd); + mi_count = GetMenuItemCount(hMenu); + for (i = 0; i < mi_count; i++) { + EnableMenuItem(hMenu, i, MF_BYPOSITION | MF_ENABLED); + } + DrawMenuBar(GetNHApp()->hMainWnd); - ShowWindow(hWnd, SW_HIDE); - GetNHApp()->hPopupWnd = NULL; + ShowWindow(hWnd, SW_HIDE); + GetNHApp()->hPopupWnd = NULL; - mswin_layout_main_window(hWnd); + mswin_layout_main_window(hWnd); - SetFocus(GetNHApp()->hMainWnd ); + SetFocus(GetNHApp()->hMainWnd); } #ifdef _DEBUG @@ -2164,63 +2193,63 @@ void mswin_popup_destroy(HWND hWnd) void logDebug(const char *fmt, ...) { - FILE *dfp; + FILE *dfp; - if (!showdebug(NHTRACE_LOG)) return; + if (!showdebug(NHTRACE_LOG)) + return; - dfp = fopen(NHTRACE_LOG, "a"); - if (dfp) { - va_list args; + dfp = fopen(NHTRACE_LOG, "a"); + if (dfp) { + va_list args; - va_start(args, fmt); - vfprintf(dfp, fmt, args); - va_end(args); - fclose(dfp); - } + va_start(args, fmt); + vfprintf(dfp, fmt, args); + va_end(args); + fclose(dfp); + } } #endif - /* Reading and writing settings from the registry. */ -#define CATEGORYKEY "Software" -#define COMPANYKEY "NetHack" -#define PRODUCTKEY "NetHack 3.6.0" -#define SETTINGSKEY "Settings" -#define MAINSHOWSTATEKEY "MainShowState" -#define MAINMINXKEY "MainMinX" -#define MAINMINYKEY "MainMinY" -#define MAINMAXXKEY "MainMaxX" -#define MAINMAXYKEY "MainMaxY" -#define MAINLEFTKEY "MainLeft" -#define MAINRIGHTKEY "MainRight" -#define MAINTOPKEY "MainTop" -#define MAINBOTTOMKEY "MainBottom" -#define MAINAUTOLAYOUT "AutoLayout" -#define MAPLEFT "MapLeft" -#define MAPRIGHT "MapRight" -#define MAPTOP "MapTop" -#define MAPBOTTOM "MapBottom" -#define MSGLEFT "MsgLeft" -#define MSGRIGHT "MsgRight" -#define MSGTOP "MsgTop" -#define MSGBOTTOM "MsgBottom" -#define STATUSLEFT "StatusLeft" -#define STATUSRIGHT "StatusRight" -#define STATUSTOP "StatusTop" -#define STATUSBOTTOM "StatusBottom" -#define MENULEFT "MenuLeft" -#define MENURIGHT "MenuRight" -#define MENUTOP "MenuTop" -#define MENUBOTTOM "MenuBottom" -#define TEXTLEFT "TextLeft" -#define TEXTRIGHT "TextRight" -#define TEXTTOP "TextTop" -#define TEXTBOTTOM "TextBottom" -#define INVENTLEFT "InventLeft" -#define INVENTRIGHT "InventRight" -#define INVENTTOP "InventTop" -#define INVENTBOTTOM "InventBottom" +#define CATEGORYKEY "Software" +#define COMPANYKEY "NetHack" +#define PRODUCTKEY "NetHack 3.6.0" +#define SETTINGSKEY "Settings" +#define MAINSHOWSTATEKEY "MainShowState" +#define MAINMINXKEY "MainMinX" +#define MAINMINYKEY "MainMinY" +#define MAINMAXXKEY "MainMaxX" +#define MAINMAXYKEY "MainMaxY" +#define MAINLEFTKEY "MainLeft" +#define MAINRIGHTKEY "MainRight" +#define MAINTOPKEY "MainTop" +#define MAINBOTTOMKEY "MainBottom" +#define MAINAUTOLAYOUT "AutoLayout" +#define MAPLEFT "MapLeft" +#define MAPRIGHT "MapRight" +#define MAPTOP "MapTop" +#define MAPBOTTOM "MapBottom" +#define MSGLEFT "MsgLeft" +#define MSGRIGHT "MsgRight" +#define MSGTOP "MsgTop" +#define MSGBOTTOM "MsgBottom" +#define STATUSLEFT "StatusLeft" +#define STATUSRIGHT "StatusRight" +#define STATUSTOP "StatusTop" +#define STATUSBOTTOM "StatusBottom" +#define MENULEFT "MenuLeft" +#define MENURIGHT "MenuRight" +#define MENUTOP "MenuTop" +#define MENUBOTTOM "MenuBottom" +#define TEXTLEFT "TextLeft" +#define TEXTRIGHT "TextRight" +#define TEXTTOP "TextTop" +#define TEXTBOTTOM "TextBottom" +#define INVENTLEFT "InventLeft" +#define INVENTRIGHT "InventRight" +#define INVENTTOP "InventTop" +#define INVENTBOTTOM "InventBottom" /* #define all the subkeys here */ #define INTFKEY "Interface" @@ -2230,79 +2259,81 @@ mswin_read_reg() { HKEY key; DWORD size; - DWORD safe_buf; + DWORD safe_buf; char keystring[MAX_PATH]; - sprintf(keystring, "%s\\%s\\%s\\%s", - CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY); + sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY, + SETTINGSKEY); - /* Set the defaults here. The very first time the app is started, nothing is + /* Set the defaults here. The very first time the app is started, nothing + is read from the registry, so these defaults apply. */ - GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */ + GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */ GetNHApp()->regNetHackMode = 0; - if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key) - != ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key) + != ERROR_SUCCESS) return; size = sizeof(DWORD); -#define NHGETREG_DWORD(name, val) \ - RegQueryValueEx(key, (name), 0, NULL, (unsigned char *)(&safe_buf), &size); (val) = safe_buf; +#define NHGETREG_DWORD(name, val) \ + RegQueryValueEx(key, (name), 0, NULL, (unsigned char *)(&safe_buf), \ + &size); \ + (val) = safe_buf; - /* read the keys here */ - NHGETREG_DWORD(INTFKEY, GetNHApp()->regNetHackMode); + /* read the keys here */ + NHGETREG_DWORD(INTFKEY, GetNHApp()->regNetHackMode); - /* read window placement */ - NHGETREG_DWORD(MAINSHOWSTATEKEY, GetNHApp()->regMainShowState); - NHGETREG_DWORD(MAINMINXKEY, GetNHApp()->regMainMinX); - NHGETREG_DWORD(MAINMINYKEY, GetNHApp()->regMainMinY); - NHGETREG_DWORD(MAINMAXXKEY, GetNHApp()->regMainMaxX); - NHGETREG_DWORD(MAINMAXYKEY, GetNHApp()->regMainMaxY); - NHGETREG_DWORD(MAINLEFTKEY, GetNHApp()->regMainLeft); - NHGETREG_DWORD(MAINRIGHTKEY, GetNHApp()->regMainRight); - NHGETREG_DWORD(MAINTOPKEY, GetNHApp()->regMainTop); - NHGETREG_DWORD(MAINBOTTOMKEY, GetNHApp()->regMainBottom); + /* read window placement */ + NHGETREG_DWORD(MAINSHOWSTATEKEY, GetNHApp()->regMainShowState); + NHGETREG_DWORD(MAINMINXKEY, GetNHApp()->regMainMinX); + NHGETREG_DWORD(MAINMINYKEY, GetNHApp()->regMainMinY); + NHGETREG_DWORD(MAINMAXXKEY, GetNHApp()->regMainMaxX); + NHGETREG_DWORD(MAINMAXYKEY, GetNHApp()->regMainMaxY); + NHGETREG_DWORD(MAINLEFTKEY, GetNHApp()->regMainLeft); + NHGETREG_DWORD(MAINRIGHTKEY, GetNHApp()->regMainRight); + NHGETREG_DWORD(MAINTOPKEY, GetNHApp()->regMainTop); + NHGETREG_DWORD(MAINBOTTOMKEY, GetNHApp()->regMainBottom); - NHGETREG_DWORD(MAINAUTOLAYOUT, GetNHApp()->bAutoLayout); - NHGETREG_DWORD(MAPLEFT, GetNHApp()->rtMapWindow.left); - NHGETREG_DWORD(MAPRIGHT, GetNHApp()->rtMapWindow.right); - NHGETREG_DWORD(MAPTOP, GetNHApp()->rtMapWindow.top); - NHGETREG_DWORD(MAPBOTTOM, GetNHApp()->rtMapWindow.bottom); - NHGETREG_DWORD(MSGLEFT, GetNHApp()->rtMsgWindow.left); - NHGETREG_DWORD(MSGRIGHT, GetNHApp()->rtMsgWindow.right); - NHGETREG_DWORD(MSGTOP, GetNHApp()->rtMsgWindow.top); - NHGETREG_DWORD(MSGBOTTOM, GetNHApp()->rtMsgWindow.bottom); - NHGETREG_DWORD(STATUSLEFT, GetNHApp()->rtStatusWindow.left); - NHGETREG_DWORD(STATUSRIGHT, GetNHApp()->rtStatusWindow.right); - NHGETREG_DWORD(STATUSTOP, GetNHApp()->rtStatusWindow.top); - NHGETREG_DWORD(STATUSBOTTOM, GetNHApp()->rtStatusWindow.bottom); - NHGETREG_DWORD(MENULEFT, GetNHApp()->rtMenuWindow.left); - NHGETREG_DWORD(MENURIGHT, GetNHApp()->rtMenuWindow.right); - NHGETREG_DWORD(MENUTOP, GetNHApp()->rtMenuWindow.top); - NHGETREG_DWORD(MENUBOTTOM, GetNHApp()->rtMenuWindow.bottom); - NHGETREG_DWORD(TEXTLEFT, GetNHApp()->rtTextWindow.left); - NHGETREG_DWORD(TEXTRIGHT, GetNHApp()->rtTextWindow.right); - NHGETREG_DWORD(TEXTTOP, GetNHApp()->rtTextWindow.top); - NHGETREG_DWORD(TEXTBOTTOM, GetNHApp()->rtTextWindow.bottom); - NHGETREG_DWORD(INVENTLEFT, GetNHApp()->rtInvenWindow.left); - NHGETREG_DWORD(INVENTRIGHT, GetNHApp()->rtInvenWindow.right); - NHGETREG_DWORD(INVENTTOP, GetNHApp()->rtInvenWindow.top); - NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); + NHGETREG_DWORD(MAINAUTOLAYOUT, GetNHApp()->bAutoLayout); + NHGETREG_DWORD(MAPLEFT, GetNHApp()->rtMapWindow.left); + NHGETREG_DWORD(MAPRIGHT, GetNHApp()->rtMapWindow.right); + NHGETREG_DWORD(MAPTOP, GetNHApp()->rtMapWindow.top); + NHGETREG_DWORD(MAPBOTTOM, GetNHApp()->rtMapWindow.bottom); + NHGETREG_DWORD(MSGLEFT, GetNHApp()->rtMsgWindow.left); + NHGETREG_DWORD(MSGRIGHT, GetNHApp()->rtMsgWindow.right); + NHGETREG_DWORD(MSGTOP, GetNHApp()->rtMsgWindow.top); + NHGETREG_DWORD(MSGBOTTOM, GetNHApp()->rtMsgWindow.bottom); + NHGETREG_DWORD(STATUSLEFT, GetNHApp()->rtStatusWindow.left); + NHGETREG_DWORD(STATUSRIGHT, GetNHApp()->rtStatusWindow.right); + NHGETREG_DWORD(STATUSTOP, GetNHApp()->rtStatusWindow.top); + NHGETREG_DWORD(STATUSBOTTOM, GetNHApp()->rtStatusWindow.bottom); + NHGETREG_DWORD(MENULEFT, GetNHApp()->rtMenuWindow.left); + NHGETREG_DWORD(MENURIGHT, GetNHApp()->rtMenuWindow.right); + NHGETREG_DWORD(MENUTOP, GetNHApp()->rtMenuWindow.top); + NHGETREG_DWORD(MENUBOTTOM, GetNHApp()->rtMenuWindow.bottom); + NHGETREG_DWORD(TEXTLEFT, GetNHApp()->rtTextWindow.left); + NHGETREG_DWORD(TEXTRIGHT, GetNHApp()->rtTextWindow.right); + NHGETREG_DWORD(TEXTTOP, GetNHApp()->rtTextWindow.top); + NHGETREG_DWORD(TEXTBOTTOM, GetNHApp()->rtTextWindow.bottom); + NHGETREG_DWORD(INVENTLEFT, GetNHApp()->rtInvenWindow.left); + NHGETREG_DWORD(INVENTRIGHT, GetNHApp()->rtInvenWindow.right); + NHGETREG_DWORD(INVENTTOP, GetNHApp()->rtInvenWindow.top); + NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); #undef NHGETREG_DWORD - + RegCloseKey(key); - /* check the data for validity */ - if( IsRectEmpty(&GetNHApp()->rtMapWindow) || - IsRectEmpty(&GetNHApp()->rtMsgWindow) || - IsRectEmpty(&GetNHApp()->rtStatusWindow) || - IsRectEmpty(&GetNHApp()->rtMenuWindow) || - IsRectEmpty(&GetNHApp()->rtTextWindow) || - IsRectEmpty(&GetNHApp()->rtInvenWindow) ) - { - GetNHApp()->bAutoLayout = TRUE; - } + /* check the data for validity */ + if (IsRectEmpty(&GetNHApp()->rtMapWindow) + || IsRectEmpty(&GetNHApp()->rtMsgWindow) + || IsRectEmpty(&GetNHApp()->rtStatusWindow) + || IsRectEmpty(&GetNHApp()->rtMenuWindow) + || IsRectEmpty(&GetNHApp()->rtTextWindow) + || IsRectEmpty(&GetNHApp()->rtInvenWindow)) { + GetNHApp()->bAutoLayout = TRUE; + } } void @@ -2311,22 +2342,24 @@ mswin_write_reg() HKEY key; DWORD disposition; - if (GetNHApp()->saveRegistrySettings) - { + if (GetNHApp()->saveRegistrySettings) { char keystring[MAX_PATH]; - DWORD safe_buf; + DWORD safe_buf; - sprintf(keystring, "%s\\%s\\%s\\%s", - CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY); + sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, + PRODUCTKEY, SETTINGSKEY); - if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_WRITE, &key) != ERROR_SUCCESS) - { + if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_WRITE, &key) + != ERROR_SUCCESS) { RegCreateKeyEx(HKEY_CURRENT_USER, keystring, 0, "", - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disposition); + REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, + &key, &disposition); } -#define NHSETREG_DWORD(name, val) \ - RegSetValueEx(key, (name), 0, REG_DWORD, (unsigned char *)((safe_buf=(val)), &safe_buf), sizeof(DWORD)); +#define NHSETREG_DWORD(name, val) \ + RegSetValueEx(key, (name), 0, REG_DWORD, \ + (unsigned char *)((safe_buf = (val)), &safe_buf), \ + sizeof(DWORD)); /* Write the keys here */ NHSETREG_DWORD(INTFKEY, GetNHApp()->regNetHackMode); @@ -2342,31 +2375,31 @@ mswin_write_reg() NHSETREG_DWORD(MAINTOPKEY, GetNHApp()->regMainTop); NHSETREG_DWORD(MAINBOTTOMKEY, GetNHApp()->regMainBottom); - NHSETREG_DWORD(MAINAUTOLAYOUT, GetNHApp()->bAutoLayout); - NHSETREG_DWORD(MAPLEFT, GetNHApp()->rtMapWindow.left); - NHSETREG_DWORD(MAPRIGHT, GetNHApp()->rtMapWindow.right); - NHSETREG_DWORD(MAPTOP, GetNHApp()->rtMapWindow.top); - NHSETREG_DWORD(MAPBOTTOM, GetNHApp()->rtMapWindow.bottom); - NHSETREG_DWORD(MSGLEFT, GetNHApp()->rtMsgWindow.left); - NHSETREG_DWORD(MSGRIGHT, GetNHApp()->rtMsgWindow.right); - NHSETREG_DWORD(MSGTOP, GetNHApp()->rtMsgWindow.top); - NHSETREG_DWORD(MSGBOTTOM, GetNHApp()->rtMsgWindow.bottom); - NHSETREG_DWORD(STATUSLEFT, GetNHApp()->rtStatusWindow.left); - NHSETREG_DWORD(STATUSRIGHT, GetNHApp()->rtStatusWindow.right); - NHSETREG_DWORD(STATUSTOP, GetNHApp()->rtStatusWindow.top); - NHSETREG_DWORD(STATUSBOTTOM, GetNHApp()->rtStatusWindow.bottom); - NHSETREG_DWORD(MENULEFT, GetNHApp()->rtMenuWindow.left); - NHSETREG_DWORD(MENURIGHT, GetNHApp()->rtMenuWindow.right); - NHSETREG_DWORD(MENUTOP, GetNHApp()->rtMenuWindow.top); - NHSETREG_DWORD(MENUBOTTOM, GetNHApp()->rtMenuWindow.bottom); - NHSETREG_DWORD(TEXTLEFT, GetNHApp()->rtTextWindow.left); - NHSETREG_DWORD(TEXTRIGHT, GetNHApp()->rtTextWindow.right); - NHSETREG_DWORD(TEXTTOP, GetNHApp()->rtTextWindow.top); - NHSETREG_DWORD(TEXTBOTTOM, GetNHApp()->rtTextWindow.bottom); - NHSETREG_DWORD(INVENTLEFT, GetNHApp()->rtInvenWindow.left); - NHSETREG_DWORD(INVENTRIGHT, GetNHApp()->rtInvenWindow.right); - NHSETREG_DWORD(INVENTTOP, GetNHApp()->rtInvenWindow.top); - NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); + NHSETREG_DWORD(MAINAUTOLAYOUT, GetNHApp()->bAutoLayout); + NHSETREG_DWORD(MAPLEFT, GetNHApp()->rtMapWindow.left); + NHSETREG_DWORD(MAPRIGHT, GetNHApp()->rtMapWindow.right); + NHSETREG_DWORD(MAPTOP, GetNHApp()->rtMapWindow.top); + NHSETREG_DWORD(MAPBOTTOM, GetNHApp()->rtMapWindow.bottom); + NHSETREG_DWORD(MSGLEFT, GetNHApp()->rtMsgWindow.left); + NHSETREG_DWORD(MSGRIGHT, GetNHApp()->rtMsgWindow.right); + NHSETREG_DWORD(MSGTOP, GetNHApp()->rtMsgWindow.top); + NHSETREG_DWORD(MSGBOTTOM, GetNHApp()->rtMsgWindow.bottom); + NHSETREG_DWORD(STATUSLEFT, GetNHApp()->rtStatusWindow.left); + NHSETREG_DWORD(STATUSRIGHT, GetNHApp()->rtStatusWindow.right); + NHSETREG_DWORD(STATUSTOP, GetNHApp()->rtStatusWindow.top); + NHSETREG_DWORD(STATUSBOTTOM, GetNHApp()->rtStatusWindow.bottom); + NHSETREG_DWORD(MENULEFT, GetNHApp()->rtMenuWindow.left); + NHSETREG_DWORD(MENURIGHT, GetNHApp()->rtMenuWindow.right); + NHSETREG_DWORD(MENUTOP, GetNHApp()->rtMenuWindow.top); + NHSETREG_DWORD(MENUBOTTOM, GetNHApp()->rtMenuWindow.bottom); + NHSETREG_DWORD(TEXTLEFT, GetNHApp()->rtTextWindow.left); + NHSETREG_DWORD(TEXTRIGHT, GetNHApp()->rtTextWindow.right); + NHSETREG_DWORD(TEXTTOP, GetNHApp()->rtTextWindow.top); + NHSETREG_DWORD(TEXTBOTTOM, GetNHApp()->rtTextWindow.bottom); + NHSETREG_DWORD(INVENTLEFT, GetNHApp()->rtInvenWindow.left); + NHSETREG_DWORD(INVENTRIGHT, GetNHApp()->rtInvenWindow.right); + NHSETREG_DWORD(INVENTTOP, GetNHApp()->rtInvenWindow.top); + NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); #undef NHSETREG_DWORD RegCloseKey(key); @@ -2381,11 +2414,10 @@ mswin_destroy_reg() DWORD nrsubkeys; /* Delete keys one by one, as NT does not delete trees */ - sprintf(keystring, "%s\\%s\\%s\\%s", - CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY); + sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY, + SETTINGSKEY); RegDeleteKey(HKEY_CURRENT_USER, keystring); - sprintf(keystring, "%s\\%s\\%s", - CATEGORYKEY, COMPANYKEY, PRODUCTKEY); + sprintf(keystring, "%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY); RegDeleteKey(HKEY_CURRENT_USER, keystring); /* The company key will also contain information about newer versions of nethack (e.g. a subkey called NetHack 4.0), so only delete that @@ -2393,10 +2425,10 @@ mswin_destroy_reg() sprintf(keystring, "%s\\%s", CATEGORYKEY, COMPANYKEY); /* If we cannot open it, we probably cannot delete it either... Just go on and see what happens. */ - RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key); + RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key); nrsubkeys = 0; - RegQueryInfoKey(key, NULL, NULL, NULL, &nrsubkeys, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + RegQueryInfoKey(key, NULL, NULL, NULL, &nrsubkeys, NULL, NULL, NULL, NULL, + NULL, NULL, NULL); RegCloseKey(key); if (nrsubkeys == 0) RegDeleteKey(HKEY_CURRENT_USER, keystring); @@ -2405,10 +2437,9 @@ mswin_destroy_reg() GetNHApp()->saveRegistrySettings = 0; } -typedef struct ctv -{ - const char *colorstring; - COLORREF colorvalue; +typedef struct ctv { + const char *colorstring; + COLORREF colorvalue; } color_table_value; /* @@ -2418,186 +2449,197 @@ typedef struct ctv */ static color_table_value color_table[] = { -/* NetHack colors */ - { "black", RGB(0x55, 0x55, 0x55)}, - { "red", RGB(0xFF, 0x00, 0x00)}, - { "green", RGB(0x00, 0x80, 0x00)}, - { "brown", RGB(0xA5, 0x2A, 0x2A)}, - { "blue", RGB(0x00, 0x00, 0xFF)}, - { "magenta", RGB(0xFF, 0x00, 0xFF)}, - { "cyan", RGB(0x00, 0xFF, 0xFF)}, - { "orange", RGB(0xFF, 0xA5, 0x00)}, - { "brightgreen", RGB(0x00, 0xFF, 0x00)}, - { "yellow", RGB(0xFF, 0xFF, 0x00)}, - { "brightblue", RGB(0x00, 0xC0, 0xFF)}, - { "brightmagenta", RGB(0xFF, 0x80, 0xFF)}, - { "brightcyan", RGB(0x80, 0xFF, 0xFF)}, - { "white", RGB(0xFF, 0xFF, 0xFF)}, -/* Remaining HTML colors */ - { "trueblack", RGB(0x00, 0x00, 0x00)}, - { "gray", RGB(0x80, 0x80, 0x80)}, - { "grey", RGB(0x80, 0x80, 0x80)}, - { "purple", RGB(0x80, 0x00, 0x80)}, - { "silver", RGB(0xC0, 0xC0, 0xC0)}, - { "maroon", RGB(0x80, 0x00, 0x00)}, - { "fuchsia", RGB(0xFF, 0x00, 0xFF)}, /* = NetHack magenta */ - { "lime", RGB(0x00, 0xFF, 0x00)}, /* = NetHack bright green */ - { "olive", RGB(0x80, 0x80, 0x00)}, - { "navy", RGB(0x00, 0x00, 0x80)}, - { "teal", RGB(0x00, 0x80, 0x80)}, - { "aqua", RGB(0x00, 0xFF, 0xFF)}, /* = NetHack cyan */ - { "", RGB(0x00, 0x00, 0x00)}, + /* NetHack colors */ + { "black", RGB(0x55, 0x55, 0x55) }, + { "red", RGB(0xFF, 0x00, 0x00) }, + { "green", RGB(0x00, 0x80, 0x00) }, + { "brown", RGB(0xA5, 0x2A, 0x2A) }, + { "blue", RGB(0x00, 0x00, 0xFF) }, + { "magenta", RGB(0xFF, 0x00, 0xFF) }, + { "cyan", RGB(0x00, 0xFF, 0xFF) }, + { "orange", RGB(0xFF, 0xA5, 0x00) }, + { "brightgreen", RGB(0x00, 0xFF, 0x00) }, + { "yellow", RGB(0xFF, 0xFF, 0x00) }, + { "brightblue", RGB(0x00, 0xC0, 0xFF) }, + { "brightmagenta", RGB(0xFF, 0x80, 0xFF) }, + { "brightcyan", RGB(0x80, 0xFF, 0xFF) }, + { "white", RGB(0xFF, 0xFF, 0xFF) }, + /* Remaining HTML colors */ + { "trueblack", RGB(0x00, 0x00, 0x00) }, + { "gray", RGB(0x80, 0x80, 0x80) }, + { "grey", RGB(0x80, 0x80, 0x80) }, + { "purple", RGB(0x80, 0x00, 0x80) }, + { "silver", RGB(0xC0, 0xC0, 0xC0) }, + { "maroon", RGB(0x80, 0x00, 0x00) }, + { "fuchsia", RGB(0xFF, 0x00, 0xFF) }, /* = NetHack magenta */ + { "lime", RGB(0x00, 0xFF, 0x00) }, /* = NetHack bright green */ + { "olive", RGB(0x80, 0x80, 0x00) }, + { "navy", RGB(0x00, 0x00, 0x80) }, + { "teal", RGB(0x00, 0x80, 0x80) }, + { "aqua", RGB(0x00, 0xFF, 0xFF) }, /* = NetHack cyan */ + { "", RGB(0x00, 0x00, 0x00) }, }; -typedef struct ctbv -{ - char *colorstring; - int syscolorvalue; +typedef struct ctbv { + char *colorstring; + int syscolorvalue; } color_table_brush_value; static color_table_brush_value color_table_brush[] = { - { "activeborder", COLOR_ACTIVEBORDER }, - { "activecaption", COLOR_ACTIVECAPTION }, - { "appworkspace", COLOR_APPWORKSPACE }, - { "background", COLOR_BACKGROUND }, - { "btnface", COLOR_BTNFACE }, - { "btnshadow", COLOR_BTNSHADOW }, - { "btntext", COLOR_BTNTEXT }, - { "captiontext", COLOR_CAPTIONTEXT }, - { "graytext", COLOR_GRAYTEXT }, - { "greytext", COLOR_GRAYTEXT }, - { "highlight", COLOR_HIGHLIGHT }, - { "highlighttext", COLOR_HIGHLIGHTTEXT }, - { "inactiveborder", COLOR_INACTIVEBORDER }, - { "inactivecaption", COLOR_INACTIVECAPTION }, - { "menu", COLOR_MENU }, - { "menutext", COLOR_MENUTEXT }, - { "scrollbar", COLOR_SCROLLBAR }, - { "window", COLOR_WINDOW }, - { "windowframe", COLOR_WINDOWFRAME }, - { "windowtext", COLOR_WINDOWTEXT }, - { "", -1 }, + { "activeborder", COLOR_ACTIVEBORDER }, + { "activecaption", COLOR_ACTIVECAPTION }, + { "appworkspace", COLOR_APPWORKSPACE }, + { "background", COLOR_BACKGROUND }, + { "btnface", COLOR_BTNFACE }, + { "btnshadow", COLOR_BTNSHADOW }, + { "btntext", COLOR_BTNTEXT }, + { "captiontext", COLOR_CAPTIONTEXT }, + { "graytext", COLOR_GRAYTEXT }, + { "greytext", COLOR_GRAYTEXT }, + { "highlight", COLOR_HIGHLIGHT }, + { "highlighttext", COLOR_HIGHLIGHTTEXT }, + { "inactiveborder", COLOR_INACTIVEBORDER }, + { "inactivecaption", COLOR_INACTIVECAPTION }, + { "menu", COLOR_MENU }, + { "menutext", COLOR_MENUTEXT }, + { "scrollbar", COLOR_SCROLLBAR }, + { "window", COLOR_WINDOW }, + { "windowframe", COLOR_WINDOWFRAME }, + { "windowtext", COLOR_WINDOWTEXT }, + { "", -1 }, }; -static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr) +static void +mswin_color_from_string(char *colorstring, HBRUSH *brushptr, + COLORREF *colorptr) { - color_table_value *ctv_ptr = color_table; - color_table_brush_value *ctbv_ptr = color_table_brush; - int red_value, blue_value, green_value; - static char *hexadecimals = "0123456789abcdef"; + color_table_value *ctv_ptr = color_table; + color_table_brush_value *ctbv_ptr = color_table_brush; + int red_value, blue_value, green_value; + static char *hexadecimals = "0123456789abcdef"; - if (colorstring == NULL) return; - if (*colorstring == '#') { - if (strlen(++colorstring) != 6) return; + if (colorstring == NULL) + return; + if (*colorstring == '#') { + if (strlen(++colorstring) != 6) + return; - red_value = (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); - red_value *= 16; - red_value += (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); + red_value = (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); + red_value *= 16; + red_value += (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); - green_value = (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); - green_value *= 16; - green_value += (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); + green_value = (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); + green_value *= 16; + green_value += (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); - blue_value = (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); - blue_value *= 16; - blue_value += (int)(index(hexadecimals, tolower(*colorstring++)) - hexadecimals); + blue_value = (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); + blue_value *= 16; + blue_value += (int) (index(hexadecimals, tolower(*colorstring++)) + - hexadecimals); - *colorptr = RGB(red_value, green_value, blue_value); - } else { - while (*ctv_ptr->colorstring && stricmp(ctv_ptr->colorstring, colorstring)) - ++ctv_ptr; - if (*ctv_ptr->colorstring) { - *colorptr = ctv_ptr->colorvalue; - } else { - while (*ctbv_ptr->colorstring && stricmp(ctbv_ptr->colorstring, colorstring)) - ++ctbv_ptr; - if (*ctbv_ptr->colorstring) { - *brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue); - *colorptr = GetSysColor(ctbv_ptr->syscolorvalue); - } - } - } - if (max_brush > TOTAL_BRUSHES) panic("Too many colors!"); - *brushptr = CreateSolidBrush(*colorptr); - brush_table[max_brush++] = *brushptr; + *colorptr = RGB(red_value, green_value, blue_value); + } else { + while (*ctv_ptr->colorstring + && stricmp(ctv_ptr->colorstring, colorstring)) + ++ctv_ptr; + if (*ctv_ptr->colorstring) { + *colorptr = ctv_ptr->colorvalue; + } else { + while (*ctbv_ptr->colorstring + && stricmp(ctbv_ptr->colorstring, colorstring)) + ++ctbv_ptr; + if (*ctbv_ptr->colorstring) { + *brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue); + *colorptr = GetSysColor(ctbv_ptr->syscolorvalue); + } + } + } + if (max_brush > TOTAL_BRUSHES) + panic("Too many colors!"); + *brushptr = CreateSolidBrush(*colorptr); + brush_table[max_brush++] = *brushptr; } -void mswin_get_window_placement(int type, LPRECT rt) +void +mswin_get_window_placement(int type, LPRECT rt) { switch (type) { case NHW_MAP: - *rt = GetNHApp()->rtMapWindow; - break; + *rt = GetNHApp()->rtMapWindow; + break; case NHW_MESSAGE: - *rt = GetNHApp()->rtMsgWindow; - break; + *rt = GetNHApp()->rtMsgWindow; + break; case NHW_STATUS: - *rt = GetNHApp()->rtStatusWindow; - break; + *rt = GetNHApp()->rtStatusWindow; + break; case NHW_MENU: - *rt = GetNHApp()->rtMenuWindow; - break; + *rt = GetNHApp()->rtMenuWindow; + break; case NHW_TEXT: - *rt = GetNHApp()->rtTextWindow; - break; + *rt = GetNHApp()->rtTextWindow; + break; case NHW_INVEN: - *rt = GetNHApp()->rtInvenWindow; - break; + *rt = GetNHApp()->rtInvenWindow; + break; - default: - SetRect(rt, 0, 0, 0, 0); - break; - } + default: + SetRect(rt, 0, 0, 0, 0); + break; + } } -void mswin_update_window_placement(int type, LPRECT rt) +void +mswin_update_window_placement(int type, LPRECT rt) { - LPRECT rt_conf = NULL; + LPRECT rt_conf = NULL; switch (type) { case NHW_MAP: - rt_conf = &GetNHApp()->rtMapWindow; - break; + rt_conf = &GetNHApp()->rtMapWindow; + break; case NHW_MESSAGE: - rt_conf = &GetNHApp()->rtMsgWindow; - break; + rt_conf = &GetNHApp()->rtMsgWindow; + break; case NHW_STATUS: - rt_conf = &GetNHApp()->rtStatusWindow; - break; + rt_conf = &GetNHApp()->rtStatusWindow; + break; case NHW_MENU: - rt_conf = &GetNHApp()->rtMenuWindow; - break; + rt_conf = &GetNHApp()->rtMenuWindow; + break; case NHW_TEXT: - rt_conf = &GetNHApp()->rtTextWindow; - break; - - case NHW_INVEN: - rt_conf = &GetNHApp()->rtInvenWindow; - break; - } - - if( rt_conf && - !IsRectEmpty(rt) && - !EqualRect(rt_conf, rt) ) - { - *rt_conf = *rt; - } + rt_conf = &GetNHApp()->rtTextWindow; + break; + + case NHW_INVEN: + rt_conf = &GetNHApp()->rtInvenWindow; + break; + } + + if (rt_conf && !IsRectEmpty(rt) && !EqualRect(rt_conf, rt)) { + *rt_conf = *rt; + } } - -int NHMessageBox(HWND hWnd, LPCTSTR text, UINT type) +int +NHMessageBox(HWND hWnd, LPCTSTR text, UINT type) { TCHAR title[MAX_LOADSTRING]; - + LoadString(GetNHApp()->hApp, IDS_APP_TITLE_SHORT, title, MAX_LOADSTRING); return MessageBox(hWnd, text, title, type); @@ -2607,272 +2649,307 @@ int NHMessageBox(HWND hWnd, LPCTSTR text, UINT type) static const char *_status_fieldnm[MAXBLSTATS]; static const char *_status_fieldfmt[MAXBLSTATS]; static char *_status_vals[MAXBLSTATS]; -static int _status_colors[MAXBLSTATS]; +static int _status_colors[MAXBLSTATS]; static boolean _status_activefields[MAXBLSTATS]; extern winid WIN_STATUS; -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES typedef struct hilite_data_struct { - int thresholdtype; - anything threshold; - int behavior; - int under; - int over; + int thresholdtype; + anything threshold; + int behavior; + int under; + int over; } hilite_data_t; static hilite_data_t _status_hilites[MAXBLSTATS]; #endif /* STATUS_HILITES */ /* status_init() -- core calls this to notify the window port that a status - display is required. The window port should perform - the necessary initialization in here, allocate memory, etc. + display is required. The window port should perform + the necessary initialization in here, allocate memory, etc. */ void mswin_status_init(void) { - int i; - logDebug("mswin_status_init()\n"); - for (i = 0; i < MAXBLSTATS; ++i) { - _status_vals[i] = (char *)alloc(BUFSZ); - *_status_vals[i] = '\0'; - _status_activefields[i] = FALSE; - _status_fieldfmt[i] = (const char *)0; - _status_colors[i] = CLR_MAX; /* no color */ -# ifdef STATUS_HILITES - _status_hilites[i].thresholdtype = 0; - _status_hilites[i].behavior = BL_TH_NONE; - _status_hilites[i].under = BL_HILITE_NONE; - _status_hilites[i].over = BL_HILITE_NONE; + int i; + logDebug("mswin_status_init()\n"); + for (i = 0; i < MAXBLSTATS; ++i) { + _status_vals[i] = (char *) alloc(BUFSZ); + *_status_vals[i] = '\0'; + _status_activefields[i] = FALSE; + _status_fieldfmt[i] = (const char *) 0; + _status_colors[i] = CLR_MAX; /* no color */ +#ifdef STATUS_HILITES + _status_hilites[i].thresholdtype = 0; + _status_hilites[i].behavior = BL_TH_NONE; + _status_hilites[i].under = BL_HILITE_NONE; + _status_hilites[i].over = BL_HILITE_NONE; #endif /* STATUS_HILITES */ - } - /* Use a window for the genl version; backward port compatibility */ - WIN_STATUS = create_nhwindow(NHW_STATUS); - display_nhwindow(WIN_STATUS, FALSE); + } + /* Use a window for the genl version; backward port compatibility */ + WIN_STATUS = create_nhwindow(NHW_STATUS); + display_nhwindow(WIN_STATUS, FALSE); } /* status_finish() -- called when it is time for the window port to tear down - the status display and free allocated memory, etc. + the status display and free allocated memory, etc. */ void mswin_status_finish(void) { - /* tear down routine */ - int i; + /* tear down routine */ + int i; - logDebug("mswin_status_finish()\n"); + logDebug("mswin_status_finish()\n"); - /* free alloc'd memory here */ - for (i = 0; i < MAXBLSTATS; ++i) { - if (_status_vals[i]) free((genericptr_t)_status_vals[i]); - _status_vals[i] = (char *)0; - } + /* free alloc'd memory here */ + for (i = 0; i < MAXBLSTATS; ++i) { + if (_status_vals[i]) + free((genericptr_t) _status_vals[i]); + _status_vals[i] = (char *) 0; + } } /* -status_enablefield(int fldindex, char fldname, char fieldfmt, boolean enable) +status_enablefield(int fldindex, char fldname, char fieldfmt, boolean enable) -- notifies the window port which fields it is authorized to - display. - -- This may be called at any time, and is used - to disable as well as enable fields, depending on the - value of the final argument (TRUE = enable). - -- fldindex could be one of the following from botl.h: - BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, - BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, - BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, - BL_LEVELDESC, BL_EXP, BL_CONDITION - -- There are MAXBLSTATS status fields (from botl.h) + display. + -- This may be called at any time, and is used + to disable as well as enable fields, depending on the + value of the final argument (TRUE = enable). + -- fldindex could be one of the following from botl.h: + BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, + BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, + BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, + BL_LEVELDESC, BL_EXP, BL_CONDITION + -- There are MAXBLSTATS status fields (from botl.h) */ void -mswin_status_enablefield(int fieldidx, const char *nm, const char *fmt, boolean enable) +mswin_status_enablefield(int fieldidx, const char *nm, const char *fmt, + boolean enable) { - logDebug("mswin_status_enablefield(%d, %s, %s, %d)\n", fieldidx, nm, fmt, (int)enable); - _status_fieldfmt[fieldidx] = fmt; - _status_fieldnm[fieldidx] = nm; - _status_activefields[fieldidx] = enable; + logDebug("mswin_status_enablefield(%d, %s, %s, %d)\n", fieldidx, nm, fmt, + (int) enable); + _status_fieldfmt[fieldidx] = fmt; + _status_fieldnm[fieldidx] = nm; + _status_activefields[fieldidx] = enable; } -# ifdef STATUS_HILITES +#ifdef STATUS_HILITES /* -status_threshold(int fldidx, int threshholdtype, anything threshold, - int behavior, int under, int over) - -- called when a hiliting preference is added, changed, or - removed. - -- the fldindex identifies which field is having its hiliting - preference set. It is an integer index value from botl.h - -- fldindex could be any one of the following from botl.h: - BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, - BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, - BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, - BL_LEVELDESC, BL_EXP, BL_CONDITION - -- datatype is P_INT, P_UINT, P_LONG, or P_MASK. - -- threshold is an "anything" union which can contain the - datatype value. - -- behavior is used to define how threshold is used and can - be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE, - or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above - or below the threshold. BL_TH_VAL_PERCENTAGE treats the - threshold value as a precentage of the maximum possible - value. BL_TH_VAL_ABSOLUTE means that the threshold is an - actual value. BL_TH_UPDOWN means that threshold is not - used, and the two below/above hilite values indicate how - to display something going down (under) or rising (over). - -- under is the hilite attribute used if value is below the - threshold. The attribute can be BL_HILITE_NONE, - BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one - of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN, - CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY, - CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE, - CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15). - -- over is the hilite attribute used if value is at or above - the threshold. The attribute can be BL_HILITE_NONE, - BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one - of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN, - CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY, - CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE, - CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15). +status_threshold(int fldidx, int threshholdtype, anything threshold, + int behavior, int under, int over) + -- called when a hiliting preference is added, changed, or + removed. + -- the fldindex identifies which field is having its hiliting + preference set. It is an integer index value from botl.h + -- fldindex could be any one of the following from botl.h: + BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, + BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, + BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, + BL_LEVELDESC, BL_EXP, BL_CONDITION + -- datatype is P_INT, P_UINT, P_LONG, or P_MASK. + -- threshold is an "anything" union which can contain the + datatype value. + -- behavior is used to define how threshold is used and can + be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE, + or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above + or below the threshold. BL_TH_VAL_PERCENTAGE treats the + threshold value as a precentage of the maximum possible + value. BL_TH_VAL_ABSOLUTE means that the threshold is an + actual value. BL_TH_UPDOWN means that threshold is not + used, and the two below/above hilite values indicate how + to display something going down (under) or rising (over). + -- under is the hilite attribute used if value is below the + threshold. The attribute can be BL_HILITE_NONE, + BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one + of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN, + CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY, + CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE, + CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15). + -- over is the hilite attribute used if value is at or above + the threshold. The attribute can be BL_HILITE_NONE, + BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one + of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN, + CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY, + CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE, + CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15). */ void -mswin_status_threshold(int fldidx, int thresholdtype, anything threshold, int behavior, int under, int over) +mswin_status_threshold(int fldidx, int thresholdtype, anything threshold, + int behavior, int under, int over) { - logDebug("mswin_status_threshold(%d, %d, %d, %d, %d)\n", fldidx, thresholdtype, behavior, under, over); - assert(fldidx>=0 && fldidx= 0 && fldidx < MAXBLSTATS); + _status_hilites[fldidx].thresholdtype = thresholdtype; + _status_hilites[fldidx].threshold = threshold; + _status_hilites[fldidx].behavior = behavior; + _status_hilites[fldidx].under = under; + _status_hilites[fldidx].over = over; } #endif /* STATUS_HILITES */ /* status_update(int fldindex, genericptr_t ptr, int chg, int percentage) - -- update the value of a status field. - -- the fldindex identifies which field is changing and - is an integer index value from botl.h - -- fldindex could be any one of the following from botl.h: - BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, - BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, - BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, - BL_LEVELDESC, BL_EXP, BL_CONDITION - -- fldindex could also be BL_FLUSH (-1), which is not really - a field index, but is a special trigger to tell the - windowport that it should redisplay all its status fields, - even if no changes have been presented to it. - -- ptr is usually a "char *", unless fldindex is BL_CONDITION. - If fldindex is BL_CONDITION, then ptr is a long value with - any or none of the following bits set (from botl.h): - BL_MASK_BLIND 0x00000001L - BL_MASK_CONF 0x00000002L - BL_MASK_FOODPOIS 0x00000004L - BL_MASK_ILL 0x00000008L - BL_MASK_HALLU 0x00000010L - BL_MASK_STUNNED 0x00000020L - BL_MASK_SLIMED 0x00000040L - -- The value passed for BL_GOLD includes a leading - symbol for GOLD "$:nnn". If the window port needs to use - the textual gold amount without the leading "$:" the port - will have to add 2 to the passed "ptr" for the BL_GOLD case. + -- update the value of a status field. + -- the fldindex identifies which field is changing and + is an integer index value from botl.h + -- fldindex could be any one of the following from botl.h: + BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, + BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX, + BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, + BL_LEVELDESC, BL_EXP, BL_CONDITION + -- fldindex could also be BL_FLUSH (-1), which is not really + a field index, but is a special trigger to tell the + windowport that it should redisplay all its status fields, + even if no changes have been presented to it. + -- ptr is usually a "char *", unless fldindex is BL_CONDITION. + If fldindex is BL_CONDITION, then ptr is a long value with + any or none of the following bits set (from botl.h): + BL_MASK_BLIND 0x00000001L + BL_MASK_CONF 0x00000002L + BL_MASK_FOODPOIS 0x00000004L + BL_MASK_ILL 0x00000008L + BL_MASK_HALLU 0x00000010L + BL_MASK_STUNNED 0x00000020L + BL_MASK_SLIMED 0x00000040L + -- The value passed for BL_GOLD includes a leading + symbol for GOLD "$:nnn". If the window port needs to use + the textual gold amount without the leading "$:" the port + will have to add 2 to the passed "ptr" for the BL_GOLD +case. */ void mswin_status_update(int idx, genericptr_t ptr, int chg, int percent) { - long cond, *condptr = (long *)ptr; - char *text = (char *)ptr; - MSNHMsgUpdateStatus update_cmd_data; - int ocolor, ochar; - unsigned ospecial; - long value = -1; - - logDebug("mswin_status_update(%d, %p, %d, %d)\n", idx, ptr, chg, percent); + long cond, *condptr = (long *) ptr; + char *text = (char *) ptr; + MSNHMsgUpdateStatus update_cmd_data; + int ocolor, ochar; + unsigned ospecial; + long value = -1; - if (idx != BL_FLUSH) { - if (!_status_activefields[idx]) return; - switch(idx) { - case BL_CONDITION: { - cond = *condptr; - *_status_vals[idx] = '\0'; - if (cond & BL_MASK_BLIND) Strcat(_status_vals[idx], " Blind"); - if (cond & BL_MASK_CONF) Strcat(_status_vals[idx], " Conf"); - if (cond & BL_MASK_FOODPOIS) - Strcat(_status_vals[idx], " FoodPois"); - if (cond & BL_MASK_ILL) Strcat(_status_vals[idx], " Ill"); - if (cond & BL_MASK_STUNNED) Strcat(_status_vals[idx], " Stun"); - if (cond & BL_MASK_HALLU) Strcat(_status_vals[idx], " Hallu"); - if (cond & BL_MASK_SLIMED) Strcat(_status_vals[idx], " Slime"); - value = cond; - } break; - case BL_GOLD: { - char buf[BUFSZ]; - char* p; - ZeroMemory(buf, sizeof(buf)); - mapglyph(objnum_to_glyph(GOLD_PIECE), &ochar, &ocolor, &ospecial, 0, 0); - buf[0] = ochar; - p = strchr(text, ':'); - if(p) strncpy(buf+1, p, sizeof(buf)-2); - value = atol(buf); - Sprintf(_status_vals[idx], - _status_fieldfmt[idx] ? _status_fieldfmt[idx] : "%s", buf); - } break; - default: { - value = atol(text); - Sprintf(_status_vals[idx], - _status_fieldfmt[idx] ? _status_fieldfmt[idx] : "%s", text); - } break; - } - } + logDebug("mswin_status_update(%d, %p, %d, %d)\n", idx, ptr, chg, percent); -# ifdef STATUS_HILITES - switch(_status_hilites[idx].behavior) { - case BL_TH_NONE: { - _status_colors[idx] = CLR_MAX; - } break; + if (idx != BL_FLUSH) { + if (!_status_activefields[idx]) + return; + switch (idx) { + case BL_CONDITION: { + cond = *condptr; + *_status_vals[idx] = '\0'; + if (cond & BL_MASK_BLIND) + Strcat(_status_vals[idx], " Blind"); + if (cond & BL_MASK_CONF) + Strcat(_status_vals[idx], " Conf"); + if (cond & BL_MASK_FOODPOIS) + Strcat(_status_vals[idx], " FoodPois"); + if (cond & BL_MASK_ILL) + Strcat(_status_vals[idx], " Ill"); + if (cond & BL_MASK_STUNNED) + Strcat(_status_vals[idx], " Stun"); + if (cond & BL_MASK_HALLU) + Strcat(_status_vals[idx], " Hallu"); + if (cond & BL_MASK_SLIMED) + Strcat(_status_vals[idx], " Slime"); + value = cond; + } break; + case BL_GOLD: { + char buf[BUFSZ]; + char *p; + ZeroMemory(buf, sizeof(buf)); + mapglyph(objnum_to_glyph(GOLD_PIECE), &ochar, &ocolor, &ospecial, + 0, 0); + buf[0] = ochar; + p = strchr(text, ':'); + if (p) + strncpy(buf + 1, p, sizeof(buf) - 2); + value = atol(buf); + Sprintf(_status_vals[idx], + _status_fieldfmt[idx] ? _status_fieldfmt[idx] : "%s", + buf); + } break; + default: { + value = atol(text); + Sprintf(_status_vals[idx], + _status_fieldfmt[idx] ? _status_fieldfmt[idx] : "%s", + text); + } break; + } + } - case BL_TH_UPDOWN: { - if(chg > 0) _status_colors[idx] = _status_hilites[idx].over; - else if(chg < 0) _status_colors[idx] = _status_hilites[idx].under; - else _status_colors[idx] = CLR_MAX; - } break; +#ifdef STATUS_HILITES + switch (_status_hilites[idx].behavior) { + case BL_TH_NONE: { + _status_colors[idx] = CLR_MAX; + } break; - case BL_TH_VAL_PERCENTAGE: { - int pct_th = 0; - if(_status_hilites[idx].thresholdtype!=ANY_INT) { - impossible("mswin_status_update: unsupported percentage threshold type %d", _status_hilites[idx].thresholdtype); - break; - } - pct_th = _status_hilites[idx].threshold.a_int; - _status_colors[idx] = (percent >= pct_th)? _status_hilites[idx].over : _status_hilites[idx].under; - } break; + case BL_TH_UPDOWN: { + if (chg > 0) + _status_colors[idx] = _status_hilites[idx].over; + else if (chg < 0) + _status_colors[idx] = _status_hilites[idx].under; + else + _status_colors[idx] = CLR_MAX; + } break; - case BL_TH_VAL_ABSOLUTE: { - int c = CLR_MAX; - int o = _status_hilites[idx].over; - int u = _status_hilites[idx].under; - anything* t = &_status_hilites[idx].threshold; - switch (_status_hilites[idx].thresholdtype) { - case ANY_LONG: c = (value >= t->a_long)? o : u; break; - case ANY_INT: c = (value >= t->a_int)? o : u; break; - case ANY_UINT: c = ((unsigned long)value >= t->a_uint)? o : u; break; - case ANY_ULONG: c = ((unsigned long)value >= t->a_ulong)? o : u; break; - case ANY_MASK32: c = (value & t->a_ulong)? o : u; break; - default: - impossible("mswin_status_update: unsupported absolute threshold type %d\n", _status_hilites[idx].thresholdtype); - break; - } - _status_colors[idx] = c; - } break; - } + case BL_TH_VAL_PERCENTAGE: { + int pct_th = 0; + if (_status_hilites[idx].thresholdtype != ANY_INT) { + impossible("mswin_status_update: unsupported percentage " + "threshold type %d", + _status_hilites[idx].thresholdtype); + break; + } + pct_th = _status_hilites[idx].threshold.a_int; + _status_colors[idx] = (percent >= pct_th) + ? _status_hilites[idx].over + : _status_hilites[idx].under; + } break; + + case BL_TH_VAL_ABSOLUTE: { + int c = CLR_MAX; + int o = _status_hilites[idx].over; + int u = _status_hilites[idx].under; + anything *t = &_status_hilites[idx].threshold; + switch (_status_hilites[idx].thresholdtype) { + case ANY_LONG: + c = (value >= t->a_long) ? o : u; + break; + case ANY_INT: + c = (value >= t->a_int) ? o : u; + break; + case ANY_UINT: + c = ((unsigned long) value >= t->a_uint) ? o : u; + break; + case ANY_ULONG: + c = ((unsigned long) value >= t->a_ulong) ? o : u; + break; + case ANY_MASK32: + c = (value & t->a_ulong) ? o : u; + break; + default: + impossible("mswin_status_update: unsupported absolute threshold " + "type %d\n", + _status_hilites[idx].thresholdtype); + break; + } + _status_colors[idx] = c; + } break; + } #endif /* STATUS_HILITES */ - - /* send command to status window */ - ZeroMemory(&update_cmd_data, sizeof(update_cmd_data)); - update_cmd_data.n_fields = MAXBLSTATS; - update_cmd_data.vals = _status_vals; - update_cmd_data.activefields = _status_activefields; - update_cmd_data.colors = _status_colors; - SendMessage( - mswin_hwnd_from_winid(WIN_STATUS), - WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_UPDATE_STATUS, (LPARAM)&update_cmd_data ); + + /* send command to status window */ + ZeroMemory(&update_cmd_data, sizeof(update_cmd_data)); + update_cmd_data.n_fields = MAXBLSTATS; + update_cmd_data.vals = _status_vals; + update_cmd_data.activefields = _status_activefields; + update_cmd_data.colors = _status_colors; + SendMessage(mswin_hwnd_from_winid(WIN_STATUS), WM_MSNH_COMMAND, + (WPARAM) MSNH_MSG_UPDATE_STATUS, (LPARAM) &update_cmd_data); } #endif /*STATUS_VIA_WINDOWPORT*/ diff --git a/win/win32/winhack.c b/win/win32/winhack.c index ec707c2f6..134b7eaad 100644 --- a/win/win32/winhack.c +++ b/win/win32/winhack.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 winhack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.6 winhack.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */ /* NetHack 3.6 winhack.c $Date: 2009/05/06 11:00:43 $ $Revision: 1.32 $ */ /* SCCS Id: @(#)winhack.c 3.5 2006/04/01 */ /* Copyright (C) 2001 by Alex Kompel */ @@ -17,13 +17,12 @@ /* Borland and MinGW redefine "boolean" in shlwapi.h, so just use the little bit we need */ -typedef struct _DLLVERSIONINFO -{ +typedef struct _DLLVERSIONINFO { DWORD cbSize; - DWORD dwMajorVersion; // Major version - DWORD dwMinorVersion; // Minor version - DWORD dwBuildNumber; // Build number - DWORD dwPlatformID; // DLLVER_PLATFORM_* + DWORD dwMajorVersion; // Major version + DWORD dwMinorVersion; // Minor version + DWORD dwBuildNumber; // Build number + DWORD dwPlatformID; // DLLVER_PLATFORM_* } DLLVERSIONINFO; // @@ -31,7 +30,7 @@ typedef struct _DLLVERSIONINFO // implicitly link to it. // -typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *); +typedef HRESULT(CALLBACK *DLLGETVERSIONPROC)(DLLVERSIONINFO *); /* end of shlwapi.h */ @@ -47,120 +46,124 @@ Version _WIN_32IE Platform/IE #define MIN_COMCTLMAJOR 4 #define MIN_COMCTLMINOR 71 #define INSTALL_NOTES "http://www.nethack.org/v340/ports/download-win.html#cc" -/*#define COMCTL_URL "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/ +/*#define COMCTL_URL + * "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/ -extern void FDECL(nethack_exit,(int)); -static TCHAR* _get_cmd_arg(TCHAR* pCmdLine); +extern void FDECL(nethack_exit, (int)); +static TCHAR *_get_cmd_arg(TCHAR *pCmdLine); static HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); - // Global Variables: NHWinApp _nethack_app; #ifdef __BORLANDC__ -#define _stricmp(s1,s2) stricmp(s1,s2) -#define _strdup(s1) strdup(s1) +#define _stricmp(s1, s2) stricmp(s1, s2) +#define _strdup(s1) strdup(s1) #endif // Foward declarations of functions included in this code module: -extern boolean FDECL(pcmain, (int,char **)); +extern boolean FDECL(pcmain, (int, char **)); static void __cdecl mswin_moveloop(void *); #define MAX_CMDLINE_PARAM 255 -int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +int APIENTRY +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, + int nCmdShow) { - INITCOMMONCONTROLSEX InitCtrls; - int argc; - char* argv[MAX_CMDLINE_PARAM]; - size_t len; - TCHAR *p; - TCHAR wbuf[BUFSZ]; - char buf[BUFSZ]; + INITCOMMONCONTROLSEX InitCtrls; + int argc; + char *argv[MAX_CMDLINE_PARAM]; + size_t len; + TCHAR *p; + TCHAR wbuf[BUFSZ]; + char buf[BUFSZ]; DWORD major, minor; - boolean resuming; + boolean resuming; - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - UNREFERENCED_PARAMETER(nCmdShow); + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + UNREFERENCED_PARAMETER(nCmdShow); - /* ensure that we don't access violate on a panic() */ - windowprocs.win_raw_print = mswin_raw_print; - windowprocs.win_raw_print_bold = mswin_raw_print_bold; + /* ensure that we don't access violate on a panic() */ + windowprocs.win_raw_print = mswin_raw_print; + windowprocs.win_raw_print_bold = mswin_raw_print_bold; - /* init applicatio structure */ - _nethack_app.hApp = hInstance; - _nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_NETHACKW); - _nethack_app.hMainWnd = NULL; - _nethack_app.hPopupWnd = NULL; - _nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES)); - if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap"); - _nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK)); - if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap"); - _nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP)); - if ( _nethack_app.bmpRip == NULL ) panic("cannot load rip bitmap"); - _nethack_app.bmpSplash = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH)); - if ( _nethack_app.bmpSplash == NULL ) panic("cannot load splash bitmap"); - _nethack_app.bmpMapTiles = _nethack_app.bmpTiles; - _nethack_app.mapTile_X = TILE_X; - _nethack_app.mapTile_Y = TILE_Y; - _nethack_app.mapTilesPerLine = TILES_PER_LINE; + /* init applicatio structure */ + _nethack_app.hApp = hInstance; + _nethack_app.hAccelTable = + LoadAccelerators(hInstance, (LPCTSTR) IDC_NETHACKW); + _nethack_app.hMainWnd = NULL; + _nethack_app.hPopupWnd = NULL; + _nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES)); + if (_nethack_app.bmpTiles == NULL) + panic("cannot load tiles bitmap"); + _nethack_app.bmpPetMark = + LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK)); + if (_nethack_app.bmpPetMark == NULL) + panic("cannot load pet mark bitmap"); + _nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP)); + if (_nethack_app.bmpRip == NULL) + panic("cannot load rip bitmap"); + _nethack_app.bmpSplash = + LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH)); + if (_nethack_app.bmpSplash == NULL) + panic("cannot load splash bitmap"); + _nethack_app.bmpMapTiles = _nethack_app.bmpTiles; + _nethack_app.mapTile_X = TILE_X; + _nethack_app.mapTile_Y = TILE_Y; + _nethack_app.mapTilesPerLine = TILES_PER_LINE; - _nethack_app.bNoHScroll = FALSE; - _nethack_app.bNoVScroll = FALSE; - _nethack_app.saved_text = strdup(""); + _nethack_app.bNoHScroll = FALSE; + _nethack_app.bNoVScroll = FALSE; + _nethack_app.saved_text = strdup(""); - _nethack_app.bAutoLayout = TRUE; - _nethack_app.bWindowsLocked = TRUE; + _nethack_app.bAutoLayout = TRUE; + _nethack_app.bWindowsLocked = TRUE; - _nethack_app.bNoSounds = FALSE; + _nethack_app.bNoSounds = FALSE; // init controls - if (FAILED(GetComCtlVersion(&major, &minor))) - { + if (FAILED(GetComCtlVersion(&major, &minor))) { char buf[TBUFSZ]; Sprintf(buf, "Cannot load common control library.\n%s\n%s", - "For further information, refer to the installation notes at", - INSTALL_NOTES); + "For further information, refer to the installation notes at", + INSTALL_NOTES); panic(buf); } if (major < MIN_COMCTLMAJOR - || (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR)) - { + || (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR)) { char buf[TBUFSZ]; Sprintf(buf, "Common control library is outdated.\n%s %d.%d\n%s\n%s", - "NetHack requires at least version ", - MIN_COMCTLMAJOR, MIN_COMCTLMINOR, - "For further information, refer to the installation notes at", - INSTALL_NOTES); + "NetHack requires at least version ", MIN_COMCTLMAJOR, + MIN_COMCTLMINOR, + "For further information, refer to the installation notes at", + INSTALL_NOTES); panic(buf); } - ZeroMemory(&InitCtrls, sizeof(InitCtrls)); - InitCtrls.dwSize = sizeof(InitCtrls); - InitCtrls.dwICC = ICC_LISTVIEW_CLASSES; - InitCommonControlsEx(&InitCtrls); - - /* get command line parameters */ - p = _get_cmd_arg(GetCommandLine()); - p = _get_cmd_arg(NULL); /* skip first paramter - command name */ - for( argc = 1; p && argc0 ) { - argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) ); - } else { - argv[argc] = ""; - } - p = _get_cmd_arg(NULL); - } - GetModuleFileName(NULL, wbuf, BUFSZ); - argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); + ZeroMemory(&InitCtrls, sizeof(InitCtrls)); + InitCtrls.dwSize = sizeof(InitCtrls); + InitCtrls.dwICC = ICC_LISTVIEW_CLASSES; + InitCommonControlsEx(&InitCtrls); + + /* get command line parameters */ + p = _get_cmd_arg(GetCommandLine()); + p = _get_cmd_arg(NULL); /* skip first paramter - command name */ + for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) { + len = _tcslen(p); + if (len > 0) { + argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ)); + } else { + argv[argc] = ""; + } + p = _get_cmd_arg(NULL); + } + GetModuleFileName(NULL, wbuf, BUFSZ); + argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); if (argc == 2) { - TCHAR *savefile = strdup(argv[1]); - TCHAR *plname; + TCHAR *savefile = strdup(argv[1]); + TCHAR *plname; for (p = savefile; *p && *p != '-'; p++) ; if (*p) { @@ -179,100 +182,110 @@ int APIENTRY WinMain(HINSTANCE hInstance, } free(savefile); } - resuming = pcmain(argc,argv); + resuming = pcmain(argc, argv); - moveloop(resuming); + moveloop(resuming); - return 0; + return 0; } - -PNHWinApp GetNHApp() +PNHWinApp +GetNHApp() { - return &_nethack_app; + return &_nethack_app; } -TCHAR* _get_cmd_arg(TCHAR* pCmdLine) +TCHAR * +_get_cmd_arg(TCHAR *pCmdLine) { - static TCHAR* pArgs = NULL; - TCHAR *pRetArg; - BOOL bQuoted; + static TCHAR *pArgs = NULL; + TCHAR *pRetArg; + BOOL bQuoted; - if( !pCmdLine && !pArgs ) return NULL; - if( !pArgs ) pArgs = pCmdLine; + if (!pCmdLine && !pArgs) + return NULL; + if (!pArgs) + pArgs = pCmdLine; - /* skip whitespace */ - for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg)); - if( !*pRetArg ) { - pArgs = NULL; - return NULL; - } + /* skip whitespace */ + for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); + pRetArg = CharNext(pRetArg)) + ; + if (!*pRetArg) { + pArgs = NULL; + return NULL; + } - /* check for quote */ - if( *pRetArg==TEXT('"') ) { - bQuoted = TRUE; - pRetArg = CharNext(pRetArg); - pArgs = _tcschr(pRetArg, TEXT('"')); - } else { - /* skip to whitespace */ - for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs)); - } - - if( pArgs && *pArgs ) { - TCHAR* p; - p = pArgs; - pArgs = CharNext(pArgs); - *p = (TCHAR)0; - } else { - pArgs = NULL; - } + /* check for quote */ + if (*pRetArg == TEXT('"')) { + bQuoted = TRUE; + pRetArg = CharNext(pRetArg); + pArgs = _tcschr(pRetArg, TEXT('"')); + } else { + /* skip to whitespace */ + for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs); + pArgs = CharNext(pArgs)) + ; + } - return pRetArg; + if (pArgs && *pArgs) { + TCHAR *p; + p = pArgs; + pArgs = CharNext(pArgs); + *p = (TCHAR) 0; + } else { + pArgs = NULL; + } + + return pRetArg; } /* Get the version of the Common Control library on this machine. Copied from the Microsoft SDK */ -HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor) +HRESULT +GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor) { - HINSTANCE hComCtl; - HRESULT hr = S_OK; - DLLGETVERSIONPROC pDllGetVersion; + HINSTANCE hComCtl; + HRESULT hr = S_OK; + DLLGETVERSIONPROC pDllGetVersion; - if(IsBadWritePtr(pdwMajor, sizeof(DWORD)) || - IsBadWritePtr(pdwMinor, sizeof(DWORD))) - return E_INVALIDARG; - //load the DLL - hComCtl = LoadLibrary(TEXT("comctl32.dll")); - if (!hComCtl) return E_FAIL; + if (IsBadWritePtr(pdwMajor, sizeof(DWORD)) + || IsBadWritePtr(pdwMinor, sizeof(DWORD))) + return E_INVALIDARG; + // load the DLL + hComCtl = LoadLibrary(TEXT("comctl32.dll")); + if (!hComCtl) + return E_FAIL; - /* - You must get this function explicitly because earlier versions of the DLL - don't implement this function. That makes the lack of implementation of the - function a version marker in itself. - */ - pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hComCtl, TEXT("DllGetVersion")); - if(pDllGetVersion) { - DLLVERSIONINFO dvi; - ZeroMemory(&dvi, sizeof(dvi)); - dvi.cbSize = sizeof(dvi); - hr = (*pDllGetVersion)(&dvi); - if(SUCCEEDED(hr)) { - *pdwMajor = dvi.dwMajorVersion; - *pdwMinor = dvi.dwMinorVersion; - } else { - hr = E_FAIL; - } + /* + You must get this function explicitly because earlier versions of the DLL + don't implement this function. That makes the lack of implementation of + the + function a version marker in itself. + */ + pDllGetVersion = + (DLLGETVERSIONPROC) GetProcAddress(hComCtl, TEXT("DllGetVersion")); + if (pDllGetVersion) { + DLLVERSIONINFO dvi; + ZeroMemory(&dvi, sizeof(dvi)); + dvi.cbSize = sizeof(dvi); + hr = (*pDllGetVersion)(&dvi); + if (SUCCEEDED(hr)) { + *pdwMajor = dvi.dwMajorVersion; + *pdwMinor = dvi.dwMinorVersion; } else { - /* - If GetProcAddress failed, then the DLL is a version previous to the one - shipped with IE 3.x. - */ - *pdwMajor = 4; - *pdwMinor = 0; - } - FreeLibrary(hComCtl); - return hr; + hr = E_FAIL; + } + } else { + /* + If GetProcAddress failed, then the DLL is a version previous to the + one + shipped with IE 3.x. + */ + *pdwMajor = 4; + *pdwMinor = 0; + } + FreeLibrary(hComCtl); + return hr; } - -